basalt-ui 2.20.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 (289) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/MIGRATING.md +394 -12
  3. package/agent/agents/basalt-design-reviewer.md +22 -5
  4. package/agent/rules/basalt-tokens.md +3 -3
  5. package/agent/skills/basalt-design/SKILL.md +10 -23
  6. package/agent/skills/basalt-design/references/anti-defaults.md +24 -0
  7. package/agent/skills/basalt-design/references/catalogue.md +49 -0
  8. package/agent/skills/basalt-design/references/concept.md +36 -0
  9. package/agent/skills/basalt-design/references/encoding-rules.md +45 -0
  10. package/agent/skills/basalt-design/references/stat-tile.md +24 -0
  11. package/agent/templates/AGENTS-block.md.tpl +3 -3
  12. package/configs/oxlint-plugin.js +1 -0
  13. package/dist/charts/BandStrip.d.ts.map +1 -1
  14. package/dist/charts/BandStrip.js +27 -3
  15. package/dist/charts/Bars.d.ts.map +1 -1
  16. package/dist/charts/Bars.js +5 -0
  17. package/dist/charts/CartesianChart.d.ts +8 -0
  18. package/dist/charts/CartesianChart.d.ts.map +1 -1
  19. package/dist/charts/CartesianChart.js +8 -5
  20. package/dist/charts/ChartCard.d.ts +17 -4
  21. package/dist/charts/ChartCard.d.ts.map +1 -1
  22. package/dist/charts/ChartCard.js +33 -8
  23. package/dist/charts/DualPanel.d.ts.map +1 -1
  24. package/dist/charts/DualPanel.js +5 -8
  25. package/dist/charts/Heatmap.d.ts +12 -1
  26. package/dist/charts/Heatmap.d.ts.map +1 -1
  27. package/dist/charts/Heatmap.js +34 -5
  28. package/dist/charts/Lines.d.ts +3 -0
  29. package/dist/charts/Lines.d.ts.map +1 -1
  30. package/dist/charts/Lines.js +29 -6
  31. package/dist/charts/MirroredBars.d.ts.map +1 -1
  32. package/dist/charts/MirroredBars.js +4 -6
  33. package/dist/charts/Sparkline.d.ts +7 -1
  34. package/dist/charts/Sparkline.d.ts.map +1 -1
  35. package/dist/charts/Sparkline.js +39 -14
  36. package/dist/charts/StackedArea.d.ts +4 -1
  37. package/dist/charts/StackedArea.d.ts.map +1 -1
  38. package/dist/charts/StackedArea.js +9 -3
  39. package/dist/charts/band-fold.d.ts +20 -1
  40. package/dist/charts/band-fold.d.ts.map +1 -1
  41. package/dist/charts/band-fold.js +9 -0
  42. package/dist/charts/chart-box.module.css +19 -0
  43. package/dist/charts/chart-card.module.css +25 -0
  44. package/dist/charts/chart-legend.module.css +7 -0
  45. package/dist/charts/compile.d.ts +17 -6
  46. package/dist/charts/compile.d.ts.map +1 -1
  47. package/dist/charts/compile.js +145 -74
  48. package/dist/charts/labels.d.ts +15 -4
  49. package/dist/charts/labels.d.ts.map +1 -1
  50. package/dist/charts/labels.js +34 -10
  51. package/dist/charts/legend.d.ts +2 -0
  52. package/dist/charts/legend.d.ts.map +1 -1
  53. package/dist/charts/legend.js +7 -21
  54. package/dist/charts/marks.js +1 -1
  55. package/dist/charts/panel.d.ts +0 -6
  56. package/dist/charts/panel.d.ts.map +1 -1
  57. package/dist/charts/panel.js +1 -10
  58. package/dist/charts/ref-label.d.ts +26 -0
  59. package/dist/charts/ref-label.d.ts.map +1 -0
  60. package/dist/charts/ref-label.js +63 -0
  61. package/dist/charts/scales.d.ts +4 -1
  62. package/dist/charts/scales.d.ts.map +1 -1
  63. package/dist/charts/scales.js +14 -3
  64. package/dist/charts/sparkline.module.css +10 -11
  65. package/dist/charts/sparkline.module.css.d.ts +1 -2
  66. package/dist/charts/state.d.ts +7 -0
  67. package/dist/charts/state.d.ts.map +1 -1
  68. package/dist/charts/state.js +4 -1
  69. package/dist/charts/types.d.ts +14 -5
  70. package/dist/charts/types.d.ts.map +1 -1
  71. package/dist/cli/check-theme.d.ts.map +1 -1
  72. package/dist/cli/check-theme.js +3 -0
  73. package/dist/cli/doctor-upgrade.d.ts +1 -0
  74. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  75. package/dist/cli/doctor-upgrade.js +1 -0
  76. package/dist/cli/help.d.ts.map +1 -1
  77. package/dist/cli/help.js +3 -2
  78. package/dist/cli/index.d.ts +4 -2
  79. package/dist/cli/index.d.ts.map +1 -1
  80. package/dist/cli/index.js +27 -15
  81. package/dist/cli/init.d.ts +2 -0
  82. package/dist/cli/init.d.ts.map +1 -1
  83. package/dist/cli/init.js +71 -6
  84. package/dist/cli/shot/capture.d.ts +21 -2
  85. package/dist/cli/shot/capture.d.ts.map +1 -1
  86. package/dist/cli/shot/capture.js +200 -33
  87. package/dist/cli/shot/detect.d.ts +51 -0
  88. package/dist/cli/shot/detect.d.ts.map +1 -0
  89. package/dist/cli/shot/detect.js +409 -0
  90. package/dist/cli/shot/index.d.ts.map +1 -1
  91. package/dist/cli/shot/index.js +7 -4
  92. package/dist/cli/shot/measure.d.ts +2 -0
  93. package/dist/cli/shot/measure.d.ts.map +1 -1
  94. package/dist/cli/shot/measure.js +2 -0
  95. package/dist/cli/shot/playwright.d.ts +5 -2
  96. package/dist/cli/shot/playwright.d.ts.map +1 -1
  97. package/dist/cli/shot/types.d.ts +6 -1
  98. package/dist/cli/shot/types.d.ts.map +1 -1
  99. package/dist/cli/shot/types.js +4 -0
  100. package/dist/cli/sync.d.ts +2 -0
  101. package/dist/cli/sync.d.ts.map +1 -1
  102. package/dist/cli/sync.js +2 -2
  103. package/dist/common/retry-button.d.ts +12 -0
  104. package/dist/common/retry-button.d.ts.map +1 -0
  105. package/dist/common/retry-button.js +22 -0
  106. package/dist/common/retry-button.module.css +58 -0
  107. package/dist/common/retry-button.module.css.d.ts +8 -0
  108. package/dist/controls/controls.module.css +11 -1
  109. package/dist/controls/filter-pill.d.ts.map +1 -1
  110. package/dist/controls/filter-pill.js +1 -0
  111. package/dist/controls/sync-button.d.ts.map +1 -1
  112. package/dist/controls/sync-button.js +22 -3
  113. package/dist/controls/sync-button.module.css +34 -2
  114. package/dist/controls/sync-button.module.css.d.ts +1 -0
  115. package/dist/dashboard/bar-list.d.ts +5 -2
  116. package/dist/dashboard/bar-list.d.ts.map +1 -1
  117. package/dist/dashboard/bar-list.js +9 -10
  118. package/dist/dashboard/bar-list.module.css +53 -0
  119. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  120. package/dist/dashboard/index.d.ts +1 -0
  121. package/dist/dashboard/index.d.ts.map +1 -1
  122. package/dist/dashboard/index.js +2 -0
  123. package/dist/dashboard/meter-model.d.ts +108 -6
  124. package/dist/dashboard/meter-model.d.ts.map +1 -1
  125. package/dist/dashboard/meter-model.js +123 -19
  126. package/dist/dashboard/meter-parts.d.ts +8 -0
  127. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  128. package/dist/dashboard/meter-parts.js +345 -146
  129. package/dist/dashboard/meter.d.ts +50 -63
  130. package/dist/dashboard/meter.d.ts.map +1 -1
  131. package/dist/dashboard/meter.js +24 -3
  132. package/dist/dashboard/meter.module.css +79 -65
  133. package/dist/dashboard/meter.module.css.d.ts +7 -7
  134. package/dist/dashboard/page-summary.d.ts +20 -0
  135. package/dist/dashboard/page-summary.d.ts.map +1 -0
  136. package/dist/dashboard/page-summary.js +28 -0
  137. package/dist/dashboard/page-summary.module.css +89 -0
  138. package/dist/dashboard/page-summary.module.css.d.ts +15 -0
  139. package/dist/dashboard/query-state.d.ts +1 -1
  140. package/dist/dashboard/query-state.d.ts.map +1 -1
  141. package/dist/dashboard/query-state.js +3 -2
  142. package/dist/dashboard/section.d.ts +25 -2
  143. package/dist/dashboard/section.d.ts.map +1 -1
  144. package/dist/dashboard/section.js +10 -5
  145. package/dist/dashboard/section.module.css +23 -0
  146. package/dist/dashboard/section.module.css.d.ts +1 -0
  147. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  148. package/dist/dashboard/stat-card-parts.js +1 -1
  149. package/dist/dashboard/stat-card.d.ts +4 -2
  150. package/dist/dashboard/stat-card.d.ts.map +1 -1
  151. package/dist/dashboard/stat-card.js +7 -4
  152. package/dist/dashboard/stat-card.module.css +17 -0
  153. package/dist/dashboard/stat-strip.d.ts +24 -1
  154. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  155. package/dist/dashboard/stat-strip.js +97 -39
  156. package/dist/dashboard/stat-strip.module.css +147 -17
  157. package/dist/dashboard/stat-strip.module.css.d.ts +8 -0
  158. package/dist/dashboard/visual-slot.d.ts +8 -0
  159. package/dist/dashboard/visual-slot.d.ts.map +1 -0
  160. package/dist/dashboard/visual-slot.js +7 -0
  161. package/dist/guard/index.d.ts +15 -2
  162. package/dist/guard/index.d.ts.map +1 -1
  163. package/dist/guard/index.js +14 -0
  164. package/dist/guard/palette.d.ts +51 -0
  165. package/dist/guard/palette.d.ts.map +1 -0
  166. package/dist/guard/palette.js +190 -0
  167. package/dist/guard/series-file.d.ts +15 -0
  168. package/dist/guard/series-file.d.ts.map +1 -0
  169. package/dist/guard/series-file.js +29 -0
  170. package/dist/guard/types.d.ts +3 -3
  171. package/dist/guard/types.d.ts.map +1 -1
  172. package/dist/guard/vx-names.d.ts.map +1 -1
  173. package/dist/guard/vx-names.js +2 -0
  174. package/dist/index.d.ts +1 -1
  175. package/dist/index.d.ts.map +1 -1
  176. package/dist/index.js +3 -1
  177. package/dist/styles.css +34 -2
  178. package/dist/surfaces.d.ts +1 -1
  179. package/dist/surfaces.d.ts.map +1 -1
  180. package/dist/surfaces.js +2 -0
  181. package/dist/theme/chrome-vars.d.ts +20 -5
  182. package/dist/theme/chrome-vars.d.ts.map +1 -1
  183. package/dist/theme/chrome-vars.js +46 -3
  184. package/dist/theme/controls.module.css +33 -0
  185. package/dist/theme/controls.module.css.d.ts +1 -0
  186. package/dist/theme/index.d.ts.map +1 -1
  187. package/dist/theme/index.js +11 -5
  188. package/dist/tokens/core.d.ts +2 -1
  189. package/dist/tokens/core.d.ts.map +1 -1
  190. package/dist/tokens/core.js +6 -1
  191. package/dist/tokens/derive.d.ts +3 -1
  192. package/dist/tokens/derive.d.ts.map +1 -1
  193. package/dist/tokens/derive.js +16 -1
  194. package/dist/tokens/oklab.d.ts +28 -0
  195. package/dist/tokens/oklab.d.ts.map +1 -0
  196. package/dist/tokens/oklab.js +73 -0
  197. package/dist/tokens/palette.d.ts +4 -0
  198. package/dist/tokens/palette.d.ts.map +1 -1
  199. package/dist/tokens/palette.js +4 -0
  200. package/dist/tokens/status-text.d.ts.map +1 -1
  201. package/dist/tokens/status-text.js +3 -1
  202. package/llms.txt +43 -23
  203. package/package.json +1 -1
  204. package/src/charts/BandStrip.tsx +33 -3
  205. package/src/charts/Bars.tsx +6 -0
  206. package/src/charts/CartesianChart.tsx +16 -3
  207. package/src/charts/ChartCard.tsx +43 -7
  208. package/src/charts/DualPanel.tsx +3 -6
  209. package/src/charts/Heatmap.tsx +54 -5
  210. package/src/charts/Lines.tsx +56 -10
  211. package/src/charts/MirroredBars.tsx +3 -5
  212. package/src/charts/Sparkline.tsx +50 -13
  213. package/src/charts/StackedArea.tsx +14 -4
  214. package/src/charts/band-fold.ts +31 -1
  215. package/src/charts/chart-box.module.css +19 -0
  216. package/src/charts/chart-card.module.css +25 -0
  217. package/src/charts/chart-legend.module.css +7 -0
  218. package/src/charts/compile.ts +210 -85
  219. package/src/charts/labels.ts +48 -14
  220. package/src/charts/legend.tsx +10 -20
  221. package/src/charts/marks.ts +1 -1
  222. package/src/charts/panel.tsx +1 -16
  223. package/src/charts/ref-label.ts +104 -0
  224. package/src/charts/scales.ts +22 -2
  225. package/src/charts/sparkline.module.css +10 -11
  226. package/src/charts/sparkline.module.css.d.ts +1 -2
  227. package/src/charts/state.tsx +12 -1
  228. package/src/charts/types.ts +14 -5
  229. package/src/cli/check-theme.ts +3 -0
  230. package/src/cli/doctor-upgrade.ts +1 -1
  231. package/src/cli/help.ts +18 -1
  232. package/src/cli/index.ts +48 -17
  233. package/src/cli/init.ts +102 -4
  234. package/src/cli/shot/capture.ts +266 -34
  235. package/src/cli/shot/detect.ts +550 -0
  236. package/src/cli/shot/index.ts +8 -4
  237. package/src/cli/shot/measure.ts +4 -0
  238. package/src/cli/shot/playwright.ts +2 -2
  239. package/src/cli/shot/types.ts +8 -1
  240. package/src/cli/sync.ts +4 -2
  241. package/src/common/retry-button.module.css +58 -0
  242. package/src/common/retry-button.module.css.d.ts +8 -0
  243. package/src/common/retry-button.tsx +29 -0
  244. package/src/controls/controls.module.css +11 -1
  245. package/src/controls/filter-pill.tsx +2 -0
  246. package/src/controls/sync-button.module.css +34 -2
  247. package/src/controls/sync-button.module.css.d.ts +1 -0
  248. package/src/controls/sync-button.tsx +40 -4
  249. package/src/dashboard/bar-list.module.css +53 -0
  250. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  251. package/src/dashboard/bar-list.tsx +88 -76
  252. package/src/dashboard/index.ts +1 -0
  253. package/src/dashboard/meter-model.ts +265 -28
  254. package/src/dashboard/meter-parts.tsx +424 -163
  255. package/src/dashboard/meter.module.css +79 -65
  256. package/src/dashboard/meter.module.css.d.ts +7 -7
  257. package/src/dashboard/meter.tsx +77 -17
  258. package/src/dashboard/page-summary.module.css +89 -0
  259. package/src/dashboard/page-summary.module.css.d.ts +15 -0
  260. package/src/dashboard/page-summary.tsx +95 -0
  261. package/src/dashboard/query-state.tsx +4 -7
  262. package/src/dashboard/section.module.css +23 -0
  263. package/src/dashboard/section.module.css.d.ts +1 -0
  264. package/src/dashboard/section.tsx +59 -11
  265. package/src/dashboard/stat-card-parts.tsx +5 -1
  266. package/src/dashboard/stat-card.module.css +17 -0
  267. package/src/dashboard/stat-card.tsx +14 -5
  268. package/src/dashboard/stat-strip.module.css +147 -17
  269. package/src/dashboard/stat-strip.module.css.d.ts +8 -0
  270. package/src/dashboard/stat-strip.tsx +182 -56
  271. package/src/dashboard/visual-slot.ts +17 -0
  272. package/src/guard/index.ts +16 -4
  273. package/src/guard/palette.ts +261 -0
  274. package/src/guard/series-file.ts +51 -0
  275. package/src/guard/types.ts +3 -2
  276. package/src/guard/vx-names.ts +2 -0
  277. package/src/index.ts +2 -0
  278. package/src/styles.css +34 -2
  279. package/src/surfaces.ts +2 -0
  280. package/src/theme/__snapshots__/plain-theme.test.ts.snap +220 -60
  281. package/src/theme/chrome-vars.ts +77 -8
  282. package/src/theme/controls.module.css +33 -0
  283. package/src/theme/controls.module.css.d.ts +1 -0
  284. package/src/theme/index.ts +18 -5
  285. package/src/tokens/core.ts +4 -1
  286. package/src/tokens/derive.ts +32 -3
  287. package/src/tokens/oklab.ts +97 -0
  288. package/src/tokens/palette.ts +4 -0
  289. package/src/tokens/status-text.ts +2 -0
