feat(image-annotate): v1.9.0 文字样式包、吸附参考线、圆角与最近色、复制到剪贴板

文字从「字号 + 颜色」扩到完整样式:字重(常规/粗/特粗)、对齐(左/中/右)、
行距、描边、底色块、多行(textarea + Shift+Enter)。新增叶子模块 text.js,
fontOf / textMetrics / textBox / drawTextObject 成为唯一事实来源,
objects.js(预览/命中/包围盒)与 layers.js(栅格化)共用,避免量一套画一套;
描边与底色撑大包围盒,手柄、吸附、缩略图随之变化。单行无描边无底色的老文字
包围盒与旧实现逐像素一致,老作业打开不变形。

吸附参考线:snap.js 只做纯计算。目标线为画布 0/中/满 + 其他可见元素的左中右、
上中下;阈值 6 屏幕像素按 viewScale() 折回图片像素,磁力不随缩放变大;
命中画洋红参考线(区别于选中框的橙),松手清空;Alt 全程禁用。
位图/文字/形状三条拖动路径都接,文字需补 b.x - t.x 原点偏移。

矩形圆角:shapeRadius 进 drawShape,半径夹到 min(w,h)/2,路径手写 arcTo
(不用 ctx.roundRect,老内核没有)。最近使用颜色最多 8 个,存 ctx.settings
跨会话保留,只有落定的改色才记录;色板改用事件委托以覆盖动态插入的色块。

导出「复制」:结果编成 PNG 写 ClipboardItem,可直接粘进聊天窗口/后台上传框
且不关闭编辑器。优先 createImageBitmap 绕开宿主 CSP 的 img-src 限制;
非安全上下文无 navigator.clipboard 时明确提示改用「导出」而非静默失败。

顺带修:选项栏中文双字标签加 white-space:nowrap(否则 36px 一行内竖排成
「常/规」);.iwb-editor-optionbar-tip 补基础样式(原来只有 display:none,
裸 span 参与 flex 收缩被挤成两行贴边);文字工具的 hint 移到按钮之后,
放不下时让说明滚出视野而不是把操作按钮顶没。

harness 140 → 158 条,全部通过;validate 9/9。
This commit is contained in:
qiqi committed 2026-11-08 20:27:32 +08:00
1 parent 040b08fe28
commit e699c22fa0
17 files changed
+1678 -99

No files matched your search

