#!/usr/bin/env node /** * accent 消费面闸:**两条通道**各一条判据。 * * ══════════════════════════════════════════════════════════════════════════ * 判据 A —— 类名通道(2026-10-17 首批) * 营销面不得出现 `accent-*` 类名。口径按文件名登记豁免。 * * 判据 B —— 内联 style 色彩通道 + 色值真源(DEC-N1 的落地,本轮新增) * 判据 A 只看得见 Tailwind 类名。但色值还有第二条入路: * · `src/lib/constants/hero-themes.ts` 的 `accentColor` 是**色值真源**, * 它以内联样式进 DetailHero 徽章(`detail-hero.tsx` 的 backgroundColor / * borderColor / `--badge-accent`),字符串里根本没有 `accent-` 这个词, * 判据 A 对它**完全无感**。 * · 可达营销组件里直接写死的内联色值字面量(`#1e3a5f`、`rgba(30,58,95,.06)`) * 同样是这条通道,而且它会**绕过真源**造出第二份色值。 * 判据 B 扫这两处,要求每个命中都在**按 文件 + 色值 登记**的豁免表里; * 再加一道**数量棘轮**:真源里的非品牌色相数不得超上限。 * 豁免纪律沿用判据 A:登记了却零命中 ⇒ 判红(防腐化成永久豁免)。 * * 依据仍是实测(Bain 全站字色只有 `#000 #FFF #CC0000 #767676`、面色 3 个; * Porsche 字色 3 个、面色 4 个,红只出现在按钮上——两家都没有用颜色给内容分类)。 * * 判据 B 的**裁定口径**(ADR-0008「决策五」):产品线色相**保留为受控例外**, * 理由是实测它的可见占比近 0(详见 ADR 的量),而"新增一个未登记色相"才是真成本。 * 所以这里不判红存量,只判红**未登记**与**超数量**。 * * 退出码:0 成立 / 1 判红(违规、豁免腐化、棘轮超限)/ 2 未能度量(分母 0)。 * ⚠ 分母 0 一律走 2 不走 0——"没量到"永远不等于"通过"。 */ import { readFileSync, existsSync, readdirSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); const SRC = path.join(ROOT, 'src'); const ACCENT_RE = /\baccent-(blue|teal|amber|purple|cyan|rose|indigo)\b/g; /* ───────────────────────── 判据 A:类名通道 ───────────────────────── */ /** 按名登记的豁免:每条都必须仍有命中,否则判红 */ const ALLOWLIST_CLASSNAME = [ // 后台工具 UI:内容模型的类型色标是**分类编码**(16 个模型要靠颜色快速区分), // 属"数据可视化"族而非编辑面。 { file: 'src/app/admin/page.tsx', reason: 'CMS 模型类型的分类色标(工具 UI)' }, // 组件库库存:当前不可达,但作为 ui 原语保留;若哪天被营销面引用,须先改语法。 { file: 'src/components/ui/product-card.tsx', reason: '组件库库存(不可达,未被营销面引用)' }, { file: 'src/components/ui/brand-visuals.tsx', reason: '组件库库存(品牌图形调色板本身)' }, ]; /* ─────────────── 判据 B:内联 style 色彩通道 + 色值真源 ─────────────── */ /** 色值真源:HERO_THEMES 所在文件(相对 ROOT 的路径) */ const THEME_SOURCE = 'src/lib/constants/hero-themes.ts'; /** * 品牌色相族。判据是**实测色相距离**,不是肉眼归类: * #C41E3A 的 HSV 色相 = 349.9°。11 个主题的 accentColor 里, * security 的 #991b1b 色相 0.0°、距品牌红 10.1°,与 `--color-brand-section` #8B1530(346.3°) * 同族——所以它**不是**第二条彩色编码,它就是品牌红本身; * 而 sds 的 #78350f 色相 21.7°、距品牌红 31.8°,已是橙褐,落在族外。 * 20° 这条线取在 10.1 与 31.8 之间,两侧各有 ≥10° 余量,不是凑数的阈值。 */ const BRAND = { hex: '#c41e3a', hue: 349.9 }; const BRAND_HUE_MAX_DISTANCE = 20; /** HSV 饱和度门限:低于此视为中性(纸白 #f8f6f3 实测 s=0.02、墨黑 #141210 s=0.20 但色带仅 4 阶)*/ const CHROMATIC_MIN_SATURATION = 0.25; const CHROMATIC_MIN_CHANNEL_SPAN = 30; /** * 数量棘轮:真源里**非品牌族色相**的上限。 * 2026-10-17 实测存量 = 7(erp/crm/bi/cms/sds/oa/novavis)。 * 新增一个产品线色相是**设计决定**,必须显式上调这里,不接受"顺手加了个字段"。 * 递减不判红,但把下调提示写进 note(和判据 A 的 R10 同一套纪律)。 */ const MAX_NON_BRAND_HUES = 7; /** * 按 文件 + 色值 登记的豁免。色值一律**归一化成 #rrggbb**(rgba(30,58,95,.06) 与 * #1e3a5f 是同一个色相,必须撞进同一条豁免,否则换个写法就绕过了)。 * 'theme.accentColor' 是保留身份,含义是"色值来自真源、本文件只做透传"。 */ const ALLOWLIST_INLINE_COLOR = [ // —— 色值真源:产品线视觉身份。保留的裁定与实测见 ADR-0008 决策五。 // 实测可见占比:徽章 162.7×44.8px = 视口的 0.538%,其中色相只以 6.3% alpha 底纹存在, // 1600×846 hero 视口的**彩色像素普查里冷色 = 0**(22407 个彩色像素全是品牌红族暖色)。 { file: THEME_SOURCE, color: '#1e3a5f', reason: '产品线视觉身份 erp(受控例外,ADR-0008 决策五)' }, { file: THEME_SOURCE, color: '#1e40af', reason: '产品线视觉身份 crm(受控例外,ADR-0008 决策五)' }, { file: THEME_SOURCE, color: '#0c4a6e', reason: '产品线视觉身份 bi(受控例外,ADR-0008 决策五)' }, { file: THEME_SOURCE, color: '#14532d', reason: '产品线视觉身份 cms(受控例外,ADR-0008 决策五)' }, { file: THEME_SOURCE, color: '#78350f', reason: '产品线视觉身份 sds(受控例外,ADR-0008 决策五)' }, { file: THEME_SOURCE, color: '#4c1d95', reason: '产品线视觉身份 oa(受控例外,ADR-0008 决策五)' }, { file: THEME_SOURCE, color: '#0f3d3e', reason: '产品线视觉身份 novavis(受控例外,ADR-0008 决策五)' }, // —— 透传点:把真源色值写进内联 style 的两处。登记后,**新增透传点即判红** // (比如哪天有人把产品线色相从徽章扩散到卡片描边)。 { file: 'src/components/detail/detail-hero.tsx', color: 'theme.accentColor', reason: '唯一持有该身份的内联透传点(hero 徽章)' }, { file: 'src/components/content/sections.tsx', color: 'theme.accentColor', reason: 'dataviz 构件的 accent 透传(默认值是品牌红,未被产品线覆盖)' }, ]; /* ───────────────────────────── 颜色数学 ───────────────────────────── */ function normalizeHex(v) { const h = v.match(/#[0-9a-fA-F]{6}\b|#[0-9a-fA-F]{3}\b/); if (h) { let s = h[0].toLowerCase(); if (s.length === 4) s = '#' + s.slice(1).split('').map((c) => c + c).join(''); return s; } const r = v.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/); if (r) return '#' + [r[1], r[2], r[3]].map((x) => parseInt(x, 10).toString(16).padStart(2, '0')).join(''); return null; } /** HSV 色相/饱和;返回 null 表示无彩色信息 */ function hsv(hex) { if (!hex || !/^#[0-9a-f]{6}$/.test(hex)) return null; const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255); const mx = Math.max(r, g, b), mn = Math.min(r, g, b), d = mx - mn; if (!mx || !d) return { hue: null, sat: 0, span: Math.round((mx - mn) * 255) }; let h; if (mx === r) h = ((g - b) / d) % 6; else if (mx === g) h = (b - r) / d + 2; else h = (r - g) / d + 4; h *= 60; if (h < 0) h += 360; return { hue: +h.toFixed(1), sat: +(d / mx).toFixed(3), span: Math.round(d * 255) }; } /** 是否为「彩色编码」:够饱和、够色带跨度,且色相离品牌红族足够远 */ function codingHue(hex) { const c = hsv(hex); if (!c || c.sat < CHROMATIC_MIN_SATURATION || c.span < CHROMATIC_MIN_CHANNEL_SPAN) return null; const dh = Math.min(Math.abs(c.hue - BRAND.hue), 360 - Math.abs(c.hue - BRAND.hue)); return dh <= BRAND_HUE_MAX_DISTANCE ? null : { ...c, distanceToBrandHue: +dh.toFixed(1) }; } const relOf = (f) => path.relative(ROOT, f).split(path.sep).join('/'); function walk(dir, acc = []) { if (!existsSync(dir)) return acc; for (const e of readdirSync(dir, { withFileTypes: true })) { if (['node_modules', '.git', 'dist', '_archive'].includes(e.name)) continue; const p = path.join(dir, e.name); if (e.isDirectory()) walk(p, acc); else if (/\.(tsx|ts)$/.test(e.name) && !/\.test\.(ts|tsx)$/.test(e.name) && !e.name.endsWith('.d.ts')) acc.push(p); } return acc; } /* ─────────────────────── 判据 A 的求值 ─────────────────────── */ function evaluateClassname(fileTexts) { const violations = []; const hitsByFile = new Map(); for (const [rel, text] of fileTexts) { const hits = [...text.matchAll(ACCENT_RE)]; if (hits.length === 0) continue; hitsByFile.set(rel, hits.length); if (!ALLOWLIST_CLASSNAME.some((a) => a.file === rel)) { const line = text.slice(0, hits[0].index).split('\n').length; violations.push({ file: rel, count: hits.length, at: line, sample: hits[0][0] }); } } const stale = ALLOWLIST_CLASSNAME.filter((a) => !hitsByFile.has(a.file)).map((a) => a.file); return { violations, stale, hitsByFile, measured: fileTexts.size > 0 }; } /* ─────────────────────── 判据 B 的求值 ─────────────────────── */ /** style={{ ... }} 块:逐字符配平花括号,块内才是内联样式通道 */ function styleBodies(text) { const out = []; const re = /style\s*=\s*\{\{/g; let m; while ((m = re.exec(text))) { let i = m.index + m[0].length, depth = 1; const start = i; while (i < text.length && depth > 0) { if (text[i] === '{') depth++; else if (text[i] === '}') depth--; i++; } out.push({ body: text.slice(start, i - 1), line: text.slice(0, start).split('\n').length }); } return out; } // 色彩属性 + CSS 自定义属性。'--badge-accent' 这种带引号的键也接。 const COLOR_PROP_RE = /(?:'(--[\w-]+)'|"(--[\w-]+)"|(--[\w-]+)|(backgroundColor|backgroundImage|background|borderColor|border|outlineColor|color|fill|stroke|boxShadow|textShadow))\s*:\s*([^,}\n]+)/g; /** 真源里每个主题的 accent 色值:字段名限定,避免把 gradientFrom 那种纸色也算进来 */ function themeSourceValues(text) { const out = []; const re = /(accentColor|accentBg)\s*:\s*['"`]([^'"`]*)['"`]/g; let m; while ((m = re.exec(text))) { const line = text.slice(0, m.index).split('\n').length; out.push({ field: m[1], raw: m[2], hex: normalizeHex(m[2]), at: line }); } return out; } function evaluateInlineColor(fileTexts) { const violations = []; const hits = new Map(); // `${file}::${colorIdentity}` -> count const addHit = (file, color) => { const k = `${file}::${color}`; hits.set(k, (hits.get(k) || 0) + 1); }; const registered = new Set(ALLOWLIST_INLINE_COLOR.map((a) => `${a.file}::${a.color}`)); const bump = (arr, x) => { if (!arr.some((y) => y.file === x.file && y.color === x.color)) arr.push(x); }; const violationsUnregistered = []; const violationsDuplicateSource = []; const registeredBrand = []; // 内联 style 里被当作色彩载体使用的属性名集合(诊断用,不参与判红)。 // 原稿把它声明在 for 循环内、却在 return 里引用 ⇒ 截断后 ReferenceError; // 提到函数作用域,语义取「所有文件的并集」,判据不受影响(runDimension 只断言四维)。 const accentProps = new Set(); const themeText = fileTexts.get(THEME_SOURCE); // 分母:真源解析出的 accent 字段数。0 ⇒ 未能度量,不许报通过。 const denominator = themeText ? themeSourceValues(themeText).length : 0; /* —— B-1 色值真源 —— */ const nonBrandHues = new Set(); if (themeText) { for (const v of themeSourceValues(themeText)) { if (!v.hex) continue; addHit(THEME_SOURCE, v.hex); const coding = codingHue(v.hex); if (!coding) { if (v.hex === BRAND.hex) registeredBrand.push(v.hex); continue; // 品牌族 / 中性 → 不是彩色编码,无需登记 } nonBrandHues.add(v.hex); if (!registered.has(`${THEME_SOURCE}::${v.hex}`)) { bump(violationsUnregistered, { file: THEME_SOURCE, color: v.hex, at: v.at, why: `真源新增未登记的产品线色相(色相 ${coding.hue}°,距品牌红 ${coding.distanceToBrandHue}°)`, }); } } } /* —— B-2 可达营销代码里的内联 style 色彩通道 —— */ for (const [rel, text] of fileTexts) { if (rel === THEME_SOURCE) continue; for (const sb of styleBodies(text)) { COLOR_PROP_RE.lastIndex = 0; let m; while ((m = COLOR_PROP_RE.exec(sb.body))) { const prop = (m[1] || m[2] || m[3] || m[4] || '').trim(); const value = m[5] || ''; if (/--color-accent-[\w-]+/.test(value)) { // 真身:把 accent 令牌塞进内联 style,比类名通道更隐蔽。 bump(violationsUnregistered, { file: rel, color: '--color-accent-*', at: sb.line, why: `内联 style 直接引用 accent 令牌(${prop})` }); continue; } if (/accentColor/.test(value)) { addHit(rel, 'theme.accentColor'); accentProps.add(prop); if (!registered.has(`${rel}::theme.accentColor`)) { bump(violationsUnregistered, { file: rel, color: 'theme.accentColor', at: sb.line, why: `新增内联透传点(${prop} 取真源 accentColor)` }); } continue; } const hex = normalizeHex(value); if (!hex) continue; // var(--color-brand) / currentColor / transparent 等:走令牌真源,不是硬编码 addHit(rel, hex); const coding = codingHue(hex); if (!coding) continue; // 中性纸墨 / 品牌红族:不算彩色编码 if (!registered.has(`${rel}::${hex}`)) { bump(violationsUnregistered, { file: rel, color: hex, at: sb.line, why: `营销面内联 style 写死色相 ${coding.hue}°(距品牌红 ${coding.distanceToBrandHue}°)`, }); } } } // 绕开真源的第二份色值:在营销代码里就地组装 HeroTheme 对象 const dupRe = /accentColor\s*(?::|=)\s*['"`]([^'"`]*)['"`]/g; let d; while ((d = dupRe.exec(text))) { const hex = normalizeHex(d[1]); if (!hex || !codingHue(hex)) continue; const at = text.slice(0, d.index).split('\n').length; bump(violationsDuplicateSource, { file: rel, color: hex, at, why: '在营销页面里就地写死 accentColor,绕过色值真源' }); } } // 豁免腐化:登记了但命中 0 ⇒ 判红(与判据 A 同纪律) const stale = ALLOWLIST_INLINE_COLOR .filter((a) => !hits.has(`${a.file}::${a.color}`)) .map((a) => ({ file: a.file, color: a.color, reason: a.reason })); const ratchetRed = nonBrandHues.size > MAX_NON_BRAND_HUES; violations.push(...violationsUnregistered, ...violationsDuplicateSource); return { violations, violationsUnregistered, violationsDuplicateSource, stale, ratchetRed, nonBrandHueCount: nonBrandHues.size, nonBrandHues: [...nonBrandHues], hits, denominator, measured: denominator > 0, accentProps, }; } /* ─────────────────────────── 自证 ─────────────────────────── */ /** * 每个情景**只测一维**。这条纪律是踩过坑换来的: * 上一版把「违规」和「豁免腐化」两个互斥前提塞进同一份夹具——豁免有命中正是 * "不腐化"的定义,于是腐化那一维永远测不到,自照出来全线绿灯。 * 现在按 dimension 只跑对应求值器,并额外断言**另一维在该夹具上为 0**, * 用来自证夹具确实只喂了一个维度(否则"单维"只是自称)。 */ const A_ALLOWED_LINES = [ ['src/app/admin/page.tsx', 'const tone = bg-accent-blue'], ['src/components/ui/product-card.tsx', 'const x = bg-accent-purple'], ['src/components/ui/brand-visuals.tsx', 'const y = text-accent-cyan'], ]; const A_MARKETING_HIT = ['src/app/(marketing)/x.tsx', '
']; // 判据 B 用的真源夹具:7 个已登记产品线色相 + 品牌红 + 品牌族的 #991b1b(后者必须不被判红) const B_THEME = [THEME_SOURCE, [ "erp: { accentColor: '#1e3a5f', accentBg: 'rgba(30, 58, 95, 0.06)' },", "crm: { accentColor: '#1e40af' },", "bi: { accentColor: '#0c4a6e' },", "cms: { accentColor: '#14532d' },", "sds: { accentColor: '#78350f' },", "oa: { accentColor: '#4c1d95' },", "novavis: { accentColor: '#0f3d3e' },", "security: { accentColor: '#991b1b' },", "solution: { accentColor: '#C41E3A' },", ].join('\n')]; const B_PROPAGATION = [ ['src/components/detail/detail-hero.tsx', 'style={{ backgroundColor: `${theme.accentColor}10` }}'], ['src/components/content/sections.tsx', 'style={{ color: accentColor }}'], ]; const SCENARIOS = [ // ── 判据 A 的三维 ── { name: '[A] 营销面类名违规(A 豁免仍各有命中)', dimension: 'classname', files: new Map([A_MARKETING_HIT, ...A_ALLOWED_LINES, B_THEME, ...B_PROPAGATION]), expect: { violations: 1, stale: 0, ratchet: false, measured: true }, }, { name: '[A] 类名豁免腐化(登记在案但命中 0)', dimension: 'classname', files: new Map([['src/app/(marketing)/y.tsx', ''], B_THEME, ...B_PROPAGATION]), expect: { violations: 0, stale: 3, ratchet: false, measured: true }, }, { name: '[A] 类名全绿(无违规也无腐化)', dimension: 'classname', files: new Map([...A_ALLOWED_LINES, B_THEME, ...B_PROPAGATION]), expect: { violations: 0, stale: 0, ratchet: false, measured: true }, }, // ── 判据 B 的四维:未登记色相 / 透传点新增 / 绕开真源 / 豁免腐化 / 棘轮 ── { name: '[B] 真源新增未登记色相', dimension: 'inline', files: new Map([[THEME_SOURCE, B_THEME[1] + "\nfinance: { accentColor: '#0e7490' },"], ...B_PROPAGATION]), expect: { violations: 1, stale: 0, ratchet: true, measured: true }, }, { name: '[B] 营销面内联 style 写死色相', dimension: 'inline', files: new Map([B_THEME, ...B_PROPAGATION, ['src/app/(marketing)/z.tsx', '']]), expect: { violations: 1, stale: 0, ratchet: false, measured: true }, }, { name: '[B] 新增内联透传点', dimension: 'inline', files: new Map([B_THEME, ...B_PROPAGATION, ['src/components/sections/new-card.tsx', 'style={{ borderColor: accentColor }}']]), expect: { violations: 1, stale: 0, ratchet: false, measured: true }, }, { name: '[B] 绕开真源、页面里就地组装 accentColor', dimension: 'inline', files: new Map([B_THEME, ...B_PROPAGATION, ['src/app/(marketing)/products/v3/page.tsx', "const t = { accentColor: '#1e3a5f' };"]]), expect: { violations: 1, stale: 0, ratchet: false, measured: true }, }, { name: '[B] 内联豁免腐化(登记在案但命中 0)', dimension: 'inline', files: new Map([[THEME_SOURCE, "solution: { accentColor: '#C41E3A' },"], ['src/components/detail/detail-hero.tsx', 'style={{ color: "var(--ink)" }}']]), expect: { violations: 0, stale: 9, ratchet: false, measured: true }, }, { name: '[B] 分母 0 = 未能度量(真源解析不出任何 accent 字段)', dimension: 'inline', files: new Map([[THEME_SOURCE, 'export const HERO_THEMES = {};'], ...B_PROPAGATION]), expect: { violations: 0, stale: 7, ratchet: false, measured: false }, }, { name: '[B] 内联全绿(产品线色相均已登记、棘轮未越界)', dimension: 'inline', files: new Map([B_THEME, ...B_PROPAGATION]), expect: { violations: 0, stale: 0, ratchet: false, measured: true }, }, { name: '[B] 色值写法归一化:rgba 与十六进制撞进同一条豁免', dimension: 'inline', files: new Map([[THEME_SOURCE, B_THEME[1].replace( "erp: { accentColor: '#1e3a5f', accentBg: 'rgba(30, 58, 95, 0.06)' },", "erp: { accentColor: 'rgba(30, 58, 95, 1)', accentBg: '#1E3A5F' },", )], ...B_PROPAGATION]), expect: { violations: 0, stale: 0, ratchet: false, measured: true }, }, ]; function runDimension(dimension, files) { const a = evaluateClassname(files); const b = evaluateInlineColor(files); const src = dimension === 'classname' ? a : b; const other = dimension === 'classname' ? b : a; return { violations: src.violations.length, stale: src.stale.length, ratchet: dimension === 'classname' ? false : b.ratchetRed, measured: dimension === 'classname' ? a.measured : b.measured, otherViolations: other.violations.length, otherStale: other.stale.length, }; } function selftest() { console.log('accent 闸自证(判据 A 类名通道 / 判据 B 内联色彩通道 + 色值真源)'); console.log('纪律:每个情景只喂一维;情景同时断言另一维在该夹具上为 0,自证"单维"不是自称。'); let ok = true; for (const s of SCENARIOS) { const got = runDimension(s.dimension, s.files); const errs = []; if (got.violations !== s.expect.violations) errs.push(`违规 ${got.violations}≠应 ${s.expect.violations}`); if (got.stale !== s.expect.stale) errs.push(`腐化 ${got.stale}≠应 ${s.expect.stale}`); if (got.ratchet !== s.expect.ratchet) errs.push(`棘轮 ${got.ratchet}≠应 ${s.expect.ratchet}`); if (got.measured !== s.expect.measured) errs.push(`可度量 ${got.measured}≠应 ${s.expect.measured}`); // 夹具纯度断言:未被测的那一维必须干净(棘轮情景例外——它本来就靠真源色相数超限成立) // 串维证据只取「另一维的违规数」:豁免腐化(stale)在单维夹具里是必然产物 —— // B 的夹具不带 A 的三个豁免文件,A 一定报 stale 3;把 stale 当串维证据会让 // 自证永远红,而把它删掉又等于放弃单维断言。违规数才是「这维真的被抓了」的证据。 if (got.otherViolations > 0) { errs.push(`夹具串维:未被测的那一维在该夹具上命中 条违规`); } if (errs.length) { ok = false; console.log(` ✗ ${s.name}:${errs.join(';')}`); } else console.log(` ✓ ${s.name}:违规 ${got.violations} · 腐化 ${got.stale} · 棘轮超限 ${got.ratchet} · 可度量 ${got.measured}`); } if (!ok) { console.log(' ⇒ 上面所有绿灯不作数'); return 1; } console.log(' ⇒ 两维各自独立可失败,夹具未串维'); return 0; } /* ─────────────────────────── 主流程 ─────────────────────────── */ function main() { if (process.argv.includes('--selftest')) process.exit(selftest()); const files = walk(SRC); if (files.length === 0) { console.log('未能度量:src 下没扫到任何文件'); process.exit(2); } const fileTexts = new Map(files.map((f) => [relOf(f), readFileSync(f, 'utf8')])); const a = evaluateClassname(fileTexts); const b = evaluateInlineColor(fileTexts); console.log(`══ 判据 A 类名通道:扫描 ${files.length} 个源文件 · 命中 ${[...a.hitsByFile.values()].reduce((x, y) => x + y, 0)} 处 / ${a.hitsByFile.size} 文件`); for (const [f, n] of a.hitsByFile) { const x = ALLOWLIST_CLASSNAME.find((y) => y.file === f); if (x) console.log(` · 豁免 ${f} (${n} 处) — ${x.reason}`); } let bad = false; for (const v of a.violations) { bad = true; console.log(` ✗ 营销面使用彩色编码 ${v.file}:${v.at} (${v.count} 处,如 ${v.sample})`); } for (const f of a.stale) { bad = true; console.log(` ✗ A 豁免已腐化:${f} 登记在案但命中 0 处 —— 请把这条豁免删掉`); } // 判据 B console.log(`\n══ 判据 B 内联 style 色彩通道 + 色值真源`); console.log(` 真源 ${THEME_SOURCE}:解析出 accent 字段 ${b.denominator} 个(分母)`); if (!b.measured) { console.log(' ⇒ 分母为 0:未能度量(不是通过)'); process.exit(2); } const brandSide = b.nonBrandHues.length; console.log(` 非品牌族色相 ${brandSide} 个 / 棘轮上限 ${MAX_NON_BRAND_HUES}:${b.nonBrandHues.join(' ')}`); for (const e of ALLOWLIST_INLINE_COLOR) { const n = b.hits.get(`${e.file}::${e.color}`) || 0; console.log(` · 豁免 ${e.file} @ ${e.color} (${n} 处) — ${e.reason}`); } for (const v of b.violationsUnregistered) { bad = true; console.log(` ✗ 未登记的彩色编码 ${v.file}:${v.at} — ${v.why}`); } for (const v of b.violationsDuplicateSource) { bad = true; console.log(` ✗ 绕过色值真源 ${v.file}:${v.at} @ ${v.color} — ${v.why}`); } for (const s of b.stale) { bad = true; console.log(` ✗ B 豁免已腐化:${s.file} @ ${s.color} 登记在案但命中 0 处(${s.reason})—— 请把这条豁免删掉`); } if (b.ratchetRed) { bad = true; console.log(` ✗ 棘轮超限:产品线非品牌色相 ${brandSide} > 上限 ${MAX_NON_BRAND_HUES} —— 加色相是设计决定,须显式上调上限`); } if (b.nonBrandHueCount < MAX_NON_BRAND_HUES && !bad) { console.log(` note:存量已降到 ${brandSide},可把 MAX_NON_BRAND_HUES 从 ${MAX_NON_BRAND_HUES} 下调(棘轮自锁)`); } if (bad) { console.log('\n不成立'); process.exit(1); } console.log('\n成立:判据 A 营销面零 accent-* 类彩色编码;判据 B 内联色彩通道与色值真源的每个命中都已按 文件+色值 登记,且两维的每条豁免都仍有命中'); console.log(` 口径:彩色编码的两条入路都在这道闸的敏感范围内(类名 / 内联 style+真源色值)。`); console.log(` 产品线色相 ${brandSide} 个是**已裁定的受控例外**(ADR-0008 决策五),不是漏网;新增未登记色相或超棘轮上限即判红。`); console.log(` 实测可见占比(同 ADR):hero 徽章 = 视口 0.538%,色相仅以 6.3% alpha 底纹存在,1600×846 hero 视口冷色像素普查 = 0。`); console.log(' ⚠ 未被本闸覆盖:CMS 内容里 authored 的色值(富文本/图表数据),属数据面而非代码面。'); } main();