dssoca 0.20.0 → 0.22.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 +404 -0
  23. package/dist/components/Popover.svelte.d.ts +55 -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 +41 -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 +111 -0
  72. package/dist/core/popover.js +86 -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 +199 -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 +32 -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 +364 -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
@@ -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;
@@ -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,199 @@
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
+ * Hover mode (DS-0206): `data-open-on="hover"` on the root makes it a hover card — a mouse
13
+ * resting on the trigger or panel, or focus on the trigger, peeks it open without moving focus;
14
+ * leaving closes it after a grace period; a touch tap peeks it. A press on the trigger emits
15
+ * `ss:activate` on the root when the root carries `data-ss-activate`, and toggles otherwise.
16
+ * (No collision avoidance on this path, as with Tooltip.)
17
+ */
18
+ import { on, emit, all, setAttrs } from './delegate.js';
19
+ import { FOCUSABLE_SELECTOR } from '../core/behaviors/focusable.js';
20
+ import { POPOVER_HOVER_CLOSE_DELAY, POPOVER_HOVER_OPEN_DELAY, popoverClose, popoverFocusIn, popoverFocusOut, popoverHoverEnter, popoverHoverLeave, popoverKey, popoverOpen, popoverOutsidePress, popoverPanelAttrs, popoverTriggerAttrs, popoverTriggerPress, } from '../core/popover.js';
21
+ const TRIGGER = '.ss-popover > .trigger';
22
+ const OPEN_TRIGGER = `${TRIGGER}[aria-expanded="true"]`;
23
+ function parts(el) {
24
+ const root = el.closest('.ss-popover');
25
+ const trigger = root?.querySelector(':scope > .trigger');
26
+ const panel = root?.querySelector(':scope > .panel');
27
+ return root && trigger && panel ? { root, trigger, panel } : null;
28
+ }
29
+ /** The popover's state, read from the DOM (the DOM is the store on the plain-HTML path). */
30
+ function read({ trigger }) {
31
+ return { open: trigger.getAttribute('aria-expanded') === 'true' };
32
+ }
33
+ let autoId = 0;
34
+ /** An unnamed `role="dialog"` panel is named by its trigger (mirrors Popover.svelte's fallback). */
35
+ function ensureName(trigger, panel) {
36
+ if (panel.hasAttribute('aria-label') || panel.hasAttribute('aria-labelledby'))
37
+ return;
38
+ if (!trigger.id)
39
+ trigger.id = `ss-popover-trigger-${++autoId}`;
40
+ panel.setAttribute('aria-labelledby', trigger.id);
41
+ }
42
+ /**
43
+ * Move focus into an opened panel: its first focusable element, else the panel itself. Shared
44
+ * with Popover.svelte. Focus lands on the panel first and is then handed to the target, retried
45
+ * over a few frames: a child with its own `visibility` transition (`transition: all`, as on
46
+ * `.ss-btn`) still computes as hidden — so refuses focus — until that transition has started.
47
+ */
48
+ export function focusPopoverPanel(panel) {
49
+ const target = panel.querySelector(FOCUSABLE_SELECTOR);
50
+ panel.focus();
51
+ if (!target)
52
+ return;
53
+ let tries = 5;
54
+ const attempt = () => {
55
+ // Focus was moved on (or the popover closed) meanwhile: leave it where it is.
56
+ if (document.activeElement !== panel)
57
+ return;
58
+ target.focus();
59
+ if (document.activeElement !== target && tries-- > 0)
60
+ requestAnimationFrame(attempt);
61
+ };
62
+ attempt();
63
+ }
64
+ const openOnOf = (root) => root.dataset.openOn === 'hover' ? 'hover' : 'press';
65
+ // A trigger getting focus back from Escape must not re-peek its card.
66
+ let quietFocus = false;
67
+ const timers = new WeakMap();
68
+ function clearTimer(root) {
69
+ clearTimeout(timers.get(root));
70
+ timers.delete(root);
71
+ }
72
+ /** Apply a core action to the DOM. */
73
+ function run(p, action) {
74
+ if (!action)
75
+ return;
76
+ const { root, trigger, panel } = p;
77
+ clearTimer(root);
78
+ if (action.type === 'activate') {
79
+ emit(root, 'ss:activate', {});
80
+ return;
81
+ }
82
+ const open = action.type === 'open' || action.type === 'peek';
83
+ if (open)
84
+ ensureName(trigger, panel);
85
+ setAttrs(trigger, popoverTriggerAttrs(open));
86
+ setAttrs(panel, popoverPanelAttrs());
87
+ panel.toggleAttribute('inert', !open);
88
+ panel.classList.toggle('open', open);
89
+ emit(root, 'ss:openchange', { open, reason: action.reason });
90
+ if (action.type === 'open') {
91
+ queueMicrotask(() => focusPopoverPanel(panel));
92
+ }
93
+ else if (action.type === 'close' && action.returnFocus) {
94
+ quietFocus = true;
95
+ trigger.focus();
96
+ quietFocus = false;
97
+ }
98
+ }
99
+ export function openPopover(trigger) {
100
+ const p = parts(trigger);
101
+ if (p)
102
+ run(p, popoverOpen(read(p)));
103
+ }
104
+ export function closePopover(trigger, returnFocus = true) {
105
+ const p = parts(trigger);
106
+ if (p)
107
+ run(p, popoverClose(read(p), returnFocus));
108
+ }
109
+ /** Every open popover, as parts. */
110
+ function openPopovers() {
111
+ return all(document, OPEN_TRIGGER)
112
+ .map((t) => parts(t))
113
+ .filter((p) => p !== null);
114
+ }
115
+ export function installPopover() {
116
+ // The pointer type of the press that becomes the next click ('' = keyboard).
117
+ let pressType = '';
118
+ document.addEventListener('pointerdown', (e) => (pressType = e.pointerType), true);
119
+ on('click', TRIGGER, (trigger) => {
120
+ const p = parts(trigger);
121
+ if (!p)
122
+ return;
123
+ const action = popoverTriggerPress(read(p), {
124
+ openOn: openOnOf(p.root),
125
+ pointerType: pressType,
126
+ hasAction: p.root.hasAttribute('data-ss-activate'),
127
+ });
128
+ pressType = '';
129
+ run(p, action);
130
+ });
131
+ // Hover mode: pointerover/out stand in for enter/leave (they bubble, so delegation
132
+ // works); moves between the trigger and the panel stay inside the root and are ignored.
133
+ const HOVER_ROOT = '.ss-popover[data-open-on="hover"]';
134
+ document.addEventListener('pointerover', (e) => {
135
+ if (e.pointerType !== 'mouse')
136
+ return;
137
+ const root = e.target?.closest(HOVER_ROOT);
138
+ if (!root || root.contains(e.relatedTarget))
139
+ return;
140
+ const p = parts(root);
141
+ if (!p)
142
+ return;
143
+ clearTimer(root);
144
+ if (read(p).open)
145
+ return;
146
+ timers.set(root, setTimeout(() => run(p, popoverHoverEnter(read(p))), POPOVER_HOVER_OPEN_DELAY));
147
+ });
148
+ document.addEventListener('pointerout', (e) => {
149
+ if (e.pointerType !== 'mouse')
150
+ return;
151
+ const root = e.target?.closest(HOVER_ROOT);
152
+ if (!root || root.contains(e.relatedTarget))
153
+ return;
154
+ const p = parts(root);
155
+ if (!p)
156
+ return;
157
+ clearTimer(root);
158
+ timers.set(root, setTimeout(() => run(p, popoverHoverLeave(read(p))), POPOVER_HOVER_CLOSE_DELAY));
159
+ });
160
+ document.addEventListener('focusin', (e) => {
161
+ if (quietFocus)
162
+ return;
163
+ const t = e.target;
164
+ if (!t?.matches(TRIGGER))
165
+ return;
166
+ const p = parts(t);
167
+ if (p)
168
+ run(p, popoverFocusIn(read(p), openOnOf(p.root)));
169
+ });
170
+ on('keydown', '.ss-popover', (root, e) => {
171
+ // Something inside (a nested menu, say) already used this key.
172
+ if (e.defaultPrevented)
173
+ return;
174
+ const p = parts(root);
175
+ const result = p && popoverKey(read(p), e.key);
176
+ if (!p || !result)
177
+ return;
178
+ if (result.preventDefault)
179
+ e.preventDefault();
180
+ run(p, result.action);
181
+ });
182
+ document.addEventListener('focusout', (e) => {
183
+ const from = e.target;
184
+ const to = e.relatedTarget;
185
+ for (const p of openPopovers()) {
186
+ if (!from || !p.root.contains(from))
187
+ continue;
188
+ run(p, popoverFocusOut(read(p), !to ? 'nowhere' : p.root.contains(to) ? 'inside' : 'outside'));
189
+ }
190
+ });
191
+ document.addEventListener('pointerdown', (e) => {
192
+ const t = e.target;
193
+ for (const p of openPopovers()) {
194
+ if (t && p.root.contains(t))
195
+ continue;
196
+ run(p, popoverOutsidePress(read(p)));
197
+ }
198
+ }, true);
199
+ }
@@ -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
+ }