dsh-pdf-workbench 1.3.1 → 1.3.3

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.
Files changed (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +199 -192
  3. package/client.js +1037 -451
  4. package/docs/RELEASE.md +119 -110
  5. package/icon.svg +6 -6
  6. package/package.json +9 -1
  7. package/screenshots.json +8 -8
  8. package/src/client/host-ui-entry.js +11 -0
  9. package/src/client/react-jsx-runtime.cjs +21 -0
  10. package/src/client/viewer.js +80 -80
  11. package/src/host/routes.js +2 -0
  12. package/src/host/update.js +10 -1
  13. package/tools/AGENTS.md +33 -33
  14. package/tools/README.md +138 -138
  15. package/tools/auto_chapters.py +122 -122
  16. package/tools/dsfile.mjs +198 -198
  17. package/tools/export_chapter.py +108 -108
  18. package/tools/export_page.py +91 -91
  19. package/tools/md2overlay.py +200 -200
  20. package/tools/md2tex.py +422 -422
  21. package/tools/node.cmd +3 -0
  22. package/tools/pdf_blocks.py +110 -110
  23. package/tools/pdf_fontsize.py +20 -20
  24. package/tools/pdf_merge.py +15 -15
  25. package/tools/pdf_pagesizes.py +8 -8
  26. package/tools/pdf_raster.py +21 -21
  27. package/tools/pdfkit.py +896 -896
  28. package/tools/py.cmd +3 -0
  29. package/tools/realign_overlay.py +248 -248
  30. package/tools/rebuild_overlay.py +55 -55
  31. package/tools/rename_chapters.py +93 -93
  32. package/tools//350/247/204/350/214/203/00_/345/205/261/345/220/214/347/272/246/345/256/232.md +142 -142
  33. package/tools//350/247/204/350/214/203/01_/346/226/207/346/234/254/346/217/220/345/217/226.md +204 -204
  34. package/tools//350/247/204/350/214/203/02_/347/255/224/347/226/221.md +61 -61
  35. package/tools//350/247/204/350/214/203/03_/344/271/240/351/242/230/350/247/243/347/255/224.md +77 -77
  36. package/tools//350/247/204/350/214/203/api/346/217/220/347/244/272/350/257/215_/346/217/220/345/217/226.md +11 -11
  37. package/vendor/cmaps/LICENSE.txt +36 -36
  38. package/vendor/fonts/excalifont/OFL.txt +98 -98
  39. package/vendor/fonts/zhhand/OFL.txt +99 -99
  40. package/vendor/host-ui.cjs +1719 -0
  41. package/vendor/host-ui.css +799 -0
  42. package/vendor/pdf.min.mjs +28 -28
  43. package/vendor/pdf.worker.min.mjs +28 -28
  44. package/vendor/pdfjs-LICENSE.txt +177 -177
  45. package/vendor/rough/LICENSE +21 -21
  46. package/vendor/rough/rough.mjs +1 -1
  47. package/vendor/wasm/LICENSE_JBIG2 +196 -196
  48. package/vendor/wasm/LICENSE_OPENJPEG +39 -39
  49. package/vendor/wasm/LICENSE_PDFJS_JBIG2 +13 -13
  50. package/vendor/wasm/LICENSE_PDFJS_OPENJPEG +22 -22
  51. package/vendor/wasm/LICENSE_PDFJS_QCMS +19 -19
  52. package/vendor/wasm/LICENSE_QCMS +21 -21
  53. package/vendor/wasm/jbig2_nowasm_fallback.js +15 -15
  54. package/vendor/wasm/openjpeg_nowasm_fallback.js +17 -17
  55. package//345/256/211/350/243/205/344/270/216/345/210/206/345/217/221.md +1 -1
package/docs/RELEASE.md CHANGED
@@ -1,110 +1,119 @@
1
- # 发版流程(固定版)
2
-
3
- > 用户说「更新 / 发版 / 发布」时,**按本文执行**,不要重新设计流程。
4
- > 日常修改仍然只本地提交;本流程只在明确发版时启动。
5
-
6
- ## 0. 发版前
7
-
8
- 1. 确认 `package.json` 版本:修复 +补丁位,新功能 +次版本位。
9
- 2. `CHANGELOG.md` 顶部新增 `## vX.Y.Z`,写清改了什么。
10
- 3. 如果界面有变化:更新 `README.md` 截图与 `screenshots.json`(市场从仓库读取,不需要为截图提 PR)。
11
- 4. 跑检查:
12
-
13
- ```powershell
14
- cd math-desk
15
- node --check client.js
16
- node --check index.js
17
- Get-ChildItem src\host\*.js | ForEach-Object { node --check $_.FullName }
18
- cd ..
19
- node .dsh-scratch\check-keys.mjs
20
- node .dsh-scratch\check-deps.mjs
21
- node .dsh-scratch\side-smoke.mjs
22
- node .dsh-scratch\notes-test.mjs
23
- node .dsh-scratch\session-seed-test.mjs
24
- node .dsh-scratch\page-store-test.mjs
25
- node .dsh-scratch\annotation-store-test.mjs
26
- node .dsh-scratch\host-test.mjs
27
- ```
28
-
29
- ## 1. GitHub Release(默认渠道)
30
-
31
- ```powershell
32
- cd math-desk
33
- powershell -ExecutionPolicy Bypass -File .\build-dist.ps1
34
- # 产出 ..\dist\dsh-pdf-workbench-X.Y.Z.zip
35
-
36
- git add -A
37
- git commit -m "vX.Y.Z: <一句话>"
38
- git tag vX.Y.Z
39
- git push origin main
40
- git push --tags origin
41
- ```
42
-
43
- 创建 GitHub Release `vX.Y.Z`,上传:
44
-
45
- - `dsh-pdf-workbench-X.Y.Z.zip`(必须)
46
- - 可选 `dsh-pdf-workbench-X.Y.Z.tgz`(干净 worktree 里 `npm pack`,作为市场 npm 失败时的回退)
47
-
48
- Release 说明直接复制 `CHANGELOG` 的该版本条目。
49
-
50
- ## 2. npm
51
-
52
- npm 包名固定 **`dsh-pdf-workbench`**。必须从**干净 worktree / 干净 clone**发布,避免带上本机 `tools/py.cmd`、`tools/node.cmd`、`__pycache__`:
53
-
54
- ```powershell
55
- cd <工作区>\math-desk
56
- git worktree add ..\dist\npm-release vX.Y.Z
57
- cd ..\dist\npm-release
58
- npm login --auth-type=web
59
- npm stage publish --access public
60
- ```
61
-
62
- 然后批准:
63
-
64
- - 网页:https://www.npmjs.com/settings/minggemofashi/staged
65
- - 或:`npm stage approve <stage-id>`(真实 6 位 OTP)
66
-
67
- 批准后验证:
68
-
69
- ```powershell
70
- npm view dsh-pdf-workbench@X.Y.Z version
71
- ```
72
-
73
- 清理:
74
-
75
- ```powershell
76
- cd <工作区>
77
- git -C math-desk worktree remove ..\dist\npm-release
78
- ```
79
-
80
- > 注意:npm 的 granular token 不能代替 2FA 发布;必须交互登录。不要用字面量 `你的6位验证码`。
81
-
82
- ## 3. 插件市场
83
-
84
- 首次上架:向 `awesome-dsh-plugin` 提交 `data/plugins/<owner>__<repo>.yml`;本插件条目已提交(PR 保留)。
85
-
86
- 首次之后:
87
-
88
- - npm 包 `repository` 指向同一仓库时,dsh-market 自动做 npm 映射,**版本更新不需要再提 PR**;
89
- - 只有改仓库地址、包名、分类或描述时才改 awesome 条目;
90
- - 截图换图只需更新仓库 `screenshots.json`;
91
- - 若 npm 发布失败,才回退到 tarball:上传新版本 `.tgz` 并更新条目的 `tarball` 字段(需要 PR)。
92
-
93
- ## 4. 一致性检查
94
-
95
- - `package.json` 版本 = tag = GitHub Release = npm 版本;
96
- - Release 的 zip / tgz 能下载;
97
- - `README.md` 安装命令版本正确;
98
- - 远程 `main` 包含发版提交;
99
- - npm 页面可见,market 能搜到(缓存可能有延迟)。
100
-
101
- ## 5. 旧包处理(已完成)
102
-
103
- 旧包 `dsh-pdf-math-desk` 已从 npm 删除(`npm view` 返回 404),无需再处理;不要重新发布这个名称。
104
-
105
- ## 6. 不要做
106
-
107
- - 不重新引入 `market/index.json`(收录由 awesome 列表负责);
108
- - 不发 npm 前不更新市场条目的 npm 映射;
109
- - 不用本机工作目录直接 `npm publish`(会带上未跟踪的包装脚本/pycache);
110
- - 不在用户没说“发版”时升版本/tag/push/Release/npm。
1
+ # 发版流程(固定版)
2
+
3
+ > 用户说「更新 / 发版 / 发布」时,**按本文执行**,不要重新设计流程。
4
+ > 日常修改仍然只本地提交;本流程只在明确发版时启动。
5
+
6
+ ## 0. 发版前
7
+
8
+ 1. 确认 `package.json` 版本:修复 +补丁位,新功能 +次版本位。
9
+ 2. `CHANGELOG.md` 顶部新增 `## vX.Y.Z`,写清改了什么。
10
+ 3. 如果界面有变化:更新 `README.md` 截图与 `screenshots.json`(市场从仓库读取,不需要为截图提 PR)。
11
+ 4. 跑检查:
12
+
13
+ ```powershell
14
+ cd math-desk
15
+ node --check client.js
16
+ node --check index.js
17
+ Get-ChildItem src\host\*.js | ForEach-Object { node --check $_.FullName }
18
+ cd ..
19
+ node .dsh-scratch\check-keys.mjs
20
+ node .dsh-scratch\check-deps.mjs
21
+ node .dsh-scratch\side-smoke.mjs
22
+ node .dsh-scratch\notes-test.mjs
23
+ node .dsh-scratch\session-seed-test.mjs
24
+ node .dsh-scratch\page-store-test.mjs
25
+ node .dsh-scratch\annotation-store-test.mjs
26
+ node .dsh-scratch\host-test.mjs
27
+ ```
28
+
29
+ ## 1. GitHub Release(默认渠道)
30
+
31
+ 先构建宿主 primitives 产物(构建依赖只在开发时安装,不随插件安装):
32
+
33
+ ```powershell
34
+ cd math-desk
35
+ npm install
36
+ npm run build:host-ui
37
+ ```
38
+
39
+ 然后构建 zip:
40
+
41
+ ```powershell
42
+ powershell -ExecutionPolicy Bypass -File .\build-dist.ps1
43
+ # 产出 ..\dist\dsh-pdf-workbench-X.Y.Z.zip
44
+
45
+ git add -A
46
+ git commit -m "vX.Y.Z: <一句话>"
47
+ git tag vX.Y.Z
48
+ git push origin main
49
+ git push --tags origin
50
+ ```
51
+
52
+ 创建 GitHub Release `vX.Y.Z`,上传:
53
+
54
+ - `dsh-pdf-workbench-X.Y.Z.zip`(必须)
55
+ - 可选 `dsh-pdf-workbench-X.Y.Z.tgz`(干净 worktree 里 `npm pack`,作为市场 npm 失败时的回退)
56
+
57
+ Release 说明直接复制 `CHANGELOG` 的该版本条目。
58
+
59
+ ## 2. npm
60
+
61
+ npm 包名固定 **`dsh-pdf-workbench`**。必须从**干净 worktree / 干净 clone**发布,避免带上本机 `tools/py.cmd`、`tools/node.cmd`、`__pycache__`:
62
+
63
+ ```powershell
64
+ cd <工作区>\math-desk
65
+ git worktree add ..\dist\npm-release vX.Y.Z
66
+ cd ..\dist\npm-release
67
+ npm login --auth-type=web
68
+ npm stage publish --access public
69
+ ```
70
+
71
+ 然后批准:
72
+
73
+ - 网页:https://www.npmjs.com/settings/minggemofashi/staged
74
+ - 或:`npm stage approve <stage-id>`(真实 6 位 OTP)
75
+
76
+ 批准后验证:
77
+
78
+ ```powershell
79
+ npm view dsh-pdf-workbench@X.Y.Z version
80
+ ```
81
+
82
+ 清理:
83
+
84
+ ```powershell
85
+ cd <工作区>
86
+ git -C math-desk worktree remove ..\dist\npm-release
87
+ ```
88
+
89
+ > 注意:npm 的 granular token 不能代替 2FA 发布;必须交互登录。不要用字面量 `你的6位验证码`。
90
+
91
+ ## 3. 插件市场
92
+
93
+ 首次上架:向 `awesome-dsh-plugin` 提交 `data/plugins/<owner>__<repo>.yml`;本插件条目已提交(PR 保留)。
94
+
95
+ 首次之后:
96
+
97
+ - npm 包 `repository` 指向同一仓库时,dsh-market 自动做 npm 映射,**版本更新不需要再提 PR**;
98
+ - 只有改仓库地址、包名、分类或描述时才改 awesome 条目;
99
+ - 截图换图只需更新仓库 `screenshots.json`;
100
+ - 若 npm 发布失败,才回退到 tarball:上传新版本 `.tgz` 并更新条目的 `tarball` 字段(需要 PR)。
101
+
102
+ ## 4. 一致性检查
103
+
104
+ - `package.json` 版本 = tag = GitHub Release = npm 版本;
105
+ - Release 的 zip / tgz 能下载;
106
+ - `README.md` 安装命令版本正确;
107
+ - 远程 `main` 包含发版提交;
108
+ - npm 页面可见,market 能搜到(缓存可能有延迟)。
109
+
110
+ ## 5. 旧包处理(已完成)
111
+
112
+ 旧包 `dsh-pdf-math-desk` 已从 npm 删除(`npm view` 返回 404),无需再处理;不要重新发布这个名称。
113
+
114
+ ## 6. 不要做
115
+
116
+ - 不重新引入 `market/index.json`(收录由 awesome 列表负责);
117
+ - 不发 npm 前不更新市场条目的 npm 映射;
118
+ - 不用本机工作目录直接 `npm publish`(会带上未跟踪的包装脚本/pycache);
119
+ - 不在用户没说“发版”时升版本/tag/push/Release/npm。
package/icon.svg CHANGED
@@ -1,6 +1,6 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24" role="img" aria-label="Math workbench">
2
- <rect x="2.8" y="6.8" width="4" height="13.6" rx="0.9" fill="#2f6f8f"/>
3
- <rect x="9.8" y="3.8" width="4" height="16.6" rx="0.9" fill="#3f8aa6"/>
4
- <rect x="16.8" y="8.6" width="4" height="11.8" rx="0.9" fill="#2a5f78"/>
5
- <path d="M2.2 21.4h19.6" stroke="#1f4a5c" stroke-width="1.4" stroke-linecap="round"/>
6
- </svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24" role="img" aria-label="Math workbench">
2
+ <rect x="2.8" y="6.8" width="4" height="13.6" rx="0.9" fill="#2f6f8f"/>
3
+ <rect x="9.8" y="3.8" width="4" height="16.6" rx="0.9" fill="#3f8aa6"/>
4
+ <rect x="16.8" y="8.6" width="4" height="11.8" rx="0.9" fill="#2a5f78"/>
5
+ <path d="M2.2 21.4h19.6" stroke="#1f4a5c" stroke-width="1.4" stroke-linecap="round"/>
6
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-pdf-workbench",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "PDF reading workbench for DSH: books and chapters, ask-as-you-read conversations, annotations, and a built-in pdf.js reader.",
@@ -47,6 +47,14 @@
47
47
  "engines": {
48
48
  "dsh": ">=0.2.2-rc.5"
49
49
  },
50
+ "scripts": {
51
+ "build:host-ui": "node scripts/build-host-ui.mjs"
52
+ },
53
+ "devDependencies": {
54
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
55
+ "clsx": "^2.1.1",
56
+ "esbuild": "^0.25.0"
57
+ },
50
58
  "dsh": {
51
59
  "bundle": {
52
60
  "patch": "./cordis.patch.yml"
package/screenshots.json CHANGED
@@ -1,8 +1,8 @@
1
- [
2
- "assets/screenshot-hero.jpg",
3
- "assets/screenshot-shelf.jpg",
4
- "assets/screenshot-reader.jpg",
5
- "assets/screenshot-bilingual.jpg",
6
- "assets/screenshot-overlay.jpg",
7
- "assets/screenshot-qa.jpg"
8
- ]
1
+ [
2
+ "assets/screenshot-hero.jpg",
3
+ "assets/screenshot-shelf.jpg",
4
+ "assets/screenshot-reader.jpg",
5
+ "assets/screenshot-bilingual.jpg",
6
+ "assets/screenshot-overlay.jpg",
7
+ "assets/screenshot-qa.jpg"
8
+ ]
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The subset of the host primitives used by the workbench.
3
+ *
4
+ * Kept deliberately narrow: importing the package root and letting esbuild
5
+ * tree-shake keeps the vendor bundle small and avoids pulling in Markdown,
6
+ * Shiki and KaTeX for three controls.
7
+ */
8
+ export { Button } from '@deepseek-ai/dsh-client-ui-primitives/src/Button.tsx'
9
+ export { Input } from '@deepseek-ai/dsh-client-ui-primitives/src/Input.tsx'
10
+ export { Modal } from '@deepseek-ai/dsh-client-ui-primitives/src/Modal.tsx'
11
+ export { Menu } from '@deepseek-ai/dsh-client-ui-primitives/src/Menu.tsx'
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Minimal react/jsx-runtime shim for the host-primitives bundle.
5
+ *
6
+ * The primitives package is compiled against React's automatic runtime, but
7
+ * the DSH client module table exposes only `react`. This shim keeps the bundle
8
+ * on that single React instance instead of shipping a second copy.
9
+ */
10
+ const React = require('react')
11
+
12
+ function normalize(props, key) {
13
+ const next = props === null || props === undefined ? {} : { ...props }
14
+ if (key !== undefined && key !== null) next.key = key
15
+ return next
16
+ }
17
+
18
+ exports.Fragment = React.Fragment
19
+ exports.jsx = (type, props, key) => React.createElement(type, normalize(props, key))
20
+ exports.jsxs = (type, props, key) => React.createElement(type, normalize(props, key))
21
+ exports.jsxDEV = (type, props, key) => React.createElement(type, normalize(props, key))
@@ -1,80 +1,80 @@
1
- /**
2
- * PdfViewer — the unified reader face of the rewrite.
3
- *
4
- * One component owns: zoom, scroll container, page painting per layer, and the
5
- * mode layout (single / continuous / dual). Modes only choose which layers and
6
- * columns are rendered; painting and geometry stay identical, which is what the
7
- * old per-mode canvases kept getting wrong.
8
- *
9
- * This module is the extracted target: `client.js` will mount it once per
10
- * reader and per side preview, then the legacy paint paths can be deleted.
11
- *
12
- * Layers:
13
- * { kind: 'source', doc }
14
- * { kind: 'translation', doc }
15
- * { kind: 'masks', boxes } // reveal boxes over `translation`
16
- * { kind: 'blocks', blocks } // debug block overlay
17
- *
18
- * Geometry rules (from docs/READER-REWRITE.md):
19
- * - centered content uses `safe center`, so a zoomed page can still scroll to
20
- * its left edge;
21
- * - the overlay is ONE page-sized translation image clipped by a `clipPath` of
22
- * rectangle subpaths per mask (v0.49.2). A per-mask canvas drifted because a
23
- * zoomed page box is wider than the stage; `maskPageStyle` below is the old
24
- * per-canvas formula, kept only for reference;
25
- * - repainting is driven by (doc, page, scale, version), not by DOM mounting.
26
- */
27
-
28
- /** CSS injected once by the viewer's owner. */
29
- export const VIEWER_STYLE = `
30
- .mdv-root { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; min-height: 0; }
31
- .mdv-stage { flex: 1 1 auto; min-height: 0; overflow: auto; }
32
- .mdv-columns { display: flex; gap: 12px; width: 100%; height: 100%; }
33
- .mdv-column { flex: 1 1 0; min-width: 0; overflow: auto; }
34
- .mdv-page { position: relative; margin: 0 auto 18px; width: fit-content; }
35
- .mdv-canvas { display: block; }
36
- .mdv-layer { position: absolute; inset: 0; pointer-events: none; }
37
- .mdv-mask { position: absolute; overflow: hidden; border: 1px dashed rgba(40, 140, 235, .9); box-sizing: border-box; }
38
- .mdv-mask-page { position: absolute; max-width: none; }
39
- .mdv-block { position: absolute; border: 1px dashed rgba(235, 70, 70, .85); box-sizing: border-box; }
40
- .mdv-block[data-kind="heading"] { border-color: rgba(60, 130, 235, .95); }
41
- .mdv-block[data-kind="formula"] { border-color: rgba(40, 160, 90, .95); }
42
- `
43
-
44
- /**
45
- * Paint one page into a canvas at a given scale.
46
- * @param {object} options - doc, pageNumber, scale, canvas, signal.
47
- * @returns {Promise<void>} resolves when the page finished painting.
48
- */
49
- export async function paintPage(options) {
50
- const { doc, pageNumber, scale, canvas, signal } = options
51
- const page = await doc.getPage(pageNumber)
52
- if (signal !== undefined && signal.aborted) return
53
- const viewport = page.getViewport({ scale })
54
- let dpr = Math.min(2, Math.max(1, typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1))
55
- if (viewport.width * dpr > 8000 || viewport.height * dpr > 8000) dpr = 1
56
- canvas.width = Math.max(1, Math.floor(viewport.width * dpr))
57
- canvas.height = Math.max(1, Math.floor(viewport.height * dpr))
58
- canvas.style.width = `${Math.floor(viewport.width)}px`
59
- canvas.style.height = `${Math.floor(viewport.height)}px`
60
- await page.render({
61
- canvasContext: canvas.getContext('2d'),
62
- viewport,
63
- transform: dpr !== 1 ? [dpr, 0, 0, dpr, 0, 0] : undefined,
64
- }).promise
65
- }
66
-
67
- /**
68
- * Compute the geometry a per-mask translated canvas used to need.
69
- * @deprecated Superseded by the single-image `clipPath` overlay (v0.49.2).
70
- * @param {{ x: number, y: number, w: number, h: number }} box - normalized box.
71
- * @returns {{ left: string, top: string, width: string, height: string }} CSS percentages.
72
- */
73
- export function maskPageStyle(box) {
74
- return {
75
- left: `${-(box.x / box.w) * 100}%`,
76
- top: `${-(box.y / box.h) * 100}%`,
77
- width: `${100 / box.w}%`,
78
- height: `${100 / box.h}%`,
79
- }
80
- }
1
+ /**
2
+ * PdfViewer — the unified reader face of the rewrite.
3
+ *
4
+ * One component owns: zoom, scroll container, page painting per layer, and the
5
+ * mode layout (single / continuous / dual). Modes only choose which layers and
6
+ * columns are rendered; painting and geometry stay identical, which is what the
7
+ * old per-mode canvases kept getting wrong.
8
+ *
9
+ * This module is the extracted target: `client.js` will mount it once per
10
+ * reader and per side preview, then the legacy paint paths can be deleted.
11
+ *
12
+ * Layers:
13
+ * { kind: 'source', doc }
14
+ * { kind: 'translation', doc }
15
+ * { kind: 'masks', boxes } // reveal boxes over `translation`
16
+ * { kind: 'blocks', blocks } // debug block overlay
17
+ *
18
+ * Geometry rules (from docs/READER-REWRITE.md):
19
+ * - centered content uses `safe center`, so a zoomed page can still scroll to
20
+ * its left edge;
21
+ * - the overlay is ONE page-sized translation image clipped by a `clipPath` of
22
+ * rectangle subpaths per mask (v0.49.2). A per-mask canvas drifted because a
23
+ * zoomed page box is wider than the stage; `maskPageStyle` below is the old
24
+ * per-canvas formula, kept only for reference;
25
+ * - repainting is driven by (doc, page, scale, version), not by DOM mounting.
26
+ */
27
+
28
+ /** CSS injected once by the viewer's owner. */
29
+ export const VIEWER_STYLE = `
30
+ .mdv-root { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; min-height: 0; }
31
+ .mdv-stage { flex: 1 1 auto; min-height: 0; overflow: auto; }
32
+ .mdv-columns { display: flex; gap: 12px; width: 100%; height: 100%; }
33
+ .mdv-column { flex: 1 1 0; min-width: 0; overflow: auto; }
34
+ .mdv-page { position: relative; margin: 0 auto 18px; width: fit-content; }
35
+ .mdv-canvas { display: block; }
36
+ .mdv-layer { position: absolute; inset: 0; pointer-events: none; }
37
+ .mdv-mask { position: absolute; overflow: hidden; border: 1px dashed rgba(40, 140, 235, .9); box-sizing: border-box; }
38
+ .mdv-mask-page { position: absolute; max-width: none; }
39
+ .mdv-block { position: absolute; border: 1px dashed rgba(235, 70, 70, .85); box-sizing: border-box; }
40
+ .mdv-block[data-kind="heading"] { border-color: rgba(60, 130, 235, .95); }
41
+ .mdv-block[data-kind="formula"] { border-color: rgba(40, 160, 90, .95); }
42
+ `
43
+
44
+ /**
45
+ * Paint one page into a canvas at a given scale.
46
+ * @param {object} options - doc, pageNumber, scale, canvas, signal.
47
+ * @returns {Promise<void>} resolves when the page finished painting.
48
+ */
49
+ export async function paintPage(options) {
50
+ const { doc, pageNumber, scale, canvas, signal } = options
51
+ const page = await doc.getPage(pageNumber)
52
+ if (signal !== undefined && signal.aborted) return
53
+ const viewport = page.getViewport({ scale })
54
+ let dpr = Math.min(2, Math.max(1, typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1))
55
+ if (viewport.width * dpr > 8000 || viewport.height * dpr > 8000) dpr = 1
56
+ canvas.width = Math.max(1, Math.floor(viewport.width * dpr))
57
+ canvas.height = Math.max(1, Math.floor(viewport.height * dpr))
58
+ canvas.style.width = `${Math.floor(viewport.width)}px`
59
+ canvas.style.height = `${Math.floor(viewport.height)}px`
60
+ await page.render({
61
+ canvasContext: canvas.getContext('2d'),
62
+ viewport,
63
+ transform: dpr !== 1 ? [dpr, 0, 0, dpr, 0, 0] : undefined,
64
+ }).promise
65
+ }
66
+
67
+ /**
68
+ * Compute the geometry a per-mask translated canvas used to need.
69
+ * @deprecated Superseded by the single-image `clipPath` overlay (v0.49.2).
70
+ * @param {{ x: number, y: number, w: number, h: number }} box - normalized box.
71
+ * @returns {{ left: string, top: string, width: string, height: string }} CSS percentages.
72
+ */
73
+ export function maskPageStyle(box) {
74
+ return {
75
+ left: `${-(box.x / box.w) * 100}%`,
76
+ top: `${-(box.y / box.h) * 100}%`,
77
+ width: `${100 / box.w}%`,
78
+ height: `${100 / box.h}%`,
79
+ }
80
+ }
@@ -56,6 +56,8 @@ function vendorContentType(name) {
56
56
  if (name === 'fonts/zhhand/OFL.txt') return 'text/plain; charset=utf-8'
57
57
  if (/^rough\/[^/]+\.mjs$/.test(name)) return 'text/javascript; charset=utf-8'
58
58
  if (name === 'rough/LICENSE') return 'text/plain; charset=utf-8'
59
+ if (name === 'host-ui.cjs') return 'text/javascript; charset=utf-8'
60
+ if (name === 'host-ui.css') return 'text/css; charset=utf-8'
59
61
  return null
60
62
  }
61
63
 
@@ -125,7 +125,16 @@ export async function checkForUpdate(configuredProxy) {
125
125
  }
126
126
  const payload = JSON.parse(response.body.toString('utf8'))
127
127
  const latest = typeof payload.tag_name === 'string' ? payload.tag_name : ''
128
- return { ok: true, latest, url: RELEASES_URL, via: attempt.via }
128
+ const version = latest.replace(/^v/i, '')
129
+ const assets = Array.isArray(payload.assets) ? payload.assets : []
130
+ const zip = assets.find(asset => asset !== null && typeof asset === 'object'
131
+ && typeof asset.name === 'string' && asset.name.toLowerCase().endsWith('.zip')
132
+ && typeof asset.browser_download_url === 'string'
133
+ && /^https:\/\/github\.com\//.test(asset.browser_download_url))
134
+ const download = zip !== undefined && zip !== null
135
+ ? zip.browser_download_url
136
+ : (version === '' ? '' : `https://github.com/${REPO}/releases/download/${encodeURIComponent(latest)}/dsh-pdf-workbench-${encodeURIComponent(version)}.zip`)
137
+ return { ok: true, latest, version, url: RELEASES_URL, download, via: attempt.via }
129
138
  } catch (error) {
130
139
  lastError = error instanceof Error ? error.message : String(error)
131
140
  }
package/tools/AGENTS.md CHANGED
@@ -1,33 +1,33 @@
1
- # 数学课本工作区
2
-
3
- 用户会用**平常的话**下任务,不需要记任何编号。按意图直接做:不要先复述流程,不要列选项让用户选。
4
-
5
- ## 按意图分发
6
-
7
- | 用户说的话像这样 | 当作 | 动手前先读 |
8
- | --- | --- | --- |
9
- | 提取 / 原文 / 抄一下 / 给我这几页 / 转成 LaTeX | **提取原文** | `规范/01_文本提取.md` |
10
- | 为什么 / 怎么回事 / 这步怎么来的 / 看不懂 / 依据在哪 | **答疑** | `规范/02_答疑.md` |
11
- | 做一下 / 解一下 / 答案 / 对一下 / 习题 | **做习题** | `规范/03_习题解答.md` |
12
- | 其它:整理书库、拆书、查工具、改规范 | 直接办 | 按需读 |
13
-
14
- 判断规则:
15
-
16
- - 只给了书名 + 页码、没说干什么 → **默认提取原文**,末尾只问一句「要不要顺带讲讲这段」。
17
- - 一句话同时像答疑和习题(「这题为什么这样做」)→ 先讲原理,再给答案。
18
- - 真判断不了,直接问一句,**不要列 1/2/3/4 选项**。
19
- - `01`/`02`/`03`/`04` 仍可用,但只是可选别名,不必记。
20
-
21
- ## 硬规则(任何任务都适用)
22
-
23
- 1. **找书**:`工具\py.cmd 工具\pdfkit.py lookup <关键词> --chapter 4`(按章,首选)或 `--page 121`(按页)。
24
- **分片优先,分片没有才退回全本**。用户按章说事时用 `--chapter`,中文数字(四)也认;返回多本候选时补一个区分词(如「白皮书」)。
25
- 2. **页码是 PDF 物理页**(= 分片文件名里 `_97-138` 那种数字)。书上印刷页码可能差几页,交付时写 `物理 p.100(书页 92)`。
26
- 3. **公式**:行内 `$…$`;行间 `$$` 独占行。禁止 `\[` `\]` `\(` `\)`,也不用 `\begin{equation}` 之类环境。
27
- 4. 答疑和习题只在对话里输出,**不落文件**;提取输出**一个**代码块 + 三行以内说明。
28
- 5. 提取交付前必须跑 `pdfkit.py verify <文件> --tex`,拿到 `ok: true` 才算完。
29
- 6. 命令一律走 `工具\py.cmd`、`工具\node.cmd`(本机专用包装器,不进 git;别的机器用 `python`/`node` 直接跑)。
30
-
31
- ## 这里只是索引
32
-
33
- 上面够你起步。真要动手时读对应的 `规范/0X_*.md`——完整 SOP、故障对照表、成本与隐私都在那里。不要把规范全文抄进回答。
1
+ # 数学课本工作区
2
+
3
+ 用户会用**平常的话**下任务,不需要记任何编号。按意图直接做:不要先复述流程,不要列选项让用户选。
4
+
5
+ ## 按意图分发
6
+
7
+ | 用户说的话像这样 | 当作 | 动手前先读 |
8
+ | --- | --- | --- |
9
+ | 提取 / 原文 / 抄一下 / 给我这几页 / 转成 LaTeX | **提取原文** | `规范/01_文本提取.md` |
10
+ | 为什么 / 怎么回事 / 这步怎么来的 / 看不懂 / 依据在哪 | **答疑** | `规范/02_答疑.md` |
11
+ | 做一下 / 解一下 / 答案 / 对一下 / 习题 | **做习题** | `规范/03_习题解答.md` |
12
+ | 其它:整理书库、拆书、查工具、改规范 | 直接办 | 按需读 |
13
+
14
+ 判断规则:
15
+
16
+ - 只给了书名 + 页码、没说干什么 → **默认提取原文**,末尾只问一句「要不要顺带讲讲这段」。
17
+ - 一句话同时像答疑和习题(「这题为什么这样做」)→ 先讲原理,再给答案。
18
+ - 真判断不了,直接问一句,**不要列 1/2/3/4 选项**。
19
+ - `01`/`02`/`03`/`04` 仍可用,但只是可选别名,不必记。
20
+
21
+ ## 硬规则(任何任务都适用)
22
+
23
+ 1. **找书**:`工具\py.cmd 工具\pdfkit.py lookup <关键词> --chapter 4`(按章,首选)或 `--page 121`(按页)。
24
+ **分片优先,分片没有才退回全本**。用户按章说事时用 `--chapter`,中文数字(四)也认;返回多本候选时补一个区分词(如「白皮书」)。
25
+ 2. **页码是 PDF 物理页**(= 分片文件名里 `_97-138` 那种数字)。书上印刷页码可能差几页,交付时写 `物理 p.100(书页 92)`。
26
+ 3. **公式**:行内 `$…$`;行间 `$$` 独占行。禁止 `\[` `\]` `\(` `\)`,也不用 `\begin{equation}` 之类环境。
27
+ 4. 答疑和习题只在对话里输出,**不落文件**;提取输出**一个**代码块 + 三行以内说明。
28
+ 5. 提取交付前必须跑 `pdfkit.py verify <文件> --tex`,拿到 `ok: true` 才算完。
29
+ 6. 命令一律走 `工具\py.cmd`、`工具\node.cmd`(本机专用包装器,不进 git;别的机器用 `python`/`node` 直接跑)。
30
+
31
+ ## 这里只是索引
32
+
33
+ 上面够你起步。真要动手时读对应的 `规范/0X_*.md`——完整 SOP、故障对照表、成本与隐私都在那里。不要把规范全文抄进回答。