@duckduckgo/autoconsent 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/.eslintrc +12 -0
  2. package/Dockerfile +9 -0
  3. package/Jenkinsfile +50 -0
  4. package/LICENSE +373 -0
  5. package/cosmetics/rules.json +110 -0
  6. package/dist/autoconsent.cjs.js +1316 -0
  7. package/dist/autoconsent.esm.js +1308 -0
  8. package/dist/autoconsent.puppet.js +980 -0
  9. package/lib/cmps/all.js +17 -0
  10. package/lib/cmps/all.ts +21 -0
  11. package/lib/cmps/base.js +170 -0
  12. package/lib/cmps/base.ts +199 -0
  13. package/lib/cmps/consentmanager.js +31 -0
  14. package/lib/cmps/consentmanager.ts +39 -0
  15. package/lib/cmps/cookiebot.js +73 -0
  16. package/lib/cmps/cookiebot.ts +81 -0
  17. package/lib/cmps/evidon.js +26 -0
  18. package/lib/cmps/evidon.ts +32 -0
  19. package/lib/cmps/sourcepoint.js +82 -0
  20. package/lib/cmps/sourcepoint.ts +95 -0
  21. package/lib/cmps/trustarc.js +106 -0
  22. package/lib/cmps/trustarc.ts +147 -0
  23. package/lib/consentomatic/index.js +52 -0
  24. package/lib/consentomatic/index.ts +86 -0
  25. package/lib/detector.js +29 -0
  26. package/lib/detector.ts +30 -0
  27. package/lib/hider.js +13 -0
  28. package/lib/hider.ts +16 -0
  29. package/lib/index.js +4 -0
  30. package/lib/index.ts +6 -0
  31. package/lib/messages.d.ts +58 -0
  32. package/lib/node.js +30 -0
  33. package/lib/node.ts +38 -0
  34. package/lib/puppet/tab.js +114 -0
  35. package/lib/puppet/tab.ts +136 -0
  36. package/lib/rules.d.ts +80 -0
  37. package/lib/tabwrapper.js +61 -0
  38. package/lib/tabwrapper.ts +68 -0
  39. package/lib/types.d.ts +61 -0
  40. package/lib/web/consentomatic/index.js +188 -0
  41. package/lib/web/consentomatic/index.ts +249 -0
  42. package/lib/web/consentomatic/tools.js +177 -0
  43. package/lib/web/consentomatic/tools.ts +198 -0
  44. package/lib/web/content.js +91 -0
  45. package/lib/web/content.ts +83 -0
  46. package/lib/web/tab.js +106 -0
  47. package/lib/web/tab.ts +171 -0
  48. package/lib/web.js +90 -0
  49. package/lib/web.ts +109 -0
  50. package/package.json +41 -0
  51. package/playwright.config.ts +31 -0
  52. package/readme.md +151 -0
  53. package/rollup.config.js +54 -0
  54. package/rules/autoconsent/asus.json +7 -0
  55. package/rules/autoconsent/cc-banner.json +9 -0
  56. package/rules/autoconsent/cookie-law-info.json +14 -0
  57. package/rules/autoconsent/cookie-notice.json +9 -0
  58. package/rules/autoconsent/cookieconsent.json +9 -0
  59. package/rules/autoconsent/drupal.json +7 -0
  60. package/rules/autoconsent/eu-cookie-compliance.json +14 -0
  61. package/rules/autoconsent/fundingchoices.json +12 -0
  62. package/rules/autoconsent/hubspot.json +7 -0
  63. package/rules/autoconsent/klaro.json +10 -0
  64. package/rules/autoconsent/notice-cookie.json +9 -0
  65. package/rules/autoconsent/onetrust.json +24 -0
  66. package/rules/autoconsent/osano.json +11 -0
  67. package/rules/autoconsent/quantcast.json +14 -0
  68. package/rules/autoconsent/tealium.json +19 -0
  69. package/rules/autoconsent/testcmp.json +12 -0
  70. package/rules/build.js +63 -0
  71. package/rules/rules.json +3030 -0
  72. package/tests/asus.spec.ts +5 -0
  73. package/tests/ccbanner.spec.ts +11 -0
  74. package/tests/consentmanager.spec.ts +10 -0
  75. package/tests/cookiebot.spec.ts +9 -0
  76. package/tests/cookieconsent.spec.ts +8 -0
  77. package/tests/cookielawinfo.spec.ts +9 -0
  78. package/tests/cookienotice.spec.ts +6 -0
  79. package/tests/didomi.spec.ts +9 -0
  80. package/tests/eu-cookie-compliance-banner.spec.ts +7 -0
  81. package/tests/evidon.spec.ts +6 -0
  82. package/tests/fundingchoices.spec.ts +10 -0
  83. package/tests/hubspot.spec.ts +6 -0
  84. package/tests/klaro.spec.ts +5 -0
  85. package/tests/notice-cookie.spec.ts +7 -0
  86. package/tests/oil.spec.ts +10 -0
  87. package/tests/onetrust.spec.ts +15 -0
  88. package/tests/optanon.spec.ts +10 -0
  89. package/tests/osano.spec.ts +5 -0
  90. package/tests/quantcast.spec.ts +16 -0
  91. package/tests/runner.ts +61 -0
  92. package/tests/sourcepoint.spec.ts +17 -0
  93. package/tests/springer.spec.ts +11 -0
  94. package/tests/tealium.spec.ts +6 -0
  95. package/tests/testcmp.spec.ts +5 -0
  96. package/tests/trustarc.spec.ts +13 -0
  97. package/tests/wordpressgdpr.spec.ts +9 -0
  98. package/tsconfig.json +14 -0
  99. package/update_version.js +8 -0
