dsh-pdf-workbench 0.0.0-stage → 1.3.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 (277) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -2
  3. package/assets/screenshot-bilingual.jpg +0 -0
  4. package/assets/screenshot-hero.jpg +0 -0
  5. package/assets/screenshot-overlay.jpg +0 -0
  6. package/assets/screenshot-qa.jpg +0 -0
  7. package/assets/screenshot-reader.jpg +0 -0
  8. package/assets/screenshot-shelf.jpg +0 -0
  9. package/client.js +13438 -0
  10. package/cordis.patch.yml +13 -0
  11. package/docs/DETAIL.md +69 -0
  12. package/docs/READER-REWRITE.md +95 -0
  13. package/docs/ROADMAP.md +172 -0
  14. package/docs/SIDE-PREVIEW.md +271 -0
  15. package/docs/TESTING.md +109 -0
  16. package/docs/TRANSLATION.md +167 -0
  17. package/icon.svg +6 -0
  18. package/index.js +192 -0
  19. package/locale/en.json +7 -0
  20. package/locale/zh.json +7 -0
  21. package/package.json +64 -6
  22. package/samples/manifest.json +52 -0
  23. package/samples/test/serre_c01_p2-3.pdf +0 -0
  24. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c00_/345/211/215/347/275/256_/345/260/201/351/235/242/347/233/256/345/275/225.pdf +0 -0
  25. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c01_/347/254/2540/347/253/240_/345/257/274/350/257/273.pdf +0 -0
  26. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c02_/347/254/2541/347/253/240_/345/217/244/351/242/230_/345/255/231/345/255/220/347/256/227/347/273/217/345/210/260/347/247/246/344/271/235/351/237/266.pdf +0 -0
  27. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c03_/347/254/2542/347/253/240_/346/225/264/346/225/260/347/211/210/346/234/254.pdf +0 -0
  28. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c04_/347/254/2543/347/253/240_/347/216/257/350/256/272/347/211/210/346/234/254.pdf +0 -0
  29. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c05_/347/254/2544/347/253/240_/345/244/232/351/241/271/345/274/217/347/211/210/346/234/254.pdf +0 -0
  30. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c06_/347/254/2545/347/253/240_/347/276/244/350/256/272/347/211/210/346/234/254.pdf +0 -0
  31. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c07_/347/254/2546/347/253/240_/347/273/237/344/270/200/347/273/223/346/236/204.pdf +0 -0
  32. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c08_/347/254/2547/347/253/240_/345/233/236/346/234/233.pdf +0 -0
  33. package/samples//345/210/206/347/211/207//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206//344/270/255/345/233/275/345/211/251/344/275/231/345/256/232/347/220/206_c90_/351/231/204/345/275/225_/346/225/231/346/235/220/351/241/265/347/240/201/347/254/246/345/217/267/350/241/250/350/207/252/346/265/213.pdf +0 -0
  34. package/screenshots.json +8 -0
  35. package/src/client/viewer.js +80 -0
  36. package/src/host/annotations.js +145 -0
  37. package/src/host/artifacts.js +317 -0
  38. package/src/host/blocks.js +44 -0
  39. package/src/host/config.js +112 -0
  40. package/src/host/digest.js +156 -0
  41. package/src/host/environment.js +42 -0
  42. package/src/host/http.js +124 -0
  43. package/src/host/index-source.js +488 -0
  44. package/src/host/libraries.js +224 -0
  45. package/src/host/links.js +201 -0
  46. package/src/host/pdf-source.js +122 -0
  47. package/src/host/pending.js +166 -0
  48. package/src/host/pressure.js +137 -0
  49. package/src/host/purge.js +100 -0
  50. package/src/host/render.js +43 -0
  51. package/src/host/routes.js +1732 -0
  52. package/src/host/shelf-groups.js +109 -0
  53. package/src/host/state.js +128 -0
  54. package/src/host/toolkit.js +54 -0
  55. package/src/host/translate-blocks.js +132 -0
  56. package/src/host/translate-job.js +316 -0
  57. package/src/host/translate.js +94 -0
  58. package/src/host/update.js +134 -0
  59. package/tools/AGENTS.md +33 -0
  60. package/tools/README.md +138 -0
  61. package/tools/auto_chapters.py +122 -0
  62. package/tools/dsfile.mjs +198 -0
  63. package/tools/export_chapter.py +108 -0
  64. package/tools/export_page.py +91 -0
  65. package/tools/md2overlay.py +200 -0
  66. package/tools/md2tex.py +422 -0
  67. package/tools/pdf_blocks.py +110 -0
  68. package/tools/pdf_fontsize.py +20 -0
  69. package/tools/pdf_merge.py +15 -0
  70. package/tools/pdf_pagesizes.py +8 -0
  71. package/tools/pdf_raster.py +21 -0
  72. package/tools/pdfkit.py +896 -0
  73. package/tools/realign_overlay.py +248 -0
  74. package/tools/rebuild_overlay.py +55 -0
  75. package/tools/rename_chapters.py +93 -0
  76. package/tools//350/247/204/350/214/203/00_/345/205/261/345/220/214/347/272/246/345/256/232.md +142 -0
  77. package/tools//350/247/204/350/214/203/01_/346/226/207/346/234/254/346/217/220/345/217/226.md +204 -0
  78. package/tools//350/247/204/350/214/203/02_/347/255/224/347/226/221.md +61 -0
  79. package/tools//350/247/204/350/214/203/03_/344/271/240/351/242/230/350/247/243/347/255/224.md +77 -0
  80. 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 -0
  81. package/vendor/cmaps/78-EUC-H.bcmap +0 -0
  82. package/vendor/cmaps/78-EUC-V.bcmap +0 -0
  83. package/vendor/cmaps/78-H.bcmap +0 -0
  84. package/vendor/cmaps/78-RKSJ-H.bcmap +0 -0
  85. package/vendor/cmaps/78-RKSJ-V.bcmap +0 -0
  86. package/vendor/cmaps/78-V.bcmap +0 -0
  87. package/vendor/cmaps/78ms-RKSJ-H.bcmap +0 -0
  88. package/vendor/cmaps/78ms-RKSJ-V.bcmap +0 -0
  89. package/vendor/cmaps/83pv-RKSJ-H.bcmap +0 -0
  90. package/vendor/cmaps/90ms-RKSJ-H.bcmap +0 -0
  91. package/vendor/cmaps/90ms-RKSJ-V.bcmap +0 -0
  92. package/vendor/cmaps/90msp-RKSJ-H.bcmap +0 -0
  93. package/vendor/cmaps/90msp-RKSJ-V.bcmap +0 -0
  94. package/vendor/cmaps/90pv-RKSJ-H.bcmap +0 -0
  95. package/vendor/cmaps/90pv-RKSJ-V.bcmap +0 -0
  96. package/vendor/cmaps/Add-H.bcmap +0 -0
  97. package/vendor/cmaps/Add-RKSJ-H.bcmap +0 -0
  98. package/vendor/cmaps/Add-RKSJ-V.bcmap +0 -0
  99. package/vendor/cmaps/Add-V.bcmap +0 -0
  100. package/vendor/cmaps/Adobe-CNS1-0.bcmap +0 -0
  101. package/vendor/cmaps/Adobe-CNS1-1.bcmap +0 -0
  102. package/vendor/cmaps/Adobe-CNS1-2.bcmap +0 -0
  103. package/vendor/cmaps/Adobe-CNS1-3.bcmap +0 -0
  104. package/vendor/cmaps/Adobe-CNS1-4.bcmap +0 -0
  105. package/vendor/cmaps/Adobe-CNS1-5.bcmap +0 -0
  106. package/vendor/cmaps/Adobe-CNS1-6.bcmap +0 -0
  107. package/vendor/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  108. package/vendor/cmaps/Adobe-GB1-0.bcmap +0 -0
  109. package/vendor/cmaps/Adobe-GB1-1.bcmap +0 -0
  110. package/vendor/cmaps/Adobe-GB1-2.bcmap +0 -0
  111. package/vendor/cmaps/Adobe-GB1-3.bcmap +0 -0
  112. package/vendor/cmaps/Adobe-GB1-4.bcmap +0 -0
  113. package/vendor/cmaps/Adobe-GB1-5.bcmap +0 -0
  114. package/vendor/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  115. package/vendor/cmaps/Adobe-Japan1-0.bcmap +0 -0
  116. package/vendor/cmaps/Adobe-Japan1-1.bcmap +0 -0
  117. package/vendor/cmaps/Adobe-Japan1-2.bcmap +0 -0
  118. package/vendor/cmaps/Adobe-Japan1-3.bcmap +0 -0
  119. package/vendor/cmaps/Adobe-Japan1-4.bcmap +0 -0
  120. package/vendor/cmaps/Adobe-Japan1-5.bcmap +0 -0
  121. package/vendor/cmaps/Adobe-Japan1-6.bcmap +0 -0
  122. package/vendor/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  123. package/vendor/cmaps/Adobe-Korea1-0.bcmap +0 -0
  124. package/vendor/cmaps/Adobe-Korea1-1.bcmap +0 -0
  125. package/vendor/cmaps/Adobe-Korea1-2.bcmap +0 -0
  126. package/vendor/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  127. package/vendor/cmaps/B5-H.bcmap +0 -0
  128. package/vendor/cmaps/B5-V.bcmap +0 -0
  129. package/vendor/cmaps/B5pc-H.bcmap +0 -0
  130. package/vendor/cmaps/B5pc-V.bcmap +0 -0
  131. package/vendor/cmaps/CNS-EUC-H.bcmap +0 -0
  132. package/vendor/cmaps/CNS-EUC-V.bcmap +0 -0
  133. package/vendor/cmaps/CNS1-H.bcmap +0 -0
  134. package/vendor/cmaps/CNS1-V.bcmap +0 -0
  135. package/vendor/cmaps/CNS2-H.bcmap +0 -0
  136. package/vendor/cmaps/CNS2-V.bcmap +3 -0
  137. package/vendor/cmaps/ETHK-B5-H.bcmap +0 -0
  138. package/vendor/cmaps/ETHK-B5-V.bcmap +0 -0
  139. package/vendor/cmaps/ETen-B5-H.bcmap +0 -0
  140. package/vendor/cmaps/ETen-B5-V.bcmap +0 -0
  141. package/vendor/cmaps/ETenms-B5-H.bcmap +3 -0
  142. package/vendor/cmaps/ETenms-B5-V.bcmap +0 -0
  143. package/vendor/cmaps/EUC-H.bcmap +0 -0
  144. package/vendor/cmaps/EUC-V.bcmap +0 -0
  145. package/vendor/cmaps/Ext-H.bcmap +0 -0
  146. package/vendor/cmaps/Ext-RKSJ-H.bcmap +0 -0
  147. package/vendor/cmaps/Ext-RKSJ-V.bcmap +0 -0
  148. package/vendor/cmaps/Ext-V.bcmap +0 -0
  149. package/vendor/cmaps/GB-EUC-H.bcmap +0 -0
  150. package/vendor/cmaps/GB-EUC-V.bcmap +0 -0
  151. package/vendor/cmaps/GB-H.bcmap +4 -0
  152. package/vendor/cmaps/GB-V.bcmap +0 -0
  153. package/vendor/cmaps/GBK-EUC-H.bcmap +0 -0
  154. package/vendor/cmaps/GBK-EUC-V.bcmap +0 -0
  155. package/vendor/cmaps/GBK2K-H.bcmap +0 -0
  156. package/vendor/cmaps/GBK2K-V.bcmap +0 -0
  157. package/vendor/cmaps/GBKp-EUC-H.bcmap +0 -0
  158. package/vendor/cmaps/GBKp-EUC-V.bcmap +0 -0
  159. package/vendor/cmaps/GBT-EUC-H.bcmap +0 -0
  160. package/vendor/cmaps/GBT-EUC-V.bcmap +0 -0
  161. package/vendor/cmaps/GBT-H.bcmap +0 -0
  162. package/vendor/cmaps/GBT-V.bcmap +0 -0
  163. package/vendor/cmaps/GBTpc-EUC-H.bcmap +0 -0
  164. package/vendor/cmaps/GBTpc-EUC-V.bcmap +0 -0
  165. package/vendor/cmaps/GBpc-EUC-H.bcmap +0 -0
  166. package/vendor/cmaps/GBpc-EUC-V.bcmap +0 -0
  167. package/vendor/cmaps/H.bcmap +0 -0
  168. package/vendor/cmaps/HKdla-B5-H.bcmap +0 -0
  169. package/vendor/cmaps/HKdla-B5-V.bcmap +0 -0
  170. package/vendor/cmaps/HKdlb-B5-H.bcmap +0 -0
  171. package/vendor/cmaps/HKdlb-B5-V.bcmap +0 -0
  172. package/vendor/cmaps/HKgccs-B5-H.bcmap +0 -0
  173. package/vendor/cmaps/HKgccs-B5-V.bcmap +0 -0
  174. package/vendor/cmaps/HKm314-B5-H.bcmap +0 -0
  175. package/vendor/cmaps/HKm314-B5-V.bcmap +0 -0
  176. package/vendor/cmaps/HKm471-B5-H.bcmap +0 -0
  177. package/vendor/cmaps/HKm471-B5-V.bcmap +0 -0
  178. package/vendor/cmaps/HKscs-B5-H.bcmap +0 -0
  179. package/vendor/cmaps/HKscs-B5-V.bcmap +0 -0
  180. package/vendor/cmaps/Hankaku.bcmap +0 -0
  181. package/vendor/cmaps/Hiragana.bcmap +0 -0
  182. package/vendor/cmaps/KSC-EUC-H.bcmap +0 -0
  183. package/vendor/cmaps/KSC-EUC-V.bcmap +0 -0
  184. package/vendor/cmaps/KSC-H.bcmap +0 -0
  185. package/vendor/cmaps/KSC-Johab-H.bcmap +0 -0
  186. package/vendor/cmaps/KSC-Johab-V.bcmap +0 -0
  187. package/vendor/cmaps/KSC-V.bcmap +0 -0
  188. package/vendor/cmaps/KSCms-UHC-H.bcmap +0 -0
  189. package/vendor/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  190. package/vendor/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  191. package/vendor/cmaps/KSCms-UHC-V.bcmap +0 -0
  192. package/vendor/cmaps/KSCpc-EUC-H.bcmap +0 -0
  193. package/vendor/cmaps/KSCpc-EUC-V.bcmap +0 -0
  194. package/vendor/cmaps/Katakana.bcmap +0 -0
  195. package/vendor/cmaps/LICENSE.txt +36 -0
  196. package/vendor/cmaps/NWP-H.bcmap +0 -0
  197. package/vendor/cmaps/NWP-V.bcmap +0 -0
  198. package/vendor/cmaps/RKSJ-H.bcmap +0 -0
  199. package/vendor/cmaps/RKSJ-V.bcmap +0 -0
  200. package/vendor/cmaps/Roman.bcmap +0 -0
  201. package/vendor/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  202. package/vendor/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  203. package/vendor/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  204. package/vendor/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  205. package/vendor/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  206. package/vendor/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  207. package/vendor/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  208. package/vendor/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  209. package/vendor/cmaps/UniGB-UCS2-H.bcmap +0 -0
  210. package/vendor/cmaps/UniGB-UCS2-V.bcmap +0 -0
  211. package/vendor/cmaps/UniGB-UTF16-H.bcmap +0 -0
  212. package/vendor/cmaps/UniGB-UTF16-V.bcmap +0 -0
  213. package/vendor/cmaps/UniGB-UTF32-H.bcmap +0 -0
  214. package/vendor/cmaps/UniGB-UTF32-V.bcmap +0 -0
  215. package/vendor/cmaps/UniGB-UTF8-H.bcmap +0 -0
  216. package/vendor/cmaps/UniGB-UTF8-V.bcmap +0 -0
  217. package/vendor/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  218. package/vendor/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  219. package/vendor/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  220. package/vendor/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  221. package/vendor/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  222. package/vendor/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  223. package/vendor/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  224. package/vendor/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  225. package/vendor/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  226. package/vendor/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  227. package/vendor/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  228. package/vendor/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  229. package/vendor/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  230. package/vendor/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  231. package/vendor/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  232. package/vendor/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  233. package/vendor/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  234. package/vendor/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  235. package/vendor/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  236. package/vendor/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  237. package/vendor/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  238. package/vendor/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  239. package/vendor/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  240. package/vendor/cmaps/UniKS-UCS2-H.bcmap +0 -0
  241. package/vendor/cmaps/UniKS-UCS2-V.bcmap +0 -0
  242. package/vendor/cmaps/UniKS-UTF16-H.bcmap +0 -0
  243. package/vendor/cmaps/UniKS-UTF16-V.bcmap +0 -0
  244. package/vendor/cmaps/UniKS-UTF32-H.bcmap +0 -0
  245. package/vendor/cmaps/UniKS-UTF32-V.bcmap +0 -0
  246. package/vendor/cmaps/UniKS-UTF8-H.bcmap +0 -0
  247. package/vendor/cmaps/UniKS-UTF8-V.bcmap +0 -0
  248. package/vendor/cmaps/V.bcmap +0 -0
  249. package/vendor/cmaps/WP-Symbol.bcmap +0 -0
  250. package/vendor/fonts/excalifont/Excalifont-Regular-349fac6ca4700ffec595a7150a0d1e1d.woff2 +0 -0
  251. package/vendor/fonts/excalifont/Excalifont-Regular-3f2c5db56cc93c5a6873b1361d730c16.woff2 +0 -0
  252. package/vendor/fonts/excalifont/Excalifont-Regular-41b173a47b57366892116a575a43e2b6.woff2 +0 -0
  253. package/vendor/fonts/excalifont/Excalifont-Regular-623ccf21b21ef6b3a0d87738f77eb071.woff2 +0 -0
  254. package/vendor/fonts/excalifont/Excalifont-Regular-a88b72a24fb54c9f94e3b5fdaa7481c9.woff2 +0 -0
  255. package/vendor/fonts/excalifont/Excalifont-Regular-b9dcf9d2e50a1eaf42fc664b50a3fd0d.woff2 +0 -0
  256. package/vendor/fonts/excalifont/Excalifont-Regular-be310b9bcd4f1a43f571c46df7809174.woff2 +0 -0
  257. package/vendor/fonts/excalifont/OFL.txt +98 -0
  258. package/vendor/fonts/zhhand/OFL.txt +99 -0
  259. package/vendor/fonts/zhhand/Xiaolai-Regular.ttf +0 -0
  260. package/vendor/pdf.min.mjs +29 -0
  261. package/vendor/pdf.worker.min.mjs +29 -0
  262. package/vendor/pdfjs-LICENSE.txt +177 -0
  263. package/vendor/rough/LICENSE +21 -0
  264. package/vendor/rough/rough.mjs +1 -0
  265. package/vendor/wasm/LICENSE_JBIG2 +196 -0
  266. package/vendor/wasm/LICENSE_OPENJPEG +39 -0
  267. package/vendor/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  268. package/vendor/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  269. package/vendor/wasm/LICENSE_PDFJS_QCMS +19 -0
  270. package/vendor/wasm/LICENSE_QCMS +21 -0
  271. package/vendor/wasm/jbig2.wasm +0 -0
  272. package/vendor/wasm/jbig2_nowasm_fallback.js +15 -0
  273. package/vendor/wasm/openjpeg.wasm +0 -0
  274. package/vendor/wasm/openjpeg_nowasm_fallback.js +17 -0
  275. package/vendor/wasm/qcms_bg.wasm +0 -0
  276. package/vendor/wasm/quickjs-eval.wasm +0 -0
  277. package//345/256/211/350/243/205/344/270/216/345/210/206/345/217/221.md +54 -0
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Resolved plugin paths.
3
+ *
4
+ * Everything the plugin reads or writes is named here once, so the routes and
5
+ * the state store never assemble paths themselves. `libraryDir` comes from the
6
+ * bundle patch (or the user's patch layer); the rest derives from it.
7
+ *
8
+ * @module dsh-pdf-workbench/config
9
+ */
10
+ import { readFileSync } from 'node:fs'
11
+ import { homedir } from 'node:os'
12
+ import { dirname, join, resolve } from 'node:path'
13
+ import { fileURLToPath } from 'node:url'
14
+
15
+ /** This module's folder, so the shipped vendor files resolve in a link install. */
16
+ const HERE = dirname(fileURLToPath(import.meta.url))
17
+
18
+ /** The package version, read once for the update check. */
19
+ export const PLUGIN_VERSION = (() => {
20
+ try {
21
+ return String(JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version ?? '0.0.0')
22
+ } catch {
23
+ return '0.0.0'
24
+ }
25
+ })()
26
+
27
+ /** Default split-library root when the bundle patch names none (a fresh install). */
28
+ export const DEFAULT_LIBRARY_DIR = join(homedir(), '数学书库')
29
+
30
+ /** Folder under the library root that holds the chapter-split PDFs. */
31
+ const FRAGMENT_FOLDER = '分片'
32
+
33
+ /** Folder under the library root that holds the per-chapter produced files. */
34
+ const ARTIFACT_FOLDER = '产物'
35
+
36
+ /** Folder under the library root where the user drops book cover images. */
37
+ const COVER_FOLDER = '封面'
38
+
39
+ /** Index file name under the library root. */
40
+ const INDEX_FILE = '索引.json'
41
+
42
+ /** Plugin data folder name under `$DSH_HOME`. */
43
+ const DATA_FOLDER = 'pdfdesk'
44
+
45
+ /** Share of a session's context window at which "New" starts a continuation. */
46
+ export const DEFAULT_RESUME_RATIO = 0.85
47
+
48
+ /**
49
+ * Expand a leading `~` to the user's home directory.
50
+ * @param {string} value - user-supplied path.
51
+ * @returns {string} the expanded path.
52
+ */
53
+ function expandHome(value) {
54
+ if (value === '~') return homedir()
55
+ if (value.startsWith('~/') || value.startsWith('~\\')) return join(homedir(), value.slice(2))
56
+ return value
57
+ }
58
+
59
+ /**
60
+ * Read one optional string config field.
61
+ * @param {Record<string, unknown>} source - raw config mapping.
62
+ * @param {string} key - field name.
63
+ * @returns {string | undefined} the trimmed value, or undefined when absent.
64
+ */
65
+ function textField(source, key) {
66
+ const value = source[key]
67
+ if (typeof value !== 'string') return undefined
68
+ const trimmed = value.trim()
69
+ return trimmed === '' ? undefined : trimmed
70
+ }
71
+
72
+ /**
73
+ * Resolve every path the plugin uses.
74
+ * @param {unknown} rawConfig - the Loader row's `config` value.
75
+ * @returns {{ libraryDir: string, fragmentDir: string, artifactDir: string, coverDir: string, indexPath: string, dataDir: string, vendorDir: string, toolsDir: string, resumeRatio: number, statePath: string, pendingPath: string, linksPath: string, pressurePath: string, librariesPath: string }} resolved paths.
76
+ */
77
+ export function resolveConfig(rawConfig) {
78
+ const source = rawConfig !== null && typeof rawConfig === 'object' ? rawConfig : {}
79
+ const libraryDir = resolve(expandHome(textField(source, 'libraryDir') ?? DEFAULT_LIBRARY_DIR))
80
+ const fragmentDir = resolve(expandHome(textField(source, 'fragmentDir') ?? join(libraryDir, FRAGMENT_FOLDER)))
81
+ const artifactDir = resolve(expandHome(textField(source, 'artifactDir') ?? join(libraryDir, ARTIFACT_FOLDER)))
82
+ const coverDir = resolve(expandHome(textField(source, 'coverDir') ?? join(libraryDir, COVER_FOLDER)))
83
+ const indexPath = resolve(expandHome(textField(source, 'indexPath') ?? join(libraryDir, INDEX_FILE)))
84
+ const dshHome = textField(source, 'dshHome') ?? process.env.DSH_HOME ?? join(homedir(), '.dsh')
85
+ const dataDir = resolve(expandHome(textField(source, 'dataDir') ?? join(dshHome, DATA_FOLDER)))
86
+ // The reader's pdf.js build ships inside this package, next to `src/`.
87
+ const vendorDir = resolve(expandHome(textField(source, 'vendorDir') ?? join(HERE, '..', '..', 'vendor')))
88
+ const toolsDir = resolve(expandHome(textField(source, 'toolsDir') ?? join(HERE, '..', '..', 'tools')))
89
+ const samplesDir = resolve(expandHome(textField(source, 'samplesDir') ?? join(HERE, '..', '..', 'samples')))
90
+ const ratio = Number(source.resumeRatio)
91
+ const resumeRatio = Number.isFinite(ratio) && ratio > 0 && ratio < 1 ? ratio : DEFAULT_RESUME_RATIO
92
+ return {
93
+ libraryDir,
94
+ fragmentDir,
95
+ artifactDir,
96
+ coverDir,
97
+ indexPath,
98
+ dataDir,
99
+ vendorDir,
100
+ toolsDir,
101
+ samplesDir,
102
+ resumeRatio,
103
+ updateProxy: textField(source, 'updateProxy'),
104
+ deepseekApiKey: textField(source, 'deepseekApiKey') ?? process.env.DEEPSEEK_API_KEY,
105
+ statePath: join(dataDir, 'state.json'),
106
+ pendingPath: join(dataDir, 'pending.json'),
107
+ linksPath: join(dataDir, 'links.json'),
108
+ pressurePath: join(dataDir, 'pressure.json'),
109
+ shelvesPath: join(dataDir, 'shelves.json'),
110
+ librariesPath: join(dataDir, 'libraries.json'),
111
+ }
112
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Chapter digest: summarize a chapter's conversations into one outline.
3
+ *
4
+ * The workbench creates one conversation per chapter and mode and continues it
5
+ * until the context fills. Before that point, a digest of everything discussed
6
+ * under the chapter is worth carrying forward: it costs one model call over the
7
+ * chapter's transcripts, and saves far more than it spends in a continuation.
8
+ *
9
+ * The Host owns this because only it can read session logs and reach the model.
10
+ * The browser sends the session ids it shows under the chapter; the Host folds
11
+ * their text, asks the default model for an outline, and saves the result next to
12
+ * the chapter's produced files so it is readable and reusable.
13
+ *
14
+ * @module dsh-pdf-workbench/digest
15
+ */
16
+ import { mkdir, writeFile } from 'node:fs/promises'
17
+ import { join } from 'node:path'
18
+
19
+ /** Characters of transcript sent to the model; longer chapters are cut. */
20
+ export const MAX_TRANSCRIPT_CHARS = 120000
21
+
22
+ /** The outline the model is asked for. */
23
+ const SYSTEM = [
24
+ '你是一位数学学习助教,负责把一段学习对话压缩成可继续使用的提纲。',
25
+ '只输出 Markdown,不要客套话。结构固定为:',
26
+ '## 本章范围(读了哪几页 / 哪些主题)',
27
+ '## 已解决的问题(要点式,保留关键结论与公式)',
28
+ '## 仍未解决的问题(明确列出)',
29
+ '## 下一步建议(简短)',
30
+ '忠实于对话,不要编造对话里没有的结论;公式用 $...$ 或 $$...$$。',
31
+ ].join('\n')
32
+
33
+ /**
34
+ * Pull readable text out of one stored session log.
35
+ * @param {{ events?: object[] }} log - `sessionQuery.readSession` result.
36
+ * @returns {string} the transcript, oldest first.
37
+ */
38
+ export function transcriptOf(log) {
39
+ if (log === null || typeof log !== 'object' || !Array.isArray(log.events)) return ''
40
+ const lines = []
41
+ for (const event of log.events) {
42
+ if (event === null || typeof event !== 'object') continue
43
+ const role = event.type === 'user/message' ? '用户' : event.type === 'assistant/message' ? '助手' : ''
44
+ if (role === '') continue
45
+ const content = event.message !== null && typeof event.message === 'object' && Array.isArray(event.message.content)
46
+ ? event.message.content
47
+ : Array.isArray(event.content) ? event.content : []
48
+ const text = content
49
+ .filter(block => block !== null && typeof block === 'object' && block.type === 'text' && typeof block.text === 'string')
50
+ .map(block => block.text.trim())
51
+ .filter(text => text !== '')
52
+ .join('\n')
53
+ if (text === '') continue
54
+ lines.push(`${role}:${text}`)
55
+ }
56
+ return lines.join('\n\n')
57
+ }
58
+
59
+ /**
60
+ * Fold several sessions into one bounded transcript.
61
+ * @param {string[]} sessionIds - sessions to read.
62
+ * @param {(id: string) => Promise<{ events?: object[] }>} readSession - host reader.
63
+ * @param {number} [maxChars] - character budget.
64
+ * @returns {Promise<{ text: string, used: string[], dropped: number }>} the transcript and what fit.
65
+ */
66
+ export async function collectTranscript(sessionIds, readSession, maxChars = MAX_TRANSCRIPT_CHARS) {
67
+ const parts = []
68
+ const used = []
69
+ let total = 0
70
+ let dropped = 0
71
+ for (const id of sessionIds) {
72
+ let log
73
+ try {
74
+ log = await readSession(id)
75
+ } catch {
76
+ dropped += 1
77
+ continue
78
+ }
79
+ const text = transcriptOf(log)
80
+ if (text === '') {
81
+ dropped += 1
82
+ continue
83
+ }
84
+ if (total + text.length > maxChars) {
85
+ // Keep a head slice of the overflow rather than dropping it whole: early
86
+ // messages usually define the chapter's question.
87
+ const room = Math.max(0, maxChars - total)
88
+ if (room > 2000) {
89
+ parts.push(text.slice(0, room))
90
+ used.push(id)
91
+ }
92
+ dropped += 1
93
+ break
94
+ }
95
+ parts.push(text)
96
+ used.push(id)
97
+ total += text.length
98
+ }
99
+ return { text: parts.join('\n\n---\n\n'), used, dropped }
100
+ }
101
+
102
+ /**
103
+ * Ask the model for the outline.
104
+ * @param {{ provider: string, model: string }} selection - default model.
105
+ * @param {(request: object) => AsyncIterable<object>} stream - `llm.stream`.
106
+ * @param {{ bookTitle: string, code: string, chapterTitle: string, mode?: string, transcript: string }} input - what is being summarized.
107
+ * @returns {Promise<string>} the outline text.
108
+ */
109
+ export async function summarize(selection, stream, input) {
110
+ const scope = input.mode === undefined || input.mode === ''
111
+ ? '本章全部对话'
112
+ : `本章「${input.mode}」这一组对话`
113
+ const prompt = [
114
+ `书:${input.bookTitle}`,
115
+ `章节:${input.code} ${input.chapterTitle}`,
116
+ `范围:${scope}`,
117
+ '',
118
+ '以下是这些对话的原文(可能被截断):',
119
+ '',
120
+ input.transcript,
121
+ ].join('\n')
122
+ let text = ''
123
+ const chunks = stream({
124
+ provider: selection.provider,
125
+ model: selection.model,
126
+ system: SYSTEM,
127
+ messages: [{ role: 'user', content: [{ type: 'text', text: prompt }] }],
128
+ maxTokens: 2400,
129
+ })
130
+ for await (const chunk of chunks) {
131
+ if (chunk === null || typeof chunk !== 'object') continue
132
+ if (chunk.type === 'text-delta' && typeof chunk.text === 'string') text += chunk.text
133
+ else if (chunk.type === 'finish' && chunk.reason !== undefined && chunk.reason.kind === 'error') {
134
+ const failure = chunk.reason.failure
135
+ throw new Error(failure !== undefined && typeof failure.message === 'string' ? failure.message : '模型调用失败')
136
+ }
137
+ }
138
+ return text.trim()
139
+ }
140
+
141
+ /**
142
+ * Save the outline beside the chapter's produced files.
143
+ * @param {{ artifactDir: string }} config - resolved paths.
144
+ * @param {string} bookId - catalog book id.
145
+ * @param {string} code - chapter code.
146
+ * @param {string} mode - `all` or a mode key, used in the file name.
147
+ * @param {string} text - outline Markdown.
148
+ * @returns {Promise<string>} the absolute file path.
149
+ */
150
+ export async function saveDigest(config, bookId, code, mode, text) {
151
+ const dir = join(config.artifactDir, bookId, code)
152
+ await mkdir(dir, { recursive: true })
153
+ const path = join(dir, `提纲-${mode}.md`)
154
+ await writeFile(path, `${text}\n`, 'utf8')
155
+ return path
156
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Detect the optional typesetting environment once per bootstrap.
3
+ *
4
+ * The plugin never installs TeX or Python: Markdown-to-PDF is an optional
5
+ * feature, so the browser hides its buttons until both are present.
6
+ * @module dsh-pdf-workbench/environment
7
+ */
8
+ import { accessSync, constants } from 'node:fs'
9
+ import { delimiter, join } from 'node:path'
10
+
11
+ /** Where TinyTeX/TeX Live commonly land when not on PATH. */
12
+ const TEX_DIRS = [
13
+ 'C:\\texlive\\2025\\bin\\windows',
14
+ 'C:\\texlive\\2024\\bin\\windows',
15
+ 'C:\\Program Files\\MiKTeX\\miktex\\bin\\x64',
16
+ join(process.env.LOCALAPPDATA ?? '', 'Programs', 'MiKTeX', 'miktex', 'bin', 'x64'),
17
+ ]
18
+
19
+ function onPath(names, extraDirs = []) {
20
+ const dirs = [...(process.env.PATH ?? '').split(delimiter), ...extraDirs].filter(Boolean)
21
+ for (const dir of dirs) {
22
+ for (const name of names) {
23
+ try {
24
+ accessSync(join(dir, name), constants.X_OK)
25
+ return true
26
+ } catch {
27
+ // try the next candidate
28
+ }
29
+ }
30
+ }
31
+ return false
32
+ }
33
+
34
+ /**
35
+ * @returns {{ python: boolean, tex: boolean }} which optional tools exist.
36
+ */
37
+ export function detectEnvironment() {
38
+ return {
39
+ python: onPath(['python.exe', 'python', 'py.exe', 'py']),
40
+ tex: onPath(['xelatex.exe', 'xelatex'], TEX_DIRS),
41
+ }
42
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * HTTP plumbing for the `/pdfdesk/*` surface.
3
+ *
4
+ * Mirrors the guards an installed plugin uses: loopback-only reads, same-origin
5
+ * mutations, a tiny JSON body cap, and `{ ok, error }` envelopes.
6
+ *
7
+ * @module dsh-pdf-workbench/http
8
+ */
9
+
10
+ /** Request bodies are a position, not data; anything larger is a client bug. */
11
+ const MAX_BODY_BYTES = 16 * 1024
12
+
13
+ /**
14
+ * Whether the request came from the local machine.
15
+ * @param {import('node:http').IncomingMessage} request - the inbound request.
16
+ * @returns {boolean} true for loopback peers.
17
+ */
18
+ export function isLoopback(request) {
19
+ const address = request.socket?.remoteAddress
20
+ if (address === undefined) return true
21
+ return address === '127.0.0.1'
22
+ || address === '::1'
23
+ || address === '::ffff:127.0.0.1'
24
+ || address.startsWith('127.')
25
+ }
26
+
27
+ /**
28
+ * Same-origin guard for mutations. A missing Origin is allowed (the Desktop
29
+ * shell strips it); a present Origin must match the Host header.
30
+ * @param {import('node:http').IncomingMessage} request - the inbound request.
31
+ * @returns {boolean} true when the request may mutate.
32
+ */
33
+ export function isSameOrigin(request) {
34
+ const origin = request.headers.origin
35
+ if (typeof origin !== 'string' || origin === '') return true
36
+ const host = request.headers.host
37
+ if (typeof host !== 'string' || host === '') return false
38
+ try {
39
+ return new URL(origin).host === host
40
+ } catch {
41
+ return false
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Send one JSON response.
47
+ * @param {import('node:http').ServerResponse} response - the outbound response.
48
+ * @param {number} status - HTTP status.
49
+ * @param {unknown} payload - JSON-serializable body.
50
+ * @returns {void}
51
+ */
52
+ export function sendJson(response, status, payload) {
53
+ if (response.writableEnded || response.destroyed) return
54
+ const body = JSON.stringify(payload)
55
+ response.writeHead(status, {
56
+ 'content-type': 'application/json; charset=utf-8',
57
+ 'cache-control': 'no-store',
58
+ 'content-length': Buffer.byteLength(body),
59
+ })
60
+ response.end(body)
61
+ }
62
+
63
+ /**
64
+ * Send one binary response (the reader's PDF bytes, the toolkit archive).
65
+ * @param {import('node:http').ServerResponse} response - the outbound response.
66
+ * @param {number} status - HTTP status.
67
+ * @param {Buffer} body - the bytes.
68
+ * @param {string} contentType - the media type.
69
+ * @param {string} [disposition] - optional `content-disposition` value.
70
+ * @returns {void}
71
+ */
72
+ export function sendBytes(response, status, body, contentType, disposition) {
73
+ if (response.writableEnded || response.destroyed) return
74
+ const headers = {
75
+ 'content-type': contentType,
76
+ 'cache-control': 'no-store',
77
+ 'accept-ranges': 'none',
78
+ 'content-length': body.length,
79
+ }
80
+ if (disposition !== undefined) headers['content-disposition'] = disposition
81
+ response.writeHead(status, headers)
82
+ response.end(body)
83
+ }
84
+
85
+ /**
86
+ * Send one failure envelope.
87
+ * @param {import('node:http').ServerResponse} response - the outbound response.
88
+ * @param {number} status - HTTP status.
89
+ * @param {string} code - stable machine code.
90
+ * @param {string} message - human-readable message.
91
+ * @returns {void}
92
+ */
93
+ export function fail(response, status, code, message) {
94
+ sendJson(response, status, { ok: false, error: { code, message } })
95
+ }
96
+
97
+ /**
98
+ * Read a bounded JSON request body.
99
+ * @param {import('node:http').IncomingMessage} request - the inbound request.
100
+ * @returns {Promise<unknown>} the parsed body.
101
+ */
102
+ export function readJson(request, limit = MAX_BODY_BYTES) {
103
+ return new Promise((resolve, reject) => {
104
+ const chunks = []
105
+ let size = 0
106
+ request.on('data', chunk => {
107
+ size += chunk.length
108
+ if (size > limit) {
109
+ reject(new Error('请求体过大'))
110
+ request.destroy()
111
+ return
112
+ }
113
+ chunks.push(chunk)
114
+ })
115
+ request.on('end', () => {
116
+ try {
117
+ resolve(JSON.parse(Buffer.concat(chunks).toString('utf8')))
118
+ } catch {
119
+ reject(new Error('请求体不是合法 JSON'))
120
+ }
121
+ })
122
+ request.on('error', reject)
123
+ })
124
+ }