basalt-ui 2.21.0 → 2.23.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 (254) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/MIGRATING.md +452 -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 +73 -3
  10. package/dist/charts/Bars.d.ts.map +1 -1
  11. package/dist/charts/Bars.js +6 -0
  12. package/dist/charts/CartesianChart.d.ts +10 -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 +39 -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 +14 -2
  29. package/dist/charts/Sparkline.d.ts.map +1 -1
  30. package/dist/charts/Sparkline.js +101 -22
  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 +38 -1
  35. package/dist/charts/band-fold.d.ts.map +1 -1
  36. package/dist/charts/band-fold.js +18 -1
  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-dates.d.ts +12 -0
  40. package/dist/charts/chart-dates.d.ts.map +1 -0
  41. package/dist/charts/chart-dates.js +16 -0
  42. package/dist/charts/chart-legend.module.css +7 -0
  43. package/dist/charts/compile.d.ts +25 -6
  44. package/dist/charts/compile.d.ts.map +1 -1
  45. package/dist/charts/compile.js +152 -72
  46. package/dist/charts/date-tick-format.d.ts +5 -5
  47. package/dist/charts/date-tick-format.d.ts.map +1 -1
  48. package/dist/charts/date-tick-format.js +3 -7
  49. package/dist/charts/labels.d.ts +21 -6
  50. package/dist/charts/labels.d.ts.map +1 -1
  51. package/dist/charts/labels.js +52 -17
  52. package/dist/charts/legend.d.ts +2 -0
  53. package/dist/charts/legend.d.ts.map +1 -1
  54. package/dist/charts/legend.js +7 -21
  55. package/dist/charts/marks.js +1 -1
  56. package/dist/charts/panel.d.ts +0 -6
  57. package/dist/charts/panel.d.ts.map +1 -1
  58. package/dist/charts/panel.js +1 -10
  59. package/dist/charts/ref-label.d.ts +43 -0
  60. package/dist/charts/ref-label.d.ts.map +1 -0
  61. package/dist/charts/ref-label.js +75 -0
  62. package/dist/charts/scales.d.ts +4 -1
  63. package/dist/charts/scales.d.ts.map +1 -1
  64. package/dist/charts/scales.js +14 -3
  65. package/dist/charts/sparkline.module.css +13 -17
  66. package/dist/charts/sparkline.module.css.d.ts +1 -2
  67. package/dist/charts/state.d.ts +2 -0
  68. package/dist/charts/state.d.ts.map +1 -1
  69. package/dist/charts/state.js +5 -2
  70. package/dist/charts/types.d.ts +18 -8
  71. package/dist/charts/types.d.ts.map +1 -1
  72. package/dist/cli/doctor-upgrade.d.ts +1 -0
  73. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  74. package/dist/cli/doctor-upgrade.js +1 -0
  75. package/dist/cli/init.d.ts +2 -0
  76. package/dist/cli/init.d.ts.map +1 -1
  77. package/dist/cli/init.js +68 -4
  78. package/dist/cli/shot/capture.d.ts +21 -2
  79. package/dist/cli/shot/capture.d.ts.map +1 -1
  80. package/dist/cli/shot/capture.js +202 -36
  81. package/dist/cli/shot/detect.d.ts.map +1 -1
  82. package/dist/cli/shot/detect.js +17 -1
  83. package/dist/cli/shot/playwright.d.ts +13 -2
  84. package/dist/cli/shot/playwright.d.ts.map +1 -1
  85. package/dist/cli/shot/playwright.js +5 -1
  86. package/dist/cli/shot/types.d.ts +4 -0
  87. package/dist/cli/shot/types.d.ts.map +1 -1
  88. package/dist/cli/shot/types.js +2 -0
  89. package/dist/cli/tokens-css.d.ts +5 -7
  90. package/dist/cli/tokens-css.d.ts.map +1 -1
  91. package/dist/cli/tokens-css.js +11 -12
  92. package/dist/controls/controls.module.css +11 -1
  93. package/dist/controls/filter-pill.d.ts.map +1 -1
  94. package/dist/controls/filter-pill.js +1 -0
  95. package/dist/controls/sync-button.d.ts.map +1 -1
  96. package/dist/controls/sync-button.js +22 -3
  97. package/dist/controls/sync-button.module.css +34 -2
  98. package/dist/controls/sync-button.module.css.d.ts +1 -0
  99. package/dist/dashboard/bar-list.d.ts +6 -1
  100. package/dist/dashboard/bar-list.d.ts.map +1 -1
  101. package/dist/dashboard/bar-list.js +15 -8
  102. package/dist/dashboard/bar-list.module.css +83 -0
  103. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  104. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  105. package/dist/dashboard/delta-badge.js +2 -2
  106. package/dist/dashboard/index.d.ts +1 -0
  107. package/dist/dashboard/index.d.ts.map +1 -1
  108. package/dist/dashboard/index.js +2 -0
  109. package/dist/dashboard/meter-model.d.ts +84 -5
  110. package/dist/dashboard/meter-model.d.ts.map +1 -1
  111. package/dist/dashboard/meter-model.js +100 -15
  112. package/dist/dashboard/meter-parts.d.ts +9 -1
  113. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  114. package/dist/dashboard/meter-parts.js +276 -74
  115. package/dist/dashboard/meter.d.ts +54 -65
  116. package/dist/dashboard/meter.d.ts.map +1 -1
  117. package/dist/dashboard/meter.js +21 -4
  118. package/dist/dashboard/meter.module.css +76 -0
  119. package/dist/dashboard/meter.module.css.d.ts +6 -0
  120. package/dist/dashboard/page-summary.d.ts +20 -0
  121. package/dist/dashboard/page-summary.d.ts.map +1 -0
  122. package/dist/dashboard/page-summary.js +28 -0
  123. package/dist/dashboard/page-summary.module.css +89 -0
  124. package/dist/dashboard/page-summary.module.css.d.ts +15 -0
  125. package/dist/dashboard/query-state.d.ts.map +1 -1
  126. package/dist/dashboard/query-state.js +1 -1
  127. package/dist/dashboard/section.d.ts +25 -2
  128. package/dist/dashboard/section.d.ts.map +1 -1
  129. package/dist/dashboard/section.js +10 -5
  130. package/dist/dashboard/section.module.css +23 -0
  131. package/dist/dashboard/section.module.css.d.ts +1 -0
  132. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  133. package/dist/dashboard/stat-card-parts.js +1 -1
  134. package/dist/dashboard/stat-card.d.ts +4 -2
  135. package/dist/dashboard/stat-card.d.ts.map +1 -1
  136. package/dist/dashboard/stat-card.js +7 -5
  137. package/dist/dashboard/stat-card.module.css +36 -0
  138. package/dist/dashboard/stat-group.module.css +7 -0
  139. package/dist/dashboard/stat-strip.d.ts +22 -6
  140. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  141. package/dist/dashboard/stat-strip.js +104 -60
  142. package/dist/dashboard/stat-strip.module.css +122 -53
  143. package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
  144. package/dist/dashboard/visual-slot.d.ts +7 -1
  145. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  146. package/dist/dashboard/visual-slot.js +3 -1
  147. package/dist/guard/index.d.ts.map +1 -1
  148. package/dist/guard/index.js +0 -5
  149. package/dist/guard/vx-names.d.ts.map +1 -1
  150. package/dist/guard/vx-names.js +2 -0
  151. package/dist/index.d.ts +1 -1
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +3 -1
  154. package/dist/styles.css +43 -4
  155. package/dist/theme/chrome-vars.d.ts +20 -5
  156. package/dist/theme/chrome-vars.d.ts.map +1 -1
  157. package/dist/theme/chrome-vars.js +46 -3
  158. package/dist/theme/controls.module.css +37 -0
  159. package/dist/theme/controls.module.css.d.ts +2 -0
  160. package/dist/theme/index.d.ts.map +1 -1
  161. package/dist/theme/index.js +18 -27
  162. package/dist/theme/status-verdict.d.ts.map +1 -1
  163. package/dist/theme/status-verdict.js +9 -1
  164. package/dist/tokens/core.d.ts +2 -1
  165. package/dist/tokens/core.d.ts.map +1 -1
  166. package/dist/tokens/core.js +6 -1
  167. package/dist/tokens/derive.d.ts +3 -1
  168. package/dist/tokens/derive.d.ts.map +1 -1
  169. package/dist/tokens/derive.js +16 -1
  170. package/dist/tokens/palette.d.ts +11 -10
  171. package/dist/tokens/palette.d.ts.map +1 -1
  172. package/dist/tokens/palette.js +11 -10
  173. package/dist/tokens/status-text.d.ts.map +1 -1
  174. package/dist/tokens/status-text.js +3 -1
  175. package/llms.txt +42 -22
  176. package/package.json +1 -1
  177. package/src/charts/BandStrip.tsx +83 -3
  178. package/src/charts/Bars.tsx +7 -0
  179. package/src/charts/CartesianChart.tsx +18 -3
  180. package/src/charts/ChartCard.tsx +54 -13
  181. package/src/charts/DualPanel.tsx +3 -6
  182. package/src/charts/Heatmap.tsx +54 -5
  183. package/src/charts/Lines.tsx +56 -10
  184. package/src/charts/MirroredBars.tsx +3 -5
  185. package/src/charts/Sparkline.tsx +135 -25
  186. package/src/charts/StackedArea.tsx +14 -4
  187. package/src/charts/band-fold.ts +50 -1
  188. package/src/charts/chart-box.module.css +19 -0
  189. package/src/charts/chart-card.module.css +25 -0
  190. package/src/charts/chart-dates.ts +30 -0
  191. package/src/charts/chart-legend.module.css +7 -0
  192. package/src/charts/compile.ts +253 -87
  193. package/src/charts/date-tick-format.ts +10 -13
  194. package/src/charts/labels.ts +81 -26
  195. package/src/charts/legend.tsx +10 -20
  196. package/src/charts/marks.ts +1 -1
  197. package/src/charts/panel.tsx +1 -16
  198. package/src/charts/ref-label.ts +131 -0
  199. package/src/charts/scales.ts +22 -2
  200. package/src/charts/sparkline.module.css +13 -17
  201. package/src/charts/sparkline.module.css.d.ts +1 -2
  202. package/src/charts/state.tsx +9 -4
  203. package/src/charts/types.ts +18 -8
  204. package/src/cli/doctor-upgrade.ts +1 -1
  205. package/src/cli/init.ts +100 -3
  206. package/src/cli/shot/capture.ts +266 -35
  207. package/src/cli/shot/detect.ts +18 -1
  208. package/src/cli/shot/playwright.ts +20 -4
  209. package/src/cli/shot/types.ts +5 -0
  210. package/src/cli/tokens-css.ts +18 -20
  211. package/src/controls/controls.module.css +11 -1
  212. package/src/controls/filter-pill.tsx +2 -0
  213. package/src/controls/sync-button.module.css +34 -2
  214. package/src/controls/sync-button.module.css.d.ts +1 -0
  215. package/src/controls/sync-button.tsx +40 -4
  216. package/src/dashboard/bar-list.module.css +83 -0
  217. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  218. package/src/dashboard/bar-list.tsx +107 -69
  219. package/src/dashboard/delta-badge.tsx +6 -2
  220. package/src/dashboard/index.ts +1 -0
  221. package/src/dashboard/meter-model.ts +207 -24
  222. package/src/dashboard/meter-parts.tsx +349 -67
  223. package/src/dashboard/meter.module.css +76 -0
  224. package/src/dashboard/meter.module.css.d.ts +6 -0
  225. package/src/dashboard/meter.tsx +72 -18
  226. package/src/dashboard/page-summary.module.css +89 -0
  227. package/src/dashboard/page-summary.module.css.d.ts +15 -0
  228. package/src/dashboard/page-summary.tsx +95 -0
  229. package/src/dashboard/query-state.tsx +1 -1
  230. package/src/dashboard/section.module.css +23 -0
  231. package/src/dashboard/section.module.css.d.ts +1 -0
  232. package/src/dashboard/section.tsx +59 -11
  233. package/src/dashboard/stat-card-parts.tsx +5 -1
  234. package/src/dashboard/stat-card.module.css +36 -0
  235. package/src/dashboard/stat-card.tsx +12 -6
  236. package/src/dashboard/stat-group.module.css +7 -0
  237. package/src/dashboard/stat-strip.module.css +122 -53
  238. package/src/dashboard/stat-strip.module.css.d.ts +4 -0
  239. package/src/dashboard/stat-strip.tsx +176 -91
  240. package/src/dashboard/visual-slot.ts +12 -3
  241. package/src/guard/index.ts +0 -5
  242. package/src/guard/vx-names.ts +2 -0
  243. package/src/index.ts +2 -0
  244. package/src/styles.css +43 -4
  245. package/src/theme/__snapshots__/plain-theme.test.ts.snap +200 -68
  246. package/src/theme/chrome-vars.ts +77 -8
  247. package/src/theme/controls.module.css +37 -0
  248. package/src/theme/controls.module.css.d.ts +2 -0
  249. package/src/theme/index.ts +22 -32
  250. package/src/theme/status-verdict.tsx +5 -1
  251. package/src/tokens/core.ts +4 -1
  252. package/src/tokens/derive.ts +32 -3
  253. package/src/tokens/palette.ts +11 -10
  254. package/src/tokens/status-text.ts +2 -0
