use-scroll-animate 4.8.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +2 -1
- package/README_ja.md +1 -0
- package/README_zh.md +2 -1
- package/bin/usa-codemod-5.mjs +79 -0
- package/dist/chunks/{base-CxYU2NK_.cjs → base-B5i8qQPR.cjs} +65 -30
- package/dist/chunks/base-B5i8qQPR.cjs.map +1 -0
- package/dist/chunks/{base-CZiIAMBc.js → base-C3Sw9sAO.js} +63 -31
- package/dist/chunks/base-C3Sw9sAO.js.map +1 -0
- package/dist/chunks/{core-HLqH3qkA.cjs → core-BDcszY4L.cjs} +2 -2
- package/dist/chunks/{core-HLqH3qkA.cjs.map → core-BDcszY4L.cjs.map} +1 -1
- package/dist/chunks/{core-COi3DrLx.js → core-BTf__I-8.js} +2 -2
- package/dist/chunks/{core-COi3DrLx.js.map → core-BTf__I-8.js.map} +1 -1
- package/dist/chunks/{core-CctNfzuP.cjs → core-BjOYKSrV.cjs} +2 -2
- package/dist/chunks/{core-CctNfzuP.cjs.map → core-BjOYKSrV.cjs.map} +1 -1
- package/dist/chunks/{core-CJHJeMI_.js → core-DN3hHbHh.js} +2 -2
- package/dist/chunks/{core-CJHJeMI_.js.map → core-DN3hHbHh.js.map} +1 -1
- package/dist/chunks/fx-B8hk1Fby.cjs +114 -0
- package/dist/chunks/fx-B8hk1Fby.cjs.map +1 -0
- package/dist/chunks/fx-ChjxrMBo.js +109 -0
- package/dist/chunks/fx-ChjxrMBo.js.map +1 -0
- package/dist/chunks/{index-tags-Dh8nwXqw.js → index-tags-DucKMQr_.js} +2 -1
- package/dist/chunks/{index-tags-Dh8nwXqw.js.map → index-tags-DucKMQr_.js.map} +1 -1
- package/dist/chunks/{index-tags-CIRY2KnU.cjs → index-tags-wv0R_vkO.cjs} +2 -1
- package/dist/chunks/{index-tags-CIRY2KnU.cjs.map → index-tags-wv0R_vkO.cjs.map} +1 -1
- package/dist/chunks/{spring-Dkpygsuj.cjs → spring--oZh55tB.cjs} +2 -2
- package/dist/chunks/{spring-Dkpygsuj.cjs.map → spring--oZh55tB.cjs.map} +1 -1
- package/dist/chunks/{spring-BS5tg6aK.js → spring-CckMe3x0.js} +2 -2
- package/dist/chunks/{spring-BS5tg6aK.js.map → spring-CckMe3x0.js.map} +1 -1
- package/dist/chunks/{variants-D9n-3x27.js → variants-Bsevy6Xm.js} +2 -2
- package/dist/chunks/{variants-D9n-3x27.js.map → variants-Bsevy6Xm.js.map} +1 -1
- package/dist/chunks/{variants-CfJzrzMh.cjs → variants-DxPmgrNX.cjs} +2 -2
- package/dist/chunks/{variants-CfJzrzMh.cjs.map → variants-DxPmgrNX.cjs.map} +1 -1
- package/dist/components/a11y.cjs +39 -2
- package/dist/components/a11y.cjs.map +1 -1
- package/dist/components/a11y.d.cts +13 -2
- package/dist/components/a11y.d.ts +13 -2
- package/dist/components/a11y.js +39 -4
- package/dist/components/a11y.js.map +1 -1
- package/dist/components/angular.cjs +8 -6
- package/dist/components/angular.cjs.map +1 -1
- package/dist/components/angular.d.cts +33 -4
- package/dist/components/angular.d.ts +33 -4
- package/dist/components/angular.js +8 -6
- package/dist/components/angular.js.map +1 -1
- package/dist/components/background.cjs +2 -4
- package/dist/components/background.cjs.map +1 -1
- package/dist/components/background.d.cts +2 -47
- package/dist/components/background.d.ts +2 -47
- package/dist/components/background.js +3 -4
- package/dist/components/background.js.map +1 -1
- package/dist/components/bridge.cjs +1 -1
- package/dist/components/bridge.js +1 -1
- package/dist/components/cards.cjs +2 -4
- package/dist/components/cards.cjs.map +1 -1
- package/dist/components/cards.d.cts +2 -47
- package/dist/components/cards.d.ts +2 -47
- package/dist/components/cards.js +2 -3
- package/dist/components/cards.js.map +1 -1
- package/dist/components/click.cjs +24 -130
- package/dist/components/click.cjs.map +1 -1
- package/dist/components/click.d.cts +2 -47
- package/dist/components/click.d.ts +2 -47
- package/dist/components/click.js +4 -109
- package/dist/components/click.js.map +1 -1
- package/dist/components/depth.cjs +3 -5
- package/dist/components/depth.cjs.map +1 -1
- package/dist/components/depth.d.cts +2 -47
- package/dist/components/depth.d.ts +2 -47
- package/dist/components/depth.js +3 -4
- package/dist/components/depth.js.map +1 -1
- package/dist/components/feedback.cjs +1 -3
- package/dist/components/feedback.cjs.map +1 -1
- package/dist/components/feedback.d.cts +2 -47
- package/dist/components/feedback.d.ts +2 -47
- package/dist/components/feedback.js +1 -2
- package/dist/components/feedback.js.map +1 -1
- package/dist/components/fx.cjs +285 -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 +271 -0
- package/dist/components/fx.js.map +1 -0
- package/dist/components/gesture.cjs +3 -5
- package/dist/components/gesture.cjs.map +1 -1
- package/dist/components/gesture.d.cts +2 -47
- package/dist/components/gesture.d.ts +2 -47
- package/dist/components/gesture.js +4 -5
- package/dist/components/gesture.js.map +1 -1
- package/dist/components/interaction.cjs +1 -3
- package/dist/components/interaction.cjs.map +1 -1
- package/dist/components/interaction.d.cts +2 -47
- package/dist/components/interaction.d.ts +2 -47
- package/dist/components/interaction.js +1 -2
- package/dist/components/interaction.js.map +1 -1
- package/dist/components/jsx.d.cts +1 -0
- package/dist/components/jsx.d.ts +1 -0
- package/dist/components/layout.cjs +1 -3
- package/dist/components/layout.cjs.map +1 -1
- package/dist/components/layout.d.cts +2 -47
- package/dist/components/layout.d.ts +2 -47
- package/dist/components/layout.js +2 -3
- package/dist/components/layout.js.map +1 -1
- package/dist/components/lazy.cjs +2 -1
- package/dist/components/lazy.cjs.map +1 -1
- package/dist/components/lazy.d.cts +1 -0
- package/dist/components/lazy.d.ts +1 -0
- package/dist/components/lazy.js +2 -1
- package/dist/components/lazy.js.map +1 -1
- package/dist/components/lite.cjs +413 -42
- package/dist/components/lite.cjs.map +1 -1
- package/dist/components/lite.js +394 -43
- package/dist/components/lite.js.map +1 -1
- package/dist/components/packs.cjs +1 -3
- package/dist/components/packs.cjs.map +1 -1
- package/dist/components/packs.d.cts +2 -47
- package/dist/components/packs.d.ts +2 -47
- package/dist/components/packs.js +2 -3
- package/dist/components/packs.js.map +1 -1
- package/dist/components/page.cjs +31 -12
- package/dist/components/page.cjs.map +1 -1
- package/dist/components/page.d.cts +15 -52
- package/dist/components/page.d.ts +15 -52
- package/dist/components/page.js +31 -12
- package/dist/components/page.js.map +1 -1
- package/dist/components/perf.cjs +3 -4
- package/dist/components/perf.cjs.map +1 -1
- package/dist/components/perf.d.cts +1 -0
- package/dist/components/perf.d.ts +1 -0
- package/dist/components/perf.js +4 -5
- package/dist/components/perf.js.map +1 -1
- package/dist/components/physics.cjs +2 -4
- package/dist/components/physics.cjs.map +1 -1
- package/dist/components/physics.d.cts +2 -47
- package/dist/components/physics.d.ts +2 -47
- package/dist/components/physics.js +3 -4
- package/dist/components/physics.js.map +1 -1
- package/dist/components/react.cjs +1 -1
- package/dist/components/react.js +1 -1
- package/dist/components/reveal.cjs +1 -3
- package/dist/components/reveal.cjs.map +1 -1
- package/dist/components/reveal.d.cts +2 -47
- package/dist/components/reveal.d.ts +2 -47
- package/dist/components/reveal.js +1 -2
- package/dist/components/reveal.js.map +1 -1
- package/dist/components/solid.cjs +8 -6
- package/dist/components/solid.cjs.map +1 -1
- package/dist/components/solid.d.cts +33 -4
- package/dist/components/solid.d.ts +33 -4
- package/dist/components/solid.js +8 -6
- package/dist/components/solid.js.map +1 -1
- package/dist/components/svelte.cjs +8 -6
- package/dist/components/svelte.cjs.map +1 -1
- package/dist/components/svelte.d.cts +33 -4
- package/dist/components/svelte.d.ts +33 -4
- package/dist/components/svelte.js +8 -6
- package/dist/components/svelte.js.map +1 -1
- package/dist/components/svg.cjs +1 -3
- package/dist/components/svg.cjs.map +1 -1
- package/dist/components/svg.d.cts +2 -47
- package/dist/components/svg.d.ts +2 -47
- package/dist/components/svg.js +2 -3
- package/dist/components/svg.js.map +1 -1
- package/dist/components/text.cjs +2 -4
- package/dist/components/text.cjs.map +1 -1
- package/dist/components/text.d.cts +2 -47
- package/dist/components/text.d.ts +2 -47
- package/dist/components/text.js +2 -3
- package/dist/components/text.js.map +1 -1
- package/dist/components/timeline.cjs +3 -5
- package/dist/components/timeline.cjs.map +1 -1
- package/dist/components/timeline.d.cts +4 -49
- package/dist/components/timeline.d.ts +4 -49
- package/dist/components/timeline.js +4 -5
- package/dist/components/timeline.js.map +1 -1
- package/dist/components/transitions.cjs +1 -3
- package/dist/components/transitions.cjs.map +1 -1
- package/dist/components/transitions.d.cts +2 -47
- package/dist/components/transitions.d.ts +2 -47
- package/dist/components/transitions.js +2 -3
- package/dist/components/transitions.js.map +1 -1
- package/dist/components/ui.cjs +3 -5
- package/dist/components/ui.cjs.map +1 -1
- package/dist/components/ui.d.cts +2 -47
- package/dist/components/ui.d.ts +2 -47
- package/dist/components/ui.js +4 -5
- package/dist/components/ui.js.map +1 -1
- package/dist/components/vue.cjs +8 -6
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.d.cts +33 -4
- package/dist/components/vue.d.ts +33 -4
- package/dist/components/vue.js +8 -6
- package/dist/components/vue.js.map +1 -1
- package/dist/components/webgl.cjs +3 -5
- package/dist/components/webgl.cjs.map +1 -1
- package/dist/components/webgl.d.cts +2 -47
- package/dist/components/webgl.d.ts +2 -47
- package/dist/components/webgl.js +3 -4
- package/dist/components/webgl.js.map +1 -1
- package/dist/components.cjs +33 -10
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +1 -0
- package/dist/components.d.cts +147 -17
- package/dist/components.d.ts +147 -17
- package/dist/components.js +16 -12
- 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 +2 -2
- package/dist/index.js +2 -2
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/docs/API.md +1 -1
- package/docs/ROADMAP.md +12 -12
- package/docs/components.md +14 -1
- package/docs/deprecations.md +6 -0
- package/docs/performance.md +1 -1
- package/docs/upgrading-5.md +31 -0
- package/package.json +18 -3
- package/dist/chunks/base-CZiIAMBc.js.map +0 -1
- package/dist/chunks/base-CxYU2NK_.cjs.map +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('./base-B5i8qQPR.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Click-effect helpers (v2.5): `burst()`, `confetti()`, `shake()`, `haptic()`.
|
|
7
|
+
* Particles live in one fixed, pointer-transparent layer and are removed when
|
|
8
|
+
* their animation ends. Under reduced motion particles are skipped and
|
|
9
|
+
* `shake()` only flashes an outline.
|
|
10
|
+
*/
|
|
11
|
+
let layer = null;
|
|
12
|
+
function fxLayer() {
|
|
13
|
+
if (layer && layer.isConnected)
|
|
14
|
+
return layer;
|
|
15
|
+
layer = document.createElement('div');
|
|
16
|
+
layer.className = 'usa-fx-layer';
|
|
17
|
+
layer.setAttribute('aria-hidden', 'true');
|
|
18
|
+
layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483000;overflow:hidden;contain:strict';
|
|
19
|
+
document.body.appendChild(layer);
|
|
20
|
+
return layer;
|
|
21
|
+
}
|
|
22
|
+
const PALETTE = ['#7c5cff', '#22d3ee', '#f472b6', '#facc15', '#34d399', '#fb923c'];
|
|
23
|
+
const GLYPH = { star: '★', heart: '♥' };
|
|
24
|
+
function particle(x, y, size, color, shape) {
|
|
25
|
+
const p = document.createElement('span');
|
|
26
|
+
const glyph = GLYPH[shape] || (shape !== 'circle' && shape !== 'square' ? shape : '');
|
|
27
|
+
p.style.cssText = `position:absolute;left:${x}px;top:${y}px;width:${size}px;height:${size}px;margin:${-size / 2}px 0 0 ${-size / 2}px;will-change:transform,opacity;` +
|
|
28
|
+
(glyph ? `font-size:${size * 2}px;line-height:${size}px;text-align:center;color:${color}` : `background:${color};border-radius:${shape === 'square' ? '2px' : '50%'}`);
|
|
29
|
+
if (glyph)
|
|
30
|
+
p.textContent = glyph;
|
|
31
|
+
fxLayer().appendChild(p);
|
|
32
|
+
return p;
|
|
33
|
+
}
|
|
34
|
+
const done = (a, el) => {
|
|
35
|
+
if (a)
|
|
36
|
+
a.onfinish = () => el.remove();
|
|
37
|
+
else
|
|
38
|
+
el.remove();
|
|
39
|
+
};
|
|
40
|
+
/** Particles radiating from client point (x, y). Returns the number spawned. */
|
|
41
|
+
function burst(x, y, options = {}) {
|
|
42
|
+
if (typeof document === 'undefined' || base.prefersReducedMotion())
|
|
43
|
+
return 0;
|
|
44
|
+
const { count = 12, colors = PALETTE, distance = 48, size = 6, shape = 'circle', duration = 600 } = options;
|
|
45
|
+
for (let i = 0; i < count; i++) {
|
|
46
|
+
const angle = (i / count) * Math.PI * 2 + Math.random() * 0.4;
|
|
47
|
+
const d = distance * (0.7 + Math.random() * 0.5);
|
|
48
|
+
const p = particle(x, y, size, colors[i % colors.length], shape);
|
|
49
|
+
const a = typeof p.animate === 'function'
|
|
50
|
+
? p.animate([
|
|
51
|
+
{ transform: 'translate(0,0) scale(1)', opacity: 1 },
|
|
52
|
+
{ transform: `translate(${Math.cos(angle) * d}px, ${Math.sin(angle) * d}px) scale(0.2)`, opacity: 0 },
|
|
53
|
+
], { duration: duration * (0.8 + Math.random() * 0.4), easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'forwards' })
|
|
54
|
+
: null;
|
|
55
|
+
done(a, p);
|
|
56
|
+
}
|
|
57
|
+
return count;
|
|
58
|
+
}
|
|
59
|
+
/** A confetti cannon (paper pieces with gravity, drift and spin). */
|
|
60
|
+
function confetti(options = {}) {
|
|
61
|
+
if (typeof document === 'undefined' || base.prefersReducedMotion())
|
|
62
|
+
return 0;
|
|
63
|
+
const W = window.innerWidth || 800;
|
|
64
|
+
const H = window.innerHeight || 600;
|
|
65
|
+
const { x = W / 2, y = H * 0.66, count = 80, spread = 70, velocity = 1, colors = PALETTE, duration = 1600 } = options;
|
|
66
|
+
for (let i = 0; i < count; i++) {
|
|
67
|
+
const angle = ((-90 + (Math.random() - 0.5) * spread) * Math.PI) / 180;
|
|
68
|
+
const speed = (260 + Math.random() * 320) * velocity;
|
|
69
|
+
const vx = Math.cos(angle) * speed;
|
|
70
|
+
const vy = Math.sin(angle) * speed;
|
|
71
|
+
const p = particle(x, y, 6 + Math.random() * 5, colors[i % colors.length], Math.random() > 0.5 ? 'square' : 'circle');
|
|
72
|
+
p.style.height = `${4 + Math.random() * 3}px`;
|
|
73
|
+
const frames = [];
|
|
74
|
+
const steps = 8;
|
|
75
|
+
const T = duration / 1000;
|
|
76
|
+
const spin = (Math.random() - 0.5) * 1440;
|
|
77
|
+
for (let s = 0; s <= steps; s++) {
|
|
78
|
+
const t = (s / steps) * T;
|
|
79
|
+
const g = 900;
|
|
80
|
+
frames.push({
|
|
81
|
+
transform: `translate(${(vx * t * 0.8).toFixed(1)}px, ${(vy * t + 0.5 * g * t * t).toFixed(1)}px) rotate(${((spin * s) / steps).toFixed(0)}deg) rotateX(${s * 120}deg)`,
|
|
82
|
+
opacity: s === steps ? 0 : 1,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const a = typeof p.animate === 'function' ? p.animate(frames, { duration: duration * (0.85 + Math.random() * 0.3), easing: 'linear', fill: 'forwards' }) : null;
|
|
86
|
+
done(a, p);
|
|
87
|
+
}
|
|
88
|
+
return count;
|
|
89
|
+
}
|
|
90
|
+
/** Horizontal error shake (`intensity` px, default 8). Reduced motion: a red outline flash. */
|
|
91
|
+
function shake(el, intensity = 8, duration = 480) {
|
|
92
|
+
const t = el;
|
|
93
|
+
if (typeof t.animate !== 'function')
|
|
94
|
+
return null;
|
|
95
|
+
if (base.prefersReducedMotion())
|
|
96
|
+
return t.animate([{ outline: '2px solid #e5484d' }, { outline: '2px solid transparent' }], { duration: 600 });
|
|
97
|
+
const k = intensity;
|
|
98
|
+
return t.animate([0, -k, k, -k * 0.75, k * 0.75, -k * 0.4, k * 0.4, 0].map((v) => ({ transform: `translateX(${v}px)` })), { duration, easing: 'ease-in-out' });
|
|
99
|
+
}
|
|
100
|
+
/** `navigator.vibrate()` where supported (Android Chrome, some WebViews). Returns whether it ran. */
|
|
101
|
+
function haptic(pattern = 10) {
|
|
102
|
+
try {
|
|
103
|
+
return typeof navigator !== 'undefined' && typeof navigator.vibrate === 'function' ? navigator.vibrate(pattern) : false;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
exports.burst = burst;
|
|
111
|
+
exports.confetti = confetti;
|
|
112
|
+
exports.haptic = haptic;
|
|
113
|
+
exports.shake = shake;
|
|
114
|
+
//# sourceMappingURL=fx-B8hk1Fby.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fx-B8hk1Fby.cjs","sources":["../../src/components/click/fx.ts"],"sourcesContent":["import { prefersReducedMotion, applyFrame } from '../base';\n\n/**\n * Click-effect helpers (v2.5): `burst()`, `confetti()`, `shake()`, `haptic()`.\n * Particles live in one fixed, pointer-transparent layer and are removed when\n * their animation ends. Under reduced motion particles are skipped and\n * `shake()` only flashes an outline.\n */\n\nlet layer: HTMLElement | null = null;\nfunction fxLayer(): HTMLElement {\n if (layer && layer.isConnected) return layer;\n layer = document.createElement('div');\n layer.className = 'usa-fx-layer';\n layer.setAttribute('aria-hidden', 'true');\n layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483000;overflow:hidden;contain:strict';\n document.body.appendChild(layer);\n return layer;\n}\n\nexport interface BurstOptions {\n /** Number of particles (default 12). */\n count?: number;\n /** Colours to pick from (default: accent palette). */\n colors?: string[];\n /** Travel distance in px (default 48). */\n distance?: number;\n /** Particle size in px (default 6). */\n size?: number;\n /** `circle` (default), `square`, `star`, `heart` or any text / emoji. */\n shape?: 'circle' | 'square' | 'star' | 'heart' | string;\n /** Duration in ms (default 600). */\n duration?: number;\n}\n\nconst PALETTE = ['#7c5cff', '#22d3ee', '#f472b6', '#facc15', '#34d399', '#fb923c'];\nconst GLYPH: Record<string, string> = { star: '★', heart: '♥' };\n\nfunction particle(x: number, y: number, size: number, color: string, shape: string): HTMLElement {\n const p = document.createElement('span');\n const glyph = GLYPH[shape] || (shape !== 'circle' && shape !== 'square' ? shape : '');\n p.style.cssText = `position:absolute;left:${x}px;top:${y}px;width:${size}px;height:${size}px;margin:${-size / 2}px 0 0 ${-size / 2}px;will-change:transform,opacity;` +\n (glyph ? `font-size:${size * 2}px;line-height:${size}px;text-align:center;color:${color}` : `background:${color};border-radius:${shape === 'square' ? '2px' : '50%'}`);\n if (glyph) p.textContent = glyph;\n fxLayer().appendChild(p);\n return p;\n}\n\nconst done = (a: Animation | null, el: Element) => {\n if (a) a.onfinish = () => el.remove();\n else el.remove();\n};\n\n/** Particles radiating from client point (x, y). Returns the number spawned. */\nexport function burst(x: number, y: number, options: BurstOptions = {}): number {\n if (typeof document === 'undefined' || prefersReducedMotion()) return 0;\n const { count = 12, colors = PALETTE, distance = 48, size = 6, shape = 'circle', duration = 600 } = options;\n for (let i = 0; i < count; i++) {\n const angle = (i / count) * Math.PI * 2 + Math.random() * 0.4;\n const d = distance * (0.7 + Math.random() * 0.5);\n const p = particle(x, y, size, colors[i % colors.length], shape);\n const a = typeof p.animate === 'function'\n ? p.animate(\n [\n { transform: 'translate(0,0) scale(1)', opacity: 1 },\n { transform: `translate(${Math.cos(angle) * d}px, ${Math.sin(angle) * d}px) scale(0.2)`, opacity: 0 },\n ],\n { duration: duration * (0.8 + Math.random() * 0.4), easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'forwards' }\n )\n : null;\n done(a, p);\n }\n return count;\n}\n\nexport interface ConfettiOptions {\n /** Origin in client px (default: centre-bottom third of the viewport). */\n x?: number;\n y?: number;\n /** Pieces (default 80). */\n count?: number;\n /** Spread angle in degrees (default 70). */\n spread?: number;\n /** Launch speed multiplier (default 1). */\n velocity?: number;\n colors?: string[];\n /** Duration in ms (default 1600). */\n duration?: number;\n}\n\n/** A confetti cannon (paper pieces with gravity, drift and spin). */\nexport function confetti(options: ConfettiOptions = {}): number {\n if (typeof document === 'undefined' || prefersReducedMotion()) return 0;\n const W = window.innerWidth || 800;\n const H = window.innerHeight || 600;\n const { x = W / 2, y = H * 0.66, count = 80, spread = 70, velocity = 1, colors = PALETTE, duration = 1600 } = options;\n for (let i = 0; i < count; i++) {\n const angle = ((-90 + (Math.random() - 0.5) * spread) * Math.PI) / 180;\n const speed = (260 + Math.random() * 320) * velocity;\n const vx = Math.cos(angle) * speed;\n const vy = Math.sin(angle) * speed;\n const p = particle(x, y, 6 + Math.random() * 5, colors[i % colors.length], Math.random() > 0.5 ? 'square' : 'circle');\n p.style.height = `${4 + Math.random() * 3}px`;\n const frames: Keyframe[] = [];\n const steps = 8;\n const T = duration / 1000;\n const spin = (Math.random() - 0.5) * 1440;\n for (let s = 0; s <= steps; s++) {\n const t = (s / steps) * T;\n const g = 900;\n frames.push({\n transform: `translate(${(vx * t * 0.8).toFixed(1)}px, ${(vy * t + 0.5 * g * t * t).toFixed(1)}px) rotate(${((spin * s) / steps).toFixed(0)}deg) rotateX(${s * 120}deg)`,\n opacity: s === steps ? 0 : 1,\n });\n }\n const a = typeof p.animate === 'function' ? p.animate(frames, { duration: duration * (0.85 + Math.random() * 0.3), easing: 'linear', fill: 'forwards' }) : null;\n done(a, p);\n }\n return count;\n}\n\n/** Horizontal error shake (`intensity` px, default 8). Reduced motion: a red outline flash. */\nexport function shake(el: Element, intensity = 8, duration = 480): Animation | null {\n const t = el as HTMLElement;\n if (typeof t.animate !== 'function') return null;\n if (prefersReducedMotion()) return t.animate([{ outline: '2px solid #e5484d' }, { outline: '2px solid transparent' }], { duration: 600 });\n const k = intensity;\n return t.animate(\n [0, -k, k, -k * 0.75, k * 0.75, -k * 0.4, k * 0.4, 0].map((v) => ({ transform: `translateX(${v}px)` })),\n { duration, easing: 'ease-in-out' }\n );\n}\n\n/** `navigator.vibrate()` where supported (Android Chrome, some WebViews). Returns whether it ran. */\nexport function haptic(pattern: number | number[] = 10): boolean {\n try {\n return typeof navigator !== 'undefined' && typeof navigator.vibrate === 'function' ? navigator.vibrate(pattern) : false;\n } catch {\n return false;\n }\n}\n\nexport { applyFrame };\n"],"names":["prefersReducedMotion"],"mappings":";;;;AAEA;;;;;AAKG;AAEH,IAAI,KAAK,GAAuB,IAAI;AACpC,SAAS,OAAO,GAAA;AACd,IAAA,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW;AAAE,QAAA,OAAO,KAAK;AAC5C,IAAA,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AACrC,IAAA,KAAK,CAAC,SAAS,GAAG,cAAc;AAChC,IAAA,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC;AACzC,IAAA,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,8FAA8F;AACpH,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;AAChC,IAAA,OAAO,KAAK;AACd;AAiBA,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;AAClF,MAAM,KAAK,GAA2B,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE;AAE/D,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAE,IAAY,EAAE,KAAa,EAAE,KAAa,EAAA;IAChF,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,EAAE,CAAC;IACrF,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,CAAA,uBAAA,EAA0B,CAAC,CAAA,OAAA,EAAU,CAA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E,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;IACzI,MAAM,CAAC,GAAG,SAAS;IACnB,OAAO,CAAC,CAAC,OAAO,CACd,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,CAAA,WAAA,EAAc,CAAC,CAAA,GAAA,CAAK,EAAE,CAAC,CAAC,EACvG,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,CACpC;AACH;AAEA;AACM,SAAU,MAAM,CAAC,OAAA,GAA6B,EAAE,EAAA;AACpD,IAAA,IAAI;QACF,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,OAAO,SAAS,CAAC,OAAO,KAAK,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK;IACzH;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;;;;;;;"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { p as prefersReducedMotion } from './base-C3Sw9sAO.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Click-effect helpers (v2.5): `burst()`, `confetti()`, `shake()`, `haptic()`.
|
|
5
|
+
* Particles live in one fixed, pointer-transparent layer and are removed when
|
|
6
|
+
* their animation ends. Under reduced motion particles are skipped and
|
|
7
|
+
* `shake()` only flashes an outline.
|
|
8
|
+
*/
|
|
9
|
+
let layer = null;
|
|
10
|
+
function fxLayer() {
|
|
11
|
+
if (layer && layer.isConnected)
|
|
12
|
+
return layer;
|
|
13
|
+
layer = document.createElement('div');
|
|
14
|
+
layer.className = 'usa-fx-layer';
|
|
15
|
+
layer.setAttribute('aria-hidden', 'true');
|
|
16
|
+
layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483000;overflow:hidden;contain:strict';
|
|
17
|
+
document.body.appendChild(layer);
|
|
18
|
+
return layer;
|
|
19
|
+
}
|
|
20
|
+
const PALETTE = ['#7c5cff', '#22d3ee', '#f472b6', '#facc15', '#34d399', '#fb923c'];
|
|
21
|
+
const GLYPH = { star: '★', heart: '♥' };
|
|
22
|
+
function particle(x, y, size, color, shape) {
|
|
23
|
+
const p = document.createElement('span');
|
|
24
|
+
const glyph = GLYPH[shape] || (shape !== 'circle' && shape !== 'square' ? shape : '');
|
|
25
|
+
p.style.cssText = `position:absolute;left:${x}px;top:${y}px;width:${size}px;height:${size}px;margin:${-size / 2}px 0 0 ${-size / 2}px;will-change:transform,opacity;` +
|
|
26
|
+
(glyph ? `font-size:${size * 2}px;line-height:${size}px;text-align:center;color:${color}` : `background:${color};border-radius:${shape === 'square' ? '2px' : '50%'}`);
|
|
27
|
+
if (glyph)
|
|
28
|
+
p.textContent = glyph;
|
|
29
|
+
fxLayer().appendChild(p);
|
|
30
|
+
return p;
|
|
31
|
+
}
|
|
32
|
+
const done = (a, el) => {
|
|
33
|
+
if (a)
|
|
34
|
+
a.onfinish = () => el.remove();
|
|
35
|
+
else
|
|
36
|
+
el.remove();
|
|
37
|
+
};
|
|
38
|
+
/** Particles radiating from client point (x, y). Returns the number spawned. */
|
|
39
|
+
function burst(x, y, options = {}) {
|
|
40
|
+
if (typeof document === 'undefined' || prefersReducedMotion())
|
|
41
|
+
return 0;
|
|
42
|
+
const { count = 12, colors = PALETTE, distance = 48, size = 6, shape = 'circle', duration = 600 } = options;
|
|
43
|
+
for (let i = 0; i < count; i++) {
|
|
44
|
+
const angle = (i / count) * Math.PI * 2 + Math.random() * 0.4;
|
|
45
|
+
const d = distance * (0.7 + Math.random() * 0.5);
|
|
46
|
+
const p = particle(x, y, size, colors[i % colors.length], shape);
|
|
47
|
+
const a = typeof p.animate === 'function'
|
|
48
|
+
? p.animate([
|
|
49
|
+
{ transform: 'translate(0,0) scale(1)', opacity: 1 },
|
|
50
|
+
{ transform: `translate(${Math.cos(angle) * d}px, ${Math.sin(angle) * d}px) scale(0.2)`, opacity: 0 },
|
|
51
|
+
], { duration: duration * (0.8 + Math.random() * 0.4), easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'forwards' })
|
|
52
|
+
: null;
|
|
53
|
+
done(a, p);
|
|
54
|
+
}
|
|
55
|
+
return count;
|
|
56
|
+
}
|
|
57
|
+
/** A confetti cannon (paper pieces with gravity, drift and spin). */
|
|
58
|
+
function confetti(options = {}) {
|
|
59
|
+
if (typeof document === 'undefined' || prefersReducedMotion())
|
|
60
|
+
return 0;
|
|
61
|
+
const W = window.innerWidth || 800;
|
|
62
|
+
const H = window.innerHeight || 600;
|
|
63
|
+
const { x = W / 2, y = H * 0.66, count = 80, spread = 70, velocity = 1, colors = PALETTE, duration = 1600 } = options;
|
|
64
|
+
for (let i = 0; i < count; i++) {
|
|
65
|
+
const angle = ((-90 + (Math.random() - 0.5) * spread) * Math.PI) / 180;
|
|
66
|
+
const speed = (260 + Math.random() * 320) * velocity;
|
|
67
|
+
const vx = Math.cos(angle) * speed;
|
|
68
|
+
const vy = Math.sin(angle) * speed;
|
|
69
|
+
const p = particle(x, y, 6 + Math.random() * 5, colors[i % colors.length], Math.random() > 0.5 ? 'square' : 'circle');
|
|
70
|
+
p.style.height = `${4 + Math.random() * 3}px`;
|
|
71
|
+
const frames = [];
|
|
72
|
+
const steps = 8;
|
|
73
|
+
const T = duration / 1000;
|
|
74
|
+
const spin = (Math.random() - 0.5) * 1440;
|
|
75
|
+
for (let s = 0; s <= steps; s++) {
|
|
76
|
+
const t = (s / steps) * T;
|
|
77
|
+
const g = 900;
|
|
78
|
+
frames.push({
|
|
79
|
+
transform: `translate(${(vx * t * 0.8).toFixed(1)}px, ${(vy * t + 0.5 * g * t * t).toFixed(1)}px) rotate(${((spin * s) / steps).toFixed(0)}deg) rotateX(${s * 120}deg)`,
|
|
80
|
+
opacity: s === steps ? 0 : 1,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const a = typeof p.animate === 'function' ? p.animate(frames, { duration: duration * (0.85 + Math.random() * 0.3), easing: 'linear', fill: 'forwards' }) : null;
|
|
84
|
+
done(a, p);
|
|
85
|
+
}
|
|
86
|
+
return count;
|
|
87
|
+
}
|
|
88
|
+
/** Horizontal error shake (`intensity` px, default 8). Reduced motion: a red outline flash. */
|
|
89
|
+
function shake(el, intensity = 8, duration = 480) {
|
|
90
|
+
const t = el;
|
|
91
|
+
if (typeof t.animate !== 'function')
|
|
92
|
+
return null;
|
|
93
|
+
if (prefersReducedMotion())
|
|
94
|
+
return t.animate([{ outline: '2px solid #e5484d' }, { outline: '2px solid transparent' }], { duration: 600 });
|
|
95
|
+
const k = intensity;
|
|
96
|
+
return t.animate([0, -k, k, -k * 0.75, k * 0.75, -k * 0.4, k * 0.4, 0].map((v) => ({ transform: `translateX(${v}px)` })), { duration, easing: 'ease-in-out' });
|
|
97
|
+
}
|
|
98
|
+
/** `navigator.vibrate()` where supported (Android Chrome, some WebViews). Returns whether it ran. */
|
|
99
|
+
function haptic(pattern = 10) {
|
|
100
|
+
try {
|
|
101
|
+
return typeof navigator !== 'undefined' && typeof navigator.vibrate === 'function' ? navigator.vibrate(pattern) : false;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { burst as b, confetti as c, haptic as h, shake as s };
|
|
109
|
+
//# sourceMappingURL=fx-ChjxrMBo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fx-ChjxrMBo.js","sources":["../../src/components/click/fx.ts"],"sourcesContent":["import { prefersReducedMotion, applyFrame } from '../base';\n\n/**\n * Click-effect helpers (v2.5): `burst()`, `confetti()`, `shake()`, `haptic()`.\n * Particles live in one fixed, pointer-transparent layer and are removed when\n * their animation ends. Under reduced motion particles are skipped and\n * `shake()` only flashes an outline.\n */\n\nlet layer: HTMLElement | null = null;\nfunction fxLayer(): HTMLElement {\n if (layer && layer.isConnected) return layer;\n layer = document.createElement('div');\n layer.className = 'usa-fx-layer';\n layer.setAttribute('aria-hidden', 'true');\n layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483000;overflow:hidden;contain:strict';\n document.body.appendChild(layer);\n return layer;\n}\n\nexport interface BurstOptions {\n /** Number of particles (default 12). */\n count?: number;\n /** Colours to pick from (default: accent palette). */\n colors?: string[];\n /** Travel distance in px (default 48). */\n distance?: number;\n /** Particle size in px (default 6). */\n size?: number;\n /** `circle` (default), `square`, `star`, `heart` or any text / emoji. */\n shape?: 'circle' | 'square' | 'star' | 'heart' | string;\n /** Duration in ms (default 600). */\n duration?: number;\n}\n\nconst PALETTE = ['#7c5cff', '#22d3ee', '#f472b6', '#facc15', '#34d399', '#fb923c'];\nconst GLYPH: Record<string, string> = { star: '★', heart: '♥' };\n\nfunction particle(x: number, y: number, size: number, color: string, shape: string): HTMLElement {\n const p = document.createElement('span');\n const glyph = GLYPH[shape] || (shape !== 'circle' && shape !== 'square' ? shape : '');\n p.style.cssText = `position:absolute;left:${x}px;top:${y}px;width:${size}px;height:${size}px;margin:${-size / 2}px 0 0 ${-size / 2}px;will-change:transform,opacity;` +\n (glyph ? `font-size:${size * 2}px;line-height:${size}px;text-align:center;color:${color}` : `background:${color};border-radius:${shape === 'square' ? '2px' : '50%'}`);\n if (glyph) p.textContent = glyph;\n fxLayer().appendChild(p);\n return p;\n}\n\nconst done = (a: Animation | null, el: Element) => {\n if (a) a.onfinish = () => el.remove();\n else el.remove();\n};\n\n/** Particles radiating from client point (x, y). Returns the number spawned. */\nexport function burst(x: number, y: number, options: BurstOptions = {}): number {\n if (typeof document === 'undefined' || prefersReducedMotion()) return 0;\n const { count = 12, colors = PALETTE, distance = 48, size = 6, shape = 'circle', duration = 600 } = options;\n for (let i = 0; i < count; i++) {\n const angle = (i / count) * Math.PI * 2 + Math.random() * 0.4;\n const d = distance * (0.7 + Math.random() * 0.5);\n const p = particle(x, y, size, colors[i % colors.length], shape);\n const a = typeof p.animate === 'function'\n ? p.animate(\n [\n { transform: 'translate(0,0) scale(1)', opacity: 1 },\n { transform: `translate(${Math.cos(angle) * d}px, ${Math.sin(angle) * d}px) scale(0.2)`, opacity: 0 },\n ],\n { duration: duration * (0.8 + Math.random() * 0.4), easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'forwards' }\n )\n : null;\n done(a, p);\n }\n return count;\n}\n\nexport interface ConfettiOptions {\n /** Origin in client px (default: centre-bottom third of the viewport). */\n x?: number;\n y?: number;\n /** Pieces (default 80). */\n count?: number;\n /** Spread angle in degrees (default 70). */\n spread?: number;\n /** Launch speed multiplier (default 1). */\n velocity?: number;\n colors?: string[];\n /** Duration in ms (default 1600). */\n duration?: number;\n}\n\n/** A confetti cannon (paper pieces with gravity, drift and spin). */\nexport function confetti(options: ConfettiOptions = {}): number {\n if (typeof document === 'undefined' || prefersReducedMotion()) return 0;\n const W = window.innerWidth || 800;\n const H = window.innerHeight || 600;\n const { x = W / 2, y = H * 0.66, count = 80, spread = 70, velocity = 1, colors = PALETTE, duration = 1600 } = options;\n for (let i = 0; i < count; i++) {\n const angle = ((-90 + (Math.random() - 0.5) * spread) * Math.PI) / 180;\n const speed = (260 + Math.random() * 320) * velocity;\n const vx = Math.cos(angle) * speed;\n const vy = Math.sin(angle) * speed;\n const p = particle(x, y, 6 + Math.random() * 5, colors[i % colors.length], Math.random() > 0.5 ? 'square' : 'circle');\n p.style.height = `${4 + Math.random() * 3}px`;\n const frames: Keyframe[] = [];\n const steps = 8;\n const T = duration / 1000;\n const spin = (Math.random() - 0.5) * 1440;\n for (let s = 0; s <= steps; s++) {\n const t = (s / steps) * T;\n const g = 900;\n frames.push({\n transform: `translate(${(vx * t * 0.8).toFixed(1)}px, ${(vy * t + 0.5 * g * t * t).toFixed(1)}px) rotate(${((spin * s) / steps).toFixed(0)}deg) rotateX(${s * 120}deg)`,\n opacity: s === steps ? 0 : 1,\n });\n }\n const a = typeof p.animate === 'function' ? p.animate(frames, { duration: duration * (0.85 + Math.random() * 0.3), easing: 'linear', fill: 'forwards' }) : null;\n done(a, p);\n }\n return count;\n}\n\n/** Horizontal error shake (`intensity` px, default 8). Reduced motion: a red outline flash. */\nexport function shake(el: Element, intensity = 8, duration = 480): Animation | null {\n const t = el as HTMLElement;\n if (typeof t.animate !== 'function') return null;\n if (prefersReducedMotion()) return t.animate([{ outline: '2px solid #e5484d' }, { outline: '2px solid transparent' }], { duration: 600 });\n const k = intensity;\n return t.animate(\n [0, -k, k, -k * 0.75, k * 0.75, -k * 0.4, k * 0.4, 0].map((v) => ({ transform: `translateX(${v}px)` })),\n { duration, easing: 'ease-in-out' }\n );\n}\n\n/** `navigator.vibrate()` where supported (Android Chrome, some WebViews). Returns whether it ran. */\nexport function haptic(pattern: number | number[] = 10): boolean {\n try {\n return typeof navigator !== 'undefined' && typeof navigator.vibrate === 'function' ? navigator.vibrate(pattern) : false;\n } catch {\n return false;\n }\n}\n\nexport { applyFrame };\n"],"names":[],"mappings":";;AAEA;;;;;AAKG;AAEH,IAAI,KAAK,GAAuB,IAAI;AACpC,SAAS,OAAO,GAAA;AACd,IAAA,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW;AAAE,QAAA,OAAO,KAAK;AAC5C,IAAA,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AACrC,IAAA,KAAK,CAAC,SAAS,GAAG,cAAc;AAChC,IAAA,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC;AACzC,IAAA,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,8FAA8F;AACpH,IAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;AAChC,IAAA,OAAO,KAAK;AACd;AAiBA,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE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N,QAAA,OAAO,KAAK;IACd;AACF;;;;"}
|
|
@@ -19,7 +19,8 @@ const COMPONENT_CATEGORIES = {
|
|
|
19
19
|
depth: ['usa-cube', 'usa-depth'],
|
|
20
20
|
layout: ['usa-auto-animate', 'usa-masonry'],
|
|
21
21
|
packs: ['usa-pack'],
|
|
22
|
+
fx: ['usa-fx'],
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
export { COMPONENT_CATEGORIES as C };
|
|
25
|
-
//# sourceMappingURL=index-tags-
|
|
26
|
+
//# sourceMappingURL=index-tags-DucKMQr_.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-tags-
|
|
1
|
+
{"version":3,"file":"index-tags-DucKMQr_.js","sources":["../../src/components/index-tags.ts"],"sourcesContent":["// The component categories and their default tags (no imports: safe for lazy loaders).\n/** The component categories and their default tags. */\nexport const COMPONENT_CATEGORIES = {\n reveal: ['usa-reveal', 'usa-stagger', 'usa-scroll-progress', 'usa-scrolly'],\n text: ['usa-typewriter', 'usa-split-text', 'usa-scramble', 'usa-counter', 'usa-shimmer-text', 'usa-text-rotate', 'usa-wave-text', 'usa-glitch', 'usa-gradient-text', 'usa-handwriting', 'usa-scroll-highlight'],\n interaction: ['usa-ripple', 'usa-magnetic', 'usa-tilt', 'usa-spotlight', 'usa-press', 'usa-toggle'],\n feedback: ['usa-spinner', 'usa-skeleton', 'usa-progress', 'usa-toaster', 'usa-check'],\n background: ['usa-aurora', 'usa-particles', 'usa-grain', 'usa-marquee', 'usa-acrylic', 'usa-grid-glow', 'usa-blobs', 'usa-water-ripple', 'usa-dot-network'],\n transitions: ['usa-dialog', 'usa-accordion', 'usa-view-switch'],\n physics: ['usa-spring', 'usa-draggable', 'usa-overscroll'],\n cards: ['usa-card', 'usa-card-stack', 'usa-sticky-stack', 'usa-carousel-3d'],\n click: ['usa-click', 'usa-button', 'usa-icon-morph', 'usa-like', 'usa-hold', 'usa-double-tap', 'usa-checkbox'],\n ui: ['usa-tabs', 'usa-drawer', 'usa-bottom-sheet', 'usa-pull-refresh', 'usa-fab', 'usa-navbar', 'usa-slider', 'usa-rating', 'usa-tooltip', 'usa-popover', 'usa-badge', 'usa-avatar-stack'],\n page: ['usa-cursor', 'usa-fullpage', 'usa-loading-bar', 'usa-back-to-top', 'usa-ambient', 'usa-splash', 'usa-auto-skeleton', 'usa-motion-switch'],\n timeline: ['usa-timeline'],\n gesture: ['usa-swipeable', 'usa-pinch-zoom'],\n svg: ['usa-draw', 'usa-morph', 'usa-mask-reveal', 'usa-anim-icon'],\n webgl: ['usa-shader', 'usa-distort', 'usa-liquid', 'usa-post-fx'],\n depth: ['usa-cube', 'usa-depth'],\n layout: ['usa-auto-animate', 'usa-masonry'],\n packs: ['usa-pack'],\n fx: ['usa-fx'],\n} as const;\n\nexport type ComponentCategory = keyof typeof COMPONENT_CATEGORIES;\n"],"names":[],"mappings":"AAAA;AACA;AACO,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,aAAa,CAAC;IAC3E,IAAI,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;AAC/M,IAAA,WAAW,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,CAAC;IACnG,QAAQ,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,CAAC;AACrF,IAAA,UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,CAAC;AAC3J,IAAA,WAAW,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,iBA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
|
25
26
|
|
|
26
27
|
exports.COMPONENT_CATEGORIES = COMPONENT_CATEGORIES;
|
|
27
|
-
//# sourceMappingURL=index-tags-
|
|
28
|
+
//# sourceMappingURL=index-tags-wv0R_vkO.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-tags-
|
|
1
|
+
{"version":3,"file":"index-tags-wv0R_vkO.cjs","sources":["../../src/components/index-tags.ts"],"sourcesContent":["// The component categories and their default tags (no imports: safe for lazy loaders).\n/** The component categories and their default tags. */\nexport const COMPONENT_CATEGORIES = {\n reveal: ['usa-reveal', 'usa-stagger', 'usa-scroll-progress', 'usa-scrolly'],\n text: ['usa-typewriter', 'usa-split-text', 'usa-scramble', 'usa-counter', 'usa-shimmer-text', 'usa-text-rotate', 'usa-wave-text', 'usa-glitch', 'usa-gradient-text', 'usa-handwriting', 'usa-scroll-highlight'],\n interaction: ['usa-ripple', 'usa-magnetic', 'usa-tilt', 'usa-spotlight', 'usa-press', 'usa-toggle'],\n feedback: ['usa-spinner', 'usa-skeleton', 'usa-progress', 'usa-toaster', 'usa-check'],\n background: ['usa-aurora', 'usa-particles', 'usa-grain', 'usa-marquee', 'usa-acrylic', 'usa-grid-glow', 'usa-blobs', 'usa-water-ripple', 'usa-dot-network'],\n transitions: ['usa-dialog', 'usa-accordion', 'usa-view-switch'],\n physics: ['usa-spring', 'usa-draggable', 'usa-overscroll'],\n cards: ['usa-card', 'usa-card-stack', 'usa-sticky-stack', 'usa-carousel-3d'],\n click: ['usa-click', 'usa-button', 'usa-icon-morph', 'usa-like', 'usa-hold', 'usa-double-tap', 'usa-checkbox'],\n ui: ['usa-tabs', 'usa-drawer', 'usa-bottom-sheet', 'usa-pull-refresh', 'usa-fab', 'usa-navbar', 'usa-slider', 'usa-rating', 'usa-tooltip', 'usa-popover', 'usa-badge', 'usa-avatar-stack'],\n page: ['usa-cursor', 'usa-fullpage', 'usa-loading-bar', 'usa-back-to-top', 'usa-ambient', 'usa-splash', 'usa-auto-skeleton', 'usa-motion-switch'],\n timeline: ['usa-timeline'],\n gesture: ['usa-swipeable', 'usa-pinch-zoom'],\n svg: ['usa-draw', 'usa-morph', 'usa-mask-reveal', 'usa-anim-icon'],\n webgl: ['usa-shader', 'usa-distort', 'usa-liquid', 'usa-post-fx'],\n depth: ['usa-cube', 'usa-depth'],\n layout: ['usa-auto-animate', 'usa-masonry'],\n packs: ['usa-pack'],\n fx: ['usa-fx'],\n} as const;\n\nexport type ComponentCategory = keyof typeof COMPONENT_CATEGORIES;\n"],"names":[],"mappings":";;AAAA;AACA;AACO,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,aAAa,CAAC;IAC3E,IAAI,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;AAC/M,IAAA,WAAW,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,CAAC;IACnG,QAAQ,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,CAAC;AACrF,IAAA,UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,CAAC;AAC3J,IAAA,WAAW,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,iBAAiB,CAAC;AAC/D,IAAA,OAAO,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,gBAAgB,CAAC;IAC1D,KAAK,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,iBAAiB,CAAC;AAC5E,IAAA,KAAK,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,CAAC;IAC9G,EAAE,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,CAAC;AAC1L,IAAA,IAAI,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,CAAC;IACjJ,QAAQ,EAAE,CAAC,cAAc,CAAC;AAC1B,IAAA,OAAO,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAC5C,GAAG,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,CAAC;IAClE,KAAK,EAAE,CAAC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,CAAC;AACjE,IAAA,KAAK,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC;AAChC,IAAA,MAAM,EAAE,CAAC,kBAAkB,EAAE,aAAa,CAAC;IAC3C,KAAK,EAAE,CAAC,UAAU,CAAC;IACnB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-
|
|
3
|
+
var base = require('./base-B5i8qQPR.cjs');
|
|
4
4
|
|
|
5
5
|
const SPRING_PRESETS = {
|
|
6
6
|
default: { stiffness: 170, damping: 26, mass: 1 },
|
|
@@ -229,4 +229,4 @@ exports.springEasing = springEasing;
|
|
|
229
229
|
exports.springSamples = springSamples;
|
|
230
230
|
exports.stepSpring = stepSpring;
|
|
231
231
|
exports.supportsLinearEasing = supportsLinearEasing;
|
|
232
|
-
//# sourceMappingURL=spring
|
|
232
|
+
//# sourceMappingURL=spring--oZh55tB.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring-Dkpygsuj.cjs","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":["EASE_SPRING","prefersReducedMotion","applyFrame","motionScale","caf","now","raf"],"mappings":";;;;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC/C,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC9C,IAAA,QAAQ,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE;;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C,GAAG,SAAS;AACtE;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"spring--oZh55tB.cjs","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":["EASE_SPRING","prefersReducedMotion","applyFrame","motionScale","caf","now","raf"],"mappings":";;;;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC/C,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC9C,IAAA,QAAQ,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,E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C,CAAC,GAAG,SAAS;AACtE;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { p as prefersReducedMotion, l as applyFrame, m as motionScale, E as EASE_SPRING, n as now, r as raf,
|
|
1
|
+
import { p as prefersReducedMotion, l as applyFrame, m as motionScale, E as EASE_SPRING, n as now, r as raf, q as caf } from './base-C3Sw9sAO.js';
|
|
2
2
|
|
|
3
3
|
const SPRING_PRESETS = {
|
|
4
4
|
default: { stiffness: 170, damping: 26, mass: 1 },
|
|
@@ -216,4 +216,4 @@ function rubberBand(distance, dimension, constant = 0.55) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
export { SPRING_PRESETS as S, rubberBand as a, spring as b, createSpring as c, springEasing as d, springSamples as e, stepSpring as f, supportsLinearEasing as g, linearEasing as l, projectInertia as p, resolveSpring as r, snapTo as s };
|
|
219
|
-
//# sourceMappingURL=spring-
|
|
219
|
+
//# sourceMappingURL=spring-CckMe3x0.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring-BS5tg6aK.js","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAA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AA,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE;AACxE,IAAA,OAAO,KAAK;AACd;AAEA;AACM,SAAU,UAAU,CAAC,QAAgB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAA;IAC7E,IAAI,SAAS,IAAI,CAAC;AAAE,QAAA,OAAO,CAAC;AAC5B,IAAA,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS;AACtE;;;;"}
|
|
1
|
+
{"version":3,"file":"spring-CckMe3x0.js","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SA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IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE;AACxE,IAAA,OAAO,KAAK;AACd;AAEA;AACM,SAAU,UAAU,CAAC,QAAgB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAA;IAC7E,IAAI,SAAS,IAAI,CAAC;AAAE,QAAA,OAAO,CAAC;AAC5B,IAAA,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS;AACtE;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { u as adoptStyles } from './base-C3Sw9sAO.js';
|
|
2
2
|
|
|
3
3
|
var css = ":root{--usa-accent:#7c5cff;--usa-accent-text:#fff;--usa-surface:#1b1e27;--usa-text:inherit;--usa-radius:14px;--usa-border:1px solid rgb(127 127 127 / 0.25);--usa-shadow:0 10px 30px -12px rgb(0 0 0 / 0.45);--usa-blur:0px;--usa-font:inherit}:where([variant=\"minimal\"],[data-usa-variant=\"minimal\"]){--usa-accent:currentColor;--usa-accent-text:Canvas;--usa-surface:transparent;--usa-radius:6px;--usa-border:1px solid color-mix(in srgb,currentColor 22%,transparent);--usa-shadow:none;--usa-blur:0px}:where([variant=\"neon\"],[data-usa-variant=\"neon\"]){--usa-accent:#00f0ff;--usa-accent-text:#04121a;--usa-surface:#0a0b14;--usa-text:#e6fbff;--usa-radius:10px;--usa-border:1px solid #00f0ff;--usa-shadow:0 0 6px #00f0ff,0 0 22px rgb(0 240 255 / 0.45);--usa-blur:0px}:where([variant=\"glass\"],[data-usa-variant=\"glass\"]){--usa-accent:#a78bfa;--usa-accent-text:#fff;--usa-surface:rgb(255 255 255 / 0.12);--usa-radius:18px;--usa-border:1px solid rgb(255 255 255 / 0.28);--usa-shadow:0 12px 40px -12px rgb(0 0 0 / 0.35);--usa-blur:16px}:where([variant=\"brutalist\"],[data-usa-variant=\"brutalist\"]){--usa-accent:#ff3d00;--usa-accent-text:#000;--usa-surface:#fff;--usa-text:#000;--usa-radius:0px;--usa-border:3px solid #000;--usa-shadow:5px 5px 0 #000;--usa-blur:0px;--usa-font:ui-monospace,\"SFMono-Regular\",Menlo,monospace}:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#0067c0;--usa-accent-text:#fff;--usa-surface:rgb(249 249 249 / 0.82);--usa-text:#1a1a1a;--usa-radius:8px;--usa-border:1px solid rgb(0 0 0 / 0.08);--usa-shadow:0 2px 4px rgb(0 0 0 / 0.14),0 0 2px rgb(0 0 0 / 0.12);--usa-blur:30px;--usa-font:\"Segoe UI Variable\",\"Segoe UI\",system-ui,sans-serif}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#6750a4;--usa-accent-text:#fff;--usa-surface:#fffbfe;--usa-text:#1c1b1f;--usa-radius:20px;--usa-border:0 solid transparent;--usa-shadow:0 1px 3px rgb(0 0 0 / 0.3),0 4px 8px 3px rgb(0 0 0 / 0.15);--usa-blur:0px;--usa-font:Roboto,system-ui,sans-serif}@media (prefers-color-scheme:dark){:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#4cc2ff;--usa-accent-text:#000;--usa-surface:rgb(44 44 44 / 0.8);--usa-text:#fff;--usa-border:1px solid rgb(255 255 255 / 0.08)}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#d0bcff;--usa-accent-text:#381e72;--usa-surface:#1c1b1f;--usa-text:#e6e1e5}}.usa-surface{background:var(--usa-surface);color:var(--usa-text);border:var(--usa-border);border-radius:var(--usa-radius);box-shadow:var(--usa-shadow);font-family:var(--usa-font);-webkit-backdrop-filter:blur(var(--usa-blur));backdrop-filter:blur(var(--usa-blur))}@media (prefers-reduced-transparency:reduce){.usa-surface{-webkit-backdrop-filter:none;backdrop-filter:none}}";
|
|
4
4
|
|
|
@@ -32,4 +32,4 @@ function setVariant(variant, root = typeof document !== 'undefined' ? document.d
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export { VARIANTS as V, adoptVariants as a, setVariant as s };
|
|
35
|
-
//# sourceMappingURL=variants-
|
|
35
|
+
//# sourceMappingURL=variants-Bsevy6Xm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants-
|
|
1
|
+
{"version":3,"file":"variants-Bsevy6Xm.js","sources":["../../src/components/ui/variants.ts"],"sourcesContent":["import { adoptStyles } from '../base';\nimport css from './variants.css?raw';\n\n/**\n * Style variants (v2.6): `variant=\"minimal | neon | glass | brutalist |\n * fluent | material\"` on any `<usa-*>` element — or on any ancestor as\n * `data-usa-variant`, or page-wide with `setVariant()` — sets the shared\n * design tokens every component reads:\n *\n * `--usa-accent`, `--usa-accent-text`, `--usa-surface`, `--usa-text`,\n * `--usa-radius`, `--usa-border`, `--usa-shadow`, `--usa-blur`, `--usa-font`.\n *\n * (`<usa-spinner>`, `<usa-check>` and `<usa-dialog>` already use `variant`\n * for their kind; the token names never clash with those values except\n * `fluent`, which means the same thing there.)\n */\nexport const VARIANTS = ['minimal', 'neon', 'glass', 'brutalist', 'fluent', 'material'] as const;\nexport type Variant = (typeof VARIANTS)[number];\n\n/** Inject the variant token sheet (done automatically by every `ui` component). */\nexport function adoptVariants(): void {\n adoptStyles('variants', css);\n}\n\n/** Apply a variant to the whole page (or `root`); `null` removes it. */\nexport function setVariant(variant: Variant | null, root: Element | null = typeof document !== 'undefined' ? document.documentElement : null): void {\n if (!root) return;\n adoptVariants();\n if (variant) root.setAttribute('data-usa-variant', variant);\n else root.removeAttribute('data-usa-variant');\n}\n"],"names":[],"mappings":";;;;AAGA;;;;;;;;;;;;AAYG;AACI,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU;AAGtF;SACgB,aAAa,GAAA;AAC3B,IAAA,WAAW,CAAC,UAAU,EAAE,GAAG,CAAC;AAC9B;AAEA;SACgB,UAAU,CAAC,OAAuB,EAAE,IAAA,GAAuB,OAAO,QAAQ,KAAK,WAAW,GAAG,QAAQ,CAAC,eAAe,GAAG,IAAI,EAAA;AAC1I,IAAA,IAAI,CAAC,IAAI;QAAE;AACX,IAAA,aAAa,EAAE;AACf,IAAA,IAAI,OAAO;AAAE,QAAA,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,OAAO,CAAC;;AACtD,QAAA,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC;AAC/C;;;;"}
|