basalt-ui 2.13.3 → 2.15.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 +66 -0
- package/MIGRATING.md +42 -12
- package/agent/agents/basalt-design-reviewer.md +83 -0
- package/agent/rules/basalt-batteries.md +1 -2
- package/agent/rules/basalt-charts.md +1 -1
- package/agent/rules/basalt-controls.md +3 -3
- package/agent/rules/basalt-mantine.md +1 -2
- package/agent/rules/basalt-state.md +1 -2
- package/agent/rules/basalt-tokens.md +1 -3
- package/agent/skills/basalt-design/SKILL.md +26 -8
- package/agent/templates/AGENTS-block.md.tpl +7 -0
- package/configs/oxlint-plugin.js +39 -2
- package/configs/oxlint-plugin.test.ts +48 -0
- package/dist/agent/chat/thread-feed-row.d.ts.map +1 -1
- package/dist/agent/chat/thread-feed-row.js +2 -2
- package/dist/agent/chat/thread-message.d.ts.map +1 -1
- package/dist/agent/chat/thread-message.js +2 -2
- package/dist/agent/chat/thread-outcome-card.js +2 -2
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +1 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +3 -2
- package/dist/charts/cursor.d.ts +10 -6
- package/dist/charts/cursor.d.ts.map +1 -1
- package/dist/charts/cursor.js +20 -13
- package/dist/charts/legend.d.ts +7 -6
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +3 -3
- package/dist/charts/panel.d.ts +2 -0
- package/dist/charts/panel.d.ts.map +1 -1
- package/dist/charts/panel.js +1 -0
- package/dist/cli/board-freshness.d.ts +25 -0
- package/dist/cli/board-freshness.d.ts.map +1 -0
- package/dist/cli/board-freshness.js +88 -0
- package/dist/cli/doctor.d.ts +2 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +3 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +9 -3
- package/dist/cli/index.d.ts +15 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +57 -7
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +6 -1
- package/dist/cli/shot/board.d.ts +5 -0
- package/dist/cli/shot/board.d.ts.map +1 -0
- package/dist/cli/shot/board.js +96 -0
- package/dist/cli/shot/capture.d.ts +59 -0
- package/dist/cli/shot/capture.d.ts.map +1 -0
- package/dist/cli/shot/capture.js +473 -0
- package/dist/cli/shot/index.d.ts +45 -0
- package/dist/cli/shot/index.d.ts.map +1 -0
- package/dist/cli/shot/index.js +289 -0
- package/dist/cli/shot/measure.d.ts +28 -0
- package/dist/cli/shot/measure.d.ts.map +1 -0
- package/dist/cli/shot/measure.js +176 -0
- package/dist/cli/shot/playwright.d.ts +101 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -0
- package/dist/cli/shot/playwright.js +60 -0
- package/dist/cli/shot/serve.d.ts +6 -0
- package/dist/cli/shot/serve.d.ts.map +1 -0
- package/dist/cli/shot/serve.js +33 -0
- package/dist/cli/shot/types.d.ts +97 -0
- package/dist/cli/shot/types.d.ts.map +1 -0
- package/dist/cli/shot/types.js +17 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -1
- package/dist/commands/notifications/center.d.ts.map +1 -1
- package/dist/commands/notifications/center.js +2 -11
- package/dist/controls/control-name.d.ts +27 -0
- package/dist/controls/control-name.d.ts.map +1 -0
- package/dist/controls/control-name.js +11 -0
- package/dist/controls/enum-filter.d.ts +3 -6
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +8 -4
- package/dist/controls/filter-base.d.ts +30 -0
- package/dist/controls/filter-base.d.ts.map +1 -0
- package/dist/controls/filter-base.js +0 -0
- package/dist/controls/filter-pill.d.ts +3 -1
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +2 -0
- package/dist/controls/filter-sheet.d.ts +0 -32
- package/dist/controls/filter-sheet.d.ts.map +1 -1
- package/dist/controls/filter-sheet.js +1 -28
- package/dist/controls/glyphs.d.ts +12 -0
- package/dist/controls/glyphs.d.ts.map +1 -1
- package/dist/controls/glyphs.js +23 -2
- package/dist/controls/index.d.ts +2 -1
- package/dist/controls/index.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.d.ts +8 -3
- package/dist/controls/multi-select-filter.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.js +27 -10
- package/dist/controls/number-filter.d.ts +3 -12
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +17 -6
- package/dist/controls/panel-row.d.ts +5 -8
- package/dist/controls/panel-row.d.ts.map +1 -1
- package/dist/controls/panel-row.js +3 -0
- package/dist/controls/range-filter.d.ts +14 -14
- package/dist/controls/range-filter.d.ts.map +1 -1
- package/dist/controls/range-filter.js +18 -41
- package/dist/controls/search-filter.d.ts +5 -2
- package/dist/controls/search-filter.d.ts.map +1 -1
- package/dist/controls/search-filter.js +74 -40
- package/dist/controls/select-filter.d.ts +2 -15
- package/dist/controls/select-filter.d.ts.map +1 -1
- package/dist/controls/sync-button.d.ts +0 -6
- package/dist/controls/sync-button.d.ts.map +1 -1
- package/dist/controls/sync-button.js +6 -36
- package/dist/controls/toggle-filter.d.ts +2 -2
- package/dist/controls/toggle-filter.d.ts.map +1 -1
- package/dist/controls/toggle-filter.js +3 -2
- package/dist/controls/view-tabs.d.ts +3 -4
- package/dist/controls/view-tabs.d.ts.map +1 -1
- package/dist/controls/view-tabs.js +24 -5
- package/dist/format/date.d.ts +43 -10
- package/dist/format/date.d.ts.map +1 -1
- package/dist/format/date.js +109 -18
- package/dist/format/index.d.ts +12 -11
- package/dist/format/index.d.ts.map +1 -1
- package/dist/format/index.js +11 -2
- package/dist/format/measure.d.ts +9 -9
- package/dist/format/measure.d.ts.map +1 -1
- package/dist/format/measure.js +19 -8
- package/dist/format/number.d.ts +35 -27
- package/dist/format/number.d.ts.map +1 -1
- package/dist/format/number.js +41 -20
- package/dist/format/shared.d.ts +38 -7
- package/dist/format/shared.d.ts.map +1 -1
- package/dist/format/shared.js +61 -13
- package/dist/provider/index.d.ts +13 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +8 -0
- package/dist/surfaces.d.ts +2 -0
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- package/llms.txt +35 -14
- package/package.json +1 -1
- package/src/agent/chat/thread-feed-row.tsx +2 -2
- package/src/agent/chat/thread-message.tsx +2 -2
- package/src/agent/chat/thread-outcome-card.tsx +2 -2
- package/src/charts/DualPanel.tsx +1 -0
- package/src/charts/compile.ts +3 -2
- package/src/charts/cursor.ts +44 -27
- package/src/charts/legend.tsx +11 -8
- package/src/charts/panel.tsx +3 -0
- package/src/cli/board-freshness.ts +132 -0
- package/src/cli/doctor.ts +10 -1
- package/src/cli/help.ts +14 -2
- package/src/cli/index.ts +80 -10
- package/src/cli/init.ts +8 -1
- package/src/cli/shot/board.ts +154 -0
- package/src/cli/shot/capture.ts +650 -0
- package/src/cli/shot/index.ts +362 -0
- package/src/cli/shot/measure.ts +225 -0
- package/src/cli/shot/playwright.ts +152 -0
- package/src/cli/shot/serve.ts +35 -0
- package/src/cli/shot/types.ts +91 -0
- package/src/cli/sync.ts +2 -1
- package/src/commands/notifications/center.tsx +2 -14
- package/src/controls/control-name.ts +33 -0
- package/src/controls/enum-filter.tsx +29 -27
- package/src/controls/filter-base.ts +31 -0
- package/src/controls/filter-pill.tsx +4 -0
- package/src/controls/filter-sheet.tsx +0 -56
- package/src/controls/glyphs.tsx +45 -2
- package/src/controls/index.ts +2 -1
- package/src/controls/multi-select-filter.tsx +67 -43
- package/src/controls/number-filter.tsx +47 -47
- package/src/controls/panel-row.tsx +7 -8
- package/src/controls/range-filter.tsx +54 -78
- package/src/controls/search-filter.tsx +107 -54
- package/src/controls/select-filter.tsx +2 -18
- package/src/controls/sync-button.tsx +7 -40
- package/src/controls/toggle-filter.tsx +9 -7
- package/src/controls/view-tabs.tsx +41 -21
- package/src/format/date.ts +189 -36
- package/src/format/index.ts +12 -11
- package/src/format/measure.ts +29 -18
- package/src/format/number.ts +76 -37
- package/src/format/shared.ts +116 -25
- package/src/provider/index.tsx +23 -0
- package/src/surfaces.ts +5 -0
- package/dist/agent/chat/relative-time.d.ts +0 -27
- package/dist/agent/chat/relative-time.d.ts.map +0 -1
- package/dist/agent/chat/relative-time.js +0 -27
- package/src/agent/chat/relative-time.ts +0 -55
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Doctor's design-loop section: the stale-board notice and the optional-Playwright probe. A leaf:
|
|
2
|
+
// imports nothing from `./index`. Stat-walk only — never reads a file body, never throws.
|
|
3
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs'
|
|
4
|
+
import type { Dirent } from 'node:fs'
|
|
5
|
+
import { createRequire } from 'node:module'
|
|
6
|
+
import { join, resolve } from 'node:path'
|
|
7
|
+
|
|
8
|
+
const LAST_SHOT = join('.basalt', 'shots', 'last.json')
|
|
9
|
+
const SKIPPED_DIRS = new Set(['node_modules', 'dist', '.git', '.basalt'])
|
|
10
|
+
const UI_FILE = /\.(tsx|css)$/
|
|
11
|
+
/** Directories plus UI files visited before the walk gives up; other files are free, so a big non-UI tree cannot pin the notice on. */
|
|
12
|
+
const WALK_CAP = 5000
|
|
13
|
+
|
|
14
|
+
export const BOARD_NOTICE =
|
|
15
|
+
'UI changed since the last board — run basalt-ui shot <routes> and the basalt-design-reviewer (/basalt-design)'
|
|
16
|
+
export const PLAYWRIGHT_INSTALL = 'bun add -d playwright && bunx playwright install chromium'
|
|
17
|
+
|
|
18
|
+
/** `newest`: latest UI mtime in ms, null when none. `truncated`: the cap hit, so `newest` may be stale. */
|
|
19
|
+
type Walk = { newest: number | null; truncated: boolean }
|
|
20
|
+
|
|
21
|
+
function mtimeOf(path: string): number | null {
|
|
22
|
+
try {
|
|
23
|
+
return statSync(path, { throwIfNoEntry: false })?.mtimeMs ?? null
|
|
24
|
+
} catch {
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function walkUi(cwd: string, roots: string[], cap: number): Walk {
|
|
30
|
+
const walk: Walk = { newest: null, truncated: false }
|
|
31
|
+
const stack = roots.map((root) => resolve(cwd, root))
|
|
32
|
+
let visited = 0
|
|
33
|
+
for (let dir = stack.pop(); dir !== undefined; dir = stack.pop()) {
|
|
34
|
+
if (++visited > cap) return { ...walk, truncated: true }
|
|
35
|
+
let entries: Dirent[]
|
|
36
|
+
try {
|
|
37
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
38
|
+
} catch (error) {
|
|
39
|
+
// Only a missing dir means "no UI here"; anything else leaves the scan unknown.
|
|
40
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') walk.truncated = true
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
const path = join(dir, entry.name)
|
|
45
|
+
if (entry.isDirectory()) {
|
|
46
|
+
if (!SKIPPED_DIRS.has(entry.name)) stack.push(path)
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
if (!UI_FILE.test(entry.name)) continue
|
|
50
|
+
if (++visited > cap) return { ...walk, truncated: true }
|
|
51
|
+
const mtime = mtimeOf(path)
|
|
52
|
+
if (mtime !== null && (walk.newest === null || mtime > walk.newest)) walk.newest = mtime
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return walk
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The last board's time (ms), or null when `last.json` is absent, corrupt or has no parseable `at`. */
|
|
59
|
+
function lastBoardAt(cwd: string): number | null {
|
|
60
|
+
try {
|
|
61
|
+
const last: unknown = JSON.parse(readFileSync(resolve(cwd, LAST_SHOT), 'utf8'))
|
|
62
|
+
if (typeof last !== 'object' || last === null) return null
|
|
63
|
+
const at = (last as { at?: unknown }).at
|
|
64
|
+
if (typeof at !== 'string') return null
|
|
65
|
+
const ms = Date.parse(at)
|
|
66
|
+
return Number.isNaN(ms) ? null : ms
|
|
67
|
+
} catch {
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The notice line when a UI file is newer than the last board, no valid board exists, or the walk
|
|
74
|
+
* hit its cap (unknown is reported, never "fresh"); else null. The signal is mtime-based, so a
|
|
75
|
+
* checkout or rebase can fire it on unchanged UI — a documented trade-off for a stat-only check.
|
|
76
|
+
*/
|
|
77
|
+
export function staleBoardNotice(
|
|
78
|
+
cwd: string,
|
|
79
|
+
roots: string[],
|
|
80
|
+
walkCap: number = WALK_CAP,
|
|
81
|
+
): string | null {
|
|
82
|
+
const { newest, truncated } = walkUi(cwd, roots, walkCap)
|
|
83
|
+
if (truncated) return BOARD_NOTICE
|
|
84
|
+
if (newest === null) return null
|
|
85
|
+
const at = lastBoardAt(cwd)
|
|
86
|
+
return at === null || newest > at ? BOARD_NOTICE : null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Loads `<id>/package.json` from the consumer; throws when unresolvable. Injectable for tests. */
|
|
90
|
+
export type PackageLoader = (id: string) => { version?: string }
|
|
91
|
+
|
|
92
|
+
/** The consumer's Playwright version (`playwright`, then `playwright-core`), or null when absent. */
|
|
93
|
+
export function playwrightVersion(
|
|
94
|
+
cwd: string,
|
|
95
|
+
load: PackageLoader = createRequire(resolve(cwd, 'package.json')),
|
|
96
|
+
): string | null {
|
|
97
|
+
for (const name of ['playwright', 'playwright-core']) {
|
|
98
|
+
try {
|
|
99
|
+
return load(`${name}/package.json`).version ?? 'unknown'
|
|
100
|
+
} catch {
|
|
101
|
+
// try the next candidate
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Test seams for {@link designLoopLines}. */
|
|
108
|
+
export type DesignLoopProbes = {
|
|
109
|
+
notice?: (cwd: string, roots: string[]) => string | null
|
|
110
|
+
playwright?: (cwd: string) => string | null
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Doctor's design-loop section: advisory info lines only. They never count as a warning, so they
|
|
115
|
+
* cannot change doctor's verdict or its "All checks passed" line.
|
|
116
|
+
*/
|
|
117
|
+
export function designLoopLines(
|
|
118
|
+
cwd: string,
|
|
119
|
+
roots: string[],
|
|
120
|
+
probes: DesignLoopProbes = {},
|
|
121
|
+
): string[] {
|
|
122
|
+
const lines: string[] = []
|
|
123
|
+
const notice = (probes.notice ?? staleBoardNotice)(cwd, roots)
|
|
124
|
+
if (notice !== null) lines.push(` → ${notice}`)
|
|
125
|
+
const playwright = (probes.playwright ?? playwrightVersion)(cwd)
|
|
126
|
+
lines.push(
|
|
127
|
+
playwright === null
|
|
128
|
+
? ` → playwright is not installed (optional, needed by basalt-ui shot): ${PLAYWRIGHT_INSTALL}`
|
|
129
|
+
: ` ✓ playwright resolves (${playwright === 'unknown' ? 'version unknown' : playwright}; optional: basalt-ui shot)`,
|
|
130
|
+
)
|
|
131
|
+
return lines
|
|
132
|
+
}
|
package/src/cli/doctor.ts
CHANGED
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
scannableFiles,
|
|
34
34
|
shippedAssetPath,
|
|
35
35
|
} from './index'
|
|
36
|
+
import { designLoopLines } from './board-freshness'
|
|
37
|
+
import type { DesignLoopProbes } from './board-freshness'
|
|
36
38
|
import { parseJsonc } from './source-text'
|
|
37
39
|
import { resolveRoots } from './config'
|
|
38
40
|
import {
|
|
@@ -121,7 +123,11 @@ function aiMajorsAt(dir: string): Partial<Record<AiMajorField, number>> {
|
|
|
121
123
|
*
|
|
122
124
|
* Returns the exit code: 0 = all good, 1 = one or more hard failures or skipped checks.
|
|
123
125
|
*/
|
|
124
|
-
export function doctor(
|
|
126
|
+
export function doctor(
|
|
127
|
+
invocationCwd: string = process.cwd(),
|
|
128
|
+
flags: string[] = [],
|
|
129
|
+
designLoop: DesignLoopProbes = {},
|
|
130
|
+
): number {
|
|
125
131
|
if (conflictingProfileFlags('doctor', flags)) return 1
|
|
126
132
|
const project = resolveProjectDir(invocationCwd)
|
|
127
133
|
// Inside the app package of a monorepo the manifest is above: read the install root instead.
|
|
@@ -420,6 +426,9 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
420
426
|
for (const line of shell.warnings) warn(line)
|
|
421
427
|
}
|
|
422
428
|
|
|
429
|
+
// ── Design loop: advisory info lines (no warning count — they never change the verdict) ─────
|
|
430
|
+
if (profile !== 'tokens-only') lines.push(...designLoopLines(cwd, resolveRoots(cfg), designLoop))
|
|
431
|
+
|
|
423
432
|
// ── Report ──────────────────────────────────────────────────────────────────
|
|
424
433
|
lines.push('')
|
|
425
434
|
if (result.hardFailures === 0 && result.warnings === 0 && result.skipped === 0) {
|
package/src/cli/help.ts
CHANGED
|
@@ -43,6 +43,12 @@ export const COMMAND_OPTIONS: Record<string, Record<string, { type: 'string' | '
|
|
|
43
43
|
only: { type: 'string' },
|
|
44
44
|
},
|
|
45
45
|
'fonts:css': { out: { type: 'string' }, check: { type: 'boolean' } },
|
|
46
|
+
shot: {
|
|
47
|
+
base: { type: 'string' },
|
|
48
|
+
dist: { type: 'string' },
|
|
49
|
+
out: { type: 'string' },
|
|
50
|
+
states: { type: 'string' },
|
|
51
|
+
},
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
/** The first flag `cmd` does not accept, or null. Unknown commands return null — the dispatcher's
|
|
@@ -51,7 +57,7 @@ export function unknownFlag(cmd: string, flags: readonly string[]): string | nul
|
|
|
51
57
|
const options = COMMAND_OPTIONS[cmd]
|
|
52
58
|
if (options === undefined) return null
|
|
53
59
|
try {
|
|
54
|
-
parseArgs({ args: [...flags], options, strict: true, allowPositionals:
|
|
60
|
+
parseArgs({ args: [...flags], options, strict: true, allowPositionals: cmd === 'shot' })
|
|
55
61
|
return null
|
|
56
62
|
} catch (err) {
|
|
57
63
|
const message = err instanceof Error ? err.message : String(err)
|
|
@@ -65,7 +71,8 @@ export const USAGE =
|
|
|
65
71
|
'Usage: basalt-ui <--version | init [--no-merge-lint] |\n' +
|
|
66
72
|
' sync [--force] [--check] [--verbose] [--tokens-only|--framework] |\n' +
|
|
67
73
|
' check-theme [--audit-allows] |\n' +
|
|
68
|
-
' doctor [--tokens-only|--framework] | guard-hook | tokens:css | fonts:css
|
|
74
|
+
' doctor [--tokens-only|--framework] | guard-hook | tokens:css | fonts:css |\n' +
|
|
75
|
+
' shot <route…> | help>\n\n' +
|
|
69
76
|
'check-theme [--tokens-only|--framework] [--audit-allows]\n' +
|
|
70
77
|
' --audit-allows reports instead of scanning: every `theme-allow` annotation and every\n' +
|
|
71
78
|
' `basalt.exemptRules` entry, with what each one still suppresses — proved by re-running the\n' +
|
|
@@ -81,6 +88,11 @@ export const USAGE =
|
|
|
81
88
|
'fonts:css [--out <path>] [--check]\n' +
|
|
82
89
|
' Emit the shipped --basalt-font-* stacks as plain CSS — the typeface half of the token layer,\n' +
|
|
83
90
|
' otherwise reachable only by importing styles.css.\n\n' +
|
|
91
|
+
'shot <route…> (--base <url> | --dist <dir>) [--out <dir>] [--states <list>]\n' +
|
|
92
|
+
' Render routes in Chromium (Playwright from YOUR project: bun add -d playwright) and write\n' +
|
|
93
|
+
' board.html, metrics.json and png/* — every data-shot anchor × light/dark × desktop/mobile ×\n' +
|
|
94
|
+
' rest, hover, focus, tooltip, empty, loading, error. --dist serves a built SPA dir itself.\n' +
|
|
95
|
+
' Default --out .basalt/shots (emptied each run); .basalt/shots/last.json names the last out dir.\n\n' +
|
|
84
96
|
'doctor [--tokens-only|--framework]\n' +
|
|
85
97
|
' Checks THIS project only: the manifest exists, the oxlint preset is wired, the pre-commit\n' +
|
|
86
98
|
' hook runs check-theme (via `lefthook dump`), and the ai package major is consistent within\n' +
|
package/src/cli/index.ts
CHANGED
|
@@ -22,12 +22,13 @@ import { fileURLToPath } from 'node:url'
|
|
|
22
22
|
|
|
23
23
|
import { DEFAULT_GUARD_CONFIG, guardWaiverHint } from '../guard'
|
|
24
24
|
import type { GuardConfig, GuardKind, GuardSeverity } from '../guard'
|
|
25
|
-
import { RULE_NAMES, SKILL_NAMES } from '../surfaces'
|
|
25
|
+
import { AGENT_NAMES, RULE_NAMES, SKILL_NAMES } from '../surfaces'
|
|
26
26
|
import { checkTheme } from './check-theme'
|
|
27
27
|
import { doctor } from './doctor'
|
|
28
28
|
import { guardHook } from './guard-hook'
|
|
29
29
|
import { COMMAND_OPTIONS, USAGE, unknownFlag } from './help'
|
|
30
30
|
import { init } from './init'
|
|
31
|
+
import { shot } from './shot'
|
|
31
32
|
import { sync } from './sync'
|
|
32
33
|
import type { BasaltInstall } from './basalt-install'
|
|
33
34
|
import {
|
|
@@ -454,6 +455,8 @@ type TemplateVars = {
|
|
|
454
455
|
SERIES_MODULE_PATH: string
|
|
455
456
|
/** The consumer's configured roots as space-separated quoted oxfmt globs, e.g. `'apps/web/src/**'`. */
|
|
456
457
|
ROOTS_GLOBS: string
|
|
458
|
+
/** The roots a rule's `paths:` renders from: `basalt.roots` (init/sync write the inferred ones first), else {@link LEGACY_RULE_ROOTS}. */
|
|
459
|
+
RULE_ROOTS: string[]
|
|
457
460
|
/** Path to the shipped oxlint preset from the consumer dir — RESOLVED, never assumed at the root. */
|
|
458
461
|
OXLINT_PRESET_PATH: string
|
|
459
462
|
/** Path to the shipped lefthook preset from the consumer dir — same resolution. */
|
|
@@ -538,6 +541,7 @@ function buildTemplateVars(pkgRoot: string, cwd: string, cfg: BasaltConfig): Tem
|
|
|
538
541
|
ACCENT_HUE: cfg.accentHue ?? 'blue',
|
|
539
542
|
SERIES_MODULE_PATH: resolveSeriesModulePath(cfg),
|
|
540
543
|
ROOTS_GLOBS: resolveRoots(cfg).map(toRootGlob).join(' '),
|
|
544
|
+
RULE_ROOTS: cfg.roots ?? [],
|
|
541
545
|
OXLINT_PRESET_PATH: shippedAssetPath(install, cwd, OXLINT_FILES.preset),
|
|
542
546
|
LEFTHOOK_PRESET_PATH: shippedAssetPath(install, cwd, 'configs/lefthook.yml'),
|
|
543
547
|
BASALT_BIN: basaltBinCommand(install, cwd),
|
|
@@ -545,12 +549,42 @@ function buildTemplateVars(pkgRoot: string, cwd: string, cfg: BasaltConfig): Tem
|
|
|
545
549
|
}
|
|
546
550
|
}
|
|
547
551
|
|
|
552
|
+
/** Rule roots when nothing is declared or inferable — what the shipped rules matched before roots. */
|
|
553
|
+
const LEGACY_RULE_ROOTS = ['src', 'apps/**/src', 'packages/**/src']
|
|
554
|
+
|
|
555
|
+
const FRONT_MATTER = /^---\n[\s\S]*?\n---\n/
|
|
556
|
+
const RULE_PATHS_BLOCK = /^paths:\n(?: {2}- .*\n)+/m
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* A rule's front-matter `paths:` block rendered from `roots`: one `'<root>/**'` item per root,
|
|
560
|
+
* normalised (no `./`, no trailing slash) and single-quoted for YAML. Only the leading `---…---`
|
|
561
|
+
* block is touched. Front matter without `paths:` is returned unchanged; a `paths:` that is not the
|
|
562
|
+
* expected list shape, or a root that would match everywhere (`''`, `/`, absolute), throws.
|
|
563
|
+
*/
|
|
564
|
+
export function renderRulePaths(text: string, roots: readonly string[]): string {
|
|
565
|
+
const front = FRONT_MATTER.exec(text)?.[0]
|
|
566
|
+
if (front === undefined || !/^paths:/m.test(front)) return text
|
|
567
|
+
if (!RULE_PATHS_BLOCK.test(front)) throw new Error('rule `paths:` is not a list of ` - …` items')
|
|
568
|
+
const items = (roots.length > 0 ? roots : LEGACY_RULE_ROOTS).map((raw) => {
|
|
569
|
+
const root = raw.replace(/^(?:\.\/)+/, '').replace(/\/+$/, '')
|
|
570
|
+
if (/[\n\r]/.test(root)) throw new Error(`basalt.roots entry has a line break: ${raw}`)
|
|
571
|
+
if (raw.startsWith('/') || root === '') {
|
|
572
|
+
throw new Error(`basalt.roots entry must be a relative directory, got ${JSON.stringify(raw)}`)
|
|
573
|
+
}
|
|
574
|
+
return ` - '${(root === '.' ? '**' : `${root}/**`).replace(/'/g, "''")}'`
|
|
575
|
+
})
|
|
576
|
+
return (
|
|
577
|
+
front.replace(RULE_PATHS_BLOCK, () => `paths:\n${items.join('\n')}\n`) +
|
|
578
|
+
text.slice(front.length)
|
|
579
|
+
)
|
|
580
|
+
}
|
|
581
|
+
|
|
548
582
|
/** Substitute every `{{KEY}}` placeholder from the variable map; unknown keys are left verbatim. */
|
|
549
583
|
function fillTemplate(tpl: string, vars: TemplateVars): string {
|
|
550
584
|
const fill = (text: string): string =>
|
|
551
585
|
text.replace(/\{\{(\w+)\}\}/g, (m, key: string) => {
|
|
552
|
-
const v = (vars as Record<string,
|
|
553
|
-
return v
|
|
586
|
+
const v = (vars as Record<string, unknown>)[key]
|
|
587
|
+
return typeof v === 'string' ? v : m
|
|
554
588
|
})
|
|
555
589
|
// The marker is a YAML comment so the template stays valid YAML; GATE_STEPS itself carries
|
|
556
590
|
// placeholders, so it expands before the generic pass.
|
|
@@ -792,7 +826,10 @@ export function managedFiles(placement: PlacementFlags = ROOT_PLACEMENT): Manage
|
|
|
792
826
|
dest: `.claude/rules/basalt-${name}.md`,
|
|
793
827
|
mode: 'managed' as const,
|
|
794
828
|
source: `agent/rules/basalt-${name}.md`,
|
|
795
|
-
render: (ctx: RenderContext) =>
|
|
829
|
+
render: (ctx: RenderContext) => {
|
|
830
|
+
const text = readSource(ctx.pkgRoot, `agent/rules/basalt-${name}.md`)
|
|
831
|
+
return text === null ? null : renderRulePaths(text, ctx.vars.RULE_ROOTS)
|
|
832
|
+
},
|
|
796
833
|
}))
|
|
797
834
|
|
|
798
835
|
// Skills take the same managed path the rules do — Claude Code cannot load skills from
|
|
@@ -805,6 +842,14 @@ export function managedFiles(placement: PlacementFlags = ROOT_PLACEMENT): Manage
|
|
|
805
842
|
render: (ctx: RenderContext) => readSource(ctx.pkgRoot, `agent/skills/${name}/SKILL.md`),
|
|
806
843
|
}))
|
|
807
844
|
|
|
845
|
+
// Subagents load only walking UP from the session cwd, so the consumer root is the right home.
|
|
846
|
+
const agents: ManagedFile[] = AGENT_NAMES.map((name) => ({
|
|
847
|
+
dest: `.claude/agents/${name}.md`,
|
|
848
|
+
mode: 'managed' as const,
|
|
849
|
+
source: `agent/agents/${name}.md`,
|
|
850
|
+
render: (ctx: RenderContext) => readSource(ctx.pkgRoot, `agent/agents/${name}.md`),
|
|
851
|
+
}))
|
|
852
|
+
|
|
808
853
|
// AGENTS.md, not CLAUDE.md: Claude Code loads a repo-root AGENTS.md directly, but ANY CLAUDE.md
|
|
809
854
|
// in or above the cwd suppresses it — so the block must not be the reason a CLAUDE.md exists.
|
|
810
855
|
const agentsBlock: ManagedFile = {
|
|
@@ -940,7 +985,17 @@ export function managedFiles(placement: PlacementFlags = ROOT_PLACEMENT): Manage
|
|
|
940
985
|
// lefthook/CI config, and writing over or beside it is worse than not writing at all.
|
|
941
986
|
const rootTooling: ManagedFile[] = placement.isPackageRepoRoot ? [lefthook, ci] : []
|
|
942
987
|
|
|
943
|
-
return [
|
|
988
|
+
return [
|
|
989
|
+
...rules,
|
|
990
|
+
...skills,
|
|
991
|
+
...agents,
|
|
992
|
+
agentsBlock,
|
|
993
|
+
design,
|
|
994
|
+
oxfmt,
|
|
995
|
+
...rootTooling,
|
|
996
|
+
oxlintrc,
|
|
997
|
+
...scaffolds,
|
|
998
|
+
]
|
|
944
999
|
}
|
|
945
1000
|
|
|
946
1001
|
/**
|
|
@@ -1016,11 +1071,11 @@ export function readManifest(cwd: string): Manifest {
|
|
|
1016
1071
|
}
|
|
1017
1072
|
|
|
1018
1073
|
/**
|
|
1019
|
-
* The
|
|
1020
|
-
* decide which files `managedFiles()` places under them, so a rule or
|
|
1074
|
+
* The managed NAMESPACES whose membership is derived, not fixed: `RULE_NAMES`, `SKILL_NAMES` and
|
|
1075
|
+
* `AGENT_NAMES` decide which files `managedFiles()` places under them, so a rule, skill or agent that is RETIRED
|
|
1021
1076
|
* upstream leaves a file behind in every consumer that ever synced it — and Claude keeps loading it.
|
|
1022
1077
|
*
|
|
1023
|
-
* Scoped to these
|
|
1078
|
+
* Scoped to these patterns on purpose, and never applied to the manifest wholesale: several
|
|
1024
1079
|
* managed/seed entries are legitimately absent from `managedFiles()` for a run (`lefthook.yml` and
|
|
1025
1080
|
* `check.yml` when the package is not the repo root). Deleting a dest just because this run did not place it would
|
|
1026
1081
|
* remove a consumer's CI workflow on a monorepo.
|
|
@@ -1028,6 +1083,7 @@ export function readManifest(cwd: string): Manifest {
|
|
|
1028
1083
|
const RETIREABLE_DEST_PATTERNS: readonly RegExp[] = [
|
|
1029
1084
|
/^\.claude\/rules\/basalt-[a-z0-9-]+\.md$/,
|
|
1030
1085
|
/^\.claude\/skills\/basalt-[a-z0-9-]+\/SKILL\.md$/,
|
|
1086
|
+
/^\.claude\/agents\/basalt-[a-z0-9-]+\.md$/,
|
|
1031
1087
|
]
|
|
1032
1088
|
|
|
1033
1089
|
/** A tracked dest inside a derived namespace that this basalt version no longer ships. */
|
|
@@ -1222,9 +1278,21 @@ export function diffSummary(file: ManagedFile, state: UnitState): string {
|
|
|
1222
1278
|
}
|
|
1223
1279
|
|
|
1224
1280
|
/** Build the render context for a run from the package root + consumer cwd/config. */
|
|
1225
|
-
export function renderContext(cwd: string): RenderContext {
|
|
1281
|
+
export function renderContext(cwd: string, ruleRoots?: readonly string[]): RenderContext {
|
|
1226
1282
|
const pkgRoot = packageRoot()
|
|
1227
|
-
|
|
1283
|
+
const vars = buildTemplateVars(pkgRoot, cwd, readBasaltConfig(cwd))
|
|
1284
|
+
return { pkgRoot, vars: ruleRoots === undefined ? vars : { ...vars, RULE_ROOTS: [...ruleRoots] } }
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* The rule roots a run renders with: what `reconcileRoots` wrote, or — on `--check`, which writes
|
|
1289
|
+
* nothing — what a real sync would have written, so check and write never disagree.
|
|
1290
|
+
*/
|
|
1291
|
+
export function ruleRootsFor(state: RootsState): readonly string[] | undefined {
|
|
1292
|
+
if (state.kind === 'wrote') return state.roots
|
|
1293
|
+
return state.kind === 'declared' && state.declared.length === 0 && state.unscanned.length > 0
|
|
1294
|
+
? state.unscanned
|
|
1295
|
+
: undefined
|
|
1228
1296
|
}
|
|
1229
1297
|
|
|
1230
1298
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
@@ -1700,6 +1768,8 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
|
|
|
1700
1768
|
return tokensCss(flags, cwd)
|
|
1701
1769
|
case 'fonts:css':
|
|
1702
1770
|
return fontsCss(flags, cwd)
|
|
1771
|
+
case 'shot':
|
|
1772
|
+
return shot(flags, cwd)
|
|
1703
1773
|
default:
|
|
1704
1774
|
// Named, not just implied by a usage dump: a full-screen help block with no error line reads
|
|
1705
1775
|
// like the command ran and chose to print help. Reported by a consumer who passed
|
package/src/cli/init.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
pruneRetiredManagedFiles,
|
|
25
25
|
readManifest,
|
|
26
26
|
reconcileRoots,
|
|
27
|
+
ruleRootsFor,
|
|
27
28
|
renderContext,
|
|
28
29
|
reportPrune,
|
|
29
30
|
resolvePlacement,
|
|
@@ -99,7 +100,13 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
|
|
|
99
100
|
const rootsState = reconcileRoots(cwd, { write: true })
|
|
100
101
|
|
|
101
102
|
// Built AFTER the roots patch — every roots-derived template variable reads the key just written.
|
|
102
|
-
|
|
103
|
+
// Nothing inferable yet: init's own seeds create the app's `src/`, which a later sync will infer.
|
|
104
|
+
const appSrc = resolvePlacement(cwd).appRel
|
|
105
|
+
const ctx = renderContext(
|
|
106
|
+
cwd,
|
|
107
|
+
ruleRootsFor(rootsState) ??
|
|
108
|
+
(rootsState.kind === 'undetectable' ? [`${appSrc ? `${appSrc}/` : ''}src`] : undefined),
|
|
109
|
+
)
|
|
103
110
|
|
|
104
111
|
// `basalt-tokens.md` tells the consumer to wire `oxlint . && basalt-ui check-theme` into their
|
|
105
112
|
// lint, and init's own closing message says to run check-theme next — but nothing ever added a
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// theme-allow-file raw-hex — board.html is a standalone artefact: no basalt tokens exist in it
|
|
2
|
+
// theme-allow-file inline-spacing — board.html is a standalone artefact: no Mantine spacing props
|
|
3
|
+
/** `board.html`: one self-contained page (inline CSS, relative image paths) over a metrics.json. */
|
|
4
|
+
import { PAGE_ANCHOR, SCHEMES, VIEWPORTS } from './types'
|
|
5
|
+
import type { AnchorMetrics, Scale, ShotMetrics, ShotRecord, ShotState, Sides } from './types'
|
|
6
|
+
|
|
7
|
+
const esc = (s: string): string => s.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`)
|
|
8
|
+
|
|
9
|
+
const CSS = `
|
|
10
|
+
:root{color-scheme:light dark;--bg:#fff;--fg:#18181b;--mut:#71717a;--line:#d4d4d8;--bad:#b91c1c}
|
|
11
|
+
@media(prefers-color-scheme:dark){:root{--bg:#09090b;--fg:#fafafa;--mut:#a1a1aa;--line:#3f3f46;--bad:#f87171}}
|
|
12
|
+
body{margin:0;padding:24px;background:var(--bg);color:var(--fg);font:13px/1.45 system-ui,sans-serif}
|
|
13
|
+
h1,h2,h3,h4{margin:0 0 8px}h2{margin-top:40px;border-bottom:1px solid var(--line);padding-bottom:4px}
|
|
14
|
+
section{margin:24px 0}.row{display:grid;grid-template-columns:minmax(0,1fr) 380px;gap:24px;align-items:start}
|
|
15
|
+
.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-bottom:16px}
|
|
16
|
+
figure{margin:0;border:1px solid var(--line);padding:6px;min-width:0}
|
|
17
|
+
figcaption,.mut{color:var(--mut);font-size:11px}img{max-width:100%;height:auto;display:block}
|
|
18
|
+
.empty{display:flex;align-items:center;justify-content:center;min-height:60px;color:var(--mut);border:1px dashed var(--line);text-align:center;padding:6px}
|
|
19
|
+
.empty.error{color:var(--bad);border-color:var(--bad)}
|
|
20
|
+
table{border-collapse:collapse;width:100%;font-size:12px}th,td{border:1px solid var(--line);padding:3px 6px;text-align:left;vertical-align:top}
|
|
21
|
+
.bad{color:var(--bad)}aside{position:sticky;top:12px}
|
|
22
|
+
`
|
|
23
|
+
|
|
24
|
+
const sides = (s: Sides): string => `${s.top} ${s.right} ${s.bottom} ${s.left}`
|
|
25
|
+
|
|
26
|
+
const cell = (shot: ShotRecord | undefined, label: string): string => {
|
|
27
|
+
const caption = `<figcaption>${esc(label)}</figcaption>`
|
|
28
|
+
if (!shot) return `<figure><div class="empty">not captured</div>${caption}</figure>`
|
|
29
|
+
if (shot.status === 'ok' && shot.file) {
|
|
30
|
+
const note = shot.note ? ` · ${esc(shot.note)}` : ''
|
|
31
|
+
return `<figure><img src="${esc(shot.file)}" loading="lazy" alt="${esc(`${shot.name} ${label}`)}"><figcaption>${esc(label)}${note}</figcaption></figure>`
|
|
32
|
+
}
|
|
33
|
+
const note = shot.note ? `: ${esc(shot.note)}` : ''
|
|
34
|
+
return `<figure><div class="empty ${shot.status}">${shot.status}${note}</div>${caption}</figure>`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const metricsRow = (a: AnchorMetrics): string => {
|
|
38
|
+
const fails = a.contrast.failures.length
|
|
39
|
+
return (
|
|
40
|
+
`<tr><td>${a.scheme}/${a.viewport}</td><td>${a.box.width}×${a.box.height}</td>` +
|
|
41
|
+
`<td>${sides(a.padding)}</td><td>${a.gap.row}/${a.gap.column}</td><td>${a.radius}</td>` +
|
|
42
|
+
`<td>${a.borderWidth}</td><td>${a.fontSizes.join(', ')}</td><td>${a.emptyRatio}</td>` +
|
|
43
|
+
`<td class="${fails ? 'bad' : ''}">${a.contrast.min ?? '–'} (${fails} fail)</td></tr>`
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const metricsTable = (rows: AnchorMetrics[]): string => {
|
|
48
|
+
if (rows.length === 0) return '<p class="mut">no metrics (the anchor never rendered)</p>'
|
|
49
|
+
const failures = rows.flatMap((a) =>
|
|
50
|
+
a.contrast.failures.map(
|
|
51
|
+
(f) =>
|
|
52
|
+
`<li>${a.scheme}/${a.viewport} “${esc(f.text)}” ${f.ratio} (${esc(f.fg)} on ${esc(f.bg)}, ${f.fontSize}px)</li>`,
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
const assumed = rows
|
|
56
|
+
.filter((a) => a.contrast.backdrop === 'assumed-white')
|
|
57
|
+
.map((a) => `${a.scheme}/${a.viewport}`)
|
|
58
|
+
const nested = rows
|
|
59
|
+
.filter((a) => a.nested.length > 0)
|
|
60
|
+
.map(
|
|
61
|
+
(a) =>
|
|
62
|
+
`<li>${a.scheme}/${a.viewport}<ul>${a.nested.map((n) => `<li>${esc(n.path)} r${n.radius} p ${sides(n.padding)}</li>`).join('')}</ul></li>`,
|
|
63
|
+
)
|
|
64
|
+
return (
|
|
65
|
+
`<table><tr><th></th><th>box</th><th>padding</th><th>gap r/c</th><th>radius</th><th>border</th>` +
|
|
66
|
+
`<th>font px</th><th>empty</th><th>contrast min</th></tr>${rows.map(metricsRow).join('')}</table>` +
|
|
67
|
+
(assumed.length
|
|
68
|
+
? `<p class="bad">backdrop assumed white (no opaque ancestor background): ${assumed.join(', ')}</p>`
|
|
69
|
+
: '') +
|
|
70
|
+
(failures.length ? `<h4>Contrast failures</h4><ul class="bad">${failures.join('')}</ul>` : '') +
|
|
71
|
+
(nested.length ? `<h4>Nested surfaces</h4><ul>${nested.join('')}</ul>` : '')
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const grid = (shots: ShotRecord[], route: string, name: string, state: ShotState): string => {
|
|
76
|
+
const cells = VIEWPORTS.flatMap((viewport) =>
|
|
77
|
+
SCHEMES.map((scheme) =>
|
|
78
|
+
cell(
|
|
79
|
+
shots.find(
|
|
80
|
+
(s) =>
|
|
81
|
+
s.route === route &&
|
|
82
|
+
s.name === name &&
|
|
83
|
+
s.state === state &&
|
|
84
|
+
s.scheme === scheme &&
|
|
85
|
+
s.viewport === viewport,
|
|
86
|
+
),
|
|
87
|
+
`${scheme} · ${viewport}`,
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
)
|
|
91
|
+
return `<h4>${state}</h4><div class="grid">${cells.join('')}</div>`
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const anchorSection = (m: ShotMetrics, route: string, name: string): string =>
|
|
95
|
+
`<section><h3>${esc(name)}</h3><div class="row"><div>${m.states
|
|
96
|
+
.map((state) => grid(m.shots, route, name, state))
|
|
97
|
+
.join('')}</div><aside>${metricsTable(
|
|
98
|
+
m.anchors.filter((a) => a.route === route && a.name === name),
|
|
99
|
+
)}</aside></div></section>`
|
|
100
|
+
|
|
101
|
+
const stepList = (steps: Record<string, number>): string =>
|
|
102
|
+
Object.entries(steps)
|
|
103
|
+
.map(([k, v]) => `${esc(k)} ${v}`)
|
|
104
|
+
.join(' · ') || '–'
|
|
105
|
+
|
|
106
|
+
/** The resolved theme steps, shown once per distinct scale (usually one for every scheme × viewport). */
|
|
107
|
+
const scaleBlock = (scale: Scale[]): string => {
|
|
108
|
+
if (scale.length === 0) return ''
|
|
109
|
+
const groups = new Map<string, { scale: Scale; where: string[] }>()
|
|
110
|
+
for (const s of scale) {
|
|
111
|
+
const key = JSON.stringify([s.spacing, s.radius, s.fontSizes])
|
|
112
|
+
const group = groups.get(key) ?? { scale: s, where: [] }
|
|
113
|
+
group.where.push(`${s.scheme}/${s.viewport}`)
|
|
114
|
+
groups.set(key, group)
|
|
115
|
+
}
|
|
116
|
+
const rows = [...groups.values()].map(
|
|
117
|
+
({ scale: s, where }) =>
|
|
118
|
+
`<tr><td>${where.join(', ')}</td><td>${stepList(s.spacing)}</td><td>${stepList(s.radius)}</td><td>${stepList(s.fontSizes)}</td></tr>`,
|
|
119
|
+
)
|
|
120
|
+
return `<details open><summary>Theme scale (px)</summary><table><tr><th></th><th>spacing</th><th>radius</th><th>font size</th></tr>${rows.join('')}</table></details>`
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** An anchor's contact sheet: every state × scheme × viewport, labelled, on one standalone page. */
|
|
124
|
+
export function buildSheet(
|
|
125
|
+
route: string,
|
|
126
|
+
name: string,
|
|
127
|
+
states: readonly ShotState[],
|
|
128
|
+
shots: ShotRecord[],
|
|
129
|
+
): string {
|
|
130
|
+
const body = states.map((state) => grid(shots, route, name, state)).join('')
|
|
131
|
+
// Lazy images never load in a screenshot taken straight after `load`.
|
|
132
|
+
return (
|
|
133
|
+
`<!doctype html><html lang="en"><head><meta charset="utf-8"><style>${CSS}</style></head><body>` +
|
|
134
|
+
`<h3>${esc(name)} <span class="mut">${esc(route)}</span></h3>${body}</body></html>`
|
|
135
|
+
).replaceAll(' loading="lazy"', '')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function buildBoard(m: ShotMetrics): string {
|
|
139
|
+
const sections = m.routes.map((route) => {
|
|
140
|
+
const names = [
|
|
141
|
+
...new Set(
|
|
142
|
+
m.shots.filter((s) => s.route === route && s.name !== PAGE_ANCHOR).map((s) => s.name),
|
|
143
|
+
),
|
|
144
|
+
]
|
|
145
|
+
const anchors = names.length
|
|
146
|
+
? names.map((name) => anchorSection(m, route, name)).join('')
|
|
147
|
+
: '<p class="mut">no data-shot anchors on this route</p>'
|
|
148
|
+
return `<h2>${esc(route)}</h2><h3>full page</h3>${grid(m.shots, route, PAGE_ANCHOR, 'rest')}${anchors}`
|
|
149
|
+
})
|
|
150
|
+
return (
|
|
151
|
+
`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>basalt-ui shot</title><style>${CSS}</style></head><body>` +
|
|
152
|
+
`<h1>basalt-ui shot</h1><p class="mut">${esc(m.base)} · ${esc(m.generatedAt)} · states: ${m.states.join(', ')}</p>${m.scaleError ? `<p class="bad">scale unavailable: ${esc(m.scaleError)}</p>` : ''}${scaleBlock(m.scale)}${sections.join('')}</body></html>\n`
|
|
153
|
+
)
|
|
154
|
+
}
|