Files
T
qiqi b48418c9ae
validate / validate (push) Canceled after 0s
feat(promptlib): 1.13.1 变量栏去掉 i 按钮 + 行间分割线(位置 2)
用户裁定:按推荐方案 A,分割线落在「变量行与行之间」。

- 删掉每行右侧 i 圆按钮(它只做「强制展开」,与整行点击重复),连同 6 处
  .iwb-plp-vi CSS 规则;展开态由 caret 主色 + 整行 hover 反馈表达。
- 旧的 .iwb-plp-vitem dashed 行线被 dialog 作用域的 border:0 覆盖,编辑弹窗里
  实际一条线都没有;改为相邻兄弟选择器画 1px 实线,首行与末行之后都不画线。
  颜色按 design-tokens.md §3.11 的 --iwb-set-divider 公式(--iwb-border 55%)就地兜底:
  该变量只定义在 .iwb-settings-modal 作用域,插件面板不在其中,直接引用会掉到全强度边框。
- 标题下、展开字段前都不另画线,避免一屏三层线;尺寸全用 --iwb-space-* /
  --iwb-radius-control / --iwb-bw,无新增裸值。

测试:npm test 全过(新增 11 项静态断言);新增 tools/vars-panel-visual-check.mjs
(Chromium 亮/暗 19 项:i 按钮为 0、首行 0px 其余 1px、55% 淡线、暗色跟随、
hover、展开输入框、正文变量色块、连点 selectionStart 不漂移),两套截图已核对。
npm scripts 新增 test:promptlib / test:promptlib:visual,前者并入默认 npm test。
2026-11-25 13:52:36 +08:00

