use-scroll-animate 1.5.0 → 2.0.1
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 +67 -0
- package/README.md +145 -10
- package/README_ja.md +57 -1
- package/README_zh.md +68 -1
- package/dist/{index.esm.js → chunks/core-BP-a1iNc.js} +297 -404
- package/dist/chunks/core-BP-a1iNc.js.map +1 -0
- package/dist/{index.mjs → chunks/core-B_J4rXbC.cjs} +312 -404
- package/dist/chunks/core-B_J4rXbC.cjs.map +1 -0
- package/dist/chunks/stagger-DHw0ExuR.cjs +86 -0
- package/dist/chunks/stagger-DHw0ExuR.cjs.map +1 -0
- package/dist/chunks/stagger-DTv_WiUQ.js +84 -0
- package/dist/chunks/stagger-DTv_WiUQ.js.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} +73 -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} +84 -51
- package/dist/index.d.ts +84 -51
- package/dist/index.js +98 -1133
- 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/solid.d.cts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
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 - Solid integration
|
|
210
|
+
*
|
|
211
|
+
* ```tsx
|
|
212
|
+
* import { scrollAnimate, scrollStagger, useScrollAnimate } from 'use-scroll-animate/solid';
|
|
213
|
+
* false && scrollAnimate; // keep the directive import (TypeScript)
|
|
214
|
+
*
|
|
215
|
+
* <div use:scrollAnimate={{ animation: 'zoom-in' }}>…</div>
|
|
216
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
217
|
+
* <div ref={useScrollAnimate({ animation: 'fade-in-up' })}>…</div>
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* `solid-js` is an optional peer dependency (only needed for this entry).
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
interface SolidScrollAnimateOptions extends AnimateOptions {
|
|
224
|
+
instance?: ScrollAnimateInstance;
|
|
225
|
+
}
|
|
226
|
+
interface SolidScrollStaggerOptions extends StaggerOptions {
|
|
227
|
+
instance?: ScrollAnimateInstance;
|
|
228
|
+
}
|
|
229
|
+
declare module 'solid-js' {
|
|
230
|
+
namespace JSX {
|
|
231
|
+
interface Directives {
|
|
232
|
+
scrollAnimate: SolidScrollAnimateOptions | true;
|
|
233
|
+
scrollStagger: SolidScrollStaggerOptions | true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Directive: `<div use:scrollAnimate={{ animation: 'fade-in' }} />` */
|
|
238
|
+
declare function scrollAnimate(el: Element, accessor?: () => SolidScrollAnimateOptions | true | undefined): void;
|
|
239
|
+
/** Directive: `<ul use:scrollStagger={{ stagger: 60, observeChildren: true }} />` */
|
|
240
|
+
declare function scrollStagger(el: Element, accessor?: () => SolidScrollStaggerOptions | true | undefined): void;
|
|
241
|
+
/** Primitive returning a `ref` callback: `<div ref={useScrollAnimate({ animation: 'fade-in-up' })} />` */
|
|
242
|
+
declare function useScrollAnimate(options?: SolidScrollAnimateOptions): (el: Element) => void;
|
|
243
|
+
|
|
244
|
+
export { scrollAnimate, scrollStagger, useScrollAnimate };
|
|
245
|
+
export type { SolidScrollAnimateOptions, SolidScrollStaggerOptions };
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
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 - Solid integration
|
|
210
|
+
*
|
|
211
|
+
* ```tsx
|
|
212
|
+
* import { scrollAnimate, scrollStagger, useScrollAnimate } from 'use-scroll-animate/solid';
|
|
213
|
+
* false && scrollAnimate; // keep the directive import (TypeScript)
|
|
214
|
+
*
|
|
215
|
+
* <div use:scrollAnimate={{ animation: 'zoom-in' }}>…</div>
|
|
216
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
217
|
+
* <div ref={useScrollAnimate({ animation: 'fade-in-up' })}>…</div>
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* `solid-js` is an optional peer dependency (only needed for this entry).
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
interface SolidScrollAnimateOptions extends AnimateOptions {
|
|
224
|
+
instance?: ScrollAnimateInstance;
|
|
225
|
+
}
|
|
226
|
+
interface SolidScrollStaggerOptions extends StaggerOptions {
|
|
227
|
+
instance?: ScrollAnimateInstance;
|
|
228
|
+
}
|
|
229
|
+
declare module 'solid-js' {
|
|
230
|
+
namespace JSX {
|
|
231
|
+
interface Directives {
|
|
232
|
+
scrollAnimate: SolidScrollAnimateOptions | true;
|
|
233
|
+
scrollStagger: SolidScrollStaggerOptions | true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Directive: `<div use:scrollAnimate={{ animation: 'fade-in' }} />` */
|
|
238
|
+
declare function scrollAnimate(el: Element, accessor?: () => SolidScrollAnimateOptions | true | undefined): void;
|
|
239
|
+
/** Directive: `<ul use:scrollStagger={{ stagger: 60, observeChildren: true }} />` */
|
|
240
|
+
declare function scrollStagger(el: Element, accessor?: () => SolidScrollStaggerOptions | true | undefined): void;
|
|
241
|
+
/** Primitive returning a `ref` callback: `<div ref={useScrollAnimate({ animation: 'fade-in-up' })} />` */
|
|
242
|
+
declare function useScrollAnimate(options?: SolidScrollAnimateOptions): (el: Element) => void;
|
|
243
|
+
|
|
244
|
+
export { scrollAnimate, scrollStagger, useScrollAnimate };
|
|
245
|
+
export type { SolidScrollAnimateOptions, SolidScrollStaggerOptions };
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { onMount, onCleanup } from 'solid-js';
|
|
2
|
+
import { c as createScrollAnimate } from './chunks/core-BP-a1iNc.js';
|
|
3
|
+
import { s as staggerChildren } from './chunks/stagger-DTv_WiUQ.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* use-scroll-animate - Solid integration
|
|
7
|
+
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { scrollAnimate, scrollStagger, useScrollAnimate } from 'use-scroll-animate/solid';
|
|
10
|
+
* false && scrollAnimate; // keep the directive import (TypeScript)
|
|
11
|
+
*
|
|
12
|
+
* <div use:scrollAnimate={{ animation: 'zoom-in' }}>…</div>
|
|
13
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
14
|
+
* <div ref={useScrollAnimate({ animation: 'fade-in-up' })}>…</div>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* `solid-js` is an optional peer dependency (only needed for this entry).
|
|
18
|
+
*/
|
|
19
|
+
let shared = null;
|
|
20
|
+
const getInstance = (own) => own || shared || (shared = createScrollAnimate());
|
|
21
|
+
function read(accessor) {
|
|
22
|
+
const v = accessor?.();
|
|
23
|
+
return (v && v !== true ? v : {});
|
|
24
|
+
}
|
|
25
|
+
function observe(el, options) {
|
|
26
|
+
const { instance, ...opts } = options;
|
|
27
|
+
const sa = getInstance(instance);
|
|
28
|
+
// Wait until the element is in the document (directives/refs run before insertion).
|
|
29
|
+
onMount(() => sa.observe(el, opts));
|
|
30
|
+
onCleanup(() => sa.unobserve(el));
|
|
31
|
+
}
|
|
32
|
+
/** Directive: `<div use:scrollAnimate={{ animation: 'fade-in' }} />` */
|
|
33
|
+
function scrollAnimate(el, accessor) {
|
|
34
|
+
observe(el, read(accessor));
|
|
35
|
+
}
|
|
36
|
+
/** Directive: `<ul use:scrollStagger={{ stagger: 60, observeChildren: true }} />` */
|
|
37
|
+
function scrollStagger(el, accessor) {
|
|
38
|
+
const { instance, ...opts } = read(accessor);
|
|
39
|
+
let stop;
|
|
40
|
+
onMount(() => {
|
|
41
|
+
stop = staggerChildren(el, opts, getInstance(instance));
|
|
42
|
+
});
|
|
43
|
+
onCleanup(() => stop?.());
|
|
44
|
+
}
|
|
45
|
+
/** Primitive returning a `ref` callback: `<div ref={useScrollAnimate({ animation: 'fade-in-up' })} />` */
|
|
46
|
+
function useScrollAnimate(options = {}) {
|
|
47
|
+
let el;
|
|
48
|
+
const { instance, ...opts } = options;
|
|
49
|
+
const sa = getInstance(instance);
|
|
50
|
+
onMount(() => el && sa.observe(el, opts));
|
|
51
|
+
onCleanup(() => el && sa.unobserve(el));
|
|
52
|
+
return (node) => {
|
|
53
|
+
el = node;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { scrollAnimate, scrollStagger, useScrollAnimate };
|
|
58
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.js","sources":["../src/solid.ts"],"sourcesContent":["/**\n * use-scroll-animate - Solid integration\n *\n * ```tsx\n * import { scrollAnimate, scrollStagger, useScrollAnimate } from 'use-scroll-animate/solid';\n * false && scrollAnimate; // keep the directive import (TypeScript)\n *\n * <div use:scrollAnimate={{ animation: 'zoom-in' }}>…</div>\n * <ul use:scrollStagger={{ stagger: 60 }}>…</ul>\n * <div ref={useScrollAnimate({ animation: 'fade-in-up' })}>…</div>\n * ```\n *\n * `solid-js` is an optional peer dependency (only needed for this entry).\n */\n\nimport { onCleanup, onMount } from 'solid-js';\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate } from './core';\nimport { staggerChildren, type StaggerOptions } from './stagger';\n\nexport interface SolidScrollAnimateOptions extends AnimateOptions {\n instance?: ScrollAnimateInstance;\n}\nexport interface SolidScrollStaggerOptions extends StaggerOptions {\n instance?: ScrollAnimateInstance;\n}\n\ndeclare module 'solid-js' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface Directives {\n scrollAnimate: SolidScrollAnimateOptions | true;\n scrollStagger: SolidScrollStaggerOptions | true;\n }\n }\n}\n\nlet shared: ScrollAnimateInstance | null = null;\nconst getInstance = (own?: ScrollAnimateInstance) => own || shared || (shared = createScrollAnimate());\n\nfunction read<T>(accessor?: () => T | true | undefined): T {\n const v = accessor?.();\n return (v && v !== true ? v : {}) as T;\n}\n\nfunction observe(el: Element, options: SolidScrollAnimateOptions): void {\n const { instance, ...opts } = options;\n const sa = getInstance(instance);\n // Wait until the element is in the document (directives/refs run before insertion).\n onMount(() => sa.observe(el, opts));\n onCleanup(() => sa.unobserve(el));\n}\n\n/** Directive: `<div use:scrollAnimate={{ animation: 'fade-in' }} />` */\nexport function scrollAnimate(el: Element, accessor?: () => SolidScrollAnimateOptions | true | undefined): void {\n observe(el, read(accessor));\n}\n\n/** Directive: `<ul use:scrollStagger={{ stagger: 60, observeChildren: true }} />` */\nexport function scrollStagger(el: Element, accessor?: () => SolidScrollStaggerOptions | true | undefined): void {\n const { instance, ...opts } = read<SolidScrollStaggerOptions>(accessor);\n let stop: (() => void) | undefined;\n onMount(() => {\n stop = staggerChildren(el, opts, getInstance(instance));\n });\n onCleanup(() => stop?.());\n}\n\n/** Primitive returning a `ref` callback: `<div ref={useScrollAnimate({ animation: 'fade-in-up' })} />` */\nexport function useScrollAnimate(options: SolidScrollAnimateOptions = {}): (el: Element) => void {\n let el: Element | undefined;\n const { instance, ...opts } = options;\n const sa = getInstance(instance);\n onMount(() => el && sa.observe(el, opts));\n onCleanup(() => el && sa.unobserve(el));\n return (node: Element) => {\n el = node;\n };\n}\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;AAaG;AAwBH,IAAI,MAAM,GAAiC,IAAI;AAC/C,MAAM,WAAW,GAAG,CAAC,GAA2B,KAAK,GAAG,IAAI,MAAM,KAAK,MAAM,GAAG,mBAAmB,EAAE,CAAC;AAEtG,SAAS,IAAI,CAAI,QAAqC,EAAA;AACpD,IAAA,MAAM,CAAC,GAAG,QAAQ,IAAI;AACtB,IAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,EAAE;AAClC;AAEA,SAAS,OAAO,CAAC,EAAW,EAAE,OAAkC,EAAA;IAC9D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO;AACrC,IAAA,MAAM,EAAE,GAAG,WAAW,CAAC,QAAQ,CAAC;;AAEhC,IAAA,OAAO,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACnC,SAAS,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACnC;AAEA;AACM,SAAU,aAAa,CAAC,EAAW,EAAE,QAA6D,EAAA;IACtG,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7B;AAEA;AACM,SAAU,aAAa,CAAC,EAAW,EAAE,QAA6D,EAAA;IACtG,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAA4B,QAAQ,CAAC;AACvE,IAAA,IAAI,IAA8B;IAClC,OAAO,CAAC,MAAK;AACX,QAAA,IAAI,GAAG,eAAe,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;AACzD,IAAA,CAAC,CAAC;IACF,SAAS,CAAC,MAAM,IAAI,IAAI,CAAC;AAC3B;AAEA;AACM,SAAU,gBAAgB,CAAC,OAAA,GAAqC,EAAE,EAAA;AACtE,IAAA,IAAI,EAAuB;IAC3B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO;AACrC,IAAA,MAAM,EAAE,GAAG,WAAW,CAAC,QAAQ,CAAC;AAChC,IAAA,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACzC,IAAA,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACvC,OAAO,CAAC,IAAa,KAAI;QACvB,EAAE,GAAG,IAAI;AACX,IAAA,CAAC;AACH;;;;"}
|
package/dist/svelte.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('./chunks/core-B_J4rXbC.cjs');
|
|
4
|
+
var stagger = require('./chunks/stagger-DHw0ExuR.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* use-scroll-animate - Svelte integration
|
|
8
|
+
*
|
|
9
|
+
* Svelte actions (no import from `svelte` needed, works with Svelte 3, 4 and 5):
|
|
10
|
+
*
|
|
11
|
+
* ```svelte
|
|
12
|
+
* <script>
|
|
13
|
+
* import { scrollAnimate, scrollStagger } from 'use-scroll-animate/svelte';
|
|
14
|
+
* </script>
|
|
15
|
+
* <div use:scrollAnimate={{ animation: 'fade-in-up', duration: 800 }}>…</div>
|
|
16
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
let shared = null;
|
|
20
|
+
const getInstance = (own) => own || shared || (shared = core.createScrollAnimate());
|
|
21
|
+
const CALLBACKS = ['onStart', 'onComplete', 'onEnter', 'onLeave', 'onProgress'];
|
|
22
|
+
/** Callbacks always call the latest parameter's version. */
|
|
23
|
+
function liveCallbacks(opts, latest) {
|
|
24
|
+
const out = { ...opts };
|
|
25
|
+
CALLBACKS.forEach((name) => {
|
|
26
|
+
if (typeof opts[name] === 'function')
|
|
27
|
+
out[name] = (...args) => latest()[name]?.(...args);
|
|
28
|
+
});
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Animate `node` when it scrolls into view. Changing the parameter updates the
|
|
33
|
+
* callbacks right away; other options are applied if the element has not
|
|
34
|
+
* animated yet.
|
|
35
|
+
*/
|
|
36
|
+
function scrollAnimate(node, options = {}) {
|
|
37
|
+
let current = options;
|
|
38
|
+
const { instance, ...opts } = options;
|
|
39
|
+
const sa = getInstance(instance);
|
|
40
|
+
sa.observe(node, liveCallbacks(opts, () => current));
|
|
41
|
+
return {
|
|
42
|
+
update(next = {}) {
|
|
43
|
+
current = next;
|
|
44
|
+
const record = sa.getObservedElements().find((r) => r.element === node);
|
|
45
|
+
if (record && !record.animated) {
|
|
46
|
+
const { instance: _ignored, ...nextOpts } = next;
|
|
47
|
+
sa.unobserve(node);
|
|
48
|
+
sa.observe(node, liveCallbacks(nextOpts, () => current));
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
destroy() {
|
|
52
|
+
sa.unobserve(node);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Stagger the children of `node` when it scrolls into view (`observeChildren: true` also animates children added later). */
|
|
57
|
+
function scrollStagger(node, options = {}) {
|
|
58
|
+
const { instance, ...opts } = options;
|
|
59
|
+
const stop = stagger.staggerChildren(node, opts, getInstance(instance));
|
|
60
|
+
return { destroy: stop };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.scrollAnimate = scrollAnimate;
|
|
64
|
+
exports.scrollStagger = scrollStagger;
|
|
65
|
+
//# sourceMappingURL=svelte.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.cjs","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":["createScrollAnimate","staggerChildren"],"mappings":";;;;;AAAA;;;;;;;;;;;;AAYG;AAqBH,IAAI,MAAM,GAAiC,IAAI;AAC/C,MAAM,WAAW,GAAG,CAAC,GAA2B,KAAK,GAAG,IAAI,MAAM,KAAK,MAAM,GAAGA,wBAAmB,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,GAAGC,uBAAe,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC/D,IAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAC1B;;;;;"}
|