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.
Files changed (155) hide show
  1. package/README.md +3 -3
  2. package/dist/components/Accordion.svelte +30 -54
  3. package/dist/components/Badge.svelte +12 -7
  4. package/dist/components/Badge.svelte.d.ts +2 -1
  5. package/dist/components/BottomNav.svelte +18 -28
  6. package/dist/components/BoxPlot.svelte +34 -7
  7. package/dist/components/BumpChart.svelte +65 -26
  8. package/dist/components/Button.svelte +23 -1
  9. package/dist/components/Button.svelte.d.ts +5 -1
  10. package/dist/components/Card.svelte +32 -14
  11. package/dist/components/Card.svelte.d.ts +4 -1
  12. package/dist/components/Chart.svelte +166 -32
  13. package/dist/components/Chart.svelte.d.ts +13 -1
  14. package/dist/components/Checkbox.svelte +210 -0
  15. package/dist/components/Checkbox.svelte.d.ts +38 -0
  16. package/dist/components/DateField.svelte +1 -1
  17. package/dist/components/FileDrop.svelte +113 -77
  18. package/dist/components/FileDrop.svelte.d.ts +12 -2
  19. package/dist/components/Heatmap.svelte +128 -50
  20. package/dist/components/Heatmap.svelte.d.ts +2 -1
  21. package/dist/components/Icon.svelte +12 -3
  22. package/dist/components/Icon.svelte.d.ts +4 -0
  23. package/dist/components/Image.svelte +44 -44
  24. package/dist/components/Input.svelte +11 -6
  25. package/dist/components/Link.svelte +25 -14
  26. package/dist/components/LogStream.svelte +48 -33
  27. package/dist/components/Menu.svelte +81 -102
  28. package/dist/components/Menu.svelte.d.ts +8 -2
  29. package/dist/components/MetricTile.svelte +11 -1
  30. package/dist/components/MetricTile.svelte.d.ts +6 -0
  31. package/dist/components/Modal.svelte +108 -21
  32. package/dist/components/Modal.svelte.d.ts +18 -5
  33. package/dist/components/NumberField.svelte +44 -22
  34. package/dist/components/Pagination.svelte +54 -41
  35. package/dist/components/Pagination.svelte.d.ts +6 -2
  36. package/dist/components/Popover.svelte +247 -0
  37. package/dist/components/Popover.svelte.d.ts +36 -0
  38. package/dist/components/RadioGroup.svelte +227 -0
  39. package/dist/components/RadioGroup.svelte.d.ts +42 -0
  40. package/dist/components/ScatterPlot.svelte +42 -7
  41. package/dist/components/SearchPalette.svelte +216 -136
  42. package/dist/components/SearchPalette.svelte.d.ts +11 -4
  43. package/dist/components/SegmentedControl.svelte +47 -59
  44. package/dist/components/SegmentedControl.svelte.d.ts +7 -2
  45. package/dist/components/Select.svelte +3 -4
  46. package/dist/components/ServiceCard.svelte +105 -68
  47. package/dist/components/ServiceCard.svelte.d.ts +8 -3
  48. package/dist/components/ShortcutsHelp.svelte +49 -48
  49. package/dist/components/Sidebar.svelte +88 -117
  50. package/dist/components/Switch.svelte +24 -18
  51. package/dist/components/Switch.svelte.d.ts +6 -2
  52. package/dist/components/Table.svelte +29 -44
  53. package/dist/components/Table.svelte.d.ts +6 -2
  54. package/dist/components/Tabs.svelte +223 -0
  55. package/dist/components/Tabs.svelte.d.ts +51 -0
  56. package/dist/components/Textarea.svelte +1 -1
  57. package/dist/components/TierList.svelte +45 -49
  58. package/dist/components/TierList.svelte.d.ts +7 -3
  59. package/dist/components/Toaster.svelte +154 -32
  60. package/dist/components/Tooltip.svelte +122 -18
  61. package/dist/components/Tooltip.svelte.d.ts +1 -1
  62. package/dist/components/Topbar.svelte +29 -49
  63. package/dist/core/accordion.d.ts +32 -0
  64. package/dist/core/accordion.js +53 -0
  65. package/dist/core/behaviors/focusable.d.ts +5 -0
  66. package/dist/core/behaviors/focusable.js +14 -0
  67. package/dist/core/behaviors/roving.d.ts +13 -0
  68. package/dist/core/behaviors/roving.js +29 -0
  69. package/dist/core/bottom-nav.d.ts +36 -0
  70. package/dist/core/bottom-nav.js +33 -0
  71. package/dist/core/chart-nav.d.ts +53 -0
  72. package/dist/core/chart-nav.js +62 -0
  73. package/dist/core/checkbox.d.ts +36 -0
  74. package/dist/core/checkbox.js +29 -0
  75. package/dist/core/file-drop.d.ts +75 -0
  76. package/dist/core/file-drop.js +101 -0
  77. package/dist/core/image.d.ts +59 -0
  78. package/dist/core/image.js +64 -0
  79. package/dist/core/input.d.ts +21 -0
  80. package/dist/core/input.js +17 -0
  81. package/dist/core/log-stream.d.ts +51 -0
  82. package/dist/core/log-stream.js +50 -0
  83. package/dist/core/menu.d.ts +70 -0
  84. package/dist/core/menu.js +84 -0
  85. package/dist/core/modal.d.ts +59 -0
  86. package/dist/core/modal.js +44 -0
  87. package/dist/core/number-field.d.ts +47 -0
  88. package/dist/core/number-field.js +64 -0
  89. package/dist/core/pagination.d.ts +59 -0
  90. package/dist/core/pagination.js +65 -0
  91. package/dist/core/popover.d.ts +68 -0
  92. package/dist/core/popover.js +55 -0
  93. package/dist/core/radio.d.ts +36 -0
  94. package/dist/core/radio.js +48 -0
  95. package/dist/core/search-palette.d.ts +124 -0
  96. package/dist/core/search-palette.js +149 -0
  97. package/dist/core/segmented.d.ts +46 -0
  98. package/dist/core/segmented.js +66 -0
  99. package/dist/core/shortcuts-help.d.ts +56 -0
  100. package/dist/core/shortcuts-help.js +50 -0
  101. package/dist/core/sidebar.d.ts +63 -0
  102. package/dist/core/sidebar.js +84 -0
  103. package/dist/core/switch.d.ts +19 -0
  104. package/dist/core/switch.js +11 -0
  105. package/dist/core/table.d.ts +40 -0
  106. package/dist/core/table.js +57 -0
  107. package/dist/core/tabs.d.ts +84 -0
  108. package/dist/core/tabs.js +90 -0
  109. package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +77 -5
  110. package/dist/{tierlist-core.js → core/tierlist.js} +64 -7
  111. package/dist/core/toast.d.ts +112 -0
  112. package/dist/{toast-core.js → core/toast.js} +48 -2
  113. package/dist/core/tooltip.d.ts +47 -0
  114. package/dist/core/tooltip.js +51 -0
  115. package/dist/core/topbar.d.ts +41 -0
  116. package/dist/core/topbar.js +52 -0
  117. package/dist/dssoca.config.d.ts +1 -1
  118. package/dist/dssoca.config.js +4 -0
  119. package/dist/icons.d.ts +19 -2
  120. package/dist/icons.js +42 -3
  121. package/dist/index.d.ts +15 -2
  122. package/dist/index.js +10 -2
  123. package/dist/theme.css +47 -0
  124. package/dist/toast.svelte.d.ts +2 -2
  125. package/dist/toast.svelte.js +1 -1
  126. package/dist/tokens.css +47 -0
  127. package/dist/vanilla/accordion.js +35 -32
  128. package/dist/vanilla/checkbox.d.ts +8 -0
  129. package/dist/vanilla/checkbox.js +43 -0
  130. package/dist/vanilla/delegate.d.ts +2 -0
  131. package/dist/vanilla/delegate.js +9 -0
  132. package/dist/vanilla/fields.js +46 -28
  133. package/dist/vanilla/index.d.ts +5 -1
  134. package/dist/vanilla/index.js +17 -4
  135. package/dist/vanilla/menu.js +101 -84
  136. package/dist/vanilla/modal.d.ts +7 -1
  137. package/dist/vanilla/modal.js +120 -15
  138. package/dist/vanilla/popover.d.ts +10 -0
  139. package/dist/vanilla/popover.js +129 -0
  140. package/dist/vanilla/radio.d.ts +3 -0
  141. package/dist/vanilla/radio.js +54 -0
  142. package/dist/vanilla/segmented.js +50 -43
  143. package/dist/vanilla/switch.d.ts +2 -1
  144. package/dist/vanilla/switch.js +13 -8
  145. package/dist/vanilla/tabs.d.ts +2 -0
  146. package/dist/vanilla/tabs.js +87 -0
  147. package/dist/vanilla/tierlist.d.ts +1 -1
  148. package/dist/vanilla/tierlist.js +34 -34
  149. package/dist/vanilla/toast.d.ts +13 -5
  150. package/dist/vanilla/toast.js +132 -16
  151. package/dist/vanilla/tooltip.d.ts +5 -1
  152. package/dist/vanilla/tooltip.js +78 -19
  153. package/dist/vanilla.css +675 -160
  154. package/package.json +1 -1
  155. package/dist/toast-core.d.ts +0 -61
