dssoca 0.20.0 → 0.21.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 (133) hide show
  1. package/README.md +3 -3
  2. package/dist/components/Accordion.svelte +23 -52
  3. package/dist/components/BottomNav.svelte +18 -28
  4. package/dist/components/BoxPlot.svelte +7 -6
  5. package/dist/components/BumpChart.svelte +9 -12
  6. package/dist/components/Chart.svelte +9 -12
  7. package/dist/components/Checkbox.svelte +210 -0
  8. package/dist/components/Checkbox.svelte.d.ts +38 -0
  9. package/dist/components/FileDrop.svelte +52 -83
  10. package/dist/components/FileDrop.svelte.d.ts +6 -2
  11. package/dist/components/Heatmap.svelte +8 -8
  12. package/dist/components/Image.svelte +44 -44
  13. package/dist/components/Input.svelte +8 -3
  14. package/dist/components/LogStream.svelte +15 -25
  15. package/dist/components/Menu.svelte +69 -94
  16. package/dist/components/Menu.svelte.d.ts +6 -0
  17. package/dist/components/Modal.svelte +61 -14
  18. package/dist/components/Modal.svelte.d.ts +7 -2
  19. package/dist/components/NumberField.svelte +18 -19
  20. package/dist/components/Pagination.svelte +47 -37
  21. package/dist/components/Pagination.svelte.d.ts +6 -2
  22. package/dist/components/Popover.svelte +247 -0
  23. package/dist/components/Popover.svelte.d.ts +36 -0
  24. package/dist/components/RadioGroup.svelte +227 -0
  25. package/dist/components/RadioGroup.svelte.d.ts +42 -0
  26. package/dist/components/ScatterPlot.svelte +11 -13
  27. package/dist/components/SearchPalette.svelte +124 -120
  28. package/dist/components/SearchPalette.svelte.d.ts +6 -4
  29. package/dist/components/SegmentedControl.svelte +41 -62
  30. package/dist/components/SegmentedControl.svelte.d.ts +7 -2
  31. package/dist/components/ShortcutsHelp.svelte +48 -47
  32. package/dist/components/Sidebar.svelte +48 -60
  33. package/dist/components/Switch.svelte +20 -10
  34. package/dist/components/Switch.svelte.d.ts +6 -2
  35. package/dist/components/Table.svelte +15 -37
  36. package/dist/components/Tabs.svelte +223 -0
  37. package/dist/components/Tabs.svelte.d.ts +51 -0
  38. package/dist/components/TierList.svelte +38 -38
  39. package/dist/components/TierList.svelte.d.ts +7 -3
  40. package/dist/components/Toaster.svelte +29 -29
  41. package/dist/components/Tooltip.svelte +37 -21
  42. package/dist/components/Topbar.svelte +13 -38
  43. package/dist/core/accordion.d.ts +32 -0
  44. package/dist/core/accordion.js +53 -0
  45. package/dist/core/behaviors/focusable.d.ts +5 -0
  46. package/dist/core/behaviors/focusable.js +14 -0
  47. package/dist/core/behaviors/roving.d.ts +13 -0
  48. package/dist/core/behaviors/roving.js +29 -0
  49. package/dist/core/bottom-nav.d.ts +36 -0
  50. package/dist/core/bottom-nav.js +33 -0
  51. package/dist/core/chart-nav.d.ts +53 -0
  52. package/dist/{chart-nav.js → core/chart-nav.js} +27 -0
  53. package/dist/core/checkbox.d.ts +36 -0
  54. package/dist/core/checkbox.js +29 -0
  55. package/dist/core/file-drop.d.ts +75 -0
  56. package/dist/core/file-drop.js +101 -0
  57. package/dist/core/image.d.ts +59 -0
  58. package/dist/core/image.js +64 -0
  59. package/dist/core/input.d.ts +21 -0
  60. package/dist/core/input.js +17 -0
  61. package/dist/core/log-stream.d.ts +51 -0
  62. package/dist/core/log-stream.js +50 -0
  63. package/dist/core/menu.d.ts +70 -0
  64. package/dist/core/menu.js +84 -0
  65. package/dist/core/modal.d.ts +59 -0
  66. package/dist/core/modal.js +44 -0
  67. package/dist/core/number-field.d.ts +47 -0
  68. package/dist/core/number-field.js +64 -0
  69. package/dist/core/pagination.d.ts +59 -0
  70. package/dist/core/pagination.js +65 -0
  71. package/dist/core/popover.d.ts +68 -0
  72. package/dist/core/popover.js +55 -0
  73. package/dist/core/radio.d.ts +36 -0
  74. package/dist/core/radio.js +48 -0
  75. package/dist/core/search-palette.d.ts +124 -0
  76. package/dist/core/search-palette.js +149 -0
  77. package/dist/core/segmented.d.ts +46 -0
  78. package/dist/core/segmented.js +66 -0
  79. package/dist/core/shortcuts-help.d.ts +56 -0
  80. package/dist/core/shortcuts-help.js +50 -0
  81. package/dist/core/sidebar.d.ts +63 -0
  82. package/dist/core/sidebar.js +84 -0
  83. package/dist/core/switch.d.ts +19 -0
  84. package/dist/core/switch.js +11 -0
  85. package/dist/core/table.d.ts +40 -0
  86. package/dist/core/table.js +57 -0
  87. package/dist/core/tabs.d.ts +84 -0
  88. package/dist/core/tabs.js +90 -0
  89. package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +62 -0
  90. package/dist/{tierlist-core.js → core/tierlist.js} +34 -0
  91. package/dist/core/toast.d.ts +112 -0
  92. package/dist/{toast-core.js → core/toast.js} +48 -2
  93. package/dist/core/tooltip.d.ts +47 -0
  94. package/dist/core/tooltip.js +51 -0
  95. package/dist/core/topbar.d.ts +41 -0
  96. package/dist/core/topbar.js +52 -0
  97. package/dist/dssoca.config.d.ts +1 -1
  98. package/dist/dssoca.config.js +4 -0
  99. package/dist/index.d.ts +14 -1
  100. package/dist/index.js +9 -1
  101. package/dist/theme.css +47 -0
  102. package/dist/toast.svelte.d.ts +2 -2
  103. package/dist/toast.svelte.js +1 -1
  104. package/dist/tokens.css +47 -0
  105. package/dist/vanilla/accordion.js +28 -29
  106. package/dist/vanilla/checkbox.d.ts +8 -0
  107. package/dist/vanilla/checkbox.js +43 -0
  108. package/dist/vanilla/delegate.d.ts +2 -0
  109. package/dist/vanilla/delegate.js +9 -0
  110. package/dist/vanilla/fields.js +37 -32
  111. package/dist/vanilla/index.d.ts +4 -0
  112. package/dist/vanilla/index.js +16 -3
  113. package/dist/vanilla/menu.js +92 -86
  114. package/dist/vanilla/modal.d.ts +3 -1
  115. package/dist/vanilla/modal.js +65 -15
  116. package/dist/vanilla/popover.d.ts +10 -0
  117. package/dist/vanilla/popover.js +129 -0
  118. package/dist/vanilla/radio.d.ts +3 -0
  119. package/dist/vanilla/radio.js +54 -0
  120. package/dist/vanilla/segmented.js +49 -51
  121. package/dist/vanilla/switch.d.ts +2 -1
  122. package/dist/vanilla/switch.js +13 -8
  123. package/dist/vanilla/tabs.d.ts +2 -0
  124. package/dist/vanilla/tabs.js +87 -0
  125. package/dist/vanilla/tierlist.d.ts +1 -1
  126. package/dist/vanilla/tierlist.js +29 -25
  127. package/dist/vanilla/toast.d.ts +2 -2
  128. package/dist/vanilla/toast.js +16 -14
  129. package/dist/vanilla/tooltip.js +35 -23
  130. package/dist/vanilla.css +349 -42
  131. package/package.json +1 -1
  132. package/dist/chart-nav.d.ts +0 -13
  133. package/dist/toast-core.d.ts +0 -61
