用户能感知的只有一件:设置页同一行里输入框 33px、按钮 24px 的 9px 落差没有了。 控件等高 - 新增 --iwb-control-h: 30px。输入框竖内边距 7→6(13px 字 + 6×2 + 2 描边 = 30), 默认按钮 24→30(align-items:center 自带居中)。 - 渠道卡片显式 height:auto —— 它是「卡片里的卡片」,固定高度会顶住上下分隔线。 - 不动全局 .iwb-input(28px):改它会让画布/停靠栏/节点里每个输入框都长 2px,不属于本批。 字号 - 设置页正文 14→13、标题 16→15(与同屏 section-title 同档);13.5×8→md、12.5×2→sm。 删 21 条死规则 - setcell(+hover/on/label)/setgrid/setopen/ratio-mini(-auto)/ratio-box/set-page-head(-headtext)/ set-row(两处定义,一 grid 一 flex)/set-row-*/pop-anchor .setcell/appear-val/appear-note-only 在 dist/app.js 与 plugins/** 里都是 0 次。 两条「写了但从未生效」的声明 - .iwb-set-nav-item 的 padding: 7px 9px 被 .iwb-settings-modal .iwb-tab(两个类)按 specificity 压掉,实测一直是 8/16 —— 改它毫无反应。同类:.iwb-appear-range 写两遍,前者 flex 被后者覆盖。 守卫(tests/settings-scope-test.js,进 test:unit) - 控件必须共用 control-h、范围内禁半像素字号、9 个死类名不许复现、引用的 token 必须存在。 - 最后一条是本批真踩到的:--iwb-radius-pill 拼错(真名 --iwb-radius-full)会让声明整条失效、 圆角静默变 0,亮色基线看不出来。 验收 - 计算样式 diff:设置页 16 个元素 + 外观 15 个元素,18 项变化全部预期,无「没打算改却被改」。 - 12 张视觉基线:只有设置弹窗亮/暗 2 张变化(已核对无裁切/溢出),其余 10 张 0 diff。 - 审计:字号写死 243→212、间距 548→483、圆角 139→128、style.css 2339→2314; 「引用了但从未定义」保持 0。verify:ci 全绿。
77 lines
4.6 KiB
JavaScript
77 lines
4.6 KiB
JavaScript
// 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')
|
||
|
||
// ── 2. 半像素字号在设置/外观范围内必须清零 ──
|
||
// 13.5px / 12.5px 这类值来自「凭手感调半像素」,闭集里没有它们;B4 范围内已全部并到 13/12。
|
||
// 范围外的(备份、右键菜单、插件市场卡)留给 B5/B6,这里不越界。
|
||
const SCOPE = /\.iwb-(settings-modal|appear|set|setcell|set-num|set-nav|set-page|set-row|set-main|setlabel|sethd|setalign|setx|sethint|seterr|setrow|setgrid|setopen)/
|
||
const halfPixel = []
|
||
css.split('\n').forEach((line, i) => {
|
||
const brace = line.indexOf('{')
|
||
if (brace < 0) return
|
||
if (!SCOPE.test(line.slice(0, brace))) return
|
||
if (/font-size:\s*[\d]+\.5px/.test(line)) halfPixel.push((i + 1) + ':' + line.trim().slice(0, 70))
|
||
})
|
||
assert.deepStrictEqual(halfPixel, [], '设置/外观范围内还有半像素字号')
|
||
|
||
// ── 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 引用全部有定义)')
|