// 标注插件本地端到端(开发用,不进 CI)。 // // 为什么需要它:真站 e2e 要发布后才能跑;本探针直接把构建产物注入合成宿主, // 在真实 Chromium 里验证「选区 / 命令层 / 撤销 / 还原原图 / 输出预设 / 便利 UI」 // 以及 ESM 循环打包后是否真的能跑起来。网络完全本地,不依赖线上 KV 与 CSP。 // // 运行:node image-annotate/tools/harness.mjs // 依赖:playwright(本仓/宿主仓 node_modules 均可;或用 IWB_PLAYWRIGHT_ROOT 指定) import { createRequire } from 'node:module' import { readFileSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const HERE = path.dirname(fileURLToPath(import.meta.url)) const REPO = path.resolve(HERE, '../..') const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web' const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js') // 版本真源是 package.json(构建时注入 manifest),探针不再硬编码,免得每次发版都要改测试 const PKG_VERSION = JSON.parse(readFileSync(path.resolve(HERE, '../package.json'), 'utf8')).version let chromium = null for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) { try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch { /* 试下一个 */ } } if (!chromium) { console.error('✗ 找不到 playwright。请在含 node_modules 的目录执行,或指定 IWB_PLAYWRIGHT_ROOT') process.exit(2) } let failed = 0 const check = (name, ok, detail) => { if (!ok) failed++ console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : '')) } const poll = async (fn, timeout = 8000, step = 80) => { const end = Date.now() + timeout for (;;) { let v try { v = await fn() } catch { v = false } if (v) return v if (Date.now() > end) return false await new Promise((r) => setTimeout(r, step)) } } const browser = await chromium.launch() const page = await browser.newPage({ viewport: { width: 1440, height: 1000 }, acceptDownloads: true }) const errors = [] page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()) }) page.on('pageerror', (e) => errors.push('pageerror: ' + e.message)) page.on('dialog', (d) => { errors.push('unexpected dialog: ' + d.message()); d.dismiss().catch(() => {}) }) await page.setContent('
') const PNG = await page.evaluate(() => { const c = document.createElement('canvas') c.width = 96; c.height = 64 const x = c.getContext('2d') x.fillStyle = '#2f6fed'; x.fillRect(0, 0, 96, 64) x.fillStyle = '#ffffff'; x.fillRect(20, 12, 56, 40) return c.toDataURL('image/png') }) // ---------- 合成宿主 ---------- await page.evaluate(() => { window.IWBPluginHost = { register(manifest, factory) { window.__manifest = manifest; window.__factory = factory }, snapshot() { return { initialized: true } }, list() { return [] } } window.__actions = {} window.__commands = {} window.__settings = {} window.__writes = [] }) await page.addScriptTag({ path: PLUGIN_ENTRY }) const boot = await page.evaluate((png) => { const ctx = { id: 'image-annotate', manifest: window.__manifest, apiVersion: 1, log() {}, settings: { get(k) { return window.__settings[k] }, set(k, v) { window.__settings[k] = v }, all() { return { ...window.__settings } } }, storage: { get() {}, set() {}, remove() {}, keys() { return [] } }, events: { on() { return () => {} }, emit() { return true } }, canvas: { getNodeImage() { return { dataUrl: png } }, getSelectedNode() { return { id: 'r1', type: 'ref', name: 'src.png' } }, setNodeImage(id, dataUrl) { window.__writes.push({ kind: 'replace', id, len: String(dataUrl).length }); return true }, createImageNode(o) { window.__writes.push({ kind: 'newNode', len: String(o.dataUrl).length }); return { id: 'r2' } } }, nodeActions: { register(r) { window.__actions[r.id] = r } }, commands: { register(r) { window.__commands[r.id] = r } } } window.__plugin = window.__factory(ctx) window.__commands['annotate-selected'].run().catch(() => {}) return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) } }, PNG) check('产物可执行(循环打包未炸)', boot.version === PKG_VERSION, 'version=' + boot.version + ' 期望 ' + PKG_VERSION) check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(',')) await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 }) const dbg = () => page.evaluate(() => window.__iwbEditor.__debug()) const pixel = (cx, cy) => page.evaluate(({ x, y }) => { const d = window.__iwbEditor.__debug() return { base: d.pixel('base', x, y), draw: d.pixel('draw', x, y), layers: d.layers.map(l => ({ id: l.id, a: d.pixel(l.id, x, y) })) } }, { x: cx, y: cy }) check('编辑器打开 + 便利 UI 五区齐全(v1.2.4 起命令带取代「更多」菜单)', await page.evaluate(() => { const q = (s) => Boolean(document.querySelector(s)) return q('.iwb-editor-optionbar') && q('.iwb-editor-statusbar') && q('.iwb-editor-sel-bar') && q('.iwb-editor-toast') && q('.iwb-editor-selection-overlay') && q('.iwb-editor-cursor-overlay') && q('[data-action="download"]') && q('.iwb-editor-commands') })) check('新增选区工具按钮', (await page.locator('.iwb-editor-tool[data-tool="marquee"]').count()) === 1 && (await page.locator('.iwb-editor-tool[data-tool="lasso"]').count()) === 1) check('modal 铺满视口、状态栏贴在 modal 底部(防多余 把状态栏挤成 overlay 的 flex 兄弟)', await page.evaluate(() => { const ov = document.querySelector('#iwb-editor-overlay') const modal = ov.querySelector('.iwb-editor-modal') const sb = ov.querySelector('.iwb-editor-statusbar') if (!ov || !modal || !sb) return false const vw = window.innerWidth const m = modal.getBoundingClientRect(), s = sb.getBoundingClientRect(), o = ov.getBoundingClientRect() const inside = (a, b) => a.left >= b.left - 1 && a.right <= b.right + 1 && a.top >= b.top - 1 && a.bottom <= b.bottom + 1 return Math.round(m.width) === vw && Math.round(o.width) === vw && Math.abs(s.bottom - m.bottom) < 3 && inside(m, o) && inside(s, m) })) const imgBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() // ---------- 默认图层结构(用户裁定:默认不预建画笔标注层) ---------- check('打开编辑器默认只有「原图」1 层,且状态栏不再写「画笔标注」', (await dbg()).layers.length === 1 && (await dbg()).layers[0].id === 'base' && !(await page.locator('.iwb-editor-status-layer').textContent()).includes('画笔标注'), JSON.stringify((await dbg()).layers.map(l => l.name))) // v1.3(用户裁定 2026-11-05):调色板从侧栏搬进工具栏弹层,侧栏只剩缩放 check('调色板已搬进工具栏:侧栏只剩缩放,SV/色相/推荐色都在弹层里', await page.evaluate(() => { const q = (s) => Boolean(document.querySelector(s)) return !q('.iwb-editor-left .iwb-editor-color-panel') && q('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]') && q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') && document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-panel-swatch').length === 12 && q('.iwb-editor-zoom') && !q('.iwb-editor-brush-size') && !q('.iwb-editor-brush-num') && document.querySelectorAll('.iwb-editor-brush-preset').length === 0 })) // v1.4:侧栏「快速效果」(用户 2026-11-05 提出:反白 + 其它推荐效果) check('侧栏快速效果:6 个效果按钮齐备,目标层标签指向当前层', await page.evaluate(() => { const keys = [...document.querySelectorAll('.iwb-editor-left .iwb-editor-fx-btn')].map(b => b.dataset.fx).join(',') const label = document.querySelector('.iwb-editor-fx-target') return keys === 'invert,gray,boost,contrast,soft,mosaic' && !!label && label.textContent.trim() === '原图' })) const fxInvert = await (async () => { const read = () => page.evaluate(() => { const c = document.querySelectorAll('.iwb-editor-layer-canvas')[0] const d = c.getContext('2d').getImageData(2, 2, 1, 1).data return d[0] + ',' + d[1] + ',' + d[2] }) const before = await read() await page.locator('.iwb-editor-left [data-fx="invert"]').click() await page.waitForTimeout(180) const after = await read() await page.keyboard.press('Control+z') await page.waitForTimeout(180) const back = await read() return { ok: after !== before && back === before, detail: `before=${before} after=${after} undo=${back}` } })() check('反白真实反相且 Ctrl+Z 能复原(效果进历史链)', fxInvert.ok, fxInvert.detail) check('色板弹层默认收起;点工具栏色点弹出、且整块在视口内(没被工具栏/画布的 overflow 裁掉)', await (async () => { const pop = page.locator('.iwb-editor-color-pop') if (await pop.isVisible()) return 'pre: 弹层一开始就开着' await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() await page.waitForTimeout(100) if (!(await pop.isVisible())) return 'post: 点了没开' const box = await pop.boundingBox() const vp = page.viewportSize() const inView = box && box.x >= 0 && box.y >= 0 && box.x + box.width <= vp.width + 1 && box.y + box.height <= vp.height + 1 // Esc 关掉(顺带验证 Esc 优先收弹层),不影响后面的用例 await page.keyboard.press('Escape') await page.waitForTimeout(80) return inView && !(await pop.isVisible()) ? true : 'box=' + JSON.stringify(box) })()) const drag = async (x1, y1, x2, y2) => { await page.mouse.move(x1, y1) await page.mouse.down() await page.mouse.move(x2, y2, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(120) } // ---------- P1 选区 ---------- await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await drag(imgBox.x + imgBox.width * 0.25, imgBox.y + imgBox.height * 0.25, imgBox.x + imgBox.width * 0.7, imgBox.y + imgBox.height * 0.7) const sel = (await dbg()).selection check('拖出矩形选区 + 蚂蚁线启动', Boolean(sel && sel.w > 5 && sel.h > 5) && (await dbg()).ants, JSON.stringify(sel)) check('选区浮动操作条自动出现', await page.locator('.iwb-editor-sel-bar').isVisible()) const cx = Math.round(sel.x + sel.w / 2) const cy = Math.round(sel.y + sel.h / 2) const beforeFill = await pixel(cx, cy) await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click() const afterFill = await pixel(cx, cy) check('填充只写当前层(base 像素不变)', afterFill.draw && afterFill.draw[3] > 0 && JSON.stringify(afterFill.base) === JSON.stringify(beforeFill.base), 'draw=' + JSON.stringify(afterFill.draw) + ' base=' + JSON.stringify(afterFill.base)) check('原图锁定时填充自动落「标注」层(不写进原图)', (await dbg()).layers.some(l => l.id === 'draw' && l.name.indexOf('标注') === 0), JSON.stringify((await dbg()).layers.map(l => l.name))) const layersBeforeCopy = (await dbg()).layers.length await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.copy"]').click() const afterCopy = await dbg() check('复制为新层:像素落在选区原位、原层不变', afterCopy.layers.length === layersBeforeCopy + 1 && (await pixel(cx, cy)).draw[3] > 0, '层数 ' + layersBeforeCopy + ' → ' + afterCopy.layers.length) check('复制来源为当前层:新层有填充像素', afterCopy.layers.some(l => l.name === '选区副本') && (await pixel(cx, cy)).layers.some(v => v.id !== 'base' && v.id !== 'draw' && v.a && v.a[3] > 0)) await page.keyboard.press('Control+z') check('Ctrl+Z 撤销「复制为新层」(图层数可回退)', (await dbg()).layers.length === layersBeforeCopy, '层数=' + (await dbg()).layers.length) await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]').click() const afterDelete = await pixel(cx, cy) check('Delete 只清当前层:draw 挖空、base 与其它层原样', afterDelete.draw[3] === 0 && JSON.stringify(afterDelete.base) === JSON.stringify(beforeFill.base), 'draw=' + JSON.stringify(afterDelete.draw) + ' base=' + JSON.stringify(afterDelete.base)) await page.keyboard.press('Control+z') check('Ctrl+Z 恢复被清除的像素', (await pixel(cx, cy)).draw[3] > 0) // 三入口共用命令层 await page.keyboard.press('Control+j') const afterHotkey = await dbg() check('快捷键 Ctrl+J 与浮动条共用 execute()', afterHotkey.layers.length === layersBeforeCopy + 1 && afterHotkey.historyLabels.includes('复制为新层'), 'labels=' + JSON.stringify(afterHotkey.historyLabels.slice(-3))) await page.keyboard.press('Control+z') await page.mouse.click(imgBox.x + imgBox.width * 0.8, imgBox.y + imgBox.height * 0.2, { button: 'right' }) check('右键菜单复用同一条操作条', await page.locator('.iwb-editor-sel-bar.as-menu').count() === 1) // ---------- 还原原图(用户裁定:全部还原 + 可撤销) ---------- await page.keyboard.press('Control+a') // 重建选区(右键/工具切换不会改像素) await page.keyboard.press('Control+j') // 制造一个额外的选区副本层 const beforeReset = await dbg() await page.locator('[data-action="reset"]').click() const afterReset = await dbg() check('还原原图:只剩「原图」单层(默认不再预建画笔层)', afterReset.layers.length === 1 && afterReset.layers.some(l => l.id === 'base'), JSON.stringify(afterReset.layers.map(l => l.name))) check('还原原图清空矢量/选区但保留 base 像素', !afterReset.selection && JSON.stringify((await pixel(cx, cy)).base) === JSON.stringify(beforeFill.base)) await page.keyboard.press('Control+z') const afterUndoReset = await dbg() check('Ctrl+Z 完整恢复还原前的图层结构(含被删的选区副本层)', beforeReset.layers.length === 3 && afterUndoReset.layers.length === beforeReset.layers.length, '还原前 ' + beforeReset.layers.length + ' → 还原后 ' + afterReset.layers.length + ' → 撤销后 ' + afterUndoReset.layers.length) // ---------- 单张输出预设(≤500KB) ---------- await page.locator('[data-action="toggleExportSettings"]').click() await page.locator('[data-export-key="preset"][data-export-value="ecom800"]').click() const opt = (await dbg()).exportOptions check('≤500KB 预设可切换并存 ctx.settings', opt.preset === 'ecom800' && opt.maxKB === 500 && (await page.evaluate(() => window.__settings.exportPreset)) === 'ecom800', JSON.stringify(opt)) await page.locator('[data-action="download"]').click() const exported = await poll(async () => (await dbg()).lastExport) check('下载只产一个结果:800×800 且 ≤500KB、编辑器不关闭', Boolean(exported && exported.width === 800 && exported.height === 800 && exported.bytes <= 500 * 1024 && await page.locator('#iwb-editor-overlay').isVisible()), JSON.stringify(exported)) // 输出面板的可见性/文案探针:面板收起时子元素 display 不在布局里, // 所以统一读 textContent 而不是 innerText(后者对隐藏元素返回空串)。 const summaryText = () => page.locator('.iwb-editor-export-summary').textContent() const noteText = () => page.locator('.iwb-editor-export-note').textContent() const ecomRowsVisible = () => page.evaluate(() => { const rows = Array.from(document.querySelectorAll('[data-export-when="ecom800"]')) return rows.length >= 2 && rows.every(r => !r.hidden) }) check('电商预设:摘要写明尺寸/格式/背景/体积上限', /800×800/.test(await summaryText()) && /≤500KB/.test(await summaryText()) && /透明/.test(await summaryText()), await summaryText()) await page.locator('[data-action="toggleExportSettings"]').click() // 上一步点「下载」会自动收起面板 check('电商预设:边长与体积控件可见', await ecomRowsVisible()) await page.locator('[data-export-key="format"][data-export-value="jpeg"]').click() const afterJpg = await dbg() check('选 JPG:背景自动收敛为白底并写回 settings(不再「显示透明、实际白底」)', afterJpg.exportOptions.bg === 'white' && (await page.evaluate(() => window.__settings.exportBg)) === 'white' && (await page.locator('[data-export-key="bg"][data-export-value="transparent"]').isDisabled()) === true, JSON.stringify(afterJpg.exportOptions)) check('JPG 摘要显示白底', /白底/.test(await summaryText()), await summaryText()) await page.locator('[data-action="download"]').click() const jpg = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.format === 'jpeg' ? d.lastExport : false }) check('格式/背景切换生效(JPG + 白底)', Boolean(jpg) && jpg.bg === 'white', JSON.stringify(jpg)) check('下载后摘要记录上次输出(尺寸 + 体积)', /上次输出 800×800/.test(await noteText()), await noteText()) // 边长 / 体积上限:原来只有计算没有控件,改完必须能真的改到并生效 await page.locator('[data-action="toggleExportSettings"]').click() await page.locator('[data-export-key="size"][data-export-value="1000"]').click() await page.locator('[data-export-key="maxKB"][data-export-value="300"]').click() const optSized = (await dbg()).exportOptions check('边长/体积控件可改并持久化到 ctx.settings', optSized.size === 1000 && optSized.maxKB === 300 && (await page.evaluate(() => window.__settings.exportSize)) === 1000 && (await page.evaluate(() => window.__settings.exportMaxKB)) === 300, JSON.stringify(optSized)) await page.locator('[data-action="download"]').click() const sized = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.width === 1000 ? d.lastExport : false }) check('边长生效:输出 1000×1000 且体积 ≤300KB', Boolean(sized) && sized.width === 1000 && sized.bytes <= 300 * 1024, JSON.stringify(sized)) await page.locator('[data-action="toggleExportSettings"]').click() await page.locator('[data-export-key="preset"][data-export-value="original"]').click() const optOriginal = (await dbg()).exportOptions check('切回原尺寸:maxKB 归零并写回 settings(重开不会让限制「复活」)', optOriginal.preset === 'original' && optOriginal.maxKB === 0 && (await page.evaluate(() => window.__settings.exportMaxKB)) === 0, JSON.stringify(optOriginal)) check('原尺寸下边长/体积控件隐藏', (await ecomRowsVisible()) === false) check('原尺寸摘要显示实际像素尺寸', /原尺寸 96×64/.test(await summaryText()), await summaryText()) await page.locator('[data-action="toggleExportSettings"]').click() // 收起,恢复后续用例的初始态 // ---------- 选区与裁剪互斥 ---------- await page.locator('.iwb-editor-tool[data-tool="crop"]').click() check('切到裁剪会清掉选区,裁剪参数出现在选项栏(不再有画布下方浮窗)', !(await dbg()).selection && (await page.locator('.iwb-editor-optionbar-body [data-action="confirmCrop"]').count()) === 1 && (await page.locator('.iwb-editor-optionbar-body [data-ratio="1:1"]').count()) === 1 && (await page.locator('.iwb-editor-crop-bar').count()) === 0) await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() check('切回选区:裁剪控件从选项栏消失、裁剪框取消', await page.evaluate(() => !document.querySelector('[data-action="confirmCrop"]'))) // ---------- 回归:矢量对象经撤销/重做后仍可渲染(快照不得把 DOM 画布序列化成 {}) ---------- await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await drag(imgBox.x + imgBox.width * 0.2, imgBox.y + imgBox.height * 0.2, imgBox.x + imgBox.width * 0.45, imgBox.y + imgBox.height * 0.45) await page.keyboard.press('Control+z') await page.keyboard.press('Control+Shift+z') check('矢量对象撤销/重做后画布正常重建', await page.evaluate(() => document.querySelectorAll('.iwb-editor-vec-canvas').length >= 1)) await page.locator('.iwb-editor-tool[data-tool="brush"]').click() // ---------- 旧流程回归:粘贴一步落层 + 覆盖写回 ---------- const beforePaste = (await dbg()).layers.length await page.evaluate((png) => { const bin = atob(png.split(',')[1]) const bytes = new Uint8Array(bin.length) for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i) const dt = new DataTransfer() dt.items.add(new File([bytes], 'paste.png', { type: 'image/png' })) document.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true })) }, PNG) const pasted = await poll(async () => (await dbg()).layers.length === beforePaste + 1) check('粘贴图片一步落层(不再需要 Enter 确认)', Boolean(pasted), '层数 ' + beforePaste + ' → ' + (await dbg()).layers.length) await page.keyboard.press('Enter') check('粘贴后按 Enter 不会重复落层', (await dbg()).layers.length === beforePaste + 1) await page.locator('[data-action="replace"]').click() const wrote = await poll(async () => page.evaluate(() => window.__writes.some(w => w.kind === 'replace'))) check('覆盖仍回写宿主节点并关闭编辑器', Boolean(wrote) && (await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false, JSON.stringify(await page.evaluate(() => window.__writes))) // ---------- Round 2:P1 缺陷回归(新会话,逐条对应已确认缺陷) ---------- // 走 glue 的 openEditor:只有它能把「退出」与宿主 Promise 的结算连起来验证。 await page.evaluate(() => { window.__openState = null window.__commands['annotate-selected'].run().then( (mode) => { window.__openState = { mode: String(mode) } }, (err) => { window.__openState = { error: String((err && err.message) || err) } } ) }) await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 }) await page.waitForFunction(() => window.__iwbEditor.__debug().open === true) const box2 = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() const drag2 = async (x1, y1, x2, y2) => { await page.mouse.move(x1, y1) await page.mouse.down() await page.mouse.move(x2, y2, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(120) } // ---- Fix1:反选后 Delete / 复制必须作用整幅(与填充一致) ---- await page.keyboard.press('Control+a') await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click() const fullFill = await pixel(6, 6) check('Fix1 前置:全选填充整层', fullFill.draw[3] > 0) await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3, box2.x + box2.width * 0.6, box2.y + box2.height * 0.6) const sel2 = (await dbg()).selection const cx2 = Math.round(sel2.x + sel2.w / 2) const cy2 = Math.round(sel2.y + sel2.h / 2) await page.keyboard.press('Control+Shift+i') const inv = (await dbg()).selection check('反选:标记 inverted 且蚂蚁线仍在', Boolean(inv && inv.inverted) && (await dbg()).ants, JSON.stringify(inv)) await page.keyboard.press('Delete') const invKeep = await pixel(cx2, cy2) const invGone = await pixel(6, 6) check('反选 + Delete:原选区内保留、原选区外挖空、base 不变', invGone.draw[3] === 0 && invKeep.draw[3] > 0 && JSON.stringify(invGone.base) === JSON.stringify(fullFill.base), 'inside=' + JSON.stringify(invKeep.draw) + ' outside=' + JSON.stringify(invGone.draw)) await page.keyboard.press('Control+z') check('反选 + Delete 可 Ctrl+Z 回退(掩膜 tile 边界未偏移)', (await pixel(6, 6)).draw[3] > 0) const layersBeforeInvCopy = (await dbg()).layers.length await page.keyboard.press('Control+j') const afterInvCopy = await dbg() const invCopyLayer = afterInvCopy.layers[afterInvCopy.layers.length - 1] const copyOutside = await pixel(6, 6) const copyInside = await pixel(cx2, cy2) const copyOutsidePx = copyOutside.layers.find(v => v.id === invCopyLayer.id).a const copyInsidePx = copyInside.layers.find(v => v.id === invCopyLayer.id).a check('反选 + Ctrl+J:新层只含原选区外像素,且与原层逐点对齐(不偏移)', afterInvCopy.layers.length === layersBeforeInvCopy + 1 && invCopyLayer.name === '选区副本' && copyOutsidePx[3] > 0 && copyOutsidePx.join(',') === copyOutside.draw.join(',') && copyInsidePx[3] === 0, 'outside=' + JSON.stringify(copyOutsidePx) + ' draw=' + JSON.stringify(copyOutside.draw) + ' inside=' + JSON.stringify(copyInsidePx)) await page.keyboard.press('Control+z') // 撤销复制新层 await page.keyboard.press('Control+d') // 取消选区 // feather>0:整幅 tile 不能把羽化边界变成硬切 await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('6') await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3, box2.x + box2.width * 0.6, box2.y + box2.height * 0.6) const selF = (await dbg()).selection await page.keyboard.press('Control+Shift+i') const afterInvert = await dbg() await page.keyboard.press('Delete') const afterDel = await dbg() const edgeAlphas = [] for (let dx = -6; dx <= 6; dx++) { edgeAlphas.push((await pixel(Math.round(selF.x) + dx, Math.round(selF.y + selF.h / 2))).draw[3]) } const edgeDbg = await dbg() check('反选 + 羽化 6px:边界仍是渐变(羽化未因整幅掩膜失效)', selF.feather === 6 && edgeAlphas.some(a => a > 0 && a < 255), JSON.stringify(edgeAlphas) + ' feather=' + selF.feather + ' active=' + edgeDbg.activeLayerId + ' inv=' + (afterInvert.selection && afterInvert.selection.inverted) + ' hist=' + afterDel.historyLabels.slice(-2).join('/') + ' sel=' + JSON.stringify(afterDel.selection)) await page.keyboard.press('Control+z') await page.keyboard.press('Control+d') await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('0') // ---- Fix3:选中形状时建立像素选区,Delete 语义必须切到「清像素」 ---- await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await drag2(box2.x + box2.width * 0.35, box2.y + box2.height * 0.35, box2.x + box2.width * 0.65, box2.y + box2.height * 0.65) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5) const shapeSelected = await dbg() check('前置:形状已绘制并处于选中态', shapeSelected.shapes.length === 1 && shapeSelected.selectedShapeId === shapeSelected.shapes[0].id, JSON.stringify(shapeSelected.shapes)) await page.keyboard.press('Control+a') const selAllShape = (await dbg()).selection await page.keyboard.press('Delete') const afterShapeDelete = await dbg() const shapeDeletePixel = await pixel(cx2, cy2) check('选中形状 → Ctrl+A → Delete ⇒ 形状仍在、当前层像素被清(全选语义)', Boolean(selAllShape && selAllShape.w >= 96 && selAllShape.h >= 64) && afterShapeDelete.shapes.length === 1 && afterShapeDelete.selectedShapeId === null && shapeDeletePixel.draw[3] === 0, 'shapes=' + afterShapeDelete.shapes.length + ' draw=' + JSON.stringify(shapeDeletePixel.draw)) await page.keyboard.press('Control+z') await page.keyboard.press('Control+d') // ---- Fix2:裁剪与选区互斥(快捷键 / 顶栏全选图标 / 右键菜单三入口) + confirmCrop 清残留 ---- await page.locator('.iwb-editor-tool[data-tool="crop"]').click() const cropStart = await dbg() check('切到裁剪:旧选区被清、蚂蚁线停止', cropStart.selection === null && cropStart.ants === false) await page.keyboard.press('Control+a') const cropAfterA = await dbg() check('裁剪中 Ctrl+A:不建选区、不启动蚂蚁线、浮动条不出现', cropAfterA.selection === null && cropAfterA.ants === false && (await page.locator('.iwb-editor-sel-bar').isVisible()) === false) check('裁剪模式下选项栏没有选区命令入口(selcmd 只属于选择工具)', (await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()) === 0) await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5, { button: 'right' }) const menuShown = await page.locator('.iwb-editor-sel-bar.as-menu').count() await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.all"]').click() const cropAfterCtx = await dbg() check('裁剪中右键菜单「全选」同样被拦', menuShown === 1 && cropAfterCtx.selection === null && cropAfterCtx.ants === false) await drag2(box2.x + box2.width * 0.1, box2.y + box2.height * 0.1, box2.x + box2.width * 0.7, box2.y + box2.height * 0.7) check('裁剪框可拉出(确认按钮可见)', await page.locator('[data-action="confirmCrop"]').isVisible()) await page.locator('[data-action="confirmCrop"]').click() const cropped = await dbg() check('确认裁剪:尺寸更新且无旧坐标系选区/蚂蚁线残留', cropped.doc.w < 96 && cropped.doc.h < 64 && cropped.selection === null && cropped.ants === false, JSON.stringify(cropped.doc)) await page.keyboard.press('Delete') const afterCropDelete = await dbg() check('裁剪后 Delete 不按旧 bbox 误擦(层数不变、底图仍有像素)', afterCropDelete.layers.length === cropped.layers.length && (await pixel(5, 5)).base[3] > 0 && afterCropDelete.selection === null) // ---- 裁剪进历史链(v1.2 非破坏性):可撤销、可重做、不 flatten ---- const cropLayers = cropped.layers.map(l => l.id) await page.keyboard.press('Control+z') const undoneCrop = await dbg() check('裁剪可 Ctrl+Z:画布尺寸与图层结构都回到裁剪前', undoneCrop.doc.w === 96 && undoneCrop.doc.h === 64 && undoneCrop.layers.length === cropLayers.length && cropLayers.every(id => undoneCrop.layers.some(l => l.id === id)), 'doc=' + JSON.stringify(undoneCrop.doc) + ' layers=' + undoneCrop.layers.map(l => l.id).join(',')) check('裁剪撤销后底图像素完整回填', (await pixel(5, 5)).base[3] > 0) await page.keyboard.press('Control+Shift+z') const redoneCrop = await dbg() check('裁剪可重做:尺寸回到裁剪后', redoneCrop.doc.w === cropped.doc.w && redoneCrop.doc.h === cropped.doc.h, JSON.stringify(redoneCrop.doc)) // ---- 还原原图的「尺寸复位」分支:必须走统一重绘,摘要/蚂蚁线才跟着走 ---- // (该分支会 setupCanvas + 清历史,此前只调 updateAllUI,摘要停留在裁剪后尺寸) const cropSummary = await summaryText() await page.locator('[data-action="reset"]').click() const restoredDoc = await dbg() const restoredSummary = await summaryText() check('还原原图复位尺寸后:输出摘要即时跟随(不停留在裁剪后尺寸)', restoredDoc.doc.w === 96 && restoredDoc.doc.h === 64 && /原尺寸 96×64/.test(restoredSummary) && cropSummary !== restoredSummary, cropSummary + ' → ' + restoredSummary) check('还原原图复位尺寸后蚂蚁线已停、选区已清', restoredDoc.ants === false && !restoredDoc.selection) // ---- v1.2 选项栏:按工具出参数,形状线宽与画笔解耦 ---- await page.locator('.iwb-editor-tool[data-tool="brush"]').click() check('画笔选项栏:大小 / 硬度 / 透明三个参数都在', (await page.locator('.iwb-editor-optionbar-body [data-opt="brushSize"]').count()) >= 2 && (await page.locator('.iwb-editor-optionbar-body [data-opt="brushHardness"]').count()) === 1 && (await page.locator('.iwb-editor-optionbar-body [data-opt="brushOpacity"]').count()) === 1) const brushSizeBefore = (await dbg()).toolOptions.brushSize await page.locator('.iwb-editor-tool[data-tool="rect"]').click() check('矩形选项栏:线宽 + 描边/实心', (await page.locator('.iwb-editor-optionbar-body [data-opt="shapeLineWidth"]').count()) >= 2 && (await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"]').count()) === 1) await page.locator('.iwb-editor-optionbar-body input[type="number"][data-opt="shapeLineWidth"]').fill('12') const optAfterLw = (await dbg()).toolOptions check('选项栏改线宽:只改形状线宽,画笔大小不受影响(已解耦)', optAfterLw.shapeLineWidth === 12 && optAfterLw.brushSize === brushSizeBefore, JSON.stringify(optAfterLw)) const shapesBefore = (await dbg()).shapes.length const liveBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2, liveBox.x + liveBox.width * 0.5, liveBox.y + liveBox.height * 0.5) const shapesAfter = (await dbg()).shapes check('新画的矩形直接用选项栏里的线宽 12', shapesAfter.length === shapesBefore + 1 && shapesAfter[shapesAfter.length - 1].lw === 12, JSON.stringify(shapesAfter.slice(-1))) await page.keyboard.press('Control+z') // isTyping 修正:参数数字框里按 Ctrl+A / Delete 应该走画布命令,而不是被当打字吞掉 await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await page.locator('.iwb-editor-optionbar-body input[data-opt="feather"]').fill('3') await page.keyboard.press('Control+a') const selAfterCtrlA = await dbg() check('参数数字框里按 Ctrl+A 仍能全选(不再被当打字吞掉)', Boolean(selAfterCtrlA.selection) && selAfterCtrlA.selection.w === selAfterCtrlA.doc.w && selAfterCtrlA.selection.h === selAfterCtrlA.doc.h, JSON.stringify(selAfterCtrlA.selection)) await page.keyboard.press('Control+d') // ---- v1.2.2:手柄只在选择工具出现 / 高亮跟随绘制目标 / 选项栏快捷点 / 侧栏实心移除 ---- // 侧栏「实心」按钮移除(选项栏 rect 工具已有描边/实心切换) check('侧栏「实心」按钮已移除(选项栏承担该功能)', (await page.locator('[data-action="toggleFill"]').count()) === 0) // 快捷点:画笔大小 await page.locator('.iwb-editor-tool[data-tool="brush"]').click() check('画笔选项栏有 4 个大小快捷点(16/24/32 已按用户裁定移除)', (await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"]').count()) === 4) await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"][data-value="12"]').click() check('点快捷点 12:笔刷大小即时生效且选项栏数字框同步', (await dbg()).toolOptions.brushSize === 12 && await page.evaluate(() => { const n = document.querySelector('.iwb-editor-optionbar-body input[type="number"][data-opt="brushSize"]') return n && Number(n.value) === 12 })) // 快捷点:矢量描边 await page.locator('.iwb-editor-tool[data-tool="arrow"]').click() check('箭头选项栏有 7 个线宽快捷点', (await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"]').count()) === 7) await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"][data-value="6"]').click() check('点线宽快捷点 6:shapeLineWidth 即时生效', (await dbg()).toolOptions.shapeLineWidth === 6) // 高亮跟随绘制目标:画一笔后面板选中层 == 画笔目标层 await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await drag2(liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.75, liveBox.x + liveBox.width * 0.65, liveBox.y + liveBox.height * 0.85) const syncDbg = await dbg() check('画笔落笔后面板高亮层 == 绘制目标层(不再「没选中却能画」)', syncDbg.selectedLayerId === syncDbg.activeLayerId, 'selected=' + syncDbg.selectedLayerId + ' active=' + syncDbg.activeLayerId) // 变换手柄只在 select 工具出现:画笔态 overlay 无手柄像素,切到选择工具后出现 const overlayAlpha = () => page.evaluate(() => { const c = document.querySelector('.iwb-editor-crop-overlay') if (!c) return -1 const cx = c.getContext('2d') const d = cx.getImageData(0, 0, c.width, c.height).data let n = 0 for (let i = 3; i < d.length; i += 4) if (d[i] > 0) n++ return n }) check('画笔工具下选中层不画变换手柄(overlay 干净)', (await overlayAlpha()) === 0) await page.locator('.iwb-editor-tool[data-tool="select"]').click() check('切到选择工具后变换框/手柄出现(overlay 有像素)', (await overlayAlpha()) > 0) await page.keyboard.press('Escape') // 清选中,避免影响后续 // 裁剪:Esc 取消 / Enter 确认 await page.locator('.iwb-editor-tool[data-tool="crop"]').click() await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15, liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6) check('拉出裁剪框后选项栏显示尺寸摘要', (await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) !== '--') await page.keyboard.press('Escape') check('Esc 取消裁剪(摘要复位为 --)', (await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) === '--') await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15, liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6) const docBeforeEnter = (await dbg()).doc await page.keyboard.press('Enter') const docAfterEnter = (await dbg()).doc check('Enter 确认裁剪(画布尺寸变小、与按钮确认等效)', docAfterEnter.w < docBeforeEnter.w && docAfterEnter.h < docBeforeEnter.h, JSON.stringify(docBeforeEnter) + ' → ' + JSON.stringify(docAfterEnter)) await page.keyboard.press('Control+z') // ---- v1.2.8:底部浮动工具栏(Figma 风格,用户裁定 2026-11-04) ---- check('工具栏移入画布容器、横排悬浮底部居中(不再在顶栏)', await page.evaluate(() => { const wrap = document.querySelector('.iwb-editor-canvas-wrap') const tools = wrap && wrap.querySelector(':scope > .iwb-editor-tools') if (!tools) return false const w = tools.getBoundingClientRect(), c = wrap.getBoundingClientRect() return w.height < w.width && Math.abs((w.left + w.right) / 2 - (c.left + c.right) / 2) <= 8 && c.bottom - w.bottom <= 30 && !document.querySelector('.iwb-editor-header > .iwb-editor-tools') })) check('适应窗口后图片底边不被工具条遮挡', await page.evaluate(() => { const img = document.querySelector('.iwb-editor-layer-canvas') const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools') if (!img || !tools) return false const i = img.getBoundingClientRect(), t = tools.getBoundingClientRect() return i.bottom <= t.top + 2 })) // ---- v1.2.3:橡皮修复 / 钢笔描边实心 / 顶栏输出组右置 ---- // 顶栏输出组(输出+下载+新建+覆盖+退出)贴最右(header 右内边距 12px) check('顶栏输出/导出按钮组贴最右侧(用户裁定 2026-11-04)', await page.evaluate(() => { const hdr = document.querySelector('.iwb-editor-header') const ex = document.querySelector('.iwb-editor-header > .iwb-editor-export-actions') const hist = document.querySelector('.iwb-editor-header > .iwb-editor-history') if (!hdr || !ex || !hist) return false const h = hdr.getBoundingClientRect(), e = ex.getBoundingClientRect() return h.right - e.right <= 14 && e.left > hist.getBoundingClientRect().right })) // 橡皮:1.2.2 回归 —— events.js 少 import getActiveLayer,一按下就 ReferenceError,表现为「橡皮不能擦」 // 注意 pixel() 探针要的是图片坐标,不是屏幕坐标:liveBox 上的比例 = 图片上的比例 const IMG = { x: Math.round((await dbg()).doc.w * 0.42), y: Math.round((await dbg()).doc.h * 0.5) } const probe = (id) => page.evaluate(({ id, x, y }) => window.__iwbEditor.__debug().pixel(id, x, y), { id, x: IMG.x, y: IMG.y }) await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5, liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5) const stampLayerId = (await dbg()).activeLayerId const stampPx = await probe(stampLayerId) const stampBasePx = await probe('base') check('画笔落笔自动落「标注」层且该点有像素', stampPx && stampPx[3] > 0, 'layer=' + stampLayerId + ' px=' + JSON.stringify(stampPx)) // 回归(2026-11-04 用户反馈):首笔自动建层时新 canvas 没套视图样式, // 以原始像素尺寸贴在 stack 原点 → 第一笔显示错位,滚轮缩放后才正常 check('首笔自动建的层立刻获得视图样式(尺寸/偏移与原图层一致,不再裸贴原点)', await page.evaluate((baseId) => { const cs = Array.from(document.querySelectorAll('.iwb-editor-layer-canvas')) const base = cs.find(c => c.style.width && parseFloat(c.style.left) > 0) const fresh = cs[cs.length - 1] return base && fresh && fresh.style.width === base.style.width && fresh.style.left === base.style.left && fresh.style.top === base.style.top }, stampLayerId)) await page.locator('.iwb-editor-tool[data-tool="eraser"]').click() await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5, liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5) const erasedPx = await probe(stampLayerId) const basePxAfterErase = await probe('base') check('橡皮沿同一笔迹擦除(不抛错、目标层挖空、base 原样)', erasedPx && erasedPx[3] === 0 && JSON.stringify(basePxAfterErase) === JSON.stringify(stampBasePx), 'erased=' + JSON.stringify(erasedPx)) await page.keyboard.press('Control+z') // 钢笔描边/实心切换(penFill 默认实心,只对闭合路径生效) await page.locator('.iwb-editor-tool[data-tool="pen"]').click() check('钢笔选项栏有 描边/实心 切换', (await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2) await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="pen"]').click() const penFillOff = (await dbg()).toolOptions.penFill === false await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="pen"]').click() check('钢笔样式切换写回 penFill(默认实心 → 描边 → 实心)', penFillOff && (await dbg()).toolOptions.penFill === true) // 橡皮兜底:只剩锁定的原图时用橡皮 → 明确提示而不是无声失败 await page.locator('[data-action="reset"]').click() const layersAfterReset = (await dbg()).layers.length await page.locator('.iwb-editor-tool[data-tool="eraser"]').click() await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5, liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5) const toastText = await page.locator('.iwb-editor-toast').textContent() check('原图锁定且无标注层时用橡皮:提示「先画再擦」且不建层', layersAfterReset === 1 && (await dbg()).layers.length === 1 && toastText.indexOf('可擦') >= 0, 'layers=' + layersAfterReset + ' toast=' + toastText) await page.keyboard.press('Control+z') // 撤销还原,恢复图层结构 // ---- v1.2.4:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ---- check('「更多」菜单已移除;顶栏只留顺序/视图命令,图层新建/导入/合并在图层面板标题栏', await page.evaluate(() => { const q = (s) => Boolean(document.querySelector(s)) const hdrCmds = document.querySelectorAll('.iwb-editor-header .iwb-editor-commands .iwb-editor-layer-btn').length const titleBar = document.querySelector('.iwb-editor-layer-panel-header') const addBtns = titleBar ? titleBar.querySelectorAll('.iwb-editor-layer-add-btn').length : 0 const hdrAdd = document.querySelector('.iwb-editor-header [data-action="addBlankLayer"], .iwb-editor-header [data-action="addBitmapLayer"]') return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') && hdrCmds === 4 && !hdrAdd && addBtns === 4 && q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') && q('.iwb-editor-layer-panel-header [data-action="addBitmapLayer"]') && q('.iwb-editor-layer-panel-header [data-action="mergeLayers"]') && q('.iwb-editor-layer-panel-header [data-action="mergeVisible"]') && q('.iwb-editor-header [data-action="zoomFit"]') && q('.iwb-editor-header [data-action="togglePanels"]') })) check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => { const svg = document.querySelector('.iwb-editor-header [data-action="reset"] svg') if (!svg) return false const paths = svg.querySelectorAll('path').length const polys = Array.from(svg.querySelectorAll('polyline')).map(p => p.getAttribute('points')).join('|') return paths >= 4 && polys.indexOf('3 6 5 6 21 6') < 0 })) check('适应窗口按钮真的生效(放大后点它回到 fit 基线并居中)', await (async () => { await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click() await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click() const zoomed = (await dbg()).zoom await page.locator('.iwb-editor-header [data-action="zoomFit"]').click() const fitted = (await dbg()).zoom return zoomed > 1 && Math.abs(fitted - 1) < 0.001 })()) check('PS 快捷键:V/M/L/B/E/P/T/U/C/I/H 切工具', await (async () => { // 先点一下工具按钮,保证焦点不在输入框里(isTyping() 会吞掉无修饰键快捷键) await page.locator('.iwb-editor-tool[data-tool="select"]').click() const seq = [['v', 'select'], ['m', 'marquee'], ['l', 'lasso'], ['b', 'brush'], ['e', 'eraser'], ['p', 'pen'], ['t', 'text'], ['u', 'rect'], ['c', 'crop'], ['i', 'picker'], ['h', 'hand']] for (const [k, tool] of seq) { await page.keyboard.press(k) if ((await dbg()).tool !== tool) return false } return true })()) check('Shift+U 在 矩形/圆形/箭头 间循环(PS 同类工具循环)', await (async () => { await page.keyboard.press('u') await page.keyboard.press('Shift+u') const a = (await dbg()).tool await page.keyboard.press('Shift+u') const b = (await dbg()).tool return a === 'circle' && b === 'arrow' })()) check('Tab 收起 / 展开侧栏(PS 习惯)', await (async () => { await page.keyboard.press('Tab') const collapsed = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed')) await page.keyboard.press('Tab') const restored = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed')) return collapsed === true && restored === false })()) check('[ / ] 增减画笔大小(PS 习惯,画笔橡皮共用)', await (async () => { await page.keyboard.press(']') // 3 → 5? 起始值不定,只验方向与 clamp const up = (await dbg()).toolOptions.brushSize await page.keyboard.press('[') await page.keyboard.press('[') const down = (await dbg()).toolOptions.brushSize return up > down && down >= 1 && up <= 300 })()) check('Ctrl+1 = 100% 实际像素 / Ctrl+0 = 适应窗口', await (async () => { await page.keyboard.press('Control+1') const d1 = await dbg() // S.zoom 是相对 fitW 的倍数:100% 实际像素 = doc.w / fit.w(小图会被放大铺满,所以可能 < 1) const expect = d1.doc.w / d1.fit.w const okActual = Math.abs(d1.zoom - expect) < 0.02 await page.keyboard.press('Control+0') return okActual && Math.abs((await dbg()).zoom - 1) < 0.001 })()) await page.locator('.iwb-editor-tool[data-tool="select"]').click() check('选择工具的选项栏里有 全选/反选/取消 三个命令(竖工具条不再有)', await page.evaluate(() => { const cmds = document.querySelectorAll('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more]') const keys = Array.from(cmds).map(b => b.dataset.more).join(',') return cmds.length === 3 && keys === 'sel.all,sel.invert,sel.none' && !document.querySelector('.iwb-editor-tools .iwb-editor-selcmd') })) await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more="sel.all"]').click() const selAllDbg = await dbg() check('点选项栏「全选」= Ctrl+A(选区生成)', Boolean(selAllDbg.selection && selAllDbg.selection.w === selAllDbg.doc.w), JSON.stringify(selAllDbg.selection)) await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more="sel.none"]').click() check('点选项栏「取消选区」清掉选区', !(await dbg()).selection) // 画一个矩形 → 切选择工具点中它 → 选项栏就地改 描边/实心 + 线宽 await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2, liveBox.x + liveBox.width * 0.45, liveBox.y + liveBox.height * 0.45) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.3) await page.waitForTimeout(150) let selShapeDbg = await dbg() check('选择工具选中矩形后选项栏出该形状的参数', selShapeDbg.selectedShapeId && (await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="rect"]').count()) === 2 && (await page.locator('.iwb-editor-optionbar-body [data-opt="shapeLineWidth"]').count()) >= 2, 'selected=' + selShapeDbg.selectedShapeId) await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').click() selShapeDbg = await dbg() check('选中矩形就地切「实心」(对象与按钮激活态一致)', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].fill === true && await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active')), JSON.stringify(selShapeDbg.shapes.slice(-1))) await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="rect"]').click() selShapeDbg = await dbg() check('再切回「描边」(按钮激活态跟随)', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].fill === false && await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="rect"]').classList.contains('active'))) await page.locator('.iwb-editor-optionbar-body input[type="number"][data-opt="shapeLineWidth"]').fill('9') await page.waitForTimeout(120) selShapeDbg = await dbg() check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9, JSON.stringify(selShapeDbg.shapes.slice(-1))) // Shift+X:选中形状切 描边/实心(PS 风格;数字框输完值直接按也必须生效) check('Shift+X 切换选中形状 描边/实心(对象与选项栏按钮同步)', await (async () => { await page.keyboard.press('Shift+x') const d = await dbg() const sh = d.shapes.find(s => s.id === d.selectedShapeId) const btnActive = await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active')) const flipped = sh && sh.fill === true && btnActive await page.keyboard.press('Shift+x') // 切回描边,恢复现场 const d2 = await dbg() const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId) return flipped && sh2 && sh2.fill === false })()) // 钢笔:闭合路径选中后同样可切描边/实心 await page.locator('.iwb-editor-tool[data-tool="pen"]').click() const pA = [liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.25] const pB = [liveBox.x + liveBox.width * 0.75, liveBox.y + liveBox.height * 0.25] const pC = [liveBox.x + liveBox.width * 0.75, liveBox.y + liveBox.height * 0.45] const pD = [liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.45] for (const [x, y] of [pA, pB, pC, pD]) await page.mouse.click(x, y) await page.mouse.click(pA[0], pA[1]) // 点回起点闭合 await page.waitForTimeout(120) const penShapeDbg = await dbg() check('钢笔闭合路径落成后自动回 V 并选中(v1.5 用户裁定)', Boolean(penShapeDbg.selectedShapeId) && penShapeDbg.tool === 'select' && penShapeDbg.shapes[penShapeDbg.shapes.length - 1].type === 'pen' && penShapeDbg.shapes[penShapeDbg.shapes.length - 1].closed === true, JSON.stringify({ sel: penShapeDbg.selectedShapeId, tool: penShapeDbg.tool, last: penShapeDbg.shapes.slice(-1) })) // 选中改为显式:切 V 再点路径内部 await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click((pA[0] + pC[0]) / 2, (pA[1] + pC[1]) / 2) await page.waitForTimeout(150) check('V 选中钢笔路径后选项栏有 描边/实心(pen 归属)', (await dbg()).selectedShapeId && (await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2, 'selected=' + (await dbg()).selectedShapeId) await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="pen"]').click() let penSelDbg = await dbg() check('选中钢笔路径就地切「描边」', penSelDbg.shapes[penSelDbg.shapes.length - 1].fill === false) await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="pen"]').click() penSelDbg = await dbg() check('再切回「实心」', penSelDbg.shapes[penSelDbg.shapes.length - 1].fill === true) // v1.5:钢笔节点编辑统一走 V 双击(用户裁定 2026-11-05),P 下双击不再进编辑 check('V 下双击钢笔进入节点编辑,P 下双击不进入', await (async () => { const dx = (pA[0] + pC[0]) / 2, dy = (pA[1] + pC[1]) / 2 await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.dblclick(dx, dy) await page.waitForTimeout(200) const inEdit = (await dbg()).penEditId await page.keyboard.press('Escape') await page.waitForTimeout(120) await page.locator('.iwb-editor-tool[data-tool="pen"]').click() await page.mouse.dblclick(dx, dy) await page.waitForTimeout(200) const underPen = (await dbg()).penEditId await page.locator('.iwb-editor-tool[data-tool="select"]').click() return inEdit && !underPen ? true : 'V=' + inEdit + ' P=' + underPen })()) // v1.5:文字输入完成(Enter)后自动回 V 并选中该文字(用户裁定 2026-11-05) check('文字输入完成后自动回 V 并选中,输入框已收起', await (async () => { const before = (await dbg()).texts.length await page.locator('.iwb-editor-tool[data-tool="text"]').click() await page.mouse.click(liveBox.x + liveBox.width * 0.14, liveBox.y + liveBox.height * 0.12) await page.waitForTimeout(150) const open = await page.evaluate(() => { const el = document.querySelector('.iwb-editor-text-input'); return el && el.style.display !== 'none' }) if (!open) return 'pre: 输入框没出现' await page.keyboard.type('V5') await page.keyboard.press('Enter') await page.waitForTimeout(260) const d = await dbg() const last = d.texts[d.texts.length - 1] const ok = d.tool === 'select' && d.texts.length === before + 1 && d.selectedTextId === (last && last.id) await page.keyboard.press('Escape') // 清掉选中 await page.keyboard.press('Control+z') // 撤掉这段文字,保持后续用例现场 await page.waitForTimeout(150) await page.locator('.iwb-editor-tool[data-tool="select"]').click() return ok ? true : 'tool=' + d.tool + ' texts=' + d.texts.length + ' selText=' + d.selectedTextId })()) // 吸管:选中矢量形状后按 I 取色,颜色必须写回对象(2026-11-04 用户反馈:切吸管后颜色只进画笔、形状不变) check('选中矢量形状后切吸管:选中态保留、取色写回形状、取完回到原工具', await (async () => { await page.locator('.iwb-editor-tool[data-tool="select"]').click() const selId = (await dbg()).selectedShapeId if (!selId) return 'pre: 没有选中形状' // 先换成一个可辨识的颜色,便于判断取色真的改了对象(v1.3:推荐色在弹层里,先点开色点) await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() await page.locator('.iwb-editor-color-pop .iwb-editor-color-panel-swatch[data-panel-color="#4488ff"]').click() await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起,别挡住后面的画布取色点 const before = (await dbg()).shapes.find(s => s.id === selId) if (!before || before.color !== '#4488ff') return 'pre: color=' + (before && before.color) await page.keyboard.press('i') // 切吸管 const d1 = await dbg() if (d1.tool !== 'picker' || d1.selectedShapeId !== selId) return 'picker: tool=' + d1.tool + ' sel=' + d1.selectedShapeId // 点画面左下角(原图实色区,避开形状本身) await page.mouse.click(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.85) await page.waitForTimeout(150) const d2 = await dbg() const after = d2.shapes.find(s => s.id === selId) const shapeBar = await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"], .iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="rect"]').count() return d2.tool === 'select' && after && after.color !== '#4488ff' && shapeBar > 0 ? true : 'post: tool=' + d2.tool + ' color=' + (after && after.color) + ' shapeBar=' + shapeBar })()) await page.keyboard.press('Control+z') // 撤销最后一次填充 await page.keyboard.press('Control+z') // 撤销钢笔路径 await page.keyboard.press('Control+z') // 撤销矩形线宽 // ---- v1.3:矢量/文字工具不再具备选择功能(用户裁定 2026-11-05)---- // 核心回归:在已有矩形范围内再拉一个矩形,必须新增图形,而不是把旧矩形拖走 check('矩形工具在已有矩形上按下 → 新建第二个矩形,并自动回 V 选中它(v1.5)', await (async () => { await page.locator('.iwb-editor-tool[data-tool="rect"]').click() const before = (await dbg()).shapes.length await drag2(liveBox.x + liveBox.width * 0.22, liveBox.y + liveBox.height * 0.22, liveBox.x + liveBox.width * 0.42, liveBox.y + liveBox.height * 0.42) const after = await dbg() const last = after.shapes[after.shapes.length - 1] return after.shapes.length === before + 1 && after.selectedShapeId === last.id && after.tool === 'select' ? true : 'shapes ' + before + '→' + after.shapes.length + ' sel=' + after.selectedShapeId + ' tool=' + after.tool })()) check('切到 矩形/文字/钢笔 都会清掉选中态(选中只属于 V 与临时吸管)', await (async () => { await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.3) await page.waitForTimeout(120) if (!(await dbg()).selectedShapeId) return 'pre: V 没选中形状' const cleared = [] for (const t of ['rect', 'text', 'pen']) { await page.locator(`.iwb-editor-tool[data-tool="${t}"]`).click() const d = await dbg() cleared.push(!d.selectedShapeId && !d.selectedTextId) } return cleared.every(Boolean) ? true : 'cleared=' + cleared.join(',') })()) // 拖调色器改颜色只记一步历史(以前每移动一步就 saveSnapshot,4K 图直接吃掉几百 MB) check('拖调色器改选中形状颜色:历史只增加 1 条', await (async () => { await page.keyboard.press('Escape') await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.3) await page.waitForTimeout(120) if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状' const h0 = (await dbg()).history await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() const sv = await page.locator('.iwb-color-sv').boundingBox() await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2) await page.mouse.down() await page.mouse.move(sv.x + sv.width * 0.9, sv.y + sv.height * 0.85, { steps: 20 }) await page.mouse.up() await page.waitForTimeout(150) const h1 = (await dbg()).history await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起 return h1 - h0 === 1 ? true : 'history ' + h0 + '→' + h1 })()) await page.keyboard.press('Escape') // 退出钢笔的半成品状态 await page.keyboard.press('Control+z') // 撤销拖动取色的那一步 await page.keyboard.press('Control+z') // 撤销上一步新建的矩形,恢复现场 // ---- v1.2.9:会话组(新建/覆盖/退出)移到顶栏最左 + 图层 PS 快捷键 ---- check('顶栏:标题最前 → 新建/覆盖/退出(统一中性色)→ 竖分隔 → 撤销组,右侧只剩 输出+导出', await page.evaluate(() => { const q = (s) => document.querySelector(s) const session = q('.iwb-editor-header > .iwb-editor-session') const title = q('.iwb-editor-header > .iwb-editor-title') const hist = q('.iwb-editor-header > .iwb-editor-history') const dl = q('.iwb-editor-header [data-action="download"]') if (!session || !title || !hist || !dl) return false const t = title.getBoundingClientRect(), s = session.getBoundingClientRect(), h = hist.getBoundingClientRect() const btns = Array.from(session.querySelectorAll('.iwb-editor-btn')).map(b => b.dataset.action).join(',') const bg = (sel) => getComputedStyle(q(sel)).backgroundColor const unified = bg('.iwb-editor-header .iwb-editor-btn-new') === bg('.iwb-editor-header .iwb-editor-btn-replace') && bg('.iwb-editor-header .iwb-editor-btn-replace') === bg('.iwb-editor-header .iwb-editor-btn-cancel') return btns === 'newNode,replace,cancel' && t.left < s.left && s.right < h.left && Boolean(q('.iwb-editor-header > .iwb-editor-divider')) && unified && dl.textContent.trim() === '导出' && !q('.iwb-editor-export-actions [data-action="newNode"]') })) check('画笔选项栏:推荐大小只留 4 个快捷点,硬度补 5 个快捷点且滑杆加宽', await (async () => { await page.locator('.iwb-editor-tool[data-tool="brush"]').click() const ok = await page.evaluate(() => { const body = document.querySelector('.iwb-editor-optionbar-body') if (!body) return false const size = body.querySelectorAll('[data-opt-preset="brushSize"]').length const hard = body.querySelectorAll('[data-opt-preset="brushHardness"]').length const wide = Boolean(body.querySelector('input[data-opt="brushHardness"].iwb-opt-range-wide')) return size === 4 && hard === 5 && wide }) await page.locator('.iwb-editor-tool[data-tool="select"]').click() return ok })()) // 按住 Alt 临时吸色(PS 手感):画笔下按住 Alt → 吸管 → 取色 → 松开回画笔 check('画笔按住 Alt 临时吸色,松开 Alt 回到画笔(可连续取色)', await (async () => { await page.locator('.iwb-editor-tool[data-tool="brush"]').click() const color0 = (await dbg()).color await page.keyboard.down('Alt') const d1 = await dbg() if (d1.tool !== 'picker' || !d1.altPicker) return 'down: tool=' + d1.tool + ' alt=' + d1.altPicker // 取色:点画面右下角(实色区) await page.mouse.click(liveBox.x + liveBox.width * 0.8, liveBox.y + liveBox.height * 0.85) await page.waitForTimeout(120) const d2 = await dbg() // 取色后仍停在吸管(Alt 还按着),颜色已变 if (d2.tool !== 'picker') return 'pick: tool=' + d2.tool if (d2.color === color0) return 'pick: color 未变 ' + d2.color await page.keyboard.up('Alt') await page.waitForTimeout(180) const d3 = await dbg() return d3.tool === 'brush' && !d3.altPicker ? true : 'up: tool=' + d3.tool + ' alt=' + d3.altPicker })()) // Shift+X:选中形状切 描边/实心(PS 风格,用户裁定 2026-11-04 晚) // 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层 // 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z) check('图层 PS 快捷键:Ctrl+[/] 上下移一层、Ctrl+Shift+[/] 置底/置顶', await (async () => { const before = (await dbg()).layers.length await page.keyboard.press('Control+Shift+n') // 新建空白图层并选中(z 最高) const d1 = await dbg() const newId = d1.selectedLayerId if (!newId || d1.layers.length !== before + 1) return false const zOf = (d) => { const bits = d.layers.map(l => ({ id: l.id, z: l.z })) const vec = d.shapes.map(s => ({ id: s.id, z: s.z })) const all = bits.concat(vec) const me = all.find(u => u.id === newId) return { me: me && me.z, max: Math.max(...all.map(u => u.z)), minNonBase: Math.min(...all.filter(u => u.id !== 'base').map(u => u.z)) } } if (zOf(d1).me !== zOf(d1).max) return false // 新层此刻在最上 await page.keyboard.press('Control+[') // 下移一层 → 不再最上 const d2 = await dbg() if (zOf(d2).me >= zOf(d2).max) return false await page.keyboard.press('Control+]') // 上移一层 → 回到最上 const d3 = await dbg() if (zOf(d3).me !== zOf(d3).max) return false await page.keyboard.press('Control+Shift+[') // 置底 → base 之上第一格 const d4 = await dbg() if (zOf(d4).me !== zOf(d4).minNonBase) return false await page.keyboard.press('Control+Shift+]') // 置顶 → 回到最上 const d5 = await dbg() return zOf(d5).me === zOf(d5).max })()) check('图层 PS 快捷键:Alt+[/] 向下/向上选择图层', await (async () => { const d1 = await dbg() const bits = d1.layers.map(l => ({ id: l.id, z: l.z })) const topUnit = bits.concat(d1.shapes.map(s => ({ id: s.id, z: s.z }))).sort((a, b) => b.z - a.z)[0] const topId = topUnit.id if (d1.selectedLayerId !== topId) return 'pre: sel=' + d1.selectedLayerId + ' top=' + topId + ' bits=' + JSON.stringify(bits) + ' shapes=' + JSON.stringify(d1.shapes) await page.keyboard.press('Alt+[') // 向下选 → 选到下一个单元(矩形 shape) const d2 = await dbg() if (!d2.selectedShapeId || d2.selectedLayerId !== null) return 'down: selLayer=' + d2.selectedLayerId + ' selShape=' + d2.selectedShapeId await page.keyboard.press('Alt+]') // 向上选 → 回到位图新层 const d3 = await dbg() if (d3.selectedLayerId !== topId || d3.selectedShapeId) return 'up: selLayer=' + d3.selectedLayerId + ' selShape=' + d3.selectedShapeId return true })()) check('Delete 删除选中的位图图层(PS 习惯)', await (async () => { const d0 = await dbg() const before = d0.layers.length await page.keyboard.press('Delete') const d = await dbg() if (d.layers.length !== before - 1) return 'layers ' + before + '→' + d.layers.length + ' sel=' + d0.selectedLayerId + ' selShape=' + d0.selectedShapeId + ' tool=' + d0.tool + ' toast=' + await page.locator('.iwb-editor-toast').textContent() return d.selectedLayerId === null ? true : 'sel 未清空: ' + d.selectedLayerId })()) // ---- v1.6:笔刷环即时反馈(按 ] / [ 不必再动鼠标) ---- check('笔刷环:按 ] 后鼠标不动,环立刻变大', await (async () => { await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await page.mouse.move(liveBox.x + liveBox.width * 0.5, liveBox.y + liveBox.height * 0.5) await page.waitForTimeout(150) const ringWidth = () => page.evaluate(() => { const c = document.querySelector('.iwb-editor-cursor-overlay') const d = c.getContext('2d').getImageData(0, 0, c.width, c.height).data let minX = 1e9, maxX = -1 for (let y = 0; y < c.height; y++) { for (let x = 0; x < c.width; x++) { if (d[(y * c.width + x) * 4 + 3] > 8) { if (x < minX) minX = x; if (x > maxX) maxX = x } } } return maxX < 0 ? 0 : maxX - minX + 1 }) const w0 = await ringWidth() const s0 = (await dbg()).toolOptions.brushSize for (let i = 0; i < 3; i++) await page.keyboard.press(']') await page.waitForTimeout(140) const w1 = await ringWidth() const s1 = (await dbg()).toolOptions.brushSize for (let i = 0; i < 3; i++) await page.keyboard.press('[') await page.waitForTimeout(120) return w0 > 0 && s1 > s0 && w1 > w0 ? true : 'w ' + w0 + '→' + w1 + ' size ' + s0 + '→' + s1 })()) // ---- v1.6:图层合并(向下合并 / 多选合并 / 合并可见) ---- // 两笔分别落在左右半区,合并后同一层里两半都要有像素,才算真合并 const strokeHalves = async (id, w, h) => page.evaluate(({ id, w, h }) => { const d = window.__iwbEditor.__debug() return { left: d.alphaIn(id, 0, 0, w / 2, h), right: d.alphaIn(id, w / 2, 0, w, h) } }, { id, w, h }) check('图层合并:Ctrl+E 向下合并两层(两笔都在),Ctrl+Z 连像素一起回退', await (async () => { await page.keyboard.press('Escape') await page.keyboard.press('Control+d') await page.locator('.iwb-editor-tool[data-tool="brush"]').click() const doc = (await dbg()).doc const n0 = (await dbg()).layers.length await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(140) const lowerId = (await dbg()).activeLayerId await drag2(liveBox.x + liveBox.width * 0.22, liveBox.y + liveBox.height * 0.62, liveBox.x + liveBox.width * 0.32, liveBox.y + liveBox.height * 0.72) await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(140) const upperId = (await dbg()).activeLayerId await drag2(liveBox.x + liveBox.width * 0.66, liveBox.y + liveBox.height * 0.62, liveBox.x + liveBox.width * 0.76, liveBox.y + liveBox.height * 0.72) const d1 = await dbg() if (d1.layers.length !== n0 + 2) return 'pre layers ' + d1.layers.length + ' expect ' + (n0 + 2) await page.keyboard.press('Control+e') await page.waitForTimeout(320) const d2 = await dbg() if (d2.layers.length !== n0 + 1) return 'merge layers ' + d2.layers.length + ' expect ' + (n0 + 1) const px = await strokeHalves(d2.activeLayerId, doc.w, doc.h) if (!(px.left > 0 && px.right > 0)) return 'pixels ' + JSON.stringify(px) await page.keyboard.press('Control+z') await page.waitForTimeout(320) const d3 = await dbg() if (d3.layers.length !== n0 + 2) return 'undo layers ' + d3.layers.length + ' expect ' + (n0 + 2) // 撤销必须把两笔还给各自原来的层,而不是留一份空层 const backLower = await strokeHalves(lowerId, doc.w, doc.h) const backUpper = await strokeHalves(upperId, doc.w, doc.h) if (!(backLower.left > 0 && backUpper.right > 0)) { return 'undo pixels lower=' + JSON.stringify(backLower) + ' upper=' + JSON.stringify(backUpper) } return true })()) check('图层多选合并:⌘/Ctrl 点击两项后合并按钮合成一层', await (async () => { const d0 = await dbg() const n0 = d0.layers.length const items = page.locator('.iwb-editor-layer-list .iwb-layer-item') await items.nth(0).click() await items.nth(1).click({ modifiers: [process.platform === 'darwin' ? 'Meta' : 'Control'] }) await page.waitForTimeout(220) const dm = await dbg() const marked = await page.locator('.iwb-layer-item.multi').count() if (dm.layerMulti.length !== 2 || marked !== 2) return 'multi ' + JSON.stringify(dm.layerMulti) + ' dom=' + marked await page.locator('[data-action="mergeLayers"]').click() await page.waitForTimeout(320) const d1 = await dbg() return d1.layers.length === n0 - 1 && d1.layerMulti.length === 0 ? true : 'after ' + d1.layers.length + '/' + n0 + ' multi=' + d1.layerMulti.length })()) check('向下合并到「原图」:笔迹写进 base,Ctrl+Z 复原像素', await (async () => { // 归一到「只剩原图」:先显示所有隐藏层,再合并可见 let d = await dbg() for (const l of d.layers) { if (!l.visible) { await page.locator('.iwb-layer-vis[data-vis-id="' + l.id + '"]').click() await page.waitForTimeout(90) } } d = await dbg() if (d.layers.length > 1) { await page.keyboard.press('Control+Shift+e') await page.waitForTimeout(320) d = await dbg() } if (d.layers.length !== 1 || d.layers[0].id !== 'base') return 'normalize: ' + JSON.stringify(d.layers) const doc = d.doc const cx = Math.round(doc.w * 0.5), cy = Math.round(doc.h * 0.5) const pxAt = () => page.evaluate(([x, y]) => window.__iwbEditor.__debug().pixel('base', x, y), [cx, cy]) const p0 = await pxAt() await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await page.locator('.iwb-editor-optionbar-body input.iwb-opt-num[data-opt="brushSize"]').fill('40') await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(140) // 斜穿中心的大笔画,避免采样点落空 await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.35, liveBox.x + liveBox.width * 0.85, liveBox.y + liveBox.height * 0.65) const d1 = await dbg() if (d1.layers.length !== 2) return 'pre layers ' + d1.layers.length await page.keyboard.press('Control+e') await page.waitForTimeout(340) const d2 = await dbg() if (d2.layers.length !== 1 || d2.layers[0].id !== 'base') return 'merge layers ' + JSON.stringify(d2.layers.map(l => l.id)) const p1 = await pxAt() if (!p1 || !p0 || (p1[0] === p0[0] && p1[1] === p0[1] && p1[2] === p0[2])) { return 'base 像素未变 ' + JSON.stringify([p0, p1]) } await page.keyboard.press('Control+z') await page.waitForTimeout(340) const p2 = await pxAt() const same = p2 && p0 && p2[0] === p0[0] && p2[1] === p0[1] && p2[2] === p0[2] return same ? true : 'undo 像素 ' + JSON.stringify([p0, p2]) })()) check('合并可见图层:隐藏层原样保留,可见层合成一层', await (async () => { // 保证至少 2 个可见层 let d = await dbg() while (d.layers.filter(l => l.visible).length < 2) { await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(140) d = await dbg() } // 再新建一层并隐藏它,验证它不参与合并、也不会被删 await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(160) const hiddenId = (await dbg()).activeLayerId await page.locator('.iwb-layer-vis[data-vis-id="' + hiddenId + '"]').click() await page.waitForTimeout(180) const visibleBefore = (await dbg()).layers.filter(l => l.visible).length await page.keyboard.press('Control+Shift+e') await page.waitForTimeout(360) const d1 = await dbg() const stillHidden = d1.layers.some(l => l.id === hiddenId && l.visible === false) const visibleAfter = d1.layers.filter(l => l.visible).length return stillHidden && visibleAfter === 1 && visibleBefore >= 2 ? true : 'hidden=' + stillHidden + ' visible ' + visibleBefore + '→' + visibleAfter + ' layers=' + d1.layers.length })()) check('图层面板:缩略图画出了图层内容(不是空框)', await (async () => { await page.waitForTimeout(260) // 缩略图有 90ms 合批延迟 const n = await page.evaluate(() => { const cv = document.querySelector('.iwb-layer-thumb canvas[data-thumb-id="base"]') if (!cv) return -1 const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data let k = 0 for (let i = 3; i < d.length; i += 4) if (d[i] > 8) k++ return k }) return n > 10 ? true : '缩略图不透明像素=' + n })()) check('图层重命名:双击名字进入编辑,Enter 提交后生效', await (async () => { await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(180) const id = (await dbg()).activeLayerId const nameEl = page.locator('.iwb-layer-name[data-name-id="' + id + '"]') await nameEl.click() await nameEl.click() // 400ms 内两次按下 → 自算双击(点一下会重绘面板) const input = page.locator('.iwb-layer-name-input') if (!(await input.count())) return '未进入重命名态' await input.fill('主体层') await input.press('Enter') await page.waitForTimeout(180) const nm = (await dbg()).layers.find(l => l.id === id) return nm && nm.name === '主体层' && !(await page.locator('.iwb-layer-name-input').count()) ? true : '名字=' + (nm && nm.name) })()) check('图层不透明度:滑杆到 40% 立刻生效,一次拖动只记 1 条撤销', await (async () => { await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(180) const id = (await dbg()).activeLayerId const row = await page.locator('.iwb-layer-item[data-layer-id="' + id + '"] .iwb-layer-op-row').count() if (!row) return '选中项下没有不透明度行' const h0 = (await dbg()).history for (const v of [70, 55, 40]) { await page.evaluate((val) => { const el = document.querySelector('.iwb-layer-opacity') el.value = String(val) el.dispatchEvent(new Event('input', { bubbles: true })) }, v) } const d = await dbg() const l = d.layers.find(x => x.id === id) const val = await page.locator('.iwb-layer-op-val').first().textContent() if (!l) return '图层丢失' if (Math.abs(l.opacity - 0.4) > 0.001) return 'opacity=' + l.opacity if (Math.abs(l.cssOpacity - 0.4) > 0.001) return 'cssOpacity=' + l.cssOpacity + '(画面没跟上)' if ((val || '').trim() !== '40%') return '标值=' + val if (d.history - h0 !== 1) return '撤销条数=' + (d.history - h0) + '(一次拖动应只拍 1 张快照)' return true })()) check('图层不透明度:Ctrl+Z 回到 100%,画面同步', await (async () => { await page.keyboard.press('Control+z') await page.waitForTimeout(320) const d = await dbg() const l = d.layers[d.layers.length - 1] return l && Math.abs(l.opacity - 1) < 0.001 && Math.abs(l.cssOpacity - 1) < 0.001 ? true : 'opacity=' + (l && l.opacity) + ' css=' + (l && l.cssOpacity) })()) // ---------- v1.8.3 图层面板交互:滑杆真能拖 + 图层真能拖排 ---------- // 面板顺序(最上层在前)与每层 id,供排序用例断言 const panelIds = () => page.evaluate(() => [...document.querySelectorAll('.iwb-layer-item')].map(el => el.dataset.layerId)) const zOf = (id) => page.evaluate((lid) => { const d = window.__iwbEditor.__debug() const l = d.layers.find(x => x.id === lid) return l ? l.z : null }, id) /** 真实鼠标把第 from 行拖到第 to 行中线之上/之下(below=true 表示越过中线) */ async function dragRow(from, to, below = true) { const a = page.locator('.iwb-layer-item').nth(from) const b = page.locator('.iwb-layer-item').nth(to) const ba = await a.boundingBox() const bb = await b.boundingBox() const x = ba.x + 44 // 落在缩略图/名字区域,避开左侧显示按钮 const y = ba.y + 10 // 行首部:选中行的下半截是不透明度滑杆,别往那儿按 await page.mouse.move(x, y) await page.mouse.down() await page.mouse.move(x, y + 8, { steps: 3 }) // 先越过 4px 阈值 await page.mouse.move(bb.x + 44, below ? bb.y + bb.height - 3 : bb.y + 3, { steps: 10 }) await page.mouse.up() await page.waitForTimeout(200) } check('图层不透明度:真实鼠标拖动滑块,数值与画面一路跟随(不再只能点)', await (async () => { await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(180) const id = (await dbg()).activeLayerId const box = await page.locator('.iwb-layer-item[data-layer-id="' + id + '"] .iwb-layer-opacity').boundingBox() if (!box) return '选中项下没有不透明度滑杆' const y = box.y + box.height / 2 // 从 85% 处按下,连续拖到 20%:被整项 draggable 抢事件时只有按下那一下生效,之后纹丝不动 await page.mouse.move(box.x + box.width * 0.85, y) await page.mouse.down() const seen = [] for (const f of [0.7, 0.5, 0.35, 0.2]) { await page.mouse.move(box.x + box.width * f, y, { steps: 4 }) const l = (await dbg()).layers.find(x => x.id === id) seen.push(l ? l.opacity : -1) } await page.mouse.up() await page.waitForTimeout(120) const l = (await dbg()).layers.find(x => x.id === id) if (!l) return '图层丢失' const follows = seen.every((v, i) => i === 0 || v < seen[i - 1] - 0.01) if (!follows) return '拖动中数值没跟随 ' + JSON.stringify(seen.map(v => Math.round(v * 100))) if (!(l.opacity < 0.35)) return '最终 opacity=' + l.opacity if (Math.abs(l.cssOpacity - l.opacity) > 0.001) return '画面没跟上 css=' + l.cssOpacity return true })()) check('图层拖动排序:向下拖过下一行中线真的换位,z 同步、一次拖动一条撤销', await (async () => { // 保证至少 3 个可移动层,才有「换位」可看 while ((await panelIds()).length < 4) { await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(140) } const before = await panelIds() const movedId = before[0], targetId = before[1] const h0 = (await dbg()).history await dragRow(0, 1, true) const after = await panelIds() if (after[0] !== targetId || after[1] !== movedId) return '没换位 ' + before.join(',') + ' → ' + after.join(',') const zMoved = await zOf(movedId), zTarget = await zOf(targetId) if (!(zMoved < zTarget)) return 'z 没同步 moved=' + zMoved + ' target=' + zTarget const h1 = (await dbg()).history if (h1 - h0 !== 1) return '撤销条数=' + (h1 - h0) + '(一次拖动应只拍 1 张快照)' await page.keyboard.press('Control+z') await page.waitForTimeout(280) const back = await panelIds() return back.join(',') === before.join(',') ? true : 'Ctrl+Z 未复原 ' + back.join(',') })()) check('图层拖动排序:拖到最底停在「原图」之上,原图永远压在最底层', await (async () => { const before = await panelIds() const movedId = before[0] const baseKey = before[before.length - 1] if (baseKey !== 'base') return '原图不在面板最底:' + before.join(',') await dragRow(0, before.length - 1, true) // 一路拖到底(原图那一行) const after = await panelIds() if (after[after.length - 1] !== 'base') return '原图没留在最底 ' + after.join(',') if (after[after.length - 2] !== movedId) return '没落到原图之上 ' + after.join(',') const zBase = await zOf('base') return zBase === 0 ? true : '原图 z=' + zBase + '(应恒为 0)' })()) check('图层拖动排序:位移不足 4px 算点击(不误判成拖动,顺序不变)', await (async () => { const before = await panelIds() const a = await page.locator('.iwb-layer-item').nth(0).boundingBox() await page.mouse.move(a.x + 44, a.y + a.height / 2) await page.mouse.down() await page.mouse.move(a.x + 44, a.y + a.height / 2 + 2, { steps: 2 }) await page.mouse.up() await page.waitForTimeout(160) const after = await panelIds() if (after.join(',') !== before.join(',')) return '顺序被改 ' + before.join(',') + ' → ' + after.join(',') // 顺手确认这次按下仍然完成了「选中该层」 const sel = await page.evaluate(() => window.__iwbEditor.__debug().selectedLayerId) return sel === before[0] ? true : '没选中 selectedLayerId=' + sel })()) check('图层拖动排序:焦点在工具栏按钮上时也能拖(blur 兜底不误伤拖动)', await (async () => { // 回归:window 捕获阶段的 blur 会连子元素失焦一起收到 —— 鼠标一按到图层行, // 焦点从工具栏按钮挪走就会立刻把这次拖动取消。这条用例专门守住那个坑。 await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await page.waitForTimeout(80) const before = await panelIds() await dragRow(0, 1, true) const after = await panelIds() await page.locator('.iwb-editor-tool[data-tool="select"]').click() return after[0] === before[1] && after[1] === before[0] ? true : '没换位 ' + before.join(',') + ' → ' + after.join(',') })()) // ---------- v1.8 快速效果:参数可调 ---------- // 造一个确定有内容的层(空层做效果没有可比像素) await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(180) const fxLayerId = (await dbg()).activeLayerId await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await page.locator('.iwb-editor-optionbar-body input.iwb-opt-num[data-opt="brushSize"]').fill('60') await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.3, liveBox.x + liveBox.width * 0.8, liveBox.y + liveBox.height * 0.7) await page.waitForTimeout(200) const fxHash = () => page.evaluate((id) => window.__iwbEditor.__debug().layerHash(id), fxLayerId) const fxSet = async (v) => { await page.evaluate((val) => { const el = document.querySelector('.iwb-editor-fx-range') if (!el) return el.value = String(val) el.dispatchEvent(new Event('input', { bubbles: true })) el.dispatchEvent(new Event('change', { bubbles: true })) }, v) await page.waitForTimeout(90) } check('快速效果:点马赛克后参数滑杆启用,单位是块大小', await (async () => { const h0 = (await dbg()).history await page.locator('[data-fx="mosaic"]').click() await page.waitForTimeout(260) const d = await dbg() const range = page.locator('.iwb-editor-fx-range') if (!d.fx.hasSource || d.fx.key !== 'mosaic') return 'fx=' + JSON.stringify(d.fx) if (await range.isDisabled()) return '滑杆仍禁用' const min = await range.getAttribute('min') const max = await range.getAttribute('max') const name = (await page.locator('.iwb-editor-fx-adj-name').textContent()) || '' const val = (await page.locator('.iwb-editor-fx-adj-val').textContent()) || '' if (min !== '2' || max !== '96') return 'range=' + min + '~' + max if (name.indexOf('马赛克') < 0 || name.indexOf('块大小') < 0) return '标签=' + name if (val.indexOf('px') < 0) return '数值=' + val if (d.history - h0 !== 1) return '撤销条数=' + (d.history - h0) + '(点效果应只拍 1 张)' return true })()) check('马赛克:块 12 → 48 → 12 与首次 12 完全一致(从基准重算,不叠加)', await (async () => { await fxSet(12) const h12a = await fxHash() await fxSet(48) const h48 = await fxHash() await fxSet(12) const h12b = await fxHash() if (!h12a) return '指纹读取失败' if (h12a === h48) return '块大小变化没有改变像素' if (h12a !== h12b) return '12px 两次结果不同,发生叠加: ' + h12a + ' vs ' + h12b return true })()) check('效果参数:连续拖动不新增撤销记录', await (async () => { const h0 = (await dbg()).history for (const v of [20, 36, 60]) await fxSet(v) const h1 = (await dbg()).history return h1 === h0 ? true : '撤销 ' + h0 + '→' + h1 })()) check('反白:50% 各通道趋近 128,100% 彻底反向(强度真的生效)', await (async () => { await page.locator('[data-fx="invert"]').click() await page.waitForTimeout(240) await fxSet(50) const c50 = await page.evaluate((id) => window.__iwbEditor.__debug().avgColor(id), fxLayerId) await fxSet(100) const c100 = await page.evaluate((id) => window.__iwbEditor.__debug().avgColor(id), fxLayerId) if (!c50 || !c100) return '取色失败' const near128 = c50.slice(0, 3).every(v => Math.abs(v - 128) <= 5) if (!near128) return '50%=' + c50.slice(0, 3).join(',') if (!(c100[0] <= 12 && c100[1] >= 160)) return '100%=' + c100.slice(0, 3).join(',') return true })()) check('同一效果再点=回默认参数,且不新增撤销记录', await (async () => { await page.locator('[data-fx="mosaic"]').click() await page.waitForTimeout(220) await fxSet(64) const before = await fxHash() const h0 = (await dbg()).history await page.locator('[data-fx="mosaic"]').click() await page.waitForTimeout(260) const d = await dbg() const after = await fxHash() if (d.history !== h0) return '撤销 +' + (d.history - h0) if (before === after) return '点第二次毫无变化(应回默认块大小)' return d.fx.key === 'mosaic' && d.fx.value !== 64 ? true : 'value=' + d.fx.value })()) check('切到别的层:效果滑杆置灰;切回原层恢复可调', await (async () => { await page.keyboard.press('Control+Shift+n') await page.waitForTimeout(240) const off = await page.locator('.iwb-editor-fx-range').isDisabled() await page.locator('.iwb-layer-item[data-layer-id="' + fxLayerId + '"]').click() await page.waitForTimeout(240) const on = !(await page.locator('.iwb-editor-fx-range').isDisabled()) return off && on ? true : '切走禁用=' + off + ' 切回恢复=' + on })()) check('形状控制点屏幕尺寸恒定(不随图片放大而膨胀)', await (async () => { // 当前这张 96×64 的图被「适应窗口」放大 ~9 倍。旧实现按 5.5 / S.zoom 画, // 屏幕尺寸实际是 11 * fitW/imgW ≈ 100px(截图里那种巨大发光点); // 现在按 viewScale() 换算,应稳定在 11px 左右、与图片尺寸无关。 await page.locator('[data-tool="rect"]').click() const b = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() await page.mouse.move(b.x + b.width * 0.25, b.y + b.height * 0.25) await page.mouse.down() await page.mouse.move(b.x + b.width * 0.75, b.y + b.height * 0.75, { steps: 6 }) await page.mouse.up() await page.waitForTimeout(320) const sizes = await page.evaluate(() => { const oc = document.querySelector('.iwb-editor-crop-overlay') const rect = oc.getBoundingClientRect() const sw = Math.max(1, Math.round(rect.width)), sh = Math.max(1, Math.round(rect.height)) // 重采样到屏幕尺寸:overlay 内部是图片坐标,小图上控制点在画布里只有 1~2px const tmp = document.createElement('canvas') tmp.width = sw; tmp.height = sh const t = tmp.getContext('2d') t.imageSmoothingEnabled = false t.drawImage(oc, 0, 0, sw, sh) const d = t.getImageData(0, 0, sw, sh).data const seen = new Uint8Array(sw * sh) const white = (i) => d[i * 4] > 235 && d[i * 4 + 1] > 235 && d[i * 4 + 2] > 235 && d[i * 4 + 3] > 200 const out = [] for (let i = 0; i < sw * sh; i++) { if (seen[i] || !white(i)) continue const st = [i]; seen[i] = 1 let mnx = 1e9, mxx = -1, mny = 1e9, mxy = -1, n = 0 while (st.length) { const p = st.pop(); const px = p % sw, py = (p - px) / sw; n++ if (px < mnx) mnx = px if (px > mxx) mxx = px if (py < mny) mny = py if (py > mxy) mxy = py for (const q of [p - 1, p + 1, p - sw, p + sw]) { if (q < 0 || q >= sw * sh || seen[q]) continue const qx = q % sw if (Math.abs(qx - px) > 1) continue if (white(q)) { seen[q] = 1; st.push(q) } else seen[q] = 1 } } if (n >= 25) out.push(Math.round(((mxx - mnx) + (mxy - mny)) / 2)) } return out }) const max = sizes.length ? Math.max(...sizes) : 0 return sizes.length >= 4 && max <= 16 ? true : '控制点屏幕尺寸=' + JSON.stringify(sizes) })()) check('图层拖动排序:位图与矢量混排也能拖(面板顺序、z、DOM 叠放三者一致)', await (async () => { // 位图和矢量走的是两套画布,排序落地后必须同时刷新 z 与 canvas-stack 的插入次序 await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2, liveBox.x + liveBox.width * 0.45, liveBox.y + liveBox.height * 0.45) await page.waitForTimeout(240) const rows = await page.evaluate(() => [...document.querySelectorAll('.iwb-layer-item')] .map(el => el.dataset.layerType + ':' + el.dataset.layerId)) const shapeKey = rows.find(k => k.indexOf('shape:') === 0) if (!shapeKey) return '没造出形状图层' if (rows[0] !== shapeKey) return '新形状不在面板最上层 ' + rows.join(',') await dragRow(0, rows.length - 1, true) // 一路拖到最底 const rows2 = await page.evaluate(() => [...document.querySelectorAll('.iwb-layer-item')] .map(el => el.dataset.layerType + ':' + el.dataset.layerId)) if (rows2[rows2.length - 1] !== 'bitmap:base') return '原图没留在最底 ' + rows2.join(',') if (rows2[rows2.length - 2] !== shapeKey) return '形状没落到原图之上 ' + rows2.join(',') const geo = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const sh = d.shapes[d.shapes.length - 1] // canvas-stack 里矢量画布排在第几个(自底向上),应与 z 一致 const nodes = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas')] const vecIdx = nodes.findIndex(n => n.className.indexOf('iwb-editor-vec-canvas') >= 0) return { z: sh ? sh.z : null, baseZ: d.layers.find(l => l.id === 'base').z, vecIdx } }) await page.locator('.iwb-editor-tool[data-tool="select"]').click() if (geo.baseZ !== 0) return '原图 z=' + geo.baseZ if (geo.z !== 1) return '形状 z=' + geo.z + '(应紧贴原图 = 1)' return geo.vecIdx >= 1 ? true : '矢量画布在 DOM 里排到了最底 vecIdx=' + geo.vecIdx })()) // ---------- v1.9 文字样式 / 吸附参考线 / 圆角 / 最近色 / 复制 ---------- /** 图片坐标 → 屏幕坐标(用位图图层 canvas 的实际显示尺寸换算,别用 zoom 猜) */ async function imgToScreen(ix, iy) { const b = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() const d = await dbg() return { x: b.x + ix * (b.width / d.doc.w), y: b.y + iy * (b.height / d.doc.h), box: b, doc: d.doc } } /** 吸附阈值(图片像素):与 snap.js 的 6 屏幕像素保持同一口径 */ async function snapTol() { const d = await dbg() const b = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() return 6 / (b.width / d.doc.w) } // 文字输入框必须贴着点击点出现。早先用 canvasStack 的矩形换算,而 stack 尺寸是 // (imgW + 2*overlayPad)*scale、图片在 stack 内还额外偏移 pad*scale —— 比例偏小又漏偏移, // 输入框整体跑到点击点的左上方。 await page.locator('.iwb-editor-tool[data-tool="select"]').click() const clearPt = await imgToScreen(90, 8) await page.mouse.click(clearPt.x, clearPt.y) await page.waitForTimeout(180) await page.locator('.iwb-editor-tool[data-tool="text"]').click() await page.waitForTimeout(180) // 测试画布只有 96×64,取左下角的空白区(已存在的两个矩形都在上半部) const clickPt = await imgToScreen(12, 56) await page.mouse.click(clickPt.x, clickPt.y) await page.waitForTimeout(260) const inpBox = await page.locator('.iwb-editor-text-input').boundingBox() if (!inpBox) throw new Error('点了画布但文字输入框没有出现,后面的定位断言无从谈起') // 输入框内「文字起点」= 左边框 2px + 左内边距 8px、上边框 2px + 上内边距 4px const dxInp = inpBox.x + 10 - clickPt.x const dyInp = inpBox.y + 6 - clickPt.y check('文字输入框贴着点击点出现(不再偏到左上方)', Math.abs(dxInp) <= 3 && Math.abs(dyInp) <= 3, 'dx=' + dxInp.toFixed(1) + ' dy=' + dyInp.toFixed(1)) await page.keyboard.press('Escape') await page.waitForTimeout(180) check('输入框按 Esc 取消后不留下空文字对象', (await dbg()).texts.length === 0, 'texts=' + (await dbg()).texts.length) // 多行文字:Shift+Enter 换行(textarea)→ 落成两行,包围盒高度约为单行两倍 await page.locator('.iwb-editor-tool[data-tool="text"]').click() let p0 = await imgToScreen(8, 8) await page.mouse.click(p0.x, p0.y) await page.waitForTimeout(150) await page.evaluate(() => { const el = document.querySelector('.iwb-editor-text-input') el.focus() el.value = 'AB\nCD' el.dispatchEvent(new Event('input', { bubbles: true })) }) await page.keyboard.press('Enter') await page.waitForTimeout(220) let vdbg = await dbg() const multiLine = vdbg.texts.length === 1 && vdbg.texts[0].text.indexOf('\n') > 0 const singleH = vdbg.texts.length ? vdbg.texts[0].fontSize * 1.25 : 0 check('文字支持多行(Shift+Enter 换行,包围盒高 ≈ 两行)', multiLine && vdbg.texts[0].box.h >= singleH * 2 - 2, multiLine ? 'h=' + vdbg.texts[0].box.h + ' 单行=' + Math.round(singleH) : JSON.stringify(vdbg.texts)) // 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。 // 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区, // 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。 // 清选中用「切到别的工具再切回来」:画布上早就有别的用例留下的图形, // 靠「点空白」清选中会点到它们(点位随用例顺序变化,很容易变成假失败)。 await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await page.waitForTimeout(120) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.waitForTimeout(220) const selIconNoSel = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count() check('选择工具未选中元素时仍有全选/反选/取消三个图标(且不重复)', selIconNoSel === 3, 'count=' + selIconNoSel + ' 选中=' + (await dbg()).selectedShapeId) await page.locator('.iwb-editor-tool[data-tool="select"]').click() p0 = await imgToScreen(10, 12) await page.mouse.click(p0.x, p0.y) await page.waitForTimeout(200) vdbg = await dbg() check('选中文字后选项栏出整套文字样式控件(字重/对齐/行距/描边/底色)', Boolean(vdbg.selectedTextId) && (await page.locator('.iwb-editor-optionbar-body [data-opt-text="fontWeight"]').count()) === 3 && (await page.locator('.iwb-editor-optionbar-body [data-opt-text="align"]').count()) === 3 && (await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').count()) === 1 && (await page.locator('.iwb-editor-optionbar-body [data-opt="textLineHeight"]').count()) >= 1 && (await page.locator('.iwb-editor-optionbar-body [data-opt-color]').count()) === 2) await page.locator('.iwb-editor-optionbar-body [data-opt-text="fontWeight"][data-value="900"]').click() await page.waitForTimeout(150) vdbg = await dbg() const boldBefore = vdbg.texts[0].fontWeight check('点「特粗」改选中文字的字重', boldBefore === '900', 'fontWeight=' + boldBefore) await page.keyboard.press('Control+z') await page.waitForTimeout(200) vdbg = await dbg() check('字重改动可撤销', vdbg.texts[0].fontWeight !== '900', 'fontWeight=' + vdbg.texts[0].fontWeight) // 撤销会清掉选中态(历史恢复后不再高亮),要继续改样式得重新选中 await page.locator('.iwb-editor-tool[data-tool="select"]').click() p0 = await imgToScreen(10, 12) await page.mouse.click(p0.x, p0.y) await page.waitForTimeout(200) vdbg = await dbg() const hBefore = vdbg.texts[0].box.h await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="textStrokeWidth"]') el.value = '6' el.dispatchEvent(new Event('input', { bubbles: true })) el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(200) vdbg = await dbg() check('描边走选项栏生效且包围盒随之变大(含描边外扩)', vdbg.texts[0].strokeWidth === 6 && vdbg.texts[0].box.h > hBefore, 'sw=' + vdbg.texts[0].strokeWidth + ' h ' + hBefore + '→' + vdbg.texts[0].box.h) // 底色块 await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click() await page.waitForTimeout(200) vdbg = await dbg() const hBg = vdbg.texts[0].box.h check('底色块开关生效(padding 让包围盒继续变大)', vdbg.texts[0].bgFill === true && hBg > vdbg.texts[0].box.h - 1 && hBg > 0, 'bgFill=' + vdbg.texts[0].bgFill + ' h=' + hBg) // 只改底色颜色、不点「底色」开关时,画布上原本什么都不会变 —— 用户会以为底色坏了 // 或被别的颜色盖住。现在选色即自动启用,按钮的 active 态也要跟着亮。 await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click() await page.waitForTimeout(180) const bgOff = (await dbg()).texts[0].bgFill await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body [data-opt-color="bgColor"]') el.value = '#ffd400' el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(220) vdbg = await dbg() const bgBtnOn = await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').classList.contains('active')) check('只选底色颜色就自动开启底色(不必先点开关)', bgOff === false && vdbg.texts[0].bgFill === true && vdbg.texts[0].bgColor === '#ffd400' && bgBtnOn, '关前=' + bgOff + ' 改色后 bgFill=' + vdbg.texts[0].bgFill + ' bgColor=' + vdbg.texts[0].bgColor + ' 按钮 active=' + bgBtnOn) // ---- v1.10:三个色块的「生效 / 未生效」语义 ---- // 用户反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」:底色默认曾是纯黑 #000000, // 关闭时也显示成一块死黑,看起来就像「又多了一个字体颜色」。现在默认值单点定义, // 且没生效的色块显示为灰色斜纹(不再显示颜色本身),语义变成「这里还没有颜色」。 const colorMeta = await page.evaluate(() => { const body = document.querySelector('.iwb-editor-optionbar-body') const out = {} body.querySelectorAll('[data-opt-color]').forEach(el => { out[el.dataset.optColor] = { off: el.classList.contains('is-off'), value: el.value } }) return { defaults: window.__iwbEditor.__debug().textDefaults, swatches: out } }) check('文字底色默认不再是纯黑(默认值收口到 text.js,近黑 #101014 + 68% 透明)', colorMeta.defaults.bgColor !== '#000000' && /^#[0-9a-f]{6}$/.test(colorMeta.defaults.bgColor) && Math.abs(colorMeta.defaults.bgAlpha - 0.68) < 1e-6, JSON.stringify(colorMeta.defaults)) // 关掉底色 + 描边宽度归零 → 两个色块都应变成「未启用」 await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click() await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="textStrokeWidth"]') el.value = '0' el.dispatchEvent(new Event('input', { bubbles: true })) el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(200) const offStates = await page.evaluate(() => [...document.querySelectorAll('.iwb-editor-optionbar-body [data-opt-color]')] .map(el => ({ k: el.dataset.optColor, off: el.classList.contains('is-off') }))) check('描边宽度为 0 / 底色关闭时,对应色块标记为「未启用」(不再显示颜色本身)', offStates.length === 2 && offStates.every(o => o.off), JSON.stringify(offStates)) // 选区命令(全选/反选/取消)属于像素选区,必须待在选区工具里 await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await page.waitForTimeout(160) const marqueeIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count() await page.locator('.iwb-editor-tool[data-tool="lasso"]').click() await page.waitForTimeout(160) const lassoIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count() check('选区工具(矩形 / 套索)都有全选、反选、取消选区三个按钮', marqueeIcons === 3 && lassoIcons === 3, 'marquee=' + marqueeIcons + ' lasso=' + lassoIcons) await page.locator('.iwb-editor-tool[data-tool="select"]').click() p0 = await imgToScreen(10, 12) await page.mouse.click(p0.x, p0.y) await page.waitForTimeout(220) const textSelIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count() check('选中文字时选项栏不再冒出选区命令按钮(那三个命令跟文字对象无关)', textSelIcons === 0, 'count=' + textSelIcons) // 选中框必须是实线:虚线圈会被当成「莫名其妙多出来的像素选区」。 // 沿选中框顶边扫一行橙色像素,虚线(6/3)覆盖率约 0.6~0.7,实线接近 1。 const frameCoverage = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const cv = document.querySelector('.iwb-editor-crop-overlay') if (!d.selectedTextId) return { err: 'no-selected-text' } if (!cv) return { err: 'no-overlay' } const ctx = cv.getContext('2d') const img = ctx.getImageData(0, 0, cv.width, cv.height).data const W = cv.width // 不按图片坐标换算:overlay 画布含 overlayPad 外扩,直接全画布扫, // 找第一条「橙色连续段」,再量这一段的覆盖率 —— 实线接近 1,6/3 虚线约 0.6~0.7。 const isOrange = (i) => img[i + 3] > 60 && img[i] > 170 && img[i + 1] > 100 && img[i + 2] < 130 for (let y = 0; y < cv.height; y++) { const base = y * W * 4 let first = -1, last = -1, n = 0 for (let x = 0; x < W; x++) { if (isOrange(base + x * 4)) { if (first < 0) first = x; last = x; n++ } } if (n >= 20 && last - first >= 40) { return { ratio: +(n / (last - first + 1)).toFixed(2), n, span: last - first + 1, y } } } return { err: 'no-orange-row' } }) check('对象选中框是实线(虚线的语义是像素选区,会把用户绕晕)', !!frameCoverage && frameCoverage.ratio >= 0.85, JSON.stringify(frameCoverage)) // 吸附:画一个实心矩形,拖到画布中心附近应被精确吸到中心并出现参考线 await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await page.waitForTimeout(100) if (await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').getAttribute('class').then(c => c.indexOf('active') < 0)) { await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').click() } let pa = await imgToScreen(6, 6) let pb = await imgToScreen(26, 26) await page.mouse.move(pa.x, pa.y) await page.mouse.down() await page.mouse.move(pb.x, pb.y, { steps: 6 }) await page.mouse.up() await page.waitForTimeout(200) await page.locator('.iwb-editor-tool[data-tool="select"]').click() pa = await imgToScreen(16, 16) await page.mouse.click(pa.x, pa.y) // 等过 380ms 的双击窗口:同一个点连点会被判成双击(双击属于「进对象编辑」, // 不该接管拖动),这里要测的是单击选中后的拖动 await page.waitForTimeout(420) const rectGeo = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes[d.shapes.length - 1] return s ? { id: s.id } : null }) const tol = await snapTol() const sBox = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')] return { doc: d.doc, shapes: d.shapes.length } }) // 抓矩形中心,拖到「画布中心 + tol/2」:若吸附生效,中心会精确回到画布中心 const rectInfo = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const sel = d.selectedShapeId return sel ? { sel, doc: d.doc } : { doc: d.doc } }) const center = { x: sBox.doc.w / 2, y: sBox.doc.h / 2 } // 用轴对齐假设取矩形中心:从墨迹范围读更稳(矩形是自己画的 6..26) const inkBox = await page.evaluate(() => { const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')] let best = null for (const c of cv) { const cx = c.getContext('2d') const d = cx.getImageData(0, 0, c.width, c.height).data let minX = 1e9, minY = 1e9, maxX = -1, maxY = -1 for (let y = 0; y < c.height; y++) for (let x = 0; x < c.width; x++) { if (d[(y * c.width + x) * 4 + 3] > 20) { if (x < minX) minX = x; if (x > maxX) maxX = x; if (y < minY) minY = y; if (y > maxY) maxY = y } } if (maxX >= 0) best = { minX, minY, maxX, maxY, w: maxX - minX + 1, h: maxY - minY + 1 } } return best }) const rc = { x: (inkBox.minX + inkBox.maxX + 1) / 2, y: (inkBox.minY + inkBox.maxY + 1) / 2 } const grab = await imgToScreen(rc.x, rc.y) const destImg = { x: center.x + tol / 2, y: center.y + tol / 2 } const dest = await imgToScreen(destImg.x, destImg.y) await page.mouse.move(grab.x, grab.y) await page.mouse.down() await page.mouse.move(grab.x + 3, grab.y + 3, { steps: 3 }) await page.mouse.move(dest.x, dest.y, { steps: 8 }) await page.waitForTimeout(160) const gMid = (await dbg()).guides await page.mouse.up() await page.waitForTimeout(220) const gEnd = (await dbg()).guides // 松手后按墨迹中心核对:应该正好落在画布中心 const inkAfter = await page.evaluate(() => { const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')] let best = null for (const c of cv) { const cx = c.getContext('2d') const d = cx.getImageData(0, 0, c.width, c.height).data let minX = 1e9, minY = 1e9, maxX = -1, maxY = -1 for (let y = 0; y < c.height; y++) for (let x = 0; x < c.width; x++) { if (d[(y * c.width + x) * 4 + 3] > 20) { if (x < minX) minX = x; if (x > maxX) maxX = x; if (y < minY) minY = y; if (y > maxY) maxY = y } } if (maxX >= 0) best = { minX, minY, maxX, maxY } } return best }) const cAfter = { x: (inkAfter.minX + inkAfter.maxX + 1) / 2, y: (inkAfter.minY + inkAfter.maxY + 1) / 2 } check('拖到画布中心附近会被精确吸附(中心误差 < 1px)', gMid.length >= 1 && Math.abs(cAfter.x - center.x) < 1 && Math.abs(cAfter.y - center.y) < 1, 'guides=' + JSON.stringify(gMid) + ' 中心=' + Math.round(cAfter.x) + ',' + Math.round(cAfter.y) + ' 期望=' + center.x + ',' + center.y) check('松手后参考线清除', gEnd.length === 0, JSON.stringify(gEnd)) // Alt 拖动不吸附 const grab2 = await imgToScreen(cAfter.x, cAfter.y) await page.keyboard.down('Alt') await page.mouse.move(grab2.x, grab2.y) await page.mouse.down() await page.mouse.move(grab2.x + 4, grab2.y + 4, { steps: 4 }) await page.waitForTimeout(140) const gAlt = (await dbg()).guides await page.mouse.up() await page.keyboard.up('Alt') check('按住 Alt 拖动时不吸附(无参考线)', gAlt.length === 0, JSON.stringify(gAlt)) // 圆角:设半径后角落被切掉,墨迹变少 // 所有矢量层墨迹的总和:前面用例画过别的矩形,只取「最大那层」会量错对象 const inkCount = () => page.evaluate(() => { const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')] let total = 0 for (const c of cv) { const d = c.getContext('2d').getImageData(0, 0, c.width, c.height).data for (let i = 3; i < d.length; i += 4) if (d[i] > 20) total++ } return total }) const inkSharp = await inkCount() await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="shapeRadius"]') el.value = '6' el.dispatchEvent(new Event('input', { bubbles: true })) el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(220) const inkRound = await inkCount() const radiusVal = (await dbg()).shapes.map(s => s.radius).filter(r => r > 0) check('矩形圆角生效(角落被切,墨迹减少)', radiusVal.length === 1 && inkRound < inkSharp, 'radius=' + JSON.stringify(radiusVal) + ' ink ' + inkSharp + '→' + inkRound) // 最近使用颜色 await page.locator('[data-action="toggleColorPop"][data-color-slot="stroke"]').click() await page.waitForTimeout(150) await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click() await page.waitForTimeout(200) const recents = (await dbg()).recentColors const recentsInPop = await page.locator('.iwb-editor-recent-colors [data-panel-color]').count() await page.keyboard.press('Escape') await page.waitForTimeout(120) check('选过的颜色进入「最近使用」并出现在色板弹层', recents[0] === '#ffd400' && recentsInPop >= 1, JSON.stringify(recents) + ' 弹层色块=' + recentsInPop) // 复制到剪贴板:harness 跑在 about:blank(非安全上下文), // 这里只验「按钮存在 + 点击有明确反馈 + 不抛错」,真安全上下文由本地 http 探针覆盖 // ---- v1.10:矢量图形也有描边色 / 填充色 ---- // 用户要求「把其他的矢量图形也加上描边与填充色属性,工具栏上加描边色设置」。 // 设计:描边色 = 主色(左侧色板 / 吸管 / 选项栏一个真相源),填充色独立存形状的 // fillColor,没单独设过就跟随描边色 —— 于是「切实心 = 同色实心」,不会突兀。 await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await page.waitForTimeout(120) const shapeColorUI = await page.evaluate(() => { const body = document.querySelector('.iwb-editor-optionbar-body') return { stroke: body.querySelectorAll('[data-shape-color="stroke"]').length, fill: body.querySelectorAll('[data-shape-color="fill"]').length } }) check('矩形工具的选项栏就带描边色 / 填充色块(画之前就能定色)', shapeColorUI.stroke === 1 && shapeColorUI.fill === 1, JSON.stringify(shapeColorUI)) pa = await imgToScreen(62, 6) pb = await imgToScreen(90, 28) await page.mouse.move(pa.x, pa.y) await page.mouse.down() await page.mouse.move(pb.x, pb.y, { steps: 6 }) await page.mouse.up() await page.waitForTimeout(300) const shapeFresh = await page.evaluate(() => { const d = window.__iwbEditor.__debug() return d.shapes[d.shapes.length - 1] }) check('新建图形的填充默认「跟随描边色」(fillColor=null),不是写死某个填充色', shapeFresh.fillColor === null, JSON.stringify({ fill: shapeFresh.fill, fillColor: shapeFresh.fillColor })) // 数「目标颜色」的像素:矢量画布含 overlayPad 外扩,按图片坐标换算单点会采到别处, // 直接全画布统计同色像素最稳(0 → 上千,量级差别足够断言) const countColorInVec = (rgb, tol) => page.evaluate(({ rgb, tol }) => { let n = 0 for (const cv of [...document.querySelectorAll('.iwb-editor-vec-canvas')]) { const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data for (let i = 0; i < d.length; i += 4) { if (d[i + 3] > 200 && Math.abs(d[i] - rgb[0]) < tol && Math.abs(d[i + 1] - rgb[1]) < tol && Math.abs(d[i + 2] - rgb[2]) < tol) n++ } } return n }, { rgb, tol }) const greenBefore = await countColorInVec([34, 204, 85], 8) await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]') el.value = '#22cc55' el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(280) const shapeFilled = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes[d.shapes.length - 1] const body = document.querySelector('.iwb-editor-optionbar-body') return { fill: s.fill, fillColor: s.fillColor, fillBtnOn: !!body.querySelector('[data-opt-toggle="fill"]').classList.contains('active'), fillSwatchOff: body.querySelector('[data-shape-color="fill"]').classList.contains('is-off') } }) const greenAfter = await countColorInVec([34, 204, 85], 8) check('选填充色即自动切实心,画面上真的是这个颜色(不是只改了个字段)', shapeFilled.fill === true && shapeFilled.fillColor === '#22cc55' && greenBefore === 0 && greenAfter > 200, JSON.stringify(shapeFilled) + ' 绿色像素 ' + greenBefore + '→' + greenAfter) check('填充色块随之变为「生效」态(不再是灰色斜纹)', shapeFilled.fillSwatchOff === false && shapeFilled.fillBtnOn === true, JSON.stringify({ off: shapeFilled.fillSwatchOff, btn: shapeFilled.fillBtnOn })) await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]') el.value = '#3388ff' el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(280) const shapeStroked = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes[d.shapes.length - 1] return { shapeColor: s.color, mainColor: d.color } }) check('改图形描边色 = 改主色(色板 / 吸管 / 选项栏不会各说各话)', shapeStroked.shapeColor === '#3388ff' && shapeStroked.mainColor === '#3388ff', JSON.stringify(shapeStroked)) // ---- v1.11:颜色收敛成「描边 / 填充」两格,工具栏与选项栏读同一份 ---- // 用户原话:「3 个位置调色有问题,应该是 2 个调色」「请给工具栏加一个描边色, // 工具选择的填充与描边与这里对应上」「填色里还需要添加一个取消颜色的按钮,就是无色状态」 const pairMode = await page.evaluate(() => { const pair = document.querySelector('.iwb-editor-color-pair') const btns = [...pair.querySelectorAll('.iwb-editor-color-btn')] return { mode: pair.dataset.colorMode, visible: btns.filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot) } }) check('工具栏给出「描边 + 填充」两格(形状工具下两格都在)', pairMode.mode === 'pair' && pairMode.visible.join(',') === 'stroke,fill', JSON.stringify(pairMode)) // 从工具栏填充槽进色板:目标应当是填充,且出现「无」 await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click() await page.waitForTimeout(220) const popTarget = await page.evaluate(() => { const pop = document.querySelector('.iwb-editor-color-pop') return { open: !pop.hidden, fillActive: pop.querySelector('.iwb-color-pop-tab[data-color-slot="fill"]').classList.contains('active'), noneVisible: !pop.querySelector('[data-color-none]').hidden } }) check('点填充槽打开色板:目标是填充,并出现「无」按钮', popTarget.open && popTarget.fillActive && popTarget.noneVisible, JSON.stringify(popTarget)) // 用一个画布上不会出现的怪色(#a014b2)验收:12 个推荐色在前面用例里都用过, // 拿黄色/绿色统计会数到别的图形,永远清不到 0。 const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color) await page.evaluate(() => { const el = document.querySelector('.iwb-editor-color-hex-input') el.value = '#a014b2' el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(300) const fromPop = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes[d.shapes.length - 1] const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]') return { main: d.color, fillColor: s.fillColor, fill: s.fill, fillBtnBg: fillBtn.querySelector('i').style.backgroundColor } }) check('色板里选色写进填充、主色(描边)不动,工具栏填充格同步变色', fromPop.main === mainBefore && fromPop.fillColor === '#a014b2' && fromPop.fill === true && /160, 20, 178/.test(fromPop.fillBtnBg), JSON.stringify(fromPop)) // 「无」:关填充,画面清空,但颜色留着 const purpleBefore = await countColorInVec([160, 20, 178], 10) await page.evaluate(() => document.querySelector('[data-color-none]').click()) await page.waitForTimeout(320) const afterNone = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes[d.shapes.length - 1] const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]') return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') } }) const purpleAfter = await countColorInVec([160, 20, 178], 10) check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)', afterNone.fill === false && afterNone.fillColor === '#a014b2' && purpleBefore > 200 && purpleAfter === 0, JSON.stringify(afterNone) + ' 紫色像素 ' + purpleBefore + '→' + purpleAfter) check('无填充时工具栏填充格显示「无」(斜杠态,不露颜色本身)', /is-none/.test(afterNone.btnCls) && afterNone.noneActive === true, JSON.stringify(afterNone)) // 反方向:选项栏改填充 → 工具栏填充格跟上 await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]') el.value = '#22cc55' el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(300) const reverse = await page.evaluate(() => { const pair = document.querySelector('.iwb-editor-color-pair') const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]') return { fillBtnBg: pair.querySelector('[data-color-slot="fill"] i').style.backgroundColor, optVal: opt.value } }) check('选项栏改填充色,工具栏填充格立刻跟上(两处同一份值)', reverse.optVal === '#22cc55' && /34, 204, 85/.test(reverse.fillBtnBg), JSON.stringify(reverse)) // 画笔没有填充概念:只留一格 await page.keyboard.press('Escape') await page.locator('.iwb-editor-tool[data-tool="brush"]').click() await page.waitForTimeout(220) const brushPair = await page.evaluate(() => { const pair = document.querySelector('.iwb-editor-color-pair') return { mode: pair.dataset.colorMode, visible: [...pair.querySelectorAll('.iwb-editor-color-btn')].filter(b => b.offsetParent !== null).length } }) check('画笔工具下只留一格(画笔没有填充概念,不留空格让人猜)', brushPair.mode === 'single' && brushPair.visible === 1, JSON.stringify(brushPair)) const copyExists = await page.locator('[data-action="copyClipboard"]').count() await page.locator('[data-action="copyClipboard"]').click() await page.waitForTimeout(400) const copyToast = await page.locator('.iwb-editor-toast').textContent() check('顶栏有「复制」且点击给出明确反馈(非静默失败)', copyExists === 1 && /复制/.test(copyToast || ''), 'toast=' + JSON.stringify(copyToast)) check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (async () => { await page.keyboard.press('Escape') // 清掉可能残留的选中态 await page.keyboard.press('Control+]') const t = await page.locator('.iwb-editor-toast').textContent() return t.indexOf('选中') >= 0 })()) await page.locator('[data-action="cancel"]').click() const openState = await poll(async () => page.evaluate(() => window.__openState)) check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭', Boolean(openState && openState.mode === 'cancel') && (await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false, JSON.stringify(openState)) check('无运行时错误 / 无弹窗', errors.length === 0, errors.slice(0, 3).join(' | ')) await browser.close() console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过')) process.exit(failed ? 1 : 0)