Files
image-workbench-desktop/tests/node-scope-test.js
T
qiqi cb9cb9ceec feat(tokens): M4-B5 节点 —— 端口不再在深色下变成黑洞(3.26.48)
用户能感知的只有一件:深色画布上节点的连接端口看得见了。它以前是嵌在卡片上的黑洞。

端口在两个主题下往相反方向错
- 暗色:--iwb-layer(#161616) 打在节点卡(#3d3d3d) 上,差 39 级 → 改 --iwb-field(#494949),差 12 级。
- 亮色:#f5f5f5 打在 #efefef 上只靠 1.5px 描边撑着 → 改 #ffffff + 描边,白点清晰。
- 同一病灶在节点内还有 6 处一并改 field:ref-img / ref-single / ref-upload-link /
  refmini-empty / task-result-img / node-head:hover。

浮条 hover 在深色下没有反馈(改数字治不好)
- 浮条底 --iwb-panel 与子项 hover 的 --iwb-layer2 深色下同为 #1c1c1c —— 换成
  color-mix(text 10%, transparent)。任务卡「等待」按钮同理(它贴在 field 卡上)。

归并
- 字号:12→sm、15→lg、11→xs、13→md,全部等值;8/10px 微缩徽标保留(11 会撑破 12px 角标)。
- 圆角:8→control、6/5→chip、14→popover,只剩 50% 与 2px 占位条。
- 间距:52 处等值、13 处 1px 级微调;提示词节点体 14/18→12/16(节点高 −4px)。
- 阴影:浮条与节点选中/连接态的内联 rgba 走 elevation-2。
- 删 6 个死类名 / 6 条规则:gen-sizerow gen-qualityrow gen-tag size-x size-align size-badge。

守卫(tests/node-scope-test.js,进 test:unit)
- 节点卡内部禁 --iwb-layer/layer2/panel 作背景(浮条除外,它是浮层);端口三态底色断言;
  节点区字号/间距/圆角必须走档位;6 个死类名不复现。

验收
- 计算样式逐属性 diff:节点/标题带/端口/浮条/生图参数/任务卡,变化全部为预期项。
- 12 张基线变了 8 张(②④⑤⑥ × 亮暗,④⑤⑥ 的画布背后也有节点),逐张核对无裁切/重叠。
- 审计:字号写死 212→188、圆角 128→104、间距 483→416、style.css 2314→2307。verify:ci 全绿。
2026-11-23 16:27:40 +08:00

98 lines
4.7 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')
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 + ' 个死类名不复现)')