basalt-ui 2.20.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 +39 -0
- package/MIGRATING.md +129 -12
- package/agent/agents/basalt-design-reviewer.md +22 -5
- package/agent/rules/basalt-tokens.md +2 -2
- 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/configs/oxlint-plugin.js +1 -0
- package/dist/charts/ChartCard.d.ts +6 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +4 -0
- package/dist/charts/state.d.ts +5 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +2 -0
- 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/dashboard/bar-list.d.ts +5 -2
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +2 -2
- package/dist/dashboard/meter-model.d.ts +34 -6
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +44 -13
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +167 -135
- package/dist/dashboard/meter.d.ts +11 -7
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +5 -1
- package/dist/dashboard/meter.module.css +18 -65
- package/dist/dashboard/meter.module.css.d.ts +2 -7
- package/dist/dashboard/query-state.d.ts +1 -1
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +3 -2
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +2 -1
- package/dist/dashboard/stat-strip.d.ts +17 -0
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +35 -5
- package/dist/dashboard/stat-strip.module.css +97 -14
- package/dist/dashboard/stat-strip.module.css.d.ts +4 -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/guard/index.d.ts +15 -2
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +14 -0
- package/dist/guard/palette.d.ts +51 -0
- package/dist/guard/palette.d.ts.map +1 -0
- package/dist/guard/palette.js +190 -0
- package/dist/guard/series-file.d.ts +15 -0
- package/dist/guard/series-file.d.ts.map +1 -0
- package/dist/guard/series-file.js +29 -0
- package/dist/guard/types.d.ts +3 -3
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +2 -0
- package/dist/theme/controls.module.css +10 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +18 -0
- 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 +7 -5
- package/package.json +1 -1
- package/src/charts/ChartCard.tsx +9 -1
- package/src/charts/state.tsx +9 -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/dashboard/bar-list.tsx +11 -8
- package/src/dashboard/meter-model.ts +91 -20
- package/src/dashboard/meter-parts.tsx +155 -115
- package/src/dashboard/meter.module.css +18 -65
- package/src/dashboard/meter.module.css.d.ts +2 -7
- package/src/dashboard/meter.tsx +18 -8
- package/src/dashboard/query-state.tsx +4 -7
- package/src/dashboard/stat-card.tsx +4 -1
- package/src/dashboard/stat-strip.module.css +97 -14
- package/src/dashboard/stat-strip.module.css.d.ts +4 -0
- package/src/dashboard/stat-strip.tsx +85 -5
- package/src/dashboard/visual-slot.ts +8 -0
- package/src/guard/index.ts +16 -4
- package/src/guard/palette.ts +261 -0
- package/src/guard/series-file.ts +51 -0
- package/src/guard/types.ts +3 -2
- package/src/surfaces.ts +2 -0
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +82 -48
- package/src/theme/controls.module.css +10 -0
- package/src/theme/index.ts +26 -0
- package/src/tokens/oklab.ts +97 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `series-palette` — the series file's palette is computed, never eyeballed.
|
|
3
|
+
*
|
|
4
|
+
* Pure: source text and the two scheme surfaces in, issues out. Reads every
|
|
5
|
+
* `defineSeries({ key: { light, dark } })` call as one ordered categorical group and judges each
|
|
6
|
+
* scheme against its own surface. The surfaces are the CALLER's to supply: this module is on the
|
|
7
|
+
* guard's import graph, which never loads the `derive` engine (see `guard/index.ts`'s header) —
|
|
8
|
+
* `series-file.ts` computes them. Colour math lives in `../tokens/oklab`; contrast is `hct.ts`'s
|
|
9
|
+
* WCAG ratio.
|
|
10
|
+
*/
|
|
11
|
+
import { contrastRatio } from '../tokens/hct'
|
|
12
|
+
import { deltaEOk, deltaEOkCvd, hexToOklch } from '../tokens/oklab'
|
|
13
|
+
|
|
14
|
+
export type SeriesScheme = 'light' | 'dark'
|
|
15
|
+
/** The surface each scheme's series are judged against. */
|
|
16
|
+
export type SeriesSurfaces = Record<SeriesScheme, string>
|
|
17
|
+
|
|
18
|
+
export type SeriesCheck =
|
|
19
|
+
| 'format'
|
|
20
|
+
| 'lightness'
|
|
21
|
+
| 'chroma'
|
|
22
|
+
| 'cvd'
|
|
23
|
+
| 'separation'
|
|
24
|
+
| 'contrast'
|
|
25
|
+
| 'order'
|
|
26
|
+
|
|
27
|
+
export type SeriesEntry = {
|
|
28
|
+
readonly key: string
|
|
29
|
+
readonly light: string
|
|
30
|
+
readonly dark: string
|
|
31
|
+
/** 1-based line of the entry in the scanned source. */
|
|
32
|
+
readonly line: number
|
|
33
|
+
}
|
|
34
|
+
export type SeriesGroup = { readonly line: number; readonly entries: readonly SeriesEntry[] }
|
|
35
|
+
|
|
36
|
+
export type SeriesIssue = {
|
|
37
|
+
readonly check: SeriesCheck
|
|
38
|
+
readonly scheme: SeriesScheme
|
|
39
|
+
readonly keys: readonly string[]
|
|
40
|
+
readonly measured: number
|
|
41
|
+
readonly threshold: number
|
|
42
|
+
/** Line of the first named key. */
|
|
43
|
+
readonly line: number
|
|
44
|
+
readonly message: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* OKLCH lightness bands, per scheme.
|
|
49
|
+
* - light [0.43, 0.77] — the brief's band: below 0.43 a series reads as ink, above 0.77 it washes
|
|
50
|
+
* out on the panel (3:1 bites earlier, near L 0.67, on the default light panel).
|
|
51
|
+
* - dark [0.58, 0.88] — lower bound is where a hue clears 3:1 against the default dark panel
|
|
52
|
+
* (#2b2b2e, L 0.29 → L ≈ 0.56, rounded up for margin); the upper bound keeps a clear step below
|
|
53
|
+
* white so a bright series does not glow against the dark page.
|
|
54
|
+
*/
|
|
55
|
+
export const LIGHTNESS_BAND: Record<SeriesScheme, readonly [number, number]> = {
|
|
56
|
+
light: [0.43, 0.77],
|
|
57
|
+
dark: [0.58, 0.88],
|
|
58
|
+
}
|
|
59
|
+
/** Minimum OKLCH chroma of a categorical hue. */
|
|
60
|
+
export const CHROMA_FLOOR = 0.1
|
|
61
|
+
/** Minimum OKLab ΔE×100 between ADJACENT series under protanopia and deuteranopia. */
|
|
62
|
+
export const CVD_ADJACENT_MIN = 8
|
|
63
|
+
/** Minimum OKLab ΔE×100 of the worst pair in a group, normal vision. */
|
|
64
|
+
export const SEPARATION_MIN = 15
|
|
65
|
+
/** Minimum WCAG contrast of a series against its scheme's surface. */
|
|
66
|
+
export const CONTRAST_MIN = 3
|
|
67
|
+
/** More categorical series than this and the next one folds into Other. */
|
|
68
|
+
export const MAX_SERIES = 8
|
|
69
|
+
/** The one escape: a series keyed `other` is deliberately neutral — exempt from the chroma floor only. */
|
|
70
|
+
export const NEUTRAL_KEY = 'other'
|
|
71
|
+
|
|
72
|
+
const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i
|
|
73
|
+
|
|
74
|
+
/** The string literal after `light:` / `dark:`, in either order. */
|
|
75
|
+
const ENTRY =
|
|
76
|
+
/([A-Za-z_$][\w$]*|'[^']+'|"[^"]+")\s*:\s*\{\s*(?:light\s*:\s*(['"])(.*?)\2\s*,\s*dark\s*:\s*(['"])(.*?)\4|dark\s*:\s*(['"])(.*?)\6\s*,\s*light\s*:\s*(['"])(.*?)\8)/g
|
|
77
|
+
|
|
78
|
+
const lineOf = (text: string, at: number): number => text.slice(0, at).split('\n').length
|
|
79
|
+
|
|
80
|
+
/** Every `defineSeries(...)` call in `source`, as an ordered group of its literal `{ light, dark }` hex pairs. */
|
|
81
|
+
export function parseSeriesGroups(source: string): SeriesGroup[] {
|
|
82
|
+
const groups: SeriesGroup[] = []
|
|
83
|
+
for (const call of source.matchAll(/\bdefineSeries\s*\(/g)) {
|
|
84
|
+
const open = (call.index ?? 0) + call[0].length
|
|
85
|
+
const lineStart = source.lastIndexOf('\n', call.index ?? 0) + 1
|
|
86
|
+
if (/^\s*(?:\/\/|\*|\/\*)/.test(source.slice(lineStart, call.index))) continue
|
|
87
|
+
let depth = 1
|
|
88
|
+
let end = open
|
|
89
|
+
while (end < source.length && depth > 0) {
|
|
90
|
+
const ch = source[end]
|
|
91
|
+
if (ch === '(') depth += 1
|
|
92
|
+
else if (ch === ')') depth -= 1
|
|
93
|
+
end += 1
|
|
94
|
+
}
|
|
95
|
+
const body = source.slice(open, end)
|
|
96
|
+
const entries = [...body.matchAll(ENTRY)].map((m): SeriesEntry => {
|
|
97
|
+
const light = m[3] ?? m[9] ?? ''
|
|
98
|
+
const dark = m[5] ?? m[7] ?? ''
|
|
99
|
+
return {
|
|
100
|
+
key: (m[1] ?? '').replace(/^['"]|['"]$/g, ''),
|
|
101
|
+
light: light.trim(),
|
|
102
|
+
dark: dark.trim(),
|
|
103
|
+
line: lineOf(source, open + (m.index ?? 0)),
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
groups.push({ line: lineOf(source, call.index ?? 0), entries })
|
|
107
|
+
}
|
|
108
|
+
return groups
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const fix = (n: number, digits = 2): string => n.toFixed(digits)
|
|
112
|
+
|
|
113
|
+
/** Judge every group against the six checks. */
|
|
114
|
+
export function auditSeriesGroups(
|
|
115
|
+
groups: readonly SeriesGroup[],
|
|
116
|
+
surfaces: SeriesSurfaces,
|
|
117
|
+
): SeriesIssue[] {
|
|
118
|
+
const issues: SeriesIssue[] = []
|
|
119
|
+
for (const group of groups) {
|
|
120
|
+
const { entries: allEntries } = group
|
|
121
|
+
const lineOfKey = (key: string) => allEntries.find((e) => e.key === key)?.line ?? group.line
|
|
122
|
+
|
|
123
|
+
const categorical = allEntries.filter((e) => e.key !== NEUTRAL_KEY)
|
|
124
|
+
if (categorical.length > MAX_SERIES) {
|
|
125
|
+
const extra = categorical.slice(MAX_SERIES).map((e) => e.key)
|
|
126
|
+
issues.push({
|
|
127
|
+
check: 'order',
|
|
128
|
+
scheme: 'light',
|
|
129
|
+
keys: extra,
|
|
130
|
+
measured: categorical.length,
|
|
131
|
+
threshold: MAX_SERIES,
|
|
132
|
+
line: lineOfKey(extra[0] ?? ''),
|
|
133
|
+
message: `${categorical.length} series in one group (max ${MAX_SERIES}) — ${extra.join(', ')} should fold into \`${NEUTRAL_KEY}\``,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (const scheme of ['light', 'dark'] as const) {
|
|
138
|
+
const [lo, hi] = LIGHTNESS_BAND[scheme]
|
|
139
|
+
const value = (e: SeriesEntry) => e[scheme]
|
|
140
|
+
// A value that is not `#rgb` / `#rrggbb` (an alpha hex, a colour name, a typo) cannot be
|
|
141
|
+
// measured — it is reported, and left out of this scheme's other checks rather than guessed at.
|
|
142
|
+
const entries = allEntries.filter((e) => {
|
|
143
|
+
if (HEX.test(value(e))) return true
|
|
144
|
+
issues.push({
|
|
145
|
+
check: 'format',
|
|
146
|
+
scheme,
|
|
147
|
+
keys: [e.key],
|
|
148
|
+
measured: 0,
|
|
149
|
+
threshold: 0,
|
|
150
|
+
line: e.line,
|
|
151
|
+
message: `${e.key} (${scheme}) "${value(e)}" is not a #rgb or #rrggbb hex — it cannot be checked`,
|
|
152
|
+
})
|
|
153
|
+
return false
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
for (const e of entries) {
|
|
157
|
+
const { L, C } = hexToOklch(value(e))
|
|
158
|
+
if (L < lo || L > hi) {
|
|
159
|
+
issues.push({
|
|
160
|
+
check: 'lightness',
|
|
161
|
+
scheme,
|
|
162
|
+
keys: [e.key],
|
|
163
|
+
measured: L,
|
|
164
|
+
threshold: L < lo ? lo : hi,
|
|
165
|
+
line: e.line,
|
|
166
|
+
message: `${e.key} (${scheme}) OKLCH lightness ${fix(L)} is outside ${lo}–${hi}`,
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
if (e.key !== NEUTRAL_KEY && C < CHROMA_FLOOR) {
|
|
170
|
+
issues.push({
|
|
171
|
+
check: 'chroma',
|
|
172
|
+
scheme,
|
|
173
|
+
keys: [e.key],
|
|
174
|
+
measured: C,
|
|
175
|
+
threshold: CHROMA_FLOOR,
|
|
176
|
+
line: e.line,
|
|
177
|
+
message: `${e.key} (${scheme}) OKLCH chroma ${fix(C, 3)} is below ${CHROMA_FLOOR} — a categorical hue must read as a hue (key a deliberately neutral series \`${NEUTRAL_KEY}\`)`,
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
const ratio = contrastRatio(value(e), surfaces[scheme])
|
|
181
|
+
if (ratio < CONTRAST_MIN) {
|
|
182
|
+
issues.push({
|
|
183
|
+
check: 'contrast',
|
|
184
|
+
scheme,
|
|
185
|
+
keys: [e.key],
|
|
186
|
+
measured: ratio,
|
|
187
|
+
threshold: CONTRAST_MIN,
|
|
188
|
+
line: e.line,
|
|
189
|
+
message: `${e.key} (${scheme}) contrast ${fix(ratio)}:1 against the surface is below ${CONTRAST_MIN}:1`,
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Cycling: an identical colour twice in one scheme is one series standing in for two.
|
|
195
|
+
const seen = new Map<string, string>()
|
|
196
|
+
const duplicated = new Set<string>()
|
|
197
|
+
for (const e of entries) {
|
|
198
|
+
const first = seen.get(value(e).toLowerCase())
|
|
199
|
+
if (first === undefined) seen.set(value(e).toLowerCase(), e.key)
|
|
200
|
+
else {
|
|
201
|
+
duplicated.add(`${first}|${e.key}`)
|
|
202
|
+
issues.push({
|
|
203
|
+
check: 'order',
|
|
204
|
+
scheme,
|
|
205
|
+
keys: [first, e.key],
|
|
206
|
+
measured: 0,
|
|
207
|
+
threshold: SEPARATION_MIN,
|
|
208
|
+
line: e.line,
|
|
209
|
+
message: `${first} and ${e.key} (${scheme}) are the same colour ${value(e)} — a group does not cycle`,
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Adjacent pairs, worst of the two dichromacies.
|
|
215
|
+
for (let i = 1; i < entries.length; i += 1) {
|
|
216
|
+
const a = entries[i - 1] as SeriesEntry
|
|
217
|
+
const b = entries[i] as SeriesEntry
|
|
218
|
+
if (duplicated.has(`${a.key}|${b.key}`)) continue
|
|
219
|
+
const sims = (['protan', 'deutan'] as const).map(
|
|
220
|
+
(kind) => [kind, deltaEOkCvd(value(a), value(b), kind)] as const,
|
|
221
|
+
)
|
|
222
|
+
const [kind, worst] = sims.reduce((m, s) => (s[1] < m[1] ? s : m))
|
|
223
|
+
if (worst < CVD_ADJACENT_MIN) {
|
|
224
|
+
issues.push({
|
|
225
|
+
check: 'cvd',
|
|
226
|
+
scheme,
|
|
227
|
+
keys: [a.key, b.key],
|
|
228
|
+
measured: worst,
|
|
229
|
+
threshold: CVD_ADJACENT_MIN,
|
|
230
|
+
line: b.line,
|
|
231
|
+
message: `${a.key} → ${b.key} (${scheme}) are ΔE ${fix(worst, 1)} apart under ${kind === 'protan' ? 'protanopia' : 'deuteranopia'}, below ${CVD_ADJACENT_MIN}`,
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Worst pair over the whole group, normal vision (identical pairs are `order`'s).
|
|
237
|
+
let worstPair: { a: SeriesEntry; b: SeriesEntry; de: number } | null = null
|
|
238
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
239
|
+
for (let j = i + 1; j < entries.length; j += 1) {
|
|
240
|
+
const a = entries[i] as SeriesEntry
|
|
241
|
+
const b = entries[j] as SeriesEntry
|
|
242
|
+
if (duplicated.has(`${a.key}|${b.key}`)) continue
|
|
243
|
+
const de = deltaEOk(value(a), value(b))
|
|
244
|
+
if (worstPair === null || de < worstPair.de) worstPair = { a, b, de }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (worstPair !== null && worstPair.de < SEPARATION_MIN) {
|
|
248
|
+
issues.push({
|
|
249
|
+
check: 'separation',
|
|
250
|
+
scheme,
|
|
251
|
+
keys: [worstPair.a.key, worstPair.b.key],
|
|
252
|
+
measured: worstPair.de,
|
|
253
|
+
threshold: SEPARATION_MIN,
|
|
254
|
+
line: worstPair.b.line,
|
|
255
|
+
message: `${worstPair.a.key} and ${worstPair.b.key} (${scheme}) are only ΔE ${fix(worstPair.de, 1)} apart, below ${SEPARATION_MIN}`,
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return issues
|
|
261
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `series-palette`: the series module as a FILE. Judges each `defineSeries` group, wraps the issues
|
|
3
|
+
* as findings, and reads the file with the surfaces derived from the default theme. Kept out of
|
|
4
|
+
* `guard/index.ts`'s import graph on purpose — that graph is on the PreToolUse hook path and never
|
|
5
|
+
* loads colour math or the `derive` engine; this one does. `check-theme` is the only caller.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
8
|
+
import { resolve } from 'node:path'
|
|
9
|
+
|
|
10
|
+
import { DEFAULT_DERIVE_CONFIG, deriveTokens } from '../tokens/derive'
|
|
11
|
+
import { isRuleExempt, severityOf } from './index'
|
|
12
|
+
import { auditSeriesGroups, parseSeriesGroups } from './palette'
|
|
13
|
+
import type { SeriesSurfaces } from './palette'
|
|
14
|
+
import type { Finding, GuardConfig } from './types'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Judge ONE series file's palette: one finding per failed check, naming the key(s), scheme,
|
|
18
|
+
* measured number and threshold. The series module is exempt from every line-scan kind, so it is
|
|
19
|
+
* judged here instead. Honors `severity` and `exemptRules` like any other kind.
|
|
20
|
+
*/
|
|
21
|
+
export function checkSeriesPalette(
|
|
22
|
+
source: string,
|
|
23
|
+
relPath: string,
|
|
24
|
+
cfg: GuardConfig,
|
|
25
|
+
surfaces: SeriesSurfaces,
|
|
26
|
+
): Finding[] {
|
|
27
|
+
if (isRuleExempt('series-palette', relPath, cfg.exemptRules)) return []
|
|
28
|
+
return auditSeriesGroups(parseSeriesGroups(source), surfaces).map((issue) => ({
|
|
29
|
+
relPath,
|
|
30
|
+
line: issue.line,
|
|
31
|
+
token: issue.keys.join(', '),
|
|
32
|
+
text: issue.message,
|
|
33
|
+
kind: 'series-palette' as const,
|
|
34
|
+
severity: severityOf('series-palette', cfg),
|
|
35
|
+
}))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Findings for the series module at `<cwd>/<rel>`; none if it does not exist. Surfaces are the
|
|
40
|
+
* derive engine's default `surface.panel` (a chart sits on a panel) — a consumer's `derive`
|
|
41
|
+
* overrides are not read.
|
|
42
|
+
*/
|
|
43
|
+
export function checkSeriesModule(cwd: string, rel: string, cfg: GuardConfig): Finding[] {
|
|
44
|
+
const file = resolve(cwd, rel)
|
|
45
|
+
if (!existsSync(file)) return []
|
|
46
|
+
const { panel } = deriveTokens(DEFAULT_DERIVE_CONFIG).surface
|
|
47
|
+
return checkSeriesPalette(readFileSync(file, 'utf8'), rel, cfg, {
|
|
48
|
+
light: panel.light,
|
|
49
|
+
dark: panel.dark,
|
|
50
|
+
})
|
|
51
|
+
}
|
package/src/guard/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Guard types — Mantine-free, dependency-free (zero imports beyond TS types).
|
|
3
3
|
*
|
|
4
|
-
* GuardKind is the closed set of
|
|
4
|
+
* GuardKind is the closed set of 27 violation kinds the theme guard can emit. Retired kinds
|
|
5
5
|
* (`unframed-chart`, `raw-visx-axis`, `chart-missing-aria-label`) stay recognized ids in
|
|
6
6
|
* `PLUGIN_RULE_IDS`/`KNOWN_RULE_IDS` so an existing `theme-allow <id>` reads as a dead waiver, not
|
|
7
7
|
* a typo.
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* GuardConfig is the per-run configuration that drives checkSource.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
/** The
|
|
12
|
+
/** The 27 theme-guard violation kinds. */
|
|
13
13
|
export type GuardKind =
|
|
14
14
|
| 'raw-hex'
|
|
15
15
|
| 'raw-color-fn'
|
|
@@ -37,6 +37,7 @@ export type GuardKind =
|
|
|
37
37
|
| 'raw-selection-control'
|
|
38
38
|
| 'raw-media-query'
|
|
39
39
|
| 'unknown-vx-token'
|
|
40
|
+
| 'series-palette'
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* How hard a finding lands. `error` fails the build; `warn` reports and passes.
|
package/src/surfaces.ts
CHANGED
|
@@ -347,6 +347,8 @@ export const SURFACES = {
|
|
|
347
347
|
'surface-shadow-override',
|
|
348
348
|
// A `var(--vx-*)` naming a token basalt no longer (or never) emits.
|
|
349
349
|
'unknown-vx-token',
|
|
350
|
+
// The series file's computed palette checks (lightness, chroma, CVD separation, contrast).
|
|
351
|
+
'series-palette',
|
|
350
352
|
// Not a token kind — the kind that judges the ANNOTATION rather than the code. It lands here
|
|
351
353
|
// because `agent/rules/basalt-tokens.md` is where the `theme-allow` grammar is documented
|
|
352
354
|
// (said once, on purpose), so this is the header that must name its enforcement.
|