Files
qiqi c81a107b5f feat(tokens): M4-B6 收尾 —— 半像素清零 + 插件契约文件级豁免归零(3.26.49)
- style.css 剩余 16 处半像素字号并入闭集,删 2 条归并后重复的规则;守卫收紧为全文件断言
- 裁定 --iwb-control-h 不扩到全局控件(并排表单 vs 成组紧凑控件),新增「全局 input 不得写死 height」守卫
- plugin-theme-contract-test 重写:ALLOW_FILES 6 → 0,改为私有皮肤自声明(skin) + chroma 强调色判据 + 行内内容色标记;私有皮肤必须自洽(不引用宿主颜色 token)
- token-audit 插件段同口径分三类报数;插件侧中性色写死归零
- 插件仓同步 4 个版本:browser 1.7.1 / batch-export 1.2.1 / image-annotate 1.20.7 / image-vectorize 0.6.1
- 视觉基线 8 张更新(含画布场景的字号栅格化变化),A/B 回退确认非环境噪声,复核 12/12
2026-11-23 17:09:46 +08:00

84 lines
5.2 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.
// B4 设置/外观:三条不变量
//
// 这一批踩到的两类坑都不是「写错值」,而是「写了但不生效」「写了但没人用」:
// ① `.iwb-set-nav-item` 声明了 padding: 7px 9px,被 `.iwb-settings-modal .iwb-tab`(两个类)
// 按 specificity 盖掉,实测一直是 8/16 —— 改它毫无反应,只能靠采样计算样式发现;
// ② `.iwb-setcell` / `.iwb-set-row` 这类类名在样式表里躺着,DOM 早已不渲染(v3.22 与插件设置页改版)。
// 所以这里的断言不看「值对不对」,只看「这条声明还有没有意义」。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const root = path.join(__dirname, '..')
const css = fs.readFileSync(path.join(root, 'style.css'), 'utf8')
const tokens = fs.readFileSync(path.join(root, 'src/design-tokens.css'), 'utf8')
// ── 1. 控件高度:同一行里的输入框与默认按钮必须共用同一个 token ──
const m = tokens.match(/--iwb-control-h:\s*(\d+px)/)
assert.ok(m, '缺少 --iwb-control-h(表单控件高度)')
assert.strictEqual(m[1], '30px', '--iwb-control-h 应为 30px')
for (const sel of ['.iwb-settings-modal .iwb-input {', '.iwb-settings-modal .iwb-btn {']) {
const i = css.indexOf(sel)
assert.ok(i >= 0, '找不到规则:' + sel)
const body = css.slice(i, css.indexOf('}', i))
assert.ok(
body.includes('height: var(--iwb-control-h)'),
sel + ' 必须用 height: var(--iwb-control-h) —— 否则它旁边的控件会高低不齐(曾是 33 vs 24)'
)
}
// 渠道卡片是「卡片里的卡片」,允许按自身内边距算高,但必须显式 height: auto 而不是继承 30
const llm = css.indexOf('.iwb-settings-modal .iwb-llm-card .iwb-input {')
assert.ok(llm > 0, '找不到渠道卡片输入框规则')
assert.ok(css.slice(llm, css.indexOf('}', llm)).includes('height: auto'), '渠道卡片输入框应显式 height: auto')
// ── 1b. 全局 .iwb-input 保持「内容撑高」,不得写死 height ──
// B6 裁定 control-h 不扩到全局:画布/节点/停靠栏里的输入框是紧凑控件,强制 30px 会连带
// 拉高节点与面板行距。判据是「有没有并排的另一半」——并排的表单用 control-h,成组的紧凑控件靠内容撑高。
const gInput = css.indexOf('.iwb-input, .iwb-textarea {')
assert.ok(gInput > 0, '找不到全局 .iwb-input 规则')
assert.ok(
!/\bheight\s*:/.test(css.slice(gInput, css.indexOf('}', gInput))),
'全局 .iwb-input 不该写死 height —— 它服务的是画布里的紧凑控件,写死就会把节点撑高(并排场景请就地用 control-h)'
)
// ── 2. 半像素字号必须清零(B6 后是全文件) ──
// 13.5px / 12.5px 这类值来自「凭手感调半像素」,闭集里没有它们。
// B4 清了设置/外观范围内的 12 处;B6 把备份页、右键菜单、操作日志、确认框、插件市场卡
// 剩下的 16 处一并清完,所以断言从「范围内」收紧成「全文件」—— 以后新增的一律拦下。
const halfPixel = []
css.split('\n').forEach((line, i) => {
if (/font-size:\s*[\d]+\.5px/.test(line)) halfPixel.push((i + 1) + ':' + line.trim().slice(0, 70))
})
assert.deepStrictEqual(halfPixel, [], 'style.css 里还有半像素字号(闭集只有 11/12/13/15/17/20/24)')
// ── 3. 已删除的死规则不许回来 ──
// 判据:DOM 不渲染 + 插件不复用。删除前查过 dist/app.js 与 plugins/**(B3 的教训:只查产物会把插件契约误删)。
const DEAD = [
'.iwb-setcell', '.iwb-setgrid', '.iwb-setopen', '.iwb-ratio-mini', '.iwb-ratio-box',
'.iwb-set-row', '.iwb-set-page-head', '.iwb-appear-val', '.iwb-appear-note-only',
]
for (const cls of DEAD) {
const re = new RegExp('\\' + cls + '(?![-A-Za-z0-9_])')
assert.ok(!re.test(css), cls + ' 已确认无生产者(DOM 与插件都不再产出),不该重新出现')
}
// ── 4. 引用的 token 必须存在 ──
// `border-radius: var(--iwb-radius-pill)` 这种拼错不会报错、不会警告,声明整条失效,圆角静默变 0。
// 本批真踩到了:999px 的药丸圆角 token 叫 `--iwb-radius-full`,我写成了 `--iwb-radius-pill`,
// 亮色基线照样「看起来正常」(那几个胶囊不在基线视野里)。所以这条必须是断言,不能只靠审计脚本打印。
const defs = new Set([...tokens.matchAll(/(?:^|[\s;{])--[a-z0-9-]+\s*:/gim)]
.map((s) => s[0].trim().replace(/^[;{]/, '').trim().replace(/\s*:$/, '')))
for (const m2 of css.matchAll(/(?:^|[\s;{])--[a-z0-9-]+\s*:/gim)) {
defs.add(m2[0].trim().replace(/^[;{]/, '').trim().replace(/\s*:$/, ''))
}
// 运行时由 JS 写进 style 的变量(见 scripts/token-audit.js 的 RUNTIME_SET)
const RUNTIME = new Set(['--iwb-dock-l', '--iwb-dock-r', '--iwb-fb-k', '--iwb-node-color'])
const missing = [...new Set([...css.matchAll(/var\(\s*(--[a-z0-9-]+)/gi)].map((r) => r[1]))]
.filter((r) => !defs.has(r) && !RUNTIME.has(r))
assert.deepStrictEqual(missing, [], '引用了不存在的 token(声明会整条失效且没有报错)')
console.log('settings scope checks passed(控件等高 / 半像素清零 / ' + DEAD.length + ' 个死类名不复现 / ' + defs.size + ' 个 token 引用全部有定义)')