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

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/image-annotate",
"private": true,
"version": "1.2.8",
"version": "1.2.9",
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
"ibwPlugin": {
"id": "image-annotate",
+10
View File
@@ -1487,6 +1487,7 @@
@media (max-width: 900px) {
.iwb-opt-hint, .iwb-editor-optionbar-tip { display: none; }
.iwb-editor-session .iwb-editor-btn-cancel,
.iwb-editor-export-actions .iwb-editor-btn-cancel { display: none; }
}
@@ -1586,3 +1587,12 @@
display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.iwb-opt-selcmd:hover { background: #45475a; }
/* ================================================================
v1.2.9:顶栏「新建/覆盖/退出」移到最左(用户裁定 2026-11-04)
布局:⟨新建·覆盖·退出⟩ 标题 | 撤销·重做·还原 | 顺序·视图 | …… | 输出·导出
会话组不设 order(默认 0 且是 header 第一个子元素)→ 与标题同序时按 DOM 排最前
================================================================ */
.iwb-editor-header > .iwb-editor-session { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn { padding: 6px 10px; font-size: 11px; min-width: 56px; white-space: nowrap; }
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-download { min-width: 72px; }
+7 -4
View File
@@ -19,6 +19,12 @@ import { bindEvents } from './events.js'
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>
@@ -72,10 +78,7 @@ import { bindEvents } from './events.js'
<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">
+27 -8
View File
@@ -8,13 +8,13 @@
import { S, ZOOM_STEP, runtime } from './state.js'
import { ROT_CURSOR, clamp, getPos, isOverRotationHandle, setView, setZoomActual, setZoomFit, zoomStep } from './viewport.js'
import { addBitmapLayer, addBlankLayer, applyBitmapDrag, beginBitmapDrag, clearSelection, ensureWritableLayer, getActiveCtx, getActiveLayer, hitBitmapHandle, removeVecCanvas, renderLayerPanel } from './layers.js'
import { addBitmapLayer, addBlankLayer, applyBitmapDrag, beginBitmapDrag, clearSelection, deleteLayer, ensureWritableLayer, getActiveCtx, getActiveLayer, hitBitmapHandle, removeVecCanvas, renderLayerPanel } from './layers.js'
import { applyColorChange, beginStroke, clearToolRing, drawToolRing, endStroke, eraseSegment, exitPicker, hidePickerTip, sampleColor, setTool, showPickerTip, strokeSegment } from './tools.js'
import { beginMarquee, updateMarquee, endMarquee, beginLasso, updateLasso, endLasso, clearMarquee, syncAnts, renderSelection } from './selection.js'
import { runCommand, toast } from './commands.js'
import { showSelectionContext, hideSelectionContext } from './floating.js'
import { applyConstraintDrag, cancelCrop, clearOverlay, confirmCrop, drawCropPreview, hideCropBar, hitCropHandle, insideRect, resizeCropRect, setConstraint, showCropBar, updateCropInfo } from './crop.js'
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, renderObjects, selectUnit, shapeBounds, showTextInput } from './objects.js'
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, renderObjects, selectNeighborLayer, selectUnit, shapeBounds, showTextInput } from './objects.js'
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
import { close, exportResult } from './index.js'
import { loadImage } from './dom.js'
@@ -1741,7 +1741,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
}
// PS:] 增大 / [ 减小画笔大小(画笔与橡皮共用,光标环即时反馈)
if (!mod && !e.altKey && (e.key === '[' || e.key === ']')) {
// 同时匹配 e.code(BracketLeft/Right):中文输入法下 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)
@@ -1799,17 +1801,34 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
}
if (S.selectedTextId) { e.preventDefault(); deleteSelectedText(); renderLayerPanel(); return }
if (S.selectedShapeId) { e.preventDefault(); deleteSelectedShape(); renderLayerPanel(); return }
// PS 习惯:选中位图层(非原图)时 Delete 直接删除该图层
if (S.selectedLayerId && S.selectedLayerId !== 'base') {
e.preventDefault()
deleteLayer(S.selectedLayerId)
renderLayerPanel()
return
}
}
if (e.code === 'Space') {
e.preventDefault()
if (!S.spaceDown) { S.spaceDown = true; updateCursor() }
return
}
if (mod && (e.key === ']' || e.key === '[')) {
e.preventDefault()
const up = e.key === ']'
moveLayer(e.shiftKey ? (up ? 'top' : 'bottom') : (up ? 'up' : 'down'))
return
// ---- 图层快捷键(PS 同款,统一用 e.code 匹配防中文输入法吞键)----
// Ctrl+] / Ctrl+[ 上移/下移一层;Ctrl+Shift+] / Ctrl+Shift+[ 置顶/置底;
// Alt+] / Alt+[ 向上/向下选择图层(Mac 上 Cmd+]/[ 被浏览器前进/后退占用,用 Ctrl)
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()
+1 -1
View File
@@ -288,7 +288,7 @@ import { toast } from './commands.js'
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,
+2 -2
View File
@@ -383,8 +383,8 @@ export function setActiveLayer(id) {
renderLayerPanel()
}
/** 删除图层 */
function deleteLayer(id) {
/** 删除图层(图层面板按钮与 Delete 快捷键共用) */
export function deleteLayer(id) {
const idx = S.layers.findIndex(l => l.id === id)
if (idx < 0) return
// 不允许删除最后一个图层
+22 -1
View File
@@ -13,6 +13,7 @@ import { drawBitmapSelection, drawVectorToCanvas, hitBitmapAt, removeVecCanvas,
import { drawPlacementPreview } from './placement.js'
import { drawShape } from './tools.js'
import { saveSnapshot, snapshotState } from './history.js'
import { toast } from './commands.js'
import { renderOptionBar, updateLayerUI } from './events.js'
import { isDrawableLayer } from '../vendor/layer-logic.js'
@@ -226,7 +227,9 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
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
// 快捷键(Ctrl+]/[)与按钮共用此入口:没选中时给出可见反馈,不再无声失败
if (!sel) { toast('先在画布或图层面板选中要调整的元素', 'info'); return }
if (sel.obj.locked || sel.obj.id === 'base') return
const units = layerUnits()
// base 是锁定且不透明的底图,固定在最下层;任何元素都不许置底到它下面(否则等于消失)
const baseIdx = units.findIndex(u => u.obj.id === 'base')
@@ -251,6 +254,24 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
renderLayerPanel()
}
/** PS: Alt+] / Alt+[ 向上/向下选择图层(位图与矢量同一份 z 列表)。
* 当前没有任何选中时:向上选最顶层、向下选最底层,让用户能用键盘从头开始遍历。 */
export function selectNeighborLayer(up) {
const units = layerUnits()
if (!units.length) return
const sel = getSelectedObject()
let cur = -1
if (sel) cur = units.findIndex(u => u.obj === sel.obj)
else if (S.selectedLayerId) cur = units.findIndex(u => u.kind === 'bitmap' && u.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') {
+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) {
+81 -1
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.2.8', 'version=' + boot.version)
check('产物可执行(循环打包未炸)', boot.version === '1.2.9', '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 })
@@ -834,6 +834,86 @@ await page.keyboard.press('Control+z') // 撤销最后一次填充
await page.keyboard.press('Control+z') // 撤销钢笔路径
await page.keyboard.press('Control+z') // 撤销矩形线宽
// ---- v1.2.9:会话组(新建/覆盖/退出)移到顶栏最左 + 图层 PS 快捷键 ----
check('顶栏:新建/覆盖/退出 在最左侧(会话组),右侧只剩 输出+导出,下载文案改「导出」', await page.evaluate(() => {
const q = (s) => document.querySelector(s)
const session = q('.iwb-editor-header > .iwb-editor-session')
const title = q('.iwb-editor-header > .iwb-editor-title')
const ex = q('.iwb-editor-header > .iwb-editor-export-actions')
const dl = q('.iwb-editor-header [data-action="download"]')
if (!session || !title || !ex || !dl) return false
const btns = Array.from(session.querySelectorAll('.iwb-editor-btn')).map(b => b.dataset.action).join(',')
return btns === 'newNode,replace,cancel' &&
session.getBoundingClientRect().left < title.getBoundingClientRect().left &&
ex.contains(dl) && dl.textContent.trim() === '导出' &&
!ex.querySelector('[data-action="newNode"]')
}))
check('顶栏会话组左侧留白 ≤ 12px(贴 header 左内边距)', await page.evaluate(() => {
const hdr = document.querySelector('.iwb-editor-header')
const s = document.querySelector('.iwb-editor-header > .iwb-editor-session')
if (!hdr || !s) return false
return s.getBoundingClientRect().left - hdr.getBoundingClientRect().left <= 12
}))
// 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层
// 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z)
check('图层 PS 快捷键:Ctrl+[/] 上下移一层、Ctrl+Shift+[/] 置底/置顶', await (async () => {
const before = (await dbg()).layers.length
await page.keyboard.press('Control+Shift+n') // 新建空白图层并选中(z 最高)
const d1 = await dbg()
const newId = d1.selectedLayerId
if (!newId || d1.layers.length !== before + 1) return false
const zOf = (d) => {
const bits = d.layers.map(l => ({ id: l.id, z: l.z }))
const vec = d.shapes.map(s => ({ id: s.id, z: s.z }))
const all = bits.concat(vec)
const me = all.find(u => u.id === newId)
return { me: me && me.z, max: Math.max(...all.map(u => u.z)), minNonBase: Math.min(...all.filter(u => u.id !== 'base').map(u => u.z)) }
}
if (zOf(d1).me !== zOf(d1).max) return false // 新层此刻在最上
await page.keyboard.press('Control+[') // 下移一层 → 不再最上
const d2 = await dbg()
if (zOf(d2).me >= zOf(d2).max) return false
await page.keyboard.press('Control+]') // 上移一层 → 回到最上
const d3 = await dbg()
if (zOf(d3).me !== zOf(d3).max) return false
await page.keyboard.press('Control+Shift+[') // 置底 → base 之上第一格
const d4 = await dbg()
if (zOf(d4).me !== zOf(d4).minNonBase) return false
await page.keyboard.press('Control+Shift+]') // 置顶 → 回到最上
const d5 = await dbg()
return zOf(d5).me === zOf(d5).max
})())
check('图层 PS 快捷键:Alt+[/] 向下/向上选择图层', await (async () => {
const d1 = await dbg()
const bits = d1.layers.map(l => ({ id: l.id, z: l.z }))
const topUnit = bits.concat(d1.shapes.map(s => ({ id: s.id, z: s.z }))).sort((a, b) => b.z - a.z)[0]
const topId = topUnit.id
if (d1.selectedLayerId !== topId) return 'pre: sel=' + d1.selectedLayerId + ' top=' + topId + ' bits=' + JSON.stringify(bits) + ' shapes=' + JSON.stringify(d1.shapes)
await page.keyboard.press('Alt+[') // 向下选 → 选到下一个单元(矩形 shape)
const d2 = await dbg()
if (!d2.selectedShapeId || d2.selectedLayerId !== null) return 'down: selLayer=' + d2.selectedLayerId + ' selShape=' + d2.selectedShapeId
await page.keyboard.press('Alt+]') // 向上选 → 回到位图新层
const d3 = await dbg()
if (d3.selectedLayerId !== topId || d3.selectedShapeId) return 'up: selLayer=' + d3.selectedLayerId + ' selShape=' + d3.selectedShapeId
return true
})())
check('Delete 删除选中的位图图层(PS 习惯)', await (async () => {
const before = (await dbg()).layers.length
await page.keyboard.press('Delete')
const d = await dbg()
return d.layers.length === before - 1 && d.selectedLayerId === null
})())
check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (async () => {
await page.keyboard.press('Escape') // 清掉可能残留的选中态
await page.keyboard.press('Control+]')
const t = await page.locator('.iwb-editor-toast').textContent()
return t.indexOf('选中') >= 0
})())
await page.locator('[data-action="cancel"]').click()
const openState = await poll(async () => page.evaluate(() => window.__openState))