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
@@ -9,7 +9,14 @@ import type { Pair } from './real-data'
9
9
 
10
10
  import { finishMeasurement, measureAnchor } from './measure'
11
11
  import type { Box, PwBrowser, PwContext, PwLocator, PwPage, ShotOptions } from './playwright'
12
- import { PAGE_ANCHOR, SCHEMES, URL_STATES, VIEWPORTS, VIEWPORT_SPECS } from './types'
12
+ import {
13
+ NO_STATES_NOTE,
14
+ PAGE_ANCHOR,
15
+ SCHEMES,
16
+ URL_STATES,
17
+ VIEWPORTS,
18
+ VIEWPORT_SPECS,
19
+ } from './types'
13
20
  import type {
14
21
  AnchorMetrics,
15
22
  Measurement,
@@ -22,6 +29,12 @@ import type {
22
29
 
23
30
  const NAV_TIMEOUT_MS = 30_000
24
31
  const HOVER_TIMEOUT_MS = 5_000
32
+ /** Every Playwright wait a capture makes on one anchor: a hidden or tall target costs this, not 30 s. */
33
+ const STEP_TIMEOUT_MS = 5_000
34
+ const SHOT_TIMEOUT_MS = 15_000
35
+ const REVEAL_SETTLE_MS = 60
36
+ /** Chromium refuses screenshots past ~16k px; a taller anchor is captured as far as this. */
37
+ const MAX_VIEWPORT_PX = 16_000
25
38
  const TOOLTIP_TIMEOUT_MS = 3_000
26
39
  const TAB_PRESSES = 80
27
40
  const FOCUS_MARGIN_PX = 8
@@ -48,7 +61,12 @@ export type CaptureInput = {
48
61
  log: (line: string) => void
49
62
  }
50
63
 
51
- type PageFacts = { anchors: string[]; declared: string[] }
64
+ type PageFacts = {
65
+ anchors: string[]
66
+ declared: string[]
67
+ /** Anchor → the URL states it declares itself absent in (`data-shot-absent="empty error"`). */
68
+ absent?: Record<string, string[]>
69
+ }
52
70
 
53
71
  /** Everything one page visit shares: where the records go and what was already measured. */
54
72
  type Ctx = {
@@ -57,6 +75,8 @@ type Ctx = {
57
75
  route: string
58
76
  scheme: Scheme
59
77
  viewport: Viewport
78
+ /** The viewport's current height: a tall anchor grows it for one shot. */
79
+ height: number
60
80
  facts: PageFacts
61
81
  anchors: AnchorMetrics[]
62
82
  shots: ShotRecord[]
@@ -79,6 +99,20 @@ type Outcome = {
79
99
  /** Thrown inside a capture when the anchor simply has no such target: recorded `not-declared`, not `error`. */
80
100
  class NotDeclared extends Error {}
81
101
 
102
+ /** Thrown when the anchor is genuinely not rendered at this viewport: recorded `absent` with the reason. */
103
+ class Absent extends Error {}
104
+
105
+ const sleep = (ms: number): Promise<void> => new Promise((done) => setTimeout(done, ms))
106
+
107
+ /** `work`, rejected after `ms`: one hung Playwright call never spends the 30 s default. */
108
+ function within<T>(what: string, work: Promise<T>, ms = STEP_TIMEOUT_MS): Promise<T> {
109
+ let timer: ReturnType<typeof setTimeout> | undefined
110
+ const late = new Promise<never>((_, reject) => {
111
+ timer = setTimeout(() => reject(new Error(`${what} timed out after ${ms / 1000} s`)), ms)
112
+ })
113
+ return Promise.race([work, late]).finally(() => clearTimeout(timer))
114
+ }
115
+
82
116
  const hash = (text: string): string => createHash('sha1').update(text).digest('hex').slice(0, 6)
83
117
  const slug = (text: string): string => text.replace(/[^\w-]+/g, '-').replace(/^-+|-+$/g, '')
84
118
  const firstLine = (error: unknown): string =>
@@ -103,9 +137,15 @@ export function withParam(route: string, state: ShotState): string {
103
137
  return `${path}${path.includes('?') ? '&' : '?'}shot-state=${state}${fragment}`
104
138
  }
105
139
 
106
- /** The rect union of `boxes`, grown by `margin` and clamped to the viewport. */
107
- export function unionClip(boxes: readonly Box[], margin: number, viewport: Viewport): Box {
108
- const { width, height } = VIEWPORT_SPECS[viewport]
140
+ /** The rect union of `boxes`, grown by `margin` and clamped to the viewport (`tall`: its current height). */
141
+ export function unionClip(
142
+ boxes: readonly Box[],
143
+ margin: number,
144
+ viewport: Viewport,
145
+ tall?: number,
146
+ ): Box {
147
+ const { width, height: base } = VIEWPORT_SPECS[viewport]
148
+ const height = tall ?? base
109
149
  const left = Math.max(0, Math.min(...boxes.map((b) => b.x)) - margin)
110
150
  const top = Math.max(0, Math.min(...boxes.map((b) => b.y)) - margin)
111
151
  const right = Math.min(width, Math.max(...boxes.map((b) => b.x + b.width)) + margin)
@@ -118,7 +158,14 @@ const snap = (
118
158
  target: { screenshot(options: ShotOptions): Promise<unknown> },
119
159
  path: string,
120
160
  extra: { fullPage?: boolean; clip?: Box } = {},
121
- ): Promise<unknown> => target.screenshot({ path, animations: 'disabled', caret: 'hide', ...extra })
161
+ ): Promise<unknown> =>
162
+ target.screenshot({
163
+ path,
164
+ animations: 'disabled',
165
+ caret: 'hide',
166
+ timeout: SHOT_TIMEOUT_MS,
167
+ ...extra,
168
+ })
122
169
 
123
170
  function record(c: Ctx, { name, state, status, file, note }: Outcome): void {
124
171
  const { route, scheme, viewport } = c
@@ -156,6 +203,7 @@ const readFacts = (page: PwPage): Promise<PageFacts> =>
156
203
  page.evaluate(`(() => ({
157
204
  anchors: [...new Set([...document.querySelectorAll('[data-shot]')].map((e) => e.getAttribute('data-shot')).filter(Boolean))],
158
205
  declared: [...document.querySelectorAll('[data-shot-states]')].flatMap((e) => (e.getAttribute('data-shot-states') ?? '').split(/\\s+/)).filter(Boolean),
206
+ absent: Object.fromEntries([...document.querySelectorAll('[data-shot][data-shot-absent]')].map((e) => [e.getAttribute('data-shot'), (e.getAttribute('data-shot-absent') ?? '').split(/\\s+/).filter(Boolean)])),
159
207
  }))()`)
160
208
 
161
209
  const addProblem = (c: Ctx, problem: string): void => {
@@ -206,11 +254,167 @@ function flagProblems(c: Ctx): void {
206
254
  c.input.log(`[shot] ${c.route} ${c.scheme}/${c.viewport}: ${note}`)
207
255
  }
208
256
 
209
- /** Brings the anchor into view; throws when it is absent, hidden or off-screen at this viewport. */
210
- async function reveal(anchor: PwLocator): Promise<void> {
211
- if ((await anchor.count()) === 0) throw new Error('anchor not found')
212
- await anchor.scrollIntoViewIfNeeded()
213
- if (!(await anchor.isVisible())) throw new Error('anchor is not visible at this viewport')
257
+ /**
258
+ * Runs in the page: why the anchor paints nothing (`display: none` on it or an ancestor, hidden,
259
+ * zero size), or '' after scrolling it into view itself. An anchor taller than the viewport is
260
+ * aligned to its top, a shorter one is centred so a tooltip has room around it. Playwright's own
261
+ * `scrollIntoViewIfNeeded` waits out its actionability checks, which is what cost 30 s on a Sparkline
262
+ * target, a hidden mobile pane and an anchor taller than the viewport.
263
+ */
264
+ export function revealInPage(el: Element): string {
265
+ for (let node: Element | null = el; node; node = node.parentElement) {
266
+ const where = node === el ? '' : ' on an ancestor'
267
+ const style = getComputedStyle(node)
268
+ if (style.display === 'none') return `display: none${where}`
269
+ if (node.hasAttribute('hidden')) return `hidden attribute${where}`
270
+ if (style.visibility === 'hidden' && node === el) return 'visibility: hidden'
271
+ }
272
+ const rect = el.getBoundingClientRect()
273
+ if (rect.width === 0 || rect.height === 0) return 'zero size'
274
+ el.scrollIntoView({
275
+ block: rect.height > window.innerHeight ? 'start' : 'center',
276
+ inline: 'nearest',
277
+ behavior: 'instant',
278
+ })
279
+ return ''
280
+ }
281
+
282
+ /**
283
+ * Brings the anchor into view. A hidden anchor is `absent` (with the reason) only where hiding is
284
+ * expected: a pointer/focus state, or a state it declared itself absent in. A hidden `rest` anchor
285
+ * (or URL state) is a defect, so it stays an `Error`, as does a missing one. No Playwright wait is
286
+ * involved, so none of them costs more than a step.
287
+ */
288
+ async function reveal(c: Ctx, name: string, state: ShotState): Promise<void> {
289
+ const anchor = anchorOf(c, name)
290
+ if ((await within('locating the anchor', anchor.count())) === 0)
291
+ throw new Error('anchor not found')
292
+ const verdict = await within('revealing the anchor', anchor.evaluate(revealInPage))
293
+ if (typeof verdict === 'string' && verdict !== '') {
294
+ const note = `not visible at this viewport: ${verdict}`
295
+ const expected = state === 'hover' || state === 'focus' || state === 'tooltip'
296
+ const declared = c.facts.absent?.[name]?.includes(state) === true
297
+ throw expected || declared ? new Absent(note) : new Error(note)
298
+ }
299
+ await sleep(REVEAL_SETTLE_MS)
300
+ }
301
+
302
+ /** The anchor's box once two reads agree: a smooth scroll or an animating card never shifts the clip. */
303
+ async function settledBox(target: PwLocator): Promise<Box | null> {
304
+ let box = await within('measuring the anchor', target.boundingBox())
305
+ for (let i = 0; i < TIP_SETTLE_READS; i++) {
306
+ await sleep(TIP_SETTLE_MS)
307
+ const next = await within('measuring the anchor', target.boundingBox())
308
+ const settled = JSON.stringify(next) === JSON.stringify(box)
309
+ box = next
310
+ if (settled) break
311
+ }
312
+ return box
313
+ }
314
+
315
+ const FRAMES = 'new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done)))'
316
+
317
+ async function resize(c: Ctx, height: number): Promise<void> {
318
+ await c.page.setViewportSize({ width: VIEWPORT_SPECS[c.viewport].width, height })
319
+ c.height = height
320
+ await c.page.evaluate(FRAMES)
321
+ }
322
+
323
+ /**
324
+ * Runs in the page: hides (`visibility`, kept in layout) every fixed or sticky element that is not
325
+ * the anchor, inside it, or around it, and not an open popup (a nav that merely owns a closed
326
+ * `role=menu` is chrome), so the shell's PageBar and bottom nav are
327
+ * never drawn over a crop. A popup that opens later is not hidden: it did not exist yet.
328
+ */
329
+ export function hideChrome(name: string): void {
330
+ const anchor = Array.from(document.querySelectorAll('[data-shot]')).find(
331
+ (el) => el.getAttribute('data-shot') === name,
332
+ )
333
+ const popup = '[role="tooltip"], [role="dialog"], [role="listbox"], [role="menu"]'
334
+ const shown = (e: Element): boolean => {
335
+ const { width, height } = e.getBoundingClientRect()
336
+ return width > 0 && height > 0
337
+ }
338
+ const isOpenPopup = (e: Element, sel: string): boolean =>
339
+ (e.matches(sel) && shown(e)) || Array.from(e.querySelectorAll(sel)).some(shown)
340
+ for (const el of Array.from(document.body.querySelectorAll('*'))) {
341
+ const { position } = getComputedStyle(el)
342
+ if (position !== 'fixed' && position !== 'sticky') continue
343
+ if (anchor && (el.contains(anchor) || anchor.contains(el))) continue
344
+ if (isOpenPopup(el, popup)) continue
345
+ const style = (el as HTMLElement).style
346
+ el.setAttribute('data-shot-chrome', style.getPropertyValue('visibility'))
347
+ style.setProperty('visibility', 'hidden', 'important')
348
+ }
349
+ }
350
+
351
+ /** Runs in the page: undoes `hideChrome`. */
352
+ export function showChrome(): void {
353
+ for (const el of Array.from(document.querySelectorAll('[data-shot-chrome]'))) {
354
+ const style = (el as HTMLElement).style
355
+ const before = el.getAttribute('data-shot-chrome') ?? ''
356
+ if (before) style.setProperty('visibility', before)
357
+ else style.removeProperty('visibility')
358
+ el.removeAttribute('data-shot-chrome')
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Prepares the page for one anchor's crops: shell chrome hidden, and the viewport grown to hold an
364
+ * anchor taller than it (the anchor's own scrollport would otherwise paint it blank below the first
365
+ * screen). Returns the undo.
366
+ */
367
+ async function frame(c: Ctx, name: string): Promise<() => Promise<void>> {
368
+ const spec = VIEWPORT_SPECS[c.viewport]
369
+ const undo = async (): Promise<void> => {
370
+ await c.page.evaluate(showChrome, undefined)
371
+ if (c.height !== spec.height) await resize(c, spec.height)
372
+ }
373
+ await c.page.evaluate(hideChrome, name)
374
+ try {
375
+ const anchor = anchorOf(c, name)
376
+ // A missing anchor is left for `reveal` to name; measuring it would only wait out the step.
377
+ if ((await within('locating the anchor', anchor.count())) > 0) {
378
+ const height = Number(
379
+ await within(
380
+ 'measuring the anchor',
381
+ anchor.evaluate((el) => el.getBoundingClientRect().height),
382
+ ),
383
+ )
384
+ if (height > spec.height)
385
+ await resize(c, Math.min(MAX_VIEWPORT_PX, Math.ceil(height) + spec.height))
386
+ }
387
+ } catch (error) {
388
+ // The caller never gets an undo for a frame that threw: put the page back before it surfaces.
389
+ await undo()
390
+ throw error
391
+ }
392
+ return undo
393
+ }
394
+
395
+ /** Runs in the page: px of content that scroll inside a large inner scrollport, which `fullPage` cannot see. */
396
+ export function hiddenScrollPx(): number {
397
+ let extra = 0
398
+ for (const el of Array.from(document.querySelectorAll('*'))) {
399
+ if (el.clientHeight < window.innerHeight / 2) continue
400
+ const { overflowY } = getComputedStyle(el)
401
+ if (overflowY === 'auto' || overflowY === 'scroll')
402
+ extra = Math.max(extra, el.scrollHeight - el.clientHeight)
403
+ }
404
+ return extra
405
+ }
406
+
407
+ /** The whole page: the viewport grows by what an inner scrollport hides, with the chrome kept. */
408
+ async function fullPage(c: Ctx, path: string): Promise<void> {
409
+ const spec = VIEWPORT_SPECS[c.viewport]
410
+ const extra = Number(await c.page.evaluate(hiddenScrollPx, undefined))
411
+ const grown = extra > 0
412
+ if (grown) await resize(c, Math.min(MAX_VIEWPORT_PX, spec.height + Math.ceil(extra)))
413
+ try {
414
+ await snap(c.page, path, { fullPage: true })
415
+ } finally {
416
+ if (grown) await resize(c, spec.height)
417
+ }
214
418
  }
215
419
 
216
420
  /**
@@ -225,12 +429,17 @@ async function attempt(
225
429
  note?: string,
226
430
  ): Promise<void> {
227
431
  const file = fileName(c.route, name, c.scheme, c.viewport, state)
432
+ let unframe: (() => Promise<void>) | undefined
228
433
  try {
434
+ if (name !== PAGE_ANCHOR) unframe = await frame(c, name)
229
435
  await run(join(c.input.pngDir, file))
230
436
  } catch (error) {
231
- const status = error instanceof NotDeclared ? 'not-declared' : 'error'
437
+ const status =
438
+ error instanceof NotDeclared ? 'not-declared' : error instanceof Absent ? 'absent' : 'error'
232
439
  record(c, { name, state, status, note: firstLine(error) })
233
440
  return
441
+ } finally {
442
+ await unframe?.()
234
443
  }
235
444
  // The PNG is good: a measurement failure is recorded beside it, never instead of it.
236
445
  let notes = note ? [note] : []
@@ -260,14 +469,13 @@ const skipOnMobile = (c: Ctx, name: string, state: ShotState): boolean => {
260
469
  return true
261
470
  }
262
471
 
263
- const restCrop = async (c: Ctx, name: string, path: string): Promise<void> => {
264
- const anchor = anchorOf(c, name)
265
- await reveal(anchor)
266
- await snap(anchor, path)
472
+ const restCrop = async (c: Ctx, name: string, state: ShotState, path: string): Promise<void> => {
473
+ await reveal(c, name, state)
474
+ await snap(anchorOf(c, name), path)
267
475
  }
268
476
 
269
477
  async function captureRest(c: Ctx, name: string): Promise<void> {
270
- await attempt(c, name, 'rest', (path) => restCrop(c, name, path))
478
+ await attempt(c, name, 'rest', (path) => restCrop(c, name, 'rest', path))
271
479
  }
272
480
 
273
481
  /**
@@ -323,7 +531,7 @@ export function parseHoverAt(raw: string): { x: number; y: number } | null {
323
531
 
324
532
  export async function hoverTrigger(target: PwLocator): Promise<void> {
325
533
  const at = parseHoverAt(String(await target.evaluate(hoverAtOf)))
326
- const box = at ? await target.boundingBox() : null
534
+ const box = at ? await within('measuring the trigger', target.boundingBox()) : null
327
535
  const position = at && box ? { x: at.x * box.width, y: at.y * box.height } : undefined
328
536
  await target.hover({ timeout: HOVER_TIMEOUT_MS, ...(position && { position }) })
329
537
  }
@@ -361,15 +569,15 @@ async function captureHover(c: Ctx, name: string): Promise<void> {
361
569
  if (skipOnMobile(c, name, 'hover')) return
362
570
  await attempt(c, name, 'hover', async (path) => {
363
571
  const anchor = anchorOf(c, name)
364
- await reveal(anchor)
572
+ await reveal(c, name, 'hover')
365
573
  const inner = c.page.locator(`${sel(name)} [data-shot-hover]`).first()
366
574
  const target = (await inner.count()) > 0 ? inner : anchor
367
575
  await c.page.evaluate(markVisibleTooltips, undefined)
368
576
  await hoverTrigger(target)
369
577
  const describedBy = idOf(await target.evaluate(describedByOf))
370
- const [box, tip] = [await anchor.boundingBox(), await openTooltipBox(c, describedBy)]
578
+ const [box, tip] = [await settledBox(anchor), await openTooltipBox(c, describedBy)]
371
579
  if (!box || !tip) return void (await snap(anchor, path))
372
- await snap(c.page, path, { clip: unionClip([box, tip], FOCUS_MARGIN_PX, c.viewport) })
580
+ await snap(c.page, path, { clip: unionClip([box, tip], FOCUS_MARGIN_PX, c.viewport, c.height) })
373
581
  })
374
582
  await c.page.mouse.move(0, 0)
375
583
  }
@@ -413,10 +621,13 @@ async function captureFocus(c: Ctx, name: string): Promise<void> {
413
621
  const anchor = anchorOf(c, name)
414
622
  if (!(await anchor.evaluate(hasFocusTarget)))
415
623
  throw new NotDeclared('no focus target in the anchor')
416
- await reveal(anchor)
624
+ await reveal(c, name, 'focus')
417
625
  await c.page.evaluate(markVisibleTooltips, undefined)
418
626
  await tabInto(c.page, name)
419
- const box = await anchor.boundingBox()
627
+ // Focus scrolls the nearest scrollport on its own terms (under a sticky bar, mid-animation): put
628
+ // the anchor back where the clip is taken, then read its box once it stops moving.
629
+ await within('re-centring the anchor', anchor.evaluate(revealInPage))
630
+ const box = await settledBox(anchor)
420
631
  if (!box) throw new Error('anchor has no box')
421
632
  const focused = idOf(
422
633
  await c.page.evaluate(
@@ -426,7 +637,7 @@ async function captureFocus(c: Ctx, name: string): Promise<void> {
426
637
  )
427
638
  const tip = await openTooltipBox(c, focused)
428
639
  await snap(c.page, path, {
429
- clip: unionClip(tip ? [box, tip] : [box], FOCUS_MARGIN_PX, c.viewport),
640
+ clip: unionClip(tip ? [box, tip] : [box], FOCUS_MARGIN_PX, c.viewport, c.height),
430
641
  })
431
642
  })
432
643
  await c.page.evaluate('document.activeElement?.blur()')
@@ -438,15 +649,15 @@ async function captureTooltip(c: Ctx, name: string): Promise<void> {
438
649
  await attempt(c, name, 'tooltip', async (path) => {
439
650
  if ((await trigger.count()) === 0) throw new NotDeclared('no [data-shot-tooltip] in the anchor')
440
651
  const anchor = anchorOf(c, name)
441
- await reveal(anchor)
652
+ await reveal(c, name, 'tooltip')
442
653
  await c.page.evaluate(markVisibleTooltips, undefined)
443
654
  await hoverTrigger(trigger)
444
655
  const describedBy = idOf(await trigger.evaluate(describedByOf))
445
656
  const t = await openTooltipBox(c, describedBy, TOOLTIP_TIMEOUT_MS)
446
657
  if (!t) throw new Error('no visible [role="tooltip"] after hover')
447
- const a = await anchor.boundingBox()
658
+ const a = await settledBox(anchor)
448
659
  if (!a) throw new Error('tooltip or anchor has no box')
449
- await snap(c.page, path, { clip: unionClip([a, t], FOCUS_MARGIN_PX, c.viewport) })
660
+ await snap(c.page, path, { clip: unionClip([a, t], FOCUS_MARGIN_PX, c.viewport, c.height) })
450
661
  })
451
662
  await c.page.mouse.move(0, 0)
452
663
  }
@@ -463,7 +674,12 @@ async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
463
674
  const restNames = c.facts.anchors
464
675
  if (!c.facts.declared.includes(state)) {
465
676
  for (const name of restNames) {
466
- record(c, { name, state, status: 'not-declared', note: 'page does not declare this state' })
677
+ record(c, {
678
+ name,
679
+ state,
680
+ status: 'not-declared',
681
+ note: c.facts.declared.length === 0 ? NO_STATES_NOTE : 'page does not declare this state',
682
+ })
467
683
  }
468
684
  return
469
685
  }
@@ -477,11 +693,18 @@ async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
477
693
  }
478
694
  for (const name of new Set([...restNames, ...here.anchors])) {
479
695
  if (!here.anchors.includes(name)) {
480
- record(c, { name, state, status: 'error', note: 'anchor absent in this state' })
696
+ // The declaration lives on the element, which is gone in this state: it is read from the rest render.
697
+ const declared = c.facts.absent?.[name]?.includes(state) ?? false
698
+ record(
699
+ c,
700
+ declared
701
+ ? { name, state, status: 'absent', note: 'declared absent in this state' }
702
+ : { name, state, status: 'error', note: 'anchor absent in this state' },
703
+ )
481
704
  continue
482
705
  }
483
706
  const note = restNames.includes(name) ? undefined : 'anchor only present in this state'
484
- await attempt(c, name, state, (path) => restCrop(c, name, path), note)
707
+ await attempt(c, name, state, (path) => restCrop(c, name, state, path), note)
485
708
  }
486
709
  }
487
710
 
@@ -571,11 +794,14 @@ export function groupScale({ mantine, vx }: ScaleRead): Steps {
571
794
  }
572
795
 
573
796
  async function capturePage(
574
- args: Omit<Ctx, 'facts' | 'anchors' | 'shots' | 'measured' | 'problems'> & { wantScale: boolean },
797
+ args: Omit<Ctx, 'facts' | 'anchors' | 'shots' | 'measured' | 'problems' | 'height'> & {
798
+ wantScale: boolean
799
+ },
575
800
  ) {
576
801
  const { wantScale, ...rest } = args
577
802
  const c: Ctx = {
578
803
  ...rest,
804
+ height: VIEWPORT_SPECS[rest.viewport].height,
579
805
  facts: { anchors: [], declared: [] },
580
806
  anchors: [],
581
807
  shots: [],
@@ -610,10 +836,16 @@ async function capturePage(
610
836
  if (usable.length === 0 && c.scheme === 'light' && c.viewport === 'desktop') {
611
837
  input.log(`[shot] no data-shot anchors on ${route}`)
612
838
  }
839
+ const asked = URL_STATES.filter((state) => input.states.includes(state))
840
+ if (c.facts.declared.length === 0 && usable.length > 0 && asked.length > 0) {
841
+ if (c.scheme === 'light' && c.viewport === 'desktop') {
842
+ input.log(
843
+ `[shot] ${route}: no data-shot-states declared, so ${asked.join('/')} will not render; add data-shot-states to an anchor`,
844
+ )
845
+ }
846
+ }
613
847
  if (input.states.includes('rest')) {
614
- await attempt(c, PAGE_ANCHOR, 'rest', (path) =>
615
- snap(c.page, path, { fullPage: true }).then(() => undefined),
616
- )
848
+ await attempt(c, PAGE_ANCHOR, 'rest', (path) => fullPage(c, path))
617
849
  }
618
850
  flagProblems(c)
619
851
  for (const name of usable) {