dsh-gallery 1.1.0 → 1.2.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 +62 -0
- package/README.md +20 -4
- package/client.js +739 -31
- package/host/changes.js +236 -0
- package/host/http.js +57 -0
- package/index.js +50 -1
- package/package.json +8 -4
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:三段式 ===== */
|
|
@@ -5175,6 +5254,7 @@ function serializeFeedback(feedback) {
|
|
|
5175
5254
|
text: format(t('mediaGrabFrameSaved'), { name: payload?.name ?? '', timecode: payload?.timecode ?? '' }),
|
|
5176
5255
|
})
|
|
5177
5256
|
// 立刻重扫:新资产出现在当前对话组,可马上点开批注 / 进反馈篮
|
|
5257
|
+
kickChanges()
|
|
5178
5258
|
if (typeof onSaved === 'function') onSaved(payload)
|
|
5179
5259
|
} catch (error) {
|
|
5180
5260
|
setGrabNotice({ kind: 'failed', text: format(t('mediaGrabFrameFailed'), { message: String(error?.message ?? error) }) })
|
|
@@ -6252,7 +6332,97 @@ ${absPath}
|
|
|
6252
6332
|
])
|
|
6253
6333
|
}
|
|
6254
6334
|
|
|
6255
|
-
|
|
6335
|
+
/**
|
|
6336
|
+
* 对比选图面板(2026-11-17)。
|
|
6337
|
+
* 老板要求「选图要方便快捷」,所以只做一件事:格子一列,点一下就进对比,选完立即关。
|
|
6338
|
+
* 缩略图沿用卡片那套 fetchRaw + makeScaled,不额外开后端路由。
|
|
6339
|
+
*/
|
|
6340
|
+
function ComparePicker({ t, candidates, onPick, onClose }) {
|
|
6341
|
+
return h('div', {
|
|
6342
|
+
className: 'dg-cmpPicker',
|
|
6343
|
+
'data-gallery-compare-picker': true,
|
|
6344
|
+
onClick: (event) => event.stopPropagation(),
|
|
6345
|
+
}, [
|
|
6346
|
+
h('div', { key: 'head', className: 'dg-cmpPickerHead' }, [
|
|
6347
|
+
h('span', { key: 'title', className: 'dg-cmpPickerTitle' }, t('cmpPickTitle')),
|
|
6348
|
+
h('button', {
|
|
6349
|
+
key: 'close',
|
|
6350
|
+
type: 'button',
|
|
6351
|
+
className: 'dg-btn dg-btnTiny',
|
|
6352
|
+
'data-gallery-compare-picker-close': true,
|
|
6353
|
+
onClick: (event) => { event.stopPropagation(); onClose() },
|
|
6354
|
+
}, '\u2715'),
|
|
6355
|
+
]),
|
|
6356
|
+
h('div', { key: 'hint', className: 'dg-cmpPickerHint' }, t('cmpPickHint')),
|
|
6357
|
+
candidates.length === 0
|
|
6358
|
+
? h('div', { key: 'empty', className: 'dg-cmpPickerEmpty' }, t('cmpPickEmpty'))
|
|
6359
|
+
: h('div', { key: 'grid', className: 'dg-cmpPickerGrid' },
|
|
6360
|
+
candidates.map((cand, i) => h(ComparePickCard, {
|
|
6361
|
+
key: cand.item.relPath,
|
|
6362
|
+
t,
|
|
6363
|
+
cand,
|
|
6364
|
+
recommend: i < 3,
|
|
6365
|
+
onPick,
|
|
6366
|
+
}))),
|
|
6367
|
+
])
|
|
6368
|
+
}
|
|
6369
|
+
|
|
6370
|
+
/** 单个候选:缩略图 + 文件名 + 尺寸(不同尺寸标出来,免得以为没对齐是 bug)。 */
|
|
6371
|
+
function ComparePickCard({ t, cand, recommend, onPick }) {
|
|
6372
|
+
const [url, setUrl] = React.useState(null)
|
|
6373
|
+
const relPath = String(cand.item.relPath ?? '')
|
|
6374
|
+
React.useEffect(() => {
|
|
6375
|
+
if (relPath === '') return undefined
|
|
6376
|
+
let cancelled = false
|
|
6377
|
+
let objUrl = null
|
|
6378
|
+
const controller = new AbortController()
|
|
6379
|
+
fetchRaw(relPath, controller.signal)
|
|
6380
|
+
.then(async (blob) => {
|
|
6381
|
+
const thumb = await makeScaled(blob, THUMB_SIZE, true)
|
|
6382
|
+
if (cancelled) {
|
|
6383
|
+
if (thumb.url !== null) URL.revokeObjectURL(thumb.url)
|
|
6384
|
+
return
|
|
6385
|
+
}
|
|
6386
|
+
objUrl = thumb.url
|
|
6387
|
+
setUrl(thumb.url)
|
|
6388
|
+
})
|
|
6389
|
+
.catch(() => {})
|
|
6390
|
+
return () => {
|
|
6391
|
+
cancelled = true
|
|
6392
|
+
controller.abort()
|
|
6393
|
+
if (objUrl !== null) URL.revokeObjectURL(objUrl)
|
|
6394
|
+
}
|
|
6395
|
+
}, [relPath])
|
|
6396
|
+
|
|
6397
|
+
const w = Number(cand.item.width) || 0
|
|
6398
|
+
const hh = Number(cand.item.height) || 0
|
|
6399
|
+
return h('button', {
|
|
6400
|
+
type: 'button',
|
|
6401
|
+
className: 'dg-cmpCard',
|
|
6402
|
+
'data-gallery-compare-cand': relPath,
|
|
6403
|
+
'data-gallery-compare-samesize': cand.sameSize ? '1' : '0',
|
|
6404
|
+
title: relPath,
|
|
6405
|
+
onClick: (event) => {
|
|
6406
|
+
event.stopPropagation()
|
|
6407
|
+
onPick(cand.item)
|
|
6408
|
+
},
|
|
6409
|
+
}, [
|
|
6410
|
+
h('span', { key: 'thumb', className: 'dg-cmpCardThumb' },
|
|
6411
|
+
url === null ? null : h('img', { key: 'i', src: url, alt: '', draggable: false })),
|
|
6412
|
+
recommend === true
|
|
6413
|
+
? h('span', { key: 'rec', className: 'dg-cmpCardRec' }, t('cmpRecommend'))
|
|
6414
|
+
: null,
|
|
6415
|
+
h('span', { key: 'meta', className: 'dg-cmpCardMeta' }, [
|
|
6416
|
+
h('span', { key: 'name', className: 'dg-cmpCardName' }, String(cand.item.name ?? '')),
|
|
6417
|
+
h('span', {
|
|
6418
|
+
key: 'size',
|
|
6419
|
+
className: 'dg-cmpCardSize' + (cand.sameSize ? '' : ' dg-cmpCardSizeDiff'),
|
|
6420
|
+
}, cand.sameSize ? w + '\u00d7' + hh : t('cmpSizeDiff')),
|
|
6421
|
+
]),
|
|
6422
|
+
])
|
|
6423
|
+
}
|
|
6424
|
+
|
|
6425
|
+
function Viewer({ items, index, onClose, onStep, t, initialOriginal, initialCompare, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop, onCopyFile }) {
|
|
6256
6426
|
const item = items[index]
|
|
6257
6427
|
// 文件预览已改走 DSH 原生侧栏(session 地址);此处 Viewer 仅处理图片,isText 恒 false,
|
|
6258
6428
|
// 下面的文本分支保留为死代码,供 v0.2 若需插件内预览时复用
|
|
@@ -6260,11 +6430,173 @@ ${absPath}
|
|
|
6260
6430
|
const [state, setState] = React.useState({ status: 'pending' })
|
|
6261
6431
|
const [zoom, setZoom] = React.useState(1)
|
|
6262
6432
|
const [pan, setPan] = React.useState({ x: 0, y: 0 })
|
|
6433
|
+
// 视图状态镜像:滚轮用原生监听,且绝不能把 setPan 嵌进 setZoom 的 updater。
|
|
6434
|
+
// updater 必须是纯函数;React 严格模式会把它跑两遍,pan 就被算两次 ——
|
|
6435
|
+
// 表现正是「平铺下以鼠标为中心缩放失灵」(实测漂移约 15px)。改用 ref 读当前值、
|
|
6436
|
+
// 算好后分别 set;渲染体每帧回写,让拖拽/按钮的改动也能同步进 ref。
|
|
6437
|
+
const viewRef = React.useRef({ zoom: 1, pan: { x: 0, y: 0 } })
|
|
6438
|
+
viewRef.current.zoom = zoom
|
|
6439
|
+
viewRef.current.pan = pan
|
|
6263
6440
|
const [dragging, setDragging] = React.useState(false)
|
|
6264
6441
|
const bodyRef = React.useRef(null)
|
|
6265
6442
|
const imgRef = React.useRef(null)
|
|
6266
6443
|
/** 图片在预览容器里的真实布局盒(不含 transform);批注层据此对齐,1:1 也不跑偏。 */
|
|
6267
6444
|
const [imgBox, setImgBox] = React.useState(null)
|
|
6445
|
+
|
|
6446
|
+
// ---- 前后对比(2026-11-17)----
|
|
6447
|
+
// 老板口径:手动选两张为主路,智能推荐为辅(优先「生成遮罩的原素材 ↔ 成稿」)。
|
|
6448
|
+
// 对比图单独走一次 fetchRaw,跟「原图模式」互不复用,换图即释放。
|
|
6449
|
+
const [cmpTarget, setCmpTarget] = React.useState(null)
|
|
6450
|
+
const [cmpMode, setCmpMode] = React.useState('slider')
|
|
6451
|
+
const [splitPct, setSplitPct] = React.useState(50)
|
|
6452
|
+
const [pickerOpen, setPickerOpen] = React.useState(false)
|
|
6453
|
+
const [cmpSwapped, setCmpSwapped] = React.useState(false)
|
|
6454
|
+
const cmpAbortRef = React.useRef(null)
|
|
6455
|
+
const cmpUrlRef = React.useRef(null)
|
|
6456
|
+
const splitDragRef = React.useRef(null)
|
|
6457
|
+
|
|
6458
|
+
/** 释放对比图占用的 object URL 与请求。 */
|
|
6459
|
+
const releaseCmp = React.useCallback(() => {
|
|
6460
|
+
if (cmpAbortRef.current !== null) {
|
|
6461
|
+
try { cmpAbortRef.current.abort() } catch {}
|
|
6462
|
+
cmpAbortRef.current = null
|
|
6463
|
+
}
|
|
6464
|
+
if (cmpUrlRef.current !== null) {
|
|
6465
|
+
URL.revokeObjectURL(cmpUrlRef.current)
|
|
6466
|
+
cmpUrlRef.current = null
|
|
6467
|
+
}
|
|
6468
|
+
}, [])
|
|
6469
|
+
|
|
6470
|
+
/**
|
|
6471
|
+
* 对比候选排序。信号按可靠度叠加:
|
|
6472
|
+
* ① 遮罩关系(这是「圈过的原素材 ↔ 遮罩产物」,最确定)
|
|
6473
|
+
* ② 同尺寸(局部重绘必然同尺寸,不同尺寸就没什么可比)
|
|
6474
|
+
* ③ 时间方向与距离(更晚的像成稿,越近越优先)
|
|
6475
|
+
* ④ 文件名主干一致
|
|
6476
|
+
* 只取前 12 个,面板里够看又不至于一次拉太多缩略图。
|
|
6477
|
+
*/
|
|
6478
|
+
const cmpCandidates = React.useMemo(() => {
|
|
6479
|
+
const curPath = String(item.relPath ?? '')
|
|
6480
|
+
const w = Number(item.width) || 0
|
|
6481
|
+
const h = Number(item.height) || 0
|
|
6482
|
+
const curSource = String(item.maskOf?.sourceRelPath ?? '')
|
|
6483
|
+
const stemOf = (name) => String(name ?? '')
|
|
6484
|
+
.replace(/\.[^.]*$/, '')
|
|
6485
|
+
.replace(/[_\-\s]*(改|重绘|修|inpaint|edit|fixed|final|v\d+)$/i, '')
|
|
6486
|
+
const base = stemOf(item.name)
|
|
6487
|
+
const out = []
|
|
6488
|
+
for (const cand of items) {
|
|
6489
|
+
const rel = String(cand.relPath ?? '')
|
|
6490
|
+
if (rel === '' || rel === curPath) continue
|
|
6491
|
+
if (!isImageItem(cand)) continue
|
|
6492
|
+
const cw = Number(cand.width) || 0
|
|
6493
|
+
const ch = Number(cand.height) || 0
|
|
6494
|
+
const sameSize = w > 0 && h > 0 && cw === w && ch === h
|
|
6495
|
+
const candSource = String(cand.maskOf?.sourceRelPath ?? '')
|
|
6496
|
+
const maskLinked = (candSource !== '' && candSource === curPath)
|
|
6497
|
+
|| (curSource !== '' && curSource === rel)
|
|
6498
|
+
|| (candSource !== '' && candSource === curSource)
|
|
6499
|
+
let score = 0
|
|
6500
|
+
if (maskLinked) score += 1000
|
|
6501
|
+
if (sameSize) score += 500
|
|
6502
|
+
const dtMin = (Number(cand.mtime) - Number(item.mtime)) / 60000
|
|
6503
|
+
if (dtMin > 0) score += 120
|
|
6504
|
+
score -= Math.min(240, Math.abs(dtMin) / 2)
|
|
6505
|
+
if (base !== '' && stemOf(cand.name) === base) score += 80
|
|
6506
|
+
out.push({ item: cand, sameSize, maskLinked, score })
|
|
6507
|
+
}
|
|
6508
|
+
out.sort((a, b) => b.score - a.score)
|
|
6509
|
+
return out.slice(0, 12)
|
|
6510
|
+
}, [items, item])
|
|
6511
|
+
|
|
6512
|
+
/** 选一张图作为对比对象:拉字节 → 转 object URL → 进对比视图。 */
|
|
6513
|
+
const pickCompare = React.useCallback((cand) => {
|
|
6514
|
+
const rel = String(cand?.relPath ?? '')
|
|
6515
|
+
if (rel === '') return
|
|
6516
|
+
setPickerOpen(false)
|
|
6517
|
+
releaseCmp()
|
|
6518
|
+
const controller = new AbortController()
|
|
6519
|
+
cmpAbortRef.current = controller
|
|
6520
|
+
setCmpTarget({
|
|
6521
|
+
relPath: rel,
|
|
6522
|
+
name: String(cand.name ?? rel.split('/').pop() ?? ''),
|
|
6523
|
+
width: Number(cand.width) || 0,
|
|
6524
|
+
height: Number(cand.height) || 0,
|
|
6525
|
+
status: 'loading',
|
|
6526
|
+
url: null,
|
|
6527
|
+
})
|
|
6528
|
+
fetchRaw(rel, controller.signal)
|
|
6529
|
+
.then((blob) => {
|
|
6530
|
+
if (controller.signal.aborted) return
|
|
6531
|
+
const url = URL.createObjectURL(blob)
|
|
6532
|
+
if (controller.signal.aborted) { URL.revokeObjectURL(url); return }
|
|
6533
|
+
cmpUrlRef.current = url
|
|
6534
|
+
setCmpTarget((cur) => (cur !== null && cur.relPath === rel
|
|
6535
|
+
? { ...cur, status: 'ready', url }
|
|
6536
|
+
: cur))
|
|
6537
|
+
})
|
|
6538
|
+
.catch((error) => {
|
|
6539
|
+
if (controller.signal.aborted) return
|
|
6540
|
+
setCmpTarget((cur) => (cur !== null && cur.relPath === rel
|
|
6541
|
+
? { ...cur, status: 'failed', message: String(error?.message ?? error) }
|
|
6542
|
+
: cur))
|
|
6543
|
+
})
|
|
6544
|
+
}, [releaseCmp])
|
|
6545
|
+
|
|
6546
|
+
/** 退出对比:清空对象、复位分割线、放掉 URL。 */
|
|
6547
|
+
const exitCompare = React.useCallback(() => {
|
|
6548
|
+
releaseCmp()
|
|
6549
|
+
setCmpTarget(null)
|
|
6550
|
+
setPickerOpen(false)
|
|
6551
|
+
setSplitPct(50)
|
|
6552
|
+
setCmpSwapped(false)
|
|
6553
|
+
}, [releaseCmp])
|
|
6554
|
+
|
|
6555
|
+
// 组件卸载时释放对比图
|
|
6556
|
+
React.useEffect(() => () => { releaseCmp() }, [releaseCmp])
|
|
6557
|
+
|
|
6558
|
+
// 从「批量选两张」进来时直接进对比:老板要的是选完就比,不再多点一步。
|
|
6559
|
+
// 只认第一次,之后左右翻页不重复触发。
|
|
6560
|
+
const initialCompareDoneRef = React.useRef(false)
|
|
6561
|
+
React.useEffect(() => {
|
|
6562
|
+
if (initialCompareDoneRef.current) return
|
|
6563
|
+
const rel = typeof initialCompare === 'string' ? initialCompare : ''
|
|
6564
|
+
if (rel === '') return
|
|
6565
|
+
const cand = items.find((it) => String(it?.relPath ?? '') === rel)
|
|
6566
|
+
if (cand === undefined) return
|
|
6567
|
+
initialCompareDoneRef.current = true
|
|
6568
|
+
pickCompare(cand)
|
|
6569
|
+
}, [initialCompare, items, pickCompare])
|
|
6570
|
+
|
|
6571
|
+
/** 把分割线移到指针所在的横向位置(百分比)。 */
|
|
6572
|
+
const moveSplitTo = React.useCallback((clientX) => {
|
|
6573
|
+
const node = bodyRef.current
|
|
6574
|
+
if (node === null) return
|
|
6575
|
+
const rect = node.getBoundingClientRect()
|
|
6576
|
+
const width = rect.width > 0 ? rect.width : 1
|
|
6577
|
+
const pct = ((clientX - rect.left) / width) * 100
|
|
6578
|
+
setSplitPct(Math.max(0, Math.min(100, pct)))
|
|
6579
|
+
}, [])
|
|
6580
|
+
|
|
6581
|
+
const onDividerDown = (event) => {
|
|
6582
|
+
if (cmpTarget === null) return
|
|
6583
|
+
event.preventDefault()
|
|
6584
|
+
event.stopPropagation()
|
|
6585
|
+
splitDragRef.current = true
|
|
6586
|
+
moveSplitTo(event.clientX)
|
|
6587
|
+
try { event.currentTarget.setPointerCapture(event.pointerId) } catch {}
|
|
6588
|
+
}
|
|
6589
|
+
const onDividerMove = (event) => {
|
|
6590
|
+
if (splitDragRef.current !== true) return
|
|
6591
|
+
event.preventDefault()
|
|
6592
|
+
event.stopPropagation()
|
|
6593
|
+
moveSplitTo(event.clientX)
|
|
6594
|
+
}
|
|
6595
|
+
const onDividerUp = (event) => {
|
|
6596
|
+
if (splitDragRef.current !== true) return
|
|
6597
|
+
splitDragRef.current = null
|
|
6598
|
+
try { event.currentTarget.releasePointerCapture(event.pointerId) } catch {}
|
|
6599
|
+
}
|
|
6268
6600
|
const dragRef = React.useRef(null)
|
|
6269
6601
|
// 上一次拖动是否真的产生了位移(用于区分「拖图」和「单击关闭」)
|
|
6270
6602
|
const lastDragMoved = React.useRef(false)
|
|
@@ -6342,10 +6674,16 @@ ${absPath}
|
|
|
6342
6674
|
setOriginalMode(false)
|
|
6343
6675
|
setOriginal({ status: 'idle' })
|
|
6344
6676
|
setCropActive(false)
|
|
6677
|
+
// 换图后对比对象失效:写盘路径不同,留着只会显示别人的图
|
|
6678
|
+
releaseCmp()
|
|
6679
|
+
setCmpTarget(null)
|
|
6680
|
+
setPickerOpen(false)
|
|
6681
|
+
setSplitPct(50)
|
|
6682
|
+
setCmpSwapped(false)
|
|
6345
6683
|
return () => {
|
|
6346
6684
|
if (originalAbortRef.current !== null) originalAbortRef.current.abort()
|
|
6347
6685
|
}
|
|
6348
|
-
}, [item.relPath])
|
|
6686
|
+
}, [item.relPath, releaseCmp])
|
|
6349
6687
|
|
|
6350
6688
|
// 首次挂载时如果要求直接看原图,立刻开始加载。
|
|
6351
6689
|
// 放在「换图重置」之后,顺序上不会再被清掉。
|
|
@@ -6440,28 +6778,64 @@ ${absPath}
|
|
|
6440
6778
|
|
|
6441
6779
|
// 滚轮缩放:以鼠标位置为中心,避免放大后目标跑出视野(仅图片模式)。
|
|
6442
6780
|
// 文本预览用原生滚动,不拦截滚轮。
|
|
6781
|
+
// 平铺对比时锚点要换成「光标所在那一格」的中心,见 onWheel 里的注释。
|
|
6782
|
+
const cmpTileRef = React.useRef(false)
|
|
6783
|
+
cmpTileRef.current = cmpTarget !== null && cmpMode === 'tile'
|
|
6443
6784
|
React.useEffect(() => {
|
|
6444
6785
|
const node = bodyRef.current
|
|
6445
6786
|
if (node === null || state.status !== 'ready' || isText) return undefined
|
|
6446
6787
|
const onWheel = (event) => {
|
|
6447
6788
|
event.preventDefault()
|
|
6448
6789
|
const delta = event.deltaY < 0 ? 1 : -1
|
|
6449
|
-
|
|
6450
|
-
//
|
|
6451
|
-
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6790
|
+
// 不动点 = 光标下那张图的中心。图片的 transform-origin 是 center,
|
|
6791
|
+
// 只有把锚点选在「元素自身中心」上,光标下的那个像素才会在缩放前后停在同一处。
|
|
6792
|
+
// 平铺对比时左右两格各自居中,两个中心相差整整一格宽;若仍拿预览框中心去算,
|
|
6793
|
+
// 光标那一格的不动点会被算到隔壁半格,放大时画面往一侧窜 —— 看着就是「以鼠标为中心失灵」。
|
|
6794
|
+
const base = node.getBoundingClientRect()
|
|
6795
|
+
let anchorX = null
|
|
6796
|
+
let anchorY = null
|
|
6797
|
+
if (cmpTileRef.current) {
|
|
6798
|
+
const pane = event.target instanceof Element ? event.target.closest('.dg-cmpPane') : null
|
|
6799
|
+
if (pane !== null) {
|
|
6800
|
+
const paneRect = pane.getBoundingClientRect()
|
|
6801
|
+
anchorX = paneRect.left + paneRect.width / 2
|
|
6802
|
+
anchorY = paneRect.top + paneRect.height / 2
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6805
|
+
const ownImg = imgRef.current
|
|
6806
|
+
if (anchorX === null && ownImg !== null && ownImg.offsetWidth > 0 && ownImg.offsetHeight > 0) {
|
|
6807
|
+
// offsetLeft/Top 相对预览框内边,且不含 transform 与缩放,正是图片未变换时的中心
|
|
6808
|
+
anchorX = base.left + ownImg.offsetLeft - node.scrollLeft + ownImg.offsetWidth / 2
|
|
6809
|
+
anchorY = base.top + ownImg.offsetTop - node.scrollTop + ownImg.offsetHeight / 2
|
|
6810
|
+
}
|
|
6811
|
+
if (anchorX === null) {
|
|
6812
|
+
anchorX = base.left + base.width / 2
|
|
6813
|
+
anchorY = base.top + base.height / 2
|
|
6814
|
+
}
|
|
6815
|
+
// 光标相对不动点的偏移
|
|
6816
|
+
const cx = event.clientX - anchorX
|
|
6817
|
+
const cy = event.clientY - anchorY
|
|
6818
|
+
|
|
6819
|
+
// 以光标为不动点缩放:光标下的像素点在缩放前后保持同一屏幕位置。
|
|
6820
|
+
// 关键:pan 只算一次。旧写法把它嵌在 setZoom updater 里,严格模式重跑会算两遍。
|
|
6821
|
+
const current = viewRef.current.zoom
|
|
6822
|
+
const next = Math.min(MAX_ZOOM, Math.max(1, current + delta * ZOOM_STEP))
|
|
6823
|
+
let nextPan
|
|
6824
|
+
if (next === 1) {
|
|
6825
|
+
nextPan = { x: 0, y: 0 }
|
|
6826
|
+
} else {
|
|
6458
6827
|
const ratio = next / current
|
|
6459
|
-
|
|
6828
|
+
const p = viewRef.current.pan
|
|
6829
|
+
nextPan = {
|
|
6460
6830
|
x: cx - (cx - p.x) * ratio,
|
|
6461
6831
|
y: cy - (cy - p.y) * ratio,
|
|
6462
|
-
}
|
|
6463
|
-
|
|
6464
|
-
|
|
6832
|
+
}
|
|
6833
|
+
}
|
|
6834
|
+
// 即时写 ref(连续滚轮时下一帧能读到最新值),再分别 set,互不嵌套
|
|
6835
|
+
viewRef.current.zoom = next
|
|
6836
|
+
viewRef.current.pan = nextPan
|
|
6837
|
+
setZoom(next)
|
|
6838
|
+
setPan(nextPan)
|
|
6465
6839
|
}
|
|
6466
6840
|
node.addEventListener('wheel', onWheel, { passive: false })
|
|
6467
6841
|
return () => node.removeEventListener('wheel', onWheel)
|
|
@@ -6528,6 +6902,9 @@ ${absPath}
|
|
|
6528
6902
|
const onClickBody = (event) => {
|
|
6529
6903
|
// 标注模式下点图只用于画框,不能顺手把大图关掉(老板 20:32 指出的冲突)
|
|
6530
6904
|
if (annotActive) return
|
|
6905
|
+
// 对比态下点画面只是看图:平铺两格各占一半,鼠标想比细节时很容易点到,
|
|
6906
|
+
// 一点就把整个大图关了,退出对比请用工具栏按钮或 Esc。
|
|
6907
|
+
if (cmpTarget !== null) return
|
|
6531
6908
|
// v0.16.0 裁剪模式下点击被裁剪层接管,不应关闭查看器
|
|
6532
6909
|
if (cropActive) return
|
|
6533
6910
|
event.preventDefault()
|
|
@@ -6582,11 +6959,14 @@ ${absPath}
|
|
|
6582
6959
|
}, [vOverflow])
|
|
6583
6960
|
|
|
6584
6961
|
const zoomBy = React.useCallback((direction) => {
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6962
|
+
// 同滚轮:不在 updater 里嵌 setPan,从镜像 ref 读当前值,算好后分别 set
|
|
6963
|
+
const current = viewRef.current.zoom
|
|
6964
|
+
const next = Math.min(MAX_ZOOM, Math.max(1, current + direction * ZOOM_STEP))
|
|
6965
|
+
const nextPan = next === 1 ? { x: 0, y: 0 } : viewRef.current.pan
|
|
6966
|
+
viewRef.current.zoom = next
|
|
6967
|
+
viewRef.current.pan = nextPan
|
|
6968
|
+
setZoom(next)
|
|
6969
|
+
setPan(nextPan)
|
|
6590
6970
|
}, [])
|
|
6591
6971
|
|
|
6592
6972
|
/**
|
|
@@ -6612,13 +6992,24 @@ ${absPath}
|
|
|
6612
6992
|
const key = event.key
|
|
6613
6993
|
if (key === 'Escape') {
|
|
6614
6994
|
event.preventDefault()
|
|
6615
|
-
|
|
6616
|
-
|
|
6995
|
+
// 对比中先退对比:不然顺手把整个大图也关了,得重新找图
|
|
6996
|
+
if (cmpTarget !== null) exitCompare()
|
|
6997
|
+
else onClose()
|
|
6998
|
+
} else if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
|
6617
6999
|
event.preventDefault()
|
|
6618
|
-
|
|
6619
|
-
|
|
7000
|
+
if (cmpTarget !== null) {
|
|
7001
|
+
// 对比时左右键归分割线(Shift 大步),避免一边看差异一边把图翻走
|
|
7002
|
+
const step = event.shiftKey ? 10 : 2
|
|
7003
|
+
setSplitPct((p) => Math.max(0, Math.min(100, p + (key === 'ArrowLeft' ? -step : step))))
|
|
7004
|
+
} else {
|
|
7005
|
+
onStep(key === 'ArrowLeft' ? -1 : 1)
|
|
7006
|
+
}
|
|
7007
|
+
} else if ((key === 'x' || key === 'X') && cmpTarget !== null) {
|
|
6620
7008
|
event.preventDefault()
|
|
6621
|
-
|
|
7009
|
+
setCmpSwapped((v) => !v)
|
|
7010
|
+
} else if ((key === 't' || key === 'T') && cmpTarget !== null) {
|
|
7011
|
+
event.preventDefault()
|
|
7012
|
+
setCmpMode((m) => (m === 'slider' ? 'tile' : 'slider'))
|
|
6622
7013
|
} else if (key === 'ArrowUp') {
|
|
6623
7014
|
event.preventDefault()
|
|
6624
7015
|
panStep(-1)
|
|
@@ -6652,7 +7043,7 @@ ${absPath}
|
|
|
6652
7043
|
}
|
|
6653
7044
|
window.addEventListener('keydown', onKey)
|
|
6654
7045
|
return () => window.removeEventListener('keydown', onKey)
|
|
6655
|
-
}, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath])
|
|
7046
|
+
}, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath, cmpTarget, exitCompare])
|
|
6656
7047
|
|
|
6657
7048
|
const sliderDragRef = React.useRef(null)
|
|
6658
7049
|
const onSliderPointerDown = (event) => {
|
|
@@ -6824,7 +7215,62 @@ ${absPath}
|
|
|
6824
7215
|
event.stopPropagation()
|
|
6825
7216
|
setCropActive((v) => !v)
|
|
6826
7217
|
},
|
|
6827
|
-
}, cropActive ?
|
|
7218
|
+
}, cropActive ? `\u2702 ${t('cropExit')}` : `\u2702 ${t('cropEnter')}`)
|
|
7219
|
+
: null,
|
|
7220
|
+
// ---- 前后对比入口(2026-11-17)----
|
|
7221
|
+
// 未对比:一个「⇄ 对比」打开选图面板;对比中:换成 模式 / 对调 / 结束 三个。
|
|
7222
|
+
state.status === 'ready' && isImageItem(item) && !isText
|
|
7223
|
+
? (cmpTarget === null
|
|
7224
|
+
? h('button', {
|
|
7225
|
+
type: 'button',
|
|
7226
|
+
className: 'dg-btn' + (pickerOpen ? ' dg-btnActive' : ''),
|
|
7227
|
+
key: 'cmp',
|
|
7228
|
+
'data-gallery-compare-toggle': true,
|
|
7229
|
+
'aria-pressed': pickerOpen,
|
|
7230
|
+
title: t('cmpPickHint'),
|
|
7231
|
+
onClick: (event) => {
|
|
7232
|
+
event.stopPropagation()
|
|
7233
|
+
// 对比与批注/裁剪抢指针,进来先把那两个关掉
|
|
7234
|
+
setAnnotActive(false)
|
|
7235
|
+
setCropActive(false)
|
|
7236
|
+
setPickerOpen((v) => !v)
|
|
7237
|
+
},
|
|
7238
|
+
}, '\u21c4 ' + t('cmpEnter'))
|
|
7239
|
+
: h(React.Fragment, { key: 'cmpCtl' }, [
|
|
7240
|
+
h('button', {
|
|
7241
|
+
type: 'button',
|
|
7242
|
+
className: 'dg-btn dg-btnActive',
|
|
7243
|
+
key: 'mode',
|
|
7244
|
+
'data-gallery-compare-mode': cmpMode,
|
|
7245
|
+
title: t('cmpSliderHint'),
|
|
7246
|
+
onClick: (event) => {
|
|
7247
|
+
event.stopPropagation()
|
|
7248
|
+
setCmpMode((m) => (m === 'slider' ? 'tile' : 'slider'))
|
|
7249
|
+
},
|
|
7250
|
+
}, cmpMode === 'slider' ? '\u25a5 ' + t('cmpModeTile') : '\u25eb ' + t('cmpModeSlider')),
|
|
7251
|
+
h('button', {
|
|
7252
|
+
type: 'button',
|
|
7253
|
+
className: 'dg-btn',
|
|
7254
|
+
key: 'swap',
|
|
7255
|
+
'data-gallery-compare-swap': true,
|
|
7256
|
+
title: t('cmpSwap'),
|
|
7257
|
+
onClick: (event) => {
|
|
7258
|
+
event.stopPropagation()
|
|
7259
|
+
setCmpSwapped((v) => !v)
|
|
7260
|
+
},
|
|
7261
|
+
}, '\u21cb ' + t('cmpSwap')),
|
|
7262
|
+
h('button', {
|
|
7263
|
+
type: 'button',
|
|
7264
|
+
className: 'dg-btn',
|
|
7265
|
+
key: 'exit',
|
|
7266
|
+
'data-gallery-compare-exit': true,
|
|
7267
|
+
title: t('cmpExit'),
|
|
7268
|
+
onClick: (event) => {
|
|
7269
|
+
event.stopPropagation()
|
|
7270
|
+
exitCompare()
|
|
7271
|
+
},
|
|
7272
|
+
}, '\u2715 ' + t('cmpExit')),
|
|
7273
|
+
]))
|
|
6828
7274
|
: null,
|
|
6829
7275
|
// 「拖到对话」确定性入口:Viewer 大图本身 draggable:false + pointerEvents:none
|
|
6830
7276
|
// (标注态的中键平移 / 右键多边形都依赖它),所以不改大图,另给一个可拖按钮。
|
|
@@ -6900,9 +7346,38 @@ ${absPath}
|
|
|
6900
7346
|
pointerEvents: 'none',
|
|
6901
7347
|
},
|
|
6902
7348
|
}),
|
|
7349
|
+
// ---- 前后对比 · 滑块模式 ----
|
|
7350
|
+
// 关键点:clip 容器不参与 transform(按屏幕坐标裁),内层 img 才跟着缩放平移,
|
|
7351
|
+
// 于是「放大到 8 倍看同一处颗粒」时,分割线留在屏幕上不动、两边始终同一块画面。
|
|
7352
|
+
cmpTarget !== null && cmpMode === 'slider' && cmpTarget.status === 'ready' && imgBox !== null
|
|
7353
|
+
? h('div', {
|
|
7354
|
+
key: 'cmpClip',
|
|
7355
|
+
className: 'dg-cmpClip',
|
|
7356
|
+
'data-gallery-compare-clip': Math.round(splitPct),
|
|
7357
|
+
style: {
|
|
7358
|
+
clipPath: cmpSwapped === true
|
|
7359
|
+
? `inset(0 0 0 ${splitPct}%)`
|
|
7360
|
+
: `inset(0 ${100 - splitPct}% 0 0)`,
|
|
7361
|
+
},
|
|
7362
|
+
}, h('img', {
|
|
7363
|
+
key: 'cmpImg',
|
|
7364
|
+
className: 'dg-cmpImg',
|
|
7365
|
+
src: cmpTarget.url,
|
|
7366
|
+
alt: cmpTarget.name,
|
|
7367
|
+
draggable: false,
|
|
7368
|
+
style: {
|
|
7369
|
+
left: imgBox.left + 'px',
|
|
7370
|
+
top: imgBox.top + 'px',
|
|
7371
|
+
width: imgBox.width + 'px',
|
|
7372
|
+
height: imgBox.height + 'px',
|
|
7373
|
+
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
7374
|
+
transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
|
|
7375
|
+
},
|
|
7376
|
+
}))
|
|
7377
|
+
: null,
|
|
6903
7378
|
// 批注层贴着图片真实布局盒,与图片共用同一组 zoom/pan。
|
|
6904
7379
|
// imgBox 还没量出来(图片未布局)时不画框,免得拿容器当基准错位。
|
|
6905
|
-
imgBox === null ? null : h(AnnotationLayer, {
|
|
7380
|
+
imgBox === null || cmpTarget !== null ? null : h(AnnotationLayer, {
|
|
6906
7381
|
key: 'annot',
|
|
6907
7382
|
t,
|
|
6908
7383
|
annotations: annotsOfCurrent,
|
|
@@ -6920,15 +7395,96 @@ ${absPath}
|
|
|
6920
7395
|
? (a) => onExportMask(item, a)
|
|
6921
7396
|
: undefined,
|
|
6922
7397
|
}),
|
|
7398
|
+
// ---- 前后对比 · 平铺模式:左右各一格,共用同一组 pan/zoom ----
|
|
7399
|
+
cmpTarget !== null && cmpMode === 'tile'
|
|
7400
|
+
? h('div', { key: 'cmpTile', className: 'dg-cmpTile', 'data-gallery-compare-tile': true }, [
|
|
7401
|
+
h('div', { key: 'paneA', className: 'dg-cmpPane' }, [
|
|
7402
|
+
cmpTarget.status === 'ready'
|
|
7403
|
+
? h('img', {
|
|
7404
|
+
key: 'imgA',
|
|
7405
|
+
className: 'dg-cmpPaneImg',
|
|
7406
|
+
src: cmpSwapped === true
|
|
7407
|
+
? (originalMode && original.status === 'ready' ? original.url : state.url)
|
|
7408
|
+
: cmpTarget.url,
|
|
7409
|
+
alt: '',
|
|
7410
|
+
draggable: false,
|
|
7411
|
+
style: {
|
|
7412
|
+
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
7413
|
+
transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
|
|
7414
|
+
},
|
|
7415
|
+
})
|
|
7416
|
+
: h('span', { key: 'msgA', className: 'dg-cmpPaneMsg' },
|
|
7417
|
+
cmpTarget.status === 'failed' ? t('cmpFailed') : t('cmpLoading')),
|
|
7418
|
+
h('span', { key: 'tagA', className: 'dg-cmpPaneTag' },
|
|
7419
|
+
cmpSwapped === true ? t('cmpAfter') : t('cmpBefore')),
|
|
7420
|
+
]),
|
|
7421
|
+
h('div', { key: 'paneB', className: 'dg-cmpPane' }, [
|
|
7422
|
+
h('img', {
|
|
7423
|
+
key: 'imgB',
|
|
7424
|
+
className: 'dg-cmpPaneImg',
|
|
7425
|
+
src: cmpSwapped === true
|
|
7426
|
+
? cmpTarget.url
|
|
7427
|
+
: (originalMode && original.status === 'ready' ? original.url : state.url),
|
|
7428
|
+
alt: item.name,
|
|
7429
|
+
draggable: false,
|
|
7430
|
+
style: {
|
|
7431
|
+
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
7432
|
+
transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
|
|
7433
|
+
},
|
|
7434
|
+
}),
|
|
7435
|
+
h('span', { key: 'tagB', className: 'dg-cmpPaneTag' },
|
|
7436
|
+
cmpSwapped === true ? t('cmpBefore') : t('cmpAfter')),
|
|
7437
|
+
]),
|
|
7438
|
+
])
|
|
7439
|
+
: null,
|
|
6923
7440
|
]))
|
|
6924
7441
|
: state.status === 'binary'
|
|
6925
7442
|
? h('div', { className: 'dg-placeholder', key: 'bin' }, t('binaryHint'))
|
|
6926
7443
|
: h('div', { className: state.status === 'failed' ? 'dg-placeholder dg-error' : 'dg-placeholder' },
|
|
6927
7444
|
state.status === 'failed' ? `${t('thumbFailed')}:${item.name}` : t('loading')),
|
|
6928
7445
|
),
|
|
7446
|
+
// ---- 前后对比 · 选图面板 ----
|
|
7447
|
+
pickerOpen
|
|
7448
|
+
? h(ComparePicker, {
|
|
7449
|
+
key: 'cmpPicker',
|
|
7450
|
+
t,
|
|
7451
|
+
candidates: cmpCandidates,
|
|
7452
|
+
onPick: (cand) => pickCompare(cand),
|
|
7453
|
+
onClose: () => setPickerOpen(false),
|
|
7454
|
+
})
|
|
7455
|
+
: null,
|
|
7456
|
+
// ---- 前后对比 · 滑块的标签与分割线(屏幕坐标,不随 pan/zoom)----
|
|
7457
|
+
cmpTarget !== null && cmpMode === 'slider'
|
|
7458
|
+
? h('div', { key: 'cmpUi', className: 'dg-cmpUi', 'data-gallery-compare-ui': true }, [
|
|
7459
|
+
h('span', { key: 'tagL', className: 'dg-cmpTag dg-cmpTagL' },
|
|
7460
|
+
cmpSwapped === true ? t('cmpAfter') : t('cmpBefore')),
|
|
7461
|
+
h('span', { key: 'tagR', className: 'dg-cmpTag dg-cmpTagR' },
|
|
7462
|
+
cmpSwapped === true ? t('cmpBefore') : t('cmpAfter')),
|
|
7463
|
+
h('div', {
|
|
7464
|
+
key: 'handle',
|
|
7465
|
+
className: 'dg-cmpHandle',
|
|
7466
|
+
'data-gallery-compare-handle': Math.round(splitPct),
|
|
7467
|
+
style: { left: splitPct + '%' },
|
|
7468
|
+
onPointerDown: onDividerDown,
|
|
7469
|
+
onPointerMove: onDividerMove,
|
|
7470
|
+
onPointerUp: onDividerUp,
|
|
7471
|
+
onPointerCancel: onDividerUp,
|
|
7472
|
+
}, [
|
|
7473
|
+
h('div', { key: 'line', className: 'dg-cmpLine' }),
|
|
7474
|
+
h('div', { key: 'grip', className: 'dg-cmpGrip' }, [
|
|
7475
|
+
h('span', { key: 'l', className: 'dg-cmpArrow' }, '\u2039'),
|
|
7476
|
+
h('span', { key: 'r', className: 'dg-cmpArrow' }, '\u203a'),
|
|
7477
|
+
]),
|
|
7478
|
+
]),
|
|
7479
|
+
cmpTarget.status === 'ready'
|
|
7480
|
+
? null
|
|
7481
|
+
: h('div', { key: 'msg', className: 'dg-cmpMsg' },
|
|
7482
|
+
cmpTarget.status === 'failed' ? t('cmpFailed') : t('cmpLoading')),
|
|
7483
|
+
])
|
|
7484
|
+
: null,
|
|
6929
7485
|
slider,
|
|
6930
7486
|
// v0.16.0 裁剪覆盖层:裁剪模式开启时显示(含微信式放大镜),固定在视口上、与 pan/zoom 解耦
|
|
6931
|
-
cropActive && isImageItem(item) && !isText && state.status === 'ready'
|
|
7487
|
+
cropActive && cmpTarget === null && isImageItem(item) && !isText && state.status === 'ready'
|
|
6932
7488
|
? h(ImageCropper, {
|
|
6933
7489
|
key: 'cropper',
|
|
6934
7490
|
t,
|
|
@@ -8014,6 +8570,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8014
8570
|
function GalleryBody(props) {
|
|
8015
8571
|
const { t, sessionId } = props
|
|
8016
8572
|
const [view, setView] = React.useState({ status: 'loading' })
|
|
8573
|
+
// 增量刷新用:读「当前列表」的最新值而不必进依赖数组。
|
|
8574
|
+
// 直接用 view 会让 useEffect 每次渲染都重建轮询器,而读 view 的闭包又拿不到最新值。
|
|
8575
|
+
const viewRef = React.useRef(view)
|
|
8576
|
+
React.useEffect(() => { viewRef.current = view }, [view])
|
|
8577
|
+
|
|
8017
8578
|
// v0.17.0:本面板自己的轻提示(写进输入框的结果反馈)。
|
|
8018
8579
|
// 不能用 FeedbackBasket 的 setNotice —— 那是另一个组件的局部 state。
|
|
8019
8580
|
const [toast, setToast] = React.useState(null)
|
|
@@ -8850,7 +9411,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8850
9411
|
* 分组视图下卡片来自 `data.groups[i].files`,与当前页的扁平 `items` 是两个不同的集合,
|
|
8851
9412
|
* 直接用全局 `items` 的索引会「点哪张都跳出同一张图」。
|
|
8852
9413
|
*/
|
|
8853
|
-
const openViewer = React.useCallback((index, anchorEl, list, asOriginal, origin) => {
|
|
9414
|
+
const openViewer = React.useCallback((index, anchorEl, list, asOriginal, origin, compareRel) => {
|
|
8854
9415
|
const scroller = bodyScrollRef.current
|
|
8855
9416
|
if (scroller !== null) {
|
|
8856
9417
|
savedScrollRef.current = {
|
|
@@ -8889,6 +9450,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8889
9450
|
const originSid = String(origin?.sessionId ?? '')
|
|
8890
9451
|
setViewer({
|
|
8891
9452
|
index, list: snapshot, asOriginal: asOriginal === true,
|
|
9453
|
+
// 2026-11-17:批量选两张时带进来,查看器一开就进对比,不用再点一次
|
|
9454
|
+
compareRel: String(compareRel ?? ''),
|
|
8892
9455
|
originSid: originSid === '__history__' ? '' : originSid,
|
|
8893
9456
|
originTitle: originSid === '__history__' ? '' : String(origin?.title ?? ''),
|
|
8894
9457
|
})
|
|
@@ -8970,6 +9533,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8970
9533
|
const payload = await callHost('delete', { path: target.item.relPath, confirm: true })
|
|
8971
9534
|
if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
|
|
8972
9535
|
setDeleteTarget(null)
|
|
9536
|
+
kickChanges()
|
|
8973
9537
|
await load(undefined, kind, scope, page).then((data) => setView({ status: 'ready', data })).catch(() => {})
|
|
8974
9538
|
} catch (error) {
|
|
8975
9539
|
console.error('dsh-gallery: 删除失败', error)
|
|
@@ -9106,6 +9670,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9106
9670
|
}
|
|
9107
9671
|
}
|
|
9108
9672
|
if (okCount > 0) {
|
|
9673
|
+
kickChanges()
|
|
9109
9674
|
void refresh()
|
|
9110
9675
|
if (lastErr !== '') console.warn('dsh-gallery: 部分粘贴失败', lastErr)
|
|
9111
9676
|
return
|
|
@@ -9272,7 +9837,110 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9272
9837
|
}
|
|
9273
9838
|
}, [load, kind, scope, page])
|
|
9274
9839
|
|
|
9275
|
-
//
|
|
9840
|
+
// ---- 增量刷新(2026-11-16)----
|
|
9841
|
+
// 任何进程往产出根里写资产,Host 侧 fs.watch 都会感知并递增版本号。
|
|
9842
|
+
// 这里每秒问一次「变了没」,只重取受影响的那个对话组,其它组不动。
|
|
9843
|
+
//
|
|
9844
|
+
// 为什么不用整表 refresh:几百张卡整表替换会让滚动位置跳动、卡片重排闪一下。
|
|
9845
|
+
// 局部替换时其它组对象引用保持不变,React 就不会重绘它们。
|
|
9846
|
+
const changesVersionRef = React.useRef(0)
|
|
9847
|
+
const changesBusyRef = React.useRef(false)
|
|
9848
|
+
// 写操作后主动催一次检查(不等 1 秒轮询),用户点了就该立刻看到结果
|
|
9849
|
+
const changesKickRef = React.useRef(null)
|
|
9850
|
+
|
|
9851
|
+
React.useEffect(() => {
|
|
9852
|
+
// 看大图时不打扰:列表在背景变化会让关掉大图后位置跳动
|
|
9853
|
+
if (viewer !== null) return undefined
|
|
9854
|
+
let alive = true
|
|
9855
|
+
|
|
9856
|
+
const tick = async () => {
|
|
9857
|
+
if (!alive || changesBusyRef.current) return
|
|
9858
|
+
changesBusyRef.current = true
|
|
9859
|
+
try {
|
|
9860
|
+
const r = await callHost('changes', { since: changesVersionRef.current })
|
|
9861
|
+
if (!alive || r?.ok !== true) return
|
|
9862
|
+
const v = Number(r.version) || 0
|
|
9863
|
+
if (v <= changesVersionRef.current) return
|
|
9864
|
+
changesVersionRef.current = v
|
|
9865
|
+
const changed = Array.isArray(r.changed) ? r.changed : []
|
|
9866
|
+
|
|
9867
|
+
// 决定「能不能局部刷」:只有分组视图且每个变动都有明确会话才能局部。
|
|
9868
|
+
// 读 viewRef(不是 view)拿最新值,避免闭包过期。
|
|
9869
|
+
const cur = viewRef.current
|
|
9870
|
+
const groups = (cur?.status === 'ready' && Array.isArray(cur.data?.groups))
|
|
9871
|
+
? cur.data.groups : null
|
|
9872
|
+
const canPartial = groups !== null
|
|
9873
|
+
&& scope !== 'session'
|
|
9874
|
+
&& changed.length > 0
|
|
9875
|
+
&& changed.every((c) => String(c?.sessionId ?? '') !== '')
|
|
9876
|
+
|
|
9877
|
+
if (!canPartial) { void refresh(); return }
|
|
9878
|
+
|
|
9879
|
+
// 逐个组重取明细
|
|
9880
|
+
const fresh = new Map()
|
|
9881
|
+
let needFull = false
|
|
9882
|
+
for (const c of changed) {
|
|
9883
|
+
const sid = String(c?.sessionId ?? '')
|
|
9884
|
+
if (sid === '') { needFull = true; break }
|
|
9885
|
+
try {
|
|
9886
|
+
const p = await callHost('groupMore', { kind, scope, sessionId: sid, page: 1 })
|
|
9887
|
+
if (p?.ok === false) { needFull = true; break }
|
|
9888
|
+
fresh.set(sid, p)
|
|
9889
|
+
} catch { needFull = true; break }
|
|
9890
|
+
}
|
|
9891
|
+
if (!alive) return
|
|
9892
|
+
if (needFull) { void refresh(); return }
|
|
9893
|
+
|
|
9894
|
+
// 局部替换:只动变化的组,其它组对象引用不变
|
|
9895
|
+
let sawUnknownGroup = false
|
|
9896
|
+
setView((prev) => {
|
|
9897
|
+
if (prev.status !== 'ready' || !Array.isArray(prev.data?.groups)) return prev
|
|
9898
|
+
const nextGroups = prev.data.groups.slice()
|
|
9899
|
+
let dirty = false
|
|
9900
|
+
for (const [sid, p] of fresh.entries()) {
|
|
9901
|
+
const idx = nextGroups.findIndex((g) => String(g?.sessionId ?? '') === sid)
|
|
9902
|
+
if (idx < 0) { sawUnknownGroup = true; continue }
|
|
9903
|
+
const files = Array.isArray(p?.files) ? p.files
|
|
9904
|
+
: (Array.isArray(p?.items) ? p.items : null)
|
|
9905
|
+
if (files === null) { sawUnknownGroup = true; continue }
|
|
9906
|
+
nextGroups[idx] = {
|
|
9907
|
+
...nextGroups[idx],
|
|
9908
|
+
files,
|
|
9909
|
+
fileCount: typeof p.fileCount === 'number' ? p.fileCount : nextGroups[idx].fileCount,
|
|
9910
|
+
returnedCount: files.length,
|
|
9911
|
+
counts: p.counts ?? nextGroups[idx].counts,
|
|
9912
|
+
latestMtime: p.latestMtime ?? nextGroups[idx].latestMtime,
|
|
9913
|
+
}
|
|
9914
|
+
dirty = true
|
|
9915
|
+
}
|
|
9916
|
+
if (!dirty) return prev
|
|
9917
|
+
return { ...prev, data: { ...prev.data, groups: nextGroups } }
|
|
9918
|
+
})
|
|
9919
|
+
// 出现了列表里还没有的会话组(新对话刚产出第一条)→ 补一次整表,把新组插进来
|
|
9920
|
+
if (sawUnknownGroup) { void refresh(); return }
|
|
9921
|
+
void callHost('changesAck', { since: v }).catch(() => {})
|
|
9922
|
+
} catch { /* 轮询失败静默,下个周期再试 */ }
|
|
9923
|
+
finally { changesBusyRef.current = false }
|
|
9924
|
+
}
|
|
9925
|
+
|
|
9926
|
+
// 外部(写操作回调)可以调这个立即催一次
|
|
9927
|
+
changesKickRef.current = () => { void tick() }
|
|
9928
|
+
|
|
9929
|
+
const timer = setInterval(() => { void tick() }, 1000)
|
|
9930
|
+
return () => {
|
|
9931
|
+
alive = false
|
|
9932
|
+
changesKickRef.current = null
|
|
9933
|
+
clearInterval(timer)
|
|
9934
|
+
}
|
|
9935
|
+
}, [callHost, kind, scope, viewer, refresh])
|
|
9936
|
+
|
|
9937
|
+
/** 写操作成功后调用:立刻检查一次变动,不用等 1 秒轮询 */
|
|
9938
|
+
const kickChanges = React.useCallback(() => {
|
|
9939
|
+
const fn = changesKickRef.current
|
|
9940
|
+
if (typeof fn === 'function') fn()
|
|
9941
|
+
}, [])
|
|
9942
|
+
|
|
9943
|
+
// 兜底自动刷新:轮询已覆盖绝大部分,这里放长周期防漏(外部程序写入 fs.watch 漏报时)
|
|
9276
9944
|
React.useEffect(() => {
|
|
9277
9945
|
if (viewer !== null) return undefined
|
|
9278
9946
|
let alive = true
|
|
@@ -9573,6 +10241,36 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9573
10241
|
* 批量操作条(v0.13.7)—— 有选中项时出现。
|
|
9574
10242
|
* 三个动作:确认 / 取消确认 / 清除标记,**全部只改标记、不碰磁盘**。
|
|
9575
10243
|
*/
|
|
10244
|
+
/**
|
|
10245
|
+
* 批量选了两张 → 直接进对比(2026-11-17)。
|
|
10246
|
+
* 第一张当主图(右/后),第二张当对比图(左/前);两张同尺寸时最准。
|
|
10247
|
+
*/
|
|
10248
|
+
const openCompareFromSelection = React.useCallback(() => {
|
|
10249
|
+
const rels = [...selected]
|
|
10250
|
+
if (rels.length !== 2) return
|
|
10251
|
+
const pool = Array.isArray(items) ? items.slice() : []
|
|
10252
|
+
if (Array.isArray(data?.groups)) {
|
|
10253
|
+
for (const gr of data.groups) {
|
|
10254
|
+
for (const f of (Array.isArray(gr.files) ? gr.files : [])) pool.push(f)
|
|
10255
|
+
}
|
|
10256
|
+
}
|
|
10257
|
+
const first = pool.find((it) => String(it?.relPath ?? '') === rels[0])
|
|
10258
|
+
const second = pool.find((it) => String(it?.relPath ?? '') === rels[1])
|
|
10259
|
+
if (first === undefined || second === undefined) {
|
|
10260
|
+
showPasteNotice('fail', t('cmpPickEmpty'))
|
|
10261
|
+
return
|
|
10262
|
+
}
|
|
10263
|
+
// 查看器的翻页范围尽量沿用当前可见列表;两张不全在里面就只用这两张
|
|
10264
|
+
let list = visibleItems.length > 0 ? visibleItems : (Array.isArray(items) ? items : [])
|
|
10265
|
+
const hasBoth = list.some((it) => String(it?.relPath ?? '') === rels[0])
|
|
10266
|
+
&& list.some((it) => String(it?.relPath ?? '') === rels[1])
|
|
10267
|
+
if (!hasBoth) list = [first, second]
|
|
10268
|
+
const idx = Math.max(0, list.findIndex((it) => String(it?.relPath ?? '') === rels[0]))
|
|
10269
|
+
setSelected(new Set())
|
|
10270
|
+
setBatchMode(false)
|
|
10271
|
+
openViewer(idx, null, list, false, null, rels[1])
|
|
10272
|
+
}, [selected, items, data, visibleItems, openViewer, showPasteNotice, t])
|
|
10273
|
+
|
|
9576
10274
|
const selectedCount = selected.size
|
|
9577
10275
|
const batchBar = selectedCount > 0
|
|
9578
10276
|
? h('div', { className: 'dg-batchBar', key: 'batchBar', 'data-gallery-batch-bar': true }, [
|
|
@@ -9592,6 +10290,15 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9592
10290
|
title: t('batchCopyHint'),
|
|
9593
10291
|
onClick: () => { void doCopyAssets([...selected]) },
|
|
9594
10292
|
}, `⧉ ${t('batchCopyFiles')} (${selectedCount})`),
|
|
10293
|
+
// 2026-11-17:正好选两张时给「对比」入口
|
|
10294
|
+
selectedCount === 2
|
|
10295
|
+
? h('button', {
|
|
10296
|
+
type: 'button', className: 'dg-btn dg-btnSmall dg-primaryBtn', key: 'compare',
|
|
10297
|
+
'data-gallery-batch-compare': true,
|
|
10298
|
+
title: t('cmpBatchHint'),
|
|
10299
|
+
onClick: () => openCompareFromSelection(),
|
|
10300
|
+
}, '\u21c4 ' + t('cmpBatchEnter'))
|
|
10301
|
+
: null,
|
|
9595
10302
|
h('button', {
|
|
9596
10303
|
type: 'button', className: 'dg-btn dg-btnSmall', key: 'clearmark',
|
|
9597
10304
|
'data-gallery-batch-clear': true,
|
|
@@ -10281,6 +10988,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
10281
10988
|
index: Math.min(viewer.index, viewer.list.length - 1),
|
|
10282
10989
|
t,
|
|
10283
10990
|
initialOriginal: viewer.asOriginal === true,
|
|
10991
|
+
initialCompare: String(viewer.compareRel ?? ''),
|
|
10284
10992
|
onClose: closeViewer,
|
|
10285
10993
|
onStep: step,
|
|
10286
10994
|
onCrop: doCrop,
|