@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,4 +1,3 @@
1
- // src/dom/keyboard.js
2
1
  function isTab(event) {
3
2
  return !event.shiftKey && event.key === "Tab";
4
3
  }
@@ -1,5 +1,4 @@
1
- // src/dom/local-store.js
2
- var localStore = {
1
+ const localStore = {
3
2
  /**
4
3
  * Retrieves a value from localStorage
5
4
  * @param {string} key - The key to retrieve from localStorage
@@ -1,4 +1,3 @@
1
- // src/dom/media.js
2
1
  async function imagesLoaded(node) {
3
2
  const images = Array.from(node.querySelectorAll("img"));
4
3
  const promises = images.map((img) => {
@@ -1,224 +1,4 @@
1
- // src/dom/events.js
2
- function dispatchEvent(node, eventName, detail, options = {}) {
3
- node.dispatchEvent(
4
- new CustomEvent(eventName, {
5
- ...options,
6
- detail
7
- })
8
- );
9
- }
10
-
11
- // src/dom/get-element.js
12
- function getNodeType(node) {
13
- if (node instanceof Element) return "element";
14
- if (node instanceof NodeList) return "nodelist";
15
- if (Array.isArray(node)) return "array";
16
- }
17
-
18
- // src/dom/observers/observer.js
19
- function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
20
- const targetType = getNodeType(target);
21
- if (targetType === "element") observer[method](target, options);
22
- if (targetType === "nodelist") {
23
- const elements = Array.from(target);
24
- elements.forEach((element) => observer[method](element, options));
25
- }
26
- if (targetType === "array") {
27
- target.forEach((element) => observer[method](element, options));
28
- }
29
- }
30
-
31
- // src/dom/observers/intersection-observer.js
32
- function intersectionObserver(target, options = {}) {
33
- const { callback, ...opts } = options;
34
- const observer = new IntersectionObserver(observerFn, opts);
35
- useObserverMethodOnTarget(target, observer, "observe");
36
- function observerFn(entries) {
37
- for (const entry of entries) {
38
- if (callback) callback({ entry, entries, observer });
39
- else dispatchEvent(target, "intersect", { entry, entries, observer });
40
- }
41
- }
42
- return {
43
- observer,
44
- observe(target2) {
45
- useObserverMethodOnTarget(target2, observer, "observe", options);
46
- },
47
- unobserve(target2) {
48
- useObserverMethodOnTarget(target2, observer, "unobserve");
49
- },
50
- takeRecords() {
51
- return observer.takeRecords();
52
- },
53
- disconnect() {
54
- const records = observer.takeRecords();
55
- observer.disconnect();
56
- if (records.length > 0) observerFn(records);
57
- },
58
- destroy() {
59
- observer.disconnect();
60
- }
61
- };
62
- }
63
-
64
- // src/dom/observers/mutation-observer.js
65
- var defaultOptions = {
66
- attributes: false,
67
- childList: false,
68
- subtree: false
69
- };
70
- function mutationObserver(target, options) {
71
- options = { ...defaultOptions, ...options };
72
- const { callback, ...opts } = options;
73
- const observer = new MutationObserver(observerFn);
74
- if (target === window) target = document.body;
75
- useObserverMethodOnTarget(target, observer, "observe", opts);
76
- function observerFn(entries) {
77
- for (const entry of entries) {
78
- if (callback) callback({ entry, entries, observer });
79
- else dispatchEvent(target, "mutate", { entry, entries, observer });
80
- }
81
- }
82
- return {
83
- observer,
84
- observe(target2) {
85
- useObserverMethodOnTarget(target2, observer, "observe", options);
86
- },
87
- takeRecords() {
88
- return observer.takeRecords();
89
- },
90
- disconnect() {
91
- const records = observer.takeRecords();
92
- observer.disconnect();
93
- if (records.length > 0) observerFn(records);
94
- },
95
- destroy() {
96
- observer.disconnect();
97
- }
98
- };
99
- }
100
-
101
- // src/dom/observers/resize-observer.js
102
- function resizeObserver(target, options) {
103
- const { callback, ...opts } = options;
104
- const observer = new ResizeObserver(observerFn);
105
- if (target === window || target === document)
106
- target = document.documentElement;
107
- useObserverMethodOnTarget(target, observer, "observe", opts);
108
- function observerFn(entries) {
109
- for (const entry of entries) {
110
- if (callback) callback({ entry, entries, observer });
111
- else
112
- dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
113
- }
114
- }
115
- return {
116
- observe(target2) {
117
- useObserverMethodOnTarget(target2, observer, "observe", options);
118
- },
119
- unobserve(target2) {
120
- useObserverMethodOnTarget(target2, observer, "unobserve");
121
- },
122
- disconnect: (_) => observer.disconnect(),
123
- destroy: (_) => observer.disconnect()
124
- };
125
- }
126
-
127
- // src/dom/observers/scroll-observer.js
128
- var defaultOptions2 = {
129
- threshold: 0,
130
- // Float between 0 to 1.
131
- tolerance: 0.1,
132
- // Float between 0 to 1. Tolerance for event firing
133
- once: false
134
- // Only fire threshold callback once
135
- };
136
- function getScrollElement(node) {
137
- if (node === document || node === window || node === document.documentElement) {
138
- return document.documentElement;
139
- }
140
- return (
141
- /** @type {Element} */
142
- node
143
- );
144
- }
145
- function scrollObserver(node, options = {}) {
146
- const { callback, onScrollDown, onScrollUp, onEnterThreshold, ...userOpts } = options;
147
- const opts = { ...defaultOptions2, ...userOpts };
148
- const { threshold, tolerance, once } = opts;
149
- let prevScrollDirection = null;
150
- let prevScrollTop = 0;
151
- let prevScrollPercent = 0;
152
- let thresholdFired = false;
153
- let rafId = null;
154
- const isDocumentScroll = node === document || node === window || node === document.documentElement;
155
- const scrollElement = getScrollElement(node);
156
- const eventTarget = isDocumentScroll ? window : node;
157
- let cachedScrollHeight = 0;
158
- let cachedClientHeight = 0;
159
- updateCache();
160
- const cacheObserver = resizeObserver(scrollElement, {
161
- callback: updateCache
162
- });
163
- eventTarget.addEventListener("scroll", throttledObserve, { passive: true });
164
- function throttledObserve() {
165
- rafId = requestAnimationFrame(observe);
166
- }
167
- function updateCache() {
168
- cachedScrollHeight = scrollElement.scrollHeight;
169
- cachedClientHeight = scrollElement.clientHeight;
170
- }
171
- function observe() {
172
- const scrollTop = scrollElement.scrollTop;
173
- if (Math.abs(scrollTop - prevScrollTop) < 1) return;
174
- const scrollDirection = scrollTop > prevScrollTop ? "down" : "up";
175
- const maxScroll = Math.max(1, cachedScrollHeight - cachedClientHeight);
176
- const scrollPercent = Math.min(1, Math.max(0, scrollTop / maxScroll));
177
- const thresholdMin = threshold - tolerance / 2;
178
- const thresholdMax = threshold + tolerance / 2;
179
- const wasInThreshold = prevScrollPercent >= thresholdMin && prevScrollPercent <= thresholdMax;
180
- const isInThreshold = scrollPercent >= thresholdMin && scrollPercent <= thresholdMax;
181
- const hasEnteredThreshold = !wasInThreshold && isInThreshold && (!once || !thresholdFired);
182
- if (hasEnteredThreshold && once) {
183
- thresholdFired = true;
184
- }
185
- const callbackData = {
186
- scrollTop,
187
- scrollDirection,
188
- scrollPercent,
189
- directionChanged: scrollDirection !== prevScrollDirection,
190
- hasEnteredThreshold,
191
- isInThreshold
192
- };
193
- if (typeof callback === "function") {
194
- callback(callbackData);
195
- }
196
- if (scrollDirection !== prevScrollDirection) {
197
- if (scrollDirection === "down" && typeof onScrollDown === "function") {
198
- onScrollDown(callbackData);
199
- }
200
- if (scrollDirection === "up" && typeof onScrollUp === "function") {
201
- onScrollUp(callbackData);
202
- }
203
- }
204
- if (hasEnteredThreshold && typeof onEnterThreshold === "function") {
205
- onEnterThreshold(callbackData);
206
- }
207
- prevScrollTop = scrollTop;
208
- prevScrollPercent = scrollPercent;
209
- prevScrollDirection = scrollDirection;
210
- }
211
- return {
212
- destroy() {
213
- eventTarget.removeEventListener("scroll", throttledObserve);
214
- if (rafId) cancelAnimationFrame(rafId);
215
- cacheObserver.destroy();
216
- }
217
- };
218
- }
219
- export {
220
- intersectionObserver,
221
- mutationObserver,
222
- resizeObserver,
223
- scrollObserver
224
- };
1
+ export * from "./intersection-observer.js";
2
+ export * from "./mutation-observer.js";
3
+ export * from "./resize-observer.js";
4
+ export * from "./scroll-observer.js";
@@ -1,34 +1,5 @@
1
- // src/dom/events.js
2
- function dispatchEvent(node, eventName, detail, options = {}) {
3
- node.dispatchEvent(
4
- new CustomEvent(eventName, {
5
- ...options,
6
- detail
7
- })
8
- );
9
- }
10
-
11
- // src/dom/get-element.js
12
- function getNodeType(node) {
13
- if (node instanceof Element) return "element";
14
- if (node instanceof NodeList) return "nodelist";
15
- if (Array.isArray(node)) return "array";
16
- }
17
-
18
- // src/dom/observers/observer.js
19
- function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
20
- const targetType = getNodeType(target);
21
- if (targetType === "element") observer[method](target, options);
22
- if (targetType === "nodelist") {
23
- const elements = Array.from(target);
24
- elements.forEach((element) => observer[method](element, options));
25
- }
26
- if (targetType === "array") {
27
- target.forEach((element) => observer[method](element, options));
28
- }
29
- }
30
-
31
- // src/dom/observers/intersection-observer.js
1
+ import { dispatchEvent } from "../events.js";
2
+ import { useObserverMethodOnTarget } from "./observer.js";
32
3
  function intersectionObserver(target, options = {}) {
33
4
  const { callback, ...opts } = options;
34
5
  const observer = new IntersectionObserver(observerFn, opts);
@@ -1,35 +1,6 @@
1
- // src/dom/events.js
2
- function dispatchEvent(node, eventName, detail, options = {}) {
3
- node.dispatchEvent(
4
- new CustomEvent(eventName, {
5
- ...options,
6
- detail
7
- })
8
- );
9
- }
10
-
11
- // src/dom/get-element.js
12
- function getNodeType(node) {
13
- if (node instanceof Element) return "element";
14
- if (node instanceof NodeList) return "nodelist";
15
- if (Array.isArray(node)) return "array";
16
- }
17
-
18
- // src/dom/observers/observer.js
19
- function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
20
- const targetType = getNodeType(target);
21
- if (targetType === "element") observer[method](target, options);
22
- if (targetType === "nodelist") {
23
- const elements = Array.from(target);
24
- elements.forEach((element) => observer[method](element, options));
25
- }
26
- if (targetType === "array") {
27
- target.forEach((element) => observer[method](element, options));
28
- }
29
- }
30
-
31
- // src/dom/observers/mutation-observer.js
32
- var defaultOptions = {
1
+ import { dispatchEvent } from "../events.js";
2
+ import { useObserverMethodOnTarget } from "./observer.js";
3
+ const defaultOptions = {
33
4
  attributes: false,
34
5
  childList: false,
35
6
  subtree: false
@@ -1,11 +1,4 @@
1
- // src/dom/get-element.js
2
- function getNodeType(node) {
3
- if (node instanceof Element) return "element";
4
- if (node instanceof NodeList) return "nodelist";
5
- if (Array.isArray(node)) return "array";
6
- }
7
-
8
- // src/dom/observers/observer.js
1
+ import { getNodeType } from "../get-element.js";
9
2
  function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
10
3
  const targetType = getNodeType(target);
11
4
  if (targetType === "element") observer[method](target, options);
@@ -1,34 +1,5 @@
1
- // src/dom/events.js
2
- function dispatchEvent(node, eventName, detail, options = {}) {
3
- node.dispatchEvent(
4
- new CustomEvent(eventName, {
5
- ...options,
6
- detail
7
- })
8
- );
9
- }
10
-
11
- // src/dom/get-element.js
12
- function getNodeType(node) {
13
- if (node instanceof Element) return "element";
14
- if (node instanceof NodeList) return "nodelist";
15
- if (Array.isArray(node)) return "array";
16
- }
17
-
18
- // src/dom/observers/observer.js
19
- function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
20
- const targetType = getNodeType(target);
21
- if (targetType === "element") observer[method](target, options);
22
- if (targetType === "nodelist") {
23
- const elements = Array.from(target);
24
- elements.forEach((element) => observer[method](element, options));
25
- }
26
- if (targetType === "array") {
27
- target.forEach((element) => observer[method](element, options));
28
- }
29
- }
30
-
31
- // src/dom/observers/resize-observer.js
1
+ import { dispatchEvent } from "../events.js";
2
+ import { useObserverMethodOnTarget } from "./observer.js";
32
3
  function resizeObserver(target, options) {
33
4
  const { callback, ...opts } = options;
34
5
  const observer = new ResizeObserver(observerFn);
@@ -1,61 +1,5 @@
1
- // src/dom/events.js
2
- function dispatchEvent(node, eventName, detail, options = {}) {
3
- node.dispatchEvent(
4
- new CustomEvent(eventName, {
5
- ...options,
6
- detail
7
- })
8
- );
9
- }
10
-
11
- // src/dom/get-element.js
12
- function getNodeType(node) {
13
- if (node instanceof Element) return "element";
14
- if (node instanceof NodeList) return "nodelist";
15
- if (Array.isArray(node)) return "array";
16
- }
17
-
18
- // src/dom/observers/observer.js
19
- function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
20
- const targetType = getNodeType(target);
21
- if (targetType === "element") observer[method](target, options);
22
- if (targetType === "nodelist") {
23
- const elements = Array.from(target);
24
- elements.forEach((element) => observer[method](element, options));
25
- }
26
- if (targetType === "array") {
27
- target.forEach((element) => observer[method](element, options));
28
- }
29
- }
30
-
31
- // src/dom/observers/resize-observer.js
32
- function resizeObserver(target, options) {
33
- const { callback, ...opts } = options;
34
- const observer = new ResizeObserver(observerFn);
35
- if (target === window || target === document)
36
- target = document.documentElement;
37
- useObserverMethodOnTarget(target, observer, "observe", opts);
38
- function observerFn(entries) {
39
- for (const entry of entries) {
40
- if (callback) callback({ entry, entries, observer });
41
- else
42
- dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
43
- }
44
- }
45
- return {
46
- observe(target2) {
47
- useObserverMethodOnTarget(target2, observer, "observe", options);
48
- },
49
- unobserve(target2) {
50
- useObserverMethodOnTarget(target2, observer, "unobserve");
51
- },
52
- disconnect: (_) => observer.disconnect(),
53
- destroy: (_) => observer.disconnect()
54
- };
55
- }
56
-
57
- // src/dom/observers/scroll-observer.js
58
- var defaultOptions = {
1
+ import { resizeObserver } from "./resize-observer.js";
2
+ const defaultOptions = {
59
3
  threshold: 0,
60
4
  // Float between 0 to 1.
61
5
  tolerance: 0.1,
@@ -1,11 +1,4 @@
1
- // src/dom/random-string.js
2
- function randomString(length = 10) {
3
- const firstLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
4
- const others = Math.random().toString(36).substring(2, 2 + length - 1);
5
- return firstLetter + others;
6
- }
7
-
8
- // src/dom/pkce.js
1
+ import { randomString } from "./random-string.js";
9
2
  async function PKCE() {
10
3
  const codeVerifier = await randomString();
11
4
  const codeChallenge = await getCodeChallenge(codeVerifier);
@@ -1,5 +1,4 @@
1
- // src/dom/query-params.js
2
- var queryParams = {
1
+ const queryParams = {
3
2
  get(key) {
4
3
  const searchParams = new URLSearchParams(location.search);
5
4
  return searchParams.get(key);
@@ -1,4 +1,3 @@
1
- // src/dom/random-string.js
2
1
  function randomString(length = 10) {
3
2
  const firstLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
4
3
  const others = Math.random().toString(36).substring(2, 2 + length - 1);
@@ -1,31 +1,8 @@
1
- // src/dom/sanitize.js
2
1
  import DOMPurify from "dompurify";
3
-
4
- // src/lib/form/sanitize.js
2
+ import { sanitize as sanitizeLib } from "../lib/form/sanitize.js";
5
3
  function sanitize(value, options = {}) {
6
- const { sanitizer, ...rest } = options;
7
- if (!sanitizer) throw new Error("sanitizer function is required");
8
- if (typeof value === "string") return sanitizer(value, rest);
9
- if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
10
- if (value && typeof value === "object") {
11
- return Object.fromEntries(
12
- Object.entries(value).map(([key, val]) => [
13
- key,
14
- sanitize(val, { sanitizer, ...rest })
15
- ])
16
- );
17
- }
18
- return value;
19
- }
20
- function sanitizeArray(arr, { sanitizer, ...rest }) {
21
- if (!sanitizer) throw new Error("sanitizer function is required");
22
- return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
23
- }
24
-
25
- // src/dom/sanitize.js
26
- function sanitize2(value, options = {}) {
27
- return sanitize(value, { sanitizer: DOMPurify.sanitize, ...options });
4
+ return sanitizeLib(value, { sanitizer: DOMPurify.sanitize, ...options });
28
5
  }
29
6
  export {
30
- sanitize2 as sanitize
7
+ sanitize
31
8
  };
@@ -1,5 +1,4 @@
1
- // src/dom/session-store.js
2
- var sessionStore = {
1
+ const sessionStore = {
3
2
  get(key) {
4
3
  const value = sessionStorage.getItem(key);
5
4
  if (!value) return;
@@ -1,4 +1,3 @@
1
- // src/dom/spam-prevention.js
2
1
  function preventSpam(form, { honeypotField = "hp", honeypotDuration = 2e3 } = {}) {
3
2
  const startTime = Date.now();
4
3
  let hasInteraction = false;
@@ -1,124 +1,5 @@
1
- // src/dom/focusable.js
2
- function getFocusableElements(container = document.body) {
3
- return {
4
- /**
5
- * Gets the number of keyboard focusable elements.
6
- * This is useful for checking if there are any focusable elements
7
- * before attempting to focus them.
8
- *
9
- * @returns {number} The number of keyboard focusable elements
10
- */
11
- get length() {
12
- return this.keyboard.length;
13
- },
14
- /**
15
- * Gets all focusable elements within the container that are visible and enabled.
16
- * This includes elements that can be focused via mouse or programmatically,
17
- * but may not be keyboard focusable.
18
- *
19
- * Elements are considered focusable if they:
20
- * - Are not disabled
21
- * - Are not hidden
22
- * - Are not display:none
23
- *
24
- * @returns {HTMLElement[]} Array of focusable elements that are visible and enabled
25
- */
26
- get all() {
27
- const elements = Array.from(
28
- container.querySelectorAll(
29
- `a,
30
- button,
31
- input,
32
- textarea,
33
- select,
34
- details,
35
- iframe,
36
- embed,
37
- object,
38
- summary,
39
- dialog,
40
- audio[controls],
41
- video[controls],
42
- [contenteditable],
43
- [tabindex]
44
- `
45
- )
46
- );
47
- return elements.filter((el) => {
48
- if (el.hasAttribute("disabled")) return false;
49
- if (el.hasAttribute("hidden")) return false;
50
- if (window.getComputedStyle(el).display === "none") return false;
51
- return true;
52
- });
53
- },
54
- /**
55
- * Gets elements that can be focused via keyboard (tabIndex > -1).
56
- * These are the elements that will be focused when using the Tab key.
57
- *
58
- * @returns {HTMLElement[]} Array of keyboard focusable elements
59
- */
60
- get keyboard() {
61
- return this.all.filter((el) => el instanceof HTMLElement && el.tabIndex > -1);
62
- },
63
- /**
64
- * Alias for keyboard focusable elements.
65
- * This is provided for semantic clarity in certain contexts.
66
- *
67
- * @returns {HTMLElement[]} Array of keyboard focusable elements
68
- */
69
- get keyboardOnly() {
70
- return this.keyboard;
71
- },
72
- /**
73
- * Gets the first keyboard focusable element.
74
- * This is useful for setting initial focus when opening a modal or dialog.
75
- *
76
- * @returns {HTMLElement|null} The first focusable element or null if none exist
77
- */
78
- get first() {
79
- return this.keyboard[0] || null;
80
- },
81
- /**
82
- * Gets the last keyboard focusable element.
83
- * This is useful for focus trapping when using Shift+Tab.
84
- *
85
- * @returns {HTMLElement|null} The last focusable element or null if none exist
86
- */
87
- get last() {
88
- return this.keyboard[this.length - 1] || null;
89
- },
90
- /**
91
- * Gets the next focusable element after the given index.
92
- * This is useful for implementing custom tab order or focus management.
93
- *
94
- * @param {number} index - The current element's index in the keyboard focusable array
95
- * @returns {HTMLElement|null} The next focusable element or null if none exists
96
- */
97
- next(index) {
98
- return this.keyboard[index + 1] || null;
99
- },
100
- /**
101
- * Gets the previous focusable element before the given index.
102
- * This is useful for implementing custom tab order or focus management.
103
- *
104
- * @param {number} index - The current element's index in the keyboard focusable array
105
- * @returns {HTMLElement|null} The previous focusable element or null if none exists
106
- */
107
- prev(index) {
108
- return this.keyboard[index - 1] || null;
109
- }
110
- };
111
- }
112
-
113
- // src/dom/keyboard.js
114
- function isTab(event) {
115
- return !event.shiftKey && event.key === "Tab";
116
- }
117
- function isShiftTab(event) {
118
- return event.shiftKey && event.key === "Tab";
119
- }
120
-
121
- // src/dom/trap-focus.js
1
+ import { getFocusableElements } from "./focusable.js";
2
+ import { isShiftTab, isTab } from "./keyboard.js";
122
3
  function trapFocus({ event, focusables }) {
123
4
  if (event.key !== "Tab") return;
124
5
  if (isTab(event) && document.activeElement === focusables.last) {
@@ -1,4 +1,3 @@
1
- // src/dom/ui/aria-current.js
2
1
  function markActiveAnchorIn(container, anchorType = "page") {
3
2
  if (!container) return;
4
3
  const { pathname } = window.location;
@@ -1,4 +1,3 @@
1
- // src/dom/ui/inconsistent-button-fix.js
2
1
  function inconsistentButtonFix() {
3
2
  document.addEventListener("click", (event) => {
4
3
  if (event.target instanceof HTMLButtonElement) {