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
@@ -9,7 +9,11 @@
9
9
  import { resolveComponentSize, type Size } from '../config.js'
10
10
  // Aliased: the module script re-exports the same names, and eslint-plugin-svelte
11
11
  // merges both scopes.
12
- import { resolveIcon as lookupIcon, type IconName as GlyphName } from '../icons.js'
12
+ import {
13
+ resolveIcon as lookupIcon,
14
+ sanitizeIconMarkup,
15
+ type IconName as GlyphName,
16
+ } from '../icons.js'
13
17
 
14
18
  /**
15
19
  * Icon-local size scale (DS-0109). Distinct from the global `Size` axis
@@ -37,6 +41,10 @@
37
41
  * Raw SVG inner markup escape hatch — rendered when `name` is not a known
38
42
  * (built-in or runtime-registered) glyph. Lets callers pass one-off icons
39
43
  * without registering them globally.
44
+ *
45
+ * **Must be trusted markup** (authored by you, never user input): it is injected as HTML.
46
+ * A light filter strips `<script>`, `<foreignObject>`, `on*` handlers and `javascript:`
47
+ * links, but it is not a security boundary.
40
48
  */
41
49
  paths?: string
42
50
  /** Accessible name; rendered as a real <title> and wired via aria-labelledby. */
@@ -88,7 +96,7 @@
88
96
 
89
97
  // Resolve the glyph: explicit `paths` escape hatch → registered/built-in → warn.
