basalt-ui 2.21.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/MIGRATING.md +277 -12
  3. package/agent/agents/basalt-design-reviewer.md +1 -1
  4. package/agent/rules/basalt-tokens.md +1 -1
  5. package/agent/skills/basalt-design/SKILL.md +1 -1
  6. package/agent/skills/basalt-design/references/anti-defaults.md +1 -1
  7. package/agent/skills/basalt-design/references/catalogue.md +1 -0
  8. package/dist/charts/BandStrip.d.ts.map +1 -1
  9. package/dist/charts/BandStrip.js +27 -3
  10. package/dist/charts/Bars.d.ts.map +1 -1
  11. package/dist/charts/Bars.js +5 -0
  12. package/dist/charts/CartesianChart.d.ts +8 -0
  13. package/dist/charts/CartesianChart.d.ts.map +1 -1
  14. package/dist/charts/CartesianChart.js +8 -5
  15. package/dist/charts/ChartCard.d.ts +12 -3
  16. package/dist/charts/ChartCard.d.ts.map +1 -1
  17. package/dist/charts/ChartCard.js +29 -8
  18. package/dist/charts/DualPanel.d.ts.map +1 -1
  19. package/dist/charts/DualPanel.js +5 -8
  20. package/dist/charts/Heatmap.d.ts +12 -1
  21. package/dist/charts/Heatmap.d.ts.map +1 -1
  22. package/dist/charts/Heatmap.js +34 -5
  23. package/dist/charts/Lines.d.ts +3 -0
  24. package/dist/charts/Lines.d.ts.map +1 -1
  25. package/dist/charts/Lines.js +29 -6
  26. package/dist/charts/MirroredBars.d.ts.map +1 -1
  27. package/dist/charts/MirroredBars.js +4 -6
  28. package/dist/charts/Sparkline.d.ts +7 -1
  29. package/dist/charts/Sparkline.d.ts.map +1 -1
  30. package/dist/charts/Sparkline.js +39 -14
  31. package/dist/charts/StackedArea.d.ts +4 -1
  32. package/dist/charts/StackedArea.d.ts.map +1 -1
  33. package/dist/charts/StackedArea.js +9 -3
  34. package/dist/charts/band-fold.d.ts +20 -1
  35. package/dist/charts/band-fold.d.ts.map +1 -1
  36. package/dist/charts/band-fold.js +9 -0
  37. package/dist/charts/chart-box.module.css +19 -0
  38. package/dist/charts/chart-card.module.css +25 -0
  39. package/dist/charts/chart-legend.module.css +7 -0
  40. package/dist/charts/compile.d.ts +17 -6
  41. package/dist/charts/compile.d.ts.map +1 -1
  42. package/dist/charts/compile.js +145 -74
  43. package/dist/charts/labels.d.ts +15 -4
  44. package/dist/charts/labels.d.ts.map +1 -1
  45. package/dist/charts/labels.js +34 -10
  46. package/dist/charts/legend.d.ts +2 -0
  47. package/dist/charts/legend.d.ts.map +1 -1
  48. package/dist/charts/legend.js +7 -21
  49. package/dist/charts/marks.js +1 -1
  50. package/dist/charts/panel.d.ts +0 -6
  51. package/dist/charts/panel.d.ts.map +1 -1
  52. package/dist/charts/panel.js +1 -10
  53. package/dist/charts/ref-label.d.ts +26 -0
  54. package/dist/charts/ref-label.d.ts.map +1 -0
  55. package/dist/charts/ref-label.js +63 -0
  56. package/dist/charts/scales.d.ts +4 -1
  57. package/dist/charts/scales.d.ts.map +1 -1
  58. package/dist/charts/scales.js +14 -3
  59. package/dist/charts/sparkline.module.css +10 -11
  60. package/dist/charts/sparkline.module.css.d.ts +1 -2
  61. package/dist/charts/state.d.ts +2 -0
  62. package/dist/charts/state.d.ts.map +1 -1
  63. package/dist/charts/state.js +2 -1
  64. package/dist/charts/types.d.ts +14 -5
  65. package/dist/charts/types.d.ts.map +1 -1
  66. package/dist/cli/doctor-upgrade.d.ts +1 -0
  67. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  68. package/dist/cli/doctor-upgrade.js +1 -0
  69. package/dist/cli/init.d.ts +2 -0
  70. package/dist/cli/init.d.ts.map +1 -1
  71. package/dist/cli/init.js +68 -4
  72. package/dist/cli/shot/capture.d.ts +21 -2
  73. package/dist/cli/shot/capture.d.ts.map +1 -1
  74. package/dist/cli/shot/capture.js +194 -32
  75. package/dist/cli/shot/detect.d.ts.map +1 -1
  76. package/dist/cli/shot/detect.js +14 -1
  77. package/dist/cli/shot/playwright.d.ts +5 -2
  78. package/dist/cli/shot/playwright.d.ts.map +1 -1
  79. package/dist/cli/shot/types.d.ts +2 -0
  80. package/dist/cli/shot/types.d.ts.map +1 -1
  81. package/dist/cli/shot/types.js +2 -0
  82. package/dist/controls/controls.module.css +11 -1
  83. package/dist/controls/filter-pill.d.ts.map +1 -1
  84. package/dist/controls/filter-pill.js +1 -0
  85. package/dist/controls/sync-button.d.ts.map +1 -1
  86. package/dist/controls/sync-button.js +22 -3
  87. package/dist/controls/sync-button.module.css +34 -2
  88. package/dist/controls/sync-button.module.css.d.ts +1 -0
  89. package/dist/dashboard/bar-list.d.ts.map +1 -1
  90. package/dist/dashboard/bar-list.js +7 -8
  91. package/dist/dashboard/bar-list.module.css +53 -0
  92. package/dist/dashboard/bar-list.module.css.d.ts +1 -0
  93. package/dist/dashboard/index.d.ts +1 -0
  94. package/dist/dashboard/index.d.ts.map +1 -1
  95. package/dist/dashboard/index.js +2 -0
  96. package/dist/dashboard/meter-model.d.ts +77 -3
  97. package/dist/dashboard/meter-model.d.ts.map +1 -1
  98. package/dist/dashboard/meter-model.js +88 -15
  99. package/dist/dashboard/meter-parts.d.ts +8 -0
  100. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  101. package/dist/dashboard/meter-parts.js +238 -71
  102. package/dist/dashboard/meter.d.ts +43 -60
  103. package/dist/dashboard/meter.d.ts.map +1 -1
  104. package/dist/dashboard/meter.js +20 -3
  105. package/dist/dashboard/meter.module.css +61 -0
  106. package/dist/dashboard/meter.module.css.d.ts +5 -0
  107. package/dist/dashboard/page-summary.d.ts +20 -0
  108. package/dist/dashboard/page-summary.d.ts.map +1 -0
  109. package/dist/dashboard/page-summary.js +28 -0
  110. package/dist/dashboard/page-summary.module.css +89 -0
  111. package/dist/dashboard/page-summary.module.css.d.ts +15 -0
  112. package/dist/dashboard/section.d.ts +25 -2
  113. package/dist/dashboard/section.d.ts.map +1 -1
  114. package/dist/dashboard/section.js +10 -5
  115. package/dist/dashboard/section.module.css +23 -0
  116. package/dist/dashboard/section.module.css.d.ts +1 -0
  117. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  118. package/dist/dashboard/stat-card-parts.js +1 -1
  119. package/dist/dashboard/stat-card.d.ts +4 -2
  120. package/dist/dashboard/stat-card.d.ts.map +1 -1
  121. package/dist/dashboard/stat-card.js +7 -5
  122. package/dist/dashboard/stat-card.module.css +17 -0
  123. package/dist/dashboard/stat-strip.d.ts +7 -1
  124. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  125. package/dist/dashboard/stat-strip.js +74 -46
  126. package/dist/dashboard/stat-strip.module.css +67 -20
  127. package/dist/dashboard/stat-strip.module.css.d.ts +4 -0
  128. package/dist/dashboard/visual-slot.d.ts +7 -1
  129. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  130. package/dist/dashboard/visual-slot.js +3 -1
  131. package/dist/guard/vx-names.d.ts.map +1 -1
  132. package/dist/guard/vx-names.js +2 -0
  133. package/dist/index.d.ts +1 -1
  134. package/dist/index.d.ts.map +1 -1
  135. package/dist/index.js +3 -1
  136. package/dist/styles.css +34 -2
  137. package/dist/theme/chrome-vars.d.ts +20 -5
  138. package/dist/theme/chrome-vars.d.ts.map +1 -1
  139. package/dist/theme/chrome-vars.js +46 -3
  140. package/dist/theme/controls.module.css +23 -0
  141. package/dist/theme/controls.module.css.d.ts +1 -0
  142. package/dist/theme/index.d.ts.map +1 -1
  143. package/dist/theme/index.js +8 -20
  144. package/dist/tokens/core.d.ts +2 -1
  145. package/dist/tokens/core.d.ts.map +1 -1
  146. package/dist/tokens/core.js +6 -1
  147. package/dist/tokens/derive.d.ts +3 -1
  148. package/dist/tokens/derive.d.ts.map +1 -1
  149. package/dist/tokens/derive.js +16 -1
  150. package/dist/tokens/palette.d.ts +4 -0
  151. package/dist/tokens/palette.d.ts.map +1 -1
  152. package/dist/tokens/palette.js +4 -0
  153. package/dist/tokens/status-text.d.ts.map +1 -1
  154. package/dist/tokens/status-text.js +3 -1
  155. package/llms.txt +38 -20
  156. package/package.json +1 -1
  157. package/src/charts/BandStrip.tsx +33 -3
  158. package/src/charts/Bars.tsx +6 -0
  159. package/src/charts/CartesianChart.tsx +16 -3
  160. package/src/charts/ChartCard.tsx +34 -6
  161. package/src/charts/DualPanel.tsx +3 -6
  162. package/src/charts/Heatmap.tsx +54 -5
  163. package/src/charts/Lines.tsx +56 -10
  164. package/src/charts/MirroredBars.tsx +3 -5
  165. package/src/charts/Sparkline.tsx +50 -13
  166. package/src/charts/StackedArea.tsx +14 -4
  167. package/src/charts/band-fold.ts +31 -1
  168. package/src/charts/chart-box.module.css +19 -0
  169. package/src/charts/chart-card.module.css +25 -0
  170. package/src/charts/chart-legend.module.css +7 -0
  171. package/src/charts/compile.ts +210 -85
  172. package/src/charts/labels.ts +48 -14
  173. package/src/charts/legend.tsx +10 -20
  174. package/src/charts/marks.ts +1 -1
  175. package/src/charts/panel.tsx +1 -16
  176. package/src/charts/ref-label.ts +104 -0
  177. package/src/charts/scales.ts +22 -2
  178. package/src/charts/sparkline.module.css +10 -11
  179. package/src/charts/sparkline.module.css.d.ts +1 -2
  180. package/src/charts/state.tsx +3 -1
  181. package/src/charts/types.ts +14 -5
  182. package/src/cli/doctor-upgrade.ts +1 -1
  183. package/src/cli/init.ts +100 -3
  184. package/src/cli/shot/capture.ts +251 -32
  185. package/src/cli/shot/detect.ts +18 -1
  186. package/src/cli/shot/playwright.ts +2 -2
  187. package/src/cli/shot/types.ts +3 -0
  188. package/src/controls/controls.module.css +11 -1
  189. package/src/controls/filter-pill.tsx +2 -0
  190. package/src/controls/sync-button.module.css +34 -2
  191. package/src/controls/sync-button.module.css.d.ts +1 -0
  192. package/src/controls/sync-button.tsx +40 -4
  193. package/src/dashboard/bar-list.module.css +53 -0
  194. package/src/dashboard/bar-list.module.css.d.ts +1 -0
  195. package/src/dashboard/bar-list.tsx +78 -69
  196. package/src/dashboard/index.ts +1 -0
  197. package/src/dashboard/meter-model.ts +186 -20
  198. package/src/dashboard/meter-parts.tsx +285 -64
  199. package/src/dashboard/meter.module.css +61 -0
  200. package/src/dashboard/meter.module.css.d.ts +5 -0
  201. package/src/dashboard/meter.tsx +60 -10
  202. package/src/dashboard/page-summary.module.css +89 -0
  203. package/src/dashboard/page-summary.module.css.d.ts +15 -0
  204. package/src/dashboard/page-summary.tsx +95 -0
  205. package/src/dashboard/section.module.css +23 -0
  206. package/src/dashboard/section.module.css.d.ts +1 -0
  207. package/src/dashboard/section.tsx +59 -11
  208. package/src/dashboard/stat-card-parts.tsx +5 -1
  209. package/src/dashboard/stat-card.module.css +17 -0
  210. package/src/dashboard/stat-card.tsx +12 -6
  211. package/src/dashboard/stat-strip.module.css +67 -20
  212. package/src/dashboard/stat-strip.module.css.d.ts +4 -0
  213. package/src/dashboard/stat-strip.tsx +118 -72
  214. package/src/dashboard/visual-slot.ts +12 -3
  215. package/src/guard/vx-names.ts +2 -0
  216. package/src/index.ts +2 -0
  217. package/src/styles.css +34 -2
  218. package/src/theme/__snapshots__/plain-theme.test.ts.snap +186 -60
  219. package/src/theme/chrome-vars.ts +77 -8
  220. package/src/theme/controls.module.css +23 -0
  221. package/src/theme/controls.module.css.d.ts +1 -0
  222. package/src/theme/index.ts +12 -25
  223. package/src/tokens/core.ts +4 -1
  224. package/src/tokens/derive.ts +32 -3
  225. package/src/tokens/palette.ts +4 -0
  226. package/src/tokens/status-text.ts +2 -0
