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

+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, // 矩形/圆形/箭头/钢笔的描边粗细