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
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
- 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
- 1fecd6a7Merge branch 'records-day39' into mainJukebox
- d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
- 5fa19e89Merge branch 'day39' into mainJukebox
- cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
- f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
- 9f5c6532Merge branch 'status-22-pr' into mainJukebox