dsh-knit 0.24.0 → 0.25.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.
@@ -15,6 +15,12 @@ window.__ModuleLoader__.load({
15
15
  factory: (require) => {
16
16
  const module = { exports: {} }
17
17
  const React = require('react')
18
+ /* v0.25(2026-10-22):全屏查看器要**盖住整个屏幕**,所以必须挂到 `document.body` 上。
19
+ 为什么不能就地渲染:`position:fixed` 会被**祖先的 transform / filter / contain 困住**
20
+ —— 宿主的右侧栏是滑入的(有 transform),那一层就成了 containing block,
21
+ `fixed` 于是变成「相对侧边栏」而不是视口,于是只能盖住面板那一块(用户实测如此)。
22
+ 这是 CSS 逃不出来的坑,只有 portal 能解。取不到 react-dom(老宿主 / 测试替身)就退回就地渲染。 */
23
+ const ReactDOM = (() => { try { return require('react-dom') } catch { return null } })()
18
24
  const h = React.createElement
19
25
 
20
26
  /* ── 国际化(DSH 官方 ctx.locale)─────────────────── */
@@ -42,6 +48,7 @@ window.__ModuleLoader__.load({
42
48
 
43
49
  'sort.relevance': '相关',
44
50
  'sort.time': '最新',
51
+ 'sort.mediaTimeTitle': '图片一律按时间排序(最新在前)',
45
52
  'sort.relevanceTitle': '按与当前对话的相关性排序(纯本地关键词匹配,不调模型)',
46
53
  'sort.timeTitle': '按文件修改时间倒序',
47
54
 
@@ -308,6 +315,25 @@ window.__ModuleLoader__.load({
308
315
 
309
316
  'preview.loading': '正在读取…',
310
317
  'preview.truncated': '(文件较大,仅预览前 512 KB)',
318
+ // v0.25 预览里的查找(Cmd+F)。数字用 {current}/{total},两种语言同形。
319
+ 'lightbox.aria': '查看大图:{name}',
320
+ 'lightbox.close': '关闭(Esc)',
321
+ 'attach.badge': '对话',
322
+ 'attach.title': '对话里生成的图,还没保存到本地',
323
+ 'fav.off': '收藏',
324
+ 'fav.on': '已收藏',
325
+ 'fav.addTitle': '收藏(排在媒体列表最前面)',
326
+ 'fav.removeTitle': '取消收藏',
327
+ 'fav.mark': '已收藏',
328
+ 'find.openBtn': '查找',
329
+ 'find.openTitle': '在本文里查找(Cmd+F)',
330
+ 'find.placeholder': '在本文里查找',
331
+ 'find.aria': '在预览的文档里查找',
332
+ 'find.count': '{current}/{total}',
333
+ 'find.none': '无结果',
334
+ 'find.prev': '上一个',
335
+ 'find.next': '下一个',
336
+ 'find.close': '关闭查找',
311
337
  'preview.fullscreen': '全屏',
312
338
  'preview.exitFullscreen': '退出全屏',
313
339
  'preview.fullscreenTitle': '全屏阅读',
@@ -395,6 +421,7 @@ window.__ModuleLoader__.load({
395
421
 
396
422
  'sort.relevance': 'Relevant',
397
423
  'sort.time': 'Recent',
424
+ 'sort.mediaTimeTitle': 'Images are always sorted by newest first',
398
425
  'sort.relevanceTitle': 'Sort by relevance to the current conversation (local keyword matching, no model call)',
399
426
  'sort.timeTitle': 'Sort by file modified time, newest first',
400
427
 
@@ -611,6 +638,24 @@ window.__ModuleLoader__.load({
611
638
 
612
639
  'preview.loading': 'Loading…',
613
640
  'preview.truncated': '(large file — showing the first 512 KB)',
641
+ 'lightbox.aria': 'Image viewer: {name}',
642
+ 'lightbox.close': 'Close (Esc)',
643
+ 'attach.badge': 'Chat',
644
+ 'attach.title': 'Generated in this chat — not saved locally yet',
645
+ 'fav.off': 'Favorite',
646
+ 'fav.on': 'Favorited',
647
+ 'fav.addTitle': 'Favorite this (it moves to the front of the media list)',
648
+ 'fav.removeTitle': 'Remove favorite',
649
+ 'fav.mark': 'Favorited',
650
+ 'find.openBtn': 'Find',
651
+ 'find.openTitle': 'Find in this document (Cmd+F)',
652
+ 'find.placeholder': 'Find in this document',
653
+ 'find.aria': 'Find in the previewed document',
654
+ 'find.count': '{current}/{total}',
655
+ 'find.none': 'No results',
656
+ 'find.prev': 'Previous',
657
+ 'find.next': 'Next',
658
+ 'find.close': 'Close find',
614
659
  'preview.fullscreen': 'Fullscreen',
615
660
  'preview.exitFullscreen': 'Exit fullscreen',
616
661
  'preview.fullscreenTitle': 'Read fullscreen',
@@ -791,6 +836,10 @@ window.__ModuleLoader__.load({
791
836
  /* v0.25:Git 变更关联的**独立接口**。它与列表接口分开,所以「列表的响应形状」
792
837
  不会被这个功能碰到;关掉功能时客户端连这个请求都不发。 */
793
838
  const CHANGES_API = '/knit/api/changes'
839
+ /* v0.25:媒体档额外显示「对话里工具产出的图」——**独立接口**,`/api/recent` 一个字节没动。
840
+ 列表零 I/O(元数据全在会话事件里);字节按 **sha256** 取(见 `attachmentUrl`)。 */
841
+ const ATTACH_LIST_API = '/knit/api/attachments'
842
+ const ATTACH_RAW_API = '/knit/api/attachment'
794
843
  const DOC_API = '/knit/api/doc'
795
844
  const RAW_API = '/knit/api/raw'
796
845
  // v0.12:某篇的「谁引用了它 / 它引用了谁」。与上面三条一样是**同源相对地址**,
@@ -969,6 +1018,227 @@ window.__ModuleLoader__.load({
969
1018
  * 格子基准宽(= CSS 的 minmax 下限)、当前宽度下能排几列、单格实际宽度、
970
1019
  * 是否让卡片文字让位
971
1020
  */
1021
+ /* ── v0.25:媒体档「悬停看大图」────────────────────────────────────────
1022
+ 用户要的是「鼠标停在图片上,弹一个大图」。
1023
+
1024
+ 三条取舍:
1025
+ ① **800×800 是上限,不是尺寸** —— 面板本身只有几百像素宽,硬占 800 会把对话区盖住。
1026
+ 所以盒子按「卡片左边还剩多少」与视口算,最后再夹到 800。
1027
+ ② **只做图片**(视频要解码 + 起播放器,噪声与代价都不是一个量级)。
1028
+ ③ **延迟出现**(`HOVER_SHOT_DELAY_MS`):鼠标扫过网格时不许一路闪;
1029
+ 离开即收。`pointer-events:none` —— 它只是「看一眼」,不许挡点击。
1030
+ */
1031
+
1032
+ /**
1033
+ * 悬停浮窗的边长上限。
1034
+ *
1035
+ * ⚠️ 2026-10-21 从 800 改成 420:用户在真机上看了之后说「现在浮窗太大了」,
1036
+ * 并在截图上用红框标出他想要的大小 —— 约等于原来的**一半**。
1037
+ * 这是**一个人眼定的大小**,不是算出来的;要再调就只改这一个数。
1038
+ */
1039
+ const HOVER_SHOT_MAX = 420
1040
+ /* ── v0.25:媒体档「双击全屏」(2026-10-22,参照用户给的 Codex 截图)────────
1041
+ 用户要的三件事:① 双击图片进全屏;② 点图片以外关闭;③ 左侧一列「近 10 张」缩略图。
1042
+ 另加两件(不然光看图就断手):图片以外是**毛玻璃**且随主题变(他第 4 点要的),
1043
+ 以及 `←` `→` 在带子里前后翻。
1044
+ 刻意**没做**(他没要,也不该顺手塞):缩放百分比、下载、用其他应用打开。
1045
+ */
1046
+
1047
+ /**
1048
+ * 把查看器挂到哪:**能 portal 就一定 portal**(否则 `fixed` 会被侧边栏的 transform 困住)。
1049
+ *
1050
+ * 单独抽成一个函数是为了「这件事有没有做」能被源码守卫直接看见 ——
1051
+ * 测试替身没有 `document`,这条路径只能在真机上走,所以形状守卫是它唯一的护栏。
1052
+ *
1053
+ * @param {object} node - 要挂的 React 元素
1054
+ * @param {{doc?:object, dom?:object}} [env] - 可注入的 document / ReactDOM(默认取模块里的)
1055
+ * @returns {object} portal 结果,或原节点(降级)
1056
+ */
1057
+ function mountLightbox(node, env = {}) {
1058
+ const dom = env.dom === undefined ? (typeof document === 'undefined' ? null : document) : env.dom
1059
+ const renderer = env.renderer === undefined ? ReactDOM : env.renderer
1060
+ try {
1061
+ if (node && dom && dom.body && renderer && typeof renderer.createPortal === 'function') {
1062
+ return renderer.createPortal(node, dom.body)
1063
+ }
1064
+ } catch { /* portal 失败就就地渲染,不许白屏 */ }
1065
+ return node
1066
+ }
1067
+
1068
+ /** 全屏查看器左侧缩略图带显示几张。 */
1069
+ const LIGHTBOX_RAIL = 10
1070
+ /** 当前这张在带子里前面留几张(偏「刚看过的」,不是偏「后面的」)。 */
1071
+ const LIGHTBOX_RAIL_LEAD = 4
1072
+
1073
+ /**
1074
+ * 全屏查看器的左侧缩略图带:取**当前这张附近**的 N 张。
1075
+ *
1076
+ * 为什么不是「最新的 N 张」:双击第 30 张时,「最新 10 张」里根本没有它 ——
1077
+ * 带子里看不到当前这张,前后翻也断在画面外。所以取一个以当前为中心的窗口,两头夹紧。
1078
+ * **纯函数**:只吃数组与下标,能真断言。
1079
+ *
1080
+ * @param {object[]} docs - 当前媒体列表(已排好序)
1081
+ * @param {number} index - 当前这张的下标
1082
+ * @param {{size?:number, lead?:number}} [opts] - 带子长度与前置张数
1083
+ * @returns {{start:number, items:object[]}} 起点与带子内容
1084
+ */
1085
+ function lightboxRail(docs, index, opts = {}) {
1086
+ const list = Array.isArray(docs) ? docs : []
1087
+ const size = Number.isFinite(opts.size) ? Math.max(1, Math.round(opts.size)) : LIGHTBOX_RAIL
1088
+ const lead = Number.isFinite(opts.lead) ? Math.max(0, Math.round(opts.lead)) : LIGHTBOX_RAIL_LEAD
1089
+ if (!list.length) return { start: 0, items: [] }
1090
+ const at = Number.isFinite(index) ? Math.min(Math.max(0, Math.round(index)), list.length - 1) : 0
1091
+ const start = Math.min(Math.max(0, at - lead), Math.max(0, list.length - size))
1092
+ return { start, items: list.slice(start, start + size) }
1093
+ }
1094
+
1095
+ /** 浮窗与卡片之间的间距。 */
1096
+ const HOVER_SHOT_GAP = 12
1097
+ /** 浮窗与视口边缘的最小留白。 */
1098
+ const HOVER_SHOT_MARGIN = 12
1099
+ /** 停多久才出现 —— 短了会在鼠标扫过时一路闪,长了会显得没反应。 */
1100
+ const HOVER_SHOT_DELAY_MS = 350
1101
+
1102
+ /**
1103
+ * 算悬停浮窗的盒子。**纯函数**:只吃两个矩形,不做任何 DOM 读。
1104
+ *
1105
+ * 规则:默认摆在卡片**左侧**(面板在右边,浮窗往对话区那边让,不压住网格);
1106
+ * 左边放不下就翻到右侧;垂直以卡片中线居中并夹进视口;盒子边长**最后**夹到 800。
1107
+ *
1108
+ * @param {{left:number,top:number,width:number,height:number}|null} card - 卡片矩形
1109
+ * @param {{width:number,height:number}} view - 视口尺寸
1110
+ * @param {{max?:number,gap?:number,margin?:number}} [opts] - 可注入的常数(测试用)
1111
+ * @returns {{left:number,top:number,width:number,height:number,side:'left'|'right'}} 盒子
1112
+ */
1113
+ function hoverShotBox(card, view, opts = {}) {
1114
+ const max = Number.isFinite(opts.max) ? opts.max : HOVER_SHOT_MAX
1115
+ const gap = Number.isFinite(opts.gap) ? opts.gap : HOVER_SHOT_GAP
1116
+ const margin = Number.isFinite(opts.margin) ? opts.margin : HOVER_SHOT_MARGIN
1117
+ const viewW = view && Number.isFinite(view.width) ? view.width : 1024
1118
+ const viewH = view && Number.isFinite(view.height) ? view.height : 768
1119
+ // 拿不到卡片矩形(测试替身没有 DOM / 事件不带 currentTarget)⇒ 视口里居中,仍然守 800 上限
1120
+ if (!card || !Number.isFinite(card.left) || !Number.isFinite(card.top)) {
1121
+ const size = Math.min(max, viewW - margin * 2, viewH - margin * 2)
1122
+ return {
1123
+ left: Math.max(margin, Math.round((viewW - size) / 2)),
1124
+ top: Math.max(margin, Math.round((viewH - size) / 2)),
1125
+ width: size,
1126
+ height: size,
1127
+ side: 'right',
1128
+ }
1129
+ }
1130
+ const roomLeft = card.left - gap - margin
1131
+ const roomRight = viewW - (card.left + card.width) - gap - margin
1132
+ const side = roomLeft >= roomRight ? 'left' : 'right'
1133
+ const room = Math.max(0, side === 'left' ? roomLeft : roomRight)
1134
+ const width = Math.max(1, Math.min(max, room, viewW - margin * 2))
1135
+ const height = Math.max(1, Math.min(max, viewH - margin * 2, width * 1.6))
1136
+ const rawLeft = side === 'left' ? card.left - gap - width : card.left + card.width + gap
1137
+ const left = Math.min(Math.max(margin, Math.round(rawLeft)), Math.max(margin, viewW - margin - width))
1138
+ const centerY = card.top + card.height / 2 - height / 2
1139
+ const top = Math.min(Math.max(margin, Math.round(centerY)), Math.max(margin, viewH - margin - height))
1140
+ return { left, top, width, height, side }
1141
+ }
1142
+
1143
+ /* ── v0.25:媒体收藏 ───────────────────────────────────────────────────
1144
+ 只活在 localStorage(`readPref / writePref` 那一族:这是**语义偏好**,不是界面几何)。
1145
+ **不改宿主、不加接口** ⇒ 只需要硬刷新,不用重启 DSH。
1146
+
1147
+ 顺序规则只有一条:**稳定分区** —— 收藏的按原有顺序排到前面,其余按原有顺序跟在后面。
1148
+ 刻意**不做第二套排序**(不按收藏时间排、不按文件名排):用户要的是「收藏的放最前面」,
1149
+ 而收藏之间谁在前仍由当前的「相关 / 最新」决定 —— 这样它不会变成第三种排序口径。
1150
+
1151
+ ⚠️ 与既有的「固定 / 排除」(`control.*`,宿主存储 `knit_control`)**不是同一件事**:
1152
+ 那一套只服务三层 Context Pack,媒体不参与,媒体卡片上也没有那个入口。
1153
+ */
1154
+
1155
+ /** 落盘的键。值形如 `{ "<root>": ["a.png", "b.mp4"] }`。 */
1156
+ const FAV_KEY = 'dsh-knit:favorites'
1157
+ /** 最多记几个工作区(换项目时旧的不会无限长)。 */
1158
+ const FAV_MAX_ROOTS = 5
1159
+ /** 每个工作区最多记几条(超了按写入顺序截断,不做 LRU)。 */
1160
+ const FAV_MAX_RELS = 200
1161
+
1162
+ /**
1163
+ * 把落盘的值解析成 `{ [root]: string[] }`。
1164
+ *
1165
+ * 畸形输入一律回空表,**不许抛** —— localStorage 里的东西可能是上一版、手改过的、
1166
+ * 或者干脆是别的插件写坏的;这里坏了不能让整个面板白掉。
1167
+ *
1168
+ * @param {string|null} raw - localStorage 里的原始字符串
1169
+ * @returns {Object<string, string[]>} 归一化后的表
1170
+ */
1171
+ function parseFavorites(raw) {
1172
+ if (typeof raw !== 'string' || !raw) return {}
1173
+ let data = null
1174
+ try { data = JSON.parse(raw) } catch { return {} }
1175
+ if (!data || typeof data !== 'object' || Array.isArray(data)) return {}
1176
+ const out = {}
1177
+ for (const root of Object.keys(data)) {
1178
+ const list = data[root]
1179
+ if (!Array.isArray(list)) continue
1180
+ const rels = []
1181
+ for (const rel of list) {
1182
+ if (typeof rel === 'string' && rel && rels.indexOf(rel) < 0) rels.push(rel)
1183
+ if (rels.length >= FAV_MAX_RELS) break
1184
+ }
1185
+ if (rels.length) out[root] = rels
1186
+ }
1187
+ return out
1188
+ }
1189
+
1190
+ /**
1191
+ * 某个工作区下的收藏。
1192
+ * @param {Object<string, string[]>} table - `parseFavorites()` 的产物
1193
+ * @param {string} root - 工作区根(未知时回空数组)
1194
+ * @returns {string[]} 副本
1195
+ */
1196
+ function favoriteRelsFor(table, root) {
1197
+ const key = typeof root === 'string' ? root : ''
1198
+ if (!key || !table || !Array.isArray(table[key])) return []
1199
+ return table[key].slice()
1200
+ }
1201
+
1202
+ /**
1203
+ * 加 / 取消一条收藏,返回**新数组**(不改入参)。
1204
+ * 新加的排到最前 —— 同一次会话里立即可见,不用等重新排序。
1205
+ *
1206
+ * @param {string[]} rels - 当前收藏
1207
+ * @param {string} rel - 目标
1208
+ * @returns {string[]} 新数组
1209
+ */
1210
+ function toggleFavoriteList(rels, rel) {
1211
+ const list = Array.isArray(rels) ? rels.slice() : []
1212
+ if (typeof rel !== 'string' || !rel) return list
1213
+ const at = list.indexOf(rel)
1214
+ if (at >= 0) { list.splice(at, 1); return list }
1215
+ list.unshift(rel)
1216
+ return list.slice(0, FAV_MAX_RELS)
1217
+ }
1218
+
1219
+ /**
1220
+ * 收藏的排到最前(**稳定**:两组内部都保持入参顺序)。
1221
+ * 没有收藏时**原样返回同一个数组**(同一引用,省一次无意义的重渲染)。
1222
+ *
1223
+ * @param {object[]} docs - 当前可见条目
1224
+ * @param {Set<string>|string[]} favorites - 收藏的 rel
1225
+ * @returns {object[]} 排好序的数组(或原数组)
1226
+ */
1227
+ function orderFavorites(docs, favorites) {
1228
+ const list = Array.isArray(docs) ? docs : []
1229
+ const has = (rel) => (favorites instanceof Set
1230
+ ? favorites.has(rel)
1231
+ : (Array.isArray(favorites) && favorites.indexOf(rel) >= 0))
1232
+ if (!list.length) return list
1233
+ const first = []
1234
+ const rest = []
1235
+ for (const doc of list) {
1236
+ if (doc && has(doc.rel)) first.push(doc)
1237
+ else rest.push(doc)
1238
+ }
1239
+ return first.length ? first.concat(rest) : list
1240
+ }
1241
+
972
1242
  function mediaLayoutFor(width) {
973
1243
  const w = Number(width)
974
1244
  const usable = Number.isFinite(w) && w > 0 ? w : MEDIA_FALLBACK_WIDTH
@@ -1011,6 +1281,7 @@ window.__ModuleLoader__.load({
1011
1281
  /* 「命中段」那一格要一个**灰底**而不是白描边(2026-10-07 用户裁决,原话是
1012
1282
  「叫它寻一个背景就行了,寻灰背景就行了,不需要在背景填充外面再加一个白色的描边」)。 */
1013
1283
  --knit-chip-bg:rgba(38,49,72,.092); /* 官方 10.20% × 0.90 */
1284
+
1014
1285
  display:flex;flex-direction:column;height:100%;min-height:0;
1015
1286
  color:var(--dsw-alias-label-primary,#e8eaed);font-size:13px}
1016
1287
  body[data-ds-dark-theme] .knit-root{
@@ -1636,6 +1907,51 @@ button.knit-why:hover,button.knit-why:focus-visible{color:var(--dsw-alias-label-
1636
1907
  .knit-notice{margin:6px 8px 0;padding:7px 10px;border-radius:7px;font-size:11px;line-height:1.5;
1637
1908
  background:rgba(255,120,120,.12);border:.5px solid rgba(255,120,120,.3);color:#ffb4b4}
1638
1909
  .knit-badge{font-size:10px;margin-right:3px}
1910
+ /* v0.25 媒体收藏:★ 是**状态标记**,所以吃品牌色(与聚焦圈 / 分区「查看全部」同一档);
1911
+ 只在**名字行里**占一个字形的位置,不上缩略图、不加底色、不做 hover —— 网格不许长出第二套 chrome。 */
1912
+ .knit-fav{font-size:10px;margin-right:3px;color:var(--knit-accent)}
1913
+ /* v0.25:对话里生成的图 —— 标记用**文字**(承担信息:还没存进项目、存进去就消失)。
1914
+ 字色取次级灰:它不是层级,是来源说明,不该抢过 ★。 */
1915
+ .knit-conv{font-size:10px;margin-right:3px;color:var(--dsw-alias-label-caption,#80868b)}
1916
+ /* v0.25 媒体档「悬停看大图」—— 与入口浮窗同一套外框(圆角 / 阴影 / 边框 / 层级)。
1917
+ ⚠️ pointer-events:none 是必须的:它只是看一眼,绝不许挡住卡片的点击。
1918
+ 尺寸由 JS 下发(上限 800,按可用空间收缩),这里只负责「图在盒子里等比铺满」。 */
1919
+ .knit-shot{position:fixed;z-index:60;display:flex;align-items:center;justify-content:center;
1920
+ padding:6px;border-radius:12px;pointer-events:none;
1921
+ background:var(--dsw-alias-bg-layer-2,#2c2c2e);
1922
+ border:.5px solid var(--dsw-alias-border-l4,rgba(255,255,255,.12));
1923
+ box-shadow:0 12px 32px rgba(0,0,0,.32)}
1924
+ .knit-shot img{display:block;max-width:100%;max-height:100%;border-radius:8px;object-fit:contain}
1925
+ /* v0.25 媒体档「双击全屏」:整窗遮罩 + 毛玻璃。层级在悬停浮窗(60)与菜单之上。
1926
+ 左侧留 96px 给缩略图带(它绝对定位在遮罩里);图片按 contain 铺满剩下的区域。 */
1927
+ .knit-lightbox{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;
1928
+ padding:32px 32px 32px 96px;outline:none;cursor:zoom-out;
1929
+ /* ⚠️ 遮罩的 α 是**人眼定的**(与 box-shadow 同一性质,推不出来);两套值**必须不同**,
1930
+ 否则「随深色模式变化」就是假话(有守卫)。
1931
+ ⚠️ 这两个变量故意**挂在查看器自己身上** —— 它被 portal 到 document.body 之后
1932
+ 不在 .knit-root 里了,读不到那层的变量(第一版就是这么静默变成透明遮罩的)。 */
1933
+ --knit-scrim:rgba(255,255,255,.62);
1934
+ background:var(--knit-scrim);backdrop-filter:blur(22px) saturate(1.1);
1935
+ -webkit-backdrop-filter:blur(22px) saturate(1.1)}
1936
+ body[data-ds-dark-theme] .knit-lightbox{--knit-scrim:rgba(18,18,20,.72)}
1937
+ .knit-lightbox-stage{flex:1 1 auto;min-width:0;min-height:0;display:flex;align-items:center;
1938
+ justify-content:center;cursor:default}
1939
+ .knit-lightbox-img{max-width:100%;max-height:100%;object-fit:contain;border-radius:10px;cursor:default;
1940
+ box-shadow:0 24px 64px rgba(0,0,0,.36);background:var(--dsw-alias-bg-base,#fff)}
1941
+ .knit-lightbox-tools{position:absolute;top:18px;right:62px;display:flex;align-items:center;gap:6px}
1942
+ .knit-lightbox-close{position:absolute;top:18px;right:18px;width:34px;height:34px;padding:0;
1943
+ display:flex;align-items:center;justify-content:center;border:0;border-radius:10px;
1944
+ cursor:pointer;font-family:inherit;font-size:15px;line-height:1;
1945
+ color:var(--dsw-alias-label-primary,#0f1115);background:transparent;opacity:.7}
1946
+ .knit-lightbox-close:hover{opacity:1;background:var(--knit-hover-bg,transparent)}
1947
+ .knit-lightbox-rail{position:absolute;left:10px;top:50%;transform:translateY(-50%);display:flex;
1948
+ flex-direction:column;gap:6px;max-height:88vh;overflow-y:auto;padding:4px;cursor:default}
1949
+ .knit-lightbox-thumb{flex:none;width:64px;height:64px;padding:0;border:0;border-radius:8px;overflow:hidden;
1950
+ cursor:pointer;background:transparent;opacity:.68;transition:opacity .16s ease}
1951
+ .knit-lightbox-thumb img{width:100%;height:100%;object-fit:cover;display:block}
1952
+ .knit-lightbox-thumb:hover{opacity:1}
1953
+ .knit-lightbox-thumb.active{opacity:1;box-shadow:0 0 0 2px var(--knit-accent,var(--dsw-alias-brand-primary-new-colorprimary-new-color))}
1954
+ @media (prefers-reduced-motion: reduce){.knit-lightbox-thumb{transition:none}}
1639
1955
 
1640
1956
  /* ── 列表下方的预览面板 ───────────────────────────────
1641
1957
  要让人一眼看出「这是另一层,不是列表的续行」,靠**结构**而不是底色:
@@ -1752,6 +2068,26 @@ body[data-ds-dark-theme] .knit-preview{box-shadow:0 -8px 24px rgba(0,0,0,.38)}
1752
2068
  一上一下两条细线把这一小块夹成了独立一截,用户的原话是「有点割裂」。
1753
2069
  现在这一层不画任何横线,收紧的 padding 就是它的边界。
1754
2070
  注意 CSS 里不要写反引号 —— 这段样式是模板字符串,一个反引号就会把它截断。 */
2071
+ /* v0.25 查找条:与 .knit-links 同一层(夹在头与正文之间,**不参与正文滚动**)。
2072
+ 输入框直接复用工具栏那套(.knit-searchwrap + .knit-filter)—— 同一份视觉语言,不新造控件;
2073
+ 这里只把它的最大宽度放开(查找条要占满一行)。
2074
+ ⚠️ 注意:本段注释里不许出现反引号 —— 整个 CSS 在一个模板串里。 */
2075
+ .knit-findbar{flex:none;display:flex;align-items:center;gap:6px;padding:4px 12px 6px}
2076
+ .knit-findbar .knit-searchwrap{flex:1 1 auto;max-width:none}
2077
+ .knit-findcount{flex:none;font-size:11px;color:var(--dsw-alias-label-caption,#80868b);
2078
+ font-variant-numeric:tabular-nums}
2079
+ .knit-findnav{flex:none;width:22px;height:22px;border-radius:6px;cursor:pointer;
2080
+ display:inline-flex;align-items:center;justify-content:center;font-size:12px;
2081
+ background:transparent;border:none;color:var(--dsw-alias-label-secondary,#9aa0a6)}
2082
+ .knit-findnav:hover:not(:disabled){background:var(--knit-hover-bg,rgba(255,255,255,.03));
2083
+ color:var(--dsw-alias-label-primary,#e8eaed)}
2084
+ .knit-findnav:disabled{opacity:.4;cursor:default}
2085
+ /* 命中的样式 —— **只有底色**。没有 padding、没有 border、颜色继承 —— 一有内边距就会改变行高与折行,
2086
+ 而代码预览的命中横带是按「滚动高度 ÷ 行数」算行高的,动了就会错位。
2087
+ 两级灰阶建立层级(普通命中 = hover 那档,当前命中 = 命中段那档),不引入第二种颜色。 */
2088
+ mark.knit-find{background:var(--knit-hover-bg,rgba(255,255,255,.03));color:inherit;
2089
+ padding:0;border:0;border-radius:2px}
2090
+ mark.knit-find-current{background:var(--knit-chip-bg)}
1755
2091
  .knit-links{flex:none;font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
1756
2092
  .knit-links-state{padding:5px 12px;color:var(--dsw-alias-label-caption,#80868b)}
1757
2093
  .knit-links-head{box-sizing:border-box;display:flex;align-items:center;gap:6px;width:100%;
@@ -2227,6 +2563,20 @@ video.knit-preview-media{width:100%;background:#000}
2227
2563
  return `${RAW_API}?sessionId=${encodeURIComponent(sessionId)}&rel=${encodeURIComponent(rel)}`
2228
2564
  }
2229
2565
 
2566
+ /**
2567
+ * 对话里生成的图(v0.25)的字节地址。
2568
+ *
2569
+ * ⚠️ **只传 sha256 id,不传路径** —— 宿主那条路由只认 `sha256:<64 hex>`,而且只读
2570
+ * **本会话出现过**的 id。这不是硬凑的 URL 形状,是那条边界的全部:给不出路径就没有穿越。
2571
+ *
2572
+ * @param {string} sessionId - 会话 id
2573
+ * @param {string} id - `sha256:<64 hex>`
2574
+ * @returns {string} 同源地址
2575
+ */
2576
+ function attachmentUrl(sessionId, id) {
2577
+ return `${ATTACH_RAW_API}?sessionId=${encodeURIComponent(sessionId)}&id=${encodeURIComponent(id)}`
2578
+ }
2579
+
2230
2580
  /**
2231
2581
  * 秒 → `m:ss` / `h:mm:ss`,用于视频时长角标。
2232
2582
  * @param {number} seconds - 秒
@@ -3138,7 +3488,7 @@ video.knit-preview-media{width:100%;background:#000}
3138
3488
  * @param {object} props - 与 DocRow 同构,外加 src
3139
3489
  * @returns {import('react').ReactElement} 元素
3140
3490
  */
3141
- function MediaCard({ doc, now, active, cursor, src, onSelect, onOpenTab, optionId }) {
3491
+ function MediaCard({ doc, now, active, cursor, src, onSelect, onOpenTab, onZoom, onPreview, optionId, favorite, conversation, onHoverStart, onHoverEnd }) {
3142
3492
  const fresh = now - doc.mtimeMs < NEW_WINDOW_MS
3143
3493
  return h('div', {
3144
3494
  className: `knit-media-card${active ? ' active' : ''}${cursor ? ' cursor' : ''}${fresh ? ' fresh' : ''}`,
@@ -3147,13 +3497,29 @@ video.knit-preview-media{width:100%;background:#000}
3147
3497
  id: optionId,
3148
3498
  'aria-selected': active ? 'true' : 'false',
3149
3499
  'data-knit-rel': doc.rel,
3150
- title: t('row.tooltip', { path: doc.rel }),
3500
+ // v0.25:对话里生成的图没有工作区路径 —— 提示语换成「还没保存到本地」
3501
+ title: conversation ? t('attach.title') : t('row.tooltip', { path: doc.rel }),
3151
3502
  onClick: () => onSelect(doc),
3152
- onDoubleClick: () => onOpenTab(doc),
3503
+ /* v0.25(2026-10-22 用户裁决):媒体档**取消单击就地预览** —— 双击才是「看」。
3504
+ 按类型分流:
3505
+ · 图片 → 全屏查看器(`onZoom`,里面自带收藏 / 本地打开);
3506
+ · 视频 → **仍走就地预览**(`onPreview`):查看器只做图片,不这么走的话
3507
+ 播放器、收藏、本地打开就全没了入口。 */
3508
+ onDoubleClick: () => (doc.kind === 'image'
3509
+ ? (onZoom && onZoom(doc))
3510
+ : (onPreview ? onPreview(doc) : onOpenTab(doc))),
3511
+ // v0.25:悬停看大图(只对图片;视频交给点击预览)。事件里带矩形,几何在纯函数里算。
3512
+ onMouseEnter: onHoverStart ? (event) => onHoverStart(doc, src, event) : undefined,
3513
+ onMouseLeave: onHoverEnd || undefined,
3153
3514
  },
3154
3515
  h('div', { className: 'knit-media-thumbbox' }, h(MediaThumb, { doc, src })),
3155
3516
  h('div', { className: 'knit-media-meta' },
3156
3517
  h('div', { className: 'knit-media-name', title: doc.name },
3518
+ // v0.25:对话里生成的图带一个「对话」标记 —— 它解释两件事:这张还没存进项目、
3519
+ // 存进去之后它会自己消失(去重规则)。用文字不用图标:它承担信息。
3520
+ conversation ? h('span', { className: 'knit-conv' }, t('attach.badge')) : null,
3521
+ // v0.25 媒体收藏:★ 是**状态标记**(不是装饰)—— 它解释「这张为什么排在最前面」
3522
+ favorite ? h('span', { className: 'knit-fav', title: t('fav.mark'), 'aria-label': t('fav.mark') }, '★') : null,
3157
3523
  fresh ? h('span', { className: 'knit-badge' }, '🆕') : null,
3158
3524
  doc.name),
3159
3525
  h('div', { className: 'knit-media-time' }, relTime(doc.mtimeMs, now))))
@@ -3502,6 +3868,214 @@ video.knit-preview-media{width:100%;background:#000}
3502
3868
  return true
3503
3869
  }
3504
3870
 
3871
+ /* ── v0.25:预览里的「查找」(Cmd+F)───────────────────────────────────
3872
+ 用户要的是「像 Chrome 那样在文档里搜关键词并定位」。三条房规决定了它长什么样:
3873
+
3874
+ ① **不自己渲染 Markdown**(见 DocPane 那条注释:那会变成第二套渲染器)
3875
+ ⇒ 与 `docAnchorHit` 同一套办法:渲染完成后走 TreeWalker,在**已经渲染出来的文本**上找。
3876
+ ② **匹配是纯函数**,DOM 那一层只负责画。测试替身没有 document,所以能被真断言钉住的
3877
+ 只有纯函数那一半 —— 这是刻意的分工,与 `docAnchorNeedles`(纯)/
3878
+ `docAnchorHit`(DOM)那条已有的分界线一致。
3879
+ ③ **命中只上底色,绝不动几何**:`mark` 不许有 padding / border,也不许改行高
3880
+ —— 代码预览的命中横带是按「滚动高度 ÷ 行数」算行高的,动了就会错位。
3881
+
3882
+ ⚠️ 已知边界(与既有锚点定位同一条):命中**不跨文本节点**。渲染会把 `**粗**字`
3883
+ 拆成两个节点,所以正好被 Markdown 语法截断的关键词(一半在「粗」左边、一半在右边)找不到。
3884
+ 跨节点要额外把「归一化后的下标」分别映射回两个节点的原文下标,代价与收益不成比例。
3885
+ `preview.truncated` 那句「仅预览前 512 KB」不算文档内容,跳过不搜。
3886
+ */
3887
+
3888
+ /**
3889
+ * 在一段文本里找出**所有**字面量命中。
3890
+ *
3891
+ * - **字面量,不是正则**:输入 `(`、`*`、`[` 时必须原样找 —— 既不许当元字符,也不许抛
3892
+ * (用户搜的是关键词,不是模式)。
3893
+ * - **不重叠、按出现顺序**(与 Chrome 的计数口径一致)。
3894
+ * - **大小写不敏感,但只在折叠后长度不变时才用折叠串**:少数 Unicode 字符折叠后会**变长**
3895
+ * (如 `İ`),那样下标就与原文错位、画出来的命中会偏一格。这种输入退回大小写敏感 ——
3896
+ * 宁可少匹配几个,也不许标错位置。
3897
+ *
3898
+ * @param {string} haystack - 被搜的文本
3899
+ * @param {string} query - 关键词
3900
+ * @returns {{start:number,end:number}[]} 命中区间(原文下标,左闭右开)
3901
+ */
3902
+ function findRanges(haystack, query) {
3903
+ const text = typeof haystack === 'string' ? haystack : ''
3904
+ const needle = typeof query === 'string' ? query : ''
3905
+ if (!text || !needle) return []
3906
+ const foldedText = text.toLowerCase()
3907
+ const foldedNeedle = needle.toLowerCase()
3908
+ const foldable = foldedText.length === text.length && foldedNeedle.length === needle.length
3909
+ const hay = foldable ? foldedText : text
3910
+ const pin = foldable ? foldedNeedle : needle
3911
+ const out = []
3912
+ let from = 0
3913
+ for (;;) {
3914
+ const at = hay.indexOf(pin, from)
3915
+ if (at < 0) break
3916
+ out.push({ start: at, end: at + pin.length })
3917
+ from = at + pin.length
3918
+ }
3919
+ return out
3920
+ }
3921
+
3922
+ /**
3923
+ * 归一化文本的**下标 → 原文下标**映射。
3924
+ *
3925
+ * 搜索要先把换行折叠成空格再找(渲染出来的文本就是这样,不折叠就对不上),
3926
+ * 但**画的时候必须切原文** —— 所以需要这座桥:返回数组第 i 项 = 归一化文本第 i 个字符
3927
+ * 在原文里的下标。归一化规则与 `docAnchorHit` 逐字同一条:一串空白 → 一个空格。
3928
+ *
3929
+ * @param {string} original - 原文
3930
+ * @returns {number[]} 映射(长度 == 归一化后的长度)
3931
+ */
3932
+ function normalizedIndexMap(original) {
3933
+ const text = typeof original === 'string' ? original : ''
3934
+ const map = []
3935
+ let i = 0
3936
+ while (i < text.length) {
3937
+ map.push(i)
3938
+ const isSpace = /\s/.test(text[i])
3939
+ i += 1
3940
+ if (isSpace) while (i < text.length && /\s/.test(text[i])) i += 1
3941
+ }
3942
+ return map
3943
+ }
3944
+
3945
+ /**
3946
+ * 下一个命中下标(**环绕**,与 Chrome 一致:最后一个再按「下一个」回到第一个)。
3947
+ *
3948
+ * @param {number} current - 当前下标
3949
+ * @param {number} total - 命中总数
3950
+ * @param {number} delta - 方向(负数 = 上一个)
3951
+ * @returns {number} 新下标(total 为 0 时恒 0)
3952
+ */
3953
+ function stepFindIndex(current, total, delta) {
3954
+ if (!(total > 0)) return 0
3955
+ const at = Number.isFinite(current) ? Math.min(Math.max(0, Math.round(current)), total - 1) : 0
3956
+ const next = (at + (delta < 0 ? -1 : 1)) % total
3957
+ return next < 0 ? next + total : next
3958
+ }
3959
+
3960
+ /** 查找时跳过的子树:`preview.truncated` 那句提示不是文档内容。 */
3961
+ function findSkippedNode(node) {
3962
+ let el = node && node.parentNode
3963
+ while (el && el.nodeType === 1) {
3964
+ if (String(el.className || '').indexOf('knit-preview-note') >= 0) return true
3965
+ el = el.parentNode
3966
+ }
3967
+ return false
3968
+ }
3969
+
3970
+ /**
3971
+ * 把命中画成 `mark.knit-find`,返回**按文档顺序**的命中元素。
3972
+ *
3973
+ * 一个文本节点里可能有多个命中 —— 先把该节点切成「文本 + mark + 文本…」再整体替换它,
3974
+ * 所以顺序天然是对的;`insertBefore` 逐片插在旧节点前面、最后删掉旧节点。
3975
+ * 没有 document(测试替身)时**静默返回空数组** —— 与 `scrollToDocAnchor` 同一层守卫。
3976
+ *
3977
+ * @param {HTMLElement|null} box - 正文容器
3978
+ * @param {string} query - 关键词
3979
+ * @returns {HTMLElement[]} 命中元素(文档顺序)
3980
+ */
3981
+ function paintFindMarks(box, query) {
3982
+ if (!box || typeof document === 'undefined' || typeof document.createTreeWalker !== 'function') return []
3983
+ if (typeof document.createElement !== 'function' || !query) return []
3984
+ const walker = document.createTreeWalker(box, 4) // 4 = SHOW_TEXT
3985
+ const targets = []
3986
+ let node = walker.nextNode()
3987
+ while (node) {
3988
+ const value = String(node.nodeValue || '')
3989
+ if (value && !findSkippedNode(node)) {
3990
+ const flat = value.replace(/\s+/g, ' ')
3991
+ const ranges = findRanges(flat, query)
3992
+ if (ranges.length && node.parentNode) {
3993
+ targets.push({ node, value, ranges, map: normalizedIndexMap(value) })
3994
+ }
3995
+ }
3996
+ node = walker.nextNode()
3997
+ }
3998
+ const marks = []
3999
+ for (const target of targets) {
4000
+ const pieces = []
4001
+ let at = 0
4002
+ for (const range of target.ranges) {
4003
+ const from = target.map[range.start]
4004
+ const to = range.end < target.map.length ? target.map[range.end] : target.value.length
4005
+ if (!(from >= at) || !(to > from)) continue
4006
+ if (from > at) pieces.push(document.createTextNode(target.value.slice(at, from)))
4007
+ const mark = document.createElement('mark')
4008
+ mark.className = 'knit-find'
4009
+ mark.textContent = target.value.slice(from, to)
4010
+ pieces.push(mark)
4011
+ marks.push(mark)
4012
+ at = to
4013
+ }
4014
+ if (!pieces.length) continue
4015
+ if (at < target.value.length) pieces.push(document.createTextNode(target.value.slice(at)))
4016
+ const parent = target.node.parentNode
4017
+ for (const piece of pieces) parent.insertBefore(piece, target.node)
4018
+ parent.removeChild(target.node)
4019
+ }
4020
+ return marks
4021
+ }
4022
+
4023
+ /**
4024
+ * 还原:把每个 `mark.knit-find` 换回纯文本节点,再把相邻文本节点合并。
4025
+ *
4026
+ * **必须还原得干净** —— 否则下一次画是在「已经画过的树」上再画一层,
4027
+ * 命中数会越算越多,而且退出查找后正文里永远留着标签。
4028
+ *
4029
+ * @param {HTMLElement|null} box - 正文容器
4030
+ * @returns {void}
4031
+ */
4032
+ function clearFindMarks(box) {
4033
+ if (!box || typeof box.querySelectorAll !== 'function' || typeof document === 'undefined') return
4034
+ const marks = box.querySelectorAll('mark.knit-find')
4035
+ const parents = []
4036
+ for (let i = 0; i < marks.length; i += 1) {
4037
+ const mark = marks[i]
4038
+ const parent = mark.parentNode
4039
+ if (!parent) continue
4040
+ parent.replaceChild(document.createTextNode(String(mark.textContent || '')), mark)
4041
+ if (parents.indexOf(parent) < 0) parents.push(parent)
4042
+ }
4043
+ for (const parent of parents) if (typeof parent.normalize === 'function') parent.normalize()
4044
+ }
4045
+
4046
+ /** 标出「当前这一条命中」(其余保持普通底色)。 */
4047
+ function markFindCurrent(marks, index) {
4048
+ if (!Array.isArray(marks)) return
4049
+ for (let i = 0; i < marks.length; i += 1) {
4050
+ const el = marks[i]
4051
+ if (!el || !el.classList) continue
4052
+ if (i === index) el.classList.add('knit-find-current')
4053
+ else el.classList.remove('knit-find-current')
4054
+ }
4055
+ }
4056
+
4057
+ /**
4058
+ * 把当前命中滚进视野 —— 与 `scrollToDocAnchor` **同一套手动算术**。
4059
+ *
4060
+ * 刻意不用 `scrollIntoView`:那会连带滚外层容器与整个面板,长文里的位置会飘
4061
+ * (见 `scrollToDocAnchor` 那条注释,同一个坑)。这里滚的仍是 `.knit-preview-body`。
4062
+ * 位置取**居中**:逐个往下找时,命中停在视野中间最好读。
4063
+ *
4064
+ * @param {HTMLElement|null} mark - 当前命中的元素
4065
+ * @returns {boolean} 是否真的滚了
4066
+ */
4067
+ function scrollMarkIntoView(mark) {
4068
+ if (!mark || typeof mark.getBoundingClientRect !== 'function') return false
4069
+ const box = typeof mark.closest === 'function' ? mark.closest('.knit-preview-body') : null
4070
+ if (!box || !Number.isFinite(box.scrollTop) || typeof box.getBoundingClientRect !== 'function') return false
4071
+ const rect = box.getBoundingClientRect()
4072
+ const delta = mark.getBoundingClientRect().top - rect.top
4073
+ const viewH = Number.isFinite(rect.height) ? rect.height : 0
4074
+ const target = box.scrollTop + delta - Math.max(0, viewH / 2 - 10)
4075
+ box.scrollTop = Math.max(0, Math.round(target))
4076
+ return true
4077
+ }
4078
+
3505
4079
  /**
3506
4080
  * Markdown 预览:在 `MarkdownText` 外面包一层,只为把「跳到你点的那一段」接上。
3507
4081
  *
@@ -3659,7 +4233,14 @@ video.knit-preview-media{width:100%;background:#000}
3659
4233
  : null)
3660
4234
  }
3661
4235
 
3662
- function PreviewPanel({ preview, pathImages, fullscreen, ratio, links, linksExpanded, onToggleLinks, onOpenLink, onClose, onOpenLocal, onReveal, onOpenMap, onOpenWeb, onToggleFullscreen, onResizeStart }) {
4236
+ /**
4237
+ * 预览面板(头 + 引用条 + 正文)。
4238
+ *
4239
+ * @param {object} props - 渲染入参。
4240
+ * `find`(v0.25)= 查找条那一组:状态在 `KnitBody`(快捷键挂在面板根上,
4241
+ * 所以状态不能只活在这一层);`bodyRef` = 正文容器 ref,由 `KnitBody` 拿去做 DOM 命中绘制。
4242
+ */
4243
+ function PreviewPanel({ preview, pathImages, fullscreen, ratio, links, linksExpanded, onToggleLinks, onOpenLink, onClose, onOpenLocal, onReveal, onOpenMap, onOpenWeb, onToggleFullscreen, onResizeStart, find, bodyRef, favorite, onToggleFavorite }) {
3663
4244
  const isMedia = preview.kind === 'image' || preview.kind === 'video'
3664
4245
  const previewPath = splitRelPath(preview.rel)
3665
4246
 
@@ -3724,6 +4305,51 @@ video.knit-preview-media{width:100%;background:#000}
3724
4305
  h('span', { className: 'knit-link-name' }, item.title),
3725
4306
  h('span', { className: 'knit-link-path' }, item.rel))))))
3726
4307
 
4308
+ /* v0.25 查找条:位置与 `linksBar` 同一层(夹在头与正文之间,**不参与正文滚动**)。
4309
+ 只在查找打开、且这篇有可搜正文(非媒体)时出现;它占的是预览内部的行高,
4310
+ 预览的**外框高度是写死的**(style.height = 拖出来的比例)⇒ 列表不会被它推着动。 */
4311
+ const findBar = find && find.on && !isMedia
4312
+ ? h('div', { className: 'knit-findbar' },
4313
+ h('div', { className: 'knit-searchwrap' },
4314
+ h('input', {
4315
+ // 第二个 class 是给测试与样式用的锚点:替身返回的是**扁平**节点表,
4316
+ // 没有父子关系可查,而工具栏那个过滤框也叫 .knit-filter —— 不区分就分不出谁是谁。
4317
+ className: 'knit-filter knit-findinput',
4318
+ ref: find.inputRef,
4319
+ value: find.query,
4320
+ placeholder: t('find.placeholder'),
4321
+ 'aria-label': t('find.aria'),
4322
+ onChange: (event) => find.onQuery(event.target.value),
4323
+ onKeyDown: (event) => {
4324
+ if (event.key === 'Enter') {
4325
+ event.preventDefault()
4326
+ find.onStep(event.shiftKey ? -1 : 1)
4327
+ } else if (event.key === 'Escape') {
4328
+ // 双保险:根上的捕获阶段通常已经处理掉了(那里要抢在列表的 Esc 之前)
4329
+ event.stopPropagation()
4330
+ find.onClose()
4331
+ }
4332
+ },
4333
+ })),
4334
+ h('span', { className: 'knit-findcount', 'aria-live': 'polite' },
4335
+ !find.query
4336
+ ? ''
4337
+ : (find.count > 0
4338
+ ? t('find.count', { current: Math.min(find.index, find.count - 1) + 1, total: find.count })
4339
+ : t('find.none'))),
4340
+ h('button', {
4341
+ type: 'button', className: 'knit-findnav', title: t('find.prev'),
4342
+ disabled: find.count === 0, onClick: () => find.onStep(-1),
4343
+ }, '↑'),
4344
+ h('button', {
4345
+ type: 'button', className: 'knit-findnav', title: t('find.next'),
4346
+ disabled: find.count === 0, onClick: () => find.onStep(1),
4347
+ }, '↓'),
4348
+ h('button', {
4349
+ type: 'button', className: 'knit-preview-close', title: t('find.close'), onClick: find.onClose,
4350
+ }, '✕'))
4351
+ : null
4352
+
3727
4353
  const linksBar = (() => {
3728
4354
  if (!links || !onToggleLinks) return null
3729
4355
  if (links.status === 'loading') {
@@ -3875,6 +4501,27 @@ video.knit-preview-media{width:100%;background:#000}
3875
4501
  onClick: onToggleFullscreen,
3876
4502
  title: fullscreen ? t('preview.exitFullscreenTitle') : t('preview.fullscreenTitle'),
3877
4503
  }, fullscreen ? t('preview.exitFullscreen') : t('preview.fullscreen')),
4504
+ // v0.25 媒体收藏:只给媒体档。
4505
+ // 「收藏」在文档 / 代码上是另一个概念(那是 Context Pack 的「固定」,宿主存储),
4506
+ // 这里不混用,也不给媒体做固定 —— 两套语义各自独立。
4507
+ isMedia && onToggleFavorite
4508
+ ? h('button', {
4509
+ className: 'knit-btn',
4510
+ onClick: () => onToggleFavorite(preview.rel),
4511
+ title: favorite ? t('fav.removeTitle') : t('fav.addTitle'),
4512
+ }, favorite ? t('fav.on') : t('fav.off'))
4513
+ : null,
4514
+ // v0.25 追加:**查找**按钮。
4515
+ // 为什么除了快捷键还要有这个按钮:外层应用(飞书客户端的内置浏览器等)有自己的
4516
+ // 原生 Cmd+F,它在按键**进入网页之前**就被处理掉了 —— 网页侧抢不回来。
4517
+ // 所以能力必须有一个**不依赖快捷键**的入口。只给有正文的档:媒体档没有可搜的东西。
4518
+ !isMedia
4519
+ ? h('button', {
4520
+ className: 'knit-btn',
4521
+ onClick: () => { if (find) find.onOpen() },
4522
+ title: t('find.openTitle'),
4523
+ }, t('find.openBtn'))
4524
+ : null,
3878
4525
  // v0.19 追加:**网页预览** —— 只给 HTML。
3879
4526
  // 它开的是官方文档预览标签页(`actions.openResource`,与双击列表行**同一条**路),
3880
4527
  // 那一侧有 DSH 自带的 HTML 渲染器,出来的是**网页**而不是源码。
@@ -3905,8 +4552,11 @@ video.knit-preview-media{width:100%;background:#000}
3905
4552
  h('button', { className: 'knit-preview-close', onClick: onClose, title: t('preview.close') }, '✕')),
3906
4553
  // v0.12 引用条:夹在头与正文之间,不参与正文滚动
3907
4554
  linksBar,
4555
+ // v0.25 查找条:同上,也是「夹在头与正文之间」
4556
+ findBar,
3908
4557
  h('div', {
3909
4558
  className: `knit-preview-body${isMedia ? ' is-media' : ''}`,
4559
+ ref: bodyRef,
3910
4560
  },
3911
4561
  !isMedia && preview.truncated ? h('div', { className: 'knit-preview-note' }, t('preview.truncated')) : null,
3912
4562
  body))
@@ -4003,6 +4653,59 @@ video.knit-preview-media{width:100%;background:#000}
4003
4653
  const [semBusy, setSemBusy] = React.useState(false)
4004
4654
  const [semNotice, setSemNotice] = React.useState('')
4005
4655
 
4656
+ /* ── v0.25:对话里「工具产出」的图 ─────────────────────────────────────
4657
+ 数据来自独立接口(只在本会话的 `tool/result` 事件里收集);**列表零 I/O**。
4658
+ 它们**不在工作区里**,所以是这一档唯一「不是文件」的条目:
4659
+ · 已经在工作区里存在同内容文件(sha256 相同)的 ⇒ 宿主侧就过滤掉了,不重复出现;
4660
+ · 一旦你把图存进项目,下一次轮询它就自己消失 —— 这就是用户要的那条规则。 */
4661
+ const [attachments, setAttachments] = React.useState([])
4662
+ /** 附件 → 伪文档:让它走**同一条**网格渲染/预览/键盘路径,不新开一套。 */
4663
+ const attachmentDocs = React.useMemo(() => (Array.isArray(attachments) ? attachments : [])
4664
+ .slice()
4665
+ .sort((a, b) => (Number.isFinite(b.at) ? b.at : 0) - (Number.isFinite(a.at) ? a.at : 0))
4666
+ .map((item) => ({
4667
+ rel: item.id,
4668
+ name: item.name,
4669
+ title: item.name,
4670
+ path: '',
4671
+ kind: item.kind === 'video' ? 'video' : 'image',
4672
+ mtimeMs: Number.isFinite(item.at) ? item.at : Date.now(),
4673
+ size: Number.isFinite(item.bytes) ? item.bytes : 0,
4674
+ summary: '',
4675
+ score: null,
4676
+ attachmentId: item.id,
4677
+ conversation: true,
4678
+ })), [attachments])
4679
+
4680
+ /* ── v0.25:媒体收藏(同样**追加在末尾**:替身按下标 seed useState/useRef)──────
4681
+ 只存 localStorage;工作区换了就重读那一格。写入时只保留最近 FAV_MAX_ROOTS 个工作区。 */
4682
+ const [favorites, setFavorites] = React.useState([])
4683
+ React.useEffect(() => {
4684
+ setFavorites(favoriteRelsFor(parseFavorites(readPref(FAV_KEY)), state.root))
4685
+ }, [state.root])
4686
+ const favoriteSet = React.useMemo(() => new Set(favorites), [favorites])
4687
+ /** 加 / 取消收藏,并立刻落盘。 */
4688
+ const toggleFavorite = React.useCallback((rel) => {
4689
+ const next = toggleFavoriteList(favorites, rel)
4690
+ setFavorites(next)
4691
+ const key = state.root || ''
4692
+ if (!key) return // 工作区未知 ⇒ 只活到这次会话结束,不写脏数据
4693
+ const table = parseFavorites(readPref(FAV_KEY))
4694
+ // 取消到空就把这一格**删掉**,不留 `{"<root>":[]}` 这种垃圾键
4695
+ if (next.length) table[key] = next
4696
+ else delete table[key]
4697
+ // 只保留最近几个工作区;**当前这个永远保留**(别把用户刚标的丢掉)
4698
+ const roots = Object.keys(table)
4699
+ while (roots.length > FAV_MAX_ROOTS) {
4700
+ const drop = roots.find((r) => r !== key)
4701
+ if (!drop) break
4702
+ delete table[drop]
4703
+ roots.splice(roots.indexOf(drop), 1)
4704
+ }
4705
+ writePref(FAV_KEY, JSON.stringify(table))
4706
+ }, [favorites, state.root])
4707
+
4708
+
4006
4709
  /* ── 曾经在这里的三个状态 + 一个 ref:右栏的形态 ──────────
4007
4710
  `packWidth`(310) / `packFloat`(null) / `packSnap`(false) / `packColRef`。
4008
4711
  **2026-09-29 随右栏一起删除**。当时它们**只存在内存里**(刷新回默认值),
@@ -4032,6 +4735,14 @@ video.knit-preview-media{width:100%;background:#000}
4032
4735
  才 bump)。原先每 5 s 都无条件落一个新对象:整屏重渲染一遍 + 一轮 FLIP 强制布局 +
4033
4736
  GC,用户体感就是「卡顿卡顿的」。签名存在状态自己身上,所以不需要新 hook
4034
4737
  (前面那些 hook 的位置被测试按位预置,别插队)。 */
4738
+ /* v0.25(2026-10-22 用户裁决):**媒体档不看相关性,一律按时间倒序**。
4739
+ 原话:「媒体这里不用跟随 Agent 读了它进行排序,目前就是以上传时间排序就可以,
4740
+ 最新的放在前面就够了……文档可以是调用,但是图片不需要有这种逻辑」。
4741
+
4742
+ ⇒ 请求**就是 time**(不只改显示):这样宿主不做无用的相关度计算、截断也按时间切。
4743
+ 排序偏好本身**不做修改** —— 切回文档/代码还是你原来选的那个。 */
4744
+ const effectiveSort = kind === KIND_MEDIA ? 'time' : sort
4745
+
4035
4746
  const load = React.useCallback(async (alive) => {
4036
4747
  const live = () => typeof alive !== 'function' || alive()
4037
4748
  if (!live()) return
@@ -4046,7 +4757,7 @@ video.knit-preview-media{width:100%;background:#000}
4046
4757
  // 而词法模式下宿主**一次 provider 调用都不会发**(方案 §9.2 判据 1)。
4047
4758
  // ⚠️ v0.25(第二轮修订):`/api/recent` 上**一个字节的变更关联都没有** ——
4048
4759
  // 它的响应形状与 v0.24 逐字相同。变更关联走**独立接口**,见下面那次 fetch。
4049
- const url = `${LIST_API}?sessionId=${encodeURIComponent(sessionId)}&limit=40&sort=${sort}&kind=${kind}&retrieval=${sort === 'relevance' && retrieval === 'hybrid' ? 'hybrid' : 'lexical'}${usageOn ? '&usage=1' : ''}`
4760
+ const url = `${LIST_API}?sessionId=${encodeURIComponent(sessionId)}&limit=40&sort=${effectiveSort}&kind=${kind}&retrieval=${effectiveSort === 'relevance' && retrieval === 'hybrid' ? 'hybrid' : 'lexical'}${usageOn ? '&usage=1' : ''}`
4050
4761
  const res = await fetch(url, { headers: { accept: 'application/json' }, cache: 'no-store' })
4051
4762
  const data = await res.json()
4052
4763
  if (!live()) return
@@ -4086,7 +4797,25 @@ video.knit-preview-media{width:100%;background:#000}
4086
4797
  · 只在「相关」序要它(时间序没有 Context Pack,变更关联无处可落);
4087
4798
  · 复用宿主刚刚那次扫描(服务端 8 s 同窗)⇒ 两个请求 = 一次扫描 + 一次 git;
4088
4799
  · 失败一律降级成 `null`(这一区消失),**绝不带坏列表** —— 列表已经落好了。 */
4089
- const wantChanges = sort === 'relevance' && changesOn
4800
+ // v0.25:媒体档额外取「对话里工具产出的图」。**只在这一档取** —— 别的档不显示它们。
4801
+ // 失败/老宿主没有这条路由 ⇒ 保持安静(列表为空),不弹错、不挡列表。
4802
+ if (kind === KIND_MEDIA) {
4803
+ try {
4804
+ const ares = await fetch(`${ATTACH_LIST_API}?sessionId=${encodeURIComponent(sessionId)}`, {
4805
+ headers: { accept: 'application/json' }, cache: 'no-store',
4806
+ })
4807
+ const adata = await ares.json()
4808
+ if (!live()) return
4809
+ if (adata && adata.ok && Array.isArray(adata.items)) {
4810
+ const items = adata.items
4811
+ // 一字未变就返回**同一个数组**(与列表同一套去重理由:省一次整屏重渲染)
4812
+ setAttachments((prev) => (prev.length === items.length
4813
+ && items.every((item, i) => item && prev[i] && item.id === prev[i].id) ? prev : items))
4814
+ }
4815
+ } catch { /* 安静:这一档少几张图,不影响文件列表 */ }
4816
+ }
4817
+
4818
+ const wantChanges = effectiveSort === 'relevance' && changesOn
4090
4819
  if (!wantChanges) {
4091
4820
  setChangesData((prev) => (prev === null ? prev : null))
4092
4821
  return
@@ -4389,7 +5118,19 @@ video.knit-preview-media{width:100%;background:#000}
4389
5118
  * 否则「其他相关文档」区里的条目键盘到不了,而已经在 Related 层里的条目
4390
5119
  * 会被算两次。(媒体档走的是网格,`visibleDocs` 就是那批媒体。)
4391
5120
  */
4392
- const navDocs = contextView ? contextView.flat : visibleDocs
5121
+ /* v0.25:媒体档的「可见条目」= 收藏在前 + 对话里生成的 + 其余。
5122
+ `navDocs` 也用它 —— 否则键盘导航会把对话里那几张**跳过去**(看得见、走不到)。
5123
+ 收藏仍然排在最前:这一条没变,只是把「还没存进项目的图」插在收藏之后。 */
5124
+ const mediaDocs = React.useMemo(() => {
5125
+ /* 媒体档的**唯一**顺序:按时间倒序(最新在前)。文档/代码才看相关性。
5126
+ 工作区文件用 `mtimeMs`,对话里生成的图用事件时间(`at` → 伪文档的 `mtimeMs`)——
5127
+ 两者同一条时间轴,所以「刚生成的」自然在最前;存进项目后它变成文件、时间也还在附近。
5128
+ 收藏仍然前移(`orderFavorites` 是**稳定**分区 ⇒ 两组内部都还是时间倒序)。 */
5129
+ const byTimeDesc = (a, b) => (Number.isFinite(b.mtimeMs) ? b.mtimeMs : 0) - (Number.isFinite(a.mtimeMs) ? a.mtimeMs : 0)
5130
+ const merged = (Array.isArray(visibleDocs) ? visibleDocs : []).concat(attachmentDocs)
5131
+ return orderFavorites(merged.slice().sort(byTimeDesc), favoriteSet)
5132
+ }, [visibleDocs, favoriteSet, attachmentDocs])
5133
+ const navDocs = kind === KIND_MEDIA && !contextView ? mediaDocs : (contextView ? contextView.flat : visibleDocs)
4393
5134
 
4394
5135
  // cursor 消失(被过滤掉 / 被上限截断 / 列表刷新)时落回第一项
4395
5136
  React.useEffect(() => {
@@ -4442,7 +5183,9 @@ video.knit-preview-media{width:100%;background:#000}
4442
5183
  anchor: anchor || null, anchorSeq: 0,
4443
5184
  }
4444
5185
  if (isMedia(doc)) {
4445
- return { ...base, kind: doc.kind, src: mediaUrl(sessionId, doc.rel), status: 'ready' }
5186
+ // v0.25:对话里生成的图走 sha256 那条地址(它没有工作区路径)
5187
+ const src = doc.attachmentId ? attachmentUrl(sessionId, doc.attachmentId) : mediaUrl(sessionId, doc.rel)
5188
+ return { ...base, kind: doc.kind, src, status: 'ready' }
4446
5189
  }
4447
5190
  return { ...base, kind: doc.kind || ARTIFACT_DOC, status: 'loading' }
4448
5191
  }, [sessionId])
@@ -4510,6 +5253,75 @@ video.knit-preview-media{width:100%;background:#000}
4510
5253
  * (这里以前一律传 `docLayout.columns`,而文档列数与媒体列数根本不是一回事 ——
4511
5254
  * 媒体档的 ←→ 一直是按文档的 2 列在走。改动顺便把它对齐了。)
4512
5255
  */
5256
+ /* ── v0.25:媒体档「双击全屏」(**追加在末尾**:替身按下标 seed useState/useRef)
5257
+ 存的是 `rel` 而不是下标 —— 列表每 5 秒会换一份,下标会漂;`rel` 不会。
5258
+ 列表里找不到它了(被删 / 被存进项目 / 切了档)就自己关掉。 */
5259
+ const [lightboxRel, setLightboxRel] = React.useState('')
5260
+ const lightboxRef = React.useRef(null)
5261
+ const lightboxIndex = React.useMemo(
5262
+ () => (lightboxRel ? mediaDocs.findIndex((doc) => doc.rel === lightboxRel) : -1),
5263
+ [mediaDocs, lightboxRel],
5264
+ )
5265
+ const lightboxDoc = lightboxIndex >= 0 ? mediaDocs[lightboxIndex] : null
5266
+ const lightboxRailView = React.useMemo(
5267
+ () => lightboxRail(mediaDocs, lightboxIndex),
5268
+ [mediaDocs, lightboxIndex],
5269
+ )
5270
+ React.useEffect(() => {
5271
+ if (lightboxRel && lightboxIndex < 0) setLightboxRel('')
5272
+ }, [lightboxRel, lightboxIndex])
5273
+ const lightboxOpen = React.useCallback((doc) => {
5274
+ if (!doc || doc.kind !== 'image') return
5275
+ setLightboxRel(doc.rel)
5276
+ // 悬停浮窗这时必须收掉:它在查看器下面,留着就是两层大字
5277
+ if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
5278
+ hoverTimerRef.current = 0
5279
+ setHoverShot(null)
5280
+ }, [])
5281
+ const lightboxClose = React.useCallback(() => setLightboxRel(''), [])
5282
+ /* 翻到第 9 张时,左列如果溢出,当前那张会被留在视野外 —— 每次换图都把它**滚进来**
5283
+ (`block:'nearest'`:已经在视野里就一格都不动,不会抖)。没有 DOM 就跳过。 */
5284
+ const lightboxRailRef = React.useRef(null)
5285
+ React.useEffect(() => {
5286
+ if (!lightboxRel) return
5287
+ const rail = lightboxRailRef.current
5288
+ if (!rail || typeof rail.querySelector !== 'function') return
5289
+ const active = rail.querySelector('.knit-lightbox-thumb.active')
5290
+ if (active && typeof active.scrollIntoView === 'function') {
5291
+ try { active.scrollIntoView({ block: 'nearest' }) } catch { /* 老浏览器:算了,不影响换图 */ }
5292
+ }
5293
+ }, [lightboxRel])
5294
+ /** 查看器里的「本地打开」:与预览头同一条宿主通道,只是路径从 rel 现算。 */
5295
+ const lightboxAbs = lightboxDoc
5296
+ ? (lightboxDoc.path || joinPath(state.hostRoot || state.root, lightboxDoc.rel))
5297
+ : ''
5298
+ const lightboxOpenLocal = React.useCallback(async () => {
5299
+ setNotice((await openLocalPath(lightboxAbs)) || '')
5300
+ }, [lightboxAbs])
5301
+ /* 打开时把焦点交给遮罩:键盘用户一进来 Esc / ← → 就该能用(真机才有 DOM)。 */
5302
+ React.useLayoutEffect(() => {
5303
+ if (!lightboxRel) return
5304
+ const node = lightboxRef.current
5305
+ if (node && typeof node.focus === 'function') node.focus()
5306
+ }, [lightboxRel])
5307
+ /**
5308
+ * 在带子里前后翻(环绕)。
5309
+ *
5310
+ * ⚠️ 必须用**函数式更新**从「当前 state」推下一步,不能读渲染时捕获的 `lightboxIndex`:
5311
+ * 连着按两下 → 如果两下都落在同一次渲染的闭包里,第二下会用**陈旧的下标**再算一遍,
5312
+ * 结果只前进一格(证伪时就是这么抓到的)。现在每一步都以「此刻的 rel」为起点。
5313
+ */
5314
+ const lightboxStep = React.useCallback((delta) => {
5315
+ if (!mediaDocs.length) return
5316
+ setLightboxRel((current) => {
5317
+ const at = mediaDocs.findIndex((doc) => doc.rel === current)
5318
+ const from = at >= 0 ? at : 0
5319
+ const next = (from + (delta < 0 ? -1 : 1) + mediaDocs.length) % mediaDocs.length
5320
+ const doc = mediaDocs[next]
5321
+ return doc ? doc.rel : current
5322
+ })
5323
+ }, [mediaDocs])
5324
+
4513
5325
  const onListKeyDown = React.useCallback((event) => {
4514
5326
  if (navDocs.length === 0) return
4515
5327
  const index = navDocs.findIndex((doc) => doc.rel === cursor)
@@ -4521,13 +5333,21 @@ video.knit-preview-media{width:100%;background:#000}
4521
5333
  if (target >= 0) {
4522
5334
  event.preventDefault()
4523
5335
  const doc = navDocs[target]
4524
- if (doc) { setCursor(doc.rel); openPreview(doc) }
5336
+ if (doc) {
5337
+ setCursor(doc.rel)
5338
+ // 媒体档不做就地预览(2026-10-22 用户裁决):方向键只移光标,看大图用 Enter / 双击
5339
+ if (kind !== KIND_MEDIA) openPreview(doc)
5340
+ }
4525
5341
  return
4526
5342
  }
4527
5343
  if (event.key === 'Enter') {
4528
5344
  event.preventDefault()
4529
5345
  const doc = navDocs.find((d) => d.rel === cursor) || navDocs[0]
4530
- if (doc) togglePreview(doc)
5346
+ if (doc) {
5347
+ // 与双击同一套分流(键盘不能比鼠标少一条路)
5348
+ if (kind === KIND_MEDIA && doc.kind === 'image') lightboxOpen(doc)
5349
+ else togglePreview(doc)
5350
+ }
4531
5351
  return
4532
5352
  }
4533
5353
  if (event.key === 'Escape') {
@@ -4535,7 +5355,7 @@ video.knit-preview-media{width:100%;background:#000}
4535
5355
  if (fullscreen) setFullscreen(false)
4536
5356
  else closePreview()
4537
5357
  }
4538
- }, [navDocs, cursor, fullscreen, kind, mediaLayout.columns, openPreview, togglePreview, closePreview])
5358
+ }, [navDocs, cursor, fullscreen, kind, mediaLayout.columns, openPreview, togglePreview, closePreview, lightboxOpen])
4539
5359
 
4540
5360
  /** 拖拽预览面板上缘改变高度。 */
4541
5361
  const onResizeStart = React.useCallback((event) => {
@@ -4744,7 +5564,10 @@ video.knit-preview-media{width:100%;background:#000}
4744
5564
  }, [])
4745
5565
 
4746
5566
  /** 媒体条目的同源字节地址(缩略图 / 就地预览)。 */
4747
- const srcFor = React.useCallback((doc) => mediaUrl(sessionId, doc.rel), [sessionId])
5567
+ const srcFor = React.useCallback(
5568
+ (doc) => (doc.attachmentId ? attachmentUrl(sessionId, doc.attachmentId) : mediaUrl(sessionId, doc.rel)),
5569
+ [sessionId],
5570
+ )
4748
5571
 
4749
5572
  /**
4750
5573
  * 切换检索模式并记住偏好。**只切偏好**:真正的 provider 调用发生在宿主侧,
@@ -5069,7 +5892,21 @@ video.knit-preview-media{width:100%;background:#000}
5069
5892
  passage: firstMatchOf(doc),
5070
5893
  onPassage: openPassage,
5071
5894
  }
5072
- if (isMedia(doc)) return h(MediaCard, { ...common, src: srcFor(doc) })
5895
+ if (isMedia(doc)) {
5896
+ return h(MediaCard, {
5897
+ ...common,
5898
+ /* 单击**只移光标**(`active` 不再亮、下方不再弹预览)——
5899
+ 这是用户 2026-10-22 明确要撤掉的那个交互。 */
5900
+ onSelect: () => setCursor(doc.rel),
5901
+ onPreview: togglePreview,
5902
+ src: srcFor(doc),
5903
+ favorite: favoriteSet.has(doc.rel),
5904
+ conversation: Boolean(doc.conversation),
5905
+ onHoverStart: hoverStart,
5906
+ onHoverEnd: hoverEnd,
5907
+ onZoom: lightboxOpen,
5908
+ })
5909
+ }
5073
5910
  // `whyText` 只认 Context Pack 条目上挂的 `reason` —— 平铺列表里没有这个字段,
5074
5911
  // 于是返回空串,那一行不渲染。
5075
5912
  // `num` / `primary` 只有分层视图会传(Design §11 / §13);平铺列表照旧无序号。
@@ -5115,7 +5952,10 @@ video.knit-preview-media{width:100%;background:#000}
5115
5952
  : kind === KIND_CODE
5116
5953
  ? t('list.emptyCode')
5117
5954
  : t('list.empty')
5118
- const body = state.status === 'loading' && state.docs.length === 0
5955
+ /* ⚠️ 为什么是**函数**而不是常量:这里要读「面板末尾才声明」的状态(媒体收藏)。
5956
+ 写成常量会在这一行就求值 ⇒ TDZ(`Cannot access 'favoriteSet' before initialization`)。
5957
+ 包成函数、在 return 里调用一次,既不改渲染结果,也不会再被后面的新状态绊倒。 */
5958
+ const listBody = () => (state.status === 'loading' && state.docs.length === 0
5119
5959
  ? h('div', { className: 'knit-msg' }, t('list.scanning'))
5120
5960
  : state.status === 'error'
5121
5961
  ? h('div', { className: 'knit-msg' }, t('list.failed', { error: state.error }), h('br'), t('list.failedHint'))
@@ -5124,10 +5964,10 @@ video.knit-preview-media{width:100%;background:#000}
5124
5964
  : visibleDocs.length === 0
5125
5965
  ? h('div', { className: 'knit-msg' }, t('list.noMatch', { query: query.trim() }))
5126
5966
  : kind === KIND_MEDIA
5127
- ? mediaGrid(visibleDocs)
5967
+ ? mediaGrid(mediaDocs)
5128
5968
  : contextView
5129
5969
  ? contextBody(contextView)
5130
- : docsGrid(withGhosts(MOTION_TIER_FLAT, visibleDocs))
5970
+ : docsGrid(withGhosts(MOTION_TIER_FLAT, visibleDocs)))
5131
5971
 
5132
5972
  // 排序说明那一行(.knit-topic)**2026-09-30 已整体删除**:排序方式由头部那个
5133
5973
  // 「相关 / 最新」切换按钮自己表达(按钮上就写着当前选的是哪个),再补一句
@@ -5643,9 +6483,184 @@ video.knit-preview-media{width:100%;background:#000}
5643
6483
  ? state.control.excluded.filter((item) => item.exists)
5644
6484
  : []
5645
6485
 
6486
+ /* ── v0.25:预览里的查找(Cmd+F)──────────────────────────────────────
6487
+ ⚠️ **这一整块必须留在组件末尾** —— 测试替身按**下标**预置 useState/useRef 的初值
6488
+ (`harness.seed`),而只有 useState/useRef 占槽位。插在中间会把后面每一个槽位
6489
+ 整体挪位,`seeded[15]` 那条就直接落到别的状态上(上一轮 `changesOn` 已经踩过一次,
6490
+ 这次的 `query.trim is not a function` 是第二次)。新钩子一律**追加在最后**。
6491
+
6492
+ /* ── v0.25:预览里的查找(Cmd+F)──────────────────────────────────────
6493
+ 状态放在**这一层**而不是 PreviewPanel:快捷键挂在面板根上(见
6494
+ `onRootKeyDownCapture`)—— 焦点通常在左边那个列表上(↑↓ 开着预览),
6495
+ 挂在 `.knit-preview` 上根本收不到那个事件。
6496
+ `findSeq` 只在**显式导航**时 +1(打开 / 输入 / 上一下一个),它是「要不要滚」的唯一开关:
6497
+ 5 秒轮询会重画命中,**但绝不滚动** —— 否则用户读到一半每 5 秒被拽回去一次
6498
+ (AGENTS.md §6.13 ② 那个「列表自己跳」的坑,同一个道理)。 */
6499
+ const [findOn, setFindOn] = React.useState(false)
6500
+ const [findQuery, setFindQuery] = React.useState('')
6501
+ const [findIndex, setFindIndex] = React.useState(0)
6502
+ const [findSeq, setFindSeq] = React.useState(0)
6503
+ const [findCount, setFindCount] = React.useState(0)
6504
+ const findMarksRef = React.useRef([])
6505
+ const findInputRef = React.useRef(null)
6506
+ const previewBodyRef = React.useRef(null)
6507
+
6508
+ /* 关掉预览就关掉查找(否则下次打开会带着上一次的关键词与一树残留标记)。 */
6509
+ React.useEffect(() => {
6510
+ if (preview) return
6511
+ setFindOn(false)
6512
+ setFindQuery('')
6513
+ }, [preview])
6514
+
6515
+ /* 画命中 —— 开关 / 关键词 / 这一篇的内容,任一变了就重画。
6516
+ ⚠️ 依赖里没有轮询刷出来的数组;`preview` 换了一篇或文件被改过就重画一次,
6517
+ 但**不滚** —— 滚动只由 `findSeq` 那条 effect 负责。 */
6518
+ React.useLayoutEffect(() => {
6519
+ const box = previewBodyRef.current
6520
+ clearFindMarks(box)
6521
+ findMarksRef.current = []
6522
+ if (!box || !findOn || !findQuery) {
6523
+ setFindCount(0)
6524
+ return
6525
+ }
6526
+ const marks = paintFindMarks(box, findQuery)
6527
+ findMarksRef.current = marks
6528
+ setFindCount(marks.length)
6529
+ }, [findOn, findQuery, preview && preview.rel, preview && preview.text])
6530
+
6531
+ /* 标出「当前这一条」并滚到它。
6532
+ ⚠️ **只依赖 `findSeq`**(显式导航才 +1)、命中数组走 ref 读:把重画当成「用户动了光标」,
6533
+ 就会每 5 秒把用户读到一半的视图拽回去一次(§6.13 ② 那条坑,同一个道理)。 */
6534
+ React.useLayoutEffect(() => {
6535
+ const marks = findMarksRef.current
6536
+ if (!findOn || !marks.length) return
6537
+ const index = Math.min(Math.max(0, findIndex), marks.length - 1)
6538
+ markFindCurrent(marks, index)
6539
+ scrollMarkIntoView(marks[index])
6540
+ }, [findSeq])
6541
+
6542
+ /* 打开后把焦点交给输入框(挂上去之后再 focus)。 */
6543
+ React.useLayoutEffect(() => {
6544
+ if (!findOn) return
6545
+ const input = findInputRef.current
6546
+ if (input && typeof input.focus === 'function') input.focus()
6547
+ }, [findOn])
6548
+
6549
+ /**
6550
+ * 打开查找条并把焦点给它。
6551
+ *
6552
+ * 两条入口都用它:**Cmd+F**(焦点在面板里时),以及预览头那个**「查找」按钮** ——
6553
+ * 后者是兜底:外层应用的原生快捷键在按键进入网页之前就被它自己处理了,网页侧抢不回来。
6554
+ * 已经开着时 `findOn` 不变、聚焦那条 effect 不会再跑,所以这里就地补一次 focus。
6555
+ */
6556
+ const openFind = React.useCallback(() => {
6557
+ setFindOn(true)
6558
+ const input = findInputRef.current
6559
+ if (input && typeof input.focus === 'function') input.focus()
6560
+ }, [])
6561
+
6562
+ /** 关掉查找条(不清正文内容,也不动预览)。 */
6563
+ const closeFind = React.useCallback(() => {
6564
+ setFindOn(false)
6565
+ setFindQuery('')
6566
+ }, [])
6567
+
6568
+ /** 上一个 / 下一个(环绕)。 */
6569
+ const findStep = React.useCallback((delta) => {
6570
+ const total = findMarksRef.current.length
6571
+ if (!total) return
6572
+ setFindIndex((current) => stepFindIndex(current, total, delta))
6573
+ setFindSeq((n) => n + 1)
6574
+ }, [])
6575
+
6576
+ /** 改关键词:回到第一条命中并滚过去(与 Chrome 一致)。 */
6577
+ const onFindQuery = React.useCallback((value) => {
6578
+ setFindQuery(value)
6579
+ setFindIndex(0)
6580
+ setFindSeq((n) => n + 1)
6581
+ }, [])
6582
+
6583
+ /**
6584
+ * 面板根上的**捕获阶段**键盘处理。
6585
+ *
6586
+ * 为什么是「这一层」:焦点通常在左边那个列表上(↑↓ 打开预览),把快捷键挂在
6587
+ * `.knit-preview` 上收不到那个事件(事件从列表冒泡,不经过预览)。
6588
+ * 为什么是「捕获」:列表自己有 Esc(关预览 / 退全屏),而查找开着时 Esc 的语义
6589
+ * 应当是**先关查找条** —— 捕获先于子节点执行,这里 stopPropagation 就把它拦下了。
6590
+ *
6591
+ * 只拦两件事(Cmd/Ctrl+F、查找开着时的 Esc),其余一律放行:不抢输入框、不抢列表方向键。
6592
+ */
6593
+ const onRootKeyDownCapture = React.useCallback((event) => {
6594
+ if (!event) return
6595
+ // ⚠️ 查看器是**最上层**:它开着时 Esc / ← / → 先归它(不许漏到列表的键盘导航上)
6596
+ if (lightboxRel) {
6597
+ if (event.key === 'Escape') {
6598
+ event.preventDefault(); event.stopPropagation(); lightboxClose(); return
6599
+ }
6600
+ /* 左列是**竖排**的,所以 ↑↓ 必须能用(用户 2026-10-22 追加要求);
6601
+ ←→ 一并留着 —— 有人就是习惯左右翻,两条路没有冲突。 */
6602
+ if (event.key === 'ArrowRight' || event.key === 'ArrowLeft'
6603
+ || event.key === 'ArrowDown' || event.key === 'ArrowUp') {
6604
+ event.preventDefault(); event.stopPropagation()
6605
+ const back = event.key === 'ArrowLeft' || event.key === 'ArrowUp'
6606
+ lightboxStep(back ? -1 : 1)
6607
+ return
6608
+ }
6609
+ }
6610
+ const mod = !!(event.metaKey || event.ctrlKey)
6611
+ if (mod && !event.altKey && String(event.key || '').toLowerCase() === 'f') {
6612
+ // 媒体档没有可搜的正文 ⇒ 不拦,交回宿主 / 浏览器自己的行为
6613
+ if (!preview || preview.kind === 'image' || preview.kind === 'video') return
6614
+ event.preventDefault()
6615
+ event.stopPropagation()
6616
+ openFind()
6617
+ return
6618
+ }
6619
+ if (event.key === 'Escape' && findOn) {
6620
+ event.preventDefault()
6621
+ event.stopPropagation()
6622
+ setFindOn(false)
6623
+ setFindQuery('')
6624
+ }
6625
+ }, [preview, findOn, openFind, lightboxRel, lightboxClose, lightboxStep])
6626
+
6627
+ /* ── v0.25:媒体档「悬停看大图」(同样**追加在末尾**:替身按下标 seed useState/useRef)
6628
+ 只对图片;停 HOVER_SHOT_DELAY_MS 才出现;离开 / 滚动 / 换档立刻收。 */
6629
+ const [hoverShot, setHoverShot] = React.useState(null)
6630
+ const hoverTimerRef = React.useRef(0)
6631
+ const hoverStart = React.useCallback((doc, src, event) => {
6632
+ if (!doc || doc.kind !== 'image' || !src) return
6633
+ if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
6634
+ // 矩形从事件里取(真机有 currentTarget);取不到就交给纯函数走「视口居中」那条路
6635
+ let rect = null
6636
+ try {
6637
+ const el = event && event.currentTarget
6638
+ if (el && typeof el.getBoundingClientRect === 'function') rect = el.getBoundingClientRect()
6639
+ } catch { rect = null }
6640
+ const view = {
6641
+ width: typeof window !== 'undefined' && Number.isFinite(window.innerWidth) ? window.innerWidth : 1024,
6642
+ height: typeof window !== 'undefined' && Number.isFinite(window.innerHeight) ? window.innerHeight : 768,
6643
+ }
6644
+ const box = hoverShotBox(rect, view)
6645
+ hoverTimerRef.current = setTimeout(() => {
6646
+ hoverTimerRef.current = 0
6647
+ setHoverShot({ rel: doc.rel, src, box })
6648
+ }, HOVER_SHOT_DELAY_MS)
6649
+ }, [])
6650
+ const hoverEnd = React.useCallback(() => {
6651
+ if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
6652
+ hoverTimerRef.current = 0
6653
+ setHoverShot((prev) => (prev ? null : prev))
6654
+ }, [])
6655
+ React.useEffect(() => () => {
6656
+ if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
6657
+ }, [])
6658
+
5646
6659
  return h('div', {
5647
6660
  className: `knit-root${fullscreen ? ' fullscreen' : ''}`,
5648
6661
  ref: rootRef,
6662
+ // v0.25 查找:捕获阶段(要抢在列表的 Esc 之前,见 onRootKeyDownCapture 的注释)
6663
+ onKeyDownCapture: onRootKeyDownCapture,
5649
6664
  },
5650
6665
  h('div', { className: 'knit-head' },
5651
6666
  h('button', {
@@ -5676,16 +6691,22 @@ video.knit-preview-media{width:100%;background:#000}
5676
6691
  ② 搜索排最后、贴最右:它只过滤当前列表,不重置排序与类型(§三.3)。
5677
6692
  ③ 六个选项彼此独立 —— 选「代码」再选「最新」= 最新的代码。
5678
6693
  顺序即控件顺序,别再挪(细则在 CSS 那边的 .knit-bar / .knit-filter 注释里)。 */
6694
+ /* v0.25(2026-10-22 用户裁决):**媒体档不看相关性** ⇒ 这一组在那一档禁用,
6695
+ 并且**如实显示「最新」在生效**(显示的是「当前实际顺序」,不是存着的偏好)。
6696
+ 偏好本身不动:切回文档/代码还是你原来选的那个。
6697
+ ⚠️ 是「禁用」不是「删掉」:控件不消失,布局不跳,鼠标悬停也有一句解释。 */
5679
6698
  h('div', { className: 'knit-seg' },
5680
6699
  h('button', {
5681
- className: `knit-seg-btn${sort === 'relevance' ? ' active' : ''}`,
6700
+ className: `knit-seg-btn${effectiveSort === 'relevance' ? ' active' : ''}`,
5682
6701
  onClick: () => pickSort('relevance'),
5683
- title: t('sort.relevanceTitle'),
6702
+ disabled: kind === KIND_MEDIA,
6703
+ title: kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.relevanceTitle'),
5684
6704
  }, t('sort.relevance')),
5685
6705
  h('button', {
5686
- className: `knit-seg-btn${sort === 'time' ? ' active' : ''}`,
6706
+ className: `knit-seg-btn${effectiveSort === 'time' ? ' active' : ''}`,
5687
6707
  onClick: () => pickSort('time'),
5688
- title: t('sort.timeTitle'),
6708
+ disabled: kind === KIND_MEDIA,
6709
+ title: kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.timeTitle'),
5689
6710
  }, t('sort.time'))),
5690
6711
  // ⚠️ 2026-10-12 用户裁决:排序组与类型组之间**那根竖线去掉了** —— 它的类名与 CSS 规则都已整体删除。
5691
6712
  // 两组靠 `.knit-bar` 的 gap 分开就够 —— 「边界」不再需要一根线来表达。
@@ -5767,6 +6788,8 @@ video.knit-preview-media{width:100%;background:#000}
5767
6788
  ref: listRef,
5768
6789
  tabIndex: 0,
5769
6790
  onKeyDown: onListKeyDown,
6791
+ // v0.25:滚动就收起悬停大图 —— 它是 fixed 定位,不跟着卡片走,留着只会错位
6792
+ onScroll: hoverEnd,
5770
6793
  role: 'listbox',
5771
6794
  'aria-label': t('list.aria'),
5772
6795
  // 焦点始终在容器上(roving 焦点会打断「移动即预览」),
@@ -5775,7 +6798,7 @@ video.knit-preview-media{width:100%;background:#000}
5775
6798
  'aria-activedescendant': navDocs.some((doc) => doc.rel === cursor)
5776
6799
  ? docOptionId(navDocs.find((doc) => doc.rel === cursor))
5777
6800
  : undefined,
5778
- }, body)
6801
+ }, listBody())
5779
6802
  /* ── 曾经在这里的一层:双栏装配 ────────────────────────
5780
6803
  `if (!contextView) return listNode` 之后是 `.knit-context-layout`
5781
6804
  (两列网格:左 `.knit-col-list` + 右 `.knit-context-column`)、
@@ -5794,6 +6817,22 @@ video.knit-preview-media{width:100%;background:#000}
5794
6817
  pathImages,
5795
6818
  fullscreen,
5796
6819
  ratio,
6820
+ // v0.25 查找:状态在 KnitBody,正文容器 ref 也交出去给 DOM 绘制用
6821
+ find: {
6822
+ on: findOn,
6823
+ query: findQuery,
6824
+ index: findIndex,
6825
+ count: findCount,
6826
+ inputRef: findInputRef,
6827
+ onOpen: openFind,
6828
+ onQuery: onFindQuery,
6829
+ onStep: findStep,
6830
+ onClose: closeFind,
6831
+ },
6832
+ bodyRef: previewBodyRef,
6833
+ // v0.25 媒体收藏
6834
+ favorite: favoriteSet.has(preview.rel),
6835
+ onToggleFavorite: toggleFavorite,
5797
6836
  // v0.12 引用条
5798
6837
  links,
5799
6838
  linksExpanded,
@@ -5819,7 +6858,93 @@ video.knit-preview-media{width:100%;background:#000}
5819
6858
  onClose: closePreview,
5820
6859
  onToggleFullscreen: () => setFullscreen((v) => !v),
5821
6860
  onResizeStart,
5822
- }) : null)
6861
+ }) : null,
6862
+ /* v0.25:媒体档「悬停看大图」。`position:fixed` + CSS 的 `pointer-events:none` ——
6863
+ 它只是「看一眼」:不参与布局、不挡点击、不抢焦点。盒子由 `hoverShotBox()` 算好。 */
6864
+ hoverShot
6865
+ ? h('div', {
6866
+ className: 'knit-shot',
6867
+ style: {
6868
+ left: `${hoverShot.box.left}px`,
6869
+ top: `${hoverShot.box.top}px`,
6870
+ width: `${hoverShot.box.width}px`,
6871
+ height: `${hoverShot.box.height}px`,
6872
+ },
6873
+ }, h('img', { src: hoverShot.src, alt: '', draggable: false }))
6874
+ : null,
6875
+ /* v0.25:媒体档「双击全屏」查看器。
6876
+ · 点**图片以外**(遮罩)⇒ 关;点图片本身 ⇒ 不关(`stopPropagation`),
6877
+ 否则「点一下想看清细节」就把查看器点没了;
6878
+ · 左侧一列缩略图(当前这张附近 10 张)——点它换图,也不许冒泡去关;
6879
+ · `role="dialog"` + `aria-modal` + 可聚焦:Esc / ← → 由根上的捕获阶段接管。 */
6880
+ lightboxDoc
6881
+ ? mountLightbox(h('div', {
6882
+ className: 'knit-lightbox',
6883
+ role: 'dialog',
6884
+ 'aria-modal': 'true',
6885
+ 'aria-label': t('lightbox.aria', { name: lightboxDoc.name || lightboxDoc.rel }),
6886
+ tabIndex: 0,
6887
+ ref: lightboxRef,
6888
+ onClick: lightboxClose,
6889
+ },
6890
+ h('div', {
6891
+ className: 'knit-lightbox-rail',
6892
+ ref: lightboxRailRef,
6893
+ onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
6894
+ }, lightboxRailView.items.map((doc, i) => h('button', {
6895
+ key: doc.rel,
6896
+ type: 'button',
6897
+ className: `knit-lightbox-thumb${doc.rel === lightboxDoc.rel ? ' active' : ''}`,
6898
+ title: doc.name || doc.rel,
6899
+ 'data-thumb-index': lightboxRailView.start + i,
6900
+ onClick: () => setLightboxRel(doc.rel),
6901
+ }, h('img', { src: srcFor(doc), alt: '', draggable: false })))),
6902
+ /* 查看器工具条:「收藏」「本地打开」原来只活在**被撤掉的**媒体预览头里 ——
6903
+ 不搬过来就等于静默丢掉两个功能(用户 2026-10-21 明确要过「收藏排第一」)。
6904
+ 收藏只对工作区文件有意义(对话里的图还没有路径),所以对话图不显示这一条。 */
6905
+ h('div', { className: 'knit-lightbox-tools' },
6906
+ lightboxDoc.conversation
6907
+ ? null
6908
+ : h('button', {
6909
+ className: 'knit-btn',
6910
+ type: 'button',
6911
+ onClick: () => toggleFavorite(lightboxDoc.rel),
6912
+ title: favoriteSet.has(lightboxDoc.rel) ? t('fav.removeTitle') : t('fav.addTitle'),
6913
+ }, favoriteSet.has(lightboxDoc.rel) ? t('fav.on') : t('fav.off')),
6914
+ lightboxDoc.conversation
6915
+ ? null
6916
+ : h('button', {
6917
+ className: 'knit-btn',
6918
+ type: 'button',
6919
+ onClick: lightboxOpenLocal,
6920
+ title: t('preview.openLocal', { path: lightboxDoc.rel }),
6921
+ }, t('preview.openLocalBtn'))),
6922
+ /* 右上角 ✕ —— 照 DSH 自带查看器那套(全屏之后必须有一个**看得见的**出口:
6923
+ 光靠「点图片以外」和 Esc,第一次用的人不知道往哪点)。 */
6924
+ h('button', {
6925
+ className: 'knit-lightbox-close',
6926
+ type: 'button',
6927
+ title: t('lightbox.close'),
6928
+ 'aria-label': t('lightbox.close'),
6929
+ onClick: () => lightboxClose(),
6930
+ }, '✕'),
6931
+ /* 滚轮翻页:只在**图片这一块**生效。左列自己会滚(它 overflow-y:auto),
6932
+ 在它上面滚轮应该滚列表,而不是换图 —— 所以监听挂在 stage 上、不挂在遮罩上。 */
6933
+ h('div', {
6934
+ className: 'knit-lightbox-stage',
6935
+ onWheel: (event) => {
6936
+ const delta = event && (event.deltaY || event.deltaX)
6937
+ if (!delta) return
6938
+ lightboxStep(delta > 0 ? 1 : -1)
6939
+ },
6940
+ }, h('img', {
6941
+ className: 'knit-lightbox-img',
6942
+ src: srcFor(lightboxDoc),
6943
+ alt: lightboxDoc.name || '',
6944
+ draggable: false,
6945
+ onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
6946
+ }))))
6947
+ : null)
5823
6948
  }
5824
6949
 
5825
6950
  /* ── 会话入口按钮 ───────────────────────────────── */