fix(image-annotate): 1.1.1 反选作用区域/裁剪态选区互斥/Delete 优先级/退出结算宿主 Promise(含 1.1.0 布局修复)
This commit is contained in:
1 parent
be05f31479
commit
9a0f5bab69
8 files changed
+259
-20
No files matched your search
@@ -24,7 +24,7 @@ import { createLayerCanvas, getActiveLayer, reorderLayerCanvas, setActiveLayer,
|
||||
export function selectionInfo() {
|
||||
if (!hasSelection()) return null
|
||||
const b = S.selection.bbox
|
||||
return { kind: S.selection.kind, x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h), feather: S.selection.feather || 0 }
|
||||
return { kind: S.selection.kind, x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h), feather: S.selection.feather || 0, inverted: !!S.selection.inverted }
|
||||
}
|
||||
|
||||
// ============ 选区图层(独立 canvas) ============
|
||||
@@ -159,6 +159,10 @@ import { createLayerCanvas, getActiveLayer, reorderLayerCanvas, setActiveLayer,
|
||||
} else {
|
||||
path.addPath(outlinePath)
|
||||
}
|
||||
// 建立像素选区即接管 Delete 语义:清掉矢量对象选中态,否则
|
||||
// 「选中形状 → Ctrl+A → Delete」会走删对象分支,而不是清像素。
|
||||
S.selectedTextId = null
|
||||
S.selectedShapeId = null
|
||||
S.selection = {
|
||||
kind, path, outlinePath, bbox,
|
||||
fillRule: inverted ? 'evenodd' : 'nonzero',
|
||||
@@ -258,27 +262,45 @@ import { createLayerCanvas, getActiveLayer, reorderLayerCanvas, setActiveLayer,
|
||||
|
||||
// ============ 局部掩膜(羽化软边) ============
|
||||
/**
|
||||
* 返回覆盖 bbox 的 alpha 掩膜(局部 tile,不是全幅)。
|
||||
* 掩膜必须覆盖的范围(整数基准,避免 tile 原点与平移量差 1px)。
|
||||
* 反选的 path 是「整图矩形 + 原选区」,只按原 bbox 开 tile 会把 tile 之外
|
||||
* 的反选区域整块丢掉 —— 填充走全幅 fill(path) 不受影响,于是 Delete/复制/剪切
|
||||
* 只作用原 bbox,与填充互相矛盾。反选时扩成整幅,临时画布用完即弃。
|
||||
*/
|
||||
function maskExtent() {
|
||||
const sel = S.selection
|
||||
const b = sel.inverted ? { x: 0, y: 0, w: S.imgW, h: S.imgH } : sel.bbox
|
||||
const x = Math.floor(b.x)
|
||||
const y = Math.floor(b.y)
|
||||
return {
|
||||
x, y,
|
||||
w: Math.max(1, Math.ceil(b.x + b.w) - x),
|
||||
h: Math.max(1, Math.ceil(b.y + b.h) - y)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回覆盖 bbox 的 alpha 掩膜(局部 tile,不是全幅;反选时整幅)。
|
||||
* feather>0 用 Canvas2D 原生 filter 模糊填充边缘,CSP 不限制。
|
||||
*/
|
||||
function buildMask() {
|
||||
const sel = S.selection
|
||||
const feather = sel.feather || 0
|
||||
const pad = Math.ceil(feather * 2)
|
||||
const b = sel.bbox
|
||||
const w = Math.max(1, Math.ceil(b.w) + pad * 2)
|
||||
const h = Math.max(1, Math.ceil(b.h) + pad * 2)
|
||||
const e = maskExtent()
|
||||
const w = e.w + pad * 2
|
||||
const h = e.h + pad * 2
|
||||
const c = document.createElement('canvas')
|
||||
c.width = w
|
||||
c.height = h
|
||||
const cx = c.getContext('2d')
|
||||
cx.save()
|
||||
cx.translate(-b.x + pad, -b.y + pad)
|
||||
cx.translate(-e.x + pad, -e.y + pad)
|
||||
if (feather > 0) cx.filter = 'blur(' + feather + 'px)'
|
||||
cx.fillStyle = '#ffffff'
|
||||
cx.fill(sel.path, sel.fillRule)
|
||||
cx.restore()
|
||||
return { canvas: c, x: Math.floor(b.x) - pad, y: Math.floor(b.y) - pad, w, h }
|
||||
return { canvas: c, x: e.x - pad, y: e.y - pad, w, h }
|
||||
}
|
||||
|
||||
function writableLayer() {
|
||||
|
||||
Reference in new issue
Block a user