dsh-gallery 1.2.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 +148 -0
- package/README.md +65 -20
- package/client.js +919 -61
- 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 +12 -3
- package/host/labels.js +3 -5
- package/host/marks.js +2 -5
- package/host/tools.js +128 -3
- 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 {
|
|
@@ -3045,6 +3386,18 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3045
3386
|
}
|
|
3046
3387
|
.dg-feedback .dg-btnSmall { padding: 3px 9px; font-size: 11px; }
|
|
3047
3388
|
|
|
3389
|
+
/* v1.3.0:Agent 批示区块(独立于表态/批注序号,不进草稿) */
|
|
3390
|
+
.dg-replyBlock { border: 1px solid #00e676; border-radius: 8px; padding: 8px; margin: 8px 0; background: rgba(0, 230, 118, 0.06); }
|
|
3391
|
+
.dg-replyHead { color: #00e676; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
|
|
3392
|
+
.dg-replyList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
|
|
3393
|
+
.dg-replyItem { border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 6px; padding: 7px 8px; background: #222831; }
|
|
3394
|
+
.dg-replyText { color: #e8eaed; font-size: 12px; line-height: 1.5; margin-bottom: 4px; word-break: break-word; }
|
|
3395
|
+
.dg-replyMeta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: #a9b1bd; margin-bottom: 6px; }
|
|
3396
|
+
.dg-replyName { color: #cdd4de; }
|
|
3397
|
+
.dg-replyOps { display: flex; gap: 6px; justify-content: flex-end; }
|
|
3398
|
+
.dg-feedback .dg-replyApprove { background: #1d7a4d; color: #ffffff; border-color: #1d7a4d; }
|
|
3399
|
+
.dg-feedback .dg-replyApprove:hover:not(:disabled) { background: #249a60; border-color: #249a60; }
|
|
3400
|
+
|
|
3048
3401
|
.dg-feedbackActions {
|
|
3049
3402
|
display: flex; justify-content: flex-end; gap: 8px;
|
|
3050
3403
|
padding: 10px 14px; border-top: 1px solid rgba(255, 255, 255, 0.10);
|
|
@@ -3106,6 +3459,14 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3106
3459
|
|
|
3107
3460
|
/* 卡片包装层 + 确认角标 + 多选框 */
|
|
3108
3461
|
.dg-cardWrap { position: relative; }
|
|
3462
|
+
/* v1.3.0:这批刚产出的终稿高亮(上限 3 张)。用外发光+角标,不动 ::after border(避免和选中态打架)。 */
|
|
3463
|
+
.dg-cardWrap.dg-cardFreshFinal { box-shadow: 0 0 0 2px #00e676, 0 0 12px rgba(0, 230, 118, 0.35); border-radius: 6px; }
|
|
3464
|
+
.dg-cardWrap.dg-cardFreshFinal::before {
|
|
3465
|
+
content: '新';
|
|
3466
|
+
position: absolute; top: 4px; right: 4px; z-index: 7;
|
|
3467
|
+
background: #00e676; color: #04220f; font-size: 11px; font-weight: 600;
|
|
3468
|
+
padding: 0 6px; border-radius: 8px; line-height: 16px;
|
|
3469
|
+
}
|
|
3109
3470
|
/* 结论角标(左上):人的表态,优先于右上角的机器预判角标 */
|
|
3110
3471
|
.dg-verdictBadge {
|
|
3111
3472
|
position: absolute; top: 6px; left: 6px; z-index: 5;
|
|
@@ -3870,6 +4231,119 @@ function syncImagePngBytes(img) {
|
|
|
3870
4231
|
}
|
|
3871
4232
|
}
|
|
3872
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
|
+
|
|
3873
4347
|
/**
|
|
3874
4348
|
* 把契约渲染成**人类与模型都能读的草稿正文**。
|
|
3875
4349
|
*
|
|
@@ -4331,7 +4805,8 @@ function serializeFeedback(feedback) {
|
|
|
4331
4805
|
*/
|
|
4332
4806
|
function FeedbackBasket({ t, items, currentSessionId, targetSessionTitle,
|
|
4333
4807
|
onClose, onRemove, onEdit, onClear, onEditSave,
|
|
4334
|
-
onRemoveAnnotation, onClearAll, onAck
|
|
4808
|
+
onRemoveAnnotation, onClearAll, onAck,
|
|
4809
|
+
onAckReply, onRejectReply }) {
|
|
4335
4810
|
// 语言判断:用 t 探测一个已知键 —— 命中中文就按 zh 渲染,否则 en。
|
|
4336
4811
|
// (不引入 detectLocale,插件没有这个工具函数)
|
|
4337
4812
|
const [locale] = React.useState(() => {
|
|
@@ -4350,6 +4825,8 @@ function serializeFeedback(feedback) {
|
|
|
4350
4825
|
const rows = React.useMemo(() => {
|
|
4351
4826
|
const out = []
|
|
4352
4827
|
for (const it of Array.isArray(items) ? items : []) {
|
|
4828
|
+
// v1.3.0:Agent 批示单独渲染在列表顶部,不进 Annotation N 序号、不进草稿
|
|
4829
|
+
if (it.reply !== undefined && it.reply !== null) continue
|
|
4353
4830
|
if (it.mark !== undefined && it.mark !== null) out.push({ kind: 'mark', it })
|
|
4354
4831
|
const annots = Array.isArray(it.annotations) ? it.annotations : []
|
|
4355
4832
|
for (const a of annots) out.push({ kind: 'annot', it, a })
|
|
@@ -4357,6 +4834,11 @@ function serializeFeedback(feedback) {
|
|
|
4357
4834
|
return out
|
|
4358
4835
|
}, [items])
|
|
4359
4836
|
const annotCount = rows.filter((r) => r.kind === 'annot').length
|
|
4837
|
+
// v1.3.0:Agent 批示条目(单独区块,独立于表态/批注序号)
|
|
4838
|
+
const replyRows = React.useMemo(
|
|
4839
|
+
() => (Array.isArray(items) ? items : []).filter((it) => it.reply !== undefined && it.reply !== null),
|
|
4840
|
+
[items],
|
|
4841
|
+
)
|
|
4360
4842
|
// 编辑弹窗:正在编辑的条目 + 三个字段的草稿值
|
|
4361
4843
|
const [editing, setEditing] = React.useState(null)
|
|
4362
4844
|
const [editReason, setEditReason] = React.useState('')
|
|
@@ -4421,7 +4903,11 @@ function serializeFeedback(feedback) {
|
|
|
4421
4903
|
*/
|
|
4422
4904
|
if (typeof onAck === 'function') {
|
|
4423
4905
|
try {
|
|
4424
|
-
|
|
4906
|
+
// v1.3.0:Agent 批示不随普通草稿被清 —— 它有自己的核准/驳回入口
|
|
4907
|
+
const humanPaths = items
|
|
4908
|
+
.filter((it) => it.reply === undefined || it.reply === null)
|
|
4909
|
+
.map((it) => it.relPath)
|
|
4910
|
+
await onAck(humanPaths)
|
|
4425
4911
|
} catch { /* ack 失败不影响草稿已经写进去这个事实 */ }
|
|
4426
4912
|
}
|
|
4427
4913
|
} else {
|
|
@@ -4471,6 +4957,48 @@ function serializeFeedback(feedback) {
|
|
|
4471
4957
|
format(t('feedbackAnnotHint'), { n: annotCount }))
|
|
4472
4958
|
: null,
|
|
4473
4959
|
|
|
4960
|
+
// v1.3.0:Agent 批示区块(独立于下面的表态/批注序号,不进草稿)
|
|
4961
|
+
// 每条批示 = Agent 改完图后的回报,人在这里核准或驳回;驳回会带着意见再回去。
|
|
4962
|
+
replyRows.length > 0
|
|
4963
|
+
? h('div', { className: 'dg-replyBlock', key: 'replies', 'data-gallery-agent-replies': replyRows.length }, [
|
|
4964
|
+
h('div', { className: 'dg-replyHead', key: 'h' },
|
|
4965
|
+
locale === 'en' ? 'Agent replies · pending your approval' : 'Agent 批示 · 待您核准'),
|
|
4966
|
+
h('ul', { className: 'dg-replyList', key: 'l' },
|
|
4967
|
+
replyRows.map((it) => {
|
|
4968
|
+
const r = it.reply
|
|
4969
|
+
const fileName = it.relPath.split('/').pop() ?? it.relPath
|
|
4970
|
+
return h('li', {
|
|
4971
|
+
className: 'dg-replyItem',
|
|
4972
|
+
key: 'reply:' + it.relPath,
|
|
4973
|
+
'data-gallery-reply-item': it.relPath,
|
|
4974
|
+
}, [
|
|
4975
|
+
h('div', { className: 'dg-replyText', key: 'text' },
|
|
4976
|
+
(locale === 'en' ? 'Agent: ' : 'Agent:') + String(r.text ?? '')),
|
|
4977
|
+
h('div', { className: 'dg-replyMeta', key: 'meta' }, [
|
|
4978
|
+
h('span', { className: 'dg-replyName', key: 'name', title: it.relPath }, fileName),
|
|
4979
|
+
r.replyOf
|
|
4980
|
+
? h('span', { className: 'dg-feedbackDim', key: 'of' },
|
|
4981
|
+
(locale === 'en' ? 're: ' : '回应:') + (r.replyOf.split('/').pop() ?? r.replyOf))
|
|
4982
|
+
: null,
|
|
4983
|
+
]),
|
|
4984
|
+
h('div', { className: 'dg-replyOps', key: 'ops' }, [
|
|
4985
|
+
h('button', {
|
|
4986
|
+
type: 'button', className: 'dg-btn dg-btnSmall dg-replyApprove', key: 'ok',
|
|
4987
|
+
'data-gallery-reply-approve': it.relPath,
|
|
4988
|
+
onClick: () => { if (typeof onAckReply === 'function') onAckReply(it.relPath) },
|
|
4989
|
+
}, locale === 'en' ? 'Approve' : '核准'),
|
|
4990
|
+
h('button', {
|
|
4991
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'no',
|
|
4992
|
+
'data-gallery-reply-reject': it.relPath,
|
|
4993
|
+
onClick: () => { if (typeof onRejectReply === 'function') onRejectReply(it.relPath) },
|
|
4994
|
+
}, locale === 'en' ? 'Reject' : '驳回'),
|
|
4995
|
+
]),
|
|
4996
|
+
])
|
|
4997
|
+
})
|
|
4998
|
+
),
|
|
4999
|
+
])
|
|
5000
|
+
: null,
|
|
5001
|
+
|
|
4474
5002
|
rows.length === 0
|
|
4475
5003
|
? h('p', { className: 'dg-status', key: 'empty' }, t('feedbackBasketEmpty'))
|
|
4476
5004
|
: h('ul', { className: 'dg-feedbackList', key: 'list' },
|
|
@@ -5654,7 +6182,7 @@ function serializeFeedback(feedback) {
|
|
|
5654
6182
|
return MEDIA_ROUTE + '?path=' + encodeURIComponent(relPath) + '&v=' + stamp
|
|
5655
6183
|
}
|
|
5656
6184
|
|
|
5657
|
-
function FileCard({ item, t, absPath, onOpenFolder, onPreview, onContextMenu, onDoubleClick }) {
|
|
6185
|
+
function FileCard({ item, t, absPath, onOpenFolder, onPreview, onContextMenu, onDoubleClick, onCopyFile, onWriteDraft }) {
|
|
5658
6186
|
const ext = (item.extension ?? '').replace(/^\./, '').toLowerCase()
|
|
5659
6187
|
const badge = (ext === '' ? 'FILE' : ext).slice(0, 4).toUpperCase()
|
|
5660
6188
|
const [copied, setCopied] = React.useState(false)
|
|
@@ -5667,15 +6195,24 @@ function serializeFeedback(feedback) {
|
|
|
5667
6195
|
|
|
5668
6196
|
const onCopy = async (event) => {
|
|
5669
6197
|
event.stopPropagation()
|
|
5670
|
-
//
|
|
5671
|
-
//
|
|
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):退回结构化文本,功能不丢
|
|
5672
6206
|
const name = dragNameOf(item, absPath)
|
|
5673
|
-
|
|
5674
|
-
setCopied(ok)
|
|
6207
|
+
setCopied(await copyText(name))
|
|
5675
6208
|
}
|
|
5676
|
-
|
|
6209
|
+
// 2026-11-19 老板拍板:这个位置不再开侧栏预览,改成「写进输入框」——
|
|
6210
|
+
// 和双击走同一条链路(writeAssetToComposer:文件名 + 绝对路径 + 主遮罩,只写不发)。
|
|
6211
|
+
// 侧栏预览没丢:点整张卡片 / 按 Enter 仍是它。
|
|
6212
|
+
const onWriteDraftBtn = (event) => {
|
|
5677
6213
|
event.stopPropagation()
|
|
5678
|
-
|
|
6214
|
+
event.preventDefault()
|
|
6215
|
+
if (typeof onWriteDraft === 'function') onWriteDraft(item, event)
|
|
5679
6216
|
}
|
|
5680
6217
|
const onFolder = (event) => {
|
|
5681
6218
|
event.stopPropagation()
|
|
@@ -5716,19 +6253,19 @@ ${absPath}
|
|
|
5716
6253
|
// ② 中部操作行
|
|
5717
6254
|
h('div', { className: 'dg-fcActions', key: 'actions' }, [
|
|
5718
6255
|
h('button', {
|
|
5719
|
-
type: 'button', key: '
|
|
6256
|
+
type: 'button', key: 'draft',
|
|
5720
6257
|
className: 'dg-fcBtn dg-fcBtnPrimary',
|
|
5721
|
-
'data-gallery-
|
|
5722
|
-
title: t('
|
|
5723
|
-
onClick:
|
|
5724
|
-
}, [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'))]),
|
|
5725
6262
|
h('button', {
|
|
5726
6263
|
type: 'button', key: 'copy',
|
|
5727
6264
|
className: `dg-fcBtn${copied ? ' dg-fcBtnOk' : ''}`,
|
|
5728
6265
|
'data-gallery-copy': item.relPath,
|
|
5729
|
-
title: t('
|
|
6266
|
+
title: t('copyFileHint'),
|
|
5730
6267
|
onClick: onCopy,
|
|
5731
|
-
}, [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'))]),
|
|
5732
6269
|
h('button', {
|
|
5733
6270
|
type: 'button', key: 'folder',
|
|
5734
6271
|
className: 'dg-fcBtn dg-fcBtnIcon',
|
|
@@ -7569,6 +8106,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7569
8106
|
const [polyNote, setPolyNote] = React.useState('')
|
|
7570
8107
|
const [polyHover, setPolyHover] = React.useState(null)
|
|
7571
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)
|
|
7572
8113
|
/** v0.14.7 选区填充色(红 / 绿 / 蓝),同时决定导出的彩色预览图颜色。 */
|
|
7573
8114
|
const [fillColor, setFillColor] = React.useState('green')
|
|
7574
8115
|
/** SVG 无 viewBox,polygon 的 points 只认用户单位 px,不能用百分比。 */
|
|
@@ -7603,6 +8144,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7603
8144
|
setPolyDrag(null)
|
|
7604
8145
|
setPolyNote('')
|
|
7605
8146
|
setPolyMode('mask')
|
|
8147
|
+
setPolyKind('click')
|
|
8148
|
+
smearRef.current = null
|
|
7606
8149
|
}
|
|
7607
8150
|
|
|
7608
8151
|
/**
|
|
@@ -7612,16 +8155,24 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7612
8155
|
* 老板 2026-11-15 拍板:左键圈出来的区域是「给人 / 给助手看的标记」,不是遮罩文件。
|
|
7613
8156
|
*/
|
|
7614
8157
|
const commitPolygon = (points, mode = polyMode) => {
|
|
7615
|
-
|
|
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) {
|
|
7616
8167
|
setMaskNotice({ kind: 'failed', text: t('polyTooFew') })
|
|
7617
8168
|
return
|
|
7618
8169
|
}
|
|
7619
|
-
if (polygonArea(
|
|
8170
|
+
if (polygonArea(use) < POLYGON_LIMITS.minArea) {
|
|
7620
8171
|
setMaskNotice({ kind: 'failed', text: t('polyDegenerate') })
|
|
7621
8172
|
return
|
|
7622
8173
|
}
|
|
7623
|
-
const box = polygonBBox(
|
|
7624
|
-
const verts =
|
|
8174
|
+
const box = polygonBBox(use)
|
|
8175
|
+
const verts = use.map((p) => [clamp01(p.x), clamp01(p.y)])
|
|
7625
8176
|
resetPoly()
|
|
7626
8177
|
if (mode === 'note') {
|
|
7627
8178
|
const normalized = normalizeAnnotation({
|
|
@@ -7721,6 +8272,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7721
8272
|
|
|
7722
8273
|
/** 逐点采集一个多边形;mode 决定闭合后去哪儿,两套选区互斥、切换时清空旧点。 */
|
|
7723
8274
|
const addPolygonPoint = (p, mode) => {
|
|
8275
|
+
setPolyKind('click')
|
|
7724
8276
|
const switching = polyMode !== mode || poly.length === 0
|
|
7725
8277
|
const cur = switching ? [] : poly
|
|
7726
8278
|
if (switching) {
|
|
@@ -7755,7 +8307,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7755
8307
|
if (p === null) return
|
|
7756
8308
|
clearPending()
|
|
7757
8309
|
dragStartRef.current = null
|
|
7758
|
-
|
|
8310
|
+
// 按下先不落点:松手时才判「原地一下=逐点」还是「拖出去=涂抹」。
|
|
8311
|
+
// 两种选区共用同一个右键入口,谁也不抢谁(老板要逐点保留)。
|
|
8312
|
+
smearRef.current = { start: p, points: [p], moved: false, pointerId: event.pointerId }
|
|
8313
|
+
try { event.currentTarget.setPointerCapture(event.pointerId) } catch { /* 忽略 */ }
|
|
7759
8314
|
return
|
|
7760
8315
|
}
|
|
7761
8316
|
if (event.button !== 0) return
|
|
@@ -7773,6 +8328,34 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7773
8328
|
const onPointerMove = (event) => {
|
|
7774
8329
|
// 中键平移进行中:标注层一律不插手,让查看器独占指针
|
|
7775
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
|
+
}
|
|
7776
8359
|
const gesture = dragStartRef.current
|
|
7777
8360
|
// 左键按下还没判定:移动超过阈值才算「拖框」,此刻才建立矩形草稿
|
|
7778
8361
|
if (gesture !== null && !gesture.moved) {
|
|
@@ -7802,8 +8385,45 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7802
8385
|
setDraft((d) => (d === null ? null : { ...d, x1: p.x, y1: p.y }))
|
|
7803
8386
|
}
|
|
7804
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
|
+
|
|
7805
8424
|
const finishDraft = (event) => {
|
|
7806
8425
|
if (dragging) return
|
|
8426
|
+
if (smearRef.current !== null) { finishSmear(event); return }
|
|
7807
8427
|
const gesture = dragStartRef.current
|
|
7808
8428
|
if (gesture === null) return
|
|
7809
8429
|
dragStartRef.current = null
|
|
@@ -7915,6 +8535,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7915
8535
|
})()
|
|
7916
8536
|
: null
|
|
7917
8537
|
|
|
8538
|
+
/** 涂抹出来的选区只画填充与边界:几十个顶点圆点会糊成一片,反而看不清圈了哪儿。 */
|
|
8539
|
+
const isSmearKind = polyKind === 'smear'
|
|
8540
|
+
|
|
7918
8541
|
/** 多边形预览:实心半透明填充 + 可拖顶点 + 橡皮筋(点回首点即闭合),两种模式共用。 */
|
|
7919
8542
|
const polyShape = poly.length === 0 ? null : (() => {
|
|
7920
8543
|
const toPx = (p) => [p.x * boxW, p.y * boxH]
|
|
@@ -7923,21 +8546,37 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7923
8546
|
const ready = poly.length >= POLYGON_LIMITS.min
|
|
7924
8547
|
// 纯色半透明填充 0.4 / 轮廓 0.7,颜色跟操作条色板联动;主遮罩 alpha 契约不受影响。
|
|
7925
8548
|
const strokeColor = maskFillRgba(fillColor, MASK_STROKE_ALPHA)
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
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', {
|
|
7935
8574
|
key: 'polyBand',
|
|
7936
8575
|
points: [pts[pts.length - 1], tip, pts[0]].map((q) => `${q[0]},${q[1]}`).join(' '),
|
|
7937
8576
|
fill: 'none', stroke: strokeColor, strokeWidth: 1.5, strokeDasharray: '5 4',
|
|
7938
8577
|
vectorEffect: 'non-scaling-stroke', opacity: 0.85,
|
|
7939
8578
|
})
|
|
7940
|
-
const dots = pts.map((q, idx) => h('circle', {
|
|
8579
|
+
const dots = isSmearKind ? [] : pts.map((q, idx) => h('circle', {
|
|
7941
8580
|
key: 'v' + idx,
|
|
7942
8581
|
cx: q[0], cy: q[1], r: idx === 0 && ready ? 6 : 4,
|
|
7943
8582
|
fill: idx === 0 ? '#ffd166' : strokeColor, stroke: '#000', strokeWidth: 1,
|
|
@@ -7966,7 +8605,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7966
8605
|
setPolyDrag(null)
|
|
7967
8606
|
},
|
|
7968
8607
|
}))
|
|
7969
|
-
const labels = pts.map((q, idx) => h('text', {
|
|
8608
|
+
const labels = isSmearKind ? [] : pts.map((q, idx) => h('text', {
|
|
7970
8609
|
key: 'n' + idx, x: q[0] + 7, y: q[1] - 7,
|
|
7971
8610
|
fill: '#fff', fontSize: 11, stroke: '#000', strokeWidth: 0.6,
|
|
7972
8611
|
style: { paintOrder: 'stroke', pointerEvents: 'none' },
|
|
@@ -7991,9 +8630,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7991
8630
|
className: 'dg-polyPanel', key: 'polyPanel',
|
|
7992
8631
|
'data-gallery-poly-panel': true,
|
|
7993
8632
|
'data-gallery-poly-mode': polyMode,
|
|
8633
|
+
'data-gallery-poly-kind': polyKind,
|
|
7994
8634
|
...blockViewer,
|
|
7995
8635
|
}, [
|
|
7996
|
-
h('div', { className: 'dg-polyPanelHead', key: 'h' },
|
|
8636
|
+
h('div', { className: 'dg-polyPanelHead', key: 'h' },
|
|
8637
|
+
t(isSmearKind ? 'smearTitle' : (isNoteMode ? 'polyNoteTitle' : 'polyTitle'))),
|
|
7997
8638
|
h('div', { className: 'dg-polyPanelInfo', key: 'i', 'data-gallery-poly-info': true },
|
|
7998
8639
|
format(t('polyInfo'), {
|
|
7999
8640
|
n: String(poly.length), max: String(POLYGON_LIMITS.max),
|
|
@@ -8001,7 +8642,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8001
8642
|
w: Math.round(polyBox.w * 100), h: Math.round(polyBox.h * 100),
|
|
8002
8643
|
area: (polygonArea(poly) * 100).toFixed(2),
|
|
8003
8644
|
})),
|
|
8004
|
-
h('div', { className: 'dg-polyPanelHint', key: 'p' },
|
|
8645
|
+
h('div', { className: 'dg-polyPanelHint', key: 'p' },
|
|
8646
|
+
t(isSmearKind ? 'smearHint' : (isNoteMode ? 'polyNoteHint' : 'polyHint'))),
|
|
8005
8647
|
// 只有「区域标记」模式才给说明框:遮罩导出不需要文字,也别把说明塞进文件名
|
|
8006
8648
|
isNoteMode ? h('div', { className: 'dg-polyPanelNote', key: 'note' },
|
|
8007
8649
|
h('input', {
|
|
@@ -8141,7 +8783,12 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8141
8783
|
onPointerDown,
|
|
8142
8784
|
onPointerMove,
|
|
8143
8785
|
onPointerUp: finishDraft,
|
|
8144
|
-
onPointerCancel: () => {
|
|
8786
|
+
onPointerCancel: () => {
|
|
8787
|
+
setDraft(null)
|
|
8788
|
+
dragStartRef.current = null
|
|
8789
|
+
// 指针被系统取消(拖出窗口 / 触控中断):涂抹轨迹也要清,否则残留半截选区
|
|
8790
|
+
smearRef.current = null
|
|
8791
|
+
},
|
|
8145
8792
|
onClick: active ? (event) => { event.preventDefault(); event.stopPropagation() } : undefined,
|
|
8146
8793
|
onContextMenu: active ? (event) => { event.preventDefault(); event.stopPropagation() } : undefined,
|
|
8147
8794
|
}, [draftShape, polyShape, ...shapes]),
|
|
@@ -8956,6 +9603,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8956
9603
|
* 两者混同就会重演「删一条反馈把定好的标签也撤了」的错。
|
|
8957
9604
|
*/
|
|
8958
9605
|
const [pendingCount, setPendingCount] = React.useState(0)
|
|
9606
|
+
// v1.3.0:Agent 批示(gallery_reply 写进 feedback.json,kind='agent-reply')。
|
|
9607
|
+
// 每项 = { relPath, text, replyOf, markedAt };只在反馈栏显示,不进草稿、不自动清。
|
|
9608
|
+
const [agentReplies, setAgentReplies] = React.useState({})
|
|
8959
9609
|
// 编辑中的条目(null 表示不编辑)
|
|
8960
9610
|
const [editingItem, setEditingItem] = React.useState(null)
|
|
8961
9611
|
// 网格滚动位置:打开查看器前记录,关闭后恢复,让视图停在原缩略图处
|
|
@@ -8978,13 +9628,32 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8978
9628
|
})
|
|
8979
9629
|
.catch((error) => console.warn('dsh-gallery: getLabels 失败', error))
|
|
8980
9630
|
// v0.16.4 · B 档:台面打开时读一次待处理条数(纯读,不标记已读)
|
|
8981
|
-
|
|
8982
|
-
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
}
|
|
9631
|
+
// v1.3.0:顺带提取 Agent 批示(kind='agent-reply')供反馈栏显示
|
|
9632
|
+
const applyPending = (payload) => {
|
|
9633
|
+
if (!alive || payload?.ok === false) return
|
|
9634
|
+
setPendingCount(Number.isFinite(payload?.count) ? payload.count : 0)
|
|
9635
|
+
const replies = {}
|
|
9636
|
+
for (const it of (Array.isArray(payload?.items) ? payload.items : [])) {
|
|
9637
|
+
if (String(it?.kind ?? '') !== 'agent-reply') continue
|
|
9638
|
+
const rel = String(it?.relPath ?? '')
|
|
9639
|
+
if (rel === '') continue
|
|
9640
|
+
replies[rel] = {
|
|
9641
|
+
relPath: rel,
|
|
9642
|
+
text: String(it?.replyText ?? ''),
|
|
9643
|
+
replyOf: String(it?.replyOf ?? ''),
|
|
9644
|
+
markedAt: Number(it?.markedAt) || 0,
|
|
9645
|
+
}
|
|
9646
|
+
}
|
|
9647
|
+
setAgentReplies(replies)
|
|
9648
|
+
}
|
|
9649
|
+
callHost('getPendingFeedback', {}).then(applyPending)
|
|
8986
9650
|
.catch((error) => console.warn('dsh-gallery: getPendingFeedback 失败', error))
|
|
8987
|
-
|
|
9651
|
+
// v1.3.0:Agent 是另一个进程,改完图写批示时台面可能一直开着 —— 低频轮询让批示自己出现。
|
|
9652
|
+
// 只读、不清零;人核准走显式 ackFeedback。
|
|
9653
|
+
const replyTimer = setInterval(() => {
|
|
9654
|
+
callHost('getPendingFeedback', {}).then(applyPending).catch(() => {})
|
|
9655
|
+
}, 5000)
|
|
9656
|
+
return () => { alive = false; clearInterval(replyTimer) }
|
|
8988
9657
|
}, [])
|
|
8989
9658
|
|
|
8990
9659
|
/** 手动标签覆写:只读独立 labels 文件,与反馈篮条目互不影响。 */
|
|
@@ -9096,6 +9765,49 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9096
9765
|
}
|
|
9097
9766
|
}, [])
|
|
9098
9767
|
|
|
9768
|
+
/**
|
|
9769
|
+
* v1.3.0:核准 Agent 批示 —— 清掉该条批示,本地 state 同步移除。
|
|
9770
|
+
* 只 ack 这一条批示,不碰同图的人写反馈(setFeedback 按 relPath 存,同 path 只有一条,
|
|
9771
|
+
* 这里 ack 后若人还有意见会重新写;批示与人意见同 path 时本就以最新为准)。
|
|
9772
|
+
*/
|
|
9773
|
+
const ackAgentReply = React.useCallback(async (relPath) => {
|
|
9774
|
+
await ackPending([relPath])
|
|
9775
|
+
setAgentReplies((prev) => {
|
|
9776
|
+
if (!(relPath in prev)) return prev
|
|
9777
|
+
const next = { ...prev }
|
|
9778
|
+
delete next[relPath]
|
|
9779
|
+
return next
|
|
9780
|
+
})
|
|
9781
|
+
}, [ackPending])
|
|
9782
|
+
|
|
9783
|
+
/**
|
|
9784
|
+
* v1.3.0:驳回 Agent 批示 —— 先清批示,再把该图标成「交付不合格」让人补一句意见,
|
|
9785
|
+
* 这样 Agent 下次取回的就是人的驳回意见,而不是那条已完成的批示。全程不发送。
|
|
9786
|
+
*/
|
|
9787
|
+
const rejectAgentReply = React.useCallback(async (relPath) => {
|
|
9788
|
+
const reply = agentReplies[relPath]
|
|
9789
|
+
// 先清批示,再写人的驳回表态 —— 顺序不能反,否则 recordPendingFeedback 会把批示覆盖掉
|
|
9790
|
+
await ackPending([relPath])
|
|
9791
|
+
setAgentReplies((prev) => {
|
|
9792
|
+
if (!(relPath in prev)) return prev
|
|
9793
|
+
const next = { ...prev }
|
|
9794
|
+
delete next[relPath]
|
|
9795
|
+
return next
|
|
9796
|
+
})
|
|
9797
|
+
// 这个回调在 GalleryBody 作用域,没有 locale 变量 —— 用 t 探测一次(与 FeedbackBasket 同口径)
|
|
9798
|
+
let isEn = false
|
|
9799
|
+
try { isEn = !/[\u4e00-\u9fa5]/.test(String(t('feedbackBasketTitle') ?? '')) } catch { isEn = false }
|
|
9800
|
+
const reason = (isEn ? 'Rejected the agent reply. ' : '驳回 Agent 的这次修改。')
|
|
9801
|
+
+ (reply?.text ? (isEn ? 'Reply was: ' : '原批示:') + reply.text : '')
|
|
9802
|
+
const mark = { action: 'reject', reason, markedAt: Date.now() }
|
|
9803
|
+
setMarks((prev) => ({ ...prev, [relPath]: mark }))
|
|
9804
|
+
try {
|
|
9805
|
+
await callHost('marks', { path: relPath, mark })
|
|
9806
|
+
} catch { /* 写回失败不阻断本地状态 */ }
|
|
9807
|
+
// 同步待处理反馈:人驳回=一条新的待处理意见,Agent 下次取回的就是它
|
|
9808
|
+
await recordPendingFeedback([{ path: relPath, item: { action: 'reject', reason } }])
|
|
9809
|
+
}, [ackPending, agentReplies, t, recordPendingFeedback])
|
|
9810
|
+
|
|
9099
9811
|
/**
|
|
9100
9812
|
* 手动改标签的主逻辑(v0.14.2)。
|
|
9101
9813
|
*
|
|
@@ -9807,7 +10519,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9807
10519
|
const doCopyAssets = React.useCallback(async (relPaths) => {
|
|
9808
10520
|
const paths = [...new Set((Array.isArray(relPaths) ? relPaths : [])
|
|
9809
10521
|
.map((p) => String(p ?? '')).filter((p) => p !== ''))]
|
|
9810
|
-
if (paths.length === 0) return
|
|
10522
|
+
if (paths.length === 0) return false
|
|
9811
10523
|
try {
|
|
9812
10524
|
const payload = await callHost('copyAssets', { paths })
|
|
9813
10525
|
if (payload?.ok !== true) throw new Error(payload?.error?.message ?? 'copyAssets failed')
|
|
@@ -9816,8 +10528,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9816
10528
|
if (Array.isArray(payload?.missed) && payload.missed.length > 0) {
|
|
9817
10529
|
console.warn('dsh-gallery: 复制时跳过了不在扫描根目录内的项', payload.missed)
|
|
9818
10530
|
}
|
|
10531
|
+
return true
|
|
9819
10532
|
} catch (error) {
|
|
9820
10533
|
showPasteNotice('fail', format(t('copyFailed'), { message: String(error?.message ?? error) }))
|
|
10534
|
+
return false
|
|
9821
10535
|
}
|
|
9822
10536
|
}, [callHost, t, showPasteNotice])
|
|
9823
10537
|
|
|
@@ -9845,6 +10559,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9845
10559
|
// 局部替换时其它组对象引用保持不变,React 就不会重绘它们。
|
|
9846
10560
|
const changesVersionRef = React.useRef(0)
|
|
9847
10561
|
const changesBusyRef = React.useRef(false)
|
|
10562
|
+
// v1.3.0:最近一批「新增资产」的时间戳 —— 用来高亮这批刚产出的终稿。
|
|
10563
|
+
// 只认 added>0 的变动,避免删除/改标签也触发高亮。state 让卡片重绘。
|
|
10564
|
+
const [lastBatchAt, setLastBatchAt] = React.useState(0)
|
|
9848
10565
|
// 写操作后主动催一次检查(不等 1 秒轮询),用户点了就该立刻看到结果
|
|
9849
10566
|
const changesKickRef = React.useRef(null)
|
|
9850
10567
|
|
|
@@ -9864,6 +10581,13 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9864
10581
|
changesVersionRef.current = v
|
|
9865
10582
|
const changed = Array.isArray(r.changed) ? r.changed : []
|
|
9866
10583
|
|
|
10584
|
+
// v1.3.0:记下这批新增的时间,供卡片高亮「刚产出的终稿」
|
|
10585
|
+
const addTimes = changed
|
|
10586
|
+
.filter((c) => Number(c?.added) > 0)
|
|
10587
|
+
.map((c) => Number(c?.at) || 0)
|
|
10588
|
+
.filter((t) => t > 0)
|
|
10589
|
+
if (addTimes.length > 0) setLastBatchAt(Math.max(...addTimes))
|
|
10590
|
+
|
|
9867
10591
|
// 决定「能不能局部刷」:只有分组视图且每个变动都有明确会话才能局部。
|
|
9868
10592
|
// 读 viewRef(不是 view)拿最新值,避免闭包过期。
|
|
9869
10593
|
const cur = viewRef.current
|
|
@@ -10021,6 +10745,33 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10021
10745
|
const groupsRef = React.useRef(null)
|
|
10022
10746
|
groupsRef.current = Array.isArray(data?.groups) ? data.groups : null
|
|
10023
10747
|
|
|
10748
|
+
/**
|
|
10749
|
+
* v1.3.0:这批刚产出的终稿(用于资产台高亮,上限 3 张)。
|
|
10750
|
+
* 口径:全视图(含分组)里 category=final 且 mtime 落在最近新增批次内的资产,
|
|
10751
|
+
* 按 mtime 取最新 3 个。lastBatchAt=0 时不高亮任何卡片(初始没有"这批")。
|
|
10752
|
+
*/
|
|
10753
|
+
const freshFinalSet = React.useMemo(() => {
|
|
10754
|
+
if (!lastBatchAt || lastBatchAt <= 0) return new Set()
|
|
10755
|
+
const all = [
|
|
10756
|
+
...(Array.isArray(items) ? items : []),
|
|
10757
|
+
...(Array.isArray(data?.groups) ? data.groups.flatMap((g) => (Array.isArray(g?.files) ? g.files : [])) : []),
|
|
10758
|
+
]
|
|
10759
|
+
const seen = new Set()
|
|
10760
|
+
const fresh = []
|
|
10761
|
+
for (const it of all) {
|
|
10762
|
+
const rel = String(it?.relPath ?? '')
|
|
10763
|
+
if (rel === '' || seen.has(rel)) continue
|
|
10764
|
+
if (String(it?.category ?? '') !== 'final') continue
|
|
10765
|
+
const mt = Number(it?.mtime) || 0
|
|
10766
|
+
// 5 秒容差:fs.watch 的 at 与文件 mtime 可能差几秒
|
|
10767
|
+
if (mt < lastBatchAt - 5000) continue
|
|
10768
|
+
seen.add(rel)
|
|
10769
|
+
fresh.push({ rel, mt })
|
|
10770
|
+
}
|
|
10771
|
+
fresh.sort((a, b) => b.mt - a.mt)
|
|
10772
|
+
return new Set(fresh.slice(0, 3).map((x) => x.rel))
|
|
10773
|
+
}, [items, data, lastBatchAt])
|
|
10774
|
+
|
|
10024
10775
|
// 分组首次渲染时,默认展开「当前对话」那一组(没有则展开第一组)。
|
|
10025
10776
|
// 只做一次:之后用户手动收起/展开都保留。
|
|
10026
10777
|
React.useEffect(() => {
|
|
@@ -10498,9 +11249,14 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10498
11249
|
const showCheckbox = selectMode || checked
|
|
10499
11250
|
const manual = manualLabelOf(item.relPath)
|
|
10500
11251
|
const isManual = manual !== null && manual !== undefined
|
|
11252
|
+
// v1.3.0:这批刚产出的终稿加高亮 class(上限 3 张,由 freshFinalSet 控制)
|
|
11253
|
+
const isFreshFinal = freshFinalSet.has(item.relPath)
|
|
10501
11254
|
return h('div', {
|
|
10502
|
-
className: `dg-cardWrap${checked ? ' dg-cardChecked' : ''}${selectMode ? ' dg-cardSelectable' : ''}`,
|
|
11255
|
+
className: `dg-cardWrap${checked ? ' dg-cardChecked' : ''}${selectMode ? ' dg-cardSelectable' : ''}${isFreshFinal ? ' dg-cardFreshFinal' : ''}`,
|
|
11256
|
+
'data-gallery-fresh-final': isFreshFinal ? '1' : '0',
|
|
10503
11257
|
key: key + ':wrap',
|
|
11258
|
+
// 三类卡片统一可拖(图片/文件/音视频):捕获阶段 dragstart 据此起原生拖出真文件。
|
|
11259
|
+
draggable: true,
|
|
10504
11260
|
'data-gallery-card-wrap': item.relPath,
|
|
10505
11261
|
'data-gallery-bucket': bucket,
|
|
10506
11262
|
'data-gallery-label-manual': isManual ? '1' : '0',
|
|
@@ -10516,7 +11272,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10516
11272
|
? (event) => {
|
|
10517
11273
|
const target = event.target
|
|
10518
11274
|
if (target !== null && target !== undefined && typeof target.closest === 'function') {
|
|
10519
|
-
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
|
|
10520
11276
|
}
|
|
10521
11277
|
event.preventDefault()
|
|
10522
11278
|
event.stopPropagation()
|
|
@@ -10525,6 +11281,25 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10525
11281
|
: undefined,
|
|
10526
11282
|
}, [
|
|
10527
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,
|
|
10528
11303
|
// 右上「改标签」:手动设定过的用琥珀色区分,hover 时完全显现。
|
|
10529
11304
|
// 不再放独立角标,避免和卡片左上角的阶段角标抢位置。
|
|
10530
11305
|
h('button', {
|
|
@@ -10606,8 +11381,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10606
11381
|
void copyText(abs)
|
|
10607
11382
|
}
|
|
10608
11383
|
},
|
|
10609
|
-
//
|
|
10610
|
-
|
|
11384
|
+
// 2026-11-19:卡面按钮改成「复制文件」(写系统剪贴板),与右键菜单那条一致
|
|
11385
|
+
onCopyFile: (relPath) => doCopyAssets([relPath]),
|
|
11386
|
+
// 另一个按钮从「预览」换成「写进输入框」,与双击同一条链路
|
|
11387
|
+
onWriteDraft: (target, event) => { handleCardDoubleClick(target, event) },
|
|
10611
11388
|
}), item, `${groupKey}:${item.relPath}`)
|
|
10612
11389
|
}
|
|
10613
11390
|
return wrapCard(h(Card, {
|
|
@@ -10845,6 +11622,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10845
11622
|
void copyText(abs)
|
|
10846
11623
|
}
|
|
10847
11624
|
},
|
|
11625
|
+
onCopyFile: (relPath) => doCopyAssets([relPath]),
|
|
11626
|
+
onWriteDraft: (target, event) => { handleCardDoubleClick(target, event) },
|
|
10848
11627
|
})
|
|
10849
11628
|
: h(Card, {
|
|
10850
11629
|
key: item.relPath,
|
|
@@ -11069,6 +11848,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11069
11848
|
const feedbackPaths = Array.from(new Set([
|
|
11070
11849
|
...Object.keys(marks),
|
|
11071
11850
|
...Object.keys(annotations),
|
|
11851
|
+
...Object.keys(agentReplies),
|
|
11072
11852
|
]))
|
|
11073
11853
|
const markedList = feedbackPaths.map((relPath) => {
|
|
11074
11854
|
// 从当前视图里找该条目,拿 category / sessionId
|
|
@@ -11086,6 +11866,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11086
11866
|
maskOf: maskBySource.get(relPath) ?? found?.maskOf,
|
|
11087
11867
|
mark: marks[relPath],
|
|
11088
11868
|
annotations: Array.isArray(annotations[relPath]) ? annotations[relPath] : [],
|
|
11869
|
+
// v1.3.0:Agent 批示(只在反馈栏显示成卡片,不进草稿、不参与序号)
|
|
11870
|
+
reply: agentReplies[relPath] ?? null,
|
|
11089
11871
|
}
|
|
11090
11872
|
})
|
|
11091
11873
|
const feedbackLayer = basketOpen && markedList.length >= 0
|
|
@@ -11115,6 +11897,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11115
11897
|
},
|
|
11116
11898
|
// v0.16.4:草稿进 composer 后把待处理清零(人已处理完这批)
|
|
11117
11899
|
onAck: (paths) => { void ackPending(paths) },
|
|
11900
|
+
// v1.3.0:Agent 批示的核准 / 驳回(独立于普通草稿流程)
|
|
11901
|
+
onAckReply: (relPath) => { void ackAgentReply(relPath) },
|
|
11902
|
+
onRejectReply: (relPath) => { void rejectAgentReply(relPath) },
|
|
11118
11903
|
})
|
|
11119
11904
|
: null
|
|
11120
11905
|
|
|
@@ -11733,10 +12518,65 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11733
12518
|
}
|
|
11734
12519
|
}, 'dsh-gallery: seam')
|
|
11735
12520
|
|
|
11736
|
-
//
|
|
11737
|
-
//
|
|
11738
|
-
//
|
|
12521
|
+
// 拖卡片:① 原生桥可用时拖出真文件到外部应用;② 同时保留旧的
|
|
12522
|
+
// 「文件名+绝对路径+主遮罩写进 File.name」通道,供拖进 DSH 对话给 Agent 定位。
|
|
12523
|
+
// 两条并存:pointerdown 异步准备原生文件,dragstart 同步起拖 + 写 PNG 兜底,
|
|
12524
|
+
// dragend/drop 清理。不改查看器缩放/批注交互、不碰 composer、不自动发送。
|
|
11739
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
|
+
|
|
11740
12580
|
const onDragStart = (event) => {
|
|
11741
12581
|
const dt = event.dataTransfer
|
|
11742
12582
|
const target = event.target
|
|
@@ -11754,20 +12594,23 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11754
12594
|
? { ...entry.item, maskOf: { ...linked, linkedMask: true } }
|
|
11755
12595
|
: entry.item
|
|
11756
12596
|
const name = dragNameOf(item, entry.absPath)
|
|
11757
|
-
// 自证 + 兜底双用途:无论 File 替换是否成功,都把同一串信息写进剪贴板。
|
|
11758
|
-
// 拖完在输入框 Ctrl+V 能粘出「产出台·…」= 新代码确实执行过、dragstart 命中;
|
|
11759
|
-
// 粘不出 = 面板仍加载旧模块,需重载窗口。编码 / 写入失败时它就是唯一可用通道。
|
|
11760
12597
|
void copyText(name)
|
|
11761
|
-
|
|
11762
|
-
//
|
|
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「拖到对话」按钮拖出时取预览大图,否则用卡片自己的缩略图。
|
|
11763
12609
|
const img = card.hasAttribute('data-gallery-dragviewer')
|
|
11764
12610
|
? document.querySelector('.dg-viewerBody img')
|
|
11765
12611
|
: (target.matches('img') ? target : target.querySelector('img'))
|
|
11766
12612
|
const bytes = syncImagePngBytes(img)
|
|
11767
|
-
if (bytes === null)
|
|
11768
|
-
// 编码失败:保留浏览器原生拖图,信息已在剪贴板供手动粘贴
|
|
11769
|
-
return
|
|
11770
|
-
}
|
|
12613
|
+
if (bytes === null) return
|
|
11771
12614
|
try {
|
|
11772
12615
|
dt.clearData()
|
|
11773
12616
|
dt.effectAllowed = 'copy'
|
|
@@ -11776,8 +12619,23 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
11776
12619
|
console.warn('dsh-gallery: 拖图元信息写入失败,信息已在剪贴板', error)
|
|
11777
12620
|
}
|
|
11778
12621
|
}
|
|
12622
|
+
|
|
12623
|
+
document.addEventListener('pointerdown', onPointerDown, true)
|
|
12624
|
+
document.addEventListener('pointerup', abandonPrep, true)
|
|
12625
|
+
document.addEventListener('pointercancel', abandonPrep, true)
|
|
11779
12626
|
document.addEventListener('dragstart', onDragStart, true)
|
|
11780
|
-
|
|
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
|
+
}
|
|
11781
12639
|
}, 'dsh-gallery: drag asset metadata')
|
|
11782
12640
|
|
|
11783
12641
|
ctx.effect(() => {
|