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.
- package/CHANGELOG.md +72 -0
- package/MIGRATING.md +394 -12
- package/agent/agents/basalt-design-reviewer.md +22 -5
- package/agent/rules/basalt-tokens.md +3 -3
- package/agent/skills/basalt-design/SKILL.md +10 -23
- package/agent/skills/basalt-design/references/anti-defaults.md +24 -0
- package/agent/skills/basalt-design/references/catalogue.md +49 -0
- package/agent/skills/basalt-design/references/concept.md +36 -0
- package/agent/skills/basalt-design/references/encoding-rules.md +45 -0
- package/agent/skills/basalt-design/references/stat-tile.md +24 -0
- package/agent/templates/AGENTS-block.md.tpl +3 -3
- package/configs/oxlint-plugin.js +1 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +27 -3
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +5 -0
- package/dist/charts/CartesianChart.d.ts +8 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +8 -5
- package/dist/charts/ChartCard.d.ts +17 -4
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +33 -8
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +5 -8
- package/dist/charts/Heatmap.d.ts +12 -1
- package/dist/charts/Heatmap.d.ts.map +1 -1
- package/dist/charts/Heatmap.js +34 -5
- package/dist/charts/Lines.d.ts +3 -0
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +29 -6
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +4 -6
- package/dist/charts/Sparkline.d.ts +7 -1
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +39 -14
- package/dist/charts/StackedArea.d.ts +4 -1
- package/dist/charts/StackedArea.d.ts.map +1 -1
- package/dist/charts/StackedArea.js +9 -3
- package/dist/charts/band-fold.d.ts +20 -1
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +9 -0
- package/dist/charts/chart-box.module.css +19 -0
- package/dist/charts/chart-card.module.css +25 -0
- package/dist/charts/chart-legend.module.css +7 -0
- package/dist/charts/compile.d.ts +17 -6
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +145 -74
- package/dist/charts/labels.d.ts +15 -4
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +34 -10
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +7 -21
- package/dist/charts/marks.js +1 -1
- package/dist/charts/panel.d.ts +0 -6
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -10
- package/dist/charts/ref-label.d.ts +26 -0
- package/dist/charts/ref-label.d.ts.map +1 -0
- package/dist/charts/ref-label.js +63 -0
- package/dist/charts/scales.d.ts +4 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +14 -3
- package/dist/charts/sparkline.module.css +10 -11
- package/dist/charts/sparkline.module.css.d.ts +1 -2
- package/dist/charts/state.d.ts +7 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +4 -1
- package/dist/charts/types.d.ts +14 -5
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +3 -0
- package/dist/cli/doctor-upgrade.d.ts +1 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +1 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +3 -2
- package/dist/cli/index.d.ts +4 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +27 -15
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +71 -6
- package/dist/cli/shot/capture.d.ts +21 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +200 -33
- package/dist/cli/shot/detect.d.ts +51 -0
- package/dist/cli/shot/detect.d.ts.map +1 -0
- package/dist/cli/shot/detect.js +409 -0
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +7 -4
- package/dist/cli/shot/measure.d.ts +2 -0
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +2 -0
- package/dist/cli/shot/playwright.d.ts +5 -2
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/types.d.ts +6 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/shot/types.js +4 -0
- package/dist/cli/sync.d.ts +2 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -2
- package/dist/common/retry-button.d.ts +12 -0
- package/dist/common/retry-button.d.ts.map +1 -0
- package/dist/common/retry-button.js +22 -0
- package/dist/common/retry-button.module.css +58 -0
- package/dist/common/retry-button.module.css.d.ts +8 -0
- package/dist/controls/controls.module.css +11 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +1 -0
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +22 -3
- package/dist/controls/sync-button.module.css +34 -2
- package/dist/controls/sync-button.module.css.d.ts +1 -0
- package/dist/dashboard/bar-list.d.ts +5 -2
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +9 -10
- package/dist/dashboard/bar-list.module.css +53 -0
- package/dist/dashboard/bar-list.module.css.d.ts +1 -0
- package/dist/dashboard/index.d.ts +1 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/meter-model.d.ts +108 -6
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +123 -19
- package/dist/dashboard/meter-parts.d.ts +8 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +345 -146
- package/dist/dashboard/meter.d.ts +50 -63
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +24 -3
- package/dist/dashboard/meter.module.css +79 -65
- package/dist/dashboard/meter.module.css.d.ts +7 -7
- package/dist/dashboard/page-summary.d.ts +20 -0
- package/dist/dashboard/page-summary.d.ts.map +1 -0
- package/dist/dashboard/page-summary.js +28 -0
- package/dist/dashboard/page-summary.module.css +89 -0
- package/dist/dashboard/page-summary.module.css.d.ts +15 -0
- package/dist/dashboard/query-state.d.ts +1 -1
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +3 -2
- package/dist/dashboard/section.d.ts +25 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +10 -5
- package/dist/dashboard/section.module.css +23 -0
- package/dist/dashboard/section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.d.ts +4 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +7 -4
- package/dist/dashboard/stat-card.module.css +17 -0
- package/dist/dashboard/stat-strip.d.ts +24 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +97 -39
- package/dist/dashboard/stat-strip.module.css +147 -17
- package/dist/dashboard/stat-strip.module.css.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts +8 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -0
- package/dist/dashboard/visual-slot.js +7 -0
- package/dist/guard/index.d.ts +15 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +14 -0
- package/dist/guard/palette.d.ts +51 -0
- package/dist/guard/palette.d.ts.map +1 -0
- package/dist/guard/palette.js +190 -0
- package/dist/guard/series-file.d.ts +15 -0
- package/dist/guard/series-file.d.ts.map +1 -0
- package/dist/guard/series-file.js +29 -0
- package/dist/guard/types.d.ts +3 -3
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/styles.css +34 -2
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- package/dist/theme/chrome-vars.d.ts +20 -5
- package/dist/theme/chrome-vars.d.ts.map +1 -1
- package/dist/theme/chrome-vars.js +46 -3
- package/dist/theme/controls.module.css +33 -0
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +11 -5
- package/dist/tokens/core.d.ts +2 -1
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -1
- package/dist/tokens/derive.d.ts +3 -1
- package/dist/tokens/derive.d.ts.map +1 -1
- package/dist/tokens/derive.js +16 -1
- package/dist/tokens/oklab.d.ts +28 -0
- package/dist/tokens/oklab.d.ts.map +1 -0
- package/dist/tokens/oklab.js +73 -0
- package/dist/tokens/palette.d.ts +4 -0
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +4 -0
- package/dist/tokens/status-text.d.ts.map +1 -1
- package/dist/tokens/status-text.js +3 -1
- package/llms.txt +43 -23
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +33 -3
- package/src/charts/Bars.tsx +6 -0
- package/src/charts/CartesianChart.tsx +16 -3
- package/src/charts/ChartCard.tsx +43 -7
- package/src/charts/DualPanel.tsx +3 -6
- package/src/charts/Heatmap.tsx +54 -5
- package/src/charts/Lines.tsx +56 -10
- package/src/charts/MirroredBars.tsx +3 -5
- package/src/charts/Sparkline.tsx +50 -13
- package/src/charts/StackedArea.tsx +14 -4
- package/src/charts/band-fold.ts +31 -1
- package/src/charts/chart-box.module.css +19 -0
- package/src/charts/chart-card.module.css +25 -0
- package/src/charts/chart-legend.module.css +7 -0
- package/src/charts/compile.ts +210 -85
- package/src/charts/labels.ts +48 -14
- package/src/charts/legend.tsx +10 -20
- package/src/charts/marks.ts +1 -1
- package/src/charts/panel.tsx +1 -16
- package/src/charts/ref-label.ts +104 -0
- package/src/charts/scales.ts +22 -2
- package/src/charts/sparkline.module.css +10 -11
- package/src/charts/sparkline.module.css.d.ts +1 -2
- package/src/charts/state.tsx +12 -1
- package/src/charts/types.ts +14 -5
- package/src/cli/check-theme.ts +3 -0
- package/src/cli/doctor-upgrade.ts +1 -1
- package/src/cli/help.ts +18 -1
- package/src/cli/index.ts +48 -17
- package/src/cli/init.ts +102 -4
- package/src/cli/shot/capture.ts +266 -34
- package/src/cli/shot/detect.ts +550 -0
- package/src/cli/shot/index.ts +8 -4
- package/src/cli/shot/measure.ts +4 -0
- package/src/cli/shot/playwright.ts +2 -2
- package/src/cli/shot/types.ts +8 -1
- package/src/cli/sync.ts +4 -2
- package/src/common/retry-button.module.css +58 -0
- package/src/common/retry-button.module.css.d.ts +8 -0
- package/src/common/retry-button.tsx +29 -0
- package/src/controls/controls.module.css +11 -1
- package/src/controls/filter-pill.tsx +2 -0
- package/src/controls/sync-button.module.css +34 -2
- package/src/controls/sync-button.module.css.d.ts +1 -0
- package/src/controls/sync-button.tsx +40 -4
- package/src/dashboard/bar-list.module.css +53 -0
- package/src/dashboard/bar-list.module.css.d.ts +1 -0
- package/src/dashboard/bar-list.tsx +88 -76
- package/src/dashboard/index.ts +1 -0
- package/src/dashboard/meter-model.ts +265 -28
- package/src/dashboard/meter-parts.tsx +424 -163
- package/src/dashboard/meter.module.css +79 -65
- package/src/dashboard/meter.module.css.d.ts +7 -7
- package/src/dashboard/meter.tsx +77 -17
- package/src/dashboard/page-summary.module.css +89 -0
- package/src/dashboard/page-summary.module.css.d.ts +15 -0
- package/src/dashboard/page-summary.tsx +95 -0
- package/src/dashboard/query-state.tsx +4 -7
- package/src/dashboard/section.module.css +23 -0
- package/src/dashboard/section.module.css.d.ts +1 -0
- package/src/dashboard/section.tsx +59 -11
- package/src/dashboard/stat-card-parts.tsx +5 -1
- package/src/dashboard/stat-card.module.css +17 -0
- package/src/dashboard/stat-card.tsx +14 -5
- package/src/dashboard/stat-strip.module.css +147 -17
- package/src/dashboard/stat-strip.module.css.d.ts +8 -0
- package/src/dashboard/stat-strip.tsx +182 -56
- package/src/dashboard/visual-slot.ts +17 -0
- package/src/guard/index.ts +16 -4
- package/src/guard/palette.ts +261 -0
- package/src/guard/series-file.ts +51 -0
- package/src/guard/types.ts +3 -2
- package/src/guard/vx-names.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles.css +34 -2
- package/src/surfaces.ts +2 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +220 -60
- package/src/theme/chrome-vars.ts +77 -8
- package/src/theme/controls.module.css +33 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +18 -5
- package/src/tokens/core.ts +4 -1
- package/src/tokens/derive.ts +32 -3
- package/src/tokens/oklab.ts +97 -0
- package/src/tokens/palette.ts +4 -0
- package/src/tokens/status-text.ts +2 -0
package/src/cli/shot/capture.ts
CHANGED
|
@@ -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 {
|
|
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 = {
|
|
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(
|
|
108
|
-
|
|
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> =>
|
|
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
|
-
/**
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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 =
|
|
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
|
-
|
|
265
|
-
await
|
|
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(
|
|
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
|
|
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(
|
|
624
|
+
await reveal(c, name, 'focus')
|
|
417
625
|
await c.page.evaluate(markVisibleTooltips, undefined)
|
|
418
626
|
await tabInto(c.page, name)
|
|
419
|
-
|
|
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(
|
|
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
|
|
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, {
|
|
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
|
-
|
|
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'> & {
|
|
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) {
|