@ggboy123/dsh-paper-reader 1.11.0 → 1.12.1
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 +27 -33
- package/dist/translate.js +10 -2
- package/lib/client.js +54 -8
- package/package.json +1 -1
- package/reader/index.html +283 -42
package/README.md
CHANGED
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
**English**: [README_EN.md](README_EN.md)
|
|
9
9
|
|
|
10
|
-
[DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness) 插件:**论文伴读工作台** —— 文献库 + PDF 阅读器 + AI 伴读,回答自带页码、点页码跳回原文。当前版本 **v1.
|
|
10
|
+
[DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness) 插件:**论文伴读工作台** —— 文献库 + PDF 阅读器 + AI 伴读,回答自带页码、点页码跳回原文。当前版本 **v1.12.1**。
|
|
11
11
|
|
|
12
12
|
> 💬 **QQ 交流群:1127244508** —— 安装/使用问题、功能建议、bug 反馈都欢迎来聊。
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## 为什么
|
|
15
15
|
|
|
16
|
-
1. **论文一多,文件和阅读进度就容易乱。**
|
|
17
|
-
2. **翻译不该打断阅读。**
|
|
18
|
-
3. **AI
|
|
16
|
+
1. **论文一多,文件和阅读进度就容易乱。** 按专题整理论文,每篇论文的 PDF、译文、笔记和学习记录收在一起;改名、移动、删除(可从回收站恢复)都有管理入口。
|
|
17
|
+
2. **翻译不该打断阅读。** 不用来回复制粘贴——中文直接生成在原 PDF 版面上:纯中文、中英对照、左右分屏、划词翻译,公式也保留。
|
|
18
|
+
3. **AI 的回答需要能核对。** 回答自带页码,点击跳回原文并高亮;可以只问当前论文,也可以把范围扩大到整个专题,减少「答得流畅却找不到出处」。
|
|
19
19
|
|
|
20
20
|

|
|
21
21
|
|
|
@@ -23,27 +23,16 @@
|
|
|
23
23
|
|
|
24
24
|

|
|
25
25
|
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- 📏 **长段落不截断 + 实时进度**:翻译由 `babeldoc-driver.py` 驱动 babeldoc —— 按输入估算输出预算(不再吃 babeldoc 写死的 2048),`finish_reason=length` 自动拆段重译;顶栏进度条实时显示「翻译段落 76%(521/798)」这样的阶段进度,端点拒绝关闭推理时自动降推理强度重试
|
|
37
|
-
- 🈯 **划词翻译(公式保留)**(v1.11.0):选中点「译」出纯译文气泡;选区含公式时用 MinerU 识别的 LaTeX 替换文本层乱码、要求模型原样保留
|
|
38
|
-
- 🖥️ **中英对照 / 分屏**(v1.11.0):并排对照页或左右分屏同步滚动,随时切换、按文献记忆
|
|
39
|
-
- 📝 **笔记**(v1.11.0):划词仍直接弹回「选中即问」气泡(与旧版一致),气泡里新增「笔记」「全局搜索」小按钮;记过的文字下方画蓝色波浪线,鼠标停上去看笔记内容、点一下改或删;笔记窗口与查找窗同一套交互(可拖动、拖边框缩放、位置记忆),批量列表按页排序、点条目跳回原文,也可在条目上直接删除(二次确认)。笔记存在 `<文献>.notes.json`(跟文献走,换浏览器不丢)
|
|
40
|
-
- ⚡ **长文档也流畅**:滚动模式只画视口附近的页、页离开视口即释放画布(其余保留等高占位,滚动条与页码始终准);原文 ↔ 中文切换只摘挂缓存好的页节点,不重新解析不重绘;切语言 / 重开论文不重传 PDF(ETag 304)。前提与已知边界见 [docs/features.md](docs/features.md)
|
|
41
|
-
- 🗂️ **文献管理**:专题/论文在文件名上原地改名,论文可跨专题移动;删除进回收站可恢复
|
|
42
|
-
- 🛰️ **OpenCode Go 端点**(v1.11.0):翻译端点供应商预设新增「OpenCode Go」(订阅后复制 API Key 即用,模型名以控制台为准);对 opencode.ai 域的请求自动带稳定 `x-opencode-session` 会话头(同一篇论文的整篇与划词共用同一 ID、跨重启稳定,ID 由本机 0600 secret 派生不含论文名),其它端点不多发任何头
|
|
43
|
-
- 🔀 **翻译模型可跟随也可覆盖**:默认直接跟随 Harness 当前模型(含账号授权,不需要复制 Key);需要专门翻译模型时,可在「设置 → 论文伴读 → 全文翻译模型」选择预设厂商、从官方链接申请 Key、自动获取模型。自定义只作用于翻译,切回跟随时配置仍保留,绝不改写 Harness 设置
|
|
44
|
-
- ➕ **可选增强**(默认关):MinerU 解析——扫描件可读、公式可点引用可检索;嵌入端点——大白话命中术语段落
|
|
45
|
-
|
|
46
|
-
各功能的前提与配置细节见 [docs/features.md](docs/features.md)。
|
|
26
|
+
## 特点
|
|
27
|
+
|
|
28
|
+
- 🔌 **零配置、不打扰**:装完即用——翻译直接跟随 Harness 当前模型与账号授权,不用申请、复制任何 Key;不改动官方界面,侧栏只多一行开关
|
|
29
|
+
- 🔒 **本地优先**:PDF、译文、笔记、学习记录都是文献文件夹里的普通文件,把 `data/` 目录拷走就都带得走;未配置第三方端点时,插件不向任何外部服务发请求(伴读对话历史与端点设置存在 dsh 一侧,不随文件夹迁移)
|
|
30
|
+
- ➕ **可选增强,默认关闭**:MinerU 解析让扫描件可读、公式可点引用可检索;嵌入端点让大白话提问也能命中术语段落——不配置就一条请求都不发
|
|
31
|
+
- ⚡ **长文档不卡**:只渲染视口附近的页,原文 ↔ 中文切换零重载,重开论文不重传 PDF
|
|
32
|
+
- 🤖 **教练式带读(可选)**:AI 制定分步计划,你读原文、作答,答好才继续,学习进度跨会话累积
|
|
33
|
+
- 🌙 **PDF 深色模式**:跟随 dsh 主题,四档强度可调(整页反色实现,图片会褪色偏色——已知代价,可一键关)
|
|
34
|
+
|
|
35
|
+
> 各功能的前提、代价与已知限制统一放在 [docs/features.md](docs/features.md);配置 MinerU、嵌入或翻译端点前,建议先读对应小节。
|
|
47
36
|
|
|
48
37
|
## 安装
|
|
49
38
|
|
|
@@ -59,13 +48,16 @@
|
|
|
59
48
|

