@splendidlabz/utils 1.11.1 → 1.11.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 (306) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +2 -2
  3. package/src/dom/actions/masonry.js +1 -0
  4. package/src/lib/objects/omit-empty.js +1 -1
  5. package/src/lib/strings/markdown.spec.js +73 -0
  6. package/src/node/context.js +0 -0
  7. package/src/node/file-cache.js +1 -1
  8. package/src/node/pkce.js +1 -1
  9. package/tsup.config.mjs +19 -1
  10. package/dist/cjs/dom/accessibility.cjs +0 -51
  11. package/dist/cjs/dom/actions/index.cjs +0 -25
  12. package/dist/cjs/dom/actions/masonry.cjs +0 -60
  13. package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +0 -113
  14. package/dist/cjs/dom/actions/sticky.cjs +0 -93
  15. package/dist/cjs/dom/bounding-box.cjs +0 -68
  16. package/dist/cjs/dom/clipboard.cjs +0 -35
  17. package/dist/cjs/dom/cookie.cjs +0 -55
  18. package/dist/cjs/dom/css-vars.cjs +0 -47
  19. package/dist/cjs/dom/events.cjs +0 -57
  20. package/dist/cjs/dom/focusable.cjs +0 -141
  21. package/dist/cjs/dom/font-size.cjs +0 -68
  22. package/dist/cjs/dom/get-element.cjs +0 -96
  23. package/dist/cjs/dom/hash.cjs +0 -33
  24. package/dist/cjs/dom/index.cjs +0 -65
  25. package/dist/cjs/dom/keyboard.cjs +0 -49
  26. package/dist/cjs/dom/local-store.cjs +0 -77
  27. package/dist/cjs/dom/media.cjs +0 -57
  28. package/dist/cjs/dom/observers/index.cjs +0 -27
  29. package/dist/cjs/dom/observers/intersection-observer.cjs +0 -59
  30. package/dist/cjs/dom/observers/mutation-observer.cjs +0 -63
  31. package/dist/cjs/dom/observers/observer.cjs +0 -38
  32. package/dist/cjs/dom/observers/resize-observer.cjs +0 -52
  33. package/dist/cjs/dom/observers/scroll-observer.cjs +0 -118
  34. package/dist/cjs/dom/pkce.cjs +0 -43
  35. package/dist/cjs/dom/query-params.cjs +0 -36
  36. package/dist/cjs/dom/random-string.cjs +0 -36
  37. package/dist/cjs/dom/sanitize.cjs +0 -41
  38. package/dist/cjs/dom/session-store.cjs +0 -47
  39. package/dist/cjs/dom/spam-prevention.cjs +0 -48
  40. package/dist/cjs/dom/trap-focus.cjs +0 -75
  41. package/dist/cjs/dom/ui/aria-current.cjs +0 -41
  42. package/dist/cjs/dom/ui/inconsistent-button-fix.cjs +0 -33
  43. package/dist/cjs/dom/ui/index.cjs +0 -27
  44. package/dist/cjs/dom/ui/scroll-container.cjs +0 -45
  45. package/dist/cjs/dom/ui/traverse-and-scramble.cjs +0 -48
  46. package/dist/cjs/lib/arrays/index.cjs +0 -31
  47. package/dist/cjs/lib/arrays/item-position.cjs +0 -40
  48. package/dist/cjs/lib/arrays/join.cjs +0 -35
  49. package/dist/cjs/lib/arrays/shuffle.cjs +0 -40
  50. package/dist/cjs/lib/arrays/sort.cjs +0 -59
  51. package/dist/cjs/lib/arrays/split-array.cjs +0 -39
  52. package/dist/cjs/lib/arrays/unique.cjs +0 -29
  53. package/dist/cjs/lib/auth/index.cjs +0 -21
  54. package/dist/cjs/lib/auth/route-manager.cjs +0 -49
  55. package/dist/cjs/lib/checks.cjs +0 -61
  56. package/dist/cjs/lib/date/days.cjs +0 -35
  57. package/dist/cjs/lib/date/index.cjs +0 -25
  58. package/dist/cjs/lib/date/months.cjs +0 -100
  59. package/dist/cjs/lib/date/time.cjs +0 -105
  60. package/dist/cjs/lib/form/form-data.cjs +0 -81
  61. package/dist/cjs/lib/form/index.cjs +0 -23
  62. package/dist/cjs/lib/form/sanitize.cjs +0 -59
  63. package/dist/cjs/lib/functions/callback.cjs +0 -29
  64. package/dist/cjs/lib/functions/debounce.cjs +0 -41
  65. package/dist/cjs/lib/functions/env.cjs +0 -30
  66. package/dist/cjs/lib/functions/functional.cjs +0 -80
  67. package/dist/cjs/lib/functions/index.cjs +0 -29
  68. package/dist/cjs/lib/functions/throttle.cjs +0 -36
  69. package/dist/cjs/lib/functions/timeout.cjs +0 -39
  70. package/dist/cjs/lib/hash.cjs +0 -41
  71. package/dist/cjs/lib/index.cjs +0 -47
  72. package/dist/cjs/lib/numbers/index.cjs +0 -36
  73. package/dist/cjs/lib/numbers/math.cjs +0 -34
  74. package/dist/cjs/lib/objects/camelcase-keys.cjs +0 -39
  75. package/dist/cjs/lib/objects/empty.cjs +0 -37
  76. package/dist/cjs/lib/objects/equal.cjs +0 -45
  77. package/dist/cjs/lib/objects/extend.cjs +0 -36
  78. package/dist/cjs/lib/objects/flatten.cjs +0 -40
  79. package/dist/cjs/lib/objects/index.cjs +0 -45
  80. package/dist/cjs/lib/objects/json.cjs +0 -33
  81. package/dist/cjs/lib/objects/loop.cjs +0 -38
  82. package/dist/cjs/lib/objects/mix/mix.cjs +0 -113
  83. package/dist/cjs/lib/objects/nested-property.cjs +0 -43
  84. package/dist/cjs/lib/objects/normalize-object.cjs +0 -32
  85. package/dist/cjs/lib/objects/omit-empty.cjs +0 -38
  86. package/dist/cjs/lib/objects/size.cjs +0 -61
  87. package/dist/cjs/lib/objects/split.cjs +0 -37
  88. package/dist/cjs/lib/promises/index.cjs +0 -21
  89. package/dist/cjs/lib/promises/reject.cjs +0 -50
  90. package/dist/cjs/lib/sse.cjs +0 -74
  91. package/dist/cjs/lib/strings/convert-case/convert-case.cjs +0 -94
  92. package/dist/cjs/lib/strings/index.cjs +0 -29
  93. package/dist/cjs/lib/strings/markdown.cjs +0 -74
  94. package/dist/cjs/lib/strings/name.cjs +0 -44
  95. package/dist/cjs/lib/strings/pluralize.cjs +0 -38
  96. package/dist/cjs/lib/strings/query-string.cjs +0 -41
  97. package/dist/cjs/lib/style/index.cjs +0 -35
  98. package/dist/cjs/lib/symbols/index.cjs +0 -21
  99. package/dist/cjs/lib/symbols/symbols.cjs +0 -36
  100. package/dist/cjs/node/dirname.cjs +0 -47
  101. package/dist/cjs/node/file-cache.cjs +0 -158
  102. package/dist/cjs/node/file.cjs +0 -48
  103. package/dist/cjs/node/hash.cjs +0 -40
  104. package/dist/cjs/node/index.cjs +0 -33
  105. package/dist/cjs/node/pkce.cjs +0 -52
  106. package/dist/cjs/node/random-string.cjs +0 -41
  107. package/dist/cjs/node/sanitize.cjs +0 -41
  108. package/dist/cjs/node/uuid.cjs +0 -40
  109. package/dist/esm/dom/accessibility.js +0 -26
  110. package/dist/esm/dom/actions/index.js +0 -3
  111. package/dist/esm/dom/actions/masonry.js +0 -37
  112. package/dist/esm/dom/actions/prefer-horizontal-scroll.js +0 -90
  113. package/dist/esm/dom/actions/sticky.js +0 -70
  114. package/dist/esm/dom/bounding-box.js +0 -44
  115. package/dist/esm/dom/clipboard.js +0 -12
  116. package/dist/esm/dom/cookie.js +0 -31
  117. package/dist/esm/dom/css-vars.js +0 -21
  118. package/dist/esm/dom/events.js +0 -31
  119. package/dist/esm/dom/focusable.js +0 -117
  120. package/dist/esm/dom/font-size.js +0 -40
  121. package/dist/esm/dom/get-element.js +0 -66
  122. package/dist/esm/dom/hash.js +0 -10
  123. package/dist/esm/dom/index.js +0 -23
  124. package/dist/esm/dom/keyboard.js +0 -22
  125. package/dist/esm/dom/local-store.js +0 -54
  126. package/dist/esm/dom/media.js +0 -32
  127. package/dist/esm/dom/observers/index.js +0 -4
  128. package/dist/esm/dom/observers/intersection-observer.js +0 -36
  129. package/dist/esm/dom/observers/mutation-observer.js +0 -40
  130. package/dist/esm/dom/observers/observer.js +0 -15
  131. package/dist/esm/dom/observers/resize-observer.js +0 -29
  132. package/dist/esm/dom/observers/scroll-observer.js +0 -95
  133. package/dist/esm/dom/pkce.js +0 -20
  134. package/dist/esm/dom/query-params.js +0 -13
  135. package/dist/esm/dom/random-string.js +0 -12
  136. package/dist/esm/dom/sanitize.js +0 -8
  137. package/dist/esm/dom/session-store.js +0 -24
  138. package/dist/esm/dom/spam-prevention.js +0 -25
  139. package/dist/esm/dom/trap-focus.js +0 -51
  140. package/dist/esm/dom/ui/aria-current.js +0 -17
  141. package/dist/esm/dom/ui/inconsistent-button-fix.js +0 -10
  142. package/dist/esm/dom/ui/index.js +0 -4
  143. package/dist/esm/dom/ui/scroll-container.js +0 -22
  144. package/dist/esm/dom/ui/traverse-and-scramble.js +0 -25
  145. package/dist/esm/lib/arrays/index.js +0 -6
  146. package/dist/esm/lib/arrays/item-position.js +0 -15
  147. package/dist/esm/lib/arrays/join.js +0 -12
  148. package/dist/esm/lib/arrays/shuffle.js +0 -17
  149. package/dist/esm/lib/arrays/sort.js +0 -36
  150. package/dist/esm/lib/arrays/split-array.js +0 -16
  151. package/dist/esm/lib/arrays/unique.js +0 -6
  152. package/dist/esm/lib/auth/index.js +0 -1
  153. package/dist/esm/lib/auth/route-manager.js +0 -25
  154. package/dist/esm/lib/checks.js +0 -34
  155. package/dist/esm/lib/date/days.js +0 -12
  156. package/dist/esm/lib/date/index.js +0 -3
  157. package/dist/esm/lib/date/months.js +0 -77
  158. package/dist/esm/lib/date/time.js +0 -75
  159. package/dist/esm/lib/form/form-data.js +0 -57
  160. package/dist/esm/lib/form/index.js +0 -2
  161. package/dist/esm/lib/form/sanitize.js +0 -34
  162. package/dist/esm/lib/functions/callback.js +0 -6
  163. package/dist/esm/lib/functions/debounce.js +0 -18
  164. package/dist/esm/lib/functions/env.js +0 -7
  165. package/dist/esm/lib/functions/functional.js +0 -52
  166. package/dist/esm/lib/functions/index.js +0 -5
  167. package/dist/esm/lib/functions/throttle.js +0 -13
  168. package/dist/esm/lib/functions/timeout.js +0 -14
  169. package/dist/esm/lib/hash.js +0 -18
  170. package/dist/esm/lib/index.js +0 -14
  171. package/dist/esm/lib/numbers/index.js +0 -11
  172. package/dist/esm/lib/numbers/math.js +0 -10
  173. package/dist/esm/lib/objects/camelcase-keys.js +0 -16
  174. package/dist/esm/lib/objects/empty.js +0 -13
  175. package/dist/esm/lib/objects/equal.js +0 -11
  176. package/dist/esm/lib/objects/extend.js +0 -13
  177. package/dist/esm/lib/objects/flatten.js +0 -17
  178. package/dist/esm/lib/objects/index.js +0 -13
  179. package/dist/esm/lib/objects/json.js +0 -10
  180. package/dist/esm/lib/objects/loop.js +0 -14
  181. package/dist/esm/lib/objects/mix/mix.js +0 -88
  182. package/dist/esm/lib/objects/nested-property.js +0 -18
  183. package/dist/esm/lib/objects/normalize-object.js +0 -9
  184. package/dist/esm/lib/objects/omit-empty.js +0 -15
  185. package/dist/esm/lib/objects/size.js +0 -38
  186. package/dist/esm/lib/objects/split.js +0 -14
  187. package/dist/esm/lib/promises/index.js +0 -1
  188. package/dist/esm/lib/promises/reject.js +0 -17
  189. package/dist/esm/lib/sse.js +0 -50
  190. package/dist/esm/lib/strings/convert-case/convert-case.js +0 -64
  191. package/dist/esm/lib/strings/index.js +0 -5
  192. package/dist/esm/lib/strings/markdown.js +0 -40
  193. package/dist/esm/lib/strings/name.js +0 -21
  194. package/dist/esm/lib/strings/pluralize.js +0 -5
  195. package/dist/esm/lib/strings/query-string.js +0 -16
  196. package/dist/esm/lib/style/index.js +0 -12
  197. package/dist/esm/lib/symbols/index.js +0 -1
  198. package/dist/esm/lib/symbols/symbols.js +0 -12
  199. package/dist/esm/node/dirname.js +0 -13
  200. package/dist/esm/node/file-cache.js +0 -121
  201. package/dist/esm/node/file.js +0 -14
  202. package/dist/esm/node/hash.js +0 -7
  203. package/dist/esm/node/index.js +0 -7
  204. package/dist/esm/node/pkce.js +0 -19
  205. package/dist/esm/node/random-string.js +0 -8
  206. package/dist/esm/node/sanitize.js +0 -8
  207. package/dist/esm/node/uuid.js +0 -7
  208. package/dist/types/dom/accessibility.d.cts +0 -30
  209. package/dist/types/dom/actions/index.d.cts +0 -3
  210. package/dist/types/dom/actions/masonry.d.cts +0 -5
  211. package/dist/types/dom/actions/prefer-horizontal-scroll.d.cts +0 -5
  212. package/dist/types/dom/actions/sticky.d.cts +0 -5
  213. package/dist/types/dom/bounding-box.d.cts +0 -41
  214. package/dist/types/dom/clipboard.d.cts +0 -7
  215. package/dist/types/dom/cookie.d.cts +0 -7
  216. package/dist/types/dom/css-vars.d.cts +0 -6
  217. package/dist/types/dom/events.d.cts +0 -92
  218. package/dist/types/dom/focusable.d.cts +0 -78
  219. package/dist/types/dom/font-size.d.cts +0 -8
  220. package/dist/types/dom/get-element.d.cts +0 -102
  221. package/dist/types/dom/hash.d.cts +0 -3
  222. package/dist/types/dom/index.d.cts +0 -31
  223. package/dist/types/dom/keyboard.d.cts +0 -32
  224. package/dist/types/dom/local-store.d.cts +0 -31
  225. package/dist/types/dom/media.d.cts +0 -5
  226. package/dist/types/dom/observers/index.d.cts +0 -4
  227. package/dist/types/dom/observers/intersection-observer.d.cts +0 -10
  228. package/dist/types/dom/observers/mutation-observer.d.cts +0 -9
  229. package/dist/types/dom/observers/observer.d.cts +0 -3
  230. package/dist/types/dom/observers/resize-observer.d.cts +0 -40
  231. package/dist/types/dom/observers/scroll-observer.d.cts +0 -40
  232. package/dist/types/dom/pkce.d.cts +0 -8
  233. package/dist/types/dom/query-params.d.cts +0 -6
  234. package/dist/types/dom/random-string.d.cts +0 -9
  235. package/dist/types/dom/sanitize.d.cts +0 -10
  236. package/dist/types/dom/session-store.d.cts +0 -7
  237. package/dist/types/dom/spam-prevention.d.cts +0 -14
  238. package/dist/types/dom/trap-focus.d.cts +0 -32
  239. package/dist/types/dom/ui/aria-current.d.cts +0 -7
  240. package/dist/types/dom/ui/inconsistent-button-fix.d.cts +0 -14
  241. package/dist/types/dom/ui/index.d.cts +0 -4
  242. package/dist/types/dom/ui/scroll-container.d.cts +0 -3
  243. package/dist/types/dom/ui/traverse-and-scramble.d.cts +0 -21
  244. package/dist/types/lib/arrays/index.d.cts +0 -6
  245. package/dist/types/lib/arrays/item-position.d.cts +0 -16
  246. package/dist/types/lib/arrays/join.d.cts +0 -15
  247. package/dist/types/lib/arrays/shuffle.d.cts +0 -3
  248. package/dist/types/lib/arrays/sort.d.cts +0 -32
  249. package/dist/types/lib/arrays/split-array.d.cts +0 -6
  250. package/dist/types/lib/arrays/unique.d.cts +0 -3
  251. package/dist/types/lib/auth/index.d.cts +0 -1
  252. package/dist/types/lib/auth/route-manager.d.cts +0 -28
  253. package/dist/types/lib/checks.d.cts +0 -33
  254. package/dist/types/lib/date/days.d.cts +0 -7
  255. package/dist/types/lib/date/index.d.cts +0 -3
  256. package/dist/types/lib/date/months.d.cts +0 -11
  257. package/dist/types/lib/date/time.d.cts +0 -21
  258. package/dist/types/lib/form/form-data.d.cts +0 -9
  259. package/dist/types/lib/form/index.d.cts +0 -2
  260. package/dist/types/lib/form/sanitize.d.cts +0 -60
  261. package/dist/types/lib/functions/callback.d.cts +0 -8
  262. package/dist/types/lib/functions/debounce.d.cts +0 -3
  263. package/dist/types/lib/functions/env.d.cts +0 -3
  264. package/dist/types/lib/functions/functional.d.cts +0 -72
  265. package/dist/types/lib/functions/index.d.cts +0 -5
  266. package/dist/types/lib/functions/throttle.d.cts +0 -3
  267. package/dist/types/lib/functions/timeout.d.cts +0 -5
  268. package/dist/types/lib/hash.d.cts +0 -3
  269. package/dist/types/lib/index.d.cts +0 -43
  270. package/dist/types/lib/numbers/index.d.cts +0 -5
  271. package/dist/types/lib/numbers/math.d.cts +0 -4
  272. package/dist/types/lib/objects/camelcase-keys.d.cts +0 -3
  273. package/dist/types/lib/objects/empty.d.cts +0 -4
  274. package/dist/types/lib/objects/equal.d.cts +0 -4
  275. package/dist/types/lib/objects/extend.d.cts +0 -6
  276. package/dist/types/lib/objects/flatten.d.cts +0 -6
  277. package/dist/types/lib/objects/index.d.cts +0 -13
  278. package/dist/types/lib/objects/json.d.cts +0 -3
  279. package/dist/types/lib/objects/loop.d.cts +0 -4
  280. package/dist/types/lib/objects/mix/mix.d.cts +0 -44
  281. package/dist/types/lib/objects/nested-property.d.cts +0 -24
  282. package/dist/types/lib/objects/normalize-object.d.cts +0 -3
  283. package/dist/types/lib/objects/omit-empty.d.cts +0 -3
  284. package/dist/types/lib/objects/size.d.cts +0 -3
  285. package/dist/types/lib/objects/split.d.cts +0 -14
  286. package/dist/types/lib/promises/index.d.cts +0 -1
  287. package/dist/types/lib/promises/reject.d.cts +0 -5
  288. package/dist/types/lib/sse.d.cts +0 -18
  289. package/dist/types/lib/strings/convert-case/convert-case.d.cts +0 -10
  290. package/dist/types/lib/strings/index.d.cts +0 -5
  291. package/dist/types/lib/strings/markdown.d.cts +0 -25
  292. package/dist/types/lib/strings/name.d.cts +0 -7
  293. package/dist/types/lib/strings/pluralize.d.cts +0 -3
  294. package/dist/types/lib/strings/query-string.d.cts +0 -10
  295. package/dist/types/lib/style/index.d.cts +0 -3
  296. package/dist/types/lib/symbols/index.d.cts +0 -1
  297. package/dist/types/lib/symbols/symbols.d.cts +0 -4
  298. package/dist/types/node/dirname.d.cts +0 -9
  299. package/dist/types/node/file-cache.d.cts +0 -56
  300. package/dist/types/node/file.d.cts +0 -4
  301. package/dist/types/node/hash.d.cts +0 -3
  302. package/dist/types/node/index.d.cts +0 -7
  303. package/dist/types/node/pkce.d.cts +0 -8
  304. package/dist/types/node/random-string.d.cts +0 -3
  305. package/dist/types/node/sanitize.d.cts +0 -10
  306. package/dist/types/node/uuid.d.cts +0 -3
