Files
qiqi 968ff46a4c feat(tokens): M4-B2 浮层层级表 + 阴影四档(3.26.45)
用户能感知的只有一件事:弹窗/确认框里操作,成功提示现在看得见。

修一个「改 CSS 治不好」的层级 bug
- .iwb-toast 挂在 .iwb-overlay 内部,而 overlay 自带 z-index:100 + fixed,本身是堆叠上下文,
  里面的 toast 写多少都压不过 portal 到 body 的弹窗(300)。所以此前「弹窗里点保存没反应」是提示被盖住。
- 修法改为把 toast 也 portal 到 body,实测 elementFromPoint 命中 toast 本身而非遮罩。

层级表(14 档 --iwb-z-*)
- 数值只在 gen-tokens.js 写一次;浮层族(弹窗/全窗口/命令面板/右键/toast/锚定/确认框/崩溃屏)全改 token,
  裸 z-index 取值种类 42 → 31。
- 三条关系由测试钉死:ctx-menu < sheet < modal、toast > modal、sheet-menu 夹在 sheet 与 modal 之间。

阴影四档 + 圆角归一
- 新增 --iwb-elevation-1..4(贴面/菜单/命令面板/弹窗),浮层 8 种写法 → 4 档。
- .iwb-pop 圆角 18px 归到 radius-popover(14);--sh-* 引用归零,legacy 名标 @deprecated。

守卫与验收
- 新增 tests/overlay-layer-test.js(进 test:unit):层级表存在性、9 条顺序约束、禁裸 z-index、
  引用必须存在、toast 必须 portal。
- 12 张视觉基线 0 diff;verify:ci 全绿。
2026-11-23 15:33:29 +08:00

76 lines
4.7 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.
// 浮层层级守卫(M4-B2)
//
// 为什么要有这个测试:z-index 是「没有类型、没有报错、错了只在特定操作顺序下露馅」的那类东西。
// 迁移前 42 种裸值散在 2400 行 CSS 里,靠人肉比大小,出过两次真 bug:
// ① toast(200) < 弹窗(300) → 在弹窗/确认框里点「保存」,成功提示被盖住,用户以为没生效;
// ② 资源中心右键菜单(91) 被全窗口面板(260) 盖住 → 当时靠给这一个选择器打 270 补丁。
// 现在层级只在 src/design-tokens.css(生成产物)里定义一次,组件引名字。本测试钉三件事:
// 1. 浮层族**不许再写裸数字**(防止回潮,M5 的 token-lint 会扩到全仓);
// 2. 引用的 --iwb-z-* 必须真的定义过(拼错名字时 z-index 变成无效声明,静默退化为 auto);
// 3. 四条顺序关系成立(见下面 INVARIANTS)。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const ROOT = path.resolve(__dirname, '..')
const css = fs.readFileSync(path.join(ROOT, 'style.css'), 'utf8')
const tokens = fs.readFileSync(path.join(ROOT, 'src/design-tokens.css'), 'utf8')
// 层级表(生成产物里的 --iwb-z-*)
const z = {}
for (const m of tokens.matchAll(/(--iwb-z-[a-z-]+)\s*:\s*(\d+)\s*;/g)) z[m[1]] = Number(m[2])
assert.ok(Object.keys(z).length >= 10, '--iwb-z-* 层级表缺失或过短:' + Object.keys(z).join(', '))
// 1. 顺序关系。改数值前先想清楚这三条,测试只负责在你改错时喊停。
const INVARIANTS = [
['toast 必须高于弹窗(弹窗里点保存要能看到提示)', '--iwb-z-toast', '--iwb-z-modal'],
['弹窗必须高于全窗口面板', '--iwb-z-modal', '--iwb-z-sheet'],
['面板内 portal 菜单要高于面板本身(否则被自己的容器盖住)', '--iwb-z-sheet-menu', '--iwb-z-sheet'],
['面板内 portal 菜单不许越过弹窗(它是子菜单,不是新一层)', '--iwb-z-modal', '--iwb-z-sheet-menu'],
['右键菜单高于右键遮罩(同一次点击里成对出现)', '--iwb-z-ctx-menu', '--iwb-z-ctx'],
['右键菜单低于全窗口面板(面板开在菜单之上是正确方向)', '--iwb-z-sheet', '--iwb-z-ctx-menu'],
['确认框/崩溃屏在最上层', '--iwb-z-alert', '--iwb-z-anchor'],
['锚定浮层高于弹窗(外观面板挂在设置弹窗里)', '--iwb-z-anchor', '--iwb-z-modal'],
['启动页高于弹窗(启动阶段不该被任何浮层穿透)', '--iwb-z-splash', '--iwb-z-modal'],
]
for (const [why, higher, lower] of INVARIANTS) {
assert.ok(z[higher] != null, '未定义:' + higher)
assert.ok(z[lower] != null, '未定义:' + lower)
assert.ok(z[higher] > z[lower], `${why}:${higher}(${z[higher]}) 必须 > ${lower}(${z[lower]})`)
}
// 2. 浮层族的声明里不许出现裸数字 z-index。
// 只查这 16 个选择器(它们构成「谁盖谁」的全部边界);画布内的端口/手柄是局部堆叠,不在此列。
const OVERLAYS = [
'.iwb-modal-mask', '.iwb-fullmask', '.iwb-command-mask', '.iwb-command',
'.iwb-ctxmask', '.iwb-ctxmenu', '.iwb-toast', '.iwb-pop-anchor',
'.iwb-ws-more', '.iwb-splash', '.iwb-imgpreview', '.iwb-crash-screen',
'.iwb-confirm-overlay', '.iwb-bg-palette-host',
]
const lines = css.split('\n')
for (const sel of OVERLAYS) {
for (const line of lines) {
if (!line.startsWith(sel + ' ') && !line.startsWith(sel + '{')) continue
const m = line.match(/z-index:\s*(-?\d+)/)
assert.ok(!m, `${sel} 还在写裸 z-index: ${m && m[1]},请改用 --iwb-z-*(层级表在 design-tokens.css)`)
}
}
// 3. 引用的 z token 必须存在(拼错 → 声明无效 → 静默退化成 auto,最难查的一类)
for (const m of css.matchAll(/z-index:\s*var\((--iwb-z-[a-z-]+)\)/g)) {
assert.ok(z[m[1]] != null, '引用了不存在的层级 token:' + m[1])
}
// 4. toast 必须 portal 到 body —— 只改 CSS 数字治不好这条。
// `.iwb-overlay` 自己带 z-index(100),是一个**堆叠上下文**:挂它里面的 toast 无论写多高,
// 整个子树都被封在 100 这一层里,压不过 portal 到 body 的弹窗(300)。这正是历史 bug
// 「弹窗里点保存看不到成功提示」的真正成因(2026-11-23 实测:改数字无效,portal 才有效)。
const appSrc = fs.readFileSync(path.join(ROOT, 'app.js'), 'utf8')
assert.ok(
/ReactDOM\.createPortal\(el\('div', \{ className: 'iwb-toast/.test(appSrc),
'toast 必须 ReactDOM.createPortal 到 document.body:.iwb-overlay 是堆叠上下文,内联渲染的 toast 永远压不过弹窗'
)
console.log('overlay layer checks passed(层级表 ' + Object.keys(z).length + ' 档,' + INVARIANTS.length + ' 条顺序约束,toast portal 已钉)')