motionary 0.0.0-stage → 6.2.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 +803 -0
- package/LICENSE +21 -0
- package/README.md +218 -2
- package/README_ja.md +219 -0
- package/README_zh.md +219 -0
- package/bin/usa-codemod-5.mjs +79 -0
- package/bin/usa-codemod-6.mjs +146 -0
- package/dist/chunks/base-BaQV-2ha.cjs +436 -0
- package/dist/chunks/base-BaQV-2ha.cjs.map +1 -0
- package/dist/chunks/base-C_3cAoRz.js +404 -0
- package/dist/chunks/base-C_3cAoRz.js.map +1 -0
- package/dist/chunks/bind-B_CTL6Qn.js +22 -0
- package/dist/chunks/bind-B_CTL6Qn.js.map +1 -0
- package/dist/chunks/bind-Ui43-n2d.cjs +25 -0
- package/dist/chunks/bind-Ui43-n2d.cjs.map +1 -0
- package/dist/chunks/core-B5T0dhFH.cjs +920 -0
- package/dist/chunks/core-B5T0dhFH.cjs.map +1 -0
- package/dist/chunks/core-BGAyaY6L.cjs +265 -0
- package/dist/chunks/core-BGAyaY6L.cjs.map +1 -0
- package/dist/chunks/core-D7cVumUu.js +909 -0
- package/dist/chunks/core-D7cVumUu.js.map +1 -0
- package/dist/chunks/core-VEBw36QK.js +260 -0
- package/dist/chunks/core-VEBw36QK.js.map +1 -0
- package/dist/chunks/core-ps8uvYuN.js +181 -0
- package/dist/chunks/core-ps8uvYuN.js.map +1 -0
- package/dist/chunks/core-zq17EeCI.cjs +185 -0
- package/dist/chunks/core-zq17EeCI.cjs.map +1 -0
- package/dist/chunks/fx-Bs6IrV4Q.js +109 -0
- package/dist/chunks/fx-Bs6IrV4Q.js.map +1 -0
- package/dist/chunks/fx-lBGVtQO1.cjs +114 -0
- package/dist/chunks/fx-lBGVtQO1.cjs.map +1 -0
- package/dist/chunks/generative-D2YyhaeO.js +336 -0
- package/dist/chunks/generative-D2YyhaeO.js.map +1 -0
- package/dist/chunks/generative-DzIZq-_g.cjs +348 -0
- package/dist/chunks/generative-DzIZq-_g.cjs.map +1 -0
- package/dist/chunks/gpu-Bu7qwugO.js +380 -0
- package/dist/chunks/gpu-Bu7qwugO.js.map +1 -0
- package/dist/chunks/gpu-CenK2l6b.cjs +387 -0
- package/dist/chunks/gpu-CenK2l6b.cjs.map +1 -0
- package/dist/chunks/index-tags-DucKMQr_.js +26 -0
- package/dist/chunks/index-tags-DucKMQr_.js.map +1 -0
- package/dist/chunks/index-tags-wv0R_vkO.cjs +28 -0
- package/dist/chunks/index-tags-wv0R_vkO.cjs.map +1 -0
- package/dist/chunks/presets-BYBVJVeP.js +226 -0
- package/dist/chunks/presets-BYBVJVeP.js.map +1 -0
- package/dist/chunks/presets-CUHys3sK.cjs +233 -0
- package/dist/chunks/presets-CUHys3sK.cjs.map +1 -0
- package/dist/chunks/registry-CKNLQpwd.js +121 -0
- package/dist/chunks/registry-CKNLQpwd.js.map +1 -0
- package/dist/chunks/registry-DehBVRDV.cjs +131 -0
- package/dist/chunks/registry-DehBVRDV.cjs.map +1 -0
- package/dist/chunks/spring-CbvHfVtP.js +219 -0
- package/dist/chunks/spring-CbvHfVtP.js.map +1 -0
- package/dist/chunks/spring-Dgx187Vh.cjs +232 -0
- package/dist/chunks/spring-Dgx187Vh.cjs.map +1 -0
- package/dist/chunks/stagger-CCFyhzSw.cjs +86 -0
- package/dist/chunks/stagger-CCFyhzSw.cjs.map +1 -0
- package/dist/chunks/stagger-DtMKo2SK.js +84 -0
- package/dist/chunks/stagger-DtMKo2SK.js.map +1 -0
- package/dist/chunks/variants-BhjyddG8.cjs +39 -0
- package/dist/chunks/variants-BhjyddG8.cjs.map +1 -0
- package/dist/chunks/variants-DRlKVHvu.js +35 -0
- package/dist/chunks/variants-DRlKVHvu.js.map +1 -0
- package/dist/components/a11y.cjs +276 -0
- package/dist/components/a11y.cjs.map +1 -0
- package/dist/components/a11y.d.cts +131 -0
- package/dist/components/a11y.d.ts +131 -0
- package/dist/components/a11y.js +259 -0
- package/dist/components/a11y.js.map +1 -0
- package/dist/components/angular.cjs +76 -0
- package/dist/components/angular.cjs.map +1 -0
- package/dist/components/angular.d.cts +1734 -0
- package/dist/components/angular.d.ts +1734 -0
- package/dist/components/angular.js +70 -0
- package/dist/components/angular.js.map +1 -0
- package/dist/components/background.cjs +659 -0
- package/dist/components/background.cjs.map +1 -0
- package/dist/components/background.css +9 -0
- package/dist/components/background.d.cts +166 -0
- package/dist/components/background.d.ts +166 -0
- package/dist/components/background.js +647 -0
- package/dist/components/background.js.map +1 -0
- package/dist/components/bridge.cjs +154 -0
- package/dist/components/bridge.cjs.map +1 -0
- package/dist/components/bridge.d.cts +63 -0
- package/dist/components/bridge.d.ts +63 -0
- package/dist/components/bridge.js +147 -0
- package/dist/components/bridge.js.map +1 -0
- package/dist/components/cards.cjs +561 -0
- package/dist/components/cards.cjs.map +1 -0
- package/dist/components/cards.css +6 -0
- package/dist/components/cards.d.cts +115 -0
- package/dist/components/cards.d.ts +115 -0
- package/dist/components/cards.js +554 -0
- package/dist/components/cards.js.map +1 -0
- package/dist/components/click.cjs +877 -0
- package/dist/components/click.cjs.map +1 -0
- package/dist/components/click.css +9 -0
- package/dist/components/click.d.cts +218 -0
- package/dist/components/click.d.ts +218 -0
- package/dist/components/click.js +863 -0
- package/dist/components/click.js.map +1 -0
- package/dist/components/depth.cjs +250 -0
- package/dist/components/depth.cjs.map +1 -0
- package/dist/components/depth.css +3 -0
- package/dist/components/depth.d.cts +86 -0
- package/dist/components/depth.d.ts +86 -0
- package/dist/components/depth.js +242 -0
- package/dist/components/depth.js.map +1 -0
- package/dist/components/effects.cjs +2258 -0
- package/dist/components/effects.cjs.map +1 -0
- package/dist/components/effects.d.cts +545 -0
- package/dist/components/effects.d.ts +545 -0
- package/dist/components/effects.js +2200 -0
- package/dist/components/effects.js.map +1 -0
- package/dist/components/feedback.cjs +442 -0
- package/dist/components/feedback.cjs.map +1 -0
- package/dist/components/feedback.css +7 -0
- package/dist/components/feedback.d.cts +144 -0
- package/dist/components/feedback.d.ts +144 -0
- package/dist/components/feedback.js +433 -0
- package/dist/components/feedback.js.map +1 -0
- package/dist/components/fx-gpu.cjs +12 -0
- package/dist/components/fx-gpu.cjs.map +1 -0
- package/dist/components/fx-gpu.d.cts +63 -0
- package/dist/components/fx-gpu.d.ts +63 -0
- package/dist/components/fx-gpu.js +5 -0
- package/dist/components/fx-gpu.js.map +1 -0
- package/dist/components/fx.cjs +169 -0
- package/dist/components/fx.cjs.map +1 -0
- package/dist/components/fx.css +3 -0
- package/dist/components/fx.d.cts +114 -0
- package/dist/components/fx.d.ts +114 -0
- package/dist/components/fx.js +156 -0
- package/dist/components/fx.js.map +1 -0
- package/dist/components/fx2.cjs +25 -0
- package/dist/components/fx2.cjs.map +1 -0
- package/dist/components/fx2.d.cts +136 -0
- package/dist/components/fx2.d.ts +136 -0
- package/dist/components/fx2.js +17 -0
- package/dist/components/fx2.js.map +1 -0
- package/dist/components/gesture.cjs +209 -0
- package/dist/components/gesture.cjs.map +1 -0
- package/dist/components/gesture.css +3 -0
- package/dist/components/gesture.d.cts +134 -0
- package/dist/components/gesture.d.ts +134 -0
- package/dist/components/gesture.js +203 -0
- package/dist/components/gesture.js.map +1 -0
- package/dist/components/interaction.cjs +424 -0
- package/dist/components/interaction.cjs.map +1 -0
- package/dist/components/interaction.css +8 -0
- package/dist/components/interaction.d.cts +115 -0
- package/dist/components/interaction.d.ts +115 -0
- package/dist/components/interaction.js +416 -0
- package/dist/components/interaction.js.map +1 -0
- package/dist/components/jsx.cjs +3 -0
- package/dist/components/jsx.cjs.map +1 -0
- package/dist/components/jsx.d.cts +53 -0
- package/dist/components/jsx.d.ts +53 -0
- package/dist/components/jsx.js +2 -0
- package/dist/components/jsx.js.map +1 -0
- package/dist/components/layout.cjs +257 -0
- package/dist/components/layout.cjs.map +1 -0
- package/dist/components/layout.css +3 -0
- package/dist/components/layout.d.cts +99 -0
- package/dist/components/layout.d.ts +99 -0
- package/dist/components/layout.js +249 -0
- package/dist/components/layout.js.map +1 -0
- package/dist/components/lazy.cjs +92 -0
- package/dist/components/lazy.cjs.map +1 -0
- package/dist/components/lazy.d.cts +48 -0
- package/dist/components/lazy.d.ts +48 -0
- package/dist/components/lazy.js +87 -0
- package/dist/components/lazy.js.map +1 -0
- package/dist/components/lite.cjs +11095 -0
- package/dist/components/lite.cjs.map +1 -0
- package/dist/components/lite.d.cts +4 -0
- package/dist/components/lite.d.ts +4 -0
- package/dist/components/lite.js +10827 -0
- package/dist/components/lite.js.map +1 -0
- package/dist/components/packs.cjs +192 -0
- package/dist/components/packs.cjs.map +1 -0
- package/dist/components/packs.css +3 -0
- package/dist/components/packs.d.cts +72 -0
- package/dist/components/packs.d.ts +72 -0
- package/dist/components/packs.js +184 -0
- package/dist/components/packs.js.map +1 -0
- package/dist/components/page.cjs +824 -0
- package/dist/components/page.cjs.map +1 -0
- package/dist/components/page.css +11 -0
- package/dist/components/page.d.cts +249 -0
- package/dist/components/page.d.ts +249 -0
- package/dist/components/page.js +799 -0
- package/dist/components/page.js.map +1 -0
- package/dist/components/perf.cjs +120 -0
- package/dist/components/perf.cjs.map +1 -0
- package/dist/components/perf.d.cts +98 -0
- package/dist/components/perf.d.ts +98 -0
- package/dist/components/perf.js +110 -0
- package/dist/components/perf.js.map +1 -0
- package/dist/components/physics.cjs +448 -0
- package/dist/components/physics.cjs.map +1 -0
- package/dist/components/physics.css +5 -0
- package/dist/components/physics.d.cts +189 -0
- package/dist/components/physics.d.ts +189 -0
- package/dist/components/physics.js +430 -0
- package/dist/components/physics.js.map +1 -0
- package/dist/components/react.cjs +96 -0
- package/dist/components/react.cjs.map +1 -0
- package/dist/components/react.d.cts +18 -0
- package/dist/components/react.d.ts +18 -0
- package/dist/components/react.js +91 -0
- package/dist/components/react.js.map +1 -0
- package/dist/components/reveal.cjs +362 -0
- package/dist/components/reveal.cjs.map +1 -0
- package/dist/components/reveal.css +5 -0
- package/dist/components/reveal.d.cts +105 -0
- package/dist/components/reveal.d.ts +105 -0
- package/dist/components/reveal.js +353 -0
- package/dist/components/reveal.js.map +1 -0
- package/dist/components/solid.cjs +86 -0
- package/dist/components/solid.cjs.map +1 -0
- package/dist/components/solid.d.cts +1751 -0
- package/dist/components/solid.d.ts +1751 -0
- package/dist/components/solid.js +82 -0
- package/dist/components/solid.js.map +1 -0
- package/dist/components/svelte.cjs +68 -0
- package/dist/components/svelte.cjs.map +1 -0
- package/dist/components/svelte.d.cts +1733 -0
- package/dist/components/svelte.d.ts +1733 -0
- package/dist/components/svelte.js +64 -0
- package/dist/components/svelte.js.map +1 -0
- package/dist/components/svg.cjs +359 -0
- package/dist/components/svg.cjs.map +1 -0
- package/dist/components/svg.css +3 -0
- package/dist/components/svg.d.cts +113 -0
- package/dist/components/svg.d.ts +113 -0
- package/dist/components/svg.js +347 -0
- package/dist/components/svg.js.map +1 -0
- package/dist/components/text.cjs +968 -0
- package/dist/components/text.cjs.map +1 -0
- package/dist/components/text.css +8 -0
- package/dist/components/text.d.cts +342 -0
- package/dist/components/text.d.ts +342 -0
- package/dist/components/text.js +947 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/timeline.cjs +109 -0
- package/dist/components/timeline.cjs.map +1 -0
- package/dist/components/timeline.css +3 -0
- package/dist/components/timeline.d.cts +155 -0
- package/dist/components/timeline.d.ts +155 -0
- package/dist/components/timeline.js +103 -0
- package/dist/components/timeline.js.map +1 -0
- package/dist/components/tokens.cjs +226 -0
- package/dist/components/tokens.cjs.map +1 -0
- package/dist/components/tokens.d.cts +74 -0
- package/dist/components/tokens.d.ts +74 -0
- package/dist/components/tokens.js +211 -0
- package/dist/components/tokens.js.map +1 -0
- package/dist/components/transitions.cjs +430 -0
- package/dist/components/transitions.cjs.map +1 -0
- package/dist/components/transitions.css +5 -0
- package/dist/components/transitions.d.cts +126 -0
- package/dist/components/transitions.d.ts +126 -0
- package/dist/components/transitions.js +423 -0
- package/dist/components/transitions.js.map +1 -0
- package/dist/components/ui.cjs +1050 -0
- package/dist/components/ui.cjs.map +1 -0
- package/dist/components/ui.css +14 -0
- package/dist/components/ui.d.cts +224 -0
- package/dist/components/ui.d.ts +224 -0
- package/dist/components/ui.js +1034 -0
- package/dist/components/ui.js.map +1 -0
- package/dist/components/vue.cjs +67 -0
- package/dist/components/vue.cjs.map +1 -0
- package/dist/components/vue.d.cts +1722 -0
- package/dist/components/vue.d.ts +1722 -0
- package/dist/components/vue.js +64 -0
- package/dist/components/vue.js.map +1 -0
- package/dist/components/webgl.cjs +459 -0
- package/dist/components/webgl.cjs.map +1 -0
- package/dist/components/webgl.css +3 -0
- package/dist/components/webgl.d.cts +133 -0
- package/dist/components/webgl.d.ts +133 -0
- package/dist/components/webgl.js +442 -0
- package/dist/components/webgl.js.map +1 -0
- package/dist/components/widgets.cjs +591 -0
- package/dist/components/widgets.cjs.map +1 -0
- package/dist/components/widgets.d.cts +110 -0
- package/dist/components/widgets.d.ts +110 -0
- package/dist/components/widgets.js +581 -0
- package/dist/components/widgets.js.map +1 -0
- package/dist/components.cjs +351 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.css +75 -0
- package/dist/components.d.cts +2997 -0
- package/dist/components.d.ts +2997 -0
- package/dist/components.js +106 -0
- package/dist/components.js.map +1 -0
- package/dist/components.umd.js +23 -0
- package/dist/components.umd.js.map +1 -0
- package/dist/element.cjs +97 -0
- package/dist/element.cjs.map +1 -0
- package/dist/element.d.cts +215 -0
- package/dist/element.d.ts +215 -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 +149 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +425 -0
- package/dist/index.d.ts +425 -0
- package/dist/index.js +131 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +15 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/presets/extended.cjs +243 -0
- package/dist/presets/extended.cjs.map +1 -0
- package/dist/presets/extended.d.cts +37 -0
- package/dist/presets/extended.d.ts +37 -0
- package/dist/presets/extended.js +239 -0
- package/dist/presets/extended.js.map +1 -0
- package/dist/presets-extended.umd.js +2 -0
- package/dist/presets-extended.umd.js.map +1 -0
- package/dist/react.cjs +68 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +158 -0
- package/dist/react.d.ts +158 -0
- package/dist/react.js +65 -0
- package/dist/react.js.map +1 -0
- package/dist/solid.cjs +93 -0
- package/dist/solid.cjs.map +1 -0
- package/dist/solid.d.cts +249 -0
- package/dist/solid.d.ts +249 -0
- package/dist/solid.js +89 -0
- package/dist/solid.js.map +1 -0
- package/dist/svelte.cjs +66 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +243 -0
- package/dist/svelte.d.ts +243 -0
- package/dist/svelte.js +63 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vue.cjs +62 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +158 -0
- package/dist/vue.d.ts +158 -0
- package/dist/vue.js +60 -0
- package/dist/vue.js.map +1 -0
- package/dist/widgets.umd.js +2 -0
- package/dist/widgets.umd.js.map +1 -0
- package/docs/API.md +147 -0
- package/docs/ROADMAP.md +14 -0
- package/docs/accessibility.md +60 -0
- package/docs/components.md +564 -0
- package/docs/deprecations.md +30 -0
- package/docs/frameworks-ssr.md +100 -0
- package/docs/hybrid-apps.md +145 -0
- package/docs/images/showcase-detail.png +0 -0
- package/docs/images/showcase-grid.png +0 -0
- package/docs/images/showcase-mobile.png +0 -0
- package/docs/migration-from-aos.md +67 -0
- package/docs/migration-from-gsap-scrolltrigger.md +80 -0
- package/docs/motion-tokens.css +31 -0
- package/docs/motion-tokens.md +46 -0
- package/docs/motion.tokens.json +132 -0
- package/docs/performance.md +24 -0
- package/docs/presets.md +310 -0
- package/docs/upgrading-3.md +21 -0
- package/docs/upgrading-4.md +65 -0
- package/docs/upgrading-5.md +31 -0
- package/docs/upgrading-6.md +32 -0
- package/docs/windows-apps.md +119 -0
- package/package.json +562 -4
package/dist/solid.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createRenderEffect, onMount, onCleanup } from 'solid-js';
|
|
2
|
+
import { c as createScrollAnimate } from './chunks/core-D7cVumUu.js';
|
|
3
|
+
import { s as staggerChildren } from './chunks/stagger-DtMKo2SK.js';
|
|
4
|
+
import './chunks/presets-BYBVJVeP.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* motionary - Solid integration
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { scrollAnimate, scrollStagger, useScrollAnimate } from 'motionary/solid';
|
|
11
|
+
* false && scrollAnimate; // keep the directive import (TypeScript)
|
|
12
|
+
*
|
|
13
|
+
* <div use:scrollAnimate={{ animation: 'zoom-in' }}>…</div>
|
|
14
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
15
|
+
* <div ref={useScrollAnimate({ animation: 'fade-in-up' })}>…</div>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* `solid-js` is an optional peer dependency (only needed for this entry).
|
|
19
|
+
*/
|
|
20
|
+
let shared = null;
|
|
21
|
+
const getInstance = (own) => own || shared || (shared = createScrollAnimate());
|
|
22
|
+
function read(accessor) {
|
|
23
|
+
const v = accessor?.();
|
|
24
|
+
return (v && v !== true ? v : {});
|
|
25
|
+
}
|
|
26
|
+
const CALLBACKS = ['onStart', 'onComplete', 'onEnter', 'onLeave', 'onProgress'];
|
|
27
|
+
/** Callbacks always call the latest options' version. */
|
|
28
|
+
function liveCallbacks(opts, latest) {
|
|
29
|
+
const out = { ...opts };
|
|
30
|
+
CALLBACKS.forEach((name) => {
|
|
31
|
+
if (typeof opts[name] === 'function')
|
|
32
|
+
out[name] = (...args) => latest()[name]?.(...args);
|
|
33
|
+
});
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Directive: `<div use:scrollAnimate={{ animation: 'fade-in' }} />`.
|
|
38
|
+
* 4.0.1: the accessor is tracked — when signals it reads change, callbacks
|
|
39
|
+
* update right away and the other options are re-applied if the element has
|
|
40
|
+
* not animated yet (no manual `refresh()` needed).
|
|
41
|
+
*/
|
|
42
|
+
function scrollAnimate(el, accessor) {
|
|
43
|
+
let latest = {};
|
|
44
|
+
let mounted = false;
|
|
45
|
+
let sa = null;
|
|
46
|
+
const apply = () => {
|
|
47
|
+
const { instance, ...opts } = latest;
|
|
48
|
+
const record = sa?.getObservedElements().find((r) => r.element === el);
|
|
49
|
+
if (sa && record?.animated)
|
|
50
|
+
return; // finished: callbacks stay live
|
|
51
|
+
sa?.unobserve(el);
|
|
52
|
+
sa = getInstance(instance);
|
|
53
|
+
sa.observe(el, liveCallbacks(opts, () => latest));
|
|
54
|
+
};
|
|
55
|
+
createRenderEffect(() => {
|
|
56
|
+
latest = read(accessor);
|
|
57
|
+
if (mounted)
|
|
58
|
+
apply();
|
|
59
|
+
});
|
|
60
|
+
// Wait until the element is in the document (directives/refs run before insertion).
|
|
61
|
+
onMount(() => {
|
|
62
|
+
mounted = true;
|
|
63
|
+
apply();
|
|
64
|
+
});
|
|
65
|
+
onCleanup(() => sa?.unobserve(el));
|
|
66
|
+
}
|
|
67
|
+
/** Directive: `<ul use:scrollStagger={{ stagger: 60, observeChildren: true }} />` */
|
|
68
|
+
function scrollStagger(el, accessor) {
|
|
69
|
+
const { instance, ...opts } = read(accessor);
|
|
70
|
+
let stop;
|
|
71
|
+
onMount(() => {
|
|
72
|
+
stop = staggerChildren(el, opts, getInstance(instance));
|
|
73
|
+
});
|
|
74
|
+
onCleanup(() => stop?.());
|
|
75
|
+
}
|
|
76
|
+
/** Primitive returning a `ref` callback: `<div ref={useScrollAnimate({ animation: 'fade-in-up' })} />` */
|
|
77
|
+
function useScrollAnimate(options = {}) {
|
|
78
|
+
let el;
|
|
79
|
+
const { instance, ...opts } = options;
|
|
80
|
+
const sa = getInstance(instance);
|
|
81
|
+
onMount(() => el && sa.observe(el, opts));
|
|
82
|
+
onCleanup(() => el && sa.unobserve(el));
|
|
83
|
+
return (node) => {
|
|
84
|
+
el = node;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { scrollAnimate, scrollStagger, useScrollAnimate };
|
|
89
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.js","sources":["../src/solid.ts"],"sourcesContent":["/**\n * motionary - Solid integration\n *\n * ```tsx\n * import { scrollAnimate, scrollStagger, useScrollAnimate } from 'motionary/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 { createRenderEffect, 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\nconst CALLBACKS = ['onStart', 'onComplete', 'onEnter', 'onLeave', 'onProgress'] as const;\n\n/** Callbacks always call the latest options' 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 * Directive: `<div use:scrollAnimate={{ animation: 'fade-in' }} />`.\n * 4.0.1: the accessor is tracked — when signals it reads change, callbacks\n * update right away and the other options are re-applied if the element has\n * not animated yet (no manual `refresh()` needed).\n */\nexport function scrollAnimate(el: Element, accessor?: () => SolidScrollAnimateOptions | true | undefined): void {\n let latest: SolidScrollAnimateOptions = {};\n let mounted = false;\n let sa: ScrollAnimateInstance | null = null;\n const apply = () => {\n const { instance, ...opts } = latest;\n const record = sa?.getObservedElements().find((r) => r.element === el);\n if (sa && record?.animated) return; // finished: callbacks stay live\n sa?.unobserve(el);\n sa = getInstance(instance);\n sa.observe(el, liveCallbacks(opts, () => latest));\n };\n createRenderEffect(() => {\n latest = read<SolidScrollAnimateOptions>(accessor);\n if (mounted) apply();\n });\n // Wait until the element is in the document (directives/refs run before insertion).\n onMount(() => {\n mounted = true;\n apply();\n });\n onCleanup(() => sa?.unobserve(el));\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;;;;;;;;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C,EAAE,CAAC,CAAC;IACvC,OAAO,CAAC,IAAa,KAAI;QACvB,EAAE,GAAG,IAAI;AACX,IAAA,CAAC;AACH;;;;"}
|
package/dist/svelte.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('./chunks/core-B5T0dhFH.cjs');
|
|
4
|
+
var stagger = require('./chunks/stagger-CCFyhzSw.cjs');
|
|
5
|
+
require('./chunks/presets-CUHys3sK.cjs');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* motionary - Svelte integration
|
|
9
|
+
*
|
|
10
|
+
* Svelte actions (no import from `svelte` needed, works with Svelte 3, 4 and 5):
|
|
11
|
+
*
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <script>
|
|
14
|
+
* import { scrollAnimate, scrollStagger } from 'motionary/svelte';
|
|
15
|
+
* </script>
|
|
16
|
+
* <div use:scrollAnimate={{ animation: 'fade-in-up', duration: 800 }}>…</div>
|
|
17
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
let shared = null;
|
|
21
|
+
const getInstance = (own) => own || shared || (shared = core.createScrollAnimate());
|
|
22
|
+
const CALLBACKS = ['onStart', 'onComplete', 'onEnter', 'onLeave', 'onProgress'];
|
|
23
|
+
/** Callbacks always call the latest parameter's version. */
|
|
24
|
+
function liveCallbacks(opts, latest) {
|
|
25
|
+
const out = { ...opts };
|
|
26
|
+
CALLBACKS.forEach((name) => {
|
|
27
|
+
if (typeof opts[name] === 'function')
|
|
28
|
+
out[name] = (...args) => latest()[name]?.(...args);
|
|
29
|
+
});
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Animate `node` when it scrolls into view. Changing the parameter updates the
|
|
34
|
+
* callbacks right away; other options are applied if the element has not
|
|
35
|
+
* animated yet.
|
|
36
|
+
*/
|
|
37
|
+
function scrollAnimate(node, options = {}) {
|
|
38
|
+
let current = options;
|
|
39
|
+
const { instance, ...opts } = options;
|
|
40
|
+
const sa = getInstance(instance);
|
|
41
|
+
sa.observe(node, liveCallbacks(opts, () => current));
|
|
42
|
+
return {
|
|
43
|
+
update(next = {}) {
|
|
44
|
+
current = next;
|
|
45
|
+
const record = sa.getObservedElements().find((r) => r.element === node);
|
|
46
|
+
if (record && !record.animated) {
|
|
47
|
+
const { instance: _ignored, ...nextOpts } = next;
|
|
48
|
+
sa.unobserve(node);
|
|
49
|
+
sa.observe(node, liveCallbacks(nextOpts, () => current));
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
destroy() {
|
|
53
|
+
sa.unobserve(node);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Stagger the children of `node` when it scrolls into view (`observeChildren: true` also animates children added later). */
|
|
58
|
+
function scrollStagger(node, options = {}) {
|
|
59
|
+
const { instance, ...opts } = options;
|
|
60
|
+
const stop = stagger.staggerChildren(node, opts, getInstance(instance));
|
|
61
|
+
return { destroy: stop };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.scrollAnimate = scrollAnimate;
|
|
65
|
+
exports.scrollStagger = scrollStagger;
|
|
66
|
+
//# sourceMappingURL=svelte.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.cjs","sources":["../src/svelte.ts"],"sourcesContent":["/**\n * motionary - 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 'motionary/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":";;;;;;AAA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,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;;;;;"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* motionary - Core Type Definitions
|
|
3
|
+
* A lightweight, high-performance scroll animation library
|
|
4
|
+
*/
|
|
5
|
+
/** The 33 core presets (always available in `PRESETS`). */
|
|
6
|
+
type CorePreset = '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
|
+
* Every built-in preset name: the core set plus the 6.1 extended set, which is
|
|
9
|
+
* available once `motionary/presets/extended` is loaded (or after
|
|
10
|
+
* `registerPresets(EXTENDED_PRESETS)`).
|
|
11
|
+
*/
|
|
12
|
+
type AnimationPreset = CorePreset | ExtendedPreset;
|
|
13
|
+
/**
|
|
14
|
+
* How `onProgress` / `progressVar` progress is measured.
|
|
15
|
+
* - `'ratio'` (default): the element's visible ratio (IntersectionObserver `intersectionRatio`).
|
|
16
|
+
* - `'scroll'`: true scroll progress, 0 when the element's top touches the bottom of the
|
|
17
|
+
* viewport and 1 when its bottom leaves the top. Works for elements taller than the screen.
|
|
18
|
+
*/
|
|
19
|
+
type ProgressMode = 'ratio' | 'scroll';
|
|
20
|
+
/**
|
|
21
|
+
* Which engine runs the entrance animation.
|
|
22
|
+
* - `'js'`: IntersectionObserver triggers a time-based Web Animation.
|
|
23
|
+
* - `'css'`: the preset runs on the browser's native scroll-driven timeline
|
|
24
|
+
* (`animation-timeline: view()`), so its progress follows the scroll position
|
|
25
|
+
* off the main thread. Falls back to `'js'` where unsupported.
|
|
26
|
+
* - `'auto'` (default since 2.0): native when supported, JS otherwise — and JS
|
|
27
|
+
* whenever the element sets `duration`, `delay`, `offset` or `stagger` itself,
|
|
28
|
+
* since those only mean something for a time-based animation.
|
|
29
|
+
*/
|
|
30
|
+
type ScrollEngine = 'auto' | 'js' | 'css';
|
|
31
|
+
/** The 6.1 extended presets (`motionary/presets/extended`). */
|
|
32
|
+
type ExtendedPreset = 'fade-in-up-sm' | 'fade-in-down-sm' | 'fade-in-left-sm' | 'fade-in-right-sm' | 'fade-in-up-lg' | 'fade-in-down-lg' | 'fade-in-left-lg' | 'fade-in-right-lg' | 'fade-in-up-left' | 'fade-in-up-right' | 'fade-in-down-left' | 'fade-in-down-right' | 'fade-in-scale' | 'fade-in-half' | 'zoom-in-up' | 'zoom-in-down' | 'zoom-in-left' | 'zoom-in-right' | 'zoom-out-up' | 'zoom-out-down' | 'zoom-out-left' | 'zoom-out-right' | 'zoom-in-big' | 'zoom-out-big' | 'zoom-bounce' | 'zoom-in-rotate' | 'scale-x-left' | 'scale-x-right' | 'scale-y-top' | 'scale-y-bottom' | 'stretch-x' | 'stretch-y' | 'flip-x-reverse' | 'flip-y-reverse' | 'flip-y-full' | 'flip-diagonal' | 'flip-diagonal-reverse' | 'flip-left' | 'flip-right' | 'unfold-down' | 'unfold-up' | 'door-open-left' | 'door-open-right' | 'fold-in' | 'flip-x-bounce' | 'flip-y-bounce' | 'swing-in-top' | 'swing-in-bottom' | 'swing-in-left' | 'swing-in-right' | 'slide-up-spring' | 'slide-down-spring' | 'slide-left-spring' | 'slide-right-spring' | 'slide-up-sm' | 'slide-down-sm' | 'back-in-up' | 'back-in-down' | 'back-in-left' | 'back-in-right' | 'light-speed-in-left' | 'light-speed-in-right' | 'rise-in' | 'sink-in' | 'float-in-up' | 'float-in-down' | 'roll-in-left' | 'roll-in-right' | 'spiral-in' | 'spiral-in-reverse' | 'spin-in' | 'rotate-in-up-left' | 'rotate-in-up-right' | 'rotate-in-down-left' | 'rotate-in-down-right' | 'skew-in-left' | 'skew-in-y' | 'shear-in' | 'shear-in-reverse' | 'twist-in' | 'tilt-in-left' | 'tilt-in-right' | 'blur-in-down' | 'blur-in-left' | 'blur-in-right' | 'blur-in-strong' | 'blur-in-zoom' | 'blur-in-scale' | 'blur-in-x' | 'mask-up' | 'mask-down' | 'mask-left' | 'mask-right' | 'blur-mask-up' | 'clip-circle-top' | 'clip-circle-bottom' | 'clip-circle-left' | 'clip-circle-right' | 'clip-circle-corner' | 'clip-ellipse' | 'clip-diamond' | 'clip-split-x' | 'clip-split-y' | 'clip-box' | 'clip-pill' | 'clip-blinds' | 'clip-blinds-x' | 'clip-diagonal' | 'clip-diagonal-reverse' | 'clip-slant-right' | 'clip-slant-left' | 'bounce-in' | 'bounce-in-up' | 'bounce-in-down' | 'bounce-in-left' | 'bounce-in-right' | 'elastic-in' | 'elastic-in-x' | 'rubber-in' | 'jello-in' | 'wobble-in' | 'tada-in' | 'heartbeat-in' | 'drop-in' | 'pop-in' | 'squash-in' | 'shake-in' | 'swing-in' | 'brightness-in' | 'darken-in' | 'color-in' | 'saturate-in' | 'hue-in' | 'sepia-in' | 'invert-in' | 'contrast-in' | 'exposure-in' | 'vintage-in' | 'blur-bright-in' | 'shadow-lift' | 'neon-glow-in' | 'glow-in' | 'perspective-in-up' | 'perspective-in-down' | 'perspective-in-left' | 'perspective-in-right' | 'depth-push' | 'depth-pull' | 'depth-in-up' | 'swoop-in-left' | 'swoop-in-right' | 'card-tilt-in' | 'glitch-in' | 'glitch-in-color' | 'typewriter' | 'typewriter-lines' | 'hinge-in' | 'flicker-in' | 'scan-in' | 'materialize' | 'teleport-in' | 'stagger-fade-up' | 'stagger-pop' | 'stagger-rise' | 'stagger-slide' | 'stagger-flip' | 'stagger-blur' | 'stagger-zoom' | 'stagger-drop' | 'scrub-parallax-up' | 'scrub-parallax-down' | 'scrub-rotate' | 'scrub-spin' | 'scrub-scale' | 'scrub-shrink' | 'scrub-pan-left' | 'scrub-pan-right' | 'scrub-tilt' | 'scrub-fade-through' | 'scrub-blur-through' | 'scrub-reveal-x';
|
|
33
|
+
/** Easing function types */
|
|
34
|
+
type EasingType = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'spring' | 'soft-spring' | 'heavy-bounce' | [number, number, number, number] | ((t: number) => number) | string;
|
|
35
|
+
/** Keyframe definition for custom animations */
|
|
36
|
+
interface AnimationKeyframe {
|
|
37
|
+
[property: string]: string | number;
|
|
38
|
+
}
|
|
39
|
+
/** One intermediate keyframe of a preset: `offset` is 0 < offset < 1. */
|
|
40
|
+
interface AnimationFrame extends AnimationKeyframe {
|
|
41
|
+
offset: number;
|
|
42
|
+
}
|
|
43
|
+
/** Custom animation definition */
|
|
44
|
+
interface CustomAnimation {
|
|
45
|
+
from: AnimationKeyframe;
|
|
46
|
+
to: AnimationKeyframe;
|
|
47
|
+
/** Optional intermediate keyframes (overshoot, bounce, …), played between `from` and `to`. */
|
|
48
|
+
frames?: AnimationFrame[];
|
|
49
|
+
}
|
|
50
|
+
/** Per-element animation options */
|
|
51
|
+
interface AnimateOptions {
|
|
52
|
+
/** Animation preset name, array of presets, or custom animation object */
|
|
53
|
+
animation?: AnimationPreset | AnimationPreset[] | CustomAnimation;
|
|
54
|
+
/** Duration in milliseconds (default: 600) */
|
|
55
|
+
duration?: number;
|
|
56
|
+
/** Delay in milliseconds (default: 0) */
|
|
57
|
+
delay?: number;
|
|
58
|
+
/** Easing function (default: 'ease') */
|
|
59
|
+
easing?: EasingType;
|
|
60
|
+
/** Intersection threshold 0-1 (default: 0.1) */
|
|
61
|
+
threshold?: number | number[];
|
|
62
|
+
/** Root margin for IntersectionObserver (default: '0px') */
|
|
63
|
+
rootMargin?: string;
|
|
64
|
+
/** Whether to replay animation each time element enters viewport (default: false) */
|
|
65
|
+
repeat?: boolean;
|
|
66
|
+
/** Whether to trigger animation only once (default: true if repeat is false) */
|
|
67
|
+
once?: boolean;
|
|
68
|
+
/** Offset in pixels from the viewport edge to trigger animation (default: 0) */
|
|
69
|
+
offset?: number;
|
|
70
|
+
/** Stagger delay for child elements in ms (default: 0) */
|
|
71
|
+
stagger?: number;
|
|
72
|
+
/** Callback fired when animation starts */
|
|
73
|
+
onStart?: (element: Element) => void;
|
|
74
|
+
/** Callback fired when animation completes */
|
|
75
|
+
onComplete?: (element: Element) => void;
|
|
76
|
+
/** Callback fired when element enters viewport */
|
|
77
|
+
onEnter?: (element: Element) => void;
|
|
78
|
+
/** Callback fired when element leaves viewport */
|
|
79
|
+
onLeave?: (element: Element) => void;
|
|
80
|
+
/** Callback fired with scroll progress (0 to 1) */
|
|
81
|
+
onProgress?: (element: Element, progress: number) => void;
|
|
82
|
+
/** How progress for `onProgress`/`progressVar` is measured (default: 'ratio') */
|
|
83
|
+
progressMode?: ProgressMode;
|
|
84
|
+
/**
|
|
85
|
+
* Name of a CSS custom property (e.g. `'--sa-progress'`) that receives the
|
|
86
|
+
* element's progress (0 to 1, same value as `onProgress`) as an inline
|
|
87
|
+
* style, for scroll-driven effects written in plain CSS. Off by default.
|
|
88
|
+
*/
|
|
89
|
+
progressVar?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Animation engine (default: `'auto'`, see `ScrollEngine`). With the native
|
|
92
|
+
* engine the animation is linked to scroll position: `duration`, `delay`,
|
|
93
|
+
* `threshold`, `offset` and `stagger` do not apply; `viewRange` does.
|
|
94
|
+
*/
|
|
95
|
+
engine?: ScrollEngine;
|
|
96
|
+
/**
|
|
97
|
+
* Native engine only: the view-timeline range the entrance animation spans,
|
|
98
|
+
* as `[rangeStart, rangeEnd]` (default: `['entry 0%', 'entry 100%']`).
|
|
99
|
+
*/
|
|
100
|
+
viewRange?: [string, string];
|
|
101
|
+
/**
|
|
102
|
+
* Animate out when the element leaves the viewport, and back in when it
|
|
103
|
+
* re-enters (implies `repeat: true` unless `repeat` is set).
|
|
104
|
+
* - `true`: play the entrance animation in reverse.
|
|
105
|
+
* - a preset / presets / `{ from, to }`: play that animation in reverse
|
|
106
|
+
* (e.g. `exit: 'fade-in-down'` leaves upwards).
|
|
107
|
+
* Skipped under reduced motion. (default: `false`)
|
|
108
|
+
*/
|
|
109
|
+
exit?: boolean | AnimationPreset | AnimationPreset[] | CustomAnimation;
|
|
110
|
+
}
|
|
111
|
+
/** Global configuration for ScrollAnimate instance */
|
|
112
|
+
interface ScrollAnimateConfig {
|
|
113
|
+
/** Default animation preset (default: 'fade-in-up') */
|
|
114
|
+
defaultAnimation?: AnimationPreset | AnimationPreset[] | CustomAnimation;
|
|
115
|
+
/** Default duration in ms (default: 600) */
|
|
116
|
+
defaultDuration?: number;
|
|
117
|
+
/** Default delay in ms (default: 0) */
|
|
118
|
+
defaultDelay?: number;
|
|
119
|
+
/** Default easing (default: 'ease') */
|
|
120
|
+
defaultEasing?: EasingType;
|
|
121
|
+
/** Default threshold (default: 0.1) */
|
|
122
|
+
defaultThreshold?: number | number[];
|
|
123
|
+
/** Default root margin (default: '0px') */
|
|
124
|
+
defaultRootMargin?: string;
|
|
125
|
+
/** Whether animations replay by default (default: false) */
|
|
126
|
+
defaultRepeat?: boolean;
|
|
127
|
+
/** Default once setting (default: true) */
|
|
128
|
+
defaultOnce?: boolean;
|
|
129
|
+
/** Default offset in pixels (default: 0) */
|
|
130
|
+
defaultOffset?: number;
|
|
131
|
+
/** CSS class added before animation (default: 'sa-hidden') */
|
|
132
|
+
hiddenClass?: string;
|
|
133
|
+
/** CSS class added when element is visible (default: 'sa-visible') */
|
|
134
|
+
visibleClass?: string;
|
|
135
|
+
/** Whether to use CSS class-based animation instead of Web Animations API */
|
|
136
|
+
useClassNames?: boolean;
|
|
137
|
+
/** Disable all animations (useful for reduced-motion preference) */
|
|
138
|
+
disabled?: boolean;
|
|
139
|
+
/** Custom IntersectionObserver root element */
|
|
140
|
+
root?: Element | null;
|
|
141
|
+
/**
|
|
142
|
+
* Drop `once` elements from the registry as soon as their entrance animation
|
|
143
|
+
* has been triggered (unless they still need onProgress/progressVar), so they can
|
|
144
|
+
* be garbage-collected. They are remembered in a WeakSet, so `init()`/`observe()`
|
|
145
|
+
* never re-hide or replay them. (default: true)
|
|
146
|
+
*/
|
|
147
|
+
autoUnregister?: boolean;
|
|
148
|
+
/** Default animation engine (default: `'auto'`; `'js'` restores the 1.x behaviour) */
|
|
149
|
+
defaultEngine?: ScrollEngine;
|
|
150
|
+
}
|
|
151
|
+
/** Registered element entry */
|
|
152
|
+
interface AnimatedElement {
|
|
153
|
+
element: Element;
|
|
154
|
+
options: Required<AnimateOptions>;
|
|
155
|
+
observer: IntersectionObserver;
|
|
156
|
+
animated: boolean;
|
|
157
|
+
progressObserver?: IntersectionObserver;
|
|
158
|
+
/** Engine actually used for this element (`'css'` = native scroll-driven timeline) */
|
|
159
|
+
engine?: 'js' | 'css';
|
|
160
|
+
}
|
|
161
|
+
/** ScrollAnimate public API */
|
|
162
|
+
interface ScrollAnimateInstance {
|
|
163
|
+
/** Observe a single element or CSS selector */
|
|
164
|
+
observe(target: string | Element | NodeList | Element[], options?: AnimateOptions): void;
|
|
165
|
+
/** Stop observing a single element or CSS selector */
|
|
166
|
+
unobserve(target: string | Element | NodeList | Element[]): void;
|
|
167
|
+
/** Observe all elements matching the data-sa attribute */
|
|
168
|
+
init(rootElement?: Element | Document): void;
|
|
169
|
+
/**
|
|
170
|
+
* Like `init()`, then keep watching `rootElement` (default: `document`) with a
|
|
171
|
+
* MutationObserver: `[data-sa]` elements added later (or that gain the
|
|
172
|
+
* attribute) are observed automatically, and removed ones are released.
|
|
173
|
+
* Returns a function that stops watching. `destroy()` stops every watcher.
|
|
174
|
+
* SSR-safe: a no-op without a DOM / MutationObserver.
|
|
175
|
+
*/
|
|
176
|
+
watch(rootElement?: Element | Document): () => void;
|
|
177
|
+
/** Destroy the instance and clean up all observers */
|
|
178
|
+
destroy(): void;
|
|
179
|
+
/** Refresh all observers (useful after DOM changes) */
|
|
180
|
+
refresh(): void;
|
|
181
|
+
/** Manually trigger animation on an element */
|
|
182
|
+
animate(target: string | Element, options?: AnimateOptions): void;
|
|
183
|
+
/** Get all currently observed elements */
|
|
184
|
+
getObservedElements(): AnimatedElement[];
|
|
185
|
+
/** Update global configuration */
|
|
186
|
+
configure(config: Partial<ScrollAnimateConfig>): void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* motionary - Staggered children
|
|
191
|
+
* Reveal a container's children one after another when the container scrolls
|
|
192
|
+
* into view, optionally also animating children that are added later.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
interface StaggerOptions extends AnimateOptions {
|
|
196
|
+
/** Delay between consecutive children in ms (default: 80) */
|
|
197
|
+
stagger?: number;
|
|
198
|
+
/**
|
|
199
|
+
* Watch the container with a MutationObserver and animate children added
|
|
200
|
+
* later (e.g. infinite lists). Children added after the container was
|
|
201
|
+
* revealed animate when they scroll into view, staggered per batch.
|
|
202
|
+
* (default: false)
|
|
203
|
+
*/
|
|
204
|
+
observeChildren?: boolean;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* motionary - Svelte integration
|
|
209
|
+
*
|
|
210
|
+
* Svelte actions (no import from `svelte` needed, works with Svelte 3, 4 and 5):
|
|
211
|
+
*
|
|
212
|
+
* ```svelte
|
|
213
|
+
* <script>
|
|
214
|
+
* import { scrollAnimate, scrollStagger } from 'motionary/svelte';
|
|
215
|
+
* </script>
|
|
216
|
+
* <div use:scrollAnimate={{ animation: 'fade-in-up', duration: 800 }}>…</div>
|
|
217
|
+
* <ul use:scrollStagger={{ stagger: 60 }}>…</ul>
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
interface ScrollAnimateActionOptions extends AnimateOptions {
|
|
222
|
+
/** Instance to register with (default: a shared instance created on first use) */
|
|
223
|
+
instance?: ScrollAnimateInstance;
|
|
224
|
+
}
|
|
225
|
+
interface ScrollStaggerActionOptions extends StaggerOptions {
|
|
226
|
+
instance?: ScrollAnimateInstance;
|
|
227
|
+
}
|
|
228
|
+
/** Shape of a Svelte action's return value. */
|
|
229
|
+
interface ActionReturn<P> {
|
|
230
|
+
update?: (parameter: P) => void;
|
|
231
|
+
destroy?: () => void;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Animate `node` when it scrolls into view. Changing the parameter updates the
|
|
235
|
+
* callbacks right away; other options are applied if the element has not
|
|
236
|
+
* animated yet.
|
|
237
|
+
*/
|
|
238
|
+
declare function scrollAnimate(node: Element, options?: ScrollAnimateActionOptions): ActionReturn<ScrollAnimateActionOptions | undefined>;
|
|
239
|
+
/** Stagger the children of `node` when it scrolls into view (`observeChildren: true` also animates children added later). */
|
|
240
|
+
declare function scrollStagger(node: Element, options?: ScrollStaggerActionOptions): ActionReturn<ScrollStaggerActionOptions | undefined>;
|
|
241
|
+
|
|
242
|
+
export { scrollAnimate, scrollStagger };
|
|
243
|
+
export type { ActionReturn, ScrollAnimateActionOptions, ScrollStaggerActionOptions };
|