dsh-pdf-workbench 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +29 -7
  2. package/client.js +4585 -530
  3. package/docs/LAYOUT.md +56 -0
  4. package/docs/RELEASE.md +214 -57
  5. package/docs/TESTING.md +16 -0
  6. package/docs/ci.md +164 -0
  7. package/docs/copy/templates.md +110 -0
  8. package/docs/copy/terms.md +62 -0
  9. package/docs/decisions.md +444 -0
  10. package/docs/features.md +61 -0
  11. package/docs/feedback/.gitkeep +0 -0
  12. package/docs/requirements/.gitkeep +0 -0
  13. package/docs/requirements/2026-11-25-v1.5/346/224/271/350/277/233/351/234/200/346/261/202.md +622 -0
  14. package/docs/reviews/.gitkeep +0 -0
  15. package/docs/reviews/T-20261124-01.md +180 -0
  16. package/docs/reviews/T-20261124-03.md +85 -0
  17. package/docs/reviews/T-20261124-04.md +106 -0
  18. package/docs/reviews/T-20261124-05.md +94 -0
  19. package/docs/reviews/T-20261124-07.md +115 -0
  20. package/docs/reviews/T-20261124-08.md +292 -0
  21. package/docs/reviews/T-20261124-09.md +112 -0
  22. package/docs/reviews/T-20261124-10.md +112 -0
  23. package/docs/roles/ci.md +98 -0
  24. package/docs/roles/programmer.md +98 -0
  25. package/docs/roles/requirements.md +68 -0
  26. package/docs/tests/.gitkeep +0 -0
  27. package/docs/tests/T-20261124-01.md +146 -0
  28. package/docs/tests/T-20261124-03.md +81 -0
  29. package/docs/tests/T-20261124-04.md +51 -0
  30. package/docs/tests/T-20261124-05.md +51 -0
  31. package/docs/tests/T-20261124-07.md +60 -0
  32. package/docs/tests/T-20261124-08.md +61 -0
  33. package/docs/tests/T-20261124-09.md +60 -0
  34. package/docs/tests/T-20261124-10.md +61 -0
  35. package/docs/todo.md +835 -0
  36. package/index.js +337 -1
  37. package/package.json +1 -1
  38. package/src/host/backup.js +172 -33
  39. package/src/host/book-wizard.js +454 -0
  40. package/src/host/digest.js +4 -0
  41. package/src/host/engine.js +88 -0
  42. package/src/host/exports.js +159 -0
  43. package/src/host/http.js +28 -1
  44. package/src/host/imports.js +650 -0
  45. package/src/host/index-source.js +117 -11
  46. package/src/host/library-export.js +162 -0
  47. package/src/host/pdf-source.js +6 -2
  48. package/src/host/routes.js +1020 -120
  49. package/src/host/shortcut.js +238 -0
  50. package/src/host/storage.js +421 -0
  51. package/src/host/translate-blocks.js +49 -45
  52. package/src/host/translate-job.js +37 -10
  53. package/src/host/translate.js +19 -45
  54. package/src/host/translation-cache.js +209 -0
  55. package/src/host/typst-install.js +132 -0
  56. package/src/host/zip.js +486 -4
  57. package/tools/latex_to_typst.py +1353 -0
  58. package/tools/md2overlay.py +147 -152
  59. package/tools/md2overlay_typst.py +312 -0
  60. package/tools/md2typst.py +818 -0
  61. package/tools/overlay_layout.py +332 -0
  62. package/tools/pdf_blocks.py +82 -10
  63. package/tools/realign_overlay.py +4 -1
  64. package/tools/rebuild_overlay.py +3 -1
  65. package/tools/split_pdf.py +158 -0
  66. package/tools/typst_runtime.py +98 -0
  67. package/vendor/katex/LICENSE +21 -0
  68. package/vendor/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  69. package/vendor/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  70. package/vendor/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  71. package/vendor/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  72. package/vendor/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  73. package/vendor/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
  74. package/vendor/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  75. package/vendor/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
  76. package/vendor/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
  77. package/vendor/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  78. package/vendor/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
  79. package/vendor/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  80. package/vendor/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  81. package/vendor/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  82. package/vendor/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
  83. package/vendor/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  84. package/vendor/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  85. package/vendor/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  86. package/vendor/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  87. package/vendor/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  88. package/vendor/katex/katex.min.css +1 -0
  89. package/vendor/katex/katex.min.js +1 -0
  90. package//345/256/211/350/243/205/344/270/216/345/210/206/345/217/221.md +9 -1
  91. package/src/host/book-import.js +0 -98
@@ -26,7 +26,7 @@
26
26
  ## 方式 C:npm(推荐给市场与更新)
27
27
 
28
28
  ```bash
29
- dsh plugin add dsh-pdf-workbench@1.3.4
29
+ dsh plugin add dsh-pdf-workbench@1.5.0
30
30
  ```
31
31
 
32
32
  旧包 `dsh-pdf-math-desk` 已从 npm 删除,请用新包名 `dsh-pdf-workbench`。
