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
@@ -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" }));
|
||||
|
||||
Reference in new issue
Block a user