basalt-ui 2.14.0 → 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 +40 -0
- package/MIGRATING.md +19 -13
- 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/charts/legend.d.ts +4 -4
- 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/surfaces.d.ts +2 -0
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- package/llms.txt +2 -2
- package/package.json +1 -1
- package/src/charts/legend.tsx +4 -4
- 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/surfaces.ts +5 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playwright, resolved from the CONSUMER (it is not a basalt dependency) and typed through the
|
|
3
|
+
* minimal structural surface `shot` uses — the package never imports Playwright at build time.
|
|
4
|
+
* The real `playwright-core` types satisfy this surface, so callers keep their own types.
|
|
5
|
+
*/
|
|
6
|
+
import { createRequire } from 'node:module'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
|
|
9
|
+
import type { Scheme } from './types'
|
|
10
|
+
|
|
11
|
+
export const INSTALL_LINE =
|
|
12
|
+
'basalt-ui shot needs Playwright: bun add -d playwright && bunx playwright install chromium'
|
|
13
|
+
|
|
14
|
+
const KILL_TIMEOUT_MS = 10_000
|
|
15
|
+
|
|
16
|
+
export type Box = { x: number; y: number; width: number; height: number }
|
|
17
|
+
|
|
18
|
+
export type ShotOptions = {
|
|
19
|
+
path: string
|
|
20
|
+
animations: 'disabled'
|
|
21
|
+
caret: 'hide'
|
|
22
|
+
fullPage?: boolean
|
|
23
|
+
clip?: Box
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type PwLocator = {
|
|
27
|
+
first(): PwLocator
|
|
28
|
+
count(): Promise<number>
|
|
29
|
+
hover(options?: { timeout?: number }): Promise<void>
|
|
30
|
+
isVisible(): Promise<boolean>
|
|
31
|
+
boundingBox(): Promise<Box | null>
|
|
32
|
+
scrollIntoViewIfNeeded(): Promise<void>
|
|
33
|
+
waitFor(options: { state: 'visible'; timeout: number }): Promise<void>
|
|
34
|
+
screenshot(options: ShotOptions): Promise<unknown>
|
|
35
|
+
evaluate<R>(fn: (el: Element) => R): Promise<R>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type PwPage = {
|
|
39
|
+
goto(url: string, options: { waitUntil: 'load' | 'networkidle' }): Promise<unknown>
|
|
40
|
+
setDefaultTimeout(ms: number): void
|
|
41
|
+
locator(selector: string): PwLocator
|
|
42
|
+
evaluate<R>(expression: string): Promise<R>
|
|
43
|
+
evaluate<R, A>(fn: (arg: A) => R, arg: A): Promise<R>
|
|
44
|
+
setContent(html: string, options: { waitUntil: 'load' }): Promise<void>
|
|
45
|
+
keyboard: { press(key: string): Promise<void> }
|
|
46
|
+
mouse: { move(x: number, y: number): Promise<void> }
|
|
47
|
+
screenshot(options: ShotOptions): Promise<unknown>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type PwContext = {
|
|
51
|
+
newPage(): Promise<PwPage>
|
|
52
|
+
addInitScript(script: string): Promise<unknown>
|
|
53
|
+
close(): Promise<void>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type ContextOptions = {
|
|
57
|
+
viewport: { width: number; height: number }
|
|
58
|
+
deviceScaleFactor: number
|
|
59
|
+
isMobile: boolean
|
|
60
|
+
hasTouch: boolean
|
|
61
|
+
colorScheme: Scheme
|
|
62
|
+
reducedMotion: 'reduce'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type PwBrowser<C extends PwContext = PwContext> = {
|
|
66
|
+
newContext(options: ContextOptions): Promise<C>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type PwServer = { wsEndpoint(): string; kill(): Promise<void> }
|
|
70
|
+
export type Playwright<B extends PwBrowser = PwBrowser> = {
|
|
71
|
+
chromium: {
|
|
72
|
+
launchServer(options: { channel?: string; chromiumSandbox: boolean }): Promise<PwServer>
|
|
73
|
+
connect(wsEndpoint: string): Promise<B>
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Thrown for failures that print one line and exit 1 (no stack). */
|
|
78
|
+
export class ShotError extends Error {}
|
|
79
|
+
|
|
80
|
+
export type PlaywrightResolver = (cwd: string) => Playwright | null
|
|
81
|
+
|
|
82
|
+
export const isPlaywright = (mod: unknown): mod is Playwright => {
|
|
83
|
+
const chromium = (mod as { chromium?: Record<string, unknown> } | null)?.chromium
|
|
84
|
+
return (
|
|
85
|
+
typeof chromium?.['launchServer'] === 'function' && typeof chromium['connect'] === 'function'
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const resolvePlaywright: PlaywrightResolver = (cwd) => {
|
|
90
|
+
const require = createRequire(join(cwd, 'package.json'))
|
|
91
|
+
for (const name of ['playwright', 'playwright-core']) {
|
|
92
|
+
try {
|
|
93
|
+
const mod: unknown = require(name)
|
|
94
|
+
if (isPlaywright(mod)) return mod
|
|
95
|
+
} catch {
|
|
96
|
+
// not installed under this name: try the next
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const firstLine = (error: unknown): string =>
|
|
103
|
+
(error instanceof Error ? error.message : String(error)).split('\n')[0] ?? ''
|
|
104
|
+
|
|
105
|
+
/** `kill()` bounded by a hang guard: a graceful stop can wedge under Bun. */
|
|
106
|
+
function killBounded(server: PwServer): Promise<unknown> {
|
|
107
|
+
const guard = new Promise((resolve) => setTimeout(resolve, KILL_TIMEOUT_MS).unref())
|
|
108
|
+
return Promise.race([server.kill().catch(() => undefined), guard])
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type LaunchOptions = {
|
|
112
|
+
/** Tried in order; `undefined` is the bundled chromium. Default: bundled, then `chrome`. */
|
|
113
|
+
channels?: readonly (string | undefined)[]
|
|
114
|
+
/** Receives this run's kill, so the caller's signal handler can stop it. */
|
|
115
|
+
stops?: (() => unknown)[]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* One Chrome for `fn`, killed afterwards. `launchServer` + `connect` + `kill()` — a graceful
|
|
120
|
+
* `close()` hangs under Bun. Every failed launch keeps its first error line for the final message.
|
|
121
|
+
*/
|
|
122
|
+
export async function withBrowser<B extends PwBrowser, T>(
|
|
123
|
+
pw: Playwright<B>,
|
|
124
|
+
fn: (browser: B, channel: string) => Promise<T>,
|
|
125
|
+
{ channels = [undefined, 'chrome'], stops }: LaunchOptions = {},
|
|
126
|
+
): Promise<T> {
|
|
127
|
+
const chromiumSandbox = !process.env['CI']
|
|
128
|
+
const failures: string[] = []
|
|
129
|
+
for (const channel of channels) {
|
|
130
|
+
const label = channel ?? 'bundled chromium'
|
|
131
|
+
let server: PwServer | undefined
|
|
132
|
+
let browser: B
|
|
133
|
+
try {
|
|
134
|
+
server = await pw.chromium.launchServer(
|
|
135
|
+
channel ? { channel, chromiumSandbox } : { chromiumSandbox },
|
|
136
|
+
)
|
|
137
|
+
browser = await pw.chromium.connect(server.wsEndpoint())
|
|
138
|
+
} catch (error) {
|
|
139
|
+
failures.push(` ${label}: ${firstLine(error)}`)
|
|
140
|
+
if (server) await killBounded(server)
|
|
141
|
+
continue
|
|
142
|
+
}
|
|
143
|
+
const live = server
|
|
144
|
+
stops?.push(() => killBounded(live))
|
|
145
|
+
try {
|
|
146
|
+
return await fn(browser, channel ?? 'chromium')
|
|
147
|
+
} finally {
|
|
148
|
+
await killBounded(live)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
throw new ShotError([INSTALL_LINE, ...failures].join('\n'))
|
|
152
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { existsSync, statSync } from 'node:fs'
|
|
2
|
+
import { join, normalize, resolve, sep } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { ShotError } from './playwright'
|
|
5
|
+
|
|
6
|
+
/** Static server for a built SPA dir: real files as-is, extensionless misses fall back to index.html. */
|
|
7
|
+
export function serveDist(distDir: string): { origin: string; stop: () => void } {
|
|
8
|
+
const root = resolve(distDir)
|
|
9
|
+
if (!existsSync(root) || !statSync(root).isDirectory()) {
|
|
10
|
+
throw new ShotError(`--dist ${distDir} is not a directory`)
|
|
11
|
+
}
|
|
12
|
+
const fileFor = (pathname: string): string | null => {
|
|
13
|
+
const file = normalize(join(root, decodeURIComponent(pathname)))
|
|
14
|
+
if (file !== root && !file.startsWith(root + sep)) return null
|
|
15
|
+
if (existsSync(file) && statSync(file).isFile()) return file
|
|
16
|
+
if (/\.[a-z0-9]+$/i.test(pathname)) return null
|
|
17
|
+
const index = join(root, 'index.html')
|
|
18
|
+
return existsSync(index) ? index : null
|
|
19
|
+
}
|
|
20
|
+
const server = Bun.serve({
|
|
21
|
+
port: 0,
|
|
22
|
+
hostname: '127.0.0.1',
|
|
23
|
+
fetch(req) {
|
|
24
|
+
try {
|
|
25
|
+
const file = fileFor(new URL(req.url).pathname)
|
|
26
|
+
return file
|
|
27
|
+
? new Response(Bun.file(file), { headers: { 'cache-control': 'no-store' } })
|
|
28
|
+
: new Response('not found', { status: 404 })
|
|
29
|
+
} catch {
|
|
30
|
+
return new Response('bad request', { status: 400 })
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
return { origin: `http://127.0.0.1:${server.port}`, stop: () => void server.stop(true) }
|
|
35
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export const SCHEMES = ['light', 'dark'] as const
|
|
2
|
+
export const VIEWPORTS = ['desktop', 'mobile'] as const
|
|
3
|
+
export const STATES = ['rest', 'hover', 'focus', 'tooltip', 'empty', 'loading', 'error'] as const
|
|
4
|
+
/** The states a page opts into with `data-shot-states`; reached through the `shot-state` URL param. */
|
|
5
|
+
export const URL_STATES = ['empty', 'loading', 'error'] as const
|
|
6
|
+
|
|
7
|
+
/** The `name` of a route's full-page shot: not a valid `data-shot` value. */
|
|
8
|
+
export const PAGE_ANCHOR = '_page'
|
|
9
|
+
|
|
10
|
+
export type Scheme = (typeof SCHEMES)[number]
|
|
11
|
+
export type Viewport = (typeof VIEWPORTS)[number]
|
|
12
|
+
export type ShotState = (typeof STATES)[number]
|
|
13
|
+
|
|
14
|
+
export const VIEWPORT_SPECS: Record<Viewport, { width: number; height: number; mobile: boolean }> =
|
|
15
|
+
{
|
|
16
|
+
desktop: { width: 1440, height: 900, mobile: false },
|
|
17
|
+
mobile: { width: 390, height: 844, mobile: true },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type Sides = { top: number; right: number; bottom: number; left: number }
|
|
21
|
+
|
|
22
|
+
export type ContrastFailure = {
|
|
23
|
+
text: string
|
|
24
|
+
ratio: number
|
|
25
|
+
fg: string
|
|
26
|
+
bg: string
|
|
27
|
+
fontSize: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What the in-page measurer returns for one anchor. */
|
|
31
|
+
export type Measurement = {
|
|
32
|
+
box: { width: number; height: number }
|
|
33
|
+
padding: Sides
|
|
34
|
+
gap: { row: number; column: number }
|
|
35
|
+
radius: number
|
|
36
|
+
borderWidth: number
|
|
37
|
+
fontSizes: number[]
|
|
38
|
+
nested: { path: string; radius: number; padding: Sides }[]
|
|
39
|
+
emptyRatio: number
|
|
40
|
+
/** `min` is null when the anchor holds no text. */
|
|
41
|
+
contrast: {
|
|
42
|
+
min: number | null
|
|
43
|
+
failures: ContrastFailure[]
|
|
44
|
+
/** Set when some text sat on no opaque ancestor background and white was assumed. */
|
|
45
|
+
backdrop?: 'assumed-white'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type AnchorMetrics = Measurement & {
|
|
50
|
+
route: string
|
|
51
|
+
name: string
|
|
52
|
+
scheme: Scheme
|
|
53
|
+
viewport: Viewport
|
|
54
|
+
/** The anchor's contact sheet (`png/…__sheet.png`): every state × scheme × viewport on one image. Absent when it could not be written. */
|
|
55
|
+
sheet?: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type ShotRecord = {
|
|
59
|
+
route: string
|
|
60
|
+
name: string
|
|
61
|
+
scheme: Scheme
|
|
62
|
+
viewport: Viewport
|
|
63
|
+
state: ShotState
|
|
64
|
+
file: string | null
|
|
65
|
+
status: 'ok' | 'not-declared' | 'skipped' | 'error'
|
|
66
|
+
note?: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The theme's resolved steps (px) for one scheme × viewport; a missing custom property is omitted. */
|
|
70
|
+
export type Scale = {
|
|
71
|
+
scheme: Scheme
|
|
72
|
+
viewport: Viewport
|
|
73
|
+
spacing: Record<string, number>
|
|
74
|
+
radius: Record<string, number>
|
|
75
|
+
fontSizes: Record<string, number>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type ShotMetrics = {
|
|
79
|
+
version: 1
|
|
80
|
+
generatedAt: string
|
|
81
|
+
base: string
|
|
82
|
+
routes: string[]
|
|
83
|
+
viewports: Viewport[]
|
|
84
|
+
schemes: Scheme[]
|
|
85
|
+
states: ShotState[]
|
|
86
|
+
scale: Scale[]
|
|
87
|
+
/** Why `scale` is empty or partial; absent when it was read. */
|
|
88
|
+
scaleError?: string
|
|
89
|
+
anchors: AnchorMetrics[]
|
|
90
|
+
shots: ShotRecord[]
|
|
91
|
+
}
|
package/src/cli/sync.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
readManifest,
|
|
28
28
|
readSource,
|
|
29
29
|
reconcileRoots,
|
|
30
|
+
ruleRootsFor,
|
|
30
31
|
relativePosix,
|
|
31
32
|
renderContext,
|
|
32
33
|
reportPrune,
|
|
@@ -143,7 +144,7 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
143
144
|
|
|
144
145
|
// Before renderContext, which reads `basalt.roots` for the roots-derived template variables.
|
|
145
146
|
const rootsState = reconcileRoots(cwd, { write: opts.check !== true })
|
|
146
|
-
const ctx = renderContext(cwd)
|
|
147
|
+
const ctx = renderContext(cwd, ruleRootsFor(rootsState))
|
|
147
148
|
const manifest = readManifest(cwd)
|
|
148
149
|
const placement = resolvePlacement(cwd)
|
|
149
150
|
const { skip: seedSkip, skipped } = routerSeedPlan(cwd, placement.appRel)
|
package/src/surfaces.ts
CHANGED
|
@@ -655,6 +655,11 @@ export const SKILL_NAMES = [
|
|
|
655
655
|
),
|
|
656
656
|
] as const satisfies readonly SkillName[]
|
|
657
657
|
|
|
658
|
+
// ── PROJECTION 1c — AGENT_NAMES ───────────────────────────────────────────────────────────────────
|
|
659
|
+
|
|
660
|
+
/** The shipped subagents (`agent/agents/<name>.md`), installed at `.claude/agents/`. */
|
|
661
|
+
export const AGENT_NAMES = ['basalt-design-reviewer'] as const
|
|
662
|
+
|
|
658
663
|
// ── Token-layer-boundary-via-plugin membership ────────────────────────────────────────────────────
|
|
659
664
|
|
|
660
665
|
/**
|