package/dist/tokens.css CHANGED
@@ -620,3 +620,50 @@
620
620
  --ss-tier-label-font: var(--ss-size-h3);
621
621
  --ss-tier-gap: var(--ss-s-2);
622
622
  }
623
+
624
+ :root,
625
+ [data-size-variant=md] {
626
+ --ss-tabs-font: var(--ss-ui-md);
627
+ --ss-tabs-py: 9px;
628
+ --ss-tabs-px: 14px;
629
+ --ss-tabs-gap: 8px;
630
+ --ss-tabs-panel-py: 16px;
631
+ }
632
+
633
+ [data-size-variant=sm] {
634
+ --ss-tabs-font: var(--ss-ui-sm);
635
+ --ss-tabs-py: 5px;
636
+ --ss-tabs-px: 10px;
637
+ --ss-tabs-gap: 6px;
638
+ --ss-tabs-panel-py: 10px;
639
+ }
640
+
641
+ [data-size-variant=lg] {
642
+ --ss-tabs-font: var(--ss-ui-lg);
643
+ --ss-tabs-py: 12px;
644
+ --ss-tabs-px: 18px;
645
+ --ss-tabs-gap: 10px;
646
+ --ss-tabs-panel-py: 20px;
647
+ }
648
+
649
+ :root,
650
+ [data-size-variant=md] {
651
+ --ss-popover-pad: 14px;
652
+ --ss-popover-min-w: 200px;
653
+ --ss-popover-max-w: 340px;
654
+ --ss-popover-offset: 6px;
655
+ }
656
+
657
+ [data-size-variant=sm] {
658
+ --ss-popover-pad: 10px;
659
+ --ss-popover-min-w: 160px;
660
+ --ss-popover-max-w: 280px;
661
+ --ss-popover-offset: 5px;
662
+ }
663
+
664
+ [data-size-variant=lg] {
665
+ --ss-popover-pad: 18px;
666
+ --ss-popover-min-w: 240px;
667
+ --ss-popover-max-w: 400px;
668
+ --ss-popover-offset: 8px;
669
+ }
@@ -3,11 +3,21 @@
3
3
  * `aria-controls`, mirroring Accordion.svelte: single-open by default (opening one closes the
4
4
  * others), `data-ss-multiple` on the root allows several, Arrow/Home/End rove between headers.
