use-scroll-animate 1.5.0 → 2.0.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 (66) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +145 -10
  3. package/README_ja.md +57 -1
  4. package/README_zh.md +68 -1
  5. package/dist/{index.mjs → chunks/core-CH41ekIo.cjs} +307 -404
  6. package/dist/chunks/core-CH41ekIo.cjs.map +1 -0
  7. package/dist/{index.esm.js → chunks/core-FUEi4ncH.js} +292 -404
  8. package/dist/chunks/core-FUEi4ncH.js.map +1 -0
  9. package/dist/chunks/stagger-DabrnrcE.js +84 -0
  10. package/dist/chunks/stagger-DabrnrcE.js.map +1 -0
  11. package/dist/chunks/stagger-XD-0-FQz.cjs +86 -0
  12. package/dist/chunks/stagger-XD-0-FQz.cjs.map +1 -0
  13. package/dist/element.cjs +97 -0
  14. package/dist/element.cjs.map +1 -0
  15. package/dist/{types/types.d.ts → element.d.cts} +73 -10
  16. package/dist/element.d.ts +216 -0
  17. package/dist/element.js +95 -0
  18. package/dist/element.js.map +1 -0
  19. package/dist/element.umd.js +2 -0
  20. package/dist/element.umd.js.map +1 -0
  21. package/dist/index.cjs +241 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/{index.d.mts → index.d.cts} +84 -51
  24. package/dist/index.d.ts +84 -51
  25. package/dist/index.js +98 -1133
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.umd.js +5 -3
  28. package/dist/index.umd.js.map +1 -1
  29. package/dist/react.cjs +67 -0
  30. package/dist/react.cjs.map +1 -0
  31. package/dist/react.d.cts +159 -0
  32. package/dist/react.d.ts +159 -0
  33. package/dist/react.js +64 -0
  34. package/dist/react.js.map +1 -0
  35. package/dist/solid.cjs +62 -0
  36. package/dist/solid.cjs.map +1 -0
  37. package/dist/solid.d.cts +245 -0
  38. package/dist/solid.d.ts +245 -0
  39. package/dist/solid.js +58 -0
  40. package/dist/solid.js.map +1 -0
  41. package/dist/svelte.cjs +65 -0
  42. package/dist/svelte.cjs.map +1 -0
  43. package/dist/svelte.d.cts +244 -0
  44. package/dist/svelte.d.ts +244 -0
  45. package/dist/svelte.js +62 -0
  46. package/dist/svelte.js.map +1 -0
  47. package/dist/vue.cjs +61 -0
  48. package/dist/vue.cjs.map +1 -0
  49. package/dist/vue.d.cts +159 -0
  50. package/dist/vue.d.ts +159 -0
  51. package/dist/vue.js +59 -0
  52. package/dist/vue.js.map +1 -0
  53. package/docs/API.md +139 -0
  54. package/docs/deprecations.md +20 -0
  55. package/docs/migration-from-aos.md +67 -0
  56. package/docs/migration-from-gsap-scrolltrigger.md +80 -0
  57. package/package.json +86 -15
  58. package/dist/index.esm.js.map +0 -1
  59. package/dist/index.mjs.map +0 -1
  60. package/dist/types/core.d.ts +0 -41
  61. package/dist/types/index.d.ts +0 -36
  62. package/dist/types/presets.d.ts +0 -15
  63. package/dist/types/react.d.ts +0 -29
  64. package/dist/types/sequence.d.ts +0 -38
  65. package/dist/types/stagger.d.ts +0 -25
  66. package/dist/types/vue.d.ts +0 -28
@@ -11,6 +11,17 @@ type AnimationPreset = 'fade-in' | 'fade-in-up' | 'fade-in-down' | 'fade-in-left
11
11
  * viewport and 1 when its bottom leaves the top. Works for elements taller than the screen.
12
12
  */
13
13
  type ProgressMode = 'ratio' | 'scroll';
14
+ /**
15
+ * Which engine runs the entrance animation.
16
+ * - `'js'`: IntersectionObserver triggers a time-based Web Animation.
17
+ * - `'css'`: the preset runs on the browser's native scroll-driven timeline
18
+ * (`animation-timeline: view()`), so its progress follows the scroll position
19
+ * off the main thread. Falls back to `'js'` where unsupported.
20
+ * - `'auto'` (default since 2.0): native when supported, JS otherwise — and JS
21
+ * whenever the element sets `duration`, `delay`, `offset` or `stagger` itself,
22
+ * since those only mean something for a time-based animation.
23
+ */
24
+ type ScrollEngine = 'auto' | 'js' | 'css';
14
25
  /** Easing function types */
