Files
image-workbench-desktop/tests/node-scope-test.js
T
qiqi f4a5709e8b
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 37s
fix(tokens): 端口描边改由文字色派生(深色下与填充同色,边缘糊)
换完 --iwb-field 底色后放大 8 倍发现:深色下端口是一团糊的圆点,不是清晰的旋钮。
原因不是颜色不够亮,是描边用的 --iwb-border2 在深色下是 #4d4d4d,与填充 #494949 同色 ——
1.5px 描边等于不存在,12px 的小圆点只能靠 12 级填充差自我定义。

改为 color-mix(text 55%, transparent):亮 #828282 / 暗 #9e9e9e,
对填充各 4.6:1 / 3.4:1(非文字元素红线 3:1),两个主题同一档锐度。

node-scope-test 补一条断言:端口描边必须由 --iwb-text 派生,不许退回 --iwb-border2。
这条守的是「边缘锐度」而不是「颜色对不对」—— 后者截图能看出来,前者只有放大才看得见。
2026-11-23 16:31:40 +08:00

104 lines
5.1 KiB
JavaScript
Raw 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.
// B5 节点:三条不变量
//
// 这一批的病灶和 B3/B4 同源,但表现更狠:节点卡内部的控件沿用了「面板」的表面色
// (--iwb-layer / --iwb-layer2)。深色下这两个值是 #161616 / #1c1c1c,而节点卡是 #3d3d3d ——
// 端口就成了一颗嵌在卡片上的纯黑洞(差 39 级),任务卡里的等待按钮同理。
// 按 D10 的相对派生原则:**控件明暗由贴着的那张卡片决定**,节点卡内一律用 --iwb-field。
//
// 另一类:浮条底是 --iwb-panel,子项 hover 也用 --iwb-layer2,深色下两者都是 #1c1c1c,
// hover 完全没有反馈 —— 这类「改数字不生效」只能靠断言兜。
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')
// 按 } 切块,取每块选择器的最后一行(多选择器组只影响可读性,不影响 body)
const blocks = []
for (const chunk of css.split('}')) {
const i = chunk.lastIndexOf('{')
if (i < 0) continue
const sel = chunk.slice(0, i).split('\n').filter((l) => l.trim()).pop() || ''
blocks.push({ sel: sel.trim(), body: chunk.slice(i + 1) })
}
const NODE_SCOPE = /^\.iwb-(node|gen|port|relay|conn|lod|ref|resize|task|size)/
const nodeBlocks = blocks.filter((b) => NODE_SCOPE.test(b.sel))
// ── 1. 节点卡内部不许用「面板表面色」 ──
// 浮条例外:它是浮层(底就是 --iwb-panel),不贴在卡片上。
const PANEL_SURFACE = /background(?:-color)?:\s*var\(--iwb-(?:layer|layer2|panel)\)/
const offenders = nodeBlocks
.filter((b) => !/floatbar/.test(b.sel))
.filter((b) => PANEL_SURFACE.test(b.body))
.map((b) => b.sel)
assert.deepStrictEqual(
offenders,
[],
'节点卡内部的控件必须用 --iwb-field(深色下 layer/layer2 #161616/#1c1c1c 打在节点卡 #3d3d3d 上等于黑洞)'
)
// 端口是本批的「样板」:它的底色必须是 field,三个态都不能退回 layer/panel
const port = blocks.find((b) => b.sel === '.iwb-port')
assert.ok(port, '找不到 .iwb-port 规则')
assert.ok(port.body.includes('background: var(--iwb-field)'), '.iwb-port 底色必须是 --iwb-field')
// 描边必须由文字色派生:深色下 --iwb-border2 是 #4d4d4d,与填充 --iwb-field(#494949) 同色,
// 描边等于没有,12px 的小圆点会糊成一团。这条断言守的是「边缘锐度」而不只是「颜色对」。
assert.ok(
/border:\s*1\.5px solid color-mix\(in srgb, var\(--iwb-text\)/.test(port.body),
'.iwb-port 描边必须由 --iwb-text 派生(--iwb-border2 在深色下与填充同色,端口边缘会糊)'
)
for (const sel of ['.iwb-node:hover .iwb-port', '.iwb-port:hover', '.iwb-node-selected .iwb-port:not(.iwb-port-linked)']) {
const b = blocks.find((x) => x.sel === sel)
assert.ok(b, '找不到规则:' + sel)
assert.ok(
!/var\(--iwb-(?:layer|layer2|panel)\)/.test(b.body),
sel + ' 不能用面板表面色 —— 端口贴在节点卡上,深色下会变成黑洞'
)
}
// ── 2. 节点区字号必须走档位,不写死 ──
// 例外:8px / 10px 是微缩徽标(序号角标、图片计数),闭集最低档 11px 会把它们撑出圆点;
// 14px 是尺寸自定义输入(属于图像设置浮层,不在节点卡内)。
const MICRO = new Set(['8px', '10px', '14px'])
const bareFont = []
for (const b of nodeBlocks) {
for (const m of b.body.matchAll(/font-size:\s*([\d.]+px)/g)) {
if (!MICRO.has(m[1])) bareFont.push(b.sel + ' → ' + m[1])
}
}
assert.deepStrictEqual(bareFont, [], '节点区字号必须用 --iwb-font-*,不写死 px(微缩徽标 8/10px 除外)')
// ── 3. 节点区间距与圆角同样走档位 ──
// 例外:端口热区 inset 是负数(扩大点击区,不是节奏值);圆角只允许 token 或 50%/2px(圆形与占位条)
const bareSpace = []
for (const b of nodeBlocks) {
for (const m of b.body.matchAll(/(?:padding|margin|gap)(?:-(?:top|right|bottom|left))?:\s*([^;}]+)/g)) {
if (/(^|[\s(])\d+px/.test(m[1])) bareSpace.push(b.sel + ' → ' + m[0].trim())
}
}
assert.deepStrictEqual(bareSpace, [], '节点区间距必须用 --iwb-space-*,不写死 px')
const bareRadius = []
for (const b of nodeBlocks) {
for (const m of b.body.matchAll(/border-radius:\s*([\d.]+px)/g)) {
if (m[1] !== '2px') bareRadius.push(b.sel + ' → ' + m[1])
}
}
assert.deepStrictEqual(bareRadius, [], '节点区圆角必须用 --iwb-radius-*,不写死 px(2px 占位条除外)')
// ── 4. 已删除的死规则不许回来 ──
// 判据:dist/app.js 与 plugins/** 里都是 0 次(尺寸/质量行已并入图像设置浮层)。
const DEAD = [
'.iwb-gen-sizerow', '.iwb-gen-qualityrow', '.iwb-gen-tag',
'.iwb-size-x', '.iwb-size-align', '.iwb-size-badge',
]
for (const cls of DEAD) {
const re = new RegExp('\\' + cls + '(?![-A-Za-z0-9_])')
assert.ok(!re.test(css), cls + ' 已确认无生产者(DOM 与插件都不再产出),不该重新出现')
}
console.log('node scope checks passed(端口用 field / ' + nodeBlocks.length + ' 条节点规则字号·间距·圆角全走档位 / ' + DEAD.length + ' 个死类名不复现)')