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
@@ -4,9 +4,20 @@ import { basename, join } from "node:path";
4
4
  import { buildSheet } from "./board.js";
5
5
  import { SEED_FLAG, seedScript } from "./real-data.js";
6
6
  import { finishMeasurement, measureAnchor } from "./measure.js";
7
- import { PAGE_ANCHOR, SCHEMES, URL_STATES, VIEWPORTS, VIEWPORT_SPECS } from "./types.js";
7
+ import {
8
+ NO_STATES_NOTE,
9
+ PAGE_ANCHOR,
10
+ SCHEMES,
11
+ URL_STATES,
12
+ VIEWPORTS,
13
+ VIEWPORT_SPECS
14
+ } from "./types.js";
8
15
  const NAV_TIMEOUT_MS = 3e4;
9
16
  const HOVER_TIMEOUT_MS = 5e3;
17
+ const STEP_TIMEOUT_MS = 5e3;
18
+ const SHOT_TIMEOUT_MS = 15e3;
19
+ const REVEAL_SETTLE_MS = 60;
20
+ const MAX_VIEWPORT_PX = 16e3;
10
21
  const TOOLTIP_TIMEOUT_MS = 3e3;
11
22
  const TAB_PRESSES = 80;
12
23
  const FOCUS_MARGIN_PX = 8;
@@ -15,6 +26,16 @@ const TIP_SETTLE_MS = 60;
15
26
  const TIP_SETTLE_READS = 10;
16
27
  class NotDeclared extends Error {
17
28
  }
29
+ class Absent extends Error {
30
+ }
31
+ const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
32
+ function within(what, work, ms = STEP_TIMEOUT_MS) {
33
+ let timer;
34
+ const late = new Promise((_, reject) => {
35
+ timer = setTimeout(() => reject(new Error(`${what} timed out after ${ms / 1e3} s`)), ms);
36
+ });
37
+ return Promise.race([work, late]).finally(() => clearTimeout(timer));
38
+ }
18
39
  const hash = (text) => createHash("sha1").update(text).digest("hex").slice(0, 6);
19
40
  const slug = (text) => text.replace(/[^\w-]+/g, "-").replace(/^-+|-+$/g, "");
20
41
  const firstLine = (error) => (error instanceof Error ? error.message : String(error)).split("\n")[0] ?? "";
@@ -26,15 +47,22 @@ function withParam(route, state) {
26
47
  const [path, fragment] = hash2 < 0 ? [route, ""] : [route.slice(0, hash2), route.slice(hash2)];
27
48
  return `${path}${path.includes("?") ? "&" : "?"}shot-state=${state}${fragment}`;
28
49
  }