|
|
60
49
|
|
|
61
50
|
> 需要官方桌面端 V0.2.0-rc.2 或更新版本(内置 dsh ≥0.2.0-rc.2);dsh 0.1.5 不再支持。
|
|
62
|
-
> 想逛插件市场可另装社区插件 [`dshmarket`](https://github.com/dsh-market/dsh-market),本插件已在其目录中。
|
|
63
51
|
|
|
64
|
-
|
|
52
|
+
<details>
|
|
53
|
+
<summary><b>安装排坑(都实测踩过)</b></summary>
|
|
65
54
|
|
|
66
55
|
- **升级后插件开关会回到停用**:重新打开「启用」并重启。症状有迷惑性——文献树还在但点论文没反应
|
|
67
56
|
- **添加务必带 `@latest`**:不带版本号对已装过的插件是 no-op,不会追新
|
|
68
57
|
- pnpm 供应链策略 `minimumReleaseAge` 拦新包时:等过窗口期,或把本包加进豁免清单(`~/.dsh/profiles/web/.npmrc` 的 `minimum-release-age-exclude[]`;桌面端在 `~/.dsh/profiles/desktop/pnpm-workspace.yaml` 的 `minimumReleaseAgeExclude`)
|
|
58
|
+
- 想逛插件市场,可另装社区插件 [`dshmarket`](https://github.com/dsh-market/dsh-market),本插件已在其目录中
|
|
59
|
+
|
|
60
|
+
</details>
|
|
69
61
|
|
|
70
62
|
### 开发者:命令行 dsh
|
|
71
63
|
|
|
@@ -75,17 +67,19 @@ dsh plugin --profile web add @ggboy123/dsh-paper-reader@latest # 升级也是
|
|
|
75
67
|
|
|
76
68
|
> 不要用 `github:GGboya/dsh-paper-reader` 安装 —— dist 不入库,git 安装会导致 profile 起不来。
|
|
77
69
|
|
|
78
|
-
##
|
|
70
|
+
## 快速上手
|
|
79
71
|
|
|
80
72
|
1. **进入**:侧栏底部点「📚 论文伴读」(再点还原)
|
|
81
73
|
2. **入库**:+ 新建专题 → ⬆ 上传 PDF
|
|
82
74
|
3. **读 + 问**:直接提问(回答自带页码),或选中文字弹框提问;点「第 N 页」跳回原文
|
|
83
|
-
4.
|
|
75
|
+
4. **中文版**:顶栏「中」一键生成;需要专用翻译模型时,在「设置 → 论文伴读 → 全文翻译模型」里单独配置
|
|
84
76
|
5. **管理**:行悬停点「⋯」,文件名原地改名(Enter 保存 / Esc 取消),论文可移动到其它专题,也可删除;对话头部 🕐 历史、+ 新开
|
|
85
77
|
|
|
86
|
-
##
|
|
78
|
+
## 数据与安全
|
|
87
79
|
|
|
88
|
-
-
|
|
80
|
+
- 所有数据都是本地文件:文献库默认在 `~/.dsh-paper-reader/data`(可在 profile 改);插件自身的端点凭据落盘 `$DSH_HOME/.dsh-paper-reader/`(权限 0600,界面只回掩码)
|
|
81
|
+
- 删除 = **移入回收站** `data/.trash/`(带 manifest,移回即恢复),会一并处理该文献的全部产物:`<文献>.pdf`、`.txt`、`.pages.json`、`.transcript.json`、`.mineru.md`、`.mineru.json`、`.embeddings.json`、`.study.json`、`.notes.json` 与译文变体 `<文献>-en.pdf` / `-zh.pdf` / `-dual.pdf`(含 `.tmp-*` 残留);伴读会话历史不删
|
|
82
|
+
- 有运行中会话或翻译中的文献会被前置拒绝;路径穿越(`..`、绝对路径、符号链接逃逸)一律拒绝;操作中途失败自动回滚
|
|
89
83
|
|
|
90
84
|
## 参与开发
|
|
91
85
|
|
|
@@ -96,7 +90,7 @@ dsh plugin --profile web add ./dsh-paper-reader # 从父目录执行,或用
|
|
|
96
90
|
dsh --profile web # 侧栏变为文献库树
|
|
97
91
|
```
|
|
98
92
|
|
|
99
|
-
改完 `pnpm run build` 重启 profile 即生效;`npm test` 跑全量测试(
|
|
93
|
+
改完 `pnpm run build` 重启 profile 即生效;`npm test` 跑全量测试(CI 跑 ubuntu / macOS / Windows 三平台)。架构、测试守卫与开发约定见 [AGENTS.md](AGENTS.md)。
|
|
100
94
|
|
|
101
95
|
## 贡献者
|
|
102
96
|
|
package/dist/translate.js
CHANGED
|
@@ -198,6 +198,14 @@ export async function restartTranslation(ref, dataDir, endpoint, hooks = {}, opt
|
|
|
198
198
|
}
|
|
199
199
|
/** 驱动脚本:包装 babeldoc(加结构化进度事件 + 解除单次请求的输出长度限制)。 */
|
|
200
200
|
const DRIVER_PATH = fileURLToPath(new URL('../runtime/babeldoc-driver.py', import.meta.url));
|
|
201
|
+
/** babeldoc 报「Scanned PDF detected」时附带的处理指引(issue #26):
|
|
202
|
+
* 扫描件没有文字层,babeldoc 拒绝翻译属预期行为;插件不自带 OCR,
|
|
203
|
+
* 如实告诉用户先 OCR 再来,而不是只甩一行英文错误。 */
|
|
204
|
+
function scannedHint(tail) {
|
|
205
|
+
return /scanned pdf/i.test(tail)
|
|
206
|
+
? '。这份 PDF 是扫描件(没有文字层):插件不自带 OCR,请先用 OCR 工具(如 pdfcraft、ocrmypdf)生成带文字层的版本后再翻译'
|
|
207
|
+
: '';
|
|
208
|
+
}
|
|
201
209
|
/** babeldoc 的阶段名 → 中文(进度条上给人看)。 */
|
|
202
210
|
const STAGE_LABELS = {
|
|
203
211
|
'Parse PDF and Create Intermediate Representation': '解析 PDF',
|
|
@@ -473,7 +481,7 @@ async function launch(ref, dataDir, endpoint, bin, task, options) {
|
|
|
473
481
|
if (error || code !== 0) {
|
|
474
482
|
const detail = (tail.trim() || error?.message || '').slice(-MAX_TAIL_CHARS);
|
|
475
483
|
console.error('[dsh-paper-reader] babeldoc failed:', detail);
|
|
476
|
-
setTaskBusy(ref, task, { error: `babeldoc 执行失败: ${detail || `退出码 ${code}`}` });
|
|
484
|
+
setTaskBusy(ref, task, { error: `babeldoc 执行失败: ${detail || `退出码 ${code}`}${scannedHint(tail)}` });
|
|
477
485
|
resolveDone();
|
|
478
486
|
return;
|
|
479
487
|
}
|
|
@@ -489,7 +497,7 @@ async function launch(ref, dataDir, endpoint, bin, task, options) {
|
|
|
489
497
|
}
|
|
490
498
|
if (!existsSync(zhPdfPath(ref)) && !existsSync(dualPdfPath(ref))) {
|
|
491
499
|
const why = tail.trim().split('\n').pop() ?? '';
|
|
492
|
-
setTaskBusy(ref, task, { error: `babeldoc 未产出译文 PDF${why ? `:${why}` : ''}` });
|
|
500
|
+
setTaskBusy(ref, task, { error: `babeldoc 未产出译文 PDF${why ? `:${why}` : ''}${scannedHint(tail)}` });
|
|
493
501
|
resolveDone();
|
|
494
502
|
return;
|
|
495
503
|
}
|
package/lib/client.js
CHANGED
|
@@ -190,6 +190,18 @@ window.__ModuleLoader__.load({
|
|
|
190
190
|
const h = React.createElement
|
|
191
191
|
|
|
192
192
|
const NS = 'dsh-paper-reader'
|
|
193
|
+
|
|
194
|
+
// 阅读器路由基址:由当前页面 URL 派生,不能写死 '/paper-reader'。
|
|
195
|
+
// 反向代理把 dsh web 挂到子路径时(如 fnOS 应用中心的 /app/fn-deepseek-harness),
|
|
196
|
+
// 以域名根为基准的绝对路径会打到代理根、被别的应用接管并返回 HTML ⇒
|
|
197
|
+
// fetch 的 r.json() 解析失败、文献库静默空白、上传 403。
|
|
198
|
+
// 本模块跑在宿主页面里,没有 <base> 可用,只能自己从 pathname 里截出前缀。
|
|
199
|
+
// 直连(/paper-reader/... 或根路径)时前缀为空,行为与原来一致。
|
|
200
|
+
function dprBase() {
|
|
201
|
+
const m = /^(.*\/)?paper-reader(\/|$)/.exec(location.pathname)
|
|
202
|
+
const prefix = m && m[1] ? m[1].replace(/\/$/, '') : ''
|
|
203
|
+
return prefix + '/paper-reader'
|
|
204
|
+
}
|
|
193
205
|
const zh = {
|
|
194
206
|
library: '文献库', refresh: '刷新',
|
|
195
207
|
empty: '文献库为空', hint: '新建专题或上传 PDF 开始', newTopic: '新建专题',
|
|
@@ -489,7 +501,7 @@ window.__ModuleLoader__.load({
|
|
|
489
501
|
}
|
|
490
502
|
|
|
491
503
|
async function api(path, opts) {
|
|
492
|
-
const r = await fetch('/
|
|
504
|
+
const r = await fetch(dprBase() + '/api' + path, opts)
|
|
493
505
|
if (!r.ok) {
|
|
494
506
|
const body = await r.json().catch(() => ({}))
|
|
495
507
|
// 机器可读码/下一步端点统一挂到 Error 上(见顶层 dprApiError):调用方按 code 分支
|
|
@@ -652,7 +664,7 @@ window.__ModuleLoader__.load({
|
|
|
652
664
|
postMessage `{type:'dpr:open', topic, name, page?, q?}` 让阅读器原地 openPaper。
|
|
653
665
|
阅读器载完回 `{type:'dpr:ready'}` 握手;没握手(首开/回退)或原地换失败
|
|
654
666
|
(回 `{type:'dpr:open-failed'}`)时退回「改 src 整页导航」的旧路径,保证一定切得过去。 */
|
|
655
|
-
const readerSrcOf = (c) =>
|
|
667
|
+
const readerSrcOf = (c) => `${dprBase()}/?topic=${encodeURIComponent(c.topic)}&name=${encodeURIComponent(c.name)}${c.page ? '&page=' + c.page : ''}${c.q ? '&q=' + encodeURIComponent(c.q) : ''}`
|
|
656
668
|
function sendReaderOpen(c) {
|
|
657
669
|
const win = readerIframeEl && readerIframeEl.contentWindow
|
|
658
670
|
if (!win) return false
|
|
@@ -751,6 +763,9 @@ window.__ModuleLoader__.load({
|
|
|
751
763
|
// overlay 测量的暂态),按 lastSeen 加 1500ms(=切换护栏窗口宽)迟滞,免得换位
|
|
752
764
|
// 撤钉又回钉,闪回当初修掉的整屏闪。
|
|
753
765
|
const setStyle = (el, prop, val) => { if (el.style[prop] !== val) el.style[prop] = val }
|
|
766
|
+
// macOS 桌面端判定(红绿灯避让用,见 applySwap 尾部):浏览器与 Win/Linux 桌面端
|
|
767
|
+
// 左上角没有原生窗口控件,不该有任何行为变化。
|
|
768
|
+
const macElectron = /Electron/.test(navigator.userAgent) && /^Mac/.test(navigator.platform || '')
|
|
754
769
|
let lastPdfTabAt = 0
|
|
755
770
|
const applySwap = () => {
|
|
756
771
|
const col = document.querySelector('[data-rightbar-col]')
|
|
@@ -791,6 +806,30 @@ window.__ModuleLoader__.load({
|
|
|
791
806
|
const dockLayer = parseFloat(getComputedStyle(panel).getPropertyValue('--dsh-dockkit-dock-layer')) || 10
|
|
792
807
|
setStyle(readerIframeEl, 'zIndex', frame.hasAttribute('data-rightbar-fullscreen') ? String(dockLayer + 2) : '10')
|
|
793
808
|
}
|
|
809
|
+
// macOS 桌面端红绿灯避让(issue #22 追问实测定位):换位生效 + 侧栏收起时,右栏
|
|
810
|
+
// 页签条被钉到窗口最左上(实测 left=1/top=0),原生红绿灯(≈x 0..70)直接浮在
|
|
811
|
+
// 「论文 PDF」页签文字上;宿主自己的左上浮动控件(leadingSeat:收起侧栏的开关等,
|
|
812
|
+
// 实测 x 88..152)已经为红绿灯让位,但没料到页签条会被换位到左缘。
|
|
813
|
+
// 这里量页签条实际位置:贴近窗口左上才补 padding-left 腾出「红绿灯 + 浮动控件」
|
|
814
|
+
// 区,让位目标取 leadingSeat 右缘(与宿主自己的避让对齐),找不到该元素回落 76px;
|
|
815
|
+
// 侧栏展开(页签条远离左缘)或撤换位时自动清掉。纯量位置、不猜侧栏状态,
|
|
816
|
+
// 宿主以后改布局也自愈。
|
|
817
|
+
if (macElectron) {
|
|
818
|
+
try {
|
|
819
|
+
const hdr = col.querySelector('[class*="tabHostHeader"]')
|
|
820
|
+
if (hdr) {
|
|
821
|
+
let clear = 76
|
|
822
|
+
const seat = document.querySelector('[class*="leadingSeat"]')
|
|
823
|
+
if (seat) {
|
|
824
|
+
const sr = seat.getBoundingClientRect()
|
|
825
|
+
if (sr.top < 40 && sr.left < 120 && sr.width > 0) clear = Math.max(clear, Math.ceil(sr.right) + 6)
|
|
826
|
+
}
|
|
827
|
+
const hr = hdr.getBoundingClientRect()
|
|
828
|
+
const pad = eff && hr.top < 40 && hr.left < clear ? String(clear - Math.floor(hr.left)) + 'px' : ''
|
|
829
|
+
setStyle(hdr, 'paddingLeft', pad)
|
|
830
|
+
}
|
|
831
|
+
} catch { /* 宿主结构变了就维持现状(页签被红绿灯盖),不影响换位本身 */ }
|
|
832
|
+
}
|
|
794
833
|
}
|
|
795
834
|
let lastGood = false
|
|
796
835
|
const tick = () => {
|
|
@@ -1647,7 +1686,7 @@ window.__ModuleLoader__.load({
|
|
|
1647
1686
|
const file = e.target.files?.[0]
|
|
1648
1687
|
e.target.value = ''
|
|
1649
1688
|
if (!file) return
|
|
1650
|
-
await fetch('/
|
|
1689
|
+
await fetch(dprBase() + '/api/library/upload', {
|
|
1651
1690
|
method: 'POST',
|
|
1652
1691
|
// header 值只允许 ISO-8859-1:中文专题名/文件名必须先编码,否则 fetch 在发请求前就抛错
|
|
1653
1692
|
headers: { 'x-dpr-topic': encodeURIComponent(uploadTopic.current), 'x-dpr-name': encodeURIComponent(file.name), 'content-type': 'application/pdf' },
|
|
@@ -2139,7 +2178,7 @@ window.__ModuleLoader__.load({
|
|
|
2139
2178
|
})
|
|
2140
2179
|
}).catch((e) => setMsg({ ok: false, text: String(e.message || e) }))
|
|
2141
2180
|
}, [props.path])
|
|
2142
|
-
useEffect(load, [load])
|
|
2181
|
+
useEffect(() => { void load() }, [load])
|
|
2143
2182
|
const sourceText = !cfg ? '' : { file: t('setSourceFile'), profile: t('setSourceProfile'), env: t('setSourceEnv'), none: t('setSourceNone') }[cfg.source] || ''
|
|
2144
2183
|
const save = async () => {
|
|
2145
2184
|
setBusy(true); setMsg(null)
|
|
@@ -2206,7 +2245,7 @@ window.__ModuleLoader__.load({
|
|
|
2206
2245
|
function TranslateProviderIcon({ provider, size = 22 }) {
|
|
2207
2246
|
if (!provider.icon) return provider.mark || '+'
|
|
2208
2247
|
return h('img', {
|
|
2209
|
-
src: '/
|
|
2248
|
+
src: dprBase() + '/vendor/' + provider.icon, alt: '', 'aria-hidden': 'true',
|
|
2210
2249
|
'data-dpr-provider-icon': provider.id,
|
|
2211
2250
|
style: { width: size, height: size, objectFit: 'contain', display: 'block', background: '#fff', borderRadius: 4 },
|
|
2212
2251
|
})
|
|
@@ -2247,7 +2286,7 @@ window.__ModuleLoader__.load({
|
|
|
2247
2286
|
setDeleteArmed(false)
|
|
2248
2287
|
}).catch((e) => setMsg({ ok: false, text: String(e.message || e) }))
|
|
2249
2288
|
}, [])
|
|
2250
|
-
useEffect(load, [load])
|
|
2289
|
+
useEffect(() => { void load() }, [load])
|
|
2251
2290
|
|
|
2252
2291
|
const chooseProvider = (id) => {
|
|
2253
2292
|
modelRequest.current += 1
|
|
@@ -2525,7 +2564,7 @@ window.__ModuleLoader__.load({
|
|
|
2525
2564
|
api('/theme/config').then((d) => { setCfg(d); writeThemeMirror(d) })
|
|
2526
2565
|
.catch((e) => setMsg({ ok: false, text: String(e.message || e) }))
|
|
2527
2566
|
}, [])
|
|
2528
|
-
useEffect(load, [load])
|
|
2567
|
+
useEffect(() => { void load() }, [load])
|
|
2529
2568
|
const save = async (patch) => {
|
|
2530
2569
|
setBusy(true); setMsg(null)
|
|
2531
2570
|
try {
|
|
@@ -2574,6 +2613,13 @@ window.__ModuleLoader__.load({
|
|
|
2574
2613
|
)
|
|
2575
2614
|
}
|
|
2576
2615
|
|
|
2616
|
+
/* 卸载契约(设置分区切走即卸载):本面板里所有 `useEffect` 的回调必须返回 **undefined 或清理函数**。
|
|
2617
|
+
React 会把 effect 的返回值当清理函数保存,切走分区卸载卡片时直接调用它。
|
|
2618
|
+
TranslateSettingsCard 的 load() 返回 api(...) 的 Promise;写成 `useEffect(load, [load])`
|
|
2619
|
+
等于把 Promise 存成 destroy,卸载时 React 调用它 → `TypeError: … is not a function`。
|
|
2620
|
+
提交阶段的错误越过本卡片的 SlotErrorBoundary,冒到 `sidebar.settings` 外壳,
|
|
2621
|
+
外壳按 single 槽 abdicate ⇒ 设置弹窗自动关闭 + 左下角账号/设置入口消失(刷新才恢复)。
|
|
2622
|
+
其余 load() 目前是块体(返回 undefined),仍统一包一层,避免以后加 `return` 时再踩。 */
|
|
2577
2623
|
function SettingsPanel() {
|
|
2578
2624
|
return h('div', { style: { maxWidth: '560px' }, 'data-dsh-plugin': 'dsh-paper-reader', 'data-dsh-surface': 'settings-modal' },
|
|
2579
2625
|
h(EndpointCard, {
|
|
@@ -2612,7 +2658,7 @@ window.__ModuleLoader__.load({
|
|
|
2612
2658
|
})
|
|
2613
2659
|
}).catch((e) => setMsg({ ok: false, text: String(e.message || e) }))
|
|
2614
2660
|
}, [])
|
|
2615
|
-
useEffect(load, [load])
|
|
2661
|
+
useEffect(() => { void load() }, [load])
|
|
2616
2662
|
const sourceText = !cfg ? '' : { file: t('setSourceFile'), profile: t('setSourceProfile'), env: t('setSourceEnv'), none: t('setSourceNone') }[cfg.source] || ''
|
|
2617
2663
|
const payload = () => ({
|
|
2618
2664
|
mode: form.mode,
|
package/package.json
CHANGED
package/reader/index.html
CHANGED
|
@@ -55,7 +55,9 @@
|
|
|
55
55
|
.tbtn svg.spin { transform-origin: center; animation: dpr-spin 1s linear infinite; }
|
|
56
56
|
@keyframes dpr-spin { to { transform: rotate(360deg); } }
|
|
57
57
|
@media (prefers-reduced-motion: reduce) { .tbtn svg.spin { animation-duration: 2.4s; } }
|
|
58
|
-
#zoom-label { flex: none; min-width: 44px; text-align: center; color: var(--text-2); }
|
|
58
|
+
#zoom-label { flex: none; min-width: 44px; text-align: center; color: var(--text-2); cursor: pointer; border-radius: 5px; }
|
|
59
|
+
#zoom-label:hover { color: var(--text); background: var(--bg); }
|
|
60
|
+
#zoom-label input { border-radius: 5px; }
|
|
59
61
|
#bar .spacer { flex: 1; }
|
|
60
62
|
/* min-width:0 —— flex 项默认 min-width:auto 会拒绝收缩,空间不够时转而去挤按钮;
|
|
61
63
|
让标题自己截断(已有 ellipsis),按钮才能保持原样 */
|
|
@@ -222,14 +224,13 @@
|
|
|
222
224
|
.textLayer span.find-hit.cur { background: rgba(255,146,0,.55); }
|
|
223
225
|
|
|
224
226
|
/* ---------- 笔记(划词标注 + 可移动笔记窗口) ----------
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
issue #22-7 定稿(维护者拍板):不用波浪线(长笔记连成密集「斑马纹」),也不加 ✎ 小标记
|
|
228
|
+
(放行尾/页边都会压到论文内容)——所有笔记统一一个**蓝色虚线圆角框**圈住原文范围。
|
|
229
|
+
框本身 pointer-events:none 不挡正文;悬停/点击的命中区是**虚线边框本体**(±5px 环带,
|
|
230
|
+
见 noteFindAt),框内部阅读零干扰。跳转定位时框内闪一层浅蓝。 */
|
|
228
231
|
.noteLayer { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
|
|
229
|
-
.note-under { position: absolute; border-radius:
|
|
230
|
-
|
|
231
|
-
background-repeat: repeat-x; background-position: 0 100%; background-size: 9px 4px; }
|
|
232
|
-
.note-under.flash { background-color: rgba(47,107,255,.20); }
|
|
232
|
+
.note-under { position: absolute; pointer-events: none; border: 2px dashed rgba(47,107,255,.8); border-radius: 6px; background-color: rgba(47,107,255,.04); }
|
|
233
|
+
.note-under.flash { background-color: rgba(47,107,255,.12); }
|
|
233
234
|
#note-tip { position: fixed; z-index: 58; display: none; max-width: 320px; background: var(--panel);
|
|
234
235
|
border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 22px rgba(0,0,0,.18);
|
|
235
236
|
padding: 8px 10px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; pointer-events: none; }
|
|
@@ -281,18 +282,21 @@
|
|
|
281
282
|
|
|
282
283
|
/* ---------- 选中即问浮层 ---------- */
|
|
283
284
|
#ask-scope-row { display: flex; align-items: center; gap: 6px; margin: 2px 0 4px; font-size: 12px; color: var(--text-2); }
|
|
285
|
+
#ask-scope-label { flex: none; white-space: nowrap; }
|
|
284
286
|
#ask-scope-row select { font: inherit; font-size: 12px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 5px; background: var(--panel); color: var(--text); max-width: 60%; }
|
|
285
|
-
#ask-scope-hint { opacity: .75; font-size: 11px; }
|
|
287
|
+
#ask-scope-hint { flex: 1; min-width: 0; opacity: .75; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
286
288
|
#cfg-pop hr { border: none; border-top: 1px solid var(--border); margin: 12px 0 8px; }
|
|
287
289
|
#cfg-theme-hint { font-size: 11.5px; color: var(--text-2); line-height: 1.5; margin-top: 4px; }
|
|
288
290
|
#ask-scope-row { display: flex; align-items: center; gap: 6px; margin: 2px 0 4px; font-size: 12px; color: var(--text-2); }
|
|
291
|
+
#ask-scope-label { flex: none; white-space: nowrap; }
|
|
289
292
|
#ask-scope-row select { font: inherit; font-size: 12px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 5px; background: var(--panel); color: var(--text); max-width: 60%; }
|
|
290
|
-
#ask-scope-hint { opacity: .75; font-size: 11px; }
|
|
293
|
+
#ask-scope-hint { flex: 1; min-width: 0; opacity: .75; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
291
294
|
#cfg-pop hr { border: none; border-top: 1px solid var(--border); margin: 12px 0 8px; }
|
|
292
295
|
#cfg-theme-hint { font-size: 11.5px; color: var(--text-2); line-height: 1.5; margin-top: 4px; }
|
|
293
296
|
#ask-pop { position: fixed; z-index: 50; display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.16); padding: 10px; width: 320px; }
|
|
294
297
|
#ask-quote { font-size: 12px; color: var(--text-2); max-height: 64px; overflow: hidden; margin-bottom: 8px; border-left: 3px solid var(--accent-soft); padding-left: 8px; }
|
|
295
|
-
#ask-input { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font: inherit; resize: none; }
|
|
298
|
+
#ask-input { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font: inherit; resize: none; }
|
|
299
|
+
#ask-input:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
|
|
296
300
|
#ask-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
|
|
297
301
|
#ask-send { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 5px 14px; cursor: pointer; }
|
|
298
302
|
#ask-send:disabled { opacity: .5; cursor: default; }
|
|
@@ -311,6 +315,13 @@
|
|
|
311
315
|
#tr-body { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
|
|
312
316
|
#tr-note { font-size: 12px; color: var(--text-2); margin-top: 6px; line-height: 1.5; }
|
|
313
317
|
#tr-note:empty { display: none; }
|
|
318
|
+
/* 气泡拖动把手(issue #22-4):顶部居中的胶囊条(sheet-handle 样式),hover 亮起提示可拖;两处气泡共用 */
|
|
319
|
+
.pop-grip { display: flex; align-items: center; justify-content: center; height: 14px; margin: -5px -2px 3px;
|
|
320
|
+
cursor: grab; user-select: none; }
|
|
321
|
+
.pop-grip::after { content: ''; width: 26px; height: 4px; border-radius: 2px; background: var(--text-2); opacity: .4; }
|
|
322
|
+
.pop-grip:hover::after { opacity: .85; }
|
|
323
|
+
.pop-grip:active { cursor: grabbing; }
|
|
324
|
+
.pop-grip:active::after { opacity: 1; }
|
|
314
325
|
/* 公式段:KaTeX 渲染进我们新建的元素(.tr-math / .tr-math-block);渲染失败时该段落回原始 LaTeX
|
|
315
326
|
文本并加 .tr-math-fallback(可读可复制,绝不留白)。 */
|
|
316
327
|
#tr-body .tr-math-block { margin: 6px 0; overflow-x: auto; }
|
|
@@ -320,18 +331,18 @@
|
|
|
320
331
|
/* ---------- 全文翻译模型设置:与 dsh 设置页同一套跟随 / 覆盖语义 ---------- */
|
|
321
332
|
#cfg-pop, #theme-pop, #generate-pop { position: fixed; z-index: 60; display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.16); padding: 10px; width: min(320px, calc(100vw - 32px)); }
|
|
322
333
|
#cfg-pop { width: min(640px, calc(100vw - 28px)); max-height: calc(100vh - 28px); overflow-y: auto; padding: 0; }
|
|
323
|
-
#cfg-pop h3, #theme-pop h3 { margin: 0; font-size: 13px; }
|
|
334
|
+
#cfg-pop h3, #theme-pop h3, #generate-pop h3 { margin: 0 0 6px; font-size: 13px; }
|
|
324
335
|
#cfg-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 16px 12px; border-bottom: 1px solid var(--border); }
|
|
325
336
|
#cfg-cancel { border: 0; background: transparent; color: var(--text-2); cursor: pointer; padding: 2px 5px; border-radius: 4px; }
|
|
326
337
|
#cfg-cancel:hover { background: var(--bg); color: var(--text); }
|
|
327
338
|
#cfg-hint { font-size: 12px; color: var(--text-2); line-height: 1.55; margin: 10px 16px 12px; }
|
|
328
|
-
#cfg-pop label, #theme-pop label { display: block; font-size: 12px; color: var(--text-2); margin: 8px 0 4px; }
|
|
339
|
+
#cfg-pop label, #theme-pop label, #generate-pop label { display: block; font-size: 12px; color: var(--text-2); margin: 8px 0 4px; }
|
|
329
340
|
#cfg-pop input[type="checkbox"], #theme-pop input[type="checkbox"] { width: auto; }
|
|
330
341
|
#theme-pop h3 { display: flex; align-items: center; justify-content: space-between; }
|
|
331
342
|
#theme-close { all: unset; cursor: pointer; font-size: 12px; color: var(--text-2); padding: 2px 6px; border-radius: 4px; }
|
|
332
343
|
#theme-close:hover { background: var(--bg); color: var(--text); }
|
|
333
|
-
#cfg-pop input, #cfg-pop select, #theme-pop input, #theme-pop select { box-sizing: border-box; width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font: inherit; background: var(--panel); color: var(--text); }
|
|
334
|
-
#cfg-pop input:focus, #cfg-pop select:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
|
|
344
|
+
#cfg-pop input, #cfg-pop select, #theme-pop input, #theme-pop select, #generate-pop select { box-sizing: border-box; width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font: inherit; background: var(--panel); color: var(--text); }
|
|
345
|
+
#cfg-pop input:focus, #cfg-pop select:focus, #generate-pop select:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
|
|
335
346
|
.cfg-modes { display: flex; gap: 9px; padding: 0 16px 14px; }
|
|
336
347
|
.cfg-mode, .cfg-provider, .cfg-model { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); cursor: pointer; text-align: left; }
|
|
337
348
|
.cfg-mode { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 9px; padding: 11px; border-radius: 8px; }
|
|
@@ -380,6 +391,7 @@
|
|
|
380
391
|
.cfg-empty { padding: 14px; border: 1px dashed var(--border); border-radius: 7px; color: var(--text-2); font-size: 11px; line-height: 1.6; text-align: center; }
|
|
381
392
|
#cfg-scope { padding: 0 16px 13px; color: var(--text-2); font-size: 11px; line-height: 1.5; text-align: center; }
|
|
382
393
|
#generate-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
|
|
394
|
+
#generate-hint { font-size: 12px; color: var(--text-2); line-height: 1.55; }
|
|
383
395
|
@media (max-width: 520px) { #cfg-provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cfg-modes { flex-direction: column; } }
|
|
384
396
|
|
|
385
397
|
#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: rgba(30,30,30,.92); color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 13px; display: none; z-index: 99; max-width: 70%; }
|
|
@@ -428,7 +440,7 @@
|
|
|
428
440
|
<button id="zh-regen" class="tbtn tucked" title="重新翻译:删除现有译文,用当前端点重跑(换模型后用)" style="display:none" data-icon="regen"></button>
|
|
429
441
|
<span class="bar-sep"></span>
|
|
430
442
|
<button id="zoom-out" class="tbtn" title="缩小" data-icon="minus"></button>
|
|
431
|
-
<span id="zoom-label">100%</span>
|
|
443
|
+
<span id="zoom-label" title="点击输入精确缩放百分比(40–300)">100%</span>
|
|
432
444
|
<button id="zoom-in" class="tbtn" title="放大" data-icon="plus"></button>
|
|
433
445
|
<button id="zoom-fit" class="tbtn">适宽</button>
|
|
434
446
|
<button id="mode-toggle" class="tbtn" title="切换 滚动/翻页模式" style="display:none" data-icon="paged"></button>
|
|
@@ -531,6 +543,7 @@
|
|
|
531
543
|
</div>
|
|
532
544
|
|
|
533
545
|
<div id="ask-pop">
|
|
546
|
+
<div class="pop-grip" id="ask-grip" title="拖动移动气泡"></div>
|
|
534
547
|
<div id="ask-quote"></div>
|
|
535
548
|
<!-- 提问范围(方案 §B3.3 入口 1):默认「本篇」=改造前行为;「所在专题」会带上整棵子专题的目录内容 -->
|
|
536
549
|
<div id="ask-scope-row">
|
|
@@ -554,6 +567,7 @@
|
|
|
554
567
|
|
|
555
568
|
<!-- 划词译文气泡:只有译文 + 状态行 + 一行诚实提示,**零按钮**(用户明确不要插入会话/复制) -->
|
|
556
569
|
<div id="tr-pop">
|
|
570
|
+
<div class="pop-grip" id="tr-grip" title="拖动移动气泡"></div>
|
|
557
571
|
<div id="tr-status"></div>
|
|
558
572
|
<div id="tr-body"></div>
|
|
559
573
|
<div id="tr-note"></div>
|
|
@@ -664,6 +678,39 @@
|
|
|
664
678
|
|
|
665
679
|
<script>
|
|
666
680
|
'use strict';
|
|
681
|
+
/* 资源与接口基址:/paper-reader 挂在什么路径下由部署环境决定,不能写死到域名根。
|
|
682
|
+
反向代理把 dsh web 挂到子路径时(如 fnOS 应用中心的 /app/fn-deepseek-harness),
|
|
683
|
+
以域名根为基准的绝对路径会打到代理根、被别的应用接管并返回 HTML,后果有二:
|
|
684
|
+
· 接口请求拿到 HTML,r.json() 解析失败 ⇒ 文献库静默空白、上传 403
|
|
685
|
+
· pdf.js 的 ES 模块拿不到 JS ⇒ 浏览器按 MIME 拒绝,报
|
|
686
|
+
Failed to fetch dynamically imported module
|
|
687
|
+
后者尤其隐蔽:反代注入的 fetch/XHR/属性改写钩子**改不到**原生模块动态 import
|
|
688
|
+
与 Worker 的 workerSrc(它们不经过 fetch),只能在这里自己算对。
|
|
689
|
+
|
|
690
|
+
PR_ASSET_BASE 由当前页面 URL 派生,直连与子路径反代两种部署都对。
|
|
691
|
+
<link>/<script> 保持绝对路径不动:它们在解析期就被反代改写过,
|
|
692
|
+
且 test/reader-script.mjs 约定本页只有一个 <script> 块,基址只能定义在这里。
|
|
693
|
+
|
|
694
|
+
降级链(与文件其余部分同风格:绝不因环境缺失抛错):
|
|
695
|
+
① location.href 可解析 → 由它派生(浏览器与 jsdom 都是这条)
|
|
696
|
+
② 否则退回 '/paper-reader/' 拼绝对 URL(老 vm 测试沙箱只给了 location.search)
|
|
697
|
+
绝不假设 URL 全局存在——顶层抛 ReferenceError 会让整页脚本停摆,比路径错更糟。 */
|
|
698
|
+
const PR_ASSET_BASE = (() => {
|
|
699
|
+
const fallback = '/paper-reader/';
|
|
700
|
+
try {
|
|
701
|
+
const href = typeof location !== 'undefined' && location.href;
|
|
702
|
+
if (typeof href !== 'string' || !href) return fallback;
|
|
703
|
+
const u = new URL(href); // ② 无 URL 时进 catch
|
|
704
|
+
if (!u.pathname.endsWith('/')) u.pathname += '/'; // 兼容 /paper-reader 无尾斜杠
|
|
705
|
+
u.search = '';
|
|
706
|
+
u.hash = '';
|
|
707
|
+
return u.href;
|
|
708
|
+
} catch (e) {
|
|
709
|
+
return fallback;
|
|
710
|
+
}
|
|
711
|
+
})();
|
|
712
|
+
const PR_API_BASE = PR_ASSET_BASE + 'api';
|
|
713
|
+
|
|
667
714
|
/* 深色首帧判定(方案 §A2.2 的四级降级链 + §A2.5「朝亮色回退」)——必须在首帧**之前**同步完成,
|
|
668
715
|
否则会出现「先白后黑」的白闪(Firefox/pdf.js #18680 同款公开案例)。放在模块脚本最前面:
|
|
669
716
|
解析期同步执行、早于首帧,且**不新增第二个 <script> 块**(test/reader-script.mjs 的提取约定)。
|
|
@@ -721,7 +768,7 @@ const iconHtml = (name) => `<svg class="ic${name === 'spin' ? ' spin' : ''}" vie
|
|
|
721
768
|
// 静态按钮按 data-icon 注入一次;动态按钮(翻译/重翻/模式切换)在状态变化时用同一函数换图标
|
|
722
769
|
// #pager:翻页条挪到阅读区底部(#main 内)后也要扫到,否则上一页/下一页图标空白
|
|
723
770
|
document.querySelectorAll('#bar [data-icon], #pager [data-icon], #find-window [data-icon], #note-window [data-icon]').forEach((b) => b.insertAdjacentHTML('afterbegin', iconHtml(b.dataset.icon)));
|
|
724
|
-
const api = (p, opts) => fetch(
|
|
771
|
+
const api = (p, opts) => fetch(PR_API_BASE + p, opts).then(async (r) => {
|
|
725
772
|
if (!r.ok) {
|
|
726
773
|
// 服务端错误体有两种:{error}(参数/权限)与 {reason}(zh/generate 的未启动原因,带完整说明)
|
|
727
774
|
const body = await r.json().catch(() => ({}));
|
|
@@ -955,7 +1002,7 @@ function pdfUrl(variant) {
|
|
|
955
1002
|
const q = `topic=${encodeURIComponent(current.topic)}&name=${encodeURIComponent(current.name)}`;
|
|
956
1003
|
// 不带 t=Date.now():/api/pdf 已有 ETag(文件 mtime+size),浏览器会 304 复用;
|
|
957
1004
|
// 重新翻译后 ETag 自动变化,不会拿到旧译文。
|
|
958
|
-
return
|
|
1005
|
+
return `${PR_API_BASE}/pdf?${q}${variant ? '&variant=' + variant : ''}`;
|
|
959
1006
|
}
|
|
960
1007
|
|
|
961
1008
|
function syncTranscribeButton() {
|
|
@@ -1011,9 +1058,9 @@ async function openPaper(topic, name, opts = {}) {
|
|
|
1011
1058
|
$('zh-toggle').classList.toggle('active', zhVariant !== null);
|
|
1012
1059
|
// 译文版页宽与原文不同(对照双栏≈2×),分屏每列只有一半宽 ⇒ 都先进适宽
|
|
1013
1060
|
if (zhVariant || viewMode === 'split') { fitMode = true; fitBtn.classList.add('active'); }
|
|
1014
|
-
// 笔记与公式索引都必须在首次 paintPage 之前到货:paintPage 直接按 notes.list
|
|
1061
|
+
// 笔记与公式索引都必须在首次 paintPage 之前到货:paintPage 直接按 notes.list 铺笔记标注框。
|
|
1015
1062
|
// 两者互不依赖,并行拉取;笔记读失败不阻塞 PDF(loadNotes 内部吞错并保留空列表)。
|
|
1016
|
-
const notesReady = loadNotes().catch(() => { /*
|
|
1063
|
+
const notesReady = loadNotes().catch(() => { /* 读失败:本页只是没有标注框,不影响读论文 */ });
|
|
1017
1064
|
// 公式索引(MinerU content_list):**必须在 loadPdf 之前到货**——热区是在 paintPage 里
|
|
1018
1065
|
// 按 eqIndex 铺的,先渲染会漏画/残留上一篇的矩形;又必须排在 zhVariant 定稿之后——
|
|
1019
1066
|
// eqHotEnabled()/renderEqPanel() 都按 zhVariant 决定「译文视图关热区」。失败不影响打开文献。
|
|
@@ -1676,8 +1723,8 @@ window.dprFindDebug = () => {
|
|
|
1676
1723
|
/* ================= 笔记(划词标注 + 可移动笔记窗口)=================
|
|
1677
1724
|
存储:服务端 `<论文>.notes.json`(与 `.study.json` 同目录 ⇒ 跟文献走、换浏览器不丢、将来也能被伴读读到)。
|
|
1678
1725
|
锚点:页号 + 「该页 DOM 文本层拼接串」里的字符区间。文本层的内容只由 PDF 决定(与缩放/模式无关),
|
|
1679
|
-
所以偏移在重渲染后仍然有效 → 每次渲染完成按偏移重建 Range →
|
|
1680
|
-
为什么不用给 span 加 text-decoration:一个选区常跨多个 span
|
|
1726
|
+
所以偏移在重渲染后仍然有效 → 每次渲染完成按偏移重建 Range → 百分比盒子(蓝色虚线框)。
|
|
1727
|
+
为什么不用给 span 加 text-decoration:一个选区常跨多个 span,加类会把整行都画上标注。
|
|
1681
1728
|
盒子层 pointer-events:none,悬停/点击靠坐标命中测试 —— 绝不挡住划词选字。 */
|
|
1682
1729
|
const NOTE_WIN_KEY = 'dpr.noteWin';
|
|
1683
1730
|
const NOTE_BODY_MAX = 20000;
|
|
@@ -1865,7 +1912,7 @@ function noteAnchorFromSelection() {
|
|
|
1865
1912
|
return { page, start: a, end: b, doc, quote: sel.text.slice(0, 400) };
|
|
1866
1913
|
}
|
|
1867
1914
|
|
|
1868
|
-
/* ----------
|
|
1915
|
+
/* ---------- 画笔记标注框(蓝色虚线圆角框,圈住选区范围) ---------- */
|
|
1869
1916
|
function noteClearLayers() {
|
|
1870
1917
|
document.querySelectorAll('.noteLayer').forEach((l) => l.remove());
|
|
1871
1918
|
noteHideTip();
|
|
@@ -1881,7 +1928,7 @@ function notePaintPageDiv(div) {
|
|
|
1881
1928
|
const hay = noteTextHay(div);
|
|
1882
1929
|
const rect = tl.getBoundingClientRect();
|
|
1883
1930
|
if (!hay || !rect.width || !rect.height) return;
|
|
1884
|
-
// 同一页可能被重画多次(逐页渲染 +
|
|
1931
|
+
// 同一页可能被重画多次(逐页渲染 + 收尾重放):先清掉这一页旧的装饰层,避免叠出两层框
|
|
1885
1932
|
const stale = div.querySelector(':scope > .noteLayer');
|
|
1886
1933
|
if (stale) stale.remove();
|
|
1887
1934
|
const pct = (v, base) => (v / base * 100).toFixed(3) + '%';
|
|
@@ -1898,22 +1945,27 @@ function notePaintPageDiv(div) {
|
|
|
1898
1945
|
const rng = document.createRange();
|
|
1899
1946
|
rng.setStart(na, oa);
|
|
1900
1947
|
rng.setEnd(nb, ob);
|
|
1948
|
+
// 统一样式(issue #22-7 定稿):一条笔记一个虚线圆角框圈住全部矩形——不用波浪线
|
|
1949
|
+
// (长笔记逐行画会连成「斑马纹」),也不加小标记(会压到论文内容)。
|
|
1950
|
+
const rs = [];
|
|
1901
1951
|
for (const r of rng.getClientRects()) {
|
|
1902
1952
|
if (r.width < 0.6 || r.height < 0.6) continue; // 换行点产生的退化矩形
|
|
1903
|
-
|
|
1904
|
-
box.className = 'note-under';
|
|
1905
|
-
box.dataset.note = n.id;
|
|
1906
|
-
box.style.left = pct(r.left - rect.left, rect.width);
|
|
1907
|
-
box.style.top = pct(r.top - rect.top, rect.height);
|
|
1908
|
-
box.style.width = pct(r.width, rect.width);
|
|
1909
|
-
box.style.height = pct(r.height, rect.height);
|
|
1910
|
-
layer.appendChild(box);
|
|
1953
|
+
rs.push(r);
|
|
1911
1954
|
}
|
|
1955
|
+
if (!rs.length) continue;
|
|
1956
|
+
const box = document.createElement('span');
|
|
1957
|
+
box.className = 'note-under';
|
|
1958
|
+
box.dataset.note = n.id;
|
|
1959
|
+
box.style.left = pct(Math.min(...rs.map((r) => r.left)) - 4 - rect.left, rect.width);
|
|
1960
|
+
box.style.top = pct(Math.min(...rs.map((r) => r.top)) - 3 - rect.top, rect.height);
|
|
1961
|
+
box.style.width = pct(Math.max(...rs.map((r) => r.right)) - Math.min(...rs.map((r) => r.left)) + 8, rect.width);
|
|
1962
|
+
box.style.height = pct(Math.max(...rs.map((r) => r.bottom)) - Math.min(...rs.map((r) => r.top)) + 6, rect.height);
|
|
1963
|
+
layer.appendChild(box);
|
|
1912
1964
|
} catch { /* 单条锚点算不出几何:跳过这条,列表里仍能看到 */ }
|
|
1913
1965
|
}
|
|
1914
1966
|
if (!layer.childElementCount) layer.remove();
|
|
1915
1967
|
}
|
|
1916
|
-
/** 缩放/切模式/换文档会重建整个 DOM
|
|
1968
|
+
/** 缩放/切模式/换文档会重建整个 DOM:重画全部标注框 */
|
|
1917
1969
|
function notesReapply() {
|
|
1918
1970
|
noteClearLayers();
|
|
1919
1971
|
if (!pdfDoc || !notes.list.length) return;
|
|
@@ -1925,9 +1977,13 @@ function noteById(id) {
|
|
|
1925
1977
|
return notes.list.find((n) => n.id === id) || null;
|
|
1926
1978
|
}
|
|
1927
1979
|
function noteFindAt(x, y) {
|
|
1980
|
+
// 命中区是虚线框的**边框环带**(框外 2px、框内 5px):贴边悬停/点击 = 操作这条笔记;
|
|
1981
|
+
// 框内部保持纯净——阅读时鼠标扫过整段不会一直弹「点击编辑」提示,框内划词提问照常。
|
|
1928
1982
|
for (const box of document.querySelectorAll('.note-under')) {
|
|
1929
1983
|
const r = box.getBoundingClientRect();
|
|
1930
|
-
if (x
|
|
1984
|
+
if (x < r.left - 2 || x > r.right + 2 || y < r.top - 2 || y > r.bottom + 2) continue;
|
|
1985
|
+
const d = Math.min(x - r.left, r.right - x, y - r.top, r.bottom - y);
|
|
1986
|
+
if (d <= 5) return box.dataset.note || null;
|
|
1931
1987
|
}
|
|
1932
1988
|
return null;
|
|
1933
1989
|
}
|
|
@@ -2081,7 +2137,7 @@ function noteCreateFromSelection() {
|
|
|
2081
2137
|
if (!sel || !current) { toast('先在正文里选中一段文字'); return; }
|
|
2082
2138
|
const anchor = noteAnchorFromSelection();
|
|
2083
2139
|
noteStartEdit({ quote: sel.text, anchor: anchor || undefined, body: '' });
|
|
2084
|
-
if (!anchor) toast('
|
|
2140
|
+
if (!anchor) toast('这段选区没能精确锚定:笔记会留在列表里,但不会画标注框', 5000);
|
|
2085
2141
|
}
|
|
2086
2142
|
function noteCreateBlank() {
|
|
2087
2143
|
const sel = askSelection;
|
|
@@ -2482,10 +2538,13 @@ $('split-toggle').onclick = () => setViewMode(viewMode === 'split' ? 'orig' : 's
|
|
|
2482
2538
|
|
|
2483
2539
|
let generateForce = false;
|
|
2484
2540
|
let generateEndpoints = [];
|
|
2541
|
+
/** 选项文本截断(issue #22-1):端点名/模型名/掩码 Key 拼起来可以很长,select 的固有宽度
|
|
2542
|
+
由最长选项决定,曾把 320px 的弹窗撑破 ~100px。宽度已用 CSS 约束(width:100%),这里再截断文本。 */
|
|
2543
|
+
const clipStr = (v, n) => { const s = String(v ?? ''); return s.length > n ? s.slice(0, n - 1) + '…' : s; };
|
|
2485
2544
|
function endpointDisplay(e) {
|
|
2486
|
-
if (e.source === 'harness') return `跟随 Harness · ${e.providerName || '当前模型'} / ${e.model}`;
|
|
2545
|
+
if (e.source === 'harness') return `跟随 Harness · ${clipStr(e.providerName || '当前模型', 20)} / ${clipStr(e.model, 36)}`;
|
|
2487
2546
|
const provider = providerOf(e.baseUrl).name;
|
|
2488
|
-
return `${e.label || provider} · ${e.model || '未填模型'} · ${e.apiKeyHint || '无 Key'}`;
|
|
2547
|
+
return `${clipStr(e.label || provider, 18)} · ${clipStr(e.model || '未填模型', 30)} · ${clipStr(e.apiKeyHint || '无 Key', 14)}`;
|
|
2489
2548
|
}
|
|
2490
2549
|
function closeGeneratePop() { $('generate-pop').style.display = 'none'; }
|
|
2491
2550
|
async function openGeneratePop(force) {
|
|
@@ -2646,7 +2705,7 @@ function cfgProviderIcon(provider) {
|
|
|
2646
2705
|
}
|
|
2647
2706
|
const img = document.createElement('img');
|
|
2648
2707
|
img.className = 'cfg-icon' + (provider.mono ? ' mono' : '');
|
|
2649
|
-
img.src = '
|
|
2708
|
+
img.src = PR_ASSET_BASE + 'vendor/' + provider.icon;
|
|
2650
2709
|
img.alt = '';
|
|
2651
2710
|
img.setAttribute('aria-hidden', 'true');
|
|
2652
2711
|
img.dataset.cfgProviderIcon = provider.id;
|
|
@@ -2942,15 +3001,15 @@ $('cfg-save-new').onclick = () => saveCfg(true);
|
|
|
2942
3001
|
let pdfjsReadyP = null;
|
|
2943
3002
|
function ensurePdfjs() {
|
|
2944
3003
|
if (!pdfjsReadyP) {
|
|
2945
|
-
pdfjsReadyP = import('
|
|
3004
|
+
pdfjsReadyP = import(PR_ASSET_BASE + 'vendor/pdf.min.mjs').then(
|
|
2946
3005
|
(m) => {
|
|
2947
3006
|
window.pdfjsLib = m;
|
|
2948
|
-
m.GlobalWorkerOptions.workerSrc = '
|
|
3007
|
+
m.GlobalWorkerOptions.workerSrc = PR_ASSET_BASE + 'vendor/pdf.worker.min.mjs';
|
|
2949
3008
|
return m;
|
|
2950
3009
|
},
|
|
2951
3010
|
(e) => {
|
|
2952
3011
|
pdfjsReadyP = null; // 失败后清缓存:瞬时故障不至于让本页签永久坏掉,下次 loadPdf 重试
|
|
2953
|
-
throw new Error(
|
|
3012
|
+
throw new Error(`pdf.js 加载失败(${PR_ASSET_BASE}vendor/pdf.min.mjs):` + (e && e.message ? e.message : e));
|
|
2954
3013
|
},
|
|
2955
3014
|
);
|
|
2956
3015
|
}
|
|
@@ -3679,6 +3738,42 @@ function fitToWidth() {
|
|
|
3679
3738
|
}
|
|
3680
3739
|
$('zoom-in').onclick = () => { exitFitMode(); setZoom(zoomScale + 0.25); };
|
|
3681
3740
|
$('zoom-out').onclick = () => { exitFitMode(); setZoom(zoomScale - 0.25); };
|
|
3741
|
+
/* 点百分比直接输入缩放值(issue #22-6):只有 ± 按钮不够精确。Enter 提交 / Esc 取消 / 失焦提交;
|
|
3742
|
+
setZoom 自己会夹在 0.6–4.5(即标签口径的 40%–300%),越界输入不会出错。 */
|
|
3743
|
+
$('zoom-label').addEventListener('click', () => {
|
|
3744
|
+
const label = $('zoom-label');
|
|
3745
|
+
if (label.querySelector('input')) return;
|
|
3746
|
+
const inp = document.createElement('input');
|
|
3747
|
+
inp.type = 'text';
|
|
3748
|
+
inp.inputMode = 'numeric';
|
|
3749
|
+
inp.value = Math.round(zoomScale / 1.5 * 100);
|
|
3750
|
+
inp.title = '40–300,Enter 确认';
|
|
3751
|
+
inp.style.cssText = 'width: 50px; font: inherit; font-size: 12px; text-align: center; border: 1px solid var(--accent); border-radius: 5px; background: var(--panel); color: var(--text); padding: 1px 2px';
|
|
3752
|
+
label.textContent = '';
|
|
3753
|
+
label.appendChild(inp);
|
|
3754
|
+
inp.focus();
|
|
3755
|
+
inp.select();
|
|
3756
|
+
let closed = false;
|
|
3757
|
+
const done = (commit) => {
|
|
3758
|
+
if (closed) return;
|
|
3759
|
+
closed = true;
|
|
3760
|
+
if (commit) {
|
|
3761
|
+
const v = Math.round(parseFloat(String(inp.value).replace('%', '').trim()));
|
|
3762
|
+
if (Number.isFinite(v) && v > 0) { exitFitMode(); setZoom(v / 100 * 1.5); }
|
|
3763
|
+
}
|
|
3764
|
+
label.textContent = Math.round(zoomScale / 1.5 * 100) + '%';
|
|
3765
|
+
};
|
|
3766
|
+
inp.addEventListener('keydown', (e) => {
|
|
3767
|
+
if (e.key === 'Enter') { e.preventDefault(); done(true); }
|
|
3768
|
+
else if (e.key === 'Escape') { e.preventDefault(); done(false); }
|
|
3769
|
+
e.stopPropagation();
|
|
3770
|
+
});
|
|
3771
|
+
inp.addEventListener('blur', () => done(true));
|
|
3772
|
+
});
|
|
3773
|
+
|
|
3774
|
+
/* 捏合缩放(issue #22-6):不上。做过两版——逐帧重渲(卡)、CSS transform 预览 +
|
|
3775
|
+
停顿提交 + wheel/gesture 双通道(合成手势下指标全绿,真触控板体验仍不佳)。
|
|
3776
|
+
维护者裁定撤销:缩放 = ± 按钮 / 适宽 / 点百分比输入。 */
|
|
3682
3777
|
fitBtn.onclick = () => { if (!pdfDoc) return; fitMode = true; fitBtn.classList.add('active'); fitBtn.blur(); fitToWidth(); };
|
|
3683
3778
|
window.addEventListener('resize', () => {
|
|
3684
3779
|
if (viewMode === 'split' && window.innerWidth < SPLIT_MIN_WIDTH) {
|
|
@@ -4282,7 +4377,7 @@ let downPt = null;
|
|
|
4282
4377
|
|
|
4283
4378
|
/** 弹层共用的展示动作(文字引用与公式引用都走这里)。 */
|
|
4284
4379
|
function showAskPop(o) {
|
|
4285
|
-
$('ask-quote').textContent = o.quote.length >
|
|
4380
|
+
$('ask-quote').textContent = o.quote.length > 220 ? o.quote.slice(0, 220) + '…' : o.quote;
|
|
4286
4381
|
$('ask-input').value = '';
|
|
4287
4382
|
$('ask-copy').style.display = askSelection && askSelection.kind === 'equation' ? 'inline-block' : 'none';
|
|
4288
4383
|
// 「译」只在「纯文字选区 + 原文视图 + **原文列** + 长度可翻译」时出现。
|
|
@@ -4306,10 +4401,132 @@ function showAskPop(o) {
|
|
|
4306
4401
|
askPop.style.left = Math.max(8, Math.min(o.x, window.innerWidth - popW - 8)) + 'px';
|
|
4307
4402
|
askPop.style.top = Math.max(8, Math.min(o.y, window.innerHeight - popH - 8)) + 'px';
|
|
4308
4403
|
$('ask-input').focus();
|
|
4404
|
+
// focus() 会把文档选区清掉(Chromium:焦点进可编辑区即清页面选区)——实测让「三击选段」
|
|
4405
|
+
// 看起来像没生效:段落已选中、气泡也引用了整段,但 PDF 上的高亮瞬间消失。把刚克隆的
|
|
4406
|
+
// 选区放回去:输入框保持焦点可直接打字,选中高亮不再消失(划词/双击选词同样受益)。
|
|
4407
|
+
try {
|
|
4408
|
+
const r0 = askSelection && askSelection.range;
|
|
4409
|
+
if (r0 && r0.startContainer && r0.startContainer.isConnected !== false && typeof r0.cloneRange === 'function') {
|
|
4410
|
+
const sel = window.getSelection();
|
|
4411
|
+
sel.removeAllRanges();
|
|
4412
|
+
sel.addRange(r0.cloneRange());
|
|
4413
|
+
}
|
|
4414
|
+
} catch { /* 选区已失效:气泡里仍有引用文本,不阻塞 */ }
|
|
4309
4415
|
}
|
|
4310
4416
|
|
|
4311
4417
|
document.addEventListener('mousedown', (e) => { downPt = { x: e.clientX, y: e.clientY }; }, true);
|
|
4312
4418
|
|
|
4419
|
+
/* 三击序列的首击落点(见 dprPickParagraph 处的三击 handler):双击弹出的提问气泡可能
|
|
4420
|
+
恰好盖住原位置,第 3 击的 target 就成了气泡 div 而非 textLayer——三击选段会静默失效
|
|
4421
|
+
(退回原生行为,实测选中一个词)。handler 在 detail≥3 且 target 不在 textLayer 时,
|
|
4422
|
+
用这里记下的首击落点回退(要求近距离 + 短间隔,只 reinterpret 同一次连击)。 */
|
|
4423
|
+
let dprLastTlHit = null;
|
|
4424
|
+
document.addEventListener('mousedown', (e) => {
|
|
4425
|
+
const tl = e.target && e.target.closest ? e.target.closest('.textLayer') : null;
|
|
4426
|
+
if (tl && tl.isConnected) dprLastTlHit = { x: e.clientX, y: e.clientY, at: Date.now(), tl };
|
|
4427
|
+
}, true);
|
|
4428
|
+
|
|
4429
|
+
/* 三击选中整段(issue #22-3,#22 追加反馈修复跨栏误并):文本层没有段落语义,原生三击会
|
|
4430
|
+
选中整个 textLayer(≈整页)。核心算法在 dprPickParagraph(纯函数,可测),事件层只做
|
|
4431
|
+
DOM 度量与选区落地。设好选区后走同一条 mouseup →「选中即问」链路,不另接气泡。 */
|
|
4432
|
+
/* 行盒分组版,两处与初版不同的关键点(都是双栏/对照版的真实教训,见 issue #22 追加反馈):
|
|
4433
|
+
· 归行不能只看 top:双栏论文同一行的左右栏、babeldoc 对照版的原文块与译文块 top 相同,
|
|
4434
|
+
只按 top 归并会得到一条横贯全页的「行」,它和谁都水平重叠 ⇒ 扩段整页串联 ⇒ 撞行数
|
|
4435
|
+
上限退回单行——「有时候一行 / 有时候超长一段 / 对照版三击没用」三个症状同一根因。
|
|
4436
|
+
现在加水平相邻判据:同行还得间隙 ≤ gapX(词距并入、栏沟断开)。
|
|
4437
|
+
· 扩段不能只看数组相邻行:正确分行后,(t,l) 排序里双栏相邻项恰是**另一栏**,逐相邻扩
|
|
4438
|
+
会在跨栏处立刻断掉 ⇒ 永远只选一行。现在按「竖直间隙小 + 与段落栏区间有重叠」在
|
|
4439
|
+
附近行里扫描跳过异栏行;栏区间每并一行取**交集**,防止居中标题把区间 creep 到另一栏。
|
|
4440
|
+
阈值依据(真浏览器实测 GFS 双栏 + babeldoc 对照版的 textLayer 盒):行内词距(含两端对齐
|
|
4441
|
+
拉伸)≤ 2×行高(≈2% 页宽),双栏栏沟 ≈ 4% 页宽(GFS 在 1368px 页宽下 54px),对照版栏沟
|
|
4442
|
+
≥ 27% 页宽。gapX = max(2×行高, 3% 页宽) 落在词距与栏沟之间;比它更宽的词距偶发拆行也无害——
|
|
4443
|
+
同 top 的两个碎片在扩段时竖直间隙为负、水平与栏区间重叠,会立即并回。
|
|
4444
|
+
竖直方向 pdf.js 的 span 高度≈字号而非行距,行间间隙明显小于段间距,0.45×行高分得开。 */
|
|
4445
|
+
function dprPickParagraph(items, x, y, pageW) {
|
|
4446
|
+
// items: [{s, l, r2, t, b}](已按 t,l 排序的 span 盒);返回 {first, last, hit} 或 null
|
|
4447
|
+
// 1) 归行:top 相差 ≤2px 且水平相邻(间隙 ≤ gapX)
|
|
4448
|
+
const lines = [];
|
|
4449
|
+
for (const it of items) {
|
|
4450
|
+
const ln = lines[lines.length - 1];
|
|
4451
|
+
const h = Math.max(1, it.b - it.t);
|
|
4452
|
+
const gapX = Math.max(2 * h, pageW * 0.03);
|
|
4453
|
+
if (ln && Math.abs(ln.t - it.t) <= 2 && it.l - ln.r2 <= gapX) {
|
|
4454
|
+
ln.b = Math.max(ln.b, it.b); ln.l = Math.min(ln.l, it.l); ln.r2 = Math.max(ln.r2, it.r2);
|
|
4455
|
+
ln.items.push(it);
|
|
4456
|
+
} else {
|
|
4457
|
+
lines.push({ t: it.t, b: it.b, l: it.l, r2: it.r2, items: [it] });
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
// 2) 命中行(±3px 容差)
|
|
4461
|
+
const idx = lines.findIndex((r) => y >= r.t - 3 && y <= r.b + 3 && x >= r.l - 3 && x <= r.r2 + 3);
|
|
4462
|
+
if (idx < 0) return null;
|
|
4463
|
+
// 3) 向上下扩段:竖直间隙 ≤ 0.45×行高 且 与栏区间有水平重叠(跳过异栏行继续扫)
|
|
4464
|
+
const lh = Math.max(5, lines[idx].b - lines[idx].t);
|
|
4465
|
+
const gapY = lh * 0.45;
|
|
4466
|
+
const up = [], down = [];
|
|
4467
|
+
let boxL = lines[idx].l, boxR = lines[idx].r2;
|
|
4468
|
+
let curT = lines[idx].t, curB = lines[idx].b;
|
|
4469
|
+
for (let i = idx - 1; i >= 0; i--) {
|
|
4470
|
+
const c = lines[i];
|
|
4471
|
+
if (curT - c.b > gapY) break; // 行按 t 升序,往上间隙只增不减
|
|
4472
|
+
if (Math.min(boxR, c.r2) - Math.max(boxL, c.l) <= 0) continue; // 异栏:跳过继续找同栏
|
|
4473
|
+
up.push(c);
|
|
4474
|
+
curT = c.t;
|
|
4475
|
+
const nl = Math.max(boxL, c.l), nr = Math.min(boxR, c.r2);
|
|
4476
|
+
if (nr - nl > 0) { boxL = nl; boxR = nr; } // 栏区间取交集,防 creep
|
|
4477
|
+
}
|
|
4478
|
+
for (let i = idx + 1; i < lines.length; i++) {
|
|
4479
|
+
const c = lines[i];
|
|
4480
|
+
if (c.t - curB > gapY) break;
|
|
4481
|
+
if (Math.min(boxR, c.r2) - Math.max(boxL, c.l) <= 0) continue;
|
|
4482
|
+
down.push(c);
|
|
4483
|
+
curB = c.b;
|
|
4484
|
+
const nl = Math.max(boxL, c.l), nr = Math.min(boxR, c.r2);
|
|
4485
|
+
if (nr - nl > 0) { boxL = nl; boxR = nr; }
|
|
4486
|
+
}
|
|
4487
|
+
const members = [...up.reverse(), lines[idx], ...down];
|
|
4488
|
+
if (members.length > 60) return { first: lines[idx].items[0].s, last: lines[idx].items[lines[idx].items.length - 1].s, hit: lines[idx] };
|
|
4489
|
+
return { first: members[0].items[0].s, last: members[members.length - 1].items[members[members.length - 1].items.length - 1].s, hit: lines[idx] };
|
|
4490
|
+
}
|
|
4491
|
+
document.addEventListener('mousedown', (e) => {
|
|
4492
|
+
if (e.detail < 3) return;
|
|
4493
|
+
const tl = e.target && e.target.closest ? e.target.closest('.textLayer') : null;
|
|
4494
|
+
let px = e.clientX, py = e.clientY, tlEl = tl;
|
|
4495
|
+
if (!tlEl || !tlEl.isConnected) {
|
|
4496
|
+
// 第 3 击被双击弹出的气泡挡住:回退到同一次连击的首击落点(近距离 + 短间隔才认)
|
|
4497
|
+
const h = dprLastTlHit;
|
|
4498
|
+
if (!h || !h.tl || !h.tl.isConnected || Date.now() - h.at > 600
|
|
4499
|
+
|| Math.abs(h.x - e.clientX) + Math.abs(h.y - e.clientY) > 8) return;
|
|
4500
|
+
px = h.x; py = h.y; tlEl = h.tl;
|
|
4501
|
+
}
|
|
4502
|
+
const tlRect = tlEl.getBoundingClientRect();
|
|
4503
|
+
const items = Array.from(tlEl.querySelectorAll('span'))
|
|
4504
|
+
.filter((s) => (s.textContent || '').trim())
|
|
4505
|
+
.map((s) => { const r = s.getBoundingClientRect(); return { s, l: r.left, r2: r.right, t: r.top, b: r.bottom }; })
|
|
4506
|
+
.filter((r) => r.r2 > r.l && r.b > r.t)
|
|
4507
|
+
.sort((a, b) => a.t - b.t || a.l - b.l);
|
|
4508
|
+
const pick = dprPickParagraph(items, px, py, tlRect.width);
|
|
4509
|
+
if (!pick) return;
|
|
4510
|
+
e.preventDefault(); // 替换原生三击(整页全选)
|
|
4511
|
+
const first = pick.first; // 段首 = 首行最左
|
|
4512
|
+
const last = pick.last; // 段尾 = 末行最右
|
|
4513
|
+
// 端点必须落在**文本节点**上(setStart(spanEl, 0) 会得到元素端点):笔记锚定的
|
|
4514
|
+
// noteAnchorFromSelection → offsetOf 只认文本节点,元素端点会让笔记画不出虚线框
|
|
4515
|
+
// (实测教训:选区正常、气泡正常,唯独笔记锚定失败)。
|
|
4516
|
+
const firstText = (sp) => { for (let n = sp.firstChild; n; n = n.nextSibling) if (n.nodeType === 3 && n.nodeValue) return n; return null; };
|
|
4517
|
+
const lastText = (sp) => { for (let n = sp.lastChild; n; n = n.previousSibling) if (n.nodeType === 3 && n.nodeValue) return n; return null; };
|
|
4518
|
+
try {
|
|
4519
|
+
const ft = firstText(first) || first.firstChild || first;
|
|
4520
|
+
const lt = lastText(last) || last.lastChild || last;
|
|
4521
|
+
const rng = document.createRange();
|
|
4522
|
+
rng.setStart(ft, 0);
|
|
4523
|
+
rng.setEnd(lt, lt.nodeType === 3 ? (lt.nodeValue || '').length : (lt.childNodes || []).length);
|
|
4524
|
+
const sel = window.getSelection();
|
|
4525
|
+
sel.removeAllRanges();
|
|
4526
|
+
sel.addRange(rng);
|
|
4527
|
+
} catch { /* 跨节点边界算不出 Range:放回原生行为(下次三击仍走原生整页) */ }
|
|
4528
|
+
}, true);
|
|
4529
|
+
|
|
4313
4530
|
document.addEventListener('mouseup', (e) => {
|
|
4314
4531
|
if (askPop.contains(e.target)) return;
|
|
4315
4532
|
if (noteWinEl && noteWinEl.contains(e.target)) return;
|
|
@@ -4360,6 +4577,30 @@ document.addEventListener('mouseup', (e) => {
|
|
|
4360
4577
|
document.addEventListener('mousedown', (e) => { if (!askPop.contains(e.target)) askPop.style.display = 'none'; });
|
|
4361
4578
|
$('ask-cancel').onclick = () => { askPop.style.display = 'none'; };
|
|
4362
4579
|
|
|
4580
|
+
/* 气泡可拖动(issue #22-4):把手 mousedown → 跟随指针移动,夹在视口内。位置不记忆——
|
|
4581
|
+
气泡是临时的,下次选中/翻译会按锚点重新定位;拖动只是当下把它挪开别挡字。 */
|
|
4582
|
+
function makePopDraggable(gripId, popId) {
|
|
4583
|
+
const grip = $(gripId);
|
|
4584
|
+
const pop = $(popId);
|
|
4585
|
+
grip.addEventListener('mousedown', (e) => {
|
|
4586
|
+
if (e.button !== 0) return;
|
|
4587
|
+
e.preventDefault();
|
|
4588
|
+
e.stopPropagation();
|
|
4589
|
+
const r = pop.getBoundingClientRect();
|
|
4590
|
+
const dx = e.clientX - r.left;
|
|
4591
|
+
const dy = e.clientY - r.top;
|
|
4592
|
+
const move = (ev) => {
|
|
4593
|
+
pop.style.left = Math.max(0, Math.min(window.innerWidth - 60, ev.clientX - dx)) + 'px';
|
|
4594
|
+
pop.style.top = Math.max(0, Math.min(window.innerHeight - 30, ev.clientY - dy)) + 'px';
|
|
4595
|
+
};
|
|
4596
|
+
const up = () => { document.removeEventListener('mousemove', move); document.removeEventListener('mouseup', up); };
|
|
4597
|
+
document.addEventListener('mousemove', move);
|
|
4598
|
+
document.addEventListener('mouseup', up);
|
|
4599
|
+
});
|
|
4600
|
+
}
|
|
4601
|
+
makePopDraggable('ask-grip', 'ask-pop');
|
|
4602
|
+
makePopDraggable('tr-grip', 'tr-pop');
|
|
4603
|
+
|
|
4363
4604
|
// 复制 LaTeX(显式动作:不自动写剪贴板,静默覆盖用户剪贴板是意外副作用)
|
|
4364
4605
|
$('ask-copy').onclick = async () => {
|
|
4365
4606
|
const latex = askSelection && askSelection.kind === 'equation' ? askSelection.text : '';
|