dssoca 0.19.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.
- package/README.md +3 -3
- package/dist/components/Accordion.svelte +30 -54
- package/dist/components/Badge.svelte +12 -7
- package/dist/components/Badge.svelte.d.ts +2 -1
- package/dist/components/BottomNav.svelte +18 -28
- package/dist/components/BoxPlot.svelte +34 -7
- package/dist/components/BumpChart.svelte +65 -26
- package/dist/components/Button.svelte +23 -1
- package/dist/components/Button.svelte.d.ts +5 -1
- package/dist/components/Card.svelte +32 -14
- package/dist/components/Card.svelte.d.ts +4 -1
- package/dist/components/Chart.svelte +166 -32
- package/dist/components/Chart.svelte.d.ts +13 -1
- package/dist/components/Checkbox.svelte +210 -0
- package/dist/components/Checkbox.svelte.d.ts +38 -0
- package/dist/components/DateField.svelte +1 -1
- package/dist/components/FileDrop.svelte +113 -77
- package/dist/components/FileDrop.svelte.d.ts +12 -2
- package/dist/components/Heatmap.svelte +128 -50
- package/dist/components/Heatmap.svelte.d.ts +2 -1
- package/dist/components/Icon.svelte +12 -3
- package/dist/components/Icon.svelte.d.ts +4 -0
- package/dist/components/Image.svelte +44 -44
- package/dist/components/Input.svelte +11 -6
- package/dist/components/Link.svelte +25 -14
- package/dist/components/LogStream.svelte +48 -33
- package/dist/components/Menu.svelte +81 -102
- package/dist/components/Menu.svelte.d.ts +8 -2
- package/dist/components/MetricTile.svelte +11 -1
- package/dist/components/MetricTile.svelte.d.ts +6 -0
- package/dist/components/Modal.svelte +108 -21
- package/dist/components/Modal.svelte.d.ts +18 -5
- package/dist/components/NumberField.svelte +44 -22
- package/dist/components/Pagination.svelte +54 -41
- package/dist/components/Pagination.svelte.d.ts +6 -2
- package/dist/components/Popover.svelte +247 -0
- package/dist/components/Popover.svelte.d.ts +36 -0
- package/dist/components/RadioGroup.svelte +227 -0
- package/dist/components/RadioGroup.svelte.d.ts +42 -0
- package/dist/components/ScatterPlot.svelte +42 -7
- package/dist/components/SearchPalette.svelte +216 -136
- package/dist/components/SearchPalette.svelte.d.ts +11 -4
- package/dist/components/SegmentedControl.svelte +47 -59
- package/dist/components/SegmentedControl.svelte.d.ts +7 -2
- package/dist/components/Select.svelte +3 -4
- package/dist/components/ServiceCard.svelte +105 -68
- package/dist/components/ServiceCard.svelte.d.ts +8 -3
- package/dist/components/ShortcutsHelp.svelte +49 -48
- package/dist/components/Sidebar.svelte +88 -117
- package/dist/components/Switch.svelte +24 -18
- package/dist/components/Switch.svelte.d.ts +6 -2
- package/dist/components/Table.svelte +29 -44
- package/dist/components/Table.svelte.d.ts +6 -2
- package/dist/components/Tabs.svelte +223 -0
- package/dist/components/Tabs.svelte.d.ts +51 -0
- package/dist/components/Textarea.svelte +1 -1
- package/dist/components/TierList.svelte +45 -49
- package/dist/components/TierList.svelte.d.ts +7 -3
- package/dist/components/Toaster.svelte +154 -32
- package/dist/components/Tooltip.svelte +122 -18
- package/dist/components/Tooltip.svelte.d.ts +1 -1
- package/dist/components/Topbar.svelte +29 -49
- package/dist/core/accordion.d.ts +32 -0
- package/dist/core/accordion.js +53 -0
- package/dist/core/behaviors/focusable.d.ts +5 -0
- package/dist/core/behaviors/focusable.js +14 -0
- package/dist/core/behaviors/roving.d.ts +13 -0
- package/dist/core/behaviors/roving.js +29 -0
- package/dist/core/bottom-nav.d.ts +36 -0
- package/dist/core/bottom-nav.js +33 -0
- package/dist/core/chart-nav.d.ts +53 -0
- package/dist/core/chart-nav.js +62 -0
- package/dist/core/checkbox.d.ts +36 -0
- package/dist/core/checkbox.js +29 -0
- package/dist/core/file-drop.d.ts +75 -0
- package/dist/core/file-drop.js +101 -0
- package/dist/core/image.d.ts +59 -0
- package/dist/core/image.js +64 -0
- package/dist/core/input.d.ts +21 -0
- package/dist/core/input.js +17 -0
- package/dist/core/log-stream.d.ts +51 -0
- package/dist/core/log-stream.js +50 -0
- package/dist/core/menu.d.ts +70 -0
- package/dist/core/menu.js +84 -0
- package/dist/core/modal.d.ts +59 -0
- package/dist/core/modal.js +44 -0
- package/dist/core/number-field.d.ts +47 -0
- package/dist/core/number-field.js +64 -0
- package/dist/core/pagination.d.ts +59 -0
- package/dist/core/pagination.js +65 -0
- package/dist/core/popover.d.ts +68 -0
- package/dist/core/popover.js +55 -0
- package/dist/core/radio.d.ts +36 -0
- package/dist/core/radio.js +48 -0
- package/dist/core/search-palette.d.ts +124 -0
- package/dist/core/search-palette.js +149 -0
- package/dist/core/segmented.d.ts +46 -0
- package/dist/core/segmented.js +66 -0
- package/dist/core/shortcuts-help.d.ts +56 -0
- package/dist/core/shortcuts-help.js +50 -0
- package/dist/core/sidebar.d.ts +63 -0
- package/dist/core/sidebar.js +84 -0
- package/dist/core/switch.d.ts +19 -0
- package/dist/core/switch.js +11 -0
- package/dist/core/table.d.ts +40 -0
- package/dist/core/table.js +57 -0
- package/dist/core/tabs.d.ts +84 -0
- package/dist/core/tabs.js +90 -0
- package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +77 -5
- package/dist/{tierlist-core.js → core/tierlist.js} +64 -7
- package/dist/core/toast.d.ts +112 -0
- package/dist/{toast-core.js → core/toast.js} +48 -2
- package/dist/core/tooltip.d.ts +47 -0
- package/dist/core/tooltip.js +51 -0
- package/dist/core/topbar.d.ts +41 -0
- package/dist/core/topbar.js +52 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +4 -0
- package/dist/icons.d.ts +19 -2
- package/dist/icons.js +42 -3
- package/dist/index.d.ts +15 -2
- package/dist/index.js +10 -2
- package/dist/theme.css +47 -0
- package/dist/toast.svelte.d.ts +2 -2
- package/dist/toast.svelte.js +1 -1
- package/dist/tokens.css +47 -0
- package/dist/vanilla/accordion.js +35 -32
- package/dist/vanilla/checkbox.d.ts +8 -0
- package/dist/vanilla/checkbox.js +43 -0
- package/dist/vanilla/delegate.d.ts +2 -0
- package/dist/vanilla/delegate.js +9 -0
- package/dist/vanilla/fields.js +46 -28
- package/dist/vanilla/index.d.ts +5 -1
- package/dist/vanilla/index.js +17 -4
- package/dist/vanilla/menu.js +101 -84
- package/dist/vanilla/modal.d.ts +7 -1
- package/dist/vanilla/modal.js +120 -15
- package/dist/vanilla/popover.d.ts +10 -0
- package/dist/vanilla/popover.js +129 -0
- package/dist/vanilla/radio.d.ts +3 -0
- package/dist/vanilla/radio.js +54 -0
- package/dist/vanilla/segmented.js +50 -43
- package/dist/vanilla/switch.d.ts +2 -1
- package/dist/vanilla/switch.js +13 -8
- package/dist/vanilla/tabs.d.ts +2 -0
- package/dist/vanilla/tabs.js +87 -0
- package/dist/vanilla/tierlist.d.ts +1 -1
- package/dist/vanilla/tierlist.js +34 -34
- package/dist/vanilla/toast.d.ts +13 -5
- package/dist/vanilla/toast.js +132 -16
- package/dist/vanilla/tooltip.d.ts +5 -1
- package/dist/vanilla/tooltip.js +78 -19
- package/dist/vanilla.css +675 -160
- package/package.json +1 -1
- 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,15 +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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
),
|
|
119
|
-
)
|
|
117
|
+
const items = $derived(topbarTabs(tabs))
|
|
118
|
+
|
|
119
|
+
// DS-0182: the roving tab stop is the active tab; when `active` matches no
|
|
120
|
+
// tab, fall back to the first button tab so the strip stays reachable by Tab.
|
|
121
|
+
const rovingIdx = $derived(topbarRovingIndex(items, active))
|
|
120
122
|
|
|
121
123
|
// DS-0081: resolve the services prop to data-or-nothing.
|
|
122
124
|
const svc = $derived(services === true ? DEFAULT_SERVICES : services === false ? null : services)
|
|
@@ -164,33 +166,13 @@
|
|
|
164
166
|
// tab stop; link tabs stay in the natural tab order so they remain
|
|
165
167
|
// keyboard-reachable without JS (SSR, DS-0080).
|
|
166
168
|
let tabEls: (HTMLAnchorElement | HTMLButtonElement)[] = $state([])
|
|
167
|
-
function focusTab(i: number) {
|
|
168
|
-
const n = items.length
|
|
169
|
-
if (!n) return
|
|
170
|
-
const idx = ((i % n) + n) % n
|
|
171
|
-
tabEls[idx]?.focus()
|
|
172
|
-
}
|
|
173
169
|
function onTabKeydown(e: KeyboardEvent, i: number) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
case 'ArrowLeft':
|
|
181
|
-
case 'ArrowUp':
|
|
182
|
-
e.preventDefault()
|
|
183
|
-
focusTab(i - 1)
|
|
184
|
-
break
|
|
185
|
-
case 'Home':
|
|
186
|
-
e.preventDefault()
|
|
187
|
-
focusTab(0)
|
|
188
|
-
break
|
|
189
|
-
case 'End':
|
|
190
|
-
e.preventDefault()
|
|
191
|
-
focusTab(items.length - 1)
|
|
192
|
-
break
|
|
193
|
-
}
|
|
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()
|
|
194
176
|
}
|
|
195
177
|
</script>
|
|
196
178
|
|
|
@@ -239,7 +221,7 @@
|
|
|
239
221
|
type="button"
|
|
240
222
|
class="tab {current ? 'active' : ''}"
|
|
241
223
|
aria-current={current ? 'page' : undefined}
|
|
242
|
-
tabindex={
|
|
224
|
+
tabindex={topbarTabTabindex(tab, i, rovingIdx)}
|
|
243
225
|
onclick={() => onTab?.(tab.id)}
|
|
244
226
|
onkeydown={(e) => onTabKeydown(e, i)}
|
|
245
227
|
>
|
|
@@ -312,8 +294,8 @@
|
|
|
312
294
|
}
|
|
313
295
|
.ss-topbar .skip {
|
|
314
296
|
position: absolute;
|
|
315
|
-
|
|
316
|
-
|
|
297
|
+
inset-inline-start: var(--ss-s-1);
|
|
298
|
+
inset-block-start: var(--ss-s-1);
|
|
317
299
|
z-index: 20;
|
|
318
300
|
padding: var(--ss-chip-py) var(--ss-badge-px);
|
|
319
301
|
background: var(--ss-primary);
|
|
@@ -331,13 +313,13 @@
|
|
|
331
313
|
align-items: center;
|
|
332
314
|
gap: var(--ss-s-2);
|
|
333
315
|
padding: 0 var(--ss-panel-head-px);
|
|
334
|
-
border-
|
|
316
|
+
border-inline-end: 1px solid var(--ss-line);
|
|
335
317
|
cursor: default;
|
|
336
318
|
flex: none;
|
|
337
319
|
}
|
|
338
320
|
.ss-topbar .seg.right {
|
|
339
|
-
border-
|
|
340
|
-
border-
|
|
321
|
+
border-inline-end: none;
|
|
322
|
+
border-inline-start: 1px solid var(--ss-line);
|
|
341
323
|
}
|
|
342
324
|
.ss-topbar .seg.click {
|
|
343
325
|
cursor: pointer;
|
|
@@ -348,15 +330,14 @@
|
|
|
348
330
|
}
|
|
349
331
|
.ss-topbar button.seg {
|
|
350
332
|
background: transparent;
|
|
351
|
-
border-
|
|
352
|
-
border-
|
|
353
|
-
border-right: 0;
|
|
333
|
+
border-block: 0;
|
|
334
|
+
border-inline-end: 0;
|
|
354
335
|
color: inherit;
|
|
355
336
|
font: inherit;
|
|
356
337
|
min-height: var(--ss-s-6);
|
|
357
338
|
}
|
|
358
339
|
.ss-topbar button.seg.right {
|
|
359
|
-
border-
|
|
340
|
+
border-inline-start: 1px solid var(--ss-line);
|
|
360
341
|
}
|
|
361
342
|
.ss-topbar .logo {
|
|
362
343
|
color: var(--ss-fg);
|
|
@@ -385,13 +366,12 @@
|
|
|
385
366
|
padding: 0 var(--ss-row-px);
|
|
386
367
|
min-height: var(--ss-s-6);
|
|
387
368
|
color: var(--ss-fg-faint);
|
|
388
|
-
border-
|
|
369
|
+
border-inline-end: 1px solid var(--ss-line);
|
|
389
370
|
cursor: pointer;
|
|
390
371
|
font: 500 var(--ss-ui-md) var(--ss-font-mono);
|
|
391
372
|
background: transparent;
|
|
392
|
-
border-
|
|
393
|
-
border-
|
|
394
|
-
border-left: 0;
|
|
373
|
+
border-block: 0;
|
|
374
|
+
border-inline-start: 0;
|
|
395
375
|
text-decoration: none;
|
|
396
376
|
transition: all var(--ss-dur-fast) var(--ss-ease);
|
|
397
377
|
}
|
|
@@ -401,7 +381,7 @@
|
|
|
401
381
|
}
|
|
402
382
|
.ss-topbar .ws .tab .n {
|
|
403
383
|
color: var(--ss-fg-faint);
|
|
404
|
-
margin-
|
|
384
|
+
margin-inline-end: 6px;
|
|
405
385
|
}
|
|
406
386
|
.ss-topbar .ws .tab.active {
|
|
407
387
|
color: var(--ss-fg);
|
|
@@ -425,7 +405,7 @@
|
|
|
425
405
|
}
|
|
426
406
|
.ss-topbar .stat .k {
|
|
427
407
|
color: var(--ss-fg-faint);
|
|
428
|
-
margin-
|
|
408
|
+
margin-inline-end: var(--ss-s-1);
|
|
429
409
|
}
|
|
430
410
|
.ss-topbar .stat .v {
|
|
431
411
|
color: var(--ss-fg);
|
|
@@ -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,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;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 function chartNavStep(key, index, count, cols) {
|
|
14
|
+
if (count <= 0)
|
|
15
|
+
return null;
|
|
16
|
+
const last = count - 1;
|
|
17
|
+
const clamp = (i) => Math.min(last, Math.max(0, i));
|
|
18
|
+
const row = cols ?? 1;
|
|
19
|
+
switch (key) {
|
|
20
|
+
case 'ArrowRight':
|
|
21
|
+
return clamp(index + 1);
|
|
22
|
+
case 'ArrowLeft':
|
|
23
|
+
return clamp(index - 1);
|
|
24
|
+
case 'ArrowDown':
|
|
25
|
+
return cols ? (index + row <= last ? index + row : index) : clamp(index + 1);
|
|
26
|
+
case 'ArrowUp':
|
|
27
|
+
return cols ? (index - row >= 0 ? index - row : index) : clamp(index - 1);
|
|
28
|
+
case 'Home':
|
|
29
|
+
return 0;
|
|
30
|
+
case 'End':
|
|
31
|
+
return last;
|
|
32
|
+
default:
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
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
|
+
};
|