dsh-gallery 0.13.7 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +381 -15
- package/host/protocol.js +57 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -30,6 +30,63 @@ const VIDEO_EXTS = ['.mp4', '.webm', '.mov', '.m4v', '.mkv', '.avi', '.ogv']
|
|
|
30
30
|
/** 音频扩展名。 */
|
|
31
31
|
const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.opus', '.wma']
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* 框选批注的坐标契约(v0.14.0)—— Host 与 Client 的唯一真源。
|
|
35
|
+
*
|
|
36
|
+
* 为什么用归一化坐标:批注要落在「图片的某个位置」上,而不是「屏幕上某个像素」。
|
|
37
|
+
* 写像素值的话,换个窗口尺寸 / 换个缩放比例就全错了。
|
|
38
|
+
* 用相对宽高的 0–1 比例,无论怎么缩放都能还原到同一块区域。
|
|
39
|
+
*
|
|
40
|
+
* 形状类型:
|
|
41
|
+
* rect —— 矩形框(最主要,圈出「这块不对」)
|
|
42
|
+
* arrow —— 箭头(指向具体某点)
|
|
43
|
+
* text —— 纯文字标注(钉在某位置,不带框)
|
|
44
|
+
*/
|
|
45
|
+
const ANNOTATION_SHAPES = ["rect", "arrow", "text"]
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 一条批注的数据形态:
|
|
49
|
+
* {
|
|
50
|
+
* id: string, // 稳定 id(同一次会话内唯一)
|
|
51
|
+
* shape: "rect|arrow|text",
|
|
52
|
+
* x: number, y: number, // 起点,归一化 0–1
|
|
53
|
+
* w: number, h: number, // 宽高,归一化 0–1(text/arrow 可只用 x,y)
|
|
54
|
+
* note: string, // 人写的说明(可为空)
|
|
55
|
+
* frameMs: number|null, // 视频帧时间(图片为 null)
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* 约束:x/y/w/h 必须落在 [0,1];越界由写入端 clamp。
|
|
59
|
+
*/
|
|
60
|
+
const ANNOTATION_LIMITS = { min: 0, max: 1, maxNoteLength: 500, maxPerAsset: 50 }
|
|
61
|
+
|
|
62
|
+
/** 把任意数值 clamp 到 [0,1](批注坐标写入前必须过一遍)。 */
|
|
63
|
+
function clamp01(v) {
|
|
64
|
+
const n = Number(v)
|
|
65
|
+
if (!Number.isFinite(n)) return 0
|
|
66
|
+
if (n < 0) return 0
|
|
67
|
+
if (n > 1) return 1
|
|
68
|
+
return n
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 校验并规整一条批注;不合法返回 null。 */
|
|
72
|
+
function normalizeAnnotation(a) {
|
|
73
|
+
if (a === null || typeof a !== "object") return null
|
|
74
|
+
const shape = ANNOTATION_SHAPES.includes(a.shape) ? a.shape : "rect"
|
|
75
|
+
const note = typeof a.note === "string" ? a.note.slice(0, ANNOTATION_LIMITS.maxNoteLength) : ""
|
|
76
|
+
const x = clamp01(a.x)
|
|
77
|
+
const y = clamp01(a.y)
|
|
78
|
+
let w = clamp01(a.w)
|
|
79
|
+
let h = clamp01(a.h)
|
|
80
|
+
// 宽高至少留一点,且不越过右/下边界
|
|
81
|
+
if (w > 0 && x + w > 1) w = 1 - x
|
|
82
|
+
if (h > 0 && y + h > 1) h = 1 - y
|
|
83
|
+
const frameMs = Number.isFinite(a.frameMs) ? Math.max(0, Math.floor(a.frameMs)) : null
|
|
84
|
+
return {
|
|
85
|
+
id: typeof a.id === "string" && a.id !== "" ? a.id : ("a" + Math.random().toString(36).slice(2, 10)),
|
|
86
|
+
shape, x, y, w, h, note, frameMs,
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
33
90
|
|
|
34
91
|
/** tab 类型的身份;也是正文与标题在 keyed slot 里的 key。 */
|
|
35
92
|
const KIND = 'gallery'
|
|
@@ -109,6 +166,13 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
109
166
|
catLegendInput: '输入素材',
|
|
110
167
|
catLegendIntermediate: '中间产物',
|
|
111
168
|
catLegendUnknown: '未归类',
|
|
169
|
+
annotEnter: '标注',
|
|
170
|
+
annotExit: '退出标注',
|
|
171
|
+
annotNotePrompt: '这块要改什么?(可留空)',
|
|
172
|
+
annotNotePlaceholder: '例如:沙发位置偏了 / 色调太暖',
|
|
173
|
+
annotNoNote: '(无说明)',
|
|
174
|
+
annotHint: '拖拽画框标出要改的位置,说明会写进决策草稿',
|
|
175
|
+
annotCount: '批注 {n} 处',
|
|
112
176
|
catFilterFinalConfirmed: '最终交付·已确认',
|
|
113
177
|
catFilterFinalPending: '最终交付·待确认',
|
|
114
178
|
filterShowHint: '点击显示「{label}」',
|
|
@@ -344,6 +408,13 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
344
408
|
catLegendInput: 'Input material',
|
|
345
409
|
catLegendIntermediate: 'Interim product',
|
|
346
410
|
catLegendUnknown: 'Unclassified',
|
|
411
|
+
annotEnter: 'Annotate',
|
|
412
|
+
annotExit: 'Exit annotate',
|
|
413
|
+
annotNotePrompt: 'What should change here? (optional)',
|
|
414
|
+
annotNotePlaceholder: 'e.g. sofa position is off / color is too warm',
|
|
415
|
+
annotNoNote: '(no note)',
|
|
416
|
+
annotHint: 'Drag to box the area that needs changes; notes go into the decision draft',
|
|
417
|
+
annotCount: '{n} annotation(s)',
|
|
347
418
|
catFilterFinalConfirmed: 'Final · confirmed',
|
|
348
419
|
catFilterFinalPending: 'Final · pending',
|
|
349
420
|
filterShowHint: 'Click to show "{label}"',
|
|
@@ -1903,6 +1974,41 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
1903
1974
|
.dg-discardList li:last-child { border-bottom: none; }
|
|
1904
1975
|
.dg-discardPath { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
|
|
1905
1976
|
.dg-discardSize { color: #a9b1bd; white-space: nowrap; }
|
|
1977
|
+
|
|
1978
|
+
/* ---------- v0.14.0:框选批注层 ---------- */
|
|
1979
|
+
|
|
1980
|
+
.dg-annotWrap { position: absolute; inset: 0; }
|
|
1981
|
+
.dg-annotSvg { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
1982
|
+
.dg-annotSvg.dg-annotActive { background: rgba(74, 124, 255, 0.04); }
|
|
1983
|
+
.dg-btnActive { background: #4a7cff !important; color: #fff !important; border-color: #4a7cff !important; }
|
|
1984
|
+
|
|
1985
|
+
/* 批注列表 */
|
|
1986
|
+
.dg-annotList {
|
|
1987
|
+
position: absolute; left: 8px; bottom: 8px; z-index: 5;
|
|
1988
|
+
max-width: 300px; max-height: 40%; overflow: auto;
|
|
1989
|
+
background: rgba(27, 30, 36, 0.95); border: 1px solid rgba(255, 255, 255, 0.16);
|
|
1990
|
+
border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 4px;
|
|
1991
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
|
|
1992
|
+
}
|
|
1993
|
+
.dg-annotItem { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #e8eaed; }
|
|
1994
|
+
.dg-annotIndex { color: #8fb6ff; font-weight: 600; }
|
|
1995
|
+
.dg-annotText { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1996
|
+
|
|
1997
|
+
/* 批注输入框 */
|
|
1998
|
+
.dg-annotEditor {
|
|
1999
|
+
position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 6;
|
|
2000
|
+
width: min(340px, 80%); background: #1b1e24; color: #e8eaed;
|
|
2001
|
+
border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 8px; padding: 10px;
|
|
2002
|
+
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
|
|
2003
|
+
}
|
|
2004
|
+
.dg-annotEditorHead { font-size: 12px; font-weight: 600; margin-bottom: 8px; }
|
|
2005
|
+
.dg-annotInput {
|
|
2006
|
+
width: 100%; box-sizing: border-box; padding: 6px 8px; border-radius: 5px;
|
|
2007
|
+
border: 1px solid rgba(255, 255, 255, 0.22); background: #2a2f38; color: #e8eaed;
|
|
2008
|
+
font-size: 12px; font-family: inherit;
|
|
2009
|
+
}
|
|
2010
|
+
.dg-annotInput:focus { outline: 2px solid #4a7cff; outline-offset: -1px; }
|
|
2011
|
+
.dg-annotEditorOps { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
|
|
1906
2012
|
`
|
|
1907
2013
|
|
|
1908
2014
|
|
|
@@ -3502,7 +3608,7 @@ ${absPath}
|
|
|
3502
3608
|
* - 右键预览区、按 O、点底部按钮 三种方式切换
|
|
3503
3609
|
* - 切换时**保留当前缩放与位置**,否则切过去跳回 1x 就没法对比
|
|
3504
3610
|
*/
|
|
3505
|
-
function Viewer({ items, index, onClose, onStep, t, initialOriginal }) {
|
|
3611
|
+
function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation }) {
|
|
3506
3612
|
const item = items[index]
|
|
3507
3613
|
// 文件预览已改走 DSH 原生侧栏(session 地址);此处 Viewer 仅处理图片,isText 恒 false,
|
|
3508
3614
|
// 下面的文本分支保留为死代码,供 v0.2 若需插件内预览时复用
|
|
@@ -3729,6 +3835,13 @@ ${absPath}
|
|
|
3729
3835
|
}
|
|
3730
3836
|
}
|
|
3731
3837
|
// 中键按下时阻止浏览器默认的自动滚动
|
|
3838
|
+
/** 批注模式(v0.14.0):开启后指针交给 SVG 标注层,查看器的缩放/拖拽暂停。 */
|
|
3839
|
+
const [annotActive, setAnnotActive] = React.useState(false)
|
|
3840
|
+
const annotsOfCurrent = React.useMemo(
|
|
3841
|
+
() => (typeof annotations === 'function' ? annotations(item) : []),
|
|
3842
|
+
[annotations, item],
|
|
3843
|
+
)
|
|
3844
|
+
|
|
3732
3845
|
const onMouseDown = (event) => {
|
|
3733
3846
|
if (event.button === 1) event.preventDefault()
|
|
3734
3847
|
}
|
|
@@ -3992,6 +4105,19 @@ ${absPath}
|
|
|
3992
4105
|
? format(t('viewerOriginalLoading'), { pct: original.pct })
|
|
3993
4106
|
: t('viewerOriginalLoadingIndeterminate'))
|
|
3994
4107
|
: (originalMode ? `◉ ${t('viewerToPreview')}` : `◎ ${t('viewerToOriginal')}`)),
|
|
4108
|
+
// v0.14.0:批注模式开关
|
|
4109
|
+
h('button', {
|
|
4110
|
+
type: 'button',
|
|
4111
|
+
className: `dg-btn${annotActive ? ' dg-btnActive' : ''}`,
|
|
4112
|
+
key: 'annot',
|
|
4113
|
+
'data-gallery-annot-toggle': true,
|
|
4114
|
+
'aria-pressed': annotActive,
|
|
4115
|
+
title: annotActive ? t('annotExit') : t('annotEnter'),
|
|
4116
|
+
onClick: (event) => {
|
|
4117
|
+
event.stopPropagation()
|
|
4118
|
+
setAnnotActive((v) => !v)
|
|
4119
|
+
},
|
|
4120
|
+
}, annotActive ? `✎ ${t('annotExit')}` : `✎ ${t('annotEnter')}`),
|
|
3995
4121
|
h('button', { type: 'button', className: 'dg-btn', key: 'prev', onClick: () => onStep(-1), 'aria-label': t('prev') }, '‹'),
|
|
3996
4122
|
h('button', { type: 'button', className: 'dg-btn', key: 'next', onClick: () => onStep(1), 'aria-label': t('next') }, '›'),
|
|
3997
4123
|
h('button', { type: 'button', className: 'dg-btn', key: 'close', onClick: onClose, 'aria-label': t('close') }, '✕'),
|
|
@@ -4027,20 +4153,35 @@ ${absPath}
|
|
|
4027
4153
|
state.status === 'ready'
|
|
4028
4154
|
? (isText
|
|
4029
4155
|
? h('pre', { className: 'dg-textPre', key: 'text' }, state.text)
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4156
|
+
// v0.14.0:图片 + 框选批注层(Fragment 包住,批注层覆盖在图上)
|
|
4157
|
+
: h(React.Fragment, { key: 'imgfrag' }, [
|
|
4158
|
+
h('img', {
|
|
4159
|
+
key: 'img',
|
|
4160
|
+
// 原图模式下显示原图 URL(按需加载好后才有);
|
|
4161
|
+
// 未就绪时继续显示预览图,避免黑屏跳变
|
|
4162
|
+
src: originalMode && original.status === 'ready' ? original.url : state.url,
|
|
4163
|
+
alt: item.name,
|
|
4164
|
+
decoding: 'async',
|
|
4165
|
+
draggable: false,
|
|
4166
|
+
style: {
|
|
4167
|
+
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
|
|
4168
|
+
transition: dragRef.current === null ? 'transform 120ms ease-out' : 'none',
|
|
4169
|
+
userSelect: 'none',
|
|
4170
|
+
pointerEvents: 'none',
|
|
4171
|
+
},
|
|
4172
|
+
}),
|
|
4173
|
+
// 批注层:只在图片(非文本)时出现,且随 zoom 一起变换
|
|
4174
|
+
h(AnnotationLayer, {
|
|
4175
|
+
key: 'annot',
|
|
4176
|
+
t,
|
|
4177
|
+
annotations: annotsOfCurrent,
|
|
4178
|
+
active: annotActive,
|
|
4179
|
+
frameMs: null,
|
|
4180
|
+
stageRef: bodyRef,
|
|
4181
|
+
onAdd: (a) => { onAddAnnotation?.(item, a) },
|
|
4182
|
+
onRemove: (id) => { onRemoveAnnotation?.(item, id) },
|
|
4183
|
+
}),
|
|
4184
|
+
]))
|
|
4044
4185
|
: state.status === 'binary'
|
|
4045
4186
|
? h('div', { className: 'dg-placeholder', key: 'bin' }, t('binaryHint'))
|
|
4046
4187
|
: h('div', { className: state.status === 'failed' ? 'dg-placeholder dg-error' : 'dg-placeholder' },
|
|
@@ -4072,6 +4213,193 @@ ${absPath}
|
|
|
4072
4213
|
* 也可以点「恢复默认」,回到自动探测的结果。
|
|
4073
4214
|
*/
|
|
4074
4215
|
|
|
4216
|
+
/**
|
|
4217
|
+
* 框选批注层(v0.14.0)—— 在查看器图片上圈出「哪儿不对」。
|
|
4218
|
+
*
|
|
4219
|
+
* 设计要点:
|
|
4220
|
+
* · 坐标全部归一化(0–1,相对图片宽高),见 shared/protocol.js 的 ANNOTATION_* 契约
|
|
4221
|
+
* · SVG 覆盖在图片之上;不干扰查看器原有的缩放/平移(只有「批注模式」下才接管指针)
|
|
4222
|
+
* · 拖拽画矩形 → 立刻弹出输入框写说明 → 存进批注列表
|
|
4223
|
+
* · 已存在的批注按归一化坐标还原绘制,缩放/换屏都不失真
|
|
4224
|
+
* · 批注不发送任何东西;出口是与决策草稿同一通道(见 05-feedback.js)
|
|
4225
|
+
*/
|
|
4226
|
+
|
|
4227
|
+
function AnnotationLayer({ t, annotations, onAdd, onRemove, active, frameMs, stageRef }) {
|
|
4228
|
+
const [draft, setDraft] = React.useState(null)
|
|
4229
|
+
const [editing, setEditing] = React.useState(null)
|
|
4230
|
+
const svgRef = React.useRef(null)
|
|
4231
|
+
|
|
4232
|
+
/** 客户坐标 → 归一化(相对 SVG 的实际渲染盒) */
|
|
4233
|
+
const toNorm = (event) => {
|
|
4234
|
+
const el = svgRef.current
|
|
4235
|
+
if (el === null) return null
|
|
4236
|
+
const rect = el.getBoundingClientRect()
|
|
4237
|
+
if (rect.width === 0 || rect.height === 0) return null
|
|
4238
|
+
return {
|
|
4239
|
+
x: clamp01((event.clientX - rect.left) / rect.width),
|
|
4240
|
+
y: clamp01((event.clientY - rect.top) / rect.height),
|
|
4241
|
+
}
|
|
4242
|
+
}
|
|
4243
|
+
|
|
4244
|
+
const onPointerDown = (event) => {
|
|
4245
|
+
if (!active) return
|
|
4246
|
+
// 只响应主键;左键拖拽画框
|
|
4247
|
+
if (event.button !== 0) return
|
|
4248
|
+
const p = toNorm(event)
|
|
4249
|
+
if (p === null) return
|
|
4250
|
+
event.preventDefault()
|
|
4251
|
+
event.stopPropagation()
|
|
4252
|
+
try { event.currentTarget.setPointerCapture(event.pointerId) } catch { /* 忽略 */ }
|
|
4253
|
+
setDraft({ x0: p.x, y0: p.y, x1: p.x, y1: p.y })
|
|
4254
|
+
}
|
|
4255
|
+
|
|
4256
|
+
const onPointerMove = (event) => {
|
|
4257
|
+
if (draft === null) return
|
|
4258
|
+
const p = toNorm(event)
|
|
4259
|
+
if (p === null) return
|
|
4260
|
+
event.preventDefault()
|
|
4261
|
+
event.stopPropagation()
|
|
4262
|
+
setDraft((d) => (d === null ? null : { ...d, x1: p.x, y1: p.y }))
|
|
4263
|
+
}
|
|
4264
|
+
|
|
4265
|
+
const finishDraft = (event) => {
|
|
4266
|
+
if (draft === null) return
|
|
4267
|
+
event.preventDefault()
|
|
4268
|
+
event.stopPropagation()
|
|
4269
|
+
const x = Math.min(draft.x0, draft.x1)
|
|
4270
|
+
const y = Math.min(draft.y0, draft.y1)
|
|
4271
|
+
const w = Math.abs(draft.x1 - draft.x0)
|
|
4272
|
+
const h = Math.abs(draft.y1 - draft.y0)
|
|
4273
|
+
setDraft(null)
|
|
4274
|
+
// 太小当成误点,不产生批注(避免满屏碎框)
|
|
4275
|
+
if (w < 0.01 || h < 0.01) return
|
|
4276
|
+
setEditing({ shape: 'rect', x, y, w, h, note: '', frameMs: frameMs ?? null })
|
|
4277
|
+
}
|
|
4278
|
+
|
|
4279
|
+
const saveEditing = () => {
|
|
4280
|
+
if (editing === null) return
|
|
4281
|
+
const normalized = normalizeAnnotation(editing)
|
|
4282
|
+
if (normalized !== null) onAdd(normalized)
|
|
4283
|
+
setEditing(null)
|
|
4284
|
+
}
|
|
4285
|
+
|
|
4286
|
+
// ---- 绘制已有批注 ----
|
|
4287
|
+
const shapes = (annotations ?? []).map((a) => {
|
|
4288
|
+
if (a.shape === 'text') {
|
|
4289
|
+
return h('g', { key: a.id }, [
|
|
4290
|
+
h('circle', {
|
|
4291
|
+
key: 'dot', cx: (a.x * 100) + '%', cy: (a.y * 100) + '%', r: 4,
|
|
4292
|
+
fill: '#ffd166', stroke: '#000', strokeWidth: 1,
|
|
4293
|
+
}),
|
|
4294
|
+
h('text', {
|
|
4295
|
+
key: 'txt', x: (a.x * 100) + '%', y: (a.y * 100) + '%',
|
|
4296
|
+
dx: 8, dy: 4, fill: '#fff', fontSize: 12, stroke: '#000', strokeWidth: 0.6,
|
|
4297
|
+
style: { paintOrder: 'stroke' },
|
|
4298
|
+
}, a.note || ''),
|
|
4299
|
+
])
|
|
4300
|
+
}
|
|
4301
|
+
// rect / arrow 都先按矩形画(arrow 后续可细化),带说明文字
|
|
4302
|
+
return h('g', { key: a.id }, [
|
|
4303
|
+
h('rect', {
|
|
4304
|
+
key: 'r',
|
|
4305
|
+
x: (a.x * 100) + '%', y: (a.y * 100) + '%',
|
|
4306
|
+
width: (a.w * 100) + '%', height: (a.h * 100) + '%',
|
|
4307
|
+
fill: 'rgba(74, 124, 255, 0.14)', stroke: '#4a7cff', strokeWidth: 2,
|
|
4308
|
+
rx: 3,
|
|
4309
|
+
}),
|
|
4310
|
+
a.note !== ''
|
|
4311
|
+
? h('text', {
|
|
4312
|
+
key: 'n',
|
|
4313
|
+
x: (a.x * 100) + '%', y: (a.y * 100) + '%',
|
|
4314
|
+
dx: 4, dy: -6, fill: '#fff', fontSize: 12, stroke: '#000', strokeWidth: 0.6,
|
|
4315
|
+
style: { paintOrder: 'stroke' },
|
|
4316
|
+
}, a.note)
|
|
4317
|
+
: null,
|
|
4318
|
+
])
|
|
4319
|
+
})
|
|
4320
|
+
|
|
4321
|
+
// ---- 正在画的框 ----
|
|
4322
|
+
const draftShape = draft === null ? null : (() => {
|
|
4323
|
+
const x = Math.min(draft.x0, draft.x1)
|
|
4324
|
+
const y = Math.min(draft.y0, draft.y1)
|
|
4325
|
+
const w = Math.abs(draft.x1 - draft.x0)
|
|
4326
|
+
const h = Math.abs(draft.y1 - draft.y0)
|
|
4327
|
+
return h('rect', {
|
|
4328
|
+
key: 'draft',
|
|
4329
|
+
x: (x * 100) + '%', y: (y * 100) + '%',
|
|
4330
|
+
width: (w * 100) + '%', height: (h * 100) + '%',
|
|
4331
|
+
fill: 'rgba(74, 124, 255, 0.22)', stroke: '#4a7cff', strokeWidth: 2, strokeDasharray: '5 3',
|
|
4332
|
+
})
|
|
4333
|
+
})()
|
|
4334
|
+
|
|
4335
|
+
const editor = editing === null ? null : h('div', {
|
|
4336
|
+
className: 'dg-annotEditor',
|
|
4337
|
+
key: 'editor',
|
|
4338
|
+
'data-gallery-annot-editor': true,
|
|
4339
|
+
}, [
|
|
4340
|
+
h('div', { className: 'dg-annotEditorHead', key: 'h' }, t('annotNotePrompt')),
|
|
4341
|
+
h('input', {
|
|
4342
|
+
type: 'text',
|
|
4343
|
+
key: 'inp',
|
|
4344
|
+
className: 'dg-annotInput',
|
|
4345
|
+
'data-gallery-annot-input': true,
|
|
4346
|
+
autoFocus: true,
|
|
4347
|
+
placeholder: t('annotNotePlaceholder'),
|
|
4348
|
+
value: editing.note,
|
|
4349
|
+
maxLength: 500,
|
|
4350
|
+
onChange: (e) => setEditing((cur) => (cur === null ? null : { ...cur, note: e.target.value })),
|
|
4351
|
+
onKeyDown: (e) => {
|
|
4352
|
+
if (e.key === 'Enter') { e.preventDefault(); saveEditing() }
|
|
4353
|
+
if (e.key === 'Escape') { e.preventDefault(); setEditing(null) }
|
|
4354
|
+
},
|
|
4355
|
+
}),
|
|
4356
|
+
h('div', { className: 'dg-annotEditorOps', key: 'o' }, [
|
|
4357
|
+
h('button', { type: 'button', className: 'dg-btn dg-btnSmall', key: 'c', onClick: () => setEditing(null) }, t('cancel')),
|
|
4358
|
+
h('button', {
|
|
4359
|
+
type: 'button', className: 'dg-btn dg-btnSmall dg-primaryBtn', key: 's',
|
|
4360
|
+
'data-gallery-annot-save': true, onClick: saveEditing,
|
|
4361
|
+
}, t('save')),
|
|
4362
|
+
]),
|
|
4363
|
+
])
|
|
4364
|
+
|
|
4365
|
+
const list = (annotations ?? []).length === 0 ? null : h('div', {
|
|
4366
|
+
className: 'dg-annotList', key: 'list', 'data-gallery-annot-list': true,
|
|
4367
|
+
}, (annotations ?? []).map((a) => h('div', {
|
|
4368
|
+
className: 'dg-annotItem', key: a.id, 'data-gallery-annot-id': a.id,
|
|
4369
|
+
}, [
|
|
4370
|
+
h('span', { className: 'dg-annotIndex', key: 'i' }, '#'),
|
|
4371
|
+
h('span', { className: 'dg-annotText', key: 't' }, a.note || t('annotNoNote')),
|
|
4372
|
+
h('button', {
|
|
4373
|
+
type: 'button', className: 'dg-btn dg-btnSmall dg-btnIcon', key: 'x',
|
|
4374
|
+
title: t('delete'), 'data-gallery-annot-remove': a.id,
|
|
4375
|
+
onClick: () => onRemove(a.id),
|
|
4376
|
+
}, '✕'),
|
|
4377
|
+
])))
|
|
4378
|
+
|
|
4379
|
+
return h('div', { className: 'dg-annotWrap', key: 'annot', style: { position: 'absolute', inset: 0 } }, [
|
|
4380
|
+
h('svg', {
|
|
4381
|
+
key: 'svg',
|
|
4382
|
+
ref: svgRef,
|
|
4383
|
+
className: `dg-annotSvg${active ? ' dg-annotActive' : ''}`,
|
|
4384
|
+
'data-gallery-annot-svg': true,
|
|
4385
|
+
'data-gallery-annot-active': active ? '1' : '0',
|
|
4386
|
+
viewBox: '0 0 100 100',
|
|
4387
|
+
preserveAspectRatio: 'none',
|
|
4388
|
+
style: {
|
|
4389
|
+
position: 'absolute', inset: 0, width: '100%', height: '100%',
|
|
4390
|
+
pointerEvents: active ? 'auto' : 'none',
|
|
4391
|
+
cursor: active ? 'crosshair' : 'default',
|
|
4392
|
+
},
|
|
4393
|
+
onPointerDown,
|
|
4394
|
+
onPointerMove,
|
|
4395
|
+
onPointerUp: finishDraft,
|
|
4396
|
+
onPointerCancel: () => setDraft(null),
|
|
4397
|
+
}, [draftShape, ...shapes]),
|
|
4398
|
+
list,
|
|
4399
|
+
editor,
|
|
4400
|
+
])
|
|
4401
|
+
}
|
|
4402
|
+
|
|
4075
4403
|
function SettingsPanel({ t, onClose, onSaved }) {
|
|
4076
4404
|
const [loading, setLoading] = React.useState(true)
|
|
4077
4405
|
const [info, setInfo] = React.useState(null)
|
|
@@ -4386,6 +4714,13 @@ ${absPath}
|
|
|
4386
4714
|
const [selected, setSelected] = React.useState(new Set())
|
|
4387
4715
|
/** 批量模式:用户显式开启,或已有选中项时自动生效(避免勾了看不见批量条)。 */
|
|
4388
4716
|
const [batchMode, setBatchMode] = React.useState(false)
|
|
4717
|
+
/**
|
|
4718
|
+
* 框选批注(v0.14.0):按 relPath 存,一次查看器内可加多条。
|
|
4719
|
+
*
|
|
4720
|
+
* 只记在内存 + 走草稿通道输出,**不落盘**(批注是"这次要跟 Agent 说的话",
|
|
4721
|
+
* 不是需要长期保留的状态;确认态才落盘,两者语义不同)。
|
|
4722
|
+
*/
|
|
4723
|
+
const [annotations, setAnnotations] = React.useState({})
|
|
4389
4724
|
const selectMode = batchMode || selected.size > 0
|
|
4390
4725
|
/** 清废稿确认对话框:null=关闭;{ phase:'list'|'deleting', files, digest, count } */
|
|
4391
4726
|
const [discardDialog, setDiscardDialog] = React.useState(null)
|
|
@@ -4580,6 +4915,34 @@ ${absPath}
|
|
|
4580
4915
|
}
|
|
4581
4916
|
}, [marks])
|
|
4582
4917
|
|
|
4918
|
+
/** 加一条批注(v0.14.0)。 */
|
|
4919
|
+
const addAnnotation = React.useCallback((item, annot) => {
|
|
4920
|
+
const relPath = item.relPath
|
|
4921
|
+
setAnnotations((prev) => {
|
|
4922
|
+
const cur = prev[relPath] ?? []
|
|
4923
|
+
if (cur.length >= 50) return prev // 与契约上限一致
|
|
4924
|
+
return { ...prev, [relPath]: [...cur, annot] }
|
|
4925
|
+
})
|
|
4926
|
+
}, [])
|
|
4927
|
+
|
|
4928
|
+
/** 删一条批注。 */
|
|
4929
|
+
const removeAnnotation = React.useCallback((item, id) => {
|
|
4930
|
+
const relPath = item.relPath
|
|
4931
|
+
setAnnotations((prev) => {
|
|
4932
|
+
const cur = prev[relPath] ?? []
|
|
4933
|
+
const next = cur.filter((a) => a.id !== id)
|
|
4934
|
+
const out = { ...prev }
|
|
4935
|
+
if (next.length === 0) delete out[relPath]
|
|
4936
|
+
else out[relPath] = next
|
|
4937
|
+
return out
|
|
4938
|
+
})
|
|
4939
|
+
}, [])
|
|
4940
|
+
|
|
4941
|
+
/** 取某文件的批注列表(给查看器用)。 */
|
|
4942
|
+
const annotationsOf = React.useCallback((item) => {
|
|
4943
|
+
return annotations[item.relPath] ?? []
|
|
4944
|
+
}, [annotations])
|
|
4945
|
+
|
|
4583
4946
|
/** 移除一条标记。 */
|
|
4584
4947
|
const removeMark = React.useCallback(async (relPath) => {
|
|
4585
4948
|
setMarks((prev) => {
|
|
@@ -5496,6 +5859,9 @@ ${absPath}
|
|
|
5496
5859
|
const viewerLayer = viewer !== null && Array.isArray(viewer.list) && viewer.list.length > 0
|
|
5497
5860
|
? h('div', { className: 'dg-viewerLayer', key: 'viewerLayer' },
|
|
5498
5861
|
h(Viewer, {
|
|
5862
|
+
annotations: annotationsOf,
|
|
5863
|
+
onAddAnnotation: addAnnotation,
|
|
5864
|
+
onRemoveAnnotation: removeAnnotation,
|
|
5499
5865
|
items: viewer.list,
|
|
5500
5866
|
index: Math.min(viewer.index, viewer.list.length - 1),
|
|
5501
5867
|
t,
|
package/host/protocol.js
CHANGED
|
@@ -23,3 +23,60 @@ export const VIDEO_EXTS = ['.mp4', '.webm', '.mov', '.m4v', '.mkv', '.avi', '.og
|
|
|
23
23
|
|
|
24
24
|
/** 音频扩展名。 */
|
|
25
25
|
export const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.opus', '.wma']
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 框选批注的坐标契约(v0.14.0)—— Host 与 Client 的唯一真源。
|
|
29
|
+
*
|
|
30
|
+
* 为什么用归一化坐标:批注要落在「图片的某个位置」上,而不是「屏幕上某个像素」。
|
|
31
|
+
* 写像素值的话,换个窗口尺寸 / 换个缩放比例就全错了。
|
|
32
|
+
* 用相对宽高的 0–1 比例,无论怎么缩放都能还原到同一块区域。
|
|
33
|
+
*
|
|
34
|
+
* 形状类型:
|
|
35
|
+
* rect —— 矩形框(最主要,圈出「这块不对」)
|
|
36
|
+
* arrow —— 箭头(指向具体某点)
|
|
37
|
+
* text —— 纯文字标注(钉在某位置,不带框)
|
|
38
|
+
*/
|
|
39
|
+
export const ANNOTATION_SHAPES = ["rect", "arrow", "text"]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 一条批注的数据形态:
|
|
43
|
+
* {
|
|
44
|
+
* id: string, // 稳定 id(同一次会话内唯一)
|
|
45
|
+
* shape: "rect|arrow|text",
|
|
46
|
+
* x: number, y: number, // 起点,归一化 0–1
|
|
47
|
+
* w: number, h: number, // 宽高,归一化 0–1(text/arrow 可只用 x,y)
|
|
48
|
+
* note: string, // 人写的说明(可为空)
|
|
49
|
+
* frameMs: number|null, // 视频帧时间(图片为 null)
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* 约束:x/y/w/h 必须落在 [0,1];越界由写入端 clamp。
|
|
53
|
+
*/
|
|
54
|
+
export const ANNOTATION_LIMITS = { min: 0, max: 1, maxNoteLength: 500, maxPerAsset: 50 }
|
|
55
|
+
|
|
56
|
+
/** 把任意数值 clamp 到 [0,1](批注坐标写入前必须过一遍)。 */
|
|
57
|
+
export function clamp01(v) {
|
|
58
|
+
const n = Number(v)
|
|
59
|
+
if (!Number.isFinite(n)) return 0
|
|
60
|
+
if (n < 0) return 0
|
|
61
|
+
if (n > 1) return 1
|
|
62
|
+
return n
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 校验并规整一条批注;不合法返回 null。 */
|
|
66
|
+
export function normalizeAnnotation(a) {
|
|
67
|
+
if (a === null || typeof a !== "object") return null
|
|
68
|
+
const shape = ANNOTATION_SHAPES.includes(a.shape) ? a.shape : "rect"
|
|
69
|
+
const note = typeof a.note === "string" ? a.note.slice(0, ANNOTATION_LIMITS.maxNoteLength) : ""
|
|
70
|
+
const x = clamp01(a.x)
|
|
71
|
+
const y = clamp01(a.y)
|
|
72
|
+
let w = clamp01(a.w)
|
|
73
|
+
let h = clamp01(a.h)
|
|
74
|
+
// 宽高至少留一点,且不越过右/下边界
|
|
75
|
+
if (w > 0 && x + w > 1) w = 1 - x
|
|
76
|
+
if (h > 0 && y + h > 1) h = 1 - y
|
|
77
|
+
const frameMs = Number.isFinite(a.frameMs) ? Math.max(0, Math.floor(a.frameMs)) : null
|
|
78
|
+
return {
|
|
79
|
+
id: typeof a.id === "string" && a.id !== "" ? a.id : ("a" + Math.random().toString(36).slice(2, 10)),
|
|
80
|
+
shape, x, y, w, h, note, frameMs,
|
|
81
|
+
}
|
|
82
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-gallery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "产出画廊:图片 / 文件 / 音视频实时可见与当场校验;按标记筛选、把「定版」真正锁住、批量处置;图上圈选批注攒成决策草稿,人工确认后送回对话。Output gallery for DeepSeek Harness: live image, file and media gallery with marker filters, persisted confirmation, batch actions, region annotation and human-approved decision drafts.",
|
|
6
6
|
"repository": {
|