+607 -49
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.8.3',
version: '1.9.0',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -63,8 +63,25 @@ var __IWB_ANNOTATE_MANIFEST__ = {
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
shapeLineWidth: 3,
// 矩形/圆形/箭头/钢笔的描边粗细
shapeRadius: 0,
// 矩形圆角半径 px(v1.9,仅 rect 有意义)
textSize: 32,
// 新建文字的字号 px
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
textWeight: "bold",
// bold | normal | 900
textAlign: "left",
// left | center | right(多行时各行按块宽对齐)
textLineHeight: 1.25,
// 行高倍数(1.25 = 老版单行高度,勿随意改)
textStrokeWidth: 0,
// 描边宽度 px,0 = 无描边
textStrokeColor: "#ffffff",
textBgFill: false,
// 底色块
textBgColor: "#000000",
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
recentColors: [],
// 图层系统
layers: [],
// 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }]
@@ -171,6 +188,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
// 轻量交互状态机:idle | marquee | lasso | placing | cropping
renderAll: null,
// 由 index.js 注入的统一重绘出口
guides: null,
// 拖动吸附参考线(图片坐标,松手清空):[{axis:'x'|'y', at, from, to}]
lastExport: null
// 观测口:{ bytes, width, height, format, preset }
};
@@ -461,6 +480,50 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return 0;
}
// image-annotate/plugin/editor/recent-colors.js
var MAX = 8;
var KEY = "recentColors";
function valid(hex) {
return /^#[0-9a-f]{6}$/i.test(String(hex || ""));
}
function loadRecentColors() {
const st = S.callbacks && S.callbacks.settings;
let list = [];
if (st && typeof st.get === "function") {
try {
const got = st.get(KEY);
if (Array.isArray(got)) list = got;
} catch (e) {
}
}
S.recentColors = list.filter(valid).map((c) => String(c).toLowerCase()).slice(0, MAX);
renderRecentColors();
}
function rememberColor(hex) {
if (!valid(hex)) return;
const c = String(hex).toLowerCase();
if (S.recentColors && S.recentColors[0] === c) return;
const list = [c].concat((S.recentColors || []).filter((x) => x !== c));
S.recentColors = list.slice(0, MAX);
const st = S.callbacks && S.callbacks.settings;
if (st && typeof st.set === "function") {
try {
st.set(KEY, S.recentColors);
} catch (e) {
}
}
renderRecentColors();
}
function renderRecentColors() {
const wrap = runtime.el && runtime.el.querySelector(".iwb-editor-recent-colors");
if (!wrap) return;
const list = S.recentColors || [];
wrap.innerHTML = list.map(
(c) => `<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="最近使用 ${c}"></button>`
).join("");
wrap.hidden = !list.length;
}
// image-annotate/plugin/editor/tools.js
var brushStampCache = { key: "", canvas: null };
function getBrushStamp(size, color, hardness) {
@@ -585,6 +648,20 @@ var __IWB_ANNOTATE_MANIFEST__ = {
S.strokeCtx.clearRect(0, 0, S.imgW, S.imgH);
S.pickerComposite = null;
}
function roundedRadius(s, w, h) {
const r = Number(s && s.radius) || 0;
if (r <= 0) return 0;
return Math.min(r, Math.min(w, h) / 2);
}
function roundRectPath(ctx, x, y, w, h, r) {
const rr = Math.min(r, Math.min(w, h) / 2);
ctx.moveTo(x + rr, y);
ctx.arcTo(x + w, y, x + w, y + h, rr);
ctx.arcTo(x + w, y + h, x, y + h, rr);
ctx.arcTo(x, y + h, x, y, rr);
ctx.arcTo(x, y, x + w, y, rr);
ctx.closePath();
}
function drawShape(ctx, s) {
ctx.save();
ctx.globalAlpha = s.opacity != null ? s.opacity : 1;
@@ -615,11 +692,22 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
} else if (s.type === "rect") {
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1);
if (s.fill) {
ctx.fillStyle = s.color;
ctx.fillRect(rx, ry, rw, rh);
const radius = roundedRadius(s, rw, rh);
if (radius > 0) {
ctx.beginPath();
roundRectPath(ctx, rx, ry, rw, rh, radius);
if (s.fill) {
ctx.fillStyle = s.color;
ctx.fill();
}
ctx.stroke();
} else {
if (s.fill) {
ctx.fillStyle = s.color;
ctx.fillRect(rx, ry, rw, rh);
}
ctx.strokeRect(rx, ry, rw, rh);
}
ctx.strokeRect(rx, ry, rw, rh);
} else if (s.type === "circle") {
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2);
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1);
@@ -780,6 +868,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
function applyColorChange(color, opts) {
const skipHistory = !!(opts && opts.skipHistory);
S.color = color;
if (!skipHistory) rememberColor(color);
updateColorUI();
const t = getSelectedText();
if (t && !t.locked && t.color !== S.color) {
@@ -901,14 +990,186 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}, 2600);
}
// image-annotate/plugin/editor/text.js
var TEXT_LINE_HEIGHT = 1.25;
var BG_PAD_RATIO = 0.3;
var _measureCtx = null;
function measureCtx() {
if (!_measureCtx) {
const c = document.createElement("canvas");
c.width = 8;
c.height = 8;
_measureCtx = c.getContext("2d");
}
return _measureCtx;
}
function weightOf(t) {
const w = t && t.fontWeight;
return w == null || w === "" ? "bold" : String(w);
}
function fontOf(t) {
const size = Math.max(4, Number(t && t.fontSize) || 32);
return weightOf(t) + " " + size + "px sans-serif";
}
function textMetrics(t) {
const ctx = measureCtx();
const font = fontOf(t);
ctx.font = font;
const raw = (t && t.text) == null ? "" : String(t.text);
const lines = raw.split("\n");
const widths = lines.map((line) => ctx.measureText(line).width);
const size = Math.max(4, Number(t && t.fontSize) || 32);
const lh = size * (Number(t && t.lineHeight) || TEXT_LINE_HEIGHT);
const w = lines.length ? Math.max.apply(null, widths) : 0;
const pad = t && t.bgFill ? Math.round(size * BG_PAD_RATIO) : 0;
const sw = Math.max(0, Number(t && t.strokeWidth) || 0);
return { lines, widths, w, h: lh * lines.length, lh, pad, sw, font, size };
}
function textBox(t) {
const m = textMetrics(t);
const half = m.sw / 2;
return {
x: t.x - half,
y: t.y - half,
w: Math.max(m.w, 2) + m.pad * 2 + m.sw,
h: Math.max(m.h, 1) + m.pad * 2 + m.sw
};
}
function alignOf(t) {
const a = t && t.align;
return a === "center" || a === "right" ? a : "left";
}
function drawTextObject(ctx, t) {
const m = textMetrics(t);
ctx.save();
ctx.textBaseline = "top";
ctx.globalAlpha = t.opacity != null ? t.opacity : 1;
const b = textBox(t);
const rot = t.rotation || 0;
if (rot) {
const cx = b.x + b.w / 2;
const cy = b.y + b.h / 2;
ctx.translate(cx, cy);
ctx.rotate(rot * Math.PI / 180);
ctx.translate(-cx, -cy);
}
ctx.font = m.font;
const align = alignOf(t);
const boxW = m.w + m.pad * 2;
if (t.bgFill) {
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2);
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? 0.55 : t.bgAlpha);
ctx.fillStyle = t.bgColor || "#000000";
const bx = t.x, by = t.y;
const bw = boxW, bh = m.h + m.pad * 2;
ctx.beginPath();
if (typeof ctx.roundRect === "function") {
ctx.roundRect(bx, by, bw, bh, r);
} else {
ctx.moveTo(bx + r, by);
ctx.arcTo(bx + bw, by, bx + bw, by + bh, r);
ctx.arcTo(bx + bw, by + bh, bx, by + bh, r);
ctx.arcTo(bx, by + bh, bx, by, r);
ctx.arcTo(bx, by, bx + bw, by, r);
ctx.closePath();
}
ctx.fill();
ctx.globalAlpha = t.opacity != null ? t.opacity : 1;
}
ctx.textAlign = align;
const left = t.x + m.pad;
const ox = align === "center" ? left + m.w / 2 : align === "right" ? left + m.w : left;
ctx.lineJoin = "round";
ctx.miterLimit = 2;
for (let i = 0; i < m.lines.length; i++) {
const y = t.y + m.pad + i * m.lh;
if (m.sw > 0) {
ctx.lineWidth = m.sw;
ctx.strokeStyle = t.strokeColor || "#ffffff";
ctx.strokeText(m.lines[i], ox, y);
}
ctx.fillStyle = t.color || "#ff4444";
ctx.fillText(m.lines[i], ox, y);
}
ctx.restore();
}
function newTextStyle(src) {
const s = src || {};
return {
fontWeight: weightOf(s),
align: alignOf(s),
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
strokeColor: s.strokeColor || "#ffffff",
bgFill: !!s.bgFill,
bgColor: s.bgColor || "#000000",
bgAlpha: s.bgAlpha == null ? 0.55 : Number(s.bgAlpha)
};
}
// image-annotate/plugin/editor/snap.js
var SNAP_SCREEN_PX = 6;
var GUIDE_COLOR = "#ff2d95";
function pushBox(targets, box) {
const x2 = box.x + box.w;
const y2 = box.y + box.h;
targets.x.push(box.x, box.x + box.w / 2, x2);
targets.y.push(box.y, box.y + box.h / 2, y2);
}
function nearest(targets, sources, tol, axis) {
let best = null;
for (let i = 0; i < targets.length; i++) {
for (let j = 0; j < sources.length; j++) {
const delta = targets[i] - sources[j];
const abs = Math.abs(delta);
if (abs > tol) continue;
if (!best || abs < Math.abs(best.delta)) best = { delta, at: targets[i], axis };
}
}
return best;
}
function snapMove(box, others) {
const tol = SNAP_SCREEN_PX / Math.max(0.02, viewScale());
const targets = { x: [0, S.imgW / 2, S.imgW], y: [0, S.imgH / 2, S.imgH] };
for (const o of others || []) {
if (!o || !isFinite(o.x) || !isFinite(o.y)) continue;
pushBox(targets, o);
}
const sourcesX = [box.x, box.x + box.w / 2, box.x + box.w];
const sourcesY = [box.y, box.y + box.h / 2, box.y + box.h];
const gx = nearest(targets.x, sourcesX, tol, "x");
const gy = nearest(targets.y, sourcesY, tol, "y");
const guides = [];
if (gx) guides.push(gx);
if (gy) guides.push(gy);
return { dx: gx ? gx.delta : 0, dy: gy ? gy.delta : 0, guides };
}
function drawGuides(ctx, guides) {
if (!guides || !guides.length || !ctx) return;
const scale = viewScale();
const pad = S.overlayPad || 0;
ctx.save();
ctx.strokeStyle = GUIDE_COLOR;
ctx.lineWidth = 1 / Math.max(0.02, scale);
ctx.setLineDash([6 / Math.max(0.02, scale), 4 / Math.max(0.02, scale)]);
for (const g of guides) {
ctx.beginPath();
if (g.axis === "x") {
ctx.moveTo(g.at, -pad);
ctx.lineTo(g.at, S.imgH + pad);
} else {
ctx.moveTo(-pad, g.at);
ctx.lineTo(S.imgW + pad, g.at);
}
ctx.stroke();
}
ctx.setLineDash([]);
ctx.restore();
}
// image-annotate/plugin/editor/objects.js
var TEXT_FONT = (size) => "bold " + size + "px sans-serif";
function textBounds(t) {
const ctx = S.textCtx;
ctx.font = TEXT_FONT(t.fontSize);
const w = ctx.measureText(t.text).width;
const h = t.fontSize * 1.25;
return { x: t.x, y: t.y, w, h };
return textBox(t);
}
function getSelectedText() {
return S.textLayers.find((t) => t.id === S.selectedTextId) || null;
@@ -1066,6 +1327,21 @@ var __IWB_ANNOTATE_MANIFEST__ = {
for (const unit of layerUnitsDesc()) if (hitUnit(unit, pos)) return unit;
return null;
}
function otherObjectBoxes(exclude) {
const out = [];
for (const unit of layerUnits()) {
const o = unit.obj;
if (!o || o === exclude || o.id === "base" || o.visible === false) continue;
if (unit.kind === "bitmap") {
if (isFinite(o.x) && isFinite(o.y) && o.w > 0 && o.h > 0) out.push({ x: o.x, y: o.y, w: o.w, h: o.h });
} else if (unit.kind === "text") {
out.push(textBox(o));
} else {
out.push(shapeBounds(o));
}
}
return out;
}
function hitAnyObject(pos) {
for (const unit of layerUnitsDesc()) {
if (unit.kind === "bitmap") continue;
@@ -1307,6 +1583,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
for (const { kind, obj } of allObjects()) drawVectorToCanvas(kind, obj);
reorderLayerCanvas();
clearOverlay();
drawGuides(S.overlayCtx, S.guides);
if (tempShape) drawShape(S.overlayCtx, tempShape);
if (S.tool === "pen" && S.penPath && S.penPath.pts.length) drawPenPathPreview();
if (S.placingImage) {
@@ -1449,6 +1726,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
input.select();
input.dataset.x = x;
input.dataset.y = y;
input.style.height = "auto";
input.style.height = Math.max(30, input.scrollHeight + 4) + "px";
}
function hideTextInput() {
const input = runtime.el.querySelector(".iwb-editor-text-input");
@@ -1493,6 +1772,16 @@ var __IWB_ANNOTATE_MANIFEST__ = {
text,
color: S.color,
fontSize: Math.max(8, S.textSize),
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
...newTextStyle({
fontWeight: S.textWeight,
align: S.textAlign,
lineHeight: S.textLineHeight,
strokeWidth: S.textStrokeWidth,
strokeColor: S.textStrokeColor,
bgFill: S.textBgFill,
bgColor: S.textBgColor
}),
opacity: 1,
visible: true,
locked: false,
@@ -1815,8 +2104,18 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (!drag || !layer) return;
const base = drag.layer;
if (drag.mode === "move") {
layer.x = base.x + pos.x - drag.start.x;
layer.y = base.y + pos.y - drag.start.y;
let nx = base.x + pos.x - drag.start.x;
let ny = base.y + pos.y - drag.start.y;
if (!S._altDown && base.w > 0 && base.h > 0) {
const s = snapMove({ x: nx, y: ny, w: base.w, h: base.h }, otherObjectBoxes(layer));
nx += s.dx;
ny += s.dy;
S.guides = s.guides.length ? s.guides : null;
} else {
S.guides = null;
}
layer.x = nx;
layer.y = ny;
if (isDrawableLayer(layer)) layer._bounds = void 0;
} else if (drag.mode === "rotate") {
const rcx = base.x + base.w / 2, rcy = base.y + base.h / 2;
@@ -1983,21 +2282,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (kind === "shape") {
drawShape(ctx, obj);
} else {
ctx.save();
ctx.textBaseline = "top";
ctx.globalAlpha = obj.opacity != null ? obj.opacity : 1;
const rot = obj.rotation || 0;
if (rot) {
const b = textBounds(obj);
const cx = b.x + b.w / 2, cy = b.y + b.h / 2;
ctx.translate(cx, cy);
ctx.rotate(rot * Math.PI / 180);
ctx.translate(-cx, -cy);
}
ctx.font = TEXT_FONT(obj.fontSize);
ctx.fillStyle = obj.color;
ctx.fillText(obj.text, obj.x, obj.y);
ctx.restore();
drawTextObject(ctx, obj);
}
}
function toggleLayerVisibility(id) {
@@ -3207,13 +3492,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<div class="iwb-editor-export-note">一次只输出一个结果;设置会记住</div>
</div>
</div>
<button class="iwb-editor-btn iwb-editor-btn-copy" data-action="copyClipboard" title="复制当前结果到系统剪贴板(可直接粘到聊天窗口/后台),不关闭编辑器">复制</button>
<button class="iwb-editor-btn iwb-editor-btn-download" data-action="download" title="导出当前这一张(不关闭编辑器)">导出</button>
</div>
</div>
<div class="iwb-editor-optionbar">
<span class="iwb-editor-optionbar-label">工具选项</span>
<div class="iwb-editor-optionbar-body"></div>
<span class="iwb-editor-optionbar-tip">选区也可右键;Ctrl+J 复制 · Delete 清除 · Ctrl+D 取消</span>
<span class="iwb-editor-optionbar-tip" title="选中后还可右键;Ctrl+J 复制 · Delete 清除 · Ctrl+D 取消选区">Ctrl+J 复制 · Delete 清除</span>
</div>
<div class="iwb-editor-main">
@@ -3242,7 +3528,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<canvas class="iwb-editor-selection-overlay"></canvas>
<canvas class="iwb-editor-cursor-overlay"></canvas>
</div>
<input class="iwb-editor-text-input" type="text" placeholder="输入文字,Enter确认,Esc取消">
<!-- v1.9:input → textarea,支持 Shift+Enter 换行(Enter 仍是确认) -->
<textarea class="iwb-editor-text-input" rows="1" wrap="off" placeholder="输入文字,Enter 确认,Shift+Enter 换行" spellcheck="false"></textarea>
<div class="iwb-editor-picker-tip"><span class="iwb-editor-picker-chip"></span><span class="iwb-editor-picker-hex">#ffffff</span></div>
<!-- 裁剪参数已迁入选项栏(v1.2.2),画布下方浮窗删除 -->
<div class="iwb-editor-sel-bar">
@@ -3367,6 +3654,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
</div>
<span class="iwb-color-pop-sep"></span>
<!-- 最近使用(v1.9):由 recent-colors.js 动态填充,空的时候整行隐藏 -->
<div class="iwb-editor-recent-colors" hidden title="最近使用"></div>
<div class="iwb-editor-color-swatches">
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff4444" style="background:#ff4444" title="#ff4444"></button>
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff8a00" style="background:#ff8a00" title="#ff8a00"></button>
@@ -4027,6 +4316,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
crop: onCropDrawMove
};
function onMouseMove(e) {
S._altDown = !!e.altKey;
if (S.placingImage && S.placingHandle && S.placingStart) {
onPlacementDragMove(e);
return;
@@ -4100,8 +4390,21 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (S.textDrag.mode === "move") {
const dx = pos0.x - S.textDrag.start.x;
const dy = pos0.y - S.textDrag.start.y;
t.x = clamp(S.textDrag.layer.x + dx, 0, Math.max(0, S.imgW - 4));
t.y = clamp(S.textDrag.layer.y + dy, 0, Math.max(0, S.imgH - 4));
let nx = clamp(S.textDrag.layer.x + dx, 0, Math.max(0, S.imgW - 4));
let ny = clamp(S.textDrag.layer.y + dy, 0, Math.max(0, S.imgH - 4));
if (!S._altDown) {
const b = textBounds(t);
const offX = b.x - t.x;
const offY = b.y - t.y;
const s = snapMove({ x: nx + offX, y: ny + offY, w: b.w, h: b.h }, otherObjectBoxes(t));
nx += s.dx;
ny += s.dy;
S.guides = s.guides.length ? s.guides : null;
} else {
S.guides = null;
}
t.x = nx;
t.y = ny;
} else if (S.textDrag.mode === "rotate") {
const st = S.textDrag;
const a1 = Math.atan2(pos0.y - st.cy, pos0.x - st.cx);
@@ -4137,8 +4440,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
const dx = pos0.x - S.shapeDrag.start.x;
const dy = pos0.y - S.shapeDrag.start.y;
const b = shapeBounds(S.shapeDrag.shape);
const cdx = clamp(dx, -b.x, Math.max(-b.x, S.imgW - (b.x + b.w)));
const cdy = clamp(dy, -b.y, Math.max(-b.y, S.imgH - (b.y + b.h)));
let cdx = clamp(dx, -b.x, Math.max(-b.x, S.imgW - (b.x + b.w)));
let cdy = clamp(dy, -b.y, Math.max(-b.y, S.imgH - (b.y + b.h)));
if (!S._altDown) {
const box = { x: b.x + cdx, y: b.y + cdy, w: b.w, h: b.h };
const s = snapMove(box, otherObjectBoxes(sh));
cdx += s.dx;
cdy += s.dy;
S.guides = s.guides.length ? s.guides : null;
} else {
S.guides = null;
}
if (sh.type === "pen") {
sh.pts = (S.shapeDrag.shape.pts || []).map((p) => ({ x: p.x + cdx, y: p.y + cdy }));
} else {
@@ -4187,6 +4499,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
lw: Math.max(1, S.shapeLineWidth),
lineWidth: Math.max(1, S.shapeLineWidth),
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
opacity: 1,
visible: true
};
@@ -4295,6 +4608,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
}
S.textDrag = null;
S.guides = null;
renderObjects();
renderLayerPanel();
return;
}
@@ -4310,6 +4625,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
}
S.bitmapDrag = null;
S.guides = null;
renderObjects();
renderLayerPanel();
return;
@@ -4324,6 +4640,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
}
S.shapeDrag = null;
S.guides = null;
renderObjects();
renderLayerPanel();
return;
}
@@ -4370,6 +4688,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
color: S.color,
lw: Math.max(1, S.shapeLineWidth),
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
opacity: 1,
visible: true,
locked: false,
@@ -4588,6 +4907,46 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心 (Shift+X 切换)">实心</button>`;
}
var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" };
var TEXT_STYLE_STATE_KEY = {
fontWeight: "textWeight",
align: "textAlign",
lineHeight: "textLineHeight",
strokeWidth: "textStrokeWidth",
strokeColor: "textStrokeColor",
bgFill: "textBgFill",
bgColor: "textBgColor"
};
function textStyleValues(t) {
const pick = (objKey, stateKey, dflt) => {
const raw = t ? t[objKey] : S[stateKey];
return raw == null ? dflt : raw;
};
return {
fontWeight: String(pick("fontWeight", "textWeight", "bold")),
align: pick("align", "textAlign", "left"),
lineHeight: Number(pick("lineHeight", "textLineHeight", 1.25)) || 1.25,
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", 0)) || 0),
strokeColor: pick("strokeColor", "textStrokeColor", "#ffffff"),
bgFill: !!pick("bgFill", "textBgFill", false),
bgColor: pick("bgColor", "textBgColor", "#000000")
};
}
function textStyleHTML(t) {
const v = textStyleValues(t);
const wBtn = (val, label, title) => `<button class="iwb-opt-btn${v.fontWeight === val ? " active" : ""}" data-opt-text="fontWeight" data-value="${val}" title="${title}">${label}</button>`;
const aBtn = (val, label, title) => `<button class="iwb-opt-btn${v.align === val ? " active" : ""}" data-opt-text="align" data-value="${val}" title="${title}">${label}</button>`;
return `<span class="iwb-opt-sep"></span>
<span class="iwb-opt-label">字重</span>${wBtn("normal", "常规", "常规字重")}${wBtn("bold", "粗", "粗体(默认)")}${wBtn("900", "特粗", "特粗,封面标题用")}
<span class="iwb-opt-label">对齐</span>${aBtn("left", "左", "多行时按左缘对齐")}${aBtn("center", "中", "多行时居中")}${aBtn("right", "右", "多行时按右缘对齐")}
<span class="iwb-opt-label">行距</span>
<input type="number" class="iwb-opt-num" data-opt="textLineHeight" min="80" max="300" step="5" value="${Math.round(v.lineHeight * 100)}"><span class="iwb-opt-unit">%</span>
<span class="iwb-opt-sep"></span>
<span class="iwb-opt-label">描边</span>
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
<input type="color" class="iwb-opt-color" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色">
<button class="iwb-opt-btn${v.bgFill ? " active" : ""}" data-opt-text="bgFill" data-value="${v.bgFill ? "0" : "1"}" title="给文字加一块半透明底色,压在花背景上也能看清">底色</button>
<input type="color" class="iwb-opt-color" data-opt-color="bgColor" value="${v.bgColor}" title="底色颜色(55% 透明)">`;
}
var SELCMD_SVGS = {
all: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="3 2"><rect x="3.5" y="3.5" width="17" height="17" rx="1"/></svg>',
invert: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="3.5" width="17" height="17" rx="1" stroke-dasharray="3 2"/><rect x="8" y="8" width="8" height="8" rx="1" fill="currentColor" stroke="none"/></svg>',
@@ -4604,12 +4963,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (t === "rect" || t === "circle" || t === "pen" || t === "arrow") {
const owner = t === "pen" ? "pen" : "rect";
const lw = Math.max(1, Math.round(sh.lw || S.shapeLineWidth));
return `<span class="iwb-opt-current">已选中:${SHAPE_NAMES[t] || t}</span>` + rangeOpt("shapeLineWidth", "线宽", 1, 60, lw, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (t === "arrow" ? "" : fillStyleHTML(owner)) + (t === "pen" && !sh.closed ? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>' : "") + selCmdHTML();
return `<span class="iwb-opt-current">已选中:${SHAPE_NAMES[t] || t}</span>` + rangeOpt("shapeLineWidth", "线宽", 1, 60, lw, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (t === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, Math.round(sh.radius || 0), "px") : "") + (t === "arrow" ? "" : fillStyleHTML(owner)) + (t === "pen" && !sh.closed ? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>' : "") + selCmdHTML();
}
}
const text = getSelectedText();
if (text) {
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + '<span class="iwb-opt-hint">双击文字改内容,拖动移动,手柄缩放</span>' + selCmdHTML();
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + textStyleHTML(text) + selCmdHTML() + '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>';
}
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>
<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里会出现它的描边、实心与粗细</span>` + selCmdHTML();
@@ -4626,7 +4985,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<span class="iwb-opt-val" data-opt-val="brushOpacity">${Math.round(S.brushOpacity * 100)}%</span>` + presetDots("brushHardness", [0, 25, 50, 75, 100]);
}
if (tool === "rect" || tool === "circle") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + fillStyleHTML("rect");
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (tool === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, S.shapeRadius, "px") : "") + fillStyleHTML("rect");
}
if (tool === "arrow") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + '<span class="iwb-opt-hint">拖出箭头,松手完成</span>';
@@ -4635,7 +4994,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + fillStyleHTML("pen") + '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>';
}
if (tool === "text") {
return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + '<span class="iwb-opt-hint">点画布输入文字,Enter 确认</span>';
return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + textStyleHTML(null) + '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>';
}
if (tool === "marquee") {
return `<span class="iwb-opt-label">形状</span>
@@ -4675,7 +5034,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (key === "brushHardness") return S.brushHardness;
if (key === "brushOpacity") return Math.round(S.brushOpacity * 100);
if (key === "shapeLineWidth") return selShape ? Math.max(1, Math.round(selShape.lw || S.shapeLineWidth)) : S.shapeLineWidth;
if (key === "shapeRadius") return selShape && selShape.type === "rect" ? Math.round(selShape.radius || 0) : S.shapeRadius;
if (key === "textSize") return selText ? Math.round(selText.fontSize || S.textSize) : S.textSize;
if (key === "textLineHeight") return Math.round((selText ? Number(selText.lineHeight) || S.textLineHeight : S.textLineHeight) * 100);
if (key === "textStrokeWidth") return Math.round(selText ? Number(selText.strokeWidth) || 0 : S.textStrokeWidth);
if (key === "feather") return S.selectionFeather;
return "";
};
@@ -4699,6 +5061,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
btn.classList.toggle("active", !!cur === (btn.dataset.value === "fill"));
});
const sv = textStyleValues(selText);
body.querySelectorAll("[data-opt-text]").forEach((btn) => {
const k = btn.dataset.optText;
const cur = k === "bgFill" ? sv.bgFill ? "1" : "0" : String(sv[k]);
btn.classList.toggle("active", cur === btn.dataset.value);
});
body.querySelectorAll("[data-opt-color]").forEach((inp) => {
if (document.activeElement === inp) return;
const v = sv[inp.dataset.optColor];
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
});
}
function updateStatusbar() {
if (!runtime.el) return;
@@ -4746,6 +5119,45 @@ var __IWB_ANNOTATE_MANIFEST__ = {
renderObjects();
if (committed) textSnapDone = false;
}
var textStyleSnapDone = false;
function applyTextStyle(key, raw, committed) {
const stateKey = TEXT_STYLE_STATE_KEY[key];
if (!stateKey) return;
let value = raw;
if (key === "bgFill") value = raw === true || raw === 1 || raw === "1" || raw === "true";
else if (key === "lineHeight") value = clamp(Number(raw) || 125, 80, 300) / 100;
else if (key === "strokeWidth") value = clamp(Number(raw) || 0, 0, 40);
else if (key === "strokeColor" || key === "bgColor") value = String(raw || "#000000").toLowerCase();
else value = String(raw);
S[stateKey] = value;
const t = getSelectedText();
if (!t || t.locked) {
textStyleSnapDone = false;
return;
}
if (committed || !textStyleSnapDone) {
saveSnapshot("文字样式");
textStyleSnapDone = true;
}
t[key] = value;
renderObjects();
if (committed) textStyleSnapDone = false;
}
var radiusSnapDone = false;
function applyShapeRadius(committed) {
const sh = getSelectedShape();
if (!sh || sh.locked || sh.type !== "rect") {
radiusSnapDone = false;
return;
}
if (committed || !radiusSnapDone) {
saveSnapshot("圆角");
radiusSnapDone = true;
}
sh.radius = S.shapeRadius;
renderObjects();
if (committed) radiusSnapDone = false;
}
function setShapeFill(fill, owner) {
const isPen = owner === "pen";
if (isPen) S.penFill = !!fill;
@@ -4784,6 +5196,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
} else if (key === "textSize") {
S.textSize = clamp(safe || 32, 8, 400);
applyTextSize(committed);
} else if (key === "textLineHeight") {
applyTextStyle("lineHeight", safe || 125, committed);
} else if (key === "textStrokeWidth") {
applyTextStyle("strokeWidth", safe, committed);
} else if (key === "shapeRadius") {
S.shapeRadius = clamp(safe, 0, 400);
applyShapeRadius(committed);
} else if (key === "feather") {
S.selectionFeather = clamp(safe, 0, 20);
if (S.selection && S.selection.active) S.selection.feather = S.selectionFeather;
@@ -4856,8 +5275,25 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (body) {
body.addEventListener("mousedown", (e) => e.stopPropagation());
body.addEventListener("input", (e) => setOptionFromControl(e.target, false));
body.addEventListener("change", (e) => setOptionFromControl(e.target, true));
body.addEventListener("change", (e) => {
const colorEl = e.target.closest ? e.target.closest("[data-opt-color]") : null;
if (colorEl) {
e.stopPropagation();
applyTextStyle(colorEl.dataset.optColor, colorEl.value, true);
syncOptionBar();
return;
}
setOptionFromControl(e.target, true);
});
body.addEventListener("click", (e) => {
const textBtn = e.target.closest("[data-opt-text]");
if (textBtn) {
e.stopPropagation();
const k = textBtn.dataset.optText;
applyTextStyle(k, textBtn.dataset.value, true);
syncOptionBar();
return;
}
const shapeBtn = e.target.closest('[data-opt="shape"]');
if (shapeBtn) {
e.stopPropagation();
@@ -5041,10 +5477,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (panelHexInput) panelHexInput.addEventListener("change", () => {
if (/^#[0-9a-f]{6}$/i.test(panelHexInput.value)) setPanelColor(panelHexInput.value);
});
runtime.el.querySelectorAll(".iwb-editor-color-panel-swatch").forEach((btn) => btn.addEventListener("click", (e) => {
e.stopPropagation();
setPanelColor(btn.dataset.panelColor);
}));
if (pop) {
pop.addEventListener("click", (e) => {
const btn = e.target.closest("[data-panel-color]");
if (!btn) return;
e.stopPropagation();
setPanelColor(btn.dataset.panelColor);
});
}
const palettePick = runtime.el.querySelector('[data-action="palettePick"]');
if (palettePick) {
palettePick.addEventListener("mousedown", (e) => e.stopPropagation());
@@ -5243,6 +5683,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
function bindExportActions() {
bindIf('[data-action="cancel"]', "click", close);
bindIf('[data-action="download"]', "click", () => exportResult("download"));
bindIf('[data-action="copyClipboard"]', "click", () => copyResult());
bindIf('[data-action="newNode"]', "click", () => exportResult("newNode"));
bindIf('[data-action="replace"]', "click", () => exportResult("replace"));
}
@@ -5251,10 +5692,16 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
function bindTextInput() {
const textInput = runtime.el.querySelector(".iwb-editor-text-input");
textInput && textInput.addEventListener("mousedown", (e) => e.stopPropagation());
textInput && textInput.addEventListener("keydown", (e) => {
if (!textInput) return;
textInput.addEventListener("mousedown", (e) => e.stopPropagation());
const autosize = () => {
textInput.style.height = "auto";
textInput.style.height = textInput.scrollHeight + 4 + "px";
};
textInput.addEventListener("input", autosize);
textInput.addEventListener("keydown", (e) => {
e.stopPropagation();
if (e.key === "Enter") {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
commitTextInput();
} else if (e.key === "Escape") {
@@ -6947,6 +7394,70 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}, 2e3);
toast("已下载 " + name + "(" + Math.round(blob.size / 1024) + "KB)", "success");
}
async function toPngBlob(blob) {
try {
if (typeof createImageBitmap === "function") {
const bmp = await createImageBitmap(blob);
const c = document.createElement("canvas");
c.width = bmp.width;
c.height = bmp.height;
c.getContext("2d").drawImage(bmp, 0, 0);
if (typeof bmp.close === "function") bmp.close();
const out = await new Promise((res) => c.toBlob((b) => res(b), "image/png"));
c.width = 0;
c.height = 0;
if (out) return out;
}
} catch (e) {
}
return await new Promise((resolve) => {
const url = URL.createObjectURL(blob);
const img = new Image();
img.onload = () => {
const c = document.createElement("canvas");
c.width = img.naturalWidth;
c.height = img.naturalHeight;
c.getContext("2d").drawImage(img, 0, 0);
try {
URL.revokeObjectURL(url);
} catch (e) {
}
c.toBlob((b) => resolve(b || blob), "image/png");
};
img.onerror = () => {
try {
URL.revokeObjectURL(url);
} catch (e) {
}
resolve(blob);
};
img.src = url;
});
}
async function copyBlobToClipboard(blob) {
const nav = typeof navigator !== "undefined" ? navigator : null;
const CI = typeof window !== "undefined" ? window.ClipboardItem : null;
if (!nav || !nav.clipboard || typeof nav.clipboard.write !== "function" || typeof CI !== "function") {
toast("当前浏览器不支持复制图片,请用「导出」下载", "warn");
return false;
}
let png = blob;
if (blob.type !== "image/png") {
try {
png = await toPngBlob(blob);
} catch (e) {
png = blob;
}
}
try {
await nav.clipboard.write([new CI({ "image/png": png })]);
toast("已复制到剪贴板(" + Math.round(png.size / 1024) + "KB),可直接粘贴", "success");
return true;
} catch (e) {
toast("复制失败:" + (e && e.message || "浏览器拒绝了剪贴板写入") + ";可用「导出」下载", "error");
return false;
}
}
// image-annotate/plugin/editor/index.js
async function open(options) {
@@ -6969,6 +7480,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
updateAllUI();
registerSelectionCommands();
loadExportOptions();
loadRecentColors();
bindLiteUI();
bindFloating();
bindExportUI();
@@ -7154,6 +7666,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (S.callbacks && S.callbacks.onError) S.callbacks.onError("导出失败:" + (e && e.message || "图片跨域"));
}
}
async function copyResult() {
if (S.placingImage) cancelImagePlacement();
try {
const { blob } = await prepareOutput();
await copyBlobToClipboard(blob);
if (S.renderAll) S.renderAll();
} catch (e) {
console.error("[IWB编辑器] 复制失败:", e);
toast("复制失败:" + (e && e.message || "图片可能跨域"), "error");
}
}
var __stats = () => ({
history: S.history.length,
historyBytes: S.history.reduce((n, s) => n + (s.__bytes || 0), 0),
@@ -7182,9 +7705,44 @@ var __IWB_ANNOTATE_MANIFEST__ = {
opacity: l.opacity == null ? 1 : l.opacity,
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || "1") : null
})),
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color })),
texts: S.textLayers.map((t) => ({ id: t.id, text: t.text })),
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
texts: S.textLayers.map((t) => ({
id: t.id,
text: t.text,
x: t.x,
y: t.y,
fontSize: t.fontSize,
color: t.color,
fontWeight: t.fontWeight,
align: t.align,
lineHeight: t.lineHeight,
strokeWidth: t.strokeWidth,
strokeColor: t.strokeColor,
bgFill: !!t.bgFill,
bgColor: t.bgColor,
// 包围盒:吸附/多行/底色/描边的断言都靠它,和绘制共用同一套度量
box: (() => {
const b = textBounds(t);
return { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h) };
})()
})),
// 吸附参考线(拖动中才有)与最近使用颜色:交互回归用
guides: S.guides ? S.guides.map((g) => ({ axis: g.axis, at: Math.round(g.at * 10) / 10 })) : [],
recentColors: (S.recentColors || []).slice(),
textDefaults: {
weight: S.textWeight,
align: S.textAlign,
lineHeight: S.textLineHeight,
strokeWidth: S.textStrokeWidth,
strokeColor: S.textStrokeColor,
bgFill: S.textBgFill,
bgColor: S.textBgColor
},
selectedShapeId: S.selectedShapeId,
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
drag: S.shapeDrag ? "shape:" + S.shapeDrag.mode + (S.shapeDrag.handle ? ":" + S.shapeDrag.handle : "") : S.textDrag ? "text:" + S.textDrag.mode : S.bitmapDrag ? "bitmap:" + S.bitmapDrag.mode + (S.bitmapDrag.handle ? ":" + S.bitmapDrag.handle : "") : null,
selectedTextId: S.selectedTextId,
penEditId: S.penEditId,
activeLayerId: S.activeLayerId,
@@ -7279,7 +7837,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) {