validate / validate (push) Canceled after 0s
同步到宿主仓后 npm run lint:tokens 拦下 plugins/gallery/styles.css 的 z-index: 30: 它是存量裸值,但 1.7.1 改 bottom 时整行被当成「新增行」,于是重新被检查。 按 design-tokens.md §3.6 层级表换成 var(--iwb-z-ctx-menu, 91):仍低于 curtain(100)/command(120),面板内浮层的相对层级不变,视觉无差异。 harness 加「不得再写死裸 z-index」断言,浏览器核对 computed z-index = 91。
165 lines
8.7 KiB
JavaScript
165 lines
8.7 KiB
JavaScript
#!/usr/bin/env node
|
||
/* 图库底栏图标「真浏览器」核对(v1.7.1)
|
||
* 静态断言只能证明代码里有 18/28,证明不了宿主 style.css + 插件 CSS 叠完后真的是这个尺寸。
|
||
* 这里加载宿主 token/style + 插件源码本体,用合成 ctx 挂载真实面板,量 computed、验浮层不压底栏,
|
||
* 并出「改前 14/20」与「改后 18/28」的亮色对比图 + 改后暗色图。
|
||
*
|
||
* 运行:node gallery/tools/foot-visual-check.mjs
|
||
* 依赖宿主仓 playwright(跨仓依赖,不进默认 npm test)。
|
||
*/
|
||
import { readFileSync } from 'node:fs'
|
||
import path from 'node:path'
|
||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||
|
||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||
const HOST = path.resolve(HERE, '..', '..', '..', 'image-workbench-desktop')
|
||
const PW = pathToFileURL(path.resolve(HOST, 'node_modules', 'playwright', 'index.mjs')).href
|
||
const { chromium } = await import(PW)
|
||
const SRC = path.resolve(HERE, '..', 'src', 'index.js')
|
||
const CSS = path.resolve(HERE, '..', 'styles.css')
|
||
const TOKENS = path.resolve(HOST, 'src', 'design-tokens.css')
|
||
const HOSTCSS = path.resolve(HOST, 'style.css')
|
||
const cssText = readFileSync(CSS, 'utf8')
|
||
|
||
let failed = 0
|
||
const ok = (name, cond, actual) => {
|
||
if (!cond) failed++
|
||
console.log((cond ? '✓ ' : '✗ ') + name + (actual === undefined ? '' : ' → ' + JSON.stringify(actual)))
|
||
}
|
||
|
||
const browser = await chromium.launch()
|
||
const page = await browser.newPage({ viewport: { width: 760, height: 520 }, deviceScaleFactor: 2 })
|
||
const errors = []
|
||
page.on('pageerror', (e) => errors.push(String(e)))
|
||
|
||
await page.setContent(`<!doctype html><html><head><meta charset="utf-8"></head>
|
||
<body style="margin:0;background:#f2f3f5">
|
||
<div style="padding:16px"><div id="host" style="width:320px;height:240px;display:flex;flex-direction:column;background:var(--iwb-panel)"></div></div>
|
||
</body></html>`)
|
||
await page.evaluate(() => { window.__TAURI__ = { core: {} }; window.IWBPluginHost = { register: (meta, factory) => { window.__reg = { meta, factory } } } })
|
||
await page.addStyleTag({ path: TOKENS })
|
||
await page.addStyleTag({ path: HOSTCSS })
|
||
await page.addStyleTag({ path: CSS })
|
||
await page.addScriptTag({ path: SRC })
|
||
|
||
const version = await page.evaluate(() => {
|
||
const names = Array.from({ length: 17 }, (_, i) => 'img-' + (i + 1) + '.png')
|
||
const items = names.map((name) => ({ name: name, w: 80, h: 80 }))
|
||
const thumb = 'data:image/svg+xml,' + encodeURIComponent(
|
||
'<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80"><rect width="80" height="80" fill="#dfe3e9"/></svg>')
|
||
const ctx = {
|
||
ui: { registerPanel: (p) => { window.__panel = p } },
|
||
data: { read: async () => ({}), patch: async () => ({ ok: true }) },
|
||
gallery: {
|
||
list: async () => ({ items: items, total: 17 }),
|
||
thumb: async () => thumb,
|
||
onChanged: () => () => {},
|
||
insert: async () => ({ ok: true }), remove: async () => ({ ok: true }),
|
||
download: async () => ({ ok: true }), preview: () => {}, openFolder: async () => ({ ok: true }),
|
||
},
|
||
}
|
||
window.__reg.factory(ctx)
|
||
window.__panel.mount(document.getElementById('host'))
|
||
return window.__reg.meta.version
|
||
})
|
||
ok('插件版本 = 1.7.1', version === '1.7.1', version)
|
||
await page.waitForTimeout(700)
|
||
|
||
const geo = await page.evaluate(() => {
|
||
const btns = Array.from(document.querySelectorAll('.iwb-gal-icobtn'))
|
||
const cs = (el) => getComputedStyle(el)
|
||
const tools = document.querySelector('.iwb-gal-tools')
|
||
const settings = document.querySelector('.iwb-gal-settings')
|
||
const foot = document.querySelector('.iwb-gal-foot')
|
||
return {
|
||
buttons: btns.length,
|
||
labels: btns.map((b) => b.getAttribute('aria-label')),
|
||
btnW: btns.map((b) => cs(b).width),
|
||
btnH: btns.map((b) => cs(b).height),
|
||
svgW: btns.map((b) => cs(b.querySelector('svg')).width),
|
||
svgAttr: btns.map((b) => b.querySelector('svg').getAttribute('width')),
|
||
gap: cs(tools).columnGap,
|
||
settingsBottom: cs(settings).bottom,
|
||
settingsZ: cs(settings).zIndex,
|
||
footH: cs(foot).height,
|
||
count: document.querySelector('.iwb-gal-count').textContent,
|
||
folderVisible: btns[1] && cs(btns[1]).display !== 'none',
|
||
}
|
||
})
|
||
console.log('几何 / 计算样式 =', JSON.stringify(geo))
|
||
ok('三个图标都在(刷新 / 打开本地目录 / 设置)', geo.buttons === 3 && geo.folderVisible, geo.labels)
|
||
ok('计数文字仍是 17 / 17 张(没动左侧信息区)', geo.count === '17 / 17 张', geo.count)
|
||
ok('命中区真的 28×28(不是只改了源码字符串)',
|
||
geo.btnW.every((w) => w === '28px') && geo.btnH.every((h) => h === '28px'), [geo.btnW, geo.btnH])
|
||
ok('图形真的 18×18(--iwb-icon-lg 生效)',
|
||
geo.svgW.every((w) => w === '18px') && geo.svgAttr.every((w) => w === '18'), geo.svgW)
|
||
ok('按钮间距 4px', geo.gap === '4px', geo.gap)
|
||
ok('设置浮层 bottom = 40px,底栏高度跟着长到 35px',
|
||
geo.settingsBottom === '40px' && geo.footH === '35px', [geo.settingsBottom, geo.footH])
|
||
ok('浮层层级真的取到 --iwb-z-ctx-menu(91)', geo.settingsZ === '91', geo.settingsZ)
|
||
|
||
// 设置浮层展开后不能被放大的底栏压住
|
||
await page.locator('button[aria-label="设置"]').click()
|
||
await page.waitForTimeout(120)
|
||
const overlap = await page.evaluate(() => {
|
||
const s = document.querySelector('.iwb-gal-settings').getBoundingClientRect()
|
||
const f = document.querySelector('.iwb-gal-foot').getBoundingClientRect()
|
||
return { settingsBottom: s.bottom, footTop: f.top, display: getComputedStyle(document.querySelector('.iwb-gal-settings')).display }
|
||
})
|
||
ok('设置浮层打开时停在底栏上沿之外(不压住图标)',
|
||
overlap.display !== 'none' && overlap.settingsBottom <= overlap.footTop + 1, overlap)
|
||
await page.locator('button[aria-label="设置"]').click()
|
||
await page.mouse.move(0, 0)
|
||
await page.waitForTimeout(120)
|
||
|
||
// 改前(1.7.0 口径)用同特异性覆盖规则模拟,不依赖 git 历史,脚本以后也能复跑
|
||
const old = await page.addStyleTag({ content: `
|
||
.iwb-gal-foot .iwb-gal-icobtn,
|
||
.iwb-gal-foot .iwb-gal-icobtn:hover,
|
||
.iwb-gal-foot .iwb-gal-icobtn:active { width:20px; height:20px; min-width:20px; }
|
||
.iwb-gal-foot .iwb-gal-icobtn svg { width:14px; height:14px; }
|
||
.iwb-gal-tools { gap:0; }
|
||
.iwb-gal-settings { bottom:34px; }` })
|
||
await page.waitForTimeout(100)
|
||
const beforeGeo = await page.evaluate(() => ({
|
||
btn: getComputedStyle(document.querySelector('.iwb-gal-icobtn')).width,
|
||
svg: getComputedStyle(document.querySelector('.iwb-gal-icobtn svg')).width,
|
||
}))
|
||
ok('覆盖出的「改前」确实是 14px 图形 / 20px 命中区',
|
||
beforeGeo.svg === '14px' && beforeGeo.btn === '20px', beforeGeo)
|
||
const before = (await page.locator('.iwb-gal-foot').screenshot()).toString('base64')
|
||
await old.evaluate((el) => el.remove())
|
||
await page.waitForTimeout(100)
|
||
const after = (await page.locator('.iwb-gal-foot').screenshot()).toString('base64')
|
||
await page.screenshot({ path: '/tmp/gal-foot-171-light.png', fullPage: true })
|
||
|
||
// 暗色:token 自动跟随,尺寸不变
|
||
await page.evaluate(() => document.documentElement.classList.add('theme-dark'))
|
||
await page.waitForTimeout(150)
|
||
const dark = await page.evaluate(() => ({
|
||
btn: getComputedStyle(document.querySelector('.iwb-gal-icobtn')).width,
|
||
svg: getComputedStyle(document.querySelector('.iwb-gal-icobtn svg')).width,
|
||
color: getComputedStyle(document.querySelector('.iwb-gal-icobtn')).color,
|
||
}))
|
||
ok('暗色下尺寸不变、图标色跟随 token', dark.btn === '28px' && dark.svg === '18px', dark)
|
||
await page.locator('.iwb-gal-foot').screenshot({ path: '/tmp/gal-foot-171-dark.png' })
|
||
await page.screenshot({ path: '/tmp/gal-foot-171-dark-full.png', fullPage: true })
|
||
|
||
// 对比图:两列底部对齐,标签用英文避免字体缺失
|
||
const cmp = await browser.newPage({ viewport: { width: 780, height: 240 }, deviceScaleFactor: 2 })
|
||
await cmp.setContent(`<!doctype html><html><head><meta charset="utf-8"></head>
|
||
<body style="margin:0;background:#fff;font-family:-apple-system,Helvetica,Arial,sans-serif">
|
||
<div style="display:flex;align-items:flex-end;gap:24px;padding:20px">
|
||
<div><div style="font-size:14px;font-weight:600;color:#333;margin-bottom:10px">BEFORE · 14px icon / 20x20 hit area</div>
|
||
<img src="data:image/png;base64,${before}" style="display:block;border:1px solid #e3e5e9"></div>
|
||
<div><div style="font-size:14px;font-weight:600;color:#333;margin-bottom:10px">AFTER · 18px icon / 28x28 hit area</div>
|
||
<img src="data:image/png;base64,${after}" style="display:block;border:1px solid #e3e5e9"></div>
|
||
</div></body></html>`)
|
||
await cmp.screenshot({ path: '/tmp/gal-foot-171-compare.png', fullPage: true })
|
||
|
||
ok('页面无 JS 报错', errors.length === 0, errors)
|
||
console.log('截图:/tmp/gal-foot-171-compare.png(对比)、-light.png、-dark.png、暗色全图')
|
||
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过')
|
||
if (failed) process.exitCode = 1
|
||
await browser.close()
|