dssoca 0.16.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +24 -2
  2. package/dist/components/BottomNav.svelte +4 -0
  3. package/dist/components/Card.svelte +16 -1
  4. package/dist/components/Card.svelte.d.ts +6 -0
  5. package/dist/components/Icon.svelte +9 -61
  6. package/dist/components/Icon.svelte.d.ts +4 -47
  7. package/dist/components/Input.svelte +3 -0
  8. package/dist/components/Kbd.svelte +17 -1
  9. package/dist/components/Kbd.svelte.d.ts +9 -0
  10. package/dist/components/LogStream.svelte +2 -2
  11. package/dist/components/MetricTile.svelte +7 -3
  12. package/dist/components/SearchPalette.svelte +3 -0
  13. package/dist/components/ServiceCard.svelte +5 -2
  14. package/dist/components/ShortcutsHelp.svelte +2 -1
  15. package/dist/components/Sidebar.svelte +43 -1
  16. package/dist/components/Sidebar.svelte.d.ts +5 -0
  17. package/dist/components/Spinner.svelte +7 -34
  18. package/dist/components/Spinner.svelte.d.ts +2 -59
  19. package/dist/components/TierList.svelte +602 -0
  20. package/dist/components/TierList.svelte.d.ts +37 -0
  21. package/dist/components/Toaster.svelte +1 -0
  22. package/dist/components/Topbar.svelte +18 -0
  23. package/dist/dssoca.config.d.ts +1 -1
  24. package/dist/dssoca.config.js +1 -0
  25. package/dist/icons.d.ts +55 -0
  26. package/dist/icons.js +57 -0
  27. package/dist/index.d.ts +6 -3
  28. package/dist/index.js +7 -2
  29. package/dist/spinner-frames.d.ts +59 -0
  30. package/dist/spinner-frames.js +15 -0
  31. package/dist/theme.css +25 -27
  32. package/dist/tierlist-core.d.ts +87 -0
  33. package/dist/tierlist-core.js +183 -0
  34. package/dist/toast-core.d.ts +61 -0
  35. package/dist/toast-core.js +73 -0
  36. package/dist/toast.svelte.d.ts +2 -33
  37. package/dist/toast.svelte.js +3 -66
  38. package/dist/tokens.css +25 -0
  39. package/dist/vanilla/accordion.d.ts +2 -0
  40. package/dist/vanilla/accordion.js +57 -0
  41. package/dist/vanilla/delegate.d.ts +16 -0
  42. package/dist/vanilla/delegate.js +33 -0
  43. package/dist/vanilla/fields.d.ts +6 -0
  44. package/dist/vanilla/fields.js +89 -0
  45. package/dist/vanilla/icons.d.ts +17 -0
  46. package/dist/vanilla/icons.js +78 -0
  47. package/dist/vanilla/index.d.ts +17 -0
  48. package/dist/vanilla/index.js +63 -0
  49. package/dist/vanilla/menu.d.ts +3 -0
  50. package/dist/vanilla/menu.js +133 -0
  51. package/dist/vanilla/modal.d.ts +3 -0
  52. package/dist/vanilla/modal.js +42 -0
  53. package/dist/vanilla/segmented.d.ts +2 -0
  54. package/dist/vanilla/segmented.js +62 -0
  55. package/dist/vanilla/switch.d.ts +2 -0
  56. package/dist/vanilla/switch.js +22 -0
  57. package/dist/vanilla/tierlist.d.ts +8 -0
  58. package/dist/vanilla/tierlist.js +304 -0
  59. package/dist/vanilla/toast.d.ts +37 -0
  60. package/dist/vanilla/toast.js +197 -0
  61. package/dist/vanilla/tooltip.d.ts +3 -0
  62. package/dist/vanilla/tooltip.js +54 -0
  63. package/dist/vanilla.css +4648 -0
  64. package/package.json +17 -5
