feat(image-annotate): 1.2.0 非破坏性裁剪(可撤销/不 flatten)+ 工具参数解耦与就地选项栏

This commit is contained in:
qiqi committed 2026-11-04 18:30:54 +08:00
1 parent a4e89f5f8b
commit d8e4e0cb26
13 files changed
+1768 -1243

No files matched your search

+63 -2
View File
@@ -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.1.2', 'version=' + boot.version)
check('产物可执行(循环打包未炸)', boot.version === '1.2.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 })
@@ -368,13 +368,20 @@ 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))
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')
@@ -436,6 +443,22 @@ 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()
@@ -449,6 +472,44 @@ check('还原原图复位尺寸后:输出摘要即时跟随(不停留在裁
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')
// ---- Fix4:点「退出」必须结算宿主 Promise(glue.openEditor → onClose) ----
await page.locator('[data-action="cancel"]').click()
const openState = await poll(async () => page.evaluate(() => window.__openState))