validate / validate (push) Canceled after 0s
用户实测:右栏「图库」底部的刷新 / 打开本地目录 / 设置三个图标太小,齿轮几乎看不清。 按宿主 design-tokens.md §3.8 落地(图标尺寸闭集 14/16/18、描边 1.6、命中区 ≥28×28): - SVG 14 → 18(ICON_PX,CSS 用 var(--iwb-icon-lg, 18px) 覆盖,宿主 token 缺失才用属性兜底); - stroke-width 1.5 → 1.6; - 按钮 20×20 → 28×28,工具组 gap 0 → 4(三个大图标不再紧贴); - 设置浮层 bottom 34 → 40:底栏长高到 35px + 容器底 4,仍用 34 会被图标压住。 左侧计数文字、三个图标的交互与类名都没动;新增尺寸全在 token 闭集内。 测试:新增 gallery/tools/harness.mjs(19 项静态断言,含旧值反向断言与散值检查), 并入默认 npm test;新增 gallery/tools/foot-visual-check.mjs(Chromium 挂真实面板 11 项: computed 28/18、gap、浮层不压底栏、亮暗尺寸一致、改前 14/20 对照),注册 test:gallery:visual。 npm test 与真浏览器核对全过,对比图 /tmp/gal-foot-171-compare.png 已人工核对。
80 lines
4.3 KiB
JavaScript
80 lines
4.3 KiB
JavaScript
#!/usr/bin/env node
|
||
/* 图库底栏图标的静态闸门(v1.7.1)
|
||
* 只改尺寸,不改交互;这些断言把「设计 token 口径」钉住,防止以后调样式时又缩回 14px/20×20。
|
||
* 运行:node gallery/tools/harness.mjs(已并入根 npm test)
|
||
*/
|
||
import { readFileSync } from 'node:fs'
|
||
import path from 'node:path'
|
||
import { fileURLToPath } from 'node:url'
|
||
|
||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||
const ROOT = path.resolve(HERE, '..')
|
||
const src = readFileSync(path.join(ROOT, 'src/index.js'), 'utf8')
|
||
const css = readFileSync(path.join(ROOT, 'styles.css'), 'utf8')
|
||
const pkg = JSON.parse(readFileSync(path.join(ROOT, 'package.json'), 'utf8'))
|
||
|
||
let failed = 0
|
||
const ok = (name, cond, actual) => {
|
||
if (!cond) failed++
|
||
console.log((cond ? '✓ ' : '✗ ') + name + (actual === undefined ? '' : ' → ' + JSON.stringify(actual)))
|
||
}
|
||
|
||
// ---- 版本两处一致 ----
|
||
ok('package.json version = 1.7.1', pkg.version === '1.7.1', pkg.version)
|
||
ok('manifest.version = 1.7.1', /version:\s*'1\.7\.1'/.test(src))
|
||
|
||
// ---- 图标尺寸:宿主 design-tokens.md §3.8 闭集 14/16/18,取最大档 ----
|
||
ok('SVG 尺寸常量 ICON_PX = 18', /\bvar ICON_PX = 18\b/.test(src))
|
||
ok('SVG width/height 都取 ICON_PX(不是写死 14)',
|
||
/setAttribute\('width', String\(ICON_PX\)\)/.test(src) &&
|
||
/setAttribute\('height', String\(ICON_PX\)\)/.test(src))
|
||
ok('描边按规范 stroke-width 1.6', /setAttribute\('stroke-width', '1\.6'\)/.test(src))
|
||
ok('CSS 图形尺寸走 --iwb-icon-lg(宿主 token 缺失才兜底 18px)',
|
||
/\.iwb-gal-foot \.iwb-gal-icobtn svg\s*\{[^}]*width:\s*var\(--iwb-icon-lg, 18px\)[^}]*height:\s*var\(--iwb-icon-lg, 18px\)/.test(css))
|
||
ok('命中区 28×28(§3.8「≥28×28」)',
|
||
/width:\s*28px;\s*height:\s*28px;\s*min-width:\s*28px/.test(css))
|
||
ok('工具组间距 4px(三个大图标不再紧贴)', /\.iwb-gal-tools\s*\{[^}]*gap:\s*4px/.test(css))
|
||
ok('设置浮层 bottom 随底栏长高到 40px(仍用 34 会被图标压住)',
|
||
/\.iwb-gal-settings\s*\{[^}]*bottom:\s*40px/.test(css))
|
||
|
||
// ---- 反向断言:旧的「小图标」写法不得回流 ----
|
||
ok('不再有 14px 的 SVG 属性', !/setAttribute\('(?:width|height)', '14'\)/.test(src))
|
||
ok('不再有 stroke-width 1.5', !/setAttribute\('stroke-width', '1\.5'\)/.test(src))
|
||
ok('不再有 20×20 命中区', !/width:\s*20px;\s*height:\s*20px;\s*min-width:\s*20px/.test(css))
|
||
ok('不再有 gap: 0 的紧贴按钮', !/gap:\s*0\s*;/.test(css))
|
||
ok('不再有 bottom: 34px', !/bottom:\s*34px/.test(css))
|
||
|
||
// ---- 交互与契约不变 ----
|
||
ok('三个图标仍是刷新 / 打开本地目录 / 设置',
|
||
/iconBtn\('刷新'/.test(src) && /iconBtn\('打开本地目录'/.test(src) && /iconBtn\('设置'/.test(src))
|
||
ok('按钮类名未变(宿主旧 .iwb-btn-sm 不会盖回来)',
|
||
/class:\s*'iwb-btn iwb-btn-sm iwb-gal-icobtn'/.test(src) &&
|
||
/\.iwb-gal-foot \.iwb-gal-icobtn/.test(css))
|
||
ok('悬停 / 键盘聚焦反馈仍在',
|
||
/\.iwb-gal-foot \.iwb-gal-icobtn:hover\s*\{[^}]*background/.test(css) &&
|
||
/\.iwb-gal-foot \.iwb-gal-icobtn:focus-visible/.test(css))
|
||
ok('左侧计数 / 选中 / 状态文字字号没被顺手改掉',
|
||
/\.iwb-gal-count\s*\{[^}]*font-size:\s*11px/.test(css) &&
|
||
/\.iwb-gal-sel\s*\{[^}]*font-size:\s*11px/.test(css))
|
||
|
||
// ---- 尺寸闭集(对齐宿主 plugin-scale-contract,防止放大时又引入散值)----
|
||
const FONT = new Set([11, 12, 13, 14, 15, 17, 20, 24])
|
||
const RADIUS = new Set([6, 8, 10, 12, 14, 999])
|
||
const SPACE = new Set([0, 2, 4, 6, 8, 10, 12, 16, 20, 24, 32, 40, 48, 64])
|
||
const stray = []
|
||
for (const m of css.matchAll(/([a-z-]+)\s*:\s*([^;{}]+)/g)) {
|
||
const prop = m[1].toLowerCase()
|
||
const val = m[2].trim()
|
||
if (val.includes('var(')) continue
|
||
const px = [...val.matchAll(/([0-9.]+)px/g)].map((x) => Number(x[1]))
|
||
if (prop === 'font-size' && px.some((n) => !FONT.has(n))) stray.push('font-size:' + val)
|
||
else if (prop === 'border-radius' && px.some((n) => !RADIUS.has(n))) stray.push('border-radius:' + val)
|
||
else if (/^(gap|row-gap|column-gap)$/.test(prop) || /^(padding|margin)/.test(prop)) {
|
||
if (px.some((n) => !SPACE.has(n))) stray.push(prop + ':' + val)
|
||
}
|
||
}
|
||
ok('CSS 字号 / 圆角 / 间距无新增散值', stray.length === 0, stray)
|
||
|
||
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过(gallery 1.7.1 底栏图标)')
|
||
if (failed) process.exitCode = 1
|