jukebox
All repositories: gitoria
6.9 KB
#!/usr/bin/env node// theme/check-theme.mjs — THE THEME GATE HELPER an app runs: it flags what bypasses the WorldAPI theme in the app's own code.// node theme/check-theme.mjs [appDir] [--ignore <path prefix>]…// 1. HARD-CODED COLOURS: #hex, rgb()/rgba(), hsl()/hsla(), oklch(), and named colours (white, black, red …) in .hl and .css// files. Colours come from the theme's named tokens (shared/tokens.hl, `colorText`, 'var(--color-text)'). A fallback inside// `var(--token, …)` is allowed (the components of components.hybriel carry those so a copy works without the theme).// 2. DECORATIVE BORDERS: any border / borderTop … / borderColor that is not 0 / none. Allowed only where a border MEANS// something (docs/design-rules.md): on a line about details/summary (foldables), drop zones, focus or an invalid field,// or on a line that says so with the comment `// functional: <why>`.// 3. CORNER RADII: every borderRadius / borderTopLeftRadius … (css: border-radius, border-top-left-radius …) is one of the two// theme radii — radiusSmall (5px: buttons, pills, fields, tags, menu items, chips) or radiusLarge (10px: panels, modals,// popovers, dropdowns, tiles/posters), in css 'var(--radius-small)' / 'var(--radius-large)' — or 0, or '50%' for round// things (avatars, check circles). Each corner of a list counts ('radiusLarge + ' ' + radiusLarge + ' 0 0'' is fine).// Never scanned: plugins/ bin/ node_modules/ storage/ .scratch/ .git/ .sessions/ and shared/tokens.hl (the one place for raw// values). More paths to skip (e.g. a vendored component folder whose frames the theme removes): --ignore, or one prefix per// line in `.check-theme-ignore` in the app folder.// Output: one `file:line: problem — text` per finding, then `check-theme: N files, M problems`; exit 1 when M > 0.import { readFileSync, readdirSync, statSync, existsSync } from 'node:fs';import { join, relative, resolve } from 'node:path';const args = process.argv.slice(2);let dir = '.';const ignore = ['plugins/', 'bin/', 'node_modules/', 'storage/', '.scratch/', '.git/', '.sessions/', 'shared/tokens.hl'];for (let i = 0; i < args.length; i++) {if (args[i] === '--ignore') ignore.push(args[++i]);else dir = args[i];}const APP = resolve(dir);const ignoreFile = join(APP, '.check-theme-ignore');if (existsSync(ignoreFile)) {for (const line of readFileSync(ignoreFile, 'utf8').split('\n')) {const p = line.replace(/#.*/, '').trim();if (p) ignore.push(p);}}function files(d) {const out = [];for (const name of readdirSync(d)) {const full = join(d, name);const rel = relative(APP, full);const st = statSync(full);if (ignore.some(p => rel === p.replace(/\/$/, '') || rel.startsWith(p.endsWith('/') ? p : p + '/') || rel === p)) continue;if (st.isDirectory()) out.push(...files(full));else if (/\.(hl|css)$/.test(name)) out.push(full);}return out;}const NAMED = 'white|black|red|green|blue|gray|grey|yellow|orange|purple|pink|brown|silver|navy|teal|maroon|olive|lime|aqua|fuchsia|cyan|magenta|gold|indigo|violet';const COLOUR = new RegExp(`(#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3}(?:[0-9a-fA-F]{2})?)?|#[0-9a-fA-F]{4})(?![0-9a-zA-Z_-])|\\b(?:rgba?|hsla?|oklch|oklab|lab|lch|hwb)\\(`);const NAMED_RE = new RegExp(`[=:]\\s*['"]?[^'";]*\\b(${NAMED})\\b`, 'i');// a css declaration that sets a colour: hl (`color = '…'`, `background = …`) or css (`color: …`)const COLOUR_PROP = /\b(color|background(?:Color|-color)?|fill|stroke|borderColor|border-color|outlineColor|outline-color|boxShadow|box-shadow|accentColor|accent-color|caretColor|caret-color|textDecorationColor)\s*[=:]/i;const BORDER = /\b(border(?:Top|Right|Bottom|Left|Block|Inline)?(?:Start|End)?(?:Color|Width|Style)?|border(?:-(?:top|right|bottom|left|block|inline))?(?:-(?:start|end))?(?:-(?:color|width|style))?)\s*([=:])\s*(?:'([^']*)'|"([^"]*)"|([^;}\s]+))/g;const FUNCTIONAL = /details|summary|drop-zone|dropZone|\.drop|:focus|focus-visible|aria-invalid|\/\/\s*functional/i;const NO_BORDER = /^\s*(0|0px|none|0 none|transparent|inherit|initial|unset)\s*$/i;// a radius: hl `borderRadius = <quoted strings / names joined by +>`, css `border-radius: <value>`const RADIUS_NAME = 'border(?:Top|Bottom|Start|End)?(?:Left|Right|Start|End)?Radius|border(?:-(?:top|bottom|start|end)-(?:left|right|start|end))?-radius';const RADIUS_HL = new RegExp(`\\b(${RADIUS_NAME})'?\\s*=\\s*((?:'[^']*'|"[^"]*"|[\\w.$-]+)(?:\\s*\\+\\s*(?:'[^']*'|"[^"]*"|[\\w.$-]+))*)`, 'g');const RADIUS_CSS = new RegExp(`\\b(${RADIUS_NAME})\\s*:\\s*([^;}'"]+)`, 'g');const RADIUS_OK = /^(0|0px|50%|radiusSmall|radiusLarge|var\(--radius-(?:small|large)\)|inherit|initial|unset)$/;// the corner values of one radius that are not the theme's two (a token's fallback `var(--radius-small, 5px)` is fine)function badRadii(value) {const words = value.replace(/var\(\s*--radius-(small|large)\s*(?:,(?:[^()]|\([^()]*\))*)?\)/g, 'var(--radius-$1)').replace(/['"+]/g, ' ').split(/[\s/]+/);return words.filter(w => w && !RADIUS_OK.test(w));}// strip comments (whole-line `//`, trailing ` // …`, /* … */ on one line)function uncomment(line) {const s = line.replace(/\/\*.*?\*\//g, '');if (/^\s*\/\//.test(s)) return '';return s.replace(/\s\/\/\s.*$/, '');}// … and the allowed var(--x, fallback) fallbacksfunction code(line) {return uncomment(line).replace(/var\(\s*--[\w-]+\s*,\s*(?:[^()]|\([^()]*\))*\)/g, 'var()');}let problems = 0;const list = files(APP);for (const f of list) {const lines = readFileSync(f, 'utf8').split('\n');lines.forEach((raw, i) => {const s = code(raw);if (!s.trim()) return;const where = `${relative(APP, f)}:${i + 1}`;const m = s.match(COLOUR);if (m && !/^\s*import\b/.test(s)) { problems++; console.log(`${where}: hard-coded colour '${m[0]}' — use a theme token — ${raw.trim().slice(0, 140)}`); }else if (COLOUR_PROP.test(s)) {const n = s.match(NAMED_RE);if (n && !/currentColor|transparent/i.test(n[0].slice(-12))) { problems++; console.log(`${where}: named colour '${n[1]}' — use a theme token — ${raw.trim().slice(0, 140)}`); }}for (const b of s.matchAll(BORDER)) {const value = (b[3] ?? b[4] ?? b[5] ?? '').trim();if (b[1].toLowerCase().includes('radius')) continue;if (NO_BORDER.test(value)) continue;if (FUNCTIONAL.test(raw)) continue;problems++;console.log(`${where}: decorative border '${b[1]} ${b[2]} ${value || '…'}' — borderless unless it means something (docs/design-rules.md), else mark it '// functional: why' — ${raw.trim().slice(0, 140)}`);}const plain = uncomment(raw);for (const r of [...plain.matchAll(RADIUS_HL), ...plain.matchAll(RADIUS_CSS)]) {const bad = badRadii(r[2]);if (!bad.length) continue;problems++;console.log(`${where}: corner radius '${r[1]} ${r[2].trim()}' — only radiusSmall (5px, small items), radiusLarge (10px, panels, popups, tiles), '50%' for round things — ${raw.trim().slice(0, 140)}`);}});}console.log(`check-theme: ${list.length} files, ${problems} problems`);process.exit(problems ? 1 : 0);
Branches
Latest commits
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre
- a01f3aa8ui gate: back to the top before the sort checks (the screen reopens where it was left)mre
- f7936c20Lists keep their scroll position across a reload (jukebox#20): per-list offsets in storage/ui.json, gate jb20mre
- d67906devirtual-list and icons from components.hybriel e5b98ec (centerId, scrollTop, onScroll)mre
- df7920ceRecords: R3 startedmre
- 0549f038Mission 010: jb20 livemre
- 273494e2STATUS rewrittenmre
- 227c9b96Records: jb19 livemre
- 9f365376README: the bar's controls (jb19)mre
- d18851fdjb19: pressed switches look different (whole selector), queue column cannot widen past the panel, gates follow the new bar (jb3, jb11, jb15)mre