feat(image-annotate): 1.2.1 默认不预建画笔层(按需自动落标注层)+ 侧栏硬度/透明去重

This commit is contained in:
qiqi committed 2026-11-04 20:06:38 +08:00
1 parent d8e4e0cb26
commit 1bf8220c05
10 files changed
+124 -114

No files matched your search

+30
View File
@@ -319,6 +319,36 @@ export function setActiveLayer(id) {
placeImageDirectly(img)
}
/** 确保有可绘制的活动图层:没有(或被锁定)就自动落一个「标注 N」空层并激活。
* 默认不再预建画笔层(用户裁定:需要时自己加),所以画笔起笔前必须兜底建层。
* 注意:本函数不进历史 —— 调用方(onBrushMouseDown)随后 saveSnapshot(),
* 这样首笔 Ctrl+Z 会连「自动建的层 + 笔迹」一起撤掉,不留空层。 */
export function ensureWritableLayer() {
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() * 1000) : 'draw'
const canvas = createLayerCanvas()
const ctx = canvas.getContext('2d', { willReadFrequently: true })
ctx.clearRect(0, 0, S.imgW, S.imgH)
const layer = {
id,
name: '标注 ' + (S.layers.filter(l => l.id !== 'base').length + 1),
canvas,
ctx,
opacity: 1,
visible: true,
locked: false,
x: 0, y: 0, w: S.imgW, h: S.imgH,
rotation: 0,
z: ++S.zCounter
}
S.layers.push(layer)
reorderLayerCanvas()
setActiveLayer(id)
renderLayerPanel()
return layer
}
/** 新建空白图层 */
export function addBlankLayer() { // 创建可独立编辑的位图图层