dsh-gallery 1.0.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 +205 -1
- package/README.md +35 -13
- package/client.js +1128 -119
- package/host/activity.js +208 -0
- package/host/changes.js +236 -0
- package/host/context.js +157 -25
- package/host/derive.js +21 -0
- package/host/http.js +231 -26
- package/host/regions.js +572 -0
- package/host/scan.js +75 -26
- package/host/tools.js +498 -26
- package/index.js +50 -1
- package/package.json +11 -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: '把这张定为「已定稿」(只写标记,不动文件,也不发送消息)',
|
|
@@ -938,6 +958,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
938
958
|
cropSaved: '已裁剪:{name}(已加入「{target}」素材)',
|
|
939
959
|
cropFailed: '裁剪失败:{message}',
|
|
940
960
|
cropMinSize: '选区太小',
|
|
961
|
+
cropCoord: '坐标',
|
|
962
|
+
cropColor: '色值',
|
|
963
|
+
cropCopyColor: '按 Ctrl+C 复制色值',
|
|
964
|
+
cropCopied: '已复制 {hex}',
|
|
941
965
|
trimEnter: '裁剪片段',
|
|
942
966
|
trimExit: '退出裁剪',
|
|
943
967
|
trimPreview: '从入点播放',
|
|
@@ -1024,6 +1048,26 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
1024
1048
|
batchModeExit: 'Exit batch',
|
|
1025
1049
|
batchModeEnterHint: 'Batch mode: click any card to select/deselect (clicking no longer opens the viewer), then edit labels in batch',
|
|
1026
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',
|
|
1027
1071
|
cardConfirm: '✓ Finalize',
|
|
1028
1072
|
cardConfirmed: '✓ Finalized',
|
|
1029
1073
|
cardConfirmHint: 'Mark this as finalized (marks only; no file changes, no message sent)',
|
|
@@ -1328,6 +1372,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
1328
1372
|
cropSaved: 'Cropped: {name} (added to "{target}" assets)',
|
|
1329
1373
|
cropFailed: 'Crop failed: {message}',
|
|
1330
1374
|
cropMinSize: 'Selection too small',
|
|
1375
|
+
cropCoord: 'Position',
|
|
1376
|
+
cropColor: 'Color',
|
|
1377
|
+
cropCopyColor: 'Press Ctrl+C to copy the color',
|
|
1378
|
+
cropCopied: 'Copied {hex}',
|
|
1331
1379
|
trimEnter: 'Trim clip',
|
|
1332
1380
|
trimExit: 'Exit trim',
|
|
1333
1381
|
trimPreview: 'Play from in',
|
|
@@ -2582,6 +2630,45 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
2582
2630
|
.dg-toast-failed { border-color: var(--dsw-alias-state-error-primary, #d9534f); }
|
|
2583
2631
|
.dg-viewerLayer .dg-viewer { flex: 1 1 auto; min-height: 0; }
|
|
2584
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; }
|
|
2585
2672
|
.dg-textBody { display: block; overflow: auto; padding: 12px 14px; user-select: text; touch-action: auto; }
|
|
2586
2673
|
|
|
2587
2674
|
/* ===== 文件卡片 v2:三段式 ===== */
|
|
@@ -3121,9 +3208,9 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3121
3208
|
.dg-annotSvg.dg-annotActive { background: rgba(74, 124, 255, 0.04); }
|
|
3122
3209
|
.dg-btnActive { background: #4a7cff !important; color: #fff !important; border-color: #4a7cff !important; }
|
|
3123
3210
|
|
|
3124
|
-
/*
|
|
3211
|
+
/* 批注列表。离边也统一 20px:原来 8px,跟右上提示条一高一低,看着歪。 */
|
|
3125
3212
|
.dg-annotList {
|
|
3126
|
-
position: absolute; left:
|
|
3213
|
+
position: absolute; left: 20px; top: 20px; z-index: 5;
|
|
3127
3214
|
max-width: 300px; max-height: 40%; overflow: auto;
|
|
3128
3215
|
background: rgba(27, 30, 36, 0.95); border: 1px solid rgba(255, 255, 255, 0.16);
|
|
3129
3216
|
border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 4px;
|
|
@@ -3133,23 +3220,28 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3133
3220
|
.dg-annotIndex { color: #8fb6ff; font-weight: 600; }
|
|
3134
3221
|
.dg-annotText { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3135
3222
|
.dg-annotItem .dg-btn { flex: 0 0 auto; }
|
|
3136
|
-
/*
|
|
3223
|
+
/* 遮罩导出结果提示:避开左上批注列表与右下角确认框,不受 svg 缩放平移影响。
|
|
3224
|
+
边距跟那三个确认框统一成 20px —— 整块界面只有一套网格。 */
|
|
3137
3225
|
.dg-maskNotice {
|
|
3138
|
-
position: absolute; right:
|
|
3226
|
+
position: absolute; right: 20px; top: 20px; z-index: 7;
|
|
3139
3227
|
max-width: min(360px, 70%); padding: 6px 10px; border-radius: 6px;
|
|
3140
3228
|
font-size: 11px; line-height: 1.5; color: #e8eaed;
|
|
3141
3229
|
background: rgba(27, 30, 36, 0.96); border: 1px solid rgba(255, 255, 255, 0.18);
|
|
3142
3230
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
|
|
3231
|
+
animation: dg-panelIn 0.14s ease-out;
|
|
3143
3232
|
}
|
|
3144
3233
|
.dg-maskNotice-ok { border-color: rgba(94, 214, 150, 0.65); }
|
|
3145
3234
|
.dg-maskNotice-failed { border-color: rgba(255, 107, 107, 0.85); color: #ffd7d7; }
|
|
3146
3235
|
|
|
3147
|
-
/*
|
|
3236
|
+
/* 批注输入框(左键拖框选完的状态确认框)。位置口径同裁剪/多边形:
|
|
3237
|
+
钉在右下角、离边 20px、宽 300、松手后淡入。
|
|
3238
|
+
原来贴底居中 —— 框要是圈在画面下半部,正好被它压住,等于边看边被挡。 */
|
|
3148
3239
|
.dg-annotEditor {
|
|
3149
|
-
position: absolute;
|
|
3150
|
-
width:
|
|
3240
|
+
position: absolute; right: 20px; bottom: 20px; left: auto; top: auto; transform: none; z-index: 6;
|
|
3241
|
+
width: 300px; max-width: calc(100% - 40px); background: #1b1e24; color: #e8eaed;
|
|
3151
3242
|
border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 8px; padding: 10px;
|
|
3152
3243
|
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
|
|
3244
|
+
animation: dg-panelIn 0.14s ease-out;
|
|
3153
3245
|
}
|
|
3154
3246
|
.dg-annotEditorHead { font-size: 12px; font-weight: 600; margin-bottom: 8px; }
|
|
3155
3247
|
.dg-annotInput {
|
|
@@ -3158,6 +3250,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3158
3250
|
font-size: 12px; font-family: inherit;
|
|
3159
3251
|
}
|
|
3160
3252
|
.dg-annotInput:focus { outline: 2px solid #4a7cff; outline-offset: -1px; }
|
|
3253
|
+
/* 深色底上浏览器默认的 placeholder 灰几乎看不见,跟 .dg-input 用同一个色 */
|
|
3254
|
+
.dg-annotInput::placeholder { color: #9aa8b8; opacity: 1; }
|
|
3161
3255
|
.dg-annotEditorOps { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
|
|
3162
3256
|
|
|
3163
3257
|
|
|
@@ -3180,13 +3274,24 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3180
3274
|
.dg-annotEditorOps .dg-annotSave:hover:not(:disabled) { background: #6a92ff !important; }
|
|
3181
3275
|
.dg-annotPendingHint { font-size: 11px; color: #ffd166; margin: -2px 0 8px; }
|
|
3182
3276
|
|
|
3183
|
-
/*
|
|
3277
|
+
/* 右下角确认框统一淡入:与裁剪面板那条同参(0.14s / 上移 6px),
|
|
3278
|
+
三个「选完才问你要不要确认」的框出现的手感必须一模一样。 */
|
|
3279
|
+
@keyframes dg-panelIn {
|
|
3280
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
3281
|
+
to { opacity: 1; transform: none; }
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
/* v0.14.6 多边形选区操作条(区域标记 / 填充遮罩共用)。
|
|
3285
|
+
位置口径 2026-11-16 统一:和裁剪确认面板一样钉在**窗口右下角**、
|
|
3286
|
+
离右边和下边各 20px、宽 300 —— 原来贴 8/14,跟另外两个框错位,眼睛要重新找。
|
|
3287
|
+
拖动顶点时整块让开(组件里按 polyDrag 门控),松手再淡入。 */
|
|
3184
3288
|
.dg-polyPanel {
|
|
3185
|
-
position: absolute; right:
|
|
3186
|
-
width:
|
|
3289
|
+
position: absolute; right: 20px; bottom: 20px; z-index: 6;
|
|
3290
|
+
width: 300px; max-width: calc(100% - 40px); box-sizing: border-box;
|
|
3187
3291
|
background: #1b1e24; color: #e8eaed;
|
|
3188
3292
|
border: 1px solid rgba(94, 214, 150, 0.55); border-radius: 8px; padding: 10px;
|
|
3189
3293
|
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
|
|
3294
|
+
animation: dg-panelIn 0.14s ease-out;
|
|
3190
3295
|
}
|
|
3191
3296
|
.dg-polyPanelHead { font-size: 12px; font-weight: 600; color: #9fe1cb; margin-bottom: 6px; }
|
|
3192
3297
|
.dg-polyPanelInfo { font-size: 11px; line-height: 1.5; word-break: break-all; }
|
|
@@ -3210,6 +3315,7 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3210
3315
|
padding: 5px 7px; font-size: 11px; outline: none;
|
|
3211
3316
|
}
|
|
3212
3317
|
.dg-polyNoteInput:focus { border-color: #5ed696; }
|
|
3318
|
+
.dg-polyNoteInput::placeholder { color: #9aa8b8; opacity: 1; }
|
|
3213
3319
|
|
|
3214
3320
|
/* v0.16.0 粘贴结果提示 */
|
|
3215
3321
|
.dg-pasteNotice {
|
|
@@ -3222,38 +3328,72 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3222
3328
|
.dg-pasteOk { border-color: rgba(94,214,150,0.6); }
|
|
3223
3329
|
.dg-pasteFail { border-color: rgba(255,107,107,0.6); color: #ffd2d2; }
|
|
3224
3330
|
|
|
3225
|
-
/*
|
|
3331
|
+
/* v1.0.2 图片裁剪层:绿框 + 八向手柄 + 像素级取色放大镜(照老板给的参考图对齐)
|
|
3226
3332
|
坐标系说明:裁剪框/放大镜都用 getBoundingClientRect 的**视口坐标**定位,
|
|
3227
3333
|
所以这一层必须 fixed 铺满视口,absolute 会相对 stage 偏移导致框错位。 */
|
|
3228
3334
|
.dg-cropLayer { position: fixed; inset: 0; z-index: 60; cursor: crosshair; }
|
|
3335
|
+
/* 框外不再压暗:参考图里整张图亮度不变,靠绿线与手柄识别边界 */
|
|
3229
3336
|
.dg-cropRect {
|
|
3230
|
-
position: absolute; border: 1px solid #
|
|
3231
|
-
box-
|
|
3232
|
-
cursor: move; background: rgba(106,146,255,0.06);
|
|
3337
|
+
position: absolute; border: 1px solid #00e676;
|
|
3338
|
+
box-sizing: border-box; cursor: move; background: transparent;
|
|
3233
3339
|
}
|
|
3234
3340
|
.dg-cropHandle {
|
|
3235
|
-
position: absolute; width:
|
|
3236
|
-
border:
|
|
3341
|
+
position: absolute; width: 9px; height: 9px; background: #00e676;
|
|
3342
|
+
border: 1px solid rgba(0,0,0,0.65); border-radius: 1px; box-sizing: border-box;
|
|
3343
|
+
z-index: 2;
|
|
3237
3344
|
}
|
|
3238
|
-
.dg-cropHandleNW { left: -
|
|
3239
|
-
.dg-cropHandleNE { right: -
|
|
3240
|
-
.dg-cropHandleSW { left: -
|
|
3241
|
-
.dg-cropHandleSE { right: -
|
|
3345
|
+
.dg-cropHandleNW { left: -5px; top: -5px; cursor: nwse-resize; }
|
|
3346
|
+
.dg-cropHandleNE { right: -5px; top: -5px; cursor: nesw-resize; }
|
|
3347
|
+
.dg-cropHandleSW { left: -5px; bottom: -5px; cursor: nesw-resize; }
|
|
3348
|
+
.dg-cropHandleSE { right: -5px; bottom: -5px; cursor: nwse-resize; }
|
|
3349
|
+
/* 四边中点:只沿一个轴拖,免得「只想收一下高度」却把宽度也带歪 */
|
|
3350
|
+
.dg-cropHandleN { left: 50%; top: -5px; margin-left: -5px; cursor: ns-resize; }
|
|
3351
|
+
.dg-cropHandleS { left: 50%; bottom: -5px; margin-left: -5px; cursor: ns-resize; }
|
|
3352
|
+
.dg-cropHandleW { left: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
|
|
3353
|
+
.dg-cropHandleE { right: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
|
|
3354
|
+
/* 尺寸标签:贴在框左上角外侧,白字带阴影,深底浅底都看得清 */
|
|
3355
|
+
.dg-cropSize {
|
|
3356
|
+
position: absolute; padding: 1px 4px; border-radius: 3px;
|
|
3357
|
+
font-size: 11px; line-height: 1.4; font-variant-numeric: tabular-nums;
|
|
3358
|
+
color: #fff; background: rgba(0,0,0,0.42); text-shadow: 0 1px 2px rgba(0,0,0,0.9);
|
|
3359
|
+
pointer-events: none; white-space: nowrap;
|
|
3360
|
+
}
|
|
3361
|
+
/* 像素放大镜(方形)+ 坐标色值卡:参考图里两者是一体的,所以外层包一个定位容器 */
|
|
3362
|
+
.dg-cropMagWrap { position: absolute; width: 148px; pointer-events: none; }
|
|
3242
3363
|
.dg-cropMagnifier {
|
|
3243
|
-
|
|
3244
|
-
border:
|
|
3245
|
-
|
|
3246
|
-
}
|
|
3247
|
-
.dg-cropMagnifier canvas {
|
|
3364
|
+
width: 148px; height: 148px; border-radius: 3px;
|
|
3365
|
+
border: 1px solid rgba(255,255,255,0.5); box-shadow: 0 4px 16px rgba(0,0,0,0.55);
|
|
3366
|
+
overflow: hidden; background: #000;
|
|
3367
|
+
}
|
|
3368
|
+
.dg-cropMagnifier canvas {
|
|
3369
|
+
display: block; width: 100%; height: 100%;
|
|
3370
|
+
image-rendering: pixelated; /* 不做硬边就成了糊图,取色就不准了 */
|
|
3371
|
+
}
|
|
3372
|
+
.dg-cropMagInfo {
|
|
3373
|
+
margin-top: 3px; box-sizing: border-box; width: 148px;
|
|
3374
|
+
background: rgba(255,255,255,0.94); color: #1a1c20;
|
|
3375
|
+
border-radius: 3px; padding: 4px 6px; font-size: 11px; line-height: 1.5;
|
|
3376
|
+
display: grid; grid-template-columns: auto 1fr; column-gap: 10px;
|
|
3377
|
+
font-variant-numeric: tabular-nums; box-shadow: 0 2px 10px rgba(0,0,0,0.4);
|
|
3378
|
+
}
|
|
3379
|
+
.dg-cropMagInfoKey { color: #6b7280; }
|
|
3380
|
+
.dg-cropMagInfoVal { color: #111318; font-weight: 600; text-align: right; }
|
|
3381
|
+
.dg-cropMagHint { grid-column: 1 / -1; color: #6b7280; margin-top: 2px; font-size: 10px; }
|
|
3382
|
+
.dg-cropMagHintOk { color: #0a7d52; font-weight: 600; }
|
|
3248
3383
|
.dg-cropPanel {
|
|
3249
|
-
/*
|
|
3250
|
-
|
|
3251
|
-
cropLayer 是 fixed inset:0
|
|
3384
|
+
/* 位置由组件以内联 right/bottom 注入:**固定在窗口右下角**(老板 2026-11-16
|
|
3385
|
+
要求「靠边固定,跟随鼠标会挡住预览」)。这里千万别再写死 left/bottom 数值 ——
|
|
3386
|
+
cropLayer 是 fixed inset:0,CSS 里的值会和内联的叠在一起把面板顶跑位。 */
|
|
3252
3387
|
position: absolute; z-index: 6; width: 300px;
|
|
3388
|
+
animation: dg-cropPanelIn 0.14s ease-out; /* 松手后才挂载,正好有「弹出来」的手感 */
|
|
3253
3389
|
box-sizing: border-box; background: #1b1e24; color: #e8eaed;
|
|
3254
3390
|
border: 1px solid rgba(106,146,255,0.55); border-radius: 8px; padding: 10px;
|
|
3255
3391
|
box-shadow: 0 8px 28px rgba(0,0,0,0.6);
|
|
3256
3392
|
}
|
|
3393
|
+
@keyframes dg-cropPanelIn {
|
|
3394
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
3395
|
+
to { opacity: 1; transform: none; }
|
|
3396
|
+
}
|
|
3257
3397
|
.dg-cropPanelHead { font-size: 12px; font-weight: 600; color: #a9c4ff; margin-bottom: 6px; }
|
|
3258
3398
|
.dg-cropPanelHint { font-size: 11px; color: #b9c2cf; line-height: 1.5; margin-top: 6px; }
|
|
3259
3399
|
.dg-cropPanelOps { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
|
|
@@ -3431,6 +3571,22 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3431
3571
|
return text !== ''
|
|
3432
3572
|
}
|
|
3433
3573
|
|
|
3574
|
+
/**
|
|
3575
|
+
* 从 MIME / dataURL 推真实扩展名(2026-11-15)。
|
|
3576
|
+
*
|
|
3577
|
+
* 以前统一写死 ext:'png',遇到 JPEG 位图会被 Host 的 PNG 校验拒掉。
|
|
3578
|
+
* 这里只做「上报」,Host 仍按真实魔数复核,写错也不会产生坏文件。
|
|
3579
|
+
*/
|
|
3580
|
+
function imageExtOf(mime, dataUrl) {
|
|
3581
|
+
const fromUrl = /^data:([^;,]+)/i.exec(String(dataUrl ?? ''))
|
|
3582
|
+
const m = String(mime ?? '').toLowerCase() || (fromUrl === null ? '' : fromUrl[1].toLowerCase())
|
|
3583
|
+
if (m === 'image/jpeg' || m === 'image/jpg' || m === 'image/pjpeg') return 'jpg'
|
|
3584
|
+
if (m === 'image/webp') return 'webp'
|
|
3585
|
+
if (m === 'image/gif') return 'gif'
|
|
3586
|
+
if (m === 'image/bmp' || m === 'image/x-ms-bmp') return 'bmp'
|
|
3587
|
+
return 'png'
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3434
3590
|
/** 把 File/Blob 读成 dataURL(含 `data:…;base64,` 前缀)。 */
|
|
3435
3591
|
function fileToDataUrl(file) {
|
|
3436
3592
|
return new Promise((resolve, reject) => {
|
|
@@ -5098,6 +5254,7 @@ function serializeFeedback(feedback) {
|
|
|
5098
5254
|
text: format(t('mediaGrabFrameSaved'), { name: payload?.name ?? '', timecode: payload?.timecode ?? '' }),
|
|
5099
5255
|
})
|
|
5100
5256
|
// 立刻重扫:新资产出现在当前对话组,可马上点开批注 / 进反馈篮
|
|
5257
|
+
kickChanges()
|
|
5101
5258
|
if (typeof onSaved === 'function') onSaved(payload)
|
|
5102
5259
|
} catch (error) {
|
|
5103
5260
|
setGrabNotice({ kind: 'failed', text: format(t('mediaGrabFrameFailed'), { message: String(error?.message ?? error) }) })
|
|
@@ -5754,13 +5911,28 @@ ${absPath}
|
|
|
5754
5911
|
* · 裁剪结果(归一化矩形)交给上层 callHost('cropImage'),落盘到源图同目录并标素材。
|
|
5755
5912
|
* · 零自动发送红线不变:本组件只产出 PNG,落盘与登记由 Host 完成。
|
|
5756
5913
|
*/
|
|
5914
|
+
/** 裁剪放大镜:148px 见方、每格 4px,因此覆盖原图 37×37 像素。
|
|
5915
|
+
* 为什么是这几个数(老板 11-16:10 倍太夸张、像素块太粗不好用,改回 4 倍):
|
|
5916
|
+
* ① 格宽 4px 既能看出「一格 = 一个像素」,又不至于几格就占满一片;
|
|
5917
|
+
* ② 4 倍下要看 37 格才填满,37 是奇数 → 光标那格正好落在正中,绿十字压得准;
|
|
5918
|
+
* ③ 37 × 4 = 148,size 必须是 factor 的整数倍,否则光标格会偏半格、十字压到缝上。
|
|
5919
|
+
* 三个数互相咬死:改倍率就得同时重算 size(tests/crop-frame-ui.test.mjs 有断言钉住)。 */
|
|
5920
|
+
const CROP_MAG_SIZE = 148
|
|
5921
|
+
const CROP_MAG_FACTOR = 4
|
|
5922
|
+
|
|
5757
5923
|
function ImageCropper({ t, item, imgRef, onCrop, onCancel }) {
|
|
5758
5924
|
const [rect, setRect] = React.useState(null) // {x,y,w,h} 归一化 0–1(相对图片宽高)
|
|
5759
|
-
|
|
5925
|
+
// mode:new 新建 / move 整体挪 / 四角 nw ne sw se / 四边 n s w e(只动单侧)
|
|
5926
|
+
const [drag, setDrag] = React.useState(null) // { mode, sx, sy, startRect }
|
|
5760
5927
|
const [mag, setMag] = React.useState(null) // { cx, cy(视口), nx, ny(归一化) }
|
|
5761
5928
|
const [full, setFull] = React.useState(null) // 全分辨率 HTMLImageElement
|
|
5762
5929
|
const [busy, setBusy] = React.useState(false)
|
|
5930
|
+
const [copied, setCopied] = React.useState('') // 复制回执,1.4 秒后自动消失
|
|
5763
5931
|
const magCanvasRef = React.useRef(null)
|
|
5932
|
+
// 取色用的 1×1 离屏画布:只读一个像素,比重建整块画布便宜得多
|
|
5933
|
+
const probeCanvasRef = React.useRef(null)
|
|
5934
|
+
// 光标处色值放 ref:快捷键 effect 不必因颜色变化反复重挂
|
|
5935
|
+
const colorRef = React.useRef('')
|
|
5764
5936
|
|
|
5765
5937
|
// 载入全分辨率源图(放大镜取真实像素 + 最终裁图)
|
|
5766
5938
|
React.useEffect(() => {
|
|
@@ -5820,6 +5992,11 @@ ${absPath}
|
|
|
5820
5992
|
else if (d.mode === 'ne') { y = n.y; w = n.x - s.x; h = (s.y + s.h) - n.y }
|
|
5821
5993
|
else if (d.mode === 'sw') { x = n.x; w = (s.x + s.w) - n.x; h = n.y - s.y }
|
|
5822
5994
|
else if (d.mode === 'nw') { x = n.x; y = n.y; w = (s.x + s.w) - n.x; h = (s.y + s.h) - n.y }
|
|
5995
|
+
// 四边中点:另一个轴原样不动,这才能「只收高度、不把宽度带歪」
|
|
5996
|
+
else if (d.mode === 'n') { y = n.y; h = (s.y + s.h) - n.y }
|
|
5997
|
+
else if (d.mode === 's') { h = n.y - s.y }
|
|
5998
|
+
else if (d.mode === 'w') { x = n.x; w = (s.x + s.w) - n.x }
|
|
5999
|
+
else if (d.mode === 'e') { w = n.x - s.x }
|
|
5823
6000
|
if (w < 0) { x += w; w = -w }
|
|
5824
6001
|
if (h < 0) { y += h; h = -h }
|
|
5825
6002
|
x = clamp01(x); y = clamp01(y); w = clamp01(w); h = clamp01(h)
|
|
@@ -5851,30 +6028,75 @@ ${absPath}
|
|
|
5851
6028
|
}
|
|
5852
6029
|
const onLayerUp = () => setDrag(null)
|
|
5853
6030
|
|
|
5854
|
-
|
|
6031
|
+
/**
|
|
6032
|
+
* 放大镜绘制:按整数像素格放大(4×),并关掉插值。
|
|
6033
|
+
* 不关插值就成了糊图、取色看着「不准」;4 倍下每格 4px,看得出格子又不像 10 倍那么粗。
|
|
6034
|
+
* 十字线用绿色高亮(白的在浅色招牌上根本看不见)。
|
|
6035
|
+
*/
|
|
5855
6036
|
React.useEffect(() => {
|
|
5856
6037
|
const canvas = magCanvasRef.current
|
|
5857
6038
|
if (canvas === null || full === null || mag === null) return
|
|
5858
6039
|
const ctx = canvas.getContext('2d')
|
|
5859
6040
|
if (ctx === null) return
|
|
5860
6041
|
const SIZE = canvas.width
|
|
5861
|
-
const FACTOR =
|
|
6042
|
+
const FACTOR = CROP_MAG_FACTOR
|
|
6043
|
+
const SPAN = SIZE / FACTOR // 源图取样边长(像素)
|
|
5862
6044
|
const FW = full.naturalWidth
|
|
5863
6045
|
const FH = full.naturalHeight
|
|
5864
|
-
|
|
5865
|
-
const
|
|
5866
|
-
const
|
|
6046
|
+
// 让光标所在像素成为正中间那格:左右各取 floor(SPAN/2) 格
|
|
6047
|
+
const half = Math.floor(SPAN / 2)
|
|
6048
|
+
const px = clampNum(Math.round(mag.nx * FW), 0, Math.max(0, FW - 1))
|
|
6049
|
+
const py = clampNum(Math.round(mag.ny * FH), 0, Math.max(0, FH - 1))
|
|
6050
|
+
const sx = clampNum(px - half, 0, Math.max(0, FW - SPAN))
|
|
6051
|
+
const sy = clampNum(py - half, 0, Math.max(0, FH - SPAN))
|
|
6052
|
+
ctx.imageSmoothingEnabled = false
|
|
5867
6053
|
ctx.fillStyle = '#000'
|
|
5868
6054
|
ctx.fillRect(0, 0, SIZE, SIZE)
|
|
5869
|
-
ctx.drawImage(full, sx, sy,
|
|
5870
|
-
|
|
5871
|
-
|
|
6055
|
+
ctx.drawImage(full, sx, sy, SPAN, SPAN, 0, 0, SIZE, SIZE)
|
|
6056
|
+
// 绿十字:压在正中那一格的中线上,线宽 2 才够醒目
|
|
6057
|
+
const mid = SIZE / 2
|
|
6058
|
+
ctx.strokeStyle = 'rgba(0,230,118,0.95)'
|
|
6059
|
+
ctx.lineWidth = 2
|
|
5872
6060
|
ctx.beginPath()
|
|
5873
|
-
ctx.moveTo(
|
|
5874
|
-
ctx.moveTo(0,
|
|
6061
|
+
ctx.moveTo(mid, 0); ctx.lineTo(mid, SIZE)
|
|
6062
|
+
ctx.moveTo(0, mid); ctx.lineTo(SIZE, mid)
|
|
5875
6063
|
ctx.stroke()
|
|
5876
6064
|
}, [mag, full])
|
|
5877
6065
|
|
|
6066
|
+
/**
|
|
6067
|
+
* 裁剪态按键:Ctrl+C 复制光标处色值;左右键不翻页。
|
|
6068
|
+
* 翻页会把框套到另一张图上(框还在、图换了),所以必须拦住。
|
|
6069
|
+
* 走捕获阶段 + stopImmediatePropagation:查看器自己的 Ctrl+C 是「复制文件」,
|
|
6070
|
+
* 不先截住就会把文件写进剪贴板,而不是色值。
|
|
6071
|
+
*/
|
|
6072
|
+
React.useEffect(() => {
|
|
6073
|
+
const onKey = (event) => {
|
|
6074
|
+
if (isTypingTarget(event.target)) return
|
|
6075
|
+
const key = String(event.key ?? '')
|
|
6076
|
+
if ((event.ctrlKey || event.metaKey) && (key === 'c' || key === 'C')) {
|
|
6077
|
+
const hex = colorRef.current
|
|
6078
|
+
if (hex === '') return
|
|
6079
|
+
event.preventDefault()
|
|
6080
|
+
event.stopImmediatePropagation()
|
|
6081
|
+
copyText(hex)
|
|
6082
|
+
setCopied(hex)
|
|
6083
|
+
return
|
|
6084
|
+
}
|
|
6085
|
+
if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
|
6086
|
+
event.stopImmediatePropagation()
|
|
6087
|
+
}
|
|
6088
|
+
}
|
|
6089
|
+
window.addEventListener('keydown', onKey, true)
|
|
6090
|
+
return () => window.removeEventListener('keydown', onKey, true)
|
|
6091
|
+
}, [])
|
|
6092
|
+
|
|
6093
|
+
// 复制回执:1.4 秒后自动收起,避免一直挂在那里
|
|
6094
|
+
React.useEffect(() => {
|
|
6095
|
+
if (copied === '') return undefined
|
|
6096
|
+
const timer = setTimeout(() => setCopied(''), 1400)
|
|
6097
|
+
return () => clearTimeout(timer)
|
|
6098
|
+
}, [copied])
|
|
6099
|
+
|
|
5878
6100
|
const confirmCrop = () => {
|
|
5879
6101
|
if (full === null || rect === null || rect.w < 0.02 || rect.h < 0.02) return
|
|
5880
6102
|
setBusy(true)
|
|
@@ -5919,44 +6141,108 @@ ${absPath}
|
|
|
5919
6141
|
height: `${rect.h * r.height}px`,
|
|
5920
6142
|
}
|
|
5921
6143
|
: {}
|
|
5922
|
-
const
|
|
5923
|
-
const
|
|
6144
|
+
const vw = Number(typeof window !== 'undefined' ? window.innerWidth : 0) || 1280
|
|
6145
|
+
const vh = Number(typeof window !== 'undefined' ? window.innerHeight : 0) || 800
|
|
6146
|
+
|
|
6147
|
+
// 尺寸标签写的是「裁下来多少像素」,所以按原图自然尺寸 × 归一化比例算,不是屏幕像素
|
|
6148
|
+
const cropSize = (rect !== null && full !== null)
|
|
6149
|
+
? {
|
|
6150
|
+
w: Math.max(1, Math.round(rect.w * full.naturalWidth)),
|
|
6151
|
+
h: Math.max(1, Math.round(rect.h * full.naturalHeight)),
|
|
6152
|
+
}
|
|
6153
|
+
: null
|
|
6154
|
+
|
|
6155
|
+
/** 光标处的原图像素坐标 + 色值。1×1 离屏画布取一个像素;
|
|
6156
|
+
* 图是 blob: 同源地址,不会污染画布,getImageData 可读。 */
|
|
6157
|
+
const probe = React.useMemo(() => {
|
|
6158
|
+
if (full === null || mag === null) return null
|
|
6159
|
+
const FW = full.naturalWidth
|
|
6160
|
+
const FH = full.naturalHeight
|
|
6161
|
+
if (FW <= 0 || FH <= 0) return null
|
|
6162
|
+
const px = clampNum(Math.round(mag.nx * FW), 0, FW - 1)
|
|
6163
|
+
const py = clampNum(Math.round(mag.ny * FH), 0, FH - 1)
|
|
6164
|
+
let hex = ''
|
|
6165
|
+
try {
|
|
6166
|
+
let canvas = probeCanvasRef.current
|
|
6167
|
+
if (canvas === null) {
|
|
6168
|
+
canvas = document.createElement('canvas')
|
|
6169
|
+
canvas.width = 1
|
|
6170
|
+
canvas.height = 1
|
|
6171
|
+
probeCanvasRef.current = canvas
|
|
6172
|
+
}
|
|
6173
|
+
const c2d = canvas.getContext('2d')
|
|
6174
|
+
if (c2d !== null) {
|
|
6175
|
+
c2d.clearRect(0, 0, 1, 1)
|
|
6176
|
+
c2d.drawImage(full, px, py, 1, 1, 0, 0, 1, 1)
|
|
6177
|
+
const d = c2d.getImageData(0, 0, 1, 1).data
|
|
6178
|
+
hex = '#' + [d[0], d[1], d[2]].map((v) => v.toString(16).padStart(2, '0')).join('').toUpperCase()
|
|
6179
|
+
}
|
|
6180
|
+
} catch { hex = '' }
|
|
6181
|
+
return { px, py, hex }
|
|
6182
|
+
}, [mag, full])
|
|
6183
|
+
colorRef.current = probe !== null ? probe.hex : ''
|
|
6184
|
+
|
|
6185
|
+
// 尺寸标签贴框左上角外侧;顶上没空间就挪进框内,别让它被视口裁掉
|
|
6186
|
+
const sizeStyle = (() => {
|
|
6187
|
+
if (rect === null || r === null) return {}
|
|
6188
|
+
const boxLeft = r.left + rect.x * r.width
|
|
6189
|
+
const boxTop = r.top + rect.y * r.height
|
|
6190
|
+
const above = boxTop - 20
|
|
6191
|
+
return {
|
|
6192
|
+
left: `${clampNum(boxLeft, 4, Math.max(4, vw - 96))}px`,
|
|
6193
|
+
top: `${above >= 4 ? above : boxTop + 3}px`,
|
|
6194
|
+
}
|
|
6195
|
+
})()
|
|
5924
6196
|
|
|
5925
6197
|
/**
|
|
5926
|
-
*
|
|
5927
|
-
*
|
|
5928
|
-
*
|
|
6198
|
+
* 操作面板**固定在窗口右下角**,不再跟着选区跑(老板 2026-11-16:
|
|
6199
|
+
* 「裁剪的这个状态确认框让靠边固定吧,跟随鼠标会挡住预览」)。
|
|
6200
|
+
* 原来按选区水平居中、贴框下方(微信截图式),实测选区在中间或偏下时
|
|
6201
|
+
* 正好压住要靠细节的那块,拖框时它还跟着晃、眼睛要一直追。
|
|
6202
|
+
* 现在钉在角落:位置可预期、永远不挡正在调的那块。
|
|
6203
|
+
* 用 right/bottom 而不是算好的 left/top —— 面板高度随提示文字换行变化,
|
|
6204
|
+
* 写死 top 一旦文字变长就会顶出窗口下沿。cropLayer 是 fixed inset:0,
|
|
6205
|
+
* absolute 子元素自然相对视口。
|
|
5929
6206
|
*/
|
|
5930
6207
|
const PANEL_W = 300
|
|
5931
|
-
const PANEL_H = 118
|
|
5932
|
-
const
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
6208
|
+
const PANEL_H = 118 // 估算值,只用于「别让放大镜压上去」
|
|
6209
|
+
const PANEL_MARGIN = 20
|
|
6210
|
+
const panelStyle = { right: `${PANEL_MARGIN}px`, bottom: `${PANEL_MARGIN}px` }
|
|
6211
|
+
// 拖动过程中先不显示面板(老板 2026-11-16:「或者选完后在弹出状态确认」)。
|
|
6212
|
+
// 拖的时候画面完全干净;松手才出现,位置永远在右下角,不跟鼠标跑。
|
|
6213
|
+
const showPanel = drag === null
|
|
6214
|
+
const canConfirm = rect !== null && rect.w >= 0.02 && rect.h >= 0.02
|
|
6215
|
+
// 面板实际矩形(估算,够判断重叠):右下角、宽 300、高约 118
|
|
6216
|
+
const panelLeft = Math.max(8, vw - PANEL_W - PANEL_MARGIN)
|
|
6217
|
+
const panelTop = Math.max(8, vh - PANEL_H - PANEL_MARGIN)
|
|
6218
|
+
|
|
6219
|
+
// 放大镜默认贴光标右下方(参考图即如此);放不下、或会压住面板,就换另一侧
|
|
6220
|
+
const MAG_W = CROP_MAG_SIZE
|
|
6221
|
+
const MAG_H = CROP_MAG_SIZE + 76 // 放大镜 + 间距 + 坐标色值卡
|
|
6222
|
+
const hitsPanel = (left, top) => left < panelLeft + PANEL_W && left + MAG_W > panelLeft
|
|
6223
|
+
&& top < panelTop + PANEL_H && top + MAG_H > panelTop
|
|
6224
|
+
const magPos = (() => {
|
|
6225
|
+
if (mag === null) return { left: 0, top: 0 }
|
|
6226
|
+
const gap = 18
|
|
6227
|
+
// 四个候选按「右下 → 左下 → 右上 → 左上」的偏好序试,跟人眼找位置的顺序一致
|
|
6228
|
+
const spots = [
|
|
6229
|
+
{ left: mag.cx + gap, top: mag.cy + gap },
|
|
6230
|
+
{ left: mag.cx - gap - MAG_W, top: mag.cy + gap },
|
|
6231
|
+
{ left: mag.cx + gap, top: mag.cy - gap - MAG_H },
|
|
6232
|
+
{ left: mag.cx - gap - MAG_W, top: mag.cy - gap - MAG_H },
|
|
6233
|
+
]
|
|
6234
|
+
const inView = (s) => s.left >= 8 && s.left + MAG_W <= vw - 8
|
|
6235
|
+
&& s.top >= 8 && s.top + MAG_H <= vh - 8
|
|
6236
|
+
const picked = spots.find((s) => inView(s) && !hitsPanel(s.left, s.top))
|
|
6237
|
+
?? spots.find((s) => !hitsPanel(s.left, s.top))
|
|
6238
|
+
?? spots[0]
|
|
6239
|
+
return {
|
|
6240
|
+
left: clampNum(picked.left, 8, Math.max(8, vw - MAG_W - 8)),
|
|
6241
|
+
top: clampNum(picked.top, 8, Math.max(8, vh - MAG_H - 8)),
|
|
6242
|
+
}
|
|
5959
6243
|
})()
|
|
6244
|
+
const magLeft = magPos.left
|
|
6245
|
+
const magTop = magPos.top
|
|
5960
6246
|
|
|
5961
6247
|
return h('div', {
|
|
5962
6248
|
className: 'dg-cropLayer',
|
|
@@ -5976,20 +6262,50 @@ ${absPath}
|
|
|
5976
6262
|
style: rectStyle,
|
|
5977
6263
|
onPointerDown: (e) => startDrag(e, 'move'),
|
|
5978
6264
|
}, [
|
|
5979
|
-
|
|
5980
|
-
h('div', { className: 'dg-cropHandle dg-
|
|
5981
|
-
h('div', { className: 'dg-cropHandle dg-
|
|
5982
|
-
h('div', { className: 'dg-cropHandle dg-
|
|
6265
|
+
// 四角:斜着调
|
|
6266
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleNW', key: 'nw', 'data-gallery-crop-handle': 'nw', onPointerDown: (e) => startDrag(e, 'nw') }),
|
|
6267
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleNE', key: 'ne', 'data-gallery-crop-handle': 'ne', onPointerDown: (e) => startDrag(e, 'ne') }),
|
|
6268
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleSW', key: 'sw', 'data-gallery-crop-handle': 'sw', onPointerDown: (e) => startDrag(e, 'sw') }),
|
|
6269
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleSE', key: 'se', 'data-gallery-crop-handle': 'se', onPointerDown: (e) => startDrag(e, 'se') }),
|
|
6270
|
+
// 四边中点:单边调(参考图上共八个手柄)
|
|
6271
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleN', key: 'n', 'data-gallery-crop-handle': 'n', onPointerDown: (e) => startDrag(e, 'n') }),
|
|
6272
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleS', key: 's', 'data-gallery-crop-handle': 's', onPointerDown: (e) => startDrag(e, 's') }),
|
|
6273
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleW', key: 'w', 'data-gallery-crop-handle': 'w', onPointerDown: (e) => startDrag(e, 'w') }),
|
|
6274
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleE', key: 'e', 'data-gallery-crop-handle': 'e', onPointerDown: (e) => startDrag(e, 'e') }),
|
|
5983
6275
|
])
|
|
5984
6276
|
: null,
|
|
5985
|
-
|
|
6277
|
+
// 左上角尺寸标签:显示裁下来是多少像素
|
|
6278
|
+
rect !== null && cropSize !== null
|
|
6279
|
+
? h('div', {
|
|
6280
|
+
className: 'dg-cropSize',
|
|
6281
|
+
key: 'size',
|
|
6282
|
+
'data-gallery-crop-size': true,
|
|
6283
|
+
style: sizeStyle,
|
|
6284
|
+
}, `${cropSize.w} × ${cropSize.h}`)
|
|
6285
|
+
: null,
|
|
6286
|
+
mag !== null && full !== null && probe !== null
|
|
5986
6287
|
? h('div', {
|
|
5987
|
-
className: 'dg-
|
|
6288
|
+
className: 'dg-cropMagWrap',
|
|
5988
6289
|
key: 'mag',
|
|
5989
|
-
|
|
5990
|
-
|
|
6290
|
+
'data-gallery-crop-mag': true,
|
|
6291
|
+
style: { left: `${magLeft}px`, top: `${magTop}px` },
|
|
6292
|
+
}, [
|
|
6293
|
+
h('div', { className: 'dg-cropMagnifier', key: 'canvas' },
|
|
6294
|
+
h('canvas', { ref: magCanvasRef, width: CROP_MAG_SIZE, height: CROP_MAG_SIZE, key: 'magCanvas' })),
|
|
6295
|
+
h('div', { className: 'dg-cropMagInfo', key: 'info' }, [
|
|
6296
|
+
h('span', { className: 'dg-cropMagInfoKey', key: 'kx' }, t('cropCoord')),
|
|
6297
|
+
h('span', { className: 'dg-cropMagInfoVal', key: 'vx', 'data-gallery-crop-coord': true }, `${probe.px}, ${probe.py}`),
|
|
6298
|
+
h('span', { className: 'dg-cropMagInfoKey', key: 'kc' }, t('cropColor')),
|
|
6299
|
+
h('span', { className: 'dg-cropMagInfoVal', key: 'vc', 'data-gallery-crop-color': true }, probe.hex === '' ? '—' : probe.hex),
|
|
6300
|
+
h('span', {
|
|
6301
|
+
className: copied === '' ? 'dg-cropMagHint' : 'dg-cropMagHint dg-cropMagHintOk',
|
|
6302
|
+
key: 'hint',
|
|
6303
|
+
'data-gallery-crop-copyhint': true,
|
|
6304
|
+
}, copied === '' ? t('cropCopyColor') : format(t('cropCopied'), { hex: copied })),
|
|
6305
|
+
]),
|
|
6306
|
+
])
|
|
5991
6307
|
: null,
|
|
5992
|
-
h('div', {
|
|
6308
|
+
showPanel ? h('div', {
|
|
5993
6309
|
className: 'dg-cropPanel',
|
|
5994
6310
|
key: 'panel',
|
|
5995
6311
|
'data-gallery-crop-panel': true,
|
|
@@ -6006,16 +6322,107 @@ ${absPath}
|
|
|
6006
6322
|
onClick: (e) => { e.stopPropagation(); onCancel() },
|
|
6007
6323
|
}, t('cropCancel')),
|
|
6008
6324
|
h('button', {
|
|
6009
|
-
type: 'button', className: 'dg-btn dg-btnPrimary', key: 'ok',
|
|
6325
|
+
type: 'button', className: 'dg-btn dg-btnPrimary', key: 'ok',
|
|
6326
|
+
disabled: busy || !canConfirm, // 还没拖出框就点不动,避免点了没反应像坏了
|
|
6010
6327
|
'data-gallery-crop-confirm': true,
|
|
6011
6328
|
onClick: (e) => { e.stopPropagation(); confirmCrop() },
|
|
6012
6329
|
}, busy ? t('cropSaving') : t('cropConfirm')),
|
|
6013
6330
|
]),
|
|
6331
|
+
]) : null,
|
|
6332
|
+
])
|
|
6333
|
+
}
|
|
6334
|
+
|
|
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')),
|
|
6014
6421
|
]),
|
|
6015
6422
|
])
|
|
6016
6423
|
}
|
|
6017
6424
|
|
|
6018
|
-
function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop, onCopyFile }) {
|
|
6425
|
+
function Viewer({ items, index, onClose, onStep, t, initialOriginal, initialCompare, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop, onCopyFile }) {
|
|
6019
6426
|
const item = items[index]
|
|
6020
6427
|
// 文件预览已改走 DSH 原生侧栏(session 地址);此处 Viewer 仅处理图片,isText 恒 false,
|
|
6021
6428
|
// 下面的文本分支保留为死代码,供 v0.2 若需插件内预览时复用
|
|
@@ -6023,11 +6430,173 @@ ${absPath}
|
|
|
6023
6430
|
const [state, setState] = React.useState({ status: 'pending' })
|
|
6024
6431
|
const [zoom, setZoom] = React.useState(1)
|
|
6025
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
|
|
6026
6440
|
const [dragging, setDragging] = React.useState(false)
|
|
6027
6441
|
const bodyRef = React.useRef(null)
|
|
6028
6442
|
const imgRef = React.useRef(null)
|
|
6029
6443
|
/** 图片在预览容器里的真实布局盒(不含 transform);批注层据此对齐,1:1 也不跑偏。 */
|
|
6030
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
|
+
}
|
|
6031
6600
|
const dragRef = React.useRef(null)
|
|
6032
6601
|
// 上一次拖动是否真的产生了位移(用于区分「拖图」和「单击关闭」)
|
|
6033
6602
|
const lastDragMoved = React.useRef(false)
|
|
@@ -6105,10 +6674,16 @@ ${absPath}
|
|
|
6105
6674
|
setOriginalMode(false)
|
|
6106
6675
|
setOriginal({ status: 'idle' })
|
|
6107
6676
|
setCropActive(false)
|
|
6677
|
+
// 换图后对比对象失效:写盘路径不同,留着只会显示别人的图
|
|
6678
|
+
releaseCmp()
|
|
6679
|
+
setCmpTarget(null)
|
|
6680
|
+
setPickerOpen(false)
|
|
6681
|
+
setSplitPct(50)
|
|
6682
|
+
setCmpSwapped(false)
|
|
6108
6683
|
return () => {
|
|
6109
6684
|
if (originalAbortRef.current !== null) originalAbortRef.current.abort()
|
|
6110
6685
|
}
|
|
6111
|
-
}, [item.relPath])
|
|
6686
|
+
}, [item.relPath, releaseCmp])
|
|
6112
6687
|
|
|
6113
6688
|
// 首次挂载时如果要求直接看原图,立刻开始加载。
|
|
6114
6689
|
// 放在「换图重置」之后,顺序上不会再被清掉。
|
|
@@ -6203,28 +6778,64 @@ ${absPath}
|
|
|
6203
6778
|
|
|
6204
6779
|
// 滚轮缩放:以鼠标位置为中心,避免放大后目标跑出视野(仅图片模式)。
|
|
6205
6780
|
// 文本预览用原生滚动,不拦截滚轮。
|
|
6781
|
+
// 平铺对比时锚点要换成「光标所在那一格」的中心,见 onWheel 里的注释。
|
|
6782
|
+
const cmpTileRef = React.useRef(false)
|
|
6783
|
+
cmpTileRef.current = cmpTarget !== null && cmpMode === 'tile'
|
|
6206
6784
|
React.useEffect(() => {
|
|
6207
6785
|
const node = bodyRef.current
|
|
6208
6786
|
if (node === null || state.status !== 'ready' || isText) return undefined
|
|
6209
6787
|
const onWheel = (event) => {
|
|
6210
6788
|
event.preventDefault()
|
|
6211
6789
|
const delta = event.deltaY < 0 ? 1 : -1
|
|
6212
|
-
|
|
6213
|
-
//
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
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 {
|
|
6221
6827
|
const ratio = next / current
|
|
6222
|
-
|
|
6828
|
+
const p = viewRef.current.pan
|
|
6829
|
+
nextPan = {
|
|
6223
6830
|
x: cx - (cx - p.x) * ratio,
|
|
6224
6831
|
y: cy - (cy - p.y) * ratio,
|
|
6225
|
-
}
|
|
6226
|
-
|
|
6227
|
-
|
|
6832
|
+
}
|
|
6833
|
+
}
|
|
6834
|
+
// 即时写 ref(连续滚轮时下一帧能读到最新值),再分别 set,互不嵌套
|
|
6835
|
+
viewRef.current.zoom = next
|
|
6836
|
+
viewRef.current.pan = nextPan
|
|
6837
|
+
setZoom(next)
|
|
6838
|
+
setPan(nextPan)
|
|
6228
6839
|
}
|
|
6229
6840
|
node.addEventListener('wheel', onWheel, { passive: false })
|
|
6230
6841
|
return () => node.removeEventListener('wheel', onWheel)
|
|
@@ -6291,6 +6902,9 @@ ${absPath}
|
|
|
6291
6902
|
const onClickBody = (event) => {
|
|
6292
6903
|
// 标注模式下点图只用于画框,不能顺手把大图关掉(老板 20:32 指出的冲突)
|
|
6293
6904
|
if (annotActive) return
|
|
6905
|
+
// 对比态下点画面只是看图:平铺两格各占一半,鼠标想比细节时很容易点到,
|
|
6906
|
+
// 一点就把整个大图关了,退出对比请用工具栏按钮或 Esc。
|
|
6907
|
+
if (cmpTarget !== null) return
|
|
6294
6908
|
// v0.16.0 裁剪模式下点击被裁剪层接管,不应关闭查看器
|
|
6295
6909
|
if (cropActive) return
|
|
6296
6910
|
event.preventDefault()
|
|
@@ -6345,11 +6959,14 @@ ${absPath}
|
|
|
6345
6959
|
}, [vOverflow])
|
|
6346
6960
|
|
|
6347
6961
|
const zoomBy = React.useCallback((direction) => {
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
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)
|
|
6353
6970
|
}, [])
|
|
6354
6971
|
|
|
6355
6972
|
/**
|
|
@@ -6375,13 +6992,24 @@ ${absPath}
|
|
|
6375
6992
|
const key = event.key
|
|
6376
6993
|
if (key === 'Escape') {
|
|
6377
6994
|
event.preventDefault()
|
|
6378
|
-
|
|
6379
|
-
|
|
6995
|
+
// 对比中先退对比:不然顺手把整个大图也关了,得重新找图
|
|
6996
|
+
if (cmpTarget !== null) exitCompare()
|
|
6997
|
+
else onClose()
|
|
6998
|
+
} else if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
|
6380
6999
|
event.preventDefault()
|
|
6381
|
-
|
|
6382
|
-
|
|
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) {
|
|
7008
|
+
event.preventDefault()
|
|
7009
|
+
setCmpSwapped((v) => !v)
|
|
7010
|
+
} else if ((key === 't' || key === 'T') && cmpTarget !== null) {
|
|
6383
7011
|
event.preventDefault()
|
|
6384
|
-
|
|
7012
|
+
setCmpMode((m) => (m === 'slider' ? 'tile' : 'slider'))
|
|
6385
7013
|
} else if (key === 'ArrowUp') {
|
|
6386
7014
|
event.preventDefault()
|
|
6387
7015
|
panStep(-1)
|
|
@@ -6415,7 +7043,7 @@ ${absPath}
|
|
|
6415
7043
|
}
|
|
6416
7044
|
window.addEventListener('keydown', onKey)
|
|
6417
7045
|
return () => window.removeEventListener('keydown', onKey)
|
|
6418
|
-
}, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath])
|
|
7046
|
+
}, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath, cmpTarget, exitCompare])
|
|
6419
7047
|
|
|
6420
7048
|
const sliderDragRef = React.useRef(null)
|
|
6421
7049
|
const onSliderPointerDown = (event) => {
|
|
@@ -6587,7 +7215,62 @@ ${absPath}
|
|
|
6587
7215
|
event.stopPropagation()
|
|
6588
7216
|
setCropActive((v) => !v)
|
|
6589
7217
|
},
|
|
6590
|
-
}, 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
|
+
]))
|
|
6591
7274
|
: null,
|
|
6592
7275
|
// 「拖到对话」确定性入口:Viewer 大图本身 draggable:false + pointerEvents:none
|
|
6593
7276
|
// (标注态的中键平移 / 右键多边形都依赖它),所以不改大图,另给一个可拖按钮。
|
|
@@ -6663,9 +7346,38 @@ ${absPath}
|
|
|
6663
7346
|
pointerEvents: 'none',
|
|
6664
7347
|
},
|
|
6665
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,
|
|
6666
7378
|
// 批注层贴着图片真实布局盒,与图片共用同一组 zoom/pan。
|
|
6667
7379
|
// imgBox 还没量出来(图片未布局)时不画框,免得拿容器当基准错位。
|
|
6668
|
-
imgBox === null ? null : h(AnnotationLayer, {
|
|
7380
|
+
imgBox === null || cmpTarget !== null ? null : h(AnnotationLayer, {
|
|
6669
7381
|
key: 'annot',
|
|
6670
7382
|
t,
|
|
6671
7383
|
annotations: annotsOfCurrent,
|
|
@@ -6683,15 +7395,96 @@ ${absPath}
|
|
|
6683
7395
|
? (a) => onExportMask(item, a)
|
|
6684
7396
|
: undefined,
|
|
6685
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,
|
|
6686
7440
|
]))
|
|
6687
7441
|
: state.status === 'binary'
|
|
6688
7442
|
? h('div', { className: 'dg-placeholder', key: 'bin' }, t('binaryHint'))
|
|
6689
7443
|
: h('div', { className: state.status === 'failed' ? 'dg-placeholder dg-error' : 'dg-placeholder' },
|
|
6690
7444
|
state.status === 'failed' ? `${t('thumbFailed')}:${item.name}` : t('loading')),
|
|
6691
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,
|
|
6692
7485
|
slider,
|
|
6693
7486
|
// v0.16.0 裁剪覆盖层:裁剪模式开启时显示(含微信式放大镜),固定在视口上、与 pan/zoom 解耦
|
|
6694
|
-
cropActive && isImageItem(item) && !isText && state.status === 'ready'
|
|
7487
|
+
cropActive && cmpTarget === null && isImageItem(item) && !isText && state.status === 'ready'
|
|
6695
7488
|
? h(ImageCropper, {
|
|
6696
7489
|
key: 'cropper',
|
|
6697
7490
|
t,
|
|
@@ -7192,7 +7985,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7192
7985
|
/** 多边形选区操作条:点数 / 外接框 / 面积实时可见,闭合前可撤销、可清空。 */
|
|
7193
7986
|
const polyBox = poly.length > 0 ? polygonBBox(poly) : null
|
|
7194
7987
|
const isNoteMode = polyMode === 'note'
|
|
7195
|
-
|
|
7988
|
+
// 拖顶点时先把面板藏起来(老板 2026-11-16:确认框别挡正在看的那块),
|
|
7989
|
+
// 松手立刻回来、带淡入;位置本来就钉在右下角,只在拖动这一瞬让开。
|
|
7990
|
+
const polyPanel = (poly.length === 0 || polyDrag !== null) ? null : h('div', {
|
|
7196
7991
|
className: 'dg-polyPanel', key: 'polyPanel',
|
|
7197
7992
|
'data-gallery-poly-panel': true,
|
|
7198
7993
|
'data-gallery-poly-mode': polyMode,
|
|
@@ -7775,6 +8570,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7775
8570
|
function GalleryBody(props) {
|
|
7776
8571
|
const { t, sessionId } = props
|
|
7777
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
|
+
|
|
7778
8578
|
// v0.17.0:本面板自己的轻提示(写进输入框的结果反馈)。
|
|
7779
8579
|
// 不能用 FeedbackBasket 的 setNotice —— 那是另一个组件的局部 state。
|
|
7780
8580
|
const [toast, setToast] = React.useState(null)
|
|
@@ -7915,6 +8715,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7915
8715
|
? { relPath: String(linkedMask.relPath ?? '') } : null),
|
|
7916
8716
|
sessionId: String(current.sessionId ?? viewer.originSid ?? ''),
|
|
7917
8717
|
sessionTitle: String(current.sessionTitle ?? viewer.originTitle ?? ''),
|
|
8718
|
+
// 第二档:文件自身改动时间(后台按活跃度排「最近看过的图」时要用)
|
|
8719
|
+
mtime: Number(current.mtime) || 0,
|
|
7918
8720
|
},
|
|
7919
8721
|
}).catch((error) => {
|
|
7920
8722
|
console.warn('dsh-gallery: 同步「正在看的图」失败(不影响看图)', error)
|
|
@@ -8006,6 +8808,36 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8006
8808
|
}))
|
|
8007
8809
|
// 取值失败兜底到 image 那份(正常情况三种 kind 都建过桶,走不到这里)
|
|
8008
8810
|
const categoryFilter = categoryFilterMap[kind] ?? categoryFilterMap.image
|
|
8811
|
+
/**
|
|
8812
|
+
* 2026-11-16 第二档:把「面板此刻长什么样」同步给后台。
|
|
8813
|
+
* 人切视图、改分类开关、翻页时防抖上报,模型才知道您眼前筛掉了哪几类、
|
|
8814
|
+
* 一共多少张、分几个对话组 —— 否则它只能瞎猜「产出台里现在有什么」。
|
|
8815
|
+
* 纯状态同步:600ms 防抖,失败只记日志,绝不影响列表本身。
|
|
8816
|
+
*/
|
|
8817
|
+
React.useEffect(() => {
|
|
8818
|
+
if (view.status !== 'ready' || view.data === null) return
|
|
8819
|
+
const timer = setTimeout(() => {
|
|
8820
|
+
const data = view.data
|
|
8821
|
+
void callHost('setPanel', {
|
|
8822
|
+
panel: {
|
|
8823
|
+
scope,
|
|
8824
|
+
kind,
|
|
8825
|
+
page,
|
|
8826
|
+
total: Number(data.total) || 0,
|
|
8827
|
+
groupCount: Array.isArray(data.groups) ? data.groups.length : 0,
|
|
8828
|
+
categories: {
|
|
8829
|
+
final: categoryFilter.final !== false,
|
|
8830
|
+
input: categoryFilter.input !== false,
|
|
8831
|
+
intermediate: categoryFilter.intermediate !== false,
|
|
8832
|
+
unknown: categoryFilter.unknown !== false,
|
|
8833
|
+
},
|
|
8834
|
+
},
|
|
8835
|
+
}).catch((error) => {
|
|
8836
|
+
console.warn('dsh-gallery: 同步面板状态失败(不影响使用)', error)
|
|
8837
|
+
})
|
|
8838
|
+
}, 600)
|
|
8839
|
+
return () => clearTimeout(timer)
|
|
8840
|
+
}, [view, scope, kind, page, categoryFilter])
|
|
8009
8841
|
/** 批量选择(v0.13.7):选中的 relPath 集合。清空条件:切 kind / 切 scope / 刷新后失效项自动剔除。 */
|
|
8010
8842
|
const [selected, setSelected] = React.useState(new Set())
|
|
8011
8843
|
/** 批量模式:用户显式开启,或已有选中项时自动生效(避免勾了看不见批量条)。 */
|
|
@@ -8579,7 +9411,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8579
9411
|
* 分组视图下卡片来自 `data.groups[i].files`,与当前页的扁平 `items` 是两个不同的集合,
|
|
8580
9412
|
* 直接用全局 `items` 的索引会「点哪张都跳出同一张图」。
|
|
8581
9413
|
*/
|
|
8582
|
-
const openViewer = React.useCallback((index, anchorEl, list, asOriginal, origin) => {
|
|
9414
|
+
const openViewer = React.useCallback((index, anchorEl, list, asOriginal, origin, compareRel) => {
|
|
8583
9415
|
const scroller = bodyScrollRef.current
|
|
8584
9416
|
if (scroller !== null) {
|
|
8585
9417
|
savedScrollRef.current = {
|
|
@@ -8618,6 +9450,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8618
9450
|
const originSid = String(origin?.sessionId ?? '')
|
|
8619
9451
|
setViewer({
|
|
8620
9452
|
index, list: snapshot, asOriginal: asOriginal === true,
|
|
9453
|
+
// 2026-11-17:批量选两张时带进来,查看器一开就进对比,不用再点一次
|
|
9454
|
+
compareRel: String(compareRel ?? ''),
|
|
8621
9455
|
originSid: originSid === '__history__' ? '' : originSid,
|
|
8622
9456
|
originTitle: originSid === '__history__' ? '' : String(origin?.title ?? ''),
|
|
8623
9457
|
})
|
|
@@ -8699,6 +9533,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8699
9533
|
const payload = await callHost('delete', { path: target.item.relPath, confirm: true })
|
|
8700
9534
|
if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
|
|
8701
9535
|
setDeleteTarget(null)
|
|
9536
|
+
kickChanges()
|
|
8702
9537
|
await load(undefined, kind, scope, page).then((data) => setView({ status: 'ready', data })).catch(() => {})
|
|
8703
9538
|
} catch (error) {
|
|
8704
9539
|
console.error('dsh-gallery: 删除失败', error)
|
|
@@ -8804,6 +9639,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8804
9639
|
let okCount = 0
|
|
8805
9640
|
let lastErr = ''
|
|
8806
9641
|
let skipped = 0
|
|
9642
|
+
// 空壳位图(只有名字没内容)标记:交给系统剪贴板读真实文件路径兜底
|
|
9643
|
+
let needClipboardFallback = false
|
|
8807
9644
|
for (const file of images) {
|
|
8808
9645
|
// 没有磁盘路径、MIME 又不是图片的(如复制的 PDF/zip):读成 base64 也过不了
|
|
8809
9646
|
// PNG 校验,直接跳过并计数,最后给一条明确的「请拖入画廊」提示。
|
|
@@ -8813,7 +9650,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8813
9650
|
const dataUrl = await fileToDataUrl(file)
|
|
8814
9651
|
const comma = dataUrl.indexOf(',')
|
|
8815
9652
|
const base64 = comma >= 0 ? dataUrl.slice(comma + 1) : dataUrl
|
|
8816
|
-
|
|
9653
|
+
// 空壳(Electron 对某些来源只给文件名、不给内容):别硬发空 base64,
|
|
9654
|
+
// 改走系统剪贴板按真实路径复制,任何格式都能原样搬过去。
|
|
9655
|
+
if (base64 === '' || Number(file?.size ?? 0) === 0) { needClipboardFallback = true; continue }
|
|
9656
|
+
const payload = await callHost('pasteImage', { sessionId: pasteTargetSid(), data: base64, ext: imageExtOf(mime, dataUrl) })
|
|
8817
9657
|
if (payload?.ok === true) { okCount += 1; showPasteNotice('ok', format(t('pasteImageOk'), { name: payload.name ?? '', target: pasteTargetLabel() })) }
|
|
8818
9658
|
else lastErr = payload?.error?.message ?? 'pasteImage failed'
|
|
8819
9659
|
} catch (error) {
|
|
@@ -8830,16 +9670,24 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8830
9670
|
}
|
|
8831
9671
|
}
|
|
8832
9672
|
if (okCount > 0) {
|
|
9673
|
+
kickChanges()
|
|
8833
9674
|
void refresh()
|
|
8834
9675
|
if (lastErr !== '') console.warn('dsh-gallery: 部分粘贴失败', lastErr)
|
|
8835
|
-
|
|
9676
|
+
return
|
|
9677
|
+
}
|
|
9678
|
+
// 事件里是空壳:退回系统剪贴板,Host 用 PowerShell 读 CF_HDROP 拿真实路径
|
|
9679
|
+
if (needClipboardFallback) {
|
|
9680
|
+
const got = await pasteFromClipboard()
|
|
9681
|
+
if (got) return
|
|
9682
|
+
}
|
|
9683
|
+
if (lastErr !== '') {
|
|
8836
9684
|
showPasteNotice('fail', format(t('pasteFailed'), { message: lastErr }))
|
|
8837
9685
|
} else if (skipped > 0) {
|
|
8838
9686
|
showPasteNotice('fail', t('pasteUnsupported'))
|
|
8839
9687
|
} else {
|
|
8840
9688
|
showPasteNotice('fail', t('pasteEmpty'))
|
|
8841
9689
|
}
|
|
8842
|
-
}, [sessionId, refresh, t, showPasteNotice])
|
|
9690
|
+
}, [sessionId, refresh, t, showPasteNotice, pasteFromClipboard])
|
|
8843
9691
|
|
|
8844
9692
|
/** Ctrl+V:优先吃 paste 事件的图片/文件;事件没给文件信息时退到系统剪贴板。 */
|
|
8845
9693
|
const doPasteEvent = React.useCallback(async (clipboardData, event) => {
|
|
@@ -8989,7 +9837,110 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8989
9837
|
}
|
|
8990
9838
|
}, [load, kind, scope, page])
|
|
8991
9839
|
|
|
8992
|
-
//
|
|
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 漏报时)
|
|
8993
9944
|
React.useEffect(() => {
|
|
8994
9945
|
if (viewer !== null) return undefined
|
|
8995
9946
|
let alive = true
|
|
@@ -9290,6 +10241,36 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9290
10241
|
* 批量操作条(v0.13.7)—— 有选中项时出现。
|
|
9291
10242
|
* 三个动作:确认 / 取消确认 / 清除标记,**全部只改标记、不碰磁盘**。
|
|
9292
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
|
+
|
|
9293
10274
|
const selectedCount = selected.size
|
|
9294
10275
|
const batchBar = selectedCount > 0
|
|
9295
10276
|
? h('div', { className: 'dg-batchBar', key: 'batchBar', 'data-gallery-batch-bar': true }, [
|
|
@@ -9309,6 +10290,15 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9309
10290
|
title: t('batchCopyHint'),
|
|
9310
10291
|
onClick: () => { void doCopyAssets([...selected]) },
|
|
9311
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,
|
|
9312
10302
|
h('button', {
|
|
9313
10303
|
type: 'button', className: 'dg-btn dg-btnSmall', key: 'clearmark',
|
|
9314
10304
|
'data-gallery-batch-clear': true,
|
|
@@ -9477,8 +10467,26 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9477
10467
|
emptyText = t('emptySession')
|
|
9478
10468
|
}
|
|
9479
10469
|
}
|
|
9480
|
-
|
|
9481
|
-
|
|
10470
|
+
// 新对话空状态也要能粘贴:和「有图」分支一样接三样 ——
|
|
10471
|
+
// ① 外层 bodyWrap 的 hover 标记,否则 document 级 Ctrl+V 门控直接忽略;
|
|
10472
|
+
// ② onPaste / onContextMenu,右键菜单与 Ctrl+V 都走这里。
|
|
10473
|
+
// onBodyPaste / onBodyContextMenu / hoveringRef 都在本分支之前声明,无 TDZ。
|
|
10474
|
+
body = h('div', {
|
|
10475
|
+
className: 'dg-bodyWrap',
|
|
10476
|
+
key: 'bodyWrap',
|
|
10477
|
+
onMouseEnter: () => { hoveringRef.current = true },
|
|
10478
|
+
onMouseLeave: () => { hoveringRef.current = false; pasteTargetRef.current = null },
|
|
10479
|
+
}, [
|
|
10480
|
+
h('div', {
|
|
10481
|
+
className: `dg-body${kind === 'file' ? ' dg-fileBody' : ''}`,
|
|
10482
|
+
key: 'body',
|
|
10483
|
+
'data-gallery-body': true,
|
|
10484
|
+
onPaste: onBodyPaste,
|
|
10485
|
+
onContextMenu: onBodyContextMenu,
|
|
10486
|
+
}, [
|
|
10487
|
+
h('p', { className: 'dg-status' }, emptyText),
|
|
10488
|
+
]),
|
|
10489
|
+
])
|
|
9482
10490
|
} else {
|
|
9483
10491
|
// 全局模式 + 有分组数据 → 按对话分组渲染(可折叠)
|
|
9484
10492
|
const useGroups = scope === 'global' && Array.isArray(data.groups) && data.groups.length > 0
|
|
@@ -9980,6 +10988,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9980
10988
|
index: Math.min(viewer.index, viewer.list.length - 1),
|
|
9981
10989
|
t,
|
|
9982
10990
|
initialOriginal: viewer.asOriginal === true,
|
|
10991
|
+
initialCompare: String(viewer.compareRel ?? ''),
|
|
9983
10992
|
onClose: closeViewer,
|
|
9984
10993
|
onStep: step,
|
|
9985
10994
|
onCrop: doCrop,
|