@@ -0,0 +1,304 @@
1
+ /**
2
+ * TierList (DS-0159) — plain-HTML behaviour for the markup `TierList.svelte` renders: pointer
3
+ * drag between/within rows (Pointer Events, so touch works) and the keyboard path (Space picks
4
+ * a tile up, arrows move it, Space drops, Escape cancels) with a polite live region. The move
5
+ * math and the wording come from `../tierlist-core.js`, shared with the Svelte component.
6
+ * Emits `ss:change` on the root with `{ placements }` (tier id → item ids; the tray is
7
+ * implicit). `data-ss-readonly` on the root makes the list inert.
8
+ */
9
+ import { on, emit, all } from './delegate.js';
10
+ import { TRAY, announceText, insertionIndex, keyboardTarget, } from '../tierlist-core.js';
11
+ const ROOT = '.ss-tierlist';
12
+ const TILE = `${ROOT} .tile[data-item]`;
13
+ const DRAG_THRESHOLD = 4;
14
+ function rootOf(el) {
15
+ return el.closest(ROOT);
16
+ }
17
+ function zonesOf(root) {
18
+ return all(root, '[data-zone]').filter((z) => rootOf(z) === root);
19
+ }
20
+ function zoneKey(zone) {
21
+ return zone.hasAttribute('data-tray') ? TRAY : zone.dataset.zone;
22
+ }
23
+ function zoneByKey(root, key) {
24
+ return zonesOf(root).find((z) => zoneKey(z) === key);
25
+ }
26
+ function zoneLabel(zone) {
27
+ return zone.getAttribute('aria-label') ?? zone.dataset.zoneLabel ?? zoneKey(zone);
28
+ }
29
+ function cellsOf(zone) {
30
+ return all(zone, ':scope > .cell');
31
+ }
32
+ /** The zone map as the DOM currently has it. */
33
+ export function readZones(root) {
34
+ const zones = {};
35
+ for (const zone of zonesOf(root)) {
36
+ zones[zoneKey(zone)] = cellsOf(zone).map((c) => c.querySelector('.tile[data-item]')?.dataset.item ?? '');
37
+ }
38
+ return zones;
39
+ }
40
+ /** Public placements read from the DOM: every non-tray zone, in DOM order. */
41
+ export function readPlacements(root) {
42
+ const out = {};
43
+ for (const zone of zonesOf(root)) {
44
+ const key = zoneKey(zone);
45
+ if (key !== TRAY)
46
+ out[key] = readZones(root)[key];
47
+ }
48
+ return out;
49
+ }
50
+ function isReadonly(root) {
51
+ return root.hasAttribute('data-ss-readonly');
52
+ }
53
+ function announce(root, text) {
54
+ const live = root.querySelector('.live');
55
+ if (live)
56
+ live.textContent = text;
57
+ }
58
+ // Re-inserting a focused node blurs it (browsers run the focus fixup on removal); while a
59
+ // keyboard move is in flight that blur must not read as "the user left the tile".
60
+ let moving = false;
61
+ /** Physically move a tile's cell to `zone` at `index` (clamped; the cell may already be there). */
62
+ function placeCell(root, cell, zone, index) {
63
+ const target = zoneByKey(root, zone);
64
+ if (!target)
65
+ return;
66
+ const siblings = cellsOf(target).filter((c) => c !== cell);
67
+ const before = siblings[Math.max(0, Math.min(index, siblings.length))] ?? null;
68
+ const was = moving;
69
+ moving = true;
70
+ try {
71
+ target.insertBefore(cell, before);
72
+ }
73
+ finally {
74
+ moving = was;
75
+ }
76
+ }
77
+ function describe(root, tile) {
78
+ const cell = tile.closest('.cell');
79
+ const zone = cell.parentElement;
80
+ const cells = cellsOf(zone);
81
+ return {
82
+ label: tile.getAttribute('aria-label') ?? tile.textContent?.trim() ?? '',
83
+ zone: zoneLabel(zone),
84
+ index: cells.indexOf(cell),
85
+ count: cells.length,
86
+ };
87
+ }
88
+ function change(root) {
89
+ emit(root, 'ss:change', { placements: readPlacements(root) });
90
+ }
91
+ const grabs = new WeakMap();
92
+ const KEY_MOVES = {
93
+ ArrowLeft: 'left',
94
+ ArrowRight: 'right',
95
+ ArrowUp: 'up',
96
+ ArrowDown: 'down',
97
+ Home: 'home',
98
+ End: 'end',
99
+ };
100
+ function setGrabbed(root, tile) {
101
+ for (const t of all(root, '.tile[aria-pressed="true"]')) {
102
+ t.setAttribute('aria-pressed', 'false');
103
+ t.closest('.cell')?.classList.remove('grabbed');
104
+ }
105
+ root.classList.toggle('sorting', Boolean(tile));
106
+ if (tile) {
107
+ tile.setAttribute('aria-pressed', 'true');
108
+ tile.closest('.cell')?.classList.add('grabbed');
109
+ }
110
+ }
111
+ /** Pick a tile up (or drop it when it is already grabbed). */
112
+ export function toggleGrab(tile) {
113
+ const root = rootOf(tile);
114
+ if (!root || isReadonly(root))
115
+ return;
116
+ const grab = grabs.get(root);
117
+ if (grab?.tile === tile) {
118
+ grabs.delete(root);
119
+ setGrabbed(root, null);
120
+ announce(root, announceText('drop', describe(root, tile)));
121
+ change(root);
122
+ return;
123
+ }
124
+ const d = describe(root, tile);
125
+ const cell = tile.closest('.cell');
126
+ grabs.set(root, { tile, zone: zoneKey(cell.parentElement), index: d.index });
127
+ setGrabbed(root, tile);
128
+ announce(root, announceText('grab', d));
129
+ }
130
+ /** `focusBack`: Escape keeps the user on the tile; a cancel caused by focus leaving must not pull it back. */
131
+ function cancelGrab(root, focusBack) {
132
+ const grab = grabs.get(root);
133
+ if (!grab)
134
+ return;
135
+ grabs.delete(root);
136
+ const cell = grab.tile.closest('.cell');
137
+ moving = true;
138
+ try {
139
+ placeCell(root, cell, grab.zone, grab.index);
140
+ setGrabbed(root, null);
141
+ if (focusBack)
142
+ grab.tile.focus();
143
+ }
144
+ finally {
145
+ moving = false;
146
+ }
147
+ announce(root, announceText('cancel', describe(root, grab.tile)));
148
+ }
149
+ function keyMove(root, tile, move) {
150
+ const zones = readZones(root);
151
+ const order = zonesOf(root).map(zoneKey);
152
+ const target = keyboardTarget(zones, order, tile.dataset.item, move);
153
+ if (!target)
154
+ return;
155
+ const cell = tile.closest('.cell');
156
+ moving = true;
157
+ try {
158
+ placeCell(root, cell, target.zone, target.index);
159
+ tile.focus();
160
+ }
161
+ finally {
162
+ moving = false;
163
+ }
164
+ announce(root, announceText('move', describe(root, tile)));
165
+ }
166
+ let drag = null;
167
+ function zoneAt(root, x, y) {
168
+ for (const el of document.elementsFromPoint(x, y)) {
169
+ const zone = el.closest('[data-zone]');
170
+ if (zone && rootOf(zone) === root)
171
+ return zone;
172
+ }
173
+ return null;
174
+ }
175
+ function startDrag(d) {
176
+ d.dragging = true;
177
+ const rect = d.tile.getBoundingClientRect();
178
+ d.dx = d.startX - rect.left;
179
+ d.dy = d.startY - rect.top;
180
+ const ghost = d.tile.cloneNode(true);
181
+ ghost.classList.add('ghost');
182
+ ghost.removeAttribute('id');
183
+ ghost.setAttribute('aria-hidden', 'true');
184
+ ghost.style.width = `${rect.width}px`;
185
+ ghost.style.height = `${rect.height}px`;
186
+ d.root.appendChild(ghost);
187
+ d.ghost = ghost;
188
+ d.cell.classList.add('shadow');
189
+ d.root.classList.add('dragging');
190
+ }
191
+ function moveDrag(d, x, y) {
192
+ if (d.ghost)
193
+ d.ghost.style.transform = `translate(${x - d.dx}px, ${y - d.dy}px)`;
194
+ const zone = zoneAt(d.root, x, y);
195
+ for (const z of zonesOf(d.root))
196
+ z.classList.toggle('target', z === zone);
197
+ if (!zone)
198
+ return;
199
+ const boxes = cellsOf(zone)
200
+ .filter((c) => c !== d.cell)
201
+ .map((c) => c.getBoundingClientRect());
202
+ placeCell(d.root, d.cell, zoneKey(zone), insertionIndex(boxes, x, y));
203
+ }
204
+ function endDrag(d, cancelled) {
205
+ d.ghost?.remove();
206
+ d.cell.classList.remove('shadow');
207
+ d.root.classList.remove('dragging');
208
+ for (const z of zonesOf(d.root))
209
+ z.classList.remove('target');
210
+ if (cancelled) {
211
+ placeCell(d.root, d.cell, d.zone, d.index);
212
+ return;
213
+ }
214
+ const now = describe(d.root, d.tile);
215
+ if (zoneKey(d.cell.parentElement) !== d.zone || now.index !== d.index) {
216
+ announce(d.root, announceText('drop', now));
217
+ change(d.root);
218
+ }
219
+ }
220
+ export function installTierlist() {
221
+ on('keydown', TILE, (tile, e) => {
222
+ const root = rootOf(tile);
223
+ if (!root || isReadonly(root))
224
+ return;
225
+ const grab = grabs.get(root);
226
+ if (e.key === ' ' || (e.key === 'Enter' && !tile.hasAttribute('data-ss-activate'))) {
227
+ e.preventDefault();
228
+ toggleGrab(tile);
229
+ return;
230
+ }
231
+ if (e.key === 'Escape' && grab?.tile === tile) {
232
+ e.preventDefault();
233
+ cancelGrab(root, true);
234
+ return;
235
+ }
236
+ const move = KEY_MOVES[e.key];
237
+ if (move && grab?.tile === tile) {
238
+ e.preventDefault();
239
+ keyMove(root, tile, move);
240
+ }
241
+ });
242
+ // Cancel when focus has really left a grabbed tile — checked a beat later, because moving
243
+ // the node (a row change re-inserts it) blurs it in some browsers before it is re-focused.
244
+ on('focusout', TILE, (tile) => {
245
+ if (moving)
246
+ return;
247
+ const root = rootOf(tile);
248
+ if (!root || grabs.get(root)?.tile !== tile)
249
+ return;
250
+ setTimeout(() => {
251
+ if (grabs.get(root)?.tile === tile && document.activeElement !== tile)
252
+ cancelGrab(root, false);
253
+ }, 0);
254
+ });
255
+ on('pointerdown', TILE, (tile, e) => {
256
+ const root = rootOf(tile);
257
+ if (!root || isReadonly(root) || e.button !== 0 || grabs.has(root))
258
+ return;
259
+ const cell = tile.closest('.cell');
260
+ const zone = cell.parentElement;
261
+ drag = {
262
+ root,
263
+ tile,
264
+ cell,
265
+ startX: e.clientX,
266
+ startY: e.clientY,
267
+ dragging: false,
268
+ ghost: null,
269
+ dx: 0,
270
+ dy: 0,
271
+ zone: zoneKey(zone),
272
+ index: cellsOf(zone).indexOf(cell),
273
+ };
274
+ });
275
+ // Document-level, not on the tile: re-inserting the cell while it moves between rows
276
+ // releases any pointer capture, so the rest of the drag must not depend on the tile.
277
+ document.addEventListener('pointermove', (e) => {
278
+ if (!drag)
279
+ return;
280
+ if (!drag.dragging) {
281
+ if (Math.hypot(e.clientX - drag.startX, e.clientY - drag.startY) < DRAG_THRESHOLD)
282
+ return;
283
+ startDrag(drag);
284
+ }
285
+ e.preventDefault();
286
+ moveDrag(drag, e.clientX, e.clientY);
287
+ });
288
+ document.addEventListener('pointerup', () => {
289
+ if (!drag)
290
+ return;
291
+ const d = drag;
292
+ drag = null;
293
+ if (d.dragging)
294
+ endDrag(d, false);
295
+ });
296
+ document.addEventListener('pointercancel', () => {
297
+ if (!drag)
298
+ return;
299
+ const d = drag;
300
+ drag = null;
301
+ if (d.dragging)
302
+ endDrag(d, true);
303
+ });
304
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Toasts (DS-0148) — framework-free port of `toast.svelte.ts` + Toaster.svelte that renders
3
+ * the exact Toaster DOM directly. Same API names as the Svelte one:
4
+ *
5
+ * toast.success('saved') toast.error('nope', { action: { label, onClick } })
6
+ * toast.loading('…') toast.promise(p, { loading, success, error })
7
+ * toasts.dismiss(id) / clear() / update(id, patch) / max
8
+ *
9
+ * The stack lives in the first `.ss-toaster` on the page (author it to choose `data-position`
10
+ * / size) or in one auto-created under `<body>`. Hover/focus pause the timer, Escape and the
11
+ * × button dismiss, exit runs the `.leaving` CSS animation from vanilla.css. Swipe-to-dismiss
12
+ * is not ported.
13
+ */
14
+ import { type Toast, type ToastKind, type ToastOptions, type ToastPatch, type PromiseMessages } from '../toast-core.js';
15
+ export type { Toast, ToastKind, ToastOptions, ToastPatch, ToastAction, PromiseMessages, } from '../toast-core.js';
16
+ declare class VanillaToastStore {
17
+ #private;
18
+ max: number;
19
+ /** Visible toasts (read-only snapshot). */
20
+ get items(): Toast[];
21
+ get container(): HTMLElement;
22
+ push(kind: ToastKind, message: string, opts?: ToastOptions | number): number;
23
+ update(id: number, patch: ToastPatch): boolean;
24
+ pause(id: number): void;
25
+ resume(id: number): void;
26
+ dismiss(id: number): void;
27
+ clear(): void;
28
+ }
29
+ export declare const toasts: VanillaToastStore;
30
+ export declare const toast: {
31
+ success: (message: string, opts?: ToastOptions | number) => number;
32
+ error: (message: string, opts?: ToastOptions | number) => number;
33
+ info: (message: string, opts?: ToastOptions | number) => number;
34
+ loading: (message: string, opts?: ToastOptions | number) => number;
35
+ /** Push a sticky `loading` toast, then flip it to success/error when the promise settles. */
36
+ promise<T>(p: Promise<T>, messages: PromiseMessages<T>): Promise<T>;
37
+ };
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Toasts (DS-0148) — framework-free port of `toast.svelte.ts` + Toaster.svelte that renders
3
+ * the exact Toaster DOM directly. Same API names as the Svelte one:
4
+ *
5
+ * toast.success('saved') toast.error('nope', { action: { label, onClick } })
6
+ * toast.loading('…') toast.promise(p, { loading, success, error })
7
+ * toasts.dismiss(id) / clear() / update(id, patch) / max
8
+ *
9
+ * The stack lives in the first `.ss-toaster` on the page (author it to choose `data-position`
10
+ * / size) or in one auto-created under `<body>`. Hover/focus pause the timer, Escape and the
11
+ * × button dismiss, exit runs the `.leaving` CSS animation from vanilla.css. Swipe-to-dismiss
12
+ * is not ported.
13
+ */
14
+ import { DEFAULT_TIMEOUT, isSticky, resolveTimeout, normalizeOptions, ToastTimer, } from '../toast-core.js';
15
+ const GLYPH = { success: '✓', error: '✕', info: 'i', loading: '' };
16
+ const LEAVE_FALLBACK_MS = 400;
17
+ const reduceMotion = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
18
+ class VanillaToastStore {
19
+ max = 3;
20
+ #seq = 0;
21
+ #live = [];
22
+ #queue = [];
23
+ #container = null;
24
+ /** Visible toasts (read-only snapshot). */
25
+ get items() {
26
+ return this.#live.map((l) => l.toast);
27
+ }
28
+ get container() {
29
+ if (this.#container?.isConnected)
30
+ return this.#container;
31
+ let el = document.querySelector('.ss-toaster');
32
+ if (!el) {
33
+ el = document.createElement('div');
34
+ el.className = 'ss-toaster';
35
+ el.setAttribute('role', 'region');
36
+ el.setAttribute('aria-label', 'Notifications');
37
+ el.dataset.position = 'top-right';
38
+ document.body.appendChild(el);
39
+ }
40
+ this.#container = el;
41
+ return el;
42
+ }
43
+ push(kind, message, opts) {
44
+ const o = normalizeOptions(opts);
45
+ const id = ++this.#seq;
46
+ const t = { id, kind, message, timeout: resolveTimeout(kind, o), action: o?.action };
47
+ if (this.#live.length < this.max)
48
+ this.#show(t);
49
+ else
50
+ this.#queue.push(t);
51
+ return id;
52
+ }
53
+ #show(t) {
54
+ const el = document.createElement('div');
55
+ el.tabIndex = -1;
56
+ this.#render(el, t);
57
+ el.addEventListener('pointerenter', () => this.pause(t.id));
58
+ el.addEventListener('pointerleave', () => this.resume(t.id));
59
+ el.addEventListener('focusin', () => this.pause(t.id));
60
+ el.addEventListener('focusout', () => this.resume(t.id));
61
+ el.addEventListener('keydown', (e) => {
62
+ if (e.key === 'Escape') {
63
+ e.stopPropagation();
64
+ this.dismiss(t.id);
65
+ }
66
+ });
67
+ el.addEventListener('click', (e) => {
68
+ const btn = e.target.closest('button');
69
+ if (!btn)
70
+ return;
71
+ if (btn.classList.contains('x'))
72
+ this.dismiss(t.id);
73
+ else if (btn.classList.contains('action')) {
74
+ const keep = this.#find(t.id)?.toast.action?.onClick() === false;
75
+ if (!keep)
76
+ this.dismiss(t.id);
77
+ }
78
+ });
79
+ this.container.appendChild(el);
80
+ const live = { toast: t, el, timer: null };
81
+ this.#live.push(live);
82
+ this.#arm(live);
83
+ }
84
+ #render(el, t) {
85
+ el.className = `ss-toast ${t.kind}`;
86
+ el.setAttribute('role', t.kind === 'error' ? 'alert' : 'status');
87
+ el.setAttribute('aria-live', t.kind === 'error' ? 'assertive' : 'polite');
88
+ const ic = t.kind === 'loading'
89
+ ? `<span class="ic spinner${reduceMotion() ? ' still' : ''}" aria-hidden="true"></span>`
90
+ : `<span class="ic" aria-hidden="true">${GLYPH[t.kind]}</span>`;
91
+ const action = t.action
92
+ ? `<button class="action" type="button">${escapeHtml(t.action.label)}</button>`
93
+ : '';
94
+ el.innerHTML =
95
+ `${ic}<span class="msg">${escapeHtml(t.message)}</span>${action}` +
96
+ `<button class="x" type="button" aria-label="Dismiss">×</button>`;
97
+ }
98
+ #find(id) {
99
+ return this.#live.find((l) => l.toast.id === id);
100
+ }
101
+ #arm(live) {
102
+ live.timer?.cancel();
103
+ live.timer = isSticky(live.toast.timeout)
104
+ ? null
105
+ : new ToastTimer(live.toast.timeout, () => this.dismiss(live.toast.id));
106
+ }
107
+ update(id, patch) {
108
+ const live = this.#find(id);
109
+ const target = live?.toast ?? this.#queue.find((t) => t.id === id);
110
+ if (!target)
111
+ return false;
112
+ if (patch.kind !== undefined)
113
+ target.kind = patch.kind;
114
+ if (patch.message !== undefined)
115
+ target.message = patch.message;
116
+ if ('action' in patch)
117
+ target.action = patch.action;
118
+ if (patch.timeout !== undefined)
119
+ target.timeout = patch.timeout;
120
+ else if (patch.kind !== undefined)
121
+ target.timeout = DEFAULT_TIMEOUT[patch.kind];
122
+ if (live) {
123
+ this.#render(live.el, live.toast);
124
+ this.#arm(live);
125
+ }
126
+ return true;
127
+ }
128
+ pause(id) {
129
+ this.#find(id)?.timer?.pause();
130
+ }
131
+ resume(id) {
132
+ this.#find(id)?.timer?.resume();
133
+ }
134
+ dismiss(id) {
135
+ const i = this.#live.findIndex((l) => l.toast.id === id);
136
+ if (i !== -1) {
137
+ const [live] = this.#live.splice(i, 1);
138
+ live.timer?.cancel();
139
+ this.#leave(live.el);
140
+ this.#promote();
141
+ return;
142
+ }
143
+ const qi = this.#queue.findIndex((t) => t.id === id);
144
+ if (qi !== -1)
145
+ this.#queue.splice(qi, 1);
146
+ }
147
+ #leave(el) {
148
+ if (reduceMotion()) {
149
+ el.remove();
150
+ return;
151
+ }
152
+ let done = false;
153
+ const finish = () => {
154
+ if (done)
155
+ return;
156
+ done = true;
157
+ el.remove();
158
+ };
159
+ el.classList.add('leaving');
160
+ el.addEventListener('animationend', finish, { once: true });
161
+ setTimeout(finish, LEAVE_FALLBACK_MS);
162
+ }
163
+ #promote() {
164
+ while (this.#live.length < this.max && this.#queue.length > 0)
165
+ this.#show(this.#queue.shift());
166
+ }
167
+ clear() {
168
+ for (const l of this.#live) {
169
+ l.timer?.cancel();
170
+ l.el.remove();
171
+ }
172
+ this.#live = [];
173
+ this.#queue = [];
174
+ }
175
+ }
176
+ function escapeHtml(s) {
177
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
178
+ }
179
+ export const toasts = new VanillaToastStore();
180
+ export const toast = {
181
+ success: (message, opts) => toasts.push('success', message, opts),
182
+ error: (message, opts) => toasts.push('error', message, opts),
183
+ info: (message, opts) => toasts.push('info', message, opts),
184
+ loading: (message, opts) => toasts.push('loading', message, opts),
185
+ /** Push a sticky `loading` toast, then flip it to success/error when the promise settles. */
186
+ promise(p, messages) {
187
+ const id = toasts.push('loading', messages.loading, { timeout: 0 });
188
+ p.then((value) => {
189
+ const msg = typeof messages.success === 'function' ? messages.success(value) : messages.success;
190
+ toasts.update(id, { kind: 'success', message: msg });
191
+ }, (err) => {
192
+ const msg = typeof messages.error === 'function' ? messages.error(err) : messages.error;
193
+ toasts.update(id, { kind: 'error', message: msg });
194
+ });
195
+ return p;
196
+ },
197
+ };
@@ -0,0 +1,3 @@
1
+ export declare function showTooltip(root: HTMLElement): void;
2
+ export declare function hideTooltip(root: HTMLElement): void;
3
+ export declare function installTooltip(): void;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Tooltip (DS-0148) — hover/focus reveal over Tooltip.svelte's DOM:
3
+ * `.ss-tooltip[data-placement] > .trigger + .tip[role=tooltip]`. Basic four-way placement
4
+ * only: the pre-rendered `data-placement` is honoured as-is (no collision engine). Escape
5
+ * hides. While open the wrapper carries `aria-describedby` → the tip (an id is generated when
6
+ * the markup has none).
7
+ */
8
+ import { on } from './delegate.js';
9
+ const ROOT = '.ss-tooltip';
10
+ let seq = 0;
11
+ function tipOf(root) {
12
+ return root.querySelector(':scope > .tip');
13
+ }
14
+ export function showTooltip(root) {
15
+ const tip = tipOf(root);
16
+ if (!tip)
17
+ return;
18
+ if (!tip.id)
19
+ tip.id = `ss-tip-${++seq}`;
20
+ tip.hidden = false;
21
+ tip.classList.add('open');
22
+ root.setAttribute('aria-describedby', tip.id);
23
+ }
24
+ export function hideTooltip(root) {
25
+ const tip = tipOf(root);
26
+ if (!tip)
27
+ return;
28
+ tip.hidden = true;
29
+ tip.classList.remove('open');
30
+ root.removeAttribute('aria-describedby');
31
+ }
32
+ export function installTooltip() {
33
+ // mouseenter/leave don't bubble; mouseover/out do — filter by relatedTarget.
34
+ on('mouseover', ROOT, (root, e) => {
35
+ const from = e.relatedTarget;
36
+ if (!from || !root.contains(from))
37
+ showTooltip(root);
38
+ });
39
+ on('mouseout', ROOT, (root, e) => {
40
+ const to = e.relatedTarget;
41
+ if (!to || !root.contains(to))
42
+ hideTooltip(root);
43
+ });
44
+ on('focusin', ROOT, (root) => showTooltip(root));
45
+ on('focusout', ROOT, (root, e) => {
46
+ const to = e.relatedTarget;
47
+ if (!to || !root.contains(to))
48
+ hideTooltip(root);
49
+ });
50
+ on('keydown', ROOT, (root, e) => {
51
+ if (e.key === 'Escape')
52
+ hideTooltip(root);
53
+ });
54
+ }