dssoca 0.5.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -13
- package/dist/components/Accordion.svelte +297 -0
- package/dist/components/Accordion.svelte.d.ts +51 -0
- package/dist/components/Badge.svelte +113 -18
- package/dist/components/Badge.svelte.d.ts +28 -2
- package/dist/components/BottomNav.svelte +254 -0
- package/dist/components/BottomNav.svelte.d.ts +32 -0
- package/dist/components/Button.svelte +147 -10
- package/dist/components/Button.svelte.d.ts +21 -4
- package/dist/components/Card.svelte +173 -8
- package/dist/components/Card.svelte.d.ts +16 -1
- package/dist/components/Container.svelte +55 -0
- package/dist/components/Container.svelte.d.ts +16 -0
- package/dist/components/EmptyState.svelte +91 -9
- package/dist/components/EmptyState.svelte.d.ts +20 -3
- package/dist/components/Heading.svelte +83 -0
- package/dist/components/Heading.svelte.d.ts +17 -0
- package/dist/components/Icon.svelte +199 -24
- package/dist/components/Icon.svelte.d.ts +70 -2
- package/dist/components/Image.svelte +428 -0
- package/dist/components/Image.svelte.d.ts +49 -0
- package/dist/components/Input.svelte +173 -39
- package/dist/components/Input.svelte.d.ts +22 -0
- package/dist/components/Link.svelte +183 -0
- package/dist/components/Link.svelte.d.ts +29 -0
- package/dist/components/LogStream.svelte +403 -47
- package/dist/components/LogStream.svelte.d.ts +35 -7
- package/dist/components/Menu.svelte +408 -0
- package/dist/components/Menu.svelte.d.ts +66 -0
- package/dist/components/MetricTile.svelte +124 -12
- package/dist/components/MetricTile.svelte.d.ts +20 -0
- package/dist/components/SegmentedControl.svelte +220 -0
- package/dist/components/SegmentedControl.svelte.d.ts +37 -0
- package/dist/components/ServiceCard.svelte +226 -30
- package/dist/components/ServiceCard.svelte.d.ts +13 -1
- package/dist/components/Sidebar.svelte +377 -40
- package/dist/components/Sidebar.svelte.d.ts +18 -7
- package/dist/components/Sparkline.svelte +198 -13
- package/dist/components/Sparkline.svelte.d.ts +20 -1
- package/dist/components/Spinner.svelte +124 -0
- package/dist/components/Spinner.svelte.d.ts +74 -0
- package/dist/components/Textarea.svelte +214 -0
- package/dist/components/Textarea.svelte.d.ts +38 -0
- package/dist/components/Toaster.svelte +209 -12
- package/dist/components/Toaster.svelte.d.ts +3 -0
- package/dist/components/Topbar.svelte +293 -42
- package/dist/components/Topbar.svelte.d.ts +48 -1
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +10 -0
- package/dist/index.d.ts +16 -3
- package/dist/index.js +18 -2
- package/dist/theme.css +406 -24
- package/dist/toast.svelte.d.ts +49 -5
- package/dist/toast.svelte.js +165 -9
- package/dist/tokens.css +597 -0
- package/package.json +25 -4
|
@@ -1,39 +1,224 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
3
3
|
|
|
4
|
+
type Trend = 'auto' | 'up' | 'down' | 'flat' | 'none'
|
|
5
|
+
type Variant = 'bars' | 'line' | 'area'
|
|
6
|
+
|
|
4
7
|
interface Props {
|
|
5
8
|
data: number[]
|
|
9
|
+
/** Bar/line fill. Ignored when `trend` resolves to a non-`none` direction. */
|
|
6
10
|
color?: string
|
|
7
11
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
8
12
|
size?: Size
|
|
9
|
-
/** Accessible label;
|
|
13
|
+
/** Accessible label; overrides the auto-generated summary as the accessible name. */
|
|
10
14
|
label?: string
|
|
15
|
+
/** Lower bound of the scale. Defaults to the data min — set to fix the scale across rows. */
|
|
16
|
+
min?: number
|
|
17
|
+
/** Upper bound of the scale. Defaults to the data max — set to fix the scale across rows. */
|
|
18
|
+
max?: number
|
|
19
|
+
/** Colour by direction. `auto` derives first-vs-last → success/danger/muted. Default `none`. */
|
|
20
|
+
trend?: Trend
|
|
21
|
+
/** Rendering style. Default `bars`. */
|
|
22
|
+
variant?: Variant
|
|
23
|
+
/** Flex the chart to fill its container width (table-cell friendly). */
|
|
24
|
+
fluid?: boolean
|
|
25
|
+
/** Explicit CSS width (e.g. `'120px'`, `'100%'`). Overrides the intrinsic width. */
|
|
26
|
+
width?: string
|
|
27
|
+
/** Format a value for the screen-reader summary (e.g. `v => v + '%'`). */
|
|
28
|
+
valueFormat?: (v: number) => string
|
|
29
|
+
/** Replace the auto-generated screen-reader summary entirely. */
|
|
30
|
+
summary?: string
|
|
31
|
+
}
|
|
32
|
+
let {
|
|
33
|
+
data,
|
|
34
|
+
color = 'var(--ss-primary)',
|
|
35
|
+
size,
|
|
36
|
+
label,
|
|
37
|
+
min,
|
|
38
|
+
max,
|
|
39
|
+
trend = 'none',
|
|
40
|
+
variant = 'bars',
|
|
41
|
+
fluid = false,
|
|
42
|
+
width,
|
|
43
|
+
valueFormat,
|
|
44
|
+
summary,
|
|
45
|
+
}: Props = $props()
|
|
46
|
+
|
|
47
|
+
const fmt = $derived(valueFormat ?? ((v: number) => String(v)))
|
|
48
|
+
|
|
49
|
+
// Scale bounds: explicit props win, else derive from the data's real range.
|
|
50
|
+
const lo = $derived(min ?? (data.length ? Math.min(...data) : 0))
|
|
51
|
+
const hi = $derived(max ?? (data.length ? Math.max(...data) : 1))
|
|
52
|
+
const range = $derived(hi - lo)
|
|
53
|
+
|
|
54
|
+
/** Normalise a value into 0..1 across [lo,hi]; flat range pins to the mid-line. */
|
|
55
|
+
function norm(v: number): number {
|
|
56
|
+
if (range <= 0) return 0.5
|
|
57
|
+
return Math.min(1, Math.max(0, (v - lo) / range))
|
|
11
58
|
}
|
|
12
|
-
let { data, color = 'var(--ss-primary)', size, label }: Props = $props()
|
|
13
59
|
|
|
14
|
-
|
|
60
|
+
// Resolved trend direction (auto derives from first-vs-last).
|
|
61
|
+
const direction = $derived.by<'up' | 'down' | 'flat' | 'none'>(() => {
|
|
62
|
+
if (trend === 'none') return 'none'
|
|
63
|
+
if (trend !== 'auto') return trend
|
|
64
|
+
if (data.length < 2) return 'flat'
|
|
65
|
+
const d = data[data.length - 1] - data[0]
|
|
66
|
+
if (d > 0) return 'up'
|
|
67
|
+
if (d < 0) return 'down'
|
|
68
|
+
return 'flat'
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Colour: a resolved direction overrides the `color` prop.
|
|
72
|
+
const fill = $derived.by(() => {
|
|
73
|
+
switch (direction) {
|
|
74
|
+
case 'up':
|
|
75
|
+
return 'var(--ss-success)'
|
|
76
|
+
case 'down':
|
|
77
|
+
return 'var(--ss-danger)'
|
|
78
|
+
case 'flat':
|
|
79
|
+
return 'var(--ss-fg-muted)'
|
|
80
|
+
default:
|
|
81
|
+
return color
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// Screen-reader summary: first→last, direction, min/max, n points.
|
|
86
|
+
const autoSummary = $derived.by(() => {
|
|
87
|
+
if (!data.length) return 'No data'
|
|
88
|
+
if (data.length === 1) return `Single value ${fmt(data[0])}`
|
|
89
|
+
const first = data[0]
|
|
90
|
+
const last = data[data.length - 1]
|
|
91
|
+
const dmin = Math.min(...data)
|
|
92
|
+
const dmax = Math.max(...data)
|
|
93
|
+
const arrow = last > first ? 'rising' : last < first ? 'falling' : 'flat'
|
|
94
|
+
return `Trend ${arrow}: ${fmt(first)} to ${fmt(last)} over ${data.length} points, range ${fmt(dmin)} to ${fmt(dmax)}.`
|
|
95
|
+
})
|
|
96
|
+
const srText = $derived(summary ?? autoSummary)
|
|
97
|
+
const accName = $derived(label ?? srText)
|
|
98
|
+
|
|
99
|
+
// SVG geometry (line/area) on a fixed viewBox; width:100% + viewBox makes it fluid.
|
|
100
|
+
const VB_W = 100
|
|
101
|
+
const VB_H = 100
|
|
102
|
+
const points = $derived.by(() => {
|
|
103
|
+
if (data.length === 0) return []
|
|
104
|
+
if (data.length === 1) {
|
|
105
|
+
const y = VB_H - norm(data[0]) * VB_H
|
|
106
|
+
return [{ x: VB_W / 2, y }]
|
|
107
|
+
}
|
|
108
|
+
return data.map((v, i) => ({
|
|
109
|
+
x: (i / (data.length - 1)) * VB_W,
|
|
110
|
+
y: VB_H - norm(v) * VB_H,
|
|
111
|
+
}))
|
|
112
|
+
})
|
|
113
|
+
const polyline = $derived(points.map((p) => `${p.x},${p.y}`).join(' '))
|
|
114
|
+
const areaPath = $derived(
|
|
115
|
+
points.length
|
|
116
|
+
? `M${points[0].x},${VB_H} L` +
|
|
117
|
+
points.map((p) => `${p.x},${p.y}`).join(' ') +
|
|
118
|
+
` L${points[points.length - 1].x},${VB_H} Z`
|
|
119
|
+
: '',
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const isEmpty = $derived(data.length === 0)
|
|
123
|
+
const isSingle = $derived(data.length === 1)
|
|
124
|
+
|
|
125
|
+
const rootStyle = $derived(
|
|
126
|
+
[width ? `width:${width}` : '', fluid && !width ? 'width:100%' : ''].filter(Boolean).join(';'),
|
|
127
|
+
)
|
|
15
128
|
</script>
|
|
16
129
|
|
|
17
130
|
<div
|
|
18
131
|
class="ss-spark"
|
|
132
|
+
class:fluid
|
|
133
|
+
data-variant={variant}
|
|
19
134
|
data-size-variant={resolveComponentSize('Sparkline', size)}
|
|
20
|
-
role=
|
|
21
|
-
aria-label={
|
|
22
|
-
|
|
135
|
+
role="img"
|
|
136
|
+
aria-label={accName}
|
|
137
|
+
style={rootStyle || undefined}
|
|
23
138
|
>
|
|
24
|
-
{#
|
|
25
|
-
<
|
|
26
|
-
{
|
|
139
|
+
{#if isEmpty}
|
|
140
|
+
<span class="empty" aria-hidden="true">—</span>
|
|
141
|
+
{:else if variant === 'bars'}
|
|
142
|
+
{#if isSingle}
|
|
143
|
+
<i
|
|
144
|
+
class="single"
|
|
145
|
+
aria-hidden="true"
|
|
146
|
+
style="height:{Math.max(8, norm(data[0]) * 100)}%;background:{fill}"
|
|
147
|
+
></i>
|
|
148
|
+
{:else}
|
|
149
|
+
{#each data as v}
|
|
150
|
+
<i aria-hidden="true" style="height:{Math.max(8, norm(v) * 100)}%;background:{fill}"></i>
|
|
151
|
+
{/each}
|
|
152
|
+
{/if}
|
|
153
|
+
{:else}
|
|
154
|
+
<svg
|
|
155
|
+
class="chart"
|
|
156
|
+
viewBox="0 0 {VB_W} {VB_H}"
|
|
157
|
+
preserveAspectRatio="none"
|
|
158
|
+
aria-hidden="true"
|
|
159
|
+
focusable="false"
|
|
160
|
+
>
|
|
161
|
+
{#if variant === 'area' && areaPath}
|
|
162
|
+
<path class="area" d={areaPath} style="fill:{fill}" />
|
|
163
|
+
{/if}
|
|
164
|
+
{#if isSingle}
|
|
165
|
+
<circle class="marker" cx={points[0].x} cy={points[0].y} r="3" style="fill:{fill}" />
|
|
166
|
+
{:else}
|
|
167
|
+
<polyline class="line" points={polyline} style="stroke:{fill}" />
|
|
168
|
+
{/if}
|
|
169
|
+
</svg>
|
|
170
|
+
{/if}
|
|
27
171
|
</div>
|
|
28
172
|
|
|
29
173
|
<style>.ss-spark {
|
|
30
|
-
display: flex;
|
|
174
|
+
display: inline-flex;
|
|
31
175
|
align-items: flex-end;
|
|
32
|
-
gap: 1px;
|
|
33
|
-
height: 18px;
|
|
176
|
+
gap: var(--ss-spark-gap, 1px);
|
|
177
|
+
height: var(--ss-spark-h, var(--ss-icon, 18px));
|
|
178
|
+
position: relative;
|
|
179
|
+
}
|
|
180
|
+
.ss-spark.fluid {
|
|
181
|
+
width: 100%;
|
|
34
182
|
}
|
|
35
183
|
.ss-spark i {
|
|
36
|
-
width: 3px;
|
|
184
|
+
width: var(--ss-spark-bar-w, 3px);
|
|
37
185
|
background: var(--ss-primary);
|
|
38
186
|
opacity: 0.85;
|
|
187
|
+
border-radius: 0;
|
|
188
|
+
}
|
|
189
|
+
.ss-spark.fluid i {
|
|
190
|
+
flex: 1 1 0;
|
|
191
|
+
width: auto;
|
|
192
|
+
min-width: 1px;
|
|
193
|
+
}
|
|
194
|
+
.ss-spark .single {
|
|
195
|
+
margin: 0 auto;
|
|
196
|
+
}
|
|
197
|
+
.ss-spark .empty {
|
|
198
|
+
align-self: center;
|
|
199
|
+
margin: auto;
|
|
200
|
+
color: var(--ss-fg-muted);
|
|
201
|
+
font-family: var(--ss-font-mono);
|
|
202
|
+
line-height: 1;
|
|
203
|
+
}
|
|
204
|
+
.ss-spark .chart {
|
|
205
|
+
display: block;
|
|
206
|
+
width: 100%;
|
|
207
|
+
height: 100%;
|
|
208
|
+
overflow: visible;
|
|
209
|
+
}
|
|
210
|
+
.ss-spark .line {
|
|
211
|
+
fill: none;
|
|
212
|
+
stroke: var(--ss-primary);
|
|
213
|
+
stroke-width: 1.5;
|
|
214
|
+
vector-effect: non-scaling-stroke;
|
|
215
|
+
stroke-linejoin: round;
|
|
216
|
+
stroke-linecap: round;
|
|
217
|
+
}
|
|
218
|
+
.ss-spark .area {
|
|
219
|
+
opacity: 0.22;
|
|
220
|
+
stroke: none;
|
|
221
|
+
}
|
|
222
|
+
.ss-spark .marker {
|
|
223
|
+
fill: var(--ss-primary);
|
|
39
224
|
}</style>
|
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
import { type Size } from '../config.js';
|
|
2
|
+
type Trend = 'auto' | 'up' | 'down' | 'flat' | 'none';
|
|
3
|
+
type Variant = 'bars' | 'line' | 'area';
|
|
2
4
|
interface Props {
|
|
3
5
|
data: number[];
|
|
6
|
+
/** Bar/line fill. Ignored when `trend` resolves to a non-`none` direction. */
|
|
4
7
|
color?: string;
|
|
5
8
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
6
9
|
size?: Size;
|
|
7
|
-
/** Accessible label;
|
|
10
|
+
/** Accessible label; overrides the auto-generated summary as the accessible name. */
|
|
8
11
|
label?: string;
|
|
12
|
+
/** Lower bound of the scale. Defaults to the data min — set to fix the scale across rows. */
|
|
13
|
+
min?: number;
|
|
14
|
+
/** Upper bound of the scale. Defaults to the data max — set to fix the scale across rows. */
|
|
15
|
+
max?: number;
|
|
16
|
+
/** Colour by direction. `auto` derives first-vs-last → success/danger/muted. Default `none`. */
|
|
17
|
+
trend?: Trend;
|
|
18
|
+
/** Rendering style. Default `bars`. */
|
|
19
|
+
variant?: Variant;
|
|
20
|
+
/** Flex the chart to fill its container width (table-cell friendly). */
|
|
21
|
+
fluid?: boolean;
|
|
22
|
+
/** Explicit CSS width (e.g. `'120px'`, `'100%'`). Overrides the intrinsic width. */
|
|
23
|
+
width?: string;
|
|
24
|
+
/** Format a value for the screen-reader summary (e.g. `v => v + '%'`). */
|
|
25
|
+
valueFormat?: (v: number) => string;
|
|
26
|
+
/** Replace the auto-generated screen-reader summary entirely. */
|
|
27
|
+
summary?: string;
|
|
9
28
|
}
|
|
10
29
|
declare const Sparkline: import("svelte").Component<Props, {}, "">;
|
|
11
30
|
type Sparkline = ReturnType<typeof Sparkline>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Text-frame spinner variants. Frames + intervals are embedded verbatim from
|
|
4
|
+
* sindresorhus/cli-spinners (MIT — https://github.com/sindresorhus/cli-spinners),
|
|
5
|
+
* curated for the squared/blocky glyphs that fit the DS's zero-radius look.
|
|
6
|
+
* No runtime fetch, no dependency — just data.
|
|
7
|
+
*/
|
|
8
|
+
export interface SpinnerFrames {
|
|
9
|
+
/** Milliseconds between frames (cli-spinners' recommended cadence). */
|
|
10
|
+
interval: number
|
|
11
|
+
/** The glyph sequence, cycled in order. */
|
|
12
|
+
frames: readonly string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const SPINNER_VARIANTS = {
|
|
16
|
+
boxBounce2: { interval: 100, frames: ['▌', '▀', '▐', '▄'] },
|
|
17
|
+
boxBounce: { interval: 120, frames: ['▖', '▘', '▝', '▗'] },
|
|
18
|
+
squareCorners: { interval: 180, frames: ['◰', '◳', '◲', '◱'] },
|
|
19
|
+
toggle2: { interval: 80, frames: ['▫', '▪'] },
|
|
20
|
+
toggle3: { interval: 120, frames: ['□', '■'] },
|
|
21
|
+
toggle4: { interval: 100, frames: ['■', '□', '▪', '▫'] },
|
|
22
|
+
pipe: { interval: 100, frames: ['┤', '┘', '┴', '└', '├', '┌', '┬', '┐'] },
|
|
23
|
+
line: { interval: 130, frames: ['-', '\\', '|', '/'] },
|
|
24
|
+
growVertical: { interval: 120, frames: ['▁', '▃', '▄', '▅', '▆', '▇', '▆', '▅', '▄', '▃'] },
|
|
25
|
+
growHorizontal: {
|
|
26
|
+
interval: 120,
|
|
27
|
+
frames: ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '▊', '▋', '▌', '▍', '▎'],
|
|
28
|
+
},
|
|
29
|
+
} as const satisfies Record<string, SpinnerFrames>
|
|
30
|
+
|
|
31
|
+
export type SpinnerVariant = keyof typeof SPINNER_VARIANTS
|
|
32
|
+
|
|
33
|
+
export const SPINNER_VARIANT_NAMES = Object.keys(SPINNER_VARIANTS) as SpinnerVariant[]
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<script lang="ts">
|
|
37
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
38
|
+
|
|
39
|
+
interface Props {
|
|
40
|
+
/** Which frame set to animate (curated from cli-spinners, MIT). */
|
|
41
|
+
variant?: SpinnerVariant
|
|
42
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
43
|
+
size?: Size
|
|
44
|
+
/** Accessible name announced via role="status". */
|
|
45
|
+
label?: string
|
|
46
|
+
/** Render the label visibly next to the glyph (it is announced either way). */
|
|
47
|
+
showLabel?: boolean
|
|
48
|
+
/** Override the variant's frame interval (ms). */
|
|
49
|
+
speed?: number
|
|
50
|
+
/** Any remaining native attributes are forwarded to the root span. */
|
|
51
|
+
[key: string]: unknown
|
|
52
|
+
}
|
|
53
|
+
let {
|
|
54
|
+
variant = 'boxBounce2',
|
|
55
|
+
size,
|
|
56
|
+
label = 'Loading',
|
|
57
|
+
showLabel = false,
|
|
58
|
+
speed,
|
|
59
|
+
...rest
|
|
60
|
+
}: Props = $props()
|
|
61
|
+
|
|
62
|
+
const spinner = $derived(SPINNER_VARIANTS[variant])
|
|
63
|
+
const interval = $derived(speed ?? spinner.interval)
|
|
64
|
+
// 'Spinner' is not in the ComponentName union yet (manifest is owned by the
|
|
65
|
+
// integration step) — cast until dssoca.config.ts registers it.
|
|
66
|
+
const resolvedSize = $derived(resolveComponentSize('Spinner', size))
|
|
67
|
+
|
|
68
|
+
// Under prefers-reduced-motion the first frame renders statically — no cycling.
|
|
69
|
+
const reduceMotion =
|
|
70
|
+
typeof window !== 'undefined' &&
|
|
71
|
+
typeof window.matchMedia === 'function' &&
|
|
72
|
+
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
73
|
+
|
|
74
|
+
let tickIndex = $state(0)
|
|
75
|
+
// Modulo on read so a variant swap to a shorter frame set never reads past the end.
|
|
76
|
+
const frame = $derived(spinner.frames[tickIndex % spinner.frames.length])
|
|
77
|
+
|
|
78
|
+
$effect(() => {
|
|
79
|
+
if (reduceMotion) return
|
|
80
|
+
const count = spinner.frames.length
|
|
81
|
+
const ms = interval
|
|
82
|
+
const id = setInterval(() => {
|
|
83
|
+
tickIndex = (tickIndex + 1) % count
|
|
84
|
+
}, ms)
|
|
85
|
+
return () => clearInterval(id)
|
|
86
|
+
})
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<span class="ss-spinner" data-size-variant={resolvedSize} role="status" {...rest}>
|
|
90
|
+
<span class="frame" aria-hidden="true">{frame}</span>
|
|
91
|
+
<span class="lbl" class:sr-only={!showLabel}>{label}</span>
|
|
92
|
+
</span>
|
|
93
|
+
|
|
94
|
+
<style>.ss-spinner {
|
|
95
|
+
display: inline-flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
gap: var(--ss-gap-sm);
|
|
98
|
+
color: var(--ss-spinner-color, var(--ss-primary));
|
|
99
|
+
}
|
|
100
|
+
.ss-spinner .frame {
|
|
101
|
+
font-family: var(--ss-font-mono);
|
|
102
|
+
font-size: var(--ss-spinner-font, var(--ss-control-font));
|
|
103
|
+
line-height: 1;
|
|
104
|
+
min-width: 1ch;
|
|
105
|
+
text-align: center;
|
|
106
|
+
color: currentColor;
|
|
107
|
+
}
|
|
108
|
+
.ss-spinner .lbl {
|
|
109
|
+
font-family: var(--ss-font-mono);
|
|
110
|
+
font-size: var(--ss-ui-sm);
|
|
111
|
+
color: var(--ss-fg-muted);
|
|
112
|
+
letter-spacing: 0.02em;
|
|
113
|
+
}
|
|
114
|
+
.ss-spinner .sr-only {
|
|
115
|
+
position: absolute;
|
|
116
|
+
width: 1px;
|
|
117
|
+
height: 1px;
|
|
118
|
+
padding: 0;
|
|
119
|
+
margin: -1px;
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
clip: rect(0, 0, 0, 0);
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
border: 0;
|
|
124
|
+
}</style>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-frame spinner variants. Frames + intervals are embedded verbatim from
|
|
3
|
+
* sindresorhus/cli-spinners (MIT — https://github.com/sindresorhus/cli-spinners),
|
|
4
|
+
* curated for the squared/blocky glyphs that fit the DS's zero-radius look.
|
|
5
|
+
* No runtime fetch, no dependency — just data.
|
|
6
|
+
*/
|
|
7
|
+
export interface SpinnerFrames {
|
|
8
|
+
/** Milliseconds between frames (cli-spinners' recommended cadence). */
|
|
9
|
+
interval: number;
|
|
10
|
+
/** The glyph sequence, cycled in order. */
|
|
11
|
+
frames: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export declare const SPINNER_VARIANTS: {
|
|
14
|
+
readonly boxBounce2: {
|
|
15
|
+
readonly interval: 100;
|
|
16
|
+
readonly frames: readonly ["▌", "▀", "▐", "▄"];
|
|
17
|
+
};
|
|
18
|
+
readonly boxBounce: {
|
|
19
|
+
readonly interval: 120;
|
|
20
|
+
readonly frames: readonly ["▖", "▘", "▝", "▗"];
|
|
21
|
+
};
|
|
22
|
+
readonly squareCorners: {
|
|
23
|
+
readonly interval: 180;
|
|
24
|
+
readonly frames: readonly ["◰", "◳", "◲", "◱"];
|
|
25
|
+
};
|
|
26
|
+
readonly toggle2: {
|
|
27
|
+
readonly interval: 80;
|
|
28
|
+
readonly frames: readonly ["▫", "▪"];
|
|
29
|
+
};
|
|
30
|
+
readonly toggle3: {
|
|
31
|
+
readonly interval: 120;
|
|
32
|
+
readonly frames: readonly ["□", "■"];
|
|
33
|
+
};
|
|
34
|
+
readonly toggle4: {
|
|
35
|
+
readonly interval: 100;
|
|
36
|
+
readonly frames: readonly ["■", "□", "▪", "▫"];
|
|
37
|
+
};
|
|
38
|
+
readonly pipe: {
|
|
39
|
+
readonly interval: 100;
|
|
40
|
+
readonly frames: readonly ["┤", "┘", "┴", "└", "├", "┌", "┬", "┐"];
|
|
41
|
+
};
|
|
42
|
+
readonly line: {
|
|
43
|
+
readonly interval: 130;
|
|
44
|
+
readonly frames: readonly ["-", "\\", "|", "/"];
|
|
45
|
+
};
|
|
46
|
+
readonly growVertical: {
|
|
47
|
+
readonly interval: 120;
|
|
48
|
+
readonly frames: readonly ["▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"];
|
|
49
|
+
};
|
|
50
|
+
readonly growHorizontal: {
|
|
51
|
+
readonly interval: 120;
|
|
52
|
+
readonly frames: readonly ["▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍", "▎"];
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export type SpinnerVariant = keyof typeof SPINNER_VARIANTS;
|
|
56
|
+
export declare const SPINNER_VARIANT_NAMES: SpinnerVariant[];
|
|
57
|
+
import { type Size } from '../config.js';
|
|
58
|
+
interface Props {
|
|
59
|
+
/** Which frame set to animate (curated from cli-spinners, MIT). */
|
|
60
|
+
variant?: SpinnerVariant;
|
|
61
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
62
|
+
size?: Size;
|
|
63
|
+
/** Accessible name announced via role="status". */
|
|
64
|
+
label?: string;
|
|
65
|
+
/** Render the label visibly next to the glyph (it is announced either way). */
|
|
66
|
+
showLabel?: boolean;
|
|
67
|
+
/** Override the variant's frame interval (ms). */
|
|
68
|
+
speed?: number;
|
|
69
|
+
/** Any remaining native attributes are forwarded to the root span. */
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
declare const Spinner: import("svelte").Component<Props, {}, "">;
|
|
73
|
+
type Spinner = ReturnType<typeof Spinner>;
|
|
74
|
+
export default Spinner;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
label?: string
|
|
6
|
+
id?: string
|
|
7
|
+
name?: string
|
|
8
|
+
value?: string
|
|
9
|
+
placeholder?: string
|
|
10
|
+
required?: boolean
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
oninput?: (e: Event & { currentTarget: HTMLTextAreaElement }) => void
|
|
13
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
14
|
+
size?: Size
|
|
15
|
+
/** Marks the field invalid for assistive tech (aria-invalid). */
|
|
16
|
+
invalid?: boolean
|
|
17
|
+
/** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
|
|
18
|
+
describedby?: string
|
|
19
|
+
/** Supplementary helper text rendered under the textarea. */
|
|
20
|
+
hint?: string
|
|
21
|
+
/** Error text rendered under the textarea; its presence implies aria-invalid and is announced to AT. */
|
|
22
|
+
error?: string
|
|
23
|
+
/** Native readonly — value visible but not editable; rendered muted. */
|
|
24
|
+
readonly?: boolean
|
|
25
|
+
/** Native maxlength. */
|
|
26
|
+
maxlength?: number
|
|
27
|
+
/** Visible rows; acts as the minimum height (also while autosizing). */
|
|
28
|
+
rows?: number
|
|
29
|
+
/** Grow with content: `field-sizing: content` where supported, JS fallback elsewhere. */
|
|
30
|
+
autosize?: boolean
|
|
31
|
+
/** Row cap while autosizing — the field scrolls beyond it. */
|
|
32
|
+
maxRows?: number
|
|
33
|
+
/** Any remaining native textarea attributes / event handlers are forwarded. */
|
|
34
|
+
[key: string]: unknown
|
|
35
|
+
}
|
|
36
|
+
let {
|
|
37
|
+
label,
|
|
38
|
+
id,
|
|
39
|
+
name,
|
|
40
|
+
value = $bindable(''),
|
|
41
|
+
placeholder = '',
|
|
42
|
+
required = false,
|
|
43
|
+
disabled = false,
|
|
44
|
+
oninput,
|
|
45
|
+
size,
|
|
46
|
+
invalid,
|
|
47
|
+
describedby,
|
|
48
|
+
hint,
|
|
49
|
+
error,
|
|
50
|
+
readonly = false,
|
|
51
|
+
maxlength,
|
|
52
|
+
rows = 3,
|
|
53
|
+
autosize = false,
|
|
54
|
+
maxRows = 10,
|
|
55
|
+
...rest
|
|
56
|
+
}: Props = $props()
|
|
57
|
+
|
|
58
|
+
// Guarantee a label↔textarea association even when no `id` is passed.
|
|
59
|
+
const uid = $props.id()
|
|
60
|
+
const fieldId = $derived(id ?? uid)
|
|
61
|
+
const hintId = $derived(`${fieldId}-hint`)
|
|
62
|
+
const errorId = $derived(`${fieldId}-error`)
|
|
63
|
+
|
|
64
|
+
// error wins, then hint, then any caller-supplied describedby — order matters for AT.
|
|
65
|
+
const describedBy = $derived(
|
|
66
|
+
[error ? errorId : null, hint ? hintId : null, describedby].filter(Boolean).join(' ') ||
|
|
67
|
+
undefined,
|
|
68
|
+
)
|
|
69
|
+
const isInvalid = $derived(invalid || Boolean(error) || undefined)
|
|
70
|
+
// 'Textarea' is not in the ComponentName union yet (manifest is owned by the
|
|
71
|
+
// integration step) — cast until dssoca.config.ts registers it.
|
|
72
|
+
const resolvedSize = $derived(resolveComponentSize('Textarea', size))
|
|
73
|
+
|
|
74
|
+
// Autosize: prefer native `field-sizing: content` (see the scoped CSS); fall
|
|
75
|
+
// back to syncing the height to scrollHeight when the engine lacks it. The
|
|
76
|
+
// CSS max-height (from maxRows) clamps both paths.
|
|
77
|
+
let el = $state<HTMLTextAreaElement>()
|
|
78
|
+
const supportsFieldSizing =
|
|
79
|
+
typeof CSS !== 'undefined' &&
|
|
80
|
+
typeof CSS.supports === 'function' &&
|
|
81
|
+
CSS.supports('field-sizing', 'content')
|
|
82
|
+
|
|
83
|
+
$effect(() => {
|
|
84
|
+
void value // re-run on every value change (including programmatic ones)
|
|
85
|
+
if (!autosize || supportsFieldSizing || !el) return
|
|
86
|
+
el.style.height = 'auto'
|
|
87
|
+
el.style.height = `${el.scrollHeight}px`
|
|
88
|
+
})
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<div class="ss-textarea" data-size-variant={resolvedSize} class:invalid={isInvalid} class:disabled>
|
|
92
|
+
{#if label}
|
|
93
|
+
<label class="lbl" for={fieldId}>
|
|
94
|
+
{label}
|
|
95
|
+
{#if required}<span class="req" aria-hidden="true">*</span>{/if}
|
|
96
|
+
</label>
|
|
97
|
+
{/if}
|
|
98
|
+
|
|
99
|
+
<div class="control">
|
|
100
|
+
<textarea
|
|
101
|
+
bind:this={el}
|
|
102
|
+
class="field"
|
|
103
|
+
class:autosize
|
|
104
|
+
id={fieldId}
|
|
105
|
+
{name}
|
|
106
|
+
bind:value
|
|
107
|
+
{placeholder}
|
|
108
|
+
{required}
|
|
109
|
+
{disabled}
|
|
110
|
+
{readonly}
|
|
111
|
+
{maxlength}
|
|
112
|
+
{rows}
|
|
113
|
+
aria-invalid={isInvalid}
|
|
114
|
+
aria-describedby={describedBy}
|
|
115
|
+
style:max-height={autosize && maxRows
|
|
116
|
+
? `calc(${maxRows} * 1lh + 2 * var(--ss-input-py))`
|
|
117
|
+
: undefined}
|
|
118
|
+
{oninput}
|
|
119
|
+
{...rest}
|
|
120
|
+
></textarea>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
{#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
|
|
124
|
+
{#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<style>.ss-textarea {
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-direction: column;
|
|
130
|
+
gap: 6px;
|
|
131
|
+
}
|
|
132
|
+
.ss-textarea .lbl {
|
|
133
|
+
font-family: var(--ss-font-mono);
|
|
134
|
+
font-size: var(--ss-ui-xs);
|
|
135
|
+
color: var(--ss-fg-muted);
|
|
136
|
+
text-transform: uppercase;
|
|
137
|
+
letter-spacing: 0.08em;
|
|
138
|
+
}
|
|
139
|
+
.ss-textarea .lbl .req {
|
|
140
|
+
color: var(--ss-red);
|
|
141
|
+
margin-left: 2px;
|
|
142
|
+
}
|
|
143
|
+
.ss-textarea .control {
|
|
144
|
+
display: flex;
|
|
145
|
+
align-items: stretch;
|
|
146
|
+
background: transparent;
|
|
147
|
+
color: var(--ss-fg);
|
|
148
|
+
border: 1px solid var(--ss-line);
|
|
149
|
+
padding: 0 var(--ss-input-px);
|
|
150
|
+
transition: border-color var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
|
|
151
|
+
}
|
|
152
|
+
.ss-textarea .control:focus-within {
|
|
153
|
+
border-color: var(--ss-primary);
|
|
154
|
+
box-shadow: 0 0 0 3px var(--ss-primary-soft);
|
|
155
|
+
}
|
|
156
|
+
.ss-textarea.invalid .control {
|
|
157
|
+
border-color: var(--ss-red);
|
|
158
|
+
}
|
|
159
|
+
.ss-textarea.invalid .control:focus-within {
|
|
160
|
+
border-color: var(--ss-red);
|
|
161
|
+
box-shadow: 0 0 0 3px rgba(var(--ss-red-rgb), 0.22);
|
|
162
|
+
}
|
|
163
|
+
.ss-textarea.disabled .control {
|
|
164
|
+
border-color: var(--ss-line);
|
|
165
|
+
}
|
|
166
|
+
.ss-textarea .field {
|
|
167
|
+
font-family: var(--ss-font-body);
|
|
168
|
+
font-size: var(--ss-input-font);
|
|
169
|
+
line-height: 1.5;
|
|
170
|
+
background: transparent;
|
|
171
|
+
color: var(--ss-fg);
|
|
172
|
+
border: none;
|
|
173
|
+
padding: var(--ss-input-py) 0;
|
|
174
|
+
width: 100%;
|
|
175
|
+
min-width: 0;
|
|
176
|
+
resize: vertical;
|
|
177
|
+
transition: color var(--ss-dur-fast) var(--ss-ease);
|
|
178
|
+
}
|
|
179
|
+
.ss-textarea .field:focus {
|
|
180
|
+
outline: none;
|
|
181
|
+
}
|
|
182
|
+
.ss-textarea .field::placeholder {
|
|
183
|
+
font-style: italic;
|
|
184
|
+
color: var(--ss-fg-faint);
|
|
185
|
+
}
|
|
186
|
+
.ss-textarea .field[readonly] {
|
|
187
|
+
color: var(--ss-fg-muted);
|
|
188
|
+
cursor: default;
|
|
189
|
+
}
|
|
190
|
+
.ss-textarea .field:disabled {
|
|
191
|
+
color: var(--ss-fg-faint);
|
|
192
|
+
cursor: not-allowed;
|
|
193
|
+
-webkit-text-fill-color: var(--ss-fg-faint);
|
|
194
|
+
}
|
|
195
|
+
.ss-textarea .field.autosize {
|
|
196
|
+
resize: none;
|
|
197
|
+
overflow-y: auto;
|
|
198
|
+
}
|
|
199
|
+
@supports (field-sizing: content) {
|
|
200
|
+
.ss-textarea .field.autosize {
|
|
201
|
+
field-sizing: content;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
.ss-textarea .msg {
|
|
205
|
+
font-family: var(--ss-font-mono);
|
|
206
|
+
font-size: var(--ss-ui-xs);
|
|
207
|
+
letter-spacing: 0.02em;
|
|
208
|
+
}
|
|
209
|
+
.ss-textarea .msg.hint {
|
|
210
|
+
color: var(--ss-fg-faint);
|
|
211
|
+
}
|
|
212
|
+
.ss-textarea .msg.error {
|
|
213
|
+
color: var(--ss-red);
|
|
214
|
+
}</style>
|