@splendidlabz/utils 1.10.0 → 1.10.1
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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/dom/actions/index.cjs +75 -73
- package/dist/cjs/dom/actions/masonry.cjs +4 -2
- package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +24 -24
- package/dist/cjs/dom/actions/sticky.cjs +4 -2
- package/dist/cjs/dom/index.cjs +62 -49
- package/dist/cjs/dom/observers/index.cjs +14 -3
- package/dist/cjs/dom/observers/resize-observer.cjs +4 -2
- package/dist/cjs/dom/observers/scroll-observer.cjs +14 -3
- package/dist/esm/dom/actions/index.js +75 -73
- package/dist/esm/dom/actions/masonry.js +4 -2
- package/dist/esm/dom/actions/prefer-horizontal-scroll.js +24 -24
- package/dist/esm/dom/actions/sticky.js +4 -2
- package/dist/esm/dom/index.js +62 -49
- package/dist/esm/dom/observers/index.js +14 -3
- package/dist/esm/dom/observers/resize-observer.js +4 -2
- package/dist/esm/dom/observers/scroll-observer.js +14 -3
- package/dist/types/dom/events.d.cts +2 -2
- package/dist/types/dom/observers/resize-observer.d.cts +3 -3
- package/dist/types/dom/observers/scroll-observer.d.cts +2 -12
- package/dist/types/dom/spam-prevention.d.cts +7 -7
- package/dist/types/lib/checks.d.cts +1 -1
- package/package.json +1 -1
- package/src/dom/actions/prefer-horizontal-scroll.js +3 -8
- package/src/dom/events.js +1 -1
- package/src/dom/font-size.js +1 -1
- package/src/dom/observers/resize-observer.js +6 -4
- package/src/dom/observers/scroll-observer.js +17 -2
- package/src/dom/spam-prevention.js +5 -4
- package/src/dom/events.test.js +0 -99
package/CHANGELOG.md
CHANGED
|
@@ -108,12 +108,14 @@ function useObserverMethodOnTarget(target, observer, method = "observe", options
|
|
|
108
108
|
function resizeObserver(target, options) {
|
|
109
109
|
const { callback, ...opts } = options;
|
|
110
110
|
const observer = new ResizeObserver(observerFn);
|
|
111
|
-
if (target === window
|
|
111
|
+
if (target === window || target === document)
|
|
112
|
+
target = document.documentElement;
|
|
112
113
|
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
113
114
|
function observerFn(entries) {
|
|
114
115
|
for (const entry of entries) {
|
|
115
116
|
if (callback) callback({ entry, entries, observer });
|
|
116
|
-
else
|
|
117
|
+
else
|
|
118
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
return {
|
|
@@ -161,58 +163,6 @@ function nativeMasonrySupport(node) {
|
|
|
161
163
|
return getComputedStyle(node).gridTemplateRows === "masonry";
|
|
162
164
|
}
|
|
163
165
|
|
|
164
|
-
// src/dom/bounding-box.js
|
|
165
|
-
function boundingBox(element, { containsPadding = true } = {}) {
|
|
166
|
-
const box = element.getBoundingClientRect();
|
|
167
|
-
const ret = {};
|
|
168
|
-
for (const prop in box) ret[prop] = box[prop];
|
|
169
|
-
if (!containsPadding) {
|
|
170
|
-
const style = getComputedStyle(element);
|
|
171
|
-
const paddingTop = parseFloat(style.paddingTop);
|
|
172
|
-
const paddingRight = parseFloat(style.paddingRight);
|
|
173
|
-
const paddingBottom = parseFloat(style.paddingBottom);
|
|
174
|
-
const paddingLeft = parseFloat(style.paddingLeft);
|
|
175
|
-
ret.x = ret.x + paddingLeft;
|
|
176
|
-
ret.y = ret.y + paddingTop;
|
|
177
|
-
ret.width = ret.width - paddingLeft - paddingRight;
|
|
178
|
-
ret.height = ret.height - paddingTop - paddingBottom;
|
|
179
|
-
ret.top = ret.top + paddingTop;
|
|
180
|
-
ret.bottom = ret.bottom - paddingBottom;
|
|
181
|
-
ret.right = ret.right - paddingRight;
|
|
182
|
-
ret.left = ret.left + paddingLeft;
|
|
183
|
-
}
|
|
184
|
-
ret.xCenter = (ret.left + ret.right) / 2;
|
|
185
|
-
ret.yCenter = (ret.top + ret.bottom) / 2;
|
|
186
|
-
return ret;
|
|
187
|
-
}
|
|
188
|
-
function boundingBoxRelativeToAncestor({ element, ancestorElement }) {
|
|
189
|
-
ancestorElement = ancestorElement || element.parentElement;
|
|
190
|
-
const box = boundingBox(element);
|
|
191
|
-
const ancestorBox = boundingBox(ancestorElement, {
|
|
192
|
-
containsPadding: false
|
|
193
|
-
});
|
|
194
|
-
return {
|
|
195
|
-
top: box.top - ancestorBox.top,
|
|
196
|
-
right: box.right - ancestorBox.right,
|
|
197
|
-
bottom: box.bottom - ancestorBox.bottom,
|
|
198
|
-
left: box.left - ancestorBox.left,
|
|
199
|
-
width: box.width,
|
|
200
|
-
height: box.height,
|
|
201
|
-
xCenter: (box.left + box.right) / 2 - ancestorBox.left,
|
|
202
|
-
yCenter: (box.top + box.bottom) / 2 - ancestorBox.top
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// src/dom/css-vars.js
|
|
207
|
-
function getCSSVar(element, prop) {
|
|
208
|
-
element = getElement(element);
|
|
209
|
-
return getComputedStyle(element).getPropertyValue(prop);
|
|
210
|
-
}
|
|
211
|
-
function setCSSVar(element, prop, value) {
|
|
212
|
-
element = getElement(element);
|
|
213
|
-
element.style.setProperty(prop, value);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
166
|
// src/lib/objects/omit-empty.js
|
|
217
167
|
function omitEmpty(obj, shallow = false) {
|
|
218
168
|
if (typeof obj !== "object" || obj === null) return obj;
|
|
@@ -227,25 +177,14 @@ function omitEmpty(obj, shallow = false) {
|
|
|
227
177
|
return result;
|
|
228
178
|
}
|
|
229
179
|
|
|
230
|
-
// src/dom/
|
|
231
|
-
function
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return parent;
|
|
239
|
-
}
|
|
240
|
-
if (direction === "horizontal") {
|
|
241
|
-
if (overflowX === "auto" || overflowX === "scroll") return parent;
|
|
242
|
-
}
|
|
243
|
-
if (direction === "vertical") {
|
|
244
|
-
if (overflowY === "auto" || overflowY === "scroll") return parent;
|
|
245
|
-
}
|
|
246
|
-
parent = parent.parentElement;
|
|
247
|
-
}
|
|
248
|
-
return document.documentElement;
|
|
180
|
+
// src/dom/css-vars.js
|
|
181
|
+
function getCSSVar(element, prop) {
|
|
182
|
+
element = getElement(element);
|
|
183
|
+
return getComputedStyle(element).getPropertyValue(prop);
|
|
184
|
+
}
|
|
185
|
+
function setCSSVar(element, prop, value) {
|
|
186
|
+
element = getElement(element);
|
|
187
|
+
element.style.setProperty(prop, value);
|
|
249
188
|
}
|
|
250
189
|
|
|
251
190
|
// src/dom/actions/prefer-horizontal-scroll.js
|
|
@@ -334,6 +273,69 @@ function isTrackpad(event) {
|
|
|
334
273
|
if (event.wheelDeltaY === event.deltaY * -3) return true;
|
|
335
274
|
}
|
|
336
275
|
|
|
276
|
+
// src/dom/bounding-box.js
|
|
277
|
+
function boundingBox(element, { containsPadding = true } = {}) {
|
|
278
|
+
const box = element.getBoundingClientRect();
|
|
279
|
+
const ret = {};
|
|
280
|
+
for (const prop in box) ret[prop] = box[prop];
|
|
281
|
+
if (!containsPadding) {
|
|
282
|
+
const style = getComputedStyle(element);
|
|
283
|
+
const paddingTop = parseFloat(style.paddingTop);
|
|
284
|
+
const paddingRight = parseFloat(style.paddingRight);
|
|
285
|
+
const paddingBottom = parseFloat(style.paddingBottom);
|
|
286
|
+
const paddingLeft = parseFloat(style.paddingLeft);
|
|
287
|
+
ret.x = ret.x + paddingLeft;
|
|
288
|
+
ret.y = ret.y + paddingTop;
|
|
289
|
+
ret.width = ret.width - paddingLeft - paddingRight;
|
|
290
|
+
ret.height = ret.height - paddingTop - paddingBottom;
|
|
291
|
+
ret.top = ret.top + paddingTop;
|
|
292
|
+
ret.bottom = ret.bottom - paddingBottom;
|
|
293
|
+
ret.right = ret.right - paddingRight;
|
|
294
|
+
ret.left = ret.left + paddingLeft;
|
|
295
|
+
}
|
|
296
|
+
ret.xCenter = (ret.left + ret.right) / 2;
|
|
297
|
+
ret.yCenter = (ret.top + ret.bottom) / 2;
|
|
298
|
+
return ret;
|
|
299
|
+
}
|
|
300
|
+
function boundingBoxRelativeToAncestor({ element, ancestorElement }) {
|
|
301
|
+
ancestorElement = ancestorElement || element.parentElement;
|
|
302
|
+
const box = boundingBox(element);
|
|
303
|
+
const ancestorBox = boundingBox(ancestorElement, {
|
|
304
|
+
containsPadding: false
|
|
305
|
+
});
|
|
306
|
+
return {
|
|
307
|
+
top: box.top - ancestorBox.top,
|
|
308
|
+
right: box.right - ancestorBox.right,
|
|
309
|
+
bottom: box.bottom - ancestorBox.bottom,
|
|
310
|
+
left: box.left - ancestorBox.left,
|
|
311
|
+
width: box.width,
|
|
312
|
+
height: box.height,
|
|
313
|
+
xCenter: (box.left + box.right) / 2 - ancestorBox.left,
|
|
314
|
+
yCenter: (box.top + box.bottom) / 2 - ancestorBox.top
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/dom/ui/scroll-container.js
|
|
319
|
+
function findScrollContainer(element, direction = "both") {
|
|
320
|
+
if (!element) return;
|
|
321
|
+
let parent = element.parentElement;
|
|
322
|
+
while (parent) {
|
|
323
|
+
const { overflow, overflowX, overflowY } = getComputedStyle(parent);
|
|
324
|
+
if (direction === "both") {
|
|
325
|
+
if (overflow.includes("auto") || overflow.includes("scroll"))
|
|
326
|
+
return parent;
|
|
327
|
+
}
|
|
328
|
+
if (direction === "horizontal") {
|
|
329
|
+
if (overflowX === "auto" || overflowX === "scroll") return parent;
|
|
330
|
+
}
|
|
331
|
+
if (direction === "vertical") {
|
|
332
|
+
if (overflowY === "auto" || overflowY === "scroll") return parent;
|
|
333
|
+
}
|
|
334
|
+
parent = parent.parentElement;
|
|
335
|
+
}
|
|
336
|
+
return document.documentElement;
|
|
337
|
+
}
|
|
338
|
+
|
|
337
339
|
// src/dom/actions/sticky.js
|
|
338
340
|
function sticky(node, props = {}) {
|
|
339
341
|
const scrollContainer = findScrollContainer(node);
|
|
@@ -91,12 +91,14 @@ function useObserverMethodOnTarget(target, observer, method = "observe", options
|
|
|
91
91
|
function resizeObserver(target, options) {
|
|
92
92
|
const { callback, ...opts } = options;
|
|
93
93
|
const observer = new ResizeObserver(observerFn);
|
|
94
|
-
if (target === window
|
|
94
|
+
if (target === window || target === document)
|
|
95
|
+
target = document.documentElement;
|
|
95
96
|
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
96
97
|
function observerFn(entries) {
|
|
97
98
|
for (const entry of entries) {
|
|
98
99
|
if (callback) callback({ entry, entries, observer });
|
|
99
|
-
else
|
|
100
|
+
else
|
|
101
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
return {
|
|
@@ -23,6 +23,20 @@ __export(prefer_horizontal_scroll_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(prefer_horizontal_scroll_exports);
|
|
25
25
|
|
|
26
|
+
// src/lib/objects/omit-empty.js
|
|
27
|
+
function omitEmpty(obj, shallow = false) {
|
|
28
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
29
|
+
if (obj instanceof Date) return obj;
|
|
30
|
+
const result = Array.isArray(obj) ? [] : {};
|
|
31
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
32
|
+
if (value === null || value === void 0 || value === "" || typeof value === "object" && !(value instanceof Date) && Object.keys(value).length === 0) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
result[key] = shallow ? value : omitEmpty(value);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
// src/dom/get-element.js
|
|
27
41
|
function getElement(selector) {
|
|
28
42
|
if (!selector) return;
|
|
@@ -30,18 +44,6 @@ function getElement(selector) {
|
|
|
30
44
|
return document.querySelector(selector);
|
|
31
45
|
}
|
|
32
46
|
|
|
33
|
-
// src/dom/events.js
|
|
34
|
-
function addListeners(listeners) {
|
|
35
|
-
listeners.forEach(({ node, event, handler }) => {
|
|
36
|
-
node.addEventListener(event, handler);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function removeListeners(listeners) {
|
|
40
|
-
listeners.forEach(({ node, event, handler }) => {
|
|
41
|
-
node.removeEventListener(event, handler);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
47
|
// src/dom/css-vars.js
|
|
46
48
|
function getCSSVar(element, prop) {
|
|
47
49
|
element = getElement(element);
|
|
@@ -52,18 +54,16 @@ function setCSSVar(element, prop, value) {
|
|
|
52
54
|
element.style.setProperty(prop, value);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
// src/
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
57
|
+
// src/dom/events.js
|
|
58
|
+
function addListeners(listeners) {
|
|
59
|
+
listeners.forEach(({ node, event, handler }) => {
|
|
60
|
+
node.addEventListener(event, handler);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function removeListeners(listeners) {
|
|
64
|
+
listeners.forEach(({ node, event, handler }) => {
|
|
65
|
+
node.removeEventListener(event, handler);
|
|
66
|
+
});
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/dom/actions/prefer-horizontal-scroll.js
|
|
@@ -99,12 +99,14 @@ function useObserverMethodOnTarget(target, observer, method = "observe", options
|
|
|
99
99
|
function resizeObserver(target, options) {
|
|
100
100
|
const { callback, ...opts } = options;
|
|
101
101
|
const observer = new ResizeObserver(observerFn);
|
|
102
|
-
if (target === window
|
|
102
|
+
if (target === window || target === document)
|
|
103
|
+
target = document.documentElement;
|
|
103
104
|
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
104
105
|
function observerFn(entries) {
|
|
105
106
|
for (const entry of entries) {
|
|
106
107
|
if (callback) callback({ entry, entries, observer });
|
|
107
|
-
else
|
|
108
|
+
else
|
|
109
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
return {
|
package/dist/cjs/dom/index.cjs
CHANGED
|
@@ -249,12 +249,14 @@ function useObserverMethodOnTarget(target, observer, method = "observe", options
|
|
|
249
249
|
function resizeObserver(target, options) {
|
|
250
250
|
const { callback, ...opts } = options;
|
|
251
251
|
const observer = new ResizeObserver(observerFn);
|
|
252
|
-
if (target === window
|
|
252
|
+
if (target === window || target === document)
|
|
253
|
+
target = document.documentElement;
|
|
253
254
|
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
254
255
|
function observerFn(entries) {
|
|
255
256
|
for (const entry of entries) {
|
|
256
257
|
if (callback) callback({ entry, entries, observer });
|
|
257
|
-
else
|
|
258
|
+
else
|
|
259
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
258
260
|
}
|
|
259
261
|
}
|
|
260
262
|
return {
|
|
@@ -302,36 +304,6 @@ function nativeMasonrySupport(node) {
|
|
|
302
304
|
return getComputedStyle(node).gridTemplateRows === "masonry";
|
|
303
305
|
}
|
|
304
306
|
|
|
305
|
-
// src/lib/numbers/index.js
|
|
306
|
-
function splitUnit(string) {
|
|
307
|
-
if (typeof string === "number") return [string, null];
|
|
308
|
-
const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
|
|
309
|
-
const match = string.match(regex);
|
|
310
|
-
if (match) return [parseFloat(match[1]), match[2]];
|
|
311
|
-
return [parseFloat(string), null];
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// src/lib/form/sanitize.js
|
|
315
|
-
function sanitize(value, options = {}) {
|
|
316
|
-
const { sanitizer, ...rest } = options;
|
|
317
|
-
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
318
|
-
if (typeof value === "string") return sanitizer(value, rest);
|
|
319
|
-
if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
|
|
320
|
-
if (value && typeof value === "object") {
|
|
321
|
-
return Object.fromEntries(
|
|
322
|
-
Object.entries(value).map(([key, val]) => [
|
|
323
|
-
key,
|
|
324
|
-
sanitize(val, { sanitizer, ...rest })
|
|
325
|
-
])
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
return value;
|
|
329
|
-
}
|
|
330
|
-
function sanitizeArray(arr, { sanitizer, ...rest }) {
|
|
331
|
-
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
332
|
-
return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
|
|
333
|
-
}
|
|
334
|
-
|
|
335
307
|
// src/lib/objects/omit-empty.js
|
|
336
308
|
function omitEmpty(obj, shallow = false) {
|
|
337
309
|
if (typeof obj !== "object" || obj === null) return obj;
|
|
@@ -346,6 +318,22 @@ function omitEmpty(obj, shallow = false) {
|
|
|
346
318
|
return result;
|
|
347
319
|
}
|
|
348
320
|
|
|
321
|
+
// src/dom/css-vars.js
|
|
322
|
+
function getCSSValue(element, prop) {
|
|
323
|
+
return getCSSVar(element, prop);
|
|
324
|
+
}
|
|
325
|
+
function setCSSValue(element, prop, value) {
|
|
326
|
+
setCSSVar(element, prop, value);
|
|
327
|
+
}
|
|
328
|
+
function getCSSVar(element, prop) {
|
|
329
|
+
element = getElement(element);
|
|
330
|
+
return getComputedStyle(element).getPropertyValue(prop);
|
|
331
|
+
}
|
|
332
|
+
function setCSSVar(element, prop, value) {
|
|
333
|
+
element = getElement(element);
|
|
334
|
+
element.style.setProperty(prop, value);
|
|
335
|
+
}
|
|
336
|
+
|
|
349
337
|
// src/dom/actions/prefer-horizontal-scroll.js
|
|
350
338
|
var DEFAULT_OPTIONS = {
|
|
351
339
|
scrollSnapDelay: 1e3
|
|
@@ -601,22 +589,6 @@ function setCookie(name, value, days) {
|
|
|
601
589
|
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
|
602
590
|
}
|
|
603
591
|
|
|
604
|
-
// src/dom/css-vars.js
|
|
605
|
-
function getCSSValue(element, prop) {
|
|
606
|
-
return getCSSVar(element, prop);
|
|
607
|
-
}
|
|
608
|
-
function setCSSValue(element, prop, value) {
|
|
609
|
-
setCSSVar(element, prop, value);
|
|
610
|
-
}
|
|
611
|
-
function getCSSVar(element, prop) {
|
|
612
|
-
element = getElement(element);
|
|
613
|
-
return getComputedStyle(element).getPropertyValue(prop);
|
|
614
|
-
}
|
|
615
|
-
function setCSSVar(element, prop, value) {
|
|
616
|
-
element = getElement(element);
|
|
617
|
-
element.style.setProperty(prop, value);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
592
|
// src/dom/focusable.js
|
|
621
593
|
function getFocusableElements(container = document.body) {
|
|
622
594
|
return {
|
|
@@ -732,6 +704,15 @@ function Focusable(container = document.body) {
|
|
|
732
704
|
return getFocusableElements(container);
|
|
733
705
|
}
|
|
734
706
|
|
|
707
|
+
// src/lib/numbers/index.js
|
|
708
|
+
function splitUnit(string) {
|
|
709
|
+
if (typeof string === "number") return [string, null];
|
|
710
|
+
const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
|
|
711
|
+
const match = string.match(regex);
|
|
712
|
+
if (match) return [parseFloat(match[1]), match[2]];
|
|
713
|
+
return [parseFloat(string), null];
|
|
714
|
+
}
|
|
715
|
+
|
|
735
716
|
// src/dom/font-size.js
|
|
736
717
|
function getUnit(value) {
|
|
737
718
|
const [, unit] = splitUnit(value);
|
|
@@ -923,6 +904,15 @@ var defaultOptions2 = {
|
|
|
923
904
|
once: false
|
|
924
905
|
// Only fire threshold callback once
|
|
925
906
|
};
|
|
907
|
+
function getScrollElement(node) {
|
|
908
|
+
if (node === document || node === window || node === document.documentElement) {
|
|
909
|
+
return document.documentElement;
|
|
910
|
+
}
|
|
911
|
+
return (
|
|
912
|
+
/** @type {Element} */
|
|
913
|
+
node
|
|
914
|
+
);
|
|
915
|
+
}
|
|
926
916
|
function scrollObserver(node, options = {}) {
|
|
927
917
|
const { callback, onScrollDown, onScrollUp, onEnterThreshold, ...userOpts } = options;
|
|
928
918
|
const opts = { ...defaultOptions2, ...userOpts };
|
|
@@ -933,7 +923,7 @@ function scrollObserver(node, options = {}) {
|
|
|
933
923
|
let thresholdFired = false;
|
|
934
924
|
let rafId = null;
|
|
935
925
|
const isDocumentScroll = node === document || node === window || node === document.documentElement;
|
|
936
|
-
const scrollElement =
|
|
926
|
+
const scrollElement = getScrollElement(node);
|
|
937
927
|
const eventTarget = isDocumentScroll ? window : node;
|
|
938
928
|
let cachedScrollHeight = 0;
|
|
939
929
|
let cachedClientHeight = 0;
|
|
@@ -1040,6 +1030,29 @@ var queryParams = {
|
|
|
1040
1030
|
|
|
1041
1031
|
// src/dom/sanitize.js
|
|
1042
1032
|
var import_dompurify = __toESM(require("dompurify"), 1);
|
|
1033
|
+
|
|
1034
|
+
// src/lib/form/sanitize.js
|
|
1035
|
+
function sanitize(value, options = {}) {
|
|
1036
|
+
const { sanitizer, ...rest } = options;
|
|
1037
|
+
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
1038
|
+
if (typeof value === "string") return sanitizer(value, rest);
|
|
1039
|
+
if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
|
|
1040
|
+
if (value && typeof value === "object") {
|
|
1041
|
+
return Object.fromEntries(
|
|
1042
|
+
Object.entries(value).map(([key, val]) => [
|
|
1043
|
+
key,
|
|
1044
|
+
sanitize(val, { sanitizer, ...rest })
|
|
1045
|
+
])
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
return value;
|
|
1049
|
+
}
|
|
1050
|
+
function sanitizeArray(arr, { sanitizer, ...rest }) {
|
|
1051
|
+
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
1052
|
+
return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// src/dom/sanitize.js
|
|
1043
1056
|
function sanitize2(value, options = {}) {
|
|
1044
1057
|
return sanitize(value, { sanitizer: import_dompurify.default.sanitize, ...options });
|
|
1045
1058
|
}
|
|
@@ -130,12 +130,14 @@ function mutationObserver(target, options) {
|
|
|
130
130
|
function resizeObserver(target, options) {
|
|
131
131
|
const { callback, ...opts } = options;
|
|
132
132
|
const observer = new ResizeObserver(observerFn);
|
|
133
|
-
if (target === window
|
|
133
|
+
if (target === window || target === document)
|
|
134
|
+
target = document.documentElement;
|
|
134
135
|
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
135
136
|
function observerFn(entries) {
|
|
136
137
|
for (const entry of entries) {
|
|
137
138
|
if (callback) callback({ entry, entries, observer });
|
|
138
|
-
else
|
|
139
|
+
else
|
|
140
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
143
|
return {
|
|
@@ -159,6 +161,15 @@ var defaultOptions2 = {
|
|
|
159
161
|
once: false
|
|
160
162
|
// Only fire threshold callback once
|
|
161
163
|
};
|
|
164
|
+
function getScrollElement(node) {
|
|
165
|
+
if (node === document || node === window || node === document.documentElement) {
|
|
166
|
+
return document.documentElement;
|
|
167
|
+
}
|
|
168
|
+
return (
|
|
169
|
+
/** @type {Element} */
|
|
170
|
+
node
|
|
171
|
+
);
|
|
172
|
+
}
|
|
162
173
|
function scrollObserver(node, options = {}) {
|
|
163
174
|
const { callback, onScrollDown, onScrollUp, onEnterThreshold, ...userOpts } = options;
|
|
164
175
|
const opts = { ...defaultOptions2, ...userOpts };
|
|
@@ -169,7 +180,7 @@ function scrollObserver(node, options = {}) {
|
|
|
169
180
|
let thresholdFired = false;
|
|
170
181
|
let rafId = null;
|
|
171
182
|
const isDocumentScroll = node === document || node === window || node === document.documentElement;
|
|
172
|
-
const scrollElement =
|
|
183
|
+
const scrollElement = getScrollElement(node);
|
|
173
184
|
const eventTarget = isDocumentScroll ? window : node;
|
|
174
185
|
let cachedScrollHeight = 0;
|
|
175
186
|
let cachedClientHeight = 0;
|
|
@@ -57,12 +57,14 @@ function useObserverMethodOnTarget(target, observer, method = "observe", options
|
|
|
57
57
|
function resizeObserver(target, options) {
|
|
58
58
|
const { callback, ...opts } = options;
|
|
59
59
|
const observer = new ResizeObserver(observerFn);
|
|
60
|
-
if (target === window
|
|
60
|
+
if (target === window || target === document)
|
|
61
|
+
target = document.documentElement;
|
|
61
62
|
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
62
63
|
function observerFn(entries) {
|
|
63
64
|
for (const entry of entries) {
|
|
64
65
|
if (callback) callback({ entry, entries, observer });
|
|
65
|
-
else
|
|
66
|
+
else
|
|
67
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
return {
|
|
@@ -57,12 +57,14 @@ function useObserverMethodOnTarget(target, observer, method = "observe", options
|
|
|
57
57
|
function resizeObserver(target, options) {
|
|
58
58
|
const { callback, ...opts } = options;
|
|
59
59
|
const observer = new ResizeObserver(observerFn);
|
|
60
|
-
if (target === window
|
|
60
|
+
if (target === window || target === document)
|
|
61
|
+
target = document.documentElement;
|
|
61
62
|
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
62
63
|
function observerFn(entries) {
|
|
63
64
|
for (const entry of entries) {
|
|
64
65
|
if (callback) callback({ entry, entries, observer });
|
|
65
|
-
else
|
|
66
|
+
else
|
|
67
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
return {
|
|
@@ -86,6 +88,15 @@ var defaultOptions = {
|
|
|
86
88
|
once: false
|
|
87
89
|
// Only fire threshold callback once
|
|
88
90
|
};
|
|
91
|
+
function getScrollElement(node) {
|
|
92
|
+
if (node === document || node === window || node === document.documentElement) {
|
|
93
|
+
return document.documentElement;
|
|
94
|
+
}
|
|
95
|
+
return (
|
|
96
|
+
/** @type {Element} */
|
|
97
|
+
node
|
|
98
|
+
);
|
|
99
|
+
}
|
|
89
100
|
function scrollObserver(node, options = {}) {
|
|
90
101
|
const { callback, onScrollDown, onScrollUp, onEnterThreshold, ...userOpts } = options;
|
|
91
102
|
const opts = { ...defaultOptions, ...userOpts };
|
|
@@ -96,7 +107,7 @@ function scrollObserver(node, options = {}) {
|
|
|
96
107
|
let thresholdFired = false;
|
|
97
108
|
let rafId = null;
|
|
98
109
|
const isDocumentScroll = node === document || node === window || node === document.documentElement;
|
|
99
|
-
const scrollElement =
|
|
110
|
+
const scrollElement = getScrollElement(node);
|
|
100
111
|
const eventTarget = isDocumentScroll ? window : node;
|
|
101
112
|
let cachedScrollHeight = 0;
|
|
102
113
|
let cachedClientHeight = 0;
|