From af2d87fcb5c197eb1d8806abde42aaa5bd69f3a6 Mon Sep 17 00:00:00 2001 From: QQ Date: Thu, 12 Nov 2026 00:03:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20verify-theme.mjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- verify-theme.mjs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 verify-theme.mjs diff --git a/verify-theme.mjs b/verify-theme.mjs new file mode 100644 index 0000000..33177ec --- /dev/null +++ b/verify-theme.mjs @@ -0,0 +1,34 @@ +// P5 theme / narrow-panel structural guard. +// +// This is a static guard, not a screenshot: it fails if the hand-written card +// reintroduces a hard-coded light-only colour or drops the wrapping that keeps +// a narrow settings panel from scrolling sideways. It also asserts the tab bar +// and the two long action rows declare flexWrap. +import { readFileSync } from 'node:fs' + +const results = [] +function check(name, ok, detail) { + results.push({ name, ok }) + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail === undefined ? '' : ` :: ${detail}`}`) +} + +const source = readFileSync('./client/index.js', 'utf8') + +const hardcoded = source.match(/(?:background|color|borderColor)\s*:\s*['"]#(?:fff(?:fff)?|000(?:000)?)['"]/gi) +check('no hard-coded pure white/black colours', hardcoded === null, hardcoded === null ? '' : hardcoded.join(',')) + +const neutralTokens = (source.match(/rgba\(127,127,127/gi) ?? []).length +check('theme-neutral colour tokens are used throughout', neutralTokens >= 5, `${neutralTokens} uses`) + +const accentTokens = (source.match(/rgba\(37,99,235/gi) ?? []).length +check('accent colour is the shared blue token', accentTokens >= 2, `${accentTokens} uses`) + +const wrapCount = (source.match(/flexWrap\s*:\s*['"]wrap['"]/g) ?? []).length +check('long rows wrap instead of scrolling sideways', wrapCount >= 4, `${wrapCount} wrapping rows`) + +check('tabs and actions declare wrapping', /tabBar[\s\S]{0,400}?flexWrap/.test(source) || /styles\.tabs/.test(source)) +check('no fixed 375px-only width is pinned', !/minWidth\s*:\s*['"]?375/.test(source)) + +const passed = results.filter((r) => r.ok).length +console.log(`\n${passed}/${results.length} passed`) +process.exit(passed === results.length ? 0 : 1)