@apliteni/apliteni-ui 0.142.1 → 0.142.4
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/README.md +24 -36
- package/guidelines/state-set.md +4 -4
- package/package.json +3 -3
- package/react/dist/index.css +7 -3
- package/react/dist/index.js +12 -5
- package/src/index.d.ts +13 -96
- package/src/index.js +17 -30
- package/src/styles/command-palette.css +9 -5
- package/src/styles/drawer.css +8 -0
- package/src/styles/dropdown.css +30 -8
- package/src/styles/feedback.css +1 -1
- package/src/styles/filter-bar.css +5 -2
- package/src/styles/input.css +14 -15
- package/src/styles/layout.css +5 -2
- package/src/styles/table.css +28 -2
- package/src/styles/tap-zone.css +9 -4
- package/src/styles/topbar.css +8 -6
- package/src/components/account-nav.js +0 -37
- package/src/components/avatar.js +0 -53
- package/src/components/back.js +0 -57
- package/src/components/button-busy.js +0 -69
- package/src/components/command-palette.js +0 -471
- package/src/components/confirm.js +0 -131
- package/src/components/drawer.js +0 -169
- package/src/components/dropdown.js +0 -1055
- package/src/components/feedback.js +0 -171
- package/src/components/filter-bar.js +0 -86
- package/src/components/footer.js +0 -102
- package/src/components/index.js +0 -352
- package/src/components/loading.js +0 -127
- package/src/components/nav.js +0 -220
- package/src/components/overlay.js +0 -263
- package/src/components/pagination.js +0 -323
- package/src/components/segmented.js +0 -33
- package/src/components/shell.js +0 -511
- package/src/components/stat.js +0 -82
- package/src/components/success.js +0 -131
- package/src/components/table-values.js +0 -32
- package/src/components/tabs.js +0 -82
- package/src/components/toasts.js +0 -118
- package/src/components/tooltip.js +0 -347
- package/src/components/topbar.js +0 -270
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// Success / confirmation surface. One factory, three layouts, two check marks,
|
|
2
|
-
// optional confetti and an optional auto-redirect countdown, every motion path
|
|
3
|
-
// reduced-motion safe. Accent-aware, but the mark stays on the --green family.
|
|
4
|
-
//
|
|
5
|
-
// container.innerHTML = success({ title, body, actions: [{ label, variant }] });
|
|
6
|
-
//
|
|
7
|
-
// The check animation is pure CSS, so string-rendered markup animates once
|
|
8
|
-
// mounted. A live countdown is opt-in via wireSuccess().
|
|
9
|
-
import { esc, button } from './index.js';
|
|
10
|
-
|
|
11
|
-
// 'line' is the bare Lucide `check`, 'circled' is Lucide circle-check-big. Which
|
|
12
|
-
// is the default, and why that departs from Guidelines / Iconography:
|
|
13
|
-
// why: docs/components.md#success-confirmations
|
|
14
|
-
// Each is written whole because the icon-sizing and glyph-stroke gates find their
|
|
15
|
-
// subjects by scanning source for a class on an `<svg …>`: a tag split across
|
|
16
|
-
// string pieces leaves both silent rather than failing.
|
|
17
|
-
const MARKS = {
|
|
18
|
-
line: '<svg class="ui-sx__check ui-sx__check--line" width="24" height="24" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="ui-sx__tick" d="M20 6L9 17l-5-5"/></svg>',
|
|
19
|
-
circled: '<svg class="ui-sx__check ui-sx__check--circled" width="24" height="24" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path class="ui-sx__circle" d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path class="ui-sx__tick" d="M22 4L12 14.01l-3-3"/></svg>',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export function successCheck(variant = 'line') {
|
|
23
|
-
return Object.hasOwn(MARKS, variant) ? MARKS[variant] : MARKS.line;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// A deterministic confetti field (opt-in). Decorative + aria-hidden; each piece
|
|
27
|
-
// carries its own drift/rotation/colour via custom props so the CSS can scatter
|
|
28
|
-
// them without inline keyframes. Deterministic so string renders stay stable
|
|
29
|
-
// (and the a11y snapshot is reproducible).
|
|
30
|
-
const CONFETTI = [
|
|
31
|
-
{ x: 8, d: 0.00, r: -24, t: 'a', s: 1.0 }, { x: 20, d: 0.14, r: 40, t: 'g', s: 0.8 },
|
|
32
|
-
{ x: 31, d: 0.06, r: 12, t: 'c', s: 1.1 }, { x: 42, d: 0.20, r: -52, t: 'p', s: 0.9 },
|
|
33
|
-
{ x: 50, d: 0.02, r: 28, t: 'a', s: 1.0 }, { x: 58, d: 0.18, r: -16, t: 'k', s: 0.75 },
|
|
34
|
-
{ x: 67, d: 0.09, r: 60, t: 'g', s: 1.05 },{ x: 76, d: 0.24, r: -36, t: 'c', s: 0.85 },
|
|
35
|
-
{ x: 85, d: 0.05, r: 20, t: 'a', s: 1.0 }, { x: 92, d: 0.16, r: -48, t: 'p', s: 0.9 },
|
|
36
|
-
{ x: 14, d: 0.30, r: 44, t: 'k', s: 0.8 }, { x: 37, d: 0.34, r: -28, t: 'g', s: 1.0 },
|
|
37
|
-
{ x: 62, d: 0.28, r: 52, t: 'a', s: 0.9 }, { x: 80, d: 0.36, r: -20, t: 'c', s: 1.05 },
|
|
38
|
-
];
|
|
39
|
-
function confettiField() {
|
|
40
|
-
const pieces = CONFETTI.map((p) =>
|
|
41
|
-
`<i class="ui-sx__piece ui-sx__piece--${p.t}" style="left:${p.x}%;--sx-d:${p.d}s;--sx-r:${p.r}deg;--sx-s:${p.s}"></i>`,
|
|
42
|
-
).join('');
|
|
43
|
-
return `<div class="ui-sx__confetti" aria-hidden="true">${pieces}</div>`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Optional auto-redirect countdown. Markup-only here (a conic ring sweeps and a
|
|
47
|
-
// static number shows); wireSuccess() turns it into a live ticking counter.
|
|
48
|
-
function countdownEl({ seconds = 5, label = 'Redirecting' } = {}) {
|
|
49
|
-
return `<div class="ui-sx__count" data-sx-count style="--sx-secs:${esc(seconds)}s">
|
|
50
|
-
<span class="ui-sx__count-ring" aria-hidden="true"></span>
|
|
51
|
-
<span class="ui-sx__count-text">${esc(label)} in <b data-sx-num>${esc(seconds)}</b>s</span>
|
|
52
|
-
</div>`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// The page-sized confirmation — what a flow lands on once it is over. It fills
|
|
56
|
-
// the space it is given, and carries the things a screen needs that a block does
|
|
57
|
-
// not: somewhere to go next, and optionally a countdown that takes the user
|
|
58
|
-
// there.
|
|
59
|
-
//
|
|
60
|
-
// For a confirmation that stays inside the page the user is already on, the kit
|
|
61
|
-
// publishes successPanel() from components/index.js — a check, a title and one
|
|
62
|
-
// line of sub, and nothing to configure. Pick by how much of the screen the
|
|
63
|
-
// confirmation owns. The two share the check, while their layout and content
|
|
64
|
-
// remain independent.
|
|
65
|
-
//
|
|
66
|
-
// Both carry one title and at most one short line under it. There is no eyebrow
|
|
67
|
-
// tier: a confirmation stacking a label, a headline and a paragraph reads as
|
|
68
|
-
// three competing voices for one outcome.
|
|
69
|
-
// why: docs/components.md#success-confirmations
|
|
70
|
-
export function success({
|
|
71
|
-
layout = 'hero', // 'hero' | 'split' | 'compact'
|
|
72
|
-
level, // heading level of the title; see the note below
|
|
73
|
-
check = 'line', // 'line' | 'circled' — see successCheck() above
|
|
74
|
-
title = 'All done',
|
|
75
|
-
body = '', // one short line, or nothing; see the note below
|
|
76
|
-
actions = [], // [{ label, variant, href, icon, iconRight, size }]
|
|
77
|
-
confetti = false, // opt-in particle burst (reduced-motion safe)
|
|
78
|
-
countdown = null, // { seconds, label } | null
|
|
79
|
-
className = '',
|
|
80
|
-
} = {}) {
|
|
81
|
-
const mark = check === 'circled' ? 'circled' : 'line';
|
|
82
|
-
const cls = ['ui-sx', `ui-sx--${layout}`, `ui-sx--check-${mark}`, confetti && 'ui-sx--confetti', className]
|
|
83
|
-
.filter(Boolean).join(' ');
|
|
84
|
-
|
|
85
|
-
// The title's rank follows the layout, because the layout is the question
|
|
86
|
-
// "how much of the screen does this own": hero and split ARE the page a flow
|
|
87
|
-
// lands on, so their title is its h1; compact sits beside other content and
|
|
88
|
-
// takes h2. It was an h3 either way, which left a page whose whole content is
|
|
89
|
-
// a success() with no h1 at all — the fault Guidelines / The page names.
|
|
90
|
-
// A caller who knows better passes `level`. The look is the class's.
|
|
91
|
-
// why: guidelines/the-page.md#the-page
|
|
92
|
-
const rank = [1, 2, 3, 4, 5, 6].includes(Number(level)) ? Number(level) : (layout === 'compact' ? 2 : 1);
|
|
93
|
-
const h = `h${rank}`;
|
|
94
|
-
|
|
95
|
-
const bodyEl = body ? `<p class="ui-sx__body">${esc(body)}</p>` : '';
|
|
96
|
-
const actionsEl = actions.length
|
|
97
|
-
? `<div class="ui-sx__actions">${actions.map((a) => button({ size: 'md', ...a })).join('')}</div>`
|
|
98
|
-
: '';
|
|
99
|
-
const countEl = countdown ? countdownEl(countdown) : '';
|
|
100
|
-
|
|
101
|
-
return `<div class="${esc(cls)}" role="status" aria-live="polite">
|
|
102
|
-
${confetti ? confettiField() : ''}
|
|
103
|
-
<div class="ui-sx__inner">
|
|
104
|
-
<div class="ui-sx__visual">${successCheck(mark)}</div>
|
|
105
|
-
<div class="ui-sx__content">
|
|
106
|
-
<${h} class="ui-sx__title">${esc(title)}</${h}>
|
|
107
|
-
${bodyEl}
|
|
108
|
-
${actionsEl}
|
|
109
|
-
${countEl}
|
|
110
|
-
</div>
|
|
111
|
-
</div>
|
|
112
|
-
</div>`;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Live countdown wiring (opt-in). Ticks the number down once a second and calls
|
|
116
|
-
// onDone() at zero — e.g. to navigate. Respects reduced-motion only for the
|
|
117
|
-
// visual sweep (owned by CSS); the counter itself is content, so it still runs.
|
|
118
|
-
// Returns a stop() to cancel (unmount / user interaction).
|
|
119
|
-
// const stop = wireSuccess(el, { onDone: () => location.assign('/strategy') });
|
|
120
|
-
export function wireSuccess(root, { onDone } = {}) {
|
|
121
|
-
const box = root && root.querySelector('[data-sx-count]');
|
|
122
|
-
if (!box) return () => {};
|
|
123
|
-
const numEl = box.querySelector('[data-sx-num]');
|
|
124
|
-
let n = parseInt(box.style.getPropertyValue('--sx-secs'), 10) || parseInt(numEl?.textContent, 10) || 5;
|
|
125
|
-
const id = setInterval(() => {
|
|
126
|
-
n -= 1;
|
|
127
|
-
if (numEl) numEl.textContent = String(Math.max(0, n));
|
|
128
|
-
if (n <= 0) { clearInterval(id); if (typeof onDone === 'function') onDone(); }
|
|
129
|
-
}, 1000);
|
|
130
|
-
return () => clearInterval(id);
|
|
131
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { formatNumericValue, formatDeltaValue } from '../logic/table-values.js';
|
|
2
|
-
import { esc } from './index.js';
|
|
3
|
-
import { safeUrl } from '../html.js';
|
|
4
|
-
export function numericValue(options = {}) {
|
|
5
|
-
const value = formatNumericValue(options);
|
|
6
|
-
return `<span class="ui-value"${value.missing !== undefined ? ` aria-label="${esc(value.missing)}"` : ''}>${esc(value.text)}${value.unit ? `<span class="ui-value__unit">${esc(value.unit)}</span>` : ''}</span>`;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function deltaValue(options = {}) {
|
|
10
|
-
const value = formatDeltaValue(options);
|
|
11
|
-
return `<span class="${value.className}"${value.basisId ? ` aria-describedby="${esc(value.basisId)}"` : ''}>${esc(value.text)}</span>`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function rowIdentity({ symbol = '', name = '', logo, href } = {}) {
|
|
15
|
-
const tag = href ? 'a' : 'span';
|
|
16
|
-
return `<${tag} class="ui-identity"${href ? ` href="${esc(safeUrl(href))}"` : ''}>`
|
|
17
|
-
+ `<span class="ui-identity__logo" aria-hidden="true"><span>${esc(symbol.slice(0, 1))}</span>${logo ? `<img src="${esc(safeUrl(logo, ''))}" alt="">` : ''}</span>`
|
|
18
|
-
+ `<span class="ui-identity__symbol">${esc(symbol)}</span><span class="ui-identity__name">${esc(name)}</span></${tag}>`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const initializedImages = new WeakSet();
|
|
22
|
-
|
|
23
|
-
// Images keep their fallback underneath; no inline handlers in server-rendered markup.
|
|
24
|
-
export function initRowIdentity(root = document) {
|
|
25
|
-
root.querySelectorAll('.ui-identity__logo img').forEach(img => {
|
|
26
|
-
if (img.complete && !img.naturalWidth) img.hidden = true;
|
|
27
|
-
if (initializedImages.has(img)) return;
|
|
28
|
-
initializedImages.add(img);
|
|
29
|
-
img.addEventListener('error', () => { img.hidden = true; });
|
|
30
|
-
img.addEventListener('load', () => { img.hidden = false; });
|
|
31
|
-
});
|
|
32
|
-
}
|
package/src/components/tabs.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Tabs — an accessible tablist + panels, as a framework-agnostic HTML string.
|
|
2
|
-
// Render with tabs(), then wire behaviour once after mount with initTabs().
|
|
3
|
-
//
|
|
4
|
-
// root.innerHTML = tabs({
|
|
5
|
-
// name: 'account', active: 0, ariaLabel: 'Account sections',
|
|
6
|
-
// items: [
|
|
7
|
-
// { label: 'Overview', panel: '<p>…</p>' },
|
|
8
|
-
// { label: 'Activity', panel: '<p>…</p>' },
|
|
9
|
-
// { label: 'Settings', panel: '<p>…</p>' },
|
|
10
|
-
// ],
|
|
11
|
-
// });
|
|
12
|
-
// initTabs(root);
|
|
13
|
-
//
|
|
14
|
-
// Follows the WAI-ARIA tabs pattern: roving tabindex, ArrowLeft/Right + Home/End,
|
|
15
|
-
// aria-selected, and aria-controls / aria-labelledby wiring. `name` must be unique
|
|
16
|
-
// per tabs instance on a page (it seeds the tab/panel ids).
|
|
17
|
-
import { playEntrance } from '../motion.js';
|
|
18
|
-
import { esc } from '../html.js';
|
|
19
|
-
export function tabs({ items = [], active = 0, name = 'tabs', ariaLabel = 'Tabs', className = '' } = {}) {
|
|
20
|
-
const cls = ['ui-tabs', className].filter(Boolean).join(' ');
|
|
21
|
-
const list = items
|
|
22
|
-
.map((it, i) => {
|
|
23
|
-
const on = i === active;
|
|
24
|
-
return `<button type="button" class="ui-tabs__tab${on ? ' is-active' : ''}" role="tab"`
|
|
25
|
-
+ ` id="${esc(name)}-tab-${i}" aria-controls="${esc(name)}-panel-${i}"`
|
|
26
|
-
+ ` aria-selected="${on ? 'true' : 'false'}" tabindex="${on ? '0' : '-1'}">${it.label}</button>`;
|
|
27
|
-
})
|
|
28
|
-
.join('');
|
|
29
|
-
const panels = items
|
|
30
|
-
.map((it, i) => {
|
|
31
|
-
const on = i === active;
|
|
32
|
-
// tabindex="0" on the panel: the APG requires it when the panel holds no
|
|
33
|
-
// focusable content of its own, and most panels here are plain text. Without
|
|
34
|
-
// it a keyboard user reaches the tab strip and then cannot reach what it
|
|
35
|
-
// switched to — Tab jumps straight past the panel to whatever follows.
|
|
36
|
-
return `<div class="ui-tabs__panel" role="tabpanel" id="${esc(name)}-panel-${i}"`
|
|
37
|
-
+ ` aria-labelledby="${esc(name)}-tab-${i}" tabindex="0"${on ? '' : ' hidden'}>${it.panel || ''}</div>`;
|
|
38
|
-
})
|
|
39
|
-
.join('');
|
|
40
|
-
return `<div class="${esc(cls)}" data-tabs>`
|
|
41
|
-
+ `<div class="ui-tabs__list" role="tablist" aria-label="${esc(ariaLabel)}">${list}</div>`
|
|
42
|
-
+ `<div class="ui-tabs__panels">${panels}</div>`
|
|
43
|
-
+ `</div>`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Wire click + keyboard for every [data-tabs] under `root`. Idempotent-safe to
|
|
47
|
-
// call once after the markup mounts. No-op off-DOM (SSR / node --test).
|
|
48
|
-
export function initTabs(root) {
|
|
49
|
-
if (typeof document === 'undefined') return;
|
|
50
|
-
const scope = root || document;
|
|
51
|
-
scope.querySelectorAll('[data-tabs]').forEach((el) => {
|
|
52
|
-
const tabEls = Array.prototype.slice.call(el.querySelectorAll('[role="tab"]'));
|
|
53
|
-
const panelFor = (t) => el.querySelector('[id="' + t.getAttribute('aria-controls') + '"]');
|
|
54
|
-
const select = (i, focus) => {
|
|
55
|
-
tabEls.forEach((t, j) => {
|
|
56
|
-
const on = j === i;
|
|
57
|
-
t.classList.toggle('is-active', on);
|
|
58
|
-
t.setAttribute('aria-selected', on ? 'true' : 'false');
|
|
59
|
-
t.tabIndex = on ? 0 : -1;
|
|
60
|
-
const p = panelFor(t);
|
|
61
|
-
if (p) {
|
|
62
|
-
// Only the panel a switch reveals fades in; the one the page loaded with does not.
|
|
63
|
-
const appearing = on && p.hidden;
|
|
64
|
-
p.hidden = !on;
|
|
65
|
-
if (appearing) playEntrance(p);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
if (focus && tabEls[i]) tabEls[i].focus();
|
|
69
|
-
};
|
|
70
|
-
tabEls.forEach((t, i) => {
|
|
71
|
-
t.addEventListener('click', () => select(i));
|
|
72
|
-
t.addEventListener('keydown', (e) => {
|
|
73
|
-
let n = null;
|
|
74
|
-
if (e.key === 'ArrowRight') n = (i + 1) % tabEls.length;
|
|
75
|
-
else if (e.key === 'ArrowLeft') n = (i - 1 + tabEls.length) % tabEls.length;
|
|
76
|
-
else if (e.key === 'Home') n = 0;
|
|
77
|
-
else if (e.key === 'End') n = tabEls.length - 1;
|
|
78
|
-
if (n !== null) { e.preventDefault(); select(n, true); }
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
package/src/components/toasts.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// Toast stack controller — entrance/exit, auto-dismiss timers, swipe-to-dismiss.
|
|
2
|
-
//
|
|
3
|
-
// The visual markup comes from toast() in index.js; this wires behaviour onto a
|
|
4
|
-
// container of them, or lets you push new ones onto a live stack:
|
|
5
|
-
//
|
|
6
|
-
// import { toast } from '@apliteni/apliteni-ui';
|
|
7
|
-
// import { wireToastStack, pushToast } from '@apliteni/apliteni-ui/toasts';
|
|
8
|
-
// stack.innerHTML = toast({ variant: 'info', title: 'Saved', timer: 5 });
|
|
9
|
-
// wireToastStack(stack);
|
|
10
|
-
// pushToast(stack, { variant: 'success', title: 'Done', timer: 5 });
|
|
11
|
-
//
|
|
12
|
-
// The kit owns the animation + interaction; your app decides when to push and
|
|
13
|
-
// what each toast says. Reduced-motion is respected (no slide, instant remove).
|
|
14
|
-
import { toast } from './index.js';
|
|
15
|
-
|
|
16
|
-
const reduceMotion = () =>
|
|
17
|
-
typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
18
|
-
|
|
19
|
-
const resolve = (container) =>
|
|
20
|
-
(typeof container === 'string' ? document.querySelector(container) : container) || null;
|
|
21
|
-
|
|
22
|
-
// Slide-and-fade a toast out, then remove it. Idempotent.
|
|
23
|
-
export function dismissToast(el) {
|
|
24
|
-
if (!el || el.dataset.leaving) return;
|
|
25
|
-
el.dataset.leaving = '1';
|
|
26
|
-
const remove = () => el.remove();
|
|
27
|
-
if (reduceMotion()) return remove();
|
|
28
|
-
el.classList.add('is-leaving');
|
|
29
|
-
el.addEventListener('animationend', remove, { once: true });
|
|
30
|
-
setTimeout(remove, 260); // fallback if animationend never fires
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Wire one toast: close button, auto-dismiss timer (pauses on hover),
|
|
34
|
-
// swipe-to-dismiss via pointer drag.
|
|
35
|
-
function wireToast(el) {
|
|
36
|
-
if (el.dataset.wired) return;
|
|
37
|
-
el.dataset.wired = '1';
|
|
38
|
-
|
|
39
|
-
el.querySelector('.ui-toast__close')?.addEventListener('click', () => dismissToast(el));
|
|
40
|
-
|
|
41
|
-
const bar = el.querySelector('[data-toast-timer]');
|
|
42
|
-
if (bar) {
|
|
43
|
-
bar.classList.add('is-running');
|
|
44
|
-
const dur = parseFloat(getComputedStyle(el).getPropertyValue('--toast-dur')) || 5;
|
|
45
|
-
let remaining = dur * 1000;
|
|
46
|
-
let started = Date.now();
|
|
47
|
-
let timer = setTimeout(() => dismissToast(el), remaining);
|
|
48
|
-
// The line's own pause lives in the sheet, on :hover and :focus-within, so
|
|
49
|
-
// it covers a keyboard reader too. What is left here is the countdown that
|
|
50
|
-
// has to stop with it. This runs even under reduced motion, where the line
|
|
51
|
-
// is hidden but the reader still gets the same hold.
|
|
52
|
-
let held = false;
|
|
53
|
-
const hold = () => {
|
|
54
|
-
if (held) return;
|
|
55
|
-
held = true;
|
|
56
|
-
clearTimeout(timer);
|
|
57
|
-
const visualLeft = !reduceMotion()
|
|
58
|
-
? parseFloat(getComputedStyle(bar).transform.split(',')[0].slice(7))
|
|
59
|
-
: NaN;
|
|
60
|
-
remaining = Number.isFinite(visualLeft)
|
|
61
|
-
? dur * 1000 * visualLeft
|
|
62
|
-
: Math.max(0, remaining - (Date.now() - started));
|
|
63
|
-
};
|
|
64
|
-
const release = () => {
|
|
65
|
-
if (!held || el.matches(':hover, :focus-within')) return;
|
|
66
|
-
held = false;
|
|
67
|
-
started = Date.now();
|
|
68
|
-
timer = setTimeout(() => dismissToast(el), remaining);
|
|
69
|
-
};
|
|
70
|
-
el.addEventListener('mouseenter', hold);
|
|
71
|
-
el.addEventListener('mouseleave', release);
|
|
72
|
-
el.addEventListener('focusin', hold);
|
|
73
|
-
// At focusout the old target has already blurred and the new one has not
|
|
74
|
-
// focused yet, so :focus-within reads false even for a move from the close
|
|
75
|
-
// button to the action. relatedTarget is the only thing that knows.
|
|
76
|
-
el.addEventListener('focusout', (e) => { if (!el.contains(e.relatedTarget)) release(); });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Swipe-to-dismiss (ignore drags that start on a button).
|
|
80
|
-
let x0 = null;
|
|
81
|
-
el.addEventListener('pointerdown', (e) => {
|
|
82
|
-
if (e.target.closest('button')) return;
|
|
83
|
-
x0 = e.clientX; el.setPointerCapture(e.pointerId); el.style.transition = 'none';
|
|
84
|
-
});
|
|
85
|
-
el.addEventListener('pointermove', (e) => {
|
|
86
|
-
if (x0 == null) return;
|
|
87
|
-
const dx = e.clientX - x0;
|
|
88
|
-
el.style.transform = `translateX(${dx}px)`;
|
|
89
|
-
el.style.opacity = String(Math.max(0, 1 - Math.abs(dx) / 240));
|
|
90
|
-
});
|
|
91
|
-
const settle = (e) => {
|
|
92
|
-
if (x0 == null) return;
|
|
93
|
-
const dx = e.clientX - x0; x0 = null;
|
|
94
|
-
if (Math.abs(dx) > 90) return dismissToast(el);
|
|
95
|
-
el.style.transition = 'transform 0.18s ease, opacity 0.18s ease';
|
|
96
|
-
el.style.transform = ''; el.style.opacity = '';
|
|
97
|
-
};
|
|
98
|
-
el.addEventListener('pointerup', settle);
|
|
99
|
-
el.addEventListener('pointercancel', settle);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Wire every toast currently inside a container (string selector or element).
|
|
103
|
-
export function wireToastStack(container) {
|
|
104
|
-
const root = resolve(container);
|
|
105
|
-
if (!root) return null;
|
|
106
|
-
root.querySelectorAll('.ui-toast').forEach(wireToast);
|
|
107
|
-
return root;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Build a toast from opts, prepend it to a live stack (newest on top), wire it.
|
|
111
|
-
export function pushToast(container, opts = {}) {
|
|
112
|
-
const root = resolve(container);
|
|
113
|
-
if (!root) return null;
|
|
114
|
-
root.insertAdjacentHTML('afterbegin', toast(opts));
|
|
115
|
-
const el = root.firstElementChild;
|
|
116
|
-
wireToast(el);
|
|
117
|
-
return el;
|
|
118
|
-
}
|