@schukai/monster 4.42.1 → 4.43.0

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.
@@ -28,46 +28,46 @@ export { getSlottedElements, getSlottedNodes };
28
28
  * @throws {Error} query must be a string
29
29
  */
30
30
  function getSlottedNodes(query, name) {
31
- const result = new Set();
32
-
33
- if (!this.shadowRoot) {
34
- return result;
35
- }
36
-
37
- let selector = "slot";
38
- if (name !== undefined) {
39
- if (name === null) {
40
- selector += ":not([name])";
41
- } else {
42
- selector += `[name=${validateString(name)}]`;
43
- }
44
- }
45
-
46
- const slots = this.shadowRoot.querySelectorAll(selector);
47
-
48
- for (const [, slot] of Object.entries(slots)) {
49
- slot.assignedNodes().forEach(function (node) {
50
- if (node === null || node === undefined) {
51
- return;
52
- }
53
-
54
- if (isString(query)) {
55
- node.querySelectorAll(query).forEach(function (n) {
56
- result.add(n);
57
- });
58
-
59
- if (node.matches(query)) {
60
- result.add(node);
61
- }
62
- } else if (query !== undefined) {
63
- throw new Error("query must be a string");
64
- } else {
65
- result.add(node);
66
- }
67
- });
68
- }
69
-
70
- return result;
31
+ const result = new Set();
32
+
33
+ if (!this.shadowRoot) {
34
+ return result;
35
+ }
36
+
37
+ let selector = "slot";
38
+ if (name !== undefined) {
39
+ if (name === null) {
40
+ selector += ":not([name])";
41
+ } else {
42
+ selector += `[name=${validateString(name)}]`;
43
+ }
44
+ }
45
+
46
+ const slots = this.shadowRoot.querySelectorAll(selector);
47
+
48
+ for (const [, slot] of Object.entries(slots)) {
49
+ slot.assignedNodes().forEach(function (node) {
50
+ if (node === null || node === undefined) {
51
+ return;
52
+ }
53
+
54
+ if (isString(query)) {
55
+ node.querySelectorAll(query).forEach(function (n) {
56
+ result.add(n);
57
+ });
58
+
59
+ if (node.matches(query)) {
60
+ result.add(node);
61
+ }
62
+ } else if (query !== undefined) {
63
+ throw new Error("query must be a string");
64
+ } else {
65
+ result.add(node);
66
+ }
67
+ });
68
+ }
69
+
70
+ return result;
71
71
  }
72
72
 
73
73
  /**
@@ -81,51 +81,51 @@ function getSlottedNodes(query, name) {
81
81
  * @throws {Error} query must be a string
82
82
  */
83
83
  function getSlottedElements(query, name) {
84
- const result = new Set();
85
-
86
- if (!(this.shadowRoot instanceof ShadowRoot)) {
87
- return result;
88
- }
89
-
90
- let selector = "slot";
91
- if (name !== undefined) {
92
- if (name === null) {
93
- selector += ":not([name])";
94
- } else {
95
- selector += `[name=${validateString(name)}]`;
96
- }
97
- }
98
-
99
- const slots = this.shadowRoot.querySelectorAll(selector);
100
-
101
- for (const [, slot] of Object.entries(slots)) {
102
- slot.assignedElements().forEach(function (node) {
103
- if (
104
- !(node instanceof HTMLElement) &&
105
- !(node instanceof SVGElement) &&
106
- !(node instanceof MathMLElement)
107
- )
108
- return;
109
-
110
- if (isString(query)) {
111
- if (query.length > 0) {
112
- node.querySelectorAll(query).forEach(function (n) {
113
- result.add(n);
114
- });
115
-
116
- if (node.matches(query)) {
117
- result.add(node);
118
- }
119
- } else {
120
- result.add(node);
121
- }
122
- } else if (query !== undefined) {
123
- throw new Error("query must be a string and not empty");
124
- } else {
125
- result.add(node);
126
- }
127
- });
128
- }
129
-
130
- return result;
84
+ const result = new Set();
85
+
86
+ if (!(this.shadowRoot instanceof ShadowRoot)) {
87
+ return result;
88
+ }
89
+
90
+ let selector = "slot";
91
+ if (name !== undefined) {
92
+ if (name === null) {
93
+ selector += ":not([name])";
94
+ } else {
95
+ selector += `[name=${validateString(name)}]`;
96
+ }
97
+ }
98
+
99
+ const slots = this.shadowRoot.querySelectorAll(selector);
100
+
101
+ for (const [, slot] of Object.entries(slots)) {
102
+ slot.assignedElements().forEach(function (node) {
103
+ if (
104
+ !(node instanceof HTMLElement) &&
105
+ !(node instanceof SVGElement) &&
106
+ !(node instanceof MathMLElement)
107
+ )
108
+ return;
109
+
110
+ if (isString(query)) {
111
+ if (query.length > 0) {
112
+ node.querySelectorAll(query).forEach(function (n) {
113
+ result.add(n);
114
+ });
115
+
116
+ if (node.matches(query)) {
117
+ result.add(node);
118
+ }
119
+ } else {
120
+ result.add(node);
121
+ }
122
+ } else if (query !== undefined) {
123
+ throw new Error("query must be a string and not empty");
124
+ } else {
125
+ result.add(node);
126
+ }
127
+ });
128
+ }
129
+
130
+ return result;
131
131
  }