163 lines
8.5 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.
// 变量栏视觉核对(v1.13.1):真实 Chromium 挂载 promptlib 编辑弹窗,亮/暗两套截图。
// 依据 docs/standards/promptlib-style-baseline.md §四「发布前检查清单」:
// 静态渲染截图核对(颜色、滚动、输入框描边)+ 真机连点验证 selectionStart 不漂移。
// 依赖宿主仓 playwright:node promptlib/tools/vars-panel-visual-check.mjs
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')
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: 1200, height: 900 }, 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"><div id="host"></div></body></html>')
await page.addStyleTag({ path: TOKENS })
await page.addStyleTag({ path: HOSTCSS })
await page.addStyleTag({ path: CSS })
await page.evaluate(() => {
window.IWBPluginHost = { register: (meta, factory) => { window.__reg = { meta, factory } } }
})
await page.addScriptTag({ path: SRC })
const info = await page.evaluate(() => {
const prompts = [{ id: 'a', name: '示例', text: '风格 {写实摄影}', group: '默认' }]
const groups = [{ id: '默认', name: '默认' }]
const data = { schemaVersion: 3, prompts, groups }
const ctx = {
data: { read: async () => data, write: async () => ({ ok: true }), set: async () => ({ ok: true }), get: async () => null },
promptlib: {
list: async () => ({ prompts, groups }), save: async () => ({ ok: true }), insert: async () => ({ ok: true }),
notify: () => {}, onChanged: () => () => {},
filePut: async () => ({ ok: true }), fileGet: async () => '', fileList: async () => [], fileRemove: async () => ({ ok: true }), fileStat: async () => ({ count: 0, bytes: 0 }),
},
files: { put: async () => ({ ok: true }), get: async () => '', list: async () => [], remove: async () => ({ ok: true }), stat: async () => ({ count: 0, bytes: 0 }) },
storage: { set: () => {}, get: () => null },
ui: { registerPanel: (p) => { window.__panel = p }, toast: () => {} },
nodes: { register: () => {} },
canvas: { screenToWorld: (x, y) => ({ x, y }) },
canvasWrite: { createNode: () => 'n1', createImageNode: () => 'n2' },
}
window.__reg.factory(ctx)
window.__panel.mount(document.getElementById('host'))
return { version: window.__reg.meta.version }
})
ok('插件版本 = 1.13.1', info.version === '1.13.1', info.version)
// 打开「新建」弹窗,正文写四个变量,展开第 2 行
await page.evaluate(() => {
const btn = Array.from(document.querySelectorAll('#host button')).find((b) => b.textContent.trim() === '新建')
btn.click()
})
await page.waitForTimeout(350)
await page.evaluate(() => {
const ta = document.querySelector('.iwb-plp-etext')
ta.value = '风格 {写实摄影},字体 {手写书法},人物 {女生},卖点 {价格与利益点},画面简洁'
ta.dispatchEvent(new Event('input', { bubbles: true }))
})
await page.waitForTimeout(450)
await page.evaluate(() => {
const rows = document.querySelectorAll('.iwb-plp-vrow2')
if (rows[1]) rows[1].click()
})
await page.waitForTimeout(250)
const geo = await page.evaluate(() => {
const items = Array.from(document.querySelectorAll('.iwb-plp-vitem'))
const rows = Array.from(document.querySelectorAll('.iwb-plp-vrow2'))
const head = document.querySelector('.iwb-plp-vhead')
const caret = document.querySelector('.iwb-plp-vitem.is-open .iwb-plp-vcaret')
const border = (el) => {
const s = getComputedStyle(el)
return { top: s.borderTopWidth, bottom: s.borderBottomWidth, color: s.borderTopColor, padTop: s.paddingTop }
}
return {
iBtn: document.querySelectorAll('.iwb-plp-vi').length,
items: items.length,
rows: rows.length,
borders: items.map(border),
headBorder: head ? getComputedStyle(head).borderBottomWidth : '',
vfieldBorder: getComputedStyle(document.querySelector('.iwb-plp-vfield') || document.body).borderTopWidth,
caretOpen: caret ? getComputedStyle(caret).color : '',
caretClosed: rows[0] ? getComputedStyle(rows[0].querySelector('.iwb-plp-vcaret')).color : '',
rowPad: rows[0] ? getComputedStyle(rows[0]).padding : '',
hlvar: document.querySelectorAll('.iwb-plp-hlvar').length,
inputs: document.querySelectorAll('.iwb-plp-vname, .iwb-plp-vdef, .iwb-plp-vdesc').length,
}
})
console.log('几何 / 计算样式 =', JSON.stringify(geo))
ok('不再渲染 i 圆按钮', geo.iBtn === 0, geo.iBtn)
ok('4 个变量都渲染出来', geo.items === 4 && geo.rows === 4, geo.items)
ok('首行不画线(顶部/底部都 0)',
geo.borders[0] && geo.borders[0].top === '0px' && geo.borders[0].bottom === '0px', geo.borders[0])
ok('第 2/3/4 行顶部各 1px 实线(位置 2)',
geo.borders.slice(1).every((b) => b && b.top === '1px'), geo.borders.slice(1).map((b) => b.top))
ok('末行之后没有多余的线', geo.borders[3] && geo.borders[3].bottom === '0px', geo.borders[3])
// color-mix 在 Chromium 里会解析成 color(srgb … / a),老版本则是 rgba(…, a)
const alphaOf = (s) => {
const str = String(s)
const m = str.match(/rgba\([^)]*,\s*([\d.]+)\)/) || str.match(/color\([^)]*\/\s*([\d.]+)\)/)
return m ? Number(m[1]) : 1
}
ok('线色是规范 55% 淡线(半透明,没掉到全强度 --iwb-border)',
/^(rgba\(|color\(srgb)/.test(geo.borders[1].color) && Math.abs(alphaOf(geo.borders[1].color) - 0.55) < 0.02, geo.borders[1].color)
ok('标题下不画线(组标题靠间距分层)', geo.headBorder === '0px', geo.headBorder)
ok('展开字段前不另画线', geo.vfieldBorder === '0px', geo.vfieldBorder)
ok('展开态 caret 用主色、与收起态可区分',
geo.caretOpen !== geo.caretClosed && /^rgb\(/.test(geo.caretOpen), { open: geo.caretOpen, closed: geo.caretClosed })
ok('展开态三个输入框仍在,且输入框描边未丢', geo.inputs === 3, geo.inputs)
ok('正文变量浅主色色块仍在(v1.9.3 两层着色没被破坏)', geo.hlvar >= 1, geo.hlvar)
// hover:整行反馈接替被删掉的 i 按钮
await page.locator('.iwb-plp-vrow2').nth(2).hover()
await page.waitForTimeout(80)
const hoverBg = await page.evaluate(() => getComputedStyle(document.querySelectorAll('.iwb-plp-vrow2')[2]).backgroundColor)
ok('整行 hover 有浅底反馈', hoverBg !== 'rgba(0, 0, 0, 0)' && hoverBg !== 'transparent', hoverBg)
// 基线硬要求:连点正文 textarea 三次,selectionStart 不能逐次左移
const ta = page.locator('.iwb-plp-etext')
const box = await ta.boundingBox()
const clicks = []
for (let i = 0; i < 3; i++) {
await page.mouse.click(box.x + 120, box.y + 18)
clicks.push(await page.evaluate(() => document.querySelector('.iwb-plp-etext').selectionStart))
}
ok('正文连点 3 次 selectionStart 不漂移(两层着色未复发)',
clicks[0] === clicks[1] && clicks[1] === clicks[2], clicks)
await page.mouse.move(0, 0)
await page.screenshot({ path: '/tmp/plp-vars-1131-light.png', fullPage: true })
// 暗色:同一套 token 自动跟随
await page.evaluate(() => document.documentElement.classList.add('theme-dark'))
await page.waitForTimeout(150)
const dark = await page.evaluate(() => ({
border: getComputedStyle(document.querySelectorAll('.iwb-plp-vitem')[1]).borderTopColor,
width: getComputedStyle(document.querySelectorAll('.iwb-plp-vitem')[1]).borderTopWidth,
first: getComputedStyle(document.querySelectorAll('.iwb-plp-vitem')[0]).borderTopWidth,
}))
ok('暗色下线宽不变、颜色自动跟随 token',
dark.width === '1px' && dark.first === '0px' && dark.border !== geo.borders[1].color, dark)
await page.screenshot({ path: '/tmp/plp-vars-1131-dark.png', fullPage: true })
ok('页面无 JS 报错', errors.length === 0, errors)
console.log('截图:/tmp/plp-vars-1131-light.png、/tmp/plp-vars-1131-dark.png')
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过')
if (failed) process.exitCode = 1
await browser.close()