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
@@ -28,6 +28,7 @@
28
28
  shortcuts,
29
29
  type ShortcutPlatform,
30
30
  } from '../shortcuts.svelte.js'
31
+ import { topbarRovingIndex, topbarTabKey, topbarTabs, topbarTabTabindex } from '../core/topbar.js'
31
32
  import Kbd from './Kbd.svelte'
32
33
  import Icon from './Icon.svelte'
33
34
 
@@ -108,22 +109,16 @@
108
109
  if (platform === 'other') platform = detectPlatform()
109
110
  })
110
111
 
112
+ // Behaviour lives in `core/topbar.ts`: the normalized tab list, the roving tab stop and
113
+ // what a key on a tab does are decided there.
114
+
111
115
  // DS-0080: normalize both tab shapes to one internal form. `string` tabs
112
116
  // keep id === label; object tabs default `label` to `id`.
113
- const items = $derived(
114
- tabs.map((t): { id: string; label: string; href?: string } =>
115
- typeof t === 'string'
116
- ? { id: t, label: t }
117
- : { id: t.id, label: t.label ?? t.id, href: t.href },
118
- ),
119
- )
117
+ const items = $derived(topbarTabs(tabs))
120
118
 
121
119
  // DS-0182: the roving tab stop is the active tab; when `active` matches no
122
120
  // tab, fall back to the first button tab so the strip stays reachable by Tab.
123
- const rovingIdx = $derived.by(() => {
124
- const i = items.findIndex((t) => t.id === active)
125
- return i >= 0 ? i : items.findIndex((t) => !t.href)
126
- })
121
+ const rovingIdx = $derived(topbarRovingIndex(items, active))
127
122
 
128
123
  // DS-0081: resolve the services prop to data-or-nothing.
129
124
  const svc = $derived(services === true ? DEFAULT_SERVICES : services === false ? null : services)
@@ -171,33 +166,13 @@
171
166
  // tab stop; link tabs stay in the natural tab order so they remain
172
167
  // keyboard-reachable without JS (SSR, DS-0080).
173
168
  let tabEls: (HTMLAnchorElement | HTMLButtonElement)[] = $state([])
174
- function focusTab(i: number) {
175
- const n = items.length
176
- if (!n) return
177
- const idx = ((i % n) + n) % n
178
- tabEls[idx]?.focus()
179
- }
180
169
  function onTabKeydown(e: KeyboardEvent, i: number) {
181
- switch (e.key) {
182
- case 'ArrowRight':
183
- case 'ArrowDown':
184
- e.preventDefault()
185
- focusTab(i + 1)
186
- break
187
- case 'ArrowLeft':
188
- case 'ArrowUp':
189
- e.preventDefault()
190
- focusTab(i - 1)
191
- break
192
- case 'Home':
193
- e.preventDefault()
194
- focusTab(0)
195
- break
196
- case 'End':
197
- e.preventDefault()
198
- focusTab(items.length - 1)
199
- break
200
- }
170
+ // The direction inherits from any ancestor `dir`; read it at keydown time.
171
+ const rtl = getComputedStyle(e.currentTarget as Element).direction === 'rtl'
172
+ const result = topbarTabKey(e.key, i, items.length, rtl)
173
+ if (!result) return
174
+ if (result.preventDefault) e.preventDefault()
175
+ if (result.action) tabEls[result.action.index]?.focus()
201
176
  }
202
177
  </script>
203
178
 
@@ -246,7 +221,7 @@
246
221
  type="button"
247
222
  class="tab {current ? 'active' : ''}"
248
223
  aria-current={current ? 'page' : undefined}
249
- tabindex={i === rovingIdx ? 0 : -1}
224
+ tabindex={topbarTabTabindex(tab, i, rovingIdx)}
250
225
  onclick={() => onTab?.(tab.id)}
251
226
  onkeydown={(e) => onTabKeydown(e, i)}
252
227
  >
