@splendidlabz/utils 1.11.2 → 1.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/dist/cjs/dom/accessibility.cjs +2 -0
  2. package/dist/cjs/dom/actions/index.cjs +392 -7
  3. package/dist/cjs/dom/actions/masonry.cjs +97 -6
  4. package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +58 -14
  5. package/dist/cjs/dom/actions/sticky.cjs +126 -6
  6. package/dist/cjs/dom/bounding-box.cjs +2 -0
  7. package/dist/cjs/dom/clipboard.cjs +2 -0
  8. package/dist/cjs/dom/cookie.cjs +3 -1
  9. package/dist/cjs/dom/css-vars.cjs +13 -3
  10. package/dist/cjs/dom/events.cjs +2 -0
  11. package/dist/cjs/dom/focusable.cjs +2 -0
  12. package/dist/cjs/dom/font-size.cjs +15 -3
  13. package/dist/cjs/dom/get-element.cjs +3 -1
  14. package/dist/cjs/dom/hash.cjs +2 -0
  15. package/dist/cjs/dom/index.cjs +1249 -47
  16. package/dist/cjs/dom/keyboard.cjs +2 -0
  17. package/dist/cjs/dom/local-store.cjs +3 -1
  18. package/dist/cjs/dom/media.cjs +2 -0
  19. package/dist/cjs/dom/observers/index.cjs +235 -9
  20. package/dist/cjs/dom/observers/intersection-observer.cjs +38 -6
  21. package/dist/cjs/dom/observers/mutation-observer.cjs +38 -6
  22. package/dist/cjs/dom/observers/observer.cjs +12 -2
  23. package/dist/cjs/dom/observers/resize-observer.cjs +38 -6
  24. package/dist/cjs/dom/observers/scroll-observer.cjs +62 -3
  25. package/dist/cjs/dom/pkce.cjs +13 -3
  26. package/dist/cjs/dom/query-params.cjs +3 -1
  27. package/dist/cjs/dom/random-string.cjs +2 -0
  28. package/dist/cjs/dom/sanitize.cjs +27 -3
  29. package/dist/cjs/dom/session-store.cjs +3 -1
  30. package/dist/cjs/dom/spam-prevention.cjs +2 -0
  31. package/dist/cjs/dom/trap-focus.cjs +131 -9
  32. package/dist/cjs/dom/ui/aria-current.cjs +2 -0
  33. package/dist/cjs/dom/ui/inconsistent-button-fix.cjs +2 -0
  34. package/dist/cjs/dom/ui/index.cjs +87 -9
  35. package/dist/cjs/dom/ui/scroll-container.cjs +2 -0
  36. package/dist/cjs/dom/ui/traverse-and-scramble.cjs +2 -0
  37. package/dist/cjs/lib/arrays/index.cjs +121 -13
  38. package/dist/cjs/lib/arrays/item-position.cjs +2 -0
  39. package/dist/cjs/lib/arrays/join.cjs +10 -2
  40. package/dist/cjs/lib/arrays/shuffle.cjs +2 -0
  41. package/dist/cjs/lib/arrays/sort.cjs +11 -3
  42. package/dist/cjs/lib/arrays/split-array.cjs +2 -0
  43. package/dist/cjs/lib/arrays/unique.cjs +2 -0
  44. package/dist/cjs/lib/auth/index.cjs +35 -3
  45. package/dist/cjs/lib/auth/route-manager.cjs +2 -0
  46. package/dist/cjs/lib/checks.cjs +2 -0
  47. package/dist/cjs/lib/date/days.cjs +3 -1
  48. package/dist/cjs/lib/date/index.cjs +190 -7
  49. package/dist/cjs/lib/date/months.cjs +3 -1
  50. package/dist/cjs/lib/date/time.cjs +14 -2
  51. package/dist/cjs/lib/form/form-data.cjs +2 -0
  52. package/dist/cjs/lib/form/index.cjs +104 -5
  53. package/dist/cjs/lib/form/sanitize.cjs +2 -0
  54. package/dist/cjs/lib/functions/callback.cjs +2 -0
  55. package/dist/cjs/lib/functions/debounce.cjs +2 -0
  56. package/dist/cjs/lib/functions/env.cjs +2 -0
  57. package/dist/cjs/lib/functions/functional.cjs +2 -0
  58. package/dist/cjs/lib/functions/index.cjs +124 -11
  59. package/dist/cjs/lib/functions/throttle.cjs +2 -0
  60. package/dist/cjs/lib/functions/timeout.cjs +2 -0
  61. package/dist/cjs/lib/hash.cjs +2 -0
  62. package/dist/cjs/lib/index.cjs +1160 -29
  63. package/dist/cjs/lib/numbers/index.cjs +17 -4
  64. package/dist/cjs/lib/numbers/math.cjs +2 -0
  65. package/dist/cjs/lib/objects/camelcase-keys.cjs +45 -4
  66. package/dist/cjs/lib/objects/empty.cjs +2 -0
  67. package/dist/cjs/lib/objects/equal.cjs +2 -0
  68. package/dist/cjs/lib/objects/extend.cjs +117 -6
  69. package/dist/cjs/lib/objects/flatten.cjs +11 -3
  70. package/dist/cjs/lib/objects/index.cjs +360 -27
  71. package/dist/cjs/lib/objects/json.cjs +2 -0
  72. package/dist/cjs/lib/objects/loop.cjs +2 -0
  73. package/dist/cjs/lib/objects/mix/mix.cjs +5 -3
  74. package/dist/cjs/lib/objects/nested-property.cjs +2 -0
  75. package/dist/cjs/lib/objects/normalize-object.cjs +78 -4
  76. package/dist/cjs/lib/objects/omit-empty.cjs +2 -0
  77. package/dist/cjs/lib/objects/size.cjs +2 -0
  78. package/dist/cjs/lib/objects/split.cjs +2 -0
  79. package/dist/cjs/lib/promises/index.cjs +51 -3
  80. package/dist/cjs/lib/promises/reject.cjs +19 -2
  81. package/dist/cjs/lib/sse.cjs +29 -4
  82. package/dist/cjs/lib/strings/convert-case/convert-case.cjs +2 -0
  83. package/dist/cjs/lib/strings/index.cjs +179 -11
  84. package/dist/cjs/lib/strings/markdown.cjs +3 -1
  85. package/dist/cjs/lib/strings/name.cjs +2 -0
  86. package/dist/cjs/lib/strings/pluralize.cjs +3 -1
  87. package/dist/cjs/lib/strings/query-string.cjs +2 -0
  88. package/dist/cjs/lib/style/index.cjs +31 -2
  89. package/dist/cjs/lib/symbols/index.cjs +22 -3
  90. package/dist/cjs/lib/symbols/symbols.cjs +2 -0
  91. package/dist/cjs/node/context.cjs +0 -0
  92. package/dist/cjs/node/dirname.cjs +4 -2
  93. package/dist/cjs/node/file-cache.cjs +45 -3
  94. package/dist/cjs/node/file.cjs +4 -2
  95. package/dist/cjs/node/hash.cjs +3 -1
  96. package/dist/cjs/node/index.cjs +278 -15
  97. package/dist/cjs/node/pkce.cjs +20 -8
  98. package/dist/cjs/node/random-string.cjs +3 -1
  99. package/dist/cjs/node/sanitize.cjs +27 -3
  100. package/dist/cjs/node/uuid.cjs +2 -0
  101. package/dist/esm/node/context.js +0 -0
  102. package/dist/esm/node/file-cache.js +1 -1
  103. package/dist/esm/node/pkce.js +3 -2
  104. package/dist/types/node/context.d.cts +2 -0
  105. package/dist/types/node/index.d.cts +1 -1
  106. package/dist/types/node/pkce.d.cts +7 -1
  107. package/package.json +5 -2
  108. package/CHANGELOG.md +0 -231
  109. package/eslint.config.js +0 -2
  110. package/src/dom/accessibility.js +0 -58
  111. package/src/dom/actions/index.js +0 -3
  112. package/src/dom/actions/masonry.js +0 -43
  113. package/src/dom/actions/prefer-horizontal-scroll.js +0 -121
  114. package/src/dom/actions/sticky.js +0 -85
  115. package/src/dom/bounding-box.js +0 -82
  116. package/src/dom/clipboard.js +0 -14
  117. package/src/dom/cookie.js +0 -32
  118. package/src/dom/css-vars.js +0 -19
  119. package/src/dom/events.js +0 -71
  120. package/src/dom/focusable.js +0 -165
  121. package/src/dom/font-size.js +0 -40
  122. package/src/dom/get-element.js +0 -176
  123. package/src/dom/hash.js +0 -9
  124. package/src/dom/index.js +0 -23
  125. package/src/dom/keyboard.js +0 -44
  126. package/src/dom/local-store.js +0 -66
  127. package/src/dom/media.js +0 -30
  128. package/src/dom/observers/index.js +0 -4
  129. package/src/dom/observers/intersection-observer.js +0 -43
  130. package/src/dom/observers/mutation-observer.js +0 -51
  131. package/src/dom/observers/observer.js +0 -18
  132. package/src/dom/observers/resize-observer.js +0 -66
  133. package/src/dom/observers/scroll-observer.js +0 -146
  134. package/src/dom/pkce.js +0 -34
  135. package/src/dom/query-params.js +0 -14
  136. package/src/dom/random-string.js +0 -18
  137. package/src/dom/random-string.test.js +0 -13
  138. package/src/dom/sanitize.js +0 -16
  139. package/src/dom/session-store.js +0 -29
  140. package/src/dom/spam-prevention.js +0 -40
  141. package/src/dom/trap-focus.js +0 -70
  142. package/src/dom/ui/aria-current.js +0 -20
  143. package/src/dom/ui/inconsistent-button-fix.js +0 -20
  144. package/src/dom/ui/index.js +0 -4
  145. package/src/dom/ui/scroll-container.js +0 -25
  146. package/src/dom/ui/traverse-and-scramble.js +0 -61
  147. package/src/lib/arrays/index.js +0 -6
  148. package/src/lib/arrays/item-position.js +0 -23
  149. package/src/lib/arrays/join.js +0 -20
  150. package/src/lib/arrays/shuffle.js +0 -21
  151. package/src/lib/arrays/sort.js +0 -88
  152. package/src/lib/arrays/sort.spec.js +0 -123
  153. package/src/lib/arrays/split-array.js +0 -15
  154. package/src/lib/arrays/unique.js +0 -3
  155. package/src/lib/auth/index.js +0 -1
  156. package/src/lib/auth/route-manager.js +0 -45
  157. package/src/lib/checks.js +0 -57
  158. package/src/lib/date/days.js +0 -9
  159. package/src/lib/date/index.js +0 -3
  160. package/src/lib/date/months.js +0 -74
  161. package/src/lib/date/time.js +0 -83
  162. package/src/lib/form/form-data.js +0 -73
  163. package/src/lib/form/index.js +0 -2
  164. package/src/lib/form/sanitize.js +0 -80
  165. package/src/lib/form/sanitize.spec.js +0 -126
  166. package/src/lib/functions/callback.js +0 -8
  167. package/src/lib/functions/debounce.js +0 -18
  168. package/src/lib/functions/env.js +0 -5
  169. package/src/lib/functions/functional.js +0 -113
  170. package/src/lib/functions/functional.test.js +0 -196
  171. package/src/lib/functions/index.js +0 -5
  172. package/src/lib/functions/throttle.js +0 -11
  173. package/src/lib/functions/timeout.js +0 -15
  174. package/src/lib/hash.js +0 -18
  175. package/src/lib/hash.spec.js +0 -163
  176. package/src/lib/index.js +0 -14
  177. package/src/lib/numbers/index.js +0 -12
  178. package/src/lib/numbers/math.js +0 -9
  179. package/src/lib/numbers/split-unit.test.js +0 -45
  180. package/src/lib/objects/camelcase-keys.js +0 -17
  181. package/src/lib/objects/camelcase-keys.test.js +0 -72
  182. package/src/lib/objects/empty.js +0 -10
  183. package/src/lib/objects/equal.js +0 -9
  184. package/src/lib/objects/extend.js +0 -16
  185. package/src/lib/objects/extend.test.js +0 -35
  186. package/src/lib/objects/flatten.js +0 -19
  187. package/src/lib/objects/index.js +0 -13
  188. package/src/lib/objects/json.js +0 -7
  189. package/src/lib/objects/loop.js +0 -11
  190. package/src/lib/objects/loop.test.js +0 -31
  191. package/src/lib/objects/mix/mix.js +0 -191
  192. package/src/lib/objects/mix/mix.md +0 -78
  193. package/src/lib/objects/mix/mix.test.js +0 -445
  194. package/src/lib/objects/nested-property.js +0 -41
  195. package/src/lib/objects/normalize-object.js +0 -10
  196. package/src/lib/objects/omit-empty.js +0 -23
  197. package/src/lib/objects/omit-empty.test.js +0 -85
  198. package/src/lib/objects/size.js +0 -41
  199. package/src/lib/objects/split.js +0 -19
  200. package/src/lib/promises/index.js +0 -1
  201. package/src/lib/promises/reject.js +0 -17
  202. package/src/lib/sse.js +0 -61
  203. package/src/lib/strings/convert-case/convert-case.js +0 -86
  204. package/src/lib/strings/convert-case/convert-case.md +0 -44
  205. package/src/lib/strings/convert-case/convert-case.test.js +0 -50
  206. package/src/lib/strings/index.js +0 -5
  207. package/src/lib/strings/markdown.js +0 -71
  208. package/src/lib/strings/name.js +0 -24
  209. package/src/lib/strings/name.test.js +0 -67
  210. package/src/lib/strings/pluralize.js +0 -2
  211. package/src/lib/strings/query-string.js +0 -18
  212. package/src/lib/style/index.js +0 -13
  213. package/src/lib/symbols/index.js +0 -1
  214. package/src/lib/symbols/symbols.js +0 -9
  215. package/src/node/dirname.js +0 -17
  216. package/src/node/file-cache.js +0 -184
  217. package/src/node/file.js +0 -13
  218. package/src/node/hash.js +0 -5
  219. package/src/node/index.js +0 -7
  220. package/src/node/pkce.js +0 -33
  221. package/src/node/random-string.js +0 -10
  222. package/src/node/random-string.test.js +0 -15
  223. package/src/node/sanitize.js +0 -13
  224. package/src/node/sanitize.spec.js +0 -142
  225. package/src/node/uuid.js +0 -5
  226. package/tsconfig.json +0 -23
  227. package/tsup.config.js +0 -38
  228. package/tsup.config.mjs +0 -45
