basalt-ui 2.17.0 → 2.18.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 (69) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/MIGRATING.md +44 -12
  3. package/agent/skills/basalt-design/SKILL.md +1 -1
  4. package/dist/cli/help.d.ts +1 -0
  5. package/dist/cli/help.d.ts.map +1 -1
  6. package/dist/cli/help.js +8 -2
  7. package/dist/cli/shot/capture.d.ts +12 -1
  8. package/dist/cli/shot/capture.d.ts.map +1 -1
  9. package/dist/cli/shot/capture.js +72 -10
  10. package/dist/cli/shot/index.d.ts +10 -1
  11. package/dist/cli/shot/index.d.ts.map +1 -1
  12. package/dist/cli/shot/index.js +40 -5
  13. package/dist/cli/shot/real-data.d.ts +35 -0
  14. package/dist/cli/shot/real-data.d.ts.map +1 -0
  15. package/dist/cli/shot/real-data.js +120 -0
  16. package/dist/cli/shot/serve.d.ts +2 -2
  17. package/dist/cli/shot/serve.d.ts.map +1 -1
  18. package/dist/cli/shot/serve.js +16 -2
  19. package/dist/dashboard/bar-list.d.ts +29 -0
  20. package/dist/dashboard/bar-list.d.ts.map +1 -0
  21. package/dist/dashboard/bar-list.js +52 -0
  22. package/dist/dashboard/bar-list.module.css +73 -0
  23. package/dist/dashboard/bar-list.module.css.d.ts +16 -0
  24. package/dist/dashboard/index.d.ts +2 -0
  25. package/dist/dashboard/index.d.ts.map +1 -1
  26. package/dist/dashboard/index.js +4 -0
  27. package/dist/dashboard/meter-model.d.ts +78 -0
  28. package/dist/dashboard/meter-model.d.ts.map +1 -0
  29. package/dist/dashboard/meter-model.js +91 -0
  30. package/dist/dashboard/meter-parts.d.ts +42 -0
  31. package/dist/dashboard/meter-parts.d.ts.map +1 -0
  32. package/dist/dashboard/meter-parts.js +163 -0
  33. package/dist/dashboard/meter.d.ts +112 -0
  34. package/dist/dashboard/meter.d.ts.map +1 -0
  35. package/dist/dashboard/meter.js +43 -0
  36. package/dist/dashboard/meter.module.css +150 -0
  37. package/dist/dashboard/meter.module.css.d.ts +28 -0
  38. package/dist/dashboard/scale.d.ts +9 -0
  39. package/dist/dashboard/scale.d.ts.map +1 -0
  40. package/dist/dashboard/scale.js +10 -0
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +5 -1
  44. package/dist/tokens/derive.d.ts +11 -1
  45. package/dist/tokens/derive.d.ts.map +1 -1
  46. package/dist/tokens/derive.js +9 -24
  47. package/dist/tokens/status-text.d.ts +26 -0
  48. package/dist/tokens/status-text.d.ts.map +1 -0
  49. package/dist/tokens/status-text.js +68 -0
  50. package/llms.txt +32 -3
  51. package/package.json +1 -1
  52. package/src/cli/help.ts +22 -2
  53. package/src/cli/shot/capture.ts +98 -9
  54. package/src/cli/shot/index.ts +50 -4
  55. package/src/cli/shot/real-data.ts +165 -0
  56. package/src/cli/shot/serve.ts +28 -3
  57. package/src/dashboard/bar-list.module.css +73 -0
  58. package/src/dashboard/bar-list.module.css.d.ts +16 -0
  59. package/src/dashboard/bar-list.tsx +112 -0
  60. package/src/dashboard/index.ts +2 -0
  61. package/src/dashboard/meter-model.ts +161 -0
  62. package/src/dashboard/meter-parts.tsx +223 -0
  63. package/src/dashboard/meter.module.css +150 -0
  64. package/src/dashboard/meter.module.css.d.ts +28 -0
  65. package/src/dashboard/meter.tsx +162 -0
  66. package/src/dashboard/scale.ts +13 -0
  67. package/src/index.ts +4 -0
  68. package/src/tokens/derive.ts +19 -31
  69. package/src/tokens/status-text.ts +85 -0
