dssoca 0.9.0 → 0.10.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.
@@ -0,0 +1,119 @@
1
+ <script module lang="ts">
2
+ // Deterministic palette for the initials tile background (DS-0099). A given
3
+ // `name` always maps to the same entry via a simple string hash, so the same
4
+ // person reads with a stable colour across the app.
5
+ const PALETTE = [
6
+ 'var(--ss-primary)',
7
+ 'var(--ss-blue)',
8
+ 'var(--ss-purple)',
9
+ 'var(--ss-cyan)',
10
+ 'var(--ss-yellow)',
11
+ 'var(--ss-lime)',
12
+ ]
13
+
14
+ /** Up to two leading initials, uppercased: "Ada Lovelace" → "AL", "Cher" → "C". */
15
+ export function avatarInitials(name: string): string {
16
+ return name
17
+ .trim()
18
+ .split(/\s+/)
19
+ .filter(Boolean)
20
+ .slice(0, 2)
21
+ .map((w) => w[0]!.toUpperCase())
22
+ .join('')
23
+ }
24
+
25
+ /** djb2-ish string hash → palette index. Stable for a given `name`. */
26
+ export function avatarColor(name: string): string {
27
+ let h = 0
28
+ for (let i = 0; i < name.length; i++) h = (h * 31 + name.charCodeAt(i)) | 0
29
+ return PALETTE[Math.abs(h) % PALETTE.length]
30
+ }
31
+ </script>
32
+
33
+ <script lang="ts">
34
+ // ─────────────────────────────────────────────────────────────────────────
35
+ // Avatar (DS-0099). A SQUARE tile (zero radius — house rule) showing either an
36
+ // image or deterministic initials. If `src` is set we render an <img>; on a
37
+ // load error we fall back to the initials tile. The root carries role="img" +
38
+ // aria-label={name} so the name is exposed once; the visual initials are
39
+ // aria-hidden to avoid a doubled accessible name.
40
+ // ─────────────────────────────────────────────────────────────────────────
41
+ import { resolveComponentSize, type Size } from '../config.js'
42
+
43
+ interface Props {
44
+ /** Person/entity name — drives the initials, the deterministic colour, and the accessible name. */
45
+ name: string
46
+ /** Optional image URL; when set, rendered as an <img> that falls back to initials on error. */
47
+ src?: string
48
+ /** Image alt text; defaults to `name`. */
49
+ alt?: string
50
+ /** Token size (sm|md|lg); inherits the global size when unset. Controls the tile box. */
51
+ size?: Size
52
+ }
53
+
54
+ let { name, src, alt, size }: Props = $props()
55
+
56
+ const initials = $derived(avatarInitials(name))
57
+ const bg = $derived(avatarColor(name))
58
+
59
+ // Show the image until/unless it errors, then fall back to the initials tile.
60
+ let failed = $state(false)
61
+ const showImage = $derived(!!src && !failed)
62
+
63
+ function onError() {
64
+ failed = true
65
+ }
66
+ </script>
67
+
68
+ <span
69
+ class="ss-avatar"
70
+ data-size-variant={resolveComponentSize('Avatar', size)}
71
+ role="img"
72
+ aria-label={name}
73
+ style:--ss-avatar-bg={showImage ? undefined : bg}
74
+ >
75
+ {#if showImage}
76
+ <img class="img" {src} alt={alt ?? name} onerror={onError} />
77
+ {:else}
78
+ <span class="initials" aria-hidden="true">{initials}</span>
79
+ {/if}
80
+ </span>
81
+
82
+ <style>.ss-avatar {
83
+ --ss-avatar-size: var(--ss-avatar-size-md, 36px);
84
+ }
85
+ .ss-avatar[data-size-variant=sm] {
86
+ --ss-avatar-size: var(--ss-avatar-size-sm, 28px);
87
+ }
88
+ .ss-avatar[data-size-variant=lg] {
89
+ --ss-avatar-size: var(--ss-avatar-size-lg, 48px);
90
+ }
91
+ .ss-avatar {
92
+ display: inline-flex;
93
+ align-items: center;
94
+ justify-content: center;
95
+ width: var(--ss-avatar-size);
96
+ height: var(--ss-avatar-size);
97
+ flex: 0 0 auto;
98
+ overflow: hidden;
99
+ border-radius: 0;
100
+ background: var(--ss-avatar-bg, var(--ss-bg-elev));
101
+ color: var(--ss-fg-on-primary, var(--ss-bg));
102
+ user-select: none;
103
+ vertical-align: middle;
104
+ }
105
+
106
+ .img {
107
+ display: block;
108
+ width: 100%;
109
+ height: 100%;
110
+ object-fit: cover;
111
+ }
112
+
113
+ .initials {
114
+ font-family: var(--ss-font-mono);
115
+ font-size: var(--ss-avatar-font, calc(var(--ss-avatar-size) * 0.4));
116
+ font-weight: 600;
117
+ line-height: 1;
118
+ letter-spacing: 0.02em;
119
+ }</style>
@@ -0,0 +1,18 @@
1
+ /** Up to two leading initials, uppercased: "Ada Lovelace" → "AL", "Cher" → "C". */
2
+ export declare function avatarInitials(name: string): string;
3
+ /** djb2-ish string hash → palette index. Stable for a given `name`. */
4
+ export declare function avatarColor(name: string): string;
5
+ import { type Size } from '../config.js';
6
+ interface Props {
7
+ /** Person/entity name — drives the initials, the deterministic colour, and the accessible name. */
8
+ name: string;
9
+ /** Optional image URL; when set, rendered as an <img> that falls back to initials on error. */
10
+ src?: string;
11
+ /** Image alt text; defaults to `name`. */
12
+ alt?: string;
13
+ /** Token size (sm|md|lg); inherits the global size when unset. Controls the tile box. */
14
+ size?: Size;
15
+ }
16
+ declare const Avatar: import("svelte").Component<Props, {}, "">;
17
+ type Avatar = ReturnType<typeof Avatar>;
18
+ export default Avatar;
@@ -0,0 +1,527 @@
1
+ <script module lang="ts">
2
+ export type ChartXValue = number | string | Date
3
+ export interface ChartPoint {
4
+ x: ChartXValue
5
+ y: number
6
+ }
7
+ export interface ChartSeries {
8
+ label: string
9
+ data: ChartPoint[]
10
+ color?: string
11
+ }
12
+ export type ChartVariant = 'line' | 'area' | 'bar'
13
+ </script>
14
+
15
+ <script lang="ts">
16
+ import { scaleLinear, scaleTime, scaleBand } from 'd3-scale'
17
+ import { line as shapeLine, area as shapeArea } from 'd3-shape'
18
+ import { extent, max } from 'd3-array'
19
+ import { resolveComponentSize, type Size } from '../config.js'
20
+
21
+ type XType = 'linear' | 'time' | 'band'
22
+
23
+ interface Props {
24
+ /** One or more data series; each is drawn in the cycling palette unless `color` is set. */
25
+ series: ChartSeries[]
26
+ /** Rendering style. `bar` groups bars per x-category across series. Default `line`. */
27
+ variant?: ChartVariant
28
+ /** X scale kind. Defaults to `band` for bars, else `time` for Date x-values, else `linear`. */
29
+ xType?: XType
30
+ /** Format an x value for axis ticks + tooltip. */
31
+ xFormat?: (x: ChartXValue) => string
32
+ /** Format a y value for axis ticks + tooltip. */
33
+ yFormat?: (y: number) => string
34
+ /** Intrinsic drawing height in px. Default 240. */
35
+ height?: number
36
+ /** Intrinsic drawing width in px. Default 480. */
37
+ width?: number
38
+ /** Stretch to the container width via the viewBox (width:100%). */
39
+ fluid?: boolean
40
+ /** Show the series legend (labels + colour swatches). Default true. */
41
+ legend?: boolean
42
+ /** Show a tooltip on hover/focus of a datum. Default true. */
43
+ tooltip?: boolean
44
+ /** SR summary + accessible name; auto-generated when absent. */
45
+ summary?: string
46
+ /** Token size (sm|md|lg); inherits the global size when unset. */
47
+ size?: Size
48
+ }
49
+
50
+ let {
51
+ series,
52
+ variant = 'line',
53
+ xType,
54
+ xFormat,
55
+ yFormat,
56
+ height = 240,
57
+ width = 480,
58
+ fluid = false,
59
+ legend = true,
60
+ tooltip = true,
61
+ summary,
62
+ size,
63
+ }: Props = $props()
64
+
65
+ const PALETTE = [
66
+ 'var(--ss-primary)',
67
+ 'var(--ss-blue)',
68
+ 'var(--ss-purple)',
69
+ 'var(--ss-cyan)',
70
+ 'var(--ss-yellow)',
71
+ 'var(--ss-lime)',
72
+ ]
73
+
74
+ const M = { top: 8, right: 12, bottom: 24, left: 40 }
75
+
76
+ const cleanSeries = $derived((series ?? []).filter((s) => s && Array.isArray(s.data)))
77
+ const allPoints = $derived(cleanSeries.flatMap((s) => s.data))
78
+ const isEmpty = $derived(allPoints.length === 0)
79
+
80
+ function colorFor(s: ChartSeries, i: number): string {
81
+ return s.color ?? PALETTE[i % PALETTE.length]
82
+ }
83
+
84
+ function toNum(x: ChartXValue): number {
85
+ if (x instanceof Date) return x.getTime()
86
+ return typeof x === 'number' ? x : Number(x)
87
+ }
88
+ function xKey(x: ChartXValue): string {
89
+ return x instanceof Date ? String(x.getTime()) : String(x)
90
+ }
91
+
92
+ // Resolve the x scale kind.
93
+ const xIsDate = $derived(allPoints.some((p) => p.x instanceof Date))
94
+ const resolvedXType = $derived<XType>(
95
+ xType ?? (variant === 'bar' ? 'band' : xIsDate ? 'time' : 'linear'),
96
+ )
97
+
98
+ const innerW = $derived(Math.max(0, width - M.left - M.right))
99
+ const innerH = $derived(Math.max(0, height - M.top - M.bottom))
100
+
101
+ const fmtX = $derived(
102
+ xFormat ?? ((x: ChartXValue) => (x instanceof Date ? x.toLocaleDateString() : String(x))),
103
+ )
104
+ const fmtY = $derived(yFormat ?? ((y: number) => String(y)))
105
+
106
+ // Distinct x categories (band scale + grouped bars), in first-seen order.
107
+ const categories = $derived.by(() => {
108
+ const seen = new Map<string, ChartXValue>()
109
+ for (const p of allPoints) {
110
+ const k = xKey(p.x)
111
+ if (!seen.has(k)) seen.set(k, p.x)
112
+ }
113
+ return [...seen.values()]
114
+ })
115
+ const categoryKeys = $derived(categories.map(xKey))
116
+
117
+ // ── d3 scales ─────────────────────────────────────────────────────────────
118
+ // Linear y scale [0..max] → [innerH..0], rounded to nice tick bounds.
119
+ const yScaleObj = $derived(
120
+ scaleLinear()
121
+ .domain([0, max(allPoints, (p) => p.y) ?? 1])
122
+ .nice()
123
+ .range([innerH, 0]),
124
+ )
125
+ function yScale(y: number): number {
126
+ return yScaleObj(y)
127
+ }
128
+
129
+ // Band scale across the distinct categories (drives bars + categorical x).
130
+ const xBand = $derived(scaleBand<string>().domain(categoryKeys).range([0, innerW]).padding(0.2))
131
+
132
+ // Continuous x scales for line/area (time for Date values, else linear).
133
+ const xLinear = $derived(
134
+ scaleLinear()
135
+ .domain((extent(allPoints, (p) => toNum(p.x)) as [number, number]) ?? [0, 1])
136
+ .range([0, innerW]),
137
+ )
138
+ const xTime = $derived(
139
+ scaleTime()
140
+ .domain(
141
+ (extent(allPoints, (p) => (p.x instanceof Date ? p.x : new Date(toNum(p.x)))) as [
142
+ Date,
143
+ Date,
144
+ ]) ?? [new Date(0), new Date(1)],
145
+ )
146
+ .range([0, innerW]),
147
+ )
148
+
149
+ function xPos(x: ChartXValue): number {
150
+ if (resolvedXType === 'band') return (xBand(xKey(x)) ?? 0) + xBand.bandwidth() / 2
151
+ if (resolvedXType === 'time') return xTime(x instanceof Date ? x : new Date(toNum(x)))
152
+ return xLinear(toNum(x))
153
+ }
154
+
155
+ // Axis ticks via the d3 scales.
156
+ const yTicks = $derived(yScaleObj.ticks(5))
157
+ const xTicks = $derived.by<{ x: number; label: string }[]>(() => {
158
+ if (resolvedXType === 'band') {
159
+ return categories.map((c) => ({ x: xPos(c), label: fmtX(c) }))
160
+ }
161
+ if (resolvedXType === 'time') {
162
+ return xTime.ticks(5).map((v) => ({ x: xTime(v), label: fmtX(v) }))
163
+ }
164
+ return xLinear.ticks(5).map((v) => ({ x: xLinear(v), label: fmtX(v) }))
165
+ })
166
+
167
+ // ── path generators (d3-shape) ─────────────────────────────────────────────
168
+ const lineGen = $derived(
169
+ shapeLine<ChartPoint>()
170
+ .x((p) => xPos(p.x))
171
+ .y((p) => yScale(p.y)),
172
+ )
173
+ const areaGen = $derived(
174
+ shapeArea<ChartPoint>()
175
+ .x((p) => xPos(p.x))
176
+ .y0(innerH)
177
+ .y1((p) => yScale(p.y)),
178
+ )
179
+
180
+ const linePaths = $derived.by(() => {
181
+ if (variant !== 'line' && variant !== 'area') return []
182
+ return cleanSeries.map((s, i) => ({
183
+ d: lineGen(s.data) ?? '',
184
+ color: colorFor(s, i),
185
+ label: s.label,
186
+ }))
187
+ })
188
+ const areaPaths = $derived.by(() => {
189
+ if (variant !== 'area') return []
190
+ return cleanSeries.map((s, i) => ({
191
+ d: areaGen(s.data) ?? '',
192
+ color: colorFor(s, i),
193
+ label: s.label,
194
+ }))
195
+ })
196
+
197
+ // Grouped bars: each x-category holds one bar per series, packed across the band.
198
+ const barGroups = $derived.by(() => {
199
+ if (variant !== 'bar') return []
200
+ const inner = scaleBand<number>()
201
+ .domain(cleanSeries.map((_, i) => i))
202
+ .range([0, xBand.bandwidth()])
203
+ .padding(0.1)
204
+ return categories.map((cat) => {
205
+ const left = xBand(xKey(cat)) ?? 0
206
+ const bars = cleanSeries
207
+ .map((s, i) => {
208
+ const pt = s.data.find((p) => xKey(p.x) === xKey(cat))
209
+ if (!pt) return null
210
+ const y = yScale(pt.y)
211
+ return {
212
+ x: left + (inner(i) ?? 0),
213
+ y,
214
+ w: inner.bandwidth(),
215
+ h: Math.max(0, innerH - y),
216
+ color: colorFor(s, i),
217
+ label: s.label,
218
+ value: pt.y,
219
+ cat,
220
+ }
221
+ })
222
+ .filter((b): b is NonNullable<typeof b> => b !== null)
223
+ return { bars }
224
+ })
225
+ })
226
+
227
+ // Focusable point markers (line/area datums).
228
+ const pointMarkers = $derived.by(() => {
229
+ if (variant !== 'line' && variant !== 'area') return []
230
+ return cleanSeries.flatMap((s, i) =>
231
+ s.data.map((p) => ({
232
+ cx: xPos(p.x),
233
+ cy: yScale(p.y),
234
+ color: colorFor(s, i),
235
+ label: s.label,
236
+ x: p.x,
237
+ value: p.y,
238
+ })),
239
+ )
240
+ })
241
+
242
+ // Auto SR summary.
243
+ const autoSummary = $derived.by(() => {
244
+ if (isEmpty) return 'No data'
245
+ const kind = variant === 'bar' ? 'Bar chart' : variant === 'area' ? 'Area chart' : 'Line chart'
246
+ const names = cleanSeries.map((s) => s.label).join(', ')
247
+ return `${kind} with ${cleanSeries.length} series (${names}); ${allPoints.length} data points.`
248
+ })
249
+ const srText = $derived(summary ?? autoSummary)
250
+
251
+ const resolvedSize = $derived(resolveComponentSize('Chart', size))
252
+
253
+ // Tooltip state.
254
+ let active = $state<{
255
+ label: string
256
+ x: ChartXValue
257
+ y: number
258
+ cx: number
259
+ cy: number
260
+ } | null>(null)
261
+ function show(label: string, x: ChartXValue, y: number, cx: number, cy: number) {
262
+ if (tooltip) active = { label, x, y, cx, cy }
263
+ }
264
+ function hide() {
265
+ active = null
266
+ }
267
+ function datumLabel(label: string, x: ChartXValue, y: number): string {
268
+ return `${label}: ${fmtX(x)}, ${fmtY(y)}`
269
+ }
270
+ </script>
271
+
272
+ <div
273
+ class="ss-chart"
274
+ class:fluid
275
+ data-variant={variant}
276
+ data-size-variant={resolvedSize}
277
+ role="group"
278
+ aria-label={srText}
279
+ >
280
+ {#if isEmpty}
281
+ <span class="empty" aria-hidden="true">—</span>
282
+ <span class="sr-only">No data</span>
283
+ {:else}
284
+ <div class="plot">
285
+ <svg
286
+ class="canvas"
287
+ viewBox="0 0 {width} {height}"
288
+ width={fluid ? undefined : width}
289
+ height={fluid ? undefined : height}
290
+ preserveAspectRatio="xMidYMid meet"
291
+ role="presentation"
292
+ >
293
+ <g transform="translate({M.left},{M.top})">
294
+ <!-- gridlines + y axis -->
295
+ {#each yTicks as t}
296
+ <line class="grid" x1="0" x2={innerW} y1={yScale(t)} y2={yScale(t)} />
297
+ <text class="tick y" x="-6" y={yScale(t)} dy="0.32em" text-anchor="end">{fmtY(t)}</text>
298
+ {/each}
299
+ <line class="axis" x1="0" x2="0" y1="0" y2={innerH} />
300
+
301
+ <!-- x axis -->
302
+ <line class="axis" x1="0" x2={innerW} y1={innerH} y2={innerH} />
303
+ {#each xTicks as t}
304
+ <text class="tick x" x={t.x} y={innerH + 16} text-anchor="middle">{t.label}</text>
305
+ {/each}
306
+
307
+ <!-- series -->
308
+ {#if variant === 'area'}
309
+ {#each areaPaths as p}
310
+ <path class="area" d={p.d} style="fill:{p.color}" />
311
+ {/each}
312
+ {/if}
313
+
314
+ {#if variant === 'line' || variant === 'area'}
315
+ {#each linePaths as p}
316
+ <path class="line" d={p.d} style="stroke:{p.color}" />
317
+ {/each}
318
+ {#each pointMarkers as m}
319
+ <circle
320
+ class="point"
321
+ cx={m.cx}
322
+ cy={m.cy}
323
+ r="4"
324
+ style="fill:{m.color}"
325
+ tabindex="0"
326
+ role="button"
327
+ aria-label={datumLabel(m.label, m.x, m.value)}
328
+ onfocus={() => show(m.label, m.x, m.value, m.cx, m.cy)}
329
+ onblur={hide}
330
+ onmouseenter={() => show(m.label, m.x, m.value, m.cx, m.cy)}
331
+ onmouseleave={hide}
332
+ />
333
+ {/each}
334
+ {/if}
335
+
336
+ {#if variant === 'bar'}
337
+ {#each barGroups as g}
338
+ {#each g.bars as b}
339
+ <rect
340
+ class="bar"
341
+ x={b.x}
342
+ y={b.y}
343
+ width={b.w}
344
+ height={b.h}
345
+ style="fill:{b.color}"
346
+ tabindex="0"
347
+ role="button"
348
+ aria-label={datumLabel(b.label, b.cat, b.value)}
349
+ onfocus={() => show(b.label, b.cat, b.value, b.x + b.w / 2, b.y)}
350
+ onblur={hide}
351
+ onmouseenter={() => show(b.label, b.cat, b.value, b.x + b.w / 2, b.y)}
352
+ onmouseleave={hide}
353
+ />
354
+ {/each}
355
+ {/each}
356
+ {/if}
357
+ </g>
358
+ </svg>
359
+
360
+ {#if tooltip && active}
361
+ <div
362
+ class="tooltip"
363
+ role="status"
364
+ style="left:{((active.cx + M.left) / width) * 100}%;top:{((active.cy + M.top) / height) *
365
+ 100}%"
366
+ >
367
+ <span class="t-label">{active.label}</span>
368
+ <span class="t-val">{fmtX(active.x)} · {fmtY(active.y)}</span>
369
+ </div>
370
+ {/if}
371
+ </div>
372
+
373
+ {#if legend}
374
+ <ul class="legend">
375
+ {#each cleanSeries as s, i}
376
+ <li class="legend-item">
377
+ <span class="swatch" style="background:{colorFor(s, i)}" aria-hidden="true"></span>
378
+ <span class="legend-label">{s.label}</span>
379
+ </li>
380
+ {/each}
381
+ </ul>
382
+ {/if}
383
+ {/if}
384
+ </div>
385
+
386
+ <style>.ss-chart {
387
+ display: inline-flex;
388
+ flex-direction: column;
389
+ gap: var(--ss-gap-sm);
390
+ font-family: var(--ss-font-body);
391
+ color: var(--ss-fg);
392
+ max-width: 100%;
393
+ }
394
+ .ss-chart.fluid {
395
+ display: flex;
396
+ width: 100%;
397
+ }
398
+ .ss-chart .plot {
399
+ position: relative;
400
+ width: 100%;
401
+ }
402
+ .ss-chart .canvas {
403
+ display: block;
404
+ max-width: 100%;
405
+ height: auto;
406
+ overflow: visible;
407
+ }
408
+ .ss-chart.fluid .canvas {
409
+ width: 100%;
410
+ }
411
+ .ss-chart .empty {
412
+ align-self: center;
413
+ margin: auto;
414
+ padding: var(--ss-gap-sm);
415
+ color: var(--ss-fg-muted);
416
+ font-family: var(--ss-font-mono);
417
+ line-height: 1;
418
+ min-height: var(--ss-chart-h, 240px);
419
+ display: flex;
420
+ align-items: center;
421
+ }
422
+ .ss-chart .sr-only {
423
+ position: absolute;
424
+ width: 1px;
425
+ height: 1px;
426
+ padding: 0;
427
+ margin: -1px;
428
+ overflow: hidden;
429
+ clip: rect(0, 0, 0, 0);
430
+ white-space: nowrap;
431
+ border: 0;
432
+ }
433
+ .ss-chart .grid {
434
+ stroke: var(--ss-line);
435
+ stroke-width: 1;
436
+ opacity: 0.5;
437
+ shape-rendering: crispEdges;
438
+ }
439
+ .ss-chart .axis {
440
+ stroke: var(--ss-line);
441
+ stroke-width: 1;
442
+ shape-rendering: crispEdges;
443
+ }
444
+ .ss-chart .tick {
445
+ font-family: var(--ss-font-mono);
446
+ font-size: var(--ss-ui-xs);
447
+ fill: var(--ss-fg-muted);
448
+ }
449
+ .ss-chart .line {
450
+ fill: none;
451
+ stroke-width: 2;
452
+ stroke-linejoin: round;
453
+ stroke-linecap: round;
454
+ }
455
+ .ss-chart .area {
456
+ opacity: 0.18;
457
+ stroke: none;
458
+ }
459
+ .ss-chart .point {
460
+ cursor: pointer;
461
+ transition: r var(--ss-dur-fast) var(--ss-ease);
462
+ }
463
+ .ss-chart .point:hover, .ss-chart .point:focus-visible {
464
+ outline: none;
465
+ r: 6;
466
+ }
467
+ .ss-chart .point:focus-visible {
468
+ stroke: var(--ss-fg);
469
+ stroke-width: 2;
470
+ }
471
+ .ss-chart .bar {
472
+ cursor: pointer;
473
+ transition: opacity var(--ss-dur-fast) var(--ss-ease);
474
+ }
475
+ .ss-chart .bar:hover {
476
+ opacity: 0.85;
477
+ }
478
+ .ss-chart .bar:focus-visible {
479
+ outline: none;
480
+ stroke: var(--ss-fg);
481
+ stroke-width: 2;
482
+ }
483
+ .ss-chart .tooltip {
484
+ position: absolute;
485
+ transform: translate(-50%, calc(-100% - 8px));
486
+ pointer-events: none;
487
+ background: var(--ss-bg-elev);
488
+ border: 1px solid var(--ss-line-strong);
489
+ padding: var(--ss-gap-sm);
490
+ font-size: var(--ss-ui-xs);
491
+ line-height: 1.3;
492
+ white-space: nowrap;
493
+ display: flex;
494
+ flex-direction: column;
495
+ gap: 2px;
496
+ z-index: 2;
497
+ }
498
+ .ss-chart .tooltip .t-label {
499
+ font-family: var(--ss-font-mono);
500
+ color: var(--ss-fg);
501
+ }
502
+ .ss-chart .tooltip .t-val {
503
+ font-family: var(--ss-font-mono);
504
+ color: var(--ss-fg-muted);
505
+ }
506
+ .ss-chart .legend {
507
+ display: flex;
508
+ flex-wrap: wrap;
509
+ gap: var(--ss-gap-sm);
510
+ list-style: none;
511
+ margin: 0;
512
+ padding: 0;
513
+ }
514
+ .ss-chart .legend-item {
515
+ display: inline-flex;
516
+ align-items: center;
517
+ gap: 6px;
518
+ font-size: var(--ss-ui-xs);
519
+ font-family: var(--ss-font-mono);
520
+ color: var(--ss-fg-muted);
521
+ }
522
+ .ss-chart .swatch {
523
+ width: 10px;
524
+ height: 10px;
525
+ flex: none;
526
+ display: inline-block;
527
+ }</style>
@@ -0,0 +1,42 @@
1
+ export type ChartXValue = number | string | Date;
2
+ export interface ChartPoint {
3
+ x: ChartXValue;
4
+ y: number;
5
+ }
6
+ export interface ChartSeries {
7
+ label: string;
8
+ data: ChartPoint[];
9
+ color?: string;
10
+ }
11
+ export type ChartVariant = 'line' | 'area' | 'bar';
12
+ import { type Size } from '../config.js';
13
+ type XType = 'linear' | 'time' | 'band';
14
+ interface Props {
15
+ /** One or more data series; each is drawn in the cycling palette unless `color` is set. */
16
+ series: ChartSeries[];
17
+ /** Rendering style. `bar` groups bars per x-category across series. Default `line`. */
18
+ variant?: ChartVariant;
19
+ /** X scale kind. Defaults to `band` for bars, else `time` for Date x-values, else `linear`. */
20
+ xType?: XType;
21
+ /** Format an x value for axis ticks + tooltip. */
22
+ xFormat?: (x: ChartXValue) => string;
23
+ /** Format a y value for axis ticks + tooltip. */
24
+ yFormat?: (y: number) => string;
25
+ /** Intrinsic drawing height in px. Default 240. */
26
+ height?: number;
27
+ /** Intrinsic drawing width in px. Default 480. */
28
+ width?: number;
29
+ /** Stretch to the container width via the viewBox (width:100%). */
30
+ fluid?: boolean;
31
+ /** Show the series legend (labels + colour swatches). Default true. */
32
+ legend?: boolean;
33
+ /** Show a tooltip on hover/focus of a datum. Default true. */
34
+ tooltip?: boolean;
35
+ /** SR summary + accessible name; auto-generated when absent. */
36
+ summary?: string;
37
+ /** Token size (sm|md|lg); inherits the global size when unset. */
38
+ size?: Size;
39
+ }
40
+ declare const Chart: import("svelte").Component<Props, {}, "">;
41
+ type Chart = ReturnType<typeof Chart>;
42
+ export default Chart;