fix(image-annotate): 1.2.3 橡皮修复(漏 import getActiveLayer + 锁定层兜底)/钢笔描边实心切换/侧栏笔刷粗细移除/顶栏输出组右置

This commit is contained in:
qiqi committed 2026-11-04 20:44:52 +08:00
1 parent f50b734fd7
commit b83b8f3755
8 files changed
+190 -242

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/image-annotate",
"private": true,
"version": "1.2.2",
"version": "1.2.3",
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
"ibwPlugin": {
"id": "image-annotate",
+7 -1
View File
@@ -1318,7 +1318,9 @@
/* 顶部左右两组工具交换:左=新建/覆盖/退出,右=撤销/重做/清空/复原 */
.iwb-editor-header > .iwb-editor-title { order: 0; }
.iwb-editor-header > .iwb-editor-export-actions { order: 1; margin-left: 0; margin-right: 4px; }
/* 输出设定 + 下载/新建/覆盖/退出 收在顶栏最右侧(用户裁定 2026-11-04):
order 排最后 + margin-left:auto 兜底,中间工具区 flex:1 会把它顶到右端 */
.iwb-editor-header > .iwb-editor-export-actions { order: 9; margin-left: auto; margin-right: 0; flex: 0 0 auto; }
.iwb-editor-header > .iwb-editor-tools { order: 2; flex: 1 1 auto; justify-content: center; }
.iwb-editor-header > .iwb-editor-history { order: 3; margin-left: 0; }
@@ -1540,3 +1542,7 @@
.iwb-editor-optionbar-body .iwb-editor-crop-confirm:hover { background: #15803d; }
.iwb-editor-optionbar-body .iwb-editor-crop-cancel { background: #cf222e; color: #fff; }
.iwb-editor-optionbar-body .iwb-editor-crop-cancel:hover { background: #b91c1c; }
/* ---- v1.2.3:侧栏只留调色板 + 缩放 ---- */
/* 笔刷粗细/快捷点从侧栏移除后,缩放条直接挂在 aside 下:贴底,与调色板拉开距离 */
.iwb-editor-left > .iwb-editor-zoom { margin-top: auto; border-top: 1px solid #313244; padding-top: 10px; }
+2 -18
View File
@@ -164,24 +164,8 @@ import { bindEvents } from './events.js'
<aside class="iwb-editor-left">
<div class="iwb-editor-color-panel"><div class="iwb-editor-color-panel-title">调色板</div><div class="iwb-editor-color-picker2"><div class="iwb-color-sv"><span></span></div><div class="iwb-color-hue"><span></span></div></div><div class="iwb-editor-color-fields"><button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:点击后在画布取样"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button><input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7"></div><div class="iwb-editor-color-swatches"><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff4444" style="background:#ff4444" title="#ff4444"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff8800" style="background:#ff8800" title="#ff8800"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffd400" style="background:#ffd400" title="#ffd400"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#44dd44" style="background:#44dd44" title="#44dd44"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#00bfa5" style="background:#00bfa5" title="#00bfa5"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4488ff" style="background:#4488ff" title="#4488ff"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#aa44ff" style="background:#aa44ff" title="#aa44ff"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff66aa" style="background:#ff66aa" title="#ff66aa"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffffff" style="background:#ffffff" title="#ffffff"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#b8b8b8" style="background:#b8b8b8" title="#b8b8b8"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#555555" style="background:#555555" title="#555555"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button></div></div>
<div class="iwb-editor-params">
<label class="iwb-editor-brush-label">描边
<input type="range" class="iwb-editor-brush-size" min="1" max="300" value="3">
<input type="number" class="iwb-editor-brush-num" min="1" max="300" step="1" value="3" title="输入精确笔刷大小(1~300)">
</label>
<div class="iwb-editor-brush-presets" aria-label="描边快捷值">
<button type="button" class="iwb-editor-brush-preset" data-brush-size="2" title="描边 2"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="4" title="描边 4"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="8" title="描边 8"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="12" title="描边 12"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="16" title="描边 16"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="24" title="描边 24"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="32" title="描边 32"><i></i></button>
</div>
<!-- 硬度/透明滑杆已移除:与就地选项栏(画笔/橡皮工具态)完全重复,参数只留选项栏一处 -->
</div>
<!-- 描边粗细/快捷点已从侧栏移除(用户裁定 2026-11-04):都收进工具选项栏一处,
侧栏只保留调色板与缩放,避免「同一参数两个入口、数值还对不上」 -->
<div class="iwb-editor-zoom">
<button class="iwb-editor-zoom-btn" data-action="zoomOut" title="缩小 (滚轮向下)">−</button>
<span class="iwb-editor-zoom-val" title="滚轮缩放">100%</span>
+55 -96
View File
@@ -8,7 +8,7 @@
import { S, ZOOM_STEP, runtime } from './state.js'
import { ROT_CURSOR, clamp, getPos, isOverRotationHandle, setView, setZoomFit, zoomStep } from './viewport.js'
import { addBitmapLayer, addBlankLayer, applyBitmapDrag, beginBitmapDrag, clearSelection, ensureWritableLayer, getActiveCtx, hitBitmapHandle, removeVecCanvas, renderLayerPanel } from './layers.js'
import { addBitmapLayer, addBlankLayer, applyBitmapDrag, beginBitmapDrag, clearSelection, ensureWritableLayer, getActiveCtx, getActiveLayer, hitBitmapHandle, removeVecCanvas, renderLayerPanel } from './layers.js'
import { applyColorChange, beginStroke, clearToolRing, drawToolRing, endStroke, eraseSegment, exitPicker, hidePickerTip, sampleColor, setTool, showPickerTip, strokeSegment } from './tools.js'
import { beginMarquee, updateMarquee, endMarquee, beginLasso, updateLasso, endLasso, clearMarquee, syncAnts, renderSelection } from './selection.js'
import { runCommand, toast } from './commands.js'
@@ -223,11 +223,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
strokeSegment(pos.x, pos.y, pos.x, pos.y)
}
/** 橡皮工具的按下:与画笔同构但**不自动建层**(减内容语义,没有可写层就忽略),
* 同样把面板高亮同步到真正的擦除目标。 */
/** 橡皮工具的按下:与画笔同构但**不自动建层**(减内容语义,没有可擦的内容就不该凭空建层),
* 同样把面板高亮同步到真正的擦除目标。
* 兜底:默认的「原图」层是锁定态,此时退到最上层可写的标注层 ——
* 否则用户刚打开图就用橡皮,会表现为「橡皮完全没反应」(2026-11-04 反馈)。 */
function onEraserMouseDown(pos) {
const layer = getActiveLayer()
if (!layer || layer.locked) return
let layer = getActiveLayer()
if (!layer || layer.locked) layer = topWritableLayer()
if (!layer) { toast('没有可擦的图层:先用画笔标注,或在图层面板新建一层', 'info'); return }
S.activeLayerId = layer.id
S.selectedLayerId = layer.id
S.isDrawing = true
saveSnapshot()
@@ -235,6 +239,16 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
eraseSegment(pos.x, pos.y, pos.x, pos.y)
}
/** 最上层可写(未锁定/可见)的标注图层;没有返回 null */
function topWritableLayer() {
let hit = null
for (const l of S.layers) {
if (l.locked || l.visible === false) continue
if (!hit || (l.z || 0) >= (hit.z || 0)) hit = l
}
return hit
}
/** 钢笔工具的按下:回到起点则闭合路径,否则追加一个路径点 */
function onPenMouseDown(pos) {
if (!S.penPath) S.penPath = { pts: [], preview: null, closed: false }
@@ -760,31 +774,14 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
}
}
/** 画笔大小/硬度/透明曾经在侧栏也有一份,2026-11-04 起只保留工具选项栏一处,
* 这两个函数退化为「把值同步进选项栏」,保留名字是因为 tools/layers 还在调用。 */
function updateBrushUI() {
const slider = runtime.el.querySelector('.iwb-editor-brush-size')
if (!slider) return
slider.value = S.brushSize
const num = runtime.el.querySelector('.iwb-editor-brush-num')
if (num && document.activeElement !== num) num.value = S.brushSize
syncOptionBar()
}
/** 画笔参数组(硬度/透明度):画笔与橡皮工具共用 */
export function updateBrushParamUI() {
const g = runtime.el.querySelector('.iwb-editor-brush-group')
if (!g) return
g.style.display = (S.tool === 'brush' || S.tool === 'eraser') ? 'flex' : 'none'
const oLabel = g.querySelector('.iwb-editor-opacity-label')
if (oLabel) oLabel.style.display = (S.tool === 'brush' || S.tool === 'eraser') ? '' : 'none'
const h = g.querySelector('.iwb-editor-brush-hardness')
if (h) {
h.value = S.brushHardness
g.querySelector('.iwb-editor-brush-hardness-val').textContent = S.brushHardness
}
const o = g.querySelector('.iwb-editor-brush-opacity')
if (o) {
o.value = Math.round(S.brushOpacity * 100)
g.querySelector('.iwb-editor-brush-opacity-val').textContent = Math.round(S.brushOpacity * 100) + '%'
}
syncOptionBar()
}
function updateFillUI() {
@@ -853,6 +850,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`
}
/** 描边/实心切换按钮组:owner 区分两套默认值(rect=矩形/圆,pen=钢笔)。
* 钢笔只在闭合路径上才有填充面积,但开关本身一直可点,便于先选后画。 */
function fillStyleHTML(owner) {
const fill = owner === 'pen' ? S.penFill : S.rectFill
return `<span class="iwb-opt-label">样式</span>
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke">描边</button>
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill">实心</button>`
}
/** 每个工具只露最常用的 2–4 个参数,全部直接写回 S(右侧参数面板同步) */
function optionBarHTML(tool) {
if (tool === 'crop') return cropOptionHTML()
@@ -869,14 +875,18 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (tool === 'rect' || tool === 'circle') {
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
+ `<span class="iwb-opt-label">样式</span>
<button class="iwb-opt-btn${S.rectFill ? '' : ' active'}" data-opt-toggle="stroke" data-value="stroke">描边</button>
<button class="iwb-opt-btn${S.rectFill ? ' active' : ''}" data-opt-toggle="fill" data-value="fill">实心</button>`
+ fillStyleHTML('rect')
}
if (tool === 'arrow' || tool === 'pen') {
if (tool === 'arrow') {
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
+ `<span class="iwb-opt-hint">${tool === 'pen' ? '逐点点击,点回起点闭合' : '拖出箭头,松手完成'}</span>`
+ '<span class="iwb-opt-hint">拖出箭头,松手完成</span>'
}
if (tool === 'pen') {
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
+ fillStyleHTML('pen')
+ '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>'
}
if (tool === 'text') {
return rangeOpt('textSize', '字号', 8, 400, S.textSize, 'px')
@@ -935,7 +945,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
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'))
const cur = btn.dataset.fillOwner === 'pen' ? S.penFill : S.rectFill
btn.classList.toggle('active', !!cur === (btn.dataset.value === 'fill'))
})
}
@@ -984,15 +995,20 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (committed) textSnapDone = false
}
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个 */
function setShapeFill(fill) {
S.rectFill = !!fill
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
* owner='rect' 作用于矩形/圆,owner='pen' 作用于钢笔闭合路径。 */
function setShapeFill(fill, owner) {
const isPen = owner === 'pen'
if (isPen) S.penFill = !!fill
else S.rectFill = !!fill
updateFillUI()
syncOptionBar()
const sh = getSelectedShape()
if (sh && (sh.type === 'rect' || sh.type === 'circle') && !sh.locked) {
const types = isPen ? ['pen'] : ['rect', 'circle']
if (sh && types.indexOf(sh.type) >= 0 && !sh.locked) {
saveSnapshot('填充')
sh.fill = S.rectFill
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
renderObjects()
}
}
@@ -1103,7 +1119,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const toggle = e.target.closest('[data-opt-toggle]')
if (toggle) {
e.stopPropagation()
setShapeFill(toggle.dataset.value === 'fill')
setShapeFill(toggle.dataset.value === 'fill', toggle.dataset.fillOwner)
return
}
// 快捷值圆点:笔刷大小 / 矢量描边(用户裁定进选项栏)
@@ -1184,8 +1200,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
bindColorPalette()
bindFillToggle()
bindLayerOrderButtons()
bindBrushSizeControls()
bindBrushParams()
bindZoomButtons()
bindHistoryActions()
bindLayerAddActions()
@@ -1288,61 +1302,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
})
}
/** 笔触粗细:预设按钮 + 滑杆 + 数值输入框双向同步 */
function bindBrushSizeControls() {
// 笔触(滑杆 + 数值输入框双向同步)
const slider = runtime.el.querySelector('.iwb-editor-brush-size')
const brushNum = runtime.el.querySelector('.iwb-editor-brush-num')
let lwHistoryPushed = false
const syncBrushSize = (value, continuous) => {
const v = clamp(parseInt(value, 10) || 1, 1, 300)
S.brushSize = v
slider.value = v
if (brushNum && document.activeElement !== brushNum) brushNum.value = v
// 选中形状(矩形/圆形/箭头/钢笔)时同步更新描边粗细
const sh = getSelectedShape()
if (sh && !sh.locked && sh.lw !== v) {
if (!continuous || !lwHistoryPushed) { saveSnapshot(); lwHistoryPushed = true }
sh.lw = v
renderObjects()
renderLayerPanel()
}
if (!continuous) lwHistoryPushed = false
}
runtime.el.querySelectorAll('.iwb-editor-brush-preset').forEach(btn => {
btn.addEventListener('mousedown', (e) => e.stopPropagation())
btn.addEventListener('click', () => syncBrushSize(btn.dataset.brushSize, false))
})
slider && slider.addEventListener('input', () => syncBrushSize(slider.value, true))
slider && slider.addEventListener('change', () => syncBrushSize(slider.value, false))
if (brushNum) {
brushNum.addEventListener('mousedown', (e) => e.stopPropagation())
brushNum.addEventListener('input', () => {
const v = clamp(parseInt(brushNum.value, 10) || 1, 1, 300)
syncBrushSize(v, true)
})
brushNum.addEventListener('blur', () => { brushNum.value = S.brushSize; lwHistoryPushed = false })
}
}
/** 画笔硬度与透明度滑杆 */
function bindBrushParams() {
// 画笔硬度
const hardnessSlider = runtime.el.querySelector('.iwb-editor-brush-hardness')
hardnessSlider && hardnessSlider.addEventListener('input', () => {
S.brushHardness = parseInt(hardnessSlider.value, 10)
runtime.el.querySelector('.iwb-editor-brush-hardness-val').textContent = S.brushHardness
})
// 画笔透明度
const opacitySlider = runtime.el.querySelector('.iwb-editor-brush-opacity')
opacitySlider && opacitySlider.addEventListener('input', () => {
S.brushOpacity = parseInt(opacitySlider.value, 10) / 100
runtime.el.querySelector('.iwb-editor-brush-opacity-val').textContent = opacitySlider.value + '%'
if (S.strokeCanvas) S.strokeCanvas.style.opacity = S.brushOpacity
})
}
/** 缩放按钮:缩小 / 放大 / 适应窗口 */
function bindZoomButtons() {
// 缩放按钮
@@ -1462,7 +1421,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(1, S.shapeLineWidth), 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.penFill && !!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()
}
+2 -1
View File
@@ -299,7 +299,8 @@ import { toast } from './commands.js'
brushOpacity: S.brushOpacity,
shapeLineWidth: S.shapeLineWidth,
textSize: S.textSize,
rectFill: S.rectFill
rectFill: S.rectFill,
penFill: S.penFill
},
history: S.history.length,
historyLabels: S.history.map(s => s.__label || ''),
+1
View File
@@ -22,6 +22,7 @@
prevTool: null, // 吸管工具激活前的工具(取色后切回)
pickerComposite: null, // 吸管取样用的合成画布缓存(切工具/画布变化时失效)
rectFill: false, // 矩形/圆形是否实心填充
penFill: true, // 钢笔闭合路径是否实心填充(只对闭合路径有意义)
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
+55 -116
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.2.2',
version: '1.2.3',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -43,6 +43,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
// 吸管取样用的合成画布缓存(切工具/画布变化时失效)
rectFill: false,
// 矩形/圆形是否实心填充
penFill: true,
// 钢笔闭合路径是否实心填充(只对闭合路径有意义)
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
shapeLineWidth: 3,
@@ -489,7 +491,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.lineTo(x2, y2);
ctx.stroke();
ctx.restore();
const active = getActiveLayer2();
const active = getActiveLayer();
if (active && active.id === "draw" && active.sourceCanvas) {
const sourceCtx = active.sourceCanvas.getContext("2d", { willReadFrequently: true });
sourceCtx.save();
@@ -518,7 +520,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
layer._bounds = void 0;
}
function beginStroke() {
bakeDrawableLayer(getActiveLayer2());
bakeDrawableLayer(getActiveLayer());
S.strokeCanvas.width = S.imgW;
S.strokeCanvas.height = S.imgH;
S.strokeCtx.clearRect(0, 0, S.imgW, S.imgH);
@@ -538,7 +540,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.drawImage(S.strokeCanvas, 0, 0);
ctx.restore();
S.strokeCanvas.style.display = "none";
const active = getActiveLayer2();
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();
@@ -1450,11 +1452,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
el.style.display = u.obj.visible === false ? "none" : "block";
}
}
function getActiveLayer2() {
function getActiveLayer() {
return S.layers.find((l) => l.id === S.activeLayerId) || null;
}
function getActiveCtx() {
const layer = getActiveLayer2();
const layer = getActiveLayer();
return layer && !layer.locked ? layer.ctx : null;
}
function clearSelection({ keepBitmap = false } = {}) {
@@ -1717,7 +1719,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
placeImageDirectly(img);
}
function ensureWritableLayer() {
const current = getActiveLayer2();
const current = getActiveLayer();
if (current && !current.locked) return current;
const id = S.layers.some((l) => l.id === "draw") ? "L" + Date.now() + Math.floor(Math.random() * 1e3) : "draw";
const canvas = createLayerCanvas();
@@ -2423,7 +2425,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return { canvas: c, x: e.x - pad, y: e.y - pad, w, h };
}
function writableLayer() {
const layer = getActiveLayer2();
const layer = getActiveLayer();
if (!layer || layer.locked) {
toast(layer && layer.locked ? "当前图层已锁定,请先解锁" : "没有可用的图层", "warn");
return null;
@@ -2792,24 +2794,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<aside class="iwb-editor-left">
<div class="iwb-editor-color-panel"><div class="iwb-editor-color-panel-title">调色板</div><div class="iwb-editor-color-picker2"><div class="iwb-color-sv"><span></span></div><div class="iwb-color-hue"><span></span></div></div><div class="iwb-editor-color-fields"><button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:点击后在画布取样"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button><input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7"></div><div class="iwb-editor-color-swatches"><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff4444" style="background:#ff4444" title="#ff4444"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff8800" style="background:#ff8800" title="#ff8800"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffd400" style="background:#ffd400" title="#ffd400"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#44dd44" style="background:#44dd44" title="#44dd44"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#00bfa5" style="background:#00bfa5" title="#00bfa5"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4488ff" style="background:#4488ff" title="#4488ff"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#aa44ff" style="background:#aa44ff" title="#aa44ff"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff66aa" style="background:#ff66aa" title="#ff66aa"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffffff" style="background:#ffffff" title="#ffffff"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#b8b8b8" style="background:#b8b8b8" title="#b8b8b8"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#555555" style="background:#555555" title="#555555"></button><button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button></div></div>
<div class="iwb-editor-params">
<label class="iwb-editor-brush-label">描边
<input type="range" class="iwb-editor-brush-size" min="1" max="300" value="3">
<input type="number" class="iwb-editor-brush-num" min="1" max="300" step="1" value="3" title="输入精确笔刷大小(1~300)">
</label>
<div class="iwb-editor-brush-presets" aria-label="描边快捷值">
<button type="button" class="iwb-editor-brush-preset" data-brush-size="2" title="描边 2"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="4" title="描边 4"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="8" title="描边 8"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="12" title="描边 12"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="16" title="描边 16"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="24" title="描边 24"><i></i></button>
<button type="button" class="iwb-editor-brush-preset" data-brush-size="32" title="描边 32"><i></i></button>
</div>
<!-- 硬度/透明滑杆已移除:与就地选项栏(画笔/橡皮工具态)完全重复,参数只留选项栏一处 -->
</div>
<!-- 描边粗细/快捷点已从侧栏移除(用户裁定 2026-11-04):都收进工具选项栏一处,
侧栏只保留调色板与缩放,避免「同一参数两个入口、数值还对不上」 -->
<div class="iwb-editor-zoom">
<button class="iwb-editor-zoom-btn" data-action="zoomOut" title="缩小 (滚轮向下)">−</button>
<span class="iwb-editor-zoom-val" title="滚轮缩放">100%</span>
@@ -3090,14 +3076,27 @@ var __IWB_ANNOTATE_MANIFEST__ = {
strokeSegment(pos.x, pos.y, pos.x, pos.y);
}
function onEraserMouseDown(pos) {
const layer = getActiveLayer();
if (!layer || layer.locked) return;
let layer = getActiveLayer();
if (!layer || layer.locked) layer = topWritableLayer();
if (!layer) {
toast("没有可擦的图层:先用画笔标注,或在图层面板新建一层", "info");
return;
}
S.activeLayerId = layer.id;
S.selectedLayerId = layer.id;
S.isDrawing = true;
saveSnapshot();
beginStroke();
eraseSegment(pos.x, pos.y, pos.x, pos.y);
}
function topWritableLayer() {
let hit = null;
for (const l of S.layers) {
if (l.locked || l.visible === false) continue;
if (!hit || (l.z || 0) >= (hit.z || 0)) hit = l;
}
return hit;
}
function onPenMouseDown(pos) {
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) };
@@ -3615,28 +3614,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
}
function updateBrushUI() {
const slider = runtime.el.querySelector(".iwb-editor-brush-size");
if (!slider) return;
slider.value = S.brushSize;
const num = runtime.el.querySelector(".iwb-editor-brush-num");
if (num && document.activeElement !== num) num.value = S.brushSize;
syncOptionBar();
}
function updateBrushParamUI() {
const g = runtime.el.querySelector(".iwb-editor-brush-group");
if (!g) return;
g.style.display = S.tool === "brush" || S.tool === "eraser" ? "flex" : "none";
const oLabel = g.querySelector(".iwb-editor-opacity-label");
if (oLabel) oLabel.style.display = S.tool === "brush" || S.tool === "eraser" ? "" : "none";
const h = g.querySelector(".iwb-editor-brush-hardness");
if (h) {
h.value = S.brushHardness;
g.querySelector(".iwb-editor-brush-hardness-val").textContent = S.brushHardness;
}
const o = g.querySelector(".iwb-editor-brush-opacity");
if (o) {
o.value = Math.round(S.brushOpacity * 100);
g.querySelector(".iwb-editor-brush-opacity-val").textContent = Math.round(S.brushOpacity * 100) + "%";
}
syncOptionBar();
}
function updateFillUI() {
const b = runtime.el.querySelector('[data-action="toggleFill"]');
@@ -3700,6 +3681,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<button type="button" class="iwb-editor-crop-cancel" data-action="cancelCrop" title="Esc">✗ 取消</button>
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`;
}
function fillStyleHTML(owner) {
const fill = owner === "pen" ? S.penFill : S.rectFill;
return `<span class="iwb-opt-label">样式</span>
<button class="iwb-opt-btn${fill ? "" : " active"}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke">描边</button>
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill">实心</button>`;
}
function optionBarHTML(tool) {
if (tool === "crop") return cropOptionHTML();
if (tool === "brush" || tool === "eraser") {
@@ -3711,12 +3698,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<span class="iwb-opt-val" data-opt-val="brushOpacity">${Math.round(S.brushOpacity * 100)}%</span>`;
}
if (tool === "rect" || tool === "circle") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + `<span class="iwb-opt-label">样式</span>
<button class="iwb-opt-btn${S.rectFill ? "" : " active"}" data-opt-toggle="stroke" data-value="stroke">描边</button>
<button class="iwb-opt-btn${S.rectFill ? " active" : ""}" data-opt-toggle="fill" data-value="fill">实心</button>`;
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + fillStyleHTML("rect");
}
if (tool === "arrow" || tool === "pen") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + `<span class="iwb-opt-hint">${tool === "pen" ? "逐点点击,点回起点闭合" : "拖出箭头,松手完成"}</span>`;
if (tool === "arrow") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + '<span class="iwb-opt-hint">拖出箭头,松手完成</span>';
}
if (tool === "pen") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + fillStyleHTML("pen") + '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>';
}
if (tool === "text") {
return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + '<span class="iwb-opt-hint">点画布输入文字,Enter 确认</span>';
@@ -3772,7 +3760,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
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"));
const cur = btn.dataset.fillOwner === "pen" ? S.penFill : S.rectFill;
btn.classList.toggle("active", !!cur === (btn.dataset.value === "fill"));
});
}
function updateStatusbar() {
@@ -3821,14 +3810,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
renderObjects();
if (committed) textSnapDone = false;
}
function setShapeFill(fill) {
S.rectFill = !!fill;
function setShapeFill(fill, owner) {
const isPen = owner === "pen";
if (isPen) S.penFill = !!fill;
else S.rectFill = !!fill;
updateFillUI();
syncOptionBar();
const sh = getSelectedShape();
if (sh && (sh.type === "rect" || sh.type === "circle") && !sh.locked) {
const types = isPen ? ["pen"] : ["rect", "circle"];
if (sh && types.indexOf(sh.type) >= 0 && !sh.locked) {
saveSnapshot("填充");
sh.fill = S.rectFill;
sh.fill = isPen ? !!S.penFill && !!sh.closed : !!S.rectFill;
renderObjects();
}
}
@@ -3934,7 +3926,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
const toggle = e.target.closest("[data-opt-toggle]");
if (toggle) {
e.stopPropagation();
setShapeFill(toggle.dataset.value === "fill");
setShapeFill(toggle.dataset.value === "fill", toggle.dataset.fillOwner);
return;
}
const dot = e.target.closest("[data-opt-preset]");
@@ -4011,8 +4003,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
bindColorPalette();
bindFillToggle();
bindLayerOrderButtons();
bindBrushSizeControls();
bindBrushParams();
bindZoomButtons();
bindHistoryActions();
bindLayerAddActions();
@@ -4144,58 +4134,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
btn.addEventListener("click", () => moveLayer(btn.dataset.layer));
});
}
function bindBrushSizeControls() {
const slider = runtime.el.querySelector(".iwb-editor-brush-size");
const brushNum = runtime.el.querySelector(".iwb-editor-brush-num");
let lwHistoryPushed = false;
const syncBrushSize = (value, continuous) => {
const v = clamp(parseInt(value, 10) || 1, 1, 300);
S.brushSize = v;
slider.value = v;
if (brushNum && document.activeElement !== brushNum) brushNum.value = v;
const sh = getSelectedShape();
if (sh && !sh.locked && sh.lw !== v) {
if (!continuous || !lwHistoryPushed) {
saveSnapshot();
lwHistoryPushed = true;
}
sh.lw = v;
renderObjects();
renderLayerPanel();
}
if (!continuous) lwHistoryPushed = false;
};
runtime.el.querySelectorAll(".iwb-editor-brush-preset").forEach((btn) => {
btn.addEventListener("mousedown", (e) => e.stopPropagation());
btn.addEventListener("click", () => syncBrushSize(btn.dataset.brushSize, false));
});
slider && slider.addEventListener("input", () => syncBrushSize(slider.value, true));
slider && slider.addEventListener("change", () => syncBrushSize(slider.value, false));
if (brushNum) {
brushNum.addEventListener("mousedown", (e) => e.stopPropagation());
brushNum.addEventListener("input", () => {
const v = clamp(parseInt(brushNum.value, 10) || 1, 1, 300);
syncBrushSize(v, true);
});
brushNum.addEventListener("blur", () => {
brushNum.value = S.brushSize;
lwHistoryPushed = false;
});
}
}
function bindBrushParams() {
const hardnessSlider = runtime.el.querySelector(".iwb-editor-brush-hardness");
hardnessSlider && hardnessSlider.addEventListener("input", () => {
S.brushHardness = parseInt(hardnessSlider.value, 10);
runtime.el.querySelector(".iwb-editor-brush-hardness-val").textContent = S.brushHardness;
});
const opacitySlider = runtime.el.querySelector(".iwb-editor-brush-opacity");
opacitySlider && opacitySlider.addEventListener("input", () => {
S.brushOpacity = parseInt(opacitySlider.value, 10) / 100;
runtime.el.querySelector(".iwb-editor-brush-opacity-val").textContent = opacitySlider.value + "%";
if (S.strokeCanvas) S.strokeCanvas.style.opacity = S.brushOpacity;
});
}
function bindZoomButtons() {
bindIf('[data-action="zoomOut"]', "click", (e) => {
e.stopPropagation();
@@ -4299,7 +4237,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(1, S.shapeLineWidth), 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.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter };
S.shapeLayers.push(shape);
selectUnit("shape", shape.id);
S.penPath = null;
@@ -6091,7 +6029,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
brushOpacity: S.brushOpacity,
shapeLineWidth: S.shapeLineWidth,
textSize: S.textSize,
rectFill: S.rectFill
rectFill: S.rectFill,
penFill: S.penFill
},
history: S.history.length,
historyLabels: S.history.map((s) => s.__label || ""),
@@ -6118,7 +6057,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
};
// image-annotate/plugin/editor.css
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
// image-annotate/plugin/glue.js
function createGlue(ctx, css) {
+67 -9
View File
@@ -96,7 +96,7 @@ const boot = await page.evaluate((png) => {
window.__commands['annotate-selected'].run().catch(() => {})
return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) }
}, PNG)
check('产物可执行(循环打包未炸)', boot.version === '1.2.2', 'version=' + boot.version)
check('产物可执行(循环打包未炸)', boot.version === '1.2.3', '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 })
@@ -136,13 +136,12 @@ check('打开编辑器默认只有「原图」1 层,且状态栏不再写「
!(await page.locator('.iwb-editor-status-layer').textContent()).includes('画笔标注'),
JSON.stringify((await dbg()).layers.map(l => l.name)))
check('侧栏保留调色板 + 笔刷大小(滑杆/数字/快捷点),硬度/透明滑杆已移除(只在选项栏)',
check('侧栏只剩调色板 + 缩放:笔刷大小/快捷点已移除(都收进工具选项栏,2026-11-04 用户裁定)',
await page.evaluate(() => {
const q = (s) => Boolean(document.querySelector(s))
return q('.iwb-editor-color-panel') && q('.iwb-color-sv') &&
q('.iwb-editor-brush-size') && q('.iwb-editor-brush-num') &&
document.querySelectorAll('.iwb-editor-brush-preset').length >= 6 &&
!q('.iwb-editor-brush-hardness') && !q('.iwb-editor-brush-opacity')
return q('.iwb-editor-color-panel') && q('.iwb-color-sv') && q('.iwb-editor-zoom') &&
!q('.iwb-editor-brush-size') && !q('.iwb-editor-brush-num') &&
document.querySelectorAll('.iwb-editor-brush-preset').length === 0
}))
const drag = async (x1, y1, x2, y2) => {
@@ -543,9 +542,12 @@ await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
check('画笔选项栏有 7 个大小快捷点',
(await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"]').count()) === 7)
await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"][data-value="12"]').click()
check('点快捷点 12:笔刷大小即时生效且侧栏滑杆同步',
check('点快捷点 12:笔刷大小即时生效且选项栏数字框同步',
(await dbg()).toolOptions.brushSize === 12 &&
await page.evaluate(() => Number(document.querySelector('.iwb-editor-brush-size').value) === 12))
await page.evaluate(() => {
const n = document.querySelector('.iwb-editor-optionbar-body input[type="number"][data-opt="brushSize"]')
return n && Number(n.value) === 12
}))
// 快捷点:矢量描边
await page.locator('.iwb-editor-tool[data-tool="arrow"]').click()
@@ -598,7 +600,63 @@ check('Enter 确认裁剪(画布尺寸变小、与按钮确认等效)',
JSON.stringify(docBeforeEnter) + ' → ' + JSON.stringify(docAfterEnter))
await page.keyboard.press('Control+z')
// ---- Fix4:点「退出」必须结算宿主 Promise(glue.openEditor → onClose) ----
// ---- v1.2.3:橡皮修复 / 钢笔描边实心 / 顶栏输出组右置 ----
// 顶栏输出组(输出+下载+新建+覆盖+退出)贴最右(header 右内边距 12px)
check('顶栏输出/导出按钮组贴最右侧(用户裁定 2026-11-04)', await page.evaluate(() => {
const hdr = document.querySelector('.iwb-editor-header')
const ex = document.querySelector('.iwb-editor-header > .iwb-editor-export-actions')
const hist = document.querySelector('.iwb-editor-header > .iwb-editor-history')
if (!hdr || !ex || !hist) return false
const h = hdr.getBoundingClientRect(), e = ex.getBoundingClientRect()
return h.right - e.right <= 14 && e.left > hist.getBoundingClientRect().right
}))
// 橡皮:1.2.2 回归 —— events.js 少 import getActiveLayer,一按下就 ReferenceError,表现为「橡皮不能擦」
// 注意 pixel() 探针要的是图片坐标,不是屏幕坐标:liveBox 上的比例 = 图片上的比例
const IMG = { x: Math.round((await dbg()).doc.w * 0.42), y: Math.round((await dbg()).doc.h * 0.5) }
const probe = (id) => page.evaluate(({ id, x, y }) => window.__iwbEditor.__debug().pixel(id, x, y), { id, x: IMG.x, y: IMG.y })
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
const stampLayerId = (await dbg()).activeLayerId
const stampPx = await probe(stampLayerId)
const stampBasePx = await probe('base')
check('画笔落笔自动落「标注」层且该点有像素', stampPx && stampPx[3] > 0,
'layer=' + stampLayerId + ' px=' + JSON.stringify(stampPx))
await page.locator('.iwb-editor-tool[data-tool="eraser"]').click()
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
const erasedPx = await probe(stampLayerId)
const basePxAfterErase = await probe('base')
check('橡皮沿同一笔迹擦除(不抛错、目标层挖空、base 原样)',
erasedPx && erasedPx[3] === 0 && JSON.stringify(basePxAfterErase) === JSON.stringify(stampBasePx),
'erased=' + JSON.stringify(erasedPx))
await page.keyboard.press('Control+z')
// 钢笔描边/实心切换(penFill 默认实心,只对闭合路径生效)
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
check('钢笔选项栏有 描边/实心 切换',
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2)
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="pen"]').click()
const penFillOff = (await dbg()).toolOptions.penFill === false
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="pen"]').click()
check('钢笔样式切换写回 penFill(默认实心 → 描边 → 实心)',
penFillOff && (await dbg()).toolOptions.penFill === true)
// 橡皮兜底:只剩锁定的原图时用橡皮 → 明确提示而不是无声失败
await page.locator('[data-action="reset"]').click()
const layersAfterReset = (await dbg()).layers.length
await page.locator('.iwb-editor-tool[data-tool="eraser"]').click()
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
const toastText = await page.locator('.iwb-editor-toast').textContent()
check('原图锁定且无标注层时用橡皮:提示「先画再擦」且不建层',
layersAfterReset === 1 && (await dbg()).layers.length === 1 && toastText.indexOf('可擦') >= 0,
'layers=' + layersAfterReset + ' toast=' + toastText)
await page.keyboard.press('Control+z') // 撤销还原,恢复图层结构
await page.locator('[data-action="cancel"]').click()
const openState = await poll(async () => page.evaluate(() => window.__openState))
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',