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
+ * Image core (DS-0197) — the load state, whether the lightbox may open, and what a key inside
3
+ * the lightbox does (Escape, and the Tab focus trap). Pure functions; Image.svelte holds the
4
+ * state, reads the focusable elements from the DOM and applies the result. No DOM, no Svelte.
5
+ */
6
+ export type ImageLoadState = 'loading' | 'loaded' | 'error';
7
+ /** The load state after the `<img>` fired `load` or `error`. */
8
+ export declare function imageLoadResult(event: 'load' | 'error'): ImageLoadState;
9
+ /**
10
+ * The aspect ratio (w / h) reserved before load. An explicit positive `ratio` wins, else it is
11
+ * derived from `width` / `height` when both exist. `null` = reserve no box.
12
+ */
13
+ export declare function imageAspect(input: {
14
+ ratio?: number;
15
+ width?: number;
16
+ height?: number;
17
+ }): number | null;
18
+ /** The lightbox trigger exists only when the lightbox is on and the image did not fail. */
19
+ export declare function imageCanOpen(lightbox: boolean, loadState: ImageLoadState): boolean;
20
+ export interface ImageDialogKeyInput {
21
+ key: string;
22
+ shiftKey: boolean;
23
+ /** How many elements inside the dialog can take Tab focus. */
24
+ focusableCount: number;
25
+ /** Index of the focused element among them; `-1` when focus is elsewhere (the dialog itself). */
26
+ activeIndex: number;
27
+ }
28
+ export type ImageDialogAction = {
29
+ type: 'close';
30
+ } | {
31
+ type: 'focus';
32
+ index: number;
33
+ };
34
+ /** A key the lightbox handles: its action, and what must be done to the event. */
35
+ export interface ImageDialogKeyResult {
36
+ action: ImageDialogAction;
37
+ preventDefault: boolean;
38
+ /** Keep the key from reaching an enclosing surface (Escape closes only the lightbox). */
39
+ stopPropagation: boolean;
40
+ }
41
+ /**
42
+ * A key inside the lightbox. Escape closes it. Tab is trapped: forward from the last focusable
43
+ * wraps to the first, Shift+Tab from the first wraps to the last. `null` = let the key through
44
+ * (any other key, a Tab that stays inside, or nothing to trap).
45
+ */
46
+ export declare function imageDialogKey(input: ImageDialogKeyInput): ImageDialogKeyResult | null;
47
+ export declare function imageFrameAttrs(loadState: ImageLoadState): {
48
+ readonly 'aria-busy': "true" | "false";
49
+ };
50
+ export declare function imageTriggerAttrs(alt: string): {
51
+ readonly 'aria-haspopup': "dialog";
52
+ readonly 'aria-label': string;
53
+ };
54
+ export declare function imageDialogAttrs(alt: string): {
55
+ readonly role: "dialog";
56
+ readonly 'aria-modal': "true";
57
+ readonly 'aria-label': string;
58
+ readonly tabindex: -1;
59
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Image core (DS-0197) — the load state, whether the lightbox may open, and what a key inside
3
+ * the lightbox does (Escape, and the Tab focus trap). Pure functions; Image.svelte holds the
4
+ * state, reads the focusable elements from the DOM and applies the result. No DOM, no Svelte.
5
+ */
6
+ /** The load state after the `<img>` fired `load` or `error`. */
7
+ export function imageLoadResult(event) {
8
+ return event === 'load' ? 'loaded' : 'error';
9
+ }
10
+ /**
11
+ * The aspect ratio (w / h) reserved before load. An explicit positive `ratio` wins, else it is
12
+ * derived from `width` / `height` when both exist. `null` = reserve no box.
13
+ */
14
+ export function imageAspect(input) {
15
+ const { ratio, width, height } = input;
16
+ if (ratio && ratio > 0)
17
+ return ratio;
18
+ return width && height && height > 0 ? width / height : null;
19
+ }
20
+ /** The lightbox trigger exists only when the lightbox is on and the image did not fail. */
21
+ export function imageCanOpen(lightbox, loadState) {
22
+ return lightbox && loadState !== 'error';
23
+ }
24
+ /**
25
+ * A key inside the lightbox. Escape closes it. Tab is trapped: forward from the last focusable
26
+ * wraps to the first, Shift+Tab from the first wraps to the last. `null` = let the key through
27
+ * (any other key, a Tab that stays inside, or nothing to trap).
28
+ */
29
+ export function imageDialogKey(input) {
30
+ if (input.key === 'Escape') {
31
+ return { action: { type: 'close' }, preventDefault: true, stopPropagation: true };
32
+ }
33
+ if (input.key !== 'Tab' || input.focusableCount === 0)
34
+ return null;
35
+ const last = input.focusableCount - 1;
36
+ const wrap = (index) => ({
37
+ action: { type: 'focus', index },
38
+ preventDefault: true,
39
+ stopPropagation: false,
40
+ });
41
+ if (input.shiftKey && input.activeIndex === 0)
42
+ return wrap(last);
43
+ if (!input.shiftKey && input.activeIndex === last)
44
+ return wrap(0);
45
+ return null;
46
+ }
47
+ const bool = (value) => (value ? 'true' : 'false');
48
+ export function imageFrameAttrs(loadState) {
49
+ return { 'aria-busy': bool(loadState === 'loading') };
50
+ }
51
+ export function imageTriggerAttrs(alt) {
52
+ return {
53
+ 'aria-haspopup': 'dialog',
54
+ 'aria-label': alt ? `View image: ${alt}` : 'View image full size',
55
+ };
56
+ }
57
+ export function imageDialogAttrs(alt) {
58
+ return {
59
+ role: 'dialog',
60
+ 'aria-modal': 'true',
61
+ 'aria-label': alt ? `Image: ${alt}` : 'Image preview',
62
+ tabindex: -1,
63
+ };
64
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Input core (DS-0197) — the clear-button decision, shared by Input.svelte and
3
+ * `vanilla/fields.ts`. No DOM, no Svelte.
4
+ */
5
+ export interface InputClearState {
6
+ value: string;
7
+ disabled: boolean;
8
+ readonly: boolean;
9
+ }
10
+ /**
11
+ * Is the clear button useful? Only on a field that has a value and can be edited. (Whether the
12
+ * field is `clearable` at all is the caller's: a prop in Svelte, the button's presence in HTML.)
13
+ */
14
+ export declare function inputShowClear(state: InputClearState): boolean;
15
+ /** What pressing clear does: the next value, and focus goes back to the input. */
16
+ export interface InputClearResult {
17
+ value: '';
18
+ focusInput: true;
19
+ }
20
+ /** The clear button was pressed. `null` when the field cannot be edited: nothing changes. */
21
+ export declare function inputClear(state: InputClearState): InputClearResult | null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Input core (DS-0197) — the clear-button decision, shared by Input.svelte and
3
+ * `vanilla/fields.ts`. No DOM, no Svelte.
4
+ */
5
+ /**
6
+ * Is the clear button useful? Only on a field that has a value and can be edited. (Whether the
7
+ * field is `clearable` at all is the caller's: a prop in Svelte, the button's presence in HTML.)
8
+ */
9
+ export function inputShowClear(state) {
10
+ return state.value !== '' && !state.readonly && !state.disabled;
11
+ }
12
+ /** The clear button was pressed. `null` when the field cannot be edited: nothing changes. */
13
+ export function inputClear(state) {
14
+ if (state.readonly || state.disabled)
15
+ return null;
16
+ return { value: '', focusInput: true };
17
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * LogStream core (DS-0197) — the viewer's decisions: which lines pass the level chips and the
3
+ * text filter, what a chip press does, when the view follows the tail, and what COPY copies.
4
+ * Pure functions; LogStream.svelte holds the state and measures the scroller. No DOM, no Svelte.
5
+ */
6
+ /** A log severity level. */
7
+ export type LogStreamLevel = 'info' | 'warn' | 'err' | 'ok';
8
+ /** The fields of a log line the decisions read (structurally the component's `LogLine`). */
9
+ export interface LogStreamLine {
10
+ /** Timestamp string, rendered verbatim. */
11
+ t?: string;
12
+ lvl: LogStreamLevel;
13
+ /** Service / source tag. */
14
+ svc?: string;
15
+ msg: string;
16
+ }
17
+ /** Every level, in the order the filter chips show them. */
18
+ export declare const LOG_LEVELS: readonly LogStreamLevel[];
19
+ export interface LogStreamFilter {
20
+ /** Levels whose chip is on. */
21
+ levels: ReadonlySet<LogStreamLevel>;
22
+ /** The text filter as typed; blank matches everything. */
23
+ query: string;
24
+ }
25
+ /**
26
+ * Whether a line is shown: its level chip is on, and the text filter (case-insensitive) occurs
27
+ * somewhere in its timestamp, level, service or message. Whitespace-only text filters nothing;
28
+ * otherwise the text is matched as typed, spaces included.
29
+ */
30
+ export declare function logLineVisible(line: LogStreamLine, filter: LogStreamFilter): boolean;
31
+ /** The lines that pass {@link logLineVisible}, in order. */
32
+ export declare function filterLogLines<T extends LogStreamLine>(lines: readonly T[], filter: LogStreamFilter): T[];
33
+ /** A level chip was pressed: the next set of active levels (a new set; the input is untouched). */
34
+ export declare function toggleLogLevel(levels: ReadonlySet<LogStreamLevel>, level: LogStreamLevel): Set<LogStreamLevel>;
35
+ /** How close to the bottom, in px, still counts as "at the bottom". */
36
+ export declare const FOLLOW_SLACK = 24;
37
+ /** The scroller's measurements, as read from the element by the caller. */
38
+ export interface LogStreamScroll {
39
+ scrollHeight: number;
40
+ scrollTop: number;
41
+ clientHeight: number;
42
+ }
43
+ /**
44
+ * Whether the view follows the tail after a scroll: yes while it sits within
45
+ * {@link FOLLOW_SLACK} of the bottom, no once the reader has scrolled up to look at something.
46
+ */
47
+ export declare function logFollowsTail(scroll: LogStreamScroll): boolean;
48
+ /** What COPY puts on the clipboard: one `time LEVEL service message` row per line. */
49
+ export declare function logCopyText(lines: readonly LogStreamLine[]): string;
50
+ /** The empty-state message: nothing has arrived yet, or the filters hide everything there is. */
51
+ export declare function logEmptyMessage(totalLines: number): string;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * LogStream core (DS-0197) — the viewer's decisions: which lines pass the level chips and the
3
+ * text filter, what a chip press does, when the view follows the tail, and what COPY copies.
4
+ * Pure functions; LogStream.svelte holds the state and measures the scroller. No DOM, no Svelte.
5
+ */
6
+ /** Every level, in the order the filter chips show them. */
7
+ export const LOG_LEVELS = Object.freeze(['info', 'warn', 'err', 'ok']);
8
+ /**
9
+ * Whether a line is shown: its level chip is on, and the text filter (case-insensitive) occurs
10
+ * somewhere in its timestamp, level, service or message. Whitespace-only text filters nothing;
11
+ * otherwise the text is matched as typed, spaces included.
12
+ */
13
+ export function logLineVisible(line, filter) {
14
+ if (!filter.levels.has(line.lvl))
15
+ return false;
16
+ if (!filter.query.trim())
17
+ return true;
18
+ const hay = `${line.t ?? ''} ${line.lvl} ${line.svc ?? ''} ${line.msg}`.toLowerCase();
19
+ return hay.includes(filter.query.toLowerCase());
20
+ }
21
+ /** The lines that pass {@link logLineVisible}, in order. */
22
+ export function filterLogLines(lines, filter) {
23
+ return lines.filter((line) => logLineVisible(line, filter));
24
+ }
25
+ /** A level chip was pressed: the next set of active levels (a new set; the input is untouched). */
26
+ export function toggleLogLevel(levels, level) {
27
+ const next = new Set(levels);
28
+ if (!next.delete(level))
29
+ next.add(level);
30
+ return next;
31
+ }
32
+ /** How close to the bottom, in px, still counts as "at the bottom". */
33
+ export const FOLLOW_SLACK = 24;
34
+ /**
35
+ * Whether the view follows the tail after a scroll: yes while it sits within
36
+ * {@link FOLLOW_SLACK} of the bottom, no once the reader has scrolled up to look at something.
37
+ */
38
+ export function logFollowsTail(scroll) {
39
+ return scroll.scrollHeight - scroll.scrollTop - scroll.clientHeight <= FOLLOW_SLACK;
40
+ }
41
+ /** What COPY puts on the clipboard: one `time LEVEL service message` row per line. */
42
+ export function logCopyText(lines) {
43
+ return lines
44
+ .map((l) => `${l.t ?? ''} ${l.lvl.toUpperCase()} ${l.svc ?? ''} ${l.msg}`.trim())
45
+ .join('\n');
46
+ }
47
+ /** The empty-state message: nothing has arrived yet, or the filters hide everything there is. */
48
+ export function logEmptyMessage(totalLines) {
49
+ return totalLines ? 'No lines match the current filters.' : 'Waiting for output…';
50
+ }
@@ -0,0 +1,70 @@
1
+ /** Why the menu opened or closed; passed to `onOpenChange` / `ss:openchange`. */
2
+ export type MenuReason = 'trigger' | 'key' | 'escape' | 'tab' | 'outside' | 'item';
3
+ export interface MenuOpenChangeDetails {
4
+ reason: MenuReason;
5
+ }
6
+ export interface MenuState {
7
+ open: boolean;
8
+ /** Index of the focused item, `-1` when none. */
9
+ active: number;
10
+ /** Indexes of the enabled items, in DOM order. */
11
+ enabled: readonly number[];
12
+ }
13
+ export type MenuAction = {
14
+ type: 'open';
15
+ focus: number;
16
+ reason: MenuReason;
17
+ } | {
18
+ type: 'close';
19
+ returnFocus: boolean;
20
+ reason: MenuReason;
21
+ } | {
22
+ type: 'focus';
23
+ index: number;
24
+ };
25
+ /** A key the menu handles: its action, and whether the browser default must be cancelled. */
26
+ export interface MenuKeyResult {
27
+ action: MenuAction | null;
28
+ preventDefault: boolean;
29
+ }
30
+ /** Open from code (`openMenu`), focusing the first or last enabled item. */
31
+ export declare function menuOpen(state: MenuState, edge?: 'first' | 'last'): MenuAction | null;
32
+ /** Close from code (`closeMenu`). */
33
+ export declare function menuClose(state: MenuState, returnFocus?: boolean): MenuAction | null;
34
+ /** The trigger was pressed: toggle. */
35
+ export declare function menuTriggerPress(state: MenuState): MenuAction | null;
36
+ /** A key on the trigger. `null` = not a menu key, let it through. */
37
+ export declare function menuTriggerKey(state: MenuState, key: string): MenuKeyResult | null;
38
+ /** A key inside the panel. `null` = not a menu key, let it through. */
39
+ export declare function menuPanelKey(state: MenuState, key: string): MenuKeyResult | null;
40
+ /** A pointer went down outside the menu: dismiss without pulling focus back. */
41
+ export declare function menuOutsidePress(state: MenuState): MenuAction | null;
42
+ /** An activated item: it is selected, and `action` closes the menu (when it is open). */
43
+ export interface MenuItemResult {
44
+ action: MenuAction | null;
45
+ }
46
+ /** An item was activated. `null` when it is disabled: nothing is selected, the menu stays. */
47
+ export declare function menuItemPress(state: MenuState, index: number): MenuItemResult | null;
48
+ export declare function menuTriggerAttrs(isOpen: boolean): {
49
+ readonly 'aria-haspopup': "menu";
50
+ readonly 'aria-expanded': "true" | "false";
51
+ };
52
+ export declare function menuPanelAttrs(isOpen: boolean): {
53
+ readonly role: "menu";
54
+ readonly 'aria-hidden': "true" | "false";
55
+ readonly tabindex: -1;
56
+ };
57
+ export interface MenuItemAttrsInput {
58
+ index: number;
59
+ active: number;
60
+ /** The menu is a selection group (some item carries a `selected` flag). */
61
+ selectable: boolean;
62
+ selected?: boolean;
63
+ disabled?: boolean;
64
+ }
65
+ export declare function menuItemAttrs(item: MenuItemAttrsInput): {
66
+ readonly role: "menuitem" | "menuitemradio";
67
+ readonly 'aria-checked': "true" | "false" | undefined;
68
+ readonly 'aria-disabled': "true" | undefined;
69
+ readonly tabindex: 0 | -1;
70
+ };
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Menu core (DS-0198) — the one place the menu's behaviour is decided. Pure functions over a
3
+ * small state object: an event comes in, a {@link MenuAction} comes out, and the caller applies
4
+ * it (Menu.svelte to its `$state`, `vanilla/menu.ts` to the DOM). No DOM, no Svelte.
5
+ */
6
+ import { rovingStep, rovingTabindex } from './behaviors/roving.js';
7
+ const open = (state, edge, reason) => state.open ? null : { type: 'open', focus: rovingStep(state.enabled, -1, edge), reason };
8
+ const close = (state, returnFocus, reason) => state.open ? { type: 'close', returnFocus, reason } : null;
9
+ /** Open from code (`openMenu`), focusing the first or last enabled item. */
10
+ export function menuOpen(state, edge = 'first') {
11
+ return open(state, edge, 'trigger');
12
+ }
13
+ /** Close from code (`closeMenu`). */
14
+ export function menuClose(state, returnFocus = true) {
15
+ return close(state, returnFocus, 'trigger');
16
+ }
17
+ /** The trigger was pressed: toggle. */
18
+ export function menuTriggerPress(state) {
19
+ return state.open ? close(state, true, 'trigger') : open(state, 'first', 'trigger');
20
+ }
21
+ /** A key on the trigger. `null` = not a menu key, let it through. */
22
+ export function menuTriggerKey(state, key) {
23
+ switch (key) {
24
+ case 'ArrowDown':
25
+ case 'Enter':
26
+ case ' ':
27
+ return { action: open(state, 'first', 'key'), preventDefault: true };
28
+ case 'ArrowUp':
29
+ return { action: open(state, 'last', 'key'), preventDefault: true };
30
+ default:
31
+ return null;
32
+ }
33
+ }
34
+ /** A key inside the panel. `null` = not a menu key, let it through. */
35
+ export function menuPanelKey(state, key) {
36
+ const move = (to) => ({
37
+ action: { type: 'focus', index: rovingStep(state.enabled, state.active, to) },
38
+ preventDefault: true,
39
+ });
40
+ switch (key) {
41
+ case 'ArrowDown':
42
+ return move('next');
43
+ case 'ArrowUp':
44
+ return move('prev');
45
+ case 'Home':
46
+ return move('first');
47
+ case 'End':
48
+ return move('last');
49
+ case 'Escape':
50
+ return { action: close(state, true, 'escape'), preventDefault: true };
51
+ case 'Tab':
52
+ // Tabbing out dismisses the menu; focus moves naturally (no trap, no default cancelled).
53
+ return { action: close(state, false, 'tab'), preventDefault: false };
54
+ default:
55
+ return null;
56
+ }
57
+ }
58
+ /** A pointer went down outside the menu: dismiss without pulling focus back. */
59
+ export function menuOutsidePress(state) {
60
+ return close(state, false, 'outside');
61
+ }
62
+ /** An item was activated. `null` when it is disabled: nothing is selected, the menu stays. */
63
+ export function menuItemPress(state, index) {
64
+ if (!state.enabled.includes(index))
65
+ return null;
66
+ return { action: close(state, true, 'item') };
67
+ }
68
+ // --- attributes ---------------------------------------------------------------
69
+ // Strings, not booleans, so the Svelte spread and the vanilla `setAttribute` write the same DOM.
70
+ const bool = (value) => (value ? 'true' : 'false');
71
+ export function menuTriggerAttrs(isOpen) {
72
+ return { 'aria-haspopup': 'menu', 'aria-expanded': bool(isOpen) };
73
+ }
74
+ export function menuPanelAttrs(isOpen) {
75
+ return { role: 'menu', 'aria-hidden': bool(!isOpen), tabindex: -1 };
76
+ }
77
+ export function menuItemAttrs(item) {
78
+ return {
79
+ role: item.selectable ? 'menuitemradio' : 'menuitem',
80
+ 'aria-checked': item.selectable ? bool(Boolean(item.selected)) : undefined,
81
+ 'aria-disabled': item.disabled ? 'true' : undefined,
82
+ tabindex: rovingTabindex(item.index, item.active),
83
+ };
84
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Modal core (DS-0197) — when the dialog closes and why, shared by Modal.svelte and
3
+ * `vanilla/modal.ts`. The element is a native `<dialog>`: the browser owns the focus trap, the
4
+ * focus return to the opener and the Escape key (it fires `cancel`, then closes). The adapters
5
+ * own `showModal()` / `close()` and the scroll lock; this module only decides. No DOM, no Svelte.
6
+ */
7
+ /**
8
+ * Why the modal closed; passed to `onclose` / `ss:close`.
9
+ * `programmatic` = closed from code (the `open` prop, `closeModal()`, a direct `.close()` or a
10
+ * `<form method="dialog">`).
11
+ */
12
+ export type ModalReason = 'escape' | 'backdrop' | 'button' | 'programmatic';
13
+ export interface ModalCloseDetails {
14
+ reason: ModalReason;
15
+ }
16
+ export interface ModalState {
17
+ open: boolean;
18
+ /** Escape closes the modal (`closeOnEsc`; vanilla: no `data-ss-no-esc`). */
19
+ closeOnEsc: boolean;
20
+ /** A press on the backdrop closes the modal (`closeOnBackdrop`; vanilla: no `data-ss-static`). */
21
+ closeOnBackdrop: boolean;
22
+ }
23
+ export type ModalAction = {
24
+ type: 'open';
25
+ } | {
26
+ type: 'close';
27
+ reason: ModalReason;
28
+ };
29
+ /** An opener was pressed (vanilla `[data-ss-modal]`). */
30
+ export declare function modalOpenerPress(state: ModalState): ModalAction | null;
31
+ /** The close button (or any `[data-ss-dismiss]` control) was pressed. */
32
+ export declare function modalDismissPress(state: ModalState): ModalAction | null;
33
+ /**
34
+ * The backdrop was clicked. `onBackdrop` = the press both started and ended on the `<dialog>`
35
+ * element itself rather than the panel inside it (the adapter's hit test, so a drag from the
36
+ * panel out to the backdrop does not count). The adapters call this on `click`, not on
37
+ * `pointerdown`: closing returns focus to the opener, and on pointerdown the same gesture's
38
+ * mousedown would then land on the page and drop focus on `<body>` (DS-0203).
39
+ */
40
+ export declare function modalBackdropPress(state: ModalState, onBackdrop: boolean): ModalAction | null;
41
+ /** The outcome of the native `cancel` event (Escape). */
42
+ export interface ModalCancelResult {
43
+ /** Cancel the event so the browser keeps the dialog open. */
44
+ preventDefault: boolean;
45
+ /** The reason to remember for the close the browser performs next; `null` when it will not. */
46
+ reason: ModalReason | null;
47
+ }
48
+ /**
49
+ * Escape was pressed: the browser fired `cancel` and will close the dialog unless prevented.
50
+ * `cancelable` is the event's own flag: a browser makes `cancel` non-cancelable when the page
51
+ * has already blocked one Escape with no interaction since (its anti-trap rule), and then
52
+ * closes the dialog whatever `closeOnEsc` says — so that close is still an `escape`.
53
+ */
54
+ export declare function modalCancel(state: ModalState, cancelable?: boolean): ModalCancelResult;
55
+ /**
56
+ * The dialog has closed (native `close` event). `pending` is the reason recorded by the action
57
+ * or the cancel that led here; with none, the close came from code.
58
+ */
59
+ export declare function modalClosed(pending: ModalReason | null | undefined): ModalCloseDetails;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Modal core (DS-0197) — when the dialog closes and why, shared by Modal.svelte and
3
+ * `vanilla/modal.ts`. The element is a native `<dialog>`: the browser owns the focus trap, the
4
+ * focus return to the opener and the Escape key (it fires `cancel`, then closes). The adapters
5
+ * own `showModal()` / `close()` and the scroll lock; this module only decides. No DOM, no Svelte.
6
+ */
7
+ /** An opener was pressed (vanilla `[data-ss-modal]`). */
8
+ export function modalOpenerPress(state) {
9
+ return state.open ? null : { type: 'open' };
10
+ }
11
+ /** The close button (or any `[data-ss-dismiss]` control) was pressed. */
12
+ export function modalDismissPress(state) {
13
+ return state.open ? { type: 'close', reason: 'button' } : null;
14
+ }
15
+ /**
16
+ * The backdrop was clicked. `onBackdrop` = the press both started and ended on the `<dialog>`
17
+ * element itself rather than the panel inside it (the adapter's hit test, so a drag from the
18
+ * panel out to the backdrop does not count). The adapters call this on `click`, not on
19
+ * `pointerdown`: closing returns focus to the opener, and on pointerdown the same gesture's
20
+ * mousedown would then land on the page and drop focus on `<body>` (DS-0203).
21
+ */
22
+ export function modalBackdropPress(state, onBackdrop) {
23
+ return state.open && onBackdrop && state.closeOnBackdrop
24
+ ? { type: 'close', reason: 'backdrop' }
25
+ : null;
26
+ }
27
+ /**
28
+ * Escape was pressed: the browser fired `cancel` and will close the dialog unless prevented.
29
+ * `cancelable` is the event's own flag: a browser makes `cancel` non-cancelable when the page
30
+ * has already blocked one Escape with no interaction since (its anti-trap rule), and then
31
+ * closes the dialog whatever `closeOnEsc` says — so that close is still an `escape`.
32
+ */
33
+ export function modalCancel(state, cancelable = true) {
34
+ return state.closeOnEsc || !cancelable
35
+ ? { preventDefault: false, reason: 'escape' }
36
+ : { preventDefault: true, reason: null };
37
+ }
38
+ /**
39
+ * The dialog has closed (native `close` event). `pending` is the reason recorded by the action
40
+ * or the cancel that led here; with none, the close came from code.
41
+ */
42
+ export function modalClosed(pending) {
43
+ return { reason: pending ?? 'programmatic' };
44
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * NumberField core (DS-0197) — parsing, clamping, stepping and the stepper state, shared by
3
+ * NumberField.svelte and `vanilla/fields.ts`. No DOM, no Svelte.
4
+ */
5
+ /** A bound or a value that may be absent (`null`/`undefined` = none). */
6
+ type Maybe = number | null | undefined;
7
+ export interface NumberFieldState {
8
+ /** Current value; `null` when the input is empty or not a number. */
9
+ value: number | null;
10
+ min?: Maybe;
11
+ max?: Maybe;
12
+ /** Stepper increment; defaults to 1. */
13
+ step?: Maybe;
14
+ /** The field is disabled or readonly: nothing may change it. */
15
+ locked: boolean;
16
+ }
17
+ /**
18
+ * The value behind what the input holds. `raw` is its text and `asNumber` what the browser
19
+ * parsed it to (`valueAsNumber`, or `Number(raw)`); empty or unparseable text is `null`.
20
+ */
21
+ export declare function numberFieldParse(raw: string, asNumber: number): number | null;
22
+ /** A numeric option read from markup (`min`/`max`/`step` attribute): `null` when absent. */
23
+ export declare function numberFieldOption(raw: string | null | undefined): number | null;
24
+ /** `n` held inside `[min, max]`; a missing bound does not constrain. */
25
+ export declare function numberFieldClamp(n: number, min?: Maybe, max?: Maybe): number;
26
+ /** Is the value sitting on (or beyond) a bound? An empty field is at neither. */
27
+ export declare function numberFieldBounds(state: Pick<NumberFieldState, 'value' | 'min' | 'max'>): {
28
+ atMin: boolean;
29
+ atMax: boolean;
30
+ };
31
+ /**
32
+ * A stepper was pressed (`dir` 1 = increase, -1 = decrease): the next value, or `null` when the
33
+ * press is a no-op (field locked, or already at that bound). An empty field starts from the
34
+ * near bound (`min` going up, `max` going down), else from 0.
35
+ */
36
+ export declare function numberFieldStep(state: NumberFieldState, dir: 1 | -1): number | null;
37
+ /** What the polite live region says after a stepper changed the value. */
38
+ export declare function numberFieldAnnouncement(value: number): string;
39
+ /**
40
+ * State of one stepper button. Natively `disabled` only when the whole field is locked; at a
41
+ * bound it stays focusable and becomes an `aria-disabled` no-op, so focus never drops to <body>.
42
+ */
43
+ export declare function numberFieldStepperAttrs(state: NumberFieldState, dir: 1 | -1): {
44
+ readonly disabled: boolean;
45
+ readonly 'aria-disabled': "true" | undefined;
46
+ };
47
+ export {};
@@ -0,0 +1,64 @@
1
+ /**
2
+ * NumberField core (DS-0197) — parsing, clamping, stepping and the stepper state, shared by
3
+ * NumberField.svelte and `vanilla/fields.ts`. No DOM, no Svelte.
4
+ */
5
+ /**
6
+ * The value behind what the input holds. `raw` is its text and `asNumber` what the browser
7
+ * parsed it to (`valueAsNumber`, or `Number(raw)`); empty or unparseable text is `null`.
8
+ */
9
+ export function numberFieldParse(raw, asNumber) {
10
+ return raw === '' || Number.isNaN(asNumber) ? null : asNumber;
11
+ }
12
+ /** A numeric option read from markup (`min`/`max`/`step` attribute): `null` when absent. */
13
+ export function numberFieldOption(raw) {
14
+ if (raw == null || raw === '')
15
+ return null;
16
+ const n = Number(raw);
17
+ return Number.isNaN(n) ? null : n;
18
+ }
19
+ /** `n` held inside `[min, max]`; a missing bound does not constrain. */
20
+ export function numberFieldClamp(n, min, max) {
21
+ if (min != null && n < min)
22
+ return min;
23
+ if (max != null && n > max)
24
+ return max;
25
+ return n;
26
+ }
27
+ /** Is the value sitting on (or beyond) a bound? An empty field is at neither. */
28
+ export function numberFieldBounds(state) {
29
+ const { value, min, max } = state;
30
+ return {
31
+ atMin: value != null && min != null && value <= min,
32
+ atMax: value != null && max != null && value >= max,
33
+ };
34
+ }
35
+ /**
36
+ * A stepper was pressed (`dir` 1 = increase, -1 = decrease): the next value, or `null` when the
37
+ * press is a no-op (field locked, or already at that bound). An empty field starts from the
38
+ * near bound (`min` going up, `max` going down), else from 0.
39
+ */
40
+ export function numberFieldStep(state, dir) {
41
+ if (state.locked)
42
+ return null;
43
+ const { atMin, atMax } = numberFieldBounds(state);
44
+ if (dir < 0 ? atMin : atMax)
45
+ return null;
46
+ const base = state.value ?? (dir > 0 ? (state.min ?? 0) : (state.max ?? 0));
47
+ return numberFieldClamp(base + dir * (state.step ?? 1), state.min, state.max);
48
+ }
49
+ /** What the polite live region says after a stepper changed the value. */
50
+ export function numberFieldAnnouncement(value) {
51
+ return String(value);
52
+ }
53
+ /**
54
+ * State of one stepper button. Natively `disabled` only when the whole field is locked; at a
55
+ * bound it stays focusable and becomes an `aria-disabled` no-op, so focus never drops to <body>.
56
+ */
57
+ export function numberFieldStepperAttrs(state, dir) {
58
+ const { atMin, atMax } = numberFieldBounds(state);
59
+ const atBound = dir < 0 ? atMin : atMax;
60
+ return {
61
+ disabled: state.locked,
62
+ 'aria-disabled': !state.locked && atBound ? 'true' : undefined,
63
+ };
64
+ }