// 标注插件本地端到端(开发用,不进 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-color-pair') })) 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:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ---- // v1.13 用户裁定:顶栏四个「置顶/上移/下移/置底」删掉(图层面板可拖 + Ctrl+]/[ 已覆盖), // 「适应窗口 / 收起侧栏」搬到画布底部工具栏的最右侧。 check('顶栏不再有图层层级按钮;视图快捷搬到画布工具栏最右;图层新建/导入/合并仍在面板标题栏', await page.evaluate(() => { const q = (s) => Boolean(document.querySelector(s)) const hdrLayerBtns = document.querySelectorAll('.iwb-editor-header .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"]') const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools') const kids = tools ? [...tools.children] : [] const lastTwo = kids.slice(-2).map(el => el.dataset && el.dataset.action) return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') && hdrLayerBtns === 0 && !hdrAdd && addBtns === 4 && !q('.iwb-editor-header [data-action="zoomFit"]') && !q('.iwb-editor-header [data-action="togglePanels"]') && lastTwo.join(',') === 'zoomFit,togglePanels' && 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"]') })) 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-tools [data-action="zoomFit"]').click() const fitted = (await dbg()).zoom return zoomed > 1 && Math.abs(fitted - 1) < 0.001 })()) check('PS 快捷键:V/M/A/L/B/E/P/T/R/O/U/C/I/H 切工具', await (async () => { // 先点一下工具按钮,保证焦点不在输入框里(isTyping() 会吞掉无修饰键快捷键) await page.locator('.iwb-editor-tool[data-tool="select"]').click() // v1.13 用户裁定:R = 矩形,O = 圆形,L = 箭头(套索从 L 让位到 A) const seq = [['v', 'select'], ['m', 'marquee'], ['a', 'lasso'], ['l', 'arrow'], ['b', 'brush'], ['e', 'eraser'], ['p', 'pen'], ['t', 'text'], ['r', 'rect'], ['o', 'circle'], ['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 的用例在文件末尾(它会把「下一个图形的填充色」也写成具体色值, // 落在中间会污染后面「新建图形填充默认跟随描边色」那条断言) // 钢笔:闭合路径选中后同样可切描边/实心 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-editor-color-pop .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 && !q('.iwb-editor-header > .iwb-editor-commands') && 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 的用例见上面「Shift+X 交换填充色与描边色」(v1.13.1 起是交换语义,不再是实心/描边开关) // 图层快捷键: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(',') })()) // v1.13(用户裁定「图层现在不能移动到原图的下面,这个需要解封」): // 原图不再被钉在最底层,拖到原图那一行就能真的沉到它下面(典型用途:垫一张背景色层)。 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() const okBottom = after[after.length - 1] === movedId const okBase = after[after.length - 2] === 'base' const zBase = await zOf('base') // 后续用例默认「原图在最底」,这里撤销回原状,不给后面留暗坑 await page.keyboard.press('Control+z') await page.waitForTimeout(260) const back = await panelIds() if (!okBottom) return '被拖的层没到最底 ' + after.join(',') if (!okBase) return '原图没被压到倒数第二格 ' + after.join(',') if (!(zBase > 0)) return '原图 z=' + zBase + '(应 > 0)' return back.join(',') === before.join(',') ? true : '撤销未复原 ' + back.join(',') })()) 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)) // ---- v1.14 字体选择:系统字体族(黑 / 宋 / 楷 / 圆)---- // 为什么只做系统字体:宿主 CSP 是 default-src 'self',font-src 回落它,第三方字体 CDN // 会被浏览器直接拦掉;中文字体 2–64MB(本机宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB), // 内联进 389KB 的插件不现实。系统字体栈 0 字节、同步可用,没有「字体没加载完就 // measureText」导致选中框和字形错位的时序问题 —— 这是内置字体方案最大的坑。 const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]' const FAM_KEYS = ['sans', 'serif', 'kai', 'round'] const famCount = await page.locator(FAM_SEL).count() const famOpts = famCount ? await page.locator(FAM_SEL + ' option').allTextContents() : [] check('选中文字后选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体', famCount === 1 && famOpts.join(',') === '黑体,宋体,楷体,圆体', 'count=' + famCount + ' opts=' + famOpts.join(',')) // 切换字体要同时做两件事:写进选中的这段文字 + 成为下一段新文字的默认值 await page.selectOption(FAM_SEL, 'kai') await page.waitForTimeout(240) let famDbg = await dbg() check('下拉切换字体写到选中文字,并同步「新建文字默认字体」', famDbg.texts[0].fontFamily === 'kai' && famDbg.textDefaults.family === 'kai', 'obj=' + famDbg.texts[0].fontFamily + ' default=' + famDbg.textDefaults.family) // 真实点击下拉框(不选任何项)不能改动字体。 // 这条是给 v1.14.1 兜底的:click 委托原先用 closest('[data-opt-text]') 判断「文字样式按钮」, // 在系统取色器里拖色时只派发 input,关闭取色器才派发 change。 // 以前只接 change ⇒ 取色器开着的整段时间画布一动不动。这里只发 input(模拟拖色中), // 断言画布像素当场就变 —— 不发 change 也不许等。 const purpleBeforeLive = await countColorInVec([122, 31, 162], 8) await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]') el.value = '#7a1fa2' el.dispatchEvent(new Event('input', { bubbles: true })) }) await page.waitForTimeout(200) const liveFill = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes[d.shapes.length - 1] return { fillColor: s.fillColor, fill: s.fill } }) const purpleAfterLive = await countColorInVec([122, 31, 162], 8) check('填充色块只发 input(取色器还开着)画布就实时变色,不必等 change', liveFill.fillColor === '#7a1fa2' && purpleAfterLive > 200, JSON.stringify(liveFill) + ' 紫色像素 ' + purpleBeforeLive + '→' + purpleAfterLive) // 拖动结束:change 收尾,历史只多一条(拖动中不逐帧拍快照) const hBeforeNative = (await dbg()).history await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]') el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(200) check('原生取色器拖动一次只记 1 步撤销(预览不逐帧拍快照)', (await dbg()).history - hBeforeNative === 0, 'history +' + ((await dbg()).history - hBeforeNative)) 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-pop .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('.iwb-editor-color-pop [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('.iwb-editor-color-pop [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 })()) // ---- v1.13.1:Shift+X 改成「交换填充色与描边色」(以前是 实心/描边 开关)---- // 旧语义下按一次,填充被关掉、描边纹丝不动 —— 用户的原话是「丢失填充色」。 // 放在最后跑:交换会把「下一个图形的填充色」也写成具体色值,前面有条断言要求它是 null。 const shiftXSwap = await (async () => { await page.locator('.iwb-editor-tool[data-tool="rect"]').click() const a = { x: imgBox.x + imgBox.width * 0.10, y: imgBox.y + imgBox.height * 0.10 } const b = { x: imgBox.x + imgBox.width * 0.30, y: imgBox.y + imgBox.height * 0.30 } await page.mouse.move(a.x, a.y); await page.mouse.down() await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up() await page.waitForTimeout(180) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2) await page.waitForTimeout(150) // 给个独立填充色,描边色保持主色,两边不同才看得出交换 await page.evaluate(() => { const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]') el.value = '#22cc55' el.dispatchEvent(new Event('input', { bubbles: true })) el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(180) const d0 = await dbg() const sh0 = d0.shapes.find(s => s.id === d0.selectedShapeId) if (!sh0) return { ok: false, detail: '没选中形状' } const stroke0 = sh0.color, fill0 = sh0.fillColor, fillOn0 = sh0.fill await page.keyboard.press('Shift+x') const d1 = await dbg() const sh1 = d1.shapes.find(s => s.id === d1.selectedShapeId) const swapped = Boolean(sh1 && sh1.color === fill0 && sh1.fillColor === stroke0 && sh1.fill === fillOn0) await page.keyboard.press('Shift+x') // 再按一次回到原样 const d2 = await dbg() const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId) const back = Boolean(sh2 && sh2.color === stroke0 && sh2.fillColor === fill0 && sh2.fill === fillOn0) return { ok: swapped && back, detail: JSON.stringify({ 原: { 描边: stroke0, 填充: fill0, 填充开: fillOn0 }, 交换后: sh1 && { 描边: sh1.color, 填充: sh1.fillColor, 填充开: sh1.fill }, 再按: sh2 && { 描边: sh2.color, 填充: sh2.fillColor } }) } })() check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail) // ================================================================ // v1.17:描边也能是「无色」;只要有一边无色,Shift+X 照样能交换 // ================================================================ // 用户原话:「让矢量图形与钢笔的描边色也可以去掉」 // 「让描边与填充,有一个是无色的时候,可以交换,现在是不可以的」 const setOptColor = (slot, hex) => page.evaluate(({ slot, hex }) => { const el = document.querySelector(`.iwb-editor-optionbar-body [data-shape-color="${slot}"]`) el.value = hex el.dispatchEvent(new Event('change', { bubbles: true })) }, { slot, hex }) async function drawRectAt(x1, y1, x2, y2) { await page.locator('.iwb-editor-tool[data-tool="rect"]').click() const a = { x: imgBox.x + imgBox.width * x1, y: imgBox.y + imgBox.height * y1 } const b = { x: imgBox.x + imgBox.width * x2, y: imgBox.y + imgBox.height * y2 } await page.mouse.move(a.x, a.y); await page.mouse.down() await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up() await page.waitForTimeout(180) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2) await page.waitForTimeout(160) return { a, b } } // 取选中形状 + 三处 UI 的「无」状态,后面几条都用它 const selectedShapeState = () => page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes.find(x => x.id === d.selectedShapeId) const btn = document.querySelector('.iwb-editor-color-pair [data-color-slot="stroke"]') const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]') const none = document.querySelector('.iwb-editor-color-pop [data-color-none]') return { type: s && s.type, closed: s && s.closed, strokeOn: s && s.strokeOn, fill: s && s.fill, color: s && s.color, fillColor: s && s.fillColor, strokeBtnNone: !!btn && btn.classList.contains('is-none'), optOff: !!opt && opt.classList.contains('is-off'), noneHidden: !none || none.hidden, noneActive: !!none && none.classList.contains('active') } }) // ---- 形状:去掉描边 ---- // 描边给一个画布上没出现过的洋红,靠像素数证明「框真的没了」而不是只改了数据 await drawRectAt(0.55, 0.52, 0.82, 0.74) await setOptColor('fill', '#0aa6c8') await page.waitForTimeout(160) await setOptColor('stroke', '#ff00aa') await page.waitForTimeout(220) // 按画布分别数:画布上还躺着别的早期用例留下的同色对象(文字就用了 #ff00aa), // 全局求和会把它们算进来 —— 只认「某一个画布从有变没有」才说得清这条描边真的没了 const magentaPerCanvas = () => page.evaluate(() => [...document.querySelectorAll('.iwb-editor-vec-canvas')].map(cv => { const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data let n = 0 for (let i = 0; i < d.length; i += 4) { if (d[i + 3] > 200 && Math.abs(d[i] - 255) < 8 && d[i + 1] < 8 && Math.abs(d[i + 2] - 170) < 8) n++ } return n })) const magentaBefore = await magentaPerCanvas() await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click() await page.waitForTimeout(220) const noneShownOnStroke = await page.evaluate(() => !document.querySelector('.iwb-editor-color-pop [data-color-none]').hidden) await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click()) await page.waitForTimeout(320) const noStroke = await selectedShapeState() const magentaAfter = await magentaPerCanvas() const cyanStill = await countColorInVec([10, 166, 200], 8) const strokeGone = magentaBefore.some((n, i) => n > 300 && magentaAfter[i] === 0) const noNewMagenta = magentaAfter.every((n, i) => n <= magentaBefore[i]) check('形状可以去掉描边:描边像素清零,填充色与描边色都留着', noneShownOnStroke && strokeGone && noNewMagenta && noStroke.strokeOn === false && noStroke.fill === true && noStroke.color === '#ff00aa' && cyanStill > 300, JSON.stringify({ noneShownOnStroke, magentaBefore, magentaAfter, cyanStill, ...noStroke })) check('无描边时工具栏描边格画斜杠、选项栏描边色块置灰、色板「无」高亮', noStroke.strokeBtnNone === true && noStroke.optOff === true && noStroke.noneActive === true, JSON.stringify({ btn: noStroke.strokeBtnNone, opt: noStroke.optOff, none: noStroke.noneActive })) // 对称保护:已经无描边、再把填充也点掉 → 对象会彻底隐形,应当自动把描边还回来 await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click() await page.waitForTimeout(200) await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click()) await page.waitForTimeout(300) const bothNone = await selectedShapeState() check('「无描边」后再点「无填充」:自动恢复描边,不会留下一个看不见的对象', bothNone.fill === false && bothNone.strokeOn === true, JSON.stringify({ fill: bothNone.fill, strokeOn: bothNone.strokeOn })) // 回到「无描边」状态给下一条用例用(色板此时停在填充槽,先切回描边) await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click() await page.waitForTimeout(200) await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click()) await page.waitForTimeout(280) // 选色即恢复描边:与「文字描边宽度 0 时选色自动给 6px」同一条逻辑, // 否则用户选了颜色画面没变化,会以为颜色设置坏了 await page.evaluate(() => { const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input') el.value = '#ff00aa' el.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(320) const revivedStroke = await selectedShapeState() const magentaRevived = await magentaPerCanvas() const strokeBack = magentaRevived.some((n, i) => n > 300 && magentaAfter[i] === 0) check('无描边时再选一次颜色 → 自动恢复描边(选了色一定有变化)', revivedStroke.strokeOn === true && revivedStroke.color === '#ff00aa' && strokeBack, JSON.stringify({ ...revivedStroke, strokeBack, magentaAfter, magentaRevived })) // ---- 钢笔闭合路径:同样能去掉描边 ---- await page.locator('.iwb-editor-tool[data-tool="pen"]').click() const t1 = { x: imgBox.x + imgBox.width * 0.34, y: imgBox.y + imgBox.height * 0.16 } const t2 = { x: imgBox.x + imgBox.width * 0.46, y: imgBox.y + imgBox.height * 0.16 } const t3 = { x: imgBox.x + imgBox.width * 0.40, y: imgBox.y + imgBox.height * 0.34 } await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(90) await page.mouse.click(t2.x, t2.y); await page.waitForTimeout(90) await page.mouse.click(t3.x, t3.y); await page.waitForTimeout(90) await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(280) // 回到起点 = 闭合 await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click() await page.waitForTimeout(220) await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click()) await page.waitForTimeout(320) const penNoStroke = await selectedShapeState() check('钢笔闭合路径也能去掉描边(去掉后只剩填充面,不会整个消失)', penNoStroke.type === 'pen' && penNoStroke.closed === true && penNoStroke.strokeOn === false && penNoStroke.fill === true, JSON.stringify(penNoStroke)) // 未闭合路径没有可填内部:去掉描边 = 这条线没了,索性不给「无」 await page.locator('.iwb-editor-tool[data-tool="pen"]').click() await page.mouse.click(imgBox.x + imgBox.width * 0.62, imgBox.y + imgBox.height * 0.36) await page.waitForTimeout(90) await page.mouse.click(imgBox.x + imgBox.width * 0.76, imgBox.y + imgBox.height * 0.42) await page.waitForTimeout(90) await page.keyboard.press('Enter') // 回车结束开放路径 await page.waitForTimeout(280) await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click() await page.waitForTimeout(220) const openPen = await selectedShapeState() check('未闭合钢笔不给「无描边」(去掉等于把这条线删了)', openPen.type === 'pen' && openPen.closed === false && openPen.noneHidden === true, JSON.stringify(openPen)) // ---- 一边无色也能交换(用户反馈的第二个问题)---- await page.keyboard.press('Escape') await drawRectAt(0.08, 0.10, 0.30, 0.30) // 先做成「只有描边」:fill 关掉,描边给独立色 await page.evaluate(() => { const btn = document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"]') if (btn) btn.click() }) await page.waitForTimeout(200) await setOptColor('stroke', '#ff00aa') await page.waitForTimeout(220) const onlyStroke = await selectedShapeState() await page.keyboard.press('Shift+x') await page.waitForTimeout(260) const afterSwap1 = await selectedShapeState() await page.keyboard.press('Shift+x') await page.waitForTimeout(260) const afterSwap2 = await selectedShapeState() check('一边无色也能交换:只描边 → 只填充(描边关、填充开),再按回到原样', onlyStroke.strokeOn === true && onlyStroke.fill === false && afterSwap1.strokeOn === false && afterSwap1.fill === true && afterSwap2.strokeOn === true && afterSwap2.fill === false, JSON.stringify({ 原: onlyStroke, 按一次: afterSwap1, 再按: afterSwap2 })) // ================================================================ // v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例) // ================================================================ await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.keyboard.press('Escape') // 前面几条效果用例会把「原图」栅格化成副本层并把原层隐藏,这里先还原成干净的单层, // 否则调节作用在一个隐藏层上 → 像素统计一动不动(第一次跑就踩了这个) await page.locator('[data-action="reset"]').click() await page.waitForTimeout(450) await page.evaluate(() => { const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || '')) if (base) base.click() }) await page.waitForTimeout(320) const adjRowCount = await page.locator('.iwb-editor-adj-row').count() const adjNames = await page.locator('.iwb-editor-adj-name').allTextContents() check('右侧栏出现「图片调节」,11 项齐全且顺序固定', adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度', 'rows=' + adjRowCount + ' ' + adjNames.join('/')) // ---------- v1.16:右栏常驻调色面板 / 两处同步 / 可拖宽度 / 字号 ---------- const sideSurface = await page.evaluate(() => { const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]') if (!side) return null const tabs = [...side.querySelectorAll('.iwb-color-pop-tab')] return { tabs: tabs.length, visibleTabs: tabs.filter(t => !t.hidden).length, swatches: side.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]').length, sv: !!side.querySelector('.iwb-color-sv'), hue: !!side.querySelector('.iwb-color-hue'), hex: !!side.querySelector('.iwb-editor-color-hex-input') } }) check('右栏有常驻调色面板:可调颜色项 + 调色器 + 12 个常用色', Boolean(sideSurface) && sideSurface.tabs === 3 && sideSurface.visibleTabs >= 1 && sideSurface.swatches === 12 && sideSurface.sv && sideSurface.hue && sideSurface.hex, JSON.stringify(sideSurface)) // 在右栏点常用色 → 弹层里同一色块也必须高亮(两处共用一份颜色状态) await page.locator('.iwb-editor-left [data-color-surface="side"] [data-panel-color="#00bfa5"]').click() await page.waitForTimeout(220) const colorSync = await page.evaluate(() => { // 只看「常用色」网格:最近使用里同色也会高亮,那是正常的两处提示,不该算进断言 const activeIn = (root) => [...root.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')] .filter(b => b.classList.contains('active')).map(b => b.dataset.panelColor) const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]') const pop = document.querySelector('.iwb-editor-color-pop') return { side: activeIn(side), pop: activeIn(pop), color: window.__iwbEditor.__debug().color } }) check('右栏选色后弹层同一色块同步高亮(不是两套各管各的)', colorSync.side.length === 1 && colorSync.side[0] === '#00bfa5' && colorSync.pop.length === 1 && colorSync.pop[0] === '#00bfa5' && colorSync.color === '#00bfa5', JSON.stringify(colorSync)) // 拖右栏宽度:侧栏在画布右侧,指针左移 80px ⇒ 宽 80px const sideW0 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width)) const grip = await page.locator('.iwb-editor-side-resizer').boundingBox() await page.mouse.move(grip.x + grip.width / 2, grip.y + grip.height / 2) await page.mouse.down() await page.mouse.move(grip.x + grip.width / 2 - 80, grip.y + grip.height / 2, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(180) const sideW1 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width)) check('拖右栏手柄:宽度随拖动变大(不是固定 220)', sideW1 >= sideW0 + 70 && sideW1 <= 520, sideW0 + ' → ' + sideW1) await page.locator('.iwb-editor-side-resizer').dblclick() await page.waitForTimeout(180) const sideW2 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width)) // 注意:aside 是 content-box,width 280 + 左右 padding 24 ⇒ rect 约 304/305。 // 这里跟「拖之前」比才对,写死 280 会误判。 check('双击手柄复位到默认宽度(回到拖动前)', Math.abs(sideW2 - sideW0) <= 2, sideW0 + ' ← ' + sideW2) const fontSizes = await page.evaluate(() => ({ adjName: getComputedStyle(document.querySelector('.iwb-editor-adj-name')).fontSize, adjTitle: getComputedStyle(document.querySelector('.iwb-editor-adj-title')).fontSize, statusbar: getComputedStyle(document.querySelector('.iwb-editor-statusbar')).fontSize, optionbar: getComputedStyle(document.querySelector('.iwb-editor-optionbar')).fontSize, layerName: document.querySelector('.iwb-layer-name') ? getComputedStyle(document.querySelector('.iwb-layer-name')).fontSize : null })) check('整体字号提升一档(面板行名 12.5 / 标题 13 / 状态栏 12 / 选项栏 13)', fontSizes.adjName === '12.5px' && fontSizes.adjTitle === '13px' && fontSizes.statusbar === '12px' && fontSizes.optionbar === '13px' && (!fontSizes.layerName || fontSizes.layerName === '13px'), JSON.stringify(fontSizes)) /** 合成整幅可见像素后统计:平均亮度 / 灰像素占比 / R、B 均值 */ const adjStat = () => page.evaluate(() => { const list = [...document.querySelectorAll('.iwb-editor-layer-canvas')] if (!list.length) return null const w = list[0].width, h = list[0].height const c = document.createElement('canvas') c.width = w; c.height = h const x = c.getContext('2d') for (const el of list) x.drawImage(el, 0, 0) const d = x.getImageData(0, 0, w, h).data let lum = 0, n = 0, gray = 0, r = 0, b = 0 for (let i = 0; i < d.length; i += 4) { if (d[i + 3] === 0) continue lum += (d[i] + d[i + 1] + d[i + 2]) / 3 if (Math.abs(d[i] - d[i + 1]) < 3 && Math.abs(d[i + 1] - d[i + 2]) < 3) gray++ r += d[i]; b += d[i + 2]; n++ } return n ? { lum: Math.round(lum / n), gray: +(gray / n).toFixed(2), r: Math.round(r / n), b: Math.round(b / n) } : null }) /** 设一个调节项的数值(模拟在数值框里输入并提交) */ const adjSet = async (key, val) => { await page.evaluate(({ key, val }) => { const row = document.querySelector(`.iwb-editor-adj-row[data-adj="${key}"]`) const num = row.querySelector('.iwb-editor-adj-val') num.value = String(val) num.dispatchEvent(new Event('input', { bubbles: true })) num.dispatchEvent(new Event('change', { bubbles: true })) }, { key, val }) await page.waitForTimeout(240) } const adjReset = async () => { const btn = page.locator('[data-adj-reset="all"]') if (await btn.isEnabled()) { await btn.click(); await page.waitForTimeout(260) } } const adjBase = await adjStat() await adjSet('exposure', 100) const adjBright = await adjStat() check('曝光 +100 明显提亮(不是「看不出变化」的强度)', adjBright && adjBase && adjBright.lum > adjBase.lum + 25, '亮度 ' + (adjBase && adjBase.lum) + ' → ' + (adjBright && adjBright.lum)) await adjReset() await adjSet('saturation', -100) const adjGray = await adjStat() check('饱和度 -100 完全去色(灰像素接近 100%)', adjGray && adjGray.gray > 0.9, '灰占比 ' + (adjGray && adjGray.gray)) await adjReset() await adjSet('temp', 100) const adjWarm = await adjStat() check('温度 +100 偏暖:R 通道升、B 通道降', adjWarm && adjBase && adjWarm.r > adjBase.r && adjWarm.b < adjBase.b, 'R ' + (adjBase && adjBase.r) + '→' + (adjWarm && adjWarm.r) + ' B ' + (adjBase && adjBase.b) + '→' + (adjWarm && adjWarm.b)) const adjDirty = (await dbg()).adjust check('调节参数写回状态(debug 可观测,供后续撤销断言)', adjDirty.params && adjDirty.params.temp === 100 && adjDirty.hasSource, JSON.stringify(adjDirty.params)) await adjReset() const adjBack = await adjStat() check('「复位」把所有项归零,像素回到原图', adjBack && adjBase && Math.abs(adjBack.lum - adjBase.lum) <= 1 && Math.abs(adjBack.r - adjBase.r) <= 1, '亮度 ' + (adjBack && adjBack.lum) + ' vs ' + (adjBase && adjBase.lum)) // 一次拖动 = 一步历史(6 次 input + 1 次 change) // 注意不能比 history.length:历史栈有容量上限,push 到底后是「进一条、淘汰一条」, // 长度永远不变(第一次跑就是被这个坑到)。数标签出现次数才准。 const adjLabelCount = async () => (await dbg()).historyLabels.filter(l => l === '图片调节').length const adjH0 = await adjLabelCount() for (const v of [20, 40, 60, 80, 90, 100]) { await page.evaluate(({ v }) => { const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range') r.value = String(v) r.dispatchEvent(new Event('input', { bubbles: true })) }, { v }) } await page.evaluate(() => { const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range') r.dispatchEvent(new Event('change', { bubbles: true })) }) await page.waitForTimeout(320) const adjH1 = await adjLabelCount() check('拖一次滑杆只记 1 步历史(不是每帧一步)', adjH1 === adjH0 + 1, '图片调节 标签 ' + adjH0 + ' → ' + adjH1) await page.keyboard.press('Control+z') await page.waitForTimeout(320) const adjUndo = (await dbg()).adjust check('Ctrl+Z 撤销调节后滑块归零(参数不能和画面对不上)', adjUndo.params && adjUndo.params.exposure === 0, 'exposure=' + (adjUndo.params && adjUndo.params.exposure)) // 切图层:面板 target 跟随,切回来参数恢复 await adjSet('exposure', 40) const adjKept = (await dbg()).adjust.params.exposure await page.locator('[data-action="addBlankLayer"]').click() await page.waitForTimeout(400) const adjTargetNew = await page.locator('.iwb-editor-adj-target').textContent() const adjNewParams = (await dbg()).adjust.params await page.evaluate(() => { const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || '')) if (base) base.click() }) await page.waitForTimeout(420) const adjBackParams = (await dbg()).adjust.params check('切图层时调节面板跟随新层,切回原层参数恢复', /空白图层/.test(adjTargetNew) && adjNewParams && adjNewParams.exposure === 0 && adjBackParams.exposure === adjKept, '新层=' + adjTargetNew + ' 新层exp=' + (adjNewParams && adjNewParams.exposure) + ' 回到原图exp=' + adjBackParams.exposure) await adjReset() // 退出前先记一笔:此时调过曝光/温度,缓存里必然有 'base' 条目, // 下面 Round 3 用它证明「退出确实把缓存清掉了」,而不是本来就没缓存。 const adjCacheBefore = (await dbg()).adjustCacheSize check('前置:调过之后基准缓存里有条目', adjCacheBefore > 0, 'cache=' + adjCacheBefore) 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)) // ---------- Round 3:退出再打开,调节基准必须重建 ---------- // 原图图层的 id 是写死的 'base',而 adjust.js 的基准缓存以 layer.id 为 key。 // 退出时不清缓存 ⇒ 第二张图 captureFor('base') 命中上一张图的像素, // 表现为「编辑另一张图时一调节,画面还原成上一张」—— 100% 复现,不是偶发。 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 adjFresh = await dbg() check('退出重开:调节基准缓存清空、无残留 source 与 layerId(否则第二张图会串上一张的像素)', adjFresh.adjustCacheSize === 0 && adjFresh.adjust.hasSource === false && adjFresh.adjust.layerId === null, 'cache=' + adjFresh.adjustCacheSize + ' layerId=' + adjFresh.adjust.layerId + ' hasSource=' + adjFresh.adjust.hasSource) const adjBase2 = await adjStat() await adjSet('exposure', 100) const adjBright2 = await adjStat() check('重开后调节以新图像素为基准:曝光 +100 正常提亮(不是把旧图重算上来)', adjBase2 && adjBright2 && adjBright2.lum > adjBase2.lum + 25, '亮度 ' + (adjBase2 && adjBase2.lum) + ' → ' + (adjBright2 && adjBright2.lum)) await adjReset() await page.locator('[data-action="cancel"]').click() check('无运行时错误 / 无弹窗', errors.length === 0, errors.slice(0, 3).join(' | ')) await browser.close() console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过')) process.exit(failed ? 1 : 0)