From d8e4e0cb261f80dbb0a665fda240303856162a08 Mon Sep 17 00:00:00 2001 From: qiqi Date: Wed, 4 Nov 2026 18:30:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(image-annotate):=201.2.0=20=E9=9D=9E?= =?UTF-8?q?=E7=A0=B4=E5=9D=8F=E6=80=A7=E8=A3=81=E5=89=AA=EF=BC=88=E5=8F=AF?= =?UTF-8?q?=E6=92=A4=E9=94=80/=E4=B8=8D=20flatten=EF=BC=89+=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=8F=82=E6=95=B0=E8=A7=A3=E8=80=A6=E4=B8=8E=E5=B0=B1?= =?UTF-8?q?=E5=9C=B0=E9=80=89=E9=A1=B9=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- image-annotate/README.md | 18 +- image-annotate/docs/PS_LITE_ROADMAP.md | 3 +- image-annotate/package.json | 2 +- image-annotate/plugin/editor.css | 17 + image-annotate/plugin/editor/crop.js | 146 +- image-annotate/plugin/editor/events.js | 244 ++- image-annotate/plugin/editor/history.js | 14 +- image-annotate/plugin/editor/index.js | 12 +- image-annotate/plugin/editor/objects.js | 6 +- image-annotate/plugin/editor/state.js | 6 +- image-annotate/plugin/editor/viewport.js | 42 + image-annotate/src/index.js | 2436 ++++++++++++---------- image-annotate/tools/harness.mjs | 65 +- 13 files changed, 1768 insertions(+), 1243 deletions(-) diff --git a/image-annotate/README.md b/image-annotate/README.md index 832da79..42eccbe 100644 --- a/image-annotate/README.md +++ b/image-annotate/README.md @@ -41,7 +41,23 @@ 两者只在电商预设下可见;`≤KB` 也只在该预设下参与降质 —— 切回「原尺寸」会把 `maxKB` 写回 0, 不会因为宿主里残留的 `exportMaxKB` 让限制「复活」或让原尺寸偷偷降质。 - **v1.1.2**:下载后与「还原原图(尺寸复位)」后都会走统一重绘,摘要里的尺寸和「上次输出 …KB」即时更新。 -- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,54 项); +### v1.2:非破坏性裁剪 + 工具参数解耦 + +- **裁剪可撤销**:`confirmCrop()` 不再合成成一张图、也不再把 `S.history` 清零,改为 + ① 先 `saveSnapshot('裁剪')`;② **逐图层**把可见区域搬进新尺寸画布(图层名/透明度/锁定全保留); + ③ `viewport.js#resizeWorkspace()` 只换尺寸不重建图层。撤销时 `restoreState()` 会先把画布尺寸 + 复位到快照里的 `imgW/imgH` 再回填像素,所以 Ctrl+Z / Ctrl+Shift+Z 能来回切。 +- **工具参数解耦**:新增 `S.shapeLineWidth`(矩形/圆形/箭头/钢笔线宽)与 `S.textSize`(文字字号), + 不再借用 `S.brushSize` —— 以前「调细画笔」会顺手改掉所有形状描边、文字大小也跟画笔联动。 +- **就地选项栏**:每个工具在顶栏下方都有自己最常用的 2–4 个参数 + (画笔/橡皮:大小·硬度·透明;矩形/圆形:线宽·描边/实心;箭头/钢笔:线宽;文字:字号; + 框选:形状·羽化;套索:羽化)。控件直接写回 `S`,与右侧参数面板双向同步; + 选中形状/文字时调线宽或字号会同步改选中对象,松手才记一步历史。 +- **打断输入的修复**:`renderAll()` 不再整块重建选项栏(改为 `syncOptionBar()` 只更新值), + 拖滑杆和输数字不会被重绘打断;`isTyping()` 只对文字输入框为真,参数数字框里按 + `Ctrl+A / Ctrl+J / Delete / Esc` 不再被当成「正在打字」吞掉。 + +- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,65 项); `node image-annotate/tools/e2e-site.mjs`(真站 CSP/SRI,发布后)。 ## 入口 diff --git a/image-annotate/docs/PS_LITE_ROADMAP.md b/image-annotate/docs/PS_LITE_ROADMAP.md index 9a1f826..4b8f5b3 100644 --- a/image-annotate/docs/PS_LITE_ROADMAP.md +++ b/image-annotate/docs/PS_LITE_ROADMAP.md @@ -305,7 +305,8 @@ getCompositeCanvas() // 当前这一张 | P0 交互 overlay 分层 | ✅ 新增 `selectionCanvas` / `cursorCanvas`,原 `overlayCanvas` 保留为交互层;三者尺寸与坐标基准由 `viewport.js` 统一同步 | | P0 轻量 UI | ✅ 精简顶栏、就地选项栏、状态栏、侧栏一键收起、更多 ▾、粘贴一步落层;CSS 以末尾追加方式覆盖历史魔数定位(未整体重写) | | P1 选区 | ✅ 矩形/椭圆/套索、羽化、反选/全选/取消、蚂蚁线、复制/剪切到新层、Delete(单层)、填充、画笔/橡皮受选区约束;加减选与选区变换留二期 | -| P2 非破坏性裁剪 | ⏳ 未做(仍会 flatten 且清历史);「还原原图」在尺寸变化路径会明确提示不可撤销 | +| P2 非破坏性裁剪 | ✅ v1.2.0:不再 flatten、不再清历史;逐图层搬运 + `resizeWorkspace()` 换尺寸,`restoreState()` 先复位尺寸再回填像素,可 Ctrl+Z / Ctrl+Shift+Z | +| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 | | P3 图层增强 | ⏳ 未做(缩略图 / 混合模式 / 蒙版) | | P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 | | 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 | diff --git a/image-annotate/package.json b/image-annotate/package.json index f7796f7..478e987 100644 --- a/image-annotate/package.json +++ b/image-annotate/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/image-annotate", "private": true, - "version": "1.1.2", + "version": "1.2.0", "description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)", "ibwPlugin": { "id": "image-annotate", diff --git a/image-annotate/plugin/editor.css b/image-annotate/plugin/editor.css index 839cabe..8ca6d7d 100755 --- a/image-annotate/plugin/editor.css +++ b/image-annotate/plugin/editor.css @@ -1485,3 +1485,20 @@ opacity: 0.32; cursor: not-allowed; text-decoration: line-through; } .iwb-editor-export-settings [data-export-key]:disabled:hover { background: #313244; } + +/* 选项栏参数控件(v1.2):滑杆 + 数字框 + 实时读数,一行放得下就该保持一行 */ +.iwb-opt-range { + width: 84px; height: 4px; flex: 0 0 auto; + accent-color: #4488ff; cursor: pointer; +} +.iwb-opt-val { + min-width: 32px; flex: 0 0 auto; color: #e8a735; font-size: 11px; + font-variant-numeric: tabular-nums; text-align: right; +} +.iwb-opt-unit { color: #7f849c; font-size: 11px; flex: 0 0 auto; } +/* 窄屏:参数多到放不下时横向滚动,不换行(换行会把 36px 高的选项栏撑开压画布) */ +.iwb-editor-optionbar-body { overflow-x: auto; scrollbar-width: none; } +.iwb-editor-optionbar-body::-webkit-scrollbar { display: none; } +@media (max-width: 1100px) { + .iwb-opt-range { width: 64px; } +} diff --git a/image-annotate/plugin/editor/crop.js b/image-annotate/plugin/editor/crop.js index 163e136..da2cd42 100644 --- a/image-annotate/plugin/editor/crop.js +++ b/image-annotate/plugin/editor/crop.js @@ -1,14 +1,15 @@ /* crop.js - 裁剪工具 * 节:裁剪、裁剪栏。 - * 遮罩绘制写 S.overlayCanvas,确认裁剪后重绘位图图层。 + * 遮罩绘制写 S.overlayCanvas;确认裁剪后逐图层搬运像素(v1.2 起不再 flatten)。 */ 'use strict' import { S, runtime } from './state.js' -import { getCompositeCanvas } from './tools.js' -import { setupCanvas } from './viewport.js' +import { resizeWorkspace } from './viewport.js' import { disposeSelection } from './selection.js' +import { saveSnapshot } from './history.js' +import { toast } from './commands.js' // ============ 裁剪 ============ @@ -235,59 +236,80 @@ import { disposeSelection } from './selection.js' S.cropRect = { x: nx, y: ny, w: nw, h: nh } } + /** + * 确认裁剪(v1.2 起非破坏性:可撤销、不 flatten)。 + * + * 旧实现把可见图层合成成一张图再 setupCanvas,等于:① 所有图层被合并成一张; + * ② S.history 直接清零 —— 裁错了没有任何退路。现在改为: + * ① 先 saveSnapshot('裁剪'),快照记的是「裁剪前」的尺寸 + 每层像素; + * ② 逐图层把可见区域搬进新尺寸的 canvas(图层结构、命名、透明度、锁定全保留); + * ③ resizeWorkspace 只换尺寸不重建图层,像素随后写回。 + * 撤销时 restoreState 会先把画布尺寸复位到快照里的 imgW/imgH,再回填像素。 + */ export function confirmCrop() { if (!S.cropRect) return const { x, y, w, h } = S.cropRect if (w < 2 || h < 2) { cancelCrop(); return } - // 画布尺寸即将变化:旧坐标系下的选区/拉框/蚂蚁线/浮动条全部失效, - // 必须按 disposeSelection 级别清理,否则之后 Delete 会按旧 bbox - // 在新画布上开超大掩膜,把当前层整层擦掉。 - disposeSelection() - // 合成所有可见图层 - const tmp = getCompositeCanvas() - const sx = Math.round(x), sy = Math.round(y) - const sw = Math.round(w), sh = Math.round(h) - const cropC = document.createElement('canvas') + const c = S.cropConstraint - - // 计算实际在原图范围内的源区域(裁剪框可超出原图边界,超出部分为透明) - const srcX = Math.max(0, sx) - const srcY = Math.max(0, sy) - const srcRight = Math.min(S.imgW, sx + sw) - const srcBottom = Math.min(S.imgH, sy + sh) - const srcW = Math.max(0, srcRight - srcX) - const srcH = Math.max(0, srcBottom - srcY) - // 在裁剪画布中的偏移 - const dstX = srcX - sx - const dstY = srcY - sy - - if (c.type === 'size' && c.sizeW > 0 && c.sizeH > 0) { - // 尺寸约束:先画到 sw×sh 画布再缩放到目标尺寸 - cropC.width = c.sizeW - cropC.height = c.sizeH - const cctx = cropC.getContext('2d') - const scaleX = c.sizeW / sw - const scaleY = c.sizeH / sh - if (srcW > 0 && srcH > 0) { - cctx.drawImage(tmp, srcX, srcY, srcW, srcH, - dstX * scaleX, dstY * scaleY, srcW * scaleX, srcH * scaleY) - } - S.imgW = c.sizeW - S.imgH = c.sizeH - } else { - cropC.width = sw - cropC.height = sh - const cctx = cropC.getContext('2d') - if (srcW > 0 && srcH > 0) { - cctx.drawImage(tmp, srcX, srcY, srcW, srcH, dstX, dstY, srcW, srcH) - } - S.imgW = sw - S.imgH = sh - } - // 文字/形状图层坐标随裁剪区域变换 + const sx = Math.round(x), sy = Math.round(y) + const sw = Math.max(1, Math.round(w)), sh = Math.max(1, Math.round(h)) const isSize = c.type === 'size' && c.sizeW > 0 && c.sizeH > 0 - const scaleX = isSize ? c.sizeW / sw : 1 - const scaleY = isSize ? c.sizeH / sh : 1 + const nw = isSize ? Math.max(1, Math.round(c.sizeW)) : sw + const nh = isSize ? Math.max(1, Math.round(c.sizeH)) : sh + // 完全没变就别记一步空历史 + if (nw === S.imgW && nh === S.imgH && sx === 0 && sy === 0) { cancelCrop(); return } + + const oldW = S.imgW, oldH = S.imgH + const scaleX = nw / sw, scaleY = nh / sh + // 裁剪框可以超出画面:源矩形先夹到画面内,目标矩形按同一比例落位(超出部分为透明) + const srcX = Math.max(0, sx), srcY = Math.max(0, sy) + const srcW = Math.max(0, Math.min(oldW, sx + sw) - srcX) + const srcH = Math.max(0, Math.min(oldH, sy + sh) - srcY) + const dstX = (srcX - sx) * scaleX, dstY = (srcY - sy) * scaleY + const dstW = srcW * scaleX, dstH = srcH * scaleY + + // ① 进历史:快照记「裁剪前」的尺寸与每层像素 + saveSnapshot('裁剪') + // ② 旧坐标系下的选区/拉框/蚂蚁线/浮动条全部失效 + disposeSelection() + + // ③ 逐图层把可见区域搬出来(保留图层结构,不再合成成一张) + const staged = S.layers.map(layer => { + const tmp = document.createElement('canvas') + tmp.width = nw + tmp.height = nh + if (srcW > 0 && srcH > 0) { + try { + tmp.getContext('2d').drawImage(layer.canvas, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH) + } catch (e) { /* 单层搬运失败不阻断其余 */ } + } + return tmp + }) + + // ④ 换尺寸(会清空图层像素)后把搬出来的内容写回 + resizeWorkspace(nw, nh) + S.layers.forEach((layer, i) => { + const tmp = staged[i] + try { layer.ctx.drawImage(tmp, 0, 0) } catch (e) { /* ignore */ } + tmp.width = 0 + tmp.height = 0 + // 像素已落在新坐标系的正确位置,几何元数据不能再参与二次定位; + // 图片源(image / sourceCanvas)尺寸是旧的,留着会让重绘错位,必须摘掉。 + // 摘掉后这些层按「像素层」参与快照与恢复(见 vendor/layer-logic.js)。 + layer.x = 0 + layer.y = 0 + layer.w = nw + layer.h = nh + layer.rotation = 0 + layer.transformable = false + layer.image = null + layer.sourceCanvas = null + layer._srcBox = null + layer._bounds = undefined + }) + + // ⑤ 文字/形状按裁剪区域位移与缩放 S.textLayers = S.textLayers.map(t => ({ ...t, x: (t.x - sx) * scaleX, @@ -295,31 +317,29 @@ import { disposeSelection } from './selection.js' fontSize: t.fontSize * scaleX })) S.shapeLayers = S.shapeLayers.map(s => ({ - ...s, - ...(s.type === 'pen' ? { pts: (s.pts || []).map(p => ({ x: (p.x - sx) * scaleX, y: (p.y - sy) * scaleY })) } : { - x1: (s.x1 - sx) * scaleX, y1: (s.y1 - sy) * scaleY, - x2: (s.x2 - sx) * scaleX, y2: (s.y2 - sy) * scaleY - }), - lw: Math.max(1, s.lw * (scaleX + scaleY) / 2) - })) + ...s, + ...(s.type === 'pen' ? { pts: (s.pts || []).map(p => ({ x: (p.x - sx) * scaleX, y: (p.y - sy) * scaleY })) } : { + x1: (s.x1 - sx) * scaleX, y1: (s.y1 - sy) * scaleY, + x2: (s.x2 - sx) * scaleX, y2: (s.y2 - sy) * scaleY + }), + lw: Math.max(1, s.lw * (scaleX + scaleY) / 2) + })) + S.selectedTextId = null S.textDrag = null S.selectedShapeId = null S.shapeDrag = null - // 裁剪后 setupCanvas 会重建全部位图图层,旧 selectedLayerId 会指向已删除的 id + // 裁剪后图层 id 不变但几何全变,旧的选中 id 与拖拽中间态都要清 S.selectedLayerId = null S.bitmapDrag = null S.zoom = 1 - setupCanvas(cropC) - S.history = [] - S.redoStack = [] S.cropRect = null + S.cropHandle = null S.cropMoving = false S.moveStart = null - clearOverlay() updateCropInfo() - // 尺寸/坐标系已变,统一重绘出口要在新画布上重建选区层与浮动条位置 if (S.renderAll) S.renderAll() + toast('已裁剪为 ' + nw + '×' + nh + '(Ctrl+Z 可撤销)', 'success') } export function cancelCrop() { diff --git a/image-annotate/plugin/editor/events.js b/image-annotate/plugin/editor/events.js index e5d93b0..8846188 100644 --- a/image-annotate/plugin/editor/events.js +++ b/image-annotate/plugin/editor/events.js @@ -231,14 +231,14 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' if (!S.penPath) S.penPath = { pts: [], preview: null, closed: false } const point = { x: clamp(pos.x, 0, S.imgW), y: clamp(pos.y, 0, S.imgH) } const first = S.penPath.pts[0] - if (first && S.penPath.pts.length >= 3 && Math.hypot(point.x - first.x, point.y - first.y) <= Math.max(12 / S.zoom, S.brushSize * 1.5)) { + if (first && S.penPath.pts.length >= 3 && Math.hypot(point.x - first.x, point.y - first.y) <= Math.max(12 / S.zoom, S.shapeLineWidth * 1.5)) { S.penPath.closed = true S.penPath.nearStart = true S.penPath.preview = null commitPenPath() } else { S.penPath.pts.push(point) - renderObjects({ id: 'pen-preview', type: 'pen', pts: S.penPath.pts.concat(S.penPath.preview ? [S.penPath.preview] : []), closed: false, color: S.color, lw: Math.max(2, S.brushSize), fill: false, opacity: 1, visible: true }) + renderObjects({ id: 'pen-preview', type: 'pen', pts: S.penPath.pts.concat(S.penPath.preview ? [S.penPath.preview] : []), closed: false, color: S.color, lw: Math.max(1, S.shapeLineWidth), fill: false, opacity: 1, visible: true }) } return } @@ -423,7 +423,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' /** 钢笔路径预览:更新悬停点与起点闭合提示 */ function onPenDrawMove(pos) { if (S.penPath) { S.penPath.preview = pos; const first = S.penPath.pts[0] - const nearStart = first && S.penPath.pts.length >= 3 && Math.hypot(pos.x - first.x, pos.y - first.y) <= Math.max(12 / S.zoom, S.brushSize * 1.5) + const nearStart = first && S.penPath.pts.length >= 3 && Math.hypot(pos.x - first.x, pos.y - first.y) <= Math.max(12 / S.zoom, S.shapeLineWidth * 1.5) S.penPath.nearStart = !!nearStart renderObjects() } } @@ -436,8 +436,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' x1: S.startX, y1: S.startY, x2: pos.x, y2: pos.y, color: S.color, - lw: Math.max(2, S.brushSize), - lineWidth: Math.max(2, S.brushSize), + lw: Math.max(1, S.shapeLineWidth), + lineWidth: Math.max(1, S.shapeLineWidth), fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false, opacity: 1, visible: true @@ -635,7 +635,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' x1: S.startX, y1: S.startY, x2: pos.x, y2: pos.y, color: S.color, - lw: Math.max(2, S.brushSize), + lw: Math.max(1, S.shapeLineWidth), fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false, opacity: 1, visible: true, @@ -799,32 +799,101 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' picker: '吸管', hand: '抓手', crop: '裁剪' } - /** 选项栏只露当前工具 2–3 个参数;用独立控件,避免与右侧旧参数区抢 querySelector */ - export function renderOptionBar() { - const body = runtime.el && runtime.el.querySelector('.iwb-editor-optionbar-body') - if (!body) return - let html = '' - if (S.tool === 'marquee') { - html = `形状 + const OPT_HINTS = { + crop: '裁剪栏在画布下方;裁剪与选区互斥,确认后可 Ctrl+Z 撤销', + select: '点击选中元素,拖拽移动,手柄缩放', + picker: '点击画布取色,取完自动切回上一个工具', + hand: '拖拽平移画布;任意工具下按住空格也可以', + marquee: '拖出选区 → 操作条就在选区旁边', + lasso: '按住拖动画圈,松手闭合' + } + + /** 滑杆 + 数字框共用同一 data-opt,两条输入路径都写回 S */ + function rangeOpt(key, label, min, max, value, unit) { + return `${label} + + ${unit ? `${unit}` : ''}` + } + + /** 每个工具只露最常用的 2–4 个参数,全部直接写回 S(右侧参数面板同步) */ + function optionBarHTML(tool) { + if (tool === 'brush' || tool === 'eraser') { + return rangeOpt('brushSize', '大小', 1, 300, S.brushSize, '') + + `硬度 + + ${S.brushHardness} + 透明 + + ${Math.round(S.brushOpacity * 100)}%` + } + if (tool === 'rect' || tool === 'circle') { + return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '') + + `样式 + + ` + } + if (tool === 'arrow' || tool === 'pen') { + return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '') + + `${tool === 'pen' ? '逐点点击,点回起点闭合' : '拖出箭头,松手完成'}` + } + if (tool === 'text') { + return rangeOpt('textSize', '字号', 8, 400, S.textSize, 'px') + + '点画布输入文字,Enter 确认' + } + if (tool === 'marquee') { + return `形状 - 拖出选区 → 操作条就在选区旁边` - } else if (S.tool === 'lasso') { - html = `套索 - - 按住拖动画圈,松手闭合` - } else { - const hints = { - crop: '裁剪栏在画布下方;裁剪与选区互斥', - brush: '选区激活时笔刷只画在选区内', - eraser: '橡皮只擦当前画笔目标图层(✎)', - select: '点击选中元素,拖拽移动,手柄缩放' - } - html = `当前工具:${TOOL_NAMES[S.tool] || S.tool} - ${hints[S.tool] || '选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层'}` + ${OPT_HINTS.marquee}` } - body.innerHTML = html + if (tool === 'lasso') { + return `羽化 px + ${OPT_HINTS.lasso}` + } + return `当前工具:${TOOL_NAMES[tool] || tool} + ${OPT_HINTS[tool] || '选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层'}` + } + + export function renderOptionBar(force) { + const body = runtime.el && runtime.el.querySelector('.iwb-editor-optionbar-body') + if (!body) return + // 工具没变就只同步数值:renderAll 每次操作都会走到这里,全量重建 innerHTML + // 会打断正在拖的滑杆和正在输入的数字框(静态审查 P2-11)。 + if (!force && body.dataset.tool === S.tool) { syncOptionBar(); return } + body.dataset.tool = S.tool + body.innerHTML = optionBarHTML(S.tool) + syncOptionBar() + } + + /** 只更新值与选中态,不重建 DOM —— 保证拖拽中的控件与输入焦点不被抢 */ + export function syncOptionBar() { + const body = runtime.el && runtime.el.querySelector('.iwb-editor-optionbar-body') + if (!body) return + const val = (key) => { + if (key === 'brushSize') return S.brushSize + if (key === 'brushHardness') return S.brushHardness + if (key === 'brushOpacity') return Math.round(S.brushOpacity * 100) + if (key === 'shapeLineWidth') return S.shapeLineWidth + if (key === 'textSize') return S.textSize + if (key === 'feather') return S.selectionFeather + return '' + } + body.querySelectorAll('input[data-opt]').forEach(el => { + if (document.activeElement === el) return // 正在拖/正在输入的不要被覆盖 + const v = val(el.dataset.opt) + if (String(el.value) !== String(v)) el.value = v + }) + body.querySelectorAll('[data-opt-val]').forEach(el => { + const v = val(el.dataset.optVal) + el.textContent = el.dataset.optVal === 'brushOpacity' ? v + '%' : v + }) + body.querySelectorAll('[data-opt="shape"]').forEach(btn => { + btn.classList.toggle('active', S.selectionKind === btn.dataset.value) + }) + body.querySelectorAll('[data-opt-toggle]').forEach(btn => { + btn.classList.toggle('active', !!S.rectFill === (btn.dataset.value === 'fill')) + }) } /** 状态栏:缩放 / 尺寸 / 光标 / 选区 / 当前层 / 工具 */ @@ -847,6 +916,74 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' put('.iwb-editor-status-tool', TOOL_NAMES[S.tool] || S.tool) } + // ---- 选项栏参数写回:单一真源是 S,右侧参数面板与画布随后同步 ---- + + let lwSnapDone = false + let textSnapDone = false + + /** 线宽也作用到当前选中的形状:拖动中只重绘,松手才记一步历史 */ + function applyShapeLineWidth(committed) { + const sh = getSelectedShape() + if (!sh || sh.locked) { lwSnapDone = false; return } + if (committed || !lwSnapDone) { saveSnapshot('线宽'); lwSnapDone = true } + sh.lw = S.shapeLineWidth + renderObjects() + if (committed) lwSnapDone = false + } + + /** 字号也作用到当前选中的文字 */ + function applyTextSize(committed) { + const t = getSelectedText() + if (!t || t.locked) { textSnapDone = false; return } + if (committed || !textSnapDone) { saveSnapshot('字号'); textSnapDone = true } + t.fontSize = S.textSize + renderObjects() + if (committed) textSnapDone = false + } + + /** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个 */ + function setShapeFill(fill) { + S.rectFill = !!fill + updateFillUI() + syncOptionBar() + const sh = getSelectedShape() + if (sh && (sh.type === 'rect' || sh.type === 'circle') && !sh.locked) { + saveSnapshot('填充') + sh.fill = S.rectFill + renderObjects() + } + } + + function setOptionFromControl(el, committed) { + const key = el && el.dataset ? el.dataset.opt : '' + if (!key) return + const n = Math.round(Number(el.value)) + const safe = Number.isFinite(n) ? n : 0 + if (key === 'brushSize') { + S.brushSize = clamp(safe || 1, 1, 300) + updateBrushUI() + updateBrushParamUI() + } else if (key === 'brushHardness') { + S.brushHardness = clamp(safe, 0, 100) + updateBrushParamUI() + } else if (key === 'brushOpacity') { + S.brushOpacity = clamp(safe || 100, 5, 100) / 100 + updateBrushParamUI() + if (S.strokeCanvas) S.strokeCanvas.style.opacity = S.brushOpacity + } else if (key === 'shapeLineWidth') { + S.shapeLineWidth = clamp(safe || 1, 1, 60) + applyShapeLineWidth(committed) + } else if (key === 'textSize') { + S.textSize = clamp(safe || 32, 8, 400) + applyTextSize(committed) + } else if (key === 'feather') { + S.selectionFeather = clamp(safe, 0, 20) + if (S.selection && S.selection.active) S.selection.feather = S.selectionFeather + updateStatusbar() + } + syncOptionBar() + } + /** 更多菜单 / 面板收起 / 选项栏控件:只绑定一次,DOM 重绘不丢事件(委托) */ export function bindLiteUI() { const root = runtime.el @@ -907,23 +1044,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' const body = root.querySelector('.iwb-editor-optionbar-body') if (body) { body.addEventListener('mousedown', (e) => e.stopPropagation()) + // 滑杆拖动中(input)与松手/失焦(change)走同一条写回路径, + // committed 只决定「要不要顺手记一步历史」,不影响参数生效。 + body.addEventListener('input', (e) => setOptionFromControl(e.target, false)) + body.addEventListener('change', (e) => setOptionFromControl(e.target, true)) body.addEventListener('click', (e) => { - const btn = e.target.closest('[data-opt="shape"]') - if (!btn) return - e.stopPropagation() - S.selectionKind = btn.dataset.value === 'ellipse' ? 'ellipse' : 'rect' - renderOptionBar() - toast('选区形状:' + (S.selectionKind === 'ellipse' ? '椭圆' : '矩形'), 'info') + const shapeBtn = e.target.closest('[data-opt="shape"]') + if (shapeBtn) { + e.stopPropagation() + S.selectionKind = shapeBtn.dataset.value === 'ellipse' ? 'ellipse' : 'rect' + syncOptionBar() + toast('选区形状:' + (S.selectionKind === 'ellipse' ? '椭圆' : '矩形'), 'info') + return + } + const toggle = e.target.closest('[data-opt-toggle]') + if (toggle) { + e.stopPropagation() + setShapeFill(toggle.dataset.value === 'fill') + } }) - const onFeather = (e) => { - const input = e.target.closest('[data-opt="feather"]') - if (!input) return - S.selectionFeather = clamp(parseInt(input.value, 10) || 0, 0, 20) - if (S.selection && S.selection.active) S.selection.feather = S.selectionFeather - updateStatusbar() - } - body.addEventListener('input', onFeather) - body.addEventListener('change', onFeather) } // 点画布 / 面板其它地方收起下拉。必须用捕获阶段:modal 自身有个 @@ -1277,7 +1416,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' function commitPenPath() { if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return } saveSnapshot() - const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, lw: Math.max(2, S.brushSize), fill: !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter } + const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter } S.shapeLayers.push(shape); selectUnit('shape', shape.id); S.penPath = null; renderObjects(); renderLayerPanel() } @@ -1452,9 +1591,24 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' S.drawCanvasCursor('crosshair') } + /** + * 是否处于「正在输入文字」态 —— 只对**文字内容**输入框为真。 + * + * v1.2 修正:原来任何 INPUT 都算打字,于是在选项栏的数字框(羽化/线宽/字号) + * 里输完值后,Ctrl+A、Ctrl+J、Delete、Esc 全被吞掉,表现成「快捷键突然没反应」。 + * 参数控件里带修饰键的组合、Delete 与 Esc 一律放行给画布;单个字符仍然正常输入。 + */ function isTyping(e) { const t = e.target - return t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA') + if (!t) return false + if (t.tagName === 'TEXTAREA') return true + if (t.tagName !== 'INPUT') return false + const cls = t.classList + if (cls && (cls.contains('iwb-editor-text-input') || cls.contains('iwb-editor-color-hex-input'))) return true + // 以下是参数控件(数字框 / 滑杆) + if (e.ctrlKey || e.metaKey || e.altKey) return false + if (e.key === 'Delete' || e.key === 'Escape') return false + return true } function onKeydown(e) { diff --git a/image-annotate/plugin/editor/history.js b/image-annotate/plugin/editor/history.js index 7c8af85..2bb8cc6 100644 --- a/image-annotate/plugin/editor/history.js +++ b/image-annotate/plugin/editor/history.js @@ -17,7 +17,7 @@ import { createLayerCanvas, purgeVectorCanvases, redrawBitmapLayer, renderLayerPanel, reorderLayerCanvas, updateLayerCanvasStyles } from './layers.js' -import { setupCanvas } from './viewport.js' +import { resizeWorkspace, setupCanvas } from './viewport.js' import { updateAllUI } from './events.js' import { isDrawableLayer, needsPixelSnapshot, restorePath } from '../vendor/layer-logic.js' import { toast } from './commands.js' @@ -160,6 +160,18 @@ import { toast } from './commands.js' /** 恢复到指定状态(含图层增删) */ function restoreState(state) { + // v1.2:裁剪也进历史链,所以快照的画布尺寸可能与当前不同,必须先把尺寸复位。 + // 尺寸一变,现有图层对象的像素缓冲已被 resizeWorkspace 清空、几何元数据也失效, + // 直接「复用现有图层再 putImageData」会让走过 redraw 路径的图片层彻底丢内容; + // 因此全部释放、让下面的「按快照重建」分支统一重建(它会按 bm 的 imageRef/sourceRef + // 选择 redraw 还是 pixels)。 + if (state.imgW && state.imgH && (state.imgW !== S.imgW || state.imgH !== S.imgH)) { + purgeVectorCanvases() + for (const l of S.layers) releaseLayer(l) + S.layers = [] + resizeWorkspace(state.imgW, state.imgH) + } + purgeVectorCanvases() for (const l of S.layers) l._bounds = undefined diff --git a/image-annotate/plugin/editor/index.js b/image-annotate/plugin/editor/index.js index 3ee974c..e540283 100644 --- a/image-annotate/plugin/editor/index.js +++ b/image-annotate/plugin/editor/index.js @@ -95,6 +95,8 @@ import { toast } from './commands.js' S.prevTool = null S.pickerComposite = null S.rectFill = false + S.shapeLineWidth = 3 + S.textSize = 32 S.cropConstraint = { type: 'free', ratio: 0, sizeW: 0, sizeH: 0 } S.textLayers = [] S.selectedTextId = null @@ -284,12 +286,20 @@ import { toast } from './commands.js' tool: S.tool, doc: { w: S.imgW, h: S.imgH }, layers: S.layers.map(l => ({ id: l.id, name: l.name, z: l.z, locked: !!l.locked, visible: l.visible !== false })), - shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type })), + shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill })), texts: S.textLayers.map(t => ({ id: t.id, text: t.text })), selectedShapeId: S.selectedShapeId, selectedTextId: S.selectedTextId, activeLayerId: S.activeLayerId, selection: selectionInfo(), + toolOptions: { + brushSize: S.brushSize, + brushHardness: S.brushHardness, + brushOpacity: S.brushOpacity, + shapeLineWidth: S.shapeLineWidth, + textSize: S.textSize, + rectFill: S.rectFill + }, history: S.history.length, historyLabels: S.history.map(s => s.__label || ''), redo: S.redoStack.length, diff --git a/image-annotate/plugin/editor/objects.js b/image-annotate/plugin/editor/objects.js index 364c650..b9f5ce7 100644 --- a/image-annotate/plugin/editor/objects.js +++ b/image-annotate/plugin/editor/objects.js @@ -343,12 +343,12 @@ import { isDrawableLayer } from '../vendor/layer-logic.js' const ctx = S.overlayCtx const pts = path.pts.slice() const first = pts[0] - const nearStart = path.preview && pts.length >= 3 && Math.hypot(path.preview.x - first.x, path.preview.y - first.y) <= Math.max(12 / S.zoom, S.brushSize * 1.5) + const nearStart = path.preview && pts.length >= 3 && Math.hypot(path.preview.x - first.x, path.preview.y - first.y) <= Math.max(12 / S.zoom, S.shapeLineWidth * 1.5) if (path.preview) pts.push(nearStart ? first : path.preview) ctx.save() ctx.strokeStyle = S.color ctx.fillStyle = nearStart ? 'rgba(232, 167, 53, 0.18)' : 'transparent' - ctx.lineWidth = Math.max(2, S.brushSize) / S.zoom + ctx.lineWidth = Math.max(1, S.shapeLineWidth) / S.zoom ctx.setLineDash([8 / S.zoom, 5 / S.zoom]) ctx.beginPath() ctx.moveTo(pts[0].x, pts[0].y) @@ -604,7 +604,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js' id: 't' + Date.now() + Math.floor(Math.random() * 1000), x, y, text, color: S.color, - fontSize: Math.max(16, S.brushSize * 6), + fontSize: Math.max(8, S.textSize), opacity: 1, visible: true, locked: false, diff --git a/image-annotate/plugin/editor/state.js b/image-annotate/plugin/editor/state.js index d0c369a..7130814 100644 --- a/image-annotate/plugin/editor/state.js +++ b/image-annotate/plugin/editor/state.js @@ -21,7 +21,11 @@ brushOpacity: 1, // 画笔透明度 0.05~1(一笔整体透明度,笔划内不叠加) prevTool: null, // 吸管工具激活前的工具(取色后切回) pickerComposite: null, // 吸管取样用的合成画布缓存(切工具/画布变化时失效) - rectFill: false, // 矩形是否实心填充 + rectFill: false, // 矩形/圆形是否实心填充 + // v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细, + // 否则「调细画笔」会顺手把所有形状的描边一起改掉。 + shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细 + textSize: 32, // 新建文字的字号 px // 图层系统 layers: [], // 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }] activeLayerId: null, // 当前活跃位图图层 ID(画笔/橡皮操作目标) diff --git a/image-annotate/plugin/editor/viewport.js b/image-annotate/plugin/editor/viewport.js index e0963dc..0ffb4c6 100644 --- a/image-annotate/plugin/editor/viewport.js +++ b/image-annotate/plugin/editor/viewport.js @@ -105,6 +105,48 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun bindCanvasEvents() } + /** + * 只调整画布尺寸与交互层,不重建图层(裁剪 / 撤销裁剪共用)。 + * + * 与 setupCanvas 的分工:setupCanvas 会清空 S.layers 并新建「原图 + 画笔」两层, + * 那是「打开一张新图」的语义。裁剪只是在同一张图上换视窗,像素由调用方先搬好, + * 这里只负责尺寸、交互层、矢量层与视图基准,图层结构原样保留。 + * + * ⚠️ 这里会把每个图层 canvas 的像素缓冲清空(canvas.width 赋值即重置), + * 调用方必须在调用前把像素复制出来,调用后写回。 + */ + export function resizeWorkspace(w, h) { + S.imgW = Math.max(1, Math.round(w)) + S.imgH = Math.max(1, Math.round(h)) + + S.textCanvas.width = S.imgW + S.textCanvas.height = S.imgH + S.strokeCanvas.width = S.imgW + S.strokeCanvas.height = S.imgH + S.overlayPad = Math.max(96, Math.ceil(Math.max(S.imgW, S.imgH) * 0.18)) + for (const [c, cx] of [[S.overlayCanvas, S.overlayCtx], [S.selectionCanvas, S.selectionCtx], [S.cursorCanvas, S.cursorCtx]]) { + if (!c || !cx) continue + c.width = S.imgW + S.overlayPad * 2 + c.height = S.imgH + S.overlayPad * 2 + cx.setTransform(1, 0, 0, 1, S.overlayPad, S.overlayPad) + } + + purgeVectorCanvases() + for (const layer of S.layers) { + layer.canvas.width = S.imgW + layer.canvas.height = S.imgH + layer._bounds = undefined + } + + S.pickerComposite = null + clearOverlay() + computeFit() + S.viewX = null + applyView() + renderObjects() + renderLayerPanel() + } + /** 计算「适应容器」的基准显示尺寸(不限制放大,小图也铺满) */ function computeFit() { const availW = Math.max(50, S.canvasWrap.clientWidth - 48) diff --git a/image-annotate/src/index.js b/image-annotate/src/index.js index 56d9884..04751f8 100644 --- a/image-annotate/src/index.js +++ b/image-annotate/src/index.js @@ -9,7 +9,7 @@ var __IWB_ANNOTATE_MANIFEST__ = { id: 'image-annotate', name: '标注 / 修图', - version: '1.1.2', + version: '1.2.0', apiVersion: 1, capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'], settings: { @@ -42,7 +42,13 @@ var __IWB_ANNOTATE_MANIFEST__ = { pickerComposite: null, // 吸管取样用的合成画布缓存(切工具/画布变化时失效) rectFill: false, - // 矩形是否实心填充 + // 矩形/圆形是否实心填充 + // v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细, + // 否则「调细画笔」会顺手把所有形状的描边一起改掉。 + shapeLineWidth: 3, + // 矩形/圆形/箭头/钢笔的描边粗细 + textSize: 32, + // 新建文字的字号 px // 图层系统 layers: [], // 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }] @@ -397,6 +403,1032 @@ var __IWB_ANNOTATE_MANIFEST__ = { return restorePath(layer) === "pixels"; } + // image-annotate/plugin/vendor/image-math.js + function hexToRgb(hex) { + const h = String(hex || "").replace("#", ""); + const v = h.length === 3 ? h.split("").map((c) => c + c).join("") : h; + return { + r: parseInt(v.slice(0, 2), 16) || 0, + g: parseInt(v.slice(2, 4), 16) || 0, + b: parseInt(v.slice(4, 6), 16) || 0 + }; + } + function rgbToHex(r, g, b) { + const to = (v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0"); + return `#${to(r)}${to(g)}${to(b)}`; + } + function parseRatio(str) { + if (str === "free" || !str) return 0; + const parts = String(str).split(":"); + if (parts.length === 2) { + const w = parseFloat(parts[0]); + const h = parseFloat(parts[1]); + if (w > 0 && h > 0) return w / h; + } + return 0; + } + + // image-annotate/plugin/editor/tools.js + var brushStampCache = { key: "", canvas: null }; + function getBrushStamp(size, color, hardness) { + const key = size + "|" + color + "|" + hardness; + if (brushStampCache.key === key && brushStampCache.canvas) return brushStampCache.canvas; + const c = document.createElement("canvas"); + c.width = size; + c.height = size; + const cx = c.getContext("2d"); + const half = size / 2; + const { r, g, b } = hexToRgb(color); + const grad = cx.createRadialGradient(half, half, half * hardness / 100, half, half, half); + grad.addColorStop(0, `rgba(${r},${g},${b},1)`); + grad.addColorStop(1, `rgba(${r},${g},${b},0)`); + cx.fillStyle = grad; + cx.fillRect(0, 0, size, size); + brushStampCache = { key, canvas: c }; + return c; + } + function strokeSegment(x1, y1, x2, y2) { + const ctx = S.strokeCtx; + const size = Math.max(1, S.brushSize); + const color = S.tool === "eraser" ? "#ffffff" : S.color; + ctx.save(); + if (S.brushHardness >= 100) { + ctx.strokeStyle = color; + ctx.lineWidth = size; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.stroke(); + } else { + const stamp = getBrushStamp(size, color, S.brushHardness); + const dist = Math.hypot(x2 - x1, y2 - y1); + const step = Math.max(1, size / 6); + const n = Math.max(0, Math.ceil(dist / step)); + for (let i = 0; i <= n; i++) { + const t = n === 0 ? 0 : i / n; + ctx.drawImage(stamp, x1 + (x2 - x1) * t - size / 2, y1 + (y2 - y1) * t - size / 2); + } + } + ctx.restore(); + S.strokeCanvas.style.opacity = S.brushOpacity; + } + function eraseSegment(x1, y1, x2, y2) { + const ctx = getActiveCtx(); + if (!ctx) return; + ctx.save(); + if (S.selection && S.selection.active) ctx.clip(S.selection.path, S.selection.fillRule); + ctx.globalCompositeOperation = "destination-out"; + ctx.globalAlpha = S.brushOpacity; + ctx.lineWidth = Math.max(1, S.brushSize); + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.stroke(); + ctx.restore(); + const active = getActiveLayer(); + if (active && active.id === "draw" && active.sourceCanvas) { + const sourceCtx = active.sourceCanvas.getContext("2d", { willReadFrequently: true }); + sourceCtx.save(); + sourceCtx.globalCompositeOperation = "destination-out"; + sourceCtx.globalAlpha = S.brushOpacity; + sourceCtx.lineWidth = Math.max(1, S.brushSize) * active.w / Math.max(S.imgW, 1); + sourceCtx.lineCap = "round"; + sourceCtx.beginPath(); + sourceCtx.moveTo((x1 - active.x) * S.imgW / active.w, (y1 - active.y) * S.imgW / active.w); + sourceCtx.lineTo((x2 - active.x) * S.imgW / active.w, (y2 - active.y) * S.imgW / active.w); + sourceCtx.stroke(); + sourceCtx.restore(); + } + S.pickerComposite = null; + renderObjects(); + } + function bakeDrawableLayer(layer) { + if (!layer || !isDrawableLayer(layer) || !layer._srcBox) return; + layer._srcBox = null; + layer.sourceCanvas = null; + layer.rotation = 0; + layer.x = 0; + layer.y = 0; + layer.w = S.imgW; + layer.h = S.imgH; + layer._bounds = void 0; + } + function beginStroke() { + bakeDrawableLayer(getActiveLayer()); + S.strokeCanvas.width = S.imgW; + S.strokeCanvas.height = S.imgH; + S.strokeCtx.clearRect(0, 0, S.imgW, S.imgH); + S.strokeCanvas.style.display = S.tool === "eraser" ? "none" : "block"; + S.strokeCanvas.style.opacity = S.brushOpacity; + } + function endStroke() { + for (const l of S.layers) l._bounds = void 0; + const ctx = getActiveCtx(); + if (!ctx) return; + ctx.save(); + if (S.selection && S.selection.active) ctx.clip(S.selection.path, S.selection.fillRule); + if (S.tool === "eraser") { + ctx.globalCompositeOperation = "destination-out"; + } + ctx.globalAlpha = S.brushOpacity; + ctx.drawImage(S.strokeCanvas, 0, 0); + ctx.restore(); + S.strokeCanvas.style.display = "none"; + const active = getActiveLayer(); + if (active && active.id === "draw" && active.sourceCanvas && active.w > 0 && active.h > 0) { + const sourceCtx = active.sourceCanvas.getContext("2d", { willReadFrequently: true }); + sourceCtx.save(); + sourceCtx.globalCompositeOperation = S.tool === "eraser" ? "destination-out" : "source-over"; + sourceCtx.globalAlpha = S.brushOpacity; + sourceCtx.translate(-active.x * S.imgW / active.w, -active.y * S.imgH / active.h); + sourceCtx.scale(S.imgW / active.w, S.imgH / active.h); + sourceCtx.drawImage(S.strokeCanvas, 0, 0); + sourceCtx.restore(); + } + S.strokeCtx.clearRect(0, 0, S.imgW, S.imgH); + S.pickerComposite = null; + } + function drawShape(ctx, s) { + ctx.save(); + ctx.globalAlpha = s.opacity != null ? s.opacity : 1; + const rot = s.rotation || 0; + if (rot) { + const b = shapeBounds(s); + 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.strokeStyle = s.color; + ctx.lineWidth = s.lw; + ctx.lineCap = "round"; + ctx.lineJoin = "round"; + if (s.type === "pen") { + const pts = Array.isArray(s.pts) ? s.pts : []; + if (pts.length > 1) { + ctx.beginPath(); + ctx.moveTo(pts[0].x, pts[0].y); + for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); + if (s.closed) ctx.closePath(); + if (s.closed && s.fill) { + ctx.fillStyle = s.color; + ctx.fill(); + } + ctx.stroke(); + } + } 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); + } + 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); + ctx.beginPath(); + ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2); + if (s.fill) { + ctx.fillStyle = s.color; + ctx.fill(); + } + ctx.stroke(); + } else { + ctx.fillStyle = s.color; + ctx.beginPath(); + ctx.moveTo(s.x1, s.y1); + ctx.lineTo(s.x2, s.y2); + ctx.stroke(); + const angle = Math.atan2(s.y2 - s.y1, s.x2 - s.x1); + const headLen = Math.max(12, s.lw * 4); + ctx.beginPath(); + ctx.moveTo(s.x2, s.y2); + ctx.lineTo(s.x2 - headLen * Math.cos(angle - Math.PI / 6), s.y2 - headLen * Math.sin(angle - Math.PI / 6)); + ctx.moveTo(s.x2, s.y2); + ctx.lineTo(s.x2 - headLen * Math.cos(angle + Math.PI / 6), s.y2 - headLen * Math.sin(angle + Math.PI / 6)); + ctx.stroke(); + } + ctx.restore(); + } + function getToolBrushRadius() { + return Math.max(1, S.brushSize) / 2; + } + function screenScale() { + const rect = S.canvasStack.getBoundingClientRect(); + return rect.width ? rect.width / S.imgW : S.zoom; + } + function clearToolRing() { + const ctx = S.cursorCtx; + if (!ctx) return; + const pad = S.overlayPad || 0; + ctx.save(); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.clearRect(0, 0, S.imgW + pad * 2, S.imgH + pad * 2); + ctx.restore(); + ctx.setTransform(1, 0, 0, 1, pad, pad); + } + function drawToolRing(pos) { + clearToolRing(); + const ctx = S.cursorCtx || S.overlayCtx; + const r = getToolBrushRadius(); + const k = 1 / screenScale(); + const rMin = 2 * k; + const rr = Math.max(r, rMin); + ctx.save(); + ctx.lineWidth = k; + ctx.strokeStyle = "rgba(0,0,0,0.8)"; + ctx.beginPath(); + ctx.arc(pos.x, pos.y, rr, 0, Math.PI * 2); + ctx.stroke(); + ctx.strokeStyle = "rgba(255,255,255,0.9)"; + ctx.lineWidth = k; + ctx.beginPath(); + ctx.arc(pos.x, pos.y, Math.max(rr - k, 0), 0, Math.PI * 2); + ctx.stroke(); + ctx.restore(); + } + function getCompositeCanvas() { + const c = document.createElement("canvas"); + c.width = S.imgW; + c.height = S.imgH; + const cx = c.getContext("2d", { willReadFrequently: true }); + cx.globalAlpha = 1; + for (const u of layerUnits()) { + if (u.obj.visible === false) continue; + const el = u.kind === "bitmap" ? u.obj.canvas : u.obj._canvas; + if (!el) continue; + cx.globalAlpha = u.obj.opacity == null ? 1 : u.obj.opacity; + cx.drawImage(el, 0, 0); + } + cx.globalAlpha = 1; + return c; + } + function getPickerComposite() { + if (!S.pickerComposite) { + S.pickerComposite = getCompositeCanvas().getContext("2d", { willReadFrequently: true }); + } + return S.pickerComposite; + } + function sampleColor(pos) { + const x = clamp(Math.floor(pos.x), 0, Math.max(0, S.imgW - 1)); + const y = clamp(Math.floor(pos.y), 0, Math.max(0, S.imgH - 1)); + try { + const d = getPickerComposite().getImageData(x, y, 1, 1).data; + return { r: d[0], g: d[1], b: d[2], a: d[3] }; + } catch (e) { + return null; + } + } + function showPickerTip(e, s) { + const tip = runtime.el.querySelector(".iwb-editor-picker-tip"); + if (!tip) return; + const chip = tip.querySelector(".iwb-editor-picker-chip"); + const hex = tip.querySelector(".iwb-editor-picker-hex"); + if (s && s.a > 0) { + const h = rgbToHex(s.r, s.g, s.b); + chip.style.background = h; + chip.style.border = "1px solid rgba(255,255,255,0.3)"; + hex.textContent = h; + } else { + chip.style.background = "transparent"; + chip.style.border = "1px dashed rgba(255,255,255,0.4)"; + hex.textContent = "透明"; + } + tip.style.display = "flex"; + tip.style.left = e.clientX + 16 + "px"; + tip.style.top = e.clientY + 16 + "px"; + } + function hidePickerTip() { + const tip = runtime.el.querySelector(".iwb-editor-picker-tip"); + if (tip) tip.style.display = "none"; + } + function exitPicker() { + S.tool = S.prevTool && S.prevTool !== "picker" ? S.prevTool : "brush"; + S.prevTool = null; + S.pickerComposite = null; + hidePickerTip(); + updateToolUI(); + updateBrushParamUI(); + if (S.tool === "crop") { + showCropBar(); + updateCropInfo(); + } else { + cancelCrop(); + hideCropBar(); + } + renderObjects(); + } + function applyColorChange(color) { + S.color = color; + updateColorUI(); + const t = getSelectedText(); + if (t && !t.locked && t.color !== S.color) { + saveSnapshot(); + t.color = S.color; + renderObjects(); + } + const sh = getSelectedShape(); + if (sh && !sh.locked && S.tool !== "text" && sh.color !== S.color) { + saveSnapshot(); + sh.color = S.color; + renderObjects(); + } + } + function setTool(tool) { + if (S.placingImage) cancelImagePlacement(); + commitTextInput(); + if (tool !== "select" && tool !== "pen") { + S.penEditId = null; + S.penDragPt = -1; + S.penDragPending = null; + } + if (tool === "picker" && S.tool !== "picker") S.prevTool = S.tool; + if (tool !== "pen") S.penPath = null; + if (tool === "crop") { + S.selection = null; + S.marquee = null; + S.lassoPts = null; + } + if (tool !== "marquee" && tool !== "lasso") { + if (S.marquee || S.lassoPts) { + S.isDrawing = false; + S.interaction = "idle"; + } + S.marquee = null; + S.lassoPts = null; + } + S.tool = tool; + if (tool !== "select") S.selectedLayerId = null; + if (tool !== "text" && tool !== "select") S.selectedTextId = null; + if (tool !== "rect" && tool !== "circle" && tool !== "arrow" && tool !== "pen" && tool !== "select") S.selectedShapeId = null; + S.bitmapDrag = null; + S.textDrag = null; + S.shapeDrag = null; + S.pickerComposite = null; + hidePickerTip(); + updateToolUI(); + updateBrushParamUI(); + if (tool === "crop") { + showCropBar(); + updateCropInfo(); + } else { + cancelCrop(); + hideCropBar(); + } + renderObjects(); + renderLayerPanel(); + if (S.renderAll) S.renderAll(); + } + + // 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 }; + } + function getSelectedText() { + return S.textLayers.find((t) => t.id === S.selectedTextId) || null; + } + function hitTextLayer(pos) { + for (let i = S.textLayers.length - 1; i >= 0; i--) { + const t = S.textLayers[i]; + if (t.visible === false) continue; + const b = textBounds(t); + const rot = t.rotation || 0; + const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]; + if (lp[0] >= b.x - 2 && lp[0] <= b.x + b.w + 2 && lp[1] >= b.y - 2 && lp[1] <= b.y + b.h + 2) { + return t; + } + } + return null; + } + function textHandlePoints(t) { + const b = textBounds(t); + const rot = t.rotation || 0; + const cx = b.x + b.w / 2, cy = b.y + b.h / 2; + const local = { nw: [b.x, b.y], ne: [b.x + b.w, b.y], sw: [b.x, b.y + b.h], se: [b.x + b.w, b.y + b.h] }; + const out = {}; + for (const k in local) out[k] = rotPt(local[k][0], local[k][1], cx, cy, rot); + return out; + } + function hitTextHandle(pos) { + const t = getSelectedText(); + if (!t) return null; + const b = textBounds(t); + const rot = t.rotation || 0; + const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]; + if (hitRotationHandle(lp, b)) return "rotate"; + const local = { nw: [b.x, b.y], ne: [b.x + b.w, b.y], sw: [b.x, b.y + b.h], se: [b.x + b.w, b.y + b.h] }; + const R = 12 / S.zoom; + let best = null, bestDist = 1e9; + for (const name in local) { + const dx = lp[0] - local[name][0], dy = lp[1] - local[name][1]; + const d = dx * dx + dy * dy; + if (d < R * R && d < bestDist) { + bestDist = d; + best = name; + } + } + return best; + } + function shapeBounds(s) { + if (s.type === "pen" && s.pts && s.pts.length) { + const xs = s.pts.map((p) => p.x), ys = s.pts.map((p) => p.y), x = Math.min(...xs), y = Math.min(...ys); + return { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y }; + } + return { x: Math.min(s.x1, s.x2), y: Math.min(s.y1, s.y2), w: Math.abs(s.x2 - s.x1), h: Math.abs(s.y2 - s.y1) }; + } + function getSelectedShape() { + return S.shapeLayers.find((s) => s.id === S.selectedShapeId) || null; + } + function distToSeg(px, py, x1, y1, x2, y2) { + const dx = x2 - x1, dy = y2 - y1; + const l2 = dx * dx + dy * dy; + let t = l2 ? ((px - x1) * dx + (py - y1) * dy) / l2 : 0; + t = clamp(t, 0, 1); + return Math.hypot(px - (x1 + t * dx), py - (y1 + t * dy)); + } + function hitShapeObj(pos, s, includeInterior) { + if (s.visible === false) return false; + if (s.rotation) { + const b = shapeBounds(s); + const lp = unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, s.rotation); + pos = { x: lp[0], y: lp[1] }; + } + if (s.type === "pen") { + const pts = s.pts || []; + for (let i = 1; i < pts.length; i++) if (distToSeg(pos.x, pos.y, pts[i - 1].x, pts[i - 1].y, pts[i].x, pts[i].y) <= Math.max(8 / S.zoom, s.lw)) return true; + if (s.closed && pts.length > 2 && distToSeg(pos.x, pos.y, pts[pts.length - 1].x, pts[pts.length - 1].y, pts[0].x, pts[0].y) <= Math.max(8 / S.zoom, s.lw)) return true; + if (!includeInterior) return false; + const b = shapeBounds(s); + return pos.x >= b.x && pos.x <= b.x + b.w && pos.y >= b.y && pos.y <= b.y + b.h; + } + if (s.type === "circle") { + const b = shapeBounds(s); + const cx = b.x + b.w / 2, cy = b.y + b.h / 2; + const rx = Math.max(0.5, b.w / 2), ry = Math.max(0.5, b.h / 2); + const nx = (pos.x - cx) / rx, ny = (pos.y - cy) / ry; + const value = nx * nx + ny * ny; + if (includeInterior || s.fill) return value <= 1; + const edgeTolerance = Math.max(4 / S.zoom, s.lw / Math.min(rx, ry)); + const outer = (1 + edgeTolerance) * (1 + edgeTolerance); + const inner = Math.max(0, 1 - edgeTolerance) * Math.max(0, 1 - edgeTolerance); + return value >= inner && value <= outer; + } + if (s.type === "rect") { + const b = shapeBounds(s); + const pad = Math.max(4, s.lw * 1.5); + const inOuter = pos.x >= b.x - pad && pos.x <= b.x + b.w + pad && pos.y >= b.y - pad && pos.y <= b.y + b.h + pad; + if (!inOuter) return false; + if (includeInterior || s.fill) return true; + const inInner = pos.x >= b.x + pad && pos.x <= b.x + b.w - pad && pos.y >= b.y + pad && pos.y <= b.y + b.h - pad; + return !inInner; + } + return distToSeg(pos.x, pos.y, s.x1, s.y1, s.x2, s.y2) <= Math.max(8 / S.zoom, s.lw); + } + function hitShapeLayer(pos, includeInterior) { + for (let i = S.shapeLayers.length - 1; i >= 0; i--) { + if (hitShapeObj(pos, S.shapeLayers[i], includeInterior)) return S.shapeLayers[i]; + } + return null; + } + function allObjects() { + const arr = S.textLayers.map((o) => ({ kind: "text", obj: o })).concat(S.shapeLayers.map((o) => ({ kind: "shape", obj: o }))); + arr.sort((a, b) => (a.obj.z || 0) - (b.obj.z || 0)); + return arr; + } + function sortLayersByZ() { + const cmp = (a, b) => (a.z || 0) - (b.z || 0); + S.textLayers.sort(cmp); + S.shapeLayers.sort(cmp); + } + function layerUnits() { + const arr = S.layers.map((obj) => ({ kind: "bitmap", obj })).concat(S.textLayers.map((obj) => ({ kind: "text", obj }))).concat(S.shapeLayers.map((obj) => ({ kind: "shape", obj }))); + arr.sort((a, b) => (a.obj.z || 0) - (b.obj.z || 0)); + return arr; + } + function layerUnitsDesc() { + return layerUnits().reverse(); + } + function assignLayerZ(units) { + units.forEach((u, i) => { + u.obj.z = i; + }); + S.zCounter = Math.max(S.zCounter, units.length - 1); + } + function selectUnit(kind, id) { + S.selectedLayerId = kind === "bitmap" ? id : null; + S.selectedTextId = kind === "text" ? id : null; + S.selectedShapeId = kind === "shape" ? id : null; + S.textDrag = null; + S.shapeDrag = null; + S.bitmapDrag = null; + } + function hitUnit(unit, pos) { + const { kind, obj } = unit; + if (!obj || obj.visible === false) return false; + if (kind === "bitmap") return obj.locked ? false : hitBitmapAt(obj, pos); + if (kind === "text") { + const b = textBounds(obj); + const rot = obj.rotation || 0; + const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]; + return lp[0] >= b.x - 2 && lp[0] <= b.x + b.w + 2 && lp[1] >= b.y - 2 && lp[1] <= b.y + b.h + 2; + } + return hitShapeObj(pos, obj, true); + } + function hitTopmost(pos) { + for (const unit of layerUnitsDesc()) if (hitUnit(unit, pos)) return unit; + return null; + } + function hitAnyObject(pos) { + for (const unit of layerUnitsDesc()) { + if (unit.kind === "bitmap") continue; + if (hitUnit(unit, pos)) return unit; + } + return null; + } + function getSelectedObject() { + const t = getSelectedText(); + if (t) return { kind: "text", obj: t }; + const s = getSelectedShape(); + if (s) return { kind: "shape", obj: s }; + return null; + } + function moveLayer(dir) { + let sel = getSelectedObject(); + if (sel) { + if (sel.obj.locked) return; + } else { + 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; + const units = layerUnits(); + const baseIdx = units.findIndex((u) => u.obj.id === "base"); + if (baseIdx > 0) { + const [b] = units.splice(baseIdx, 1); + units.unshift(b); + } + const from = units.findIndex((u) => u.obj === sel.obj); + if (from < 0) return; + const min = baseIdx >= 0 ? 1 : 0; + let to; + if (dir === "up") to = Math.min(from + 1, units.length - 1); + else if (dir === "down") to = Math.max(from - 1, min); + else if (dir === "top") to = units.length - 1; + else if (dir === "bottom") to = min; + else return; + if (to === from) return; + saveSnapshot(); + const [moved] = units.splice(from, 1); + units.splice(to, 0, moved); + assignLayerZ(units); + sortLayersByZ(); + reorderLayerCanvas(); + renderObjects(); + renderLayerPanel(); + } + function shapeHandlePoints(s) { + const b = shapeBounds(s); + if (s.type === "pen") { + return Object.fromEntries((s.pts || []).map((p, i) => ["p" + i, [p.x, p.y]])); + } + if (s.type === "arrow") { + return { start: [s.x1, s.y1], end: [s.x2, s.y2] }; + } + return { + nw: [b.x, b.y], + ne: [b.x + b.w, b.y], + sw: [b.x, b.y + b.h], + se: [b.x + b.w, b.y + b.h], + n: [b.x + b.w / 2, b.y], + s: [b.x + b.w / 2, b.y + b.h], + e: [b.x + b.w, b.y + b.h / 2], + w: [b.x, b.y + b.h / 2] + }; + } + function shapeHandleWorld(s) { + const b = shapeBounds(s); + const rot = s.rotation || 0; + const cx = b.x + b.w / 2, cy = b.y + b.h / 2; + const local = shapeHandlePoints(s); + const out = {}; + for (const k in local) out[k] = rotPt(local[k][0], local[k][1], cx, cy, rot); + return out; + } + function hitShapeHandle(pos) { + const s = getSelectedShape(); + if (!s) return null; + const b = shapeBounds(s); + const rot = s.rotation || 0; + const cx = b.x + b.w / 2, cy = b.y + b.h / 2; + const lp = rot ? unrotPt(pos.x, pos.y, cx, cy, rot) : [pos.x, pos.y]; + if (hitRotationHandle(lp, b)) return "rotate"; + const pts = shapeHandlePoints(s); + const offset = 8 / S.zoom; + const R = Math.max(18 / S.zoom, 11); + let best = null, bestDist = 1e9; + for (const name in pts) { + const px = pts[name][0] + (name.includes("w") ? -offset : name.includes("e") ? offset : 0); + const py = pts[name][1] + (name.includes("n") ? -offset : name.includes("s") ? offset : 0); + const dx = lp[0] - px, dy = lp[1] - py; + const d = dx * dx + dy * dy; + if (d < R * R && d < bestDist) { + bestDist = d; + best = name; + } + } + return best; + } + function applyShapeHandle(s, handle, pos) { + const b0 = shapeBounds(s); + const rot0 = s.rotation || 0; + const c0x = b0.x + b0.w / 2, c0y = b0.y + b0.h / 2; + if (handle === "rotate") { + const st = S.shapeDrag && S.shapeDrag.start; + const baseRot = S.shapeDrag && S.shapeDrag.shape && (S.shapeDrag.shape.rotation || 0) || 0; + if (st) { + const a0 = Math.atan2(st.y - c0y, st.x - c0x); + const a1 = Math.atan2(pos.y - c0y, pos.x - c0x); + let deg = baseRot + (a1 - a0) * 180 / Math.PI; + if (S._shiftDown) deg = Math.round(deg / 15) * 15; + s.rotation = deg; + } + return; + } + const lp = rot0 ? unrotPt(pos.x, pos.y, c0x, c0y, rot0) : [pos.x, pos.y]; + pos = { x: lp[0], y: lp[1] }; + if (s.type === "pen" && handle && handle[0] === "p") { + const i = parseInt(handle.slice(1), 10); + if (s.pts && s.pts[i]) { + s.pts[i].x = clamp(pos.x, 0, S.imgW); + s.pts[i].y = clamp(pos.y, 0, S.imgH); + } + return; + } + if (s.type === "arrow") { + if (handle === "start") { + s.x1 = clamp(pos.x, 0, S.imgW); + s.y1 = clamp(pos.y, 0, S.imgH); + } else { + s.x2 = clamp(pos.x, 0, S.imgW); + s.y2 = clamp(pos.y, 0, S.imgH); + } + return; + } + const b = shapeBounds(s); + const offset = 8 / S.zoom; + const adjusted = { x: pos.x - (handle.includes("w") ? -offset : handle.includes("e") ? offset : 0), y: pos.y - (handle.includes("n") ? -offset : handle.includes("s") ? offset : 0) }; + let x1 = b.x, y1 = b.y, x2 = b.x + b.w, y2 = b.y + b.h; + if (handle.includes("e")) x2 = Math.max(x1 + 2, adjusted.x); + if (handle.includes("s")) y2 = Math.max(y1 + 2, adjusted.y); + if (handle.includes("w")) x1 = Math.min(x2 - 2, adjusted.x); + if (handle.includes("n")) y1 = Math.min(y2 - 2, adjusted.y); + s.x1 = x1; + s.y1 = y1; + s.x2 = x2; + s.y2 = y2; + } + function drawPenPathPreview() { + const path = S.penPath; + if (!path || !path.pts || !path.pts.length) return; + const ctx = S.overlayCtx; + const pts = path.pts.slice(); + const first = pts[0]; + const nearStart = path.preview && pts.length >= 3 && Math.hypot(path.preview.x - first.x, path.preview.y - first.y) <= Math.max(12 / S.zoom, S.shapeLineWidth * 1.5); + if (path.preview) pts.push(nearStart ? first : path.preview); + ctx.save(); + ctx.strokeStyle = S.color; + ctx.fillStyle = nearStart ? "rgba(232, 167, 53, 0.18)" : "transparent"; + ctx.lineWidth = Math.max(1, S.shapeLineWidth) / S.zoom; + ctx.setLineDash([8 / S.zoom, 5 / S.zoom]); + ctx.beginPath(); + ctx.moveTo(pts[0].x, pts[0].y); + for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); + if (nearStart) { + ctx.closePath(); + ctx.fill(); + } + ctx.stroke(); + ctx.setLineDash([]); + for (let i = 0; i < path.pts.length; i++) { + const point = path.pts[i]; + ctx.beginPath(); + ctx.fillStyle = i === 0 && nearStart ? "#e8a735" : "#ffffff"; + ctx.strokeStyle = S.color; + ctx.arc(point.x, point.y, Math.max(4, 6 / S.zoom), 0, Math.PI * 2); + ctx.fill(); + ctx.stroke(); + } + ctx.restore(); + } + function drawShapeSelection(s) { + const octx = S.overlayCtx; + const b = shapeBounds(s); + const rot = s.rotation || 0; + octx.save(); + octx.strokeStyle = "#e8a735"; + octx.lineWidth = 1.5 / S.zoom; + octx.setLineDash([6 / S.zoom, 3 / S.zoom]); + const corners = boxCorners(b.x, b.y, b.w, b.h, rot); + octx.beginPath(); + octx.moveTo(corners[0][0], corners[0][1]); + for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]); + octx.closePath(); + octx.stroke(); + octx.setLineDash([]); + const hs = 8.5 / S.zoom; + octx.fillStyle = "#ffffff"; + octx.strokeStyle = "#e8a735"; + const pts = shapeHandleWorld(s); + for (const name in pts) { + octx.beginPath(); + octx.rect(pts[name][0] - hs, pts[name][1] - hs, hs * 2, hs * 2); + octx.fill(); + octx.stroke(); + } + octx.restore(); + drawRotationHandles(octx, b, rot); + } + function deleteSelectedShape() { + if (!S.selectedShapeId) return; + const selected = getSelectedShape(); + if (selected && selected.locked) return; + saveSnapshot(); + removeVecCanvas(selected); + S.shapeLayers = S.shapeLayers.filter((s) => s.id !== S.selectedShapeId); + S.selectedShapeId = null; + renderObjects(); + } + function renderObjects(tempShape) { + for (const { kind, obj } of allObjects()) drawVectorToCanvas(kind, obj); + reorderLayerCanvas(); + clearOverlay(); + if (tempShape) drawShape(S.overlayCtx, tempShape); + if (S.tool === "pen" && S.penPath && S.penPath.pts.length) drawPenPathPreview(); + if (S.placingImage) { + drawPlacementPreview(); + return; + } + const bitmapSelection = S.layers.find((l) => l.id === S.selectedLayerId && (l.transformable || isDrawableLayer(l))); + if (bitmapSelection) drawBitmapSelection(bitmapSelection); + const sel = getSelectedText(); + if (sel) { + const b = textBounds(sel); + const rot = sel.rotation || 0; + const octx = S.overlayCtx; + octx.save(); + octx.strokeStyle = "#e8a735"; + octx.lineWidth = 1.5 / S.zoom; + octx.setLineDash([6 / S.zoom, 3 / S.zoom]); + const corners = boxCorners(b.x - 2 / S.zoom, b.y - 2 / S.zoom, b.w + 4 / S.zoom, b.h + 4 / S.zoom, rot); + octx.beginPath(); + octx.moveTo(corners[0][0], corners[0][1]); + for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]); + octx.closePath(); + octx.stroke(); + octx.setLineDash([]); + const hs = 7 / S.zoom; + octx.fillStyle = "#ffffff"; + octx.strokeStyle = "#e8a735"; + const pts = textHandlePoints(sel); + for (const name in pts) { + octx.beginPath(); + octx.rect(pts[name][0] - hs, pts[name][1] - hs, hs * 2, hs * 2); + octx.fill(); + octx.stroke(); + } + octx.restore(); + } else { + const sh = getSelectedShape(); + if (sh) drawShapeSelection(sh); + } + const penShape = getPenEditingShape(); + if (penShape) drawPenEditOverlay(penShape); + if (S.cropRect) drawCropPreview(); + updateLayerUI(); + } + function getPenEditingShape() { + if (!S.penEditId) return null; + return S.shapeLayers.find((sh) => sh.id === S.penEditId && sh.type === "pen") || null; + } + function beginPenEdit(shape) { + S.penEditId = shape.id; + S.selectedShapeId = shape.id; + S.selectedTextId = null; + S.selectedLayerId = null; + S.shapeDrag = null; + S.penDragPt = -1; + S.penDragBase = null; + S.penDragPending = null; + renderObjects(); + renderLayerPanel(); + } + function exitPenEdit() { + S.penEditId = null; + S.penDragPt = -1; + S.penDragBase = null; + S.penDragPending = null; + renderObjects(); + renderLayerPanel(); + } + function hitPenPoint(pos, shape, r) { + const pts = shape.pts || []; + const b = shapeBounds(shape); + const lp = shape.rotation ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, shape.rotation) : [pos.x, pos.y]; + for (let i = 0; i < pts.length; i++) { + if (Math.hypot(lp[0] - pts[i].x, lp[1] - pts[i].y) <= r) return i; + } + return -1; + } + function hitPenEdgeInsert(pos, shape) { + const pts = shape.pts || []; + const b = shapeBounds(shape); + const lp = shape.rotation ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, shape.rotation) : [pos.x, pos.y]; + const r = Math.max(12 / S.zoom, 6); + for (let i = 0; i < pts.length - 1; i++) { + if (distToSeg(lp[0], lp[1], pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y) <= r) return i; + } + if (shape.closed && pts.length >= 3) { + if (distToSeg(lp[0], lp[1], pts[pts.length - 1].x, pts[pts.length - 1].y, pts[0].x, pts[0].y) <= r) return pts.length - 1; + } + return -1; + } + function drawPenEditOverlay(shape) { + const ctx = S.overlayCtx; + const pts = shape.pts || []; + const b = shapeBounds(shape); + const rot = shape.rotation || 0; + const cx = b.x + b.w / 2, cy = b.y + b.h / 2; + const W = (p) => rotPt(p.x, p.y, cx, cy, rot); + const R = Math.max(7 / S.zoom, 5); + ctx.save(); + ctx.lineWidth = 1.5 / S.zoom; + const segments = []; + for (let i = 0; i < pts.length - 1; i++) segments.push([pts[i], pts[i + 1]]); + if (shape.closed && pts.length >= 3) segments.push([pts[pts.length - 1], pts[0]]); + ctx.strokeStyle = "#e8a735"; + for (const [a, bb] of segments) { + const wa = W(a), wb = W(bb); + const mx = (wa[0] + wb[0]) / 2, my = (wa[1] + wb[1]) / 2; + ctx.beginPath(); + ctx.arc(mx, my, Math.max(3 / S.zoom, 2), 0, Math.PI * 2); + ctx.stroke(); + } + for (let i = 0; i < pts.length; i++) { + const wp = W(pts[i]); + ctx.beginPath(); + ctx.rect(wp[0] - R / 2, wp[1] - R / 2, R, R); + ctx.fillStyle = "#ffffff"; + ctx.strokeStyle = i === S.penDragPt ? "#ff8c00" : "#e8a735"; + ctx.fill(); + ctx.stroke(); + } + ctx.restore(); + } + function showTextInput(x, y, layer) { + const input = runtime.el.querySelector(".iwb-editor-text-input"); + const rect = S.canvasStack.getBoundingClientRect(); + const wrapRect = S.canvasWrap.getBoundingClientRect(); + const sx = rect.width / S.imgW; + const sy = rect.height / S.imgH; + input.style.left = rect.left - wrapRect.left + x * sx + "px"; + input.style.top = rect.top - wrapRect.top + y * sy + "px"; + input.style.display = "block"; + if (layer) { + input.value = layer.text; + S.textEditingId = layer.id; + } else { + input.value = ""; + S.textEditingId = null; + } + input.focus(); + input.select(); + input.dataset.x = x; + input.dataset.y = y; + } + function hideTextInput() { + const input = runtime.el.querySelector(".iwb-editor-text-input"); + if (input) { + if (document.activeElement === input) input.blur(); + input.style.display = "none"; + input.value = ""; + } + S.textEditingId = null; + } + function commitTextInput() { + const input = runtime.el.querySelector(".iwb-editor-text-input"); + if (!input || input.style.display === "none") return false; + const text = input.value.trim(); + const x = parseFloat(input.dataset.x); + const y = parseFloat(input.dataset.y); + let committed = false; + if (S.textEditingId) { + const t = S.textLayers.find((l) => l.id === S.textEditingId); + if (t && t.locked) { + hideTextInput(); + return true; + } + if (t && text !== t.text) { + saveSnapshot(); + if (text) { + t.text = text; + } else { + removeVecCanvas(t); + S.textLayers = S.textLayers.filter((l) => l.id !== t.id); + S.selectedTextId = null; + } + renderObjects(); + } + committed = true; + } else if (text) { + saveSnapshot(); + const layer = { + id: "t" + Date.now() + Math.floor(Math.random() * 1e3), + x, + y, + text, + color: S.color, + fontSize: Math.max(8, S.textSize), + opacity: 1, + visible: true, + locked: false, + z: ++S.zCounter + }; + S.textLayers.push(layer); + selectUnit("text", layer.id); + renderObjects(); + committed = true; + } + hideTextInput(); + return committed; + } + function deleteSelectedText() { + if (!S.selectedTextId) return; + const selected = getSelectedText(); + if (selected && selected.locked) return; + saveSnapshot(); + removeVecCanvas(selected); + S.textLayers = S.textLayers.filter((t) => t.id !== S.selectedTextId); + S.selectedTextId = null; + renderObjects(); + } + function beginTextRotate(pos) { + const t = getSelectedText(); + if (!t || t.locked) return; + const b = textBounds(t); + S.textDrag = { + mode: "rotate", + rotation: t.rotation || 0, + cx: b.x + b.w / 2, + cy: b.y + b.h / 2, + startX0: pos.x, + startY0: pos.y, + pending: snapshotState() + }; + } + function beginTextScaleDrag(handle, pos) { + const t = getSelectedText(); + if (!t || t.locked) return; + const b = textBounds(t); + const rot = t.rotation || 0; + const cx = b.x + b.w / 2, cy = b.y + b.h / 2; + const anchors = { + se: [b.x, b.y], + ne: [b.x, b.y + b.h], + sw: [b.x + b.w, b.y], + nw: [b.x + b.w, b.y + b.h] + }; + const a = rotPt(anchors[handle][0], anchors[handle][1], cx, cy, rot); + const anchor = { x: a[0], y: a[1] }; + const dx = pos.x - anchor.x, dy = pos.y - anchor.y; + S.textDrag = { + mode: "scale", + anchor, + d0: Math.sqrt(dx * dx + dy * dy), + fontSize: t.fontSize, + pending: snapshotState() + }; + } + function beginShapeHandleDrag(handle, pos) { + const sh = getSelectedShape(); + if (!sh || sh.locked) return; + S.shapeDrag = { + mode: "handle", + handle, + start: pos, + shape: { ...sh }, + pending: snapshotState() + }; + } + // image-annotate/plugin/editor/layers.js function createLayerCanvas() { const c = document.createElement("canvas"); @@ -1862,31 +2894,6 @@ var __IWB_ANNOTATE_MANIFEST__ = { } } - // image-annotate/plugin/vendor/image-math.js - function hexToRgb(hex) { - const h = String(hex || "").replace("#", ""); - const v = h.length === 3 ? h.split("").map((c) => c + c).join("") : h; - return { - r: parseInt(v.slice(0, 2), 16) || 0, - g: parseInt(v.slice(2, 4), 16) || 0, - b: parseInt(v.slice(4, 6), 16) || 0 - }; - } - function rgbToHex(r, g, b) { - const to = (v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0"); - return `#${to(r)}${to(g)}${to(b)}`; - } - function parseRatio(str) { - if (str === "free" || !str) return 0; - const parts = String(str).split(":"); - if (parts.length === 2) { - const w = parseFloat(parts[0]); - const h = parseFloat(parts[1]); - if (w > 0 && h > 0) return w / h; - } - return 0; - } - // image-annotate/plugin/editor/events.js var MOUSE_DOWN_HANDLERS = { select: onSelectMouseDown, @@ -2095,14 +3102,14 @@ var __IWB_ANNOTATE_MANIFEST__ = { if (!S.penPath) S.penPath = { pts: [], preview: null, closed: false }; const point = { x: clamp(pos.x, 0, S.imgW), y: clamp(pos.y, 0, S.imgH) }; const first = S.penPath.pts[0]; - if (first && S.penPath.pts.length >= 3 && Math.hypot(point.x - first.x, point.y - first.y) <= Math.max(12 / S.zoom, S.brushSize * 1.5)) { + if (first && S.penPath.pts.length >= 3 && Math.hypot(point.x - first.x, point.y - first.y) <= Math.max(12 / S.zoom, S.shapeLineWidth * 1.5)) { S.penPath.closed = true; S.penPath.nearStart = true; S.penPath.preview = null; commitPenPath(); } else { S.penPath.pts.push(point); - renderObjects({ id: "pen-preview", type: "pen", pts: S.penPath.pts.concat(S.penPath.preview ? [S.penPath.preview] : []), closed: false, color: S.color, lw: Math.max(2, S.brushSize), fill: false, opacity: 1, visible: true }); + renderObjects({ id: "pen-preview", type: "pen", pts: S.penPath.pts.concat(S.penPath.preview ? [S.penPath.preview] : []), closed: false, color: S.color, lw: Math.max(1, S.shapeLineWidth), fill: false, opacity: 1, visible: true }); } return; } @@ -2285,7 +3292,7 @@ var __IWB_ANNOTATE_MANIFEST__ = { if (S.penPath) { S.penPath.preview = pos; const first = S.penPath.pts[0]; - const nearStart = first && S.penPath.pts.length >= 3 && Math.hypot(pos.x - first.x, pos.y - first.y) <= Math.max(12 / S.zoom, S.brushSize * 1.5); + const nearStart = first && S.penPath.pts.length >= 3 && Math.hypot(pos.x - first.x, pos.y - first.y) <= Math.max(12 / S.zoom, S.shapeLineWidth * 1.5); S.penPath.nearStart = !!nearStart; renderObjects(); } @@ -2299,8 +3306,8 @@ var __IWB_ANNOTATE_MANIFEST__ = { x2: pos.x, y2: pos.y, color: S.color, - lw: Math.max(2, S.brushSize), - lineWidth: Math.max(2, S.brushSize), + lw: Math.max(1, S.shapeLineWidth), + lineWidth: Math.max(1, S.shapeLineWidth), fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false, opacity: 1, visible: true @@ -2483,7 +3490,7 @@ var __IWB_ANNOTATE_MANIFEST__ = { x2: pos.x, y2: pos.y, color: S.color, - lw: Math.max(2, S.brushSize), + lw: Math.max(1, S.shapeLineWidth), fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false, opacity: 1, visible: true, @@ -2656,31 +3663,91 @@ var __IWB_ANNOTATE_MANIFEST__ = { hand: "抓手", crop: "裁剪" }; - function renderOptionBar() { - const body = runtime.el && runtime.el.querySelector(".iwb-editor-optionbar-body"); - if (!body) return; - let html = ""; - if (S.tool === "marquee") { - html = `形状 + var OPT_HINTS = { + crop: "裁剪栏在画布下方;裁剪与选区互斥,确认后可 Ctrl+Z 撤销", + select: "点击选中元素,拖拽移动,手柄缩放", + picker: "点击画布取色,取完自动切回上一个工具", + hand: "拖拽平移画布;任意工具下按住空格也可以", + marquee: "拖出选区 → 操作条就在选区旁边", + lasso: "按住拖动画圈,松手闭合" + }; + function rangeOpt(key, label, min, max, value, unit) { + return `${label} + + ${unit ? `${unit}` : ""}`; + } + function optionBarHTML(tool) { + if (tool === "brush" || tool === "eraser") { + return rangeOpt("brushSize", "大小", 1, 300, S.brushSize, "") + `硬度 + + ${S.brushHardness} + 透明 + + ${Math.round(S.brushOpacity * 100)}%`; + } + if (tool === "rect" || tool === "circle") { + return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + `样式 + + `; + } + if (tool === "arrow" || tool === "pen") { + return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + `${tool === "pen" ? "逐点点击,点回起点闭合" : "拖出箭头,松手完成"}`; + } + if (tool === "text") { + return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + '点画布输入文字,Enter 确认'; + } + if (tool === "marquee") { + return `形状 - 拖出选区 → 操作条就在选区旁边`; - } else if (S.tool === "lasso") { - html = `套索 - - 按住拖动画圈,松手闭合`; - } else { - const hints = { - crop: "裁剪栏在画布下方;裁剪与选区互斥", - brush: "选区激活时笔刷只画在选区内", - eraser: "橡皮只擦当前画笔目标图层(✎)", - select: "点击选中元素,拖拽移动,手柄缩放" - }; - html = `当前工具:${TOOL_NAMES[S.tool] || S.tool} - ${hints[S.tool] || "选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层"}`; + ${OPT_HINTS.marquee}`; } - body.innerHTML = html; + if (tool === "lasso") { + return `羽化 px + ${OPT_HINTS.lasso}`; + } + return `当前工具:${TOOL_NAMES[tool] || tool} + ${OPT_HINTS[tool] || "选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层"}`; + } + function renderOptionBar(force) { + const body = runtime.el && runtime.el.querySelector(".iwb-editor-optionbar-body"); + if (!body) return; + if (!force && body.dataset.tool === S.tool) { + syncOptionBar(); + return; + } + body.dataset.tool = S.tool; + body.innerHTML = optionBarHTML(S.tool); + syncOptionBar(); + } + function syncOptionBar() { + const body = runtime.el && runtime.el.querySelector(".iwb-editor-optionbar-body"); + if (!body) return; + const val = (key) => { + if (key === "brushSize") return S.brushSize; + if (key === "brushHardness") return S.brushHardness; + if (key === "brushOpacity") return Math.round(S.brushOpacity * 100); + if (key === "shapeLineWidth") return S.shapeLineWidth; + if (key === "textSize") return S.textSize; + if (key === "feather") return S.selectionFeather; + return ""; + }; + body.querySelectorAll("input[data-opt]").forEach((el) => { + if (document.activeElement === el) return; + const v = val(el.dataset.opt); + if (String(el.value) !== String(v)) el.value = v; + }); + body.querySelectorAll("[data-opt-val]").forEach((el) => { + const v = val(el.dataset.optVal); + el.textContent = el.dataset.optVal === "brushOpacity" ? v + "%" : v; + }); + body.querySelectorAll('[data-opt="shape"]').forEach((btn) => { + btn.classList.toggle("active", S.selectionKind === btn.dataset.value); + }); + body.querySelectorAll("[data-opt-toggle]").forEach((btn) => { + btn.classList.toggle("active", !!S.rectFill === (btn.dataset.value === "fill")); + }); } function updateStatusbar() { if (!runtime.el) return; @@ -2698,6 +3765,76 @@ var __IWB_ANNOTATE_MANIFEST__ = { put(".iwb-editor-status-layer", "当前层:" + (layer ? layer.name : "—")); put(".iwb-editor-status-tool", TOOL_NAMES[S.tool] || S.tool); } + var lwSnapDone = false; + var textSnapDone = false; + function applyShapeLineWidth(committed) { + const sh = getSelectedShape(); + if (!sh || sh.locked) { + lwSnapDone = false; + return; + } + if (committed || !lwSnapDone) { + saveSnapshot("线宽"); + lwSnapDone = true; + } + sh.lw = S.shapeLineWidth; + renderObjects(); + if (committed) lwSnapDone = false; + } + function applyTextSize(committed) { + const t = getSelectedText(); + if (!t || t.locked) { + textSnapDone = false; + return; + } + if (committed || !textSnapDone) { + saveSnapshot("字号"); + textSnapDone = true; + } + t.fontSize = S.textSize; + renderObjects(); + if (committed) textSnapDone = false; + } + function setShapeFill(fill) { + S.rectFill = !!fill; + updateFillUI(); + syncOptionBar(); + const sh = getSelectedShape(); + if (sh && (sh.type === "rect" || sh.type === "circle") && !sh.locked) { + saveSnapshot("填充"); + sh.fill = S.rectFill; + renderObjects(); + } + } + function setOptionFromControl(el, committed) { + const key = el && el.dataset ? el.dataset.opt : ""; + if (!key) return; + const n = Math.round(Number(el.value)); + const safe = Number.isFinite(n) ? n : 0; + if (key === "brushSize") { + S.brushSize = clamp(safe || 1, 1, 300); + updateBrushUI(); + updateBrushParamUI(); + } else if (key === "brushHardness") { + S.brushHardness = clamp(safe, 0, 100); + updateBrushParamUI(); + } else if (key === "brushOpacity") { + S.brushOpacity = clamp(safe || 100, 5, 100) / 100; + updateBrushParamUI(); + if (S.strokeCanvas) S.strokeCanvas.style.opacity = S.brushOpacity; + } else if (key === "shapeLineWidth") { + S.shapeLineWidth = clamp(safe || 1, 1, 60); + applyShapeLineWidth(committed); + } else if (key === "textSize") { + S.textSize = clamp(safe || 32, 8, 400); + applyTextSize(committed); + } else if (key === "feather") { + S.selectionFeather = clamp(safe, 0, 20); + if (S.selection && S.selection.active) S.selection.feather = S.selectionFeather; + updateStatusbar(); + } + syncOptionBar(); + } function bindLiteUI() { const root = runtime.el; if (!root || root.dataset.liteBound === "1") return; @@ -2757,23 +3894,23 @@ var __IWB_ANNOTATE_MANIFEST__ = { const body = root.querySelector(".iwb-editor-optionbar-body"); 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("click", (e) => { - const btn = e.target.closest('[data-opt="shape"]'); - if (!btn) return; - e.stopPropagation(); - S.selectionKind = btn.dataset.value === "ellipse" ? "ellipse" : "rect"; - renderOptionBar(); - toast("选区形状:" + (S.selectionKind === "ellipse" ? "椭圆" : "矩形"), "info"); + const shapeBtn = e.target.closest('[data-opt="shape"]'); + if (shapeBtn) { + e.stopPropagation(); + S.selectionKind = shapeBtn.dataset.value === "ellipse" ? "ellipse" : "rect"; + syncOptionBar(); + toast("选区形状:" + (S.selectionKind === "ellipse" ? "椭圆" : "矩形"), "info"); + return; + } + const toggle = e.target.closest("[data-opt-toggle]"); + if (toggle) { + e.stopPropagation(); + setShapeFill(toggle.dataset.value === "fill"); + } }); - const onFeather = (e) => { - const input = e.target.closest('[data-opt="feather"]'); - if (!input) return; - S.selectionFeather = clamp(parseInt(input.value, 10) || 0, 0, 20); - if (S.selection && S.selection.active) S.selection.feather = S.selectionFeather; - updateStatusbar(); - }; - body.addEventListener("input", onFeather); - body.addEventListener("change", onFeather); } const modal = root.querySelector(".iwb-editor-modal") || root; modal.addEventListener("mousedown", (e) => { @@ -3126,7 +4263,7 @@ var __IWB_ANNOTATE_MANIFEST__ = { return; } saveSnapshot(); - const shape = { id: "s" + Date.now() + Math.floor(Math.random() * 1e3), type: "pen", pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, lw: Math.max(2, S.brushSize), fill: !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }; + const shape = { id: "s" + Date.now() + Math.floor(Math.random() * 1e3), type: "pen", pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }; S.shapeLayers.push(shape); selectUnit("shape", shape.id); S.penPath = null; @@ -3302,7 +4439,14 @@ var __IWB_ANNOTATE_MANIFEST__ = { } function isTyping(e) { const t = e.target; - return t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA"); + if (!t) return false; + if (t.tagName === "TEXTAREA") return true; + if (t.tagName !== "INPUT") return false; + const cls = t.classList; + if (cls && (cls.contains("iwb-editor-text-input") || cls.contains("iwb-editor-color-hex-input"))) return true; + if (e.ctrlKey || e.metaKey || e.altKey) return false; + if (e.key === "Delete" || e.key === "Escape") return false; + return true; } function onKeydown(e) { if (!S.open) return; @@ -3585,6 +4729,34 @@ var __IWB_ANNOTATE_MANIFEST__ = { renderLayerPanel(); bindCanvasEvents(); } + function resizeWorkspace(w, h) { + S.imgW = Math.max(1, Math.round(w)); + S.imgH = Math.max(1, Math.round(h)); + S.textCanvas.width = S.imgW; + S.textCanvas.height = S.imgH; + S.strokeCanvas.width = S.imgW; + S.strokeCanvas.height = S.imgH; + S.overlayPad = Math.max(96, Math.ceil(Math.max(S.imgW, S.imgH) * 0.18)); + for (const [c, cx] of [[S.overlayCanvas, S.overlayCtx], [S.selectionCanvas, S.selectionCtx], [S.cursorCanvas, S.cursorCtx]]) { + if (!c || !cx) continue; + c.width = S.imgW + S.overlayPad * 2; + c.height = S.imgH + S.overlayPad * 2; + cx.setTransform(1, 0, 0, 1, S.overlayPad, S.overlayPad); + } + purgeVectorCanvases(); + for (const layer of S.layers) { + layer.canvas.width = S.imgW; + layer.canvas.height = S.imgH; + layer._bounds = void 0; + } + S.pickerComposite = null; + clearOverlay(); + computeFit(); + S.viewX = null; + applyView(); + renderObjects(); + renderLayerPanel(); + } function computeFit() { const availW = Math.max(50, S.canvasWrap.clientWidth - 48); const availH = Math.max(50, S.canvasWrap.clientHeight - 48); @@ -3740,1007 +4912,6 @@ var __IWB_ANNOTATE_MANIFEST__ = { }; } - // 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 }; - } - function getSelectedText() { - return S.textLayers.find((t) => t.id === S.selectedTextId) || null; - } - function hitTextLayer(pos) { - for (let i = S.textLayers.length - 1; i >= 0; i--) { - const t = S.textLayers[i]; - if (t.visible === false) continue; - const b = textBounds(t); - const rot = t.rotation || 0; - const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]; - if (lp[0] >= b.x - 2 && lp[0] <= b.x + b.w + 2 && lp[1] >= b.y - 2 && lp[1] <= b.y + b.h + 2) { - return t; - } - } - return null; - } - function textHandlePoints(t) { - const b = textBounds(t); - const rot = t.rotation || 0; - const cx = b.x + b.w / 2, cy = b.y + b.h / 2; - const local = { nw: [b.x, b.y], ne: [b.x + b.w, b.y], sw: [b.x, b.y + b.h], se: [b.x + b.w, b.y + b.h] }; - const out = {}; - for (const k in local) out[k] = rotPt(local[k][0], local[k][1], cx, cy, rot); - return out; - } - function hitTextHandle(pos) { - const t = getSelectedText(); - if (!t) return null; - const b = textBounds(t); - const rot = t.rotation || 0; - const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]; - if (hitRotationHandle(lp, b)) return "rotate"; - const local = { nw: [b.x, b.y], ne: [b.x + b.w, b.y], sw: [b.x, b.y + b.h], se: [b.x + b.w, b.y + b.h] }; - const R = 12 / S.zoom; - let best = null, bestDist = 1e9; - for (const name in local) { - const dx = lp[0] - local[name][0], dy = lp[1] - local[name][1]; - const d = dx * dx + dy * dy; - if (d < R * R && d < bestDist) { - bestDist = d; - best = name; - } - } - return best; - } - function shapeBounds(s) { - if (s.type === "pen" && s.pts && s.pts.length) { - const xs = s.pts.map((p) => p.x), ys = s.pts.map((p) => p.y), x = Math.min(...xs), y = Math.min(...ys); - return { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y }; - } - return { x: Math.min(s.x1, s.x2), y: Math.min(s.y1, s.y2), w: Math.abs(s.x2 - s.x1), h: Math.abs(s.y2 - s.y1) }; - } - function getSelectedShape() { - return S.shapeLayers.find((s) => s.id === S.selectedShapeId) || null; - } - function distToSeg(px, py, x1, y1, x2, y2) { - const dx = x2 - x1, dy = y2 - y1; - const l2 = dx * dx + dy * dy; - let t = l2 ? ((px - x1) * dx + (py - y1) * dy) / l2 : 0; - t = clamp(t, 0, 1); - return Math.hypot(px - (x1 + t * dx), py - (y1 + t * dy)); - } - function hitShapeObj(pos, s, includeInterior) { - if (s.visible === false) return false; - if (s.rotation) { - const b = shapeBounds(s); - const lp = unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, s.rotation); - pos = { x: lp[0], y: lp[1] }; - } - if (s.type === "pen") { - const pts = s.pts || []; - for (let i = 1; i < pts.length; i++) if (distToSeg(pos.x, pos.y, pts[i - 1].x, pts[i - 1].y, pts[i].x, pts[i].y) <= Math.max(8 / S.zoom, s.lw)) return true; - if (s.closed && pts.length > 2 && distToSeg(pos.x, pos.y, pts[pts.length - 1].x, pts[pts.length - 1].y, pts[0].x, pts[0].y) <= Math.max(8 / S.zoom, s.lw)) return true; - if (!includeInterior) return false; - const b = shapeBounds(s); - return pos.x >= b.x && pos.x <= b.x + b.w && pos.y >= b.y && pos.y <= b.y + b.h; - } - if (s.type === "circle") { - const b = shapeBounds(s); - const cx = b.x + b.w / 2, cy = b.y + b.h / 2; - const rx = Math.max(0.5, b.w / 2), ry = Math.max(0.5, b.h / 2); - const nx = (pos.x - cx) / rx, ny = (pos.y - cy) / ry; - const value = nx * nx + ny * ny; - if (includeInterior || s.fill) return value <= 1; - const edgeTolerance = Math.max(4 / S.zoom, s.lw / Math.min(rx, ry)); - const outer = (1 + edgeTolerance) * (1 + edgeTolerance); - const inner = Math.max(0, 1 - edgeTolerance) * Math.max(0, 1 - edgeTolerance); - return value >= inner && value <= outer; - } - if (s.type === "rect") { - const b = shapeBounds(s); - const pad = Math.max(4, s.lw * 1.5); - const inOuter = pos.x >= b.x - pad && pos.x <= b.x + b.w + pad && pos.y >= b.y - pad && pos.y <= b.y + b.h + pad; - if (!inOuter) return false; - if (includeInterior || s.fill) return true; - const inInner = pos.x >= b.x + pad && pos.x <= b.x + b.w - pad && pos.y >= b.y + pad && pos.y <= b.y + b.h - pad; - return !inInner; - } - return distToSeg(pos.x, pos.y, s.x1, s.y1, s.x2, s.y2) <= Math.max(8 / S.zoom, s.lw); - } - function hitShapeLayer(pos, includeInterior) { - for (let i = S.shapeLayers.length - 1; i >= 0; i--) { - if (hitShapeObj(pos, S.shapeLayers[i], includeInterior)) return S.shapeLayers[i]; - } - return null; - } - function allObjects() { - const arr = S.textLayers.map((o) => ({ kind: "text", obj: o })).concat(S.shapeLayers.map((o) => ({ kind: "shape", obj: o }))); - arr.sort((a, b) => (a.obj.z || 0) - (b.obj.z || 0)); - return arr; - } - function sortLayersByZ() { - const cmp = (a, b) => (a.z || 0) - (b.z || 0); - S.textLayers.sort(cmp); - S.shapeLayers.sort(cmp); - } - function layerUnits() { - const arr = S.layers.map((obj) => ({ kind: "bitmap", obj })).concat(S.textLayers.map((obj) => ({ kind: "text", obj }))).concat(S.shapeLayers.map((obj) => ({ kind: "shape", obj }))); - arr.sort((a, b) => (a.obj.z || 0) - (b.obj.z || 0)); - return arr; - } - function layerUnitsDesc() { - return layerUnits().reverse(); - } - function assignLayerZ(units) { - units.forEach((u, i) => { - u.obj.z = i; - }); - S.zCounter = Math.max(S.zCounter, units.length - 1); - } - function selectUnit(kind, id) { - S.selectedLayerId = kind === "bitmap" ? id : null; - S.selectedTextId = kind === "text" ? id : null; - S.selectedShapeId = kind === "shape" ? id : null; - S.textDrag = null; - S.shapeDrag = null; - S.bitmapDrag = null; - } - function hitUnit(unit, pos) { - const { kind, obj } = unit; - if (!obj || obj.visible === false) return false; - if (kind === "bitmap") return obj.locked ? false : hitBitmapAt(obj, pos); - if (kind === "text") { - const b = textBounds(obj); - const rot = obj.rotation || 0; - const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]; - return lp[0] >= b.x - 2 && lp[0] <= b.x + b.w + 2 && lp[1] >= b.y - 2 && lp[1] <= b.y + b.h + 2; - } - return hitShapeObj(pos, obj, true); - } - function hitTopmost(pos) { - for (const unit of layerUnitsDesc()) if (hitUnit(unit, pos)) return unit; - return null; - } - function hitAnyObject(pos) { - for (const unit of layerUnitsDesc()) { - if (unit.kind === "bitmap") continue; - if (hitUnit(unit, pos)) return unit; - } - return null; - } - function getSelectedObject() { - const t = getSelectedText(); - if (t) return { kind: "text", obj: t }; - const s = getSelectedShape(); - if (s) return { kind: "shape", obj: s }; - return null; - } - function moveLayer(dir) { - let sel = getSelectedObject(); - if (sel) { - if (sel.obj.locked) return; - } else { - 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; - const units = layerUnits(); - const baseIdx = units.findIndex((u) => u.obj.id === "base"); - if (baseIdx > 0) { - const [b] = units.splice(baseIdx, 1); - units.unshift(b); - } - const from = units.findIndex((u) => u.obj === sel.obj); - if (from < 0) return; - const min = baseIdx >= 0 ? 1 : 0; - let to; - if (dir === "up") to = Math.min(from + 1, units.length - 1); - else if (dir === "down") to = Math.max(from - 1, min); - else if (dir === "top") to = units.length - 1; - else if (dir === "bottom") to = min; - else return; - if (to === from) return; - saveSnapshot(); - const [moved] = units.splice(from, 1); - units.splice(to, 0, moved); - assignLayerZ(units); - sortLayersByZ(); - reorderLayerCanvas(); - renderObjects(); - renderLayerPanel(); - } - function shapeHandlePoints(s) { - const b = shapeBounds(s); - if (s.type === "pen") { - return Object.fromEntries((s.pts || []).map((p, i) => ["p" + i, [p.x, p.y]])); - } - if (s.type === "arrow") { - return { start: [s.x1, s.y1], end: [s.x2, s.y2] }; - } - return { - nw: [b.x, b.y], - ne: [b.x + b.w, b.y], - sw: [b.x, b.y + b.h], - se: [b.x + b.w, b.y + b.h], - n: [b.x + b.w / 2, b.y], - s: [b.x + b.w / 2, b.y + b.h], - e: [b.x + b.w, b.y + b.h / 2], - w: [b.x, b.y + b.h / 2] - }; - } - function shapeHandleWorld(s) { - const b = shapeBounds(s); - const rot = s.rotation || 0; - const cx = b.x + b.w / 2, cy = b.y + b.h / 2; - const local = shapeHandlePoints(s); - const out = {}; - for (const k in local) out[k] = rotPt(local[k][0], local[k][1], cx, cy, rot); - return out; - } - function hitShapeHandle(pos) { - const s = getSelectedShape(); - if (!s) return null; - const b = shapeBounds(s); - const rot = s.rotation || 0; - const cx = b.x + b.w / 2, cy = b.y + b.h / 2; - const lp = rot ? unrotPt(pos.x, pos.y, cx, cy, rot) : [pos.x, pos.y]; - if (hitRotationHandle(lp, b)) return "rotate"; - const pts = shapeHandlePoints(s); - const offset = 8 / S.zoom; - const R = Math.max(18 / S.zoom, 11); - let best = null, bestDist = 1e9; - for (const name in pts) { - const px = pts[name][0] + (name.includes("w") ? -offset : name.includes("e") ? offset : 0); - const py = pts[name][1] + (name.includes("n") ? -offset : name.includes("s") ? offset : 0); - const dx = lp[0] - px, dy = lp[1] - py; - const d = dx * dx + dy * dy; - if (d < R * R && d < bestDist) { - bestDist = d; - best = name; - } - } - return best; - } - function applyShapeHandle(s, handle, pos) { - const b0 = shapeBounds(s); - const rot0 = s.rotation || 0; - const c0x = b0.x + b0.w / 2, c0y = b0.y + b0.h / 2; - if (handle === "rotate") { - const st = S.shapeDrag && S.shapeDrag.start; - const baseRot = S.shapeDrag && S.shapeDrag.shape && (S.shapeDrag.shape.rotation || 0) || 0; - if (st) { - const a0 = Math.atan2(st.y - c0y, st.x - c0x); - const a1 = Math.atan2(pos.y - c0y, pos.x - c0x); - let deg = baseRot + (a1 - a0) * 180 / Math.PI; - if (S._shiftDown) deg = Math.round(deg / 15) * 15; - s.rotation = deg; - } - return; - } - const lp = rot0 ? unrotPt(pos.x, pos.y, c0x, c0y, rot0) : [pos.x, pos.y]; - pos = { x: lp[0], y: lp[1] }; - if (s.type === "pen" && handle && handle[0] === "p") { - const i = parseInt(handle.slice(1), 10); - if (s.pts && s.pts[i]) { - s.pts[i].x = clamp(pos.x, 0, S.imgW); - s.pts[i].y = clamp(pos.y, 0, S.imgH); - } - return; - } - if (s.type === "arrow") { - if (handle === "start") { - s.x1 = clamp(pos.x, 0, S.imgW); - s.y1 = clamp(pos.y, 0, S.imgH); - } else { - s.x2 = clamp(pos.x, 0, S.imgW); - s.y2 = clamp(pos.y, 0, S.imgH); - } - return; - } - const b = shapeBounds(s); - const offset = 8 / S.zoom; - const adjusted = { x: pos.x - (handle.includes("w") ? -offset : handle.includes("e") ? offset : 0), y: pos.y - (handle.includes("n") ? -offset : handle.includes("s") ? offset : 0) }; - let x1 = b.x, y1 = b.y, x2 = b.x + b.w, y2 = b.y + b.h; - if (handle.includes("e")) x2 = Math.max(x1 + 2, adjusted.x); - if (handle.includes("s")) y2 = Math.max(y1 + 2, adjusted.y); - if (handle.includes("w")) x1 = Math.min(x2 - 2, adjusted.x); - if (handle.includes("n")) y1 = Math.min(y2 - 2, adjusted.y); - s.x1 = x1; - s.y1 = y1; - s.x2 = x2; - s.y2 = y2; - } - function drawPenPathPreview() { - const path = S.penPath; - if (!path || !path.pts || !path.pts.length) return; - const ctx = S.overlayCtx; - const pts = path.pts.slice(); - const first = pts[0]; - const nearStart = path.preview && pts.length >= 3 && Math.hypot(path.preview.x - first.x, path.preview.y - first.y) <= Math.max(12 / S.zoom, S.brushSize * 1.5); - if (path.preview) pts.push(nearStart ? first : path.preview); - ctx.save(); - ctx.strokeStyle = S.color; - ctx.fillStyle = nearStart ? "rgba(232, 167, 53, 0.18)" : "transparent"; - ctx.lineWidth = Math.max(2, S.brushSize) / S.zoom; - ctx.setLineDash([8 / S.zoom, 5 / S.zoom]); - ctx.beginPath(); - ctx.moveTo(pts[0].x, pts[0].y); - for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); - if (nearStart) { - ctx.closePath(); - ctx.fill(); - } - ctx.stroke(); - ctx.setLineDash([]); - for (let i = 0; i < path.pts.length; i++) { - const point = path.pts[i]; - ctx.beginPath(); - ctx.fillStyle = i === 0 && nearStart ? "#e8a735" : "#ffffff"; - ctx.strokeStyle = S.color; - ctx.arc(point.x, point.y, Math.max(4, 6 / S.zoom), 0, Math.PI * 2); - ctx.fill(); - ctx.stroke(); - } - ctx.restore(); - } - function drawShapeSelection(s) { - const octx = S.overlayCtx; - const b = shapeBounds(s); - const rot = s.rotation || 0; - octx.save(); - octx.strokeStyle = "#e8a735"; - octx.lineWidth = 1.5 / S.zoom; - octx.setLineDash([6 / S.zoom, 3 / S.zoom]); - const corners = boxCorners(b.x, b.y, b.w, b.h, rot); - octx.beginPath(); - octx.moveTo(corners[0][0], corners[0][1]); - for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]); - octx.closePath(); - octx.stroke(); - octx.setLineDash([]); - const hs = 8.5 / S.zoom; - octx.fillStyle = "#ffffff"; - octx.strokeStyle = "#e8a735"; - const pts = shapeHandleWorld(s); - for (const name in pts) { - octx.beginPath(); - octx.rect(pts[name][0] - hs, pts[name][1] - hs, hs * 2, hs * 2); - octx.fill(); - octx.stroke(); - } - octx.restore(); - drawRotationHandles(octx, b, rot); - } - function deleteSelectedShape() { - if (!S.selectedShapeId) return; - const selected = getSelectedShape(); - if (selected && selected.locked) return; - saveSnapshot(); - removeVecCanvas(selected); - S.shapeLayers = S.shapeLayers.filter((s) => s.id !== S.selectedShapeId); - S.selectedShapeId = null; - renderObjects(); - } - function renderObjects(tempShape) { - for (const { kind, obj } of allObjects()) drawVectorToCanvas(kind, obj); - reorderLayerCanvas(); - clearOverlay(); - if (tempShape) drawShape(S.overlayCtx, tempShape); - if (S.tool === "pen" && S.penPath && S.penPath.pts.length) drawPenPathPreview(); - if (S.placingImage) { - drawPlacementPreview(); - return; - } - const bitmapSelection = S.layers.find((l) => l.id === S.selectedLayerId && (l.transformable || isDrawableLayer(l))); - if (bitmapSelection) drawBitmapSelection(bitmapSelection); - const sel = getSelectedText(); - if (sel) { - const b = textBounds(sel); - const rot = sel.rotation || 0; - const octx = S.overlayCtx; - octx.save(); - octx.strokeStyle = "#e8a735"; - octx.lineWidth = 1.5 / S.zoom; - octx.setLineDash([6 / S.zoom, 3 / S.zoom]); - const corners = boxCorners(b.x - 2 / S.zoom, b.y - 2 / S.zoom, b.w + 4 / S.zoom, b.h + 4 / S.zoom, rot); - octx.beginPath(); - octx.moveTo(corners[0][0], corners[0][1]); - for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]); - octx.closePath(); - octx.stroke(); - octx.setLineDash([]); - const hs = 7 / S.zoom; - octx.fillStyle = "#ffffff"; - octx.strokeStyle = "#e8a735"; - const pts = textHandlePoints(sel); - for (const name in pts) { - octx.beginPath(); - octx.rect(pts[name][0] - hs, pts[name][1] - hs, hs * 2, hs * 2); - octx.fill(); - octx.stroke(); - } - octx.restore(); - } else { - const sh = getSelectedShape(); - if (sh) drawShapeSelection(sh); - } - const penShape = getPenEditingShape(); - if (penShape) drawPenEditOverlay(penShape); - if (S.cropRect) drawCropPreview(); - updateLayerUI(); - } - function getPenEditingShape() { - if (!S.penEditId) return null; - return S.shapeLayers.find((sh) => sh.id === S.penEditId && sh.type === "pen") || null; - } - function beginPenEdit(shape) { - S.penEditId = shape.id; - S.selectedShapeId = shape.id; - S.selectedTextId = null; - S.selectedLayerId = null; - S.shapeDrag = null; - S.penDragPt = -1; - S.penDragBase = null; - S.penDragPending = null; - renderObjects(); - renderLayerPanel(); - } - function exitPenEdit() { - S.penEditId = null; - S.penDragPt = -1; - S.penDragBase = null; - S.penDragPending = null; - renderObjects(); - renderLayerPanel(); - } - function hitPenPoint(pos, shape, r) { - const pts = shape.pts || []; - const b = shapeBounds(shape); - const lp = shape.rotation ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, shape.rotation) : [pos.x, pos.y]; - for (let i = 0; i < pts.length; i++) { - if (Math.hypot(lp[0] - pts[i].x, lp[1] - pts[i].y) <= r) return i; - } - return -1; - } - function hitPenEdgeInsert(pos, shape) { - const pts = shape.pts || []; - const b = shapeBounds(shape); - const lp = shape.rotation ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, shape.rotation) : [pos.x, pos.y]; - const r = Math.max(12 / S.zoom, 6); - for (let i = 0; i < pts.length - 1; i++) { - if (distToSeg(lp[0], lp[1], pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y) <= r) return i; - } - if (shape.closed && pts.length >= 3) { - if (distToSeg(lp[0], lp[1], pts[pts.length - 1].x, pts[pts.length - 1].y, pts[0].x, pts[0].y) <= r) return pts.length - 1; - } - return -1; - } - function drawPenEditOverlay(shape) { - const ctx = S.overlayCtx; - const pts = shape.pts || []; - const b = shapeBounds(shape); - const rot = shape.rotation || 0; - const cx = b.x + b.w / 2, cy = b.y + b.h / 2; - const W = (p) => rotPt(p.x, p.y, cx, cy, rot); - const R = Math.max(7 / S.zoom, 5); - ctx.save(); - ctx.lineWidth = 1.5 / S.zoom; - const segments = []; - for (let i = 0; i < pts.length - 1; i++) segments.push([pts[i], pts[i + 1]]); - if (shape.closed && pts.length >= 3) segments.push([pts[pts.length - 1], pts[0]]); - ctx.strokeStyle = "#e8a735"; - for (const [a, bb] of segments) { - const wa = W(a), wb = W(bb); - const mx = (wa[0] + wb[0]) / 2, my = (wa[1] + wb[1]) / 2; - ctx.beginPath(); - ctx.arc(mx, my, Math.max(3 / S.zoom, 2), 0, Math.PI * 2); - ctx.stroke(); - } - for (let i = 0; i < pts.length; i++) { - const wp = W(pts[i]); - ctx.beginPath(); - ctx.rect(wp[0] - R / 2, wp[1] - R / 2, R, R); - ctx.fillStyle = "#ffffff"; - ctx.strokeStyle = i === S.penDragPt ? "#ff8c00" : "#e8a735"; - ctx.fill(); - ctx.stroke(); - } - ctx.restore(); - } - function showTextInput(x, y, layer) { - const input = runtime.el.querySelector(".iwb-editor-text-input"); - const rect = S.canvasStack.getBoundingClientRect(); - const wrapRect = S.canvasWrap.getBoundingClientRect(); - const sx = rect.width / S.imgW; - const sy = rect.height / S.imgH; - input.style.left = rect.left - wrapRect.left + x * sx + "px"; - input.style.top = rect.top - wrapRect.top + y * sy + "px"; - input.style.display = "block"; - if (layer) { - input.value = layer.text; - S.textEditingId = layer.id; - } else { - input.value = ""; - S.textEditingId = null; - } - input.focus(); - input.select(); - input.dataset.x = x; - input.dataset.y = y; - } - function hideTextInput() { - const input = runtime.el.querySelector(".iwb-editor-text-input"); - if (input) { - if (document.activeElement === input) input.blur(); - input.style.display = "none"; - input.value = ""; - } - S.textEditingId = null; - } - function commitTextInput() { - const input = runtime.el.querySelector(".iwb-editor-text-input"); - if (!input || input.style.display === "none") return false; - const text = input.value.trim(); - const x = parseFloat(input.dataset.x); - const y = parseFloat(input.dataset.y); - let committed = false; - if (S.textEditingId) { - const t = S.textLayers.find((l) => l.id === S.textEditingId); - if (t && t.locked) { - hideTextInput(); - return true; - } - if (t && text !== t.text) { - saveSnapshot(); - if (text) { - t.text = text; - } else { - removeVecCanvas(t); - S.textLayers = S.textLayers.filter((l) => l.id !== t.id); - S.selectedTextId = null; - } - renderObjects(); - } - committed = true; - } else if (text) { - saveSnapshot(); - const layer = { - id: "t" + Date.now() + Math.floor(Math.random() * 1e3), - x, - y, - text, - color: S.color, - fontSize: Math.max(16, S.brushSize * 6), - opacity: 1, - visible: true, - locked: false, - z: ++S.zCounter - }; - S.textLayers.push(layer); - selectUnit("text", layer.id); - renderObjects(); - committed = true; - } - hideTextInput(); - return committed; - } - function deleteSelectedText() { - if (!S.selectedTextId) return; - const selected = getSelectedText(); - if (selected && selected.locked) return; - saveSnapshot(); - removeVecCanvas(selected); - S.textLayers = S.textLayers.filter((t) => t.id !== S.selectedTextId); - S.selectedTextId = null; - renderObjects(); - } - function beginTextRotate(pos) { - const t = getSelectedText(); - if (!t || t.locked) return; - const b = textBounds(t); - S.textDrag = { - mode: "rotate", - rotation: t.rotation || 0, - cx: b.x + b.w / 2, - cy: b.y + b.h / 2, - startX0: pos.x, - startY0: pos.y, - pending: snapshotState() - }; - } - function beginTextScaleDrag(handle, pos) { - const t = getSelectedText(); - if (!t || t.locked) return; - const b = textBounds(t); - const rot = t.rotation || 0; - const cx = b.x + b.w / 2, cy = b.y + b.h / 2; - const anchors = { - se: [b.x, b.y], - ne: [b.x, b.y + b.h], - sw: [b.x + b.w, b.y], - nw: [b.x + b.w, b.y + b.h] - }; - const a = rotPt(anchors[handle][0], anchors[handle][1], cx, cy, rot); - const anchor = { x: a[0], y: a[1] }; - const dx = pos.x - anchor.x, dy = pos.y - anchor.y; - S.textDrag = { - mode: "scale", - anchor, - d0: Math.sqrt(dx * dx + dy * dy), - fontSize: t.fontSize, - pending: snapshotState() - }; - } - function beginShapeHandleDrag(handle, pos) { - const sh = getSelectedShape(); - if (!sh || sh.locked) return; - S.shapeDrag = { - mode: "handle", - handle, - start: pos, - shape: { ...sh }, - pending: snapshotState() - }; - } - - // image-annotate/plugin/editor/tools.js - var brushStampCache = { key: "", canvas: null }; - function getBrushStamp(size, color, hardness) { - const key = size + "|" + color + "|" + hardness; - if (brushStampCache.key === key && brushStampCache.canvas) return brushStampCache.canvas; - const c = document.createElement("canvas"); - c.width = size; - c.height = size; - const cx = c.getContext("2d"); - const half = size / 2; - const { r, g, b } = hexToRgb(color); - const grad = cx.createRadialGradient(half, half, half * hardness / 100, half, half, half); - grad.addColorStop(0, `rgba(${r},${g},${b},1)`); - grad.addColorStop(1, `rgba(${r},${g},${b},0)`); - cx.fillStyle = grad; - cx.fillRect(0, 0, size, size); - brushStampCache = { key, canvas: c }; - return c; - } - function strokeSegment(x1, y1, x2, y2) { - const ctx = S.strokeCtx; - const size = Math.max(1, S.brushSize); - const color = S.tool === "eraser" ? "#ffffff" : S.color; - ctx.save(); - if (S.brushHardness >= 100) { - ctx.strokeStyle = color; - ctx.lineWidth = size; - ctx.lineCap = "round"; - ctx.lineJoin = "round"; - ctx.beginPath(); - ctx.moveTo(x1, y1); - ctx.lineTo(x2, y2); - ctx.stroke(); - } else { - const stamp = getBrushStamp(size, color, S.brushHardness); - const dist = Math.hypot(x2 - x1, y2 - y1); - const step = Math.max(1, size / 6); - const n = Math.max(0, Math.ceil(dist / step)); - for (let i = 0; i <= n; i++) { - const t = n === 0 ? 0 : i / n; - ctx.drawImage(stamp, x1 + (x2 - x1) * t - size / 2, y1 + (y2 - y1) * t - size / 2); - } - } - ctx.restore(); - S.strokeCanvas.style.opacity = S.brushOpacity; - } - function eraseSegment(x1, y1, x2, y2) { - const ctx = getActiveCtx(); - if (!ctx) return; - ctx.save(); - if (S.selection && S.selection.active) ctx.clip(S.selection.path, S.selection.fillRule); - ctx.globalCompositeOperation = "destination-out"; - ctx.globalAlpha = S.brushOpacity; - ctx.lineWidth = Math.max(1, S.brushSize); - ctx.lineCap = "round"; - ctx.lineJoin = "round"; - ctx.beginPath(); - ctx.moveTo(x1, y1); - ctx.lineTo(x2, y2); - ctx.stroke(); - ctx.restore(); - const active = getActiveLayer(); - if (active && active.id === "draw" && active.sourceCanvas) { - const sourceCtx = active.sourceCanvas.getContext("2d", { willReadFrequently: true }); - sourceCtx.save(); - sourceCtx.globalCompositeOperation = "destination-out"; - sourceCtx.globalAlpha = S.brushOpacity; - sourceCtx.lineWidth = Math.max(1, S.brushSize) * active.w / Math.max(S.imgW, 1); - sourceCtx.lineCap = "round"; - sourceCtx.beginPath(); - sourceCtx.moveTo((x1 - active.x) * S.imgW / active.w, (y1 - active.y) * S.imgW / active.w); - sourceCtx.lineTo((x2 - active.x) * S.imgW / active.w, (y2 - active.y) * S.imgW / active.w); - sourceCtx.stroke(); - sourceCtx.restore(); - } - S.pickerComposite = null; - renderObjects(); - } - function bakeDrawableLayer(layer) { - if (!layer || !isDrawableLayer(layer) || !layer._srcBox) return; - layer._srcBox = null; - layer.sourceCanvas = null; - layer.rotation = 0; - layer.x = 0; - layer.y = 0; - layer.w = S.imgW; - layer.h = S.imgH; - layer._bounds = void 0; - } - function beginStroke() { - bakeDrawableLayer(getActiveLayer()); - S.strokeCanvas.width = S.imgW; - S.strokeCanvas.height = S.imgH; - S.strokeCtx.clearRect(0, 0, S.imgW, S.imgH); - S.strokeCanvas.style.display = S.tool === "eraser" ? "none" : "block"; - S.strokeCanvas.style.opacity = S.brushOpacity; - } - function endStroke() { - for (const l of S.layers) l._bounds = void 0; - const ctx = getActiveCtx(); - if (!ctx) return; - ctx.save(); - if (S.selection && S.selection.active) ctx.clip(S.selection.path, S.selection.fillRule); - if (S.tool === "eraser") { - ctx.globalCompositeOperation = "destination-out"; - } - ctx.globalAlpha = S.brushOpacity; - ctx.drawImage(S.strokeCanvas, 0, 0); - ctx.restore(); - S.strokeCanvas.style.display = "none"; - const active = getActiveLayer(); - if (active && active.id === "draw" && active.sourceCanvas && active.w > 0 && active.h > 0) { - const sourceCtx = active.sourceCanvas.getContext("2d", { willReadFrequently: true }); - sourceCtx.save(); - sourceCtx.globalCompositeOperation = S.tool === "eraser" ? "destination-out" : "source-over"; - sourceCtx.globalAlpha = S.brushOpacity; - sourceCtx.translate(-active.x * S.imgW / active.w, -active.y * S.imgH / active.h); - sourceCtx.scale(S.imgW / active.w, S.imgH / active.h); - sourceCtx.drawImage(S.strokeCanvas, 0, 0); - sourceCtx.restore(); - } - S.strokeCtx.clearRect(0, 0, S.imgW, S.imgH); - S.pickerComposite = null; - } - function drawShape(ctx, s) { - ctx.save(); - ctx.globalAlpha = s.opacity != null ? s.opacity : 1; - const rot = s.rotation || 0; - if (rot) { - const b = shapeBounds(s); - 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.strokeStyle = s.color; - ctx.lineWidth = s.lw; - ctx.lineCap = "round"; - ctx.lineJoin = "round"; - if (s.type === "pen") { - const pts = Array.isArray(s.pts) ? s.pts : []; - if (pts.length > 1) { - ctx.beginPath(); - ctx.moveTo(pts[0].x, pts[0].y); - for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); - if (s.closed) ctx.closePath(); - if (s.closed && s.fill) { - ctx.fillStyle = s.color; - ctx.fill(); - } - ctx.stroke(); - } - } 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); - } - 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); - ctx.beginPath(); - ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2); - if (s.fill) { - ctx.fillStyle = s.color; - ctx.fill(); - } - ctx.stroke(); - } else { - ctx.fillStyle = s.color; - ctx.beginPath(); - ctx.moveTo(s.x1, s.y1); - ctx.lineTo(s.x2, s.y2); - ctx.stroke(); - const angle = Math.atan2(s.y2 - s.y1, s.x2 - s.x1); - const headLen = Math.max(12, s.lw * 4); - ctx.beginPath(); - ctx.moveTo(s.x2, s.y2); - ctx.lineTo(s.x2 - headLen * Math.cos(angle - Math.PI / 6), s.y2 - headLen * Math.sin(angle - Math.PI / 6)); - ctx.moveTo(s.x2, s.y2); - ctx.lineTo(s.x2 - headLen * Math.cos(angle + Math.PI / 6), s.y2 - headLen * Math.sin(angle + Math.PI / 6)); - ctx.stroke(); - } - ctx.restore(); - } - function getToolBrushRadius() { - return Math.max(1, S.brushSize) / 2; - } - function screenScale() { - const rect = S.canvasStack.getBoundingClientRect(); - return rect.width ? rect.width / S.imgW : S.zoom; - } - function clearToolRing() { - const ctx = S.cursorCtx; - if (!ctx) return; - const pad = S.overlayPad || 0; - ctx.save(); - ctx.setTransform(1, 0, 0, 1, 0, 0); - ctx.clearRect(0, 0, S.imgW + pad * 2, S.imgH + pad * 2); - ctx.restore(); - ctx.setTransform(1, 0, 0, 1, pad, pad); - } - function drawToolRing(pos) { - clearToolRing(); - const ctx = S.cursorCtx || S.overlayCtx; - const r = getToolBrushRadius(); - const k = 1 / screenScale(); - const rMin = 2 * k; - const rr = Math.max(r, rMin); - ctx.save(); - ctx.lineWidth = k; - ctx.strokeStyle = "rgba(0,0,0,0.8)"; - ctx.beginPath(); - ctx.arc(pos.x, pos.y, rr, 0, Math.PI * 2); - ctx.stroke(); - ctx.strokeStyle = "rgba(255,255,255,0.9)"; - ctx.lineWidth = k; - ctx.beginPath(); - ctx.arc(pos.x, pos.y, Math.max(rr - k, 0), 0, Math.PI * 2); - ctx.stroke(); - ctx.restore(); - } - function getCompositeCanvas() { - const c = document.createElement("canvas"); - c.width = S.imgW; - c.height = S.imgH; - const cx = c.getContext("2d", { willReadFrequently: true }); - cx.globalAlpha = 1; - for (const u of layerUnits()) { - if (u.obj.visible === false) continue; - const el = u.kind === "bitmap" ? u.obj.canvas : u.obj._canvas; - if (!el) continue; - cx.globalAlpha = u.obj.opacity == null ? 1 : u.obj.opacity; - cx.drawImage(el, 0, 0); - } - cx.globalAlpha = 1; - return c; - } - function getPickerComposite() { - if (!S.pickerComposite) { - S.pickerComposite = getCompositeCanvas().getContext("2d", { willReadFrequently: true }); - } - return S.pickerComposite; - } - function sampleColor(pos) { - const x = clamp(Math.floor(pos.x), 0, Math.max(0, S.imgW - 1)); - const y = clamp(Math.floor(pos.y), 0, Math.max(0, S.imgH - 1)); - try { - const d = getPickerComposite().getImageData(x, y, 1, 1).data; - return { r: d[0], g: d[1], b: d[2], a: d[3] }; - } catch (e) { - return null; - } - } - function showPickerTip(e, s) { - const tip = runtime.el.querySelector(".iwb-editor-picker-tip"); - if (!tip) return; - const chip = tip.querySelector(".iwb-editor-picker-chip"); - const hex = tip.querySelector(".iwb-editor-picker-hex"); - if (s && s.a > 0) { - const h = rgbToHex(s.r, s.g, s.b); - chip.style.background = h; - chip.style.border = "1px solid rgba(255,255,255,0.3)"; - hex.textContent = h; - } else { - chip.style.background = "transparent"; - chip.style.border = "1px dashed rgba(255,255,255,0.4)"; - hex.textContent = "透明"; - } - tip.style.display = "flex"; - tip.style.left = e.clientX + 16 + "px"; - tip.style.top = e.clientY + 16 + "px"; - } - function hidePickerTip() { - const tip = runtime.el.querySelector(".iwb-editor-picker-tip"); - if (tip) tip.style.display = "none"; - } - function exitPicker() { - S.tool = S.prevTool && S.prevTool !== "picker" ? S.prevTool : "brush"; - S.prevTool = null; - S.pickerComposite = null; - hidePickerTip(); - updateToolUI(); - updateBrushParamUI(); - if (S.tool === "crop") { - showCropBar(); - updateCropInfo(); - } else { - cancelCrop(); - hideCropBar(); - } - renderObjects(); - } - function applyColorChange(color) { - S.color = color; - updateColorUI(); - const t = getSelectedText(); - if (t && !t.locked && t.color !== S.color) { - saveSnapshot(); - t.color = S.color; - renderObjects(); - } - const sh = getSelectedShape(); - if (sh && !sh.locked && S.tool !== "text" && sh.color !== S.color) { - saveSnapshot(); - sh.color = S.color; - renderObjects(); - } - } - function setTool(tool) { - if (S.placingImage) cancelImagePlacement(); - commitTextInput(); - if (tool !== "select" && tool !== "pen") { - S.penEditId = null; - S.penDragPt = -1; - S.penDragPending = null; - } - if (tool === "picker" && S.tool !== "picker") S.prevTool = S.tool; - if (tool !== "pen") S.penPath = null; - if (tool === "crop") { - S.selection = null; - S.marquee = null; - S.lassoPts = null; - } - if (tool !== "marquee" && tool !== "lasso") { - if (S.marquee || S.lassoPts) { - S.isDrawing = false; - S.interaction = "idle"; - } - S.marquee = null; - S.lassoPts = null; - } - S.tool = tool; - if (tool !== "select") S.selectedLayerId = null; - if (tool !== "text" && tool !== "select") S.selectedTextId = null; - if (tool !== "rect" && tool !== "circle" && tool !== "arrow" && tool !== "pen" && tool !== "select") S.selectedShapeId = null; - S.bitmapDrag = null; - S.textDrag = null; - S.shapeDrag = null; - S.pickerComposite = null; - hidePickerTip(); - updateToolUI(); - updateBrushParamUI(); - if (tool === "crop") { - showCropBar(); - updateCropInfo(); - } else { - cancelCrop(); - hideCropBar(); - } - renderObjects(); - renderLayerPanel(); - if (S.renderAll) S.renderAll(); - } - // image-annotate/plugin/editor/crop.js function setConstraint(type, ratio, sizeW, sizeH) { S.cropConstraint = { type, ratio: ratio || 0, sizeW: sizeW || 0, sizeH: sizeH || 0 }; @@ -4970,54 +5141,57 @@ var __IWB_ANNOTATE_MANIFEST__ = { cancelCrop(); return; } - disposeSelection(); - const tmp = getCompositeCanvas(); - const sx = Math.round(x), sy = Math.round(y); - const sw = Math.round(w), sh = Math.round(h); - const cropC = document.createElement("canvas"); const c = S.cropConstraint; - const srcX = Math.max(0, sx); - const srcY = Math.max(0, sy); - const srcRight = Math.min(S.imgW, sx + sw); - const srcBottom = Math.min(S.imgH, sy + sh); - const srcW = Math.max(0, srcRight - srcX); - const srcH = Math.max(0, srcBottom - srcY); - const dstX = srcX - sx; - const dstY = srcY - sy; - if (c.type === "size" && c.sizeW > 0 && c.sizeH > 0) { - cropC.width = c.sizeW; - cropC.height = c.sizeH; - const cctx = cropC.getContext("2d"); - const scaleX2 = c.sizeW / sw; - const scaleY2 = c.sizeH / sh; - if (srcW > 0 && srcH > 0) { - cctx.drawImage( - tmp, - srcX, - srcY, - srcW, - srcH, - dstX * scaleX2, - dstY * scaleY2, - srcW * scaleX2, - srcH * scaleY2 - ); - } - S.imgW = c.sizeW; - S.imgH = c.sizeH; - } else { - cropC.width = sw; - cropC.height = sh; - const cctx = cropC.getContext("2d"); - if (srcW > 0 && srcH > 0) { - cctx.drawImage(tmp, srcX, srcY, srcW, srcH, dstX, dstY, srcW, srcH); - } - S.imgW = sw; - S.imgH = sh; - } + const sx = Math.round(x), sy = Math.round(y); + const sw = Math.max(1, Math.round(w)), sh = Math.max(1, Math.round(h)); const isSize = c.type === "size" && c.sizeW > 0 && c.sizeH > 0; - const scaleX = isSize ? c.sizeW / sw : 1; - const scaleY = isSize ? c.sizeH / sh : 1; + const nw = isSize ? Math.max(1, Math.round(c.sizeW)) : sw; + const nh = isSize ? Math.max(1, Math.round(c.sizeH)) : sh; + if (nw === S.imgW && nh === S.imgH && sx === 0 && sy === 0) { + cancelCrop(); + return; + } + const oldW = S.imgW, oldH = S.imgH; + const scaleX = nw / sw, scaleY = nh / sh; + const srcX = Math.max(0, sx), srcY = Math.max(0, sy); + const srcW = Math.max(0, Math.min(oldW, sx + sw) - srcX); + const srcH = Math.max(0, Math.min(oldH, sy + sh) - srcY); + const dstX = (srcX - sx) * scaleX, dstY = (srcY - sy) * scaleY; + const dstW = srcW * scaleX, dstH = srcH * scaleY; + saveSnapshot("裁剪"); + disposeSelection(); + const staged = S.layers.map((layer) => { + const tmp = document.createElement("canvas"); + tmp.width = nw; + tmp.height = nh; + if (srcW > 0 && srcH > 0) { + try { + tmp.getContext("2d").drawImage(layer.canvas, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH); + } catch (e) { + } + } + return tmp; + }); + resizeWorkspace(nw, nh); + S.layers.forEach((layer, i) => { + const tmp = staged[i]; + try { + layer.ctx.drawImage(tmp, 0, 0); + } catch (e) { + } + tmp.width = 0; + tmp.height = 0; + layer.x = 0; + layer.y = 0; + layer.w = nw; + layer.h = nh; + layer.rotation = 0; + layer.transformable = false; + layer.image = null; + layer.sourceCanvas = null; + layer._srcBox = null; + layer._bounds = void 0; + }); S.textLayers = S.textLayers.map((t) => ({ ...t, x: (t.x - sx) * scaleX, @@ -5041,15 +5215,13 @@ var __IWB_ANNOTATE_MANIFEST__ = { S.selectedLayerId = null; S.bitmapDrag = null; S.zoom = 1; - setupCanvas(cropC); - S.history = []; - S.redoStack = []; S.cropRect = null; + S.cropHandle = null; S.cropMoving = false; S.moveStart = null; - clearOverlay(); updateCropInfo(); if (S.renderAll) S.renderAll(); + toast("已裁剪为 " + nw + "×" + nh + "(Ctrl+Z 可撤销)", "success"); } function cancelCrop() { S.cropRect = null; @@ -5193,6 +5365,12 @@ var __IWB_ANNOTATE_MANIFEST__ = { } } function restoreState(state) { + if (state.imgW && state.imgH && (state.imgW !== S.imgW || state.imgH !== S.imgH)) { + purgeVectorCanvases(); + for (const l of S.layers) releaseLayer(l); + S.layers = []; + resizeWorkspace(state.imgW, state.imgH); + } purgeVectorCanvases(); for (const l of S.layers) l._bounds = void 0; const snaps = state.bitmaps || []; @@ -5734,6 +5912,8 @@ var __IWB_ANNOTATE_MANIFEST__ = { S.prevTool = null; S.pickerComposite = null; S.rectFill = false; + S.shapeLineWidth = 3; + S.textSize = 32; S.cropConstraint = { type: "free", ratio: 0, sizeW: 0, sizeH: 0 }; S.textLayers = []; S.selectedTextId = null; @@ -5894,12 +6074,20 @@ var __IWB_ANNOTATE_MANIFEST__ = { tool: S.tool, doc: { w: S.imgW, h: S.imgH }, layers: S.layers.map((l) => ({ id: l.id, name: l.name, z: l.z, locked: !!l.locked, visible: l.visible !== false })), - shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type })), + shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill })), texts: S.textLayers.map((t) => ({ id: t.id, text: t.text })), selectedShapeId: S.selectedShapeId, selectedTextId: S.selectedTextId, activeLayerId: S.activeLayerId, selection: selectionInfo(), + toolOptions: { + brushSize: S.brushSize, + brushHardness: S.brushHardness, + brushOpacity: S.brushOpacity, + shapeLineWidth: S.shapeLineWidth, + textSize: S.textSize, + rectFill: S.rectFill + }, history: S.history.length, historyLabels: S.history.map((s) => s.__label || ""), redo: S.redoStack.length, @@ -5925,7 +6113,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-editor-tools .iwb-editor-action[data-action="redo"] { right: 118px; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"] { right: 82px; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] { right: 46px; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-divider {\n width: 24px;\n height: 1px;\n margin: 4px 0;\n}\n\n.iwb-editor-title {\n color: #cdd6f4;\n font-size: 14px;\n font-weight: 600;\n white-space: nowrap;\n}\n\n.iwb-editor-tools {\n display: flex;\n align-items: center;\n gap: 4px;\n}\n\n.iwb-editor-tool, .iwb-editor-action {\n background: #313244;\n border: none;\n border-radius: 6px;\n color: #cdd6f4;\n width: 32px; height: 32px;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 15px;\n transition: background 0.15s, transform 0.1s;\n}\n.iwb-editor-tool:hover, .iwb-editor-action:hover { background: #45475a; transform: scale(1.08); }\n.iwb-editor-tool.active { background: #e8a735; color: #1e1e2e; }\n.iwb-editor-tool svg, .iwb-editor-action svg { display: block; }\n.iwb-editor-layer-btn svg { display: block; }\n\n/* 复原按钮:绿色高亮,与撤销/重做/清空区分 */\n.iwb-editor-action-restore { background: #1a7f37; color: #fff; }\n.iwb-editor-action-restore:hover { background: #15803d !important; }\n\n.iwb-editor-divider {\n width: 1px; height: 20px;\n background: #45475a;\n margin: 0 4px;\n}\n\n.iwb-editor-params {\n display: flex;\n align-items: center;\n gap: 10px;\n margin-left: 12px;\n justify-content: flex-start;\n min-width: 0;\n flex: 1 1 auto;\n flex-wrap: wrap;\n}\n.iwb-editor-params .iwb-editor-zoom { margin-left: auto; order: 20; }\n.iwb-editor-top-colors { display: none; }\n\n.iwb-editor-colors { display: flex; gap: 4px; }\n.iwb-editor-color {\n width: 20px; height: 20px;\n border-radius: 50%;\n cursor: pointer;\n border: 2px solid transparent;\n transition: transform 0.1s, border-color 0.15s;\n}\n.iwb-editor-color:hover { transform: scale(1.2); }\n.iwb-editor-color.active { border-color: #fff; transform: scale(1.15); }\n\n.iwb-editor-brush-label {\n display: flex;\n align-items: center;\n gap: 6px;\n color: #a6adc8;\n font-size: 12px;\n}\n.iwb-editor-brush-size { width: 80px; cursor: pointer; }\n.iwb-editor-brush-val { color: #e8a735; font-weight: 600; min-width: 16px; }\n\n/* 笔刷/橡皮大小精确数值输入框 */\n.iwb-editor-brush-num,\n.iwb-editor-eraser-num {\n width: 44px;\n padding: 2px 3px;\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 5px;\n color: #e8a735;\n font-weight: 600;\n font-size: 11px;\n font-family: inherit;\n text-align: center;\n}\n.iwb-editor-brush-num:focus,\n.iwb-editor-eraser-num:focus {\n outline: none;\n border-color: #e8a735;\n background: #1e1e2e;\n}\n.iwb-editor-brush-num::-webkit-outer-spin-button,\n.iwb-editor-brush-num::-webkit-inner-spin-button,\n.iwb-editor-eraser-num::-webkit-outer-spin-button,\n.iwb-editor-eraser-num::-webkit-inner-spin-button {\n -webkit-appearance: none; /* 去掉上下箭头,窄输入框更干净 */\n margin: 0;\n}\n\n/* 实心矩形开关 */\n.iwb-editor-fill-btn {\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 6px;\n color: #a6adc8;\n padding: 4px 10px;\n font-size: 12px;\n cursor: pointer;\n transition: background 0.15s, color 0.15s, border-color 0.15s;\n white-space: nowrap;\n}\n.iwb-editor-fill-btn:hover { background: #45475a; }\n.iwb-editor-fill-btn.active {\n background: #e8a735;\n border-color: #e8a735;\n color: #1e1e2e;\n font-weight: 600;\n}\n\n/* 画笔参数组(硬度/透明度,画笔与橡皮工具共用) */\n.iwb-editor-brush-group {\n display: flex;\n align-items: center;\n gap: 10px;\n}\n.iwb-editor-layer-group {\n display: flex;\n align-items: center;\n gap: 3px;\n}\n.iwb-editor-layer-btn {\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 6px;\n color: #a6adc8;\n width: 26px;\n height: 26px;\n font-size: 14px;\n line-height: 1;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;\n}\n.iwb-editor-layer-btn:hover:not(:disabled) { background: #45475a; color: #cdd6f4; }\n.iwb-editor-layer-btn:disabled {\n opacity: 0.35;\n cursor: not-allowed;\n}\n\n/* 缩放控件 */\n.iwb-editor-zoom {\n display: flex;\n align-items: center;\n gap: 2px;\n background: #313244;\n border-radius: 6px;\n padding: 2px;\n}\n.iwb-editor-zoom-btn {\n background: transparent;\n border: none;\n color: #cdd6f4;\n width: 26px;\n height: 26px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n line-height: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.15s;\n}\n.iwb-editor-zoom-btn:hover { background: #45475a; }\n.iwb-editor-zoom-btn:active { transform: scale(0.94); }\n.iwb-editor-zoom-fit { font-size: 12px; width: auto; padding: 0 8px; }\n.iwb-editor-zoom-val {\n color: #e8a735;\n font-size: 12px;\n font-weight: 600;\n min-width: 46px;\n text-align: center;\n font-variant-numeric: tabular-nums;\n user-select: none;\n}\n\n/* 底部操作提示 */\n.iwb-editor-zoom-hint {\n position: absolute;\n bottom: 8px;\n right: 14px;\n color: #7f849c;\n font-size: 11px;\n background: rgba(24, 24, 37, 0.85);\n padding: 3px 10px;\n border-radius: 4px;\n pointer-events: none;\n z-index: 5;\n}\n\n.iwb-editor-canvas-wrap {\n position: relative;\n background: #11111b;\n flex: 1 1 auto;\n min-height: 0;\n max-width: 100%;\n max-height: 100%;\n overflow: hidden; /* 裁剪框允许显示在图片边界外;编辑区仍由模态层裁切 */\n padding: 12px;\n}\n\n.iwb-editor-canvas-stack {\n position: absolute;\n left: 0;\n top: 0;\n display: block;\n width: 0;\n height: 0;\n /* 仅图片工作区显示透明棋盘格,外围裁剪工作区保持纯色。 */\n background-color: #d6d6d6;\n background-image:\n linear-gradient(45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(-45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, #b8b8b8 75%),\n linear-gradient(-45deg, transparent 75%, #b8b8b8 75%);\n background-size: 20px 20px;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0;\n}\n\n.iwb-editor-base, .iwb-editor-draw, .iwb-editor-text, .iwb-editor-crop-overlay {\n display: block;\n}\n/* 位图图层 canvas(动态创建) */\n.iwb-editor-layer-canvas {\n display: block;\n position: absolute;\n top: 0; left: 0;\n}\n.iwb-editor-base {\n background: #fff;\n /* 棋盘格透明背景示意 */\n background-image:\n linear-gradient(45deg, #e0e0e0 25%, transparent 25%),\n linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, #e0e0e0 75%),\n linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);\n background-size: 20px 20px;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0px;\n}\n.iwb-editor-draw {\n position: absolute;\n top: 0; left: 0;\n cursor: crosshair;\n}\n\n/* 笔划预览层:一笔进行中显示(draw 之上、text 之下),事件穿透 */\n.iwb-editor-stroke {\n position: absolute;\n top: 0; left: 0;\n pointer-events: none;\n display: none;\n}\n\n.iwb-editor-brush-hardness { width: 70px; cursor: pointer; }\n.iwb-editor-brush-hardness-val { color: #e8a735; font-weight: 600; min-width: 20px; display: inline-block; text-align: right; }\n.iwb-editor-brush-opacity { width: 70px; cursor: pointer; }\n.iwb-editor-brush-opacity-val { color: #e8a735; font-weight: 600; min-width: 34px; display: inline-block; text-align: right; }\n\n/* 自定义颜色(原生取色器伪装成圆形色板) */\n.iwb-editor-color-custom {\n position: relative;\n overflow: hidden;\n border: 2px dashed #a6adc8;\n}\n.iwb-editor-color-custom.active { border-color: #fff; border-style: solid; transform: scale(1.15); }\n.iwb-editor-color-custom input[type="color"] {\n position: absolute;\n inset: -6px;\n width: calc(100% + 12px);\n height: calc(100% + 12px);\n padding: 0;\n border: none;\n cursor: pointer;\n background: conic-gradient(#ff4444, #ffaa00, #44dd44, #4488ff, #aa44ff, #ff4444);\n}\n.iwb-editor-color-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }\n.iwb-editor-color-custom input[type="color"]::-webkit-color-swatch { border: none; }\n\n/* 吸管悬停预览浮窗 */\n.iwb-editor-picker-tip {\n position: fixed;\n z-index: 2147483000;\n display: none;\n align-items: center;\n gap: 6px;\n background: rgba(30, 30, 46, 0.95);\n border: 1px solid rgba(255, 255, 255, 0.14);\n border-radius: 6px;\n padding: 4px 8px;\n pointer-events: none;\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n}\n.iwb-editor-picker-chip {\n width: 16px;\n height: 16px;\n border-radius: 4px;\n background: transparent;\n}\n.iwb-editor-picker-hex {\n color: #cdd6f4;\n font-size: 12px;\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n}\n\n/* 文字图层:独立 canvas,事件穿透到下层 drawCanvas */\n.iwb-editor-text {\n position: absolute;\n top: 0; left: 0;\n pointer-events: none;\n}\n\n/* 裁剪覆盖层:遮罩/选区框/手柄画在这层,不污染标注层 */\n.iwb-editor-crop-overlay {\n position: absolute;\n top: 0; left: 0;\n pointer-events: none;\n}\n\n/* 文字输入框 */\n.iwb-editor-text-input {\n position: absolute;\n display: none;\n padding: 4px 8px;\n border: 2px solid #4488ff;\n border-radius: 4px;\n font-size: 14px;\n background: rgba(255, 255, 255, 0.95);\n color: #1e1e2e;\n z-index: 10;\n min-width: 120px;\n}\n.iwb-editor-text-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(68, 136, 255, 0.3); }\n\n/* 裁剪确认栏(含约束控件) */\n.iwb-editor-crop-bar {\n position: absolute;\n bottom: 16px;\n left: 50%;\n transform: translateX(-50%);\n display: none;\n gap: 8px;\n z-index: 10;\n align-items: center;\n background: rgba(24, 24, 37, 0.92);\n border: 1px solid #313244;\n border-radius: 8px;\n padding: 6px 10px;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);\n flex-wrap: wrap;\n max-width: 90%;\n justify-content: center;\n}\n\n.iwb-editor-constraint-group {\n display: flex;\n align-items: center;\n gap: 4px;\n}\n\n.iwb-editor-constraint-label {\n color: #7f849c;\n font-size: 11px;\n margin-right: 2px;\n white-space: nowrap;\n}\n\n.iwb-editor-constraint-btn {\n background: #313244;\n border: none;\n border-radius: 4px;\n color: #cdd6f4;\n padding: 3px 8px;\n font-size: 12px;\n cursor: pointer;\n transition: background 0.15s, transform 0.1s;\n white-space: nowrap;\n}\n.iwb-editor-constraint-btn:hover { background: #45475a; transform: scale(1.05); }\n.iwb-editor-constraint-btn.active { background: #4488ff; color: #fff; }\n\n.iwb-editor-constraint-sep {\n width: 1px;\n height: 20px;\n background: #45475a;\n}\n\n.iwb-editor-size-input {\n width: 50px;\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 4px;\n color: #cdd6f4;\n padding: 3px 6px;\n font-size: 12px;\n text-align: center;\n}\n.iwb-editor-size-input:focus { outline: none; border-color: #4488ff; }\n.iwb-editor-size-input::-webkit-inner-spin-button { -webkit-appearance: none; }\n\n.iwb-editor-size-x { color: #7f849c; font-size: 12px; }\n\n.iwb-editor-size-apply {\n background: #313244;\n border: 1px solid #4488ff;\n color: #4488ff;\n border-radius: 4px;\n padding: 3px 8px;\n font-size: 12px;\n cursor: pointer;\n transition: background 0.15s;\n}\n.iwb-editor-size-apply:hover { background: #4488ff; color: #fff; }\n\n.iwb-editor-crop-info {\n color: #e8a735;\n font-size: 12px;\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n min-width: 60px;\n text-align: center;\n}\n\n.iwb-editor-crop-confirm, .iwb-editor-crop-cancel {\n padding: 6px 16px;\n border: none;\n border-radius: 6px;\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n}\n.iwb-editor-crop-confirm { background: #1a7f37; color: #fff; }\n.iwb-editor-crop-confirm:hover { background: #15803d; }\n.iwb-editor-crop-cancel { background: #cf222e; color: #fff; }\n.iwb-editor-crop-cancel:hover { background: #b91c1c; }\n\n/* 底部 */\n.iwb-editor-footer {\n display: flex;\n justify-content: flex-end;\n gap: 8px;\n padding: 12px 16px;\n background: #181825;\n border-top: 1px solid #313244;\n}\n\n.iwb-editor-btn {\n padding: 8px 20px;\n border: none;\n border-radius: 6px;\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n transition: background 0.15s, transform 0.1s;\n}\n.iwb-editor-btn:hover { transform: scale(1.03); }\n.iwb-editor-btn-cancel { background: #45475a; color: #cdd6f4; }\n.iwb-editor-btn-cancel:hover { background: #585b70; }\n.iwb-editor-btn-new { background: #4488ff; color: #fff; }\n.iwb-editor-btn-new:hover { background: #3578f0; }\n.iwb-editor-btn-replace { background: #e8a735; color: #1e1e2e; }\n.iwb-editor-btn-replace:hover { background: #d49628; }\n\n/* ==================== 图层面板 ==================== */\n\n.iwb-editor-layer-panel {\n width: 290px;\n min-width: 290px;\n background: #181825;\n border-left: 1px solid #313244;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n\n.iwb-editor-layer-panel-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 10px 12px;\n border-bottom: 1px solid #313244;\n}\n\n.iwb-editor-layer-panel-title {\n color: #cdd6f4;\n font-size: 13px;\n font-weight: 600;\n}\n\n.iwb-editor-layer-add-group {\n display: flex;\n gap: 4px;\n}\n\n.iwb-editor-layer-add-btn {\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 6px;\n color: #cdd6f4;\n width: 26px;\n height: 26px;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.15s;\n}\n.iwb-editor-layer-add-btn:hover { background: #45475a; color: #e8a735; }\n.iwb-editor-layer-add-btn svg { display: block; }\n\n.iwb-editor-layer-list {\n flex: 1 1 auto;\n overflow-y: auto;\n padding: 4px;\n}\n\n/* 图层项 */\n.iwb-layer-item {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 6px 8px;\n border-radius: 6px;\n cursor: pointer;\n transition: background 0.12s;\n margin-bottom: 2px;\n}\n.iwb-layer-item:hover { background: #313244; }\n.iwb-layer-item.active {\n background: #313244;\n box-shadow: inset 2px 0 0 #e8a735;\n}\n.iwb-layer-item.hidden { opacity: 0.5; }\n.iwb-layer-item[draggable="true"] { cursor: grab; }\n.iwb-layer-item.dragging { opacity: 0.45; }\n.iwb-layer-item.drop-target { outline: 1px dashed #e8a735; background: rgba(232, 167, 53, 0.16); }\n/* 画笔/橡皮作用目标:与「选中」分离,避免出现两个图层同时高亮 */\n.iwb-layer-paint { flex: 0 0 auto; color: #a6adc8; font-size: 11px; opacity: 0.85; }\n.iwb-layer-color { width: 22px; height: 22px; padding: 0; border: 1px solid #45475a; border-radius: 50%; background: transparent; cursor: pointer; flex: 0 0 auto; }\n.iwb-layer-width { width: 42px; height: 22px; padding: 2px 3px; border: 1px solid #45475a; border-radius: 4px; background: #1e1e2e; color: #e8a735; font-size: 11px; text-align: center; flex: 0 0 auto; }\n.iwb-layer-width:focus { outline: none; border-color: #e8a735; }\n\n.iwb-layer-vis {\n background: none;\n border: none;\n color: #a6adc8;\n cursor: pointer;\n font-size: 13px;\n width: 20px;\n height: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n transition: background 0.12s;\n}\n.iwb-layer-vis:hover { background: #45475a; }\n\n.iwb-layer-icon {\n font-size: 13px;\n width: 18px;\n text-align: center;\n flex-shrink: 0;\n}\n\n.iwb-layer-name {\n color: #cdd6f4;\n font-size: 12px;\n flex: 1 1 auto;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n min-width: 0;\n}\n\n.iwb-layer-lock {\n background: none;\n border: none;\n color: #7f849c;\n cursor: pointer;\n width: 20px;\n height: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n transition: background 0.12s, color 0.12s;\n flex-shrink: 0;\n}\n.iwb-layer-lock:hover, .iwb-layer-lock.active { background: #45475a; color: #e8a735; }\n\n.iwb-layer-del {\n background: none;\n border: none;\n color: #585b70;\n cursor: pointer;\n font-size: 12px;\n width: 18px;\n height: 18px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n transition: background 0.12s, color 0.12s;\n flex-shrink: 0;\n}\n.iwb-layer-del:hover { background: #cf222e; color: #fff; }\n\n/* SVG 图标尺寸 */\n.iwb-layer-vis svg { display: block; }\n.iwb-layer-icon svg { display: block; }\n.iwb-layer-lock svg { display: block; }\n.iwb-layer-del svg { display: block; }\n\n/* 独立 PS 风格颜色面板 */\n.iwb-editor-color-panel { padding: 12px; border-bottom: 1px solid #313244; background: #202033; }\n.iwb-editor-color-panel-title { color: #cdd6f4; font-size: 12px; font-weight: 600; margin-bottom: 10px; }\n.iwb-editor-color-panel-main { display: flex; align-items: center; gap: 10px; }\n.iwb-editor-color-current { width: 52px; height: 52px; border: 2px solid #cdd6f4; border-radius: 6px; overflow: hidden; display: block; background: #ff4444; }\n.iwb-editor-color-panel-input { width: 100%; height: 100%; padding: 0; border: 0; cursor: pointer; opacity: 0; }\n.iwb-editor-color-panel-values { min-width: 0; flex: 1; }\n.iwb-editor-color-hex { color: #cdd6f4; font: 600 12px monospace; display: block; margin-bottom: 8px; }\n.iwb-editor-color-swatches { display: flex; flex-wrap: wrap; gap: 6px; }\n.iwb-editor-color-panel-swatch { width: 20px; height: 20px; border: 1px solid #585b70; border-radius: 4px; cursor: pointer; }\n.iwb-editor-color-panel-swatch:hover { transform: scale(1.12); border-color: #fff; }\n.iwb-editor-panel-width { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: #a6adc8; font-size: 11px; }\n.iwb-editor-panel-width-range { flex: 1; min-width: 60px; }\n.iwb-editor-panel-width-num { width: 42px; padding: 3px; background: #313244; color: #e8a735; border: 1px solid #45475a; border-radius: 4px; text-align: center; }\n.iwb-layer-color, .iwb-layer-width { display: none !important; }\n\n/* 顶部独立操作区,避免操作按钮被竖向工具栏裁切 */\n.iwb-editor-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; flex: 0 0 auto; }\n.iwb-editor-actions .iwb-editor-action { position: static !important; }\n.iwb-editor-actions .iwb-editor-action-restore { width: auto; padding: 0 9px; font-size: 12px; }\n\n/* 原图 canvas 只负责绘制像素,透明处透出 stack 的棋盘格。 */\n.iwb-editor-base { background: transparent !important; background-image: none !important; }\n\n/* 透明区域使用 Photoshop 风格的灰色棋盘格,覆盖整个实际图片区域。 */\n.iwb-editor-canvas-stack {\n background-color: #d6d6d6 !important;\n background-image:\n linear-gradient(45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(-45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, #b8b8b8 75%),\n linear-gradient(-45deg, transparent 75%, #b8b8b8 75%) !important;\n background-size: 20px 20px !important;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0 !important;\n}\n.iwb-editor-base { background: transparent !important; background-image: none !important; }\n\n/* 顶部参数区必须保持可见且可交互,避免被侧栏定位层覆盖。 */\n.iwb-editor-header { position: relative; min-height: 56px; overflow: visible; }\n.iwb-editor-params { position: relative; z-index: 30; overflow: visible; pointer-events: auto; }\n.iwb-editor-params input, .iwb-editor-params button, .iwb-editor-params label { pointer-events: auto; }\n.iwb-editor-brush-size, .iwb-editor-brush-hardness, .iwb-editor-brush-opacity { min-width: 70px; accent-color: #e8a735; }\n.iwb-editor-brush-num, .iwb-editor-eraser-num { pointer-events: auto; }\n\n/* canvas 的透明像素必须透出 stack 棋盘格,不能被黑色工作区遮住。 */\n.iwb-editor-canvas-stack { isolation: isolate; }\n.iwb-editor-layer-canvas, .iwb-editor-text, .iwb-editor-stroke, .iwb-editor-crop-overlay { background: transparent !important; }\n\n/* 透明棋盘格只覆盖原图的显示矩形,外围裁剪扩展区保持纯色。 */\n.iwb-editor-canvas-stack { background: #11111b !important; background-image: none !important; }\n.iwb-editor-transparency-grid { position: absolute; z-index: 0; pointer-events: none; background-color: #d6d6d6; background-image: linear-gradient(45deg, #b8b8b8 25%, transparent 25%), linear-gradient(-45deg, #b8b8b8 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #b8b8b8 75%), linear-gradient(-45deg, transparent 75%, #b8b8b8 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }\n.iwb-editor-layer-canvas, .iwb-editor-stroke, .iwb-editor-text { z-index: 1; }\n.iwb-editor-crop-overlay { z-index: 10; }\n\n/* 画布扩展区不得盖过编辑器外围,图片区域由透明层单独标识。 */\n.iwb-editor-canvas-stack { overflow: visible; max-width: 100%; max-height: 100%; background: #11111b !important; background-image: none !important; }\n.iwb-editor-transparency-grid { z-index: 0; overflow: hidden; }\n.iwb-editor-layer-canvas { z-index: 1; }\n.iwb-editor-stroke { z-index: 4; }\n.iwb-editor-text { z-index: 5; }\n.iwb-editor-crop-overlay { z-index: 10; }\n\n/* 导出操作与缩放同处顶栏,缩放独立靠右。 */\n.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }\n.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }\n.iwb-editor-footer { display: none !important; }\n.iwb-layer-color, .iwb-layer-width { display: none !important; }\n\n.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }\n.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }\n.iwb-editor-footer { display: none !important; }\n.iwb-layer-color, .iwb-layer-width { display: none !important; }\n\n/* 顶部七个操作按钮统一文本按钮样式,自适应中文宽度。 */\n.iwb-editor-actions { gap: 6px; }\n.iwb-editor-actions .iwb-editor-action { width: auto; min-width: 72px; height: 32px; padding: 0 12px; gap: 5px; font-size: 12px; font-weight: 500; white-space: nowrap; }\n.iwb-editor-actions .iwb-editor-action svg { width: 14px; height: 14px; flex: 0 0 auto; }\n.iwb-editor-export-actions .iwb-editor-btn { min-width: 72px; white-space: nowrap; }\n\n/* 顶部操作按钮统一为纯文本,图标隐藏并保持一致宽度。 */\n.iwb-editor-actions .iwb-editor-action svg { display: none !important; }\n.iwb-editor-actions .iwb-editor-action { min-width: 76px; width: 76px; justify-content: center; background: #3b3d52; color: #cdd6f4; }\n.iwb-editor-actions .iwb-editor-action:hover { background: #50536b; }\n.iwb-editor-actions .iwb-editor-action-restore { background: #3b3d52; color: #cdd6f4; }\n.iwb-editor-actions .iwb-editor-action-restore:hover { background: #50536b !important; }\n\n.iwb-editor-actions .iwb-editor-action svg { display: none !important; }\n.iwb-editor-actions .iwb-editor-action { min-width: 76px; width: 76px; justify-content: center; background: #3b3d52; color: #cdd6f4; }\n.iwb-editor-actions .iwb-editor-action:hover, .iwb-editor-actions .iwb-editor-action-restore:hover { background: #50536b !important; }\n\n.iwb-editor-actions .iwb-editor-action { width: auto; min-width: 76px; padding: 0 12px; gap: 5px; }\n.iwb-editor-actions .iwb-editor-action span { display: inline-block; }\n\n.iwb-editor-actions { margin-left: 12px; }\n.iwb-editor-actions .iwb-editor-btn { width: auto; min-width: 76px; height: 32px; padding: 0 12px; font-size: 12px; white-space: nowrap; }\n.iwb-editor-actions .iwb-editor-action { width: auto; min-width: 76px; }\n\n.iwb-editor-actions .iwb-editor-action { min-width: 52px; width: auto; padding: 0 10px; font-size: 12px; }\n.iwb-editor-brush-presets { display: flex; align-items: center; gap: 7px; margin-left: 4px; }\n.iwb-editor-brush-preset { display: inline-flex; align-items: center; gap: 3px; padding: 2px 3px; border: 0; background: transparent; color: #a6adc8; cursor: pointer; font-size: 11px; }\n.iwb-editor-brush-preset i { display: block; width: 12px; height: 12px; border-radius: 50%; background: #e8a735; border: 1px solid #f6d38a; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 16px; height: 16px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 20px; height: 20px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 24px; height: 24px; }\n.iwb-editor-brush-preset:hover, .iwb-editor-brush-preset.active { color: #fff; }\n\n/* 紧凑顶栏:操作按钮与描边快捷点仅保留必要视觉信息。 */\n.iwb-editor-actions .iwb-editor-action { width: 28px; min-width: 28px; height: 28px; padding: 0; }\n.iwb-editor-actions .iwb-editor-action svg { display: block !important; width: 14px; height: 14px; }\n.iwb-editor-brush-presets { gap: 5px; margin-left: 2px; }\n.iwb-editor-brush-preset { width: 24px; height: 24px; padding: 0; justify-content: center; }\n.iwb-editor-brush-preset i { width: 5px; height: 5px; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 8px; height: 8px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 12px; height: 12px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 16px; height: 16px; }\n\n/* 图层栏内嵌调色板:颜色直接点击应用,不弹出系统取色器。 */\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-color-current { width: 42px; height: 42px; flex: 0 0 42px; cursor: default; }\n.iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(7, 20px); gap: 5px; }\n.iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; }\n\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-color-current { width: 42px; height: 42px; flex: 0 0 42px; cursor: default; }\n.iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(7, 20px); gap: 5px; }\n.iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; }\n\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-palette-current { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-palette-current .iwb-editor-color-current { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-hex { margin: 0; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }\n\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-palette-current { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-palette-current .iwb-editor-color-current { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-hex { margin: 0; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }\n\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { width: 42px; height: 28px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { width: 42px; height: 28px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { width: 42px; height: 28px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n\n.iwb-editor-color-panel { padding: 9px; }\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { display: block; width: 44px; height: 30px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }\n\n.iwb-editor-color-picker2 { display: flex; gap: 8px; height: 118px; }\n.iwb-color-sv { position: relative; flex: 1; background: linear-gradient(to top,#000,transparent),linear-gradient(to right,#fff,rgba(255,255,255,0)); background-color: #f44; border-radius: 4px; }\n.iwb-color-hue { width: 18px; border-radius: 4px; background: linear-gradient(to bottom,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00); }\n.iwb-editor-color-fields { display: flex; gap: 6px; margin: 8px 0; }\n.iwb-editor-color-hex-input { width: 72px; background:#313244; color:#cdd6f4; border:1px solid #585b70; padding:4px; }\n.iwb-editor-color-panel-input { width: 32px; height: 26px; opacity: 1; padding: 0; }\n\n.iwb-color-sv span, .iwb-color-hue span { position: absolute; width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #222; transform: translate(-50%, -50%); pointer-events: none; }\n.iwb-color-sv span { left: 100%; top: 0; }\n.iwb-color-hue span { left: 50%; top: 0; }\n\n.iwb-compress-btn { color: #16a34a !important; font-size: 11px; font-weight: 700; }\n\n/* 新版浮动气泡栏内的工具按钮 */\n.iwb-node-floatbar .iwb-compress-btn { font-size: 11px; font-weight: 700; }\n.iwb-node-floatbar .iwb-cutout-btn.processing,\n.iwb-node-floatbar .iwb-whitebg-btn.processing,\n.iwb-node-floatbar .iwb-compress-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n\n/* 调色板:吸色按钮(替代原来的弹出式取色器) */\n.iwb-editor-color-eye { width: 26px; height: 26px; border: 1px solid #585b70; border-radius: 4px; background: #313244; color: #cdd6f4; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }\n.iwb-editor-color-eye:hover { border-color: #e8a735; color: #e8a735; }\n\n/* 矢量对象独立画布:与位图图层统一参与 z 排序 */\n.iwb-editor-vec-canvas { position: absolute; top: 0; left: 0; z-index: 1; background: transparent !important; }\n\n/* 空白画布创建菜单 */\n.iwb-blank-menu { position: fixed; width: 242px; background: #fff; border: 1px solid #d0d7de; border-radius: 12px; box-shadow: 0 12px 32px rgba(15,23,42,.2); padding: 10px; z-index: 2147483000; font-size: 12px; color: #1f2328; }\n.iwb-blank-menu .iwb-blank-title { font-weight: 700; font-size: 12px; margin-bottom: 8px; }\n.iwb-blank-menu .iwb-blank-bg, .iwb-blank-menu .iwb-blank-res { display: flex; align-items: center; gap: 5px; margin-bottom: 7px; }\n.iwb-blank-menu .iwb-blank-bg span, .iwb-blank-menu .iwb-blank-res span { color: #656d76; min-width: 26px; }\n.iwb-blank-menu button { border: 1px solid #d0d7de; background: #f6f8fa; color: #1f2328; border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 11px; }\n.iwb-blank-menu button:hover { background: #eff2f4; }\n.iwb-blank-menu button.on { background: #0ea5e9; border-color: #0ea5e9; color: #fff; }\n.iwb-blank-menu .iwb-blank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }\n.iwb-blank-menu .iwb-blank-grid button { display: flex; flex-direction: column; gap: 1px; align-items: center; padding: 5px 4px; }\n.iwb-blank-menu .iwb-blank-grid b { font-weight: 600; }\n.iwb-blank-menu .iwb-blank-grid i { font-style: normal; color: #656d76; font-size: 10px; }\n\n/* 空参考图节点:常驻“空白画布”按钮(位于节点顶部中央) */\n.iwb-blank-inline-btn { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 6; display: inline-flex; align-items: center; gap: 5px; background: #fff; border: 1px solid #d0d7de; border-radius: 14px; padding: 4px 11px; color: #0ea5e9; font-size: 11px; font-weight: 600; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }\n.iwb-blank-inline-btn:hover { background: #f0f9ff; border-color: #0ea5e9; }\n.iwb-blank-inline-btn svg { width: 13px; height: 13px; }\n\n/* ============ UI 布局重构(参照 excalidraw) ============ */\n/* 顶部:功能按钮在左,工具栏横排整行、按快捷键排序并带数字角标 */\n.iwb-editor-header { flex-wrap: wrap; }\n.iwb-editor-header > .iwb-editor-title { order: 1; }\n.iwb-editor-header > .iwb-editor-actions { order: 2; }\n.iwb-editor-header > .iwb-editor-tools {\n position: static;\n order: 3;\n flex: 1 1 100%;\n width: auto;\n left: auto;\n top: auto;\n margin-top: 8px;\n flex-direction: row;\n justify-content: center;\n padding: 6px 10px;\n border-radius: 10px;\n}\n.iwb-editor-tool { position: relative; }\n.iwb-tool-key {\n position: absolute;\n right: -3px;\n bottom: -3px;\n font-size: 8px;\n line-height: 1;\n background: #45475a;\n color: #cdd6f4;\n padding: 1px 3px;\n border-radius: 3px;\n pointer-events: none;\n font-style: normal;\n font-weight: 600;\n}\n.iwb-editor-tool.active .iwb-tool-key { background: #1e1e2e; color: #e8a735; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-divider { width: 1px; height: 22px; margin: 0 6px; }\n\n/* 左侧:工具参数设定栏(缩放/实心/图层/描边/硬度/透明度) */\n.iwb-editor-params {\n width: 216px;\n min-width: 216px;\n flex: 0 0 216px;\n flex-direction: column;\n align-items: stretch;\n gap: 12px;\n margin-left: 0;\n padding: 14px 12px;\n background: #181825;\n border-right: 1px solid #313244;\n overflow-y: auto;\n}\n.iwb-editor-params .iwb-editor-zoom { margin-left: 0; order: 0; }\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-val { min-width: 52px; text-align: center; }\n.iwb-editor-params .iwb-editor-layer-group { flex-wrap: wrap; justify-content: flex-start; }\n.iwb-editor-params .iwb-editor-brush-label { width: 100%; }\n.iwb-editor-params .iwb-editor-brush-presets { justify-content: flex-start; }\n.iwb-editor-params .iwb-editor-fill-btn { align-self: stretch; }\n.iwb-editor-main { display: flex; flex-direction: row; }\n\n/* ======== 布局重构 v2(按用户 6 点) ======== */\n.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }\n\n/* 顶部一行:标题 + 工具栏(含数字角标) + 撤销重做清空还原 */\n.iwb-editor-header { flex-wrap: nowrap; align-items: center; }\n.iwb-editor-header > .iwb-editor-title { order: 0; }\n.iwb-editor-header > .iwb-editor-tools {\n position: static; order: 1; flex: 1 1 auto; flex-basis: auto;\n margin-top: 0; width: auto; left: auto; top: auto;\n flex-direction: row; justify-content: center;\n padding: 0; background: transparent; border: 0; border-radius: 0;\n}\n.iwb-editor-header > .iwb-editor-divider { order: 2; }\n.iwb-editor-header > .iwb-editor-history { order: 3; display: flex; align-items: center; gap: 4px; }\n\n/* 左栏:调色板在上,参数竖排,导出按钮底部 */\n.iwb-editor-left {\n width: 240px; min-width: 240px; flex: 0 0 240px;\n display: flex; flex-direction: column; gap: 14px;\n padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;\n}\n.iwb-editor-left > .iwb-editor-color-panel { padding: 0; background: transparent; border-bottom: 0; }\n.iwb-editor-left > .iwb-editor-params {\n width: auto; min-width: 0; flex: 1 1 auto;\n flex-direction: column; align-items: stretch; gap: 12px; margin-left: 0; padding: 0;\n}\n.iwb-editor-left > .iwb-editor-export-actions {\n display: flex; flex-direction: column; gap: 8px;\n margin-top: auto; padding-top: 12px; border-top: 1px solid #313244;\n}\n.iwb-editor-left > .iwb-editor-export-actions .iwb-editor-btn { width: 100%; }\n\n/* 参数竖排:一行一个设置 */\n.iwb-editor-params .iwb-editor-brush-group { display: flex; flex-direction: column; gap: 10px; }\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-btn,\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-val { flex: 1 1 auto; }\n.iwb-editor-params .iwb-editor-layer-group { flex-wrap: wrap; }\n\n/* 颜色值后面的 实心/边线 切换 */\n.iwb-editor-fill-pair { display: inline-flex; margin-left: 6px; }\n.iwb-editor-fill-pair .iwb-editor-fill-btn { align-self: center; }\n\n/* ======== 布局优化 v3 ======== */\n/* 左栏可交互(避免被画布/层级遮挡导致“调节不起作用”) */\n.iwb-editor-left { position: relative; z-index: 40; pointer-events: auto; }\n.iwb-editor-left input, .iwb-editor-left select, .iwb-editor-left button, .iwb-editor-left label { pointer-events: auto; }\n\n/* 顶部工具栏内的 面/边(实心) 切换按钮 */\n.iwb-editor-tools .iwb-editor-fill-btn {\n width: 42px; height: 32px; padding: 0; border: 0; border-radius: 8px;\n background: transparent; color: #cdd6f4; cursor: pointer; font-size: 11px; font-weight: 600;\n}\n.iwb-editor-tools .iwb-editor-fill-btn:hover { background: #45475a; }\n.iwb-editor-tools .iwb-editor-fill-btn.active { background: #e8a735; color: #1e1e2e; }\n\n/* 右侧图层面板内的图层顺序按钮 */\n.iwb-editor-layer-panel .iwb-editor-layer-group {\n display: flex; align-items: center; gap: 6px;\n padding: 10px 12px; border-bottom: 1px solid #313244;\n}\n.iwb-editor-layer-panel .iwb-editor-layer-group .iwb-editor-constraint-label { color: #a6adc8; font-size: 12px; margin-right: 2px; }\n\n/* 缩放(画面调整)移到左栏下方 */\n.iwb-editor-params .iwb-editor-zoom {\n order: 99; margin-top: 10px; padding-top: 10px; border-top: 1px solid #313244;\n}\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-btn { flex: 0 0 auto; }\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-val { flex: 0 0 auto; }\n\n/* ======== 布局优化 v4 ======== */\n/* 交换左右栏:图层在左,调色板/参数在右 */\n.iwb-editor-main { flex-direction: row; }\n.iwb-editor-main > .iwb-editor-layer-panel { order: 1; border-left: 0; border-right: 1px solid #313244; }\n.iwb-editor-main > .iwb-editor-canvas-wrap { order: 2; }\n.iwb-editor-left { order: 3; border-right: 0; border-left: 1px solid #313244; }\n\n/* 硬度/透明度 数值与滑块对齐 */\n.iwb-editor-params .iwb-editor-brush-label .iwb-editor-brush-hardness-val,\n.iwb-editor-params .iwb-editor-brush-label .iwb-editor-brush-opacity-val {\n min-width: 40px; text-align: right; color: #cdd6f4; font-size: 12px;\n}\n.iwb-editor-params .iwb-editor-brush-label input[type="range"] { flex: 1 1 auto; }\n\n/* 缩放块放在参数区最底部 */\n.iwb-editor-params .iwb-editor-zoom, .iwb-editor-left .iwb-editor-zoom {\n display: flex; align-items: center; justify-content: center; gap: 8px;\n width: 100%; padding: 8px 4px; border-top: 1px solid #313244; margin-top: 12px;\n}\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-btn {\n flex: 0 0 auto; min-width: 28px; height: 26px; background: #313244; color: #cdd6f4; border: 0; border-radius: 6px; cursor: pointer; font-size: 14px;\n}\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-btn:hover { background: #45475a; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-val { min-width: 52px; text-align: center; color: #cdd6f4; font: 600 12px sans-serif; }\n\n/* 调色板与下方参数调节之间的横线分割 */\n.iwb-editor-params { border-top: 1px solid #313244; padding-top: 12px; }\n\n/* 色相条指示器需定位父级相对 */\n.iwb-color-hue { position: relative; }\n\n/* 顶部实心按钮与工具匹配:默认背景 */\n.iwb-editor-tools .iwb-editor-fill-btn { background: #313244; color: #cdd6f4; }\n\n/* 裁剪工具条:三行展示(比例 / 尺寸 / 确认取消),避免被挤压 */\n.iwb-editor-crop-bar {\n display: flex;\n flex-direction: column;\n gap: 8px;\n align-items: center;\n padding: 10px 14px;\n}\n.iwb-editor-crop-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; width: 100%; gap: 6px; }\n.iwb-editor-crop-row .iwb-editor-constraint-group { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }\n.iwb-editor-crop-actions { gap: 10px; }\n.iwb-editor-crop-actions .iwb-editor-crop-info { min-width: 88px; text-align: center; }\n.iwb-editor-constraint-sep { display: none; }\n\n/* ======== 修复:左列(图层)占满高度,三列稳定布局 ======== */\n.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }\n.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 290px; min-width: 290px; width: 290px; }\n.iwb-editor-main > .iwb-editor-canvas-wrap { flex: 1 1 auto; min-width: 0; }\n.iwb-editor-left { flex: 0 0 240px; min-width: 240px; width: 240px; }\n.iwb-editor-layer-panel .iwb-editor-layer-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }\n\n/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */\n.iwb-editor-header > .iwb-editor-title { order: 0; }\n.iwb-editor-header > .iwb-editor-history { order: 1; display: flex; align-items: center; gap: 4px; }\n.iwb-editor-header > .iwb-editor-tools { order: 2; flex: 1 1 auto; justify-content: center; }\n.iwb-editor-header > .iwb-editor-export-actions { order: 3; display: flex; align-items: center; gap: 6px; margin-left: 4px; }\n\n/* 重置类(撤销/重做/清空/复原)统一小圆角按钮 */\n.iwb-editor-header .iwb-editor-history .iwb-editor-action {\n width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px;\n background: #313244; color: #cdd6f4; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;\n}\n.iwb-editor-header .iwb-editor-history .iwb-editor-action:hover { background: #45475a; }\n.iwb-editor-header .iwb-editor-history .iwb-editor-action-restore { background: #313244; color: #cdd6f4; }\n\n/* 保存类(新建/覆盖/退出)统一样式 */\n.iwb-editor-header .iwb-editor-export-actions .iwb-editor-btn {\n height: 30px; padding: 0 14px; border: 0; border-radius: 8px; font-size: 12px; font-weight: 600;\n background: #313244; color: #cdd6f4; cursor: pointer;\n}\n.iwb-editor-header .iwb-editor-export-actions .iwb-editor-btn:hover { background: #45475a; }\n\n/* 调色板与参数之间的分割线及间距 */\n.iwb-editor-left > .iwb-editor-params { border-top: 1px solid #313244; margin-top: 16px; padding-top: 16px; }\n\n/* 笔刷快捷值 7 档圆点 */\n.iwb-editor-brush-presets { display: flex; align-items: center; gap: 8px; }\n.iwb-editor-brush-preset i { width: 6px; height: 6px; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 8px; height: 8px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 10px; height: 10px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 13px; height: 13px; }\n.iwb-editor-brush-preset:nth-child(5) i { width: 16px; height: 16px; }\n.iwb-editor-brush-preset:nth-child(6) i { width: 20px; height: 20px; }\n.iwb-editor-brush-preset:nth-child(7) i { width: 24px; height: 24px; }\n\n/* 缩放:缩小比例、圆角 */\n.iwb-editor-left .iwb-editor-zoom { gap: 6px; padding: 6px 4px; margin-top: 10px; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-btn { min-width: 26px; height: 24px; border-radius: 8px; font-size: 13px; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-val { min-width: 44px; font-size: 11px; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-fit { font-size: 11px; padding: 0 8px; }\n\n/* 笔刷快捷值:压缩横向间距,避免右栏出现横向滚动条 */\n.iwb-editor-left { overflow-x: hidden; }\n.iwb-editor-params { overflow-x: hidden; }\n.iwb-editor-brush-presets { gap: 3px; flex-wrap: wrap; max-width: 100%; justify-content: flex-start; }\n.iwb-editor-brush-preset { padding: 0 1px; min-width: 0; flex: 0 0 auto; }\n.iwb-editor-brush-preset i { width: 5px; height: 5px; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 7px; height: 7px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 9px; height: 9px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 11px; height: 11px; }\n.iwb-editor-brush-preset:nth-child(5) i { width: 14px; height: 14px; }\n.iwb-editor-brush-preset:nth-child(6) i { width: 17px; height: 17px; }\n.iwb-editor-brush-preset:nth-child(7) i { width: 20px; height: 20px; }\n\n/* 去掉参数模块右侧的边线(隐藏纵向滚动条与右边框) */\n.iwb-editor-left { border-right: 0 !important; scrollbar-width: none; -ms-overflow-style: none; }\n.iwb-editor-left::-webkit-scrollbar { width: 0; height: 0; display: none; }\n.iwb-editor-left > .iwb-editor-params { border-right: 0; }\n.iwb-editor-brush-presets::-webkit-scrollbar { width: 0; height: 0; display: none; }\n\n/* 独立悬浮工具条(扩展自建,不插入应用 React DOM) */\n.iwb-cutout-toolbar {\n position: fixed; z-index: 2147483000; display: none; align-items: center; gap: 3px;\n padding: 4px 6px; border-radius: 14px; background: #fff;\n border: 1px solid #d0d7de; box-shadow: 0 8px 28px rgba(15, 23, 42, 0.14);\n pointer-events: auto;\n}\n.iwb-cutout-toolbar button {\n width: 30px; height: 28px; padding: 0; border: 0; border-radius: 8px;\n background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;\n}\n.iwb-cutout-toolbar button:hover { background: #eef2f7; }\n.iwb-cutout-toolbar button i { font-style: normal; font-size: 11px; font-weight: 700; }\n.iwb-cutout-toolbar button svg { display: block; }\n\n/* 顶部左右两组工具交换:左=新建/覆盖/退出,右=撤销/重做/清空/复原 */\n.iwb-editor-header > .iwb-editor-title { order: 0; }\n.iwb-editor-header > .iwb-editor-export-actions { order: 1; margin-left: 0; margin-right: 4px; }\n.iwb-editor-header > .iwb-editor-tools { order: 2; flex: 1 1 auto; justify-content: center; }\n.iwb-editor-header > .iwb-editor-history { order: 3; margin-left: 0; }\n\n/* 图层面板:放大锁定 / 删除按钮的点击区域与图标 */\n.iwb-editor-layer-panel .iwb-layer-lock,\n.iwb-editor-layer-panel .iwb-layer-del {\n width: 24px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center;\n}\n.iwb-editor-layer-panel .iwb-layer-lock svg,\n.iwb-editor-layer-panel .iwb-layer-del svg { width: 16px; height: 16px; }\n\n\n/* 图层按钮图标统一 14px */\n.iwb-editor-layer-panel .iwb-layer-vis svg,\n.iwb-editor-layer-panel .iwb-layer-lock svg,\n.iwb-editor-layer-panel .iwb-layer-del svg { width: 14px; height: 14px; }\n.iwb-editor-layer-panel .iwb-layer-vis,\n.iwb-editor-layer-panel .iwb-layer-lock,\n.iwb-editor-layer-panel .iwb-layer-del { width: 22px; height: 22px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }\n\n/* ================================================================\n v1.1 便利版 UI(单张处理)\n 只追加、不重写历史样式:旧规则里的魔数定位在这里统一覆盖。\n 分区:顶栏 / 就地选项栏 / 竖工具栏 / 画布浮层 / 状态栏 / toast\n ================================================================ */\n\n/* ---- 顶栏:精简、一步可达 ---- */\n.iwb-editor-header { min-height: 44px; padding: 6px 12px; gap: 8px; }\n.iwb-editor-title em.iwb-editor-doc-size { font-style: normal; font-weight: 400; font-size: 11px; color: #7f849c; margin-left: 6px; }\n.iwb-editor-optionbar {\n display: flex; align-items: center; gap: 10px;\n height: 36px; min-height: 36px; padding: 0 12px;\n background: #202033; border-bottom: 1px solid #313244;\n color: #a6adc8; font-size: 12px;\n}\n.iwb-editor-optionbar-label { color: #7f849c; font-weight: 600; white-space: nowrap; }\n.iwb-editor-optionbar-body { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }\n.iwb-opt-label { color: #a6adc8; white-space: nowrap; }\n.iwb-opt-btn {\n background: #313244; color: #cdd6f4; border: 1px solid transparent; border-radius: 5px;\n padding: 3px 9px; font-size: 12px; cursor: pointer;\n}\n.iwb-opt-btn:hover { background: #45475a; }\n.iwb-opt-btn.active { background: #4488ff; color: #fff; }\n.iwb-opt-num {\n width: 46px; padding: 2px 4px; background: #313244; color: #e8a735;\n border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;\n}\n.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }\n.iwb-opt-hint { color: #7f849c; font-size: 11px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n\n.iwb-editor-more-wrap, .iwb-editor-export-settings-wrap { position: relative; flex: 0 0 auto; z-index: 45; }\n.iwb-editor-more-btn, .iwb-editor-panel-toggle, .iwb-editor-export-settings-btn {\n background: #313244; color: #cdd6f4; border: 1px solid #45475a; border-radius: 6px;\n padding: 5px 10px; font-size: 12px; cursor: pointer; white-space: nowrap;\n}\n.iwb-editor-more-btn:hover, .iwb-editor-panel-toggle:hover, .iwb-editor-export-settings-btn:hover { background: #45475a; }\n.iwb-editor-panel-toggle { padding: 5px 8px; }\n.iwb-editor-export-summary { color: #e8a735; margin: 0 2px; }\n\n.iwb-editor-more-menu, .iwb-editor-export-settings {\n display: none; position: absolute; top: 34px; z-index: 60;\n background: #252537; border: 1px solid #45475a; border-radius: 8px;\n padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,0.45);\n}\n.iwb-editor-more-menu { left: 0; width: 206px; flex-direction: column; gap: 2px; }\n.iwb-editor-more-menu.open, .iwb-editor-export-settings.open { display: flex; flex-direction: column; gap: 4px; }\n.iwb-editor-export-settings { right: 0; width: 268px; }\n.iwb-editor-more-menu button, .iwb-editor-export-row button {\n background: transparent; color: #cdd6f4; border: 0; border-radius: 5px;\n padding: 6px 8px; font-size: 12px; text-align: left; cursor: pointer; white-space: nowrap;\n}\n.iwb-editor-more-menu button:hover, .iwb-editor-export-row button:hover { background: #3b3d52; }\n.iwb-editor-more-menu kbd { float: right; color: #7f849c; font-size: 10px; }\n.iwb-editor-more-sep { height: 1px; background: #45475a; margin: 4px 0; }\n.iwb-editor-export-row { display: flex; align-items: center; gap: 4px; }\n.iwb-editor-export-row > span { width: 34px; flex: 0 0 34px; color: #7f849c; font-size: 11px; }\n.iwb-editor-export-row button { flex: 1 1 auto; text-align: center; background: #313244; }\n.iwb-editor-export-row button.active { background: #4488ff; color: #fff; }\n.iwb-editor-export-note { color: #7f849c; font-size: 11px; border-top: 1px solid #313244; padding-top: 6px; }\n.iwb-editor-btn-download { background: #1a7f37 !important; color: #fff !important; }\n.iwb-editor-btn-download:hover { background: #15803d !important; }\n\n/* ---- 竖工具栏:真正固定在左侧,给 main 留出 56px ---- */\n.iwb-editor-header > .iwb-editor-tools {\n position: fixed !important; left: 8px !important; top: 112px !important;\n width: 40px !important; max-height: calc(100vh - 128px);\n flex-direction: column; padding: 5px !important; border-radius: 10px;\n overflow-y: auto; overflow-x: hidden; scrollbar-width: none; z-index: 50;\n}\n.iwb-editor-header > .iwb-editor-tools::-webkit-scrollbar { display: none; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-tool,\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { width: 30px !important; height: 30px !important; min-width: 30px; flex: 0 0 auto; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-divider { width: 22px; height: 1px; margin: 3px 0; flex: 0 0 auto; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-fill-btn { width: 30px !important; padding: 3px 0 !important; font-size: 10px; writing-mode: vertical-rl; }\n.iwb-editor-main { padding-left: 56px; }\n.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 260px !important; min-width: 260px !important; width: 260px !important; }\n.iwb-editor-left { flex: 0 0 220px !important; min-width: 220px !important; width: 220px !important; }\n.iwb-editor-overlay.panels-collapsed .iwb-editor-layer-panel,\n.iwb-editor-overlay.panels-collapsed .iwb-editor-left { display: none !important; }\n.iwb-editor-zoom-hint { display: none !important; }\n\n/* ---- 交互层:蚂蚁线 / 笔刷环各自独立,互不擦除 ---- */\n.iwb-editor-selection-overlay, .iwb-editor-cursor-overlay {\n position: absolute; top: 0; left: 0; display: block; pointer-events: none;\n background: transparent !important;\n}\n.iwb-editor-selection-overlay { z-index: 11; }\n.iwb-editor-cursor-overlay { z-index: 12; }\n\n/* ---- 选区浮动操作条(体验后再定去留;纯视图,可随时替换) ---- */\n.iwb-editor-sel-bar {\n display: none; position: absolute; z-index: 30; align-items: center; gap: 4px;\n padding: 5px 6px; background: rgba(24,24,37,0.96);\n border: 1px solid #45475a; border-radius: 8px;\n box-shadow: 0 8px 26px rgba(0,0,0,0.45); white-space: nowrap;\n}\n.iwb-editor-sel-bar.as-menu { border-color: #4488ff; }\n.iwb-editor-sel-bar .iwb-editor-sel-info {\n color: #7f849c; font-size: 11px; padding: 0 6px;\n border-right: 1px solid #45475a; margin-right: 2px; font-variant-numeric: tabular-nums;\n}\n.iwb-editor-sel-bar button {\n background: #313244; color: #cdd6f4; border: 1px solid transparent; border-radius: 5px;\n padding: 4px 8px; font-size: 12px; cursor: pointer;\n}\n.iwb-editor-sel-bar button:hover:not(:disabled) { background: #4488ff; color: #fff; }\n.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]:hover:not(:disabled) { background: #cf222e; }\n.iwb-editor-sel-bar button:disabled { opacity: 0.35; cursor: not-allowed; }\n\n/* ---- 状态栏 / toast ---- */\n.iwb-editor-statusbar {\n display: flex; align-items: center; gap: 14px;\n height: 26px; min-height: 26px; padding: 0 12px;\n background: #181825; border-top: 1px solid #313244;\n color: #a6adc8; font-size: 11px; font-variant-numeric: tabular-nums;\n}\n.iwb-editor-statusbar span + span { border-left: 1px solid #313244; padding-left: 14px; }\n.iwb-editor-status-tool { margin-left: auto; color: #e8a735; }\n.iwb-editor-toast {\n position: fixed; left: 50%; bottom: 46px; z-index: 1000000;\n transform: translate(-50%, 12px); opacity: 0; pointer-events: none;\n transition: opacity 0.2s, transform 0.2s;\n background: #313244; color: #cdd6f4; padding: 8px 14px; border-radius: 8px;\n font-size: 12px; max-width: 80vw; box-shadow: 0 8px 26px rgba(0,0,0,0.45);\n}\n.iwb-editor-toast.show { opacity: 1; transform: translate(-50%, 0); }\n.iwb-editor-toast-success { background: #1a7f37; color: #fff; }\n.iwb-editor-toast-error { background: #cf222e; color: #fff; }\n.iwb-editor-toast-warn { background: #b06a00; color: #fff; }\n.iwb-editor-toast-info { background: #2f6fed; color: #fff; }\n\n@media (max-width: 900px) {\n .iwb-opt-hint, .iwb-editor-optionbar-tip { display: none; }\n .iwb-editor-export-actions .iwb-editor-btn-cancel { display: none; }\n}\n\n\n/* 输出设置:按预设显示的行(尺寸/体积只属于电商方图)\n 注意 `.iwb-editor-export-row` 是 display:flex,会盖掉 UA 的 [hidden]{display:none},\n 必须显式 !important,否则 JS 设 hidden 后行还留在面板里。 */\n.iwb-editor-export-row[hidden] { display: none !important; }\n.iwb-editor-export-settings [data-export-key]:disabled {\n opacity: 0.32; cursor: not-allowed; text-decoration: line-through;\n}\n.iwb-editor-export-settings [data-export-key]:disabled:hover { background: #313244; }\n'; + 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-editor-tools .iwb-editor-action[data-action="redo"] { right: 118px; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"] { right: 82px; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] { right: 46px; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-divider {\n width: 24px;\n height: 1px;\n margin: 4px 0;\n}\n\n.iwb-editor-title {\n color: #cdd6f4;\n font-size: 14px;\n font-weight: 600;\n white-space: nowrap;\n}\n\n.iwb-editor-tools {\n display: flex;\n align-items: center;\n gap: 4px;\n}\n\n.iwb-editor-tool, .iwb-editor-action {\n background: #313244;\n border: none;\n border-radius: 6px;\n color: #cdd6f4;\n width: 32px; height: 32px;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n font-size: 15px;\n transition: background 0.15s, transform 0.1s;\n}\n.iwb-editor-tool:hover, .iwb-editor-action:hover { background: #45475a; transform: scale(1.08); }\n.iwb-editor-tool.active { background: #e8a735; color: #1e1e2e; }\n.iwb-editor-tool svg, .iwb-editor-action svg { display: block; }\n.iwb-editor-layer-btn svg { display: block; }\n\n/* 复原按钮:绿色高亮,与撤销/重做/清空区分 */\n.iwb-editor-action-restore { background: #1a7f37; color: #fff; }\n.iwb-editor-action-restore:hover { background: #15803d !important; }\n\n.iwb-editor-divider {\n width: 1px; height: 20px;\n background: #45475a;\n margin: 0 4px;\n}\n\n.iwb-editor-params {\n display: flex;\n align-items: center;\n gap: 10px;\n margin-left: 12px;\n justify-content: flex-start;\n min-width: 0;\n flex: 1 1 auto;\n flex-wrap: wrap;\n}\n.iwb-editor-params .iwb-editor-zoom { margin-left: auto; order: 20; }\n.iwb-editor-top-colors { display: none; }\n\n.iwb-editor-colors { display: flex; gap: 4px; }\n.iwb-editor-color {\n width: 20px; height: 20px;\n border-radius: 50%;\n cursor: pointer;\n border: 2px solid transparent;\n transition: transform 0.1s, border-color 0.15s;\n}\n.iwb-editor-color:hover { transform: scale(1.2); }\n.iwb-editor-color.active { border-color: #fff; transform: scale(1.15); }\n\n.iwb-editor-brush-label {\n display: flex;\n align-items: center;\n gap: 6px;\n color: #a6adc8;\n font-size: 12px;\n}\n.iwb-editor-brush-size { width: 80px; cursor: pointer; }\n.iwb-editor-brush-val { color: #e8a735; font-weight: 600; min-width: 16px; }\n\n/* 笔刷/橡皮大小精确数值输入框 */\n.iwb-editor-brush-num,\n.iwb-editor-eraser-num {\n width: 44px;\n padding: 2px 3px;\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 5px;\n color: #e8a735;\n font-weight: 600;\n font-size: 11px;\n font-family: inherit;\n text-align: center;\n}\n.iwb-editor-brush-num:focus,\n.iwb-editor-eraser-num:focus {\n outline: none;\n border-color: #e8a735;\n background: #1e1e2e;\n}\n.iwb-editor-brush-num::-webkit-outer-spin-button,\n.iwb-editor-brush-num::-webkit-inner-spin-button,\n.iwb-editor-eraser-num::-webkit-outer-spin-button,\n.iwb-editor-eraser-num::-webkit-inner-spin-button {\n -webkit-appearance: none; /* 去掉上下箭头,窄输入框更干净 */\n margin: 0;\n}\n\n/* 实心矩形开关 */\n.iwb-editor-fill-btn {\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 6px;\n color: #a6adc8;\n padding: 4px 10px;\n font-size: 12px;\n cursor: pointer;\n transition: background 0.15s, color 0.15s, border-color 0.15s;\n white-space: nowrap;\n}\n.iwb-editor-fill-btn:hover { background: #45475a; }\n.iwb-editor-fill-btn.active {\n background: #e8a735;\n border-color: #e8a735;\n color: #1e1e2e;\n font-weight: 600;\n}\n\n/* 画笔参数组(硬度/透明度,画笔与橡皮工具共用) */\n.iwb-editor-brush-group {\n display: flex;\n align-items: center;\n gap: 10px;\n}\n.iwb-editor-layer-group {\n display: flex;\n align-items: center;\n gap: 3px;\n}\n.iwb-editor-layer-btn {\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 6px;\n color: #a6adc8;\n width: 26px;\n height: 26px;\n font-size: 14px;\n line-height: 1;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;\n}\n.iwb-editor-layer-btn:hover:not(:disabled) { background: #45475a; color: #cdd6f4; }\n.iwb-editor-layer-btn:disabled {\n opacity: 0.35;\n cursor: not-allowed;\n}\n\n/* 缩放控件 */\n.iwb-editor-zoom {\n display: flex;\n align-items: center;\n gap: 2px;\n background: #313244;\n border-radius: 6px;\n padding: 2px;\n}\n.iwb-editor-zoom-btn {\n background: transparent;\n border: none;\n color: #cdd6f4;\n width: 26px;\n height: 26px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n line-height: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.15s;\n}\n.iwb-editor-zoom-btn:hover { background: #45475a; }\n.iwb-editor-zoom-btn:active { transform: scale(0.94); }\n.iwb-editor-zoom-fit { font-size: 12px; width: auto; padding: 0 8px; }\n.iwb-editor-zoom-val {\n color: #e8a735;\n font-size: 12px;\n font-weight: 600;\n min-width: 46px;\n text-align: center;\n font-variant-numeric: tabular-nums;\n user-select: none;\n}\n\n/* 底部操作提示 */\n.iwb-editor-zoom-hint {\n position: absolute;\n bottom: 8px;\n right: 14px;\n color: #7f849c;\n font-size: 11px;\n background: rgba(24, 24, 37, 0.85);\n padding: 3px 10px;\n border-radius: 4px;\n pointer-events: none;\n z-index: 5;\n}\n\n.iwb-editor-canvas-wrap {\n position: relative;\n background: #11111b;\n flex: 1 1 auto;\n min-height: 0;\n max-width: 100%;\n max-height: 100%;\n overflow: hidden; /* 裁剪框允许显示在图片边界外;编辑区仍由模态层裁切 */\n padding: 12px;\n}\n\n.iwb-editor-canvas-stack {\n position: absolute;\n left: 0;\n top: 0;\n display: block;\n width: 0;\n height: 0;\n /* 仅图片工作区显示透明棋盘格,外围裁剪工作区保持纯色。 */\n background-color: #d6d6d6;\n background-image:\n linear-gradient(45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(-45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, #b8b8b8 75%),\n linear-gradient(-45deg, transparent 75%, #b8b8b8 75%);\n background-size: 20px 20px;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0;\n}\n\n.iwb-editor-base, .iwb-editor-draw, .iwb-editor-text, .iwb-editor-crop-overlay {\n display: block;\n}\n/* 位图图层 canvas(动态创建) */\n.iwb-editor-layer-canvas {\n display: block;\n position: absolute;\n top: 0; left: 0;\n}\n.iwb-editor-base {\n background: #fff;\n /* 棋盘格透明背景示意 */\n background-image:\n linear-gradient(45deg, #e0e0e0 25%, transparent 25%),\n linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, #e0e0e0 75%),\n linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);\n background-size: 20px 20px;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0px;\n}\n.iwb-editor-draw {\n position: absolute;\n top: 0; left: 0;\n cursor: crosshair;\n}\n\n/* 笔划预览层:一笔进行中显示(draw 之上、text 之下),事件穿透 */\n.iwb-editor-stroke {\n position: absolute;\n top: 0; left: 0;\n pointer-events: none;\n display: none;\n}\n\n.iwb-editor-brush-hardness { width: 70px; cursor: pointer; }\n.iwb-editor-brush-hardness-val { color: #e8a735; font-weight: 600; min-width: 20px; display: inline-block; text-align: right; }\n.iwb-editor-brush-opacity { width: 70px; cursor: pointer; }\n.iwb-editor-brush-opacity-val { color: #e8a735; font-weight: 600; min-width: 34px; display: inline-block; text-align: right; }\n\n/* 自定义颜色(原生取色器伪装成圆形色板) */\n.iwb-editor-color-custom {\n position: relative;\n overflow: hidden;\n border: 2px dashed #a6adc8;\n}\n.iwb-editor-color-custom.active { border-color: #fff; border-style: solid; transform: scale(1.15); }\n.iwb-editor-color-custom input[type="color"] {\n position: absolute;\n inset: -6px;\n width: calc(100% + 12px);\n height: calc(100% + 12px);\n padding: 0;\n border: none;\n cursor: pointer;\n background: conic-gradient(#ff4444, #ffaa00, #44dd44, #4488ff, #aa44ff, #ff4444);\n}\n.iwb-editor-color-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }\n.iwb-editor-color-custom input[type="color"]::-webkit-color-swatch { border: none; }\n\n/* 吸管悬停预览浮窗 */\n.iwb-editor-picker-tip {\n position: fixed;\n z-index: 2147483000;\n display: none;\n align-items: center;\n gap: 6px;\n background: rgba(30, 30, 46, 0.95);\n border: 1px solid rgba(255, 255, 255, 0.14);\n border-radius: 6px;\n padding: 4px 8px;\n pointer-events: none;\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n}\n.iwb-editor-picker-chip {\n width: 16px;\n height: 16px;\n border-radius: 4px;\n background: transparent;\n}\n.iwb-editor-picker-hex {\n color: #cdd6f4;\n font-size: 12px;\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n}\n\n/* 文字图层:独立 canvas,事件穿透到下层 drawCanvas */\n.iwb-editor-text {\n position: absolute;\n top: 0; left: 0;\n pointer-events: none;\n}\n\n/* 裁剪覆盖层:遮罩/选区框/手柄画在这层,不污染标注层 */\n.iwb-editor-crop-overlay {\n position: absolute;\n top: 0; left: 0;\n pointer-events: none;\n}\n\n/* 文字输入框 */\n.iwb-editor-text-input {\n position: absolute;\n display: none;\n padding: 4px 8px;\n border: 2px solid #4488ff;\n border-radius: 4px;\n font-size: 14px;\n background: rgba(255, 255, 255, 0.95);\n color: #1e1e2e;\n z-index: 10;\n min-width: 120px;\n}\n.iwb-editor-text-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(68, 136, 255, 0.3); }\n\n/* 裁剪确认栏(含约束控件) */\n.iwb-editor-crop-bar {\n position: absolute;\n bottom: 16px;\n left: 50%;\n transform: translateX(-50%);\n display: none;\n gap: 8px;\n z-index: 10;\n align-items: center;\n background: rgba(24, 24, 37, 0.92);\n border: 1px solid #313244;\n border-radius: 8px;\n padding: 6px 10px;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);\n flex-wrap: wrap;\n max-width: 90%;\n justify-content: center;\n}\n\n.iwb-editor-constraint-group {\n display: flex;\n align-items: center;\n gap: 4px;\n}\n\n.iwb-editor-constraint-label {\n color: #7f849c;\n font-size: 11px;\n margin-right: 2px;\n white-space: nowrap;\n}\n\n.iwb-editor-constraint-btn {\n background: #313244;\n border: none;\n border-radius: 4px;\n color: #cdd6f4;\n padding: 3px 8px;\n font-size: 12px;\n cursor: pointer;\n transition: background 0.15s, transform 0.1s;\n white-space: nowrap;\n}\n.iwb-editor-constraint-btn:hover { background: #45475a; transform: scale(1.05); }\n.iwb-editor-constraint-btn.active { background: #4488ff; color: #fff; }\n\n.iwb-editor-constraint-sep {\n width: 1px;\n height: 20px;\n background: #45475a;\n}\n\n.iwb-editor-size-input {\n width: 50px;\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 4px;\n color: #cdd6f4;\n padding: 3px 6px;\n font-size: 12px;\n text-align: center;\n}\n.iwb-editor-size-input:focus { outline: none; border-color: #4488ff; }\n.iwb-editor-size-input::-webkit-inner-spin-button { -webkit-appearance: none; }\n\n.iwb-editor-size-x { color: #7f849c; font-size: 12px; }\n\n.iwb-editor-size-apply {\n background: #313244;\n border: 1px solid #4488ff;\n color: #4488ff;\n border-radius: 4px;\n padding: 3px 8px;\n font-size: 12px;\n cursor: pointer;\n transition: background 0.15s;\n}\n.iwb-editor-size-apply:hover { background: #4488ff; color: #fff; }\n\n.iwb-editor-crop-info {\n color: #e8a735;\n font-size: 12px;\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n min-width: 60px;\n text-align: center;\n}\n\n.iwb-editor-crop-confirm, .iwb-editor-crop-cancel {\n padding: 6px 16px;\n border: none;\n border-radius: 6px;\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n}\n.iwb-editor-crop-confirm { background: #1a7f37; color: #fff; }\n.iwb-editor-crop-confirm:hover { background: #15803d; }\n.iwb-editor-crop-cancel { background: #cf222e; color: #fff; }\n.iwb-editor-crop-cancel:hover { background: #b91c1c; }\n\n/* 底部 */\n.iwb-editor-footer {\n display: flex;\n justify-content: flex-end;\n gap: 8px;\n padding: 12px 16px;\n background: #181825;\n border-top: 1px solid #313244;\n}\n\n.iwb-editor-btn {\n padding: 8px 20px;\n border: none;\n border-radius: 6px;\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n transition: background 0.15s, transform 0.1s;\n}\n.iwb-editor-btn:hover { transform: scale(1.03); }\n.iwb-editor-btn-cancel { background: #45475a; color: #cdd6f4; }\n.iwb-editor-btn-cancel:hover { background: #585b70; }\n.iwb-editor-btn-new { background: #4488ff; color: #fff; }\n.iwb-editor-btn-new:hover { background: #3578f0; }\n.iwb-editor-btn-replace { background: #e8a735; color: #1e1e2e; }\n.iwb-editor-btn-replace:hover { background: #d49628; }\n\n/* ==================== 图层面板 ==================== */\n\n.iwb-editor-layer-panel {\n width: 290px;\n min-width: 290px;\n background: #181825;\n border-left: 1px solid #313244;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n\n.iwb-editor-layer-panel-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 10px 12px;\n border-bottom: 1px solid #313244;\n}\n\n.iwb-editor-layer-panel-title {\n color: #cdd6f4;\n font-size: 13px;\n font-weight: 600;\n}\n\n.iwb-editor-layer-add-group {\n display: flex;\n gap: 4px;\n}\n\n.iwb-editor-layer-add-btn {\n background: #313244;\n border: 1px solid #45475a;\n border-radius: 6px;\n color: #cdd6f4;\n width: 26px;\n height: 26px;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.15s;\n}\n.iwb-editor-layer-add-btn:hover { background: #45475a; color: #e8a735; }\n.iwb-editor-layer-add-btn svg { display: block; }\n\n.iwb-editor-layer-list {\n flex: 1 1 auto;\n overflow-y: auto;\n padding: 4px;\n}\n\n/* 图层项 */\n.iwb-layer-item {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 6px 8px;\n border-radius: 6px;\n cursor: pointer;\n transition: background 0.12s;\n margin-bottom: 2px;\n}\n.iwb-layer-item:hover { background: #313244; }\n.iwb-layer-item.active {\n background: #313244;\n box-shadow: inset 2px 0 0 #e8a735;\n}\n.iwb-layer-item.hidden { opacity: 0.5; }\n.iwb-layer-item[draggable="true"] { cursor: grab; }\n.iwb-layer-item.dragging { opacity: 0.45; }\n.iwb-layer-item.drop-target { outline: 1px dashed #e8a735; background: rgba(232, 167, 53, 0.16); }\n/* 画笔/橡皮作用目标:与「选中」分离,避免出现两个图层同时高亮 */\n.iwb-layer-paint { flex: 0 0 auto; color: #a6adc8; font-size: 11px; opacity: 0.85; }\n.iwb-layer-color { width: 22px; height: 22px; padding: 0; border: 1px solid #45475a; border-radius: 50%; background: transparent; cursor: pointer; flex: 0 0 auto; }\n.iwb-layer-width { width: 42px; height: 22px; padding: 2px 3px; border: 1px solid #45475a; border-radius: 4px; background: #1e1e2e; color: #e8a735; font-size: 11px; text-align: center; flex: 0 0 auto; }\n.iwb-layer-width:focus { outline: none; border-color: #e8a735; }\n\n.iwb-layer-vis {\n background: none;\n border: none;\n color: #a6adc8;\n cursor: pointer;\n font-size: 13px;\n width: 20px;\n height: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n transition: background 0.12s;\n}\n.iwb-layer-vis:hover { background: #45475a; }\n\n.iwb-layer-icon {\n font-size: 13px;\n width: 18px;\n text-align: center;\n flex-shrink: 0;\n}\n\n.iwb-layer-name {\n color: #cdd6f4;\n font-size: 12px;\n flex: 1 1 auto;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n min-width: 0;\n}\n\n.iwb-layer-lock {\n background: none;\n border: none;\n color: #7f849c;\n cursor: pointer;\n width: 20px;\n height: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n transition: background 0.12s, color 0.12s;\n flex-shrink: 0;\n}\n.iwb-layer-lock:hover, .iwb-layer-lock.active { background: #45475a; color: #e8a735; }\n\n.iwb-layer-del {\n background: none;\n border: none;\n color: #585b70;\n cursor: pointer;\n font-size: 12px;\n width: 18px;\n height: 18px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n transition: background 0.12s, color 0.12s;\n flex-shrink: 0;\n}\n.iwb-layer-del:hover { background: #cf222e; color: #fff; }\n\n/* SVG 图标尺寸 */\n.iwb-layer-vis svg { display: block; }\n.iwb-layer-icon svg { display: block; }\n.iwb-layer-lock svg { display: block; }\n.iwb-layer-del svg { display: block; }\n\n/* 独立 PS 风格颜色面板 */\n.iwb-editor-color-panel { padding: 12px; border-bottom: 1px solid #313244; background: #202033; }\n.iwb-editor-color-panel-title { color: #cdd6f4; font-size: 12px; font-weight: 600; margin-bottom: 10px; }\n.iwb-editor-color-panel-main { display: flex; align-items: center; gap: 10px; }\n.iwb-editor-color-current { width: 52px; height: 52px; border: 2px solid #cdd6f4; border-radius: 6px; overflow: hidden; display: block; background: #ff4444; }\n.iwb-editor-color-panel-input { width: 100%; height: 100%; padding: 0; border: 0; cursor: pointer; opacity: 0; }\n.iwb-editor-color-panel-values { min-width: 0; flex: 1; }\n.iwb-editor-color-hex { color: #cdd6f4; font: 600 12px monospace; display: block; margin-bottom: 8px; }\n.iwb-editor-color-swatches { display: flex; flex-wrap: wrap; gap: 6px; }\n.iwb-editor-color-panel-swatch { width: 20px; height: 20px; border: 1px solid #585b70; border-radius: 4px; cursor: pointer; }\n.iwb-editor-color-panel-swatch:hover { transform: scale(1.12); border-color: #fff; }\n.iwb-editor-panel-width { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: #a6adc8; font-size: 11px; }\n.iwb-editor-panel-width-range { flex: 1; min-width: 60px; }\n.iwb-editor-panel-width-num { width: 42px; padding: 3px; background: #313244; color: #e8a735; border: 1px solid #45475a; border-radius: 4px; text-align: center; }\n.iwb-layer-color, .iwb-layer-width { display: none !important; }\n\n/* 顶部独立操作区,避免操作按钮被竖向工具栏裁切 */\n.iwb-editor-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; flex: 0 0 auto; }\n.iwb-editor-actions .iwb-editor-action { position: static !important; }\n.iwb-editor-actions .iwb-editor-action-restore { width: auto; padding: 0 9px; font-size: 12px; }\n\n/* 原图 canvas 只负责绘制像素,透明处透出 stack 的棋盘格。 */\n.iwb-editor-base { background: transparent !important; background-image: none !important; }\n\n/* 透明区域使用 Photoshop 风格的灰色棋盘格,覆盖整个实际图片区域。 */\n.iwb-editor-canvas-stack {\n background-color: #d6d6d6 !important;\n background-image:\n linear-gradient(45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(-45deg, #b8b8b8 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, #b8b8b8 75%),\n linear-gradient(-45deg, transparent 75%, #b8b8b8 75%) !important;\n background-size: 20px 20px !important;\n background-position: 0 0, 0 10px, 10px -10px, -10px 0 !important;\n}\n.iwb-editor-base { background: transparent !important; background-image: none !important; }\n\n/* 顶部参数区必须保持可见且可交互,避免被侧栏定位层覆盖。 */\n.iwb-editor-header { position: relative; min-height: 56px; overflow: visible; }\n.iwb-editor-params { position: relative; z-index: 30; overflow: visible; pointer-events: auto; }\n.iwb-editor-params input, .iwb-editor-params button, .iwb-editor-params label { pointer-events: auto; }\n.iwb-editor-brush-size, .iwb-editor-brush-hardness, .iwb-editor-brush-opacity { min-width: 70px; accent-color: #e8a735; }\n.iwb-editor-brush-num, .iwb-editor-eraser-num { pointer-events: auto; }\n\n/* canvas 的透明像素必须透出 stack 棋盘格,不能被黑色工作区遮住。 */\n.iwb-editor-canvas-stack { isolation: isolate; }\n.iwb-editor-layer-canvas, .iwb-editor-text, .iwb-editor-stroke, .iwb-editor-crop-overlay { background: transparent !important; }\n\n/* 透明棋盘格只覆盖原图的显示矩形,外围裁剪扩展区保持纯色。 */\n.iwb-editor-canvas-stack { background: #11111b !important; background-image: none !important; }\n.iwb-editor-transparency-grid { position: absolute; z-index: 0; pointer-events: none; background-color: #d6d6d6; background-image: linear-gradient(45deg, #b8b8b8 25%, transparent 25%), linear-gradient(-45deg, #b8b8b8 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #b8b8b8 75%), linear-gradient(-45deg, transparent 75%, #b8b8b8 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }\n.iwb-editor-layer-canvas, .iwb-editor-stroke, .iwb-editor-text { z-index: 1; }\n.iwb-editor-crop-overlay { z-index: 10; }\n\n/* 画布扩展区不得盖过编辑器外围,图片区域由透明层单独标识。 */\n.iwb-editor-canvas-stack { overflow: visible; max-width: 100%; max-height: 100%; background: #11111b !important; background-image: none !important; }\n.iwb-editor-transparency-grid { z-index: 0; overflow: hidden; }\n.iwb-editor-layer-canvas { z-index: 1; }\n.iwb-editor-stroke { z-index: 4; }\n.iwb-editor-text { z-index: 5; }\n.iwb-editor-crop-overlay { z-index: 10; }\n\n/* 导出操作与缩放同处顶栏,缩放独立靠右。 */\n.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }\n.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }\n.iwb-editor-footer { display: none !important; }\n.iwb-layer-color, .iwb-layer-width { display: none !important; }\n\n.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }\n.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }\n.iwb-editor-footer { display: none !important; }\n.iwb-layer-color, .iwb-layer-width { display: none !important; }\n\n/* 顶部七个操作按钮统一文本按钮样式,自适应中文宽度。 */\n.iwb-editor-actions { gap: 6px; }\n.iwb-editor-actions .iwb-editor-action { width: auto; min-width: 72px; height: 32px; padding: 0 12px; gap: 5px; font-size: 12px; font-weight: 500; white-space: nowrap; }\n.iwb-editor-actions .iwb-editor-action svg { width: 14px; height: 14px; flex: 0 0 auto; }\n.iwb-editor-export-actions .iwb-editor-btn { min-width: 72px; white-space: nowrap; }\n\n/* 顶部操作按钮统一为纯文本,图标隐藏并保持一致宽度。 */\n.iwb-editor-actions .iwb-editor-action svg { display: none !important; }\n.iwb-editor-actions .iwb-editor-action { min-width: 76px; width: 76px; justify-content: center; background: #3b3d52; color: #cdd6f4; }\n.iwb-editor-actions .iwb-editor-action:hover { background: #50536b; }\n.iwb-editor-actions .iwb-editor-action-restore { background: #3b3d52; color: #cdd6f4; }\n.iwb-editor-actions .iwb-editor-action-restore:hover { background: #50536b !important; }\n\n.iwb-editor-actions .iwb-editor-action svg { display: none !important; }\n.iwb-editor-actions .iwb-editor-action { min-width: 76px; width: 76px; justify-content: center; background: #3b3d52; color: #cdd6f4; }\n.iwb-editor-actions .iwb-editor-action:hover, .iwb-editor-actions .iwb-editor-action-restore:hover { background: #50536b !important; }\n\n.iwb-editor-actions .iwb-editor-action { width: auto; min-width: 76px; padding: 0 12px; gap: 5px; }\n.iwb-editor-actions .iwb-editor-action span { display: inline-block; }\n\n.iwb-editor-actions { margin-left: 12px; }\n.iwb-editor-actions .iwb-editor-btn { width: auto; min-width: 76px; height: 32px; padding: 0 12px; font-size: 12px; white-space: nowrap; }\n.iwb-editor-actions .iwb-editor-action { width: auto; min-width: 76px; }\n\n.iwb-editor-actions .iwb-editor-action { min-width: 52px; width: auto; padding: 0 10px; font-size: 12px; }\n.iwb-editor-brush-presets { display: flex; align-items: center; gap: 7px; margin-left: 4px; }\n.iwb-editor-brush-preset { display: inline-flex; align-items: center; gap: 3px; padding: 2px 3px; border: 0; background: transparent; color: #a6adc8; cursor: pointer; font-size: 11px; }\n.iwb-editor-brush-preset i { display: block; width: 12px; height: 12px; border-radius: 50%; background: #e8a735; border: 1px solid #f6d38a; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 16px; height: 16px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 20px; height: 20px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 24px; height: 24px; }\n.iwb-editor-brush-preset:hover, .iwb-editor-brush-preset.active { color: #fff; }\n\n/* 紧凑顶栏:操作按钮与描边快捷点仅保留必要视觉信息。 */\n.iwb-editor-actions .iwb-editor-action { width: 28px; min-width: 28px; height: 28px; padding: 0; }\n.iwb-editor-actions .iwb-editor-action svg { display: block !important; width: 14px; height: 14px; }\n.iwb-editor-brush-presets { gap: 5px; margin-left: 2px; }\n.iwb-editor-brush-preset { width: 24px; height: 24px; padding: 0; justify-content: center; }\n.iwb-editor-brush-preset i { width: 5px; height: 5px; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 8px; height: 8px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 12px; height: 12px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 16px; height: 16px; }\n\n/* 图层栏内嵌调色板:颜色直接点击应用,不弹出系统取色器。 */\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-color-current { width: 42px; height: 42px; flex: 0 0 42px; cursor: default; }\n.iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(7, 20px); gap: 5px; }\n.iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; }\n\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-color-current { width: 42px; height: 42px; flex: 0 0 42px; cursor: default; }\n.iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(7, 20px); gap: 5px; }\n.iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; }\n\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-palette-current { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-palette-current .iwb-editor-color-current { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-hex { margin: 0; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }\n\n.iwb-editor-color-panel { padding: 10px; }\n.iwb-editor-palette-current { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-palette-current .iwb-editor-color-current { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-hex { margin: 0; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }\n\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { width: 42px; height: 28px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { width: 42px; height: 28px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { width: 42px; height: 28px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n\n.iwb-editor-color-panel { padding: 9px; }\n.iwb-editor-inline-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }\n.iwb-editor-inline-picker .iwb-editor-color-panel-input { display: block; width: 44px; height: 30px; padding: 0; opacity: 1; cursor: pointer; border: 1px solid #585b70; border-radius: 4px; }\n.iwb-editor-color-panel .iwb-editor-color-swatches { display: grid; grid-template-columns: repeat(6, 20px); gap: 7px; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch { width: 20px; height: 20px; border-radius: 50%; padding: 0; }\n.iwb-editor-color-panel .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }\n\n.iwb-editor-color-picker2 { display: flex; gap: 8px; height: 118px; }\n.iwb-color-sv { position: relative; flex: 1; background: linear-gradient(to top,#000,transparent),linear-gradient(to right,#fff,rgba(255,255,255,0)); background-color: #f44; border-radius: 4px; }\n.iwb-color-hue { width: 18px; border-radius: 4px; background: linear-gradient(to bottom,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00); }\n.iwb-editor-color-fields { display: flex; gap: 6px; margin: 8px 0; }\n.iwb-editor-color-hex-input { width: 72px; background:#313244; color:#cdd6f4; border:1px solid #585b70; padding:4px; }\n.iwb-editor-color-panel-input { width: 32px; height: 26px; opacity: 1; padding: 0; }\n\n.iwb-color-sv span, .iwb-color-hue span { position: absolute; width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #222; transform: translate(-50%, -50%); pointer-events: none; }\n.iwb-color-sv span { left: 100%; top: 0; }\n.iwb-color-hue span { left: 50%; top: 0; }\n\n.iwb-compress-btn { color: #16a34a !important; font-size: 11px; font-weight: 700; }\n\n/* 新版浮动气泡栏内的工具按钮 */\n.iwb-node-floatbar .iwb-compress-btn { font-size: 11px; font-weight: 700; }\n.iwb-node-floatbar .iwb-cutout-btn.processing,\n.iwb-node-floatbar .iwb-whitebg-btn.processing,\n.iwb-node-floatbar .iwb-compress-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n\n/* 调色板:吸色按钮(替代原来的弹出式取色器) */\n.iwb-editor-color-eye { width: 26px; height: 26px; border: 1px solid #585b70; border-radius: 4px; background: #313244; color: #cdd6f4; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }\n.iwb-editor-color-eye:hover { border-color: #e8a735; color: #e8a735; }\n\n/* 矢量对象独立画布:与位图图层统一参与 z 排序 */\n.iwb-editor-vec-canvas { position: absolute; top: 0; left: 0; z-index: 1; background: transparent !important; }\n\n/* 空白画布创建菜单 */\n.iwb-blank-menu { position: fixed; width: 242px; background: #fff; border: 1px solid #d0d7de; border-radius: 12px; box-shadow: 0 12px 32px rgba(15,23,42,.2); padding: 10px; z-index: 2147483000; font-size: 12px; color: #1f2328; }\n.iwb-blank-menu .iwb-blank-title { font-weight: 700; font-size: 12px; margin-bottom: 8px; }\n.iwb-blank-menu .iwb-blank-bg, .iwb-blank-menu .iwb-blank-res { display: flex; align-items: center; gap: 5px; margin-bottom: 7px; }\n.iwb-blank-menu .iwb-blank-bg span, .iwb-blank-menu .iwb-blank-res span { color: #656d76; min-width: 26px; }\n.iwb-blank-menu button { border: 1px solid #d0d7de; background: #f6f8fa; color: #1f2328; border-radius: 6px; padding: 3px 8px; cursor: pointer; font-size: 11px; }\n.iwb-blank-menu button:hover { background: #eff2f4; }\n.iwb-blank-menu button.on { background: #0ea5e9; border-color: #0ea5e9; color: #fff; }\n.iwb-blank-menu .iwb-blank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }\n.iwb-blank-menu .iwb-blank-grid button { display: flex; flex-direction: column; gap: 1px; align-items: center; padding: 5px 4px; }\n.iwb-blank-menu .iwb-blank-grid b { font-weight: 600; }\n.iwb-blank-menu .iwb-blank-grid i { font-style: normal; color: #656d76; font-size: 10px; }\n\n/* 空参考图节点:常驻“空白画布”按钮(位于节点顶部中央) */\n.iwb-blank-inline-btn { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 6; display: inline-flex; align-items: center; gap: 5px; background: #fff; border: 1px solid #d0d7de; border-radius: 14px; padding: 4px 11px; color: #0ea5e9; font-size: 11px; font-weight: 600; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }\n.iwb-blank-inline-btn:hover { background: #f0f9ff; border-color: #0ea5e9; }\n.iwb-blank-inline-btn svg { width: 13px; height: 13px; }\n\n/* ============ UI 布局重构(参照 excalidraw) ============ */\n/* 顶部:功能按钮在左,工具栏横排整行、按快捷键排序并带数字角标 */\n.iwb-editor-header { flex-wrap: wrap; }\n.iwb-editor-header > .iwb-editor-title { order: 1; }\n.iwb-editor-header > .iwb-editor-actions { order: 2; }\n.iwb-editor-header > .iwb-editor-tools {\n position: static;\n order: 3;\n flex: 1 1 100%;\n width: auto;\n left: auto;\n top: auto;\n margin-top: 8px;\n flex-direction: row;\n justify-content: center;\n padding: 6px 10px;\n border-radius: 10px;\n}\n.iwb-editor-tool { position: relative; }\n.iwb-tool-key {\n position: absolute;\n right: -3px;\n bottom: -3px;\n font-size: 8px;\n line-height: 1;\n background: #45475a;\n color: #cdd6f4;\n padding: 1px 3px;\n border-radius: 3px;\n pointer-events: none;\n font-style: normal;\n font-weight: 600;\n}\n.iwb-editor-tool.active .iwb-tool-key { background: #1e1e2e; color: #e8a735; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-divider { width: 1px; height: 22px; margin: 0 6px; }\n\n/* 左侧:工具参数设定栏(缩放/实心/图层/描边/硬度/透明度) */\n.iwb-editor-params {\n width: 216px;\n min-width: 216px;\n flex: 0 0 216px;\n flex-direction: column;\n align-items: stretch;\n gap: 12px;\n margin-left: 0;\n padding: 14px 12px;\n background: #181825;\n border-right: 1px solid #313244;\n overflow-y: auto;\n}\n.iwb-editor-params .iwb-editor-zoom { margin-left: 0; order: 0; }\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-val { min-width: 52px; text-align: center; }\n.iwb-editor-params .iwb-editor-layer-group { flex-wrap: wrap; justify-content: flex-start; }\n.iwb-editor-params .iwb-editor-brush-label { width: 100%; }\n.iwb-editor-params .iwb-editor-brush-presets { justify-content: flex-start; }\n.iwb-editor-params .iwb-editor-fill-btn { align-self: stretch; }\n.iwb-editor-main { display: flex; flex-direction: row; }\n\n/* ======== 布局重构 v2(按用户 6 点) ======== */\n.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }\n\n/* 顶部一行:标题 + 工具栏(含数字角标) + 撤销重做清空还原 */\n.iwb-editor-header { flex-wrap: nowrap; align-items: center; }\n.iwb-editor-header > .iwb-editor-title { order: 0; }\n.iwb-editor-header > .iwb-editor-tools {\n position: static; order: 1; flex: 1 1 auto; flex-basis: auto;\n margin-top: 0; width: auto; left: auto; top: auto;\n flex-direction: row; justify-content: center;\n padding: 0; background: transparent; border: 0; border-radius: 0;\n}\n.iwb-editor-header > .iwb-editor-divider { order: 2; }\n.iwb-editor-header > .iwb-editor-history { order: 3; display: flex; align-items: center; gap: 4px; }\n\n/* 左栏:调色板在上,参数竖排,导出按钮底部 */\n.iwb-editor-left {\n width: 240px; min-width: 240px; flex: 0 0 240px;\n display: flex; flex-direction: column; gap: 14px;\n padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;\n}\n.iwb-editor-left > .iwb-editor-color-panel { padding: 0; background: transparent; border-bottom: 0; }\n.iwb-editor-left > .iwb-editor-params {\n width: auto; min-width: 0; flex: 1 1 auto;\n flex-direction: column; align-items: stretch; gap: 12px; margin-left: 0; padding: 0;\n}\n.iwb-editor-left > .iwb-editor-export-actions {\n display: flex; flex-direction: column; gap: 8px;\n margin-top: auto; padding-top: 12px; border-top: 1px solid #313244;\n}\n.iwb-editor-left > .iwb-editor-export-actions .iwb-editor-btn { width: 100%; }\n\n/* 参数竖排:一行一个设置 */\n.iwb-editor-params .iwb-editor-brush-group { display: flex; flex-direction: column; gap: 10px; }\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-btn,\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-val { flex: 1 1 auto; }\n.iwb-editor-params .iwb-editor-layer-group { flex-wrap: wrap; }\n\n/* 颜色值后面的 实心/边线 切换 */\n.iwb-editor-fill-pair { display: inline-flex; margin-left: 6px; }\n.iwb-editor-fill-pair .iwb-editor-fill-btn { align-self: center; }\n\n/* ======== 布局优化 v3 ======== */\n/* 左栏可交互(避免被画布/层级遮挡导致“调节不起作用”) */\n.iwb-editor-left { position: relative; z-index: 40; pointer-events: auto; }\n.iwb-editor-left input, .iwb-editor-left select, .iwb-editor-left button, .iwb-editor-left label { pointer-events: auto; }\n\n/* 顶部工具栏内的 面/边(实心) 切换按钮 */\n.iwb-editor-tools .iwb-editor-fill-btn {\n width: 42px; height: 32px; padding: 0; border: 0; border-radius: 8px;\n background: transparent; color: #cdd6f4; cursor: pointer; font-size: 11px; font-weight: 600;\n}\n.iwb-editor-tools .iwb-editor-fill-btn:hover { background: #45475a; }\n.iwb-editor-tools .iwb-editor-fill-btn.active { background: #e8a735; color: #1e1e2e; }\n\n/* 右侧图层面板内的图层顺序按钮 */\n.iwb-editor-layer-panel .iwb-editor-layer-group {\n display: flex; align-items: center; gap: 6px;\n padding: 10px 12px; border-bottom: 1px solid #313244;\n}\n.iwb-editor-layer-panel .iwb-editor-layer-group .iwb-editor-constraint-label { color: #a6adc8; font-size: 12px; margin-right: 2px; }\n\n/* 缩放(画面调整)移到左栏下方 */\n.iwb-editor-params .iwb-editor-zoom {\n order: 99; margin-top: 10px; padding-top: 10px; border-top: 1px solid #313244;\n}\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-btn { flex: 0 0 auto; }\n.iwb-editor-params .iwb-editor-zoom .iwb-editor-zoom-val { flex: 0 0 auto; }\n\n/* ======== 布局优化 v4 ======== */\n/* 交换左右栏:图层在左,调色板/参数在右 */\n.iwb-editor-main { flex-direction: row; }\n.iwb-editor-main > .iwb-editor-layer-panel { order: 1; border-left: 0; border-right: 1px solid #313244; }\n.iwb-editor-main > .iwb-editor-canvas-wrap { order: 2; }\n.iwb-editor-left { order: 3; border-right: 0; border-left: 1px solid #313244; }\n\n/* 硬度/透明度 数值与滑块对齐 */\n.iwb-editor-params .iwb-editor-brush-label .iwb-editor-brush-hardness-val,\n.iwb-editor-params .iwb-editor-brush-label .iwb-editor-brush-opacity-val {\n min-width: 40px; text-align: right; color: #cdd6f4; font-size: 12px;\n}\n.iwb-editor-params .iwb-editor-brush-label input[type="range"] { flex: 1 1 auto; }\n\n/* 缩放块放在参数区最底部 */\n.iwb-editor-params .iwb-editor-zoom, .iwb-editor-left .iwb-editor-zoom {\n display: flex; align-items: center; justify-content: center; gap: 8px;\n width: 100%; padding: 8px 4px; border-top: 1px solid #313244; margin-top: 12px;\n}\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-btn {\n flex: 0 0 auto; min-width: 28px; height: 26px; background: #313244; color: #cdd6f4; border: 0; border-radius: 6px; cursor: pointer; font-size: 14px;\n}\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-btn:hover { background: #45475a; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-val { min-width: 52px; text-align: center; color: #cdd6f4; font: 600 12px sans-serif; }\n\n/* 调色板与下方参数调节之间的横线分割 */\n.iwb-editor-params { border-top: 1px solid #313244; padding-top: 12px; }\n\n/* 色相条指示器需定位父级相对 */\n.iwb-color-hue { position: relative; }\n\n/* 顶部实心按钮与工具匹配:默认背景 */\n.iwb-editor-tools .iwb-editor-fill-btn { background: #313244; color: #cdd6f4; }\n\n/* 裁剪工具条:三行展示(比例 / 尺寸 / 确认取消),避免被挤压 */\n.iwb-editor-crop-bar {\n display: flex;\n flex-direction: column;\n gap: 8px;\n align-items: center;\n padding: 10px 14px;\n}\n.iwb-editor-crop-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; width: 100%; gap: 6px; }\n.iwb-editor-crop-row .iwb-editor-constraint-group { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }\n.iwb-editor-crop-actions { gap: 10px; }\n.iwb-editor-crop-actions .iwb-editor-crop-info { min-width: 88px; text-align: center; }\n.iwb-editor-constraint-sep { display: none; }\n\n/* ======== 修复:左列(图层)占满高度,三列稳定布局 ======== */\n.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }\n.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 290px; min-width: 290px; width: 290px; }\n.iwb-editor-main > .iwb-editor-canvas-wrap { flex: 1 1 auto; min-width: 0; }\n.iwb-editor-left { flex: 0 0 240px; min-width: 240px; width: 240px; }\n.iwb-editor-layer-panel .iwb-editor-layer-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }\n\n/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */\n.iwb-editor-header > .iwb-editor-title { order: 0; }\n.iwb-editor-header > .iwb-editor-history { order: 1; display: flex; align-items: center; gap: 4px; }\n.iwb-editor-header > .iwb-editor-tools { order: 2; flex: 1 1 auto; justify-content: center; }\n.iwb-editor-header > .iwb-editor-export-actions { order: 3; display: flex; align-items: center; gap: 6px; margin-left: 4px; }\n\n/* 重置类(撤销/重做/清空/复原)统一小圆角按钮 */\n.iwb-editor-header .iwb-editor-history .iwb-editor-action {\n width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px;\n background: #313244; color: #cdd6f4; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;\n}\n.iwb-editor-header .iwb-editor-history .iwb-editor-action:hover { background: #45475a; }\n.iwb-editor-header .iwb-editor-history .iwb-editor-action-restore { background: #313244; color: #cdd6f4; }\n\n/* 保存类(新建/覆盖/退出)统一样式 */\n.iwb-editor-header .iwb-editor-export-actions .iwb-editor-btn {\n height: 30px; padding: 0 14px; border: 0; border-radius: 8px; font-size: 12px; font-weight: 600;\n background: #313244; color: #cdd6f4; cursor: pointer;\n}\n.iwb-editor-header .iwb-editor-export-actions .iwb-editor-btn:hover { background: #45475a; }\n\n/* 调色板与参数之间的分割线及间距 */\n.iwb-editor-left > .iwb-editor-params { border-top: 1px solid #313244; margin-top: 16px; padding-top: 16px; }\n\n/* 笔刷快捷值 7 档圆点 */\n.iwb-editor-brush-presets { display: flex; align-items: center; gap: 8px; }\n.iwb-editor-brush-preset i { width: 6px; height: 6px; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 8px; height: 8px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 10px; height: 10px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 13px; height: 13px; }\n.iwb-editor-brush-preset:nth-child(5) i { width: 16px; height: 16px; }\n.iwb-editor-brush-preset:nth-child(6) i { width: 20px; height: 20px; }\n.iwb-editor-brush-preset:nth-child(7) i { width: 24px; height: 24px; }\n\n/* 缩放:缩小比例、圆角 */\n.iwb-editor-left .iwb-editor-zoom { gap: 6px; padding: 6px 4px; margin-top: 10px; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-btn { min-width: 26px; height: 24px; border-radius: 8px; font-size: 13px; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-val { min-width: 44px; font-size: 11px; }\n.iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-fit { font-size: 11px; padding: 0 8px; }\n\n/* 笔刷快捷值:压缩横向间距,避免右栏出现横向滚动条 */\n.iwb-editor-left { overflow-x: hidden; }\n.iwb-editor-params { overflow-x: hidden; }\n.iwb-editor-brush-presets { gap: 3px; flex-wrap: wrap; max-width: 100%; justify-content: flex-start; }\n.iwb-editor-brush-preset { padding: 0 1px; min-width: 0; flex: 0 0 auto; }\n.iwb-editor-brush-preset i { width: 5px; height: 5px; }\n.iwb-editor-brush-preset:nth-child(2) i { width: 7px; height: 7px; }\n.iwb-editor-brush-preset:nth-child(3) i { width: 9px; height: 9px; }\n.iwb-editor-brush-preset:nth-child(4) i { width: 11px; height: 11px; }\n.iwb-editor-brush-preset:nth-child(5) i { width: 14px; height: 14px; }\n.iwb-editor-brush-preset:nth-child(6) i { width: 17px; height: 17px; }\n.iwb-editor-brush-preset:nth-child(7) i { width: 20px; height: 20px; }\n\n/* 去掉参数模块右侧的边线(隐藏纵向滚动条与右边框) */\n.iwb-editor-left { border-right: 0 !important; scrollbar-width: none; -ms-overflow-style: none; }\n.iwb-editor-left::-webkit-scrollbar { width: 0; height: 0; display: none; }\n.iwb-editor-left > .iwb-editor-params { border-right: 0; }\n.iwb-editor-brush-presets::-webkit-scrollbar { width: 0; height: 0; display: none; }\n\n/* 独立悬浮工具条(扩展自建,不插入应用 React DOM) */\n.iwb-cutout-toolbar {\n position: fixed; z-index: 2147483000; display: none; align-items: center; gap: 3px;\n padding: 4px 6px; border-radius: 14px; background: #fff;\n border: 1px solid #d0d7de; box-shadow: 0 8px 28px rgba(15, 23, 42, 0.14);\n pointer-events: auto;\n}\n.iwb-cutout-toolbar button {\n width: 30px; height: 28px; padding: 0; border: 0; border-radius: 8px;\n background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;\n}\n.iwb-cutout-toolbar button:hover { background: #eef2f7; }\n.iwb-cutout-toolbar button i { font-style: normal; font-size: 11px; font-weight: 700; }\n.iwb-cutout-toolbar button svg { display: block; }\n\n/* 顶部左右两组工具交换:左=新建/覆盖/退出,右=撤销/重做/清空/复原 */\n.iwb-editor-header > .iwb-editor-title { order: 0; }\n.iwb-editor-header > .iwb-editor-export-actions { order: 1; margin-left: 0; margin-right: 4px; }\n.iwb-editor-header > .iwb-editor-tools { order: 2; flex: 1 1 auto; justify-content: center; }\n.iwb-editor-header > .iwb-editor-history { order: 3; margin-left: 0; }\n\n/* 图层面板:放大锁定 / 删除按钮的点击区域与图标 */\n.iwb-editor-layer-panel .iwb-layer-lock,\n.iwb-editor-layer-panel .iwb-layer-del {\n width: 24px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center;\n}\n.iwb-editor-layer-panel .iwb-layer-lock svg,\n.iwb-editor-layer-panel .iwb-layer-del svg { width: 16px; height: 16px; }\n\n\n/* 图层按钮图标统一 14px */\n.iwb-editor-layer-panel .iwb-layer-vis svg,\n.iwb-editor-layer-panel .iwb-layer-lock svg,\n.iwb-editor-layer-panel .iwb-layer-del svg { width: 14px; height: 14px; }\n.iwb-editor-layer-panel .iwb-layer-vis,\n.iwb-editor-layer-panel .iwb-layer-lock,\n.iwb-editor-layer-panel .iwb-layer-del { width: 22px; height: 22px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }\n\n/* ================================================================\n v1.1 便利版 UI(单张处理)\n 只追加、不重写历史样式:旧规则里的魔数定位在这里统一覆盖。\n 分区:顶栏 / 就地选项栏 / 竖工具栏 / 画布浮层 / 状态栏 / toast\n ================================================================ */\n\n/* ---- 顶栏:精简、一步可达 ---- */\n.iwb-editor-header { min-height: 44px; padding: 6px 12px; gap: 8px; }\n.iwb-editor-title em.iwb-editor-doc-size { font-style: normal; font-weight: 400; font-size: 11px; color: #7f849c; margin-left: 6px; }\n.iwb-editor-optionbar {\n display: flex; align-items: center; gap: 10px;\n height: 36px; min-height: 36px; padding: 0 12px;\n background: #202033; border-bottom: 1px solid #313244;\n color: #a6adc8; font-size: 12px;\n}\n.iwb-editor-optionbar-label { color: #7f849c; font-weight: 600; white-space: nowrap; }\n.iwb-editor-optionbar-body { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }\n.iwb-opt-label { color: #a6adc8; white-space: nowrap; }\n.iwb-opt-btn {\n background: #313244; color: #cdd6f4; border: 1px solid transparent; border-radius: 5px;\n padding: 3px 9px; font-size: 12px; cursor: pointer;\n}\n.iwb-opt-btn:hover { background: #45475a; }\n.iwb-opt-btn.active { background: #4488ff; color: #fff; }\n.iwb-opt-num {\n width: 46px; padding: 2px 4px; background: #313244; color: #e8a735;\n border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;\n}\n.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }\n.iwb-opt-hint { color: #7f849c; font-size: 11px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n\n.iwb-editor-more-wrap, .iwb-editor-export-settings-wrap { position: relative; flex: 0 0 auto; z-index: 45; }\n.iwb-editor-more-btn, .iwb-editor-panel-toggle, .iwb-editor-export-settings-btn {\n background: #313244; color: #cdd6f4; border: 1px solid #45475a; border-radius: 6px;\n padding: 5px 10px; font-size: 12px; cursor: pointer; white-space: nowrap;\n}\n.iwb-editor-more-btn:hover, .iwb-editor-panel-toggle:hover, .iwb-editor-export-settings-btn:hover { background: #45475a; }\n.iwb-editor-panel-toggle { padding: 5px 8px; }\n.iwb-editor-export-summary { color: #e8a735; margin: 0 2px; }\n\n.iwb-editor-more-menu, .iwb-editor-export-settings {\n display: none; position: absolute; top: 34px; z-index: 60;\n background: #252537; border: 1px solid #45475a; border-radius: 8px;\n padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,0.45);\n}\n.iwb-editor-more-menu { left: 0; width: 206px; flex-direction: column; gap: 2px; }\n.iwb-editor-more-menu.open, .iwb-editor-export-settings.open { display: flex; flex-direction: column; gap: 4px; }\n.iwb-editor-export-settings { right: 0; width: 268px; }\n.iwb-editor-more-menu button, .iwb-editor-export-row button {\n background: transparent; color: #cdd6f4; border: 0; border-radius: 5px;\n padding: 6px 8px; font-size: 12px; text-align: left; cursor: pointer; white-space: nowrap;\n}\n.iwb-editor-more-menu button:hover, .iwb-editor-export-row button:hover { background: #3b3d52; }\n.iwb-editor-more-menu kbd { float: right; color: #7f849c; font-size: 10px; }\n.iwb-editor-more-sep { height: 1px; background: #45475a; margin: 4px 0; }\n.iwb-editor-export-row { display: flex; align-items: center; gap: 4px; }\n.iwb-editor-export-row > span { width: 34px; flex: 0 0 34px; color: #7f849c; font-size: 11px; }\n.iwb-editor-export-row button { flex: 1 1 auto; text-align: center; background: #313244; }\n.iwb-editor-export-row button.active { background: #4488ff; color: #fff; }\n.iwb-editor-export-note { color: #7f849c; font-size: 11px; border-top: 1px solid #313244; padding-top: 6px; }\n.iwb-editor-btn-download { background: #1a7f37 !important; color: #fff !important; }\n.iwb-editor-btn-download:hover { background: #15803d !important; }\n\n/* ---- 竖工具栏:真正固定在左侧,给 main 留出 56px ---- */\n.iwb-editor-header > .iwb-editor-tools {\n position: fixed !important; left: 8px !important; top: 112px !important;\n width: 40px !important; max-height: calc(100vh - 128px);\n flex-direction: column; padding: 5px !important; border-radius: 10px;\n overflow-y: auto; overflow-x: hidden; scrollbar-width: none; z-index: 50;\n}\n.iwb-editor-header > .iwb-editor-tools::-webkit-scrollbar { display: none; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-tool,\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { width: 30px !important; height: 30px !important; min-width: 30px; flex: 0 0 auto; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-divider { width: 22px; height: 1px; margin: 3px 0; flex: 0 0 auto; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-fill-btn { width: 30px !important; padding: 3px 0 !important; font-size: 10px; writing-mode: vertical-rl; }\n.iwb-editor-main { padding-left: 56px; }\n.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 260px !important; min-width: 260px !important; width: 260px !important; }\n.iwb-editor-left { flex: 0 0 220px !important; min-width: 220px !important; width: 220px !important; }\n.iwb-editor-overlay.panels-collapsed .iwb-editor-layer-panel,\n.iwb-editor-overlay.panels-collapsed .iwb-editor-left { display: none !important; }\n.iwb-editor-zoom-hint { display: none !important; }\n\n/* ---- 交互层:蚂蚁线 / 笔刷环各自独立,互不擦除 ---- */\n.iwb-editor-selection-overlay, .iwb-editor-cursor-overlay {\n position: absolute; top: 0; left: 0; display: block; pointer-events: none;\n background: transparent !important;\n}\n.iwb-editor-selection-overlay { z-index: 11; }\n.iwb-editor-cursor-overlay { z-index: 12; }\n\n/* ---- 选区浮动操作条(体验后再定去留;纯视图,可随时替换) ---- */\n.iwb-editor-sel-bar {\n display: none; position: absolute; z-index: 30; align-items: center; gap: 4px;\n padding: 5px 6px; background: rgba(24,24,37,0.96);\n border: 1px solid #45475a; border-radius: 8px;\n box-shadow: 0 8px 26px rgba(0,0,0,0.45); white-space: nowrap;\n}\n.iwb-editor-sel-bar.as-menu { border-color: #4488ff; }\n.iwb-editor-sel-bar .iwb-editor-sel-info {\n color: #7f849c; font-size: 11px; padding: 0 6px;\n border-right: 1px solid #45475a; margin-right: 2px; font-variant-numeric: tabular-nums;\n}\n.iwb-editor-sel-bar button {\n background: #313244; color: #cdd6f4; border: 1px solid transparent; border-radius: 5px;\n padding: 4px 8px; font-size: 12px; cursor: pointer;\n}\n.iwb-editor-sel-bar button:hover:not(:disabled) { background: #4488ff; color: #fff; }\n.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]:hover:not(:disabled) { background: #cf222e; }\n.iwb-editor-sel-bar button:disabled { opacity: 0.35; cursor: not-allowed; }\n\n/* ---- 状态栏 / toast ---- */\n.iwb-editor-statusbar {\n display: flex; align-items: center; gap: 14px;\n height: 26px; min-height: 26px; padding: 0 12px;\n background: #181825; border-top: 1px solid #313244;\n color: #a6adc8; font-size: 11px; font-variant-numeric: tabular-nums;\n}\n.iwb-editor-statusbar span + span { border-left: 1px solid #313244; padding-left: 14px; }\n.iwb-editor-status-tool { margin-left: auto; color: #e8a735; }\n.iwb-editor-toast {\n position: fixed; left: 50%; bottom: 46px; z-index: 1000000;\n transform: translate(-50%, 12px); opacity: 0; pointer-events: none;\n transition: opacity 0.2s, transform 0.2s;\n background: #313244; color: #cdd6f4; padding: 8px 14px; border-radius: 8px;\n font-size: 12px; max-width: 80vw; box-shadow: 0 8px 26px rgba(0,0,0,0.45);\n}\n.iwb-editor-toast.show { opacity: 1; transform: translate(-50%, 0); }\n.iwb-editor-toast-success { background: #1a7f37; color: #fff; }\n.iwb-editor-toast-error { background: #cf222e; color: #fff; }\n.iwb-editor-toast-warn { background: #b06a00; color: #fff; }\n.iwb-editor-toast-info { background: #2f6fed; color: #fff; }\n\n@media (max-width: 900px) {\n .iwb-opt-hint, .iwb-editor-optionbar-tip { display: none; }\n .iwb-editor-export-actions .iwb-editor-btn-cancel { display: none; }\n}\n\n\n/* 输出设置:按预设显示的行(尺寸/体积只属于电商方图)\n 注意 `.iwb-editor-export-row` 是 display:flex,会盖掉 UA 的 [hidden]{display:none},\n 必须显式 !important,否则 JS 设 hidden 后行还留在面板里。 */\n.iwb-editor-export-row[hidden] { display: none !important; }\n.iwb-editor-export-settings [data-export-key]:disabled {\n opacity: 0.32; cursor: not-allowed; text-decoration: line-through;\n}\n.iwb-editor-export-settings [data-export-key]:disabled:hover { background: #313244; }\n\n/* 选项栏参数控件(v1.2):滑杆 + 数字框 + 实时读数,一行放得下就该保持一行 */\n.iwb-opt-range {\n width: 84px; height: 4px; flex: 0 0 auto;\n accent-color: #4488ff; cursor: pointer;\n}\n.iwb-opt-val {\n min-width: 32px; flex: 0 0 auto; color: #e8a735; font-size: 11px;\n font-variant-numeric: tabular-nums; text-align: right;\n}\n.iwb-opt-unit { color: #7f849c; font-size: 11px; flex: 0 0 auto; }\n/* 窄屏:参数多到放不下时横向滚动,不换行(换行会把 36px 高的选项栏撑开压画布) */\n.iwb-editor-optionbar-body { overflow-x: auto; scrollbar-width: none; }\n.iwb-editor-optionbar-body::-webkit-scrollbar { display: none; }\n@media (max-width: 1100px) {\n .iwb-opt-range { width: 64px; }\n}\n'; // image-annotate/plugin/glue.js function createGlue(ctx, css) { diff --git a/image-annotate/tools/harness.mjs b/image-annotate/tools/harness.mjs index cc243ed..877b7fc 100644 --- a/image-annotate/tools/harness.mjs +++ b/image-annotate/tools/harness.mjs @@ -96,7 +96,7 @@ const boot = await page.evaluate((png) => { window.__commands['annotate-selected'].run().catch(() => {}) return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) } }, PNG) -check('产物可执行(循环打包未炸)', boot.version === '1.1.2', 'version=' + boot.version) +check('产物可执行(循环打包未炸)', boot.version === '1.2.0', '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 }) @@ -368,13 +368,20 @@ await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3, box2.x + box2.width * 0.6, box2.y + box2.height * 0.6) const selF = (await dbg()).selection await page.keyboard.press('Control+Shift+i') +const afterInvert = await dbg() await page.keyboard.press('Delete') +const afterDel = await dbg() const edgeAlphas = [] for (let dx = -6; dx <= 6; dx++) { edgeAlphas.push((await pixel(Math.round(selF.x) + dx, Math.round(selF.y + selF.h / 2))).draw[3]) } +const edgeDbg = await dbg() check('反选 + 羽化 6px:边界仍是渐变(羽化未因整幅掩膜失效)', - selF.feather === 6 && edgeAlphas.some(a => a > 0 && a < 255), JSON.stringify(edgeAlphas)) + selF.feather === 6 && edgeAlphas.some(a => a > 0 && a < 255), + JSON.stringify(edgeAlphas) + ' feather=' + selF.feather + ' active=' + edgeDbg.activeLayerId + + ' inv=' + (afterInvert.selection && afterInvert.selection.inverted) + + ' hist=' + afterDel.historyLabels.slice(-2).join('/') + + ' sel=' + JSON.stringify(afterDel.selection)) await page.keyboard.press('Control+z') await page.keyboard.press('Control+d') await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('0') @@ -436,6 +443,22 @@ check('裁剪后 Delete 不按旧 bbox 误擦(层数不变、底图仍有像 afterCropDelete.layers.length === cropped.layers.length && (await pixel(5, 5)).base[3] > 0 && afterCropDelete.selection === null) +// ---- 裁剪进历史链(v1.2 非破坏性):可撤销、可重做、不 flatten ---- +const cropLayers = cropped.layers.map(l => l.id) +await page.keyboard.press('Control+z') +const undoneCrop = await dbg() +check('裁剪可 Ctrl+Z:画布尺寸与图层结构都回到裁剪前', + undoneCrop.doc.w === 96 && undoneCrop.doc.h === 64 && + undoneCrop.layers.length === cropLayers.length && + cropLayers.every(id => undoneCrop.layers.some(l => l.id === id)), + 'doc=' + JSON.stringify(undoneCrop.doc) + ' layers=' + undoneCrop.layers.map(l => l.id).join(',')) +check('裁剪撤销后底图像素完整回填', (await pixel(5, 5)).base[3] > 0) +await page.keyboard.press('Control+Shift+z') +const redoneCrop = await dbg() +check('裁剪可重做:尺寸回到裁剪后', + redoneCrop.doc.w === cropped.doc.w && redoneCrop.doc.h === cropped.doc.h, + JSON.stringify(redoneCrop.doc)) + // ---- 还原原图的「尺寸复位」分支:必须走统一重绘,摘要/蚂蚁线才跟着走 ---- // (该分支会 setupCanvas + 清历史,此前只调 updateAllUI,摘要停留在裁剪后尺寸) const cropSummary = await summaryText() @@ -449,6 +472,44 @@ check('还原原图复位尺寸后:输出摘要即时跟随(不停留在裁 check('还原原图复位尺寸后蚂蚁线已停、选区已清', restoredDoc.ants === false && !restoredDoc.selection) +// ---- v1.2 选项栏:按工具出参数,形状线宽与画笔解耦 ---- +await page.locator('.iwb-editor-tool[data-tool="brush"]').click() +check('画笔选项栏:大小 / 硬度 / 透明三个参数都在', + (await page.locator('.iwb-editor-optionbar-body [data-opt="brushSize"]').count()) >= 2 && + (await page.locator('.iwb-editor-optionbar-body [data-opt="brushHardness"]').count()) === 1 && + (await page.locator('.iwb-editor-optionbar-body [data-opt="brushOpacity"]').count()) === 1) +const brushSizeBefore = (await dbg()).toolOptions.brushSize + +await page.locator('.iwb-editor-tool[data-tool="rect"]').click() +check('矩形选项栏:线宽 + 描边/实心', + (await page.locator('.iwb-editor-optionbar-body [data-opt="shapeLineWidth"]').count()) >= 2 && + (await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"]').count()) === 1) +await page.locator('.iwb-editor-optionbar-body input[type="number"][data-opt="shapeLineWidth"]').fill('12') +const optAfterLw = (await dbg()).toolOptions +check('选项栏改线宽:只改形状线宽,画笔大小不受影响(已解耦)', + optAfterLw.shapeLineWidth === 12 && optAfterLw.brushSize === brushSizeBefore, + JSON.stringify(optAfterLw)) +const shapesBefore = (await dbg()).shapes.length +const liveBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() +await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2, + liveBox.x + liveBox.width * 0.5, liveBox.y + liveBox.height * 0.5) +const shapesAfter = (await dbg()).shapes +check('新画的矩形直接用选项栏里的线宽 12', + shapesAfter.length === shapesBefore + 1 && shapesAfter[shapesAfter.length - 1].lw === 12, + JSON.stringify(shapesAfter.slice(-1))) +await page.keyboard.press('Control+z') + +// isTyping 修正:参数数字框里按 Ctrl+A / Delete 应该走画布命令,而不是被当打字吞掉 +await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() +await page.locator('.iwb-editor-optionbar-body input[data-opt="feather"]').fill('3') +await page.keyboard.press('Control+a') +const selAfterCtrlA = await dbg() +check('参数数字框里按 Ctrl+A 仍能全选(不再被当打字吞掉)', + Boolean(selAfterCtrlA.selection) && + selAfterCtrlA.selection.w === selAfterCtrlA.doc.w && selAfterCtrlA.selection.h === selAfterCtrlA.doc.h, + JSON.stringify(selAfterCtrlA.selection)) +await page.keyboard.press('Control+d') + // ---- Fix4:点「退出」必须结算宿主 Promise(glue.openEditor → onClose) ---- await page.locator('[data-action="cancel"]').click() const openState = await poll(async () => page.evaluate(() => window.__openState))