dsh-gallery 0.14.3 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -3
- package/README.md +66 -15
- package/client.js +1236 -24
- package/cordis.patch.yml +1 -1
- package/docs/screenshots/01-current-chat.png +0 -0
- package/docs/screenshots/02-global-assets.png +0 -0
- package/docs/screenshots/03-frame-feedback.png +0 -0
- package/docs/screenshots/04-annot-follow.png +0 -0
- package/docs/screenshots/05-mask-principle.png +0 -0
- package/host/feedback-text.js +44 -1
- package/host/frames.js +59 -0
- package/host/http.js +167 -1
- package/host/scan.js +106 -6
- package/icon.svg +4 -6
- package/index.js +1 -1
- package/locale/zh.json +1 -1
- package/package.json +12 -3
package/client.js
CHANGED
|
@@ -87,6 +87,374 @@ function normalizeAnnotation(a) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* 批注层几何(v0.14.4):SVG 与 <img> 共用同一布局盒、同一组 translate/scale。
|
|
92
|
+
* 图片按 object-fit:contain 居中后,实际显示盒往往小于预览容器;旧版 SVG 覆盖整个
|
|
93
|
+
* 容器且不带变换,1:1 就可能错位,放大后更彻底脱框。抽成纯函数便于离线钉死契约。
|
|
94
|
+
*/
|
|
95
|
+
function annotationSvgStyle(imgBox, pan, zoom, transition) {
|
|
96
|
+
return {
|
|
97
|
+
position: 'absolute',
|
|
98
|
+
left: `${imgBox.left}px`,
|
|
99
|
+
top: `${imgBox.top}px`,
|
|
100
|
+
width: `${imgBox.width}px`,
|
|
101
|
+
height: `${imgBox.height}px`,
|
|
102
|
+
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
103
|
+
transformOrigin: '50% 50%',
|
|
104
|
+
transition,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 标注态「按下要不要拦冒泡 / 交给谁」的判定(v0.14.4)。
|
|
110
|
+
* 查看器本身就支持中键拖拽平移;标注层过去对所有按键一律 stopPropagation,
|
|
111
|
+
* 把中键吞掉,导致标注时挪不动图。现在:中键放行给查看器平移,左键留给画框。
|
|
112
|
+
*/
|
|
113
|
+
function annotationPointerRouting(active, button) {
|
|
114
|
+
// 未激活:不拦(图片 pointerEvents:none,事件本就落到查看器)
|
|
115
|
+
if (!active) return 'pass'
|
|
116
|
+
// 中键(1):放行给查看器的中键拖拽平移,框跟着图走(已画框与图共用 pan/zoom)
|
|
117
|
+
if (button === 1) return 'pan'
|
|
118
|
+
// 左键(0)及其余:拦住,交给标注层画框;顺带防止弹窗输入被查看器拖图抢走
|
|
119
|
+
return 'draw'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 标注层 SVG 的光标:中键平移进行中显示抓握,否则画框态为十字。 */
|
|
123
|
+
function annotationSvgCursor(active, dragging, zoom) {
|
|
124
|
+
if (!active) return 'default'
|
|
125
|
+
if (dragging && zoom > 1) return 'grabbing'
|
|
126
|
+
return 'crosshair'
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 遮罩编码契约(v0.14.5 本机 MVP)—— 本机实证,不是推测:
|
|
131
|
+
* ComfyUI 官方 LoadImage 与本机孤海 LoadImageGoohai 的 MASK 输出都是 `1 - alpha/255`。
|
|
132
|
+
* 所以「框内 alpha=0、框外 alpha=255」的普通 RGBA PNG 直接就是可用遮罩,
|
|
133
|
+
* RGB 必须保留原图像素(LoadImage 的 IMAGE 输出仍拿它做局部重绘)。
|
|
134
|
+
* 这与 clipspace-painted-* 涂鸦遮罩等价,但不必复刻 ComfyUI 画布交互。
|
|
135
|
+
*
|
|
136
|
+
* 注意:遮罩是**新资产**(同视频截帧,落盘并登记到当前对话),不是批注;
|
|
137
|
+
* 批注依旧只存内存。导出的路径只进反馈草稿,零自动发送、插件零外部请求。
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/** 原图像素上限:超过拒绝生成,避免超大图卡死前端(host 另有 24 MB 兜底)。 */
|
|
141
|
+
const MASK_MAX_PIXELS = 24000000
|
|
142
|
+
|
|
143
|
+
/** 归一化框选批注 → 原图像素矩形(clamp + 至少 1px,不越界)。 */
|
|
144
|
+
function maskPixelRect(annotation, width, height) {
|
|
145
|
+
const w = Math.max(1, Math.round(Number(width) || 0))
|
|
146
|
+
const h = Math.max(1, Math.round(Number(height) || 0))
|
|
147
|
+
const x = clamp01(annotation?.x)
|
|
148
|
+
const y = clamp01(annotation?.y)
|
|
149
|
+
let nw = clamp01(annotation?.w)
|
|
150
|
+
let nh = clamp01(annotation?.h)
|
|
151
|
+
if (nw > 0 && x + nw > 1) nw = 1 - x
|
|
152
|
+
if (nh > 0 && y + nh > 1) nh = 1 - y
|
|
153
|
+
const x0 = Math.min(w - 1, Math.max(0, Math.round(x * w)))
|
|
154
|
+
const y0 = Math.min(h - 1, Math.max(0, Math.round(y * h)))
|
|
155
|
+
const x1 = Math.min(w, Math.max(x0 + 1, Math.round((x + nw) * w)))
|
|
156
|
+
const y1 = Math.min(h, Math.max(y0 + 1, Math.round((y + nh) * h)))
|
|
157
|
+
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0, width: w, height: h }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 单像素 alpha:框内 0(mask=1 待重绘),框外 255(mask=0 保留)。 */
|
|
161
|
+
function maskAlphaAt(px, py, rect) {
|
|
162
|
+
const inside = px >= rect.x && px < rect.x + rect.w && py >= rect.y && py < rect.y + rect.h
|
|
163
|
+
return inside ? 0 : 255
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* ------------------------------------------------------------------ *
|
|
167
|
+
* v0.14.6 右键多点选区(老板 2026-11-12 拍板):
|
|
168
|
+
* 标记态下左键仍是矩形批注,右键逐点点击 4–20 个顶点,闭合成实心多边形。
|
|
169
|
+
* 实测口径(见验证报告第九节):必须是「实心、贴合目标外接框」的块,
|
|
170
|
+
* 描笔画的镂空线框 / 椭圆 / 大矩形都会出白底;多边形天然实心且面积可量。
|
|
171
|
+
* ------------------------------------------------------------------ */
|
|
172
|
+
const POLYGON_LIMITS = { min: 4, max: 20, closeRadius: 0.02, minArea: 0.0001 }
|
|
173
|
+
|
|
174
|
+
/* ------------------------------------------------------------------ *
|
|
175
|
+
* 选区纯色半透明填充(v0.14.7 引入;老板 2026-11-12 20:22 再定版):
|
|
176
|
+
* 填充 0.4 / 轮廓 0.7,界面选区与「填充预览图」共用红 / 绿 / 蓝三色;
|
|
177
|
+
* 导出的主 alpha 遮罩仍是「RGB 原图 + alpha 二值」,ComfyUI 链路一点不动。
|
|
178
|
+
* 轮廓视觉宽度统一 1.5px:界面 SVG 用 non-scaling-stroke 直接画 1.5px;
|
|
179
|
+
* 导出预览图按「DSH 缩到 200px 长边后仍留 1.5px」反推线宽 —— 固定 2px
|
|
180
|
+
* 描边缩完会消失,过宽的边线又会糊住选区,两端共用同一个基准常量。
|
|
181
|
+
* ------------------------------------------------------------------ */
|
|
182
|
+
const MASK_FILL_COLORS = Object.freeze({
|
|
183
|
+
green: { rgb: [94, 214, 150], label: '绿' },
|
|
184
|
+
red: { rgb: [239, 68, 68], label: '红' },
|
|
185
|
+
blue: { rgb: [59, 130, 246], label: '蓝' },
|
|
186
|
+
})
|
|
187
|
+
const MASK_FILL_KEYS = Object.keys(MASK_FILL_COLORS)
|
|
188
|
+
const MASK_FILL_ALPHA = 0.4
|
|
189
|
+
const MASK_STROKE_ALPHA = 0.7
|
|
190
|
+
/** 轮廓视觉宽度基准(px):界面直接画,导出预览图按缩略图比例反推。 */
|
|
191
|
+
const MASK_STROKE_PX = 1.5
|
|
192
|
+
|
|
193
|
+
/** 未知颜色一律回落绿色,避免脏值写进文件名 / 元数据。 */
|
|
194
|
+
function maskFillColor(key) {
|
|
195
|
+
return Object.prototype.hasOwnProperty.call(MASK_FILL_COLORS, key)
|
|
196
|
+
? MASK_FILL_COLORS[key] : MASK_FILL_COLORS.green
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function maskFillRgba(key, alpha = MASK_FILL_ALPHA) {
|
|
200
|
+
const [r, g, b] = maskFillColor(key).rgb
|
|
201
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 预览图轮廓线宽:以「DSH 缩略图长边 200px 时描边仍约 1.5px」反推,
|
|
206
|
+
* 夹在 6–40px,避免小图线条消失、超大图线条糊成一片。纯函数,测试跑真身。
|
|
207
|
+
*/
|
|
208
|
+
function maskStrokeWidth(width, height) {
|
|
209
|
+
const w = Math.max(1, Number(width) || 0)
|
|
210
|
+
const h = Math.max(1, Number(height) || 0)
|
|
211
|
+
const scale = Math.max(w, h) / 200
|
|
212
|
+
return Math.max(6, Math.min(40, Math.round(MASK_STROKE_PX * scale)))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** 预览层的填充 / 轮廓描述(纯函数,测试直接跑真身):多边形优先,矩形回落。 */
|
|
216
|
+
function maskOverlayPath(rect, polygonPx, colorKey) {
|
|
217
|
+
const hasPolygon = Array.isArray(polygonPx) && polygonPx.length >= 3
|
|
218
|
+
return {
|
|
219
|
+
key: Object.prototype.hasOwnProperty.call(MASK_FILL_COLORS, colorKey) ? colorKey : 'green',
|
|
220
|
+
label: maskFillColor(colorKey).label,
|
|
221
|
+
rgba: maskFillRgba(colorKey, MASK_FILL_ALPHA),
|
|
222
|
+
strokeRgba: maskFillRgba(colorKey, MASK_STROKE_ALPHA),
|
|
223
|
+
strokeWidth: maskStrokeWidth(rect?.width, rect?.height),
|
|
224
|
+
points: hasPolygon ? polygonPx : null,
|
|
225
|
+
rect: hasPolygon ? null : { x: rect.x, y: rect.y, w: rect.w, h: rect.h },
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** 顶点数组的归一外接框;points 既接受 [{x,y}] 也接受 [[x,y]]。 */
|
|
230
|
+
function polygonBBox(points) {
|
|
231
|
+
const xs = points.map((p) => clamp01(Array.isArray(p) ? p[0] : p?.x))
|
|
232
|
+
const ys = points.map((p) => clamp01(Array.isArray(p) ? p[1] : p?.y))
|
|
233
|
+
const x0 = Math.min(...xs)
|
|
234
|
+
const y0 = Math.min(...ys)
|
|
235
|
+
const x1 = Math.max(...xs)
|
|
236
|
+
const y1 = Math.max(...ys)
|
|
237
|
+
return { x: x0, y: y0, w: clamp01(x1 - x0), h: clamp01(y1 - y0) }
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** 鞋带公式:归一化面积,用来挡掉「点成一条线」的退化选区。 */
|
|
241
|
+
function polygonArea(points) {
|
|
242
|
+
let sum = 0
|
|
243
|
+
for (let i = 0, j = points.length - 1; i < points.length; j = i, i += 1) {
|
|
244
|
+
const xi = Array.isArray(points[i]) ? points[i][0] : points[i].x
|
|
245
|
+
const yi = Array.isArray(points[i]) ? points[i][1] : points[i].y
|
|
246
|
+
const xj = Array.isArray(points[j]) ? points[j][0] : points[j].x
|
|
247
|
+
const yj = Array.isArray(points[j]) ? points[j][1] : points[j].y
|
|
248
|
+
sum += (xj * yi) - (xi * yj)
|
|
249
|
+
}
|
|
250
|
+
return Math.abs(sum) / 2
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** 射线法(无 canvas 环境兜底,也用于离线断言钉死「多边形内 alpha=0」)。 */
|
|
254
|
+
function pointInPolygon(px, py, points) {
|
|
255
|
+
let inside = false
|
|
256
|
+
for (let i = 0, j = points.length - 1; i < points.length; j = i, i += 1) {
|
|
257
|
+
const xi = points[i][0]
|
|
258
|
+
const yi = points[i][1]
|
|
259
|
+
const xj = points[j][0]
|
|
260
|
+
const yj = points[j][1]
|
|
261
|
+
const hit = ((yi > py) !== (yj > py))
|
|
262
|
+
&& (px < (((xj - xi) * (py - yi)) / (yj - yi)) + xi)
|
|
263
|
+
if (hit) inside = !inside
|
|
264
|
+
}
|
|
265
|
+
return inside
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** 归一化顶点 → 原图像素顶点;点不合法或数量越界一律返回 null。 */
|
|
269
|
+
function normalizePolygon(value, width, height) {
|
|
270
|
+
if (!Array.isArray(value) || value.length < POLYGON_LIMITS.min || value.length > POLYGON_LIMITS.max) return null
|
|
271
|
+
const w = Math.max(1, Math.round(Number(width) || 0))
|
|
272
|
+
const h = Math.max(1, Math.round(Number(height) || 0))
|
|
273
|
+
const pts = []
|
|
274
|
+
for (const p of value) {
|
|
275
|
+
const nx = Number(Array.isArray(p) ? p[0] : p?.x)
|
|
276
|
+
const ny = Number(Array.isArray(p) ? p[1] : p?.y)
|
|
277
|
+
if (!Number.isFinite(nx) || !Number.isFinite(ny)) return null
|
|
278
|
+
pts.push([clamp01(nx) * w, clamp01(ny) * h])
|
|
279
|
+
}
|
|
280
|
+
return pts
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 多边形 → 全尺寸二值 alpha 层(0 = 待重绘,255 = 保留)。
|
|
285
|
+
* 优先用离屏 canvas 填充(浏览器自动处理自交、抗锯齿与非零环绕),
|
|
286
|
+
* 只在 bbox 子画布上读一次像素,避免全图再开一份 ImageData;
|
|
287
|
+
* 读回后按 >127 强制二值,保持与 ComfyUI `MASK = 1 - alpha/255` 的实证契约一致。
|
|
288
|
+
* Node / 无 canvas 环境退化为射线法,测试可直接跑真身。
|
|
289
|
+
*/
|
|
290
|
+
function polygonAlphaLayer(points, width, height) {
|
|
291
|
+
const w = Math.max(1, Math.round(Number(width) || 0))
|
|
292
|
+
const h = Math.max(1, Math.round(Number(height) || 0))
|
|
293
|
+
const out = new Uint8Array(w * h).fill(255)
|
|
294
|
+
const xs = points.map((p) => p[0])
|
|
295
|
+
const ys = points.map((p) => p[1])
|
|
296
|
+
const x0 = Math.max(0, Math.min(w - 1, Math.floor(Math.min(...xs))))
|
|
297
|
+
const y0 = Math.max(0, Math.min(h - 1, Math.floor(Math.min(...ys))))
|
|
298
|
+
const x1 = Math.min(w, Math.max(x0 + 1, Math.ceil(Math.max(...xs))))
|
|
299
|
+
const y1 = Math.min(h, Math.max(y0 + 1, Math.ceil(Math.max(...ys))))
|
|
300
|
+
const bw = x1 - x0
|
|
301
|
+
const bh = y1 - y0
|
|
302
|
+
let ctx = null
|
|
303
|
+
try {
|
|
304
|
+
if (typeof OffscreenCanvas === 'function') {
|
|
305
|
+
const canvas = new OffscreenCanvas(bw, bh)
|
|
306
|
+
ctx = canvas.getContext('2d', { willReadFrequently: true })
|
|
307
|
+
} else if (typeof document !== 'undefined') {
|
|
308
|
+
const canvas = document.createElement('canvas')
|
|
309
|
+
canvas.width = bw
|
|
310
|
+
canvas.height = bh
|
|
311
|
+
ctx = canvas.getContext('2d', { willReadFrequently: true })
|
|
312
|
+
}
|
|
313
|
+
} catch { ctx = null }
|
|
314
|
+
if (ctx !== null) {
|
|
315
|
+
ctx.fillStyle = '#000'
|
|
316
|
+
ctx.fillRect(0, 0, bw, bh)
|
|
317
|
+
ctx.fillStyle = '#fff'
|
|
318
|
+
ctx.beginPath()
|
|
319
|
+
ctx.moveTo(points[0][0] - x0, points[0][1] - y0)
|
|
320
|
+
for (let i = 1; i < points.length; i += 1) ctx.lineTo(points[i][0] - x0, points[i][1] - y0)
|
|
321
|
+
ctx.closePath()
|
|
322
|
+
ctx.fill()
|
|
323
|
+
const sub = ctx.getImageData(0, 0, bw, bh).data
|
|
324
|
+
for (let py = 0; py < bh; py += 1) {
|
|
325
|
+
for (let px = 0; px < bw; px += 1) {
|
|
326
|
+
if (sub[((py * bw) + px) * 4] > 127) out[((py + y0) * w) + (px + x0)] = 0
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
for (let py = y0; py < y1; py += 1) {
|
|
331
|
+
for (let px = x0; px < x1; px += 1) {
|
|
332
|
+
if (pointInPolygon(px + 0.5, py + 0.5, points)) out[(py * w) + px] = 0
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return out
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/* ------------------------------------------------------------------ *
|
|
340
|
+
* RGBA 主遮罩 PNG 编码器(v0.14.9 修复 canvas 预乘 alpha 丢 RGB)
|
|
341
|
+
*
|
|
342
|
+
* 本机实证:canvas 内部是预乘 alpha 存储,putImageData → convertToBlob 往返后,
|
|
343
|
+
* alpha=0 的选区内 RGB 会被清零(区内均值差 147.39),而 ComfyUI
|
|
344
|
+
* #369 LoadImageGoohai 的 IMAGE 输出需要原图 RGB。主遮罩必须直接从
|
|
345
|
+
* 「RGB 原图 + 只改过 alpha」的 ImageData 编 PNG,一次也不回写 canvas。
|
|
346
|
+
* ------------------------------------------------------------------ */
|
|
347
|
+
|
|
348
|
+
/** CRC-32(IEEE 802.3),PNG chunk 校验用。 */
|
|
349
|
+
function pngCrc32(bytes) {
|
|
350
|
+
let c = 0xffffffff
|
|
351
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
352
|
+
c ^= bytes[i]
|
|
353
|
+
for (let k = 0; k < 8; k += 1) c = (c >>> 1) ^ (0xedb88320 & -(c & 1))
|
|
354
|
+
}
|
|
355
|
+
return (c ^ 0xffffffff) >>> 0
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** 组装一个 PNG chunk:长度 + 类型 + 数据 + CRC。 */
|
|
359
|
+
function pngChunk(type, data) {
|
|
360
|
+
const out = new Uint8Array(12 + data.length)
|
|
361
|
+
const view = new DataView(out.buffer)
|
|
362
|
+
view.setUint32(0, data.length)
|
|
363
|
+
for (let i = 0; i < 4; i += 1) out[4 + i] = type.charCodeAt(i)
|
|
364
|
+
out.set(data, 8)
|
|
365
|
+
view.setUint32(8 + data.length, pngCrc32(out.subarray(4, 8 + data.length)))
|
|
366
|
+
return out
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** ImageData → PNG 扫描线:每行前置 filter=0,RGBA 四通道原样搬运。 */
|
|
370
|
+
function pngScanlines(imageData, width, height) {
|
|
371
|
+
const src = imageData.data
|
|
372
|
+
const stride = width * 4
|
|
373
|
+
const out = new Uint8Array((stride + 1) * height)
|
|
374
|
+
let p = 0
|
|
375
|
+
for (let y = 0; y < height; y += 1) {
|
|
376
|
+
out[p] = 0
|
|
377
|
+
p += 1
|
|
378
|
+
out.set(src.subarray(y * stride, (y + 1) * stride), p)
|
|
379
|
+
p += stride
|
|
380
|
+
}
|
|
381
|
+
return out
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Adler-32,zlib 尾部校验。 */
|
|
385
|
+
function pngAdler32(bytes) {
|
|
386
|
+
let a = 1
|
|
387
|
+
let b = 0
|
|
388
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
389
|
+
a = (a + bytes[i]) % 65521
|
|
390
|
+
b = (b + a) % 65521
|
|
391
|
+
}
|
|
392
|
+
return ((b << 16) | a) >>> 0
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** 拼接若干 Uint8Array。 */
|
|
396
|
+
function pngConcat(parts) {
|
|
397
|
+
const out = new Uint8Array(parts.reduce((s, p) => s + p.length, 0))
|
|
398
|
+
let p = 0
|
|
399
|
+
for (const part of parts) { out.set(part, p); p += part.length }
|
|
400
|
+
return out
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** zlib「stored」无压缩流,同步兜底(CompressionStream 不可用时)。 */
|
|
404
|
+
function pngZlibStored(bytes) {
|
|
405
|
+
const parts = [new Uint8Array([0x78, 0x01])]
|
|
406
|
+
let off = 0
|
|
407
|
+
while (off < bytes.length) {
|
|
408
|
+
const len = Math.min(65535, bytes.length - off)
|
|
409
|
+
const last = off + len >= bytes.length ? 1 : 0
|
|
410
|
+
const blk = new Uint8Array(5 + len)
|
|
411
|
+
blk[0] = last
|
|
412
|
+
blk[1] = len & 0xff
|
|
413
|
+
blk[2] = (len >> 8) & 0xff
|
|
414
|
+
blk[3] = (~len) & 0xff
|
|
415
|
+
blk[4] = ((~len) >> 8) & 0xff
|
|
416
|
+
blk.set(bytes.subarray(off, off + len), 5)
|
|
417
|
+
parts.push(blk)
|
|
418
|
+
off += len
|
|
419
|
+
}
|
|
420
|
+
const tail = new Uint8Array(4)
|
|
421
|
+
new DataView(tail.buffer).setUint32(0, pngAdler32(bytes))
|
|
422
|
+
parts.push(tail)
|
|
423
|
+
return pngConcat(parts)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* ImageData → RGBA PNG 字节。优先 CompressionStream('deflate') 出标准 zlib 流,
|
|
428
|
+
* 不可用则退回同步 stored 流;两条路都不经过 canvas,RGB 一像素不丢。
|
|
429
|
+
*/
|
|
430
|
+
async function encodeMaskPngBytes(imageData, width, height) {
|
|
431
|
+
const w = Math.max(1, Math.round(Number(width) || 0))
|
|
432
|
+
const h = Math.max(1, Math.round(Number(height) || 0))
|
|
433
|
+
const ihdr = new Uint8Array(13)
|
|
434
|
+
const iv = new DataView(ihdr.buffer)
|
|
435
|
+
iv.setUint32(0, w)
|
|
436
|
+
iv.setUint32(4, h)
|
|
437
|
+
ihdr[8] = 8
|
|
438
|
+
ihdr[9] = 6
|
|
439
|
+
const raw = pngScanlines(imageData, w, h)
|
|
440
|
+
let idat = null
|
|
441
|
+
if (typeof CompressionStream === 'function' && typeof Blob === 'function' && typeof Response === 'function') {
|
|
442
|
+
try {
|
|
443
|
+
const stream = new Blob([raw]).stream().pipeThrough(new CompressionStream('deflate'))
|
|
444
|
+
idat = new Uint8Array(await new Response(stream).arrayBuffer())
|
|
445
|
+
} catch {
|
|
446
|
+
idat = null
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (idat === null) idat = pngZlibStored(raw)
|
|
450
|
+
return pngConcat([
|
|
451
|
+
new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]),
|
|
452
|
+
pngChunk('IHDR', ihdr),
|
|
453
|
+
pngChunk('IDAT', idat),
|
|
454
|
+
pngChunk('IEND', new Uint8Array(0)),
|
|
455
|
+
])
|
|
456
|
+
}
|
|
457
|
+
|
|
90
458
|
|
|
91
459
|
/** tab 类型的身份;也是正文与标题在 keyed slot 里的 key。 */
|
|
92
460
|
const KIND = 'gallery'
|
|
@@ -137,8 +505,8 @@ function normalizeAnnotation(a) {
|
|
|
137
505
|
/** 中英字典(拆分自 client.js L54-L379)。 */
|
|
138
506
|
|
|
139
507
|
const zh = {
|
|
140
|
-
'type.label': '
|
|
141
|
-
'guide.title': '
|
|
508
|
+
'type.label': '产出台',
|
|
509
|
+
'guide.title': '产出台',
|
|
142
510
|
'guide.description': '最近 24 小时的产出图片',
|
|
143
511
|
loading: '正在扫描…',
|
|
144
512
|
refreshing: '刷新中…',
|
|
@@ -194,10 +562,11 @@ function normalizeAnnotation(a) {
|
|
|
194
562
|
catFilterFinal: '定稿',
|
|
195
563
|
annotEnter: '标注',
|
|
196
564
|
annotExit: '退出标注',
|
|
565
|
+
annotPanHint: '按住鼠标中键拖动可平移图片(放大后生效),已画框会跟着走',
|
|
197
566
|
annotNotePrompt: '这块要改什么?(可留空)',
|
|
198
567
|
annotNotePlaceholder: '例如:沙发位置偏了 / 色调太暖',
|
|
199
568
|
annotNoNote: '(无说明)',
|
|
200
|
-
annotHint: '
|
|
569
|
+
annotHint: '左键拖拽或点两下画矩形批注;右键逐点圈出 4–20 点的多边形,闭合后直接生成局部重绘遮罩',
|
|
201
570
|
annotCount: '批注 {n} 处',
|
|
202
571
|
annotPendingTag: '待保存',
|
|
203
572
|
annotPendingHint: '黄色亮框就是刚圈的位置;写完点「保存并生效」,也可以直接在图上继续圈下一处(这处会先自动存档)',
|
|
@@ -378,6 +747,23 @@ function normalizeAnnotation(a) {
|
|
|
378
747
|
feedbackAnnotRegion: '区域 左{x}% 上{y}% · 宽{w}% 高{h}%',
|
|
379
748
|
feedbackAnnotNoNote: '(未填说明,按框选区域改)',
|
|
380
749
|
feedbackFrameFrom: '取自《{name}》{timecode} 帧',
|
|
750
|
+
// 遮罩导出(v0.14.5 本机 MVP):矩形框选批注 → ComfyUI 可用的 RGBA 遮罩
|
|
751
|
+
maskExport: '导出遮罩',
|
|
752
|
+
maskExportHint: '按这个框生成 ComfyUI 可用的 RGBA 遮罩(框内为待重绘区域)',
|
|
753
|
+
maskExporting: '正在生成遮罩…',
|
|
754
|
+
maskSaved: '已生成遮罩:{name}(已入当前对话资产)',
|
|
755
|
+
maskFailed: '遮罩生成失败:{message}',
|
|
756
|
+
// v0.14.6 右键多点选区(4–20 点)→ 实心多边形遮罩
|
|
757
|
+
polyTitle: '多边形遮罩选区',
|
|
758
|
+
polyInfo: '{n}/{max} 点 · 外接框 左{x}% 上{y}% · {w}%×{h}% · 选区约占全图 {area}%',
|
|
759
|
+
polyHint: '右键逐点圈选;点回起点、按 Enter 或点「闭合并生成遮罩」即导出。顶点可左键拖动微调,Backspace 撤销一点,Escape 清空。',
|
|
760
|
+
polyFillColor: '填充色:',
|
|
761
|
+
polyClose: '闭合并生成遮罩',
|
|
762
|
+
polyUndo: '撤销一点',
|
|
763
|
+
polyClear: '清空',
|
|
764
|
+
polyTooFew: '至少 4 个点才能闭合',
|
|
765
|
+
polyDegenerate: '选区面积太小(点几乎连成一条线),请重新围一圈',
|
|
766
|
+
feedbackMaskFrom: '已有遮罩:{name}',
|
|
381
767
|
feedbackAnnotHint: '{n} 条框选批注会随反馈一起发出,序号与草稿里的 Annotation N 一一对应',
|
|
382
768
|
feedbackEditTitle: '编辑:{name}',
|
|
383
769
|
feedbackReasonLabel: '理由(可选)',
|
|
@@ -511,10 +897,11 @@ function normalizeAnnotation(a) {
|
|
|
511
897
|
catFilterFinal: 'Final',
|
|
512
898
|
annotEnter: 'Annotate',
|
|
513
899
|
annotExit: 'Exit annotate',
|
|
900
|
+
annotPanHint: 'Hold the middle mouse button to pan (works when zoomed in); drawn boxes follow the image',
|
|
514
901
|
annotNotePrompt: 'What should change here? (optional)',
|
|
515
902
|
annotNotePlaceholder: 'e.g. sofa position is off / color is too warm',
|
|
516
903
|
annotNoNote: '(no note)',
|
|
517
|
-
annotHint: '
|
|
904
|
+
annotHint: 'Left-drag or click twice for a boxed note; right-click 4–20 vertices for a polygon selection that becomes an inpaint mask',
|
|
518
905
|
annotCount: '{n} annotation(s)',
|
|
519
906
|
annotPendingTag: 'Pending',
|
|
520
907
|
annotPendingHint: 'The yellow box is the area you just marked. Add a note and click Save, or keep boxing more areas (this one is stored first).',
|
|
@@ -693,6 +1080,23 @@ function normalizeAnnotation(a) {
|
|
|
693
1080
|
feedbackAnnotRegion: 'region left {x}% top {y}% · {w}%×{h}%',
|
|
694
1081
|
feedbackAnnotNoNote: '(no note — change the boxed area)',
|
|
695
1082
|
feedbackFrameFrom: 'From "{name}" at frame {timecode}',
|
|
1083
|
+
// Mask export (v0.14.5 local MVP): rectangular box annotation -> ComfyUI-ready RGBA mask
|
|
1084
|
+
maskExport: 'Export mask',
|
|
1085
|
+
maskExportHint: 'Generate a ComfyUI-ready RGBA mask from this box (box = area to inpaint)',
|
|
1086
|
+
maskExporting: 'Generating mask…',
|
|
1087
|
+
maskSaved: 'Mask saved: {name} (added to current chat assets)',
|
|
1088
|
+
maskFailed: 'Mask export failed: {message}',
|
|
1089
|
+
// v0.14.6 right-click polygon selection (4-20 points) -> solid polygon mask
|
|
1090
|
+
polyTitle: 'Polygon mask selection',
|
|
1091
|
+
polyInfo: '{n}/{max} points · bbox left {x}% top {y}% · {w}%×{h}% · ~{area}% of image',
|
|
1092
|
+
polyHint: 'Right-click to add vertices; click the first point, press Enter, or use Close & make mask. Drag vertices with the left button; Backspace removes the last point.',
|
|
1093
|
+
polyFillColor: 'Fill:',
|
|
1094
|
+
polyClose: 'Close & make mask',
|
|
1095
|
+
polyUndo: 'Undo point',
|
|
1096
|
+
polyClear: 'Clear',
|
|
1097
|
+
polyTooFew: 'At least 4 points are needed',
|
|
1098
|
+
polyDegenerate: 'Selection area is too small — the points are nearly a line',
|
|
1099
|
+
feedbackMaskFrom: 'Mask ready: {name}',
|
|
696
1100
|
feedbackAnnotHint: '{n} boxed note(s) will be sent with this feedback, numbered to match `Annotation N` in the draft',
|
|
697
1101
|
feedbackEditTitle: 'Edit: {name}',
|
|
698
1102
|
feedbackReasonLabel: 'Reason (optional)',
|
|
@@ -947,6 +1351,106 @@ function normalizeAnnotation(a) {
|
|
|
947
1351
|
})
|
|
948
1352
|
}
|
|
949
1353
|
|
|
1354
|
+
/**
|
|
1355
|
+
* 由「原图 + 一条矩形框选批注」生成 ComfyUI 可用的 RGBA 遮罩 PNG。
|
|
1356
|
+
* 只走插件自己的 Host 路由取原图(同源,canvas 不会被 taint),不发任何外部请求。
|
|
1357
|
+
*/
|
|
1358
|
+
async function buildMaskPng(relPath, annotation) {
|
|
1359
|
+
const blob = await fetchRaw(relPath, new AbortController().signal)
|
|
1360
|
+
const bitmap = await createImageBitmap(blob)
|
|
1361
|
+
try {
|
|
1362
|
+
const rect = maskPixelRect(annotation, bitmap.width, bitmap.height)
|
|
1363
|
+
if (rect.width * rect.height > MASK_MAX_PIXELS) throw new Error('mask-image-too-large')
|
|
1364
|
+
// 右键多边形选区:归一化顶点换算成原图像素坐标;矩形批注为 null,走原来的逐像素框判定。
|
|
1365
|
+
const polygonPx = normalizePolygon(annotation?.polygon, rect.width, rect.height)
|
|
1366
|
+
let canvas
|
|
1367
|
+
if (typeof OffscreenCanvas === 'function') {
|
|
1368
|
+
canvas = new OffscreenCanvas(rect.width, rect.height)
|
|
1369
|
+
} else {
|
|
1370
|
+
canvas = document.createElement('canvas')
|
|
1371
|
+
canvas.width = rect.width
|
|
1372
|
+
canvas.height = rect.height
|
|
1373
|
+
}
|
|
1374
|
+
const context = canvas.getContext('2d', { willReadFrequently: true })
|
|
1375
|
+
if (context === null) throw new Error('mask-canvas-unavailable')
|
|
1376
|
+
// 先画原图:RGB 完整保留;框外 alpha 一律强制 255,源 PNG 自带透明也不会被误判成待重绘。
|
|
1377
|
+
context.drawImage(bitmap, 0, 0)
|
|
1378
|
+
const image = context.getImageData(0, 0, rect.width, rect.height)
|
|
1379
|
+
const data = image.data
|
|
1380
|
+
if (polygonPx !== null) {
|
|
1381
|
+
// 多边形:只在选区内 alpha=0,仍是严格二值,RGB 一像素不动。
|
|
1382
|
+
const alpha = polygonAlphaLayer(polygonPx, rect.width, rect.height)
|
|
1383
|
+
for (let i = 0; i < alpha.length; i += 1) data[(i * 4) + 3] = alpha[i]
|
|
1384
|
+
} else {
|
|
1385
|
+
for (let py = 0; py < rect.height; py += 1) {
|
|
1386
|
+
for (let px = 0; px < rect.width; px += 1) {
|
|
1387
|
+
data[((py * rect.width) + px) * 4 + 3] = maskAlphaAt(px, py, rect)
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
// 🔴 不再 putImageData → convertToBlob:canvas 是预乘 alpha 存储,
|
|
1392
|
+
// alpha=0 的选区内 RGB 会被清零,ComfyUI #369 的 IMAGE 输出必须是原图 RGB。
|
|
1393
|
+
// 直接从上面这份「RGB 原图 + 只改过 alpha」的 ImageData 编 PNG。
|
|
1394
|
+
const pngBytes = await encodeMaskPngBytes(image, rect.width, rect.height)
|
|
1395
|
+
const url = await toDataUrl(new Blob([pngBytes], { type: 'image/png' }))
|
|
1396
|
+
|
|
1397
|
+
// 彩色填充预览:另起一张干净画布,绝不能复用已改 alpha 的遮罩画布。
|
|
1398
|
+
// 选区内叠 0.4 半透明纯色 + 沿同一路径叠 0.7 半透明轮廓;
|
|
1399
|
+
// 轮廓居中描边会让边界外一圈也带色,这是「视觉钥匙」的预期行为,
|
|
1400
|
+
// 精确几何仍只认主 alpha 遮罩,绝不拿这张图去反解或回填工作流。
|
|
1401
|
+
const fill = maskOverlayPath(rect, polygonPx, annotation?.fillColor)
|
|
1402
|
+
let overlayData = null
|
|
1403
|
+
let previewCanvas
|
|
1404
|
+
if (typeof OffscreenCanvas === 'function') {
|
|
1405
|
+
previewCanvas = new OffscreenCanvas(rect.width, rect.height)
|
|
1406
|
+
} else {
|
|
1407
|
+
previewCanvas = document.createElement('canvas')
|
|
1408
|
+
previewCanvas.width = rect.width
|
|
1409
|
+
previewCanvas.height = rect.height
|
|
1410
|
+
}
|
|
1411
|
+
const previewCtx = previewCanvas.getContext('2d')
|
|
1412
|
+
if (previewCtx !== null) {
|
|
1413
|
+
previewCtx.drawImage(bitmap, 0, 0)
|
|
1414
|
+
previewCtx.fillStyle = fill.rgba
|
|
1415
|
+
previewCtx.beginPath()
|
|
1416
|
+
if (fill.points !== null) {
|
|
1417
|
+
previewCtx.moveTo(fill.points[0][0], fill.points[0][1])
|
|
1418
|
+
for (let i = 1; i < fill.points.length; i += 1) {
|
|
1419
|
+
previewCtx.lineTo(fill.points[i][0], fill.points[i][1])
|
|
1420
|
+
}
|
|
1421
|
+
previewCtx.closePath()
|
|
1422
|
+
} else {
|
|
1423
|
+
previewCtx.rect(fill.rect.x, fill.rect.y, fill.rect.w, fill.rect.h)
|
|
1424
|
+
}
|
|
1425
|
+
previewCtx.fill()
|
|
1426
|
+
// 0.7 半透明轮廓:与填充共用同一条路径,线宽按缩略图可见性自适应。
|
|
1427
|
+
// 只画在预览画布上,主遮罩画布一像素不动。
|
|
1428
|
+
previewCtx.strokeStyle = fill.strokeRgba
|
|
1429
|
+
previewCtx.lineWidth = fill.strokeWidth
|
|
1430
|
+
previewCtx.lineJoin = 'round'
|
|
1431
|
+
previewCtx.lineCap = 'round'
|
|
1432
|
+
previewCtx.stroke()
|
|
1433
|
+
const previewBlob = typeof previewCanvas.convertToBlob === 'function'
|
|
1434
|
+
? await previewCanvas.convertToBlob({ type: 'image/png' })
|
|
1435
|
+
: await new Promise((resolve, reject) => {
|
|
1436
|
+
previewCanvas.toBlob((b) => (b === null
|
|
1437
|
+
? reject(new Error('preview-toBlob-null')) : resolve(b)), 'image/png')
|
|
1438
|
+
})
|
|
1439
|
+
const previewUrl = await toDataUrl(previewBlob)
|
|
1440
|
+
overlayData = previewUrl.slice(previewUrl.indexOf(',') + 1)
|
|
1441
|
+
}
|
|
1442
|
+
return {
|
|
1443
|
+
data: url.slice(url.indexOf(',') + 1),
|
|
1444
|
+
overlay: overlayData,
|
|
1445
|
+
fillColor: fill.key,
|
|
1446
|
+
fillLabel: fill.label,
|
|
1447
|
+
rect, width: rect.width, height: rect.height, polygonPx,
|
|
1448
|
+
}
|
|
1449
|
+
} finally {
|
|
1450
|
+
if (typeof bitmap.close === 'function') bitmap.close()
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
950
1454
|
/**
|
|
951
1455
|
* 读图片真实像素尺寸。优先用 host 已解析好的 item.width/height(零成本);
|
|
952
1456
|
* 缺失时才解码一次图像测 naturalWidth/Height(大图解码有开销,能免则免)。
|
|
@@ -1049,7 +1553,11 @@ function normalizeAnnotation(a) {
|
|
|
1049
1553
|
background: color-mix(in srgb, var(--dsw-alias-brand-primary) 24%, transparent);
|
|
1050
1554
|
}
|
|
1051
1555
|
.dg-scopeBtn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
|
|
1052
|
-
.dg-title { font-weight: 600; white-space: nowrap; overflow:
|
|
1556
|
+
.dg-title { font-weight: 600; white-space: nowrap; overflow: visible; text-overflow: clip; flex: 0 0 auto; }
|
|
1557
|
+
/* tab 标题:包成单个 inline-flex 容器,宿主 chip 的 gap 插不进图标与文字之间;名称不再被裁切。 */
|
|
1558
|
+
.dg-titleWrap { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; white-space: nowrap; }
|
|
1559
|
+
/* tab 标题图标:与宿主内置 tab 的 titleIcon 同规格(16px / currentColor);间距统一由容器 gap 控制 */
|
|
1560
|
+
.dg-tabTitleIcon { width: 16px; height: 16px; flex: 0 0 auto; margin-right: 0; color: var(--dsw-alias-brand-primary); }
|
|
1053
1561
|
.dg-sub { color: var(--dsw-alias-label-secondary); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
1054
1562
|
/* ⚠️ 硬编码:宿主 --dsw-alias-* 变量为空字符串时不会启用 var() 的 fallback */
|
|
1055
1563
|
.dg-btn {
|
|
@@ -2100,7 +2608,13 @@ function normalizeAnnotation(a) {
|
|
|
2100
2608
|
.dg-mediaNoticeFail { color: #ff8a8a; background: rgba(220, 60, 60, 0.12); }
|
|
2101
2609
|
|
|
2102
2610
|
.dg-open { white-space: nowrap; }
|
|
2103
|
-
|
|
2611
|
+
/* 侧栏脚部入口:展开态「图标 + 名称」并排,收窄态仅图标;图标跟随 currentColor */
|
|
2612
|
+
.dg-openWide, .dg-openNarrow { display: inline-flex; align-items: center; gap: 7px; }
|
|
2613
|
+
.dg-openNarrow { justify-content: center; padding: 5px 8px; }
|
|
2614
|
+
.dg-openLabel { line-height: 18px; }
|
|
2615
|
+
.dg-sideIcon { width: 16px; height: 16px; flex: 0 0 auto; color: currentColor; }
|
|
2616
|
+
.dg-openCompact { padding: 2px 6px; line-height: 16px; font-size: 12px; display: inline-flex; align-items: center; }
|
|
2617
|
+
.dg-openCompact .dg-sideIcon { width: 15px; height: 15px; }
|
|
2104
2618
|
|
|
2105
2619
|
/* ---------- 反馈篮(S3-a)---------- */
|
|
2106
2620
|
/* ⚠️ 配色全部硬编码:宿主 --dsw-alias-* 变量「已定义但值为空」,
|
|
@@ -2348,6 +2862,8 @@ function normalizeAnnotation(a) {
|
|
|
2348
2862
|
|
|
2349
2863
|
/* ---------- v0.14.0:框选批注层 ---------- */
|
|
2350
2864
|
|
|
2865
|
+
/* annotWrap 故意不带 transform —— 批注列表/编辑弹窗挂在这一层,不能被图片缩放拖走。
|
|
2866
|
+
变换只作用在里面的 svg 上,且必须与 img 的 translate/scale 取值完全一致(v0.14.4)。 */
|
|
2351
2867
|
.dg-annotWrap { position: absolute; inset: 0; }
|
|
2352
2868
|
.dg-annotSvg { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
2353
2869
|
.dg-annotSvg.dg-annotActive { background: rgba(74, 124, 255, 0.04); }
|
|
@@ -2364,6 +2880,17 @@ function normalizeAnnotation(a) {
|
|
|
2364
2880
|
.dg-annotItem { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #e8eaed; }
|
|
2365
2881
|
.dg-annotIndex { color: #8fb6ff; font-weight: 600; }
|
|
2366
2882
|
.dg-annotText { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2883
|
+
.dg-annotItem .dg-btn { flex: 0 0 auto; }
|
|
2884
|
+
/* 遮罩导出结果提示:避开左上批注列表与底部批注输入框,不受 svg 缩放平移影响 */
|
|
2885
|
+
.dg-maskNotice {
|
|
2886
|
+
position: absolute; right: 8px; top: 8px; z-index: 7;
|
|
2887
|
+
max-width: min(360px, 70%); padding: 6px 10px; border-radius: 6px;
|
|
2888
|
+
font-size: 11px; line-height: 1.5; color: #e8eaed;
|
|
2889
|
+
background: rgba(27, 30, 36, 0.96); border: 1px solid rgba(255, 255, 255, 0.18);
|
|
2890
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
|
|
2891
|
+
}
|
|
2892
|
+
.dg-maskNotice-ok { border-color: rgba(94, 214, 150, 0.65); }
|
|
2893
|
+
.dg-maskNotice-failed { border-color: rgba(255, 107, 107, 0.85); color: #ffd7d7; }
|
|
2367
2894
|
|
|
2368
2895
|
/* 批注输入框:贴底居中,别挡住刚圈出来的框 */
|
|
2369
2896
|
.dg-annotEditor {
|
|
@@ -2400,6 +2927,28 @@ function normalizeAnnotation(a) {
|
|
|
2400
2927
|
}
|
|
2401
2928
|
.dg-annotEditorOps .dg-annotSave:hover:not(:disabled) { background: #6a92ff !important; }
|
|
2402
2929
|
.dg-annotPendingHint { font-size: 11px; color: #ffd166; margin: -2px 0 8px; }
|
|
2930
|
+
|
|
2931
|
+
/* v0.14.6 右键多边形选区操作条:贴右下,避开左上批注列表与底部矩形输入框 */
|
|
2932
|
+
.dg-polyPanel {
|
|
2933
|
+
position: absolute; right: 8px; bottom: 14px; z-index: 6;
|
|
2934
|
+
width: min(320px, 76%); box-sizing: border-box;
|
|
2935
|
+
background: #1b1e24; color: #e8eaed;
|
|
2936
|
+
border: 1px solid rgba(94, 214, 150, 0.55); border-radius: 8px; padding: 10px;
|
|
2937
|
+
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
|
|
2938
|
+
}
|
|
2939
|
+
.dg-polyPanelHead { font-size: 12px; font-weight: 600; color: #9fe1cb; margin-bottom: 6px; }
|
|
2940
|
+
.dg-polyPanelInfo { font-size: 11px; line-height: 1.5; word-break: break-all; }
|
|
2941
|
+
.dg-polyPanelHint { font-size: 11px; color: #b9c2cf; line-height: 1.5; margin-top: 6px; }
|
|
2942
|
+
.dg-polyColors { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; }
|
|
2943
|
+
.dg-polyColorsLabel { font-size: 11px; color: #b9c2cf; margin-right: 2px; }
|
|
2944
|
+
.dg-polyColorBtn { min-width: 26px; height: 20px; padding: 0 5px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.22); color: #10161f; font-size: 11px; font-weight: 600; cursor: pointer; line-height: 18px; }
|
|
2945
|
+
.dg-polyColorBtn.is-active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.28); }
|
|
2946
|
+
.dg-polyPanelOps { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
|
|
2947
|
+
.dg-polyPanelOps .dg-polyClose {
|
|
2948
|
+
background: #0f6e56 !important; color: #fff !important;
|
|
2949
|
+
border-color: #1d9e75 !important; font-weight: 600;
|
|
2950
|
+
}
|
|
2951
|
+
.dg-polyPanelOps .dg-polyClose:disabled { opacity: 0.45; }
|
|
2403
2952
|
`
|
|
2404
2953
|
|
|
2405
2954
|
|
|
@@ -2576,6 +3125,24 @@ function makeItem(item) {
|
|
|
2576
3125
|
frameMs: Number(item.frameOf.frameMs) || 0,
|
|
2577
3126
|
}
|
|
2578
3127
|
}
|
|
3128
|
+
// v0.14.5 遮罩来源:由本条框选区域生成的 RGBA 遮罩资产,路径只随草稿带出
|
|
3129
|
+
// v0.14.6 右键多边形:把外接框 / 顶点像素坐标 / 面积一并带出,供 Agent 精确回填。
|
|
3130
|
+
if (item?.maskOf !== undefined && item?.maskOf !== null && typeof item.maskOf === 'object') {
|
|
3131
|
+
out.maskOf = {
|
|
3132
|
+
relPath: String(item.maskOf.relPath ?? ''),
|
|
3133
|
+
sourceName: String(item.maskOf.sourceName ?? ''),
|
|
3134
|
+
region: item.maskOf.region ?? null,
|
|
3135
|
+
polygon: Array.isArray(item.maskOf.polygon) ? item.maskOf.polygon : null,
|
|
3136
|
+
polygonPx: Array.isArray(item.maskOf.polygonPx) ? item.maskOf.polygonPx : null,
|
|
3137
|
+
bboxPx: Array.isArray(item.maskOf.bboxPx) ? item.maskOf.bboxPx : null,
|
|
3138
|
+
areaPx: Number(item.maskOf.areaPx) || 0,
|
|
3139
|
+
imageWidth: Number(item.maskOf.imageWidth) || 0,
|
|
3140
|
+
imageHeight: Number(item.maskOf.imageHeight) || 0,
|
|
3141
|
+
// v0.14.7 彩色填充预览图:只用于目视核对,工作流仍用主 alpha 遮罩
|
|
3142
|
+
overlayRelPath: String(item.maskOf.overlayRelPath ?? ''),
|
|
3143
|
+
fillColor: String(item.maskOf.fillColor ?? ''),
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
2579
3146
|
return out
|
|
2580
3147
|
}
|
|
2581
3148
|
|
|
@@ -2601,6 +3168,86 @@ function baseName(relPath) {
|
|
|
2601
3168
|
return i >= 0 ? s.slice(i + 1) : s
|
|
2602
3169
|
}
|
|
2603
3170
|
|
|
3171
|
+
/* ------------------------------------------------------------------ *
|
|
3172
|
+
* 拖图带位置信息(2026-11-12 实证后落地)
|
|
3173
|
+
*
|
|
3174
|
+
* DSH 宿主源码实证(`dsh-client-ui-attachment` / `dsh-client-ui-conversation`):
|
|
3175
|
+
* · document 级 drop 只认 `dataTransfer.files`(或内部 application/x-dsh-file
|
|
3176
|
+
* 令牌),**完全不读 text/plain / text/uri-list** —— 所以塞文本无效;
|
|
3177
|
+
* · `browserDraftAttachment(file)` 保留原 File,
|
|
3178
|
+
* `encodeImage(file)` 返回 `{ mediaType, data, name: file.name }`,
|
|
3179
|
+
* 即 **file.name 会原样进发给模型的消息**。
|
|
3180
|
+
* 因此正解是:拖出时把「文件名 + 绝对路径 + 主遮罩」写进 File.name,
|
|
3181
|
+
* DSH 的 Agent 拿到附件就能直接定位,不必整目录扫描比对。
|
|
3182
|
+
*
|
|
3183
|
+
* 红线:只写草稿附件,绝不调用 submit();主 alpha 遮罩契约不动。
|
|
3184
|
+
* ------------------------------------------------------------------ */
|
|
3185
|
+
|
|
3186
|
+
/** relPath → { item, absPath },由 GalleryBody 在列表刷新时填,供 dragstart 同步查。 */
|
|
3187
|
+
const dragAssetIndex = new Map()
|
|
3188
|
+
/**
|
|
3189
|
+
* 彩色填充预览图 / 原图 → 主遮罩元数据。
|
|
3190
|
+
* frames.json 只登记主遮罩帧,预览图靠「同目录素材」规则出现、本身没有 maskOf,
|
|
3191
|
+
* 所以拖预览图时必须按 overlayRelPath(或原图 sourceRelPath)反查主遮罩。
|
|
3192
|
+
*/
|
|
3193
|
+
const dragMaskByOverlay = new Map()
|
|
3194
|
+
const dragMaskBySource = new Map()
|
|
3195
|
+
|
|
3196
|
+
/**
|
|
3197
|
+
* 生成拖出 File 的名字(纯函数,测试跑真身)。
|
|
3198
|
+
* 全角「|」分隔,控制字符清掉,长度夹在 240 以内,避免 DSH 卡片显示被截到看不懂。
|
|
3199
|
+
*/
|
|
3200
|
+
function dragNameOf(item, absPath) {
|
|
3201
|
+
const name = String(item?.name ?? baseName(item?.relPath ?? ''))
|
|
3202
|
+
const parts = [`产出台·${name}`]
|
|
3203
|
+
const path = String(absPath ?? '')
|
|
3204
|
+
if (path !== '') parts.push(`路径=${path}`)
|
|
3205
|
+
const m = item?.maskOf ?? null
|
|
3206
|
+
if (m !== null && typeof m === 'object') {
|
|
3207
|
+
const maskRel = String(m.relPath ?? '')
|
|
3208
|
+
if (maskRel !== '') parts.push(`主遮罩=${baseName(maskRel)}`)
|
|
3209
|
+
const overlayRel = String(m.overlayRelPath ?? '')
|
|
3210
|
+
if (m.linkedMask === true) {
|
|
3211
|
+
// 反查命中的预览图 / 原图本身不是遮罩,必须把用法讲死,
|
|
3212
|
+
// 免得 Agent 把这张 RGB 合成图直接回填 #369.image。
|
|
3213
|
+
parts.push('工作流请用主遮罩,预览仅供目视')
|
|
3214
|
+
} else if (overlayRel !== '') {
|
|
3215
|
+
parts.push(`填充预览=${baseName(overlayRel)}`)
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
const rel = String(item?.relPath ?? '')
|
|
3219
|
+
if (rel !== '' && path === '') parts.push(`相对路径=${rel}`)
|
|
3220
|
+
return parts.join(' | ').replace(/[\u0000-\u001f]/g, ' ').slice(0, 240)
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
/**
|
|
3224
|
+
* dragstart 是同步事件,不能 await 取原图字节;这里从已渲染的 <img> 同步重编码 PNG。
|
|
3225
|
+
* 卡片缩略图是 data/blob URL,同源不污染 canvas;失败返回 null 走剪贴板兜底。
|
|
3226
|
+
*/
|
|
3227
|
+
function syncImagePngBytes(img) {
|
|
3228
|
+
if (img === null || img === undefined || String(img.tagName ?? '').toLowerCase() !== 'img') return null
|
|
3229
|
+
const w = Number(img.naturalWidth || img.width || 0)
|
|
3230
|
+
const h = Number(img.naturalHeight || img.height || 0)
|
|
3231
|
+
if (w < 1 || h < 1) return null
|
|
3232
|
+
try {
|
|
3233
|
+
const canvas = document.createElement('canvas')
|
|
3234
|
+
canvas.width = w
|
|
3235
|
+
canvas.height = h
|
|
3236
|
+
const cx = canvas.getContext('2d')
|
|
3237
|
+
if (cx === null) return null
|
|
3238
|
+
cx.drawImage(img, 0, 0, w, h)
|
|
3239
|
+
const url = canvas.toDataURL('image/png')
|
|
3240
|
+
const comma = url.indexOf(',')
|
|
3241
|
+
if (comma < 0) return null
|
|
3242
|
+
const bin = atob(url.slice(comma + 1))
|
|
3243
|
+
const bytes = new Uint8Array(bin.length)
|
|
3244
|
+
for (let i = 0; i < bin.length; i += 1) bytes[i] = bin.charCodeAt(i)
|
|
3245
|
+
return bytes
|
|
3246
|
+
} catch {
|
|
3247
|
+
return null
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
|
|
2604
3251
|
/**
|
|
2605
3252
|
* 把契约渲染成**人类与模型都能读的草稿正文**。
|
|
2606
3253
|
*
|
|
@@ -2629,7 +3276,7 @@ function renderFeedbackText(feedback, options) {
|
|
|
2629
3276
|
lines.push('Reply item by item using the `Annotation N:` prefix, so each decision maps to one annotation.')
|
|
2630
3277
|
lines.push('')
|
|
2631
3278
|
} else {
|
|
2632
|
-
lines.push(
|
|
3279
|
+
lines.push(`【产出台反馈 · 共 ${items.length} 条】`)
|
|
2633
3280
|
lines.push('')
|
|
2634
3281
|
lines.push('请按 `Annotation 1:`、`Annotation 2:` … 逐条回应,让每条决定都对应到一个批注。')
|
|
2635
3282
|
lines.push('')
|
|
@@ -2652,6 +3299,31 @@ function renderFeedbackText(feedback, options) {
|
|
|
2652
3299
|
? `Frame source: taken from "${f.videoName}" at ${f.timecode} (${f.frameMs} ms)`
|
|
2653
3300
|
: `帧来源:取自视频《${f.videoName}》${f.timecode}(第 ${f.frameMs} 毫秒)`)
|
|
2654
3301
|
}
|
|
3302
|
+
// 遮罩来源是「资产路径 + 编码说明」,不是自动指令:模型拿到后自行上传 / 回填 image 输入
|
|
3303
|
+
if (item.maskOf !== undefined && item.maskOf !== null && String(item.maskOf.relPath ?? '') !== '') {
|
|
3304
|
+
lines.push(locale === 'en'
|
|
3305
|
+
? `Mask source: ${item.maskOf.relPath} — RGBA mask from this box; alpha=0 inside the box, so ComfyUI LoadImage MASK (1 - alpha/255) marks only the area to inpaint`
|
|
3306
|
+
: `遮罩来源:${item.maskOf.relPath} —— 由本条框选区域生成的 RGBA 遮罩,框内 alpha=0,ComfyUI LoadImage 的 MASK 输出(1 - alpha/255)即待重绘区域;可用于局部重绘 / 移除流回填 image 输入`)
|
|
3307
|
+
const mp = item.maskOf
|
|
3308
|
+
// v0.14.7 彩色填充预览图:只供人核对选区位置,别拿去回填工作流
|
|
3309
|
+
if (String(mp.overlayRelPath ?? '') !== '') {
|
|
3310
|
+
const fillName = { green: '绿', red: '红', blue: '蓝' }[String(mp.fillColor ?? '')] ?? '绿'
|
|
3311
|
+
lines.push(locale === 'en'
|
|
3312
|
+
? `Mask preview: ${mp.overlayRelPath} — original image with a solid semi-transparent fill over the selection; visual check only, hand the RGBA mask above to the workflow`
|
|
3313
|
+
: `遮罩预览:${mp.overlayRelPath} —— 原图上叠加${fillName}色半透明填充,仅用于目视核对选区位置;工作流请用上面的 RGBA 遮罩`)
|
|
3314
|
+
}
|
|
3315
|
+
if (Array.isArray(mp.polygonPx) && mp.polygonPx.length > 0) {
|
|
3316
|
+
const b = Array.isArray(mp.bboxPx) ? mp.bboxPx : [0, 0, 0, 0]
|
|
3317
|
+
const size = `${Number(mp.imageWidth) || 0}×${Number(mp.imageHeight) || 0}`
|
|
3318
|
+
const verts = JSON.stringify(mp.polygonPx)
|
|
3319
|
+
lines.push(locale === 'en'
|
|
3320
|
+
? `Mask region: ${size}px source · ${mp.polygonPx.length} vertices · bbox (${b[0]},${b[1]})-(${b[2]},${b[3]}) · ~${Number(mp.areaPx) || 0}px · vertex pixels ${verts}`
|
|
3321
|
+
: `遮罩区域:原图 ${size}px · ${mp.polygonPx.length} 个顶点 · 外接框 (${b[0]},${b[1]})-(${b[2]},${b[3]}) · 面积约 ${Number(mp.areaPx) || 0}px · 顶点像素坐标 ${verts}`)
|
|
3322
|
+
lines.push(locale === 'en'
|
|
3323
|
+
? 'Mask handoff: upload it, then replace the target workflow image input; use ONE short target phrase (e.g. change "X" to "Y", keep the original lettering), do not expand into a whole-word rewrite with extra constraints'
|
|
3324
|
+
: '遮罩回填:上传后替换目标工作流的 image 入参;提示词用单目标短句(例如:将图中的「X」,改为「Y」,保持原有字体色调),不要扩写成整词替换加约束')
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
2655
3327
|
if (item.reason !== undefined) {
|
|
2656
3328
|
lines.push(`${locale === 'en' ? 'Reason' : '理由'}:${item.reason}`)
|
|
2657
3329
|
}
|
|
@@ -2988,6 +3660,8 @@ function serializeFeedback(feedback) {
|
|
|
2988
3660
|
preserve: mark.preserve,
|
|
2989
3661
|
// 截帧来源随草稿带出(v0.14.3)
|
|
2990
3662
|
frameOf: it.frameOf,
|
|
3663
|
+
// 遮罩来源随草稿带出(v0.14.5):由本图框选区域生成的 RGBA 遮罩资产
|
|
3664
|
+
maskOf: it.maskOf,
|
|
2991
3665
|
})
|
|
2992
3666
|
}
|
|
2993
3667
|
const annots = Array.isArray(it.annotations) ? it.annotations : []
|
|
@@ -3001,6 +3675,8 @@ function serializeFeedback(feedback) {
|
|
|
3001
3675
|
reason: note === '' ? undefined : note,
|
|
3002
3676
|
region: { x: a.x, y: a.y, w: a.w, h: a.h },
|
|
3003
3677
|
frameOf: it.frameOf,
|
|
3678
|
+
// 遮罩来源随草稿带出(v0.14.5):由本图框选区域生成的 RGBA 遮罩资产
|
|
3679
|
+
maskOf: it.maskOf,
|
|
3004
3680
|
})
|
|
3005
3681
|
}
|
|
3006
3682
|
}
|
|
@@ -3183,6 +3859,11 @@ function serializeFeedback(feedback) {
|
|
|
3183
3859
|
timecode: it.frameOf.timecode ?? '',
|
|
3184
3860
|
}))
|
|
3185
3861
|
: null,
|
|
3862
|
+
// 遮罩资产已生成:在篮子里就能看到路径,不必等草稿
|
|
3863
|
+
it.maskOf !== undefined && it.maskOf !== null && String(it.maskOf.relPath ?? '') !== ''
|
|
3864
|
+
? h('span', { className: 'dg-feedbackDim', key: 'mask', 'data-gallery-feedback-mask': it.maskOf.relPath },
|
|
3865
|
+
format(t('feedbackMaskFrom'), { name: baseName(it.maskOf.relPath) }))
|
|
3866
|
+
: null,
|
|
3186
3867
|
h('span', { className: 'dg-feedbackDim dg-feedbackRegion', key: 'r' },
|
|
3187
3868
|
format(t('feedbackAnnotRegion'), { x: pct(a.x), y: pct(a.y), w: pct(a.w), h: pct(a.h) })),
|
|
3188
3869
|
h('span', { className: 'dg-feedbackNote', key: 'note' },
|
|
@@ -3221,6 +3902,11 @@ function serializeFeedback(feedback) {
|
|
|
3221
3902
|
timecode: it.frameOf.timecode ?? '',
|
|
3222
3903
|
}))
|
|
3223
3904
|
: null,
|
|
3905
|
+
// 遮罩资产已生成:在篮子里就能看到路径,不必等草稿
|
|
3906
|
+
it.maskOf !== undefined && it.maskOf !== null && String(it.maskOf.relPath ?? '') !== ''
|
|
3907
|
+
? h('span', { className: 'dg-feedbackDim', key: 'mask', 'data-gallery-feedback-mask': it.maskOf.relPath },
|
|
3908
|
+
format(t('feedbackMaskFrom'), { name: baseName(it.maskOf.relPath) }))
|
|
3909
|
+
: null,
|
|
3224
3910
|
(it.mark?.changeOnly !== undefined && it.mark.changeOnly.length > 0)
|
|
3225
3911
|
? h('span', { className: 'dg-feedbackDim', key: 'co' },
|
|
3226
3912
|
`${t('feedbackChangeOnly')}:${it.mark.changeOnly.join('/')}`)
|
|
@@ -4252,7 +4938,7 @@ ${absPath}
|
|
|
4252
4938
|
* - 右键预览区、按 O、点底部按钮 三种方式切换
|
|
4253
4939
|
* - 切换时**保留当前缩放与位置**,否则切过去跳回 1x 就没法对比
|
|
4254
4940
|
*/
|
|
4255
|
-
function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation }) {
|
|
4941
|
+
function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask }) {
|
|
4256
4942
|
const item = items[index]
|
|
4257
4943
|
// 文件预览已改走 DSH 原生侧栏(session 地址);此处 Viewer 仅处理图片,isText 恒 false,
|
|
4258
4944
|
// 下面的文本分支保留为死代码,供 v0.2 若需插件内预览时复用
|
|
@@ -4262,6 +4948,9 @@ ${absPath}
|
|
|
4262
4948
|
const [pan, setPan] = React.useState({ x: 0, y: 0 })
|
|
4263
4949
|
const [dragging, setDragging] = React.useState(false)
|
|
4264
4950
|
const bodyRef = React.useRef(null)
|
|
4951
|
+
const imgRef = React.useRef(null)
|
|
4952
|
+
/** 图片在预览容器里的真实布局盒(不含 transform);批注层据此对齐,1:1 也不跑偏。 */
|
|
4953
|
+
const [imgBox, setImgBox] = React.useState(null)
|
|
4265
4954
|
const dragRef = React.useRef(null)
|
|
4266
4955
|
// 上一次拖动是否真的产生了位移(用于区分「拖图」和「单击关闭」)
|
|
4267
4956
|
const lastDragMoved = React.useRef(false)
|
|
@@ -4406,8 +5095,34 @@ ${absPath}
|
|
|
4406
5095
|
setPan({ x: 0, y: 0 })
|
|
4407
5096
|
setDragging(false)
|
|
4408
5097
|
dragRef.current = null
|
|
5098
|
+
setImgBox(null)
|
|
4409
5099
|
}, [item.relPath])
|
|
4410
5100
|
|
|
5101
|
+
/**
|
|
5102
|
+
* 量出图片在容器里的真实布局盒。offsetWidth/Height 不含 transform,
|
|
5103
|
+
* 正是批注 SVG 该贴的基准 —— 图片按 object-fit:contain 居中后往往小于容器,
|
|
5104
|
+
* 拿容器当基准,1:1 圈的位置就会和画面错开。
|
|
5105
|
+
* 窗口缩放、原图/预览切换、换图都会改变盒子,监听容器尺寸并重新量。
|
|
5106
|
+
*/
|
|
5107
|
+
const measureImgBox = React.useCallback(() => {
|
|
5108
|
+
const img = imgRef.current
|
|
5109
|
+
if (img === null || state.status !== 'ready' || isText) { setImgBox(null); return }
|
|
5110
|
+
const width = img.offsetWidth
|
|
5111
|
+
const height = img.offsetHeight
|
|
5112
|
+
if (width <= 0 || height <= 0) return
|
|
5113
|
+
// offsetLeft/Top 相对 offsetParent;img 直接挂在 position:relative 的 dg-viewerBody 下
|
|
5114
|
+
setImgBox({ left: img.offsetLeft, top: img.offsetTop, width, height })
|
|
5115
|
+
}, [state.status, isText])
|
|
5116
|
+
|
|
5117
|
+
React.useLayoutEffect(() => {
|
|
5118
|
+
measureImgBox()
|
|
5119
|
+
const body = bodyRef.current
|
|
5120
|
+
if (body === null || typeof ResizeObserver === 'undefined') return undefined
|
|
5121
|
+
const ro = new ResizeObserver(() => measureImgBox())
|
|
5122
|
+
ro.observe(body)
|
|
5123
|
+
return () => ro.disconnect()
|
|
5124
|
+
}, [measureImgBox, item.relPath, originalMode, original.status])
|
|
5125
|
+
|
|
4411
5126
|
// 滚轮缩放:以鼠标位置为中心,避免放大后目标跑出视野(仅图片模式)。
|
|
4412
5127
|
// 文本预览用原生滚动,不拦截滚轮。
|
|
4413
5128
|
React.useEffect(() => {
|
|
@@ -4761,12 +5476,26 @@ ${absPath}
|
|
|
4761
5476
|
key: 'annot',
|
|
4762
5477
|
'data-gallery-annot-toggle': true,
|
|
4763
5478
|
'aria-pressed': annotActive,
|
|
4764
|
-
title: annotActive ? t('annotExit') : t('annotEnter'),
|
|
5479
|
+
title: annotActive ? `${t('annotExit')} · ${t('annotPanHint')}` : t('annotEnter'),
|
|
4765
5480
|
onClick: (event) => {
|
|
4766
5481
|
event.stopPropagation()
|
|
4767
5482
|
setAnnotActive((v) => !v)
|
|
4768
5483
|
},
|
|
4769
5484
|
}, annotActive ? `✎ ${t('annotExit')}` : `✎ ${t('annotEnter')}`),
|
|
5485
|
+
// 「拖到对话」确定性入口:Viewer 大图本身 draggable:false + pointerEvents:none
|
|
5486
|
+
// (标注态的中键平移 / 右键多边形都依赖它),所以不改大图,另给一个可拖按钮。
|
|
5487
|
+
// 这个按钮同时是「新 client.js 已加载」的可见标记 —— 看到它就说明面板不是旧模块。
|
|
5488
|
+
h('button', {
|
|
5489
|
+
type: 'button',
|
|
5490
|
+
className: 'dg-btn',
|
|
5491
|
+
key: 'dragAsset',
|
|
5492
|
+
draggable: true,
|
|
5493
|
+
'data-gallery-relpath': item.relPath,
|
|
5494
|
+
'data-gallery-dragviewer': true,
|
|
5495
|
+
title: '拖到对话:附带绝对路径 / 主遮罩 / 填充预览文件名',
|
|
5496
|
+
'aria-label': '拖到对话',
|
|
5497
|
+
onClick: (event) => event.stopPropagation(),
|
|
5498
|
+
}, '⇥ 拖到对话'),
|
|
4770
5499
|
h('button', { type: 'button', className: 'dg-btn', key: 'prev', onClick: () => onStep(-1), 'aria-label': t('prev') }, '‹'),
|
|
4771
5500
|
h('button', { type: 'button', className: 'dg-btn', key: 'next', onClick: () => onStep(1), 'aria-label': t('next') }, '›'),
|
|
4772
5501
|
h('button', { type: 'button', className: 'dg-btn', key: 'close', onClick: onClose, 'aria-label': t('close') }, '✕'),
|
|
@@ -4812,6 +5541,8 @@ ${absPath}
|
|
|
4812
5541
|
alt: item.name,
|
|
4813
5542
|
decoding: 'async',
|
|
4814
5543
|
draggable: false,
|
|
5544
|
+
ref: imgRef,
|
|
5545
|
+
onLoad: measureImgBox,
|
|
4815
5546
|
style: {
|
|
4816
5547
|
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
4817
5548
|
transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
|
|
@@ -4819,16 +5550,25 @@ ${absPath}
|
|
|
4819
5550
|
pointerEvents: 'none',
|
|
4820
5551
|
},
|
|
4821
5552
|
}),
|
|
4822
|
-
//
|
|
4823
|
-
|
|
5553
|
+
// 批注层贴着图片真实布局盒,与图片共用同一组 zoom/pan。
|
|
5554
|
+
// imgBox 还没量出来(图片未布局)时不画框,免得拿容器当基准错位。
|
|
5555
|
+
imgBox === null ? null : h(AnnotationLayer, {
|
|
4824
5556
|
key: 'annot',
|
|
4825
5557
|
t,
|
|
4826
5558
|
annotations: annotsOfCurrent,
|
|
4827
5559
|
active: annotActive,
|
|
5560
|
+
dragging,
|
|
4828
5561
|
frameMs: null,
|
|
4829
|
-
|
|
5562
|
+
zoom,
|
|
5563
|
+
pan,
|
|
5564
|
+
imgBox,
|
|
5565
|
+
transformTransition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
|
|
4830
5566
|
onAdd: (a) => { onAddAnnotation?.(item, a) },
|
|
4831
5567
|
onRemove: (id) => { onRemoveAnnotation?.(item, id) },
|
|
5568
|
+
// 遮罩导出:把「当前这张图 + 这条矩形批注」一起交给上层执行
|
|
5569
|
+
onExportMask: typeof onExportMask === 'function'
|
|
5570
|
+
? (a) => onExportMask(item, a)
|
|
5571
|
+
: undefined,
|
|
4832
5572
|
}),
|
|
4833
5573
|
]))
|
|
4834
5574
|
: state.status === 'binary'
|
|
@@ -4881,21 +5621,115 @@ ${absPath}
|
|
|
4881
5621
|
* v0.14.2 修:
|
|
4882
5622
|
* ⑤ 弹窗开着时第二处按不下:改为一按下就先把当前草稿存档,可连续圈多处
|
|
4883
5623
|
* ⑥ 只认「按住拖拽」:补「点两下」定义矩形(点起点 → 点终点),两种习惯都能用
|
|
5624
|
+
*
|
|
5625
|
+
* v0.14.4 本地热修:
|
|
5626
|
+
* ⑦ SVG 原先覆盖整个预览容器且不带 transform,图片却是 contain 居中后单独
|
|
5627
|
+
* translate/scale —— 两套坐标系,1:1 就可能错位、放大后彻底不跟随。
|
|
5628
|
+
* 现在 SVG 的布局盒对齐图片真实显示盒(imgBox),并复用同一组 zoom/pan;
|
|
5629
|
+
* 批注列表与编辑弹窗仍留在外层 dg-annotWrap(无 transform),
|
|
5630
|
+
* 不会被放大、也不会被平移拖出视野。
|
|
4884
5631
|
*/
|
|
4885
5632
|
|
|
4886
|
-
function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs,
|
|
5633
|
+
function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, frameMs, zoom, pan, imgBox, transformTransition, onExportMask }) {
|
|
4887
5634
|
const [draft, setDraft] = React.useState(null)
|
|
4888
5635
|
const [editing, setEditing] = React.useState(null)
|
|
4889
5636
|
/** 已点下第一下、等第二下定终点时的起点(归一化坐标)。 */
|
|
4890
5637
|
const [pendingStart, setPendingStart] = React.useState(null)
|
|
4891
5638
|
const svgRef = React.useRef(null)
|
|
5639
|
+
/** 遮罩导出提示(成功/失败),2.5 秒自动消失。 */
|
|
5640
|
+
const [maskNotice, setMaskNotice] = React.useState(null)
|
|
5641
|
+
const [maskBusy, setMaskBusy] = React.useState(false)
|
|
5642
|
+
/** 右键多边形选区:归一化顶点 / 橡皮筋终点 / 正在拖动的顶点下标。 */
|
|
5643
|
+
const [poly, setPoly] = React.useState([])
|
|
5644
|
+
const [polyHover, setPolyHover] = React.useState(null)
|
|
5645
|
+
const [polyDrag, setPolyDrag] = React.useState(null)
|
|
5646
|
+
/** v0.14.7 选区填充色(红 / 绿 / 蓝),同时决定导出的彩色预览图颜色。 */
|
|
5647
|
+
const [fillColor, setFillColor] = React.useState('green')
|
|
5648
|
+
/** SVG 无 viewBox,polygon 的 points 只认用户单位 px,不能用百分比。 */
|
|
5649
|
+
const boxW = Math.max(1, Number(imgBox?.width) || 1)
|
|
5650
|
+
const boxH = Math.max(1, Number(imgBox?.height) || 1)
|
|
5651
|
+
|
|
5652
|
+
React.useEffect(() => {
|
|
5653
|
+
if (maskNotice === null) return undefined
|
|
5654
|
+
const timer = setTimeout(() => setMaskNotice(null), 2500)
|
|
5655
|
+
return () => clearTimeout(timer)
|
|
5656
|
+
}, [maskNotice])
|
|
5657
|
+
|
|
5658
|
+
/** 只把「导出」交给上层;提示与防连点留在本层,查看器其余交互一概不动。 */
|
|
5659
|
+
const runExportMask = (a) => {
|
|
5660
|
+
if (typeof onExportMask !== 'function' || maskBusy) return
|
|
5661
|
+
setMaskBusy(true)
|
|
5662
|
+
setMaskNotice({ kind: 'ok', text: t('maskExporting') })
|
|
5663
|
+
Promise.resolve()
|
|
5664
|
+
.then(() => onExportMask(a))
|
|
5665
|
+
.then((r) => setMaskNotice({ kind: 'ok', text: format(t('maskSaved'), { name: r?.name ?? '' }) }))
|
|
5666
|
+
.catch((error) => setMaskNotice({
|
|
5667
|
+
kind: 'failed',
|
|
5668
|
+
text: format(t('maskFailed'), { message: String(error?.message ?? error) }),
|
|
5669
|
+
}))
|
|
5670
|
+
.finally(() => setMaskBusy(false))
|
|
5671
|
+
}
|
|
5672
|
+
|
|
5673
|
+
/**
|
|
5674
|
+
* 闭合多边形 → 立刻生成遮罩资产。老板要的是「右键点完就形成区域遮罩」,
|
|
5675
|
+
* 所以闭合即导出,不再多一层确认;顶点/面积在闭合前一直可见可撤销。
|
|
5676
|
+
* 零自动发送红线不变:这里只落盘遮罩资产,草稿仍要人工发送。
|
|
5677
|
+
*/
|
|
5678
|
+
const commitPolygon = (points) => {
|
|
5679
|
+
if (points.length < POLYGON_LIMITS.min) {
|
|
5680
|
+
setMaskNotice({ kind: 'failed', text: t('polyTooFew') })
|
|
5681
|
+
return
|
|
5682
|
+
}
|
|
5683
|
+
if (polygonArea(points) < POLYGON_LIMITS.minArea) {
|
|
5684
|
+
setMaskNotice({ kind: 'failed', text: t('polyDegenerate') })
|
|
5685
|
+
return
|
|
5686
|
+
}
|
|
5687
|
+
const box = polygonBBox(points)
|
|
5688
|
+
setPoly([])
|
|
5689
|
+
setPolyHover(null)
|
|
5690
|
+
setPolyDrag(null)
|
|
5691
|
+
runExportMask({
|
|
5692
|
+
shape: 'polygon',
|
|
5693
|
+
...box,
|
|
5694
|
+
polygon: points.map((p) => [clamp01(p.x), clamp01(p.y)]),
|
|
5695
|
+
fillColor,
|
|
5696
|
+
note: '',
|
|
5697
|
+
})
|
|
5698
|
+
}
|
|
4892
5699
|
|
|
4893
|
-
/**
|
|
5700
|
+
/** Enter 闭合 / Backspace 撤销一点 / Escape 清空;输入框有焦点时不抢键。 */
|
|
5701
|
+
React.useEffect(() => {
|
|
5702
|
+
if (!active || poly.length === 0 || editing !== null) return undefined
|
|
5703
|
+
const onKey = (e) => {
|
|
5704
|
+
const el = e.target
|
|
5705
|
+
if (el !== null && (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA'
|
|
5706
|
+
|| (typeof el.closest === 'function' && el.closest('[data-gallery-annot-editor]') !== null))) return
|
|
5707
|
+
if (e.key === 'Enter' && poly.length >= POLYGON_LIMITS.min) {
|
|
5708
|
+
e.preventDefault()
|
|
5709
|
+
commitPolygon(poly)
|
|
5710
|
+
} else if (e.key === 'Backspace') {
|
|
5711
|
+
e.preventDefault()
|
|
5712
|
+
setPoly((cur) => cur.slice(0, -1))
|
|
5713
|
+
setPolyHover(null)
|
|
5714
|
+
} else if (e.key === 'Escape') {
|
|
5715
|
+
e.preventDefault()
|
|
5716
|
+
setPoly([])
|
|
5717
|
+
setPolyHover(null)
|
|
5718
|
+
}
|
|
5719
|
+
}
|
|
5720
|
+
window.addEventListener('keydown', onKey)
|
|
5721
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
5722
|
+
}, [active, poly, editing])
|
|
5723
|
+
|
|
5724
|
+
/** 退出标注模式时清掉未保存的草稿,避免输入框/虚线框/顶点残留。 */
|
|
4894
5725
|
React.useEffect(() => {
|
|
4895
5726
|
if (active) return undefined
|
|
4896
5727
|
setDraft(null)
|
|
4897
5728
|
setEditing(null)
|
|
4898
5729
|
setPendingStart(null)
|
|
5730
|
+
setPoly([])
|
|
5731
|
+
setPolyHover(null)
|
|
5732
|
+
setPolyDrag(null)
|
|
4899
5733
|
return undefined
|
|
4900
5734
|
}, [active])
|
|
4901
5735
|
|
|
@@ -4947,14 +5781,41 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
4947
5781
|
}
|
|
4948
5782
|
|
|
4949
5783
|
const onPointerDown = (event) => {
|
|
4950
|
-
|
|
5784
|
+
// 中键(1)放行给查看器的原生拖拽平移;左键留给画框(v0.14.4 标注态中键移动)。
|
|
5785
|
+
// 若继续对所有按键 stopPropagation,中键会被吞、标注时挪不动图。
|
|
5786
|
+
if (annotationPointerRouting(active, event.button) !== 'draw') return
|
|
4951
5787
|
// 放大状态下查看器会在 pointerdown 里 setPointerCapture;这里必须拦住冒泡,
|
|
4952
5788
|
// 否则弹窗内的输入框/按钮会被「拖图」逻辑抢走,表现为点击无反应。
|
|
4953
5789
|
event.stopPropagation()
|
|
5790
|
+
// 右键(2):多边形遮罩选区逐点采集(4–20 点)。点回首点 / 满 20 点 / Enter / 面板按钮都可闭合。
|
|
5791
|
+
// 左键矩形批注与右键多边形互斥,避免两套草稿同时活着互相打架。
|
|
5792
|
+
if (event.button === 2) {
|
|
5793
|
+
event.preventDefault()
|
|
5794
|
+
const p = toNorm(event)
|
|
5795
|
+
if (p === null) return
|
|
5796
|
+
clearPending()
|
|
5797
|
+
const first = poly[0]
|
|
5798
|
+
const nearFirst = poly.length >= POLYGON_LIMITS.min && first !== undefined
|
|
5799
|
+
&& Math.hypot(p.x - first.x, p.y - first.y) <= POLYGON_LIMITS.closeRadius
|
|
5800
|
+
if (nearFirst || poly.length >= POLYGON_LIMITS.max) {
|
|
5801
|
+
commitPolygon(poly)
|
|
5802
|
+
return
|
|
5803
|
+
}
|
|
5804
|
+
const next = [...poly, p]
|
|
5805
|
+
setPoly(next)
|
|
5806
|
+
setPolyHover(null)
|
|
5807
|
+
if (next.length >= POLYGON_LIMITS.max) commitPolygon(next)
|
|
5808
|
+
return
|
|
5809
|
+
}
|
|
4954
5810
|
if (event.button !== 0) return
|
|
4955
5811
|
const p = toNorm(event)
|
|
4956
5812
|
if (p === null) return
|
|
4957
5813
|
event.preventDefault()
|
|
5814
|
+
if (poly.length > 0) {
|
|
5815
|
+
setPoly([])
|
|
5816
|
+
setPolyHover(null)
|
|
5817
|
+
setPolyDrag(null)
|
|
5818
|
+
}
|
|
4958
5819
|
try { event.currentTarget.setPointerCapture(event.pointerId) } catch { /* 忽略 */ }
|
|
4959
5820
|
|
|
4960
5821
|
// 上一处还在输入 → 先存档,第二处才按得下去(v0.14.2 ⑤)
|
|
@@ -4978,6 +5839,15 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
4978
5839
|
}
|
|
4979
5840
|
|
|
4980
5841
|
const onPointerMove = (event) => {
|
|
5842
|
+
// 中键平移进行中:标注层一律不插手,让查看器独占指针(双保险,主保险是中键不再拦冒泡)
|
|
5843
|
+
if (dragging) return
|
|
5844
|
+
// 多边形橡皮筋:只在没有矩形草稿、没有说明弹窗时跟随指针
|
|
5845
|
+
if (active && poly.length > 0 && draft === null && editing === null) {
|
|
5846
|
+
event.stopPropagation()
|
|
5847
|
+
const p = toNorm(event)
|
|
5848
|
+
if (p !== null) setPolyHover(p)
|
|
5849
|
+
return
|
|
5850
|
+
}
|
|
4981
5851
|
if (!active || draft === null || editing !== null) return
|
|
4982
5852
|
event.stopPropagation()
|
|
4983
5853
|
const p = toNorm(event)
|
|
@@ -4987,6 +5857,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
4987
5857
|
}
|
|
4988
5858
|
|
|
4989
5859
|
const finishDraft = (event) => {
|
|
5860
|
+
if (dragging) return
|
|
4990
5861
|
if (draft === null || editing !== null) return
|
|
4991
5862
|
event.preventDefault()
|
|
4992
5863
|
event.stopPropagation()
|
|
@@ -5047,6 +5918,22 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5047
5918
|
}, a.note || ''),
|
|
5048
5919
|
])
|
|
5049
5920
|
}
|
|
5921
|
+
// v0.14.7 已保存的多边形批注:用选区当时的填充色画实心半透明多边形,
|
|
5922
|
+
// 而不是退化成外接矩形(矩形批注仍走下面的老分支)。
|
|
5923
|
+
if (a.shape === 'polygon') {
|
|
5924
|
+
const pts = normalizePolygon(a.polygon, boxW, boxH)
|
|
5925
|
+
if (pts !== null) {
|
|
5926
|
+
return h('g', { key: a.id }, [
|
|
5927
|
+
h('polygon', {
|
|
5928
|
+
key: 'fill',
|
|
5929
|
+
points: pts.map((q) => `${q[0]},${q[1]}`).join(' '),
|
|
5930
|
+
fill: maskFillRgba(a.fillColor, MASK_FILL_ALPHA),
|
|
5931
|
+
stroke: maskFillRgba(a.fillColor, MASK_STROKE_ALPHA), strokeWidth: MASK_STROKE_PX,
|
|
5932
|
+
vectorEffect: 'non-scaling-stroke',
|
|
5933
|
+
}),
|
|
5934
|
+
])
|
|
5935
|
+
}
|
|
5936
|
+
}
|
|
5050
5937
|
// rect / arrow 都先按矩形画(arrow 后续可细化),带编号与说明文字
|
|
5051
5938
|
return h('g', { key: a.id }, [
|
|
5052
5939
|
rectPair('r', a, '#4a7cff', false),
|
|
@@ -5089,6 +5976,62 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5089
5976
|
])
|
|
5090
5977
|
: null)
|
|
5091
5978
|
|
|
5979
|
+
/** 右键多边形预览:实心半透明填充 + 可拖顶点 + 橡皮筋(点回首点即闭合)。 */
|
|
5980
|
+
const polyShape = poly.length === 0 ? null : (() => {
|
|
5981
|
+
const toPx = (p) => [p.x * boxW, p.y * boxH]
|
|
5982
|
+
const pts = poly.map(toPx)
|
|
5983
|
+
const tip = polyHover === null ? null : toPx(polyHover)
|
|
5984
|
+
const ready = poly.length >= POLYGON_LIMITS.min
|
|
5985
|
+
// 纯色半透明填充 0.4 / 轮廓 0.7,颜色跟操作条色板联动;主遮罩 alpha 契约不受影响。
|
|
5986
|
+
const strokeColor = maskFillRgba(fillColor, MASK_STROKE_ALPHA)
|
|
5987
|
+
const fillNode = h('polygon', {
|
|
5988
|
+
key: 'polyFill',
|
|
5989
|
+
points: pts.map((q) => `${q[0]},${q[1]}`).join(' '),
|
|
5990
|
+
fill: maskFillRgba(fillColor, ready ? MASK_FILL_ALPHA : 0.12),
|
|
5991
|
+
stroke: strokeColor, strokeWidth: MASK_STROKE_PX, vectorEffect: 'non-scaling-stroke',
|
|
5992
|
+
strokeDasharray: ready ? undefined : '6 4',
|
|
5993
|
+
'data-gallery-poly': String(poly.length),
|
|
5994
|
+
})
|
|
5995
|
+
const bandNode = tip === null ? null : h('polyline', {
|
|
5996
|
+
key: 'polyBand',
|
|
5997
|
+
points: [pts[pts.length - 1], tip, pts[0]].map((q) => `${q[0]},${q[1]}`).join(' '),
|
|
5998
|
+
fill: 'none', stroke: strokeColor, strokeWidth: 1.5, strokeDasharray: '5 4',
|
|
5999
|
+
vectorEffect: 'non-scaling-stroke', opacity: 0.85,
|
|
6000
|
+
})
|
|
6001
|
+
const dots = pts.map((q, idx) => h('circle', {
|
|
6002
|
+
key: 'v' + idx,
|
|
6003
|
+
cx: q[0], cy: q[1], r: idx === 0 && ready ? 6 : 4,
|
|
6004
|
+
fill: idx === 0 ? '#ffd166' : strokeColor, stroke: '#000', strokeWidth: 1,
|
|
6005
|
+
vectorEffect: 'non-scaling-stroke', style: { cursor: 'move' },
|
|
6006
|
+
'data-gallery-poly-vertex': String(idx),
|
|
6007
|
+
onPointerDown: (e) => {
|
|
6008
|
+
if (e.button !== 0) return
|
|
6009
|
+
e.stopPropagation()
|
|
6010
|
+
e.preventDefault()
|
|
6011
|
+
setPolyDrag(idx)
|
|
6012
|
+
try { e.currentTarget.setPointerCapture(e.pointerId) } catch { /* 忽略 */ }
|
|
6013
|
+
},
|
|
6014
|
+
onPointerMove: (e) => {
|
|
6015
|
+
if (polyDrag !== idx) return
|
|
6016
|
+
e.stopPropagation()
|
|
6017
|
+
e.preventDefault()
|
|
6018
|
+
const p = toNorm(e)
|
|
6019
|
+
if (p !== null) setPoly((cur) => cur.map((q2, i) => (i === idx ? p : q2)))
|
|
6020
|
+
},
|
|
6021
|
+
onPointerUp: (e) => {
|
|
6022
|
+
if (polyDrag !== idx) return
|
|
6023
|
+
e.stopPropagation()
|
|
6024
|
+
setPolyDrag(null)
|
|
6025
|
+
},
|
|
6026
|
+
}))
|
|
6027
|
+
const labels = pts.map((q, idx) => h('text', {
|
|
6028
|
+
key: 'n' + idx, x: q[0] + 7, y: q[1] - 7,
|
|
6029
|
+
fill: '#fff', fontSize: 11, stroke: '#000', strokeWidth: 0.6,
|
|
6030
|
+
style: { paintOrder: 'stroke', pointerEvents: 'none' },
|
|
6031
|
+
}, String(idx + 1)))
|
|
6032
|
+
return h('g', { key: 'poly' }, [fillNode, bandNode, ...dots, ...labels])
|
|
6033
|
+
})()
|
|
6034
|
+
|
|
5092
6035
|
/** 弹窗与批注列表:一律拦住指针/点击冒泡,别让查看器抢事件。 */
|
|
5093
6036
|
const blockViewer = {
|
|
5094
6037
|
onPointerDown: (e) => e.stopPropagation(),
|
|
@@ -5097,6 +6040,58 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5097
6040
|
onContextMenu: (e) => { e.preventDefault(); e.stopPropagation() },
|
|
5098
6041
|
}
|
|
5099
6042
|
|
|
6043
|
+
/** 多边形选区操作条:点数 / 外接框 / 面积实时可见,闭合前可撤销、可清空。 */
|
|
6044
|
+
const polyBox = poly.length > 0 ? polygonBBox(poly) : null
|
|
6045
|
+
const polyPanel = poly.length === 0 ? null : h('div', {
|
|
6046
|
+
className: 'dg-polyPanel', key: 'polyPanel', 'data-gallery-poly-panel': true,
|
|
6047
|
+
...blockViewer,
|
|
6048
|
+
}, [
|
|
6049
|
+
h('div', { className: 'dg-polyPanelHead', key: 'h' }, t('polyTitle')),
|
|
6050
|
+
h('div', { className: 'dg-polyPanelInfo', key: 'i', 'data-gallery-poly-info': true },
|
|
6051
|
+
format(t('polyInfo'), {
|
|
6052
|
+
n: String(poly.length), max: String(POLYGON_LIMITS.max),
|
|
6053
|
+
x: Math.round(polyBox.x * 100), y: Math.round(polyBox.y * 100),
|
|
6054
|
+
w: Math.round(polyBox.w * 100), h: Math.round(polyBox.h * 100),
|
|
6055
|
+
area: (polygonArea(poly) * 100).toFixed(2),
|
|
6056
|
+
})),
|
|
6057
|
+
h('div', { className: 'dg-polyPanelHint', key: 'p' }, t('polyHint')),
|
|
6058
|
+
h('div', { className: 'dg-polyColors', key: 'colors', 'data-gallery-poly-colors': true }, [
|
|
6059
|
+
h('span', { className: 'dg-polyColorsLabel', key: 'l' }, t('polyFillColor')),
|
|
6060
|
+
...MASK_FILL_KEYS.map((k) => h('button', {
|
|
6061
|
+
type: 'button', key: k,
|
|
6062
|
+
className: `dg-polyColorBtn${fillColor === k ? ' is-active' : ''}`,
|
|
6063
|
+
'data-gallery-poly-color': k,
|
|
6064
|
+
style: { background: maskFillRgba(k, 0.9) },
|
|
6065
|
+
title: MASK_FILL_COLORS[k].label,
|
|
6066
|
+
onClick: (e) => { e.stopPropagation(); e.preventDefault(); setFillColor(k) },
|
|
6067
|
+
}, MASK_FILL_COLORS[k].label)),
|
|
6068
|
+
]),
|
|
6069
|
+
h('div', { className: 'dg-polyPanelOps', key: 'o' }, [
|
|
6070
|
+
h('button', {
|
|
6071
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'u',
|
|
6072
|
+
disabled: poly.length === 0,
|
|
6073
|
+
onClick: (e) => {
|
|
6074
|
+
e.stopPropagation(); e.preventDefault()
|
|
6075
|
+
setPoly((cur) => cur.slice(0, -1))
|
|
6076
|
+
setPolyHover(null)
|
|
6077
|
+
},
|
|
6078
|
+
}, t('polyUndo')),
|
|
6079
|
+
h('button', {
|
|
6080
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'c',
|
|
6081
|
+
onClick: (e) => {
|
|
6082
|
+
e.stopPropagation(); e.preventDefault()
|
|
6083
|
+
setPoly([]); setPolyHover(null); setPolyDrag(null)
|
|
6084
|
+
},
|
|
6085
|
+
}, t('polyClear')),
|
|
6086
|
+
h('button', {
|
|
6087
|
+
type: 'button', className: 'dg-btn dg-btnSmall dg-polyClose', key: 's',
|
|
6088
|
+
'data-gallery-poly-close': true,
|
|
6089
|
+
disabled: maskBusy || poly.length < POLYGON_LIMITS.min,
|
|
6090
|
+
onClick: (e) => { e.stopPropagation(); e.preventDefault(); commitPolygon(poly) },
|
|
6091
|
+
}, t('polyClose')),
|
|
6092
|
+
]),
|
|
6093
|
+
])
|
|
6094
|
+
|
|
5100
6095
|
const editor = editing === null ? null : h('div', {
|
|
5101
6096
|
className: 'dg-annotEditor',
|
|
5102
6097
|
key: 'editor',
|
|
@@ -5143,6 +6138,15 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5143
6138
|
}, [
|
|
5144
6139
|
h('span', { className: 'dg-annotIndex', key: 'i' }, `#${idx + 1}`),
|
|
5145
6140
|
h('span', { className: 'dg-annotText', key: 't' }, a.note || t('annotNoNote')),
|
|
6141
|
+
// 只有矩形框能导出遮罩;箭头 / 纯文字标注没有面积,不显示这个动作。
|
|
6142
|
+
typeof onExportMask === 'function' && (a.shape ?? 'rect') === 'rect' && a.w > 0 && a.h > 0
|
|
6143
|
+
? h('button', {
|
|
6144
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'm',
|
|
6145
|
+
title: t('maskExportHint'), 'data-gallery-mask-export': a.id,
|
|
6146
|
+
disabled: maskBusy,
|
|
6147
|
+
onClick: (e) => { e.stopPropagation(); e.preventDefault(); runExportMask(a) },
|
|
6148
|
+
}, t('maskExport'))
|
|
6149
|
+
: null,
|
|
5146
6150
|
h('button', {
|
|
5147
6151
|
type: 'button', className: 'dg-btn dg-btnSmall dg-btnIcon', key: 'x',
|
|
5148
6152
|
title: t('delete'), 'data-gallery-annot-remove': a.id,
|
|
@@ -5150,6 +6154,12 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5150
6154
|
}, '✕'),
|
|
5151
6155
|
])))
|
|
5152
6156
|
|
|
6157
|
+
const maskNoticeNode = maskNotice === null ? null : h('div', {
|
|
6158
|
+
className: `dg-maskNotice dg-maskNotice-${maskNotice.kind}`,
|
|
6159
|
+
key: 'maskNotice', 'data-gallery-mask-notice': true,
|
|
6160
|
+
...blockViewer,
|
|
6161
|
+
}, maskNotice.text)
|
|
6162
|
+
|
|
5153
6163
|
return h('div', {
|
|
5154
6164
|
className: 'dg-annotWrap', key: 'annot',
|
|
5155
6165
|
style: { position: 'absolute', inset: 0, zIndex: 3 },
|
|
@@ -5163,9 +6173,12 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5163
6173
|
// 不设 viewBox:坐标本来就是百分比(相对 SVG 视口),去掉 viewBox 后
|
|
5164
6174
|
// 线宽与字号按屏幕像素计算,否则 12 号字会被放大成几十像素、盖住整张图。
|
|
5165
6175
|
style: {
|
|
5166
|
-
|
|
6176
|
+
// 贴着图片真实布局盒,并用与 <img> 完全相同的 translate/scale。
|
|
6177
|
+
// toNorm 取 getBoundingClientRect() 拿到的是变换后的盒子,
|
|
6178
|
+
// 归一化坐标依旧落在原图同一位置;1:1 不偏、放大平移不脱框。
|
|
6179
|
+
...annotationSvgStyle(imgBox, pan, zoom, transformTransition),
|
|
5167
6180
|
pointerEvents: active ? 'auto' : 'none',
|
|
5168
|
-
cursor: active
|
|
6181
|
+
cursor: annotationSvgCursor(active, dragging, zoom),
|
|
5169
6182
|
},
|
|
5170
6183
|
onPointerDown,
|
|
5171
6184
|
onPointerMove,
|
|
@@ -5173,9 +6186,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5173
6186
|
onPointerCancel: () => { setDraft(null); setPendingStart(null) },
|
|
5174
6187
|
onClick: active ? (event) => { event.preventDefault(); event.stopPropagation() } : undefined,
|
|
5175
6188
|
onContextMenu: active ? (event) => { event.preventDefault(); event.stopPropagation() } : undefined,
|
|
5176
|
-
}, [draftShape, ...shapes]),
|
|
6189
|
+
}, [draftShape, polyShape, ...shapes]),
|
|
5177
6190
|
list,
|
|
5178
6191
|
editor,
|
|
6192
|
+
polyPanel,
|
|
6193
|
+
maskNoticeNode,
|
|
5179
6194
|
])
|
|
5180
6195
|
}
|
|
5181
6196
|
|
|
@@ -5673,6 +6688,12 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
5673
6688
|
* 不是需要长期保留的状态;确认态才落盘,两者语义不同)。
|
|
5674
6689
|
*/
|
|
5675
6690
|
const [annotations, setAnnotations] = React.useState({})
|
|
6691
|
+
/**
|
|
6692
|
+
* 遮罩「原图 → 资产」的内存兜底(v0.14.5):导出成功后立刻登记,
|
|
6693
|
+
* 不用等列表重扫 / 翻页,反馈草稿马上就能带出遮罩路径。刷新后由扫描侧
|
|
6694
|
+
* 的 maskOf 元数据继续兜底;这里同样只存内存,不写 marks、不落盘批注。
|
|
6695
|
+
*/
|
|
6696
|
+
const [maskOverrides, setMaskOverrides] = React.useState({})
|
|
5676
6697
|
const selectMode = batchMode || selected.size > 0
|
|
5677
6698
|
/** 清废稿确认对话框:null=关闭;{ phase:'list'|'deleting', files, digest, count } */
|
|
5678
6699
|
const [discardDialog, setDiscardDialog] = React.useState(null)
|
|
@@ -6145,6 +7166,34 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
6145
7166
|
}, [viewer])
|
|
6146
7167
|
|
|
6147
7168
|
const data = view.status === 'ready' ? view.data : null
|
|
7169
|
+
// 拖图元信息索引:卡片容器只有 relPath,绝对路径与遮罩关联从这里查。
|
|
7170
|
+
// 分组视图的条目在 groups[].files 里,扁平视图在 items 里,两边都收。
|
|
7171
|
+
React.useEffect(() => {
|
|
7172
|
+
dragAssetIndex.clear()
|
|
7173
|
+
dragMaskByOverlay.clear()
|
|
7174
|
+
dragMaskBySource.clear()
|
|
7175
|
+
if (data === null) return undefined
|
|
7176
|
+
const root = String(data.root ?? '')
|
|
7177
|
+
const put = (it) => {
|
|
7178
|
+
// 主遮罩帧自带 maskOf,用它建立「预览图 / 原图 → 主遮罩」反查表。
|
|
7179
|
+
const m = it?.maskOf
|
|
7180
|
+
if (m !== null && m !== undefined && typeof m === 'object' && String(m.relPath ?? '') !== '') {
|
|
7181
|
+
const ov = String(m.overlayRelPath ?? '')
|
|
7182
|
+
const src = String(m.sourceRelPath ?? '')
|
|
7183
|
+
if (ov !== '' && !dragMaskByOverlay.has(ov)) dragMaskByOverlay.set(ov, m)
|
|
7184
|
+
if (src !== '' && !dragMaskBySource.has(src)) dragMaskBySource.set(src, m)
|
|
7185
|
+
}
|
|
7186
|
+
const rel = String(it?.relPath ?? '')
|
|
7187
|
+
if (rel !== '' && !dragAssetIndex.has(rel)) {
|
|
7188
|
+
dragAssetIndex.set(rel, { item: it, absPath: buildAbsPath(root, rel) })
|
|
7189
|
+
}
|
|
7190
|
+
}
|
|
7191
|
+
if (Array.isArray(data.items)) data.items.forEach(put)
|
|
7192
|
+
for (const g of (Array.isArray(data.groups) ? data.groups : [])) {
|
|
7193
|
+
if (Array.isArray(g.files)) g.files.forEach(put)
|
|
7194
|
+
}
|
|
7195
|
+
return undefined
|
|
7196
|
+
}, [data])
|
|
6148
7197
|
const items = data?.items ?? []
|
|
6149
7198
|
/**
|
|
6150
7199
|
* 顶部分类筛选后的可见条目(v0.14.3)。
|
|
@@ -6870,6 +7919,61 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
6870
7919
|
})
|
|
6871
7920
|
: null
|
|
6872
7921
|
|
|
7922
|
+
/**
|
|
7923
|
+
* 矩形框选批注 → ComfyUI 遮罩(v0.14.5 本机 MVP)。
|
|
7924
|
+
* 全链路只碰插件自己的 Host 路由:取原图 → 生成 RGBA PNG → 落盘 → 登记当前对话 → 重扫。
|
|
7925
|
+
* 不自动发送、不写会话日志、不请求 ComfyUI;路径由「遮罩来源」随反馈草稿带出,
|
|
7926
|
+
* 由老板确认后手动发送,模型再拿去回填 #369.image / #193.image。
|
|
7927
|
+
*/
|
|
7928
|
+
const exportMask = React.useCallback(async (item, annotation) => {
|
|
7929
|
+
const built = await buildMaskPng(item.relPath, annotation)
|
|
7930
|
+
// 右键多边形选区带归一化顶点;矩形批注没有这个字段,Host 仍按老契约处理。
|
|
7931
|
+
const isPolygon = Array.isArray(annotation?.polygon) && annotation.polygon.length >= 4
|
|
7932
|
+
const payload = await callHost('saveMask', {
|
|
7933
|
+
path: item.relPath,
|
|
7934
|
+
data: built.data,
|
|
7935
|
+
region: {
|
|
7936
|
+
x: clamp01(annotation.x), y: clamp01(annotation.y),
|
|
7937
|
+
w: clamp01(annotation.w), h: clamp01(annotation.h),
|
|
7938
|
+
},
|
|
7939
|
+
...(isPolygon ? {
|
|
7940
|
+
polygon: annotation.polygon,
|
|
7941
|
+
width: built.width,
|
|
7942
|
+
height: built.height,
|
|
7943
|
+
} : {}),
|
|
7944
|
+
// v0.14.7 彩色填充预览图:与主 alpha 遮罩一起落盘,颜色由界面色板决定
|
|
7945
|
+
...(built.overlay ? {
|
|
7946
|
+
overlay: built.overlay,
|
|
7947
|
+
fillColor: String(built.fillColor ?? 'green'),
|
|
7948
|
+
fillLabel: String(built.fillLabel ?? '绿'),
|
|
7949
|
+
} : {}),
|
|
7950
|
+
sessionId: sessionId ?? '',
|
|
7951
|
+
sessionTitle: Array.isArray(data?.groups)
|
|
7952
|
+
? (data.groups.find((g) => g.isCurrent)?.title ?? '')
|
|
7953
|
+
: '',
|
|
7954
|
+
sessionCreatedAt: Array.isArray(data?.groups)
|
|
7955
|
+
? (data.groups.find((g) => g.isCurrent)?.createdAt ?? 0)
|
|
7956
|
+
: 0,
|
|
7957
|
+
})
|
|
7958
|
+
if (payload?.ok === false) throw new Error(payload?.error?.message ?? 'saveMask failed')
|
|
7959
|
+
setMaskOverrides((prev) => ({
|
|
7960
|
+
...prev,
|
|
7961
|
+
[item.relPath]: {
|
|
7962
|
+
relPath: String(payload?.relPath ?? ''),
|
|
7963
|
+
sourceName: String(item.name ?? ''),
|
|
7964
|
+
region: payload?.region ?? null,
|
|
7965
|
+
polygon: payload?.polygon ?? null,
|
|
7966
|
+
polygonPx: payload?.polygonPx ?? null,
|
|
7967
|
+
bboxPx: payload?.bboxPx ?? null,
|
|
7968
|
+
areaPx: Number(payload?.areaPx) || 0,
|
|
7969
|
+
overlayRelPath: String(payload?.overlayRelPath ?? ''),
|
|
7970
|
+
fillColor: String(built.fillColor ?? 'green'),
|
|
7971
|
+
},
|
|
7972
|
+
}))
|
|
7973
|
+
void refresh()
|
|
7974
|
+
return payload
|
|
7975
|
+
}, [sessionId, data, refresh])
|
|
7976
|
+
|
|
6873
7977
|
// 查看器作为覆盖层叠在网格上:网格保持挂载,滚动位置不丢
|
|
6874
7978
|
// 用 viewer.list(打开时记录的快照),不用全局 items:
|
|
6875
7979
|
// 分组视图下卡片来自组内文件,与当前页的扁平 items 不是同一个集合。
|
|
@@ -6879,6 +7983,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
6879
7983
|
annotations: annotationsOf,
|
|
6880
7984
|
onAddAnnotation: addAnnotation,
|
|
6881
7985
|
onRemoveAnnotation: removeAnnotation,
|
|
7986
|
+
onExportMask: exportMask,
|
|
6882
7987
|
items: viewer.list,
|
|
6883
7988
|
index: Math.min(viewer.index, viewer.list.length - 1),
|
|
6884
7989
|
t,
|
|
@@ -6920,6 +8025,39 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
6920
8025
|
// 反馈篮(S3-a):列出已标记条目 + 带批注的卡片(v0.14.3 批注并入反馈)
|
|
6921
8026
|
// 批注属于「反馈」这一侧:它不进 marks(不参与表态/筛选/落盘),
|
|
6922
8027
|
// 但只要有批注,这张卡就出现在反馈篮里,草稿会按 Annotation N 逐条带出说明与框选区域。
|
|
8028
|
+
// 遮罩资产由扫描侧透传 maskOf.sourceRelPath;反查成「原图 → 遮罩」映射,
|
|
8029
|
+
// 这样原图的反馈条目(带框选批注)在草稿里会自动带出「遮罩来源」,无需人工复制路径。
|
|
8030
|
+
const allAssets = [
|
|
8031
|
+
...(Array.isArray(data?.items) ? data.items : []),
|
|
8032
|
+
...(Array.isArray(data?.groups)
|
|
8033
|
+
? data.groups.flatMap((gr) => (Array.isArray(gr.files) ? gr.files : []))
|
|
8034
|
+
: []),
|
|
8035
|
+
]
|
|
8036
|
+
const maskBySource = new Map()
|
|
8037
|
+
for (const asset of allAssets) {
|
|
8038
|
+
const m = asset.maskOf
|
|
8039
|
+
const source = String(m?.sourceRelPath ?? '')
|
|
8040
|
+
if (source === '' || maskBySource.has(source)) continue
|
|
8041
|
+
maskBySource.set(source, {
|
|
8042
|
+
relPath: String(asset.relPath ?? ''),
|
|
8043
|
+
sourceName: String(m?.sourceName ?? ''),
|
|
8044
|
+
region: m?.region ?? null,
|
|
8045
|
+
// v0.14.6/14.7:源图的反馈条目也要带全顶点坐标与彩色预览路径,
|
|
8046
|
+
// 否则这里会把扫描元数据「压扁」,草稿里只剩 region。
|
|
8047
|
+
polygon: Array.isArray(m?.polygon) ? m.polygon : null,
|
|
8048
|
+
polygonPx: Array.isArray(m?.polygonPx) ? m.polygonPx : null,
|
|
8049
|
+
bboxPx: Array.isArray(m?.bboxPx) ? m.bboxPx : null,
|
|
8050
|
+
areaPx: Number(m?.areaPx) || 0,
|
|
8051
|
+
imageWidth: Number(m?.imageWidth) || 0,
|
|
8052
|
+
imageHeight: Number(m?.imageHeight) || 0,
|
|
8053
|
+
overlayRelPath: String(m?.overlayRelPath ?? ''),
|
|
8054
|
+
fillColor: String(m?.fillColor ?? ''),
|
|
8055
|
+
})
|
|
8056
|
+
}
|
|
8057
|
+
// 刚导出、列表还没刷出遮罩时,用内存兜底覆盖(刷新后由扫描元数据接管)
|
|
8058
|
+
for (const [source, meta] of Object.entries(maskOverrides)) {
|
|
8059
|
+
if (String(meta?.relPath ?? '') !== '') maskBySource.set(source, meta)
|
|
8060
|
+
}
|
|
6923
8061
|
const feedbackPaths = Array.from(new Set([
|
|
6924
8062
|
...Object.keys(marks),
|
|
6925
8063
|
...Object.keys(annotations),
|
|
@@ -6937,6 +8075,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
6937
8075
|
category: found?.category ?? 'unknown',
|
|
6938
8076
|
sessionId: found?.sessionId,
|
|
6939
8077
|
frameOf: found?.frameOf,
|
|
8078
|
+
maskOf: maskBySource.get(relPath) ?? found?.maskOf,
|
|
6940
8079
|
mark: marks[relPath],
|
|
6941
8080
|
annotations: Array.isArray(annotations[relPath]) ? annotations[relPath] : [],
|
|
6942
8081
|
}
|
|
@@ -7269,17 +8408,41 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
7269
8408
|
])
|
|
7270
8409
|
}
|
|
7271
8410
|
|
|
7272
|
-
/**
|
|
8411
|
+
/**
|
|
8412
|
+
* 画廊图标(相框 + 山 + 闪光)—— tab 标题、侧栏脚部入口、输入框入口三处复用,
|
|
8413
|
+
* 保证同一份图形不漂移。内联 SVG、跟随 currentColor、尺寸由外层 className 决定;
|
|
8414
|
+
* 不依赖包内 icon.svg(其首行是非法的 <!DOCTYPE html>,且从未被引用过)。
|
|
8415
|
+
*/
|
|
8416
|
+
function GalleryGlyph({ className }) {
|
|
8417
|
+
return h('svg', {
|
|
8418
|
+
className: className || 'dg-tabTitleIcon',
|
|
8419
|
+
viewBox: '0 0 64 64',
|
|
8420
|
+
width: 16, height: 16,
|
|
8421
|
+
'aria-hidden': 'true', focusable: 'false',
|
|
8422
|
+
}, [
|
|
8423
|
+
// 叠层工作台:后层只露右上边角。三层完整轮廓在 16px 下会互相交叠糊成一块,
|
|
8424
|
+
// 故减为「一张主卡片 + 露角」,线宽加粗到 4(缩到 16px 约 1px 实线)。
|
|
8425
|
+
h('path', { key: 'back', d: 'M22 8h28a4 4 0 0 1 4 4v24', fill: 'none', stroke: 'currentColor', strokeWidth: 4, strokeLinecap: 'round', opacity: 0.55 }),
|
|
8426
|
+
h('rect', { key: 'card', x: 6, y: 16, width: 42, height: 38, rx: 6, fill: 'none', stroke: 'currentColor', strokeWidth: 4 }),
|
|
8427
|
+
h('path', { key: 'check', d: 'M15 35l6 6 12-13', fill: 'none', stroke: 'currentColor', strokeWidth: 4.5, strokeLinecap: 'round', strokeLinejoin: 'round' }),
|
|
8428
|
+
])
|
|
8429
|
+
}
|
|
7273
8430
|
|
|
8431
|
+
/** tab 标题(chip / 浮动面板标题):图标 + 名称。 */
|
|
7274
8432
|
function GalleryTitle({ t }) {
|
|
7275
|
-
|
|
8433
|
+
// 包成单个 inline-flex 容器:宿主 chip 会把 slot 的每个子节点当 flex item 并额外插一份 gap,
|
|
8434
|
+
// 若用 Fragment 返回 [图标, 文字],间距会与图标自带的 margin-right 叠加而过大,还挤压名称。
|
|
8435
|
+
return h('span', { className: 'dg-titleWrap' },
|
|
8436
|
+
h(GalleryGlyph),
|
|
8437
|
+
h('span', { className: 'dg-title' }, t('type.label')))
|
|
7276
8438
|
}
|
|
7277
8439
|
|
|
7278
|
-
/** 侧栏脚部入口按钮:点击打开画廊 tab
|
|
8440
|
+
/** 侧栏脚部入口按钮:点击打开画廊 tab。展开态「图标 + 名称」,收窄态仅图标。 */
|
|
7279
8441
|
function OpenButton({ t, wide }) {
|
|
8442
|
+
const glyph = h(GalleryGlyph, { className: 'dg-sideIcon' })
|
|
7280
8443
|
return h('button', {
|
|
7281
8444
|
type: 'button',
|
|
7282
|
-
className:
|
|
8445
|
+
className: `dg-btn dg-open ${wide ? 'dg-openWide' : 'dg-openNarrow'}`,
|
|
7283
8446
|
'data-gallery-open': true,
|
|
7284
8447
|
title: t('type.label'),
|
|
7285
8448
|
'aria-label': t('type.label'),
|
|
@@ -7290,7 +8453,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
7290
8453
|
console.error('dsh-gallery: open failed', error)
|
|
7291
8454
|
}
|
|
7292
8455
|
},
|
|
7293
|
-
}, wide
|
|
8456
|
+
}, wide
|
|
8457
|
+
? h(React.Fragment, null, glyph, h('span', { className: 'dg-openLabel' }, t('type.label')))
|
|
8458
|
+
: glyph)
|
|
7294
8459
|
}
|
|
7295
8460
|
|
|
7296
8461
|
|
|
@@ -7392,7 +8557,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
7392
8557
|
console.error('dsh-gallery: open failed', error)
|
|
7393
8558
|
}
|
|
7394
8559
|
},
|
|
7395
|
-
}, '
|
|
8560
|
+
}, h(GalleryGlyph, { className: 'dg-sideIcon' }))
|
|
7396
8561
|
}
|
|
7397
8562
|
|
|
7398
8563
|
return {
|
|
@@ -7416,6 +8581,53 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, sta
|
|
|
7416
8581
|
}
|
|
7417
8582
|
}, 'dsh-gallery: seam')
|
|
7418
8583
|
|
|
8584
|
+
// 拖图带位置信息:捕获阶段拦截画廊卡片的 dragstart,把
|
|
8585
|
+
// 「文件名 + 绝对路径 + 主遮罩」写进 File.name(DSH 会原样带进消息)。
|
|
8586
|
+
// 不改图片节点、不改 draggable、不碰 Viewer 的缩放/批注交互、不自动发送。
|
|
8587
|
+
ctx.effect(() => {
|
|
8588
|
+
const onDragStart = (event) => {
|
|
8589
|
+
const dt = event.dataTransfer
|
|
8590
|
+
const target = event.target
|
|
8591
|
+
if (dt === null || dt === undefined || !(target instanceof Element)) return
|
|
8592
|
+
const card = target.closest('[data-gallery-relpath]')
|
|
8593
|
+
if (card === null) return
|
|
8594
|
+
const relPath = String(card.getAttribute('data-gallery-relpath') ?? '')
|
|
8595
|
+
const entry = dragAssetIndex.get(relPath)
|
|
8596
|
+
if (entry === undefined) return
|
|
8597
|
+
// 预览图 / 原图没有 maskOf,按 overlayRelPath / sourceRelPath 反查主遮罩,
|
|
8598
|
+
// 把「主遮罩=<文件名> | 工作流请用主遮罩,预览仅供目视」写进拖拽文本。
|
|
8599
|
+
const linked = dragMaskByOverlay.get(relPath) ?? dragMaskBySource.get(relPath) ?? null
|
|
8600
|
+
const hasMask = entry.item?.maskOf !== null && entry.item?.maskOf !== undefined
|
|
8601
|
+
const item = (!hasMask && linked !== null)
|
|
8602
|
+
? { ...entry.item, maskOf: { ...linked, linkedMask: true } }
|
|
8603
|
+
: entry.item
|
|
8604
|
+
const name = dragNameOf(item, entry.absPath)
|
|
8605
|
+
// 自证 + 兜底双用途:无论 File 替换是否成功,都把同一串信息写进剪贴板。
|
|
8606
|
+
// 拖完在输入框 Ctrl+V 能粘出「产出台·…」= 新代码确实执行过、dragstart 命中;
|
|
8607
|
+
// 粘不出 = 面板仍加载旧模块,需重载窗口。编码 / 写入失败时它就是唯一可用通道。
|
|
8608
|
+
void copyText(name)
|
|
8609
|
+
// 从 Viewer「拖到对话」按钮拖出时,取预览大图而不是按钮内的节点;
|
|
8610
|
+
// 列表卡片则仍用自己那张缩略图。两者都是同源 blob URL,canvas 不会被污染。
|
|
8611
|
+
const img = card.hasAttribute('data-gallery-dragviewer')
|
|
8612
|
+
? document.querySelector('.dg-viewerBody img')
|
|
8613
|
+
: (target.matches('img') ? target : target.querySelector('img'))
|
|
8614
|
+
const bytes = syncImagePngBytes(img)
|
|
8615
|
+
if (bytes === null) {
|
|
8616
|
+
// 编码失败:保留浏览器原生拖图,信息已在剪贴板供手动粘贴
|
|
8617
|
+
return
|
|
8618
|
+
}
|
|
8619
|
+
try {
|
|
8620
|
+
dt.clearData()
|
|
8621
|
+
dt.effectAllowed = 'copy'
|
|
8622
|
+
dt.items.add(new File([bytes], name, { type: 'image/png' }))
|
|
8623
|
+
} catch (error) {
|
|
8624
|
+
console.warn('dsh-gallery: 拖图元信息写入失败,信息已在剪贴板', error)
|
|
8625
|
+
}
|
|
8626
|
+
}
|
|
8627
|
+
document.addEventListener('dragstart', onDragStart, true)
|
|
8628
|
+
return () => document.removeEventListener('dragstart', onDragStart, true)
|
|
8629
|
+
}, 'dsh-gallery: drag asset metadata')
|
|
8630
|
+
|
|
7419
8631
|
ctx.effect(() => {
|
|
7420
8632
|
const tag = document.createElement('style')
|
|
7421
8633
|
tag.dataset.plugin = 'dsh-gallery'
|