use-scroll-animate 2.2.0 → 2.4.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +3 -1
  3. package/README_ja.md +2 -0
  4. package/README_zh.md +2 -0
  5. package/dist/chunks/{base-BiTc85p_.cjs → base-CJ7XfidP.cjs} +2 -1
  6. package/dist/chunks/{base-BiTc85p_.cjs.map → base-CJ7XfidP.cjs.map} +1 -1
  7. package/dist/chunks/{base-CFtnmfli.js → base-CuvCgqLy.js} +2 -2
  8. package/dist/chunks/{base-CFtnmfli.js.map → base-CuvCgqLy.js.map} +1 -1
  9. package/dist/chunks/spring-BKUU7-Xm.js +219 -0
  10. package/dist/chunks/spring-BKUU7-Xm.js.map +1 -0
  11. package/dist/chunks/spring-CGO9Jd9b.cjs +232 -0
  12. package/dist/chunks/spring-CGO9Jd9b.cjs.map +1 -0
  13. package/dist/components/background.cjs +1 -1
  14. package/dist/components/background.js +2 -2
  15. package/dist/components/cards.cjs +563 -0
  16. package/dist/components/cards.cjs.map +1 -0
  17. package/dist/components/cards.css +6 -0
  18. package/dist/components/cards.d.cts +142 -0
  19. package/dist/components/cards.d.ts +142 -0
  20. package/dist/components/cards.js +555 -0
  21. package/dist/components/cards.js.map +1 -0
  22. package/dist/components/feedback.cjs +1 -1
  23. package/dist/components/feedback.js +2 -2
  24. package/dist/components/interaction.cjs +1 -1
  25. package/dist/components/interaction.js +2 -2
  26. package/dist/components/physics.cjs +450 -0
  27. package/dist/components/physics.cjs.map +1 -0
  28. package/dist/components/physics.css +5 -0
  29. package/dist/components/physics.d.cts +216 -0
  30. package/dist/components/physics.d.ts +216 -0
  31. package/dist/components/physics.js +431 -0
  32. package/dist/components/physics.js.map +1 -0
  33. package/dist/components/reveal.cjs +1 -1
  34. package/dist/components/reveal.js +2 -2
  35. package/dist/components/text.cjs +1 -1
  36. package/dist/components/text.js +2 -2
  37. package/dist/components/transitions.cjs +1 -1
  38. package/dist/components/transitions.js +2 -2
  39. package/dist/components.cjs +32 -1
  40. package/dist/components.cjs.map +1 -1
  41. package/dist/components.css +7 -0
  42. package/dist/components.d.cts +284 -2
  43. package/dist/components.d.ts +284 -2
  44. package/dist/components.js +11 -2
  45. package/dist/components.js.map +1 -1
  46. package/dist/components.umd.js +2 -2
  47. package/dist/components.umd.js.map +1 -1
  48. package/docs/components.md +23 -0
  49. package/package.json +25 -2
