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