dsh-gallery 1.3.0 → 1.4.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 +94 -0
- package/README.md +31 -10
- package/client.js +725 -52
- package/host/atomic.js +75 -0
- package/host/context.js +2 -4
- package/host/feedback.js +81 -10
- package/host/frames.js +3 -5
- package/host/http.js +4 -2
- package/host/labels.js +3 -5
- package/host/marks.js +2 -5
- package/index.js +20 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -223,6 +223,15 @@ function maskAlphaAt(px, py, rect) {
|
|
|
223
223
|
const POLYGON_LIMITS = { min: 4, max: 20, closeRadius: 0.02, minArea: 0.0001 }
|
|
224
224
|
/** 左键按下后移动超过这个归一化距离才算「拖框」,否则算一次点击(区域顶点)。 */
|
|
225
225
|
const ANNOT_DRAG_THRESHOLD = 0.008
|
|
226
|
+
/** 右键涂抹:每走过这么多屏幕像素采一个点(再按图片显示尺寸换算成归一化距离)。 */
|
|
227
|
+
const SMEAR_SAMPLE_PX = 4
|
|
228
|
+
/** 涂抹笔迹简化容差(屏幕像素);压不到上限以内就按 1.6 倍逐级放宽。 */
|
|
229
|
+
const SMEAR_SIMPLIFY_PX = 1.5
|
|
230
|
+
/**
|
|
231
|
+
* 涂抹进行中的笔迹宽度(屏幕像素)。
|
|
232
|
+
* 只在「还没松手」的那一瞬用;松手后 poly 已换成区域外轮廓,描边回到 MASK_STROKE_PX。
|
|
233
|
+
*/
|
|
234
|
+
const SMEAR_LIVE_STROKE_PX = 2
|
|
226
235
|
|
|
227
236
|
/* ------------------------------------------------------------------ *
|
|
228
237
|
* 选区纯色半透明填充(v0.14.7 引入;老板 2026-11-12 20:22 再定版):
|
|
@@ -303,6 +312,324 @@ function polygonArea(points) {
|
|
|
303
312
|
return Math.abs(sum) / 2
|
|
304
313
|
}
|
|
305
314
|
|
|
315
|
+
/**
|
|
316
|
+
* 取一个顶点的 x / y,兼容 [{x,y}] 与 [[x,y]] 两种形态。
|
|
317
|
+
* 涂抹轨迹来自 toNorm(),是 {x,y} 对象;离线几何测试用的是数组。
|
|
318
|
+
* 取值形态不统一会让距离算出 NaN,整圈被简化成首尾两点(2026-11-19 实测踩过)。
|
|
319
|
+
*/
|
|
320
|
+
function polygonXY(p) {
|
|
321
|
+
if (Array.isArray(p)) return [Number(p[0]), Number(p[1])]
|
|
322
|
+
return [Number(p?.x), Number(p?.y)]
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 点到线段距离(归一化坐标)。RDP 简化要用,单独抽出来方便离线钉死。
|
|
327
|
+
*/
|
|
328
|
+
function polygonPointLineDist(p, a, b) {
|
|
329
|
+
const [px, py] = polygonXY(p)
|
|
330
|
+
const [ax, ay] = polygonXY(a)
|
|
331
|
+
const [bx, by] = polygonXY(b)
|
|
332
|
+
const dx = bx - ax
|
|
333
|
+
const dy = by - ay
|
|
334
|
+
const len2 = dx * dx + dy * dy
|
|
335
|
+
if (len2 === 0) return Math.hypot(px - ax, py - ay)
|
|
336
|
+
let t = ((px - ax) * dx + (py - ay) * dy) / len2
|
|
337
|
+
t = t < 0 ? 0 : (t > 1 ? 1 : t)
|
|
338
|
+
return Math.hypot(px - (ax + t * dx), py - (ay + t * dy))
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Ramer–Douglas–Peucker:把涂抹轨迹里共线的中间点压掉,保住拐角。
|
|
343
|
+
* 输入输出都是归一化顶点数组([{x,y}] / [[x,y]] 都吃,原样返回同一形态),首尾两点一定保留。
|
|
344
|
+
*/
|
|
345
|
+
function polygonSimplify(points, eps) {
|
|
346
|
+
if (!Array.isArray(points) || points.length <= 2) {
|
|
347
|
+
return Array.isArray(points) ? points.slice() : []
|
|
348
|
+
}
|
|
349
|
+
const a = points[0]
|
|
350
|
+
const b = points[points.length - 1]
|
|
351
|
+
let idx = -1
|
|
352
|
+
let maxD = -1
|
|
353
|
+
for (let i = 1; i < points.length - 1; i += 1) {
|
|
354
|
+
const d = polygonPointLineDist(points[i], a, b)
|
|
355
|
+
if (d > maxD) { maxD = d; idx = i }
|
|
356
|
+
}
|
|
357
|
+
if (idx < 0 || maxD <= eps) return [a, b]
|
|
358
|
+
const left = polygonSimplify(points.slice(0, idx + 1), eps)
|
|
359
|
+
const right = polygonSimplify(points.slice(idx), eps)
|
|
360
|
+
return left.slice(0, -1).concat(right)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 把涂抹笔迹收敛到 host 契约允许的点数(4–20)。
|
|
365
|
+
* host/http.js 对 saveMask 的 polygon 直接校验 4–20 个顶点,超了回 400,
|
|
366
|
+
* 所以必须在这里压下来:先保形(小容差),实在压不下来再逐级放宽;
|
|
367
|
+
* 极端情况(整圈都在抖)按等距抽稀兜底,保证仍是合法闭合多边形。
|
|
368
|
+
*/
|
|
369
|
+
function polygonSimplifyToLimit(points, maxPoints, baseEps) {
|
|
370
|
+
if (!Array.isArray(points) || points.length === 0) return []
|
|
371
|
+
const limit = Math.max(3, Math.floor(Number(maxPoints) || POLYGON_LIMITS.max))
|
|
372
|
+
let eps = Number.isFinite(baseEps) && baseEps > 0 ? baseEps : 0.001
|
|
373
|
+
let out = polygonSimplify(points, eps)
|
|
374
|
+
let guard = 0
|
|
375
|
+
while (out.length > limit && guard < 24) {
|
|
376
|
+
eps *= 1.6
|
|
377
|
+
out = polygonSimplify(points, eps)
|
|
378
|
+
guard += 1
|
|
379
|
+
}
|
|
380
|
+
if (out.length > limit) {
|
|
381
|
+
const step = out.length / limit
|
|
382
|
+
const thinned = []
|
|
383
|
+
for (let i = 0; i < limit; i += 1) thinned.push(out[Math.floor(i * step)])
|
|
384
|
+
out = thinned
|
|
385
|
+
}
|
|
386
|
+
return out
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/* ------------------------------------------------------------------ *
|
|
390
|
+
* 涂抹轨迹 → 闭合区域外轮廓(老板 2026-11-19 晚提出)
|
|
391
|
+
*
|
|
392
|
+
* 问题:SVG <polygon> 的描边沿**每一条边**画,轨迹自相交时内部交叉的线段
|
|
393
|
+
* 也被描出来,看着是「一堆路径」而不是「一整块区域」。填充本身是对的。
|
|
394
|
+
*
|
|
395
|
+
* 做法(与宿主生成遮罩同一语义:多边形填充 → 二值栅格):
|
|
396
|
+
* 1. 轨迹按 nonzero 环绕规则栅格化到 bbox 局部网格;若几乎没填上
|
|
397
|
+
* (正反两圈互相抵消这类),再按奇偶规则补算一次,取面积大的。
|
|
398
|
+
* 2. 取面积最大的 8 连通域 —— 涂抹断成两截时只认主体。
|
|
399
|
+
* 3. Moore 邻域边界追踪取外环:洞与内部交叉线天然不参与。
|
|
400
|
+
* 4. 闭合环 RDP 简化,收敛到 host 契约的 4–20 顶点。
|
|
401
|
+
* 纯函数、零依赖,Node 里可直接抽出来跑断言。
|
|
402
|
+
* ------------------------------------------------------------------ */
|
|
403
|
+
const MOORE_DX = [0, 1, 1, 1, 0, -1, -1, -1]
|
|
404
|
+
const MOORE_DY = [-1, -1, 0, 1, 1, 1, 0, -1]
|
|
405
|
+
|
|
406
|
+
/** 扫描线栅格化:mode='nonzero' 按环绕数,'evenodd' 按奇偶。返回 gw*gh 的 0/1 网格。 */
|
|
407
|
+
function polygonRasterFill(norm, gw, gh, gx0, gy0, scale, mode) {
|
|
408
|
+
const grid = new Uint8Array(gw * gh)
|
|
409
|
+
if (!Array.isArray(norm) || norm.length < 3) return grid
|
|
410
|
+
const edges = []
|
|
411
|
+
for (let i = 0; i < norm.length; i += 1) {
|
|
412
|
+
const a = norm[i]
|
|
413
|
+
const b = norm[(i + 1) % norm.length]
|
|
414
|
+
const ax = (a[0] - gx0) * scale
|
|
415
|
+
const ay = (a[1] - gy0) * scale
|
|
416
|
+
const bx = (b[0] - gx0) * scale
|
|
417
|
+
const by = (b[1] - gy0) * scale
|
|
418
|
+
if (ay === by) continue
|
|
419
|
+
edges.push([ax, ay, bx, by])
|
|
420
|
+
}
|
|
421
|
+
if (edges.length < 2) return grid
|
|
422
|
+
const hits = []
|
|
423
|
+
for (let gy = 0; gy < gh; gy += 1) {
|
|
424
|
+
const y = gy + 0.5
|
|
425
|
+
hits.length = 0
|
|
426
|
+
for (const e of edges) {
|
|
427
|
+
if ((e[1] > y) === (e[3] > y)) continue
|
|
428
|
+
const k = (y - e[1]) / (e[3] - e[1])
|
|
429
|
+
hits.push({ x: e[0] + (k * (e[2] - e[0])), dir: e[3] > e[1] ? 1 : -1 })
|
|
430
|
+
}
|
|
431
|
+
if (hits.length < 2) continue
|
|
432
|
+
hits.sort((p, q) => p.x - q.x)
|
|
433
|
+
let wind = 0
|
|
434
|
+
for (let i = 0; i < hits.length - 1; i += 1) {
|
|
435
|
+
wind += hits[i].dir
|
|
436
|
+
const on = mode === 'evenodd' ? (i % 2 === 0) : (wind !== 0)
|
|
437
|
+
if (!on) continue
|
|
438
|
+
let c0 = Math.ceil(hits[i].x - 0.5)
|
|
439
|
+
let c1 = Math.floor(hits[i + 1].x - 0.5)
|
|
440
|
+
if (c1 < c0) continue
|
|
441
|
+
if (c0 < 0) c0 = 0
|
|
442
|
+
if (c1 > gw - 1) c1 = gw - 1
|
|
443
|
+
for (let cx = c0; cx <= c1; cx += 1) grid[(gy * gw) + cx] = 1
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return grid
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** 取面积最大的 8 连通域,其余清零。返回 { grid, size }。 */
|
|
450
|
+
function polygonLargestRegion(grid, gw, gh) {
|
|
451
|
+
const out = new Uint8Array(gw * gh)
|
|
452
|
+
const seen = new Uint8Array(gw * gh)
|
|
453
|
+
const stack = []
|
|
454
|
+
let best = null
|
|
455
|
+
let bestSize = 0
|
|
456
|
+
for (let start = 0; start < grid.length; start += 1) {
|
|
457
|
+
if (grid[start] === 0 || seen[start] === 1) continue
|
|
458
|
+
const cx0 = start % gw
|
|
459
|
+
const cy0 = (start - cx0) / gw
|
|
460
|
+
stack.length = 0
|
|
461
|
+
stack.push(start)
|
|
462
|
+
seen[start] = 1
|
|
463
|
+
const cells = [start]
|
|
464
|
+
while (stack.length > 0) {
|
|
465
|
+
const cur = stack.pop()
|
|
466
|
+
const cx = cur % gw
|
|
467
|
+
const cy = (cur - cx) / gw
|
|
468
|
+
for (let dy = -1; dy <= 1; dy += 1) {
|
|
469
|
+
for (let dx = -1; dx <= 1; dx += 1) {
|
|
470
|
+
if (dx === 0 && dy === 0) continue
|
|
471
|
+
const nx = cx + dx
|
|
472
|
+
const ny = cy + dy
|
|
473
|
+
if (nx < 0 || ny < 0 || nx >= gw || ny >= gh) continue
|
|
474
|
+
const ni = (ny * gw) + nx
|
|
475
|
+
if (grid[ni] === 0 || seen[ni] === 1) continue
|
|
476
|
+
seen[ni] = 1
|
|
477
|
+
stack.push(ni)
|
|
478
|
+
cells.push(ni)
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (cells.length > bestSize) { best = cells; bestSize = cells.length }
|
|
483
|
+
void cx0
|
|
484
|
+
void cy0
|
|
485
|
+
}
|
|
486
|
+
if (best === null) return { grid: out, size: 0 }
|
|
487
|
+
for (const i of best) out[i] = 1
|
|
488
|
+
return { grid: out, size: bestSize }
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** Moore 邻域边界追踪:返回最外圈边界格坐标序列(末尾不回写起点)。 */
|
|
492
|
+
function polygonTraceRing(grid, gw, gh) {
|
|
493
|
+
let sx = -1
|
|
494
|
+
let sy = -1
|
|
495
|
+
for (let y = 0; y < gh && sy < 0; y += 1) {
|
|
496
|
+
for (let x = 0; x < gw; x += 1) {
|
|
497
|
+
if (grid[(y * gw) + x] === 1) { sx = x; sy = y; break }
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (sx < 0) return []
|
|
501
|
+
const at = (x, y) => (x >= 0 && y >= 0 && x < gw && y < gh && grid[(y * gw) + x] === 1 ? 1 : 0)
|
|
502
|
+
const ring = [[sx, sy]]
|
|
503
|
+
let cx = sx
|
|
504
|
+
let cy = sy
|
|
505
|
+
// 起点是行优先第一个前景格:上方与左侧必为空,回溯方向取「左」
|
|
506
|
+
let dir = 6
|
|
507
|
+
const guard = grid.length * 8 + 16
|
|
508
|
+
for (let step = 0; step < guard; step += 1) {
|
|
509
|
+
let moved = false
|
|
510
|
+
for (let k = 0; k < 8; k += 1) {
|
|
511
|
+
const d = (dir + k) % 8
|
|
512
|
+
const nx = cx + MOORE_DX[d]
|
|
513
|
+
const ny = cy + MOORE_DY[d]
|
|
514
|
+
if (at(nx, ny) === 0) continue
|
|
515
|
+
dir = (d + 5) % 8
|
|
516
|
+
cx = nx
|
|
517
|
+
cy = ny
|
|
518
|
+
ring.push([cx, cy])
|
|
519
|
+
moved = true
|
|
520
|
+
break
|
|
521
|
+
}
|
|
522
|
+
if (!moved) break
|
|
523
|
+
if (cx === sx && cy === sy) break
|
|
524
|
+
}
|
|
525
|
+
return ring
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** 闭合环 RDP:从离首点最远处拆成两条链分别简化,避免首尾被削平。 */
|
|
529
|
+
function polygonSimplifyRing(ring, eps) {
|
|
530
|
+
if (!Array.isArray(ring) || ring.length <= 4) {
|
|
531
|
+
return Array.isArray(ring) ? ring.slice() : []
|
|
532
|
+
}
|
|
533
|
+
const head = ring[0]
|
|
534
|
+
let far = 1
|
|
535
|
+
let farD = -1
|
|
536
|
+
for (let i = 1; i < ring.length; i += 1) {
|
|
537
|
+
const dx = ring[i][0] - head[0]
|
|
538
|
+
const dy = ring[i][1] - head[1]
|
|
539
|
+
const d = (dx * dx) + (dy * dy)
|
|
540
|
+
if (d > farD) { farD = d; far = i }
|
|
541
|
+
}
|
|
542
|
+
const a = polygonSimplify(ring.slice(0, far + 1), eps)
|
|
543
|
+
const b = polygonSimplify(ring.slice(far).concat([head]), eps)
|
|
544
|
+
return a.slice(0, -1).concat(b.slice(0, -1))
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** 环简化到 maxPoints 以内:逐级放宽,兜底等距抽稀。 */
|
|
548
|
+
function polygonRingToLimit(ring, maxPoints, baseEps) {
|
|
549
|
+
const limit = Math.max(3, Math.floor(Number(maxPoints) || POLYGON_LIMITS.max))
|
|
550
|
+
let eps = Number.isFinite(baseEps) && baseEps > 0 ? baseEps : 0.001
|
|
551
|
+
let out = polygonSimplifyRing(ring, eps)
|
|
552
|
+
let guard = 0
|
|
553
|
+
while (out.length > limit && guard < 24) {
|
|
554
|
+
eps *= 1.6
|
|
555
|
+
out = polygonSimplifyRing(ring, eps)
|
|
556
|
+
guard += 1
|
|
557
|
+
}
|
|
558
|
+
if (out.length > limit) {
|
|
559
|
+
const step = out.length / limit
|
|
560
|
+
const thinned = []
|
|
561
|
+
for (let i = 0; i < limit; i += 1) thinned.push(out[Math.floor(i * step)])
|
|
562
|
+
out = thinned
|
|
563
|
+
}
|
|
564
|
+
return out
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* 涂抹轨迹 → 区域外轮廓顶点(归一化 [{x,y}])。
|
|
569
|
+
* 轨迹过短或区域退化时返回 [],调用方按「选区无效」处理。
|
|
570
|
+
*/
|
|
571
|
+
function polygonRegionOutline(points, options = {}) {
|
|
572
|
+
const list = Array.isArray(points) ? points : []
|
|
573
|
+
if (list.length < 3) return []
|
|
574
|
+
const maxPoints = Math.max(
|
|
575
|
+
POLYGON_LIMITS.min,
|
|
576
|
+
Math.min(POLYGON_LIMITS.max, Math.floor(Number(options.maxPoints) || POLYGON_LIMITS.max)),
|
|
577
|
+
)
|
|
578
|
+
const longSide = Math.max(48, Math.min(512, Math.floor(Number(options.gridSize) || 240)))
|
|
579
|
+
const norm = []
|
|
580
|
+
for (const p of list) {
|
|
581
|
+
const xy = polygonXY(p)
|
|
582
|
+
if (!Number.isFinite(xy[0]) || !Number.isFinite(xy[1])) continue
|
|
583
|
+
norm.push([clamp01(xy[0]), clamp01(xy[1])])
|
|
584
|
+
}
|
|
585
|
+
if (norm.length < 3) return []
|
|
586
|
+
let bx0 = Infinity
|
|
587
|
+
let by0 = Infinity
|
|
588
|
+
let bx1 = -Infinity
|
|
589
|
+
let by1 = -Infinity
|
|
590
|
+
for (const p of norm) {
|
|
591
|
+
if (p[0] < bx0) bx0 = p[0]
|
|
592
|
+
if (p[0] > bx1) bx1 = p[0]
|
|
593
|
+
if (p[1] < by0) by0 = p[1]
|
|
594
|
+
if (p[1] > by1) by1 = p[1]
|
|
595
|
+
}
|
|
596
|
+
const span = Math.max(bx1 - bx0, by1 - by0)
|
|
597
|
+
if (!(span > 1e-5)) return []
|
|
598
|
+
const scale = longSide / span
|
|
599
|
+
const gx0 = bx0 - (1 / scale)
|
|
600
|
+
const gy0 = by0 - (1 / scale)
|
|
601
|
+
const gw = Math.max(4, Math.ceil((bx1 - bx0) * scale) + 3)
|
|
602
|
+
const gh = Math.max(4, Math.ceil((by1 - by0) * scale) + 3)
|
|
603
|
+
const bboxCells = Math.max(1, (bx1 - bx0) * scale * (by1 - by0) * scale)
|
|
604
|
+
|
|
605
|
+
let best = polygonLargestRegion(
|
|
606
|
+
polygonRasterFill(norm, gw, gh, gx0, gy0, scale, 'nonzero'), gw, gh)
|
|
607
|
+
if (best.size < bboxCells * 0.05) {
|
|
608
|
+
const alt = polygonLargestRegion(
|
|
609
|
+
polygonRasterFill(norm, gw, gh, gx0, gy0, scale, 'evenodd'), gw, gh)
|
|
610
|
+
if (alt.size > best.size) best = alt
|
|
611
|
+
}
|
|
612
|
+
if (best.size < 4) return []
|
|
613
|
+
|
|
614
|
+
const ring = polygonTraceRing(best.grid, gw, gh)
|
|
615
|
+
if (ring.length < 4) return []
|
|
616
|
+
const cells = ring.map((c) => [
|
|
617
|
+
clamp01(gx0 + ((c[0] + 0.5) / scale)),
|
|
618
|
+
clamp01(gy0 + ((c[1] + 0.5) / scale)),
|
|
619
|
+
])
|
|
620
|
+
// 容差默认 1.4 个格,刚好压掉栅格锯齿又不动拐角;
|
|
621
|
+
// 但极窄选区(细长条只有 2 格高)会被这么大的容差整条压平,所以再拿短边夹一道。
|
|
622
|
+
const thin = Math.min(bx1 - bx0, by1 - by0)
|
|
623
|
+
const rawEps = (Number.isFinite(options.simplifyEps) && options.simplifyEps > 0)
|
|
624
|
+
? options.simplifyEps
|
|
625
|
+
: (1.4 / scale)
|
|
626
|
+
const eps = Math.min(rawEps, thin * 0.3)
|
|
627
|
+
const simplified = polygonRingToLimit(cells, maxPoints, eps)
|
|
628
|
+
// 少于 host 下限(4 点)直接当无效选区,交给调用方统一报「面积太小」
|
|
629
|
+
if (simplified.length < POLYGON_LIMITS.min) return []
|
|
630
|
+
return simplified.map((p) => ({ x: p[0], y: p[1] }))
|
|
631
|
+
}
|
|
632
|
+
|
|
306
633
|
/** 射线法(无 canvas 环境兜底,也用于离线断言钉死「多边形内 alpha=0」)。 */
|
|
307
634
|
function pointInPolygon(px, py, points) {
|
|
308
635
|
let inside = false
|
|
@@ -567,6 +894,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
567
894
|
preview: '预览',
|
|
568
895
|
previewInSidebar: '在 DSH 右侧栏预览该文件',
|
|
569
896
|
copy: '带路径复制',
|
|
897
|
+
copyFile: '复制文件',
|
|
898
|
+
copyFileHint: '复制文件本身到系统剪贴板,可在 WorkBuddy / 微信对话框按 Ctrl+V 直接粘贴',
|
|
899
|
+
writeDraft: '写进输入框',
|
|
900
|
+
writeDraftHint: '把「文件名 + 绝对路径 + 主遮罩」写进对话输入框(只写不发)',
|
|
570
901
|
copyPath: '复制文件名+绝对路径+关联遮罩(可直接粘进对话框)',
|
|
571
902
|
copied: '已复制',
|
|
572
903
|
openFolder: '打开所在文件夹',
|
|
@@ -834,8 +1165,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
834
1165
|
maskFailed: '遮罩生成失败:{message}',
|
|
835
1166
|
// v0.14.6 右键多点选区(4–20 点)→ 实心多边形遮罩
|
|
836
1167
|
polyTitle: '多边形遮罩选区',
|
|
1168
|
+
smearTitle: '涂抹遮罩选区',
|
|
1169
|
+
smearHint: '按住右键涂抹成区域;松手只保留区域外轮廓(内部交叉的笔迹不计入),可确认导出或点「清空」重涂。逐点仍可用:右键一下落一个顶点。',
|
|
837
1170
|
polyInfo: '{n}/{max} 点 · 外接框 左{x}% 上{y}% · {w}%×{h}% · 选区约占全图 {area}%',
|
|
838
|
-
polyHint: '
|
|
1171
|
+
polyHint: '右键逐点圈选,或按住右键直接涂抹;点回起点、按 Enter 或点「闭合并生成遮罩」即导出。顶点可左键拖动微调,Backspace 撤销一点,Escape 清空。',
|
|
839
1172
|
polyFillColor: '填充色:',
|
|
840
1173
|
polyClose: '闭合并生成遮罩',
|
|
841
1174
|
polyUndo: '撤销一点',
|
|
@@ -987,6 +1320,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
987
1320
|
previewInSidebar: 'Preview this file in the DSH sidebar',
|
|
988
1321
|
copy: 'Copy with path',
|
|
989
1322
|
copyPath: 'Copy file name + absolute path + linked mask (pasteable into chat)',
|
|
1323
|
+
copyFile: 'Copy file',
|
|
1324
|
+
copyFileHint: 'Copy the file itself to the system clipboard, then paste into WorkBuddy / WeChat with Ctrl+V',
|
|
1325
|
+
writeDraft: 'Write to input',
|
|
1326
|
+
writeDraftHint: 'Write file name + absolute path + linked mask into the chat input (never sends)',
|
|
990
1327
|
copied: 'Copied',
|
|
991
1328
|
openFolder: 'Open containing folder',
|
|
992
1329
|
kindImage: 'Images',
|
|
@@ -1250,8 +1587,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
1250
1587
|
maskFailed: 'Mask export failed: {message}',
|
|
1251
1588
|
// v0.14.6 right-click polygon selection (4-20 points) -> solid polygon mask
|
|
1252
1589
|
polyTitle: 'Polygon mask selection',
|
|
1590
|
+
smearTitle: 'Painted mask selection',
|
|
1591
|
+
smearHint: 'Hold the right button and paint the area; on release only the outer outline is kept (criss-cross strokes inside are dropped). Then confirm or clear. Click-by-click still works: one right click drops a vertex.',
|
|
1253
1592
|
polyInfo: '{n}/{max} points · bbox left {x}% top {y}% · {w}%×{h}% · ~{area}% of image',
|
|
1254
|
-
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.',
|
|
1593
|
+
polyHint: 'Right-click to add vertices, or hold the right button and paint; click the first point, press Enter, or use Close & make mask. Drag vertices with the left button; Backspace removes the last point.',
|
|
1255
1594
|
polyFillColor: 'Fill:',
|
|
1256
1595
|
polyClose: 'Close & make mask',
|
|
1257
1596
|
polyUndo: 'Undo point',
|
|
@@ -2179,6 +2518,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
2179
2518
|
.dg-cardWrap:hover .dg-labelBtn { opacity: 1; }
|
|
2180
2519
|
.dg-labelBtn:hover { border-color: #fff; transform: scale(1.06); }
|
|
2181
2520
|
.dg-labelBtnManual { background: #8a6520; border-color: #e2b968; opacity: .95; }
|
|
2521
|
+
/* 「复制文件」与「改标签 ✎」并排:✎ 占 right:4,复制按钮往左挪一档不重叠。 */
|
|
2522
|
+
.dg-labelBtnCopy { right: 30px; }
|
|
2182
2523
|
.dg-cardSelectable .dg-labelBtn { display: none; }
|
|
2183
2524
|
|
|
2184
2525
|
.dg-labelLayer {
|
|
@@ -3890,6 +4231,119 @@ function syncImagePngBytes(img) {
|
|
|
3890
4231
|
}
|
|
3891
4232
|
}
|
|
3892
4233
|
|
|
4234
|
+
/* ------------------------------------------------------------------ *
|
|
4235
|
+
* 原生拖出真文件到外部应用(2026-11-19)
|
|
4236
|
+
*
|
|
4237
|
+
* DSH 桌面端通过 preload 暴露 window.dshDesktop.fileDrag(底层
|
|
4238
|
+
* webContents.startDrag),WorkBuddy 自带的文件卡片拖到外部应用就是用它。
|
|
4239
|
+
* 产出台的卡片照同一条桥拖出【磁盘上的真文件】,而不是旧逻辑里的缩略图 PNG。
|
|
4240
|
+
*
|
|
4241
|
+
* 流程:pointerdown 时异步 prepare(媒体路由取原始字节 → 桥准备临时文件),
|
|
4242
|
+
* dragstart 同步 start() 起原生拖放,dragend/drop 时 release 清理。
|
|
4243
|
+
* 红线:桥缺失/准备失败一律返回 null 降级到旧的 PNG+路径逻辑;只准备、不改动
|
|
4244
|
+
* 任何资产;不碰 composer、不发送、不 cancel 对话。
|
|
4245
|
+
* ------------------------------------------------------------------ */
|
|
4246
|
+
|
|
4247
|
+
/** 探测原生拖文件桥。Web 版 / 老宿主没有 → 返回 null 走旧逻辑。 */
|
|
4248
|
+
function nativeDragBridge() {
|
|
4249
|
+
try {
|
|
4250
|
+
const d = (typeof window !== 'undefined') ? window.dshDesktop : null
|
|
4251
|
+
if (d === null || d === undefined || d.protocolVersion !== 1) return null
|
|
4252
|
+
const fd = d.fileDrag
|
|
4253
|
+
if (fd === null || fd === undefined || typeof fd.prepare !== 'function'
|
|
4254
|
+
|| typeof fd.start !== 'function' || typeof fd.release !== 'function') return null
|
|
4255
|
+
return fd
|
|
4256
|
+
} catch {
|
|
4257
|
+
return null
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
|
|
4261
|
+
/** 文件扩展名(小写、无点),用于拖出时的文件名后缀校正。 */
|
|
4262
|
+
function nativeDragExt(name) {
|
|
4263
|
+
const s = String(name ?? '')
|
|
4264
|
+
const dot = s.lastIndexOf('.')
|
|
4265
|
+
if (dot < 0) return ''
|
|
4266
|
+
return s.slice(dot + 1).toLowerCase()
|
|
4267
|
+
}
|
|
4268
|
+
|
|
4269
|
+
/** 根据扩展名猜 MIME;猜不出给 octet-stream,宿主侧 resolveDragFileName 会据此补后缀。 */
|
|
4270
|
+
function nativeDragMime(ext) {
|
|
4271
|
+
const map = {
|
|
4272
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif',
|
|
4273
|
+
webp: 'image/webp', bmp: 'image/bmp', svg: 'image/svg+xml',
|
|
4274
|
+
pdf: 'application/pdf', json: 'application/json', md: 'text/markdown',
|
|
4275
|
+
txt: 'text/plain', csv: 'text/csv', xml: 'application/xml',
|
|
4276
|
+
zip: 'application/zip', mp4: 'video/mp4', webm: 'video/webm',
|
|
4277
|
+
mp3: 'audio/mpeg', wav: 'audio/wav',
|
|
4278
|
+
}
|
|
4279
|
+
return map[String(ext ?? '').toLowerCase()] ?? 'application/octet-stream'
|
|
4280
|
+
}
|
|
4281
|
+
|
|
4282
|
+
/**
|
|
4283
|
+
* 异步准备一次原生拖放。成功返回 { start, release },任何失败返回 null。
|
|
4284
|
+
* @param relPath 资产相对路径(喂媒体路由 + 命名)
|
|
4285
|
+
* @param item 卡片 item(提供 name)
|
|
4286
|
+
*/
|
|
4287
|
+
async function prepareNativeDrag(relPath, item) {
|
|
4288
|
+
const bridge = nativeDragBridge()
|
|
4289
|
+
if (bridge === null) return null
|
|
4290
|
+
const rel = String(relPath ?? '')
|
|
4291
|
+
if (rel === '') return null
|
|
4292
|
+
const name = String(item?.name ?? baseName(rel))
|
|
4293
|
+
const ext = nativeDragExt(name) || nativeDragExt(rel)
|
|
4294
|
+
let requestId = ''
|
|
4295
|
+
let prepared = false
|
|
4296
|
+
try {
|
|
4297
|
+
// 媒体路由是同源 GET、只读、走白名单,返回文件原始字节。
|
|
4298
|
+
const url = MEDIA_ROUTE + '?path=' + encodeURIComponent(rel)
|
|
4299
|
+
const res = await fetch(url, { credentials: 'same-origin' })
|
|
4300
|
+
if (!res.ok) return null
|
|
4301
|
+
const blob = await res.blob()
|
|
4302
|
+
if (blob.size < 1) return null
|
|
4303
|
+
const bytes = new Uint8Array(await blob.arrayBuffer())
|
|
4304
|
+
requestId = 'dg-drag-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 10)
|
|
4305
|
+
// 主进程 prepare 接受 { kind:'bytes', bytes, name, mediaType, outputExtension },
|
|
4306
|
+
// 返回 handle;start(handle) 内部才真正调 webContents.startDrag。
|
|
4307
|
+
const handle = await bridge.prepare({
|
|
4308
|
+
kind: 'bytes',
|
|
4309
|
+
bytes,
|
|
4310
|
+
name,
|
|
4311
|
+
mediaType: nativeDragMime(ext),
|
|
4312
|
+
outputExtension: ext,
|
|
4313
|
+
}, requestId)
|
|
4314
|
+
if (typeof handle !== 'string' || handle === '') return null
|
|
4315
|
+
prepared = true
|
|
4316
|
+
let started = false
|
|
4317
|
+
return {
|
|
4318
|
+
relPath: rel,
|
|
4319
|
+
start: () => {
|
|
4320
|
+
if (started) return false
|
|
4321
|
+
started = true
|
|
4322
|
+
try {
|
|
4323
|
+
void Promise.resolve(bridge.start(handle)).then((ok) => {
|
|
4324
|
+
// start 返回 false 表示宿主侧没起来(如文件被占用);静默即可,
|
|
4325
|
+
// dragstart 里 dataTransfer 仍带着 PNG+路径,至少拖进对话可用。
|
|
4326
|
+
if (ok === false) console.warn('dsh-gallery: 原生拖出未启动,已保留对话拖拽兜底')
|
|
4327
|
+
}).catch(() => {})
|
|
4328
|
+
} catch {
|
|
4329
|
+
// 起拖失败不阻断:dataTransfer 的 PNG+路径通道仍在。
|
|
4330
|
+
}
|
|
4331
|
+
return true
|
|
4332
|
+
},
|
|
4333
|
+
release: () => {
|
|
4334
|
+
if (!started) return
|
|
4335
|
+
try { void Promise.resolve(bridge.release(handle)).catch(() => {}) } catch { /* 清理失败不影响交互 */ }
|
|
4336
|
+
},
|
|
4337
|
+
}
|
|
4338
|
+
} catch {
|
|
4339
|
+
// 准备途中任何异常:若桥那边已占用 requestId,尽力取消(仅取消本次准备,非对话)。
|
|
4340
|
+
if (prepared === false && requestId !== '' && typeof bridge.cancel === 'function') {
|
|
4341
|
+
try { void Promise.resolve(bridge.cancel(requestId)).catch(() => {}) } catch { /* noop */ }
|
|
4342
|
+
}
|
|
4343
|
+
return null
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
|
|
3893
4347
|
/**
|
|
3894
4348
|
* 把契约渲染成**人类与模型都能读的草稿正文**。
|
|
3895
4349
|
*
|
|
@@ -5728,7 +6182,7 @@ function serializeFeedback(feedback) {
|
|
|
5728
6182
|
return MEDIA_ROUTE + '?path=' + encodeURIComponent(relPath) + '&v=' + stamp
|
|
5729
6183
|
}
|
|
5730
6184
|
|
|
5731
|
-
function FileCard({ item, t, absPath, onOpenFolder, onPreview, onContextMenu, onDoubleClick }) {
|
|
6185
|
+
function FileCard({ item, t, absPath, onOpenFolder, onPreview, onContextMenu, onDoubleClick, onCopyFile, onWriteDraft }) {
|
|
5732
6186
|
const ext = (item.extension ?? '').replace(/^\./, '').toLowerCase()
|
|
5733
6187
|
const badge = (ext === '' ? 'FILE' : ext).slice(0, 4).toUpperCase()
|
|
5734
6188
|
const [copied, setCopied] = React.useState(false)
|
|
@@ -5741,15 +6195,24 @@ function serializeFeedback(feedback) {
|
|
|
5741
6195
|
|
|
5742
6196
|
const onCopy = async (event) => {
|
|
5743
6197
|
event.stopPropagation()
|
|
5744
|
-
//
|
|
5745
|
-
//
|
|
6198
|
+
// 2026-11-19 老板拍板:这个按钮不再复制「文件名 + 路径 + 遮罩」那段长文本,
|
|
6199
|
+
// 改成真正的「复制文件」—— 写系统剪贴板(CF_HDROP),
|
|
6200
|
+
// 在 WorkBuddy / 微信对话框里 Ctrl+V 能直接粘出文件本身,与右键「复制文件」等价。
|
|
6201
|
+
if (typeof onCopyFile === 'function') {
|
|
6202
|
+
setCopied(await onCopyFile(item.relPath))
|
|
6203
|
+
return
|
|
6204
|
+
}
|
|
6205
|
+
// 兜底(老的调用方没传 onCopyFile):退回结构化文本,功能不丢
|
|
5746
6206
|
const name = dragNameOf(item, absPath)
|
|
5747
|
-
|
|
5748
|
-
setCopied(ok)
|
|
6207
|
+
setCopied(await copyText(name))
|
|
5749
6208
|
}
|
|
5750
|
-
|
|
6209
|
+
// 2026-11-19 老板拍板:这个位置不再开侧栏预览,改成「写进输入框」——
|
|
6210
|
+
// 和双击走同一条链路(writeAssetToComposer:文件名 + 绝对路径 + 主遮罩,只写不发)。
|
|
6211
|
+
// 侧栏预览没丢:点整张卡片 / 按 Enter 仍是它。
|
|
6212
|
+
const onWriteDraftBtn = (event) => {
|
|
5751
6213
|
event.stopPropagation()
|
|
5752
|
-
|
|
6214
|
+
event.preventDefault()
|
|
6215
|
+
if (typeof onWriteDraft === 'function') onWriteDraft(item, event)
|
|
5753
6216
|
}
|
|
5754
6217
|
const onFolder = (event) => {
|
|
5755
6218
|
event.stopPropagation()
|
|
@@ -5790,19 +6253,19 @@ ${absPath}
|
|
|
5790
6253
|
// ② 中部操作行
|
|
5791
6254
|
h('div', { className: 'dg-fcActions', key: 'actions' }, [
|
|
5792
6255
|
h('button', {
|
|
5793
|
-
type: 'button', key: '
|
|
6256
|
+
type: 'button', key: 'draft',
|
|
5794
6257
|
className: 'dg-fcBtn dg-fcBtnPrimary',
|
|
5795
|
-
'data-gallery-
|
|
5796
|
-
title: t('
|
|
5797
|
-
onClick:
|
|
5798
|
-
}, [h('span', { className: 'dg-fcIco', key: 'i' }, '
|
|
6258
|
+
'data-gallery-write-draft': item.relPath,
|
|
6259
|
+
title: t('writeDraftHint'),
|
|
6260
|
+
onClick: onWriteDraftBtn,
|
|
6261
|
+
}, [h('span', { className: 'dg-fcIco', key: 'i' }, '📝'), h('span', { key: 'l' }, t('writeDraft'))]),
|
|
5799
6262
|
h('button', {
|
|
5800
6263
|
type: 'button', key: 'copy',
|
|
5801
6264
|
className: `dg-fcBtn${copied ? ' dg-fcBtnOk' : ''}`,
|
|
5802
6265
|
'data-gallery-copy': item.relPath,
|
|
5803
|
-
title: t('
|
|
6266
|
+
title: t('copyFileHint'),
|
|
5804
6267
|
onClick: onCopy,
|
|
5805
|
-
}, [h('span', { className: 'dg-fcIco', key: 'i' }, copied ? '✓' : '⧉'), h('span', { key: 'l' }, copied ? t('copied') : t('
|
|
6268
|
+
}, [h('span', { className: 'dg-fcIco', key: 'i' }, copied ? '✓' : '⧉'), h('span', { key: 'l' }, copied ? t('copied') : t('copyFile'))]),
|
|
5806
6269
|
h('button', {
|
|
5807
6270
|
type: 'button', key: 'folder',
|
|
5808
6271
|
className: 'dg-fcBtn dg-fcBtnIcon',
|
|
@@ -7643,6 +8106,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7643
8106
|
const [polyNote, setPolyNote] = React.useState('')
|
|
7644
8107
|
const [polyHover, setPolyHover] = React.useState(null)
|
|
7645
8108
|
const [polyDrag, setPolyDrag] = React.useState(null)
|
|
8109
|
+
/** 选区来源:click = 逐点点出来的(画顶点与编号);smear = 右键涂抹按出来的(只画填充与边界)。 */
|
|
8110
|
+
const [polyKind, setPolyKind] = React.useState('click')
|
|
8111
|
+
/** 右键按住的涂抹轨迹。用 ref 存:拖动过程只有 setPoly 触发渲染。 */
|
|
8112
|
+
const smearRef = React.useRef(null)
|
|
7646
8113
|
/** v0.14.7 选区填充色(红 / 绿 / 蓝),同时决定导出的彩色预览图颜色。 */
|
|
7647
8114
|
const [fillColor, setFillColor] = React.useState('green')
|
|
7648
8115
|
/** SVG 无 viewBox,polygon 的 points 只认用户单位 px,不能用百分比。 */
|
|
@@ -7677,6 +8144,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7677
8144
|
setPolyDrag(null)
|
|
7678
8145
|
setPolyNote('')
|
|
7679
8146
|
setPolyMode('mask')
|
|
8147
|
+
setPolyKind('click')
|
|
8148
|
+
smearRef.current = null
|
|
7680
8149
|
}
|
|
7681
8150
|
|
|
7682
8151
|
/**
|
|
@@ -7686,16 +8155,24 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7686
8155
|
* 老板 2026-11-15 拍板:左键圈出来的区域是「给人 / 给助手看的标记」,不是遮罩文件。
|
|
7687
8156
|
*/
|
|
7688
8157
|
const commitPolygon = (points, mode = polyMode) => {
|
|
7689
|
-
|
|
8158
|
+
// 涂抹轨迹可能远超 host 允许的 20 个顶点(http.js 对超限直接回 400),
|
|
8159
|
+
// 统一在这里收敛一次;逐点点选本来就 ≤20,不受影响。
|
|
8160
|
+
const use = points.length > POLYGON_LIMITS.max
|
|
8161
|
+
? polygonSimplifyToLimit(
|
|
8162
|
+
points, POLYGON_LIMITS.max,
|
|
8163
|
+
SMEAR_SIMPLIFY_PX / Math.max(1, Math.min(boxW, boxH)),
|
|
8164
|
+
)
|
|
8165
|
+
: points
|
|
8166
|
+
if (use.length < POLYGON_LIMITS.min) {
|
|
7690
8167
|
setMaskNotice({ kind: 'failed', text: t('polyTooFew') })
|
|
7691
8168
|
return
|
|
7692
8169
|
}
|
|
7693
|
-
if (polygonArea(
|
|
8170
|
+
if (polygonArea(use) < POLYGON_LIMITS.minArea) {
|
|
7694
8171
|
setMaskNotice({ kind: 'failed', text: t('polyDegenerate') })
|
|
7695
8172
|
return
|
|
7696
8173
|
}
|
|
7697
|
-
const box = polygonBBox(
|
|
7698
|
-
const verts =
|
|
8174
|
+
const box = polygonBBox(use)
|
|
8175
|
+
const verts = use.map((p) => [clamp01(p.x), clamp01(p.y)])
|
|
7699
8176
|
resetPoly()
|
|
7700
8177
|
if (mode === 'note') {
|
|
7701
8178
|
const normalized = normalizeAnnotation({
|
|
@@ -7795,6 +8272,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7795
8272
|
|
|
7796
8273
|
/** 逐点采集一个多边形;mode 决定闭合后去哪儿,两套选区互斥、切换时清空旧点。 */
|
|
7797
8274
|
const addPolygonPoint = (p, mode) => {
|
|
8275
|
+
setPolyKind('click')
|
|
7798
8276
|
const switching = polyMode !== mode || poly.length === 0
|
|
7799
8277
|
const cur = switching ? [] : poly
|
|
7800
8278
|
if (switching) {
|
|
@@ -7829,7 +8307,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7829
8307
|
if (p === null) return
|
|
7830
8308
|
clearPending()
|
|
7831
8309
|
dragStartRef.current = null
|
|
7832
|
-
|
|
8310
|
+
// 按下先不落点:松手时才判「原地一下=逐点」还是「拖出去=涂抹」。
|
|
8311
|
+
// 两种选区共用同一个右键入口,谁也不抢谁(老板要逐点保留)。
|
|
8312
|
+
smearRef.current = { start: p, points: [p], moved: false, pointerId: event.pointerId }
|
|
8313
|
+
try { event.currentTarget.setPointerCapture(event.pointerId) } catch { /* 忽略 */ }
|
|
7833
8314
|
return
|
|
7834
8315
|
}
|
|
7835
8316
|
if (event.button !== 0) return
|
|
@@ -7847,6 +8328,34 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7847
8328
|
const onPointerMove = (event) => {
|
|
7848
8329
|
// 中键平移进行中:标注层一律不插手,让查看器独占指针
|
|
7849
8330
|
if (dragging) return
|
|
8331
|
+
// 右键涂抹进行中:整段接管,不走左键那套矩形判定
|
|
8332
|
+
const smear = smearRef.current
|
|
8333
|
+
if (smear !== null) {
|
|
8334
|
+
const p = toNorm(event)
|
|
8335
|
+
if (p === null) return
|
|
8336
|
+
if (!smear.moved) {
|
|
8337
|
+
if (Math.hypot(p.x - smear.start.x, p.y - smear.start.y) < ANNOT_DRAG_THRESHOLD) return
|
|
8338
|
+
smear.moved = true
|
|
8339
|
+
// 涂抹=新选区,没闭合的逐点草稿先撤掉,两种选区不混着画
|
|
8340
|
+
setPoly([])
|
|
8341
|
+
setPolyNote('')
|
|
8342
|
+
setPolyHover(null)
|
|
8343
|
+
setPolyDrag(null)
|
|
8344
|
+
setPolyMode('mask')
|
|
8345
|
+
setPolyKind('smear')
|
|
8346
|
+
setPoly(smear.points.slice())
|
|
8347
|
+
}
|
|
8348
|
+
// 按「显示像素」采样:图片被缩放时归一化阈值要跟着换算,否则小图上点过密
|
|
8349
|
+
const step = SMEAR_SAMPLE_PX / Math.max(1, Math.min(boxW, boxH))
|
|
8350
|
+
const last = smear.points[smear.points.length - 1]
|
|
8351
|
+
if (Math.hypot(p.x - last.x, p.y - last.y) >= step) {
|
|
8352
|
+
smear.points.push(p)
|
|
8353
|
+
setPoly(smear.points.slice())
|
|
8354
|
+
}
|
|
8355
|
+
event.stopPropagation()
|
|
8356
|
+
event.preventDefault()
|
|
8357
|
+
return
|
|
8358
|
+
}
|
|
7850
8359
|
const gesture = dragStartRef.current
|
|
7851
8360
|
// 左键按下还没判定:移动超过阈值才算「拖框」,此刻才建立矩形草稿
|
|
7852
8361
|
if (gesture !== null && !gesture.moved) {
|
|
@@ -7876,8 +8385,45 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7876
8385
|
setDraft((d) => (d === null ? null : { ...d, x1: p.x, y1: p.y }))
|
|
7877
8386
|
}
|
|
7878
8387
|
|
|
8388
|
+
/**
|
|
8389
|
+
* 右键松开:没拖动过 = 老行为落一个顶点;拖过 = 涂抹成一块区域。
|
|
8390
|
+
* 涂抹松手后**不立刻导出**,只把简化后的顶点摆进选区 ——
|
|
8391
|
+
* 面板带着「闭合并生成遮罩 / 清空」出现,老板还有反悔的机会。
|
|
8392
|
+
*/
|
|
8393
|
+
const finishSmear = (event) => {
|
|
8394
|
+
const smear = smearRef.current
|
|
8395
|
+
if (smear === null) return
|
|
8396
|
+
smearRef.current = null
|
|
8397
|
+
try { event.currentTarget.releasePointerCapture(smear.pointerId) } catch { /* 忽略 */ }
|
|
8398
|
+
event.preventDefault()
|
|
8399
|
+
event.stopPropagation()
|
|
8400
|
+
if (!smear.moved) {
|
|
8401
|
+
setPolyKind('click')
|
|
8402
|
+
addPolygonPoint(smear.start, 'mask')
|
|
8403
|
+
return
|
|
8404
|
+
}
|
|
8405
|
+
// 轨迹 → 区域外轮廓:自相交处的内部线段不进选区,只描整体边界。
|
|
8406
|
+
// 面板点数即实际导出顶点数,撤销 / 拖顶点改的也都是外轮廓。
|
|
8407
|
+
const simplified = polygonRegionOutline(smear.points, {
|
|
8408
|
+
maxPoints: POLYGON_LIMITS.max,
|
|
8409
|
+
simplifyEps: SMEAR_SIMPLIFY_PX / Math.max(1, Math.min(boxW, boxH)),
|
|
8410
|
+
})
|
|
8411
|
+
if (simplified.length < POLYGON_LIMITS.min
|
|
8412
|
+
|| polygonArea(simplified) < POLYGON_LIMITS.minArea) {
|
|
8413
|
+
resetPoly()
|
|
8414
|
+
setMaskNotice({ kind: 'failed', text: t('polyDegenerate') })
|
|
8415
|
+
return
|
|
8416
|
+
}
|
|
8417
|
+
setPolyKind('smear')
|
|
8418
|
+
setPolyMode('mask')
|
|
8419
|
+
setPoly(simplified)
|
|
8420
|
+
setPolyHover(null)
|
|
8421
|
+
setPolyDrag(null)
|
|
8422
|
+
}
|
|
8423
|
+
|
|
7879
8424
|
const finishDraft = (event) => {
|
|
7880
8425
|
if (dragging) return
|
|
8426
|
+
if (smearRef.current !== null) { finishSmear(event); return }
|
|
7881
8427
|
const gesture = dragStartRef.current
|
|
7882
8428
|
if (gesture === null) return
|
|
7883
8429
|
dragStartRef.current = null
|
|
@@ -7989,6 +8535,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7989
8535
|
})()
|
|
7990
8536
|
: null
|
|
7991
8537
|
|
|
8538
|
+
/** 涂抹出来的选区只画填充与边界:几十个顶点圆点会糊成一片,反而看不清圈了哪儿。 */
|
|
8539
|
+
const isSmearKind = polyKind === 'smear'
|
|
8540
|
+
|
|
7992
8541
|
/** 多边形预览:实心半透明填充 + 可拖顶点 + 橡皮筋(点回首点即闭合),两种模式共用。 */
|
|
7993
8542
|
const polyShape = poly.length === 0 ? null : (() => {
|
|
7994
8543
|
const toPx = (p) => [p.x * boxW, p.y * boxH]
|
|
@@ -7997,21 +8546,37 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7997
8546
|
const ready = poly.length >= POLYGON_LIMITS.min
|
|
7998
8547
|
// 纯色半透明填充 0.4 / 轮廓 0.7,颜色跟操作条色板联动;主遮罩 alpha 契约不受影响。
|
|
7999
8548
|
const strokeColor = maskFillRgba(fillColor, MASK_STROKE_ALPHA)
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8549
|
+
// 涂抹进行中:只画笔迹本身。此刻 poly 是原始轨迹,按多边形填充会从起点
|
|
8550
|
+
// 拉出一大片三角扇、越涂越乱;松手后 poly 已换成区域外轮廓,走下面的 polygon。
|
|
8551
|
+
const smearing = isSmearKind && smearRef.current !== null
|
|
8552
|
+
const fillNode = smearing
|
|
8553
|
+
? h('polyline', {
|
|
8554
|
+
key: 'polyFill',
|
|
8555
|
+
points: pts.map((q) => `${q[0]},${q[1]}`).join(' '),
|
|
8556
|
+
fill: 'none',
|
|
8557
|
+
stroke: strokeColor,
|
|
8558
|
+
strokeWidth: SMEAR_LIVE_STROKE_PX,
|
|
8559
|
+
strokeLinecap: 'round',
|
|
8560
|
+
strokeLinejoin: 'round',
|
|
8561
|
+
vectorEffect: 'non-scaling-stroke',
|
|
8562
|
+
'data-gallery-poly': String(poly.length),
|
|
8563
|
+
'data-gallery-poly-live': 'smear',
|
|
8564
|
+
})
|
|
8565
|
+
: h('polygon', {
|
|
8566
|
+
key: 'polyFill',
|
|
8567
|
+
points: pts.map((q) => `${q[0]},${q[1]}`).join(' '),
|
|
8568
|
+
fill: maskFillRgba(fillColor, ready ? MASK_FILL_ALPHA : 0.12),
|
|
8569
|
+
stroke: strokeColor, strokeWidth: MASK_STROKE_PX, vectorEffect: 'non-scaling-stroke',
|
|
8570
|
+
strokeDasharray: ready ? undefined : '6 4',
|
|
8571
|
+
'data-gallery-poly': String(poly.length),
|
|
8572
|
+
})
|
|
8573
|
+
const bandNode = tip === null || isSmearKind ? null : h('polyline', {
|
|
8009
8574
|
key: 'polyBand',
|
|
8010
8575
|
points: [pts[pts.length - 1], tip, pts[0]].map((q) => `${q[0]},${q[1]}`).join(' '),
|
|
8011
8576
|
fill: 'none', stroke: strokeColor, strokeWidth: 1.5, strokeDasharray: '5 4',
|
|
8012
8577
|
vectorEffect: 'non-scaling-stroke', opacity: 0.85,
|
|
8013
8578
|
})
|
|
8014
|
-
const dots = pts.map((q, idx) => h('circle', {
|
|
8579
|
+
const dots = isSmearKind ? [] : pts.map((q, idx) => h('circle', {
|
|
8015
8580
|
key: 'v' + idx,
|
|
8016
8581
|
cx: q[0], cy: q[1], r: idx === 0 && ready ? 6 : 4,
|
|
8017
8582
|
fill: idx === 0 ? '#ffd166' : strokeColor, stroke: '#000', strokeWidth: 1,
|
|
@@ -8040,7 +8605,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8040
8605
|
setPolyDrag(null)
|
|
8041
8606
|
},
|
|
8042
8607
|
}))
|
|
8043
|
-
const labels = pts.map((q, idx) => h('text', {
|
|
8608
|
+
const labels = isSmearKind ? [] : pts.map((q, idx) => h('text', {
|
|
8044
8609
|
key: 'n' + idx, x: q[0] + 7, y: q[1] - 7,
|
|
8045
8610
|
fill: '#fff', fontSize: 11, stroke: '#000', strokeWidth: 0.6,
|
|
8046
8611
|
style: { paintOrder: 'stroke', pointerEvents: 'none' },
|
|
@@ -8065,9 +8630,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8065
8630
|
className: 'dg-polyPanel', key: 'polyPanel',
|
|
8066
8631
|
'data-gallery-poly-panel': true,
|
|
8067
8632
|
'data-gallery-poly-mode': polyMode,
|
|
8633
|
+
'data-gallery-poly-kind': polyKind,
|
|
8068
8634
|
...blockViewer,
|
|
8069
8635
|
}, [
|
|
8070
|
-
h('div', { className: 'dg-polyPanelHead', key: 'h' },
|
|
8636
|
+
h('div', { className: 'dg-polyPanelHead', key: 'h' },
|
|
8637
|
+
t(isSmearKind ? 'smearTitle' : (isNoteMode ? 'polyNoteTitle' : 'polyTitle'))),
|
|
8071
8638
|
h('div', { className: 'dg-polyPanelInfo', key: 'i', 'data-gallery-poly-info': true },
|
|
8072
8639
|
format(t('polyInfo'), {
|
|
8073
8640
|
n: String(poly.length), max: String(POLYGON_LIMITS.max),
|
|
@@ -8075,7 +8642,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8075
8642
|
w: Math.round(polyBox.w * 100), h: Math.round(polyBox.h * 100),
|
|
8076
8643
|
area: (polygonArea(poly) * 100).toFixed(2),
|
|
8077
8644
|
})),
|
|
8078
|
-
h('div', { className: 'dg-polyPanelHint', key: 'p' },
|
|
8645
|
+
h('div', { className: 'dg-polyPanelHint', key: 'p' },
|
|
8646
|
+
t(isSmearKind ? 'smearHint' : (isNoteMode ? 'polyNoteHint' : 'polyHint'))),
|
|
8079
8647
|
// 只有「区域标记」模式才给说明框:遮罩导出不需要文字,也别把说明塞进文件名
|
|
8080
8648
|
isNoteMode ? h('div', { className: 'dg-polyPanelNote', key: 'note' },
|
|
8081
8649
|
h('input', {
|
|
@@ -8215,7 +8783,12 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8215
8783
|
onPointerDown,
|
|
8216
8784
|
onPointerMove,
|
|
8217
8785
|
onPointerUp: finishDraft,
|
|
8218
|
-
onPointerCancel: () => {
|
|
8786
|
+
onPointerCancel: () => {
|
|
8787
|
+
setDraft(null)
|
|
8788
|
+
dragStartRef.current = null
|
|
8789
|
+
// 指针被系统取消(拖出窗口 / 触控中断):涂抹轨迹也要清,否则残留半截选区
|
|
8790
|
+
smearRef.current = null
|
|
8791
|
+
},
|
|
8219
8792
|
onClick: active ? (event) => { event.preventDefault(); event.stopPropagation() } : undefined,
|
|
8220
8793
|
onContextMenu: active ? (event) => { event.preventDefault(); event.stopPropagation() } : undefined,
|
|
8221
8794
|
}, [draftShape, polyShape, ...shapes]),
|
|
@@ -9946,7 +10519,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9946
10519
|
const doCopyAssets = React.useCallback(async (relPaths) => {
|
|
9947
10520
|
const paths = [...new Set((Array.isArray(relPaths) ? relPaths : [])
|
|
9948
10521
|
.map((p) => String(p ?? '')).filter((p) => p !== ''))]
|
|
9949
|
-
if (paths.length === 0) return
|
|
10522
|
+
if (paths.length === 0) return false
|
|
9950
10523
|
try {
|
|
9951
10524
|
const payload = await callHost('copyAssets', { paths })
|
|
9952
10525
|
if (payload?.ok !== true) throw new Error(payload?.error?.message ?? 'copyAssets failed')
|
|
@@ -9955,8 +10528,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9955
10528
|
if (Array.isArray(payload?.missed) && payload.missed.length > 0) {
|
|
9956
10529
|
console.warn('dsh-gallery: 复制时跳过了不在扫描根目录内的项', payload.missed)
|
|
9957
10530
|
}
|
|
10531
|
+
return true
|
|
9958
10532
|
} catch (error) {
|
|
9959
10533
|
showPasteNotice('fail', format(t('copyFailed'), { message: String(error?.message ?? error) }))
|
|
10534
|
+
return false
|
|
9960
10535
|
}
|
|
9961
10536
|
}, [callHost, t, showPasteNotice])
|
|
9962
10537
|
|
|
@@ -10680,6 +11255,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10680
11255
|
className: `dg-cardWrap${checked ? ' dg-cardChecked' : ''}${selectMode ? ' dg-cardSelectable' : ''}${isFreshFinal ? ' dg-cardFreshFinal' : ''}`,
|
|
10681
11256
|
'data-gallery-fresh-final': isFreshFinal ? '1' : '0',
|
|
10682
11257
|
key: key + ':wrap',
|
|
11258
|
+
// 三类卡片统一可拖(图片/文件/音视频):捕获阶段 dragstart 据此起原生拖出真文件。
|
|
11259
|
+
draggable: true,
|
|
10683
11260
|
'data-gallery-card-wrap': item.relPath,
|
|
10684
11261
|
'data-gallery-bucket': bucket,
|
|
10685
11262
|
'data-gallery-label-manual': isManual ? '1' : '0',
|
|
@@ -10695,7 +11272,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10695
11272
|
? (event) => {
|
|
10696
11273
|
const target = event.target
|
|
10697
11274
|
if (target !== null && target !== undefined && typeof target.closest === 'function') {
|
|
10698
|
-
if (target.closest('[data-gallery-label-edit],[data-gallery-card-check]') !== null) return
|
|
11275
|
+
if (target.closest('[data-gallery-label-edit],[data-gallery-card-check],[data-gallery-card-copy-file]') !== null) return
|
|
10699
11276
|
}
|
|
10700
11277
|
event.preventDefault()
|
|
10701
11278
|
event.stopPropagation()
|
|
@@ -10704,6 +11281,25 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10704
11281
|
: undefined,
|
|
10705
11282
|
}, [
|
|
10706
11283
|
node,
|
|
11284
|
+
// 图片卡片右上角「复制文件」(2026-11-19 老板要):等价右键菜单那条,
|
|
11285
|
+
// 写系统剪贴板,Ctrl+V 能直接粘出文件;文件卡片另有自己的按钮,故只对图片出。
|
|
11286
|
+
kind === 'image'
|
|
11287
|
+
? h('button', {
|
|
11288
|
+
type: 'button', key: 'copyFile',
|
|
11289
|
+
className: 'dg-labelBtn dg-labelBtnCopy',
|
|
11290
|
+
'data-gallery-card-copy-file': item.relPath,
|
|
11291
|
+
title: t('copyFileHint'),
|
|
11292
|
+
onClick: (e) => {
|
|
11293
|
+
e.stopPropagation(); e.preventDefault()
|
|
11294
|
+
const btn = e.currentTarget
|
|
11295
|
+
void doCopyAssets([item.relPath]).then((ok) => {
|
|
11296
|
+
if (ok !== true || btn === null || btn === undefined) return
|
|
11297
|
+
btn.textContent = '✓'
|
|
11298
|
+
setTimeout(() => { if (btn.isConnected === true) btn.textContent = '⧉' }, 1200)
|
|
11299
|
+
})
|
|
11300
|
+
},
|
|
11301
|
+
}, '⧉')
|
|
11302
|
+
: null,
|
|
10707
11303
|
// 右上「改标签」:手动设定过的用琥珀色区分,hover 时完全显现。
|
|
10708
11304
|
// 不再放独立角标,避免和卡片左上角的阶段角标抢位置。
|
|
10709
11305
|
h('button', {
|
|
@@ -10785,8 +11381,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10785
11381
|
void copyText(abs)
|
|
10786
11382
|
}
|
|
10787
11383
|
},
|
|
10788
|
-
//
|
|
10789
|
-
|
|
11384
|
+
// 2026-11-19:卡面按钮改成「复制文件」(写系统剪贴板),与右键菜单那条一致
|
|
11385
|
+
onCopyFile: (relPath) => doCopyAssets([relPath]),
|
|
11386
|
+
// 另一个按钮从「预览」换成「写进输入框」,与双击同一条链路
|
|
11387
|
+
onWriteDraft: (target, event) => { handleCardDoubleClick(target, event) },
|
|
10790
11388
|
}), item, `${groupKey}:${item.relPath}`)
|
|
10791
11389
|
}
|
|
10792
11390
|
return wrapCard(h(Card, {
|
|
@@ -11024,6 +11622,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11024
11622
|
void copyText(abs)
|
|
11025
11623
|
}
|
|
11026
11624
|
},
|
|
11625
|
+
onCopyFile: (relPath) => doCopyAssets([relPath]),
|
|
11626
|
+
onWriteDraft: (target, event) => { handleCardDoubleClick(target, event) },
|
|
11027
11627
|
})
|
|
11028
11628
|
: h(Card, {
|
|
11029
11629
|
key: item.relPath,
|
|
@@ -11918,10 +12518,65 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11918
12518
|
}
|
|
11919
12519
|
}, 'dsh-gallery: seam')
|
|
11920
12520
|
|
|
11921
|
-
//
|
|
11922
|
-
//
|
|
11923
|
-
//
|
|
12521
|
+
// 拖卡片:① 原生桥可用时拖出真文件到外部应用;② 同时保留旧的
|
|
12522
|
+
// 「文件名+绝对路径+主遮罩写进 File.name」通道,供拖进 DSH 对话给 Agent 定位。
|
|
12523
|
+
// 两条并存:pointerdown 异步准备原生文件,dragstart 同步起拖 + 写 PNG 兜底,
|
|
12524
|
+
// dragend/drop 清理。不改查看器缩放/批注交互、不碰 composer、不自动发送。
|
|
11924
12525
|
ctx.effect(() => {
|
|
12526
|
+
// 当前正在准备 / 已就绪的原生拖放(pointerdown 写入,dragstart 读取,dragend 清理)。
|
|
12527
|
+
// token 防止"按下 A 又按下 B"时旧准备覆盖新卡片。
|
|
12528
|
+
let nativePrep = null
|
|
12529
|
+
let nativeActive = null
|
|
12530
|
+
let prepToken = 0
|
|
12531
|
+
|
|
12532
|
+
const releasePrep = (prep) => {
|
|
12533
|
+
if (prep !== null && typeof prep.release === 'function') {
|
|
12534
|
+
try { prep.release() } catch { /* 清理失败不影响交互 */ }
|
|
12535
|
+
}
|
|
12536
|
+
}
|
|
12537
|
+
// dragend/drop:释放正在拖的那次
|
|
12538
|
+
const releaseNative = () => {
|
|
12539
|
+
releasePrep(nativeActive)
|
|
12540
|
+
nativeActive = null
|
|
12541
|
+
nativePrep = null
|
|
12542
|
+
}
|
|
12543
|
+
// pointerup/pointercancel:单击没拖起来时,释放未被 dragstart 转走的预准备,
|
|
12544
|
+
// 避免每次点卡片都留一个宿主侧临时文件。真正起拖后 nativePrep 已被转走为
|
|
12545
|
+
// nativeActive,且拖放过程中不会派发 pointerup,所以这里不会误伤在拖的文件。
|
|
12546
|
+
const abandonPrep = () => {
|
|
12547
|
+
releasePrep(nativePrep)
|
|
12548
|
+
nativePrep = null
|
|
12549
|
+
// 让还在途中的 prepare 回调 token 失效 → 它自己会 release,不会回填。
|
|
12550
|
+
prepToken += 1
|
|
12551
|
+
}
|
|
12552
|
+
|
|
12553
|
+
// pointerdown(捕获):命中卡片就异步准备真文件。prepare 是异步的,
|
|
12554
|
+
// 必须在 dragstart 之前发出;若用户只是点击没拖,pointerup 会主动释放。
|
|
12555
|
+
const onPointerDown = (event) => {
|
|
12556
|
+
const bridge = nativeDragBridge()
|
|
12557
|
+
if (bridge === null) return
|
|
12558
|
+
const target = event.target
|
|
12559
|
+
if (!(target instanceof Element)) return
|
|
12560
|
+
// 按钮上按下(预览/复制/文件夹等)不走拖拽准备
|
|
12561
|
+
if (target.closest('button,[data-gallery-label-edit]') !== null) return
|
|
12562
|
+
const card = target.closest('[data-gallery-relpath]')
|
|
12563
|
+
if (card === null) return
|
|
12564
|
+
const relPath = String(card.getAttribute('data-gallery-relpath') ?? '')
|
|
12565
|
+
const entry = dragAssetIndex.get(relPath)
|
|
12566
|
+
if (entry === undefined) return
|
|
12567
|
+
const token = ++prepToken
|
|
12568
|
+
nativePrep = null
|
|
12569
|
+
void prepareNativeDrag(relPath, entry.item).then((prep) => {
|
|
12570
|
+
if (token !== prepToken) { // 已被后续 pointerdown 取代
|
|
12571
|
+
if (prep !== null && typeof prep.release === 'function') {
|
|
12572
|
+
try { prep.release() } catch { /* noop */ }
|
|
12573
|
+
}
|
|
12574
|
+
return
|
|
12575
|
+
}
|
|
12576
|
+
nativePrep = prep
|
|
12577
|
+
})
|
|
12578
|
+
}
|
|
12579
|
+
|
|
11925
12580
|
const onDragStart = (event) => {
|
|
11926
12581
|
const dt = event.dataTransfer
|
|
11927
12582
|
const target = event.target
|
|
@@ -11939,20 +12594,23 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11939
12594
|
? { ...entry.item, maskOf: { ...linked, linkedMask: true } }
|
|
11940
12595
|
: entry.item
|
|
11941
12596
|
const name = dragNameOf(item, entry.absPath)
|
|
11942
|
-
// 自证 + 兜底双用途:无论 File 替换是否成功,都把同一串信息写进剪贴板。
|
|
11943
|
-
// 拖完在输入框 Ctrl+V 能粘出「产出台·…」= 新代码确实执行过、dragstart 命中;
|
|
11944
|
-
// 粘不出 = 面板仍加载旧模块,需重载窗口。编码 / 写入失败时它就是唯一可用通道。
|
|
11945
12597
|
void copyText(name)
|
|
11946
|
-
|
|
11947
|
-
//
|
|
12598
|
+
|
|
12599
|
+
// ① 原生真文件拖出:准备已就绪且属于本卡片 → 同步 start。
|
|
12600
|
+
// start 必须在 dragstart 同步栈里调用, Electron 才认这次拖放。
|
|
12601
|
+
if (nativePrep !== null && nativePrep.relPath === relPath) {
|
|
12602
|
+
nativeActive = nativePrep
|
|
12603
|
+
nativePrep = null
|
|
12604
|
+
try { nativeActive.start() } catch { /* start 内部已兜底 */ }
|
|
12605
|
+
}
|
|
12606
|
+
|
|
12607
|
+
// ② 旧的 PNG+路径通道照写(拖进 DSH 对话给 Agent 定位;也是原生失败时的兜底)。
|
|
12608
|
+
// 从 Viewer「拖到对话」按钮拖出时取预览大图,否则用卡片自己的缩略图。
|
|
11948
12609
|
const img = card.hasAttribute('data-gallery-dragviewer')
|
|
11949
12610
|
? document.querySelector('.dg-viewerBody img')
|
|
11950
12611
|
: (target.matches('img') ? target : target.querySelector('img'))
|
|
11951
12612
|
const bytes = syncImagePngBytes(img)
|
|
11952
|
-
if (bytes === null)
|
|
11953
|
-
// 编码失败:保留浏览器原生拖图,信息已在剪贴板供手动粘贴
|
|
11954
|
-
return
|
|
11955
|
-
}
|
|
12613
|
+
if (bytes === null) return
|
|
11956
12614
|
try {
|
|
11957
12615
|
dt.clearData()
|
|
11958
12616
|
dt.effectAllowed = 'copy'
|
|
@@ -11961,8 +12619,23 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11961
12619
|
console.warn('dsh-gallery: 拖图元信息写入失败,信息已在剪贴板', error)
|
|
11962
12620
|
}
|
|
11963
12621
|
}
|
|
12622
|
+
|
|
12623
|
+
document.addEventListener('pointerdown', onPointerDown, true)
|
|
12624
|
+
document.addEventListener('pointerup', abandonPrep, true)
|
|
12625
|
+
document.addEventListener('pointercancel', abandonPrep, true)
|
|
11964
12626
|
document.addEventListener('dragstart', onDragStart, true)
|
|
11965
|
-
|
|
12627
|
+
document.addEventListener('dragend', releaseNative, true)
|
|
12628
|
+
window.addEventListener('drop', releaseNative, true)
|
|
12629
|
+
return () => {
|
|
12630
|
+
releaseNative()
|
|
12631
|
+
abandonPrep()
|
|
12632
|
+
document.removeEventListener('pointerdown', onPointerDown, true)
|
|
12633
|
+
document.removeEventListener('pointerup', abandonPrep, true)
|
|
12634
|
+
document.removeEventListener('pointercancel', abandonPrep, true)
|
|
12635
|
+
document.removeEventListener('dragstart', onDragStart, true)
|
|
12636
|
+
document.removeEventListener('dragend', releaseNative, true)
|
|
12637
|
+
window.removeEventListener('drop', releaseNative, true)
|
|
12638
|
+
}
|
|
11966
12639
|
}, 'dsh-gallery: drag asset metadata')
|
|
11967
12640
|
|
|
11968
12641
|
ctx.effect(() => {
|