5
5
  * Emits `ss:change` on the root with `{ value }` (open ids: string | string[] | undefined).
6
+ * The behaviour itself comes from `../core/accordion.js`, shared with the Svelte component
7
+ * (DS-0197): this file reads the state from the DOM, asks the core, and writes the result back.
6
8
  */
7
- import { on, emit, wrap, all, byId } from './delegate.js';
9
+ import { on, emit, all, byId } from './delegate.js';
10
+ import { accordionHeaderAttrs, accordionHeaderKey, accordionToggle, accordionValue, } from '../core/accordion.js';
8
11
  const HEAD = '.ss-accordion .head[aria-controls]';
12
+ /** The root's own headers (not those of a nested accordion), in DOM order. */
13
+ function heads(root) {
14
+ return all(root, '.head[aria-controls]').filter((h) => h.closest('.ss-accordion') === root);
15
+ }
16
+ const isOpen = (head) => head.getAttribute('aria-expanded') === 'true';
17
+ /** A section's id on the plain-HTML path is its panel id (`aria-controls`). */
18
+ const idOf = (head) => head.getAttribute('aria-controls');
9
19
  function setOpen(head, open) {
10
- head.setAttribute('aria-expanded', String(open));
20
+ head.setAttribute('aria-expanded', accordionHeaderAttrs(open)['aria-expanded']);
11
21
  head.closest('.item')?.classList.toggle('open', open);
12
22
  const panel = byId(head.getAttribute('aria-controls'));
13
23
  if (!panel)
@@ -18,23 +28,20 @@ function setOpen(head, open) {
18
28
  panel.toggleAttribute('inert', !open);
19
29
  }
20
30
  export function toggleAccordion(head) {
21
- if (head.getAttribute('aria-disabled') === 'true')
22
- return;
23
31
  const root = head.closest('.ss-accordion');
24
32
  if (!root)
25
33
  return;
26
34
  const multiple = root.hasAttribute('data-ss-multiple');
27
- const wasOpen = head.getAttribute('aria-expanded') === 'true';
28
- const heads = all(root, '.head[aria-controls]').filter((h) => h.closest('.ss-accordion') === root);
29
- if (!wasOpen && !multiple)
30
- for (const h of heads)
31
- if (h !== head)
32
- setOpen(h, false);
33
- setOpen(head, !wasOpen);
34
- const openIds = heads
35
- .filter((h) => h.getAttribute('aria-expanded') === 'true')
36
- .map((h) => h.getAttribute('aria-controls'));
37
- emit(root, 'ss:change', { value: multiple ? openIds : openIds[0] });
35
+ const list = heads(root);
36
+ // The DOM is the store: read the open ids, ask the core, write the result back.
37
+ const next = accordionToggle({ open: list.filter(isOpen).map(idOf), multiple }, idOf(head), head.getAttribute('aria-disabled') === 'true');
38
+ if (!next)
39
+ return;
40
+ for (const h of list)
41
+ setOpen(h, next.includes(idOf(h)));
42
+ // Reported in DOM order, whatever order the sections were opened in.
43
+ const openIds = list.map(idOf).filter((id) => next.includes(id));
44
+ emit(root, 'ss:change', { value: accordionValue(openIds, multiple) });
38
45
  }
39
46
  export function installAccordion() {
40
47
  on('click', HEAD, (head) => toggleAccordion(head));
@@ -42,20 +49,12 @@ export function installAccordion() {
42
49
  const root = head.closest('.ss-accordion');
43
50
  if (!root)
44
51
  return;
45
- const heads = all(root, '.head[aria-controls]').filter((h) => h.closest('.ss-accordion') === root);
46
- const i = heads.indexOf(head);
47
- let target = -1;
48
- if (e.key === 'ArrowDown')
49
- target = wrap(i + 1, heads.length);
50
- else if (e.key === 'ArrowUp')
51
- target = wrap(i - 1, heads.length);
52
- else if (e.key === 'Home')
53
- target = 0;
54
- else if (e.key === 'End')
55
- target = heads.length - 1;
56
- if (target < 0)
52
+ const list = heads(root);
53
+ const result = accordionHeaderKey(list.length, list.indexOf(head), e.key);
54
+ if (!result)
57
55
  return;
58
- e.preventDefault();
59
- heads[target]?.focus();
56
+ if (result.preventDefault)
57
+ e.preventDefault();
58
+ list[result.focus]?.focus();
60
59
  });
61
60
  }
