calendar
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
- e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
- eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
- cef81394Wait for the DST fixture page instead of an unused socketmre
- 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
- 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
- cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
- f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
- edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
- bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
- 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
- cc759328Merge sb3-standby: calendar deploys through its standbymre
- f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre
- 229643f7Merge branch 'cal-14'mre
- 1110b26fcalendar#14: the month name no longer breaks into two lines on a phone (Reminder settings drops to its own row when the header is too narrow), gate checks for one-line title and all header controls on screenmre
- 490c658aident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- 18095868calendar: Reminder settings button opens its dialog again (the dialog's open handler still closed the removed user menu and stopped); old e2e and gate scripts use the new headermre
- 6eee4b5acalendar header: the selector alone top right plus Log out as before the theme missions; Reminder settings back on the month page (WIP: the settings test still fails)mre
- 0b909decident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 0c8f9364Merge branch 'sy-sync'mre