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
@@ -5,15 +5,18 @@
5
5
  * <button data-ss-modal="#confirm">Open</button>
6
6
  * <dialog class="ss-modal" id="confirm"> … <button class="close" data-ss-dismiss>×</button>
7
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`).
8
+ * A backdrop click closes unless the dialog carries `data-ss-static`; Escape is blocked
9
+ * when it carries `data-ss-no-esc` (mirrors `closeOnBackdrop` / `closeOnEsc`). Those decisions
10
+ * come from `core/modal.ts`, the same functions Modal.svelte calls. Every close emits `ss:close`
11
+ * on the dialog with `{ reason }` (escape · backdrop · button · programmatic).
10
12
  *
11
13
  * While a modal is open the page behind it must not scroll (DS-0178): `lockScroll()` sets
12
14
  * `overflow: hidden` on `<html>` and `unlockScroll()` restores it. The lock is ref-counted on
13
15
  * `<html data-ss-scroll-lock>` so stacked dialogs, and the Svelte component sharing this helper
14
16
  * from a separate bundle, release it only when the last one closes.
15
17
  */
16
- import { on, byId } from './delegate.js';
18
+ import { on, byId, emit } from './delegate.js';
19
+ import { modalBackdropPress, modalCancel, modalClosed, modalDismissPress, modalOpenerPress, } from '../core/modal.js';
17
20
  const COUNT = 'ssScrollLock';
18
21
  const PREV = 'ssScrollLockPrev';
19
22
  /** Lock page scrolling on `<html>` (ref-counted). Pair every call with `unlockScroll()`. */
@@ -52,46 +55,93 @@ function release(dialog) {
52
55
  locked.delete(dialog);
53
56
  unlockScroll();
54
57
  }
58
+ // Why a dialog is about to close, kept from the action (or the cancel) until its native `close`.
59
+ const pending = new WeakMap();
60
+ /** The core's state, read from the DOM. */
61
+ function stateOf(dialog) {
62
+ return {
63
+ open: dialog.open,
64
+ closeOnEsc: !dialog.hasAttribute('data-ss-no-esc'),
65
+ closeOnBackdrop: !dialog.hasAttribute('data-ss-static'),
66
+ };
67
+ }
55
68
  export function openModal(dialog) {
56
69
  if (dialog.open)
57
70
  return;
71
+ pending.delete(dialog);
58
72
  dialog.showModal();
59
73
  if (!locked.has(dialog)) {
60
74
  locked.add(dialog);
61
75
  lockScroll();
62
76
  }
63
77
  }
64
- export function closeModal(dialog) {
65
- if (dialog.open)
78
+ /** Close `dialog`; `reason` is reported on its `ss:close` event. */
79
+ export function closeModal(dialog, reason = 'programmatic') {
80
+ if (dialog.open) {
81
+ pending.set(dialog, reason);
66
82
  dialog.close();
83
+ }
67
84
  release(dialog);
68
85
  }
86
+ /** Apply a core action to the DOM. */
87
+ function run(dialog, action) {
88
+ if (!action)
89
+ return;
90
+ if (action.type === 'open')
91
+ openModal(dialog);
92
+ else
93
+ closeModal(dialog, action.reason);
94
+ }
69
95
  export function installModal() {
70
96
  on('click', '[data-ss-modal]', (opener, e) => {
71
97
  const target = byId(opener.getAttribute('data-ss-modal'));
72
98
  if (!(target instanceof HTMLDialogElement))
73
99
  return;
74
100
  e.preventDefault();
75
- openModal(target);
101
+ run(target, modalOpenerPress(stateOf(target)));
76
102
  });
77
103
  on('click', 'dialog.ss-modal [data-ss-dismiss]', (btn) => {
78
104
  const dialog = btn.closest('dialog.ss-modal');
79
105
  if (dialog instanceof HTMLDialogElement)
80
- closeModal(dialog);
106
+ run(dialog, modalDismissPress(stateOf(dialog)));
81
107
  });
82
- on('pointerdown', 'dialog.ss-modal', (dialog, e) => {
83
- if (e.target !== dialog || dialog.hasAttribute('data-ss-static'))
108
+ // A press that starts on the dialog itself is a backdrop hit; the dialog closes on the click
109
+ // that follows. Closing on the pointerdown would return focus to the opener and then let the
110
+ // same gesture's mousedown blur it, dropping focus on <body>. Remembering where the press
111
+ // began keeps a drag from inside the panel to the backdrop from closing.
112
+ let pressed = null;
113
+ document.addEventListener('pointerdown', (e) => {
114
+ const t = e.target;
115
+ pressed = t instanceof HTMLDialogElement && t.matches('dialog.ss-modal') ? t : null;
116
+ });
117
+ on('click', 'dialog.ss-modal', (dialog, e) => {
118
+ const hit = pressed === dialog && e.target === dialog;
119
+ pressed = null;
120
+ if (!(dialog instanceof HTMLDialogElement))
84
121
  return;
85
- closeModal(dialog);
122
+ run(dialog, modalBackdropPress(stateOf(dialog), hit));
86
123
  });
87
124
  // Native closes (Escape, `<form method="dialog">`, a direct `.close()`) release the scroll
88
125
  // lock too. `close` does not bubble — capture it.
89
126
  on('close', 'dialog.ss-modal', (dialog) => {
90
- if (dialog instanceof HTMLDialogElement)
91
- release(dialog);
127
+ if (!(dialog instanceof HTMLDialogElement))
128
+ return;
129
+ const details = modalClosed(pending.get(dialog));
130
+ pending.delete(dialog);
131
+ release(dialog);
132
+ emit(dialog, 'ss:close', details);
92
133
  }, { capture: true });
93
- // `cancel` does not bubble — capture it.
94
- on('cancel', 'dialog.ss-modal[data-ss-no-esc]', (_dialog, e) => {
95
- e.preventDefault();
134
+ // Escape fires `cancel` before the browser closes the dialog. `cancel` does not bubble —
135
+ // capture it.
136
+ on('cancel', 'dialog.ss-modal', (dialog, e) => {
137
+ if (!(dialog instanceof HTMLDialogElement))
138
+ return;
139
+ const result = modalCancel(stateOf(dialog), e.cancelable);
140
+ if (result.preventDefault)
141
+ e.preventDefault();
142
+ if (result.reason)
143
+ pending.set(dialog, result.reason);
144
+ else
145
+ pending.delete(dialog);
96
146
  }, { capture: true });
97
147
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Move focus into an opened panel: its first focusable element, else the panel itself. Shared
3
+ * with Popover.svelte. Focus lands on the panel first and is then handed to the target, retried
4
+ * over a few frames: a child with its own `visibility` transition (`transition: all`, as on
5
+ * `.ss-btn`) still computes as hidden — so refuses focus — until that transition has started.
6
+ */
7
+ export declare function focusPopoverPanel(panel: HTMLElement): void;
8
+ export declare function openPopover(trigger: HTMLElement): void;
9
+ export declare function closePopover(trigger: HTMLElement, returnFocus?: boolean): void;
10
+ export declare function installPopover(): void;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Popover (DS-0197) — Popover.svelte's non-modal panel over the exact same DOM:
3
+ * `.ss-popover > .trigger[aria-expanded][aria-controls]` and `.panel[role=dialog]`. The
4
+ * behaviour itself comes from `../core/popover.js`, shared with the Svelte component: this file
5
+ * reads the state from the DOM, asks the core, and writes the result back. Opening moves focus
6
+ * into the panel (its first focusable element, else the panel); Escape closes and returns focus
7
+ * to the trigger; an outside pointerdown or tabbing out closes without pulling focus back. A
8
+ * closed panel is `inert`. Emits `ss:openchange` on the root with `{ open, reason }`. A panel
9
+ * with neither `aria-label` nor `aria-labelledby` gets `aria-labelledby` pointing at its
10
+ * trigger on first open (an id is minted if needed).
11
+ */
12
+ import { on, emit, all, setAttrs } from './delegate.js';
13
+ import { FOCUSABLE_SELECTOR } from '../core/behaviors/focusable.js';
14
+ import { popoverClose, popoverFocusOut, popoverKey, popoverOpen, popoverOutsidePress, popoverPanelAttrs, popoverTriggerAttrs, popoverTriggerPress, } from '../core/popover.js';
15
+ const TRIGGER = '.ss-popover > .trigger';
16
+ const OPEN_TRIGGER = `${TRIGGER}[aria-expanded="true"]`;
17
+ function parts(el) {
18
+ const root = el.closest('.ss-popover');
19
+ const trigger = root?.querySelector(':scope > .trigger');
20
+ const panel = root?.querySelector(':scope > .panel');
21
+ return root && trigger && panel ? { root, trigger, panel } : null;
22
+ }
23
+ /** The popover's state, read from the DOM (the DOM is the store on the plain-HTML path). */
24
+ function read({ trigger }) {
25
+ return { open: trigger.getAttribute('aria-expanded') === 'true' };
26
+ }
27
+ let autoId = 0;
28
+ /** An unnamed `role="dialog"` panel is named by its trigger (mirrors Popover.svelte's fallback). */
29
+ function ensureName(trigger, panel) {
30
+ if (panel.hasAttribute('aria-label') || panel.hasAttribute('aria-labelledby'))
31
+ return;
32
+ if (!trigger.id)
33
+ trigger.id = `ss-popover-trigger-${++autoId}`;
34
+ panel.setAttribute('aria-labelledby', trigger.id);
35
+ }
36
+ /**
37
+ * Move focus into an opened panel: its first focusable element, else the panel itself. Shared
38
+ * with Popover.svelte. Focus lands on the panel first and is then handed to the target, retried
39
+ * over a few frames: a child with its own `visibility` transition (`transition: all`, as on
40
+ * `.ss-btn`) still computes as hidden — so refuses focus — until that transition has started.
41
+ */
42
+ export function focusPopoverPanel(panel) {
43
+ const target = panel.querySelector(FOCUSABLE_SELECTOR);
44
+ panel.focus();
45
+ if (!target)
46
+ return;
47
+ let tries = 5;
48
+ const attempt = () => {
49
+ // Focus was moved on (or the popover closed) meanwhile: leave it where it is.
50
+ if (document.activeElement !== panel)
51
+ return;
52
+ target.focus();
53
+ if (document.activeElement !== target && tries-- > 0)
54
+ requestAnimationFrame(attempt);
55
+ };
56
+ attempt();
57
+ }
58
+ /** Apply a core action to the DOM. */
59
+ function run(p, action) {
60
+ if (!action)
61
+ return;
62
+ const { root, trigger, panel } = p;
63
+ const open = action.type === 'open';
64
+ if (open)
65
+ ensureName(trigger, panel);
66
+ setAttrs(trigger, popoverTriggerAttrs(open));
67
+ setAttrs(panel, popoverPanelAttrs());
68
+ panel.toggleAttribute('inert', !open);
69
+ panel.classList.toggle('open', open);
70
+ emit(root, 'ss:openchange', { open, reason: action.reason });
71
+ if (action.type === 'open') {
72
+ queueMicrotask(() => focusPopoverPanel(panel));
73
+ }
74
+ else if (action.returnFocus) {
75
+ trigger.focus();
76
+ }
77
+ }
78
+ export function openPopover(trigger) {
79
+ const p = parts(trigger);
80
+ if (p)
81
+ run(p, popoverOpen(read(p)));
82
+ }
83
+ export function closePopover(trigger, returnFocus = true) {
84
+ const p = parts(trigger);
85
+ if (p)
86
+ run(p, popoverClose(read(p), returnFocus));
87
+ }
88
+ /** Every open popover, as parts. */
89
+ function openPopovers() {
90
+ return all(document, OPEN_TRIGGER)
91
+ .map((t) => parts(t))
92
+ .filter((p) => p !== null);
93
+ }
94
+ export function installPopover() {
95
+ on('click', TRIGGER, (trigger) => {
96
+ const p = parts(trigger);
97
+ if (p)
98
+ run(p, popoverTriggerPress(read(p)));
99
+ });
100
+ on('keydown', '.ss-popover', (root, e) => {
101
+ // Something inside (a nested menu, say) already used this key.
102
+ if (e.defaultPrevented)
103
+ return;
104
+ const p = parts(root);
105
+ const result = p && popoverKey(read(p), e.key);
106
+ if (!p || !result)
107
+ return;
108
+ if (result.preventDefault)
109
+ e.preventDefault();
110
+ run(p, result.action);
111
+ });
112
+ document.addEventListener('focusout', (e) => {
113
+ const from = e.target;
114
+ const to = e.relatedTarget;
115
+ for (const p of openPopovers()) {
116
+ if (!from || !p.root.contains(from))
117
+ continue;
118
+ run(p, popoverFocusOut(read(p), !to ? 'nowhere' : p.root.contains(to) ? 'inside' : 'outside'));
119
+ }
120
+ });
121
+ document.addEventListener('pointerdown', (e) => {
122
+ const t = e.target;
123
+ for (const p of openPopovers()) {
124
+ if (t && p.root.contains(t))
125
+ continue;
126
+ run(p, popoverOutsidePress(read(p)));
127
+ }
128
+ }, true);
129
+ }
@@ -0,0 +1,3 @@
1
+ /** Select a radio from script, exactly as a press would (emits `ss:change` when it changes). */
2
+ export declare function selectRadio(radio: HTMLInputElement): void;
3
+ export declare function installRadio(): void;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * RadioGroup (DS-0197) — `.ss-radio-group .input[type=radio]` are native radios sharing a
3
+ * `name`, so selection, arrow keys (wrapping, skipping disabled, mirrored under RTL), Space and
4
+ * form submission need no script. This module keeps the group's single tab stop where
5
+ * `../core/radio.js` says it belongs after the selection moves, and emits `ss:change` on the
6
+ * root with `{ value, index }`. No `reason`: the browser reports a press and an arrow key as the
7
+ * same `change` event. State is read from the DOM.
8
+ */
9
+ import { on, emit, all, setAttrs } from './delegate.js';
10
+ import { radioEnabled, radioInputAttrs, radioPress, radioTabStop, } from '../core/radio.js';
11
+ const INPUT = '.ss-radio-group .input[type="radio"]';
12
+ function radios(root) {
13
+ return all(root, '.input[type="radio"]').filter((r) => r.closest('.ss-radio-group') === root);
14
+ }
15
+ /** The group's state, read from the DOM (the DOM is the store on the plain-HTML path). */
16
+ function read(root, list) {
17
+ return {
18
+ selected: list.findIndex((r) => r.checked),
19
+ enabled: radioEnabled(list.map((r) => r.disabled), root.getAttribute('aria-disabled') === 'true'),
20
+ };
21
+ }
22
+ /** Apply a core action to the DOM. */
23
+ function run(root, list, action) {
24
+ if (!action)
25
+ return;
26
+ const radio = list[action.index];
27
+ if (!radio)
28
+ return;
29
+ radio.checked = true;
30
+ const tabStop = radioTabStop(read(root, list));
31
+ list.forEach((r, index) => setAttrs(r, radioInputAttrs(index, tabStop)));
32
+ if (action.changed)
33
+ emit(root, 'ss:change', { value: radio.value, index: action.index });
34
+ }
35
+ /** Select a radio from script, exactly as a press would (emits `ss:change` when it changes). */
36
+ export function selectRadio(radio) {
37
+ const root = radio.closest('.ss-radio-group');
38
+ if (!root)
39
+ return;
40
+ const list = radios(root);
41
+ run(root, list, radioPress(read(root, list), list.indexOf(radio)));
42
+ }
43
+ export function installRadio() {
44
+ on('change', INPUT, (el) => {
45
+ const root = el.closest('.ss-radio-group');
46
+ if (!root)
47
+ return;
48
+ const list = radios(root);
49
+ // The browser has already moved the selection, and a native `change` only fires when it
50
+ // did move — so the selection the core compares against is "some other option".
51
+ const before = { ...read(root, list), selected: -1 };
52
+ run(root, list, radioPress(before, list.indexOf(el)));
53
+ });
54
+ }
@@ -1,71 +1,69 @@
1
1
  /**
2
2
  * SegmentedControl (DS-0148) — radio-group selection over `.ss-segmented > .segment[role=radio]`
3
3
  * with the same roving model as SegmentedControl.svelte (Arrow/Home/End select + focus,
4
- * wrapping over enabled segments; Left/Right mirror under RTL). Emits `ss:change` on the root with `{ value, index }`;
5
- * `value` is the segment's `data-value` (vanilla-only attribute) or its label text.
4
+ * wrapping over enabled segments; Left/Right mirror under RTL). The behaviour itself comes from
5
+ * `../core/segmented.js`, shared with the Svelte component (DS-0197): this file reads the state
6
+ * from the DOM, asks the core, and writes the result back. Emits `ss:change` on the root with
7
+ * `{ value, index, reason }`; `value` is the segment's `data-value` (vanilla-only attribute) or
8
+ * its label text, `reason` is `'press'` or `'key'`.
6
9
  */
7
- import { on, emit, all } from './delegate.js';
10
+ import { on, emit, all, setAttrs } from './delegate.js';
11
+ import { segmentedItemAttrs, segmentedKey, segmentedPress, segmentedTabStop, } from '../core/segmented.js';
12
+ const SEGMENT = '.ss-segmented .segment[role="radio"]';
8
13
  function segments(root) {
9
14
  return all(root, '.segment[role="radio"]').filter((s) => s.closest('.ss-segmented') === root);
10
15
  }
16
+ /** The group's state, read from the DOM (the DOM is the store on the plain-HTML path). */
17
+ function read(root, list) {
18
+ const groupDisabled = root.getAttribute('aria-disabled') === 'true';
19
+ return {
20
+ selected: list.findIndex((s) => s.getAttribute('aria-checked') === 'true'),
21
+ enabled: groupDisabled
22
+ ? []
23
+ : list.map((s, index) => (s.disabled ? -1 : index)).filter((index) => index >= 0),
24
+ };
25
+ }
26
+ /** Apply a core action to the DOM. */
27
+ function run(root, list, action) {
28
+ if (!action)
29
+ return;
30
+ const segment = list[action.index];
31
+ if (!segment)
32
+ return;
33
+ const tabStop = segmentedTabStop({ ...read(root, list), selected: action.index });
34
+ list.forEach((s, index) => {
35
+ s.classList.toggle('selected', index === action.index);
36
+ setAttrs(s, segmentedItemAttrs(index, action.index, tabStop));
37
+ });
38
+ if (action.changed) {
39
+ const value = segment.dataset.value ?? segment.querySelector('.label')?.textContent?.trim() ?? '';
40
+ emit(root, 'ss:change', { value, index: action.index, reason: action.reason });
41
+ }
42
+ if (action.focus)
43
+ segment.focus();
44
+ }
11
45
  export function selectSegment(segment) {
12
46
  const root = segment.closest('.ss-segmented');
13
- if (!root || segment.disabled || root.getAttribute('aria-disabled') === 'true')
47
+ if (!root)
14
48
  return;
15
49
  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) });
50
+ run(root, list, segmentedPress(read(root, list), list.indexOf(segment)));
27
51
  }
28
52
  export function installSegmented() {
29
- on('click', '.ss-segmented .segment[role="radio"]', (s) => selectSegment(s));
30
- on('keydown', '.ss-segmented .segment[role="radio"]', (segment, e) => {
53
+ on('click', SEGMENT, (s) => selectSegment(s));
54
+ on('keydown', SEGMENT, (segment, e) => {
31
55
  const root = segment.closest('.ss-segmented');
32
56
  if (!root)
33
57
  return;
34
- const enabled = segments(root).filter((s) => !s.disabled);
35
- const pos = enabled.indexOf(segment);
36
- const n = enabled.length;
37
- const next = ((pos < 0 ? -1 : pos) + 1 + n) % n;
38
- const prev = ((pos < 0 ? 0 : pos) - 1 + n) % n;
39
- // RTL: the row runs right-to-left, so ArrowLeft points at the NEXT segment.
40
- // Read the inherited computed direction at keydown time; Up/Down stay logical.
58
+ const list = segments(root);
59
+ // RTL: the row runs right-to-left, so ArrowLeft points at the NEXT segment. Read the
60
+ // inherited computed direction at keydown time and hand it to the core.
41
61
  const rtl = getComputedStyle(segment).direction === 'rtl';
42
- let target;
43
- switch (e.key) {
44
- case 'ArrowRight':
45
- target = rtl ? prev : next;
46
- break;
47
- case 'ArrowLeft':
48
- target = rtl ? next : prev;
49
- break;
50
- case 'ArrowDown':
51
- target = next;
52
- break;
53
- case 'ArrowUp':
54
- target = prev;
55
- break;
56
- case 'Home':
57
- target = 0;
58
- break;
59
- case 'End':
60
- target = n - 1;
61
- break;
62
- default:
63
- return;
64
- }
65
- if (n === 0)
62
+ const result = segmentedKey(read(root, list), list.indexOf(segment), e.key, rtl);
63
+ if (!result)
66
64
  return;
67
- e.preventDefault();
68
- selectSegment(enabled[target]);
69
- enabled[target].focus();
65
+ if (result.preventDefault)
66
+ e.preventDefault();
67
+ run(root, list, result.action);
70
68
  });
71
69
  }
@@ -1,2 +1,3 @@
1
- export declare function toggleSwitch(track: HTMLButtonElement): void;
1
+ import { type SwitchReason } from '../core/switch.js';
2
+ export declare function toggleSwitch(track: HTMLButtonElement, reason?: SwitchReason): void;
2
3
  export declare function installSwitch(): void;
@@ -1,22 +1,27 @@
1
1
  /**
2
2
  * Switch (DS-0148) — flips `aria-checked` + `.on` on `.ss-switch .track[role=switch]`; clicking
3
3
  * the sibling `.label` toggles too (same target as the control, like Switch.svelte). Emits
4
- * `ss:change` on the root with `{ checked }`.
4
+ * `ss:change` on the root with `{ checked, reason }`. The decision comes from
5
+ * `../core/switch.js`, shared with the Svelte component (DS-0198); state is read from the DOM.
5
6
  */
6
- import { on, emit } from './delegate.js';
7
- export function toggleSwitch(track) {
8
- if (track.disabled)
7
+ import { on, emit, setAttrs } from './delegate.js';
8
+ import { switchToggle, switchTrackAttrs } from '../core/switch.js';
9
+ export function toggleSwitch(track, reason = 'track') {
10
+ const next = switchToggle({
11
+ checked: track.getAttribute('aria-checked') === 'true',
12
+ disabled: track.disabled,
13
+ });
14
+ if (next === null)
9
15
  return;
10
- const next = track.getAttribute('aria-checked') !== 'true';
11
- track.setAttribute('aria-checked', String(next));
16
+ setAttrs(track, switchTrackAttrs(next));
12
17
  track.classList.toggle('on', next);
13
- emit(track.closest('.ss-switch') ?? track, 'ss:change', { checked: next });
18
+ emit(track.closest('.ss-switch') ?? track, 'ss:change', { checked: next, reason });
14
19
  }
15
20
  export function installSwitch() {
16
21
  on('click', '.ss-switch .track[role="switch"]', (track) => toggleSwitch(track));
17
22
  on('click', '.ss-switch .label', (label) => {
18
23
  const track = label.closest('.ss-switch')?.querySelector('.track');
19
24
  if (track)
20
- toggleSwitch(track);
25
+ toggleSwitch(track, 'label');
21
26
  });
22
27
  }
@@ -0,0 +1,2 @@
1
+ export declare function selectTab(tab: HTMLButtonElement): void;
2
+ export declare function installTabs(): void;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Tabs (DS-0197) — the WAI-ARIA tabs pattern over the exact DOM Tabs.svelte renders:
3
+ * `.ss-tabs > .list[role=tablist] > .tab[role=tab]` plus one `.panel[role=tabpanel]` per tab
4
+ * (each tab's `aria-controls` names its panel; without it the n-th tab owns the n-th panel).
5
+ * The behaviour itself comes from `../core/tabs.js`, shared with the Svelte component: this file
6
+ * reads the state from the DOM, asks the core, and writes the result back — the selected tab's
7
+ * panel is shown, the others get `hidden`. `data-activation="manual"` on the root makes the
8
+ * arrows move focus only (Enter / Space select). Emits `ss:change` on the root with
9
+ * `{ value, index, reason }`; `value` is the tab's `data-value` (vanilla-only attribute) or its
10
+ * label text, `reason` is `'press'` or `'key'`.
11
+ */
12
+ import { on, emit, all, byId, setAttrs } from './delegate.js';
13
+ import { tabsKey, tabsPress, tabsTabAttrs, tabsTabStop, } from '../core/tabs.js';
14
+ const TAB = '.ss-tabs > .list[role="tablist"] > .tab[role="tab"]';
15
+ function parts(el) {
16
+ const root = el.closest('.ss-tabs');
17
+ if (!root)
18
+ return null;
19
+ const tabs = all(root, ':scope > .list > .tab[role="tab"]');
20
+ const own = all(root, ':scope > .panel');
21
+ const panels = tabs.map((t, i) => byId(t.getAttribute('aria-controls')) ?? own[i] ?? null);
22
+ return { root, tabs, panels };
23
+ }
24
+ /** The list's state, read from the DOM (the DOM is the store on the plain-HTML path). */
25
+ function read({ tabs }) {
26
+ return {
27
+ selected: tabs.findIndex((t) => t.getAttribute('aria-selected') === 'true'),
28
+ enabled: tabs
29
+ .map((t, index) => (t.disabled || t.getAttribute('aria-disabled') === 'true' ? -1 : index))
30
+ .filter((index) => index >= 0),
31
+ };
32
+ }
33
+ /** Apply a core action to the DOM. */
34
+ function run(p, action) {
35
+ if (!action)
36
+ return;
37
+ const tab = p.tabs[action.index];
38
+ if (!tab)
39
+ return;
40
+ if (action.type === 'select') {
41
+ const tabStop = tabsTabStop({ ...read(p), selected: action.index });
42
+ p.tabs.forEach((t, index) => {
43
+ t.classList.toggle('selected', index === action.index);
44
+ setAttrs(t, {
45
+ ...tabsTabAttrs({ index, selected: action.index, tabStop }),
46
+ // Authored wiring stays as it is.
47
+ 'aria-controls': t.getAttribute('aria-controls') ?? undefined,
48
+ });
49
+ const panel = p.panels[index];
50
+ if (panel)
51
+ panel.hidden = index !== action.index;
52
+ });
53
+ if (action.changed) {
54
+ const value = tab.dataset.value ?? tab.querySelector('.label')?.textContent?.trim() ?? '';
55
+ emit(p.root, 'ss:change', { value, index: action.index, reason: action.reason });
56
+ }
57
+ if (!action.focus)
58
+ return;
59
+ }
60
+ tab.focus();
61
+ }
62
+ export function selectTab(tab) {
63
+ const p = parts(tab);
64
+ if (p)
65
+ run(p, tabsPress(read(p), p.tabs.indexOf(tab)));
66
+ }
67
+ export function installTabs() {
68
+ on('click', TAB, (t) => selectTab(t));
69
+ on('keydown', TAB, (tab, e) => {
70
+ const p = parts(tab);
71
+ if (!p)
72
+ return;
73
+ // RTL: the list runs right-to-left, so ArrowLeft points at the NEXT tab. Read the inherited
74
+ // computed direction at keydown time and hand it to the core.
75
+ const rtl = getComputedStyle(tab).direction === 'rtl';
76
+ const activation = p.root.dataset.activation === 'manual' ? 'manual' : 'auto';
77
+ const result = tabsKey(read(p), p.tabs.indexOf(tab), e.key, {
78
+ rtl,
79
+ activation,
80
+ });
81
+ if (!result)
82
+ return;
83
+ if (result.preventDefault)
84
+ e.preventDefault();
85
+ run(p, result.action);
86
+ });
87
+ }
@@ -1,4 +1,4 @@
1
- import { type TierListPlacements, type TierListZones } from '../tierlist-core.js';
1
+ import { type TierListPlacements, type TierListZones } from '../core/tierlist.js';
2
2
  /** The zone map as the DOM currently has it. */
3
3
  export declare function readZones(root: HTMLElement): TierListZones;
4
4
  /** Public placements read from the DOM: every non-tray zone, in DOM order. */