use-scroll-animate 5.8.0 → 5.9.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 +16 -0
- package/bin/usa-codemod-6.mjs +146 -0
- package/dist/components/angular.d.cts +2 -1
- package/dist/components/angular.d.ts +2 -1
- package/dist/components/click.cjs +23 -4
- package/dist/components/click.cjs.map +1 -1
- package/dist/components/click.d.cts +12 -7
- package/dist/components/click.d.ts +12 -7
- package/dist/components/click.js +28 -9
- package/dist/components/click.js.map +1 -1
- package/dist/components/effects.cjs +306 -1
- package/dist/components/effects.cjs.map +1 -1
- package/dist/components/effects.d.cts +66 -2
- package/dist/components/effects.d.ts +66 -2
- package/dist/components/effects.js +303 -2
- package/dist/components/effects.js.map +1 -1
- package/dist/components/fx.cjs +2 -2
- package/dist/components/fx.cjs.map +1 -1
- package/dist/components/fx.js +2 -2
- package/dist/components/fx.js.map +1 -1
- package/dist/components/lite.cjs +35 -14
- package/dist/components/lite.cjs.map +1 -1
- package/dist/components/lite.js +35 -14
- package/dist/components/lite.js.map +1 -1
- package/dist/components/page.cjs +2 -0
- package/dist/components/page.cjs.map +1 -1
- package/dist/components/page.js +3 -1
- package/dist/components/page.js.map +1 -1
- package/dist/components/solid.d.cts +2 -1
- package/dist/components/solid.d.ts +2 -1
- package/dist/components/svelte.d.cts +2 -1
- package/dist/components/svelte.d.ts +2 -1
- package/dist/components/vue.d.cts +2 -1
- package/dist/components/vue.d.ts +2 -1
- package/dist/components.cjs +5 -5
- package/dist/components.d.cts +12 -7
- package/dist/components.d.ts +12 -7
- package/dist/components.js +2 -2
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/docs/ROADMAP.md +1 -1
- package/docs/components.md +26 -0
- package/docs/deprecations.md +4 -0
- package/docs/upgrading-6.md +32 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [5.9.0] - 2026-10-08
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **`<usa-player>`** (`use-scroll-animate/components/effects`, `definePlayer()`) — plays JSON animations (`format: "use-scroll-animate/animation"`, `version: 1`): tracks with a `target` selector, `start` / `duration`, and a timeline `preset`, your own `keyframes` + `easing`, or any registered `effect` fired at `start`. Source: `src="…json"` or an inline `<script type="application/json">`. `trigger="load | view | scroll | click | manual"` (`scroll` scrubs with the page), `loop`, `rate`, `controls`; methods `play()`, `pause()`, `seek(ms)`, `load(json)`; events `usa-player-ready`, `usa-player-finish`; `data-error` on bad input.
|
|
14
|
+
- `createPlayer(root, animation, { autoplay, loop, rate })` → `{ play, pause, seek, rate, duration, currentTime, playing, finished, destroy }` — keyframe tracks are WAAPI animations driven by one clock; `normalizeAnimation()` validates (and reads Playground presets too).
|
|
15
|
+
- Playground: new **`<usa-player> JSON`** export tab (`tracksToAnimation()`).
|
|
16
|
+
- The registered `burst` effect accepts `x` / `y`.
|
|
17
|
+
- `docs/upgrading-6.md` and **`npx usa-codemod-6 [--write] [paths]`**.
|
|
18
|
+
|
|
19
|
+
### Deprecated (removed in 6.0 — warned once in the console)
|
|
20
|
+
- `burst()`, `confetti()`, `shake()` (components / components/click entries, UMD global) → `playEffect(el, 'burst' | 'confetti' | 'shake', …)` — the codemod rewrites calls and imports.
|
|
21
|
+
- `<usa-cursor mode="trail">` → the 5.7 `comet-trail` effect (`<usa-fx effect="comet-trail" trigger="load" self>`) — reported by the codemod for a manual edit.
|
|
22
|
+
|
|
23
|
+
### Accessibility
|
|
24
|
+
- Under reduced motion `<usa-player>` jumps to the final state and fires no effects.
|
|
25
|
+
|
|
10
26
|
## [5.8.0] - 2026-10-08
|
|
11
27
|
|
|
12
28
|
### Added
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// use-scroll-animate 5.x → 6.0 codemod.
|
|
3
|
+
// npx usa-codemod-6 [--write] [paths…] (default: ./src; dry run without --write)
|
|
4
|
+
// Rewrites (5.9 deprecations, removed in 6.0 — every effect goes through the registry):
|
|
5
|
+
// 1. burst(x, y[, opts]) → playEffect(document.body, 'burst', { x: x, y: y[, ...opts] })
|
|
6
|
+
// 2. confetti([opts]) → playEffect(document.body, 'confetti'[, opts])
|
|
7
|
+
// 3. shake(el[, i[, d]]) → playEffect(el, 'shake'[, { intensity: i[, duration: d] }])
|
|
8
|
+
// …and the import of burst / confetti / shake from use-scroll-animate/components[/click]
|
|
9
|
+
// becomes `import { playEffect } from 'use-scroll-animate/components/fx'`.
|
|
10
|
+
// Reported for a manual change (no safe rewrite):
|
|
11
|
+
// 4. <usa-cursor mode="trail"> → <usa-fx effect="comet-trail" trigger="load" self> around the content
|
|
12
|
+
import { readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs';
|
|
13
|
+
import { join, extname } from 'node:path';
|
|
14
|
+
import { pathToFileURL } from 'node:url';
|
|
15
|
+
|
|
16
|
+
const EXT = new Set(['.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx', '.mts', '.cts', '.vue', '.svelte', '.html', '.astro']);
|
|
17
|
+
const OLD = ['burst', 'confetti', 'shake'];
|
|
18
|
+
|
|
19
|
+
/** Split a call's argument list at top-level commas (pure). */
|
|
20
|
+
export function splitArgs(s) {
|
|
21
|
+
const out = [];
|
|
22
|
+
let depth = 0;
|
|
23
|
+
let cur = '';
|
|
24
|
+
let q = '';
|
|
25
|
+
for (let i = 0; i < s.length; i++) {
|
|
26
|
+
const c = s[i];
|
|
27
|
+
if (q) {
|
|
28
|
+
cur += c;
|
|
29
|
+
if (c === '\\') cur += s[++i] ?? '';
|
|
30
|
+
else if (c === q) q = '';
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (c === '"' || c === "'" || c === '`') q = c;
|
|
34
|
+
else if ('([{'.includes(c)) depth++;
|
|
35
|
+
else if (')]}'.includes(c)) depth--;
|
|
36
|
+
if (c === ',' && depth === 0) {
|
|
37
|
+
out.push(cur.trim());
|
|
38
|
+
cur = '';
|
|
39
|
+
} else cur += c;
|
|
40
|
+
}
|
|
41
|
+
if (cur.trim()) out.push(cur.trim());
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Find `name(` calls and their balanced argument text. */
|
|
46
|
+
function rewriteCalls(code, name, fn, changes) {
|
|
47
|
+
const re = new RegExp(`(?<![\\w.$])${name}\\(`, 'g');
|
|
48
|
+
let out = '';
|
|
49
|
+
let last = 0;
|
|
50
|
+
let m;
|
|
51
|
+
while ((m = re.exec(code))) {
|
|
52
|
+
const start = m.index;
|
|
53
|
+
let i = re.lastIndex;
|
|
54
|
+
let depth = 1;
|
|
55
|
+
let q = '';
|
|
56
|
+
for (; i < code.length && depth; i++) {
|
|
57
|
+
const c = code[i];
|
|
58
|
+
if (q) {
|
|
59
|
+
if (c === '\\') i++;
|
|
60
|
+
else if (c === q) q = '';
|
|
61
|
+
} else if (c === '"' || c === "'" || c === '`') q = c;
|
|
62
|
+
else if (c === '(') depth++;
|
|
63
|
+
else if (c === ')') depth--;
|
|
64
|
+
}
|
|
65
|
+
if (depth) break;
|
|
66
|
+
const args = splitArgs(code.slice(re.lastIndex, i - 1));
|
|
67
|
+
const rep = fn(args);
|
|
68
|
+
if (rep == null) continue;
|
|
69
|
+
out += code.slice(last, start) + rep;
|
|
70
|
+
last = i;
|
|
71
|
+
re.lastIndex = i;
|
|
72
|
+
changes.push(`${name.replace('\\', '')}() → playEffect(…)`);
|
|
73
|
+
}
|
|
74
|
+
return out + code.slice(last);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const objOf = (pairs, rest) => {
|
|
78
|
+
const lit = rest && /^\{[\s\S]*\}$/.test(rest) ? rest.slice(1, -1).trim() : '';
|
|
79
|
+
const tail = rest ? [lit || `...${rest}`] : [];
|
|
80
|
+
return `{ ${[...pairs.filter(([, v]) => v !== undefined).map(([k, v]) => (k === v ? k : `${k}: ${v}`)), ...tail].filter(Boolean).join(', ')} }`;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Apply every rewrite to one file's source. Returns { code, changes, manual }. */
|
|
84
|
+
export function transform(source) {
|
|
85
|
+
const changes = [];
|
|
86
|
+
const manual = [];
|
|
87
|
+
let code = source;
|
|
88
|
+
// Only touch files that import the old helpers from the library (or use the UMD global).
|
|
89
|
+
const importRe = /import\s*\{([^}]*)\}\s*from\s*(['"])use-scroll-animate\/components(?:\/click)?\2;?/g;
|
|
90
|
+
const imported = new Map(); // local name → original helper
|
|
91
|
+
code = code.replace(importRe, (m, names, q) => {
|
|
92
|
+
const list = names.split(',').map((n) => n.trim()).filter(Boolean);
|
|
93
|
+
const old = list.filter((n) => OLD.includes(n.split(/\s+as\s+/)[0]));
|
|
94
|
+
if (!old.length) return m;
|
|
95
|
+
old.forEach((n) => imported.set(n.split(/\s+as\s+/).pop(), n.split(/\s+as\s+/)[0]));
|
|
96
|
+
const rest = list.filter((n) => !old.includes(n));
|
|
97
|
+
const src = m.match(/from\s*(['"])(.*?)\1/)[2];
|
|
98
|
+
changes.push(`import { ${old.join(', ')} } → import { playEffect } from 'use-scroll-animate/components/fx'`);
|
|
99
|
+
const keep = rest.length ? `import { ${rest.join(', ')} } from ${q}${src}${q};\n` : '';
|
|
100
|
+
return `${keep}import { playEffect } from ${q}use-scroll-animate/components/fx${q};`;
|
|
101
|
+
});
|
|
102
|
+
const umd = /UsaComponents\.(burst|confetti|shake)\(/.test(code);
|
|
103
|
+
if (umd) code = code.replace(/UsaComponents\.(burst|confetti|shake)\(/g, (_m, n) => (imported.set(`UsaComponents.${n}`, n), `UsaComponents.${n}(`));
|
|
104
|
+
for (const [name, kind] of imported) {
|
|
105
|
+
const pe = name.startsWith('UsaComponents.') ? 'UsaComponents.playEffect' : 'playEffect';
|
|
106
|
+
const esc = name.replace('.', '\\.');
|
|
107
|
+
code = rewriteCalls(code, esc, (a) => {
|
|
108
|
+
if (kind === 'burst') return a.length >= 2 ? `${pe}(document.body, 'burst', ${objOf([['x', a[0]], ['y', a[1]]], a[2])})` : null;
|
|
109
|
+
if (kind === 'confetti') return `${pe}(document.body, 'confetti'${a[0] ? `, ${a[0]}` : ''})`;
|
|
110
|
+
if (kind === 'shake') return a.length ? `${pe}(${a[0]}, 'shake'${a.length > 1 ? `, ${objOf([['intensity', a[1]], ['duration', a[2]]])}` : ''})` : null;
|
|
111
|
+
return null;
|
|
112
|
+
}, changes);
|
|
113
|
+
}
|
|
114
|
+
if (/<usa-cursor\b[^>]*\bmode=(["'])trail\1/.test(code)) manual.push('<usa-cursor mode="trail"> is removed in 6.0 — wrap the content in <usa-fx effect="comet-trail" trigger="load" self> (see docs/upgrading-6.md)');
|
|
115
|
+
return { code, changes, manual };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function* walk(p) {
|
|
119
|
+
const st = statSync(p);
|
|
120
|
+
if (st.isDirectory()) {
|
|
121
|
+
for (const f of readdirSync(p)) if (!['node_modules', 'dist', '.git'].includes(f)) yield* walk(join(p, f));
|
|
122
|
+
} else if (EXT.has(extname(p))) yield p;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function run(args) {
|
|
126
|
+
const write = args.includes('--write');
|
|
127
|
+
const paths = args.filter((a) => !a.startsWith('--'));
|
|
128
|
+
let files = 0;
|
|
129
|
+
let edits = 0;
|
|
130
|
+
let todo = 0;
|
|
131
|
+
for (const root of paths.length ? paths : ['src'])
|
|
132
|
+
for (const f of walk(root)) {
|
|
133
|
+
const src = readFileSync(f, 'utf8');
|
|
134
|
+
const { code, changes, manual } = transform(src);
|
|
135
|
+
if (!changes.length && !manual.length) continue;
|
|
136
|
+
files++;
|
|
137
|
+
edits += changes.length;
|
|
138
|
+
todo += manual.length;
|
|
139
|
+
console.log(`${f}${changes.map((c) => `\n - ${c}`).join('')}${manual.map((c) => `\n ! manual: ${c}`).join('')}`);
|
|
140
|
+
if (write && changes.length) writeFileSync(f, code);
|
|
141
|
+
}
|
|
142
|
+
console.log(`\n${edits} change(s), ${todo} manual item(s) in ${files} file(s)${write ? ' written' : ' (dry run — add --write to apply)'}.`);
|
|
143
|
+
return { files, edits, manual: todo };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (import.meta.url === pathToFileURL(process.argv[1] || '').href) run(process.argv.slice(2));
|
|
@@ -1033,7 +1033,8 @@ interface UsaCheckboxElement extends UsaElement {
|
|
|
1033
1033
|
* `<usa-button>` (button click deformation: squash, wobble, gooey, dent;
|
|
1034
1034
|
* shape morph; submit → loading → success), `<usa-icon-morph>`,
|
|
1035
1035
|
* `<usa-like>`, `<usa-hold>`, `<usa-double-tap>`, `<usa-checkbox>`, plus
|
|
1036
|
-
* `burst()`, `confetti()`, `shake()`
|
|
1036
|
+
* `haptic()` (`burst()`, `confetti()`, `shake()` are deprecated in 5.9 —
|
|
1037
|
+
* use the registered effects through `playEffect()`).
|
|
1037
1038
|
*/
|
|
1038
1039
|
|
|
1039
1040
|
declare global {
|
|
@@ -1033,7 +1033,8 @@ interface UsaCheckboxElement extends UsaElement {
|
|
|
1033
1033
|
* `<usa-button>` (button click deformation: squash, wobble, gooey, dent;
|
|
1034
1034
|
* shape morph; submit → loading → success), `<usa-icon-morph>`,
|
|
1035
1035
|
* `<usa-like>`, `<usa-hold>`, `<usa-double-tap>`, `<usa-checkbox>`, plus
|
|
1036
|
-
* `burst()`, `confetti()`, `shake()`
|
|
1036
|
+
* `haptic()` (`burst()`, `confetti()`, `shake()` are deprecated in 5.9 —
|
|
1037
|
+
* use the registered effects through `playEffect()`).
|
|
1037
1038
|
*/
|
|
1038
1039
|
|
|
1039
1040
|
declare global {
|
|
@@ -847,8 +847,27 @@ function defineCheckbox(tag = 'usa-checkbox') {
|
|
|
847
847
|
* `<usa-button>` (button click deformation: squash, wobble, gooey, dent;
|
|
848
848
|
* shape morph; submit → loading → success), `<usa-icon-morph>`,
|
|
849
849
|
* `<usa-like>`, `<usa-hold>`, `<usa-double-tap>`, `<usa-checkbox>`, plus
|
|
850
|
-
* `burst()`, `confetti()`, `shake()`
|
|
850
|
+
* `haptic()` (`burst()`, `confetti()`, `shake()` are deprecated in 5.9 —
|
|
851
|
+
* use the registered effects through `playEffect()`).
|
|
851
852
|
*/
|
|
853
|
+
/**
|
|
854
|
+
* @deprecated 5.9 — removed in 6.0. Use the registered effect:
|
|
855
|
+
* `playEffect(document.body, 'burst', { x, y, ...options })` (`use-scroll-animate/components/fx`).
|
|
856
|
+
*/
|
|
857
|
+
function burst(x, y, options = {}) {
|
|
858
|
+
base.deprecate('burst()', "burst() is deprecated and removed in 6.0 — use playEffect(el, 'burst', { x, y, …options }) from use-scroll-animate/components/fx (npx usa-codemod-6).");
|
|
859
|
+
return fx.burst(x, y, options);
|
|
860
|
+
}
|
|
861
|
+
/** @deprecated 5.9 — removed in 6.0. Use `playEffect(document.body, 'confetti', options)`. */
|
|
862
|
+
function confetti(options = {}) {
|
|
863
|
+
base.deprecate('confetti()', "confetti() is deprecated and removed in 6.0 — use playEffect(el, 'confetti', options) from use-scroll-animate/components/fx (npx usa-codemod-6).");
|
|
864
|
+
return fx.confetti(options);
|
|
865
|
+
}
|
|
866
|
+
/** @deprecated 5.9 — removed in 6.0. Use `playEffect(el, 'shake', { intensity, duration })`. */
|
|
867
|
+
function shake(el, intensity = 8, duration = 480) {
|
|
868
|
+
base.deprecate('shake()', "shake() is deprecated and removed in 6.0 — use playEffect(el, 'shake', { intensity, duration }) from use-scroll-animate/components/fx (npx usa-codemod-6).");
|
|
869
|
+
return fx.shake(el, intensity, duration);
|
|
870
|
+
}
|
|
852
871
|
/** Register every component of this category under its default tag. */
|
|
853
872
|
function defineClickComponents() {
|
|
854
873
|
defineClick();
|
|
@@ -860,13 +879,12 @@ function defineClickComponents() {
|
|
|
860
879
|
defineCheckbox();
|
|
861
880
|
}
|
|
862
881
|
|
|
863
|
-
exports.burst = fx.burst;
|
|
864
|
-
exports.confetti = fx.confetti;
|
|
865
882
|
exports.haptic = fx.haptic;
|
|
866
|
-
exports.shake = fx.shake;
|
|
867
883
|
exports.BUTTON_DEFORMS = BUTTON_DEFORMS;
|
|
868
884
|
exports.CLICK_EFFECTS = CLICK_EFFECTS;
|
|
869
885
|
exports.MORPH_ICONS = MORPH_ICONS;
|
|
886
|
+
exports.burst = burst;
|
|
887
|
+
exports.confetti = confetti;
|
|
870
888
|
exports.defineButton = defineButton;
|
|
871
889
|
exports.defineCheckbox = defineCheckbox;
|
|
872
890
|
exports.defineClick = defineClick;
|
|
@@ -876,4 +894,5 @@ exports.defineHold = defineHold;
|
|
|
876
894
|
exports.defineIconMorph = defineIconMorph;
|
|
877
895
|
exports.defineLike = defineLike;
|
|
878
896
|
exports.morphPath = morphPath;
|
|
897
|
+
exports.shake = shake;
|
|
879
898
|
//# sourceMappingURL=click.cjs.map
|