@@ -8,6 +8,18 @@
8
8
  * `tone` inks the VALUE only, for a verdict; a null reading is `—`. A cell may carry BOTH: the hero
9
9
  * (e.g. VO2max) with `rows` under it; omit `value` to render the rows alone.
10
10
  *
11
+ * `state` replaces the readings (hero, visual, rows, footer) with the cell's empty or error body, at
12
+ * the cell's size. Empty: `—` in the value position and the reason, muted. Error: the shared error
13
+ * anatomy compact — status dot, the word `Failed`, the message, the shared Retry. The caption stays.
14
+ * A `visual` is a hero host: a zoned `Meter` in it does not repeat the value at its marker.
15
+ *
16
+ * Alignment: cells of one row align by PART (caption, value, hero footer, visual, rows, footer share
17
+ * tracks via subgrid), and each cell spans only down to its last part, so its own box ends at its
18
+ * content. A footer rides with what it captions (under the hero: its own track right below it).
19
+ * The dividers belong to a row-high slot around the cell, so they run the whole row and the area
20
+ * under a short cell is the strip's own surface. `action` sits at the end of the caption line (the
21
+ * caption truncates first); a row with `hideValue` prints its label alone.
22
+ *
11
23
  * Anchors: each cell is `data-shot="strip-<key>"` and each footer cell