90
98
  const markup = $derived.by(() => {
91
- if (paths != null) return paths
99
+ if (paths != null) return sanitizeIconMarkup(paths)
92
100
  const found = lookupIcon(name)
93
101
  if (found != null) return found
94
102
  if (typeof console !== 'undefined') {
@@ -132,7 +140,6 @@
132
140
  )
133
141
  </script>
134
142
 
135
- <!-- eslint-disable-next-line svelte/no-at-html-tags -->
136
143
  <svg
137
144
  viewBox="0 0 24 24"
138
145
  fill={isSolid ? 'currentColor' : 'none'}
@@ -152,6 +159,8 @@
152
159
  aria-hidden={isDecorative ? 'true' : undefined}
153
160
  focusable="false"
154
161
  >
162
+ <!-- Trusted glyph markup only (DS-0176): title/desc are escaped, glyphs pass sanitizeIconMarkup. -->
163
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
155
164
  {@html inner}
156
165
  </svg>
157
166
 
@@ -23,6 +23,10 @@ interface Props {
23
23
  * Raw SVG inner markup escape hatch — rendered when `name` is not a known
24
24
  * (built-in or runtime-registered) glyph. Lets callers pass one-off icons
25
25
  * without registering them globally.
26
+ *
27
+ * **Must be trusted markup** (authored by you, never user input): it is injected as HTML.
28
+ * A light filter strips `<script>`, `<foreignObject>`, `on*` handlers and `javascript:`
29
+ * links, but it is not a security boundary.
26
30
  */
27
31
  paths?: string;
28
32
  /** Accessible name; rendered as a real <title> and wired via aria-labelledby. */
@@ -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
 
@@ -142,7 +147,7 @@
142
147
  }
143
148
  .ss-field .lbl .req {
144
149
  color: var(--ss-red);
145
- margin-left: 2px;
150
+ margin-inline-start: 2px;
146
151
  }
147
152
  .ss-field .control {
148
153
  display: flex;
@@ -180,6 +185,8 @@
180
185
  align-items: center;
181
186
  justify-content: center;
182
187
  flex: none;
188
+ min-inline-size: var(--ss-s-6);
189
+ min-block-size: var(--ss-s-6);
183
190
  font-family: var(--ss-font-body);
184
191
  font-size: var(--ss-input-font);
185
192
  line-height: 1;
@@ -198,9 +205,7 @@
198
205
  display: none;
199
206
  }
200
207
  .ss-field .clear:focus-visible {
201
- outline: none;
202
208
  color: var(--ss-fg);
203
- box-shadow: 0 0 0 2px var(--ss-primary-soft);
204
209
  }
205
210
  .ss-field .msg {
206
211
  font-family: var(--ss-font-mono);
@@ -48,10 +48,23 @@
48
48
  // A disabled link gets no external affordances (it cannot navigate).
49
49
  const isExternal = $derived(!disabled && (external ?? looksExternal))
50
50
 
51
- // External links open in a new tab and carry the security rel; callers can
52
- // still override target/rel explicitly via the forwarded attributes.
51
+ // External links default to a new tab; an explicit `target` always wins.
53
52
  const resolvedTarget = $derived(target ?? (isExternal ? '_blank' : undefined))
54
- const resolvedRel = $derived(rel ?? (isExternal ? 'noopener noreferrer' : undefined))
53
+ // The new-tab safeguards follow the RESOLVED target, not `isExternal`: any
54
+ // link that opens a new tab (auto-detected or an explicit target="_blank")
55
+ // gets `noopener noreferrer` and the "opens in a new tab" hint.
56
+ const opensNewTab = $derived(!disabled && resolvedTarget?.toLowerCase() === '_blank')
57
+ // Merge rather than replace: a caller's `rel` tokens are kept and the
58
+ // security tokens are appended when missing.
59
+ const resolvedRel = $derived.by(() => {
60
+ const tokens = (rel ?? '').split(/\s+/).filter(Boolean)
61
+ if (opensNewTab) {
62
+ for (const t of ['noopener', 'noreferrer']) {
63
+ if (!tokens.some((x) => x.toLowerCase() === t)) tokens.push(t)
64
+ }
65
+ }
66
+ return tokens.length ? tokens.join(' ') : undefined
67
+ })
55
68
 
56
69
  // Swallow activation while disabled; otherwise defer to a forwarded onclick.
57
70
  function handleClick(e: MouseEvent) {
@@ -80,10 +93,8 @@
80
93
  {...rest}
81
94
  >
82
95
  {#if children}<span class="label">{@render children()}</span>{/if}
83
- {#if isExternal}
84
- <Icon name="external" {size} class="ss-link-ext" />
85
- <span class="sr-only"> (opens in a new tab)</span>
86
- {/if}
96
+ {#if isExternal}<Icon name="external" {size} class="ss-link-ext" />{/if}
97
+ {#if opensNewTab}<span class="sr-only"> (opens in a new tab)</span>{/if}
87
98
  </a>
88
99
 
89
100
  <style>@charset "UTF-8";
@@ -99,6 +110,9 @@
99
110
  cursor: pointer;
100
111
  transition: color var(--ss-dur-fast) var(--ss-ease);
101
112
  }
113
+ .ss-link::before {
114
+ content: none;
115
+ }
102
116
  .ss-link:focus-visible {
103
117
  outline: 2px solid var(--ss-primary);
104
118
  outline-offset: 2px;
@@ -108,24 +122,21 @@
108
122
  opacity: 0.45;
109
123
  }
110
124
 
111
- /* ── inline: animated underline that reveals on hover/focus, with a glow ── */
125
+ /* ── inline: always-underlined, thickening with a glow on hover/focus ── */
112
126
  .ss-link.inline .label {
113
127
  position: relative;
114
128
  }
115
129
  .ss-link.inline .label::after {
116
130
  content: "";
117
131
  position: absolute;
118
- left: 0;
119
- right: 0;
132
+ inset-inline: 0;
120
133
  bottom: -1px;
121
134
  height: 1px;
122
135
  background: var(--ss-primary);
123
- transform: scaleX(0);
124
- transform-origin: left center;
125
- transition: transform var(--ss-dur-slow) var(--ss-ease), height var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-slow) var(--ss-ease);
136
+ transform: scaleX(1);
137
+ transition: height var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-slow) var(--ss-ease);
126
138
  }
127
139
  .ss-link.inline:hover .label::after, .ss-link.inline:focus-visible .label::after {
128
- transform: scaleX(1);
129
140
  height: 2px;
130
141
  box-shadow: var(--ss-shadow-glow);
131
142
  }
@@ -12,14 +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'
22
- import EmptyState from './EmptyState.svelte'
20
+ import {
21
+ LOG_LEVELS,
22
+ filterLogLines,
23
+ logCopyText,
24
+ logEmptyMessage,
25
+ logFollowsTail,
26
+ toggleLogLevel,
27
+ } from '../core/log-stream.js'
23
28
 
24
29
  interface Props {
25
30
  /** Controlled lines. When provided, the component renders exactly these (capped to `maxLines`). */
@@ -103,36 +108,21 @@
103
108
  const allLines = $derived((controlled ? (lines as LogLine[]) : demoLines).slice(-maxLines))
104
109
 
105
110
  // --- toolbar state ---
106
- let activeLevels = $state<Set<LogLevel>>(new Set(LEVELS))
111
+ let activeLevels = $state<Set<LogLevel>>(new Set(LOG_LEVELS))
107
112
  let query = $state('')
108
113
  let wrapOn = $state(untrack(() => wrap))
109
114
  $effect(() => {
110
115
  wrapOn = wrap
111
116
  })
112
117
 
113
- const visibleLines = $derived(
114
- allLines.filter((l) => {
115
- if (!activeLevels.has(l.lvl)) return false
116
- if (query.trim()) {
117
- const q = query.toLowerCase()
118
- const hay = `${l.t ?? ''} ${l.lvl} ${l.svc ?? ''} ${l.msg}`.toLowerCase()
119
- if (!hay.includes(q)) return false
120
- }
121
- return true
122
- }),
123
- )
118
+ const visibleLines = $derived(filterLogLines(allLines, { levels: activeLevels, query }))
124
119
 
125
120
  function toggleLevel(lvl: LogLevel) {
126
- const next = new Set(activeLevels)
127
- if (next.has(lvl)) next.delete(lvl)
128
- else next.add(lvl)
129
- activeLevels = next
121
+ activeLevels = toggleLogLevel(activeLevels, lvl)
130
122
  }
131
123
 
132
124
  async function copyVisible() {
133
- const text = visibleLines
134
- .map((l) => `${l.t ?? ''} ${l.lvl.toUpperCase()} ${l.svc ?? ''} ${l.msg}`.trim())
135
- .join('\n')
125
+ const text = logCopyText(visibleLines)
136
126
  try {
137
127
  await navigator.clipboard?.writeText(text)
138
128
  } catch {
@@ -148,11 +138,10 @@
148
138
  // --- follow-tail ---
149
139
  let el: HTMLDivElement | undefined
150
140
  let following = $state(true)
151
- const NEAR = 24 // px from bottom considered "at bottom"
152
141
 
153
142
  function atBottom() {
154
143
  if (!el) return true
155
- return el.scrollHeight - el.scrollTop - el.clientHeight <= NEAR
144
+ return logFollowsTail(el)
156
145
  }
157
146
 
158
147
  function onScroll() {
@@ -197,7 +186,7 @@
197
186
  {:else}
198
187
  <div class="bar">
199
188
  <div class="filters" role="group" aria-label="Filter by level">
200
- {#each LEVELS as lvl (lvl)}
189
+ {#each LOG_LEVELS as lvl (lvl)}
201
190
  <button
202
191
  type="button"
203
192
  class="chip {lvl}"
@@ -225,12 +214,15 @@
225
214
  {/if}
226
215
 
227
216
  <div class="viewport">
217
+ <!-- Focusable so keyboard users (notably Safari, which doesn't focus scrollers) can scroll it. -->
218
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
228
219
  <div
229
220
  class="scroll"
230
221
  class:nowrap={!wrapOn}
231
222
  bind:this={el}
232
223
  onscroll={onScroll}
233
224
  role="log"
225
+ tabindex="0"
234
226
  aria-label={ariaLabel}
235
227
  aria-live={announce}
236
228
  aria-busy={loading}
@@ -245,13 +237,14 @@
245
237
  {#if empty}
246
238
  {@render empty()}
247
239
  {:else}
248
- <EmptyState
249
- title="No log lines"
250
- message={allLines.length
251
- ? 'No lines match the current filters.'
252
- : 'Waiting for output…'}
253
- {size}
254
- />
240
+ <!-- Plain text, not <EmptyState>: its role="status" nested inside the
241
+ role="log" live region would announce the message twice. -->
242
+ <div class="empty">
243
+ <p class="empty-title">No log lines</p>
244
+ <p class="empty-msg">
245
+ {logEmptyMessage(allLines.length)}
246
+ </p>
247
+ </div>
255
248
  {/if}
256
249
  {:else}
257
250
  {#each visibleLines as line, i (keyFor(line, i))}
@@ -330,7 +323,8 @@
330
323
  border-color: var(--ss-line-strong);
331
324
  }
332
325
  .chip[aria-pressed=false] {
333
- opacity: 0.45;
326
+ color: var(--ss-fg-muted);
327
+ border-style: dashed;
334
328
  }
335
329
  .chip.info[aria-pressed=true] {
336
330
  color: var(--ss-log-info);
@@ -412,6 +406,27 @@
412
406
  flex: none;
413
407
  }
414
408
 
409
+ .empty {
410
+ display: flex;
411
+ flex-direction: column;
412
+ align-items: center;
413
+ justify-content: center;
414
+ gap: var(--ss-gap-sm);
415
+ min-height: calc(var(--_min-h) - 2 * var(--ss-gap));
416
+ text-align: center;
417
+ }
418
+ .empty p {
419
+ margin: 0;
420
+ }
421
+ .empty .empty-title {
422
+ color: var(--ss-code-fg);
423
+ font-size: var(--ss-ui-md);
424
+ }
425
+ .empty .empty-msg {
426
+ color: var(--ss-fg-faint);
427
+ font-size: var(--ss-ui-sm);
428
+ }
429
+
415
430
  .status {
416
431
  display: flex;
417
432
  align-items: center;