@@ -52,3 +52,11 @@ dsh plugin add dsh-pdf-workbench@1.3.4
52
52
  - 工作台不写你的书库(只写自己的 `产物\`、`封面\` 和 `~/.dsh/pdfdesk/`)。
53
53
  - 阅读器基于 pdf.js;个别扫描版 PDF 的封面图可能缺字体资源,不影响正文阅读。
54
54
  - 拆分的“按章节”判断由人做:插件不识别书的内容,也不做 OCR。
55
+
56
+
57
+ ## 排版引擎(Typst,可选)
58
+
59
+ - v1.5 起默认识别 Typst,查找顺序:`MATH_DESK_TYPST` → 插件 `tools\typst\` → `%LOCALAPPDATA%\dsh-pdf-workbench\typst\` → PATH。
60
+ - 设置 → 环境 →「排版引擎」显示当前引擎、版本与回退原因;没有 Typst 时可一键下载(约 21 MB 压缩包,校验后装到 `%LOCALAPPDATA%`),装完重启 DSH 生效。
61
+ - 安装包不含 Typst;不装时用 TeX Live(xelatex)回退,功能不变,只是更慢(同一章 99 s 对 10.5 s)。
62
+ - 手动安装:`winget install --id Typst.Typst`,或把 `typst.exe` 放到上面任一位置。
@@ -1,98 +0,0 @@
1
- /**
2
- * Import a user-supplied PDF archive into one library folder. The archive is
3
- * read in memory (store/deflate), every entry is path-checked, and name clashes
4
- * follow the same merge/overwrite/skip policy as the migration import.
5
- * @module dsh-pdf-workbench/book-import
6
- */
7
-
8
- import { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises'
9
- import { basename, extname, join } from 'node:path'
10
-
11
- import { readZip, safeZipName } from './zip.js'
12
-
13
- /** Per-file ceiling for a book PDF. */
14
- export const MAX_BOOK_PDF_BYTES = 2 * 1024 * 1024 * 1024
15
- /** Total uncompressed ceiling for one archive. */
16
- export const MAX_BOOK_ARCHIVE_BYTES = 4 * 1024 * 1024 * 1024
17
-
18
- /**
19
- * Pick a free file name by appending `-1`, `-2`, ...
20
- * @param {string} dir - destination folder.
21
- * @param {string} name - wanted base name.
22
- * @returns {Promise<string>} an unused name.
23
- */
24
- async function freeName(dir, name) {
25
- const extension = extname(name)
26
- const stem = extension === '' ? name : name.slice(0, -extension.length)
27
- let candidate = name
28
- let counter = 0
29
- while (await stat(join(dir, candidate)).catch(() => null) !== null) {
30
- counter += 1
31
- candidate = `${stem}-${counter}${extension}`
32
- if (counter > 999) throw new Error(`同名文件太多:${name}`)
33
- }
34
- return candidate
35
- }
36
-
37
- /**
38
- * Import PDFs from a ZIP into `targetDir`.
39
- * @param {{ archivePath: string, targetDir: string, strategy?: 'merge'|'overwrite'|'skip' }} options - source, destination and conflict policy.
40
- * @returns {Promise<{ targetDir: string, imported: string[], renamed: string[], skipped: string[], warnings: string[] }>} the report.
41
- */
42
- export async function importBookArchive(options) {
43
- const strategy = options.strategy === 'overwrite' || options.strategy === 'skip' ? options.strategy : 'merge'
44
- const bytes = await readFile(options.archivePath)
45
- const entries = readZip(bytes)
46
- const targetDir = options.targetDir
47
- await mkdir(targetDir, { recursive: true })
48
- const report = { targetDir, imported: [], renamed: [], skipped: [], warnings: [] }
49
- let total = 0
50
- for (const [name, data] of entries) {
51
- const safe = safeZipName(name)
52
- if (extname(safe).toLowerCase() !== '.pdf') {
53
- report.warnings.push(`跳过非 PDF:${safe}`)
54
- continue
55
- }
56
- if (data.length > MAX_BOOK_PDF_BYTES) {
57
- report.warnings.push(`文件过大:${safe}`)
58
- continue
59
- }
60
- total += data.length
61
- if (total > MAX_BOOK_ARCHIVE_BYTES) {
62
- report.warnings.push('压缩包总大小超过 4 GB,剩余文件未导入')
63
- break
64
- }
65
- const wanted = basename(safe)
66
- const target = join(targetDir, wanted)
67
- const exists = await stat(target).catch(() => null)
68
- if (exists !== null && strategy === 'skip') {
69
- report.skipped.push(wanted)
70
- continue
71
- }
72
- if (exists !== null && strategy === 'merge') {
73
- const alternative = await freeName(targetDir, wanted)
74
- await writeFile(join(targetDir, alternative), data)
75
- report.renamed.push(`${wanted} → ${alternative}`)
76
- continue
77
- }
78
- await writeFile(target, data)
79
- report.imported.push(wanted)
80
- }
81
- return report
82
- }
83
-
84
- /**
85
- * List the PDFs already in a folder (used by the UI to show a target summary).
86
- * @param {string} dir - folder.
87
- * @returns {Promise<number>} count of PDFs.
88
- */
89
- export async function countPdfs(dir) {
90
- const names = await readdir(dir).catch(() => [])
91
- let count = 0
92
- for (const name of names) {
93
- if (extname(name).toLowerCase() !== '.pdf') continue
94
- const info = await stat(join(dir, name)).catch(() => null)
95
- if (info !== null && info.isFile()) count += 1
96
- }
97
- return count
98
- }