fix(image-annotate): 1.1.1 反选作用区域/裁剪态选区互斥/Delete 优先级/退出结算宿主 Promise(含 1.1.0 布局修复)
This commit is contained in:
1 parent
be05f31479
commit
9a0f5bab69
8 files changed
+259
-20
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/image-annotate",
|
||||
"private": true,
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||
"ibwPlugin": {
|
||||
"id": "image-annotate",
|
||||
|
||||
@@ -41,6 +41,12 @@ export function execute(label, mutator) {
|
||||
export function runCommand(name) {
|
||||
const def = COMMANDS[name]
|
||||
if (!def) return false
|
||||
// 选区与裁剪互斥:只在 setTool('crop') 清一次选区不够 —— 快捷键 / 更多菜单 /
|
||||
// 右键菜单都还能再建选区。三条入口都经过这里,统一在工作层拦掉 sel.*。
|
||||
if (S.tool === 'crop' && String(name).indexOf('sel.') === 0) {
|
||||
toast('裁剪中不可使用选区命令,请先切换工具', 'warn')
|
||||
return false
|
||||
}
|
||||
if (typeof def.enabled === 'function' && !def.enabled()) {
|
||||
toast(def.hint || '当前状态下不可用', 'warn')
|
||||
return false
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import { S, runtime } from './state.js'
|
||||
import { getCompositeCanvas } from './tools.js'
|
||||
import { setupCanvas } from './viewport.js'
|
||||
import { disposeSelection } from './selection.js'
|
||||
|
||||
|
||||
// ============ 裁剪 ============
|
||||
@@ -238,6 +239,10 @@ import { setupCanvas } from './viewport.js'
|
||||
if (!S.cropRect) return
|
||||
const { x, y, w, h } = S.cropRect
|
||||
if (w < 2 || h < 2) { cancelCrop(); return }
|
||||
// 画布尺寸即将变化:旧坐标系下的选区/拉框/蚂蚁线/浮动条全部失效,
|
||||
// 必须按 disposeSelection 级别清理,否则之后 Delete 会按旧 bbox
|
||||
// 在新画布上开超大掩膜,把当前层整层擦掉。
|
||||
disposeSelection()
|
||||
// 合成所有可见图层
|
||||
const tmp = getCompositeCanvas()
|
||||
const sx = Math.round(x), sy = Math.round(y)
|
||||
@@ -313,6 +318,8 @@ import { setupCanvas } from './viewport.js'
|
||||
S.moveStart = null
|
||||
clearOverlay()
|
||||
updateCropInfo()
|
||||
// 尺寸/坐标系已变,统一重绘出口要在新画布上重建选区层与浮动条位置
|
||||
if (S.renderAll) S.renderAll()
|
||||
}
|
||||
|
||||
export function cancelCrop() {
|
||||
|
||||
@@ -157,7 +157,19 @@ import { toast } from './commands.js'
|
||||
runtime.el.classList.toggle('panels-collapsed', saved || auto)
|
||||
}
|
||||
|
||||
export function close() {
|
||||
/**
|
||||
* 关闭编辑器。reason:'cancel'(用户点退出)| 'done'(导出成功后关闭)。
|
||||
* 必须先通知宿主再置空 S.callbacks —— glue.js 的 openEditor() 只在
|
||||
* onResult / onError / onClose 三处结算,「退出」曾经没有任何回调,宿主
|
||||
* Promise 永远悬挂;回调异常不能阻断后面的内存释放。
|
||||
*/
|
||||
export function close(reason) {
|
||||
const callbacks = S.callbacks
|
||||
try {
|
||||
if (callbacks && typeof callbacks.onClose === 'function') callbacks.onClose(reason || 'cancel')
|
||||
} catch (e) {
|
||||
console.error('[IWB编辑器] onClose 回调异常:', e)
|
||||
}
|
||||
if (runtime.el) {
|
||||
hideTextInput()
|
||||
runtime.el.style.display = 'none'
|
||||
@@ -234,7 +246,7 @@ import { toast } from './commands.js'
|
||||
const { blob } = await prepareOutput()
|
||||
if (mode === 'download') { downloadBlob(blob); return }
|
||||
if (S.callbacks && S.callbacks.onResult) S.callbacks.onResult(blob, mode)
|
||||
close()
|
||||
close('done')
|
||||
} catch (e) {
|
||||
console.error('[IWB编辑器] 导出失败:', e)
|
||||
toast('导出失败:' + ((e && e.message) || '图片可能跨域'), 'error')
|
||||
@@ -267,6 +279,10 @@ import { toast } from './commands.js'
|
||||
tool: S.tool,
|
||||
doc: { w: S.imgW, h: S.imgH },
|
||||
layers: S.layers.map(l => ({ id: l.id, name: l.name, z: l.z, locked: !!l.locked, visible: l.visible !== false })),
|
||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type })),
|
||||
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
|
||||
selectedShapeId: S.selectedShapeId,
|
||||
selectedTextId: S.selectedTextId,
|
||||
activeLayerId: S.activeLayerId,
|
||||
selection: selectionInfo(),
|
||||
history: S.history.length,
|
||||
|
||||
@@ -24,7 +24,7 @@ import { createLayerCanvas, getActiveLayer, reorderLayerCanvas, setActiveLayer,
|
||||
export function selectionInfo() {
|
||||
if (!hasSelection()) return null
|
||||
const b = S.selection.bbox
|
||||
return { kind: S.selection.kind, x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h), feather: S.selection.feather || 0 }
|
||||
return { kind: S.selection.kind, x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h), feather: S.selection.feather || 0, inverted: !!S.selection.inverted }
|
||||
}
|
||||
|
||||
// ============ 选区图层(独立 canvas) ============
|
||||
@@ -159,6 +159,10 @@ import { createLayerCanvas, getActiveLayer, reorderLayerCanvas, setActiveLayer,
|
||||
} else {
|
||||
path.addPath(outlinePath)
|
||||
}
|
||||
// 建立像素选区即接管 Delete 语义:清掉矢量对象选中态,否则
|
||||
// 「选中形状 → Ctrl+A → Delete」会走删对象分支,而不是清像素。
|
||||
S.selectedTextId = null
|
||||
S.selectedShapeId = null
|
||||
S.selection = {
|
||||
kind, path, outlinePath, bbox,
|
||||
fillRule: inverted ? 'evenodd' : 'nonzero',
|
||||
@@ -258,27 +262,45 @@ import { createLayerCanvas, getActiveLayer, reorderLayerCanvas, setActiveLayer,
|
||||
|
||||
// ============ 局部掩膜(羽化软边) ============
|
||||
/**
|
||||
* 返回覆盖 bbox 的 alpha 掩膜(局部 tile,不是全幅)。
|
||||
* 掩膜必须覆盖的范围(整数基准,避免 tile 原点与平移量差 1px)。
|
||||
* 反选的 path 是「整图矩形 + 原选区」,只按原 bbox 开 tile 会把 tile 之外
|
||||
* 的反选区域整块丢掉 —— 填充走全幅 fill(path) 不受影响,于是 Delete/复制/剪切
|
||||
* 只作用原 bbox,与填充互相矛盾。反选时扩成整幅,临时画布用完即弃。
|
||||
*/
|
||||
function maskExtent() {
|
||||
const sel = S.selection
|
||||
const b = sel.inverted ? { x: 0, y: 0, w: S.imgW, h: S.imgH } : sel.bbox
|
||||
const x = Math.floor(b.x)
|
||||
const y = Math.floor(b.y)
|
||||
return {
|
||||
x, y,
|
||||
w: Math.max(1, Math.ceil(b.x + b.w) - x),
|
||||
h: Math.max(1, Math.ceil(b.y + b.h) - y)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回覆盖 bbox 的 alpha 掩膜(局部 tile,不是全幅;反选时整幅)。
|
||||
* feather>0 用 Canvas2D 原生 filter 模糊填充边缘,CSP 不限制。
|
||||
*/
|
||||
function buildMask() {
|
||||
const sel = S.selection
|
||||
const feather = sel.feather || 0
|
||||
const pad = Math.ceil(feather * 2)
|
||||
const b = sel.bbox
|
||||
const w = Math.max(1, Math.ceil(b.w) + pad * 2)
|
||||
const h = Math.max(1, Math.ceil(b.h) + pad * 2)
|
||||
const e = maskExtent()
|
||||
const w = e.w + pad * 2
|
||||
const h = e.h + pad * 2
|
||||
const c = document.createElement('canvas')
|
||||
c.width = w
|
||||
c.height = h
|
||||
const cx = c.getContext('2d')
|
||||
cx.save()
|
||||
cx.translate(-b.x + pad, -b.y + pad)
|
||||
cx.translate(-e.x + pad, -e.y + pad)
|
||||
if (feather > 0) cx.filter = 'blur(' + feather + 'px)'
|
||||
cx.fillStyle = '#ffffff'
|
||||
cx.fill(sel.path, sel.fillRule)
|
||||
cx.restore()
|
||||
return { canvas: c, x: Math.floor(b.x) - pad, y: Math.floor(b.y) - pad, w, h }
|
||||
return { canvas: c, x: e.x - pad, y: e.y - pad, w, h }
|
||||
}
|
||||
|
||||
function writableLayer() {
|
||||
|
||||
@@ -67,6 +67,9 @@ export function createGlue(ctx, css) {
|
||||
ensureStyle()
|
||||
return new Promise(function (resolve, reject) {
|
||||
let settled = false
|
||||
// onResult 一旦接管(异步编码 + 写回节点),close() 触发的 onClose
|
||||
// 就不能再抢先结算,否则会变成「节点已写回但 Promise 报取消」。
|
||||
let handedOff = false
|
||||
const settle = function (fn) { if (!settled) { settled = true; fn() } }
|
||||
|
||||
Promise.resolve(editor.open({
|
||||
@@ -76,7 +79,13 @@ export function createGlue(ctx, css) {
|
||||
onError: function (message) {
|
||||
settle(function () { reject(new Error(String(message || '编辑失败'))) })
|
||||
},
|
||||
onClose: function () {
|
||||
// 点「退出」:编辑器不产出结果,必须在这里结算,否则 Promise 永远悬挂。
|
||||
if (handedOff) return
|
||||
settle(function () { resolve('cancel') })
|
||||
},
|
||||
onResult: function (out, mode) {
|
||||
handedOff = true
|
||||
imageToDataUrl(out).then(function (dataUrl) {
|
||||
const replaced = mode === 'replace'
|
||||
const ok = replaced
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
id: 'image-annotate',
|
||||
name: '标注 / 修图',
|
||||
version: '1.1.0',
|
||||
version: '1.1.1',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||
settings: {
|
||||
@@ -1072,6 +1072,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
function runCommand(name) {
|
||||
const def = COMMANDS[name];
|
||||
if (!def) return false;
|
||||
if (S.tool === "crop" && String(name).indexOf("sel.") === 0) {
|
||||
toast("裁剪中不可使用选区命令,请先切换工具", "warn");
|
||||
return false;
|
||||
}
|
||||
if (typeof def.enabled === "function" && !def.enabled()) {
|
||||
toast(def.hint || "当前状态下不可用", "warn");
|
||||
return false;
|
||||
@@ -1110,7 +1114,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
function selectionInfo() {
|
||||
if (!hasSelection()) return null;
|
||||
const b = S.selection.bbox;
|
||||
return { kind: S.selection.kind, x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h), feather: S.selection.feather || 0 };
|
||||
return { kind: S.selection.kind, x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h), feather: S.selection.feather || 0, inverted: !!S.selection.inverted };
|
||||
}
|
||||
function clearSelectionCanvas() {
|
||||
const ctx = S.selectionCtx;
|
||||
@@ -1228,6 +1232,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
} else {
|
||||
path.addPath(outlinePath);
|
||||
}
|
||||
S.selectedTextId = null;
|
||||
S.selectedShapeId = null;
|
||||
S.selection = {
|
||||
kind,
|
||||
path,
|
||||
@@ -1324,24 +1330,36 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
}
|
||||
clearMarquee();
|
||||
}
|
||||
function maskExtent() {
|
||||
const sel = S.selection;
|
||||
const b = sel.inverted ? { x: 0, y: 0, w: S.imgW, h: S.imgH } : sel.bbox;
|
||||
const x = Math.floor(b.x);
|
||||
const y = Math.floor(b.y);
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
w: Math.max(1, Math.ceil(b.x + b.w) - x),
|
||||
h: Math.max(1, Math.ceil(b.y + b.h) - y)
|
||||
};
|
||||
}
|
||||
function buildMask() {
|
||||
const sel = S.selection;
|
||||
const feather = sel.feather || 0;
|
||||
const pad = Math.ceil(feather * 2);
|
||||
const b = sel.bbox;
|
||||
const w = Math.max(1, Math.ceil(b.w) + pad * 2);
|
||||
const h = Math.max(1, Math.ceil(b.h) + pad * 2);
|
||||
const e = maskExtent();
|
||||
const w = e.w + pad * 2;
|
||||
const h = e.h + pad * 2;
|
||||
const c = document.createElement("canvas");
|
||||
c.width = w;
|
||||
c.height = h;
|
||||
const cx = c.getContext("2d");
|
||||
cx.save();
|
||||
cx.translate(-b.x + pad, -b.y + pad);
|
||||
cx.translate(-e.x + pad, -e.y + pad);
|
||||
if (feather > 0) cx.filter = "blur(" + feather + "px)";
|
||||
cx.fillStyle = "#ffffff";
|
||||
cx.fill(sel.path, sel.fillRule);
|
||||
cx.restore();
|
||||
return { canvas: c, x: Math.floor(b.x) - pad, y: Math.floor(b.y) - pad, w, h };
|
||||
return { canvas: c, x: e.x - pad, y: e.y - pad, w, h };
|
||||
}
|
||||
function writableLayer() {
|
||||
const layer = getActiveLayer();
|
||||
@@ -4940,6 +4958,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
cancelCrop();
|
||||
return;
|
||||
}
|
||||
disposeSelection();
|
||||
const tmp = getCompositeCanvas();
|
||||
const sx = Math.round(x), sy = Math.round(y);
|
||||
const sw = Math.round(w), sh = Math.round(h);
|
||||
@@ -5018,6 +5037,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
S.moveStart = null;
|
||||
clearOverlay();
|
||||
updateCropInfo();
|
||||
if (S.renderAll) S.renderAll();
|
||||
}
|
||||
function cancelCrop() {
|
||||
S.cropRect = null;
|
||||
@@ -5694,7 +5714,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const auto = (window.innerWidth || 1440) < 1100;
|
||||
runtime.el.classList.toggle("panels-collapsed", saved || auto);
|
||||
}
|
||||
function close() {
|
||||
function close(reason) {
|
||||
const callbacks = S.callbacks;
|
||||
try {
|
||||
if (callbacks && typeof callbacks.onClose === "function") callbacks.onClose(reason || "cancel");
|
||||
} catch (e) {
|
||||
console.error("[IWB编辑器] onClose 回调异常:", e);
|
||||
}
|
||||
if (runtime.el) {
|
||||
hideTextInput();
|
||||
runtime.el.style.display = "none";
|
||||
@@ -5758,7 +5784,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
return;
|
||||
}
|
||||
if (S.callbacks && S.callbacks.onResult) S.callbacks.onResult(blob, mode);
|
||||
close();
|
||||
close("done");
|
||||
} catch (e) {
|
||||
console.error("[IWB编辑器] 导出失败:", e);
|
||||
toast("导出失败:" + (e && e.message || "图片可能跨域"), "error");
|
||||
@@ -5780,6 +5806,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
tool: S.tool,
|
||||
doc: { w: S.imgW, h: S.imgH },
|
||||
layers: S.layers.map((l) => ({ id: l.id, name: l.name, z: l.z, locked: !!l.locked, visible: l.visible !== false })),
|
||||
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type })),
|
||||
texts: S.textLayers.map((t) => ({ id: t.id, text: t.text })),
|
||||
selectedShapeId: S.selectedShapeId,
|
||||
selectedTextId: S.selectedTextId,
|
||||
activeLayerId: S.activeLayerId,
|
||||
selection: selectionInfo(),
|
||||
history: S.history.length,
|
||||
@@ -5859,6 +5889,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
ensureStyle();
|
||||
return new Promise(function(resolve, reject) {
|
||||
let settled = false;
|
||||
let handedOff = false;
|
||||
const settle = function(fn) {
|
||||
if (!settled) {
|
||||
settled = true;
|
||||
@@ -5875,7 +5906,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
reject(new Error(String(message || "编辑失败")));
|
||||
});
|
||||
},
|
||||
onClose: function() {
|
||||
if (handedOff) return;
|
||||
settle(function() {
|
||||
resolve("cancel");
|
||||
});
|
||||
},
|
||||
onResult: function(out, mode) {
|
||||
handedOff = true;
|
||||
imageToDataUrl(out).then(function(dataUrl) {
|
||||
const replaced = mode === "replace";
|
||||
const ok = replaced ? ctx.canvas.setNodeImage(id, dataUrl) : Boolean(ctx.canvas.createImageNode({ dataUrl, name: baseName(node) + "_edit.png" }));
|
||||
|
||||
@@ -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.0', 'version=' + boot.version)
|
||||
check('产物可执行(循环打包未炸)', boot.version === '1.1.1', '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 })
|
||||
@@ -257,6 +257,147 @@ const wrote = await poll(async () => page.evaluate(() => window.__writes.some(w
|
||||
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')
|
||||
await page.keyboard.press('Delete')
|
||||
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])
|
||||
}
|
||||
check('反选 + 羽化 6px:边界仍是渐变(羽化未因整幅掩膜失效)',
|
||||
selF.feather === 6 && edgeAlphas.some(a => a > 0 && a < 255), JSON.stringify(edgeAlphas))
|
||||
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)
|
||||
await page.locator('[data-action="toggleMore"]').click()
|
||||
await page.locator('[data-more="sel.all"]').click()
|
||||
const cropAfterMenu = await dbg()
|
||||
check('裁剪中「更多 → 全选」同样被拦', cropAfterMenu.selection === null && cropAfterMenu.ants === false)
|
||||
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)
|
||||
|
||||
// ---- Fix4:点「退出」必须结算宿主 Promise(glue.openEditor → onClose) ----
|
||||
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()
|
||||
|
||||
Reference in new issue
Block a user