@@ -0,0 +1,38 @@
1
+ import { type Size } from '../config.js';
2
+ interface Props {
3
+ /** Checked state (bindable). */
4
+ checked?: boolean;
5
+ /**
6
+ * Mixed state (bindable): shown as a dash and announced as "mixed". A user
7
+ * toggle always clears it and lands on checked.
8
+ */
9
+ indeterminate?: boolean;
10
+ /** Visible label next to the box; becomes the accessible name. */
11
+ label?: string;
12
+ /**
13
+ * Visually hide the label while keeping it as the accessible name — for
14
+ * dense rows (table row selection) where the visible context sits elsewhere.
15
+ */
16
+ labelHidden?: boolean;
17
+ /** Id for the underlying input. */
18
+ id?: string;
19
+ /** Form field name: the checkbox is submitted with its form when checked. */
20
+ name?: string;
21
+ /** Submitted value when checked (the browser default is `on`). */
22
+ value?: string;
23
+ /** Disable the checkbox: inert + non-toggling, not submitted. */
24
+ disabled?: boolean;
25
+ /** Token size (sm|md|lg); inherits the global size when unset. */
26
+ size?: Size;
27
+ /** Id of an element that further describes the checkbox (→ aria-describedby). */
28
+ describedby?: string;
29
+ /**
30
+ * Fired after `checked` changes, with the new value. There is no
31
+ * `details.reason`: the native input reports a press on the box, a press on
32
+ * the label and Space as the same event.
33
+ */
34
+ onchange?: (checked: boolean) => void;
35
+ }
36
+ declare const Checkbox: import("svelte").Component<Props, {}, "checked" | "indeterminate">;
37
+ type Checkbox = ReturnType<typeof Checkbox>;
38
+ export default Checkbox;
@@ -112,7 +112,7 @@
112
112
  }