15
26
  type EasingType = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'soft-spring' | 'heavy-bounce' | [number, number, number, number] | ((t: number) => number) | string;
16
27
  /** Keyframe definition for custom animations */
@@ -77,6 +88,26 @@ interface AnimateOptions {
77
88
  * style, for scroll-driven effects written in plain CSS. Off by default.
78
89
  */
79
90
  progressVar?: string;
91
+ /**
92
+ * Animation engine (default: `'auto'`, see `ScrollEngine`). With the native
93
+ * engine the animation is linked to scroll position: `duration`, `delay`,
94
+ * `threshold`, `offset` and `stagger` do not apply; `viewRange` does.
95
+ */
96
+ engine?: ScrollEngine;
97
+ /**
98
+ * Native engine only: the view-timeline range the entrance animation spans,
99
+ * as `[rangeStart, rangeEnd]` (default: `['entry 0%', 'entry 100%']`).
100
+ */
101
+ viewRange?: [string, string];
102
+ /**
103
+ * Animate out when the element leaves the viewport, and back in when it
104
+ * re-enters (implies `repeat: true` unless `repeat` is set).
105
+ * - `true`: play the entrance animation in reverse.
106
+ * - a preset / presets / `{ from, to }`: play that animation in reverse
107
+ * (e.g. `exit: 'fade-in-down'` leaves upwards).
108
+ * Skipped under reduced motion. (default: `false`)
109
+ */
110
+ exit?: boolean | AnimationPreset | AnimationPreset[] | CustomAnimation;
80
111
  }
81
112
  /** Global configuration for ScrollAnimate instance */
