feat(image-annotate): v1.2.9 图层 PS 快捷键 + 顶栏会话组左移

- 图层快捷键(PS 同款,e.code 匹配防中文输入法吞键):
  Ctrl+]/[ 上/下移一层、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 向上/向下选层
- Delete 删除选中的位图图层(原图锁定除外)
- moveLayer 无选中时 toast 提示,不再无声失败
- 顶栏「新建/覆盖/退出」移到最左会话组;右侧只留 输出+导出,下载改文案「导出」
- [ / ] 笔刷大小同时匹配 e.code,中文输入法下不再失灵
- __debug().shapes 补 z 字段;harness 新增 6 项断言(113 项全绿)
This commit is contained in:
qiqi committed 2026-11-04 22:48:12 +08:00
1 parent e1465b9d68
commit 9d923aed26
9 files changed
+255 -88

No files matched your search

+104 -70
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.2.8',
version: '1.2.9',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -786,6 +786,62 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (S.renderAll) S.renderAll();
}
// image-annotate/plugin/editor/commands.js
var COMMANDS = /* @__PURE__ */ Object.create(null);
function defineCommand(name, def) {
COMMANDS[name] = Object.assign({ label: name }, def || {});
}
function execute(label, mutator) {
const before = S.history.length;
saveSnapshot(label);
let result;
try {
result = mutator();
} catch (err) {
if (S.history.length === before + 1) S.history.pop();
throw err;
}
if (S.renderAll) S.renderAll();
return result;
}
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;
}
const args = Array.prototype.slice.call(arguments, 1);
try {
if (def.view) {
const r = def.run.apply(null, args);
if (S.renderAll) S.renderAll();
return r;
}
return execute(def.label, () => def.run.apply(null, args));
} catch (err) {
console.error("[IWB编辑器] 命令执行失败:" + name, err);
toast("操作失败:" + (err && err.message || name), "error");
return false;
}
}
var toastTimer = null;
function toast(message, kind) {
const el = runtime.el && runtime.el.querySelector(".iwb-editor-toast");
if (!el) return;
el.textContent = String(message || "");
el.className = "iwb-editor-toast iwb-editor-toast-" + (kind || "info") + " show";
if (toastTimer) clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
el.classList.remove("show");
toastTimer = null;
}, 2600);
}
// image-annotate/plugin/editor/objects.js
var TEXT_FONT = (size) => "bold " + size + "px sans-serif";
function textBounds(t) {
@@ -972,7 +1028,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
const layer = S.layers.find((l) => l.id === S.selectedLayerId && l.id !== "base" && !l.locked);
if (layer) sel = { kind: "bitmap", obj: layer };
}
if (!sel || sel.obj.locked || sel.obj.id === "base") return;
if (!sel) {
toast("先在画布或图层面板选中要调整的元素", "info");
return;
}
if (sel.obj.locked || sel.obj.id === "base") return;
const units = layerUnits();
const baseIdx = units.findIndex((u) => u.obj.id === "base");
if (baseIdx > 0) {
@@ -998,6 +1058,19 @@ var __IWB_ANNOTATE_MANIFEST__ = {
renderObjects();
renderLayerPanel();
}
function selectNeighborLayer(up) {
const units = layerUnits();
if (!units.length) return;
const sel = getSelectedObject();
let cur = -1;
if (sel) cur = units.findIndex((u2) => u2.obj === sel.obj);
else if (S.selectedLayerId) cur = units.findIndex((u2) => u2.kind === "bitmap" && u2.obj.id === S.selectedLayerId);
const idx = cur < 0 ? up ? units.length - 1 : 0 : up ? Math.min(cur + 1, units.length - 1) : Math.max(cur - 1, 0);
const u = units[idx];
if (!u) return;
selectUnit(u.kind, u.obj.id);
renderLayerPanel();
}
function shapeHandlePoints(s) {
const b = shapeBounds(s);
if (s.type === "pen") {
@@ -2116,62 +2189,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
});
}
// image-annotate/plugin/editor/commands.js
var COMMANDS = /* @__PURE__ */ Object.create(null);
function defineCommand(name, def) {
COMMANDS[name] = Object.assign({ label: name }, def || {});
}
function execute(label, mutator) {
const before = S.history.length;
saveSnapshot(label);
let result;
try {
result = mutator();
} catch (err) {
if (S.history.length === before + 1) S.history.pop();
throw err;
}
if (S.renderAll) S.renderAll();
return result;
}
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;
}
const args = Array.prototype.slice.call(arguments, 1);
try {
if (def.view) {
const r = def.run.apply(null, args);
if (S.renderAll) S.renderAll();
return r;
}
return execute(def.label, () => def.run.apply(null, args));
} catch (err) {
console.error("[IWB编辑器] 命令执行失败:" + name, err);
toast("操作失败:" + (err && err.message || name), "error");
return false;
}
}
var toastTimer = null;
function toast(message, kind) {
const el = runtime.el && runtime.el.querySelector(".iwb-editor-toast");
if (!el) return;
el.textContent = String(message || "");
el.className = "iwb-editor-toast iwb-editor-toast-" + (kind || "info") + " show";
if (toastTimer) clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
el.classList.remove("show");
toastTimer = null;
}, 2600);
}
// image-annotate/plugin/editor/selection.js
function hasSelection() {
return !!(S.selection && S.selection.active);
@@ -2651,6 +2668,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
runtime.el.innerHTML = `
<div class="iwb-editor-modal">
<div class="iwb-editor-header">
<!-- 会话组(v1.2.9):新建/覆盖/退出从顶栏最右移到最左(用户裁定 2026-11-04) -->
<div class="iwb-editor-session">
<button class="iwb-editor-btn iwb-editor-btn-new" data-action="newNode" title="把当前编辑结果新建为节点(不关闭编辑器)">新建</button>
<button class="iwb-editor-btn iwb-editor-btn-replace" data-action="replace" title="用当前编辑结果覆盖原图">覆盖</button>
<button class="iwb-editor-btn iwb-editor-btn-cancel" data-action="cancel" title="放弃修改并退出">退出</button>
</div>
<span class="iwb-editor-title">图片编辑 <em class="iwb-editor-doc-size">—</em></span>
<div class="iwb-editor-history">
<button class="iwb-editor-action" data-action="undo" title="撤销 (Ctrl+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg></button>
@@ -2704,10 +2727,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<div class="iwb-editor-export-note">一次只输出一个结果;设置会记住</div>
</div>
</div>
<button class="iwb-editor-btn iwb-editor-btn-download" data-action="download" title="下载当前这一张(不关闭编辑器)">下载</button>
<button class="iwb-editor-btn iwb-editor-btn-new" data-action="newNode">新建</button>
<button class="iwb-editor-btn iwb-editor-btn-replace" data-action="replace">覆盖</button>
<button class="iwb-editor-btn iwb-editor-btn-cancel" data-action="cancel">退出</button>
<button class="iwb-editor-btn iwb-editor-btn-download" data-action="download" title="导出当前这一张(不关闭编辑器)">导出</button>
</div>
</div>
<div class="iwb-editor-optionbar">
@@ -4542,7 +4562,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
togglePanelsCollapsed();
return;
}
if (!mod && !e.altKey && (e.key === "[" || e.key === "]")) {
const isBracket = e.key === "[" || e.key === "]" || e.code === "BracketLeft" || e.code === "BracketRight";
if (!mod && !e.altKey && isBracket) {
e.preventDefault();
const step = S.brushSize >= 64 ? 8 : S.brushSize >= 24 ? 4 : S.brushSize >= 8 ? 2 : 1;
S.brushSize = clamp(S.brushSize + (e.key === "]" ? step : -step), 1, 300);
@@ -4630,6 +4651,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
renderLayerPanel();
return;
}
if (S.selectedLayerId && S.selectedLayerId !== "base") {
e.preventDefault();
deleteLayer(S.selectedLayerId);
renderLayerPanel();
return;
}
}
if (e.code === "Space") {
e.preventDefault();
@@ -4639,11 +4666,18 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
return;
}
if (mod && (e.key === "]" || e.key === "[")) {
e.preventDefault();
const up = e.key === "]";
moveLayer(e.shiftKey ? up ? "top" : "bottom" : up ? "up" : "down");
return;
if (e.code === "BracketLeft" || e.code === "BracketRight") {
const up = e.code === "BracketRight";
if (mod) {
e.preventDefault();
moveLayer(e.shiftKey ? up ? "top" : "bottom" : up ? "up" : "down");
return;
}
if (e.altKey) {
e.preventDefault();
selectNeighborLayer(up);
return;
}
}
if (mod && key === "z") {
e.preventDefault();
@@ -6123,7 +6157,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
zoom: S.zoom,
fit: { w: Math.round(S.fitW || 0), h: Math.round(S.fitH || 0) },
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, lw: s.lw, fill: !!s.fill, closed: !!s.closed })),
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z })),
texts: S.textLayers.map((t) => ({ id: t.id, text: t.text })),
selectedShapeId: S.selectedShapeId,
selectedTextId: S.selectedTextId,
@@ -6165,7 +6199,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
};
// image-annotate/plugin/editor.css
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
// image-annotate/plugin/glue.js
function createGlue(ctx, css) {