113
113
  .ss-datefield .lbl .req {
114
114
  color: var(--ss-red);
115
- margin-left: 2px;
115
+ margin-inline-start: 2px;
116
116
  }
117
117
  .ss-datefield .control {
118
118
  display: flex;
@@ -1,5 +1,18 @@
1
1
  <script lang="ts">
2
+ import { tick } from 'svelte'
2
3
  import { resolveComponentSize, type Size } from '../config.js'
4
+ import {
5
+ fileDropDrag,
6
+ fileDropKey,
7
+ fileDropPress,
8
+ fileDropRemove,
9
+ fileDropSelect,
10
+ fileDropSize,
11
+ fileDropZoneAttrs,
12
+ type FileDropAction,
13
+ type FileDropChangeDetails,
14
+ type FileDropReason,
15
+ } from '../core/file-drop.js'
3
16
 
4
17
  interface Props {
5
18
  /** Field label, doubles as part of the drop zone's accessible name. */
@@ -18,8 +31,17 @@
18
31
  error?: string
19
32
  /** Selected files. Bindable. */
20
33
  files?: File[]
21
- /** Fired with the resolved file list whenever the selection changes. */
22
- onfiles?: (files: File[]) => void
34
+ /**
35
+ * Fired with the resolved file list whenever the selection changes; `details.reason` says
36
+ * why (`select` from the picker, `drop`, `remove` of one file, or `clear`).
37
+ */
38
+ onfiles?: (files: File[], details: FileDropChangeDetails) => void
39
+ /**
40
+ * Fired with the files a selection/drop discarded (wrong type for `accept`,
41
+ * or extras when `multiple` is false). Rejections are also announced
42
+ * through a polite live region.
43
+ */
44
+ onreject?: (files: File[]) => void
23
45
  }
24
46
  let {
25
47
  label,
@@ -31,10 +53,13 @@
31
53
  error,
32
54
  files = $bindable([]),
33
55
  onfiles,
56
+ onreject,
34
57
  }: Props = $props()
35
58
 
36
59
  const uid = $props.id()
37
60
  const inputId = `${uid}-input`
61
+ const labelId = `${uid}-label`
62
+ const titleId = `${uid}-title`
38
63
  const hintId = `${uid}-hint`
39
64
  const errorId = `${uid}-error`
40
65
 
@@ -43,107 +68,101 @@
43
68
  )
44
69
  const resolvedSize = $derived(resolveComponentSize('FileDrop', size))
45
70
 