@@ -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
@@ -62,6 +75,8 @@ type Ctx = {
62
75
  route: string
63
76
  scheme: Scheme
64
77
  viewport: Viewport
78
+ /** The viewport's current height: a tall anchor grows it for one shot. */
79
+ height: number
65
80
  facts: PageFacts
66
81
  anchors: AnchorMetrics[]
67
82
  shots: ShotRecord[]
@@ -84,6 +99,20 @@ type Outcome = {
84
99
  /** Thrown inside a capture when the anchor simply has no such target: recorded `not-declared`, not `error`. */
85
100
  class NotDeclared extends Error {}
86
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
+
87
116
  const hash = (text: string): string => createHash('sha1').update(text).digest('hex').slice(0, 6)
88
117
  const slug = (text: string): string => text.replace(/[^\w-]+/g, '-').replace(/^-+|-+$/g, '')
89
118
  const firstLine = (error: unknown): string =>
@@ -108,9 +137,15 @@ export function withParam(route: string, state: ShotState): string {
108
137
  return `${path}${path.includes('?') ? '&' : '?'}shot-state=${state}${fragment}`
109
138
  }
110
139
 
111
- /** The rect union of `boxes`, grown by `margin` and clamped to the viewport. */
112
- export function unionClip(boxes: readonly Box[], margin: number, viewport: Viewport): Box {
113
- 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
114
149
  const left = Math.max(0, Math.min(...boxes.map((b) => b.x)) - margin)
115
150
  const top = Math.max(0, Math.min(...boxes.map((b) => b.y)) - margin)
116
151
  const right = Math.min(width, Math.max(...boxes.map((b) => b.x + b.width)) + margin)
@@ -123,7 +158,14 @@ const snap = (
123
158
  target: { screenshot(options: ShotOptions): Promise<unknown> },
124
159
  path: string,
125
160
  extra: { fullPage?: boolean; clip?: Box } = {},
126
- ): 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
+ })
127
169
 
128
170
  function record(c: Ctx, { name, state, status, file, note }: Outcome): void {
129
171
  const { route, scheme, viewport } = c
@@ -212,11 +254,167 @@ function flagProblems(c: Ctx): void {
212
254
  c.input.log(`[shot] ${c.route} ${c.scheme}/${c.viewport}: ${note}`)
213
255
  }
214
256
 
215
- /** Brings the anchor into view; throws when it is absent, hidden or off-screen at this viewport. */
216
- async function reveal(anchor: PwLocator): Promise<void> {
217
- if ((await anchor.count()) === 0) throw new Error('anchor not found')
218
- await anchor.scrollIntoViewIfNeeded()
219
- 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
+ }
220
418
  }
221
419
 
222
420
  /**
@@ -231,12 +429,17 @@ async function attempt(
231
429
  note?: string,
232
430
  ): Promise<void> {
233
431
  const file = fileName(c.route, name, c.scheme, c.viewport, state)
432
+ let unframe: (() => Promise<void>) | undefined
234
433
  try {
434
+ if (name !== PAGE_ANCHOR) unframe = await frame(c, name)
235
435
  await run(join(c.input.pngDir, file))
236
436
  } catch (error) {
237
- const status = error instanceof NotDeclared ? 'not-declared' : 'error'
437
+ const status =
438
+ error instanceof NotDeclared ? 'not-declared' : error instanceof Absent ? 'absent' : 'error'
238
439
  record(c, { name, state, status, note: firstLine(error) })
239
440
  return
441
+ } finally {
442
+ await unframe?.()
240
443
  }
241
444
  // The PNG is good: a measurement failure is recorded beside it, never instead of it.
242
445
  let notes = note ? [note] : []
@@ -266,14 +469,13 @@ const skipOnMobile = (c: Ctx, name: string, state: ShotState): boolean => {
266
469
  return true
267
470
  }
268
471
 
269
- const restCrop = async (c: Ctx, name: string, path: string): Promise<void> => {
270
- const anchor = anchorOf(c, name)
271
- await reveal(anchor)
272
- 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)
273
475
  }
274
476
 
275
477
  async function captureRest(c: Ctx, name: string): Promise<void> {
276
- await attempt(c, name, 'rest', (path) => restCrop(c, name, path))
478
+ await attempt(c, name, 'rest', (path) => restCrop(c, name, 'rest', path))
277
479
  }
278
480
 
279
481
  /**
@@ -329,7 +531,7 @@ export function parseHoverAt(raw: string): { x: number; y: number } | null {
329
531
 
330
532
  export async function hoverTrigger(target: PwLocator): Promise<void> {
331
533
  const at = parseHoverAt(String(await target.evaluate(hoverAtOf)))
332
- const box = at ? await target.boundingBox() : null
534
+ const box = at ? await within('measuring the trigger', target.boundingBox()) : null
333
535
  const position = at && box ? { x: at.x * box.width, y: at.y * box.height } : undefined
334
536
  await target.hover({ timeout: HOVER_TIMEOUT_MS, ...(position && { position }) })
335
537
  }
@@ -367,15 +569,15 @@ async function captureHover(c: Ctx, name: string): Promise<void> {
367
569
  if (skipOnMobile(c, name, 'hover')) return
368
570
  await attempt(c, name, 'hover', async (path) => {
369
571
  const anchor = anchorOf(c, name)
370
- await reveal(anchor)
572
+ await reveal(c, name, 'hover')
371
573
  const inner = c.page.locator(`${sel(name)} [data-shot-hover]`).first()
372
574
  const target = (await inner.count()) > 0 ? inner : anchor
373
575
  await c.page.evaluate(markVisibleTooltips, undefined)
374
576
  await hoverTrigger(target)
375
577
  const describedBy = idOf(await target.evaluate(describedByOf))
376
- const [box, tip] = [await anchor.boundingBox(), await openTooltipBox(c, describedBy)]
578
+ const [box, tip] = [await settledBox(anchor), await openTooltipBox(c, describedBy)]
377
579
  if (!box || !tip) return void (await snap(anchor, path))
378
- 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) })
379
581
  })
380
582
  await c.page.mouse.move(0, 0)
381
583
  }
@@ -419,10 +621,13 @@ async function captureFocus(c: Ctx, name: string): Promise<void> {
419
621
  const anchor = anchorOf(c, name)
420
622
  if (!(await anchor.evaluate(hasFocusTarget)))
421
623
  throw new NotDeclared('no focus target in the anchor')
422
- await reveal(anchor)
624
+ await reveal(c, name, 'focus')
423
625
  await c.page.evaluate(markVisibleTooltips, undefined)
424
626
  await tabInto(c.page, name)
425
- 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)
426
631
  if (!box) throw new Error('anchor has no box')
427
632
  const focused = idOf(
428
633
  await c.page.evaluate(
@@ -432,7 +637,7 @@ async function captureFocus(c: Ctx, name: string): Promise<void> {
432
637
  )
433
638
  const tip = await openTooltipBox(c, focused)
434
639
  await snap(c.page, path, {
435
- 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),
436
641
  })
437
642
  })
438
643
  await c.page.evaluate('document.activeElement?.blur()')
@@ -444,15 +649,15 @@ async function captureTooltip(c: Ctx, name: string): Promise<void> {
444
649
  await attempt(c, name, 'tooltip', async (path) => {
445
650
  if ((await trigger.count()) === 0) throw new NotDeclared('no [data-shot-tooltip] in the anchor')
446
651
  const anchor = anchorOf(c, name)
447
- await reveal(anchor)
652
+ await reveal(c, name, 'tooltip')
448
653
  await c.page.evaluate(markVisibleTooltips, undefined)
449
654
  await hoverTrigger(trigger)
450
655
  const describedBy = idOf(await trigger.evaluate(describedByOf))
451
656
  const t = await openTooltipBox(c, describedBy, TOOLTIP_TIMEOUT_MS)
452
657
  if (!t) throw new Error('no visible [role="tooltip"] after hover')
453
- const a = await anchor.boundingBox()
658
+ const a = await settledBox(anchor)
454
659
  if (!a) throw new Error('tooltip or anchor has no box')
455
- 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) })
456
661
  })
457
662
  await c.page.mouse.move(0, 0)
458
663
  }
@@ -469,7 +674,12 @@ async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
469
674
  const restNames = c.facts.anchors
470
675
  if (!c.facts.declared.includes(state)) {
471
676
  for (const name of restNames) {
472
- 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
+ })
473
683
  }
474
684
  return
475
685
  }
@@ -494,7 +704,7 @@ async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
494
704
  continue
495
705
  }
496
706
  const note = restNames.includes(name) ? undefined : 'anchor only present in this state'
497
- await attempt(c, name, state, (path) => restCrop(c, name, path), note)
707
+ await attempt(c, name, state, (path) => restCrop(c, name, state, path), note)
498
708
  }
499
709
  }
500
710
 
@@ -584,11 +794,14 @@ export function groupScale({ mantine, vx }: ScaleRead): Steps {
584
794
  }
585
795
 
586
796
  async function capturePage(
587
- args: Omit<Ctx, 'facts' | 'anchors' | 'shots' | 'measured' | 'problems'> & { wantScale: boolean },
797
+ args: Omit<Ctx, 'facts' | 'anchors' | 'shots' | 'measured' | 'problems' | 'height'> & {
798
+ wantScale: boolean
799
+ },
588
800
  ) {
589
801
  const { wantScale, ...rest } = args
590
802
  const c: Ctx = {
591
803
  ...rest,
804
+ height: VIEWPORT_SPECS[rest.viewport].height,
592
805
  facts: { anchors: [], declared: [] },
593
806
  anchors: [],
594
807
  shots: [],
@@ -623,10 +836,16 @@ async function capturePage(
623
836
  if (usable.length === 0 && c.scheme === 'light' && c.viewport === 'desktop') {
624
837
  input.log(`[shot] no data-shot anchors on ${route}`)
625
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
+ }
626
847
  if (input.states.includes('rest')) {
627
- await attempt(c, PAGE_ANCHOR, 'rest', (path) =>
628
- snap(c.page, path, { fullPage: true }).then(() => undefined),
629
- )
848
+ await attempt(c, PAGE_ANCHOR, 'rest', (path) => fullPage(c, path))
630
849
  }
631
850
  flagProblems(c)
632
851
  for (const name of usable) {
@@ -9,6 +9,7 @@
9
9
  * |-|-|-|
10
10
  * | scan/shot-error | content | P0 |
11
11
  * | scan/no-anchors | content | P0 |
12
+ * | craft-7/no-declared-states | content | P1 |
12
13
  * | craft-5/contrast | content | P0 |
13
14
  * | craft-5/assumed-backdrop | content | P2 |
14
15
  * | craft-1/scale-error, -missing| layout | P1 |
@@ -28,7 +29,7 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from '
28
29
  import { isAbsolute, join, relative, resolve } from 'node:path'
29
30
  import { parseArgs } from 'node:util'
30
31
 
31
- import { PAGE_ANCHOR, SHOT_HOME } from './types'
32
+ import { NO_STATES_NOTE, PAGE_ANCHOR, SHOT_HOME } from './types'
32
33
  import type { AnchorMetrics, Scale, ShotMetrics, Sides } from './types'
33
34
 
34
35
  export type Severity = 'P0' | 'P1' | 'P2' | 'P3'
@@ -290,6 +291,22 @@ export function detectFindings(m: ShotMetrics, lint?: LintReport): Finding[] {
290
291
  defect: `The shot failed${s.note ? `: ${s.note}` : ''}.`,
291
292
  })
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
+ }
293
310
  if (m.scaleError || m.scale.length === 0) {
294
311
  drafts.push({
295
312
  ...scan,
@@ -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>
@@ -7,6 +7,9 @@ export const URL_STATES = ['empty', 'loading', 'error'] as const
7
7
  /** Where shot keeps `last.json`, `history.json` and the default out dir. */
8
8
  export const SHOT_HOME = '.basalt/shots'
9
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
+
10
13
  /** The `name` of a route's full-page shot: not a valid `data-shot` value. */
11
14
  export const PAGE_ANCHOR = '_page'
12
15
 
@@ -112,7 +112,9 @@
112
112
  .pill {
113
113
  --vx-hit-gap: var(--vx-space-control-gap);
114
114
  position: relative;
115
- max-width: 15rem;
115
+ /* A filter pill fits its selected option; this is only the ceiling. 15rem clipped an ordinary site
116
+ * or project name (argo astro site select) — 24rem holds a long one and the label truncates past it. */
117
+ max-width: 24rem;
116
118
  border-color: color-mix(in srgb, var(--vx-ink) 12%, transparent);
117
119
  }
118
120
 
@@ -353,6 +355,14 @@
353
355
  flex: 0 1 auto;
354
356
  }
