dssoca 0.20.0 → 0.22.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 +404 -0
  23. package/dist/components/Popover.svelte.d.ts +55 -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 +41 -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 +111 -0
  72. package/dist/core/popover.js +86 -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 +199 -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 +32 -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 +364 -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
@@ -1,6 +1,18 @@
1
1
  <script lang="ts">
2
2
  import { tick } from 'svelte'
3
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'
4
16
 
5
17
  interface Props {
6
18
  /** Field label, doubles as part of the drop zone's accessible name. */
@@ -19,8 +31,11 @@
19
31
  error?: string
20
32
  /** Selected files. Bindable. */
21
33
  files?: File[]
22
- /** Fired with the resolved file list whenever the selection changes. */
23
- 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
24
39
  /**
25
40
  * Fired with the files a selection/drop discarded (wrong type for `accept`,
26
41
  * or extras when `multiple` is false). Rejections are also announced
@@ -65,35 +80,6 @@
65
80
  // Polite live region text; the region is always mounted so updates announce.
66
81
  let status = $state('')
67
82
 
68
- /** Human-readable byte size (1 KB = 1024 B). */
69
- function humanSize(bytes: number): string {
70
- if (bytes < 1024) return `${bytes} B`
71
- const units = ['KB', 'MB', 'GB', 'TB']
72
- let v = bytes / 1024
73
- let i = 0
74
- while (v >= 1024 && i < units.length - 1) {
75
- v /= 1024
76
- i++
77
- }
78
- return `${v.toFixed(v < 10 ? 1 : 0)} ${units[i]}`
79
- }
80
-
81
- /** Does a file satisfy the `accept` filter? Empty accept matches everything. */
82
- function matchesAccept(file: File): boolean {
83
- if (!accept) return true
84
- const name = file.name.toLowerCase()
85
- const type = file.type.toLowerCase()
86
- return accept
87
- .split(',')
88
- .map((t) => t.trim().toLowerCase())
89
- .filter(Boolean)
90
- .some((token) => {
91
- if (token.startsWith('.')) return name.endsWith(token)
92
- if (token.endsWith('/*')) return type.startsWith(token.slice(0, -1))
93
- return type === token
94
- })
95
- }
96
-
97
83
  /** Set the live-region text, clearing first so a repeat message re-announces. */
98
84
  async function announce(message: string) {
99
85
  status = ''
@@ -102,82 +88,67 @@
102
88
  status = message
103
89
  }
104
90
 
91
+ // Every decision below comes from core/file-drop.ts; this file holds the state and applies it.
92
+
105
93
  /** Apply accept/multiple, update state, notify (and report rejections). */
106
- function applyFiles(list: File[]) {
94
+ function applyFiles(list: File[], reason: FileDropReason) {
107
95
  if (disabled) return
108
- const reasons: string[] = []
109
- const rejected: File[] = []
110
- let next: File[] = []
111
- for (const file of list) {
112
- if (!matchesAccept(file)) {
113
- rejected.push(file)
114
- reasons.push(`${file.name} (file type not accepted)`)
115
- } else if (!multiple && next.length) {
116
- rejected.push(file)
117
- reasons.push(`${file.name} (only one file allowed)`)
118
- } else {
119
- next.push(file)
120
- }
121
- }
122
- files = next
123
- onfiles?.(next)
124
- if (rejected.length) onreject?.(rejected)
125
- void announce(rejected.length ? `Not added: ${reasons.join(', ')}.` : '')
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()
126
105
  }
127
106
 
128
107
  function openPicker() {
129
- if (disabled) return
130
- inputEl?.click()
108
+ apply(fileDropPress({ disabled }))
131
109
  }
132
110
 
133
111
  function onKeydown(e: KeyboardEvent) {
134
- if (disabled) return
135
- if (e.key === 'Enter' || e.key === ' ') {
136
- e.preventDefault()
137
- openPicker()
138
- }
112
+ const result = fileDropKey({ disabled }, e.key)
113
+ if (!result) return
114
+ if (result.preventDefault) e.preventDefault()
115
+ apply(result.action)
139
116
  }
140
117
 
141
118
  function onChange(e: Event & { currentTarget: HTMLInputElement }) {
142
- applyFiles(Array.from(e.currentTarget.files ?? []))
119
+ applyFiles(Array.from(e.currentTarget.files ?? []), 'select')
143
120
  }
144
121
 
145
- function onDragOver(e: DragEvent) {
146
- 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
147
126
  e.preventDefault()
148
- dragging = true
149
- }
150
-
151
- function onDragLeave(e: DragEvent) {
152
- if (disabled) return
153
- e.preventDefault()
154
- dragging = false
127
+ dragging = next
128
+ return true
155
129
  }
156
130
 
157
131
  function onDrop(e: DragEvent) {
158
- if (disabled) return
159
- e.preventDefault()
160
- dragging = false
161
- applyFiles(Array.from(e.dataTransfer?.files ?? []))
132
+ if (drag(e, 'drop')) applyFiles(Array.from(e.dataTransfer?.files ?? []), 'drop')
162
133
  }
163
134
 
164
135
  async function removeAt(index: number) {
165
136
  if (disabled) return
166
- const next = files.filter((_, i) => i !== index)
167
- files = next
168
- onfiles?.(next)
137
+ const result = fileDropRemove(files, index)
138
+ files = result.files
139
+ onfiles?.(result.files, { reason: 'remove' })
169
140
  // The focused button just unmounted: land on the next remove button, else
170
141
  // the previous one, else the zone (WCAG 2.4.3).
171
142
  await tick()
172
143
  const buttons = rootEl?.querySelectorAll<HTMLButtonElement>('.files .remove') ?? []
173
- ;(buttons[index] ?? buttons[index - 1] ?? zoneEl)?.focus()
144
+ ;((result.focus === 'zone' ? undefined : buttons[result.focus]) ?? zoneEl)?.focus()
174
145
  }
175
146
 
176
147
  async function clear() {
177
148
  if (disabled) return
178
149
  files = []
179
150
  if (inputEl) inputEl.value = ''
180
- onfiles?.([])
151
+ onfiles?.([], { reason: 'clear' })
181
152
  await tick()
182
153
  zoneEl?.focus()
183
154
  }
@@ -210,16 +181,14 @@
210
181
  bind:this={zoneEl}
211
182
  class="zone"
212
183
  class:dragging
213
- role="button"
214
- tabindex={disabled ? -1 : 0}
184
+ {...fileDropZoneAttrs({ disabled })}
215
185
  aria-labelledby={labelledBy}
216
- aria-disabled={disabled || undefined}
217
186
  aria-describedby={describedBy}
218
187
  onclick={openPicker}
219
188
  onkeydown={onKeydown}
220
- ondragover={onDragOver}
221
- ondragenter={onDragOver}
222
- ondragleave={onDragLeave}
189
+ ondragover={(e) => drag(e, 'over')}
190
+ ondragenter={(e) => drag(e, 'over')}
191
+ ondragleave={(e) => drag(e, 'leave')}
223
192
  ondrop={onDrop}
224
193
  >
225
194
  <span class="prompt">
@@ -233,7 +202,7 @@
233
202
  {#each files as file, i (file.name + i)}
234
203
  <li class="file">
235
204
  <span class="name">{file.name}</span>
236
- <span class="bytes">{humanSize(file.size)}</span>
205
+ <span class="bytes">{fileDropSize(file.size)}</span>
237
206
  <button
238
207
  type="button"
239
208
  class="remove"
@@ -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,11 @@ 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;
21
25
  /**
22
26
  * Fired with the files a selection/drop discarded (wrong type for `accept`,
23
27
  * or extras when `multiple` is false). Rejections are also announced
@@ -2,7 +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 { chartNavStep } from '../chart-nav.js'
5
+ import { chartMarkKey, chartTabStop, chartWindowKey } from '../core/chart-nav.js'
6
6
 
7
7
  interface Props {
8
8
  /** Row labels, top→bottom. */
@@ -119,16 +119,16 @@
119
119
  ),
120
120
  )
121
121
 
122
- // Roving tabindex: the whole grid is one tab stop (DS-0161 / chart-nav.ts).
122
+ // Roving tabindex: the whole grid is one tab stop (DS-0161 / core/chart-nav.ts).
123
123
  let focusIndex = $state(0)
124
- const tabStop = $derived(Math.min(focusIndex, Math.max(0, cellCount - 1)))
124
+ const tabStop = $derived(chartTabStop(focusIndex, cellCount))
125
125
  let gridEl = $state<SVGGElement | null>(null)
126
126
 
127
127
  function onCellKeydown(e: KeyboardEvent, i: number) {
128
- // SVG geometry does not mirror in RTL, so Left/Right stay physical.
129
- const next = chartNavStep(e.key, i, cellCount, cleanCols.length)
130
- if (next === null) return
131
- e.preventDefault()
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
132
  focusIndex = next
133
133
  gridEl?.querySelector<SVGElement>(`[data-index="${next}"]`)?.focus()
134
134
  }
@@ -158,7 +158,7 @@
158
158
  <!-- Escape dismisses the tooltip wherever focus is, incl. one opened by hover (WCAG 1.4.13). -->
159
159
  <svelte:window
160
160
  onkeydown={(e) => {
161
- if (active && e.key === 'Escape') hide()
161
+ if (chartWindowKey(active !== null, e.key)) hide()
162
162
  }}
163
163
  />
164
164
 
@@ -22,6 +22,16 @@
22
22
  // ─────────────────────────────────────────────────────────────────────────
23
23
  import { tick } from 'svelte'
24
24
  import { resolveComponentSize, type Size } from '../config.js'
25
+ import {
26
+ imageAspect,
27
+ imageCanOpen,
28
+ imageDialogAttrs,
29
+ imageDialogKey,
30
+ imageFrameAttrs,
31
+ imageLoadResult,
32
+ imageTriggerAttrs,
33
+ type ImageLoadState,
34
+ } from '../core/image.js'
25
35
 
26
36
  interface Props {
27
37
  /** Image URL. */
@@ -77,20 +87,20 @@
77
87
  class: className,
78
88
  }: Props = $props()
79
89
 
90
+ // Behaviour lives in `core/image.ts`: the load state, whether the lightbox may open and
91
+ // what a key inside it does are decided there; this file holds the state and applies it.
92
+
80
93
  // Reserve space before load → no layout shift (CLS). Prefer an explicit
81
94
  // ratio, else derive from intrinsic width/height. `null` → no box reserved.
82
- const aspect = $derived(
83
- ratio && ratio > 0 ? ratio : width && height && height > 0 ? width / height : null,
84
- )
95
+ const aspect = $derived(imageAspect({ ratio, width, height }))
85
96
 
86
- type State = 'loading' | 'loaded' | 'error'
87
- let loadState = $state<State>('loading')
97
+ let loadState = $state<ImageLoadState>('loading')
88
98
 
89
99
  function onLoad() {
90
- loadState = 'loaded'
100
+ loadState = imageLoadResult('load')
91
101
  }
92
102
  function onError() {
93
- loadState = 'error'
103
+ loadState = imageLoadResult('error')
94
104
  }
95
105
 
96
106
  // ── Lightbox ───────────────────────────────────────────────────────────
@@ -99,7 +109,7 @@
99
109
  let dialog = $state<HTMLDivElement | null>(null)
100
110
  let closeBtn = $state<HTMLButtonElement | null>(null)
101
111
 
102
- const canOpen = $derived(lightbox && loadState !== 'error')
112
+ const canOpen = $derived(imageCanOpen(lightbox, loadState))
103
113
 
104
114
  async function openLightbox() {
105
115
  if (!canOpen) return
@@ -114,36 +124,30 @@
114
124
  trigger?.focus()
115
125
  }
116
126
 
117
- // Focus trap + Esc, scoped to the dialog (keeps Tab inside the overlay).
127
+ // DS-0078: exclude disabled focusables (and anything opted out of the tab
128
+ // order with tabindex="-1", e.g. the backdrop button) so the trap never
129
+ // wraps relative to an element that cannot actually take tab focus.
130
+ const FOCUSABLE = [
131
+ 'button:not([disabled]):not([aria-disabled="true"]):not([tabindex="-1"])',
132
+ '[href]:not([aria-disabled="true"]):not([tabindex="-1"])',
133
+ '[tabindex]:not([tabindex="-1"]):not([disabled]):not([aria-disabled="true"])',
134
+ ].join(', ')
135
+
136
+ // Focus trap + Esc, scoped to the dialog (keeps Tab inside the overlay). The DOM is read
137
+ // here; the core decides what the key does.
118
138
  function onDialogKeydown(e: KeyboardEvent) {
119
- if (e.key === 'Escape') {
120
- e.preventDefault()
121
- e.stopPropagation()
122
- closeLightbox()
123
- return
124
- }
125
- if (e.key !== 'Tab' || !dialog) return
126
- // DS-0078: exclude disabled focusables (and anything opted out of the tab
127
- // order with tabindex="-1", e.g. the backdrop button) so the trap never
128
- // wraps relative to an element that cannot actually take tab focus.
129
- const focusables = dialog.querySelectorAll<HTMLElement>(
130
- [
131
- 'button:not([disabled]):not([aria-disabled="true"]):not([tabindex="-1"])',
132
- '[href]:not([aria-disabled="true"]):not([tabindex="-1"])',
133
- '[tabindex]:not([tabindex="-1"]):not([disabled]):not([aria-disabled="true"])',
134
- ].join(', '),
135
- )
136
- if (focusables.length === 0) return
137
- const first = focusables[0]
138
- const last = focusables[focusables.length - 1]
139
- const active = document.activeElement
140
- if (e.shiftKey && active === first) {
141
- e.preventDefault()
142
- last.focus()
143
- } else if (!e.shiftKey && active === last) {
144
- e.preventDefault()
145
- first.focus()
146
- }
139
+ const focusables = dialog ? [...dialog.querySelectorAll<HTMLElement>(FOCUSABLE)] : []
140
+ const result = imageDialogKey({
141
+ key: e.key,
142
+ shiftKey: e.shiftKey,
143
+ focusableCount: focusables.length,
144
+ activeIndex: focusables.indexOf(document.activeElement as HTMLElement),
145
+ })
146
+ if (!result) return
147
+ if (result.preventDefault) e.preventDefault()
148
+ if (result.stopPropagation) e.stopPropagation()
149
+ if (result.action.type === 'close') closeLightbox()
150
+ else focusables[result.action.index]?.focus()
147
151
  }
148
152
  </script>
149
153
 
@@ -157,7 +161,7 @@
157
161
  <div
158
162
  class="frame"
159
163
  style:aspect-ratio={aspect != null ? `${aspect}` : undefined}
160
- aria-busy={loadState === 'loading'}
164
+ {...imageFrameAttrs(loadState)}
161
165
  >
162
166
  {#if loadState === 'error'}
163
167
  <div class="fallback" role="img" aria-label={alt || 'Image failed to load'}>
@@ -172,8 +176,7 @@
172
176
  bind:this={trigger}
173
177
  type="button"
174
178
  class="trigger"
175
- aria-haspopup="dialog"
176
- aria-label={alt ? `View image: ${alt}` : 'View image full size'}
179
+ {...imageTriggerAttrs(alt)}
177
180
  onclick={openLightbox}
178
181
  >
179
182
  {@render media()}
@@ -215,10 +218,7 @@
215
218
  bind:this={dialog}
216
219
  class="ss-image-lightbox"
217
220
  data-size-variant={resolveComponentSize('Image', size)}
218
- role="dialog"
219
- aria-modal="true"
220
- aria-label={alt ? `Image: ${alt}` : 'Image preview'}
221
- tabindex="-1"
221
+ {...imageDialogAttrs(alt)}
222
222
  onkeydown={onDialogKeydown}
223
223
  >
224
224
  <button type="button" class="backdrop" tabindex="-1" aria-hidden="true" onclick={closeLightbox}
@@ -2,6 +2,7 @@
2
2
  import type { Snippet } from 'svelte'
3
3
  import type { HTMLInputAttributes, FullAutoFill } from 'svelte/elements'
4
4
  import { resolveComponentSize, type Size } from '../config.js'
5
+ import { inputClear, inputShowClear } from '../core/input.js'
5
6
 
6
7
  interface Props {
7
8
  label?: string
@@ -80,12 +81,16 @@
80
81
  const resolvedSize = $derived(resolveComponentSize('Input', size))
81
82
 
82
83
  // The .ss-field wrapper carries the border/focus ring; show the clear button only when useful.
83
- const showClear = $derived(clearable && !!value && !readonly && !disabled)
84
+ // Both decisions come from core/input.ts, shared with vanilla.js.
85
+ const clearState = $derived({ value: value ? String(value) : '', readonly, disabled })
86
+ const showClear = $derived(clearable && inputShowClear(clearState))
84
87
 
85
88
  let inputEl = $state<HTMLInputElement>()
86
89
  function clear() {
87
- value = ''
88
- inputEl?.focus()
90
+ const result = inputClear(clearState)
91
+ if (!result) return
92
+ value = result.value
93
+ if (result.focusInput) inputEl?.focus()
89
94
  }
90
95
  </script>
91
96
 
@@ -12,13 +12,19 @@
12
12
  svc?: string
13
13
  msg: string
14
14
  }
15
-
16
- const LEVELS: LogLevel[] = ['info', 'warn', 'err', 'ok']
17
15
  </script>
18
16
 
19
17
  <script lang="ts">
20
18
  import { tick, untrack, type Snippet } from 'svelte'
21
19
  import { resolveComponentSize, type Size } from '../config.js'
20
+ import {
21
+ LOG_LEVELS,
22
+ filterLogLines,
23
+ logCopyText,
24
+ logEmptyMessage,
25
+ logFollowsTail,
26
+ toggleLogLevel,
27
+ } from '../core/log-stream.js'
22
28
 
23
29
  interface Props {
24
30
  /** Controlled lines. When provided, the component renders exactly these (capped to `maxLines`). */
@@ -102,36 +108,21 @@
102
108
  const allLines = $derived((controlled ? (lines as LogLine[]) : demoLines).slice(-maxLines))
103
109
 
104
110
  // --- toolbar state ---
105
- let activeLevels = $state<Set<LogLevel>>(new Set(LEVELS))
111
+ let activeLevels = $state<Set<LogLevel>>(new Set(LOG_LEVELS))
106
112
  let query = $state('')
107
113
  let wrapOn = $state(untrack(() => wrap))
108
114
  $effect(() => {
109
115
  wrapOn = wrap
110
116
  })
111
117
 
112
- const visibleLines = $derived(
113
- allLines.filter((l) => {
114
- if (!activeLevels.has(l.lvl)) return false
115
- if (query.trim()) {
116
- const q = query.toLowerCase()
117
- const hay = `${l.t ?? ''} ${l.lvl} ${l.svc ?? ''} ${l.msg}`.toLowerCase()
118
- if (!hay.includes(q)) return false
119
- }
120
- return true
121
- }),
122
- )
118
+ const visibleLines = $derived(filterLogLines(allLines, { levels: activeLevels, query }))
123
119
 
124
120
  function toggleLevel(lvl: LogLevel) {
125
- const next = new Set(activeLevels)
126
- if (next.has(lvl)) next.delete(lvl)
127
- else next.add(lvl)
128
- activeLevels = next
121
+ activeLevels = toggleLogLevel(activeLevels, lvl)
129
122
  }
130
123
 
131
124
  async function copyVisible() {
132
- const text = visibleLines
133
- .map((l) => `${l.t ?? ''} ${l.lvl.toUpperCase()} ${l.svc ?? ''} ${l.msg}`.trim())
134
- .join('\n')
125
+ const text = logCopyText(visibleLines)
135
126
  try {
136
127
  await navigator.clipboard?.writeText(text)
137
128
  } catch {
@@ -147,11 +138,10 @@
147
138
  // --- follow-tail ---
148
139
  let el: HTMLDivElement | undefined
149
140
  let following = $state(true)
150
- const NEAR = 24 // px from bottom considered "at bottom"
151
141
 
152
142
  function atBottom() {
153
143
  if (!el) return true
154
- return el.scrollHeight - el.scrollTop - el.clientHeight <= NEAR
144
+ return logFollowsTail(el)
155
145
  }
156
146
 
157
147
  function onScroll() {
@@ -196,7 +186,7 @@
196
186
  {:else}
197
187
  <div class="bar">
198
188
  <div class="filters" role="group" aria-label="Filter by level">
199
- {#each LEVELS as lvl (lvl)}
189
+ {#each LOG_LEVELS as lvl (lvl)}
200
190
  <button
201
191
  type="button"
202
192
  class="chip {lvl}"
@@ -252,7 +242,7 @@
252
242
  <div class="empty">
253
243
  <p class="empty-title">No log lines</p>
254
244
  <p class="empty-msg">
255
- {allLines.length ? 'No lines match the current filters.' : 'Waiting for output…'}
245
+ {logEmptyMessage(allLines.length)}
256
246
  </p>
257
247
  </div>
258
248
  {/if}