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
@@ -0,0 +1,550 @@
1
+ /**
2
+ * `basalt-ui shot detect [--out <dir>] [--lint <oxlint-json-file>]` — the deterministic second
3
+ * review pass: every [measured] item of the design reviewer, read from `metrics.json` with no model
4
+ * in the loop, plus the `basalt/*` diagnostics of an `oxlint --format json` report.
5
+ *
6
+ * Severity (P0 = broken or unreadable, P1 = a rubric item fails, P2 = degraded, P3 = polish):
7
+ *
8
+ * | rule | layer | severity |
9
+ * |-|-|-|
10
+ * | scan/shot-error | content | P0 |
11
+ * | scan/no-anchors | content | P0 |
12
+ * | craft-7/no-declared-states | content | P1 |
13
+ * | craft-5/contrast | content | P0 |
14
+ * | craft-5/assumed-backdrop | content | P2 |
15
+ * | craft-1/scale-error, -missing| layout | P1 |
16
+ * | craft-1/off-scale-inset, -gap| layout | P1; P3 when every off value is within 1 px of a step |
17
+ * | craft-3/empty-region | layout | P1 |
18
+ * | craft-1/off-scale-radius | style | P1; P3 when every off value is within 1 px of a step |
19
+ * | craft-1/nested-radius-step | style | P1 |
20
+ * | craft-2/font-sizes | style | P1 |
21
+ * | lint/basalt/<rule> | style | P1 for an error, P2 for a warning |
22
+ *
23
+ * P0 and P1 fail the run (exit 2); P2 and P3 are listed findings that do not (exit 0).
24
+ * Findings run content → layout → style, the order the reviewer reports in.
25
+ * Score = 100 − (25·P0 + 10·P1 + 3·P2 + 1·P3), floored at 0.
26
+ */
27
+ import { execFileSync } from 'node:child_process'
28
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
29
+ import { isAbsolute, join, relative, resolve } from 'node:path'
30
+ import { parseArgs } from 'node:util'
31
+
32
+ import { NO_STATES_NOTE, PAGE_ANCHOR, SHOT_HOME } from './types'
33
+ import type { AnchorMetrics, Scale, ShotMetrics, Sides } from './types'
34
+
35
+ export type Severity = 'P0' | 'P1' | 'P2' | 'P3'
36
+ export type Layer = 'content' | 'layout' | 'style'
37
+
38
+ export type Finding = {
39
+ /** Stable id: `<craft-n | scan | lint>/<kebab-name>`. */
40
+ rule: string
41
+ severity: Severity
42
+ layer: Layer
43
+ /** The component (`data-shot` name), or the source file of a lint diagnostic. */
44
+ anchor: string
45
+ route?: string
46
+ /** `<scheme>/<viewport>` of every render showing the defect. */
47
+ where: string[]
48
+ /** The file and field the defect is read from. */
49
+ cite: string
50
+ defect: string
51
+ }
52
+
53
+ /** The slice of an `oxlint --format json` report detect reads. */
54
+ export type LintReport = {
55
+ diagnostics: {
56
+ message?: string
57
+ code?: string
58
+ severity?: string
59
+ filename?: string
60
+ labels?: { span?: { line?: number; column?: number } }[]
61
+ }[]
62
+ }
63
+
64
+ export type DetectDeps = {
65
+ now?: () => Date
66
+ log?: (line: string) => void
67
+ /** The short HEAD hash for the history entry; undefined outside a git checkout. */
68
+ commit?: (cwd: string) => string | undefined
69
+ }
70
+
71
+ export type HistoryEntry = {
72
+ at: string
73
+ out: string
74
+ commit?: string
75
+ counts: Record<Severity, number>
76
+ score: number
77
+ }
78
+
79
+ const LAYERS: readonly Layer[] = ['content', 'layout', 'style']
80
+ const SEVERITIES: readonly Severity[] = ['P0', 'P1', 'P2', 'P3']
81
+ const WEIGHT: Record<Severity, number> = { P0: 25, P1: 10, P2: 3, P3: 1 }
82
+ const FONT_SIZE_LIMIT = 3
83
+ const EMPTY_LIMIT = 0.4
84
+ const NESTED_MIN_STEP_PX = 3
85
+ const POLISH_PX = 1
86
+ const TREND_RUNS = 5
87
+ const USAGE_LINE = 'usage: basalt-ui shot detect [--out <dir>] [--lint <oxlint-json-file>]'
88
+
89
+ class DetectError extends Error {}
90
+
91
+ export const scoreOf = (findings: readonly Finding[]): number =>
92
+ Math.max(0, 100 - findings.reduce((sum, f) => sum + WEIGHT[f.severity], 0))
93
+
94
+ const countsOf = (findings: readonly Finding[]): Record<Severity, number> => ({
95
+ P0: findings.filter((f) => f.severity === 'P0').length,
96
+ P1: findings.filter((f) => f.severity === 'P1').length,
97
+ P2: findings.filter((f) => f.severity === 'P2').length,
98
+ P3: findings.filter((f) => f.severity === 'P3').length,
99
+ })
100
+
101
+ const where = (a: AnchorMetrics): string => `${a.scheme}/${a.viewport}`
102
+ const SIDE_NAMES: (keyof Sides)[] = ['top', 'right', 'bottom', 'left']
103
+
104
+ type Draft = Omit<Finding, 'where'> & { where: string }
105
+
106
+ /** Distance from `value` to the nearest step; 0 and `'full'` need no step. */
107
+ function offScale(value: number | 'full', steps: readonly number[]): number | null {
108
+ if (value === 'full' || value === 0 || steps.length === 0) return null
109
+ const nearest = Math.min(...steps.map((s) => Math.abs(s - value)))
110
+ return nearest < 0.011 ? null : nearest
111
+ }
112
+
113
+ const stepsText = (steps: Record<string, number>): string =>
114
+ [...new Set(Object.values(steps))].sort((a, b) => a - b).join(', ')
115
+
116
+ /** P1, or P3 when every off value is a rounding away from a step. */
117
+ const sizing = (distances: number[]): Severity =>
118
+ distances.every((d) => d <= POLISH_PX) ? 'P3' : 'P1'
119
+
120
+ function craftOne(a: AnchorMetrics, scale: Scale | undefined): Draft[] {
121
+ if (!scale) return []
122
+ const base = { anchor: a.name, route: a.route, where: where(a) }
123
+ const out: Draft[] = []
124
+ const spacing = Object.values(scale.spacing)
125
+ const radii = Object.values(scale.radius)
126
+
127
+ const inset = SIDE_NAMES.map((side) => ({ side, v: a.padding[side] })).flatMap(({ side, v }) => {
128
+ const d = offScale(v, spacing)
129
+ return d === null ? [] : [{ side, v, d }]
130
+ })
131
+ if (inset.length > 0) {
132
+ out.push({
133
+ ...base,
134
+ rule: 'craft-1/off-scale-inset',
135
+ severity: sizing(inset.map((i) => i.d)),
136
+ layer: 'layout',
137
+ cite: `metrics.json anchors[${a.name} ${where(a)}].padding`,
138
+ defect: `Padding ${inset.map((i) => `${i.side} ${i.v}px`).join(', ')} is not a spacing step (${stepsText(scale.spacing)}).`,
139
+ })
140
+ }
141
+
142
+ const gap = (['row', 'column'] as const).flatMap((axis) => {
143
+ const d = offScale(a.gap[axis], spacing)
144
+ return d === null ? [] : [{ axis, v: a.gap[axis], d }]
145
+ })
146
+ if (gap.length > 0) {
147
+ out.push({
148
+ ...base,
149
+ rule: 'craft-1/off-scale-gap',
150
+ severity: sizing(gap.map((g) => g.d)),
151
+ layer: 'layout',
152
+ cite: `metrics.json anchors[${a.name} ${where(a)}].gap`,
153
+ defect: `Gap ${gap.map((g) => `${g.axis} ${g.v}px`).join(', ')} is not a spacing step (${stepsText(scale.spacing)}).`,
154
+ })
155
+ }
156
+
157
+ const radius = offScale(a.radius, radii)
158
+ if (radius !== null) {
159
+ out.push({
160
+ ...base,
161
+ rule: 'craft-1/off-scale-radius',
162
+ severity: sizing([radius]),
163
+ layer: 'style',
164
+ cite: `metrics.json anchors[${a.name} ${where(a)}].radius`,
165
+ defect: `Radius ${String(a.radius)}px is not a radius step (${stepsText(scale.radius)}).`,
166
+ })
167
+ }
168
+ return out
169
+ }
170
+
171
+ /** Each nested surface against its nearest painted ancestor (the longest path prefix), else the anchor. */
172
+ function nestedRadius(a: AnchorMetrics): Draft[] {
173
+ const out: Draft[] = []
174
+ for (const child of a.nested) {
175
+ const parent = a.nested
176
+ .filter((n) => n !== child && child.path.startsWith(`${n.path} > `))
177
+ .sort((x, y) => y.path.length - x.path.length)[0]
178
+ const parentRadius = parent ? parent.radius : a.radius
179
+ if (typeof parentRadius !== 'number' || typeof child.radius !== 'number') continue
180
+ if (parentRadius === 0 || child.radius === 0) continue
181
+ if (Math.abs(parentRadius - child.radius) >= NESTED_MIN_STEP_PX) continue
182
+ out.push({
183
+ rule: 'craft-1/nested-radius-step',
184
+ severity: 'P1',
185
+ layer: 'style',
186
+ anchor: a.name,
187
+ route: a.route,
188
+ where: where(a),
189
+ cite: `metrics.json anchors[${a.name} ${where(a)}].nested[${child.path}]`,
190
+ defect: `Nested surface radius ${child.radius}px is within ${NESTED_MIN_STEP_PX}px of its parent's ${parentRadius}px.`,
191
+ })
192
+ }
193
+ return out
194
+ }
195
+
196
+ function anchorFindings(a: AnchorMetrics, scale: Scale | undefined): Draft[] {
197
+ const base = { anchor: a.name, route: a.route, where: where(a) }
198
+ const cite = (field: string): string => `metrics.json anchors[${a.name} ${where(a)}].${field}`
199
+ const out: Draft[] = [...craftOne(a, scale), ...nestedRadius(a)]
200
+ const sizes = new Set(a.fontSizes)
201
+ if (sizes.size > FONT_SIZE_LIMIT) {
202
+ out.push({
203
+ ...base,
204
+ rule: 'craft-2/font-sizes',
205
+ severity: 'P1',
206
+ layer: 'style',
207
+ cite: cite('fontSizes'),
208
+ defect: `${sizes.size} distinct font sizes (${[...sizes].sort((x, y) => x - y).join(', ')}px); the limit is ${FONT_SIZE_LIMIT}.`,
209
+ })
210
+ }
211
+ if (a.emptyRatio >= EMPTY_LIMIT) {
212
+ out.push({
213
+ ...base,
214
+ rule: 'craft-3/empty-region',
215
+ severity: 'P1',
216
+ layer: 'layout',
217
+ cite: cite('emptyRatio'),
218
+ defect: `${Math.round(a.emptyRatio * 100)}% of the component's height is an empty region; the limit is ${EMPTY_LIMIT * 100}%.`,
219
+ })
220
+ }
221
+ const failures = a.contrast.failures
222
+ if (failures.length > 0) {
223
+ const worst = failures.reduce((lo, f) => (f.ratio < lo.ratio ? f : lo))
224
+ out.push({
225
+ ...base,
226
+ rule: 'craft-5/contrast',
227
+ severity: 'P0',
228
+ layer: 'content',
229
+ cite: cite('contrast.failures'),
230
+ defect: `${failures.length} text run${failures.length === 1 ? '' : 's'} below the AA contrast threshold; lowest ${worst.ratio}:1 on "${worst.text}" (${worst.fontSize}px).`,
231
+ })
232
+ }
233
+ if (a.contrast.backdrop === 'assumed-white') {
234
+ out.push({
235
+ ...base,
236
+ rule: 'craft-5/assumed-backdrop',
237
+ severity: 'P2',
238
+ layer: 'content',
239
+ cite: cite('contrast.backdrop'),
240
+ defect:
241
+ 'Some text sat on no opaque background and white was assumed, so its contrast is unproven.',
242
+ })
243
+ }
244
+ return out
245
+ }
246
+
247
+ function lintFindings(report: LintReport): Draft[] {
248
+ return report.diagnostics.flatMap((d) => {
249
+ const id = /^basalt\((.+)\)$/.exec(d.code ?? '')?.[1]
250
+ if (!id) return []
251
+ const span = d.labels?.[0]?.span
252
+ const file = d.filename ?? '?'
253
+ return [
254
+ {
255
+ rule: `lint/basalt/${id}`,
256
+ severity: d.severity === 'error' ? 'P1' : 'P2',
257
+ layer: 'style',
258
+ anchor: file,
259
+ where: '',
260
+ cite: `${file}:${span?.line ?? 0}:${span?.column ?? 0}`,
261
+ defect: d.message ?? `basalt/${id}`,
262
+ } satisfies Draft,
263
+ ]
264
+ })
265
+ }
266
+
267
+ /** Every deterministic finding of one round, grouped across scheme × viewport, content → layout → style. */
268
+ export function detectFindings(m: ShotMetrics, lint?: LintReport): Finding[] {
269
+ const drafts: Draft[] = []
270
+ const scan = { layer: 'content', where: '' } as const
271
+ if (m.anchors.length === 0) {
272
+ drafts.push({
273
+ ...scan,
274
+ rule: 'scan/no-anchors',
275
+ severity: 'P0',
276
+ anchor: '—',
277
+ cite: 'metrics.json anchors',
278
+ defect: 'The round measured no component: no data-shot anchor rendered.',
279
+ })
280
+ }
281
+ for (const s of m.shots) {
282
+ if (s.status !== 'error') continue
283
+ drafts.push({
284
+ ...scan,
285
+ rule: 'scan/shot-error',
286
+ severity: 'P0',
287
+ anchor: s.name === PAGE_ANCHOR ? `${PAGE_ANCHOR} (full page)` : s.name,
288
+ route: s.route,
289
+ where: `${s.scheme}/${s.viewport}/${s.state}`,
290
+ cite: `metrics.json shots[${s.name} ${s.scheme}/${s.viewport}/${s.state}]`,
291
+ defect: `The shot failed${s.note ? `: ${s.note}` : ''}.`,
292
+ })
293
+ }
294
+ for (const route of new Set(
295
+ m.shots
296
+ .filter((s) => s.status === 'not-declared' && s.note === NO_STATES_NOTE)
297
+ .map((s) => s.route),
298
+ )) {
299
+ drafts.push({
300
+ ...scan,
301
+ rule: 'craft-7/no-declared-states',
302
+ severity: 'P1',
303
+ anchor: '—',
304
+ route,
305
+ cite: `metrics.json shots[${route} not-declared]`,
306
+ defect:
307
+ 'No anchor declares data-shot-states, so empty, loading and error were never rendered or scored: declare them with data-shot-states.',
308
+ })
309
+ }
310
+ if (m.scaleError || m.scale.length === 0) {
311
+ drafts.push({
312
+ ...scan,
313
+ layer: 'layout',
314
+ rule: 'craft-1/scale-error',
315
+ severity: 'P1',
316
+ anchor: '—',
317
+ cite: 'metrics.json scale',
318
+ defect: `The theme scale was not read${m.scaleError ? ` (${m.scaleError})` : ''}, so Craft 1 is unverified.`,
319
+ })
320
+ }
321
+ for (const a of m.anchors) {
322
+ const scale = m.scale.find((s) => s.scheme === a.scheme && s.viewport === a.viewport)
323
+ if (!scale && m.scale.length > 0) {
324
+ drafts.push({
325
+ rule: 'craft-1/scale-missing',
326
+ severity: 'P1',
327
+ layer: 'layout',
328
+ anchor: a.name,
329
+ route: a.route,
330
+ where: where(a),
331
+ cite: `metrics.json scale[${where(a)}]`,
332
+ defect: `No theme scale was read for ${where(a)}, so Craft 1 is unverified there.`,
333
+ })
334
+ }
335
+ drafts.push(...anchorFindings(a, scale))
336
+ }
337
+ if (lint) drafts.push(...lintFindings(lint))
338
+
339
+ const grouped = new Map<string, Finding>()
340
+ for (const d of drafts) {
341
+ const key = [
342
+ d.rule,
343
+ d.route ?? '',
344
+ d.anchor,
345
+ d.cite.replace(/ (light|dark)\/(desktop|mobile)/, ''),
346
+ d.defect,
347
+ ].join('|')
348
+ const hit = grouped.get(key)
349
+ if (hit) {
350
+ if (d.where && !hit.where.includes(d.where)) hit.where.push(d.where)
351
+ } else {
352
+ grouped.set(key, { ...d, where: d.where ? [d.where] : [] })
353
+ }
354
+ }
355
+ return [...grouped.values()].sort(
356
+ (x, y) =>
357
+ LAYERS.indexOf(x.layer) - LAYERS.indexOf(y.layer) ||
358
+ SEVERITIES.indexOf(x.severity) - SEVERITIES.indexOf(y.severity),
359
+ )
360
+ }
361
+
362
+ function readJson(path: string, what: string): unknown {
363
+ let text: string
364
+ try {
365
+ text = readFileSync(path, 'utf8')
366
+ } catch (error) {
367
+ throw new DetectError(`${what} ${path} is unreadable: ${(error as Error).message}`)
368
+ }
369
+ try {
370
+ return JSON.parse(text)
371
+ } catch {
372
+ throw new DetectError(`${what} ${path} is not valid JSON`)
373
+ }
374
+ }
375
+
376
+ function readMetrics(path: string): ShotMetrics {
377
+ const m = readJson(path, 'metrics.json') as Partial<ShotMetrics> | null
378
+ if (!m || m.version !== 1 || !Array.isArray(m.anchors) || !Array.isArray(m.shots)) {
379
+ throw new DetectError(
380
+ `metrics.json ${path} is not a shot output (version 1 with anchors and shots)`,
381
+ )
382
+ }
383
+ return { ...m, scale: Array.isArray(m.scale) ? m.scale : [] } as ShotMetrics
384
+ }
385
+
386
+ function readLint(path: string): LintReport {
387
+ const report = readJson(path, '--lint file') as Partial<LintReport> | null
388
+ if (!report || !Array.isArray(report.diagnostics)) {
389
+ throw new DetectError(
390
+ `--lint file ${path} is not an oxlint JSON report (no "diagnostics" array)`,
391
+ )
392
+ }
393
+ return report as LintReport
394
+ }
395
+
396
+ /** The out dir to read: `--out`, else the last run's (`last.json`), else the default. */
397
+ function outDirOf(cwd: string, out: string | undefined): string {
398
+ if (out) return resolve(cwd, out)
399
+ const last = join(cwd, SHOT_HOME, 'last.json')
400
+ try {
401
+ const named = (JSON.parse(readFileSync(last, 'utf8')) as { out?: unknown }).out
402
+ if (typeof named === 'string' && named) return resolve(cwd, named)
403
+ } catch {
404
+ // No last run recorded: the default dir.
405
+ }
406
+ return join(cwd, SHOT_HOME, 'latest')
407
+ }
408
+
409
+ const gitHead = (cwd: string): string | undefined => {
410
+ try {
411
+ return execFileSync('git', ['rev-parse', '--short', 'HEAD'], {
412
+ cwd,
413
+ stdio: ['ignore', 'pipe', 'ignore'],
414
+ })
415
+ .toString()
416
+ .trim()
417
+ } catch {
418
+ return undefined
419
+ }
420
+ }
421
+
422
+ /** Runs an fs step; any I/O failure becomes a clean `DetectError`. */
423
+ function io<T>(what: string, step: () => T): T {
424
+ try {
425
+ return step()
426
+ } catch (error) {
427
+ throw new DetectError(
428
+ `cannot ${what}: ${error instanceof Error ? error.message : String(error)}`,
429
+ )
430
+ }
431
+ }
432
+
433
+ /**
434
+ * The runs on record plus `entry`. A history that is not an array of runs is moved to
435
+ * `history.json.bak` (never overwritten in place) and a new one starts.
436
+ */
437
+ function nextHistory(
438
+ path: string,
439
+ entry: HistoryEntry,
440
+ log: (line: string) => void,
441
+ ): HistoryEntry[] {
442
+ if (!existsSync(path)) return [entry]
443
+ try {
444
+ const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))
445
+ if (!Array.isArray(parsed)) throw new TypeError('not an array')
446
+ return [...(parsed as HistoryEntry[]), entry]
447
+ } catch {
448
+ io(`move the unreadable ${path} aside`, () => renameSync(path, `${path}.bak`))
449
+ log(`[detect] ${path} was unreadable; kept as history.json.bak, starting a new history`)
450
+ return [entry]
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Writes `detect.json` and `history.json` through temp files and renames both only after both are
456
+ * written, so a failed write never leaves one without the other. Returns the last scores.
457
+ */
458
+ function persist(
459
+ files: { detectPath: string; report: object; home: string; entry: HistoryEntry },
460
+ log: (line: string) => void,
461
+ ): number[] {
462
+ const { detectPath, report, home, entry } = files
463
+ const historyPath = join(home, 'history.json')
464
+ return io('write detect.json or history.json', () => {
465
+ mkdirSync(home, { recursive: true })
466
+ if (!existsSync(join(home, '.gitignore'))) writeFileSync(join(home, '.gitignore'), '*\n')
467
+ const runs = nextHistory(historyPath, entry, log)
468
+ const json = (value: unknown): string => JSON.stringify(value, null, 2) + '\n'
469
+ writeFileSync(`${historyPath}.tmp`, json(runs))
470
+ writeFileSync(`${detectPath}.tmp`, json(report))
471
+ renameSync(`${historyPath}.tmp`, historyPath)
472
+ renameSync(`${detectPath}.tmp`, detectPath)
473
+ return runs.slice(-TREND_RUNS).map((r) => r.score)
474
+ })
475
+ }
476
+
477
+ const compactWhere = (w: string[]): string => (w.length >= 4 ? 'all' : w.join(','))
478
+
479
+ /** A compact, plain-text table: severity, rule, component, where, defect. */
480
+ function table(findings: readonly Finding[]): string[] {
481
+ const rows = findings.map((f) => [
482
+ f.severity,
483
+ f.rule,
484
+ f.route ? `${f.route} ${f.anchor}` : f.anchor,
485
+ compactWhere(f.where),
486
+ f.defect,
487
+ ])
488
+ const widths = [0, 1, 2, 3].map((i) => Math.max(...rows.map((r) => (r[i] ?? '').length)))
489
+ return rows.map((r) =>
490
+ r
491
+ .map((cell, i) => (i < 4 ? cell.padEnd(widths[i] ?? 0) : cell))
492
+ .join(' ')
493
+ .trimEnd(),
494
+ )
495
+ }
496
+
497
+ /** `shot detect`: exit 0 (none, or only P2/P3), 2 on a P0/P1 finding, 1 scan failure. */
498
+ export async function detect(
499
+ flags: readonly string[],
500
+ cwd: string,
501
+ deps: DetectDeps = {},
502
+ ): Promise<number> {
503
+ const log = deps.log ?? ((line: string) => console.log(line))
504
+ try {
505
+ let values: { out?: string | undefined; lint?: string | undefined }
506
+ try {
507
+ values = parseArgs({
508
+ args: [...flags],
509
+ options: { out: { type: 'string' }, lint: { type: 'string' } },
510
+ strict: true,
511
+ }).values
512
+ } catch (error) {
513
+ throw new DetectError(
514
+ `${error instanceof Error ? error.message : String(error)}\n${USAGE_LINE}`,
515
+ )
516
+ }
517
+ const outDir = outDirOf(cwd, values.out)
518
+ const metrics = readMetrics(join(outDir, 'metrics.json'))
519
+ const lint = values.lint ? readLint(resolve(cwd, values.lint)) : undefined
520
+ const findings = detectFindings(metrics, lint)
521
+ const counts = countsOf(findings)
522
+ const score = scoreOf(findings)
523
+ const at = (deps.now ?? (() => new Date()))().toISOString()
524
+ const rel = relative(cwd, outDir)
525
+ const out = rel === '' || rel.startsWith('..') || isAbsolute(rel) ? outDir : rel
526
+ const commit = (deps.commit ?? gitHead)(cwd)
527
+ const trend = persist(
528
+ {
529
+ detectPath: join(outDir, 'detect.json'),
530
+ report: { version: 1, at, out, ...(commit && { commit }), counts, score, findings },
531
+ home: join(cwd, SHOT_HOME),
532
+ entry: { at, out, ...(commit && { commit }), counts, score },
533
+ },
534
+ log,
535
+ )
536
+ const summary = SEVERITIES.filter((s) => counts[s] > 0)
537
+ .map((s) => `${s} ${counts[s]}`)
538
+ .join(', ')
539
+ log(
540
+ `[detect] ${findings.length === 0 ? 'no findings' : `${findings.length} findings (${summary})`} · score ${score}`,
541
+ )
542
+ for (const line of table(findings)) log(line)
543
+ log(`[detect] trend ${trend.join(' → ')} · ${relative(cwd, join(outDir, 'detect.json'))}`)
544
+ return counts.P0 + counts.P1 > 0 ? 2 : 0
545
+ } catch (error) {
546
+ if (!(error instanceof DetectError)) throw error
547
+ console.error(`basalt-ui shot detect: ${error.message}`)
548
+ return 1
549
+ }
550
+ }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * `basalt-ui shot <route…> (--base <url> | --dist <dir>) [--out <dir>] [--states <list>]` — render
3
3
  * routes in a real browser and write `board.html`, `metrics.json` and `png/*` for a design round.
4
+ * `basalt-ui shot detect` reads that out dir back without a browser (`./detect`).
4
5
  */
5
6
  import {
6
7
  lstatSync,
@@ -19,15 +20,16 @@ import { parseArgs } from 'node:util'
19
20
 
20
21
  import { buildBoard } from './board'
21
22
  import { capture } from './capture'
23
+ import { detect } from './detect'
22
24
  import { INSTALL_LINE, ShotError, resolvePlaywright, withBrowser } from './playwright'
23
25
  import type { Playwright, PlaywrightResolver } from './playwright'
24
26
  import { apiProxy, parseApi, parseHeaders, parseStorage } from './real-data'
25
27
  import type { ApiRoute, Pair, Source } from './real-data'
26
28
  import { serveDist } from './serve'
27
- import { SCHEMES, STATES, VIEWPORTS } from './types'
29
+ import { SCHEMES, SHOT_HOME, STATES, VIEWPORTS } from './types'
28
30
  import type { ShotMetrics, ShotState } from './types'
29
31
 
30
- const HOME = '.basalt/shots'
32
+ const HOME = SHOT_HOME
31
33
  /** A run dir under the home, so `last.json` and a named run's dir never share the default out. */
32
34
  const DEFAULT_OUT = `${HOME}/latest`
33
35
  const USAGE_LINE =
@@ -129,7 +131,7 @@ export function parseShotArgs(
129
131
 
130
132
  const PROTECTED_SEGMENTS = new Set(['.git', 'node_modules'])
131
133
  /** What a shot writes into its out dir: only a dir made of these is ever emptied. */
132
- const SHOT_OWNED = new Set(['png', 'board.html', 'metrics.json', '.gitignore'])
134
+ const SHOT_OWNED = new Set(['png', 'board.html', 'metrics.json', 'detect.json', '.gitignore'])
133
135
 
134
136
  const outside = (rel: string): boolean =>
135
137
  rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)
@@ -318,6 +320,7 @@ export async function shot(
318
320
  cwd: string,
319
321
  deps: ShotDeps = {},
320
322
  ): Promise<number> {
323
+ if (flags[0] === 'detect') return detect(flags.slice(1), cwd, deps)
321
324
  const log = deps.log ?? ((line: string) => console.log(line))
322
325
  const stops: (() => unknown)[] = []
323
326
  const uninstall = exitOnSignal(stops)
@@ -381,8 +384,9 @@ export async function shot(
381
384
  writeFileSync(join(tmp, 'board.html'), buildBoard(metrics))
382
385
  commitOut(cwd, args.out, tmp, args.routes, now)
383
386
  const count = (status: string): number => shots.filter((s) => s.status === status).length
387
+ const absent = count('absent') ? `${count('absent')} absent, ` : ''
384
388
  log(
385
- `[shot] ${count('ok')} shots, ${count('not-declared')} not declared, ${count('skipped')} skipped, ${count('error')} failed → ${relative(cwd, outDir)}/board.html`,
389
+ `[shot] ${count('ok')} shots, ${count('not-declared')} not declared, ${absent}${count('skipped')} skipped, ${count('error')} failed → ${relative(cwd, outDir)}/board.html`,
386
390
  )
387
391
  if (count('error') > 0) {
388
392
  console.error(`basalt-ui shot: ${count('error')} shot(s) failed; see board.html`)
@@ -32,6 +32,8 @@ export type TextReading = {
32
32
  bold: boolean
33
33
  /** No opaque ancestor background was found: `bg` is white by assumption. */
34
34
  assumedWhite: boolean
35
+ /** Inside a disabled control: WCAG 1.4.3 exempts inactive components, so it is not measured. */
36
+ disabled?: boolean
35
37
  }
36
38
  /** A computed `border-top-left-radius` as the page read it, with the box it rounds. */
37
39
  export type RawRadius = { value: string; width: number; height: number }
@@ -72,6 +74,7 @@ export function finishMeasurement({ texts, radius, nested, ...rest }: Reading):
72
74
  const failures: ContrastFailure[] = []
73
75
  let min: number | null = null
74
76
  for (const t of texts) {
77
+ if (t.disabled) continue
75
78
  const exact = contrastRatio(t.fg, t.bg)
76
79
  const ratio = Math.round(exact * 100) / 100
77
80
  min = min === null ? ratio : Math.min(min, ratio)
@@ -220,6 +223,7 @@ export function measureAnchor(root: Element): Reading {
220
223
  fg: over(rgba(s.color), back.color),
221
224
  bg: back.color,
222
225
  assumedWhite: back.assumedWhite,
226
+ disabled: el.closest(':disabled, [aria-disabled="true"], [data-disabled]') !== null,
223
227
  fontSize: size,
224
228
  bold: parseInt(s.fontWeight, 10) >= 700,
225
229
  })
@@ -21,15 +21,14 @@ export type ShotOptions = {
21
21
  caret: 'hide'
22
22
  fullPage?: boolean
23
23
  clip?: Box
24
+ timeout?: number
24
25
  }
25
26
 
26
27
  export type PwLocator = {
27
28
  first(): PwLocator
28
29
  count(): Promise<number>
29
30
  hover(options?: { timeout?: number; position?: { x: number; y: number } }): Promise<void>
30
- isVisible(): Promise<boolean>
31
31
  boundingBox(): Promise<Box | null>
32
- scrollIntoViewIfNeeded(): Promise<void>
33
32
  waitFor(options: { state: 'visible'; timeout: number }): Promise<void>
34
33
  screenshot(options: ShotOptions): Promise<unknown>
35
34
  evaluate<R>(fn: (el: Element) => R): Promise<R>
@@ -38,6 +37,7 @@ export type PwLocator = {
38
37
  export type PwPage = {
39
38
  goto(url: string, options: { waitUntil: 'load' | 'networkidle' }): Promise<unknown>
40
39
  setDefaultTimeout(ms: number): void
40
+ setViewportSize(size: { width: number; height: number }): Promise<void>
41
41
  locator(selector: string): PwLocator
42
42
  evaluate<R>(expression: string): Promise<R>
43
43
  evaluate<R, A>(fn: (arg: A) => R, arg: A): Promise<R>
@@ -4,6 +4,12 @@ export const STATES = ['rest', 'hover', 'focus', 'tooltip', 'empty', 'loading',
4
4
  /** The states a page opts into with `data-shot-states`; reached through the `shot-state` URL param. */
5
5
  export const URL_STATES = ['empty', 'loading', 'error'] as const
6
6
 
7
+ /** Where shot keeps `last.json`, `history.json` and the default out dir. */
8
+ export const SHOT_HOME = '.basalt/shots'
9
+
10
+ /** The note of a URL-state shot skipped because the route declares no `data-shot-states` at all (`shot detect` reads it). */
11
+ export const NO_STATES_NOTE = 'page declares no data-shot-states'
12
+
7
13
  /** The `name` of a route's full-page shot: not a valid `data-shot` value. */
8
14
  export const PAGE_ANCHOR = '_page'
9
15
 
@@ -63,7 +69,8 @@ export type ShotRecord = {
63
69
  viewport: Viewport
64
70
  state: ShotState
65
71
  file: string | null
66
- status: 'ok' | 'not-declared' | 'skipped' | 'error'
72
+ /** `absent`: the anchor declared itself missing in this state (`data-shot-absent`): not a defect. */
73
+ status: 'ok' | 'not-declared' | 'absent' | 'skipped' | 'error'
67
74
  note?: string
68
75
  }
69
76