feat(image-annotate): v1.6.0 色板入工具栏 + 快速效果 + 画完回 V + 图层合并(补齐 1.3.0–1.6.0)
上一次提交停在 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=
This commit is contained in:
1 parent
577a891e73
commit
5f11e40f43
14 files changed
+2034
-233
No files matched your search
@@ -96,7 +96,7 @@ const boot = await page.evaluate((png) => {
|
||||
window.__commands['annotate-selected'].run().catch(() => {})
|
||||
return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) }
|
||||
}, PNG)
|
||||
check('产物可执行(循环打包未炸)', boot.version === '1.2.12', 'version=' + boot.version)
|
||||
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 })
|
||||
@@ -136,14 +136,61 @@ check('打开编辑器默认只有「原图」1 层,且状态栏不再写「
|
||||
!(await page.locator('.iwb-editor-status-layer').textContent()).includes('画笔标注'),
|
||||
JSON.stringify((await dbg()).layers.map(l => l.name)))
|
||||
|
||||
check('侧栏只剩调色板 + 缩放:笔刷大小/快捷点已移除(都收进工具选项栏,2026-11-04 用户裁定)',
|
||||
// v1.3(用户裁定 2026-11-05):调色板从侧栏搬进工具栏弹层,侧栏只剩缩放
|
||||
check('调色板已搬进工具栏:侧栏只剩缩放,SV/色相/推荐色都在弹层里',
|
||||
await page.evaluate(() => {
|
||||
const q = (s) => Boolean(document.querySelector(s))
|
||||
return q('.iwb-editor-color-panel') && q('.iwb-color-sv') && q('.iwb-editor-zoom') &&
|
||||
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()
|
||||
@@ -684,15 +731,17 @@ await page.keyboard.press('Control+z') // 撤销还原,恢复图层结构
|
||||
|
||||
// ---- v1.2.4:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ----
|
||||
|
||||
check('「更多」菜单已移除;顶栏只留顺序/视图命令,图层新建与导入回图层面板标题栏', await page.evaluate(() => {
|
||||
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 === 2 && q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') &&
|
||||
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"]')
|
||||
}))
|
||||
@@ -830,26 +879,72 @@ 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('钢笔闭合路径落成并自动选中', penShapeDbg.selectedShapeId &&
|
||||
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(penShapeDbg.shapes.slice(-1)))
|
||||
check('选中钢笔路径的选项栏有 描边/实心(pen 归属)',
|
||||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2)
|
||||
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: 没有选中形状'
|
||||
// 先换成一个可辨识的颜色,便于判断取色真的改了对象
|
||||
await page.locator('.iwb-editor-color-panel-swatch[data-panel-color="#4488ff"]').click()
|
||||
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(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') // 切吸管
|
||||
@@ -870,6 +965,58 @@ 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(() => {
|
||||
@@ -982,6 +1129,169 @@ check('Delete 删除选中的位图图层(PS 习惯)', await (async () => {
|
||||
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+]')
|
||||
|
||||
Reference in new issue
Block a user