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