use-scroll-animate 1.4.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.
- package/CHANGELOG.md +68 -0
- package/README.md +184 -10
- package/README_ja.md +57 -1
- package/README_zh.md +68 -1
- package/dist/{index.mjs → chunks/core-CH41ekIo.cjs} +366 -393
- package/dist/chunks/core-CH41ekIo.cjs.map +1 -0
- package/dist/{index.esm.js → chunks/core-FUEi4ncH.js} +351 -393
- package/dist/chunks/core-FUEi4ncH.js.map +1 -0
- package/dist/chunks/stagger-DabrnrcE.js +84 -0
- package/dist/chunks/stagger-DabrnrcE.js.map +1 -0
- package/dist/chunks/stagger-XD-0-FQz.cjs +86 -0
- package/dist/chunks/stagger-XD-0-FQz.cjs.map +1 -0
- package/dist/element.cjs +97 -0
- package/dist/element.cjs.map +1 -0
- package/dist/{types/types.d.ts → element.d.cts} +87 -10
- package/dist/element.d.ts +216 -0
- package/dist/element.js +95 -0
- package/dist/element.js.map +1 -0
- package/dist/element.umd.js +2 -0
- package/dist/element.umd.js.map +1 -0
- package/dist/index.cjs +241 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +98 -51
- package/dist/index.d.ts +98 -51
- package/dist/index.js +105 -1070
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +5 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/react.cjs +67 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +159 -0
- package/dist/react.d.ts +159 -0
- package/dist/react.js +64 -0
- package/dist/react.js.map +1 -0
- package/dist/solid.cjs +62 -0
- package/dist/solid.cjs.map +1 -0
- package/dist/solid.d.cts +245 -0
- package/dist/solid.d.ts +245 -0
- package/dist/solid.js +58 -0
- package/dist/solid.js.map +1 -0
- package/dist/svelte.cjs +65 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +244 -0
- package/dist/svelte.d.ts +244 -0
- package/dist/svelte.js +62 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vue.cjs +61 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +159 -0
- package/dist/vue.d.ts +159 -0
- package/dist/vue.js +59 -0
- package/dist/vue.js.map +1 -0
- package/docs/API.md +139 -0
- package/docs/deprecations.md +20 -0
- package/docs/migration-from-aos.md +67 -0
- package/docs/migration-from-gsap-scrolltrigger.md +80 -0
- package/package.json +86 -15
- package/dist/index.esm.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/types/core.d.ts +0 -41
- package/dist/types/index.d.ts +0 -36
- package/dist/types/presets.d.ts +0 -15
- package/dist/types/react.d.ts +0 -29
- package/dist/types/sequence.d.ts +0 -38
- package/dist/types/stagger.d.ts +0 -25
- package/dist/types/vue.d.ts +0 -28
package/dist/vue.d.cts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* use-scroll-animate - Core Type Definitions
|
|
3
|
+
* A lightweight, high-performance scroll animation library
|
|
4
|
+
*/
|
|
5
|
+
/** Built-in animation presets */
|
|
6
|
+
type AnimationPreset = 'fade-in' | 'fade-in-up' | 'fade-in-down' | 'fade-in-left' | 'fade-in-right' | 'zoom-in' | 'zoom-out' | 'flip-x' | 'flip-y' | 'slide-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'bounce' | 'rotate-in' | 'blur-in' | 'skew-in' | 'scale-x' | 'scale-y' | 'shimmer' | 'pulse' | 'swing' | 'scale-up' | 'blur-in-up' | 'flip-up' | 'flip-down' | 'rotate-left' | 'rotate-right' | 'clip-up' | 'clip-down' | 'clip-left' | 'clip-right' | 'clip-circle';
|
|
7
|
+
/**
|
|
8
|
+
* How `onProgress` (and parallax) progress is measured.
|
|
9
|
+
* - `'ratio'` (default): the element's visible ratio (IntersectionObserver `intersectionRatio`).
|
|
10
|
+
* - `'scroll'`: true scroll progress, 0 when the element's top touches the bottom of the
|
|
11
|
+
* viewport and 1 when its bottom leaves the top. Works for elements taller than the screen.
|
|
12
|
+
*/
|
|
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';
|
|
25
|
+
/** Easing function types */
|
|
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;
|
|
27
|
+
/** Keyframe definition for custom animations */
|
|
28
|
+
interface AnimationKeyframe {
|
|
29
|
+
[property: string]: string | number;
|
|
30
|
+
}
|
|
31
|
+
/** Custom animation definition */
|
|
32
|
+
interface CustomAnimation {
|
|
33
|
+
from: AnimationKeyframe;
|
|
34
|
+
to: AnimationKeyframe;
|
|
35
|
+
}
|
|
36
|
+
/** Parallax configuration */
|
|
37
|
+
interface ParallaxOptions {
|
|
38
|
+
/** Movement on X axis (e.g., '100px', '20%') */
|
|
39
|
+
x?: string | number;
|
|
40
|
+
/** Movement on Y axis (e.g., '100px', '20%') */
|
|
41
|
+
y?: string | number;
|
|
42
|
+
/** Rotation in degrees */
|
|
43
|
+
rotate?: number;
|
|
44
|
+
/** Scale factor */
|
|
45
|
+
scale?: number;
|
|
46
|
+
/** Speed multiplier (default: 1) */
|
|
47
|
+
speed?: number;
|
|
48
|
+
}
|
|
49
|
+
/** Per-element animation options */
|
|
50
|
+
interface AnimateOptions {
|
|
51
|
+
/** Animation preset name, array of presets, or custom animation object */
|
|
52
|
+
animation?: AnimationPreset | AnimationPreset[] | CustomAnimation;
|
|
53
|
+
/** Duration in milliseconds (default: 600) */
|
|
54
|
+
duration?: number;
|
|
55
|
+
/** Delay in milliseconds (default: 0) */
|
|
56
|
+
delay?: number;
|
|
57
|
+
/** Easing function (default: 'ease') */
|
|
58
|
+
easing?: EasingType;
|
|
59
|
+
/** Intersection threshold 0-1 (default: 0.1) */
|
|
60
|
+
threshold?: number | number[];
|
|
61
|
+
/** Root margin for IntersectionObserver (default: '0px') */
|
|
62
|
+
rootMargin?: string;
|
|
63
|
+
/** Whether to replay animation each time element enters viewport (default: false) */
|
|
64
|
+
repeat?: boolean;
|
|
65
|
+
/** Whether to trigger animation only once (default: true if repeat is false) */
|
|
66
|
+
once?: boolean;
|
|
67
|
+
/** Offset in pixels from the viewport edge to trigger animation (default: 0) */
|
|
68
|
+
offset?: number;
|
|
69
|
+
/** Stagger delay for child elements in ms (default: 0) */
|
|
70
|
+
stagger?: number;
|
|
71
|
+
/** Parallax effect configuration */
|
|
72
|
+
parallax?: ParallaxOptions;
|
|
73
|
+
/** Callback fired when animation starts */
|
|
74
|
+
onStart?: (element: Element) => void;
|
|
75
|
+
/** Callback fired when animation completes */
|
|
76
|
+
onComplete?: (element: Element) => void;
|
|
77
|
+
/** Callback fired when element enters viewport */
|
|
78
|
+
onEnter?: (element: Element) => void;
|
|
79
|
+
/** Callback fired when element leaves viewport */
|
|
80
|
+
onLeave?: (element: Element) => void;
|
|
81
|
+
/** Callback fired with scroll progress (0 to 1) */
|
|
82
|
+
onProgress?: (element: Element, progress: number) => void;
|
|
83
|
+
/** How progress for `onProgress`/parallax is measured (default: 'ratio') */
|
|
84
|
+
progressMode?: ProgressMode;
|
|
85
|
+
/**
|
|
86
|
+
* Name of a CSS custom property (e.g. `'--sa-progress'`) that receives the
|
|
87
|
+
* element's progress (0 to 1, same value as `onProgress`) as an inline
|
|
88
|
+
* style, for scroll-driven effects written in plain CSS. Off by default.
|
|
89
|
+
*/
|
|
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;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* use-scroll-animate - Staggered children
|
|
115
|
+
* Reveal a container's children one after another when the container scrolls
|
|
116
|
+
* into view, optionally also animating children that are added later.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
interface StaggerOptions extends AnimateOptions {
|
|
120
|
+
/** Delay between consecutive children in ms (default: 80) */
|
|
121
|
+
stagger?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Watch the container with a MutationObserver and animate children added
|
|
124
|
+
* later (e.g. infinite lists). Children added after the container was
|
|
125
|
+
* revealed animate when they scroll into view, staggered per batch.
|
|
126
|
+
* (default: false)
|
|
127
|
+
*/
|
|
128
|
+
observeChildren?: boolean;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* use-scroll-animate - Vue 3 Integration
|
|
133
|
+
* Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
|
|
134
|
+
*
|
|
135
|
+
* A thin wrapper around the core engine, so it shares its behaviour: `once`,
|
|
136
|
+
* `offset`, custom easing functions, parallax, `prefers-reduced-motion`
|
|
137
|
+
* support, and cleanup on unmount.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
declare function createVueComposables(Vue: {
|
|
141
|
+
ref: <T>(value: T | null) => {
|
|
142
|
+
value: T | null;
|
|
143
|
+
};
|
|
144
|
+
onMounted: (fn: () => void) => void;
|
|
145
|
+
onUnmounted: (fn: () => void) => void;
|
|
146
|
+
}): {
|
|
147
|
+
useScrollAnimate: (options?: AnimateOptions) => {
|
|
148
|
+
animateRef: {
|
|
149
|
+
value: Element | null;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
useScrollStagger: (options?: StaggerOptions) => {
|
|
153
|
+
staggerRef: {
|
|
154
|
+
value: Element | null;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export { createVueComposables };
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* use-scroll-animate - Core Type Definitions
|
|
3
|
+
* A lightweight, high-performance scroll animation library
|
|
4
|
+
*/
|
|
5
|
+
/** Built-in animation presets */
|
|
6
|
+
type AnimationPreset = 'fade-in' | 'fade-in-up' | 'fade-in-down' | 'fade-in-left' | 'fade-in-right' | 'zoom-in' | 'zoom-out' | 'flip-x' | 'flip-y' | 'slide-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'bounce' | 'rotate-in' | 'blur-in' | 'skew-in' | 'scale-x' | 'scale-y' | 'shimmer' | 'pulse' | 'swing' | 'scale-up' | 'blur-in-up' | 'flip-up' | 'flip-down' | 'rotate-left' | 'rotate-right' | 'clip-up' | 'clip-down' | 'clip-left' | 'clip-right' | 'clip-circle';
|
|
7
|
+
/**
|
|
8
|
+
* How `onProgress` (and parallax) progress is measured.
|
|
9
|
+
* - `'ratio'` (default): the element's visible ratio (IntersectionObserver `intersectionRatio`).
|
|
10
|
+
* - `'scroll'`: true scroll progress, 0 when the element's top touches the bottom of the
|
|
11
|
+
* viewport and 1 when its bottom leaves the top. Works for elements taller than the screen.
|
|
12
|
+
*/
|
|
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';
|
|
25
|
+
/** Easing function types */
|
|
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;
|
|
27
|
+
/** Keyframe definition for custom animations */
|
|
28
|
+
interface AnimationKeyframe {
|
|
29
|
+
[property: string]: string | number;
|
|
30
|
+
}
|
|
31
|
+
/** Custom animation definition */
|
|
32
|
+
interface CustomAnimation {
|
|
33
|
+
from: AnimationKeyframe;
|
|
34
|
+
to: AnimationKeyframe;
|
|
35
|
+
}
|
|
36
|
+
/** Parallax configuration */
|
|
37
|
+
interface ParallaxOptions {
|
|
38
|
+
/** Movement on X axis (e.g., '100px', '20%') */
|
|
39
|
+
x?: string | number;
|
|
40
|
+
/** Movement on Y axis (e.g., '100px', '20%') */
|
|
41
|
+
y?: string | number;
|
|
42
|
+
/** Rotation in degrees */
|
|
43
|
+
rotate?: number;
|
|
44
|
+
/** Scale factor */
|
|
45
|
+
scale?: number;
|
|
46
|
+
/** Speed multiplier (default: 1) */
|
|
47
|
+
speed?: number;
|
|
48
|
+
}
|
|
49
|
+
/** Per-element animation options */
|
|
50
|
+
interface AnimateOptions {
|
|
51
|
+
/** Animation preset name, array of presets, or custom animation object */
|
|
52
|
+
animation?: AnimationPreset | AnimationPreset[] | CustomAnimation;
|
|
53
|
+
/** Duration in milliseconds (default: 600) */
|
|
54
|
+
duration?: number;
|
|
55
|
+
/** Delay in milliseconds (default: 0) */
|
|
56
|
+
delay?: number;
|
|
57
|
+
/** Easing function (default: 'ease') */
|
|
58
|
+
easing?: EasingType;
|
|
59
|
+
/** Intersection threshold 0-1 (default: 0.1) */
|
|
60
|
+
threshold?: number | number[];
|
|
61
|
+
/** Root margin for IntersectionObserver (default: '0px') */
|
|
62
|
+
rootMargin?: string;
|
|
63
|
+
/** Whether to replay animation each time element enters viewport (default: false) */
|
|
64
|
+
repeat?: boolean;
|
|
65
|
+
/** Whether to trigger animation only once (default: true if repeat is false) */
|
|
66
|
+
once?: boolean;
|
|
67
|
+
/** Offset in pixels from the viewport edge to trigger animation (default: 0) */
|
|
68
|
+
offset?: number;
|
|
69
|
+
/** Stagger delay for child elements in ms (default: 0) */
|
|
70
|
+
stagger?: number;
|
|
71
|
+
/** Parallax effect configuration */
|
|
72
|
+
parallax?: ParallaxOptions;
|
|
73
|
+
/** Callback fired when animation starts */
|
|
74
|
+
onStart?: (element: Element) => void;
|
|
75
|
+
/** Callback fired when animation completes */
|
|
76
|
+
onComplete?: (element: Element) => void;
|
|
77
|
+
/** Callback fired when element enters viewport */
|
|
78
|
+
onEnter?: (element: Element) => void;
|
|
79
|
+
/** Callback fired when element leaves viewport */
|
|
80
|
+
onLeave?: (element: Element) => void;
|
|
81
|
+
/** Callback fired with scroll progress (0 to 1) */
|
|
82
|
+
onProgress?: (element: Element, progress: number) => void;
|
|
83
|
+
/** How progress for `onProgress`/parallax is measured (default: 'ratio') */
|
|
84
|
+
progressMode?: ProgressMode;
|
|
85
|
+
/**
|
|
86
|
+
* Name of a CSS custom property (e.g. `'--sa-progress'`) that receives the
|
|
87
|
+
* element's progress (0 to 1, same value as `onProgress`) as an inline
|
|
88
|
+
* style, for scroll-driven effects written in plain CSS. Off by default.
|
|
89
|
+
*/
|
|
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;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* use-scroll-animate - Staggered children
|
|
115
|
+
* Reveal a container's children one after another when the container scrolls
|
|
116
|
+
* into view, optionally also animating children that are added later.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
interface StaggerOptions extends AnimateOptions {
|
|
120
|
+
/** Delay between consecutive children in ms (default: 80) */
|
|
121
|
+
stagger?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Watch the container with a MutationObserver and animate children added
|
|
124
|
+
* later (e.g. infinite lists). Children added after the container was
|
|
125
|
+
* revealed animate when they scroll into view, staggered per batch.
|
|
126
|
+
* (default: false)
|
|
127
|
+
*/
|
|
128
|
+
observeChildren?: boolean;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* use-scroll-animate - Vue 3 Integration
|
|
133
|
+
* Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
|
|
134
|
+
*
|
|
135
|
+
* A thin wrapper around the core engine, so it shares its behaviour: `once`,
|
|
136
|
+
* `offset`, custom easing functions, parallax, `prefers-reduced-motion`
|
|
137
|
+
* support, and cleanup on unmount.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
declare function createVueComposables(Vue: {
|
|
141
|
+
ref: <T>(value: T | null) => {
|
|
142
|
+
value: T | null;
|
|
143
|
+
};
|
|
144
|
+
onMounted: (fn: () => void) => void;
|
|
145
|
+
onUnmounted: (fn: () => void) => void;
|
|
146
|
+
}): {
|
|
147
|
+
useScrollAnimate: (options?: AnimateOptions) => {
|
|
148
|
+
animateRef: {
|
|
149
|
+
value: Element | null;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
useScrollStagger: (options?: StaggerOptions) => {
|
|
153
|
+
staggerRef: {
|
|
154
|
+
value: Element | null;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export { createVueComposables };
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { c as createScrollAnimate } from './chunks/core-FUEi4ncH.js';
|
|
2
|
+
import { s as staggerChildren } from './chunks/stagger-DabrnrcE.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* use-scroll-animate - Vue 3 Integration
|
|
6
|
+
* Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
|
|
7
|
+
*
|
|
8
|
+
* A thin wrapper around the core engine, so it shares its behaviour: `once`,
|
|
9
|
+
* `offset`, custom easing functions, parallax, `prefers-reduced-motion`
|
|
10
|
+
* support, and cleanup on unmount.
|
|
11
|
+
*/
|
|
12
|
+
/** Support refs on components (`$el`) as well as plain elements. */
|
|
13
|
+
function unwrap(value) {
|
|
14
|
+
if (value && typeof Element !== 'undefined' && !(value instanceof Element) && value.$el instanceof Element) {
|
|
15
|
+
return value.$el;
|
|
16
|
+
}
|
|
17
|
+
return value || null;
|
|
18
|
+
}
|
|
19
|
+
function createVueComposables(Vue) {
|
|
20
|
+
// Created lazily on the client so importing on the server is side-effect free.
|
|
21
|
+
let instance = null;
|
|
22
|
+
const getInstance = () => instance || (instance = createScrollAnimate());
|
|
23
|
+
function useScrollAnimate(options = {}) {
|
|
24
|
+
const animateRef = Vue.ref(null);
|
|
25
|
+
let el = null;
|
|
26
|
+
Vue.onMounted(() => {
|
|
27
|
+
const target = unwrap(animateRef.value);
|
|
28
|
+
if (!target)
|
|
29
|
+
return;
|
|
30
|
+
el = target;
|
|
31
|
+
getInstance().observe(el, options);
|
|
32
|
+
});
|
|
33
|
+
Vue.onUnmounted(() => {
|
|
34
|
+
if (el)
|
|
35
|
+
getInstance().unobserve(el);
|
|
36
|
+
el = null;
|
|
37
|
+
});
|
|
38
|
+
return { animateRef };
|
|
39
|
+
}
|
|
40
|
+
/** Stagger the children of `staggerRef`; `observeChildren: true` also animates children added later. */
|
|
41
|
+
function useScrollStagger(options = {}) {
|
|
42
|
+
const staggerRef = Vue.ref(null);
|
|
43
|
+
let stop;
|
|
44
|
+
Vue.onMounted(() => {
|
|
45
|
+
const target = unwrap(staggerRef.value);
|
|
46
|
+
if (target)
|
|
47
|
+
stop = staggerChildren(target, options, getInstance());
|
|
48
|
+
});
|
|
49
|
+
Vue.onUnmounted(() => {
|
|
50
|
+
stop?.();
|
|
51
|
+
stop = undefined;
|
|
52
|
+
});
|
|
53
|
+
return { staggerRef };
|
|
54
|
+
}
|
|
55
|
+
return { useScrollAnimate, useScrollStagger };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { createVueComposables };
|
|
59
|
+
//# sourceMappingURL=vue.js.map
|
package/dist/vue.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.js","sources":["../src/vue.ts"],"sourcesContent":["/**\n * use-scroll-animate - Vue 3 Integration\n * Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.\n *\n * A thin wrapper around the core engine, so it shares its behaviour: `once`,\n * `offset`, custom easing functions, parallax, `prefers-reduced-motion`\n * support, and cleanup on unmount.\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate } from './core';\nimport { staggerChildren, type StaggerOptions } from './stagger';\n\n/** Support refs on components (`$el`) as well as plain elements. */\nfunction unwrap(value: unknown): Element | null {\n if (value && typeof Element !== 'undefined' && !(value instanceof Element) && (value as any).$el instanceof Element) {\n return (value as any).$el as Element;\n }\n return (value as Element | null) || null;\n}\n\nexport function createVueComposables(Vue: {\n ref: <T>(value: T | null) => { value: T | null };\n onMounted: (fn: () => void) => void;\n onUnmounted: (fn: () => void) => void;\n}) {\n // Created lazily on the client so importing on the server is side-effect free.\n let instance: ScrollAnimateInstance | null = null;\n const getInstance = () => instance || (instance = createScrollAnimate());\n\n function useScrollAnimate(options: AnimateOptions = {}) {\n const animateRef = Vue.ref<Element>(null);\n let el: Element | null = null;\n\n Vue.onMounted(() => {\n const target = unwrap(animateRef.value);\n if (!target) return;\n el = target;\n getInstance().observe(el, options);\n });\n\n Vue.onUnmounted(() => {\n if (el) getInstance().unobserve(el);\n el = null;\n });\n\n return { animateRef };\n }\n\n /** Stagger the children of `staggerRef`; `observeChildren: true` also animates children added later. */\n function useScrollStagger(options: StaggerOptions = {}) {\n const staggerRef = Vue.ref<Element>(null);\n let stop: (() => void) | undefined;\n\n Vue.onMounted(() => {\n const target = unwrap(staggerRef.value);\n if (target) stop = staggerChildren(target, options, getInstance());\n });\n\n Vue.onUnmounted(() => {\n stop?.();\n stop = undefined;\n });\n\n return { staggerRef };\n }\n\n return { useScrollAnimate, useScrollStagger };\n}\n"],"names":[],"mappings":";;;AAAA;;;;;;;AAOG;AAMH;AACA,SAAS,MAAM,CAAC,KAAc,EAAA;IAC5B,IAAI,KAAK,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,EAAE,KAAK,YAAY,OAAO,CAAC,IAAK,KAAa,CAAC,GAAG,YAAY,OAAO,EAAE;QACnH,OAAQ,KAAa,CAAC,GAAc;IACtC;IACA,OAAQ,KAAwB,IAAI,IAAI;AAC1C;AAEM,SAAU,oBAAoB,CAAC,GAIpC,EAAA;;IAEC,IAAI,QAAQ,GAAiC,IAAI;AACjD,IAAA,MAAM,WAAW,GAAG,MAAM,QAAQ,KAAK,QAAQ,GAAG,mBAAmB,EAAE,CAAC;IAExE,SAAS,gBAAgB,CAAC,OAAA,GAA0B,EAAE,EAAA;QACpD,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAU,IAAI,CAAC;QACzC,IAAI,EAAE,GAAmB,IAAI;AAE7B,QAAA,GAAG,CAAC,SAAS,CAAC,MAAK;YACjB,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;AACvC,YAAA,IAAI,CAAC,MAAM;gBAAE;YACb,EAAE,GAAG,MAAM;YACX,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC;AACpC,QAAA,CAAC,CAAC;AAEF,QAAA,GAAG,CAAC,WAAW,CAAC,MAAK;AACnB,YAAA,IAAI,EAAE;AAAE,gBAAA,WAAW,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;YACnC,EAAE,GAAG,IAAI;AACX,QAAA,CAAC,CAAC;QAEF,OAAO,EAAE,UAAU,EAAE;IACvB;;IAGA,SAAS,gBAAgB,CAAC,OAAA,GAA0B,EAAE,EAAA;QACpD,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAU,IAAI,CAAC;AACzC,QAAA,IAAI,IAA8B;AAElC,QAAA,GAAG,CAAC,SAAS,CAAC,MAAK;YACjB,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;AACvC,YAAA,IAAI,MAAM;gBAAE,IAAI,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AACpE,QAAA,CAAC,CAAC;AAEF,QAAA,GAAG,CAAC,WAAW,CAAC,MAAK;YACnB,IAAI,IAAI;YACR,IAAI,GAAG,SAAS;AAClB,QAAA,CAAC,CAAC;QAEF,OAAO,EAAE,UAAU,EAAE;IACvB;AAEA,IAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE;AAC/C;;;;"}
|
package/docs/API.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
`use-scroll-animate` — every public export, option and attribute. See the [README](../README.md) for a tour, the [demo](../demo/index.html) to try every preset, and the migration guides for [AOS](./migration-from-aos.md) and [GSAP ScrollTrigger](./migration-from-gsap-scrolltrigger.md). Upgrading from 1.x: see [Upgrading to 2.0](./deprecations.md).
|
|
4
|
+
|
|
5
|
+
- [Entry points](#entry-points)
|
|
6
|
+
- [Default instance & `createScrollAnimate(config)`](#default-instance--createscrollanimateconfig)
|
|
7
|
+
- [Instance methods](#instance-methods)
|
|
8
|
+
- [Per-element options (`AnimateOptions`)](#per-element-options-animateoptions)
|
|
9
|
+
- [Data attributes](#data-attributes)
|
|
10
|
+
- [Global config (`ScrollAnimateConfig`)](#global-config-scrollanimateconfig)
|
|
11
|
+
- [Presets & easings](#presets--easings)
|
|
12
|
+
- [Helpers: `staggerChildren`, `sequence`, `parallax`, `getScrollProgress`, `supportsScrollTimeline`](#helpers)
|
|
13
|
+
- [Framework integrations](#framework-integrations)
|
|
14
|
+
- [Behaviour notes](#behaviour-notes)
|
|
15
|
+
|
|
16
|
+
## Entry points
|
|
17
|
+
|
|
18
|
+
| Import | Contents |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `use-scroll-animate` | Default instance, `createScrollAnimate`, `staggerChildren`, `sequence`, `parallax`, `getScrollProgress`, `supportsScrollTimeline`, `PRESETS`, `resolvePreset`, `resolveEasing`, `EASING_MAP`, all types |
|
|
21
|
+
| `use-scroll-animate/react` | `createReactHooks(React)` |
|
|
22
|
+
| `use-scroll-animate/vue` | `createVueComposables({ ref, onMounted, onUnmounted })` |
|
|
23
|
+
| `use-scroll-animate/svelte` | `scrollAnimate`, `scrollStagger` actions |
|
|
24
|
+
| `use-scroll-animate/solid` | `scrollAnimate`, `scrollStagger` directives, `useScrollAnimate()` (needs `solid-js`) |
|
|
25
|
+
| `use-scroll-animate/element` | `defineScrollAnimate(tagName?, instance?)` for `<scroll-animate>` |
|
|
26
|
+
| `dist/index.umd.js` | Global `ScrollAnimate` (`ScrollAnimate.default` is the instance, other exports as properties) |
|
|
27
|
+
| `dist/element.umd.js` | Registers `<scroll-animate>` on load; global `ScrollAnimateElement` |
|
|
28
|
+
|
|
29
|
+
Every entry is ESM-first (`import` → `.js` + `.d.ts`) with a CommonJS build (`require` → `.cjs` + `.d.cts`), SSR-safe (no DOM access at import), and has zero runtime dependencies.
|
|
30
|
+
|
|
31
|
+
## Default instance & `createScrollAnimate(config)`
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import ScrollAnimate, { createScrollAnimate } from 'use-scroll-animate';
|
|
35
|
+
|
|
36
|
+
ScrollAnimate.init(); // shared default instance
|
|
37
|
+
const sa = createScrollAnimate({ defaultDuration: 800, defaultEngine: 'auto' }); // isolated instance
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`createScrollAnimate(config?: ScrollAnimateConfig): ScrollAnimateInstance`. Instances share no state: each has its own registry, observers, watchers and timers.
|
|
41
|
+
|
|
42
|
+
## Instance methods
|
|
43
|
+
|
|
44
|
+
| Method | Description |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `init(root?: Element \| Document)` | Observe every `[data-sa]` element under `root` (default `document`). Already observed / finished elements are skipped. |
|
|
47
|
+
| `watch(root?)` → `() => void` | `init()` and keep observing `[data-sa]` elements added later (MutationObserver); removed elements are released. Returns a stop function. |
|
|
48
|
+
| `observe(target, options?)` | Observe a selector, `Element`, `NodeList` or `Element[]`. Elements are hidden until they enter (JS engine). |
|
|
49
|
+
| `unobserve(target)` | Stop observing. Elements that never animated are made visible; native scroll-linked animations are cancelled. |
|
|
50
|
+
| `animate(target, options?)` | Play the entrance animation now (time-based JS engine), without observing. |
|
|
51
|
+
| `refresh()` | Rebuild the observers (e.g. after `configure({ root })`) without replaying finished elements. |
|
|
52
|
+
| `configure(config)` | Merge new global config. |
|
|
53
|
+
| `getObservedElements()` → `AnimatedElement[]` | Registered elements: `{ element, options, observer, animated, progressObserver?, engine? }`. Finished `once` elements are dropped when `autoUnregister` is on. |
|
|
54
|
+
| `destroy()` | Disconnect everything (observers, watchers, scroll listeners, class-name timers), reveal elements that never animated, cancel native animations. |
|
|
55
|
+
|
|
56
|
+
`target` is always `string | Element | NodeList | Element[]`.
|
|
57
|
+
|
|
58
|
+
## Per-element options (`AnimateOptions`)
|
|
59
|
+
|
|
60
|
+
| Option | Type | Default | Description |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| `animation` | `AnimationPreset \| AnimationPreset[] \| { from, to }` | `'fade-in-up'` | Preset, presets combined (transforms are concatenated), or custom keyframes |
|
|
63
|
+
| `duration` | `number` (ms) | `600` | JS engine only (setting it makes `'auto'` pick JS) |
|
|
64
|
+
| `delay` | `number` (ms) | `0` | JS engine only (setting it makes `'auto'` pick JS) |
|
|
65
|
+
| `easing` | `EasingType` | `'ease'` | CSS easing string, named easing, `[x1, y1, x2, y2]`, or `(t) => number` (sampled into `linear()`) |
|
|
66
|
+
| `threshold` | `number \| number[]` | `0.1` | IntersectionObserver threshold(s) |
|
|
67
|
+
| `rootMargin` | `string` | `'0px'` | IntersectionObserver root margin |
|
|
68
|
+
| `offset` | `number` (px) | `0` | Trigger this many px later (subtracted from the bottom root margin) |
|
|
69
|
+
| `once` | `boolean` | `true` | Animate on the first entry only |
|
|
70
|
+
| `repeat` | `boolean` | `false` | Re-hide on leave, replay on each entry |
|
|
71
|
+
| `exit` | `boolean \| preset \| preset[] \| { from, to }` | `false` | Animate out (in reverse) when leaving; implies `repeat` |
|
|
72
|
+
| `stagger` | `number` (ms) | `0` | Extra delay per sibling revealed in the same batch |
|
|
73
|
+
| `engine` | `'auto' \| 'js' \| 'css'` | `'auto'` | `'auto'`: native scroll-driven timeline when supported, else JS — and JS when the element sets `duration`/`delay`/`offset`/`stagger`; `'css'`: native whenever supported; `'js'`: always time-based |
|
|
74
|
+
| `viewRange` | `[string, string]` | `['entry 0%', 'entry 100%']` | Native engine: view-timeline range of the entrance |
|
|
75
|
+
| `parallax` | `{ x?, y?, rotate?, scale?, speed? }` | `{}` | Legacy transform-based parallax (writes `transform`); see also `parallax()` |
|
|
76
|
+
| `progressMode` | `'ratio' \| 'scroll'` | `'ratio'` | `onProgress` source: visible ratio, or true scroll progress (0 = top enters at the bottom, 1 = bottom leaves at the top) |
|
|
77
|
+
| `progressVar` | `string` | – | CSS custom property that receives the progress |
|
|
78
|
+
| `onEnter` / `onLeave` | `(el) => void` | – | Viewport entry / exit |
|
|
79
|
+
| `onStart` / `onComplete` | `(el) => void` | – | Animation start / end (also fired under reduced motion, immediately) |
|
|
80
|
+
| `onProgress` | `(el, progress) => void` | – | Progress 0–1 |
|
|
81
|
+
|
|
82
|
+
## Data attributes
|
|
83
|
+
|
|
84
|
+
Mark elements with `data-sa` and call `init()` / `watch()`. Every option has an attribute:
|
|
85
|
+
|
|
86
|
+
`data-sa-animation` (comma-separated to combine), `data-sa-duration`, `data-sa-delay`, `data-sa-easing` (name, CSS string or JSON array), `data-sa-threshold` (comma-separated list allowed), `data-sa-root-margin`, `data-sa-offset`, `data-sa-once`, `data-sa-repeat`, `data-sa-exit` (bare = `true`, or preset name), `data-sa-stagger`, `data-sa-engine`, `data-sa-view-range` (`"entry 0%, cover 40%"`), `data-sa-progress` (`"scroll"`), `data-sa-progress-var` (bare = `--sa-progress`), `data-sa-parallax-x|y|rotate|scale|speed`.
|
|
87
|
+
|
|
88
|
+
Boolean attributes are true when present unless their value is `"false"`.
|
|
89
|
+
|
|
90
|
+
## Global config (`ScrollAnimateConfig`)
|
|
91
|
+
|
|
92
|
+
| Key | Default | Description |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `defaultAnimation`, `defaultDuration`, `defaultDelay`, `defaultEasing`, `defaultThreshold`, `defaultRootMargin`, `defaultRepeat`, `defaultOnce`, `defaultOffset` | as per-element defaults | Defaults for options not set per element |
|
|
95
|
+
| `defaultEngine` | `'auto'` | Default `engine` (`'js'` = 1.x behaviour) |
|
|
96
|
+
| `useClassNames` | `false` | Toggle `hiddenClass`/`visibleClass` instead of Web Animations (animate with your own CSS) |
|
|
97
|
+
| `hiddenClass` / `visibleClass` | `'sa-hidden'` / `'sa-visible'` | Class names for class-name mode |
|
|
98
|
+
| `disabled` | `false` | Show everything immediately, no motion (callbacks still fire) |
|
|
99
|
+
| `root` | `null` | Scroll container for IntersectionObserver / progress |
|
|
100
|
+
| `autoUnregister` | `true` | Drop finished `once` elements from the registry (remembered in a `WeakSet`, never replayed) |
|
|
101
|
+
|
|
102
|
+
## Presets & easings
|
|
103
|
+
|
|
104
|
+
`PRESETS` (`Record<AnimationPreset, { from, to }>`): `fade-in`, `fade-in-up`, `fade-in-down`, `fade-in-left`, `fade-in-right`, `zoom-in`, `zoom-out`, `scale-up`, `flip-x`, `flip-y`, `flip-up`, `flip-down`, `slide-up`, `slide-down`, `slide-left`, `slide-right`, `bounce`, `rotate-in`, `rotate-left`, `rotate-right`, `blur-in`, `blur-in-up`, `skew-in`, `scale-x`, `scale-y`, `clip-up`, `clip-down`, `clip-left`, `clip-right`, `clip-circle`, `shimmer`, `pulse`, `swing`.
|
|
105
|
+
|
|
106
|
+
`EASING_MAP`: `linear`, `ease`, `ease-in`, `ease-out`, `ease-in-out`, `spring`, `soft-spring`, `heavy-bounce`. `resolvePreset(animation)` and `resolveEasing(easing)` expose the resolution used internally.
|
|
107
|
+
|
|
108
|
+
## Helpers
|
|
109
|
+
|
|
110
|
+
### `staggerChildren(container, options?, instance?)` → `() => void`
|
|
111
|
+
Reveal the children of `container` one after another when it enters. `StaggerOptions` = `AnimateOptions` + `stagger` (default `80` ms) + `observeChildren` (MutationObserver for children added later). Stopping before the reveal makes the children visible.
|
|
112
|
+
|
|
113
|
+
### `sequence(steps, options?)` → `SequenceController`
|
|
114
|
+
Timeline across targets. `SequenceStep` = `AnimateOptions` + `target` + `gap` (ms after the previous step; negative overlaps) or `at` (absolute ms). `SequenceOptions` = `AnimateOptions` + `trigger` (play once when it enters) + `instance`. Controller: `play(): Promise<void>`, `cancel()`, `duration()`.
|
|
115
|
+
|
|
116
|
+
### `parallax(target, options?)` → `() => void`
|
|
117
|
+
`{ speed = 0.2, axis = 'y', progressVar = '--sa-parallax', root = null, respectReducedMotion = true }`. Offset `(progress − 0.5) × speed × 100vh` (or `vw`) on the `translate` property; progress (0–1) in the CSS variable. The stop function removes listeners and inline styles.
|
|
118
|
+
|
|
119
|
+
### `getScrollProgress(el, root?)` → `number`
|
|
120
|
+
True scroll progress 0–1 of `el` through the viewport or `root`. `0` without a DOM.
|
|
121
|
+
|
|
122
|
+
### `supportsScrollTimeline()` → `boolean`
|
|
123
|
+
`CSS.supports('animation-timeline: view()')` and `ViewTimeline` available — i.e. whether `engine: 'auto'` will use the native engine.
|
|
124
|
+
|
|
125
|
+
## Framework integrations
|
|
126
|
+
|
|
127
|
+
- **React** — `const { useScrollAnimate, useScrollStagger } = createReactHooks(React)`; both return a ref. Callbacks always call the latest render's version.
|
|
128
|
+
- **Vue 3** — `createVueComposables({ ref, onMounted, onUnmounted })` → `useScrollAnimate()` (`{ animateRef }`), `useScrollStagger()` (`{ staggerRef }`); component refs (`$el`) are supported.
|
|
129
|
+
- **Svelte** — `use:scrollAnimate={options}`, `use:scrollStagger={options}`; `update()` swaps callbacks (and other options before the element animated). Optional `instance`.
|
|
130
|
+
- **Solid** — `use:scrollAnimate`, `use:scrollStagger` (typed via `JSX.Directives`), `ref={useScrollAnimate(options)}`.
|
|
131
|
+
- **Web Component** — `<scroll-animate animation="…" …>` with the `data-sa-*` attribute names minus the prefix; events `sa:enter`, `sa:leave`, `sa:start`, `sa:complete`, `sa:progress` (`detail.progress`). Attribute changes before the element animated re-apply the options.
|
|
132
|
+
|
|
133
|
+
## Behaviour notes
|
|
134
|
+
|
|
135
|
+
- **Reduced motion**: with `prefers-reduced-motion: reduce` (or `disabled: true`) nothing is hidden or moved; callbacks still fire; `progressVar` is still written (it is data); `parallax()` writes only its variable.
|
|
136
|
+
- **SSR**: every entry can be imported and called on the server; calls are no-ops without a DOM.
|
|
137
|
+
- **No IntersectionObserver**: content is shown immediately.
|
|
138
|
+
- **Native engine**: scroll-linked, so `duration`/`delay`/`threshold`/`offset`/`stagger` don't apply; `once` freezes the end state on completion; class-name mode, reduced motion, `animate()`, `sequence()` and `staggerChildren()` always use JS.
|
|
139
|
+
- **Native engine by default**: in browsers without `animation-timeline: view()` everything runs on the JS engine.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Upgrading to 2.0 (removed APIs)
|
|
2
|
+
|
|
3
|
+
Everything below was deprecated in 1.9 and is **removed in 2.0.0**. The full step-by-step list is the MIGRATION section of the [CHANGELOG](../CHANGELOG.md).
|
|
4
|
+
|
|
5
|
+
| Removed in 2.0 | Use instead |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `import { createReactHooks } from 'use-scroll-animate'` | `import { createReactHooks } from 'use-scroll-animate/react'` |
|
|
8
|
+
| `import { createVueComposables } from 'use-scroll-animate'` | `import { createVueComposables } from 'use-scroll-animate/vue'` |
|
|
9
|
+
| `module` field, `dist/index.esm.js`, `dist/index.mjs` | the `exports` map: `import` → `dist/index.js` (ESM) |
|
|
10
|
+
| `dist/index.js` as CommonJS | `require('use-scroll-animate')` → `dist/index.cjs` (`main`) |
|
|
11
|
+
| per-file declarations in `dist/types/*`, `dist/*.d.mts` | bundled `dist/*.d.ts` (ESM) / `dist/*.d.cts` (CJS), resolved through `exports` |
|
|
12
|
+
| `use-scroll-animate/dist/*` deep imports | the named entry points (`use-scroll-animate`, `/react`, `/vue`, `/svelte`, `/solid`, `/element`) |
|
|
13
|
+
|
|
14
|
+
Unchanged: the browser bundles at `dist/index.umd.js` (global `ScrollAnimate`) and `dist/element.umd.js` keep their CDN URLs (`https://unpkg.com/use-scroll-animate/dist/index.umd.js`).
|
|
15
|
+
|
|
16
|
+
Behaviour changes in 2.0 (no API removed):
|
|
17
|
+
|
|
18
|
+
- `engine` defaults to `'auto'`: the native scroll-driven timeline is used where `animation-timeline: view()` is supported, unless the element sets `duration`, `delay`, `offset` or `stagger` itself. `createScrollAnimate({ defaultEngine: 'js' })` (or `ScrollAnimate.configure({ defaultEngine: 'js' })`) restores the 1.x behaviour.
|
|
19
|
+
- Output targets ES2020 (optional chaining / nullish coalescing are no longer down-levelled). Every browser with `Animation.commitStyles()` — which the library already relied on — supports ES2020.
|
|
20
|
+
- Node ≥ 18 is declared in `engines` (only relevant for SSR imports).
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Migrating from AOS (Animate On Scroll)
|
|
2
|
+
|
|
3
|
+
AOS and `use-scroll-animate` work the same way at the markup level — mark elements with attributes and call `init()` — so most pages migrate with a search-and-replace.
|
|
4
|
+
|
|
5
|
+
## 1. Install and initialise
|
|
6
|
+
|
|
7
|
+
```diff
|
|
8
|
+
- import AOS from 'aos';
|
|
9
|
+
- import 'aos/dist/aos.css';
|
|
10
|
+
- AOS.init({ duration: 800, once: true, offset: 120 });
|
|
11
|
+
+ import ScrollAnimate from 'use-scroll-animate';
|
|
12
|
+
+ ScrollAnimate.configure({ defaultDuration: 800, defaultOnce: true, defaultOffset: 120 });
|
|
13
|
+
+ ScrollAnimate.watch(); // like init(), and also picks up elements added later (AOS.refreshHard())
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
No stylesheet is needed: animations run through the Web Animations API (or opt into CSS classes with `useClassNames: true`).
|
|
17
|
+
|
|
18
|
+
## 2. Attributes
|
|
19
|
+
|
|
20
|
+
| AOS | use-scroll-animate |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `data-aos="fade-up"` | `data-sa data-sa-animation="fade-in-up"` |
|
|
23
|
+
| `data-aos-duration="800"` | `data-sa-duration="800"` |
|
|
24
|
+
| `data-aos-delay="200"` | `data-sa-delay="200"` |
|
|
25
|
+
| `data-aos-easing="ease-in-out"` | `data-sa-easing="ease-in-out"` (also `spring`, `soft-spring`, `heavy-bounce`, `[x1,y1,x2,y2]`) |
|
|
26
|
+
| `data-aos-offset="120"` | `data-sa-offset="120"` |
|
|
27
|
+
| `data-aos-once="true"` | `data-sa-once` (default) |
|
|
28
|
+
| `data-aos-mirror="true"` (animate out when scrolling past) | `data-sa-exit` |
|
|
29
|
+
| `data-aos-anchor-placement="top-center"` | `data-sa-threshold="0.5"` or `data-sa-root-margin="0px 0px -50% 0px"` |
|
|
30
|
+
| `data-aos-anchor=".other"` | `sequence([...], { trigger: '.other' })` |
|
|
31
|
+
|
|
32
|
+
## 3. Animation names
|
|
33
|
+
|
|
34
|
+
| AOS | use-scroll-animate |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `fade` | `fade-in` |
|
|
37
|
+
| `fade-up` / `fade-down` | `fade-in-up` / `fade-in-down` |
|
|
38
|
+
| `fade-left` / `fade-right` | `fade-in-right` / `fade-in-left` (see the note below) |
|
|
39
|
+
| `fade-up-right` etc. | `['fade-in-up', 'fade-in-left']` (combine presets) |
|
|
40
|
+
| `flip-up` / `flip-down` | `flip-up` / `flip-down` |
|
|
41
|
+
| `flip-left` / `flip-right` | `flip-y` |
|
|
42
|
+
| `slide-up` / `slide-down` / `slide-left` / `slide-right` | `slide-up` / `slide-down` / `slide-right` / `slide-left` |
|
|
43
|
+
| `zoom-in` / `zoom-out` | `zoom-in` / `zoom-out` |
|
|
44
|
+
| `zoom-in-up` etc. | `['zoom-in', 'fade-in-up']` |
|
|
45
|
+
|
|
46
|
+
**Left/right naming:** AOS names the direction of travel — `fade-left` moves *towards* the left, i.e. comes in from the right. Here presets name where the element comes *from*: `fade-in-right` comes in from the right. Same for `slide-*`.
|
|
47
|
+
|
|
48
|
+
## 4. Global options
|
|
49
|
+
|
|
50
|
+
| `AOS.init({...})` | `createScrollAnimate({...})` / `configure()` |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `duration`, `delay`, `easing`, `offset`, `once` | `defaultDuration`, `defaultDelay`, `defaultEasing`, `defaultOffset`, `defaultOnce` |
|
|
53
|
+
| `mirror: true` | per element `exit: true` (or `data-sa-exit`) |
|
|
54
|
+
| `disable: 'mobile'` / function | `disabled: window.matchMedia('(max-width: 600px)').matches` |
|
|
55
|
+
| `startEvent`, `initClassName`, `animatedClassName` | `useClassNames`, `hiddenClass`, `visibleClass` |
|
|
56
|
+
| `throttleDelay`, `debounceDelay` | not needed (IntersectionObserver, no scroll listener) |
|
|
57
|
+
|
|
58
|
+
## 5. Events and refresh
|
|
59
|
+
|
|
60
|
+
| AOS | use-scroll-animate |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `document.addEventListener('aos:in', ...)` | `onEnter` / `onStart` options, or `<scroll-animate>`'s `sa:enter` / `sa:start` events |
|
|
63
|
+
| `aos:out` | `onLeave` |
|
|
64
|
+
| `AOS.refresh()` | `ScrollAnimate.refresh()` |
|
|
65
|
+
| `AOS.refreshHard()` | `ScrollAnimate.watch()` handles DOM changes automatically |
|
|
66
|
+
|
|
67
|
+
`prefers-reduced-motion` is respected out of the box (AOS needs `disable`).
|