82
113
  interface ScrollAnimateConfig {
@@ -115,6 +146,8 @@ interface ScrollAnimateConfig {
115
146
  * never re-hide or replay them. (default: true)
116
147
  */
117
148
  autoUnregister?: boolean;
149
+ /** Default animation engine (default: `'auto'`; `'js'` restores the 1.x behaviour) */
150
+ defaultEngine?: ScrollEngine;
118
151
  }
119
152
  /** Registered element entry */
120
153
  interface AnimatedElement {
@@ -123,6 +156,8 @@ interface AnimatedElement {
123
156
  observer: IntersectionObserver;
124
157
  animated: boolean;
125
158
  progressObserver?: IntersectionObserver;
159
+ /** Engine actually used for this element (`'css'` = native scroll-driven timeline) */
160
+ engine?: 'js' | 'css';
126
161
  }
127
162
  /** ScrollAnimate public API */
128
163
  interface ScrollAnimateInstance {
@@ -158,6 +193,12 @@ interface ScrollAnimateInstance {
158
193
  * high-performance scroll-triggered animations.
159
194
  */
160
195
 
196
+ /**
197
+ * Whether the browser can run presets on a native scroll-driven timeline:
198
+ * `CSS.supports('animation-timeline: view()')` plus the `ViewTimeline`
199
+ * constructor used to attach it from JavaScript. Cached. SSR-safe.
200
+ */
201
+ declare function supportsScrollTimeline(): boolean;
161
202
  /**
162
203
  * True scroll progress of `el` through the viewport (or `root`): 0 when its top
163
204
  * edge reaches the bottom of the viewport, 1 when its bottom edge passes the top.
@@ -231,6 +272,47 @@ interface SequenceController {
231
272
  */
232
273
  declare function sequence(steps: SequenceStep[], options?: SequenceOptions): SequenceController;
233
274
 
275
+ /**
276
+ * use-scroll-animate - parallax() helper
277
+ *
278
+ * Moves elements at a different speed than the page while they cross the
279
+ * viewport. Built on the same scroll progress as `progressVar` (0 when the
280
+ * element's top enters at the bottom, 1 when its bottom leaves at the top):
281
+ * the progress is written to a CSS custom property (default `--sa-parallax`)
282
+ * and the offset is applied with the individual `translate` property, so it
283
+ * composes with entrance animations and other `transform`s.
284
+ */
285
+ interface ParallaxHelperOptions {
286
+ /**
287
+ * Total distance the element shifts while it crosses the viewport, as a
288
+ * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values
289
+ * lag behind the scroll (background-like), negative values move ahead of it
290
+ * (foreground-like). (default: `0.2`)
291
+ */
292
+ speed?: number;
293
+ /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */
294
+ axis?: 'x' | 'y';
295
+ /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */
296
+ progressVar?: string;
297
+ /** Scroll container (default: the viewport) */
298
+ root?: Element | null;
299
+ /**
300
+ * Under `prefers-reduced-motion: reduce` no offset is applied (the progress
301
+ * variable is still written). Set to `false` to move anyway. (default: `true`)
302
+ */
303
+ respectReducedMotion?: boolean;
304
+ }
305
+ /**
306
+ * Apply a scroll parallax to `target` (selector, Element, NodeList or array).
307
+ * Returns a function that stops it and removes the inline styles it set.
308
+ * SSR-safe (no-op without a DOM / IntersectionObserver).
309
+ *
310
+ * @example
311
+ * const stop = parallax('.hero-bg', { speed: 0.3 });
312
+ * parallax('.badge', { speed: -0.15, axis: 'x' });
313
+ */
314
+ declare function parallax(target: string | Element | NodeList | Element[], options?: ParallaxHelperOptions): () => void;
315
+
234
316
  /**
235
317
  * use-scroll-animate - Animation Presets
236
318
  * Defines keyframes for all built-in animation presets
@@ -246,55 +328,6 @@ declare function resolvePreset(animation: AnimationPreset | AnimationPreset[] |
246
328
  declare const EASING_MAP: Record<string, string>;
247
329
  declare function resolveEasing(easing: EasingType): string;
248
330
 
249
- /**
250
- * use-scroll-animate - React Integration
251
- * Provides useScrollAnimate and useScrollStagger hooks for React applications.
252
- * `useScrollStagger({ observeChildren: true })` also animates children added later.
253
- *
254
- * Both hooks are thin wrappers around the core engine, so they share its
255
- * behaviour: `once`, `offset`, custom easing functions, parallax,
256
- * `prefers-reduced-motion` support, and proper cleanup on unmount.
257
- */
258
-
259
- type ReactRef<T> = {
260
- current: T | null;
261
- };
262
- declare function createReactHooks(React: {
263
- useRef: <T>(initial: T | null) => ReactRef<T>;
264
- useEffect: (effect: () => (() => void) | void, deps?: unknown[]) => void;
265
- }): {
266
- useScrollAnimate: (options?: AnimateOptions) => ReactRef<Element>;
267
- useScrollStagger: (options?: StaggerOptions) => ReactRef<Element>;
268
- };
269
-
270
- /**
271
- * use-scroll-animate - Vue 3 Integration
272
- * Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
273
- *
274
- * A thin wrapper around the core engine, so it shares its behaviour: `once`,
275
- * `offset`, custom easing functions, parallax, `prefers-reduced-motion`
276
- * support, and cleanup on unmount.
277
- */
278
-
279
- declare function createVueComposables(Vue: {
280
- ref: <T>(value: T | null) => {
281
- value: T | null;
282
- };
283
- onMounted: (fn: () => void) => void;
284
- onUnmounted: (fn: () => void) => void;
285
- }): {
286
- useScrollAnimate: (options?: AnimateOptions) => {
287
- animateRef: {
288
- value: Element | null;
289
- };
290
- };
291
- useScrollStagger: (options?: StaggerOptions) => {
292
- staggerRef: {
293
- value: Element | null;
294
- };
295
- };
296
- };
297
-
298
331
  /**
299
332
  * Default singleton instance of ScrollAnimate.
300
333
  * Ready to use out of the box with sensible defaults.
@@ -312,5 +345,5 @@ declare function createVueComposables(Vue: {
312
345
  */
313
346
  declare const ScrollAnimate: ScrollAnimateInstance;
314
347
 
315
- export { EASING_MAP, PRESETS, createReactHooks, createScrollAnimate, createVueComposables, ScrollAnimate as default, getScrollProgress, resolveEasing, resolvePreset, sequence, staggerChildren };
316
- export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };
348
+ export { EASING_MAP, PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing, resolvePreset, sequence, staggerChildren, supportsScrollTimeline };
349
+ export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };
package/dist/index.d.ts CHANGED
@@ -11,6 +11,17 @@ type AnimationPreset = 'fade-in' | 'fade-in-up' | 'fade-in-down' | 'fade-in-left
11
11
  * viewport and 1 when its bottom leaves the top. Works for elements taller than the screen.
12
12
  */
13
13
  type ProgressMode = 'ratio' | 'scroll';
14
+ /**
15
+ * Which engine runs the entrance animation.
16
+ * - `'js'`: IntersectionObserver triggers a time-based Web Animation.
17
+ * - `'css'`: the preset runs on the browser's native scroll-driven timeline
18
+ * (`animation-timeline: view()`), so its progress follows the scroll position
19
+ * off the main thread. Falls back to `'js'` where unsupported.
20
+ * - `'auto'` (default since 2.0): native when supported, JS otherwise — and JS
21
+ * whenever the element sets `duration`, `delay`, `offset` or `stagger` itself,
22
+ * since those only mean something for a time-based animation.
23
+ */
24
+ type ScrollEngine = 'auto' | 'js' | 'css';
14
25
  /** Easing function types */
15
26
  type EasingType = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'soft-spring' | 'heavy-bounce' | [number, number, number, number] | ((t: number) => number) | string;
16
27
  /** Keyframe definition for custom animations */
@@ -77,6 +88,26 @@ interface AnimateOptions {
77
88
  * style, for scroll-driven effects written in plain CSS. Off by default.
78
89
  */
79
90
  progressVar?: string;
91
+ /**
92
+ * Animation engine (default: `'auto'`, see `ScrollEngine`). With the native
93
+ * engine the animation is linked to scroll position: `duration`, `delay`,
94
+ * `threshold`, `offset` and `stagger` do not apply; `viewRange` does.
95
+ */
96
+ engine?: ScrollEngine;
97
+ /**
98
+ * Native engine only: the view-timeline range the entrance animation spans,
99
+ * as `[rangeStart, rangeEnd]` (default: `['entry 0%', 'entry 100%']`).
100
+ */
101
+ viewRange?: [string, string];
102
+ /**
103
+ * Animate out when the element leaves the viewport, and back in when it
104
+ * re-enters (implies `repeat: true` unless `repeat` is set).
105
+ * - `true`: play the entrance animation in reverse.
106
+ * - a preset / presets / `{ from, to }`: play that animation in reverse
107
+ * (e.g. `exit: 'fade-in-down'` leaves upwards).
108
+ * Skipped under reduced motion. (default: `false`)
109
+ */
110
+ exit?: boolean | AnimationPreset | AnimationPreset[] | CustomAnimation;
80
111
  }
81
112
  /** Global configuration for ScrollAnimate instance */
82
113
  interface ScrollAnimateConfig {
@@ -115,6 +146,8 @@ interface ScrollAnimateConfig {
115
146
  * never re-hide or replay them. (default: true)
116
147
  */
117
148
  autoUnregister?: boolean;
149
+ /** Default animation engine (default: `'auto'`; `'js'` restores the 1.x behaviour) */
150
+ defaultEngine?: ScrollEngine;
118
151
  }
119
152
  /** Registered element entry */
120
153
  interface AnimatedElement {
@@ -123,6 +156,8 @@ interface AnimatedElement {
123
156
  observer: IntersectionObserver;
124
157
  animated: boolean;
125
158
  progressObserver?: IntersectionObserver;
159
+ /** Engine actually used for this element (`'css'` = native scroll-driven timeline) */
160
+ engine?: 'js' | 'css';
126
161
  }
127
162
  /** ScrollAnimate public API */
128
163
  interface ScrollAnimateInstance {
@@ -158,6 +193,12 @@ interface ScrollAnimateInstance {
158
193
  * high-performance scroll-triggered animations.
159
194
  */
160
195
 
196
+ /**
197
+ * Whether the browser can run presets on a native scroll-driven timeline:
198
+ * `CSS.supports('animation-timeline: view()')` plus the `ViewTimeline`
199
+ * constructor used to attach it from JavaScript. Cached. SSR-safe.
200
+ */
201
+ declare function supportsScrollTimeline(): boolean;
161
202
  /**
162
203
  * True scroll progress of `el` through the viewport (or `root`): 0 when its top
163
204
  * edge reaches the bottom of the viewport, 1 when its bottom edge passes the top.
@@ -231,6 +272,47 @@ interface SequenceController {
231
272
  */
232
273
  declare function sequence(steps: SequenceStep[], options?: SequenceOptions): SequenceController;
233
274
 
275
+ /**
276
+ * use-scroll-animate - parallax() helper
277
+ *
278
+ * Moves elements at a different speed than the page while they cross the
279
+ * viewport. Built on the same scroll progress as `progressVar` (0 when the
280
+ * element's top enters at the bottom, 1 when its bottom leaves at the top):
281
+ * the progress is written to a CSS custom property (default `--sa-parallax`)
282
+ * and the offset is applied with the individual `translate` property, so it
283
+ * composes with entrance animations and other `transform`s.
284
+ */
285
+ interface ParallaxHelperOptions {
286
+ /**
287
+ * Total distance the element shifts while it crosses the viewport, as a
288
+ * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values
289
+ * lag behind the scroll (background-like), negative values move ahead of it
290
+ * (foreground-like). (default: `0.2`)
291
+ */
292
+ speed?: number;
293
+ /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */
294
+ axis?: 'x' | 'y';
295
+ /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */
296
+ progressVar?: string;
297
+ /** Scroll container (default: the viewport) */
298
+ root?: Element | null;
299
+ /**
300
+ * Under `prefers-reduced-motion: reduce` no offset is applied (the progress
301
+ * variable is still written). Set to `false` to move anyway. (default: `true`)
302
+ */
303
+ respectReducedMotion?: boolean;
304
+ }
305
+ /**
306
+ * Apply a scroll parallax to `target` (selector, Element, NodeList or array).
307
+ * Returns a function that stops it and removes the inline styles it set.
308
+ * SSR-safe (no-op without a DOM / IntersectionObserver).
309
+ *
310
+ * @example
311
+ * const stop = parallax('.hero-bg', { speed: 0.3 });
312
+ * parallax('.badge', { speed: -0.15, axis: 'x' });
313
+ */
314
+ declare function parallax(target: string | Element | NodeList | Element[], options?: ParallaxHelperOptions): () => void;
315
+
234
316
  /**
235
317
  * use-scroll-animate - Animation Presets
236
318
  * Defines keyframes for all built-in animation presets
@@ -246,55 +328,6 @@ declare function resolvePreset(animation: AnimationPreset | AnimationPreset[] |
246
328
  declare const EASING_MAP: Record<string, string>;
247
329
  declare function resolveEasing(easing: EasingType): string;
248
330
 
249
- /**
250
- * use-scroll-animate - React Integration
251
- * Provides useScrollAnimate and useScrollStagger hooks for React applications.
252
- * `useScrollStagger({ observeChildren: true })` also animates children added later.
253
- *
254
- * Both hooks are thin wrappers around the core engine, so they share its
255
- * behaviour: `once`, `offset`, custom easing functions, parallax,
256
- * `prefers-reduced-motion` support, and proper cleanup on unmount.
257
- */
258
-
259
- type ReactRef<T> = {
260
- current: T | null;
261
- };
262
- declare function createReactHooks(React: {
263
- useRef: <T>(initial: T | null) => ReactRef<T>;
264
- useEffect: (effect: () => (() => void) | void, deps?: unknown[]) => void;
265
- }): {
266
- useScrollAnimate: (options?: AnimateOptions) => ReactRef<Element>;
267
- useScrollStagger: (options?: StaggerOptions) => ReactRef<Element>;
268
- };
269
-
270
- /**
271
- * use-scroll-animate - Vue 3 Integration
272
- * Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
273
- *
274
- * A thin wrapper around the core engine, so it shares its behaviour: `once`,
275
- * `offset`, custom easing functions, parallax, `prefers-reduced-motion`
276
- * support, and cleanup on unmount.
277
- */
278
-
279
- declare function createVueComposables(Vue: {
280
- ref: <T>(value: T | null) => {
281
- value: T | null;
282
- };
283
- onMounted: (fn: () => void) => void;
284
- onUnmounted: (fn: () => void) => void;
285
- }): {
286
- useScrollAnimate: (options?: AnimateOptions) => {
287
- animateRef: {
288
- value: Element | null;
289
- };
290
- };
291
- useScrollStagger: (options?: StaggerOptions) => {
292
- staggerRef: {
293
- value: Element | null;
294
- };
295
- };
296
- };
297
-
298
331
  /**
299
332
  * Default singleton instance of ScrollAnimate.
300
333
  * Ready to use out of the box with sensible defaults.
@@ -312,5 +345,5 @@ declare function createVueComposables(Vue: {
312
345
  */
313
346
  declare const ScrollAnimate: ScrollAnimateInstance;
314
347
 
315
- export { EASING_MAP, PRESETS, createReactHooks, createScrollAnimate, createVueComposables, ScrollAnimate as default, getScrollProgress, resolveEasing, resolvePreset, sequence, staggerChildren };
316
- export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };
348
+ export { EASING_MAP, PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing, resolvePreset, sequence, staggerChildren, supportsScrollTimeline };
349
+ export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };