use-scroll-animate 3.8.0 → 3.9.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 (123) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -0
  3. package/README_ja.md +1 -0
  4. package/README_zh.md +1 -0
  5. package/dist/chunks/{base-BpROOcey.js → base-BRIPyPtX.js} +11 -2
  6. package/dist/chunks/{base-BpROOcey.js.map → base-BRIPyPtX.js.map} +1 -1
  7. package/dist/chunks/{base-CXx7jZ-o.cjs → base-Dm6ee5ug.cjs} +11 -1
  8. package/dist/chunks/{base-CXx7jZ-o.cjs.map → base-Dm6ee5ug.cjs.map} +1 -1
  9. package/dist/chunks/{core-IaorbTdu.cjs → core-CHAtivHV.cjs} +2 -2
  10. package/dist/chunks/{core-IaorbTdu.cjs.map → core-CHAtivHV.cjs.map} +1 -1
  11. package/dist/chunks/{core-uxs3ETou.js → core-CYozf_E-.js} +2 -2
  12. package/dist/chunks/{core-uxs3ETou.js.map → core-CYozf_E-.js.map} +1 -1
  13. package/dist/chunks/{index-tags-BANJ-e4H.js → index-tags-BmQR17Sb.js} +2 -1
  14. package/dist/chunks/{index-tags-BANJ-e4H.js.map → index-tags-BmQR17Sb.js.map} +1 -1
  15. package/dist/chunks/{index-tags-wbuPiMR6.cjs → index-tags-DYYsgbba.cjs} +2 -1
  16. package/dist/chunks/{index-tags-wbuPiMR6.cjs.map → index-tags-DYYsgbba.cjs.map} +1 -1
  17. package/dist/chunks/{spring-2OTnYCzm.cjs → spring-Dp5BllPB.cjs} +2 -2
  18. package/dist/chunks/{spring-2OTnYCzm.cjs.map → spring-Dp5BllPB.cjs.map} +1 -1
  19. package/dist/chunks/{spring-C-fw7_9f.js → spring-UBPhrh1X.js} +2 -2
  20. package/dist/chunks/{spring-C-fw7_9f.js.map → spring-UBPhrh1X.js.map} +1 -1
  21. package/dist/chunks/{variants-CHe1VbSn.js → variants-DTypaOH3.js} +2 -2
  22. package/dist/chunks/{variants-CHe1VbSn.js.map → variants-DTypaOH3.js.map} +1 -1
  23. package/dist/chunks/{variants-BNIrn4ch.cjs → variants-_dC-ey6R.cjs} +2 -2
  24. package/dist/chunks/{variants-BNIrn4ch.cjs.map → variants-_dC-ey6R.cjs.map} +1 -1
  25. package/dist/components/angular.cjs +6 -5
  26. package/dist/components/angular.cjs.map +1 -1
  27. package/dist/components/angular.d.cts +25 -0
  28. package/dist/components/angular.d.ts +25 -0
  29. package/dist/components/angular.js +6 -5
  30. package/dist/components/angular.js.map +1 -1
  31. package/dist/components/background.cjs +2 -2
  32. package/dist/components/background.js +3 -3
  33. package/dist/components/cards.cjs +2 -2
  34. package/dist/components/cards.js +3 -3
  35. package/dist/components/click.cjs +2 -2
  36. package/dist/components/click.js +3 -3
  37. package/dist/components/depth.cjs +3 -3
  38. package/dist/components/depth.js +4 -4
  39. package/dist/components/feedback.cjs +1 -1
  40. package/dist/components/feedback.js +2 -2
  41. package/dist/components/gesture.cjs +3 -3
  42. package/dist/components/gesture.js +5 -5
  43. package/dist/components/interaction.cjs +1 -1
  44. package/dist/components/interaction.js +2 -2
  45. package/dist/components/jsx.d.cts +1 -0
  46. package/dist/components/jsx.d.ts +1 -0
  47. package/dist/components/layout.cjs +1 -1
  48. package/dist/components/layout.js +2 -2
  49. package/dist/components/lazy.cjs +2 -1
  50. package/dist/components/lazy.cjs.map +1 -1
  51. package/dist/components/lazy.d.cts +1 -0
  52. package/dist/components/lazy.d.ts +1 -0
  53. package/dist/components/lazy.js +2 -1
  54. package/dist/components/lazy.js.map +1 -1
  55. package/dist/components/packs.cjs +194 -0
  56. package/dist/components/packs.cjs.map +1 -0
  57. package/dist/components/packs.css +3 -0
  58. package/dist/components/packs.d.cts +107 -0
  59. package/dist/components/packs.d.ts +107 -0
  60. package/dist/components/packs.js +185 -0
  61. package/dist/components/packs.js.map +1 -0
  62. package/dist/components/page.cjs +2 -2
  63. package/dist/components/page.js +3 -3
  64. package/dist/components/physics.cjs +2 -2
  65. package/dist/components/physics.js +4 -4
  66. package/dist/components/react.cjs +1 -1
  67. package/dist/components/react.js +1 -1
  68. package/dist/components/reveal.cjs +1 -1
  69. package/dist/components/reveal.js +2 -2
  70. package/dist/components/solid.cjs +6 -5
  71. package/dist/components/solid.cjs.map +1 -1
  72. package/dist/components/solid.d.cts +25 -0
  73. package/dist/components/solid.d.ts +25 -0
  74. package/dist/components/solid.js +6 -5
  75. package/dist/components/solid.js.map +1 -1
  76. package/dist/components/svelte.cjs +6 -5
  77. package/dist/components/svelte.cjs.map +1 -1
  78. package/dist/components/svelte.d.cts +25 -0
  79. package/dist/components/svelte.d.ts +25 -0
  80. package/dist/components/svelte.js +6 -5
  81. package/dist/components/svelte.js.map +1 -1
  82. package/dist/components/svg.cjs +1 -1
  83. package/dist/components/svg.js +2 -2
  84. package/dist/components/text.cjs +1 -1
  85. package/dist/components/text.js +2 -2
  86. package/dist/components/timeline.cjs +1 -1
  87. package/dist/components/timeline.js +2 -2
  88. package/dist/components/transitions.cjs +5 -1
  89. package/dist/components/transitions.cjs.map +1 -1
  90. package/dist/components/transitions.d.cts +2 -0
  91. package/dist/components/transitions.d.ts +2 -0
  92. package/dist/components/transitions.js +6 -2
  93. package/dist/components/transitions.js.map +1 -1
  94. package/dist/components/ui.cjs +3 -3
  95. package/dist/components/ui.js +5 -5
  96. package/dist/components/vue.cjs +6 -5
  97. package/dist/components/vue.cjs.map +1 -1
  98. package/dist/components/vue.d.cts +25 -0
  99. package/dist/components/vue.d.ts +25 -0
  100. package/dist/components/vue.js +6 -5
  101. package/dist/components/vue.js.map +1 -1
  102. package/dist/components/webgl.cjs +1 -1
  103. package/dist/components/webgl.js +2 -2
  104. package/dist/components.cjs +14 -5
  105. package/dist/components.cjs.map +1 -1
  106. package/dist/components.css +1 -0
  107. package/dist/components.d.cts +65 -2
  108. package/dist/components.d.ts +65 -2
  109. package/dist/components.js +11 -8
  110. package/dist/components.js.map +1 -1
  111. package/dist/components.umd.js +2 -2
  112. package/dist/components.umd.js.map +1 -1
  113. package/dist/index.cjs +7 -0
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.d.cts +2 -0
  116. package/dist/index.d.ts +2 -0
  117. package/dist/index.js +7 -0
  118. package/dist/index.js.map +1 -1
  119. package/dist/index.umd.js +2 -2
  120. package/dist/index.umd.js.map +1 -1
  121. package/docs/components.md +14 -0
  122. package/docs/upgrading-4.md +65 -0
  123. package/package.json +13 -2
package/dist/index.cjs CHANGED
@@ -10,6 +10,7 @@ var stagger = require('./chunks/stagger-CLc3j58T.cjs');
10
10
  * Chain animations on several targets, one after another (or overlapping).
11
11
  */
12
12
  let fallback = null;
