// 令牌孪生一致性闸:--X-rgb 必须等于同名 --X 的 hex 分量。 // 为什么要有它:Tailwind 把 29 个颜色键映成 rgb(var(--X-rgb)),也就是**渲染的主通道在 -rgb 上**; // 而 check:contrast 读的是 hex。于是"只改 hex、漏改 -rgb"能同时骗过对比度闸与视觉基线 // (2026-10-16 实测:68 处 hex 已转暖,22 条 -rgb 仍是冷色,视觉套件 0 张重写、对比度 44/44 全绿)。 // 判据按 selector 块配对 —— 跨块配对会把明暗两套主题当成一对,报出 26 条假红(本轮踩过)。 import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const file = process.argv[2] || path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "src/app/globals.css"); const lines = readFileSync(file, "utf8").split("\n"); const blocks = []; let cur = null; for (let i = 0; i < lines.length; i++) { const st = lines[i].trim(); if (st.endsWith("{") && !st.startsWith("@")) { cur = { sel: st.slice(0, -1).trim(), hex: new Map(), rgb: [] }; blocks.push(cur); continue; } if (st === "}") { cur = null; continue; } if (!cur) continue; let m = /^\s*(--[a-z0-9-]+):\s*#([0-9A-Fa-f]{6})\s*;/.exec(lines[i]); if (m) { cur.hex.set(m[1], m[2]); continue; } m = /^\s*(--[a-z0-9-]+)-rgb:\s*(\d+)\s+(\d+)\s+(\d+)\s*;/.exec(lines[i]); if (m) cur.rgb.push({ name: m[1], line: i + 1, got: [+m[2], +m[3], +m[4]] }); } let n = 0, bad = [], orphan = []; for (const b of blocks) for (const r of b.rgb) { n++; const h = b.hex.get(r.name); if (!h) { orphan.push(`[${b.sel}] L${r.line} --${r.name}-rgb 无同块兄弟 --${r.name}`); continue; } const want = [0, 2, 4].map((j) => parseInt(h.slice(j, j + 2), 16)); if (want.join() !== r.got.join()) bad.push(`[${b.sel}] L${r.line} --${r.name}-rgb = ${r.got.join(" ")} ≠ #${h} → ${want.join(" ")}`); } console.log(`令牌孪生对账:${n} 条 -rgb 声明(按 ${blocks.length} 个 selector 块配对)`); if (n === 0) { console.log("红:0 条 -rgb 声明 ⇒ 判据没有目标,不算通过"); process.exit(1); } for (const x of [...bad, ...orphan]) console.log(" ✗ " + x); if (bad.length || orphan.length) { console.log(`不成立:数值不一致 ${bad.length} 条、无兄弟 ${orphan.length} 条`); process.exit(1); } console.log(`成立:全部 -rgb 与同块 hex 逐通道相等(${n}/${n})`);