Files
zhangxiang dd8ee80b97 feat(theme): 中性色转暖落地(含 -rgb 孪生通道),挂上孪生一致性闸
P1:globals.css 68 处中性色转暖,深通道按「保 L、色相→33°、S≤0.14」算;P4 弱文字分三档
(装饰线 #C3BDB1/非文本信息 #8A8377/正文级 #6E675D);P3 三个深底红收敛为 #E9455F(对暖墨
#141210 实测 4.88:1)。14 处彩性蓝按裁决故意不动。P2:public/fonts/ 放思源宋体可变子集 388.1KB
(cmap 回读 0 缺字)+两份 OFL 1.1 正文,--font-serif 队首插入 Novalon Serif SC,系统兜底全保留。

落库时查出并修一条真缺陷:43 条 -rgb 三元组有 22 条从未迁移(:root 11+深色块 11,色相仍 H210-217),
而 Tailwind 有 29 个颜色键经 rgb(var(--X-rgb)) 消费 ⇒ 渲染主通道还是冷的;当时 check:contrast 44/44
全绿(读 hex)、视觉套件 0 张重写 ⇒ 两道闸一起假绿。按「孪生等于同块 hex」对齐 22 条并新增常驻闸
npm run check:token-twins(0 条判红/不等判红/孤儿判红),复测 43/43 一致。
2026-10-16 19:23:25 +08:00

37 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 令牌孪生一致性闸:--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})`);