13
+ let warned = false;
13
14
  function plan(steps, defaults) {
14
15
  const out = [];
15
16
  let cursor = 0;
@@ -31,6 +32,8 @@ function plan(steps, defaults) {
31
32
  /**
32
33
  * Build a timeline of animations.
33
34
  *
35
+ * @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).
36
+ *
34
37
  * @example
35
38
  * sequence([
36
39
  * { target: '.title', animation: 'fade-in-up' },
@@ -39,6 +42,10 @@ function plan(steps, defaults) {
39
42
  * ], { trigger: '.hero' });
40
43
  */
41
44
  function sequence(steps, options = {}) {
45
+ if (!warned && typeof console !== 'undefined') {
46
+ warned = true;
47
+ console.warn("[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md.");
48
+ }
42
49
  const { trigger, instance, ...defaults } = options;
43
50
  const sa = () => instance || fallback || (fallback = core.createScrollAnimate());
44
51
  let io;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/sequence.ts","../src/parallax.ts","../src/index.ts"],"sourcesContent":["/**\n * use-scroll-animate - Sequence / timeline helper\n * Chain animations on several targets, one after another (or overlapping).\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate, hasDOM, prepareElement, resolveTargets, stopAnimation, supportsObserver } from './core';\n\nexport interface SequenceStep extends AnimateOptions {\n /** Selector, Element, NodeList or Element[] to animate in this step */\n target: string | Element | NodeList | Element[];\n /** Pause (ms) after the previous step ends before this one starts. Negative values overlap. (default: 0) */\n gap?: number;\n /** Absolute start time (ms) on the timeline; overrides `gap` */\n at?: number;\n}\n\nexport interface SequenceOptions extends AnimateOptions {\n /** Play automatically (once) when this element/selector enters the viewport */\n trigger?: string | Element;\n /** Instance whose global config (easing, classes, `disabled`) is used */\n instance?: ScrollAnimateInstance;\n}\n\nexport interface SequenceController {\n /** Play (or replay) the timeline. Resolves when every step has completed, or on `cancel()`. */\n play(): Promise<void>;\n /** Stop the trigger and running animations; elements are left visible. */\n cancel(): void;\n /** Total duration of the timeline in ms (computed for the current DOM). */\n duration(): number;\n}\n\nlet fallback: ScrollAnimateInstance | null = null;\n\ntype Planned = { el: Element; opts: AnimateOptions; end: number };\n\nfunction plan(steps: SequenceStep[], defaults: AnimateOptions): Planned[] {\n const out: Planned[] = [];\n let cursor = 0;\n steps.forEach((step) => {\n const { target, gap = 0, at, ...stepOpts } = step;\n const opts = { ...defaults, ...stepOpts };\n const duration = opts.duration ?? 600;\n const start = Math.max(0, at ?? cursor + gap) + (opts.delay ?? 0);\n let end = Math.max(cursor, start);\n resolveTargets(target).forEach((el, i) => {\n const delay = start + i * (opts.stagger ?? 0);\n out.push({ el, opts: { ...opts, duration, delay, stagger: 0 }, end: delay + duration });\n end = Math.max(end, delay + duration);\n });\n cursor = end;\n });\n return out;\n}\n\n/**\n * Build a timeline of animations.\n *\n * @example\n * sequence([\n * { target: '.title', animation: 'fade-in-up' },\n * { target: '.subtitle', animation: 'blur-in', gap: -300 }, // overlap by 300ms\n * { target: '.card', animation: 'scale-up', stagger: 80 },\n * ], { trigger: '.hero' });\n */\nexport function sequence(steps: SequenceStep[], options: SequenceOptions = {}): SequenceController {\n const { trigger, instance, ...defaults } = options;\n const sa = () => instance || fallback || (fallback = createScrollAnimate());\n let io: IntersectionObserver | undefined;\n let active: Planned[] = [];\n let settle: (() => void) | undefined;\n // Targets hidden while waiting for `trigger`; revealed if cancelled before it fires.\n let prepared: Element[] = [];\n\n const controller: SequenceController = {\n play() {\n controller.cancel();\n if (!hasDOM()) return Promise.resolve();\n active = plan(steps, defaults);\n return new Promise<void>((resolve) => {\n let left = active.length;\n settle = () => {\n settle = undefined;\n resolve();\n };\n if (!left) return settle();\n const run = active;\n run.forEach(({ el, opts }) => {\n const done = opts.onComplete;\n sa().animate(el, {\n ...opts,\n onComplete: (node) => {\n done?.(node);\n if (run === active && --left === 0) settle?.();\n },\n });\n });\n });\n },\n\n cancel() {\n io?.disconnect();\n io = undefined;\n prepared.forEach((el) => stopAnimation(el));\n prepared = [];\n active.forEach(({ el }) => stopAnimation(el));\n active = [];\n settle?.();\n },\n\n duration() {\n return plan(steps, defaults).reduce((max, p) => Math.max(max, p.end), 0);\n },\n };\n\n if (trigger && hasDOM() && supportsObserver()) {\n const el = resolveTargets(trigger)[0];\n if (el) {\n prepared = plan(steps, defaults).map(({ el: target }) => target);\n prepared.forEach((target) => prepareElement(target));\n io = new IntersectionObserver(\n (entries) => {\n if (!entries.some((e) => e.isIntersecting)) return;\n io?.disconnect();\n io = undefined;\n prepared = []; // play() takes over from here\n controller.play();\n },\n { threshold: defaults.threshold ?? 0.1, rootMargin: defaults.rootMargin ?? '0px' }\n );\n io.observe(el);\n }\n }\n\n return controller;\n}\n","/**\n * use-scroll-animate - parallax() helper\n *\n * Moves elements at a different speed than the page while they cross the\n * viewport. Built on the same scroll progress as `progressVar` (0 when the\n * element's top enters at the bottom, 1 when its bottom leaves at the top):\n * the progress is written to a CSS custom property (default `--sa-parallax`)\n * and the offset is applied with the individual `translate` property, so it\n * composes with entrance animations and other `transform`s.\n */\n\nimport { getScrollProgress, hasDOM, prefersReducedMotion, resolveTargets, supportsObserver } from './core';\n\nexport interface ParallaxHelperOptions {\n /**\n * Total distance the element shifts while it crosses the viewport, as a\n * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values\n * lag behind the scroll (background-like), negative values move ahead of it\n * (foreground-like). (default: `0.2`)\n */\n speed?: number;\n /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */\n axis?: 'x' | 'y';\n /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */\n progressVar?: string;\n /** Scroll container (default: the viewport) */\n root?: Element | null;\n /**\n * Under `prefers-reduced-motion: reduce` no offset is applied (the progress\n * variable is still written). Set to `false` to move anyway. (default: `true`)\n */\n respectReducedMotion?: boolean;\n}\n\nconst PASSIVE: AddEventListenerOptions = { passive: true };\n\n/**\n * Apply a scroll parallax to `target` (selector, Element, NodeList or array).\n * Returns a function that stops it and removes the inline styles it set.\n * SSR-safe (no-op without a DOM / IntersectionObserver).\n *\n * @example\n * const stop = parallax('.hero-bg', { speed: 0.3 });\n * parallax('.badge', { speed: -0.15, axis: 'x' });\n */\nexport function parallax(\n target: string | Element | NodeList | Element[],\n options: ParallaxHelperOptions = {}\n): () => void {\n const els = resolveTargets(target);\n if (!els.length || !hasDOM() || !supportsObserver()) return () => undefined;\n const { speed = 0.2, axis = 'y', root = null, respectReducedMotion = true } = options;\n const name = options.progressVar ? (options.progressVar.startsWith('--') ? options.progressVar : `--${options.progressVar}`) : '--sa-parallax';\n const unit = axis === 'x' ? 'vw' : 'vh';\n const visible = new Set<Element>();\n let frame = 0;\n let listening = false;\n const scroller: EventTarget = root || window;\n\n const apply = (el: Element) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n const p = getScrollProgress(el, root);\n style.setProperty(name, String(+p.toFixed(4)));\n if (respectReducedMotion && prefersReducedMotion()) {\n style.removeProperty('translate');\n return;\n }\n const offset = `${+((p - 0.5) * speed * 100).toFixed(3)}${unit}`;\n style.setProperty('translate', axis === 'x' ? `${offset} 0px` : `0px ${offset}`);\n };\n\n const update = () => {\n frame = 0;\n visible.forEach(apply);\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(update);\n };\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n const method = on ? 'addEventListener' : 'removeEventListener';\n scroller[method]('scroll', schedule, PASSIVE);\n window[method]('resize', schedule, PASSIVE);\n if (!on && frame) {\n cancelAnimationFrame(frame);\n frame = 0;\n }\n };\n\n const io = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) visible.add(entry.target);\n else visible.delete(entry.target);\n apply(entry.target); // report the edges even on fast scrolls\n });\n listen(visible.size > 0);\n },\n { threshold: 0, root }\n );\n els.forEach((el) => {\n apply(el); // no jump before the first observer callback\n io.observe(el);\n });\n\n return () => {\n io.disconnect();\n listen(false);\n visible.clear();\n els.forEach((el) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n style.removeProperty('translate');\n style.removeProperty(name);\n });\n };\n}\n","/**\n * use-scroll-animate\n *\n * A lightweight, dependency-free scroll animation library for modern web\n * applications. Built with TypeScript, powered by IntersectionObserver and\n * the Web Animations API (or the native scroll-driven timeline). Safe to\n * import during SSR. Framework integrations live in the subpath entries:\n * `use-scroll-animate/react`, `/vue`, `/svelte`, `/solid`, `/element`.\n *\n * @license MIT\n * @see https://github.com/HarrisonCN/use-scroll-animate\n */\n\nexport { createScrollAnimate, getScrollProgress, supportsScrollTimeline } from './core';\nexport { staggerChildren } from './stagger';\nexport { sequence } from './sequence';\nexport { parallax } from './parallax';\nexport { PRESETS, resolvePreset, resolveEasing, EASING_MAP } from './presets';\nexport type {\n AnimationPreset,\n EasingType,\n AnimationKeyframe,\n CustomAnimation,\n ProgressMode,\n ScrollEngine,\n AnimateOptions,\n ScrollAnimateConfig,\n AnimatedElement,\n ScrollAnimateInstance,\n} from './types';\nexport type { StaggerOptions } from './stagger';\nexport type { ParallaxHelperOptions } from './parallax';\nexport type { SequenceStep, SequenceOptions, SequenceController } from './sequence';\n\n// Default export: a ready-to-use singleton instance\nimport { createScrollAnimate } from './core';\n\n/**\n * Default singleton instance of ScrollAnimate.\n * Ready to use out of the box with sensible defaults.\n *\n * @example\n * ```js\n * import ScrollAnimate from 'use-scroll-animate';\n *\n * // Auto-initialize all elements with data-sa attribute\n * ScrollAnimate.init();\n *\n * // Or manually observe elements\n * ScrollAnimate.observe('.my-element', { animation: 'fade-in-up' });\n * ```\n */\nconst ScrollAnimate = /* @__PURE__ */ createScrollAnimate();\nexport default ScrollAnimate;\n"],"names":["resolveTargets","createScrollAnimate","hasDOM","stopAnimation","supportsObserver","prepareElement","getScrollProgress","prefersReducedMotion"],"mappings":";;;;;;;AAAA;;;AAGG;AA8BH,IAAI,QAAQ,GAAiC,IAAI;AAIjD,SAAS,IAAI,CAAC,KAAqB,EAAE,QAAwB,EAAA;IAC3D,MAAM,GAAG,GAAc,EAAE;IACzB,IAAI,MAAM,GAAG,CAAC;AACd,IAAA,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;AACrB,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI;QACjD,MAAM,IAAI,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,QAAQ,EAAE;AACzC,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,GAAG;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QACjE,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC;QACjCA,mBAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,KAAI;AACvC,YAAA,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;AAC7C,YAAA,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,GA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,KAAI;AACjB,YAAA,MAAM,KAAK,GAAI,EAAkB,CAAC,KAAK;AACvC,YAAA,IAAI,CAAC,KAAK;gBAAE;AACZ,YAAA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;AACjC,YAAA,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC;AAC5B,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC;AACH;;ACtHA;;;;;;;;;;;AAWG;AA0BH;;;;;;;;;;;;;;AAcG;AACH,MAAM,aAAa,mBAAmBN,wBAAmB;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/sequence.ts","../src/parallax.ts","../src/index.ts"],"sourcesContent":["/**\n * use-scroll-animate - Sequence / timeline helper\n * Chain animations on several targets, one after another (or overlapping).\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate, hasDOM, prepareElement, resolveTargets, stopAnimation, supportsObserver } from './core';\n\nexport interface SequenceStep extends AnimateOptions {\n /** Selector, Element, NodeList or Element[] to animate in this step */\n target: string | Element | NodeList | Element[];\n /** Pause (ms) after the previous step ends before this one starts. Negative values overlap. (default: 0) */\n gap?: number;\n /** Absolute start time (ms) on the timeline; overrides `gap` */\n at?: number;\n}\n\nexport interface SequenceOptions extends AnimateOptions {\n /** Play automatically (once) when this element/selector enters the viewport */\n trigger?: string | Element;\n /** Instance whose global config (easing, classes, `disabled`) is used */\n instance?: ScrollAnimateInstance;\n}\n\nexport interface SequenceController {\n /** Play (or replay) the timeline. Resolves when every step has completed, or on `cancel()`. */\n play(): Promise<void>;\n /** Stop the trigger and running animations; elements are left visible. */\n cancel(): void;\n /** Total duration of the timeline in ms (computed for the current DOM). */\n duration(): number;\n}\n\nlet fallback: ScrollAnimateInstance | null = null;\nlet warned = false;\n\ntype Planned = { el: Element; opts: AnimateOptions; end: number };\n\nfunction plan(steps: SequenceStep[], defaults: AnimateOptions): Planned[] {\n const out: Planned[] = [];\n let cursor = 0;\n steps.forEach((step) => {\n const { target, gap = 0, at, ...stepOpts } = step;\n const opts = { ...defaults, ...stepOpts };\n const duration = opts.duration ?? 600;\n const start = Math.max(0, at ?? cursor + gap) + (opts.delay ?? 0);\n let end = Math.max(cursor, start);\n resolveTargets(target).forEach((el, i) => {\n const delay = start + i * (opts.stagger ?? 0);\n out.push({ el, opts: { ...opts, duration, delay, stagger: 0 }, end: delay + duration });\n end = Math.max(end, delay + duration);\n });\n cursor = end;\n });\n return out;\n}\n\n/**\n * Build a timeline of animations.\n *\n * @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).\n *\n * @example\n * sequence([\n * { target: '.title', animation: 'fade-in-up' },\n * { target: '.subtitle', animation: 'blur-in', gap: -300 }, // overlap by 300ms\n * { target: '.card', animation: 'scale-up', stagger: 80 },\n * ], { trigger: '.hero' });\n */\nexport function sequence(steps: SequenceStep[], options: SequenceOptions = {}): SequenceController {\n if (!warned && typeof console !== 'undefined') {\n warned = true;\n console.warn(\"[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md.\");\n }\n const { trigger, instance, ...defaults } = options;\n const sa = () => instance || fallback || (fallback = createScrollAnimate());\n let io: IntersectionObserver | undefined;\n let active: Planned[] = [];\n let settle: (() => void) | undefined;\n // Targets hidden while waiting for `trigger`; revealed if cancelled before it fires.\n let prepared: Element[] = [];\n\n const controller: SequenceController = {\n play() {\n controller.cancel();\n if (!hasDOM()) return Promise.resolve();\n active = plan(steps, defaults);\n return new Promise<void>((resolve) => {\n let left = active.length;\n settle = () => {\n settle = undefined;\n resolve();\n };\n if (!left) return settle();\n const run = active;\n run.forEach(({ el, opts }) => {\n const done = opts.onComplete;\n sa().animate(el, {\n ...opts,\n onComplete: (node) => {\n done?.(node);\n if (run === active && --left === 0) settle?.();\n },\n });\n });\n });\n },\n\n cancel() {\n io?.disconnect();\n io = undefined;\n prepared.forEach((el) => stopAnimation(el));\n prepared = [];\n active.forEach(({ el }) => stopAnimation(el));\n active = [];\n settle?.();\n },\n\n duration() {\n return plan(steps, defaults).reduce((max, p) => Math.max(max, p.end), 0);\n },\n };\n\n if (trigger && hasDOM() && supportsObserver()) {\n const el = resolveTargets(trigger)[0];\n if (el) {\n prepared = plan(steps, defaults).map(({ el: target }) => target);\n prepared.forEach((target) => prepareElement(target));\n io = new IntersectionObserver(\n (entries) => {\n if (!entries.some((e) => e.isIntersecting)) return;\n io?.disconnect();\n io = undefined;\n prepared = []; // play() takes over from here\n controller.play();\n },\n { threshold: defaults.threshold ?? 0.1, rootMargin: defaults.rootMargin ?? '0px' }\n );\n io.observe(el);\n }\n }\n\n return controller;\n}\n","/**\n * use-scroll-animate - parallax() helper\n *\n * Moves elements at a different speed than the page while they cross the\n * viewport. Built on the same scroll progress as `progressVar` (0 when the\n * element's top enters at the bottom, 1 when its bottom leaves at the top):\n * the progress is written to a CSS custom property (default `--sa-parallax`)\n * and the offset is applied with the individual `translate` property, so it\n * composes with entrance animations and other `transform`s.\n */\n\nimport { getScrollProgress, hasDOM, prefersReducedMotion, resolveTargets, supportsObserver } from './core';\n\nexport interface ParallaxHelperOptions {\n /**\n * Total distance the element shifts while it crosses the viewport, as a\n * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values\n * lag behind the scroll (background-like), negative values move ahead of it\n * (foreground-like). (default: `0.2`)\n */\n speed?: number;\n /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */\n axis?: 'x' | 'y';\n /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */\n progressVar?: string;\n /** Scroll container (default: the viewport) */\n root?: Element | null;\n /**\n * Under `prefers-reduced-motion: reduce` no offset is applied (the progress\n * variable is still written). Set to `false` to move anyway. (default: `true`)\n */\n respectReducedMotion?: boolean;\n}\n\nconst PASSIVE: AddEventListenerOptions = { passive: true };\n\n/**\n * Apply a scroll parallax to `target` (selector, Element, NodeList or array).\n * Returns a function that stops it and removes the inline styles it set.\n * SSR-safe (no-op without a DOM / IntersectionObserver).\n *\n * @example\n * const stop = parallax('.hero-bg', { speed: 0.3 });\n * parallax('.badge', { speed: -0.15, axis: 'x' });\n */\nexport function parallax(\n target: string | Element | NodeList | Element[],\n options: ParallaxHelperOptions = {}\n): () => void {\n const els = resolveTargets(target);\n if (!els.length || !hasDOM() || !supportsObserver()) return () => undefined;\n const { speed = 0.2, axis = 'y', root = null, respectReducedMotion = true } = options;\n const name = options.progressVar ? (options.progressVar.startsWith('--') ? options.progressVar : `--${options.progressVar}`) : '--sa-parallax';\n const unit = axis === 'x' ? 'vw' : 'vh';\n const visible = new Set<Element>();\n let frame = 0;\n let listening = false;\n const scroller: EventTarget = root || window;\n\n const apply = (el: Element) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n const p = getScrollProgress(el, root);\n style.setProperty(name, String(+p.toFixed(4)));\n if (respectReducedMotion && prefersReducedMotion()) {\n style.removeProperty('translate');\n return;\n }\n const offset = `${+((p - 0.5) * speed * 100).toFixed(3)}${unit}`;\n style.setProperty('translate', axis === 'x' ? `${offset} 0px` : `0px ${offset}`);\n };\n\n const update = () => {\n frame = 0;\n visible.forEach(apply);\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(update);\n };\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n const method = on ? 'addEventListener' : 'removeEventListener';\n scroller[method]('scroll', schedule, PASSIVE);\n window[method]('resize', schedule, PASSIVE);\n if (!on && frame) {\n cancelAnimationFrame(frame);\n frame = 0;\n }\n };\n\n const io = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) visible.add(entry.target);\n else visible.delete(entry.target);\n apply(entry.target); // report the edges even on fast scrolls\n });\n listen(visible.size > 0);\n },\n { threshold: 0, root }\n );\n els.forEach((el) => {\n apply(el); // no jump before the first observer callback\n io.observe(el);\n });\n\n return () => {\n io.disconnect();\n listen(false);\n visible.clear();\n els.forEach((el) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n style.removeProperty('translate');\n style.removeProperty(name);\n });\n };\n}\n","/**\n * use-scroll-animate\n *\n * A lightweight, dependency-free scroll animation library for modern web\n * applications. Built with TypeScript, powered by IntersectionObserver and\n * the Web Animations API (or the native scroll-driven timeline). Safe to\n * import during SSR. Framework integrations live in the subpath entries:\n * `use-scroll-animate/react`, `/vue`, `/svelte`, `/solid`, `/element`.\n *\n * @license MIT\n * @see https://github.com/HarrisonCN/use-scroll-animate\n */\n\nexport { createScrollAnimate, getScrollProgress, supportsScrollTimeline } from './core';\nexport { staggerChildren } from './stagger';\nexport { sequence } from './sequence';\nexport { parallax } from './parallax';\nexport { PRESETS, resolvePreset, resolveEasing, EASING_MAP } from './presets';\nexport type {\n AnimationPreset,\n EasingType,\n AnimationKeyframe,\n CustomAnimation,\n ProgressMode,\n ScrollEngine,\n AnimateOptions,\n ScrollAnimateConfig,\n AnimatedElement,\n ScrollAnimateInstance,\n} from './types';\nexport type { StaggerOptions } from './stagger';\nexport type { ParallaxHelperOptions } from './parallax';\nexport type { SequenceStep, SequenceOptions, SequenceController } from './sequence';\n\n// Default export: a ready-to-use singleton instance\nimport { createScrollAnimate } from './core';\n\n/**\n * Default singleton instance of ScrollAnimate.\n * Ready to use out of the box with sensible defaults.\n *\n * @example\n * ```js\n * import ScrollAnimate from 'use-scroll-animate';\n *\n * // Auto-initialize all elements with data-sa attribute\n * ScrollAnimate.init();\n *\n * // Or manually observe elements\n * ScrollAnimate.observe('.my-element', { animation: 'fade-in-up' });\n * ```\n */\nconst ScrollAnimate = /* @__PURE__ */ createScrollAnimate();\nexport default ScrollAnimate;\n"],"names":["resolveTargets","createScrollAnimate","hasDOM","stopAnimation","supportsObserver","prepareElement","getScrollProgress","prefersReducedMotion"],"mappings":";;;;;;;AAAA;;;AAGG;AA8BH,IAAI,QAAQ,GAAiC,IAAI;AACjD,IAAI,MAAM,GAAG,KAAK;AAIlB,SAAS,IAAI,CAAC,KAAqB,EAAE,QAAwB,E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;;;;;;;;AAcG;AACH,MAAM,aAAa,mBAAmBN,wBAAmB;;;;;;;;;;;;;;"}
package/dist/index.d.cts CHANGED
@@ -248,6 +248,8 @@ interface SequenceController {
248
248
  /**
249
249
  * Build a timeline of animations.
250
250
  *
251
+ * @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).
252
+ *
251
253
  * @example
252
254
  * sequence([
253
255
  * { target: '.title', animation: 'fade-in-up' },
package/dist/index.d.ts CHANGED
@@ -248,6 +248,8 @@ interface SequenceController {
248
248
  /**
249
249
  * Build a timeline of animations.
250
250
  *
251
+ * @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).
252
+ *
251
253
  * @example
252
254
  * sequence([
253
255
  * { target: '.title', animation: 'fade-in-up' },
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export { s as staggerChildren } from './chunks/stagger-BFAhKknX.js';
7
7
  * Chain animations on several targets, one after another (or overlapping).
8
8
  */
9
9
  let fallback = null;
10
+ let warned = false;
10
11
  function plan(steps, defaults) {
11
12
  const out = [];
12
13
  let cursor = 0;
@@ -28,6 +29,8 @@ function plan(steps, defaults) {
28
29
  /**
29
30
  * Build a timeline of animations.
30
31
  *
32
+ * @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).
33
+ *
31
34
  * @example
32
35
  * sequence([
33
36
  * { target: '.title', animation: 'fade-in-up' },
@@ -36,6 +39,10 @@ function plan(steps, defaults) {
36
39
  * ], { trigger: '.hero' });
37
40
  */
38
41
  function sequence(steps, options = {}) {
42
+ if (!warned && typeof console !== 'undefined') {
43
+ warned = true;
44
+ console.warn("[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md.");
45
+ }
39
46
  const { trigger, instance, ...defaults } = options;
40
47
  const sa = () => instance || fallback || (fallback = createScrollAnimate());
41
48
  let io;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/sequence.ts","../src/parallax.ts","../src/index.ts"],"sourcesContent":["/**\n * use-scroll-animate - Sequence / timeline helper\n * Chain animations on several targets, one after another (or overlapping).\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate, hasDOM, prepareElement, resolveTargets, stopAnimation, supportsObserver } from './core';\n\nexport interface SequenceStep extends AnimateOptions {\n /** Selector, Element, NodeList or Element[] to animate in this step */\n target: string | Element | NodeList | Element[];\n /** Pause (ms) after the previous step ends before this one starts. Negative values overlap. (default: 0) */\n gap?: number;\n /** Absolute start time (ms) on the timeline; overrides `gap` */\n at?: number;\n}\n\nexport interface SequenceOptions extends AnimateOptions {\n /** Play automatically (once) when this element/selector enters the viewport */\n trigger?: string | Element;\n /** Instance whose global config (easing, classes, `disabled`) is used */\n instance?: ScrollAnimateInstance;\n}\n\nexport interface SequenceController {\n /** Play (or replay) the timeline. Resolves when every step has completed, or on `cancel()`. */\n play(): Promise<void>;\n /** Stop the trigger and running animations; elements are left visible. */\n cancel(): void;\n /** Total duration of the timeline in ms (computed for the current DOM). */\n duration(): number;\n}\n\nlet fallback: ScrollAnimateInstance | null = null;\n\ntype Planned = { el: Element; opts: AnimateOptions; end: number };\n\nfunction plan(steps: SequenceStep[], defaults: AnimateOptions): Planned[] {\n const out: Planned[] = [];\n let cursor = 0;\n steps.forEach((step) => {\n const { target, gap = 0, at, ...stepOpts } = step;\n const opts = { ...defaults, ...stepOpts };\n const duration = opts.duration ?? 600;\n const start = Math.max(0, at ?? cursor + gap) + (opts.delay ?? 0);\n let end = Math.max(cursor, start);\n resolveTargets(target).forEach((el, i) => {\n const delay = start + i * (opts.stagger ?? 0);\n out.push({ el, opts: { ...opts, duration, delay, stagger: 0 }, end: delay + duration });\n end = Math.max(end, delay + duration);\n });\n cursor = end;\n });\n return out;\n}\n\n/**\n * Build a timeline of animations.\n *\n * @example\n * sequence([\n * { target: '.title', animation: 'fade-in-up' },\n * { target: '.subtitle', animation: 'blur-in', gap: -300 }, // overlap by 300ms\n * { target: '.card', animation: 'scale-up', stagger: 80 },\n * ], { trigger: '.hero' });\n */\nexport function sequence(steps: SequenceStep[], options: SequenceOptions = {}): SequenceController {\n const { trigger, instance, ...defaults } = options;\n const sa = () => instance || fallback || (fallback = createScrollAnimate());\n let io: IntersectionObserver | undefined;\n let active: Planned[] = [];\n let settle: (() => void) | undefined;\n // Targets hidden while waiting for `trigger`; revealed if cancelled before it fires.\n let prepared: Element[] = [];\n\n const controller: SequenceController = {\n play() {\n controller.cancel();\n if (!hasDOM()) return Promise.resolve();\n active = plan(steps, defaults);\n return new Promise<void>((resolve) => {\n let left = active.length;\n settle = () => {\n settle = undefined;\n resolve();\n };\n if (!left) return settle();\n const run = active;\n run.forEach(({ el, opts }) => {\n const done = opts.onComplete;\n sa().animate(el, {\n ...opts,\n onComplete: (node) => {\n done?.(node);\n if (run === active && --left === 0) settle?.();\n },\n });\n });\n });\n },\n\n cancel() {\n io?.disconnect();\n io = undefined;\n prepared.forEach((el) => stopAnimation(el));\n prepared = [];\n active.forEach(({ el }) => stopAnimation(el));\n active = [];\n settle?.();\n },\n\n duration() {\n return plan(steps, defaults).reduce((max, p) => Math.max(max, p.end), 0);\n },\n };\n\n if (trigger && hasDOM() && supportsObserver()) {\n const el = resolveTargets(trigger)[0];\n if (el) {\n prepared = plan(steps, defaults).map(({ el: target }) => target);\n prepared.forEach((target) => prepareElement(target));\n io = new IntersectionObserver(\n (entries) => {\n if (!entries.some((e) => e.isIntersecting)) return;\n io?.disconnect();\n io = undefined;\n prepared = []; // play() takes over from here\n controller.play();\n },\n { threshold: defaults.threshold ?? 0.1, rootMargin: defaults.rootMargin ?? '0px' }\n );\n io.observe(el);\n }\n }\n\n return controller;\n}\n","/**\n * use-scroll-animate - parallax() helper\n *\n * Moves elements at a different speed than the page while they cross the\n * viewport. Built on the same scroll progress as `progressVar` (0 when the\n * element's top enters at the bottom, 1 when its bottom leaves at the top):\n * the progress is written to a CSS custom property (default `--sa-parallax`)\n * and the offset is applied with the individual `translate` property, so it\n * composes with entrance animations and other `transform`s.\n */\n\nimport { getScrollProgress, hasDOM, prefersReducedMotion, resolveTargets, supportsObserver } from './core';\n\nexport interface ParallaxHelperOptions {\n /**\n * Total distance the element shifts while it crosses the viewport, as a\n * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values\n * lag behind the scroll (background-like), negative values move ahead of it\n * (foreground-like). (default: `0.2`)\n */\n speed?: number;\n /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */\n axis?: 'x' | 'y';\n /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */\n progressVar?: string;\n /** Scroll container (default: the viewport) */\n root?: Element | null;\n /**\n * Under `prefers-reduced-motion: reduce` no offset is applied (the progress\n * variable is still written). Set to `false` to move anyway. (default: `true`)\n */\n respectReducedMotion?: boolean;\n}\n\nconst PASSIVE: AddEventListenerOptions = { passive: true };\n\n/**\n * Apply a scroll parallax to `target` (selector, Element, NodeList or array).\n * Returns a function that stops it and removes the inline styles it set.\n * SSR-safe (no-op without a DOM / IntersectionObserver).\n *\n * @example\n * const stop = parallax('.hero-bg', { speed: 0.3 });\n * parallax('.badge', { speed: -0.15, axis: 'x' });\n */\nexport function parallax(\n target: string | Element | NodeList | Element[],\n options: ParallaxHelperOptions = {}\n): () => void {\n const els = resolveTargets(target);\n if (!els.length || !hasDOM() || !supportsObserver()) return () => undefined;\n const { speed = 0.2, axis = 'y', root = null, respectReducedMotion = true } = options;\n const name = options.progressVar ? (options.progressVar.startsWith('--') ? options.progressVar : `--${options.progressVar}`) : '--sa-parallax';\n const unit = axis === 'x' ? 'vw' : 'vh';\n const visible = new Set<Element>();\n let frame = 0;\n let listening = false;\n const scroller: EventTarget = root || window;\n\n const apply = (el: Element) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n const p = getScrollProgress(el, root);\n style.setProperty(name, String(+p.toFixed(4)));\n if (respectReducedMotion && prefersReducedMotion()) {\n style.removeProperty('translate');\n return;\n }\n const offset = `${+((p - 0.5) * speed * 100).toFixed(3)}${unit}`;\n style.setProperty('translate', axis === 'x' ? `${offset} 0px` : `0px ${offset}`);\n };\n\n const update = () => {\n frame = 0;\n visible.forEach(apply);\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(update);\n };\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n const method = on ? 'addEventListener' : 'removeEventListener';\n scroller[method]('scroll', schedule, PASSIVE);\n window[method]('resize', schedule, PASSIVE);\n if (!on && frame) {\n cancelAnimationFrame(frame);\n frame = 0;\n }\n };\n\n const io = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) visible.add(entry.target);\n else visible.delete(entry.target);\n apply(entry.target); // report the edges even on fast scrolls\n });\n listen(visible.size > 0);\n },\n { threshold: 0, root }\n );\n els.forEach((el) => {\n apply(el); // no jump before the first observer callback\n io.observe(el);\n });\n\n return () => {\n io.disconnect();\n listen(false);\n visible.clear();\n els.forEach((el) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n style.removeProperty('translate');\n style.removeProperty(name);\n });\n };\n}\n","/**\n * use-scroll-animate\n *\n * A lightweight, dependency-free scroll animation library for modern web\n * applications. Built with TypeScript, powered by IntersectionObserver and\n * the Web Animations API (or the native scroll-driven timeline). Safe to\n * import during SSR. Framework integrations live in the subpath entries:\n * `use-scroll-animate/react`, `/vue`, `/svelte`, `/solid`, `/element`.\n *\n * @license MIT\n * @see https://github.com/HarrisonCN/use-scroll-animate\n */\n\nexport { createScrollAnimate, getScrollProgress, supportsScrollTimeline } from './core';\nexport { staggerChildren } from './stagger';\nexport { sequence } from './sequence';\nexport { parallax } from './parallax';\nexport { PRESETS, resolvePreset, resolveEasing, EASING_MAP } from './presets';\nexport type {\n AnimationPreset,\n EasingType,\n AnimationKeyframe,\n CustomAnimation,\n ProgressMode,\n ScrollEngine,\n AnimateOptions,\n ScrollAnimateConfig,\n AnimatedElement,\n ScrollAnimateInstance,\n} from './types';\nexport type { StaggerOptions } from './stagger';\nexport type { ParallaxHelperOptions } from './parallax';\nexport type { SequenceStep, SequenceOptions, SequenceController } from './sequence';\n\n// Default export: a ready-to-use singleton instance\nimport { createScrollAnimate } from './core';\n\n/**\n * Default singleton instance of ScrollAnimate.\n * Ready to use out of the box with sensible defaults.\n *\n * @example\n * ```js\n * import ScrollAnimate from 'use-scroll-animate';\n *\n * // Auto-initialize all elements with data-sa attribute\n * ScrollAnimate.init();\n *\n * // Or manually observe elements\n * ScrollAnimate.observe('.my-element', { animation: 'fade-in-up' });\n * ```\n */\nconst ScrollAnimate = /* @__PURE__ */ createScrollAnimate();\nexport default ScrollAnimate;\n"],"names":[],"mappings":";;;;AAAA;;;AAGG;AA8BH,IAAI,QAAQ,GAAiC,IAAI;AAIjD,SAAS,IAAI,CAAC,KAAqB,EAAE,QAAwB,EAAA;IAC3D,MAAM,GAAG,GAAc,EAAE;IACzB,IAAI,MAAM,GAAG,CAAC;AACd,IAAA,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;AACrB,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI;QACjD,MAAM,IAAI,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,QAAQ,EAAE;AACzC,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,GAAG;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QACjE,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC;QACjC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,KAAI;AACv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OAAO,MAAK;QACV,EAAE,CAAC,UAAU,EAAE;QACf,MAAM,CAAC,KAAK,CAAC;QACb,OAAO,CAAC,KAAK,EAAE;AACf,QAAA,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;AACjB,YAAA,MAAM,KAAK,GAAI,EAAkB,CAAC,KAAK;AACvC,YAAA,IAAI,CAAC,KAAK;gBAAE;AACZ,YAAA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;AACjC,YAAA,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC;AAC5B,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC;AACH;;ACtHA;;;;;;;;;;;AAWG;AA0BH;;;;;;;;;;;;;;AAcG;AACH,MAAM,aAAa,mBAAmB,mBAAmB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/sequence.ts","../src/parallax.ts","../src/index.ts"],"sourcesContent":["/**\n * use-scroll-animate - Sequence / timeline helper\n * Chain animations on several targets, one after another (or overlapping).\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate, hasDOM, prepareElement, resolveTargets, stopAnimation, supportsObserver } from './core';\n\nexport interface SequenceStep extends AnimateOptions {\n /** Selector, Element, NodeList or Element[] to animate in this step */\n target: string | Element | NodeList | Element[];\n /** Pause (ms) after the previous step ends before this one starts. Negative values overlap. (default: 0) */\n gap?: number;\n /** Absolute start time (ms) on the timeline; overrides `gap` */\n at?: number;\n}\n\nexport interface SequenceOptions extends AnimateOptions {\n /** Play automatically (once) when this element/selector enters the viewport */\n trigger?: string | Element;\n /** Instance whose global config (easing, classes, `disabled`) is used */\n instance?: ScrollAnimateInstance;\n}\n\nexport interface SequenceController {\n /** Play (or replay) the timeline. Resolves when every step has completed, or on `cancel()`. */\n play(): Promise<void>;\n /** Stop the trigger and running animations; elements are left visible. */\n cancel(): void;\n /** Total duration of the timeline in ms (computed for the current DOM). */\n duration(): number;\n}\n\nlet fallback: ScrollAnimateInstance | null = null;\nlet warned = false;\n\ntype Planned = { el: Element; opts: AnimateOptions; end: number };\n\nfunction plan(steps: SequenceStep[], defaults: AnimateOptions): Planned[] {\n const out: Planned[] = [];\n let cursor = 0;\n steps.forEach((step) => {\n const { target, gap = 0, at, ...stepOpts } = step;\n const opts = { ...defaults, ...stepOpts };\n const duration = opts.duration ?? 600;\n const start = Math.max(0, at ?? cursor + gap) + (opts.delay ?? 0);\n let end = Math.max(cursor, start);\n resolveTargets(target).forEach((el, i) => {\n const delay = start + i * (opts.stagger ?? 0);\n out.push({ el, opts: { ...opts, duration, delay, stagger: 0 }, end: delay + duration });\n end = Math.max(end, delay + duration);\n });\n cursor = end;\n });\n return out;\n}\n\n/**\n * Build a timeline of animations.\n *\n * @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).\n *\n * @example\n * sequence([\n * { target: '.title', animation: 'fade-in-up' },\n * { target: '.subtitle', animation: 'blur-in', gap: -300 }, // overlap by 300ms\n * { target: '.card', animation: 'scale-up', stagger: 80 },\n * ], { trigger: '.hero' });\n */\nexport function sequence(steps: SequenceStep[], options: SequenceOptions = {}): SequenceController {\n if (!warned && typeof console !== 'undefined') {\n warned = true;\n console.warn(\"[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md.\");\n }\n const { trigger, instance, ...defaults } = options;\n const sa = () => instance || fallback || (fallback = createScrollAnimate());\n let io: IntersectionObserver | undefined;\n let active: Planned[] = [];\n let settle: (() => void) | undefined;\n // Targets hidden while waiting for `trigger`; revealed if cancelled before it fires.\n let prepared: Element[] = [];\n\n const controller: SequenceController = {\n play() {\n controller.cancel();\n if (!hasDOM()) return Promise.resolve();\n active = plan(steps, defaults);\n return new Promise<void>((resolve) => {\n let left = active.length;\n settle = () => {\n settle = undefined;\n resolve();\n };\n if (!left) return settle();\n const run = active;\n run.forEach(({ el, opts }) => {\n const done = opts.onComplete;\n sa().animate(el, {\n ...opts,\n onComplete: (node) => {\n done?.(node);\n if (run === active && --left === 0) settle?.();\n },\n });\n });\n });\n },\n\n cancel() {\n io?.disconnect();\n io = undefined;\n prepared.forEach((el) => stopAnimation(el));\n prepared = [];\n active.forEach(({ el }) => stopAnimation(el));\n active = [];\n settle?.();\n },\n\n duration() {\n return plan(steps, defaults).reduce((max, p) => Math.max(max, p.end), 0);\n },\n };\n\n if (trigger && hasDOM() && supportsObserver()) {\n const el = resolveTargets(trigger)[0];\n if (el) {\n prepared = plan(steps, defaults).map(({ el: target }) => target);\n prepared.forEach((target) => prepareElement(target));\n io = new IntersectionObserver(\n (entries) => {\n if (!entries.some((e) => e.isIntersecting)) return;\n io?.disconnect();\n io = undefined;\n prepared = []; // play() takes over from here\n controller.play();\n },\n { threshold: defaults.threshold ?? 0.1, rootMargin: defaults.rootMargin ?? '0px' }\n );\n io.observe(el);\n }\n }\n\n return controller;\n}\n","/**\n * use-scroll-animate - parallax() helper\n *\n * Moves elements at a different speed than the page while they cross the\n * viewport. Built on the same scroll progress as `progressVar` (0 when the\n * element's top enters at the bottom, 1 when its bottom leaves at the top):\n * the progress is written to a CSS custom property (default `--sa-parallax`)\n * and the offset is applied with the individual `translate` property, so it\n * composes with entrance animations and other `transform`s.\n */\n\nimport { getScrollProgress, hasDOM, prefersReducedMotion, resolveTargets, supportsObserver } from './core';\n\nexport interface ParallaxHelperOptions {\n /**\n * Total distance the element shifts while it crosses the viewport, as a\n * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values\n * lag behind the scroll (background-like), negative values move ahead of it\n * (foreground-like). (default: `0.2`)\n */\n speed?: number;\n /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */\n axis?: 'x' | 'y';\n /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */\n progressVar?: string;\n /** Scroll container (default: the viewport) */\n root?: Element | null;\n /**\n * Under `prefers-reduced-motion: reduce` no offset is applied (the progress\n * variable is still written). Set to `false` to move anyway. (default: `true`)\n */\n respectReducedMotion?: boolean;\n}\n\nconst PASSIVE: AddEventListenerOptions = { passive: true };\n\n/**\n * Apply a scroll parallax to `target` (selector, Element, NodeList or array).\n * Returns a function that stops it and removes the inline styles it set.\n * SSR-safe (no-op without a DOM / IntersectionObserver).\n *\n * @example\n * const stop = parallax('.hero-bg', { speed: 0.3 });\n * parallax('.badge', { speed: -0.15, axis: 'x' });\n */\nexport function parallax(\n target: string | Element | NodeList | Element[],\n options: ParallaxHelperOptions = {}\n): () => void {\n const els = resolveTargets(target);\n if (!els.length || !hasDOM() || !supportsObserver()) return () => undefined;\n const { speed = 0.2, axis = 'y', root = null, respectReducedMotion = true } = options;\n const name = options.progressVar ? (options.progressVar.startsWith('--') ? options.progressVar : `--${options.progressVar}`) : '--sa-parallax';\n const unit = axis === 'x' ? 'vw' : 'vh';\n const visible = new Set<Element>();\n let frame = 0;\n let listening = false;\n const scroller: EventTarget = root || window;\n\n const apply = (el: Element) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n const p = getScrollProgress(el, root);\n style.setProperty(name, String(+p.toFixed(4)));\n if (respectReducedMotion && prefersReducedMotion()) {\n style.removeProperty('translate');\n return;\n }\n const offset = `${+((p - 0.5) * speed * 100).toFixed(3)}${unit}`;\n style.setProperty('translate', axis === 'x' ? `${offset} 0px` : `0px ${offset}`);\n };\n\n const update = () => {\n frame = 0;\n visible.forEach(apply);\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(update);\n };\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n const method = on ? 'addEventListener' : 'removeEventListener';\n scroller[method]('scroll', schedule, PASSIVE);\n window[method]('resize', schedule, PASSIVE);\n if (!on && frame) {\n cancelAnimationFrame(frame);\n frame = 0;\n }\n };\n\n const io = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) visible.add(entry.target);\n else visible.delete(entry.target);\n apply(entry.target); // report the edges even on fast scrolls\n });\n listen(visible.size > 0);\n },\n { threshold: 0, root }\n );\n els.forEach((el) => {\n apply(el); // no jump before the first observer callback\n io.observe(el);\n });\n\n return () => {\n io.disconnect();\n listen(false);\n visible.clear();\n els.forEach((el) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n style.removeProperty('translate');\n style.removeProperty(name);\n });\n };\n}\n","/**\n * use-scroll-animate\n *\n * A lightweight, dependency-free scroll animation library for modern web\n * applications. Built with TypeScript, powered by IntersectionObserver and\n * the Web Animations API (or the native scroll-driven timeline). Safe to\n * import during SSR. Framework integrations live in the subpath entries:\n * `use-scroll-animate/react`, `/vue`, `/svelte`, `/solid`, `/element`.\n *\n * @license MIT\n * @see https://github.com/HarrisonCN/use-scroll-animate\n */\n\nexport { createScrollAnimate, getScrollProgress, supportsScrollTimeline } from './core';\nexport { staggerChildren } from './stagger';\nexport { sequence } from './sequence';\nexport { parallax } from './parallax';\nexport { PRESETS, resolvePreset, resolveEasing, EASING_MAP } from './presets';\nexport type {\n AnimationPreset,\n EasingType,\n AnimationKeyframe,\n CustomAnimation,\n ProgressMode,\n ScrollEngine,\n AnimateOptions,\n ScrollAnimateConfig,\n AnimatedElement,\n ScrollAnimateInstance,\n} from './types';\nexport type { StaggerOptions } from './stagger';\nexport type { ParallaxHelperOptions } from './parallax';\nexport type { SequenceStep, SequenceOptions, SequenceController } from './sequence';\n\n// Default export: a ready-to-use singleton instance\nimport { createScrollAnimate } from './core';\n\n/**\n * Default singleton instance of ScrollAnimate.\n * Ready to use out of the box with sensible defaults.\n *\n * @example\n * ```js\n * import ScrollAnimate from 'use-scroll-animate';\n *\n * // Auto-initialize all elements with data-sa attribute\n * ScrollAnimate.init();\n *\n * // Or manually observe elements\n * ScrollAnimate.observe('.my-element', { animation: 'fade-in-up' });\n * ```\n */\nconst ScrollAnimate = /* @__PURE__ */ createScrollAnimate();\nexport default ScrollAnimate;\n"],"names":[],"mappings":";;;;AAAA;;;AAGG;AA8BH,IAAI,QAAQ,GAAiC,IAAI;AACjD,IAAI,MAAM,GAAG,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;;;;;;;;;;;AAWG;AA0BH;;;;;;;;;;;;;;AAcG;AACH,MAAM,aAAa,mBAAmB,mBAAmB;;;;"}
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ScrollAnimate={})}(this,function(e){"use strict";const t={"fade-in":{from:{opacity:0},to:{opacity:1}},"fade-in-up":{from:{opacity:0,transform:"translateY(40px)"},to:{opacity:1,transform:"translateY(0px)"}},"fade-in-down":{from:{opacity:0,transform:"translateY(-40px)"},to:{opacity:1,transform:"translateY(0px)"}},"fade-in-left":{from:{opacity:0,transform:"translateX(-40px)"},to:{opacity:1,transform:"translateX(0px)"}},"fade-in-right":{from:{opacity:0,transform:"translateX(40px)"},to:{opacity:1,transform:"translateX(0px)"}},"zoom-in":{from:{opacity:0,transform:"scale(0.8)"},to:{opacity:1,transform:"scale(1)"}},"zoom-out":{from:{opacity:0,transform:"scale(1.2)"},to:{opacity:1,transform:"scale(1)"}},"flip-x":{from:{opacity:0,transform:"rotateX(-90deg)"},to:{opacity:1,transform:"rotateX(0deg)"}},"flip-y":{from:{opacity:0,transform:"rotateY(-90deg)"},to:{opacity:1,transform:"rotateY(0deg)"}},"slide-up":{from:{transform:"translateY(100%)"},to:{transform:"translateY(0px)"}},"slide-down":{from:{transform:"translateY(-100%)"},to:{transform:"translateY(0px)"}},"slide-left":{from:{transform:"translateX(-100%)"},to:{transform:"translateX(0px)"}},"slide-right":{from:{transform:"translateX(100%)"},to:{transform:"translateX(0px)"}},bounce:{from:{opacity:0,transform:"translateY(-60px)"},to:{opacity:1,transform:"translateY(0px)"}},"rotate-in":{from:{opacity:0,transform:"rotate(-180deg) scale(0.5)"},to:{opacity:1,transform:"rotate(0deg) scale(1)"}},"blur-in":{from:{opacity:0,filter:"blur(12px)"},to:{opacity:1,filter:"blur(0px)"}},"skew-in":{from:{opacity:0,transform:"skewX(20deg) translateX(30px)"},to:{opacity:1,transform:"skewX(0deg) translateX(0px)"}},"scale-x":{from:{transform:"scaleX(0)"},to:{transform:"scaleX(1)"}},"scale-y":{from:{transform:"scaleY(0)"},to:{transform:"scaleY(1)"}},shimmer:{from:{opacity:.5,filter:"brightness(1)"},to:{opacity:1,filter:"brightness(1.5)"}},pulse:{from:{transform:"scale(1)"},to:{transform:"scale(1.05)"}},swing:{from:{transform:"rotate(-10deg)"},to:{transform:"rotate(10deg)"}},"scale-up":{from:{opacity:0,transform:"scale(0.5)"},to:{opacity:1,transform:"scale(1)"}},"blur-in-up":{from:{opacity:0,filter:"blur(12px)",transform:"translateY(40px)"},to:{opacity:1,filter:"blur(0px)",transform:"translateY(0px)"}},"flip-up":{from:{opacity:0,transform:"perspective(800px) rotateX(60deg)"},to:{opacity:1,transform:"perspective(800px) rotateX(0deg)"}},"flip-down":{from:{opacity:0,transform:"perspective(800px) rotateX(-60deg)"},to:{opacity:1,transform:"perspective(800px) rotateX(0deg)"}},"rotate-left":{from:{opacity:0,transform:"rotate(-15deg) translateX(-40px)"},to:{opacity:1,transform:"rotate(0deg) translateX(0px)"}},"rotate-right":{from:{opacity:0,transform:"rotate(15deg) translateX(40px)"},to:{opacity:1,transform:"rotate(0deg) translateX(0px)"}},"clip-up":{from:{clipPath:"inset(100% 0% 0% 0%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-down":{from:{clipPath:"inset(0% 0% 100% 0%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-left":{from:{clipPath:"inset(0% 0% 0% 100%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-right":{from:{clipPath:"inset(0% 100% 0% 0%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-circle":{from:{clipPath:"circle(0% at 50% 50%)"},to:{clipPath:"circle(75% at 50% 50%)"}}};function r(e){if("string"==typeof e)return t[e.trim()]??t["fade-in-up"];if(Array.isArray(e)){const r={from:{},to:{}};return e.forEach(e=>{const o=t[e.trim()];o&&(Object.entries(o.from).forEach(([e,t])=>{"transform"===e&&r.from[e]?r.from[e]=`${r.from[e]} ${t}`:r.from[e]=t}),Object.entries(o.to).forEach(([e,t])=>{"transform"===e&&r.to[e]?r.to[e]=`${r.to[e]} ${t}`:r.to[e]=t}))}),r}return e}const o={linear:"linear",ease:"ease","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out",spring:"cubic-bezier(0.34, 1.56, 0.64, 1)","soft-spring":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","heavy-bounce":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"};function n(e){return"string"==typeof e?o[e]??e:Array.isArray(e)?`cubic-bezier(${e.join(", ")})`:"function"==typeof e?"linear":"ease"}const a={defaultAnimation:"fade-in-up",defaultDuration:600,defaultDelay:0,defaultEasing:"ease",defaultThreshold:.1,defaultRootMargin:"0px",defaultRepeat:!1,defaultOnce:!0,defaultOffset:0,hiddenClass:"sa-hidden",visibleClass:"sa-visible",useClassNames:!1,disabled:!1,root:null,autoUnregister:!0,defaultEngine:"auto"},s=()=>{},i=()=>"undefined"!=typeof window&&"undefined"!=typeof document,c=()=>i()&&"undefined"!=typeof IntersectionObserver;let l,f;function d(){return!!i()&&(void 0===l&&(l="function"==typeof window.matchMedia?window.matchMedia("(prefers-reduced-motion: reduce)"):null),!!l&&l.matches)}function u(){return void 0===f&&(f=i()&&"undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("animation-timeline: view()")&&"function"==typeof globalThis.ViewTimeline),f}function p(e){if(void 0===e||""===e.trim())return;const t=parseFloat(e);return Number.isFinite(t)?t:void 0}const m=["entry 0%","entry 100%"];function g(e){const t=e.trim();return t?t.startsWith("--")?t:`--${t}`:"--sa-progress"}function h(e,t){return y(function(e){const t={},r=e("animation");r&&(t.animation=r.includes(",")?r.split(",").map(e=>e.trim()):r.trim()),t.duration=p(e("duration")),t.delay=p(e("delay"));const o=e("easing");if(o){const e=o.trim();if(e.startsWith("["))try{t.easing=JSON.parse(e)}catch{}else t.easing=e}const n=e("threshold");n&&(t.threshold=n.includes(",")?n.split(",").map(parseFloat).filter(Number.isFinite):p(n));const a=e("root-margin");a&&(t.rootMargin=a);const s=e("repeat");void 0!==s&&(t.repeat="false"!==s);const i=e("once");void 0!==i&&(t.once="false"!==i),t.offset=p(e("offset")),t.stagger=p(e("stagger"));const c=e("progress-var");void 0!==c&&(t.progressVar=g(c));const l=e("engine")?.trim();"auto"!==l&&"js"!==l&&"css"!==l||(t.engine=l);const f=e("view-range");if(f){const[e,r]=f.split(",").map(e=>e.trim());e&&r&&(t.viewRange=[e,r])}const d=e("exit");if(void 0!==d){const e=d.trim();t.exit=""===e||"true"===e||"false"!==e&&(e.includes(",")?e.split(",").map(e=>e.trim()):e)}const u=e("progress");return u&&(t.progressMode="scroll"===u.trim()?"scroll":"ratio"),Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}(t=>{const r=e.getAttribute(`data-sa-${t}`);return null===r?void 0:r}),t)}function y(e,t){let r=e.engine??t.defaultEngine;"auto"===r&&(void 0!==e.duration||void 0!==e.delay||void 0!==e.offset||(e.stagger??0)>0)&&(r="js");const o=e.exit??!1,n=e.repeat??(!!o||t.defaultRepeat),a=e.threshold??t.defaultThreshold;return{animation:e.animation??t.defaultAnimation,duration:e.duration??t.defaultDuration,delay:e.delay??t.defaultDelay,easing:e.easing??t.defaultEasing,threshold:Array.isArray(a)&&0===a.length?t.defaultThreshold:a,rootMargin:e.rootMargin??t.defaultRootMargin,repeat:n,once:e.once??(!n&&t.defaultOnce),offset:e.offset??t.defaultOffset,stagger:e.stagger??0,onStart:e.onStart??s,onComplete:e.onComplete??s,onEnter:e.onEnter??s,onLeave:e.onLeave??s,onProgress:e.onProgress??s,progressMode:e.progressMode??"ratio",progressVar:e.progressVar?g(e.progressVar):"",engine:r,viewRange:e.viewRange??m,exit:o}}function v(e){return e&&i()?"string"==typeof e?Array.from(document.querySelectorAll(e)):e instanceof Element?[e]:Array.isArray(e)||e instanceof NodeList?Array.from(e).filter(e=>e instanceof Element):[]:[]}function b(e,t){if(!i())return 0;const r=e.getBoundingClientRect();let o=0,n=window.innerHeight||document.documentElement.clientHeight||0;if(t){const e=t.getBoundingClientRect();o=e.top,n=e.height}const a=n+r.height;if(a<=0)return 0;const s=(o+n-r.top)/a;return s<0?0:s>1?1:s}const x=new WeakMap,E=new WeakMap,w=new WeakMap;function S(e){const t=E.get(e);t&&(E.delete(e),t.cancel());const r=x.get(e);r&&(x.delete(e),r.onfinish=null,r.cancel());const o=w.get(e);void 0!==o&&(clearTimeout(o),w.delete(e))}function M(e,t){const r=e.style;r&&Object.keys(t).forEach(e=>{r[e]=String(t[e])})}const C=/(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)([a-z%]*)/gi;let O,A;function P(e,t){if("function"!=typeof t)return{keyframes:[e.from,e.to],easing:n(t)};const r=function(e){const t=[];for(let r=0;r<=30;r++){const o=e(r/30);t.push(Number.isFinite(o)?+o.toFixed(4):r/30)}return t}(t);if(void 0===O&&(O="undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("animation-timing-function","linear(0, 1)")),O)return{keyframes:[e.from,e.to],easing:`linear(${r.join(", ")})`};const o=Object.keys(e.from).filter(t=>t in e.to);return{keyframes:r.map((t,r)=>{const n={offset:r/30};return o.forEach(r=>{n[r]=function(e,t,r){if("number"==typeof e&&"number"==typeof t)return e+(t-e)*r;const o=String(e),n=String(t),a=[],s=[],i=o.replace(C,(e,t,r)=>(a.push([parseFloat(t),r]),"#"));if(i!==n.replace(C,(e,t,r)=>(s.push([parseFloat(t),r]),"#"))||a.length!==s.length)return r<.5?e:t;let c=0,l=!0;const f=i.replace(/#/g,()=>{const[e,t]=a[c],[o,n]=s[c++];t!==n&&0!==e&&0!==o&&t&&n&&(l=!1);const i=t||n;return`${+(e+(o-e)*r).toFixed(4)}${i}`});return l?f:r<.5?e:t}(e.from[r],e.to[r],t)}),n}),easing:"linear"}}function $(e,t){if(S(e),t.useClassNames)e.classList.remove(t.hiddenClass),e.classList.add(t.visibleClass);else{const t=e.style;t&&(t.opacity="")}}function X(e,t={}){$(e,{...a,...t})}function k(e){return!!e.disabled||d()}function F(e,t,o,n=0,a){const{duration:s,delay:i,stagger:c,onStart:l,onComplete:f}=t,d=Math.max(0,i+n*c);if(S(e),k(o))return $(e,o),l(e),void f(e);if(o.useClassNames)return d>0&&(e.style.animationDelay=`${d}ms`),e.classList.remove(o.hiddenClass),e.classList.add(o.visibleClass),l(e),a?.add(e),void w.set(e,setTimeout(()=>{w.delete(e),a?.delete(e),f(e)},s+d));const u=r(t.animation);if(!("opacity"in u.to)){const t=e.style;t&&"0"===t.opacity&&(t.opacity="")}if("function"!=typeof e.animate)return M(e,u.to),l(e),void f(e);const p=P(u,t.easing),m={duration:s,delay:d,easing:p.easing,fill:"both"};let g;try{g=e.animate(p.keyframes,m)}catch{g=e.animate(p.keyframes,{...m,easing:"ease"})}x.set(e,g),l(e),g.onfinish=()=>{if(x.get(e)===g){x.delete(e);try{g.commitStyles()}catch{M(e,u.to)}g.cancel()}f(e)}}function N(e,t){if(S(e),t.useClassNames)e.classList.add(t.hiddenClass),e.classList.remove(t.visibleClass);else{const t=e.style;t&&(t.opacity="0")}}function L(e,t={}){const r={...a,...t};k(r)||N(e,r)}function j(){if(!A){A=[];for(let e=0;e<=100;e++)A.push(e/100)}return A}const T={passive:!0};function Y(e={}){let t={...a,...e};const o=new Map;let n=new WeakSet;const l=new Set;let f=0,d=null;const p=new Set,m=new Set,g=new Set,C=new Map;function O(e,t,r){let o=C.get(e);o||C.set(e,o=new Map);let n=o.get(t);return n||o.set(t,n=r()),n}function A(e,r){const n=o.get(e);n&&(n.observer.unobserve(e),n.progressObserver?.unobserve(e),o.delete(e),V(e),"css"!==n.engine?r&&!n.animated&&$(e,t):r?(g.delete(e),$(e,t)):!1===e.isConnected&&g.delete(e))}function X(){o.forEach((e,t)=>{!1===t.isConnected&&A(t,!1)})}function L(e,t,r){const o=t.options;if(o.onProgress(e,r),o.progressVar){const t=e.style;t&&t.setProperty(o.progressVar,String(+r.toFixed(4)))}}function Y(){f=0,l.forEach(e=>{const r=o.get(e);r&&L(e,r,b(e,t.root))})}const I=()=>f||(f=requestAnimationFrame(Y));function R(e){if(e===!!d)return;const r=e?"addEventListener":"removeEventListener",o=d||t.root||window;o[r]("scroll",I,T),window[r]("resize",I,T),d=e?o:null,!e&&f&&(cancelAnimationFrame(f),f=0)}function V(e){l.delete(e)&&!l.size&&R(!1)}function z(e){e.forEach(e=>{const r=e.target,n=o.get(r);n&&(e.isIntersecting?(l.add(r),R(!0)):V(r),L(r,n,b(r,t.root)))})}function W(e){const a=new Map;e.forEach(e=>{const s=e.target,i=o.get(s);if(!i)return;const c=i.options;if(!1!==s.isConnected)if("css"!==i.engine)if(e.isIntersecting){if(c.onEnter(s),i.animated&&!c.repeat)return;let e=0;if(c.stagger>0){const t=s.parentElement;e=a.get(t)??0,a.set(t,e+1)}F(s,c,t,e,m),i.animated=!0,c.once&&!c.repeat&&(i.observer.unobserve(s),t.autoUnregister&&!i.progressObserver&&(n.add(s),A(s,!1)))}else c.onLeave(s),c.repeat&&i.animated&&(k(t)||(c.exit?function(e,t,o){if(o.useClassNames||"function"!=typeof e.animate)return void N(e,o);S(e);const n=r(!0===t.exit?t.animation:t.exit),a=P({from:n.to,to:n.from},t.easing),s={duration:t.duration,easing:a.easing,fill:"forwards"};let i;try{i=e.animate(a.keyframes,s)}catch{i=e.animate(a.keyframes,{...s,easing:"ease"})}x.set(e,i)}(s,c,t):N(s,t)),i.animated=!1);else e.isIntersecting?(c.onEnter(s),i.animated||(i.animated=!0,c.onStart(s)),c.once&&!c.repeat&&(i.observer.unobserve(s),t.autoUnregister&&!i.progressObserver&&(n.add(s),A(s,!1)))):(c.onLeave(s),c.repeat&&(i.animated=!1));else A(s,!1)})}function q(e){e.forEach(e=>{const t=o.get(e.target);t&&L(e.target,t,e.intersectionRatio)})}function D(e){const r=function(e,t){if(!t)return e;const r=(e||"0px").trim().split(/\s+/),o=r[0],n=r[1]??o,a=r[2]??o,s=r[3]??n,i=/^(-?\d*\.?\d+)(px)?$/.exec(a);return`${o} ${n} ${(i?parseFloat(i[1]):0)-t}px ${s}`}(e.rootMargin,e.offset),o=e.threshold,n=t.root;return O(n,`m|${r}|${String(o)}`,()=>new IntersectionObserver(W,{threshold:o,rootMargin:r,root:n}))}function U(e,r,o){var n;r.observer=D(r.options),o&&r.observer.observe(e),r.progressObserver=(n=r.options).onProgress!==s||n.progressVar?function(e){const r=t.root;return"scroll"===e.progressMode?O(r,`s|${e.rootMargin}`,()=>new IntersectionObserver(z,{threshold:0,rootMargin:e.rootMargin,root:r})):O(r,`p|${e.rootMargin}`,()=>new IntersectionObserver(q,{threshold:j(),rootMargin:e.rootMargin,root:r}))}(r.options):void 0,r.progressObserver?.observe(e)}function _(e,a){if(o.has(e)||n.has(e))return;if(!c())return void $(e,t);const s={element:e,options:a,animated:!1,engine:"js"};(function(e){return"js"!==e.engine&&!t.useClassNames&&!k(t)&&u()})(a)&&(S(e),function(e,t,o){if("function"!=typeof e.animate)return null;const n=r(t.animation),a=P(n,t.easing);let s;try{const r=new globalThis.ViewTimeline({subject:e,axis:"block"}),o={fill:"both",easing:a.easing,timeline:r,rangeStart:t.viewRange[0],rangeEnd:t.viewRange[1]};try{s=e.animate(a.keyframes,o)}catch{s=e.animate(a.keyframes,{...o,easing:"linear"})}}catch{return null}if(x.set(e,s),t.exit){const o=r(!0===t.exit?t.animation:t.exit),n=P({from:o.to,to:o.from},t.easing);try{const t=new globalThis.ViewTimeline({subject:e,axis:"block"}),r={fill:"forwards",easing:n.easing,timeline:t,rangeStart:"exit 0%",rangeEnd:"exit 100%"};E.set(e,e.animate(n.keyframes,r))}catch{}}const i=t.repeat||!t.once;return s.onfinish=()=>{if(!i&&x.get(e)===s){x.delete(e);try{s.commitStyles()}catch{M(e,n.to)}s.cancel(),o?.()}t.onComplete(e)},s}(e,a,()=>g.delete(e))&&(s.engine="css",g.add(e))),"js"!==s.engine||k(t)||N(e,t),o.set(e,s),U(e,s,!0)}function B(e){o.has(e)||_(e,h(e,t))}const H={observe(e,r={}){X();const o=y(r,t);v(e).forEach(e=>_(e,o))},unobserve(e){v(e).forEach(e=>{n.delete(e),A(e,!0)})},init(e){const t=e??(i()?document:null);t&&(X(),t.querySelectorAll("[data-sa]").forEach(B))},watch(e){const t=e??(i()?document:null);if(!t||"undefined"==typeof MutationObserver)return s;H.init(t);const r=e=>{e.hasAttribute("data-sa")&&B(e),e.querySelectorAll("[data-sa]").forEach(B)},o=new MutationObserver(e=>{let t=!1;e.forEach(e=>{if("attributes"===e.type){const t=e.target;return void(!1!==t.isConnected&&r(t))}e.addedNodes.forEach(e=>{e instanceof Element&&!1!==e.isConnected&&r(e)}),e.removedNodes.length&&(t=!0)}),t&&X()});return o.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-sa"]}),p.add(o),()=>{o.disconnect(),p.delete(o)}},destroy(){p.forEach(e=>e.disconnect()),p.clear(),m.forEach(e=>{const t=w.get(e);void 0!==t&&(clearTimeout(t),w.delete(e))}),m.clear(),o.forEach((e,r)=>{e.animated||"css"===e.engine||$(r,t)}),g.forEach(e=>{x.has(e)&&$(e,t)}),g.clear(),C.forEach(e=>e.forEach(e=>e.disconnect())),C.clear(),o.clear(),l.clear(),R(!1),n=new WeakSet},refresh(){C.forEach(e=>e.forEach(e=>e.disconnect())),C.clear(),l.clear(),R(!1),X(),c()&&o.forEach((e,t)=>{U(t,e,!(e.animated&&e.options.once&&!e.options.repeat))})},animate(e,r={}){const o=y(r,t);v(e).forEach(e=>F(e,o,t,0,m))},getObservedElements:()=>Array.from(o.values()),configure(e){t={...t,...e}}};return H}let I=null;let R=null;function V(e,t){const r=[];let o=0;return e.forEach(e=>{const{target:n,gap:a=0,at:s,...i}=e,c={...t,...i},l=c.duration??600,f=Math.max(0,s??o+a)+(c.delay??0);let d=Math.max(o,f);v(n).forEach((e,t)=>{const o=f+t*(c.stagger??0);r.push({el:e,opts:{...c,duration:l,delay:o,stagger:0},end:o+l}),d=Math.max(d,o+l)}),o=d}),r}const z={passive:!0};
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ScrollAnimate={})}(this,function(e){"use strict";const t={"fade-in":{from:{opacity:0},to:{opacity:1}},"fade-in-up":{from:{opacity:0,transform:"translateY(40px)"},to:{opacity:1,transform:"translateY(0px)"}},"fade-in-down":{from:{opacity:0,transform:"translateY(-40px)"},to:{opacity:1,transform:"translateY(0px)"}},"fade-in-left":{from:{opacity:0,transform:"translateX(-40px)"},to:{opacity:1,transform:"translateX(0px)"}},"fade-in-right":{from:{opacity:0,transform:"translateX(40px)"},to:{opacity:1,transform:"translateX(0px)"}},"zoom-in":{from:{opacity:0,transform:"scale(0.8)"},to:{opacity:1,transform:"scale(1)"}},"zoom-out":{from:{opacity:0,transform:"scale(1.2)"},to:{opacity:1,transform:"scale(1)"}},"flip-x":{from:{opacity:0,transform:"rotateX(-90deg)"},to:{opacity:1,transform:"rotateX(0deg)"}},"flip-y":{from:{opacity:0,transform:"rotateY(-90deg)"},to:{opacity:1,transform:"rotateY(0deg)"}},"slide-up":{from:{transform:"translateY(100%)"},to:{transform:"translateY(0px)"}},"slide-down":{from:{transform:"translateY(-100%)"},to:{transform:"translateY(0px)"}},"slide-left":{from:{transform:"translateX(-100%)"},to:{transform:"translateX(0px)"}},"slide-right":{from:{transform:"translateX(100%)"},to:{transform:"translateX(0px)"}},bounce:{from:{opacity:0,transform:"translateY(-60px)"},to:{opacity:1,transform:"translateY(0px)"}},"rotate-in":{from:{opacity:0,transform:"rotate(-180deg) scale(0.5)"},to:{opacity:1,transform:"rotate(0deg) scale(1)"}},"blur-in":{from:{opacity:0,filter:"blur(12px)"},to:{opacity:1,filter:"blur(0px)"}},"skew-in":{from:{opacity:0,transform:"skewX(20deg) translateX(30px)"},to:{opacity:1,transform:"skewX(0deg) translateX(0px)"}},"scale-x":{from:{transform:"scaleX(0)"},to:{transform:"scaleX(1)"}},"scale-y":{from:{transform:"scaleY(0)"},to:{transform:"scaleY(1)"}},shimmer:{from:{opacity:.5,filter:"brightness(1)"},to:{opacity:1,filter:"brightness(1.5)"}},pulse:{from:{transform:"scale(1)"},to:{transform:"scale(1.05)"}},swing:{from:{transform:"rotate(-10deg)"},to:{transform:"rotate(10deg)"}},"scale-up":{from:{opacity:0,transform:"scale(0.5)"},to:{opacity:1,transform:"scale(1)"}},"blur-in-up":{from:{opacity:0,filter:"blur(12px)",transform:"translateY(40px)"},to:{opacity:1,filter:"blur(0px)",transform:"translateY(0px)"}},"flip-up":{from:{opacity:0,transform:"perspective(800px) rotateX(60deg)"},to:{opacity:1,transform:"perspective(800px) rotateX(0deg)"}},"flip-down":{from:{opacity:0,transform:"perspective(800px) rotateX(-60deg)"},to:{opacity:1,transform:"perspective(800px) rotateX(0deg)"}},"rotate-left":{from:{opacity:0,transform:"rotate(-15deg) translateX(-40px)"},to:{opacity:1,transform:"rotate(0deg) translateX(0px)"}},"rotate-right":{from:{opacity:0,transform:"rotate(15deg) translateX(40px)"},to:{opacity:1,transform:"rotate(0deg) translateX(0px)"}},"clip-up":{from:{clipPath:"inset(100% 0% 0% 0%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-down":{from:{clipPath:"inset(0% 0% 100% 0%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-left":{from:{clipPath:"inset(0% 0% 0% 100%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-right":{from:{clipPath:"inset(0% 100% 0% 0%)"},to:{clipPath:"inset(0% 0% 0% 0%)"}},"clip-circle":{from:{clipPath:"circle(0% at 50% 50%)"},to:{clipPath:"circle(75% at 50% 50%)"}}};function r(e){if("string"==typeof e)return t[e.trim()]??t["fade-in-up"];if(Array.isArray(e)){const r={from:{},to:{}};return e.forEach(e=>{const n=t[e.trim()];n&&(Object.entries(n.from).forEach(([e,t])=>{"transform"===e&&r.from[e]?r.from[e]=`${r.from[e]} ${t}`:r.from[e]=t}),Object.entries(n.to).forEach(([e,t])=>{"transform"===e&&r.to[e]?r.to[e]=`${r.to[e]} ${t}`:r.to[e]=t}))}),r}return e}const n={linear:"linear",ease:"ease","ease-in":"ease-in","ease-out":"ease-out","ease-in-out":"ease-in-out",spring:"cubic-bezier(0.34, 1.56, 0.64, 1)","soft-spring":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","heavy-bounce":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"};function o(e){return"string"==typeof e?n[e]??e:Array.isArray(e)?`cubic-bezier(${e.join(", ")})`:"function"==typeof e?"linear":"ease"}const a={defaultAnimation:"fade-in-up",defaultDuration:600,defaultDelay:0,defaultEasing:"ease",defaultThreshold:.1,defaultRootMargin:"0px",defaultRepeat:!1,defaultOnce:!0,defaultOffset:0,hiddenClass:"sa-hidden",visibleClass:"sa-visible",useClassNames:!1,disabled:!1,root:null,autoUnregister:!0,defaultEngine:"auto"},s=()=>{},i=()=>"undefined"!=typeof window&&"undefined"!=typeof document,c=()=>i()&&"undefined"!=typeof IntersectionObserver;let l,f;function d(){return!!i()&&(void 0===l&&(l="function"==typeof window.matchMedia?window.matchMedia("(prefers-reduced-motion: reduce)"):null),!!l&&l.matches)}function u(){return void 0===f&&(f=i()&&"undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("animation-timeline: view()")&&"function"==typeof globalThis.ViewTimeline),f}function p(e){if(void 0===e||""===e.trim())return;const t=parseFloat(e);return Number.isFinite(t)?t:void 0}const m=["entry 0%","entry 100%"];function g(e){const t=e.trim();return t?t.startsWith("--")?t:`--${t}`:"--sa-progress"}function h(e,t){return y(function(e){const t={},r=e("animation");r&&(t.animation=r.includes(",")?r.split(",").map(e=>e.trim()):r.trim()),t.duration=p(e("duration")),t.delay=p(e("delay"));const n=e("easing");if(n){const e=n.trim();if(e.startsWith("["))try{t.easing=JSON.parse(e)}catch{}else t.easing=e}const o=e("threshold");o&&(t.threshold=o.includes(",")?o.split(",").map(parseFloat).filter(Number.isFinite):p(o));const a=e("root-margin");a&&(t.rootMargin=a);const s=e("repeat");void 0!==s&&(t.repeat="false"!==s);const i=e("once");void 0!==i&&(t.once="false"!==i),t.offset=p(e("offset")),t.stagger=p(e("stagger"));const c=e("progress-var");void 0!==c&&(t.progressVar=g(c));const l=e("engine")?.trim();"auto"!==l&&"js"!==l&&"css"!==l||(t.engine=l);const f=e("view-range");if(f){const[e,r]=f.split(",").map(e=>e.trim());e&&r&&(t.viewRange=[e,r])}const d=e("exit");if(void 0!==d){const e=d.trim();t.exit=""===e||"true"===e||"false"!==e&&(e.includes(",")?e.split(",").map(e=>e.trim()):e)}const u=e("progress");return u&&(t.progressMode="scroll"===u.trim()?"scroll":"ratio"),Object.keys(t).forEach(e=>void 0===t[e]&&delete t[e]),t}(t=>{const r=e.getAttribute(`data-sa-${t}`);return null===r?void 0:r}),t)}function y(e,t){let r=e.engine??t.defaultEngine;"auto"===r&&(void 0!==e.duration||void 0!==e.delay||void 0!==e.offset||(e.stagger??0)>0)&&(r="js");const n=e.exit??!1,o=e.repeat??(!!n||t.defaultRepeat),a=e.threshold??t.defaultThreshold;return{animation:e.animation??t.defaultAnimation,duration:e.duration??t.defaultDuration,delay:e.delay??t.defaultDelay,easing:e.easing??t.defaultEasing,threshold:Array.isArray(a)&&0===a.length?t.defaultThreshold:a,rootMargin:e.rootMargin??t.defaultRootMargin,repeat:o,once:e.once??(!o&&t.defaultOnce),offset:e.offset??t.defaultOffset,stagger:e.stagger??0,onStart:e.onStart??s,onComplete:e.onComplete??s,onEnter:e.onEnter??s,onLeave:e.onLeave??s,onProgress:e.onProgress??s,progressMode:e.progressMode??"ratio",progressVar:e.progressVar?g(e.progressVar):"",engine:r,viewRange:e.viewRange??m,exit:n}}function v(e){return e&&i()?"string"==typeof e?Array.from(document.querySelectorAll(e)):e instanceof Element?[e]:Array.isArray(e)||e instanceof NodeList?Array.from(e).filter(e=>e instanceof Element):[]:[]}function b(e,t){if(!i())return 0;const r=e.getBoundingClientRect();let n=0,o=window.innerHeight||document.documentElement.clientHeight||0;if(t){const e=t.getBoundingClientRect();n=e.top,o=e.height}const a=o+r.height;if(a<=0)return 0;const s=(n+o-r.top)/a;return s<0?0:s>1?1:s}const x=new WeakMap,E=new WeakMap,w=new WeakMap;function S(e){const t=E.get(e);t&&(E.delete(e),t.cancel());const r=x.get(e);r&&(x.delete(e),r.onfinish=null,r.cancel());const n=w.get(e);void 0!==n&&(clearTimeout(n),w.delete(e))}function M(e,t){const r=e.style;r&&Object.keys(t).forEach(e=>{r[e]=String(t[e])})}const C=/(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)([a-z%]*)/gi;let O,A;function P(e,t){if("function"!=typeof t)return{keyframes:[e.from,e.to],easing:o(t)};const r=function(e){const t=[];for(let r=0;r<=30;r++){const n=e(r/30);t.push(Number.isFinite(n)?+n.toFixed(4):r/30)}return t}(t);if(void 0===O&&(O="undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("animation-timing-function","linear(0, 1)")),O)return{keyframes:[e.from,e.to],easing:`linear(${r.join(", ")})`};const n=Object.keys(e.from).filter(t=>t in e.to);return{keyframes:r.map((t,r)=>{const o={offset:r/30};return n.forEach(r=>{o[r]=function(e,t,r){if("number"==typeof e&&"number"==typeof t)return e+(t-e)*r;const n=String(e),o=String(t),a=[],s=[],i=n.replace(C,(e,t,r)=>(a.push([parseFloat(t),r]),"#"));if(i!==o.replace(C,(e,t,r)=>(s.push([parseFloat(t),r]),"#"))||a.length!==s.length)return r<.5?e:t;let c=0,l=!0;const f=i.replace(/#/g,()=>{const[e,t]=a[c],[n,o]=s[c++];t!==o&&0!==e&&0!==n&&t&&o&&(l=!1);const i=t||o;return`${+(e+(n-e)*r).toFixed(4)}${i}`});return l?f:r<.5?e:t}(e.from[r],e.to[r],t)}),o}),easing:"linear"}}function $(e,t){if(S(e),t.useClassNames)e.classList.remove(t.hiddenClass),e.classList.add(t.visibleClass);else{const t=e.style;t&&(t.opacity="")}}function X(e,t={}){$(e,{...a,...t})}function k(e){return!!e.disabled||d()}function F(e,t,n,o=0,a){const{duration:s,delay:i,stagger:c,onStart:l,onComplete:f}=t,d=Math.max(0,i+o*c);if(S(e),k(n))return $(e,n),l(e),void f(e);if(n.useClassNames)return d>0&&(e.style.animationDelay=`${d}ms`),e.classList.remove(n.hiddenClass),e.classList.add(n.visibleClass),l(e),a?.add(e),void w.set(e,setTimeout(()=>{w.delete(e),a?.delete(e),f(e)},s+d));const u=r(t.animation);if(!("opacity"in u.to)){const t=e.style;t&&"0"===t.opacity&&(t.opacity="")}if("function"!=typeof e.animate)return M(e,u.to),l(e),void f(e);const p=P(u,t.easing),m={duration:s,delay:d,easing:p.easing,fill:"both"};let g;try{g=e.animate(p.keyframes,m)}catch{g=e.animate(p.keyframes,{...m,easing:"ease"})}x.set(e,g),l(e),g.onfinish=()=>{if(x.get(e)===g){x.delete(e);try{g.commitStyles()}catch{M(e,u.to)}g.cancel()}f(e)}}function N(e,t){if(S(e),t.useClassNames)e.classList.add(t.hiddenClass),e.classList.remove(t.visibleClass);else{const t=e.style;t&&(t.opacity="0")}}function L(e,t={}){const r={...a,...t};k(r)||N(e,r)}function j(){if(!A){A=[];for(let e=0;e<=100;e++)A.push(e/100)}return A}const T={passive:!0};function Y(e={}){let t={...a,...e};const n=new Map;let o=new WeakSet;const l=new Set;let f=0,d=null;const p=new Set,m=new Set,g=new Set,C=new Map;function O(e,t,r){let n=C.get(e);n||C.set(e,n=new Map);let o=n.get(t);return o||n.set(t,o=r()),o}function A(e,r){const o=n.get(e);o&&(o.observer.unobserve(e),o.progressObserver?.unobserve(e),n.delete(e),V(e),"css"!==o.engine?r&&!o.animated&&$(e,t):r?(g.delete(e),$(e,t)):!1===e.isConnected&&g.delete(e))}function X(){n.forEach((e,t)=>{!1===t.isConnected&&A(t,!1)})}function L(e,t,r){const n=t.options;if(n.onProgress(e,r),n.progressVar){const t=e.style;t&&t.setProperty(n.progressVar,String(+r.toFixed(4)))}}function Y(){f=0,l.forEach(e=>{const r=n.get(e);r&&L(e,r,b(e,t.root))})}const I=()=>f||(f=requestAnimationFrame(Y));function R(e){if(e===!!d)return;const r=e?"addEventListener":"removeEventListener",n=d||t.root||window;n[r]("scroll",I,T),window[r]("resize",I,T),d=e?n:null,!e&&f&&(cancelAnimationFrame(f),f=0)}function V(e){l.delete(e)&&!l.size&&R(!1)}function z(e){e.forEach(e=>{const r=e.target,o=n.get(r);o&&(e.isIntersecting?(l.add(r),R(!0)):V(r),L(r,o,b(r,t.root)))})}function W(e){const a=new Map;e.forEach(e=>{const s=e.target,i=n.get(s);if(!i)return;const c=i.options;if(!1!==s.isConnected)if("css"!==i.engine)if(e.isIntersecting){if(c.onEnter(s),i.animated&&!c.repeat)return;let e=0;if(c.stagger>0){const t=s.parentElement;e=a.get(t)??0,a.set(t,e+1)}F(s,c,t,e,m),i.animated=!0,c.once&&!c.repeat&&(i.observer.unobserve(s),t.autoUnregister&&!i.progressObserver&&(o.add(s),A(s,!1)))}else c.onLeave(s),c.repeat&&i.animated&&(k(t)||(c.exit?function(e,t,n){if(n.useClassNames||"function"!=typeof e.animate)return void N(e,n);S(e);const o=r(!0===t.exit?t.animation:t.exit),a=P({from:o.to,to:o.from},t.easing),s={duration:t.duration,easing:a.easing,fill:"forwards"};let i;try{i=e.animate(a.keyframes,s)}catch{i=e.animate(a.keyframes,{...s,easing:"ease"})}x.set(e,i)}(s,c,t):N(s,t)),i.animated=!1);else e.isIntersecting?(c.onEnter(s),i.animated||(i.animated=!0,c.onStart(s)),c.once&&!c.repeat&&(i.observer.unobserve(s),t.autoUnregister&&!i.progressObserver&&(o.add(s),A(s,!1)))):(c.onLeave(s),c.repeat&&(i.animated=!1));else A(s,!1)})}function q(e){e.forEach(e=>{const t=n.get(e.target);t&&L(e.target,t,e.intersectionRatio)})}function D(e){const r=function(e,t){if(!t)return e;const r=(e||"0px").trim().split(/\s+/),n=r[0],o=r[1]??n,a=r[2]??n,s=r[3]??o,i=/^(-?\d*\.?\d+)(px)?$/.exec(a);return`${n} ${o} ${(i?parseFloat(i[1]):0)-t}px ${s}`}(e.rootMargin,e.offset),n=e.threshold,o=t.root;return O(o,`m|${r}|${String(n)}`,()=>new IntersectionObserver(W,{threshold:n,rootMargin:r,root:o}))}function U(e,r,n){var o;r.observer=D(r.options),n&&r.observer.observe(e),r.progressObserver=(o=r.options).onProgress!==s||o.progressVar?function(e){const r=t.root;return"scroll"===e.progressMode?O(r,`s|${e.rootMargin}`,()=>new IntersectionObserver(z,{threshold:0,rootMargin:e.rootMargin,root:r})):O(r,`p|${e.rootMargin}`,()=>new IntersectionObserver(q,{threshold:j(),rootMargin:e.rootMargin,root:r}))}(r.options):void 0,r.progressObserver?.observe(e)}function _(e,a){if(n.has(e)||o.has(e))return;if(!c())return void $(e,t);const s={element:e,options:a,animated:!1,engine:"js"};(function(e){return"js"!==e.engine&&!t.useClassNames&&!k(t)&&u()})(a)&&(S(e),function(e,t,n){if("function"!=typeof e.animate)return null;const o=r(t.animation),a=P(o,t.easing);let s;try{const r=new globalThis.ViewTimeline({subject:e,axis:"block"}),n={fill:"both",easing:a.easing,timeline:r,rangeStart:t.viewRange[0],rangeEnd:t.viewRange[1]};try{s=e.animate(a.keyframes,n)}catch{s=e.animate(a.keyframes,{...n,easing:"linear"})}}catch{return null}if(x.set(e,s),t.exit){const n=r(!0===t.exit?t.animation:t.exit),o=P({from:n.to,to:n.from},t.easing);try{const t=new globalThis.ViewTimeline({subject:e,axis:"block"}),r={fill:"forwards",easing:o.easing,timeline:t,rangeStart:"exit 0%",rangeEnd:"exit 100%"};E.set(e,e.animate(o.keyframes,r))}catch{}}const i=t.repeat||!t.once;return s.onfinish=()=>{if(!i&&x.get(e)===s){x.delete(e);try{s.commitStyles()}catch{M(e,o.to)}s.cancel(),n?.()}t.onComplete(e)},s}(e,a,()=>g.delete(e))&&(s.engine="css",g.add(e))),"js"!==s.engine||k(t)||N(e,t),n.set(e,s),U(e,s,!0)}function B(e){n.has(e)||_(e,h(e,t))}const H={observe(e,r={}){X();const n=y(r,t);v(e).forEach(e=>_(e,n))},unobserve(e){v(e).forEach(e=>{o.delete(e),A(e,!0)})},init(e){const t=e??(i()?document:null);t&&(X(),t.querySelectorAll("[data-sa]").forEach(B))},watch(e){const t=e??(i()?document:null);if(!t||"undefined"==typeof MutationObserver)return s;H.init(t);const r=e=>{e.hasAttribute("data-sa")&&B(e),e.querySelectorAll("[data-sa]").forEach(B)},n=new MutationObserver(e=>{let t=!1;e.forEach(e=>{if("attributes"===e.type){const t=e.target;return void(!1!==t.isConnected&&r(t))}e.addedNodes.forEach(e=>{e instanceof Element&&!1!==e.isConnected&&r(e)}),e.removedNodes.length&&(t=!0)}),t&&X()});return n.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-sa"]}),p.add(n),()=>{n.disconnect(),p.delete(n)}},destroy(){p.forEach(e=>e.disconnect()),p.clear(),m.forEach(e=>{const t=w.get(e);void 0!==t&&(clearTimeout(t),w.delete(e))}),m.clear(),n.forEach((e,r)=>{e.animated||"css"===e.engine||$(r,t)}),g.forEach(e=>{x.has(e)&&$(e,t)}),g.clear(),C.forEach(e=>e.forEach(e=>e.disconnect())),C.clear(),n.clear(),l.clear(),R(!1),o=new WeakSet},refresh(){C.forEach(e=>e.forEach(e=>e.disconnect())),C.clear(),l.clear(),R(!1),X(),c()&&n.forEach((e,t)=>{U(t,e,!(e.animated&&e.options.once&&!e.options.repeat))})},animate(e,r={}){const n=y(r,t);v(e).forEach(e=>F(e,n,t,0,m))},getObservedElements:()=>Array.from(n.values()),configure(e){t={...t,...e}}};return H}let I=null;let R=null,V=!1;function z(e,t){const r=[];let n=0;return e.forEach(e=>{const{target:o,gap:a=0,at:s,...i}=e,c={...t,...i},l=c.duration??600,f=Math.max(0,s??n+a)+(c.delay??0);let d=Math.max(n,f);v(o).forEach((e,t)=>{const n=f+t*(c.stagger??0);r.push({el:e,opts:{...c,duration:l,delay:n,stagger:0},end:n+l}),d=Math.max(d,n+l)}),n=d}),r}const W={passive:!0};
2
2
  /**
3
3
  * use-scroll-animate
4
4
  *
@@ -11,5 +11,5 @@
11
11
  * @license MIT
12
12
  * @see https://github.com/HarrisonCN/use-scroll-animate
13
13
  */
14
- const W=Y();e.EASING_MAP=o,e.PRESETS=t,e.createScrollAnimate=Y,e.default=W,e.getScrollProgress=b,e.parallax=function(e,t={}){const r=v(e);if(!r.length||!i()||!c())return()=>{};const{speed:o=.2,axis:n="y",root:a=null,respectReducedMotion:s=!0}=t,l=t.progressVar?t.progressVar.startsWith("--")?t.progressVar:`--${t.progressVar}`:"--sa-parallax",f="x"===n?"vw":"vh",u=new Set;let p=0,m=!1;const g=a||window,h=e=>{const t=e.style;if(!t)return;const r=b(e,a);if(t.setProperty(l,String(+r.toFixed(4))),s&&d())return void t.removeProperty("translate");const i=`${+((r-.5)*o*100).toFixed(3)}${f}`;t.setProperty("translate","x"===n?`${i} 0px`:`0px ${i}`)},y=()=>{p=0,u.forEach(h)},x=()=>{p||(p=requestAnimationFrame(y))},E=e=>{if(e===m)return;m=e;const t=e?"addEventListener":"removeEventListener";g[t]("scroll",x,z),window[t]("resize",x,z),!e&&p&&(cancelAnimationFrame(p),p=0)},w=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting?u.add(e.target):u.delete(e.target),h(e.target)}),E(u.size>0)},{threshold:0,root:a});return r.forEach(e=>{h(e),w.observe(e)}),()=>{w.disconnect(),E(!1),u.clear(),r.forEach(e=>{const t=e.style;t&&(t.removeProperty("translate"),t.removeProperty(l))})}},e.resolveEasing=n,e.resolvePreset=r,e.sequence=function(e,t={}){const{trigger:r,instance:o,...n}=t;let a,s,l=[],f=[];const d={play:()=>(d.cancel(),i()?(l=V(e,n),new Promise(e=>{let t=l.length;if(s=()=>{s=void 0,e()},!t)return s();const r=l;r.forEach(({el:e,opts:n})=>{const a=n.onComplete;(o||R||(R=Y())).animate(e,{...n,onComplete:e=>{a?.(e),r===l&&0===--t&&s?.()}})})})):Promise.resolve()),cancel(){a?.disconnect(),a=void 0,f.forEach(e=>X(e)),f=[],l.forEach(({el:e})=>X(e)),l=[],s?.()},duration:()=>V(e,n).reduce((e,t)=>Math.max(e,t.end),0)};if(r&&i()&&c()){const t=v(r)[0];t&&(f=V(e,n).map(({el:e})=>e),f.forEach(e=>L(e)),a=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(a?.disconnect(),a=void 0,f=[],d.play())},{threshold:n.threshold??.1,rootMargin:n.rootMargin??"0px"}),a.observe(t))}return d},e.staggerChildren=function(e,t={},r){if(!e||!i()||!c())return()=>{};const o=r||I||(I=Y()),{stagger:n=80,delay:a=0,threshold:s=.1,rootMargin:l="0px",observeChildren:f=!1,...d}=t;let u=Array.from(e.children),p=!1;const m=[];u.forEach(e=>L(e));const g=new IntersectionObserver(t=>{!p&&t.some(e=>e.isIntersecting)&&(p=!0,g.disconnect(),u.forEach((t,r)=>{t.parentNode===e&&o.animate(t,{...d,delay:a+r*n})}),u=[])},{threshold:s,rootMargin:l});let h;return g.observe(e),f&&"undefined"!=typeof MutationObserver&&(h=new MutationObserver(t=>{t.forEach(t=>{t.addedNodes.forEach(t=>{t instanceof Element&&t.parentNode===e&&(p?(m.push(t),o.observe(t,{...d,delay:a,stagger:n,threshold:s,rootMargin:l})):(L(t),u.push(t)))}),t.removedNodes.forEach(e=>{if(!(e instanceof Element))return;u=u.filter(t=>t!==e);const t=m.indexOf(e);t>=0&&(m.splice(t,1),o.unobserve(e))})})}),h.observe(e,{childList:!0})),()=>{g.disconnect(),h?.disconnect(),p||(p=!0,u.forEach(e=>X(e)),u=[]),m.forEach(e=>o.unobserve(e)),m.length=0}},e.supportsScrollTimeline=u,Object.defineProperty(e,"__esModule",{value:!0})});
14
+ const q=Y();e.EASING_MAP=n,e.PRESETS=t,e.createScrollAnimate=Y,e.default=q,e.getScrollProgress=b,e.parallax=function(e,t={}){const r=v(e);if(!r.length||!i()||!c())return()=>{};const{speed:n=.2,axis:o="y",root:a=null,respectReducedMotion:s=!0}=t,l=t.progressVar?t.progressVar.startsWith("--")?t.progressVar:`--${t.progressVar}`:"--sa-parallax",f="x"===o?"vw":"vh",u=new Set;let p=0,m=!1;const g=a||window,h=e=>{const t=e.style;if(!t)return;const r=b(e,a);if(t.setProperty(l,String(+r.toFixed(4))),s&&d())return void t.removeProperty("translate");const i=`${+((r-.5)*n*100).toFixed(3)}${f}`;t.setProperty("translate","x"===o?`${i} 0px`:`0px ${i}`)},y=()=>{p=0,u.forEach(h)},x=()=>{p||(p=requestAnimationFrame(y))},E=e=>{if(e===m)return;m=e;const t=e?"addEventListener":"removeEventListener";g[t]("scroll",x,W),window[t]("resize",x,W),!e&&p&&(cancelAnimationFrame(p),p=0)},w=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting?u.add(e.target):u.delete(e.target),h(e.target)}),E(u.size>0)},{threshold:0,root:a});return r.forEach(e=>{h(e),w.observe(e)}),()=>{w.disconnect(),E(!1),u.clear(),r.forEach(e=>{const t=e.style;t&&(t.removeProperty("translate"),t.removeProperty(l))})}},e.resolveEasing=o,e.resolvePreset=r,e.sequence=function(e,t={}){V||"undefined"==typeof console||(V=!0,console.warn("[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md."));const{trigger:r,instance:n,...o}=t;let a,s,l=[],f=[];const d={play:()=>(d.cancel(),i()?(l=z(e,o),new Promise(e=>{let t=l.length;if(s=()=>{s=void 0,e()},!t)return s();const r=l;r.forEach(({el:e,opts:o})=>{const a=o.onComplete;(n||R||(R=Y())).animate(e,{...o,onComplete:e=>{a?.(e),r===l&&0===--t&&s?.()}})})})):Promise.resolve()),cancel(){a?.disconnect(),a=void 0,f.forEach(e=>X(e)),f=[],l.forEach(({el:e})=>X(e)),l=[],s?.()},duration:()=>z(e,o).reduce((e,t)=>Math.max(e,t.end),0)};if(r&&i()&&c()){const t=v(r)[0];t&&(f=z(e,o).map(({el:e})=>e),f.forEach(e=>L(e)),a=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(a?.disconnect(),a=void 0,f=[],d.play())},{threshold:o.threshold??.1,rootMargin:o.rootMargin??"0px"}),a.observe(t))}return d},e.staggerChildren=function(e,t={},r){if(!e||!i()||!c())return()=>{};const n=r||I||(I=Y()),{stagger:o=80,delay:a=0,threshold:s=.1,rootMargin:l="0px",observeChildren:f=!1,...d}=t;let u=Array.from(e.children),p=!1;const m=[];u.forEach(e=>L(e));const g=new IntersectionObserver(t=>{!p&&t.some(e=>e.isIntersecting)&&(p=!0,g.disconnect(),u.forEach((t,r)=>{t.parentNode===e&&n.animate(t,{...d,delay:a+r*o})}),u=[])},{threshold:s,rootMargin:l});let h;return g.observe(e),f&&"undefined"!=typeof MutationObserver&&(h=new MutationObserver(t=>{t.forEach(t=>{t.addedNodes.forEach(t=>{t instanceof Element&&t.parentNode===e&&(p?(m.push(t),n.observe(t,{...d,delay:a,stagger:o,threshold:s,rootMargin:l})):(L(t),u.push(t)))}),t.removedNodes.forEach(e=>{if(!(e instanceof Element))return;u=u.filter(t=>t!==e);const t=m.indexOf(e);t>=0&&(m.splice(t,1),n.unobserve(e))})})}),h.observe(e,{childList:!0})),()=>{g.disconnect(),h?.disconnect(),p||(p=!0,u.forEach(e=>X(e)),u=[]),m.forEach(e=>n.unobserve(e)),m.length=0}},e.supportsScrollTimeline=u,Object.defineProperty(e,"__esModule",{value:!0})});
15
15
  //# sourceMappingURL=index.umd.js.map