- style.css 插件面板两段六次叠加(1819-1885 / 2194-2295)合并成一份有意图的实现;133 行新增零裸值,净减 34 行,删 3 个死类与 1 条死兜底 - 新增 --iwb-font-base: 14px(8 档):全站 10 处标准正文原本在 13→15 之间无处安放;走 gen-tokens 单一源同步 CSS/DTCG/快照 - derive() 亮色状态色调深(ok #15803d / err #b91c1c / warn #b45309,暗色不变)—— --iwb-ok 原本对浅页面仅 2.13 却一直当文字色用 - theme-contrast-test 补 3 状态色 × 4 表面 × 2 主题,114 → 138 对 - 新增 ⑦⑧ 组件夹具基线(桌面端面板在网页 e2e 不可达),夹具内禁用 transition 消除 1 级灰度随机 diff;16 张连跑两次全绿 - batch-export 1.2.2 同步(内容寻址 + SRI):状态色走宿主 token,去掉纯蓝主按钮 - 棘轮基线首次下调:字号 159 / 圆角 95 / 间距 377 / hex 79 / 圆角种数 17 / 阴影 44 - 文档:规范 §5.7 接入案例、§3.3 第 8 档、修正 §5.2 里不存在的 --iwb-dur-* 引用;计划 M6 执行结果与度量看板
79 lines
4.5 KiB
JavaScript
79 lines
4.5 KiB
JavaScript
'use strict'
|
||
// 对比度回归守卫(M5-T5.4)
|
||
//
|
||
// 为什么需要它:暗色主题的对比度不是「写死一个值」就完了 —— derive() 用 mix + clampAgainst
|
||
// 现算,任何一次调色(把 panel 提亮、把 layer 压深、把文字权重从 .30 改成 .34)都可能让
|
||
// 某对「文字 × 表面」掉到阈值以下,而**肉眼在编辑器里看不出来**(唯一能看出来的用户会截图说
|
||
// 「这个字看不清」,但我们拿不到他的主题参数)。
|
||
//
|
||
// 阈值取 theme-tokens.js 的 RATIO(单一源,禁止在这里再写 4.5 / 7 这种魔数):
|
||
// text 7.0(AAA 正文)/ text2 4.5(AA 正文)/ dim 3.0(AA 大字下限)/ canvas 6.0(节点标题,预留 opacity .8)/ onBrand 4.5
|
||
// 计划里写的「text ≥4.5、tertiary ≥3.0、on-brand ≥4.5」是**下限**,实现取更严的 7.0/3.0/4.5。
|
||
//
|
||
// 亮暗两套主题都跑;DEFAULTS 之外的配色(用户在设置里改过的)不在本守卫范围 ——
|
||
// 那条路由 clampText 在运行时兜底。
|
||
const assert = require('assert')
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
const root = path.resolve(__dirname, '..')
|
||
const sandbox = {}
|
||
new Function('window', fs.readFileSync(path.join(root, 'src', 'theme-tokens.js'), 'utf8'))(sandbox)
|
||
const T = sandbox.IWBThemeTokens
|
||
assert.ok(T && typeof T.derive === 'function', 'theme-tokens.js 没暴露 IWBThemeTokens.derive')
|
||
|
||
// 承载文字的整套表面。canvas 单独处理:画布上只有节点标题,它用 canvasText(阈值 6,
|
||
// 且要预留 opacity .8 的余量)—— 界面文字本来就不该直接压在画布底上,混进通用集合会误报。
|
||
const SURFACES = ['bg', 'panel', 'layer', 'layer2', 'nodeBg', 'field', 'pluginSurface', 'pluginCard', 'pluginInset', 'pluginHover', 'hover', 'dockBg', 'chrome', 'inset']
|
||
|
||
const rows = []
|
||
function check (theme, fgName, fg, surfaces, min, label) {
|
||
for (const s of surfaces) {
|
||
const bg = theme[s]
|
||
if (!bg || !/^#[0-9a-f]{6}$/i.test(bg)) continue
|
||
const r = T.contrast(fg, bg)
|
||
rows.push({ name: fgName + ' × ' + s, ratio: r, min, label, ok: r + 1e-9 >= min })
|
||
}
|
||
}
|
||
|
||
for (const dark of [false, true]) {
|
||
const t = T.derive(T.DEFAULTS, dark)
|
||
const label = dark ? '暗色' : '亮色'
|
||
const present = SURFACES.filter((s) => t[s])
|
||
check(t, 'text', t.text, present, T.RATIO.text, label)
|
||
check(t, 'text2', t.text2, present, T.RATIO.text2, label)
|
||
check(t, 'textDim', t.textDim, present, T.RATIO.dim, label)
|
||
check(t, 'brandText', t.brandText, present, T.RATIO.text2, label)
|
||
check(t, 'canvasText', t.canvasText, ['canvasBg'], T.RATIO.canvas, label)
|
||
check(t, 'nodeText2', t.nodeText2, ['nodeBg', 'layer', 'panel'], T.RATIO.text2, label)
|
||
// M6 补漏:状态色(ok/err/warn)在 .iwb-status-ok / .iwb-ratio.ok / 插件标签里是**直接当文字色**
|
||
// 用的,M5 的 114 对只覆盖了 text/text2/dim/brandText,把它们漏了 —— 于是亮色 --iwb-ok
|
||
// 长期是 #22c55e(对浅页面 2.13)也一路绿灯。状态文字同样按 AA 正文要求 ≥4.5。
|
||
const STATUS_SURFACES = ['bg', 'panel', 'layer', 'layer2']
|
||
for (const k of ['ok', 'err', 'warn']) check(t, k, t[k], STATUS_SURFACES, T.RATIO.text2, label)
|
||
// 品牌底上的字:onBrand 是按对比度自动选的黑/白,选错了就会「主按钮白字压浅蓝」
|
||
rows.push({
|
||
name: 'onBrand × brand',
|
||
ratio: T.contrast(t.onBrand, t.brand),
|
||
min: T.RATIO.onBrand,
|
||
label,
|
||
ok: T.contrast(t.onBrand, t.brand) + 1e-9 >= T.RATIO.onBrand
|
||
})
|
||
}
|
||
|
||
const bad = rows.filter((r) => !r.ok)
|
||
if (bad.length) {
|
||
console.log('对比度不达标(阈值来自 theme-tokens.js 的 RATIO):')
|
||
for (const r of bad) console.log(' ✗ ' + r.label + ' ' + r.name.padEnd(26) + r.ratio.toFixed(2) + ' < ' + r.min)
|
||
console.log('\n最低的三对(含达标的):')
|
||
for (const r of rows.slice().sort((a, b) => a.ratio - b.ratio).slice(0, 3)) {
|
||
console.log(' · ' + r.label + ' ' + r.name.padEnd(26) + r.ratio.toFixed(2) + '(下限 ' + r.min + ')')
|
||
}
|
||
}
|
||
assert.deepStrictEqual(bad.map((r) => r.label + ' ' + r.name + ' ' + r.ratio.toFixed(2) + '<' + r.min), [],
|
||
'文字与表面的对比度掉到阈值以下 —— 调色时改坏了,改回去或用 clampAgainst 重新夹紧')
|
||
|
||
const minRow = rows.slice().sort((a, b) => a.ratio - b.ratio)[0]
|
||
console.log('token-contrast: ' + rows.length + ' 对(亮/暗 × 文字 × 表面)全部达标;最紧的一对是 '
|
||
+ minRow.label + ' ' + minRow.name + ' = ' + minRow.ratio.toFixed(2) + '(下限 ' + minRow.min + ')')
|