dsh-gallery 1.1.0 → 1.3.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/client.js CHANGED
@@ -629,6 +629,26 @@ async function encodeMaskPngBytes(imageData, width, height) {
629
629
  batchModeExit: '退出批量',
630
630
  batchModeEnterHint: '批量模式:直接点卡片即可选中/取消(此时点卡片不会打开大图),选好后批量改标签',
631
631
  batchModeExitHint: '退出批量模式并清空已选',
632
+ // ---- 前后对比(2026-11-17)----
633
+ cmpEnter: '对比',
634
+ cmpExit: '结束对比',
635
+ cmpPickTitle: '选一张来对比',
636
+ cmpPickHint: '同尺寸排前面;标「推荐」的是刚圈过遮罩、或时间最接近的那几张',
637
+ cmpPickEmpty: '这一组里没有别的图可以对比',
638
+ cmpSameSize: '同尺寸',
639
+ cmpSizeDiff: '尺寸不同',
640
+ cmpModeSlider: '滑块',
641
+ cmpModeTile: '平铺',
642
+ cmpSliderHint: '拖分割线 · 点轨道跳转 · ← → 微调',
643
+ cmpSwap: '对调',
644
+ cmpBefore: '前',
645
+ cmpAfter: '后',
646
+ cmpLoading: '正在载入对比图…',
647
+ cmpFailed: '对比图载入失败',
648
+ cmpRecommend: '推荐',
649
+ cmpSizeWarn: '两张尺寸不同,对齐仅供参考',
650
+ cmpBatchEnter: '对比两张',
651
+ cmpBatchHint: '选中两张后进对比',
632
652
  cardConfirm: '✓ 定稿',
633
653
  cardConfirmed: '✓ 已定稿',
634
654
  cardConfirmHint: '把这张定为「已定稿」(只写标记,不动文件,也不发送消息)',
@@ -1028,6 +1048,26 @@ async function encodeMaskPngBytes(imageData, width, height) {
1028
1048
  batchModeExit: 'Exit batch',
1029
1049
  batchModeEnterHint: 'Batch mode: click any card to select/deselect (clicking no longer opens the viewer), then edit labels in batch',
1030
1050
  batchModeExitHint: 'Leave batch mode and clear the selection',
1051
+ // ---- before / after compare (2026-11-17) ----
1052
+ cmpEnter: 'Compare',
1053
+ cmpExit: 'Exit compare',
1054
+ cmpPickTitle: 'Pick an image to compare',
1055
+ cmpPickHint: 'Same-size files first; "Suggested" had a mask or are closest in time',
1056
+ cmpPickEmpty: 'No other image in this group to compare',
1057
+ cmpSameSize: 'Same size',
1058
+ cmpSizeDiff: 'Different size',
1059
+ cmpModeSlider: 'Slider',
1060
+ cmpModeTile: 'Side by side',
1061
+ cmpSliderHint: 'Drag the divider, click the track to jump, arrow keys to nudge',
1062
+ cmpSwap: 'Swap',
1063
+ cmpBefore: 'Before',
1064
+ cmpAfter: 'After',
1065
+ cmpLoading: 'Loading comparison image...',
1066
+ cmpFailed: 'Comparison image failed to load',
1067
+ cmpRecommend: 'Suggested',
1068
+ cmpSizeWarn: 'Different sizes, alignment is approximate',
1069
+ cmpBatchEnter: 'Compare two',
1070
+ cmpBatchHint: 'Select two images to compare',
1031
1071
  cardConfirm: '✓ Finalize',
1032
1072
  cardConfirmed: '✓ Finalized',
1033
1073
  cardConfirmHint: 'Mark this as finalized (marks only; no file changes, no message sent)',
@@ -2590,6 +2630,45 @@ async function encodeMaskPngBytes(imageData, width, height) {
2590
2630
  .dg-toast-failed { border-color: var(--dsw-alias-state-error-primary, #d9534f); }
2591
2631
  .dg-viewerLayer .dg-viewer { flex: 1 1 auto; min-height: 0; }
2592
2632
  .dg-viewerBody { touch-action: none; }
2633
+
2634
+ /* ---- 前后对比(2026-11-17)----
2635
+ 两个关键点:
2636
+ ① .dg-cmpClip 不参与 transform —— 分割线按屏幕坐标切,放大后不跟着图跑
2637
+ ② .dg-cmpImg 用 imgBox 的绝对位置 + 与主图同一组 pan/zoom,两层像素级重合
2638
+ 配色一律硬编码高对比:宿主 --dsw-alias-* 未定义时 var() 兜底会整体发暗。 */
2639
+ .dg-cmpClip { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
2640
+ .dg-cmpImg { position: absolute; max-width: none; max-height: none; object-fit: contain; pointer-events: none; user-select: none; transform-origin: center center; }
2641
+ .dg-cmpUi { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
2642
+ .dg-cmpTag { position: absolute; top: 10px; padding: 2px 8px; border-radius: 4px; font-size: 11px; line-height: 16px; color: #e8f5ee; background: rgba(10, 14, 18, 0.74); border: 0.5px solid rgba(0, 230, 118, 0.45); }
2643
+ .dg-cmpTagL { left: 10px; }
2644
+ .dg-cmpTagR { right: 10px; }
2645
+ .dg-cmpHandle { position: absolute; top: 0; bottom: 0; width: 34px; margin-left: -17px; pointer-events: auto; cursor: ew-resize; touch-action: none; }
2646
+ .dg-cmpLine { position: absolute; top: 0; bottom: 0; left: 50%; margin-left: -1px; width: 2px; background: #00e676; }
2647
+ .dg-cmpGrip { position: absolute; top: 50%; left: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: rgba(8, 12, 16, 0.92); border: 2px solid #00e676; display: flex; align-items: center; justify-content: center; color: #00e676; font-size: 13px; line-height: 1; }
2648
+ .dg-cmpArrow { display: block; transform: scaleY(1.35); }
2649
+ .dg-cmpMsg { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); padding: 4px 10px; border-radius: 4px; font-size: 11px; color: #e8f5ee; background: rgba(10, 14, 18, 0.82); }
2650
+ /* 平铺模式:左右各一格,共用同一组 pan/zoom */
2651
+ .dg-cmpTile { position: absolute; inset: 0; z-index: 4; display: flex; gap: 4px; padding: 4px; background: var(--dsw-specific-sidebar-fill, #111); }
2652
+ .dg-cmpPane { position: relative; flex: 1 1 0; min-width: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; border-radius: 4px; background: rgba(0, 0, 0, 0.28); }
2653
+ .dg-cmpPaneImg { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; user-select: none; transform-origin: center center; }
2654
+ .dg-cmpPaneTag { position: absolute; top: 8px; left: 8px; padding: 1px 7px; border-radius: 4px; font-size: 11px; color: #e8f5ee; background: rgba(10, 14, 18, 0.74); border: 0.5px solid rgba(0, 230, 118, 0.45); }
2655
+ .dg-cmpPaneMsg { font-size: 12px; color: #9aa8b8; }
2656
+ /* 选图面板 */
2657
+ .dg-cmpPicker { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; gap: 8px; padding: 14px; overflow: auto; background: rgba(8, 11, 15, 0.95); }
2658
+ .dg-cmpPickerHead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
2659
+ .dg-cmpPickerTitle { font-size: 13px; font-weight: 600; color: #eef2f6; }
2660
+ .dg-cmpPickerHint { font-size: 11px; line-height: 1.5; color: #8b98a8; }
2661
+ .dg-cmpPickerEmpty { padding: 18px 4px; font-size: 12px; color: #8b98a8; }
2662
+ .dg-cmpPickerGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
2663
+ .dg-cmpCard { position: relative; display: flex; flex-direction: column; gap: 0; padding: 0; border: 0.5px solid rgba(255, 255, 255, 0.14); border-radius: 6px; background: rgba(255, 255, 255, 0.04); cursor: pointer; overflow: hidden; text-align: left; }
2664
+ .dg-cmpCard:hover { border-color: #00e676; background: rgba(0, 230, 118, 0.08); }
2665
+ .dg-cmpCardThumb { display: block; width: 100%; height: 84px; background: rgba(0, 0, 0, 0.35); }
2666
+ .dg-cmpCardThumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
2667
+ .dg-cmpCardRec { position: absolute; top: 4px; left: 4px; padding: 1px 6px; border-radius: 3px; font-size: 10px; color: #06120a; background: #00e676; }
2668
+ .dg-cmpCardMeta { display: flex; flex-direction: column; gap: 1px; padding: 4px 6px 6px; }
2669
+ .dg-cmpCardName { font-size: 11px; color: #dfe6ee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2670
+ .dg-cmpCardSize { font-size: 10px; color: #7f8b9a; }
2671
+ .dg-cmpCardSizeDiff { color: #e6a23c; }
2593
2672
  .dg-textBody { display: block; overflow: auto; padding: 12px 14px; user-select: text; touch-action: auto; }
2594
2673
 
2595
2674
  /* ===== 文件卡片 v2:三段式 ===== */
@@ -2966,6 +3045,18 @@ async function encodeMaskPngBytes(imageData, width, height) {
2966
3045
  }
2967
3046
  .dg-feedback .dg-btnSmall { padding: 3px 9px; font-size: 11px; }
2968
3047
 
3048
+ /* v1.3.0:Agent 批示区块(独立于表态/批注序号,不进草稿) */
3049
+ .dg-replyBlock { border: 1px solid #00e676; border-radius: 8px; padding: 8px; margin: 8px 0; background: rgba(0, 230, 118, 0.06); }
3050
+ .dg-replyHead { color: #00e676; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
3051
+ .dg-replyList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
3052
+ .dg-replyItem { border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 6px; padding: 7px 8px; background: #222831; }
3053
+ .dg-replyText { color: #e8eaed; font-size: 12px; line-height: 1.5; margin-bottom: 4px; word-break: break-word; }
3054
+ .dg-replyMeta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: #a9b1bd; margin-bottom: 6px; }
3055
+ .dg-replyName { color: #cdd4de; }
3056
+ .dg-replyOps { display: flex; gap: 6px; justify-content: flex-end; }
3057
+ .dg-feedback .dg-replyApprove { background: #1d7a4d; color: #ffffff; border-color: #1d7a4d; }
3058
+ .dg-feedback .dg-replyApprove:hover:not(:disabled) { background: #249a60; border-color: #249a60; }
3059
+
2969
3060
  .dg-feedbackActions {
2970
3061
  display: flex; justify-content: flex-end; gap: 8px;
2971
3062
  padding: 10px 14px; border-top: 1px solid rgba(255, 255, 255, 0.10);
@@ -3027,6 +3118,14 @@ async function encodeMaskPngBytes(imageData, width, height) {
3027
3118
 
3028
3119
  /* 卡片包装层 + 确认角标 + 多选框 */
3029
3120
  .dg-cardWrap { position: relative; }
3121
+ /* v1.3.0:这批刚产出的终稿高亮(上限 3 张)。用外发光+角标,不动 ::after border(避免和选中态打架)。 */
3122
+ .dg-cardWrap.dg-cardFreshFinal { box-shadow: 0 0 0 2px #00e676, 0 0 12px rgba(0, 230, 118, 0.35); border-radius: 6px; }
3123
+ .dg-cardWrap.dg-cardFreshFinal::before {
3124
+ content: '新';
3125
+ position: absolute; top: 4px; right: 4px; z-index: 7;
3126
+ background: #00e676; color: #04220f; font-size: 11px; font-weight: 600;
3127
+ padding: 0 6px; border-radius: 8px; line-height: 16px;
3128
+ }
3030
3129
  /* 结论角标(左上):人的表态,优先于右上角的机器预判角标 */
3031
3130
  .dg-verdictBadge {
3032
3131
  position: absolute; top: 6px; left: 6px; z-index: 5;
@@ -4252,7 +4351,8 @@ function serializeFeedback(feedback) {
4252
4351
  */
4253
4352
  function FeedbackBasket({ t, items, currentSessionId, targetSessionTitle,
4254
4353
  onClose, onRemove, onEdit, onClear, onEditSave,
4255
- onRemoveAnnotation, onClearAll, onAck }) {
4354
+ onRemoveAnnotation, onClearAll, onAck,
4355
+ onAckReply, onRejectReply }) {
4256
4356
  // 语言判断:用 t 探测一个已知键 —— 命中中文就按 zh 渲染,否则 en。
4257
4357
  // (不引入 detectLocale,插件没有这个工具函数)
4258
4358
  const [locale] = React.useState(() => {
@@ -4271,6 +4371,8 @@ function serializeFeedback(feedback) {
4271
4371
  const rows = React.useMemo(() => {
4272
4372
  const out = []
4273
4373
  for (const it of Array.isArray(items) ? items : []) {
4374
+ // v1.3.0:Agent 批示单独渲染在列表顶部,不进 Annotation N 序号、不进草稿
4375
+ if (it.reply !== undefined && it.reply !== null) continue
4274
4376
  if (it.mark !== undefined && it.mark !== null) out.push({ kind: 'mark', it })
4275
4377
  const annots = Array.isArray(it.annotations) ? it.annotations : []
4276
4378
  for (const a of annots) out.push({ kind: 'annot', it, a })
@@ -4278,6 +4380,11 @@ function serializeFeedback(feedback) {
4278
4380
  return out
4279
4381
  }, [items])
4280
4382
  const annotCount = rows.filter((r) => r.kind === 'annot').length
4383
+ // v1.3.0:Agent 批示条目(单独区块,独立于表态/批注序号)
4384
+ const replyRows = React.useMemo(
4385
+ () => (Array.isArray(items) ? items : []).filter((it) => it.reply !== undefined && it.reply !== null),
4386
+ [items],
4387
+ )
4281
4388
  // 编辑弹窗:正在编辑的条目 + 三个字段的草稿值
4282
4389
  const [editing, setEditing] = React.useState(null)
4283
4390
  const [editReason, setEditReason] = React.useState('')
@@ -4342,7 +4449,11 @@ function serializeFeedback(feedback) {
4342
4449
  */
4343
4450
  if (typeof onAck === 'function') {
4344
4451
  try {
4345
- await onAck(items.map((it) => it.relPath))
4452
+ // v1.3.0:Agent 批示不随普通草稿被清 —— 它有自己的核准/驳回入口
4453
+ const humanPaths = items
4454
+ .filter((it) => it.reply === undefined || it.reply === null)
4455
+ .map((it) => it.relPath)
4456
+ await onAck(humanPaths)
4346
4457
  } catch { /* ack 失败不影响草稿已经写进去这个事实 */ }
4347
4458
  }
4348
4459
  } else {
@@ -4392,6 +4503,48 @@ function serializeFeedback(feedback) {
4392
4503
  format(t('feedbackAnnotHint'), { n: annotCount }))
4393
4504
  : null,
4394
4505
 
4506
+ // v1.3.0:Agent 批示区块(独立于下面的表态/批注序号,不进草稿)
4507
+ // 每条批示 = Agent 改完图后的回报,人在这里核准或驳回;驳回会带着意见再回去。
4508
+ replyRows.length > 0
4509
+ ? h('div', { className: 'dg-replyBlock', key: 'replies', 'data-gallery-agent-replies': replyRows.length }, [
4510
+ h('div', { className: 'dg-replyHead', key: 'h' },
4511
+ locale === 'en' ? 'Agent replies · pending your approval' : 'Agent 批示 · 待您核准'),
4512
+ h('ul', { className: 'dg-replyList', key: 'l' },
4513
+ replyRows.map((it) => {
4514
+ const r = it.reply
4515
+ const fileName = it.relPath.split('/').pop() ?? it.relPath
4516
+ return h('li', {
4517
+ className: 'dg-replyItem',
4518
+ key: 'reply:' + it.relPath,
4519
+ 'data-gallery-reply-item': it.relPath,
4520
+ }, [
4521
+ h('div', { className: 'dg-replyText', key: 'text' },
4522
+ (locale === 'en' ? 'Agent: ' : 'Agent:') + String(r.text ?? '')),
4523
+ h('div', { className: 'dg-replyMeta', key: 'meta' }, [
4524
+ h('span', { className: 'dg-replyName', key: 'name', title: it.relPath }, fileName),
4525
+ r.replyOf
4526
+ ? h('span', { className: 'dg-feedbackDim', key: 'of' },
4527
+ (locale === 'en' ? 're: ' : '回应:') + (r.replyOf.split('/').pop() ?? r.replyOf))
4528
+ : null,
4529
+ ]),
4530
+ h('div', { className: 'dg-replyOps', key: 'ops' }, [
4531
+ h('button', {
4532
+ type: 'button', className: 'dg-btn dg-btnSmall dg-replyApprove', key: 'ok',
4533
+ 'data-gallery-reply-approve': it.relPath,
4534
+ onClick: () => { if (typeof onAckReply === 'function') onAckReply(it.relPath) },
4535
+ }, locale === 'en' ? 'Approve' : '核准'),
4536
+ h('button', {
4537
+ type: 'button', className: 'dg-btn dg-btnSmall', key: 'no',
4538
+ 'data-gallery-reply-reject': it.relPath,
4539
+ onClick: () => { if (typeof onRejectReply === 'function') onRejectReply(it.relPath) },
4540
+ }, locale === 'en' ? 'Reject' : '驳回'),
4541
+ ]),
4542
+ ])
4543
+ })
4544
+ ),
4545
+ ])
4546
+ : null,
4547
+
4395
4548
  rows.length === 0
4396
4549
  ? h('p', { className: 'dg-status', key: 'empty' }, t('feedbackBasketEmpty'))
4397
4550
  : h('ul', { className: 'dg-feedbackList', key: 'list' },
@@ -5175,6 +5328,7 @@ function serializeFeedback(feedback) {
5175
5328
  text: format(t('mediaGrabFrameSaved'), { name: payload?.name ?? '', timecode: payload?.timecode ?? '' }),
5176
5329
  })
5177
5330
  // 立刻重扫:新资产出现在当前对话组,可马上点开批注 / 进反馈篮
5331
+ kickChanges()
5178
5332
  if (typeof onSaved === 'function') onSaved(payload)
5179
5333
  } catch (error) {
5180
5334
  setGrabNotice({ kind: 'failed', text: format(t('mediaGrabFrameFailed'), { message: String(error?.message ?? error) }) })
@@ -6252,7 +6406,97 @@ ${absPath}
6252
6406
  ])
6253
6407
  }
6254
6408
 
6255
- function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop, onCopyFile }) {
6409
+ /**
6410
+ * 对比选图面板(2026-11-17)。
6411
+ * 老板要求「选图要方便快捷」,所以只做一件事:格子一列,点一下就进对比,选完立即关。
6412
+ * 缩略图沿用卡片那套 fetchRaw + makeScaled,不额外开后端路由。
6413
+ */
6414
+ function ComparePicker({ t, candidates, onPick, onClose }) {
6415
+ return h('div', {
6416
+ className: 'dg-cmpPicker',
6417
+ 'data-gallery-compare-picker': true,
6418
+ onClick: (event) => event.stopPropagation(),
6419
+ }, [
6420
+ h('div', { key: 'head', className: 'dg-cmpPickerHead' }, [
6421
+ h('span', { key: 'title', className: 'dg-cmpPickerTitle' }, t('cmpPickTitle')),
6422
+ h('button', {
6423
+ key: 'close',
6424
+ type: 'button',
6425
+ className: 'dg-btn dg-btnTiny',
6426
+ 'data-gallery-compare-picker-close': true,
6427
+ onClick: (event) => { event.stopPropagation(); onClose() },
6428
+ }, '\u2715'),
6429
+ ]),
6430
+ h('div', { key: 'hint', className: 'dg-cmpPickerHint' }, t('cmpPickHint')),
6431
+ candidates.length === 0
6432
+ ? h('div', { key: 'empty', className: 'dg-cmpPickerEmpty' }, t('cmpPickEmpty'))
6433
+ : h('div', { key: 'grid', className: 'dg-cmpPickerGrid' },
6434
+ candidates.map((cand, i) => h(ComparePickCard, {
6435
+ key: cand.item.relPath,
6436
+ t,
6437
+ cand,
6438
+ recommend: i < 3,
6439
+ onPick,
6440
+ }))),
6441
+ ])
6442
+ }
6443
+
6444
+ /** 单个候选:缩略图 + 文件名 + 尺寸(不同尺寸标出来,免得以为没对齐是 bug)。 */
6445
+ function ComparePickCard({ t, cand, recommend, onPick }) {
6446
+ const [url, setUrl] = React.useState(null)
6447
+ const relPath = String(cand.item.relPath ?? '')
6448
+ React.useEffect(() => {
6449
+ if (relPath === '') return undefined
6450
+ let cancelled = false
6451
+ let objUrl = null
6452
+ const controller = new AbortController()
6453
+ fetchRaw(relPath, controller.signal)
6454
+ .then(async (blob) => {
6455
+ const thumb = await makeScaled(blob, THUMB_SIZE, true)
6456
+ if (cancelled) {
6457
+ if (thumb.url !== null) URL.revokeObjectURL(thumb.url)
6458
+ return
6459
+ }
6460
+ objUrl = thumb.url
6461
+ setUrl(thumb.url)
6462
+ })
6463
+ .catch(() => {})
6464
+ return () => {
6465
+ cancelled = true
6466
+ controller.abort()
6467
+ if (objUrl !== null) URL.revokeObjectURL(objUrl)
6468
+ }
6469
+ }, [relPath])
6470
+
6471
+ const w = Number(cand.item.width) || 0
6472
+ const hh = Number(cand.item.height) || 0
6473
+ return h('button', {
6474
+ type: 'button',
6475
+ className: 'dg-cmpCard',
6476
+ 'data-gallery-compare-cand': relPath,
6477
+ 'data-gallery-compare-samesize': cand.sameSize ? '1' : '0',
6478
+ title: relPath,
6479
+ onClick: (event) => {
6480
+ event.stopPropagation()
6481
+ onPick(cand.item)
6482
+ },
6483
+ }, [
6484
+ h('span', { key: 'thumb', className: 'dg-cmpCardThumb' },
6485
+ url === null ? null : h('img', { key: 'i', src: url, alt: '', draggable: false })),
6486
+ recommend === true
6487
+ ? h('span', { key: 'rec', className: 'dg-cmpCardRec' }, t('cmpRecommend'))
6488
+ : null,
6489
+ h('span', { key: 'meta', className: 'dg-cmpCardMeta' }, [
6490
+ h('span', { key: 'name', className: 'dg-cmpCardName' }, String(cand.item.name ?? '')),
6491
+ h('span', {
6492
+ key: 'size',
6493
+ className: 'dg-cmpCardSize' + (cand.sameSize ? '' : ' dg-cmpCardSizeDiff'),
6494
+ }, cand.sameSize ? w + '\u00d7' + hh : t('cmpSizeDiff')),
6495
+ ]),
6496
+ ])
6497
+ }
6498
+
6499
+ function Viewer({ items, index, onClose, onStep, t, initialOriginal, initialCompare, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop, onCopyFile }) {
6256
6500
  const item = items[index]
6257
6501
  // 文件预览已改走 DSH 原生侧栏(session 地址);此处 Viewer 仅处理图片,isText 恒 false,
6258
6502
  // 下面的文本分支保留为死代码,供 v0.2 若需插件内预览时复用
@@ -6260,11 +6504,173 @@ ${absPath}
6260
6504
  const [state, setState] = React.useState({ status: 'pending' })
6261
6505
  const [zoom, setZoom] = React.useState(1)
6262
6506
  const [pan, setPan] = React.useState({ x: 0, y: 0 })
6507
+ // 视图状态镜像:滚轮用原生监听,且绝不能把 setPan 嵌进 setZoom 的 updater。
6508
+ // updater 必须是纯函数;React 严格模式会把它跑两遍,pan 就被算两次 ——
6509
+ // 表现正是「平铺下以鼠标为中心缩放失灵」(实测漂移约 15px)。改用 ref 读当前值、
6510
+ // 算好后分别 set;渲染体每帧回写,让拖拽/按钮的改动也能同步进 ref。
6511
+ const viewRef = React.useRef({ zoom: 1, pan: { x: 0, y: 0 } })
6512
+ viewRef.current.zoom = zoom
6513
+ viewRef.current.pan = pan
6263
6514
  const [dragging, setDragging] = React.useState(false)
6264
6515
  const bodyRef = React.useRef(null)
6265
6516
  const imgRef = React.useRef(null)
6266
6517
  /** 图片在预览容器里的真实布局盒(不含 transform);批注层据此对齐,1:1 也不跑偏。 */
6267
6518
  const [imgBox, setImgBox] = React.useState(null)
6519
+
6520
+ // ---- 前后对比(2026-11-17)----
6521
+ // 老板口径:手动选两张为主路,智能推荐为辅(优先「生成遮罩的原素材 ↔ 成稿」)。
6522
+ // 对比图单独走一次 fetchRaw,跟「原图模式」互不复用,换图即释放。
6523
+ const [cmpTarget, setCmpTarget] = React.useState(null)
6524
+ const [cmpMode, setCmpMode] = React.useState('slider')
6525
+ const [splitPct, setSplitPct] = React.useState(50)
6526
+ const [pickerOpen, setPickerOpen] = React.useState(false)
6527
+ const [cmpSwapped, setCmpSwapped] = React.useState(false)
6528
+ const cmpAbortRef = React.useRef(null)
6529
+ const cmpUrlRef = React.useRef(null)
6530
+ const splitDragRef = React.useRef(null)
6531
+
6532
+ /** 释放对比图占用的 object URL 与请求。 */
6533
+ const releaseCmp = React.useCallback(() => {
6534
+ if (cmpAbortRef.current !== null) {
6535
+ try { cmpAbortRef.current.abort() } catch {}
6536
+ cmpAbortRef.current = null
6537
+ }
6538
+ if (cmpUrlRef.current !== null) {
6539
+ URL.revokeObjectURL(cmpUrlRef.current)
6540
+ cmpUrlRef.current = null
6541
+ }
6542
+ }, [])
6543
+
6544
+ /**
6545
+ * 对比候选排序。信号按可靠度叠加:
6546
+ * ① 遮罩关系(这是「圈过的原素材 ↔ 遮罩产物」,最确定)
6547
+ * ② 同尺寸(局部重绘必然同尺寸,不同尺寸就没什么可比)
6548
+ * ③ 时间方向与距离(更晚的像成稿,越近越优先)
6549
+ * ④ 文件名主干一致
6550
+ * 只取前 12 个,面板里够看又不至于一次拉太多缩略图。
6551
+ */
6552
+ const cmpCandidates = React.useMemo(() => {
6553
+ const curPath = String(item.relPath ?? '')
6554
+ const w = Number(item.width) || 0
6555
+ const h = Number(item.height) || 0
6556
+ const curSource = String(item.maskOf?.sourceRelPath ?? '')
6557
+ const stemOf = (name) => String(name ?? '')
6558
+ .replace(/\.[^.]*$/, '')
6559
+ .replace(/[_\-\s]*(改|重绘|修|inpaint|edit|fixed|final|v\d+)$/i, '')
6560
+ const base = stemOf(item.name)
6561
+ const out = []
6562
+ for (const cand of items) {
6563
+ const rel = String(cand.relPath ?? '')
6564
+ if (rel === '' || rel === curPath) continue
6565
+ if (!isImageItem(cand)) continue
6566
+ const cw = Number(cand.width) || 0
6567
+ const ch = Number(cand.height) || 0
6568
+ const sameSize = w > 0 && h > 0 && cw === w && ch === h
6569
+ const candSource = String(cand.maskOf?.sourceRelPath ?? '')
6570
+ const maskLinked = (candSource !== '' && candSource === curPath)
6571
+ || (curSource !== '' && curSource === rel)
6572
+ || (candSource !== '' && candSource === curSource)
6573
+ let score = 0
6574
+ if (maskLinked) score += 1000
6575
+ if (sameSize) score += 500
6576
+ const dtMin = (Number(cand.mtime) - Number(item.mtime)) / 60000
6577
+ if (dtMin > 0) score += 120
6578
+ score -= Math.min(240, Math.abs(dtMin) / 2)
6579
+ if (base !== '' && stemOf(cand.name) === base) score += 80
6580
+ out.push({ item: cand, sameSize, maskLinked, score })
6581
+ }
6582
+ out.sort((a, b) => b.score - a.score)
6583
+ return out.slice(0, 12)
6584
+ }, [items, item])
6585
+
6586
+ /** 选一张图作为对比对象:拉字节 → 转 object URL → 进对比视图。 */
6587
+ const pickCompare = React.useCallback((cand) => {
6588
+ const rel = String(cand?.relPath ?? '')
6589
+ if (rel === '') return
6590
+ setPickerOpen(false)
6591
+ releaseCmp()
6592
+ const controller = new AbortController()
6593
+ cmpAbortRef.current = controller
6594
+ setCmpTarget({
6595
+ relPath: rel,
6596
+ name: String(cand.name ?? rel.split('/').pop() ?? ''),
6597
+ width: Number(cand.width) || 0,
6598
+ height: Number(cand.height) || 0,
6599
+ status: 'loading',
6600
+ url: null,
6601
+ })
6602
+ fetchRaw(rel, controller.signal)
6603
+ .then((blob) => {
6604
+ if (controller.signal.aborted) return
6605
+ const url = URL.createObjectURL(blob)
6606
+ if (controller.signal.aborted) { URL.revokeObjectURL(url); return }
6607
+ cmpUrlRef.current = url
6608
+ setCmpTarget((cur) => (cur !== null && cur.relPath === rel
6609
+ ? { ...cur, status: 'ready', url }
6610
+ : cur))
6611
+ })
6612
+ .catch((error) => {
6613
+ if (controller.signal.aborted) return
6614
+ setCmpTarget((cur) => (cur !== null && cur.relPath === rel
6615
+ ? { ...cur, status: 'failed', message: String(error?.message ?? error) }
6616
+ : cur))
6617
+ })
6618
+ }, [releaseCmp])
6619
+
6620
+ /** 退出对比:清空对象、复位分割线、放掉 URL。 */
6621
+ const exitCompare = React.useCallback(() => {
6622
+ releaseCmp()
6623
+ setCmpTarget(null)
6624
+ setPickerOpen(false)
6625
+ setSplitPct(50)
6626
+ setCmpSwapped(false)
6627
+ }, [releaseCmp])
6628
+
6629
+ // 组件卸载时释放对比图
6630
+ React.useEffect(() => () => { releaseCmp() }, [releaseCmp])
6631
+
6632
+ // 从「批量选两张」进来时直接进对比:老板要的是选完就比,不再多点一步。
6633
+ // 只认第一次,之后左右翻页不重复触发。
6634
+ const initialCompareDoneRef = React.useRef(false)
6635
+ React.useEffect(() => {
6636
+ if (initialCompareDoneRef.current) return
6637
+ const rel = typeof initialCompare === 'string' ? initialCompare : ''
6638
+ if (rel === '') return
6639
+ const cand = items.find((it) => String(it?.relPath ?? '') === rel)
6640
+ if (cand === undefined) return
6641
+ initialCompareDoneRef.current = true
6642
+ pickCompare(cand)
6643
+ }, [initialCompare, items, pickCompare])
6644
+
6645
+ /** 把分割线移到指针所在的横向位置(百分比)。 */
6646
+ const moveSplitTo = React.useCallback((clientX) => {
6647
+ const node = bodyRef.current
6648
+ if (node === null) return
6649
+ const rect = node.getBoundingClientRect()
6650
+ const width = rect.width > 0 ? rect.width : 1
6651
+ const pct = ((clientX - rect.left) / width) * 100
6652
+ setSplitPct(Math.max(0, Math.min(100, pct)))
6653
+ }, [])
6654
+
6655
+ const onDividerDown = (event) => {
6656
+ if (cmpTarget === null) return
6657
+ event.preventDefault()
6658
+ event.stopPropagation()
6659
+ splitDragRef.current = true
6660
+ moveSplitTo(event.clientX)
6661
+ try { event.currentTarget.setPointerCapture(event.pointerId) } catch {}
6662
+ }
6663
+ const onDividerMove = (event) => {
6664
+ if (splitDragRef.current !== true) return
6665
+ event.preventDefault()
6666
+ event.stopPropagation()
6667
+ moveSplitTo(event.clientX)
6668
+ }
6669
+ const onDividerUp = (event) => {
6670
+ if (splitDragRef.current !== true) return
6671
+ splitDragRef.current = null
6672
+ try { event.currentTarget.releasePointerCapture(event.pointerId) } catch {}
6673
+ }
6268
6674
  const dragRef = React.useRef(null)
6269
6675
  // 上一次拖动是否真的产生了位移(用于区分「拖图」和「单击关闭」)
6270
6676
  const lastDragMoved = React.useRef(false)
@@ -6342,10 +6748,16 @@ ${absPath}
6342
6748
  setOriginalMode(false)
6343
6749
  setOriginal({ status: 'idle' })
6344
6750
  setCropActive(false)
6751
+ // 换图后对比对象失效:写盘路径不同,留着只会显示别人的图
6752
+ releaseCmp()
6753
+ setCmpTarget(null)
6754
+ setPickerOpen(false)
6755
+ setSplitPct(50)
6756
+ setCmpSwapped(false)
6345
6757
  return () => {
6346
6758
  if (originalAbortRef.current !== null) originalAbortRef.current.abort()
6347
6759
  }
6348
- }, [item.relPath])
6760
+ }, [item.relPath, releaseCmp])
6349
6761
 
6350
6762
  // 首次挂载时如果要求直接看原图,立刻开始加载。
6351
6763
  // 放在「换图重置」之后,顺序上不会再被清掉。
@@ -6440,28 +6852,64 @@ ${absPath}
6440
6852
 
6441
6853
  // 滚轮缩放:以鼠标位置为中心,避免放大后目标跑出视野(仅图片模式)。
6442
6854
  // 文本预览用原生滚动,不拦截滚轮。
6855
+ // 平铺对比时锚点要换成「光标所在那一格」的中心,见 onWheel 里的注释。
6856
+ const cmpTileRef = React.useRef(false)
6857
+ cmpTileRef.current = cmpTarget !== null && cmpMode === 'tile'
6443
6858
  React.useEffect(() => {
6444
6859
  const node = bodyRef.current
6445
6860
  if (node === null || state.status !== 'ready' || isText) return undefined
6446
6861
  const onWheel = (event) => {
6447
6862
  event.preventDefault()
6448
6863
  const delta = event.deltaY < 0 ? 1 : -1
6449
- const rect = node.getBoundingClientRect()
6450
- // 光标相对预览框中心的偏移
6451
- const cx = event.clientX - (rect.left + rect.width / 2)
6452
- const cy = event.clientY - (rect.top + rect.height / 2)
6453
-
6454
- setZoom((current) => {
6455
- const next = Math.min(MAX_ZOOM, Math.max(1, current + delta * ZOOM_STEP))
6456
- if (next === 1) { setPan({ x: 0, y: 0 }); return 1 }
6457
- // 以光标为不动点缩放:光标下的像素点在缩放前后保持同一屏幕位置
6864
+ // 不动点 = 光标下那张图的中心。图片的 transform-origin 是 center,
6865
+ // 只有把锚点选在「元素自身中心」上,光标下的那个像素才会在缩放前后停在同一处。
6866
+ // 平铺对比时左右两格各自居中,两个中心相差整整一格宽;若仍拿预览框中心去算,
6867
+ // 光标那一格的不动点会被算到隔壁半格,放大时画面往一侧窜 —— 看着就是「以鼠标为中心失灵」。
6868
+ const base = node.getBoundingClientRect()
6869
+ let anchorX = null
6870
+ let anchorY = null
6871
+ if (cmpTileRef.current) {
6872
+ const pane = event.target instanceof Element ? event.target.closest('.dg-cmpPane') : null
6873
+ if (pane !== null) {
6874
+ const paneRect = pane.getBoundingClientRect()
6875
+ anchorX = paneRect.left + paneRect.width / 2
6876
+ anchorY = paneRect.top + paneRect.height / 2
6877
+ }
6878
+ }
6879
+ const ownImg = imgRef.current
6880
+ if (anchorX === null && ownImg !== null && ownImg.offsetWidth > 0 && ownImg.offsetHeight > 0) {
6881
+ // offsetLeft/Top 相对预览框内边,且不含 transform 与缩放,正是图片未变换时的中心
6882
+ anchorX = base.left + ownImg.offsetLeft - node.scrollLeft + ownImg.offsetWidth / 2
6883
+ anchorY = base.top + ownImg.offsetTop - node.scrollTop + ownImg.offsetHeight / 2
6884
+ }
6885
+ if (anchorX === null) {
6886
+ anchorX = base.left + base.width / 2
6887
+ anchorY = base.top + base.height / 2
6888
+ }
6889
+ // 光标相对不动点的偏移
6890
+ const cx = event.clientX - anchorX
6891
+ const cy = event.clientY - anchorY
6892
+
6893
+ // 以光标为不动点缩放:光标下的像素点在缩放前后保持同一屏幕位置。
6894
+ // 关键:pan 只算一次。旧写法把它嵌在 setZoom updater 里,严格模式重跑会算两遍。
6895
+ const current = viewRef.current.zoom
6896
+ const next = Math.min(MAX_ZOOM, Math.max(1, current + delta * ZOOM_STEP))
6897
+ let nextPan
6898
+ if (next === 1) {
6899
+ nextPan = { x: 0, y: 0 }
6900
+ } else {
6458
6901
  const ratio = next / current
6459
- setPan((p) => ({
6902
+ const p = viewRef.current.pan
6903
+ nextPan = {
6460
6904
  x: cx - (cx - p.x) * ratio,
6461
6905
  y: cy - (cy - p.y) * ratio,
6462
- }))
6463
- return next
6464
- })
6906
+ }
6907
+ }
6908
+ // 即时写 ref(连续滚轮时下一帧能读到最新值),再分别 set,互不嵌套
6909
+ viewRef.current.zoom = next
6910
+ viewRef.current.pan = nextPan
6911
+ setZoom(next)
6912
+ setPan(nextPan)
6465
6913
  }
6466
6914
  node.addEventListener('wheel', onWheel, { passive: false })
6467
6915
  return () => node.removeEventListener('wheel', onWheel)
@@ -6528,6 +6976,9 @@ ${absPath}
6528
6976
  const onClickBody = (event) => {
6529
6977
  // 标注模式下点图只用于画框,不能顺手把大图关掉(老板 20:32 指出的冲突)
6530
6978
  if (annotActive) return
6979
+ // 对比态下点画面只是看图:平铺两格各占一半,鼠标想比细节时很容易点到,
6980
+ // 一点就把整个大图关了,退出对比请用工具栏按钮或 Esc。
6981
+ if (cmpTarget !== null) return
6531
6982
  // v0.16.0 裁剪模式下点击被裁剪层接管,不应关闭查看器
6532
6983
  if (cropActive) return
6533
6984
  event.preventDefault()
@@ -6582,11 +7033,14 @@ ${absPath}
6582
7033
  }, [vOverflow])
6583
7034
 
6584
7035
  const zoomBy = React.useCallback((direction) => {
6585
- setZoom((current) => {
6586
- const next = Math.min(MAX_ZOOM, Math.max(1, current + direction * ZOOM_STEP))
6587
- if (next === 1) setPan({ x: 0, y: 0 })
6588
- return next
6589
- })
7036
+ // 同滚轮:不在 updater 里嵌 setPan,从镜像 ref 读当前值,算好后分别 set
7037
+ const current = viewRef.current.zoom
7038
+ const next = Math.min(MAX_ZOOM, Math.max(1, current + direction * ZOOM_STEP))
7039
+ const nextPan = next === 1 ? { x: 0, y: 0 } : viewRef.current.pan
7040
+ viewRef.current.zoom = next
7041
+ viewRef.current.pan = nextPan
7042
+ setZoom(next)
7043
+ setPan(nextPan)
6590
7044
  }, [])
6591
7045
 
6592
7046
  /**
@@ -6612,13 +7066,24 @@ ${absPath}
6612
7066
  const key = event.key
6613
7067
  if (key === 'Escape') {
6614
7068
  event.preventDefault()
6615
- onClose()
6616
- } else if (key === 'ArrowLeft') {
7069
+ // 对比中先退对比:不然顺手把整个大图也关了,得重新找图
7070
+ if (cmpTarget !== null) exitCompare()
7071
+ else onClose()
7072
+ } else if (key === 'ArrowLeft' || key === 'ArrowRight') {
6617
7073
  event.preventDefault()
6618
- onStep(-1)
6619
- } else if (key === 'ArrowRight') {
7074
+ if (cmpTarget !== null) {
7075
+ // 对比时左右键归分割线(Shift 大步),避免一边看差异一边把图翻走
7076
+ const step = event.shiftKey ? 10 : 2
7077
+ setSplitPct((p) => Math.max(0, Math.min(100, p + (key === 'ArrowLeft' ? -step : step))))
7078
+ } else {
7079
+ onStep(key === 'ArrowLeft' ? -1 : 1)
7080
+ }
7081
+ } else if ((key === 'x' || key === 'X') && cmpTarget !== null) {
7082
+ event.preventDefault()
7083
+ setCmpSwapped((v) => !v)
7084
+ } else if ((key === 't' || key === 'T') && cmpTarget !== null) {
6620
7085
  event.preventDefault()
6621
- onStep(1)
7086
+ setCmpMode((m) => (m === 'slider' ? 'tile' : 'slider'))
6622
7087
  } else if (key === 'ArrowUp') {
6623
7088
  event.preventDefault()
6624
7089
  panStep(-1)
@@ -6652,7 +7117,7 @@ ${absPath}
6652
7117
  }
6653
7118
  window.addEventListener('keydown', onKey)
6654
7119
  return () => window.removeEventListener('keydown', onKey)
6655
- }, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath])
7120
+ }, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath, cmpTarget, exitCompare])
6656
7121
 
6657
7122
  const sliderDragRef = React.useRef(null)
6658
7123
  const onSliderPointerDown = (event) => {
@@ -6824,7 +7289,62 @@ ${absPath}
6824
7289
  event.stopPropagation()
6825
7290
  setCropActive((v) => !v)
6826
7291
  },
6827
- }, cropActive ? `✂ ${t('cropExit')}` : `✂ ${t('cropEnter')}`)
7292
+ }, cropActive ? `\u2702 ${t('cropExit')}` : `\u2702 ${t('cropEnter')}`)
7293
+ : null,
7294
+ // ---- 前后对比入口(2026-11-17)----
7295
+ // 未对比:一个「⇄ 对比」打开选图面板;对比中:换成 模式 / 对调 / 结束 三个。
7296
+ state.status === 'ready' && isImageItem(item) && !isText
7297
+ ? (cmpTarget === null
7298
+ ? h('button', {
7299
+ type: 'button',
7300
+ className: 'dg-btn' + (pickerOpen ? ' dg-btnActive' : ''),
7301
+ key: 'cmp',
7302
+ 'data-gallery-compare-toggle': true,
7303
+ 'aria-pressed': pickerOpen,
7304
+ title: t('cmpPickHint'),
7305
+ onClick: (event) => {
7306
+ event.stopPropagation()
7307
+ // 对比与批注/裁剪抢指针,进来先把那两个关掉
7308
+ setAnnotActive(false)
7309
+ setCropActive(false)
7310
+ setPickerOpen((v) => !v)
7311
+ },
7312
+ }, '\u21c4 ' + t('cmpEnter'))
7313
+ : h(React.Fragment, { key: 'cmpCtl' }, [
7314
+ h('button', {
7315
+ type: 'button',
7316
+ className: 'dg-btn dg-btnActive',
7317
+ key: 'mode',
7318
+ 'data-gallery-compare-mode': cmpMode,
7319
+ title: t('cmpSliderHint'),
7320
+ onClick: (event) => {
7321
+ event.stopPropagation()
7322
+ setCmpMode((m) => (m === 'slider' ? 'tile' : 'slider'))
7323
+ },
7324
+ }, cmpMode === 'slider' ? '\u25a5 ' + t('cmpModeTile') : '\u25eb ' + t('cmpModeSlider')),
7325
+ h('button', {
7326
+ type: 'button',
7327
+ className: 'dg-btn',
7328
+ key: 'swap',
7329
+ 'data-gallery-compare-swap': true,
7330
+ title: t('cmpSwap'),
7331
+ onClick: (event) => {
7332
+ event.stopPropagation()
7333
+ setCmpSwapped((v) => !v)
7334
+ },
7335
+ }, '\u21cb ' + t('cmpSwap')),
7336
+ h('button', {
7337
+ type: 'button',
7338
+ className: 'dg-btn',
7339
+ key: 'exit',
7340
+ 'data-gallery-compare-exit': true,
7341
+ title: t('cmpExit'),
7342
+ onClick: (event) => {
7343
+ event.stopPropagation()
7344
+ exitCompare()
7345
+ },
7346
+ }, '\u2715 ' + t('cmpExit')),
7347
+ ]))
6828
7348
  : null,
6829
7349
  // 「拖到对话」确定性入口:Viewer 大图本身 draggable:false + pointerEvents:none
6830
7350
  // (标注态的中键平移 / 右键多边形都依赖它),所以不改大图,另给一个可拖按钮。
@@ -6900,9 +7420,38 @@ ${absPath}
6900
7420
  pointerEvents: 'none',
6901
7421
  },
6902
7422
  }),
7423
+ // ---- 前后对比 · 滑块模式 ----
7424
+ // 关键点:clip 容器不参与 transform(按屏幕坐标裁),内层 img 才跟着缩放平移,
7425
+ // 于是「放大到 8 倍看同一处颗粒」时,分割线留在屏幕上不动、两边始终同一块画面。
7426
+ cmpTarget !== null && cmpMode === 'slider' && cmpTarget.status === 'ready' && imgBox !== null
7427
+ ? h('div', {
7428
+ key: 'cmpClip',
7429
+ className: 'dg-cmpClip',
7430
+ 'data-gallery-compare-clip': Math.round(splitPct),
7431
+ style: {
7432
+ clipPath: cmpSwapped === true
7433
+ ? `inset(0 0 0 ${splitPct}%)`
7434
+ : `inset(0 ${100 - splitPct}% 0 0)`,
7435
+ },
7436
+ }, h('img', {
7437
+ key: 'cmpImg',
7438
+ className: 'dg-cmpImg',
7439
+ src: cmpTarget.url,
7440
+ alt: cmpTarget.name,
7441
+ draggable: false,
7442
+ style: {
7443
+ left: imgBox.left + 'px',
7444
+ top: imgBox.top + 'px',
7445
+ width: imgBox.width + 'px',
7446
+ height: imgBox.height + 'px',
7447
+ transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
7448
+ transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
7449
+ },
7450
+ }))
7451
+ : null,
6903
7452
  // 批注层贴着图片真实布局盒,与图片共用同一组 zoom/pan。
6904
7453
  // imgBox 还没量出来(图片未布局)时不画框,免得拿容器当基准错位。
6905
- imgBox === null ? null : h(AnnotationLayer, {
7454
+ imgBox === null || cmpTarget !== null ? null : h(AnnotationLayer, {
6906
7455
  key: 'annot',
6907
7456
  t,
6908
7457
  annotations: annotsOfCurrent,
@@ -6920,15 +7469,96 @@ ${absPath}
6920
7469
  ? (a) => onExportMask(item, a)
6921
7470
  : undefined,
6922
7471
  }),
7472
+ // ---- 前后对比 · 平铺模式:左右各一格,共用同一组 pan/zoom ----
7473
+ cmpTarget !== null && cmpMode === 'tile'
7474
+ ? h('div', { key: 'cmpTile', className: 'dg-cmpTile', 'data-gallery-compare-tile': true }, [
7475
+ h('div', { key: 'paneA', className: 'dg-cmpPane' }, [
7476
+ cmpTarget.status === 'ready'
7477
+ ? h('img', {
7478
+ key: 'imgA',
7479
+ className: 'dg-cmpPaneImg',
7480
+ src: cmpSwapped === true
7481
+ ? (originalMode && original.status === 'ready' ? original.url : state.url)
7482
+ : cmpTarget.url,
7483
+ alt: '',
7484
+ draggable: false,
7485
+ style: {
7486
+ transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
7487
+ transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
7488
+ },
7489
+ })
7490
+ : h('span', { key: 'msgA', className: 'dg-cmpPaneMsg' },
7491
+ cmpTarget.status === 'failed' ? t('cmpFailed') : t('cmpLoading')),
7492
+ h('span', { key: 'tagA', className: 'dg-cmpPaneTag' },
7493
+ cmpSwapped === true ? t('cmpAfter') : t('cmpBefore')),
7494
+ ]),
7495
+ h('div', { key: 'paneB', className: 'dg-cmpPane' }, [
7496
+ h('img', {
7497
+ key: 'imgB',
7498
+ className: 'dg-cmpPaneImg',
7499
+ src: cmpSwapped === true
7500
+ ? cmpTarget.url
7501
+ : (originalMode && original.status === 'ready' ? original.url : state.url),
7502
+ alt: item.name,
7503
+ draggable: false,
7504
+ style: {
7505
+ transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
7506
+ transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
7507
+ },
7508
+ }),
7509
+ h('span', { key: 'tagB', className: 'dg-cmpPaneTag' },
7510
+ cmpSwapped === true ? t('cmpBefore') : t('cmpAfter')),
7511
+ ]),
7512
+ ])
7513
+ : null,
6923
7514
  ]))
6924
7515
  : state.status === 'binary'
6925
7516
  ? h('div', { className: 'dg-placeholder', key: 'bin' }, t('binaryHint'))
6926
7517
  : h('div', { className: state.status === 'failed' ? 'dg-placeholder dg-error' : 'dg-placeholder' },
6927
7518
  state.status === 'failed' ? `${t('thumbFailed')}:${item.name}` : t('loading')),
6928
7519
  ),
7520
+ // ---- 前后对比 · 选图面板 ----
7521
+ pickerOpen
7522
+ ? h(ComparePicker, {
7523
+ key: 'cmpPicker',
7524
+ t,
7525
+ candidates: cmpCandidates,
7526
+ onPick: (cand) => pickCompare(cand),
7527
+ onClose: () => setPickerOpen(false),
7528
+ })
7529
+ : null,
7530
+ // ---- 前后对比 · 滑块的标签与分割线(屏幕坐标,不随 pan/zoom)----
7531
+ cmpTarget !== null && cmpMode === 'slider'
7532
+ ? h('div', { key: 'cmpUi', className: 'dg-cmpUi', 'data-gallery-compare-ui': true }, [
7533
+ h('span', { key: 'tagL', className: 'dg-cmpTag dg-cmpTagL' },
7534
+ cmpSwapped === true ? t('cmpAfter') : t('cmpBefore')),
7535
+ h('span', { key: 'tagR', className: 'dg-cmpTag dg-cmpTagR' },
7536
+ cmpSwapped === true ? t('cmpBefore') : t('cmpAfter')),
7537
+ h('div', {
7538
+ key: 'handle',
7539
+ className: 'dg-cmpHandle',
7540
+ 'data-gallery-compare-handle': Math.round(splitPct),
7541
+ style: { left: splitPct + '%' },
7542
+ onPointerDown: onDividerDown,
7543
+ onPointerMove: onDividerMove,
7544
+ onPointerUp: onDividerUp,
7545
+ onPointerCancel: onDividerUp,
7546
+ }, [
7547
+ h('div', { key: 'line', className: 'dg-cmpLine' }),
7548
+ h('div', { key: 'grip', className: 'dg-cmpGrip' }, [
7549
+ h('span', { key: 'l', className: 'dg-cmpArrow' }, '\u2039'),
7550
+ h('span', { key: 'r', className: 'dg-cmpArrow' }, '\u203a'),
7551
+ ]),
7552
+ ]),
7553
+ cmpTarget.status === 'ready'
7554
+ ? null
7555
+ : h('div', { key: 'msg', className: 'dg-cmpMsg' },
7556
+ cmpTarget.status === 'failed' ? t('cmpFailed') : t('cmpLoading')),
7557
+ ])
7558
+ : null,
6929
7559
  slider,
6930
7560
  // v0.16.0 裁剪覆盖层:裁剪模式开启时显示(含微信式放大镜),固定在视口上、与 pan/zoom 解耦
6931
- cropActive && isImageItem(item) && !isText && state.status === 'ready'
7561
+ cropActive && cmpTarget === null && isImageItem(item) && !isText && state.status === 'ready'
6932
7562
  ? h(ImageCropper, {
6933
7563
  key: 'cropper',
6934
7564
  t,
@@ -8014,6 +8644,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8014
8644
  function GalleryBody(props) {
8015
8645
  const { t, sessionId } = props
8016
8646
  const [view, setView] = React.useState({ status: 'loading' })
8647
+ // 增量刷新用:读「当前列表」的最新值而不必进依赖数组。
8648
+ // 直接用 view 会让 useEffect 每次渲染都重建轮询器,而读 view 的闭包又拿不到最新值。
8649
+ const viewRef = React.useRef(view)
8650
+ React.useEffect(() => { viewRef.current = view }, [view])
8651
+
8017
8652
  // v0.17.0:本面板自己的轻提示(写进输入框的结果反馈)。
8018
8653
  // 不能用 FeedbackBasket 的 setNotice —— 那是另一个组件的局部 state。
8019
8654
  const [toast, setToast] = React.useState(null)
@@ -8395,6 +9030,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8395
9030
  * 两者混同就会重演「删一条反馈把定好的标签也撤了」的错。
8396
9031
  */
8397
9032
  const [pendingCount, setPendingCount] = React.useState(0)
9033
+ // v1.3.0:Agent 批示(gallery_reply 写进 feedback.json,kind='agent-reply')。
9034
+ // 每项 = { relPath, text, replyOf, markedAt };只在反馈栏显示,不进草稿、不自动清。
9035
+ const [agentReplies, setAgentReplies] = React.useState({})
8398
9036
  // 编辑中的条目(null 表示不编辑)
8399
9037
  const [editingItem, setEditingItem] = React.useState(null)
8400
9038
  // 网格滚动位置:打开查看器前记录,关闭后恢复,让视图停在原缩略图处
@@ -8417,13 +9055,32 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8417
9055
  })
8418
9056
  .catch((error) => console.warn('dsh-gallery: getLabels 失败', error))
8419
9057
  // v0.16.4 · B 档:台面打开时读一次待处理条数(纯读,不标记已读)
8420
- callHost('getPendingFeedback', {})
8421
- .then((payload) => {
8422
- if (!alive || payload?.ok === false) return
8423
- setPendingCount(Number.isFinite(payload?.count) ? payload.count : 0)
8424
- })
9058
+ // v1.3.0:顺带提取 Agent 批示(kind='agent-reply')供反馈栏显示
9059
+ const applyPending = (payload) => {
9060
+ if (!alive || payload?.ok === false) return
9061
+ setPendingCount(Number.isFinite(payload?.count) ? payload.count : 0)
9062
+ const replies = {}
9063
+ for (const it of (Array.isArray(payload?.items) ? payload.items : [])) {
9064
+ if (String(it?.kind ?? '') !== 'agent-reply') continue
9065
+ const rel = String(it?.relPath ?? '')
9066
+ if (rel === '') continue
9067
+ replies[rel] = {
9068
+ relPath: rel,
9069
+ text: String(it?.replyText ?? ''),
9070
+ replyOf: String(it?.replyOf ?? ''),
9071
+ markedAt: Number(it?.markedAt) || 0,
9072
+ }
9073
+ }
9074
+ setAgentReplies(replies)
9075
+ }
9076
+ callHost('getPendingFeedback', {}).then(applyPending)
8425
9077
  .catch((error) => console.warn('dsh-gallery: getPendingFeedback 失败', error))
8426
- return () => { alive = false }
9078
+ // v1.3.0:Agent 是另一个进程,改完图写批示时台面可能一直开着 —— 低频轮询让批示自己出现。
9079
+ // 只读、不清零;人核准走显式 ackFeedback。
9080
+ const replyTimer = setInterval(() => {
9081
+ callHost('getPendingFeedback', {}).then(applyPending).catch(() => {})
9082
+ }, 5000)
9083
+ return () => { alive = false; clearInterval(replyTimer) }
8427
9084
  }, [])
8428
9085
 
8429
9086
  /** 手动标签覆写:只读独立 labels 文件,与反馈篮条目互不影响。 */
@@ -8535,6 +9192,49 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8535
9192
  }
8536
9193
  }, [])
8537
9194
 
9195
+ /**
9196
+ * v1.3.0:核准 Agent 批示 —— 清掉该条批示,本地 state 同步移除。
9197
+ * 只 ack 这一条批示,不碰同图的人写反馈(setFeedback 按 relPath 存,同 path 只有一条,
9198
+ * 这里 ack 后若人还有意见会重新写;批示与人意见同 path 时本就以最新为准)。
9199
+ */
9200
+ const ackAgentReply = React.useCallback(async (relPath) => {
9201
+ await ackPending([relPath])
9202
+ setAgentReplies((prev) => {
9203
+ if (!(relPath in prev)) return prev
9204
+ const next = { ...prev }
9205
+ delete next[relPath]
9206
+ return next
9207
+ })
9208
+ }, [ackPending])
9209
+
9210
+ /**
9211
+ * v1.3.0:驳回 Agent 批示 —— 先清批示,再把该图标成「交付不合格」让人补一句意见,
9212
+ * 这样 Agent 下次取回的就是人的驳回意见,而不是那条已完成的批示。全程不发送。
9213
+ */
9214
+ const rejectAgentReply = React.useCallback(async (relPath) => {
9215
+ const reply = agentReplies[relPath]
9216
+ // 先清批示,再写人的驳回表态 —— 顺序不能反,否则 recordPendingFeedback 会把批示覆盖掉
9217
+ await ackPending([relPath])
9218
+ setAgentReplies((prev) => {
9219
+ if (!(relPath in prev)) return prev
9220
+ const next = { ...prev }
9221
+ delete next[relPath]
9222
+ return next
9223
+ })
9224
+ // 这个回调在 GalleryBody 作用域,没有 locale 变量 —— 用 t 探测一次(与 FeedbackBasket 同口径)
9225
+ let isEn = false
9226
+ try { isEn = !/[\u4e00-\u9fa5]/.test(String(t('feedbackBasketTitle') ?? '')) } catch { isEn = false }
9227
+ const reason = (isEn ? 'Rejected the agent reply. ' : '驳回 Agent 的这次修改。')
9228
+ + (reply?.text ? (isEn ? 'Reply was: ' : '原批示:') + reply.text : '')
9229
+ const mark = { action: 'reject', reason, markedAt: Date.now() }
9230
+ setMarks((prev) => ({ ...prev, [relPath]: mark }))
9231
+ try {
9232
+ await callHost('marks', { path: relPath, mark })
9233
+ } catch { /* 写回失败不阻断本地状态 */ }
9234
+ // 同步待处理反馈:人驳回=一条新的待处理意见,Agent 下次取回的就是它
9235
+ await recordPendingFeedback([{ path: relPath, item: { action: 'reject', reason } }])
9236
+ }, [ackPending, agentReplies, t, recordPendingFeedback])
9237
+
8538
9238
  /**
8539
9239
  * 手动改标签的主逻辑(v0.14.2)。
8540
9240
  *
@@ -8850,7 +9550,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8850
9550
  * 分组视图下卡片来自 `data.groups[i].files`,与当前页的扁平 `items` 是两个不同的集合,
8851
9551
  * 直接用全局 `items` 的索引会「点哪张都跳出同一张图」。
8852
9552
  */
8853
- const openViewer = React.useCallback((index, anchorEl, list, asOriginal, origin) => {
9553
+ const openViewer = React.useCallback((index, anchorEl, list, asOriginal, origin, compareRel) => {
8854
9554
  const scroller = bodyScrollRef.current
8855
9555
  if (scroller !== null) {
8856
9556
  savedScrollRef.current = {
@@ -8889,6 +9589,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8889
9589
  const originSid = String(origin?.sessionId ?? '')
8890
9590
  setViewer({
8891
9591
  index, list: snapshot, asOriginal: asOriginal === true,
9592
+ // 2026-11-17:批量选两张时带进来,查看器一开就进对比,不用再点一次
9593
+ compareRel: String(compareRel ?? ''),
8892
9594
  originSid: originSid === '__history__' ? '' : originSid,
8893
9595
  originTitle: originSid === '__history__' ? '' : String(origin?.title ?? ''),
8894
9596
  })
@@ -8970,6 +9672,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8970
9672
  const payload = await callHost('delete', { path: target.item.relPath, confirm: true })
8971
9673
  if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
8972
9674
  setDeleteTarget(null)
9675
+ kickChanges()
8973
9676
  await load(undefined, kind, scope, page).then((data) => setView({ status: 'ready', data })).catch(() => {})
8974
9677
  } catch (error) {
8975
9678
  console.error('dsh-gallery: 删除失败', error)
@@ -9106,6 +9809,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9106
9809
  }
9107
9810
  }
9108
9811
  if (okCount > 0) {
9812
+ kickChanges()
9109
9813
  void refresh()
9110
9814
  if (lastErr !== '') console.warn('dsh-gallery: 部分粘贴失败', lastErr)
9111
9815
  return
@@ -9272,7 +9976,120 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9272
9976
  }
9273
9977
  }, [load, kind, scope, page])
9274
9978
 
9275
- // 自动刷新:定时拉取最新列表;查看器打开时暂停,避免打断放大查看
9979
+ // ---- 增量刷新(2026-11-16)----
9980
+ // 任何进程往产出根里写资产,Host 侧 fs.watch 都会感知并递增版本号。
9981
+ // 这里每秒问一次「变了没」,只重取受影响的那个对话组,其它组不动。
9982
+ //
9983
+ // 为什么不用整表 refresh:几百张卡整表替换会让滚动位置跳动、卡片重排闪一下。
9984
+ // 局部替换时其它组对象引用保持不变,React 就不会重绘它们。
9985
+ const changesVersionRef = React.useRef(0)
9986
+ const changesBusyRef = React.useRef(false)
9987
+ // v1.3.0:最近一批「新增资产」的时间戳 —— 用来高亮这批刚产出的终稿。
9988
+ // 只认 added>0 的变动,避免删除/改标签也触发高亮。state 让卡片重绘。
9989
+ const [lastBatchAt, setLastBatchAt] = React.useState(0)
9990
+ // 写操作后主动催一次检查(不等 1 秒轮询),用户点了就该立刻看到结果
9991
+ const changesKickRef = React.useRef(null)
9992
+
9993
+ React.useEffect(() => {
9994
+ // 看大图时不打扰:列表在背景变化会让关掉大图后位置跳动
9995
+ if (viewer !== null) return undefined
9996
+ let alive = true
9997
+
9998
+ const tick = async () => {
9999
+ if (!alive || changesBusyRef.current) return
10000
+ changesBusyRef.current = true
10001
+ try {
10002
+ const r = await callHost('changes', { since: changesVersionRef.current })
10003
+ if (!alive || r?.ok !== true) return
10004
+ const v = Number(r.version) || 0
10005
+ if (v <= changesVersionRef.current) return
10006
+ changesVersionRef.current = v
10007
+ const changed = Array.isArray(r.changed) ? r.changed : []
10008
+
10009
+ // v1.3.0:记下这批新增的时间,供卡片高亮「刚产出的终稿」
10010
+ const addTimes = changed
10011
+ .filter((c) => Number(c?.added) > 0)
10012
+ .map((c) => Number(c?.at) || 0)
10013
+ .filter((t) => t > 0)
10014
+ if (addTimes.length > 0) setLastBatchAt(Math.max(...addTimes))
10015
+
10016
+ // 决定「能不能局部刷」:只有分组视图且每个变动都有明确会话才能局部。
10017
+ // 读 viewRef(不是 view)拿最新值,避免闭包过期。
10018
+ const cur = viewRef.current
10019
+ const groups = (cur?.status === 'ready' && Array.isArray(cur.data?.groups))
10020
+ ? cur.data.groups : null
10021
+ const canPartial = groups !== null
10022
+ && scope !== 'session'
10023
+ && changed.length > 0
10024
+ && changed.every((c) => String(c?.sessionId ?? '') !== '')
10025
+
10026
+ if (!canPartial) { void refresh(); return }
10027
+
10028
+ // 逐个组重取明细
10029
+ const fresh = new Map()
10030
+ let needFull = false
10031
+ for (const c of changed) {
10032
+ const sid = String(c?.sessionId ?? '')
10033
+ if (sid === '') { needFull = true; break }
10034
+ try {
10035
+ const p = await callHost('groupMore', { kind, scope, sessionId: sid, page: 1 })
10036
+ if (p?.ok === false) { needFull = true; break }
10037
+ fresh.set(sid, p)
10038
+ } catch { needFull = true; break }
10039
+ }
10040
+ if (!alive) return
10041
+ if (needFull) { void refresh(); return }
10042
+
10043
+ // 局部替换:只动变化的组,其它组对象引用不变
10044
+ let sawUnknownGroup = false
10045
+ setView((prev) => {
10046
+ if (prev.status !== 'ready' || !Array.isArray(prev.data?.groups)) return prev
10047
+ const nextGroups = prev.data.groups.slice()
10048
+ let dirty = false
10049
+ for (const [sid, p] of fresh.entries()) {
10050
+ const idx = nextGroups.findIndex((g) => String(g?.sessionId ?? '') === sid)
10051
+ if (idx < 0) { sawUnknownGroup = true; continue }
10052
+ const files = Array.isArray(p?.files) ? p.files
10053
+ : (Array.isArray(p?.items) ? p.items : null)
10054
+ if (files === null) { sawUnknownGroup = true; continue }
10055
+ nextGroups[idx] = {
10056
+ ...nextGroups[idx],
10057
+ files,
10058
+ fileCount: typeof p.fileCount === 'number' ? p.fileCount : nextGroups[idx].fileCount,
10059
+ returnedCount: files.length,
10060
+ counts: p.counts ?? nextGroups[idx].counts,
10061
+ latestMtime: p.latestMtime ?? nextGroups[idx].latestMtime,
10062
+ }
10063
+ dirty = true
10064
+ }
10065
+ if (!dirty) return prev
10066
+ return { ...prev, data: { ...prev.data, groups: nextGroups } }
10067
+ })
10068
+ // 出现了列表里还没有的会话组(新对话刚产出第一条)→ 补一次整表,把新组插进来
10069
+ if (sawUnknownGroup) { void refresh(); return }
10070
+ void callHost('changesAck', { since: v }).catch(() => {})
10071
+ } catch { /* 轮询失败静默,下个周期再试 */ }
10072
+ finally { changesBusyRef.current = false }
10073
+ }
10074
+
10075
+ // 外部(写操作回调)可以调这个立即催一次
10076
+ changesKickRef.current = () => { void tick() }
10077
+
10078
+ const timer = setInterval(() => { void tick() }, 1000)
10079
+ return () => {
10080
+ alive = false
10081
+ changesKickRef.current = null
10082
+ clearInterval(timer)
10083
+ }
10084
+ }, [callHost, kind, scope, viewer, refresh])
10085
+
10086
+ /** 写操作成功后调用:立刻检查一次变动,不用等 1 秒轮询 */
10087
+ const kickChanges = React.useCallback(() => {
10088
+ const fn = changesKickRef.current
10089
+ if (typeof fn === 'function') fn()
10090
+ }, [])
10091
+
10092
+ // 兜底自动刷新:轮询已覆盖绝大部分,这里放长周期防漏(外部程序写入 fs.watch 漏报时)
9276
10093
  React.useEffect(() => {
9277
10094
  if (viewer !== null) return undefined
9278
10095
  let alive = true
@@ -9353,6 +10170,33 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9353
10170
  const groupsRef = React.useRef(null)
9354
10171
  groupsRef.current = Array.isArray(data?.groups) ? data.groups : null
9355
10172
 
10173
+ /**
10174
+ * v1.3.0:这批刚产出的终稿(用于资产台高亮,上限 3 张)。
10175
+ * 口径:全视图(含分组)里 category=final 且 mtime 落在最近新增批次内的资产,
10176
+ * 按 mtime 取最新 3 个。lastBatchAt=0 时不高亮任何卡片(初始没有"这批")。
10177
+ */
10178
+ const freshFinalSet = React.useMemo(() => {
10179
+ if (!lastBatchAt || lastBatchAt <= 0) return new Set()
10180
+ const all = [
10181
+ ...(Array.isArray(items) ? items : []),
10182
+ ...(Array.isArray(data?.groups) ? data.groups.flatMap((g) => (Array.isArray(g?.files) ? g.files : [])) : []),
10183
+ ]
10184
+ const seen = new Set()
10185
+ const fresh = []
10186
+ for (const it of all) {
10187
+ const rel = String(it?.relPath ?? '')
10188
+ if (rel === '' || seen.has(rel)) continue
10189
+ if (String(it?.category ?? '') !== 'final') continue
10190
+ const mt = Number(it?.mtime) || 0
10191
+ // 5 秒容差:fs.watch 的 at 与文件 mtime 可能差几秒
10192
+ if (mt < lastBatchAt - 5000) continue
10193
+ seen.add(rel)
10194
+ fresh.push({ rel, mt })
10195
+ }
10196
+ fresh.sort((a, b) => b.mt - a.mt)
10197
+ return new Set(fresh.slice(0, 3).map((x) => x.rel))
10198
+ }, [items, data, lastBatchAt])
10199
+
9356
10200
  // 分组首次渲染时,默认展开「当前对话」那一组(没有则展开第一组)。
9357
10201
  // 只做一次:之后用户手动收起/展开都保留。
9358
10202
  React.useEffect(() => {
@@ -9573,6 +10417,36 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9573
10417
  * 批量操作条(v0.13.7)—— 有选中项时出现。
9574
10418
  * 三个动作:确认 / 取消确认 / 清除标记,**全部只改标记、不碰磁盘**。
9575
10419
  */
10420
+ /**
10421
+ * 批量选了两张 → 直接进对比(2026-11-17)。
10422
+ * 第一张当主图(右/后),第二张当对比图(左/前);两张同尺寸时最准。
10423
+ */
10424
+ const openCompareFromSelection = React.useCallback(() => {
10425
+ const rels = [...selected]
10426
+ if (rels.length !== 2) return
10427
+ const pool = Array.isArray(items) ? items.slice() : []
10428
+ if (Array.isArray(data?.groups)) {
10429
+ for (const gr of data.groups) {
10430
+ for (const f of (Array.isArray(gr.files) ? gr.files : [])) pool.push(f)
10431
+ }
10432
+ }
10433
+ const first = pool.find((it) => String(it?.relPath ?? '') === rels[0])
10434
+ const second = pool.find((it) => String(it?.relPath ?? '') === rels[1])
10435
+ if (first === undefined || second === undefined) {
10436
+ showPasteNotice('fail', t('cmpPickEmpty'))
10437
+ return
10438
+ }
10439
+ // 查看器的翻页范围尽量沿用当前可见列表;两张不全在里面就只用这两张
10440
+ let list = visibleItems.length > 0 ? visibleItems : (Array.isArray(items) ? items : [])
10441
+ const hasBoth = list.some((it) => String(it?.relPath ?? '') === rels[0])
10442
+ && list.some((it) => String(it?.relPath ?? '') === rels[1])
10443
+ if (!hasBoth) list = [first, second]
10444
+ const idx = Math.max(0, list.findIndex((it) => String(it?.relPath ?? '') === rels[0]))
10445
+ setSelected(new Set())
10446
+ setBatchMode(false)
10447
+ openViewer(idx, null, list, false, null, rels[1])
10448
+ }, [selected, items, data, visibleItems, openViewer, showPasteNotice, t])
10449
+
9576
10450
  const selectedCount = selected.size
9577
10451
  const batchBar = selectedCount > 0
9578
10452
  ? h('div', { className: 'dg-batchBar', key: 'batchBar', 'data-gallery-batch-bar': true }, [
@@ -9592,6 +10466,15 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9592
10466
  title: t('batchCopyHint'),
9593
10467
  onClick: () => { void doCopyAssets([...selected]) },
9594
10468
  }, `⧉ ${t('batchCopyFiles')} (${selectedCount})`),
10469
+ // 2026-11-17:正好选两张时给「对比」入口
10470
+ selectedCount === 2
10471
+ ? h('button', {
10472
+ type: 'button', className: 'dg-btn dg-btnSmall dg-primaryBtn', key: 'compare',
10473
+ 'data-gallery-batch-compare': true,
10474
+ title: t('cmpBatchHint'),
10475
+ onClick: () => openCompareFromSelection(),
10476
+ }, '\u21c4 ' + t('cmpBatchEnter'))
10477
+ : null,
9595
10478
  h('button', {
9596
10479
  type: 'button', className: 'dg-btn dg-btnSmall', key: 'clearmark',
9597
10480
  'data-gallery-batch-clear': true,
@@ -9791,8 +10674,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9791
10674
  const showCheckbox = selectMode || checked
9792
10675
  const manual = manualLabelOf(item.relPath)
9793
10676
  const isManual = manual !== null && manual !== undefined
10677
+ // v1.3.0:这批刚产出的终稿加高亮 class(上限 3 张,由 freshFinalSet 控制)
10678
+ const isFreshFinal = freshFinalSet.has(item.relPath)
9794
10679
  return h('div', {
9795
- className: `dg-cardWrap${checked ? ' dg-cardChecked' : ''}${selectMode ? ' dg-cardSelectable' : ''}`,
10680
+ className: `dg-cardWrap${checked ? ' dg-cardChecked' : ''}${selectMode ? ' dg-cardSelectable' : ''}${isFreshFinal ? ' dg-cardFreshFinal' : ''}`,
10681
+ 'data-gallery-fresh-final': isFreshFinal ? '1' : '0',
9796
10682
  key: key + ':wrap',
9797
10683
  'data-gallery-card-wrap': item.relPath,
9798
10684
  'data-gallery-bucket': bucket,
@@ -10281,6 +11167,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10281
11167
  index: Math.min(viewer.index, viewer.list.length - 1),
10282
11168
  t,
10283
11169
  initialOriginal: viewer.asOriginal === true,
11170
+ initialCompare: String(viewer.compareRel ?? ''),
10284
11171
  onClose: closeViewer,
10285
11172
  onStep: step,
10286
11173
  onCrop: doCrop,
@@ -10361,6 +11248,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10361
11248
  const feedbackPaths = Array.from(new Set([
10362
11249
  ...Object.keys(marks),
10363
11250
  ...Object.keys(annotations),
11251
+ ...Object.keys(agentReplies),
10364
11252
  ]))
10365
11253
  const markedList = feedbackPaths.map((relPath) => {
10366
11254
  // 从当前视图里找该条目,拿 category / sessionId
@@ -10378,6 +11266,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10378
11266
  maskOf: maskBySource.get(relPath) ?? found?.maskOf,
10379
11267
  mark: marks[relPath],
10380
11268
  annotations: Array.isArray(annotations[relPath]) ? annotations[relPath] : [],
11269
+ // v1.3.0:Agent 批示(只在反馈栏显示成卡片,不进草稿、不参与序号)
11270
+ reply: agentReplies[relPath] ?? null,
10381
11271
  }
10382
11272
  })
10383
11273
  const feedbackLayer = basketOpen && markedList.length >= 0
@@ -10407,6 +11297,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10407
11297
  },
10408
11298
  // v0.16.4:草稿进 composer 后把待处理清零(人已处理完这批)
10409
11299
  onAck: (paths) => { void ackPending(paths) },
11300
+ // v1.3.0:Agent 批示的核准 / 驳回(独立于普通草稿流程)
11301
+ onAckReply: (relPath) => { void ackAgentReply(relPath) },
11302
+ onRejectReply: (relPath) => { void rejectAgentReply(relPath) },
10410
11303
  })
10411
11304
  : null
10412
11305