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
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Pagination core (DS-0197) — the page-window maths, the bounds, and what a press on a page
3
+ * button or a stepper does. Pure functions over a small state object; Pagination.svelte holds
4
+ * the state and applies the result. No DOM, no Svelte.
5
+ */
6
+ /** What changed the page; passed to `onchange`. */
7
+ export type PaginationReason = 'page' | 'prev' | 'next';
8
+ export interface PaginationChangeDetails {
9
+ reason: PaginationReason;
10
+ }
11
+ export interface PaginationCountInput {
12
+ /** Explicit page count; wins over `total` / `pageSize`. */
13
+ pageCount?: number;
14
+ /** Total item count. */
15
+ total?: number;
16
+ /** Items per page. */
17
+ pageSize: number;
18
+ }
19
+ /** Number of pages. Derived counts are at least 1, so the control never renders empty. */
20
+ export declare function paginationPageCount(input: PaginationCountInput): number;
21
+ /** `page` clamped into `[1, pages]`. */
22
+ export declare function paginationClamp(page: number, pages: number): number;
23
+ /** One rendered cell: a page number, or the ellipsis before / after the sibling window. */
24
+ export type PaginationSlot = number | 'gap-start' | 'gap-end';
25
+ /**
26
+ * The windowed list of slots: first page, last page, `siblingCount` pages on each side of
27
+ * `current`, and an ellipsis wherever a run of pages is hidden. A single hidden page is cheaper
28
+ * to show than an ellipsis, so a run only collapses when it hides more than one page.
29
+ */
30
+ export declare function paginationSlots(current: number, pages: number, siblingCount: number): PaginationSlot[];
31
+ export declare function paginationIsGap(slot: PaginationSlot): slot is 'gap-start' | 'gap-end';
32
+ export interface PaginationState {
33
+ /** The clamped current page (see {@link paginationClamp}). */
34
+ current: number;
35
+ pages: number;
36
+ disabled: boolean;
37
+ }
38
+ export interface PaginationChange {
39
+ /** The new page. */
40
+ page: number;
41
+ reason: PaginationReason;
42
+ /**
43
+ * Where focus must go once the page has changed. A stepper that lands on its bound becomes
44
+ * natively disabled while it is focused, which would drop focus to `<body>`; it hands focus
45
+ * to the new current-page button instead. `null` = leave focus where it is.
46
+ */
47
+ focus: 'current' | null;
48
+ }
49
+ /** A page-number button was pressed. `null` = nothing changes (disabled, or already there). */
50
+ export declare function paginationPagePress(state: PaginationState, target: number): PaginationChange | null;
51
+ /** The Prev / Next stepper was pressed. `null` = nothing changes (disabled, or at the bound). */
52
+ export declare function paginationStep(state: PaginationState, direction: 'prev' | 'next'): PaginationChange | null;
53
+ /** Whether the Prev / Next stepper is disabled: the whole control is, or it sits at its bound. */
54
+ export declare function paginationStepperDisabled(state: PaginationState, direction: 'prev' | 'next'): boolean;
55
+ /** State attributes of one page-number button. */
56
+ export declare function paginationPageAttrs(slot: number, current: number): {
57
+ readonly 'aria-current': "page" | undefined;
58
+ readonly 'aria-label': `Page ${number}`;
59
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Pagination core (DS-0197) — the page-window maths, the bounds, and what a press on a page
3
+ * button or a stepper does. Pure functions over a small state object; Pagination.svelte holds
4
+ * the state and applies the result. No DOM, no Svelte.
5
+ */
6
+ /** Number of pages. Derived counts are at least 1, so the control never renders empty. */
7
+ export function paginationPageCount(input) {
8
+ return input.pageCount ?? Math.max(1, Math.ceil((input.total ?? 0) / input.pageSize));
9
+ }
10
+ /** `page` clamped into `[1, pages]`. */
11
+ export function paginationClamp(page, pages) {
12
+ return Math.min(Math.max(1, page), pages);
13
+ }
14
+ /**
15
+ * The windowed list of slots: first page, last page, `siblingCount` pages on each side of
16
+ * `current`, and an ellipsis wherever a run of pages is hidden. A single hidden page is cheaper
17
+ * to show than an ellipsis, so a run only collapses when it hides more than one page.
18
+ */
19
+ export function paginationSlots(current, pages, siblingCount) {
20
+ const start = Math.max(2, current - siblingCount);
21
+ const end = Math.min(pages - 1, current + siblingCount);
22
+ const out = [1];
23
+ if (start > 3)
24
+ out.push('gap-start');
25
+ else if (start === 3)
26
+ out.push(2);
27
+ for (let p = start; p <= end; p++)
28
+ out.push(p);
29
+ if (end < pages - 2)
30
+ out.push('gap-end');
31
+ else if (end === pages - 2)
32
+ out.push(pages - 1);
33
+ if (pages > 1)
34
+ out.push(pages);
35
+ return out;
36
+ }
37
+ export function paginationIsGap(slot) {
38
+ return slot === 'gap-start' || slot === 'gap-end';
39
+ }
40
+ function change(state, target, reason) {
41
+ const page = paginationClamp(target, state.pages);
42
+ if (state.disabled || page === state.current)
43
+ return null;
44
+ const atBound = (reason === 'prev' && page <= 1) || (reason === 'next' && page >= state.pages);
45
+ return { page, reason, focus: atBound ? 'current' : null };
46
+ }
47
+ /** A page-number button was pressed. `null` = nothing changes (disabled, or already there). */
48
+ export function paginationPagePress(state, target) {
49
+ return change(state, target, 'page');
50
+ }
51
+ /** The Prev / Next stepper was pressed. `null` = nothing changes (disabled, or at the bound). */
52
+ export function paginationStep(state, direction) {
53
+ return change(state, state.current + (direction === 'prev' ? -1 : 1), direction);
54
+ }
55
+ /** Whether the Prev / Next stepper is disabled: the whole control is, or it sits at its bound. */
56
+ export function paginationStepperDisabled(state, direction) {
57
+ return (state.disabled || (direction === 'prev' ? state.current <= 1 : state.current >= state.pages));
58
+ }
59
+ /** State attributes of one page-number button. */
60
+ export function paginationPageAttrs(slot, current) {
61
+ return {
62
+ 'aria-current': slot === current ? 'page' : undefined,
63
+ 'aria-label': `Page ${slot}`,
64
+ };
65
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Popover core (DS-0197) — the one place the popover's behaviour is decided: a non-modal panel
3
+ * anchored to a trigger. Pure functions over a small state object: an event comes in, a
4
+ * {@link PopoverAction} comes out, and the caller applies it (Popover.svelte to its `$state`,
5
+ * `vanilla/popover.ts` to the DOM). No DOM, no Svelte. Sibling of `menu.ts`.
6
+ */
7
+ /** Why the popover opened or closed; passed to `onOpenChange` / `ss:openchange`. */
8
+ export type PopoverReason = 'trigger' | 'escape' | 'outside' | 'tab';
9
+ export interface PopoverOpenChangeDetails {
10
+ reason: PopoverReason;
11
+ }
12
+ export interface PopoverState {
13
+ open: boolean;
14
+ }
15
+ export type PopoverAction =
16
+ /** Show the panel and move focus into it (first focusable element, else the panel). */
17
+ {
18
+ type: 'open';
19
+ reason: PopoverReason;
20
+ } | {
21
+ type: 'close';
22
+ returnFocus: boolean;
23
+ reason: PopoverReason;
24
+ };
25
+ /** A key the popover handles: its action, and whether the browser default must be cancelled. */
26
+ export interface PopoverKeyResult {
27
+ action: PopoverAction | null;
28
+ preventDefault: boolean;
29
+ }
30
+ /**
31
+ * Where focus went when it left an element of the popover: to another element `inside` it
32
+ * (trigger or panel), to an element `outside` it, or `nowhere` (the window lost focus, or a
33
+ * pointer landed on something that takes none).
34
+ */
35
+ export type PopoverFocusTarget = 'inside' | 'outside' | 'nowhere';
36
+ /** Open from code (`openPopover`). */
37
+ export declare function popoverOpen(state: PopoverState): PopoverAction | null;
38
+ /** Close from code (`closePopover`). */
39
+ export declare function popoverClose(state: PopoverState, returnFocus?: boolean): PopoverAction | null;
40
+ /** The trigger was pressed: toggle. */
41
+ export declare function popoverTriggerPress(state: PopoverState): PopoverAction | null;
42
+ /**
43
+ * A key anywhere in the popover (trigger or panel). Escape closes an open popover and hands
44
+ * focus back to the trigger. `null` = not a popover key (or nothing to close): let it through,
45
+ * so an enclosing surface still sees it.
46
+ */
47
+ export declare function popoverKey(state: PopoverState, key: string): PopoverKeyResult | null;
48
+ /** A pointer went down outside the popover: dismiss without pulling focus back. */
49
+ export declare function popoverOutsidePress(state: PopoverState): PopoverAction | null;
50
+ /**
51
+ * Focus left an element of the popover. Tabbing out (focus lands on an element outside) closes
52
+ * it and lets focus go on; moving between the trigger and the panel, or losing focus to nothing,
53
+ * does not — the popover is persistent.
54
+ */
55
+ export declare function popoverFocusOut(state: PopoverState, to: PopoverFocusTarget): PopoverAction | null;
56
+ export declare function popoverTriggerAttrs(isOpen: boolean): {
57
+ readonly 'aria-haspopup': "dialog";
58
+ readonly 'aria-expanded': "true" | "false";
59
+ };
60
+ /**
61
+ * The panel: a non-modal dialog (no `aria-modal`), focusable from code so focus has somewhere
62
+ * to land when the content holds nothing focusable. Closed-state hiding (`inert`) is written by
63
+ * the caller.
64
+ */
65
+ export declare function popoverPanelAttrs(): {
66
+ readonly role: "dialog";
67
+ readonly tabindex: -1;
68
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Popover core (DS-0197) — the one place the popover's behaviour is decided: a non-modal panel
3
+ * anchored to a trigger. Pure functions over a small state object: an event comes in, a
4
+ * {@link PopoverAction} comes out, and the caller applies it (Popover.svelte to its `$state`,
5
+ * `vanilla/popover.ts` to the DOM). No DOM, no Svelte. Sibling of `menu.ts`.
6
+ */
7
+ const open = (state, reason) => state.open ? null : { type: 'open', reason };
8
+ const close = (state, returnFocus, reason) => (state.open ? { type: 'close', returnFocus, reason } : null);
9
+ /** Open from code (`openPopover`). */
10
+ export function popoverOpen(state) {
11
+ return open(state, 'trigger');
12
+ }
13
+ /** Close from code (`closePopover`). */
14
+ export function popoverClose(state, returnFocus = true) {
15
+ return close(state, returnFocus, 'trigger');
16
+ }
17
+ /** The trigger was pressed: toggle. */
18
+ export function popoverTriggerPress(state) {
19
+ return state.open ? close(state, true, 'trigger') : open(state, 'trigger');
20
+ }
21
+ /**
22
+ * A key anywhere in the popover (trigger or panel). Escape closes an open popover and hands
23
+ * focus back to the trigger. `null` = not a popover key (or nothing to close): let it through,
24
+ * so an enclosing surface still sees it.
25
+ */
26
+ export function popoverKey(state, key) {
27
+ if (key !== 'Escape' || !state.open)
28
+ return null;
29
+ return { action: close(state, true, 'escape'), preventDefault: true };
30
+ }
31
+ /** A pointer went down outside the popover: dismiss without pulling focus back. */
32
+ export function popoverOutsidePress(state) {
33
+ return close(state, false, 'outside');
34
+ }
35
+ /**
36
+ * Focus left an element of the popover. Tabbing out (focus lands on an element outside) closes
37
+ * it and lets focus go on; moving between the trigger and the panel, or losing focus to nothing,
38
+ * does not — the popover is persistent.
39
+ */
40
+ export function popoverFocusOut(state, to) {
41
+ return to === 'outside' ? close(state, false, 'tab') : null;
42
+ }
43
+ // --- attributes ---------------------------------------------------------------
44
+ // Strings, not booleans, so the Svelte spread and the vanilla `setAttribute` write the same DOM.
45
+ export function popoverTriggerAttrs(isOpen) {
46
+ return { 'aria-haspopup': 'dialog', 'aria-expanded': isOpen ? 'true' : 'false' };
47
+ }
48
+ /**
49
+ * The panel: a non-modal dialog (no `aria-modal`), focusable from code so focus has somewhere
50
+ * to land when the content holds nothing focusable. Closed-state hiding (`inert`) is written by
51
+ * the caller.
52
+ */
53
+ export function popoverPanelAttrs() {
54
+ return { role: 'dialog', tabindex: -1 };
55
+ }
@@ -0,0 +1,36 @@
1
+ export interface RadioState {
2
+ /** Index of the selected option, `-1` when none. */
3
+ selected: number;
4
+ /** Indexes of the enabled options, in DOM order (empty when the whole group is disabled). */
5
+ enabled: readonly number[];
6
+ }
7
+ /** Select option `index`. `changed` is false when it already was the selection (no event). */
8
+ export interface RadioAction {
9
+ type: 'select';
10
+ index: number;
11
+ changed: boolean;
12
+ }
13
+ /**
14
+ * The enabled option indexes: `optionDisabled[i]` is each option's own flag, and a disabled
15
+ * group enables nothing.
16
+ */
17
+ export declare function radioEnabled(optionDisabled: readonly boolean[], groupDisabled: boolean): number[];
18
+ /** An option was picked (pressed, or reached with an arrow key). `null` when it is disabled. */
19
+ export declare function radioPress(state: RadioState, index: number): RadioAction | null;
20
+ /**
21
+ * The index that owns the group's single tab stop: the selected option when it is enabled,
22
+ * otherwise the first enabled one (so a group with no selection, or with a disabled selection,
23
+ * is still reachable); `-1` when nothing is enabled.
24
+ */
25
+ export declare function radioTabStop(state: RadioState): number;
26
+ export declare function radioGroupAttrs(disabled: boolean): {
27
+ readonly role: "radiogroup";
28
+ readonly 'aria-disabled': "true" | undefined;
29
+ };
30
+ /**
31
+ * Attributes for one native radio. No `role` and no `aria-checked`: the input already exposes
32
+ * both from its `checked` property.
33
+ */
34
+ export declare function radioInputAttrs(index: number, tabStop: number): {
35
+ readonly tabindex: 0 | -1;
36
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * RadioGroup core (DS-0197) — the decisions that belong to the group, shared by
3
+ * RadioGroup.svelte and `vanilla/radio.ts`. Pure functions: no DOM, no Svelte.
4
+ *
5
+ * The options are native `<input type="radio">` elements sharing a `name`, so the browser owns
6
+ * arrow-key movement (wrapping, skipping disabled, mirrored under RTL), Space and form
7
+ * submission, and reports every one of them as a `change` event on the newly checked input.
8
+ * What stays ours is decided here: which options are enabled, what a press on an option
9
+ * selects, which option is the tab stop (most of all when nothing is selected), and the state
10
+ * attributes. A press and an arrow key cannot be told apart reliably from a `change` event, so
11
+ * there is no `reason`: the callback and the `ss:change` event carry the new value only.
12
+ */
13
+ import { rovingTabindex } from './behaviors/roving.js';
14
+ /**
15
+ * The enabled option indexes: `optionDisabled[i]` is each option's own flag, and a disabled
16
+ * group enables nothing.
17
+ */
18
+ export function radioEnabled(optionDisabled, groupDisabled) {
19
+ if (groupDisabled)
20
+ return [];
21
+ return optionDisabled.map((off, index) => (off ? -1 : index)).filter((index) => index >= 0);
22
+ }
23
+ /** An option was picked (pressed, or reached with an arrow key). `null` when it is disabled. */
24
+ export function radioPress(state, index) {
25
+ return state.enabled.includes(index)
26
+ ? { type: 'select', index, changed: index !== state.selected }
27
+ : null;
28
+ }
29
+ /**
30
+ * The index that owns the group's single tab stop: the selected option when it is enabled,
31
+ * otherwise the first enabled one (so a group with no selection, or with a disabled selection,
32
+ * is still reachable); `-1` when nothing is enabled.
33
+ */
34
+ export function radioTabStop(state) {
35
+ return state.enabled.includes(state.selected) ? state.selected : (state.enabled[0] ?? -1);
36
+ }
37
+ // --- attributes ---------------------------------------------------------------
38
+ // Strings, not booleans, so the Svelte spread and the vanilla `setAttribute` write the same DOM.
39
+ export function radioGroupAttrs(disabled) {
40
+ return { role: 'radiogroup', 'aria-disabled': disabled ? 'true' : undefined };
41
+ }
42
+ /**
43
+ * Attributes for one native radio. No `role` and no `aria-checked`: the input already exposes
44
+ * both from its `checked` property.
45
+ */
46
+ export function radioInputAttrs(index, tabStop) {
47
+ return { tabindex: rovingTabindex(index, tabStop) };
48
+ }
@@ -0,0 +1,124 @@
1
+ /** Why the palette opened or closed; passed to `onopen` / `onclose`. */
2
+ export type SearchPaletteReason =
3
+ /** The toggle shortcut (`mod+k`). */
4
+ 'shortcut'
5
+ /** Escape (the native dialog's `cancel`). */
6
+ | 'escape'
7
+ /** A press on the backdrop. */
8
+ | 'backdrop'
9
+ /** The × close button. */
10
+ | 'close-button'
11
+ /** An item was chosen. */
12
+ | 'select'
13
+ /** The consumer changed `open` (or called the dialog's `close()`) itself. */
14
+ | 'prop';
15
+ export interface SearchPaletteOpenDetails {
16
+ reason: SearchPaletteReason;
17
+ }
18
+ /** The fields of an item the core reads. */
19
+ export interface SearchItemLike {
20
+ label: string;
21
+ group?: string;
22
+ keywords?: string[];
23
+ disabled?: boolean;
24
+ href?: string;
25
+ }
26
+ /** Case- and diacritic-insensitive fold ("São" matches "sao"). */
27
+ export declare function searchFold(text: string): string;
28
+ /** Items whose label or keywords contain the query; a blank query keeps them all. */
29
+ export declare function searchFilter<T extends SearchItemLike>(items: readonly T[], query: string): T[];
30
+ export interface SearchGroup<T> {
31
+ /** Group heading; `null` for the ungrouped bucket. */
32
+ label: string | null;
33
+ /** The bucket's items with their flat index (keyboard order equals DOM order). */
34
+ entries: {
35
+ item: T;
36
+ index: number;
37
+ }[];
38
+ }
39
+ /** Buckets in first-appearance order, the ungrouped one (label `null`) always first. */
40
+ export declare function searchGroups<T extends SearchItemLike>(items: readonly T[]): SearchGroup<T>[];
41
+ /** The grouped items in display order — what the flat `index` of an entry points into. */
42
+ export declare function searchFlat<T>(groups: readonly SearchGroup<T>[]): T[];
43
+ /** Live-region text: silent until the user types, then the count (or the no-results text). */
44
+ export declare function searchStatus(query: string, count: number, resultsText: (count: number) => string, emptyText: string): string;
45
+ export interface SearchPaletteState {
46
+ open: boolean;
47
+ /** Flat index of the active option. */
48
+ active: number;
49
+ /** The options in display order (see {@link searchFlat}). */
50
+ items: readonly Pick<SearchItemLike, 'disabled' | 'href'>[];
51
+ }
52
+ /** The option a fresh list starts on: the first selectable one (0 when there is none). */
53
+ export declare function searchFirstActive(state: SearchPaletteState): number;
54
+ /** `active` when it still points at a selectable option, else the first selectable one. */
55
+ export declare function searchValidActive(state: SearchPaletteState): number;
56
+ /** The pointer moved over an option: it becomes active unless disabled (`null`). */
57
+ export declare function searchHover(state: SearchPaletteState, index: number): number | null;
58
+ export type SearchPaletteAction = {
59
+ type: 'open';
60
+ reason: SearchPaletteReason;
61
+ } | {
62
+ type: 'close';
63
+ reason: SearchPaletteReason;
64
+ }
65
+ /** Make `index` the active option and scroll it into view. */
66
+ | {
67
+ type: 'move';
68
+ index: number;
69
+ }
70
+ /**
71
+ * Activate option `index`. `via: 'anchor'` = it is a link: click the rendered `<a>` so the
72
+ * router's/native navigation applies (its click handler then runs the item press).
73
+ */
74
+ | {
75
+ type: 'activate';
76
+ index: number;
77
+ via: 'anchor' | 'item';
78
+ };
79
+ /** A key the palette handles: its action, and whether the browser default must be cancelled. */
80
+ export interface SearchPaletteKeyResult {
81
+ action: SearchPaletteAction | null;
82
+ preventDefault: boolean;
83
+ }
84
+ /** The toggle shortcut fired. */
85
+ export declare function searchShortcut(isOpen: boolean): SearchPaletteAction;
86
+ /**
87
+ * The backdrop was clicked; `onBackdrop` = the press both started and ended on the dialog
88
+ * itself, not the panel. Called on `click`, not `pointerdown`, for the same reason as
89
+ * `modalBackdropPress`: closing on the pointerdown lets the gesture's mousedown drop the
90
+ * returned focus on `<body>` (DS-0205).
91
+ */
92
+ export declare function searchBackdropPress(state: SearchPaletteState, onBackdrop: boolean): SearchPaletteAction | null;
93
+ /** The × close button was pressed. */
94
+ export declare function searchClosePress(state: SearchPaletteState): SearchPaletteAction | null;
95
+ /** An activated option: it is selected, and `close` dismisses the palette unless the
96
+ * consumer's `onselect` returned `false`. */
97
+ export interface SearchItemResult {
98
+ close: SearchPaletteAction | null;
99
+ }
100
+ /** An option was activated (click or Enter). `null` when it is disabled or missing. */
101
+ export declare function searchItemPress(state: SearchPaletteState, index: number): SearchItemResult | null;
102
+ /**
103
+ * A key on the input. `null` = not a palette key, let it through (typing, caret keys — Home/End
104
+ * stay native per the APG combobox; PageUp/PageDown jump to the first/last option instead).
105
+ * `composing` = an IME composition is in progress: every key belongs to it.
106
+ */
107
+ export declare function searchInputKey(state: SearchPaletteState, key: string, composing?: boolean): SearchPaletteKeyResult | null;
108
+ /** Combobox state on the input; `activeId` is the DOM id of the active option. */
109
+ export declare function searchInputAttrs(count: number, activeId: string): {
110
+ readonly role: "combobox";
111
+ readonly 'aria-autocomplete': "list";
112
+ readonly 'aria-expanded': "true" | "false";
113
+ readonly 'aria-activedescendant': string | undefined;
114
+ };
115
+ export declare function searchOptionAttrs(option: {
116
+ index: number;
117
+ active: number;
118
+ disabled?: boolean;
119
+ }): {
120
+ readonly role: "option";
121
+ readonly 'aria-selected': "true" | "false";
122
+ readonly 'aria-disabled': "true" | undefined;
123
+ readonly tabindex: -1;
124
+ };
@@ -0,0 +1,149 @@
1
+ /**
2
+ * SearchPalette core (DS-0197) — the one place the palette's behaviour is decided: which
3
+ * items match a query, how they group, where the active option moves, what a key does and
4
+ * why the palette opens or closes. Pure functions over a small state object; SearchPalette.svelte
5
+ * holds the state and applies the result. No DOM, no Svelte.
6
+ */
7
+ import { rovingStep } from './behaviors/roving.js';
8
+ // --- results ------------------------------------------------------------------
9
+ /** Case- and diacritic-insensitive fold ("São" matches "sao"). */
10
+ export function searchFold(text) {
11
+ return text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
12
+ }
13
+ /** Items whose label or keywords contain the query; a blank query keeps them all. */
14
+ export function searchFilter(items, query) {
15
+ const q = searchFold(query.trim());
16
+ if (!q)
17
+ return [...items];
18
+ return items.filter((it) => searchFold([it.label, ...(it.keywords ?? [])].join(' ')).includes(q));
19
+ }
20
+ /** Buckets in first-appearance order, the ungrouped one (label `null`) always first. */
21
+ export function searchGroups(items) {
22
+ const buckets = [];
23
+ for (const it of items) {
24
+ const label = it.group ?? null;
25
+ let b = buckets.find((entry) => entry.label === label);
26
+ if (!b) {
27
+ b = { label, bucket: [] };
28
+ buckets.push(b);
29
+ }
30
+ b.bucket.push(it);
31
+ }
32
+ buckets.sort((a, b) => Number(b.label === null) - Number(a.label === null));
33
+ let index = 0;
34
+ return buckets.map(({ label, bucket }) => ({
35
+ label,
36
+ entries: bucket.map((item) => ({ item, index: index++ })),
37
+ }));
38
+ }
39
+ /** The grouped items in display order — what the flat `index` of an entry points into. */
40
+ export function searchFlat(groups) {
41
+ return groups.flatMap((g) => g.entries.map((e) => e.item));
42
+ }
43
+ /** Live-region text: silent until the user types, then the count (or the no-results text). */
44
+ export function searchStatus(query, count, resultsText, emptyText) {
45
+ if (!query.trim())
46
+ return '';
47
+ return count ? resultsText(count) : emptyText;
48
+ }
49
+ const enabled = (state) => state.items.map((it, i) => (it.disabled ? -1 : i)).filter((i) => i >= 0);
50
+ /** The option a fresh list starts on: the first selectable one (0 when there is none). */
51
+ export function searchFirstActive(state) {
52
+ return Math.max(0, rovingStep(enabled(state), -1, 'first'));
53
+ }
54
+ /** `active` when it still points at a selectable option, else the first selectable one. */
55
+ export function searchValidActive(state) {
56
+ const { active, items } = state;
57
+ return active >= items.length || items[active]?.disabled ? searchFirstActive(state) : active;
58
+ }
59
+ /** The pointer moved over an option: it becomes active unless disabled (`null`). */
60
+ export function searchHover(state, index) {
61
+ return state.items[index] && !state.items[index].disabled ? index : null;
62
+ }
63
+ const close = (state, reason) => (state.open ? { type: 'close', reason } : null);
64
+ /** The toggle shortcut fired. */
65
+ export function searchShortcut(isOpen) {
66
+ return { type: isOpen ? 'close' : 'open', reason: 'shortcut' };
67
+ }
68
+ /**
69
+ * The backdrop was clicked; `onBackdrop` = the press both started and ended on the dialog
70
+ * itself, not the panel. Called on `click`, not `pointerdown`, for the same reason as
71
+ * `modalBackdropPress`: closing on the pointerdown lets the gesture's mousedown drop the
72
+ * returned focus on `<body>` (DS-0205).
73
+ */
74
+ export function searchBackdropPress(state, onBackdrop) {
75
+ return onBackdrop ? close(state, 'backdrop') : null;
76
+ }
77
+ /** The × close button was pressed. */
78
+ export function searchClosePress(state) {
79
+ return close(state, 'close-button');
80
+ }
81
+ /** An option was activated (click or Enter). `null` when it is disabled or missing. */
82
+ export function searchItemPress(state, index) {
83
+ const it = state.items[index];
84
+ if (!it || it.disabled)
85
+ return null;
86
+ return { close: close(state, 'select') };
87
+ }
88
+ /**
89
+ * A key on the input. `null` = not a palette key, let it through (typing, caret keys — Home/End
90
+ * stay native per the APG combobox; PageUp/PageDown jump to the first/last option instead).
91
+ * `composing` = an IME composition is in progress: every key belongs to it.
92
+ */
93
+ export function searchInputKey(state, key, composing = false) {
94
+ if (composing)
95
+ return null;
96
+ const move = (to) => {
97
+ const index = rovingStep(enabled(state), state.active, to);
98
+ // Nothing selectable: stay put (still revealing the active row), or do nothing when empty.
99
+ const target = index >= 0 ? index : state.items.length ? state.active : -1;
100
+ return {
101
+ action: target >= 0 ? { type: 'move', index: target } : null,
102
+ preventDefault: true,
103
+ };
104
+ };
105
+ switch (key) {
106
+ case 'ArrowDown':
107
+ return move('next');
108
+ case 'ArrowUp':
109
+ return move('prev');
110
+ case 'PageUp':
111
+ return move('first');
112
+ case 'PageDown':
113
+ return move('last');
114
+ case 'Enter': {
115
+ const it = state.items[state.active];
116
+ return {
117
+ action: it && !it.disabled
118
+ ? { type: 'activate', index: state.active, via: it.href ? 'anchor' : 'item' }
119
+ : null,
120
+ preventDefault: true,
121
+ };
122
+ }
123
+ case 'Tab':
124
+ // Focus stays on the input while the palette is open.
125
+ return { action: null, preventDefault: true };
126
+ default:
127
+ return null;
128
+ }
129
+ }
130
+ // --- attributes ---------------------------------------------------------------
131
+ // Strings, not booleans, so a spread writes the same DOM everywhere.
132
+ const bool = (value) => (value ? 'true' : 'false');
133
+ /** Combobox state on the input; `activeId` is the DOM id of the active option. */
134
+ export function searchInputAttrs(count, activeId) {
135
+ return {
136
+ role: 'combobox',
137
+ 'aria-autocomplete': 'list',
138
+ 'aria-expanded': bool(count > 0),
139
+ 'aria-activedescendant': count > 0 ? activeId : undefined,
140
+ };
141
+ }
142
+ export function searchOptionAttrs(option) {
143
+ return {
144
+ role: 'option',
145
+ 'aria-selected': bool(option.index === option.active),
146
+ 'aria-disabled': option.disabled ? 'true' : undefined,
147
+ tabindex: -1,
148
+ };
149
+ }
@@ -0,0 +1,46 @@
1
+ /** What moved the selection; passed to `onChange` / `ss:change`. */
2
+ export type SegmentedReason = 'press' | 'key';
3
+ export interface SegmentedChangeDetails {
4
+ reason: SegmentedReason;
5
+ }
6
+ export interface SegmentedState {
7
+ /** Index of the selected segment, `-1` when none. */
8
+ selected: number;
9
+ /** Indexes of the enabled segments, in DOM order (empty when the whole group is disabled). */
10
+ enabled: readonly number[];
11
+ }
12
+ /** Select segment `index`. `changed` is false when it already was the selection (no event). */
13
+ export interface SegmentedAction {
14
+ type: 'select';
15
+ index: number;
16
+ changed: boolean;
17
+ /** Move DOM focus to the segment too (keyboard: focus and selection travel together). */
18
+ focus: boolean;
19
+ reason: SegmentedReason;
20
+ }
21
+ /** A key the group handles: its action, and whether the browser default must be cancelled. */
22
+ export interface SegmentedKeyResult {
23
+ action: SegmentedAction;
24
+ preventDefault: boolean;
25
+ }
26
+ /** A segment was pressed. `null` when it (or the group) is disabled. */
27
+ export declare function segmentedPress(state: SegmentedState, index: number): SegmentedAction | null;
28
+ /**
29
+ * A key on segment `index`. Arrows / Home / End move over the enabled segments (wrapping) and
30
+ * select the target. `null` = not a group key, or nothing is enabled: let it through.
31
+ */
32
+ export declare function segmentedKey(state: SegmentedState, index: number, key: string, rtl?: boolean): SegmentedKeyResult | null;
33
+ /**
34
+ * The index that owns the group's single tab stop: the selected segment when it is enabled,
35
+ * otherwise the first enabled one; `-1` when nothing is enabled.
36
+ */
37
+ export declare function segmentedTabStop(state: SegmentedState): number;
38
+ export declare function segmentedGroupAttrs(disabled: boolean): {
39
+ readonly role: "radiogroup";
40
+ readonly 'aria-disabled': "true" | undefined;
41
+ };
42
+ export declare function segmentedItemAttrs(index: number, selected: number, tabStop: number): {
43
+ readonly role: "radio";
44
+ readonly 'aria-checked': "true" | "false";
45
+ readonly tabindex: 0 | -1;
46
+ };