@@ -0,0 +1,8 @@
1
+ /** Write a state to a checkbox (property + `data-indeterminate`). Emits nothing. */
2
+ export declare function setCheckbox(input: HTMLInputElement, state: {
3
+ checked?: boolean;
4
+ indeterminate?: boolean;
5
+ }): void;
6
+ /** Copy `data-indeterminate="true"` onto the `indeterminate` property under `root`. */
7
+ export declare function mountCheckboxes(root?: ParentNode): void;
8
+ export declare function installCheckbox(): void;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Checkbox (DS-0197) — `.ss-checkbox .input[type=checkbox]` is a native checkbox, so toggling,
3
+ * Space, label presses and form submission need no script. This module adds what HTML cannot
4
+ * express: the mixed state (`data-indeterminate="true"` on the input → the `indeterminate`
5
+ * property, applied by `mount()`), the shared rule that a mixed checkbox toggles to checked, and
6
+ * an `ss:change` event on the root with `{ checked }`. No `reason`: the browser reports a press
7
+ * on the box, on the label and Space as the same `change` event. The decision comes from
8
+ * `../core/checkbox.js`, shared with the Svelte component; state is read from the DOM.
9
+ */
10
+ import { on, emit, all, setAttrs } from './delegate.js';
11
+ import { checkboxInputAttrs, checkboxToggle } from '../core/checkbox.js';
12
+ const INPUT = '.ss-checkbox .input[type="checkbox"]';
13
+ /** Write a state to a checkbox (property + `data-indeterminate`). Emits nothing. */
14
+ export function setCheckbox(input, state) {
15
+ if (state.checked !== undefined)
16
+ input.checked = state.checked;
17
+ if (state.indeterminate !== undefined) {
18
+ input.indeterminate = state.indeterminate;
19
+ setAttrs(input, checkboxInputAttrs(state.indeterminate));
20
+ }
21
+ }
22
+ /** Copy `data-indeterminate="true"` onto the `indeterminate` property under `root`. */
23
+ export function mountCheckboxes(root = document) {
24
+ for (const input of all(root, `${INPUT}[data-indeterminate="true"]`)) {
25
+ input.indeterminate = true;
26
+ }
27
+ }
28
+ export function installCheckbox() {
29
+ on('change', INPUT, (el) => {
30
+ const input = el;
31
+ // The browser has already flipped `checked` and cleared `indeterminate`; the state from
32
+ // before the press is the inverse value plus the attribute the markup still carries.
33
+ const next = checkboxToggle({
34
+ checked: !input.checked,
35
+ indeterminate: input.dataset.indeterminate === 'true',
36
+ disabled: input.disabled,
37
+ });
38
+ if (!next)
39
+ return;
40
+ setCheckbox(input, next);
41
+ emit(input.closest('.ss-checkbox') ?? input, 'ss:change', { checked: next.checked });
42
+ });
43
+ }
@@ -13,4 +13,6 @@ export declare function wrap(i: number, n: number): number;
13
13
  export declare function all<E extends Element = HTMLElement>(root: ParentNode, selector: string): E[];
14
14
  /** Resolve an `aria-controls` / `#id` reference, preferring the nearest root. */
15
15
  export declare function byId(id: string | null): HTMLElement | null;
16
+ /** Write a core's attribute bag onto an element; `undefined` removes the attribute. */
17
+ export declare function setAttrs(el: Element, attrs: Record<string, string | number | undefined>): void;
16
18
  export {};
@@ -31,3 +31,12 @@ export function byId(id) {
31
31
  return null;
32
32
  return document.getElementById(id.startsWith('#') ? id.slice(1) : id);
33
33
  }
34
+ /** Write a core's attribute bag onto an element; `undefined` removes the attribute. */
35
+ export function setAttrs(el, attrs) {
36
+ for (const [name, value] of Object.entries(attrs)) {
37
+ if (value === undefined)
38
+ el.removeAttribute(name);
39
+ else
40
+ el.setAttribute(name, String(value));
41
+ }
42
+ }
@@ -4,76 +4,81 @@
4
4
  * - Input `clearable`: `.ss-field .clear` empties `.ss-input`, refocuses it and hides itself;
5
5
  * typing shows it again (Input.svelte removes the button entirely — vanilla toggles `hidden`).
6
6
  * - NumberField steppers: `.ss-numberfield .step.dec/.inc` nudge by `step`, clamped to
7
- * `min`/`max` (same `nudge`/`clamp` as the component). At a bound a stepper becomes an
7
+ * `min`/`max` (decided in `core/number-field.ts`, like the component). At a bound a stepper becomes an
8
8
  * `aria-disabled` no-op (still focusable, so focus never drops to <body>); it is natively
9
9
  * `disabled` only when the input is disabled/readonly. Each nudge writes the new value to
10
10
  * the field's polite `.live` region.
11
11
  * - Textarea autosize: `.ss-textarea .field.autosize` grows with content. Browsers with
12
12
  * `field-sizing: content` do it in CSS; the JS `scrollHeight` sync is the fallback.
13
13
  */
