feat(gallery): 1.7.1 底栏三个图标加大(14→18,命中区 20→28)
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 已人工核对。
This commit is contained in:
qiqi committed 2026-11-25 14:13:28 +08:00
1 parent b48418c9ae
commit 2a484dac05
6 files changed
+268 -12

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/gallery",
"private": true,
"version": "1.7.0",
"version": "1.7.1",
"description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供",
"ibwPlugin": {
"id": "gallery",
+8 -4
View File
@@ -47,16 +47,20 @@
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
// v1.4.1:底栏按钮改用图标(窄栏里「刷新/设置」会被挤成竖排两行)
// v1.7.1:14px 在底栏里太小(齿轮细节几乎看不清)。按宿主 design-tokens.md §3.8
// 图标尺寸闭集 14/16/18 取最大档 --iwb-icon-lg(18),描边按规范 1.6;
// 命中区 ≥28×28 由 styles.css 的按钮尺寸兜住(图形放大不等于点击区变大)。
var SVG_NS = 'http://www.w3.org/2000/svg'
var ICON_PX = 18
function iconBtn (label, build, title) {
var b = el('button', { class: 'iwb-btn iwb-btn-sm iwb-gal-icobtn', title: title || label, 'aria-label': label })
var svg = document.createElementNS(SVG_NS, 'svg')
svg.setAttribute('viewBox', '0 0 16 16')
svg.setAttribute('width', '14')
svg.setAttribute('height', '14')
svg.setAttribute('width', String(ICON_PX))
svg.setAttribute('height', String(ICON_PX))
svg.setAttribute('fill', 'none')
svg.setAttribute('stroke', 'currentColor')
svg.setAttribute('stroke-width', '1.5')
svg.setAttribute('stroke-width', '1.6')
svg.setAttribute('stroke-linecap', 'round')
svg.setAttribute('stroke-linejoin', 'round')
svg.setAttribute('aria-hidden', 'true')
@@ -590,7 +594,7 @@
global.IWBPluginHost.register({
id: 'gallery',
name: '图库',
version: '1.7.0',
version: '1.7.1',
apiVersion: 1,
capabilities: ['panels', 'gallery'],
data: { schemaVersion: 1, maxBytes: 65536 },
+15 -6
View File
@@ -24,25 +24,34 @@
.iwb-gal-count { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; }
.iwb-gal-sel { font-size: 11px; color: var(--iwb-brand); white-space: nowrap; }
.iwb-gal-status { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; max-width: none; }
.iwb-gal-tools { display: flex; align-items: center; gap: 0; flex: 0 0 auto; margin-left: auto; }
/* v1.7.1:图标放大后三个按钮不再紧贴(4px 是 spacing 闭集值) */
.iwb-gal-tools { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; margin-left: auto; }
/* ---- 图标按钮:无外框、无底色,只在悬停时给一点反馈 ---- */
/* ---- 图标按钮:无外框、无底色,只在悬停时给一点反馈 ----
v1.7.1:命中区 20×20 → 28×28(design-tokens.md §3.8「≥28×28」),
图形 14 → var(--iwb-icon-lg) 18;CSS 尺寸覆盖 SVG 的 presentation attribute,
属性里的 18 只作宿主 token 缺失时的兜底。 */
.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; padding: 0; box-sizing: border-box;
width: 28px; height: 28px; min-width: 28px; padding: 0; box-sizing: border-box;
display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
border: 0; box-shadow: none; background: transparent; border-radius: 6px;
color: var(--iwb-text2); line-height: 1; transform: none;
}
.iwb-gal-foot .iwb-gal-icobtn svg { display: block; pointer-events: none; }
.iwb-gal-foot .iwb-gal-icobtn svg {
display: block; pointer-events: none;
width: var(--iwb-icon-lg, 18px); height: var(--iwb-icon-lg, 18px);
}
.iwb-gal-foot .iwb-gal-icobtn:hover { background: var(--iwb-layer2); color: var(--iwb-text); }
.iwb-gal-foot .iwb-gal-icobtn:focus-visible { outline: 2px solid color-mix(in srgb, var(--iwb-brand) 60%, transparent); outline-offset: 1px; }
.iwb-gal-setbtn-on { color: var(--iwb-brand); background: var(--iwb-layer2); }
/* ---- 设置浮层(三个下拉不占前台) ---- */
/* ---- 设置浮层(三个下拉不占前台) ----
bottom 随底栏高度走:底栏 = padding-top 6 + border 1 + 按钮 28,再加容器底 4 → 39,
取 40 让浮层正好停在底栏上沿之外;仍用 34 会被放大后的图标压住。 */
.iwb-gal-settings {
position: absolute; right: 8px; bottom: 34px; z-index: 30; width: 176px; max-width: calc(100% - 16px);
position: absolute; right: 8px; bottom: 40px; z-index: 30; width: 176px; max-width: calc(100% - 16px);
display: flex; flex-direction: column; gap: 8px; padding: 8px 10px;
background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 8px;
box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
+162
View File
@@ -0,0 +1,162 @@
#!/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,
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])
// 设置浮层展开后不能被放大的底栏压住
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()
+79
View File
@@ -0,0 +1,79 @@
#!/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
+3 -1
View File
@@ -6,9 +6,11 @@
"scripts": {
"validate": "node scripts/validate.mjs",
"build": "node scripts/build-plugin.mjs",
"test": "npm run validate && npm run test:album && npm run test:promptlib",
"test": "npm run validate && npm run test:album && npm run test:promptlib && npm run test:gallery",
"test:album": "node album/tools/harness.mjs",
"test:album:e2e": "node album/tools/viewer-e2e.mjs",
"test:gallery": "node gallery/tools/harness.mjs",
"test:gallery:visual": "node gallery/tools/foot-visual-check.mjs",
"test:promptlib": "node promptlib/tools/harness.mjs && node promptlib/tools/vars-editor-test.mjs",
"test:promptlib:visual": "node promptlib/tools/vars-panel-visual-check.mjs"
},