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