@splendidlabz/utils 1.10.2 → 1.10.3

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