@@ -0,0 +1,223 @@
1
+ /** Meter's internal pieces: bar, ring, empty and loading. `meter.tsx` dispatches between them. */
2
+ import { Skeleton, VisuallyHidden } from '@mantine/core'
3
+ import { useId } from 'react'
4
+ import type { CSSProperties, ReactNode } from 'react'
5
+ import { cx } from '../common/props'
6
+ import { ariaValues, modelBar, ringFraction, zoneBand } from './meter-model'
7
+ import type { MeterSegment, MeterZone, Part } from './meter-model'
8
+ import classes from './meter.module.css'
9
+ import { toPct } from './scale'
10
+
11
+ export type Shell = { className: string | undefined; style: CSSProperties | undefined }
12
+
13
+ const RING_VIEWBOX = 36
14
+ const RING_STROKE = 4
15
+ const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2
16
+ const RING_LENGTH = 2 * Math.PI * RING_RADIUS
17
+ const RING_CENTER = RING_VIEWBOX / 2
18
+
19
+ /** The one ring drawing: a track and, when there is a reading, its arc (a fraction of the circle). */
20
+ function RingSvg({ fraction, color }: { fraction?: number; color?: string | undefined }) {
21
+ return (
22
+ <svg className={classes.ring} viewBox={`0 0 ${RING_VIEWBOX} ${RING_VIEWBOX}`} aria-hidden>
23
+ <circle
24
+ className={classes.ringTrack}
25
+ cx={RING_CENTER}
26
+ cy={RING_CENTER}
27
+ r={RING_RADIUS}
28
+ strokeWidth={RING_STROKE}
29
+ />
30
+ {fraction !== undefined && (
31
+ <circle
32
+ className={classes.ringArc}
33
+ cx={RING_CENTER}
34
+ cy={RING_CENTER}
35
+ r={RING_RADIUS}
36
+ strokeWidth={RING_STROKE}
37
+ strokeDasharray={`${fraction * RING_LENGTH} ${RING_LENGTH}`}
38
+ {...(color !== undefined && { style: { stroke: color } })}
39
+ />
40
+ )}
41
+ </svg>
42
+ )
43
+ }
44
+
45
+ export function MeterLoading({
46
+ label,
47
+ ring,
48
+ shell,
49
+ }: {
50
+ label: string
51
+ ring: boolean
52
+ shell: Shell
53
+ }) {
54
+ return (
55
+ <div className={cx(classes.root, shell.className)} style={shell.style} aria-busy="true">
56
+ <VisuallyHidden>{`Loading ${label}`}</VisuallyHidden>
57
+ {ring ? (
58
+ <Skeleton className={classes.skeletonRing} circle />
59
+ ) : (
60
+ <>
61
+ <Skeleton className={classes.skeletonTrack} />
62
+ <Skeleton className={classes.skeletonCaption} radius="sm" />
63
+ </>
64
+ )}
65
+ </div>
66
+ )
67
+ }
68
+
69
+ export function MeterEmpty(props: { label: string; text: string; ring: boolean; shell: Shell }) {
70
+ const { label, text, ring, shell } = props
71
+ return (
72
+ <output className={cx(classes.root, shell.className)} style={shell.style} aria-label={label}>
73
+ {ring ? (
74
+ <span className={classes.ringBox}>
75
+ <RingSvg />
76
+ </span>
77
+ ) : (
78
+ <div className={classes.trackBox}>
79
+ <div className={classes.track} data-meter-track />
80
+ </div>
81
+ )}
82
+ <span className={classes.empty}>{text}</span>
83
+ </output>
84
+ )
85
+ }
86
+
87
+ export function MeterRing(props: {
88
+ label: string
89
+ reading: number
90
+ min: number
91
+ max: number
92
+ color: string | undefined
93
+ format: (value: number) => string
94
+ shell: Shell
95
+ }) {
96
+ const { label, reading, min, max, color, format, shell } = props
97
+ return (
98
+ <div className={cx(classes.root, shell.className)} style={shell.style}>
99
+ <span
100
+ className={classes.ringBox}
101
+ aria-label={label}
102
+ {...ariaValues(reading, min, max, format)}
103
+ >
104
+ <RingSvg fraction={ringFraction(reading, min, max)} color={color} />
105
+ <span className={classes.ringValue}>{format(reading)}</span>
106
+ </span>
107
+ </div>
108
+ )
109
+ }
110
+
111
+ function fillStyle(p: Part): CSSProperties {
112
+ return { width: `${toPct(p.size)}%`, ...(p.color !== undefined && { background: p.color }) }
113
+ }
114
+
115
+ /** Uncoloured zones step from `MIN` to `MIN + STEP` percent of the neutral, so order reads without hue. */
116
+ const ZONE_STRENGTH_MIN = 15
117
+ const ZONE_STRENGTH_STEP = 45
118
+ const ZONE_STRENGTH_SOLO = 40
119
+ /** Every band after the first gives up its leading pixel, so a boundary never relies on fill strength. */
120
+ const ZONE_GAP = '1px'
121
+
122
+ function zoneStyle(zone: MeterZone, index: number, count: number, min: number, span: number) {
123
+ const band = zoneBand(zone, min, span)
124
+ const gap = index > 0
125
+ const strength =
126
+ count > 1 ? ZONE_STRENGTH_MIN + (index / (count - 1)) * ZONE_STRENGTH_STEP : ZONE_STRENGTH_SOLO
127
+ return {
128
+ insetInlineStart: gap ? `calc(${band.start}% + ${ZONE_GAP})` : `${band.start}%`,
129
+ width: gap ? `calc(${band.width}% - ${ZONE_GAP})` : `${band.width}%`,
130
+ background: zone.color ?? `color-mix(in srgb, var(--vx-line) ${strength}%, transparent)`,
131
+ } satisfies CSSProperties
132
+ }
133
+
134
+ export function MeterBar(props: {
135
+ label: string
136
+ reading: number
137
+ min: number
138
+ max: number
139
+ format: (value: number) => string
140
+ color: string | undefined
141
+ segments: readonly MeterSegment[] | undefined
142
+ zones: readonly MeterZone[] | undefined
143
+ target: number | undefined
144
+ forecastCaption: string | undefined
145
+ startCaption: ReactNode
146
+ endCaption: ReactNode
147
+ shell: Shell
148
+ }) {
149
+ const { label, reading, min, max, format, zones, shell } = props
150
+ const describedId = useId()
151
+ const model = modelBar(props)
152
+ const start = props.startCaption === undefined ? model.startText : props.startCaption
153
+ const end = props.endCaption === undefined ? model.endText : props.endCaption
154
+ const hasCaptions = start !== null || end !== null || model.forecastText !== null
155
+ const describedBy =
156
+ model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
157
+
158
+ return (
159
+ <div className={cx(classes.root, shell.className)} style={shell.style}>
160
+ <div
161
+ className={classes.trackBox}
162
+ aria-label={label}
163
+ {...ariaValues(reading, min, max, format)}
164
+ {...describedBy}
165
+ >
166
+ <div className={classes.track} data-meter-track>
167
+ {model.markerPct !== undefined &&
168
+ zones?.map((z, i) => (
169
+ <div
170
+ key={i}
171
+ className={classes.zone}
172
+ data-meter-zone={z.label}
173
+ style={zoneStyle(z, i, zones.length, min, model.span)}
174
+ />
175
+ ))}
176
+ {model.parts.map((p, i) => (
177
+ <div
178
+ key={i}
179
+ className={cx(classes.fill, p.forecast && classes.forecastFill)}
180
+ data-meter-fill={p.forecast ? 'forecast' : 'committed'}
181
+ style={fillStyle(p)}
182
+ />
183
+ ))}
184
+ </div>
185
+ <Tick kind="marker" className={classes.marker} pct={model.markerPct} />
186
+ <Tick kind="boundary" className={classes.boundaryTick} pct={model.boundaryPct} />
187
+ <Tick kind="target" className={classes.tick} pct={model.targetPct} />
188
+ </div>
189
+ {model.describedByText !== null && (
190
+ <VisuallyHidden id={describedId}>{model.describedByText}</VisuallyHidden>
191
+ )}
192
+ {hasCaptions && (
193
+ <div className={classes.captions} data-meter-captions>
194
+ {start !== null && <span className={classes.caption}>{start}</span>}
195
+ {model.forecastText !== null && (
196
+ <span className={classes.caption}>{model.forecastText}</span>
197
+ )}
198
+ {end !== null && <span className={classes.captionEnd}>{end}</span>}
199
+ </div>
200
+ )}
201
+ </div>
202
+ )
203
+ }
204
+
205
+ function Tick({
206
+ kind,
207
+ className,
208
+ pct,
209
+ }: {
210
+ kind: 'marker' | 'boundary' | 'target'
211
+ className: string
212
+ pct: number | undefined
213
+ }) {
214
+ if (pct === undefined) return null
215
+ return (
216
+ <div
217
+ className={className}
218
+ data-meter-tick={kind}
219
+ style={{ insetInlineStart: `${pct}%` }}
220
+ aria-hidden
221
+ />
222
+ )
223
+ }
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Meter — one neutral track, ordered fills, optional target tick (docs/waves/design-parity/SPEC.md
3
+ * § 6.3). Flat fills, no hatching. Bar height 6 is the measured reference; the radius is the `fine`
4
+ * step so the track follows the radius knob.
5
+ */
6
+
7
+ .root {
8
+ display: flex;
9
+ flex-direction: column;
10
+ gap: var(--vx-space-stack-xs, 0.25rem);
11
+ min-width: 0;
12
+ }
13
+
14
+ .track {
15
+ position: relative;
16
+ display: flex;
17
+ height: 0.375rem;
18
+ overflow: hidden;
19
+ border-radius: var(--vx-radius-fine);
20
+ background: var(--vx-surface-subtle);
21
+ }
22
+
23
+ /* The tick is drawn OVER the fills and outside the clipped track, so it can stand 2px proud of it. */
24
+ .trackBox {
25
+ position: relative;
26
+ }
27
+
28
+ .fill {
29
+ flex: none;
30
+ height: 100%;
31
+ background: var(--vx-line);
32
+ }
33
+
34
+ /* The committed/forecast pair: the same neutral at two strengths. Flat, never hatched. */
35
+ .forecastFill {
36
+ background: color-mix(in srgb, var(--vx-line) 45%, transparent);
37
+ }
38
+
39
+ .zone {
40
+ position: absolute;
41
+ inset-block: 0;
42
+ }
43
+
44
+ /* The reading on a zone track: a notch standing proud of the bands, in ink. */
45
+ .marker {
46
+ position: absolute;
47
+ top: -3px;
48
+ bottom: -3px;
49
+ width: 3px;
50
+ margin-inline-start: -1.5px;
51
+ border-radius: 1px;
52
+ background: var(--vx-ink);
53
+ }
54
+
55
+ .tick {
56
+ position: absolute;
57
+ top: -2px;
58
+ bottom: -2px;
59
+ width: 2px;
60
+ margin-inline-start: -1px;
61
+ border-radius: 1px;
62
+ background: var(--vx-ink);
63
+ }
64
+
65
+ .boundaryTick {
66
+ composes: tick;
67
+ background: var(--vx-muted);
68
+ }
69
+
70
+ .captions {
71
+ display: flex;
72
+ align-items: baseline;
73
+ justify-content: space-between;
74
+ gap: var(--vx-space-control-gap, 0.375rem);
75
+ font-family: var(--basalt-font-mono);
76
+ font-size: var(--vx-text-micro);
77
+ color: var(--vx-muted);
78
+ }
79
+
80
+ .caption {
81
+ white-space: nowrap;
82
+ }
83
+
84
+ .captionEnd {
85
+ composes: caption;
86
+ text-align: end;
87
+ }
88
+
89
+ /* Alone in the row, the end caption still sits at the end. */
90
+ .captionEnd:first-child {
91
+ margin-inline-start: auto;
92
+ }
93
+
94
+ .empty {
95
+ font-size: var(--vx-text-sm);
96
+ color: var(--vx-muted);
97
+ }
98
+
99
+ /* The skeleton holds the track + one caption line: 6 + 4 + a micro line. */
100
+ .skeletonTrack {
101
+ height: 0.375rem;
102
+ }
103
+
104
+ .skeletonCaption {
105
+ width: 40%;
106
+ height: 0.75rem;
107
+ }
108
+
109
+ /* ── ring ────────────────────────────────────────────────────────────────────────────────────── */
110
+
111
+ .ringBox {
112
+ position: relative;
113
+ display: inline-flex;
114
+ align-items: center;
115
+ justify-content: center;
116
+ align-self: flex-start;
117
+ width: 5rem;
118
+ height: 5rem;
119
+ }
120
+
121
+ .ring {
122
+ position: absolute;
123
+ inset: 0;
124
+ width: 100%;
125
+ height: 100%;
126
+ transform: rotate(-90deg);
127
+ }
128
+
129
+ .ringTrack {
130
+ fill: none;
131
+ stroke: var(--vx-surface-subtle);
132
+ }
133
+
134
+ .ringArc {
135
+ fill: none;
136
+ stroke: var(--vx-line);
137
+ }
138
+
139
+ .ringValue {
140
+ position: relative;
141
+ font-family: var(--basalt-font-mono);
142
+ font-size: var(--vx-text-md);
143
+ font-weight: 500;
144
+ color: var(--vx-ink);
145
+ }
146
+
147
+ .skeletonRing {
148
+ width: 5rem;
149
+ height: 5rem;
150
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
3
+ * signature — so dot access stays verbatim under the package's strict flags.
4
+ */
5
+ declare const classes: {
6
+ readonly root: string
7
+ readonly track: string
8
+ readonly trackBox: string
9
+ readonly fill: string
10
+ readonly forecastFill: string
11
+ readonly zone: string
12
+ readonly marker: string
13
+ readonly tick: string
14
+ readonly boundaryTick: string
15
+ readonly captions: string
16
+ readonly caption: string
17
+ readonly captionEnd: string
18
+ readonly empty: string
19
+ readonly skeletonTrack: string
20
+ readonly skeletonCaption: string
21
+ readonly ringBox: string
22
+ readonly ring: string
23
+ readonly ringTrack: string
24
+ readonly ringArc: string
25
+ readonly ringValue: string
26
+ readonly skeletonRing: string
27
+ }
28
+ export default classes
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Meter — one bounded quantity on a track: progress to a target, a committed/forecast split, a
3
+ * part-of-a-whole strip (`segments`), or a single headline ratio as a `ring`. Choose it for "how far
4
+ * along is this against a limit"; choose `BarList` for a ranking and a chart for a trend. An HTML/CSS
5
+ * primitive, not a chart kind (no scale, axis or tooltip).
6
+ *
7
+ * Colour law: the fill is neutral (`VX.line`). `color` is for a VERDICT only (over budget, below
8
+ * target) and is a status colour the consumer passes; categorical `segments` take the consumer's
9
+ * series colours. Committed vs forecast is the same neutral at two strengths — never colour alone: a
10
+ * tick marks the boundary and a caption names the forecast. A value past `max` clamps the fill at the
11
+ * track end; the caption still states the real value.
12
+ *
13
+ * `zones` (bar only) draws the track as contiguous bands (neutral at stepped strengths unless a zone
14
+ * passes a status colour) and the reading becomes a MARKER on the track, not a fill; the caption names
15
+ * the zone that holds the value (`from` inclusive). Use it for a reading judged against ranges.
16
+ *
17
+ * @example
18
+ * import { Meter } from 'basalt-ui'
19
+ *
20
+ * // Spend against a budget: past the target the end caption states the overage.
21
+ * <Meter label="Monthly spend" value={512} max={600} target={450} color="var(--vx-status-bad)" format={usd} />
22
+ * // Training load as a zone band with a marker: caption reads "Optimal · 612".
23
+ * <Meter
24
+ * label="Training load"
25
+ * max={1000}
26
+ * value={612}
27
+ * zones={[
28
+ * { from: 0, to: 300, label: 'Low' },
29
+ * { from: 300, to: 750, label: 'Optimal' },
30
+ * { from: 750, to: 1000, label: 'High' },
31
+ * ]}
32
+ * />
33
+ * // A readiness score on its 0–100 scale (its contributors: <BarList max={100} … secondary="Good" />).
34
+ * <Meter label="Recovery" value={72} max={100} />
35
+ * <Meter
36
+ * label="Course progress"
37
+ * max={120}
38
+ * segments={[{ value: 70, label: 'Done' }, { value: 25, label: 'Planned', forecast: true }]}
39
+ * />
40
+ * <Meter shape="ring" label="Cache hit rate" value={87} max={100} format={(v) => `${v}%`} />
41
+ */
42
+ import type { ReactNode } from 'react'
43
+ import type { BasaltProps } from '../common/props'
44
+ import { isReading, normalizeSegments, segmentReading, spanOf } from './meter-model'
45
+ import type { MeterSegment, MeterZone } from './meter-model'
46
+ import { MeterBar, MeterEmpty, MeterLoading, MeterRing } from './meter-parts'
47
+ import { asText } from './scale'
48
+
49
+ type Common = BasaltProps & {
50
+ /** Accessible name (`aria-label`). Required: a meter without one is announced as a bare number. */
51
+ label: string
52
+ /** Track start. Default 0. */
53
+ min?: number
54
+ /** Track end. Default 100. */
55
+ max?: number
56
+ /** Formats values in captions and the accessible text. Default: the number as written. */
57
+ format?: (value: number) => string
58
+ /** Renders a skeleton with the meter's footprint. */
59
+ loading?: boolean
60
+ /** Muted line shown when there is no reading. The track stays so the footprint holds. */
61
+ emptyText?: string
62
+ }
63
+
64
+ type BarCommon = Common & {
65
+ shape?: 'bar'
66
+ /** Target position; draws a tick and states it in the end caption (with the overage past it). */
67
+ target?: number
68
+ /** Start caption (default: the formatted reading, or `Zone · reading`). `null` drops it. */
69
+ startCaption?: ReactNode
70
+ /** End caption (default: `Target <target>`). `null` drops it. */
71
+ endCaption?: ReactNode
72
+ }
73
+
74
+ /**
75
+ * One of four forms; mixing them is a compile error.
76
+ * - Bar `value` (+ `target`, `color`): one reading on a neutral track.
77
+ * - Bar `segments`: ordered parts that sum to the reading (committed/forecast, part of a whole).
78
+ * - Bar `value` + `zones`: the reading is a marker against contiguous bands.
79
+ * - Ring (`shape: 'ring'`) `value` (+ `color`): one headline ratio; no target, captions, segments or zones.
80
+ */
81
+ export type MeterProps =
82
+ | (BarCommon & {
83
+ /** The reading. `null`/`undefined` (or non-finite) renders the empty state. */
84
+ value?: number | null | undefined
85
+ /** A status colour, for a verdict only. Omit for the neutral fill. */
86
+ color?: string
87
+ segments?: never
88
+ zones?: never
89
+ })
90
+ | (BarCommon & {
91
+ /** Ordered parts, accumulated from `min`; their sum is the reading. `forecast` parts render lighter. */
92
+ segments: readonly MeterSegment[]
93
+ /** Names the forecast beside the boundary tick (default: `Forecast: <labels>`). */
94
+ forecastCaption?: string
95
+ value?: never
96
+ color?: never
97
+ zones?: never
98
+ })
99
+ | (BarCommon & {
100
+ value?: number | null | undefined
101
+ /**
102
+ * Contiguous bands drawn as the track, positioned from each `from`. The reading becomes a marker
103
+ * and the caption names the band that holds it.
104
+ */
105
+ zones: readonly MeterZone[]
106
+ segments?: never
107
+ color?: never
108
+ })
109
+ | (Common & {
110
+ shape: 'ring'
111
+ value?: number | null | undefined
112
+ /** A status colour, for a verdict only. */
113
+ color?: string
114
+ segments?: never
115
+ zones?: never
116
+ target?: never
117
+ startCaption?: never
118
+ endCaption?: never
119
+ })
120
+
121
+ let warnedTrack = false
122
+ /** One dev warning per page load for a track that ends at or before its start. */
123
+ function warnInvalidTrack(min: number, max: number) {
124
+ if (warnedTrack || spanOf(min, max).valid || process.env.NODE_ENV === 'production') return
125
+ warnedTrack = true
126
+ console.warn(
127
+ `[basalt] Meter: max (${max}) must be greater than min (${min}); drawing an empty track`,
128
+ )
129
+ }
130
+
131
+ export function Meter(props: MeterProps) {
132
+ const { label, min = 0, max = 100, format = asText, className, style } = props
133
+ const shell = { className, style }
134
+ const ring = props.shape === 'ring'
135
+ warnInvalidTrack(min, max)
136
+
137
+ if (props.loading === true) return <MeterLoading label={label} ring={ring} shell={shell} />
138
+
139
+ const segments = props.segments === undefined ? undefined : normalizeSegments(props.segments)
140
+ const reading = segments === undefined ? props.value : segmentReading(segments, min)
141
+ if (!isReading(reading) || segments?.length === 0) {
142
+ return (
143
+ <MeterEmpty label={label} text={props.emptyText ?? 'No data'} ring={ring} shell={shell} />
144
+ )
145
+ }
146
+
147
+ if (props.shape === 'ring') {
148
+ return <MeterRing {...{ label, reading, min, max, format, shell }} color={props.color} />
149
+ }
150
+ return (
151
+ <MeterBar
152
+ {...{ label, reading, min, max, format, shell }}
153
+ color={props.color}
154
+ segments={segments}
155
+ zones={props.zones}
156
+ target={isReading(props.target) ? props.target : undefined}
157
+ forecastCaption={props.segments === undefined ? undefined : props.forecastCaption}
158
+ startCaption={props.startCaption}
159
+ endCaption={props.endCaption}
160
+ />
161
+ )
162
+ }
@@ -0,0 +1,13 @@
1
+ /** Shared by `Meter` and `BarList`: the one place a value becomes a track percentage. Internal. */
2
+
3
+ /** Clamps to 0–1; a non-finite fraction is 0. */
4
+ export const clamp01 = (n: number): number => (Number.isFinite(n) ? Math.min(1, Math.max(0, n)) : 0)
5
+
6
+ /** A 0–1 fraction as a percent, rounded so float noise never reaches the DOM. */
7
+ export const toPct = (n: number): number => Math.round(clamp01(n) * 10000) / 100
8
+
9
+ /** A value on a track that ends at `scale`; a non-finite value or an empty scale draws nothing. */
10
+ export const barPercent = (value: number, scale: number): number =>
11
+ Number.isFinite(value) && Number.isFinite(scale) && scale > 0 ? toPct(value / scale) : 0
12
+
13
+ export const asText = (n: number): string => String(n)
package/src/index.ts CHANGED
@@ -48,6 +48,10 @@ export {
48
48
  SettingsSection,
49
49
  SettingsRow,
50
50
  DangerZone,
51
+ Meter,
52
+ type MeterProps,
53
+ BarList,
54
+ type BarListProps,
51
55
  } from './dashboard'
52
56
  export { unwrap } from './unwrap'
53
57
 
@@ -10,6 +10,7 @@
10
10
  * constants below, never hand-editing a hex in `palette.ts`.
11
11
  */
12
12
  import { contrastRatio, hctToHex, hexToHct, yToTone } from './hct'
13
+ import { deriveStatusHexes } from './status-text'
13
14
  import type { ColorPair } from './core'
14
15
 
15
16
  export type DeriveConfig = {
@@ -316,18 +317,6 @@ const INK_TONE: Record<Side, Record<InkKey, number>> = {
316
317
  // ── Status/semantic — three baked hues, each with its own calibrated tone+chroma stop per scheme.
317
318
  export type StatusKey = 'good' | 'warn' | 'bad'
318
319
 
319
- const STATUS_HUE: Record<StatusKey, number> = { good: 151.975, warn: 76.64, bad: 29.905 }
320
- // Every stop is read as TEXT somewhere (`DeltaBadge`, a toned breakdown row), so each clears WCAG AA
321
- // (4.5:1) on every text surface (bg / panel / panelHover / elevated / subtle / field) at the default
322
- // derive config only (default seed, every level knob 0) — pinned in `derive.test.ts`; a retuned
323
- // `lightLevel` / `darkLevel` / `neutral` is not covered. `warn` light sat at tone 54.64 (3.64:1 on the panel) and `bad`
324
- // dark at 58.58 (4.22:1); both moved along their lightness axis only, hue and chroma untouched.
325
- const STATUS_STOP: Record<StatusKey, Record<Side, { tone: number; chroma: number }>> = {
326
- good: { light: { tone: 45.75, chroma: 37.75 }, dark: { tone: 70.23, chroma: 53.23 } },
327
- warn: { light: { tone: 46, chroma: 61.12 }, dark: { tone: 72.34, chroma: 62.55 } },
328
- bad: { light: { tone: 43.86, chroma: 54.46 }, dark: { tone: 66.5, chroma: 53.79 } },
329
- }
330
-
331
320
  /**
332
321
  * Continuous derivation parameters — the derivation CORE's inputs, decoupled from the -5..5
333
322
  * slider levels. `deriveTokens` maps levels onto these (with the re-centered baselines baked in).
@@ -357,16 +346,30 @@ export type DerivedPalette = {
357
346
  status: Record<StatusKey, ColorPair>
358
347
  }
359
348
 
349
+ /** The accepted `lightLevel` / `darkLevel` range; `deriveTokens` clamps to it. */
350
+ export const DERIVE_LEVEL_RANGE = { min: -5, max: 5 } as const
351
+
352
+ function clampLevel(level: number): number {
353
+ return Number.isFinite(level) ? clamp(level, DERIVE_LEVEL_RANGE.min, DERIVE_LEVEL_RANGE.max) : 0
354
+ }
355
+
360
356
  /** Derive the full palette from a seed accent + neutral family + surface levels.
361
357
  * Public level-based entry: maps the -5..5 sliders onto `DeriveParams` (vibrancy x0.72 center,
362
- * surface +2 baseline) and delegates to `deriveTokensRaw`. */
358
+ * surface +2 baseline) and delegates to `deriveTokensRaw`.
359
+ *
360
+ * `lightLevel` / `darkLevel` are clamped to {@link DERIVE_LEVEL_RANGE} (non-finite → 0).
361
+ * @throws Error when no status tone clears 4.5:1 on every text surface — unreachable for clamped
362
+ * levels (the test grid proves it); only a raw shift outside the slider range gets there.
363
+ */
363
364
  export function deriveTokens(config: DeriveConfig): DerivedPalette {
364
365
  assertValidAccentHex(config.accent)
365
366
  return deriveTokensRaw(config, {
366
367
  chromaMult: vibrancyChromaMult(config.vibrancy),
367
368
  accentToneShift: config.accentBrightness * ACCENT_BRIGHTNESS_TONE_STEP,
368
- lightSurfaceShift: SURFACE_LEVEL_TONE_STEP * config.lightLevel + SURFACE_BASELINE_TONE_SHIFT,
369
- darkSurfaceShift: SURFACE_LEVEL_TONE_STEP * config.darkLevel + SURFACE_BASELINE_TONE_SHIFT,
369
+ lightSurfaceShift:
370
+ SURFACE_LEVEL_TONE_STEP * clampLevel(config.lightLevel) + SURFACE_BASELINE_TONE_SHIFT,
371
+ darkSurfaceShift:
372
+ SURFACE_LEVEL_TONE_STEP * clampLevel(config.darkLevel) + SURFACE_BASELINE_TONE_SHIFT,
370
373
  })
371
374
  }
372
375
 
@@ -457,22 +460,7 @@ export function deriveTokensRaw(
457
460
  }
458
461
  }
459
462
 
460
- const status = {} as Record<StatusKey, ColorPair>
461
- for (const key of Object.keys(STATUS_HUE) as StatusKey[]) {
462
- const hue = STATUS_HUE[key]
463
- status[key] = {
464
- light: hctToHex({
465
- hue,
466
- chroma: STATUS_STOP[key].light.chroma,
467
- tone: STATUS_STOP[key].light.tone,
468
- }),
469
- dark: hctToHex({
470
- hue,
471
- chroma: STATUS_STOP[key].dark.chroma,
472
- tone: STATUS_STOP[key].dark.tone,
473
- }),
474
- }
475
- }
463
+ const status = deriveStatusHexes(surface)
476
464
 
477
465
  return {
478
466
  accent: { light: accentFill, dark: accentInkDark },