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.
Files changed (44) hide show
  1. package/README.md +19 -0
  2. package/dist/components/Icon.svelte +9 -61
  3. package/dist/components/Icon.svelte.d.ts +4 -47
  4. package/dist/components/LogStream.svelte +2 -2
  5. package/dist/components/MetricTile.svelte +2 -2
  6. package/dist/components/ServiceCard.svelte +2 -2
  7. package/dist/components/Spinner.svelte +7 -34
  8. package/dist/components/Spinner.svelte.d.ts +2 -59
  9. package/dist/components/Tooltip.svelte +151 -15
  10. package/dist/components/Tooltip.svelte.d.ts +11 -1
  11. package/dist/icons.d.ts +54 -0
  12. package/dist/icons.js +56 -0
  13. package/dist/index.d.ts +4 -3
  14. package/dist/index.js +4 -2
  15. package/dist/spinner-frames.d.ts +59 -0
  16. package/dist/spinner-frames.js +15 -0
  17. package/dist/toast-core.d.ts +61 -0
  18. package/dist/toast-core.js +73 -0
  19. package/dist/toast.svelte.d.ts +2 -33
  20. package/dist/toast.svelte.js +3 -66
  21. package/dist/vanilla/accordion.d.ts +2 -0
  22. package/dist/vanilla/accordion.js +57 -0
  23. package/dist/vanilla/delegate.d.ts +16 -0
  24. package/dist/vanilla/delegate.js +33 -0
  25. package/dist/vanilla/fields.d.ts +6 -0
  26. package/dist/vanilla/fields.js +89 -0
  27. package/dist/vanilla/icons.d.ts +17 -0
  28. package/dist/vanilla/icons.js +78 -0
  29. package/dist/vanilla/index.d.ts +16 -0
  30. package/dist/vanilla/index.js +60 -0
  31. package/dist/vanilla/menu.d.ts +3 -0
  32. package/dist/vanilla/menu.js +133 -0
  33. package/dist/vanilla/modal.d.ts +3 -0
  34. package/dist/vanilla/modal.js +42 -0
  35. package/dist/vanilla/segmented.d.ts +2 -0
  36. package/dist/vanilla/segmented.js +62 -0
  37. package/dist/vanilla/switch.d.ts +2 -0
  38. package/dist/vanilla/switch.js +22 -0
  39. package/dist/vanilla/toast.d.ts +37 -0
  40. package/dist/vanilla/toast.js +196 -0
  41. package/dist/vanilla/tooltip.d.ts +3 -0
  42. package/dist/vanilla/tooltip.js +54 -0
  43. package/dist/vanilla.css +4433 -0
  44. package/package.json +14 -5
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Field behaviours (DS-0148) over the shared field skeleton:
3
+ *
4
+ * - Input `clearable`: `.ss-field .clear` empties `.ss-input`, refocuses it and hides itself;
5
+ * typing shows it again (Input.svelte removes the button entirely — vanilla toggles `hidden`).
6
+ * - NumberField steppers: `.ss-numberfield .step.dec/.inc` nudge by `step`, clamped to
7
+ * `min`/`max`, and disable themselves at the bounds (same `nudge`/`clamp` as the component).
8
+ * - Textarea autosize: `.ss-textarea .field.autosize` grows with content. Browsers with
9
+ * `field-sizing: content` do it in CSS; the JS `scrollHeight` sync is the fallback.
10
+ */
11
+ import { on, all } from './delegate.js';
12
+ const fire = (el, type) => el.dispatchEvent(new Event(type, { bubbles: true }));
13
+ // ── Input clearable ─────────────────────────────────────────────────────────
14
+ function syncClear(input) {
15
+ const btn = input.closest('.control')?.querySelector('.clear');
16
+ if (btn)
17
+ btn.hidden = !input.value || input.readOnly || input.disabled;
18
+ }
19
+ export function clearInput(btn) {
20
+ const input = btn.closest('.control')?.querySelector('.ss-input');
21
+ if (!input)
22
+ return;
23
+ input.value = '';
24
+ fire(input, 'input');
25
+ syncClear(input);
26
+ input.focus();
27
+ }
28
+ // ── NumberField steppers ───────────────────────────────────────────────────
29
+ const num = (s) => (s == null || s === '' ? null : Number(s));
30
+ function syncSteppers(input) {
31
+ const control = input.closest('.control');
32
+ if (!control)
33
+ return;
34
+ const v = input.value === '' ? null : input.valueAsNumber;
35
+ const min = num(input.getAttribute('min'));
36
+ const max = num(input.getAttribute('max'));
37
+ const locked = input.disabled || input.readOnly;
38
+ const dec = control.querySelector('.step.dec');
39
+ const inc = control.querySelector('.step.inc');
40
+ if (dec)
41
+ dec.disabled = locked || (v != null && min != null && v <= min);
42
+ if (inc)
43
+ inc.disabled = locked || (v != null && max != null && v >= max);
44
+ }
45
+ export function nudgeNumber(btn) {
46
+ const input = btn.closest('.control')?.querySelector('.ss-input');
47
+ if (!input || btn.disabled)
48
+ return;
49
+ const dir = btn.classList.contains('inc') ? 1 : -1;
50
+ const min = num(input.getAttribute('min'));
51
+ const max = num(input.getAttribute('max'));
52
+ const step = num(input.getAttribute('step')) ?? 1;
53
+ const current = input.value === '' || Number.isNaN(input.valueAsNumber) ? null : input.valueAsNumber;
54
+ const base = current ?? (dir > 0 ? (min ?? 0) : (max ?? 0));
55
+ let next = base + dir * step;
56
+ if (min != null && next < min)
57
+ next = min;
58
+ if (max != null && next > max)
59
+ next = max;
60
+ input.value = String(next);
61
+ fire(input, 'input');
62
+ fire(input, 'change');
63
+ syncSteppers(input);
64
+ }
65
+ // ── Textarea autosize ──────────────────────────────────────────────────────
66
+ export const supportsFieldSizing = typeof CSS !== 'undefined' &&
67
+ typeof CSS.supports === 'function' &&
68
+ CSS.supports('field-sizing', 'content');
69
+ export function autosize(el) {
70
+ if (supportsFieldSizing)
71
+ return;
72
+ el.style.height = 'auto';
73
+ el.style.height = `${el.scrollHeight}px`;
74
+ }
75
+ export function mountFields(root) {
76
+ for (const ta of all(root, '.ss-textarea .field.autosize'))
77
+ autosize(ta);
78
+ for (const input of all(root, '.ss-field .ss-input'))
79
+ syncClear(input);
80
+ for (const input of all(root, '.ss-numberfield .ss-input'))
81
+ syncSteppers(input);
82
+ }
83
+ export function installFields() {
84
+ on('click', '.ss-field .clear', (btn) => clearInput(btn));
85
+ on('input', '.ss-field .ss-input', (input) => syncClear(input));
86
+ on('click', '.ss-numberfield .step', (btn) => nudgeNumber(btn));
87
+ on('input', '.ss-numberfield .ss-input', (input) => syncSteppers(input));
88
+ on('input', '.ss-textarea .field.autosize', (ta) => autosize(ta));
89
+ }
@@ -0,0 +1,17 @@
1
+ export type IconSizeName = 'xs' | 'sm' | 'md' | 'lg';
2
+ export interface IconOptions {
3
+ size?: IconSizeName;
4
+ px?: number;
5
+ variant?: 'outline' | 'solid';
6
+ spin?: boolean;
7
+ rotate?: 0 | 90 | 180 | 270;
8
+ flip?: 'horizontal' | 'vertical';
9
+ title?: string;
10
+ desc?: string;
11
+ strokeWidth?: number;
12
+ class?: string;
13
+ }
14
+ /** Markup for one icon — byte-compatible with Icon.svelte's rendered `<svg>`. */
15
+ export declare function iconSvg(name: string, o?: IconOptions): string;
16
+ /** Replace every `[data-ss-icon]` placeholder under `root` with the rendered SVG. */
17
+ export declare function hydrateIcons(root?: ParentNode): void;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Icons (DS-0148) — renders the exact `<svg class="ss-icon">` Icon.svelte produces from the
3
+ * shared glyph table, and hydrates placeholders:
4
+ *
5
+ * <span data-ss-icon="chevron" data-size="sm" class="ic"></span>
6
+ *
7
+ * Supported data attributes mirror the component props: `data-size` (xs|sm|md|lg), `data-px`,
8
+ * `data-variant="solid"`, `data-spin`, `data-rotate` (90|180|270), `data-flip`
9
+ * (horizontal|vertical), `data-title` (+ `data-desc`) for a labelled, non-decorative icon.
10
+ * Extra classes on the placeholder are carried over.
11
+ */
12
+ import { resolveIcon } from '../icons.js';
13
+ import { all } from './delegate.js';
14
+ const SIZE_PX = { xs: 12, sm: 16, md: 20, lg: 24 };
15
+ let seq = 0;
16
+ const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
17
+ const attr = (s) => esc(s).replace(/"/g, '&quot;');
18
+ /** Markup for one icon — byte-compatible with Icon.svelte's rendered `<svg>`. */
19
+ export function iconSvg(name, o = {}) {
20
+ const paths = resolveIcon(name);
21
+ if (paths == null && typeof console !== 'undefined') {
22
+ console.warn(`[dssoca] icon: unknown name "${name}" (no registered glyph). Rendering empty.`);
23
+ }
24
+ const dim = o.px != null ? `${o.px}px` : o.size != null ? `${SIZE_PX[o.size]}px` : 'var(--ss-icon)';
25
+ const solid = o.variant === 'solid';
26
+ const classes = [
27
+ 'ss-icon',
28
+ o.class,
29
+ o.spin && 'spin',
30
+ o.flip === 'horizontal' && 'flip-h',
31
+ o.flip === 'vertical' && 'flip-v',
32
+ ]
33
+ .filter(Boolean)
34
+ .join(' ');
35
+ const axis = o.size && o.size !== 'xs' ? ` data-size-variant="${o.size}"` : '';
36
+ const rotate = o.rotate ? ` data-rotate="${o.rotate}"` : '';
37
+ const uid = o.title ? `ss-ic-${++seq}` : '';
38
+ const titleId = o.title ? `${uid}-t` : '';
39
+ const descId = o.desc && o.title ? `${uid}-d` : '';
40
+ const labelledBy = [titleId, descId].filter(Boolean).join(' ');
41
+ const a11y = o.title ? ` role="img" aria-labelledby="${labelledBy}"` : ' aria-hidden="true"';
42
+ const inner = (o.title ? `<title id="${titleId}">${esc(o.title)}</title>` : '') +
43
+ (descId ? `<desc id="${descId}">${esc(o.desc)}</desc>` : '') +
44
+ (paths ?? '');
45
+ return (`<svg viewBox="0 0 24 24" fill="${solid ? 'currentColor' : 'none'}" stroke="${solid ? 'none' : 'currentColor'}"` +
46
+ ` stroke-width="${o.strokeWidth ?? 2}" stroke-linecap="square" stroke-linejoin="miter"` +
47
+ ` class="${attr(classes)}"${axis}${rotate} style="width:${dim};height:${dim}"${a11y} focusable="false">` +
48
+ `${inner}</svg>`);
49
+ }
50
+ function optionsFrom(el) {
51
+ const d = el.dataset;
52
+ const rotate = d.rotate ? Number(d.rotate) : 0;
53
+ return {
54
+ size: d.size ?? undefined,
55
+ px: d.px ? Number(d.px) : undefined,
56
+ variant: d.variant === 'solid' ? 'solid' : undefined,
57
+ spin: 'spin' in d,
58
+ rotate: rotate === 90 || rotate === 180 || rotate === 270 ? rotate : 0,
59
+ flip: d.flip === 'horizontal' || d.flip === 'vertical' ? d.flip : undefined,
60
+ title: d.title,
61
+ desc: d.desc,
62
+ strokeWidth: d.strokeWidth ? Number(d.strokeWidth) : undefined,
63
+ class: el.className || undefined,
64
+ };
65
+ }
66
+ /** Replace every `[data-ss-icon]` placeholder under `root` with the rendered SVG. */
67
+ export function hydrateIcons(root = document) {
68
+ for (const el of all(root, '[data-ss-icon]')) {
69
+ const name = el.getAttribute('data-ss-icon');
70
+ if (!name)
71
+ continue;
72
+ const tpl = document.createElement('template');
73
+ tpl.innerHTML = iconSvg(name, optionsFrom(el));
74
+ const svg = tpl.content.firstElementChild;
75
+ if (svg)
76
+ el.replaceWith(svg);
77
+ }
78
+ }
@@ -0,0 +1,16 @@
1
+ export { toast, toasts } from './toast.js';
2
+ export type { Toast, ToastKind, ToastOptions, ToastPatch, ToastAction, PromiseMessages, } from './toast.js';
3
+ export { iconSvg, hydrateIcons, type IconOptions } from './icons.js';
4
+ export { registerIcon, type IconName } from '../icons.js';
5
+ export { openModal, closeModal } from './modal.js';
6
+ export { toggleAccordion } from './accordion.js';
7
+ export { openMenu, closeMenu } from './menu.js';
8
+ export { showTooltip, hideTooltip } from './tooltip.js';
9
+ export { toggleSwitch } from './switch.js';
10
+ export { selectSegment } from './segmented.js';
11
+ export { clearInput, nudgeNumber, autosize } from './fields.js';
12
+ export { applyDesignConfig, designAttributes, getDesignConfig, paletteToCss, type DesignConfig, type ColorTheme, type Size, } from '../config.js';
13
+ /** Hydrate icon placeholders and initialise setup-type behaviours under `root`. */
14
+ export declare function mount(root?: ParentNode): void;
15
+ /** Register every delegated behaviour once per document. Safe to call repeatedly. */
16
+ export declare function install(): void;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `dssoca/vanilla.js` (DS-0148) — small, dependency-free behaviours for the plain-HTML
3
+ * consumption path. Importing this module wires every behaviour once via document-level event
4
+ * delegation (so markup added later just works) and runs `mount()` when the DOM is ready.
5
+ *
6
+ * <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.17/dist/theme.css">
7
+ * <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.17/dist/vanilla.css">
8
+ * <script type="module" src="https://cdn.jsdelivr.net/npm/dssoca@0.17/dist/vanilla/index.js"></script>
9
+ *
10
+ * Call `mount(root)` after injecting HTML that contains `[data-ss-icon]` placeholders or
11
+ * autosizing textareas. Nothing here imports Svelte or a `.svelte` module.
12
+ */
13
+ import { installModal } from './modal.js';
14
+ import { installAccordion } from './accordion.js';
15
+ import { installMenu } from './menu.js';
16
+ import { installTooltip } from './tooltip.js';
17
+ import { installSwitch } from './switch.js';
18
+ import { installSegmented } from './segmented.js';
19
+ import { installFields, mountFields } from './fields.js';
20
+ import { hydrateIcons } from './icons.js';
21
+ export { toast, toasts } from './toast.js';
22
+ export { iconSvg, hydrateIcons } from './icons.js';
23
+ export { registerIcon } from '../icons.js';
24
+ export { openModal, closeModal } from './modal.js';
25
+ export { toggleAccordion } from './accordion.js';
26
+ export { openMenu, closeMenu } from './menu.js';
27
+ export { showTooltip, hideTooltip } from './tooltip.js';
28
+ export { toggleSwitch } from './switch.js';
29
+ export { selectSegment } from './segmented.js';
30
+ export { clearInput, nudgeNumber, autosize } from './fields.js';
31
+ export { applyDesignConfig, designAttributes, getDesignConfig, paletteToCss, } from '../config.js';
32
+ /** Hydrate icon placeholders and initialise setup-type behaviours under `root`. */
33
+ export function mount(root = document) {
34
+ hydrateIcons(root);
35
+ mountFields(root);
36
+ }
37
+ const FLAG = '__dssocaVanilla';
38
+ /** Register every delegated behaviour once per document. Safe to call repeatedly. */
39
+ export function install() {
40
+ if (typeof document === 'undefined')
41
+ return;
42
+ const doc = document;
43
+ if (doc[FLAG])
44
+ return;
45
+ doc[FLAG] = true;
46
+ installModal();
47
+ installAccordion();
48
+ installMenu();
49
+ installTooltip();
50
+ installSwitch();
51
+ installSegmented();
52
+ installFields();
53
+ if (document.readyState === 'loading') {
54
+ document.addEventListener('DOMContentLoaded', () => mount(), { once: true });
55
+ }
56
+ else {
57
+ mount();
58
+ }
59
+ }
60
+ install();
@@ -0,0 +1,3 @@
1
+ export declare function openMenu(trigger: HTMLElement, focus?: 'first' | 'last'): void;
2
+ export declare function closeMenu(trigger: HTMLElement, returnFocus?: boolean): void;
3
+ export declare function installMenu(): void;
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Menu (DS-0148) — port of Menu.svelte's open/close + roving-focus model over the exact same
3
+ * DOM: `.ss-menu > .trigger[aria-expanded][aria-controls]` and `.panel[role=menu] > .item`.
4
+ * Outside pointerdown closes without returning focus; Escape / item activation return focus
5
+ * to the trigger. Emits `ss:select` on the root with `{ index, value }` (`value` is the
6
+ * item's `data-value`, when authored). For `menuitemradio` items the check marker moves to
7
+ * the activated item.
8
+ */
9
+ import { on, emit, all } from './delegate.js';
10
+ import { iconSvg } from './icons.js';
11
+ const TRIGGER = '.ss-menu > .trigger';
12
+ const PANEL = '.ss-menu > .panel[role="menu"]';
13
+ function parts(el) {
14
+ const root = el.closest('.ss-menu');
15
+ const trigger = root?.querySelector(':scope > .trigger') ?? null;
16
+ const panel = root?.querySelector(':scope > .panel') ?? null;
17
+ return { root, trigger, panel };
18
+ }
19
+ function items(panel) {
20
+ return all(panel, '.item').filter((i) => i.closest('.panel') === panel);
21
+ }
22
+ function enabled(panel) {
23
+ return items(panel).filter((i) => !i.disabled && i.getAttribute('aria-disabled') !== 'true');
24
+ }
25
+ function focusItem(panel, item) {
26
+ if (!item)
27
+ return;
28
+ for (const i of items(panel))
29
+ i.tabIndex = i === item ? 0 : -1;
30
+ item.focus();
31
+ }
32
+ export function openMenu(trigger, focus = 'first') {
33
+ const { panel } = parts(trigger);
34
+ if (!panel || trigger.getAttribute('aria-expanded') === 'true')
35
+ return;
36
+ trigger.setAttribute('aria-expanded', 'true');
37
+ panel.classList.add('open');
38
+ panel.setAttribute('aria-hidden', 'false');
39
+ queueMicrotask(() => {
40
+ const list = enabled(panel);
41
+ focusItem(panel, focus === 'first' ? list[0] : list[list.length - 1]);
42
+ });
43
+ }
44
+ export function closeMenu(trigger, returnFocus = true) {
45
+ const { panel } = parts(trigger);
46
+ if (!panel || trigger.getAttribute('aria-expanded') !== 'true')
47
+ return;
48
+ trigger.setAttribute('aria-expanded', 'false');
49
+ panel.classList.remove('open');
50
+ panel.setAttribute('aria-hidden', 'true');
51
+ for (const i of items(panel))
52
+ i.tabIndex = -1;
53
+ if (returnFocus)
54
+ trigger.focus();
55
+ }
56
+ function activate(item) {
57
+ const { root, trigger, panel } = parts(item);
58
+ if (!root || !trigger || !panel || item.disabled)
59
+ return;
60
+ if (item.getAttribute('role') === 'menuitemradio') {
61
+ for (const i of items(panel)) {
62
+ const on = i === item;
63
+ i.classList.toggle('selected', on);
64
+ i.setAttribute('aria-checked', String(on));
65
+ const marker = i.querySelector('.marker');
66
+ if (marker)
67
+ marker.innerHTML = on ? iconSvg('check') : '';
68
+ }
69
+ }
70
+ emit(root, 'ss:select', { index: items(panel).indexOf(item), value: item.dataset.value });
71
+ closeMenu(trigger);
72
+ }
73
+ export function installMenu() {
74
+ on('click', TRIGGER, (trigger) => {
75
+ if (trigger.getAttribute('aria-expanded') === 'true')
76
+ closeMenu(trigger);
77
+ else
78
+ openMenu(trigger, 'first');
79
+ });
80
+ on('keydown', TRIGGER, (trigger, e) => {
81
+ if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {
82
+ e.preventDefault();
83
+ openMenu(trigger, 'first');
84
+ }
85
+ else if (e.key === 'ArrowUp') {
86
+ e.preventDefault();
87
+ openMenu(trigger, 'last');
88
+ }
89
+ });
90
+ on('keydown', PANEL, (panel, e) => {
91
+ const { trigger } = parts(panel);
92
+ if (!trigger)
93
+ return;
94
+ const list = enabled(panel);
95
+ const active = list.findIndex((i) => i === document.activeElement);
96
+ const pick = (i) => focusItem(panel, list[((i % list.length) + list.length) % list.length]);
97
+ switch (e.key) {
98
+ case 'ArrowDown':
99
+ e.preventDefault();
100
+ pick(active < 0 ? 0 : active + 1);
101
+ break;
102
+ case 'ArrowUp':
103
+ e.preventDefault();
104
+ pick(active < 0 ? list.length - 1 : active - 1);
105
+ break;
106
+ case 'Home':
107
+ e.preventDefault();
108
+ pick(0);
109
+ break;
110
+ case 'End':
111
+ e.preventDefault();
112
+ pick(list.length - 1);
113
+ break;
114
+ case 'Escape':
115
+ e.preventDefault();
116
+ closeMenu(trigger);
117
+ break;
118
+ case 'Tab':
119
+ closeMenu(trigger, false);
120
+ break;
121
+ }
122
+ });
123
+ on('click', `${PANEL} .item`, (item) => activate(item));
124
+ document.addEventListener('pointerdown', (e) => {
125
+ const t = e.target;
126
+ for (const trigger of all(document, `${TRIGGER}[aria-expanded="true"]`)) {
127
+ const root = trigger.closest('.ss-menu');
128
+ if (root && t && root.contains(t))
129
+ continue;
130
+ closeMenu(trigger, false);
131
+ }
132
+ }, true);
133
+ }
@@ -0,0 +1,3 @@
1
+ export declare function openModal(dialog: HTMLDialogElement): void;
2
+ export declare function closeModal(dialog: HTMLDialogElement): void;
3
+ export declare function installModal(): void;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Modal (DS-0148) — the component is a native `<dialog class="ss-modal">`, so the browser owns
3
+ * the focus trap, inertness and Escape. Vanilla only needs openers and closers:
4
+ *
5
+ * <button data-ss-modal="#confirm">Open</button>
6
+ * <dialog class="ss-modal" id="confirm"> … <button class="close" data-ss-dismiss>×</button>
7
+ *
8
+ * Backdrop pointerdown closes unless the dialog carries `data-ss-static`; Escape is blocked
9
+ * when it carries `data-ss-no-esc` (mirrors `closeOnBackdrop` / `closeOnEsc`).
10
+ */
11
+ import { on, byId } from './delegate.js';
12
+ export function openModal(dialog) {
13
+ if (!dialog.open)
14
+ dialog.showModal();
15
+ }
16
+ export function closeModal(dialog) {
17
+ if (dialog.open)
18
+ dialog.close();
19
+ }
20
+ export function installModal() {
21
+ on('click', '[data-ss-modal]', (opener, e) => {
22
+ const target = byId(opener.getAttribute('data-ss-modal'));
23
+ if (!(target instanceof HTMLDialogElement))
24
+ return;
25
+ e.preventDefault();
26
+ openModal(target);
27
+ });
28
+ on('click', 'dialog.ss-modal [data-ss-dismiss]', (btn) => {
29
+ const dialog = btn.closest('dialog.ss-modal');
30
+ if (dialog instanceof HTMLDialogElement)
31
+ closeModal(dialog);
32
+ });
33
+ on('pointerdown', 'dialog.ss-modal', (dialog, e) => {
34
+ if (e.target !== dialog || dialog.hasAttribute('data-ss-static'))
35
+ return;
36
+ closeModal(dialog);
37
+ });
38
+ // `cancel` does not bubble — capture it.
39
+ on('cancel', 'dialog.ss-modal[data-ss-no-esc]', (_dialog, e) => {
40
+ e.preventDefault();
41
+ }, { capture: true });
42
+ }
@@ -0,0 +1,2 @@
1
+ export declare function selectSegment(segment: HTMLButtonElement): void;
2
+ export declare function installSegmented(): void;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * SegmentedControl (DS-0148) — radio-group selection over `.ss-segmented > .segment[role=radio]`
3
+ * with the same roving model as SegmentedControl.svelte (Arrow/Home/End select + focus,
4
+ * wrapping over enabled segments). Emits `ss:change` on the root with `{ value, index }`;
5
+ * `value` is the segment's `data-value` (vanilla-only attribute) or its label text.
6
+ */
7
+ import { on, emit, all } from './delegate.js';
8
+ function segments(root) {
9
+ return all(root, '.segment[role="radio"]').filter((s) => s.closest('.ss-segmented') === root);
10
+ }
11
+ export function selectSegment(segment) {
12
+ const root = segment.closest('.ss-segmented');
13
+ if (!root || segment.disabled || root.getAttribute('aria-disabled') === 'true')
14
+ return;
15
+ const list = segments(root);
16
+ const already = segment.getAttribute('aria-checked') === 'true';
17
+ for (const s of list) {
18
+ const on = s === segment;
19
+ s.classList.toggle('selected', on);
20
+ s.setAttribute('aria-checked', String(on));
21
+ s.tabIndex = on ? 0 : -1;
22
+ }
23
+ if (already)
24
+ return;
25
+ const value = segment.dataset.value ?? segment.querySelector('.label')?.textContent?.trim() ?? '';
26
+ emit(root, 'ss:change', { value, index: list.indexOf(segment) });
27
+ }
28
+ export function installSegmented() {
29
+ on('click', '.ss-segmented .segment[role="radio"]', (s) => selectSegment(s));
30
+ on('keydown', '.ss-segmented .segment[role="radio"]', (segment, e) => {
31
+ const root = segment.closest('.ss-segmented');
32
+ if (!root)
33
+ return;
34
+ const enabled = segments(root).filter((s) => !s.disabled);
35
+ const pos = enabled.indexOf(segment);
36
+ const n = enabled.length;
37
+ let target;
38
+ switch (e.key) {
39
+ case 'ArrowRight':
40
+ case 'ArrowDown':
41
+ target = ((pos < 0 ? -1 : pos) + 1 + n) % n;
42
+ break;
43
+ case 'ArrowLeft':
44
+ case 'ArrowUp':
45
+ target = ((pos < 0 ? 0 : pos) - 1 + n) % n;
46
+ break;
47
+ case 'Home':
48
+ target = 0;
49
+ break;
50
+ case 'End':
51
+ target = n - 1;
52
+ break;
53
+ default:
54
+ return;
55
+ }
56
+ if (n === 0)
57
+ return;
58
+ e.preventDefault();
59
+ selectSegment(enabled[target]);
60
+ enabled[target].focus();
61
+ });
62
+ }
@@ -0,0 +1,2 @@
1
+ export declare function toggleSwitch(track: HTMLButtonElement): void;
2
+ export declare function installSwitch(): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Switch (DS-0148) — flips `aria-checked` + `.on` on `.ss-switch .track[role=switch]`; clicking
3
+ * the sibling `.label` toggles too (same target as the control, like Switch.svelte). Emits
4
+ * `ss:change` on the root with `{ checked }`.
5
+ */
6
+ import { on, emit } from './delegate.js';
7
+ export function toggleSwitch(track) {
8
+ if (track.disabled)
9
+ return;
10
+ const next = track.getAttribute('aria-checked') !== 'true';
11
+ track.setAttribute('aria-checked', String(next));
12
+ track.classList.toggle('on', next);
13
+ emit(track.closest('.ss-switch') ?? track, 'ss:change', { checked: next });
14
+ }
15
+ export function installSwitch() {
16
+ on('click', '.ss-switch .track[role="switch"]', (track) => toggleSwitch(track));
17
+ on('click', '.ss-switch .label', (label) => {
18
+ const track = label.closest('.ss-switch')?.querySelector('.track');
19
+ if (track)
20
+ toggleSwitch(track);
21
+ });
22
+ }
@@ -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
+ };