package/CHANGELOG.md DELETED
@@ -1,231 +0,0 @@
1
- # @splendidlabz/utils
2
-
3
- ## 1.11.2
4
-
5
- ### Patch Changes
6
-
7
- - - Add `updateMasonryLayout` method to `masonry` nodes.
8
-
9
- ## 1.11.1
10
-
11
- ### Patch Changes
12
-
13
- - Fix auth jwt secret
14
-
15
- ## 1.11.0
16
-
17
- ### Minor Changes
18
-
19
- - Utils: Add isFunction
20
-
21
- ## 1.10.7
22
-
23
- ### Patch Changes
24
-
25
- - Allow fileCache to accept absolute urls
26
-
27
- ## 1.10.6
28
-
29
- ### Patch Changes
30
-
31
- - Bump
32
-
33
- ## 1.10.5
34
-
35
- ### Patch Changes
36
-
37
- - Fixed `env` in node
38
-
39
- ## 1.10.4
40
-
41
- ### Patch Changes
42
-
43
- - - Add env to utils/node.
44
- - Allow JWT_SECRET to be retrieved from both import.meta.env and process.env
45
-
46
- ## 1.10.3
47
-
48
- ### Patch Changes
49
-
50
- - Prevent tsup from bundling — allows tree shaking
51
-
52
- ## 1.10.2
53
-
54
- ### Patch Changes
55
-
56
- - Built
57
-
58
- ## 1.10.1
59
-
60
- ### Patch Changes
61
-
62
- - Fix circular references and typescript errors
63
-
64
- ## 1.10.0
65
-
66
- ### Minor Changes
67
-
68
- - 4efacb3: - 6c636877 fix scroll observer
69
- - 54effb06 add rlh
70
-
71
- ## 1.9.1
72
-
73
- ### Patch Changes
74
-
75
- - Replace Markdown with Markdown-it
76
-
77
- ## 1.9.0
78
-
79
- ### Minor Changes
80
-
81
- - 8f2cb34: - 48406c69 Add JSDocs for events
82
- - 304b5310 Utils: Add runCallback
83
-
84
- ## 1.8.2
85
-
86
- ### Patch Changes
87
-
88
- - - abd0770c Add pipeAsync and composeAsync along with tests
89
-
90
- ## 1.8.1
91
-
92
- ### Patch Changes
93
-
94
- - Build
95
-
96
- ## 1.8.0
97
-
98
- ### Minor Changes
99
-
100
- - Several updates
101
-
102
- ## 1.7.0
103
-
104
- ### Minor Changes
105
-
106
- - 2c149fc: Now supports CJS
107
- - Many changes! Woo
108
-
109
- ## 1.6.0
110
-
111
- ### Minor Changes
112
-
113
- - Many many upgrades which I didn't document properly 😅. The details are in Github history, but too many details to talk about now.
114
-
115
- ## 1.5.1
116
-
117
- ### Patch Changes
118
-
119
- - - Utils: Added getFocusableElements as alias of Focusables
120
- - Styles: Adjusted `grid-with-breakout` children classes and CSS properties. Wrote docs for it.
121
-
122
- ## 1.5.0
123
-
124
- ### Minor Changes
125
-
126
- - 859a2b0: Add utilities for SSE
127
- - acf9faf: Improve sort function
128
- - 8b17adc: Ready for next release
129
- - 5fe7c51: - Just bumping
130
- - Fix bug with `mix` erroring when a `null` or `undefined` source is passed to it. `mix` now ignores `null` and `undefined`.
131
- - Adds `toDegrees`
132
- - Adds `toRadians`
133
- - Adds `getCSSValue` and `setCSSValue`. They're aliases for `getCSSVar` and `setCSSVar` but they're more descriptive for standard properties.
134
- - Renamed `hasLabel` to `checkForAccessibleName`
135
- - Add `getParentElement` to get the parent element of a DOM node. If it encounters an `ASTRO-ISLAND` and `ASTRO-SLOT`, it goes one level up.
136
-
137
- ### Patch Changes
138
-
139
- - df4f2d6: Simplified Markdown — so utils now contain a markdown function
140
- - Include typescript checks!
141
- - bb06596: Updates
142
-
143
- ## 1.5.0-beta.6
144
-
145
- ### Minor Changes
146
-
147
- - Add utilities for SSE
148
-
149
- ## 1.5.0-beta.5
150
-
151
- ### Minor Changes
152
-
153
- - Ready for next release
154
-
155
- ## 1.5.0-alpha.4
156
-
157
- ### Patch Changes
158
-
159
- - Updates
160
-
161
- ## 1.5.0-alpha.3
162
-
163
- ### Minor Changes
164
-
165
- - 5fe7c51: - Just bumping
166
- - Fix bug with `mix` erroring when a `null` or `undefined` source is passed to it. `mix` now ignores `null` and `undefined`.
167
- - Adds `toDegrees`
168
- - Adds `toRadians`
169
- - Adds `getCSSValue` and `setCSSValue`. They're aliases for `getCSSVar` and `setCSSVar` but they're more descriptive for standard properties.
170
- - Renamed `hasLabel` to `checkForAccessibleName`
171
- - Add `getParentElement` to get the parent element of a DOM node. If it encounters an `ASTRO-ISLAND` and `ASTRO-SLOT`, it goes one level up.
172
-
173
- ## 1.5.0-alpha.2
174
-
175
- ### Minor Changes
176
-
177
- - acf9faf: Improve sort function
178
-
179
- ## 1.5.0-alpha.1
180
-
181
- ### Patch Changes
182
-
183
- - df4f2d6: Simplified Markdown — so utils now contain a markdown function
184
-
185
- ## 1.5.0-alpha.0
186
-
187
- ### Minor Changes
188
-
189
- - Just bumping
190
-
191
- ## 1.4.0
192
-
193
- ### Minor Changes
194
-
195
- - Added a couple of improvements
196
-
197
- ## 1.3.0
198
-
199
- ### Minor Changes
200
-
201
- - a9128f4: Add Debounce and Throttle functions
202
-
203
- ## 1.2.0
204
-
205
- ### Minor Changes
206
-
207
- - a9128f4: - Add `uuid` to `utils/node`
208
- - Add `uuid` to `utils/dom`
209
- - Add `MONTHS` constant to `utils`
210
-
211
- ### Patch Changes
212
-
213
- - a9128f4: - Change `randomString` in `utils/dom` to produce a HTML-usable string
214
-
215
- ## 1.1.2
216
-
217
- ### Patch Changes
218
-
219
- - Add query params path
220
-
221
- ## 1.1.1
222
-
223
- ### Patch Changes
224
-
225
- - Fix session store path
226
-
227
- ## 1.1.0
228
-
229
- ### Minor Changes
230
-
231
- - 2d5789f: New and better cache utility
package/eslint.config.js DELETED
@@ -1,2 +0,0 @@
1
- import config from '@splendidlabz/eslint-config'
2
- export default config
@@ -1,58 +0,0 @@
1
- // export function stopBodyScroll(element) {
2
- // if (!element) element = document.body
3
- // const top = document.documentElement.scrollTop
4
- // element.style.top = -1 * top + 'px'
5
- // element.style.overflow = 'hidden'
6
- // }
7
-
8
- // export function allowBodyScroll() {
9
- // const top = parseFloat(document.body.style.top) * -1
10
- // document.body.style.top = null
11
- // document.body.style.overflow = null
12
- // document.documentElement.scrollTop = top
13
- // }
14
-
15
- /**
16
- * Checks if an element has an accessible name through label or aria-labelledby
17
- * @param {string} [label] - The label text
18
- * @param {string} [labelledBy] - The aria-labelledby value
19
- * @returns {boolean} True if the element has an accessible name
20
- */
21
- export function hasAccessibleName(label, labelledBy) {
22
- if (label || labelledBy) return true
23
- return false
24
- }
25
-
26
- /**
27
- * Checks if an element has an accessible name and logs a warning/error if it doesn't
28
- * @param {Object} [options] - Options for checking accessible name
29
- * @param {string} [options.name] - The name of the element being checked
30
- * @param {string} [options.ariaLabel] - The aria-label value
31
- * @param {string} [options.ariaLabelledBy] - The aria-labelledby value
32
- * @param {'warn'|'error'} [options.severity='warn'] - Severity level for the message
33
- * @returns {boolean} True if the element has an accessible name
34
- */
35
- export function checkForAccessibleName({
36
- name,
37
- ariaLabel,
38
- ariaLabelledBy,
39
- severity = 'warn',
40
- } = {}) {
41
- if (ariaLabel || ariaLabelledBy) return true
42
-
43
- const message = `${name} is missing an accessible name. Please provide an accessible name with 'aria-label' or 'aria-labelledby'.`
44
- if (severity === 'warn') console.warn(message)
45
- if (severity === 'error') console.error(message)
46
- return false
47
- }
48
-
49
- /**
50
- * Checks if an ARIA popup value is valid
51
- * @param {string} value - The ARIA popup value to check
52
- * @returns {boolean} True if the value is invalid
53
- */
54
- export function isInvalidAriaPopup(value) {
55
- const allowedPopoupValues = ['dialog', 'menu', 'listbox', 'grid', 'tree']
56
- if (!allowedPopoupValues.includes(value)) return true
57
- return false
58
- }
@@ -1,3 +0,0 @@
1
- export * from './masonry.js'
2
- export * from './prefer-horizontal-scroll.js'
3
- export * from './sticky.js'
@@ -1,43 +0,0 @@
1
- import { getChildrenElements } from '../get-element.js'
2
- import { mediaLoaded } from '../media.js'
3
- import { resizeObserver } from '../observers/resize-observer.js'
4
-
5
- export async function masonry(node) {
6
- if (nativeMasonrySupport(node)) return
7
-
8
- const colGap = parseFloat(getComputedStyle(node).columnGap)
9
- const items = getChildrenElements(node)
10
-
11
- node.style.setProperty('row-gap', '1px', 'important')
12
- node.style.gridAutoRows = '0px'
13
- node.updateMasonryLayout = _ => layout({ colGap, items })
14
-
15
- try {
16
- await mediaLoaded(node)
17
- } catch (e) {}
18
-
19
- layout({ colGap, items })
20
-
21
- const obs = resizeObserver(node, {
22
- async callback(opts) {
23
- layout({ colGap, items })
24
- },
25
- })
26
-
27
- async function layout({ colGap, items }) {
28
- items.forEach(item => {
29
- const ib = item.getBoundingClientRect()
30
- item.style.gridRowEnd = `span ${Math.round(ib.height + colGap)}`
31
- })
32
- }
33
-
34
- return {
35
- destroy() {
36
- obs.disconnect()
37
- },
38
- }
39
- }
40
-
41
- function nativeMasonrySupport(node) {
42
- return getComputedStyle(node).gridTemplateRows === 'masonry'
43
- }
@@ -1,121 +0,0 @@
1
- import { omitEmpty } from '../../lib/objects/omit-empty.js'
2
- import { getCSSVar, setCSSVar } from '../css-vars.js'
3
- import { addListeners, removeListeners } from '../events.js'
4
-
5
- const DEFAULT_OPTIONS = {
6
- scrollSnapDelay: 1000,
7
- }
8
-
9
- export function preferHorizontalScroll(node, props = {}) {
10
- if (!node.classList.contains('scrollable-prefer-horizontal')) return
11
-
12
- const state = {
13
- origSnapType: null,
14
- currentSnapType: null,
15
- snapTimeoutID: null,
16
- }
17
-
18
- const options = {
19
- ...DEFAULT_OPTIONS,
20
- ...omitEmpty({
21
- scrollSnapDelay: getCSSVar(node, '--scroll-snap-delay'),
22
- }),
23
- ...omitEmpty(props),
24
- }
25
-
26
- const listeners = [
27
- {
28
- event: 'wheel',
29
- node,
30
- handler: handleWheel,
31
- },
32
-
33
- {
34
- event: 'pointerenter',
35
- node,
36
- handler: handlePointerEnter,
37
- },
38
-
39
- {
40
- event: 'pointerleave',
41
- node,
42
- handler: handlePointerLeave,
43
- },
44
- ]
45
-
46
- addListeners(listeners)
47
-
48
- function handleWheel(event) {
49
- const direction = event.deltaY > 0 ? 'down' : 'up'
50
- const updatedDelta = event.deltaY
51
-
52
- // Only handle mouse wheel
53
- // Trackpad users can scroll horizontally themselves
54
- if (isTrackpad(event)) return false
55
-
56
- setCSSVar(node, '--snap-type', 'none')
57
-
58
- const scrolledAmount = node.scrollLeft
59
- const scrollWidth = node.scrollWidth
60
- const clientWidth = node.clientWidth
61
- const scrollableAmount = scrollWidth - clientWidth // Maximum scrollable width to the right
62
-
63
- // Hijack downwards scroll
64
- if (direction === 'down' && scrolledAmount < scrollableAmount) {
65
- node.scrollLeft += updatedDelta
66
- event.preventDefault()
67
- }
68
-
69
- // Hijack upwards scroll
70
- if (direction === 'up' && scrolledAmount > 0) {
71
- node.scrollLeft += updatedDelta
72
- event.preventDefault()
73
- }
74
-
75
- // Restore snap type after a delay
76
- const { snapTimeoutID } = state
77
- if (snapTimeoutID) clearTimeout(snapTimeoutID)
78
- state.snapTimeoutID = setTimeout(_ => {
79
- restoreHijackedState(node, state)
80
- }, options.scrollSnapDelay)
81
- }
82
-
83
- function handlePointerEnter(event) {
84
- state.origSnapType = getCSSVar(node, '--snap-type') || 'proximity'
85
- }
86
-
87
- function handlePointerLeave(event) {
88
- restoreHijackedState(node, state)
89
- }
90
-
91
- return {
92
- destroy() {
93
- removeListeners(listeners)
94
- },
95
- }
96
- }
97
-
98
- function restoreHijackedState(node, state) {
99
- const scrollLeft = node.scrollLeft
100
-
101
- // Get the final scroll position
102
- setCSSVar(node, '--snap-type', state.origSnapType)
103
- const finalScrollLeft = node.scrollLeft
104
-
105
- // Scroll back to original position before replacing snap
106
- setCSSVar(node, '--snap-type', 'none')
107
- node.scrollTo({ left: scrollLeft, behavior: 'instant' })
108
-
109
- // Scroll back to the final position smoothly
110
- node.scrollTo({ left: finalScrollLeft, behavior: 'smooth' })
111
-
112
- setTimeout(_ => {
113
- setCSSVar(node, '--snap-type', state.origSnapType)
114
- }, 250)
115
- }
116
-
117
- // https://stackoverflow.com/questions/10744645/detect-touchpad-vs-mouse-in-javascript/62415754#62415754
118
- function isTrackpad(event) {
119
- // if (event.deltaMode === 0) return true // Deltamode no longer works in Chrome
120
- if (event.wheelDeltaY === event.deltaY * -3) return true
121
- }
@@ -1,85 +0,0 @@
1
- import { boundingBoxRelativeToAncestor } from '../bounding-box.js'
2
- import { resizeObserver } from '../observers/resize-observer.js'
3
- import { findScrollContainer } from '../ui/scroll-container.js'
4
-
5
- export function sticky(node, props = {}) {
6
- const scrollContainer = findScrollContainer(node)
7
- let stickyTBLR = getComputedTBLR(node)
8
-
9
- const obs = resizeObserver(node, {
10
- callback: ({ entry }) => {
11
- stickyTBLR = getComputedTBLR(node)
12
- isSticking()
13
-
14
- // Arguably, one can use a single container to check for all Sticky elements, but that is unnecessarily complicated to code. This adds more listeners to the scroll containers (assuming many), but it shouldn't be have enough listeners to break performance in any way.
15
- scrollContainer === document.documentElement
16
- ? window.addEventListener('scroll', scrollEventListener)
17
- : scrollContainer.addEventListener('scroll', scrollEventListener)
18
- },
19
- })
20
-
21
- function scrollEventListener(event) {
22
- isSticking()
23
- }
24
-
25
- function isSticking() {
26
- const { top, bottom, left, right } = stickyTBLR
27
- const relativeRect = boundingBoxRelativeToAncestor({
28
- element: node,
29
- ancestorElement: scrollContainer,
30
- })
31
-
32
- // Sticky Top
33
- if (!isNaN(top)) {
34
- if (relativeRect.top - top <= 1) {
35
- node.classList.add('sticking')
36
- } else {
37
- node.classList.remove('sticking')
38
- }
39
- }
40
-
41
- // Sticky Bottom
42
- if (!isNaN(bottom)) {
43
- if (relativeRect.bottom + bottom >= -1) {
44
- node.classList.add('sticking')
45
- } else {
46
- node.classList.remove('sticking')
47
- }
48
- }
49
-
50
- // Sticky Left
51
- if (!isNaN(left)) {
52
- if (relativeRect.left - left <= 1) {
53
- node.classList.add('sticking')
54
- } else {
55
- node.classList.remove('sticking')
56
- }
57
- }
58
-
59
- // Sticky Right
60
- if (!isNaN(right)) {
61
- if (relativeRect.right + right >= -1) {
62
- node.classList.add('sticking')
63
- } else {
64
- node.classList.remove('sticking')
65
- }
66
- }
67
- }
68
-
69
- return {
70
- destroy() {
71
- obs.disconnect()
72
- scrollContainer.removeEventListener('scroll', scrollEventListener)
73
- },
74
- }
75
- }
76
-
77
- function getComputedTBLR(element) {
78
- const style = getComputedStyle(element)
79
- return {
80
- top: parseFloat(style.top),
81
- bottom: parseFloat(style.bottom),
82
- left: parseFloat(style.left),
83
- right: parseFloat(style.right),
84
- }
85
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Advanced boundingClientRect that contains information vertical and horizontal centers.
3
- * @param {HTMLElement} element - The element to get the bounding box for
4
- * @param {Object} [options] - Options for the bounding box calculation
5
- * @param {boolean} [options.containsPadding=true] - Whether to include padding in the calculations
6
- * @returns {Object} The bounding box object with additional center coordinates
7
- * @property {number} x - The x coordinate
8
- * @property {number} y - The y coordinate
9
- * @property {number} width - The width
10
- * @property {number} height - The height
11
- * @property {number} top - The top coordinate
12
- * @property {number} right - The right coordinate
13
- * @property {number} bottom - The bottom coordinate
14
- * @property {number} left - The left coordinate
15
- * @property {number} xCenter - The horizontal center coordinate
16
- * @property {number} yCenter - The vertical center coordinate
17
- */
18
- export function boundingBox(element, { containsPadding = true } = {}) {
19
- const box = element.getBoundingClientRect()
20
-
21
- // Spread original properties into the return object
22
- const ret = {}
23
- for (const prop in box) ret[prop] = box[prop]
24
-
25
- // Gets boundingClientRect value without padding
26
- if (!containsPadding) {
27
- const style = getComputedStyle(element)
28
- // Parse padding values immediately to numbers
29
- const paddingTop = parseFloat(style.paddingTop)
30
- const paddingRight = parseFloat(style.paddingRight)
31
- const paddingBottom = parseFloat(style.paddingBottom)
32
- const paddingLeft = parseFloat(style.paddingLeft)
33
-
34
- ret.x = ret.x + paddingLeft
35
- ret.y = ret.y + paddingTop
36
- ret.width = ret.width - paddingLeft - paddingRight
37
- ret.height = ret.height - paddingTop - paddingBottom
38
- ret.top = ret.top + paddingTop
39
- ret.bottom = ret.bottom - paddingBottom
40
- ret.right = ret.right - paddingRight
41
- ret.left = ret.left + paddingLeft
42
- }
43
-
44
- ret.xCenter = (ret.left + ret.right) / 2
45
- ret.yCenter = (ret.top + ret.bottom) / 2
46
- return ret
47
- }
48
-
49
- /**
50
- * Gets the bounding box of an element relative to its ancestor
51
- * @param {Object} params - Parameters for the calculation
52
- * @param {HTMLElement} params.element - The element to get the bounding box for
53
- * @param {HTMLElement} [params.ancestorElement] - The ancestor element to calculate position relative to. Defaults to parent element
54
- * @returns {Object} The relative bounding box with center coordinates
55
- * @property {number} top - Distance from ancestor's top
56
- * @property {number} right - Distance from ancestor's right
57
- * @property {number} bottom - Distance from ancestor's bottom
58
- * @property {number} left - Distance from ancestor's left
59
- * @property {number} width - The width
60
- * @property {number} height - The height
61
- * @property {number} xCenter - The horizontal center coordinate relative to ancestor
62
- * @property {number} yCenter - The vertical center coordinate relative to ancestor
63
- */
64
- export function boundingBoxRelativeToAncestor({ element, ancestorElement }) {
65
- ancestorElement = ancestorElement || element.parentElement
66
-
67
- const box = boundingBox(element)
68
- const ancestorBox = boundingBox(ancestorElement, {
69
- containsPadding: false,
70
- })
71
-
72
- return {
73
- top: box.top - ancestorBox.top,
74
- right: box.right - ancestorBox.right,
75
- bottom: box.bottom - ancestorBox.bottom,
76
- left: box.left - ancestorBox.left,
77
- width: box.width,
78
- height: box.height,
79
- xCenter: (box.left + box.right) / 2 - ancestorBox.left,
80
- yCenter: (box.top + box.bottom) / 2 - ancestorBox.top,
81
- }
82
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Copies rich text from an element to the clipboard
3
- * @param HTMLElement element - Element to copy
4
- */
5
- export function copyRichText(element) {
6
- const range = document.createRange()
7
- range.selectNode(element)
8
-
9
- const selection = window.getSelection()
10
- selection.removeAllRanges()
11
- selection.addRange(range)
12
- document.execCommand('copy')
13
- selection.removeAllRanges()
14
- }
package/src/dom/cookie.js DELETED
@@ -1,32 +0,0 @@
1
- export const cookies = {
2
- get(name) {
3
- return getCookie(name)
4
- },
5
-
6
- set(name, value, days) {
7
- setCookie(name, value, days)
8
- },
9
- }
10
-
11
- export function getCookie(name) {
12
- const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'))
13
- if (!match) return null
14
- const decoded = decodeURIComponent(match[2])
15
-
16
- try {
17
- return JSON.parse(decoded)
18
- } catch (e) {
19
- return decoded
20
- }
21
- }
22
-
23
- // By Copilot. Needs testing before confirmation.
24
- function setCookie(name, value, days) {
25
- let expires = ''
26
- if (days) {
27
- const date = new Date()
28
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)
29
- expires = '; expires=' + date.toUTCString()
30
- }
31
- document.cookie = name + '=' + (value || '') + expires + '; path=/'
32
- }
@@ -1,19 +0,0 @@
1
- import { getElement } from './get-element.js'
2
-
3
- export function getCSSValue(element, prop) {
4
- return getCSSVar(element, prop)
5
- }
6
-
7
- export function setCSSValue(element, prop, value) {
8
- setCSSVar(element, prop, value)
9
- }
10
-
11
- export function getCSSVar(element, prop) {
12
- element = getElement(element)
13
- return getComputedStyle(element).getPropertyValue(prop)
14
- }
15
-
16
- export function setCSSVar(element, prop, value) {
17
- element = getElement(element)
18
- element.style.setProperty(prop, value)
19
- }