@li-canghai/dsh-paper 0.8.0 → 0.8.2

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/lib/client.js CHANGED
@@ -575,14 +575,26 @@ function createLibraryModel() {
575
575
  return { tex, tag: typeof block.math?.tag === 'string' ? block.math.tag : '' }
576
576
  }
577
577
 
578
- /** 行内片段的稳定 key:块 id + 下标就够定位,同一块的两段各自的片段也不会撞。 */
578
+ /**
579
+ * 行内片段的稳定 key:块 id + 下标就够定位,同一块的两段各自的片段也不会撞。
580
+ *
581
+ * 🔴 **必须把 raw / items 原样带过来**:这两个字段由 {@link inlineRefs} 给多标号
582
+ * (`[41, 44, 13, 16]`)产出好后,这一层是通往悬停预览的**唯一通道**。
583
+ * 早先只复制 key/type/value/text,它们在这里被静默丢掉 —— 下游 {@link paintCiteSpans}
584
+ * 于是退回用 value 拼 `[41,44,13,16]`(无空格)去正文里找,而页面上真实的字带空格,
585
+ * 结果单编号 `[23]` 能悬停、多标号一律没反应。丢字段不报错,所以肉眼查不出来。
586
+ */
579
587
  function inlinePart(part, index, at) {
580
- return {
588
+ const shape = {
581
589
  key: `${index}-${at}-${part.type}-${part.value ?? ''}`,
582
590
  type: part.type,
583
591
  value: part.value ?? '',
584
592
  text: part.text ?? '',
585
593
  }
594
+ // 单编号不带这两项时**不补空值**:既有断言按字段全等,多一个 raw: undefined 也会红。
595
+ if (part.raw !== undefined) shape.raw = part.raw
596
+ if (part.items !== undefined) shape.items = part.items
597
+ return shape
586
598
  }
587
599
 
588
600
  // 阅读器布局(D46 + D75):右栏未展开 —— 或读不到展开状态 —— 恒定单栏,这时宽度再大也不并排;
@@ -759,6 +771,60 @@ function createLibraryModel() {
759
771
  * @returns {Map<string, object[]>} blockId → 该块的划线,按面板顺序。
760
772
  */
761
773
 
774
+ /**
775
+ * 将 PDF 原生字形宽度和后继词的物理空隙分别映射到 CSS。
776
+ * 不能把 (字框 + gap) 一起分摊给字形:这会把本词最后一个字母推向下一个词,
777
+ * 而浏览器的选区、插入光标又按实际字形推进量走,最终表现为蓝色选区水平偏移。
778
+ *
779
+ * 有尾空格时,letter-spacing 也会作用于这个空格,所以 word-spacing 必须减掉它。
780
+ * 返回的长度遵循:字形 = wordWidth;字形 + 尾空格 = wordWidth + gap。
781
+ */
782
+ function pdfWordMetrics(text, wordWidth, gap, measure) {
783
+ const raw = String(text ?? '')
784
+ const glyphs = raw.replace(/\s+$/, '')
785
+ const count = Array.from(glyphs).length
786
+ if (!(wordWidth > 0) || count === 0 || typeof measure !== 'function') return null
787
+ const glyphWidth = measure(glyphs)
788
+ const trailingWidth = measure(raw) - glyphWidth
789
+ if (!Number.isFinite(glyphWidth) || !Number.isFinite(trailingWidth)) return null
790
+ const letterSpacing = (wordWidth - glyphWidth) / count
791
+ return {
792
+ letterSpacing,
793
+ wordSpacing: glyphs.length !== raw.length ? gap - trailingWidth - letterSpacing : 0,
794
+ }
795
+ }
796
+
797
+ /**
798
+ * 将 PDFium 原生字符的每个起点转换成浏览器可渲染的字符推进宽度。
799
+ * 单词字体、字重、连字均不可假定等于浏览器 serif,所以不能再让
800
+ * 所有字母平分整词宽差。非法、倒序、叠字或不匹配的字符回退整词布局。
801
+ */
802
+ function pdfGlyphAdvances(word, scale) {
803
+ const raw = String(word?.text ?? '')
804
+ const core = raw.replace(/\s+$/, '')
805
+ const trailing = raw.slice(core.length)
806
+ const chars = word?.chars
807
+ const box = word?.bbox
808
+ if (!Array.isArray(chars) || chars.length === 0 || !Array.isArray(box) || !(scale > 0)
809
+ || (trailing !== '' && trailing !== ' ')
810
+ || !chars.every(char => typeof char?.text === 'string'
811
+ && Array.from(char.text).length === 1 && Array.isArray(char.bbox)
812
+ && char.bbox.length === 4 && char.bbox.every(Number.isFinite))
813
+ || chars.map(char => char.text).join('') !== core) return null
814
+ const left = box[0], right = box[2]
815
+ if (!Number.isFinite(left) || !Number.isFinite(right) || !(right > left)
816
+ || Math.abs(chars[0].bbox[0] - left) > 0.1) return null
817
+ const spans = []
818
+ for (let i = 0; i < chars.length; i++) {
819
+ const start = chars[i].bbox[0]
820
+ const end = i + 1 < chars.length ? chars[i + 1].bbox[0] : right
821
+ if (start < left - 0.1 || end > right + 0.1 || end - start < 0.01) return null
822
+ spans.push({ text: chars[i].text, advance: (end - start) * scale })
823
+ }
824
+ if (trailing) spans.push({ text: ' ', advance: Math.max(0, Number(word.gap) || 0) * scale })
825
+ return spans
826
+ }
827
+
762
828
  function selectionCount(text) {
763
829
  const source = String(text ?? '')
764
830
  const characters = (source.match(/\p{Script=Han}/gu) ?? []).length
@@ -1091,6 +1157,218 @@ function createLibraryModel() {
1091
1157
  * 相反,译文上划的线(offset = -1)照样能在 zhText 里精确定位。围栏内容整段跳过 ——
1092
1158
  * 高亮 Range 落进代码块没有视觉语义,还会把行号 / 高亮会话搅乱。
1093
1159
  */
1160
+ /** 空白字符集:行接缝的补空格、软连字符、零宽字符。与宿主 pdfQuoteInText 同口径。 */
1161
+ const spaceRun = () => /[\s\u00ad\u200b\u200c\u200d\ufeff]+/gu
1162
+ /** 单个字符是不是空白(含软连字符、零宽字符)。逐字符判断,不碰正则状态。 */
1163
+ const isSpaceChar = ch => ch === undefined || /[\s\u00ad\u200b\u200c\u200d\ufeff]/.test(ch)
1164
+
1165
+ /**
1166
+ * 忽略空白地在一段文本里定位原话,返回在**原文本**里的起止下标。
1167
+ *
1168
+ * 🔴 为什么绘制侧也需要它:PDF 档的文字层是逐词、逐字符的 span 拼出来的,行与行之间
1169
+ * **一个分隔符都没有**(每行是 display:block 的绝对定位元素),而 mark.quote 来自服务端
1170
+ * 的 group.text —— 那份在**行接缝补一个空格**。于是同一次拖选在两侧差着几个空格:
1171
+ * 实测 ResNet 第 2 页 `…problem by introducing…`(702 字)对 `…problem byintroducing…`
1172
+ * (693 字),`display.indexOf(quote)` 必然落空,划线画不出来。
1173
+ *
1174
+ * 做法:把两侧的空白都去掉再找,然后用一张「去空白后的下标 → 原文本下标」的表把结果
1175
+ * 换算回去。区间两端向外吸附到完整词元,避免高亮停在半个词上。
1176
+ *
1177
+ * @param {string} text 屏上显示文本(原样,含它自己的空白)
1178
+ * @param {string} quote 原话(可能带另一种空白)
1179
+ * @returns {{start: number, end: number}|null} 原文本里的区间;对不上返回 null
1180
+ */
1181
+ function locateQuoteIgnoringSpace(text, quote) {
1182
+ if (text === '' || quote === '') return null
1183
+ // squeezed 去掉空白,index 记录每个保留字符在原文本里的下标。
1184
+ let squeezed = ''
1185
+ const index = []
1186
+ for (let at = 0; at < text.length; at++) {
1187
+ if (isSpaceChar(text[at])) continue
1188
+ squeezed += text[at]
1189
+ index.push(at)
1190
+ }
1191
+ const target = quote.replace(spaceRun(), '')
1192
+ if (target === '' || squeezed === '') return null
1193
+ const hit = squeezed.indexOf(target)
1194
+ if (hit < 0) return null
1195
+ const start = index[hit]
1196
+ const end = index[hit + target.length - 1] + 1
1197
+ return { start, end }
1198
+ }
1199
+
1200
+ /** 行内公式的源码形态:`$…$`(不跨行)。两端锚定量词,避免跨段乱匹配。 */
1201
+ const formulaSource = () => /(\$[^$\n]+\$)/g
1202
+
1203
+ /**
1204
+ * 把原话按**行内公式**切成「文字段 / 公式段」,再把公式当**通配**去匹配显示文本。
1205
+ *
1206
+ * 🔴 为什么要这样:同一条划线在两侧的文字形态不同,公式是其中唯一的硬分界。
1207
+ * · 原文栏的显示文本里,公式是 KaTeX 渲染物被 {@link formulaSelectionText} 换回的
1208
+ * **LaTeX 源码**(`$\mathcal{H}(\mathbf{x})$`);
1209
+ * · PDF 档的显示文本里,公式是**渲染后的字形**(`H(x)`);
1210
+ * · 两边的**普通文字**逐字相同(只差空白)。
1211
+ *
1212
+ * 实测 ResNet 第 2 页 `p2-p2`:原话来自 PDF 字形,含 `H(x)`;原文栏那份是
1213
+ * `$\mathcal{H}(\mathbf{x})$`。整串逐字对不上,但公式**之间**的文字段四段全中
1214
+ * (0 / 254 / 316 / 353)。所以只要认定「这一段是公式」,两侧就能对齐 ——
1215
+ * 不必去猜公式该渲染成什么。
1216
+ *
1217
+ * 用户裁定:公式是**原子单位**——选区碰到公式的任何一部分,整个公式一起高亮。
1218
+ * 通配区间的两端就落在公式边界上,天然满足这条。
1219
+ *
1220
+ * @param {string} text 屏上显示文本(原样)
1221
+ * @param {string} quote 原话(公式是 `$…$` 源码形态)
1222
+ * @returns {{start: number, end: number}|null} 显示文本里的区间;对不上返回 null
1223
+ */
1224
+ /** 去掉空白,同时留一张「压缩下标 → 原文下标」的表。 */
1225
+ function squeezeWithIndex(text) {
1226
+ let squeezed = ''
1227
+ const index = []
1228
+ for (let at = 0; at < text.length; at++) {
1229
+ if (isSpaceChar(text[at])) continue
1230
+ squeezed += text[at]
1231
+ index.push(at)
1232
+ }
1233
+ return { squeezed, index }
1234
+ }
1235
+
1236
+ /**
1237
+ * 按 `$…$` 把一段文字切成「文字段 / 公式段」,返回**文字段**(公式段为 null)。
1238
+ * 奇数下标是公式。没有公式时返回 null —— 调用方据此判断这一侧能不能当模板。
1239
+ */
1240
+ function formulaSplit(text) {
1241
+ const pattern = formulaSource()
1242
+ if (!pattern.test(text)) return null
1243
+ // 🔴 正则**必须带捕获组**:String.split 在没有捕获组时会把分隔符整个丢掉,
1244
+ // 返回的只是文字段(['A ', ' B ', ' C']),公式位置根本没占位。
1245
+ // 旧实现用 map((p, i) => i % 2 === 0 ? p : null) 于是把下标 1 的**真文字**判成公式、
1246
+ // 三处公式全部丢失 —— 实测把 7 段切成 4 段,所有跨公式的划线定位失败。
1247
+ // 带捕获组后 split 返回 [文字, 公式, 文字, 公式, …],奇数位才是公式。
1248
+ return text.split(formulaSource()).map((piece, at) => at % 2 === 1 ? null : piece)
1249
+ }
1250
+
1251
+ /**
1252
+ * 一侧含行内公式、另一侧不含时,把**含公式的那侧**当模板切段,另一侧逐段定位。
1253
+ *
1254
+ * 🔴 方向是**双向**的,实测两种都真实存在:
1255
+ * · 划线取自 PDF 档 —— quote 是字形 `H(x)`(无 `$…$`),原文栏的 display 是
1256
+ * LaTeX 源码(3 处 `$…$`)。此时模板是 display。
1257
+ * · 划线取自原文栏 —— quote 带 `$…$` 源码,PDF 档的 display 是字形。此时模板是 quote。
1258
+ *
1259
+ * 先把模板的公式段换成通配,再用公式**之间**的文字段去另一侧依次定位;两侧都在
1260
+ * 压缩坐标(去空白)里走,最后换算回**目标文本**的原下标。
1261
+ *
1262
+ * 公式是原子单位(用户裁定):通配区间横跨整个公式,选区碰到哪一部分都整块高亮。
1263
+ *
1264
+ * @param {string} text 屏上显示文本(定位目标)
1265
+ * @param {string} quote 原话
1266
+ * @returns {{start: number, end: number}|null} 目标文本里的区间;对不上返回 null
1267
+ */
1268
+ function locateQuoteAcrossFormulas(text, quote) {
1269
+ if (text === '' || quote === '') return null
1270
+ const target = squeezeWithIndex(text)
1271
+ if (target.squeezed === '') return null
1272
+ // 两侧是否含 $…$。含公式的那一侧当**模板**切段,另一侧当**定位目标**。
1273
+ const quoteParts = formulaSplit(quote)
1274
+ const textParts = formulaSplit(text)
1275
+ if (quoteParts === null && textParts === null) return null
1276
+ const isText = piece => typeof piece === 'string' && piece !== ''
1277
+ const textPiecesOf = parts => parts.map(piece => piece === null ? null : piece.replace(spaceRun(), ''))
1278
+
1279
+ /**
1280
+ * 在 needle 里依次找 template 的各个文字段,返回覆盖到的**压缩坐标**区间。
1281
+ * 公式位不推进 —— 它只表示"这里跳过任意内容"。
1282
+ */
1283
+ const align = (needle, template) => {
1284
+ const wanted = textPiecesOf(template)
1285
+ const first = wanted.findIndex(isText)
1286
+ const last = wanted.length - 1 - [...wanted].reverse().findIndex(isText)
1287
+ if (first < 0) return null
1288
+ let cursor = needle.squeezed.indexOf(wanted[first])
1289
+ if (cursor < 0) return null
1290
+ const startAt = cursor
1291
+ cursor += wanted[first].length
1292
+ let endAt = cursor
1293
+ for (let at = first + 1; at <= last; at += 1) {
1294
+ const piece = wanted[at]
1295
+ if (piece === null) continue
1296
+ const found = needle.squeezed.indexOf(piece, cursor)
1297
+ if (found < 0) return null
1298
+ cursor = found + piece.length
1299
+ endAt = cursor
1300
+ }
1301
+ return { startAt, endAt }
1302
+ }
1303
+
1304
+ // 🔴 两种情形方向相反,必须分开写 —— 混用会让区间落在错误的坐标系上。
1305
+ let from
1306
+ let to
1307
+ if (textParts !== null && quoteParts === null) {
1308
+ // ① display 含公式、quote 不含(划线取自 PDF 档)。
1309
+ // quote 那侧的文字就是 display 文字段压缩后来的一份,先在 quote 里确认
1310
+ // 「这条划线覆盖到 display 的第几段」——对不上就说明不是同一段文字。
1311
+ const quoteTarget = squeezeWithIndex(quote)
1312
+ if (align(quoteTarget, textParts) === null) return null
1313
+ // 🔴 区间取 **display 自己**的范围:从第一段文字的开头到最后一段文字的结尾。
1314
+ // 中间那些公式段原样落在区间里,天然被整块包住 —— 这正是「公式是原子」
1315
+ // 要的效果,也不需要任何坐标换算(换算过一次,两次都算错)。
1316
+ // 带捕获组的 split 直接给出 [文字, 公式源码, 文字, …],按真实长度累加即可 ——
1317
+ // 不需要再猜公式段有多长。
1318
+ const shape = text.split(formulaSource())
1319
+ const isTextSeg = (piece, at) => at % 2 === 0 && piece !== ''
1320
+ const firstIdx = shape.findIndex(isTextSeg)
1321
+ const lastIdx = shape.length - 1 - [...shape].reverse().findIndex(isTextSeg)
1322
+ if (firstIdx < 0 || lastIdx < firstIdx) return null
1323
+ let cursorAt = 0
1324
+ let startPx = -1
1325
+ let endPx = -1
1326
+ for (let at = 0; at < shape.length; at += 1) {
1327
+ if (at === firstIdx) startPx = cursorAt
1328
+ cursorAt += shape[at].length
1329
+ if (at === lastIdx) { endPx = cursorAt; break }
1330
+ }
1331
+ if (startPx < 0 || endPx <= startPx) return null
1332
+ from = startPx
1333
+ to = endPx
1334
+ } else if (quoteParts !== null && textParts === null) {
1335
+ // ② quote 含公式、display 不含(划线取自原文栏)。
1336
+ // 用 quote 的文字段去 **display** 里定位,直接得到 display 区间。
1337
+ const hit = align(target, quoteParts)
1338
+ if (hit === null) return null
1339
+ from = target.index[hit.startAt]
1340
+ to = target.index[hit.endAt - 1] + 1
1341
+ // 🔴 划线**以公式开头/结尾**时,那个公式在 display 里是 KaTeX 渲染后的纯文本
1342
+ // (没有 `$…$`),所以 align 只能从公式**之后**的那段文字起算 —— 起点于是落在
1343
+ // 公式右边,公式本身永远进不了区间。实测 ResNet p2-p3:整段划线以
1344
+ // `$\mathcal{F}(\mathbf{x})+\mathbf{x}$` 开头,区间被算成 `[40,228)`,公式被排除在外。
1345
+ // 判据是模板的**首/尾段为空串**:空 = 划线是从那个公式开始的(结束的)。
1346
+ // 把区间扩到 display 的对应端点 —— 不猜长度,只是把「公式被当成光标位置」补回来。
1347
+ if (quoteParts[0] === '') from = 0
1348
+ if (quoteParts[quoteParts.length - 1] === '') to = text.length
1349
+ } else {
1350
+ return null
1351
+ }
1352
+ if (!(to > from)) return null
1353
+ // 🔴 **公式原子化**(用户裁定):选区碰到公式的任何一部分,整个公式一起高亮。
1354
+ for (let guard = 0; guard < 32; guard += 1) {
1355
+ let grown = false
1356
+ // 🔴 正则**必须在循环外建一次**:每次 new 一个带 g 的正则,lastIndex 永远从 0 起,
1357
+ // exec 每次都返回第一个匹配 —— 这是死循环(实测把测试跑成超时、日志 0 字节)。
1358
+ const pattern = formulaSource()
1359
+ let hit
1360
+ while ((hit = pattern.exec(text)) !== null) {
1361
+ const formulaFrom = hit.index
1362
+ const formulaTo = hit.index + hit[0].length
1363
+ if (!(formulaFrom < to && formulaTo > from)) continue
1364
+ if (formulaFrom < from) { from = formulaFrom; grown = true }
1365
+ if (formulaTo > to) { to = formulaTo; grown = true }
1366
+ }
1367
+ if (!grown) break
1368
+ }
1369
+ return { start: from, end: to }
1370
+ }
1371
+
1094
1372
  function quoteSpanPlan(mark, text) {
1095
1373
  if (mark === null || typeof mark !== 'object' || mark.anchor !== 'exact') return null
1096
1374
  const display = typeof text === 'string' ? text : ''
@@ -1103,7 +1381,22 @@ function createLibraryModel() {
1103
1381
  const at = locateQuoteInText(display, candidate, prefix, suffix)
1104
1382
  if (at >= 0) return { quote: candidate, start: at, end: at + candidate.length }
1105
1383
  }
1106
- // 🔴 逐字都对不上再试括号法:公式段的选区串是 KaTeX 两条渲染臂拼的,永远逐字对不上。
1384
+ // 🔴 逐字对不上先试**忽略空白**:PDF 文字层的行接缝没有分隔符,而原话那份有空格,
1385
+ // 同一次拖选两侧差着几个空格。这一步只放宽空白,别的字仍然要逐字对上。
1386
+ for (const candidate of quoteCandidates(quote)) {
1387
+ const span = locateQuoteIgnoringSpace(display, candidate)
1388
+ if (span !== null) return { quote: display.slice(span.start, span.end), start: span.start, end: span.end }
1389
+ }
1390
+ // 🔴 再试**公式通配**:同一条划线在两侧的文字形态不同 —— 原文栏把公式还原成 LaTeX
1391
+ // 源码($\mathcal{H}(\mathbf{x})$),PDF 档是渲染后的字形(H(x))。公式之间的普通文字
1392
+ // 逐字相同,所以只认「这一段是公式」、把它当通配,两侧就能对齐(见
1393
+ // {@link locateQuoteAcrossFormulas})。用户裁定公式是**原子单位**:选区碰到哪一部分,
1394
+ // 整个公式一起高亮。
1395
+ for (const candidate of quoteCandidates(quote)) {
1396
+ const span = locateQuoteAcrossFormulas(display, candidate)
1397
+ if (span !== null) return { quote: display.slice(span.start, span.end), start: span.start, end: span.end }
1398
+ }
1399
+ // 🔴 再试括号法:公式段的选区串是 KaTeX 两条渲染臂拼的,永远逐字对不上。
1107
1400
  // 只有**长原话**才走这一步 —— 短原话的首尾两截谁都能对上,夹出来的区间没有意义。
1108
1401
  for (const candidate of quoteCandidates(quote)) {
1109
1402
  const span = bracketSpan(display, candidate)
@@ -1509,13 +1802,46 @@ function createLibraryModel() {
1509
1802
  const range = new Range()
1510
1803
  if (!locate(row.node, target.start, false, range) || !locate(row.node, target.end, true, range)) continue
1511
1804
  const got = range.toString()
1512
- if (!got || (direct ? got !== direct.quote : got.trim() !== got)) continue
1805
+ // 🔴 终验:**普通文字逐字相等**;含公式时按 {@link formulaSelectionText} 的口径比。
1806
+ //
1807
+ // KaTeX 把公式摊成「TeX 源码 + 渲染字形」留在 textContent 里(实测
1808
+ // `$\mathcal{F}(\mathbf{x})+\mathbf{x}$` 是 34 字源码 + 5 字字形),与 `$…$` 形态的
1809
+ // quote 永远不可能逐字相等。用严格相等的话,凡覆盖公式的划线都被这道终验拒掉 ——
1810
+ // 实测区间已算对(`[0,228)` 覆盖公式)却 `painted = 0`,整条划线一个字都不画。
1811
+ // 折符号也**不行**(实测折完 190 vs 184:`\mathcal`/`\mathbf` 的命令名留在 DOM 里,
1812
+ // 而 quote 那侧只有符号)—— 唯一正确的口径是把公式还原成 `$…$` 再比。
1813
+ const matches = () => {
1814
+ if (!got) return false
1815
+ if (!direct) return got.trim() === got
1816
+ if (got === direct.quote) return true
1817
+ if (!formulaSource().test(direct.quote) && !formulaSource().test(got)) return false
1818
+ const contents = range.cloneContents?.()
1819
+ if (!contents) return false
1820
+ return formulaSelectionText(contents).trim() === direct.quote.trim()
1821
+ }
1822
+ if (!matches()) continue
1513
1823
  const name = 'dsh-paper-mark-' + color
1514
1824
  let entry = names.get(name)
1515
1825
  if (!entry) { entry = { ranges: [], hits: [] }; names.set(name, entry) }
1516
1826
  entry.ranges.push(range)
1517
1827
  entry.hits ??= []
1518
1828
  entry.hits.push({ range, markId: mark.id })
1829
+ // 🔴 **公式整块上色**(用户裁定:公式是原子单位,选区碰到哪一部分都整块亮)。
1830
+ //
1831
+ // KaTeX 把一个公式渲染成两条臂:`.katex-mathml`(`annotation` 里的 TeX 源码,
1832
+ // 被 clip 成 1×1 摆在屏幕外)与 `.katex-html`(真正看得见的字形)。实测
1833
+ // ResNet p2-p3 的 `$\mathcal{F}(\mathbf{x})+\mathbf{x}$`:mathml 臂占 34 个字符、
1834
+ // html 臂只有 5 个(`F(x)+x`)。划线的区间按 DOM 字符算,**整段都落在 mathml 臂上**,
1835
+ // 于是浏览器把颜色涂在那 1×1 的不可见区域 —— 用户看到的就是「公式没高亮」。
1836
+ //
1837
+ // 补法:凡区间碰到的 `.katex`,另给它的 `.katex-html` 加一条整块 Range。
1838
+ // 与 PDF 档 `pdfQuoteInText` 的口径一致,也不动定位逻辑一个字。
1839
+ for (const formula of katexArmsIn(row.node, range)) {
1840
+ const arm = new Range()
1841
+ arm.selectNodeContents(formula)
1842
+ entry.ranges.push(arm)
1843
+ entry.hits.push({ range: arm, markId: mark.id })
1844
+ }
1519
1845
  painted += 1
1520
1846
  completed.set(row.node, completed.get(row.node) + 1)
1521
1847
  }
@@ -1529,6 +1855,31 @@ function createLibraryModel() {
1529
1855
  return painted
1530
1856
  }
1531
1857
 
1858
+ /**
1859
+ * 一段 Range 碰到的所有 KaTeX 公式,返回各自**可见臂**(`.katex-html`)的根节点。
1860
+ *
1861
+ * 🔴 KaTeX 的 `.katex` 里有两条臂:`.katex-mathml`(无障碍树,TeX 源码,被 clip 成
1862
+ * 1×1 摆在屏幕外)与 `.katex-html`(可见字形)。划线的区间按 DOM 字符算,落在
1863
+ * mathml 臂上时浏览器会把颜色涂在那不可见的 1×1 区域 —— 用户看到「公式没高亮」。
1864
+ * 这里把碰到的公式找出来,交给调用方补一条覆盖可见臂的 Range(公式整块上色)。
1865
+ *
1866
+ * @param {unknown} node 块节点
1867
+ * @param {Range} range 已定位好的区间
1868
+ * @returns {Element[]} 可见臂节点(不可用的公式跳过)
1869
+ */
1870
+ function katexArmsIn(node, range) {
1871
+ const formulas = typeof node?.querySelectorAll === 'function' ? node.querySelectorAll('.katex') : []
1872
+ const arms = []
1873
+ for (const formula of formulas) {
1874
+ const arm = typeof formula?.querySelector === 'function' ? formula.querySelector('.katex-html') : null
1875
+ if (!arm) continue
1876
+ // 只要区间**碰到**这个公式就整块亮(用户裁定:公式是原子单位)。
1877
+ let touches = true
1878
+ try { touches = typeof range?.intersectsNode === 'function' ? range.intersectsNode(formula) : true } catch { touches = true }
1879
+ if (touches) arms.push(arm)
1880
+ }
1881
+ return arms
1882
+ }
1532
1883
  // KaTeX 同时包含无障碍树与可视树。克隆后用公式源码替换,避免把两份文字一起引用。
1533
1884
  function formulaSelectionText(node) {
1534
1885
  const clone = node.cloneNode(true)
@@ -2002,11 +2353,54 @@ function createLibraryModel() {
2002
2353
  // 引用编号挂 data-ref,公式编号挂 data-eq。只认"本篇里真的存在的编号":引用编号来自参考
2003
2354
  // 文献块开头的 [n](条目正文里的年份括号不算),公式编号来自 math 块的 tag。认不出、或编号
2004
2355
  // 不在集合里,一律原样留在纯文本里 —— 不猜、不改写正文。
2005
- const REF_NUMBER = /\[(\d{1,3})\]/g
2356
+ // 🔴 一次引用多篇(`[42, 43]`、`[40–41]`)在真实论文里很常见(实测 ResNet 一篇就有
2357
+ // `[42, 43]` 3 次、`[40, 41]` 2 次)。旧版正则只认 `[41]` 这一种形态,多标号会整段落回
2358
+ // 纯文本 —— 那是缺口,不是刻意省略。现在把**连编号带分隔符**的整段一起捕获,再由
2359
+ // {@link refItemsOf} 摊成单个编号。
2360
+ //
2361
+ // 仍然要求方括号内**以数字开头**:`[.5, .95]` 这类置信区间因此天然不匹配(实测同一篇里
2362
+ // 出现 7 次),不需要额外的黑白名单。
2363
+ // 🔴 编号位数不能写死 3 位:实测一篇综述有 1411 条参考文献,正文里出现 `[841, 1141]`、
2364
+ // `[1211, 1372]` 这类四位数编号(`\d{1,3}` 会把它们整段挡掉,界面上就是"悬停没反应")。
2365
+ // 上限给到 5 位足以覆盖任何真实文献表,同时仍挡掉更长的方括号噪声。
2366
+ const REF_NUMBER = /\[(\d{1,5}(?:\s*[,,、–—-]\s*\d{1,5})*)\]/g
2006
2367
  // 公式号不加单词边界:词边界只对拉丁字母成立,中文的"式 (4)"加了就永远匹配不上。
2007
2368
  const EQUATION_NUMBER = /(?:\bEquations?\b|\bEqs?\.|式)\s*\(?\s*(\d{1,3})\)?/g
2008
2369
  /** 引用条目开头的方括号编号;条目正文里的年份括号不会被当成编号。 */
2009
- const REFERENCE_LEAD = /^\[\s*(\d{1,3})\s*\]/
2370
+ const REFERENCE_LEAD = /^\[\s*(\d{1,5})\s*\]/
2371
+ /** 连字符区间的最大展开跨度;超过它的一律不当作引用区间。 */
2372
+ const REF_RANGE_MAX = 200
2373
+
2374
+ /**
2375
+ * 把一个引用标记的内部文本摊成单个编号字符串。
2376
+ *
2377
+ * 逗号/顿号分隔 = 并列,原样列出;连字符/短破折号/长破折号分隔 = 区间,展开。
2378
+ * 任何一个成分认不出来(例如 `4a`、小数、空段)**整段作废**返回空数组:
2379
+ * 只认得出的那几个编号不算数 —— 显示半截引用比不显示更坏,读者会以为那就是全部。
2380
+ *
2381
+ * 区间跨度过大也整段作废:那不是引用区间,是解析事故。
2382
+ *
2383
+ * @param {unknown} inner 方括号内部的文本(不含两侧方括号)。
2384
+ * @returns {string[]} 单个编号,按出现顺序;空数组表示"这不是引用标记"。
2385
+ */
2386
+ function refItemsOf(inner) {
2387
+ if (typeof inner !== 'string' || inner === '') return []
2388
+ const items = []
2389
+ for (const chunk of inner.split(/[,,、]/)) {
2390
+ const range = /^\s*(\d{1,5})\s*[–—-]\s*(\d{1,5})\s*$/.exec(chunk)
2391
+ if (range !== null) {
2392
+ const start = Number(range[1])
2393
+ const end = Number(range[2])
2394
+ if (end < start || end - start > REF_RANGE_MAX) return []
2395
+ for (let value = start; value <= end; value += 1) items.push(String(value))
2396
+ continue
2397
+ }
2398
+ const single = /^\s*(\d{1,5})\s*$/.exec(chunk)
2399
+ if (single === null) return []
2400
+ items.push(single[1])
2401
+ }
2402
+ return items
2403
+ }
2010
2404
 
2011
2405
  /**
2012
2406
  * 把段落切成"文字段 + 标记"的有序片段。标记是结构化对象({"type":"ref"|"eq", value}),
@@ -2015,9 +2409,15 @@ function createLibraryModel() {
2015
2409
  * 两个模式都带 g,lastIndex 在换模式时不会被重置,所以每次 exec 前按 cursor 重新定位;
2016
2410
  * 空匹配(两个正则都不可能产生)原地踏步时按一个字符推进,保证一定会终止。
2017
2411
  *
2412
+ * `ref` 片段一次引用多篇时带 {@link items}:正文**原样**保留(`[42, 43]` 不拆成两段),
2413
+ * 悬停预览再逐条展开。单编号时不带 `items` —— 与旧行为逐字段相同,既有断言不受影响。
2414
+ *
2415
+ * 多标号里只要有一个编号不在本篇集合内,整段按纯文本处理(同 {@link refItemsOf} 的口径):
2416
+ * 显示半截引用会让读者以为那就是全部。
2417
+ *
2018
2418
  * @param {unknown} text 段落文本。
2019
2419
  * @param {unknown} known {refs: Set, eqs: Set},本篇真实存在的编号。
2020
- * @returns {Array<{type: string, value: string} | {type: 'text', text: string}>}
2420
+ * @returns {Array<{type: string, value: string, items?: string[]} | {type: 'text', text: string}>}
2021
2421
  */
2022
2422
  function inlineRefs(text, known) {
2023
2423
  if (typeof text !== 'string' || text === '') return []
@@ -2039,9 +2439,21 @@ function createLibraryModel() {
2039
2439
  if (hit === null) break
2040
2440
  const match = hit === 'ref' ? ref : eq
2041
2441
  plain += text.slice(cursor, match.index)
2042
- if ((hit === 'ref' ? refs : eqs).has(match[1])) {
2442
+ if (hit === 'ref') {
2443
+ const items = refItemsOf(match[1])
2444
+ if (items.length > 0 && items.every(number => refs.has(number))) {
2445
+ flush()
2446
+ // 单编号不带 raw/items:与旧的 {type, value} 逐字段相同,既有断言照旧通过。
2447
+ // 多标号必须带 raw —— 渲染时按它原样输出(`[42,43]` 不能变成 `[42, 43]`)。
2448
+ parts.push(items.length === 1
2449
+ ? { type: 'ref', value: items[0] }
2450
+ : { type: 'ref', value: items.join(','), items, raw: match[0] })
2451
+ } else {
2452
+ plain += match[0]
2453
+ }
2454
+ } else if (eqs.has(match[1])) {
2043
2455
  flush()
2044
- parts.push({ type: hit, value: match[1] })
2456
+ parts.push({ type: 'eq', value: match[1] })
2045
2457
  } else {
2046
2458
  plain += match[0]
2047
2459
  }
@@ -2060,6 +2472,27 @@ function createLibraryModel() {
2060
2472
  return lead === null ? '' : lead[1]
2061
2473
  }
2062
2474
 
2475
+ /**
2476
+ * 编号 → 该条参考文献的**原文**(去掉开头的 `[n]` 与两侧空白)。
2477
+ *
2478
+ * 悬停预览要给人看的是条目文字本身,不是块 id —— 所以与 {@link referenceIndex} 分开:
2479
+ * 那个给"跳到哪一段"用,这个给"显示什么"用。两者同一口径地只认参考文献块**开头**的编号。
2480
+ *
2481
+ * @param {unknown} blocks 阅读器的块列表。
2482
+ * @returns {Map<string, {blockId: string, text: string}>}
2483
+ */
2484
+ function referenceTexts(blocks) {
2485
+ const texts = new Map()
2486
+ for (const block of Array.isArray(blocks) ? blocks : []) {
2487
+ if (block === null || typeof block !== 'object' || typeof block.id !== 'string') continue
2488
+ const number = refNumbersOf(block)
2489
+ if (number === '' || texts.has(number)) continue
2490
+ const source = typeof block.sourceText === 'string' ? block.sourceText : ''
2491
+ texts.set(number, { blockId: block.id, text: source.replace(REFERENCE_LEAD, '').trim() })
2492
+ }
2493
+ return texts
2494
+ }
2495
+
2063
2496
  /** 全文真实的编号集合。非数组入参按没有编号处理,不抛错。 */
2064
2497
  function numbersOf(values, pick) {
2065
2498
  const numbers = new Set()
@@ -2071,11 +2504,18 @@ function createLibraryModel() {
2071
2504
  return numbers
2072
2505
  }
2073
2506
 
2074
- /** 本篇真实存在的编号:refs 来自参考文献块,eqs 来自 math 块的 tag。 */
2507
+ /**
2508
+ * 本篇真实存在的编号:refs 来自参考文献块,eqs 来自 math 块的 tag。
2509
+ *
2510
+ * 编号制整篇一条都没识别出来时**才**建作者-年份索引:那套索引要解析每一条参考文献的
2511
+ * 姓氏与年份,对编号制论文是纯浪费(实测 4128 个 ref_text 块,建一次不便宜)。
2512
+ */
2075
2513
  function readerNumbers(blocks) {
2514
+ const refs = numbersOf(blocks, refNumbersOf)
2076
2515
  return {
2077
- refs: numbersOf(blocks, refNumbersOf),
2516
+ refs,
2078
2517
  eqs: numbersOf(blocks, block => (typeof block?.math?.tag === 'string' ? block.math.tag : '')),
2518
+ authorYears: refs.size > 0 ? new Map() : authorYearIndex(blocks),
2079
2519
  }
2080
2520
  }
2081
2521
  /**
@@ -2754,6 +3194,101 @@ function createLibraryModel() {
2754
3194
  return { ratio: Math.min(1, page / last), block }
2755
3195
  }
2756
3196
 
3197
+ // ---- 作者-年份制引用(T25b,纯函数) ----
3198
+ // 很多论文的参考文献**不带编号**(实测抽查 4 篇里有 2 篇),正文改用 `(Zhang et al., 2020)`。
3199
+ // 这条链路独立于编号制:编号制未命中时才启用,两套规则不互相干扰。
3200
+ //
3201
+ // 🔴 与编号制最大的差别是**没有唯一键**。"姓氏 + 年份"在 AI 领域经常撞车(同一作者同年
3202
+ // 多篇),所以索引是一对多:命中几条就全列,由读者自己判断。宁可显示两条让人选,也不要
3203
+ // 挑一条赌对 —— 猜错时读者无从知道错。
3204
+ /** `(Surname et al., 2020)` / `(Surname & Other, 2020)` / `(Surname, 2020)`。 */
3205
+ const AUTHOR_YEAR =
3206
+ /\(\s*([\p{Lu}][\p{L}'-]+)(?:\s+et\s+al\.?|\s*(?:&|and)\s*[\p{Lu}][\p{L}'-]+)?\s*,\s*(\d{4})[a-z]?\s*\)/gu
3207
+ // 🔴 三个正则都**必须带 u flag**:`\p{Lu}` / `\p{L}` 是 Unicode 属性转义,没有 u 时
3208
+ // 会被当成字面量 p / L / u,正则永远匹配不上而**不报错** —— 表现为索引恒为空、悬停全无反应。
3209
+ // 这条踩过一次(首版漏了 u,4 条作者-年份用例全挂)。
3210
+ /** 参考文献条目开头的姓:surname, Initial. */
3211
+ const REFERENCE_SURNAME = /^\s*(?:\[\s*\d{1,3}\s*\]\s*)?([\p{Lu}][\p{L}'-]+)\s*,/u
3212
+ /** 条目里出现的第一个四位数年份。 */
3213
+ const REFERENCE_YEAR = /\b(\d{4})\b/
3214
+
3215
+ /** 匹配键:姓氏折叠成小写 + 年份。作者大小写与变音符号不在这一层处理。 */
3216
+ function authorYearKey(surname, year) {
3217
+ return typeof surname === 'string' && surname !== '' && /^\d{4}$/.test(String(year))
3218
+ ? surname.toLowerCase() + '|' + year
3219
+ : ''
3220
+ }
3221
+
3222
+ /**
3223
+ * 从参考文献块建「姓氏|年份 → 块」的一对多索引。
3224
+ *
3225
+ * 姓氏取条目开头(可带 `[n]` 前缀)的第一个大写词,年份取条目里第一个四位数 ——
3226
+ * 学术期刊格式千差万别,这是**启发式**而不是解析器。认不出来的条目直接跳过:
3227
+ * 索引里少一条只是那条引用悬停没反应,不会错配到别的条目上。
3228
+ *
3229
+ * @param {unknown} blocks 阅读器的块列表。
3230
+ * @returns {Map<string, Array<{blockId: string, text: string}>>}
3231
+ */
3232
+ function authorYearIndex(blocks) {
3233
+ const index = new Map()
3234
+ for (const block of Array.isArray(blocks) ? blocks : []) {
3235
+ if (block === null || typeof block !== 'object' || typeof block.id !== 'string') continue
3236
+ if (readerKindOf(block) !== 'references') continue
3237
+ const source = typeof block.sourceText === 'string' ? block.sourceText : ''
3238
+ const surname = REFERENCE_SURNAME.exec(source)
3239
+ const year = REFERENCE_YEAR.exec(source)
3240
+ if (surname === null || year === null) continue
3241
+ const key = authorYearKey(surname[1], year[1])
3242
+ if (key === '') continue
3243
+ const entry = { blockId: block.id, text: source.replace(REFERENCE_LEAD, '').trim() }
3244
+ const list = index.get(key)
3245
+ if (list === undefined) index.set(key, [entry])
3246
+ else if (!list.some(item => item.blockId === block.id)) list.push(entry)
3247
+ }
3248
+ return index
3249
+ }
3250
+
3251
+ /**
3252
+ * 把段落切成「文字段 + 作者-年份标记」。
3253
+ *
3254
+ * 只产出**索引里真有**的标记:查不到的括号原样留在文本里。这一条与编号制同一口径 ——
3255
+ * 点了没反应/悬停了没内容,比没有标记更坏。
3256
+ *
3257
+ * 标记带 `ambiguous`:命中多条时为真,渲染层据此提示"共 N 条可能匹配"。
3258
+ *
3259
+ * @param {unknown} text 段落文本。
3260
+ * @param {unknown} index {@link authorYearIndex} 的产物。
3261
+ * @returns {Array<{type: string, value: string, surname: string, year: string, ambiguous?: boolean, count?: number} | {type: 'text', text: string}>}
3262
+ */
3263
+ function inlineAuthors(text, index) {
3264
+ if (typeof text !== 'string' || text === '' || !(index instanceof Map) || index.size === 0) return []
3265
+ const parts = []
3266
+ let plain = ''
3267
+ const flush = () => {
3268
+ if (plain !== '') parts.push({ type: 'text', text: plain })
3269
+ plain = ''
3270
+ }
3271
+ let cursor = 0
3272
+ AUTHOR_YEAR.lastIndex = 0
3273
+ for (let match = AUTHOR_YEAR.exec(text); match !== null; match = AUTHOR_YEAR.exec(text)) {
3274
+ const key = authorYearKey(match[1], match[2])
3275
+ const hits = key === '' ? undefined : index.get(key)
3276
+ if (hits === undefined || hits.length === 0) continue
3277
+ plain += text.slice(cursor, match.index)
3278
+ flush()
3279
+ parts.push({
3280
+ type: 'author',
3281
+ value: match[0],
3282
+ surname: match[1],
3283
+ year: match[2],
3284
+ ...(hits.length > 1 ? { ambiguous: true, count: hits.length } : {}),
3285
+ })
3286
+ cursor = match.index + match[0].length
3287
+ }
3288
+ plain += text.slice(cursor)
3289
+ flush()
3290
+ return parts
3291
+ }
2757
3292
  // END CLIENT PARTS
2758
3293
  // 量容器的实际宽度(resize 时重量):ResizeObserver 不在就退回 window resize,清理函数
2759
3294
  // 一律走同一个 disconnect 形状。回调 ref 而不是 ref 对象 —— 节点挂上/换掉时都要重挂观察者。
@@ -3060,8 +3595,29 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
3060
3595
  .paper-pdf-line{position:absolute;display:block;white-space:nowrap;pointer-events:auto}
3061
3596
  /* The word box is the PDF word rect including its trailing space; the invisible glyphs are
3062
3597
  stretched across it, so the browser paints the selection over the gap as well. */
3063
- .paper-pdf-word{display:inline-block;vertical-align:top;white-space:pre;font-family:serif;color:transparent;pointer-events:auto;cursor:text;user-select:text;overflow:hidden}
3064
- .paper-pdf-line::selection,.paper-pdf-word::selection{background:rgba(66,133,244,.3);color:transparent}
3598
+ .paper-pdf-word{display:inline-block;vertical-align:top;white-space:pre;font-family:serif;font-weight:400;font-style:normal;font-kerning:none;color:transparent;pointer-events:auto;cursor:text;user-select:text;overflow:hidden}
3599
+ /* 物理行仍负责行间的鼠标命中,但不把其整片行盒涂成蓝色;只给实际选中文字上色。 */
3600
+ .paper-pdf-line::selection{background:transparent;color:transparent}
3601
+ .paper-pdf-char{white-space:pre}
3602
+ .paper-pdf-word::selection{background:rgba(66,133,244,.22);color:transparent}
3603
+ .paper-pdf-char::selection{background:rgba(66,133,244,.22);color:transparent}
3604
+ .paper-cite{background:transparent;border-radius:2px;cursor:help;transition:background-color var(--paper-t-feedback)}
3605
+ .paper-cite:hover,.paper-cite:focus-visible{background:color-mix(in srgb,var(--paper-accent,#3b82f6) 16%,transparent);outline:none}
3606
+ /* 🔴 PDF 原页这侧**不套 span**:文字层是「绝对定位行盒 + 定宽词盒 + 逐字符盒」,把字节点从
3607
+ 这些盒子里 extractContents 出来再塞进一个新 span,等于让它们退回普通行内流 —— 位置全歪,
3608
+ 背景框压在相邻文字上(实测截图:蓝块明显大于 [23, 9, 37, 13] 那几个字,还跑到左边距上)。
3609
+ 这里改为直接给既有的字符 / 词元素打标记,DOM 结构一个节点都不动。
3610
+ 背景因此落在字形自己的内容盒上,刚好是字的大小。 */
3611
+ .paper-pdf-text [data-cite]{cursor:help}
3612
+ /* 🔴 **同一引用标记要整组一起亮**:文字层逐字符渲染,每个 .paper-pdf-char 都是独立元素,
3613
+ CSS 的 :hover 只命中鼠标正下方那一个 —— 实测「[41, 44, 13, 16] 里只有鼠标指着的那个字变色」。
3614
+ 所以这里**不用 :hover**:高亮由 onCiteOver/onCiteOut 按组号写 is-cite-active,
3615
+ 一次点亮同一处标记的全部字符。混用两者会让"鼠标下的那个"和"整组"两套样式打架。 */
3616
+ .paper-pdf-text [data-cite].is-cite-active{background:color-mix(in srgb,var(--paper-accent,#3b82f6) 16%,transparent)}
3617
+ .paper-cite-pop{position:fixed;z-index:var(--paper-layer-float,40);box-sizing:border-box;width:min(420px,calc(100vw - 16px));max-height:280px;overflow:auto;display:flex;flex-direction:column;gap:0;padding:8px 10px;border:1px solid var(--paper-border);border-radius:8px;background:var(--paper-bg,#fff);color:var(--paper-text);box-shadow:0 8px 24px rgba(0,0,0,.16);font-size:12px;line-height:1.55}
3618
+ .paper-cite-entry{padding:6px 0;overflow-wrap:anywhere;user-select:text}
3619
+ .paper-cite-entry + .paper-cite-entry{border-top:1px solid var(--paper-border)}
3620
+ .paper-cite-note{margin-top:4px;padding-top:6px;border-top:1px solid var(--paper-border);color:var(--paper-muted);font-size:11px}
3065
3621
  .paper-mark-draft{position:fixed;z-index:var(--paper-layer-float,40);display:flex;flex-direction:column;gap:0;width:min(400px,calc(100vw - 16px));max-height:70vh;min-height:0;overflow:auto;padding:0;border:1px solid var(--paper-border);border-radius:10px;background:var(--paper-bg,#fff);color:var(--paper-text);box-shadow:0 8px 28px rgba(0,0,0,.18);font-size:12px;line-height:1.5}
3066
3622
  .paper-selection-toolbar{display:flex;align-items:center;flex:0 0 auto;gap:2px;padding:5px;overflow-x:auto;white-space:nowrap}
3067
3623
  .paper-selection-toolbar .paper-btn{flex:0 0 auto;border:0;border-radius:5px;padding:6px;background:transparent;font-size:12px}
@@ -3648,6 +4204,292 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
3648
4204
  * @param {object} row 这一行对应的渲染行(拿 payload)。
3649
4205
  * @param {{pathImages: object, documentId: string, onJump: Function}} options
3650
4206
  */
4207
+ /**
4208
+ * 给正文里已渲染的引用标记包一层可悬停的 span(T25b)。
4209
+ *
4210
+ * 🔴 **为什么要走 DOM 而不是渲染**:正文整块交给宿主的 MarkdownText,拿不到里面的节点;
4211
+ * 而绕开 MarkdownText 自己渲染会破坏「正文统一由渲染器排版」这条既有约束
4212
+ * (reader-render 的用例名就叫「阅读器正文渲染成 MarkdownText,而不是自己画的」)。
4213
+ * 所以与划线同一范式({@link paintMarkHighlights}):**渲染不动,只在已挂载的 DOM 上
4214
+ * 按文本找位置**。字形/排版全归渲染器,这里只加属性与外层包装。
4215
+ *
4216
+ * 与划线的差别:划线用 CSS.highlights 画横线(不需要改 DOM 结构),这里必须**包元素**
4217
+ * 才能拿到 hover 事件。包的是标记自己那几个字,前后文本节点原样保留、顺序不变。
4218
+ *
4219
+ * 找不到 / 已经包过的块跳过;重复调用是幂等的(先按 data-cite 还原再重建)。
4220
+ *
4221
+ * @param {object|null} scope 正文容器。
4222
+ * @param {Map<string, object[]>} grouped 块 id → 该块的标记片段。
4223
+ * @returns {number} 实际包上的标记数(测试断言用)。
4224
+ */
4225
+ /**
4226
+ * 块 id → 该块的引用标记片段。渲染层与 DOM 装饰层共用这一份判定。
4227
+ *
4228
+ * 编号制整篇一条都没认出来时才走作者-年份制(与 readerNumbers 的 authorYears 同源),
4229
+ * 两套规则不叠加:同一段既按编号切又按作者切,会切出互相重叠的标记。
4230
+ *
4231
+ * @param {unknown} blocks /reader 的块列表。
4232
+ * @param {unknown} numbers {@link readerNumbers} 的产物。
4233
+ * @returns {Map<string, object[]>}
4234
+ */
4235
+ /**
4236
+ * 按「姓氏|年份」从一对多索引里取出候选条目。
4237
+ *
4238
+ * 键的构造与 {@link authorYearIndex} 一致;这里只做查表,不重新解析。
4239
+ * 取不到时返回空数组 —— 调用方据此不弹窗(宁可不显示,也不显示错的)。
4240
+ *
4241
+ * @param {unknown} index {@link authorYearIndex} 的产物。
4242
+ * @param {unknown} surname 标记上的姓氏。
4243
+ * @param {unknown} year 标记上的年份。
4244
+ * @returns {Array<{blockId: string, text: string}>}
4245
+ */
4246
+ /**
4247
+ * 引用浮层的位置。
4248
+ *
4249
+ * 锚点是标记自己的 bounding rect:优先放在**下方** 6px;下方空间不够(浮层估计高 160px)
4250
+ * 就翻到上方。左右按视口夹住,宽度由 CSS 上限(420px)保证,不让它越出屏幕。
4251
+ *
4252
+ * 锚点拿不到(测试替身、节点已脱离)时返回 hidden —— 位置宁可不显示,也不摆在 (0,0)。
4253
+ *
4254
+ * @param {{anchor?: {left: number, top: number, bottom: number}|null}} hover 悬停状态。
4255
+ * @returns {object} React style。
4256
+ */
4257
+ function citePopStyle(hover) {
4258
+ const anchor = hover?.anchor ?? null
4259
+ if (anchor === null || !Number.isFinite(anchor.left) || !Number.isFinite(anchor.top)) {
4260
+ return { visibility: 'hidden', left: 0, top: 0 }
4261
+ }
4262
+ const height = 160
4263
+ const width = 420
4264
+ const gap = 6
4265
+ const viewportWidth = typeof window !== 'undefined' && Number(window.innerWidth) > 0 ? Number(window.innerWidth) : 1280
4266
+ const viewportHeight = typeof window !== 'undefined' && Number(window.innerHeight) > 0 ? Number(window.innerHeight) : 800
4267
+ const below = anchor.bottom + gap
4268
+ const top = below + height > viewportHeight && anchor.top - height - gap > 0
4269
+ ? anchor.top - height - gap
4270
+ : below
4271
+ const left = Math.max(8, Math.min(anchor.left, viewportWidth - width - 8))
4272
+ return { left, top }
4273
+ }
4274
+
4275
+ function ambiguousLookup(index, surname, year) {
4276
+ if (!(index instanceof Map)) return []
4277
+ const key = authorYearKey(surname, year)
4278
+ if (key === '') return []
4279
+ const hits = index.get(key)
4280
+ return Array.isArray(hits) ? hits : []
4281
+ }
4282
+
4283
+ /**
4284
+ * 块 id → 该块要包成可悬停元素的标记片段。
4285
+ *
4286
+ * 🔴 **与渲染层同一口径**:`readerRows` 已经按 `sourceText` 算好了 `row.inline.parts`,
4287
+ * 这里直接复用,不再自己调一遍 `inlineRefs` —— 两处各算一次迟早会分叉(第一版就是这样:
4288
+ * 这边用 `displayInlineHtml` 之后的串、那边用原始串,含上标的段落两边对不上)。
4289
+ *
4290
+ * 没有 `row.inline.parts` 时(非 render 档)才退回自行计算,保证函数单独可测。
4291
+ *
4292
+ * @param {Map<string, object>} rowsById readerRows 产物按 id 建的索引(可为空)。
4293
+ * @param {unknown} blocks 块列表。
4294
+ * @param {unknown} numbers {@link readerNumbers} 的产物。
4295
+ * @returns {Map<string, object[]>}
4296
+ */
4297
+ function citePartsOf(rowsById, blocks, numbers) {
4298
+ const grouped = new Map()
4299
+ if (!Array.isArray(blocks)) return grouped
4300
+ const authorYears = numbers?.authorYears instanceof Map ? numbers.authorYears : new Map()
4301
+ for (const block of blocks) {
4302
+ if (block === null || typeof block !== 'object' || typeof block.id !== 'string') continue
4303
+ const row = rowsById instanceof Map ? rowsById.get(block.id) : undefined
4304
+ const known = Array.isArray(row?.inline?.parts) ? row.inline.parts : null
4305
+ let tags
4306
+ if (known !== null) {
4307
+ tags = known.filter(part => part.type !== 'text')
4308
+ } else {
4309
+ const payload = readerPayloadOf(block, String(block.sourceText ?? ''), '')
4310
+ if (payload.markdown !== true || readerKindOf(block) === 'references') continue
4311
+ const sourceText = displayInlineHtml(String(block.sourceText ?? ''))
4312
+ const byNumber = inlineRefs(sourceText, numbers)
4313
+ const parts = byNumber.length > 0 ? byNumber : inlineAuthors(sourceText, authorYears)
4314
+ tags = parts.filter(part => part.type !== 'text')
4315
+ }
4316
+ if (tags.length > 0) grouped.set(block.id, tags)
4317
+ }
4318
+ return grouped
4319
+ }
4320
+
4321
+ /**
4322
+ * 收集一个宿主节点里的可见文本节点,并拼出「整串 + 每段起点」。
4323
+ *
4324
+ * 🔴 **必须拼接而不是逐节点找**:PDF 文字层是逐字符渲染的(每个 `.paper-pdf-char`
4325
+ * 只装一个字符),`indexOf('[41]')` 在单字符节点里永远不命中 —— 这正是原版在原页
4326
+ * 那侧全无反应的原因。拼接后整串里才有完整标记,再按偏移映射回具体节点。
4327
+ *
4328
+ * 只收父级仍是本宿主的文本节点;`<style>` 之类不参与。
4329
+ */
4330
+ function citeTextRuns(node, doc = typeof document === 'undefined' ? null : document) {
4331
+ if (doc === null || typeof doc.createTreeWalker !== 'function') return { runs: [], joined: '' }
4332
+ const walker = doc.createTreeWalker(node, 4 /* NodeFilter.SHOW_TEXT */)
4333
+ const runs = []
4334
+ let joined = ''
4335
+ for (let current = walker.nextNode(); current !== null; current = walker.nextNode()) {
4336
+ const value = String(current.nodeValue ?? '')
4337
+ if (value === '') continue
4338
+ runs.push({ node: current, start: joined.length, length: value.length })
4339
+ joined += value
4340
+ }
4341
+ return { runs, joined }
4342
+ }
4343
+
4344
+ /**
4345
+ * 把整串里的 [from, to) 拆成「一段或连续几段」,供 Range 逐段落点。
4346
+ *
4347
+ * 纯字符节点时一个标记会横跨好几个文本节点;跨节点的 Range 无法 `surroundContents`
4348
+ * (会抛错),所以这里返回逐段的落点,由调用方按段合并处理。
4349
+ */
4350
+ function citeSlice(runs, from, to) {
4351
+ const pieces = []
4352
+ for (const run of runs) {
4353
+ const start = Math.max(from, run.start)
4354
+ const end = Math.min(to, run.start + run.length)
4355
+ if (end <= start) continue
4356
+ pieces.push({ node: run.node, start: start - run.start, end: end - run.start })
4357
+ }
4358
+ return pieces
4359
+ }
4360
+
4361
+ /** 正则元字符转义;只给 {@link citeLocate} 用。空格不在其中,容错那一步要靠它保留。 */
4362
+ function citeEscape(text) {
4363
+ return String(text).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
4364
+ }
4365
+
4366
+ /**
4367
+ * 在拼接好的整串里找出一个引用标记出现的**全部**位置。
4368
+ *
4369
+ * 先按原样精确找;一处都没有时才按「空白容错」再找一次。两条都需要:
4370
+ * PDF 文字层把每个词单独成一个 span,词间空白由 pdf-page 按版面重算,于是同一处标记
4371
+ * 在 DOM 里的空白数量(甚至有没有空白)都可能与解析正文那一份不同 —— 正文栏走精确匹配,
4372
+ * 容错只在 PDF 那侧兜底。
4373
+ *
4374
+ * 🔴 **容错不能优先**:让 `\s*` 先上场时,`[4]` 会命中到 `[44]` 这类串的内部。
4375
+ * 精确命中不为空就说明正文自洽,这时容错只会引入误判。
4376
+ *
4377
+ * @returns {Array<{at: number, length: number}>} 命中位置与**实际**长度(容错命中会比 raw 长)。
4378
+ */
4379
+ function citeLocate(joined, raw) {
4380
+ const exact = []
4381
+ let at = joined.indexOf(raw)
4382
+ while (at >= 0) {
4383
+ exact.push({ at, length: raw.length })
4384
+ at = joined.indexOf(raw, at + raw.length)
4385
+ }
4386
+ if (exact.length > 0) return exact
4387
+ const pattern = new RegExp(citeEscape(raw).replace(/\s+/g, '\\s*'), 'g')
4388
+ const loose = []
4389
+ for (const match of joined.matchAll(pattern)) loose.push({ at: match.index, length: match[0].length })
4390
+ return loose
4391
+ }
4392
+
4393
+ let citeSpanCounter = 0
4394
+ /**
4395
+ * 给已挂载 DOM 里的引用标记包一层可悬停 span。
4396
+ *
4397
+ * @param {object|null} scope 容器。
4398
+ * @param {Map<string, object[]>} grouped 块 id → 该块的标记片段。
4399
+ * @returns {number} 实际包上的标记数。
4400
+ */
4401
+ function paintCiteSpans(scope, grouped, doc = typeof document === 'undefined' ? null : document) {
4402
+ if (scope === null || typeof scope !== 'object' || typeof scope.querySelectorAll !== 'function') return 0
4403
+ if (!(grouped instanceof Map) || grouped.size === 0) return 0
4404
+ if (doc === null || doc === undefined || typeof doc.createTreeWalker !== 'function') return 0
4405
+ let painted = 0
4406
+ for (const node of scope.querySelectorAll('[data-block-id]')) {
4407
+ const blockId = typeof node?.getAttribute === 'function' ? node.getAttribute('data-block-id') : null
4408
+ const parts = blockId === null ? undefined : grouped.get(blockId)
4409
+ if (!Array.isArray(parts) || parts.length === 0) continue
4410
+ if (typeof node.querySelector === 'function' && node.querySelector('.paper-cite') !== null) continue
4411
+ const { runs, joined } = citeTextRuns(node, doc)
4412
+ if (runs.length === 0) continue
4413
+ // 从后往前包:包前面的标记会切分后面的文本节点,倒序处理可让后面的偏移一直有效。
4414
+ const hits = []
4415
+ for (const part of parts) {
4416
+ const raw = part.raw !== undefined
4417
+ ? String(part.raw)
4418
+ : part.type === 'ref' ? `[${part.value}]` : String(part.value ?? '')
4419
+ if (raw === '') continue
4420
+ // 位置由 citeLocate 给:精确优先、空白容错兜底(PDF 文字层的空白与解析正文不同源)。
4421
+ for (const found of citeLocate(joined, raw)) hits.push({ part, raw, at: found.at, length: found.length })
4422
+ }
4423
+ hits.sort((a, b) => b.at - a.at)
4424
+ const spanId = () => String((citeSpanCounter += 1))
4425
+ for (const hit of hits) {
4426
+ const pieces = citeSlice(runs, hit.at, hit.at + hit.length)
4427
+ if (pieces.length === 0) continue
4428
+ const first = pieces[0]
4429
+ if (first.node.parentNode === null || first.node.parentNode === undefined) continue
4430
+ // 🔴 **PDF 原页走另一条路**:那里不套 span,只给已有元素打标记。
4431
+ // 文字层是「绝对定位行盒 → 定宽词盒 → 逐字符盒」,把字节点 extractContents 出来
4432
+ // 塞进新 span 会让它们退回普通行内流:位置全歪、背景框压在相邻文字上(实测截图)。
4433
+ // 打标记不改 DOM 结构,背景就落在字形自己的盒子上,大小刚好。
4434
+ if (typeof node.querySelectorAll === 'function' && node.closest?.('.paper-pdf-text') != null) {
4435
+ const markId = spanId()
4436
+ const marked = []
4437
+ for (const piece of pieces) {
4438
+ // 逐字符渲染时落点是 .paper-pdf-char,整词时是 .paper-pdf-word。
4439
+ // 跨字符的那一段要把沿途**每个**字符都标上 —— 只标首尾会漏掉中间几个字,
4440
+ // 表现就是「[41, 44, 13, 16] 里只有一两个字能悬停」。
4441
+ const hostElement = piece.node.parentNode
4442
+ if (hostElement === null || hostElement === undefined) continue
4443
+ if (!marked.includes(hostElement)) marked.push(hostElement)
4444
+ }
4445
+ for (const element of marked) {
4446
+ if (element === node) continue
4447
+ element.setAttribute('data-cite', hit.part.type)
4448
+ element.setAttribute('data-cite-key', String(hit.part.value ?? ''))
4449
+ if (hit.part.items !== undefined) element.setAttribute('data-cite-items', hit.part.items.join(','))
4450
+ if (hit.part.surname !== undefined) element.setAttribute('data-cite-surname', String(hit.part.surname))
4451
+ if (hit.part.year !== undefined) element.setAttribute('data-cite-year', String(hit.part.year))
4452
+ if (hit.part.ambiguous === true) element.setAttribute('data-cite-ambiguous', String(hit.part.count ?? 2))
4453
+ element.setAttribute('data-cite-span', markId)
4454
+ }
4455
+ if (marked.length > 0) painted += 1
4456
+ continue
4457
+ }
4458
+ const span = doc.createElement('span')
4459
+ span.className = 'paper-cite'
4460
+ span.setAttribute('data-cite', hit.part.type)
4461
+ span.setAttribute('data-cite-key', String(hit.part.value ?? ''))
4462
+ if (hit.part.items !== undefined) span.setAttribute('data-cite-items', hit.part.items.join(','))
4463
+ if (hit.part.surname !== undefined) span.setAttribute('data-cite-surname', String(hit.part.surname))
4464
+ if (hit.part.year !== undefined) span.setAttribute('data-cite-year', String(hit.part.year))
4465
+ if (hit.part.ambiguous === true) span.setAttribute('data-cite-ambiguous', String(hit.part.count ?? 2))
4466
+ span.setAttribute('data-cite-span', spanId())
4467
+ try {
4468
+ if (pieces.length === 1) {
4469
+ // 最常见:标记在一个文本节点里(正文栏的段落)。
4470
+ const range = doc.createRange()
4471
+ range.setStart(first.node, first.start)
4472
+ range.setEnd(first.node, first.end)
4473
+ range.surroundContents(span)
4474
+ } else {
4475
+ // 逐字符渲染:把标记覆盖到的那些节点整体搬进 span。
4476
+ // 🔴 用 extractContents 而不是 surroundContents —— 后者跨节点必抛。
4477
+ const range = doc.createRange()
4478
+ range.setStart(first.node, first.start)
4479
+ const last = pieces[pieces.length - 1]
4480
+ range.setEnd(last.node, last.end)
4481
+ span.appendChild(range.extractContents())
4482
+ range.insertNode(span)
4483
+ }
4484
+ painted += 1
4485
+ } catch {
4486
+ // 跨元素边界等失败的情况跳过:宁可这一处没有悬停,也不破坏正文。
4487
+ }
4488
+ }
4489
+ }
4490
+ return painted
4491
+ }
4492
+
3651
4493
  function readerBlockNode(line, row, options) {
3652
4494
  const payload = row?.payload ?? null
3653
4495
  const tag = line.column === "src" ? "p" : line.tag
@@ -3788,6 +4630,17 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
3788
4630
  const matchingMarks = React.useRef(new Set())
3789
4631
  const [matchingIds, setMatchingIds] = React.useState([])
3790
4632
  const markDraftEpoch = React.useRef(0)
4633
+ // ---- 引用悬停预览(T25b)----
4634
+ // cite = { key, type, anchor: {left, top, bottom}, entries: [{blockId, text}], ambiguous }
4635
+ // 只存**已经解析好**的内容:悬停时查表,不在这里做任何匹配计算。
4636
+ const [citeHover, setCiteHover] = React.useState(null)
4637
+ const citeTimer = React.useRef(null)
4638
+ /** 当前亮着的整组元素。见 showCite 的说明:PDF 逐字符渲染,高亮不能靠 CSS :hover。
4639
+ * 用 ref 而不是 state:它只管 DOM 类的加减,本身不参与渲染。 */
4640
+ const citeGroupOfMarked = React.useRef([])
4641
+ /** 悬停处理函数经它转存给 PDF 页面树 —— 那棵树在本组件渲染期构建,早于下面两个
4642
+ * const 的初始化位置(见 PDF 块上的注释)。初始值是空操作,避免 ref 未装时报错。 */
4643
+ const citeHandlersRef = React.useRef({ over: () => {}, out: () => {} })
3791
4644
  // ---- 选区即时释义(D160) ----
3792
4645
  // 条上那一行译文的状态:null / pending / ready / failed / no-text。每一项都带 key,
3793
4646
  // 换过选区之后晚到的回复据此丢弃(否则 A 的译文会覆盖到 B 那一行上)。
@@ -4160,9 +5013,25 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
4160
5013
  // 并排时把「我读到哪一段」广播给另一格(D183)。只在并排里发 —— 单格时没有听众,
4161
5014
  // 白算一次锚点。判据是本格是不是被分出来的那一格,或对面那格有没有登记过存在。
4162
5015
  if (!paneSyncLiveRef.current) return
4163
- // 回声屏蔽(D185 / D189):跟随途中或刚跟完的静默窗口里一律不广播。
4164
- // 🔴 只比「游标是否正好落在目标块上」不够了:跟随是**逐帧**靠近的,途中游标会扫过
4165
- // 一串中间块,每一个都会被当成"读者滚到了这里"推回去,两格就互相拖着走。
5016
+ // 🔴 **手动滚动优先于跟随**(2026-11-20 用户实测抓出)。
5017
+ //
5018
+ // 现象:并排里先在译文滚,原文跟着滚;接着去滚原文,**原文一动不动**。反过来一样。
5019
+ //
5020
+ // 根因不是渲染,是这里原来只 `return` 了事:
5021
+ //
5022
+ // ```text
5023
+ // A 滚 → 广播 → B 的 paneFollowRef 非空、排上 requestAnimationFrame
5024
+ // runFollow 每帧 container.scrollTop = next,并把 hold 推到 now+120ms
5025
+ // 用户去滚 B → onReaderScroll 被 hold 拦下 return(既不广播,也不取消 follow)
5026
+ // → 但 runFollow 还在跑,下一帧又把 B 拉回去 → 用户看到「滚不动」
5027
+ // ```
5028
+ //
5029
+ // 所以静默窗口只该压**广播**,不能顺手把用户的操作也压掉。用户真的滚动时,
5030
+ // 必须立刻终止本格的跟随,并把状态交还给用户。
5031
+ // 🔴 **不能靠 scroll 事件本身来区分「用户」和「回声」**:回声也是 scroll 事件,
5032
+ // 而且它在 paneFollowRef 还有效时就到了 —— 拿它取消跟随,跟随会被自己的尾巴打断,
5033
+ // 永远收敛不了。真正的用户信号只有**输入事件**(滚轮 / 触摸 / 指针 / 按键),
5034
+ // 所以那一路单独取消跟随(见 stopFollowForUser),这里仍然只压广播。
4166
5035
  if (Date.now() < paneSyncHoldRef.current.until) return
4167
5036
  publishScrollAnchor(readerRef.current, cursor.block, paneRole, anchor === null ? 0 : anchor.ratio)
4168
5037
  }
@@ -4218,11 +5087,54 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
4218
5087
  }
4219
5088
  if (typeof requestAnimationFrame === 'function') paneFollowFrameRef.current = requestAnimationFrame(runFollow)
4220
5089
  }
5090
+ /**
5091
+ * 用户一旦真的动手,立刻交出控制权(2026-11-20 用户实测)。
5092
+ *
5093
+ * 🔴 判据必须用**输入事件**,不能用 scroll 事件:跟随自身每帧设 scrollTop,
5094
+ * 它产生的 scroll 事件与用户的混在一起,拿来判断会把跟随自己的尾巴当成人手,
5095
+ * 跟随永远收敛不了。滚轮、触摸、指针按下、方向键 —— 这些只可能来自用户。
5096
+ *
5097
+ * 不这么做的后果(实测):A 格滚完,B 格的 runFollow 还在跑;用户去滚 B,
5098
+ * 每帧被拉回 A 的位置,表现出来就是「这一格滚不动」,且要等 follow 自己收敛才恢复。
5099
+ */
5100
+ const stopFollowForUser = () => {
5101
+ if (paneFollowRef.current === null && paneFollowFrameRef.current === null)
5102
+ return
5103
+ paneFollowRef.current = null
5104
+ if (paneFollowFrameRef.current !== null && typeof cancelAnimationFrame === 'function')
5105
+ cancelAnimationFrame(paneFollowFrameRef.current)
5106
+ paneFollowFrameRef.current = null
5107
+ // 窗口一起撤掉:下一帧用户的真实滚动应当照常广播给对面。
5108
+ paneSyncHoldRef.current.until = 0
5109
+ }
5110
+ // 🔴 **监听挂在第一次真正收到锚点上,不在 effect 开头**(2026-11-20)。
5111
+ //
5112
+ // 这个 effect 的依赖是 [paneRole, paneView],它不能保证在 layoutRef 回调 ref
5113
+ // 赋值之后再跑一次。effect 开头直接读 `layoutElRef.current` 可能拿到 null,
5114
+ // 于是监听静默没挂上 —— 而用户看到的仍然是「滚不动」,且没有任何报错。
5115
+ // 收到锚点时容器一定已经挂好(锚点就是从滚动容器里发出来的),在那儿挂最稳。
5116
+ let settled = null
5117
+ const bindUserStop = () => {
5118
+ const node = layoutElRef.current
5119
+ if (node === null || node === settled || typeof node?.addEventListener !== 'function') return
5120
+ if (settled !== null && typeof settled.removeEventListener === 'function') {
5121
+ settled.removeEventListener('wheel', stopFollowForUser)
5122
+ settled.removeEventListener('touchmove', stopFollowForUser)
5123
+ settled.removeEventListener('pointerdown', stopFollowForUser)
5124
+ settled.removeEventListener('keydown', stopFollowForUser)
5125
+ }
5126
+ settled = node
5127
+ settled.addEventListener('wheel', stopFollowForUser, { passive: true })
5128
+ settled.addEventListener('touchmove', stopFollowForUser, { passive: true })
5129
+ settled.addEventListener('pointerdown', stopFollowForUser, { passive: true })
5130
+ settled.addEventListener('keydown', stopFollowForUser)
5131
+ }
4221
5132
  const stop = subscribeScrollAnchor(anchor => {
4222
5133
  if (!shouldFollowAnchor(anchor, { live: paneSyncLiveRef.current, role: paneRole, documentId: readerRef.current })) return
4223
5134
  const container = layoutElRef.current
4224
5135
  if (container === null || typeof container !== 'object') return
4225
5136
  if (blockNodeOf(container, anchor.blockId) === null) return
5137
+ bindUserStop()
4226
5138
  paneFollowRef.current = { blockId: anchor.blockId, ratio: anchor.ratio }
4227
5139
  // 已经有一帧在等就复用它:锚点每秒会来几十次,每次都排一帧等于自己跟自己打架。
4228
5140
  if (paneFollowFrameRef.current === null && typeof requestAnimationFrame === 'function') {
@@ -4231,11 +5143,17 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
4231
5143
  })
4232
5144
  return () => {
4233
5145
  stop()
5146
+ if (settled !== null && typeof settled.removeEventListener === 'function') {
5147
+ settled.removeEventListener('wheel', stopFollowForUser)
5148
+ settled.removeEventListener('touchmove', stopFollowForUser)
5149
+ settled.removeEventListener('pointerdown', stopFollowForUser)
5150
+ settled.removeEventListener('keydown', stopFollowForUser)
5151
+ }
4234
5152
  if (paneFollowFrameRef.current !== null && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(paneFollowFrameRef.current)
4235
5153
  paneFollowFrameRef.current = null
4236
5154
  paneFollowRef.current = null
4237
5155
  }
4238
- }, [paneRole, paneView])
5156
+ }, [paneRole, paneView, readerId])
4239
5157
 
4240
5158
  // ---- 阅读器(T16b) ----
4241
5159
  // 进入阅读器时拉一次 /reader。**只在进入时拉**,不挂轮询:/reader 会带一整篇的块,
@@ -5379,7 +6297,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
5379
6297
  // ---- PDF page and native selection layer ----
5380
6298
  const firstPage = React.useMemo(() => (readerBlocks.find(row => typeof row.page === 'number')?.page) ?? 1, [readerBlocks])
5381
6299
  const currentPage = readerPage === null ? firstPage : readerPage
5382
- const activePdf = pdfData?.documentId === readerId && pdfData.page === currentPage ? pdfData : null
6300
+ const activePdf = pdfData?.documentId === readerId && pdfData.page === currentPage && pdfData.cropped === pdfCrop ? pdfData : null
5383
6301
  async function loadPdfPage(documentId = readerId, page = currentPage, force = false) {
5384
6302
  if (!documentId) return
5385
6303
  if (force) setPdfImageAttempt(value => value + 1)
@@ -5462,6 +6380,13 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
5462
6380
  style: { left: bounds[0] * activePdf.width / 1000, top: bounds[1] * activePdf.height / 1000,
5463
6381
  width: (bounds[2] - bounds[0]) * activePdf.width / 1000, height: (bounds[3] - bounds[1]) * activePdf.height / 1000 },
5464
6382
  onMouseUp: event => { event.stopPropagation?.(); captureSelection(event, true) },
6383
+ // 引用悬停(T25b):原页这侧的引用标记同样是 paintCiteSpans 事后包出来的
6384
+ // (文字层的字符 span 就是 DOM 文字,包法与正文栏一致)。
6385
+ // 🔴 走 ref 转存而不是直接引用那两个箭头函数:PDF 页面树的 useMemo 在本组件的
6386
+ // 渲染期就执行,那时后面的 const 还处于 TDZ —— 直接引用会抛
6387
+ // "Cannot access 'onCiteOver' before initialization"(本机实测踩过)。
6388
+ onMouseOver: event => citeHandlersRef.current.over(event),
6389
+ onMouseOut: event => citeHandlersRef.current.out(event),
5465
6390
  }, rows.map((row, rowIndex) => {
5466
6391
  const size = Math.max(1, (row.bottom - row.top) * activePdf.height / 1000)
5467
6392
  const rowWidth = (row.words.at(-1).bbox[2] - row.words[0].bbox[0]) * activePdf.width / 1000
@@ -5493,32 +6418,43 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
5493
6418
  // 也是词与词之间那段**要被子选区覆盖**的宽度来源。
5494
6419
  const core = word.text
5495
6420
  const box = width + gap
5496
- // 把不可见的文字**拉伸到整个词框**(含词间距)。文字本身全透明,拉多宽都看不见;
5497
- // 但浏览器是沿字形推进宽度画选区的 —— 不拉满,词与词之间就露出那几条缝。
5498
- //
5499
- // 🔴 只改 letterSpacing,不给字形定宽:定宽会让 Chromium 在词尾放错光标。
5500
- // 🔴 字距只摊到**字形**上,词尾空格不参与等分(PITFALLS 99):按整串(含空格)等分会让空格分走
5501
- // 一截、字形被挤窄,词内每个字都比页图往左偏一点,位置越靠后偏得越多。
5502
- // 空格自己本来就占着那一格,字距只补字形与词框之间的差额。
5503
- const glyphs = core.replace(/\s+$/, '')
6421
+ const nativeChars = pdfGlyphAdvances(word, activePdf.width / 1000)
6422
+ // 词盒仍取字框 + 词间隙,但浏览器选择范围必须有两个独立终点:
6423
+ // 字形的右沿对齐 PDF bbox[2],尾空格才延伸到下一个词 bbox[0]。
6424
+ // 原实现把整盒宽度摊给字形(只用 letter-spacing),本词最后几个字会越过 PDF 字框;
6425
+ // CSS 再以 overflow:hidden 截断选区,视觉上就像蓝色区域和文字错位。
6426
+ // 🔴 不用 scaleX:字符光标及 Range 的字形位置必须继续由浏览器正常排版。
5504
6427
  const stretch = node => {
5505
- if (!node || !(box > 0)) return
6428
+ if (!node || !(width > 0)) return
6429
+ const context = pdfMeasureRef.current ??= document.createElement('canvas').getContext?.('2d')
6430
+ if (!context) return
6431
+ context.font = size + 'px serif'
6432
+ const metrics = pdfWordMetrics(core, width, gap, text => context.measureText(text).width)
6433
+ if (!metrics) return
6434
+ node.style.letterSpacing = metrics.letterSpacing + 'px'
6435
+ node.style.wordSpacing = metrics.wordSpacing + 'px'
6436
+ }
6437
+ // 逐字对齐时,每个独立文本 span 只包含一个 PDF 字符。
6438
+ // CSS 的末字 letter-spacing 会自然画满字符与下一个字符之间的空当;
6439
+ // 选区由连续的原生文本节点组成,不会在两个字符之间留下蓝色断缝。
6440
+ const stretchChar = (node, advance) => {
6441
+ if (!node) return
5506
6442
  const context = pdfMeasureRef.current ??= document.createElement('canvas').getContext?.('2d')
5507
6443
  if (!context) return
5508
6444
  context.font = size + 'px serif'
5509
- const measured = context.measureText(core).width
5510
- const glyphMeasured = context.measureText(glyphs).width
5511
- const spaceWidth = measured - glyphMeasured
5512
- const count = Array.from(glyphs).length
5513
- if (glyphMeasured > 0 && count > 0) node.style.letterSpacing = (box - spaceWidth - glyphMeasured) / count + 'px'
6445
+ node.style.letterSpacing = (advance - context.measureText(node.textContent).width) + 'px'
5514
6446
  }
5515
6447
  return h('span', {
5516
6448
  className: 'paper-pdf-word', key: index,
5517
- ref: stretch,
6449
+ ref: nativeChars ? undefined : stretch,
5518
6450
  style: { width: box, height: band, lineHeight: size + 'px', fontSize: size,
6451
+ letterSpacing: 'normal', wordSpacing: 'normal',
5519
6452
  boxSizing: 'border-box', paddingTop: before,
5520
6453
  marginLeft: index > 0 ? Math.min(0, word.bbox[0] - row.words[index - 1].bbox[2]) * activePdf.width / 1000 : 0 },
5521
- }, core)
6454
+ }, nativeChars ? nativeChars.map((char, i) => h('span', {
6455
+ className: 'paper-pdf-char', key: i,
6456
+ ref: node => stretchChar(node, char.advance),
6457
+ }, char.text)) : core)
5522
6458
  }))
5523
6459
  }))
5524
6460
  })) : null), [activePdf, readerId, currentPage, pdfZoom, pdfImageAttempt, pdfCrop])
@@ -5659,6 +6595,198 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
5659
6595
  )
5660
6596
  return undefined
5661
6597
  }, [highlightSupport, view, reader, marks, paneView, activePdf])
6598
+ // ---- 引用悬停预览(T25b)----
6599
+ // 与划线同一范式:渲染树不动,effect 里把已挂载的 DOM 包上 span(见 paintCiteSpans)。
6600
+ // 依赖与划线那条一致 —— 正文 DOM 会在切换档位时重建,span 必须跟着重包。
6601
+ // 解析后的查找表:编号 → 原文、姓氏|年份 → 原文。只在 blocks 变化时重建一次,
6602
+ // 悬停时只做 Map 查询 —— 每次鼠标移动都重扫几千条参考文献是不可接受的。
6603
+ const citeLookup = React.useMemo(() => ({
6604
+ numbers: referenceTexts(reader?.blocks),
6605
+ authors: authorYearIndex(reader?.blocks),
6606
+ }), [reader])
6607
+ // 🔴 渲染行按 id 建索引**只在换篇时做一次**。早先这段在 effect 体内,每次依赖变化
6608
+ // 都要重建 400+ 项的 Map —— 翻页、缩放、切档位都跑一遍,纯属浪费。
6609
+ const citeRowsById = React.useMemo(() => {
6610
+ const map = new Map()
6611
+ for (const row of readerBlocks) {
6612
+ if (typeof row?.id === 'string') map.set(row.id, row)
6613
+ }
6614
+ return map
6615
+ }, [readerBlocks])
6616
+ // 最后一次涂过的「容器 + 内容签名」。DOM 没被重建、块内容也没变就不必重扫。
6617
+ const citePaintedRef = React.useRef({ layout: '', pdf: '' })
6618
+ React.useEffect(() => {
6619
+ if (view !== 'reader') {
6620
+ citePaintedRef.current = { layout: '', pdf: '' }
6621
+ return undefined
6622
+ }
6623
+ // 🔴 **两个容器都要涂**:正文栏挂在 layoutElRef,PDF 原页是另一个子树(pdfFrameRef)。
6624
+ // 只涂前者时原页那侧静默没有任何反应 —— 界面上看不出错,只是"悬停不管用"。
6625
+ // PDF 这侧的块文本以文字层 group.text 为准(与划线那条同一口径),否则段落正文与
6626
+ // 页面上真实的字对不上,找位置会失败。
6627
+ const pdfMode = isPdfPane(paneView) && activePdf !== null
6628
+ const blocks = pdfMode
6629
+ ? (reader?.blocks ?? []).map(block => {
6630
+ const group = activePdf.groups.find(item => item.id === block.id)
6631
+ return group ? { ...block, sourceText: group.text } : block
6632
+ })
6633
+ : reader?.blocks
6634
+ const parts = citePartsOf(citeRowsById, blocks, readerNumbers(blocks ?? []))
6635
+ // 内容签名:**块 id + 该块标记原文**逐个拼起来。只看数量是不够的 —— 换一篇论文
6636
+ // 完全可能块数与标记数都不变而内容全变,那时按数量判会漏涂。
6637
+ // 拼接是 O(标记数),比重新扫几千个文本节点便宜两个数量级。
6638
+ let signature = String((blocks ?? []).length)
6639
+ for (const [blockId, tags] of parts) {
6640
+ signature += '|' + blockId
6641
+ for (const tag of tags) signature += ',' + (tag.raw ?? tag.value ?? '')
6642
+ }
6643
+ // 正文栏的 key 带上档位:切原文 / 译文 / 双语时渲染的是不同的行集合
6644
+ // (visibleRows 按 paneView 取),React 会重建这批段落节点。
6645
+ const layoutKey = `${paneView}:${layout}:${signature}`
6646
+ const painted = citePaintedRef.current
6647
+ // 🔴 签名只是**省钱的门槛,不是正确性的依据**:要不要重涂最终看 DOM 里标记还在不在。
6648
+ // 靠内容哈希判就得穷举「所有会让 React 重建这批节点的输入」—— 这一点漏过两次
6649
+ // (PDF 侧漏 pdfZoom、正文栏漏 paneView),每次都表现为"某个操作之后悬停整片失灵"。
6650
+ // 直接探测不必穷举:少列哪个输入都不会坏,代价只是一次 querySelectorAll。
6651
+ // 探测比的是**应有标记数**,不是"有没有标记":切档位后可能残留别的块的标记,
6652
+ // 只判存在会漏掉"这一块的标记没了"。
6653
+ const stillMarked = () => {
6654
+ const scope = layoutElRef.current
6655
+ if (scope === null || typeof scope?.querySelectorAll !== 'function') return false
6656
+ const found = scope.querySelectorAll('.paper-cite').length
6657
+ let expected = 0
6658
+ for (const tags of parts.values()) expected += tags.length
6659
+ return found >= expected
6660
+ }
6661
+ if (painted.layout !== layoutKey || !stillMarked()) {
6662
+ paintCiteSpans(layoutElRef.current ?? (typeof document !== 'undefined' ? document : null), parts)
6663
+ painted.layout = layoutKey
6664
+ }
6665
+ // 🔴 PDF 侧另有一份签名:**任何让页面树 useMemo 重算的输入**都会重建整棵子树并
6666
+ // 丢掉 data-cite-span,那时块内容可能一模一样,仍然必须重涂。
6667
+ // 页面树的依赖是 [activePdf, readerId, currentPage, pdfZoom, pdfImageAttempt, pdfCrop]
6668
+ // —— 少放一个就会出现「缩放之后悬停失灵」,而界面上完全不报错。
6669
+ const pdfKey = pdfMode
6670
+ ? `${activePdf.page}:${pdfCrop ? 1 : 0}:${currentPage}:${pdfZoom}:${pdfImageAttempt}:${signature}`
6671
+ : ''
6672
+ const pdfStillMarked = () => {
6673
+ const scope = pdfFrameRef.current
6674
+ if (scope === null || typeof scope?.querySelectorAll !== 'function') return false
6675
+ return scope.querySelectorAll('[data-cite-span]').length > 0
6676
+ }
6677
+ if (pdfKey !== '' && (painted.pdf !== pdfKey || !pdfStillMarked())) {
6678
+ paintCiteSpans(pdfFrameRef.current, parts)
6679
+ painted.pdf = pdfKey
6680
+ } else if (pdfKey === '') {
6681
+ painted.pdf = ''
6682
+ }
6683
+ return undefined
6684
+ // readerBlocks 在依赖里:渲染行变了(换篇、重解析)标记位置也跟着变。
6685
+ // currentPage 在依赖里:PDF 原页翻页是**整棵子树重建**,不重涂新页就没有悬停。
6686
+ }, [view, reader, readerBlocks, paneView, activePdf, currentPage, pdfZoom, pdfCrop, pdfImageAttempt])
6687
+ React.useEffect(() => () => { if (citeTimer.current) clearTimeout(citeTimer.current) }, [])
6688
+ /**
6689
+ * 指针落进/离开一个引用标记。
6690
+ *
6691
+ * 悬停进入有约 140ms 延迟:正文里引用很密,鼠标划过时立刻弹窗会一路闪。
6692
+ * 离开延迟 100ms 且**可被取消** —— 指针从标记移到浮层上时不该关掉它。
6693
+ */
6694
+ const citeUnder = event => {
6695
+ let node = event?.target ?? null
6696
+ // 🔴 判据用 `data-cite-span`:**两侧的标记元素都带它**(正文栏的 .paper-cite 与
6697
+ // PDF 的字形元素),而组号悬停时本来就要读,一次 getAttribute 拿到两样东西。
6698
+ // 这个函数在 PDF 上每次 mousemove 都跑,且要爬 3~4 层(字符 → 词 → 行 → 块)。
6699
+ while (node && typeof node.getAttribute === 'function') {
6700
+ if (node.getAttribute('data-cite-span') !== null) return node
6701
+ node = node.parentNode
6702
+ }
6703
+ return null
6704
+ }
6705
+ /**
6706
+ * 同一引用标记的整组一起高亮。
6707
+ *
6708
+ * 🔴 PDF 文字层逐字符渲染,`[41, 44, 13, 16]` 会拆成十几个独立元素。CSS 的 `:hover`
6709
+ * 只命中鼠标正下方那一个 —— 实测"只有指着的那一个字变色"。所以高亮状态由这里按组号写,
6710
+ * 而不是交给 CSS 伪类。组号是 paintCiteSpans 打在**同一处标记**全部元素上的
6711
+ * `data-cite-span`;清掉旧的再加新的,保证同一时刻只有一组亮着。
6712
+ */
6713
+ const citeGroup = node => {
6714
+ const id = node.getAttribute('data-cite-span')
6715
+ const root = node.ownerDocument ?? (typeof document === 'undefined' ? null : document)
6716
+ if (id === null || id === '' || root === null) return []
6717
+ const scope = pdfFrameRef.current ?? root
6718
+ if (typeof scope.querySelectorAll !== 'function') return []
6719
+ return [...scope.querySelectorAll('[data-cite-span]')].filter(item => item.getAttribute('data-cite-span') === id)
6720
+ }
6721
+ const clearCiteGroup = () => {
6722
+ for (const node of citeGroupOfMarked.current) node.classList?.remove('is-cite-active')
6723
+ citeGroupOfMarked.current = []
6724
+ }
6725
+ const showCite = node => {
6726
+ clearCiteGroup()
6727
+ for (const item of citeGroup(node)) {
6728
+ item.classList?.add('is-cite-active')
6729
+ citeGroupOfMarked.current.push(item)
6730
+ }
6731
+ const key = node.getAttribute('data-cite-key') ?? ''
6732
+ const type = node.getAttribute('data-cite') ?? 'ref'
6733
+ let entries = []
6734
+ let ambiguous = 0
6735
+ if (type === 'ref') {
6736
+ // 多标号:data-cite-items 是逗号分隔的全部编号,逐条查。
6737
+ const items = String(node.getAttribute('data-cite-items') ?? (key === '' ? '' : key)).split(',')
6738
+ for (const number of items) {
6739
+ const hit = citeLookup.numbers.get(number)
6740
+ if (hit !== undefined) entries.push(hit)
6741
+ }
6742
+ } else {
6743
+ entries = ambiguousLookup(
6744
+ citeLookup.authors,
6745
+ node.getAttribute('data-cite-surname') ?? '',
6746
+ node.getAttribute('data-cite-year') ?? '',
6747
+ )
6748
+ }
6749
+ ambiguous = Number(node.getAttribute('data-cite-ambiguous') ?? 0)
6750
+ if (entries.length === 0) return
6751
+ const box = typeof node.getBoundingClientRect === 'function' ? node.getBoundingClientRect() : null
6752
+ setCiteHover({
6753
+ key: `${type}:${key}`,
6754
+ type,
6755
+ entries,
6756
+ ambiguous: Number.isFinite(ambiguous) ? ambiguous : 0,
6757
+ anchor: box === null ? null : { left: box.left, top: box.top, bottom: box.bottom },
6758
+ })
6759
+ }
6760
+ const onCiteOver = event => {
6761
+ const node = citeUnder(event)
6762
+ if (node === null) return
6763
+ if (citeTimer.current) { clearTimeout(citeTimer.current); citeTimer.current = null }
6764
+ citeTimer.current = setTimeout(() => { citeTimer.current = null; showCite(node) }, 140)
6765
+ }
6766
+ const onCiteOut = event => {
6767
+ const node = citeUnder(event)
6768
+ const next = event?.relatedTarget ?? null
6769
+ // 移到浮层里(或浮层内部的另一个节点)时保持显示。
6770
+ let inside = next
6771
+ while (inside && typeof inside.getAttribute === 'function') {
6772
+ if (inside.getAttribute('data-cite-pop') !== null) return
6773
+ inside = inside.parentNode
6774
+ }
6775
+ // 同一组内换字(PDF 逐字符,指针从 4 移到 1 就是跨了元素):不算离开。
6776
+ if (node !== null && next !== null) {
6777
+ const id = node.getAttribute('data-cite-span')
6778
+ let probe = next
6779
+ while (probe && typeof probe.getAttribute === 'function') {
6780
+ if (probe.getAttribute('data-cite-span') === id) return
6781
+ probe = probe.parentNode
6782
+ }
6783
+ }
6784
+ if (citeTimer.current) { clearTimeout(citeTimer.current); citeTimer.current = null }
6785
+ clearCiteGroup()
6786
+ setCiteHover(null)
6787
+ }
6788
+ // 每轮渲染后把最新的处理函数交给 PDF 页面树(它是渲染期构建的,拿不到这两个 const)。
6789
+ citeHandlersRef.current = { over: onCiteOver, out: onCiteOut }
5662
6790
  const editClickedMark = event => {
5663
6791
  const selection = window.getSelection?.()
5664
6792
  if (selection && !selection.isCollapsed && String(selection).trim()) return
@@ -6099,6 +7227,10 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
6099
7227
  ref: layoutRef,
6100
7228
  className: 'paper-reader-layout',
6101
7229
  onClick: editClickedMark,
7230
+ // 引用悬停(T25b):事件委托挂在整个正文容器上,标记 span 是事后由
7231
+ // paintCiteSpans 包出来的 —— 逐个挂监听会在每次重涂后全部失效。
7232
+ onMouseOver: onCiteOver,
7233
+ onMouseOut: onCiteOut,
6102
7234
  // 阅读位置靠这条(D163):正文自己的滚动容器才知道"视口上沿那一块"是谁。
6103
7235
  onScroll: isPdfPane(paneView) ? undefined : onReaderScroll,
6104
7236
  onMouseUp: isPdfPane(paneView) ? event => {
@@ -6157,6 +7289,23 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
6157
7289
  }, '让 AI 点评')))
6158
7290
  return [node, ...inlineNotes]
6159
7291
  }))]),