@@ -0,0 +1,563 @@
1
+ 'use strict';
2
+
3
+ var base = require('../chunks/base-CJ7XfidP.cjs');
4
+ var spring = require('../chunks/spring-CGO9Jd9b.cjs');
5
+
6
+ var css$3 = "usa-card{--usa-card-radius:18px;--usa-card-bg:var(--usa-surface,#1b1e27);--usa-card-glow:var(--usa-accent,#7c5cff);--usa-card-x:50%;--usa-card-y:50%;--usa-card-nx:0;--usa-card-ny:0;position:relative;display:block;border-radius:var(--usa-card-radius);isolation:isolate;-webkit-tap-highlight-color:transparent}usa-card:focus-visible{outline:2px solid var(--usa-card-glow);outline-offset:3px}usa-card[effect~=\"lift\"]{transition:transform 0.45s cubic-bezier(0.34,1.56,0.64,1),box-shadow 0.45s ease}usa-card[effect~=\"lift\"][data-hover],usa-card[effect~=\"lift\"]:focus-visible{transform:translateY(-6px) perspective(900px) rotateX(calc(var(--usa-card-ny) * -4deg)) rotateY(calc(var(--usa-card-nx) * 4deg));box-shadow:0 22px 44px -18px rgb(0 0 0 / 0.55)}usa-card[effect~=\"glass\"]{background:color-mix(in srgb,var(--usa-card-bg) 45%,transparent);border:1px solid rgb(255 255 255 / 0.16);-webkit-backdrop-filter:blur(18px) saturate(1.5);backdrop-filter:blur(18px) saturate(1.5)}usa-card[effect~=\"spotlight\"]::before,usa-card[effect~=\"border-glow\"]::after{content:\"\";position:absolute;inset:0;border-radius:inherit;pointer-events:none;opacity:0;transition:opacity 0.3s ease}usa-card[effect~=\"spotlight\"]::before{z-index:-1;background:radial-gradient(260px circle at var(--usa-card-x) var(--usa-card-y),color-mix(in srgb,var(--usa-card-glow) 28%,transparent),transparent 70%)}usa-card[effect~=\"border-glow\"]::after{padding:1.5px;background:radial-gradient(180px circle at var(--usa-card-x) var(--usa-card-y),var(--usa-card-glow),transparent 70%);-webkit-mask:linear-gradient(#000 0 0) content-box exclude,linear-gradient(#000 0 0);mask:linear-gradient(#000 0 0) content-box exclude,linear-gradient(#000 0 0)}usa-card[data-hover]::before,usa-card[data-hover]::after{opacity:1}@property --usa-card-angle{syntax:\"<angle>\";inherits:false;initial-value:0deg}usa-card[effect~=\"conic-border\"]{border:2px solid transparent;background:linear-gradient(var(--usa-card-bg),var(--usa-card-bg)) padding-box,conic-gradient(from var(--usa-card-angle),var(--usa-card-glow),#22d3ee,#f472b6,var(--usa-card-glow)) border-box;animation:usa-card-spin 4s linear infinite}@keyframes usa-card-spin{to{--usa-card-angle:360deg}}usa-card .usa-card-sheen{position:absolute;inset:0;border-radius:inherit;overflow:hidden;pointer-events:none}usa-card .usa-card-sheen::before{content:\"\";position:absolute;top:0;bottom:0;width:45%;left:-60%;transform:skewX(-20deg);background:linear-gradient(90deg,transparent,rgb(255 255 255 / 0.35),transparent)}usa-card[effect~=\"sheen\"]:hover .usa-card-sheen::before,usa-card[effect~=\"sheen\"]:focus-visible .usa-card-sheen::before{left:130%;transition:left 0.8s cubic-bezier(0.22,1,0.36,1)}usa-card .usa-card-holo{position:absolute;inset:0;border-radius:inherit;pointer-events:none;mix-blend-mode:color-dodge;opacity:0.35;background:linear-gradient(115deg,transparent 20%,#ff7ad9 35%,#7af0ff 45%,#ffe27a 55%,transparent 70%) calc(var(--usa-card-x) * 1.4 - 20%) calc(var(--usa-card-y) * 1.4 - 20%) / 220% 220%;transition:opacity 0.3s ease}usa-card[data-hover] .usa-card-holo{opacity:0.7}usa-card[effect~=\"parallax-layers\"] [data-depth]{transition:transform 0.25s ease-out;will-change:transform}usa-card[effect~=\"flip\"]{perspective:1000px;display:grid}usa-card[effect~=\"flip\"]>[data-front],usa-card[effect~=\"flip\"]>[data-back]{grid-area:1 / 1;backface-visibility:hidden;-webkit-backface-visibility:hidden;border-radius:inherit;transition:transform 0.7s cubic-bezier(0.34,1.3,0.64,1),opacity 0.3s ease}usa-card[effect~=\"flip\"]>[data-back]{transform:rotateY(180deg)}usa-card[effect~=\"flip\"][axis=\"x\"]>[data-back]{transform:rotateX(180deg)}usa-card[effect~=\"flip\"][flipped]>[data-front],usa-card[effect~=\"flip\"]:not([trigger=\"click\"]):hover>[data-front]{transform:rotateY(-180deg)}usa-card[effect~=\"flip\"][flipped]>[data-back],usa-card[effect~=\"flip\"]:not([trigger=\"click\"]):hover>[data-back]{transform:rotateY(0deg)}usa-card[effect~=\"flip\"][axis=\"x\"][flipped]>[data-front],usa-card[effect~=\"flip\"][axis=\"x\"]:not([trigger=\"click\"]):hover>[data-front]{transform:rotateX(180deg)}usa-card[effect~=\"flip\"][axis=\"x\"][flipped]>[data-back],usa-card[effect~=\"flip\"][axis=\"x\"]:not([trigger=\"click\"]):hover>[data-back]{transform:rotateX(0deg)}usa-card[effect~=\"flip\"][trigger=\"click\"]{cursor:pointer}usa-card[effect~=\"expand\"]{cursor:zoom-in}usa-card[effect~=\"expand\"]:not([expanded]) [data-detail]{display:none}usa-card[expanded]{position:fixed;inset:6vh max(4vw,calc(50vw - 420px));z-index:1000;overflow:auto;cursor:default;background:var(--usa-card-bg);box-shadow:0 30px 80px -20px rgb(0 0 0 / 0.6)}.usa-card-backdrop{position:fixed;inset:0;z-index:999;background:rgb(0 0 0 / 0.45)}@media (prefers-reduced-motion:reduce){usa-card,usa-card *,usa-card .usa-card-sheen::before{transition-duration:0.01ms !important;animation:none !important}usa-card[effect~=\"lift\"][data-hover]{transform:none}usa-card[effect~=\"flip\"]>[data-front],usa-card[effect~=\"flip\"]>[data-back]{transform:none !important}usa-card[effect~=\"flip\"][flipped]>[data-front],usa-card[effect~=\"flip\"]:not([flipped])>[data-back]{opacity:0;visibility:hidden}usa-card[effect~=\"flip\"]:not([trigger=\"click\"]):hover>[data-front]{opacity:0;visibility:hidden}usa-card[effect~=\"flip\"]:not([trigger=\"click\"]):hover>[data-back]{opacity:1;visibility:visible}}@media (prefers-reduced-transparency:reduce),(forced-colors:active){usa-card[effect~=\"glass\"]{background:var(--usa-card-bg);-webkit-backdrop-filter:none;backdrop-filter:none}}";
7
+
8
+ const CARD_EFFECTS = ['flip', 'holo', 'glass', 'border-glow', 'conic-border', 'lift', 'spotlight', 'sheen', 'parallax-layers', 'expand'];
9
+ /** Effects that follow the pointer (they share one rAF-throttled tracker). */
10
+ const TRACKING = new Set(['holo', 'border-glow', 'spotlight', 'parallax-layers', 'lift']);
11
+ function defineCard(tag = 'usa-card') {
12
+ return base.defineElement(tag, (Base) => class UsaCard extends Base {
13
+ constructor() {
14
+ super(...arguments);
15
+ this._frame = 0;
16
+ this._spacer = null;
17
+ this._backdrop = null;
18
+ this._busy = false;
19
+ }
20
+ static get observedAttributes() {
21
+ return ['effect', 'trigger', 'disabled'];
22
+ }
23
+ get effects() {
24
+ return this.str('effect', 'lift').split(/[\s,]+/).filter(Boolean);
25
+ }
26
+ has(e) {
27
+ return this.effects.includes(e);
28
+ }
29
+ get flipped() {
30
+ return this.flag('flipped');
31
+ }
32
+ set flipped(v) {
33
+ this.setFlag('flipped', v);
34
+ }
35
+ get expanded() {
36
+ return this.flag('expanded');
37
+ }
38
+ mount() {
39
+ if (this.flag('disabled'))
40
+ return;
41
+ const color = this.str('color');
42
+ if (color)
43
+ this.style.setProperty('--usa-card-glow', color);
44
+ if (this.has('sheen') && !this.querySelector(':scope > .usa-card-sheen'))
45
+ this.append(deco('usa-card-sheen'));
46
+ if (this.has('holo') && !this.querySelector(':scope > .usa-card-holo'))
47
+ this.append(deco('usa-card-holo'));
48
+ if (this.has('flip')) {
49
+ const click = this.str('trigger', 'hover') === 'click';
50
+ if (click) {
51
+ if (!this.hasAttribute('tabindex'))
52
+ this.tabIndex = 0;
53
+ this.setAttribute('role', this.getAttribute('role') || 'button');
54
+ this.setAttribute('aria-pressed', String(this.flipped));
55
+ this.listen(this, 'click', (e) => !interactive(e.target, this) && this.flip());
56
+ this.listen(this, 'keydown', (e) => {
57
+ if ((e.key === 'Enter' || e.key === ' ') && e.target === this) {
58
+ e.preventDefault();
59
+ this.flip();
60
+ }
61
+ });
62
+ }
63
+ this.setBackHidden();
64
+ }
65
+ if (this.has('expand')) {
66
+ if (!this.hasAttribute('tabindex'))
67
+ this.tabIndex = 0;
68
+ this.setAttribute('aria-expanded', String(this.expanded));
69
+ this.listen(this, 'click', (e) => {
70
+ const t = e.target;
71
+ if (t.closest?.('[data-close]')) {
72
+ e.stopPropagation();
73
+ this.collapse();
74
+ }
75
+ else if (!this.expanded && !interactive(t, this))
76
+ this.expand();
77
+ });
78
+ this.listen(this, 'keydown', (e) => {
79
+ if (e.key === 'Escape' && this.expanded)
80
+ this.collapse();
81
+ else if ((e.key === 'Enter' || e.key === ' ') && e.target === this && !this.expanded) {
82
+ e.preventDefault();
83
+ this.expand();
84
+ }
85
+ });
86
+ }
87
+ if (!this.effects.some((e) => TRACKING.has(e)) || this.reduced)
88
+ return;
89
+ let rect = null;
90
+ let px = 0.5;
91
+ let py = 0.5;
92
+ const apply = () => {
93
+ this._frame = 0;
94
+ const nx = base.clamp(px * 2 - 1, -1, 1);
95
+ const ny = base.clamp(py * 2 - 1, -1, 1);
96
+ this.style.setProperty('--usa-card-x', `${(px * 100).toFixed(1)}%`);
97
+ this.style.setProperty('--usa-card-y', `${(py * 100).toFixed(1)}%`);
98
+ this.style.setProperty('--usa-card-nx', nx.toFixed(3));
99
+ this.style.setProperty('--usa-card-ny', ny.toFixed(3));
100
+ if (this.has('parallax-layers')) {
101
+ const depth = this.num('depth', 16);
102
+ this.querySelectorAll('[data-depth]').forEach((l) => {
103
+ const d = Number(l.dataset.depth) || 0.5;
104
+ l.style.transform = `translate3d(${(nx * depth * d).toFixed(1)}px, ${(ny * depth * d).toFixed(1)}px, 0)`;
105
+ });
106
+ }
107
+ };
108
+ this.listen(this, 'pointerenter', () => {
109
+ rect = this.getBoundingClientRect();
110
+ this.setAttribute('data-hover', '');
111
+ });
112
+ this.listen(this, 'pointermove', (e) => {
113
+ if (this.expanded)
114
+ return;
115
+ rect = rect || this.getBoundingClientRect();
116
+ px = (e.clientX - rect.left) / (rect.width || 1);
117
+ py = (e.clientY - rect.top) / (rect.height || 1);
118
+ if (!this._frame)
119
+ this._frame = base.raf(apply);
120
+ });
121
+ this.listen(this, 'pointerleave', () => {
122
+ rect = null;
123
+ px = py = 0.5;
124
+ this.removeAttribute('data-hover');
125
+ if (!this._frame)
126
+ this._frame = base.raf(apply);
127
+ });
128
+ }
129
+ unmount() {
130
+ base.caf(this._frame);
131
+ this._frame = 0;
132
+ if (this.expanded)
133
+ this.finishCollapse();
134
+ }
135
+ setBackHidden() {
136
+ const front = this.querySelector(':scope > [data-front]');
137
+ const back = this.querySelector(':scope > [data-back]');
138
+ front?.setAttribute('aria-hidden', String(this.flipped));
139
+ back?.setAttribute('aria-hidden', String(!this.flipped));
140
+ }
141
+ flip(force) {
142
+ const next = force === undefined ? !this.flipped : force;
143
+ if (next === this.flipped)
144
+ return;
145
+ this.flipped = next;
146
+ if (this.hasAttribute('aria-pressed'))
147
+ this.setAttribute('aria-pressed', String(next));
148
+ this.setBackHidden();
149
+ this.emit('flip', { flipped: next });
150
+ }
151
+ async expand() {
152
+ if (this.expanded || this._busy)
153
+ return;
154
+ this._busy = true;
155
+ const first = this.getBoundingClientRect();
156
+ const spacer = document.createElement('div');
157
+ spacer.className = 'usa-card-spacer';
158
+ spacer.style.cssText = `width:${first.width}px;height:${first.height}px`;
159
+ spacer.setAttribute('aria-hidden', 'true');
160
+ this.before(spacer);
161
+ this._spacer = spacer;
162
+ const backdrop = document.createElement('div');
163
+ backdrop.className = 'usa-card-backdrop';
164
+ backdrop.addEventListener('click', () => this.collapse());
165
+ this.before(backdrop);
166
+ this._backdrop = backdrop;
167
+ this.setFlag('expanded', true);
168
+ this.setAttribute('aria-expanded', 'true');
169
+ this.emit('expand');
170
+ const last = this.getBoundingClientRect();
171
+ await this.flipFrom(first, last);
172
+ this.motion(backdrop, [{ opacity: 0 }, { opacity: 1 }], { duration: 250, easing: 'ease-out' });
173
+ this.focus({ preventScroll: true });
174
+ this._busy = false;
175
+ }
176
+ async collapse() {
177
+ if (!this.expanded || this._busy)
178
+ return;
179
+ this._busy = true;
180
+ const first = this.getBoundingClientRect();
181
+ const b = this._backdrop;
182
+ if (b)
183
+ this.motion(b, [{ opacity: 1 }, { opacity: 0 }], { duration: 200, easing: 'ease-in', fill: 'forwards' });
184
+ this.finishCollapse();
185
+ this.emit('collapse');
186
+ const last = this.getBoundingClientRect();
187
+ await this.flipFrom(first, last);
188
+ this._busy = false;
189
+ }
190
+ finishCollapse() {
191
+ this.setFlag('expanded', false);
192
+ this.setAttribute('aria-expanded', 'false');
193
+ this._spacer?.remove();
194
+ this._backdrop?.remove();
195
+ this._spacer = this._backdrop = null;
196
+ }
197
+ async flipFrom(first, last) {
198
+ if (this.reduced) {
199
+ const a = this.motion(this, [{ opacity: 0.4 }, { opacity: 1 }], { duration: 200 });
200
+ await a?.finished.catch(() => undefined);
201
+ return;
202
+ }
203
+ const sx = first.width / (last.width || 1);
204
+ const sy = first.height / (last.height || 1);
205
+ const dx = first.left - last.left;
206
+ const dy = first.top - last.top;
207
+ const { easing, duration } = spring.springEasing('stiff');
208
+ const a = this.motion(this, [{ transformOrigin: '0 0', transform: `translate(${dx}px, ${dy}px) scale(${sx}, ${sy})` }, { transformOrigin: '0 0', transform: 'none' }], { duration: Math.min(duration, 900), easing: easing || base.EASE_OUT });
209
+ await a?.finished.catch(() => undefined);
210
+ }
211
+ }, { id: 'card', text: css$3 });
212
+ }
213
+ function deco(cls) {
214
+ const s = document.createElement('span');
215
+ s.className = cls;
216
+ s.setAttribute('aria-hidden', 'true');
217
+ return s;
218
+ }
219
+ /** Clicks on links, buttons and form fields inside the card keep their own behaviour. */
220
+ function interactive(t, host) {
221
+ const el = t?.closest?.('a, button, input, select, textarea, label, [contenteditable]');
222
+ return !!el && el !== host && host.contains(el);
223
+ }
224
+
225
+ var css$2 = "usa-card-stack{position:relative;display:grid;touch-action:pan-y;user-select:none;-webkit-user-select:none}usa-card-stack>*{grid-area:1 / 1;transform-origin:50% 100%;transition:transform 0.35s cubic-bezier(0.34,1.3,0.64,1),opacity 0.3s ease;will-change:transform}usa-card-stack>[data-top]{cursor:grab}usa-card-stack[data-dragging]>*,usa-card-stack>[data-top]{transition:none}usa-card-stack:focus-visible{outline:2px solid var(--usa-accent,#7c5cff);outline-offset:4px;border-radius:12px}@media (prefers-reduced-motion:reduce){usa-card-stack>*{transition:none}}";
226
+
227
+ function defineCardStack(tag = 'usa-card-stack') {
228
+ return base.defineElement(tag, (Base) => class UsaCardStack extends Base {
229
+ constructor() {
230
+ super(...arguments);
231
+ this._drag = null;
232
+ this._busy = false;
233
+ }
234
+ static get observedAttributes() {
235
+ return ['visible', 'offset', 'disabled'];
236
+ }
237
+ get top() {
238
+ return this.cards()[0] || null;
239
+ }
240
+ cards() {
241
+ return Array.from(this.children).filter((c) => !c.hasAttribute('data-gone'));
242
+ }
243
+ layout(dragX = 0) {
244
+ const visible = this.num('visible', 3);
245
+ const off = this.num('offset', 10);
246
+ const reduced = this.reduced;
247
+ this.cards().forEach((c, i) => {
248
+ c.style.zIndex = String(100 - i);
249
+ c.toggleAttribute('data-top', i === 0);
250
+ c.setAttribute('aria-hidden', String(i !== 0));
251
+ if (i === 0) {
252
+ const rot = reduced ? 0 : dragX / 18;
253
+ c.style.transform = `translate3d(${dragX}px, 0, 0) rotate(${rot.toFixed(2)}deg)`;
254
+ c.style.opacity = '1';
255
+ }
256
+ else {
257
+ const k = Math.min(i, visible);
258
+ const pull = Math.min(1, Math.abs(dragX) / this.num('threshold', 90));
259
+ const kk = Math.max(0, k - pull);
260
+ c.style.transform = `translate3d(0, ${(kk * off).toFixed(1)}px, 0) scale(${(1 - kk * 0.05).toFixed(3)})`;
261
+ c.style.opacity = i > visible ? '0' : '1';
262
+ }
263
+ });
264
+ }
265
+ mount() {
266
+ if (!this.hasAttribute('tabindex'))
267
+ this.tabIndex = 0;
268
+ if (!this.hasAttribute('role'))
269
+ this.setAttribute('role', 'group');
270
+ this.setAttribute('aria-roledescription', 'card stack');
271
+ this._x = spring.createSpring({ spring: 'wobbly', onUpdate: (v) => this.layout(v) });
272
+ this.layout();
273
+ this.listen(this, 'pointerdown', (e) => {
274
+ if (this.flag('disabled') || this._busy || !this.top || !this.top.contains(e.target))
275
+ return;
276
+ this._x.stop();
277
+ this._drag = { id: e.pointerId, x0: e.clientX - this._x.value, t0: e.timeStamp };
278
+ try {
279
+ this.setPointerCapture?.(e.pointerId);
280
+ }
281
+ catch {
282
+ /* synthetic */
283
+ }
284
+ this.setAttribute('data-dragging', '');
285
+ });
286
+ this.listen(this, 'pointermove', (e) => {
287
+ if (!this._drag || e.pointerId !== this._drag.id)
288
+ return;
289
+ this._x.jump(e.clientX - this._drag.x0);
290
+ });
291
+ const up = (e) => {
292
+ if (!this._drag || e.pointerId !== this._drag.id)
293
+ return;
294
+ this._drag = null;
295
+ this.removeAttribute('data-dragging');
296
+ const x = this._x.value;
297
+ if (Math.abs(x) >= this.num('threshold', 90))
298
+ this.swipe(x > 0 ? 'right' : 'left');
299
+ else
300
+ this._x.set(0);
301
+ };
302
+ this.listen(this, 'pointerup', up);
303
+ this.listen(this, 'pointercancel', up);
304
+ this.listen(this, 'keydown', (e) => {
305
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
306
+ e.preventDefault();
307
+ this.swipe(e.key === 'ArrowLeft' ? 'left' : 'right');
308
+ }
309
+ });
310
+ const mo = typeof MutationObserver !== 'undefined' ? new MutationObserver(() => this.layout(this._x.value)) : null;
311
+ mo?.observe(this, { childList: true });
312
+ this.onCleanup(() => mo?.disconnect());
313
+ }
314
+ unmount() {
315
+ this._x?.stop();
316
+ }
317
+ async swipe(direction) {
318
+ const card = this.top;
319
+ if (!card || this._busy || this.flag('disabled'))
320
+ return;
321
+ this._busy = true;
322
+ this._x.stop();
323
+ const from = this._x.value;
324
+ const to = (direction === 'left' ? -1 : 1) * Math.max(320, (this.getBoundingClientRect().width || 300) * 1.4);
325
+ card.setAttribute('data-gone', '');
326
+ this._x.jump(0);
327
+ this.layout(0);
328
+ const a = this.reduced
329
+ ? null
330
+ : this.motion(card, [{ transform: `translate3d(${from}px,0,0) rotate(${from / 18}deg)`, opacity: 1 }, { transform: `translate3d(${to}px,0,0) rotate(${to / 14}deg)`, opacity: 0 }], {
331
+ duration: 380,
332
+ easing: 'cubic-bezier(0.3, 0.7, 0.4, 1)',
333
+ fill: 'forwards',
334
+ });
335
+ await a?.finished.catch(() => undefined);
336
+ a?.cancel();
337
+ card.removeAttribute('data-gone');
338
+ if (this.flag('loop'))
339
+ this.append(card);
340
+ else
341
+ card.remove();
342
+ this.layout(0);
343
+ this._busy = false;
344
+ this.emit('swipe', { direction, card });
345
+ if (!this.top)
346
+ this.emit('empty');
347
+ }
348
+ }, { id: 'card-stack', text: css$2 });
349
+ }
350
+
351
+ var css$1 = "usa-sticky-stack{display:grid;gap:28vh;padding-bottom:10vh}usa-sticky-stack>*{position:sticky;transform-origin:50% 0;will-change:transform}";
352
+
353
+ function defineStickyStack(tag = 'usa-sticky-stack') {
354
+ return base.defineElement(tag, (Base) => class UsaStickyStack extends Base {
355
+ constructor() {
356
+ super(...arguments);
357
+ this._frame = 0;
358
+ }
359
+ static get observedAttributes() {
360
+ return ['top', 'gap', 'scale'];
361
+ }
362
+ mount() {
363
+ const top = this.num('top', 80);
364
+ const gap = this.num('gap', 16);
365
+ const cards = Array.from(this.children);
366
+ cards.forEach((c, i) => {
367
+ c.style.top = `${top + i * gap}px`;
368
+ c.style.zIndex = String(i + 1);
369
+ });
370
+ if (this.reduced)
371
+ return;
372
+ const schedule = () => {
373
+ if (!this._frame)
374
+ this._frame = base.raf(() => this.update());
375
+ };
376
+ let active = false;
377
+ this.inView((v) => {
378
+ if (v && !active) {
379
+ active = true;
380
+ window.addEventListener('scroll', schedule, { passive: true });
381
+ window.addEventListener('resize', schedule, { passive: true });
382
+ schedule();
383
+ }
384
+ else if (!v && active) {
385
+ active = false;
386
+ window.removeEventListener('scroll', schedule);
387
+ window.removeEventListener('resize', schedule);
388
+ }
389
+ });
390
+ this.onCleanup(() => {
391
+ window.removeEventListener('scroll', schedule);
392
+ window.removeEventListener('resize', schedule);
393
+ });
394
+ }
395
+ unmount() {
396
+ base.caf(this._frame);
397
+ this._frame = 0;
398
+ }
399
+ update() {
400
+ this._frame = 0;
401
+ const cards = Array.from(this.children);
402
+ const rects = cards.map((c) => c.getBoundingClientRect());
403
+ const shrink = this.num('scale', 0.06);
404
+ cards.forEach((c, i) => {
405
+ let covered = 0;
406
+ for (let j = i + 1; j < cards.length; j++) {
407
+ const h = rects[i].height || 1;
408
+ covered += base.clamp((rects[i].bottom - rects[j].top) / h, 0, 1);
409
+ }
410
+ const s = 1 - Math.min(3, covered) * shrink;
411
+ c.style.transform = covered > 0.001 ? `scale(${s.toFixed(4)})` : '';
412
+ c.style.filter = covered > 0.001 ? `brightness(${(1 - Math.min(0.35, covered * 0.12)).toFixed(3)})` : '';
413
+ });
414
+ }
415
+ }, { id: 'sticky-stack', text: css$1 });
416
+ }
417
+
418
+ var css = "usa-carousel-3d{position:relative;display:grid;place-items:center;perspective:var(--usa-c3d-perspective,1200px);transform-style:preserve-3d;touch-action:pan-y;user-select:none;-webkit-user-select:none;min-height:220px}usa-carousel-3d>*{grid-area:1 / 1;backface-visibility:hidden;transition:opacity 0.3s ease;cursor:pointer}usa-carousel-3d>[aria-current]{cursor:default}usa-carousel-3d:focus-visible{outline:2px solid var(--usa-accent,#7c5cff);outline-offset:4px;border-radius:12px}@media (prefers-reduced-motion:reduce){usa-carousel-3d{perspective:none}usa-carousel-3d>:not([aria-current]){visibility:hidden}}";
419
+
420
+ function defineCarousel3d(tag = 'usa-carousel-3d') {
421
+ return base.defineElement(tag, (Base) => class UsaCarousel3d extends Base {
422
+ constructor() {
423
+ super(...arguments);
424
+ this._i = 0;
425
+ }
426
+ static get observedAttributes() {
427
+ return ['radius', 'perspective', 'autoplay'];
428
+ }
429
+ get index() {
430
+ return this._i;
431
+ }
432
+ set index(v) {
433
+ this.goTo(v);
434
+ }
435
+ items() {
436
+ return Array.from(this.children);
437
+ }
438
+ render(angle) {
439
+ const items = this.items();
440
+ const n = items.length || 1;
441
+ const step = 360 / n;
442
+ const w = items[0]?.offsetWidth || 200;
443
+ const r = this.num('radius', Math.round(w / 2 / Math.tan(Math.PI / n)) + 24);
444
+ const reduced = this.reduced;
445
+ items.forEach((it, i) => {
446
+ const norm = ((((i * step - angle) % 360) + 540) % 360) - 180;
447
+ it.style.transform = reduced ? '' : `rotateY(${norm.toFixed(2)}deg) translateZ(${r}px)`;
448
+ it.style.opacity = reduced ? (i === this._i ? '1' : '0') : String(Math.max(0.25, 1 - Math.abs(norm) / 200));
449
+ });
450
+ }
451
+ mount() {
452
+ this.style.setProperty('--usa-c3d-perspective', `${this.num('perspective', 1200)}px`);
453
+ if (!this.hasAttribute('tabindex'))
454
+ this.tabIndex = 0;
455
+ this.setAttribute('role', 'region');
456
+ this.setAttribute('aria-roledescription', 'carousel');
457
+ this._i = Math.max(0, Math.min(this.items().length - 1, this.num('index', 0)));
458
+ const step = () => 360 / (this.items().length || 1);
459
+ this._angle = spring.createSpring({ value: this._i * step(), spring: 'gentle', onUpdate: (v) => this.render(v) });
460
+ this.render(this._angle.value);
461
+ this.mark();
462
+ this.listen(this, 'keydown', (e) => {
463
+ if (e.key === 'ArrowRight')
464
+ this.next();
465
+ else if (e.key === 'ArrowLeft')
466
+ this.prev();
467
+ else
468
+ return;
469
+ e.preventDefault();
470
+ });
471
+ let x0 = null;
472
+ this.listen(this, 'pointerdown', (e) => (x0 = e.clientX));
473
+ this.listen(this, 'pointerup', (e) => {
474
+ if (x0 === null)
475
+ return;
476
+ const dx = e.clientX - x0;
477
+ x0 = null;
478
+ if (Math.abs(dx) > 40)
479
+ dx < 0 ? this.next() : this.prev();
480
+ });
481
+ this.listen(this, 'click', (e) => {
482
+ const it = this.items().find((c) => c.contains(e.target));
483
+ if (it) {
484
+ const i = this.items().indexOf(it);
485
+ if (i !== this._i)
486
+ this.goTo(i);
487
+ }
488
+ });
489
+ const every = this.num('autoplay', 0);
490
+ if (every > 0 && !this.reduced) {
491
+ let paused = false;
492
+ const pause = () => (paused = true);
493
+ const resume = () => (paused = false);
494
+ this.listen(this, 'pointerenter', pause);
495
+ this.listen(this, 'pointerleave', resume);
496
+ this.listen(this, 'focusin', pause);
497
+ this.listen(this, 'focusout', resume);
498
+ const t = setInterval(() => !paused && !document.hidden && this.next(), every);
499
+ this.onCleanup(() => clearInterval(t));
500
+ }
501
+ }
502
+ unmount() {
503
+ this._angle?.stop();
504
+ }
505
+ mark() {
506
+ this.items().forEach((it, i) => {
507
+ if (i === this._i)
508
+ it.setAttribute('aria-current', 'true');
509
+ else
510
+ it.removeAttribute('aria-current');
511
+ });
512
+ }
513
+ goTo(i) {
514
+ const n = this.items().length;
515
+ if (!n || !this._angle)
516
+ return;
517
+ const step = 360 / n;
518
+ // shortest rotation from the current target
519
+ const cur = this._angle.target;
520
+ const curIdx = Math.round(cur / step);
521
+ let delta = (((i - curIdx) % n) + n) % n;
522
+ if (delta > n / 2)
523
+ delta -= n;
524
+ this._i = ((i % n) + n) % n;
525
+ this._angle.set((curIdx + delta) * step);
526
+ if (this.reduced)
527
+ this.render(this._angle.value);
528
+ this.mark();
529
+ this.emit('change', { index: this._i });
530
+ }
531
+ next() {
532
+ this.goTo(this._i + 1);
533
+ }
534
+ prev() {
535
+ this.goTo(this._i - 1);
536
+ }
537
+ }, { id: 'carousel-3d', text: css });
538
+ }
539
+
540
+ /**
541
+ * use-scroll-animate/components/cards — card effects (v2.4).
542
+ * `<usa-card effect="flip | holo | glass | border-glow | conic-border | lift |
543
+ * spotlight | sheen | parallax-layers | expand">` (combinable),
544
+ * `<usa-card-stack>` (swipeable deck), `<usa-sticky-stack>` (stacking on
545
+ * scroll) and `<usa-carousel-3d>`.
546
+ */
547
+ /** Register every component of this category under its default tag. */
548
+ function defineCardComponents() {
549
+ defineCard();
550
+ defineCardStack();
551
+ defineStickyStack();
552
+ defineCarousel3d();
553
+ }
554
+
555
+ exports.configureComponents = base.configureComponents;
556
+ exports.prefersReducedMotion = base.prefersReducedMotion;
557
+ exports.CARD_EFFECTS = CARD_EFFECTS;
558
+ exports.defineCard = defineCard;
559
+ exports.defineCardComponents = defineCardComponents;
560
+ exports.defineCardStack = defineCardStack;
561
+ exports.defineCarousel3d = defineCarousel3d;
562
+ exports.defineStickyStack = defineStickyStack;
563
+ //# sourceMappingURL=cards.cjs.map