12
24
  * `data-shot="strip-footer-<key>"` (derived — a consumer cannot choose another name).
13
25
  *
@@ -18,11 +30,15 @@
18
30
  import { Card, Skeleton } from '@mantine/core'
19
31
  import { useId } from 'react'
20
32
  import type { CSSProperties, ReactNode } from 'react'
33
+ import { toErrorMessage } from '../common/errors'
21
34
  import { cx } from '../common/props'
22
35
  import type { BasaltProps, Tone } from '../common/props'
36
+ import { RetryButton } from '../common/retry-button'
37
+ import { StatusDot } from '../theme/status-dot'
23
38
  import { VX } from '../tokens'
24
39
  import { InfoGlyph } from './widget-header'
25
40
  import classes from './stat-strip.module.css'
41
+ import { HOSTED, VisualSlotContext } from './visual-slot'
26
42
 
27
43
  export type StatStripRow = {
28
44
  key: string
@@ -32,13 +48,36 @@ export type StatStripRow = {
32
48
  visual?: ReactNode
33
49
  /** A `DeltaBadge`. */
34
50
  delta?: ReactNode
51
+ /** The reading is already shown (the hero): print the label alone. `value` is ignored. */
52
+ hideValue?: boolean
35
53
  }
36
54
 
55
+ /** What a cell shows instead of its readings. Mirrors `StatCard`'s `query` branches. */
56
+ type StatStripCellState =
57
+ | {
58
+ kind: 'empty'
59
+ /** Why there is no reading, one muted line (`'No sleep logged'`). */
60
+ reason?: string
61
+ }
62
+ | {
63
+ kind: 'error'
64
+ /** Whatever was thrown; decoded like `ErrorState`'s. */
65
+ error?: unknown
66
+ /** Renders the shared Retry button. */
67
+ onRetry?: () => void
68
+ /** A refetch is in flight: Retry is inert. */
69
+ retrying?: boolean
70
+ }
71
+
37
72
  export type StatStripCell = {
38
73
  key: string
39
74
  caption: string
40
- /** Muted, on the caption line: `CAPTION · qualifier`. */
75
+ /** Muted, on the caption line: `CAPTION · qualifier`. It wraps whole under the caption when it
76
+ * does not fit (by design: no truncation, so no `title`). */
41
77
  qualifier?: string
78
+ /** A control at the end of the caption line (a popover trigger). Never wraps the line: the
79
+ * caption truncates first. */
80
+ action?: ReactNode
42
81
  /** The definition behind the caption, in the info-glyph tooltip. */
43
82
  info?: string
44
83
  /** `null` = no reading, printed as `—`. Omit only when `rows` carries the cell. */
@@ -58,6 +97,8 @@ export type StatStripCell = {
58
97
  loading?: boolean
59
98
  /** Dims the cell while placeholder data shows. */
60
99
  stale?: boolean
100
+ /** Empty or failed: replaces the readings; `loading` wins while pending. */
101
+ state?: StatStripCellState
61
102
  }
62
103
 
63
104
  export type StatStripProps = BasaltProps & {
@@ -72,70 +113,155 @@ export type StatStripProps = BasaltProps & {
72
113
 
73
114
  const EMPTY = '—'
74
115
 
116
+ function CellState({ state }: { state: StatStripCellState }) {
117
+ if (state.kind === 'empty') {
118
+ return (
119
+ <>
120
+ <div className={classes.valueRow}>
121
+ <span className={classes.value} data-strip-value>
122
+ {EMPTY}
123
+ </span>
124
+ </div>
125
+ {state.reason !== undefined && <p className={classes.reason}>{state.reason}</p>}
126
+ </>
127
+ )
128
+ }
129
+ const message = toErrorMessage(state.error, 'The request failed.')
130
+ return (
131
+ <div className={classes.error} role="alert" data-strip-state="error">
132
+ <span className={classes.errorHead}>
133
+ <StatusDot color={VX.status.bad} />
134
+ Failed
135
+ </span>
136
+ <p className={classes.reason}>{message}</p>
137
+ {state.onRetry !== undefined && (
138
+ <RetryButton onClick={state.onRetry} retrying={state.retrying ?? false} />
139
+ )}
140
+ </div>
141
+ )
142
+ }
143
+
144
+ /** The last of the six shared tracks (caption, hero, hero footer, visual, rows, footer) a cell paints into. */
145
+ function lastTrackOf(cell: StatStripCell, state: StatStripCellState | undefined) {
146
+ if (state !== undefined) return state.kind === 'empty' && state.reason !== undefined ? 4 : 2
147
+ if (cell.rows !== undefined)
148
+ return cell.footer !== undefined ? 6 : cell.visual !== undefined ? 5 : 4
149
+ if (cell.visual !== undefined) return 4
150
+ return cell.footer !== undefined ? 3 : 2
151
+ }
152
+
75
153
  function StripCell({ cell }: { cell: StatStripCell }) {
76
154
  const captionId = useId()
77
155
  const { rows, loading } = cell
156
+ const state = loading ? undefined : cell.state
78
157
  const hasHero = cell.value !== undefined || rows === undefined
158
+ // A footer under a visual (and no rows) rides with it, so it hugs that visual instead of dropping
159
+ // to a taller sibling's; under a hero alone it rides with the value; only under rows does it take
160
+ // the row's shared footer track.
161
+ const ownFooter = cell.visual !== undefined && rows === undefined
162
+ const heroFooter = hasHero && cell.visual === undefined && rows === undefined
163
+ // The cell spans the tracks down to its last part, so its box ends at its content (the slot
164
+ // around it still runs the whole row for the dividers).
165
+ // The cell's verdict colours a plain Meter in its visual too (a hero host only).
166
+ const hostSlot = !hasHero ? null : cell.tone === undefined ? HOSTED : { tone: cell.tone }
167
+ const lastTrack = lastTrackOf(cell, state)
168
+ const footerEl = cell.footer !== undefined && (
169
+ <div className={cx(classes.footer, heroFooter && classes.heroFooter)} data-strip-footer>
170
+ {cell.footer}
171
+ </div>
172
+ )
173
+ const heroEl = loading ? (
174
+ <Skeleton className={classes.skeletonValue} radius="sm" />
175
+ ) : (
176
+ <div className={classes.valueRow}>
177
+ <span
178
+ className={classes.value}
179
+ data-strip-value
180
+ style={cell.tone !== undefined ? { color: VX.status[cell.tone] } : undefined}
181
+ >
182
+ {cell.value ?? EMPTY}
183
+ </span>
184
+ {cell.value !== undefined && cell.value !== null && cell.unit !== undefined && (
185
+ <span className={classes.unit}>{cell.unit}</span>
186
+ )}
187
+ {cell.delta}
188
+ </div>
189
+ )
79
190
  return (
80
- <article
81
- className={classes.cell}
82
- data-strip-cell={cell.key}
83
- data-shot={`strip-${cell.key}`}
84
- aria-labelledby={captionId}
85
- {...(cell.stale && { 'data-stale': 'true' })}
86
- >
87
- <div className={classes.captionLine}>
88
- {/* The caption and its info glyph are one unit: the qualifier wraps whole, never between them. */}
89
- <span className={classes.lead}>
90
- <span className={classes.caption} id={captionId} title={cell.caption} data-strip-caption>
91
- {cell.caption}
92
- </span>
93
- {cell.info !== undefined && <InfoGlyph text={cell.info} />}
94
- </span>
95
- {cell.qualifier !== undefined && (
96
- <span className={classes.qualifier}>{cell.qualifier}</span>
97
- )}
98
- </div>
99
- {hasHero &&
100
- (loading ? (
101
- <Skeleton className={classes.skeletonValue} radius="sm" />
102
- ) : (
103
- <div className={classes.valueRow}>
104
- <span
105
- className={classes.value}
106
- data-strip-value
107
- style={cell.tone !== undefined ? { color: VX.status[cell.tone] } : undefined}
108
- >
109
- {cell.value ?? EMPTY}
191
+ // The slot owns the dividers and stretches to the row; the article inside ends at its content.
192
+ <div className={classes.cell} data-strip-slot>
193
+ <article
194
+ className={classes.content}
195
+ style={{ '--basalt-strip-span': lastTrack } as CSSProperties}
196
+ data-strip-cell={cell.key}
197
+ data-shot={`strip-${cell.key}`}
198
+ aria-labelledby={captionId}
199
+ {...(state === undefined && cell.visual !== undefined && { 'data-strip-has-visual': '' })}
200
+ {...(state === undefined && rows !== undefined && { 'data-strip-has-rows': '' })}
201
+ {...(cell.stale && { 'data-stale': 'true' })}
202
+ >
203
+ <div className={classes.captionLine}>
204
+ <div className={classes.captionMain}>
205
+ {/* The caption and its info glyph are one unit: the qualifier wraps whole, never between them. */}
206
+ <span className={classes.lead}>
207
+ <span
208
+ className={classes.caption}
209
+ id={captionId}
210
+ title={cell.caption}
211
+ data-strip-caption
212
+ >
213
+ {cell.caption}
214
+ </span>
215
+ {cell.info !== undefined && <InfoGlyph text={cell.info} />}
110
216
  </span>
111
- {cell.value !== undefined && cell.value !== null && cell.unit !== undefined && (
112
- <span className={classes.unit}>{cell.unit}</span>
217
+ {cell.qualifier !== undefined && (
218
+ <span className={classes.qualifier}>{cell.qualifier}</span>
113
219
  )}
114
- {cell.delta}
115
220
  </div>
116
- ))}
117
- {cell.visual !== undefined && <div className={classes.visual}>{cell.visual}</div>}
118
- {rows !== undefined &&
119
- (loading ? (
120
- <div className={classes.rows} aria-hidden="true">
121
- {rows.map((row) => (
122
- <Skeleton key={row.key} className={classes.skeletonRow} radius="sm" />
123
- ))}
221
+ {cell.action !== undefined && (
222
+ <span className={classes.action} data-strip-action>
223
+ {cell.action}
224
+ </span>
225
+ )}
226
+ </div>
227
+ {state !== undefined && <CellState state={state} />}
228
+ {state === undefined && hasHero && heroEl}
229
+ {state === undefined && heroFooter && footerEl}
230
+ {state === undefined && cell.visual !== undefined && (
231
+ <div className={classes.visualStack}>
232
+ <div className={classes.visual} data-strip-visual>
233
+ <VisualSlotContext.Provider value={hostSlot}>
234
+ {cell.visual}
235
+ </VisualSlotContext.Provider>
236
+ </div>
237
+ {ownFooter && footerEl}
124
238
  </div>
125
- ) : (
126
- <ul className={classes.rows}>
127
- {rows.map((row) => (
128
- <li key={row.key} className={classes.row} data-strip-row={row.key}>
129
- <span className={classes.rowLabel}>{row.label}</span>
130
- <span className={classes.visual}>{row.visual}</span>
131
- <span className={classes.rowValue}>{row.value ?? EMPTY}</span>
132
- <span>{row.delta}</span>
133
- </li>
134
- ))}
135
- </ul>
136
- ))}
137
- {cell.footer !== undefined && <div className={classes.footer}>{cell.footer}</div>}
138
- </article>
239
+ )}
240
+ {state === undefined &&
241
+ rows !== undefined &&
242
+ (loading ? (
243
+ <div className={classes.rows} aria-hidden="true">
244
+ {rows.map((row) => (
245
+ <Skeleton key={row.key} className={classes.skeletonRow} radius="sm" />
246
+ ))}
247
+ </div>
248
+ ) : (
249
+ <ul className={classes.rows} data-strip-rows>
250
+ {rows.map((row) => (
251
+ <li key={row.key} className={classes.row} data-strip-row={row.key}>
252
+ <span className={classes.rowLabel}>{row.label}</span>
253
+ <span className={classes.visual}>{row.visual}</span>
254
+ <span className={classes.rowValue}>
255
+ {row.hideValue ? null : (row.value ?? EMPTY)}
256
+ </span>
257
+ <span>{row.delta}</span>
258
+ </li>
259
+ ))}
260
+ </ul>
261
+ ))}
262
+ {state === undefined && !ownFooter && !heroFooter && footerEl}
263
+ </article>
264
+ </div>
139
265
  )
140
266
  }
141
267
 
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Set by a host that already shows the reading as its hero (a `StatCard` sparkline slot, a strip
3
+ * cell's `visual`). A `Meter` reads it: a zoned track drops the reading it would draw at the marker
4
+ * (the headline is not printed twice; `reading` overrides), and a plain bar or ring with no `tone` or
5
+ * `color` of its own takes the host's `tone` as its verdict colour. Internal: never exported.
6
+ */
7
+ import { createContext } from 'react'
8
+ import type { Tone } from '../common/props'
9
+
10
+ export interface VisualSlot {
11
+ readonly tone?: Tone
12
+ }
13
+
14
+ /** A host with no verdict of its own: one shared object, so a provider never re-renders its readers. */
15
+ export const HOSTED: VisualSlot = {}
16
+
17
+ export const VisualSlotContext = createContext<VisualSlot | null>(null)
@@ -3,7 +3,7 @@
3
3
  * (`tokens/space-scale`, `common/*`), never `tokens/palette` or `derive` (colour math on every
4
4
  * Write/Edit).
5
5
  *
6
- * GUARD_RULES: the closed registry of all 26 violation kinds.
6
+ * GUARD_RULES: the closed registry of all 27 violation kinds.
7
7
  * checkSource: pure (text, relPath, cfg) → Finding[]. No FS, no walk, no console.
8
8
  */
9
9
  import type { Finding, GuardConfig, GuardKind, GuardSeverity } from './types'
@@ -911,10 +911,15 @@ export const GRACE_PERIOD_KINDS: Partial<Record<GuardKind, GraceEntry>> = {
911
911
  promote: '2.24.0',
912
912
  why: 'The scale moved to 8/12/16/20/24 and the CSS micro ceiling dropped 10 → 7 in 2.16.0: a literal 8px/10px in CSS is newly a finding.',
913
913
  },
914
+ 'series-palette': {
915
+ since: '2.21.0',
916
+ promote: '2.23.0',
917
+ why: 'New in 2.21.0: the series file is judged by computed lightness, chroma, colour-blind separation and contrast; a palette that was tuned by eye is newly a finding.',
918
+ },
914
919
  }
915
920
 
916
921
  /** A kind's effective severity: consumer override first, then the grace table, then `error`. */
917
- function severityOf(kind: GuardKind, cfg: GuardConfig): GuardSeverity {
922
+ export function severityOf(kind: GuardKind, cfg: GuardConfig): GuardSeverity {
918
923
  return cfg.severity?.[kind] ?? (Object.hasOwn(GRACE_PERIOD_KINDS, kind) ? 'warn' : 'error')
919
924
  }
920
925
 
@@ -985,7 +990,7 @@ function exemptPatternMatches(pattern: string, relPath: string): boolean {
985
990
  * Whether `kind` is exempted at `relPath` via `cfg.exemptRules` — the config-driven, per-rule
986
991
  * counterpart to `isChartFile`'s hardcoded path scoping.
987
992
  */
988
- function isRuleExempt(
993
+ export function isRuleExempt(
989
994
  kind: GuardKind,
990
995
  relPath: string,
991
996
  exemptRules: GuardConfig['exemptRules'],
@@ -1982,7 +1987,7 @@ type GuardRule = {
1982
1987
  }
1983
1988
 
1984
1989
  /**
1985
- * The closed registry of all 26 guard kinds. The triad test asserts
1990
+ * The closed registry of all 27 guard kinds. The triad test asserts
1986
1991
  * `surface.guardKinds ⊆ keyof GUARD_RULES` at runtime.
1987
1992
  *
1988
1993
  * raw-surface, raw-html-layout, and sub-16-input-font are handled inline in checkSource
@@ -2208,6 +2213,13 @@ export const GUARD_RULES = {
2208
2213
  pattern: VX_VAR_REF, // handled inline (basalt-owned families); entry keeps the registry complete
2209
2214
  message: `var() names a --vx-* token basalt does not emit, so it resolves to its fallback (or to nothing) with no error anywhere. Judged: every name inside a basalt-owned family (${[...BASALT_VX_FAMILY_SET].join(', ')}), plus any name basalt used to emit in any family — pick the token from the stylesheet basalt-ui tokens:css emits; your own series belong in a family of their own (groupTokens throws on one inside basalt's, in dev builds). A removed name is reported with its replacement on the finding line (MIGRATING.md has the table). Any other name outside a basalt family is never judged, because groupTokens may declare it in a file this scan cannot see.`,
2210
2215
  },
2216
+ 'series-palette': {
2217
+ kind: 'series-palette',
2218
+ pattern: /(?!)/, // never matches: judged over the whole series FILE by `series-file.ts`, not per line
2219
+ appliesTo: () => false,
2220
+ message:
2221
+ "The series file's palette fails a computed check (OKLCH lightness band, chroma floor, colour-blind separation of neighbours, worst-pair separation, 3:1 contrast against the surface, ≤ 8 series without a repeat) — retune the hex in the series file; it is judged per scheme, light against the light panel and dark against the dark one. A deliberately neutral series is keyed `other`.",
2222
+ },
2211
2223
  } as const satisfies Record<GuardKind, GuardRule>
2212
2224
 
2213
2225
  /**
@@ -0,0 +1,261 @@
1
+ /**
2
+ * `series-palette` — the series file's palette is computed, never eyeballed.
3
+ *
4
+ * Pure: source text and the two scheme surfaces in, issues out. Reads every
5
+ * `defineSeries({ key: { light, dark } })` call as one ordered categorical group and judges each
6
+ * scheme against its own surface. The surfaces are the CALLER's to supply: this module is on the
7
+ * guard's import graph, which never loads the `derive` engine (see `guard/index.ts`'s header) —
8
+ * `series-file.ts` computes them. Colour math lives in `../tokens/oklab`; contrast is `hct.ts`'s
9
+ * WCAG ratio.
10
+ */
11
+ import { contrastRatio } from '../tokens/hct'
12
+ import { deltaEOk, deltaEOkCvd, hexToOklch } from '../tokens/oklab'
13
+
14
+ export type SeriesScheme = 'light' | 'dark'
15
+ /** The surface each scheme's series are judged against. */
16
+ export type SeriesSurfaces = Record<SeriesScheme, string>
17
+
18
+ export type SeriesCheck =
19
+ | 'format'
20
+ | 'lightness'
21
+ | 'chroma'
22
+ | 'cvd'
23
+ | 'separation'
24
+ | 'contrast'
25
+ | 'order'
26
+
27
+ export type SeriesEntry = {
28
+ readonly key: string
29
+ readonly light: string
30
+ readonly dark: string
31
+ /** 1-based line of the entry in the scanned source. */
32
+ readonly line: number
33
+ }
34
+ export type SeriesGroup = { readonly line: number; readonly entries: readonly SeriesEntry[] }
35
+
36
+ export type SeriesIssue = {
37
+ readonly check: SeriesCheck
38
+ readonly scheme: SeriesScheme
39
+ readonly keys: readonly string[]
40
+ readonly measured: number
41
+ readonly threshold: number
42
+ /** Line of the first named key. */
43
+ readonly line: number
44
+ readonly message: string
45
+ }
46
+
47
+ /**
48
+ * OKLCH lightness bands, per scheme.
49
+ * - light [0.43, 0.77] — the brief's band: below 0.43 a series reads as ink, above 0.77 it washes
50
+ * out on the panel (3:1 bites earlier, near L 0.67, on the default light panel).
51
+ * - dark [0.58, 0.88] — lower bound is where a hue clears 3:1 against the default dark panel
52
+ * (#2b2b2e, L 0.29 → L ≈ 0.56, rounded up for margin); the upper bound keeps a clear step below
53
+ * white so a bright series does not glow against the dark page.
54
+ */
55
+ export const LIGHTNESS_BAND: Record<SeriesScheme, readonly [number, number]> = {
56
+ light: [0.43, 0.77],
57
+ dark: [0.58, 0.88],
58
+ }
59
+ /** Minimum OKLCH chroma of a categorical hue. */
60
+ export const CHROMA_FLOOR = 0.1
61
+ /** Minimum OKLab ΔE×100 between ADJACENT series under protanopia and deuteranopia. */
62
+ export const CVD_ADJACENT_MIN = 8
63
+ /** Minimum OKLab ΔE×100 of the worst pair in a group, normal vision. */
64
+ export const SEPARATION_MIN = 15
65
+ /** Minimum WCAG contrast of a series against its scheme's surface. */
66
+ export const CONTRAST_MIN = 3
67
+ /** More categorical series than this and the next one folds into Other. */
68
+ export const MAX_SERIES = 8
69
+ /** The one escape: a series keyed `other` is deliberately neutral — exempt from the chroma floor only. */
70
+ export const NEUTRAL_KEY = 'other'
71
+
72
+ const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i
73
+
74
+ /** The string literal after `light:` / `dark:`, in either order. */
75
+ const ENTRY =
76
+ /([A-Za-z_$][\w$]*|'[^']+'|"[^"]+")\s*:\s*\{\s*(?:light\s*:\s*(['"])(.*?)\2\s*,\s*dark\s*:\s*(['"])(.*?)\4|dark\s*:\s*(['"])(.*?)\6\s*,\s*light\s*:\s*(['"])(.*?)\8)/g
77
+
78
+ const lineOf = (text: string, at: number): number => text.slice(0, at).split('\n').length
79
+
80
+ /** Every `defineSeries(...)` call in `source`, as an ordered group of its literal `{ light, dark }` hex pairs. */
81
+ export function parseSeriesGroups(source: string): SeriesGroup[] {
82
+ const groups: SeriesGroup[] = []
83
+ for (const call of source.matchAll(/\bdefineSeries\s*\(/g)) {
84
+ const open = (call.index ?? 0) + call[0].length
85
+ const lineStart = source.lastIndexOf('\n', call.index ?? 0) + 1
86
+ if (/^\s*(?:\/\/|\*|\/\*)/.test(source.slice(lineStart, call.index))) continue
87
+ let depth = 1
88
+ let end = open
89
+ while (end < source.length && depth > 0) {
90
+ const ch = source[end]
91
+ if (ch === '(') depth += 1
92
+ else if (ch === ')') depth -= 1
93
+ end += 1
94
+ }
95
+ const body = source.slice(open, end)
96
+ const entries = [...body.matchAll(ENTRY)].map((m): SeriesEntry => {
97
+ const light = m[3] ?? m[9] ?? ''
98
+ const dark = m[5] ?? m[7] ?? ''
99
+ return {
100
+ key: (m[1] ?? '').replace(/^['"]|['"]$/g, ''),
101
+ light: light.trim(),
102
+ dark: dark.trim(),
103
+ line: lineOf(source, open + (m.index ?? 0)),
104
+ }
105
+ })
106
+ groups.push({ line: lineOf(source, call.index ?? 0), entries })
107
+ }
108
+ return groups
109
+ }
110
+
111
+ const fix = (n: number, digits = 2): string => n.toFixed(digits)
112
+
113
+ /** Judge every group against the six checks. */
114
+ export function auditSeriesGroups(
115
+ groups: readonly SeriesGroup[],
116
+ surfaces: SeriesSurfaces,
117
+ ): SeriesIssue[] {
118
+ const issues: SeriesIssue[] = []
119
+ for (const group of groups) {
120
+ const { entries: allEntries } = group
121
+ const lineOfKey = (key: string) => allEntries.find((e) => e.key === key)?.line ?? group.line
122
+
123
+ const categorical = allEntries.filter((e) => e.key !== NEUTRAL_KEY)
124
+ if (categorical.length > MAX_SERIES) {
125
+ const extra = categorical.slice(MAX_SERIES).map((e) => e.key)
126
+ issues.push({
127
+ check: 'order',
128
+ scheme: 'light',
129
+ keys: extra,
130
+ measured: categorical.length,
131
+ threshold: MAX_SERIES,
132
+ line: lineOfKey(extra[0] ?? ''),
133
+ message: `${categorical.length} series in one group (max ${MAX_SERIES}) — ${extra.join(', ')} should fold into \`${NEUTRAL_KEY}\``,
134
+ })
135
+ }
136
+
137
+ for (const scheme of ['light', 'dark'] as const) {
138
+ const [lo, hi] = LIGHTNESS_BAND[scheme]
139
+ const value = (e: SeriesEntry) => e[scheme]
140
+ // A value that is not `#rgb` / `#rrggbb` (an alpha hex, a colour name, a typo) cannot be
141
+ // measured — it is reported, and left out of this scheme's other checks rather than guessed at.
142
+ const entries = allEntries.filter((e) => {
143
+ if (HEX.test(value(e))) return true
144
+ issues.push({
145
+ check: 'format',
146
+ scheme,
147
+ keys: [e.key],
148
+ measured: 0,
149
+ threshold: 0,
150
+ line: e.line,
151
+ message: `${e.key} (${scheme}) "${value(e)}" is not a #rgb or #rrggbb hex — it cannot be checked`,
152
+ })
153
+ return false
154
+ })
155
+
156
+ for (const e of entries) {
157
+ const { L, C } = hexToOklch(value(e))
158
+ if (L < lo || L > hi) {
159
+ issues.push({
160
+ check: 'lightness',
161
+ scheme,
162
+ keys: [e.key],
163
+ measured: L,
164
+ threshold: L < lo ? lo : hi,
165
+ line: e.line,
166
+ message: `${e.key} (${scheme}) OKLCH lightness ${fix(L)} is outside ${lo}–${hi}`,
167
+ })
168
+ }
169
+ if (e.key !== NEUTRAL_KEY && C < CHROMA_FLOOR) {
170
+ issues.push({
171
+ check: 'chroma',
172
+ scheme,
173
+ keys: [e.key],
174
+ measured: C,
175
+ threshold: CHROMA_FLOOR,
176
+ line: e.line,
177
+ message: `${e.key} (${scheme}) OKLCH chroma ${fix(C, 3)} is below ${CHROMA_FLOOR} — a categorical hue must read as a hue (key a deliberately neutral series \`${NEUTRAL_KEY}\`)`,
178
+ })
179
+ }
180
+ const ratio = contrastRatio(value(e), surfaces[scheme])
181
+ if (ratio < CONTRAST_MIN) {
182
+ issues.push({
183
+ check: 'contrast',
184
+ scheme,
185
+ keys: [e.key],
186
+ measured: ratio,
187
+ threshold: CONTRAST_MIN,
188
+ line: e.line,
189
+ message: `${e.key} (${scheme}) contrast ${fix(ratio)}:1 against the surface is below ${CONTRAST_MIN}:1`,
190
+ })
191
+ }
192
+ }
193
+
194
+ // Cycling: an identical colour twice in one scheme is one series standing in for two.
195
+ const seen = new Map<string, string>()
196
+ const duplicated = new Set<string>()
197
+ for (const e of entries) {
198
+ const first = seen.get(value(e).toLowerCase())
199
+ if (first === undefined) seen.set(value(e).toLowerCase(), e.key)
200
+ else {
201
+ duplicated.add(`${first}|${e.key}`)
202
+ issues.push({
203
+ check: 'order',
204
+ scheme,
205
+ keys: [first, e.key],
206
+ measured: 0,
207
+ threshold: SEPARATION_MIN,
208
+ line: e.line,
209
+ message: `${first} and ${e.key} (${scheme}) are the same colour ${value(e)} — a group does not cycle`,
210
+ })
211
+ }
212
+ }
213
+
214
+ // Adjacent pairs, worst of the two dichromacies.
215
+ for (let i = 1; i < entries.length; i += 1) {
216
+ const a = entries[i - 1] as SeriesEntry
217
+ const b = entries[i] as SeriesEntry
218
+ if (duplicated.has(`${a.key}|${b.key}`)) continue
219
+ const sims = (['protan', 'deutan'] as const).map(
220
+ (kind) => [kind, deltaEOkCvd(value(a), value(b), kind)] as const,
221
+ )
222
+ const [kind, worst] = sims.reduce((m, s) => (s[1] < m[1] ? s : m))
223
+ if (worst < CVD_ADJACENT_MIN) {
224
+ issues.push({
225
+ check: 'cvd',
226
+ scheme,
227
+ keys: [a.key, b.key],
228
+ measured: worst,
229
+ threshold: CVD_ADJACENT_MIN,
230
+ line: b.line,
231
+ message: `${a.key} → ${b.key} (${scheme}) are ΔE ${fix(worst, 1)} apart under ${kind === 'protan' ? 'protanopia' : 'deuteranopia'}, below ${CVD_ADJACENT_MIN}`,
232
+ })
233
+ }
234
+ }
235
+
236
+ // Worst pair over the whole group, normal vision (identical pairs are `order`'s).
237
+ let worstPair: { a: SeriesEntry; b: SeriesEntry; de: number } | null = null
238
+ for (let i = 0; i < entries.length; i += 1) {
239
+ for (let j = i + 1; j < entries.length; j += 1) {
240
+ const a = entries[i] as SeriesEntry
241
+ const b = entries[j] as SeriesEntry
242
+ if (duplicated.has(`${a.key}|${b.key}`)) continue
243
+ const de = deltaEOk(value(a), value(b))
244
+ if (worstPair === null || de < worstPair.de) worstPair = { a, b, de }
245
+ }
246
+ }
247
+ if (worstPair !== null && worstPair.de < SEPARATION_MIN) {
248
+ issues.push({
249
+ check: 'separation',
250
+ scheme,
251
+ keys: [worstPair.a.key, worstPair.b.key],
252
+ measured: worstPair.de,
253
+ threshold: SEPARATION_MIN,
254
+ line: worstPair.b.line,
255
+ message: `${worstPair.a.key} and ${worstPair.b.key} (${scheme}) are only ΔE ${fix(worstPair.de, 1)} apart, below ${SEPARATION_MIN}`,
256
+ })
257
+ }
258
+ }
259
+ }
260
+ return issues
261
+ }