@@ -15,19 +15,29 @@
15
15
  import { proxyInstanceMarker } from "../constants.mjs";
16
16
 
17
17
  export {
18
- isIterable,
19
- isPrimitive,
20
- isSymbol,
21
- isBoolean,
22
- isString,
23
- isObject,
24
- isInstance,
25
- isArray,
26
- isFunction,
27
- isInteger,
28
- isProxy,
18
+ isIterable,
19
+ isPrimitive,
20
+ isSymbol,
21
+ isBoolean,
22
+ isString,
23
+ isObject,
24
+ isInstance,
25
+ isArray,
26
+ isFunction,
27
+ isInteger,
28
+ isProxy,
29
+ isElement,
29
30
  };
30
31
 
32
+ /**
33
+ * Checks whether the value passed is a DOM Element.
34
+ * @param {*} value
35
+ * @returns {boolean}
36
+ */
37
+ function isElement(value) {
38
+ return value instanceof Element;
39
+ }
40
+
31
41
  /**
32
42
  * Checks whether the value passed is a Proxy.
33
43
  *
@@ -35,7 +45,7 @@ export {
35
45
  * @returns {boolean}
36
46
  */
37
47
  function isProxy(value) {
38
- return value?.[proxyInstanceMarker] === proxyInstanceMarker;
48
+ return value?.[proxyInstanceMarker] === proxyInstanceMarker;
39
49
  }
40
50
 
41
51
  /**
@@ -53,9 +63,9 @@ function isProxy(value) {
53
63
  * @copyright schukai GmbH
54
64
  */
55
65
  function isIterable(value) {
56
- if (value === undefined) return false;
57
- if (value === null) return false;
58
- return typeof value?.[Symbol.iterator] === "function";
66
+ if (value === undefined) return false;
67
+ if (value === null) return false;
68
+ return typeof value?.[Symbol.iterator] === "function";
59
69
  }
60
70
 
61
71
  /**
@@ -71,24 +81,24 @@ function isIterable(value) {
71
81
  * @copyright schukai GmbH
72
82
  */
73
83
  function isPrimitive(value) {
74
- var type;
84
+ var type;
75
85
 
76
- if (value === undefined || value === null) {
77
- return true;
78
- }
86
+ if (value === undefined || value === null) {
87
+ return true;
88
+ }
79
89
 
80
- type = typeof value;
90
+ type = typeof value;
81
91
 
82
- if (
83
- type === "string" ||
84
- type === "number" ||
85
- type === "boolean" ||
86
- type === "symbol"
87
- ) {
88
- return true;
89
- }
92
+ if (
93
+ type === "string" ||
94
+ type === "number" ||
95
+ type === "boolean" ||
96
+ type === "symbol"
97
+ ) {
98
+ return true;
99
+ }
90
100
 
91
- return false;
101
+ return false;
92
102
  }
