dssoca 0.15.0 → 0.17.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 +19 -0
- package/dist/components/Icon.svelte +9 -61
- package/dist/components/Icon.svelte.d.ts +4 -47
- package/dist/components/LogStream.svelte +2 -2
- package/dist/components/MetricTile.svelte +2 -2
- package/dist/components/ServiceCard.svelte +2 -2
- package/dist/components/Spinner.svelte +7 -34
- package/dist/components/Spinner.svelte.d.ts +2 -59
- package/dist/components/Tooltip.svelte +151 -15
- package/dist/components/Tooltip.svelte.d.ts +11 -1
- package/dist/icons.d.ts +54 -0
- package/dist/icons.js +56 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -2
- package/dist/spinner-frames.d.ts +59 -0
- package/dist/spinner-frames.js +15 -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/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 +16 -0
- package/dist/vanilla/index.js +60 -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/toast.d.ts +37 -0
- package/dist/vanilla/toast.js +196 -0
- package/dist/vanilla/tooltip.d.ts +3 -0
- package/dist/vanilla/tooltip.js +54 -0
- package/dist/vanilla.css +4433 -0
- package/package.json +14 -5
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icon glyph table + runtime registry (DS-0148).
|
|
3
|
+
*
|
|
4
|
+
* Lives outside `Icon.svelte` so framework-free consumers (`dssoca/vanilla.js`) and node
|
|
5
|
+
* scripts can share the exact same paths as the Svelte component. `Icon.svelte` re-exports
|
|
6
|
+
* everything here, so existing imports from the component path keep working.
|
|
7
|
+
*/
|
|
8
|
+
/** Curated glyph set. `target`'s centre dot is a filled circle in the *outline*
|
|
9
|
+
* variant — handled by the `variant` switch in markup, not a per-glyph fill hack. */
|
|
10
|
+
declare const BUILTIN_PATHS: {
|
|
11
|
+
readonly grid: "<rect x=\"3\" y=\"3\" width=\"7\" height=\"7\"/><rect x=\"14\" y=\"3\" width=\"7\" height=\"7\"/><rect x=\"3\" y=\"14\" width=\"7\" height=\"7\"/><rect x=\"14\" y=\"14\" width=\"7\" height=\"7\"/>";
|
|
12
|
+
readonly activity: "<path d=\"M3 12h4l3-8 4 16 3-8h4\"/>";
|
|
13
|
+
readonly database: "<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\"/><path d=\"M3 9h18M8 4v5\"/>";
|
|
14
|
+
readonly logs: "<path d=\"M4 6h16M4 12h16M4 18h10\"/>";
|
|
15
|
+
readonly terminal: "<rect x=\"3\" y=\"5\" width=\"18\" height=\"14\"/><path d=\"M3 9h18M7 14h4\"/>";
|
|
16
|
+
readonly settings: "<circle cx=\"12\" cy=\"12\" r=\"3\"/><path d=\"M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M4.9 19.1L7 17M17 7l2.1-2.1\"/>";
|
|
17
|
+
readonly user: "<circle cx=\"12\" cy=\"8\" r=\"4\"/><path d=\"M4 21c0-4 4-7 8-7s8 3 8 7\"/>";
|
|
18
|
+
readonly arrow: "<path d=\"M5 12h14M13 5l7 7-7 7\"/>";
|
|
19
|
+
readonly chevron: "<path d=\"M8 10l4 4 4-4\"/>";
|
|
20
|
+
readonly external: "<path d=\"M7 17L17 7M9 7h8v8\"/>";
|
|
21
|
+
readonly film: "<rect x=\"3\" y=\"4\" width=\"18\" height=\"16\"/><path d=\"M3 8h4M3 16h4M17 8h4M17 16h4M3 12h18\"/>";
|
|
22
|
+
readonly note: "<rect x=\"4\" y=\"3\" width=\"16\" height=\"18\"/><path d=\"M8 8h8M8 12h8M8 16h6\"/>";
|
|
23
|
+
readonly book: "<path d=\"M6 4h11a1 1 0 011 1v15H7a1 1 0 01-1-1z\"/><path d=\"M17 20a2 2 0 002-2V6a2 2 0 00-2-2\"/><path d=\"M9 8h5\"/>";
|
|
24
|
+
readonly check: "<path d=\"M5 12l4 4L19 6\"/>";
|
|
25
|
+
readonly cup: "<path d=\"M4 8h12v6a4 4 0 01-4 4H8a4 4 0 01-4-4z\"/><path d=\"M16 10h2a2 2 0 010 4h-2M6 4v2M10 4v2M14 4v2\"/>";
|
|
26
|
+
readonly wallet: "<rect x=\"3\" y=\"6\" width=\"18\" height=\"14\"/><path d=\"M3 10h18M17 14h2\"/>";
|
|
27
|
+
readonly target: "<circle cx=\"12\" cy=\"12\" r=\"9\"/><circle cx=\"12\" cy=\"12\" r=\"5\"/><circle cx=\"12\" cy=\"12\" r=\"1.5\" class=\"ss-icon-dot\"/>";
|
|
28
|
+
readonly spinner: "<path d=\"M12 3a9 9 0 1 0 9 9\" stroke-linecap=\"round\"/>";
|
|
29
|
+
readonly home: "<path d=\"M4 11l8-8 8 8\"/><path d=\"M6 9v12h12V9\"/><path d=\"M10 21v-6h4v6\"/>";
|
|
30
|
+
readonly briefcase: "<rect x=\"3\" y=\"7\" width=\"18\" height=\"13\"/><path d=\"M9 7V4h6v3M3 12h18\"/>";
|
|
31
|
+
readonly folder: "<path d=\"M3 5h7l2 3h9v13H3z\"/><path d=\"M3 8h9\"/>";
|
|
32
|
+
readonly github: "<path d=\"M7 3h10l2 2v6l-2 3h-4l1 2v5h-4v-5l1-2H7l-2-3V5l2-2z\"/><path d=\"M9 8h1M14 8h1\"/>";
|
|
33
|
+
readonly linkedin: "<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\"/><path d=\"M8 16v-5M8 8v.01M12 16v-5h2l2 2v3\"/>";
|
|
34
|
+
readonly language: "<circle cx=\"12\" cy=\"12\" r=\"9\"/><path d=\"M3 12h18M12 3L8 12l4 9M12 3l4 9-4 9\"/>";
|
|
35
|
+
readonly 'color-swatch': "<rect x=\"3\" y=\"3\" width=\"8\" height=\"18\"/><path d=\"M7 17v.01\"/><path d=\"M11 19l8-8 2 2-8 8\"/><path d=\"M13 21h8\"/>";
|
|
36
|
+
};
|
|
37
|
+
export type IconName = keyof typeof BUILTIN_PATHS;
|
|
38
|
+
/**
|
|
39
|
+
* The curated built-in glyphs plus any runtime-registered ones.
|
|
40
|
+
* (`PATHS` is kept as the public name for backward compatibility.)
|
|
41
|
+
*/
|
|
42
|
+
export declare const PATHS: Record<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* Register (or override) a glyph at runtime so `<Icon name="foo" />` resolves
|
|
45
|
+
* raw SVG inner markup that isn't part of the curated {@link IconName} union.
|
|
46
|
+
* The markup is rendered verbatim inside the icon's `<svg viewBox="0 0 24 24">`.
|
|
47
|
+
*
|
|
48
|
+
* registerIcon('heart', '<path d="M12 21 4 13a5 5 0 0 1 7-7l1 1 1-1a5 5 0 0 1 7 7z"/>')
|
|
49
|
+
* <Icon name={'heart' as IconName} />
|
|
50
|
+
*/
|
|
51
|
+
export declare function registerIcon(name: string, paths: string): void;
|
|
52
|
+
/** Look a glyph up; built-ins first, then runtime registrations. */
|
|
53
|
+
export declare function resolveIcon(name: string): string | undefined;
|
|
54
|
+
export {};
|
package/dist/icons.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icon glyph table + runtime registry (DS-0148).
|
|
3
|
+
*
|
|
4
|
+
* Lives outside `Icon.svelte` so framework-free consumers (`dssoca/vanilla.js`) and node
|
|
5
|
+
* scripts can share the exact same paths as the Svelte component. `Icon.svelte` re-exports
|
|
6
|
+
* everything here, so existing imports from the component path keep working.
|
|
7
|
+
*/
|
|
8
|
+
/** Curated glyph set. `target`'s centre dot is a filled circle in the *outline*
|
|
9
|
+
* variant — handled by the `variant` switch in markup, not a per-glyph fill hack. */
|
|
10
|
+
const BUILTIN_PATHS = {
|
|
11
|
+
grid: '<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/>',
|
|
12
|
+
activity: '<path d="M3 12h4l3-8 4 16 3-8h4"/>',
|
|
13
|
+
database: '<rect x="3" y="4" width="18" height="16"/><path d="M3 9h18M8 4v5"/>',
|
|
14
|
+
logs: '<path d="M4 6h16M4 12h16M4 18h10"/>',
|
|
15
|
+
terminal: '<rect x="3" y="5" width="18" height="14"/><path d="M3 9h18M7 14h4"/>',
|
|
16
|
+
settings: '<circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M4.9 19.1L7 17M17 7l2.1-2.1"/>',
|
|
17
|
+
user: '<circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-7 8-7s8 3 8 7"/>',
|
|
18
|
+
arrow: '<path d="M5 12h14M13 5l7 7-7 7"/>',
|
|
19
|
+
chevron: '<path d="M8 10l4 4 4-4"/>',
|
|
20
|
+
external: '<path d="M7 17L17 7M9 7h8v8"/>',
|
|
21
|
+
film: '<rect x="3" y="4" width="18" height="16"/><path d="M3 8h4M3 16h4M17 8h4M17 16h4M3 12h18"/>',
|
|
22
|
+
note: '<rect x="4" y="3" width="16" height="18"/><path d="M8 8h8M8 12h8M8 16h6"/>',
|
|
23
|
+
book: '<path d="M6 4h11a1 1 0 011 1v15H7a1 1 0 01-1-1z"/><path d="M17 20a2 2 0 002-2V6a2 2 0 00-2-2"/><path d="M9 8h5"/>',
|
|
24
|
+
check: '<path d="M5 12l4 4L19 6"/>',
|
|
25
|
+
cup: '<path d="M4 8h12v6a4 4 0 01-4 4H8a4 4 0 01-4-4z"/><path d="M16 10h2a2 2 0 010 4h-2M6 4v2M10 4v2M14 4v2"/>',
|
|
26
|
+
wallet: '<rect x="3" y="6" width="18" height="14"/><path d="M3 10h18M17 14h2"/>',
|
|
27
|
+
target: '<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.5" class="ss-icon-dot"/>',
|
|
28
|
+
spinner: '<path d="M12 3a9 9 0 1 0 9 9" stroke-linecap="round"/>',
|
|
29
|
+
home: '<path d="M4 11l8-8 8 8"/><path d="M6 9v12h12V9"/><path d="M10 21v-6h4v6"/>',
|
|
30
|
+
briefcase: '<rect x="3" y="7" width="18" height="13"/><path d="M9 7V4h6v3M3 12h18"/>',
|
|
31
|
+
folder: '<path d="M3 5h7l2 3h9v13H3z"/><path d="M3 8h9"/>',
|
|
32
|
+
github: '<path d="M7 3h10l2 2v6l-2 3h-4l1 2v5h-4v-5l1-2H7l-2-3V5l2-2z"/><path d="M9 8h1M14 8h1"/>',
|
|
33
|
+
linkedin: '<rect x="3" y="3" width="18" height="18"/><path d="M8 16v-5M8 8v.01M12 16v-5h2l2 2v3"/>',
|
|
34
|
+
language: '<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3L8 12l4 9M12 3l4 9-4 9"/>',
|
|
35
|
+
'color-swatch': '<rect x="3" y="3" width="8" height="18"/><path d="M7 17v.01"/><path d="M11 19l8-8 2 2-8 8"/><path d="M13 21h8"/>',
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The curated built-in glyphs plus any runtime-registered ones.
|
|
39
|
+
* (`PATHS` is kept as the public name for backward compatibility.)
|
|
40
|
+
*/
|
|
41
|
+
export const PATHS = { ...BUILTIN_PATHS };
|
|
42
|
+
/**
|
|
43
|
+
* Register (or override) a glyph at runtime so `<Icon name="foo" />` resolves
|
|
44
|
+
* raw SVG inner markup that isn't part of the curated {@link IconName} union.
|
|
45
|
+
* The markup is rendered verbatim inside the icon's `<svg viewBox="0 0 24 24">`.
|
|
46
|
+
*
|
|
47
|
+
* registerIcon('heart', '<path d="M12 21 4 13a5 5 0 0 1 7-7l1 1 1-1a5 5 0 0 1 7 7z"/>')
|
|
48
|
+
* <Icon name={'heart' as IconName} />
|
|
49
|
+
*/
|
|
50
|
+
export function registerIcon(name, paths) {
|
|
51
|
+
PATHS[name] = paths;
|
|
52
|
+
}
|
|
53
|
+
/** Look a glyph up; built-ins first, then runtime registrations. */
|
|
54
|
+
export function resolveIcon(name) {
|
|
55
|
+
return PATHS[name];
|
|
56
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export { type ColorTheme, type Size, type DesignConfig, defaultDesignConfig, get
|
|
|
2
2
|
export { dssocaConfig, SPINNER_VARIANT_NAMES, PALETTE_SLOTS, type DssocaConfig, type DesignAxis, type ComponentName, type ComponentsSize, type SpinnerVariant, type Palette, type ThemePalette, type PaletteSlot, } from './dssoca.config.js';
|
|
3
3
|
export { CHART_PALETTE } from './palette.js';
|
|
4
4
|
export { PRESET_THEMES, presetPalette, type PresetTheme, type PresetName } from './presets.js';
|
|
5
|
-
export { default as Icon,
|
|
5
|
+
export { default as Icon, type IconSize } from './components/Icon.svelte';
|
|
6
|
+
export { registerIcon, type IconName } from './icons.js';
|
|
6
7
|
export { default as Badge } from './components/Badge.svelte';
|
|
7
8
|
export { default as Button } from './components/Button.svelte';
|
|
8
9
|
export { default as Input } from './components/Input.svelte';
|
|
@@ -26,8 +27,8 @@ export { default as Image, type ImageSource } from './components/Image.svelte';
|
|
|
26
27
|
export { default as Heading } from './components/Heading.svelte';
|
|
27
28
|
export { default as Container } from './components/Container.svelte';
|
|
28
29
|
export { default as Textarea } from './components/Textarea.svelte';
|
|
29
|
-
export { default as Spinner
|
|
30
|
-
export type
|
|
30
|
+
export { default as Spinner } from './components/Spinner.svelte';
|
|
31
|
+
export { SPINNER_VARIANTS, type SpinnerFrames } from './spinner-frames.js';
|
|
31
32
|
export { default as Chart, type ChartSeries, type ChartPoint } from './components/Chart.svelte';
|
|
32
33
|
export { default as Table, type TableColumn, type TableSort } from './components/Table.svelte';
|
|
33
34
|
export { default as Select } from './components/Select.svelte';
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,8 @@ export { dssocaConfig, SPINNER_VARIANT_NAMES, PALETTE_SLOTS, } from './dssoca.co
|
|
|
4
4
|
export { CHART_PALETTE } from './palette.js';
|
|
5
5
|
// Preset terminal palettes (DS-0142): ready-made 19-slot themes.
|
|
6
6
|
export { PRESET_THEMES, presetPalette } from './presets.js';
|
|
7
|
-
export { default as Icon
|
|
7
|
+
export { default as Icon } from './components/Icon.svelte';
|
|
8
|
+
export { registerIcon } from './icons.js';
|
|
8
9
|
export { default as Badge } from './components/Badge.svelte';
|
|
9
10
|
export { default as Button } from './components/Button.svelte';
|
|
10
11
|
export { default as Input } from './components/Input.svelte';
|
|
@@ -32,7 +33,8 @@ export { default as Image } from './components/Image.svelte';
|
|
|
32
33
|
export { default as Heading } from './components/Heading.svelte';
|
|
33
34
|
export { default as Container } from './components/Container.svelte';
|
|
34
35
|
export { default as Textarea } from './components/Textarea.svelte';
|
|
35
|
-
export { default as Spinner
|
|
36
|
+
export { default as Spinner } from './components/Spinner.svelte';
|
|
37
|
+
export { SPINNER_VARIANTS } from './spinner-frames.js';
|
|
36
38
|
// geossoca component gaps (DS-0090).
|
|
37
39
|
export { default as Chart } from './components/Chart.svelte';
|
|
38
40
|
export { default as Table } from './components/Table.svelte';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-frame spinner variants. Frames + intervals are embedded verbatim from
|
|
3
|
+
* sindresorhus/cli-spinners (MIT — https://github.com/sindresorhus/cli-spinners),
|
|
4
|
+
* curated for the squared/blocky glyphs that fit the DS's zero-radius look.
|
|
5
|
+
* No runtime fetch, no dependency — just data.
|
|
6
|
+
*
|
|
7
|
+
* The *variant names* are owned by `dssoca.config.ts` (`SpinnerVariant`,
|
|
8
|
+
* derived from the `spinner` manifest axis — DS-0108); this object holds the
|
|
9
|
+
* frame data and is pinned to that union via `satisfies Record<SpinnerVariant,
|
|
10
|
+
* …>`, so the two cannot drift.
|
|
11
|
+
*/
|
|
12
|
+
export interface SpinnerFrames {
|
|
13
|
+
/** Milliseconds between frames (cli-spinners' recommended cadence). */
|
|
14
|
+
interval: number;
|
|
15
|
+
/** The glyph sequence, cycled in order. */
|
|
16
|
+
frames: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export declare const SPINNER_VARIANTS: {
|
|
19
|
+
readonly boxBounce2: {
|
|
20
|
+
readonly interval: 100;
|
|
21
|
+
readonly frames: readonly ["▌", "▀", "▐", "▄"];
|
|
22
|
+
};
|
|
23
|
+
readonly boxBounce: {
|
|
24
|
+
readonly interval: 120;
|
|
25
|
+
readonly frames: readonly ["▖", "▘", "▝", "▗"];
|
|
26
|
+
};
|
|
27
|
+
readonly squareCorners: {
|
|
28
|
+
readonly interval: 180;
|
|
29
|
+
readonly frames: readonly ["◰", "◳", "◲", "◱"];
|
|
30
|
+
};
|
|
31
|
+
readonly toggle2: {
|
|
32
|
+
readonly interval: 80;
|
|
33
|
+
readonly frames: readonly ["▫", "▪"];
|
|
34
|
+
};
|
|
35
|
+
readonly toggle3: {
|
|
36
|
+
readonly interval: 120;
|
|
37
|
+
readonly frames: readonly ["□", "■"];
|
|
38
|
+
};
|
|
39
|
+
readonly toggle4: {
|
|
40
|
+
readonly interval: 100;
|
|
41
|
+
readonly frames: readonly ["■", "□", "▪", "▫"];
|
|
42
|
+
};
|
|
43
|
+
readonly pipe: {
|
|
44
|
+
readonly interval: 100;
|
|
45
|
+
readonly frames: readonly ["┤", "┘", "┴", "└", "├", "┌", "┬", "┐"];
|
|
46
|
+
};
|
|
47
|
+
readonly line: {
|
|
48
|
+
readonly interval: 130;
|
|
49
|
+
readonly frames: readonly ["-", "\\", "|", "/"];
|
|
50
|
+
};
|
|
51
|
+
readonly growVertical: {
|
|
52
|
+
readonly interval: 120;
|
|
53
|
+
readonly frames: readonly ["▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"];
|
|
54
|
+
};
|
|
55
|
+
readonly growHorizontal: {
|
|
56
|
+
readonly interval: 120;
|
|
57
|
+
readonly frames: readonly ["▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍", "▎"];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const SPINNER_VARIANTS = {
|
|
2
|
+
boxBounce2: { interval: 100, frames: ['▌', '▀', '▐', '▄'] },
|
|
3
|
+
boxBounce: { interval: 120, frames: ['▖', '▘', '▝', '▗'] },
|
|
4
|
+
squareCorners: { interval: 180, frames: ['◰', '◳', '◲', '◱'] },
|
|
5
|
+
toggle2: { interval: 80, frames: ['▫', '▪'] },
|
|
6
|
+
toggle3: { interval: 120, frames: ['□', '■'] },
|
|
7
|
+
toggle4: { interval: 100, frames: ['■', '□', '▪', '▫'] },
|
|
8
|
+
pipe: { interval: 100, frames: ['┤', '┘', '┴', '└', '├', '┌', '┬', '┐'] },
|
|
9
|
+
line: { interval: 130, frames: ['-', '\\', '|', '/'] },
|
|
10
|
+
growVertical: { interval: 120, frames: ['▁', '▃', '▄', '▅', '▆', '▇', '▆', '▅', '▄', '▃'] },
|
|
11
|
+
growHorizontal: {
|
|
12
|
+
interval: 120,
|
|
13
|
+
frames: ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '▊', '▋', '▌', '▍', '▎'],
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -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) {
|
|
@@ -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;
|