7292
+ // ---- 引用悬停浮层(T25b)----
7293
+ // 定位与 .paper-mark-draft 同一套(fixed + 状态里的坐标),但内容只读:
7294
+ // 一段一条参考文献原文,不提供任何会改动数据的按钮。
7295
+ citeHover !== null && h('div', {
7296
+ className: 'paper-cite-pop',
7297
+ 'data-cite-pop': citeHover.key,
7298
+ role: 'tooltip',
7299
+ 'aria-label': '参考文献',
7300
+ style: citePopStyle(citeHover),
7301
+ onMouseEnter: () => { if (citeTimer.current) { clearTimeout(citeTimer.current); citeTimer.current = null } },
7302
+ onMouseLeave: () => setCiteHover(null),
7303
+ },
7304
+ citeHover.entries.map((entry, at) => h('div', {
7305
+ className: 'paper-cite-entry',
7306
+ key: `${entry.blockId}-${at}`,
7307
+ }, entry.text)),
7308
+ citeHover.ambiguous > 1 && h('div', { className: 'paper-cite-note' }, `共 ${citeHover.ambiguous} 条可能匹配`)),
6160
7309
  pendingMark !== null && h('div', {
6161
7310
  className: 'paper-mark-draft',
6162
7311
  ref: markPopoverRef,
@@ -9471,6 +10620,9 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
9471
10620
  // 文本级高亮(D167)的纯函数:显示文本里的原话区间、每块的第一条计划、跨块夹回、
9472
10621
  // 挂高亮的核心过程(scope/names 进出,测试喂假 DOM)。
9473
10622
  exports.quoteSpanPlan = quoteSpanPlan
10623
+ exports.locateQuoteIgnoringSpace = locateQuoteIgnoringSpace
10624
+ exports.locateQuoteAcrossFormulas = locateQuoteAcrossFormulas
10625
+ exports.formulaSplit = formulaSplit
9474
10626
  // 中英匹配(D171):句级切分与跨列映射,测试直接喂中英两列断言。
9475
10627
  exports.sentenceSpans = sentenceSpans
9476
10628
  exports.crossSentenceSpan = crossSentenceSpan
@@ -9484,6 +10636,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
9484
10636
  exports.glossRow = glossRow
9485
10637
  exports.glossSegmentOf = glossSegmentOf
9486
10638
  exports.formulaSelectionText = formulaSelectionText
10639
+ exports.pdfGlyphAdvances = pdfGlyphAdvances
10640
+ exports.pdfWordMetrics = pdfWordMetrics
9487
10641
  exports.selectionTextInBlock = selectionTextInBlock
9488
10642
  // 跨块选区(D46):按块收集、分段视图、多段原话。纯函数,测试直接喂假 DOM 与草稿。
9489
10643
  exports.selectionSegmentInNode = selectionSegmentInNode
@@ -9553,6 +10707,17 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
9553
10707
  // 引用索引与「这一段引了谁」(P6):纯函数,测试直接断言。
9554
10708
  exports.referenceIndex = referenceIndex
9555
10709
  exports.citedNumbersOf = citedNumbersOf
10710
+ // 悬停预览(T25b):编号 → 条目原文,以及作者-年份制那条独立链路。
10711
+ exports.referenceTexts = referenceTexts
10712
+ exports.refItemsOf = refItemsOf
10713
+ // 引用装饰层的两个纯函数:跨节点定位的判据都在这里,测试直接断言。
10714
+ exports.citeTextRuns = citeTextRuns
10715
+ exports.citeSlice = citeSlice
10716
+ exports.citeLocate = citeLocate
10717
+ exports.citePartsOf = citePartsOf
10718
+ exports.paintCiteSpans = paintCiteSpans
10719
+ exports.authorYearIndex = authorYearIndex
10720
+ exports.inlineAuthors = inlineAuthors
9556
10721
  // 正文渲染的档位与本地化文案:视图区按引用传给 MarkdownText,不能在渲染里新建对象。
9557
10722
  exports.MARKDOWN_VARIANT = MARKDOWN_VARIANT
9558
10723
  exports.MARKDOWN_LABELS = MARKDOWN_LABELS