29
- function unionClip(boxes, margin, viewport) {
30
- const { width, height } = VIEWPORT_SPECS[viewport];
50
+ function unionClip(boxes, margin, viewport, tall) {
51
+ const { width, height: base } = VIEWPORT_SPECS[viewport];
52
+ const height = tall ?? base;
31
53
  const left = Math.max(0, Math.min(...boxes.map((b) => b.x)) - margin);
32
54
  const top = Math.max(0, Math.min(...boxes.map((b) => b.y)) - margin);
33
55
  const right = Math.min(width, Math.max(...boxes.map((b) => b.x + b.width)) + margin);
34
56
  const bottom = Math.min(height, Math.max(...boxes.map((b) => b.y + b.height)) + margin);
35
57
  return { x: left, y: top, width: Math.max(1, right - left), height: Math.max(1, bottom - top) };
36
58
  }
37
- const snap = (target, path, extra = {}) => target.screenshot({ path, animations: "disabled", caret: "hide", ...extra });
59
+ const snap = (target, path, extra = {}) => target.screenshot({
60
+ path,
61
+ animations: "disabled",
62
+ caret: "hide",
63
+ timeout: SHOT_TIMEOUT_MS,
64
+ ...extra
65
+ });
38
66
  function record(c, { name, state, status, file, note }) {
39
67
  const { route, scheme, viewport } = c;
40
68
  c.shots.push({
@@ -66,6 +94,7 @@ function tagAutoAnchors() {
66
94
  const readFacts = (page) => page.evaluate(`(() => ({
67
95
  anchors: [...new Set([...document.querySelectorAll('[data-shot]')].map((e) => e.getAttribute('data-shot')).filter(Boolean))],
68
96
  declared: [...document.querySelectorAll('[data-shot-states]')].flatMap((e) => (e.getAttribute('data-shot-states') ?? '').split(/\\s+/)).filter(Boolean),
97
+ 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)])),
69
98
  }))()`);
70
99
  const addProblem = (c, problem) => {
71
100
  if (!c.problems.includes(problem)) c.problems.push(problem);
@@ -102,19 +131,140 @@ function flagProblems(c) {
102
131
  record(c, { name: PAGE_ANCHOR, state: "rest", status: "error", note });
103
132
  c.input.log(`[shot] ${c.route} ${c.scheme}/${c.viewport}: ${note}`);
104
133
  }
105
- async function reveal(anchor) {
106
- if (await anchor.count() === 0) throw new Error("anchor not found");
107
- await anchor.scrollIntoViewIfNeeded();
108
- if (!await anchor.isVisible()) throw new Error("anchor is not visible at this viewport");
134
+ function revealInPage(el) {
135
+ for (let node = el; node; node = node.parentElement) {
136
+ const where = node === el ? "" : " on an ancestor";
137
+ const style = getComputedStyle(node);
138
+ if (style.display === "none") return `display: none${where}`;
139
+ if (node.hasAttribute("hidden")) return `hidden attribute${where}`;
140
+ if (style.visibility === "hidden" && node === el) return "visibility: hidden";
141
+ }
142
+ const rect = el.getBoundingClientRect();
143
+ if (rect.width === 0 || rect.height === 0) return "zero size";
144
+ el.scrollIntoView({
145
+ block: rect.height > window.innerHeight ? "start" : "center",
146
+ inline: "nearest",
147
+ behavior: "instant"
148
+ });
149
+ return "";
150
+ }
151
+ async function reveal(c, name, state) {
152
+ const anchor = anchorOf(c, name);
153
+ if (await within("locating the anchor", anchor.count()) === 0)
154
+ throw new Error("anchor not found");
155
+ const verdict = await within("revealing the anchor", anchor.evaluate(revealInPage));
156
+ if (typeof verdict === "string" && verdict !== "") {
157
+ const note = `not visible at this viewport: ${verdict}`;
158
+ const expected = state === "hover" || state === "focus" || state === "tooltip";
159
+ const declared = c.facts.absent?.[name]?.includes(state) === true;
160
+ throw expected || declared ? new Absent(note) : new Error(note);
161
+ }
162
+ await sleep(REVEAL_SETTLE_MS);
163
+ }
164
+ async function settledBox(target) {
165
+ let box = await within("measuring the anchor", target.boundingBox());
166
+ for (let i = 0; i < TIP_SETTLE_READS; i++) {
167
+ await sleep(TIP_SETTLE_MS);
168
+ const next = await within("measuring the anchor", target.boundingBox());
169
+ const settled = JSON.stringify(next) === JSON.stringify(box);
170
+ box = next;
171
+ if (settled) break;
172
+ }
173
+ return box;
174
+ }
175
+ const FRAMES = "new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done)))";
176
+ async function resize(c, height) {
177
+ await c.page.setViewportSize({ width: VIEWPORT_SPECS[c.viewport].width, height });
178
+ c.height = height;
179
+ await c.page.evaluate(FRAMES);
180
+ }
181
+ function hideChrome(name) {
182
+ const anchor = Array.from(document.querySelectorAll("[data-shot]")).find(
183
+ (el) => el.getAttribute("data-shot") === name
184
+ );
185
+ const popup = '[role="tooltip"], [role="dialog"], [role="listbox"], [role="menu"]';
186
+ const shown = (e) => {
187
+ const { width, height } = e.getBoundingClientRect();
188
+ return width > 0 && height > 0;
189
+ };
190
+ const isOpenPopup = (e, sel2) => e.matches(sel2) && shown(e) || Array.from(e.querySelectorAll(sel2)).some(shown);
191
+ for (const el of Array.from(document.body.querySelectorAll("*"))) {
192
+ const { position } = getComputedStyle(el);
193
+ if (position !== "fixed" && position !== "sticky") continue;
194
+ if (anchor && (el.contains(anchor) || anchor.contains(el))) continue;
195
+ if (isOpenPopup(el, popup)) continue;
196
+ const style = el.style;
197
+ el.setAttribute("data-shot-chrome", style.getPropertyValue("visibility"));
198
+ style.setProperty("visibility", "hidden", "important");
199
+ }
200
+ }
201
+ function showChrome() {
202
+ for (const el of Array.from(document.querySelectorAll("[data-shot-chrome]"))) {
203
+ const style = el.style;
204
+ const before = el.getAttribute("data-shot-chrome") ?? "";
205
+ if (before) style.setProperty("visibility", before);
206
+ else style.removeProperty("visibility");
207
+ el.removeAttribute("data-shot-chrome");
208
+ }
209
+ }
210
+ async function frame(c, name) {
211
+ const spec = VIEWPORT_SPECS[c.viewport];
212
+ const undo = async () => {
213
+ await c.page.evaluate(showChrome, void 0);
214
+ if (c.height !== spec.height) await resize(c, spec.height);
215
+ };
216
+ await c.page.evaluate(hideChrome, name);
217
+ try {
218
+ const anchor = anchorOf(c, name);
219
+ if (await within("locating the anchor", anchor.count()) > 0) {
220
+ const height = Number(
221
+ await within(
222
+ "measuring the anchor",
223
+ anchor.evaluate((el) => el.getBoundingClientRect().height)
224
+ )
225
+ );
226
+ if (height > spec.height)
227
+ await resize(c, Math.min(MAX_VIEWPORT_PX, Math.ceil(height) + spec.height));
228
+ }
229
+ } catch (error) {
230
+ await undo();
231
+ throw error;
232
+ }
233
+ return undo;
234
+ }
235
+ function hiddenScrollPx() {
236
+ let extra = 0;
237
+ for (const el of Array.from(document.querySelectorAll("*"))) {
238
+ if (el.clientHeight < window.innerHeight / 2) continue;
239
+ const { overflowY } = getComputedStyle(el);
240
+ if (overflowY === "auto" || overflowY === "scroll")
241
+ extra = Math.max(extra, el.scrollHeight - el.clientHeight);
242
+ }
243
+ return extra;
244
+ }
245
+ async function fullPage(c, path) {
246
+ const spec = VIEWPORT_SPECS[c.viewport];
247
+ const extra = Number(await c.page.evaluate(hiddenScrollPx, void 0));
248
+ const grown = extra > 0;
249
+ if (grown) await resize(c, Math.min(MAX_VIEWPORT_PX, spec.height + Math.ceil(extra)));
250
+ try {
251
+ await snap(c.page, path, { fullPage: true });
252
+ } finally {
253
+ if (grown) await resize(c, spec.height);
254
+ }
109
255
  }
110
256
  async function attempt(c, name, state, run, note) {
111
257
  const file = fileName(c.route, name, c.scheme, c.viewport, state);
258
+ let unframe;
112
259
  try {
260
+ if (name !== PAGE_ANCHOR) unframe = await frame(c, name);
113
261
  await run(join(c.input.pngDir, file));
114
262
  } catch (error) {
115
- const status = error instanceof NotDeclared ? "not-declared" : "error";
263
+ const status = error instanceof NotDeclared ? "not-declared" : error instanceof Absent ? "absent" : "error";
116
264
  record(c, { name, state, status, note: firstLine(error) });
117
265
  return;
266
+ } finally {
267
+ await unframe?.();
118
268
  }
119
269
  let notes = note ? [note] : [];
120
270
  if (name !== PAGE_ANCHOR && !c.measured.has(name)) {
@@ -140,13 +290,12 @@ const skipOnMobile = (c, name, state) => {
140
290
  record(c, { name, state, status: "skipped", note: "desktop only" });
141
291
  return true;
142
292
  };
143
- const restCrop = async (c, name, path) => {
144
- const anchor = anchorOf(c, name);
145
- await reveal(anchor);
146
- await snap(anchor, path);
293
+ const restCrop = async (c, name, state, path) => {
294
+ await reveal(c, name, state);
295
+ await snap(anchorOf(c, name), path);
147
296
  };
148
297
  async function captureRest(c, name) {
149
- await attempt(c, name, "rest", (path) => restCrop(c, name, path));
298
+ await attempt(c, name, "rest", (path) => restCrop(c, name, "rest", path));
150
299
  }
151
300
  function markVisibleTooltips() {
152
301
  for (const el of Array.from(document.querySelectorAll("[data-shot-seen]")))
@@ -175,7 +324,7 @@ function parseHoverAt(raw) {
175
324
  }
176
325
  async function hoverTrigger(target) {
177
326
  const at = parseHoverAt(String(await target.evaluate(hoverAtOf)));
178
- const box = at ? await target.boundingBox() : null;
327
+ const box = at ? await within("measuring the trigger", target.boundingBox()) : null;
179
328
  const position = at && box ? { x: at.x * box.width, y: at.y * box.height } : void 0;
180
329
  await target.hover({ timeout: HOVER_TIMEOUT_MS, ...position && { position } });
181
330
  }
@@ -201,15 +350,15 @@ async function captureHover(c, name) {
201
350
  if (skipOnMobile(c, name, "hover")) return;
202
351
  await attempt(c, name, "hover", async (path) => {
203
352
  const anchor = anchorOf(c, name);
204
- await reveal(anchor);
353
+ await reveal(c, name, "hover");
205
354
  const inner = c.page.locator(`${sel(name)} [data-shot-hover]`).first();
206
355
  const target = await inner.count() > 0 ? inner : anchor;
207
356
  await c.page.evaluate(markVisibleTooltips, void 0);
208
357
  await hoverTrigger(target);
209
358
  const describedBy = idOf(await target.evaluate(describedByOf));
210
- const [box, tip] = [await anchor.boundingBox(), await openTooltipBox(c, describedBy)];
359
+ const [box, tip] = [await settledBox(anchor), await openTooltipBox(c, describedBy)];
211
360
  if (!box || !tip) return void await snap(anchor, path);
212
- await snap(c.page, path, { clip: unionClip([box, tip], FOCUS_MARGIN_PX, c.viewport) });
361
+ await snap(c.page, path, { clip: unionClip([box, tip], FOCUS_MARGIN_PX, c.viewport, c.height) });
213
362
  });
214
363
  await c.page.mouse.move(0, 0);
215
364
  }
@@ -235,10 +384,11 @@ async function captureFocus(c, name) {
235
384
  const anchor = anchorOf(c, name);
236
385
  if (!await anchor.evaluate(hasFocusTarget))
237
386
  throw new NotDeclared("no focus target in the anchor");
238
- await reveal(anchor);
387
+ await reveal(c, name, "focus");
239
388
  await c.page.evaluate(markVisibleTooltips, void 0);
240
389
  await tabInto(c.page, name);
241
- const box = await anchor.boundingBox();
390
+ await within("re-centring the anchor", anchor.evaluate(revealInPage));
391
+ const box = await settledBox(anchor);
242
392
  if (!box) throw new Error("anchor has no box");
243
393
  const focused = idOf(
244
394
  await c.page.evaluate(
@@ -248,7 +398,7 @@ async function captureFocus(c, name) {
248
398
  );
249
399
  const tip = await openTooltipBox(c, focused);
250
400
  await snap(c.page, path, {
251
- clip: unionClip(tip ? [box, tip] : [box], FOCUS_MARGIN_PX, c.viewport)
401
+ clip: unionClip(tip ? [box, tip] : [box], FOCUS_MARGIN_PX, c.viewport, c.height)
252
402
  });
253
403
  });
254
404
  await c.page.evaluate("document.activeElement?.blur()");
@@ -259,15 +409,15 @@ async function captureTooltip(c, name) {
259
409
  await attempt(c, name, "tooltip", async (path) => {
260
410
  if (await trigger.count() === 0) throw new NotDeclared("no [data-shot-tooltip] in the anchor");
261
411
  const anchor = anchorOf(c, name);
262
- await reveal(anchor);
412
+ await reveal(c, name, "tooltip");
263
413
  await c.page.evaluate(markVisibleTooltips, void 0);
264
414
  await hoverTrigger(trigger);
265
415
  const describedBy = idOf(await trigger.evaluate(describedByOf));
266
416
  const t = await openTooltipBox(c, describedBy, TOOLTIP_TIMEOUT_MS);
267
417
  if (!t) throw new Error('no visible [role="tooltip"] after hover');
268
- const a = await anchor.boundingBox();
418
+ const a = await settledBox(anchor);
269
419
  if (!a) throw new Error("tooltip or anchor has no box");
270
- await snap(c.page, path, { clip: unionClip([a, t], FOCUS_MARGIN_PX, c.viewport) });
420
+ await snap(c.page, path, { clip: unionClip([a, t], FOCUS_MARGIN_PX, c.viewport, c.height) });
271
421
  });
272
422
  await c.page.mouse.move(0, 0);
273
423
  }
@@ -281,7 +431,12 @@ async function captureUrlState(c, state) {
281
431
  const restNames = c.facts.anchors;
282
432
  if (!c.facts.declared.includes(state)) {
283
433
  for (const name of restNames) {
284
- record(c, { name, state, status: "not-declared", note: "page does not declare this state" });
434
+ record(c, {
435
+ name,
436
+ state,
437
+ status: "not-declared",
438
+ note: c.facts.declared.length === 0 ? NO_STATES_NOTE : "page does not declare this state"
439
+ });
285
440
  }
286
441
  return;
287
442
  }
@@ -295,11 +450,15 @@ async function captureUrlState(c, state) {
295
450
  }
296
451
  for (const name of /* @__PURE__ */ new Set([...restNames, ...here.anchors])) {
297
452
  if (!here.anchors.includes(name)) {
298
- record(c, { name, state, status: "error", note: "anchor absent in this state" });
453
+ const declared = c.facts.absent?.[name]?.includes(state) ?? false;
454
+ record(
455
+ c,
456
+ declared ? { name, state, status: "absent", note: "declared absent in this state" } : { name, state, status: "error", note: "anchor absent in this state" }
457
+ );
299
458
  continue;
300
459
  }
301
460
  const note = restNames.includes(name) ? void 0 : "anchor only present in this state";
302
- await attempt(c, name, state, (path) => restCrop(c, name, path), note);
461
+ await attempt(c, name, state, (path) => restCrop(c, name, state, path), note);
303
462
  }
304
463
  }
305
464
  const STEPS = ["xs", "sm", "md", "lg", "xl", "default"];
@@ -373,6 +532,7 @@ async function capturePage(args) {
373
532
  const { wantScale, ...rest } = args;
374
533
  const c = {
375
534
  ...rest,
535
+ height: VIEWPORT_SPECS[rest.viewport].height,
376
536
  facts: { anchors: [], declared: [] },
377
537
  anchors: [],
378
538
  shots: [],
@@ -407,13 +567,16 @@ async function capturePage(args) {
407
567
  if (usable.length === 0 && c.scheme === "light" && c.viewport === "desktop") {
408
568
  input.log(`[shot] no data-shot anchors on ${route}`);
409
569
  }
570
+ const asked = URL_STATES.filter((state) => input.states.includes(state));
571
+ if (c.facts.declared.length === 0 && usable.length > 0 && asked.length > 0) {
572
+ if (c.scheme === "light" && c.viewport === "desktop") {
573
+ input.log(
574
+ `[shot] ${route}: no data-shot-states declared, so ${asked.join("/")} will not render; add data-shot-states to an anchor`
575
+ );
576
+ }
577
+ }
410
578
  if (input.states.includes("rest")) {
411
- await attempt(
412
- c,
413
- PAGE_ANCHOR,
414
- "rest",
415
- (path) => snap(c.page, path, { fullPage: true }).then(() => void 0)
416
- );
579
+ await attempt(c, PAGE_ANCHOR, "rest", (path) => fullPage(c, path));
417
580
  }
418
581
  flagProblems(c);
419
582
  for (const name of usable) {
@@ -541,13 +704,17 @@ export {
541
704
  fileName,
542
705
  groupScale,
543
706
  hasFocusTarget,
707
+ hiddenScrollPx,
708
+ hideChrome,
544
709
  hoverAtOf,
545
710
  hoverTrigger,
546
711
  markVisibleTooltips,
547
712
  openContext,
548
713
  parseHoverAt,
549
714
  readScaleInPage,
715
+ revealInPage,
550
716
  sheetName,
717
+ showChrome,
551
718
  tagAutoAnchors,
552
719
  tooltipSelector,
553
720
  unionClip,
@@ -0,0 +1,51 @@
1
+ import type { ShotMetrics } from './types.js';
2
+ export type Severity = 'P0' | 'P1' | 'P2' | 'P3';
3
+ export type Layer = 'content' | 'layout' | 'style';
4
+ export type Finding = {
5
+ /** Stable id: `<craft-n | scan | lint>/<kebab-name>`. */
6
+ rule: string;
7
+ severity: Severity;
8
+ layer: Layer;
9
+ /** The component (`data-shot` name), or the source file of a lint diagnostic. */
10
+ anchor: string;
11
+ route?: string;
12
+ /** `<scheme>/<viewport>` of every render showing the defect. */
13
+ where: string[];
14
+ /** The file and field the defect is read from. */
15
+ cite: string;
16
+ defect: string;
17
+ };
18
+ /** The slice of an `oxlint --format json` report detect reads. */
19
+ export type LintReport = {
20
+ diagnostics: {
21
+ message?: string;
22
+ code?: string;
23
+ severity?: string;
24
+ filename?: string;
25
+ labels?: {
26
+ span?: {
27
+ line?: number;
28
+ column?: number;
29
+ };
30
+ }[];
31
+ }[];
32
+ };
33
+ export type DetectDeps = {
34
+ now?: () => Date;
35
+ log?: (line: string) => void;
36
+ /** The short HEAD hash for the history entry; undefined outside a git checkout. */
37
+ commit?: (cwd: string) => string | undefined;
38
+ };
39
+ export type HistoryEntry = {
40
+ at: string;
41
+ out: string;
42
+ commit?: string;
43
+ counts: Record<Severity, number>;
44
+ score: number;
45
+ };
46
+ export declare const scoreOf: (findings: readonly Finding[]) => number;
47
+ /** Every deterministic finding of one round, grouped across scheme × viewport, content → layout → style. */
48
+ export declare function detectFindings(m: ShotMetrics, lint?: LintReport): Finding[];
49
+ /** `shot detect`: exit 0 (none, or only P2/P3), 2 on a P0/P1 finding, 1 scan failure. */
50
+ export declare function detect(flags: readonly string[], cwd: string, deps?: DetectDeps): Promise<number>;
51
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../src/cli/shot/detect.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAwB,WAAW,EAAS,MAAM,SAAS,CAAA;AAEvE,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAChD,MAAM,MAAM,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAA;AAElD,MAAM,MAAM,OAAO,GAAG;IACpB,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,QAAQ,CAAA;IAClB,KAAK,EAAE,KAAK,CAAA;IACZ,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE;QACX,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,MAAM,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE;gBAAE,IAAI,CAAC,EAAE,MAAM,CAAC;gBAAC,MAAM,CAAC,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,EAAE,CAAA;KACzD,EAAE,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAA;IAChB,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5B,mFAAmF;IACnF,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAChC,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAcD,eAAO,MAAM,OAAO,GAAI,UAAU,SAAS,OAAO,EAAE,KAAG,MACsB,CAAA;AA+K7E,4GAA4G;AAC5G,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CA4F3E;AAyID,yFAAyF;AACzF,wBAAsB,MAAM,CAC1B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,UAAe,GACpB,OAAO,CAAC,MAAM,CAAC,CAgDjB"}