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
|
@@ -0,0 +1,244 @@
|
|
|
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
|
+
/** Global configuration for ScrollAnimate instance */
|
|
113
|
+
interface ScrollAnimateConfig {
|
|
114
|
+
/** Default animation preset (default: 'fade-in-up') */
|
|
115
|
+
defaultAnimation?: AnimationPreset | AnimationPreset[] | CustomAnimation;
|
|
116
|
+
/** Default duration in ms (default: 600) */
|
|
117
|
+
defaultDuration?: number;
|
|
118
|
+
/** Default delay in ms (default: 0) */
|
|
119
|
+
defaultDelay?: number;
|
|
120
|
+
/** Default easing (default: 'ease') */
|
|
121
|
+
defaultEasing?: EasingType;
|
|
122
|
+
/** Default threshold (default: 0.1) */
|
|
123
|
+
defaultThreshold?: number | number[];
|
|
124
|
+
/** Default root margin (default: '0px') */
|
|
125
|
+
defaultRootMargin?: string;
|
|
126
|
+
/** Whether animations replay by default (default: false) */
|
|
127
|
+
defaultRepeat?: boolean;
|
|
128
|
+
/** Default once setting (default: true) */
|
|
129
|
+
defaultOnce?: boolean;
|
|
130
|
+
/** Default offset in pixels (default: 0) */
|
|
131
|
+
defaultOffset?: number;
|
|
132
|
+
/** CSS class added before animation (default: 'sa-hidden') */
|
|
133
|
+
hiddenClass?: string;
|
|
134
|
+
/** CSS class added when element is visible (default: 'sa-visible') */
|
|
135
|
+
visibleClass?: string;
|
|
136
|
+
/** Whether to use CSS class-based animation instead of Web Animations API */
|
|
137
|
+
useClassNames?: boolean;
|
|
138
|
+
/** Disable all animations (useful for reduced-motion preference) */
|
|
139
|
+
disabled?: boolean;
|
|
140
|
+
/** Custom IntersectionObserver root element */
|
|
141
|
+
root?: Element | null;
|
|
142
|
+
/**
|
|
143
|
+
* Drop `once` elements from the registry as soon as their entrance animation
|
|
144
|
+
* has been triggered (unless they still need parallax/onProgress), so they can
|
|
145
|
+
* be garbage-collected. They are remembered in a WeakSet, so `init()`/`observe()`
|
|
146
|
+
* never re-hide or replay them. (default: true)
|
|
147
|
+
*/
|
|
148
|
+
autoUnregister?: boolean;
|
|
149
|
+
/** Default animation engine (default: `'auto'`; `'js'` restores the 1.x behaviour) */
|
|
150
|
+
defaultEngine?: ScrollEngine;
|
|
151
|
+
}
|
|
152
|
+
/** Registered element entry */
|
|
153
|
+
interface AnimatedElement {
|
|
154
|
+
element: Element;
|
|
155
|
+
options: Required<AnimateOptions>;
|
|
156
|
+
observer: IntersectionObserver;
|
|
157
|
+
animated: boolean;
|
|
158
|
+
progressObserver?: IntersectionObserver;
|
|
159
|
+
/** Engine actually used for this element (`'css'` = native scroll-driven timeline) */
|
|
160
|
+
engine?: 'js' | 'css';
|
|
161
|
+
}
|
|
162
|
+
/** ScrollAnimate public API */
|
|
163
|
+
interface ScrollAnimateInstance {
|
|
164
|
+
/** Observe a single element or CSS selector */
|
|
165
|
+
observe(target: string | Element | NodeList | Element[], options?: AnimateOptions): void;
|
|
166
|
+
/** Stop observing a single element or CSS selector */
|
|
167
|
+
unobserve(target: string | Element | NodeList | Element[]): void;
|
|
168
|
+
/** Observe all elements matching the data-sa attribute */
|
|
169
|
+
init(rootElement?: Element | Document): void;
|
|
170
|
+
/**
|
|
171
|
+
* Like `init()`, then keep watching `rootElement` (default: `document`) with a
|
|
172
|
+
* MutationObserver: `[data-sa]` elements added later (or that gain the
|
|
173
|
+
* attribute) are observed automatically, and removed ones are released.
|
|
174
|
+
* Returns a function that stops watching. `destroy()` stops every watcher.
|
|
175
|
+
* SSR-safe: a no-op without a DOM / MutationObserver.
|
|
176
|
+
*/
|
|
177
|
+
watch(rootElement?: Element | Document): () => void;
|
|
178
|
+
/** Destroy the instance and clean up all observers */
|
|
179
|
+
destroy(): void;
|
|
180
|
+
/** Refresh all observers (useful after DOM changes) */
|
|
181
|
+
refresh(): void;
|
|
182
|
+
/** Manually trigger animation on an element */
|
|
183
|
+
animate(target: string | Element, options?: AnimateOptions): void;
|
|
184
|
+
/** Get all currently observed elements */
|
|
185
|
+
getObservedElements(): AnimatedElement[];
|
|
186
|
+
/** Update global configuration */
|
|
187
|
+
configure(config: Partial<ScrollAnimateConfig>): void;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* use-scroll-animate - Staggered children
|
|
192
|
+
* Reveal a container's children one after another when the container scrolls
|
|
193
|
+
* into view, optionally also animating children that are added later.
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
interface StaggerOptions extends AnimateOptions {
|
|
197
|
+
/** Delay between consecutive children in ms (default: 80) */
|
|
198
|
+
stagger?: number;
|
|
199
|
+
/**
|
|
200
|
+
* Watch the container with a MutationObserver and animate children added
|
|
201
|
+
* later (e.g. infinite lists). Children added after the container was
|
|
202
|
+
* revealed animate when they scroll into view, staggered per batch.
|
|
203
|
+
* (default: false)
|
|
204
|
+
*/
|
|
205
|
+
observeChildren?: boolean;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* use-scroll-animate - Svelte integration
|
|
210
|
+
*
|
|
211
|
+
* Svelte actions (no import from `svelte` needed, works with Svelte 3, 4 and 5):
|
|
212
|
+
*
|
|
213
|
+
* ```svelte
|
|
214
|
+
* <script>
|
|
215
|
+
* import { scrollAnimate, scrollStagger } from 'use-scroll-animate/svelte';
|
|
216
|
+
* </script>
|
|
217
|
+
* <div use:scrollAnimate={{ animation: 'fade-in-up', duration: 800 }}>…</div>
|
|
218
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
interface ScrollAnimateActionOptions extends AnimateOptions {
|
|
223
|
+
/** Instance to register with (default: a shared instance created on first use) */
|
|
224
|
+
instance?: ScrollAnimateInstance;
|
|
225
|
+
}
|
|
226
|
+
interface ScrollStaggerActionOptions extends StaggerOptions {
|
|
227
|
+
instance?: ScrollAnimateInstance;
|
|
228
|
+
}
|
|
229
|
+
/** Shape of a Svelte action's return value. */
|
|
230
|
+
interface ActionReturn<P> {
|
|
231
|
+
update?: (parameter: P) => void;
|
|
232
|
+
destroy?: () => void;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Animate `node` when it scrolls into view. Changing the parameter updates the
|
|
236
|
+
* callbacks right away; other options are applied if the element has not
|
|
237
|
+
* animated yet.
|
|
238
|
+
*/
|
|
239
|
+
declare function scrollAnimate(node: Element, options?: ScrollAnimateActionOptions): ActionReturn<ScrollAnimateActionOptions | undefined>;
|
|
240
|
+
/** Stagger the children of `node` when it scrolls into view (`observeChildren: true` also animates children added later). */
|
|
241
|
+
declare function scrollStagger(node: Element, options?: ScrollStaggerActionOptions): ActionReturn<ScrollStaggerActionOptions | undefined>;
|
|
242
|
+
|
|
243
|
+
export { scrollAnimate, scrollStagger };
|
|
244
|
+
export type { ActionReturn, ScrollAnimateActionOptions, ScrollStaggerActionOptions };
|
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
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
|
+
/** Global configuration for ScrollAnimate instance */
|
|
113
|
+
interface ScrollAnimateConfig {
|
|
114
|
+
/** Default animation preset (default: 'fade-in-up') */
|
|
115
|
+
defaultAnimation?: AnimationPreset | AnimationPreset[] | CustomAnimation;
|
|
116
|
+
/** Default duration in ms (default: 600) */
|
|
117
|
+
defaultDuration?: number;
|
|
118
|
+
/** Default delay in ms (default: 0) */
|
|
119
|
+
defaultDelay?: number;
|
|
120
|
+
/** Default easing (default: 'ease') */
|
|
121
|
+
defaultEasing?: EasingType;
|
|
122
|
+
/** Default threshold (default: 0.1) */
|
|
123
|
+
defaultThreshold?: number | number[];
|
|
124
|
+
/** Default root margin (default: '0px') */
|
|
125
|
+
defaultRootMargin?: string;
|
|
126
|
+
/** Whether animations replay by default (default: false) */
|
|
127
|
+
defaultRepeat?: boolean;
|
|
128
|
+
/** Default once setting (default: true) */
|
|
129
|
+
defaultOnce?: boolean;
|
|
130
|
+
/** Default offset in pixels (default: 0) */
|
|
131
|
+
defaultOffset?: number;
|
|
132
|
+
/** CSS class added before animation (default: 'sa-hidden') */
|
|
133
|
+
hiddenClass?: string;
|
|
134
|
+
/** CSS class added when element is visible (default: 'sa-visible') */
|
|
135
|
+
visibleClass?: string;
|
|
136
|
+
/** Whether to use CSS class-based animation instead of Web Animations API */
|
|
137
|
+
useClassNames?: boolean;
|
|
138
|
+
/** Disable all animations (useful for reduced-motion preference) */
|
|
139
|
+
disabled?: boolean;
|
|
140
|
+
/** Custom IntersectionObserver root element */
|
|
141
|
+
root?: Element | null;
|
|
142
|
+
/**
|
|
143
|
+
* Drop `once` elements from the registry as soon as their entrance animation
|
|
144
|
+
* has been triggered (unless they still need parallax/onProgress), so they can
|
|
145
|
+
* be garbage-collected. They are remembered in a WeakSet, so `init()`/`observe()`
|
|
146
|
+
* never re-hide or replay them. (default: true)
|
|
147
|
+
*/
|
|
148
|
+
autoUnregister?: boolean;
|
|
149
|
+
/** Default animation engine (default: `'auto'`; `'js'` restores the 1.x behaviour) */
|
|
150
|
+
defaultEngine?: ScrollEngine;
|
|
151
|
+
}
|
|
152
|
+
/** Registered element entry */
|
|
153
|
+
interface AnimatedElement {
|
|
154
|
+
element: Element;
|
|
155
|
+
options: Required<AnimateOptions>;
|
|
156
|
+
observer: IntersectionObserver;
|
|
157
|
+
animated: boolean;
|
|
158
|
+
progressObserver?: IntersectionObserver;
|
|
159
|
+
/** Engine actually used for this element (`'css'` = native scroll-driven timeline) */
|
|
160
|
+
engine?: 'js' | 'css';
|
|
161
|
+
}
|
|
162
|
+
/** ScrollAnimate public API */
|
|
163
|
+
interface ScrollAnimateInstance {
|
|
164
|
+
/** Observe a single element or CSS selector */
|
|
165
|
+
observe(target: string | Element | NodeList | Element[], options?: AnimateOptions): void;
|
|
166
|
+
/** Stop observing a single element or CSS selector */
|
|
167
|
+
unobserve(target: string | Element | NodeList | Element[]): void;
|
|
168
|
+
/** Observe all elements matching the data-sa attribute */
|
|
169
|
+
init(rootElement?: Element | Document): void;
|
|
170
|
+
/**
|
|
171
|
+
* Like `init()`, then keep watching `rootElement` (default: `document`) with a
|
|
172
|
+
* MutationObserver: `[data-sa]` elements added later (or that gain the
|
|
173
|
+
* attribute) are observed automatically, and removed ones are released.
|
|
174
|
+
* Returns a function that stops watching. `destroy()` stops every watcher.
|
|
175
|
+
* SSR-safe: a no-op without a DOM / MutationObserver.
|
|
176
|
+
*/
|
|
177
|
+
watch(rootElement?: Element | Document): () => void;
|
|
178
|
+
/** Destroy the instance and clean up all observers */
|
|
179
|
+
destroy(): void;
|
|
180
|
+
/** Refresh all observers (useful after DOM changes) */
|
|
181
|
+
refresh(): void;
|
|
182
|
+
/** Manually trigger animation on an element */
|
|
183
|
+
animate(target: string | Element, options?: AnimateOptions): void;
|
|
184
|
+
/** Get all currently observed elements */
|
|
185
|
+
getObservedElements(): AnimatedElement[];
|
|
186
|
+
/** Update global configuration */
|
|
187
|
+
configure(config: Partial<ScrollAnimateConfig>): void;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* use-scroll-animate - Staggered children
|
|
192
|
+
* Reveal a container's children one after another when the container scrolls
|
|
193
|
+
* into view, optionally also animating children that are added later.
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
interface StaggerOptions extends AnimateOptions {
|
|
197
|
+
/** Delay between consecutive children in ms (default: 80) */
|
|
198
|
+
stagger?: number;
|
|
199
|
+
/**
|
|
200
|
+
* Watch the container with a MutationObserver and animate children added
|
|
201
|
+
* later (e.g. infinite lists). Children added after the container was
|
|
202
|
+
* revealed animate when they scroll into view, staggered per batch.
|
|
203
|
+
* (default: false)
|
|
204
|
+
*/
|
|
205
|
+
observeChildren?: boolean;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* use-scroll-animate - Svelte integration
|
|
210
|
+
*
|
|
211
|
+
* Svelte actions (no import from `svelte` needed, works with Svelte 3, 4 and 5):
|
|
212
|
+
*
|
|
213
|
+
* ```svelte
|
|
214
|
+
* <script>
|
|
215
|
+
* import { scrollAnimate, scrollStagger } from 'use-scroll-animate/svelte';
|
|
216
|
+
* </script>
|
|
217
|
+
* <div use:scrollAnimate={{ animation: 'fade-in-up', duration: 800 }}>…</div>
|
|
218
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
interface ScrollAnimateActionOptions extends AnimateOptions {
|
|
223
|
+
/** Instance to register with (default: a shared instance created on first use) */
|
|
224
|
+
instance?: ScrollAnimateInstance;
|
|
225
|
+
}
|
|
226
|
+
interface ScrollStaggerActionOptions extends StaggerOptions {
|
|
227
|
+
instance?: ScrollAnimateInstance;
|
|
228
|
+
}
|
|
229
|
+
/** Shape of a Svelte action's return value. */
|
|
230
|
+
interface ActionReturn<P> {
|
|
231
|
+
update?: (parameter: P) => void;
|
|
232
|
+
destroy?: () => void;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Animate `node` when it scrolls into view. Changing the parameter updates the
|
|
236
|
+
* callbacks right away; other options are applied if the element has not
|
|
237
|
+
* animated yet.
|
|
238
|
+
*/
|
|
239
|
+
declare function scrollAnimate(node: Element, options?: ScrollAnimateActionOptions): ActionReturn<ScrollAnimateActionOptions | undefined>;
|
|
240
|
+
/** Stagger the children of `node` when it scrolls into view (`observeChildren: true` also animates children added later). */
|
|
241
|
+
declare function scrollStagger(node: Element, options?: ScrollStaggerActionOptions): ActionReturn<ScrollStaggerActionOptions | undefined>;
|
|
242
|
+
|
|
243
|
+
export { scrollAnimate, scrollStagger };
|
|
244
|
+
export type { ActionReturn, ScrollAnimateActionOptions, ScrollStaggerActionOptions };
|
package/dist/svelte.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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 - Svelte integration
|
|
6
|
+
*
|
|
7
|
+
* Svelte actions (no import from `svelte` needed, works with Svelte 3, 4 and 5):
|
|
8
|
+
*
|
|
9
|
+
* ```svelte
|
|
10
|
+
* <script>
|
|
11
|
+
* import { scrollAnimate, scrollStagger } from 'use-scroll-animate/svelte';
|
|
12
|
+
* </script>
|
|
13
|
+
* <div use:scrollAnimate={{ animation: 'fade-in-up', duration: 800 }}>…</div>
|
|
14
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
let shared = null;
|
|
18
|
+
const getInstance = (own) => own || shared || (shared = createScrollAnimate());
|
|
19
|
+
const CALLBACKS = ['onStart', 'onComplete', 'onEnter', 'onLeave', 'onProgress'];
|
|
20
|
+
/** Callbacks always call the latest parameter's version. */
|
|
21
|
+
function liveCallbacks(opts, latest) {
|
|
22
|
+
const out = { ...opts };
|
|
23
|
+
CALLBACKS.forEach((name) => {
|
|
24
|
+
if (typeof opts[name] === 'function')
|
|
25
|
+
out[name] = (...args) => latest()[name]?.(...args);
|
|
26
|
+
});
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Animate `node` when it scrolls into view. Changing the parameter updates the
|
|
31
|
+
* callbacks right away; other options are applied if the element has not
|
|
32
|
+
* animated yet.
|
|
33
|
+
*/
|
|
34
|
+
function scrollAnimate(node, options = {}) {
|
|
35
|
+
let current = options;
|
|
36
|
+
const { instance, ...opts } = options;
|
|
37
|
+
const sa = getInstance(instance);
|
|
38
|
+
sa.observe(node, liveCallbacks(opts, () => current));
|
|
39
|
+
return {
|
|
40
|
+
update(next = {}) {
|
|
41
|
+
current = next;
|
|
42
|
+
const record = sa.getObservedElements().find((r) => r.element === node);
|
|
43
|
+
if (record && !record.animated) {
|
|
44
|
+
const { instance: _ignored, ...nextOpts } = next;
|
|
45
|
+
sa.unobserve(node);
|
|
46
|
+
sa.observe(node, liveCallbacks(nextOpts, () => current));
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
destroy() {
|
|
50
|
+
sa.unobserve(node);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Stagger the children of `node` when it scrolls into view (`observeChildren: true` also animates children added later). */
|
|
55
|
+
function scrollStagger(node, options = {}) {
|
|
56
|
+
const { instance, ...opts } = options;
|
|
57
|
+
const stop = staggerChildren(node, opts, getInstance(instance));
|
|
58
|
+
return { destroy: stop };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { scrollAnimate, scrollStagger };
|
|
62
|
+
//# sourceMappingURL=svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.js","sources":["../src/svelte.ts"],"sourcesContent":["/**\n * use-scroll-animate - Svelte integration\n *\n * Svelte actions (no import from `svelte` needed, works with Svelte 3, 4 and 5):\n *\n * ```svelte\n * <script>\n * import { scrollAnimate, scrollStagger } from 'use-scroll-animate/svelte';\n * </script>\n * <div use:scrollAnimate={{ animation: 'fade-in-up', duration: 800 }}>…</div>\n * <ul use:scrollStagger={{ stagger: 60 }}>…</ul>\n * ```\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate } from './core';\nimport { staggerChildren, type StaggerOptions } from './stagger';\n\nexport interface ScrollAnimateActionOptions extends AnimateOptions {\n /** Instance to register with (default: a shared instance created on first use) */\n instance?: ScrollAnimateInstance;\n}\n\nexport interface ScrollStaggerActionOptions extends StaggerOptions {\n instance?: ScrollAnimateInstance;\n}\n\n/** Shape of a Svelte action's return value. */\nexport interface ActionReturn<P> {\n update?: (parameter: P) => void;\n destroy?: () => void;\n}\n\nlet shared: ScrollAnimateInstance | null = null;\nconst getInstance = (own?: ScrollAnimateInstance) => own || shared || (shared = createScrollAnimate());\n\nconst CALLBACKS = ['onStart', 'onComplete', 'onEnter', 'onLeave', 'onProgress'] as const;\n\n/** Callbacks always call the latest parameter's version. */\nfunction liveCallbacks(opts: AnimateOptions, latest: () => AnimateOptions): AnimateOptions {\n const out: AnimateOptions = { ...opts };\n CALLBACKS.forEach((name) => {\n if (typeof opts[name] === 'function') (out as any)[name] = (...args: unknown[]) => (latest()[name] as any)?.(...args);\n });\n return out;\n}\n\n/**\n * Animate `node` when it scrolls into view. Changing the parameter updates the\n * callbacks right away; other options are applied if the element has not\n * animated yet.\n */\nexport function scrollAnimate(\n node: Element,\n options: ScrollAnimateActionOptions = {}\n): ActionReturn<ScrollAnimateActionOptions | undefined> {\n let current = options;\n const { instance, ...opts } = options;\n const sa = getInstance(instance);\n sa.observe(node, liveCallbacks(opts, () => current));\n\n return {\n update(next = {}) {\n current = next;\n const record = sa.getObservedElements().find((r) => r.element === node);\n if (record && !record.animated) {\n const { instance: _ignored, ...nextOpts } = next;\n sa.unobserve(node);\n sa.observe(node, liveCallbacks(nextOpts, () => current));\n }\n },\n destroy() {\n sa.unobserve(node);\n },\n };\n}\n\n/** Stagger the children of `node` when it scrolls into view (`observeChildren: true` also animates children added later). */\nexport function scrollStagger(\n node: Element,\n options: ScrollStaggerActionOptions = {}\n): ActionReturn<ScrollStaggerActionOptions | undefined> {\n const { instance, ...opts } = options;\n const stop = staggerChildren(node, opts, getInstance(instance));\n return { destroy: stop };\n}\n"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;AAYG;AAqBH,IAAI,MAAM,GAAiC,IAAI;AAC/C,MAAM,WAAW,GAAG,CAAC,GAA2B,KAAK,GAAG,IAAI,MAAM,KAAK,MAAM,GAAG,mBAAmB,EAAE,CAAC;AAEtG,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAU;AAExF;AACA,SAAS,aAAa,CAAC,IAAoB,EAAE,MAA4B,EAAA;AACvE,IAAA,MAAM,GAAG,GAAmB,EAAE,GAAG,IAAI,EAAE;AACvC,IAAA,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;AACzB,QAAA,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,UAAU;YAAG,GAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAe,KAAM,MAAM,EAAE,CAAC,IAAI,CAAS,GAAG,GAAG,IAAI,CAAC;AACvH,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,GAAG;AACZ;AAEA;;;;AAIG;SACa,aAAa,CAC3B,IAAa,EACb,UAAsC,EAAE,EAAA;IAExC,IAAI,OAAO,GAAG,OAAO;IACrB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO;AACrC,IAAA,MAAM,EAAE,GAAG,WAAW,CAAC,QAAQ,CAAC;AAChC,IAAA,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC;IAEpD,OAAO;QACL,MAAM,CAAC,IAAI,GAAG,EAAE,EAAA;YACd,OAAO,GAAG,IAAI;YACd,MAAM,MAAM,GAAG,EAAE,CAAC,mBAAmB,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC;AACvE,YAAA,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAC9B,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI;AAChD,gBAAA,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC;AAClB,gBAAA,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC;YAC1D;QACF,CAAC;QACD,OAAO,GAAA;AACL,YAAA,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC;QACpB,CAAC;KACF;AACH;AAEA;SACgB,aAAa,CAC3B,IAAa,EACb,UAAsC,EAAE,EAAA;IAExC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO;AACrC,IAAA,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC/D,IAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAC1B;;;;"}
|
package/dist/vue.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('./chunks/core-CH41ekIo.cjs');
|
|
4
|
+
var stagger = require('./chunks/stagger-XD-0-FQz.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* use-scroll-animate - Vue 3 Integration
|
|
8
|
+
* Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
|
|
9
|
+
*
|
|
10
|
+
* A thin wrapper around the core engine, so it shares its behaviour: `once`,
|
|
11
|
+
* `offset`, custom easing functions, parallax, `prefers-reduced-motion`
|
|
12
|
+
* support, and cleanup on unmount.
|
|
13
|
+
*/
|
|
14
|
+
/** Support refs on components (`$el`) as well as plain elements. */
|
|
15
|
+
function unwrap(value) {
|
|
16
|
+
if (value && typeof Element !== 'undefined' && !(value instanceof Element) && value.$el instanceof Element) {
|
|
17
|
+
return value.$el;
|
|
18
|
+
}
|
|
19
|
+
return value || null;
|
|
20
|
+
}
|
|
21
|
+
function createVueComposables(Vue) {
|
|
22
|
+
// Created lazily on the client so importing on the server is side-effect free.
|
|
23
|
+
let instance = null;
|
|
24
|
+
const getInstance = () => instance || (instance = core.createScrollAnimate());
|
|
25
|
+
function useScrollAnimate(options = {}) {
|
|
26
|
+
const animateRef = Vue.ref(null);
|
|
27
|
+
let el = null;
|
|
28
|
+
Vue.onMounted(() => {
|
|
29
|
+
const target = unwrap(animateRef.value);
|
|
30
|
+
if (!target)
|
|
31
|
+
return;
|
|
32
|
+
el = target;
|
|
33
|
+
getInstance().observe(el, options);
|
|
34
|
+
});
|
|
35
|
+
Vue.onUnmounted(() => {
|
|
36
|
+
if (el)
|
|
37
|
+
getInstance().unobserve(el);
|
|
38
|
+
el = null;
|
|
39
|
+
});
|
|
40
|
+
return { animateRef };
|
|
41
|
+
}
|
|
42
|
+
/** Stagger the children of `staggerRef`; `observeChildren: true` also animates children added later. */
|
|
43
|
+
function useScrollStagger(options = {}) {
|
|
44
|
+
const staggerRef = Vue.ref(null);
|
|
45
|
+
let stop;
|
|
46
|
+
Vue.onMounted(() => {
|
|
47
|
+
const target = unwrap(staggerRef.value);
|
|
48
|
+
if (target)
|
|
49
|
+
stop = stagger.staggerChildren(target, options, getInstance());
|
|
50
|
+
});
|
|
51
|
+
Vue.onUnmounted(() => {
|
|
52
|
+
stop?.();
|
|
53
|
+
stop = undefined;
|
|
54
|
+
});
|
|
55
|
+
return { staggerRef };
|
|
56
|
+
}
|
|
57
|
+
return { useScrollAnimate, useScrollStagger };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.createVueComposables = createVueComposables;
|
|
61
|
+
//# sourceMappingURL=vue.cjs.map
|
package/dist/vue.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.cjs","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":["createScrollAnimate","staggerChildren"],"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,GAAGA,wBAAmB,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,GAAGC,uBAAe,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;;;;"}
|