355
357
 
358
+ /* Mantine's own inline-start inset is `--input-height / 3` = 10.67px, off every step. The `ctl` inset
359
+ * is the one the buttons beside it already use, so the value lines up with their labels. Set on the
360
+ * input itself: the `--input-padding-inline-start` var is declared on a CHILD of the root this class
361
+ * lands on, so a root-level override would be shadowed. */
362
+ .phoneSelect input {
363
+ padding-inline-start: var(--button-padding-x-ctl);
364
+ }
365
+
356
366
  /* ── The facet list (MultiSelectFilter, `panel` + `sheet` surfaces) ──────────────────────────────── */
357
367
 
358
368
  /*
@@ -75,6 +75,8 @@ export function FilterPill({
75
75
  size="ctl"
76
76
  className={cx(classes.pill, className)}
77
77
  data-basalt-hit
78
+ // The label truncates past the pill's width cap; the full name stays one hover away.
79
+ title={label}
78
80
  classNames={{ label: classes.pillLabel }}
79
81
  {...(style !== undefined && { style })}
80
82
  {...(active === true && { 'data-active': true })}
@@ -34,8 +34,22 @@
34
34
  }
35
35
 
36
36
  /*
37
- * `scope: 'page'` below `sm`: the label and the age go, the glyph stays, and the button collapses
38
- * to the square icon form (spec §3, "icon-only, age in tooltip"). Hidden, not unmounted — a second
37
+ * The phone form's age (`2 m`): hidden above `sm`, where the long age already sits beside the label.
38
+ * `nowrap` is the whole point of it — a two-token string that wraps inside a 32px button is worse
39
+ * than no age at all.
40
+ */
41
+ .ageCompact {
42
+ display: none;
43
+ white-space: nowrap;
44
+ color: var(--vx-muted);
45
+ font-family: var(--basalt-font-mono);
46
+ font-size: var(--vx-text-xs);
47
+ }
48
+
49
+ /*
50
+ * `scope: 'page'` below `sm`: the label and the long age go, the glyph stays, and the button
51
+ * collapses to the square icon form (spec §3) — unless an age exists, in which case the compact age
52
+ * rides beside the glyph and the square pin is released (argo m365 refresh at 390). Hidden, not unmounted — a second
39
53
  * mount under `hiddenFrom` is exactly the responsive twin law C9 forbids, which is also why the
40
54
  * accessible name lives on `aria-label` rather than in this text.
41
55
  *
@@ -52,6 +66,10 @@
52
66
  display: none;
53
67
  }
54
68
 
69
+ .ageCompact {
70
+ display: inline;
71
+ }
72
+
55
73
  .pageButton {
56
74
  --button-padding-x: 0;
57
75
 
@@ -61,4 +79,18 @@
61
79
  .pageButton :global(.mantine-Button-section[data-position='left']) {
62
80
  margin-inline-end: 0;
63
81
  }
82
+
83
+ /* An age beside the glyph: content-width, on the `ctl` inset, glyph and age one control gap apart. */
84
+ .pageButton[data-with-age] {
85
+ --button-padding-x: var(--button-padding-x-ctl);
86
+
87
+ /* Mantine divides the inline-start padding by 1.5 when a left section exists — off the scale. */
88
+ padding-inline: var(--button-padding-x-ctl);
89
+ width: auto;
90
+ flex: none;
91
+ }
92
+
93
+ .pageButton[data-with-age] :global(.mantine-Button-section[data-position='left']) {
94
+ margin-inline-end: var(--vx-space-control-gap);
95
+ }
64
96
  }
@@ -5,6 +5,7 @@
5
5
  declare const classes: {
6
6
  readonly spin: string
7
7
  readonly age: string
8
+ readonly ageCompact: string
8
9
  readonly label: string
9
10
  readonly pageButton: string
10
11
  }