use-scroll-animate 6.1.0 → 6.2.0

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 (352) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +157 -411
  3. package/README_ja.md +170 -175
  4. package/README_zh.md +169 -198
  5. package/dist/chunks/{base-B5i8qQPR.cjs → base-BaQV-2ha.cjs} +3 -3
  6. package/dist/chunks/base-BaQV-2ha.cjs.map +1 -0
  7. package/dist/chunks/{base-C3Sw9sAO.js → base-C_3cAoRz.js} +4 -4
  8. package/dist/chunks/base-C_3cAoRz.js.map +1 -0
  9. package/dist/chunks/{core-BYLtO0Po.cjs → core-B5T0dhFH.cjs} +3 -3
  10. package/dist/chunks/core-B5T0dhFH.cjs.map +1 -0
  11. package/dist/chunks/{core-BDcszY4L.cjs → core-BGAyaY6L.cjs} +2 -2
  12. package/dist/chunks/{core-BDcszY4L.cjs.map → core-BGAyaY6L.cjs.map} +1 -1
  13. package/dist/chunks/{core-BVQW34aX.js → core-D7cVumUu.js} +3 -3
  14. package/dist/chunks/core-D7cVumUu.js.map +1 -0
  15. package/dist/chunks/{core-DN3hHbHh.js → core-VEBw36QK.js} +2 -2
  16. package/dist/chunks/{core-DN3hHbHh.js.map → core-VEBw36QK.js.map} +1 -1
  17. package/dist/chunks/{core-BTf__I-8.js → core-ps8uvYuN.js} +2 -2
  18. package/dist/chunks/{core-BTf__I-8.js.map → core-ps8uvYuN.js.map} +1 -1
  19. package/dist/chunks/{core-BjOYKSrV.cjs → core-zq17EeCI.cjs} +2 -2
  20. package/dist/chunks/{core-BjOYKSrV.cjs.map → core-zq17EeCI.cjs.map} +1 -1
  21. package/dist/chunks/{fx-ChjxrMBo.js → fx-Bs6IrV4Q.js} +2 -2
  22. package/dist/chunks/{fx-ChjxrMBo.js.map → fx-Bs6IrV4Q.js.map} +1 -1
  23. package/dist/chunks/{fx-B8hk1Fby.cjs → fx-lBGVtQO1.cjs} +2 -2
  24. package/dist/chunks/{fx-B8hk1Fby.cjs.map → fx-lBGVtQO1.cjs.map} +1 -1
  25. package/dist/chunks/generative-D2YyhaeO.js +336 -0
  26. package/dist/chunks/generative-D2YyhaeO.js.map +1 -0
  27. package/dist/chunks/generative-DzIZq-_g.cjs +348 -0
  28. package/dist/chunks/generative-DzIZq-_g.cjs.map +1 -0
  29. package/dist/chunks/gpu-Bu7qwugO.js +380 -0
  30. package/dist/chunks/gpu-Bu7qwugO.js.map +1 -0
  31. package/dist/chunks/gpu-CenK2l6b.cjs +387 -0
  32. package/dist/chunks/gpu-CenK2l6b.cjs.map +1 -0
  33. package/dist/chunks/{presets-BJ09NeTo.js → presets-BYBVJVeP.js} +3 -3
  34. package/dist/chunks/presets-BYBVJVeP.js.map +1 -0
  35. package/dist/chunks/{presets-D2ksQNzJ.cjs → presets-CUHys3sK.cjs} +3 -3
  36. package/dist/chunks/presets-CUHys3sK.cjs.map +1 -0
  37. package/dist/chunks/registry-CKNLQpwd.js +121 -0
  38. package/dist/chunks/registry-CKNLQpwd.js.map +1 -0
  39. package/dist/chunks/registry-DehBVRDV.cjs +131 -0
  40. package/dist/chunks/registry-DehBVRDV.cjs.map +1 -0
  41. package/dist/chunks/{spring-CckMe3x0.js → spring-CbvHfVtP.js} +2 -2
  42. package/dist/chunks/{spring-CckMe3x0.js.map → spring-CbvHfVtP.js.map} +1 -1
  43. package/dist/chunks/{spring--oZh55tB.cjs → spring-Dgx187Vh.cjs} +2 -2
  44. package/dist/chunks/{spring--oZh55tB.cjs.map → spring-Dgx187Vh.cjs.map} +1 -1
  45. package/dist/chunks/{stagger-CvhYlKrF.cjs → stagger-CCFyhzSw.cjs} +3 -3
  46. package/dist/chunks/stagger-CCFyhzSw.cjs.map +1 -0
  47. package/dist/chunks/{stagger-Dh4V-OL0.js → stagger-DtMKo2SK.js} +3 -3
  48. package/dist/chunks/stagger-DtMKo2SK.js.map +1 -0
  49. package/dist/chunks/{variants-DxPmgrNX.cjs → variants-BhjyddG8.cjs} +2 -2
  50. package/dist/chunks/{variants-DxPmgrNX.cjs.map → variants-BhjyddG8.cjs.map} +1 -1
  51. package/dist/chunks/{variants-Bsevy6Xm.js → variants-DRlKVHvu.js} +2 -2
  52. package/dist/chunks/{variants-Bsevy6Xm.js.map → variants-DRlKVHvu.js.map} +1 -1
  53. package/dist/components/a11y.cjs +4 -4
  54. package/dist/components/a11y.cjs.map +1 -1
  55. package/dist/components/a11y.d.cts +2 -2
  56. package/dist/components/a11y.d.ts +2 -2
  57. package/dist/components/a11y.js +5 -5
  58. package/dist/components/a11y.js.map +1 -1
  59. package/dist/components/angular.cjs +9 -8
  60. package/dist/components/angular.cjs.map +1 -1
  61. package/dist/components/angular.d.cts +22 -22
  62. package/dist/components/angular.d.ts +22 -22
  63. package/dist/components/angular.js +9 -8
  64. package/dist/components/angular.js.map +1 -1
  65. package/dist/components/background.cjs +3 -3
  66. package/dist/components/background.cjs.map +1 -1
  67. package/dist/components/background.css +1 -1
  68. package/dist/components/background.d.cts +1 -1
  69. package/dist/components/background.d.ts +1 -1
  70. package/dist/components/background.js +3 -3
  71. package/dist/components/background.js.map +1 -1
  72. package/dist/components/bridge.cjs +2 -2
  73. package/dist/components/bridge.cjs.map +1 -1
  74. package/dist/components/bridge.d.cts +1 -1
  75. package/dist/components/bridge.d.ts +1 -1
  76. package/dist/components/bridge.js +2 -2
  77. package/dist/components/bridge.js.map +1 -1
  78. package/dist/components/cards.cjs +3 -3
  79. package/dist/components/cards.cjs.map +1 -1
  80. package/dist/components/cards.css +1 -1
  81. package/dist/components/cards.d.cts +1 -1
  82. package/dist/components/cards.d.ts +1 -1
  83. package/dist/components/cards.js +3 -3
  84. package/dist/components/cards.js.map +1 -1
  85. package/dist/components/click.cjs +4 -4
  86. package/dist/components/click.cjs.map +1 -1
  87. package/dist/components/click.css +1 -1
  88. package/dist/components/click.d.cts +1 -1
  89. package/dist/components/click.d.ts +1 -1
  90. package/dist/components/click.js +4 -4
  91. package/dist/components/click.js.map +1 -1
  92. package/dist/components/depth.cjs +4 -4
  93. package/dist/components/depth.cjs.map +1 -1
  94. package/dist/components/depth.css +1 -1
  95. package/dist/components/depth.d.cts +1 -1
  96. package/dist/components/depth.d.ts +1 -1
  97. package/dist/components/depth.js +4 -4
  98. package/dist/components/depth.js.map +1 -1
  99. package/dist/components/effects.cjs +84 -416
  100. package/dist/components/effects.cjs.map +1 -1
  101. package/dist/components/effects.d.cts +2 -2
  102. package/dist/components/effects.d.ts +2 -2
  103. package/dist/components/effects.js +18 -349
  104. package/dist/components/effects.js.map +1 -1
  105. package/dist/components/feedback.cjs +2 -2
  106. package/dist/components/feedback.cjs.map +1 -1
  107. package/dist/components/feedback.css +1 -1
  108. package/dist/components/feedback.d.cts +1 -1
  109. package/dist/components/feedback.d.ts +1 -1
  110. package/dist/components/feedback.js +2 -2
  111. package/dist/components/feedback.js.map +1 -1
  112. package/dist/components/fx-gpu.cjs +12 -0
  113. package/dist/components/fx-gpu.cjs.map +1 -0
  114. package/dist/components/fx-gpu.d.cts +63 -0
  115. package/dist/components/fx-gpu.d.ts +63 -0
  116. package/dist/components/fx-gpu.js +5 -0
  117. package/dist/components/fx-gpu.js.map +1 -0
  118. package/dist/components/fx.cjs +18 -138
  119. package/dist/components/fx.cjs.map +1 -1
  120. package/dist/components/fx.css +1 -1
  121. package/dist/components/fx.d.cts +2 -2
  122. package/dist/components/fx.d.ts +2 -2
  123. package/dist/components/fx.js +8 -127
  124. package/dist/components/fx.js.map +1 -1
  125. package/dist/components/fx2.cjs +25 -0
  126. package/dist/components/fx2.cjs.map +1 -0
  127. package/dist/components/fx2.d.cts +136 -0
  128. package/dist/components/fx2.d.ts +136 -0
  129. package/dist/components/fx2.js +17 -0
  130. package/dist/components/fx2.js.map +1 -0
  131. package/dist/components/gesture.cjs +4 -4
  132. package/dist/components/gesture.cjs.map +1 -1
  133. package/dist/components/gesture.css +1 -1
  134. package/dist/components/gesture.d.cts +1 -1
  135. package/dist/components/gesture.d.ts +1 -1
  136. package/dist/components/gesture.js +5 -5
  137. package/dist/components/gesture.js.map +1 -1
  138. package/dist/components/interaction.cjs +2 -2
  139. package/dist/components/interaction.cjs.map +1 -1
  140. package/dist/components/interaction.css +1 -1
  141. package/dist/components/interaction.d.cts +1 -1
  142. package/dist/components/interaction.d.ts +1 -1
  143. package/dist/components/interaction.js +2 -2
  144. package/dist/components/interaction.js.map +1 -1
  145. package/dist/components/jsx.d.cts +2 -2
  146. package/dist/components/jsx.d.ts +2 -2
  147. package/dist/components/layout.cjs +2 -2
  148. package/dist/components/layout.cjs.map +1 -1
  149. package/dist/components/layout.css +1 -1
  150. package/dist/components/layout.d.cts +1 -1
  151. package/dist/components/layout.d.ts +1 -1
  152. package/dist/components/layout.js +2 -2
  153. package/dist/components/layout.js.map +1 -1
  154. package/dist/components/lazy.cjs +2 -2
  155. package/dist/components/lazy.cjs.map +1 -1
  156. package/dist/components/lazy.d.cts +2 -2
  157. package/dist/components/lazy.d.ts +2 -2
  158. package/dist/components/lazy.js +2 -2
  159. package/dist/components/lazy.js.map +1 -1
  160. package/dist/components/lite.cjs +46 -50
  161. package/dist/components/lite.cjs.map +1 -1
  162. package/dist/components/lite.js +46 -50
  163. package/dist/components/lite.js.map +1 -1
  164. package/dist/components/packs.cjs +2 -2
  165. package/dist/components/packs.cjs.map +1 -1
  166. package/dist/components/packs.css +1 -1
  167. package/dist/components/packs.d.cts +1 -1
  168. package/dist/components/packs.d.ts +1 -1
  169. package/dist/components/packs.js +2 -2
  170. package/dist/components/packs.js.map +1 -1
  171. package/dist/components/page.cjs +3 -3
  172. package/dist/components/page.cjs.map +1 -1
  173. package/dist/components/page.css +1 -1
  174. package/dist/components/page.d.cts +1 -1
  175. package/dist/components/page.d.ts +1 -1
  176. package/dist/components/page.js +4 -4
  177. package/dist/components/page.js.map +1 -1
  178. package/dist/components/perf.cjs +3 -3
  179. package/dist/components/perf.cjs.map +1 -1
  180. package/dist/components/perf.d.cts +2 -2
  181. package/dist/components/perf.d.ts +2 -2
  182. package/dist/components/perf.js +4 -4
  183. package/dist/components/perf.js.map +1 -1
  184. package/dist/components/physics.cjs +3 -3
  185. package/dist/components/physics.cjs.map +1 -1
  186. package/dist/components/physics.css +1 -1
  187. package/dist/components/physics.d.cts +1 -1
  188. package/dist/components/physics.d.ts +1 -1
  189. package/dist/components/physics.js +4 -4
  190. package/dist/components/physics.js.map +1 -1
  191. package/dist/components/react.cjs +4 -4
  192. package/dist/components/react.cjs.map +1 -1
  193. package/dist/components/react.js +4 -4
  194. package/dist/components/react.js.map +1 -1
  195. package/dist/components/reveal.cjs +2 -2
  196. package/dist/components/reveal.cjs.map +1 -1
  197. package/dist/components/reveal.css +1 -1
  198. package/dist/components/reveal.d.cts +1 -1
  199. package/dist/components/reveal.d.ts +1 -1
  200. package/dist/components/reveal.js +2 -2
  201. package/dist/components/reveal.js.map +1 -1
  202. package/dist/components/solid.cjs +10 -9
  203. package/dist/components/solid.cjs.map +1 -1
  204. package/dist/components/solid.d.cts +22 -22
  205. package/dist/components/solid.d.ts +22 -22
  206. package/dist/components/solid.js +10 -9
  207. package/dist/components/solid.js.map +1 -1
  208. package/dist/components/svelte.cjs +9 -8
  209. package/dist/components/svelte.cjs.map +1 -1
  210. package/dist/components/svelte.d.cts +22 -22
  211. package/dist/components/svelte.d.ts +22 -22
  212. package/dist/components/svelte.js +9 -8
  213. package/dist/components/svelte.js.map +1 -1
  214. package/dist/components/svg.cjs +2 -2
  215. package/dist/components/svg.cjs.map +1 -1
  216. package/dist/components/svg.css +1 -1
  217. package/dist/components/svg.d.cts +1 -1
  218. package/dist/components/svg.d.ts +1 -1
  219. package/dist/components/svg.js +2 -2
  220. package/dist/components/svg.js.map +1 -1
  221. package/dist/components/text.cjs +3 -3
  222. package/dist/components/text.cjs.map +1 -1
  223. package/dist/components/text.css +1 -1
  224. package/dist/components/text.d.cts +1 -1
  225. package/dist/components/text.d.ts +1 -1
  226. package/dist/components/text.js +3 -3
  227. package/dist/components/text.js.map +1 -1
  228. package/dist/components/timeline.cjs +3 -3
  229. package/dist/components/timeline.cjs.map +1 -1
  230. package/dist/components/timeline.css +1 -1
  231. package/dist/components/timeline.d.cts +1 -1
  232. package/dist/components/timeline.d.ts +1 -1
  233. package/dist/components/timeline.js +4 -4
  234. package/dist/components/timeline.js.map +1 -1
  235. package/dist/components/tokens.cjs +2 -2
  236. package/dist/components/tokens.cjs.map +1 -1
  237. package/dist/components/tokens.d.cts +2 -2
  238. package/dist/components/tokens.d.ts +2 -2
  239. package/dist/components/tokens.js +2 -2
  240. package/dist/components/tokens.js.map +1 -1
  241. package/dist/components/transitions.cjs +2 -2
  242. package/dist/components/transitions.cjs.map +1 -1
  243. package/dist/components/transitions.css +1 -1
  244. package/dist/components/transitions.d.cts +1 -1
  245. package/dist/components/transitions.d.ts +1 -1
  246. package/dist/components/transitions.js +2 -2
  247. package/dist/components/transitions.js.map +1 -1
  248. package/dist/components/ui.cjs +4 -4
  249. package/dist/components/ui.cjs.map +1 -1
  250. package/dist/components/ui.css +1 -1
  251. package/dist/components/ui.d.cts +1 -1
  252. package/dist/components/ui.d.ts +1 -1
  253. package/dist/components/ui.js +5 -5
  254. package/dist/components/ui.js.map +1 -1
  255. package/dist/components/vue.cjs +10 -9
  256. package/dist/components/vue.cjs.map +1 -1
  257. package/dist/components/vue.d.cts +23 -23
  258. package/dist/components/vue.d.ts +23 -23
  259. package/dist/components/vue.js +10 -9
  260. package/dist/components/vue.js.map +1 -1
  261. package/dist/components/webgl.cjs +2 -2
  262. package/dist/components/webgl.cjs.map +1 -1
  263. package/dist/components/webgl.css +1 -1
  264. package/dist/components/webgl.d.cts +1 -1
  265. package/dist/components/webgl.d.ts +1 -1
  266. package/dist/components/webgl.js +2 -2
  267. package/dist/components/webgl.js.map +1 -1
  268. package/dist/components/widgets.cjs +591 -0
  269. package/dist/components/widgets.cjs.map +1 -0
  270. package/dist/components/widgets.d.cts +110 -0
  271. package/dist/components/widgets.d.ts +110 -0
  272. package/dist/components/widgets.js +581 -0
  273. package/dist/components/widgets.js.map +1 -0
  274. package/dist/components.cjs +19 -18
  275. package/dist/components.cjs.map +1 -1
  276. package/dist/components.css +1 -1
  277. package/dist/components.d.cts +30 -30
  278. package/dist/components.d.ts +30 -30
  279. package/dist/components.js +13 -12
  280. package/dist/components.js.map +1 -1
  281. package/dist/components.umd.js +5 -5
  282. package/dist/components.umd.js.map +1 -1
  283. package/dist/element.cjs +4 -4
  284. package/dist/element.cjs.map +1 -1
  285. package/dist/element.d.cts +5 -5
  286. package/dist/element.d.ts +5 -5
  287. package/dist/element.js +4 -4
  288. package/dist/element.js.map +1 -1
  289. package/dist/element.umd.js.map +1 -1
  290. package/dist/index.cjs +10 -10
  291. package/dist/index.cjs.map +1 -1
  292. package/dist/index.d.cts +9 -9
  293. package/dist/index.d.ts +9 -9
  294. package/dist/index.js +11 -11
  295. package/dist/index.js.map +1 -1
  296. package/dist/index.umd.js +3 -3
  297. package/dist/index.umd.js.map +1 -1
  298. package/dist/presets/extended.cjs +3 -3
  299. package/dist/presets/extended.cjs.map +1 -1
  300. package/dist/presets/extended.d.cts +3 -3
  301. package/dist/presets/extended.d.ts +3 -3
  302. package/dist/presets/extended.js +3 -3
  303. package/dist/presets/extended.js.map +1 -1
  304. package/dist/presets-extended.umd.js.map +1 -1
  305. package/dist/react.cjs +4 -4
  306. package/dist/react.cjs.map +1 -1
  307. package/dist/react.d.cts +5 -5
  308. package/dist/react.d.ts +5 -5
  309. package/dist/react.js +4 -4
  310. package/dist/react.js.map +1 -1
  311. package/dist/solid.cjs +5 -5
  312. package/dist/solid.cjs.map +1 -1
  313. package/dist/solid.d.cts +6 -6
  314. package/dist/solid.d.ts +6 -6
  315. package/dist/solid.js +5 -5
  316. package/dist/solid.js.map +1 -1
  317. package/dist/svelte.cjs +5 -5
  318. package/dist/svelte.cjs.map +1 -1
  319. package/dist/svelte.d.cts +6 -6
  320. package/dist/svelte.d.ts +6 -6
  321. package/dist/svelte.js +5 -5
  322. package/dist/svelte.js.map +1 -1
  323. package/dist/vue.cjs +4 -4
  324. package/dist/vue.cjs.map +1 -1
  325. package/dist/vue.d.cts +5 -5
  326. package/dist/vue.d.ts +5 -5
  327. package/dist/vue.js +4 -4
  328. package/dist/vue.js.map +1 -1
  329. package/dist/widgets.umd.js +2 -0
  330. package/dist/widgets.umd.js.map +1 -0
  331. package/docs/API.md +13 -13
  332. package/docs/ROADMAP.md +11 -12
  333. package/docs/accessibility.md +2 -2
  334. package/docs/components.md +62 -33
  335. package/docs/frameworks-ssr.md +12 -12
  336. package/docs/hybrid-apps.md +10 -10
  337. package/docs/migration-from-aos.md +5 -5
  338. package/docs/migration-from-gsap-scrolltrigger.md +3 -3
  339. package/docs/motion-tokens.css +1 -1
  340. package/docs/motion-tokens.md +2 -2
  341. package/docs/performance.md +6 -6
  342. package/docs/presets.md +5 -5
  343. package/docs/windows-apps.md +8 -8
  344. package/package.json +56 -25
  345. package/dist/chunks/base-B5i8qQPR.cjs.map +0 -1
  346. package/dist/chunks/base-C3Sw9sAO.js.map +0 -1
  347. package/dist/chunks/core-BVQW34aX.js.map +0 -1
  348. package/dist/chunks/core-BYLtO0Po.cjs.map +0 -1
  349. package/dist/chunks/presets-BJ09NeTo.js.map +0 -1
  350. package/dist/chunks/presets-D2ksQNzJ.cjs.map +0 -1
  351. package/dist/chunks/stagger-CvhYlKrF.cjs.map +0 -1
  352. package/dist/chunks/stagger-Dh4V-OL0.js.map +0 -1
