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
|
@@ -11,6 +11,17 @@ type AnimationPreset = 'fade-in' | 'fade-in-up' | 'fade-in-down' | 'fade-in-left
|
|
|
11
11
|
* viewport and 1 when its bottom leaves the top. Works for elements taller than the screen.
|
|
12
12
|
*/
|
|
13
13
|
type ProgressMode = 'ratio' | 'scroll';
|
|
14
|
+
/**
|
|
15
|
+
* Which engine runs the entrance animation.
|
|
16
|
+
* - `'js'`: IntersectionObserver triggers a time-based Web Animation.
|
|
17
|
+
* - `'css'`: the preset runs on the browser's native scroll-driven timeline
|
|
18
|
+
* (`animation-timeline: view()`), so its progress follows the scroll position
|
|
19
|
+
* off the main thread. Falls back to `'js'` where unsupported.
|
|
20
|
+
* - `'auto'` (default since 2.0): native when supported, JS otherwise — and JS
|
|
21
|
+
* whenever the element sets `duration`, `delay`, `offset` or `stagger` itself,
|
|
22
|
+
* since those only mean something for a time-based animation.
|
|
23
|
+
*/
|
|
24
|
+
type ScrollEngine = 'auto' | 'js' | 'css';
|
|
14
25
|
/** Easing function types */
|
|
15
26
|
type EasingType = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'soft-spring' | 'heavy-bounce' | [number, number, number, number] | ((t: number) => number) | string;
|
|
16
27
|
/** Keyframe definition for custom animations */
|
|
@@ -71,6 +82,32 @@ interface AnimateOptions {
|
|
|
71
82
|
onProgress?: (element: Element, progress: number) => void;
|
|
72
83
|
/** How progress for `onProgress`/parallax is measured (default: 'ratio') */
|
|
73
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;
|
|
74
111
|
}
|
|
75
112
|
/** Global configuration for ScrollAnimate instance */
|
|
76
113
|
interface ScrollAnimateConfig {
|
|
@@ -109,6 +146,8 @@ interface ScrollAnimateConfig {
|
|
|
109
146
|
* never re-hide or replay them. (default: true)
|
|
110
147
|
*/
|
|
111
148
|
autoUnregister?: boolean;
|
|
149
|
+
/** Default animation engine (default: `'auto'`; `'js'` restores the 1.x behaviour) */
|
|
150
|
+
defaultEngine?: ScrollEngine;
|
|
112
151
|
}
|
|
113
152
|
/** Registered element entry */
|
|
114
153
|
interface AnimatedElement {
|
|
@@ -117,6 +156,8 @@ interface AnimatedElement {
|
|
|
117
156
|
observer: IntersectionObserver;
|
|
118
157
|
animated: boolean;
|
|
119
158
|
progressObserver?: IntersectionObserver;
|
|
159
|
+
/** Engine actually used for this element (`'css'` = native scroll-driven timeline) */
|
|
160
|
+
engine?: 'js' | 'css';
|
|
120
161
|
}
|
|
121
162
|
/** ScrollAnimate public API */
|
|
122
163
|
interface ScrollAnimateInstance {
|
|
@@ -126,6 +167,14 @@ interface ScrollAnimateInstance {
|
|
|
126
167
|
unobserve(target: string | Element | NodeList | Element[]): void;
|
|
127
168
|
/** Observe all elements matching the data-sa attribute */
|
|
128
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;
|
|
129
178
|
/** Destroy the instance and clean up all observers */
|
|
130
179
|
destroy(): void;
|
|
131
180
|
/** Refresh all observers (useful after DOM changes) */
|
|
@@ -144,6 +193,12 @@ interface ScrollAnimateInstance {
|
|
|
144
193
|
* high-performance scroll-triggered animations.
|
|
145
194
|
*/
|
|
146
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Whether the browser can run presets on a native scroll-driven timeline:
|
|
198
|
+
* `CSS.supports('animation-timeline: view()')` plus the `ViewTimeline`
|
|
199
|
+
* constructor used to attach it from JavaScript. Cached. SSR-safe.
|
|
200
|
+
*/
|
|
201
|
+
declare function supportsScrollTimeline(): boolean;
|
|
147
202
|
/**
|
|
148
203
|
* True scroll progress of `el` through the viewport (or `root`): 0 when its top
|
|
149
204
|
* edge reaches the bottom of the viewport, 1 when its bottom edge passes the top.
|
|
@@ -217,6 +272,47 @@ interface SequenceController {
|
|
|
217
272
|
*/
|
|
218
273
|
declare function sequence(steps: SequenceStep[], options?: SequenceOptions): SequenceController;
|
|
219
274
|
|
|
275
|
+
/**
|
|
276
|
+
* use-scroll-animate - parallax() helper
|
|
277
|
+
*
|
|
278
|
+
* Moves elements at a different speed than the page while they cross the
|
|
279
|
+
* viewport. Built on the same scroll progress as `progressVar` (0 when the
|
|
280
|
+
* element's top enters at the bottom, 1 when its bottom leaves at the top):
|
|
281
|
+
* the progress is written to a CSS custom property (default `--sa-parallax`)
|
|
282
|
+
* and the offset is applied with the individual `translate` property, so it
|
|
283
|
+
* composes with entrance animations and other `transform`s.
|
|
284
|
+
*/
|
|
285
|
+
interface ParallaxHelperOptions {
|
|
286
|
+
/**
|
|
287
|
+
* Total distance the element shifts while it crosses the viewport, as a
|
|
288
|
+
* fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values
|
|
289
|
+
* lag behind the scroll (background-like), negative values move ahead of it
|
|
290
|
+
* (foreground-like). (default: `0.2`)
|
|
291
|
+
*/
|
|
292
|
+
speed?: number;
|
|
293
|
+
/** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */
|
|
294
|
+
axis?: 'x' | 'y';
|
|
295
|
+
/** CSS custom property receiving the progress (default: `'--sa-parallax'`) */
|
|
296
|
+
progressVar?: string;
|
|
297
|
+
/** Scroll container (default: the viewport) */
|
|
298
|
+
root?: Element | null;
|
|
299
|
+
/**
|
|
300
|
+
* Under `prefers-reduced-motion: reduce` no offset is applied (the progress
|
|
301
|
+
* variable is still written). Set to `false` to move anyway. (default: `true`)
|
|
302
|
+
*/
|
|
303
|
+
respectReducedMotion?: boolean;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Apply a scroll parallax to `target` (selector, Element, NodeList or array).
|
|
307
|
+
* Returns a function that stops it and removes the inline styles it set.
|
|
308
|
+
* SSR-safe (no-op without a DOM / IntersectionObserver).
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* const stop = parallax('.hero-bg', { speed: 0.3 });
|
|
312
|
+
* parallax('.badge', { speed: -0.15, axis: 'x' });
|
|
313
|
+
*/
|
|
314
|
+
declare function parallax(target: string | Element | NodeList | Element[], options?: ParallaxHelperOptions): () => void;
|
|
315
|
+
|
|
220
316
|
/**
|
|
221
317
|
* use-scroll-animate - Animation Presets
|
|
222
318
|
* Defines keyframes for all built-in animation presets
|
|
@@ -232,55 +328,6 @@ declare function resolvePreset(animation: AnimationPreset | AnimationPreset[] |
|
|
|
232
328
|
declare const EASING_MAP: Record<string, string>;
|
|
233
329
|
declare function resolveEasing(easing: EasingType): string;
|
|
234
330
|
|
|
235
|
-
/**
|
|
236
|
-
* use-scroll-animate - React Integration
|
|
237
|
-
* Provides useScrollAnimate and useScrollStagger hooks for React applications.
|
|
238
|
-
* `useScrollStagger({ observeChildren: true })` also animates children added later.
|
|
239
|
-
*
|
|
240
|
-
* Both hooks are thin wrappers around the core engine, so they share its
|
|
241
|
-
* behaviour: `once`, `offset`, custom easing functions, parallax,
|
|
242
|
-
* `prefers-reduced-motion` support, and proper cleanup on unmount.
|
|
243
|
-
*/
|
|
244
|
-
|
|
245
|
-
type ReactRef<T> = {
|
|
246
|
-
current: T | null;
|
|
247
|
-
};
|
|
248
|
-
declare function createReactHooks(React: {
|
|
249
|
-
useRef: <T>(initial: T | null) => ReactRef<T>;
|
|
250
|
-
useEffect: (effect: () => (() => void) | void, deps?: unknown[]) => void;
|
|
251
|
-
}): {
|
|
252
|
-
useScrollAnimate: (options?: AnimateOptions) => ReactRef<Element>;
|
|
253
|
-
useScrollStagger: (options?: StaggerOptions) => ReactRef<Element>;
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* use-scroll-animate - Vue 3 Integration
|
|
258
|
-
* Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
|
|
259
|
-
*
|
|
260
|
-
* A thin wrapper around the core engine, so it shares its behaviour: `once`,
|
|
261
|
-
* `offset`, custom easing functions, parallax, `prefers-reduced-motion`
|
|
262
|
-
* support, and cleanup on unmount.
|
|
263
|
-
*/
|
|
264
|
-
|
|
265
|
-
declare function createVueComposables(Vue: {
|
|
266
|
-
ref: <T>(value: T | null) => {
|
|
267
|
-
value: T | null;
|
|
268
|
-
};
|
|
269
|
-
onMounted: (fn: () => void) => void;
|
|
270
|
-
onUnmounted: (fn: () => void) => void;
|
|
271
|
-
}): {
|
|
272
|
-
useScrollAnimate: (options?: AnimateOptions) => {
|
|
273
|
-
animateRef: {
|
|
274
|
-
value: Element | null;
|
|
275
|
-
};
|
|
276
|
-
};
|
|
277
|
-
useScrollStagger: (options?: StaggerOptions) => {
|
|
278
|
-
staggerRef: {
|
|
279
|
-
value: Element | null;
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
|
|
284
331
|
/**
|
|
285
332
|
* Default singleton instance of ScrollAnimate.
|
|
286
333
|
* Ready to use out of the box with sensible defaults.
|
|
@@ -298,5 +345,5 @@ declare function createVueComposables(Vue: {
|
|
|
298
345
|
*/
|
|
299
346
|
declare const ScrollAnimate: ScrollAnimateInstance;
|
|
300
347
|
|
|
301
|
-
export { EASING_MAP, PRESETS,
|
|
302
|
-
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };
|
|
348
|
+
export { EASING_MAP, PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing, resolvePreset, sequence, staggerChildren, supportsScrollTimeline };
|
|
349
|
+
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,17 @@ type AnimationPreset = 'fade-in' | 'fade-in-up' | 'fade-in-down' | 'fade-in-left
|
|
|
11
11
|
* viewport and 1 when its bottom leaves the top. Works for elements taller than the screen.
|
|
12
12
|
*/
|
|
13
13
|
type ProgressMode = 'ratio' | 'scroll';
|
|
14
|
+
/**
|
|
15
|
+
* Which engine runs the entrance animation.
|
|
16
|
+
* - `'js'`: IntersectionObserver triggers a time-based Web Animation.
|
|
17
|
+
* - `'css'`: the preset runs on the browser's native scroll-driven timeline
|
|
18
|
+
* (`animation-timeline: view()`), so its progress follows the scroll position
|
|
19
|
+
* off the main thread. Falls back to `'js'` where unsupported.
|
|
20
|
+
* - `'auto'` (default since 2.0): native when supported, JS otherwise — and JS
|
|
21
|
+
* whenever the element sets `duration`, `delay`, `offset` or `stagger` itself,
|
|
22
|
+
* since those only mean something for a time-based animation.
|
|
23
|
+
*/
|
|
24
|
+
type ScrollEngine = 'auto' | 'js' | 'css';
|
|
14
25
|
/** Easing function types */
|
|
15
26
|
type EasingType = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'soft-spring' | 'heavy-bounce' | [number, number, number, number] | ((t: number) => number) | string;
|
|
16
27
|
/** Keyframe definition for custom animations */
|
|
@@ -71,6 +82,32 @@ interface AnimateOptions {
|
|
|
71
82
|
onProgress?: (element: Element, progress: number) => void;
|
|
72
83
|
/** How progress for `onProgress`/parallax is measured (default: 'ratio') */
|
|
73
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;
|
|
74
111
|
}
|
|
75
112
|
/** Global configuration for ScrollAnimate instance */
|
|
76
113
|
interface ScrollAnimateConfig {
|
|
@@ -109,6 +146,8 @@ interface ScrollAnimateConfig {
|
|
|
109
146
|
* never re-hide or replay them. (default: true)
|
|
110
147
|
*/
|
|
111
148
|
autoUnregister?: boolean;
|
|
149
|
+
/** Default animation engine (default: `'auto'`; `'js'` restores the 1.x behaviour) */
|
|
150
|
+
defaultEngine?: ScrollEngine;
|
|
112
151
|
}
|
|
113
152
|
/** Registered element entry */
|
|
114
153
|
interface AnimatedElement {
|
|
@@ -117,6 +156,8 @@ interface AnimatedElement {
|
|
|
117
156
|
observer: IntersectionObserver;
|
|
118
157
|
animated: boolean;
|
|
119
158
|
progressObserver?: IntersectionObserver;
|
|
159
|
+
/** Engine actually used for this element (`'css'` = native scroll-driven timeline) */
|
|
160
|
+
engine?: 'js' | 'css';
|
|
120
161
|
}
|
|
121
162
|
/** ScrollAnimate public API */
|
|
122
163
|
interface ScrollAnimateInstance {
|
|
@@ -126,6 +167,14 @@ interface ScrollAnimateInstance {
|
|
|
126
167
|
unobserve(target: string | Element | NodeList | Element[]): void;
|
|
127
168
|
/** Observe all elements matching the data-sa attribute */
|
|
128
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;
|
|
129
178
|
/** Destroy the instance and clean up all observers */
|
|
130
179
|
destroy(): void;
|
|
131
180
|
/** Refresh all observers (useful after DOM changes) */
|
|
@@ -144,6 +193,12 @@ interface ScrollAnimateInstance {
|
|
|
144
193
|
* high-performance scroll-triggered animations.
|
|
145
194
|
*/
|
|
146
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Whether the browser can run presets on a native scroll-driven timeline:
|
|
198
|
+
* `CSS.supports('animation-timeline: view()')` plus the `ViewTimeline`
|
|
199
|
+
* constructor used to attach it from JavaScript. Cached. SSR-safe.
|
|
200
|
+
*/
|
|
201
|
+
declare function supportsScrollTimeline(): boolean;
|
|
147
202
|
/**
|
|
148
203
|
* True scroll progress of `el` through the viewport (or `root`): 0 when its top
|
|
149
204
|
* edge reaches the bottom of the viewport, 1 when its bottom edge passes the top.
|
|
@@ -217,6 +272,47 @@ interface SequenceController {
|
|
|
217
272
|
*/
|
|
218
273
|
declare function sequence(steps: SequenceStep[], options?: SequenceOptions): SequenceController;
|
|
219
274
|
|
|
275
|
+
/**
|
|
276
|
+
* use-scroll-animate - parallax() helper
|
|
277
|
+
*
|
|
278
|
+
* Moves elements at a different speed than the page while they cross the
|
|
279
|
+
* viewport. Built on the same scroll progress as `progressVar` (0 when the
|
|
280
|
+
* element's top enters at the bottom, 1 when its bottom leaves at the top):
|
|
281
|
+
* the progress is written to a CSS custom property (default `--sa-parallax`)
|
|
282
|
+
* and the offset is applied with the individual `translate` property, so it
|
|
283
|
+
* composes with entrance animations and other `transform`s.
|
|
284
|
+
*/
|
|
285
|
+
interface ParallaxHelperOptions {
|
|
286
|
+
/**
|
|
287
|
+
* Total distance the element shifts while it crosses the viewport, as a
|
|
288
|
+
* fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values
|
|
289
|
+
* lag behind the scroll (background-like), negative values move ahead of it
|
|
290
|
+
* (foreground-like). (default: `0.2`)
|
|
291
|
+
*/
|
|
292
|
+
speed?: number;
|
|
293
|
+
/** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */
|
|
294
|
+
axis?: 'x' | 'y';
|
|
295
|
+
/** CSS custom property receiving the progress (default: `'--sa-parallax'`) */
|
|
296
|
+
progressVar?: string;
|
|
297
|
+
/** Scroll container (default: the viewport) */
|
|
298
|
+
root?: Element | null;
|
|
299
|
+
/**
|
|
300
|
+
* Under `prefers-reduced-motion: reduce` no offset is applied (the progress
|
|
301
|
+
* variable is still written). Set to `false` to move anyway. (default: `true`)
|
|
302
|
+
*/
|
|
303
|
+
respectReducedMotion?: boolean;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Apply a scroll parallax to `target` (selector, Element, NodeList or array).
|
|
307
|
+
* Returns a function that stops it and removes the inline styles it set.
|
|
308
|
+
* SSR-safe (no-op without a DOM / IntersectionObserver).
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* const stop = parallax('.hero-bg', { speed: 0.3 });
|
|
312
|
+
* parallax('.badge', { speed: -0.15, axis: 'x' });
|
|
313
|
+
*/
|
|
314
|
+
declare function parallax(target: string | Element | NodeList | Element[], options?: ParallaxHelperOptions): () => void;
|
|
315
|
+
|
|
220
316
|
/**
|
|
221
317
|
* use-scroll-animate - Animation Presets
|
|
222
318
|
* Defines keyframes for all built-in animation presets
|
|
@@ -232,55 +328,6 @@ declare function resolvePreset(animation: AnimationPreset | AnimationPreset[] |
|
|
|
232
328
|
declare const EASING_MAP: Record<string, string>;
|
|
233
329
|
declare function resolveEasing(easing: EasingType): string;
|
|
234
330
|
|
|
235
|
-
/**
|
|
236
|
-
* use-scroll-animate - React Integration
|
|
237
|
-
* Provides useScrollAnimate and useScrollStagger hooks for React applications.
|
|
238
|
-
* `useScrollStagger({ observeChildren: true })` also animates children added later.
|
|
239
|
-
*
|
|
240
|
-
* Both hooks are thin wrappers around the core engine, so they share its
|
|
241
|
-
* behaviour: `once`, `offset`, custom easing functions, parallax,
|
|
242
|
-
* `prefers-reduced-motion` support, and proper cleanup on unmount.
|
|
243
|
-
*/
|
|
244
|
-
|
|
245
|
-
type ReactRef<T> = {
|
|
246
|
-
current: T | null;
|
|
247
|
-
};
|
|
248
|
-
declare function createReactHooks(React: {
|
|
249
|
-
useRef: <T>(initial: T | null) => ReactRef<T>;
|
|
250
|
-
useEffect: (effect: () => (() => void) | void, deps?: unknown[]) => void;
|
|
251
|
-
}): {
|
|
252
|
-
useScrollAnimate: (options?: AnimateOptions) => ReactRef<Element>;
|
|
253
|
-
useScrollStagger: (options?: StaggerOptions) => ReactRef<Element>;
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* use-scroll-animate - Vue 3 Integration
|
|
258
|
-
* Provides useScrollAnimate and useScrollStagger composables for Vue 3 applications.
|
|
259
|
-
*
|
|
260
|
-
* A thin wrapper around the core engine, so it shares its behaviour: `once`,
|
|
261
|
-
* `offset`, custom easing functions, parallax, `prefers-reduced-motion`
|
|
262
|
-
* support, and cleanup on unmount.
|
|
263
|
-
*/
|
|
264
|
-
|
|
265
|
-
declare function createVueComposables(Vue: {
|
|
266
|
-
ref: <T>(value: T | null) => {
|
|
267
|
-
value: T | null;
|
|
268
|
-
};
|
|
269
|
-
onMounted: (fn: () => void) => void;
|
|
270
|
-
onUnmounted: (fn: () => void) => void;
|
|
271
|
-
}): {
|
|
272
|
-
useScrollAnimate: (options?: AnimateOptions) => {
|
|
273
|
-
animateRef: {
|
|
274
|
-
value: Element | null;
|
|
275
|
-
};
|
|
276
|
-
};
|
|
277
|
-
useScrollStagger: (options?: StaggerOptions) => {
|
|
278
|
-
staggerRef: {
|
|
279
|
-
value: Element | null;
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
|
|
284
331
|
/**
|
|
285
332
|
* Default singleton instance of ScrollAnimate.
|
|
286
333
|
* Ready to use out of the box with sensible defaults.
|
|
@@ -298,5 +345,5 @@ declare function createVueComposables(Vue: {
|
|
|
298
345
|
*/
|
|
299
346
|
declare const ScrollAnimate: ScrollAnimateInstance;
|
|
300
347
|
|
|
301
|
-
export { EASING_MAP, PRESETS,
|
|
302
|
-
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };
|
|
348
|
+
export { EASING_MAP, PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing, resolvePreset, sequence, staggerChildren, supportsScrollTimeline };
|
|
349
|
+
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ParallaxOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine, SequenceController, SequenceOptions, SequenceStep, StaggerOptions };
|