@@ -0,0 +1,32 @@
1
+ /** The public open value: one id (single mode), a list (`multiple`), or nothing open. */
2
+ export type AccordionOpenValue = string | string[] | undefined;
3
+ export interface AccordionState {
4
+ /** Ids of the open sections. */
5
+ open: readonly string[];
6
+ /** Several sections may be open at once; otherwise opening one closes the others. */
7
+ multiple: boolean;
8
+ }
9
+ /** Normalise a public value (`value` / `defaultValue`) into a list of open ids. */
10
+ export declare function accordionOpenIds(value: AccordionOpenValue): string[];
11
+ /** Project the open ids back to the public value shape (`value`, `onChange`, `ss:change`). */
12
+ export declare function accordionValue(open: readonly string[], multiple: boolean): AccordionOpenValue;
13
+ /**
14
+ * A header was pressed: the next open ids, or `null` when the section is disabled and nothing
15
+ * changes. Closing keeps the others; opening appends (or replaces everything in single mode).
16
+ */
17
+ export declare function accordionToggle(state: AccordionState, id: string, disabled?: boolean): string[] | null;
18
+ /** A key the accordion handles: the header to focus; the browser default is always cancelled. */
19
+ export interface AccordionKeyResult {
20
+ focus: number;
21
+ preventDefault: true;
22
+ }
23
+ /**
24
+ * A key on header `index` of `count`. Focus roves over every header, wrapping, disabled ones
25
+ * included (they stay focusable so the section is discoverable). `null` = not an accordion key
26
+ * (Enter / Space activate the native button), let it through.
27
+ */
28
+ export declare function accordionHeaderKey(count: number, index: number, key: string): AccordionKeyResult | null;
29
+ export declare function accordionHeaderAttrs(expanded: boolean, disabled?: boolean): {
30
+ readonly 'aria-expanded': "true" | "false";
31
+ readonly 'aria-disabled': "true" | undefined;
32
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Accordion core (DS-0197) — which sections are open after a header press, and where the arrow
3
+ * keys move focus, decided once for Accordion.svelte and `vanilla/accordion.ts`. Pure functions:
4
+ * no DOM, no Svelte. The caller owns the store (a `$state` Set / the `aria-expanded` attributes).
5
+ */
6
+ import { rovingStep } from './behaviors/roving.js';
7
+ /** Normalise a public value (`value` / `defaultValue`) into a list of open ids. */
8
+ export function accordionOpenIds(value) {
9
+ if (value == null)
10
+ return [];
11
+ return Array.isArray(value) ? [...new Set(value)] : [value];
12
+ }
13
+ /** Project the open ids back to the public value shape (`value`, `onChange`, `ss:change`). */
14
+ export function accordionValue(open, multiple) {
15
+ return multiple ? [...open] : open[0];
16
+ }
17
+ /**
18
+ * A header was pressed: the next open ids, or `null` when the section is disabled and nothing
19
+ * changes. Closing keeps the others; opening appends (or replaces everything in single mode).
20
+ */
21
+ export function accordionToggle(state, id, disabled = false) {
22
+ if (disabled)
23
+ return null;
24
+ if (state.open.includes(id))
25
+ return state.open.filter((o) => o !== id);
26
+ return state.multiple ? [...state.open, id] : [id];
27
+ }
28
+ const MOVES = {
29
+ ArrowDown: 'next',
30
+ ArrowUp: 'prev',
31
+ Home: 'first',
32
+ End: 'last',
33
+ };
34
+ /**
35
+ * A key on header `index` of `count`. Focus roves over every header, wrapping, disabled ones
36
+ * included (they stay focusable so the section is discoverable). `null` = not an accordion key
37
+ * (Enter / Space activate the native button), let it through.
38
+ */
39
+ export function accordionHeaderKey(count, index, key) {
40
+ const move = Object.hasOwn(MOVES, key) ? MOVES[key] : undefined;
41
+ if (!move || count <= 0)
42
+ return null;
43
+ const all = Array.from({ length: count }, (_, i) => i);
44
+ return { focus: rovingStep(all, index, move), preventDefault: true };
45
+ }
46
+ // --- attributes ---------------------------------------------------------------
47
+ // Strings, not booleans, so the Svelte spread and the vanilla `setAttribute` write the same DOM.
48
+ export function accordionHeaderAttrs(expanded, disabled = false) {
49
+ return {
50
+ 'aria-expanded': expanded ? 'true' : 'false',
51
+ 'aria-disabled': disabled ? 'true' : undefined,
52
+ };
53
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * What counts as focusable (DS-0197): the selector a surface uses to find where focus goes when
3
+ * it opens. A string only — the caller runs the query, so the core stays DOM-free.
4
+ */
5
+ export declare const FOCUSABLE_SELECTOR: string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * What counts as focusable (DS-0197): the selector a surface uses to find where focus goes when
3
+ * it opens. A string only — the caller runs the query, so the core stays DOM-free.
4
+ */
5
+ export const FOCUSABLE_SELECTOR = [
6
+ 'a[href]',
7
+ 'button:not([disabled])',
8
+ 'input:not([disabled]):not([type="hidden"])',
9
+ 'select:not([disabled])',
10
+ 'textarea:not([disabled])',
11
+ 'summary',
12
+ '[contenteditable]:not([contenteditable="false"])',
13
+ '[tabindex]:not([tabindex="-1"])',
14
+ ].join(', ');
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Roving focus (DS-0198): a composite widget is ONE tab stop and the arrow keys move focus
3
+ * between its enabled items. Pure index maths — the caller owns the DOM focus call.
4
+ */
5
+ export type RovingMove = 'next' | 'prev' | 'first' | 'last';
6
+ /**
7
+ * The index to focus after `move`. `enabled` holds the focusable item indexes in DOM order;
8
+ * `active` is the currently focused index (`-1` or a disabled index when none is). Wraps at
9
+ * both ends. Returns `-1` when nothing is focusable.
10
+ */
11
+ export declare function rovingStep(enabled: readonly number[], active: number, move: RovingMove): number;
12
+ /** Roving tabindex for one item: the active item is the tab stop, the rest are skipped. */
13
+ export declare function rovingTabindex(index: number, active: number): 0 | -1;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Roving focus (DS-0198): a composite widget is ONE tab stop and the arrow keys move focus
3
+ * between its enabled items. Pure index maths — the caller owns the DOM focus call.
4
+ */
5
+ /**
6
+ * The index to focus after `move`. `enabled` holds the focusable item indexes in DOM order;
7
+ * `active` is the currently focused index (`-1` or a disabled index when none is). Wraps at
8
+ * both ends. Returns `-1` when nothing is focusable.
9
+ */
10
+ export function rovingStep(enabled, active, move) {
11
+ if (enabled.length === 0)
12
+ return -1;
13
+ const first = enabled[0];
14
+ const last = enabled[enabled.length - 1];
15
+ switch (move) {
16
+ case 'first':
17
+ return first;
18
+ case 'last':
19
+ return last;
20
+ case 'next':
21
+ return active < 0 ? first : (enabled.find((i) => i > active) ?? first);
22
+ case 'prev':
23
+ return active < 0 ? last : ([...enabled].reverse().find((i) => i < active) ?? last);
24
+ }
25
+ }
26
+ /** Roving tabindex for one item: the active item is the tab stop, the rest are skipped. */
27
+ export function rovingTabindex(index, active) {
28
+ return index === active ? 0 : -1;
29
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * BottomNav core (DS-0197) — which element a tab is, what pressing it does, and the attributes
3
+ * that reflect its state. Pure functions; BottomNav.svelte renders the result. No DOM, no Svelte.
4
+ */
5
+ /** What the decisions need to know about one tab. */
6
+ export interface BottomNavTab {
7
+ id: string;
8
+ label: string;
9
+ href?: string;
10
+ badge?: string | number;
11
+ disabled?: boolean;
12
+ }
13
+ /**
14
+ * A tab is a real link only when it has an `href` and is enabled. A disabled `href` tab is a
15
+ * (natively disabled) button: reliably inert and out of the tab order, where a dead `<a>` would
16
+ * need tabindex/role juggling.
17
+ */
18
+ export declare function bottomNavTabElement(tab: BottomNavTab): 'a' | 'button';
19
+ export interface BottomNavPressResult {
20
+ /** Fire `onSelect` with the tab id. */
21
+ select: boolean;
22
+ /** Cancel the browser default (navigation / button activation). */
23
+ preventDefault: boolean;
24
+ }
25
+ /**
26
+ * A tab was pressed. A disabled tab is inert: nothing is selected and nothing navigates. An
27
+ * `href` tab navigates natively and still selects (SPA fallback); a tab without one only selects.
28
+ */
29
+ export declare function bottomNavPress(tab: BottomNavTab): BottomNavPressResult;
30
+ export declare function bottomNavHasBadge(tab: BottomNavTab): boolean;
31
+ /** State attributes of one tab (either element). */
32
+ export declare function bottomNavTabAttrs(tab: BottomNavTab, active: string | undefined): {
33
+ readonly 'aria-current': "page" | undefined;
34
+ readonly 'aria-label': string | undefined;
35
+ readonly 'aria-disabled': "true" | undefined;
36
+ };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * BottomNav core (DS-0197) — which element a tab is, what pressing it does, and the attributes
3
+ * that reflect its state. Pure functions; BottomNav.svelte renders the result. No DOM, no Svelte.
4
+ */
5
+ /**
6
+ * A tab is a real link only when it has an `href` and is enabled. A disabled `href` tab is a
7
+ * (natively disabled) button: reliably inert and out of the tab order, where a dead `<a>` would
8
+ * need tabindex/role juggling.
9
+ */
10
+ export function bottomNavTabElement(tab) {
11
+ return tab.href && !tab.disabled ? 'a' : 'button';
12
+ }
13
+ /**
14
+ * A tab was pressed. A disabled tab is inert: nothing is selected and nothing navigates. An
15
+ * `href` tab navigates natively and still selects (SPA fallback); a tab without one only selects.
16
+ */
17
+ export function bottomNavPress(tab) {
18
+ if (tab.disabled)
19
+ return { select: false, preventDefault: true };
20
+ return { select: true, preventDefault: !tab.href };
21
+ }
22
+ export function bottomNavHasBadge(tab) {
23
+ return tab.badge != null && tab.badge !== '';
24
+ }
25
+ /** State attributes of one tab (either element). */
26
+ export function bottomNavTabAttrs(tab, active) {
27
+ return {
28
+ 'aria-current': tab.id === active ? 'page' : undefined,
29
+ // The badge is folded into the accessible name so the count is not lost to AT.
30
+ 'aria-label': bottomNavHasBadge(tab) ? `${tab.label}, ${tab.badge}` : undefined,
31
+ 'aria-disabled': tab.disabled ? 'true' : undefined,
32
+ };
33
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Shared keyboard contract for the chart components (Chart, BoxPlot, BumpChart, ScatterPlot,
3
+ * Heatmap): a chart is ONE tab stop, and the arrow keys move focus between its data marks
4
+ * (roving tabindex). See agile DS-0161.
5
+ *
6
+ * - 1-D (default): ArrowRight/ArrowDown → next mark, ArrowLeft/ArrowUp → previous.
7
+ * - 2-D (`cols` given, e.g. Heatmap): ArrowLeft/ArrowRight move within a row, ArrowUp/ArrowDown
8
+ * move by `cols`.
9
+ * - Home/End → first/last mark. Movement clamps at the edges (no wrap-around).
10
+ *
11
+ * Returns the new index, or `null` when the key is not a navigation key (let it through).
12
+ */
13
+ export declare function chartNavStep(key: string, index: number, count: number, cols?: number): number | null;
14
+ /** What a key on a chart does: move focus to another mark, or dismiss the tooltip. */
15
+ export type ChartAction = {
16
+ type: 'focus';
17
+ index: number;
18
+ } | {
19
+ type: 'dismiss';
20
+ };
21
+ /** A key the chart handles: its action, and whether the browser default must be cancelled. */
22
+ export interface ChartKeyResult {
23
+ action: ChartAction;
24
+ preventDefault: boolean;
25
+ }
26
+ export interface ChartMarkState {
27
+ /** Index of the mark that has focus. */
28
+ index: number;
29
+ /** Number of marks in the chart. */
30
+ count: number;
31
+ /** Columns of a 2-D grid (Heatmap); leave out for a 1-D chart. */
32
+ cols?: number;
33
+ /**
34
+ * How the focused mark treats Escape. Leave out when the mark leaves Escape to the window
35
+ * handler ({@link chartWindowKey}). `'dismiss'` hides the tooltip from the mark and lets the
36
+ * key carry on. `'consume'` also cancels the key, but only while a tooltip is showing.
37
+ */
38
+ escape?: 'dismiss' | 'consume';
39
+ /** A tooltip is showing. Only read for `escape: 'consume'`. */
40
+ tooltipOpen?: boolean;
41
+ }
42
+ /**
43
+ * A key on a focused mark. `null` = not a chart key, let it through.
44
+ * SVG geometry does not mirror in RTL, so Left/Right stay physical.
45
+ */
46
+ export declare function chartMarkKey(state: ChartMarkState, key: string): ChartKeyResult | null;
47
+ /**
48
+ * A key anywhere on the page while a chart is mounted: Escape dismisses the tooltip, including
49
+ * one opened by hover with focus elsewhere (WCAG 1.4.13). `null` = nothing to do.
50
+ */
51
+ export declare function chartWindowKey(tooltipOpen: boolean, key: string): ChartAction | null;
52
+ /** The mark that is the chart's single tab stop: the last focused one, clamped to the marks. */
53
+ export declare function chartTabStop(focusIndex: number, count: number): number;
@@ -33,3 +33,30 @@ export function chartNavStep(key, index, count, cols) {
33
33
  return null;
34
34
  }
35
35
  }
36
+ /**
37
+ * A key on a focused mark. `null` = not a chart key, let it through.
38
+ * SVG geometry does not mirror in RTL, so Left/Right stay physical.
39
+ */
40
+ export function chartMarkKey(state, key) {
41
+ if (key === 'Escape') {
42
+ if (state.escape === 'dismiss')
43
+ return { action: { type: 'dismiss' }, preventDefault: false };
44
+ if (state.escape === 'consume' && state.tooltipOpen) {
45
+ return { action: { type: 'dismiss' }, preventDefault: true };
46
+ }
47
+ return null;
48
+ }
49
+ const index = chartNavStep(key, state.index, state.count, state.cols);
50
+ return index === null ? null : { action: { type: 'focus', index }, preventDefault: true };
51
+ }
52
+ /**
53
+ * A key anywhere on the page while a chart is mounted: Escape dismisses the tooltip, including
54
+ * one opened by hover with focus elsewhere (WCAG 1.4.13). `null` = nothing to do.
55
+ */
56
+ export function chartWindowKey(tooltipOpen, key) {
57
+ return tooltipOpen && key === 'Escape' ? { type: 'dismiss' } : null;
58
+ }
59
+ /** The mark that is the chart's single tab stop: the last focused one, clamped to the marks. */
60
+ export function chartTabStop(focusIndex, count) {
61
+ return Math.min(focusIndex, Math.max(0, count - 1));
62
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Checkbox core (DS-0197) — the toggle decision and the state attribute, shared by
3
+ * Checkbox.svelte and `vanilla/checkbox.ts`. No DOM, no Svelte.
4
+ *
5
+ * The control is a native `<input type="checkbox">`, so the browser owns activation (Space, a
6
+ * press on the box, a press on the wrapping `<label>`) and reports all of them as one `change`
7
+ * event. Those sources cannot be told apart, so there is no `reason`: the callback and the
8
+ * `ss:change` event carry the new value only.
9
+ */
10
+ export interface CheckboxState {
11
+ checked: boolean;
12
+ /** The "mixed" third state (a parent of partly-selected children). */
13
+ indeterminate: boolean;
14
+ disabled: boolean;
15
+ }
16
+ /** The state after a toggle. A user toggle always resolves the mixed state. */
17
+ export interface CheckboxNext {
18
+ checked: boolean;
19
+ indeterminate: false;
20
+ }
21
+ /**
22
+ * The next state for a toggle, or `null` when the checkbox is disabled and must not change.
23
+ * Toggling a mixed checkbox always lands on checked, whatever `checked` was underneath (the
24
+ * browser would flip the hidden value instead, which can land on unchecked).
25
+ */
26
+ export declare function checkboxToggle(state: CheckboxState): CheckboxNext | null;
27
+ /**
28
+ * State attribute for the input. `indeterminate` is a DOM property with no HTML attribute, so
29
+ * the markup carries it as `data-indeterminate` (plain HTML declares the mixed state with it and
30
+ * `vanilla.js` copies it onto the property). No `aria-checked`: a native checkbox already exposes
31
+ * checked / unchecked / mixed from `checked` + `indeterminate`, and ARIA in HTML forbids
32
+ * `aria-checked` on it.
33
+ */
34
+ export declare function checkboxInputAttrs(indeterminate: boolean): {
35
+ readonly 'data-indeterminate': "true" | undefined;
36
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Checkbox core (DS-0197) — the toggle decision and the state attribute, shared by
3
+ * Checkbox.svelte and `vanilla/checkbox.ts`. No DOM, no Svelte.
4
+ *
5
+ * The control is a native `<input type="checkbox">`, so the browser owns activation (Space, a
6
+ * press on the box, a press on the wrapping `<label>`) and reports all of them as one `change`
7
+ * event. Those sources cannot be told apart, so there is no `reason`: the callback and the
8
+ * `ss:change` event carry the new value only.
9
+ */
10
+ /**
11
+ * The next state for a toggle, or `null` when the checkbox is disabled and must not change.
12
+ * Toggling a mixed checkbox always lands on checked, whatever `checked` was underneath (the
13
+ * browser would flip the hidden value instead, which can land on unchecked).
14
+ */
15
+ export function checkboxToggle(state) {
16
+ if (state.disabled)
17
+ return null;
18
+ return { checked: state.indeterminate ? true : !state.checked, indeterminate: false };
19
+ }
20
+ /**
21
+ * State attribute for the input. `indeterminate` is a DOM property with no HTML attribute, so
22
+ * the markup carries it as `data-indeterminate` (plain HTML declares the mixed state with it and
23
+ * `vanilla.js` copies it onto the property). No `aria-checked`: a native checkbox already exposes
24
+ * checked / unchecked / mixed from `checked` + `indeterminate`, and ARIA in HTML forbids
25
+ * `aria-checked` on it.
26
+ */
27
+ export function checkboxInputAttrs(indeterminate) {
28
+ return { 'data-indeterminate': indeterminate ? 'true' : undefined };
29
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * FileDrop core (DS-0197) — what a key on the zone does, which files a selection keeps
3
+ * (`accept` + `multiple`), what the rejection announcement says, and where focus lands after a
4
+ * removal. Pure functions over plain data: FileDrop.svelte holds the files and applies the
5
+ * result. No DOM, no Svelte (a `File` is only ever read as `{ name, type, size }`).
6
+ */
7
+ /** Why the selection changed; passed to `onfiles`. */
8
+ export type FileDropReason = 'select' | 'drop' | 'remove' | 'clear';
9
+ export interface FileDropChangeDetails {
10
+ reason: FileDropReason;
11
+ }
12
+ /** The parts of a `File` the core reads. */
13
+ export interface FileDropFile {
14
+ name: string;
15
+ type: string;
16
+ size?: number;
17
+ }
18
+ export interface FileDropZoneState {
19
+ disabled: boolean;
20
+ }
21
+ export type FileDropAction = {
22
+ type: 'browse';
23
+ };
24
+ /** A key the zone handles: its action, and whether the browser default must be cancelled. */
25
+ export interface FileDropKeyResult {
26
+ action: FileDropAction | null;
27
+ preventDefault: boolean;
28
+ }
29
+ /** The zone was clicked: open the native picker, unless disabled. */
30
+ export declare function fileDropPress(state: FileDropZoneState): FileDropAction | null;
31
+ /** A key on the zone. `null` = not a zone key (or the zone is disabled), let it through. */
32
+ export declare function fileDropKey(state: FileDropZoneState, key: string): FileDropKeyResult | null;
33
+ /**
34
+ * A drag moved over (`over`), left (`leave`) or dropped on (`drop`) the zone: the next
35
+ * `dragging` flag. `null` when disabled — the event is not ours and must not be cancelled.
36
+ */
37
+ export declare function fileDropDrag(state: FileDropZoneState, event: 'over' | 'leave' | 'drop'): boolean | null;
38
+ /** Does a file satisfy the `accept` filter? An empty filter matches everything. */
39
+ export declare function fileDropMatchesAccept(file: FileDropFile, accept?: string | null): boolean;
40
+ /** Why a file was discarded: wrong type for `accept`, or an extra when not `multiple`. */
41
+ export type FileDropRejectReason = 'type' | 'count';
42
+ export interface FileDropRejection<F extends FileDropFile> {
43
+ file: F;
44
+ reason: FileDropRejectReason;
45
+ }
46
+ export interface FileDropSelection<F extends FileDropFile> {
47
+ /** The files kept, in the order given. */
48
+ accepted: F[];
49
+ rejected: FileDropRejection<F>[];
50
+ /** Live-region text for the rejections; `''` when nothing was discarded. */
51
+ announcement: string;
52
+ }
53
+ export interface FileDropRules {
54
+ accept?: string | null;
55
+ multiple?: boolean;
56
+ }
57
+ /** Apply `accept` and `multiple` to a picked or dropped list. The type check comes first. */
58
+ export declare function fileDropSelect<F extends FileDropFile>(list: readonly F[], rules?: FileDropRules): FileDropSelection<F>;
59
+ export interface FileDropRemoval<F> {
60
+ files: F[];
61
+ /**
62
+ * Where focus goes once the pressed remove button is gone: the remove button now at that
63
+ * index (the next file, else the previous one), or the `zone` when the list is empty.
64
+ */
65
+ focus: number | 'zone';
66
+ }
67
+ /** Remove the file at `index`. */
68
+ export declare function fileDropRemove<F>(files: readonly F[], index: number): FileDropRemoval<F>;
69
+ /** Human-readable byte size (1 KB = 1024 B). */
70
+ export declare function fileDropSize(bytes: number): string;
71
+ export declare function fileDropZoneAttrs(state: FileDropZoneState): {
72
+ readonly role: "button";
73
+ readonly tabindex: 0 | -1;
74
+ readonly 'aria-disabled': "true" | undefined;
75
+ };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * FileDrop core (DS-0197) — what a key on the zone does, which files a selection keeps
3
+ * (`accept` + `multiple`), what the rejection announcement says, and where focus lands after a
4
+ * removal. Pure functions over plain data: FileDrop.svelte holds the files and applies the
5
+ * result. No DOM, no Svelte (a `File` is only ever read as `{ name, type, size }`).
6
+ */
7
+ /** The zone was clicked: open the native picker, unless disabled. */
8
+ export function fileDropPress(state) {
9
+ return state.disabled ? null : { type: 'browse' };
10
+ }
11
+ /** A key on the zone. `null` = not a zone key (or the zone is disabled), let it through. */
12
+ export function fileDropKey(state, key) {
13
+ if (state.disabled)
14
+ return null;
15
+ switch (key) {
16
+ case 'Enter':
17
+ case ' ':
18
+ return { action: fileDropPress(state), preventDefault: true };
19
+ default:
20
+ return null;
21
+ }
22
+ }
23
+ /**
24
+ * A drag moved over (`over`), left (`leave`) or dropped on (`drop`) the zone: the next
25
+ * `dragging` flag. `null` when disabled — the event is not ours and must not be cancelled.
26
+ */
27
+ export function fileDropDrag(state, event) {
28
+ if (state.disabled)
29
+ return null;
30
+ return event === 'over';
31
+ }
32
+ // --- validation -----------------------------------------------------------------
33
+ /** Does a file satisfy the `accept` filter? An empty filter matches everything. */
34
+ export function fileDropMatchesAccept(file, accept) {
35
+ if (!accept)
36
+ return true;
37
+ const name = file.name.toLowerCase();
38
+ const type = file.type.toLowerCase();
39
+ return accept
40
+ .split(',')
41
+ .map((t) => t.trim().toLowerCase())
42
+ .filter(Boolean)
43
+ .some((token) => {
44
+ if (token.startsWith('.'))
45
+ return name.endsWith(token);
46
+ if (token.endsWith('/*'))
47
+ return type.startsWith(token.slice(0, -1));
48
+ return type === token;
49
+ });
50
+ }
51
+ const REJECT_TEXT = {
52
+ type: 'file type not accepted',
53
+ count: 'only one file allowed',
54
+ };
55
+ /** Apply `accept` and `multiple` to a picked or dropped list. The type check comes first. */
56
+ export function fileDropSelect(list, rules = {}) {
57
+ const accepted = [];
58
+ const rejected = [];
59
+ for (const file of list) {
60
+ if (!fileDropMatchesAccept(file, rules.accept))
61
+ rejected.push({ file, reason: 'type' });
62
+ else if (!rules.multiple && accepted.length)
63
+ rejected.push({ file, reason: 'count' });
64
+ else
65
+ accepted.push(file);
66
+ }
67
+ const reasons = rejected.map(({ file, reason }) => `${file.name} (${REJECT_TEXT[reason]})`);
68
+ return {
69
+ accepted,
70
+ rejected,
71
+ announcement: reasons.length ? `Not added: ${reasons.join(', ')}.` : '',
72
+ };
73
+ }
74
+ /** Remove the file at `index`. */
75
+ export function fileDropRemove(files, index) {
76
+ const next = files.filter((_, i) => i !== index);
77
+ const focus = index < next.length ? index : next.length ? next.length - 1 : 'zone';
78
+ return { files: next, focus };
79
+ }
80
+ // --- presentation ---------------------------------------------------------------
81
+ /** Human-readable byte size (1 KB = 1024 B). */
82
+ export function fileDropSize(bytes) {
83
+ if (bytes < 1024)
84
+ return `${bytes} B`;
85
+ const units = ['KB', 'MB', 'GB', 'TB'];
86
+ let v = bytes / 1024;
87
+ let i = 0;
88
+ while (v >= 1024 && i < units.length - 1) {
89
+ v /= 1024;
90
+ i++;
91
+ }
92
+ return `${v.toFixed(v < 10 ? 1 : 0)} ${units[i]}`;
93
+ }
94
+ // Strings, not booleans, so the attributes read the same wherever they are written.
95
+ export function fileDropZoneAttrs(state) {
96
+ return {
97
+ role: 'button',
98
+ tabindex: state.disabled ? -1 : 0,
99
+ 'aria-disabled': state.disabled ? 'true' : undefined,
100
+ };
101
+ }