@@ -1,10 +0,0 @@
1
- async function sha256Hash(string) {
2
- const utf8 = new TextEncoder().encode(string);
3
- const hashBuffer = await crypto.subtle.digest("SHA-256", utf8);
4
- const hashArray = Array.from(new Uint8Array(hashBuffer));
5
- const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join("");
6
- return hashHex;
7
- }
8
- export {
9
- sha256Hash
10
- };
@@ -1,23 +0,0 @@
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";
@@ -1,22 +0,0 @@
1
- function isTab(event) {
2
- return !event.shiftKey && event.key === "Tab";
3
- }
4
- function isShiftTab(event) {
5
- return event.shiftKey && event.key === "Tab";
6
- }
7
- function isTabKey(key) {
8
- return key === "Tab";
9
- }
10
- function isArrowKey(key) {
11
- return ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(key);
12
- }
13
- function isEscapeKey(key) {
14
- return key === "Escape";
15
- }
16
- export {
17
- isArrowKey,
18
- isEscapeKey,
19
- isShiftTab,
20
- isTab,
21
- isTabKey
22
- };
@@ -1,54 +0,0 @@
1
- const localStore = {
2
- /**
3
- * Retrieves a value from localStorage
4
- * @param {string} key - The key to retrieve from localStorage
5
- * @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
6
- */
7
- get(key) {
8
- const value = localStorage.getItem(key);
9
- if (!value) return;
10
- try {
11
- return JSON.parse(value);
12
- } catch (error) {
13
- return value;
14
- }
15
- },
16
- /**
17
- * Stores a value in localStorage
18
- * @param {string} key - The key to store the value under
19
- * @param {any} value - The value to store. Objects will be stringified to JSON
20
- */
21
- set(key, value) {
22
- if (typeof value === "string") {
23
- localStorage.setItem(key, value);
24
- } else {
25
- localStorage.setItem(key, JSON.stringify(value));
26
- }
27
- },
28
- /**
29
- * Stores multiple key-value pairs in localStorage
30
- * @param {Object|Map} data - An object or Map containing key-value pairs to store
31
- */
32
- setMultiple(data) {
33
- for (const [key, value] of Object.entries(data)) {
34
- this.set(key, value);
35
- }
36
- },
37
- /**
38
- * Removes a value from localStorage
39
- * @param {string} key - The key to remove from localStorage
40
- */
41
- remove(key) {
42
- localStorage.removeItem(key);
43
- },
44
- /**
45
- * Removes multiple keys from localStorage
46
- * @param {string[]} keys - Array of keys to remove from localStorage
47
- */
48
- removeMultiple(keys) {
49
- keys.forEach((key) => this.remove(key));
50
- }
51
- };
52
- export {
53
- localStore
54
- };
@@ -1,32 +0,0 @@
1
- async function imagesLoaded(node) {
2
- const images = Array.from(node.querySelectorAll("img"));
3
- const promises = images.map((img) => {
4
- return new Promise((resolve, reject) => {
5
- if (img.complete) return resolve();
6
- img.onload = resolve;
7
- img.onerror = (e) => {
8
- reject("Image failed to load");
9
- };
10
- });
11
- });
12
- return Promise.all(promises);
13
- }
14
- async function videosLoaded(node) {
15
- const videos = Array.from(node.querySelectorAll("video"));
16
- const promises = videos.map((video) => {
17
- return new Promise((resolve, reject) => {
18
- if (video.readyState === 4) return resolve();
19
- video.onloadedmetadata = resolve;
20
- video.onerror = reject;
21
- });
22
- });
23
- return Promise.all(promises);
24
- }
25
- async function mediaLoaded(node) {
26
- return Promise.all([imagesLoaded(node), videosLoaded(node)]);
27
- }
28
- export {
29
- imagesLoaded,
30
- mediaLoaded,
31
- videosLoaded
32
- };
@@ -1,4 +0,0 @@
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,36 +0,0 @@
1
- import { dispatchEvent } from "../events.js";
2
- import { useObserverMethodOnTarget } from "./observer.js";
3
- function intersectionObserver(target, options = {}) {
4
- const { callback, ...opts } = options;
5
- const observer = new IntersectionObserver(observerFn, opts);
6
- useObserverMethodOnTarget(target, observer, "observe");
7
- function observerFn(entries) {
8
- for (const entry of entries) {
9
- if (callback) callback({ entry, entries, observer });
10
- else dispatchEvent(target, "intersect", { entry, entries, observer });
11
- }
12
- }
13
- return {
14
- observer,
15
- observe(target2) {
16
- useObserverMethodOnTarget(target2, observer, "observe", options);
17
- },
18
- unobserve(target2) {
19
- useObserverMethodOnTarget(target2, observer, "unobserve");
20
- },
21
- takeRecords() {
22
- return observer.takeRecords();
23
- },
24
- disconnect() {
25
- const records = observer.takeRecords();
26
- observer.disconnect();
27
- if (records.length > 0) observerFn(records);
28
- },
29
- destroy() {
30
- observer.disconnect();
31
- }
32
- };
33
- }
34
- export {
35
- intersectionObserver
36
- };
@@ -1,40 +0,0 @@
1
- import { dispatchEvent } from "../events.js";
2
- import { useObserverMethodOnTarget } from "./observer.js";
3
- const defaultOptions = {
4
- attributes: false,
5
- childList: false,
6
- subtree: false
7
- };
8
- function mutationObserver(target, options) {
9
- options = { ...defaultOptions, ...options };
10
- const { callback, ...opts } = options;
11
- const observer = new MutationObserver(observerFn);
12
- if (target === window) target = document.body;
13
- useObserverMethodOnTarget(target, observer, "observe", opts);
14
- function observerFn(entries) {
15
- for (const entry of entries) {
16
- if (callback) callback({ entry, entries, observer });
17
- else dispatchEvent(target, "mutate", { entry, entries, observer });
18
- }
19
- }
20
- return {
21
- observer,
22
- observe(target2) {
23
- useObserverMethodOnTarget(target2, observer, "observe", options);
24
- },
25
- takeRecords() {
26
- return observer.takeRecords();
27
- },
28
- disconnect() {
29
- const records = observer.takeRecords();
30
- observer.disconnect();
31
- if (records.length > 0) observerFn(records);
32
- },
33
- destroy() {
34
- observer.disconnect();
35
- }
36
- };
37
- }
38
- export {
39
- mutationObserver
40
- };
@@ -1,15 +0,0 @@
1
- import { getNodeType } from "../get-element.js";
2
- function useObserverMethodOnTarget(target, observer, method = "observe", options = void 0) {
3
- const targetType = getNodeType(target);
4
- if (targetType === "element") observer[method](target, options);
5
- if (targetType === "nodelist") {
6
- const elements = Array.from(target);
7
- elements.forEach((element) => observer[method](element, options));
8
- }
9
- if (targetType === "array") {
10
- target.forEach((element) => observer[method](element, options));
11
- }
12
- }
13
- export {
14
- useObserverMethodOnTarget
15
- };
@@ -1,29 +0,0 @@
1
- import { dispatchEvent } from "../events.js";
2
- import { useObserverMethodOnTarget } from "./observer.js";
3
- function resizeObserver(target, options) {
4
- const { callback, ...opts } = options;
5
- const observer = new ResizeObserver(observerFn);
6
- if (target === window || target === document)
7
- target = document.documentElement;
8
- useObserverMethodOnTarget(target, observer, "observe", opts);
9
- function observerFn(entries) {
10
- for (const entry of entries) {
11
- if (callback) callback({ entry, entries, observer });
12
- else
13
- dispatchEvent(entry.target, "resize-obs", { entry, entries, observer });
14
- }
15
- }
16
- return {
17
- observe(target2) {
18
- useObserverMethodOnTarget(target2, observer, "observe", options);
19
- },
20
- unobserve(target2) {
21
- useObserverMethodOnTarget(target2, observer, "unobserve");
22
- },
23
- disconnect: (_) => observer.disconnect(),
24
- destroy: (_) => observer.disconnect()
25
- };
26
- }
27
- export {
28
- resizeObserver
29
- };
@@ -1,95 +0,0 @@
1
- import { resizeObserver } from "./resize-observer.js";
2
- const defaultOptions = {
3
- threshold: 0,
4
- // Float between 0 to 1.
5
- tolerance: 0.1,
6
- // Float between 0 to 1. Tolerance for event firing
7
- once: false
8
- // Only fire threshold callback once
9
- };
10
- function getScrollElement(node) {
11
- if (node === document || node === window || node === document.documentElement) {
12
- return document.documentElement;
13
- }
14
- return (
15
- /** @type {Element} */
16
- node
17
- );
18
- }
19
- function scrollObserver(node, options = {}) {
20
- const { callback, onScrollDown, onScrollUp, onEnterThreshold, ...userOpts } = options;
21
- const opts = { ...defaultOptions, ...userOpts };
22
- const { threshold, tolerance, once } = opts;
23
- let prevScrollDirection = null;
24
- let prevScrollTop = 0;
25
- let prevScrollPercent = 0;
26
- let thresholdFired = false;
27
- let rafId = null;
28
- const isDocumentScroll = node === document || node === window || node === document.documentElement;
29
- const scrollElement = getScrollElement(node);
30
- const eventTarget = isDocumentScroll ? window : node;
31
- let cachedScrollHeight = 0;
32
- let cachedClientHeight = 0;
33
- updateCache();
34
- const cacheObserver = resizeObserver(scrollElement, {
35
- callback: updateCache
36
- });
37
- eventTarget.addEventListener("scroll", throttledObserve, { passive: true });
38
- function throttledObserve() {
39
- rafId = requestAnimationFrame(observe);
40
- }
41
- function updateCache() {
42
- cachedScrollHeight = scrollElement.scrollHeight;
43
- cachedClientHeight = scrollElement.clientHeight;
44
- }
45
- function observe() {
46
- const scrollTop = scrollElement.scrollTop;
47
- if (Math.abs(scrollTop - prevScrollTop) < 1) return;
48
- const scrollDirection = scrollTop > prevScrollTop ? "down" : "up";
49
- const maxScroll = Math.max(1, cachedScrollHeight - cachedClientHeight);
50
- const scrollPercent = Math.min(1, Math.max(0, scrollTop / maxScroll));
51
- const thresholdMin = threshold - tolerance / 2;
52
- const thresholdMax = threshold + tolerance / 2;
53
- const wasInThreshold = prevScrollPercent >= thresholdMin && prevScrollPercent <= thresholdMax;
54
- const isInThreshold = scrollPercent >= thresholdMin && scrollPercent <= thresholdMax;
55
- const hasEnteredThreshold = !wasInThreshold && isInThreshold && (!once || !thresholdFired);
56
- if (hasEnteredThreshold && once) {
57
- thresholdFired = true;
58
- }
59
- const callbackData = {
60
- scrollTop,
61
- scrollDirection,
62
- scrollPercent,
63
- directionChanged: scrollDirection !== prevScrollDirection,
64
- hasEnteredThreshold,
65
- isInThreshold
66
- };
67
- if (typeof callback === "function") {
68
- callback(callbackData);
69
- }
70
- if (scrollDirection !== prevScrollDirection) {
71
- if (scrollDirection === "down" && typeof onScrollDown === "function") {
72
- onScrollDown(callbackData);
73
- }
74
- if (scrollDirection === "up" && typeof onScrollUp === "function") {
75
- onScrollUp(callbackData);
76
- }
77
- }
78
- if (hasEnteredThreshold && typeof onEnterThreshold === "function") {
79
- onEnterThreshold(callbackData);
80
- }
81
- prevScrollTop = scrollTop;
82
- prevScrollPercent = scrollPercent;
83
- prevScrollDirection = scrollDirection;
84
- }
85
- return {
86
- destroy() {
87
- eventTarget.removeEventListener("scroll", throttledObserve);
88
- if (rafId) cancelAnimationFrame(rafId);
89
- cacheObserver.destroy();
90
- }
91
- };
92
- }
93
- export {
94
- scrollObserver
95
- };
@@ -1,20 +0,0 @@
1
- import { randomString } from "./random-string.js";
2
- async function PKCE() {
3
- const codeVerifier = await randomString();
4
- const codeChallenge = await getCodeChallenge(codeVerifier);
5
- return {
6
- state: await randomString(),
7
- code_verifier: codeVerifier,
8
- code_challenge: codeChallenge,
9
- code_challenge_method: "S256"
10
- };
11
- }
12
- async function getCodeChallenge(verifier) {
13
- const encoder = new TextEncoder();
14
- const data = encoder.encode(verifier);
15
- const hashed = await window.crypto.subtle.digest("SHA-256", data);
16
- return window.btoa(String.fromCharCode.apply(null, new Uint8Array(hashed))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
17
- }
18
- export {
19
- PKCE
20
- };
@@ -1,13 +0,0 @@
1
- const queryParams = {
2
- get(key) {
3
- const searchParams = new URLSearchParams(location.search);
4
- return searchParams.get(key);
5
- },
6
- stringify(params) {
7
- const searchParams = new URLSearchParams(location.search);
8
- return searchParams.toString();
9
- }
10
- };
11
- export {
12
- queryParams
13
- };
@@ -1,12 +0,0 @@
1
- function randomString(length = 10) {
2
- const firstLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
3
- const others = Math.random().toString(36).substring(2, 2 + length - 1);
4
- return firstLetter + others;
5
- }
6
- function uuid() {
7
- return crypto.randomUUID();
8
- }
9
- export {
10
- randomString,
11
- uuid
12
- };
@@ -1,8 +0,0 @@
1
- import DOMPurify from "dompurify";
2
- import { sanitize as sanitizeLib } from "../lib/form/sanitize.js";
3
- function sanitize(value, options = {}) {
4
- return sanitizeLib(value, { sanitizer: DOMPurify.sanitize, ...options });
5
- }
6
- export {
7
- sanitize
8
- };
@@ -1,24 +0,0 @@
1
- const sessionStore = {
2
- get(key) {
3
- const value = sessionStorage.getItem(key);
4
- if (!value) return;
5
- try {
6
- return JSON.parse(value);
7
- } catch (error) {
8
- return value;
9
- }
10
- },
11
- set(key, value) {
12
- if (typeof value === "string") {
13
- sessionStorage.setItem(key, value);
14
- } else {
15
- sessionStorage.setItem(key, JSON.stringify(value));
16
- }
17
- },
18
- remove(key) {
19
- sessionStorage.removeItem(key);
20
- }
21
- };
22
- export {
23
- sessionStore
24
- };
@@ -1,25 +0,0 @@
1
- function preventSpam(form, { honeypotField = "hp", honeypotDuration = 2e3 } = {}) {
2
- const startTime = Date.now();
3
- let hasInteraction = false;
4
- function checkForInteraction() {
5
- hasInteraction = true;
6
- }
7
- const events = ["keydown", "mousemove", "touchstart", "click"];
8
- events.forEach((event) => {
9
- form.addEventListener(event, checkForInteraction, { once: true });
10
- });
11
- form.containsSpam = function() {
12
- const fillTime = Date.now() - startTime;
13
- const isTooFast = fillTime < honeypotDuration;
14
- const honeypotInput = form.querySelector(`[name="${honeypotField}"]`);
15
- const hasHoneypotValue = honeypotInput?.value?.trim();
16
- const noInteraction = !hasInteraction;
17
- events.forEach(
18
- (event) => form.removeEventListener(event, checkForInteraction)
19
- );
20
- return isTooFast || !!hasHoneypotValue || noInteraction;
21
- };
22
- }
23
- export {
24
- preventSpam
25
- };
@@ -1,51 +0,0 @@
1
- import { getFocusableElements } from "./focusable.js";
2
- import { isShiftTab, isTab } from "./keyboard.js";
3
- function trapFocus({ event, focusables }) {
4
- if (event.key !== "Tab") return;
5
- if (isTab(event) && document.activeElement === focusables.last) {
6
- event.preventDefault();
7
- focusables.first.focus();
8
- }
9
- if (isShiftTab(event) && document.activeElement === focusables.first) {
10
- event.preventDefault();
11
- focusables.last.focus();
12
- }
13
- }
14
- function manageFocus({
15
- event,
16
- triggerNode,
17
- contentNode,
18
- focusables,
19
- tabOutFocus = "next",
20
- // 'trigger'
21
- onLeave = function() {
22
- }
23
- }) {
24
- const activeEl = document.activeElement;
25
- if (activeEl === contentNode && isShiftTab(event)) return backFocus();
26
- if (activeEl === contentNode && focusables.length === 0 && isTab(event))
27
- return nextFocus();
28
- if (activeEl === focusables.last && isTab(event)) return nextFocus();
29
- if (activeEl === focusables.first && isShiftTab(event)) return backFocus();
30
- function backFocus() {
31
- event.preventDefault();
32
- triggerNode.focus();
33
- onLeave("back");
34
- }
35
- function nextFocus() {
36
- if (tabOutFocus === "trigger") triggerNode.focus();
37
- if (tabOutFocus === "next") {
38
- event.preventDefault();
39
- const DOMFocusables = getFocusableElements().keyboard;
40
- const index = DOMFocusables.findIndex((e) => e === triggerNode);
41
- const next = DOMFocusables[index + 1];
42
- if (next) next.focus();
43
- else triggerNode.focus();
44
- }
45
- onLeave("forward");
46
- }
47
- }
48
- export {
49
- manageFocus,
50
- trapFocus
51
- };
@@ -1,17 +0,0 @@
1
- function markActiveAnchorIn(container, anchorType = "page") {
2
- if (!container) return;
3
- const { pathname } = window.location;
4
- const element = container.querySelector(`[href="${pathname}"]`);
5
- if (!element) return;
6
- element.setAttribute("aria-current", "page");
7
- return element;
8
- }
9
- function scrollToElement(element, { scrollBehaviour = "instant", scrollMargin = "3rem" } = {}) {
10
- if (!element) return;
11
- element.style.scrollMarginTop = scrollMargin;
12
- element.scrollIntoView({ behavior: scrollBehaviour });
13
- }
14
- export {
15
- markActiveAnchorIn,
16
- scrollToElement
17
- };
@@ -1,10 +0,0 @@
1
- function inconsistentButtonFix() {
2
- document.addEventListener("click", (event) => {
3
- if (event.target instanceof HTMLButtonElement) {
4
- event.target.focus();
5
- }
6
- });
7
- }
8
- export {
9
- inconsistentButtonFix
10
- };
@@ -1,4 +0,0 @@
1
- export * from "./aria-current.js";
2
- export * from "./inconsistent-button-fix.js";
3
- export * from "./scroll-container.js";
4
- export * from "./traverse-and-scramble.js";
@@ -1,22 +0,0 @@
1
- function findScrollContainer(element, direction = "both") {
2
- if (!element) return;
3
- let parent = element.parentElement;
4
- while (parent) {
5
- const { overflow, overflowX, overflowY } = getComputedStyle(parent);
6
- if (direction === "both") {
7
- if (overflow.includes("auto") || overflow.includes("scroll"))
8
- return parent;
9
- }
10
- if (direction === "horizontal") {
11
- if (overflowX === "auto" || overflowX === "scroll") return parent;
12
- }
13
- if (direction === "vertical") {
14
- if (overflowY === "auto" || overflowY === "scroll") return parent;
15
- }
16
- parent = parent.parentElement;
17
- }
18
- return document.documentElement;
19
- }
20
- export {
21
- findScrollContainer
22
- };
@@ -1,25 +0,0 @@
1
- function traverseAndScramble(node, { excludes = [] } = {}) {
2
- if (node instanceof Element && excludes.some((selector) => node.matches(selector))) {
3
- return;
4
- }
5
- node.childNodes.forEach((child) => {
6
- if (child.nodeType === 3) {
7
- child.nodeValue = scrambleText(child.nodeValue);
8
- } else if (child.nodeType === 1 && child instanceof Element) {
9
- traverseAndScramble(child, { excludes });
10
- }
11
- });
12
- }
13
- function scrambleText(text) {
14
- return text.split("").map((char) => {
15
- if (/^[A-Za-z0-9]$/.test(char)) {
16
- const randomCharCode = Math.random() < 26 / 36 ? Math.floor(Math.random() * 26) + (char === char.toUpperCase() ? 65 : 97) : Math.floor(Math.random() * 10) + 48;
17
- return String.fromCharCode(randomCharCode);
18
- } else {
19
- return char;
20
- }
21
- }).join("");
22
- }
23
- export {
24
- traverseAndScramble
25
- };
@@ -1,6 +0,0 @@
1
- export * from "./item-position.js";
2
- export * from "./join.js";
3
- export * from "./shuffle.js";
4
- export * from "./sort.js";
5
- export * from "./split-array.js";
6
- export * from "./unique.js";
@@ -1,15 +0,0 @@
1
- function last(array, index) {
2
- console.warn("last is deprecated. Use isLastItem instead.");
3
- return index === array.length - 1;
4
- }
5
- function isLastItem(array, index) {
6
- return index === array.length - 1;
7
- }
8
- function lastArrayItem(array) {
9
- return array[array.length - 1];
10
- }
11
- export {
12
- isLastItem,
13
- last,
14
- lastArrayItem
15
- };
@@ -1,12 +0,0 @@
1
- import { lastArrayItem } from "./item-position.js";
2
- function joinWithConjunction(array, { conjunction = "and" } = {}) {
3
- if (!array?.length) return "";
4
- if (array.length === 1) return array[0];
5
- if (array.length === 2) return `${array[0]} ${conjunction} ${array[1]}`;
6
- const lastItem = lastArrayItem(array);
7
- const rest = array.slice(0, -1);
8
- return `${rest.join(", ")} ${conjunction} ${lastItem}`;
9
- }
10
- export {
11
- joinWithConjunction
12
- };
@@ -1,17 +0,0 @@
1
- function shuffle(array) {
2
- const clone = array.slice();
3
- let currentIndex = array.length;
4
- let temporaryValue;
5
- let randomIndex;
6
- while (currentIndex !== 0) {
7
- randomIndex = Math.floor(Math.random() * currentIndex);
8
- currentIndex -= 1;
9
- temporaryValue = clone[currentIndex];
10
- clone[currentIndex] = clone[randomIndex];
11
- clone[randomIndex] = temporaryValue;
12
- }
13
- return clone;
14
- }
15
- export {
16
- shuffle
17
- };