14
- import { on, all } from './delegate.js';
14
+ import { on, all, setAttrs } from './delegate.js';
15
+ import { inputClear, inputShowClear } from '../core/input.js';
16
+ import { numberFieldAnnouncement, numberFieldOption, numberFieldParse, numberFieldStep, numberFieldStepperAttrs, } from '../core/number-field.js';
15
17
  const fire = (el, type) => el.dispatchEvent(new Event(type, { bubbles: true }));
16
18
  // ── Input clearable ─────────────────────────────────────────────────────────
19
+ // The decisions come from `../core/input.js`, shared with Input.svelte; state is read from the DOM.
20
+ const clearState = (input) => ({
21
+ value: input.value,
22
+ readonly: input.readOnly,
23
+ disabled: input.disabled,
24
+ });
17
25
  function syncClear(input) {
18
26
  const btn = input.closest('.control')?.querySelector('.clear');
19
27
  if (btn)
20
- btn.hidden = !input.value || input.readOnly || input.disabled;
28
+ btn.hidden = !inputShowClear(clearState(input));
21
29
  }
22
30
  export function clearInput(btn) {
23
31
  const input = btn.closest('.control')?.querySelector('.ss-input');
24
32
  if (!input)
25
33
  return;
26
- input.value = '';
34
+ const result = inputClear(clearState(input));
35
+ if (!result)
36
+ return;
37
+ input.value = result.value;
27
38
  fire(input, 'input');
28
39
  syncClear(input);
29
- input.focus();
40
+ if (result.focusInput)
41
+ input.focus();
30
42
  }
31
43
  // ── NumberField steppers ───────────────────────────────────────────────────