@@ -0,0 +1,121 @@
1
+ import { e as animateWithMotion, i as getMotionSensitivity, p as prefersReducedMotion } from './base-C_3cAoRz.js';
2
+
3
+ var _a;
4
+ const EFFECT_KINDS = ['enter', 'exit', 'attention', 'click', 'hover', 'card', 'loop', 'page', 'background', 'text', 'cursor', 'scroll'];
5
+ const EFFECT_TRIGGERS = ['click', 'hover', 'enter', 'load', 'loop', 'manual'];
6
+ // 6.2: one table per page (Symbol.for), shared by every bundle that registers effects —
7
+ // e.g. dist/components.umd.js and dist/widgets.umd.js on the same page.
8
+ const REG_KEY = Symbol.for('use-scroll-animate.effects');
9
+ const registry = ((_a = globalThis)[REG_KEY] || (_a[REG_KEY] = new Map()));
10
+ /** Register an effect (throws on a duplicate name unless `override`). Returns an unregister function. */
11
+ function registerEffect(def, opts = {}) {
12
+ if (!/^[a-z][a-z0-9-]*$/.test(def.name))
13
+ throw new Error(`[motionary] invalid effect name "${def.name}"`);
14
+ if (!EFFECT_KINDS.includes(def.kind))
15
+ throw new Error(`[motionary] unknown effect kind "${def.kind}"`);
16
+ if (registry.has(def.name) && !opts.override)
17
+ throw new Error(`[motionary] effect "${def.name}" is already registered`);
18
+ registry.set(def.name, def);
19
+ return () => {
20
+ if (registry.get(def.name) === def)
21
+ registry.delete(def.name);
22
+ };
23
+ }
24
+ /** Register several effects at once (already-registered names are skipped). */
25
+ function registerEffects(defs) {
26
+ for (const d of defs)
27
+ if (!registry.has(d.name))
28
+ registerEffect(d);
29
+ }
30
+ const getEffect = (name) => registry.get(name);
31
+ const hasEffect = (name) => registry.has(name);
32
+ /** Registered effects (optionally of one kind), sorted by name. */
33
+ function listEffects(kind) {
34
+ return Array.from(registry.values())
35
+ .filter((d) => !kind || d.kind === kind)
36
+ .sort((a, b) => a.name.localeCompare(b.name));
37
+ }
38
+ const SKIP_BY_DEFAULT = ['loop', 'background', 'cursor'];
39
+ function context(event) {
40
+ const cleanups = [];
41
+ return {
42
+ reduced: prefersReducedMotion(),
43
+ sensitivity: getMotionSensitivity(),
44
+ event,
45
+ animate: animateWithMotion,
46
+ onCleanup: (fn) => cleanups.push(fn),
47
+ cleanups,
48
+ };
49
+ }
50
+ /**
51
+ * Play a registered effect once on `el`. Resolves when it finishes (or
52
+ * immediately for fire-and-forget effects). Unknown names reject.
53
+ */
54
+ async function playEffect(el, name, options = {}, event) {
55
+ const def = registry.get(name);
56
+ if (!def)
57
+ throw new Error(`[motionary] unknown effect "${name}" — registered: ${Array.from(registry.keys()).join(', ')}`);
58
+ const ctx = context(event);
59
+ if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip')
60
+ return;
61
+ const out = def.run(el, { ...(def.defaults || {}), ...options }, ctx);
62
+ if (out && typeof out.finished?.then === 'function')
63
+ await out.finished.catch(() => undefined);
64
+ else if (out && typeof out.then === 'function')
65
+ await out;
66
+ }
67
+ /**
68
+ * Bind an effect to a trigger on `el`: `click`, `hover` (pointerenter / focus),
69
+ * `enter` (scrolls into view; `once` by default), `load` (now), `loop`
70
+ * (starts now, cleanup stops it) or `manual` (nothing). Returns an unbind.
71
+ */
72
+ function bindEffect(el, name, options = {}) {
73
+ const { trigger = 'click', once, ...opts } = options;
74
+ const def = registry.get(name);
75
+ if (!def)
76
+ throw new Error(`[motionary] unknown effect "${name}"`);
77
+ const offs = [];
78
+ let current = null;
79
+ const fire = (e) => {
80
+ const ctx = context(e);
81
+ if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip')
82
+ return;
83
+ // A persistent effect (returns a cleanup) replaces its previous run instead of stacking.
84
+ current?.();
85
+ current = null;
86
+ const out = def.run(el, { ...(def.defaults || {}), ...opts }, ctx);
87
+ const stops = [...ctx.cleanups, ...(typeof out === 'function' ? [out] : [])];
88
+ if (stops.length)
89
+ current = () => stops.splice(0).forEach((f) => f());
90
+ };
91
+ offs.push(() => {
92
+ current?.();
93
+ current = null;
94
+ });
95
+ const on = (type, opt) => {
96
+ el.addEventListener(type, fire, opt);
97
+ offs.push(() => el.removeEventListener(type, fire, opt));
98
+ };
99
+ if (trigger === 'click')
100
+ on('click', { once: !!once });
101
+ else if (trigger === 'hover')
102
+ (on('pointerenter'), on('focusin'));
103
+ else if (trigger === 'load' || trigger === 'loop')
104
+ fire();
105
+ else if (trigger === 'enter' && typeof IntersectionObserver !== 'undefined') {
106
+ const io = new IntersectionObserver((entries) => {
107
+ for (const en of entries)
108
+ if (en.isIntersecting) {
109
+ fire();
110
+ if (once !== false)
111
+ io.disconnect();
112
+ }
113
+ }, { threshold: 0.15 });
114
+ io.observe(el);
115
+ offs.push(() => io.disconnect());
116
+ }
117
+ return () => offs.splice(0).reverse().forEach((f) => f());
118
+ }
119
+
120
+ export { EFFECT_KINDS as E, EFFECT_TRIGGERS as a, bindEffect as b, registerEffects as c, getEffect as g, hasEffect as h, listEffects as l, playEffect as p, registerEffect as r };
121
+ //# sourceMappingURL=registry-CKNLQpwd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-CKNLQpwd.js","sources":["../../src/components/fx/registry.ts"],"sourcesContent":["/**\n * 5.0 — unified plugin-style effect registration. Every effect (built-in or\n * yours) is a plain object registered once and played the same way:\n * `playEffect(el, name)`, `bindEffect(el, name, { trigger })` or\n * `<usa-fx effect=\"name\" trigger=\"click\">`. Effects get a context that\n * already applies reduced motion, motion sensitivity, intensity and the\n * animation budget.\n */\nimport { animateWithMotion, prefersReducedMotion, getMotionSensitivity, type MotionSensitivity, type Cleanup } from '../base';\n\nexport const EFFECT_KINDS = ['enter', 'exit', 'attention', 'click', 'hover', 'card', 'loop', 'page', 'background', 'text', 'cursor', 'scroll'] as const;\nexport type EffectKind = (typeof EFFECT_KINDS)[number];\n\nexport const EFFECT_TRIGGERS = ['click', 'hover', 'enter', 'load', 'loop', 'manual'] as const;\nexport type EffectTrigger = (typeof EFFECT_TRIGGERS)[number];\n\nexport interface EffectContext {\n /** Reduced motion applies (OS setting, `minimal` / `static` sensitivity). */\n readonly reduced: boolean;\n readonly sensitivity: MotionSensitivity;\n /** The triggering event (pointer position for click effects), if any. */\n readonly event?: Event;\n /** `el.animate()` with the library's motion rules (may return `null`). */\n animate(el: Element, keyframes: Keyframe[], options: KeyframeAnimationOptions): Animation | null;\n /** Register teardown for long-running effects (loops, listeners). */\n onCleanup(fn: Cleanup): void;\n}\n\nexport interface EffectDefinition<O extends Record<string, unknown> = Record<string, any>> {\n /** Unique, kebab-case. */\n name: string;\n kind: EffectKind;\n /** One line for docs and the gallery. */\n description?: string;\n /** Option defaults (merged under the caller's options). */\n defaults?: Partial<O>;\n /**\n * Under reduced motion: `'skip'` (do nothing — default for loop, background\n * and cursor effects) or `'run'` (run with `ctx.reduced === true`, the\n * effect degrades itself — default for everything else).\n */\n reduced?: 'skip' | 'run';\n /** Play the effect. Return an Animation / Promise to be awaited, or a cleanup. */\n run(el: HTMLElement, options: O, ctx: EffectContext): void | Cleanup | Animation | null | Promise<unknown>;\n}\n\n// 6.2: one table per page (Symbol.for), shared by every bundle that registers effects —\n// e.g. dist/components.umd.js and dist/widgets.umd.js on the same page.\nconst REG_KEY = Symbol.for('use-scroll-animate.effects');\nconst registry: Map<string, EffectDefinition> = ((globalThis as any)[REG_KEY] ||= new Map<string, EffectDefinition>());\n\n/** Register an effect (throws on a duplicate name unless `override`). Returns an unregister function. */\nexport function registerEffect<O extends Record<string, unknown>>(def: EffectDefinition<O>, opts: { override?: boolean } = {}): () => void {\n if (!/^[a-z][a-z0-9-]*$/.test(def.name)) throw new Error(`[motionary] invalid effect name \"${def.name}\"`);\n if (!EFFECT_KINDS.includes(def.kind)) throw new Error(`[motionary] unknown effect kind \"${def.kind}\"`);\n if (registry.has(def.name) && !opts.override) throw new Error(`[motionary] effect \"${def.name}\" is already registered`);\n registry.set(def.name, def as unknown as EffectDefinition);\n return () => {\n if (registry.get(def.name) === (def as unknown)) registry.delete(def.name);\n };\n}\n\n/** Register several effects at once (already-registered names are skipped). */\nexport function registerEffects(defs: EffectDefinition<any>[]): void {\n for (const d of defs) if (!registry.has(d.name)) registerEffect(d);\n}\n\nexport const getEffect = (name: string): EffectDefinition | undefined => registry.get(name);\nexport const hasEffect = (name: string): boolean => registry.has(name);\n/** Registered effects (optionally of one kind), sorted by name. */\nexport function listEffects(kind?: EffectKind): EffectDefinition[] {\n return Array.from(registry.values())\n .filter((d) => !kind || d.kind === kind)\n .sort((a, b) => a.name.localeCompare(b.name));\n}\n\nconst SKIP_BY_DEFAULT: EffectKind[] = ['loop', 'background', 'cursor'];\n\nfunction context(event?: Event): EffectContext & { cleanups: Cleanup[] } {\n const cleanups: Cleanup[] = [];\n return {\n reduced: prefersReducedMotion(),\n sensitivity: getMotionSensitivity(),\n event,\n animate: animateWithMotion,\n onCleanup: (fn) => cleanups.push(fn),\n cleanups,\n };\n}\n\n/**\n * Play a registered effect once on `el`. Resolves when it finishes (or\n * immediately for fire-and-forget effects). Unknown names reject.\n */\nexport async function playEffect(el: HTMLElement, name: string, options: Record<string, unknown> = {}, event?: Event): Promise<void> {\n const def = registry.get(name);\n if (!def) throw new Error(`[motionary] unknown effect \"${name}\" — registered: ${Array.from(registry.keys()).join(', ')}`);\n const ctx = context(event);\n if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip') return;\n const out = def.run(el, { ...(def.defaults || {}), ...options }, ctx);\n if (out && typeof (out as Animation).finished?.then === 'function') await (out as Animation).finished.catch(() => undefined);\n else if (out && typeof (out as Promise<unknown>).then === 'function') await out;\n}\n\n/**\n * Bind an effect to a trigger on `el`: `click`, `hover` (pointerenter / focus),\n * `enter` (scrolls into view; `once` by default), `load` (now), `loop`\n * (starts now, cleanup stops it) or `manual` (nothing). Returns an unbind.\n */\nexport function bindEffect(el: HTMLElement, name: string, options: Record<string, unknown> & { trigger?: EffectTrigger; once?: boolean } = {}): Cleanup {\n const { trigger = 'click', once, ...opts } = options;\n const def = registry.get(name);\n if (!def) throw new Error(`[motionary] unknown effect \"${name}\"`);\n const offs: Cleanup[] = [];\n let current: Cleanup | null = null;\n const fire = (e?: Event) => {\n const ctx = context(e);\n if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip') return;\n // A persistent effect (returns a cleanup) replaces its previous run instead of stacking.\n current?.();\n current = null;\n const out = def.run(el, { ...(def.defaults || {}), ...opts }, ctx);\n const stops = [...ctx.cleanups, ...(typeof out === 'function' ? [out as Cleanup] : [])];\n if (stops.length) current = () => stops.splice(0).forEach((f) => f());\n };\n offs.push(() => {\n current?.();\n current = null;\n });\n const on = (type: string, opt?: AddEventListenerOptions) => {\n el.addEventListener(type, fire, opt);\n offs.push(() => el.removeEventListener(type, fire, opt));\n };\n if (trigger === 'click') on('click', { once: !!once });\n else if (trigger === 'hover') (on('pointerenter'), on('focusin'));\n else if (trigger === 'load' || trigger === 'loop') fire();\n else if (trigger === 'enter' && typeof IntersectionObserver !== 'undefined') {\n const io = new IntersectionObserver((entries) => {\n for (const en of entries)\n if (en.isIntersecting) {\n fire();\n if (once !== false) io.disconnect();\n }\n }, { threshold: 0.15 });\n io.observe(el);\n offs.push(() => io.disconnect());\n }\n return () => offs.splice(0).reverse().forEach((f) => f());\n}\n"],"names":[],"mappings":";;;AAUO,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;AAGtI,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ;AAiCnF;AACA;AACA,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC;AACxD,MAAM,QAAQ,IAAkC,CAAA,EAAA,GAAE,UAAkB,EAAC,OAAO,CAAA,KAAA,EAAA,CAAP,OAAO,CAAA,GAAM,IAAI,GAAG,EAA4B,EAAC;AAEtH;SACgB,cAAc,CAAoC,GAAwB,EAAE,OAA+B,EAAE,EAAA;IAC3H,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,CAAA,iCAAA,EAAoC,GAAG,CAAC,IAAI,CAAA,CAAA,CAAG,CAAC;IACzG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,M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,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3D;;;;"}
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ var base = require('./base-BaQV-2ha.cjs');
4
+
5
+ var _a;
6
+ const EFFECT_KINDS = ['enter', 'exit', 'attention', 'click', 'hover', 'card', 'loop', 'page', 'background', 'text', 'cursor', 'scroll'];
7
+ const EFFECT_TRIGGERS = ['click', 'hover', 'enter', 'load', 'loop', 'manual'];
8
+ // 6.2: one table per page (Symbol.for), shared by every bundle that registers effects —
9
+ // e.g. dist/components.umd.js and dist/widgets.umd.js on the same page.
10
+ const REG_KEY = Symbol.for('use-scroll-animate.effects');
11
+ const registry = ((_a = globalThis)[REG_KEY] || (_a[REG_KEY] = new Map()));
12
+ /** Register an effect (throws on a duplicate name unless `override`). Returns an unregister function. */
13
+ function registerEffect(def, opts = {}) {
14
+ if (!/^[a-z][a-z0-9-]*$/.test(def.name))
15
+ throw new Error(`[motionary] invalid effect name "${def.name}"`);
16
+ if (!EFFECT_KINDS.includes(def.kind))
17
+ throw new Error(`[motionary] unknown effect kind "${def.kind}"`);
18
+ if (registry.has(def.name) && !opts.override)
19
+ throw new Error(`[motionary] effect "${def.name}" is already registered`);
20
+ registry.set(def.name, def);
21
+ return () => {
22
+ if (registry.get(def.name) === def)
23
+ registry.delete(def.name);
24
+ };
25
+ }
26
+ /** Register several effects at once (already-registered names are skipped). */
27
+ function registerEffects(defs) {
28
+ for (const d of defs)
29
+ if (!registry.has(d.name))
30
+ registerEffect(d);
31
+ }
32
+ const getEffect = (name) => registry.get(name);
33
+ const hasEffect = (name) => registry.has(name);
34
+ /** Registered effects (optionally of one kind), sorted by name. */
35
+ function listEffects(kind) {
36
+ return Array.from(registry.values())
37
+ .filter((d) => !kind || d.kind === kind)
38
+ .sort((a, b) => a.name.localeCompare(b.name));
39
+ }
40
+ const SKIP_BY_DEFAULT = ['loop', 'background', 'cursor'];
41
+ function context(event) {
42
+ const cleanups = [];
43
+ return {
44
+ reduced: base.prefersReducedMotion(),
45
+ sensitivity: base.getMotionSensitivity(),
46
+ event,
47
+ animate: base.animateWithMotion,
48
+ onCleanup: (fn) => cleanups.push(fn),
49
+ cleanups,
50
+ };
51
+ }
52
+ /**
53
+ * Play a registered effect once on `el`. Resolves when it finishes (or
54
+ * immediately for fire-and-forget effects). Unknown names reject.
55
+ */
56
+ async function playEffect(el, name, options = {}, event) {
57
+ const def = registry.get(name);
58
+ if (!def)
59
+ throw new Error(`[motionary] unknown effect "${name}" — registered: ${Array.from(registry.keys()).join(', ')}`);
60
+ const ctx = context(event);
61
+ if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip')
62
+ return;
63
+ const out = def.run(el, { ...(def.defaults || {}), ...options }, ctx);
64
+ if (out && typeof out.finished?.then === 'function')
65
+ await out.finished.catch(() => undefined);
66
+ else if (out && typeof out.then === 'function')
67
+ await out;
68
+ }
69
+ /**
70
+ * Bind an effect to a trigger on `el`: `click`, `hover` (pointerenter / focus),
71
+ * `enter` (scrolls into view; `once` by default), `load` (now), `loop`
72
+ * (starts now, cleanup stops it) or `manual` (nothing). Returns an unbind.
73
+ */
74
+ function bindEffect(el, name, options = {}) {
75
+ const { trigger = 'click', once, ...opts } = options;
76
+ const def = registry.get(name);
77
+ if (!def)
78
+ throw new Error(`[motionary] unknown effect "${name}"`);
79
+ const offs = [];
80
+ let current = null;
81
+ const fire = (e) => {
82
+ const ctx = context(e);
83
+ if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip')
84
+ return;
85
+ // A persistent effect (returns a cleanup) replaces its previous run instead of stacking.
86
+ current?.();
87
+ current = null;
88
+ const out = def.run(el, { ...(def.defaults || {}), ...opts }, ctx);
89
+ const stops = [...ctx.cleanups, ...(typeof out === 'function' ? [out] : [])];
90
+ if (stops.length)
91
+ current = () => stops.splice(0).forEach((f) => f());
92
+ };
93
+ offs.push(() => {
94
+ current?.();
95
+ current = null;
96
+ });
97
+ const on = (type, opt) => {
98
+ el.addEventListener(type, fire, opt);
99
+ offs.push(() => el.removeEventListener(type, fire, opt));
100
+ };
101
+ if (trigger === 'click')
102
+ on('click', { once: !!once });
103
+ else if (trigger === 'hover')
104
+ (on('pointerenter'), on('focusin'));
105
+ else if (trigger === 'load' || trigger === 'loop')
106
+ fire();
107
+ else if (trigger === 'enter' && typeof IntersectionObserver !== 'undefined') {
108
+ const io = new IntersectionObserver((entries) => {
109
+ for (const en of entries)
110
+ if (en.isIntersecting) {
111
+ fire();
112
+ if (once !== false)
113
+ io.disconnect();
114
+ }
115
+ }, { threshold: 0.15 });
116
+ io.observe(el);
117
+ offs.push(() => io.disconnect());
118
+ }
119
+ return () => offs.splice(0).reverse().forEach((f) => f());
120
+ }
121
+
122
+ exports.EFFECT_KINDS = EFFECT_KINDS;
123
+ exports.EFFECT_TRIGGERS = EFFECT_TRIGGERS;
124
+ exports.bindEffect = bindEffect;
125
+ exports.getEffect = getEffect;
126
+ exports.hasEffect = hasEffect;
127
+ exports.listEffects = listEffects;
128
+ exports.playEffect = playEffect;
129
+ exports.registerEffect = registerEffect;
130
+ exports.registerEffects = registerEffects;
131
+ //# sourceMappingURL=registry-DehBVRDV.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-DehBVRDV.cjs","sources":["../../src/components/fx/registry.ts"],"sourcesContent":["/**\n * 5.0 — unified plugin-style effect registration. Every effect (built-in or\n * yours) is a plain object registered once and played the same way:\n * `playEffect(el, name)`, `bindEffect(el, name, { trigger })` or\n * `<usa-fx effect=\"name\" trigger=\"click\">`. Effects get a context that\n * already applies reduced motion, motion sensitivity, intensity and the\n * animation budget.\n */\nimport { animateWithMotion, prefersReducedMotion, getMotionSensitivity, type MotionSensitivity, type Cleanup } from '../base';\n\nexport const EFFECT_KINDS = ['enter', 'exit', 'attention', 'click', 'hover', 'card', 'loop', 'page', 'background', 'text', 'cursor', 'scroll'] as const;\nexport type EffectKind = (typeof EFFECT_KINDS)[number];\n\nexport const EFFECT_TRIGGERS = ['click', 'hover', 'enter', 'load', 'loop', 'manual'] as const;\nexport type EffectTrigger = (typeof EFFECT_TRIGGERS)[number];\n\nexport interface EffectContext {\n /** Reduced motion applies (OS setting, `minimal` / `static` sensitivity). */\n readonly reduced: boolean;\n readonly sensitivity: MotionSensitivity;\n /** The triggering event (pointer position for click effects), if any. */\n readonly event?: Event;\n /** `el.animate()` with the library's motion rules (may return `null`). */\n animate(el: Element, keyframes: Keyframe[], options: KeyframeAnimationOptions): Animation | null;\n /** Register teardown for long-running effects (loops, listeners). */\n onCleanup(fn: Cleanup): void;\n}\n\nexport interface EffectDefinition<O extends Record<string, unknown> = Record<string, any>> {\n /** Unique, kebab-case. */\n name: string;\n kind: EffectKind;\n /** One line for docs and the gallery. */\n description?: string;\n /** Option defaults (merged under the caller's options). */\n defaults?: Partial<O>;\n /**\n * Under reduced motion: `'skip'` (do nothing — default for loop, background\n * and cursor effects) or `'run'` (run with `ctx.reduced === true`, the\n * effect degrades itself — default for everything else).\n */\n reduced?: 'skip' | 'run';\n /** Play the effect. Return an Animation / Promise to be awaited, or a cleanup. */\n run(el: HTMLElement, options: O, ctx: EffectContext): void | Cleanup | Animation | null | Promise<unknown>;\n}\n\n// 6.2: one table per page (Symbol.for), shared by every bundle that registers effects —\n// e.g. dist/components.umd.js and dist/widgets.umd.js on the same page.\nconst REG_KEY = Symbol.for('use-scroll-animate.effects');\nconst registry: Map<string, EffectDefinition> = ((globalThis as any)[REG_KEY] ||= new Map<string, EffectDefinition>());\n\n/** Register an effect (throws on a duplicate name unless `override`). Returns an unregister function. */\nexport function registerEffect<O extends Record<string, unknown>>(def: EffectDefinition<O>, opts: { override?: boolean } = {}): () => void {\n if (!/^[a-z][a-z0-9-]*$/.test(def.name)) throw new Error(`[motionary] invalid effect name \"${def.name}\"`);\n if (!EFFECT_KINDS.includes(def.kind)) throw new Error(`[motionary] unknown effect kind \"${def.kind}\"`);\n if (registry.has(def.name) && !opts.override) throw new Error(`[motionary] effect \"${def.name}\" is already registered`);\n registry.set(def.name, def as unknown as EffectDefinition);\n return () => {\n if (registry.get(def.name) === (def as unknown)) registry.delete(def.name);\n };\n}\n\n/** Register several effects at once (already-registered names are skipped). */\nexport function registerEffects(defs: EffectDefinition<any>[]): void {\n for (const d of defs) if (!registry.has(d.name)) registerEffect(d);\n}\n\nexport const getEffect = (name: string): EffectDefinition | undefined => registry.get(name);\nexport const hasEffect = (name: string): boolean => registry.has(name);\n/** Registered effects (optionally of one kind), sorted by name. */\nexport function listEffects(kind?: EffectKind): EffectDefinition[] {\n return Array.from(registry.values())\n .filter((d) => !kind || d.kind === kind)\n .sort((a, b) => a.name.localeCompare(b.name));\n}\n\nconst SKIP_BY_DEFAULT: EffectKind[] = ['loop', 'background', 'cursor'];\n\nfunction context(event?: Event): EffectContext & { cleanups: Cleanup[] } {\n const cleanups: Cleanup[] = [];\n return {\n reduced: prefersReducedMotion(),\n sensitivity: getMotionSensitivity(),\n event,\n animate: animateWithMotion,\n onCleanup: (fn) => cleanups.push(fn),\n cleanups,\n };\n}\n\n/**\n * Play a registered effect once on `el`. Resolves when it finishes (or\n * immediately for fire-and-forget effects). Unknown names reject.\n */\nexport async function playEffect(el: HTMLElement, name: string, options: Record<string, unknown> = {}, event?: Event): Promise<void> {\n const def = registry.get(name);\n if (!def) throw new Error(`[motionary] unknown effect \"${name}\" — registered: ${Array.from(registry.keys()).join(', ')}`);\n const ctx = context(event);\n if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip') return;\n const out = def.run(el, { ...(def.defaults || {}), ...options }, ctx);\n if (out && typeof (out as Animation).finished?.then === 'function') await (out as Animation).finished.catch(() => undefined);\n else if (out && typeof (out as Promise<unknown>).then === 'function') await out;\n}\n\n/**\n * Bind an effect to a trigger on `el`: `click`, `hover` (pointerenter / focus),\n * `enter` (scrolls into view; `once` by default), `load` (now), `loop`\n * (starts now, cleanup stops it) or `manual` (nothing). Returns an unbind.\n */\nexport function bindEffect(el: HTMLElement, name: string, options: Record<string, unknown> & { trigger?: EffectTrigger; once?: boolean } = {}): Cleanup {\n const { trigger = 'click', once, ...opts } = options;\n const def = registry.get(name);\n if (!def) throw new Error(`[motionary] unknown effect \"${name}\"`);\n const offs: Cleanup[] = [];\n let current: Cleanup | null = null;\n const fire = (e?: Event) => {\n const ctx = context(e);\n if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip') return;\n // A persistent effect (returns a cleanup) replaces its previous run instead of stacking.\n current?.();\n current = null;\n const out = def.run(el, { ...(def.defaults || {}), ...opts }, ctx);\n const stops = [...ctx.cleanups, ...(typeof out === 'function' ? [out as Cleanup] : [])];\n if (stops.length) current = () => stops.splice(0).forEach((f) => f());\n };\n offs.push(() => {\n current?.();\n current = null;\n });\n const on = (type: string, opt?: AddEventListenerOptions) => {\n el.addEventListener(type, fire, opt);\n offs.push(() => el.removeEventListener(type, fire, opt));\n };\n if (trigger === 'click') on('click', { once: !!once });\n else if (trigger === 'hover') (on('pointerenter'), on('focusin'));\n else if (trigger === 'load' || trigger === 'loop') fire();\n else if (trigger === 'enter' && typeof IntersectionObserver !== 'undefined') {\n const io = new IntersectionObserver((entries) => {\n for (const en of entries)\n if (en.isIntersecting) {\n fire();\n if (once !== false) io.disconnect();\n }\n }, { threshold: 0.15 });\n io.observe(el);\n offs.push(() => io.disconnect());\n }\n return () => offs.splice(0).reverse().forEach((f) => f());\n}\n"],"names":["prefersReducedMotion","getMotionSensitivity","animateWithMotion"],"mappings":";;;;;AAUO,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;AAGtI,MAAM,eAAe,GAAG,CAAC,OAAO,EAA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,OAAO,KAAK,OAAO,IAAI,OAAO,oBAAoB,KAAK,WAAW,EAAE;QAC3E,MAAM,EAAE,GAAG,IAAI,oBAAoB,CAAC,CAAC,OAAO,KAAI;YAC9C,KAAK,MAAM,EAAE,IAAI,OAAO;AACtB,gBAAA,IAAI,EAAE,CAAC,cAAc,EAAE;AACrB,oBAAA,IAAI,EAAE;oBACN,IAAI,IAAI,KAAK,KAAK;wBAAE,EAAE,CAAC,UAAU,EAAE;gBACrC;AACJ,QAAA,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACvB,QAAA,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;QACd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC;IAClC;IACA,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3D;;;;;;;;;;;;"}
@@ -1,4 +1,4 @@
1
- import { p as prefersReducedMotion, l as applyFrame, m as motionScale, E as EASE_SPRING, n as now, r as raf, q as caf } from './base-C3Sw9sAO.js';
1
+ import { p as prefersReducedMotion, n as applyFrame, m as motionScale, E as EASE_SPRING, q as now, r as raf, l as caf } from './base-C_3cAoRz.js';
2
2
 
