dsh-gallery 1.0.0 → 1.1.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 +143 -1
- package/README.md +18 -12
- package/client.js +390 -89
- package/host/activity.js +208 -0
- package/host/context.js +157 -25
- package/host/derive.js +21 -0
- package/host/http.js +174 -26
- package/host/regions.js +572 -0
- package/host/scan.js +75 -26
- package/host/tools.js +498 -26
- package/package.json +6 -3
package/client.js
CHANGED
|
@@ -938,6 +938,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
938
938
|
cropSaved: '已裁剪:{name}(已加入「{target}」素材)',
|
|
939
939
|
cropFailed: '裁剪失败:{message}',
|
|
940
940
|
cropMinSize: '选区太小',
|
|
941
|
+
cropCoord: '坐标',
|
|
942
|
+
cropColor: '色值',
|
|
943
|
+
cropCopyColor: '按 Ctrl+C 复制色值',
|
|
944
|
+
cropCopied: '已复制 {hex}',
|
|
941
945
|
trimEnter: '裁剪片段',
|
|
942
946
|
trimExit: '退出裁剪',
|
|
943
947
|
trimPreview: '从入点播放',
|
|
@@ -1328,6 +1332,10 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
1328
1332
|
cropSaved: 'Cropped: {name} (added to "{target}" assets)',
|
|
1329
1333
|
cropFailed: 'Crop failed: {message}',
|
|
1330
1334
|
cropMinSize: 'Selection too small',
|
|
1335
|
+
cropCoord: 'Position',
|
|
1336
|
+
cropColor: 'Color',
|
|
1337
|
+
cropCopyColor: 'Press Ctrl+C to copy the color',
|
|
1338
|
+
cropCopied: 'Copied {hex}',
|
|
1331
1339
|
trimEnter: 'Trim clip',
|
|
1332
1340
|
trimExit: 'Exit trim',
|
|
1333
1341
|
trimPreview: 'Play from in',
|
|
@@ -3121,9 +3129,9 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3121
3129
|
.dg-annotSvg.dg-annotActive { background: rgba(74, 124, 255, 0.04); }
|
|
3122
3130
|
.dg-btnActive { background: #4a7cff !important; color: #fff !important; border-color: #4a7cff !important; }
|
|
3123
3131
|
|
|
3124
|
-
/*
|
|
3132
|
+
/* 批注列表。离边也统一 20px:原来 8px,跟右上提示条一高一低,看着歪。 */
|
|
3125
3133
|
.dg-annotList {
|
|
3126
|
-
position: absolute; left:
|
|
3134
|
+
position: absolute; left: 20px; top: 20px; z-index: 5;
|
|
3127
3135
|
max-width: 300px; max-height: 40%; overflow: auto;
|
|
3128
3136
|
background: rgba(27, 30, 36, 0.95); border: 1px solid rgba(255, 255, 255, 0.16);
|
|
3129
3137
|
border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 4px;
|
|
@@ -3133,23 +3141,28 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3133
3141
|
.dg-annotIndex { color: #8fb6ff; font-weight: 600; }
|
|
3134
3142
|
.dg-annotText { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3135
3143
|
.dg-annotItem .dg-btn { flex: 0 0 auto; }
|
|
3136
|
-
/*
|
|
3144
|
+
/* 遮罩导出结果提示:避开左上批注列表与右下角确认框,不受 svg 缩放平移影响。
|
|
3145
|
+
边距跟那三个确认框统一成 20px —— 整块界面只有一套网格。 */
|
|
3137
3146
|
.dg-maskNotice {
|
|
3138
|
-
position: absolute; right:
|
|
3147
|
+
position: absolute; right: 20px; top: 20px; z-index: 7;
|
|
3139
3148
|
max-width: min(360px, 70%); padding: 6px 10px; border-radius: 6px;
|
|
3140
3149
|
font-size: 11px; line-height: 1.5; color: #e8eaed;
|
|
3141
3150
|
background: rgba(27, 30, 36, 0.96); border: 1px solid rgba(255, 255, 255, 0.18);
|
|
3142
3151
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
|
|
3152
|
+
animation: dg-panelIn 0.14s ease-out;
|
|
3143
3153
|
}
|
|
3144
3154
|
.dg-maskNotice-ok { border-color: rgba(94, 214, 150, 0.65); }
|
|
3145
3155
|
.dg-maskNotice-failed { border-color: rgba(255, 107, 107, 0.85); color: #ffd7d7; }
|
|
3146
3156
|
|
|
3147
|
-
/*
|
|
3157
|
+
/* 批注输入框(左键拖框选完的状态确认框)。位置口径同裁剪/多边形:
|
|
3158
|
+
钉在右下角、离边 20px、宽 300、松手后淡入。
|
|
3159
|
+
原来贴底居中 —— 框要是圈在画面下半部,正好被它压住,等于边看边被挡。 */
|
|
3148
3160
|
.dg-annotEditor {
|
|
3149
|
-
position: absolute;
|
|
3150
|
-
width:
|
|
3161
|
+
position: absolute; right: 20px; bottom: 20px; left: auto; top: auto; transform: none; z-index: 6;
|
|
3162
|
+
width: 300px; max-width: calc(100% - 40px); background: #1b1e24; color: #e8eaed;
|
|
3151
3163
|
border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 8px; padding: 10px;
|
|
3152
3164
|
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
|
|
3165
|
+
animation: dg-panelIn 0.14s ease-out;
|
|
3153
3166
|
}
|
|
3154
3167
|
.dg-annotEditorHead { font-size: 12px; font-weight: 600; margin-bottom: 8px; }
|
|
3155
3168
|
.dg-annotInput {
|
|
@@ -3158,6 +3171,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3158
3171
|
font-size: 12px; font-family: inherit;
|
|
3159
3172
|
}
|
|
3160
3173
|
.dg-annotInput:focus { outline: 2px solid #4a7cff; outline-offset: -1px; }
|
|
3174
|
+
/* 深色底上浏览器默认的 placeholder 灰几乎看不见,跟 .dg-input 用同一个色 */
|
|
3175
|
+
.dg-annotInput::placeholder { color: #9aa8b8; opacity: 1; }
|
|
3161
3176
|
.dg-annotEditorOps { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
|
|
3162
3177
|
|
|
3163
3178
|
|
|
@@ -3180,13 +3195,24 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3180
3195
|
.dg-annotEditorOps .dg-annotSave:hover:not(:disabled) { background: #6a92ff !important; }
|
|
3181
3196
|
.dg-annotPendingHint { font-size: 11px; color: #ffd166; margin: -2px 0 8px; }
|
|
3182
3197
|
|
|
3183
|
-
/*
|
|
3198
|
+
/* 右下角确认框统一淡入:与裁剪面板那条同参(0.14s / 上移 6px),
|
|
3199
|
+
三个「选完才问你要不要确认」的框出现的手感必须一模一样。 */
|
|
3200
|
+
@keyframes dg-panelIn {
|
|
3201
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
3202
|
+
to { opacity: 1; transform: none; }
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
/* v0.14.6 多边形选区操作条(区域标记 / 填充遮罩共用)。
|
|
3206
|
+
位置口径 2026-11-16 统一:和裁剪确认面板一样钉在**窗口右下角**、
|
|
3207
|
+
离右边和下边各 20px、宽 300 —— 原来贴 8/14,跟另外两个框错位,眼睛要重新找。
|
|
3208
|
+
拖动顶点时整块让开(组件里按 polyDrag 门控),松手再淡入。 */
|
|
3184
3209
|
.dg-polyPanel {
|
|
3185
|
-
position: absolute; right:
|
|
3186
|
-
width:
|
|
3210
|
+
position: absolute; right: 20px; bottom: 20px; z-index: 6;
|
|
3211
|
+
width: 300px; max-width: calc(100% - 40px); box-sizing: border-box;
|
|
3187
3212
|
background: #1b1e24; color: #e8eaed;
|
|
3188
3213
|
border: 1px solid rgba(94, 214, 150, 0.55); border-radius: 8px; padding: 10px;
|
|
3189
3214
|
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
|
|
3215
|
+
animation: dg-panelIn 0.14s ease-out;
|
|
3190
3216
|
}
|
|
3191
3217
|
.dg-polyPanelHead { font-size: 12px; font-weight: 600; color: #9fe1cb; margin-bottom: 6px; }
|
|
3192
3218
|
.dg-polyPanelInfo { font-size: 11px; line-height: 1.5; word-break: break-all; }
|
|
@@ -3210,6 +3236,7 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3210
3236
|
padding: 5px 7px; font-size: 11px; outline: none;
|
|
3211
3237
|
}
|
|
3212
3238
|
.dg-polyNoteInput:focus { border-color: #5ed696; }
|
|
3239
|
+
.dg-polyNoteInput::placeholder { color: #9aa8b8; opacity: 1; }
|
|
3213
3240
|
|
|
3214
3241
|
/* v0.16.0 粘贴结果提示 */
|
|
3215
3242
|
.dg-pasteNotice {
|
|
@@ -3222,38 +3249,72 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3222
3249
|
.dg-pasteOk { border-color: rgba(94,214,150,0.6); }
|
|
3223
3250
|
.dg-pasteFail { border-color: rgba(255,107,107,0.6); color: #ffd2d2; }
|
|
3224
3251
|
|
|
3225
|
-
/*
|
|
3252
|
+
/* v1.0.2 图片裁剪层:绿框 + 八向手柄 + 像素级取色放大镜(照老板给的参考图对齐)
|
|
3226
3253
|
坐标系说明:裁剪框/放大镜都用 getBoundingClientRect 的**视口坐标**定位,
|
|
3227
3254
|
所以这一层必须 fixed 铺满视口,absolute 会相对 stage 偏移导致框错位。 */
|
|
3228
3255
|
.dg-cropLayer { position: fixed; inset: 0; z-index: 60; cursor: crosshair; }
|
|
3256
|
+
/* 框外不再压暗:参考图里整张图亮度不变,靠绿线与手柄识别边界 */
|
|
3229
3257
|
.dg-cropRect {
|
|
3230
|
-
position: absolute; border: 1px solid #
|
|
3231
|
-
box-
|
|
3232
|
-
cursor: move; background: rgba(106,146,255,0.06);
|
|
3258
|
+
position: absolute; border: 1px solid #00e676;
|
|
3259
|
+
box-sizing: border-box; cursor: move; background: transparent;
|
|
3233
3260
|
}
|
|
3234
3261
|
.dg-cropHandle {
|
|
3235
|
-
position: absolute; width:
|
|
3236
|
-
border:
|
|
3262
|
+
position: absolute; width: 9px; height: 9px; background: #00e676;
|
|
3263
|
+
border: 1px solid rgba(0,0,0,0.65); border-radius: 1px; box-sizing: border-box;
|
|
3264
|
+
z-index: 2;
|
|
3237
3265
|
}
|
|
3238
|
-
.dg-cropHandleNW { left: -
|
|
3239
|
-
.dg-cropHandleNE { right: -
|
|
3240
|
-
.dg-cropHandleSW { left: -
|
|
3241
|
-
.dg-cropHandleSE { right: -
|
|
3266
|
+
.dg-cropHandleNW { left: -5px; top: -5px; cursor: nwse-resize; }
|
|
3267
|
+
.dg-cropHandleNE { right: -5px; top: -5px; cursor: nesw-resize; }
|
|
3268
|
+
.dg-cropHandleSW { left: -5px; bottom: -5px; cursor: nesw-resize; }
|
|
3269
|
+
.dg-cropHandleSE { right: -5px; bottom: -5px; cursor: nwse-resize; }
|
|
3270
|
+
/* 四边中点:只沿一个轴拖,免得「只想收一下高度」却把宽度也带歪 */
|
|
3271
|
+
.dg-cropHandleN { left: 50%; top: -5px; margin-left: -5px; cursor: ns-resize; }
|
|
3272
|
+
.dg-cropHandleS { left: 50%; bottom: -5px; margin-left: -5px; cursor: ns-resize; }
|
|
3273
|
+
.dg-cropHandleW { left: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
|
|
3274
|
+
.dg-cropHandleE { right: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
|
|
3275
|
+
/* 尺寸标签:贴在框左上角外侧,白字带阴影,深底浅底都看得清 */
|
|
3276
|
+
.dg-cropSize {
|
|
3277
|
+
position: absolute; padding: 1px 4px; border-radius: 3px;
|
|
3278
|
+
font-size: 11px; line-height: 1.4; font-variant-numeric: tabular-nums;
|
|
3279
|
+
color: #fff; background: rgba(0,0,0,0.42); text-shadow: 0 1px 2px rgba(0,0,0,0.9);
|
|
3280
|
+
pointer-events: none; white-space: nowrap;
|
|
3281
|
+
}
|
|
3282
|
+
/* 像素放大镜(方形)+ 坐标色值卡:参考图里两者是一体的,所以外层包一个定位容器 */
|
|
3283
|
+
.dg-cropMagWrap { position: absolute; width: 148px; pointer-events: none; }
|
|
3242
3284
|
.dg-cropMagnifier {
|
|
3243
|
-
|
|
3244
|
-
border:
|
|
3245
|
-
|
|
3246
|
-
}
|
|
3247
|
-
.dg-cropMagnifier canvas {
|
|
3285
|
+
width: 148px; height: 148px; border-radius: 3px;
|
|
3286
|
+
border: 1px solid rgba(255,255,255,0.5); box-shadow: 0 4px 16px rgba(0,0,0,0.55);
|
|
3287
|
+
overflow: hidden; background: #000;
|
|
3288
|
+
}
|
|
3289
|
+
.dg-cropMagnifier canvas {
|
|
3290
|
+
display: block; width: 100%; height: 100%;
|
|
3291
|
+
image-rendering: pixelated; /* 不做硬边就成了糊图,取色就不准了 */
|
|
3292
|
+
}
|
|
3293
|
+
.dg-cropMagInfo {
|
|
3294
|
+
margin-top: 3px; box-sizing: border-box; width: 148px;
|
|
3295
|
+
background: rgba(255,255,255,0.94); color: #1a1c20;
|
|
3296
|
+
border-radius: 3px; padding: 4px 6px; font-size: 11px; line-height: 1.5;
|
|
3297
|
+
display: grid; grid-template-columns: auto 1fr; column-gap: 10px;
|
|
3298
|
+
font-variant-numeric: tabular-nums; box-shadow: 0 2px 10px rgba(0,0,0,0.4);
|
|
3299
|
+
}
|
|
3300
|
+
.dg-cropMagInfoKey { color: #6b7280; }
|
|
3301
|
+
.dg-cropMagInfoVal { color: #111318; font-weight: 600; text-align: right; }
|
|
3302
|
+
.dg-cropMagHint { grid-column: 1 / -1; color: #6b7280; margin-top: 2px; font-size: 10px; }
|
|
3303
|
+
.dg-cropMagHintOk { color: #0a7d52; font-weight: 600; }
|
|
3248
3304
|
.dg-cropPanel {
|
|
3249
|
-
/*
|
|
3250
|
-
|
|
3251
|
-
cropLayer 是 fixed inset:0
|
|
3305
|
+
/* 位置由组件以内联 right/bottom 注入:**固定在窗口右下角**(老板 2026-11-16
|
|
3306
|
+
要求「靠边固定,跟随鼠标会挡住预览」)。这里千万别再写死 left/bottom 数值 ——
|
|
3307
|
+
cropLayer 是 fixed inset:0,CSS 里的值会和内联的叠在一起把面板顶跑位。 */
|
|
3252
3308
|
position: absolute; z-index: 6; width: 300px;
|
|
3309
|
+
animation: dg-cropPanelIn 0.14s ease-out; /* 松手后才挂载,正好有「弹出来」的手感 */
|
|
3253
3310
|
box-sizing: border-box; background: #1b1e24; color: #e8eaed;
|
|
3254
3311
|
border: 1px solid rgba(106,146,255,0.55); border-radius: 8px; padding: 10px;
|
|
3255
3312
|
box-shadow: 0 8px 28px rgba(0,0,0,0.6);
|
|
3256
3313
|
}
|
|
3314
|
+
@keyframes dg-cropPanelIn {
|
|
3315
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
3316
|
+
to { opacity: 1; transform: none; }
|
|
3317
|
+
}
|
|
3257
3318
|
.dg-cropPanelHead { font-size: 12px; font-weight: 600; color: #a9c4ff; margin-bottom: 6px; }
|
|
3258
3319
|
.dg-cropPanelHint { font-size: 11px; color: #b9c2cf; line-height: 1.5; margin-top: 6px; }
|
|
3259
3320
|
.dg-cropPanelOps { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
|
|
@@ -3431,6 +3492,22 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3431
3492
|
return text !== ''
|
|
3432
3493
|
}
|
|
3433
3494
|
|
|
3495
|
+
/**
|
|
3496
|
+
* 从 MIME / dataURL 推真实扩展名(2026-11-15)。
|
|
3497
|
+
*
|
|
3498
|
+
* 以前统一写死 ext:'png',遇到 JPEG 位图会被 Host 的 PNG 校验拒掉。
|
|
3499
|
+
* 这里只做「上报」,Host 仍按真实魔数复核,写错也不会产生坏文件。
|
|
3500
|
+
*/
|
|
3501
|
+
function imageExtOf(mime, dataUrl) {
|
|
3502
|
+
const fromUrl = /^data:([^;,]+)/i.exec(String(dataUrl ?? ''))
|
|
3503
|
+
const m = String(mime ?? '').toLowerCase() || (fromUrl === null ? '' : fromUrl[1].toLowerCase())
|
|
3504
|
+
if (m === 'image/jpeg' || m === 'image/jpg' || m === 'image/pjpeg') return 'jpg'
|
|
3505
|
+
if (m === 'image/webp') return 'webp'
|
|
3506
|
+
if (m === 'image/gif') return 'gif'
|
|
3507
|
+
if (m === 'image/bmp' || m === 'image/x-ms-bmp') return 'bmp'
|
|
3508
|
+
return 'png'
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3434
3511
|
/** 把 File/Blob 读成 dataURL(含 `data:…;base64,` 前缀)。 */
|
|
3435
3512
|
function fileToDataUrl(file) {
|
|
3436
3513
|
return new Promise((resolve, reject) => {
|
|
@@ -5754,13 +5831,28 @@ ${absPath}
|
|
|
5754
5831
|
* · 裁剪结果(归一化矩形)交给上层 callHost('cropImage'),落盘到源图同目录并标素材。
|
|
5755
5832
|
* · 零自动发送红线不变:本组件只产出 PNG,落盘与登记由 Host 完成。
|
|
5756
5833
|
*/
|
|
5834
|
+
/** 裁剪放大镜:148px 见方、每格 4px,因此覆盖原图 37×37 像素。
|
|
5835
|
+
* 为什么是这几个数(老板 11-16:10 倍太夸张、像素块太粗不好用,改回 4 倍):
|
|
5836
|
+
* ① 格宽 4px 既能看出「一格 = 一个像素」,又不至于几格就占满一片;
|
|
5837
|
+
* ② 4 倍下要看 37 格才填满,37 是奇数 → 光标那格正好落在正中,绿十字压得准;
|
|
5838
|
+
* ③ 37 × 4 = 148,size 必须是 factor 的整数倍,否则光标格会偏半格、十字压到缝上。
|
|
5839
|
+
* 三个数互相咬死:改倍率就得同时重算 size(tests/crop-frame-ui.test.mjs 有断言钉住)。 */
|
|
5840
|
+
const CROP_MAG_SIZE = 148
|
|
5841
|
+
const CROP_MAG_FACTOR = 4
|
|
5842
|
+
|
|
5757
5843
|
function ImageCropper({ t, item, imgRef, onCrop, onCancel }) {
|
|
5758
5844
|
const [rect, setRect] = React.useState(null) // {x,y,w,h} 归一化 0–1(相对图片宽高)
|
|
5759
|
-
|
|
5845
|
+
// mode:new 新建 / move 整体挪 / 四角 nw ne sw se / 四边 n s w e(只动单侧)
|
|
5846
|
+
const [drag, setDrag] = React.useState(null) // { mode, sx, sy, startRect }
|
|
5760
5847
|
const [mag, setMag] = React.useState(null) // { cx, cy(视口), nx, ny(归一化) }
|
|
5761
5848
|
const [full, setFull] = React.useState(null) // 全分辨率 HTMLImageElement
|
|
5762
5849
|
const [busy, setBusy] = React.useState(false)
|
|
5850
|
+
const [copied, setCopied] = React.useState('') // 复制回执,1.4 秒后自动消失
|
|
5763
5851
|
const magCanvasRef = React.useRef(null)
|
|
5852
|
+
// 取色用的 1×1 离屏画布:只读一个像素,比重建整块画布便宜得多
|
|
5853
|
+
const probeCanvasRef = React.useRef(null)
|
|
5854
|
+
// 光标处色值放 ref:快捷键 effect 不必因颜色变化反复重挂
|
|
5855
|
+
const colorRef = React.useRef('')
|
|
5764
5856
|
|
|
5765
5857
|
// 载入全分辨率源图(放大镜取真实像素 + 最终裁图)
|
|
5766
5858
|
React.useEffect(() => {
|
|
@@ -5820,6 +5912,11 @@ ${absPath}
|
|
|
5820
5912
|
else if (d.mode === 'ne') { y = n.y; w = n.x - s.x; h = (s.y + s.h) - n.y }
|
|
5821
5913
|
else if (d.mode === 'sw') { x = n.x; w = (s.x + s.w) - n.x; h = n.y - s.y }
|
|
5822
5914
|
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 }
|
|
5915
|
+
// 四边中点:另一个轴原样不动,这才能「只收高度、不把宽度带歪」
|
|
5916
|
+
else if (d.mode === 'n') { y = n.y; h = (s.y + s.h) - n.y }
|
|
5917
|
+
else if (d.mode === 's') { h = n.y - s.y }
|
|
5918
|
+
else if (d.mode === 'w') { x = n.x; w = (s.x + s.w) - n.x }
|
|
5919
|
+
else if (d.mode === 'e') { w = n.x - s.x }
|
|
5823
5920
|
if (w < 0) { x += w; w = -w }
|
|
5824
5921
|
if (h < 0) { y += h; h = -h }
|
|
5825
5922
|
x = clamp01(x); y = clamp01(y); w = clamp01(w); h = clamp01(h)
|
|
@@ -5851,30 +5948,75 @@ ${absPath}
|
|
|
5851
5948
|
}
|
|
5852
5949
|
const onLayerUp = () => setDrag(null)
|
|
5853
5950
|
|
|
5854
|
-
|
|
5951
|
+
/**
|
|
5952
|
+
* 放大镜绘制:按整数像素格放大(4×),并关掉插值。
|
|
5953
|
+
* 不关插值就成了糊图、取色看着「不准」;4 倍下每格 4px,看得出格子又不像 10 倍那么粗。
|
|
5954
|
+
* 十字线用绿色高亮(白的在浅色招牌上根本看不见)。
|
|
5955
|
+
*/
|
|
5855
5956
|
React.useEffect(() => {
|
|
5856
5957
|
const canvas = magCanvasRef.current
|
|
5857
5958
|
if (canvas === null || full === null || mag === null) return
|
|
5858
5959
|
const ctx = canvas.getContext('2d')
|
|
5859
5960
|
if (ctx === null) return
|
|
5860
5961
|
const SIZE = canvas.width
|
|
5861
|
-
const FACTOR =
|
|
5962
|
+
const FACTOR = CROP_MAG_FACTOR
|
|
5963
|
+
const SPAN = SIZE / FACTOR // 源图取样边长(像素)
|
|
5862
5964
|
const FW = full.naturalWidth
|
|
5863
5965
|
const FH = full.naturalHeight
|
|
5864
|
-
|
|
5865
|
-
const
|
|
5866
|
-
const
|
|
5966
|
+
// 让光标所在像素成为正中间那格:左右各取 floor(SPAN/2) 格
|
|
5967
|
+
const half = Math.floor(SPAN / 2)
|
|
5968
|
+
const px = clampNum(Math.round(mag.nx * FW), 0, Math.max(0, FW - 1))
|
|
5969
|
+
const py = clampNum(Math.round(mag.ny * FH), 0, Math.max(0, FH - 1))
|
|
5970
|
+
const sx = clampNum(px - half, 0, Math.max(0, FW - SPAN))
|
|
5971
|
+
const sy = clampNum(py - half, 0, Math.max(0, FH - SPAN))
|
|
5972
|
+
ctx.imageSmoothingEnabled = false
|
|
5867
5973
|
ctx.fillStyle = '#000'
|
|
5868
5974
|
ctx.fillRect(0, 0, SIZE, SIZE)
|
|
5869
|
-
ctx.drawImage(full, sx, sy,
|
|
5870
|
-
|
|
5871
|
-
|
|
5975
|
+
ctx.drawImage(full, sx, sy, SPAN, SPAN, 0, 0, SIZE, SIZE)
|
|
5976
|
+
// 绿十字:压在正中那一格的中线上,线宽 2 才够醒目
|
|
5977
|
+
const mid = SIZE / 2
|
|
5978
|
+
ctx.strokeStyle = 'rgba(0,230,118,0.95)'
|
|
5979
|
+
ctx.lineWidth = 2
|
|
5872
5980
|
ctx.beginPath()
|
|
5873
|
-
ctx.moveTo(
|
|
5874
|
-
ctx.moveTo(0,
|
|
5981
|
+
ctx.moveTo(mid, 0); ctx.lineTo(mid, SIZE)
|
|
5982
|
+
ctx.moveTo(0, mid); ctx.lineTo(SIZE, mid)
|
|
5875
5983
|
ctx.stroke()
|
|
5876
5984
|
}, [mag, full])
|
|
5877
5985
|
|
|
5986
|
+
/**
|
|
5987
|
+
* 裁剪态按键:Ctrl+C 复制光标处色值;左右键不翻页。
|
|
5988
|
+
* 翻页会把框套到另一张图上(框还在、图换了),所以必须拦住。
|
|
5989
|
+
* 走捕获阶段 + stopImmediatePropagation:查看器自己的 Ctrl+C 是「复制文件」,
|
|
5990
|
+
* 不先截住就会把文件写进剪贴板,而不是色值。
|
|
5991
|
+
*/
|
|
5992
|
+
React.useEffect(() => {
|
|
5993
|
+
const onKey = (event) => {
|
|
5994
|
+
if (isTypingTarget(event.target)) return
|
|
5995
|
+
const key = String(event.key ?? '')
|
|
5996
|
+
if ((event.ctrlKey || event.metaKey) && (key === 'c' || key === 'C')) {
|
|
5997
|
+
const hex = colorRef.current
|
|
5998
|
+
if (hex === '') return
|
|
5999
|
+
event.preventDefault()
|
|
6000
|
+
event.stopImmediatePropagation()
|
|
6001
|
+
copyText(hex)
|
|
6002
|
+
setCopied(hex)
|
|
6003
|
+
return
|
|
6004
|
+
}
|
|
6005
|
+
if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
|
6006
|
+
event.stopImmediatePropagation()
|
|
6007
|
+
}
|
|
6008
|
+
}
|
|
6009
|
+
window.addEventListener('keydown', onKey, true)
|
|
6010
|
+
return () => window.removeEventListener('keydown', onKey, true)
|
|
6011
|
+
}, [])
|
|
6012
|
+
|
|
6013
|
+
// 复制回执:1.4 秒后自动收起,避免一直挂在那里
|
|
6014
|
+
React.useEffect(() => {
|
|
6015
|
+
if (copied === '') return undefined
|
|
6016
|
+
const timer = setTimeout(() => setCopied(''), 1400)
|
|
6017
|
+
return () => clearTimeout(timer)
|
|
6018
|
+
}, [copied])
|
|
6019
|
+
|
|
5878
6020
|
const confirmCrop = () => {
|
|
5879
6021
|
if (full === null || rect === null || rect.w < 0.02 || rect.h < 0.02) return
|
|
5880
6022
|
setBusy(true)
|
|
@@ -5919,44 +6061,108 @@ ${absPath}
|
|
|
5919
6061
|
height: `${rect.h * r.height}px`,
|
|
5920
6062
|
}
|
|
5921
6063
|
: {}
|
|
5922
|
-
const
|
|
5923
|
-
const
|
|
6064
|
+
const vw = Number(typeof window !== 'undefined' ? window.innerWidth : 0) || 1280
|
|
6065
|
+
const vh = Number(typeof window !== 'undefined' ? window.innerHeight : 0) || 800
|
|
6066
|
+
|
|
6067
|
+
// 尺寸标签写的是「裁下来多少像素」,所以按原图自然尺寸 × 归一化比例算,不是屏幕像素
|
|
6068
|
+
const cropSize = (rect !== null && full !== null)
|
|
6069
|
+
? {
|
|
6070
|
+
w: Math.max(1, Math.round(rect.w * full.naturalWidth)),
|
|
6071
|
+
h: Math.max(1, Math.round(rect.h * full.naturalHeight)),
|
|
6072
|
+
}
|
|
6073
|
+
: null
|
|
6074
|
+
|
|
6075
|
+
/** 光标处的原图像素坐标 + 色值。1×1 离屏画布取一个像素;
|
|
6076
|
+
* 图是 blob: 同源地址,不会污染画布,getImageData 可读。 */
|
|
6077
|
+
const probe = React.useMemo(() => {
|
|
6078
|
+
if (full === null || mag === null) return null
|
|
6079
|
+
const FW = full.naturalWidth
|
|
6080
|
+
const FH = full.naturalHeight
|
|
6081
|
+
if (FW <= 0 || FH <= 0) return null
|
|
6082
|
+
const px = clampNum(Math.round(mag.nx * FW), 0, FW - 1)
|
|
6083
|
+
const py = clampNum(Math.round(mag.ny * FH), 0, FH - 1)
|
|
6084
|
+
let hex = ''
|
|
6085
|
+
try {
|
|
6086
|
+
let canvas = probeCanvasRef.current
|
|
6087
|
+
if (canvas === null) {
|
|
6088
|
+
canvas = document.createElement('canvas')
|
|
6089
|
+
canvas.width = 1
|
|
6090
|
+
canvas.height = 1
|
|
6091
|
+
probeCanvasRef.current = canvas
|
|
6092
|
+
}
|
|
6093
|
+
const c2d = canvas.getContext('2d')
|
|
6094
|
+
if (c2d !== null) {
|
|
6095
|
+
c2d.clearRect(0, 0, 1, 1)
|
|
6096
|
+
c2d.drawImage(full, px, py, 1, 1, 0, 0, 1, 1)
|
|
6097
|
+
const d = c2d.getImageData(0, 0, 1, 1).data
|
|
6098
|
+
hex = '#' + [d[0], d[1], d[2]].map((v) => v.toString(16).padStart(2, '0')).join('').toUpperCase()
|
|
6099
|
+
}
|
|
6100
|
+
} catch { hex = '' }
|
|
6101
|
+
return { px, py, hex }
|
|
6102
|
+
}, [mag, full])
|
|
6103
|
+
colorRef.current = probe !== null ? probe.hex : ''
|
|
6104
|
+
|
|
6105
|
+
// 尺寸标签贴框左上角外侧;顶上没空间就挪进框内,别让它被视口裁掉
|
|
6106
|
+
const sizeStyle = (() => {
|
|
6107
|
+
if (rect === null || r === null) return {}
|
|
6108
|
+
const boxLeft = r.left + rect.x * r.width
|
|
6109
|
+
const boxTop = r.top + rect.y * r.height
|
|
6110
|
+
const above = boxTop - 20
|
|
6111
|
+
return {
|
|
6112
|
+
left: `${clampNum(boxLeft, 4, Math.max(4, vw - 96))}px`,
|
|
6113
|
+
top: `${above >= 4 ? above : boxTop + 3}px`,
|
|
6114
|
+
}
|
|
6115
|
+
})()
|
|
5924
6116
|
|
|
5925
6117
|
/**
|
|
5926
|
-
*
|
|
5927
|
-
*
|
|
5928
|
-
*
|
|
6118
|
+
* 操作面板**固定在窗口右下角**,不再跟着选区跑(老板 2026-11-16:
|
|
6119
|
+
* 「裁剪的这个状态确认框让靠边固定吧,跟随鼠标会挡住预览」)。
|
|
6120
|
+
* 原来按选区水平居中、贴框下方(微信截图式),实测选区在中间或偏下时
|
|
6121
|
+
* 正好压住要靠细节的那块,拖框时它还跟着晃、眼睛要一直追。
|
|
6122
|
+
* 现在钉在角落:位置可预期、永远不挡正在调的那块。
|
|
6123
|
+
* 用 right/bottom 而不是算好的 left/top —— 面板高度随提示文字换行变化,
|
|
6124
|
+
* 写死 top 一旦文字变长就会顶出窗口下沿。cropLayer 是 fixed inset:0,
|
|
6125
|
+
* absolute 子元素自然相对视口。
|
|
5929
6126
|
*/
|
|
5930
6127
|
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
|
-
|
|
6128
|
+
const PANEL_H = 118 // 估算值,只用于「别让放大镜压上去」
|
|
6129
|
+
const PANEL_MARGIN = 20
|
|
6130
|
+
const panelStyle = { right: `${PANEL_MARGIN}px`, bottom: `${PANEL_MARGIN}px` }
|
|
6131
|
+
// 拖动过程中先不显示面板(老板 2026-11-16:「或者选完后在弹出状态确认」)。
|
|
6132
|
+
// 拖的时候画面完全干净;松手才出现,位置永远在右下角,不跟鼠标跑。
|
|
6133
|
+
const showPanel = drag === null
|
|
6134
|
+
const canConfirm = rect !== null && rect.w >= 0.02 && rect.h >= 0.02
|
|
6135
|
+
// 面板实际矩形(估算,够判断重叠):右下角、宽 300、高约 118
|
|
6136
|
+
const panelLeft = Math.max(8, vw - PANEL_W - PANEL_MARGIN)
|
|
6137
|
+
const panelTop = Math.max(8, vh - PANEL_H - PANEL_MARGIN)
|
|
6138
|
+
|
|
6139
|
+
// 放大镜默认贴光标右下方(参考图即如此);放不下、或会压住面板,就换另一侧
|
|
6140
|
+
const MAG_W = CROP_MAG_SIZE
|
|
6141
|
+
const MAG_H = CROP_MAG_SIZE + 76 // 放大镜 + 间距 + 坐标色值卡
|
|
6142
|
+
const hitsPanel = (left, top) => left < panelLeft + PANEL_W && left + MAG_W > panelLeft
|
|
6143
|
+
&& top < panelTop + PANEL_H && top + MAG_H > panelTop
|
|
6144
|
+
const magPos = (() => {
|
|
6145
|
+
if (mag === null) return { left: 0, top: 0 }
|
|
6146
|
+
const gap = 18
|
|
6147
|
+
// 四个候选按「右下 → 左下 → 右上 → 左上」的偏好序试,跟人眼找位置的顺序一致
|
|
6148
|
+
const spots = [
|
|
6149
|
+
{ left: mag.cx + gap, top: mag.cy + gap },
|
|
6150
|
+
{ left: mag.cx - gap - MAG_W, top: mag.cy + gap },
|
|
6151
|
+
{ left: mag.cx + gap, top: mag.cy - gap - MAG_H },
|
|
6152
|
+
{ left: mag.cx - gap - MAG_W, top: mag.cy - gap - MAG_H },
|
|
6153
|
+
]
|
|
6154
|
+
const inView = (s) => s.left >= 8 && s.left + MAG_W <= vw - 8
|
|
6155
|
+
&& s.top >= 8 && s.top + MAG_H <= vh - 8
|
|
6156
|
+
const picked = spots.find((s) => inView(s) && !hitsPanel(s.left, s.top))
|
|
6157
|
+
?? spots.find((s) => !hitsPanel(s.left, s.top))
|
|
6158
|
+
?? spots[0]
|
|
6159
|
+
return {
|
|
6160
|
+
left: clampNum(picked.left, 8, Math.max(8, vw - MAG_W - 8)),
|
|
6161
|
+
top: clampNum(picked.top, 8, Math.max(8, vh - MAG_H - 8)),
|
|
6162
|
+
}
|
|
5959
6163
|
})()
|
|
6164
|
+
const magLeft = magPos.left
|
|
6165
|
+
const magTop = magPos.top
|
|
5960
6166
|
|
|
5961
6167
|
return h('div', {
|
|
5962
6168
|
className: 'dg-cropLayer',
|
|
@@ -5976,20 +6182,50 @@ ${absPath}
|
|
|
5976
6182
|
style: rectStyle,
|
|
5977
6183
|
onPointerDown: (e) => startDrag(e, 'move'),
|
|
5978
6184
|
}, [
|
|
5979
|
-
|
|
5980
|
-
h('div', { className: 'dg-cropHandle dg-
|
|
5981
|
-
h('div', { className: 'dg-cropHandle dg-
|
|
5982
|
-
h('div', { className: 'dg-cropHandle dg-
|
|
6185
|
+
// 四角:斜着调
|
|
6186
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleNW', key: 'nw', 'data-gallery-crop-handle': 'nw', onPointerDown: (e) => startDrag(e, 'nw') }),
|
|
6187
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleNE', key: 'ne', 'data-gallery-crop-handle': 'ne', onPointerDown: (e) => startDrag(e, 'ne') }),
|
|
6188
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleSW', key: 'sw', 'data-gallery-crop-handle': 'sw', onPointerDown: (e) => startDrag(e, 'sw') }),
|
|
6189
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleSE', key: 'se', 'data-gallery-crop-handle': 'se', onPointerDown: (e) => startDrag(e, 'se') }),
|
|
6190
|
+
// 四边中点:单边调(参考图上共八个手柄)
|
|
6191
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleN', key: 'n', 'data-gallery-crop-handle': 'n', onPointerDown: (e) => startDrag(e, 'n') }),
|
|
6192
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleS', key: 's', 'data-gallery-crop-handle': 's', onPointerDown: (e) => startDrag(e, 's') }),
|
|
6193
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleW', key: 'w', 'data-gallery-crop-handle': 'w', onPointerDown: (e) => startDrag(e, 'w') }),
|
|
6194
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleE', key: 'e', 'data-gallery-crop-handle': 'e', onPointerDown: (e) => startDrag(e, 'e') }),
|
|
5983
6195
|
])
|
|
5984
6196
|
: null,
|
|
5985
|
-
|
|
6197
|
+
// 左上角尺寸标签:显示裁下来是多少像素
|
|
6198
|
+
rect !== null && cropSize !== null
|
|
5986
6199
|
? h('div', {
|
|
5987
|
-
className: 'dg-
|
|
6200
|
+
className: 'dg-cropSize',
|
|
6201
|
+
key: 'size',
|
|
6202
|
+
'data-gallery-crop-size': true,
|
|
6203
|
+
style: sizeStyle,
|
|
6204
|
+
}, `${cropSize.w} × ${cropSize.h}`)
|
|
6205
|
+
: null,
|
|
6206
|
+
mag !== null && full !== null && probe !== null
|
|
6207
|
+
? h('div', {
|
|
6208
|
+
className: 'dg-cropMagWrap',
|
|
5988
6209
|
key: 'mag',
|
|
5989
|
-
|
|
5990
|
-
|
|
6210
|
+
'data-gallery-crop-mag': true,
|
|
6211
|
+
style: { left: `${magLeft}px`, top: `${magTop}px` },
|
|
6212
|
+
}, [
|
|
6213
|
+
h('div', { className: 'dg-cropMagnifier', key: 'canvas' },
|
|
6214
|
+
h('canvas', { ref: magCanvasRef, width: CROP_MAG_SIZE, height: CROP_MAG_SIZE, key: 'magCanvas' })),
|
|
6215
|
+
h('div', { className: 'dg-cropMagInfo', key: 'info' }, [
|
|
6216
|
+
h('span', { className: 'dg-cropMagInfoKey', key: 'kx' }, t('cropCoord')),
|
|
6217
|
+
h('span', { className: 'dg-cropMagInfoVal', key: 'vx', 'data-gallery-crop-coord': true }, `${probe.px}, ${probe.py}`),
|
|
6218
|
+
h('span', { className: 'dg-cropMagInfoKey', key: 'kc' }, t('cropColor')),
|
|
6219
|
+
h('span', { className: 'dg-cropMagInfoVal', key: 'vc', 'data-gallery-crop-color': true }, probe.hex === '' ? '—' : probe.hex),
|
|
6220
|
+
h('span', {
|
|
6221
|
+
className: copied === '' ? 'dg-cropMagHint' : 'dg-cropMagHint dg-cropMagHintOk',
|
|
6222
|
+
key: 'hint',
|
|
6223
|
+
'data-gallery-crop-copyhint': true,
|
|
6224
|
+
}, copied === '' ? t('cropCopyColor') : format(t('cropCopied'), { hex: copied })),
|
|
6225
|
+
]),
|
|
6226
|
+
])
|
|
5991
6227
|
: null,
|
|
5992
|
-
h('div', {
|
|
6228
|
+
showPanel ? h('div', {
|
|
5993
6229
|
className: 'dg-cropPanel',
|
|
5994
6230
|
key: 'panel',
|
|
5995
6231
|
'data-gallery-crop-panel': true,
|
|
@@ -6006,12 +6242,13 @@ ${absPath}
|
|
|
6006
6242
|
onClick: (e) => { e.stopPropagation(); onCancel() },
|
|
6007
6243
|
}, t('cropCancel')),
|
|
6008
6244
|
h('button', {
|
|
6009
|
-
type: 'button', className: 'dg-btn dg-btnPrimary', key: 'ok',
|
|
6245
|
+
type: 'button', className: 'dg-btn dg-btnPrimary', key: 'ok',
|
|
6246
|
+
disabled: busy || !canConfirm, // 还没拖出框就点不动,避免点了没反应像坏了
|
|
6010
6247
|
'data-gallery-crop-confirm': true,
|
|
6011
6248
|
onClick: (e) => { e.stopPropagation(); confirmCrop() },
|
|
6012
6249
|
}, busy ? t('cropSaving') : t('cropConfirm')),
|
|
6013
6250
|
]),
|
|
6014
|
-
]),
|
|
6251
|
+
]) : null,
|
|
6015
6252
|
])
|
|
6016
6253
|
}
|
|
6017
6254
|
|
|
@@ -7192,7 +7429,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7192
7429
|
/** 多边形选区操作条:点数 / 外接框 / 面积实时可见,闭合前可撤销、可清空。 */
|
|
7193
7430
|
const polyBox = poly.length > 0 ? polygonBBox(poly) : null
|
|
7194
7431
|
const isNoteMode = polyMode === 'note'
|
|
7195
|
-
|
|
7432
|
+
// 拖顶点时先把面板藏起来(老板 2026-11-16:确认框别挡正在看的那块),
|
|
7433
|
+
// 松手立刻回来、带淡入;位置本来就钉在右下角,只在拖动这一瞬让开。
|
|
7434
|
+
const polyPanel = (poly.length === 0 || polyDrag !== null) ? null : h('div', {
|
|
7196
7435
|
className: 'dg-polyPanel', key: 'polyPanel',
|
|
7197
7436
|
'data-gallery-poly-panel': true,
|
|
7198
7437
|
'data-gallery-poly-mode': polyMode,
|
|
@@ -7915,6 +8154,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7915
8154
|
? { relPath: String(linkedMask.relPath ?? '') } : null),
|
|
7916
8155
|
sessionId: String(current.sessionId ?? viewer.originSid ?? ''),
|
|
7917
8156
|
sessionTitle: String(current.sessionTitle ?? viewer.originTitle ?? ''),
|
|
8157
|
+
// 第二档:文件自身改动时间(后台按活跃度排「最近看过的图」时要用)
|
|
8158
|
+
mtime: Number(current.mtime) || 0,
|
|
7918
8159
|
},
|
|
7919
8160
|
}).catch((error) => {
|
|
7920
8161
|
console.warn('dsh-gallery: 同步「正在看的图」失败(不影响看图)', error)
|
|
@@ -8006,6 +8247,36 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8006
8247
|
}))
|
|
8007
8248
|
// 取值失败兜底到 image 那份(正常情况三种 kind 都建过桶,走不到这里)
|
|
8008
8249
|
const categoryFilter = categoryFilterMap[kind] ?? categoryFilterMap.image
|
|
8250
|
+
/**
|
|
8251
|
+
* 2026-11-16 第二档:把「面板此刻长什么样」同步给后台。
|
|
8252
|
+
* 人切视图、改分类开关、翻页时防抖上报,模型才知道您眼前筛掉了哪几类、
|
|
8253
|
+
* 一共多少张、分几个对话组 —— 否则它只能瞎猜「产出台里现在有什么」。
|
|
8254
|
+
* 纯状态同步:600ms 防抖,失败只记日志,绝不影响列表本身。
|
|
8255
|
+
*/
|
|
8256
|
+
React.useEffect(() => {
|
|
8257
|
+
if (view.status !== 'ready' || view.data === null) return
|
|
8258
|
+
const timer = setTimeout(() => {
|
|
8259
|
+
const data = view.data
|
|
8260
|
+
void callHost('setPanel', {
|
|
8261
|
+
panel: {
|
|
8262
|
+
scope,
|
|
8263
|
+
kind,
|
|
8264
|
+
page,
|
|
8265
|
+
total: Number(data.total) || 0,
|
|
8266
|
+
groupCount: Array.isArray(data.groups) ? data.groups.length : 0,
|
|
8267
|
+
categories: {
|
|
8268
|
+
final: categoryFilter.final !== false,
|
|
8269
|
+
input: categoryFilter.input !== false,
|
|
8270
|
+
intermediate: categoryFilter.intermediate !== false,
|
|
8271
|
+
unknown: categoryFilter.unknown !== false,
|
|
8272
|
+
},
|
|
8273
|
+
},
|
|
8274
|
+
}).catch((error) => {
|
|
8275
|
+
console.warn('dsh-gallery: 同步面板状态失败(不影响使用)', error)
|
|
8276
|
+
})
|
|
8277
|
+
}, 600)
|
|
8278
|
+
return () => clearTimeout(timer)
|
|
8279
|
+
}, [view, scope, kind, page, categoryFilter])
|
|
8009
8280
|
/** 批量选择(v0.13.7):选中的 relPath 集合。清空条件:切 kind / 切 scope / 刷新后失效项自动剔除。 */
|
|
8010
8281
|
const [selected, setSelected] = React.useState(new Set())
|
|
8011
8282
|
/** 批量模式:用户显式开启,或已有选中项时自动生效(避免勾了看不见批量条)。 */
|
|
@@ -8804,6 +9075,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8804
9075
|
let okCount = 0
|
|
8805
9076
|
let lastErr = ''
|
|
8806
9077
|
let skipped = 0
|
|
9078
|
+
// 空壳位图(只有名字没内容)标记:交给系统剪贴板读真实文件路径兜底
|
|
9079
|
+
let needClipboardFallback = false
|
|
8807
9080
|
for (const file of images) {
|
|
8808
9081
|
// 没有磁盘路径、MIME 又不是图片的(如复制的 PDF/zip):读成 base64 也过不了
|
|
8809
9082
|
// PNG 校验,直接跳过并计数,最后给一条明确的「请拖入画廊」提示。
|
|
@@ -8813,7 +9086,10 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8813
9086
|
const dataUrl = await fileToDataUrl(file)
|
|
8814
9087
|
const comma = dataUrl.indexOf(',')
|
|
8815
9088
|
const base64 = comma >= 0 ? dataUrl.slice(comma + 1) : dataUrl
|
|
8816
|
-
|
|
9089
|
+
// 空壳(Electron 对某些来源只给文件名、不给内容):别硬发空 base64,
|
|
9090
|
+
// 改走系统剪贴板按真实路径复制,任何格式都能原样搬过去。
|
|
9091
|
+
if (base64 === '' || Number(file?.size ?? 0) === 0) { needClipboardFallback = true; continue }
|
|
9092
|
+
const payload = await callHost('pasteImage', { sessionId: pasteTargetSid(), data: base64, ext: imageExtOf(mime, dataUrl) })
|
|
8817
9093
|
if (payload?.ok === true) { okCount += 1; showPasteNotice('ok', format(t('pasteImageOk'), { name: payload.name ?? '', target: pasteTargetLabel() })) }
|
|
8818
9094
|
else lastErr = payload?.error?.message ?? 'pasteImage failed'
|
|
8819
9095
|
} catch (error) {
|
|
@@ -8832,14 +9108,21 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8832
9108
|
if (okCount > 0) {
|
|
8833
9109
|
void refresh()
|
|
8834
9110
|
if (lastErr !== '') console.warn('dsh-gallery: 部分粘贴失败', lastErr)
|
|
8835
|
-
|
|
9111
|
+
return
|
|
9112
|
+
}
|
|
9113
|
+
// 事件里是空壳:退回系统剪贴板,Host 用 PowerShell 读 CF_HDROP 拿真实路径
|
|
9114
|
+
if (needClipboardFallback) {
|
|
9115
|
+
const got = await pasteFromClipboard()
|
|
9116
|
+
if (got) return
|
|
9117
|
+
}
|
|
9118
|
+
if (lastErr !== '') {
|
|
8836
9119
|
showPasteNotice('fail', format(t('pasteFailed'), { message: lastErr }))
|
|
8837
9120
|
} else if (skipped > 0) {
|
|
8838
9121
|
showPasteNotice('fail', t('pasteUnsupported'))
|
|
8839
9122
|
} else {
|
|
8840
9123
|
showPasteNotice('fail', t('pasteEmpty'))
|
|
8841
9124
|
}
|
|
8842
|
-
}, [sessionId, refresh, t, showPasteNotice])
|
|
9125
|
+
}, [sessionId, refresh, t, showPasteNotice, pasteFromClipboard])
|
|
8843
9126
|
|
|
8844
9127
|
/** Ctrl+V:优先吃 paste 事件的图片/文件;事件没给文件信息时退到系统剪贴板。 */
|
|
8845
9128
|
const doPasteEvent = React.useCallback(async (clipboardData, event) => {
|
|
@@ -9477,8 +9760,26 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
9477
9760
|
emptyText = t('emptySession')
|
|
9478
9761
|
}
|
|
9479
9762
|
}
|
|
9480
|
-
|
|
9481
|
-
|
|
9763
|
+
// 新对话空状态也要能粘贴:和「有图」分支一样接三样 ——
|
|
9764
|
+
// ① 外层 bodyWrap 的 hover 标记,否则 document 级 Ctrl+V 门控直接忽略;
|
|
9765
|
+
// ② onPaste / onContextMenu,右键菜单与 Ctrl+V 都走这里。
|
|
9766
|
+
// onBodyPaste / onBodyContextMenu / hoveringRef 都在本分支之前声明,无 TDZ。
|
|
9767
|
+
body = h('div', {
|
|
9768
|
+
className: 'dg-bodyWrap',
|
|
9769
|
+
key: 'bodyWrap',
|
|
9770
|
+
onMouseEnter: () => { hoveringRef.current = true },
|
|
9771
|
+
onMouseLeave: () => { hoveringRef.current = false; pasteTargetRef.current = null },
|
|
9772
|
+
}, [
|
|
9773
|
+
h('div', {
|
|
9774
|
+
className: `dg-body${kind === 'file' ? ' dg-fileBody' : ''}`,
|
|
9775
|
+
key: 'body',
|
|
9776
|
+
'data-gallery-body': true,
|
|
9777
|
+
onPaste: onBodyPaste,
|
|
9778
|
+
onContextMenu: onBodyContextMenu,
|
|
9779
|
+
}, [
|
|
9780
|
+
h('p', { className: 'dg-status' }, emptyText),
|
|
9781
|
+
]),
|
|
9782
|
+
])
|
|
9482
9783
|
} else {
|
|
9483
9784
|
// 全局模式 + 有分组数据 → 按对话分组渲染(可折叠)
|
|
9484
9785
|
const useGroups = scope === 'global' && Array.isArray(data.groups) && data.groups.length > 0
|