93
103
 
94
104
  /**
@@ -104,7 +114,7 @@ function isPrimitive(value) {
104
114
  * @copyright schukai GmbH
105
115
  */
106
116
  function isSymbol(value) {
107
- return "symbol" === typeof value ? true : false;
117
+ return "symbol" === typeof value ? true : false;
108
118
  }
109
119
 
110
120
  /**
@@ -120,11 +130,11 @@ function isSymbol(value) {
120
130
  * @copyright schukai GmbH
121
131
  */
122
132
  function isBoolean(value) {
123
- if (value === true || value === false) {
124
- return true;
125
- }
133
+ if (value === true || value === false) {
134
+ return true;
135
+ }
126
136
 
127
- return false;
137
+ return false;
128
138
  }
129
139
 
130
140
  /**
@@ -140,10 +150,10 @@ function isBoolean(value) {
140
150
  * @copyright schukai GmbH
141
151
  */
142
152
  function isString(value) {
143
- if (value === undefined || typeof value !== "string") {
144
- return false;
145
- }
146
- return true;
153
+ if (value === undefined || typeof value !== "string") {
154
+ return false;
155
+ }
156
+ return true;
147
157
  }
148
158
 
149
159
  /**
@@ -159,14 +169,14 @@ function isString(value) {
159
169
  * @copyright schukai GmbH
160
170
  */
161
171
  function isObject(value) {
162
- if (isArray(value)) return false;
163
- if (isPrimitive(value)) return false;
172
+ if (isArray(value)) return false;
173
+ if (isPrimitive(value)) return false;
164
174
 
165
- if (typeof value === "object") {
166
- return true;
167
- }
175
+ if (typeof value === "object") {
176
+ return true;
177
+ }
168
178
 
169
- return false;
179
+ return false;
170
180
  }
171
181
 
172
182
  /**
@@ -183,18 +193,18 @@ function isObject(value) {
183
193
  * @copyright schukai GmbH
184
194
  */
185
195
  function isInstance(value, instance) {
186
- if (!isObject(value)) return false;
187
- if (!isFunction(instance)) return false;
188
- if (!instance.hasOwnProperty("prototype")) return false;
189
- if (value instanceof instance) return true;
190
-
191
- let proto = Object.getPrototypeOf(value);
192
- while (proto != null) {
193
- if (proto === instance.prototype) return true;
194
- proto = Object.getPrototypeOf(proto);
195
- }
196
-
197
- return false;
196
+ if (!isObject(value)) return false;
197
+ if (!isFunction(instance)) return false;
198
+ if (!instance.hasOwnProperty("prototype")) return false;
199
+ if (value instanceof instance) return true;
200
+
201
+ let proto = Object.getPrototypeOf(value);
202
+ while (proto != null) {
203
+ if (proto === instance.prototype) return true;
204
+ proto = Object.getPrototypeOf(proto);
205
+ }
206
+
207
+ return false;
198
208
  }
199
209
 
200
210
  /**
@@ -211,7 +221,7 @@ function isInstance(value, instance) {
211
221
  * @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
212
222
  */
213
223
  function isArray(value) {
214
- return Array.isArray(value);
224
+ return Array.isArray(value);
215
225
  }
216
226
 
217
227
  /**
@@ -227,14 +237,14 @@ function isArray(value) {
227
237
  * @copyright schukai GmbH
228
238
  */
229
239
  function isFunction(value) {
230
- if (isArray(value)) return false;
231
- if (isPrimitive(value)) return false;
240
+ if (isArray(value)) return false;
241
+ if (isPrimitive(value)) return false;
232
242
 
233
- if (typeof value === "function") {
234
- return true;
235
- }
243
+ if (typeof value === "function") {
244
+ return true;
245
+ }
236
246
 
237
- return false;
247
+ return false;
238
248
  }
239
249
 
240
250
  /**
@@ -250,5 +260,5 @@ function isFunction(value) {
250
260
  * @copyright schukai GmbH
251
261
  */
252
262
  function isInteger(value) {
253
- return Number.isInteger(value);
263
+ return Number.isInteger(value);
254
264
  }