@@ -0,0 +1,188 @@
1
+ import Tools from "./tools";
2
+ export function matches(config) {
3
+ const result = Tools.find(config);
4
+ if (config.type === "css") {
5
+ return !!result.target;
6
+ }
7
+ else if (config.type === "checkbox") {
8
+ return !!result.target && result.target.checked;
9
+ }
10
+ }
11
+ export async function executeAction(config, param) {
12
+ switch (config.type) {
13
+ case "click":
14
+ return clickAction(config);
15
+ case "list":
16
+ return listAction(config, param);
17
+ case "consent":
18
+ return consentAction(config, param);
19
+ case "ifcss":
20
+ return ifCssAction(config, param);
21
+ case "waitcss":
22
+ return waitCssAction(config);
23
+ case "foreach":
24
+ return forEachAction(config, param);
25
+ case "hide":
26
+ return hideAction(config);
27
+ case "slide":
28
+ return slideAction(config);
29
+ case "close":
30
+ return closeAction(config);
31
+ case "wait":
32
+ return waitAction(config);
33
+ case "eval":
34
+ return evalAction(config);
35
+ default:
36
+ throw "Unknown action type: " + config.type;
37
+ }
38
+ }
39
+ const STEP_TIMEOUT = 0;
40
+ function waitTimeout(timeout) {
41
+ return new Promise(resolve => {
42
+ setTimeout(() => {
43
+ resolve();
44
+ }, timeout);
45
+ });
46
+ }
47
+ async function clickAction(config) {
48
+ const result = Tools.find(config);
49
+ if (result.target != null) {
50
+ result.target.click();
51
+ }
52
+ return waitTimeout(STEP_TIMEOUT);
53
+ }
54
+ async function listAction(config, param) {
55
+ for (let action of config.actions) {
56
+ await executeAction(action, param);
57
+ }
58
+ }
59
+ async function consentAction(config, consentTypes) {
60
+ for (const consentConfig of config.consents) {
61
+ const shouldEnable = consentTypes.indexOf(consentConfig.type) !== -1;
62
+ if (consentConfig.matcher && consentConfig.toggleAction) {
63
+ const isEnabled = matches(consentConfig.matcher);
64
+ if (isEnabled !== shouldEnable) {
65
+ await executeAction(consentConfig.toggleAction);
66
+ }
67
+ }
68
+ else {
69
+ if (shouldEnable) {
70
+ await executeAction(consentConfig.trueAction);
71
+ }
72
+ else {
73
+ await executeAction(consentConfig.falseAction);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ async function ifCssAction(config, param) {
79
+ const result = Tools.find(config);
80
+ if (!result.target) {
81
+ if (config.trueAction) {
82
+ await executeAction(config.trueAction, param);
83
+ }
84
+ }
85
+ else {
86
+ if (config.falseAction) {
87
+ await executeAction(config.falseAction, param);
88
+ }
89
+ }
90
+ }
91
+ async function waitCssAction(config) {
92
+ await new Promise(resolve => {
93
+ let numRetries = config.retries || 10;
94
+ const waitTime = config.waitTime || 250;
95
+ const checkCss = () => {
96
+ const result = Tools.find(config);
97
+ if ((config.negated && result.target) ||
98
+ (!config.negated && !result.target)) {
99
+ if (numRetries > 0) {
100
+ numRetries -= 1;
101
+ setTimeout(checkCss, waitTime);
102
+ }
103
+ else {
104
+ resolve();
105
+ }
106
+ }
107
+ else {
108
+ resolve();
109
+ }
110
+ };
111
+ checkCss();
112
+ });
113
+ }
114
+ async function forEachAction(config, param) {
115
+ const results = Tools.find(config, true);
116
+ const oldBase = Tools.base;
117
+ for (const result of results) {
118
+ if (result.target) {
119
+ Tools.setBase(result.target);
120
+ await executeAction(config.action, param);
121
+ }
122
+ }
123
+ Tools.setBase(oldBase);
124
+ }
125
+ async function hideAction(config) {
126
+ const result = Tools.find(config);
127
+ if (result.target) {
128
+ result.target.classList.add("Autoconsent-Hidden");
129
+ // result.target.setAttribute("style", "display: none;");
130
+ }
131
+ }
132
+ async function slideAction(config) {
133
+ const result = Tools.find(config);
134
+ const dragResult = Tools.find(config.dragTarget);
135
+ if (result.target) {
136
+ let targetBounds = result.target.getBoundingClientRect();
137
+ let dragTargetBounds = dragResult.target.getBoundingClientRect();
138
+ let yDiff = dragTargetBounds.top - targetBounds.top;
139
+ let xDiff = dragTargetBounds.left - targetBounds.left;
140
+ if (this.config.axis.toLowerCase() === "y") {
141
+ xDiff = 0;
142
+ }
143
+ if (this.config.axis.toLowerCase() === "x") {
144
+ yDiff = 0;
145
+ }
146
+ let screenX = window.screenX + targetBounds.left + targetBounds.width / 2.0;
147
+ let screenY = window.screenY + targetBounds.top + targetBounds.height / 2.0;
148
+ let clientX = targetBounds.left + targetBounds.width / 2.0;
149
+ let clientY = targetBounds.top + targetBounds.height / 2.0;
150
+ let mouseDown = document.createEvent("MouseEvents");
151
+ mouseDown.initMouseEvent("mousedown", true, true, window, 0, screenX, screenY, clientX, clientY, false, false, false, false, 0, result.target);
152
+ let mouseMove = document.createEvent("MouseEvents");
153
+ mouseMove.initMouseEvent("mousemove", true, true, window, 0, screenX + xDiff, screenY + yDiff, clientX + xDiff, clientY + yDiff, false, false, false, false, 0, result.target);
154
+ let mouseUp = document.createEvent("MouseEvents");
155
+ mouseUp.initMouseEvent("mouseup", true, true, window, 0, screenX + xDiff, screenY + yDiff, clientX + xDiff, clientY + yDiff, false, false, false, false, 0, result.target);
156
+ result.target.dispatchEvent(mouseDown);
157
+ await this.waitTimeout(10);
158
+ result.target.dispatchEvent(mouseMove);
159
+ await this.waitTimeout(10);
160
+ result.target.dispatchEvent(mouseUp);
161
+ }
162
+ }
163
+ async function waitAction(config) {
164
+ await waitTimeout(config.waitTime);
165
+ }
166
+ async function closeAction(config) {
167
+ window.close();
168
+ }
169
+ async function evalAction(config) {
170
+ console.log("eval!", config.code);
171
+ return new Promise(resolve => {
172
+ try {
173
+ if (config.async) {
174
+ window.eval(config.code);
175
+ setTimeout(() => {
176
+ resolve(window.eval("window.__consentCheckResult"));
177
+ }, config.timeout || 250);
178
+ }
179
+ else {
180
+ resolve(window.eval(config.code));
181
+ }
182
+ }
183
+ catch (e) {
184
+ console.warn("eval error", e, config.code);
185
+ resolve(false);
186
+ }
187
+ });
188
+ }
@@ -0,0 +1,249 @@
1
+ import Tools from "./tools";
2
+
3
+ export function matches(config: any) {
4
+ const result = Tools.find(config);
5
+ if (config.type === "css") {
6
+ return !!result.target;
7
+ } else if (config.type === "checkbox") {
8
+ return !!result.target && result.target.checked;
9
+ }
10
+ }
11
+
12
+ export async function executeAction(config: any, param?: any): Promise<boolean | void> {
13
+ switch (config.type) {
14
+ case "click":
15
+ return clickAction(config);
16
+ case "list":
17
+ return listAction(config, param);
18
+ case "consent":
19
+ return consentAction(config, param);
20
+ case "ifcss":
21
+ return ifCssAction(config, param);
22
+ case "waitcss":
23
+ return waitCssAction(config);
24
+ case "foreach":
25
+ return forEachAction(config, param);
26
+ case "hide":
27
+ return hideAction(config);
28
+ case "slide":
29
+ return slideAction(config);
30
+ case "close":
31
+ return closeAction(config);
32
+ case "wait":
33
+ return waitAction(config);
34
+ case "eval":
35
+ return evalAction(config);
36
+ default:
37
+ throw "Unknown action type: " + config.type;
38
+ }
39
+ }
40
+
41
+ const STEP_TIMEOUT = 0;
42
+
43
+ function waitTimeout(timeout: number): Promise<void> {
44
+ return new Promise(resolve => {
45
+ setTimeout(() => {
46
+ resolve();
47
+ }, timeout);
48
+ });
49
+ }
50
+
51
+ async function clickAction(config: any) {
52
+ const result = Tools.find(config);
53
+ if (result.target != null) {
54
+ result.target.click();
55
+ }
56
+ return waitTimeout(STEP_TIMEOUT);
57
+ }
58
+
59
+ async function listAction(config: any, param: any) {
60
+ for (let action of config.actions) {
61
+ await executeAction(action, param);
62
+ }
63
+ }
64
+
65
+ async function consentAction(config: any, consentTypes: any) {
66
+ for (const consentConfig of config.consents) {
67
+ const shouldEnable = consentTypes.indexOf(consentConfig.type) !== -1;
68
+ if (consentConfig.matcher && consentConfig.toggleAction) {
69
+ const isEnabled = matches(consentConfig.matcher);
70
+ if (isEnabled !== shouldEnable) {
71
+ await executeAction(consentConfig.toggleAction);
72
+ }
73
+ } else {
74
+ if (shouldEnable) {
75
+ await executeAction(consentConfig.trueAction);
76
+ } else {
77
+ await executeAction(consentConfig.falseAction);
78
+ }
79
+ }
80
+ }
81
+ }
82
+
83
+ async function ifCssAction(config: any, param: any) {
84
+ const result = Tools.find(config);
85
+ if (!result.target) {
86
+ if (config.trueAction) {
87
+ await executeAction(config.trueAction, param);
88
+ }
89
+ } else {
90
+ if (config.falseAction) {
91
+ await executeAction(config.falseAction, param);
92
+ }
93
+ }
94
+ }
95
+
96
+ async function waitCssAction(config: any) {
97
+ await new Promise<void>(resolve => {
98
+ let numRetries = config.retries || 10;
99
+ const waitTime = config.waitTime || 250;
100
+ const checkCss = () => {
101
+ const result = Tools.find(config);
102
+ if (
103
+ (config.negated && result.target) ||
104
+ (!config.negated && !result.target)
105
+ ) {
106
+ if (numRetries > 0) {
107
+ numRetries -= 1;
108
+ setTimeout(checkCss, waitTime);
109
+ } else {
110
+ resolve();
111
+ }
112
+ } else {
113
+ resolve();
114
+ }
115
+ };
116
+ checkCss();
117
+ });
118
+ }
119
+
120
+ async function forEachAction(config: any, param: any) {
121
+ const results = Tools.find(config, true);
122
+ const oldBase = Tools.base;
123
+ for (const result of results) {
124
+ if (result.target) {
125
+ Tools.setBase(result.target);
126
+ await executeAction(config.action, param);
127
+ }
128
+ }
129
+ Tools.setBase(oldBase);
130
+ }
131
+
132
+ async function hideAction(config: any) {
133
+ const result = Tools.find(config);
134
+ if (result.target) {
135
+ result.target.classList.add("Autoconsent-Hidden");
136
+ // result.target.setAttribute("style", "display: none;");
137
+ }
138
+ }
139
+
140
+ async function slideAction(config: any) {
141
+ const result = Tools.find(config);
142
+ const dragResult = Tools.find(config.dragTarget);
143
+ if (result.target) {
144
+ let targetBounds = result.target.getBoundingClientRect();
145
+ let dragTargetBounds = dragResult.target.getBoundingClientRect();
146
+
147
+ let yDiff = dragTargetBounds.top - targetBounds.top;
148
+ let xDiff = dragTargetBounds.left - targetBounds.left;
149
+
150
+ if (this.config.axis.toLowerCase() === "y") {
151
+ xDiff = 0;
152
+ }
153
+ if (this.config.axis.toLowerCase() === "x") {
154
+ yDiff = 0;
155
+ }
156
+
157
+ let screenX = window.screenX + targetBounds.left + targetBounds.width / 2.0;
158
+ let screenY = window.screenY + targetBounds.top + targetBounds.height / 2.0;
159
+ let clientX = targetBounds.left + targetBounds.width / 2.0;
160
+ let clientY = targetBounds.top + targetBounds.height / 2.0;
161
+
162
+ let mouseDown = document.createEvent("MouseEvents");
163
+ mouseDown.initMouseEvent(
164
+ "mousedown",
165
+ true,
166
+ true,
167
+ window,
168
+ 0,
169
+ screenX,
170
+ screenY,
171
+ clientX,
172
+ clientY,
173
+ false,
174
+ false,
175
+ false,
176
+ false,
177
+ 0,
178
+ result.target
179
+ );
180
+ let mouseMove = document.createEvent("MouseEvents");
181
+ mouseMove.initMouseEvent(
182
+ "mousemove",
183
+ true,
184
+ true,
185
+ window,
186
+ 0,
187
+ screenX + xDiff,
188
+ screenY + yDiff,
189
+ clientX + xDiff,
190
+ clientY + yDiff,
191
+ false,
192
+ false,
193
+ false,
194
+ false,
195
+ 0,
196
+ result.target
197
+ );
198
+ let mouseUp = document.createEvent("MouseEvents");
199
+ mouseUp.initMouseEvent(
200
+ "mouseup",
201
+ true,
202
+ true,
203
+ window,
204
+ 0,
205
+ screenX + xDiff,
206
+ screenY + yDiff,
207
+ clientX + xDiff,
208
+ clientY + yDiff,
209
+ false,
210
+ false,
211
+ false,
212
+ false,
213
+ 0,
214
+ result.target
215
+ );
216
+ result.target.dispatchEvent(mouseDown);
217
+ await this.waitTimeout(10);
218
+ result.target.dispatchEvent(mouseMove);
219
+ await this.waitTimeout(10);
220
+ result.target.dispatchEvent(mouseUp);
221
+ }
222
+ }
223
+
224
+ async function waitAction(config: any) {
225
+ await waitTimeout(config.waitTime);
226
+ }
227
+
228
+ async function closeAction(config: any) {
229
+ window.close();
230
+ }
231
+
232
+ async function evalAction(config: any): Promise<boolean> {
233
+ console.log("eval!", config.code);
234
+ return new Promise(resolve => {
235
+ try {
236
+ if (config.async) {
237
+ window.eval(config.code);
238
+ setTimeout(() => {
239
+ resolve(window.eval("window.__consentCheckResult"));
240
+ }, config.timeout || 250);
241
+ } else {
242
+ resolve(window.eval(config.code));
243
+ }
244
+ } catch (e) {
245
+ console.warn("eval error", e, config.code);
246
+ resolve(false);
247
+ }
248
+ });
249
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * This code is in most parts copied from https://github.com/cavi-au/Consent-O-Matic/blob/master/Extension/Tools.js
3
+ * which is licened under the MIT.
4
+ */
5
+ export default class Tools {
6
+ static setBase(base) {
7
+ Tools.base = base;
8
+ }
9
+ static findElement(options, parent = null, multiple = false) {
10
+ let possibleTargets = null;
11
+ if (parent != null) {
12
+ possibleTargets = Array.from(parent.querySelectorAll(options.selector));
13
+ }
14
+ else {
15
+ if (Tools.base != null) {
16
+ possibleTargets = Array.from(Tools.base.querySelectorAll(options.selector));
17
+ }
18
+ else {
19
+ possibleTargets = Array.from(document.querySelectorAll(options.selector));
20
+ }
21
+ }
22
+ if (options.textFilter != null) {
23
+ possibleTargets = possibleTargets.filter(possibleTarget => {
24
+ let textContent = possibleTarget.textContent.toLowerCase();
25
+ if (Array.isArray(options.textFilter)) {
26
+ let foundText = false;
27
+ for (let text of options.textFilter) {
28
+ if (textContent.indexOf(text.toLowerCase()) !== -1) {
29
+ foundText = true;
30
+ break;
31
+ }
32
+ }
33
+ return foundText;
34
+ }
35
+ else if (options.textFilter != null) {
36
+ return textContent.indexOf(options.textFilter.toLowerCase()) !== -1;
37
+ }
38
+ });
39
+ }
40
+ if (options.styleFilters != null) {
41
+ possibleTargets = possibleTargets.filter(possibleTarget => {
42
+ let styles = window.getComputedStyle(possibleTarget);
43
+ let keep = true;
44
+ for (let styleFilter of options.styleFilters) {
45
+ let option = styles[styleFilter.option];
46
+ if (styleFilter.negated) {
47
+ keep = keep && option !== styleFilter.value;
48
+ }
49
+ else {
50
+ keep = keep && option === styleFilter.value;
51
+ }
52
+ }
53
+ return keep;
54
+ });
55
+ }
56
+ if (options.displayFilter != null) {
57
+ possibleTargets = possibleTargets.filter(possibleTarget => {
58
+ if (options.displayFilter) {
59
+ //We should be displayed
60
+ return possibleTarget.offsetHeight !== 0;
61
+ }
62
+ else {
63
+ //We should not be displayed
64
+ return possibleTarget.offsetHeight === 0;
65
+ }
66
+ });
67
+ }
68
+ if (options.iframeFilter != null) {
69
+ possibleTargets = possibleTargets.filter(possibleTarget => {
70
+ if (options.iframeFilter) {
71
+ //We should be inside an iframe
72
+ return window.location !== window.parent.location;
73
+ }
74
+ else {
75
+ //We should not be inside an iframe
76
+ return window.location === window.parent.location;
77
+ }
78
+ });
79
+ }
80
+ if (options.childFilter != null) {
81
+ possibleTargets = possibleTargets.filter(possibleTarget => {
82
+ let oldBase = Tools.base;
83
+ Tools.setBase(possibleTarget);
84
+ let childResults = Tools.find(options.childFilter);
85
+ Tools.setBase(oldBase);
86
+ return childResults.target != null;
87
+ });
88
+ }
89
+ if (multiple) {
90
+ return possibleTargets;
91
+ }
92
+ else {
93
+ if (possibleTargets.length > 1) {
94
+ console.warn("Multiple possible targets: ", possibleTargets, options, parent);
95
+ }
96
+ return possibleTargets[0];
97
+ }
98
+ }
99
+ static find(options, multiple = false) {
100
+ let results = [];
101
+ if (options.parent != null) {
102
+ let parent = Tools.findElement(options.parent, null, multiple);
103
+ if (parent != null) {
104
+ if (parent instanceof Array) {
105
+ parent.forEach(p => {
106
+ let targets = Tools.findElement(options.target, p, multiple);
107
+ if (targets instanceof Array) {
108
+ targets.forEach(target => {
109
+ results.push({
110
+ parent: p,
111
+ target: target
112
+ });
113
+ });
114
+ }
115
+ else {
116
+ results.push({
117
+ parent: p,
118
+ target: targets
119
+ });
120
+ }
121
+ });
122
+ return results;
123
+ }
124
+ else {
125
+ let targets = Tools.findElement(options.target, parent, multiple);
126
+ if (targets instanceof Array) {
127
+ targets.forEach(target => {
128
+ results.push({
129
+ parent: parent,
130
+ target: target
131
+ });
132
+ });
133
+ }
134
+ else {
135
+ results.push({
136
+ parent: parent,
137
+ target: targets
138
+ });
139
+ }
140
+ }
141
+ }
142
+ }
143
+ else {
144
+ let targets = Tools.findElement(options.target, null, multiple);
145
+ if (targets instanceof Array) {
146
+ targets.forEach(target => {
147
+ results.push({
148
+ parent: null,
149
+ target: target
150
+ });
151
+ });
152
+ }
153
+ else {
154
+ results.push({
155
+ parent: null,
156
+ target: targets
157
+ });
158
+ }
159
+ }
160
+ if (results.length === 0) {
161
+ results.push({
162
+ parent: null,
163
+ target: null
164
+ });
165
+ }
166
+ if (multiple) {
167
+ return results;
168
+ }
169
+ else {
170
+ if (results.length !== 1) {
171
+ console.warn("Multiple results found, even though multiple false", results);
172
+ }
173
+ return results[0];
174
+ }
175
+ }
176
+ }
177
+ Tools.base = null;