32
- const num = (s) => (s == null || s === '' ? null : Number(s));
44
+ // Parsing, clamping, stepping and the stepper state come from `../core/number-field.js`,
45
+ // shared with NumberField.svelte; this side only reads the input and writes the result back.
46
+ const numberState = (input) => ({
47
+ value: numberFieldParse(input.value, input.valueAsNumber),
48
+ min: numberFieldOption(input.getAttribute('min')),
49
+ max: numberFieldOption(input.getAttribute('max')),
50
+ step: numberFieldOption(input.getAttribute('step')),
51
+ locked: input.disabled || input.readOnly,
52
+ });
33
53
  function syncSteppers(input) {
34
54
  const control = input.closest('.control');
35
55
  if (!control)
36
56
  return;
37
- const v = input.value === '' ? null : input.valueAsNumber;
38
- const min = num(input.getAttribute('min'));
39
- const max = num(input.getAttribute('max'));
40
- const locked = input.disabled || input.readOnly;
41
- const dec = control.querySelector('.step.dec');
42
- const inc = control.querySelector('.step.inc');
43
- const bound = (btn, atBound) => {
57
+ const state = numberState(input);
58
+ const apply = (btn, dir) => {
44
59
  if (!btn)
45
60
  return;
46
- btn.disabled = locked;
47
- if (!locked && atBound)
48
- btn.setAttribute('aria-disabled', 'true');
49
- else
50
- btn.removeAttribute('aria-disabled');
61
+ const { disabled, ...aria } = numberFieldStepperAttrs(state, dir);
62
+ btn.disabled = disabled;
63
+ setAttrs(btn, aria);
51
64
  };
52
- bound(dec, v != null && min != null && v <= min);
53
- bound(inc, v != null && max != null && v >= max);
65
+ apply(control.querySelector('.step.dec'), -1);
66
+ apply(control.querySelector('.step.inc'), 1);
54
67
  }
55
68
  export function nudgeNumber(btn) {
56
69
  const input = btn.closest('.control')?.querySelector('.ss-input');
57
70
  if (!input || btn.disabled || btn.getAttribute('aria-disabled') === 'true')
58
71
  return;
59
- const dir = btn.classList.contains('inc') ? 1 : -1;
60
- const min = num(input.getAttribute('min'));
61
- const max = num(input.getAttribute('max'));
62
- const step = num(input.getAttribute('step')) ?? 1;
63
- const current = input.value === '' || Number.isNaN(input.valueAsNumber) ? null : input.valueAsNumber;
64
- const base = current ?? (dir > 0 ? (min ?? 0) : (max ?? 0));
65
- let next = base + dir * step;
66
- if (min != null && next < min)
67
- next = min;
68
- if (max != null && next > max)
69
- next = max;
72
+ const next = numberFieldStep(numberState(input), btn.classList.contains('inc') ? 1 : -1);
73
+ if (next === null)
74
+ return;
70
75
  input.value = String(next);
71
76
  fire(input, 'input');
72
77
  fire(input, 'change');
73
78
  syncSteppers(input);
74
79
  const live = input.closest('.ss-numberfield')?.querySelector('.live');
75
80
  if (live)
76
- live.textContent = input.value;
81
+ live.textContent = numberFieldAnnouncement(next);
77
82
  }
78
83
  // ── Textarea autosize ──────────────────────────────────────────────────────
79
84
  export const supportsFieldSizing = typeof CSS !== 'undefined' &&
@@ -9,7 +9,11 @@ export { showTooltip, hideTooltip } from './tooltip.js';
9
9
  export { toggleSwitch } from './switch.js';
10
10
  export { selectSegment } from './segmented.js';
11
11
  export { toggleGrab, readPlacements } from './tierlist.js';
12
+ export { selectTab } from './tabs.js';
13
+ export { openPopover, closePopover } from './popover.js';
12
14
  export { clearInput, nudgeNumber, autosize } from './fields.js';
15
+ export { setCheckbox } from './checkbox.js';
16
+ export { selectRadio } from './radio.js';
13
17
  export { applyDesignConfig, designAttributes, getDesignConfig, paletteToCss, type DesignConfig, type ColorTheme, type Size, } from '../config.js';
14
18
  /** Hydrate icon placeholders and initialise setup-type behaviours under `root`. */
15
19
  export declare function mount(root?: ParentNode): void;
@@ -3,9 +3,9 @@
3
3
  * consumption path. Importing this module wires every behaviour once via document-level event
4
4
  * delegation (so markup added later just works) and runs `mount()` when the DOM is ready.
5
5
  *
6
- * <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.20/dist/theme.css">
7
- * <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.20/dist/vanilla.css">
8
- * <script type="module" src="https://cdn.jsdelivr.net/npm/dssoca@0.20/dist/vanilla/index.js"></script>
6
+ * <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.21/dist/theme.css">
7
+ * <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dssoca@0.21/dist/vanilla.css">
8
+ * <script type="module" src="https://cdn.jsdelivr.net/npm/dssoca@0.21/dist/vanilla/index.js"></script>
9
9
  *
10
10
  * Call `mount(root)` after injecting HTML that contains `[data-ss-icon]` placeholders or
11
11
  * autosizing textareas. Nothing here imports Svelte or a `.svelte` module.
@@ -17,7 +17,11 @@ import { installTooltip } from './tooltip.js';
17
17
  import { installSwitch } from './switch.js';
18
18
  import { installSegmented } from './segmented.js';
19
19
  import { installTierlist } from './tierlist.js';
20
+ import { installTabs } from './tabs.js';
21
+ import { installPopover } from './popover.js';
20
22
  import { installFields, mountFields } from './fields.js';
23
+ import { installCheckbox, mountCheckboxes } from './checkbox.js';
24
+ import { installRadio } from './radio.js';
21
25
  import { hydrateIcons } from './icons.js';
22
26
  export { toast, toasts } from './toast.js';
23
27
  export { iconSvg, hydrateIcons } from './icons.js';
@@ -29,12 +33,17 @@ export { showTooltip, hideTooltip } from './tooltip.js';
29
33
  export { toggleSwitch } from './switch.js';
30
34
  export { selectSegment } from './segmented.js';
31
35
  export { toggleGrab, readPlacements } from './tierlist.js';
36
+ export { selectTab } from './tabs.js';
37
+ export { openPopover, closePopover } from './popover.js';
32
38
  export { clearInput, nudgeNumber, autosize } from './fields.js';
39
+ export { setCheckbox } from './checkbox.js';
40
+ export { selectRadio } from './radio.js';
33
41
  export { applyDesignConfig, designAttributes, getDesignConfig, paletteToCss, } from '../config.js';
34
42
  /** Hydrate icon placeholders and initialise setup-type behaviours under `root`. */
35
43
  export function mount(root = document) {
36
44
  hydrateIcons(root);
37
45
  mountFields(root);
46
+ mountCheckboxes(root);
38
47
  }
39
48
  const FLAG = '__dssocaVanilla';
40
49
  /** Register every delegated behaviour once per document. Safe to call repeatedly. */
@@ -52,7 +61,11 @@ export function install() {
52
61
  installSwitch();
53
62
  installSegmented();
54
63
  installTierlist();
64
+ installTabs();
65
+ installPopover();
55
66
  installFields();
67
+ installCheckbox();
68
+ installRadio();
56
69
  if (document.readyState === 'loading') {
57
70
  document.addEventListener('DOMContentLoaded', () => mount(), { once: true });
58
71
  }
@@ -1,32 +1,46 @@
1
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`.
2
+ * Menu (DS-0148) — Menu.svelte's open/close + roving-focus model over the exact same DOM:
3
+ * `.ss-menu > .trigger[aria-expanded][aria-controls]` and `.panel[role=menu] > .item`.
4
+ * The behaviour itself comes from `../core/menu.js`, shared with the Svelte component
5
+ * (DS-0198): this file reads the state from the DOM, asks the core, and writes the result back.
4
6
  * 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. A panel with neither `aria-label` nor `aria-labelledby` gets
8
- * `aria-labelledby` pointing at its trigger on first open (an id is minted if needed).
7
+ * to the trigger. Emits on the root: `ss:select` with `{ index, value }` (`value` is the
8
+ * item's `data-value`, when authored) and `ss:openchange` with `{ open, reason }`. For
9
+ * `menuitemradio` items the check marker moves to the activated item. A panel with neither
10
+ * `aria-label` nor `aria-labelledby` gets `aria-labelledby` pointing at its trigger on first
11
+ * open (an id is minted if needed).
9
12
  */
10
- import { on, emit, all } from './delegate.js';
13
+ import { on, emit, all, setAttrs } from './delegate.js';
11
14
  import { iconSvg } from './icons.js';
15
+ import { menuClose, menuItemPress, menuOpen, menuOutsidePress, menuPanelAttrs, menuPanelKey, menuTriggerAttrs, menuTriggerKey, menuTriggerPress, } from '../core/menu.js';
12
16
  const TRIGGER = '.ss-menu > .trigger';
13
17
  const PANEL = '.ss-menu > .panel[role="menu"]';
14
18
  function parts(el) {
15
19
  const root = el.closest('.ss-menu');
16
- const trigger = root?.querySelector(':scope > .trigger') ?? null;
17
- const panel = root?.querySelector(':scope > .panel') ?? null;
18
- return { root, trigger, panel };
20
+ const trigger = root?.querySelector(':scope > .trigger');
21
+ const panel = root?.querySelector(':scope > .panel');
22
+ return root && trigger && panel ? { root, trigger, panel } : null;
19
23
  }
20
24
  function items(panel) {
21
25
  return all(panel, '.item').filter((i) => i.closest('.panel') === panel);
22
26
  }
23
- function enabled(panel) {
24
- return items(panel).filter((i) => !i.disabled && i.getAttribute('aria-disabled') !== 'true');
27
+ /** The menu's state, read from the DOM (the DOM is the store on the plain-HTML path). */
28
+ function read({ trigger, panel }) {
29
+ const list = items(panel);
30
+ return {
31
+ open: trigger.getAttribute('aria-expanded') === 'true',
32
+ active: list.indexOf(document.activeElement),
33
+ enabled: list
34
+ .map((i, index) => (i.disabled || i.getAttribute('aria-disabled') === 'true' ? -1 : index))
35
+ .filter((index) => index >= 0),
36
+ };
25
37
  }
26
- function focusItem(panel, item) {
38
+ function focusItem(panel, index) {
39
+ const list = items(panel);
40
+ const item = list[index];
27
41
  if (!item)
28
42
  return;
29
- for (const i of items(panel))
43
+ for (const i of list)
30
44
  i.tabIndex = i === item ? 0 : -1;
31
45
  item.focus();
32
46
  }
@@ -39,37 +53,63 @@ function ensureName(trigger, panel) {
39
53
  trigger.id = `ss-menu-trigger-${++autoId}`;
40
54
  panel.setAttribute('aria-labelledby', trigger.id);
41
55
  }
42
- export function openMenu(trigger, focus = 'first') {
43
- const { panel } = parts(trigger);
44
- if (!panel || trigger.getAttribute('aria-expanded') === 'true')
56
+ /** Apply a core action to the DOM. */
57
+ function run(p, action) {
58
+ if (!action)
45
59
  return;
46
- ensureName(trigger, panel);
47
- trigger.setAttribute('aria-expanded', 'true');
48
- panel.classList.add('open');
49
- panel.setAttribute('aria-hidden', 'false');
50
- queueMicrotask(() => {
51
- const list = enabled(panel);
52
- focusItem(panel, focus === 'first' ? list[0] : list[list.length - 1]);
53
- });
60
+ const { root, trigger, panel } = p;
61
+ switch (action.type) {
62
+ case 'open':
63
+ ensureName(trigger, panel);
64
+ setAttrs(trigger, menuTriggerAttrs(true));
65
+ setAttrs(panel, menuPanelAttrs(true));
66
+ panel.classList.add('open');
67
+ emit(root, 'ss:openchange', { open: true, reason: action.reason });
68
+ queueMicrotask(() => focusItem(panel, action.focus));
69
+ break;
70
+ case 'close':
71
+ setAttrs(trigger, menuTriggerAttrs(false));
72
+ setAttrs(panel, menuPanelAttrs(false));
73
+ panel.classList.remove('open');
74
+ for (const i of items(panel))
75
+ i.tabIndex = -1;
76
+ emit(root, 'ss:openchange', { open: false, reason: action.reason });
77
+ if (action.returnFocus)
78
+ trigger.focus();
79
+ break;
80
+ case 'focus':
81
+ focusItem(panel, action.index);
82
+ break;
83
+ }
54
84
  }
55
- export function closeMenu(trigger, returnFocus = true) {
56
- const { panel } = parts(trigger);
57
- if (!panel || trigger.getAttribute('aria-expanded') !== 'true')
85
+ function onKey(p, result, e) {
86
+ if (!result)
58
87
  return;
59
- trigger.setAttribute('aria-expanded', 'false');
60
- panel.classList.remove('open');
61
- panel.setAttribute('aria-hidden', 'true');
62
- for (const i of items(panel))
63
- i.tabIndex = -1;
64
- if (returnFocus)
65
- trigger.focus();
88
+ if (result.preventDefault)
89
+ e.preventDefault();
90
+ run(p, result.action);
91
+ }
92
+ export function openMenu(trigger, focus = 'first') {
93
+ const p = parts(trigger);
94
+ if (p)
95
+ run(p, menuOpen(read(p), focus));
96
+ }
97
+ export function closeMenu(trigger, returnFocus = true) {
98
+ const p = parts(trigger);
99
+ if (p)
100
+ run(p, menuClose(read(p), returnFocus));
66
101
  }
67
102
  function activate(item) {
68
- const { root, trigger, panel } = parts(item);
69
- if (!root || !trigger || !panel || item.disabled)
103
+ const p = parts(item);
104
+ if (!p)
105
+ return;
106
+ const list = items(p.panel);
107
+ const index = list.indexOf(item);
108
+ const result = menuItemPress(read(p), index);
109
+ if (!result)
70
110
  return;
71
111
  if (item.getAttribute('role') === 'menuitemradio') {
72
- for (const i of items(panel)) {
112
+ for (const i of list) {
73
113
  const on = i === item;
74
114
  i.classList.toggle('selected', on);
75
115
  i.setAttribute('aria-checked', String(on));
@@ -78,67 +118,33 @@ function activate(item) {
78
118
  marker.innerHTML = on ? iconSvg('check') : '';
79
119
  }
80
120
  }
81
- emit(root, 'ss:select', { index: items(panel).indexOf(item), value: item.dataset.value });
82
- closeMenu(trigger);
121
+ emit(p.root, 'ss:select', { index, value: item.dataset.value });
122
+ run(p, result.action);
83
123
  }
84
124
  export function installMenu() {
85
125
  on('click', TRIGGER, (trigger) => {
86
- if (trigger.getAttribute('aria-expanded') === 'true')
87
- closeMenu(trigger);
88
- else
89
- openMenu(trigger, 'first');
126
+ const p = parts(trigger);
127
+ if (p)
128
+ run(p, menuTriggerPress(read(p)));
90
129
  });
91
130
  on('keydown', TRIGGER, (trigger, e) => {
92
- if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {
93
- e.preventDefault();
94
- openMenu(trigger, 'first');
95
- }
96
- else if (e.key === 'ArrowUp') {
97
- e.preventDefault();
98
- openMenu(trigger, 'last');
99
- }
131
+ const p = parts(trigger);
132
+ if (p)
133
+ onKey(p, menuTriggerKey(read(p), e.key), e);
100
134
  });
101
135
  on('keydown', PANEL, (panel, e) => {
102
- const { trigger } = parts(panel);
103
- if (!trigger)
104
- return;
105
- const list = enabled(panel);
106
- const active = list.findIndex((i) => i === document.activeElement);
107
- const pick = (i) => focusItem(panel, list[((i % list.length) + list.length) % list.length]);
108
- switch (e.key) {
109
- case 'ArrowDown':
110
- e.preventDefault();
111
- pick(active < 0 ? 0 : active + 1);
112
- break;
113
- case 'ArrowUp':
114
- e.preventDefault();
115
- pick(active < 0 ? list.length - 1 : active - 1);
116
- break;
117
- case 'Home':
118
- e.preventDefault();
119
- pick(0);
120
- break;
121
- case 'End':
122
- e.preventDefault();
123
- pick(list.length - 1);
124
- break;
125
- case 'Escape':
126
- e.preventDefault();
127
- closeMenu(trigger);
128
- break;
129
- case 'Tab':
130
- closeMenu(trigger, false);
131
- break;
132
- }
136
+ const p = parts(panel);
137
+ if (p)
138
+ onKey(p, menuPanelKey(read(p), e.key), e);
133
139
  });
134
140
  on('click', `${PANEL} .item`, (item) => activate(item));
135
141
  document.addEventListener('pointerdown', (e) => {
136
142
  const t = e.target;
137
143
  for (const trigger of all(document, `${TRIGGER}[aria-expanded="true"]`)) {
138
- const root = trigger.closest('.ss-menu');
139
- if (root && t && root.contains(t))
144
+ const p = parts(trigger);
145
+ if (!p || (t && p.root.contains(t)))
140
146
  continue;
141
- closeMenu(trigger, false);
147
+ run(p, menuOutsidePress(read(p)));
142
148
  }
143
149
  }, true);
144
150
  }
@@ -1,7 +1,9 @@
1
+ import { type ModalReason } from '../core/modal.js';
1
2
  /** Lock page scrolling on `<html>` (ref-counted). Pair every call with `unlockScroll()`. */
2
3
  export declare function lockScroll(): void;
3
4
  /** Release one `lockScroll()`; the last release restores `<html>`'s previous `overflow`. */
4
5
  export declare function unlockScroll(): void;
5
6
  export declare function openModal(dialog: HTMLDialogElement): void;
6
- export declare function closeModal(dialog: HTMLDialogElement): void;
7
+ /** Close `dialog`; `reason` is reported on its `ss:close` event. */
8
+ export declare function closeModal(dialog: HTMLDialogElement, reason?: ModalReason): void;
7
9
  export declare function installModal(): void;