@li-canghai/dsh-paper 0.8.2 → 0.8.6
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/README.md +42 -93
- package/THIRD_PARTY_NOTICES.md +69 -0
- package/lib/annotate-tool.js +58 -10
- package/lib/block-cache.js +45 -26
- package/lib/blocks-reconcile.js +56 -17
- package/lib/client-parts/01-pure-helpers.js +216 -7
- package/lib/client-parts/02-author-year.js +111 -24
- package/lib/client-parts/03-pdf-stack.js +97 -0
- package/lib/client.js +1206 -293
- package/lib/code-source.js +8 -8
- package/lib/discussion.js +2 -101
- package/lib/export.js +228 -14
- package/lib/file-lock.js +128 -16
- package/lib/gloss.js +12 -3
- package/lib/index.js +137 -68
- package/lib/inline-html.js +1 -1
- package/lib/item-ops.js +14 -2
- package/lib/library-service.js +32 -8
- package/lib/library-tool.js +6 -0
- package/lib/metadata-enrichment.js +8 -1
- package/lib/pdf-analysis-tool.js +72 -0
- package/lib/pdf-page.js +600 -8
- package/lib/picker.js +19 -5
- package/lib/reader-store.js +14 -10
- package/lib/rename-document.js +25 -3
- package/lib/search-index.js +0 -9
- package/lib/selection-message.js +2 -3
- package/lib/storage.js +122 -10
- package/lib/store-paths.js +0 -13
- package/lib/table-gfm.js +42 -14
- package/lib/tex-fetch.js +0 -1
- package/lib/tex-merge.js +0 -1
- package/lib/tex-prepare.js +74 -13
- package/lib/text-similarity.js +0 -9
- package/lib/tool-host.js +4 -1
- package/lib/translate-queue.js +1 -34
- package/lib/translate-task.js +1 -1
- package/lib/translate.js +57 -26
- package/lib/update-contracts.js +5 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -2
package/lib/client.js
CHANGED
|
@@ -144,7 +144,9 @@ function createLibraryModel() {
|
|
|
144
144
|
// 正文富渲染用宿主自带的 MarkdownText(micromark + KaTeX:GFM 表格/列表/围栏代码、
|
|
145
145
|
// 行内 $…$ 与行间 $$…$$ 公式)。该包在 PLATFORM_MODULES 里,取法与 react 完全一样,
|
|
146
146
|
// 所以客户端半不引任何第三方依赖、不加构建步骤。
|
|
147
|
-
|
|
147
|
+
// 下拉一律用宿主 primitives 的 Menu(见 selectControlOf 的说明),与 MarkdownText 同一个
|
|
148
|
+
// PLATFORM_MODULES 模块,取法完全一样:客户端半不引第三方依赖、不加构建步骤。
|
|
149
|
+
const { MarkdownText, Menu, MenuItemButton } = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
148
150
|
|
|
149
151
|
// BEGIN CLIENT PARTS
|
|
150
152
|
// 侧栏标题下的 MinerU 状态文案。三态:还没拿到 /state 时说"检查中",拿到后只看
|
|
@@ -196,6 +198,22 @@ function createLibraryModel() {
|
|
|
196
198
|
return jobKindOf(job) === JOB_KINDS.translate ? '翻译' : '解析'
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
// 卡片副标题:失败/中断时给原因,在跑时给「后台处理中」,并在有任务编号时把它露出来。
|
|
202
|
+
//
|
|
203
|
+
// 🔴 为什么要把编号显示给用户:模型回执里给的是**任务编号**,用户拿着它去问
|
|
204
|
+
// 「那批解析到哪了」时,得有个地方能看见同一个编号 —— 否则那个编号只存在于
|
|
205
|
+
// 聊天记录里,和面板对不上。翻译任务没有编号(不进任务清单),所以只加在解析卡片上。
|
|
206
|
+
function jobMetaText(job) {
|
|
207
|
+
const reason = typeof job?.error === 'string' && job.error !== ''
|
|
208
|
+
? job.error
|
|
209
|
+
: (jobKindOf(job) === JOB_KINDS.translate ? '后台翻译中' : '后台处理中')
|
|
210
|
+
// 只有解析任务进任务清单,翻译任务的编号即使被塞进来也不显示 —— 那个编号查不到东西。
|
|
211
|
+
const taskId = jobKindOf(job) === JOB_KINDS.parse && typeof job?.taskId === 'string' && job.taskId !== ''
|
|
212
|
+
? job.taskId
|
|
213
|
+
: ''
|
|
214
|
+
return taskId === '' ? reason : reason + ' · 编号 ' + taskId
|
|
215
|
+
}
|
|
216
|
+
|
|
199
217
|
// 一条翻译任务当前能做什么。纯函数,单测直接断言。
|
|
200
218
|
//
|
|
201
219
|
// 翻译是远程模型调用、有成本,所以按钮比解析那边收敛:
|
|
@@ -549,9 +567,19 @@ function createLibraryModel() {
|
|
|
549
567
|
}
|
|
550
568
|
const payload = readerPayloadOf(block, sourceText, id)
|
|
551
569
|
// 参考文献块自己**就是**跳转目标:它的 [7] 指向自己,标出来只会让人点了个原地不动。
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
570
|
+
//
|
|
571
|
+
// 🔴 **编号制没认出任何标记时才走作者-年份制**,判据是「有没有非 text 片段」而不是
|
|
572
|
+
// 「数组是不是空的」:没有编号的段落,inlineRefs 返回的是 `[{type:'text', …}]` ——
|
|
573
|
+
// 数组非空,但一个标记都没有。早先按长度判,于是作者-年份那一路在生产路径上**永远
|
|
574
|
+
// 不执行**:测试直接调 inlineAuthors 所以一直是绿的,界面上却怎么点都没反应。
|
|
575
|
+
let parts = []
|
|
576
|
+
if (payload.markdown === true && row.kind !== 'references') {
|
|
577
|
+
const numbered = inlineRefs(sourceText, numbers)
|
|
578
|
+
const cited = numbered.some(part => part.type !== 'text')
|
|
579
|
+
? numbered
|
|
580
|
+
: inlineAuthors(sourceText, numbers?.authorYears)
|
|
581
|
+
parts = cited.map((part, at) => inlinePart(part, index, at))
|
|
582
|
+
}
|
|
555
583
|
row.inline = { parts, source: parts.length > 0 ? sourceText : '' }
|
|
556
584
|
row.zhText = translated.text
|
|
557
585
|
row.zhRaw = translated.raw
|
|
@@ -591,9 +619,14 @@ function createLibraryModel() {
|
|
|
591
619
|
value: part.value ?? '',
|
|
592
620
|
text: part.text ?? '',
|
|
593
621
|
}
|
|
594
|
-
//
|
|
622
|
+
// 不带的字段**不补空值**:既有断言按字段全等,多一个 raw: undefined 也会红。
|
|
595
623
|
if (part.raw !== undefined) shape.raw = part.raw
|
|
596
624
|
if (part.items !== undefined) shape.items = part.items
|
|
625
|
+
// 🔴 作者-年份制靠这两项才能落到 DOM 上:paintCiteSpans 把它们写成 data-cite-surname /
|
|
626
|
+
// data-cite-year,showCite 再用这对键查浮层。丢了就只有标记没有内容 —— 悬停毫无反应,
|
|
627
|
+
// 而且不报错。与 raw/items 被丢是同一类问题,只是那一次丢的是编号制。
|
|
628
|
+
if (part.surname !== undefined) shape.surname = part.surname
|
|
629
|
+
if (part.year !== undefined) shape.year = part.year
|
|
597
630
|
return shape
|
|
598
631
|
}
|
|
599
632
|
|
|
@@ -794,6 +827,19 @@ function createLibraryModel() {
|
|
|
794
827
|
}
|
|
795
828
|
}
|
|
796
829
|
|
|
830
|
+
/**
|
|
831
|
+
* 一个块在某一页上的**完整正文**(所有 part 合起来)。
|
|
832
|
+
*
|
|
833
|
+
* 🔴 块可能被拆成多段 DOM(见宿主 pdf-page.js 的 splitRuns),但划线校验、
|
|
834
|
+
* 高亮定位、引用识别都按**整块**做 —— 只取第一段会漏掉被图或公式隔开的另一半。
|
|
835
|
+
* 与宿主 pdfBlockText 同口径:有 fullText 就用它,否则把各段拼起来。
|
|
836
|
+
*/
|
|
837
|
+
function pdfBlockTextOf(groups, blockId) {
|
|
838
|
+
const parts = (Array.isArray(groups) ? groups : []).filter(group => group?.id === blockId)
|
|
839
|
+
if (parts.length === 0) return ''
|
|
840
|
+
return parts[0].fullText ?? parts.map(part => part.text).join(' ')
|
|
841
|
+
}
|
|
842
|
+
|
|
797
843
|
/**
|
|
798
844
|
* 将 PDFium 原生字符的每个起点转换成浏览器可渲染的字符推进宽度。
|
|
799
845
|
* 单词字体、字重、连字均不可假定等于浏览器 serif,所以不能再让
|
|
@@ -2046,6 +2092,33 @@ function createLibraryModel() {
|
|
|
2046
2092
|
}
|
|
2047
2093
|
}
|
|
2048
2094
|
|
|
2095
|
+
/**
|
|
2096
|
+
* 图注这类**纯文本块**里出现的行内公式:只把 `$…$` 那几段交给渲染器,其余照旧字面显示。
|
|
2097
|
+
*
|
|
2098
|
+
* 🔴 为什么图注不走整段 Markdown(见 readerBlockNode):图注不成文,整段过 Markdown 会让
|
|
2099
|
+
* 下划线变斜体、星号变强调("Figure 3 * p<0.05" 会被吃掉一半)。但**同时**图注里确实
|
|
2100
|
+
* 夹着公式 —— 实测 STITCH 的 Figure 2 图注是
|
|
2101
|
+
* `Thematic Scope $( \sigma _ { t } ) .$`,纯文本渲染的结果就是满屏的 `$(\sigma_{t})$`。
|
|
2102
|
+
* 所以按**公式边界**切开:公式段原样送进 MarkdownText(KaTeX 会渲染它),文字段照旧
|
|
2103
|
+
* 按纯文本显示。既保住了「图注不做强调解析」,也让公式真的排出来。
|
|
2104
|
+
*
|
|
2105
|
+
* @param {unknown} value 图注原文
|
|
2106
|
+
* @returns {Array<{text: string, math: boolean}>} 按顺序切出的片段;没有公式时只有一片
|
|
2107
|
+
*/
|
|
2108
|
+
function captionPieces(value) {
|
|
2109
|
+
const text = String(value ?? '')
|
|
2110
|
+
const formula = /\$\$[\s\S]+?\$\$|\$(?!\s)[^$\n]+?\$/g
|
|
2111
|
+
const pieces = []
|
|
2112
|
+
let at = 0
|
|
2113
|
+
for (const match of text.matchAll(formula)) {
|
|
2114
|
+
if (match.index > at) pieces.push({ text: text.slice(at, match.index), math: false })
|
|
2115
|
+
pieces.push({ text: match[0], math: true })
|
|
2116
|
+
at = match.index + match[0].length
|
|
2117
|
+
}
|
|
2118
|
+
if (at < text.length) pieces.push({ text: text.slice(at), math: false })
|
|
2119
|
+
return pieces.length === 0 ? [{ text, math: false }] : pieces
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2049
2122
|
function renderSelectionText(value) {
|
|
2050
2123
|
const text = String(value ?? '')
|
|
2051
2124
|
const formula = /\$\$[\s\S]+?\$\$|\$(?!\s)[^$\n]+?\$/g
|
|
@@ -2177,7 +2250,7 @@ function createLibraryModel() {
|
|
|
2177
2250
|
* 只脱**行内排版**标签的壳、保留里面的文字。用白名单而不是「把所有尖括号都删掉」:
|
|
2178
2251
|
* markdown 的自动链接写作尖括号包 URL,把尖括号一律当标签会把链接吃掉。
|
|
2179
2252
|
*/
|
|
2180
|
-
const INLINE_TAG_RE = /<\/?\s*(?:sup|sub|i|em|b|strong|u|s|del|ins|mark|small|big|tt|code|abbr|cite|q|span|font)(?:\s[
|
|
2253
|
+
const INLINE_TAG_RE = /<\/?\s*(?:sup|sub|i|em|b|strong|u|s|del|ins|mark|small|big|tt|code|abbr|cite|q|span|font)(?:\s+[a-z-]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))*\s*\/?>/gi
|
|
2181
2254
|
const mapChars = (value, table) => Array.from(String(value), ch => table[ch] ?? ch).join('')
|
|
2182
2255
|
/**
|
|
2183
2256
|
* 把正文里的行内 HTML 换成等价的可读字符(D150)。
|
|
@@ -2733,9 +2806,100 @@ function createLibraryModel() {
|
|
|
2733
2806
|
// 写不进去就算了:下次打开退回默认值,不该为此打断阅读。
|
|
2734
2807
|
}
|
|
2735
2808
|
}
|
|
2736
|
-
/**
|
|
2809
|
+
/**
|
|
2810
|
+
* 字体族清单。**按语言分开两份**(用户裁定:原文是英文,不该被中文字体名接管)。
|
|
2811
|
+
*
|
|
2812
|
+
* 🔴 为什么要分:界面上那三个按钮改的是**当前档位**那一套排版,而双语/并排档里
|
|
2813
|
+
* 原文段与译文段同时在场。共用一份清单时,中文档选的「宋体」会原样落到英文段上 ——
|
|
2814
|
+
* 宋体没有拉丁字形,浏览器只能回退,读者的选择于是看起来「没生效」。
|
|
2815
|
+
*
|
|
2816
|
+
* 🔴 「系统默认」是**栈本身**为空,不是名字叫 'system-ui':空栈表示不写 font-family,
|
|
2817
|
+
* 由浏览器用自己那套默认字体渲染(Chrome 在中文 Windows 上是宋体 / 雅黑)。
|
|
2818
|
+
* 写死 system-ui 反而会剥夺用户改浏览器默认字体的能力,那是另一回事。
|
|
2819
|
+
*
|
|
2820
|
+
* 固定清单,不给自由输入 —— 允许任意字符串等于允许读者把正文变成豆腐块,
|
|
2821
|
+
* 而浏览器又不提供"列出系统字体"的接口(字体枚举要用户授权且各浏览器行为不一)。
|
|
2822
|
+
*/
|
|
2823
|
+
const SRC_FONT_FAMILIES = Object.freeze([
|
|
2824
|
+
Object.freeze({ value: 'system', label: '系统默认', stack: '' }),
|
|
2825
|
+
Object.freeze({ value: 'serif', label: '衬线', stack: "Georgia,'Times New Roman',Times,'Source Serif Pro',Charter,serif" }),
|
|
2826
|
+
Object.freeze({ value: 'sans', label: '无衬线', stack: "'Helvetica Neue',Helvetica,Arial,'Segoe UI',system-ui,sans-serif" }),
|
|
2827
|
+
Object.freeze({ value: 'mono', label: '等宽', stack: "'JetBrains Mono','SF Mono',Consolas,'Liberation Mono',Menlo,monospace" }),
|
|
2828
|
+
Object.freeze({ value: 'kai', label: '手写', stack: "'Iowan Old Style',Charter,'Segoe Print','Bradley Hand',cursive" }),
|
|
2829
|
+
])
|
|
2830
|
+
const ZH_FONT_FAMILIES = Object.freeze([
|
|
2831
|
+
Object.freeze({ value: 'system', label: '系统默认', stack: '' }),
|
|
2832
|
+
Object.freeze({ value: 'serif', label: '宋体', stack: "'Noto Serif SC','Source Han Serif SC','Songti SC',SimSun,Georgia,serif" }),
|
|
2833
|
+
Object.freeze({ value: 'sans', label: '黑体', stack: "'Noto Sans SC','Source Han Sans SC','PingFang SC','Microsoft YaHei',system-ui,sans-serif" }),
|
|
2834
|
+
// ⚠️ 楷体在 Windows 上的注册名是 STKaiti(simkai.ttf 实际注册的族名),
|
|
2835
|
+
// 'Kaiti SC' 是 macOS 的写法;两个都列,再补中文名兜底。
|
|
2836
|
+
Object.freeze({ value: 'kai', label: '楷体', stack: "'Kaiti SC','STKaiti',KaiTi,'楷体','Noto Serif SC',serif" }),
|
|
2837
|
+
])
|
|
2838
|
+
/** 某一侧的字体清单。side 是 'src' / 'zh'。 */
|
|
2839
|
+
function fontFamiliesOf(side) {
|
|
2840
|
+
return side === 'src' ? SRC_FONT_FAMILIES : ZH_FONT_FAMILIES
|
|
2841
|
+
}
|
|
2842
|
+
/**
|
|
2843
|
+
* 把存下来的 family 解析成某一侧真正要用的栈。**每侧各用各的清单**:
|
|
2844
|
+
* 旧数据里译文存的 'serif' 拿到原文那侧仍然叫 'serif',但栈换成了拉丁字体。
|
|
2845
|
+
* 认不出的值回落该侧的第一项(系统默认)—— 与"缺字段回默认"同一口径。
|
|
2846
|
+
*/
|
|
2847
|
+
function fontStackOf(side, value) {
|
|
2848
|
+
const list = fontFamiliesOf(side)
|
|
2849
|
+
const entry = list.find(item => item.value === value)
|
|
2850
|
+
return (entry === undefined ? list[0] : entry).stack
|
|
2851
|
+
}
|
|
2852
|
+
/** 字体族取值校验。认不出的回落该侧的默认档 —— 每侧清单不同,校验也要按侧来。 */
|
|
2853
|
+
function fontOf(side, value) {
|
|
2854
|
+
return fontFamiliesOf(side).some(entry => entry.value === value) ? value : fontFamiliesOf(side)[0].value
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
/**
|
|
2858
|
+
* 排版偏好(字号 / 行距 / 字体族),**原文与译文各一套**。
|
|
2859
|
+
*
|
|
2860
|
+
* 🔴 **全局一份、不按论文分**(D152 原意不变):它答的是"我习惯怎么读",不是"这一篇怎么看"。
|
|
2861
|
+
*
|
|
2862
|
+
* 🔴 **旧格式要能读**。拆包之前存的是 `{ size, height }`(只有一套),读者机器上可能就躺着
|
|
2863
|
+
* 这么一个对象。读成"译文那套",原文整组用默认值 —— 升级不丢读者已经调好的字号。
|
|
2864
|
+
* 反过来说:把旧字段直接丢弃、整块回落默认,等于悄悄把人家调了半天的字号重置掉。
|
|
2865
|
+
*
|
|
2866
|
+
* @returns {{src: {size: number, height: number, family: string}, zh: {size: number, height: number, family: string}}}
|
|
2867
|
+
*/
|
|
2737
2868
|
function readTypePref() { return readPref(TYPE_PREF_KEY) }
|
|
2738
|
-
function
|
|
2869
|
+
function typePref() {
|
|
2870
|
+
const raw = readTypePref()
|
|
2871
|
+
const pick = (side, group, fallback) => {
|
|
2872
|
+
const source = group !== null && typeof group === 'object' ? group : null
|
|
2873
|
+
// 旧格式没有 src/zh 分组,size/height 直接躺在顶层。
|
|
2874
|
+
const legacy = source === null && fallback === 'legacy' ? raw : null
|
|
2875
|
+
const sizeOf = value => clampType(value, MIN_FONT_SIZE, MAX_FONT_SIZE, DEFAULT_FONT_SIZE)
|
|
2876
|
+
const heightOf = value => clampType(value, MIN_LINE_HEIGHT, MAX_LINE_HEIGHT, DEFAULT_LINE_HEIGHT)
|
|
2877
|
+
if (legacy !== null) {
|
|
2878
|
+
// 旧数据没有 family 字段。原文那侧回「系统默认」,译文那侧回宋体 ——
|
|
2879
|
+
// 两侧清单不同,同一个字面量在两边指向的不是同一套字体。
|
|
2880
|
+
return { size: sizeOf(legacy.size), height: heightOf(legacy.height), family: side === 'src' ? 'system' : 'serif' }
|
|
2881
|
+
}
|
|
2882
|
+
return {
|
|
2883
|
+
size: sizeOf(source?.size),
|
|
2884
|
+
height: heightOf(source?.height),
|
|
2885
|
+
family: fontOf(side, source?.family),
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
return {
|
|
2889
|
+
src: pick('src', raw?.src, 'default'),
|
|
2890
|
+
// 🔴 顶层旧字段只喂给译文那套:它是拆包前唯一存在的那一套。
|
|
2891
|
+
zh: pick('zh', raw?.zh, 'legacy'),
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* 写一套排版偏好。
|
|
2896
|
+
*
|
|
2897
|
+
* 🔴 **每次都要写全**,不能只写改动的那一组:`writePref` 是整键覆盖,
|
|
2898
|
+
* 只写 `{zh}` 会把 `src` 从磁盘上抹掉 —— 读者改完译文再刷新,原文那套就没了。
|
|
2899
|
+
*
|
|
2900
|
+
* @param {object} next 完整的三组值。
|
|
2901
|
+
*/
|
|
2902
|
+
function writeTypePref(next) { writePref(TYPE_PREF_KEY, next) }
|
|
2739
2903
|
/**
|
|
2740
2904
|
* 视图档位的取值校验(D152)。只认下拉里真有的档 —— 手改过的 localStorage 不该让选择框
|
|
2741
2905
|
* 落在一个不存在的值上(那时正文按 zh 渲染、选择框却显示别的,看着像「设置没生效」)。
|
|
@@ -2883,6 +3047,53 @@ function createLibraryModel() {
|
|
|
2883
3047
|
+ '&page=' + encodeURIComponent(String(page)) + '&width=' + width + (crop ? '&crop=1' : '')
|
|
2884
3048
|
}
|
|
2885
3049
|
|
|
3050
|
+
/**
|
|
3051
|
+
* 字形宽度的测量缓存(连续滚动的性能关键之一)。
|
|
3052
|
+
*
|
|
3053
|
+
* 🔴 **为什么必须缓存**:逐字符对齐要对每个字符调一次 `canvas.measureText`。
|
|
3054
|
+
* 真实论文实测:一篇 9 页的论文共 16,491 个字符 —— 每页一万六千次**同步**测量。
|
|
3055
|
+
* 单页时代这样建一次还能接受;连续滚动下窗口里同时挂三页,一次重建就是近五万次
|
|
3056
|
+
* `measureText`,那是主线程直接卡住半秒的量级(滚轮会一顿一顿)。
|
|
3057
|
+
*
|
|
3058
|
+
* 🔴 **为什么缓存有效率极高**:同一篇论文里出现的不同字符只有 85 个,字号虽随行高
|
|
3059
|
+
* 浮动,但量化到 0.1px 之后只有二十来档 —— 去重上界约 2,000 次,比逐次测量省 88%。
|
|
3060
|
+
* 字体固定是 serif(与 CSS 的 `.paper-pdf-word` 一致),所以"同一字号 + 同一字串"
|
|
3061
|
+
* 的宽度是确定的,缓存不会失真。
|
|
3062
|
+
*
|
|
3063
|
+
* 量化到 0.1px 是刻意的:字号算出来是浮点(行高 × 页高 / 1000),不量化则几乎每个
|
|
3064
|
+
* 词的 key 都不同,缓存命中率会掉到接近 0。0.1px 的差异在屏幕上不可见,而选区宽度
|
|
3065
|
+
* 只由 `letter-spacing` 的**差值**决定,缩放时也不会累积误差。
|
|
3066
|
+
*/
|
|
3067
|
+
const glyphWidthCache = new Map()
|
|
3068
|
+
/** 缓存上界:一篇论文 85 个字符 × 三十档字号也到不了 5,000,超了说明用法出问题了。 */
|
|
3069
|
+
const GLYPH_CACHE_LIMIT = 5000
|
|
3070
|
+
/**
|
|
3071
|
+
* 量一个字符串在某个字号下的宽度(带缓存)。
|
|
3072
|
+
*
|
|
3073
|
+
* @param {CanvasRenderingContext2D|null} context 测量用的 2d 上下文
|
|
3074
|
+
* @param {number} size 字号(px)
|
|
3075
|
+
* @param {string} text 要量的字串
|
|
3076
|
+
* @returns {number|null} 宽度;上下文不可用是 null(调用方据此跳过对齐,不编一个宽度)
|
|
3077
|
+
*/
|
|
3078
|
+
function glyphWidthOf(context, size, text) {
|
|
3079
|
+
if (context === null || context === undefined) return null
|
|
3080
|
+
const pixels = Number(size)
|
|
3081
|
+
if (!Number.isFinite(pixels) || pixels <= 0) return null
|
|
3082
|
+
// 量化到 0.1px —— 不量化则每个词的 key 都不同,缓存等于没有(见上面的说明)。
|
|
3083
|
+
const quantized = Math.round(pixels * 10) / 10
|
|
3084
|
+
const key = quantized + '|' + text
|
|
3085
|
+
const hit = glyphWidthCache.get(key)
|
|
3086
|
+
if (hit !== undefined) return hit
|
|
3087
|
+
context.font = quantized + 'px serif'
|
|
3088
|
+
const measured = context.measureText(text).width
|
|
3089
|
+
if (!Number.isFinite(measured)) return null
|
|
3090
|
+
// 满了就整片清掉而不是逐条淘汰:条目本身很便宜(数字 + 短串),
|
|
3091
|
+
// 而一篇论文的字符集是稳定的,清掉之后下一轮的命中率依然高。
|
|
3092
|
+
if (glyphWidthCache.size >= GLYPH_CACHE_LIMIT) glyphWidthCache.clear()
|
|
3093
|
+
glyphWidthCache.set(key, measured)
|
|
3094
|
+
return measured
|
|
3095
|
+
}
|
|
3096
|
+
|
|
2886
3097
|
/**
|
|
2887
3098
|
* bbox(0–1000 归一化坐标) → overlay 的百分比样式。
|
|
2888
3099
|
*
|
|
@@ -3201,16 +3412,31 @@ function createLibraryModel() {
|
|
|
3201
3412
|
// 🔴 与编号制最大的差别是**没有唯一键**。"姓氏 + 年份"在 AI 领域经常撞车(同一作者同年
|
|
3202
3413
|
// 多篇),所以索引是一对多:命中几条就全列,由读者自己判断。宁可显示两条让人选,也不要
|
|
3203
3414
|
// 挑一条赌对 —— 猜错时读者无从知道错。
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
//
|
|
3415
|
+
//
|
|
3416
|
+
// 🔴 参考文献有**两种排版**,两种都得认(实测一篇 AAAI 式论文 27 条全灭):
|
|
3417
|
+
// · CS 式 `Zhang, Y. Title. 2020.` —— 姓在前,后面跟逗号
|
|
3418
|
+
// · AAAI 式 `Parth Sarthi, Salman Abdullah, …, and Christopher D. Manning. 2024.`
|
|
3419
|
+
// —— 名在前姓在后,年份在整串作者**之后**
|
|
3420
|
+
// 所以不再拿正则硬抠"姓 + 逗号",改成**先按年份切开、再从作者串里取第一个人的最后一个词**。
|
|
3421
|
+
/** 整个括号。**不**要求里面只有一条引用:`(A et al., 2024; B et al., 2025)` 是常态。 */
|
|
3422
|
+
const AUTHOR_YEAR = /\(([^()]{1,240})\)/gu
|
|
3423
|
+
// 🔴 下面的正则都**必须带 u flag**:`\p{Lu}` / `\p{L}` 是 Unicode 属性转义,没有 u 时
|
|
3208
3424
|
// 会被当成字面量 p / L / u,正则永远匹配不上而**不报错** —— 表现为索引恒为空、悬停全无反应。
|
|
3209
3425
|
// 这条踩过一次(首版漏了 u,4 条作者-年份用例全挂)。
|
|
3210
|
-
/**
|
|
3211
|
-
const
|
|
3212
|
-
/**
|
|
3213
|
-
const
|
|
3426
|
+
/** `e.g.,` / `i.e.,` / `cf.` / `see` 这些前缀不属于引用本身,逐条匹配前先剥掉。 */
|
|
3427
|
+
const CITE_PREFIX = /^\s*(?:e\.g\.|i\.e\.|cf\.|see|also)\s*,?\s*/i
|
|
3428
|
+
/** 并列里的一条:`Surname, 2020` / `Surname et al., 2020` / `Surname and Other, 2020`。 */
|
|
3429
|
+
const CITE_ITEM =
|
|
3430
|
+
/^\s*([\p{Lu}][\p{L}'-]+)(?:\s+et\s+al\.?|\s*(?:&|and)\s+[\p{Lu}][\p{L}'-]+(?:\s+[\p{Lu}][\p{L}'-]+)?)?\s*,\s*((?:19|20)\d{2})[a-z]?\s*$/u
|
|
3431
|
+
/**
|
|
3432
|
+
* 条目里第一个年份。
|
|
3433
|
+
*
|
|
3434
|
+
* 🔴 尾巴上的年份后缀要一起吃掉:`\b\d{4}\b` 匹配不了 `2024a`,那种条目会整条掉出索引。
|
|
3435
|
+
* 以 `19` / `20` 开头也顺带挡掉了页码 `1234` 之类误判。
|
|
3436
|
+
*/
|
|
3437
|
+
const REFERENCE_YEAR = /\b((?:19|20)\d{2})[a-z]?\b/
|
|
3438
|
+
/** 作者串里一个像姓的词。`O'Brien` / `Gutiérrez` / `Liu-Lin` 都要能过。 */
|
|
3439
|
+
const NAME_WORD = /^[\p{Lu}][\p{L}'-]*$/u
|
|
3214
3440
|
|
|
3215
3441
|
/** 匹配键:姓氏折叠成小写 + 年份。作者大小写与变音符号不在这一层处理。 */
|
|
3216
3442
|
function authorYearKey(surname, year) {
|
|
@@ -3219,10 +3445,59 @@ function createLibraryModel() {
|
|
|
3219
3445
|
: ''
|
|
3220
3446
|
}
|
|
3221
3447
|
|
|
3448
|
+
/**
|
|
3449
|
+
* 参考文献条目 → 第一作者的姓。
|
|
3450
|
+
*
|
|
3451
|
+
* 两步,顺序不能反:
|
|
3452
|
+
* 1. **先按年份切开**。年份之后是标题、期刊、卷号,里面全是首字母大写的词 ——
|
|
3453
|
+
* 不先切掉就会取到 `Cognition` / `Psychological` 这种,索引里凭空多出一条假条目。
|
|
3454
|
+
* 2. 再从作者串里取**第一个人的最后一个词**。第一个人的边界是 `and` / `&` / 逗号 ——
|
|
3455
|
+
* 三种排版都用它们分隔作者。
|
|
3456
|
+
*
|
|
3457
|
+
* 逗号在两种排版里含义不同(`Smith, John` 是"姓, 名",而 `Ge Bai, Jie Liu` 是作者分隔),
|
|
3458
|
+
* 但两种情况下第一个逗号之前都正好是第一作者的姓氏串,所以先切逗号两边都对。
|
|
3459
|
+
*
|
|
3460
|
+
* @param {unknown} source 参考文献原文。
|
|
3461
|
+
* @returns {string} 姓氏;认不出时为空串(那条引用只是悬停没反应,不会错配到别人)。
|
|
3462
|
+
*/
|
|
3463
|
+
function referenceSurname(source) {
|
|
3464
|
+
const lead = String(source ?? '').replace(/^\s*\[\s*\d{1,5}\s*\]\s*/, '')
|
|
3465
|
+
if (lead === '') return ''
|
|
3466
|
+
const year = REFERENCE_YEAR.exec(lead)
|
|
3467
|
+
const authors = year === null ? lead : lead.slice(0, year.index)
|
|
3468
|
+
const pick = zone => {
|
|
3469
|
+
const first = zone.split(/\s+(?:and|&)\s+|,/)[0]
|
|
3470
|
+
// 🔴 尾部句点必须剥掉:`Leonard Talmy.` 里 `Talmy.` 带点,不剥就过不了 NAME_WORD,
|
|
3471
|
+
// 于是只剩 `Leonard` 当姓 —— 索引里多出一个"Leonard 1975",正文的 `Talmy, 1975` 全落空。
|
|
3472
|
+
const words = first.trim().replace(/[.,;:]+$/, '').split(/\s+/).filter(word => NAME_WORD.test(word))
|
|
3473
|
+
return words.length === 0 ? '' : words[words.length - 1]
|
|
3474
|
+
}
|
|
3475
|
+
// 年份在最前(极少数期刊把年份编进卷首)时作者串是空的,退回整条开头再试一次。
|
|
3476
|
+
return pick(authors) || pick(lead)
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
/**
|
|
3480
|
+
* 一个括号里解析出的全部引用。`;` 分隔并列,逐条剥掉 `e.g.,` 之类前缀。
|
|
3481
|
+
*
|
|
3482
|
+
* 🔴 任一条认不出就**整段作废**,与编号制同一口径(那个编号不在本篇就整段按纯文本):
|
|
3483
|
+
* 只标出认得的一半,读者会以为括号里只有那一半。
|
|
3484
|
+
*
|
|
3485
|
+
* @param {string} inner 括号内部(不含两侧圆括号)。
|
|
3486
|
+
* @returns {Array<{surname: string, year: string}>} 一条都认不出时为空数组。
|
|
3487
|
+
*/
|
|
3488
|
+
function authorYearItems(inner) {
|
|
3489
|
+
const items = []
|
|
3490
|
+
for (const chunk of String(inner).split(';')) {
|
|
3491
|
+
const match = CITE_ITEM.exec(chunk.replace(CITE_PREFIX, ''))
|
|
3492
|
+
if (match === null) return []
|
|
3493
|
+
items.push({ surname: match[1], year: match[2] })
|
|
3494
|
+
}
|
|
3495
|
+
return items
|
|
3496
|
+
}
|
|
3497
|
+
|
|
3222
3498
|
/**
|
|
3223
3499
|
* 从参考文献块建「姓氏|年份 → 块」的一对多索引。
|
|
3224
3500
|
*
|
|
3225
|
-
* 姓氏取条目开头(可带 `[n]` 前缀)的第一个大写词,年份取条目里第一个四位数 ——
|
|
3226
3501
|
* 学术期刊格式千差万别,这是**启发式**而不是解析器。认不出来的条目直接跳过:
|
|
3227
3502
|
* 索引里少一条只是那条引用悬停没反应,不会错配到别的条目上。
|
|
3228
3503
|
*
|
|
@@ -3235,10 +3510,10 @@ function createLibraryModel() {
|
|
|
3235
3510
|
if (block === null || typeof block !== 'object' || typeof block.id !== 'string') continue
|
|
3236
3511
|
if (readerKindOf(block) !== 'references') continue
|
|
3237
3512
|
const source = typeof block.sourceText === 'string' ? block.sourceText : ''
|
|
3238
|
-
const surname =
|
|
3513
|
+
const surname = referenceSurname(source)
|
|
3239
3514
|
const year = REFERENCE_YEAR.exec(source)
|
|
3240
|
-
if (surname ===
|
|
3241
|
-
const key = authorYearKey(surname
|
|
3515
|
+
if (surname === '' || year === null) continue
|
|
3516
|
+
const key = authorYearKey(surname, year[1])
|
|
3242
3517
|
if (key === '') continue
|
|
3243
3518
|
const entry = { blockId: block.id, text: source.replace(REFERENCE_LEAD, '').trim() }
|
|
3244
3519
|
const list = index.get(key)
|
|
@@ -3254,11 +3529,15 @@ function createLibraryModel() {
|
|
|
3254
3529
|
* 只产出**索引里真有**的标记:查不到的括号原样留在文本里。这一条与编号制同一口径 ——
|
|
3255
3530
|
* 点了没反应/悬停了没内容,比没有标记更坏。
|
|
3256
3531
|
*
|
|
3257
|
-
*
|
|
3532
|
+
* 括号里并列多条时,**整段合成一个标记**(而不是拆成几个可点区域):读者看到的是
|
|
3533
|
+
* 一个括号,悬停展开全部条目才符合直觉;拆开还会让"哪几个字属于同一条引用"变得无法判断。
|
|
3534
|
+
* 标记上带 `items`(每条的 `姓氏|年份` 键),形状与编号制的多标号一致。
|
|
3535
|
+
*
|
|
3536
|
+
* 标记带 `ambiguous`:全部条目命中总数 > 1 时为真,渲染层据此提示"共 N 条可能匹配"。
|
|
3258
3537
|
*
|
|
3259
3538
|
* @param {unknown} text 段落文本。
|
|
3260
3539
|
* @param {unknown} index {@link authorYearIndex} 的产物。
|
|
3261
|
-
* @returns {Array<{type: string, value: string, surname
|
|
3540
|
+
* @returns {Array<{type: string, value: string, surname?: string, year?: string, items?: string[], ambiguous?: boolean, count?: number} | {type: 'text', text: string}>}
|
|
3262
3541
|
*/
|
|
3263
3542
|
function inlineAuthors(text, index) {
|
|
3264
3543
|
if (typeof text !== 'string' || text === '' || !(index instanceof Map) || index.size === 0) return []
|
|
@@ -3271,24 +3550,140 @@ function createLibraryModel() {
|
|
|
3271
3550
|
let cursor = 0
|
|
3272
3551
|
AUTHOR_YEAR.lastIndex = 0
|
|
3273
3552
|
for (let match = AUTHOR_YEAR.exec(text); match !== null; match = AUTHOR_YEAR.exec(text)) {
|
|
3274
|
-
const
|
|
3275
|
-
|
|
3276
|
-
|
|
3553
|
+
const items = authorYearItems(match[1])
|
|
3554
|
+
if (items.length === 0) continue
|
|
3555
|
+
// 先确认**每一条**都查得到,再决定要不要出标记:查到一半就放弃,才不会出现
|
|
3556
|
+
// "括号里两条、只标了一条"这种让人误解的部分标记。
|
|
3557
|
+
const keys = []
|
|
3558
|
+
let total = 0
|
|
3559
|
+
let known = true
|
|
3560
|
+
for (const item of items) {
|
|
3561
|
+
const key = authorYearKey(item.surname, item.year)
|
|
3562
|
+
const hits = key === '' ? undefined : index.get(key)
|
|
3563
|
+
if (hits === undefined || hits.length === 0) { known = false; break }
|
|
3564
|
+
keys.push(key)
|
|
3565
|
+
total += hits.length
|
|
3566
|
+
}
|
|
3567
|
+
if (!known) continue
|
|
3277
3568
|
plain += text.slice(cursor, match.index)
|
|
3278
3569
|
flush()
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
}
|
|
3570
|
+
const single = items.length === 1
|
|
3571
|
+
const part = { type: 'author', value: match[0] }
|
|
3572
|
+
// 单条的字段形状**保持不变**:既有 4 条用例按字段全等断言,多一个字段就红。
|
|
3573
|
+
if (single) {
|
|
3574
|
+
part.surname = items[0].surname
|
|
3575
|
+
part.year = items[0].year
|
|
3576
|
+
} else {
|
|
3577
|
+
part.items = keys
|
|
3578
|
+
}
|
|
3579
|
+
if (total > 1) {
|
|
3580
|
+
part.ambiguous = true
|
|
3581
|
+
part.count = total
|
|
3582
|
+
}
|
|
3583
|
+
parts.push(part)
|
|
3286
3584
|
cursor = match.index + match[0].length
|
|
3287
3585
|
}
|
|
3288
3586
|
plain += text.slice(cursor)
|
|
3289
3587
|
flush()
|
|
3290
3588
|
return parts
|
|
3291
3589
|
}
|
|
3590
|
+
// ---- PDF 原页页栈(连续滚动)----
|
|
3591
|
+
/**
|
|
3592
|
+
* 一篇论文的页身份键:`文档|页|裁边档`。
|
|
3593
|
+
*
|
|
3594
|
+
* 🔴 **裁边是身份的一部分**:同一页裁与不裁拿到的坐标不是一套(宿主 readPdfPage 按满页口径
|
|
3595
|
+
* 缓存、cropPdfGroups 在读出后换算),拿裁边的文字层去配整页的位图,选字框会整片偏出页面。
|
|
3596
|
+
* 所以 key 里必须带它,改 key 就等于换一份数据,与旧实现在 pdfData.cropped 上做的判定同源。
|
|
3597
|
+
*
|
|
3598
|
+
* @param {unknown} documentId 本篇 documentId
|
|
3599
|
+
* @param {unknown} page 页码(1 起)
|
|
3600
|
+
* @param {unknown} crop 是否裁边
|
|
3601
|
+
* @returns {string} 空串 = 这个身份不成立(文档 id 为空或页码不是正整数)
|
|
3602
|
+
*/
|
|
3603
|
+
function pdfStackKey(documentId, page, crop) {
|
|
3604
|
+
const id = typeof documentId === 'string' ? documentId : ''
|
|
3605
|
+
const number = Number(page)
|
|
3606
|
+
if (id === '' || !Number.isSafeInteger(number) || number < 1) return ''
|
|
3607
|
+
return id + '|' + number + '|' + (crop ? '1' : '0')
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
/**
|
|
3611
|
+
* 该挂载哪几页:当前页 ± radius,并夹在 [1, pageCount] 里。
|
|
3612
|
+
*
|
|
3613
|
+
* 🔴 **这是连续滚动唯一的性能闸门**。一页的文字层约 4300 个 DOM 节点(逐字符对齐的代价,
|
|
3614
|
+
* 见 client.js 里 pdfPageView 的说明),12 页全挂就是 5 万个节点 —— 滚动与重涂都会被拖死。
|
|
3615
|
+
* 只挂「当前页 ± 半径」把常驻节点数钉在 (2·radius+1) 页的量级,滚出窗口的页整页卸载。
|
|
3616
|
+
*
|
|
3617
|
+
* radius = 1 是**滑动手感**的下限:滚到一页底部时下一页必须已经在 DOM 里,否则会先看到
|
|
3618
|
+
* 一屏骨架再等 JSON。再大只是白烧节点,滚一页用不到第三页。
|
|
3619
|
+
*
|
|
3620
|
+
* @param {unknown} page 当前页
|
|
3621
|
+
* @param {unknown} pageCount 总页数
|
|
3622
|
+
* @param {unknown} radius 前后各挂几页
|
|
3623
|
+
* @returns {number[]} 升序页码;参数不成立时空数组(**不编一圈默认页**)
|
|
3624
|
+
*/
|
|
3625
|
+
function pdfPageWindow(page, pageCount, radius = 1) {
|
|
3626
|
+
const current = Number(page)
|
|
3627
|
+
const total = Number(pageCount)
|
|
3628
|
+
if (!Number.isSafeInteger(current) || current < 1) return []
|
|
3629
|
+
if (!Number.isSafeInteger(total) || total < 1) return []
|
|
3630
|
+
const span = Number.isSafeInteger(Number(radius)) && Number(radius) >= 0 ? Number(radius) : 1
|
|
3631
|
+
const from = Math.max(1, current - span)
|
|
3632
|
+
const to = Math.min(total, current + span)
|
|
3633
|
+
const pages = []
|
|
3634
|
+
for (let number = from; number <= to; number++) pages.push(number)
|
|
3635
|
+
return pages
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
/**
|
|
3639
|
+
* 页框宽高比,**按 CSS `aspect-ratio` 的口径给(宽 / 高)**(纯函数)。
|
|
3640
|
+
*
|
|
3641
|
+
* 🔴 为什么可以篇内统一:实测同一篇论文各页尺寸逐页相同(PDF 页面框固定),所以一篇之内
|
|
3642
|
+
* 用同一个比例不会让任何一页变形;换来的是**不必等每页位图加载完就能定高度** ——
|
|
3643
|
+
* 否则滚动条会随着每一页加载完毕而跳动,而连续滚动最刺眼的就是这种跳。
|
|
3644
|
+
*
|
|
3645
|
+
* 🔴 方向别搞反:CSS 的 `aspect-ratio` 写的是**宽 / 高**。给成高 / 宽时,
|
|
3646
|
+
* A4 那种竖版页会被排成横版(0.77 与 1.29 差了 67%),整篇高度全错。
|
|
3647
|
+
* 换算不出正数时返回 null,调用方退回「按图片自然尺寸」而不是编一个比例。
|
|
3648
|
+
*
|
|
3649
|
+
* @param {unknown} width 页面宽(PDF 点)
|
|
3650
|
+
* @param {unknown} height 页面高(PDF 点)
|
|
3651
|
+
* @returns {number|null} 宽 / 高;无效是 null
|
|
3652
|
+
*/
|
|
3653
|
+
function pdfPageAspectOf(width, height) {
|
|
3654
|
+
const w = Number(width)
|
|
3655
|
+
const h = Number(height)
|
|
3656
|
+
if (!Number.isFinite(w) || !Number.isFinite(h) || !(w > 0) || !(h > 0)) return null
|
|
3657
|
+
return w / h
|
|
3658
|
+
}
|
|
3659
|
+
|
|
3660
|
+
/**
|
|
3661
|
+
* 从滚动位置反推"现在是第几页"(纯函数)。
|
|
3662
|
+
*
|
|
3663
|
+
* 🔴 用**页顶坐标**而不是"视口中心落在谁身上":连续滚动下用户可能正停在两页交界处,
|
|
3664
|
+
* 中心判据在那一瞬间会来回跳(页码跟着闪),而"最后一个页顶已经滚过视口上沿的页"
|
|
3665
|
+
* 单调、稳定,滚过一页才前进一页。
|
|
3666
|
+
*
|
|
3667
|
+
* @param {number[]} tops 各页页顶的 scrollTop 偏移(升序)
|
|
3668
|
+
* @param {unknown} pages 与 tops 一一对应的页码
|
|
3669
|
+
* @param {unknown} scrollTop 当前滚动位置
|
|
3670
|
+
* @returns {number|null} 页码;参数不成立是 null
|
|
3671
|
+
*/
|
|
3672
|
+
function pdfPageAt(tops, pages, scrollTop) {
|
|
3673
|
+
if (!Array.isArray(tops) || !Array.isArray(pages) || tops.length !== pages.length) return null
|
|
3674
|
+
if (tops.length === 0) return null
|
|
3675
|
+
const position = Number(scrollTop)
|
|
3676
|
+
if (!Number.isFinite(position)) return null
|
|
3677
|
+
// 留 2px 容差:滚动容器的 scrollTop 是整数化的,页顶算出来可能带小数,
|
|
3678
|
+
// 差这一线就会让"刚滚到下一页"判成还在上一页。
|
|
3679
|
+
let found = Number(pages[0])
|
|
3680
|
+
for (let index = 0; index < tops.length; index++) {
|
|
3681
|
+
if (Number(tops[index]) <= position + 2) found = Number(pages[index])
|
|
3682
|
+
else break
|
|
3683
|
+
}
|
|
3684
|
+
return Number.isSafeInteger(found) && found > 0 ? found : null
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3292
3687
|
// END CLIENT PARTS
|
|
3293
3688
|
// 量容器的实际宽度(resize 时重量):ResizeObserver 不在就退回 window resize,清理函数
|
|
3294
3689
|
// 一律走同一个 disconnect 形状。回调 ref 而不是 ref 对象 —— 节点挂上/换掉时都要重挂观察者。
|
|
@@ -3451,6 +3846,33 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3451
3846
|
.paper-reader-inject{flex:0 0 auto;padding:5px 8px}
|
|
3452
3847
|
.paper-reader-dual{flex:0 0 auto;padding:5px 8px}
|
|
3453
3848
|
.paper-reader-head .paper-seg .paper-btn{padding:5px 8px}
|
|
3849
|
+
/* ---- 顶栏三个排版按钮(D195)----
|
|
3850
|
+
位置:阅读视图分段控件的右边(读者裁定「就笔记的右边」)。
|
|
3851
|
+
🔴 三个都是 flex:0 0 auto:分段控件自己带 overflow-x:auto,挤的时候由它让位,
|
|
3852
|
+
排版按钮绝不能被压扁或者掉到第二行 —— 它们显示的是当前值,压扁就读不出来了。 */
|
|
3853
|
+
/* 三个按钮 + 它们的弹层包在一个 holder 里。holder 自己**不定位**(不设 position),
|
|
3854
|
+
只吃顶栏的 flex 排布;弹层的包含块因此是 .paper-reader-head(它带 position:relative)。
|
|
3855
|
+
🔴 这正是拿掉 per-button 定位的理由,见 typePopover 的注释。 */
|
|
3856
|
+
.paper-type-row-holder{display:flex;align-items:center;gap:8px;flex:0 0 auto;min-width:0}
|
|
3857
|
+
.paper-type-trigger{display:inline-flex;align-items:center;gap:4px;padding:5px 8px;flex:0 0 auto}
|
|
3858
|
+
.paper-type-glyph{font-size:10px;font-weight:700;opacity:.62;letter-spacing:.02em}
|
|
3859
|
+
/* 弹层:铺满顶栏整行的宽度,永远在容器内。
|
|
3860
|
+
🔴 不用固定像素宽度 —— 侧栏最窄 300px,220px 的弹层挂在任何一个按钮上都有一端溢出
|
|
3861
|
+
(锚左沿则最右那个越界,锚右沿则最左那个越界,用户实测「都看不到了」)。
|
|
3862
|
+
left/right 都归零就与容器同宽,多窄都完整可见。 */
|
|
3863
|
+
.paper-type-pop{position:absolute;top:calc(100% - 2px);left:0;right:0;z-index:var(--paper-layer-sticky);
|
|
3864
|
+
padding:10px;border:1px solid var(--paper-border);border-radius:10px;
|
|
3865
|
+
background:var(--paper-card);box-shadow:0 8px 24px rgba(0,0,0,.18)}
|
|
3866
|
+
/* 弹层里的行:标签定宽、控件吃满剩余。行距/字号的数值回显右对齐,改的时候不跳。 */
|
|
3867
|
+
.paper-type-row{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--paper-muted);margin:0}
|
|
3868
|
+
.paper-type-row>span:first-child{flex:0 0 32px}
|
|
3869
|
+
.paper-type-row input[type=range]{flex:1;min-width:0}
|
|
3870
|
+
.paper-type-value{flex:0 0 34px;text-align:right;color:var(--paper-text);font-variant-numeric:tabular-nums}
|
|
3871
|
+
.paper-type-select{flex:1;min-width:0}
|
|
3872
|
+
/* 双语档才出现的「原 / 译」切换:比阅读视图那条窄得多,按内容排、不等分。
|
|
3873
|
+
⚠️ 它复用 .paper-seg 的滑动高亮块,所以要显式给出项数 —— 两档就是 2。 */
|
|
3874
|
+
.paper-type-side{flex:0 0 auto;--paper-seg-count:2}
|
|
3875
|
+
.paper-type-side>button{flex:0 0 auto;padding:5px 7px}
|
|
3454
3876
|
/* 🔴 这里是 src(英文正文)档,不是 pdf(原页位图)档。位图档渲染的是
|
|
3455
3877
|
.paper-pdf-* 那一套,树里根本没有 .paper-reader-raw —— 把这条挂到 pdf 上等于死规则,
|
|
3456
3878
|
而 src 档里每一行都是 raw:true,会被下面 .paper-reader-raw{color:var(--paper-muted)}
|
|
@@ -3469,18 +3891,48 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3469
3891
|
.paper-reader-split .paper-reader-body-zh .paper-reader-block{border-left:2px solid var(--paper-accent);padding-left:8px}
|
|
3470
3892
|
/* ---- P6 阅读页排版(对照 EasyRead 的 design.md §版面)----
|
|
3471
3893
|
🔴 版心(35em ≈ 630px)**做不到**:侧栏宽度由宿主定(300px 起、上限视口 70%)。
|
|
3472
|
-
|
|
3473
|
-
正文用宋体(中文长读比黑体舒服),暖白纸色底、墨色字,不用纯黑纯白。
|
|
3474
|
-
|
|
3894
|
+
能做的是字号、行距与字体族 —— 三者都由顶栏那三个排版按钮以下面的 CSS 变量下发。
|
|
3895
|
+
正文用宋体(中文长读比黑体舒服),暖白纸色底、墨色字,不用纯黑纯白。
|
|
3896
|
+
|
|
3897
|
+
🔴 **原文与译文各一套**(D195):读者裁定「选到哪个档,就改哪个档的排版」。
|
|
3898
|
+
两套值由 inline style 落在 .paper-reader-layout 上,下面按 data-pane 分派:
|
|
3899
|
+
原文档 → 整档用 src 那套;译文档 → 整档用 zh 那套;双语档 → 原文段用 src、译文段用 zh。
|
|
3900
|
+
⚠️ 兜底必须与源码常量同口径(DEFAULT_FONT_SIZE / DEFAULT_LINE_HEIGHT),
|
|
3901
|
+
client-css.test.js 会拿源码里的常量来对,改常量时这里不改就会红。 ---- */
|
|
3902
|
+
.paper-reader{--reader-src-font-size:18px;--reader-src-line-height:1.7;
|
|
3903
|
+
--reader-zh-font-size:18px;--reader-zh-line-height:1.7;
|
|
3475
3904
|
--reader-paper:#f6f3ec;--reader-ink:#23211d}
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
.paper-reader-layout
|
|
3905
|
+
/* 🔴 字体族**故意不给兜底值**。读者选「系统默认」时那侧的 --reader-*-font-family 根本
|
|
3906
|
+
不下发,而 font-family:var(--reader-*-font-family) 在变量未定义时整条声明在计算值阶段
|
|
3907
|
+
失效 —— 正文于是不设字族,用浏览器自己那套默认字体,正是这一档要的语义。
|
|
3908
|
+
一旦在这里补一个兜底栈,"系统默认"就退化成"宋体",读者改了浏览器默认字体也看不出来。 */
|
|
3909
|
+
/* 🔴 分派这一层只认 data-pane,不看内容语言:档位是读者亲手选的,语言是翻译结果的副作用。
|
|
3910
|
+
双语档里原文段与译文段同在 .paper-reader-body-zh 里(.paper-reader-body-src 那列只在
|
|
3911
|
+
已退役的并排档渲染),所以双语档必须按 .paper-reader-raw 再分一次。 */
|
|
3912
|
+
.paper-reader-layout{font-size:var(--reader-zh-font-size);line-height:var(--reader-zh-line-height)}
|
|
3913
|
+
[data-pane="src"] .paper-reader-layout{font-size:var(--reader-src-font-size);line-height:var(--reader-src-line-height);
|
|
3914
|
+
font-family:var(--reader-src-font-family)}
|
|
3915
|
+
[data-pane="zh"] .paper-reader-layout{font-size:var(--reader-zh-font-size);line-height:var(--reader-zh-line-height);
|
|
3916
|
+
font-family:var(--reader-zh-font-family)}
|
|
3917
|
+
[data-pane="bi"] .paper-reader-layout{font-size:var(--reader-zh-font-size);line-height:var(--reader-zh-line-height);
|
|
3918
|
+
font-family:var(--reader-zh-font-family)}
|
|
3919
|
+
[data-pane="bi"] .paper-reader-layout .paper-reader-raw{font-size:var(--reader-src-font-size);
|
|
3920
|
+
line-height:var(--reader-src-line-height);font-family:var(--reader-src-font-family)}
|
|
3921
|
+
/* 🔴 宿主的 .markdown 用 font: **简写**把字号、行距、**字族**一起定死在 --dsw-font-markdown-base
|
|
3922
|
+
(ui-primitives/markdown/MarkdownText.module.css:8)。它又是 CSS Module 的哈希类名,
|
|
3923
|
+
点名打不到,而继承链在那一层就断了 —— 我们的三个排版变量根本传不进正文。
|
|
3924
|
+
它是块的**唯一直接子节点**,所以从我们的块往下一层把这几项接回去。
|
|
3925
|
+
color 同理:宿主那条 .markdown{color:var(--dsw-alias-label-primary)} 也盖掉了双语的分层。
|
|
3926
|
+
⚠️ font-family 那一项曾经漏过(用户实测「切换字体无反应,换了还是宋体」):
|
|
3927
|
+
当时只补了字号与行距,于是三个滑杆里两个能用、一个不能用。简写里的每一项都要接。
|
|
3928
|
+
🔴 选择器里那个 [data-dsh-paper] **不是**装饰:主题插件会覆盖正文的字族,例如
|
|
3929
|
+
dsh-claude-style 的 typography.css 用
|
|
3930
|
+
body[data-dsh-claude-style] [data-dsh-claude-part~="markdown"]{font-family:…}
|
|
3931
|
+
抢走整块的字族。那条是 (0,2,1),本规则只写两个类名时是 (0,2,0) —— 低一档就必然输,
|
|
3932
|
+
于是字号、行距都跟着读者走,唯独字体纹丝不动(用户实测:变量下发正确、档位也正确,
|
|
3933
|
+
块上的计算字族却是主题插件那套)。这里多挂自己 DOM 根上的属性把特异性提到 (0,3,0),
|
|
3934
|
+
超过主题插件又不依赖它的类名。 */
|
|
3935
|
+
[data-dsh-paper] .paper-reader-layout .paper-reader-block > *{font-size:inherit;line-height:inherit;font-family:inherit;color:inherit}
|
|
3484
3936
|
/* 每个块是一份独立的 MarkdownText,宿主的 .markdown p{margin:16px 0} 于是每两块之间白送
|
|
3485
3937
|
32px,再叠上本层的 gap:10px = 42px —— 这就是「行距太开」。首末子节点归零,间距交回 gap。 */
|
|
3486
3938
|
.paper-reader-layout .paper-reader-block > * > :first-child{margin-top:0}
|
|
@@ -3493,19 +3945,23 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3493
3945
|
.paper-reader-layout .paper-reader-block{margin-top:0;margin-bottom:0;min-width:0;overflow-wrap:anywhere;content-visibility:auto;contain-intrinsic-size:auto 180px}
|
|
3494
3946
|
.paper-reader-block .katex{white-space:normal;text-align:left}
|
|
3495
3947
|
.paper-reader-block .katex-display{max-width:100%;overflow-x:auto;overflow-y:hidden}
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3948
|
+
/* 字体族由上面 [data-pane] 那几条按档位下发,这里只剩对齐。
|
|
3949
|
+
⚠️ 别再往这条规则里写 font-family:档位分派在上层,写在这儿会把双语档原文段的
|
|
3950
|
+
字体盖回宋体 —— 而那一层正是读者能单独设字体的地方。 */
|
|
3951
|
+
.paper-reader-body-zh .paper-reader-block{text-align:justify}
|
|
3952
|
+
/* 双语档的原文段左对齐:它是英文,两端对齐会把含公式的行拉出大洞(用户报过)。
|
|
3953
|
+
⚠️ 这条不能并进上面那条 —— 上面是 justify,这里是 left,同级选择器后写的赢。 */
|
|
3499
3954
|
.paper-reader-body-zh .paper-reader-raw{text-align:left}
|
|
3500
3955
|
/* 原文那一列小一号、灰一级,左侧一条细线 —— 与译文明显分层。 */
|
|
3501
|
-
.paper-reader-body-src{font-size:calc(var(--reader-font-size) - 2px);color:var(--paper-muted)
|
|
3502
|
-
font-family:'Source Serif Pro',Charter,Georgia,serif}
|
|
3956
|
+
.paper-reader-body-src{font-size:calc(var(--reader-src-font-size) - 2px);color:var(--paper-muted)}
|
|
3503
3957
|
.paper-reader-body-src .paper-reader-block{border-left:2px solid var(--paper-border);padding-left:8px}
|
|
3504
3958
|
/* ---- D149 双语分层(用户裁定,照他给的参考图:原文大而亮、译文小一号 + 次级色)----
|
|
3505
3959
|
⚠️ 只作用于**双语档**。译文档里译文是唯一内容,必须保持主字号 + 主色 ——
|
|
3506
3960
|
把这两条放宽一格,译文 tab 的正文就整体降级了。
|
|
3507
3961
|
⚠️ 主色用 inherit:--reader-ink 只声明过、没有任何规则用过它(T16 留下的空变量)。
|
|
3508
3962
|
⚠️ 字号只降到 div 上:译文的小标题是 h3/h4,各自已有自己的字号,不该再被降一档。 */
|
|
3963
|
+
/* ⚠️ 这一条**只给颜色**,不给 font-size:原文段在双语档里是主层,字号由它自己那套
|
|
3964
|
+
(--reader-src-font-size)决定,在这里再降一档等于读者选的字号被偷偷改掉。 */
|
|
3509
3965
|
[data-pane="bi"] .paper-reader-raw{color:inherit}
|
|
3510
3966
|
/* ---- D149 双语分层:译文那一层(次级色 + 小一号 + 左侧竖条)----
|
|
3511
3967
|
🔴 三条必须写在**同一条规则**里。同一个选择器出现两次时,测试里的 ruleOf 只取第一条,
|
|
@@ -3518,7 +3974,7 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3518
3974
|
[data-pane="bi"] .paper-reader-body-zh .paper-reader-block:not(.paper-reader-raw){
|
|
3519
3975
|
color:var(--paper-muted);border-left:2px solid var(--paper-border);padding-left:8px}
|
|
3520
3976
|
[data-pane="bi"] .paper-reader-body-zh div.paper-reader-block:not(.paper-reader-raw){
|
|
3521
|
-
font-size:calc(var(--reader-font-size) - 3px)}
|
|
3977
|
+
font-size:calc(var(--reader-zh-font-size) - 3px)}
|
|
3522
3978
|
/* ---- 目录抽屉 ---- */
|
|
3523
3979
|
.paper-reader-drawer{display:flex;flex-direction:column;gap:8px;padding:10px;
|
|
3524
3980
|
background:var(--paper-card);box-shadow:var(--paper-shadow)}
|
|
@@ -3585,6 +4041,13 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
3585
4041
|
|
|
3586
4042
|
.paper-pdf-controls{display:flex;align-items:center;gap:4px;flex:0 0 auto;flex-wrap:wrap;font-size:12px;color:var(--paper-muted)}
|
|
3587
4043
|
.paper-pdf-controls .paper-btn{padding:3px 6px}
|
|
4044
|
+
/* ---- 连续滚动(页栈)----
|
|
4045
|
+
页面一页页竖排,滚动交给 .paper-reader-layout 的原生 overflow:auto —— 滚轮 / 触控板 /
|
|
4046
|
+
滚动条因此天然都是"翻页",不需要任何 wheel 事件处理。 */
|
|
4047
|
+
.paper-pdf-stack{display:flex;flex-direction:column;flex:0 0 auto;min-width:0;align-self:stretch;gap:calc(14px * var(--paper-pdf-zoom,1))}
|
|
4048
|
+
/* 页位:一页的"座位"。它比页面本身高一点点(就是上下那半格间距),保证滚动到底时
|
|
4049
|
+
下一章的第一行也露出来,用户能看出"还没完"。min-height 由行内样式按统一宽高比给。 */
|
|
4050
|
+
.paper-pdf-slot{display:flex;flex-direction:column;flex:0 0 auto;min-width:0;scroll-margin-top:0}
|
|
3588
4051
|
.paper-pdf-page{position:relative;flex:0 0 auto;min-width:0;align-self:flex-start;background:var(--paper-pdf-paper,#fff);overflow:hidden}
|
|
3589
4052
|
.paper-pdf-image{display:block;width:100%;max-width:none;height:auto;user-select:none;-webkit-user-drag:none}
|
|
3590
4053
|
.paper-pdf-text{position:absolute;left:0;top:0;transform:scale(var(--paper-pdf-scale,0));transform-origin:0 0;z-index:1}
|
|
@@ -3685,11 +4148,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
3685
4148
|
契约这条不猜。 */
|
|
3686
4149
|
.paper-lib{display:flex;flex-direction:row;height:100%;max-height:100%;min-height:0;position:relative;overflow:hidden;font-size:13px}
|
|
3687
4150
|
.paper-import-control{position:relative;display:flex}
|
|
3688
|
-
|
|
3689
|
-
.paper-import-menu>.paper-btn{justify-content:flex-start;border-color:transparent}
|
|
3690
|
-
.paper-import-control>.paper-btn{background:var(--paper-accent);border-color:var(--paper-accent);color:var(--paper-on-accent)}
|
|
3691
|
-
.paper-import-control>.paper-btn:hover{background:var(--paper-accent);filter:brightness(1.1)}
|
|
3692
|
-
.paper-import-control>.paper-btn .paper-library-icon{color:inherit}
|
|
4151
|
+
|
|
3693
4152
|
.paper-lib-head>.paper-btn:hover{background:var(--paper-hover)}
|
|
3694
4153
|
.paper-lib .paper-btn,.paper-lib .paper-input{border-radius:6px;font:inherit;font-size:12px;padding:4px 8px;min-height:28px}
|
|
3695
4154
|
.paper-lib .paper-rename{display:flex;flex-direction:column;gap:6px}
|
|
@@ -3879,11 +4338,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
3879
4338
|
.paper-info-label{flex:0 0 56px;color:var(--paper-muted);text-align:right}
|
|
3880
4339
|
.paper-info-value{min-width:0;flex:1;overflow-wrap:anywhere}
|
|
3881
4340
|
.paper-detail-files{border-top:1px solid var(--paper-border);margin-top:4px}
|
|
3882
|
-
.paper-menu{position:fixed;z-index:var(--paper-layer-float);min-width:132px;padding:5px;display:flex;flex-direction:column;gap:1px;overflow-y:auto;overscroll-behavior:contain;background:var(--paper-bg);box-shadow:var(--paper-shadow-pop)}
|
|
3883
|
-
.paper-menu button{flex:0 0 auto;border:0;background:transparent;color:var(--paper-text);text-align:left;padding:7px 9px;border-radius:var(--paper-radius-sm);cursor:pointer;font:inherit;white-space:normal;overflow-wrap:anywhere}
|
|
3884
|
-
.paper-menu button:hover{background:var(--paper-hover)}
|
|
3885
|
-
.paper-menu button.active{background:var(--paper-accent-soft);color:var(--paper-accent)}
|
|
3886
|
-
.paper-menu-label{flex:0 0 auto;padding:6px 9px 3px;color:var(--paper-muted);font-size:11px;font-weight:600;letter-spacing:.02em}
|
|
3887
4341
|
/* 🔴 height:100% 只给**主栏**那份(它带 data-dsh-paper)。
|
|
3888
4342
|
右栏阅读区那个 section 的类名**也叫 paper-reader**:全局加高度会把它钉成一屏高、
|
|
3889
4343
|
内容溢出自己的盒子 —— 后果不只是"盒子小",而是把「顶栏 sticky」的**包含块**压成一屏,
|
|
@@ -3941,7 +4395,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
3941
4395
|
@keyframes paper-surface-in{from{opacity:0;transform:translateY(4px) scale(.98)}to{opacity:1;transform:none}}
|
|
3942
4396
|
@media (prefers-reduced-motion:reduce){
|
|
3943
4397
|
:is([data-dsh-paper],.paper-config){--paper-t-feedback:0.01ms;--paper-t-surface:0.01ms;--paper-t-open:0.01ms;--paper-t-exit:0.01ms;--paper-t-slide:0.01ms}
|
|
3944
|
-
.paper-menu,.paper-import-menu{animation:none}
|
|
3945
4398
|
}
|
|
3946
4399
|
`
|
|
3947
4400
|
|
|
@@ -4529,7 +4982,13 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4529
4982
|
alt: payload.caption === '' ? line.text : payload.caption,
|
|
4530
4983
|
})
|
|
4531
4984
|
// 图注也过一遍行内 HTML:图块里同样会出现上标(如 "Fig. 2<sup>a</sup>")。
|
|
4532
|
-
|
|
4985
|
+
// 🔴 但图注里的 `$…$` 必须交给渲染器:实测 STITCH 的 Figure 2 图注写着
|
|
4986
|
+
// `Thematic Scope $( \sigma _ { t } ) .$`,整段字面显示出来就是一屏 LaTeX 源码。
|
|
4987
|
+
// 只切出公式段送进 MarkdownText,其余仍是纯文本 —— 图注照样不做强调解析。
|
|
4988
|
+
return h(tag ?? "p", shared, image, captionPieces(displayInlineHtml(line.text)).map((piece, index) =>
|
|
4989
|
+
piece.math
|
|
4990
|
+
? h(MarkdownText, { key: index, text: piece.text, labels: MARKDOWN_LABELS, variant: MARKDOWN_VARIANT })
|
|
4991
|
+
: piece.text))
|
|
4533
4992
|
}
|
|
4534
4993
|
// markdownText 是真正喂给渲染器的串(表格 / 公式 / 代码),缺省退回显示文本。
|
|
4535
4994
|
const text = typeof payload?.markdownText === "string" && payload.markdownText !== ""
|
|
@@ -4553,8 +5012,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4553
5012
|
const publishReaderBridge = patch => {
|
|
4554
5013
|
if (!boundDocumentId || visibleRef.current) bridgeSet({ ...patch, ...(boundDocumentId ? { documentId: boundDocumentId } : {}) })
|
|
4555
5014
|
}
|
|
4556
|
-
//
|
|
4557
|
-
const [selectMenu, setSelectMenu] = React.useState(
|
|
5015
|
+
// 打开中的下拉:存的是**它的 aria-label**(一个面板同一时刻只有一张开着)。
|
|
5016
|
+
const [selectMenu, setSelectMenu] = React.useState('')
|
|
4558
5017
|
const [state, setState] = React.useState(null)
|
|
4559
5018
|
const [path, setPath] = React.useState('')
|
|
4560
5019
|
const [query, setQuery] = React.useState('')
|
|
@@ -4672,16 +5131,30 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4672
5131
|
// 术语页的文本。**按需拉**(切到那一页才拉):术语表是全局一份,
|
|
4673
5132
|
// 进阅读器就拉等于每次打开论文都白读一次盘,而多数人从不打开抽屉。
|
|
4674
5133
|
const [termsText, setTermsText] = React.useState('')
|
|
4675
|
-
//
|
|
4676
|
-
// 行距按**十分之一**存(滑杆是整数,1.9 存成 19),与 --reader
|
|
5134
|
+
// 排版:字号 / 行距 / 字体族,**原文与译文各一套**(D195)。
|
|
5135
|
+
// 行距按**十分之一**存(滑杆是整数,1.9 存成 19),与 --reader-*-line-height 同一口径。
|
|
4677
5136
|
// 🔴 初值用**惰性初始化**只读一次 localStorage:每轮渲染都读会把本轮刚写进去的值再读回来,
|
|
4678
5137
|
// 看着一样,但只要写失败(配额满、隐私模式)就会当场跳回默认值。
|
|
4679
|
-
const [
|
|
4680
|
-
|
|
4681
|
-
)
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
5138
|
+
const [readerType, setReaderType] = React.useState(() => typePref())
|
|
5139
|
+
// 三个排版弹层里当前开着哪一个('' = 都关着)。互斥:点另一个直接换过去。
|
|
5140
|
+
const [typePop, setTypePop] = React.useState('')
|
|
5141
|
+
// 排版按钮与它的弹层。点外部关闭这条要用它判「点到的是不是自己人」。
|
|
5142
|
+
const typePopRef = React.useRef(null)
|
|
5143
|
+
// 双语档下三个按钮改的是原文那套还是译文那套('src' / 'zh')。
|
|
5144
|
+
// 🔴 只影响**双语档**:原文档与译文档的归属是确定的,不给第二个选择。
|
|
5145
|
+
const [typeSide, setTypeSide] = React.useState('zh')
|
|
5146
|
+
/**
|
|
5147
|
+
* 改一套排版并落盘。
|
|
5148
|
+
*
|
|
5149
|
+
* 🔴 **一次写全三组**:writePref 是整键覆盖,只写改动那一组会把另一组从磁盘抹掉。
|
|
5150
|
+
* 🔴 先算 next 再写,不在 setState 回调里写 localStorage —— React 的严格模式会
|
|
5151
|
+
* 把 updater 跑两遍,那是两次写盘。
|
|
5152
|
+
*/
|
|
5153
|
+
const patchType = (side, patch) => {
|
|
5154
|
+
const next = { src: { ...readerType.src }, zh: { ...readerType.zh }, [side]: { ...readerType[side], ...patch } }
|
|
5155
|
+
setReaderType(next)
|
|
5156
|
+
writeTypePref(next)
|
|
5157
|
+
}
|
|
4685
5158
|
// ---- 边注讨论(T20) ----
|
|
4686
5159
|
const [threads, setThreads] = React.useState([])
|
|
4687
5160
|
const [question, setQuestion] = React.useState('')
|
|
@@ -4749,17 +5222,28 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4749
5222
|
const [exported, setExported] = React.useState('')
|
|
4750
5223
|
// null follows the saved reading position or the first parsed page.
|
|
4751
5224
|
const [readerPage, setReaderPage] = React.useState(null)
|
|
4752
|
-
|
|
5225
|
+
// ---- PDF 原页页栈(连续滚动)----
|
|
5226
|
+
// 🔴 **从「一页」变成「一份按页键索引的页字典」**。单值那版的全部判据都写成
|
|
5227
|
+
// `pdfData.documentId === readerId && pdfData.page === currentPage && pdfData.cropped === pdfCrop`
|
|
5228
|
+
// —— 连续滚动下同时挂着好几页,这三条没有一个还能成立,必须换成按页键查:
|
|
5229
|
+
// 键由 pdfStackKey 统一给出(文档 + 页 + 裁边档),裁边为什么算身份见那个函数的说明。
|
|
5230
|
+
const [pdfPages, setPdfPages] = React.useState({})
|
|
4753
5231
|
const [pdfFailure, setPdfFailure] = React.useState('')
|
|
4754
5232
|
const [pdfLoading, setPdfLoading] = React.useState(false)
|
|
5233
|
+
// 这一篇一共有多少页。取第一份到手的文字层里的 pageCount(宿主 readPdfPage 逐页都带),
|
|
5234
|
+
// 拿不到就退回块列表里的最大页码 —— 不让页栈因为少一个字段就整片不渲染。
|
|
5235
|
+
const [pdfPageCount, setPdfPageCount] = React.useState(0)
|
|
4755
5236
|
const [pdfZoom, setPdfZoom] = React.useState(1)
|
|
4756
5237
|
// 裁边(默认开)。与视图档位、排版同样落 localStorage,**全局一份**:它答的是
|
|
4757
5238
|
// 「我习惯怎么看原页」,不是「这一篇怎么看」。存 false 才关,缺省/读不出来都是开。
|
|
4758
5239
|
const [pdfCrop, setPdfCrop] = React.useState(() => readPref(CROP_PREF_KEY)?.crop !== false)
|
|
4759
5240
|
const [pdfImageAttempt, setPdfImageAttempt] = React.useState(0)
|
|
4760
|
-
|
|
5241
|
+
// 页栈里**每一页**各有一个 DOM 容器(.paper-pdf-page),比例尺与涂色都得逐页做。
|
|
5242
|
+
const pdfFrameRefs = React.useRef(new Map())
|
|
4761
5243
|
const pdfMeasureRef = React.useRef(null)
|
|
4762
|
-
|
|
5244
|
+
// 在飞的文字层请求,**按页键分槽**:单槽那版换页时会 abort 掉上一页,连续滚动下
|
|
5245
|
+
// 那等于「滚到上一页就把下一页的请求掐死」,来回滚会一直重取。
|
|
5246
|
+
const pdfRequestRef = React.useRef(new Map())
|
|
4763
5247
|
// <img onError> does not expose the route's status code.
|
|
4764
5248
|
// P21 起它**只服务详情页封面**(右栏的原页面板已移除)。
|
|
4765
5249
|
const [pageNote, setPageNote] = React.useState('')
|
|
@@ -5004,6 +5488,27 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
5004
5488
|
* 替身没有 DOM)—— 不写一个假的 0%,那会把用户读到一半的位置抹掉。
|
|
5005
5489
|
*/
|
|
5006
5490
|
const onReaderScroll = event => {
|
|
5491
|
+
// 🔴 PDF 原页档(连续滚动)**也要接管滚动**:这一档没有正文块可量,但滚动位置就是
|
|
5492
|
+
// "我在第几页"。原来这一档 onScroll 是 undefined,于是翻页只能靠按钮;连续滚动之后
|
|
5493
|
+
// 页面一页页排开,滚动自然就该更新当前页 —— 而当前页是页栈窗口的输入,
|
|
5494
|
+
// 不更新的话滚到第 5 页时窗口还停在第 1 页附近,屏幕上是空的。
|
|
5495
|
+
if (isPdfPane(paneView)) {
|
|
5496
|
+
const tops = []
|
|
5497
|
+
const pages = []
|
|
5498
|
+
for (const page of pdfWindow) {
|
|
5499
|
+
const node = pdfFrameRefs.current.get(page) ?? null
|
|
5500
|
+
const top = node === null ? null : blockScrollTopOf(layoutElRef.current, node, 0)
|
|
5501
|
+
if (top === null) continue
|
|
5502
|
+
tops.push(top)
|
|
5503
|
+
pages.push(page)
|
|
5504
|
+
}
|
|
5505
|
+
const at = pdfPageAt(tops, pages, layoutElRef.current?.scrollTop ?? 0)
|
|
5506
|
+
if (at !== null && at !== currentPage) {
|
|
5507
|
+
setReaderPage(at)
|
|
5508
|
+
readingRef.current = { block: readerBlocks.find(block => block.page === at)?.id ?? '', page: at }
|
|
5509
|
+
}
|
|
5510
|
+
return
|
|
5511
|
+
}
|
|
5007
5512
|
// 量一次、两处用:游标要的是块 id,锚点还要带上块内比例(D189 见 topAnchorOf)。
|
|
5008
5513
|
const anchor = topAnchorOf(event?.currentTarget ?? layoutElRef.current)
|
|
5009
5514
|
const cursor = readingCursorOf(anchor === null ? '' : anchor.blockId, readingRowsRef.current)
|
|
@@ -5430,7 +5935,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
5430
5935
|
try {
|
|
5431
5936
|
const result = await api('/gloss', {
|
|
5432
5937
|
method: 'POST',
|
|
5433
|
-
body: JSON.stringify({ documentId: readerId, blockId: segment.blockId, quote: segment.quote, ...(segment.pdfPage ? { pdfPage: segment.pdfPage } : {}) }),
|
|
5938
|
+
body: JSON.stringify({ sessionId, documentId: readerId, blockId: segment.blockId, quote: segment.quote, ...(segment.pdfPage ? { pdfPage: segment.pdfPage } : {}) }),
|
|
5434
5939
|
...(controller === null ? {} : { signal: controller.signal }),
|
|
5435
5940
|
})
|
|
5436
5941
|
if (glossSeq.current !== seq) return
|
|
@@ -5496,7 +6001,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
5496
6001
|
try {
|
|
5497
6002
|
const result = await api('/gloss', {
|
|
5498
6003
|
method: 'POST',
|
|
5499
|
-
body: JSON.stringify({ documentId: readerId, blockId: segment.blockId, quote: segment.quote, ...(segment.pdfPage ? { pdfPage: segment.pdfPage } : {}) }),
|
|
6004
|
+
body: JSON.stringify({ sessionId, documentId: readerId, blockId: segment.blockId, quote: segment.quote, ...(segment.pdfPage ? { pdfPage: segment.pdfPage } : {}) }),
|
|
5500
6005
|
...(controller === null ? {} : { signal: controller.signal }),
|
|
5501
6006
|
})
|
|
5502
6007
|
if (glossSeq.current !== seq) return
|
|
@@ -5755,6 +6260,196 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
5755
6260
|
? '当前版本不支持并排(宿主没有分栏接口)。'
|
|
5756
6261
|
: '没能并排:右栏宽度不足或已经开了两格;拖宽右栏后再试。')
|
|
5757
6262
|
}
|
|
6263
|
+
/**
|
|
6264
|
+
* 三个排版按钮跟着**当前档位**走(D195,读者裁定「选到哪就显示那个档的字体设置」)。
|
|
6265
|
+
*
|
|
6266
|
+
* | 档位 | 改的是哪一套 |
|
|
6267
|
+
* | --- | --- |
|
|
6268
|
+
* | 原文(src) | 原文那套,不给选择 |
|
|
6269
|
+
* | 译文(zh) | 译文那套,不给选择 |
|
|
6270
|
+
* | 双语(bi) | 由 typeSide 决定,前面另给一个「原 / 译」小切换 |
|
|
6271
|
+
* | PDF / 笔记 | 沿用上一次的单语言档(typeSide),**不跳变** |
|
|
6272
|
+
*
|
|
6273
|
+
* 🔴 PDF 与笔记档不参与归属判断:PDF 是位图、笔记是批注面板,它们没有"正文语言"。
|
|
6274
|
+
* 让它们各自记一套等于多出两个永远没人改的存储槽。
|
|
6275
|
+
*/
|
|
6276
|
+
const typeSideOf = () => (paneView === 'src' ? 'src' : paneView === 'zh' ? 'zh' : typeSide)
|
|
6277
|
+
/** 双语档才给的「原 / 译」小切换:切它会同时改 typeSide 与三个按钮显示的值。 */
|
|
6278
|
+
const typeSideSwitch = () => {
|
|
6279
|
+
if (paneView !== 'bi') return null
|
|
6280
|
+
const values = ['src', 'zh']
|
|
6281
|
+
const index = Math.max(0, values.indexOf(typeSideOf()))
|
|
6282
|
+
return h('div', {
|
|
6283
|
+
className: 'paper-seg paper-type-side',
|
|
6284
|
+
role: 'tablist',
|
|
6285
|
+
'aria-label': '改哪一套排版',
|
|
6286
|
+
// 🔴 滑块的下标必须和项数一起给。只给项数时 --paper-seg-index 取默认值 0,
|
|
6287
|
+
// 白块就永远停在「原」上 —— 而「译」的文字照样变深(那走的是 aria-selected 的
|
|
6288
|
+
// color/font-weight),于是症状是「颜色变了,块还在原字上」(用户实测报过)。
|
|
6289
|
+
// 另两处分段控件(档位、阅读状态)都是这么给的两个变量,这里曾经漏了一个。
|
|
6290
|
+
style: {
|
|
6291
|
+
'--paper-seg-count': String(values.length),
|
|
6292
|
+
'--paper-seg-index': String(index),
|
|
6293
|
+
},
|
|
6294
|
+
}, values.map(value => h('button', {
|
|
6295
|
+
className: 'paper-btn', type: 'button', role: 'tab', key: value,
|
|
6296
|
+
'aria-selected': typeSideOf() === value,
|
|
6297
|
+
'aria-label': value === 'src' ? '改原文那套排版' : '改译文那套排版',
|
|
6298
|
+
title: value === 'src' ? '改原文那套排版' : '改译文那套排版',
|
|
6299
|
+
onClick: () => setTypeSide(value),
|
|
6300
|
+
}, value === 'src' ? '原' : '译')))
|
|
6301
|
+
}
|
|
6302
|
+
/**
|
|
6303
|
+
* 一个排版按钮 + 它自己的弹层。
|
|
6304
|
+
*
|
|
6305
|
+
* 🔴 三个弹层**互斥**(读者裁定):点另一个直接换过去,点空白或 Esc 关闭,再点同一个收起。
|
|
6306
|
+
* 同时开两个会在 300px 的侧栏里叠成一片,谁也看不清。
|
|
6307
|
+
*
|
|
6308
|
+
* @param {string} key 弹层标识(size / height / family)。
|
|
6309
|
+
* @param {string} label 按钮上的文字,直接显示**当前值**。
|
|
6310
|
+
* @param {string} title 悬停说明。
|
|
6311
|
+
* @param {object} pop 弹层内容。
|
|
6312
|
+
*/
|
|
6313
|
+
/**
|
|
6314
|
+
* 点外部关闭排版弹层。
|
|
6315
|
+
*
|
|
6316
|
+
* 🔴 **不能用铺满视口的透明遮罩**(第一版就是),它会盖住整条顶栏 —— 「原 / 译」
|
|
6317
|
+
* 切换、并排、注入、五个视图档位统统点不动,用户实测报「原/译按钮点击无反应」。
|
|
6318
|
+
* 遮罩的本意是"点空白处关闭",代价却是"整条顶栏都变成空白"。
|
|
6319
|
+
* 改成在 document 上听一次捕获阶段的 pointerdown:点在弹层或任一排版按钮之外才关。
|
|
6320
|
+
*/
|
|
6321
|
+
React.useEffect(() => {
|
|
6322
|
+
// 🔴 字体档交给 Menu 自己关。它 portal 到 document.body,压根不在
|
|
6323
|
+
// .paper-type-row-holder 子树里,于是下面这个「点在外面」的判据把菜单项本身
|
|
6324
|
+
// 也当成外面:捕获阶段的 pointerdown 先 setTypePop(''),菜单连同里面的按钮
|
|
6325
|
+
// 当场卸载,后面的 click 就没有目标了 —— 症状正是「点楷体毫无反应,菜单还开着」
|
|
6326
|
+
// (用户实测:加的探针一行都没打出来,说明 onSelect 从未被调用)。
|
|
6327
|
+
// Menu 自己就监听 document 的 pointerdown 并区分内外,这一档不必也不该再插手。
|
|
6328
|
+
if (typePop === '' || typePop === 'family') return undefined
|
|
6329
|
+
const away = event => {
|
|
6330
|
+
const node = event?.target
|
|
6331
|
+
if (node !== null && typeof node?.closest === 'function' && node.closest('.paper-type-row-holder') !== null) return
|
|
6332
|
+
setTypePop('')
|
|
6333
|
+
}
|
|
6334
|
+
document.addEventListener('pointerdown', away, true)
|
|
6335
|
+
return () => document.removeEventListener('pointerdown', away, true)
|
|
6336
|
+
}, [typePop])
|
|
6337
|
+
/**
|
|
6338
|
+
* 一个排版按钮。**弹层不挂在按钮上**,见 typePopover 的说明。
|
|
6339
|
+
*
|
|
6340
|
+
* @param {string} key 弹层标识(size / height / family)。
|
|
6341
|
+
* @param {string} label 按钮上的文字,直接显示**当前值**。
|
|
6342
|
+
* @param {string} title 悬停说明,也是弹层的 aria-label。
|
|
6343
|
+
*/
|
|
6344
|
+
const typeButton = (key, label, title) => {
|
|
6345
|
+
const open = typePop === key
|
|
6346
|
+
return h('button', {
|
|
6347
|
+
className: 'paper-btn paper-type-trigger' + (open ? ' active' : ''),
|
|
6348
|
+
type: 'button', key,
|
|
6349
|
+
'aria-label': title,
|
|
6350
|
+
'aria-expanded': open,
|
|
6351
|
+
title,
|
|
6352
|
+
onClick: () => setTypePop(open ? '' : key),
|
|
6353
|
+
}, h('span', { className: 'paper-type-glyph' }, 'Aa'), label)
|
|
6354
|
+
}
|
|
6355
|
+
/**
|
|
6356
|
+
* 字体那一档的触发按钮。**与上面两个同构**:同样的类名、同样的 Aa 起头、同样把当前值
|
|
6357
|
+
* 写成文字。它点开的是宿主的 Menu(见 typeFamily),但按钮本身不该长成别的东西 ——
|
|
6358
|
+
* 三个排版按钮并排,其中两个是 .paper-btn 一个是 .paper-input 的话,一眼就看得出破绽。
|
|
6359
|
+
*/
|
|
6360
|
+
const typeFamilyTrigger = (side, open) => h('button', {
|
|
6361
|
+
className: 'paper-btn paper-type-trigger' + (open ? ' active' : ''),
|
|
6362
|
+
type: 'button',
|
|
6363
|
+
'aria-label': '字体',
|
|
6364
|
+
'aria-haspopup': 'menu',
|
|
6365
|
+
'aria-expanded': open,
|
|
6366
|
+
title: '字体',
|
|
6367
|
+
onClick: () => setTypePop(open ? '' : 'family'),
|
|
6368
|
+
}, h('span', { className: 'paper-type-glyph' }, 'Aa'),
|
|
6369
|
+
(fontFamiliesOf(side).find(entry => entry.value === readerType[side].family)?.label ?? fontFamiliesOf(side)[0].label))
|
|
6370
|
+
/**
|
|
6371
|
+
* 当前开着的那个滑杆弹层(字号 / 行距)。**挂在顶栏这一行上,不挂在按钮上。**
|
|
6372
|
+
*
|
|
6373
|
+
* 🔴 为什么不跟按钮走(用户实测截图报「都看不到了」):弹层 220px 宽,挂在某个按钮上
|
|
6374
|
+
* 就只能在那个按钮的坐标里选锚点 ——
|
|
6375
|
+
* · 锚左沿(left:0)时,最右的那个一点开就朝右伸出侧栏被裁掉;
|
|
6376
|
+
* · 锚右沿(right:0)时,最左的「字号」反过来朝左溢出,一样看不见。
|
|
6377
|
+
* 侧栏最窄 300px,220px 的弹层无论锚哪一端都盖不住整排按钮的跨度。
|
|
6378
|
+
*
|
|
6379
|
+
* 挂在顶栏行上就没有这个两难:left:0; right:0 铺满整行,永远在容器里面,
|
|
6380
|
+
* 侧栏多窄都完整可见。代价是弹层比按钮宽,但那正是它该有的样子 ——
|
|
6381
|
+
* 这个弹层里放的是**一个滑杆 + 它的数值**,不是按钮的下拉菜单。
|
|
6382
|
+
*
|
|
6383
|
+
* 字体那一档不是滑杆,它是选项列表,所以走宿主的 Menu(见 typeFamily)——
|
|
6384
|
+
* 由 Menu 自己 portal 到 body,同样不受侧栏裁剪。
|
|
6385
|
+
*/
|
|
6386
|
+
const typePopover = () => {
|
|
6387
|
+
if (typePop === '' || typePop === 'family' || typeControlsHidden()) return null
|
|
6388
|
+
const side = typeSideOf()
|
|
6389
|
+
const spec = {
|
|
6390
|
+
size: { title: '字号', body: typeSlider(side, 'size', MIN_FONT_SIZE, MAX_FONT_SIZE, 1, '字号') },
|
|
6391
|
+
height: { title: '行距', body: typeSlider(side, 'height', MIN_LINE_HEIGHT, MAX_LINE_HEIGHT, 1, '行距', 10) },
|
|
6392
|
+
}[typePop]
|
|
6393
|
+
if (spec === undefined) return null
|
|
6394
|
+
return h('div', {
|
|
6395
|
+
className: 'paper-type-panel paper-type-pop', role: 'dialog', 'aria-label': spec.title,
|
|
6396
|
+
onKeyDown: event => { if (event?.key === 'Escape') setTypePop('') },
|
|
6397
|
+
}, spec.body)
|
|
6398
|
+
}
|
|
6399
|
+
/** 字号 / 行距共用的滑杆。步长与区间取自源码常量,不在这里写死数字。 */
|
|
6400
|
+
const typeSlider = (side, field, min, max, step, unit, scale = 1) => {
|
|
6401
|
+
const current = readerType[side][field]
|
|
6402
|
+
return h('label', { className: 'paper-type-row' },
|
|
6403
|
+
h('span', null, unit),
|
|
6404
|
+
h('input', {
|
|
6405
|
+
type: 'range', min: String(min), max: String(max), step: String(step),
|
|
6406
|
+
value: String(current),
|
|
6407
|
+
'aria-label': unit,
|
|
6408
|
+
onChange: event => {
|
|
6409
|
+
const raw = Number(event?.target?.value)
|
|
6410
|
+
if (!Number.isFinite(raw)) return
|
|
6411
|
+
patchType(side, { [field]: Math.round(Math.min(max, Math.max(min, raw))) })
|
|
6412
|
+
},
|
|
6413
|
+
}),
|
|
6414
|
+
h('span', { className: 'paper-type-value' }, scale === 10 ? (current / 10).toFixed(1) : String(current)))
|
|
6415
|
+
}
|
|
6416
|
+
/**
|
|
6417
|
+
* 字体族下拉。三档固定清单,取值校验在 fontOf 那一层。
|
|
6418
|
+
*
|
|
6419
|
+
* 🔴 用宿主的 Menu,不是原生 select(用户实测截图:原生那份是系统画的直角白底蓝条,
|
|
6420
|
+
* 与侧栏、与同一排的字号/行距滑杆都不是一套东西)。三档正好对应 Menu 的单选形态:
|
|
6421
|
+
* selectedId 打勾,portal 让浮层挂到 body —— 顶栏这一行在窄侧栏里放不下 220px 的卡。
|
|
6422
|
+
*/
|
|
6423
|
+
const typeFamily = side => h(Menu, {
|
|
6424
|
+
open: typePop === 'family',
|
|
6425
|
+
onClose: () => setTypePop(''),
|
|
6426
|
+
items: fontFamiliesOf(side).map(entry => ({ id: entry.value, label: entry.label })),
|
|
6427
|
+
selectedId: readerType[side].family,
|
|
6428
|
+
onSelect: id => { setTypePop(''); patchType(side, { family: fontOf(side, id) }) },
|
|
6429
|
+
portal: true,
|
|
6430
|
+
minWidthFromAnchor: true,
|
|
6431
|
+
anchor: typeFamilyTrigger(side, typePop === 'family'),
|
|
6432
|
+
})
|
|
6433
|
+
/**
|
|
6434
|
+
* 三个排版按钮整体。双语档时前面多一个「原 / 译」切换。
|
|
6435
|
+
*
|
|
6436
|
+
* 🔴 **PDF 档不渲染**(用户裁定):那一档是原页位图,位图上的字由 PDF 自己排版,
|
|
6437
|
+
* 我们的字号 / 行距 / 字体一个都不作用于它。摆在顶栏上就是个点了没反应的假控件。
|
|
6438
|
+
* 笔记档同理 —— 它是批注面板,不是正文。两档都不渲染,不是置灰:
|
|
6439
|
+
* 灰按钮仍然占位,而这两档本来就不该有"能调但调不了"的暗示。
|
|
6440
|
+
*/
|
|
6441
|
+
/** 这一档要不要出排版控件(PDF 是位图、笔记是批注面板,都不出)。 */
|
|
6442
|
+
const typeControlsHidden = () => isPdfPane(paneView) || paneView === 'notes'
|
|
6443
|
+
const typeControls = () => {
|
|
6444
|
+
if (typeControlsHidden()) return null
|
|
6445
|
+
const side = typeSideOf()
|
|
6446
|
+
return [
|
|
6447
|
+
typeSideSwitch(),
|
|
6448
|
+
typeButton('size', `${readerType[side].size}px`, '字号'),
|
|
6449
|
+
typeButton('height', (readerType[side].height / 10).toFixed(1), '行距'),
|
|
6450
|
+
typeFamily(side),
|
|
6451
|
+
].filter(item => item !== null && item !== undefined && item !== false)
|
|
6452
|
+
}
|
|
5758
6453
|
/** 阅读视图共用一组分段按钮,选择结果按全局偏好保存。 */
|
|
5759
6454
|
const paneSegmented = () => h('div', {
|
|
5760
6455
|
className: 'paper-seg paper-reader-view',
|
|
@@ -5803,9 +6498,10 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
5803
6498
|
let failure = ''
|
|
5804
6499
|
try {
|
|
5805
6500
|
for (const target of targets) {
|
|
5806
|
-
|
|
6501
|
+
// 这一块在页栈的哪一页上:按页键遍历已挂载的页找(页栈之前是直接读 pdfData.page)。
|
|
6502
|
+
const nativePage = target.pdfPage ?? pdfMountedPages.find(page => pdfPages[pdfStackKey(documentId, page, pdfCrop)]?.groups?.some(group => group.id === target.blockId))
|
|
5807
6503
|
try {
|
|
5808
|
-
const result = await api('/gloss', { method: 'POST', body: JSON.stringify({ documentId, blockId: target.blockId, quote: target.quote, align: true, markId: target.id, ...(nativePage ? { pdfPage: nativePage } : {}) }) })
|
|
6504
|
+
const result = await api('/gloss', { method: 'POST', body: JSON.stringify({ sessionId, documentId, blockId: target.blockId, quote: target.quote, align: true, markId: target.id, ...(nativePage ? { pdfPage: nativePage } : {}) }) })
|
|
5809
6505
|
if (readerRef.current !== documentId) return
|
|
5810
6506
|
if (typeof result?.parallelQuote === 'string' && result.parallelQuote) {
|
|
5811
6507
|
matched += 1
|
|
@@ -6295,41 +6991,112 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6295
6991
|
const zhLines = React.useMemo(() => columns !== null ? columns.zh : visibleRows(readerVisible, paneView === 'notes' ? 'zh' : paneView, 'single'), [columns, readerVisible, paneView])
|
|
6296
6992
|
const srcLines = columns !== null ? columns.src : []
|
|
6297
6993
|
// ---- PDF page and native selection layer ----
|
|
6994
|
+
// 这篇的最后一页。放在渲染期最前:页栈窗口、滚动比例、翻页按钮都要用它,
|
|
6995
|
+
// 而它只跟块列表有关 —— 摆到页栈下面会在渲染期撞 TDZ(依赖数组在求值时立即读它)。
|
|
6996
|
+
const readerLastPage = React.useMemo(() => readerBlocks.reduce((max, row) => (typeof row.page === 'number' && row.page > max ? row.page : max), 0), [readerBlocks])
|
|
6298
6997
|
const firstPage = React.useMemo(() => (readerBlocks.find(row => typeof row.page === 'number')?.page) ?? 1, [readerBlocks])
|
|
6299
6998
|
const currentPage = readerPage === null ? firstPage : readerPage
|
|
6300
|
-
|
|
6999
|
+
// 当前页的文字层。页栈里同时挂着好几页,但**"当前页"仍是单数** —— 阅读位置、进度落盘、
|
|
7000
|
+
// 并排广播都只认一页。查不到是 null(第一次打开、这一页还在路上)。
|
|
7001
|
+
const activePdf = pdfPages[pdfStackKey(readerId, currentPage, pdfCrop)] ?? null
|
|
7002
|
+
// 这篇一共几页:首份文字层给的 pageCount 最准(宿主逐页都带),拿不到时退回块列表的最大页码。
|
|
7003
|
+
const pdfTotal = pdfPageCount > 0 ? pdfPageCount : readerLastPage
|
|
7004
|
+
// 该挂载哪几页。radius=1 就是「当前页 ± 1」,是滑动手感的下限:滚到一页底部时
|
|
7005
|
+
// 下一页必须已经在 DOM 里,否则会先看到一屏骨架再等 JSON。见 pdfPageWindow 的说明。
|
|
7006
|
+
const pdfWindow = React.useMemo(
|
|
7007
|
+
() => (isPdfPane(paneView) ? pdfPageWindow(currentPage, pdfTotal, 1) : []),
|
|
7008
|
+
[paneView, currentPage, pdfTotal],
|
|
7009
|
+
)
|
|
7010
|
+
// 已挂载那几页的页码(页栈之外的地方拿它反查"这一块在第几页")。
|
|
7011
|
+
const pdfMountedPages = pdfWindow
|
|
7012
|
+
/**
|
|
7013
|
+
* 窗口内所有页的文字层段落合集。
|
|
7014
|
+
*
|
|
7015
|
+
* 🔴 划线与引用涂色都要按**块**找文本,而连续滚动下一个块可能落在窗口内任意一页 ——
|
|
7016
|
+
* 只看当前页会漏掉滚到一半时横跨两页的那些块(旧单页版永远只有一页,所以没这个问题)。
|
|
7017
|
+
* 合集顺序按页码升序,pdfBlockTextOf 取第一个命中的段落,与旧口径一致。
|
|
7018
|
+
*/
|
|
7019
|
+
const pdfGroupsAll = React.useMemo(() => {
|
|
7020
|
+
const merged = []
|
|
7021
|
+
for (const page of pdfWindow) {
|
|
7022
|
+
const data = pdfPages[pdfStackKey(readerId, page, pdfCrop)]
|
|
7023
|
+
if (data === undefined || !Array.isArray(data.groups)) continue
|
|
7024
|
+
for (const group of data.groups) merged.push(group)
|
|
7025
|
+
}
|
|
7026
|
+
return merged
|
|
7027
|
+
// pdfMountedPages 是 pdfWindow 的别名,不另立依赖。
|
|
7028
|
+
}, [pdfWindow, pdfPages, readerId, pdfCrop])
|
|
7029
|
+
/**
|
|
7030
|
+
* 取某一页的文字层(按页键去重、按页并发,不互相 abort)。
|
|
7031
|
+
*
|
|
7032
|
+
* 🔴 与单槽那版的差别全在**并发语义**上:原来换页就 abort 上一页,因为同时只需要一页;
|
|
7033
|
+
* 连续滚动下页面栈里前后各挂一页,abort 会让「往回滚一页」重新走一遍网络。
|
|
7034
|
+
* 现在一个页键一个槽位,重复请求直接复用同一个 promise,只有强制重试才换 controller。
|
|
7035
|
+
*
|
|
7036
|
+
* @param {string} documentId 本篇 documentId
|
|
7037
|
+
* @param {number} page 页码(1 起)
|
|
7038
|
+
* @param {boolean} force 忽略已到手的那份,重新取("重试 PDF"按钮)
|
|
7039
|
+
*/
|
|
6301
7040
|
async function loadPdfPage(documentId = readerId, page = currentPage, force = false) {
|
|
6302
7041
|
if (!documentId) return
|
|
7042
|
+
const key = pdfStackKey(documentId, page, pdfCrop)
|
|
7043
|
+
if (key === '') return
|
|
6303
7044
|
if (force) setPdfImageAttempt(value => value + 1)
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
if (!force &&
|
|
6307
|
-
if (!force &&
|
|
6308
|
-
|
|
7045
|
+
const flight = pdfRequestRef.current
|
|
7046
|
+
// 已经有这一页了,且不是强制重试:什么都不用做(滚动窗口会反复调到这里)。
|
|
7047
|
+
if (!force && pdfPages[key] !== undefined) return
|
|
7048
|
+
if (!force && flight.has(key)) return flight.get(key).promise
|
|
7049
|
+
flight.get(key)?.controller?.abort()
|
|
6309
7050
|
const controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
6310
7051
|
const request = { key, controller }
|
|
6311
|
-
|
|
7052
|
+
flight.set(key, request)
|
|
6312
7053
|
setPdfFailure(''); setPdfLoading(true)
|
|
6313
7054
|
request.promise = api('/pdf-page?documentId=' + encodeURIComponent(documentId) + '&page=' + page + (pdfCrop ? '&crop=1' : ''),
|
|
6314
7055
|
controller ? { signal: controller.signal } : undefined).then(data => {
|
|
6315
|
-
|
|
6316
|
-
|
|
7056
|
+
// 换篇之后,旧篇还在飞的请求回来要丢掉 —— 判据是**这一篇还是不是当前篇**,
|
|
7057
|
+
// 而不是"这个槽位有没有被顶掉"(槽位按页键分开,永远顶不到彼此)。
|
|
7058
|
+
if (readerRef.current !== documentId) return
|
|
7059
|
+
setPdfPages(current => ({ ...current, [key]: { ...data, documentId, cropped: pdfCrop } }))
|
|
7060
|
+
const count = Number(data?.pageCount)
|
|
7061
|
+
if (Number.isSafeInteger(count) && count > 0) setPdfPageCount(current => (current === count ? current : count))
|
|
6317
7062
|
}).catch(reason => {
|
|
6318
|
-
if (reason?.name !== 'AbortError' && readerRef.current === documentId
|
|
7063
|
+
if (reason?.name !== 'AbortError' && readerRef.current === documentId) setPdfFailure(String(reason?.message ?? reason))
|
|
6319
7064
|
}).finally(() => {
|
|
6320
|
-
if (
|
|
7065
|
+
if (flight.get(key) === request) {
|
|
7066
|
+
flight.delete(key)
|
|
7067
|
+
// 还有别的页在路上就别熄灭加载提示 —— 连续滚动下同时两三页是常态。
|
|
7068
|
+
if (flight.size === 0) setPdfLoading(false)
|
|
7069
|
+
}
|
|
6321
7070
|
})
|
|
6322
7071
|
return request.promise
|
|
6323
7072
|
}
|
|
7073
|
+
/**
|
|
7074
|
+
* 滚到某一页的页顶(按钮与滚轮**共用这一个入口**)。
|
|
7075
|
+
*
|
|
7076
|
+
* 🔴 用户裁定「按钮保留,点击下一页自动移动到下一页」:连续滚动下按钮不再是"换一份数据",
|
|
7077
|
+
* 而是"把容器滚到那一页"。与滚轮共用同一个滚动位置,两种操作因此不可能各说一套。
|
|
7078
|
+
* 平滑滚动用 `behavior:'smooth'`;量不到页顶(还没挂上、替身没有 DOM)时退回朴素 scrollTo,
|
|
7079
|
+
* 不编一个位置。
|
|
7080
|
+
*/
|
|
7081
|
+
const scrollToPage = page => {
|
|
7082
|
+
const container = layoutElRef.current
|
|
7083
|
+
const node = pdfFrameRefs.current.get(page) ?? null
|
|
7084
|
+
const top = node === null ? null : blockScrollTopOf(container, node, 0)
|
|
7085
|
+
if (top !== null) container?.scrollTo?.({ top, left: 0, behavior: 'smooth' })
|
|
7086
|
+
else container?.scrollTo?.({ top: 0, left: 0 })
|
|
7087
|
+
}
|
|
6324
7088
|
const changePdfPage = page => {
|
|
6325
7089
|
dismissMark()
|
|
6326
7090
|
pendingScrollRef.current = ''
|
|
6327
7091
|
setScrollTarget('')
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
7092
|
+
const target = Number(page)
|
|
7093
|
+
if (!Number.isSafeInteger(target) || target < 1) return
|
|
7094
|
+
// 先确保这一页与它的邻居在窗口里(快速连点时窗口还没跟上),再滚过去。
|
|
7095
|
+
void loadPdfPage(readerId, target)
|
|
7096
|
+
setReaderPage(target)
|
|
7097
|
+
scrollToPage(target)
|
|
7098
|
+
const row = readerBlocks.find(block => block.page === target)
|
|
7099
|
+
readingRef.current = { block: row?.id ?? '', page: target }
|
|
6333
7100
|
// 并排时把「我翻到哪一段」广播给对面(D188,用户实测报「PDF 翻页时译文没跟着滑」)。
|
|
6334
7101
|
// 🔴 原页档**没有 scroll 事件**(onScroll 在这一档是 undefined),所以它是全仓唯一
|
|
6335
7102
|
// 不会自动发锚点的档 —— 翻页必须在这里显式补一发,否则对面永远停在原处。
|
|
@@ -6339,32 +7106,78 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6339
7106
|
publishScrollAnchor(readerRef.current, row.id, paneRole, 0)
|
|
6340
7107
|
}
|
|
6341
7108
|
}
|
|
7109
|
+
// 窗口内的每一页都要有文字层:滚到边界之前下一页必须已经在(见 pdfPageWindow)。
|
|
7110
|
+
// 依赖里放 pdfWindow 而不只是 currentPage —— 页数从 0 变成真实值时窗口会重算。
|
|
6342
7111
|
React.useEffect(() => {
|
|
6343
|
-
if (isPdfPane(paneView)
|
|
6344
|
-
|
|
6345
|
-
|
|
7112
|
+
if (!isPdfPane(paneView) || readerId === '') return
|
|
7113
|
+
for (const page of pdfWindow) void loadPdfPage(readerId, page)
|
|
7114
|
+
}, [readerId, pdfWindow, paneView])
|
|
7115
|
+
// 切裁边档位要重取:键里的裁边变了,旧那份一个字也用不上(坐标与图都随它变)。
|
|
6346
7116
|
React.useEffect(() => {
|
|
6347
7117
|
if (!isPdfPane(paneView) || !readerId) return
|
|
6348
|
-
void loadPdfPage(readerId,
|
|
7118
|
+
for (const page of pdfWindow) void loadPdfPage(readerId, page)
|
|
6349
7119
|
}, [pdfCrop])
|
|
6350
|
-
|
|
7120
|
+
// 卸载:把所有在飞的页请求一起撤掉(Map 里可能有好几个,单槽那版只撤了一个)。
|
|
7121
|
+
React.useEffect(() => () => {
|
|
7122
|
+
for (const request of pdfRequestRef.current.values()) request.controller?.abort()
|
|
7123
|
+
pdfRequestRef.current.clear()
|
|
7124
|
+
}, [])
|
|
7125
|
+
// 比例尺逐页算:文字层按 PDF 点坐标绝对定位,得乘上"这一页渲染出来多宽 / PDF 多宽"。
|
|
7126
|
+
// 🔴 每页各一份 ResizeObserver 而不是只观察当前页 —— 否则滚到下一页时它的比例尺还是 0,
|
|
7127
|
+
// 整层文字会缩成一个点(transform:scale(0) 就在 CSS 里当默认值)。
|
|
6351
7128
|
React.useEffect(() => {
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
const
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
7129
|
+
if (!isPdfPane(paneView)) return undefined
|
|
7130
|
+
const frames = pdfFrameRefs.current
|
|
7131
|
+
const cleanups = []
|
|
7132
|
+
for (const page of pdfWindow) {
|
|
7133
|
+
const frame = frames.get(page) ?? null
|
|
7134
|
+
const data = pdfPages[pdfStackKey(readerId, page, pdfCrop)] ?? null
|
|
7135
|
+
if (frame === null || data === null || !(Number(data.width) > 0)) continue
|
|
7136
|
+
const fit = () => frame.style.setProperty('--paper-pdf-scale', String(frame.getBoundingClientRect().width / data.width))
|
|
7137
|
+
fit()
|
|
7138
|
+
const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(fit) : null
|
|
7139
|
+
observer?.observe(frame)
|
|
7140
|
+
cleanups.push(() => observer?.disconnect())
|
|
7141
|
+
}
|
|
7142
|
+
const onResize = () => {
|
|
7143
|
+
for (const page of pdfWindow) {
|
|
7144
|
+
const frame = frames.get(page) ?? null
|
|
7145
|
+
const data = pdfPages[pdfStackKey(readerId, page, pdfCrop)] ?? null
|
|
7146
|
+
if (frame === null || data === null || !(Number(data.width) > 0)) continue
|
|
7147
|
+
frame.style.setProperty('--paper-pdf-scale', String(frame.getBoundingClientRect().width / data.width))
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
window.addEventListener('resize', onResize)
|
|
7151
|
+
return () => { for (const stop of cleanups) stop(); window.removeEventListener('resize', onResize) }
|
|
7152
|
+
}, [pdfWindow, pdfPages, paneView, readerId, pdfCrop, pdfZoom])
|
|
7153
|
+
/**
|
|
7154
|
+
* 一页的原页位图 + 选字层(连续滚动的**一个页位**)。
|
|
7155
|
+
*
|
|
7156
|
+
* 🔴 与单页那版的差别只在**入参**:原来的 `activePdf` 是"永远指向当前页"的闭包变量,
|
|
7157
|
+
* 页栈里同时挂着前后各一页,每一页都得按自己的文字层画,所以它变成参数。
|
|
7158
|
+
* 函数体一根线不动 —— 位图与坐标同源(同 crop 档)、逐字符 span 拉伸对齐、
|
|
7159
|
+
* 引用悬停走 ref 转存,全部照旧,这样选字精度不会被这次改动碰到。
|
|
7160
|
+
*
|
|
7161
|
+
* @param {number} page 页码(1 起)
|
|
7162
|
+
* @param {object|null} activePdf 这一页的文字层(未到是 null,只画位图)
|
|
7163
|
+
* @param {number|null} aspect 统一的宽高比(见 pdfPageAspectOf),null 时按图片自然尺寸
|
|
7164
|
+
*/
|
|
7165
|
+
const pdfPageNode = (page, activePdf, aspect) => h('div', {
|
|
7166
|
+
className: 'paper-pdf-page',
|
|
7167
|
+
// 每页一个容器引用:比例尺、滚动定位、涂色都要按页找到它。
|
|
7168
|
+
ref: node => { if (node === null) pdfFrameRefs.current.delete(page); else pdfFrameRefs.current.set(page, node) },
|
|
7169
|
+
'data-page': page,
|
|
7170
|
+
style: {
|
|
7171
|
+
width: (pdfZoom * 100) + '%',
|
|
7172
|
+
// 位图没到之前先用统一比例占住高度,滚动条不会随加载跳动。
|
|
7173
|
+
aspectRatio: aspect === null ? undefined : String(aspect),
|
|
7174
|
+
},
|
|
6364
7175
|
}, h('img', {
|
|
6365
|
-
key: readerId + ':' +
|
|
6366
|
-
className: 'paper-pdf-image', src: pageImageUrl(readerId,
|
|
7176
|
+
key: readerId + ':' + page + ':' + pdfImageAttempt,
|
|
7177
|
+
className: 'paper-pdf-image', src: pageImageUrl(readerId, page, PAGE_IMAGE_WIDTH, pdfCrop), alt: 'PDF 原文 · 第 ' + page + ' 页',
|
|
6367
7178
|
draggable: false, width: activePdf?.width, height: activePdf?.height,
|
|
7179
|
+
// 窗口里通常还挂着前后各一页,让浏览器自己排加载顺序比我们抢带宽更准。
|
|
7180
|
+
loading: 'lazy', decoding: 'async',
|
|
6368
7181
|
onError: () => setPdfFailure(PAGE_IMAGE_FAILED_NOTE),
|
|
6369
7182
|
}), activePdf ? h('div', { className: 'paper-pdf-text', style: { width: activePdf.width, height: activePdf.height } },
|
|
6370
7183
|
activePdf.groups.map(group => {
|
|
@@ -6376,7 +7189,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6376
7189
|
rows.at(-1).words.push(word)
|
|
6377
7190
|
}
|
|
6378
7191
|
return h('div', {
|
|
6379
|
-
|
|
7192
|
+
// 🔴 key 必须带上 part:一个块被拆成多段时 id 相同,只按 id 做 key 会撞。
|
|
7193
|
+
className: 'paper-pdf-block', key: group.id + '#' + (group.part ?? 0), 'data-block-id': group.id, 'data-language': 'source', 'data-pdf-page': activePdf.page,
|
|
6380
7194
|
style: { left: bounds[0] * activePdf.width / 1000, top: bounds[1] * activePdf.height / 1000,
|
|
6381
7195
|
width: (bounds[2] - bounds[0]) * activePdf.width / 1000, height: (bounds[3] - bounds[1]) * activePdf.height / 1000 },
|
|
6382
7196
|
onMouseUp: event => { event.stopPropagation?.(); captureSelection(event, true) },
|
|
@@ -6428,8 +7242,9 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6428
7242
|
if (!node || !(width > 0)) return
|
|
6429
7243
|
const context = pdfMeasureRef.current ??= document.createElement('canvas').getContext?.('2d')
|
|
6430
7244
|
if (!context) return
|
|
6431
|
-
|
|
6432
|
-
|
|
7245
|
+
// 走 glyphWidthOf 而不是直接 measureText:同一字号 + 同一字串的宽度是确定的,
|
|
7246
|
+
// 缓存能省掉 88% 的测量(见 glyphWidthOf 的说明)。
|
|
7247
|
+
const metrics = pdfWordMetrics(core, width, gap, text => glyphWidthOf(context, size, text) ?? 0)
|
|
6433
7248
|
if (!metrics) return
|
|
6434
7249
|
node.style.letterSpacing = metrics.letterSpacing + 'px'
|
|
6435
7250
|
node.style.wordSpacing = metrics.wordSpacing + 'px'
|
|
@@ -6440,9 +7255,9 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6440
7255
|
const stretchChar = (node, advance) => {
|
|
6441
7256
|
if (!node) return
|
|
6442
7257
|
const context = pdfMeasureRef.current ??= document.createElement('canvas').getContext?.('2d')
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
node.style.letterSpacing = (advance -
|
|
7258
|
+
const measured = glyphWidthOf(context, size, node.textContent)
|
|
7259
|
+
if (measured === null) return
|
|
7260
|
+
node.style.letterSpacing = (advance - measured) + 'px'
|
|
6446
7261
|
}
|
|
6447
7262
|
return h('span', {
|
|
6448
7263
|
className: 'paper-pdf-word', key: index,
|
|
@@ -6457,9 +7272,44 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6457
7272
|
}, char.text)) : core)
|
|
6458
7273
|
}))
|
|
6459
7274
|
}))
|
|
6460
|
-
})) : null)
|
|
6461
|
-
|
|
6462
|
-
|
|
7275
|
+
})) : null)
|
|
7276
|
+
/**
|
|
7277
|
+
* 页栈本体:窗口内的每一页竖直排开,滚轮 / 触控板 / 滚动条全都交给浏览器原生滚动。
|
|
7278
|
+
*
|
|
7279
|
+
* 🔴 这就是「鼠标滑动浏览上一页/下一页」的全部实现 —— **没有任何 wheel 事件处理**。
|
|
7280
|
+
* 容器本来就是 overflow:auto 的 .paper-reader-layout,页面一页页往下排之后,
|
|
7281
|
+
* 滑动就是滚动,滚动就是翻页。这与「连续滚动,页面一页页往下排」的裁定一致。
|
|
7282
|
+
*
|
|
7283
|
+
* 🔴 **窗口化是唯一的数据闸门**:一页文字层约 4,300 个 DOM 节点(逐字符对齐的代价,
|
|
7284
|
+
* 见 pdfPageNode 的说明),全篇 12 页就是 5 万个节点 —— 滚动与重涂都会被拖死。
|
|
7285
|
+
* pdfPageWindow 只放「当前页 ± 1」,滚出窗口的页整页卸载(不是 display:none,
|
|
7286
|
+
* 那还占着节点)。滚到一页底部时下一页必然已在 DOM 里,所以看不到骨架。
|
|
7287
|
+
*
|
|
7288
|
+
* 🔴 页与页之间的间距随缩放走:固定 px 在 300% 时看起来像条分割线。
|
|
7289
|
+
*/
|
|
7290
|
+
const pdfPageView = React.useMemo(() => {
|
|
7291
|
+
// 比例尺取窗口内任一份到手的文字层:篇内各页尺寸相同(实测),所以一份就够。
|
|
7292
|
+
const sample = pdfWindow
|
|
7293
|
+
.map(page => pdfPages[pdfStackKey(readerId, page, pdfCrop)])
|
|
7294
|
+
.find(data => data !== undefined) ?? null
|
|
7295
|
+
const aspect = sample === null ? null : pdfPageAspectOf(sample.width, sample.height)
|
|
7296
|
+
return h('div', { className: 'paper-pdf-stack', 'data-pages': String(pdfWindow.length) },
|
|
7297
|
+
pdfWindow.map(page => h('div', {
|
|
7298
|
+
className: 'paper-pdf-slot' + (page === currentPage ? ' is-current' : ''),
|
|
7299
|
+
key: page,
|
|
7300
|
+
'data-page': page,
|
|
7301
|
+
// 🔴 **不要给页位设高度**,高度一律由页图自己撑开。
|
|
7302
|
+
//
|
|
7303
|
+
// 踩过的坑:这里原来写 `minHeight: calc(100% * aspect)`。百分比是相对**容器**
|
|
7304
|
+
// 高度解析的,而容器高度又由内容加起来 —— 自引用。实测结果就是裁边档下面露出
|
|
7305
|
+
// 一大片纸色空白:图按裁边后的比例只有 0.66 高,容器却按满页 0.77 撑着,
|
|
7306
|
+
// 差出来的那一截全是背景色(用户截图报的"上下的边没有裁")。
|
|
7307
|
+
//
|
|
7308
|
+
// 页面图本身带 `aspect-ratio`(见 pdfPageNode),位图没到时也已经有正确高度,
|
|
7309
|
+
// 所以页位完全不需要自己再撑一遍。这样裁边与整页两档的高度各自由各自的宽高比
|
|
7310
|
+
// 决定,永远不会互相打架。
|
|
7311
|
+
}, pdfPageNode(page, pdfPages[pdfStackKey(readerId, page, pdfCrop)] ?? null, aspect))))
|
|
7312
|
+
}, [pdfWindow, pdfPages, readerId, currentPage, pdfZoom, pdfImageAttempt, pdfCrop])
|
|
6463
7313
|
// Keep the reading bridge available when the library view remounts.
|
|
6464
7314
|
// 这个 effect 必须放在 currentPage 声明之后 —— 依赖数组在渲染期求值,写前面会撞 TDZ。
|
|
6465
7315
|
React.useEffect(() => {
|
|
@@ -6588,13 +7438,16 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6588
7438
|
layoutElRef.current ?? (typeof document !== 'undefined' ? document : null),
|
|
6589
7439
|
markHighlightNames.current,
|
|
6590
7440
|
markGroups(marks),
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
7441
|
+
// 🔴 用**窗口内全部页**的段落合集,不是当前页那一份:连续滚动下一个块可能落在
|
|
7442
|
+
// 相邻那一页上,只看当前页会让滚到一半时的划线整片对不上(旧单页版没有这个问题)。
|
|
7443
|
+
isPdfPane(paneView) && pdfGroupsAll.length > 0 ? reader?.blocks?.map(block => {
|
|
7444
|
+
// 整块正文:块可能被拆成多段 DOM,取某一段会漏另一半。
|
|
7445
|
+
const text = pdfBlockTextOf(pdfGroupsAll, block.id)
|
|
7446
|
+
return text === '' ? block : { ...block, sourceText: text }
|
|
6594
7447
|
}) : reader?.blocks,
|
|
6595
7448
|
)
|
|
6596
7449
|
return undefined
|
|
6597
|
-
}, [highlightSupport, view, reader, marks, paneView,
|
|
7450
|
+
}, [highlightSupport, view, reader, marks, paneView, pdfGroupsAll])
|
|
6598
7451
|
// ---- 引用悬停预览(T25b)----
|
|
6599
7452
|
// 与划线同一范式:渲染树不动,effect 里把已挂载的 DOM 包上 span(见 paintCiteSpans)。
|
|
6600
7453
|
// 依赖与划线那条一致 —— 正文 DOM 会在切换档位时重建,span 必须跟着重包。
|
|
@@ -6624,11 +7477,13 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6624
7477
|
// 只涂前者时原页那侧静默没有任何反应 —— 界面上看不出错,只是"悬停不管用"。
|
|
6625
7478
|
// PDF 这侧的块文本以文字层 group.text 为准(与划线那条同一口径),否则段落正文与
|
|
6626
7479
|
// 页面上真实的字对不上,找位置会失败。
|
|
6627
|
-
|
|
7480
|
+
// 🔴 用**窗口内全部页**的段落合集。连续滚动下窗口里挂着前后各一页,一个块可能落在
|
|
7481
|
+
// 相邻那一页上;只看当前页会让「滚到页边界时引用整片点不动」(旧单页版没这问题)。
|
|
7482
|
+
const pdfMode = isPdfPane(paneView) && pdfGroupsAll.length > 0
|
|
6628
7483
|
const blocks = pdfMode
|
|
6629
7484
|
? (reader?.blocks ?? []).map(block => {
|
|
6630
|
-
const
|
|
6631
|
-
return
|
|
7485
|
+
const text = pdfBlockTextOf(pdfGroupsAll, block.id)
|
|
7486
|
+
return text === '' ? block : { ...block, sourceText: text }
|
|
6632
7487
|
})
|
|
6633
7488
|
: reader?.blocks
|
|
6634
7489
|
const parts = citePartsOf(citeRowsById, blocks, readerNumbers(blocks ?? []))
|
|
@@ -6662,28 +7517,47 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6662
7517
|
paintCiteSpans(layoutElRef.current ?? (typeof document !== 'undefined' ? document : null), parts)
|
|
6663
7518
|
painted.layout = layoutKey
|
|
6664
7519
|
}
|
|
6665
|
-
// 🔴 PDF
|
|
6666
|
-
//
|
|
6667
|
-
//
|
|
7520
|
+
// 🔴 PDF 侧另有一份签名:**任何让页面栈重算的输入**都会重建那几页的子树并丢掉
|
|
7521
|
+
// data-cite-span,那时块内容可能一模一样,仍然必须重涂。
|
|
7522
|
+
// 页面栈的依赖是 [pdfWindow, pdfPages, readerId, currentPage, pdfZoom, pdfImageAttempt, pdfCrop]
|
|
6668
7523
|
// —— 少放一个就会出现「缩放之后悬停失灵」,而界面上完全不报错。
|
|
7524
|
+
// 🔴 签名里**必须有 pdfWindow**:连续滚动时窗口随当前页滑动而换人,
|
|
7525
|
+
// 页内容与块内容可能一个字没变(来回滚同一段),但挂载的是另外几页。
|
|
6669
7526
|
const pdfKey = pdfMode
|
|
6670
|
-
? `${
|
|
7527
|
+
? `${pdfWindow.join('.')}:${pdfCrop ? 1 : 0}:${pdfZoom}:${pdfImageAttempt}:${signature}`
|
|
6671
7528
|
: ''
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
7529
|
+
/**
|
|
7530
|
+
* PDF 侧要不要重涂:**逐页探测**。
|
|
7531
|
+
*
|
|
7532
|
+
* 🔴 与正文栏同一条纪律(见 stillMarked 的说明):签名只当省钱的门槛,正确性落在
|
|
7533
|
+
* 「DOM 里标记还在不在」上。连续滚动后窗口里有多页,任何一页丢了标记都要重涂 ——
|
|
7534
|
+
* 只探当前页会让「滚过去再滚回来」的那一页悬停整片失灵。
|
|
7535
|
+
*/
|
|
7536
|
+
const pdfMissing = () => {
|
|
7537
|
+
for (const page of pdfWindow) {
|
|
7538
|
+
const scope = pdfFrameRefs.current.get(page) ?? null
|
|
7539
|
+
if (scope === null || typeof scope?.querySelectorAll !== 'function') continue
|
|
7540
|
+
if (scope.querySelectorAll('[data-cite-span]').length === 0) return true
|
|
7541
|
+
}
|
|
7542
|
+
return false
|
|
6676
7543
|
}
|
|
6677
|
-
if (pdfKey !== '' && (painted.pdf !== pdfKey ||
|
|
6678
|
-
paintCiteSpans
|
|
7544
|
+
if (pdfKey !== '' && (painted.pdf !== pdfKey || pdfMissing())) {
|
|
7545
|
+
// 🔴 逐页涂:一次 paintCiteSpans 只扫一个子树,而每个页位是独立子树。
|
|
7546
|
+
for (const page of pdfWindow) {
|
|
7547
|
+
const scope = pdfFrameRefs.current.get(page) ?? null
|
|
7548
|
+
if (scope !== null) paintCiteSpans(scope, parts)
|
|
7549
|
+
}
|
|
6679
7550
|
painted.pdf = pdfKey
|
|
6680
7551
|
} else if (pdfKey === '') {
|
|
6681
7552
|
painted.pdf = ''
|
|
6682
7553
|
}
|
|
6683
7554
|
return undefined
|
|
6684
7555
|
// readerBlocks 在依赖里:渲染行变了(换篇、重解析)标记位置也跟着变。
|
|
6685
|
-
//
|
|
6686
|
-
|
|
7556
|
+
// pdfWindow 在依赖里:连续滚动时窗口换人 = 挂载的页换了,不重涂新页就没有悬停。
|
|
7557
|
+
// 🔴 pdfPages 与 pdfWindow **两个都要**在依赖里,不能靠 pdfGroupsAll 的传递性:
|
|
7558
|
+
// 页面栈会因这两者任一变化而重建,而"重建就必须重涂"这条不变量要在源码里看得见
|
|
7559
|
+
// (cite-dom.test.js 逐项比对这两份清单,传递性一律视为没写)。
|
|
7560
|
+
}, [view, reader, readerBlocks, paneView, pdfGroupsAll, pdfPages, pdfWindow, currentPage, pdfZoom, pdfCrop, pdfImageAttempt])
|
|
6687
7561
|
React.useEffect(() => () => { if (citeTimer.current) clearTimeout(citeTimer.current) }, [])
|
|
6688
7562
|
/**
|
|
6689
7563
|
* 指针落进/离开一个引用标记。
|
|
@@ -6714,7 +7588,11 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6714
7588
|
const id = node.getAttribute('data-cite-span')
|
|
6715
7589
|
const root = node.ownerDocument ?? (typeof document === 'undefined' ? null : document)
|
|
6716
7590
|
if (id === null || id === '' || root === null) return []
|
|
6717
|
-
|
|
7591
|
+
// 🔴 从**标记自己所在的那个页位**往上找检查范围,而不是写死当前页:
|
|
7592
|
+
// 连续滚动下窗口里挂着多页,悬停发生的那一页不一定是 currentPage(用户可能正在
|
|
7593
|
+
// 滚向下一页的途中),拿 currentPage 那个容器去找会一个都找不到 —— 表现为"整组不亮"。
|
|
7594
|
+
const own = typeof node.closest === 'function' ? node.closest('.paper-pdf-page') : null
|
|
7595
|
+
const scope = own ?? root
|
|
6718
7596
|
if (typeof scope.querySelectorAll !== 'function') return []
|
|
6719
7597
|
return [...scope.querySelectorAll('[data-cite-span]')].filter(item => item.getAttribute('data-cite-span') === id)
|
|
6720
7598
|
}
|
|
@@ -6739,6 +7617,15 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6739
7617
|
const hit = citeLookup.numbers.get(number)
|
|
6740
7618
|
if (hit !== undefined) entries.push(hit)
|
|
6741
7619
|
}
|
|
7620
|
+
} else if (node.getAttribute('data-cite-items') !== null) {
|
|
7621
|
+
// 并列:data-cite-items 是「姓氏|年份」键的逗号分隔串。键里不含逗号
|
|
7622
|
+
// (authorYearKey 用 | 连接),所以直接 split 是安全的。
|
|
7623
|
+
// 🔴 不能用 surname/year 那两个属性查 —— 并列标记上它们**是空的**(整段一个标记,
|
|
7624
|
+
// 没有单一姓氏),拿空键查表必然落空,表现是"括号标出来了但悬停没内容"。
|
|
7625
|
+
for (const key of String(node.getAttribute('data-cite-items')).split(',')) {
|
|
7626
|
+
const hits = citeLookup.authors instanceof Map ? citeLookup.authors.get(key) : undefined
|
|
7627
|
+
if (Array.isArray(hits)) entries.push(...hits)
|
|
7628
|
+
}
|
|
6742
7629
|
} else {
|
|
6743
7630
|
entries = ambiguousLookup(
|
|
6744
7631
|
citeLookup.authors,
|
|
@@ -6868,10 +7755,24 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6868
7755
|
// ---- 阅读页顶栏(P6)的派生量 ----
|
|
6869
7756
|
// 「注入」按当前会话的 desired 集算 —— 与列表卡片上那个按钮同一口径,不另立概念。
|
|
6870
7757
|
const readerInjected = readerId !== '' && desired.has(readerId)
|
|
6871
|
-
//
|
|
7758
|
+
// 正文排版:每个档位六个变量(字号 / 行距 / 字体族 × 原文 / 译文)一次性下发。
|
|
7759
|
+
// 🔴 六组**一起**给:按 data-pane 分派的那几条 CSS 直接读变量,缺一个就会在切到
|
|
7760
|
+
// 那个档位时退化成 CSS 里的兜底值,看着像"改了没生效"。
|
|
7761
|
+
// 🔴 栈为空(「系统默认」档)时**不下发这个变量**。CSS 里那几条分派规则写的是
|
|
7762
|
+
// font-family:var(--reader-*-font-family),变量未定义时整条声明在计算值阶段失效,
|
|
7763
|
+
// 于是不写 font-family —— 正是让浏览器用自己那套默认字体。若下发空串,
|
|
7764
|
+
// font-family:'' 是无效值,同样失效,但语义不如"干脆不给"明确。
|
|
7765
|
+
const fontStyleOf = side => {
|
|
7766
|
+
const stack = fontStackOf(side, readerType[side].family)
|
|
7767
|
+
return stack === '' ? {} : { ['--reader-' + side + '-font-family']: stack }
|
|
7768
|
+
}
|
|
6872
7769
|
const readerTypeStyle = {
|
|
6873
|
-
'--reader-font-size': `${
|
|
6874
|
-
'--reader-line-height': String(
|
|
7770
|
+
'--reader-src-font-size': `${readerType.src.size}px`,
|
|
7771
|
+
'--reader-src-line-height': String(readerType.src.height / 10),
|
|
7772
|
+
'--reader-zh-font-size': `${readerType.zh.size}px`,
|
|
7773
|
+
'--reader-zh-line-height': String(readerType.zh.height / 10),
|
|
7774
|
+
...fontStyleOf('src'),
|
|
7775
|
+
...fontStyleOf('zh'),
|
|
6875
7776
|
}
|
|
6876
7777
|
// 抽屉正文。三个页各自的文本都从**已经下发的数据**里取,不为它多打一次请求。
|
|
6877
7778
|
const drawerOutline = typeof reader?.outlineText === 'string' ? reader.outlineText : ''
|
|
@@ -6946,9 +7847,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6946
7847
|
await deleteDocuments(pickedIds)
|
|
6947
7848
|
}
|
|
6948
7849
|
const pickSelect = (label, value, options, onPick, extra) =>
|
|
6949
|
-
selectControlOf(setSelectMenu, label, value, options, onPick, extra)
|
|
7850
|
+
selectControlOf(selectMenu, setSelectMenu, label, value, options, onPick, extra)
|
|
6950
7851
|
return h('div', { 'data-dsh-paper': true },
|
|
6951
|
-
selectMenu === null ? null : renderSelectMenu(selectMenu, setSelectMenu),
|
|
6952
7852
|
// 🔴 P6:侧栏**不再显示或编辑任何设置**(用户裁定「要设置的地方都进入插件」)。
|
|
6953
7853
|
// 原来这里挂着「MinerU:已配置/未配置」—— 那是状态,但紧挨着它就该有设置入口,
|
|
6954
7854
|
// 而宿主**没有**给插件"打开设置页"的导航 API(查过 ui-settings / ui-commands /
|
|
@@ -7073,7 +7973,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7073
7973
|
: (translateLive > 0 && h('button', { className: 'paper-btn', type: 'button', disabled: busy, onClick: () => pauseAllTranslations() }, '暂停翻译')),
|
|
7074
7974
|
(translateLive > 0 || translatePaused) && h('button', { className: 'paper-btn danger', type: 'button', disabled: busy, onClick: () => cancelAllTranslations() }, '取消翻译')),
|
|
7075
7975
|
unresolved.map(job => h('article', { className: 'paper-card', key: job.id, 'data-job-kind': JOB_KINDS.parse },
|
|
7076
|
-
h('div', { className: 'paper-row' }, h('div', null, h('div', { className: 'paper-name' }, job.pdfName || job.pdfPath), h('div', { className: 'paper-meta' }, job
|
|
7976
|
+
h('div', { className: 'paper-row' }, h('div', null, h('div', { className: 'paper-name' }, job.pdfName || job.pdfPath), h('div', { className: 'paper-meta' }, jobMetaText(job))), h('span', { className: 'paper-status' }, jobKindLabel(job), ' · ', job.status)),
|
|
7077
7977
|
RETRYABLE_STATUSES.includes(job.status) && h('button', { className: 'paper-btn', type: 'button', disabled: busy, onClick: () => retry(job.id) }, '↻ 重新解析'))),
|
|
7078
7978
|
// 翻译任务卡片。角标与解析卡片共用同一套 status 文案,但按钮是另一组 ——
|
|
7079
7979
|
// 翻译在跑时能暂停/取消(远程调用有成本),停了之后能重新触发或只重试失败的那部分。
|
|
@@ -7085,7 +7985,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7085
7985
|
// 第二下又落回同一条分支,请求**从来没发出去过**。
|
|
7086
7986
|
const cancelArmed = armed === `cancel-translate:${job.documentId}`
|
|
7087
7987
|
return h('article', { className: 'paper-card', key: job.id, 'data-job-kind': JOB_KINDS.translate },
|
|
7088
|
-
h('div', { className: 'paper-row' }, h('div', null, h('div', { className: 'paper-name' }, job.pdfName || job.pdfPath), h('div', { className: 'paper-meta' }, job
|
|
7988
|
+
h('div', { className: 'paper-row' }, h('div', null, h('div', { className: 'paper-name' }, job.pdfName || job.pdfPath), h('div', { className: 'paper-meta' }, jobMetaText(job))), h('span', { className: 'paper-status' }, jobKindLabel(job), ' · ', job.status)),
|
|
7089
7989
|
actions.length === 0 ? null : h('div', { className: 'paper-actions' },
|
|
7090
7990
|
actions.includes('translate') && h('button', { className: 'paper-btn primary', type: 'button', disabled: busy, onClick: () => translateIncremental(job.documentId), 'aria-label': `翻译 ${job.pdfName || job.pdfPath}` }, '翻译'),
|
|
7091
7991
|
actions.includes('translateAll') && h('button', { className: 'paper-btn', type: 'button', disabled: busy, onClick: () => translate(job.documentId), 'aria-label': `整篇重译 ${job.pdfName || job.pdfPath}` }, '整篇重译'),
|
|
@@ -7143,6 +8043,13 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7143
8043
|
onClick: () => setDrawerOpen(!drawerOpen),
|
|
7144
8044
|
}, '☰'),
|
|
7145
8045
|
paneSegmented(),
|
|
8046
|
+
// 三个排版按钮(D195):紧跟在视图档位之后、「并排」之前(读者裁定)。
|
|
8047
|
+
// 它跟着当前档位显示值;PDF 与笔记档整体不渲染。
|
|
8048
|
+
// 🔴 按钮与弹层包在同一个 holder 里:弹层相对**整行**定位(见 typePopover),
|
|
8049
|
+
// 而不是相对某个按钮 —— 后者在 300px 侧栏里必有一端溢出。
|
|
8050
|
+
!typeControlsHidden() && h('div', { className: 'paper-type-row-holder' },
|
|
8051
|
+
typeControls(),
|
|
8052
|
+
typePopover()),
|
|
7146
8053
|
// 并排(D183):把这一篇在右栏另一格再开一份,左原文右译文对照读。
|
|
7147
8054
|
// 🔴 只在主格显示:副格再点它只会揭示已有的那格,多一个按钮不多一个能力。
|
|
7148
8055
|
paneRole === 'main' && h('button', {
|
|
@@ -7200,8 +8107,10 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7200
8107
|
readerNotice !== '' && h('div', { className: 'paper-notice', role: 'status' }, readerNotice),
|
|
7201
8108
|
isPdfPane(paneView) && readerId !== '' && h('div', { className: 'paper-pdf-controls', 'aria-label': 'PDF 阅读控制' },
|
|
7202
8109
|
h('button', { className: 'paper-btn', type: 'button', disabled: currentPage <= 1, onClick: () => changePdfPage(currentPage - 1) }, '上一页'),
|
|
7203
|
-
h('span', {}, '第 ' + currentPage + ' / ' +
|
|
7204
|
-
|
|
8110
|
+
h('span', {}, '第 ' + currentPage + ' / ' + pdfTotal + ' 页'),
|
|
8111
|
+
// 🔴 按钮保留(用户裁定):连续滚动下它不再是"换一份数据",而是把容器滚到下一页
|
|
8112
|
+
// 的页顶 —— 与滚轮共用同一个滚动位置,两种操作不可能各说一套。
|
|
8113
|
+
h('button', { className: 'paper-btn', type: 'button', disabled: currentPage >= pdfTotal, onClick: () => changePdfPage(currentPage + 1) }, '下一页'),
|
|
7205
8114
|
h('button', { className: 'paper-btn', type: 'button', 'aria-label': '缩小 PDF', disabled: pdfZoom <= 0.5, onClick: () => setPdfZoom(value => Math.max(0.5, value - 0.25)) }, '−'),
|
|
7206
8115
|
h('button', { className: 'paper-btn', type: 'button', 'aria-label': 'PDF 适合宽度', onClick: () => setPdfZoom(1) }, Math.round(pdfZoom * 100) + '%'),
|
|
7207
8116
|
h('button', { className: 'paper-btn', type: 'button', 'aria-label': '放大 PDF', disabled: pdfZoom >= 3, onClick: () => setPdfZoom(value => Math.min(3, value + 0.25)) }, '+'),
|
|
@@ -7232,7 +8141,9 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7232
8141
|
onMouseOver: onCiteOver,
|
|
7233
8142
|
onMouseOut: onCiteOut,
|
|
7234
8143
|
// 阅读位置靠这条(D163):正文自己的滚动容器才知道"视口上沿那一块"是谁。
|
|
7235
|
-
|
|
8144
|
+
// 🔴 PDF 原页档也挂(连续滚动):这一档的滚动位置就是"我在第几页",
|
|
8145
|
+
// 不挂的话滚到第 5 页而当前页还停在第 1 页,页栈窗口不跟着走,屏幕会空。
|
|
8146
|
+
onScroll: onReaderScroll,
|
|
7236
8147
|
onMouseUp: isPdfPane(paneView) ? event => {
|
|
7237
8148
|
const selection = window.getSelection?.()
|
|
7238
8149
|
const focus = selection?.focusNode
|
|
@@ -7769,8 +8680,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7769
8680
|
const [busy, setBusy] = React.useState(false)
|
|
7770
8681
|
const [error, setError] = React.useState('')
|
|
7771
8682
|
const [notice, setNotice] = React.useState('')
|
|
7772
|
-
//
|
|
7773
|
-
const [selectMenu, setSelectMenu] = React.useState(
|
|
8683
|
+
// 打开中的下拉:存它的 aria-label(见 selectControlOf)。
|
|
8684
|
+
const [selectMenu, setSelectMenu] = React.useState('')
|
|
7774
8685
|
React.useEffect(() => {
|
|
7775
8686
|
if (api === undefined) return undefined
|
|
7776
8687
|
let alive = true
|
|
@@ -7808,7 +8719,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7808
8719
|
// 分组顺序按 provider 首次出现的顺序,组内保持宿主给的顺序 —— 不动宿主的排序。
|
|
7809
8720
|
const modelGroups = groupModelsByProvider(models.models)
|
|
7810
8721
|
const pickSelect = (label, value, options, onPick, extra) =>
|
|
7811
|
-
selectControlOf(setSelectMenu, label, value, options, onPick, extra)
|
|
8722
|
+
selectControlOf(selectMenu, setSelectMenu, label, value, options, onPick, extra)
|
|
7812
8723
|
return h('div', { className: 'paper-mineru' },
|
|
7813
8724
|
h('div', { className: 'paper-mineru-title' }, '解析'),
|
|
7814
8725
|
h('label', { className: 'paper-translate-row' },
|
|
@@ -7911,7 +8822,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7911
8822
|
{ disabled: busy }),
|
|
7912
8823
|
notice === '' ? null : h('div', { className: 'paper-notice', role: 'status' }, notice),
|
|
7913
8824
|
error === '' ? null : h('div', { className: 'paper-error', role: 'alert' }, error),
|
|
7914
|
-
|
|
8825
|
+
)
|
|
7915
8826
|
}
|
|
7916
8827
|
|
|
7917
8828
|
/**
|
|
@@ -8140,126 +9051,74 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
8140
9051
|
strokeWidth: '1.6', strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true', focusable: 'false',
|
|
8141
9052
|
}, h('path', { d: CHEVRON_PATH[direction] ?? CHEVRON_PATH.down }))
|
|
8142
9053
|
|
|
9054
|
+
|
|
8143
9055
|
/**
|
|
8144
|
-
*
|
|
8145
|
-
*
|
|
8146
|
-
* 三个面板(文献库主栏 / 阅读器 / 翻译设置)共用这一份,各自只持有自己的浮层状态。
|
|
8147
|
-
*/
|
|
8148
|
-
/**
|
|
8149
|
-
* 浮层:同一时刻只有一张,点外面收起。
|
|
8150
|
-
*
|
|
8151
|
-
* 原来两处各写一套 —— 主栏下拉挂了全局 click 监听,右栏那套什么都没挂(点别处不关),
|
|
8152
|
-
* 「添加论文」菜单只认自己的 Escape。这里收成一份注册表:打开 B 先关掉 A,点浮层与触发器
|
|
8153
|
-
* 之外的地方收起来。dwell(悬停 120ms 才展开)没有做:这些触发器都是点击打开的,鼠标
|
|
8154
|
-
* 经过工具栏时不该弹出菜单。
|
|
9056
|
+
* 选项表 → Menu 的 items。同名但不同来源的条目(同一个模型挂在多个 provider 下)
|
|
9057
|
+
* 用 `type:'label'` 起分组标题,那是 Menu 自己的装饰行,不可选中。
|
|
8155
9058
|
*/
|
|
8156
|
-
const
|
|
8157
|
-
const registerPopover = close => {
|
|
8158
|
-
if (popoverRegistry.close !== null && popoverRegistry.close !== close) popoverRegistry.close()
|
|
8159
|
-
popoverRegistry.close = close
|
|
8160
|
-
}
|
|
8161
|
-
const dismissPopover = () => {
|
|
8162
|
-
const close = popoverRegistry.close
|
|
8163
|
-
popoverRegistry.close = null
|
|
8164
|
-
if (typeof close === 'function') close()
|
|
8165
|
-
}
|
|
8166
|
-
if (typeof document !== 'undefined' && typeof document.addEventListener === 'function' && popoverRegistry.listening === false) {
|
|
8167
|
-
popoverRegistry.listening = true
|
|
8168
|
-
document.addEventListener('pointerdown', event => {
|
|
8169
|
-
if (popoverRegistry.close === null) return
|
|
8170
|
-
const target = event?.target
|
|
8171
|
-
// 触发器与浮层自己:让它们的 onClick 处理(触发器是 toggle,浮层自己会关)。
|
|
8172
|
-
if (typeof target?.closest === 'function' && target.closest('.paper-select,.paper-import-control,.paper-menu,.paper-import-menu')) return
|
|
8173
|
-
dismissPopover()
|
|
8174
|
-
}, true)
|
|
8175
|
-
}
|
|
8176
|
-
const openSelect = (setMenu, event, options, value, onPick) => {
|
|
8177
|
-
event.preventDefault()
|
|
8178
|
-
event.stopPropagation()
|
|
8179
|
-
const rect = event.currentTarget?.getBoundingClientRect?.()
|
|
9059
|
+
const menuItemsOf = options => {
|
|
8180
9060
|
const items = []
|
|
8181
9061
|
let group = ''
|
|
8182
|
-
for (const option of options) {
|
|
9062
|
+
for (const [index, option] of options.entries()) {
|
|
8183
9063
|
if (option.group !== undefined && option.group !== group) {
|
|
8184
9064
|
group = option.group
|
|
8185
|
-
items.push({ label: group,
|
|
9065
|
+
items.push({ type: 'label', id: 'group:' + group, text: group })
|
|
8186
9066
|
}
|
|
8187
|
-
items.push({
|
|
8188
|
-
label: option.label,
|
|
8189
|
-
checked: String(option.value) === String(value),
|
|
8190
|
-
run: () => { if (String(option.value) !== String(value)) onPick(option.value) },
|
|
8191
|
-
})
|
|
9067
|
+
items.push({ id: 'option:' + index, label: option.label, disabled: option.disabled === true })
|
|
8192
9068
|
}
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
style: {
|
|
8247
|
-
// 首帧的近似位置(测量前的兜底);真正的摆位在 ref 里按实测宽高修正。
|
|
8248
|
-
left: Math.max(0, Math.min(menu.x, (typeof window === 'undefined' ? menu.x : window.innerWidth)
|
|
8249
|
-
- Math.max(150, (menu.minWidth ?? 0) + 16))) + 'px',
|
|
8250
|
-
top: menu.y + 'px',
|
|
8251
|
-
maxWidth: 'calc(100vw - 16px)',
|
|
8252
|
-
...(menu.minWidth ? { minWidth: Math.max(132, menu.minWidth) + 'px' } : {}),
|
|
8253
|
-
},
|
|
8254
|
-
}, (menu.items ?? []).map((item, index) => item.heading === true
|
|
8255
|
-
? h('div', { className: 'paper-menu-label', key: 'h:' + index }, item.label)
|
|
8256
|
-
: h('button', {
|
|
8257
|
-
key: item.label + ':' + index,
|
|
8258
|
-
type: 'button',
|
|
8259
|
-
className: item.checked === true ? 'active' : '',
|
|
8260
|
-
disabled: item.disabled === true,
|
|
8261
|
-
onClick: () => { setMenu(null); void item.run() },
|
|
8262
|
-
}, item.label)))
|
|
9069
|
+
return items
|
|
9070
|
+
}
|
|
9071
|
+
/**
|
|
9072
|
+
* 一个下拉,用宿主的 Menu 渲染(D198)。
|
|
9073
|
+
*
|
|
9074
|
+
* 🔴 原来是自己画的:按钮 + `openSelect` 摆位 + `renderSelectMenu` 出浮层。那套要自己
|
|
9075
|
+
* 处理视口边界、翻转方向、滚动上限、点外关闭、键盘走位,每一项都容易漏(摆位那条就漏
|
|
9076
|
+
* 过一次:十条长路径的集合列表顶穿屏幕底部,后面几项点都点不到)。宿主 `Menu` 这些都做过了,
|
|
9077
|
+
* 而且 `portal` 直接把浮层挂到 `document.body` —— 侧栏再窄也裁不到它。
|
|
9078
|
+
*
|
|
9079
|
+
* 值仍然按**渲染顺序下标**回传:`onSelect` 给的是 item id,把它映回第几个选项,
|
|
9080
|
+
* 调用方拿到的还是自己的值,不必关心列表长什么样。
|
|
9081
|
+
*
|
|
9082
|
+
* @param {string} label 无障碍名,也是测试找这个控件的把手。
|
|
9083
|
+
* @param {*} value 当前值(与选项的 value 严格按字符串比对)。
|
|
9084
|
+
* @param {Array<{value:*, label:string, group?:string, disabled?:boolean}>} options 选项表。
|
|
9085
|
+
* @param {(value:*) => void} onPick 选中回调;选中的是与当前值相同的项时不回调。
|
|
9086
|
+
* @param {object} [extra] `className`/`style`/`disabled`/`title`,与原来的用法一致。
|
|
9087
|
+
*/
|
|
9088
|
+
const selectControlOf = (open, setOpen, label, value, options, onPick, extra = {}) => {
|
|
9089
|
+
const items = menuItemsOf(options)
|
|
9090
|
+
const current = options.findIndex(option => String(option.value) === String(value))
|
|
9091
|
+
const shown = options[current]?.label ?? ''
|
|
9092
|
+
return h(Menu, {
|
|
9093
|
+
open: open === label,
|
|
9094
|
+
onClose: () => setOpen(''),
|
|
9095
|
+
items,
|
|
9096
|
+
selectedId: current < 0 ? undefined : 'option:' + current,
|
|
9097
|
+
onSelect: id => {
|
|
9098
|
+
setOpen('')
|
|
9099
|
+
const index = Number(String(id).slice('option:'.length))
|
|
9100
|
+
const option = options[index]
|
|
9101
|
+
if (option === undefined) return
|
|
9102
|
+
if (String(option.value) !== String(value)) onPick(option.value)
|
|
9103
|
+
},
|
|
9104
|
+
// 浮层挂到 body:祖先的 overflow 一律裁不到它(侧栏最窄 300px 时的老问题)。
|
|
9105
|
+
portal: true,
|
|
9106
|
+
minWidthFromAnchor: true,
|
|
9107
|
+
anchor: h('button', {
|
|
9108
|
+
className: 'paper-input paper-select' + (extra.className === undefined ? '' : ' ' + extra.className),
|
|
9109
|
+
type: 'button',
|
|
9110
|
+
'aria-label': label,
|
|
9111
|
+
'aria-haspopup': 'menu',
|
|
9112
|
+
'aria-expanded': open === label,
|
|
9113
|
+
...(extra.title === undefined ? {} : { title: extra.title }),
|
|
9114
|
+
...(extra.style === undefined ? {} : { style: extra.style }),
|
|
9115
|
+
...(extra.disabled === undefined ? {} : { disabled: extra.disabled }),
|
|
9116
|
+
onClick: () => setOpen(open === label ? '' : label),
|
|
9117
|
+
}, h('span', null, shown),
|
|
9118
|
+
h('span', { className: 'paper-select-caret', 'aria-hidden': 'true' }, chevronIcon('down'))),
|
|
9119
|
+
})
|
|
9120
|
+
}
|
|
9121
|
+
|
|
8263
9122
|
function paperIdFromAddress(address) {
|
|
8264
9123
|
return typeof address === 'string' && address.startsWith(PAPER_RESOURCE) ? address.slice(PAPER_RESOURCE.length).split(/[?#]/)[0] : ''
|
|
8265
9124
|
}
|
|
@@ -9007,7 +9866,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
9007
9866
|
const timer = setInterval(refreshQueue, 2000)
|
|
9008
9867
|
return () => clearInterval(timer)
|
|
9009
9868
|
}, [refreshQueue])
|
|
9010
|
-
// 点外面收起浮层由模块级的 popoverRegistry 统一负责(见 registerPopover)。
|
|
9011
9869
|
|
|
9012
9870
|
const items = Array.isArray(library?.items) ? library.items : []
|
|
9013
9871
|
const view = library?.library ?? {}
|
|
@@ -9612,16 +10470,77 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
9612
10470
|
{ label: entry.item?.pinned === true ? '取消置顶' : '置顶', run: () => paperAction(entry.documentId, { action: 'pin', pinned: entry.item?.pinned !== true }) },
|
|
9613
10471
|
{ label: entry.item?.trashed === true ? '从回收站恢复' : '移入回收站', run: () => paperAction(entry.documentId, { action: entry.item?.trashed === true ? 'restore' : 'trash' }) },
|
|
9614
10472
|
]
|
|
10473
|
+
/**
|
|
10474
|
+
* 右键菜单(光标处开)。
|
|
10475
|
+
*
|
|
10476
|
+
* 用宿主 Menu 的 `anchorPoint` + `portal`:坐标不来自某个元素,而是光标位置,
|
|
10477
|
+
* Menu 会把根 span 钉在那一格再让浮层按 CSS anchor 定位。`contextual` 负责
|
|
10478
|
+
* 「右键不关闭、按行对齐分隔线」这些右键菜单才有的行为。
|
|
10479
|
+
*/
|
|
9615
10480
|
const openMenuAt = (event, menuItems) => {
|
|
9616
10481
|
event.preventDefault()
|
|
9617
10482
|
event.stopPropagation()
|
|
9618
10483
|
setMenu({ x: event.clientX, y: event.clientY, items: menuItems })
|
|
9619
10484
|
}
|
|
10485
|
+
const contextMenu = () => menu === null ? null : h(Menu, {
|
|
10486
|
+
open: true,
|
|
10487
|
+
onClose: () => setMenu(null),
|
|
10488
|
+
contextual: true,
|
|
10489
|
+
portal: true,
|
|
10490
|
+
autoFocus: true,
|
|
10491
|
+
anchorPoint: { x: menu.x, y: menu.y },
|
|
10492
|
+
anchor: null,
|
|
10493
|
+
items: menu.items.map((item, index) => item.heading === true
|
|
10494
|
+
? { type: 'label', id: 'label:' + index, text: item.label }
|
|
10495
|
+
: { id: 'item:' + index, label: item.label, disabled: item.disabled === true }),
|
|
10496
|
+
onSelect: id => {
|
|
10497
|
+
const item = menu.items[Number(String(id).slice('item:'.length))]
|
|
10498
|
+
setMenu(null)
|
|
10499
|
+
if (item !== undefined) void item.run()
|
|
10500
|
+
},
|
|
10501
|
+
})
|
|
9620
10502
|
|
|
9621
|
-
//
|
|
10503
|
+
// 下拉实现是模块级的(selectControlOf),这里只绑上本面板「哪一张开着」的状态。
|
|
10504
|
+
const [openSelect, setOpenSelect] = React.useState('')
|
|
9622
10505
|
const selectControl = (label, value, options, onPick, extra) =>
|
|
9623
|
-
selectControlOf(
|
|
10506
|
+
selectControlOf(openSelect, setOpenSelect, label, value, options, onPick, extra)
|
|
9624
10507
|
|
|
10508
|
+
/**
|
|
10509
|
+
* 「添加论文」菜单。
|
|
10510
|
+
*
|
|
10511
|
+
* 🔴 目标集合在**打开的那一刻**捕获(`importCollection`):用户很可能是先点开这个菜单、
|
|
10512
|
+
* 再换分类、然后才点「浏览文件」,那时 pick 已经变了,而"添加到哪儿"要按点开时看到的算。
|
|
10513
|
+
* 这条行为原来就有,换 Menu 之后不变。
|
|
10514
|
+
*/
|
|
10515
|
+
const addMenu = () => h(Menu, {
|
|
10516
|
+
open: addOpen,
|
|
10517
|
+
onClose: () => setAddOpen(false),
|
|
10518
|
+
portal: true,
|
|
10519
|
+
autoFocus: true,
|
|
10520
|
+
minWidthFromAnchor: true,
|
|
10521
|
+
items: [
|
|
10522
|
+
{ id: 'browse', label: '浏览文件' },
|
|
10523
|
+
{ id: 'folder', label: '打开文件夹' },
|
|
10524
|
+
{ id: 'bib', label: '导入书目文件' },
|
|
10525
|
+
{ type: 'separator', id: 'sep' },
|
|
10526
|
+
{ id: 'cancel', label: '取消' },
|
|
10527
|
+
],
|
|
10528
|
+
onSelect: id => {
|
|
10529
|
+
if (id === 'cancel') { setAddOpen(false); return }
|
|
10530
|
+
if (id === 'browse') { void addFromPicker(); return }
|
|
10531
|
+
if (id === 'folder') { void scanFolder(); return }
|
|
10532
|
+
setAddOpen(false)
|
|
10533
|
+
setBibliographyDialog({ mode: 'import', collectionId: pick.kind === 'collection' ? pick.name : undefined })
|
|
10534
|
+
},
|
|
10535
|
+
anchor: h('button', {
|
|
10536
|
+
className: 'paper-btn', type: 'button', disabled: busy,
|
|
10537
|
+
'aria-expanded': addOpen, 'aria-haspopup': 'menu',
|
|
10538
|
+
onClick: () => {
|
|
10539
|
+
setImportCollection(pick.kind === 'collection' ? pick.name : null)
|
|
10540
|
+
setAddOpen(!addOpen)
|
|
10541
|
+
},
|
|
10542
|
+
}, '添加论文', h(LibraryIcon, { kind: 'add' })),
|
|
10543
|
+
})
|
|
9625
10544
|
// 图标不从这里传:分类的图标**由语义唯一决定**(selection.kind / view 名 → LibraryIcon),
|
|
9626
10545
|
// 曾经额外带一个 icon 字符串参数,那些 Unicode 字形(▤ ▱ ⌕ ⌫)与 SVG 混在同一列里,
|
|
9627
10546
|
// 字族不同、重心也不同,排下来一眼就能看出不是一套。
|
|
@@ -9799,20 +10718,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
9799
10718
|
label: mode_ === 'title' ? '标题' : mode_ === 'opened' ? '最近打开' : '最近加入' })),
|
|
9800
10719
|
value => void categoryAction({ action: 'sort', sort: value }),
|
|
9801
10720
|
{ style: { flex: '0 0 96px' } }),
|
|
9802
|
-
|
|
9803
|
-
h('button', {
|
|
9804
|
-
className: 'paper-btn', type: 'button', disabled: busy, 'aria-expanded': addOpen, 'aria-haspopup': 'menu',
|
|
9805
|
-
onClick: () => {
|
|
9806
|
-
setImportCollection(pick.kind === 'collection' ? pick.name : null)
|
|
9807
|
-
if (addOpen) setAddOpen(false)
|
|
9808
|
-
else { registerPopover(() => setAddOpen(false)); setAddOpen(true) }
|
|
9809
|
-
}
|
|
9810
|
-
}, '添加论文', h(LibraryIcon, { kind: 'add' })),
|
|
9811
|
-
addOpen ? h('div', { className: 'paper-import-menu', role: 'menu', 'aria-label': '添加论文方式', onKeyDown: event => { const { key: pressed } = event; if (pressed === 'Escape') setAddOpen(false) } },
|
|
9812
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => void addFromPicker() }, '浏览文件'),
|
|
9813
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => void scanFolder() }, '打开文件夹'),
|
|
9814
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => { setAddOpen(false); setBibliographyDialog({ mode: 'import', collectionId: pick.kind === 'collection' ? pick.name : undefined }) } }, '导入书目文件'),
|
|
9815
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => setAddOpen(false) }, '取消')) : null),
|
|
10721
|
+
addMenu(),
|
|
9816
10722
|
h('button', { className: 'paper-btn', disabled: busy || !shown.length, onClick: () => setBibliographyDialog({ mode: 'export', documentIds: picked.length ? picked : selectedId ? [selectedId] : shown.map(row => row.documentId) }) }, '导出书目'),
|
|
9817
10723
|
h('button', { className: 'paper-btn', disabled: busy, onClick: () => setBibliographyDialog({ mode: 'styles' }) }, '引用样式'),
|
|
9818
10724
|
// 一键补全书目:全库范围,只碰缺作者/年份/DOI 的论文。写入条件由服务端把关。
|
|
@@ -10322,8 +11228,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10322
11228
|
h('button', { className: 'paper-btn danger', type: 'button', disabled: busy, onClick: () => void confirmScan() }, '确认扫描'),
|
|
10323
11229
|
h('button', { className: 'paper-btn', type: 'button', onClick: () => setRisk(null) }, '取消')))
|
|
10324
11230
|
|
|
10325
|
-
const menuNode = () => renderSelectMenu(menu, setMenu)
|
|
10326
|
-
|
|
10327
11231
|
// Keep collections visible. A narrow work area puts details below the list.
|
|
10328
11232
|
// 🔴 同阅读页:opt-in 宿主的 overlay 契约,文献库自己内部滚动,不再把宿主整页顶滚(D180)。
|
|
10329
11233
|
return h('div', { className: 'paper-lib' + (narrow ? ' stacked' : '') + (selected ? ' has-selection' : ''), 'data-dsh-paper': true, 'data-conversation-composer-overlay': '', 'aria-busy': loading, ref: widthRef },
|
|
@@ -10334,7 +11238,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10334
11238
|
bibliographyDialog ? h(BibliographyDialog, { ...bibliographyDialog, onClose: () => setBibliographyDialog(null), onChanged: load }) : null,
|
|
10335
11239
|
searchDraft ? searchDialog() : null,
|
|
10336
11240
|
h('datalist', { id: 'paper-existing-tags' }, allTags.map(tag => h('option', { key: tag, value: tag }))),
|
|
10337
|
-
|
|
11241
|
+
contextMenu())
|
|
10338
11242
|
}
|
|
10339
11243
|
|
|
10340
11244
|
function apply(ctx) {
|
|
@@ -10586,14 +11490,13 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10586
11490
|
// 任务类别的判据(与宿主侧 jobKindOf 同义),供 test/queue.test.js 直接断言。
|
|
10587
11491
|
exports.jobKindOf = jobKindOf
|
|
10588
11492
|
exports.jobKindLabel = jobKindLabel
|
|
11493
|
+
// 卡片副标题(含任务编号),供 test/queue.test.js 直接断言。
|
|
11494
|
+
exports.jobMetaText = jobMetaText
|
|
10589
11495
|
exports.translationActions = translationActions
|
|
10590
11496
|
exports.scanReport = scanReport
|
|
10591
11497
|
// 「浏览文件」的回执文案(D182),test/add-report.test.js 直接断言。
|
|
10592
11498
|
exports.addReport = addReport
|
|
10593
11499
|
// 滑动多选与批量动作的纯函数,供 test/batch-ui.test.js 直接断言。
|
|
10594
|
-
// 浮层注册表(唯一打开 + 点外收起):测试直接驱动它,不必挂组件。
|
|
10595
|
-
exports.registerPopover = registerPopover
|
|
10596
|
-
exports.dismissPopover = dismissPopover
|
|
10597
11500
|
exports.rangeIds = rangeIds
|
|
10598
11501
|
exports.unionIds = unionIds
|
|
10599
11502
|
exports.toggleId = toggleId
|
|
@@ -10612,6 +11515,16 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10612
11515
|
exports.readingCursorOf = readingCursorOf
|
|
10613
11516
|
exports.readerResumeOf = readerResumeOf
|
|
10614
11517
|
exports.progressOf = progressOf
|
|
11518
|
+
// PDF 原页页栈(连续滚动):页身份键 / 挂载窗口 / 宽高比 / 滚动位置→页码。
|
|
11519
|
+
// 四个都是纯函数,测试直接喂数据断言,不经 DOM。
|
|
11520
|
+
exports.pdfStackKey = pdfStackKey
|
|
11521
|
+
exports.pdfPageWindow = pdfPageWindow
|
|
11522
|
+
exports.pdfPageAspectOf = pdfPageAspectOf
|
|
11523
|
+
exports.pdfPageAt = pdfPageAt
|
|
11524
|
+
// 字形宽度缓存(连续滚动的性能关键):逐字符对齐每页要量一万六千次,去重后省 88%。
|
|
11525
|
+
exports.glyphWidthOf = glyphWidthOf
|
|
11526
|
+
exports.glyphWidthCache = glyphWidthCache
|
|
11527
|
+
exports.GLYPH_CACHE_LIMIT = GLYPH_CACHE_LIMIT
|
|
10615
11528
|
// 划线与笔记(T19)的纯函数:分组只认 exact,面板不筛 anchor。
|
|
10616
11529
|
exports.markGroups = markGroups
|
|
10617
11530
|
exports.noteRows = noteRows
|
|
@@ -10667,8 +11580,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10667
11580
|
exports.progressText = progressText
|
|
10668
11581
|
exports.rowMetaText = rowMetaText
|
|
10669
11582
|
exports.LIBRARY_BUCKETS = LIBRARY_BUCKETS
|
|
10670
|
-
// 浮层摆位单独导出:它靠 ref 回调在挂载后测量,React 替身不跑 ref,只有直接调用才测得到。
|
|
10671
|
-
exports.placeSelectMenu = placeSelectMenu
|
|
10672
11583
|
exports.outlineEntries = outlineEntries
|
|
10673
11584
|
exports.markScrollTarget = markScrollTarget
|
|
10674
11585
|
// 全局文献库(T21)的纯函数:分组与排序,供 test/library-view.test.js 直接断言。
|
|
@@ -10728,6 +11639,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10728
11639
|
exports.pageImageUrl = pageImageUrl
|
|
10729
11640
|
// D150:行内 HTML 的显示改写。纯函数,单测直接喂真实论文里的那两行。
|
|
10730
11641
|
exports.displayInlineHtml = displayInlineHtml
|
|
11642
|
+
// 图注里的行内公式切分(纯文本块也要让 `$…$` 过 KaTeX):纯函数,单测直接喂真实图注。
|
|
11643
|
+
exports.captionPieces = captionPieces
|
|
10731
11644
|
return module.exports
|
|
10732
11645
|
},
|
|
10733
11646
|
})
|