@@ -7,16 +7,22 @@ import { cx } from '../common/props'
7
7
  import {
8
8
  ariaValues,
9
9
  modelBar,
10
+ partsFitUnder,
11
+ placeMarkCaptions,
12
+ placeRowLabels,
10
13
  ringFraction,
14
+ ringMarks,
11
15
  startCaptionText,
12
- placeRowLabels,
13
16
  zoneBand,
17
+ zoneFill,
14
18
  } from './meter-model'
15
19
  import type {
20
+ MarkItem,
16
21
  MeterSegment,
17
22
  MeterTick,
18
23
  MeterZone,
19
24
  Part,
25
+ PartCaption,
20
26
  RowLabel,
21
27
  TickMark,
22
28
  ZoneLabel,
@@ -50,8 +56,20 @@ const RING_RADIUS = (RING_VIEWBOX - RING_STROKE) / 2
50
56
  const RING_LENGTH = 2 * Math.PI * RING_RADIUS
51
57
  const RING_CENTER = RING_VIEWBOX / 2
52
58
 
59
+ /** A ring tick spans from just inside the stroke's inner edge to just inside the box. */
60
+ const RING_TICK_INNER = RING_RADIUS - RING_STROKE / 2 - 0.75
61
+ const RING_TICK_OUTER = RING_VIEWBOX / 2 - 0.5
62
+
53
63
  /** The one ring drawing: a track and, when there is a reading, its arc (a fraction of the circle). */
54
- function RingSvg({ fraction, color }: { fraction?: number; color?: string | undefined }) {
64
+ function RingSvg({
65
+ fraction,
66
+ color,
67
+ marks = [],
68
+ }: {
69
+ fraction?: number
70
+ color?: string | undefined
71
+ marks?: readonly { angle: number }[]
72
+ }) {
55
73
  return (
56
74
  <svg className={classes.ring} viewBox={`0 0 ${RING_VIEWBOX} ${RING_VIEWBOX}`} aria-hidden>
57
75
  <circle
@@ -72,6 +90,22 @@ function RingSvg({ fraction, color }: { fraction?: number; color?: string | unde
72
90
  {...(color !== undefined && { style: { stroke: color } })}
73
91
  />
74
92
  )}
93
+ {marks.map((m, i) => (
94
+ // The svg is rotated so 0° is the top: a horizontal line at the rim, turned `angle` clockwise.
95
+ <g key={i} data-meter-ring-tick="">
96
+ {[classes.ringTickHalo, classes.ringTick].map((cls, n) => (
97
+ <line
98
+ key={n}
99
+ className={cls}
100
+ x1={RING_CENTER + RING_TICK_INNER}
101
+ x2={RING_CENTER + RING_TICK_OUTER}
102
+ y1={RING_CENTER}
103
+ y2={RING_CENTER}
104
+ transform={`rotate(${m.angle} ${RING_CENTER} ${RING_CENTER})`}
105
+ />
106
+ ))}
107
+ </g>
108
+ ))}
75
109
  </svg>
76
110
  )
77
111
  }
@@ -116,20 +150,32 @@ export function MeterLoading({
116
150
  )
117
151
  }
118
152
 
119
- export function MeterEmpty(props: { label: string; text: string; ring: boolean; shell: Shell }) {
153
+ const EMPTY_READING = '—'
154
+
155
+ export function MeterEmpty(props: {
156
+ label: string
157
+ text: string | undefined
158
+ ring: boolean
159
+ shell: Shell
160
+ }) {
120
161
  const { label, text, ring, shell } = props
162
+ // The ring has a reading slot (its centre), so the dash sits there as the reading; a bar prints
163
+ // its reading in the caption row, so the dash is that row's muted line. A `text` is the caption.
121
164
  return (
122
165
  <output {...rootProps(shell)} aria-label={label}>
123
166
  {ring ? (
124
167
  <span className={classes.ringBox}>
125
168
  <RingSvg />
169
+ <span className={classes.ringValue}>{EMPTY_READING}</span>
126
170
  </span>
127
171
  ) : (
128
172
  <div className={classes.trackBox}>
129
173
  <div className={classes.track} data-meter-track />
130
174
  </div>
131
175
  )}
132
- <span className={classes.empty}>{text}</span>
176
+ {(!ring || text !== undefined) && (
177
+ <span className={classes.empty}>{text ?? EMPTY_READING}</span>
178
+ )}
133
179
  </output>
134
180
  )
135
181
  }
@@ -140,20 +186,30 @@ export function MeterRing(props: {
140
186
  min: number
141
187
  max: number
142
188
  color: string | undefined
189
+ target: number | undefined
190
+ ticks: readonly MeterTick[] | undefined
143
191
  format: (value: number) => string
144
192
  shell: Shell
145
193
  }) {
146
194
  const { label, reading, min, max, color, format, shell } = props
195
+ const describedId = useId()
196
+ const marks = ringMarks(props.target, props.ticks, min, max, format)
147
197
  return (
148
198
  <div {...rootProps(shell)}>
149
199
  <span
150
200
  className={classes.ringBox}
151
201
  aria-label={label}
152
202
  {...ariaValues(reading, min, max, format)}
203
+ {...(marks.length > 0 && { 'aria-describedby': describedId })}
153
204
  >
154
- <RingSvg fraction={ringFraction(reading, min, max)} color={color} />
205
+ <RingSvg fraction={ringFraction(reading, min, max)} color={color} marks={marks} />
155
206
  <span className={classes.ringValue}>{format(reading)}</span>
156
207
  </span>
208
+ {marks.length > 0 && (
209
+ <VisuallyHidden id={describedId} className={classes.summary}>
210
+ {marks.map((m) => m.text).join('; ')}
211
+ </VisuallyHidden>
212
+ )}
157
213
  </div>
158
214
  )
159
215
  }
@@ -162,27 +218,24 @@ function fillStyle(p: Part): CSSProperties {
162
218
  return { width: `${toPct(p.size)}%`, ...(p.color !== undefined && { background: p.color }) }
163
219
  }
164
220
 
165
- /** Uncoloured zones step from `MIN` to `MIN + STEP` percent of the neutral, so order reads without hue. */
166
- const ZONE_STRENGTH_MIN = 15
167
- const ZONE_STRENGTH_STEP = 45
168
- const ZONE_STRENGTH_SOLO = 40
169
221
  /** Every band after the first gives up its leading pixel, so a boundary never relies on fill strength. */
170
222
  const ZONE_GAP = '1px'
171
223
 
172
224
  function zoneStyle(zone: MeterZone, index: number, count: number, min: number, span: number) {
173
225
  const band = zoneBand(zone, min, span)
174
226
  const gap = index > 0
175
- const strength =
176
- count > 1 ? ZONE_STRENGTH_MIN + (index / (count - 1)) * ZONE_STRENGTH_STEP : ZONE_STRENGTH_SOLO
177
227
  return {
178
228
  insetInlineStart: gap ? `calc(${band.start}% + ${ZONE_GAP})` : `${band.start}%`,
179
229
  width: gap ? `calc(${band.width}% - ${ZONE_GAP})` : `${band.width}%`,
180
- background: zone.color ?? `color-mix(in srgb, var(--vx-line) ${strength}%, transparent)`,
230
+ background: zoneFill(zone, index, count),
181
231
  } satisfies CSSProperties
182
232
  }
183
233
 
234
+ /** The row's `column-gap` in px: one gap step of the host's spacing, the least two captions keep apart. */
235
+ const columnGapOf = (el: Element): number => Number.parseFloat(getComputedStyle(el).columnGap) || 0
236
+
184
237
  /** One label on the row: its span in percent of the row (a zone name) or none (an end tick). */
185
- type RowSlot = { spanPct?: readonly [number, number]; holding?: boolean }
238
+ type RowSlot = { spanPct?: readonly [number, number]; holding?: boolean; end?: boolean }
186
239
 
187
240
  type RowLayout = { shown: boolean[]; short: boolean[]; shift: number[] }
188
241
  const sameLayout = (a: RowLayout, b: RowLayout) =>
@@ -232,6 +285,7 @@ function useRowLabelLayout(
232
285
  ...(a !== undefined &&
233
286
  b !== undefined && { span: { left: Math.min(a, b), right: Math.max(a, b) } }),
234
287
  ...(slot?.holding && { holding: true }),
288
+ ...(slot?.end && { end: true }),
235
289
  }
236
290
  })
237
291
  shortOfRef.current.forEach((labelIndex, n) => {
@@ -239,7 +293,7 @@ function useRowLabelLayout(
239
293
  const label = labels[labelIndex]
240
294
  if (r && label) label.short = { left: r.left - origin.left, right: r.right - origin.left }
241
295
  })
242
- const placed = placeRowLabels(labels, origin.width)
296
+ const placed = placeRowLabels(labels, origin.width, columnGapOf(row))
243
297
  // The hook measures on the physical x axis; the margin is logical, so it flips with `dir`.
244
298
  const next = {
245
299
  shown: placed.shown,
@@ -321,7 +375,7 @@ const TICK_LABEL_FLIP_PCT = 50
321
375
  function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readonly TickMark[] }) {
322
376
  const rowRef = useRef<HTMLDivElement>(null)
323
377
  const slots: RowSlot[] = [
324
- ...ticks.map((): RowSlot => ({})),
378
+ ...ticks.map((t): RowSlot => (t.pct <= 0 || t.pct >= 100 ? { end: true } : {})),
325
379
  ...zones.map((z): RowSlot => ({
326
380
  spanPct: [z.centrePct - z.widthPct / 2, z.centrePct + z.widthPct / 2],
327
381
  holding: z.holding,
@@ -395,6 +449,162 @@ function LabelRow({ zones, ticks }: { zones: readonly ZoneLabel[]; ticks: readon
395
449
  )
396
450
  }
397
451
 
452
+ /** One caption of the marks row, in flow order: its anchor (`pct`, or the row's `edge`) when it has one. */
453
+ type CaptionItem = { key: string; node: ReactNode; pct?: number; edge?: 'end'; end?: boolean }
454
+
455
+ /** The measurement shared by the marks row and the part list: natural widths, row width, gap step. */
456
+ function measureItems(row: HTMLElement) {
457
+ const kids = [...row.children] as HTMLElement[]
458
+ const widths = kids.map((kid) => {
459
+ // In the flow a caption may shrink and wrap inside itself; its anchored width is its one-line one.
460
+ const { whiteSpace, flex } = kid.style
461
+ kid.style.whiteSpace = 'nowrap'
462
+ kid.style.flex = 'none'
463
+ const width = kid.offsetWidth
464
+ kid.style.whiteSpace = whiteSpace
465
+ kid.style.flex = flex
466
+ return width
467
+ })
468
+ return { widths, rowWidth: row.clientWidth, gap: columnGapOf(row) }
469
+ }
470
+
471
+ /**
472
+ * Runs `measure` when `key` (what the row says) changes, when the row resizes and when web fonts
473
+ * load (a swap changes widths without resizing the row). Without layout (server markup, happy-dom)
474
+ * nothing is measured and the row keeps its flow.
475
+ */
476
+ function useMeasured(
477
+ rowRef: RefObject<HTMLElement | null>,
478
+ measure: (row: HTMLElement) => void,
479
+ key: string,
480
+ ) {
481
+ const measureRef = useRef(measure)
482
+ // Declared first so the effect below reads this render's closure.
483
+ useIsomorphicLayoutEffect(() => {
484
+ measureRef.current = measure
485
+ })
486
+ useIsomorphicLayoutEffect(() => {
487
+ const row = rowRef.current
488
+ if (!row) return
489
+ const run = () => measureRef.current(row)
490
+ run()
491
+ const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(run)
492
+ observer?.observe(row)
493
+ // A caption's own size changes with its content, whatever it is (a ReactNode has no string key).
494
+ for (const kid of row.children) observer?.observe(kid)
495
+ const fonts =
496
+ typeof document === 'undefined' ? undefined : (document.fonts as FontFaceSet | undefined)
497
+ fonts?.addEventListener?.('loadingdone', run)
498
+ return () => {
499
+ observer?.disconnect()
500
+ fonts?.removeEventListener?.('loadingdone', run)
501
+ }
502
+ }, [rowRef, key])
503
+ }
504
+
505
+ const sameStarts = (a: number[] | null, b: number[] | null) =>
506
+ a === b || (a !== null && b !== null && a.length === b.length && a.every((v, i) => v === b[i]))
507
+
508
+ /**
509
+ * The captions under the track. A caption that names a mark (the forecast boundary, the target) sits
510
+ * AT that mark, centred and clamped inside the track, when every caption fits with a gap step between
511
+ * them; otherwise (and in server markup) the row flows and wraps: start, forecast, end.
512
+ */
513
+ function CaptionRow({ items }: { items: readonly CaptionItem[] }) {
514
+ const rowRef = useRef<HTMLDivElement>(null)
515
+ const [starts, setStarts] = useState<number[] | null>(null)
516
+ useMeasured(
517
+ rowRef,
518
+ (row) => {
519
+ const { widths, rowWidth, gap } = measureItems(row)
520
+ const marks: MarkItem[] = items.map((item, i) => ({
521
+ width: widths[i] ?? 0,
522
+ ...(item.pct !== undefined && { pct: item.pct }),
523
+ ...(item.edge !== undefined && { edge: item.edge }),
524
+ }))
525
+ const next = placeMarkCaptions(marks, rowWidth, gap)
526
+ setStarts((prev) => (sameStarts(prev, next) ? prev : next))
527
+ },
528
+ items
529
+ .map((i) => `${i.key}@${i.pct ?? i.edge ?? ''}:${typeof i.node === 'string' ? i.node : ''}`)
530
+ .join('\u0000'),
531
+ )
532
+ return (
533
+ <div
534
+ ref={rowRef}
535
+ className={cx(classes.captions, starts !== null && classes.captionsAnchored)}
536
+ data-meter-captions
537
+ data-anchored={starts === null ? undefined : ''}
538
+ >
539
+ {items.map((item, i) => (
540
+ <span
541
+ key={item.key}
542
+ className={item.end ? classes.captionEnd : classes.caption}
543
+ {...(starts?.[i] !== undefined && { style: { insetInlineStart: `${starts[i]}px` } })}
544
+ >
545
+ {item.node}
546
+ </span>
547
+ ))}
548
+ </div>
549
+ )
550
+ }
551
+
552
+ /**
553
+ * Categorical part captions (swatch, name, value): each under its own segment when every one fits
554
+ * there on one line, else a wrapping row of entries from the track's start. An entry stays on one
555
+ * line unless it is wider than the row itself.
556
+ */
557
+ function PartCaptions({ captions }: { captions: readonly PartCaption[] }) {
558
+ const rowRef = useRef<HTMLUListElement>(null)
559
+ const [under, setUnder] = useState(false)
560
+ const [overwide, setOverwide] = useState(false)
561
+ useMeasured(
562
+ rowRef,
563
+ (row) => {
564
+ const { widths, rowWidth, gap } = measureItems(row)
565
+ setOverwide(widths.some((w) => w > rowWidth))
566
+ const fits = partsFitUnder(
567
+ captions.map((c, i) => ({ startPct: c.startPct, width: widths[i] ?? 0 })),
568
+ rowWidth,
569
+ gap,
570
+ )
571
+ setUnder(fits)
572
+ },
573
+ captions.map((c) => `${c.label} ${c.text}@${c.startPct}`).join('\u0000'),
574
+ )
575
+ return (
576
+ <ul
577
+ ref={rowRef}
578
+ className={cx(
579
+ classes.partCaptions,
580
+ under && classes.partCaptionsUnder,
581
+ overwide && classes.partCaptionsWrap,
582
+ )}
583
+ // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
584
+ // oxlint-disable-next-line jsx-a11y/no-redundant-roles
585
+ role="list"
586
+ data-meter-parts
587
+ data-anchored={under ? '' : undefined}
588
+ >
589
+ {captions.map((c) => (
590
+ <li
591
+ key={c.key}
592
+ className={classes.partCaption}
593
+ {...(under && { style: { insetInlineStart: `${c.startPct}%` } })}
594
+ >
595
+ <span
596
+ className={classes.swatch}
597
+ // theme-allow hidden-inline-style — the swatch repeats the part's fill colour (data)
598
+ style={{ background: c.color ?? 'var(--vx-line)' }}
599
+ aria-hidden
600
+ />
601
+ {glueUnits(`${c.label} ${c.text}`)}
602
+ </li>
603
+ ))}
604
+ </ul>
605
+ )
606
+ }
607
+
398
608
  export function MeterBar(props: {
399
609
  label: string
400
610
  reading: number
@@ -404,6 +614,9 @@ export function MeterBar(props: {
404
614
  color: string | undefined
405
615
  segments: readonly MeterSegment[] | undefined
406
616
  zones: readonly MeterZone[] | undefined
617
+ stops: readonly { at: number; color: string }[] | undefined
618
+ track: boolean | undefined
619
+ markerReading: boolean | undefined
407
620
  target: number | undefined
408
621
  ticks: readonly MeterTick[] | undefined
409
622
  tone: 'muted' | undefined
@@ -412,28 +625,106 @@ export function MeterBar(props: {
412
625
  endCaption: ReactNode
413
626
  shell: Shell
414
627
  }) {
415
- const { label, reading, min, max, format, zones, shell } = props
628
+ const { label, min, max, format, zones, shell } = props
416
629
  const describedId = useId()
417
630
  const model = modelBar(props)
418
631
  const compact = shell.row
632
+ const hosted = useContext(VisualSlotContext) !== null
419
633
  // A host that already shows the value as its hero (StatCard, a strip cell) owns the reading: a
420
- // zoned track keeps its marker and zone labels but does not print the number a second time. A
421
- // consumer's own `startCaption` is not the reading and still renders.
422
- const hosted =
423
- useContext(VisualSlotContext) &&
424
- model.markerPct !== undefined &&
425
- props.startCaption === undefined
426
- const start = compact || hosted ? null : startCaptionText(model, props.startCaption)
427
- const end = compact ? null : props.endCaption === undefined ? model.endText : props.endCaption
428
- const anchored = model.markerPct !== undefined && start !== null
429
- const hasCaptions =
430
- (start !== null && !anchored) || end !== null || (!compact && model.forecastText !== null)
431
- const hasParts = !compact && model.partCaptions.length > 0
432
- const tickLabels = compact ? [] : model.ticks.filter((t) => t.label !== undefined)
634
+ // marked track keeps its marker and labels but does not print the number a second time, and a
635
+ // stops track prints it only on request. `reading` overrides either way. A consumer's own
636
+ // `startCaption` is not the reading and still renders.
637
+ const marked = model.markerPct !== undefined
638
+ const readingOn = props.markerReading ?? (model.zoneLabels.length > 0 && !hosted)
639
+ const start =
640
+ compact || (marked && !readingOn && props.startCaption === undefined)
641
+ ? null
642
+ : startCaptionText(model, props.startCaption)
643
+ const anchored = marked && start !== null
644
+ const trackHidden =
645
+ props.track === false &&
646
+ model.parts.length === 1 &&
647
+ props.segments === undefined &&
648
+ props.target === undefined &&
649
+ model.ticks.length === 0
650
+ const hasParts = model.partCaptions.length > 0
651
+ // A scale's start figure: a Meter with marks or a target labels where its track begins, with its
652
+ // `format`, unless the consumer opted out (`startCaption={null}`) or already labelled that end.
653
+ const zoned = zones !== undefined && zones.length > 0
654
+ const labelled = model.ticks.filter((t) => t.label !== undefined)
655
+ const startFigure =
656
+ !compact &&
657
+ !zoned &&
658
+ props.startCaption !== null &&
659
+ (model.ticks.length > 0 || model.targetPct !== undefined) &&
660
+ !labelled.some((t) => t.pct <= 0)
661
+ const tickLabels: TickMark[] = compact
662
+ ? []
663
+ : [
664
+ ...(startFigure
665
+ ? [
666
+ {
667
+ key: 'start',
668
+ pct: 0,
669
+ label: format(min),
670
+ caption: undefined,
671
+ text: '',
672
+ } satisfies TickMark,
673
+ ]
674
+ : []),
675
+ ...labelled,
676
+ ]
433
677
  const zoneLabels = compact ? [] : model.zoneLabels
434
678
  const describedBy =
435
679
  model.describedByText === null ? {} : ({ 'aria-describedby': describedId } as const)
436
680
 
681
+ // The caption row, in flow order. The target's caption sits at its tick unless the consumer
682
+ // supplied an end caption (theirs goes at the end, as written).
683
+ const endOverride = props.endCaption !== undefined
684
+ const targetHere = !endOverride && model.targetPct !== undefined && model.endText !== null
685
+ const end = compact ? null : endOverride ? props.endCaption : model.endText
686
+ const items: CaptionItem[] = compact
687
+ ? []
688
+ : [
689
+ ...(start !== null && !anchored
690
+ ? [{ key: 'start', node: glue(start) } satisfies CaptionItem]
691
+ : []),
692
+ ...(model.forecastText !== null
693
+ ? [
694
+ {
695
+ key: 'forecast',
696
+ node: glue(model.forecastText),
697
+ ...(model.boundaryPct !== undefined && { pct: model.boundaryPct }),
698
+ } satisfies CaptionItem,
699
+ ]
700
+ : []),
701
+ ...(compact
702
+ ? []
703
+ : model.ticks.flatMap((t) =>
704
+ t.caption === undefined
705
+ ? []
706
+ : [
707
+ {
708
+ key: `tick${t.key}`,
709
+ node: glue(t.caption),
710
+ pct: t.pct,
711
+ } satisfies CaptionItem,
712
+ ],
713
+ )),
714
+ ...(end !== null
715
+ ? [
716
+ {
717
+ key: 'end',
718
+ node: glue(end),
719
+ end: true,
720
+ ...(targetHere && model.targetPct !== undefined
721
+ ? { pct: model.targetPct }
722
+ : { edge: 'end' as const }),
723
+ } satisfies CaptionItem,
724
+ ]
725
+ : []),
726
+ ]
727
+
437
728
  const root = rootProps(shell)
438
729
  return (
439
730
  <div {...root} className={root.className}>
@@ -441,26 +732,41 @@ export function MeterBar(props: {
441
732
  <LabelRow zones={zoneLabels} ticks={tickLabels} />
442
733
  )}
443
734
  <div
444
- className={classes.trackBox}
735
+ className={cx(classes.trackBox, trackHidden && classes.trackHidden)}
736
+ data-meter-track-hidden={trackHidden ? '' : undefined}
445
737
  aria-label={label}
446
- {...ariaValues(reading, min, max, format)}
738
+ {...ariaValues(props.reading, min, max, format)}
447
739
  {...describedBy}
448
740
  >
449
- <div className={classes.track} data-meter-track>
450
- {model.markerPct !== undefined &&
451
- zones?.map((z, i) => (
452
- <div
453
- key={i}
454
- className={classes.zone}
455
- data-meter-zone={z.label}
456
- style={zoneStyle(z, i, zones.length, min, model.span)}
457
- />
458
- ))}
741
+ <div
742
+ className={classes.track}
743
+ data-meter-track
744
+ {...(model.stopsCss !== undefined && {
745
+ 'data-meter-stops': '',
746
+ // theme-allow hidden-inline-style — the gradient is the consumer's colour data
747
+ style: { '--basalt-stops': model.stopsCss } as CSSProperties,
748
+ })}
749
+ >
750
+ {zones?.map(
751
+ (z, i) =>
752
+ model.markerPct !== undefined && (
753
+ <div
754
+ key={i}
755
+ className={classes.zone}
756
+ data-meter-zone={z.label}
757
+ {...(i > 0 &&
758
+ zones[i - 1]?.tone === 'muted' &&
759
+ z.tone === 'muted' && { 'data-meter-zone-seam': '' })}
760
+ style={zoneStyle(z, i, zones.length, min, model.span)}
761
+ />
762
+ ),
763
+ )}
459
764
  {model.parts.map((p, i) => (
460
765
  <div
461
766
  key={i}
462
767
  className={cx(classes.fill, p.forecast && classes.forecastFill)}
463
768
  data-meter-fill={p.forecast ? 'forecast' : 'committed'}
769
+ {...(p.seam && { 'data-meter-seam': '' })}
464
770
  data-tone={
465
771
  props.tone === 'muted' && p.color === undefined && !p.forecast ? 'muted' : undefined
466
772
  }
@@ -482,32 +788,8 @@ export function MeterBar(props: {
482
788
  {model.describedByText}
483
789
  </VisuallyHidden>
484
790
  )}
485
- {hasParts && (
486
- // The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
487
- // oxlint-disable-next-line jsx-a11y/no-redundant-roles
488
- <ul className={classes.partCaptions} role="list" data-meter-parts>
489
- {model.partCaptions.map((c) => (
490
- <li key={c.key} className={classes.partCaption}>
491
- <span
492
- className={classes.swatch}
493
- // theme-allow hidden-inline-style — the swatch repeats the part's fill colour (data)
494
- style={{ background: c.color ?? 'var(--vx-line)' }}
495
- aria-hidden
496
- />
497
- {glueUnits(`${c.label} ${c.text}`)}
498
- </li>
499
- ))}
500
- </ul>
501
- )}
502
- {hasCaptions && (
503
- <div className={classes.captions} data-meter-captions>
504
- {start !== null && !anchored && <span className={classes.caption}>{glue(start)}</span>}
505
- {!compact && model.forecastText !== null && (
506
- <span className={classes.caption}>{glue(model.forecastText)}</span>
507
- )}
508
- {end !== null && <span className={classes.captionEnd}>{glue(end)}</span>}
509
- </div>
510
- )}
791
+ {hasParts && <PartCaptions captions={model.partCaptions} />}
792
+ {items.length > 0 && <CaptionRow items={items} />}
511
793
  </div>
512
794
  )
513
795
  }
@@ -28,6 +28,26 @@
28
28
  position: relative;
29
29
  }
30
30
 
31
+ /* A `stops` track is one gradient through the consumer's colours; the reading is a marker on it. */
32
+ .track[data-meter-stops] {
33
+ background: linear-gradient(var(--basalt-stop-dir, to right), var(--basalt-stops));
34
+ }
35
+
36
+ .trackBox:dir(rtl) {
37
+ --basalt-stop-dir: to left;
38
+ }
39
+
40
+ /* `track={false}`: no drawn track, still in the accessibility tree (the role and value stay). */
41
+ .trackHidden {
42
+ position: absolute;
43
+ width: 1px;
44
+ height: 1px;
45
+ margin: -1px;
46
+ overflow: hidden;
47
+ clip-path: inset(50%);
48
+ white-space: nowrap;
49
+ }
50
+
31
51
  .fill {
32
52
  flex: none;
33
53
  height: 100%;
@@ -42,6 +62,12 @@
42
62
  background: color-mix(in srgb, var(--vx-muted) 65%, transparent);
43
63
  }
44
64
 
65
+ /* Muted parts share one flat fill: a track-coloured hairline at the shared edge tells them apart. */
66
+ .fill[data-meter-seam] {
67
+ box-sizing: border-box;
68
+ border-inline-start: 1px solid var(--vx-surface-subtle);
69
+ }
70
+
45
71
  /* The committed/forecast pair: the same neutral at two strengths. Flat, never hatched. */
46
72
  .forecastFill {
47
73
  background: color-mix(in srgb, var(--vx-line) 45%, transparent);
@@ -63,6 +89,8 @@
63
89
  /* A hidden name keeps its box (so it can be measured again) and may sit past the row's end. */
64
90
  overflow-x: clip;
65
91
  height: 1.25em;
92
+ /* Read by the layout: the least two captions keep apart (one gap step). */
93
+ column-gap: var(--vx-space-control-gap, 0.375rem);
66
94
  font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
67
95
  font-variant-numeric: lining-nums;
68
96
  font-size: var(--basalt-meter-caption);
@@ -164,6 +192,20 @@
164
192
  color: var(--vx-muted);
165
193
  }
166
194
 
195
+ /* Captions at their marks: each is placed (inline `inset-inline-start`) by the measured layout. */
196
+ .captionsAnchored {
197
+ position: relative;
198
+ display: block;
199
+ height: 1lh;
200
+ }
201
+
202
+ .captionsAnchored > * {
203
+ position: absolute;
204
+ top: 0;
205
+ margin: 0;
206
+ white-space: nowrap;
207
+ }
208
+
167
209
  /* Captions never truncate: the row wraps, and a caption wider than the row wraps inside itself. */
168
210
  .caption {
169
211
  min-width: 0;
@@ -199,14 +241,37 @@
199
241
  color: var(--vx-muted);
200
242
  }
201
243
 
244
+ /* An entry is one line: swatch, name and value never break apart; the row wraps between entries. */
202
245
  .partCaption {
203
246
  display: inline-flex;
247
+ flex: none;
204
248
  align-items: baseline;
205
249
  gap: var(--vx-space-control-gap, 0.375rem);
250
+ white-space: nowrap;
251
+ }
252
+
253
+ /* Only an entry wider than the whole row may break (measured), so nothing overflows the card. */
254
+ .partCaptionsWrap > .partCaption {
255
+ flex: 0 1 auto;
206
256
  min-width: 0;
257
+ white-space: normal;
207
258
  overflow-wrap: anywhere;
208
259
  }
209
260
 
261
+ /* Every part's caption fits under its own segment: the list is positioned, not wrapped. */
262
+ .partCaptionsUnder {
263
+ position: relative;
264
+ display: block;
265
+ height: 1lh;
266
+ }
267
+
268
+ /* Under its segment a caption is one line by construction: it was measured to fit as one. */
269
+ .partCaptionsUnder > .partCaption {
270
+ position: absolute;
271
+ top: 0;
272
+ white-space: nowrap;
273
+ }
274
+
210
275
  /* A shape cue beside the name, so the part never reads by colour alone. */
211
276
  .swatch {
212
277
  flex: none;
@@ -265,6 +330,17 @@
265
330
  stroke: var(--vx-line);
266
331
  }
267
332
 
333
+ /* A ring tick: an ink mark with a track-coloured halo, so it reads over the arc and the track. */
334
+ .ringTick {
335
+ stroke: var(--vx-ink);
336
+ stroke-width: 1.5;
337
+ }
338
+
339
+ .ringTickHalo {
340
+ stroke: var(--vx-surface-subtle);
341
+ stroke-width: 3;
342
+ }
343
+
268
344
  .ringValue {
269
345
  position: relative;
270
346
  font-family: var(--basalt-font-numeral, var(--basalt-font-sans));