@splendidlabz/utils 1.11.2 → 1.11.4
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/dist/cjs/dom/accessibility.cjs +2 -0
- package/dist/cjs/dom/actions/index.cjs +392 -7
- package/dist/cjs/dom/actions/masonry.cjs +97 -6
- package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +58 -14
- package/dist/cjs/dom/actions/sticky.cjs +126 -6
- package/dist/cjs/dom/bounding-box.cjs +2 -0
- package/dist/cjs/dom/clipboard.cjs +2 -0
- package/dist/cjs/dom/cookie.cjs +3 -1
- package/dist/cjs/dom/css-vars.cjs +13 -3
- package/dist/cjs/dom/events.cjs +2 -0
- package/dist/cjs/dom/focusable.cjs +2 -0
- package/dist/cjs/dom/font-size.cjs +15 -3
- package/dist/cjs/dom/get-element.cjs +3 -1
- package/dist/cjs/dom/hash.cjs +2 -0
- package/dist/cjs/dom/index.cjs +1249 -47
- package/dist/cjs/dom/keyboard.cjs +2 -0
- package/dist/cjs/dom/local-store.cjs +3 -1
- package/dist/cjs/dom/media.cjs +2 -0
- package/dist/cjs/dom/observers/index.cjs +235 -9
- package/dist/cjs/dom/observers/intersection-observer.cjs +38 -6
- package/dist/cjs/dom/observers/mutation-observer.cjs +38 -6
- package/dist/cjs/dom/observers/observer.cjs +12 -2
- package/dist/cjs/dom/observers/resize-observer.cjs +38 -6
- package/dist/cjs/dom/observers/scroll-observer.cjs +62 -3
- package/dist/cjs/dom/pkce.cjs +13 -3
- package/dist/cjs/dom/query-params.cjs +3 -1
- package/dist/cjs/dom/random-string.cjs +2 -0
- package/dist/cjs/dom/sanitize.cjs +27 -3
- package/dist/cjs/dom/session-store.cjs +3 -1
- package/dist/cjs/dom/spam-prevention.cjs +2 -0
- package/dist/cjs/dom/trap-focus.cjs +131 -9
- package/dist/cjs/dom/ui/aria-current.cjs +2 -0
- package/dist/cjs/dom/ui/inconsistent-button-fix.cjs +2 -0
- package/dist/cjs/dom/ui/index.cjs +87 -9
- package/dist/cjs/dom/ui/scroll-container.cjs +2 -0
- package/dist/cjs/dom/ui/traverse-and-scramble.cjs +2 -0
- package/dist/cjs/lib/arrays/index.cjs +121 -13
- package/dist/cjs/lib/arrays/item-position.cjs +2 -0
- package/dist/cjs/lib/arrays/join.cjs +10 -2
- package/dist/cjs/lib/arrays/shuffle.cjs +2 -0
- package/dist/cjs/lib/arrays/sort.cjs +11 -3
- package/dist/cjs/lib/arrays/split-array.cjs +2 -0
- package/dist/cjs/lib/arrays/unique.cjs +2 -0
- package/dist/cjs/lib/auth/index.cjs +35 -3
- package/dist/cjs/lib/auth/route-manager.cjs +2 -0
- package/dist/cjs/lib/checks.cjs +2 -0
- package/dist/cjs/lib/date/days.cjs +3 -1
- package/dist/cjs/lib/date/index.cjs +190 -7
- package/dist/cjs/lib/date/months.cjs +3 -1
- package/dist/cjs/lib/date/time.cjs +14 -2
- package/dist/cjs/lib/form/form-data.cjs +2 -0
- package/dist/cjs/lib/form/index.cjs +104 -5
- package/dist/cjs/lib/form/sanitize.cjs +2 -0
- package/dist/cjs/lib/functions/callback.cjs +2 -0
- package/dist/cjs/lib/functions/debounce.cjs +2 -0
- package/dist/cjs/lib/functions/env.cjs +2 -0
- package/dist/cjs/lib/functions/functional.cjs +2 -0
- package/dist/cjs/lib/functions/index.cjs +124 -11
- package/dist/cjs/lib/functions/throttle.cjs +2 -0
- package/dist/cjs/lib/functions/timeout.cjs +2 -0
- package/dist/cjs/lib/hash.cjs +2 -0
- package/dist/cjs/lib/index.cjs +1160 -29
- package/dist/cjs/lib/numbers/index.cjs +17 -4
- package/dist/cjs/lib/numbers/math.cjs +2 -0
- package/dist/cjs/lib/objects/camelcase-keys.cjs +45 -4
- package/dist/cjs/lib/objects/empty.cjs +2 -0
- package/dist/cjs/lib/objects/equal.cjs +2 -0
- package/dist/cjs/lib/objects/extend.cjs +117 -6
- package/dist/cjs/lib/objects/flatten.cjs +11 -3
- package/dist/cjs/lib/objects/index.cjs +360 -27
- package/dist/cjs/lib/objects/json.cjs +2 -0
- package/dist/cjs/lib/objects/loop.cjs +2 -0
- package/dist/cjs/lib/objects/mix/mix.cjs +5 -3
- package/dist/cjs/lib/objects/nested-property.cjs +2 -0
- package/dist/cjs/lib/objects/normalize-object.cjs +78 -4
- package/dist/cjs/lib/objects/omit-empty.cjs +2 -0
- package/dist/cjs/lib/objects/size.cjs +2 -0
- package/dist/cjs/lib/objects/split.cjs +2 -0
- package/dist/cjs/lib/promises/index.cjs +51 -3
- package/dist/cjs/lib/promises/reject.cjs +19 -2
- package/dist/cjs/lib/sse.cjs +29 -4
- package/dist/cjs/lib/strings/convert-case/convert-case.cjs +2 -0
- package/dist/cjs/lib/strings/index.cjs +179 -11
- package/dist/cjs/lib/strings/markdown.cjs +3 -1
- package/dist/cjs/lib/strings/name.cjs +2 -0
- package/dist/cjs/lib/strings/pluralize.cjs +3 -1
- package/dist/cjs/lib/strings/query-string.cjs +2 -0
- package/dist/cjs/lib/style/index.cjs +31 -2
- package/dist/cjs/lib/symbols/index.cjs +22 -3
- package/dist/cjs/lib/symbols/symbols.cjs +2 -0
- package/dist/cjs/node/context.cjs +0 -0
- package/dist/cjs/node/dirname.cjs +4 -2
- package/dist/cjs/node/file-cache.cjs +45 -3
- package/dist/cjs/node/file.cjs +4 -2
- package/dist/cjs/node/hash.cjs +3 -1
- package/dist/cjs/node/index.cjs +278 -15
- package/dist/cjs/node/pkce.cjs +20 -8
- package/dist/cjs/node/random-string.cjs +3 -1
- package/dist/cjs/node/sanitize.cjs +27 -3
- package/dist/cjs/node/uuid.cjs +2 -0
- package/dist/esm/node/context.js +0 -0
- package/dist/esm/node/file-cache.js +1 -1
- package/dist/esm/node/pkce.js +3 -2
- package/dist/types/node/context.d.cts +2 -0
- package/dist/types/node/index.d.cts +1 -1
- package/dist/types/node/pkce.d.cts +7 -1
- package/package.json +5 -2
- package/CHANGELOG.md +0 -231
- package/eslint.config.js +0 -2
- package/src/dom/accessibility.js +0 -58
- package/src/dom/actions/index.js +0 -3
- package/src/dom/actions/masonry.js +0 -43
- package/src/dom/actions/prefer-horizontal-scroll.js +0 -121
- package/src/dom/actions/sticky.js +0 -85
- package/src/dom/bounding-box.js +0 -82
- package/src/dom/clipboard.js +0 -14
- package/src/dom/cookie.js +0 -32
- package/src/dom/css-vars.js +0 -19
- package/src/dom/events.js +0 -71
- package/src/dom/focusable.js +0 -165
- package/src/dom/font-size.js +0 -40
- package/src/dom/get-element.js +0 -176
- package/src/dom/hash.js +0 -9
- package/src/dom/index.js +0 -23
- package/src/dom/keyboard.js +0 -44
- package/src/dom/local-store.js +0 -66
- package/src/dom/media.js +0 -30
- package/src/dom/observers/index.js +0 -4
- package/src/dom/observers/intersection-observer.js +0 -43
- package/src/dom/observers/mutation-observer.js +0 -51
- package/src/dom/observers/observer.js +0 -18
- package/src/dom/observers/resize-observer.js +0 -66
- package/src/dom/observers/scroll-observer.js +0 -146
- package/src/dom/pkce.js +0 -34
- package/src/dom/query-params.js +0 -14
- package/src/dom/random-string.js +0 -18
- package/src/dom/random-string.test.js +0 -13
- package/src/dom/sanitize.js +0 -16
- package/src/dom/session-store.js +0 -29
- package/src/dom/spam-prevention.js +0 -40
- package/src/dom/trap-focus.js +0 -70
- package/src/dom/ui/aria-current.js +0 -20
- package/src/dom/ui/inconsistent-button-fix.js +0 -20
- package/src/dom/ui/index.js +0 -4
- package/src/dom/ui/scroll-container.js +0 -25
- package/src/dom/ui/traverse-and-scramble.js +0 -61
- package/src/lib/arrays/index.js +0 -6
- package/src/lib/arrays/item-position.js +0 -23
- package/src/lib/arrays/join.js +0 -20
- package/src/lib/arrays/shuffle.js +0 -21
- package/src/lib/arrays/sort.js +0 -88
- package/src/lib/arrays/sort.spec.js +0 -123
- package/src/lib/arrays/split-array.js +0 -15
- package/src/lib/arrays/unique.js +0 -3
- package/src/lib/auth/index.js +0 -1
- package/src/lib/auth/route-manager.js +0 -45
- package/src/lib/checks.js +0 -57
- package/src/lib/date/days.js +0 -9
- package/src/lib/date/index.js +0 -3
- package/src/lib/date/months.js +0 -74
- package/src/lib/date/time.js +0 -83
- package/src/lib/form/form-data.js +0 -73
- package/src/lib/form/index.js +0 -2
- package/src/lib/form/sanitize.js +0 -80
- package/src/lib/form/sanitize.spec.js +0 -126
- package/src/lib/functions/callback.js +0 -8
- package/src/lib/functions/debounce.js +0 -18
- package/src/lib/functions/env.js +0 -5
- package/src/lib/functions/functional.js +0 -113
- package/src/lib/functions/functional.test.js +0 -196
- package/src/lib/functions/index.js +0 -5
- package/src/lib/functions/throttle.js +0 -11
- package/src/lib/functions/timeout.js +0 -15
- package/src/lib/hash.js +0 -18
- package/src/lib/hash.spec.js +0 -163
- package/src/lib/index.js +0 -14
- package/src/lib/numbers/index.js +0 -12
- package/src/lib/numbers/math.js +0 -9
- package/src/lib/numbers/split-unit.test.js +0 -45
- package/src/lib/objects/camelcase-keys.js +0 -17
- package/src/lib/objects/camelcase-keys.test.js +0 -72
- package/src/lib/objects/empty.js +0 -10
- package/src/lib/objects/equal.js +0 -9
- package/src/lib/objects/extend.js +0 -16
- package/src/lib/objects/extend.test.js +0 -35
- package/src/lib/objects/flatten.js +0 -19
- package/src/lib/objects/index.js +0 -13
- package/src/lib/objects/json.js +0 -7
- package/src/lib/objects/loop.js +0 -11
- package/src/lib/objects/loop.test.js +0 -31
- package/src/lib/objects/mix/mix.js +0 -191
- package/src/lib/objects/mix/mix.md +0 -78
- package/src/lib/objects/mix/mix.test.js +0 -445
- package/src/lib/objects/nested-property.js +0 -41
- package/src/lib/objects/normalize-object.js +0 -10
- package/src/lib/objects/omit-empty.js +0 -23
- package/src/lib/objects/omit-empty.test.js +0 -85
- package/src/lib/objects/size.js +0 -41
- package/src/lib/objects/split.js +0 -19
- package/src/lib/promises/index.js +0 -1
- package/src/lib/promises/reject.js +0 -17
- package/src/lib/sse.js +0 -61
- package/src/lib/strings/convert-case/convert-case.js +0 -86
- package/src/lib/strings/convert-case/convert-case.md +0 -44
- package/src/lib/strings/convert-case/convert-case.test.js +0 -50
- package/src/lib/strings/index.js +0 -5
- package/src/lib/strings/markdown.js +0 -71
- package/src/lib/strings/name.js +0 -24
- package/src/lib/strings/name.test.js +0 -67
- package/src/lib/strings/pluralize.js +0 -2
- package/src/lib/strings/query-string.js +0 -18
- package/src/lib/style/index.js +0 -13
- package/src/lib/symbols/index.js +0 -1
- package/src/lib/symbols/symbols.js +0 -9
- package/src/node/dirname.js +0 -17
- package/src/node/file-cache.js +0 -184
- package/src/node/file.js +0 -13
- package/src/node/hash.js +0 -5
- package/src/node/index.js +0 -7
- package/src/node/pkce.js +0 -33
- package/src/node/random-string.js +0 -10
- package/src/node/random-string.test.js +0 -15
- package/src/node/sanitize.js +0 -13
- package/src/node/sanitize.spec.js +0 -142
- package/src/node/uuid.js +0 -5
- package/tsconfig.json +0 -23
- package/tsup.config.js +0 -38
- package/tsup.config.mjs +0 -45
package/dist/cjs/dom/index.cjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
5
11
|
var __copyProps = (to, from, except, desc) => {
|
|
6
12
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
13
|
for (let key of __getOwnPropNames(from))
|
|
@@ -10,56 +16,1252 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
10
16
|
}
|
|
11
17
|
return to;
|
|
12
18
|
};
|
|
13
|
-
var
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
14
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/dom/index.js
|
|
15
30
|
var dom_exports = {};
|
|
31
|
+
__export(dom_exports, {
|
|
32
|
+
Focusable: () => Focusable,
|
|
33
|
+
PKCE: () => PKCE,
|
|
34
|
+
addListeners: () => addListeners,
|
|
35
|
+
boundingBox: () => boundingBox,
|
|
36
|
+
boundingBoxRelativeToAncestor: () => boundingBoxRelativeToAncestor,
|
|
37
|
+
checkForAccessibleName: () => checkForAccessibleName,
|
|
38
|
+
cookies: () => cookies,
|
|
39
|
+
copyRichText: () => copyRichText,
|
|
40
|
+
dispatchEvent: () => dispatchEvent,
|
|
41
|
+
em: () => em,
|
|
42
|
+
findScrollContainer: () => findScrollContainer,
|
|
43
|
+
getAncestorWithSiblings: () => getAncestorWithSiblings,
|
|
44
|
+
getCSSValue: () => getCSSValue,
|
|
45
|
+
getCSSVar: () => getCSSVar,
|
|
46
|
+
getChildrenElements: () => getChildrenElements,
|
|
47
|
+
getCookie: () => getCookie,
|
|
48
|
+
getElement: () => getElement,
|
|
49
|
+
getFocusableElements: () => getFocusableElements,
|
|
50
|
+
getNodeType: () => getNodeType,
|
|
51
|
+
getParentElement: () => getParentElement,
|
|
52
|
+
getSelfIndex: () => getSelfIndex,
|
|
53
|
+
getSiblingElements: () => getSiblingElements,
|
|
54
|
+
getUnit: () => getUnit,
|
|
55
|
+
hasAccessibleName: () => hasAccessibleName,
|
|
56
|
+
imagesLoaded: () => imagesLoaded,
|
|
57
|
+
inconsistentButtonFix: () => inconsistentButtonFix,
|
|
58
|
+
intersectionObserver: () => intersectionObserver,
|
|
59
|
+
isAncestor: () => isAncestor,
|
|
60
|
+
isArrowKey: () => isArrowKey,
|
|
61
|
+
isEscapeKey: () => isEscapeKey,
|
|
62
|
+
isInvalidAriaPopup: () => isInvalidAriaPopup,
|
|
63
|
+
isShiftTab: () => isShiftTab,
|
|
64
|
+
isTab: () => isTab,
|
|
65
|
+
isTabKey: () => isTabKey,
|
|
66
|
+
lh: () => lh,
|
|
67
|
+
localStore: () => localStore,
|
|
68
|
+
manageFocus: () => manageFocus,
|
|
69
|
+
markActiveAnchorIn: () => markActiveAnchorIn,
|
|
70
|
+
masonry: () => masonry,
|
|
71
|
+
mediaLoaded: () => mediaLoaded,
|
|
72
|
+
mutationObserver: () => mutationObserver,
|
|
73
|
+
preferHorizontalScroll: () => preferHorizontalScroll,
|
|
74
|
+
preventSpam: () => preventSpam,
|
|
75
|
+
queryParams: () => queryParams,
|
|
76
|
+
randomString: () => randomString,
|
|
77
|
+
rem: () => rem,
|
|
78
|
+
removeListeners: () => removeListeners,
|
|
79
|
+
resizeObserver: () => resizeObserver,
|
|
80
|
+
rlh: () => rlh,
|
|
81
|
+
sanitize: () => sanitize2,
|
|
82
|
+
scrollObserver: () => scrollObserver,
|
|
83
|
+
scrollToElement: () => scrollToElement,
|
|
84
|
+
sessionStore: () => sessionStore,
|
|
85
|
+
setCSSValue: () => setCSSValue,
|
|
86
|
+
setCSSVar: () => setCSSVar,
|
|
87
|
+
sha256Hash: () => sha256Hash,
|
|
88
|
+
sticky: () => sticky,
|
|
89
|
+
toPx: () => toPx,
|
|
90
|
+
trapFocus: () => trapFocus,
|
|
91
|
+
traverseAndScramble: () => traverseAndScramble,
|
|
92
|
+
updateEvent: () => updateEvent,
|
|
93
|
+
uuid: () => uuid,
|
|
94
|
+
videosLoaded: () => videosLoaded
|
|
95
|
+
});
|
|
16
96
|
module.exports = __toCommonJS(dom_exports);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
97
|
+
|
|
98
|
+
// src/dom/accessibility.js
|
|
99
|
+
function hasAccessibleName(label, labelledBy) {
|
|
100
|
+
if (label || labelledBy) return true;
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
function checkForAccessibleName({
|
|
104
|
+
name,
|
|
105
|
+
ariaLabel,
|
|
106
|
+
ariaLabelledBy,
|
|
107
|
+
severity = "warn"
|
|
108
|
+
} = {}) {
|
|
109
|
+
if (ariaLabel || ariaLabelledBy) return true;
|
|
110
|
+
const message = `${name} is missing an accessible name. Please provide an accessible name with 'aria-label' or 'aria-labelledby'.`;
|
|
111
|
+
if (severity === "warn") console.warn(message);
|
|
112
|
+
if (severity === "error") console.error(message);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
function isInvalidAriaPopup(value) {
|
|
116
|
+
const allowedPopoupValues = ["dialog", "menu", "listbox", "grid", "tree"];
|
|
117
|
+
if (!allowedPopoupValues.includes(value)) return true;
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/dom/get-element.js
|
|
122
|
+
var astroNodes = ["ASTRO-SLOT", "ASTRO-ISLAND"];
|
|
123
|
+
function getNodeType(node) {
|
|
124
|
+
if (node instanceof Element) return "element";
|
|
125
|
+
if (node instanceof NodeList) return "nodelist";
|
|
126
|
+
if (Array.isArray(node)) return "array";
|
|
127
|
+
}
|
|
128
|
+
function getElement(selector) {
|
|
129
|
+
if (!selector) return;
|
|
130
|
+
if (selector instanceof Element) return selector;
|
|
131
|
+
return document.querySelector(selector);
|
|
132
|
+
}
|
|
133
|
+
function getChildrenElements(node) {
|
|
134
|
+
let children = node.children;
|
|
135
|
+
if (children[0]?.nodeName === "ASTRO-SLOT") children = children[0].children;
|
|
136
|
+
return Array.from(children);
|
|
137
|
+
}
|
|
138
|
+
function getParentElement(element) {
|
|
139
|
+
const parent = element.parentElement;
|
|
140
|
+
if (astroNodes.includes(parent.nodeName)) return getParentElement(parent);
|
|
141
|
+
return parent;
|
|
142
|
+
}
|
|
143
|
+
function getSiblingElements(element) {
|
|
144
|
+
return Array.from(element.parentElement.children).filter(
|
|
145
|
+
(child) => child !== element
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
function getSelfIndex(element) {
|
|
149
|
+
return Array.from(element.parentElement.children).indexOf(element);
|
|
150
|
+
}
|
|
151
|
+
function isAncestor(ancestor, element, { searchLevels = 0 } = {}) {
|
|
152
|
+
if (ancestor === element) return true;
|
|
153
|
+
let parent = element.parentElement;
|
|
154
|
+
if (searchLevels === 0) {
|
|
155
|
+
while (parent) {
|
|
156
|
+
if (ancestor === parent) return true;
|
|
157
|
+
parent = parent.parentElement;
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
for (let i = 0; i < searchLevels; i++) {
|
|
161
|
+
if (ancestor === parent) return true;
|
|
162
|
+
parent = parent.parentElement;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
function getAncestorWithSiblings(element, { limit = false } = {}) {
|
|
168
|
+
const ancestor = element.parentElement;
|
|
169
|
+
const siblings = getSiblingElements(ancestor);
|
|
170
|
+
if (siblings.length) return siblings;
|
|
171
|
+
if (!ancestor) return null;
|
|
172
|
+
if (limit === false) return getAncestorWithSiblings(ancestor);
|
|
173
|
+
if (typeof limit === "number" && limit > 0) {
|
|
174
|
+
return getAncestorWithSiblings(ancestor, { limit: limit - 1 });
|
|
175
|
+
}
|
|
176
|
+
if (limit === 0) return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/dom/media.js
|
|
180
|
+
async function imagesLoaded(node) {
|
|
181
|
+
const images = Array.from(node.querySelectorAll("img"));
|
|
182
|
+
const promises = images.map((img) => {
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
if (img.complete) return resolve();
|
|
185
|
+
img.onload = resolve;
|
|
186
|
+
img.onerror = (e) => {
|
|
187
|
+
reject("Image failed to load");
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
return Promise.all(promises);
|
|
192
|
+
}
|
|
193
|
+
async function videosLoaded(node) {
|
|
194
|
+
const videos = Array.from(node.querySelectorAll("video"));
|
|
195
|
+
const promises = videos.map((video) => {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
if (video.readyState === 4) return resolve();
|
|
198
|
+
video.onloadedmetadata = resolve;
|
|
199
|
+
video.onerror = reject;
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
return Promise.all(promises);
|
|
203
|
+
}
|
|
204
|
+
async function mediaLoaded(node) {
|
|
205
|
+
return Promise.all([imagesLoaded(node), videosLoaded(node)]);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/dom/events.js
|
|
209
|
+
function addListeners(listeners) {
|
|
210
|
+
listeners.forEach(({ node, event, handler }) => {
|
|
211
|
+
node.addEventListener(event, handler);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function removeListeners(listeners) {
|
|
215
|
+
listeners.forEach(({ node, event, handler }) => {
|
|
216
|
+
node.removeEventListener(event, handler);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function dispatchEvent(node, eventName, detail, options = {}) {
|
|
220
|
+
node.dispatchEvent(
|
|
221
|
+
new CustomEvent(eventName, {
|
|
222
|
+
...options,
|
|
223
|
+
detail
|
|
224
|
+
})
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
function updateEvent(event, updates) {
|
|
228
|
+
const { type, ...rest } = event;
|
|
229
|
+
return new CustomEvent(event.type, {
|
|
230
|
+
...rest,
|
|
231
|
+
...updates
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/dom/observers/observer.js
|
|
236
|
+
function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
|
|
237
|
+
const targetType = getNodeType(target);
|
|
238
|
+
if (targetType === "element") observer[method](target, options);
|
|
239
|
+
if (targetType === "nodelist") {
|
|
240
|
+
const elements = Array.from(target);
|
|
241
|
+
elements.forEach((element) => observer[method](element, options));
|
|
242
|
+
}
|
|
243
|
+
if (targetType === "array") {
|
|
244
|
+
target.forEach((element) => observer[method](element, options));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/dom/observers/resize-observer.js
|
|
249
|
+
function resizeObserver(target, options) {
|
|
250
|
+
const { callback, ...opts } = options;
|
|
251
|
+
const observer = new ResizeObserver(observerFn);
|
|
252
|
+
if (target === window || target === document)
|
|
253
|
+
target = document.documentElement;
|
|
254
|
+
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
255
|
+
function observerFn(entries) {
|
|
256
|
+
for (const entry of entries) {
|
|
257
|
+
if (callback) callback({ entry, entries, observer });
|
|
258
|
+
else
|
|
259
|
+
dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
observe(target2) {
|
|
264
|
+
useObserverMethodOnTarget(target2, observer, "observe", options);
|
|
265
|
+
},
|
|
266
|
+
unobserve(target2) {
|
|
267
|
+
useObserverMethodOnTarget(target2, observer, "unobserve");
|
|
268
|
+
},
|
|
269
|
+
disconnect: (_) => observer.disconnect(),
|
|
270
|
+
destroy: (_) => observer.disconnect()
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/dom/actions/masonry.js
|
|
275
|
+
async function masonry(node) {
|
|
276
|
+
if (nativeMasonrySupport(node)) return;
|
|
277
|
+
const colGap = parseFloat(getComputedStyle(node).columnGap);
|
|
278
|
+
const items = getChildrenElements(node);
|
|
279
|
+
node.style.setProperty("row-gap", "1px", "important");
|
|
280
|
+
node.style.gridAutoRows = "0px";
|
|
281
|
+
node.updateMasonryLayout = (_) => layout({ colGap, items });
|
|
282
|
+
try {
|
|
283
|
+
await mediaLoaded(node);
|
|
284
|
+
} catch (e) {
|
|
285
|
+
}
|
|
286
|
+
layout({ colGap, items });
|
|
287
|
+
const obs = resizeObserver(node, {
|
|
288
|
+
async callback(opts) {
|
|
289
|
+
layout({ colGap, items });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
async function layout({ colGap: colGap2, items: items2 }) {
|
|
293
|
+
items2.forEach((item) => {
|
|
294
|
+
const ib = item.getBoundingClientRect();
|
|
295
|
+
item.style.gridRowEnd = `span ${Math.round(ib.height + colGap2)}`;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
destroy() {
|
|
300
|
+
obs.disconnect();
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function nativeMasonrySupport(node) {
|
|
305
|
+
return getComputedStyle(node).gridTemplateRows === "masonry";
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/lib/objects/omit-empty.js
|
|
309
|
+
function omitEmpty(obj, shallow = false) {
|
|
310
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
311
|
+
if (obj instanceof Date) return obj;
|
|
312
|
+
const result = Array.isArray(obj) ? [] : {};
|
|
313
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
314
|
+
if (value === null || value === void 0 || value === "" || typeof value === "object" && !(value instanceof Date) && Object.keys(value).length === 0) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
result[key] = shallow ? value : omitEmpty(value);
|
|
318
|
+
}
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/dom/css-vars.js
|
|
323
|
+
function getCSSValue(element, prop) {
|
|
324
|
+
return getCSSVar(element, prop);
|
|
325
|
+
}
|
|
326
|
+
function setCSSValue(element, prop, value) {
|
|
327
|
+
setCSSVar(element, prop, value);
|
|
328
|
+
}
|
|
329
|
+
function getCSSVar(element, prop) {
|
|
330
|
+
element = getElement(element);
|
|
331
|
+
return getComputedStyle(element).getPropertyValue(prop);
|
|
332
|
+
}
|
|
333
|
+
function setCSSVar(element, prop, value) {
|
|
334
|
+
element = getElement(element);
|
|
335
|
+
element.style.setProperty(prop, value);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/dom/actions/prefer-horizontal-scroll.js
|
|
339
|
+
var DEFAULT_OPTIONS = {
|
|
340
|
+
scrollSnapDelay: 1e3
|
|
341
|
+
};
|
|
342
|
+
function preferHorizontalScroll(node, props = {}) {
|
|
343
|
+
if (!node.classList.contains("scrollable-prefer-horizontal")) return;
|
|
344
|
+
const state = {
|
|
345
|
+
origSnapType: null,
|
|
346
|
+
currentSnapType: null,
|
|
347
|
+
snapTimeoutID: null
|
|
348
|
+
};
|
|
349
|
+
const options = {
|
|
350
|
+
...DEFAULT_OPTIONS,
|
|
351
|
+
...omitEmpty({
|
|
352
|
+
scrollSnapDelay: getCSSVar(node, "--scroll-snap-delay")
|
|
353
|
+
}),
|
|
354
|
+
...omitEmpty(props)
|
|
355
|
+
};
|
|
356
|
+
const listeners = [
|
|
357
|
+
{
|
|
358
|
+
event: "wheel",
|
|
359
|
+
node,
|
|
360
|
+
handler: handleWheel
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
event: "pointerenter",
|
|
364
|
+
node,
|
|
365
|
+
handler: handlePointerEnter
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
event: "pointerleave",
|
|
369
|
+
node,
|
|
370
|
+
handler: handlePointerLeave
|
|
371
|
+
}
|
|
372
|
+
];
|
|
373
|
+
addListeners(listeners);
|
|
374
|
+
function handleWheel(event) {
|
|
375
|
+
const direction = event.deltaY > 0 ? "down" : "up";
|
|
376
|
+
const updatedDelta = event.deltaY;
|
|
377
|
+
if (isTrackpad(event)) return false;
|
|
378
|
+
setCSSVar(node, "--snap-type", "none");
|
|
379
|
+
const scrolledAmount = node.scrollLeft;
|
|
380
|
+
const scrollWidth = node.scrollWidth;
|
|
381
|
+
const clientWidth = node.clientWidth;
|
|
382
|
+
const scrollableAmount = scrollWidth - clientWidth;
|
|
383
|
+
if (direction === "down" && scrolledAmount < scrollableAmount) {
|
|
384
|
+
node.scrollLeft += updatedDelta;
|
|
385
|
+
event.preventDefault();
|
|
386
|
+
}
|
|
387
|
+
if (direction === "up" && scrolledAmount > 0) {
|
|
388
|
+
node.scrollLeft += updatedDelta;
|
|
389
|
+
event.preventDefault();
|
|
390
|
+
}
|
|
391
|
+
const { snapTimeoutID } = state;
|
|
392
|
+
if (snapTimeoutID) clearTimeout(snapTimeoutID);
|
|
393
|
+
state.snapTimeoutID = setTimeout((_) => {
|
|
394
|
+
restoreHijackedState(node, state);
|
|
395
|
+
}, options.scrollSnapDelay);
|
|
396
|
+
}
|
|
397
|
+
function handlePointerEnter(event) {
|
|
398
|
+
state.origSnapType = getCSSVar(node, "--snap-type") || "proximity";
|
|
399
|
+
}
|
|
400
|
+
function handlePointerLeave(event) {
|
|
401
|
+
restoreHijackedState(node, state);
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
destroy() {
|
|
405
|
+
removeListeners(listeners);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function restoreHijackedState(node, state) {
|
|
410
|
+
const scrollLeft = node.scrollLeft;
|
|
411
|
+
setCSSVar(node, "--snap-type", state.origSnapType);
|
|
412
|
+
const finalScrollLeft = node.scrollLeft;
|
|
413
|
+
setCSSVar(node, "--snap-type", "none");
|
|
414
|
+
node.scrollTo({ left: scrollLeft, behavior: "instant" });
|
|
415
|
+
node.scrollTo({ left: finalScrollLeft, behavior: "smooth" });
|
|
416
|
+
setTimeout((_) => {
|
|
417
|
+
setCSSVar(node, "--snap-type", state.origSnapType);
|
|
418
|
+
}, 250);
|
|
419
|
+
}
|
|
420
|
+
function isTrackpad(event) {
|
|
421
|
+
if (event.wheelDeltaY === event.deltaY * -3) return true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/dom/bounding-box.js
|
|
425
|
+
function boundingBox(element, { containsPadding = true } = {}) {
|
|
426
|
+
const box = element.getBoundingClientRect();
|
|
427
|
+
const ret = {};
|
|
428
|
+
for (const prop in box) ret[prop] = box[prop];
|
|
429
|
+
if (!containsPadding) {
|
|
430
|
+
const style = getComputedStyle(element);
|
|
431
|
+
const paddingTop = parseFloat(style.paddingTop);
|
|
432
|
+
const paddingRight = parseFloat(style.paddingRight);
|
|
433
|
+
const paddingBottom = parseFloat(style.paddingBottom);
|
|
434
|
+
const paddingLeft = parseFloat(style.paddingLeft);
|
|
435
|
+
ret.x = ret.x + paddingLeft;
|
|
436
|
+
ret.y = ret.y + paddingTop;
|
|
437
|
+
ret.width = ret.width - paddingLeft - paddingRight;
|
|
438
|
+
ret.height = ret.height - paddingTop - paddingBottom;
|
|
439
|
+
ret.top = ret.top + paddingTop;
|
|
440
|
+
ret.bottom = ret.bottom - paddingBottom;
|
|
441
|
+
ret.right = ret.right - paddingRight;
|
|
442
|
+
ret.left = ret.left + paddingLeft;
|
|
443
|
+
}
|
|
444
|
+
ret.xCenter = (ret.left + ret.right) / 2;
|
|
445
|
+
ret.yCenter = (ret.top + ret.bottom) / 2;
|
|
446
|
+
return ret;
|
|
447
|
+
}
|
|
448
|
+
function boundingBoxRelativeToAncestor({ element, ancestorElement }) {
|
|
449
|
+
ancestorElement = ancestorElement || element.parentElement;
|
|
450
|
+
const box = boundingBox(element);
|
|
451
|
+
const ancestorBox = boundingBox(ancestorElement, {
|
|
452
|
+
containsPadding: false
|
|
453
|
+
});
|
|
454
|
+
return {
|
|
455
|
+
top: box.top - ancestorBox.top,
|
|
456
|
+
right: box.right - ancestorBox.right,
|
|
457
|
+
bottom: box.bottom - ancestorBox.bottom,
|
|
458
|
+
left: box.left - ancestorBox.left,
|
|
459
|
+
width: box.width,
|
|
460
|
+
height: box.height,
|
|
461
|
+
xCenter: (box.left + box.right) / 2 - ancestorBox.left,
|
|
462
|
+
yCenter: (box.top + box.bottom) / 2 - ancestorBox.top
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/dom/ui/scroll-container.js
|
|
467
|
+
function findScrollContainer(element, direction = "both") {
|
|
468
|
+
if (!element) return;
|
|
469
|
+
let parent = element.parentElement;
|
|
470
|
+
while (parent) {
|
|
471
|
+
const { overflow, overflowX, overflowY } = getComputedStyle(parent);
|
|
472
|
+
if (direction === "both") {
|
|
473
|
+
if (overflow.includes("auto") || overflow.includes("scroll"))
|
|
474
|
+
return parent;
|
|
475
|
+
}
|
|
476
|
+
if (direction === "horizontal") {
|
|
477
|
+
if (overflowX === "auto" || overflowX === "scroll") return parent;
|
|
478
|
+
}
|
|
479
|
+
if (direction === "vertical") {
|
|
480
|
+
if (overflowY === "auto" || overflowY === "scroll") return parent;
|
|
481
|
+
}
|
|
482
|
+
parent = parent.parentElement;
|
|
483
|
+
}
|
|
484
|
+
return document.documentElement;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/dom/actions/sticky.js
|
|
488
|
+
function sticky(node, props = {}) {
|
|
489
|
+
const scrollContainer = findScrollContainer(node);
|
|
490
|
+
let stickyTBLR = getComputedTBLR(node);
|
|
491
|
+
const obs = resizeObserver(node, {
|
|
492
|
+
callback: ({ entry }) => {
|
|
493
|
+
stickyTBLR = getComputedTBLR(node);
|
|
494
|
+
isSticking();
|
|
495
|
+
scrollContainer === document.documentElement ? window.addEventListener("scroll", scrollEventListener) : scrollContainer.addEventListener("scroll", scrollEventListener);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
function scrollEventListener(event) {
|
|
499
|
+
isSticking();
|
|
500
|
+
}
|
|
501
|
+
function isSticking() {
|
|
502
|
+
const { top, bottom, left, right } = stickyTBLR;
|
|
503
|
+
const relativeRect = boundingBoxRelativeToAncestor({
|
|
504
|
+
element: node,
|
|
505
|
+
ancestorElement: scrollContainer
|
|
506
|
+
});
|
|
507
|
+
if (!isNaN(top)) {
|
|
508
|
+
if (relativeRect.top - top <= 1) {
|
|
509
|
+
node.classList.add("sticking");
|
|
510
|
+
} else {
|
|
511
|
+
node.classList.remove("sticking");
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (!isNaN(bottom)) {
|
|
515
|
+
if (relativeRect.bottom + bottom >= -1) {
|
|
516
|
+
node.classList.add("sticking");
|
|
517
|
+
} else {
|
|
518
|
+
node.classList.remove("sticking");
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (!isNaN(left)) {
|
|
522
|
+
if (relativeRect.left - left <= 1) {
|
|
523
|
+
node.classList.add("sticking");
|
|
524
|
+
} else {
|
|
525
|
+
node.classList.remove("sticking");
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (!isNaN(right)) {
|
|
529
|
+
if (relativeRect.right + right >= -1) {
|
|
530
|
+
node.classList.add("sticking");
|
|
531
|
+
} else {
|
|
532
|
+
node.classList.remove("sticking");
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
destroy() {
|
|
538
|
+
obs.disconnect();
|
|
539
|
+
scrollContainer.removeEventListener("scroll", scrollEventListener);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function getComputedTBLR(element) {
|
|
544
|
+
const style = getComputedStyle(element);
|
|
545
|
+
return {
|
|
546
|
+
top: parseFloat(style.top),
|
|
547
|
+
bottom: parseFloat(style.bottom),
|
|
548
|
+
left: parseFloat(style.left),
|
|
549
|
+
right: parseFloat(style.right)
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/dom/clipboard.js
|
|
554
|
+
function copyRichText(element) {
|
|
555
|
+
const range = document.createRange();
|
|
556
|
+
range.selectNode(element);
|
|
557
|
+
const selection = window.getSelection();
|
|
558
|
+
selection.removeAllRanges();
|
|
559
|
+
selection.addRange(range);
|
|
560
|
+
document.execCommand("copy");
|
|
561
|
+
selection.removeAllRanges();
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// src/dom/cookie.js
|
|
565
|
+
var cookies = {
|
|
566
|
+
get(name) {
|
|
567
|
+
return getCookie(name);
|
|
568
|
+
},
|
|
569
|
+
set(name, value, days) {
|
|
570
|
+
setCookie(name, value, days);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
function getCookie(name) {
|
|
574
|
+
const match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
|
|
575
|
+
if (!match) return null;
|
|
576
|
+
const decoded = decodeURIComponent(match[2]);
|
|
577
|
+
try {
|
|
578
|
+
return JSON.parse(decoded);
|
|
579
|
+
} catch (e) {
|
|
580
|
+
return decoded;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function setCookie(name, value, days) {
|
|
584
|
+
let expires = "";
|
|
585
|
+
if (days) {
|
|
586
|
+
const date = /* @__PURE__ */ new Date();
|
|
587
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
|
|
588
|
+
expires = "; expires=" + date.toUTCString();
|
|
589
|
+
}
|
|
590
|
+
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/dom/focusable.js
|
|
594
|
+
function getFocusableElements(container = document.body) {
|
|
595
|
+
return {
|
|
596
|
+
/**
|
|
597
|
+
* Gets the number of keyboard focusable elements.
|
|
598
|
+
* This is useful for checking if there are any focusable elements
|
|
599
|
+
* before attempting to focus them.
|
|
600
|
+
*
|
|
601
|
+
* @returns {number} The number of keyboard focusable elements
|
|
602
|
+
*/
|
|
603
|
+
get length() {
|
|
604
|
+
return this.keyboard.length;
|
|
605
|
+
},
|
|
606
|
+
/**
|
|
607
|
+
* Gets all focusable elements within the container that are visible and enabled.
|
|
608
|
+
* This includes elements that can be focused via mouse or programmatically,
|
|
609
|
+
* but may not be keyboard focusable.
|
|
610
|
+
*
|
|
611
|
+
* Elements are considered focusable if they:
|
|
612
|
+
* - Are not disabled
|
|
613
|
+
* - Are not hidden
|
|
614
|
+
* - Are not display:none
|
|
615
|
+
*
|
|
616
|
+
* @returns {HTMLElement[]} Array of focusable elements that are visible and enabled
|
|
617
|
+
*/
|
|
618
|
+
get all() {
|
|
619
|
+
const elements = Array.from(
|
|
620
|
+
container.querySelectorAll(
|
|
621
|
+
`a,
|
|
622
|
+
button,
|
|
623
|
+
input,
|
|
624
|
+
textarea,
|
|
625
|
+
select,
|
|
626
|
+
details,
|
|
627
|
+
iframe,
|
|
628
|
+
embed,
|
|
629
|
+
object,
|
|
630
|
+
summary,
|
|
631
|
+
dialog,
|
|
632
|
+
audio[controls],
|
|
633
|
+
video[controls],
|
|
634
|
+
[contenteditable],
|
|
635
|
+
[tabindex]
|
|
636
|
+
`
|
|
637
|
+
)
|
|
638
|
+
);
|
|
639
|
+
return elements.filter((el) => {
|
|
640
|
+
if (el.hasAttribute("disabled")) return false;
|
|
641
|
+
if (el.hasAttribute("hidden")) return false;
|
|
642
|
+
if (window.getComputedStyle(el).display === "none") return false;
|
|
643
|
+
return true;
|
|
644
|
+
});
|
|
645
|
+
},
|
|
646
|
+
/**
|
|
647
|
+
* Gets elements that can be focused via keyboard (tabIndex > -1).
|
|
648
|
+
* These are the elements that will be focused when using the Tab key.
|
|
649
|
+
*
|
|
650
|
+
* @returns {HTMLElement[]} Array of keyboard focusable elements
|
|
651
|
+
*/
|
|
652
|
+
get keyboard() {
|
|
653
|
+
return this.all.filter((el) => el instanceof HTMLElement && el.tabIndex > -1);
|
|
654
|
+
},
|
|
655
|
+
/**
|
|
656
|
+
* Alias for keyboard focusable elements.
|
|
657
|
+
* This is provided for semantic clarity in certain contexts.
|
|
658
|
+
*
|
|
659
|
+
* @returns {HTMLElement[]} Array of keyboard focusable elements
|
|
660
|
+
*/
|
|
661
|
+
get keyboardOnly() {
|
|
662
|
+
return this.keyboard;
|
|
663
|
+
},
|
|
664
|
+
/**
|
|
665
|
+
* Gets the first keyboard focusable element.
|
|
666
|
+
* This is useful for setting initial focus when opening a modal or dialog.
|
|
667
|
+
*
|
|
668
|
+
* @returns {HTMLElement|null} The first focusable element or null if none exist
|
|
669
|
+
*/
|
|
670
|
+
get first() {
|
|
671
|
+
return this.keyboard[0] || null;
|
|
672
|
+
},
|
|
673
|
+
/**
|
|
674
|
+
* Gets the last keyboard focusable element.
|
|
675
|
+
* This is useful for focus trapping when using Shift+Tab.
|
|
676
|
+
*
|
|
677
|
+
* @returns {HTMLElement|null} The last focusable element or null if none exist
|
|
678
|
+
*/
|
|
679
|
+
get last() {
|
|
680
|
+
return this.keyboard[this.length - 1] || null;
|
|
681
|
+
},
|
|
682
|
+
/**
|
|
683
|
+
* Gets the next focusable element after the given index.
|
|
684
|
+
* This is useful for implementing custom tab order or focus management.
|
|
685
|
+
*
|
|
686
|
+
* @param {number} index - The current element's index in the keyboard focusable array
|
|
687
|
+
* @returns {HTMLElement|null} The next focusable element or null if none exists
|
|
688
|
+
*/
|
|
689
|
+
next(index) {
|
|
690
|
+
return this.keyboard[index + 1] || null;
|
|
691
|
+
},
|
|
692
|
+
/**
|
|
693
|
+
* Gets the previous focusable element before the given index.
|
|
694
|
+
* This is useful for implementing custom tab order or focus management.
|
|
695
|
+
*
|
|
696
|
+
* @param {number} index - The current element's index in the keyboard focusable array
|
|
697
|
+
* @returns {HTMLElement|null} The previous focusable element or null if none exists
|
|
698
|
+
*/
|
|
699
|
+
prev(index) {
|
|
700
|
+
return this.keyboard[index - 1] || null;
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function Focusable(container = document.body) {
|
|
705
|
+
return getFocusableElements(container);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// src/lib/numbers/index.js
|
|
709
|
+
function splitUnit(string) {
|
|
710
|
+
if (typeof string === "number") return [string, null];
|
|
711
|
+
const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
|
|
712
|
+
const match = string.match(regex);
|
|
713
|
+
if (match) return [parseFloat(match[1]), match[2]];
|
|
714
|
+
return [parseFloat(string), null];
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// src/dom/font-size.js
|
|
718
|
+
function getUnit(value) {
|
|
719
|
+
const [, unit] = splitUnit(value);
|
|
720
|
+
return unit;
|
|
721
|
+
}
|
|
722
|
+
function rem(multiple = 1) {
|
|
723
|
+
const value = parseFloat(getComputedStyle(document.body)["font-size"]);
|
|
724
|
+
return Math.round(value * multiple);
|
|
725
|
+
}
|
|
726
|
+
function em(element = document.body, multiple = 1) {
|
|
727
|
+
const value = parseFloat(getComputedStyle(element)["font-size"]);
|
|
728
|
+
return Math.round(value * multiple);
|
|
729
|
+
}
|
|
730
|
+
function rlh(multiple = 1) {
|
|
731
|
+
const lineHeight = parseFloat(getComputedStyle(document.body)["line-height"]);
|
|
732
|
+
return Math.round(lineHeight * multiple);
|
|
733
|
+
}
|
|
734
|
+
function lh(element = document.body, multiple = 1) {
|
|
735
|
+
const lineHeight = getComputedStyle(element)["line-height"];
|
|
736
|
+
const value = parseFloat(lineHeight);
|
|
737
|
+
return Math.round(value * multiple);
|
|
738
|
+
}
|
|
739
|
+
function toPx(value, element = null) {
|
|
740
|
+
const [numeric, unit] = splitUnit(value);
|
|
741
|
+
let finalValue = 0;
|
|
742
|
+
if (unit === "rem") finalValue = rem(numeric);
|
|
743
|
+
if (unit === "em") finalValue = em(element, numeric);
|
|
744
|
+
if (unit === "lh") finalValue = lh(element, numeric);
|
|
745
|
+
if (unit === "px") finalValue = numeric;
|
|
746
|
+
if (!unit) finalValue = numeric;
|
|
747
|
+
return finalValue;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// src/dom/hash.js
|
|
751
|
+
async function sha256Hash(string) {
|
|
752
|
+
const utf8 = new TextEncoder().encode(string);
|
|
753
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", utf8);
|
|
754
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
755
|
+
const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join("");
|
|
756
|
+
return hashHex;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/dom/keyboard.js
|
|
760
|
+
function isTab(event) {
|
|
761
|
+
return !event.shiftKey && event.key === "Tab";
|
|
762
|
+
}
|
|
763
|
+
function isShiftTab(event) {
|
|
764
|
+
return event.shiftKey && event.key === "Tab";
|
|
765
|
+
}
|
|
766
|
+
function isTabKey(key) {
|
|
767
|
+
return key === "Tab";
|
|
768
|
+
}
|
|
769
|
+
function isArrowKey(key) {
|
|
770
|
+
return ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(key);
|
|
771
|
+
}
|
|
772
|
+
function isEscapeKey(key) {
|
|
773
|
+
return key === "Escape";
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// src/dom/local-store.js
|
|
777
|
+
var localStore = {
|
|
778
|
+
/**
|
|
779
|
+
* Retrieves a value from localStorage
|
|
780
|
+
* @param {string} key - The key to retrieve from localStorage
|
|
781
|
+
* @returns {any} The stored value. Returns parsed JSON if the value was stored as JSON. Returns the original string if not JSON, or undefined if key doesn't exist
|
|
782
|
+
*/
|
|
783
|
+
get(key) {
|
|
784
|
+
const value = localStorage.getItem(key);
|
|
785
|
+
if (!value) return;
|
|
786
|
+
try {
|
|
787
|
+
return JSON.parse(value);
|
|
788
|
+
} catch (error) {
|
|
789
|
+
return value;
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
/**
|
|
793
|
+
* Stores a value in localStorage
|
|
794
|
+
* @param {string} key - The key to store the value under
|
|
795
|
+
* @param {any} value - The value to store. Objects will be stringified to JSON
|
|
796
|
+
*/
|
|
797
|
+
set(key, value) {
|
|
798
|
+
if (typeof value === "string") {
|
|
799
|
+
localStorage.setItem(key, value);
|
|
800
|
+
} else {
|
|
801
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
/**
|
|
805
|
+
* Stores multiple key-value pairs in localStorage
|
|
806
|
+
* @param {Object|Map} data - An object or Map containing key-value pairs to store
|
|
807
|
+
*/
|
|
808
|
+
setMultiple(data) {
|
|
809
|
+
for (const [key, value] of Object.entries(data)) {
|
|
810
|
+
this.set(key, value);
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
/**
|
|
814
|
+
* Removes a value from localStorage
|
|
815
|
+
* @param {string} key - The key to remove from localStorage
|
|
816
|
+
*/
|
|
817
|
+
remove(key) {
|
|
818
|
+
localStorage.removeItem(key);
|
|
819
|
+
},
|
|
820
|
+
/**
|
|
821
|
+
* Removes multiple keys from localStorage
|
|
822
|
+
* @param {string[]} keys - Array of keys to remove from localStorage
|
|
823
|
+
*/
|
|
824
|
+
removeMultiple(keys) {
|
|
825
|
+
keys.forEach((key) => this.remove(key));
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
// src/dom/observers/intersection-observer.js
|
|
830
|
+
function intersectionObserver(target, options = {}) {
|
|
831
|
+
const { callback, ...opts } = options;
|
|
832
|
+
const observer = new IntersectionObserver(observerFn, opts);
|
|
833
|
+
useObserverMethodOnTarget(target, observer, "observe");
|
|
834
|
+
function observerFn(entries) {
|
|
835
|
+
for (const entry of entries) {
|
|
836
|
+
if (callback) callback({ entry, entries, observer });
|
|
837
|
+
else dispatchEvent(target, "intersect", { entry, entries, observer });
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return {
|
|
841
|
+
observer,
|
|
842
|
+
observe(target2) {
|
|
843
|
+
useObserverMethodOnTarget(target2, observer, "observe", options);
|
|
844
|
+
},
|
|
845
|
+
unobserve(target2) {
|
|
846
|
+
useObserverMethodOnTarget(target2, observer, "unobserve");
|
|
847
|
+
},
|
|
848
|
+
takeRecords() {
|
|
849
|
+
return observer.takeRecords();
|
|
850
|
+
},
|
|
851
|
+
disconnect() {
|
|
852
|
+
const records = observer.takeRecords();
|
|
853
|
+
observer.disconnect();
|
|
854
|
+
if (records.length > 0) observerFn(records);
|
|
855
|
+
},
|
|
856
|
+
destroy() {
|
|
857
|
+
observer.disconnect();
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// src/dom/observers/mutation-observer.js
|
|
863
|
+
var defaultOptions = {
|
|
864
|
+
attributes: false,
|
|
865
|
+
childList: false,
|
|
866
|
+
subtree: false
|
|
867
|
+
};
|
|
868
|
+
function mutationObserver(target, options) {
|
|
869
|
+
options = { ...defaultOptions, ...options };
|
|
870
|
+
const { callback, ...opts } = options;
|
|
871
|
+
const observer = new MutationObserver(observerFn);
|
|
872
|
+
if (target === window) target = document.body;
|
|
873
|
+
useObserverMethodOnTarget(target, observer, "observe", opts);
|
|
874
|
+
function observerFn(entries) {
|
|
875
|
+
for (const entry of entries) {
|
|
876
|
+
if (callback) callback({ entry, entries, observer });
|
|
877
|
+
else dispatchEvent(target, "mutate", { entry, entries, observer });
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return {
|
|
881
|
+
observer,
|
|
882
|
+
observe(target2) {
|
|
883
|
+
useObserverMethodOnTarget(target2, observer, "observe", options);
|
|
884
|
+
},
|
|
885
|
+
takeRecords() {
|
|
886
|
+
return observer.takeRecords();
|
|
887
|
+
},
|
|
888
|
+
disconnect() {
|
|
889
|
+
const records = observer.takeRecords();
|
|
890
|
+
observer.disconnect();
|
|
891
|
+
if (records.length > 0) observerFn(records);
|
|
892
|
+
},
|
|
893
|
+
destroy() {
|
|
894
|
+
observer.disconnect();
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// src/dom/observers/scroll-observer.js
|
|
900
|
+
var defaultOptions2 = {
|
|
901
|
+
threshold: 0,
|
|
902
|
+
// Float between 0 to 1.
|
|
903
|
+
tolerance: 0.1,
|
|
904
|
+
// Float between 0 to 1. Tolerance for event firing
|
|
905
|
+
once: false
|
|
906
|
+
// Only fire threshold callback once
|
|
907
|
+
};
|
|
908
|
+
function getScrollElement(node) {
|
|
909
|
+
if (node === document || node === window || node === document.documentElement) {
|
|
910
|
+
return document.documentElement;
|
|
911
|
+
}
|
|
912
|
+
return (
|
|
913
|
+
/** @type {Element} */
|
|
914
|
+
node
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
function scrollObserver(node, options = {}) {
|
|
918
|
+
const { callback, onScrollDown, onScrollUp, onEnterThreshold, ...userOpts } = options;
|
|
919
|
+
const opts = { ...defaultOptions2, ...userOpts };
|
|
920
|
+
const { threshold, tolerance, once } = opts;
|
|
921
|
+
let prevScrollDirection = null;
|
|
922
|
+
let prevScrollTop = 0;
|
|
923
|
+
let prevScrollPercent = 0;
|
|
924
|
+
let thresholdFired = false;
|
|
925
|
+
let rafId = null;
|
|
926
|
+
const isDocumentScroll = node === document || node === window || node === document.documentElement;
|
|
927
|
+
const scrollElement = getScrollElement(node);
|
|
928
|
+
const eventTarget = isDocumentScroll ? window : node;
|
|
929
|
+
let cachedScrollHeight = 0;
|
|
930
|
+
let cachedClientHeight = 0;
|
|
931
|
+
updateCache();
|
|
932
|
+
const cacheObserver = resizeObserver(scrollElement, {
|
|
933
|
+
callback: updateCache
|
|
934
|
+
});
|
|
935
|
+
eventTarget.addEventListener("scroll", throttledObserve, { passive: true });
|
|
936
|
+
function throttledObserve() {
|
|
937
|
+
rafId = requestAnimationFrame(observe);
|
|
938
|
+
}
|
|
939
|
+
function updateCache() {
|
|
940
|
+
cachedScrollHeight = scrollElement.scrollHeight;
|
|
941
|
+
cachedClientHeight = scrollElement.clientHeight;
|
|
942
|
+
}
|
|
943
|
+
function observe() {
|
|
944
|
+
const scrollTop = scrollElement.scrollTop;
|
|
945
|
+
if (Math.abs(scrollTop - prevScrollTop) < 1) return;
|
|
946
|
+
const scrollDirection = scrollTop > prevScrollTop ? "down" : "up";
|
|
947
|
+
const maxScroll = Math.max(1, cachedScrollHeight - cachedClientHeight);
|
|
948
|
+
const scrollPercent = Math.min(1, Math.max(0, scrollTop / maxScroll));
|
|
949
|
+
const thresholdMin = threshold - tolerance / 2;
|
|
950
|
+
const thresholdMax = threshold + tolerance / 2;
|
|
951
|
+
const wasInThreshold = prevScrollPercent >= thresholdMin && prevScrollPercent <= thresholdMax;
|
|
952
|
+
const isInThreshold = scrollPercent >= thresholdMin && scrollPercent <= thresholdMax;
|
|
953
|
+
const hasEnteredThreshold = !wasInThreshold && isInThreshold && (!once || !thresholdFired);
|
|
954
|
+
if (hasEnteredThreshold && once) {
|
|
955
|
+
thresholdFired = true;
|
|
956
|
+
}
|
|
957
|
+
const callbackData = {
|
|
958
|
+
scrollTop,
|
|
959
|
+
scrollDirection,
|
|
960
|
+
scrollPercent,
|
|
961
|
+
directionChanged: scrollDirection !== prevScrollDirection,
|
|
962
|
+
hasEnteredThreshold,
|
|
963
|
+
isInThreshold
|
|
964
|
+
};
|
|
965
|
+
if (typeof callback === "function") {
|
|
966
|
+
callback(callbackData);
|
|
967
|
+
}
|
|
968
|
+
if (scrollDirection !== prevScrollDirection) {
|
|
969
|
+
if (scrollDirection === "down" && typeof onScrollDown === "function") {
|
|
970
|
+
onScrollDown(callbackData);
|
|
971
|
+
}
|
|
972
|
+
if (scrollDirection === "up" && typeof onScrollUp === "function") {
|
|
973
|
+
onScrollUp(callbackData);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (hasEnteredThreshold && typeof onEnterThreshold === "function") {
|
|
977
|
+
onEnterThreshold(callbackData);
|
|
978
|
+
}
|
|
979
|
+
prevScrollTop = scrollTop;
|
|
980
|
+
prevScrollPercent = scrollPercent;
|
|
981
|
+
prevScrollDirection = scrollDirection;
|
|
982
|
+
}
|
|
983
|
+
return {
|
|
984
|
+
destroy() {
|
|
985
|
+
eventTarget.removeEventListener("scroll", throttledObserve);
|
|
986
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
987
|
+
cacheObserver.destroy();
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// src/dom/random-string.js
|
|
993
|
+
function randomString(length = 10) {
|
|
994
|
+
const firstLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
|
|
995
|
+
const others = Math.random().toString(36).substring(2, 2 + length - 1);
|
|
996
|
+
return firstLetter + others;
|
|
997
|
+
}
|
|
998
|
+
function uuid() {
|
|
999
|
+
return crypto.randomUUID();
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// src/dom/pkce.js
|
|
1003
|
+
async function PKCE() {
|
|
1004
|
+
const codeVerifier = await randomString();
|
|
1005
|
+
const codeChallenge = await getCodeChallenge(codeVerifier);
|
|
1006
|
+
return {
|
|
1007
|
+
state: await randomString(),
|
|
1008
|
+
code_verifier: codeVerifier,
|
|
1009
|
+
code_challenge: codeChallenge,
|
|
1010
|
+
code_challenge_method: "S256"
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
async function getCodeChallenge(verifier) {
|
|
1014
|
+
const encoder = new TextEncoder();
|
|
1015
|
+
const data = encoder.encode(verifier);
|
|
1016
|
+
const hashed = await window.crypto.subtle.digest("SHA-256", data);
|
|
1017
|
+
return window.btoa(String.fromCharCode.apply(null, new Uint8Array(hashed))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// src/dom/query-params.js
|
|
1021
|
+
var queryParams = {
|
|
1022
|
+
get(key) {
|
|
1023
|
+
const searchParams = new URLSearchParams(location.search);
|
|
1024
|
+
return searchParams.get(key);
|
|
1025
|
+
},
|
|
1026
|
+
stringify(params) {
|
|
1027
|
+
const searchParams = new URLSearchParams(location.search);
|
|
1028
|
+
return searchParams.toString();
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
// src/dom/sanitize.js
|
|
1033
|
+
var import_dompurify = __toESM(require("dompurify"), 1);
|
|
1034
|
+
|
|
1035
|
+
// src/lib/form/sanitize.js
|
|
1036
|
+
function sanitize(value, options = {}) {
|
|
1037
|
+
const { sanitizer, ...rest } = options;
|
|
1038
|
+
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
1039
|
+
if (typeof value === "string") return sanitizer(value, rest);
|
|
1040
|
+
if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
|
|
1041
|
+
if (value && typeof value === "object") {
|
|
1042
|
+
return Object.fromEntries(
|
|
1043
|
+
Object.entries(value).map(([key, val]) => [
|
|
1044
|
+
key,
|
|
1045
|
+
sanitize(val, { sanitizer, ...rest })
|
|
1046
|
+
])
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
1049
|
+
return value;
|
|
1050
|
+
}
|
|
1051
|
+
function sanitizeArray(arr, { sanitizer, ...rest }) {
|
|
1052
|
+
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
1053
|
+
return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
// src/dom/sanitize.js
|
|
1057
|
+
function sanitize2(value, options = {}) {
|
|
1058
|
+
return sanitize(value, { sanitizer: import_dompurify.default.sanitize, ...options });
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// src/dom/session-store.js
|
|
1062
|
+
var sessionStore = {
|
|
1063
|
+
get(key) {
|
|
1064
|
+
const value = sessionStorage.getItem(key);
|
|
1065
|
+
if (!value) return;
|
|
1066
|
+
try {
|
|
1067
|
+
return JSON.parse(value);
|
|
1068
|
+
} catch (error) {
|
|
1069
|
+
return value;
|
|
1070
|
+
}
|
|
1071
|
+
},
|
|
1072
|
+
set(key, value) {
|
|
1073
|
+
if (typeof value === "string") {
|
|
1074
|
+
sessionStorage.setItem(key, value);
|
|
1075
|
+
} else {
|
|
1076
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
remove(key) {
|
|
1080
|
+
sessionStorage.removeItem(key);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
|
|
1084
|
+
// src/dom/spam-prevention.js
|
|
1085
|
+
function preventSpam(form, { honeypotField = "hp", honeypotDuration = 2e3 } = {}) {
|
|
1086
|
+
const startTime = Date.now();
|
|
1087
|
+
let hasInteraction = false;
|
|
1088
|
+
function checkForInteraction() {
|
|
1089
|
+
hasInteraction = true;
|
|
1090
|
+
}
|
|
1091
|
+
const events = ["keydown", "mousemove", "touchstart", "click"];
|
|
1092
|
+
events.forEach((event) => {
|
|
1093
|
+
form.addEventListener(event, checkForInteraction, { once: true });
|
|
1094
|
+
});
|
|
1095
|
+
form.containsSpam = function() {
|
|
1096
|
+
const fillTime = Date.now() - startTime;
|
|
1097
|
+
const isTooFast = fillTime < honeypotDuration;
|
|
1098
|
+
const honeypotInput = form.querySelector(`[name="${honeypotField}"]`);
|
|
1099
|
+
const hasHoneypotValue = honeypotInput?.value?.trim();
|
|
1100
|
+
const noInteraction = !hasInteraction;
|
|
1101
|
+
events.forEach(
|
|
1102
|
+
(event) => form.removeEventListener(event, checkForInteraction)
|
|
1103
|
+
);
|
|
1104
|
+
return isTooFast || !!hasHoneypotValue || noInteraction;
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// src/dom/trap-focus.js
|
|
1109
|
+
function trapFocus({ event, focusables }) {
|
|
1110
|
+
if (event.key !== "Tab") return;
|
|
1111
|
+
if (isTab(event) && document.activeElement === focusables.last) {
|
|
1112
|
+
event.preventDefault();
|
|
1113
|
+
focusables.first.focus();
|
|
1114
|
+
}
|
|
1115
|
+
if (isShiftTab(event) && document.activeElement === focusables.first) {
|
|
1116
|
+
event.preventDefault();
|
|
1117
|
+
focusables.last.focus();
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
function manageFocus({
|
|
1121
|
+
event,
|
|
1122
|
+
triggerNode,
|
|
1123
|
+
contentNode,
|
|
1124
|
+
focusables,
|
|
1125
|
+
tabOutFocus = "next",
|
|
1126
|
+
// 'trigger'
|
|
1127
|
+
onLeave = function() {
|
|
1128
|
+
}
|
|
1129
|
+
}) {
|
|
1130
|
+
const activeEl = document.activeElement;
|
|
1131
|
+
if (activeEl === contentNode && isShiftTab(event)) return backFocus();
|
|
1132
|
+
if (activeEl === contentNode && focusables.length === 0 && isTab(event))
|
|
1133
|
+
return nextFocus();
|
|
1134
|
+
if (activeEl === focusables.last && isTab(event)) return nextFocus();
|
|
1135
|
+
if (activeEl === focusables.first && isShiftTab(event)) return backFocus();
|
|
1136
|
+
function backFocus() {
|
|
1137
|
+
event.preventDefault();
|
|
1138
|
+
triggerNode.focus();
|
|
1139
|
+
onLeave("back");
|
|
1140
|
+
}
|
|
1141
|
+
function nextFocus() {
|
|
1142
|
+
if (tabOutFocus === "trigger") triggerNode.focus();
|
|
1143
|
+
if (tabOutFocus === "next") {
|
|
1144
|
+
event.preventDefault();
|
|
1145
|
+
const DOMFocusables = getFocusableElements().keyboard;
|
|
1146
|
+
const index = DOMFocusables.findIndex((e) => e === triggerNode);
|
|
1147
|
+
const next = DOMFocusables[index + 1];
|
|
1148
|
+
if (next) next.focus();
|
|
1149
|
+
else triggerNode.focus();
|
|
1150
|
+
}
|
|
1151
|
+
onLeave("forward");
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// src/dom/ui/aria-current.js
|
|
1156
|
+
function markActiveAnchorIn(container, anchorType = "page") {
|
|
1157
|
+
if (!container) return;
|
|
1158
|
+
const { pathname } = window.location;
|
|
1159
|
+
const element = container.querySelector(`[href="${pathname}"]`);
|
|
1160
|
+
if (!element) return;
|
|
1161
|
+
element.setAttribute("aria-current", "page");
|
|
1162
|
+
return element;
|
|
1163
|
+
}
|
|
1164
|
+
function scrollToElement(element, { scrollBehaviour = "instant", scrollMargin = "3rem" } = {}) {
|
|
1165
|
+
if (!element) return;
|
|
1166
|
+
element.style.scrollMarginTop = scrollMargin;
|
|
1167
|
+
element.scrollIntoView({ behavior: scrollBehaviour });
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// src/dom/ui/inconsistent-button-fix.js
|
|
1171
|
+
function inconsistentButtonFix() {
|
|
1172
|
+
document.addEventListener("click", (event) => {
|
|
1173
|
+
if (event.target instanceof HTMLButtonElement) {
|
|
1174
|
+
event.target.focus();
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// src/dom/ui/traverse-and-scramble.js
|
|
1180
|
+
function traverseAndScramble(node, { excludes = [] } = {}) {
|
|
1181
|
+
if (node instanceof Element && excludes.some((selector) => node.matches(selector))) {
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
node.childNodes.forEach((child) => {
|
|
1185
|
+
if (child.nodeType === 3) {
|
|
1186
|
+
child.nodeValue = scrambleText(child.nodeValue);
|
|
1187
|
+
} else if (child.nodeType === 1 && child instanceof Element) {
|
|
1188
|
+
traverseAndScramble(child, { excludes });
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
function scrambleText(text) {
|
|
1193
|
+
return text.split("").map((char) => {
|
|
1194
|
+
if (/^[A-Za-z0-9]$/.test(char)) {
|
|
1195
|
+
const randomCharCode = Math.random() < 26 / 36 ? Math.floor(Math.random() * 26) + (char === char.toUpperCase() ? 65 : 97) : Math.floor(Math.random() * 10) + 48;
|
|
1196
|
+
return String.fromCharCode(randomCharCode);
|
|
1197
|
+
} else {
|
|
1198
|
+
return char;
|
|
1199
|
+
}
|
|
1200
|
+
}).join("");
|
|
1201
|
+
}
|
|
40
1202
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
1203
|
0 && (module.exports = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1204
|
+
Focusable,
|
|
1205
|
+
PKCE,
|
|
1206
|
+
addListeners,
|
|
1207
|
+
boundingBox,
|
|
1208
|
+
boundingBoxRelativeToAncestor,
|
|
1209
|
+
checkForAccessibleName,
|
|
1210
|
+
cookies,
|
|
1211
|
+
copyRichText,
|
|
1212
|
+
dispatchEvent,
|
|
1213
|
+
em,
|
|
1214
|
+
findScrollContainer,
|
|
1215
|
+
getAncestorWithSiblings,
|
|
1216
|
+
getCSSValue,
|
|
1217
|
+
getCSSVar,
|
|
1218
|
+
getChildrenElements,
|
|
1219
|
+
getCookie,
|
|
1220
|
+
getElement,
|
|
1221
|
+
getFocusableElements,
|
|
1222
|
+
getNodeType,
|
|
1223
|
+
getParentElement,
|
|
1224
|
+
getSelfIndex,
|
|
1225
|
+
getSiblingElements,
|
|
1226
|
+
getUnit,
|
|
1227
|
+
hasAccessibleName,
|
|
1228
|
+
imagesLoaded,
|
|
1229
|
+
inconsistentButtonFix,
|
|
1230
|
+
intersectionObserver,
|
|
1231
|
+
isAncestor,
|
|
1232
|
+
isArrowKey,
|
|
1233
|
+
isEscapeKey,
|
|
1234
|
+
isInvalidAriaPopup,
|
|
1235
|
+
isShiftTab,
|
|
1236
|
+
isTab,
|
|
1237
|
+
isTabKey,
|
|
1238
|
+
lh,
|
|
1239
|
+
localStore,
|
|
1240
|
+
manageFocus,
|
|
1241
|
+
markActiveAnchorIn,
|
|
1242
|
+
masonry,
|
|
1243
|
+
mediaLoaded,
|
|
1244
|
+
mutationObserver,
|
|
1245
|
+
preferHorizontalScroll,
|
|
1246
|
+
preventSpam,
|
|
1247
|
+
queryParams,
|
|
1248
|
+
randomString,
|
|
1249
|
+
rem,
|
|
1250
|
+
removeListeners,
|
|
1251
|
+
resizeObserver,
|
|
1252
|
+
rlh,
|
|
1253
|
+
sanitize,
|
|
1254
|
+
scrollObserver,
|
|
1255
|
+
scrollToElement,
|
|
1256
|
+
sessionStore,
|
|
1257
|
+
setCSSValue,
|
|
1258
|
+
setCSSVar,
|
|
1259
|
+
sha256Hash,
|
|
1260
|
+
sticky,
|
|
1261
|
+
toPx,
|
|
1262
|
+
trapFocus,
|
|
1263
|
+
traverseAndScramble,
|
|
1264
|
+
updateEvent,
|
|
1265
|
+
uuid,
|
|
1266
|
+
videosLoaded
|
|
65
1267
|
});
|