basalt-ui 2.21.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/MIGRATING.md +277 -12
  3. package/agent/agents/basalt-design-reviewer.md +1 -1
  4. package/agent/rules/basalt-tokens.md +1 -1
  5. package/agent/skills/basalt-design/SKILL.md +1 -1
  6. package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
  7. package/agent/skills/basalt-design/references/catalogue.md +1 -0
  8. package/dist/charts/BandStrip.d.ts.map +1 -1
  9. package/dist/charts/BandStrip.js +27 -3
  10. package/dist/charts/Bars.d.ts.map +1 -1
  11. package/dist/charts/Bars.js +5 -0
  12. package/dist/charts/CartesianChart.d.ts +8 -0
  13. package/dist/charts/CartesianChart.d.ts.map +1 -1
  14. package/dist/charts/CartesianChart.js +8 -5
  15. package/dist/charts/ChartCard.d.ts +12 -3
  16. package/dist/charts/ChartCard.d.ts.map +1 -1
  17. package/dist/charts/ChartCard.js +29 -8
  18. package/dist/charts/DualPanel.d.ts.map +1 -1
  19. package/dist/charts/DualPanel.js +5 -8
  20. package/dist/charts/Heatmap.d.ts +12 -1
  21. package/dist/charts/Heatmap.d.ts.map +1 -1
  22. package/dist/charts/Heatmap.js +34 -5
  23. package/dist/charts/Lines.d.ts +3 -0
  24. package/dist/charts/Lines.d.ts.map +1 -1
  25. package/dist/charts/Lines.js +29 -6
  26. package/dist/charts/MirroredBars.d.ts.map +1 -1
  27. package/dist/charts/MirroredBars.js +4 -6
  28. package/dist/charts/Sparkline.d.ts +7 -1
  29. package/dist/charts/Sparkline.d.ts.map +1 -1
  30. package/dist/charts/Sparkline.js +39 -14
  31. package/dist/charts/StackedArea.d.ts +4 -1
  32. package/dist/charts/StackedArea.d.ts.map +1 -1
  33. package/dist/charts/StackedArea.js +9 -3
  34. package/dist/charts/band-fold.d.ts +20 -1
  35. package/dist/charts/band-fold.d.ts.map +1 -1
  36. package/dist/charts/band-fold.js +9 -0
  37. package/dist/charts/chart-box.module.css +19 -0
  38. package/dist/charts/chart-card.module.css +25 -0
  39. package/dist/charts/chart-legend.module.css +7 -0
  40. package/dist/charts/compile.d.ts +17 -6
  41. package/dist/charts/compile.d.ts.map +1 -1
  42. package/dist/charts/compile.js +145 -74
  43. package/dist/charts/labels.d.ts +15 -4
  44. package/dist/charts/labels.d.ts.map +1 -1
  45. package/dist/charts/labels.js +34 -10
  46. package/dist/charts/legend.d.ts +2 -0
  47. package/dist/charts/legend.d.ts.map +1 -1
  48. package/dist/charts/legend.js +7 -21
  49. package/dist/charts/marks.js +1 -1
  50. package/dist/charts/panel.d.ts +0 -6
  51. package/dist/charts/panel.d.ts.map +1 -1
  52. package/dist/charts/panel.js +1 -10
  53. package/dist/charts/ref-label.d.ts +26 -0
  54. package/dist/charts/ref-label.d.ts.map +1 -0
  55. package/dist/charts/ref-label.js +63 -0
  56. package/dist/charts/scales.d.ts +4 -1
  57. package/dist/charts/scales.d.ts.map +1 -1
  58. package/dist/charts/scales.js +14 -3
  59. package/dist/charts/sparkline.module.css +10 -11
  60. package/dist/charts/sparkline.module.css.d.ts +1 -2
  61. package/dist/charts/state.d.ts +2 -0
  62. package/dist/charts/state.d.ts.map +1 -1
  63. package/dist/charts/state.js +2 -1
  64. package/dist/charts/types.d.ts +14 -5
  65. package/dist/charts/types.d.ts.map +1 -1
  66. package/dist/cli/doctor-upgrade.d.ts +1 -0
  67. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  68. package/dist/cli/doctor-upgrade.js +1 -0
  69. package/dist/cli/init.d.ts +2 -0
  70. package/dist/cli/init.d.ts.map +1 -1
  71. package/dist/cli/init.js +68 -4
  72. package/dist/cli/shot/capture.d.ts +21 -2
  73. package/dist/cli/shot/capture.d.ts.map +1 -1
  74. package/dist/cli/shot/capture.js +194 -32
  75. package/dist/cli/shot/detect.d.ts.map +1 -1
  76. package/dist/cli/shot/detect.js +14 -1
  77. package/dist/cli/shot/playwright.d.ts +5 -2
  78. package/dist/cli/shot/playwright.d.ts.map +1 -1
  79. package/dist/cli/shot/types.d.ts +2 -0
  80. package/dist/cli/shot/types.d.ts.map +1 -1
  81. package/dist/cli/shot/types.js +2 -0
  82. package/dist/controls/controls.module.css +11 -1
  83. package/dist/controls/filter-pill.d.ts.map +1 -1
  84. package/dist/controls/filter-pill.js +1 -0
  85. package/dist/controls/sync-button.d.ts.map +1 -1
  86. package/dist/controls/sync-button.js +22 -3
  87. package/dist/controls/sync-button.module.css +34 -2
  88. package/dist/controls/sync-button.module.css.d.ts +1 -0
  89. package/dist/dashboard/bar-list.d.ts.map +1 -1
  90. package/dist/dashboard/bar-list.js +7 -8
  91. package/dist/dashboard/bar-list.module.css +53 -0
  92. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  93. package/dist/dashboard/index.d.ts +1 -0
  94. package/dist/dashboard/index.d.ts.map +1 -1
  95. package/dist/dashboard/index.js +2 -0
  96. package/dist/dashboard/meter-model.d.ts +77 -3
  97. package/dist/dashboard/meter-model.d.ts.map +1 -1
  98. package/dist/dashboard/meter-model.js +88 -15
  99. package/dist/dashboard/meter-parts.d.ts +8 -0
  100. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  101. package/dist/dashboard/meter-parts.js +238 -71
  102. package/dist/dashboard/meter.d.ts +43 -60
  103. package/dist/dashboard/meter.d.ts.map +1 -1
  104. package/dist/dashboard/meter.js +20 -3
  105. package/dist/dashboard/meter.module.css +61 -0
  106. package/dist/dashboard/meter.module.css.d.ts +5 -0
  107. package/dist/dashboard/page-summary.d.ts +20 -0
  108. package/dist/dashboard/page-summary.d.ts.map +1 -0
  109. package/dist/dashboard/page-summary.js +28 -0
  110. package/dist/dashboard/page-summary.module.css +89 -0
  111. package/dist/dashboard/page-summary.module.css.d.ts +15 -0
  112. package/dist/dashboard/section.d.ts +25 -2
  113. package/dist/dashboard/section.d.ts.map +1 -1
  114. package/dist/dashboard/section.js +10 -5
  115. package/dist/dashboard/section.module.css +23 -0
  116. package/dist/dashboard/section.module.css.d.ts +1 -0
  117. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  118. package/dist/dashboard/stat-card-parts.js +1 -1
  119. package/dist/dashboard/stat-card.d.ts +4 -2
  120. package/dist/dashboard/stat-card.d.ts.map +1 -1
  121. package/dist/dashboard/stat-card.js +7 -5
  122. package/dist/dashboard/stat-card.module.css +17 -0
  123. package/dist/dashboard/stat-strip.d.ts +7 -1
  124. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  125. package/dist/dashboard/stat-strip.js +74 -46
  126. package/dist/dashboard/stat-strip.module.css +67 -20
  127. package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
  128. package/dist/dashboard/visual-slot.d.ts +7 -1
  129. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  130. package/dist/dashboard/visual-slot.js +3 -1
  131. package/dist/guard/vx-names.d.ts.map +1 -1
  132. package/dist/guard/vx-names.js +2 -0
  133. package/dist/index.d.ts +1 -1
  134. package/dist/index.d.ts.map +1 -1
  135. package/dist/index.js +3 -1
  136. package/dist/styles.css +34 -2
  137. package/dist/theme/chrome-vars.d.ts +20 -5
  138. package/dist/theme/chrome-vars.d.ts.map +1 -1
  139. package/dist/theme/chrome-vars.js +46 -3
  140. package/dist/theme/controls.module.css +23 -0
  141. package/dist/theme/controls.module.css.d.ts +1 -0
  142. package/dist/theme/index.d.ts.map +1 -1
  143. package/dist/theme/index.js +8 -20
  144. package/dist/tokens/core.d.ts +2 -1
  145. package/dist/tokens/core.d.ts.map +1 -1
  146. package/dist/tokens/core.js +6 -1
  147. package/dist/tokens/derive.d.ts +3 -1
  148. package/dist/tokens/derive.d.ts.map +1 -1
  149. package/dist/tokens/derive.js +16 -1
  150. package/dist/tokens/palette.d.ts +4 -0
  151. package/dist/tokens/palette.d.ts.map +1 -1
  152. package/dist/tokens/palette.js +4 -0
  153. package/dist/tokens/status-text.d.ts.map +1 -1
  154. package/dist/tokens/status-text.js +3 -1
  155. package/llms.txt +38 -20
  156. package/package.json +1 -1
  157. package/src/charts/BandStrip.tsx +33 -3
  158. package/src/charts/Bars.tsx +6 -0
  159. package/src/charts/CartesianChart.tsx +16 -3
  160. package/src/charts/ChartCard.tsx +34 -6
  161. package/src/charts/DualPanel.tsx +3 -6
  162. package/src/charts/Heatmap.tsx +54 -5
  163. package/src/charts/Lines.tsx +56 -10
  164. package/src/charts/MirroredBars.tsx +3 -5
  165. package/src/charts/Sparkline.tsx +50 -13
  166. package/src/charts/StackedArea.tsx +14 -4
  167. package/src/charts/band-fold.ts +31 -1
  168. package/src/charts/chart-box.module.css +19 -0
  169. package/src/charts/chart-card.module.css +25 -0
  170. package/src/charts/chart-legend.module.css +7 -0
  171. package/src/charts/compile.ts +210 -85
  172. package/src/charts/labels.ts +48 -14
  173. package/src/charts/legend.tsx +10 -20
  174. package/src/charts/marks.ts +1 -1
  175. package/src/charts/panel.tsx +1 -16
  176. package/src/charts/ref-label.ts +104 -0
  177. package/src/charts/scales.ts +22 -2
  178. package/src/charts/sparkline.module.css +10 -11
  179. package/src/charts/sparkline.module.css.d.ts +1 -2
  180. package/src/charts/state.tsx +3 -1
  181. package/src/charts/types.ts +14 -5
  182. package/src/cli/doctor-upgrade.ts +1 -1
  183. package/src/cli/init.ts +100 -3
  184. package/src/cli/shot/capture.ts +251 -32
  185. package/src/cli/shot/detect.ts +18 -1
  186. package/src/cli/shot/playwright.ts +2 -2
  187. package/src/cli/shot/types.ts +3 -0
  188. package/src/controls/controls.module.css +11 -1
  189. package/src/controls/filter-pill.tsx +2 -0
  190. package/src/controls/sync-button.module.css +34 -2
  191. package/src/controls/sync-button.module.css.d.ts +1 -0
  192. package/src/controls/sync-button.tsx +40 -4
  193. package/src/dashboard/bar-list.module.css +53 -0
  194. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  195. package/src/dashboard/bar-list.tsx +78 -69
  196. package/src/dashboard/index.ts +1 -0
  197. package/src/dashboard/meter-model.ts +186 -20
  198. package/src/dashboard/meter-parts.tsx +285 -64
  199. package/src/dashboard/meter.module.css +61 -0
  200. package/src/dashboard/meter.module.css.d.ts +5 -0
  201. package/src/dashboard/meter.tsx +60 -10
  202. package/src/dashboard/page-summary.module.css +89 -0
  203. package/src/dashboard/page-summary.module.css.d.ts +15 -0
  204. package/src/dashboard/page-summary.tsx +95 -0
  205. package/src/dashboard/section.module.css +23 -0
  206. package/src/dashboard/section.module.css.d.ts +1 -0
  207. package/src/dashboard/section.tsx +59 -11
  208. package/src/dashboard/stat-card-parts.tsx +5 -1
  209. package/src/dashboard/stat-card.module.css +17 -0
  210. package/src/dashboard/stat-card.tsx +12 -6
  211. package/src/dashboard/stat-strip.module.css +67 -20
  212. package/src/dashboard/stat-strip.module.css.d.ts +4 -0
  213. package/src/dashboard/stat-strip.tsx +118 -72
  214. package/src/dashboard/visual-slot.ts +12 -3
  215. package/src/guard/vx-names.ts +2 -0
  216. package/src/index.ts +2 -0
  217. package/src/styles.css +34 -2
  218. package/src/theme/__snapshots__/plain-theme.test.ts.snap +186 -60
  219. package/src/theme/chrome-vars.ts +77 -8
  220. package/src/theme/controls.module.css +23 -0
  221. package/src/theme/controls.module.css.d.ts +1 -0
  222. package/src/theme/index.ts +12 -25
  223. package/src/tokens/core.ts +4 -1
  224. package/src/tokens/derive.ts +32 -3
  225. package/src/tokens/palette.ts +4 -0
  226. package/src/tokens/status-text.ts +2 -0
