use-scroll-animate 6.1.1 → 6.3.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/dist/chunks/{base-Yno7N2eC.js → base-DchG4q_S.js} +2 -2
- package/dist/chunks/{base-Yno7N2eC.js.map → base-DchG4q_S.js.map} +1 -1
- package/dist/chunks/{core-BIOaYdgN.js → core-D2vF8kZb.js} +2 -2
- package/dist/chunks/{core-BIOaYdgN.js.map → core-D2vF8kZb.js.map} +1 -1
- package/dist/chunks/{core-CUGCsMsJ.js → core-DVyTlo9Q.js} +2 -2
- package/dist/chunks/{core-CUGCsMsJ.js.map → core-DVyTlo9Q.js.map} +1 -1
- package/dist/chunks/{fx-BqDeFywO.js → fx-DUMVKSvg.js} +2 -2
- package/dist/chunks/{fx-BqDeFywO.js.map → fx-DUMVKSvg.js.map} +1 -1
- package/dist/chunks/generative-BHIj-NU0.cjs +295 -0
- package/dist/chunks/generative-BHIj-NU0.cjs.map +1 -0
- package/dist/chunks/generative-BRUZaIsX.js +290 -0
- package/dist/chunks/generative-BRUZaIsX.js.map +1 -0
- package/dist/chunks/gpu-BBRLgEzM.cjs +388 -0
- package/dist/chunks/gpu-BBRLgEzM.cjs.map +1 -0
- package/dist/chunks/gpu-XHWzeNb5.js +381 -0
- package/dist/chunks/gpu-XHWzeNb5.js.map +1 -0
- package/dist/chunks/registry-Bu5NrAyA.js +121 -0
- package/dist/chunks/registry-Bu5NrAyA.js.map +1 -0
- package/dist/chunks/registry-DehBVRDV.cjs +131 -0
- package/dist/chunks/registry-DehBVRDV.cjs.map +1 -0
- package/dist/chunks/shared-eweTlzxv.js +50 -0
- package/dist/chunks/shared-eweTlzxv.js.map +1 -0
- package/dist/chunks/shared-jkgRH-Hx.cjs +58 -0
- package/dist/chunks/shared-jkgRH-Hx.cjs.map +1 -0
- package/dist/chunks/{spring-DfQO5USi.js → spring-BhoT09Qb.js} +2 -2
- package/dist/chunks/{spring-DfQO5USi.js.map → spring-BhoT09Qb.js.map} +1 -1
- package/dist/chunks/{variants-VNscPeTD.js → variants-C_hv_s23.js} +2 -2
- package/dist/chunks/{variants-VNscPeTD.js.map → variants-C_hv_s23.js.map} +1 -1
- package/dist/components/a11y.js +2 -2
- package/dist/components/angular.cjs +1 -0
- package/dist/components/angular.cjs.map +1 -1
- package/dist/components/angular.js +7 -6
- package/dist/components/angular.js.map +1 -1
- package/dist/components/background.js +2 -2
- package/dist/components/bridge.js +1 -1
- package/dist/components/cards.js +2 -2
- package/dist/components/click.js +3 -3
- package/dist/components/depth.js +3 -3
- package/dist/components/effects.cjs +72 -403
- package/dist/components/effects.cjs.map +1 -1
- package/dist/components/effects.js +9 -339
- package/dist/components/effects.js.map +1 -1
- package/dist/components/feedback.js +1 -1
- package/dist/components/fx-gpu.cjs +13 -0
- package/dist/components/fx-gpu.cjs.map +1 -0
- package/dist/components/fx-gpu.d.cts +63 -0
- package/dist/components/fx-gpu.d.ts +63 -0
- package/dist/components/fx-gpu.js +6 -0
- package/dist/components/fx-gpu.js.map +1 -0
- package/dist/components/fx-text.cjs +267 -0
- package/dist/components/fx-text.cjs.map +1 -0
- package/dist/components/fx-text.d.cts +70 -0
- package/dist/components/fx-text.d.ts +70 -0
- package/dist/components/fx-text.js +263 -0
- package/dist/components/fx-text.js.map +1 -0
- package/dist/components/fx.cjs +13 -133
- package/dist/components/fx.cjs.map +1 -1
- package/dist/components/fx.js +6 -125
- package/dist/components/fx.js.map +1 -1
- package/dist/components/fx2.cjs +32 -0
- package/dist/components/fx2.cjs.map +1 -0
- package/dist/components/fx2.d.cts +162 -0
- package/dist/components/fx2.d.ts +162 -0
- package/dist/components/fx2.js +22 -0
- package/dist/components/fx2.js.map +1 -0
- package/dist/components/gesture.js +4 -4
- package/dist/components/interaction.js +1 -1
- package/dist/components/layout.js +1 -1
- package/dist/components/lite.cjs +5 -9
- package/dist/components/lite.cjs.map +1 -1
- package/dist/components/lite.js +5 -9
- package/dist/components/lite.js.map +1 -1
- package/dist/components/packs.js +1 -1
- package/dist/components/page.js +3 -3
- package/dist/components/perf.js +2 -2
- package/dist/components/physics.js +3 -3
- package/dist/components/reveal.js +1 -1
- package/dist/components/solid.cjs +1 -0
- package/dist/components/solid.cjs.map +1 -1
- package/dist/components/solid.js +7 -6
- package/dist/components/solid.js.map +1 -1
- package/dist/components/svelte.cjs +1 -0
- package/dist/components/svelte.cjs.map +1 -1
- package/dist/components/svelte.js +7 -6
- package/dist/components/svelte.js.map +1 -1
- package/dist/components/svg.js +1 -1
- package/dist/components/text.js +2 -2
- package/dist/components/timeline.js +3 -3
- package/dist/components/transitions.js +1 -1
- package/dist/components/ui.js +4 -4
- package/dist/components/vue.cjs +1 -0
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.js +7 -6
- package/dist/components/vue.js.map +1 -1
- package/dist/components/webgl.js +1 -1
- package/dist/components/widgets.cjs +1174 -0
- package/dist/components/widgets.cjs.map +1 -0
- package/dist/components/widgets.d.cts +206 -0
- package/dist/components/widgets.d.ts +206 -0
- package/dist/components/widgets.js +1155 -0
- package/dist/components/widgets.js.map +1 -0
- package/dist/components.cjs +10 -9
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +10 -9
- 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.js +2 -2
- package/dist/widgets.umd.js +2 -0
- package/dist/widgets.umd.js.map +1 -0
- package/docs/ROADMAP.md +10 -11
- package/docs/components.md +61 -0
- package/package.json +41 -1
|
@@ -0,0 +1,1155 @@
|
|
|
1
|
+
import { y as defineElement } from '../chunks/base-DchG4q_S.js';
|
|
2
|
+
import { d as springEasing } from '../chunks/spring-BhoT09Qb.js';
|
|
3
|
+
|
|
4
|
+
/** Helpers shared by the 6.x widgets (`motionary/components/widgets`). */
|
|
5
|
+
const clampN = (v, a, b) => Math.min(b, Math.max(a, v));
|
|
6
|
+
/** Children of `el` that are elements and not created by the widget itself. */
|
|
7
|
+
const ownChildren = (el, skip = '[data-usa-part]') => Array.from(el.children).filter((c) => c instanceof HTMLElement && !c.matches(skip));
|
|
8
|
+
/** Create a part element (marked so re-mounts can find / skip it). */
|
|
9
|
+
function part(tag, cls, attrs = {}, html = '') {
|
|
10
|
+
const n = document.createElement(tag);
|
|
11
|
+
n.className = cls;
|
|
12
|
+
n.setAttribute('data-usa-part', '');
|
|
13
|
+
for (const [k, v] of Object.entries(attrs))
|
|
14
|
+
n.setAttribute(k, v);
|
|
15
|
+
if (html)
|
|
16
|
+
n.innerHTML = html;
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
/** Remove the parts a previous mount created. */
|
|
20
|
+
const dropParts = (el) => el.querySelectorAll(':scope > [data-usa-part]').forEach((n) => n.remove());
|
|
21
|
+
let uid = 0;
|
|
22
|
+
/** A document-unique id with a prefix. */
|
|
23
|
+
const nextId = (p) => `${p}-${++uid}`;
|
|
24
|
+
/** Roving arrow-key focus over `items` (horizontal or vertical); returns the new index or -1. */
|
|
25
|
+
function arrowIndex(e, i, n, vertical = false) {
|
|
26
|
+
const prev = vertical ? 'ArrowUp' : 'ArrowLeft';
|
|
27
|
+
const next = vertical ? 'ArrowDown' : 'ArrowRight';
|
|
28
|
+
if (e.key === prev)
|
|
29
|
+
return (i - 1 + n) % n;
|
|
30
|
+
if (e.key === next)
|
|
31
|
+
return (i + 1) % n;
|
|
32
|
+
if (e.key === 'Home')
|
|
33
|
+
return 0;
|
|
34
|
+
if (e.key === 'End')
|
|
35
|
+
return n - 1;
|
|
36
|
+
return -1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var css$6 = "usa-carousel{display:block;position:relative;--usa-carousel-dur:520ms;--usa-carousel-ease:cubic-bezier(.22,1,.36,1);overflow:hidden;border-radius:var(--usa-radius,14px);touch-action:pan-y}.usa-carousel-viewport{position:relative;overflow:hidden;height:100%;min-height:inherit}.usa-carousel-track{display:flex;height:100%;transition:transform var(--usa-carousel-dur) var(--usa-carousel-ease);will-change:transform}.usa-carousel-track>*{flex:0 0 100%;min-width:0;box-sizing:border-box}usa-carousel:not([data-effect=\"slide\"]) .usa-carousel-track{display:grid}usa-carousel:not([data-effect=\"slide\"]) .usa-carousel-track>*{grid-area:1/1;transition:opacity var(--usa-carousel-dur) ease,transform var(--usa-carousel-dur) var(--usa-carousel-ease),filter var(--usa-carousel-dur) ease}usa-carousel[data-effect=\"cards\"] .usa-carousel-viewport{perspective:900px}usa-carousel[data-dragging] .usa-carousel-track,usa-carousel[data-dragging] .usa-carousel-track>*{transition:none}.usa-carousel-nav{position:absolute;top:50%;translate:0 -50%;z-index:2;width:36px;height:36px;border-radius:50%;border:0;background:rgba(255,255,255,.85);color:#111;font:600 18px/1 system-ui;cursor:pointer;display:grid;place-items:center;box-shadow:0 4px 14px rgba(0,0,0,.18);transition:transform .2s}.usa-carousel-nav:hover{transform:scale(1.08)}.usa-carousel-nav:focus-visible{outline:2px solid #7c5cff;outline-offset:2px}.usa-carousel-prev{left:10px}.usa-carousel-next{right:10px}.usa-carousel-dots{position:absolute;left:0;right:0;bottom:10px;display:flex;justify-content:center;gap:6px;z-index:2}.usa-carousel-dot{width:8px;height:8px;padding:0;border:0;border-radius:99px;background:rgba(255,255,255,.55);cursor:pointer;transition:width .35s var(--usa-carousel-ease),background .35s}.usa-carousel-dot[aria-current=\"true\"]{width:22px;background:#fff}@media (prefers-reduced-motion:reduce){usa-carousel .usa-carousel-track,usa-carousel .usa-carousel-track>*,.usa-carousel-dot{transition:none!important}}usa-carousel[data-reduced] .usa-carousel-track,usa-carousel[data-reduced] .usa-carousel-track>*{transition:none!important}";
|
|
40
|
+
|
|
41
|
+
const CAROUSEL_EFFECTS = ['slide', 'fade', 'scale', 'cards'];
|
|
42
|
+
function defineCarousel(tag = 'usa-carousel') {
|
|
43
|
+
return defineElement(tag, (Base) => {
|
|
44
|
+
class UsaCarousel extends Base {
|
|
45
|
+
constructor() {
|
|
46
|
+
super(...arguments);
|
|
47
|
+
this._i = 0;
|
|
48
|
+
this._slides = [];
|
|
49
|
+
this._track = null;
|
|
50
|
+
this._timer = 0;
|
|
51
|
+
this._hold = false;
|
|
52
|
+
this._dots = [];
|
|
53
|
+
}
|
|
54
|
+
static get observedAttributes() {
|
|
55
|
+
return ['effect', 'autoplay', 'loop', 'no-controls', 'no-dots'];
|
|
56
|
+
}
|
|
57
|
+
get length() {
|
|
58
|
+
return this._slides.length;
|
|
59
|
+
}
|
|
60
|
+
get index() {
|
|
61
|
+
return this._i;
|
|
62
|
+
}
|
|
63
|
+
set index(v) {
|
|
64
|
+
this.goTo(v);
|
|
65
|
+
}
|
|
66
|
+
get effect() {
|
|
67
|
+
const e = this.str('effect', 'slide');
|
|
68
|
+
return CAROUSEL_EFFECTS.includes(e) ? e : 'slide';
|
|
69
|
+
}
|
|
70
|
+
mount() {
|
|
71
|
+
this.dataset.effect = this.effect; // (not the observed attribute: no re-mount loop)
|
|
72
|
+
this.toggleAttribute('data-reduced', this.reduced);
|
|
73
|
+
const old = this.querySelector(':scope > .usa-carousel-viewport');
|
|
74
|
+
this._slides = old ? ownChildren(old.firstElementChild) : ownChildren(this);
|
|
75
|
+
dropParts(this);
|
|
76
|
+
const vp = part('div', 'usa-carousel-viewport', { 'aria-live': this.num('autoplay', 0) ? 'off' : 'polite' });
|
|
77
|
+
const track = part('div', 'usa-carousel-track');
|
|
78
|
+
this._track = track;
|
|
79
|
+
vp.append(track);
|
|
80
|
+
const n = this._slides.length;
|
|
81
|
+
this._slides.forEach((s, i) => {
|
|
82
|
+
s.setAttribute('role', 'group');
|
|
83
|
+
s.setAttribute('aria-roledescription', 'slide');
|
|
84
|
+
s.setAttribute('aria-label', `${i + 1} of ${n}`);
|
|
85
|
+
track.append(s);
|
|
86
|
+
});
|
|
87
|
+
this.prepend(vp);
|
|
88
|
+
this.setAttribute('role', 'region');
|
|
89
|
+
this.setAttribute('aria-roledescription', 'carousel');
|
|
90
|
+
this.setAttribute('aria-label', this.str('label', 'Carousel'));
|
|
91
|
+
if (!this.hasAttribute('tabindex'))
|
|
92
|
+
this.tabIndex = 0;
|
|
93
|
+
if (n > 1 && !this.flag('no-controls')) {
|
|
94
|
+
const prev = part('button', 'usa-carousel-nav usa-carousel-prev', { type: 'button', 'aria-label': 'Previous slide' }, '‹');
|
|
95
|
+
const next = part('button', 'usa-carousel-nav usa-carousel-next', { type: 'button', 'aria-label': 'Next slide' }, '›');
|
|
96
|
+
this.listen(prev, 'click', () => this.prev());
|
|
97
|
+
this.listen(next, 'click', () => this.next());
|
|
98
|
+
this.append(prev, next);
|
|
99
|
+
}
|
|
100
|
+
this._dots = [];
|
|
101
|
+
if (n > 1 && !this.flag('no-dots')) {
|
|
102
|
+
const dots = part('div', 'usa-carousel-dots', { role: 'group', 'aria-label': 'Choose slide' });
|
|
103
|
+
for (let i = 0; i < n; i++) {
|
|
104
|
+
const d = part('button', 'usa-carousel-dot', { type: 'button', 'aria-label': `Slide ${i + 1}` });
|
|
105
|
+
this.listen(d, 'click', () => this.goTo(i));
|
|
106
|
+
this._dots.push(d);
|
|
107
|
+
dots.append(d);
|
|
108
|
+
}
|
|
109
|
+
this.append(dots);
|
|
110
|
+
}
|
|
111
|
+
this._i = clampN(Math.round(this.num('index', 0)), 0, Math.max(0, n - 1));
|
|
112
|
+
this.layout(0);
|
|
113
|
+
this.listen(this, 'keydown', (e) => {
|
|
114
|
+
if (e.key === 'ArrowRight')
|
|
115
|
+
(e.preventDefault(), this.next());
|
|
116
|
+
else if (e.key === 'ArrowLeft')
|
|
117
|
+
(e.preventDefault(), this.prev());
|
|
118
|
+
});
|
|
119
|
+
this.drag(vp);
|
|
120
|
+
const ms = this.num('autoplay', 0);
|
|
121
|
+
if (ms > 0 && n > 1 && !this.reduced) {
|
|
122
|
+
let visible = true;
|
|
123
|
+
this.inView((v) => (visible = v));
|
|
124
|
+
const pause = (on) => () => (this._hold = on);
|
|
125
|
+
this.listen(this, 'pointerenter', pause(true));
|
|
126
|
+
this.listen(this, 'pointerleave', pause(false));
|
|
127
|
+
this.listen(this, 'focusin', pause(true));
|
|
128
|
+
this.listen(this, 'focusout', pause(false));
|
|
129
|
+
this._timer = window.setInterval(() => {
|
|
130
|
+
if (visible && !this._hold && !document.hidden)
|
|
131
|
+
this.next();
|
|
132
|
+
}, Math.max(1200, ms));
|
|
133
|
+
this.onCleanup(() => clearInterval(this._timer));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
drag(vp) {
|
|
137
|
+
let x0 = 0;
|
|
138
|
+
let dx = 0;
|
|
139
|
+
let id = -1;
|
|
140
|
+
this.listen(vp, 'pointerdown', (e) => {
|
|
141
|
+
if (this.length < 2 || e.target.closest('button,a,input'))
|
|
142
|
+
return;
|
|
143
|
+
id = e.pointerId;
|
|
144
|
+
x0 = e.clientX;
|
|
145
|
+
dx = 0;
|
|
146
|
+
this.setAttribute('data-dragging', '');
|
|
147
|
+
});
|
|
148
|
+
this.listen(window, 'pointermove', (e) => {
|
|
149
|
+
if (e.pointerId !== id)
|
|
150
|
+
return;
|
|
151
|
+
dx = e.clientX - x0;
|
|
152
|
+
this.layout(dx / Math.max(1, vp.clientWidth));
|
|
153
|
+
});
|
|
154
|
+
const end = (e) => {
|
|
155
|
+
if (e.pointerId !== id)
|
|
156
|
+
return;
|
|
157
|
+
id = -1;
|
|
158
|
+
this.removeAttribute('data-dragging');
|
|
159
|
+
const w = Math.max(1, vp.clientWidth);
|
|
160
|
+
if (Math.abs(dx) > w * 0.18)
|
|
161
|
+
dx < 0 ? this.next() : this.prev();
|
|
162
|
+
else
|
|
163
|
+
this.layout(0);
|
|
164
|
+
};
|
|
165
|
+
this.listen(window, 'pointerup', end);
|
|
166
|
+
this.listen(window, 'pointercancel', end);
|
|
167
|
+
}
|
|
168
|
+
/** Position the slides (`drag` = fraction of a slide the pointer moved). */
|
|
169
|
+
layout(drag) {
|
|
170
|
+
const n = this.length;
|
|
171
|
+
const i = this._i;
|
|
172
|
+
const fx = this.effect;
|
|
173
|
+
if (this._track)
|
|
174
|
+
this._track.style.transform = fx === 'slide' ? `translateX(${(-i + drag) * 100}%)` : '';
|
|
175
|
+
this._slides.forEach((s, k) => {
|
|
176
|
+
let off = k - i + drag;
|
|
177
|
+
if (this.flag('loop') && n > 2) {
|
|
178
|
+
if (off > n / 2)
|
|
179
|
+
off -= n;
|
|
180
|
+
if (off < -n / 2)
|
|
181
|
+
off += n;
|
|
182
|
+
}
|
|
183
|
+
const active = k === i;
|
|
184
|
+
s.toggleAttribute('data-active', active);
|
|
185
|
+
s.setAttribute('aria-hidden', String(!active));
|
|
186
|
+
s.inert = !active;
|
|
187
|
+
if (fx === 'slide') {
|
|
188
|
+
s.style.transform = s.style.opacity = s.style.zIndex = s.style.filter = '';
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const a = Math.abs(off);
|
|
192
|
+
if (fx === 'fade') {
|
|
193
|
+
s.style.opacity = String(clampN(1 - a, 0, 1));
|
|
194
|
+
s.style.transform = '';
|
|
195
|
+
}
|
|
196
|
+
else if (fx === 'scale') {
|
|
197
|
+
s.style.opacity = String(clampN(1 - a, 0, 1));
|
|
198
|
+
s.style.transform = `scale(${1 + Math.min(1, a) * (off < 0 ? 0.12 : -0.12)})`;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
s.style.opacity = a > 2.2 ? '0' : String(1 - Math.min(a, 2) * 0.28);
|
|
202
|
+
s.style.transform = `translateX(${off * 58}%) translateZ(${-a * 140}px) rotateY(${clampN(-off * 38, -60, 60)}deg)`;
|
|
203
|
+
s.style.filter = a > 0.5 ? `brightness(${1 - Math.min(a, 2) * 0.18})` : '';
|
|
204
|
+
}
|
|
205
|
+
s.style.zIndex = String(100 - Math.round(a * 10));
|
|
206
|
+
});
|
|
207
|
+
this._dots.forEach((d, k) => d.setAttribute('aria-current', String(k === i)));
|
|
208
|
+
}
|
|
209
|
+
goTo(to) {
|
|
210
|
+
const n = this.length;
|
|
211
|
+
if (!n)
|
|
212
|
+
return;
|
|
213
|
+
const t = this.flag('loop') ? ((Math.round(to) % n) + n) % n : clampN(Math.round(to), 0, n - 1);
|
|
214
|
+
const from = this._i;
|
|
215
|
+
this._i = t;
|
|
216
|
+
this.layout(0);
|
|
217
|
+
if (t !== from)
|
|
218
|
+
this.emit('change', { index: t, from });
|
|
219
|
+
}
|
|
220
|
+
next() {
|
|
221
|
+
this.goTo(this._i + 1 >= this.length && !this.flag('loop') ? 0 : this._i + 1);
|
|
222
|
+
}
|
|
223
|
+
prev() {
|
|
224
|
+
this.goTo(this._i - 1 < 0 && !this.flag('loop') ? this.length - 1 : this._i - 1);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return UsaCarousel;
|
|
228
|
+
}, { id: 'carousel', text: css$6 });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
var css$5 = "usa-tab-bar{display:block;--usa-tab-accent:#7c5cff;--usa-tab-ease:cubic-bezier(.22,1,.36,1)}.usa-tab-bar-list{position:relative;display:flex;gap:4px;padding:4px;border-radius:12px;background:rgba(127,127,127,.12);isolation:isolate;overflow-x:auto;scrollbar-width:none}.usa-tab-bar-list::-webkit-scrollbar{display:none}.usa-tab-bar-list>[role=\"tab\"]{position:relative;z-index:1;flex:1 0 auto;border:0;background:none;color:inherit;font:inherit;font-weight:600;padding:8px 14px;border-radius:9px;cursor:pointer;opacity:.7;transition:opacity .25s,color .25s;white-space:nowrap}.usa-tab-bar-list>[role=\"tab\"][aria-selected=\"true\"]{opacity:1}.usa-tab-bar-list>[role=\"tab\"]:focus-visible{outline:2px solid var(--usa-tab-accent);outline-offset:1px}.usa-tab-bar-ink{position:absolute;z-index:0;left:0;top:4px;bottom:4px;width:0;border-radius:9px;background:var(--usa-tab-accent);pointer-events:none}usa-tab-bar[data-indicator=\"pill\"] [aria-selected=\"true\"]{color:#fff}usa-tab-bar[data-indicator=\"underline\"] .usa-tab-bar-list{background:none;border-bottom:1px solid rgba(127,127,127,.25);border-radius:0}usa-tab-bar[data-indicator=\"underline\"] .usa-tab-bar-ink{top:auto;bottom:0;height:3px;border-radius:3px}usa-tab-bar[data-indicator=\"glow\"] .usa-tab-bar-ink{background:transparent;box-shadow:0 0 0 2px var(--usa-tab-accent),0 0 18px var(--usa-tab-accent)}usa-tab-bar[data-indicator=\"gooey\"] .usa-tab-bar-ink{filter:blur(.5px);border-radius:999px}usa-tab-bar[data-indicator=\"gooey\"] [aria-selected=\"true\"]{color:#fff}.usa-tab-bar-panel{padding:14px 2px}.usa-tab-bar-panel[hidden]{display:none}";
|
|
232
|
+
|
|
233
|
+
const TAB_INDICATORS = ['pill', 'underline', 'glow', 'gooey'];
|
|
234
|
+
function defineTabBar(tag = 'usa-tab-bar') {
|
|
235
|
+
return defineElement(tag, (Base) => {
|
|
236
|
+
class UsaTabBar extends Base {
|
|
237
|
+
constructor() {
|
|
238
|
+
super(...arguments);
|
|
239
|
+
this._tabs = [];
|
|
240
|
+
this._panels = [];
|
|
241
|
+
this._ink = null;
|
|
242
|
+
this._i = 0;
|
|
243
|
+
}
|
|
244
|
+
static get observedAttributes() {
|
|
245
|
+
return ['indicator'];
|
|
246
|
+
}
|
|
247
|
+
get selected() {
|
|
248
|
+
return this._i;
|
|
249
|
+
}
|
|
250
|
+
set selected(v) {
|
|
251
|
+
this.select(v);
|
|
252
|
+
}
|
|
253
|
+
mount() {
|
|
254
|
+
const ind = this.str('indicator', 'pill');
|
|
255
|
+
this.dataset.indicator = TAB_INDICATORS.includes(ind) ? ind : 'pill';
|
|
256
|
+
let list = this.querySelector(':scope > .usa-tab-bar-list');
|
|
257
|
+
if (!list) {
|
|
258
|
+
list = part('div', 'usa-tab-bar-list');
|
|
259
|
+
this.prepend(list);
|
|
260
|
+
}
|
|
261
|
+
list.setAttribute('role', 'tablist');
|
|
262
|
+
list.setAttribute('aria-label', this.str('label', 'Tabs'));
|
|
263
|
+
const kids = ownChildren(this);
|
|
264
|
+
this._panels = kids.filter((k) => k.hasAttribute('data-panel'));
|
|
265
|
+
for (const k of kids)
|
|
266
|
+
if (!k.hasAttribute('data-panel') && k.matches('button,[data-tab]'))
|
|
267
|
+
list.append(k);
|
|
268
|
+
this._tabs = Array.from(list.children).filter((c) => c instanceof HTMLElement && !c.classList.contains('usa-tab-bar-ink'));
|
|
269
|
+
this._ink = list.querySelector('.usa-tab-bar-ink') || part('span', 'usa-tab-bar-ink', { 'aria-hidden': 'true' });
|
|
270
|
+
list.prepend(this._ink);
|
|
271
|
+
this._tabs.forEach((t, i) => {
|
|
272
|
+
t.setAttribute('role', 'tab');
|
|
273
|
+
if (t.localName === 'button' && !t.hasAttribute('type'))
|
|
274
|
+
t.setAttribute('type', 'button');
|
|
275
|
+
t.id || (t.id = nextId('usa-tab'));
|
|
276
|
+
const p = this._panels[i];
|
|
277
|
+
if (p) {
|
|
278
|
+
p.id || (p.id = nextId('usa-tabpanel'));
|
|
279
|
+
p.classList.add('usa-tab-bar-panel');
|
|
280
|
+
p.setAttribute('role', 'tabpanel');
|
|
281
|
+
p.setAttribute('aria-labelledby', t.id);
|
|
282
|
+
p.tabIndex = 0;
|
|
283
|
+
t.setAttribute('aria-controls', p.id);
|
|
284
|
+
}
|
|
285
|
+
this.listen(t, 'click', () => this.select(i));
|
|
286
|
+
});
|
|
287
|
+
this.listen(list, 'keydown', (e) => {
|
|
288
|
+
const n = arrowIndex(e, this._i, this._tabs.length);
|
|
289
|
+
if (n < 0)
|
|
290
|
+
return;
|
|
291
|
+
e.preventDefault();
|
|
292
|
+
this.select(n);
|
|
293
|
+
this._tabs[n].focus();
|
|
294
|
+
});
|
|
295
|
+
this._i = Math.min(Math.max(0, Math.round(this.num('selected', 0))), Math.max(0, this._tabs.length - 1));
|
|
296
|
+
this.sync(-1);
|
|
297
|
+
if (typeof ResizeObserver === 'function') {
|
|
298
|
+
const ro = new ResizeObserver(() => this.place());
|
|
299
|
+
ro.observe(list);
|
|
300
|
+
this.onCleanup(() => ro.disconnect());
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
rect(i) {
|
|
304
|
+
const t = this._tabs[i];
|
|
305
|
+
return t ? [t.offsetLeft, t.offsetWidth] : [0, 0];
|
|
306
|
+
}
|
|
307
|
+
place() {
|
|
308
|
+
if (!this._ink)
|
|
309
|
+
return;
|
|
310
|
+
const [x, w] = this.rect(this._i);
|
|
311
|
+
this._ink.style.transform = `translateX(${x}px)`;
|
|
312
|
+
this._ink.style.width = `${w}px`;
|
|
313
|
+
}
|
|
314
|
+
sync(from) {
|
|
315
|
+
this._tabs.forEach((t, k) => {
|
|
316
|
+
t.setAttribute('aria-selected', String(k === this._i));
|
|
317
|
+
t.tabIndex = k === this._i ? 0 : -1;
|
|
318
|
+
});
|
|
319
|
+
this._panels.forEach((p, k) => (p.hidden = k !== this._i));
|
|
320
|
+
this.place();
|
|
321
|
+
if (from < 0 || from === this._i || !this._ink || this.reduced)
|
|
322
|
+
return;
|
|
323
|
+
// stretchy travel: the leading edge arrives first, the trailing edge follows
|
|
324
|
+
const [x0, w0] = this.rect(from);
|
|
325
|
+
const [x1, w1] = this.rect(this._i);
|
|
326
|
+
const right = x1 > x0;
|
|
327
|
+
const mid = right ? { transform: `translateX(${x0}px)`, width: `${x1 + w1 - x0}px` } : { transform: `translateX(${x1}px)`, width: `${x0 + w0 - x1}px` };
|
|
328
|
+
this.motion(this._ink, [{ transform: `translateX(${x0}px)`, width: `${w0}px` }, { ...mid, offset: 0.45 }, { transform: `translateX(${x1}px)`, width: `${w1}px` }], { duration: 480, easing: 'cubic-bezier(.22,1,.36,1)' });
|
|
329
|
+
const p = this._panels[this._i];
|
|
330
|
+
if (p)
|
|
331
|
+
this.motion(p, [{ opacity: 0, transform: `translateX(${right ? 24 : -24}px)` }, { opacity: 1, transform: 'none' }], { duration: 320, easing: 'cubic-bezier(.22,1,.36,1)' });
|
|
332
|
+
}
|
|
333
|
+
select(i) {
|
|
334
|
+
const n = Math.min(Math.max(0, Math.round(i)), this._tabs.length - 1);
|
|
335
|
+
if (n === this._i || n < 0)
|
|
336
|
+
return;
|
|
337
|
+
const from = this._i;
|
|
338
|
+
this._i = n;
|
|
339
|
+
this.sync(from);
|
|
340
|
+
this.emit('change', { index: n, from });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return UsaTabBar;
|
|
344
|
+
}, { id: 'tab-bar', text: css$5 });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
var css$4 = "usa-disclosure{display:block;--usa-disclosure-accent:#7c5cff}usa-disclosure>details{border-bottom:1px solid rgba(127,127,127,.25);overflow:hidden}usa-disclosure>details>summary{list-style:none;cursor:pointer;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 4px;font-weight:600}usa-disclosure>details>summary::-webkit-details-marker{display:none}usa-disclosure>details>summary::after{content:\"\";flex:none;width:9px;height:9px;border-right:2px solid currentColor;border-bottom:2px solid currentColor;rotate:45deg;translate:0 -3px;transition:rotate .35s cubic-bezier(.34,1.56,.64,1),translate .35s}usa-disclosure>details[open]>summary::after{rotate:225deg;translate:0 2px}usa-disclosure>details>summary:focus-visible{outline:2px solid var(--usa-disclosure-accent);outline-offset:2px;border-radius:6px}usa-disclosure>details>:not(summary){padding:0 4px 12px}usa-disclosure[variant=\"cards\"]>details{border:1px solid rgba(127,127,127,.25);border-radius:12px;margin-bottom:8px;padding:0 10px;transition:box-shadow .3s,border-color .3s}usa-disclosure[variant=\"cards\"]>details[open]{border-color:var(--usa-disclosure-accent);box-shadow:0 8px 24px rgba(124,92,255,.16)}@media (prefers-reduced-motion:reduce){usa-disclosure>details>summary::after{transition:none}}";
|
|
348
|
+
|
|
349
|
+
function defineDisclosure(tag = 'usa-disclosure') {
|
|
350
|
+
return defineElement(tag, (Base) => {
|
|
351
|
+
class UsaDisclosure extends Base {
|
|
352
|
+
constructor() {
|
|
353
|
+
super(...arguments);
|
|
354
|
+
this._anims = new WeakMap();
|
|
355
|
+
}
|
|
356
|
+
get items() {
|
|
357
|
+
return Array.from(this.children).filter((c) => c.localName === 'details');
|
|
358
|
+
}
|
|
359
|
+
mount() {
|
|
360
|
+
this.listen(this, 'click', (e) => {
|
|
361
|
+
const s = e.target.closest('summary');
|
|
362
|
+
const d = s?.parentElement;
|
|
363
|
+
if (!s || !d || d.parentElement !== this)
|
|
364
|
+
return;
|
|
365
|
+
e.preventDefault();
|
|
366
|
+
this.set(d, !d.open);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
set(d, open) {
|
|
370
|
+
if (open && !this.flag('multiple'))
|
|
371
|
+
for (const o of this.items)
|
|
372
|
+
if (o !== d && o.open)
|
|
373
|
+
this.set(o, false);
|
|
374
|
+
if (d.open === open && !this._anims.get(d))
|
|
375
|
+
return;
|
|
376
|
+
const summary = d.querySelector('summary');
|
|
377
|
+
const closedH = summary ? summary.offsetHeight : 0;
|
|
378
|
+
const startH = d.offsetHeight;
|
|
379
|
+
this._anims.get(d)?.cancel();
|
|
380
|
+
if (open)
|
|
381
|
+
d.open = true;
|
|
382
|
+
const endH = open ? d.scrollHeight : closedH;
|
|
383
|
+
const sp = springEasing(this.str('spring', 'gentle'));
|
|
384
|
+
const a = this.reduced ? null : this.motion(d, [{ height: `${startH}px` }, { height: `${endH}px` }], { duration: Math.min(sp.duration, 700), easing: sp.easing, fill: 'forwards' });
|
|
385
|
+
const body = Array.from(d.children).filter((c) => c.localName !== 'summary');
|
|
386
|
+
if (open && !this.reduced)
|
|
387
|
+
body.forEach((b) => this.motion(b, [{ opacity: 0, transform: 'translateY(-6px)' }, { opacity: 1, transform: 'none' }], { duration: 300, delay: 60, easing: 'ease-out' }));
|
|
388
|
+
const done = () => {
|
|
389
|
+
this._anims.delete(d);
|
|
390
|
+
if (!open)
|
|
391
|
+
d.open = false;
|
|
392
|
+
a?.cancel();
|
|
393
|
+
};
|
|
394
|
+
if (a) {
|
|
395
|
+
this._anims.set(d, a);
|
|
396
|
+
a.finished.then(() => this._anims.get(d) === a && done(), () => undefined);
|
|
397
|
+
}
|
|
398
|
+
else
|
|
399
|
+
done();
|
|
400
|
+
this.emit('toggle', { index: this.items.indexOf(d), open });
|
|
401
|
+
}
|
|
402
|
+
toggle(i, force) {
|
|
403
|
+
const d = this.items[i];
|
|
404
|
+
if (d)
|
|
405
|
+
this.set(d, force ?? !d.open);
|
|
406
|
+
}
|
|
407
|
+
openAll() {
|
|
408
|
+
this.items.forEach((d) => (d.open = true));
|
|
409
|
+
}
|
|
410
|
+
closeAll() {
|
|
411
|
+
this.items.forEach((d) => this.set(d, false));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return UsaDisclosure;
|
|
415
|
+
}, { id: 'disclosure', text: css$4 });
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
var css$3 = "usa-stories{display:block;position:relative;overflow:hidden;border-radius:var(--usa-radius,16px);background:#111;color:#fff;aspect-ratio:9/14;max-height:520px;user-select:none;-webkit-user-select:none;touch-action:manipulation}usa-stories>:not([data-usa-part]){position:absolute;inset:0;opacity:0;transition:opacity .35s ease,transform .5s cubic-bezier(.22,1,.36,1);transform:scale(1.04);pointer-events:none;box-sizing:border-box}usa-stories>[data-active]:not([data-usa-part]){opacity:1;transform:none;pointer-events:auto}usa-stories>img:not([data-usa-part]){width:100%;height:100%;object-fit:cover}.usa-stories-bars{position:absolute;z-index:3;top:8px;left:8px;right:48px;display:flex;gap:4px}.usa-stories-bar{flex:1;height:3px;border-radius:3px;background:rgba(255,255,255,.35);overflow:hidden}.usa-stories-bar>i{display:block;height:100%;width:100%;background:#fff;transform-origin:left;transform:scaleX(0)}.usa-stories-bar[data-done]>i{transform:scaleX(1)}.usa-stories-toggle{position:absolute;z-index:3;top:2px;right:6px;width:36px;height:30px;border:0;background:none;color:#fff;font:700 14px/1 system-ui;cursor:pointer;border-radius:8px}.usa-stories-toggle:focus-visible{outline:2px solid #fff}@media (prefers-reduced-motion:reduce){usa-stories>*{transition:none!important;transform:none!important}}";
|
|
419
|
+
|
|
420
|
+
function defineStories(tag = 'usa-stories') {
|
|
421
|
+
return defineElement(tag, (Base) => {
|
|
422
|
+
class UsaStories extends Base {
|
|
423
|
+
constructor() {
|
|
424
|
+
super(...arguments);
|
|
425
|
+
this._i = 0;
|
|
426
|
+
this._items = [];
|
|
427
|
+
this._bars = [];
|
|
428
|
+
this._fill = null;
|
|
429
|
+
this._btn = null;
|
|
430
|
+
}
|
|
431
|
+
static get observedAttributes() {
|
|
432
|
+
return ['duration', 'loop'];
|
|
433
|
+
}
|
|
434
|
+
get index() {
|
|
435
|
+
return this._i;
|
|
436
|
+
}
|
|
437
|
+
mount() {
|
|
438
|
+
dropParts(this);
|
|
439
|
+
this._items = ownChildren(this);
|
|
440
|
+
const bars = part('div', 'usa-stories-bars', { 'aria-hidden': 'true' });
|
|
441
|
+
this._bars = this._items.map(() => {
|
|
442
|
+
const b = part('div', 'usa-stories-bar', {}, '<i></i>');
|
|
443
|
+
bars.append(b);
|
|
444
|
+
return b;
|
|
445
|
+
});
|
|
446
|
+
this._btn = part('button', 'usa-stories-toggle', { type: 'button' });
|
|
447
|
+
this.listen(this._btn, 'click', (e) => {
|
|
448
|
+
e.stopPropagation();
|
|
449
|
+
this.hasAttribute('paused') ? this.play() : this.pause();
|
|
450
|
+
});
|
|
451
|
+
this.append(bars, this._btn);
|
|
452
|
+
this.setAttribute('role', 'region');
|
|
453
|
+
this.setAttribute('aria-roledescription', 'stories');
|
|
454
|
+
if (!this.hasAttribute('aria-label'))
|
|
455
|
+
this.setAttribute('aria-label', 'Stories');
|
|
456
|
+
if (!this.hasAttribute('tabindex'))
|
|
457
|
+
this.tabIndex = 0;
|
|
458
|
+
if (this.reduced)
|
|
459
|
+
this.setAttribute('paused', '');
|
|
460
|
+
let held = false;
|
|
461
|
+
let downAt = 0;
|
|
462
|
+
this.listen(this, 'pointerdown', (e) => {
|
|
463
|
+
if (e.target.closest('button,a'))
|
|
464
|
+
return;
|
|
465
|
+
downAt = performance.now();
|
|
466
|
+
held = !this.hasAttribute('paused');
|
|
467
|
+
if (held)
|
|
468
|
+
this._fill?.pause();
|
|
469
|
+
});
|
|
470
|
+
this.listen(this, 'pointerup', (e) => {
|
|
471
|
+
if (e.target.closest('button,a') || !downAt)
|
|
472
|
+
return;
|
|
473
|
+
const long = performance.now() - downAt > 350;
|
|
474
|
+
downAt = 0;
|
|
475
|
+
if (held && !this.hasAttribute('paused'))
|
|
476
|
+
this._fill?.play();
|
|
477
|
+
if (long)
|
|
478
|
+
return;
|
|
479
|
+
const r = this.getBoundingClientRect();
|
|
480
|
+
e.clientX - r.left < r.width / 3 ? this.prev() : this.next();
|
|
481
|
+
});
|
|
482
|
+
this.listen(this, 'keydown', (e) => {
|
|
483
|
+
if (e.key === 'ArrowRight')
|
|
484
|
+
this.next();
|
|
485
|
+
else if (e.key === 'ArrowLeft')
|
|
486
|
+
this.prev();
|
|
487
|
+
else if (e.key === ' ')
|
|
488
|
+
(e.preventDefault(), this.hasAttribute('paused') ? this.play() : this.pause());
|
|
489
|
+
});
|
|
490
|
+
this.onCleanup(() => this._fill?.cancel());
|
|
491
|
+
this.goTo(Math.min(this._i, Math.max(0, this._items.length - 1)), true);
|
|
492
|
+
}
|
|
493
|
+
label() {
|
|
494
|
+
if (this._btn) {
|
|
495
|
+
const p = this.hasAttribute('paused');
|
|
496
|
+
this._btn.textContent = p ? '▶' : '❚❚';
|
|
497
|
+
this._btn.setAttribute('aria-label', p ? 'Play stories' : 'Pause stories');
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
goTo(i, initial = false) {
|
|
501
|
+
const n = this._items.length;
|
|
502
|
+
if (!n)
|
|
503
|
+
return;
|
|
504
|
+
if (i >= n && !this.flag('loop')) {
|
|
505
|
+
this.emit('end');
|
|
506
|
+
this.pause();
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const t = ((i % n) + n) % n;
|
|
510
|
+
const changed = t !== this._i || initial;
|
|
511
|
+
this._i = t;
|
|
512
|
+
this._items.forEach((s, k) => {
|
|
513
|
+
s.toggleAttribute('data-active', k === t);
|
|
514
|
+
s.setAttribute('aria-hidden', String(k !== t));
|
|
515
|
+
});
|
|
516
|
+
this._bars.forEach((b, k) => b.toggleAttribute('data-done', k < t));
|
|
517
|
+
this._fill?.cancel();
|
|
518
|
+
const fillEl = this._bars[t]?.firstElementChild;
|
|
519
|
+
this._fill = fillEl ? fillEl.animate?.([{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], { duration: Math.max(800, this.num('duration', 5000)), fill: 'forwards' }) ?? null : null;
|
|
520
|
+
if (this._fill) {
|
|
521
|
+
const a = this._fill;
|
|
522
|
+
a.onfinish = () => this._fill === a && this.goTo(this._i + 1);
|
|
523
|
+
if (this.hasAttribute('paused'))
|
|
524
|
+
a.pause();
|
|
525
|
+
}
|
|
526
|
+
this.label();
|
|
527
|
+
if (changed && !initial)
|
|
528
|
+
this.emit('change', { index: t });
|
|
529
|
+
}
|
|
530
|
+
next() {
|
|
531
|
+
this.goTo(this._i + 1);
|
|
532
|
+
}
|
|
533
|
+
prev() {
|
|
534
|
+
this.goTo(Math.max(0, this._i - 1));
|
|
535
|
+
}
|
|
536
|
+
pause() {
|
|
537
|
+
this.setAttribute('paused', '');
|
|
538
|
+
this._fill?.pause();
|
|
539
|
+
this.label();
|
|
540
|
+
}
|
|
541
|
+
play() {
|
|
542
|
+
this.removeAttribute('paused');
|
|
543
|
+
if (this._fill?.playState === 'finished')
|
|
544
|
+
this.goTo(this._i + 1 >= this._items.length ? 0 : this._i + 1);
|
|
545
|
+
else
|
|
546
|
+
this._fill?.play();
|
|
547
|
+
this.label();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return UsaStories;
|
|
551
|
+
}, { id: 'stories', text: css$3 });
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
var css$2 = "usa-modal,usa-sheet{display:contents}.usa-ov{border:0;padding:0;margin:auto;color:inherit;background:transparent;max-width:min(92vw,520px);max-height:88vh;overflow:visible}.usa-ov::backdrop{background:rgba(10,12,20,.45);-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px)}.usa-ov-body{box-sizing:border-box;background:var(--usa-ov-bg,#fff);color:var(--usa-ov-fg,#111827);border-radius:var(--usa-ov-radius,18px);padding:var(--usa-ov-pad,22px);box-shadow:0 30px 80px -20px rgba(0,0,0,.45);max-height:88vh;overflow:auto}.usa-sheet-panel{margin:0;max-width:none;max-height:none}usa-sheet[data-side=\"right\"] .usa-sheet-panel{inset:0 0 0 auto;height:100%;width:min(88vw,var(--usa-sheet-size,380px))}usa-sheet[data-side=\"left\"] .usa-sheet-panel{inset:0 auto 0 0;height:100%;width:min(88vw,var(--usa-sheet-size,380px))}usa-sheet[data-side=\"bottom\"] .usa-sheet-panel{inset:auto 0 0 0;width:100%;max-height:85vh}usa-sheet[data-side=\"top\"] .usa-sheet-panel{inset:0 0 auto 0;width:100%;max-height:85vh}usa-sheet .usa-ov-body{height:100%;max-height:inherit;border-radius:0}usa-sheet[data-side=\"bottom\"] .usa-ov-body{border-radius:var(--usa-ov-radius,18px) var(--usa-ov-radius,18px) 0 0;height:auto;max-height:85vh;touch-action:none}usa-sheet[data-side=\"top\"] .usa-ov-body{border-radius:0 0 var(--usa-ov-radius,18px) var(--usa-ov-radius,18px);height:auto}.usa-ov-grab{width:44px;height:5px;border-radius:3px;background:rgba(127,127,127,.45);margin:-8px auto 14px;cursor:grab}@media (prefers-color-scheme:dark){.usa-ov-body{background:var(--usa-ov-bg,#171a23);color:var(--usa-ov-fg,#e5e7eb)}}";
|
|
555
|
+
|
|
556
|
+
const MODAL_EFFECTS = ['scale', 'slide-up', 'flip', 'origin'];
|
|
557
|
+
const SHEET_SIDES = ['right', 'left', 'bottom', 'top'];
|
|
558
|
+
const EASE_OUT = 'cubic-bezier(.22,1,.36,1)';
|
|
559
|
+
// one delegated listener for [data-usa-open] / [data-usa-toast] triggers anywhere on the page
|
|
560
|
+
let delegated = false;
|
|
561
|
+
function delegateTriggers() {
|
|
562
|
+
if (delegated || typeof document === 'undefined')
|
|
563
|
+
return;
|
|
564
|
+
delegated = true;
|
|
565
|
+
document.addEventListener('click', (e) => {
|
|
566
|
+
const t = e.target?.closest?.('[data-usa-open]');
|
|
567
|
+
if (!t)
|
|
568
|
+
return;
|
|
569
|
+
const target = document.getElementById(t.getAttribute('data-usa-open') || '');
|
|
570
|
+
if (target && typeof target.show === 'function') {
|
|
571
|
+
e.preventDefault();
|
|
572
|
+
if (target.opened)
|
|
573
|
+
void target.close?.();
|
|
574
|
+
else
|
|
575
|
+
target.show(t);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
function defineOverlay(tag, kind) {
|
|
580
|
+
delegateTriggers();
|
|
581
|
+
return defineElement(tag, (Base) => {
|
|
582
|
+
class UsaOverlay extends Base {
|
|
583
|
+
constructor() {
|
|
584
|
+
super(...arguments);
|
|
585
|
+
this._dlg = null;
|
|
586
|
+
this._panel = null;
|
|
587
|
+
this._open = false;
|
|
588
|
+
this._ret = null;
|
|
589
|
+
this._origin = null;
|
|
590
|
+
this._value = '';
|
|
591
|
+
this._closing = null;
|
|
592
|
+
}
|
|
593
|
+
static get observedAttributes() {
|
|
594
|
+
return kind === 'modal' ? ['effect'] : ['side'];
|
|
595
|
+
}
|
|
596
|
+
get opened() {
|
|
597
|
+
return this._open;
|
|
598
|
+
}
|
|
599
|
+
get returnValue() {
|
|
600
|
+
return this._value;
|
|
601
|
+
}
|
|
602
|
+
mount() {
|
|
603
|
+
let d = this.querySelector(':scope > dialog.usa-ov');
|
|
604
|
+
if (!d) {
|
|
605
|
+
d = part('dialog', `usa-ov usa-${kind}-panel`);
|
|
606
|
+
const body = part('div', 'usa-ov-body');
|
|
607
|
+
body.append(...ownChildren(this));
|
|
608
|
+
d.append(body);
|
|
609
|
+
this.append(d);
|
|
610
|
+
}
|
|
611
|
+
this._dlg = d;
|
|
612
|
+
this._panel = d.querySelector('.usa-ov-body');
|
|
613
|
+
if (kind === 'modal') {
|
|
614
|
+
const ef = this.str('effect', 'scale');
|
|
615
|
+
this.dataset.effect = MODAL_EFFECTS.includes(ef) ? ef : 'scale';
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
const side = this.str('side', 'right');
|
|
619
|
+
this.dataset.side = SHEET_SIDES.includes(side) ? side : 'right';
|
|
620
|
+
if (this.dataset.side === 'bottom' && this._panel && !this._panel.querySelector('[data-handle]'))
|
|
621
|
+
this._panel.prepend(part('div', 'usa-ov-grab', { 'data-handle': '', 'aria-hidden': 'true' }));
|
|
622
|
+
this.drag();
|
|
623
|
+
}
|
|
624
|
+
if (!d.hasAttribute('aria-labelledby'))
|
|
625
|
+
d.setAttribute('aria-label', this.str('label', kind === 'modal' ? 'Dialog' : 'Panel'));
|
|
626
|
+
this.listen(d, 'cancel', (e) => {
|
|
627
|
+
e.preventDefault();
|
|
628
|
+
if (!this.flag('persistent'))
|
|
629
|
+
void this.close();
|
|
630
|
+
});
|
|
631
|
+
this.listen(d, 'click', (e) => {
|
|
632
|
+
const t = e.target;
|
|
633
|
+
const c = t.closest?.('[data-usa-close]');
|
|
634
|
+
if (c)
|
|
635
|
+
return void this.close(c.getAttribute('data-usa-close') || '');
|
|
636
|
+
if (t === d && !this.flag('persistent'))
|
|
637
|
+
void this.close(); // the ::backdrop
|
|
638
|
+
});
|
|
639
|
+
if (this.flag('open') && !this._open)
|
|
640
|
+
this.show();
|
|
641
|
+
}
|
|
642
|
+
unmount() {
|
|
643
|
+
if (this._open && this._dlg?.open)
|
|
644
|
+
this._dlg.close?.();
|
|
645
|
+
this._open = false;
|
|
646
|
+
}
|
|
647
|
+
frames(opening) {
|
|
648
|
+
const fade = [{ opacity: 0 }, { opacity: 1 }];
|
|
649
|
+
if (this.reduced)
|
|
650
|
+
return opening ? fade : [...fade].reverse();
|
|
651
|
+
let f;
|
|
652
|
+
if (kind === 'sheet') {
|
|
653
|
+
const s = this.dataset.side;
|
|
654
|
+
const off = s === 'left' ? 'translateX(-100%)' : s === 'bottom' ? 'translateY(100%)' : s === 'top' ? 'translateY(-100%)' : 'translateX(100%)';
|
|
655
|
+
f = [{ transform: off }, { transform: 'none' }];
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
const e = this.dataset.effect;
|
|
659
|
+
const o = this._origin;
|
|
660
|
+
const r = this._dlg?.getBoundingClientRect();
|
|
661
|
+
if (e === 'origin' && o && r && r.width) {
|
|
662
|
+
const dx = o.left + o.width / 2 - (r.left + r.width / 2);
|
|
663
|
+
const dy = o.top + o.height / 2 - (r.top + r.height / 2);
|
|
664
|
+
f = [{ transform: `translate(${dx}px,${dy}px) scale(${Math.max(0.05, o.width / r.width).toFixed(3)},${Math.max(0.05, o.height / r.height).toFixed(3)})`, opacity: 0, borderRadius: '40px' }, { transform: 'none', opacity: 1 }];
|
|
665
|
+
}
|
|
666
|
+
else if (e === 'slide-up')
|
|
667
|
+
f = [{ transform: 'translateY(48px)', opacity: 0 }, { transform: 'none', opacity: 1 }];
|
|
668
|
+
else if (e === 'flip')
|
|
669
|
+
f = [{ transform: 'perspective(900px) rotateX(-28deg) translateY(30px)', opacity: 0 }, { transform: 'none', opacity: 1 }];
|
|
670
|
+
else
|
|
671
|
+
f = [{ transform: 'scale(.88)', opacity: 0 }, { transform: 'scale(1.015)', opacity: 1, offset: 0.7 }, { transform: 'none', opacity: 1 }];
|
|
672
|
+
}
|
|
673
|
+
return opening ? f : [f[0], f[f.length - 1]].reverse();
|
|
674
|
+
}
|
|
675
|
+
backdrop(opening) {
|
|
676
|
+
if (!this._dlg)
|
|
677
|
+
return;
|
|
678
|
+
const k = [{ opacity: 0 }, { opacity: 1 }];
|
|
679
|
+
try {
|
|
680
|
+
this._dlg.animate?.(opening ? k : k.reverse(), { duration: opening ? 280 : 200, pseudoElement: '::backdrop', fill: 'forwards' });
|
|
681
|
+
}
|
|
682
|
+
catch {
|
|
683
|
+
/* no ::backdrop animation support */
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
show(trigger) {
|
|
687
|
+
const d = this._dlg;
|
|
688
|
+
if (!d || this._open)
|
|
689
|
+
return;
|
|
690
|
+
this._open = true;
|
|
691
|
+
this._ret = trigger || document.activeElement;
|
|
692
|
+
this._origin = trigger ? trigger.getBoundingClientRect() : null;
|
|
693
|
+
if (typeof d.showModal === 'function') {
|
|
694
|
+
try {
|
|
695
|
+
d.showModal();
|
|
696
|
+
}
|
|
697
|
+
catch {
|
|
698
|
+
d.setAttribute('open', '');
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
else
|
|
702
|
+
d.setAttribute('open', '');
|
|
703
|
+
this.setAttribute('data-open', '');
|
|
704
|
+
this.backdrop(true);
|
|
705
|
+
this.motion(d, this.frames(true), { duration: this.reduced ? 150 : kind === 'sheet' ? 420 : 460, easing: EASE_OUT });
|
|
706
|
+
const f = d.querySelector('[autofocus]') || d.querySelector('button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])');
|
|
707
|
+
f?.focus?.();
|
|
708
|
+
this.emit('open', { trigger: trigger || null });
|
|
709
|
+
}
|
|
710
|
+
close(value = '') {
|
|
711
|
+
const d = this._dlg;
|
|
712
|
+
if (!d || !this._open)
|
|
713
|
+
return Promise.resolve();
|
|
714
|
+
if (this._closing)
|
|
715
|
+
return this._closing;
|
|
716
|
+
this._value = value;
|
|
717
|
+
this.backdrop(false);
|
|
718
|
+
const a = this.motion(d, this.frames(false), { duration: this.reduced ? 120 : 260, easing: 'cubic-bezier(.4,0,1,1)', fill: 'forwards' });
|
|
719
|
+
const done = () => {
|
|
720
|
+
this._closing = null;
|
|
721
|
+
this._open = false;
|
|
722
|
+
this.removeAttribute('data-open');
|
|
723
|
+
if (d.open && typeof d.close === 'function')
|
|
724
|
+
d.close(value);
|
|
725
|
+
else
|
|
726
|
+
d.removeAttribute('open');
|
|
727
|
+
a?.cancel?.();
|
|
728
|
+
d.style.transform = '';
|
|
729
|
+
this._ret?.focus?.();
|
|
730
|
+
this.emit('close', { value });
|
|
731
|
+
};
|
|
732
|
+
this._closing = a ? a.finished.then(done, done) : Promise.resolve().then(done);
|
|
733
|
+
return this._closing;
|
|
734
|
+
}
|
|
735
|
+
toggle() {
|
|
736
|
+
if (this._open)
|
|
737
|
+
void this.close();
|
|
738
|
+
else
|
|
739
|
+
this.show();
|
|
740
|
+
}
|
|
741
|
+
// bottom sheet: drag down to dismiss, springs back otherwise
|
|
742
|
+
drag() {
|
|
743
|
+
const p = this._panel;
|
|
744
|
+
const d = this._dlg;
|
|
745
|
+
if (!p || !d || this.dataset.side !== 'bottom')
|
|
746
|
+
return;
|
|
747
|
+
let y0 = -1;
|
|
748
|
+
let dy = 0;
|
|
749
|
+
let t0 = 0;
|
|
750
|
+
this.listen(p, 'pointerdown', (e) => {
|
|
751
|
+
if (!e.target.closest('[data-handle]'))
|
|
752
|
+
return;
|
|
753
|
+
y0 = e.clientY;
|
|
754
|
+
dy = 0;
|
|
755
|
+
t0 = performance.now();
|
|
756
|
+
e.target.setPointerCapture?.(e.pointerId);
|
|
757
|
+
});
|
|
758
|
+
this.listen(p, 'pointermove', (e) => {
|
|
759
|
+
if (y0 < 0)
|
|
760
|
+
return;
|
|
761
|
+
dy = Math.max(0, e.clientY - y0);
|
|
762
|
+
d.style.transform = `translateY(${dy}px)`;
|
|
763
|
+
});
|
|
764
|
+
const up = () => {
|
|
765
|
+
if (y0 < 0)
|
|
766
|
+
return;
|
|
767
|
+
y0 = -1;
|
|
768
|
+
const v = dy / Math.max(1, performance.now() - t0);
|
|
769
|
+
if (dy > d.offsetHeight * 0.3 || v > 0.6)
|
|
770
|
+
void this.close();
|
|
771
|
+
else {
|
|
772
|
+
this.motion(d, [{ transform: `translateY(${dy}px)` }, { transform: 'translateY(-6px)', offset: 0.6 }, { transform: 'none' }], { duration: 380, easing: EASE_OUT });
|
|
773
|
+
d.style.transform = '';
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
this.listen(p, 'pointerup', up);
|
|
777
|
+
this.listen(p, 'pointercancel', up);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return UsaOverlay;
|
|
781
|
+
}, { id: 'overlay', text: css$2 });
|
|
782
|
+
}
|
|
783
|
+
const defineModal = (tag = 'usa-modal') => defineOverlay(tag, 'modal');
|
|
784
|
+
const defineSheet = (tag = 'usa-sheet') => defineOverlay(tag, 'sheet');
|
|
785
|
+
|
|
786
|
+
var css$1 = "usa-toast-stack{position:fixed;z-index:2147482000;width:min(360px,calc(100vw - 24px));pointer-events:none;--usa-tstack-bg:#111827;--usa-tstack-fg:#f9fafb}usa-toast-stack[contained]{position:absolute;width:min(360px,calc(100% - 24px))}usa-toast-stack[data-position^=\"bottom\"]{bottom:12px}usa-toast-stack[data-position^=\"top\"]{top:12px}usa-toast-stack[data-position$=\"right\"]{right:12px}usa-toast-stack[data-position$=\"left\"]{left:12px}usa-toast-stack[data-position$=\"center\"]{left:50%;transform:translateX(-50%)}.usa-tstack-list{position:relative;list-style:none;margin:0;padding:0;min-height:1px;transition:height .3s}.usa-tstack{position:absolute;left:0;right:0;display:flex;align-items:center;gap:10px;box-sizing:border-box;padding:12px 12px 12px 14px;border-radius:14px;background:var(--usa-tstack-bg);color:var(--usa-tstack-fg);box-shadow:0 12px 32px -10px rgba(0,0,0,.45);font:500 14px/1.35 system-ui,sans-serif;pointer-events:auto;touch-action:pan-y;transition:transform .38s cubic-bezier(.22,1,.36,1),opacity .3s;user-select:none}usa-toast-stack[data-position^=\"bottom\"] .usa-tstack{bottom:0;transform-origin:50% 100%}usa-toast-stack[data-position^=\"top\"] .usa-tstack{top:0;transform-origin:50% 0}.usa-tstack-icon{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;font-size:13px;font-weight:800;background:#3b82f6;color:#fff}.usa-tstack-success .usa-tstack-icon{background:#22c55e}.usa-tstack-warning .usa-tstack-icon{background:#f59e0b}.usa-tstack-error .usa-tstack-icon{background:#ef4444}.usa-tstack-text{flex:1;min-width:0;display:flex;flex-direction:column}.usa-tstack-text strong{font-weight:700}.usa-tstack-action{border:0;border-radius:8px;padding:6px 10px;background:rgba(255,255,255,.14);color:inherit;font:600 13px system-ui,sans-serif;cursor:pointer}.usa-tstack-close{border:0;background:none;color:inherit;opacity:.6;font-size:18px;line-height:1;cursor:pointer;padding:2px 4px}.usa-tstack-close:hover{opacity:1}@media (prefers-reduced-motion:reduce){.usa-tstack,.usa-tstack-list{transition:none}}";
|
|
787
|
+
|
|
788
|
+
const TOAST_POSITIONS = ['bottom-right', 'bottom-left', 'bottom-center', 'top-right', 'top-left', 'top-center'];
|
|
789
|
+
const ICONS = { info: 'ℹ', success: '✓', warning: '!', error: '✕' };
|
|
790
|
+
let tid = 0;
|
|
791
|
+
function defineToastStack(tag = 'usa-toast-stack') {
|
|
792
|
+
installToastTriggers();
|
|
793
|
+
return defineElement(tag, (Base) => {
|
|
794
|
+
class UsaToastStack extends Base {
|
|
795
|
+
constructor() {
|
|
796
|
+
super(...arguments);
|
|
797
|
+
this._list = null;
|
|
798
|
+
this._timers = new Map();
|
|
799
|
+
this._hover = false;
|
|
800
|
+
}
|
|
801
|
+
static get observedAttributes() {
|
|
802
|
+
return ['position'];
|
|
803
|
+
}
|
|
804
|
+
get count() {
|
|
805
|
+
return this._list ? this._list.querySelectorAll(':scope > .usa-tstack:not([data-leaving])').length : 0;
|
|
806
|
+
}
|
|
807
|
+
mount() {
|
|
808
|
+
const pos = this.str('position', 'bottom-right');
|
|
809
|
+
this.dataset.position = TOAST_POSITIONS.includes(pos) ? pos : 'bottom-right';
|
|
810
|
+
this.setAttribute('role', 'region');
|
|
811
|
+
if (!this.hasAttribute('aria-label'))
|
|
812
|
+
this.setAttribute('aria-label', 'Notifications');
|
|
813
|
+
this._list = this.querySelector(':scope > .usa-tstack-list') || part('ol', 'usa-tstack-list', { 'aria-live': 'polite', 'aria-relevant': 'additions' });
|
|
814
|
+
if (!this._list.isConnected)
|
|
815
|
+
this.append(this._list);
|
|
816
|
+
const expand = (on) => {
|
|
817
|
+
this._hover = on;
|
|
818
|
+
this.toggleAttribute('data-expanded', on);
|
|
819
|
+
this.layout();
|
|
820
|
+
for (const [id, t] of this._timers)
|
|
821
|
+
on ? this.pause(id, t) : this.resume(id);
|
|
822
|
+
};
|
|
823
|
+
this.listen(this, 'pointerenter', () => expand(true));
|
|
824
|
+
this.listen(this, 'pointerleave', () => expand(false));
|
|
825
|
+
this.listen(this, 'focusin', () => expand(true));
|
|
826
|
+
this.listen(this, 'focusout', (e) => !this.contains(e.relatedTarget) && expand(false));
|
|
827
|
+
this.onCleanup(() => this._timers.forEach((t) => t.h && clearTimeout(t.h)));
|
|
828
|
+
}
|
|
829
|
+
pause(_id, t) {
|
|
830
|
+
if (!t.h)
|
|
831
|
+
return;
|
|
832
|
+
clearTimeout(t.h);
|
|
833
|
+
t.h = 0;
|
|
834
|
+
t.left -= Date.now() - t.start;
|
|
835
|
+
}
|
|
836
|
+
resume(id) {
|
|
837
|
+
const t = this._timers.get(id);
|
|
838
|
+
if (!t || t.h)
|
|
839
|
+
return;
|
|
840
|
+
t.start = Date.now();
|
|
841
|
+
t.h = setTimeout(() => this.dismiss(id, 'timeout'), Math.max(400, t.left));
|
|
842
|
+
}
|
|
843
|
+
show(input) {
|
|
844
|
+
const o = typeof input === 'string' ? { message: input } : input || {};
|
|
845
|
+
const id = `usa-tstack-${++tid}`;
|
|
846
|
+
const type = o.type && ICONS[o.type] ? o.type : 'info';
|
|
847
|
+
const li = part('li', `usa-tstack usa-tstack-${type}`, { id, role: type === 'error' ? 'alert' : 'status' });
|
|
848
|
+
li.append(part('span', 'usa-tstack-icon', { 'aria-hidden': 'true' }, ICONS[type]));
|
|
849
|
+
const txt = part('div', 'usa-tstack-text');
|
|
850
|
+
if (o.title)
|
|
851
|
+
txt.append(Object.assign(document.createElement('strong'), { textContent: o.title }));
|
|
852
|
+
if (o.message)
|
|
853
|
+
txt.append(Object.assign(document.createElement('span'), { textContent: o.message }));
|
|
854
|
+
li.append(txt);
|
|
855
|
+
if (o.action) {
|
|
856
|
+
const b = part('button', 'usa-tstack-action', { type: 'button' });
|
|
857
|
+
b.textContent = o.action.label;
|
|
858
|
+
b.addEventListener('click', () => {
|
|
859
|
+
o.action?.onClick?.();
|
|
860
|
+
this.dismiss(id, 'action');
|
|
861
|
+
});
|
|
862
|
+
li.append(b);
|
|
863
|
+
}
|
|
864
|
+
const x = part('button', 'usa-tstack-close', { type: 'button', 'aria-label': 'Dismiss' }, '×');
|
|
865
|
+
x.addEventListener('click', () => this.dismiss(id, 'close'));
|
|
866
|
+
li.append(x);
|
|
867
|
+
this.swipe(li, id);
|
|
868
|
+
this._list?.prepend(li);
|
|
869
|
+
const top = this.dataset.position?.startsWith('top');
|
|
870
|
+
this.motion(li, this.reduced ? [{ opacity: 0 }, { opacity: 1 }] : [{ opacity: 0, translate: `0 ${top ? -110 : 110}%`, scale: '0.9' }, { opacity: 1, translate: '0 0', scale: '1' }], { duration: this.reduced ? 150 : 420, easing: 'cubic-bezier(.22,1,.36,1)' });
|
|
871
|
+
this.layout();
|
|
872
|
+
const dur = o.duration ?? this.num('duration', 4000);
|
|
873
|
+
if (dur > 0) {
|
|
874
|
+
this._timers.set(id, { left: dur, start: Date.now(), h: 0 });
|
|
875
|
+
if (!this._hover)
|
|
876
|
+
this.resume(id);
|
|
877
|
+
}
|
|
878
|
+
this.emit('show', { id, ...o });
|
|
879
|
+
return id;
|
|
880
|
+
}
|
|
881
|
+
dismiss(id, reason = 'api') {
|
|
882
|
+
const li = this._list?.querySelector(`#${id}`);
|
|
883
|
+
const t = this._timers.get(id);
|
|
884
|
+
if (t?.h)
|
|
885
|
+
clearTimeout(t.h);
|
|
886
|
+
this._timers.delete(id);
|
|
887
|
+
if (!li || li.hasAttribute('data-leaving'))
|
|
888
|
+
return;
|
|
889
|
+
li.setAttribute('data-leaving', '');
|
|
890
|
+
const dx = Number(li.dataset.dx || 0);
|
|
891
|
+
const a = this.motion(li, this.reduced ? [{ opacity: 1 }, { opacity: 0 }] : [{ opacity: 1, transform: `translateX(${dx}px)` }, { opacity: 0, transform: `translateX(${dx >= 0 ? 120 : -120}%)` }], { duration: this.reduced ? 120 : 260, easing: 'cubic-bezier(.4,0,1,1)', fill: 'forwards' });
|
|
892
|
+
const rm = () => {
|
|
893
|
+
li.remove();
|
|
894
|
+
this.layout();
|
|
895
|
+
};
|
|
896
|
+
if (a)
|
|
897
|
+
a.finished.then(rm, rm);
|
|
898
|
+
else
|
|
899
|
+
rm();
|
|
900
|
+
this.emit('dismiss', { id, reason });
|
|
901
|
+
}
|
|
902
|
+
clear() {
|
|
903
|
+
this._list?.querySelectorAll(':scope > .usa-tstack').forEach((li) => this.dismiss(li.id, 'clear'));
|
|
904
|
+
}
|
|
905
|
+
/** Collapsed: newest in front, older ones scaled down peeking behind. Expanded: a list. */
|
|
906
|
+
layout() {
|
|
907
|
+
if (!this._list)
|
|
908
|
+
return;
|
|
909
|
+
const items = Array.from(this._list.querySelectorAll(':scope > .usa-tstack:not([data-leaving])'));
|
|
910
|
+
const max = Math.max(1, this.num('max', 3));
|
|
911
|
+
const dir = this.dataset.position?.startsWith('top') ? 1 : -1;
|
|
912
|
+
let y = 0;
|
|
913
|
+
items.forEach((li, k) => {
|
|
914
|
+
const h = li.offsetHeight || 56;
|
|
915
|
+
const tf = this._hover ? `translateY(${dir * y}px)` : `translateY(${dir * k * 10}px) scale(${(1 - k * 0.05).toFixed(3)})`;
|
|
916
|
+
li.style.transform = tf;
|
|
917
|
+
li.style.zIndex = String(100 - k);
|
|
918
|
+
li.style.opacity = !this._hover && k >= max ? '0' : '';
|
|
919
|
+
li.toggleAttribute('inert', !this._hover && k > 0);
|
|
920
|
+
y += h + 10;
|
|
921
|
+
});
|
|
922
|
+
this._list.style.height = this._hover && items.length ? `${y}px` : '';
|
|
923
|
+
}
|
|
924
|
+
swipe(li, id) {
|
|
925
|
+
let x0 = NaN;
|
|
926
|
+
li.addEventListener('pointerdown', (e) => {
|
|
927
|
+
if (e.target.closest('button'))
|
|
928
|
+
return;
|
|
929
|
+
x0 = e.clientX;
|
|
930
|
+
li.setPointerCapture?.(e.pointerId);
|
|
931
|
+
});
|
|
932
|
+
li.addEventListener('pointermove', (e) => {
|
|
933
|
+
if (Number.isNaN(x0))
|
|
934
|
+
return;
|
|
935
|
+
const dx = e.clientX - x0;
|
|
936
|
+
li.dataset.dx = String(dx);
|
|
937
|
+
li.style.translate = `${dx}px 0`;
|
|
938
|
+
li.style.opacity = String(Math.max(0.2, 1 - Math.abs(dx) / 240));
|
|
939
|
+
});
|
|
940
|
+
const up = () => {
|
|
941
|
+
if (Number.isNaN(x0))
|
|
942
|
+
return;
|
|
943
|
+
x0 = NaN;
|
|
944
|
+
const dx = Number(li.dataset.dx || 0);
|
|
945
|
+
li.style.translate = '';
|
|
946
|
+
li.style.opacity = '';
|
|
947
|
+
if (Math.abs(dx) > 80)
|
|
948
|
+
this.dismiss(id, 'swipe');
|
|
949
|
+
else
|
|
950
|
+
li.dataset.dx = '0';
|
|
951
|
+
};
|
|
952
|
+
li.addEventListener('pointerup', up);
|
|
953
|
+
li.addEventListener('pointercancel', up);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return UsaToastStack;
|
|
957
|
+
}, { id: 'toast', text: css$1 });
|
|
958
|
+
}
|
|
959
|
+
/** Show a toast on the first `<usa-toast-stack>` of the page (one is created when missing). */
|
|
960
|
+
function stackToast(input, stack) {
|
|
961
|
+
defineToastStack();
|
|
962
|
+
let s = stack || document.querySelector('usa-toast-stack');
|
|
963
|
+
if (!s) {
|
|
964
|
+
s = document.createElement('usa-toast-stack');
|
|
965
|
+
document.body.append(s);
|
|
966
|
+
}
|
|
967
|
+
return s.show(input);
|
|
968
|
+
}
|
|
969
|
+
let trig = false;
|
|
970
|
+
function installToastTriggers() {
|
|
971
|
+
delegateTriggers();
|
|
972
|
+
if (trig || typeof document === 'undefined')
|
|
973
|
+
return;
|
|
974
|
+
trig = true;
|
|
975
|
+
document.addEventListener('click', (e) => {
|
|
976
|
+
const t = e.target?.closest?.('[data-usa-toast]');
|
|
977
|
+
if (!t)
|
|
978
|
+
return;
|
|
979
|
+
const target = t.getAttribute('data-usa-target');
|
|
980
|
+
const s = target ? document.getElementById(target) : null;
|
|
981
|
+
stackToast({ message: t.getAttribute('data-usa-toast') || '', title: t.getAttribute('data-usa-toast-title') || undefined, type: t.getAttribute('data-usa-toast-type') || 'info' }, s);
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
var css = "usa-menu{position:relative;display:inline-block}.usa-menu-list{position:absolute;z-index:50;min-width:180px;max-width:min(280px,90vw);box-sizing:border-box;padding:6px;border-radius:12px;background:var(--usa-menu-bg,#fff);color:var(--usa-menu-fg,#111827);box-shadow:0 18px 44px -12px rgba(0,0,0,.35),0 0 0 1px rgba(127,127,127,.15);display:flex;flex-direction:column;gap:2px;text-align:left}.usa-menu-list[hidden]{display:none}usa-menu[data-placement^=\"bottom\"] .usa-menu-list{top:calc(100% + 6px)}usa-menu[data-placement^=\"top\"] .usa-menu-list{bottom:calc(100% + 6px)}usa-menu[data-placement$=\"start\"] .usa-menu-list{left:0;transform-origin:0 0}usa-menu[data-placement$=\"end\"] .usa-menu-list{right:0;transform-origin:100% 0}usa-menu[data-placement=\"top-start\"] .usa-menu-list{transform-origin:0 100%}usa-menu[data-placement=\"top-end\"] .usa-menu-list{transform-origin:100% 100%}.usa-menu-list>[role=\"menuitem\"]{display:flex;align-items:center;gap:8px;width:100%;box-sizing:border-box;border:0;background:none;color:inherit;font:500 14px/1.3 system-ui,sans-serif;text-align:left;text-decoration:none;padding:8px 10px;border-radius:8px;cursor:pointer}.usa-menu-list>[role=\"menuitem\"]:hover,.usa-menu-list>[role=\"menuitem\"]:focus-visible{background:var(--usa-menu-hover,rgba(124,92,255,.14));outline:none}.usa-menu-list>hr{border:0;border-top:1px solid rgba(127,127,127,.2);margin:4px 2px}@media (prefers-color-scheme:dark){.usa-menu-list{background:var(--usa-menu-bg,#1d2130);color:var(--usa-menu-fg,#e5e7eb)}}";
|
|
986
|
+
|
|
987
|
+
const MENU_EFFECTS = ['scale', 'fold', 'slide'];
|
|
988
|
+
function defineMenu(tag = 'usa-menu') {
|
|
989
|
+
return defineElement(tag, (Base) => {
|
|
990
|
+
class UsaMenu extends Base {
|
|
991
|
+
constructor() {
|
|
992
|
+
super(...arguments);
|
|
993
|
+
this._btn = null;
|
|
994
|
+
this._list = null;
|
|
995
|
+
this._items = [];
|
|
996
|
+
this._open = false;
|
|
997
|
+
}
|
|
998
|
+
static get observedAttributes() {
|
|
999
|
+
return ['placement', 'effect'];
|
|
1000
|
+
}
|
|
1001
|
+
get opened() {
|
|
1002
|
+
return this._open;
|
|
1003
|
+
}
|
|
1004
|
+
mount() {
|
|
1005
|
+
const kids = ownChildren(this);
|
|
1006
|
+
this._btn = kids.find((k) => k.hasAttribute('data-trigger')) || kids[0] || null;
|
|
1007
|
+
let list = this.querySelector(':scope > .usa-menu-list');
|
|
1008
|
+
if (!list) {
|
|
1009
|
+
list = part('div', 'usa-menu-list', { role: 'menu' });
|
|
1010
|
+
for (const k of kids)
|
|
1011
|
+
if (k !== this._btn)
|
|
1012
|
+
list.append(k);
|
|
1013
|
+
this.append(list);
|
|
1014
|
+
}
|
|
1015
|
+
this._list = list;
|
|
1016
|
+
list.id || (list.id = nextId('usa-menu'));
|
|
1017
|
+
list.hidden = !this._open;
|
|
1018
|
+
const pl = this.str('placement', 'bottom-start');
|
|
1019
|
+
this.dataset.placement = /^(bottom|top)-(start|end)$/.test(pl) ? pl : 'bottom-start';
|
|
1020
|
+
const ef = this.str('effect', 'scale');
|
|
1021
|
+
this.dataset.effect = MENU_EFFECTS.includes(ef) ? ef : 'scale';
|
|
1022
|
+
this._items = Array.from(list.children).filter((c) => c instanceof HTMLElement && !c.matches('hr,[role="separator"]'));
|
|
1023
|
+
list.querySelectorAll('hr').forEach((h) => h.setAttribute('role', 'separator'));
|
|
1024
|
+
this._items.forEach((it, i) => {
|
|
1025
|
+
it.setAttribute('role', 'menuitem');
|
|
1026
|
+
it.tabIndex = -1;
|
|
1027
|
+
if (it.localName === 'button' && !it.hasAttribute('type'))
|
|
1028
|
+
it.setAttribute('type', 'button');
|
|
1029
|
+
this.listen(it, 'click', () => {
|
|
1030
|
+
this.emit('select', { index: i, value: it.dataset.value || (it.textContent || '').trim(), item: it });
|
|
1031
|
+
this.close(true);
|
|
1032
|
+
});
|
|
1033
|
+
});
|
|
1034
|
+
const b = this._btn;
|
|
1035
|
+
if (b) {
|
|
1036
|
+
b.setAttribute('aria-haspopup', 'menu');
|
|
1037
|
+
b.setAttribute('aria-expanded', String(this._open));
|
|
1038
|
+
b.setAttribute('aria-controls', list.id);
|
|
1039
|
+
if (b.localName === 'button' && !b.hasAttribute('type'))
|
|
1040
|
+
b.setAttribute('type', 'button');
|
|
1041
|
+
this.listen(b, 'click', () => this.toggle());
|
|
1042
|
+
this.listen(b, 'keydown', (e) => {
|
|
1043
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
1044
|
+
e.preventDefault();
|
|
1045
|
+
this.open(e.key === 'ArrowUp' ? 'last' : 'first');
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
this.listen(list, 'keydown', (e) => {
|
|
1050
|
+
const n = this._items.length;
|
|
1051
|
+
const i = this._items.indexOf(document.activeElement);
|
|
1052
|
+
let j = -1;
|
|
1053
|
+
if (e.key === 'ArrowDown')
|
|
1054
|
+
j = (i + 1) % n;
|
|
1055
|
+
else if (e.key === 'ArrowUp')
|
|
1056
|
+
j = (i - 1 + n) % n;
|
|
1057
|
+
else if (e.key === 'Home')
|
|
1058
|
+
j = 0;
|
|
1059
|
+
else if (e.key === 'End')
|
|
1060
|
+
j = n - 1;
|
|
1061
|
+
else if (e.key === 'Escape') {
|
|
1062
|
+
e.preventDefault();
|
|
1063
|
+
return this.close(true);
|
|
1064
|
+
}
|
|
1065
|
+
else if (e.key === 'Tab')
|
|
1066
|
+
return this.close(false);
|
|
1067
|
+
if (j >= 0) {
|
|
1068
|
+
e.preventDefault();
|
|
1069
|
+
this._items[j]?.focus();
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
this.listen(document, 'pointerdown', (e) => {
|
|
1073
|
+
if (this._open && !this.contains(e.target))
|
|
1074
|
+
this.close(false);
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
open(focus = 'first') {
|
|
1078
|
+
const l = this._list;
|
|
1079
|
+
if (!l || this._open)
|
|
1080
|
+
return;
|
|
1081
|
+
this._open = true;
|
|
1082
|
+
l.hidden = false;
|
|
1083
|
+
this._btn?.setAttribute('aria-expanded', 'true');
|
|
1084
|
+
this.setAttribute('data-open', '');
|
|
1085
|
+
const ef = this.dataset.effect;
|
|
1086
|
+
if (this.reduced)
|
|
1087
|
+
this.motion(l, [{ opacity: 0 }, { opacity: 1 }], { duration: 120 });
|
|
1088
|
+
else {
|
|
1089
|
+
const f = ef === 'fold' ? [{ transform: 'perspective(600px) rotateX(-70deg)', opacity: 0 }, { transform: 'none', opacity: 1 }] : ef === 'slide' ? [{ transform: 'translateY(-10px)', opacity: 0, clipPath: 'inset(0 0 100% 0 round 12px)' }, { transform: 'none', opacity: 1, clipPath: 'inset(0 0 0 0 round 12px)' }] : [{ transform: 'scale(.6)', opacity: 0 }, { transform: 'scale(1.03)', opacity: 1, offset: 0.7 }, { transform: 'none', opacity: 1 }];
|
|
1090
|
+
this.motion(l, f, { duration: 300, easing: 'cubic-bezier(.22,1,.36,1)' });
|
|
1091
|
+
this._items.forEach((it, i) => this.motion(it, [{ opacity: 0, transform: 'translateY(-6px)' }, { opacity: 1, transform: 'none' }], { duration: 260, delay: 40 + i * 35, easing: 'cubic-bezier(.22,1,.36,1)', fill: 'backwards' }));
|
|
1092
|
+
}
|
|
1093
|
+
(focus === 'last' ? this._items[this._items.length - 1] : this._items[0])?.focus();
|
|
1094
|
+
this.emit('open');
|
|
1095
|
+
}
|
|
1096
|
+
close(focusTrigger = false) {
|
|
1097
|
+
const l = this._list;
|
|
1098
|
+
if (!l || !this._open)
|
|
1099
|
+
return;
|
|
1100
|
+
this._open = false;
|
|
1101
|
+
this._btn?.setAttribute('aria-expanded', 'false');
|
|
1102
|
+
this.removeAttribute('data-open');
|
|
1103
|
+
const a = this.motion(l, [{ opacity: 1, transform: 'none' }, { opacity: 0, transform: this.reduced ? 'none' : 'scale(.96)' }], { duration: this.reduced ? 80 : 150, easing: 'ease-in' });
|
|
1104
|
+
const hide = () => {
|
|
1105
|
+
if (!this._open)
|
|
1106
|
+
l.hidden = true;
|
|
1107
|
+
};
|
|
1108
|
+
if (a)
|
|
1109
|
+
a.finished.then(hide, hide);
|
|
1110
|
+
else
|
|
1111
|
+
hide();
|
|
1112
|
+
if (focusTrigger)
|
|
1113
|
+
this._btn?.focus();
|
|
1114
|
+
this.emit('close');
|
|
1115
|
+
}
|
|
1116
|
+
toggle() {
|
|
1117
|
+
if (this._open)
|
|
1118
|
+
this.close(true);
|
|
1119
|
+
else
|
|
1120
|
+
this.open();
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
return UsaMenu;
|
|
1124
|
+
}, { id: 'menu', text: css });
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* motionary/components/widgets — the 6.x animated UI widgets, in their own
|
|
1129
|
+
* entry so `motionary/components` and `components/lite` keep their size
|
|
1130
|
+
* budgets. Every widget is reduced-motion safe and keyboard accessible.
|
|
1131
|
+
*
|
|
1132
|
+
* ```ts
|
|
1133
|
+
* import { defineWidgets } from 'motionary/components/widgets';
|
|
1134
|
+
* defineWidgets(); // or defineCarousel(), defineTabBar(), …
|
|
1135
|
+
* ```
|
|
1136
|
+
* No build step: `<script src="https://unpkg.com/motionary@6/dist/widgets.umd.js">`
|
|
1137
|
+
* (registers every widget and every 6.x effect pack; `window.UsaWidgets`).
|
|
1138
|
+
*/
|
|
1139
|
+
/** The widgets by release (tag → define function). */
|
|
1140
|
+
const WIDGETS = {
|
|
1141
|
+
'6.2': { 'usa-carousel': defineCarousel, 'usa-tab-bar': defineTabBar, 'usa-disclosure': defineDisclosure, 'usa-stories': defineStories },
|
|
1142
|
+
'6.3': { 'usa-toast-stack': defineToastStack, 'usa-modal': defineModal, 'usa-sheet': defineSheet, 'usa-menu': defineMenu },
|
|
1143
|
+
};
|
|
1144
|
+
/** Every widget tag, in release order. */
|
|
1145
|
+
const WIDGET_TAGS = Object.values(WIDGETS).flatMap((g) => Object.keys(g));
|
|
1146
|
+
/** Register every widget (or only those of one release, e.g. `'6.2'`) under its default tag. */
|
|
1147
|
+
function defineWidgets(release) {
|
|
1148
|
+
for (const [v, group] of Object.entries(WIDGETS))
|
|
1149
|
+
if (!release || release === v)
|
|
1150
|
+
for (const [tag, fn] of Object.entries(group))
|
|
1151
|
+
fn(tag);
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
export { CAROUSEL_EFFECTS, MENU_EFFECTS, MODAL_EFFECTS, SHEET_SIDES, TAB_INDICATORS, TOAST_POSITIONS, WIDGETS, WIDGET_TAGS, defineCarousel, defineDisclosure, defineMenu, defineModal, defineSheet, defineStories, defineTabBar, defineToastStack, defineWidgets, stackToast };
|
|
1155
|
+
//# sourceMappingURL=widgets.js.map
|