feat(image-annotate): 1.2.2 手柄仅选择工具/高亮跟随绘制目标/选项栏快捷点与裁剪参数/Enter-Esc 裁剪

This commit is contained in:
qiqi committed 2026-11-04 20:30:49 +08:00
1 parent 1bf8220c05
commit f50b734fd7
11 files changed
+340 -164

No files matched your search

+13 -1
View File
@@ -66,10 +66,22 @@
- **侧栏去重**:移除硬度/透明两条滑杆(与就地选项栏画笔/橡皮态完全重复);
侧栏保留调色板全量 + 笔刷大小(滑杆/数字/快捷点)+ 缩放行。
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,68 项);
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,79 项);
`node image-annotate/tools/e2e-site.mjs`(真站 CSP/SRI,发布后)。
## v1.2.2
- **变换手柄只在「选择」工具出现**:画笔/橡皮等绘制工具下不再画选中层的虚线框与 8 个手柄(用户裁定)。
- **面板高亮跟随绘制目标**:画笔/橡皮落笔时 `selectedLayerId` 同步为绘制目标层,
杜绝「面板没选中这层却能画上去」的逻辑矛盾。
- **选项栏快捷值圆点**:画笔/橡皮有 7 个大小快捷点(2/4/8/12/16/24/32),
矩形/圆形/箭头/钢笔有 7 个线宽快捷点(1/2/3/6/10/16/24),点击即时生效并与侧栏滑杆同步。
- **侧栏「实心」按钮移除**:矩形/圆形的描边/实心切换只在选项栏(一处真源)。
- **裁剪参数迁入选项栏**:比例/尺寸约束、尺寸摘要、确认/取消按钮全部在裁剪工具的选项栏里,
画布下方浮窗删除;**Enter 确认、Esc 取消**(按钮保留)。旧直连绑定改为选项栏委托,重渲染不丢事件。
## 入口
- **节点漂浮菜单**「标注 / 修图」(**仅 `ref` 图片输入节点**)
- `out` / `gen` / `layer` 是产图节点:一个节点可能有多张结果或多个图层,`getNodeImage` 只能取 `result[0]`,在漂浮菜单放「编辑图片」会被误读成「编辑结果图」。要处理产出的图,先「复制 / 插入为参考图节点」。
- 右键菜单「插件命令 → 标注 / 修图:选中节点」
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/image-annotate",
"private": true,
"version": "1.2.1",
"version": "1.2.2",
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
"ibwPlugin": {
"id": "image-annotate",
+38
View File
@@ -1502,3 +1502,41 @@
@media (max-width: 1100px) {
.iwb-opt-range { width: 64px; }
}
/* ---- v1.2.2 ---- */
/* 选项栏快捷值圆点(笔刷大小 / 矢量描边推荐值),与侧栏描边快捷点同交互 */
.iwb-opt-dots { display: inline-flex; align-items: center; gap: 3px; flex: 0 0 auto; }
.iwb-opt-dot {
display: inline-flex; align-items: center; justify-content: center;
width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%;
background: transparent; cursor: pointer;
}
.iwb-opt-dot i { display: block; width: 5px; height: 5px; border-radius: 50%; background: #e8a735; border: 1px solid #f6d38a; }
.iwb-opt-dot:nth-child(2) i { width: 7px; height: 7px; }
.iwb-opt-dot:nth-child(3) i { width: 9px; height: 9px; }
.iwb-opt-dot:nth-child(4) i { width: 11px; height: 11px; }
.iwb-opt-dot:nth-child(5) i { width: 14px; height: 14px; }
.iwb-opt-dot:nth-child(6) i { width: 17px; height: 17px; }
.iwb-opt-dot:nth-child(7) i { width: 20px; height: 20px; }
.iwb-opt-dot:hover { background: #313244; }
/* 裁剪控件在选项栏内联布局(旧 .iwb-editor-crop-bar 的绝对定位容器已删除) */
.iwb-editor-optionbar-body .iwb-editor-crop-info {
min-width: 88px; text-align: center; color: #e8a735;
font-size: 11px; font-variant-numeric: tabular-nums; flex: 0 0 auto;
}
.iwb-editor-optionbar-body .iwb-editor-size-input {
width: 52px; padding: 2px 5px; font-size: 11px;
background: #1e2030; color: #e5e9f0;
border: 1px solid #45475a; border-radius: 4px;
}
.iwb-editor-optionbar-body .iwb-editor-size-input:focus { outline: none; border-color: #4488ff; }
.iwb-editor-optionbar-body .iwb-editor-size-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.iwb-editor-optionbar-body .iwb-editor-crop-confirm,
.iwb-editor-optionbar-body .iwb-editor-crop-cancel {
padding: 3px 10px; border: 0; border-radius: 4px; cursor: pointer; font-size: 12px; flex: 0 0 auto;
}
.iwb-editor-optionbar-body .iwb-editor-crop-confirm { background: #1a7f37; color: #fff; }
.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; }
+4 -2
View File
@@ -352,5 +352,7 @@ import { toast } from './commands.js'
}
// ============ 裁剪栏 ============
export function showCropBar() { runtime.el.querySelector('.iwb-editor-crop-bar').style.display = 'flex' }
export function hideCropBar() { runtime.el.querySelector('.iwb-editor-crop-bar').style.display = 'none' }
// 裁剪参数已迁入选项栏(optionBarHTML('crop'),随工具切换自动出现/消失),
// 画布下方的浮窗 DOM 已删除。这两个入口保留为空操作,调用点(setTool / 拉框)无需改动。
export function showCropBar() { /* 选项栏自动承载,见 events.js#optionBarHTML */ }
export function hideCropBar() { /* 同上 */ }
+2 -26
View File
@@ -67,11 +67,9 @@ import { bindEvents } from './events.js'
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪(参数在选项栏;Enter 确认 / Esc 取消)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-fill-btn" data-action="toggleFill" title="矩形实心填充开关(选中矩形时切换即时生效)">实心</button>
</div>
<span class="iwb-editor-divider"></span>
@@ -150,29 +148,7 @@ import { bindEvents } from './events.js'
</div>
<input class="iwb-editor-text-input" type="text" placeholder="输入文字,Enter确认,Esc取消">
<div class="iwb-editor-picker-tip"><span class="iwb-editor-picker-chip"></span><span class="iwb-editor-picker-hex">#ffffff</span></div>
<div class="iwb-editor-crop-bar">
<div class="iwb-editor-crop-row"><div class="iwb-editor-constraint-group">
<span class="iwb-editor-constraint-label">比例</span>
<button class="iwb-editor-constraint-btn active" data-ratio="free">自由</button>
<button class="iwb-editor-constraint-btn" data-ratio="1:1">1:1</button>
<button class="iwb-editor-constraint-btn" data-ratio="4:3">4:3</button>
<button class="iwb-editor-constraint-btn" data-ratio="3:4">3:4</button>
<button class="iwb-editor-constraint-btn" data-ratio="16:9">16:9</button>
<button class="iwb-editor-constraint-btn" data-ratio="9:16">9:16</button>
</div></div>
<div class="iwb-editor-crop-row"><div class="iwb-editor-constraint-group">
<span class="iwb-editor-constraint-label">尺寸</span>
<input class="iwb-editor-size-input iwb-editor-size-w" type="number" min="1" placeholder="宽" value="800">
<span class="iwb-editor-size-x">×</span>
<input class="iwb-editor-size-input iwb-editor-size-h" type="number" min="1" placeholder="高" value="800">
<button class="iwb-editor-constraint-btn iwb-editor-size-toggle" data-action="toggleSizeConstraint" aria-pressed="false">启用尺寸</button>
<button class="iwb-editor-constraint-btn iwb-editor-size-apply" data-action="applySize">应用</button>
</div></div>
<div class="iwb-editor-crop-row iwb-editor-crop-actions"><span class="iwb-editor-crop-info">--</span>
<button class="iwb-editor-crop-confirm" data-action="confirmCrop">✓ 确认</button>
<button class="iwb-editor-crop-cancel" data-action="cancelCrop">✗ 取消</button>
</div>
</div>
<!-- 裁剪参数已迁入选项栏(v1.2.2),画布下方浮窗删除 -->
<div class="iwb-editor-sel-bar">
<span class="iwb-editor-sel-info">未框选</span>
<button data-sel-cmd="sel.copy" data-needs-sel="1" title="把当前图层选区复制为新图层 (Ctrl+J)">复制</button>
+93 -45
View File
@@ -210,18 +210,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
/** 画笔工具的按下:无可写图层则自动落「标注」层(用户裁定:默认不预建画笔层),
* 否则存快照并落下第一点。注意 ensureWritableLayer 必须在 saveSnapshot 之前,
* 让首笔 Ctrl+Z 连自动建的层一起撤掉。 */
* 让首笔 Ctrl+Z 连自动建的层一起撤掉。
* 选中态同步:面板高亮(selectedLayerId)必须跟随真正的绘制目标(activeLayerId),
* 否则会出现「面板没选中这层却能画上去」的逻辑矛盾(用户反馈 2026-11-04)。 */
function onBrushMouseDown(pos) {
if (!ensureWritableLayer()) return
const layer = ensureWritableLayer()
if (!layer) return
S.selectedLayerId = layer.id
S.isDrawing = true
saveSnapshot()
beginStroke()
strokeSegment(pos.x, pos.y, pos.x, pos.y)
}
/** 橡皮工具的按下:与画笔同构,存快照并擦除第一段 */
/** 橡皮工具的按下:与画笔同构但**不自动建层**(减内容语义,没有可写层就忽略),
* 同样把面板高亮同步到真正的擦除目标。 */
function onEraserMouseDown(pos) {
if (!getActiveCtx()) return
const layer = getActiveLayer()
if (!layer || layer.locked) return
S.selectedLayerId = layer.id
S.isDrawing = true
saveSnapshot()
beginStroke()
@@ -817,10 +824,41 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
<input type="number" class="iwb-opt-num" data-opt="${key}" min="${min}" max="${max}" step="1" value="${value}">${unit ? `<span class="iwb-opt-unit">${unit}</span>` : ''}`
}
/** 快捷值圆点(用户裁定 2026-11-04:笔刷大小/矢量描边都要推荐值,跟侧栏快捷点同款交互) */
function presetDots(key, values) {
return `<span class="iwb-opt-dots">${values.map(v =>
`<button type="button" class="iwb-opt-dot" data-opt-preset="${key}" data-value="${v}" title="${v}"><i></i></button>`).join('')}</span>`
}
/** 裁剪参数行(用户裁定 2026-11-04:从画布下方浮窗搬进选项栏;Enter 确认 / Esc 取消) */
function cropOptionHTML() {
const c = S.cropConstraint
const sizeOn = c.type === 'size'
return `<span class="iwb-opt-label">比例</span>
<button type="button" class="iwb-editor-constraint-btn${c.type === 'free' ? ' active' : ''}" data-ratio="free">自由</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="1:1">1:1</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="4:3">4:3</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="3:4">3:4</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="16:9">16:9</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="9:16">9:16</button>
<span class="iwb-opt-label">尺寸</span>
<input type="number" class="iwb-editor-size-input iwb-editor-size-w" min="1" placeholder="宽" value="800">
<span class="iwb-opt-unit">×</span>
<input type="number" class="iwb-editor-size-input iwb-editor-size-h" min="1" placeholder="高" value="800">
<button type="button" class="iwb-editor-constraint-btn iwb-editor-size-toggle" data-action="toggleSizeConstraint" aria-pressed="${sizeOn}">启用尺寸</button>
<button type="button" class="iwb-editor-constraint-btn iwb-editor-size-apply" data-action="applySize">应用</button>
<span class="iwb-editor-crop-info">--</span>
<button type="button" class="iwb-editor-crop-confirm" data-action="confirmCrop" title="Enter">✓ 确认</button>
<button type="button" class="iwb-editor-crop-cancel" data-action="cancelCrop" title="Esc">✗ 取消</button>
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`
}
/** 每个工具只露最常用的 2–4 个参数,全部直接写回 S(右侧参数面板同步) */
function optionBarHTML(tool) {
if (tool === 'crop') return cropOptionHTML()
if (tool === 'brush' || tool === 'eraser') {
return rangeOpt('brushSize', '大小', 1, 300, S.brushSize, '')
+ presetDots('brushSize', [2, 4, 8, 12, 16, 24, 32])
+ `<span class="iwb-opt-label">硬度</span>
<input type="range" class="iwb-opt-range" data-opt="brushHardness" min="0" max="100" step="1" value="${S.brushHardness}">
<span class="iwb-opt-val" data-opt-val="brushHardness">${S.brushHardness}</span>
@@ -830,12 +868,14 @@ 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>`
}
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 === 'text') {
@@ -865,6 +905,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (!force && body.dataset.tool === S.tool) { syncOptionBar(); return }
body.dataset.tool = S.tool
body.innerHTML = optionBarHTML(S.tool)
if (S.tool === 'crop') updateCropInfo() // 重渲染后裁剪尺寸摘要要立即就位
syncOptionBar()
}
@@ -1063,7 +1104,49 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (toggle) {
e.stopPropagation()
setShapeFill(toggle.dataset.value === 'fill')
return
}
// 快捷值圆点:笔刷大小 / 矢量描边(用户裁定进选项栏)
const dot = e.target.closest('[data-opt-preset]')
if (dot) {
e.stopPropagation()
setOptionFromControl({ dataset: { opt: dot.dataset.optPreset }, value: dot.dataset.value }, true)
return
}
// ---- 裁剪控件(从画布下方浮窗搬进选项栏,委托绑定防重渲染丢事件) ----
const ratioBtn = e.target.closest('[data-ratio]')
if (ratioBtn) {
e.stopPropagation()
const ratio = parseRatio(ratioBtn.dataset.ratio)
body.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.toggle('active', b === ratioBtn))
setConstraint(ratio > 0 ? 'ratio' : 'free', ratio > 0 ? ratio : 0, 0, 0)
return
}
if (e.target.closest('[data-action="toggleSizeConstraint"]')) {
e.stopPropagation()
if (S.cropConstraint.type === 'size') { setConstraint('free', 0, 0, 0) }
else {
const w = parseInt(body.querySelector('.iwb-editor-size-w').value, 10)
const h = parseInt(body.querySelector('.iwb-editor-size-h').value, 10)
if (w > 0 && h > 0) {
body.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.remove('active'))
setConstraint('size', w / h, w, h)
}
}
return
}
if (e.target.closest('[data-action="applySize"]')) {
e.stopPropagation()
const w = parseInt(body.querySelector('.iwb-editor-size-w').value, 10)
const h = parseInt(body.querySelector('.iwb-editor-size-h').value, 10)
if (w > 0 && h > 0) {
body.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.remove('active'))
setConstraint('size', w / h, w, h)
}
return
}
if (e.target.closest('[data-action="confirmCrop"]')) { e.stopPropagation(); confirmCrop(); return }
if (e.target.closest('[data-action="cancelCrop"]')) { e.stopPropagation(); cancelCrop(); return }
})
}
@@ -1098,7 +1181,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
export function bindEvents() {
bindToolButtons()
bindColorPanel()
bindCropConstraintControls()
bindColorPalette()
bindFillToggle()
bindLayerOrderButtons()
@@ -1106,7 +1188,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
bindBrushParams()
bindZoomButtons()
bindHistoryActions()
bindCropActions()
bindLayerAddActions()
bindExportActions()
bindWheelZoom()
@@ -1164,39 +1245,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (hue) { hue.addEventListener('pointerdown', e => { pick(hue, e) }); hue.addEventListener('pointermove', e => { if (e.buttons) pick(hue, e) }) }
}
/** 裁剪约束控件:比例按钮、尺寸约束开关、应用尺寸按钮 */
function bindCropConstraintControls() {
// 比例约束按钮
runtime.el.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(btn => {
btn.addEventListener('mousedown', (e) => e.stopPropagation())
btn.addEventListener('click', () => {
const r = btn.dataset.ratio
runtime.el.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.remove('active'))
btn.classList.add('active')
const ratio = parseRatio(r)
if (ratio > 0) {
setConstraint('ratio', ratio, 0, 0)
} else {
setConstraint('free', 0, 0, 0)
}
})
})
// 尺寸约束开关
const sizeToggle = runtime.el.querySelector('[data-action="toggleSizeConstraint"]')
if (sizeToggle) sizeToggle.addEventListener('click', () => { if (S.cropConstraint.type === 'size') setConstraint('free', 0, 0, 0); else { const w = parseInt(runtime.el.querySelector('.iwb-editor-size-w').value, 10), h = parseInt(runtime.el.querySelector('.iwb-editor-size-h').value, 10); if (w > 0 && h > 0) setConstraint('size', w / h, w, h) } })
// 应用尺寸按钮
bindIf('[data-action="applySize"]', 'mousedown', (e) => e.stopPropagation())
bindIf('[data-action="applySize"]', 'click', () => {
const w = parseInt(runtime.el.querySelector('.iwb-editor-size-w').value, 10)
const h = parseInt(runtime.el.querySelector('.iwb-editor-size-h').value, 10)
if (w > 0 && h > 0) {
runtime.el.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.remove('active'))
setConstraint('size', w / h, w, h)
}
})
}
/** 裁剪约束控件已迁入选项栏(bindLiteUI 的点击委托统一处理),旧的直连绑定移除。 */
/** 调色板色块与自定义取色 input */
function bindColorPalette() {
@@ -1328,12 +1377,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
restoreBtn && restoreBtn.addEventListener('click', restoreOriginal)
}
/** 裁剪确认 / 取消按钮 */
function bindCropActions() {
// 裁剪
bindIf('[data-action="confirmCrop"]', 'click', confirmCrop)
bindIf('[data-action="cancelCrop"]', 'click', cancelCrop)
}
/** 裁剪确认/取消已迁入选项栏(bindLiteUI 委托),旧直连绑定移除。 */
/** 添加位图图层(导入图片)与新建空白图层 */
function bindLayerAddActions() {
@@ -1622,8 +1666,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
}
if (e.key === 'Shift') S._shiftDown = true
if (e.key === 'Enter' && S.tool === 'pen' && S.penPath) { e.preventDefault(); commitPenPath(); return }
// 裁剪:Enter 确认 / Esc 取消(用户裁定,替代浮窗上的两个按钮 —— 按钮也保留在选项栏)
if (e.key === 'Enter' && S.tool === 'crop' && S.cropRect) { e.preventDefault(); confirmCrop(); return }
if (e.key === 'Escape') {
if (isTyping(e)) { hideTextInput(); return }
// 裁剪优先:有裁剪框时 Esc 取消裁剪
if (S.tool === 'crop' && S.cropRect) { e.preventDefault(); cancelCrop(); return }
// 选区优先:Esc 一步取消,不进菜单
if (S.marquee || S.lassoPts || (S.selection && S.selection.active)) { e.preventDefault(); clearMarquee(); return }
if (S.penPath) { e.preventDefault(); S.penPath = null; renderObjects(); return }
+1
View File
@@ -291,6 +291,7 @@ import { toast } from './commands.js'
selectedShapeId: S.selectedShapeId,
selectedTextId: S.selectedTextId,
activeLayerId: S.activeLayerId,
selectedLayerId: S.selectedLayerId,
selection: selectionInfo(),
toolOptions: {
brushSize: S.brushSize,
+3
View File
@@ -193,6 +193,9 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
export function drawBitmapSelection(layer) {
if (!layer) return
// 变换框/手柄只在「选择」工具下出现(用户裁定 2026-11-04):
// 画笔/橡皮等绘制工具下不显示调节杆,避免误抓手柄也减少视觉噪音。
if (S.tool !== 'select') return
const drawable = isDrawableLayer(layer)
if (!layer.transformable && !drawable) return
const box = layerFrame(layer)
+107 -81
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.2.1',
version: '1.2.2',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -489,7 +489,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.lineTo(x2, y2);
ctx.stroke();
ctx.restore();
const active = getActiveLayer();
const active = getActiveLayer2();
if (active && active.id === "draw" && active.sourceCanvas) {
const sourceCtx = active.sourceCanvas.getContext("2d", { willReadFrequently: true });
sourceCtx.save();
@@ -518,7 +518,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
layer._bounds = void 0;
}
function beginStroke() {
bakeDrawableLayer(getActiveLayer());
bakeDrawableLayer(getActiveLayer2());
S.strokeCanvas.width = S.imgW;
S.strokeCanvas.height = S.imgH;
S.strokeCtx.clearRect(0, 0, S.imgW, S.imgH);
@@ -538,7 +538,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.drawImage(S.strokeCanvas, 0, 0);
ctx.restore();
S.strokeCanvas.style.display = "none";
const active = getActiveLayer();
const active = getActiveLayer2();
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 +1450,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
el.style.display = u.obj.visible === false ? "none" : "block";
}
}
function getActiveLayer() {
function getActiveLayer2() {
return S.layers.find((l) => l.id === S.activeLayerId) || null;
}
function getActiveCtx() {
const layer = getActiveLayer();
const layer = getActiveLayer2();
return layer && !layer.locked ? layer.ctx : null;
}
function clearSelection({ keepBitmap = false } = {}) {
@@ -1579,6 +1579,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
function drawBitmapSelection(layer) {
if (!layer) return;
if (S.tool !== "select") return;
const drawable = isDrawableLayer(layer);
if (!layer.transformable && !drawable) return;
const box = layerFrame(layer);
@@ -1716,7 +1717,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
placeImageDirectly(img);
}
function ensureWritableLayer() {
const current = getActiveLayer();
const current = getActiveLayer2();
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();
@@ -2422,7 +2423,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return { canvas: c, x: e.x - pad, y: e.y - pad, w, h };
}
function writableLayer() {
const layer = getActiveLayer();
const layer = getActiveLayer2();
if (!layer || layer.locked) {
toast(layer && layer.locked ? "当前图层已锁定,请先解锁" : "没有可用的图层", "warn");
return null;
@@ -2694,11 +2695,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪(参数在选项栏;Enter 确认 / Esc 取消)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-fill-btn" data-action="toggleFill" title="矩形实心填充开关(选中矩形时切换即时生效)">实心</button>
</div>
<span class="iwb-editor-divider"></span>
@@ -2777,29 +2776,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
</div>
<input class="iwb-editor-text-input" type="text" placeholder="输入文字,Enter确认,Esc取消">
<div class="iwb-editor-picker-tip"><span class="iwb-editor-picker-chip"></span><span class="iwb-editor-picker-hex">#ffffff</span></div>
<div class="iwb-editor-crop-bar">
<div class="iwb-editor-crop-row"><div class="iwb-editor-constraint-group">
<span class="iwb-editor-constraint-label">比例</span>
<button class="iwb-editor-constraint-btn active" data-ratio="free">自由</button>
<button class="iwb-editor-constraint-btn" data-ratio="1:1">1:1</button>
<button class="iwb-editor-constraint-btn" data-ratio="4:3">4:3</button>
<button class="iwb-editor-constraint-btn" data-ratio="3:4">3:4</button>
<button class="iwb-editor-constraint-btn" data-ratio="16:9">16:9</button>
<button class="iwb-editor-constraint-btn" data-ratio="9:16">9:16</button>
</div></div>
<div class="iwb-editor-crop-row"><div class="iwb-editor-constraint-group">
<span class="iwb-editor-constraint-label">尺寸</span>
<input class="iwb-editor-size-input iwb-editor-size-w" type="number" min="1" placeholder="宽" value="800">
<span class="iwb-editor-size-x">×</span>
<input class="iwb-editor-size-input iwb-editor-size-h" type="number" min="1" placeholder="高" value="800">
<button class="iwb-editor-constraint-btn iwb-editor-size-toggle" data-action="toggleSizeConstraint" aria-pressed="false">启用尺寸</button>
<button class="iwb-editor-constraint-btn iwb-editor-size-apply" data-action="applySize">应用</button>
</div></div>
<div class="iwb-editor-crop-row iwb-editor-crop-actions"><span class="iwb-editor-crop-info">--</span>
<button class="iwb-editor-crop-confirm" data-action="confirmCrop">✓ 确认</button>
<button class="iwb-editor-crop-cancel" data-action="cancelCrop">✗ 取消</button>
</div>
</div>
<!-- 裁剪参数已迁入选项栏(v1.2.2),画布下方浮窗删除 -->
<div class="iwb-editor-sel-bar">
<span class="iwb-editor-sel-info">未框选</span>
<button data-sel-cmd="sel.copy" data-needs-sel="1" title="把当前图层选区复制为新图层 (Ctrl+J)">复制</button>
@@ -3104,14 +3081,18 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return;
}
function onBrushMouseDown(pos) {
if (!ensureWritableLayer()) return;
const layer = ensureWritableLayer();
if (!layer) return;
S.selectedLayerId = layer.id;
S.isDrawing = true;
saveSnapshot();
beginStroke();
strokeSegment(pos.x, pos.y, pos.x, pos.y);
}
function onEraserMouseDown(pos) {
if (!getActiveCtx()) return;
const layer = getActiveLayer();
if (!layer || layer.locked) return;
S.selectedLayerId = layer.id;
S.isDrawing = true;
saveSnapshot();
beginStroke();
@@ -3695,9 +3676,34 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<input type="range" class="iwb-opt-range" data-opt="${key}" min="${min}" max="${max}" step="1" value="${value}">
<input type="number" class="iwb-opt-num" data-opt="${key}" min="${min}" max="${max}" step="1" value="${value}">${unit ? `<span class="iwb-opt-unit">${unit}</span>` : ""}`;
}
function presetDots(key, values) {
return `<span class="iwb-opt-dots">${values.map((v) => `<button type="button" class="iwb-opt-dot" data-opt-preset="${key}" data-value="${v}" title="${v}"><i></i></button>`).join("")}</span>`;
}
function cropOptionHTML() {
const c = S.cropConstraint;
const sizeOn = c.type === "size";
return `<span class="iwb-opt-label">比例</span>
<button type="button" class="iwb-editor-constraint-btn${c.type === "free" ? " active" : ""}" data-ratio="free">自由</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="1:1">1:1</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="4:3">4:3</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="3:4">3:4</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="16:9">16:9</button>
<button type="button" class="iwb-editor-constraint-btn" data-ratio="9:16">9:16</button>
<span class="iwb-opt-label">尺寸</span>
<input type="number" class="iwb-editor-size-input iwb-editor-size-w" min="1" placeholder="宽" value="800">
<span class="iwb-opt-unit">×</span>
<input type="number" class="iwb-editor-size-input iwb-editor-size-h" min="1" placeholder="高" value="800">
<button type="button" class="iwb-editor-constraint-btn iwb-editor-size-toggle" data-action="toggleSizeConstraint" aria-pressed="${sizeOn}">启用尺寸</button>
<button type="button" class="iwb-editor-constraint-btn iwb-editor-size-apply" data-action="applySize">应用</button>
<span class="iwb-editor-crop-info">--</span>
<button type="button" class="iwb-editor-crop-confirm" data-action="confirmCrop" title="Enter">✓ 确认</button>
<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 optionBarHTML(tool) {
if (tool === "crop") return cropOptionHTML();
if (tool === "brush" || tool === "eraser") {
return rangeOpt("brushSize", "大小", 1, 300, S.brushSize, "") + `<span class="iwb-opt-label">硬度</span>
return rangeOpt("brushSize", "大小", 1, 300, S.brushSize, "") + presetDots("brushSize", [2, 4, 8, 12, 16, 24, 32]) + `<span class="iwb-opt-label">硬度</span>
<input type="range" class="iwb-opt-range" data-opt="brushHardness" min="0" max="100" step="1" value="${S.brushHardness}">
<span class="iwb-opt-val" data-opt-val="brushHardness">${S.brushHardness}</span>
<span class="iwb-opt-label">透明</span>
@@ -3705,12 +3711,12 @@ 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, "") + `<span class="iwb-opt-label">样式</span>
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>`;
}
if (tool === "arrow" || tool === "pen") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + `<span class="iwb-opt-hint">${tool === "pen" ? "逐点点击,点回起点闭合" : "拖出箭头,松手完成"}</span>`;
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 === "text") {
return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + '<span class="iwb-opt-hint">点画布输入文字,Enter 确认</span>';
@@ -3738,6 +3744,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
body.dataset.tool = S.tool;
body.innerHTML = optionBarHTML(S.tool);
if (S.tool === "crop") updateCropInfo();
syncOptionBar();
}
function syncOptionBar() {
@@ -3928,6 +3935,55 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (toggle) {
e.stopPropagation();
setShapeFill(toggle.dataset.value === "fill");
return;
}
const dot = e.target.closest("[data-opt-preset]");
if (dot) {
e.stopPropagation();
setOptionFromControl({ dataset: { opt: dot.dataset.optPreset }, value: dot.dataset.value }, true);
return;
}
const ratioBtn = e.target.closest("[data-ratio]");
if (ratioBtn) {
e.stopPropagation();
const ratio = parseRatio(ratioBtn.dataset.ratio);
body.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((b) => b.classList.toggle("active", b === ratioBtn));
setConstraint(ratio > 0 ? "ratio" : "free", ratio > 0 ? ratio : 0, 0, 0);
return;
}
if (e.target.closest('[data-action="toggleSizeConstraint"]')) {
e.stopPropagation();
if (S.cropConstraint.type === "size") {
setConstraint("free", 0, 0, 0);
} else {
const w = parseInt(body.querySelector(".iwb-editor-size-w").value, 10);
const h = parseInt(body.querySelector(".iwb-editor-size-h").value, 10);
if (w > 0 && h > 0) {
body.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((b) => b.classList.remove("active"));
setConstraint("size", w / h, w, h);
}
}
return;
}
if (e.target.closest('[data-action="applySize"]')) {
e.stopPropagation();
const w = parseInt(body.querySelector(".iwb-editor-size-w").value, 10);
const h = parseInt(body.querySelector(".iwb-editor-size-h").value, 10);
if (w > 0 && h > 0) {
body.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((b) => b.classList.remove("active"));
setConstraint("size", w / h, w, h);
}
return;
}
if (e.target.closest('[data-action="confirmCrop"]')) {
e.stopPropagation();
confirmCrop();
return;
}
if (e.target.closest('[data-action="cancelCrop"]')) {
e.stopPropagation();
cancelCrop();
return;
}
});
}
@@ -3952,7 +4008,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
function bindEvents() {
bindToolButtons();
bindColorPanel();
bindCropConstraintControls();
bindColorPalette();
bindFillToggle();
bindLayerOrderButtons();
@@ -3960,7 +4015,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
bindBrushParams();
bindZoomButtons();
bindHistoryActions();
bindCropActions();
bindLayerAddActions();
bindExportActions();
bindWheelZoom();
@@ -4059,39 +4113,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
});
}
}
function bindCropConstraintControls() {
runtime.el.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((btn) => {
btn.addEventListener("mousedown", (e) => e.stopPropagation());
btn.addEventListener("click", () => {
const r = btn.dataset.ratio;
runtime.el.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((b) => b.classList.remove("active"));
btn.classList.add("active");
const ratio = parseRatio(r);
if (ratio > 0) {
setConstraint("ratio", ratio, 0, 0);
} else {
setConstraint("free", 0, 0, 0);
}
});
});
const sizeToggle = runtime.el.querySelector('[data-action="toggleSizeConstraint"]');
if (sizeToggle) sizeToggle.addEventListener("click", () => {
if (S.cropConstraint.type === "size") setConstraint("free", 0, 0, 0);
else {
const w = parseInt(runtime.el.querySelector(".iwb-editor-size-w").value, 10), h = parseInt(runtime.el.querySelector(".iwb-editor-size-h").value, 10);
if (w > 0 && h > 0) setConstraint("size", w / h, w, h);
}
});
bindIf('[data-action="applySize"]', "mousedown", (e) => e.stopPropagation());
bindIf('[data-action="applySize"]', "click", () => {
const w = parseInt(runtime.el.querySelector(".iwb-editor-size-w").value, 10);
const h = parseInt(runtime.el.querySelector(".iwb-editor-size-h").value, 10);
if (w > 0 && h > 0) {
runtime.el.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((b) => b.classList.remove("active"));
setConstraint("size", w / h, w, h);
}
});
}
function bindColorPalette() {
runtime.el.querySelectorAll(".iwb-editor-color[data-color]").forEach((s) => {
s.addEventListener("mousedown", (e) => e.stopPropagation());
@@ -4203,10 +4224,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
resetBtn && resetBtn.addEventListener("click", resetDraw);
restoreBtn && restoreBtn.addEventListener("click", restoreOriginal);
}
function bindCropActions() {
bindIf('[data-action="confirmCrop"]', "click", confirmCrop);
bindIf('[data-action="cancelCrop"]', "click", cancelCrop);
}
function bindLayerAddActions() {
bindIf('[data-action="addBitmapLayer"]', "mousedown", (e) => e.stopPropagation());
bindIf('[data-action="addBitmapLayer"]', "click", () => {
@@ -4487,11 +4504,21 @@ var __IWB_ANNOTATE_MANIFEST__ = {
commitPenPath();
return;
}
if (e.key === "Enter" && S.tool === "crop" && S.cropRect) {
e.preventDefault();
confirmCrop();
return;
}
if (e.key === "Escape") {
if (isTyping(e)) {
hideTextInput();
return;
}
if (S.tool === "crop" && S.cropRect) {
e.preventDefault();
cancelCrop();
return;
}
if (S.marquee || S.lassoPts || S.selection && S.selection.active) {
e.preventDefault();
clearMarquee();
@@ -5231,10 +5258,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
updateCropInfo();
}
function showCropBar() {
runtime.el.querySelector(".iwb-editor-crop-bar").style.display = "flex";
}
function hideCropBar() {
runtime.el.querySelector(".iwb-editor-crop-bar").style.display = "none";
}
// image-annotate/plugin/editor/history.js
@@ -6058,6 +6083,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
selectedShapeId: S.selectedShapeId,
selectedTextId: S.selectedTextId,
activeLayerId: S.activeLayerId,
selectedLayerId: S.selectedLayerId,
selection: selectionInfo(),
toolOptions: {
brushSize: S.brushSize,
@@ -6092,7 +6118,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) {
+4 -2
View File
@@ -205,7 +205,9 @@ check('v1.1 框选 + 浮动操作条出现', Boolean(v11sel && v11sel.w > 5 && v
await page.locator('.iwb-editor-sel-bar').isVisible(), JSON.stringify(v11sel))
const v11px = (x, y) => page.evaluate(({ px, py }) => {
const d = window.__iwbEditor.__debug()
return { base: d.pixel('base', px, py), draw: d.pixel('draw', px, py) }
// 1.2.1 起默认没有 id='draw' 的预建层:填充落进「当前活动层」,
// 所以这里读活动层像素而不是写死 'draw'
return { base: d.pixel('base', px, py), draw: d.pixel(d.activeLayerId, px, py), activeId: d.activeLayerId }
}, { px: x, py: y })
const vcX = Math.round(v11sel.x + v11sel.w / 2)
const vcY = Math.round(v11sel.y + v11sel.h / 2)
@@ -219,7 +221,7 @@ check('v1.1 Delete 只清当前层(base 像素原样)',
await page.keyboard.press('Control+z')
const v11layersBeforeReset = (await dbg()).layers.length
await page.locator('[data-action="reset"]').click()
check('v1.1 还原原图=只剩原图+画笔层,不留下空白层', (await dbg()).layers.length === 2, JSON.stringify((await dbg()).layers))
check('v1.1 还原原图=只剩原图单层(1.2.1 起不预建画笔层)', (await dbg()).layers.length === 1, JSON.stringify((await dbg()).layers))
await page.keyboard.press('Control+z')
check('v1.1 还原原图可 Ctrl+Z 撤销', (await dbg()).layers.length === v11layersBeforeReset,
'层数 ' + v11layersBeforeReset + ' → 2 → ' + (await dbg()).layers.length)
+74 -6
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.1', 'version=' + boot.version)
check('产物可执行(循环打包未炸)', boot.version === '1.2.2', '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 })
@@ -286,12 +286,14 @@ await page.locator('[data-action="toggleExportSettings"]').click() // 收起,
// ---------- 选区与裁剪互斥 ----------
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
check('切到裁剪会清掉选区', !(await dbg()).selection)
check('切到裁剪会清掉选区,裁剪参数出现在选项栏(不再有画布下方浮窗)',
!(await dbg()).selection &&
(await page.locator('.iwb-editor-optionbar-body [data-action="confirmCrop"]').count()) === 1 &&
(await page.locator('.iwb-editor-optionbar-body [data-ratio="1:1"]').count()) === 1 &&
(await page.locator('.iwb-editor-crop-bar').count()) === 0)
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
check('切回选区会取消裁剪框', await page.evaluate(() => {
const bar = document.querySelector('.iwb-editor-crop-bar')
return bar && getComputedStyle(bar).display === 'none'
}))
check('切回选区:裁剪控件从选项栏消失、裁剪框取消',
await page.evaluate(() => !document.querySelector('[data-action="confirmCrop"]')))
// ---------- 回归:矢量对象经撤销/重做后仍可渲染(快照不得把 DOM 画布序列化成 {}) ----------
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
@@ -530,6 +532,72 @@ check('参数数字框里按 Ctrl+A 仍能全选(不再被当打字吞掉)',
JSON.stringify(selAfterCtrlA.selection))
await page.keyboard.press('Control+d')
// ---- v1.2.2:手柄只在选择工具出现 / 高亮跟随绘制目标 / 选项栏快捷点 / 侧栏实心移除 ----
// 侧栏「实心」按钮移除(选项栏 rect 工具已有描边/实心切换)
check('侧栏「实心」按钮已移除(选项栏承担该功能)',
(await page.locator('[data-action="toggleFill"]').count()) === 0)
// 快捷点:画笔大小
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:笔刷大小即时生效且侧栏滑杆同步',
(await dbg()).toolOptions.brushSize === 12 &&
await page.evaluate(() => Number(document.querySelector('.iwb-editor-brush-size').value) === 12))
// 快捷点:矢量描边
await page.locator('.iwb-editor-tool[data-tool="arrow"]').click()
check('箭头选项栏有 7 个线宽快捷点',
(await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"]').count()) === 7)
await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"][data-value="6"]').click()
check('点线宽快捷点 6:shapeLineWidth 即时生效',
(await dbg()).toolOptions.shapeLineWidth === 6)
// 高亮跟随绘制目标:画一笔后面板选中层 == 画笔目标层
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
await drag2(liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.75,
liveBox.x + liveBox.width * 0.65, liveBox.y + liveBox.height * 0.85)
const syncDbg = await dbg()
check('画笔落笔后面板高亮层 == 绘制目标层(不再「没选中却能画」)',
syncDbg.selectedLayerId === syncDbg.activeLayerId,
'selected=' + syncDbg.selectedLayerId + ' active=' + syncDbg.activeLayerId)
// 变换手柄只在 select 工具出现:画笔态 overlay 无手柄像素,切到选择工具后出现
const overlayAlpha = () => page.evaluate(() => {
const c = document.querySelector('.iwb-editor-crop-overlay')
if (!c) return -1
const cx = c.getContext('2d')
const d = cx.getImageData(0, 0, c.width, c.height).data
let n = 0
for (let i = 3; i < d.length; i += 4) if (d[i] > 0) n++
return n
})
check('画笔工具下选中层不画变换手柄(overlay 干净)', (await overlayAlpha()) === 0)
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
check('切到选择工具后变换框/手柄出现(overlay 有像素)', (await overlayAlpha()) > 0)
await page.keyboard.press('Escape') // 清选中,避免影响后续
// 裁剪:Esc 取消 / Enter 确认
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15,
liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6)
check('拉出裁剪框后选项栏显示尺寸摘要',
(await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) !== '--')
await page.keyboard.press('Escape')
check('Esc 取消裁剪(摘要复位为 --)',
(await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) === '--')
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15,
liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6)
const docBeforeEnter = (await dbg()).doc
await page.keyboard.press('Enter')
const docAfterEnter = (await dbg()).doc
check('Enter 确认裁剪(画布尺寸变小、与按钮确认等效)',
docAfterEnter.w < docBeforeEnter.w && docAfterEnter.h < docBeforeEnter.h,
JSON.stringify(docBeforeEnter) + ' → ' + JSON.stringify(docAfterEnter))
await page.keyboard.press('Control+z')
// ---- Fix4:点「退出」必须结算宿主 Promise(glue.openEditor → onClose) ----
await page.locator('[data-action="cancel"]').click()
const openState = await poll(async () => page.evaluate(() => window.__openState))