@@ -5,11 +5,26 @@
5
5
  import type { ReactNode } from 'react'
6
6
  import { clamp01, toPct } from './scale'
7
7
 
8
- export type MeterSegment = { value: number; label: string; color?: string; forecast?: boolean }
8
+ export type MeterSegment = {
9
+ value: number
10
+ label: string
11
+ color?: string
12
+ /**
13
+ * `'muted'`: the part takes a step of the muted ramp (a lightness step per muted part). A `color`
14
+ * wins. Steps stay ≥15 points apart up to five muted parts; more merge at the cap.
15
+ */
16
+ tone?: 'muted'
17
+ forecast?: boolean
18
+ }
9
19
  export type MeterZone = {
10
20
  from: number
11
21
  to: number
12
22
  label: string
23
+ /**
24
+ * `'muted'`: the band takes its step of the muted ramp instead of the line ramp. A `color` wins.
25
+ * Steps stay ≥15 points apart up to six zones; more merge at the cap.
26
+ */
27
+ tone?: 'muted'
13
28
  /**
14
29
  * A shorter name for a narrow track. The row tries `label`, then `short`, and only then hides the
15
30
  * name; the holding zone always shows its full `label`. The described-by text keeps `label`.
@@ -20,6 +35,40 @@ export type MeterZone = {
20
35
  /** A mark on the track at `at` (in the reading's units). A label is captioned beside it. */
21
36
  export type MeterTick = { at: number; label?: string }
22
37
 
38
+ /** A colour of a `stops` gradient at `at` (in the reading's units); the colour is the consumer's. */
39
+ type MeterStop = { at: number; color: string }
40
+
41
+ /** A ramp step's strength in percent of its neutral: from `lo`, spread over `step` across the steps. */
42
+ export const RAMP_ZONE = { lo: 15, step: 45, solo: 40 }
43
+ export const RAMP_PART = { lo: 35, step: 50, solo: 60 }
44
+ /** Neighbouring steps stay at least this far apart (the contrast the zone ramp always had), up to `RAMP_MAX`. */
45
+ export const RAMP_MIN_STEP = 15
46
+ export const RAMP_MAX = 95
47
+
48
+ /**
49
+ * Step `index` of `count`. The spread is floored at `RAMP_MIN_STEP` per step, so a ramp stays
50
+ * distinguishable by lightness up to six zones (five segments); past that the last steps clamp at
51
+ * `RAMP_MAX` and merge, which is the cue to group parts.
52
+ */
53
+ export function rampStrength(index: number, count: number, ramp: typeof RAMP_ZONE): number {
54
+ if (count <= 1) return ramp.solo
55
+ return Math.min(RAMP_MAX, ramp.lo + index * Math.max(RAMP_MIN_STEP, ramp.step / (count - 1)))
56
+ }
57
+
58
+ function rampFill(
59
+ base: 'line' | 'muted',
60
+ index: number,
61
+ count: number,
62
+ ramp: typeof RAMP_ZONE,
63
+ ): string {
64
+ return `color-mix(in srgb, var(--vx-${base}) ${rampStrength(index, count, ramp)}%, transparent)`
65
+ }
66
+
67
+ /** A zone's fill: its own colour, else its step of the line (or, `tone="muted"`, the muted) ramp. */
68
+ export function zoneFill(zone: MeterZone, index: number, count: number): string {
69
+ return zone.color ?? rampFill(zone.tone === 'muted' ? 'muted' : 'line', index, count, RAMP_ZONE)
70
+ }
71
+
23
72
  /** One tick on the track: its percent position and what it says (caption `label`, aria `text`). */
24
73
  export type TickMark = { key: string; pct: number; label: string | undefined; text: string }
25
74
 
@@ -35,7 +84,14 @@ export type Part = {
35
84
  }
36
85
 
37
86
  /** One categorical part's caption: its position key, name, formatted amount and fill colour (`undefined` = neutral). */
38
- export type PartCaption = { key: string; label: string; text: string; color: string | undefined }
87
+ export type PartCaption = {
88
+ key: string
89
+ label: string
90
+ text: string
91
+ color: string | undefined
92
+ /** Where the part starts on the track, in percent: the caption sits under it when they all fit. */
93
+ startPct: number
94
+ }
39
95
 
40
96
  /** One zone's name on the label row: its span's centre and width (percent) and whether it holds the reading. */
41
97
  export type ZoneLabel = {
@@ -81,6 +137,36 @@ export function tickMarks(
81
137
  )
82
138
  }
83
139
 
140
+ /** A `stops` gradient's colour list, in order along the track; `at` outside `[min, max]` clamps. */
141
+ export function stopsGradient(stops: readonly MeterStop[], min: number, span: number): string {
142
+ return stops
143
+ .toSorted((a, b) => a.at - b.at)
144
+ .map((s) => `${s.color} ${toPct(clamp01((s.at - min) / span))}%`)
145
+ .join(', ')
146
+ }
147
+
148
+ const ringAngle = (pct: number) => Math.round(pct * 3.6 * 100) / 100
149
+
150
+ /** A ring's marks (target, ticks): the angle clockwise from the top, and the accessible text. */
151
+ export function ringMarks(
152
+ target: number | undefined,
153
+ ticks: readonly MeterTick[] | undefined,
154
+ min: number,
155
+ max: number,
156
+ format: Format,
157
+ ): { angle: number; text: string }[] {
158
+ const { span } = spanOf(min, max)
159
+ const marks = tickMarks(ticks, min, max, format).map((t) => ({
160
+ angle: ringAngle(t.pct),
161
+ text: t.text,
162
+ }))
163
+ if (target === undefined || !Number.isFinite(target) || target < min || target > max) return marks
164
+ return [
165
+ { angle: ringAngle(toPct((target - min) / span)), text: `Target ${format(target)}` },
166
+ ...marks,
167
+ ]
168
+ }
169
+
84
170
  export const isReading = (n: number | null | undefined): n is number =>
85
171
  typeof n === 'number' && Number.isFinite(n)
86
172
 
@@ -110,6 +196,9 @@ export function normalizeSegments(segments: readonly MeterSegment[]): MeterSegme
110
196
  /** Segment amounts (already normalised) accumulate from `min`; a part never passes the track end. */
111
197
  export function layoutSegments(segments: readonly MeterSegment[], span: number): Part[] {
112
198
  let cursor = 0
199
+ const isMuted = (s: MeterSegment) => s.tone === 'muted' && s.color === undefined && !s.forecast
200
+ const mutedCount = segments.filter(isMuted).length
201
+ let muted = 0
113
202
  return segments.map((s) => {
114
203
  const size = Math.max(0, Math.min(clamp01(s.value / span), 1 - cursor))
115
204
  const forecast = s.forecast === true
@@ -117,7 +206,11 @@ export function layoutSegments(segments: readonly MeterSegment[], span: number):
117
206
  const part = {
118
207
  start: cursor,
119
208
  size,
120
- color: forecast ? undefined : s.color,
209
+ color: forecast
210
+ ? undefined
211
+ : isMuted(s)
212
+ ? rampFill('muted', muted++, mutedCount, RAMP_PART)
213
+ : s.color,
121
214
  forecast,
122
215
  label: s.label,
123
216
  amount: s.value,
@@ -143,7 +236,14 @@ export type LabelBox = { left: number; right: number }
143
236
  * A label on the shared row: its measured box and, for a zone name, the span it must stay inside.
144
237
  * The holding zone's name never hides for width: it ignores its span and is shifted into the row.
145
238
  */
146
- export type RowLabel = { box: LabelBox; span?: LabelBox; holding?: boolean; short?: LabelBox }
239
+ export type RowLabel = {
240
+ box: LabelBox
241
+ span?: LabelBox
242
+ holding?: boolean
243
+ /** A tick at the track's start or end: it yields to every zone name it would touch. */
244
+ end?: boolean
245
+ short?: LabelBox
246
+ }
147
247
 
148
248
  /** The placement of the row's labels, index-aligned with the input. */
149
249
  export type RowPlacement = {
@@ -157,33 +257,44 @@ export type RowPlacement = {
157
257
  /**
158
258
  * Which labels of the row show, in input order. The holding zone's name claims its place first (it
159
259
  * is the reading's verdict, so it never hides for width: it may spill past its span, shifted inside
160
- * the row); the labels without a span (the end ticks) go next; every other zone name then shows only
260
+ * the row); the other ticks go next; every other zone name then shows only
161
261
  * when it lies inside the row and its own span and clears every label already kept, trying its full
162
- * name and then its `short` box. A hidden name is still named in the described-by text.
262
+ * name and then its `short` box; the end ticks (at the track's start or end) go last, so they yield
263
+ * to any name they would touch. A tick keeps at least `gap` px (one gap step of the host's
264
+ * spacing) from every other label; zone names among themselves only must not touch. A hidden name is still named in the described-by text.
163
265
  */
164
- export function placeRowLabels(labels: readonly RowLabel[], rowWidth: number): RowPlacement {
266
+ export function placeRowLabels(
267
+ labels: readonly RowLabel[],
268
+ rowWidth: number,
269
+ gap = 0,
270
+ ): RowPlacement {
165
271
  const shown = labels.map(() => false)
166
272
  const short = labels.map(() => false)
167
273
  const shift = labels.map(() => 0)
168
- const kept: LabelBox[] = []
169
- const rank = (l: RowLabel) => (l.holding ? 0 : l.span ? 2 : 1)
274
+ const kept: { box: LabelBox; tick: boolean }[] = []
275
+ const rank = (l: RowLabel) => (l.holding ? 0 : l.end ? 3 : l.span ? 2 : 1)
170
276
  const order = labels
171
277
  .map((_, i) => i)
172
278
  .toSorted((a, b) => rank(labels[a] as RowLabel) - rank(labels[b] as RowLabel))
173
- const clears = (b: LabelBox) =>
174
- !kept.some((k) => b.left < k.right - LABEL_SUBPIXEL && k.left < b.right - LABEL_SUBPIXEL)
279
+ // The gap step applies when either label of a pair is a tick; zone names keep to "not touching".
280
+ const clears = (b: LabelBox, tick: boolean) =>
281
+ !kept.some(({ box: k, tick: kTick }) => {
282
+ const pad = tick || kTick ? gap : 0
283
+ return b.left < k.right + pad - LABEL_SUBPIXEL && k.left < b.right + pad - LABEL_SUBPIXEL
284
+ })
175
285
  for (const i of order) {
176
286
  const label = labels[i] as RowLabel
177
287
  const { span } = label
288
+ const tick = span === undefined && !label.holding
178
289
  let box = label.box
179
290
  if (label.holding) {
180
291
  const width = box.right - box.left
181
292
  const left = Math.max(0, Math.min(box.left, rowWidth - width))
182
293
  shift[i] = left - box.left
183
294
  box = { left, right: left + width }
184
- if (!clears(box)) continue
295
+ if (!clears(box, false)) continue
185
296
  shown[i] = true
186
- kept.push(box)
297
+ kept.push({ box, tick: false })
187
298
  continue
188
299
  }
189
300
  const fits = (b: LabelBox) =>
@@ -191,13 +302,13 @@ export function placeRowLabels(labels: readonly RowLabel[], rowWidth: number): R
191
302
  b.right <= rowWidth + LABEL_SUBPIXEL &&
192
303
  (span === undefined ||
193
304
  (b.left >= span.left - LABEL_SUBPIXEL && b.right <= span.right + LABEL_SUBPIXEL)) &&
194
- clears(b)
305
+ clears(b, tick)
195
306
  const useShort = !fits(box) && label.short !== undefined && fits(label.short)
196
307
  if (useShort) box = label.short as LabelBox
197
308
  else if (!fits(box)) continue
198
309
  shown[i] = true
199
310
  short[i] = useShort
200
- kept.push(box)
311
+ kept.push({ box, tick })
201
312
  }
202
313
  return { shown, short, shift }
203
314
  }
@@ -219,6 +330,7 @@ export type BarInput = {
219
330
  format: Format
220
331
  segments?: readonly MeterSegment[] | undefined
221
332
  zones?: readonly MeterZone[] | undefined
333
+ stops?: readonly MeterStop[] | undefined
222
334
  target?: number | undefined
223
335
  ticks?: readonly MeterTick[] | undefined
224
336
  color?: string | undefined
@@ -235,6 +347,8 @@ export type BarModel = {
235
347
  captionMode: CaptionMode
236
348
  /** Only in `parts` mode: one caption per part, in order. Empty otherwise. */
237
349
  partCaptions: readonly PartCaption[]
350
+ /** The `stops` gradient's colour list; absent without `stops`. */
351
+ stopsCss: string | undefined
238
352
  /** Only on a zoned track: every zone's name, in zone order. Empty otherwise. */
239
353
  zoneLabels: readonly ZoneLabel[]
240
354
  ticks: readonly TickMark[]
@@ -252,8 +366,8 @@ function endCaptionText(reading: number, target: number | undefined, format: For
252
366
  return `Target ${format(target)}`
253
367
  }
254
368
 
255
- function fillParts(input: BarInput, span: number, zoned: boolean): Part[] {
256
- if (zoned) return []
369
+ function fillParts(input: BarInput, span: number, marked: boolean): Part[] {
370
+ if (marked) return []
257
371
  if (input.segments !== undefined) return layoutSegments(input.segments, span)
258
372
  const fill = { value: input.reading - input.min, label: '' }
259
373
  return layoutSegments([input.color === undefined ? fill : { ...fill, color: input.color }], span)
@@ -270,6 +384,7 @@ function partCaptionsOf(parts: readonly Part[], format: Format): PartCaption[] {
270
384
  label: p.label,
271
385
  text: format(p.amount),
272
386
  color: p.color,
387
+ startPct: toPct(p.start),
273
388
  }))
274
389
  }
275
390
 
@@ -294,13 +409,14 @@ export function startCaptionText(model: BarModel, override: ReactNode | undefine
294
409
  }
295
410
 
296
411
  export function modelBar(input: BarInput): BarModel {
297
- const { reading, min, max, format, segments, zones, target } = input
412
+ const { reading, min, max, format, segments, zones, target, stops } = input
298
413
  const ticks = tickMarks(input.ticks, min, max, format)
299
414
  const { span } = spanOf(min, max)
300
415
  const zoned = zones !== undefined && zones.length > 0
301
416
  const holding = zoned ? findHoldingZone(zones, reading) : undefined
302
417
 
303
- const parts = fillParts(input, span, zoned)
418
+ const striped = !zoned && stops !== undefined && stops.length > 0
419
+ const parts = fillParts(input, span, zoned || striped)
304
420
  const firstForecast = parts.findIndex((p) => p.forecast)
305
421
  const forecastLabels =
306
422
  segments?.filter((s) => s.forecast === true).map((s) => `${s.label} ${format(s.value)}`) ?? []
@@ -333,6 +449,7 @@ export function modelBar(input: BarInput): BarModel {
333
449
  : (input.forecastCaption ?? `Forecast: ${forecastLabels.join(', ')}`),
334
450
  captionMode,
335
451
  partCaptions,
452
+ stopsCss: striped ? stopsGradient(stops, min, span) : undefined,
336
453
  zoneLabels: !zoned
337
454
  ? []
338
455
  : zones.map((z, i) => {
@@ -347,7 +464,7 @@ export function modelBar(input: BarInput): BarModel {
347
464
  }
348
465
  }),
349
466
  ticks,
350
- markerPct: zoned ? toPct((reading - min) / span) : undefined,
467
+ markerPct: zoned || striped ? toPct((reading - min) / span) : undefined,
351
468
  targetPct: target === undefined ? undefined : toPct((target - min) / span),
352
469
  startText: format(reading),
353
470
  endText: endCaptionText(reading, target, format),
@@ -358,3 +475,52 @@ export function modelBar(input: BarInput): BarModel {
358
475
  /** The ring's one arc, as a fraction of the circumference. */
359
476
  export const ringFraction = (reading: number, min: number, max: number): number =>
360
477
  clamp01((reading - min) / spanOf(min, max).span)
478
+
479
+ /** One caption on the marks row: its natural width and where it is anchored (`pct`), else its edge. */
480
+ export type MarkItem = { width: number; pct?: number; edge?: 'end' }
481
+
482
+ /**
483
+ * Where each caption of the marks row starts (px, logical start edge), index-aligned with `items`: an
484
+ * anchored caption is centred on its mark and clamped inside the row, the others sit at the start (or,
485
+ * `edge: 'end'`, the end). `null` when nothing is anchored, the row is unmeasured, a caption is wider
486
+ * than the row, or two captions would sit closer than `gap`: the row then flows and wraps instead.
487
+ */
488
+ export function placeMarkCaptions(
489
+ items: readonly MarkItem[],
490
+ rowWidth: number,
491
+ gap: number,
492
+ ): number[] | null {
493
+ if (rowWidth <= 0 || !items.some((i) => i.pct !== undefined)) return null
494
+ if (items.some((i) => i.width > rowWidth)) return null
495
+ const lefts = items.map((i) => {
496
+ if (i.pct === undefined) return i.edge === 'end' ? rowWidth - i.width : 0
497
+ return Math.max(0, Math.min((rowWidth * i.pct) / 100 - i.width / 2, rowWidth - i.width))
498
+ })
499
+ const order = lefts.map((_, i) => i).toSorted((a, b) => (lefts[a] ?? 0) - (lefts[b] ?? 0))
500
+ const crowded = order.some((i, n) => {
501
+ const next = order[n + 1]
502
+ return (
503
+ next !== undefined &&
504
+ (lefts[next] ?? 0) < (lefts[i] ?? 0) + (items[i]?.width ?? 0) + gap - LABEL_SUBPIXEL
505
+ )
506
+ })
507
+ return crowded ? null : lefts
508
+ }
509
+
510
+ /**
511
+ * Whether every categorical part's caption fits under its own segment: left-aligned at the part's
512
+ * start and ending before the next part's start (less `gap`) or the row's end. A zero-width part never fits.
513
+ */
514
+ export function partsFitUnder(
515
+ parts: readonly { startPct: number; width: number }[],
516
+ rowWidth: number,
517
+ gap: number,
518
+ ): boolean {
519
+ if (rowWidth <= 0) return false
520
+ return parts.every((p, i) => {
521
+ const left = (rowWidth * p.startPct) / 100
522
+ const next = parts[i + 1]
523
+ const limit = next === undefined ? rowWidth : (rowWidth * next.startPct) / 100 - gap
524
+ return left + p.width <= limit + LABEL_SUBPIXEL
525
+ })
526
+ }