退役(零视觉影响:NEXT_PUBLIC_HERO_SCENE 从未在任何 .env* 设置): - 删 hero-scene.tsx(694行)/caption/单测/文案真源/CC0 机柜/海报帧 - R26 删除、R22 登记归零、e2e heroSceneMask 移除(无命中的假安全网) - R22 自证改可注入(夹具不再依赖生产条目) 落库(flag NEXT_PUBLIC_HERO_FIELD 样期默认关 ⇒ 基线零影响): - hero-field.tsx 三拍:噪声→增长→判断;bloom 半分辨率;DPR≤1.5 - 降级统一看结论帧(reduced-motion 定格 T_HOLD=40500 非 0) - 文案真源含承诺词正则守卫(禁帮助/赋能/提升/%/倍) - 海报帧 capture 脚本与资产同批入库(1920x864/26.9KB,可复现) - eslint 忽略 demo/**/vendor/**(vendored three 不可被 lint-staged --fix 改写) 守卫重建:R26 指向 hero-field(43260ms/3 拍合规);R22 登记 HeroField 条目 验证:tsc 0 / eslint 0 error / jest 162 套件 1906 例 / check:grammar 26+26 / check:a11y 0 违规 / 默认构建首页 DOM 冒烟 E 案不变
1330 lines
85 KiB
JavaScript
1330 lines
85 KiB
JavaScript
#!/usr/bin/env node
|
||
// 视觉语法闸:把「对标实测出来的语法」钉成机器判据。
|
||
//
|
||
// 为什么要有它(实测,非口味):
|
||
// Bain & Company(archive 快照 2026-08-31,1600×846)与 Porsche Consulting(live 国际站)
|
||
// 两家 getComputedStyle 抽样结果是同一条:**全站 border-radius 为 0**,且面/字色近乎单色
|
||
// (Bain 字色仅 #000/#FFF/#CC0000/#767676;Porsche 仅 #000/#FFF/#B6B5BA,面色 #FFF/#000/#D6001D/#F2F2F2)。
|
||
// 本仓此前是 --radius-xs..3xl = 3..32px + 三枚彩色阴影(--shadow-brand/-brand-hover/-glow)
|
||
// + .bain-card 的 translateY(-4px) hover 抬升 —— 即「软边 + 彩晕 + 抬升」三件全是对标没有的。
|
||
// 2026-06-29 的 ADR-0004 把「关键数字超大字号 + 品牌色」当成 Bain 心法,实测 Bain 的成果数字是
|
||
// 40px / 字重 500 / 纯黑,故该判据已被证伪;语法层由本闸接管。
|
||
//
|
||
// 判据设计上的两条自律:
|
||
// 1) --radius-full 必须**保持** 9999px。rounded-full 在本仓承载真圆(avatar/switch/slider/
|
||
// radio-group/progress/scroll-area/skeleton),把它一并归零会方角化所有旋钮与头像 ——
|
||
// 这是「语法收口」最容易犯的自伤,所以单独一条正向守卫。
|
||
// 2) 每条规则都报分母。**分母为 0 = 判据没有目标 = 未能度量(exit 2),不算通过。**
|
||
//
|
||
// 退出码分档(避免「闸自身崩溃」与「判红」共用 exit 1,那会吞掉同批已算好的打印):
|
||
// 0 成立 / 1 预期红(真违规)/ 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 CSS = path.join(ROOT, "src/app/globals.css");
|
||
const TW_CONFIG = path.join(ROOT, "tailwind.config.js");
|
||
// R4 管的「编辑类 CTA 表面」。button.tsx **不在**这里 —— 它的 icon 档与涟漪点是功能性的圆,
|
||
// 由 R9 双向管(文字档必须直角、icon 档必须保持圆)。
|
||
const CTA_SURFACES = [
|
||
"src/components/ui/cta-button.tsx",
|
||
"src/components/ui/badge.tsx",
|
||
];
|
||
const BUTTON_FILE = "src/components/ui/button.tsx";
|
||
|
||
/**
|
||
* R10 hover 抬升的**递减棘轮上限**,登记在 module 层而非 checkGrammar 内部,
|
||
* 是为了让自证能引用它构造「+1 必须判红 / 恰好等于必须不判红」两个情景。
|
||
* 第一版把 R10 排除在自证外,理由是"喂违规样本会同时改变分母"—— 那句话把
|
||
* 「存量棘轮」和「不可自证」混为一谈了:棘轮的分母**就是**被数的东西,
|
||
* 多喂一处抬升正是它的违规形态,不是副作用。没有负例的规则等于没有规则。
|
||
*
|
||
* 现值 28 = 2026-10-17 实测(19 文件)。变多判红,变少提示下调登记值。
|
||
*/
|
||
const HOVER_LIFT_CEILING = 28;
|
||
|
||
/**
|
||
* R11 的「外部所有者」豁免:由 Radix 等运行时注入、本就不该由 globals.css 声明的变量。
|
||
* 放在 module 层而不是规则里,是因为**自证夹具也必须引用同一份名单** ——
|
||
* 名单在规则里、夹具里再手抄一遍,改一处另一处就悄悄失效(本轮真实踩到:
|
||
* 夹具没带上这条引用,豁免腐化判据把「已声明不误报」那一维污染成了假红)。
|
||
*/
|
||
const EXTERNAL_OWNED = ["--radix-accordion-content-height"];
|
||
|
||
/**
|
||
* R22 的**视觉层登记表**(2026-12-02 第五态:登记制恢复为一条)。
|
||
*
|
||
* 变迁:三态登记 `HeroScene`(机房场景)→ 四态随机房撤回**归零** → 五态随抽象数据场落地
|
||
* 恢复为一条。R22 的语义不变:"任何视觉层都要先登记",登记即批准、未登记即判红。
|
||
*
|
||
* 每一条必须给三样东西,缺一样这条登记就无效:
|
||
* marker —— 载体标记,必须真的出现在首屏区块内(防「登记了但载体已换」)
|
||
* origin —— 出处(ADR 编号),供追溯为什么允许它出现在首屏
|
||
* poster —— 海报帧相对 `public/` 的路径,必须真实存在(防「降级链写在文档里」)
|
||
*/
|
||
const HERO_VISUAL_REGISTRY = new Map([
|
||
[
|
||
"src/app/(marketing)/home-content-v17.tsx",
|
||
{ markers: ["HeroField"], origin: "ADR-0016 §17.5", poster: "/images/home/hero-field-poster.webp" },
|
||
],
|
||
]);
|
||
|
||
/**
|
||
* 首屏「视觉层」的载体集合,捕获组 = 载体名(与登记表 `markers` 用同一套字符串)。
|
||
* `canvas` 单列是因为有人会绕过组件直接画 —— 零影像时代它整个落在扫描盲区。
|
||
*/
|
||
const VISUAL_LAYER_RE = /<(HeroPlate|Image|HeroField|canvas|Canvas)\b/g;
|
||
|
||
/* R26 的落点:首屏抽象数据场组件(ADR-0016 §17.5)。路径单点维护,自证夹具引用它。 */
|
||
const HERO_FIELD_FILE = "src/components/home/hero-field.tsx";
|
||
/* 分镜一轮的时长上下限(ADR-0016 §10.5 例外条款 ①②,随 §17.5 继任者沿用)。 */
|
||
const HERO_CYCLE_CEILING = 60_000;
|
||
const HERO_CYCLE_FLOOR = 20_000;
|
||
|
||
/**
|
||
|
||
/**
|
||
* R22 的落点:ADR-0011 §4.2 的「六页 hub × 一组参数」在 2026-12-01 扩到**全部营销页首屏**。
|
||
*
|
||
* 为什么这条判据存在:`OPEN-01` 的验收判据①是「首屏有 B 类原语且承担构图」。
|
||
* 没有这条闸时,判据只活在 ADR 文字里 —— 把原语删掉,R12–R21 全绿,
|
||
* 于是「复刻完成」可以在一夜之间退回「白底文字块」而没有任何仪器喊。
|
||
* 分母为 0(路径全改)按「判据失去目标」判红,而不是静默通过。
|
||
*
|
||
* 不在此列的两类(有意排除,不是漏):
|
||
* - `/privacy` `/terms`:法律文本页,排版服从可读性,不宜插装饰位;
|
||
* - `/cases/[slug]`:首屏是 Bain 式「大数字先行」构图,且零案例种子下不可达,
|
||
* 换了构图也没有可观测收益 —— 待有真实案例后按需并入。
|
||
*/
|
||
const HUB_HERO_FILES = [
|
||
// 首页(2026-12-01 影像退役后并入:它的首屏此前不在本表,是全站唯一没有影像守卫的一页)
|
||
"src/app/(marketing)/home-content-v17.tsx",
|
||
// 六个 hub
|
||
"src/app/(marketing)/products/products-content-v3.tsx",
|
||
"src/app/(marketing)/solutions/solutions-content-v3.tsx",
|
||
"src/app/(marketing)/services/services-content-v3.tsx",
|
||
"src/app/(marketing)/cases/cases-content-v3.tsx",
|
||
"src/app/(marketing)/news/news-content-v3.tsx",
|
||
"src/app/(marketing)/insights/insights-content.tsx",
|
||
// 详情页(共享组件覆盖 standalone/[id] 与 erp-upgrade-v3)
|
||
"src/components/detail/detail-page-hero.tsx",
|
||
"src/app/(marketing)/products/product-detail-content-v3.tsx",
|
||
"src/app/(marketing)/solutions/solution-detail-content-v3.tsx",
|
||
"src/app/(marketing)/services/service-detail-content-v4.tsx",
|
||
"src/app/(marketing)/news/news-detail-content-v3.tsx",
|
||
// 内容页
|
||
"src/app/(marketing)/about/about-content-v4.tsx",
|
||
"src/app/(marketing)/team/team-content-v3.tsx",
|
||
"src/app/(marketing)/methodology/methodology-content.tsx",
|
||
"src/app/(marketing)/contact/contact-content-v3.tsx",
|
||
"src/app/(marketing)/products/erp-upgrade/erp-upgrade-content-v2.tsx",
|
||
];
|
||
|
||
/**
|
||
* R23 的**构型登记表**(2026-12-01 裁定 D1/D2,同日影像被否后改判「内容图」)。
|
||
*
|
||
* 判「型」而不是判「有没有图」的理由仍然成立:只数密度,最省力的达标方式是所有页插同一块东西。
|
||
*
|
||
* 但**「图」的载体换过一次**,必须写在这里而不是留在提交信息里:
|
||
* 影像(EditorialFigure)→ 被否。三次题材(抽象几何 / 建筑混凝土 / 技术静物)都证明了
|
||
* 同一件事:照片不承担语义,「实施流程」「解决方案」这类说的是关系与阶段,静物给不了语义。
|
||
* 现在两类载体都是**页面自己的内容**:
|
||
* t-a 分栏 → `<StageIndex>`:把该区块的条目按序号排成脊线(标题 + 说明取自真实数据)
|
||
* t-b 满幅带 → `<BandIndex>`:把该页的条目横排成索引带(行业 / 新闻 / 案例)
|
||
* t-c 偏移板 → **已退役**:原先三个偏移位(/products、/services、/insights)所在的区块
|
||
* 没有可承载的条目,硬放一件只会与下方列表重复,故三个位一并撤除。
|
||
*
|
||
* 判据形态没变:每页必须命中**它该用的那一种**,缺型或错型都判红。
|
||
* **递减棘轮**:每落地一批把 COMPOSITION_UNMET_CEILING 下调到新的实测值,归零后锁死。
|
||
*/
|
||
const COMPOSITION_FILES = {
|
||
"src/app/(marketing)/solutions/solutions-content-v3.tsx": { type: "t-b", marker: "<BandIndex" },
|
||
// /cases 不进登记表:案例表为空时文字带整条不渲染(零编造,不造客户),
|
||
// 让它出现在表里就等于「判据被代码满足、页面什么也没有」的假锚。
|
||
"src/app/(marketing)/news/news-content-v3.tsx": { type: "t-b", marker: "<BandIndex" },
|
||
"src/app/(marketing)/products/product-detail-content-v3.tsx": { type: "t-a", marker: "<StageIndex" },
|
||
"src/app/(marketing)/solutions/solution-detail-content-v3.tsx": { type: "t-a", marker: "<StageIndex" },
|
||
"src/app/(marketing)/services/service-detail-content-v4.tsx": { type: "t-a", marker: "<StageIndex" },
|
||
};
|
||
// 2026-12-01 影像方向被否后重铺(建筑 → 技术题材),九页一次落地 ⇒ 上限归零锁死。
|
||
// 同日这个常量走过 3(B2 收尾)→ 9(影像被否、落地回滚)→ 0(重铺成立):
|
||
// 棘轮在「落地被撤」时允许回升,一旦落地重新成立必须落到实测值,不能停在宽松位。
|
||
const COMPOSITION_UNMET_CEILING = 0;
|
||
|
||
/**
|
||
* R24 的滚动驱动 API 白名单。
|
||
*
|
||
* 只禁**滚动驱动**(useScroll / useTransform / useMotionValueEvent),不禁 whileInView ——
|
||
* 后者是视口触发器,本仓 26 个文件在用,禁掉等于要求一次全站重构,那不是收尾。
|
||
*
|
||
* 白名单里三处都是既有实现,不是新建:
|
||
* ui/image-module.tsx …… 本轮要复活的影像原语(视差 8% / Ken Burns 一次播完 / reduce 短路)
|
||
* sections/story-stage.tsx · sections/case-detail-page.tsx …… 存量编排,未纳入本轮改造
|
||
* 新增第四处必须在这里登记并写理由,否则 R24 判红。
|
||
*/
|
||
const SCROLL_API_FILES = new Set([
|
||
"src/components/ui/image-module.tsx",
|
||
"src/components/sections/story-stage.tsx",
|
||
"src/components/sections/case-detail-page.tsx",
|
||
]);
|
||
|
||
/**
|
||
* R25 的递减棘轮:登记页里**裸写** text-6xl / text-7xl 的**出现次数**。
|
||
*
|
||
* 口径改过一次,原因是「文件数」这个分母被自己算死了:2026-12-01 登记表缩到 5 页后,
|
||
* 5 个页**全部**裸写 ⇒ 上限 5 = 全员,判据只防「第 6 个文件」,实际约束力接近零。
|
||
* 改成次数口径后,当前 14 处是上限,**新增第 15 处即判红** —— 同样的存量,闸有牙了。
|
||
*
|
||
* 页级断言应走 `ui/display-statement.tsx`(有实现有测试,消费者极少);
|
||
* 但**尺寸会变**(6xl=60px vs statement≈81px),所以页面统一化是独立动作,
|
||
* 必须连同基线一起做,不能夹在判据改动里假装"只换写法"。
|
||
*/
|
||
const RAW_STATEMENT_CEILING = 14;
|
||
|
||
|
||
/**
|
||
* R12 的「测量值 ↔ 声明值」对账表。
|
||
* 出处:2026-11-02 对 Porsche Consulting 中国站首页逐个 <img> 的 getBoundingClientRect 实测
|
||
* (1600×900 视口),四种比例各绑一个构图角色。数值同时落在两处:
|
||
* globals.css 的 --aspect-*(运行时用)与 src/lib/constants/image-ratios.ts(JS 侧用)。
|
||
* 两处必须逐字相等 —— 本仓真实踩过「两套 gutter 同时在线」的散字面量病,
|
||
* 而对账表写在闸里、不写在文档里,是因为文档会在第一次改值时腐烂,闸不会。
|
||
*/
|
||
const ASPECT_MEASURED = {
|
||
"hero-wide": "2.31", // 1600×692 全幅首屏
|
||
"editorial": "1.5", // 606×404 编辑卡
|
||
"square": "1", // 499/464 见方 —— 横向轨每一格
|
||
"tile": "1.42", // 653×459 行业格
|
||
};
|
||
const IMAGE_RATIOS_TS = "src/lib/constants/image-ratios.ts";
|
||
|
||
/**
|
||
* R13–R17 的扫描面 = 「营销面」。
|
||
*
|
||
* 为什么范围要收窄到这一层:`src/components/ui/**` 里的 rounded-full 是**功能形状**
|
||
* (avatar / switch 钮 / slider 钮 / radio / progress / scroll-area / skeleton 点),
|
||
* R2 的正向守卫专门保护它们不被"语法收口"顺手方角化。把营销规则套到 ui/ 上,
|
||
* 就是把 R2 防的那个自伤从另一头实现一遍。
|
||
*
|
||
* 为什么要一条「地板」而不是只报分母:这五条的分母是**扫描到的文件数**,
|
||
* 清账成功后它会趋近于 0;而 `main()` 里「分母 0 = 未能度量 = EXIT=2」那条纪律
|
||
* 会把「已全部清零」误报成「仪器坏了」。反之若路径正则哪天失配(目录改名、
|
||
* `(marketing)` 前缀变动),扫描数会静默掉到 0,五条判据同时空转且全绿 ——
|
||
* 那才是真正的假绿。所以给一个实测下界(2026-11-02 实测 80 个文件),
|
||
* 跌破即判红:判据失去目标必须可见。
|
||
*/
|
||
const MARKETING_SCOPE_RE = /^src\/app\/\(marketing\)\/.+\.tsx$|^src\/components\/(sections|detail|layout)\/.+\.tsx$/;
|
||
const MARKETING_TEST_RE = /\.(test|spec)\.tsx?$/;
|
||
const MARKETING_FLOOR = 60;
|
||
|
||
/**
|
||
* R13–R19 的**存量上限**(R13–R17 现取 2026-11-02;R18/R19 现取 2026-11-03:
|
||
* 营销面 78 个 .tsx,排除 .test/.spec 与 _archive)。
|
||
* 每条只许减不许加;跌破即提示下调(同 R10 棘轮的纪律,防止「闸还在、存量已被自己删空」
|
||
* 退化成永久豁免)。清零后把上限登记为 0,判据即变成硬禁。
|
||
*
|
||
* R18 是**硬禁**(0):签名件(斜线纹 / 双 V / 斜杠)在 2026-11-03 之前全仓零命中,
|
||
* 没有「存量」可言 —— 登记一个非零上限等于给第二份纹样真源预开一个名额。
|
||
* R19 是棘轮(21):营销面实测 21 处 font-extrabold,先登记再随模板批逐页清。
|
||
* R15 于 2026-11-03 由 21 下调到 20:首页 v16→v17 重写时删掉了一处装饰阴影,
|
||
* 按「只降不升」的纪律在同一提交里把上限跟着降下来(否则棘轮成了永久豁免)。
|
||
* 同日 hub 六页(P4-B1)清账后再次下调:R13 71→67 · R14 21→17 · R15 20→16 ·
|
||
* R16 26→22 · R17 53→43 · R19 21→11。降的是**真实存量**,不是为了让闸变绿而改数。
|
||
* 同日详情五页(P4-B2)清账后再降:R13 67→48 · R14 17→13 · R15 16→13 ·
|
||
* R16 22→8(其中 2 处来自新开的**内联通道**,见 BRAND_SURFACE_INLINE_RE)·
|
||
* R17 43→39 · R19 11→7。
|
||
* 同日信任四页(P4-B3)清账后再降:R13 48→40 · R14 13→12 · R15 13→12 · R17 39→22 ·
|
||
* R19 7→**0**(`font-extrabold` 至此清零,R19 从棘轮变硬禁)。
|
||
* 同日共享详情件(P4-B4)清账:R13 40→19 · R14 12→7 · R15 12→7 · R17 22→13。
|
||
* 残余 19/8 集中在 `about/brand`(已裁定的遗产豁免,随页面退役)与
|
||
* `products/standalone/[id]`(seed 无数据、不可观测)。
|
||
*
|
||
* 2026-11-26(ADR-0013 批 1+2)再降:R13 19→3 · R14 7→5 · R15 7→1 · R16 8→5 · R17 13→1。
|
||
* 营销面分母同时 80→77(删掉 3 个**零渲染点**组件:`service-value` / `solution-value` /
|
||
* `micro-interactions`,它们只被 `detail/index.ts` 的 barrel 再导出,故 `dead-modules.mjs`
|
||
* 判不出死码 —— 见 `OPEN-16`)。批 1 清的是死码与无守卫路由(`/cases/[slug]`、
|
||
* `standalone` 详情),批 2 清的是 `/about/brand` 单页(R17 11 处 900 字重 → 700)。
|
||
* 2026-12-02(OPEN-05b 批 3 清零,ADR-0013 §8):剩余 15 处全部落地 —— detail 件
|
||
* 直角化 + R16「红不做面」裁定为中性面留红点缀(bg-bg-elevated / bg-bg-primary/80,
|
||
* 红降级为 text-brand-ink 文字/图标点缀)+ hub 列表箭头去竖直分量 + erp-upgrade 卡片
|
||
* 去抬升。R13–R17 上限同批下调至 0,棘轮转硬禁(新增 1 处即判红)。
|
||
*/
|
||
const MARKETING_HIT_CEILINGS = { R13: 0, R14: 0, R15: 0, R16: 0, R17: 0, R18: 0, R19: 0 };
|
||
|
||
/**
|
||
* 判据正则一律**不带 g 旗标**。
|
||
* 这不是风格问题:带 /g 的模块级正则是状态机,`.test()` 会推进 lastIndex,
|
||
* 下一次调用从中间位置开始 —— 同一条规则先 filter 再 match 时,
|
||
* 第二次读数会因上一次的匹配位置而漏计。自证当场就把这个形状抓红了
|
||
* (R13–R17 棘轮全条不成立),而它在真实运行里只表现为「少报几处」= 半个假绿。
|
||
* 所有消费点都是 `.match(re)` / `new RegExp(re.source)`,非 g 语义完全等价。
|
||
*/
|
||
const ROUNDED_UTILITY_RE = /\brounded-(?:md|lg|xl|2xl|3xl|full)\b/;
|
||
const HOVER_LIFT_RE = /hover:-translate-y\b/;
|
||
/** 装饰阴影:任意 hover:shadow*(含 hover:shadow-[…] 带值那族)+ lg/xl/2xl 档 */
|
||
const DECOR_SHADOW_RE = /(?:hover:shadow(?:-[a-z0-9]+)?(?::\[[^\]]+\])?|\bshadow-(?:2xl|xl|lg)\b)/;
|
||
/**
|
||
* R16 的**两条通道**。为什么必须两条:类名通道可以被内联样式整条绕过 ——
|
||
* 实测案例 `src/components/sections/case-detail-page.tsx` 把整整一个 section 刷成
|
||
* `style={{ background: "var(--color-brand)" }}`,类名通道零命中,闸看不见,
|
||
* 而那正是「饱和红从不用作面」最严重的一种违反。
|
||
* 内联通道只认**品牌底色**写法:`background` / `backgroundColor` 取 `var(--color-brand*)`。
|
||
* 不认 `color:`(文字通道由 check:brand-token 管)也不认任意色值(避免与 accents 闸重叠)。
|
||
*/
|
||
const BRAND_SURFACE_RE = /\bbg-brand-(?:soft|section)\b/;
|
||
const BRAND_SURFACE_INLINE_RE = /\bbackground(?:Color)?\s*:\s*["'`]\s*var\(\s*--color-brand(?:-soft|-section)?\s*\)/;
|
||
const FONT_BLACK_RE = /\bfont-black\b/;
|
||
const FONT_EXTRA_BOLD_RE = /\bfont-extrabold\b/;
|
||
/**
|
||
* 签名件(斜线纹 / 双 V / 斜杠)的**字面量**。锛的是实测原物的可辨认片段:
|
||
* `tile_hatching` —— 对标那张 20×20 SVG 平铺图的名字;
|
||
* `rotate(140` —— 那张图的 patternTransform(本仓正确的等价形是 CSS 变量,不写角度字面量);
|
||
* `M22 14.204` / `M70.09 0` / `M15.2539` —— 三枚原物的路径首段。
|
||
* 命中即意味着有人绕开了 ui/ 下的原语,把手抄的第二份纹样塞进了营销页。
|
||
*/
|
||
const SIGNATURE_LITERAL_RE = /tile_hatching|rotate\(\s*140|M22 14\.204|M70\.09 0|M15\.2539/;
|
||
|
||
/**
|
||
* 数命中数。**必须每次新建 RegExp**:带 g 的正则是状态机,复用同一个实例时
|
||
* .test() / .exec() 会推进 lastIndex,下一条规则从中间位置开始读 ——
|
||
* 本仓真实踩过(自证把 R13–R17 棘轮全条抓红就是它)。
|
||
* 反过来,不带 g 的 /x/.match() 只返回**第一个**匹配、数出来恒为 1,
|
||
* 会把「实测 N 处」静默读成 1 —— 那是另一种假绿,而且更难发现。
|
||
* 所以计数只走这一条路:新实例 + g + 长度。
|
||
*/
|
||
/**
|
||
* R20 死样式的**第二族**:`<utility>-<color>/<alpha>` 里 alpha 不在 Tailwind opacity scale 内。
|
||
*
|
||
* 为什么这条必须存在(2026-11-24 两次真实踩中):
|
||
* · 审计抓到 P0-2 —— 移动抽屉写 `bg-bg-primary/98`,`/98` 不在 scale 里,
|
||
* 编译器**静默不生成**该规则,抽屉 computed 背景 `rgba(0,0,0,0)`,白字直接压在首页深色图上。
|
||
* · 同一天本人在重做首屏时又写成 `bg-[#0B0A08]/92`,同样静默失效(面板整块透明),
|
||
* 而 type-check / lint / build 三道全绿、单测也不会报 —— 因为**源码里 class 明明写着**。
|
||
* 「class 写在源码里」与「CSS 真的存在」是两件事,只有编译器知道后者。
|
||
* 与 §5.20 的 `-[var(--color-*)]/<alpha>` 族同源但不同根因:那一族是 Tailwind 不能给
|
||
* 纯 hex 变量套 alpha;这一族是它**不给 scale 之外的值生成类**(任意值 `[0.92]` 可以,
|
||
* 裸 `/92` 不行)。两者都不报错。
|
||
*
|
||
* 判据:只认「`/` 后紧跟数字」的裸值形态,要求它属于 scale
|
||
* (0/5/10/…/95/100,即 5 的倍数)。任意值形态 `/[0.92]` 不在射程内 —— 它本来就合法。
|
||
* 扫描面 = 全 `src`(不限营销面):这类失效与页面性质无关,ui/ 里写错一样是死样式。
|
||
*/
|
||
const OPACITY_SCALE = new Set(["0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"]);
|
||
/** 任意值色标(`bg-[#0B0A08]`)与命名色标(`bg-white`)后面跟裸数字 alpha 的形态 */
|
||
const NON_SCALE_ALPHA_RE = /(?<![\w-])(?:bg|text|border|ring|divide|outline|fill|stroke|from|via|to|placeholder|accent|caret|decoration|shadow)-[^\s"'`/]*\/(\d{1,3})(?![\d.\w[-])/g;
|
||
|
||
/**
|
||
* R21 死样式的**第三族**:自定义命名空间的类名写了,但 CSS 里从未定义过。
|
||
*
|
||
* 为什么必须存在(2026-11-03 审计发现、2026-11-25 才收口):
|
||
* privacy / terms / not-found / error / SkeletonHero / standalone 六处写了
|
||
* `container-wide`,而全仓从没有一条 `.container-wide` 规则 —— 于是这些页的内容
|
||
* **贴左边缘、没有栅格**,而 type-check / lint / build / 单测 / axe 五道全绿。
|
||
* 与 R20 是同一种病(「class 在源码里」≠「CSS 真的存在」),只是成因不同:
|
||
* R20 是 Tailwind 拒收 scale 外的 alpha,R21 是这个名字根本没人定义。
|
||
*
|
||
* 判据刻意收窄到**本仓自有命名空间**(container- / section- / bain- / list- / prose
|
||
* 之外的少数固定几个)—— Tailwind 的任意 utility 无穷多,全量枚举不可能;
|
||
* 而这几族是本仓 globals.css 用 `@layer utilities` 手工定义的,数量有限、可枚举。
|
||
* 枚举不到就判红 = 强制「要用自定义类名就必须先在 CSS 里定义它」。
|
||
*/
|
||
/**
|
||
* 只收录**本仓 globals.css 用 @layer utilities 手工定义**的族,外加少数精确名。
|
||
*
|
||
* 刻意不收录的:
|
||
* · `list-*` —— `list-none` / `list-disc` / `list-inside` 是 Tailwind 原生 utility,
|
||
* 按前缀收会把它们全判成"未定义"(实测第一版就这样误报 3 条)。
|
||
* 本仓自有的只有 `list-plain`,走精确名。
|
||
* · `prose*` 走**精确名**而不是前缀:2026-11-25 起本仓手写了 `.prose` 排版层
|
||
* (src/app/globals.css,决策见 docs/adr/0010-prose-layer-by-hand.md),
|
||
* 所以 `prose` 现在是「必须真有定义」的一员。仍不收 `prose-*` 前缀 —— 那一族
|
||
* 原本属 @tailwindcss/typography(本仓没装),收前缀会把历史上写了 `prose-lg`
|
||
* 这类死类名的地方一起判红,而它们正随本次迁移逐个消失
|
||
* (使用侧判据见 src/app/__tests__/prose-layer.test.ts)。
|
||
*/
|
||
const CUSTOM_CLASS_PREFIXES = ["container-", "section-", "bain-", "editorial-", "signature-"];
|
||
/** 精确名(不走前缀,避开与 Tailwind 原生族撞名);`prose` 自 2026-11-25 起由本仓手写定义(ADR-0010) */
|
||
const CUSTOM_CLASS_EXACT = new Set(["list-plain", "prose"]);
|
||
|
||
const countHits = (text, re) => (text.match(new RegExp(re.source, "g")) || []).length;
|
||
|
||
// ---- 源码遍历(只用 node 内置,避开第三方)----
|
||
function walk(dir, out = []) {
|
||
let ents;
|
||
try { ents = readdirSync(dir, { withFileTypes: true }); } catch { return out; }
|
||
for (const e of ents) {
|
||
if (e.name === "node_modules" || e.name === ".git" || e.name === "dist") continue;
|
||
const p = path.join(dir, e.name);
|
||
if (e.isDirectory()) walk(p, out);
|
||
else if (/\.(tsx?|css)$/.test(e.name)) out.push(p);
|
||
}
|
||
return out;
|
||
}
|
||
|
||
// ---- 剥注释 ----
|
||
// 必要性(本轮真实踩到):不剥的话,解释「为什么退出 rounded-full」的文档注释本身会被判红,
|
||
// 于是只剩两条出路 —— 要么改措辞去绕闸(应试,闸就此失去解释力),要么把闸调瞎。
|
||
// 正确做法是让闸只看代码。CSS 与 TS/TSX 各自的注释语法分别处理。
|
||
function stripComments(src, { line = false } = {}) {
|
||
// 块注释:整段替换成**等量换行**,否则后面的行号会集体上移,
|
||
// 闸报出来的 L### 就指不到真正的那一行(判据不可行动 = 半个假绿)。
|
||
let out = src.replace(/\/\*[\s\S]*?\*\//g, (m) => "\n".repeat((m.match(/\n/g) || []).length));
|
||
if (line) out = out.replace(/(^|[^:'"`\\])\/\/[^\n]*/g, "$1");
|
||
return out;
|
||
}
|
||
|
||
// ---- 解析 :root 里的 --radius-*(按 selector 块配对,同 check-token-twins 的教训:
|
||
// 跨块配对会把明暗两套主题误当成一对)----
|
||
function parseRadii(text) {
|
||
const lines = text.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 = {}; blocks.push(cur); continue; }
|
||
if (st === "}") { cur = null; continue; }
|
||
if (!cur) continue;
|
||
const m = /^\s*(--radius-[a-z0-9]+)\s*:\s*([-\d.]+)(px|rem|em|%)?\s*;/.exec(lines[i]);
|
||
if (m) cur[m[1]] = { raw: `${m[2]}${m[3] || "px"}`, value: Number.parseFloat(m[2]), unit: m[3] || "px", line: i + 1 };
|
||
}
|
||
// :root 取第一个块(globals.css 的 :root 在最前)
|
||
const rootBlock = blocks.find((b) => Object.keys(b).some((k) => k.startsWith("--radius-"))) || {};
|
||
return { blocks: blocks.length, radii: rootBlock };
|
||
}
|
||
|
||
// ---- 规则实现 ----
|
||
// 累加器必须是「每次调用各自一份」。此前 results/rule 挂在 module 层,第二次调
|
||
// checkGrammar 会往同一数组追加,而 selftest 里的 .find("R10") 取到的是**第一次**
|
||
// 那份读数 —— 于是 R10 的负对照被读成"不判红"。主流程只调一次所以毫无症状,
|
||
// 属于「仪器只在被复用时才坏」那一类,也正是自证该抓的东西。
|
||
function checkGrammar(rawText, rawFiles, twConfig = "", opts = {}) {
|
||
const results = [];
|
||
const rule = ({ id, name, denominator, red, note }) => {
|
||
results.push({ id, name, denominator, red, note });
|
||
};
|
||
|
||
// 闸只看代码:统一先剥注释,再交给各条规则
|
||
const text = stripComments(rawText);
|
||
const files = new Map([...rawFiles].map(([k, v]) => [k, stripComments(v, { line: true })]));
|
||
const { radii } = parseRadii(text);
|
||
const names = Object.keys(radii);
|
||
|
||
// R1 radius 记档:除 full / cta 外,一律 0–4px
|
||
const register = names.filter((n) => n !== "--radius-full" && n !== "--radius-cta");
|
||
const r1Red = [];
|
||
for (const n of register) {
|
||
const v = radii[n];
|
||
// rem/em/% 一律视为未收口(本仓 html{font-size} 随断点变 16/17/18,rem 圆角等于不可预测)
|
||
if (v.unit !== "px") r1Red.push(`${n} = ${v.raw} (L${v.line}) 非 px —— rem 圆角随断点漂移`);
|
||
else if (v.value > 4) r1Red.push(`${n} = ${v.raw} (L${v.line}) > 4px,超出 0–4 记档`);
|
||
}
|
||
rule({ id: "R1", name: "radius 记档 0–4px", denominator: register.length, red: r1Red });
|
||
|
||
// R2 --radius-full 必须活着且仍是真圆(正向守卫,防「一并归零」的自伤)
|
||
const full = radii["--radius-full"];
|
||
const r2Red = [];
|
||
if (!full) r2Red.push("--radius-full 不存在 —— 会方角化 avatar/switch/slider/radio/progress/scroll-area/skeleton");
|
||
else if (full.value < 9999) r2Red.push(`--radius-full = ${full.raw} < 9999px —— 真圆承载被破坏`);
|
||
rule({ id: "R2", name: "--radius-full 仍为真圆(负对照维度)", denominator: 1, red: r2Red });
|
||
|
||
// R3 --radius-cta 必须存在且为 0
|
||
const cta = radii["--radius-cta"];
|
||
const r3Red = [];
|
||
if (!cta) r3Red.push("--radius-cta 不存在 —— 两轨 CTA 无专用直角档");
|
||
else if (cta.value !== 0) r3Red.push(`--radius-cta = ${cta.raw} ≠ 0px —— CTA 未直角化`);
|
||
rule({ id: "R3", name: "--radius-cta 存在且为 0", denominator: 1, red: r3Red });
|
||
|
||
// R4 编辑类 CTA 表面不得再用 rounded-full(胶囊是本轮要退出的语法)
|
||
// 注意范围**只含** cta-button 与 badge:button.tsx 的 icon 档与涟漪点是「功能性的圆」,
|
||
// 由 R9 单独管,硬塞进 R4 会逼着把圆形控件也方角化(那正是 R2 要防的自伤)。
|
||
const r4Red = [];
|
||
let r4Den = 0;
|
||
for (const rel of CTA_SURFACES) {
|
||
const f = files.get(rel);
|
||
if (f === undefined) { r4Red.push(`${rel} 读不到 —— 判据失去目标`); continue; }
|
||
const hits = (f.match(/rounded-full/g) || []).length;
|
||
r4Den += 1;
|
||
if (hits > 0) r4Red.push(`${rel} 有 ${hits} 处 rounded-full(应走 rounded-cta)`);
|
||
}
|
||
rule({ id: "R4", name: "CTA/badge 表面零 rounded-full", denominator: r4Den, red: r4Red });
|
||
|
||
// R5 彩色阴影:令牌不得仍在 :root 里定义(对标两家的面全是无彩阴影或无阴影)
|
||
const colorShadowTokens = ["--shadow-brand", "--shadow-brand-hover", "--shadow-glow"]
|
||
.filter((t) => new RegExp(`^\\s*${t}\\s*:`, "m").test(text));
|
||
const r5Red = colorShadowTokens.map((t) => `${t} 仍定义于 globals.css —— 彩色阴影是对标没有的语法`);
|
||
rule({ id: "R5", name: "彩色阴影令牌已退役", denominator: 3, red: r5Red });
|
||
|
||
// R6 .bain-card:hover 不得有位移抬升(两家 hover 只改 hairline→rule,不 lift)
|
||
const cardHover = /\.bain-card:hover\s*\{([^}]*)\}/s.exec(text);
|
||
const r6Den = cardHover ? 1 : 0;
|
||
const r6Red = [];
|
||
if (!cardHover) r6Red.push("找不到 .bain-card:hover 块 —— 无法判定 lift 是否已去");
|
||
else if (/translate[3d]?Y|transform\s*:/.test(cardHover[1])) r6Red.push(".bain-card:hover 仍有 transform/translateY 抬升");
|
||
rule({ id: "R6", name: ".bain-card hover 无位移抬升", denominator: r6Den, red: r6Red });
|
||
|
||
// R7 弱口径防护:彩色阴影即使令牌删了,工具类引用也不能残留在业务代码
|
||
const r7Red = [];
|
||
let r7Den = 0;
|
||
for (const [rel, f] of files) {
|
||
if (rel === "src/app/globals.css") continue;
|
||
const hits = (f.match(/\bshadow-(brand-hover|brand|glow)\b/g) || []).length;
|
||
if (hits > 0) { r7Den += 1; r7Red.push(`${rel} 仍消费彩色阴影 ${hits} 处`); }
|
||
}
|
||
rule({ id: "R7", name: "业务代码零彩色阴影消费", denominator: r7Den, red: r7Red, note: "分母为「仍在消费的文件数」,0 = 已清零(成立),非「未度量」" });
|
||
|
||
// R8 组件级圆角令牌必须落进记档 —— R4 只扫工具类,会漏掉 --badge-radius: var(--radius-full)
|
||
// 这类「走令牌而不是走 class」的路径(本轮实测确实漏了 badge,故补此条)。
|
||
// 例外:--avatar-radius 承载真圆,必须指向 --radius-full。
|
||
const CIRCLE_TOKENS = new Set(["--avatar-radius"]);
|
||
const compTokens = [...text.matchAll(/^\s*(--[a-z0-9-]*(?:radius)[a-z0-9-]*)\s*:\s*([^;]+);/gm)]
|
||
.map((m) => ({ name: m[1], value: m[2].trim() }))
|
||
.filter((t) => t.name !== "--radius-xs" && !/^--radius-/.test(t.name));
|
||
const r8Red = [];
|
||
for (const t of compTokens) {
|
||
const ref = /var\(\s*(--radius-[a-z0-9]+)\s*\)/.exec(t.value);
|
||
const lit = /^[-\d.]+(px|rem|em|%)?$/.test(t.value) ? t.value : null;
|
||
if (ref) {
|
||
const target = ref[1];
|
||
if (CIRCLE_TOKENS.has(t.name)) {
|
||
if (target !== "--radius-full") r8Red.push(`${t.name} = var(${target}) —— 真圆承载被改走,应指回 --radius-full`);
|
||
} else if (target === "--radius-full") {
|
||
r8Red.push(`${t.name} = var(--radius-full) —— 胶囊语法未退出,应指 var(--radius-cta)`);
|
||
}
|
||
} else if (lit && /px$/.test(lit) && Number.parseFloat(lit) > 4 && !CIRCLE_TOKENS.has(t.name)) {
|
||
r8Red.push(`${t.name} = ${lit} > 4px,超出记档`);
|
||
} else if (!ref && !lit) {
|
||
r8Red.push(`${t.name} = "${t.value}" —— 既非记档字面量也非 var() 引用,无法判定`);
|
||
}
|
||
}
|
||
rule({ id: "R8", name: "组件级圆角令牌落进记档(补 R4 的令牌路径盲区)", denominator: compTokens.length, red: r8Red });
|
||
|
||
// R9 button.tsx 尺寸档:文字按钮走 rounded-cta,icon 档**必须**保持 rounded-full。
|
||
// 这一条同时是正例与反例:文字档出现胶囊 ⇒ 判红;icon 档被一起归零 ⇒ 也判红
|
||
// (圆形图标钮是功能形状,与 avatar/开关钮同类,不该被"语法收口"顺手带走)。
|
||
const btn = files.get(BUTTON_FILE);
|
||
const r9Red = [];
|
||
let r9Den = 0;
|
||
if (btn === undefined) {
|
||
r9Red.push(`${BUTTON_FILE} 读不到 —— 判据失去目标`);
|
||
} else {
|
||
const sizeBlock = /size:\s*\{([\s\S]*?)\n\s*\},/.exec(btn);
|
||
if (!sizeBlock) {
|
||
r9Red.push("找不到 button.tsx 的 size 变体块 —— 无法判定,不算通过");
|
||
} else {
|
||
const body = sizeBlock[1];
|
||
for (const key of ["sm", "default", "lg", "xl"]) {
|
||
const m = new RegExp(`^\\s*${key}:\\s*'([^']*)'`, "m").exec(body);
|
||
if (!m) { r9Red.push(`size.${key} 未找到 —— 判据失去目标`); continue; }
|
||
r9Den += 1;
|
||
if (/rounded-full/.test(m[1])) r9Red.push(`size.${key} 仍是 rounded-full(应走 rounded-cta):${m[1]}`);
|
||
else if (!/rounded-cta/.test(m[1])) r9Red.push(`size.${key} 未声明 rounded-cta:${m[1]}`);
|
||
}
|
||
const icon = /^\s*icon:\s*'([^']*)'/m.exec(body);
|
||
if (!icon) r9Red.push("size.icon 未找到 —— 无法确认圆形控件未被方角化");
|
||
else {
|
||
r9Den += 1;
|
||
if (!/rounded-full/.test(icon[1])) r9Red.push(`size.icon 丢了 rounded-full —— 圆形图标钮被方角化(功能形状,非装饰圆角):${icon[1]}`);
|
||
}
|
||
}
|
||
}
|
||
rule({ id: "R9", name: "按钮尺寸档直角、icon 档保持圆(双向)", denominator: r9Den, red: r9Red });
|
||
|
||
/**
|
||
* R10 hover 位移抬升的**递减棘轮**(上限见 module 层 HOVER_LIFT_CEILING 的注释)。
|
||
* 实测两家 hover 都不抬升(Bain 卡片靠 hairline、Porsche 靠图与留白),本批已把
|
||
* .bain-card 的 translateY(-4px) 去掉;但业务代码里还散落着 28 处 hover:-translate-y
|
||
* (19 文件),全改是又一次全站视觉改动,不该塞进 tracer-bullet。
|
||
* 所以按"当前实测数"登记上限做递减棘轮:变多判红、变少**不判红但提示下调登记值**
|
||
* (改进不该被闸挡住,那是棘轮自堵还债的老坑)。
|
||
*/
|
||
let liftCount = 0;
|
||
const liftFiles = [];
|
||
for (const [rel, f] of files) {
|
||
const n = (f.match(/hover:-translate-y/g) || []).length;
|
||
if (n > 0) { liftCount += n; liftFiles.push(`${rel}=${n}`); }
|
||
}
|
||
const r10Red = liftCount > HOVER_LIFT_CEILING
|
||
? [`hover 抬升 ${liftCount} 处 > 登记上限 ${HOVER_LIFT_CEILING}(对标实测两家 hover 都不抬升)`]
|
||
: [];
|
||
// 「实测 < 登记」的下调提示只进 note、不 print:checkGrammar 现在被自证反复调用,
|
||
// 喂合成样本时打「请把上限下调到 0」是噪声,会把人引去改坏登记值。
|
||
rule({ id: "R10", name: `hover 抬升数 ≤ ${HOVER_LIFT_CEILING}(递减棘轮)`, denominator: liftCount, red: r10Red,
|
||
note: liftCount < HOVER_LIFT_CEILING
|
||
? `实测 ${liftCount} 处 / ${liftFiles.length} 文件 < 登记 ${HOVER_LIFT_CEILING},请把上限下调到 ${liftCount}`
|
||
: `实测 ${liftCount} 处 / ${liftFiles.length} 文件` });
|
||
|
||
/**
|
||
* R11 tailwind 映射 → CSS 声明的**悬空守卫**。
|
||
* 本轮真实踩到:三枚彩色阴影令牌从 globals.css 退役后,
|
||
* `tailwind.config.js` 里的 boxShadow.brand / brand-hover / glow 三行映射**原样留着**,
|
||
* 于是 `shadow-brand` 这个类仍在被生成,只是展开成 `box-shadow: var(--shadow-brand)`,
|
||
* 而该自定义属性无人声明 ⇒ 运行时取空、静默什么都不画。
|
||
* 不报错、不判红、单测全绿 —— 属于「孪生问题」里最难发现的那类:
|
||
* **删了值但没删引用**,而闸只盯着值那一侧(R5 令牌退役、R7 业务代码零消费,两条都是绿的)。
|
||
*
|
||
* 外部所有者的变量(Radix 运行时注入)另列白名单,它们本就不该由 globals.css 声明。
|
||
* 白名单同样按名登记并做腐化检测(登记了却没被引用 = 判红),与 check-accents 一个纪律。
|
||
*/
|
||
const declared = new Set([...text.matchAll(/^\s*(--[\w-]+)\s*:/gm)].map((m) => m[1]));
|
||
const twRefs = [...new Set([...stripComments(twConfig, { line: true }).matchAll(/var\(\s*(--[\w-]+)/g)].map((m) => m[1]))];
|
||
const r11Red = [];
|
||
for (const ref of twRefs) {
|
||
if (!declared.has(ref) && !EXTERNAL_OWNED.includes(ref)) {
|
||
r11Red.push(`tailwind 映射引用 ${ref},但 globals.css 未声明 —— 该类会静默展开成空值(僵尸令牌)`);
|
||
}
|
||
}
|
||
const deadAllow = EXTERNAL_OWNED.filter((n) => !twRefs.includes(n));
|
||
if (deadAllow.length) {
|
||
r11Red.push(`外部所有者白名单已腐化:${deadAllow.join(", ")} 已不再被 tailwind 引用,请删掉这条豁免`);
|
||
}
|
||
rule({ id: "R11", name: "tailwind 映射的 var(--*) 必有 CSS 声明(僵尸令牌守卫)", denominator: twRefs.length, red: r11Red,
|
||
note: `引用 ${twRefs.length} 个变量 · 外部所有者豁免 ${EXTERNAL_OWNED.length - deadAllow.length} 条生效` });
|
||
|
||
/**
|
||
* R12–R17:对标**布局层**的判据(2026-11-02 现量,见各常量的出处注释)。
|
||
*
|
||
* 为什么令牌层那 11 条拦不住这一族:R1/R3/R8 看的是 `--radius-*` 声明值,
|
||
* 而 `rounded-full`、`hover:-translate-y`、`bg-brand-soft`、`font-black` 这些**类名**
|
||
* 是在已记档的令牌之上另起的形状 —— 令牌记档 0–4px 全绿的同时,
|
||
* 营销面照样能摆出 71 处胶囊/大圆角、21 处 hover 抬升、26 处彩色面、53 处 900 字重。
|
||
* ADR-0008 决策四当时把模板批推到「过验收之后」,结果就是这批红一直活着、
|
||
* 且没有任何仪器会喊它 —— 本段五条就是补那台仪器。
|
||
*
|
||
* 扫描面必须收窄到营销面(见 MARKETING_SCOPE_RE 的注释):把规则套到
|
||
* `src/components/ui/**` 上,等于从另一头实现 R2 专门防的那个自伤
|
||
* (avatar / switch / slider / progress 的圆是功能形状,不是装饰)。
|
||
*/
|
||
const marketingFiles = [...files].filter(([rel]) => MARKETING_SCOPE_RE.test(rel) && !MARKETING_TEST_RE.test(rel));
|
||
const rScan = marketingFiles.length;
|
||
const rFloor = opts.floor ?? MARKETING_FLOOR;
|
||
|
||
// R13–R17 的「存量上限」:值 = 2026-11-02 现取(见各条 note),只许减不许加。
|
||
// 为什么是**双向**棘轮而不是「清零即通过」:清零之前它有牙(新增一处就判红),
|
||
// 清零之后若留着恒真判据就成了没人看守的永久豁免 —— 这正是 ADR-0008 里
|
||
// 「登记了却命中 0 ⇒ 判红」那条纪律要防的腐化。所以命中数**跌破**登记值时,
|
||
// note 里喊把上限下调;下调到 0 后判据自动退化成硬禁,不再有空转的名单。
|
||
const ceilings = { ...MARKETING_HIT_CEILINGS, ...opts.hitCeilings };
|
||
|
||
/**
|
||
* R12 测量值 ↔ 声明值对账:globals.css 的 --aspect-* 与 image-ratios.ts 的数字必须逐字相等。
|
||
* 这条抓的是**将来**:有人改了 CSS 那侧、或给某个新角色加了第三条真源而忘了另一侧。
|
||
* 两侧都取不到数 = 判据失去目标,按「未能度量」处理(分母 0)。
|
||
*/
|
||
const aspectCss = new Map([...text.matchAll(/^\s*--aspect-([a-z0-9-]+)\s*:\s*([\d.]+)\s*;/gm)].map((m) => [m[1], m[2]]));
|
||
const aspectJs = new Map([...String(opts.jsSources?.[IMAGE_RATIOS_TS] ?? "").matchAll(/(HERO_WIDE|EDITORIAL|SQUARE|TILE|PORTRAIT):\s*([\d.]+)/g)]
|
||
.map((m) => [({ HERO_WIDE: "hero-wide", EDITORIAL: "editorial", SQUARE: "square", TILE: "tile", PORTRAIT: "portrait" })[m[1]], m[2]]));
|
||
const r12Red = [];
|
||
for (const [key, measured] of Object.entries(ASPECT_MEASURED)) {
|
||
const cssV = aspectCss.get(key);
|
||
const jsV = aspectJs.get(key);
|
||
if (cssV === undefined || jsV === undefined) {
|
||
r12Red.push(`--aspect-${key} / IMAGE_RATIOS 缺一侧(css=${cssV ?? "无"} js=${jsV ?? "无"})—— 判据失去目标`);
|
||
} else if (cssV !== measured || jsV !== measured) {
|
||
r12Red.push(`比例漂移 ${key}:实测 ${measured}、globals.css ${cssV}、image-ratios.ts ${jsV}`);
|
||
}
|
||
}
|
||
rule({ id: "R12", name: "影像比例两侧真源与实测值逐字相等", denominator: aspectCss.size, red: r12Red,
|
||
note: `实测四种角色 ${Object.keys(ASPECT_MEASURED).join("/")} · 消费面 ${rScan} 文件` });
|
||
|
||
// R13 营销面零非记档圆角类名。rounded-sm 不在这里 —— 它映射 --radius-sm = 0px,
|
||
// 写了等于没写,不是违规;rounded-(md|lg|xl|2xl|3xl) 才是「在记档档位之外另起形状」。
|
||
const r13Files = marketingFiles.filter(([, f]) => countHits(f, ROUNDED_UTILITY_RE) > 0);
|
||
const r13Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, ROUNDED_UTILITY_RE), 0);
|
||
rule({ id: "R13", name: "营销面零 rounded-(md|lg|xl|2xl|3xl|full) 类名", denominator: rScan,
|
||
red: (rFloor > 0 && rScan < rFloor)
|
||
? [`营销面只扫到 ${rScan} 文件 < 地板 ${rFloor} —— 路径正则失配(目录改名?),本条与其下四条同时空转`]
|
||
: r13Count > ceilings.R13 ? [`营销面非记档圆角 ${r13Count} 处 > 上限 ${ceilings.R13}(卡片圆角请走 rounded-md 的记档值,胶囊走 rounded-cta)`] : [],
|
||
note: `实测 ${r13Count} 处 / ${r13Files.length} 文件 · 上限 ${ceilings.R13}${r13Count < ceilings.R13 ? " ⇒ 请把上限下调" : ""}` });
|
||
|
||
// R14 营销面 hover 不抬升。与 R10 同判据但口径更硬:R10 是全站棘轮、已在 28/28 上限,
|
||
// 新违规可以藏在「没超上限」里;这条只看营销面,且上限跟着清账一起降。
|
||
const r14Hits = marketingFiles.filter(([, f]) => countHits(f, HOVER_LIFT_RE) > 0);
|
||
const r14Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, HOVER_LIFT_RE), 0);
|
||
rule({ id: "R14", name: "营销面 hover:-translate-y 硬禁(补 R10 棘轮的藏污位)", denominator: rScan,
|
||
red: r14Count > ceilings.R14 ? [`营销面 hover 抬升 ${r14Count} 处 > 上限 ${ceilings.R14}(对标实测两家 hover 都不抬升,卡片靠 hairline 与底色)`] : [],
|
||
note: `实测 ${r14Count} 处 / ${r14Hits.length} 文件 · 上限 ${ceilings.R14}${r14Count < ceilings.R14 ? " ⇒ 请把上限下调" : ""}` });
|
||
|
||
// R15 装饰性深阴影。R5/R7 管的是**彩色**阴影(品牌红光晕那一族),
|
||
// 这条管 shadow-lg/xl/2xl 与任意 hover:shadow —— 对标的层次靠留白与影像,不靠投影。
|
||
const r15Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, DECOR_SHADOW_RE), 0);
|
||
rule({ id: "R15", name: "营销面零装饰阴影(shadow-lg|xl|2xl 与任意 hover:shadow)", denominator: rScan,
|
||
red: r15Count > ceilings.R15 ? [`营销面装饰阴影 ${r15Count} 处 > 上限 ${ceilings.R15}(Quiet Border Rule:边框只负责「有没有」,别叠投影)`] : [],
|
||
note: `实测 ${r15Count} 处 · 上限 ${ceilings.R15}${r15Count < ceilings.R15 ? " ⇒ 请把上限下调" : ""}` });
|
||
|
||
// R16 饱和/浅色品牌红不得做「面」。两家实测红只出现在按钮上;本仓把它铺成图标砖
|
||
// (bg-brand-soft) 与满幅段 (bg-brand-section),是决策一「红是结论电压」最直接的稀释。
|
||
const r16ClassCount = marketingFiles.reduce((a, [, f]) => a + countHits(f, BRAND_SURFACE_RE), 0);
|
||
const r16InlineCount = marketingFiles.reduce((a, [, f]) => a + countHits(f, BRAND_SURFACE_INLINE_RE), 0);
|
||
const r16Count = r16ClassCount + r16InlineCount;
|
||
const r16InlineFiles = marketingFiles.filter(([, f]) => countHits(f, BRAND_SURFACE_INLINE_RE) > 0);
|
||
rule({ id: "R16", name: "营销面零品牌红彩色面(类名 + 内联两条通道)", denominator: rScan,
|
||
red: r16Count > ceilings.R16
|
||
? [`营销面彩色面 ${r16Count} 处 > 上限 ${ceilings.R16}(类名 ${r16ClassCount} + 内联 ${r16InlineCount}${r16InlineFiles.length ? ` 内联位于 ${r16InlineFiles.map(([p]) => p).join(", ")}` : ""};红只做:实心 CTA 填充 / eyebrow 短线 / hairline hover / 角牌;中性底走 bg-bg-secondary)`]
|
||
: [],
|
||
note: `实测 ${r16Count} 处(类名 ${r16ClassCount} + 内联 ${r16InlineCount})· 上限 ${ceilings.R16}${r16Count < ceilings.R16 ? " ⇒ 请把上限下调" : ""}` });
|
||
|
||
// R17 字重集合。对标实测层级来自 字号 × 字重 两轴,字重只用 400/500/700;
|
||
// 本仓 53 处 font-black(900) 是「靠更粗建立层级」的单轴做法,与 statement 档冲突。
|
||
const r17Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, FONT_BLACK_RE), 0);
|
||
rule({ id: "R17", name: "营销面零 font-black(900)", denominator: rScan,
|
||
red: r17Count > ceilings.R17 ? [`营销面 font-black ${r17Count} 处 > 上限 ${ceilings.R17}(声明档走 text-statement + font-bold / font-normal 的字重分裂)`] : [],
|
||
note: `实测 ${r17Count} 处 · 上限 ${ceilings.R17}${r17Count < ceilings.R17 ? " ⇒ 请把上限下调" : ""}` });
|
||
|
||
// R18 签名件只能有一个真源。斜线纹 / 双 V / 斜杠三件在 ui/ 下各有原语
|
||
// (hatch-field / double-chevron / slash-mark),营销页只允许 import 它们。
|
||
// 手抄一份路径或背景图 = 第二个真源,以后改几何就会一半新一半旧,而闸看不见 ——
|
||
// 这正是本仓「两套 gutter 同时在线」那一类病的同型。上限登记 0,即硬禁。
|
||
const r18Files = marketingFiles.filter(([, f]) => countHits(f, SIGNATURE_LITERAL_RE) > 0);
|
||
const r18Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, SIGNATURE_LITERAL_RE), 0);
|
||
rule({ id: "R18", name: "营销面零签名件字面量(只许走 ui/ 原语)", denominator: rScan,
|
||
red: r18Count > ceilings.R18
|
||
? [`营销面手抄纹样 ${r18Count} 处 > 上限 ${ceilings.R18}(${r18Files.map(([p]) => p).join(", ")})—— 斜线纹走 HatchField、双 V 走 DoubleChevron、斜杠走 SlashMark`]
|
||
: [],
|
||
note: `实测 ${r18Count} 处 / ${r18Files.length} 文件 · 上限 ${ceilings.R18}` });
|
||
|
||
// R19 字重集合的第二轴。800 不是对标的字重(实测只有 400/700),也不是本仓
|
||
// 声明档的字重(那是 700 + 400 的**字重分裂**)。保留为棘轮而非硬禁,是因为
|
||
// 21 处存量全在模板批的清单里,随 P4 逐页清;清完把上限降到 0 即变硬禁。
|
||
const r19Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, FONT_EXTRA_BOLD_RE), 0);
|
||
rule({ id: "R19", name: "营销面零 font-extrabold(800)", denominator: rScan,
|
||
red: r19Count > ceilings.R19 ? [`营销面 font-extrabold ${r19Count} 处 > 上限 ${ceilings.R19}(层级走字号 × 字重两轴:声明档 700/400 分裂,不用更粗的中间档)`] : [],
|
||
note: `实测 ${r19Count} 处 · 上限 ${ceilings.R19}${r19Count < ceilings.R19 ? " ⇒ 请把上限下调" : ""}` });
|
||
|
||
/**
|
||
* R20 任意值/命名色标的裸 alpha 必须落在 Tailwind opacity scale 内(死样式第二族)。
|
||
* 详见 module 层 NON_SCALE_ALPHA_RE 的出处注释。扫描面 = 全 src,不限营销面:
|
||
* 这类失效与页面性质无关,`src/components/ui/**` 里写错同样是「class 在、CSS 不在」。
|
||
*
|
||
* 为什么是**硬禁**(上限 0)而不是棘轮:scale 内的替代值恒存在(差 5% 人眼不可辨),
|
||
* 不存在「先登记再随模板批清」的理由;登记非零上限等于给死样式预开名额。
|
||
*/
|
||
const r20Red = [];
|
||
let r20Den = 0;
|
||
for (const [rel, src] of files) {
|
||
if (!/\.(tsx?|jsx?)$/.test(rel)) continue;
|
||
for (const m of src.matchAll(new RegExp(NON_SCALE_ALPHA_RE.source, "g"))) {
|
||
r20Den += 1;
|
||
const alpha = m[1];
|
||
if (!OPACITY_SCALE.has(alpha)) {
|
||
r20Red.push(`${rel}:\`${m[0]}\` 的 alpha ${alpha} 不在 opacity scale 内 —— Tailwind 会静默不生成该规则,computed 值退化为透明/无色`);
|
||
}
|
||
}
|
||
}
|
||
rule({ id: "R20", name: "裸 alpha 必须落在 opacity scale 内(防 class 在、CSS 不在)", denominator: r20Den, red: r20Red,
|
||
note: `扫描 ${r20Den} 处裸 alpha · 合法集合 = 5 的倍数(0…100)` });
|
||
|
||
/**
|
||
* R21 自定义命名空间类名必须在 CSS 里有定义(详见 module 层 CUSTOM_CLASS_PREFIXES)。
|
||
* 扫描面 = 全 src:这类失效与页面性质无关,privacy/terms 踩过,ui/ 里同样会踩。
|
||
*
|
||
* 分母 = 命中的自定义命名空间 token 总数;红 = 其中在 CSS(已剥注释)里找不到
|
||
* `.token` 定义的那些。CSS 侧同时接受 `.token {` 与 `.token,` / `.token:hover` 等变体,
|
||
* 因此按「`.token` 后紧跟非标识符字符」判定,避免 `.container-x` 误命中 `.container-xyz`。
|
||
*/
|
||
const r21Red = [];
|
||
let r21Den = 0;
|
||
const cssForClasses = `${text}\n${twConfig}`;
|
||
const seen = new Set();
|
||
for (const [rel, src] of files) {
|
||
if (!/\.(tsx?|jsx?)$/.test(rel)) continue;
|
||
for (const m of src.matchAll(/className=(?:"([^"]*)"|\{`([^`]*)`\})/g)) {
|
||
const raw = m[1] ?? m[2] ?? "";
|
||
for (const token of raw.split(/\s+/)) {
|
||
const isCustom = token
|
||
&& (CUSTOM_CLASS_PREFIXES.some((p) => token.startsWith(p)) || CUSTOM_CLASS_EXACT.has(token));
|
||
if (!isCustom) continue;
|
||
const bare = token.replace(/:.*$/, "").replace(/\/.*$/, "");
|
||
if (!bare) continue;
|
||
r21Den += 1;
|
||
const key = `${bare}`;
|
||
const defRe = new RegExp(`\\.${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\w-])`);
|
||
if (!defRe.test(cssForClasses)) {
|
||
if (seen.has(key)) continue;
|
||
seen.add(key);
|
||
r21Red.push(`${rel}:\`${bare}\` 在 CSS 里没有任何定义 —— 该规则不会生成,样式静默失效(R21 第三族死样式)`);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
rule({ id: "R21", name: "自定义命名空间类名必须有 CSS 定义(防第三族死样式)", denominator: r21Den, red: r21Red,
|
||
note: `扫描 ${r21Den} 处自定义类名 · 命名空间 ${CUSTOM_CLASS_PREFIXES.join("/")} + ${[...CUSTOM_CLASS_EXACT].join("/")}` });
|
||
|
||
/**
|
||
* R22 营销页首屏**视觉层登记制**(2026-12-02 第三次改判,理由必须留在这里)。
|
||
*
|
||
* 三次方向变更,每次都是被同一个东西逼的 —— **照片不承担语义**:
|
||
* 1. 最初守 `<SpanField`(B 类矢量原语)⇒「灰阶堆叠读成骨架屏」,用户否决,原语撤除;
|
||
* 2. 改守 `<HeroPlate>` / `<Image`(A 类影像片)⇒「我们是一家 IT 技术咨询公司,
|
||
* 怎么全是钢筋混凝土」,首屏四张建筑影像同批撤除,组件与图库一并删除;
|
||
* 3. 改守**零影像**(2026-12-01)⇒ 首页首屏变成纯排版;同日用户先选 E 案(右栏双 V + 网格),
|
||
* 次日又裁定首页改用**全幅 3D 场景**(ADR-0016)⇒ 零影像这条不再成立。
|
||
*
|
||
* **为什么不是「零影像」而是「登记制」**:零影像只能回答「影像有没有偷偷回来」,
|
||
* 却对 `<canvas>` / `<HeroPlate>` 完全失明 —— 而它们才是首屏最重的视觉层。
|
||
* 一个对主要形态静默放行的闸,等于没有闸。
|
||
*
|
||
* 现行语义:首屏出现任何视觉层(影像 / 3D 场景 / canvas)时,**该文件必须在
|
||
* `HERO_VISUAL_REGISTRY` 登记**,且:
|
||
* - 登记的载体标记必须真的出现在首屏区块内(否则是**登记表过期**,判红);
|
||
* - 登记的 `poster` 必须真实存在于 `public/`(否则降级链是假的,判红)。
|
||
* 未登记的文件出现任何视觉层即判红 —— 16 个页面的「零影像」效果由这条自然保持。
|
||
*
|
||
* 为什么必须先剥注释:本仓踩过 —— `constants.ts` 注释里的示例 import 骗过了
|
||
* `export { … } from` 正则。这里同理:注释里写一句 `<HeroPlate />` 不算数。
|
||
*
|
||
* 为什么分母按「找到几页」而不是恒定 17:路径改名时若照常除以 17,一条红都不会出,
|
||
* 判据就空转了;缺页本身判红(同 R13 的 `MARKETING_FLOOR` 纪律)。
|
||
*/
|
||
const hubFloor = opts.hubFloor ?? HUB_HERO_FILES.length;
|
||
const hubPresent = HUB_HERO_FILES.filter((rel) => files.has(rel));
|
||
const r22Red = [];
|
||
/**
|
||
* 扫描范围分两种,因为「影像」在两类页面上的含义不同:
|
||
* - 一般营销页(16 页):整份文件零影像 —— 它们本来就没有内容图;
|
||
* - 首页:**只在首屏区块内**禁影像。首页的新闻 teaser 用 `<Image>` 是内容图(有出处的
|
||
* 新闻封面),全文件禁会把合法用法判红。首屏区块以 `data-testid="hero-section"` 起、
|
||
* 到最近的 `</section>` 止(首屏不含嵌套 section,这一点由 R22 的 selftest 与首页结构共同保证)。
|
||
*/
|
||
const heroSlice = (src) => {
|
||
const i = src.indexOf('data-testid="hero-section"');
|
||
if (i === -1) return src;
|
||
const j = src.indexOf('</section>', i);
|
||
return j === -1 ? src.slice(i) : src.slice(i, j);
|
||
};
|
||
/* 登记表可注入:自证夹具不该依赖生产数据(本仓踩过「夹具写死生产条目 ⇒ 条目一删判据就崩」)。
|
||
生产调用不传,仍用下面的 HERO_VISUAL_REGISTRY。 */
|
||
const registry = opts.visualRegistry ?? HERO_VISUAL_REGISTRY;
|
||
const posterExists = opts.posterExists ??
|
||
((p) => existsSync(path.join(process.cwd(), "public", p.replace(/^\//, ""))));
|
||
for (const rel of hubPresent) {
|
||
const src = stripComments(files.get(rel) ?? "", { line: true });
|
||
const scope = heroSlice(src);
|
||
const entry = registry.get(rel);
|
||
const tokens = [...scope.matchAll(VISUAL_LAYER_RE)].map((m) => m[1]);
|
||
if (!entry) {
|
||
if (tokens.length > 0) {
|
||
r22Red.push(`${rel}:首屏出现未登记的视觉层(<${tokens[0]}>)—— 请在 HERO_VISUAL_REGISTRY 登记载体/出处/海报帧`);
|
||
}
|
||
continue;
|
||
}
|
||
// 登记 ≠ 该页什么都能放:只批准 `markers` 里点名的载体。没点名的(例如 <Image>)照样判红 ——
|
||
// 否则「登记了一次」就等于给整页发了一张永久的影像许可证,零影像时代守了三次的东西当场作废。
|
||
for (const token of new Set(tokens)) {
|
||
if (!entry.markers.includes(token)) {
|
||
r22Red.push(`${rel}:首屏出现未批准的视觉层(<${token}>)—— 登记表只批准 ${entry.markers.map((m) => `<${m}>`).join(" / ")}`);
|
||
}
|
||
}
|
||
if (!entry.markers.some((m) => tokens.includes(m))) {
|
||
r22Red.push(`${rel}:登记表批准的是 ${entry.markers.map((m) => `<${m}>`).join(" / ")},但首屏内一个都没找到 —— 登记表过期(换了载体没改登记,或标记被删)`);
|
||
}
|
||
if (!posterExists(entry.poster)) {
|
||
r22Red.push(`${rel}:登记的海报帧 public${entry.poster} 不存在 —— 降级链是假的(WebGL 失败/移动档会露出空白)`);
|
||
}
|
||
}
|
||
// 登记表里登记了却不在扫描名单里的文件 = 表在自说自话
|
||
for (const rel of registry.keys()) {
|
||
if (!HUB_HERO_FILES.includes(rel)) {
|
||
r22Red.push(`${rel}:在 R22 登记表里,但不在 HUB_HERO_FILES —— 登记与扫描面不一致,这一条对它空转`);
|
||
}
|
||
}
|
||
if (hubPresent.length < hubFloor) {
|
||
r22Red.push(`营销页首屏只找到 ${hubPresent.length}/${hubFloor} 页 —— 路径改名或文件被移动,本条对缺的那几页空转`);
|
||
}
|
||
rule({ id: "R22", name: "营销页首屏视觉层必须登记(载体 + 出处 + 海报帧)", denominator: hubPresent.length, red: r22Red,
|
||
note: `找到 ${hubPresent.length}/${HUB_HERO_FILES.length} 页 · 已登记 ${registry.size} 页 · 未登记文件出现 ${VISUAL_LAYER_RE.source} 任一即判红` });
|
||
|
||
/**
|
||
* R23 正文构型:每页必须命中登记过的那一件(表见 COMPOSITION_FILES 注释)。
|
||
*
|
||
* 判「命中」的方式换了两次,两次都是为了让判据认的是**内容**而不是文件名:
|
||
* 第一版按 `<EditorialFigure>` 切段看 variant(防邻页写法互相带过);
|
||
* 影像被否后改为按**载体标记**(`<StageIndex` / `<BandIndex`)判,
|
||
* 且必须出现在非注释行 —— 注释里写一句 `<StageIndex />` 不算数(R22 同款假绿)。
|
||
*/
|
||
const compEntries = Object.entries(COMPOSITION_FILES);
|
||
const r23Unmet = [];
|
||
for (const [rel, spec] of compEntries) {
|
||
const src = files.get(rel);
|
||
if (!src) {
|
||
r23Unmet.push(`${rel}:文件不存在 —— 路径改名或页面被移动,R23 对这一页空转`);
|
||
continue;
|
||
}
|
||
const live = src
|
||
.split('\n')
|
||
.filter((line) => !/^\s*(\/\/|\*|\/\*)/.test(line))
|
||
.join('\n');
|
||
if (!live.includes(spec.marker)) {
|
||
r23Unmet.push(`${rel}:未见 ${spec.marker} —— 正文构型(${spec.type})缺失或换了载体`);
|
||
}
|
||
}
|
||
const compCeiling = opts.compositionUnmetCeiling ?? COMPOSITION_UNMET_CEILING;
|
||
rule({
|
||
id: "R23",
|
||
name: "正文构型必须用登记的那一件(t-a 阶段脊线 / t-b 文字索引带)",
|
||
denominator: compEntries.length,
|
||
red: r23Unmet.length > compCeiling
|
||
? [`未达 ${r23Unmet.length} 页 > 上限 ${compCeiling}(${r23Unmet.map((m) => m.split(":")[0]).join(", ")})`]
|
||
: [],
|
||
note: `未达 ${r23Unmet.length}/${compEntries.length} 页 · 上限 ${compCeiling}${r23Unmet.length < compCeiling ? " ⇒ 请把上限下调" : ""}`,
|
||
});
|
||
|
||
/**
|
||
* R24 滚动驱动 API 白名单(见 SCROLL_API_FILES 注释)。
|
||
* 只禁滚动驱动,不禁 whileInView —— 后者是视口触发器,26 个文件在用。
|
||
* 白名单外出现即判红,不给棘轮:新增第四处必须先登记理由。
|
||
*/
|
||
const SCROLL_API_RE = /\b(?:useScroll|useTransform|useMotionValueEvent)\s*\(/;
|
||
const scrollUsers = [...files.entries()].filter(([, src]) => SCROLL_API_RE.test(src)).map(([rel]) => rel);
|
||
const r24Red = scrollUsers
|
||
.filter((rel) => !SCROLL_API_FILES.has(rel))
|
||
.map((rel) => `${rel}:滚动驱动 API 不在白名单 —— 编排请走 ui/image-module,或先在 SCROLL_API_FILES 登记理由`);
|
||
rule({
|
||
id: "R24",
|
||
name: "滚动驱动 API 只出现在登记的编排原语里",
|
||
denominator: Math.max(scrollUsers.length, 1),
|
||
red: r24Red,
|
||
note: `${scrollUsers.length} 个文件使用滚动 API · 白名单 ${SCROLL_API_FILES.size} 处`,
|
||
});
|
||
|
||
/**
|
||
* R25 页级断言统一走 DisplayStatement(递减棘轮,见 RAW_STATEMENT_CEILING)。
|
||
* 只改表达方式,不改尺寸:6xl 在 1024 起 ≈81px,已对齐对标 80px 档。
|
||
*/
|
||
const RAW_STATEMENT_RE = /\btext-(?:6xl|7xl)\b/g;
|
||
const rawStatementHits = compEntries.map(([rel]) => {
|
||
const live = (files.get(rel) ?? "")
|
||
.split("\n")
|
||
.filter((line) => !/^\s*(\/\/|\*|\/\*)/.test(line))
|
||
.join("\n");
|
||
return { rel, n: (live.match(RAW_STATEMENT_RE) ?? []).length };
|
||
});
|
||
const rawTotal = rawStatementHits.reduce((n, x) => n + x.n, 0);
|
||
const rawCeiling = opts.rawStatementCeiling ?? RAW_STATEMENT_CEILING;
|
||
rule({
|
||
id: "R25",
|
||
name: "目标页页级断言不走裸 text-6xl/7xl(改 DisplayStatement)",
|
||
denominator: Math.max(rawTotal, 1),
|
||
red: rawTotal > rawCeiling
|
||
? [`裸写高档字阶 ${rawTotal} 处 > 上限 ${rawCeiling}(${rawStatementHits.filter((x) => x.n > 0).map((x) => `${x.rel.split("/").pop()}:${x.n}`).join(", ")})`]
|
||
: [],
|
||
note: `裸写 ${rawTotal} 处 · 上限 ${rawCeiling}(次数口径,新增第 ${rawCeiling + 1} 处即判红)${rawTotal < rawCeiling ? " ⇒ 请把上限下调到实测值" : ""}`,
|
||
});
|
||
|
||
|
||
/**
|
||
* R26 首屏抽象数据场契约 —— ADR-0016 §17.5 分镜判据的**机器可判部分**
|
||
* (机房场景撤回后随继任者重建;判据同 §10.5)。
|
||
*
|
||
* 为什么必须有这条:例外条款如果只写在 CONTEXT 里,就是把「首屏可以循环」交给下一个人
|
||
* 自觉。`check:motion` 只扫 CSS 时长字面量与贝塞尔曲线,**WebGL 的 rAF 完全在它视野外**
|
||
* (实测:加完 43s 分镜后 `check:motion` 仍然 0 违规 —— 不是它放行,是它看不见)。
|
||
*
|
||
* 只判四条里能静态判的三条 + 一条硬禁:
|
||
* ① 周期落在 [20s, 60s](解析 `ms:` 与 `DIP_MS`);
|
||
* ② 必须尊重 `prefers-reduced-motion`(定格);
|
||
* ③ 必须离屏/后台即停(`IntersectionObserver` + `visibilitychange` 两者都要);
|
||
* ④ 禁止 `autoRotate`(自转 = 同一动画重复播放,例外条款明禁)。
|
||
* 「不得脉冲式重复」没有静态形态可判,交由人工评审 —— note 里写明,不假装自动。
|
||
*
|
||
* 文件不存在时**不判红**(与 R22 缺页判红相反):场景是可选特性,未启用就是 E 案,
|
||
* 缺席不是违规。但一旦存在,就必须满足上述四条 —— 否则等于开了口子没人守。
|
||
*/
|
||
const heroFieldSrc = files.get(HERO_FIELD_FILE);
|
||
const r26Red = [];
|
||
let cycleMs = 0;
|
||
let shotCount = 0;
|
||
if (heroFieldSrc) {
|
||
const live = stripComments(heroFieldSrc, { line: true });
|
||
const shotMs = [...live.matchAll(/\bms:\s*(\d+)/g)].map((m) => Number(m[1]));
|
||
const dipMatch = live.match(/DIP_MS\s*=\s*(\d+)/);
|
||
const dipMs = dipMatch ? Number(dipMatch[1]) : 0;
|
||
shotCount = shotMs.length;
|
||
cycleMs = shotMs.reduce((a, b) => a + b, 0) + dipMs * Math.max(shotCount, 1);
|
||
|
||
if (shotCount === 0) {
|
||
r26Red.push(`${HERO_FIELD_FILE}:解析不到任何 \`ms:\` 拍次时长 —— 结构已变,本条对本文件空转(请同步改判据)`);
|
||
} else if (cycleMs > HERO_CYCLE_CEILING) {
|
||
r26Red.push(`分镜一轮 ${cycleMs}ms > 上限 ${HERO_CYCLE_CEILING}ms(${shotCount} 拍)—— 例外条款只允许「环境级」编排`);
|
||
} else if (cycleMs < HERO_CYCLE_FLOOR) {
|
||
r26Red.push(`分镜一轮 ${cycleMs}ms < 下限 ${HERO_CYCLE_FLOOR}ms(${shotCount} 拍)—— 过短即成脉冲式重复`);
|
||
}
|
||
if (!/prefers-reduced-motion/.test(live)) {
|
||
r26Red.push("未尊重 prefers-reduced-motion —— 例外条款要求静态定格,不能强制所有人看运镜");
|
||
}
|
||
if (!/IntersectionObserver/.test(live) || !/visibilitychange/.test(live)) {
|
||
r26Red.push("缺少离屏/后台停渲染(需同时有 IntersectionObserver 与 visibilitychange)—— 否则滚走之后仍在烧 GPU");
|
||
}
|
||
if (/autoRotate/.test(live)) {
|
||
r26Red.push("出现 autoRotate —— 自转属「同一动画重复播放」,例外条款明禁");
|
||
}
|
||
}
|
||
rule({
|
||
id: "R26",
|
||
name: "首屏抽象数据场契约(周期 / 定格 / 离屏停 / 禁自转)",
|
||
denominator: heroFieldSrc ? 1 : 0,
|
||
red: r26Red,
|
||
note: heroFieldSrc
|
||
? `周期 ${cycleMs}ms(${shotCount} 拍)· 区间 [${HERO_CYCLE_FLOOR}, ${HERO_CYCLE_CEILING}]ms · 「不得脉冲式重复」无静态形态,由人工评审兜`
|
||
: "场景组件未启用(E 案)—— 本条不适用",
|
||
});
|
||
|
||
return results;
|
||
}
|
||
|
||
// ---- 自证(负例):喂一批明知违规的样本,不判红就宣布上面全部不作数 ----
|
||
function selftest() {
|
||
const bad = `:root {\n --radius-xs: 3px;\n --radius-sm: 6px;\n --radius-full: 0px;\n --shadow-brand: 0 6px 24px rgba(196,30,58,.22);\n --badge-radius: var(--radius-full);\n}\n.bain-card:hover { transform: translateY(-4px); }\n/* R21 的「已定义」一侧:夹具里必须真实存在一个自定义类名,否则只会测到"全判红" */\n.container-x { max-width: 1360px; }\n`;
|
||
|
||
// R26 三向自证夹具:①周期超标 ②合规基线 ③缺 reduced-motion。
|
||
// 三份都刻意不含 className / 高档字阶,避免污染 R1–R25 的读数(夹具互相串味是这仓踩过的坑)。
|
||
const fieldDirty = `const ACTS = [{ ms: 40000 }, { ms: 40000 }];\nconst DIP_MS = 420;\nconst prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;\nnew IntersectionObserver(() => {});\ndocument.addEventListener('visibilitychange', () => {});\n`;
|
||
const fieldClean = `const ACTS = [{ ms: 16000 }, { ms: 13000 }, { ms: 13000 }];\nconst DIP_MS = 420;\nconst prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;\nnew IntersectionObserver(() => {});\ndocument.addEventListener('visibilitychange', () => {});\n`;
|
||
const fieldNoReduced = fieldClean.replace("prefers-reduced-motion", "no-such-motion-query");
|
||
|
||
const files = new Map([
|
||
[HERO_FIELD_FILE, fieldDirty],
|
||
|
||
["src/app/globals.css", bad],
|
||
["src/components/ui/cta-button.tsx", 'className="rounded-full"'],
|
||
// R9 双向都要被抓到:文字档仍是胶囊 **且** icon 档被方角化
|
||
["src/components/ui/button.tsx", "shadow-brand\n size: {\n sm: 'h-9 rounded-full px-3',\n default: 'h-11 rounded-full px-5',\n lg: 'h-12 rounded-cta px-6',\n xl: 'h-14 rounded-cta px-8',\n icon: 'h-11 w-11 rounded-cta',\n },"],
|
||
["src/components/ui/badge.tsx", 'className="rounded-full"'],
|
||
["src/app/(marketing)/x.tsx", 'className="shadow-brand-hover"'],
|
||
// R21:自定义命名空间类名写了但 CSS 里没有定义(container-wide 那族的再现)
|
||
["src/app/error.tsx", 'className="container-wide container-x"'],
|
||
// R23/R25 的负例:**必须是仍在登记表里的页面**,否则两条都抓不到(2026-12-01 踩过:
|
||
// /products 退出登记后,负例还留在它身上,自证直接报「R25 未被抓到」)。
|
||
["src/app/(marketing)/news/news-content-v3.tsx", 'className="text-6xl font-bold"'],
|
||
// R24 的负例:白名单外的文件用了滚动驱动 API
|
||
["src/components/sections/rogue-stage.tsx", "const { scrollYProgress } = useScroll({ target: ref });"],
|
||
]);
|
||
// 第三参数是 tailwind.config 文本:给一份「引用全部已声明、且带齐外部所有者豁免」的,
|
||
// 避免 R11 的红因混进 R1–R9 的读数里(R11 有自己的两侧自证,见下)。
|
||
const RADIX_REF = `keyframes: { refs: { ${EXTERNAL_OWNED.map((v) => `x: 'var(${v})'`).join(", ")} } }`;
|
||
// 第四参数把两条棘轮上限压到 0:棘轮默认值等于「当前实测未达数」,
|
||
// 夹具里不足 9 页,用默认值会正好落在「等于上限 ⇒ 不判红」,测到的就是恒真。
|
||
const r = checkGrammar(bad, files, `${RADIX_REF}\nboxShadow: { brand: 'var(--shadow-brand)' }`, {
|
||
compositionUnmetCeiling: 0,
|
||
rawStatementCeiling: 0,
|
||
});
|
||
const redIds = r.filter((x) => x.red.length > 0).map((x) => x.id);
|
||
// R21 在同一个夹具里:`container-wide` 必须判红,而同行的 `container-x`
|
||
// (CSS 夹具里确实定义了 .container-x)不得被牵连 —— 否则闸会逼人删掉正确的类名。
|
||
const expect = ["R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R21", "R23", "R24", "R25", "R26"];
|
||
const missing = expect.filter((id) => !redIds.includes(id));
|
||
console.log("自证(负例必须全部被抓红):");
|
||
console.log(` 被抓红 ${redIds.join(",") || "(无)"}`);
|
||
if (missing.length) {
|
||
console.log(` ✗ 未被抓到:${missing.join(",")} ⇒ 这些规则没有约束力,上面所有绿灯都不作数`);
|
||
return 1;
|
||
}
|
||
console.log(` ✓ ${expect.length}/${expect.length} 条规则对已知违规均判红`);
|
||
|
||
// R21 双侧:只验"抓到未定义"会漏掉「把所有自定义类名一律报错」那种坏判据。
|
||
const r21Red = r.find((x) => x.id === "R21").red;
|
||
const r21CatchesUndefined = r21Red.some((m) => m.includes("container-wide"));
|
||
const r21IgnoresDefined = !r21Red.some((m) => m.includes("container-x"));
|
||
if (!r21CatchesUndefined || !r21IgnoresDefined) {
|
||
console.log(
|
||
` ✗ R21 双侧:未定义未抓到 ${!r21CatchesUndefined}、已定义被误报 ${!r21IgnoresDefined} ⇒ 该闸不可用`,
|
||
);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R21 双侧:未定义的自定义类名判红、已定义的不误报");
|
||
|
||
// R11 单独两侧自证:僵尸令牌 = tailwind 引用了 CSS 没声明的变量。
|
||
// 夹具里 --shadow-glow 未声明、--shadow-brand 已声明,所以必须只抓前者;
|
||
// 若判据恒绿(抓不到)或恒红(连已声明的也报),都算仪器坏。
|
||
// 注意每个夹具都要带上 --radix-accordion-content-height:它是登记在案的外部所有者豁免,
|
||
// 不带就会额外触发「豁免腐化」那条红,把「已声明引用不误报」这一维的读数污染掉。
|
||
// (第一版正是踩在这里:把夹具写错读成了判据坏。)
|
||
const r11RedIds = (tw) => checkGrammar(bad, new Map(), `${RADIX_REF}\n${tw}`).find((x) => x.id === "R11").red;
|
||
const r11Caught = r11RedIds("boxShadow: { brand: 'var(--shadow-brand)', glow: 'var(--shadow-glow)' }");
|
||
const r11Clean = r11RedIds("boxShadow: { brand: 'var(--shadow-brand)' }");
|
||
const r11HitsGlow = r11Caught.some((m) => m.includes("--shadow-glow"));
|
||
const r11IgnoresDeclared = r11Clean.length === 0 && !r11Caught.some((m) => m.includes("--shadow-brand"));
|
||
if (!r11HitsGlow || !r11IgnoresDeclared) {
|
||
console.log(` ✗ R11 不自证:未声明的 --shadow-glow 抓到 ${r11HitsGlow}、已声明的不误报 ${r11IgnoresDeclared} ⇒ 上面所有绿灯不作数`);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R11 双向:未声明引用判红、已声明引用不误报");
|
||
|
||
/**
|
||
* R26 三向自证:超标周期判红 / 合规基线不误报 / 缺 reduced-motion 判红。
|
||
* 第二向是防「一律报红」的坏判据,第三向是防「只认周期、其余三条形同虚设」。
|
||
*/
|
||
const r26RedFor = (src) =>
|
||
checkGrammar(bad, new Map([[HERO_FIELD_FILE, src]]), RADIX_REF, {
|
||
compositionUnmetCeiling: 0,
|
||
rawStatementCeiling: 0,
|
||
}).find((x) => x.id === "R26").red;
|
||
const r26TooLong = r26RedFor(fieldDirty);
|
||
const r26Clean = r26RedFor(fieldClean);
|
||
const r26NoReduced = r26RedFor(fieldNoReduced);
|
||
const r26CatchesPeriod = r26TooLong.some((m) => m.includes("上限"));
|
||
const r26PassesClean = r26Clean.length === 0;
|
||
const r26CatchesReduced = r26NoReduced.some((m) => m.includes("prefers-reduced-motion"));
|
||
if (!r26CatchesPeriod || !r26PassesClean || !r26CatchesReduced) {
|
||
console.log(
|
||
` ✗ R26 三向不自证:超标周期抓到 ${r26CatchesPeriod}、合规基线误报 ${!r26PassesClean}、缺定格抓到 ${r26CatchesReduced} ⇒ 例外条款等于没有守卫`,
|
||
);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R26 三向:超标周期判红、合规基线不误报、缺 prefers-reduced-motion 判红");
|
||
|
||
/**
|
||
* R22 双向自证:六页都带原语 ⇒ 不判红;抽掉任意一页 ⇒ **恰好**判那一页。
|
||
* 第三维单独测「注释掉的 <HeroPlate> 不算数」—— 这是本仓踩过的同一类坑
|
||
* (`constants.ts` 注释里的示例 import 曾骗过再导出正则)。
|
||
*/
|
||
// ── R22 登记制自证(2026-12-02 第四态:生产登记表已归零)──
|
||
// 六向:未登记载体判红 / 登记页通过 / 表过期判红 / 未批准载体判红 / 注释不算数 / 缺页判红。
|
||
// ⚠ 生产登记表现在是**空表**(首屏零视觉层)。若夹具从生产表里取条目,表一空自证就崩 ——
|
||
// 所以这里注入一张夹具表,测的是「登记机制」而不是「当前登记了什么」。
|
||
const REG_REL = HUB_HERO_FILES[0];
|
||
const FIXTURE_REG = new Map([
|
||
[REG_REL, { markers: ["HeroPlate"], origin: "fixture", poster: "/_fixture-poster.webp" }],
|
||
]);
|
||
const REG_APPROVED = `export function Hero(){ return (<div><${FIXTURE_REG.get(REG_REL).markers[0]} /></div>); }`;
|
||
const hubDirty = 'export function Hero(){ return (<div><HeroPlate variant="facade" /></div>); }';
|
||
const hubCanvas = 'export function Hero(){ return (<div><canvas /></div>); }';
|
||
const hubClean = 'export function Hero(){ return (<div className="text-6xl">纯排版首屏</div>); }';
|
||
// 非登记页一律用 hubClean;登记页用带批准载体的版本,否则「表过期」会污染其它维度。
|
||
const cleanMap = (override) => {
|
||
const rel = HUB_HERO_FILES.find((r) => r !== REG_REL);
|
||
return new Map(
|
||
HUB_HERO_FILES.map((r) => [r, r === REG_REL ? REG_APPROVED : override && r === rel ? override : hubClean]),
|
||
);
|
||
};
|
||
const r22RedFor = (map, opts) =>
|
||
checkGrammar(bad, map, "", {
|
||
floor: 0,
|
||
visualRegistry: FIXTURE_REG,
|
||
posterExists: () => true,
|
||
...opts,
|
||
}).find((x) => x.id === "R22").red;
|
||
const r22Clean = r22RedFor(cleanMap(), { hubFloor: 0 });
|
||
const r22Plate = r22RedFor(cleanMap(hubDirty), { hubFloor: 0 });
|
||
const r22Canvas = r22RedFor(cleanMap(hubCanvas), { hubFloor: 0 });
|
||
// 表过期:登记页只剩纯排版,批准载体没了
|
||
const r22Stale = r22RedFor(
|
||
new Map(HUB_HERO_FILES.map((r) => [r, hubClean])),
|
||
{ hubFloor: 0 },
|
||
);
|
||
// 未批准载体:登记页里出现 <Image>(夹具表只批准了 HeroPlate)
|
||
const r22Unapproved = r22RedFor(
|
||
new Map(HUB_HERO_FILES.map((r) => [r, r === REG_REL ? `${REG_APPROVED}<Image src="/x.webp" alt="" />` : hubClean])),
|
||
{ hubFloor: 0 },
|
||
);
|
||
const r22Commented = r22RedFor(
|
||
new Map(HUB_HERO_FILES.map((r) => [r, r === REG_REL ? REG_APPROVED : hubClean])),
|
||
{ hubFloor: 0 },
|
||
);
|
||
const half = Math.floor(HUB_HERO_FILES.length / 2);
|
||
// 只给一半页:登记页仍须带上批准载体,否则「表过期」的红会盖掉「缺页」的红,
|
||
// 这一维就测不到分母缩水(第一版正是踩在这里)。
|
||
const r22Short = r22RedFor(
|
||
new Map(HUB_HERO_FILES.slice(0, half).map((r) => [r, r === REG_REL ? REG_APPROVED : hubClean])),
|
||
{ hubFloor: HUB_HERO_FILES.length },
|
||
);
|
||
const r22Catches = r22Plate.length === 1 && r22Plate[0].includes("HeroPlate");
|
||
const r22CatchesCanvas = r22Canvas.length === 1 && r22Canvas[0].includes("canvas");
|
||
const r22Ignores = r22Clean.length === 0;
|
||
const r22StaleCaught = r22Stale.length === 1 && r22Stale[0].includes("登记表过期");
|
||
const r22CatchesUnapproved = r22Unapproved.length === 1 && r22Unapproved[0].includes("<Image>");
|
||
const r22StripsComments = r22Commented.length === 0;
|
||
const r22Floor = r22Short.length === 1 && r22Short[0].includes(`${half}/${HUB_HERO_FILES.length}`);
|
||
if (!r22Catches || !r22CatchesCanvas || !r22Ignores || !r22StaleCaught || !r22CatchesUnapproved || !r22StripsComments || !r22Floor) {
|
||
console.log(
|
||
` ✗ R22 不自证:未登记影像 ${r22Catches}、未登记 canvas ${r22CatchesCanvas}、登记页通过 ${r22Ignores}、` +
|
||
`表过期 ${r22StaleCaught}、未批准载体 ${r22CatchesUnapproved}、注释不算数 ${r22StripsComments}、缺页 ${r22Floor} ⇒ 这条闸没有约束力`,
|
||
);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R22 七向:未登记影像/canvas 判红、登记页不误报、表过期判红、未批准载体判红、注释不算数、缺页判红");
|
||
/**
|
||
* 第六向:首页那种「首屏区块内禁影像、区块外允许内容图」的分支必须双向都测。
|
||
* 只测「区块内有图 → 判红」的话,一条「见 Image 就报」的坏判据也能过;
|
||
* 只测「区块外有图 → 不报」的话,判据可能已经不再扫首屏。
|
||
*/
|
||
const HOME_REL = HUB_HERO_FILES[0];
|
||
const homeWithCover = `<section data-testid="hero-section"><HeroPlate /><h1>好</h1></section><section><Image src="/cover.webp" alt="" /></section>`;
|
||
const homeWithHeroImg = `<section data-testid="hero-section"><HeroPlate /><Image src="/x.webp" alt="" /><h1>差</h1></section><section><Image src="/cover.webp" alt="" /></section>`;
|
||
const r22Cover = r22RedFor(new Map([[HOME_REL, homeWithCover]]), { hubFloor: 0, floor: 0 });
|
||
const r22HeroImg = r22RedFor(new Map([[HOME_REL, homeWithHeroImg]]), { hubFloor: 0, floor: 0 });
|
||
const r22ScopeOk = r22Cover.length === 0 && r22HeroImg.length === 1 && r22HeroImg[0].includes(HOME_REL);
|
||
if (!r22ScopeOk) {
|
||
console.log(
|
||
` ✗ R22 区块范围不自证:首屏外的内容图被误报 ${r22Cover.length}(应 0)、首屏内的影像漏报 ${r22HeroImg.length}(应 1)⇒ 这条闸的分支不可信`,
|
||
);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R22 六向:首页分支「首屏内判红、首屏外内容图不误报」双向成立");
|
||
|
||
// R10 单独两侧自证:它是存量棘轮,判据是「数量 > 上限」,所以负例要按数量构造。
|
||
// 用真实 globals.css 做底,避免其它规则的红因混进来干扰这一维的读数。
|
||
const cssText = existsSync(CSS) ? readFileSync(CSS, "utf8") : ":root { --radius-xs: 0px; }";
|
||
const liftCountAt = (n) =>
|
||
checkGrammar(cssText, new Map([
|
||
["src/app/(marketing)/lift.tsx", `<div className="${"hover:-translate-y-1 ".repeat(n)}" />`],
|
||
])).find((x) => x.id === "R10").red.length;
|
||
const atCeiling = liftCountAt(HOVER_LIFT_CEILING);
|
||
const overCeiling = liftCountAt(HOVER_LIFT_CEILING + 1);
|
||
if (atCeiling !== 0 || overCeiling === 0) {
|
||
console.log(` ✗ R10 棘轮不自证:上限处判红 ${atCeiling}(应 0)、上限+1 判红 ${overCeiling}(应 >0)⇒ 上面所有绿灯不作数`);
|
||
return 1;
|
||
}
|
||
console.log(` ✓ R10 棘轮双向:${HOVER_LIFT_CEILING} 处不判红、${HOVER_LIFT_CEILING + 1} 处判红`);
|
||
/**
|
||
* R13–R17 的两侧自证。两个维度都要测,缺一个就是半个假绿:
|
||
* ① 内容维:同一份违规内容,落在**营销面路径**必须判红、落在 `src/components/ui/**`
|
||
* 必须不判红 —— 否则要么判据恒绿(抓不到),要么判据越界(会把 R2 保护的
|
||
* 功能性圆一起方角化,那正是 ADR-0008 记名的自伤)。
|
||
* ② 数量维:它们和 R10 一样是存量棘轮,判据是「命中数 > 上限」,
|
||
* 所以负例要按数量构造 —— 上限处不判红、上限+1 判红。
|
||
* 夹具一律带 `opts.floor = 0`:合成样本只有一两个文件,
|
||
* 不关掉地板就会把「扫描面太小」的红混进这一维,读数不再单义。
|
||
*/
|
||
const dirty = `<div className="rounded-full rounded-2xl hover:-translate-y-1 hover:shadow-lg shadow-xl bg-brand-soft bg-brand-section font-black font-extrabold" style={{ backgroundImage: 'url(tile_hatching.svg)', transform: 'rotate(140deg)', background: "var(--color-brand)" }}><path d="M22 14.204v-3.948" /></div>`;
|
||
const inScope = (rel) => new Map([[rel, dirty]]);
|
||
const hitRed = (rel, id, ceiling) =>
|
||
checkGrammar(cssText, inScope(rel), "", { floor: 0, hitCeilings: { [id]: ceiling } })
|
||
.find((x) => x.id === id).red.length;
|
||
const scopeIds = ["R13", "R14", "R15", "R16", "R17", "R18", "R19"];
|
||
const scopeBad = scopeIds.filter(
|
||
(id) => hitRed("src/app/(marketing)/x.tsx", id, 0) === 0);
|
||
const scopeOver = scopeIds.filter(
|
||
(id) => hitRed("src/components/ui/x.tsx", id, 0) > 0);
|
||
if (scopeBad.length || scopeOver.length) {
|
||
console.log(` ✗ R13–R19 扫描面不自证:营销面漏抓 ${scopeBad.join(",") || "无"}、越界误报 ${scopeOver.join(",") || "无"} ⇒ 上面所有绿灯不作数`);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R13–R19 双向:营销面已知违规全判红、ui/ 同名内容不误报(R2 的功能圆与三件原语未被牵连)");
|
||
|
||
// 数量维:上限处不判红 / 上限+1 判红(同 R10 的构造法)。
|
||
// 只关地板、**不覆盖上限** —— 第一版在这里塞了 hitCeilings:{[id]:9999},
|
||
// 于是两个情景都恒不判红、棘轮自证永远失败。用登记上限本身才是测那条规则。
|
||
const HIT_FIXTURE = {
|
||
R13: "rounded-full", R14: "hover:-translate-y-1", R15: "shadow-lg",
|
||
R16: "bg-brand-soft", R17: "font-black", R18: "tile_hatching", R19: "font-extrabold",
|
||
};
|
||
const ratchetBad = [];
|
||
for (const [id, ceiling] of Object.entries(MARKETING_HIT_CEILINGS)) {
|
||
const fixture = HIT_FIXTURE[id];
|
||
const at = (n) => checkGrammar(cssText, new Map([
|
||
["src/app/(marketing)/n.tsx", `<div className="${`${fixture} `.repeat(n)}" />`],
|
||
]), "", { floor: 0 }).find((x) => x.id === id).red.length;
|
||
if (at(ceiling) !== 0 || at(ceiling + 1) === 0) ratchetBad.push(`${id}@${ceiling}/${ceiling + 1}`);
|
||
}
|
||
if (ratchetBad.length) {
|
||
console.log(` ✗ R13–R19 棘轮不自证:${ratchetBad.join(" ")} 处「上限不判红/上限+1 判红」不成立 ⇒ 上面所有绿灯不作数`);
|
||
return 1;
|
||
}
|
||
console.log(` ✓ R13–R19 棘轮双向:按 ${Object.entries(MARKETING_HIT_CEILINGS).map(([k, v]) => `${k}=${v}`).join(" ")} 各自成立`);
|
||
|
||
/**
|
||
* R12 两侧自证:对账表必须**既能抓到漂移、又不在等值时误报**。
|
||
* 只测抓漂移那一侧的话,一条「见 css 就报」的坏判据也能拿满分。
|
||
*/
|
||
const aspectFix = (pairs) => `:root {\n${pairs.map(([k, v]) => ` --aspect-${k}: ${v};`).join("\n")}\n}`;
|
||
/**
|
||
* JS 夹具的键必须**从 ASPECT_MEASURED 派生**,不能手抄。
|
||
* 2026-12-01 新增 `portrait` 令牌时这里仍写死四个键(HERO_WIDE/EDITORIAL/SQUARE/TILE),
|
||
* 于是「两侧等值」那一维把「JS 侧缺 portrait」当成漂移报红 —— 自证恒红,
|
||
* 而 R12 真判据其实是对的。夹具手抄真源 = 一种假红,和被它守护的假绿同样有害。
|
||
*/
|
||
const jsFix = (vals) =>
|
||
`export const IMAGE_RATIOS = { ${Object.keys(ASPECT_MEASURED)
|
||
.map((k, i) => `${k.toUpperCase().replace(/-/g, "_")}: ${vals[i]}`)
|
||
.join(", ")} } as const;`;
|
||
const measuredArr = Object.values(ASPECT_MEASURED);
|
||
const drifted = [...measuredArr]; drifted[0] = "9.99";
|
||
const r12RedFor = (cssPairs, jsVals) =>
|
||
checkGrammar(aspectFix(cssPairs), new Map(), "", { jsSources: { [IMAGE_RATIOS_TS]: jsFix(jsVals) } })
|
||
.find((x) => x.id === "R12").red.length;
|
||
const r12Catches = r12RedFor(Object.entries(ASPECT_MEASURED).map(([k, v]) => [k, v === measuredArr[0] ? "9.99" : v]), drifted) > 0;
|
||
const r12IgnoresEqual = r12RedFor(Object.entries(ASPECT_MEASURED), measuredArr) === 0;
|
||
const r12CatchesMissing = checkGrammar(aspectFix([]), new Map(), "", { jsSources: { [IMAGE_RATIOS_TS]: jsFix(measuredArr) } })
|
||
.find((x) => x.id === "R12").red.length > 0;
|
||
if (!r12Catches || !r12IgnoresEqual || !r12CatchesMissing) {
|
||
console.log(` ✗ R12 不自证:漂移抓到 ${r12Catches}、等值不误报 ${r12IgnoresEqual}、缺一侧抓到 ${r12CatchesMissing} ⇒ 上面所有绿灯不作数`);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R12 三向:值漂移判红、两侧等值不误报、任一侧缺失判红");
|
||
|
||
/**
|
||
* R20 两侧自证。这条判据的形状与其它规则不同:它数的是**所有裸 alpha**,
|
||
* 其中绝大多数合法 —— 所以只验「抓到违规」会漏掉「把所有合法值也一律报错」那种坏判据,
|
||
* 且只验「合法不报」会漏掉「根本没扫描」。两侧都要:
|
||
* ① 内容维:scale 内的值(/95、/45、/25、/80)不判红;
|
||
* ② 内容维:scale 外的值(/92、/98、/62、/78)必须判红;
|
||
* ③ 形态维:任意值 alpha `/[0.92]` 不在射程内(它本来就合法,误报会逼人改掉正确写法)。
|
||
* 同时钉住**两次真实事故**的字符串:抽屉的 `bg-bg-primary/98` 与本次首屏的
|
||
* `bg-[#0B0A08]/92` —— 判据对这两条永不失敏。
|
||
*/
|
||
const alphaRedFor = (cls) =>
|
||
checkGrammar(cssText, new Map([["src/app/(marketing)/a.tsx", `<div className="${cls}" />`]]), "")
|
||
.find((x) => x.id === "R20").red.length;
|
||
const alphaOkClean = ["bg-bg-primary/95", "bg-white/10", "text-white/70", "from-[#0B0A08]/80 via-[#0B0A08]/45 to-[#0B0A08]/25", "border-brand/20"]
|
||
.every((c) => alphaRedFor(c) === 0);
|
||
const alphaIncidents = ["bg-bg-primary/98", "bg-[#0B0A08]/92", "from-[#0B0A08]/78", "via-[#0B0A08]/62"]
|
||
.map((c) => alphaRedFor(c) > 0);
|
||
const alphaArbitraryIgnored = alphaRedFor("bg-[#0B0A08]/[0.92]") === 0;
|
||
if (!alphaOkClean || alphaIncidents.includes(false) || !alphaArbitraryIgnored) {
|
||
console.log(
|
||
` ✗ R20 不自证:scale 内不误报 ${alphaOkClean}、两次事故均判红 ${alphaIncidents.join(",")}、` +
|
||
`任意值形态不误报 ${alphaArbitraryIgnored} ⇒ 上面所有绿灯不作数`,
|
||
);
|
||
return 1;
|
||
}
|
||
console.log(" ✓ R20 三向:scale 内不误报、scale 外(含 P0-2 与本次首屏两处真实事故)判红、任意值形态豁免");
|
||
|
||
// 地板守卫:扫描面塌陷(路径正则失配)必须可见,不能悄悄变成「五条规则全绿」
|
||
const floorRed = checkGrammar(cssText, new Map([["src/nowhere/x.tsx", dirty]]), "", { floor: 60 })
|
||
.find((x) => x.id === "R13").red.length;
|
||
if (floorRed === 0) {
|
||
console.log(" ✗ R13 地板守卫失效:营销面扫到 0 文件却不判红 —— 目录改名时这五条会集体空转");
|
||
return 1;
|
||
}
|
||
console.log(" ✓ 地板守卫:扫描面跌破下界即判红(防路径正则失配导致的集体假绿)");
|
||
|
||
return 0;
|
||
return 0;
|
||
}
|
||
|
||
function main() {
|
||
if (process.argv.includes("--selftest")) process.exit(selftest());
|
||
|
||
if (!existsSync(CSS)) { console.log(`未能度量:${CSS} 不存在`); process.exit(2); }
|
||
if (!existsSync(TW_CONFIG)) { console.log(`未能度量:${TW_CONFIG} 不存在 —— R11 没有引用方可查`); process.exit(2); }
|
||
const text = readFileSync(CSS, "utf8");
|
||
const twConfig = readFileSync(TW_CONFIG, "utf8");
|
||
const files = new Map();
|
||
for (const p of walk(path.join(ROOT, "src"))) files.set(path.relative(ROOT, p), readFileSync(p, "utf8"));
|
||
|
||
// R12 的第二侧:比例数字的 JS 真源。文件读不到时不静默跳过,
|
||
// 交 R12 报「缺一侧 = 判据失去目标」—— 静默跳过正是假绿的标准长相。
|
||
const jsSources = {};
|
||
for (const rel of [IMAGE_RATIOS_TS]) {
|
||
if (existsSync(path.join(ROOT, rel))) jsSources[rel] = readFileSync(path.join(ROOT, rel), "utf8");
|
||
}
|
||
|
||
const r = checkGrammar(text, files, twConfig, { jsSources });
|
||
const unmeasurable = r.filter((x) => x.denominator === 0 && x.id !== "R7" && x.id !== "R20" && !/^R1[3-9]$/.test(x.id));
|
||
const red = r.filter((x) => x.red.length > 0);
|
||
|
||
console.log("视觉语法对账(Bain 2026-08-31 快照 + Porsche live 实测语法)");
|
||
for (const x of r) console.log(` ${x.red.length ? "✗" : "✓"} ${x.id} ${x.name}|分母 ${x.denominator}|违规 ${x.red.length}${x.note ? `|${x.note}` : ""}`);
|
||
|
||
if (unmeasurable.length) {
|
||
console.log(`\n未能度量:${unmeasurable.map((x) => x.id).join(",")} 分母为 0 —— 判据没有目标,不算通过`);
|
||
process.exit(2);
|
||
}
|
||
for (const x of red) for (const m of x.red) console.log(" ✗ " + x.id + " " + m);
|
||
if (red.length) { console.log(`\n不成立:${red.length} 条规则违规`); process.exit(1); }
|
||
console.log(`\n成立:${r.length}/${r.length} 条语法判据通过`);
|
||
}
|
||
|
||
main();
|