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.
- package/README.md +24 -2
- package/dist/components/BottomNav.svelte +4 -0
- package/dist/components/Card.svelte +16 -1
- package/dist/components/Card.svelte.d.ts +6 -0
- package/dist/components/Icon.svelte +9 -61
- package/dist/components/Icon.svelte.d.ts +4 -47
- package/dist/components/Input.svelte +3 -0
- package/dist/components/Kbd.svelte +17 -1
- package/dist/components/Kbd.svelte.d.ts +9 -0
- package/dist/components/LogStream.svelte +2 -2
- package/dist/components/MetricTile.svelte +7 -3
- package/dist/components/SearchPalette.svelte +3 -0
- package/dist/components/ServiceCard.svelte +5 -2
- package/dist/components/ShortcutsHelp.svelte +2 -1
- package/dist/components/Sidebar.svelte +43 -1
- package/dist/components/Sidebar.svelte.d.ts +5 -0
- package/dist/components/Spinner.svelte +7 -34
- package/dist/components/Spinner.svelte.d.ts +2 -59
- package/dist/components/TierList.svelte +602 -0
- package/dist/components/TierList.svelte.d.ts +37 -0
- package/dist/components/Toaster.svelte +1 -0
- package/dist/components/Topbar.svelte +18 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +1 -0
- package/dist/icons.d.ts +55 -0
- package/dist/icons.js +57 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -2
- package/dist/spinner-frames.d.ts +59 -0
- package/dist/spinner-frames.js +15 -0
- package/dist/theme.css +25 -27
- package/dist/tierlist-core.d.ts +87 -0
- package/dist/tierlist-core.js +183 -0
- package/dist/toast-core.d.ts +61 -0
- package/dist/toast-core.js +73 -0
- package/dist/toast.svelte.d.ts +2 -33
- package/dist/toast.svelte.js +3 -66
- package/dist/tokens.css +25 -0
- package/dist/vanilla/accordion.d.ts +2 -0
- package/dist/vanilla/accordion.js +57 -0
- package/dist/vanilla/delegate.d.ts +16 -0
- package/dist/vanilla/delegate.js +33 -0
- package/dist/vanilla/fields.d.ts +6 -0
- package/dist/vanilla/fields.js +89 -0
- package/dist/vanilla/icons.d.ts +17 -0
- package/dist/vanilla/icons.js +78 -0
- package/dist/vanilla/index.d.ts +17 -0
- package/dist/vanilla/index.js +63 -0
- package/dist/vanilla/menu.d.ts +3 -0
- package/dist/vanilla/menu.js +133 -0
- package/dist/vanilla/modal.d.ts +3 -0
- package/dist/vanilla/modal.js +42 -0
- package/dist/vanilla/segmented.d.ts +2 -0
- package/dist/vanilla/segmented.js +62 -0
- package/dist/vanilla/switch.d.ts +2 -0
- package/dist/vanilla/switch.js +22 -0
- package/dist/vanilla/tierlist.d.ts +8 -0
- package/dist/vanilla/tierlist.js +304 -0
- package/dist/vanilla/toast.d.ts +37 -0
- package/dist/vanilla/toast.js +197 -0
- package/dist/vanilla/tooltip.d.ts +3 -0
- package/dist/vanilla/tooltip.js +54 -0
- package/dist/vanilla.css +4648 -0
- package/package.json +17 -5
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TierList core (DS-0159) — the framework-free half of the component: the data model, the pure
|
|
3
|
+
* move/keyboard/hit-test math and the live-region wording. `TierList.svelte` and the plain-HTML
|
|
4
|
+
* behaviour (`vanilla/tierlist.ts`) both run on this module, so the two paths cannot drift.
|
|
5
|
+
* No DOM, no Svelte, no runes.
|
|
6
|
+
*/
|
|
7
|
+
/** Zone key of the unranked tray. Never a valid tier id. */
|
|
8
|
+
export const TRAY = '__tray__';
|
|
9
|
+
/** The classic five rows. */
|
|
10
|
+
export const DEFAULT_TIERS = Object.freeze([
|
|
11
|
+
{ id: 'S', label: 'S' },
|
|
12
|
+
{ id: 'A', label: 'A' },
|
|
13
|
+
{ id: 'B', label: 'B' },
|
|
14
|
+
{ id: 'C', label: 'C' },
|
|
15
|
+
{ id: 'D', label: 'D' },
|
|
16
|
+
]);
|
|
17
|
+
/**
|
|
18
|
+
* Default row accents by index: palette slots, never literals (DS-0125). The first five mirror
|
|
19
|
+
* the reference app (accent → cyan → yellow → muted → red); longer lists cycle through the rest.
|
|
20
|
+
*/
|
|
21
|
+
export const TIER_COLOR_VARS = Object.freeze([
|
|
22
|
+
'--ss-accent',
|
|
23
|
+
'--ss-cyan',
|
|
24
|
+
'--ss-yellow',
|
|
25
|
+
'--ss-fg-muted',
|
|
26
|
+
'--ss-red',
|
|
27
|
+
'--ss-blue',
|
|
28
|
+
'--ss-magenta',
|
|
29
|
+
'--ss-green',
|
|
30
|
+
]);
|
|
31
|
+
/** The CSS colour a row uses: its own `color`, else the slot for its index. */
|
|
32
|
+
export function tierColor(tier, index) {
|
|
33
|
+
return tier.color ?? `var(${TIER_COLOR_VARS[index % TIER_COLOR_VARS.length]})`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build the zone map from props. Placement ids that name no item are dropped, an item placed
|
|
37
|
+
* in two tiers keeps its first placement, and everything unplaced goes to the tray — in the
|
|
38
|
+
* order the previous zones had it (so a tray reorder survives a re-render), then `items` order.
|
|
39
|
+
*/
|
|
40
|
+
export function buildZones(tiers, items, placements, previous) {
|
|
41
|
+
const known = new Set(items.map((i) => i.id));
|
|
42
|
+
const placed = new Set();
|
|
43
|
+
const zones = {};
|
|
44
|
+
for (const tier of tiers) {
|
|
45
|
+
const ids = [];
|
|
46
|
+
for (const id of placements?.[tier.id] ?? []) {
|
|
47
|
+
if (!known.has(id) || placed.has(id))
|
|
48
|
+
continue;
|
|
49
|
+
placed.add(id);
|
|
50
|
+
ids.push(id);
|
|
51
|
+
}
|
|
52
|
+
zones[tier.id] = ids;
|
|
53
|
+
}
|
|
54
|
+
const tray = [];
|
|
55
|
+
for (const id of previous?.[TRAY] ?? []) {
|
|
56
|
+
if (known.has(id) && !placed.has(id)) {
|
|
57
|
+
placed.add(id);
|
|
58
|
+
tray.push(id);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
if (!placed.has(item.id)) {
|
|
63
|
+
placed.add(item.id);
|
|
64
|
+
tray.push(item.id);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
zones[TRAY] = tray;
|
|
68
|
+
return zones;
|
|
69
|
+
}
|
|
70
|
+
/** Where an item currently sits. `null` when it is in no zone. */
|
|
71
|
+
export function locate(zones, itemId) {
|
|
72
|
+
for (const zone of Object.keys(zones)) {
|
|
73
|
+
const index = zones[zone].indexOf(itemId);
|
|
74
|
+
if (index >= 0)
|
|
75
|
+
return { zone, index };
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Move an item to `toZone` at `toIndex` (clamped to the zone's length, counted after the item
|
|
81
|
+
* has been lifted out). Returns the same object when nothing changes, so callers can compare
|
|
82
|
+
* by identity.
|
|
83
|
+
*/
|
|
84
|
+
export function moveItem(zones, itemId, toZone, toIndex) {
|
|
85
|
+
const from = locate(zones, itemId);
|
|
86
|
+
if (!from || !(toZone in zones))
|
|
87
|
+
return zones;
|
|
88
|
+
const lifted = zones[from.zone].filter((id) => id !== itemId);
|
|
89
|
+
const target = from.zone === toZone ? lifted : zones[toZone].slice();
|
|
90
|
+
const index = Math.max(0, Math.min(toIndex, target.length));
|
|
91
|
+
if (from.zone === toZone && index === from.index)
|
|
92
|
+
return zones;
|
|
93
|
+
target.splice(index, 0, itemId);
|
|
94
|
+
return {
|
|
95
|
+
...zones,
|
|
96
|
+
[from.zone]: from.zone === toZone ? target : lifted,
|
|
97
|
+
[toZone]: target,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** The public placements: tiers only, in the given tier order; the tray is implicit. */
|
|
101
|
+
export function placementsOf(zones, tiers) {
|
|
102
|
+
const out = {};
|
|
103
|
+
for (const tier of tiers)
|
|
104
|
+
out[tier.id] = (zones[tier.id] ?? []).slice();
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
export function zonesEqual(a, b) {
|
|
108
|
+
const ka = Object.keys(a);
|
|
109
|
+
const kb = Object.keys(b);
|
|
110
|
+
if (ka.length !== kb.length)
|
|
111
|
+
return false;
|
|
112
|
+
for (const k of ka) {
|
|
113
|
+
const x = a[k];
|
|
114
|
+
const y = b[k];
|
|
115
|
+
if (!y || x.length !== y.length)
|
|
116
|
+
return false;
|
|
117
|
+
for (let i = 0; i < x.length; i++)
|
|
118
|
+
if (x[i] !== y[i])
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Keyboard sorting target: left/right step within the zone (wrapping is deliberately off —
|
|
125
|
+
* the edges are meaningful), home/end jump within it, up/down move to the neighbouring zone
|
|
126
|
+
* keeping the same position (clamped). `zoneOrder` is the visual order, tray last.
|
|
127
|
+
* Returns `null` when the move is impossible (already at the edge).
|
|
128
|
+
*/
|
|
129
|
+
export function keyboardTarget(zones, zoneOrder, itemId, move) {
|
|
130
|
+
const at = locate(zones, itemId);
|
|
131
|
+
if (!at)
|
|
132
|
+
return null;
|
|
133
|
+
const len = zones[at.zone].length;
|
|
134
|
+
const zi = zoneOrder.indexOf(at.zone);
|
|
135
|
+
switch (move) {
|
|
136
|
+
case 'left':
|
|
137
|
+
return at.index > 0 ? { zone: at.zone, index: at.index - 1 } : null;
|
|
138
|
+
case 'right':
|
|
139
|
+
return at.index < len - 1 ? { zone: at.zone, index: at.index + 1 } : null;
|
|
140
|
+
case 'home':
|
|
141
|
+
return at.index > 0 ? { zone: at.zone, index: 0 } : null;
|
|
142
|
+
case 'end':
|
|
143
|
+
return at.index < len - 1 ? { zone: at.zone, index: len - 1 } : null;
|
|
144
|
+
case 'up':
|
|
145
|
+
case 'down': {
|
|
146
|
+
const next = zoneOrder[zi + (move === 'up' ? -1 : 1)];
|
|
147
|
+
if (next === undefined)
|
|
148
|
+
return null;
|
|
149
|
+
return { zone: next, index: Math.min(at.index, zones[next].length) };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Insertion index for a pointer at (x, y) among wrapped tiles: every tile whose row ends above
|
|
155
|
+
* the pointer counts as "before", and on the pointer's own row every tile whose centre is left
|
|
156
|
+
* of it. The dragged tile's own box must not be in `cells`.
|
|
157
|
+
*/
|
|
158
|
+
export function insertionIndex(cells, x, y) {
|
|
159
|
+
let index = 0;
|
|
160
|
+
for (const c of cells) {
|
|
161
|
+
if (c.bottom <= y)
|
|
162
|
+
index++;
|
|
163
|
+
else if (c.top <= y && (c.left + c.right) / 2 <= x)
|
|
164
|
+
index++;
|
|
165
|
+
}
|
|
166
|
+
return index;
|
|
167
|
+
}
|
|
168
|
+
/** Copy for the polite live region — one sentence per step, position 1-based. */
|
|
169
|
+
export function announceText(kind, d) {
|
|
170
|
+
const where = `${d.zone}, position ${d.index + 1} of ${d.count}`;
|
|
171
|
+
switch (kind) {
|
|
172
|
+
case 'grab':
|
|
173
|
+
return `Picked up ${d.label}, ${where}. Use the arrow keys to move it, Space to drop, Escape to cancel.`;
|
|
174
|
+
case 'move':
|
|
175
|
+
return `${d.label} moved to ${where}.`;
|
|
176
|
+
case 'drop':
|
|
177
|
+
return `Dropped ${d.label} in ${where}.`;
|
|
178
|
+
case 'cancel':
|
|
179
|
+
return `Cancelled. ${d.label} returned to ${where}.`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Screen-reader instructions attached to every tile. */
|
|
183
|
+
export const TILE_INSTRUCTIONS = 'Press Space to pick up the tile, then the arrow keys to move it between positions and tiers, Space again to drop it, or Escape to cancel.';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-free core of the toast system (DS-0148): types, per-kind defaults and the
|
|
3
|
+
* pause/resume timer. Shared by the Svelte-runes store (`toast.svelte.ts`) and the vanilla
|
|
4
|
+
* DOM store (`vanilla/toast.ts`) so the two can never disagree on semantics.
|
|
5
|
+
*/
|
|
6
|
+
export type ToastKind = 'success' | 'error' | 'info' | 'loading';
|
|
7
|
+
/** An optional inline action rendered as a button inside the toast. */
|
|
8
|
+
export interface ToastAction {
|
|
9
|
+
label: string;
|
|
10
|
+
/**
|
|
11
|
+
* Invoked on click. Return `false` to keep the toast open (e.g. an async
|
|
12
|
+
* action that wants to swap itself for a result toast); any other return
|
|
13
|
+
* value dismisses the toast.
|
|
14
|
+
*/
|
|
15
|
+
onClick: () => void | false;
|
|
16
|
+
}
|
|
17
|
+
export interface Toast {
|
|
18
|
+
id: number;
|
|
19
|
+
kind: ToastKind;
|
|
20
|
+
message: string;
|
|
21
|
+
/** Effective auto-dismiss duration in ms; <= 0 / Infinity means sticky. */
|
|
22
|
+
timeout: number;
|
|
23
|
+
action?: ToastAction;
|
|
24
|
+
}
|
|
25
|
+
/** Fields a caller may set when pushing; the store fills in the rest. */
|
|
26
|
+
export interface ToastOptions {
|
|
27
|
+
timeout?: number;
|
|
28
|
+
action?: ToastAction;
|
|
29
|
+
}
|
|
30
|
+
/** A subset of a toast a caller may patch in-place via `update`. */
|
|
31
|
+
export type ToastPatch = Partial<Pick<Toast, 'kind' | 'message' | 'timeout' | 'action'>>;
|
|
32
|
+
/** Options for `toast.promise`. */
|
|
33
|
+
export interface PromiseMessages<T> {
|
|
34
|
+
loading: string;
|
|
35
|
+
success: string | ((value: T) => string);
|
|
36
|
+
error: string | ((err: unknown) => string);
|
|
37
|
+
}
|
|
38
|
+
/** Default auto-dismiss per kind. Errors linger; loading is sticky. */
|
|
39
|
+
export declare const DEFAULT_TIMEOUT: Record<ToastKind, number>;
|
|
40
|
+
/** Toasts carrying an action default to sticky so the action stays reachable. */
|
|
41
|
+
export declare const ACTION_TIMEOUT = 0;
|
|
42
|
+
/** Treat <= 0 or non-finite as sticky (never auto-dismiss). */
|
|
43
|
+
export declare function isSticky(timeout: number): boolean;
|
|
44
|
+
/** Effective timeout for a push: explicit > action-sticky > per-kind default. */
|
|
45
|
+
export declare function resolveTimeout(kind: ToastKind, opts?: ToastOptions): number;
|
|
46
|
+
/** Back-compat: the old push signature accepted a bare `timeout` number. */
|
|
47
|
+
export declare function normalizeOptions(opts?: ToastOptions | number): ToastOptions | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Per-toast auto-dismiss controller. Tracks remaining time so the timer can be
|
|
50
|
+
* paused (on hover/focus) and resumed without losing or resetting the budget.
|
|
51
|
+
*/
|
|
52
|
+
export declare class ToastTimer {
|
|
53
|
+
#private;
|
|
54
|
+
constructor(timeout: number, fire: () => void);
|
|
55
|
+
get sticky(): boolean;
|
|
56
|
+
resume(): void;
|
|
57
|
+
pause(): void;
|
|
58
|
+
/** Re-arm with a fresh budget (used by `update`). */
|
|
59
|
+
reset(timeout: number): void;
|
|
60
|
+
cancel(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-free core of the toast system (DS-0148): types, per-kind defaults and the
|
|
3
|
+
* pause/resume timer. Shared by the Svelte-runes store (`toast.svelte.ts`) and the vanilla
|
|
4
|
+
* DOM store (`vanilla/toast.ts`) so the two can never disagree on semantics.
|
|
5
|
+
*/
|
|
6
|
+
/** Default auto-dismiss per kind. Errors linger; loading is sticky. */
|
|
7
|
+
export const DEFAULT_TIMEOUT = {
|
|
8
|
+
success: 4000,
|
|
9
|
+
info: 4000,
|
|
10
|
+
error: 7000,
|
|
11
|
+
loading: 0, // sticky until updated/dismissed
|
|
12
|
+
};
|
|
13
|
+
/** Toasts carrying an action default to sticky so the action stays reachable. */
|
|
14
|
+
export const ACTION_TIMEOUT = 0;
|
|
15
|
+
/** Treat <= 0 or non-finite as sticky (never auto-dismiss). */
|
|
16
|
+
export function isSticky(timeout) {
|
|
17
|
+
return !(timeout > 0) || !Number.isFinite(timeout);
|
|
18
|
+
}
|
|
19
|
+
/** Effective timeout for a push: explicit > action-sticky > per-kind default. */
|
|
20
|
+
export function resolveTimeout(kind, opts) {
|
|
21
|
+
if (opts?.timeout !== undefined)
|
|
22
|
+
return opts.timeout;
|
|
23
|
+
if (opts?.action)
|
|
24
|
+
return ACTION_TIMEOUT;
|
|
25
|
+
return DEFAULT_TIMEOUT[kind];
|
|
26
|
+
}
|
|
27
|
+
/** Back-compat: the old push signature accepted a bare `timeout` number. */
|
|
28
|
+
export function normalizeOptions(opts) {
|
|
29
|
+
return typeof opts === 'number' ? { timeout: opts } : opts;
|
|
30
|
+
}
|
|
31
|
+
const hasWindow = typeof window !== 'undefined';
|
|
32
|
+
/**
|
|
33
|
+
* Per-toast auto-dismiss controller. Tracks remaining time so the timer can be
|
|
34
|
+
* paused (on hover/focus) and resumed without losing or resetting the budget.
|
|
35
|
+
*/
|
|
36
|
+
export class ToastTimer {
|
|
37
|
+
#fire;
|
|
38
|
+
#remaining;
|
|
39
|
+
#startedAt = 0;
|
|
40
|
+
#handle = null;
|
|
41
|
+
constructor(timeout, fire) {
|
|
42
|
+
this.#fire = fire;
|
|
43
|
+
this.#remaining = timeout;
|
|
44
|
+
this.resume();
|
|
45
|
+
}
|
|
46
|
+
get sticky() {
|
|
47
|
+
return isSticky(this.#remaining);
|
|
48
|
+
}
|
|
49
|
+
resume() {
|
|
50
|
+
if (this.#handle !== null || this.sticky || !hasWindow)
|
|
51
|
+
return;
|
|
52
|
+
this.#startedAt = Date.now();
|
|
53
|
+
this.#handle = setTimeout(this.#fire, this.#remaining);
|
|
54
|
+
}
|
|
55
|
+
pause() {
|
|
56
|
+
if (this.#handle === null)
|
|
57
|
+
return;
|
|
58
|
+
clearTimeout(this.#handle);
|
|
59
|
+
this.#handle = null;
|
|
60
|
+
this.#remaining -= Date.now() - this.#startedAt;
|
|
61
|
+
}
|
|
62
|
+
/** Re-arm with a fresh budget (used by `update`). */
|
|
63
|
+
reset(timeout) {
|
|
64
|
+
this.cancel();
|
|
65
|
+
this.#remaining = timeout;
|
|
66
|
+
this.resume();
|
|
67
|
+
}
|
|
68
|
+
cancel() {
|
|
69
|
+
if (this.#handle !== null)
|
|
70
|
+
clearTimeout(this.#handle);
|
|
71
|
+
this.#handle = null;
|
|
72
|
+
}
|
|
73
|
+
}
|
package/dist/toast.svelte.d.ts
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface ToastAction {
|
|
4
|
-
label: string;
|
|
5
|
-
/**
|
|
6
|
-
* Invoked on click. Return `false` to keep the toast open (e.g. an async
|
|
7
|
-
* action that wants to swap itself for a result toast); any other return
|
|
8
|
-
* value dismisses the toast.
|
|
9
|
-
*/
|
|
10
|
-
onClick: () => void | false;
|
|
11
|
-
}
|
|
12
|
-
export interface Toast {
|
|
13
|
-
id: number;
|
|
14
|
-
kind: ToastKind;
|
|
15
|
-
message: string;
|
|
16
|
-
/** Effective auto-dismiss duration in ms; <= 0 / Infinity means sticky. */
|
|
17
|
-
timeout: number;
|
|
18
|
-
action?: ToastAction;
|
|
19
|
-
}
|
|
20
|
-
/** Fields a caller may set when pushing; the store fills in the rest. */
|
|
21
|
-
export interface ToastOptions {
|
|
22
|
-
timeout?: number;
|
|
23
|
-
action?: ToastAction;
|
|
24
|
-
}
|
|
25
|
-
/** A subset of a toast a caller may patch in-place via `update`. */
|
|
26
|
-
export type ToastPatch = Partial<Pick<Toast, 'kind' | 'message' | 'timeout' | 'action'>>;
|
|
1
|
+
import { type Toast, type ToastKind, type ToastOptions, type ToastPatch, type PromiseMessages } from './toast-core.js';
|
|
2
|
+
export type { Toast, ToastKind, ToastAction, ToastOptions, ToastPatch, PromiseMessages, } from './toast-core.js';
|
|
27
3
|
/**
|
|
28
4
|
* Module-singleton toast store (Svelte 5 runes). One instance is shared by
|
|
29
5
|
* every consumer of the package, so `toast.success(...)` from anywhere shows
|
|
@@ -49,12 +25,6 @@ declare class ToastStore {
|
|
|
49
25
|
clear(): void;
|
|
50
26
|
}
|
|
51
27
|
export declare const toasts: ToastStore;
|
|
52
|
-
/** Options for `toast.promise`. */
|
|
53
|
-
export interface PromiseMessages<T> {
|
|
54
|
-
loading: string;
|
|
55
|
-
success: string | ((value: T) => string);
|
|
56
|
-
error: string | ((err: unknown) => string);
|
|
57
|
-
}
|
|
58
28
|
export declare const toast: {
|
|
59
29
|
success: (message: string, opts?: ToastOptions | number) => number;
|
|
60
30
|
error: (message: string, opts?: ToastOptions | number) => number;
|
|
@@ -66,4 +36,3 @@ export declare const toast: {
|
|
|
66
36
|
*/
|
|
67
37
|
promise<T>(p: Promise<T>, messages: PromiseMessages<T>): Promise<T>;
|
|
68
38
|
};
|
|
69
|
-
export {};
|
package/dist/toast.svelte.js
CHANGED
|
@@ -1,59 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const DEFAULT_TIMEOUT = {
|
|
3
|
-
success: 4000,
|
|
4
|
-
info: 4000,
|
|
5
|
-
error: 7000,
|
|
6
|
-
loading: 0, // sticky until updated/dismissed
|
|
7
|
-
};
|
|
8
|
-
/** Toasts carrying an action default to sticky so the action stays reachable. */
|
|
9
|
-
const ACTION_TIMEOUT = 0;
|
|
10
|
-
/** Treat <= 0 or non-finite as sticky (never auto-dismiss). */
|
|
11
|
-
function isSticky(timeout) {
|
|
12
|
-
return !(timeout > 0) || !Number.isFinite(timeout);
|
|
13
|
-
}
|
|
14
|
-
const hasWindow = typeof window !== 'undefined';
|
|
15
|
-
/**
|
|
16
|
-
* Per-toast auto-dismiss controller. Tracks remaining time so the timer can be
|
|
17
|
-
* paused (on hover/focus) and resumed without losing or resetting the budget.
|
|
18
|
-
*/
|
|
19
|
-
class ToastTimer {
|
|
20
|
-
#fire;
|
|
21
|
-
#remaining;
|
|
22
|
-
#startedAt = 0;
|
|
23
|
-
#handle = null;
|
|
24
|
-
constructor(timeout, fire) {
|
|
25
|
-
this.#fire = fire;
|
|
26
|
-
this.#remaining = timeout;
|
|
27
|
-
this.resume();
|
|
28
|
-
}
|
|
29
|
-
get sticky() {
|
|
30
|
-
return isSticky(this.#remaining);
|
|
31
|
-
}
|
|
32
|
-
resume() {
|
|
33
|
-
if (this.#handle !== null || this.sticky || !hasWindow)
|
|
34
|
-
return;
|
|
35
|
-
this.#startedAt = Date.now();
|
|
36
|
-
this.#handle = setTimeout(this.#fire, this.#remaining);
|
|
37
|
-
}
|
|
38
|
-
pause() {
|
|
39
|
-
if (this.#handle === null)
|
|
40
|
-
return;
|
|
41
|
-
clearTimeout(this.#handle);
|
|
42
|
-
this.#handle = null;
|
|
43
|
-
this.#remaining -= Date.now() - this.#startedAt;
|
|
44
|
-
}
|
|
45
|
-
/** Re-arm with a fresh budget (used by `update`). */
|
|
46
|
-
reset(timeout) {
|
|
47
|
-
this.cancel();
|
|
48
|
-
this.#remaining = timeout;
|
|
49
|
-
this.resume();
|
|
50
|
-
}
|
|
51
|
-
cancel() {
|
|
52
|
-
if (this.#handle !== null)
|
|
53
|
-
clearTimeout(this.#handle);
|
|
54
|
-
this.#handle = null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
import { DEFAULT_TIMEOUT, isSticky, resolveTimeout, normalizeOptions, ToastTimer, } from './toast-core.js';
|
|
57
2
|
/**
|
|
58
3
|
* Module-singleton toast store (Svelte 5 runes). One instance is shared by
|
|
59
4
|
* every consumer of the package, so `toast.success(...)` from anywhere shows
|
|
@@ -70,22 +15,14 @@ class ToastStore {
|
|
|
70
15
|
#seq = 0;
|
|
71
16
|
#queue = [];
|
|
72
17
|
#timers = new Map();
|
|
73
|
-
#resolveTimeout(kind, opts) {
|
|
74
|
-
if (opts?.timeout !== undefined)
|
|
75
|
-
return opts.timeout;
|
|
76
|
-
if (opts?.action)
|
|
77
|
-
return ACTION_TIMEOUT;
|
|
78
|
-
return DEFAULT_TIMEOUT[kind];
|
|
79
|
-
}
|
|
80
18
|
push(kind, message, opts) {
|
|
81
|
-
|
|
82
|
-
const o = typeof opts === 'number' ? { timeout: opts } : opts;
|
|
19
|
+
const o = normalizeOptions(opts);
|
|
83
20
|
const id = ++this.#seq;
|
|
84
21
|
const toast = {
|
|
85
22
|
id,
|
|
86
23
|
kind,
|
|
87
24
|
message,
|
|
88
|
-
timeout:
|
|
25
|
+
timeout: resolveTimeout(kind, o),
|
|
89
26
|
action: o?.action,
|
|
90
27
|
};
|
|
91
28
|
if (this.items.length < this.max) {
|
package/dist/tokens.css
CHANGED
|
@@ -595,3 +595,28 @@
|
|
|
595
595
|
[data-size-variant=lg] {
|
|
596
596
|
--ss-spinner-font: 22px;
|
|
597
597
|
}
|
|
598
|
+
|
|
599
|
+
:root,
|
|
600
|
+
[data-size-variant=md] {
|
|
601
|
+
--ss-tier-tile-w: 108px;
|
|
602
|
+
--ss-tier-tile-h: 108px;
|
|
603
|
+
--ss-tier-label-w: 44px;
|
|
604
|
+
--ss-tier-label-font: var(--ss-ui-lg);
|
|
605
|
+
--ss-tier-gap: 6px;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
[data-size-variant=sm] {
|
|
609
|
+
--ss-tier-tile-w: 84px;
|
|
610
|
+
--ss-tier-tile-h: 84px;
|
|
611
|
+
--ss-tier-label-w: 36px;
|
|
612
|
+
--ss-tier-label-font: var(--ss-ui-md);
|
|
613
|
+
--ss-tier-gap: var(--ss-s-1);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
[data-size-variant=lg] {
|
|
617
|
+
--ss-tier-tile-w: 132px;
|
|
618
|
+
--ss-tier-tile-h: 132px;
|
|
619
|
+
--ss-tier-label-w: 56px;
|
|
620
|
+
--ss-tier-label-font: var(--ss-size-h3);
|
|
621
|
+
--ss-tier-gap: var(--ss-s-2);
|
|
622
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accordion (DS-0148) — toggles `hidden` on the panel referenced by each header's
|
|
3
|
+
* `aria-controls`, mirroring Accordion.svelte: single-open by default (opening one closes the
|
|
4
|
+
* others), `data-ss-multiple` on the root allows several, Arrow/Home/End rove between headers.
|
|
5
|
+
* Emits `ss:change` on the root with `{ value }` (open ids: string | string[] | undefined).
|
|
6
|
+
*/
|
|
7
|
+
import { on, emit, wrap, all, byId } from './delegate.js';
|
|
8
|
+
const HEAD = '.ss-accordion .head[aria-controls]';
|
|
9
|
+
function setOpen(head, open) {
|
|
10
|
+
head.setAttribute('aria-expanded', String(open));
|
|
11
|
+
head.closest('.item')?.classList.toggle('open', open);
|
|
12
|
+
const panel = byId(head.getAttribute('aria-controls'));
|
|
13
|
+
if (panel)
|
|
14
|
+
panel.hidden = !open;
|
|
15
|
+
}
|
|
16
|
+
export function toggleAccordion(head) {
|
|
17
|
+
if (head.getAttribute('aria-disabled') === 'true')
|
|
18
|
+
return;
|
|
19
|
+
const root = head.closest('.ss-accordion');
|
|
20
|
+
if (!root)
|
|
21
|
+
return;
|
|
22
|
+
const multiple = root.hasAttribute('data-ss-multiple');
|
|
23
|
+
const wasOpen = head.getAttribute('aria-expanded') === 'true';
|
|
24
|
+
const heads = all(root, '.head[aria-controls]').filter((h) => h.closest('.ss-accordion') === root);
|
|
25
|
+
if (!wasOpen && !multiple)
|
|
26
|
+
for (const h of heads)
|
|
27
|
+
if (h !== head)
|
|
28
|
+
setOpen(h, false);
|
|
29
|
+
setOpen(head, !wasOpen);
|
|
30
|
+
const openIds = heads
|
|
31
|
+
.filter((h) => h.getAttribute('aria-expanded') === 'true')
|
|
32
|
+
.map((h) => h.getAttribute('aria-controls'));
|
|
33
|
+
emit(root, 'ss:change', { value: multiple ? openIds : openIds[0] });
|
|
34
|
+
}
|
|
35
|
+
export function installAccordion() {
|
|
36
|
+
on('click', HEAD, (head) => toggleAccordion(head));
|
|
37
|
+
on('keydown', HEAD, (head, e) => {
|
|
38
|
+
const root = head.closest('.ss-accordion');
|
|
39
|
+
if (!root)
|
|
40
|
+
return;
|
|
41
|
+
const heads = all(root, '.head[aria-controls]').filter((h) => h.closest('.ss-accordion') === root);
|
|
42
|
+
const i = heads.indexOf(head);
|
|
43
|
+
let target = -1;
|
|
44
|
+
if (e.key === 'ArrowDown')
|
|
45
|
+
target = wrap(i + 1, heads.length);
|
|
46
|
+
else if (e.key === 'ArrowUp')
|
|
47
|
+
target = wrap(i - 1, heads.length);
|
|
48
|
+
else if (e.key === 'Home')
|
|
49
|
+
target = 0;
|
|
50
|
+
else if (e.key === 'End')
|
|
51
|
+
target = heads.length - 1;
|
|
52
|
+
if (target < 0)
|
|
53
|
+
return;
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
heads[target]?.focus();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny document-level event delegation (DS-0148). Every vanilla behaviour listens once on
|
|
3
|
+
* `document` and resolves its target with `closest()`, so markup injected after load keeps
|
|
4
|
+
* working without a MutationObserver.
|
|
5
|
+
*/
|
|
6
|
+
type Listener<K extends keyof DocumentEventMap> = (target: HTMLElement, e: DocumentEventMap[K]) => void;
|
|
7
|
+
export declare function on<K extends keyof DocumentEventMap>(type: K, selector: string, handler: Listener<K>, options?: AddEventListenerOptions): void;
|
|
8
|
+
/** Dispatch a bubbling `ss:*` CustomEvent so consumer code can react to a behaviour. */
|
|
9
|
+
export declare function emit<T>(el: Element, name: `ss:${string}`, detail: T): void;
|
|
10
|
+
/** Wrap-around modulo for roving focus. */
|
|
11
|
+
export declare function wrap(i: number, n: number): number;
|
|
12
|
+
/** All matching descendants as a real array. */
|
|
13
|
+
export declare function all<E extends Element = HTMLElement>(root: ParentNode, selector: string): E[];
|
|
14
|
+
/** Resolve an `aria-controls` / `#id` reference, preferring the nearest root. */
|
|
15
|
+
export declare function byId(id: string | null): HTMLElement | null;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny document-level event delegation (DS-0148). Every vanilla behaviour listens once on
|
|
3
|
+
* `document` and resolves its target with `closest()`, so markup injected after load keeps
|
|
4
|
+
* working without a MutationObserver.
|
|
5
|
+
*/
|
|
6
|
+
export function on(type, selector, handler, options) {
|
|
7
|
+
document.addEventListener(type, (e) => {
|
|
8
|
+
const t = e.target;
|
|
9
|
+
if (!(t instanceof Element))
|
|
10
|
+
return;
|
|
11
|
+
const target = t.closest(selector);
|
|
12
|
+
if (target)
|
|
13
|
+
handler(target, e);
|
|
14
|
+
}, options);
|
|
15
|
+
}
|
|
16
|
+
/** Dispatch a bubbling `ss:*` CustomEvent so consumer code can react to a behaviour. */
|
|
17
|
+
export function emit(el, name, detail) {
|
|
18
|
+
el.dispatchEvent(new CustomEvent(name, { detail, bubbles: true }));
|
|
19
|
+
}
|
|
20
|
+
/** Wrap-around modulo for roving focus. */
|
|
21
|
+
export function wrap(i, n) {
|
|
22
|
+
return ((i % n) + n) % n;
|
|
23
|
+
}
|
|
24
|
+
/** All matching descendants as a real array. */
|
|
25
|
+
export function all(root, selector) {
|
|
26
|
+
return Array.from(root.querySelectorAll(selector));
|
|
27
|
+
}
|
|
28
|
+
/** Resolve an `aria-controls` / `#id` reference, preferring the nearest root. */
|
|
29
|
+
export function byId(id) {
|
|
30
|
+
if (!id)
|
|
31
|
+
return null;
|
|
32
|
+
return document.getElementById(id.startsWith('#') ? id.slice(1) : id);
|
|
33
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function clearInput(btn: HTMLElement): void;
|
|
2
|
+
export declare function nudgeNumber(btn: HTMLButtonElement): void;
|
|
3
|
+
export declare const supportsFieldSizing: boolean;
|
|
4
|
+
export declare function autosize(el: HTMLTextAreaElement): void;
|
|
5
|
+
export declare function mountFields(root: ParentNode): void;
|
|
6
|
+
export declare function installFields(): void;
|