46
- // The zone's accessible name: explicit label, else a sensible default; hint
47
- // is folded in for extra context when present.
48
- const accName = $derived(
49
- [label || 'Upload files', hint].filter(Boolean).join('. ') || 'Upload files',
50
- )
71
+ // The zone is named by its visible text (label + "Drop files here") so the
72
+ // accessible name matches what speech-input users see (WCAG 2.5.3). The hint
73
+ // stays in aria-describedby only, so it isn't read twice.
74
+ const labelledBy = $derived(label ? `${labelId} ${titleId}` : titleId)
51
75
 
76
+ let rootEl = $state<HTMLDivElement>()
77
+ let zoneEl = $state<HTMLDivElement>()
52
78
  let inputEl = $state<HTMLInputElement>()
53
79
  let dragging = $state(false)
80
+ // Polite live region text; the region is always mounted so updates announce.
81
+ let status = $state('')
54
82
 
55
- /** Human-readable byte size (1 KB = 1024 B). */
56
- function humanSize(bytes: number): string {
57
- if (bytes < 1024) return `${bytes} B`
58
- const units = ['KB', 'MB', 'GB', 'TB']
59
- let v = bytes / 1024
60
- let i = 0
61
- while (v >= 1024 && i < units.length - 1) {
62
- v /= 1024
63
- i++
64
- }
65
- return `${v.toFixed(v < 10 ? 1 : 0)} ${units[i]}`
83
+ /** Set the live-region text, clearing first so a repeat message re-announces. */
84
+ async function announce(message: string) {
85
+ status = ''
86
+ if (!message) return
87
+ await tick()
88
+ status = message
66
89
  }
67
90
 
68
- /** Does a file satisfy the `accept` filter? Empty accept matches everything. */
69
- function matchesAccept(file: File): boolean {
70
- if (!accept) return true
71
- const name = file.name.toLowerCase()
72
- const type = file.type.toLowerCase()
73
- return accept
74
- .split(',')
75
- .map((t) => t.trim().toLowerCase())
76
- .filter(Boolean)
77
- .some((token) => {
78
- if (token.startsWith('.')) return name.endsWith(token)
79
- if (token.endsWith('/*')) return type.startsWith(token.slice(0, -1))
80
- return type === token
81
- })
82
- }
91
+ // Every decision below comes from core/file-drop.ts; this file holds the state and applies it.
83
92
 
84
- /** Apply accept/multiple, update state, notify. */
85
- function applyFiles(list: File[]) {
93
+ /** Apply accept/multiple, update state, notify (and report rejections). */
94
+ function applyFiles(list: File[], reason: FileDropReason) {
86
95
  if (disabled) return
87
- let next = list.filter(matchesAccept)
88
- if (!multiple) next = next.slice(0, 1)
89
- files = next
90
- onfiles?.(next)
96
+ const { accepted, rejected, announcement } = fileDropSelect(list, { accept, multiple })
97
+ files = accepted
98
+ onfiles?.(accepted, { reason })
99
+ if (rejected.length) onreject?.(rejected.map((r) => r.file))
100
+ void announce(announcement)
101
+ }
102
+
103
+ function apply(action: FileDropAction | null) {
104
+ if (action?.type === 'browse') inputEl?.click()
91
105
  }
92
106
 
93
107
  function openPicker() {
94
- if (disabled) return
95
- inputEl?.click()
108
+ apply(fileDropPress({ disabled }))
96
109
  }
97
110
 
98
111
  function onKeydown(e: KeyboardEvent) {
99
- if (disabled) return
100
- if (e.key === 'Enter' || e.key === ' ') {
101
- e.preventDefault()
102
- openPicker()
103
- }
112
+ const result = fileDropKey({ disabled }, e.key)
113
+ if (!result) return
114
+ if (result.preventDefault) e.preventDefault()
115
+ apply(result.action)
104
116
  }
105
117
 
106
118
  function onChange(e: Event & { currentTarget: HTMLInputElement }) {
107
- applyFiles(Array.from(e.currentTarget.files ?? []))
119
+ applyFiles(Array.from(e.currentTarget.files ?? []), 'select')
108
120
  }
109
121
 
110
- function onDragOver(e: DragEvent) {
111
- if (disabled) return
122
+ /** Track the drag; `false` when the zone is disabled and the event is not ours. */
123
+ function drag(e: DragEvent, event: 'over' | 'leave' | 'drop'): boolean {
124
+ const next = fileDropDrag({ disabled }, event)
125
+ if (next === null) return false
112
126
  e.preventDefault()
113
- dragging = true
114
- }
115
-
116
- function onDragLeave(e: DragEvent) {
117
- if (disabled) return
118
- e.preventDefault()
119
- dragging = false
127
+ dragging = next
128
+ return true
120
129
  }
121
130
 
122
131
  function onDrop(e: DragEvent) {
123
- if (disabled) return
124
- e.preventDefault()
125
- dragging = false
126
- applyFiles(Array.from(e.dataTransfer?.files ?? []))
132
+ if (drag(e, 'drop')) applyFiles(Array.from(e.dataTransfer?.files ?? []), 'drop')
127
133
  }
128
134
 
129
- function removeAt(index: number) {
135
+ async function removeAt(index: number) {
130
136
  if (disabled) return
131
- const next = files.filter((_, i) => i !== index)
132
- files = next
133
- onfiles?.(next)
137
+ const result = fileDropRemove(files, index)
138
+ files = result.files
139
+ onfiles?.(result.files, { reason: 'remove' })
140
+ // The focused button just unmounted: land on the next remove button, else
141
+ // the previous one, else the zone (WCAG 2.4.3).
142
+ await tick()
143
+ const buttons = rootEl?.querySelectorAll<HTMLButtonElement>('.files .remove') ?? []
144
+ ;((result.focus === 'zone' ? undefined : buttons[result.focus]) ?? zoneEl)?.focus()
134
145
  }
135
146
 
136
- function clear() {
147
+ async function clear() {
137
148
  if (disabled) return
138
149
  files = []
139
150
  if (inputEl) inputEl.value = ''
140
- onfiles?.([])
151
+ onfiles?.([], { reason: 'clear' })
152
+ await tick()
153
+ zoneEl?.focus()
141
154
  }
142
155
  </script>
143
156
 
144
- <div class="ss-filedrop" data-size-variant={resolvedSize} class:invalid={!!error} class:disabled>
157
+ <div
158
+ bind:this={rootEl}
159
+ class="ss-filedrop"
160
+ data-size-variant={resolvedSize}
161
+ class:invalid={!!error}
162
+ class:disabled
163
+ >
145
164
  {#if label}
146
- <span class="lbl" id={`${uid}-label`}>{label}</span>
165
+ <span class="lbl" id={labelId}>{label}</span>
147
166
  {/if}
148
167
 
149
168
  <input
@@ -159,22 +178,21 @@
159
178
  onchange={onChange}
160
179
  />
161
180
  <div
181
+ bind:this={zoneEl}
162
182
  class="zone"
163
183
  class:dragging
164
- role="button"
165
- tabindex={disabled ? -1 : 0}
166
- aria-label={accName}
167
- aria-disabled={disabled || undefined}
184
+ {...fileDropZoneAttrs({ disabled })}
185
+ aria-labelledby={labelledBy}
168
186
  aria-describedby={describedBy}
169
187
  onclick={openPicker}
170
188
  onkeydown={onKeydown}
171
- ondragover={onDragOver}
172
- ondragenter={onDragOver}
173
- ondragleave={onDragLeave}
189
+ ondragover={(e) => drag(e, 'over')}
190
+ ondragenter={(e) => drag(e, 'over')}
191
+ ondragleave={(e) => drag(e, 'leave')}
174
192
  ondrop={onDrop}
175
193
  >
176
194
  <span class="prompt">
177
- <span class="title">Drop files here</span>
195
+ <span class="title" id={titleId}>Drop files here</span>
178
196
  <span class="sub">or click to browse</span>
179
197
  </span>
180
198
  </div>
@@ -184,7 +202,7 @@
184
202
  {#each files as file, i (file.name + i)}
185
203
  <li class="file">
186
204
  <span class="name">{file.name}</span>
187
- <span class="bytes">{humanSize(file.size)}</span>
205
+ <span class="bytes">{fileDropSize(file.size)}</span>
188
206
  <button
189
207
  type="button"
190
208
  class="remove"
@@ -200,6 +218,7 @@
200
218
 
201
219
  {#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
202
220
  {#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
221
+ <span class="sr-only" role="status" aria-live="polite">{status}</span>
203
222
  </div>
204
223
 
205
224
  <style>.ss-filedrop {
@@ -247,6 +266,17 @@
247
266
  white-space: nowrap;
248
267
  border: 0;
249
268
  }
269
+ .ss-filedrop .sr-only {
270
+ position: absolute;
271
+ width: 1px;
272
+ height: 1px;
273
+ padding: 0;
274
+ margin: -1px;
275
+ overflow: hidden;
276
+ clip: rect(0 0 0 0);
277
+ white-space: nowrap;
278
+ border: 0;
279
+ }
250
280
  .ss-filedrop .prompt {
251
281
  display: flex;
252
282
  flex-direction: column;
@@ -297,6 +327,11 @@
297
327
  }
298
328
  .ss-filedrop .remove,
299
329
  .ss-filedrop .clear {
330
+ display: inline-flex;
331
+ align-items: center;
332
+ justify-content: center;
333
+ min-inline-size: 24px;
334
+ min-block-size: 24px;
300
335
  font-family: var(--ss-font-body);
301
336
  background: transparent;
302
337
  border: none;
@@ -318,6 +353,7 @@
318
353
  }
319
354
  .ss-filedrop .clear {
320
355
  align-self: flex-start;
356
+ padding-inline: var(--ss-s-1, 4px);
321
357
  font-family: var(--ss-font-mono);
322
358
  font-size: var(--ss-ui-xs);
323
359
  text-transform: uppercase;
@@ -1,4 +1,5 @@
1
1
  import { type Size } from '../config.js';
2
+ import { type FileDropChangeDetails } from '../core/file-drop.js';
2
3
  interface Props {
3
4
  /** Field label, doubles as part of the drop zone's accessible name. */
4
5
  label?: string;
@@ -16,8 +17,17 @@ interface Props {
16
17
  error?: string;
17
18
  /** Selected files. Bindable. */
18
19
  files?: File[];
19
- /** Fired with the resolved file list whenever the selection changes. */
20
- onfiles?: (files: File[]) => void;
20
+ /**
21
+ * Fired with the resolved file list whenever the selection changes; `details.reason` says
22
+ * why (`select` from the picker, `drop`, `remove` of one file, or `clear`).
23
+ */
24
+ onfiles?: (files: File[], details: FileDropChangeDetails) => void;
25
+ /**
26
+ * Fired with the files a selection/drop discarded (wrong type for `accept`,
27
+ * or extras when `multiple` is false). Rejections are also announced
28
+ * through a polite live region.
29
+ */
30
+ onreject?: (files: File[]) => void;
21
31
  }
22
32
  declare const FileDrop: import("svelte").Component<Props, {}, "files">;
23
33
  type FileDrop = ReturnType<typeof FileDrop>;
@@ -2,6 +2,7 @@
2
2
  import { scaleLinear } from 'd3-scale'
3
3
  import { extent } from 'd3-array'
4
4
  import { resolveComponentSize, type Size } from '../config.js'
5
+ import { chartMarkKey, chartTabStop, chartWindowKey } from '../core/chart-nav.js'
5
6
 
6
7
  interface Props {
7
8
  /** Row labels, top→bottom. */
@@ -14,7 +15,8 @@
14
15
  domain?: [number, number]
15
16
  /** Format a cell value for its text + tooltip. */
16
17
  valueFormat?: (v: number) => string
17
- /** Render the value text inside each cell. Default true. */
18
+ /** Render the value text inside each cell. Default true. When false, a min→max legend is
19
+ * drawn instead so intensity is not the only cue. */
18
20
  showValues?: boolean
19
21
  /** X axis caption (drawn under the column headers). */
20
22
  xLabel?: string
@@ -88,11 +90,13 @@
88
90
  // Opacity on the primary token encodes intensity.
89
91
  const opacityScale = $derived(scaleLinear().domain(dom).range([0.12, 1]).clamp(true))
90
92
 
91
- const cells = $derived.by(() =>
92
- cleanRows.flatMap((row, r) =>
93
+ // Grid rows of cells; `i` is the row-major index used by the roving tabindex.
94
+ const gridRows = $derived.by(() =>
95
+ cleanRows.map((row, r) =>
93
96
  cleanCols.map((col, c) => {
94
97
  const v = valueAt(r, c)
95
98
  return {
99
+ i: r * cleanCols.length + c,
96
100
  r,
97
101
  c,
98
102
  row,
@@ -105,6 +109,29 @@
105
109
  }),
106
110
  ),
107
111
  )
112
+ const cellCount = $derived(cleanRows.length * cleanCols.length)
113
+
114
+ // Legend swatches (shown when values are not printed in the cells).
115
+ const LEGEND_STEPS = 5
116
+ const legendStops = $derived(
117
+ Array.from({ length: LEGEND_STEPS }, (_, k) =>
118
+ opacityScale(dom[0] + ((dom[1] - dom[0]) * k) / (LEGEND_STEPS - 1)),
119
+ ),
120
+ )
121
+
122
+ // Roving tabindex: the whole grid is one tab stop (DS-0161 / core/chart-nav.ts).
123
+ let focusIndex = $state(0)
124
+ const tabStop = $derived(chartTabStop(focusIndex, cellCount))
125
+ let gridEl = $state<SVGGElement | null>(null)
126
+
127
+ function onCellKeydown(e: KeyboardEvent, i: number) {
128
+ const result = chartMarkKey({ index: i, count: cellCount, cols: cleanCols.length }, e.key)
129
+ if (!result || result.action.type !== 'focus') return
130
+ if (result.preventDefault) e.preventDefault()
131
+ const next = result.action.index
132
+ focusIndex = next
133
+ gridEl?.querySelector<SVGElement>(`[data-index="${next}"]`)?.focus()
134
+ }
108
135
 
109
136
  const autoSummary = $derived.by(() => {
110
137
  if (isEmpty) return 'No data'
@@ -123,11 +150,18 @@
123
150
  function hide() {
124
151
  active = null
125
152
  }
126
- function cellLabel(row: string, col: string, value: number): string {
127
- return `${row} vs ${col}: ${fmt(value)}`
153
+ function cellLabel(row: string, col: string, value: number | null): string {
154
+ return `${row} vs ${col}: ${value === null ? 'no value' : fmt(value)}`
128
155
  }
129
156
  </script>
130
157
 
158
+ <!-- Escape dismisses the tooltip wherever focus is, incl. one opened by hover (WCAG 1.4.13). -->
159
+ <svelte:window
160
+ onkeydown={(e) => {
161
+ if (chartWindowKey(active !== null, e.key)) hide()
162
+ }}
163
+ />
164
+
131
165
  <div class="ss-heatmap" data-size-variant={resolvedSize} role="group" aria-label={srText}>
132
166
  {#if isEmpty}
133
167
  <span class="empty" aria-hidden="true">—</span>
@@ -143,7 +177,7 @@
143
177
  role="presentation"
144
178
  >
145
179
  <!-- column headers -->
146
- {#each cleanCols as col, c}
180
+ {#each cleanCols as col, c (c)}
147
181
  <text
148
182
  class="header col"
149
183
  x={headLeft + c * cellSize + cellSize / 2}
@@ -153,7 +187,7 @@
153
187
  {/each}
154
188
 
155
189
  <!-- row headers -->
156
- {#each cleanRows as row, r}
190
+ {#each cleanRows as row, r (r)}
157
191
  <text
158
192
  class="header row"
159
193
  x={headLeft - 8}
@@ -163,46 +197,51 @@
163
197
  >
164
198
  {/each}
165
199
 
166
- <!-- cells -->
167
- {#each cells as cell}
168
- {#if cell.value === null}
169
- <rect
170
- class="cell cell-empty"
171
- x={cell.x}
172
- y={cell.y}
173
- width={cellSize}
174
- height={cellSize}
175
- aria-hidden="true"
176
- />
177
- {:else}
178
- <rect
179
- class="cell"
180
- x={cell.x}
181
- y={cell.y}
182
- width={cellSize}
183
- height={cellSize}
184
- fill="var(--ss-primary)"
185
- fill-opacity={cell.opacity}
186
- tabindex="0"
187
- role="button"
188
- aria-label={cellLabel(cell.row, cell.col, cell.value)}
189
- onfocus={() => show(cell.row, cell.col, cell.value!, cell.x + cellSize / 2, cell.y)}
190
- onblur={hide}
191
- onmouseenter={() =>
192
- show(cell.row, cell.col, cell.value!, cell.x + cellSize / 2, cell.y)}
193
- onmouseleave={hide}
194
- />
195
- {#if showValues}
196
- <text
197
- class="cell-text"
198
- x={cell.x + cellSize / 2}
199
- y={cell.y + cellSize / 2}
200
- dy="0.32em"
201
- text-anchor="middle">{fmt(cell.value)}</text
202
- >
203
- {/if}
204
- {/if}
205
- {/each}
200
+ <!-- cells: role=grid > row > gridcell, one tab stop with arrow-key navigation -->
201
+ <g role="grid" bind:this={gridEl}>
202
+ {#each gridRows as cells, r (r)}
203
+ <g role="row">
204
+ {#each cells as cell (cell.i)}
205
+ <rect
206
+ class="cell"
207
+ class:cell-empty={cell.value === null}
208
+ x={cell.x}
209
+ y={cell.y}
210
+ width={cellSize}
211
+ height={cellSize}
212
+ fill={cell.value === null ? undefined : 'var(--ss-primary)'}
213
+ fill-opacity={cell.value === null ? undefined : cell.opacity}
214
+ role="gridcell"
215
+ tabindex={cell.i === tabStop ? 0 : -1}
216
+ data-index={cell.i}
217
+ aria-label={cellLabel(cell.row, cell.col, cell.value)}
218
+ onfocus={() => {
219
+ focusIndex = cell.i
220
+ if (cell.value !== null)
221
+ show(cell.row, cell.col, cell.value, cell.x + cellSize / 2, cell.y)
222
+ }}
223
+ onblur={hide}
224
+ onkeydown={(e) => onCellKeydown(e, cell.i)}
225
+ onmouseenter={() => {
226
+ if (cell.value !== null)
227
+ show(cell.row, cell.col, cell.value, cell.x + cellSize / 2, cell.y)
228
+ }}
229
+ onmouseleave={hide}
230
+ />
231
+ {#if showValues && cell.value !== null}
232
+ <text
233
+ class="cell-text"
234
+ x={cell.x + cellSize / 2}
235
+ y={cell.y + cellSize / 2}
236
+ dy="0.32em"
237
+ text-anchor="middle"
238
+ aria-hidden="true">{fmt(cell.value)}</text
239
+ >
240
+ {/if}
241
+ {/each}
242
+ </g>
243
+ {/each}
244
+ </g>
206
245
 
207
246
  <!-- axis captions -->
208
247
  {#if xLabel}
@@ -222,7 +261,7 @@
222
261
  {#if tooltip && active}
223
262
  <div
224
263
  class="tooltip"
225
- role="status"
264
+ aria-hidden="true"
226
265
  style="left:{(active.cx / width) * 100}%;top:{(active.cy / height) * 100}%"
227
266
  >
228
267
  <span class="t-label">{active.row} · {active.col}</span>
@@ -230,10 +269,23 @@
230
269
  </div>
231
270
  {/if}
232
271
  </div>
272
+ {#if !showValues}
273
+ <!-- Visual-only scale key: every cell's aria-label already carries its value. -->
274
+ <div class="legend" aria-hidden="true">
275
+ <span class="legend-val">{fmt(dom[0])}</span>
276
+ <span class="legend-ramp" aria-hidden="true">
277
+ {#each legendStops as o, k (k)}
278
+ <span class="legend-step" style="opacity:{o}"></span>
279
+ {/each}
280
+ </span>
281
+ <span class="legend-val">{fmt(dom[1])}</span>
282
+ </div>
283
+ {/if}
233
284
  {/if}
234
285
  </div>
235
286
 
236
- <style>.ss-heatmap {
287
+ <style>@charset "UTF-8";
288
+ .ss-heatmap {
237
289
  display: inline-flex;
238
290
  flex-direction: column;
239
291
  gap: var(--ss-gap-sm);
@@ -286,7 +338,7 @@
286
338
  .ss-heatmap .cell {
287
339
  stroke: var(--ss-line);
288
340
  stroke-width: 1;
289
- cursor: pointer;
341
+ cursor: default;
290
342
  shape-rendering: crispEdges;
291
343
  transition: fill-opacity var(--ss-dur-fast) var(--ss-ease);
292
344
  }
@@ -302,12 +354,38 @@
302
354
  fill: none;
303
355
  cursor: default;
304
356
  }
357
+ .ss-heatmap {
358
+ /* Value text: --ss-fg glyphs on a --ss-bg halo, so the glyph's immediate background is
359
+ always --ss-bg whatever the cell opacity (≥13.9:1 in both themes; see DS-0164). A
360
+ two-colour flip cannot reach 4.5:1 across the mid-opacity band. */
361
+ }
305
362
  .ss-heatmap .cell-text {
306
363
  font-family: var(--ss-font-mono);
307
364
  font-size: var(--ss-ui-xs);
308
365
  fill: var(--ss-fg);
366
+ stroke: var(--ss-bg);
367
+ stroke-width: 0.3em;
368
+ stroke-linejoin: round;
369
+ paint-order: stroke fill;
309
370
  pointer-events: none;
310
371
  }
372
+ .ss-heatmap .legend {
373
+ display: flex;
374
+ align-items: center;
375
+ gap: var(--ss-gap-xs);
376
+ font-family: var(--ss-font-mono);
377
+ font-size: var(--ss-ui-xs);
378
+ color: var(--ss-fg-muted);
379
+ }
380
+ .ss-heatmap .legend-ramp {
381
+ display: inline-flex;
382
+ border: 1px solid var(--ss-line);
383
+ }
384
+ .ss-heatmap .legend-step {
385
+ inline-size: var(--ss-icon);
386
+ block-size: var(--ss-gap-sm);
387
+ background: var(--ss-primary);
388
+ }
311
389
  .ss-heatmap .tooltip {
312
390
  position: absolute;
313
391
  transform: translate(-50%, calc(-100% - 8px));
@@ -10,7 +10,8 @@ interface Props {
10
10
  domain?: [number, number];
11
11
  /** Format a cell value for its text + tooltip. */
12
12
  valueFormat?: (v: number) => string;
13
- /** Render the value text inside each cell. Default true. */
13
+ /** Render the value text inside each cell. Default true. When false, a min→max legend is
14
+ * drawn instead so intensity is not the only cue. */
14
15
  showValues?: boolean;
15
16
  /** X axis caption (drawn under the column headers). */
16
17
  xLabel?: string;