dssoca 0.16.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 (42) 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/icons.d.ts +54 -0
  10. package/dist/icons.js +56 -0
  11. package/dist/index.d.ts +4 -3
  12. package/dist/index.js +4 -2
  13. package/dist/spinner-frames.d.ts +59 -0
  14. package/dist/spinner-frames.js +15 -0
  15. package/dist/toast-core.d.ts +61 -0
  16. package/dist/toast-core.js +73 -0
  17. package/dist/toast.svelte.d.ts +2 -33
  18. package/dist/toast.svelte.js +3 -66
  19. package/dist/vanilla/accordion.d.ts +2 -0
  20. package/dist/vanilla/accordion.js +57 -0
  21. package/dist/vanilla/delegate.d.ts +16 -0
  22. package/dist/vanilla/delegate.js +33 -0
  23. package/dist/vanilla/fields.d.ts +6 -0
  24. package/dist/vanilla/fields.js +89 -0
  25. package/dist/vanilla/icons.d.ts +17 -0
  26. package/dist/vanilla/icons.js +78 -0
  27. package/dist/vanilla/index.d.ts +16 -0
  28. package/dist/vanilla/index.js +60 -0
  29. package/dist/vanilla/menu.d.ts +3 -0
  30. package/dist/vanilla/menu.js +133 -0
  31. package/dist/vanilla/modal.d.ts +3 -0
  32. package/dist/vanilla/modal.js +42 -0
  33. package/dist/vanilla/segmented.d.ts +2 -0
  34. package/dist/vanilla/segmented.js +62 -0
  35. package/dist/vanilla/switch.d.ts +2 -0
  36. package/dist/vanilla/switch.js +22 -0
  37. package/dist/vanilla/toast.d.ts +37 -0
  38. package/dist/vanilla/toast.js +196 -0
  39. package/dist/vanilla/tooltip.d.ts +3 -0
  40. package/dist/vanilla/tooltip.js +54 -0
  41. package/dist/vanilla.css +4433 -0
  42. package/package.json +14 -5
@@ -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
+ }
@@ -1,29 +1,5 @@
1
- export type ToastKind = 'success' | 'error' | 'info' | 'loading';
2
- /** An optional inline action rendered as a button inside the toast. */
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 {};
@@ -1,59 +1,4 @@
1
- /** Default auto-dismiss per kind. Errors linger; loading is sticky. */
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
- // Back-compat: the old signature accepted a bare `timeout` number.
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: this.#resolveTimeout(kind, o),
25
+ timeout: resolveTimeout(kind, o),
89
26
  action: o?.action,
90
27
  };
91
28
  if (this.items.length < this.max) {
@@ -0,0 +1,2 @@
1
+ export declare function toggleAccordion(head: HTMLElement): void;
2
+ export declare function installAccordion(): void;
@@ -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;
@@ -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;