上一次提交停在 1.2.12,本次把 1.3.0 → 1.6.0 四个版本的源码一并归档。 v1.3.0 色板进工具栏 + 矢量/文字工具只负责创建 - 工具栏最左色点 → 弹层(前调色器、后颜色设置 + 推荐颜色) - 弹层必须挂 .iwb-editor-modal 下:工具栏是 overflow-x:auto、画布 wrap 是 overflow:clip,塞进去会被裁 - applyColorChange 改 pointerdown 拍一次快照,修「拖调色器爆撤销栈」 - 每次按下前从 S.color 重同步 hsv,修「点推荐色后再拖 SV 跳回红」 - 外部点击改 document 捕获阶段监听(画布 mousedown preventDefault,冒泡收不到) - onShapeMouseDown / onTextMouseDown 不再命中已有对象;setTool 的 keepSel 只剩 select|picker v1.4.0 侧栏快速效果 - 6 个:反白(反相,非排版意义的黑底白字)/ 灰度 / 提亮 / 压暗 / 高对比 / 马赛克 - 目标是当前位图图层,标题右侧实时显示层名;不碰图层几何也不改 image - 导入图片层先克隆栅格化成「xxx · 效果」层、原层 visible=false(直接改像素会被 redraw 冲掉) - 撤销走快照,base 与画笔层走像素路径 v1.5.0 画完自动回 V,编辑统一走 V - 图形/文字落笔完成即退出当前工具并切 V - 钢笔改为只用 V 双击进节点编辑 - 双击判定改成自算 380ms 窗口:单击选中会重绘矢量画布,浏览器不再派发 dblclick v1.6.0 笔刷环 + 图层合并 - 画笔用 [ / ] 调粗细时立刻刷新笔刷环(原来只在 mousemove 里 drawToolRing,键改后不动) - 图层合并:⌘/Ctrl 点击多选后合并、⌘E 向下合并、⌘⇧E 合并可见(PS 语义) - 统一用 composeUnitsInto 合成并按结果重排 z,避免合并后像素为空 - 隐藏层不参与且保留;矢量(文字/形状/钢笔)直接栅格化 - 有 base 参与时写回 base(像素快照可逐像素撤销),否则新建位图层承载 harness 129 项全通。1.6.0 已发布到线上: plugin-image-annotate.198a20e4d722.js / sha256-GYog5NcinRDM67in67JxJUtBhUPB2lfttM/kw9UHwFo=
1314 lines
74 KiB
JavaScript
1314 lines
74 KiB
JavaScript
// 标注插件本地端到端(开发用,不进 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')
|
||
|
||
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('<!doctype html><html><head><meta charset="utf-8"></head><body><div id="host"></div></body></html>')
|
||
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 === '1.6.0', 'version=' + boot.version)
|
||
check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(','))
|
||
|
||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||
const dbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||
const pixel = (cx, cy) => page.evaluate(({ x, y }) => {
|
||
const d = window.__iwbEditor.__debug()
|
||
return { base: d.pixel('base', x, y), draw: d.pixel('draw', x, y), layers: d.layers.map(l => ({ id: l.id, a: d.pixel(l.id, x, y) })) }
|
||
}, { x: cx, y: cy })
|
||
|
||
check('编辑器打开 + 便利 UI 五区齐全(v1.2.4 起命令带取代「更多」菜单)', await page.evaluate(() => {
|
||
const q = (s) => Boolean(document.querySelector(s))
|
||
return q('.iwb-editor-optionbar') && q('.iwb-editor-statusbar') && q('.iwb-editor-sel-bar') &&
|
||
q('.iwb-editor-toast') && q('.iwb-editor-selection-overlay') && q('.iwb-editor-cursor-overlay') &&
|
||
q('[data-action="download"]') && q('.iwb-editor-commands')
|
||
}))
|
||
check('新增选区工具按钮', (await page.locator('.iwb-editor-tool[data-tool="marquee"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-tool[data-tool="lasso"]').count()) === 1)
|
||
|
||
check('modal 铺满视口、状态栏贴在 modal 底部(防多余 </div> 把状态栏挤成 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"]') &&
|
||
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"]').click()
|
||
await page.waitForTimeout(100)
|
||
if (!(await pop.isVisible())) return 'post: 点了没开'
|
||
const box = await pop.boundingBox()
|
||
const vp = page.viewportSize()
|
||
const inView = box && box.x >= 0 && box.y >= 0 &&
|
||
box.x + box.width <= vp.width + 1 && box.y + box.height <= vp.height + 1
|
||
// Esc 关掉(顺带验证 Esc 优先收弹层),不影响后面的用例
|
||
await page.keyboard.press('Escape')
|
||
await page.waitForTimeout(80)
|
||
return inView && !(await pop.isVisible()) ? true : 'box=' + JSON.stringify(box)
|
||
})())
|
||
|
||
const drag = async (x1, y1, x2, y2) => {
|
||
await page.mouse.move(x1, y1)
|
||
await page.mouse.down()
|
||
await page.mouse.move(x2, y2, { steps: 8 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(120)
|
||
}
|
||
|
||
// ---------- P1 选区 ----------
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await drag(imgBox.x + imgBox.width * 0.25, imgBox.y + imgBox.height * 0.25,
|
||
imgBox.x + imgBox.width * 0.7, imgBox.y + imgBox.height * 0.7)
|
||
const sel = (await dbg()).selection
|
||
check('拖出矩形选区 + 蚂蚁线启动', Boolean(sel && sel.w > 5 && sel.h > 5) && (await dbg()).ants, JSON.stringify(sel))
|
||
check('选区浮动操作条自动出现', await page.locator('.iwb-editor-sel-bar').isVisible())
|
||
const cx = Math.round(sel.x + sel.w / 2)
|
||
const cy = Math.round(sel.y + sel.h / 2)
|
||
const beforeFill = await pixel(cx, cy)
|
||
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click()
|
||
const afterFill = await pixel(cx, cy)
|
||
check('填充只写当前层(base 像素不变)',
|
||
afterFill.draw && afterFill.draw[3] > 0 && JSON.stringify(afterFill.base) === JSON.stringify(beforeFill.base),
|
||
'draw=' + JSON.stringify(afterFill.draw) + ' base=' + JSON.stringify(afterFill.base))
|
||
check('原图锁定时填充自动落「标注」层(不写进原图)',
|
||
(await dbg()).layers.some(l => l.id === 'draw' && l.name.indexOf('标注') === 0),
|
||
JSON.stringify((await dbg()).layers.map(l => l.name)))
|
||
|
||
const layersBeforeCopy = (await dbg()).layers.length
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.copy"]').click()
|
||
const afterCopy = await dbg()
|
||
check('复制为新层:像素落在选区原位、原层不变',
|
||
afterCopy.layers.length === layersBeforeCopy + 1 && (await pixel(cx, cy)).draw[3] > 0,
|
||
'层数 ' + layersBeforeCopy + ' → ' + afterCopy.layers.length)
|
||
check('复制来源为当前层:新层有填充像素', afterCopy.layers.some(l => l.name === '选区副本') &&
|
||
(await pixel(cx, cy)).layers.some(v => v.id !== 'base' && v.id !== 'draw' && v.a && v.a[3] > 0))
|
||
await page.keyboard.press('Control+z')
|
||
check('Ctrl+Z 撤销「复制为新层」(图层数可回退)', (await dbg()).layers.length === layersBeforeCopy, '层数=' + (await dbg()).layers.length)
|
||
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]').click()
|
||
const afterDelete = await pixel(cx, cy)
|
||
check('Delete 只清当前层:draw 挖空、base 与其它层原样',
|
||
afterDelete.draw[3] === 0 && JSON.stringify(afterDelete.base) === JSON.stringify(beforeFill.base),
|
||
'draw=' + JSON.stringify(afterDelete.draw) + ' base=' + JSON.stringify(afterDelete.base))
|
||
await page.keyboard.press('Control+z')
|
||
check('Ctrl+Z 恢复被清除的像素', (await pixel(cx, cy)).draw[3] > 0)
|
||
|
||
// 三入口共用命令层
|
||
await page.keyboard.press('Control+j')
|
||
const afterHotkey = await dbg()
|
||
check('快捷键 Ctrl+J 与浮动条共用 execute()',
|
||
afterHotkey.layers.length === layersBeforeCopy + 1 && afterHotkey.historyLabels.includes('复制为新层'),
|
||
'labels=' + JSON.stringify(afterHotkey.historyLabels.slice(-3)))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
await page.mouse.click(imgBox.x + imgBox.width * 0.8, imgBox.y + imgBox.height * 0.2, { button: 'right' })
|
||
check('右键菜单复用同一条操作条', await page.locator('.iwb-editor-sel-bar.as-menu').count() === 1)
|
||
|
||
// ---------- 还原原图(用户裁定:全部还原 + 可撤销) ----------
|
||
await page.keyboard.press('Control+a') // 重建选区(右键/工具切换不会改像素)
|
||
await page.keyboard.press('Control+j') // 制造一个额外的选区副本层
|
||
const beforeReset = await dbg()
|
||
await page.locator('[data-action="reset"]').click()
|
||
const afterReset = await dbg()
|
||
check('还原原图:只剩「原图」单层(默认不再预建画笔层)',
|
||
afterReset.layers.length === 1 && afterReset.layers.some(l => l.id === 'base'),
|
||
JSON.stringify(afterReset.layers.map(l => l.name)))
|
||
check('还原原图清空矢量/选区但保留 base 像素',
|
||
!afterReset.selection && JSON.stringify((await pixel(cx, cy)).base) === JSON.stringify(beforeFill.base))
|
||
await page.keyboard.press('Control+z')
|
||
const afterUndoReset = await dbg()
|
||
check('Ctrl+Z 完整恢复还原前的图层结构(含被删的选区副本层)',
|
||
beforeReset.layers.length === 3 && afterUndoReset.layers.length === beforeReset.layers.length,
|
||
'还原前 ' + beforeReset.layers.length + ' → 还原后 ' + afterReset.layers.length + ' → 撤销后 ' + afterUndoReset.layers.length)
|
||
|
||
// ---------- 单张输出预设(≤500KB) ----------
|
||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||
await page.locator('[data-export-key="preset"][data-export-value="ecom800"]').click()
|
||
const opt = (await dbg()).exportOptions
|
||
check('≤500KB 预设可切换并存 ctx.settings', opt.preset === 'ecom800' && opt.maxKB === 500 &&
|
||
(await page.evaluate(() => window.__settings.exportPreset)) === 'ecom800', JSON.stringify(opt))
|
||
await page.locator('[data-action="download"]').click()
|
||
const exported = await poll(async () => (await dbg()).lastExport)
|
||
check('下载只产一个结果:800×800 且 ≤500KB、编辑器不关闭',
|
||
Boolean(exported && exported.width === 800 && exported.height === 800 && exported.bytes <= 500 * 1024 &&
|
||
await page.locator('#iwb-editor-overlay').isVisible()), JSON.stringify(exported))
|
||
// 输出面板的可见性/文案探针:面板收起时子元素 display 不在布局里,
|
||
// 所以统一读 textContent 而不是 innerText(后者对隐藏元素返回空串)。
|
||
const summaryText = () => page.locator('.iwb-editor-export-summary').textContent()
|
||
const noteText = () => page.locator('.iwb-editor-export-note').textContent()
|
||
const ecomRowsVisible = () => page.evaluate(() => {
|
||
const rows = Array.from(document.querySelectorAll('[data-export-when="ecom800"]'))
|
||
return rows.length >= 2 && rows.every(r => !r.hidden)
|
||
})
|
||
|
||
check('电商预设:摘要写明尺寸/格式/背景/体积上限',
|
||
/800×800/.test(await summaryText()) && /≤500KB/.test(await summaryText()) && /透明/.test(await summaryText()),
|
||
await summaryText())
|
||
await page.locator('[data-action="toggleExportSettings"]').click() // 上一步点「下载」会自动收起面板
|
||
check('电商预设:边长与体积控件可见', await ecomRowsVisible())
|
||
|
||
await page.locator('[data-export-key="format"][data-export-value="jpeg"]').click()
|
||
const afterJpg = await dbg()
|
||
check('选 JPG:背景自动收敛为白底并写回 settings(不再「显示透明、实际白底」)',
|
||
afterJpg.exportOptions.bg === 'white' &&
|
||
(await page.evaluate(() => window.__settings.exportBg)) === 'white' &&
|
||
(await page.locator('[data-export-key="bg"][data-export-value="transparent"]').isDisabled()) === true,
|
||
JSON.stringify(afterJpg.exportOptions))
|
||
check('JPG 摘要显示白底', /白底/.test(await summaryText()), await summaryText())
|
||
await page.locator('[data-action="download"]').click()
|
||
const jpg = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.format === 'jpeg' ? d.lastExport : false })
|
||
check('格式/背景切换生效(JPG + 白底)', Boolean(jpg) && jpg.bg === 'white', JSON.stringify(jpg))
|
||
check('下载后摘要记录上次输出(尺寸 + 体积)',
|
||
/上次输出 800×800/.test(await noteText()), await noteText())
|
||
|
||
// 边长 / 体积上限:原来只有计算没有控件,改完必须能真的改到并生效
|
||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||
await page.locator('[data-export-key="size"][data-export-value="1000"]').click()
|
||
await page.locator('[data-export-key="maxKB"][data-export-value="300"]').click()
|
||
const optSized = (await dbg()).exportOptions
|
||
check('边长/体积控件可改并持久化到 ctx.settings',
|
||
optSized.size === 1000 && optSized.maxKB === 300 &&
|
||
(await page.evaluate(() => window.__settings.exportSize)) === 1000 &&
|
||
(await page.evaluate(() => window.__settings.exportMaxKB)) === 300, JSON.stringify(optSized))
|
||
await page.locator('[data-action="download"]').click()
|
||
const sized = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.width === 1000 ? d.lastExport : false })
|
||
check('边长生效:输出 1000×1000 且体积 ≤300KB',
|
||
Boolean(sized) && sized.width === 1000 && sized.bytes <= 300 * 1024, JSON.stringify(sized))
|
||
|
||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||
await page.locator('[data-export-key="preset"][data-export-value="original"]').click()
|
||
const optOriginal = (await dbg()).exportOptions
|
||
check('切回原尺寸:maxKB 归零并写回 settings(重开不会让限制「复活」)',
|
||
optOriginal.preset === 'original' && optOriginal.maxKB === 0 &&
|
||
(await page.evaluate(() => window.__settings.exportMaxKB)) === 0, JSON.stringify(optOriginal))
|
||
check('原尺寸下边长/体积控件隐藏', (await ecomRowsVisible()) === false)
|
||
check('原尺寸摘要显示实际像素尺寸', /原尺寸 96×64/.test(await summaryText()), await summaryText())
|
||
await page.locator('[data-action="toggleExportSettings"]').click() // 收起,恢复后续用例的初始态
|
||
|
||
// ---------- 选区与裁剪互斥 ----------
|
||
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
|
||
check('切到裁剪会清掉选区,裁剪参数出现在选项栏(不再有画布下方浮窗)',
|
||
!(await dbg()).selection &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-action="confirmCrop"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-ratio="1:1"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-crop-bar').count()) === 0)
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
check('切回选区:裁剪控件从选项栏消失、裁剪框取消',
|
||
await page.evaluate(() => !document.querySelector('[data-action="confirmCrop"]')))
|
||
|
||
// ---------- 回归:矢量对象经撤销/重做后仍可渲染(快照不得把 DOM 画布序列化成 {}) ----------
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await drag(imgBox.x + imgBox.width * 0.2, imgBox.y + imgBox.height * 0.2,
|
||
imgBox.x + imgBox.width * 0.45, imgBox.y + imgBox.height * 0.45)
|
||
await page.keyboard.press('Control+z')
|
||
await page.keyboard.press('Control+Shift+z')
|
||
check('矢量对象撤销/重做后画布正常重建', await page.evaluate(() =>
|
||
document.querySelectorAll('.iwb-editor-vec-canvas').length >= 1))
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
|
||
// ---------- 旧流程回归:粘贴一步落层 + 覆盖写回 ----------
|
||
const beforePaste = (await dbg()).layers.length
|
||
await page.evaluate((png) => {
|
||
const bin = atob(png.split(',')[1])
|
||
const bytes = new Uint8Array(bin.length)
|
||
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i)
|
||
const dt = new DataTransfer()
|
||
dt.items.add(new File([bytes], 'paste.png', { type: 'image/png' }))
|
||
document.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }))
|
||
}, PNG)
|
||
const pasted = await poll(async () => (await dbg()).layers.length === beforePaste + 1)
|
||
check('粘贴图片一步落层(不再需要 Enter 确认)', Boolean(pasted), '层数 ' + beforePaste + ' → ' + (await dbg()).layers.length)
|
||
await page.keyboard.press('Enter')
|
||
check('粘贴后按 Enter 不会重复落层', (await dbg()).layers.length === beforePaste + 1)
|
||
|
||
await page.locator('[data-action="replace"]').click()
|
||
const wrote = await poll(async () => page.evaluate(() => window.__writes.some(w => w.kind === 'replace')))
|
||
check('覆盖仍回写宿主节点并关闭编辑器', Boolean(wrote) &&
|
||
(await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false, JSON.stringify(await page.evaluate(() => window.__writes)))
|
||
|
||
// ---------- Round 2:P1 缺陷回归(新会话,逐条对应已确认缺陷) ----------
|
||
// 走 glue 的 openEditor:只有它能把「退出」与宿主 Promise 的结算连起来验证。
|
||
await page.evaluate(() => {
|
||
window.__openState = null
|
||
window.__commands['annotate-selected'].run().then(
|
||
(mode) => { window.__openState = { mode: String(mode) } },
|
||
(err) => { window.__openState = { error: String((err && err.message) || err) } }
|
||
)
|
||
})
|
||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||
await page.waitForFunction(() => window.__iwbEditor.__debug().open === true)
|
||
const box2 = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
const drag2 = async (x1, y1, x2, y2) => {
|
||
await page.mouse.move(x1, y1)
|
||
await page.mouse.down()
|
||
await page.mouse.move(x2, y2, { steps: 8 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(120)
|
||
}
|
||
|
||
// ---- Fix1:反选后 Delete / 复制必须作用整幅(与填充一致) ----
|
||
await page.keyboard.press('Control+a')
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click()
|
||
const fullFill = await pixel(6, 6)
|
||
check('Fix1 前置:全选填充整层', fullFill.draw[3] > 0)
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3,
|
||
box2.x + box2.width * 0.6, box2.y + box2.height * 0.6)
|
||
const sel2 = (await dbg()).selection
|
||
const cx2 = Math.round(sel2.x + sel2.w / 2)
|
||
const cy2 = Math.round(sel2.y + sel2.h / 2)
|
||
await page.keyboard.press('Control+Shift+i')
|
||
const inv = (await dbg()).selection
|
||
check('反选:标记 inverted 且蚂蚁线仍在', Boolean(inv && inv.inverted) && (await dbg()).ants, JSON.stringify(inv))
|
||
await page.keyboard.press('Delete')
|
||
const invKeep = await pixel(cx2, cy2)
|
||
const invGone = await pixel(6, 6)
|
||
check('反选 + Delete:原选区内保留、原选区外挖空、base 不变',
|
||
invGone.draw[3] === 0 && invKeep.draw[3] > 0 && JSON.stringify(invGone.base) === JSON.stringify(fullFill.base),
|
||
'inside=' + JSON.stringify(invKeep.draw) + ' outside=' + JSON.stringify(invGone.draw))
|
||
await page.keyboard.press('Control+z')
|
||
check('反选 + Delete 可 Ctrl+Z 回退(掩膜 tile 边界未偏移)', (await pixel(6, 6)).draw[3] > 0)
|
||
|
||
const layersBeforeInvCopy = (await dbg()).layers.length
|
||
await page.keyboard.press('Control+j')
|
||
const afterInvCopy = await dbg()
|
||
const invCopyLayer = afterInvCopy.layers[afterInvCopy.layers.length - 1]
|
||
const copyOutside = await pixel(6, 6)
|
||
const copyInside = await pixel(cx2, cy2)
|
||
const copyOutsidePx = copyOutside.layers.find(v => v.id === invCopyLayer.id).a
|
||
const copyInsidePx = copyInside.layers.find(v => v.id === invCopyLayer.id).a
|
||
check('反选 + Ctrl+J:新层只含原选区外像素,且与原层逐点对齐(不偏移)',
|
||
afterInvCopy.layers.length === layersBeforeInvCopy + 1 && invCopyLayer.name === '选区副本' &&
|
||
copyOutsidePx[3] > 0 && copyOutsidePx.join(',') === copyOutside.draw.join(',') && copyInsidePx[3] === 0,
|
||
'outside=' + JSON.stringify(copyOutsidePx) + ' draw=' + JSON.stringify(copyOutside.draw) + ' inside=' + JSON.stringify(copyInsidePx))
|
||
await page.keyboard.press('Control+z') // 撤销复制新层
|
||
await page.keyboard.press('Control+d') // 取消选区
|
||
|
||
// feather>0:整幅 tile 不能把羽化边界变成硬切
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('6')
|
||
await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3,
|
||
box2.x + box2.width * 0.6, box2.y + box2.height * 0.6)
|
||
const selF = (await dbg()).selection
|
||
await page.keyboard.press('Control+Shift+i')
|
||
const afterInvert = await dbg()
|
||
await page.keyboard.press('Delete')
|
||
const afterDel = await dbg()
|
||
const edgeAlphas = []
|
||
for (let dx = -6; dx <= 6; dx++) {
|
||
edgeAlphas.push((await pixel(Math.round(selF.x) + dx, Math.round(selF.y + selF.h / 2))).draw[3])
|
||
}
|
||
const edgeDbg = await dbg()
|
||
check('反选 + 羽化 6px:边界仍是渐变(羽化未因整幅掩膜失效)',
|
||
selF.feather === 6 && edgeAlphas.some(a => a > 0 && a < 255),
|
||
JSON.stringify(edgeAlphas) + ' feather=' + selF.feather + ' active=' + edgeDbg.activeLayerId +
|
||
' inv=' + (afterInvert.selection && afterInvert.selection.inverted) +
|
||
' hist=' + afterDel.historyLabels.slice(-2).join('/') +
|
||
' sel=' + JSON.stringify(afterDel.selection))
|
||
await page.keyboard.press('Control+z')
|
||
await page.keyboard.press('Control+d')
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('0')
|
||
|
||
// ---- Fix3:选中形状时建立像素选区,Delete 语义必须切到「清像素」 ----
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await drag2(box2.x + box2.width * 0.35, box2.y + box2.height * 0.35,
|
||
box2.x + box2.width * 0.65, box2.y + box2.height * 0.65)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5)
|
||
const shapeSelected = await dbg()
|
||
check('前置:形状已绘制并处于选中态',
|
||
shapeSelected.shapes.length === 1 && shapeSelected.selectedShapeId === shapeSelected.shapes[0].id,
|
||
JSON.stringify(shapeSelected.shapes))
|
||
await page.keyboard.press('Control+a')
|
||
const selAllShape = (await dbg()).selection
|
||
await page.keyboard.press('Delete')
|
||
const afterShapeDelete = await dbg()
|
||
const shapeDeletePixel = await pixel(cx2, cy2)
|
||
check('选中形状 → Ctrl+A → Delete ⇒ 形状仍在、当前层像素被清(全选语义)',
|
||
Boolean(selAllShape && selAllShape.w >= 96 && selAllShape.h >= 64) &&
|
||
afterShapeDelete.shapes.length === 1 && afterShapeDelete.selectedShapeId === null &&
|
||
shapeDeletePixel.draw[3] === 0,
|
||
'shapes=' + afterShapeDelete.shapes.length + ' draw=' + JSON.stringify(shapeDeletePixel.draw))
|
||
await page.keyboard.press('Control+z')
|
||
await page.keyboard.press('Control+d')
|
||
|
||
// ---- Fix2:裁剪与选区互斥(快捷键 / 顶栏全选图标 / 右键菜单三入口) + confirmCrop 清残留 ----
|
||
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
|
||
const cropStart = await dbg()
|
||
check('切到裁剪:旧选区被清、蚂蚁线停止', cropStart.selection === null && cropStart.ants === false)
|
||
await page.keyboard.press('Control+a')
|
||
const cropAfterA = await dbg()
|
||
check('裁剪中 Ctrl+A:不建选区、不启动蚂蚁线、浮动条不出现',
|
||
cropAfterA.selection === null && cropAfterA.ants === false &&
|
||
(await page.locator('.iwb-editor-sel-bar').isVisible()) === false)
|
||
check('裁剪模式下选项栏没有选区命令入口(selcmd 只属于选择工具)',
|
||
(await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()) === 0)
|
||
await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5, { button: 'right' })
|
||
const menuShown = await page.locator('.iwb-editor-sel-bar.as-menu').count()
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.all"]').click()
|
||
const cropAfterCtx = await dbg()
|
||
check('裁剪中右键菜单「全选」同样被拦',
|
||
menuShown === 1 && cropAfterCtx.selection === null && cropAfterCtx.ants === false)
|
||
|
||
await drag2(box2.x + box2.width * 0.1, box2.y + box2.height * 0.1,
|
||
box2.x + box2.width * 0.7, box2.y + box2.height * 0.7)
|
||
check('裁剪框可拉出(确认按钮可见)', await page.locator('[data-action="confirmCrop"]').isVisible())
|
||
await page.locator('[data-action="confirmCrop"]').click()
|
||
const cropped = await dbg()
|
||
check('确认裁剪:尺寸更新且无旧坐标系选区/蚂蚁线残留',
|
||
cropped.doc.w < 96 && cropped.doc.h < 64 && cropped.selection === null && cropped.ants === false,
|
||
JSON.stringify(cropped.doc))
|
||
await page.keyboard.press('Delete')
|
||
const afterCropDelete = await dbg()
|
||
check('裁剪后 Delete 不按旧 bbox 误擦(层数不变、底图仍有像素)',
|
||
afterCropDelete.layers.length === cropped.layers.length && (await pixel(5, 5)).base[3] > 0 &&
|
||
afterCropDelete.selection === null)
|
||
|
||
// ---- 裁剪进历史链(v1.2 非破坏性):可撤销、可重做、不 flatten ----
|
||
const cropLayers = cropped.layers.map(l => l.id)
|
||
await page.keyboard.press('Control+z')
|
||
const undoneCrop = await dbg()
|
||
check('裁剪可 Ctrl+Z:画布尺寸与图层结构都回到裁剪前',
|
||
undoneCrop.doc.w === 96 && undoneCrop.doc.h === 64 &&
|
||
undoneCrop.layers.length === cropLayers.length &&
|
||
cropLayers.every(id => undoneCrop.layers.some(l => l.id === id)),
|
||
'doc=' + JSON.stringify(undoneCrop.doc) + ' layers=' + undoneCrop.layers.map(l => l.id).join(','))
|
||
check('裁剪撤销后底图像素完整回填', (await pixel(5, 5)).base[3] > 0)
|
||
await page.keyboard.press('Control+Shift+z')
|
||
const redoneCrop = await dbg()
|
||
check('裁剪可重做:尺寸回到裁剪后',
|
||
redoneCrop.doc.w === cropped.doc.w && redoneCrop.doc.h === cropped.doc.h,
|
||
JSON.stringify(redoneCrop.doc))
|
||
|
||
// ---- 还原原图的「尺寸复位」分支:必须走统一重绘,摘要/蚂蚁线才跟着走 ----
|
||
// (该分支会 setupCanvas + 清历史,此前只调 updateAllUI,摘要停留在裁剪后尺寸)
|
||
const cropSummary = await summaryText()
|
||
await page.locator('[data-action="reset"]').click()
|
||
const restoredDoc = await dbg()
|
||
const restoredSummary = await summaryText()
|
||
check('还原原图复位尺寸后:输出摘要即时跟随(不停留在裁剪后尺寸)',
|
||
restoredDoc.doc.w === 96 && restoredDoc.doc.h === 64 &&
|
||
/原尺寸 96×64/.test(restoredSummary) && cropSummary !== restoredSummary,
|
||
cropSummary + ' → ' + restoredSummary)
|
||
check('还原原图复位尺寸后蚂蚁线已停、选区已清',
|
||
restoredDoc.ants === false && !restoredDoc.selection)
|
||
|
||
// ---- v1.2 选项栏:按工具出参数,形状线宽与画笔解耦 ----
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
check('画笔选项栏:大小 / 硬度 / 透明三个参数都在',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="brushSize"]').count()) >= 2 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="brushHardness"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="brushOpacity"]').count()) === 1)
|
||
const brushSizeBefore = (await dbg()).toolOptions.brushSize
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
check('矩形选项栏:线宽 + 描边/实心',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="shapeLineWidth"]').count()) >= 2 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"]').count()) === 1)
|
||
await page.locator('.iwb-editor-optionbar-body input[type="number"][data-opt="shapeLineWidth"]').fill('12')
|
||
const optAfterLw = (await dbg()).toolOptions
|
||
check('选项栏改线宽:只改形状线宽,画笔大小不受影响(已解耦)',
|
||
optAfterLw.shapeLineWidth === 12 && optAfterLw.brushSize === brushSizeBefore,
|
||
JSON.stringify(optAfterLw))
|
||
const shapesBefore = (await dbg()).shapes.length
|
||
const liveBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2,
|
||
liveBox.x + liveBox.width * 0.5, liveBox.y + liveBox.height * 0.5)
|
||
const shapesAfter = (await dbg()).shapes
|
||
check('新画的矩形直接用选项栏里的线宽 12',
|
||
shapesAfter.length === shapesBefore + 1 && shapesAfter[shapesAfter.length - 1].lw === 12,
|
||
JSON.stringify(shapesAfter.slice(-1)))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
// isTyping 修正:参数数字框里按 Ctrl+A / Delete 应该走画布命令,而不是被当打字吞掉
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await page.locator('.iwb-editor-optionbar-body input[data-opt="feather"]').fill('3')
|
||
await page.keyboard.press('Control+a')
|
||
const selAfterCtrlA = await dbg()
|
||
check('参数数字框里按 Ctrl+A 仍能全选(不再被当打字吞掉)',
|
||
Boolean(selAfterCtrlA.selection) &&
|
||
selAfterCtrlA.selection.w === selAfterCtrlA.doc.w && selAfterCtrlA.selection.h === selAfterCtrlA.doc.h,
|
||
JSON.stringify(selAfterCtrlA.selection))
|
||
await page.keyboard.press('Control+d')
|
||
|
||
// ---- v1.2.2:手柄只在选择工具出现 / 高亮跟随绘制目标 / 选项栏快捷点 / 侧栏实心移除 ----
|
||
|
||
// 侧栏「实心」按钮移除(选项栏 rect 工具已有描边/实心切换)
|
||
check('侧栏「实心」按钮已移除(选项栏承担该功能)',
|
||
(await page.locator('[data-action="toggleFill"]').count()) === 0)
|
||
|
||
// 快捷点:画笔大小
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
check('画笔选项栏有 4 个大小快捷点(16/24/32 已按用户裁定移除)',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"]').count()) === 4)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"][data-value="12"]').click()
|
||
check('点快捷点 12:笔刷大小即时生效且选项栏数字框同步',
|
||
(await dbg()).toolOptions.brushSize === 12 &&
|
||
await page.evaluate(() => {
|
||
const n = document.querySelector('.iwb-editor-optionbar-body input[type="number"][data-opt="brushSize"]')
|
||
return n && Number(n.value) === 12
|
||
}))
|
||
|
||
// 快捷点:矢量描边
|
||
await page.locator('.iwb-editor-tool[data-tool="arrow"]').click()
|
||
check('箭头选项栏有 7 个线宽快捷点',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"]').count()) === 7)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"][data-value="6"]').click()
|
||
check('点线宽快捷点 6:shapeLineWidth 即时生效',
|
||
(await dbg()).toolOptions.shapeLineWidth === 6)
|
||
|
||
// 高亮跟随绘制目标:画一笔后面板选中层 == 画笔目标层
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.75,
|
||
liveBox.x + liveBox.width * 0.65, liveBox.y + liveBox.height * 0.85)
|
||
const syncDbg = await dbg()
|
||
check('画笔落笔后面板高亮层 == 绘制目标层(不再「没选中却能画」)',
|
||
syncDbg.selectedLayerId === syncDbg.activeLayerId,
|
||
'selected=' + syncDbg.selectedLayerId + ' active=' + syncDbg.activeLayerId)
|
||
|
||
// 变换手柄只在 select 工具出现:画笔态 overlay 无手柄像素,切到选择工具后出现
|
||
const overlayAlpha = () => page.evaluate(() => {
|
||
const c = document.querySelector('.iwb-editor-crop-overlay')
|
||
if (!c) return -1
|
||
const cx = c.getContext('2d')
|
||
const d = cx.getImageData(0, 0, c.width, c.height).data
|
||
let n = 0
|
||
for (let i = 3; i < d.length; i += 4) if (d[i] > 0) n++
|
||
return n
|
||
})
|
||
check('画笔工具下选中层不画变换手柄(overlay 干净)', (await overlayAlpha()) === 0)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
check('切到选择工具后变换框/手柄出现(overlay 有像素)', (await overlayAlpha()) > 0)
|
||
await page.keyboard.press('Escape') // 清选中,避免影响后续
|
||
|
||
// 裁剪:Esc 取消 / Enter 确认
|
||
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15,
|
||
liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6)
|
||
check('拉出裁剪框后选项栏显示尺寸摘要',
|
||
(await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) !== '--')
|
||
await page.keyboard.press('Escape')
|
||
check('Esc 取消裁剪(摘要复位为 --)',
|
||
(await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) === '--')
|
||
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15,
|
||
liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6)
|
||
const docBeforeEnter = (await dbg()).doc
|
||
await page.keyboard.press('Enter')
|
||
const docAfterEnter = (await dbg()).doc
|
||
check('Enter 确认裁剪(画布尺寸变小、与按钮确认等效)',
|
||
docAfterEnter.w < docBeforeEnter.w && docAfterEnter.h < docBeforeEnter.h,
|
||
JSON.stringify(docBeforeEnter) + ' → ' + JSON.stringify(docAfterEnter))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
// ---- v1.2.8:底部浮动工具栏(Figma 风格,用户裁定 2026-11-04) ----
|
||
check('工具栏移入画布容器、横排悬浮底部居中(不再在顶栏)', await page.evaluate(() => {
|
||
const wrap = document.querySelector('.iwb-editor-canvas-wrap')
|
||
const tools = wrap && wrap.querySelector(':scope > .iwb-editor-tools')
|
||
if (!tools) return false
|
||
const w = tools.getBoundingClientRect(), c = wrap.getBoundingClientRect()
|
||
return w.height < w.width &&
|
||
Math.abs((w.left + w.right) / 2 - (c.left + c.right) / 2) <= 8 &&
|
||
c.bottom - w.bottom <= 30 &&
|
||
!document.querySelector('.iwb-editor-header > .iwb-editor-tools')
|
||
}))
|
||
check('适应窗口后图片底边不被工具条遮挡', await page.evaluate(() => {
|
||
const img = document.querySelector('.iwb-editor-layer-canvas')
|
||
const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools')
|
||
if (!img || !tools) return false
|
||
const i = img.getBoundingClientRect(), t = tools.getBoundingClientRect()
|
||
return i.bottom <= t.top + 2
|
||
}))
|
||
|
||
// ---- v1.2.3:橡皮修复 / 钢笔描边实心 / 顶栏输出组右置 ----
|
||
|
||
// 顶栏输出组(输出+下载+新建+覆盖+退出)贴最右(header 右内边距 12px)
|
||
check('顶栏输出/导出按钮组贴最右侧(用户裁定 2026-11-04)', await page.evaluate(() => {
|
||
const hdr = document.querySelector('.iwb-editor-header')
|
||
const ex = document.querySelector('.iwb-editor-header > .iwb-editor-export-actions')
|
||
const hist = document.querySelector('.iwb-editor-header > .iwb-editor-history')
|
||
if (!hdr || !ex || !hist) return false
|
||
const h = hdr.getBoundingClientRect(), e = ex.getBoundingClientRect()
|
||
return h.right - e.right <= 14 && e.left > hist.getBoundingClientRect().right
|
||
}))
|
||
|
||
// 橡皮:1.2.2 回归 —— events.js 少 import getActiveLayer,一按下就 ReferenceError,表现为「橡皮不能擦」
|
||
// 注意 pixel() 探针要的是图片坐标,不是屏幕坐标:liveBox 上的比例 = 图片上的比例
|
||
const IMG = { x: Math.round((await dbg()).doc.w * 0.42), y: Math.round((await dbg()).doc.h * 0.5) }
|
||
const probe = (id) => page.evaluate(({ id, x, y }) => window.__iwbEditor.__debug().pixel(id, x, y), { id, x: IMG.x, y: IMG.y })
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
|
||
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
|
||
const stampLayerId = (await dbg()).activeLayerId
|
||
const stampPx = await probe(stampLayerId)
|
||
const stampBasePx = await probe('base')
|
||
check('画笔落笔自动落「标注」层且该点有像素', stampPx && stampPx[3] > 0,
|
||
'layer=' + stampLayerId + ' px=' + JSON.stringify(stampPx))
|
||
// 回归(2026-11-04 用户反馈):首笔自动建层时新 canvas 没套视图样式,
|
||
// 以原始像素尺寸贴在 stack 原点 → 第一笔显示错位,滚轮缩放后才正常
|
||
check('首笔自动建的层立刻获得视图样式(尺寸/偏移与原图层一致,不再裸贴原点)', await page.evaluate((baseId) => {
|
||
const cs = Array.from(document.querySelectorAll('.iwb-editor-layer-canvas'))
|
||
const base = cs.find(c => c.style.width && parseFloat(c.style.left) > 0)
|
||
const fresh = cs[cs.length - 1]
|
||
return base && fresh && fresh.style.width === base.style.width &&
|
||
fresh.style.left === base.style.left && fresh.style.top === base.style.top
|
||
}, stampLayerId))
|
||
await page.locator('.iwb-editor-tool[data-tool="eraser"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
|
||
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
|
||
const erasedPx = await probe(stampLayerId)
|
||
const basePxAfterErase = await probe('base')
|
||
check('橡皮沿同一笔迹擦除(不抛错、目标层挖空、base 原样)',
|
||
erasedPx && erasedPx[3] === 0 && JSON.stringify(basePxAfterErase) === JSON.stringify(stampBasePx),
|
||
'erased=' + JSON.stringify(erasedPx))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
// 钢笔描边/实心切换(penFill 默认实心,只对闭合路径生效)
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
check('钢笔选项栏有 描边/实心 切换',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="pen"]').click()
|
||
const penFillOff = (await dbg()).toolOptions.penFill === false
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="pen"]').click()
|
||
check('钢笔样式切换写回 penFill(默认实心 → 描边 → 实心)',
|
||
penFillOff && (await dbg()).toolOptions.penFill === true)
|
||
|
||
// 橡皮兜底:只剩锁定的原图时用橡皮 → 明确提示而不是无声失败
|
||
await page.locator('[data-action="reset"]').click()
|
||
const layersAfterReset = (await dbg()).layers.length
|
||
await page.locator('.iwb-editor-tool[data-tool="eraser"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
|
||
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
|
||
const toastText = await page.locator('.iwb-editor-toast').textContent()
|
||
check('原图锁定且无标注层时用橡皮:提示「先画再擦」且不建层',
|
||
layersAfterReset === 1 && (await dbg()).layers.length === 1 && toastText.indexOf('可擦') >= 0,
|
||
'layers=' + layersAfterReset + ' toast=' + toastText)
|
||
await page.keyboard.press('Control+z') // 撤销还原,恢复图层结构
|
||
|
||
// ---- v1.2.4:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ----
|
||
|
||
check('「更多」菜单已移除;顶栏只留顺序/视图命令,图层新建/导入/合并在图层面板标题栏', await page.evaluate(() => {
|
||
const q = (s) => Boolean(document.querySelector(s))
|
||
const hdrCmds = document.querySelectorAll('.iwb-editor-header .iwb-editor-commands .iwb-editor-layer-btn').length
|
||
const titleBar = document.querySelector('.iwb-editor-layer-panel-header')
|
||
const addBtns = titleBar ? titleBar.querySelectorAll('.iwb-editor-layer-add-btn').length : 0
|
||
const hdrAdd = document.querySelector('.iwb-editor-header [data-action="addBlankLayer"], .iwb-editor-header [data-action="addBitmapLayer"]')
|
||
return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') && hdrCmds === 4 && !hdrAdd &&
|
||
addBtns === 4 && q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') &&
|
||
q('.iwb-editor-layer-panel-header [data-action="addBitmapLayer"]') &&
|
||
q('.iwb-editor-layer-panel-header [data-action="mergeLayers"]') &&
|
||
q('.iwb-editor-layer-panel-header [data-action="mergeVisible"]') &&
|
||
q('.iwb-editor-header [data-action="zoomFit"]') &&
|
||
q('.iwb-editor-header [data-action="togglePanels"]')
|
||
}))
|
||
|
||
check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => {
|
||
const svg = document.querySelector('.iwb-editor-header [data-action="reset"] svg')
|
||
if (!svg) return false
|
||
const paths = svg.querySelectorAll('path').length
|
||
const polys = Array.from(svg.querySelectorAll('polyline')).map(p => p.getAttribute('points')).join('|')
|
||
return paths >= 4 && polys.indexOf('3 6 5 6 21 6') < 0
|
||
}))
|
||
|
||
check('适应窗口按钮真的生效(放大后点它回到 fit 基线并居中)', await (async () => {
|
||
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
|
||
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
|
||
const zoomed = (await dbg()).zoom
|
||
await page.locator('.iwb-editor-header [data-action="zoomFit"]').click()
|
||
const fitted = (await dbg()).zoom
|
||
return zoomed > 1 && Math.abs(fitted - 1) < 0.001
|
||
})())
|
||
|
||
check('PS 快捷键:V/M/L/B/E/P/T/U/C/I/H 切工具', await (async () => {
|
||
// 先点一下工具按钮,保证焦点不在输入框里(isTyping() 会吞掉无修饰键快捷键)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
const seq = [['v', 'select'], ['m', 'marquee'], ['l', 'lasso'], ['b', 'brush'], ['e', 'eraser'],
|
||
['p', 'pen'], ['t', 'text'], ['u', 'rect'], ['c', 'crop'], ['i', 'picker'], ['h', 'hand']]
|
||
for (const [k, tool] of seq) {
|
||
await page.keyboard.press(k)
|
||
if ((await dbg()).tool !== tool) return false
|
||
}
|
||
return true
|
||
})())
|
||
|
||
check('Shift+U 在 矩形/圆形/箭头 间循环(PS 同类工具循环)', await (async () => {
|
||
await page.keyboard.press('u')
|
||
await page.keyboard.press('Shift+u')
|
||
const a = (await dbg()).tool
|
||
await page.keyboard.press('Shift+u')
|
||
const b = (await dbg()).tool
|
||
return a === 'circle' && b === 'arrow'
|
||
})())
|
||
|
||
check('Tab 收起 / 展开侧栏(PS 习惯)', await (async () => {
|
||
await page.keyboard.press('Tab')
|
||
const collapsed = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed'))
|
||
await page.keyboard.press('Tab')
|
||
const restored = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed'))
|
||
return collapsed === true && restored === false
|
||
})())
|
||
|
||
check('[ / ] 增减画笔大小(PS 习惯,画笔橡皮共用)', await (async () => {
|
||
await page.keyboard.press(']') // 3 → 5? 起始值不定,只验方向与 clamp
|
||
const up = (await dbg()).toolOptions.brushSize
|
||
await page.keyboard.press('[')
|
||
await page.keyboard.press('[')
|
||
const down = (await dbg()).toolOptions.brushSize
|
||
return up > down && down >= 1 && up <= 300
|
||
})())
|
||
|
||
check('Ctrl+1 = 100% 实际像素 / Ctrl+0 = 适应窗口', await (async () => {
|
||
await page.keyboard.press('Control+1')
|
||
const d1 = await dbg()
|
||
// S.zoom 是相对 fitW 的倍数:100% 实际像素 = doc.w / fit.w(小图会被放大铺满,所以可能 < 1)
|
||
const expect = d1.doc.w / d1.fit.w
|
||
const okActual = Math.abs(d1.zoom - expect) < 0.02
|
||
await page.keyboard.press('Control+0')
|
||
return okActual && Math.abs((await dbg()).zoom - 1) < 0.001
|
||
})())
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
check('选择工具的选项栏里有 全选/反选/取消 三个命令(竖工具条不再有)', await page.evaluate(() => {
|
||
const cmds = document.querySelectorAll('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more]')
|
||
const keys = Array.from(cmds).map(b => b.dataset.more).join(',')
|
||
return cmds.length === 3 && keys === 'sel.all,sel.invert,sel.none' &&
|
||
!document.querySelector('.iwb-editor-tools .iwb-editor-selcmd')
|
||
}))
|
||
|
||
await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more="sel.all"]').click()
|
||
const selAllDbg = await dbg()
|
||
check('点选项栏「全选」= Ctrl+A(选区生成)', Boolean(selAllDbg.selection && selAllDbg.selection.w === selAllDbg.doc.w),
|
||
JSON.stringify(selAllDbg.selection))
|
||
await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more="sel.none"]').click()
|
||
check('点选项栏「取消选区」清掉选区', !(await dbg()).selection)
|
||
|
||
// 画一个矩形 → 切选择工具点中它 → 选项栏就地改 描边/实心 + 线宽
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2,
|
||
liveBox.x + liveBox.width * 0.45, liveBox.y + liveBox.height * 0.45)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.3)
|
||
await page.waitForTimeout(150)
|
||
let selShapeDbg = await dbg()
|
||
check('选择工具选中矩形后选项栏出该形状的参数',
|
||
selShapeDbg.selectedShapeId &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="rect"]').count()) === 2 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="shapeLineWidth"]').count()) >= 2,
|
||
'selected=' + selShapeDbg.selectedShapeId)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').click()
|
||
selShapeDbg = await dbg()
|
||
check('选中矩形就地切「实心」(对象与按钮激活态一致)',
|
||
selShapeDbg.shapes[selShapeDbg.shapes.length - 1].fill === true &&
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active')),
|
||
JSON.stringify(selShapeDbg.shapes.slice(-1)))
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="rect"]').click()
|
||
selShapeDbg = await dbg()
|
||
check('再切回「描边」(按钮激活态跟随)',
|
||
selShapeDbg.shapes[selShapeDbg.shapes.length - 1].fill === false &&
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="rect"]').classList.contains('active')))
|
||
await page.locator('.iwb-editor-optionbar-body input[type="number"][data-opt="shapeLineWidth"]').fill('9')
|
||
await page.waitForTimeout(120)
|
||
selShapeDbg = await dbg()
|
||
check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9,
|
||
JSON.stringify(selShapeDbg.shapes.slice(-1)))
|
||
|
||
// Shift+X:选中形状切 描边/实心(PS 风格;数字框输完值直接按也必须生效)
|
||
check('Shift+X 切换选中形状 描边/实心(对象与选项栏按钮同步)', await (async () => {
|
||
await page.keyboard.press('Shift+x')
|
||
const d = await dbg()
|
||
const sh = d.shapes.find(s => s.id === d.selectedShapeId)
|
||
const btnActive = await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active'))
|
||
const flipped = sh && sh.fill === true && btnActive
|
||
await page.keyboard.press('Shift+x') // 切回描边,恢复现场
|
||
const d2 = await dbg()
|
||
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
|
||
return flipped && sh2 && sh2.fill === false
|
||
})())
|
||
|
||
// 钢笔:闭合路径选中后同样可切描边/实心
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
const pA = [liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.25]
|
||
const pB = [liveBox.x + liveBox.width * 0.75, liveBox.y + liveBox.height * 0.25]
|
||
const pC = [liveBox.x + liveBox.width * 0.75, liveBox.y + liveBox.height * 0.45]
|
||
const pD = [liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.45]
|
||
for (const [x, y] of [pA, pB, pC, pD]) await page.mouse.click(x, y)
|
||
await page.mouse.click(pA[0], pA[1]) // 点回起点闭合
|
||
await page.waitForTimeout(120)
|
||
const penShapeDbg = await dbg()
|
||
check('钢笔闭合路径落成后自动回 V 并选中(v1.5 用户裁定)', Boolean(penShapeDbg.selectedShapeId) &&
|
||
penShapeDbg.tool === 'select' &&
|
||
penShapeDbg.shapes[penShapeDbg.shapes.length - 1].type === 'pen' &&
|
||
penShapeDbg.shapes[penShapeDbg.shapes.length - 1].closed === true,
|
||
JSON.stringify({ sel: penShapeDbg.selectedShapeId, tool: penShapeDbg.tool, last: penShapeDbg.shapes.slice(-1) }))
|
||
// 选中改为显式:切 V 再点路径内部
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click((pA[0] + pC[0]) / 2, (pA[1] + pC[1]) / 2)
|
||
await page.waitForTimeout(150)
|
||
check('V 选中钢笔路径后选项栏有 描边/实心(pen 归属)',
|
||
(await dbg()).selectedShapeId &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2,
|
||
'selected=' + (await dbg()).selectedShapeId)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="pen"]').click()
|
||
let penSelDbg = await dbg()
|
||
check('选中钢笔路径就地切「描边」', penSelDbg.shapes[penSelDbg.shapes.length - 1].fill === false)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="pen"]').click()
|
||
penSelDbg = await dbg()
|
||
check('再切回「实心」', penSelDbg.shapes[penSelDbg.shapes.length - 1].fill === true)
|
||
|
||
// v1.5:钢笔节点编辑统一走 V 双击(用户裁定 2026-11-05),P 下双击不再进编辑
|
||
check('V 下双击钢笔进入节点编辑,P 下双击不进入', await (async () => {
|
||
const dx = (pA[0] + pC[0]) / 2, dy = (pA[1] + pC[1]) / 2
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.dblclick(dx, dy)
|
||
await page.waitForTimeout(200)
|
||
const inEdit = (await dbg()).penEditId
|
||
await page.keyboard.press('Escape')
|
||
await page.waitForTimeout(120)
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
await page.mouse.dblclick(dx, dy)
|
||
await page.waitForTimeout(200)
|
||
const underPen = (await dbg()).penEditId
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
return inEdit && !underPen ? true : 'V=' + inEdit + ' P=' + underPen
|
||
})())
|
||
|
||
// v1.5:文字输入完成(Enter)后自动回 V 并选中该文字(用户裁定 2026-11-05)
|
||
check('文字输入完成后自动回 V 并选中,输入框已收起', await (async () => {
|
||
const before = (await dbg()).texts.length
|
||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.14, liveBox.y + liveBox.height * 0.12)
|
||
await page.waitForTimeout(150)
|
||
const open = await page.evaluate(() => { const el = document.querySelector('.iwb-editor-text-input'); return el && el.style.display !== 'none' })
|
||
if (!open) return 'pre: 输入框没出现'
|
||
await page.keyboard.type('V5')
|
||
await page.keyboard.press('Enter')
|
||
await page.waitForTimeout(260)
|
||
const d = await dbg()
|
||
const last = d.texts[d.texts.length - 1]
|
||
const ok = d.tool === 'select' && d.texts.length === before + 1 && d.selectedTextId === (last && last.id)
|
||
await page.keyboard.press('Escape') // 清掉选中
|
||
await page.keyboard.press('Control+z') // 撤掉这段文字,保持后续用例现场
|
||
await page.waitForTimeout(150)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
return ok ? true : 'tool=' + d.tool + ' texts=' + d.texts.length + ' selText=' + d.selectedTextId
|
||
})())
|
||
// 吸管:选中矢量形状后按 I 取色,颜色必须写回对象(2026-11-04 用户反馈:切吸管后颜色只进画笔、形状不变)
|
||
check('选中矢量形状后切吸管:选中态保留、取色写回形状、取完回到原工具', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
const selId = (await dbg()).selectedShapeId
|
||
if (!selId) return 'pre: 没有选中形状'
|
||
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(v1.3:推荐色在弹层里,先点开色点)
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').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"]').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"]').click()
|
||
const sv = await page.locator('.iwb-color-sv').boundingBox()
|
||
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
|
||
await page.mouse.down()
|
||
await page.mouse.move(sv.x + sv.width * 0.9, sv.y + sv.height * 0.85, { steps: 20 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(150)
|
||
const h1 = (await dbg()).history
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click() // 收起
|
||
return h1 - h0 === 1 ? true : 'history ' + h0 + '→' + h1
|
||
})())
|
||
|
||
await page.keyboard.press('Escape') // 退出钢笔的半成品状态
|
||
await page.keyboard.press('Control+z') // 撤销拖动取色的那一步
|
||
await page.keyboard.press('Control+z') // 撤销上一步新建的矩形,恢复现场
|
||
|
||
// ---- v1.2.9:会话组(新建/覆盖/退出)移到顶栏最左 + 图层 PS 快捷键 ----
|
||
|
||
check('顶栏:标题最前 → 新建/覆盖/退出(统一中性色)→ 竖分隔 → 撤销组,右侧只剩 输出+导出', await page.evaluate(() => {
|
||
const q = (s) => document.querySelector(s)
|
||
const session = q('.iwb-editor-header > .iwb-editor-session')
|
||
const title = q('.iwb-editor-header > .iwb-editor-title')
|
||
const hist = q('.iwb-editor-header > .iwb-editor-history')
|
||
const dl = q('.iwb-editor-header [data-action="download"]')
|
||
if (!session || !title || !hist || !dl) return false
|
||
const t = title.getBoundingClientRect(), s = session.getBoundingClientRect(), h = hist.getBoundingClientRect()
|
||
const btns = Array.from(session.querySelectorAll('.iwb-editor-btn')).map(b => b.dataset.action).join(',')
|
||
const bg = (sel) => getComputedStyle(q(sel)).backgroundColor
|
||
const unified = bg('.iwb-editor-header .iwb-editor-btn-new') === bg('.iwb-editor-header .iwb-editor-btn-replace') &&
|
||
bg('.iwb-editor-header .iwb-editor-btn-replace') === bg('.iwb-editor-header .iwb-editor-btn-cancel')
|
||
return btns === 'newNode,replace,cancel' &&
|
||
t.left < s.left && s.right < h.left &&
|
||
Boolean(q('.iwb-editor-header > .iwb-editor-divider')) &&
|
||
unified && dl.textContent.trim() === '导出' &&
|
||
!q('.iwb-editor-export-actions [data-action="newNode"]')
|
||
}))
|
||
check('画笔选项栏:推荐大小只留 4 个快捷点,硬度补 5 个快捷点且滑杆加宽', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
const ok = await page.evaluate(() => {
|
||
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||
if (!body) return false
|
||
const size = body.querySelectorAll('[data-opt-preset="brushSize"]').length
|
||
const hard = body.querySelectorAll('[data-opt-preset="brushHardness"]').length
|
||
const wide = Boolean(body.querySelector('input[data-opt="brushHardness"].iwb-opt-range-wide'))
|
||
return size === 4 && hard === 5 && wide
|
||
})
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
return ok
|
||
})())
|
||
|
||
// 按住 Alt 临时吸色(PS 手感):画笔下按住 Alt → 吸管 → 取色 → 松开回画笔
|
||
check('画笔按住 Alt 临时吸色,松开 Alt 回到画笔(可连续取色)', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
const color0 = (await dbg()).color
|
||
await page.keyboard.down('Alt')
|
||
const d1 = await dbg()
|
||
if (d1.tool !== 'picker' || !d1.altPicker) return 'down: tool=' + d1.tool + ' alt=' + d1.altPicker
|
||
// 取色:点画面右下角(实色区)
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.8, liveBox.y + liveBox.height * 0.85)
|
||
await page.waitForTimeout(120)
|
||
const d2 = await dbg()
|
||
// 取色后仍停在吸管(Alt 还按着),颜色已变
|
||
if (d2.tool !== 'picker') return 'pick: tool=' + d2.tool
|
||
if (d2.color === color0) return 'pick: color 未变 ' + d2.color
|
||
await page.keyboard.up('Alt')
|
||
await page.waitForTimeout(180)
|
||
const d3 = await dbg()
|
||
return d3.tool === 'brush' && !d3.altPicker
|
||
? true
|
||
: 'up: tool=' + d3.tool + ' alt=' + d3.altPicker
|
||
})())
|
||
|
||
// Shift+X:选中形状切 描边/实心(PS 风格,用户裁定 2026-11-04 晚)
|
||
|
||
// 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层
|
||
// 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z)
|
||
check('图层 PS 快捷键:Ctrl+[/] 上下移一层、Ctrl+Shift+[/] 置底/置顶', await (async () => {
|
||
const before = (await dbg()).layers.length
|
||
await page.keyboard.press('Control+Shift+n') // 新建空白图层并选中(z 最高)
|
||
const d1 = await dbg()
|
||
const newId = d1.selectedLayerId
|
||
if (!newId || d1.layers.length !== before + 1) return false
|
||
const zOf = (d) => {
|
||
const bits = d.layers.map(l => ({ id: l.id, z: l.z }))
|
||
const vec = d.shapes.map(s => ({ id: s.id, z: s.z }))
|
||
const all = bits.concat(vec)
|
||
const me = all.find(u => u.id === newId)
|
||
return { me: me && me.z, max: Math.max(...all.map(u => u.z)), minNonBase: Math.min(...all.filter(u => u.id !== 'base').map(u => u.z)) }
|
||
}
|
||
if (zOf(d1).me !== zOf(d1).max) return false // 新层此刻在最上
|
||
await page.keyboard.press('Control+[') // 下移一层 → 不再最上
|
||
const d2 = await dbg()
|
||
if (zOf(d2).me >= zOf(d2).max) return false
|
||
await page.keyboard.press('Control+]') // 上移一层 → 回到最上
|
||
const d3 = await dbg()
|
||
if (zOf(d3).me !== zOf(d3).max) return false
|
||
await page.keyboard.press('Control+Shift+[') // 置底 → base 之上第一格
|
||
const d4 = await dbg()
|
||
if (zOf(d4).me !== zOf(d4).minNonBase) return false
|
||
await page.keyboard.press('Control+Shift+]') // 置顶 → 回到最上
|
||
const d5 = await dbg()
|
||
return zOf(d5).me === zOf(d5).max
|
||
})())
|
||
|
||
check('图层 PS 快捷键:Alt+[/] 向下/向上选择图层', await (async () => {
|
||
const d1 = await dbg()
|
||
const bits = d1.layers.map(l => ({ id: l.id, z: l.z }))
|
||
const topUnit = bits.concat(d1.shapes.map(s => ({ id: s.id, z: s.z }))).sort((a, b) => b.z - a.z)[0]
|
||
const topId = topUnit.id
|
||
if (d1.selectedLayerId !== topId) return 'pre: sel=' + d1.selectedLayerId + ' top=' + topId + ' bits=' + JSON.stringify(bits) + ' shapes=' + JSON.stringify(d1.shapes)
|
||
await page.keyboard.press('Alt+[') // 向下选 → 选到下一个单元(矩形 shape)
|
||
const d2 = await dbg()
|
||
if (!d2.selectedShapeId || d2.selectedLayerId !== null) return 'down: selLayer=' + d2.selectedLayerId + ' selShape=' + d2.selectedShapeId
|
||
await page.keyboard.press('Alt+]') // 向上选 → 回到位图新层
|
||
const d3 = await dbg()
|
||
if (d3.selectedLayerId !== topId || d3.selectedShapeId) return 'up: selLayer=' + d3.selectedLayerId + ' selShape=' + d3.selectedShapeId
|
||
return true
|
||
})())
|
||
|
||
check('Delete 删除选中的位图图层(PS 习惯)', await (async () => {
|
||
const d0 = await dbg()
|
||
const before = d0.layers.length
|
||
await page.keyboard.press('Delete')
|
||
const d = await dbg()
|
||
if (d.layers.length !== before - 1) return 'layers ' + before + '→' + d.layers.length + ' sel=' + d0.selectedLayerId + ' selShape=' + d0.selectedShapeId + ' tool=' + d0.tool + ' toast=' + await page.locator('.iwb-editor-toast').textContent()
|
||
return d.selectedLayerId === null ? true : 'sel 未清空: ' + d.selectedLayerId
|
||
})())
|
||
|
||
// ---- v1.6:笔刷环即时反馈(按 ] / [ 不必再动鼠标) ----
|
||
check('笔刷环:按 ] 后鼠标不动,环立刻变大', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.mouse.move(liveBox.x + liveBox.width * 0.5, liveBox.y + liveBox.height * 0.5)
|
||
await page.waitForTimeout(150)
|
||
const ringWidth = () => page.evaluate(() => {
|
||
const c = document.querySelector('.iwb-editor-cursor-overlay')
|
||
const d = c.getContext('2d').getImageData(0, 0, c.width, c.height).data
|
||
let minX = 1e9, maxX = -1
|
||
for (let y = 0; y < c.height; y++) {
|
||
for (let x = 0; x < c.width; x++) {
|
||
if (d[(y * c.width + x) * 4 + 3] > 8) { if (x < minX) minX = x; if (x > maxX) maxX = x }
|
||
}
|
||
}
|
||
return maxX < 0 ? 0 : maxX - minX + 1
|
||
})
|
||
const w0 = await ringWidth()
|
||
const s0 = (await dbg()).toolOptions.brushSize
|
||
for (let i = 0; i < 3; i++) await page.keyboard.press(']')
|
||
await page.waitForTimeout(140)
|
||
const w1 = await ringWidth()
|
||
const s1 = (await dbg()).toolOptions.brushSize
|
||
for (let i = 0; i < 3; i++) await page.keyboard.press('[')
|
||
await page.waitForTimeout(120)
|
||
return w0 > 0 && s1 > s0 && w1 > w0 ? true : 'w ' + w0 + '→' + w1 + ' size ' + s0 + '→' + s1
|
||
})())
|
||
|
||
// ---- v1.6:图层合并(向下合并 / 多选合并 / 合并可见) ----
|
||
// 两笔分别落在左右半区,合并后同一层里两半都要有像素,才算真合并
|
||
const strokeHalves = async (id, w, h) => page.evaluate(({ id, w, h }) => {
|
||
const d = window.__iwbEditor.__debug()
|
||
return {
|
||
left: d.alphaIn(id, 0, 0, w / 2, h),
|
||
right: d.alphaIn(id, w / 2, 0, w, h)
|
||
}
|
||
}, { id, w, h })
|
||
|
||
check('图层合并:Ctrl+E 向下合并两层(两笔都在),Ctrl+Z 连像素一起回退', await (async () => {
|
||
await page.keyboard.press('Escape')
|
||
await page.keyboard.press('Control+d')
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
const doc = (await dbg()).doc
|
||
const n0 = (await dbg()).layers.length
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
const lowerId = (await dbg()).activeLayerId
|
||
await drag2(liveBox.x + liveBox.width * 0.22, liveBox.y + liveBox.height * 0.62,
|
||
liveBox.x + liveBox.width * 0.32, liveBox.y + liveBox.height * 0.72)
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
const upperId = (await dbg()).activeLayerId
|
||
await drag2(liveBox.x + liveBox.width * 0.66, liveBox.y + liveBox.height * 0.62,
|
||
liveBox.x + liveBox.width * 0.76, liveBox.y + liveBox.height * 0.72)
|
||
const d1 = await dbg()
|
||
if (d1.layers.length !== n0 + 2) return 'pre layers ' + d1.layers.length + ' expect ' + (n0 + 2)
|
||
await page.keyboard.press('Control+e')
|
||
await page.waitForTimeout(320)
|
||
const d2 = await dbg()
|
||
if (d2.layers.length !== n0 + 1) return 'merge layers ' + d2.layers.length + ' expect ' + (n0 + 1)
|
||
const px = await strokeHalves(d2.activeLayerId, doc.w, doc.h)
|
||
if (!(px.left > 0 && px.right > 0)) return 'pixels ' + JSON.stringify(px)
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(320)
|
||
const d3 = await dbg()
|
||
if (d3.layers.length !== n0 + 2) return 'undo layers ' + d3.layers.length + ' expect ' + (n0 + 2)
|
||
// 撤销必须把两笔还给各自原来的层,而不是留一份空层
|
||
const backLower = await strokeHalves(lowerId, doc.w, doc.h)
|
||
const backUpper = await strokeHalves(upperId, doc.w, doc.h)
|
||
if (!(backLower.left > 0 && backUpper.right > 0)) {
|
||
return 'undo pixels lower=' + JSON.stringify(backLower) + ' upper=' + JSON.stringify(backUpper)
|
||
}
|
||
return true
|
||
})())
|
||
|
||
check('图层多选合并:⌘/Ctrl 点击两项后合并按钮合成一层', await (async () => {
|
||
const d0 = await dbg()
|
||
const n0 = d0.layers.length
|
||
const items = page.locator('.iwb-editor-layer-list .iwb-layer-item')
|
||
await items.nth(0).click()
|
||
await items.nth(1).click({ modifiers: [process.platform === 'darwin' ? 'Meta' : 'Control'] })
|
||
await page.waitForTimeout(220)
|
||
const dm = await dbg()
|
||
const marked = await page.locator('.iwb-layer-item.multi').count()
|
||
if (dm.layerMulti.length !== 2 || marked !== 2) return 'multi ' + JSON.stringify(dm.layerMulti) + ' dom=' + marked
|
||
await page.locator('[data-action="mergeLayers"]').click()
|
||
await page.waitForTimeout(320)
|
||
const d1 = await dbg()
|
||
return d1.layers.length === n0 - 1 && d1.layerMulti.length === 0
|
||
? true
|
||
: 'after ' + d1.layers.length + '/' + n0 + ' multi=' + d1.layerMulti.length
|
||
})())
|
||
|
||
check('向下合并到「原图」:笔迹写进 base,Ctrl+Z 复原像素', await (async () => {
|
||
// 归一到「只剩原图」:先显示所有隐藏层,再合并可见
|
||
let d = await dbg()
|
||
for (const l of d.layers) {
|
||
if (!l.visible) {
|
||
await page.locator('.iwb-layer-vis[data-vis-id="' + l.id + '"]').click()
|
||
await page.waitForTimeout(90)
|
||
}
|
||
}
|
||
d = await dbg()
|
||
if (d.layers.length > 1) {
|
||
await page.keyboard.press('Control+Shift+e')
|
||
await page.waitForTimeout(320)
|
||
d = await dbg()
|
||
}
|
||
if (d.layers.length !== 1 || d.layers[0].id !== 'base') return 'normalize: ' + JSON.stringify(d.layers)
|
||
|
||
const doc = d.doc
|
||
const cx = Math.round(doc.w * 0.5), cy = Math.round(doc.h * 0.5)
|
||
const pxAt = () => page.evaluate(([x, y]) => window.__iwbEditor.__debug().pixel('base', x, y), [cx, cy])
|
||
const p0 = await pxAt()
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.locator('.iwb-editor-optionbar-body input.iwb-opt-num[data-opt="brushSize"]').fill('40')
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
// 斜穿中心的大笔画,避免采样点落空
|
||
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.35,
|
||
liveBox.x + liveBox.width * 0.85, liveBox.y + liveBox.height * 0.65)
|
||
const d1 = await dbg()
|
||
if (d1.layers.length !== 2) return 'pre layers ' + d1.layers.length
|
||
await page.keyboard.press('Control+e')
|
||
await page.waitForTimeout(340)
|
||
const d2 = await dbg()
|
||
if (d2.layers.length !== 1 || d2.layers[0].id !== 'base') return 'merge layers ' + JSON.stringify(d2.layers.map(l => l.id))
|
||
const p1 = await pxAt()
|
||
if (!p1 || !p0 || (p1[0] === p0[0] && p1[1] === p0[1] && p1[2] === p0[2])) {
|
||
return 'base 像素未变 ' + JSON.stringify([p0, p1])
|
||
}
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(340)
|
||
const p2 = await pxAt()
|
||
const same = p2 && p0 && p2[0] === p0[0] && p2[1] === p0[1] && p2[2] === p0[2]
|
||
return same ? true : 'undo 像素 ' + JSON.stringify([p0, p2])
|
||
})())
|
||
|
||
check('合并可见图层:隐藏层原样保留,可见层合成一层', await (async () => {
|
||
// 保证至少 2 个可见层
|
||
let d = await dbg()
|
||
while (d.layers.filter(l => l.visible).length < 2) {
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
d = await dbg()
|
||
}
|
||
// 再新建一层并隐藏它,验证它不参与合并、也不会被删
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(160)
|
||
const hiddenId = (await dbg()).activeLayerId
|
||
await page.locator('.iwb-layer-vis[data-vis-id="' + hiddenId + '"]').click()
|
||
await page.waitForTimeout(180)
|
||
const visibleBefore = (await dbg()).layers.filter(l => l.visible).length
|
||
await page.keyboard.press('Control+Shift+e')
|
||
await page.waitForTimeout(360)
|
||
const d1 = await dbg()
|
||
const stillHidden = d1.layers.some(l => l.id === hiddenId && l.visible === false)
|
||
const visibleAfter = d1.layers.filter(l => l.visible).length
|
||
return stillHidden && visibleAfter === 1 && visibleBefore >= 2
|
||
? true
|
||
: 'hidden=' + stillHidden + ' visible ' + visibleBefore + '→' + visibleAfter + ' layers=' + d1.layers.length
|
||
})())
|
||
|
||
check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (async () => {
|
||
await page.keyboard.press('Escape') // 清掉可能残留的选中态
|
||
await page.keyboard.press('Control+]')
|
||
const t = await page.locator('.iwb-editor-toast').textContent()
|
||
return t.indexOf('选中') >= 0
|
||
})())
|
||
|
||
await page.locator('[data-action="cancel"]').click()
|
||
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
||
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
||
Boolean(openState && openState.mode === 'cancel') &&
|
||
(await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false,
|
||
JSON.stringify(openState))
|
||
|
||
check('无运行时错误 / 无弹窗', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||
|
||
await browser.close()
|
||
console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过'))
|
||
process.exit(failed ? 1 : 0)
|