3
3
  const SPRING_PRESETS = {
4
4
  default: { stiffness: 170, damping: 26, mass: 1 },
@@ -216,4 +216,4 @@ function rubberBand(distance, dimension, constant = 0.55) {
216
216
  }
217
217
 
218
218
  export { SPRING_PRESETS as S, rubberBand as a, spring as b, createSpring as c, springEasing as d, springSamples as e, stepSpring as f, supportsLinearEasing as g, linearEasing as l, projectInertia as p, resolveSpring as r, snapTo as s };
219
- //# sourceMappingURL=spring-CckMe3x0.js.map
219
+ //# sourceMappingURL=spring-CbvHfVtP.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spring-CckMe3x0.js","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC/C,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC9C,IAAA,QAAQ,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE;;AAKrD;AACM,SAAU,aAAa,CAAC,KAAmB,EAAA;AAC/C,IAAA,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,cAAc,CAAC,KAAqB,CAAC,IAAI,cAAc,CAAC,OAAO,GA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E,QAAgB,EAAE,YAAY,GAAG,KAAK,EAAA;AAClF,IAAA,OAAO,KAAK,GAAG,QAAQ,GAAG,YAAY;AACxC;AAEA;AACM,SAAU,MAAM,CAAC,KAAa,EAAE,EAAwC,EAAA;AAC5E,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACrB,IAAI,CAAC,EAAE,CAAC,MAAM;AAAE,YAAA,OAAO,KAAK;QAC5B,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACjG;AACA,IAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE;AACxE,IAAA,OAAO,KAAK;AACd;AAEA;AACM,SAAU,UAAU,CAAC,QAAgB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAA;IAC7E,IAAI,SAAS,IAAI,CAAC;AAAE,QAAA,OAAO,CAAC;AAC5B,IAAA,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS;AACtE;;;;"}
1
+ {"version":3,"file":"spring-CbvHfVtP.js","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC/C,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC9C,IAAA,QAAQ,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE;;AAKrD;AACM,SAAU,aAAa,CAAC,KAAmB,EAAA;AAC/C,IAAA,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,cAAc,CAAC,KAAqB,CAAC,IAAI,cAAc,CAAC,OAAO,GAAG,EAAE,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC,EAAE;A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GAAG,YAAY;AACxC;AAEA;AACM,SAAU,MAAM,CAAC,KAAa,EAAE,EAAwC,EAAA;AAC5E,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACrB,IAAI,CAAC,EAAE,CAAC,MAAM;AAAE,YAAA,OAAO,KAAK;QAC5B,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACjG;AACA,IAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE;AACxE,IAAA,OAAO,KAAK;AACd;AAEA;AACM,SAAU,UAAU,CAAC,QAAgB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAA;IAC7E,IAAI,SAAS,IAAI,CAAC;AAAE,QAAA,OAAO,CAAC;AAC5B,IAAA,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS;AACtE;;;;"}
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var base = require('./base-B5i8qQPR.cjs');
3
+ var base = require('./base-BaQV-2ha.cjs');
4
4
 
5
5
  const SPRING_PRESETS = {
6
6
  default: { stiffness: 170, damping: 26, mass: 1 },
@@ -229,4 +229,4 @@ exports.springEasing = springEasing;
229
229
  exports.springSamples = springSamples;
230
230
  exports.stepSpring = stepSpring;
231
231
  exports.supportsLinearEasing = supportsLinearEasing;
232
- //# sourceMappingURL=spring--oZh55tB.cjs.map
232
+ //# sourceMappingURL=spring-Dgx187Vh.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"spring--oZh55tB.cjs","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":["EASE_SPRING","prefersReducedMotion","applyFrame","motionScale","caf","now","raf"],"mappings":";;;;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC/C,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,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AC;IAC5B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS;AACtE;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"spring-Dgx187Vh.cjs","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":["EASE_SPRING","prefersReducedMotion","applyFrame","motionScale","caf","now","raf"],"mappings":";;;;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC/C,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC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AAC;IAC5B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS;AACtE;;;;;;;;;;;;;;;"}
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var core = require('./core-BYLtO0Po.cjs');
3
+ var core = require('./core-B5T0dhFH.cjs');
4
4
 
5
5
  /**
6
- * use-scroll-animate - Staggered children
6
+ * motionary - Staggered children
7
7
  * Reveal a container's children one after another when the container scrolls
8
8
  * into view, optionally also animating children that are added later.
9
9
  */
@@ -83,4 +83,4 @@ function staggerChildren(container, options = {}, instance) {
83
83
  }
84
84
 
85
85
  exports.staggerChildren = staggerChildren;
86
- //# sourceMappingURL=stagger-CvhYlKrF.cjs.map
86
+ //# sourceMappingURL=stagger-CCFyhzSw.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagger-CCFyhzSw.cjs","sources":["../../src/stagger.ts"],"sourcesContent":["/**\n * motionary - Staggered children\n * Reveal a container's children one after another when the container scrolls\n * into view, optionally also animating children that are added later.\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate, hasDOM, prepareElement, stopAnimation, supportsObserver } from './core';\n\nexport interface StaggerOptions extends AnimateOptions {\n /** Delay between consecutive children in ms (default: 80) */\n stagger?: number;\n /**\n * Watch the container with a MutationObserver and animate children added\n * later (e.g. infinite lists). Children added after the container was\n * revealed animate when they scroll into view, staggered per batch.\n * (default: false)\n */\n observeChildren?: boolean;\n}\n\nlet fallback: ScrollAnimateInstance | null = null;\n\n/**\n * Animate the children of `container` with a stagger once it enters the\n * viewport. Returns a cleanup function. SSR-safe (no-op without a DOM).\n *\n * @example\n * const stop = staggerChildren(document.querySelector('ul'), { stagger: 60, observeChildren: true });\n */\nexport function staggerChildren(\n container: Element | null | undefined,\n options: StaggerOptions = {},\n instance?: ScrollAnimateInstance\n): () => void {\n if (!container || !hasDOM() || !supportsObserver()) return () => undefined; // leave content visible\n const sa = instance || fallback || (fallback = createScrollAnimate());\n const { stagger = 80, delay = 0, threshold = 0.1, rootMargin = '0px', observeChildren = false, ...rest } = options;\n\n let items = Array.from(container.children);\n let revealed = false;\n const late: Element[] = [];\n items.forEach((child) => prepareElement(child));\n\n const io = new IntersectionObserver(\n (entries) => {\n if (revealed || !entries.some((entry) => entry.isIntersecting)) return;\n revealed = true;\n io.disconnect();\n items.forEach((child, i) => {\n if (child.parentNode === container) sa.animate(child, { ...rest, delay: delay + i * stagger });\n });\n items = [];\n },\n { threshold, rootMargin }\n );\n io.observe(container);\n\n let mo: MutationObserver | undefined;\n if (observeChildren && typeof MutationObserver !== 'undefined') {\n mo = new MutationObserver((records) => {\n records.forEach((record) => {\n record.addedNodes.forEach((node) => {\n if (!(node instanceof Element) || node.parentNode !== container) return;\n if (!revealed) {\n prepareElement(node);\n items.push(node);\n } else {\n // The core engine staggers siblings relative to the batch that\n // enters the viewport together.\n late.push(node);\n sa.observe(node, { ...rest, delay, stagger, threshold, rootMargin });\n }\n });\n record.removedNodes.forEach((node) => {\n if (!(node instanceof Element)) return;\n items = items.filter((el) => el !== node);\n const i = late.indexOf(node);\n if (i >= 0) {\n late.splice(i, 1);\n sa.unobserve(node);\n }\n });\n });\n });\n mo.observe(container, { childList: true });\n }\n\n return () => {\n io.disconnect();\n mo?.disconnect();\n // Stopped before the container was revealed: never leave the children hidden.\n if (!revealed) {\n revealed = true;\n items.forEach((child) => stopAnimation(child));\n items = [];\n }\n late.forEach((el) => sa.unobserve(el));\n late.length = 0;\n };\n}\n"],"names":["hasDOM","supportsObserver","createScrollAnimate","prepareElement","stopAnimation"],"mappings":";;;;AAAA;;;;AAIG;AAiBH,IAAI,QAAQ,GAAiC,IAAI;AAEjD;;;;;;AAMG;AACG,SAAU,eAAe,CAC7B,SAAqC,EACrC,OAAA,GAA0B,EAAE,EAC5B,QAAgC,EAAA;IAEhC,IAAI,CAAC,SAAS,IAAI,CAAC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AA,OAAO,MAAK;QACV,EAAE,CAAC,UAAU,EAAE;QACf,EAAE,EAAE,UAAU,EAAE;;QAEhB,IAAI,CAAC,QAAQ,EAAE;YACb,QAAQ,GAAG,IAAI;AACf,YAAA,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,KAAKC,kBAAa,CAAC,KAAK,CAAC,CAAC;YAC9C,KAAK,GAAG,EAAE;QACZ;AACA,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACtC,QAAA,IAAI,CAAC,MAAM,GAAG,CAAC;AACjB,IAAA,CAAC;AACH;;;;"}
@@ -1,7 +1,7 @@
1
- import { h as hasDOM, s as supportsObserver, c as createScrollAnimate, p as prepareElement, a as stopAnimation } from './core-BVQW34aX.js';
1
+ import { h as hasDOM, s as supportsObserver, c as createScrollAnimate, p as prepareElement, a as stopAnimation } from './core-D7cVumUu.js';
2
2
 
3
3
  /**
4
- * use-scroll-animate - Staggered children
4
+ * motionary - Staggered children
5
5
  * Reveal a container's children one after another when the container scrolls
6
6
  * into view, optionally also animating children that are added later.
7
7
  */
@@ -81,4 +81,4 @@ function staggerChildren(container, options = {}, instance) {
81
81
  }
82
82
 
83
83
  export { staggerChildren as s };
84
- //# sourceMappingURL=stagger-Dh4V-OL0.js.map
84
+ //# sourceMappingURL=stagger-DtMKo2SK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagger-DtMKo2SK.js","sources":["../../src/stagger.ts"],"sourcesContent":["/**\n * motionary - Staggered children\n * Reveal a container's children one after another when the container scrolls\n * into view, optionally also animating children that are added later.\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate, hasDOM, prepareElement, stopAnimation, supportsObserver } from './core';\n\nexport interface StaggerOptions extends AnimateOptions {\n /** Delay between consecutive children in ms (default: 80) */\n stagger?: number;\n /**\n * Watch the container with a MutationObserver and animate children added\n * later (e.g. infinite lists). Children added after the container was\n * revealed animate when they scroll into view, staggered per batch.\n * (default: false)\n */\n observeChildren?: boolean;\n}\n\nlet fallback: ScrollAnimateInstance | null = null;\n\n/**\n * Animate the children of `container` with a stagger once it enters the\n * viewport. Returns a cleanup function. SSR-safe (no-op without a DOM).\n *\n * @example\n * const stop = staggerChildren(document.querySelector('ul'), { stagger: 60, observeChildren: true });\n */\nexport function staggerChildren(\n container: Element | null | undefined,\n options: StaggerOptions = {},\n instance?: ScrollAnimateInstance\n): () => void {\n if (!container || !hasDOM() || !supportsObserver()) return () => undefined; // leave content visible\n const sa = instance || fallback || (fallback = createScrollAnimate());\n const { stagger = 80, delay = 0, threshold = 0.1, rootMargin = '0px', observeChildren = false, ...rest } = options;\n\n let items = Array.from(container.children);\n let revealed = false;\n const late: Element[] = [];\n items.forEach((child) => prepareElement(child));\n\n const io = new IntersectionObserver(\n (entries) => {\n if (revealed || !entries.some((entry) => entry.isIntersecting)) return;\n revealed = true;\n io.disconnect();\n items.forEach((child, i) => {\n if (child.parentNode === container) sa.animate(child, { ...rest, delay: delay + i * stagger });\n });\n items = [];\n },\n { threshold, rootMargin }\n );\n io.observe(container);\n\n let mo: MutationObserver | undefined;\n if (observeChildren && typeof MutationObserver !== 'undefined') {\n mo = new MutationObserver((records) => {\n records.forEach((record) => {\n record.addedNodes.forEach((node) => {\n if (!(node instanceof Element) || node.parentNode !== container) return;\n if (!revealed) {\n prepareElement(node);\n items.push(node);\n } else {\n // The core engine staggers siblings relative to the batch that\n // enters the viewport together.\n late.push(node);\n sa.observe(node, { ...rest, delay, stagger, threshold, rootMargin });\n }\n });\n record.removedNodes.forEach((node) => {\n if (!(node instanceof Element)) return;\n items = items.filter((el) => el !== node);\n const i = late.indexOf(node);\n if (i >= 0) {\n late.splice(i, 1);\n sa.unobserve(node);\n }\n });\n });\n });\n mo.observe(container, { childList: true });\n }\n\n return () => {\n io.disconnect();\n mo?.disconnect();\n // Stopped before the container was revealed: never leave the children hidden.\n if (!revealed) {\n revealed = true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AA,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AACjB,wBAAA,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC;oBACpB;AACF,gBAAA,CAAC,CAAC;AACJ,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC,CAAC;QACF,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC5C;AAEA,IAAA,OAAO,MAAK;QACV,EAAE,CAAC,UAAU,EAAE;QACf,EAAE,EAAE,UAAU,EAAE;;QAEhB,IAAI,CAAC,QAAQ,EAAE;YACb,QAAQ,GAAG,IAAI;AACf,YAAA,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,aAAa,CAAC,KAAK,CAAC,CAAC;YAC9C,KAAK,GAAG,EAAE;QACZ;AACA,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACtC,QAAA,IAAI,CAAC,MAAM,GAAG,CAAC;AACjB,IAAA,CAAC;AACH;;;;"}
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var base = require('./base-B5i8qQPR.cjs');
3
+ var base = require('./base-BaQV-2ha.cjs');
4
4
 
5
5
  var css = ":root{--usa-accent:#7c5cff;--usa-accent-text:#fff;--usa-surface:#1b1e27;--usa-text:inherit;--usa-radius:14px;--usa-border:1px solid rgb(127 127 127 / 0.25);--usa-shadow:0 10px 30px -12px rgb(0 0 0 / 0.45);--usa-blur:0px;--usa-font:inherit}:where([variant=\"minimal\"],[data-usa-variant=\"minimal\"]){--usa-accent:currentColor;--usa-accent-text:Canvas;--usa-surface:transparent;--usa-radius:6px;--usa-border:1px solid color-mix(in srgb,currentColor 22%,transparent);--usa-shadow:none;--usa-blur:0px}:where([variant=\"neon\"],[data-usa-variant=\"neon\"]){--usa-accent:#00f0ff;--usa-accent-text:#04121a;--usa-surface:#0a0b14;--usa-text:#e6fbff;--usa-radius:10px;--usa-border:1px solid #00f0ff;--usa-shadow:0 0 6px #00f0ff,0 0 22px rgb(0 240 255 / 0.45);--usa-blur:0px}:where([variant=\"glass\"],[data-usa-variant=\"glass\"]){--usa-accent:#a78bfa;--usa-accent-text:#fff;--usa-surface:rgb(255 255 255 / 0.12);--usa-radius:18px;--usa-border:1px solid rgb(255 255 255 / 0.28);--usa-shadow:0 12px 40px -12px rgb(0 0 0 / 0.35);--usa-blur:16px}:where([variant=\"brutalist\"],[data-usa-variant=\"brutalist\"]){--usa-accent:#ff3d00;--usa-accent-text:#000;--usa-surface:#fff;--usa-text:#000;--usa-radius:0px;--usa-border:3px solid #000;--usa-shadow:5px 5px 0 #000;--usa-blur:0px;--usa-font:ui-monospace,\"SFMono-Regular\",Menlo,monospace}:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#0067c0;--usa-accent-text:#fff;--usa-surface:rgb(249 249 249 / 0.82);--usa-text:#1a1a1a;--usa-radius:8px;--usa-border:1px solid rgb(0 0 0 / 0.08);--usa-shadow:0 2px 4px rgb(0 0 0 / 0.14),0 0 2px rgb(0 0 0 / 0.12);--usa-blur:30px;--usa-font:\"Segoe UI Variable\",\"Segoe UI\",system-ui,sans-serif}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#6750a4;--usa-accent-text:#fff;--usa-surface:#fffbfe;--usa-text:#1c1b1f;--usa-radius:20px;--usa-border:0 solid transparent;--usa-shadow:0 1px 3px rgb(0 0 0 / 0.3),0 4px 8px 3px rgb(0 0 0 / 0.15);--usa-blur:0px;--usa-font:Roboto,system-ui,sans-serif}@media (prefers-color-scheme:dark){:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#4cc2ff;--usa-accent-text:#000;--usa-surface:rgb(44 44 44 / 0.8);--usa-text:#fff;--usa-border:1px solid rgb(255 255 255 / 0.08)}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#d0bcff;--usa-accent-text:#381e72;--usa-surface:#1c1b1f;--usa-text:#e6e1e5}}.usa-surface{background:var(--usa-surface);color:var(--usa-text);border:var(--usa-border);border-radius:var(--usa-radius);box-shadow:var(--usa-shadow);font-family:var(--usa-font);-webkit-backdrop-filter:blur(var(--usa-blur));backdrop-filter:blur(var(--usa-blur))}@media (prefers-reduced-transparency:reduce){.usa-surface{-webkit-backdrop-filter:none;backdrop-filter:none}}";
6
6
 
@@ -36,4 +36,4 @@ function setVariant(variant, root = typeof document !== 'undefined' ? document.d
36
36
  exports.VARIANTS = VARIANTS;
37
37
  exports.adoptVariants = adoptVariants;
38
38
  exports.setVariant = setVariant;
39
- //# sourceMappingURL=variants-DxPmgrNX.cjs.map
39
+ //# sourceMappingURL=variants-BhjyddG8.cjs.map