use-scroll-animate 3.9.0 → 4.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 +40 -0
- package/README.md +16 -14
- package/README_ja.md +10 -11
- package/README_zh.md +11 -12
- package/dist/chunks/{base-Dm6ee5ug.cjs → base-CXx7jZ-o.cjs} +1 -11
- package/dist/chunks/{base-Dm6ee5ug.cjs.map → base-CXx7jZ-o.cjs.map} +1 -1
- package/dist/chunks/{base-BRIPyPtX.js → base-ZARFccur.js} +2 -11
- package/dist/chunks/{base-BRIPyPtX.js.map → base-ZARFccur.js.map} +1 -1
- package/dist/chunks/core-Co-6AL0h.js +218 -0
- package/dist/chunks/core-Co-6AL0h.js.map +1 -0
- package/dist/chunks/{core-CYozf_E-.js → core-DKY-fVzR.js} +2 -2
- package/dist/chunks/{core-CYozf_E-.js.map → core-DKY-fVzR.js.map} +1 -1
- package/dist/chunks/core-DXqZm5Il.cjs +222 -0
- package/dist/chunks/core-DXqZm5Il.cjs.map +1 -0
- package/dist/chunks/{core-CHAtivHV.cjs → core-IaorbTdu.cjs} +2 -2
- package/dist/chunks/{core-CHAtivHV.cjs.map → core-IaorbTdu.cjs.map} +1 -1
- package/dist/chunks/{index-tags-BmQR17Sb.js → index-tags-43Xtd01A.js} +2 -2
- package/dist/chunks/index-tags-43Xtd01A.js.map +1 -0
- package/dist/chunks/{index-tags-DYYsgbba.cjs → index-tags-BQh_uGqH.cjs} +2 -2
- package/dist/chunks/index-tags-BQh_uGqH.cjs.map +1 -0
- package/dist/chunks/{spring-Dp5BllPB.cjs → spring-2OTnYCzm.cjs} +2 -2
- package/dist/chunks/{spring-Dp5BllPB.cjs.map → spring-2OTnYCzm.cjs.map} +1 -1
- package/dist/chunks/{spring-UBPhrh1X.js → spring-E2ickYNI.js} +2 -2
- package/dist/chunks/{spring-UBPhrh1X.js.map → spring-E2ickYNI.js.map} +1 -1
- package/dist/chunks/{variants-_dC-ey6R.cjs → variants-BNIrn4ch.cjs} +2 -2
- package/dist/chunks/{variants-_dC-ey6R.cjs.map → variants-BNIrn4ch.cjs.map} +1 -1
- package/dist/chunks/{variants-DTypaOH3.js → variants-DvnxvRCM.js} +2 -2
- package/dist/chunks/{variants-DTypaOH3.js.map → variants-DvnxvRCM.js.map} +1 -1
- package/dist/components/angular.cjs +6 -5
- package/dist/components/angular.cjs.map +1 -1
- package/dist/components/angular.d.cts +4 -17
- package/dist/components/angular.d.ts +4 -17
- package/dist/components/angular.js +6 -5
- package/dist/components/angular.js.map +1 -1
- package/dist/components/background.cjs +2 -2
- package/dist/components/background.js +3 -3
- package/dist/components/cards.cjs +2 -2
- package/dist/components/cards.js +3 -3
- package/dist/components/click.cjs +2 -2
- package/dist/components/click.js +3 -3
- package/dist/components/depth.cjs +3 -3
- package/dist/components/depth.js +4 -4
- package/dist/components/feedback.cjs +1 -1
- package/dist/components/feedback.js +2 -2
- package/dist/components/gesture.cjs +3 -3
- package/dist/components/gesture.js +5 -5
- package/dist/components/interaction.cjs +1 -1
- package/dist/components/interaction.js +2 -2
- package/dist/components/jsx.d.cts +1 -1
- package/dist/components/jsx.d.ts +1 -1
- package/dist/components/layout.cjs +1 -1
- package/dist/components/layout.js +2 -2
- package/dist/components/lazy.cjs +1 -1
- package/dist/components/lazy.d.cts +1 -1
- package/dist/components/lazy.d.ts +1 -1
- package/dist/components/lazy.js +1 -1
- package/dist/components/packs.cjs +1 -1
- package/dist/components/packs.js +2 -2
- package/dist/components/page.cjs +2 -2
- package/dist/components/page.js +3 -3
- package/dist/components/physics.cjs +2 -2
- package/dist/components/physics.js +4 -4
- package/dist/components/react.cjs +2 -2
- package/dist/components/react.cjs.map +1 -1
- package/dist/components/react.d.cts +1 -1
- package/dist/components/react.d.ts +1 -1
- package/dist/components/react.js +2 -2
- package/dist/components/react.js.map +1 -1
- package/dist/components/reveal.cjs +1 -1
- package/dist/components/reveal.js +2 -2
- package/dist/components/solid.cjs +25 -9
- package/dist/components/solid.cjs.map +1 -1
- package/dist/components/solid.d.cts +8 -35
- package/dist/components/solid.d.ts +8 -35
- package/dist/components/solid.js +25 -9
- package/dist/components/solid.js.map +1 -1
- package/dist/components/svelte.cjs +6 -5
- package/dist/components/svelte.cjs.map +1 -1
- package/dist/components/svelte.d.cts +4 -17
- package/dist/components/svelte.d.ts +4 -17
- package/dist/components/svelte.js +6 -5
- package/dist/components/svelte.js.map +1 -1
- package/dist/components/svg.cjs +17 -11
- package/dist/components/svg.cjs.map +1 -1
- package/dist/components/svg.css +1 -1
- package/dist/components/svg.js +18 -12
- package/dist/components/svg.js.map +1 -1
- package/dist/components/text.cjs +2 -2
- package/dist/components/text.css +1 -1
- package/dist/components/text.js +3 -3
- package/dist/components/timeline.cjs +23 -223
- package/dist/components/timeline.cjs.map +1 -1
- package/dist/components/timeline.js +21 -220
- package/dist/components/timeline.js.map +1 -1
- package/dist/components/transitions.cjs +8 -125
- package/dist/components/transitions.cjs.map +1 -1
- package/dist/components/transitions.css +0 -1
- package/dist/components/transitions.d.cts +5 -34
- package/dist/components/transitions.d.ts +5 -34
- package/dist/components/transitions.js +10 -125
- package/dist/components/transitions.js.map +1 -1
- package/dist/components/ui.cjs +3 -3
- package/dist/components/ui.js +5 -5
- package/dist/components/vue.cjs +6 -5
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.d.cts +4 -17
- package/dist/components/vue.d.ts +4 -17
- package/dist/components/vue.js +6 -5
- package/dist/components/vue.js.map +1 -1
- package/dist/components/webgl.cjs +11 -1
- package/dist/components/webgl.cjs.map +1 -1
- package/dist/components/webgl.js +12 -2
- package/dist/components/webgl.js.map +1 -1
- package/dist/components.cjs +12 -13
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +2 -3
- package/dist/components.d.cts +6 -35
- package/dist/components.d.ts +6 -35
- package/dist/components.js +10 -9
- package/dist/components.js.map +1 -1
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/dist/index.cjs +5 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -32
- package/dist/index.d.ts +72 -32
- package/dist/index.js +4 -110
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/solid.cjs +38 -8
- package/dist/solid.cjs.map +1 -1
- package/dist/solid.d.cts +6 -1
- package/dist/solid.d.ts +6 -1
- package/dist/solid.js +39 -9
- package/dist/solid.js.map +1 -1
- package/docs/API.md +6 -6
- package/docs/ROADMAP.md +14 -0
- package/docs/components.md +3 -5
- package/docs/migration-from-aos.md +1 -1
- package/docs/migration-from-gsap-scrolltrigger.md +6 -6
- package/package.json +1 -1
- package/dist/chunks/index-tags-BmQR17Sb.js.map +0 -1
- package/dist/chunks/index-tags-DYYsgbba.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -4,114 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('./chunks/core-qpECfEkb.cjs');
|
|
6
6
|
var stagger = require('./chunks/stagger-CLc3j58T.cjs');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* use-scroll-animate - Sequence / timeline helper
|
|
10
|
-
* Chain animations on several targets, one after another (or overlapping).
|
|
11
|
-
*/
|
|
12
|
-
let fallback = null;
|
|
13
|
-
let warned = false;
|
|
14
|
-
function plan(steps, defaults) {
|
|
15
|
-
const out = [];
|
|
16
|
-
let cursor = 0;
|
|
17
|
-
steps.forEach((step) => {
|
|
18
|
-
const { target, gap = 0, at, ...stepOpts } = step;
|
|
19
|
-
const opts = { ...defaults, ...stepOpts };
|
|
20
|
-
const duration = opts.duration ?? 600;
|
|
21
|
-
const start = Math.max(0, at ?? cursor + gap) + (opts.delay ?? 0);
|
|
22
|
-
let end = Math.max(cursor, start);
|
|
23
|
-
core.resolveTargets(target).forEach((el, i) => {
|
|
24
|
-
const delay = start + i * (opts.stagger ?? 0);
|
|
25
|
-
out.push({ el, opts: { ...opts, duration, delay, stagger: 0 }, end: delay + duration });
|
|
26
|
-
end = Math.max(end, delay + duration);
|
|
27
|
-
});
|
|
28
|
-
cursor = end;
|
|
29
|
-
});
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Build a timeline of animations.
|
|
34
|
-
*
|
|
35
|
-
* @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* sequence([
|
|
39
|
-
* { target: '.title', animation: 'fade-in-up' },
|
|
40
|
-
* { target: '.subtitle', animation: 'blur-in', gap: -300 }, // overlap by 300ms
|
|
41
|
-
* { target: '.card', animation: 'scale-up', stagger: 80 },
|
|
42
|
-
* ], { trigger: '.hero' });
|
|
43
|
-
*/
|
|
44
|
-
function sequence(steps, options = {}) {
|
|
45
|
-
if (!warned && typeof console !== 'undefined') {
|
|
46
|
-
warned = true;
|
|
47
|
-
console.warn("[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md.");
|
|
48
|
-
}
|
|
49
|
-
const { trigger, instance, ...defaults } = options;
|
|
50
|
-
const sa = () => instance || fallback || (fallback = core.createScrollAnimate());
|
|
51
|
-
let io;
|
|
52
|
-
let active = [];
|
|
53
|
-
let settle;
|
|
54
|
-
// Targets hidden while waiting for `trigger`; revealed if cancelled before it fires.
|
|
55
|
-
let prepared = [];
|
|
56
|
-
const controller = {
|
|
57
|
-
play() {
|
|
58
|
-
controller.cancel();
|
|
59
|
-
if (!core.hasDOM())
|
|
60
|
-
return Promise.resolve();
|
|
61
|
-
active = plan(steps, defaults);
|
|
62
|
-
return new Promise((resolve) => {
|
|
63
|
-
let left = active.length;
|
|
64
|
-
settle = () => {
|
|
65
|
-
settle = undefined;
|
|
66
|
-
resolve();
|
|
67
|
-
};
|
|
68
|
-
if (!left)
|
|
69
|
-
return settle();
|
|
70
|
-
const run = active;
|
|
71
|
-
run.forEach(({ el, opts }) => {
|
|
72
|
-
const done = opts.onComplete;
|
|
73
|
-
sa().animate(el, {
|
|
74
|
-
...opts,
|
|
75
|
-
onComplete: (node) => {
|
|
76
|
-
done?.(node);
|
|
77
|
-
if (run === active && --left === 0)
|
|
78
|
-
settle?.();
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
cancel() {
|
|
85
|
-
io?.disconnect();
|
|
86
|
-
io = undefined;
|
|
87
|
-
prepared.forEach((el) => core.stopAnimation(el));
|
|
88
|
-
prepared = [];
|
|
89
|
-
active.forEach(({ el }) => core.stopAnimation(el));
|
|
90
|
-
active = [];
|
|
91
|
-
settle?.();
|
|
92
|
-
},
|
|
93
|
-
duration() {
|
|
94
|
-
return plan(steps, defaults).reduce((max, p) => Math.max(max, p.end), 0);
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
if (trigger && core.hasDOM() && core.supportsObserver()) {
|
|
98
|
-
const el = core.resolveTargets(trigger)[0];
|
|
99
|
-
if (el) {
|
|
100
|
-
prepared = plan(steps, defaults).map(({ el: target }) => target);
|
|
101
|
-
prepared.forEach((target) => core.prepareElement(target));
|
|
102
|
-
io = new IntersectionObserver((entries) => {
|
|
103
|
-
if (!entries.some((e) => e.isIntersecting))
|
|
104
|
-
return;
|
|
105
|
-
io?.disconnect();
|
|
106
|
-
io = undefined;
|
|
107
|
-
prepared = []; // play() takes over from here
|
|
108
|
-
controller.play();
|
|
109
|
-
}, { threshold: defaults.threshold ?? 0.1, rootMargin: defaults.rootMargin ?? '0px' });
|
|
110
|
-
io.observe(el);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return controller;
|
|
114
|
-
}
|
|
7
|
+
var core$1 = require('./chunks/core-DXqZm5Il.cjs');
|
|
8
|
+
require('./chunks/base-CXx7jZ-o.cjs');
|
|
115
9
|
|
|
116
10
|
/**
|
|
117
11
|
* use-scroll-animate - parallax() helper
|
|
@@ -242,7 +136,9 @@ exports.resolveEasing = core.resolveEasing;
|
|
|
242
136
|
exports.resolvePreset = core.resolvePreset;
|
|
243
137
|
exports.supportsScrollTimeline = core.supportsScrollTimeline;
|
|
244
138
|
exports.staggerChildren = stagger.staggerChildren;
|
|
139
|
+
exports.TIMELINE_PRESETS = core$1.TIMELINE_PRESETS;
|
|
140
|
+
exports.resolvePosition = core$1.resolvePosition;
|
|
141
|
+
exports.timeline = core$1.timeline;
|
|
245
142
|
exports.default = ScrollAnimate;
|
|
246
143
|
exports.parallax = parallax;
|
|
247
|
-
exports.sequence = sequence;
|
|
248
144
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/sequence.ts","../src/parallax.ts","../src/index.ts"],"sourcesContent":["/**\n * use-scroll-animate - Sequence / timeline helper\n * Chain animations on several targets, one after another (or overlapping).\n */\n\nimport type { AnimateOptions, ScrollAnimateInstance } from './types';\nimport { createScrollAnimate, hasDOM, prepareElement, resolveTargets, stopAnimation, supportsObserver } from './core';\n\nexport interface SequenceStep extends AnimateOptions {\n /** Selector, Element, NodeList or Element[] to animate in this step */\n target: string | Element | NodeList | Element[];\n /** Pause (ms) after the previous step ends before this one starts. Negative values overlap. (default: 0) */\n gap?: number;\n /** Absolute start time (ms) on the timeline; overrides `gap` */\n at?: number;\n}\n\nexport interface SequenceOptions extends AnimateOptions {\n /** Play automatically (once) when this element/selector enters the viewport */\n trigger?: string | Element;\n /** Instance whose global config (easing, classes, `disabled`) is used */\n instance?: ScrollAnimateInstance;\n}\n\nexport interface SequenceController {\n /** Play (or replay) the timeline. Resolves when every step has completed, or on `cancel()`. */\n play(): Promise<void>;\n /** Stop the trigger and running animations; elements are left visible. */\n cancel(): void;\n /** Total duration of the timeline in ms (computed for the current DOM). */\n duration(): number;\n}\n\nlet fallback: ScrollAnimateInstance | null = null;\nlet warned = false;\n\ntype Planned = { el: Element; opts: AnimateOptions; end: number };\n\nfunction plan(steps: SequenceStep[], defaults: AnimateOptions): Planned[] {\n const out: Planned[] = [];\n let cursor = 0;\n steps.forEach((step) => {\n const { target, gap = 0, at, ...stepOpts } = step;\n const opts = { ...defaults, ...stepOpts };\n const duration = opts.duration ?? 600;\n const start = Math.max(0, at ?? cursor + gap) + (opts.delay ?? 0);\n let end = Math.max(cursor, start);\n resolveTargets(target).forEach((el, i) => {\n const delay = start + i * (opts.stagger ?? 0);\n out.push({ el, opts: { ...opts, duration, delay, stagger: 0 }, end: delay + duration });\n end = Math.max(end, delay + duration);\n });\n cursor = end;\n });\n return out;\n}\n\n/**\n * Build a timeline of animations.\n *\n * @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).\n *\n * @example\n * sequence([\n * { target: '.title', animation: 'fade-in-up' },\n * { target: '.subtitle', animation: 'blur-in', gap: -300 }, // overlap by 300ms\n * { target: '.card', animation: 'scale-up', stagger: 80 },\n * ], { trigger: '.hero' });\n */\nexport function sequence(steps: SequenceStep[], options: SequenceOptions = {}): SequenceController {\n if (!warned && typeof console !== 'undefined') {\n warned = true;\n console.warn(\"[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md.\");\n }\n const { trigger, instance, ...defaults } = options;\n const sa = () => instance || fallback || (fallback = createScrollAnimate());\n let io: IntersectionObserver | undefined;\n let active: Planned[] = [];\n let settle: (() => void) | undefined;\n // Targets hidden while waiting for `trigger`; revealed if cancelled before it fires.\n let prepared: Element[] = [];\n\n const controller: SequenceController = {\n play() {\n controller.cancel();\n if (!hasDOM()) return Promise.resolve();\n active = plan(steps, defaults);\n return new Promise<void>((resolve) => {\n let left = active.length;\n settle = () => {\n settle = undefined;\n resolve();\n };\n if (!left) return settle();\n const run = active;\n run.forEach(({ el, opts }) => {\n const done = opts.onComplete;\n sa().animate(el, {\n ...opts,\n onComplete: (node) => {\n done?.(node);\n if (run === active && --left === 0) settle?.();\n },\n });\n });\n });\n },\n\n cancel() {\n io?.disconnect();\n io = undefined;\n prepared.forEach((el) => stopAnimation(el));\n prepared = [];\n active.forEach(({ el }) => stopAnimation(el));\n active = [];\n settle?.();\n },\n\n duration() {\n return plan(steps, defaults).reduce((max, p) => Math.max(max, p.end), 0);\n },\n };\n\n if (trigger && hasDOM() && supportsObserver()) {\n const el = resolveTargets(trigger)[0];\n if (el) {\n prepared = plan(steps, defaults).map(({ el: target }) => target);\n prepared.forEach((target) => prepareElement(target));\n io = new IntersectionObserver(\n (entries) => {\n if (!entries.some((e) => e.isIntersecting)) return;\n io?.disconnect();\n io = undefined;\n prepared = []; // play() takes over from here\n controller.play();\n },\n { threshold: defaults.threshold ?? 0.1, rootMargin: defaults.rootMargin ?? '0px' }\n );\n io.observe(el);\n }\n }\n\n return controller;\n}\n","/**\n * use-scroll-animate - parallax() helper\n *\n * Moves elements at a different speed than the page while they cross the\n * viewport. Built on the same scroll progress as `progressVar` (0 when the\n * element's top enters at the bottom, 1 when its bottom leaves at the top):\n * the progress is written to a CSS custom property (default `--sa-parallax`)\n * and the offset is applied with the individual `translate` property, so it\n * composes with entrance animations and other `transform`s.\n */\n\nimport { getScrollProgress, hasDOM, prefersReducedMotion, resolveTargets, supportsObserver } from './core';\n\nexport interface ParallaxHelperOptions {\n /**\n * Total distance the element shifts while it crosses the viewport, as a\n * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values\n * lag behind the scroll (background-like), negative values move ahead of it\n * (foreground-like). (default: `0.2`)\n */\n speed?: number;\n /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */\n axis?: 'x' | 'y';\n /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */\n progressVar?: string;\n /** Scroll container (default: the viewport) */\n root?: Element | null;\n /**\n * Under `prefers-reduced-motion: reduce` no offset is applied (the progress\n * variable is still written). Set to `false` to move anyway. (default: `true`)\n */\n respectReducedMotion?: boolean;\n}\n\nconst PASSIVE: AddEventListenerOptions = { passive: true };\n\n/**\n * Apply a scroll parallax to `target` (selector, Element, NodeList or array).\n * Returns a function that stops it and removes the inline styles it set.\n * SSR-safe (no-op without a DOM / IntersectionObserver).\n *\n * @example\n * const stop = parallax('.hero-bg', { speed: 0.3 });\n * parallax('.badge', { speed: -0.15, axis: 'x' });\n */\nexport function parallax(\n target: string | Element | NodeList | Element[],\n options: ParallaxHelperOptions = {}\n): () => void {\n const els = resolveTargets(target);\n if (!els.length || !hasDOM() || !supportsObserver()) return () => undefined;\n const { speed = 0.2, axis = 'y', root = null, respectReducedMotion = true } = options;\n const name = options.progressVar ? (options.progressVar.startsWith('--') ? options.progressVar : `--${options.progressVar}`) : '--sa-parallax';\n const unit = axis === 'x' ? 'vw' : 'vh';\n const visible = new Set<Element>();\n let frame = 0;\n let listening = false;\n const scroller: EventTarget = root || window;\n\n const apply = (el: Element) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n const p = getScrollProgress(el, root);\n style.setProperty(name, String(+p.toFixed(4)));\n if (respectReducedMotion && prefersReducedMotion()) {\n style.removeProperty('translate');\n return;\n }\n const offset = `${+((p - 0.5) * speed * 100).toFixed(3)}${unit}`;\n style.setProperty('translate', axis === 'x' ? `${offset} 0px` : `0px ${offset}`);\n };\n\n const update = () => {\n frame = 0;\n visible.forEach(apply);\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(update);\n };\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n const method = on ? 'addEventListener' : 'removeEventListener';\n scroller[method]('scroll', schedule, PASSIVE);\n window[method]('resize', schedule, PASSIVE);\n if (!on && frame) {\n cancelAnimationFrame(frame);\n frame = 0;\n }\n };\n\n const io = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) visible.add(entry.target);\n else visible.delete(entry.target);\n apply(entry.target); // report the edges even on fast scrolls\n });\n listen(visible.size > 0);\n },\n { threshold: 0, root }\n );\n els.forEach((el) => {\n apply(el); // no jump before the first observer callback\n io.observe(el);\n });\n\n return () => {\n io.disconnect();\n listen(false);\n visible.clear();\n els.forEach((el) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n style.removeProperty('translate');\n style.removeProperty(name);\n });\n };\n}\n","/**\n * use-scroll-animate\n *\n * A lightweight, dependency-free scroll animation library for modern web\n * applications. Built with TypeScript, powered by IntersectionObserver and\n * the Web Animations API (or the native scroll-driven timeline). Safe to\n * import during SSR. Framework integrations live in the subpath entries:\n * `use-scroll-animate/react`, `/vue`, `/svelte`, `/solid`, `/element`.\n *\n * @license MIT\n * @see https://github.com/HarrisonCN/use-scroll-animate\n */\n\nexport { createScrollAnimate, getScrollProgress, supportsScrollTimeline } from './core';\nexport { staggerChildren } from './stagger';\nexport { sequence } from './sequence';\nexport { parallax } from './parallax';\nexport { PRESETS, resolvePreset, resolveEasing, EASING_MAP } from './presets';\nexport type {\n AnimationPreset,\n EasingType,\n AnimationKeyframe,\n CustomAnimation,\n ProgressMode,\n ScrollEngine,\n AnimateOptions,\n ScrollAnimateConfig,\n AnimatedElement,\n ScrollAnimateInstance,\n} from './types';\nexport type { StaggerOptions } from './stagger';\nexport type { ParallaxHelperOptions } from './parallax';\nexport type { SequenceStep, SequenceOptions, SequenceController } from './sequence';\n\n// Default export: a ready-to-use singleton instance\nimport { createScrollAnimate } from './core';\n\n/**\n * Default singleton instance of ScrollAnimate.\n * Ready to use out of the box with sensible defaults.\n *\n * @example\n * ```js\n * import ScrollAnimate from 'use-scroll-animate';\n *\n * // Auto-initialize all elements with data-sa attribute\n * ScrollAnimate.init();\n *\n * // Or manually observe elements\n * ScrollAnimate.observe('.my-element', { animation: 'fade-in-up' });\n * ```\n */\nconst ScrollAnimate = /* @__PURE__ */ createScrollAnimate();\nexport default ScrollAnimate;\n"],"names":["resolveTargets","createScrollAnimate","hasDOM","stopAnimation","supportsObserver","prepareElement","getScrollProgress","pref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C,WAAW,CAAC;AACjC,YAAA,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC;AAC5B,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC;AACH;;ACtHA;;;;;;;;;;;AAWG;AA0BH;;;;;;;;;;;;;;AAcG;AACH,MAAM,aAAa,mBAAmBN,wBAAmB;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/parallax.ts","../src/index.ts"],"sourcesContent":["/**\n * use-scroll-animate - parallax() helper\n *\n * Moves elements at a different speed than the page while they cross the\n * viewport. Built on the same scroll progress as `progressVar` (0 when the\n * element's top enters at the bottom, 1 when its bottom leaves at the top):\n * the progress is written to a CSS custom property (default `--sa-parallax`)\n * and the offset is applied with the individual `translate` property, so it\n * composes with entrance animations and other `transform`s.\n */\n\nimport { getScrollProgress, hasDOM, prefersReducedMotion, resolveTargets, supportsObserver } from './core';\n\nexport interface ParallaxHelperOptions {\n /**\n * Total distance the element shifts while it crosses the viewport, as a\n * fraction of the viewport size (`0.2` = 20vh on the y axis). Positive values\n * lag behind the scroll (background-like), negative values move ahead of it\n * (foreground-like). (default: `0.2`)\n */\n speed?: number;\n /** `'y'` (default) or `'x'` (horizontal drift, in `vw`) */\n axis?: 'x' | 'y';\n /** CSS custom property receiving the progress (default: `'--sa-parallax'`) */\n progressVar?: string;\n /** Scroll container (default: the viewport) */\n root?: Element | null;\n /**\n * Under `prefers-reduced-motion: reduce` no offset is applied (the progress\n * variable is still written). Set to `false` to move anyway. (default: `true`)\n */\n respectReducedMotion?: boolean;\n}\n\nconst PASSIVE: AddEventListenerOptions = { passive: true };\n\n/**\n * Apply a scroll parallax to `target` (selector, Element, NodeList or array).\n * Returns a function that stops it and removes the inline styles it set.\n * SSR-safe (no-op without a DOM / IntersectionObserver).\n *\n * @example\n * const stop = parallax('.hero-bg', { speed: 0.3 });\n * parallax('.badge', { speed: -0.15, axis: 'x' });\n */\nexport function parallax(\n target: string | Element | NodeList | Element[],\n options: ParallaxHelperOptions = {}\n): () => void {\n const els = resolveTargets(target);\n if (!els.length || !hasDOM() || !supportsObserver()) return () => undefined;\n const { speed = 0.2, axis = 'y', root = null, respectReducedMotion = true } = options;\n const name = options.progressVar ? (options.progressVar.startsWith('--') ? options.progressVar : `--${options.progressVar}`) : '--sa-parallax';\n const unit = axis === 'x' ? 'vw' : 'vh';\n const visible = new Set<Element>();\n let frame = 0;\n let listening = false;\n const scroller: EventTarget = root || window;\n\n const apply = (el: Element) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n const p = getScrollProgress(el, root);\n style.setProperty(name, String(+p.toFixed(4)));\n if (respectReducedMotion && prefersReducedMotion()) {\n style.removeProperty('translate');\n return;\n }\n const offset = `${+((p - 0.5) * speed * 100).toFixed(3)}${unit}`;\n style.setProperty('translate', axis === 'x' ? `${offset} 0px` : `0px ${offset}`);\n };\n\n const update = () => {\n frame = 0;\n visible.forEach(apply);\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(update);\n };\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n const method = on ? 'addEventListener' : 'removeEventListener';\n scroller[method]('scroll', schedule, PASSIVE);\n window[method]('resize', schedule, PASSIVE);\n if (!on && frame) {\n cancelAnimationFrame(frame);\n frame = 0;\n }\n };\n\n const io = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) visible.add(entry.target);\n else visible.delete(entry.target);\n apply(entry.target); // report the edges even on fast scrolls\n });\n listen(visible.size > 0);\n },\n { threshold: 0, root }\n );\n els.forEach((el) => {\n apply(el); // no jump before the first observer callback\n io.observe(el);\n });\n\n return () => {\n io.disconnect();\n listen(false);\n visible.clear();\n els.forEach((el) => {\n const style = (el as HTMLElement).style;\n if (!style) return;\n style.removeProperty('translate');\n style.removeProperty(name);\n });\n };\n}\n","/**\n * use-scroll-animate\n *\n * A lightweight, dependency-free scroll animation library for modern web\n * applications. Built with TypeScript, powered by IntersectionObserver and\n * the Web Animations API (or the native scroll-driven timeline). Safe to\n * import during SSR. Framework integrations live in the subpath entries:\n * `use-scroll-animate/react`, `/vue`, `/svelte`, `/solid`, `/element`.\n *\n * @license MIT\n * @see https://github.com/HarrisonCN/use-scroll-animate\n */\n\nexport { createScrollAnimate, getScrollProgress, supportsScrollTimeline } from './core';\nexport { staggerChildren } from './stagger';\nexport { timeline, resolvePosition, TIMELINE_PRESETS } from './components/timeline/core';\nexport { parallax } from './parallax';\nexport { PRESETS, resolvePreset, resolveEasing, EASING_MAP } from './presets';\nexport type {\n AnimationPreset,\n EasingType,\n AnimationKeyframe,\n CustomAnimation,\n ProgressMode,\n ScrollEngine,\n AnimateOptions,\n ScrollAnimateConfig,\n AnimatedElement,\n ScrollAnimateInstance,\n} from './types';\nexport type { StaggerOptions } from './stagger';\nexport type { ParallaxHelperOptions } from './parallax';\nexport type { Timeline, TimelineOptions, TimelineStepOptions, TimelinePosition, ScrubOptions } from './components/timeline/core';\n\n// Default export: a ready-to-use singleton instance\nimport { createScrollAnimate } from './core';\n\n/**\n * Default singleton instance of ScrollAnimate.\n * Ready to use out of the box with sensible defaults.\n *\n * @example\n * ```js\n * import ScrollAnimate from 'use-scroll-animate';\n *\n * // Auto-initialize all elements with data-sa attribute\n * ScrollAnimate.init();\n *\n * // Or manually observe elements\n * ScrollAnimate.observe('.my-element', { animation: 'fade-in-up' });\n * ```\n */\nconst ScrollAnimate = /* @__PURE__ */ createScrollAnimate();\nexport default ScrollAnimate;\n"],"names":["resolveTargets","hasDOM","supportsObserver","getScrollProgress","prefersReducedMotion","createScrollAnimate"],"mappings":";;;;;;;;;AAAA;;;;;;;;;AASG;AAyBH,MAAM,OAAO,GAA4B,EAAE,OAAO,EAAE,IAAI,EAAE;AAE1D;;;;;;;;AAQG;SACa,QAAQ,CACtB,MAA+C,EAC/C,UAAiC,EAAE,EAAA;AAEnC,IAAA,MAAM,GAAG,GAAGA,mBAAc,CAAC,MAAM,CAAC;IAClC,IAAI,CAAC,GAAG,CAAC,MAAM,IA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C,CAAC;IAC1B,CAAC,EACD,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,CACvB;AACD,IAAA,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;AACjB,QAAA,KAAK,CAAC,EAAE,CAAC,CAAC;AACV,QAAA,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;AAChB,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAK;QACV,EAAE,CAAC,UAAU,EAAE;QACf,MAAM,CAAC,KAAK,CAAC;QACb,OAAO,CAAC,KAAK,EAAE;AACf,QAAA,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;AACjB,YAAA,MAAM,KAAK,GAAI,EAAkB,CAAC,KAAK;AACvC,YAAA,IAAI,CAAC,KAAK;gBAAE;AACZ,YAAA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;AACjC,YAAA,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC;AAC5B,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC;AACH;;ACtHA;;;;;;;;;;;AAWG;AA0BH;;;;;;;;;;;;;;AAcG;AACH,MAAM,aAAa,mBAAmBC,wBAAmB;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.cts
CHANGED
|
@@ -219,45 +219,85 @@ interface StaggerOptions extends AnimateOptions {
|
|
|
219
219
|
declare function staggerChildren(container: Element | null | undefined, options?: StaggerOptions, instance?: ScrollAnimateInstance): () => void;
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
222
|
+
* Where a step starts on a timeline:
|
|
223
|
+
* - a number: absolute time in ms
|
|
224
|
+
* - `'>'` (default): when the previous step ends · `'<'`: when it starts
|
|
225
|
+
* - `'+=200'` / `'-=200'`: after / overlapping the previous end
|
|
226
|
+
* - `'<+=100'`: 100ms after the previous step's start
|
|
227
|
+
* - `'intro'` / `'intro+=150'`: at (or relative to) a label
|
|
224
228
|
*/
|
|
225
|
-
|
|
226
|
-
interface
|
|
227
|
-
/**
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
at?:
|
|
229
|
+
type TimelinePosition = number | string;
|
|
230
|
+
interface TimelineStepOptions {
|
|
231
|
+
/** Duration in ms (default: timeline default, 600). */
|
|
232
|
+
duration?: number;
|
|
233
|
+
/** CSS easing (default `cubic-bezier(0.22, 1, 0.36, 1)`). */
|
|
234
|
+
easing?: string;
|
|
235
|
+
/** Start position, see `TimelinePosition`. */
|
|
236
|
+
at?: TimelinePosition;
|
|
237
|
+
/** ms between targets when the selector matches several elements. */
|
|
238
|
+
stagger?: number;
|
|
233
239
|
}
|
|
234
|
-
interface
|
|
235
|
-
/**
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
|
|
240
|
+
interface TimelineOptions {
|
|
241
|
+
/** Defaults for every step. */
|
|
242
|
+
defaults?: Pick<TimelineStepOptions, 'duration' | 'easing' | 'stagger'>;
|
|
243
|
+
/** Playback rate (1 = normal). */
|
|
244
|
+
speed?: number;
|
|
245
|
+
/** Called after `play()` reaches the end (or the start when reversed). */
|
|
246
|
+
onComplete?: () => void;
|
|
247
|
+
/** Called on every frame with progress 0–1. */
|
|
248
|
+
onUpdate?: (progress: number) => void;
|
|
239
249
|
}
|
|
240
|
-
interface
|
|
241
|
-
/**
|
|
242
|
-
|
|
243
|
-
/**
|
|
250
|
+
interface ScrubOptions {
|
|
251
|
+
/** Scroll offset (px) before the source's top reaches the viewport bottom where progress starts. */
|
|
252
|
+
offset?: number;
|
|
253
|
+
/** Smoothing 0–1 (0 = immediate, default 0). */
|
|
254
|
+
smooth?: number;
|
|
255
|
+
}
|
|
256
|
+
interface Timeline {
|
|
257
|
+
/** Total length in ms. */
|
|
258
|
+
readonly duration: number;
|
|
259
|
+
/** Label positions in ms. */
|
|
260
|
+
readonly labels: Readonly<Record<string, number>>;
|
|
261
|
+
/** Current playhead in ms. */
|
|
262
|
+
readonly time: number;
|
|
263
|
+
/** Add a step: animate `target` with keyframes or a preset name (`fade-up`, `scale`…). */
|
|
264
|
+
to(target: string | Element | Element[] | NodeList, frames: Keyframe[] | string, options?: TimelineStepOptions): Timeline;
|
|
265
|
+
/** Name a position (default: the current end). */
|
|
266
|
+
label(name: string, at?: TimelinePosition): Timeline;
|
|
267
|
+
/** Run `fn` when the playhead passes `at`. */
|
|
268
|
+
call(fn: () => void, at?: TimelinePosition): Timeline;
|
|
269
|
+
/** Play forwards from the playhead (from 0 when at the end). Resolves at the end. */
|
|
270
|
+
play(from?: TimelinePosition): Promise<void>;
|
|
271
|
+
/** Play backwards to 0. */
|
|
272
|
+
reverse(): Promise<void>;
|
|
273
|
+
pause(): Timeline;
|
|
274
|
+
/** Jump to a time (ms) or label. */
|
|
275
|
+
seek(to: TimelinePosition): Timeline;
|
|
276
|
+
/** Get or set progress 0–1. */
|
|
277
|
+
progress(p?: number): number;
|
|
278
|
+
/** Tie progress to the scroll position of `source` (it moves through the viewport). Returns a stop function. */
|
|
279
|
+
scrub(source: Element, options?: ScrubOptions): () => void;
|
|
280
|
+
/** Stop and drop every animation (elements keep their last frame). */
|
|
244
281
|
cancel(): void;
|
|
245
|
-
/** Total duration of the timeline in ms (computed for the current DOM). */
|
|
246
|
-
duration(): number;
|
|
247
282
|
}
|
|
283
|
+
/** Keyframe presets usable by name in `to()` and `data-tl`. */
|
|
284
|
+
declare const TIMELINE_PRESETS: Record<string, Keyframe[]>;
|
|
285
|
+
/** Resolve a position against the previous step and labels (pure). */
|
|
286
|
+
declare function resolvePosition(pos: TimelinePosition | undefined, end: number, prevStart: number, labels?: Record<string, number>): number;
|
|
248
287
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
288
|
+
* Choreograph animations on one clock: chain, overlap, label, seek, reverse and
|
|
289
|
+
* scrub them with scroll. Built on WAAPI (paused animations driven by one
|
|
290
|
+
* playhead); without WAAPI or under reduced motion it jumps to the end state.
|
|
252
291
|
*
|
|
253
292
|
* @example
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* ], {
|
|
293
|
+
* const tl = timeline({ defaults: { duration: 500 } })
|
|
294
|
+
* .to('.title', 'fade-up')
|
|
295
|
+
* .label('cards')
|
|
296
|
+
* .to('.card', 'scale', { stagger: 80, at: '-=200' })
|
|
297
|
+
* .to('.cta', [{ opacity: 0 }, { opacity: 1 }], { at: 'cards+=400' });
|
|
298
|
+
* tl.play(); // or tl.scrub(document.querySelector('.hero'))
|
|
259
299
|
*/
|
|
260
|
-
declare function
|
|
300
|
+
declare function timeline(options?: TimelineOptions): Timeline;
|
|
261
301
|
|
|
262
302
|
/**
|
|
263
303
|
* use-scroll-animate - parallax() helper
|
|
@@ -332,5 +372,5 @@ declare function resolveEasing(easing: EasingType): string;
|
|
|
332
372
|
*/
|
|
333
373
|
declare const ScrollAnimate: ScrollAnimateInstance;
|
|
334
374
|
|
|
335
|
-
export { EASING_MAP, PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing,
|
|
336
|
-
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine,
|
|
375
|
+
export { EASING_MAP, PRESETS, TIMELINE_PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing, resolvePosition, resolvePreset, staggerChildren, supportsScrollTimeline, timeline };
|
|
376
|
+
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine, ScrubOptions, StaggerOptions, Timeline, TimelineOptions, TimelinePosition, TimelineStepOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -219,45 +219,85 @@ interface StaggerOptions extends AnimateOptions {
|
|
|
219
219
|
declare function staggerChildren(container: Element | null | undefined, options?: StaggerOptions, instance?: ScrollAnimateInstance): () => void;
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
222
|
+
* Where a step starts on a timeline:
|
|
223
|
+
* - a number: absolute time in ms
|
|
224
|
+
* - `'>'` (default): when the previous step ends · `'<'`: when it starts
|
|
225
|
+
* - `'+=200'` / `'-=200'`: after / overlapping the previous end
|
|
226
|
+
* - `'<+=100'`: 100ms after the previous step's start
|
|
227
|
+
* - `'intro'` / `'intro+=150'`: at (or relative to) a label
|
|
224
228
|
*/
|
|
225
|
-
|
|
226
|
-
interface
|
|
227
|
-
/**
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
at?:
|
|
229
|
+
type TimelinePosition = number | string;
|
|
230
|
+
interface TimelineStepOptions {
|
|
231
|
+
/** Duration in ms (default: timeline default, 600). */
|
|
232
|
+
duration?: number;
|
|
233
|
+
/** CSS easing (default `cubic-bezier(0.22, 1, 0.36, 1)`). */
|
|
234
|
+
easing?: string;
|
|
235
|
+
/** Start position, see `TimelinePosition`. */
|
|
236
|
+
at?: TimelinePosition;
|
|
237
|
+
/** ms between targets when the selector matches several elements. */
|
|
238
|
+
stagger?: number;
|
|
233
239
|
}
|
|
234
|
-
interface
|
|
235
|
-
/**
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
|
|
240
|
+
interface TimelineOptions {
|
|
241
|
+
/** Defaults for every step. */
|
|
242
|
+
defaults?: Pick<TimelineStepOptions, 'duration' | 'easing' | 'stagger'>;
|
|
243
|
+
/** Playback rate (1 = normal). */
|
|
244
|
+
speed?: number;
|
|
245
|
+
/** Called after `play()` reaches the end (or the start when reversed). */
|
|
246
|
+
onComplete?: () => void;
|
|
247
|
+
/** Called on every frame with progress 0–1. */
|
|
248
|
+
onUpdate?: (progress: number) => void;
|
|
239
249
|
}
|
|
240
|
-
interface
|
|
241
|
-
/**
|
|
242
|
-
|
|
243
|
-
/**
|
|
250
|
+
interface ScrubOptions {
|
|
251
|
+
/** Scroll offset (px) before the source's top reaches the viewport bottom where progress starts. */
|
|
252
|
+
offset?: number;
|
|
253
|
+
/** Smoothing 0–1 (0 = immediate, default 0). */
|
|
254
|
+
smooth?: number;
|
|
255
|
+
}
|
|
256
|
+
interface Timeline {
|
|
257
|
+
/** Total length in ms. */
|
|
258
|
+
readonly duration: number;
|
|
259
|
+
/** Label positions in ms. */
|
|
260
|
+
readonly labels: Readonly<Record<string, number>>;
|
|
261
|
+
/** Current playhead in ms. */
|
|
262
|
+
readonly time: number;
|
|
263
|
+
/** Add a step: animate `target` with keyframes or a preset name (`fade-up`, `scale`…). */
|
|
264
|
+
to(target: string | Element | Element[] | NodeList, frames: Keyframe[] | string, options?: TimelineStepOptions): Timeline;
|
|
265
|
+
/** Name a position (default: the current end). */
|
|
266
|
+
label(name: string, at?: TimelinePosition): Timeline;
|
|
267
|
+
/** Run `fn` when the playhead passes `at`. */
|
|
268
|
+
call(fn: () => void, at?: TimelinePosition): Timeline;
|
|
269
|
+
/** Play forwards from the playhead (from 0 when at the end). Resolves at the end. */
|
|
270
|
+
play(from?: TimelinePosition): Promise<void>;
|
|
271
|
+
/** Play backwards to 0. */
|
|
272
|
+
reverse(): Promise<void>;
|
|
273
|
+
pause(): Timeline;
|
|
274
|
+
/** Jump to a time (ms) or label. */
|
|
275
|
+
seek(to: TimelinePosition): Timeline;
|
|
276
|
+
/** Get or set progress 0–1. */
|
|
277
|
+
progress(p?: number): number;
|
|
278
|
+
/** Tie progress to the scroll position of `source` (it moves through the viewport). Returns a stop function. */
|
|
279
|
+
scrub(source: Element, options?: ScrubOptions): () => void;
|
|
280
|
+
/** Stop and drop every animation (elements keep their last frame). */
|
|
244
281
|
cancel(): void;
|
|
245
|
-
/** Total duration of the timeline in ms (computed for the current DOM). */
|
|
246
|
-
duration(): number;
|
|
247
282
|
}
|
|
283
|
+
/** Keyframe presets usable by name in `to()` and `data-tl`. */
|
|
284
|
+
declare const TIMELINE_PRESETS: Record<string, Keyframe[]>;
|
|
285
|
+
/** Resolve a position against the previous step and labels (pure). */
|
|
286
|
+
declare function resolvePosition(pos: TimelinePosition | undefined, end: number, prevStart: number, labels?: Record<string, number>): number;
|
|
248
287
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
288
|
+
* Choreograph animations on one clock: chain, overlap, label, seek, reverse and
|
|
289
|
+
* scrub them with scroll. Built on WAAPI (paused animations driven by one
|
|
290
|
+
* playhead); without WAAPI or under reduced motion it jumps to the end state.
|
|
252
291
|
*
|
|
253
292
|
* @example
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* ], {
|
|
293
|
+
* const tl = timeline({ defaults: { duration: 500 } })
|
|
294
|
+
* .to('.title', 'fade-up')
|
|
295
|
+
* .label('cards')
|
|
296
|
+
* .to('.card', 'scale', { stagger: 80, at: '-=200' })
|
|
297
|
+
* .to('.cta', [{ opacity: 0 }, { opacity: 1 }], { at: 'cards+=400' });
|
|
298
|
+
* tl.play(); // or tl.scrub(document.querySelector('.hero'))
|
|
259
299
|
*/
|
|
260
|
-
declare function
|
|
300
|
+
declare function timeline(options?: TimelineOptions): Timeline;
|
|
261
301
|
|
|
262
302
|
/**
|
|
263
303
|
* use-scroll-animate - parallax() helper
|
|
@@ -332,5 +372,5 @@ declare function resolveEasing(easing: EasingType): string;
|
|
|
332
372
|
*/
|
|
333
373
|
declare const ScrollAnimate: ScrollAnimateInstance;
|
|
334
374
|
|
|
335
|
-
export { EASING_MAP, PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing,
|
|
336
|
-
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine,
|
|
375
|
+
export { EASING_MAP, PRESETS, TIMELINE_PRESETS, createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax, resolveEasing, resolvePosition, resolvePreset, staggerChildren, supportsScrollTimeline, timeline };
|
|
376
|
+
export type { AnimateOptions, AnimatedElement, AnimationKeyframe, AnimationPreset, CustomAnimation, EasingType, ParallaxHelperOptions, ProgressMode, ScrollAnimateConfig, ScrollAnimateInstance, ScrollEngine, ScrubOptions, StaggerOptions, Timeline, TimelineOptions, TimelinePosition, TimelineStepOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,114 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as resolveTargets, h as hasDOM, s as supportsObserver, g as getScrollProgress, d as prefersReducedMotion, c as createScrollAnimate } from './chunks/core-mV_TPgG_.js';
|
|
2
2
|
export { E as EASING_MAP, P as PRESETS, e as resolveEasing, f as resolvePreset, i as supportsScrollTimeline } from './chunks/core-mV_TPgG_.js';
|
|
3
3
|
export { s as staggerChildren } from './chunks/stagger-BFAhKknX.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* use-scroll-animate - Sequence / timeline helper
|
|
7
|
-
* Chain animations on several targets, one after another (or overlapping).
|
|
8
|
-
*/
|
|
9
|
-
let fallback = null;
|
|
10
|
-
let warned = false;
|
|
11
|
-
function plan(steps, defaults) {
|
|
12
|
-
const out = [];
|
|
13
|
-
let cursor = 0;
|
|
14
|
-
steps.forEach((step) => {
|
|
15
|
-
const { target, gap = 0, at, ...stepOpts } = step;
|
|
16
|
-
const opts = { ...defaults, ...stepOpts };
|
|
17
|
-
const duration = opts.duration ?? 600;
|
|
18
|
-
const start = Math.max(0, at ?? cursor + gap) + (opts.delay ?? 0);
|
|
19
|
-
let end = Math.max(cursor, start);
|
|
20
|
-
resolveTargets(target).forEach((el, i) => {
|
|
21
|
-
const delay = start + i * (opts.stagger ?? 0);
|
|
22
|
-
out.push({ el, opts: { ...opts, duration, delay, stagger: 0 }, end: delay + duration });
|
|
23
|
-
end = Math.max(end, delay + duration);
|
|
24
|
-
});
|
|
25
|
-
cursor = end;
|
|
26
|
-
});
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Build a timeline of animations.
|
|
31
|
-
*
|
|
32
|
-
* @deprecated since 3.9, removed in 4.0 — use `timeline()` (`.to(target, preset, { at: '-=300' })`).
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* sequence([
|
|
36
|
-
* { target: '.title', animation: 'fade-in-up' },
|
|
37
|
-
* { target: '.subtitle', animation: 'blur-in', gap: -300 }, // overlap by 300ms
|
|
38
|
-
* { target: '.card', animation: 'scale-up', stagger: 80 },
|
|
39
|
-
* ], { trigger: '.hero' });
|
|
40
|
-
*/
|
|
41
|
-
function sequence(steps, options = {}) {
|
|
42
|
-
if (!warned && typeof console !== 'undefined') {
|
|
43
|
-
warned = true;
|
|
44
|
-
console.warn("[use-scroll-animate] sequence() is deprecated and will be removed in 4.0 — use timeline() from 'use-scroll-animate/components/timeline' (also exported from 'use-scroll-animate' in 4.0). See docs/upgrading-4.md.");
|
|
45
|
-
}
|
|
46
|
-
const { trigger, instance, ...defaults } = options;
|
|
47
|
-
const sa = () => instance || fallback || (fallback = createScrollAnimate());
|
|
48
|
-
let io;
|
|
49
|
-
let active = [];
|
|
50
|
-
let settle;
|
|
51
|
-
// Targets hidden while waiting for `trigger`; revealed if cancelled before it fires.
|
|
52
|
-
let prepared = [];
|
|
53
|
-
const controller = {
|
|
54
|
-
play() {
|
|
55
|
-
controller.cancel();
|
|
56
|
-
if (!hasDOM())
|
|
57
|
-
return Promise.resolve();
|
|
58
|
-
active = plan(steps, defaults);
|
|
59
|
-
return new Promise((resolve) => {
|
|
60
|
-
let left = active.length;
|
|
61
|
-
settle = () => {
|
|
62
|
-
settle = undefined;
|
|
63
|
-
resolve();
|
|
64
|
-
};
|
|
65
|
-
if (!left)
|
|
66
|
-
return settle();
|
|
67
|
-
const run = active;
|
|
68
|
-
run.forEach(({ el, opts }) => {
|
|
69
|
-
const done = opts.onComplete;
|
|
70
|
-
sa().animate(el, {
|
|
71
|
-
...opts,
|
|
72
|
-
onComplete: (node) => {
|
|
73
|
-
done?.(node);
|
|
74
|
-
if (run === active && --left === 0)
|
|
75
|
-
settle?.();
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
cancel() {
|
|
82
|
-
io?.disconnect();
|
|
83
|
-
io = undefined;
|
|
84
|
-
prepared.forEach((el) => stopAnimation(el));
|
|
85
|
-
prepared = [];
|
|
86
|
-
active.forEach(({ el }) => stopAnimation(el));
|
|
87
|
-
active = [];
|
|
88
|
-
settle?.();
|
|
89
|
-
},
|
|
90
|
-
duration() {
|
|
91
|
-
return plan(steps, defaults).reduce((max, p) => Math.max(max, p.end), 0);
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
if (trigger && hasDOM() && supportsObserver()) {
|
|
95
|
-
const el = resolveTargets(trigger)[0];
|
|
96
|
-
if (el) {
|
|
97
|
-
prepared = plan(steps, defaults).map(({ el: target }) => target);
|
|
98
|
-
prepared.forEach((target) => prepareElement(target));
|
|
99
|
-
io = new IntersectionObserver((entries) => {
|
|
100
|
-
if (!entries.some((e) => e.isIntersecting))
|
|
101
|
-
return;
|
|
102
|
-
io?.disconnect();
|
|
103
|
-
io = undefined;
|
|
104
|
-
prepared = []; // play() takes over from here
|
|
105
|
-
controller.play();
|
|
106
|
-
}, { threshold: defaults.threshold ?? 0.1, rootMargin: defaults.rootMargin ?? '0px' });
|
|
107
|
-
io.observe(el);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return controller;
|
|
111
|
-
}
|
|
4
|
+
export { T as TIMELINE_PRESETS, r as resolvePosition, t as timeline } from './chunks/core-Co-6AL0h.js';
|
|
5
|
+
import './chunks/base-ZARFccur.js';
|
|
112
6
|
|
|
113
7
|
/**
|
|
114
8
|
* use-scroll-animate - parallax() helper
|
|
@@ -231,5 +125,5 @@ function parallax(target, options = {}) {
|
|
|
231
125
|
*/
|
|
232
126
|
const ScrollAnimate = /* @__PURE__ */ createScrollAnimate();
|
|
233
127
|
|
|
234
|
-
export { createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax
|
|
128
|
+
export { createScrollAnimate, ScrollAnimate as default, getScrollProgress, parallax };
|
|
235
129
|
//# sourceMappingURL=index.js.map
|