@open-press/cli 0.8.0 → 1.1.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 (250) hide show
  1. package/README.md +33 -23
  2. package/dist/cli.js +320 -252
  3. package/package.json +9 -8
  4. package/template/core/AGENTS.md +0 -126
  5. package/template/core/CHANGELOG.md +0 -215
  6. package/template/core/README.md +0 -40
  7. package/template/core/engine/cli.mjs +0 -96
  8. package/template/core/engine/commands/_shared.mjs +0 -177
  9. package/template/core/engine/commands/deploy.mjs +0 -31
  10. package/template/core/engine/commands/dev.mjs +0 -49
  11. package/template/core/engine/commands/doctor.mjs +0 -229
  12. package/template/core/engine/commands/export.mjs +0 -8
  13. package/template/core/engine/commands/init.mjs +0 -24
  14. package/template/core/engine/commands/inspect.mjs +0 -35
  15. package/template/core/engine/commands/pdf.mjs +0 -26
  16. package/template/core/engine/commands/preview.mjs +0 -26
  17. package/template/core/engine/commands/render.mjs +0 -17
  18. package/template/core/engine/commands/replace.mjs +0 -41
  19. package/template/core/engine/commands/search.mjs +0 -33
  20. package/template/core/engine/commands/typecheck.mjs +0 -5
  21. package/template/core/engine/commands/upgrade.mjs +0 -159
  22. package/template/core/engine/commands/validate.mjs +0 -17
  23. package/template/core/engine/document-export.mjs +0 -15
  24. package/template/core/engine/init.mjs +0 -90
  25. package/template/core/engine/output/chrome-pdf.d.mts +0 -34
  26. package/template/core/engine/output/chrome-pdf.mjs +0 -358
  27. package/template/core/engine/output/deploy-sync.mjs +0 -15
  28. package/template/core/engine/output/fonts.mjs +0 -62
  29. package/template/core/engine/output/katex-assets.mjs +0 -45
  30. package/template/core/engine/output/page-block.mjs +0 -30
  31. package/template/core/engine/output/pdf-media.mjs +0 -45
  32. package/template/core/engine/output/public-assets.mjs +0 -19
  33. package/template/core/engine/output/static-server.mjs +0 -532
  34. package/template/core/engine/react/caption-numbering.mjs +0 -73
  35. package/template/core/engine/react/comment-endpoint.d.mts +0 -11
  36. package/template/core/engine/react/comment-endpoint.mjs +0 -102
  37. package/template/core/engine/react/comment-marker.mjs +0 -374
  38. package/template/core/engine/react/document-entry.mjs +0 -324
  39. package/template/core/engine/react/document-export.mjs +0 -373
  40. package/template/core/engine/react/http-json.mjs +0 -24
  41. package/template/core/engine/react/mdx-compile.mjs +0 -599
  42. package/template/core/engine/react/measurement-css.mjs +0 -136
  43. package/template/core/engine/react/object-entities.mjs +0 -119
  44. package/template/core/engine/react/pagination/allocator.mjs +0 -122
  45. package/template/core/engine/react/pagination/regions.mjs +0 -81
  46. package/template/core/engine/react/pagination-constants.mjs +0 -3
  47. package/template/core/engine/react/pagination.mjs +0 -9
  48. package/template/core/engine/react/pipeline/allocate.mjs +0 -251
  49. package/template/core/engine/react/pipeline/final-render.mjs +0 -94
  50. package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -302
  51. package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
  52. package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
  53. package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
  54. package/template/core/engine/react/section-css.mjs +0 -56
  55. package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
  56. package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
  57. package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
  58. package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
  59. package/template/core/engine/react/style-discovery.mjs +0 -142
  60. package/template/core/engine/runtime/config.d.mts +0 -40
  61. package/template/core/engine/runtime/config.mjs +0 -175
  62. package/template/core/engine/runtime/file-utils.mjs +0 -106
  63. package/template/core/engine/runtime/file-walk.mjs +0 -22
  64. package/template/core/engine/runtime/inspection.mjs +0 -328
  65. package/template/core/engine/runtime/issue-report.mjs +0 -44
  66. package/template/core/engine/runtime/path-utils.mjs +0 -20
  67. package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
  68. package/template/core/engine/runtime/source-text-tools.mjs +0 -832
  69. package/template/core/engine/runtime/source-workspace.mjs +0 -159
  70. package/template/core/engine/runtime/validation.mjs +0 -174
  71. package/template/core/index.html +0 -13
  72. package/template/core/openpress.config.mjs +0 -12
  73. package/template/core/package.json +0 -91
  74. package/template/core/src/main.tsx +0 -16
  75. package/template/core/src/openpress/app/OpenPressApp.tsx +0 -140
  76. package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -94
  77. package/template/core/src/openpress/app/index.ts +0 -2
  78. package/template/core/src/openpress/core/Frame.tsx +0 -78
  79. package/template/core/src/openpress/core/FrameContext.tsx +0 -24
  80. package/template/core/src/openpress/core/MdxArea.tsx +0 -34
  81. package/template/core/src/openpress/core/Press.tsx +0 -34
  82. package/template/core/src/openpress/core/cn.ts +0 -4
  83. package/template/core/src/openpress/core/index.tsx +0 -40
  84. package/template/core/src/openpress/core/primitives.tsx +0 -44
  85. package/template/core/src/openpress/core/types.ts +0 -191
  86. package/template/core/src/openpress/core/useSource.ts +0 -28
  87. package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
  88. package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
  89. package/template/core/src/openpress/document-model/documentTypes.ts +0 -138
  90. package/template/core/src/openpress/document-model/index.ts +0 -6
  91. package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -51
  92. package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
  93. package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
  94. package/template/core/src/openpress/manuscript/index.tsx +0 -238
  95. package/template/core/src/openpress/mdx/index.ts +0 -88
  96. package/template/core/src/openpress/numbering/index.ts +0 -294
  97. package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
  98. package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
  99. package/template/core/src/openpress/reader/index.ts +0 -10
  100. package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
  101. package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
  102. package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
  103. package/template/core/src/openpress/reader/readerScroll.ts +0 -92
  104. package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
  105. package/template/core/src/openpress/reader/readerTypes.ts +0 -4
  106. package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
  107. package/template/core/src/openpress/reader/usePanelState.ts +0 -56
  108. package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
  109. package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
  110. package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
  111. package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
  112. package/template/core/src/openpress/shared/Panel.tsx +0 -77
  113. package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
  114. package/template/core/src/openpress/shared/index.ts +0 -4
  115. package/template/core/src/openpress/shared/numberUtils.ts +0 -3
  116. package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
  117. package/template/core/src/openpress/workbench/Workbench.tsx +0 -407
  118. package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
  119. package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
  120. package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
  121. package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
  122. package/template/core/src/openpress/workbench/actions/index.ts +0 -5
  123. package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
  124. package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
  125. package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
  126. package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
  127. package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
  128. package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
  129. package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
  130. package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
  131. package/template/core/src/openpress/workbench/document/index.ts +0 -10
  132. package/template/core/src/openpress/workbench/index.ts +0 -2
  133. package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
  134. package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
  135. package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
  136. package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
  137. package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
  138. package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -248
  139. package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
  140. package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
  141. package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
  142. package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
  143. package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -76
  144. package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
  145. package/template/core/src/openpress/workbench/panels/index.ts +0 -3
  146. package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -523
  147. package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
  148. package/template/core/src/openpress/workbench/project/index.ts +0 -2
  149. package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
  150. package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
  151. package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
  152. package/template/core/src/openpress/workbench/shell/index.ts +0 -1
  153. package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
  154. package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
  155. package/template/core/src/styles/openpress/app-shell.css +0 -251
  156. package/template/core/src/styles/openpress/media-workspace.css +0 -230
  157. package/template/core/src/styles/openpress/print-route.css +0 -184
  158. package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
  159. package/template/core/src/styles/openpress/public-viewer.css +0 -688
  160. package/template/core/src/styles/openpress/reader-runtime.css +0 -980
  161. package/template/core/src/styles/openpress/responsive.css +0 -245
  162. package/template/core/src/styles/openpress/workbench-panels.css +0 -594
  163. package/template/core/src/styles/openpress/workbench.css +0 -1255
  164. package/template/core/src/styles/openpress.css +0 -14
  165. package/template/core/src/vite-env.d.ts +0 -9
  166. package/template/core/tsconfig.json +0 -40
  167. package/template/core/vite.config.ts +0 -584
  168. package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +0 -35
  169. package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +0 -50
  170. package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +0 -47
  171. package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +0 -26
  172. package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +0 -32
  173. package/template/packs/academic-paper/document/components/ChapterOpenerVisual/index.tsx +0 -76
  174. package/template/packs/academic-paper/document/components/Page.tsx +0 -60
  175. package/template/packs/academic-paper/document/components/TokenSwatchGrid/index.tsx +0 -46
  176. package/template/packs/academic-paper/document/components/TokenSwatchGrid/style.css +0 -63
  177. package/template/packs/academic-paper/document/components/TypeSpecimen/index.tsx +0 -38
  178. package/template/packs/academic-paper/document/components/TypeSpecimen/style.css +0 -111
  179. package/template/packs/academic-paper/document/design.md +0 -279
  180. package/template/packs/academic-paper/document/index.tsx +0 -123
  181. package/template/packs/academic-paper/document/media/README.md +0 -13
  182. package/template/packs/academic-paper/document/media/figure-placeholder.svg +0 -9
  183. package/template/packs/academic-paper/document/openpress.config.mjs +0 -26
  184. package/template/packs/academic-paper/document/theme/README.md +0 -11
  185. package/template/packs/academic-paper/document/theme/base/page-contract.css +0 -522
  186. package/template/packs/academic-paper/document/theme/base/print.css +0 -93
  187. package/template/packs/academic-paper/document/theme/base/typography.css +0 -333
  188. package/template/packs/academic-paper/document/theme/fonts.css +0 -3
  189. package/template/packs/academic-paper/document/theme/page-surfaces/back-cover.css +0 -43
  190. package/template/packs/academic-paper/document/theme/page-surfaces/chapter-opener.css +0 -205
  191. package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +0 -294
  192. package/template/packs/academic-paper/document/theme/page-surfaces/toc.css +0 -149
  193. package/template/packs/academic-paper/document/theme/patterns/_chart-frame.css +0 -49
  194. package/template/packs/academic-paper/document/theme/patterns/figure-grid.css +0 -68
  195. package/template/packs/academic-paper/document/theme/patterns/table-utilities.css +0 -66
  196. package/template/packs/academic-paper/document/theme/shell/reader-controls.css +0 -761
  197. package/template/packs/academic-paper/document/theme/tokens.css +0 -80
  198. package/template/packs/academic-paper/openpress.config.mjs +0 -5
  199. package/template/packs/claude-document/document/chapters/01-document-shape/content/01-document-shape.mdx +0 -51
  200. package/template/packs/claude-document/document/chapters/02-review-loop/content/01-review-loop.mdx +0 -31
  201. package/template/packs/claude-document/document/components/ChapterOpenerVisual.tsx +0 -96
  202. package/template/packs/claude-document/document/components/Page.tsx +0 -37
  203. package/template/packs/claude-document/document/design.md +0 -142
  204. package/template/packs/claude-document/document/index.tsx +0 -94
  205. package/template/packs/claude-document/document/media/README.md +0 -13
  206. package/template/packs/claude-document/document/openpress.config.mjs +0 -26
  207. package/template/packs/claude-document/document/theme/README.md +0 -15
  208. package/template/packs/claude-document/document/theme/base/page-contract.css +0 -525
  209. package/template/packs/claude-document/document/theme/base/print.css +0 -93
  210. package/template/packs/claude-document/document/theme/base/typography.css +0 -612
  211. package/template/packs/claude-document/document/theme/fonts.css +0 -4
  212. package/template/packs/claude-document/document/theme/page-surfaces/back-cover.css +0 -72
  213. package/template/packs/claude-document/document/theme/page-surfaces/chapter-opener.css +0 -236
  214. package/template/packs/claude-document/document/theme/page-surfaces/cover.css +0 -309
  215. package/template/packs/claude-document/document/theme/page-surfaces/toc.css +0 -225
  216. package/template/packs/claude-document/document/theme/patterns/_chart-frame.css +0 -53
  217. package/template/packs/claude-document/document/theme/patterns/figure-grid.css +0 -68
  218. package/template/packs/claude-document/document/theme/patterns/table-utilities.css +0 -66
  219. package/template/packs/claude-document/document/theme/shell/reader-controls.css +0 -789
  220. package/template/packs/claude-document/document/theme/tokens.css +0 -89
  221. package/template/packs/claude-document/openpress.config.mjs +0 -5
  222. package/template/packs/editorial-monograph/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +0 -31
  223. package/template/packs/editorial-monograph/document/chapters/02-workflow/content/01-workflow.mdx +0 -89
  224. package/template/packs/editorial-monograph/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +0 -51
  225. package/template/packs/editorial-monograph/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +0 -39
  226. package/template/packs/editorial-monograph/document/components/ChapterOpenerVisual/index.tsx +0 -76
  227. package/template/packs/editorial-monograph/document/components/Page.tsx +0 -37
  228. package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/index.tsx +0 -46
  229. package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/style.css +0 -63
  230. package/template/packs/editorial-monograph/document/components/TypeSpecimen/index.tsx +0 -38
  231. package/template/packs/editorial-monograph/document/components/TypeSpecimen/style.css +0 -111
  232. package/template/packs/editorial-monograph/document/design.md +0 -279
  233. package/template/packs/editorial-monograph/document/index.tsx +0 -97
  234. package/template/packs/editorial-monograph/document/media/README.md +0 -13
  235. package/template/packs/editorial-monograph/document/openpress.config.mjs +0 -26
  236. package/template/packs/editorial-monograph/document/theme/README.md +0 -11
  237. package/template/packs/editorial-monograph/document/theme/base/page-contract.css +0 -505
  238. package/template/packs/editorial-monograph/document/theme/base/print.css +0 -93
  239. package/template/packs/editorial-monograph/document/theme/base/typography.css +0 -336
  240. package/template/packs/editorial-monograph/document/theme/fonts.css +0 -3
  241. package/template/packs/editorial-monograph/document/theme/page-surfaces/back-cover.css +0 -43
  242. package/template/packs/editorial-monograph/document/theme/page-surfaces/chapter-opener.css +0 -205
  243. package/template/packs/editorial-monograph/document/theme/page-surfaces/cover.css +0 -147
  244. package/template/packs/editorial-monograph/document/theme/page-surfaces/toc.css +0 -149
  245. package/template/packs/editorial-monograph/document/theme/patterns/_chart-frame.css +0 -49
  246. package/template/packs/editorial-monograph/document/theme/patterns/figure-grid.css +0 -68
  247. package/template/packs/editorial-monograph/document/theme/patterns/table-utilities.css +0 -66
  248. package/template/packs/editorial-monograph/document/theme/shell/reader-controls.css +0 -761
  249. package/template/packs/editorial-monograph/document/theme/tokens.css +0 -80
  250. package/template/packs/editorial-monograph/openpress.config.mjs +0 -5
@@ -1,358 +0,0 @@
1
- import { spawn, spawnSync } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
- import fs from "node:fs/promises";
4
- import path from "node:path";
5
-
6
- const CHROME_CANDIDATE_PATHS = {
7
- darwin: [
8
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
9
- "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
10
- "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
11
- "/Applications/Chromium.app/Contents/MacOS/Chromium",
12
- "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
13
- ],
14
- linux: [
15
- "/usr/bin/google-chrome",
16
- "/usr/bin/google-chrome-stable",
17
- "/usr/bin/chromium",
18
- "/usr/bin/chromium-browser",
19
- "/snap/bin/chromium",
20
- "/opt/google/chrome/chrome",
21
- ],
22
- win32: [
23
- "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
24
- "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
25
- ],
26
- };
27
-
28
- const CHROME_BIN_NAMES = {
29
- darwin: [],
30
- linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"],
31
- win32: ["chrome.exe"],
32
- };
33
-
34
- let cachedChromePath = null;
35
-
36
- function resolveChromePath() {
37
- if (cachedChromePath) return cachedChromePath;
38
- if (process.env.CHROME) {
39
- cachedChromePath = process.env.CHROME;
40
- return cachedChromePath;
41
- }
42
-
43
- const platform = process.platform;
44
- const candidates = [...(CHROME_CANDIDATE_PATHS[platform] ?? [])];
45
-
46
- if (platform === "win32") {
47
- const roots = [process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"], process.env.LOCALAPPDATA].filter(Boolean);
48
- for (const root of roots) {
49
- candidates.push(`${root}\\Google\\Chrome\\Application\\chrome.exe`);
50
- }
51
- }
52
-
53
- for (const candidate of candidates) {
54
- if (existsSync(candidate)) {
55
- cachedChromePath = candidate;
56
- return cachedChromePath;
57
- }
58
- }
59
-
60
- const whichCommand = platform === "win32" ? "where" : "which";
61
- for (const name of CHROME_BIN_NAMES[platform] ?? []) {
62
- try {
63
- const result = spawnSync(whichCommand, [name], { encoding: "utf8" });
64
- const output = result.stdout?.trim().split(/\r?\n/)[0];
65
- if (result.status === 0 && output && existsSync(output)) {
66
- cachedChromePath = output;
67
- return cachedChromePath;
68
- }
69
- } catch {
70
- // continue
71
- }
72
- }
73
-
74
- const lines = [
75
- `Cannot locate a Chrome / Chromium executable on ${platform}.`,
76
- `Set the CHROME environment variable to your Chrome binary path, or install Chrome at one of:`,
77
- ...candidates.map((p) => ` - ${p}`),
78
- ];
79
- throw new Error(lines.join("\n"));
80
- }
81
-
82
- const DEFAULT_PRINT_OPTIONS = {
83
- printBackground: true,
84
- displayHeaderFooter: false,
85
- preferCSSPageSize: true,
86
- paperWidth: 8.2677,
87
- paperHeight: 11.6929,
88
- marginTop: 0,
89
- marginRight: 0,
90
- marginBottom: 0,
91
- marginLeft: 0,
92
- };
93
-
94
- export const DEFAULT_PRINT_VIEWPORT = Object.freeze({
95
- width: 1200,
96
- height: 1698,
97
- deviceScaleFactor: 1,
98
- mobile: false,
99
- });
100
-
101
- export async function printUrlToPdf({
102
- root,
103
- url,
104
- outPath,
105
- chrome,
106
- waitForReady = waitForPrintReady,
107
- printOptions = {},
108
- viewport = DEFAULT_PRINT_VIEWPORT,
109
- debuggingPortBase = 9600,
110
- debuggingPortRange = 300,
111
- profilePrefix = "chrome-pdf",
112
- }) {
113
- chrome ??= resolveChromePath();
114
- await fs.mkdir(path.dirname(outPath), { recursive: true });
115
-
116
- const debuggingPort = String(debuggingPortBase + Math.floor(Math.random() * debuggingPortRange));
117
- const profileDir = path.join(root, ".openpress", "tmp", `${profilePrefix}-${process.pid}-${Date.now()}`);
118
- await fs.mkdir(profileDir, { recursive: true });
119
-
120
- const child = spawn(
121
- chrome,
122
- [
123
- "--headless=new",
124
- "--disable-gpu",
125
- "--no-sandbox",
126
- `--remote-debugging-port=${debuggingPort}`,
127
- `--user-data-dir=${profileDir}`,
128
- "about:blank",
129
- ],
130
- { cwd: root, stdio: ["ignore", "pipe", "pipe"] },
131
- );
132
-
133
- try {
134
- const tab = await waitForChromeTab(debuggingPort);
135
- const client = await connectChromeDevTools(tab.webSocketDebuggerUrl);
136
- try {
137
- await preparePdfPage(client, { viewport });
138
- await client.send("Page.navigate", { url });
139
- const readyResult = await waitForReady(client);
140
- const result = await client.send("Page.printToPDF", {
141
- ...DEFAULT_PRINT_OPTIONS,
142
- ...printOptions,
143
- });
144
- await fs.writeFile(outPath, Buffer.from(String(result.data ?? ""), "base64"));
145
- return readyResult;
146
- } finally {
147
- client.close();
148
- }
149
- } finally {
150
- await stopChildProcess(child);
151
- await cleanupChromeProfile(profileDir);
152
- }
153
- }
154
-
155
- export async function preparePdfPage(client, { viewport = DEFAULT_PRINT_VIEWPORT } = {}) {
156
- await client.send("Page.enable");
157
- await client.send("Runtime.enable");
158
- if (viewport) {
159
- await client.send("Emulation.setDeviceMetricsOverride", viewport);
160
- }
161
- await client.send("Emulation.setEmulatedMedia", { media: "print" });
162
- }
163
-
164
- export async function evaluateUrlWithChrome({
165
- root,
166
- url,
167
- chrome,
168
- evaluate,
169
- emulatedMedia,
170
- debuggingPortBase = 9900,
171
- debuggingPortRange = 300,
172
- profilePrefix = "chrome-eval",
173
- }) {
174
- chrome ??= resolveChromePath();
175
-
176
- const debuggingPort = String(debuggingPortBase + Math.floor(Math.random() * debuggingPortRange));
177
- const profileDir = path.join(root, ".openpress", "tmp", `${profilePrefix}-${process.pid}-${Date.now()}`);
178
- await fs.mkdir(profileDir, { recursive: true });
179
-
180
- const child = spawn(
181
- chrome,
182
- [
183
- "--headless=new",
184
- "--disable-gpu",
185
- "--no-sandbox",
186
- `--remote-debugging-port=${debuggingPort}`,
187
- `--user-data-dir=${profileDir}`,
188
- "about:blank",
189
- ],
190
- { cwd: root, stdio: ["ignore", "pipe", "pipe"] },
191
- );
192
-
193
- try {
194
- const tab = await waitForChromeTab(debuggingPort);
195
- const client = await connectChromeDevTools(tab.webSocketDebuggerUrl);
196
- try {
197
- await client.send("Page.enable");
198
- await client.send("Runtime.enable");
199
- if (emulatedMedia) {
200
- await client.send("Emulation.setEmulatedMedia", { media: emulatedMedia });
201
- }
202
- await client.send("Page.navigate", { url });
203
- return await evaluate(client);
204
- } finally {
205
- client.close();
206
- }
207
- } finally {
208
- await stopChildProcess(child);
209
- await cleanupChromeProfile(profileDir);
210
- }
211
- }
212
-
213
- export async function waitForPrintReady(client) {
214
- const deadline = Date.now() + 30000;
215
- while (Date.now() < deadline) {
216
- const result = await client.send("Runtime.evaluate", {
217
- returnByValue: true,
218
- awaitPromise: true,
219
- expression: `Promise.resolve().then(async () => {
220
- const root = document.querySelector('[data-openpress-print-document="true"]');
221
- if (!root || root.querySelectorAll('.openpress-html-page').length === 0) return 0;
222
-
223
- await document.fonts?.ready;
224
- await Promise.all(Array.from(document.images).map(async (img) => {
225
- if (!img.complete) {
226
- await new Promise((resolve) => {
227
- const settle = () => {
228
- img.removeEventListener('load', settle);
229
- img.removeEventListener('error', settle);
230
- resolve();
231
- };
232
-
233
- img.addEventListener('load', settle, { once: true });
234
- img.addEventListener('error', settle, { once: true });
235
- });
236
- }
237
-
238
- await img.decode?.().catch(() => undefined);
239
- }));
240
-
241
- await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
242
-
243
- const pages = Array.from(document.querySelectorAll('.openpress-public-page > .openpress-html-page'));
244
- const contentFitsPageBody = (body) => {
245
- const bodyBottom = body.getBoundingClientRect().bottom;
246
- const contentBottom = Array.from(body.children).reduce((bottom, child) => {
247
- if (getComputedStyle(child).display === 'none') return bottom;
248
- const marginBottom = Number.parseFloat(getComputedStyle(child).marginBottom) || 0;
249
- return Math.max(bottom, child.getBoundingClientRect().bottom + marginBottom);
250
- }, body.getBoundingClientRect().top);
251
- return contentBottom <= bodyBottom + 1;
252
- };
253
- const bodyOverflowSafe = pages.every((page) => {
254
- const body = page.querySelector('.page-body');
255
- return !body || contentFitsPageBody(body);
256
- });
257
-
258
- return pages.length > 0 && bodyOverflowSafe ? pages.length : 0;
259
- })`,
260
- });
261
- const count = Number(result.result?.value ?? 0);
262
- if (count > 0) return count;
263
- await delay(100);
264
- }
265
- throw new Error("Timed out waiting for OpenPress pagination before PDF export.");
266
- }
267
-
268
- export async function stopChildProcess(child) {
269
- if (child.exitCode !== null || child.signalCode !== null) return;
270
- child.kill();
271
- const closed = await waitForChildClose(child, 2500);
272
- if (closed || child.exitCode !== null || child.signalCode !== null) return;
273
- child.kill("SIGKILL");
274
- await waitForChildClose(child, 2500);
275
- }
276
-
277
- async function waitForChromeTab(debuggingPort) {
278
- const deadline = Date.now() + 10000;
279
- let lastError;
280
- while (Date.now() < deadline) {
281
- try {
282
- const response = await fetch(`http://127.0.0.1:${debuggingPort}/json/list`);
283
- const tabs = await response.json();
284
- const tab = tabs.find((item) => item.type === "page" && item.webSocketDebuggerUrl);
285
- if (tab) return tab;
286
- } catch (error) {
287
- lastError = error;
288
- }
289
- await delay(100);
290
- }
291
- throw new Error(`Timed out waiting for Chrome DevTools${lastError ? `: ${lastError.message}` : ""}`);
292
- }
293
-
294
- async function connectChromeDevTools(webSocketDebuggerUrl) {
295
- const socket = new WebSocket(webSocketDebuggerUrl);
296
- const pending = new Map();
297
- let nextId = 0;
298
-
299
- await new Promise((resolve, reject) => {
300
- socket.addEventListener("open", resolve, { once: true });
301
- socket.addEventListener("error", reject, { once: true });
302
- });
303
-
304
- socket.addEventListener("message", (event) => {
305
- const message = JSON.parse(String(event.data));
306
- if (!message.id || !pending.has(message.id)) return;
307
- const callbacks = pending.get(message.id);
308
- pending.delete(message.id);
309
- if (message.error) callbacks?.reject(new Error(message.error.message ?? "Chrome DevTools command failed."));
310
- else callbacks?.resolve(message.result ?? {});
311
- });
312
-
313
- return {
314
- send(method, params = {}) {
315
- return new Promise((resolve, reject) => {
316
- const id = ++nextId;
317
- pending.set(id, { resolve, reject });
318
- socket.send(JSON.stringify({ id, method, params }));
319
- });
320
- },
321
- close() {
322
- socket.close();
323
- },
324
- };
325
- }
326
-
327
- function waitForChildClose(child, timeoutMs) {
328
- if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(true);
329
- return new Promise((resolve) => {
330
- let settled = false;
331
- const finish = (closed) => {
332
- if (settled) return;
333
- settled = true;
334
- clearTimeout(timer);
335
- child.off("close", onClose);
336
- child.off("error", onError);
337
- resolve(closed);
338
- };
339
- const onClose = () => finish(true);
340
- const onError = () => finish(true);
341
- const timer = setTimeout(() => finish(false), timeoutMs);
342
- child.once("close", onClose);
343
- child.once("error", onError);
344
- });
345
- }
346
-
347
- async function cleanupChromeProfile(profileDir) {
348
- try {
349
- await fs.rm(profileDir, { recursive: true, force: true, maxRetries: 8, retryDelay: 150 });
350
- } catch (error) {
351
- const message = error instanceof Error ? error.message : String(error);
352
- console.warn(`Could not remove temporary Chrome profile ${profileDir}: ${message}`);
353
- }
354
- }
355
-
356
- function delay(ms) {
357
- return new Promise((resolve) => setTimeout(resolve, ms));
358
- }
@@ -1,15 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { loadConfig } from "../runtime/config.mjs";
4
- import { copyDirectory } from "../runtime/file-utils.mjs";
5
-
6
- export async function deploySync(root, sourceDir, deployDir) {
7
- const config = await loadConfig(root);
8
- sourceDir ??= config.outputDir;
9
- deployDir ??= config.deploy.source;
10
- const dist = path.join(root, sourceDir);
11
- const deploy = path.join(root, deployDir);
12
- await fs.rm(deploy, { recursive: true, force: true });
13
- await fs.mkdir(deploy, { recursive: true });
14
- await copyDirectory(dist, deploy);
15
- }
@@ -1,62 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { copyDirectory } from "../runtime/file-utils.mjs";
4
-
5
- export async function copyThemeFonts(root, publicOutputDir, config) {
6
- const themeDir = config?.paths?.themeDir ?? path.join(path.resolve(root), "theme");
7
- const target = path.join(publicOutputDir, "fonts.css");
8
- const themeFonts = path.join(themeDir, "fonts.css");
9
- if (await isFile(themeFonts)) {
10
- await fs.copyFile(themeFonts, target);
11
- } else {
12
- await fs.writeFile(target, defaultFontsCss(), "utf8");
13
- }
14
-
15
- const themeFontFiles = path.join(themeDir, "fonts");
16
- if (await isDirectory(themeFontFiles)) {
17
- await copyDirectory(themeFontFiles, path.join(publicOutputDir, "fonts"));
18
- } else {
19
- await fs.rm(path.join(publicOutputDir, "fonts"), { recursive: true, force: true });
20
- }
21
- }
22
-
23
- async function isFile(filePath) {
24
- try {
25
- return (await fs.stat(filePath)).isFile();
26
- } catch {
27
- return false;
28
- }
29
- }
30
-
31
- async function isDirectory(filePath) {
32
- try {
33
- return (await fs.stat(filePath)).isDirectory();
34
- } catch {
35
- return false;
36
- }
37
- }
38
-
39
- function defaultFontsCss() {
40
- return `@font-face {
41
- font-family: "OpenPress Body";
42
- src: local("PingFang TC"), local("Noto Sans TC"), local("Hiragino Sans"), local("Microsoft JhengHei");
43
- font-weight: 300 700;
44
- font-style: normal;
45
- font-display: swap;
46
- }
47
-
48
- @font-face {
49
- font-family: "OpenPress Serif";
50
- src: local("Noto Serif TC"), local("Songti TC"), local("Source Han Serif TC"), local("PMingLiU");
51
- font-weight: 300 700;
52
- font-style: normal;
53
- font-display: swap;
54
- }
55
-
56
- :root {
57
- --openpress-font-body: "OpenPress Body", "PingFang TC", "Noto Sans TC", "Hiragino Sans", "Microsoft JhengHei", sans-serif;
58
- --openpress-font-serif: "OpenPress Serif", "Noto Serif TC", "Songti TC", "Source Han Serif TC", "PMingLiU", serif;
59
- --openpress-font-mono: "SFMono-Regular", "Menlo", "Consolas", monospace;
60
- }
61
- `;
62
- }
@@ -1,45 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { createRequire } from "node:module";
4
-
5
- const require = createRequire(import.meta.url);
6
-
7
- const KATEX_OVERRIDES = `
8
-
9
- /* OpenPress math sizing keeps inline equations aligned with document typography. */
10
- .reader-page--content .katex {
11
- font-size: 1em;
12
- }
13
-
14
- .reader-page--content .katex-display {
15
- display: block;
16
- width: fit-content;
17
- max-width: 100%;
18
- margin: var(--openpress-space-2) auto var(--openpress-space-3);
19
- border-block: 1px solid color-mix(in srgb, var(--openpress-color-line) 76%, transparent);
20
- padding: 0.55em 1.15em;
21
- background: color-mix(in srgb, var(--openpress-color-panel) 78%, var(--openpress-color-document));
22
- color: var(--openpress-color-ink);
23
- overflow-x: auto;
24
- overflow-y: hidden;
25
- text-align: center;
26
- }
27
-
28
- .reader-page--content .katex-display > .katex {
29
- font-size: 1.05em;
30
- }
31
- `;
32
-
33
- export async function readKatexCss() {
34
- const cssPath = require.resolve("katex/dist/katex.min.css");
35
- const css = await fs.readFile(cssPath, "utf8");
36
- return `${css.replace(/url\(fonts\/([^)]+)\)/g, 'url("/openpress/katex-fonts/$1")')}${KATEX_OVERRIDES}`;
37
- }
38
-
39
- export async function copyKatexFonts(publicOutputDir) {
40
- const sampleFont = require.resolve("katex/dist/fonts/KaTeX_Main-Regular.woff2");
41
- const sourceDir = path.dirname(sampleFont);
42
- const targetDir = path.join(publicOutputDir, "katex-fonts");
43
- await fs.rm(targetDir, { recursive: true, force: true });
44
- await fs.cp(sourceDir, targetDir, { recursive: true });
45
- }
@@ -1,30 +0,0 @@
1
- import path from "node:path";
2
-
3
- export function documentRelativePath(config, ...parts) {
4
- return path.posix.join(
5
- ...(config.documentDir === "." ? [] : [config.documentDir]),
6
- ...parts,
7
- );
8
- }
9
-
10
- function rewriteAssetPaths(pageHtml, config) {
11
- const mediaDir = config.mediaDir.replace(/^\/+|\/+$/g, "");
12
- return pageHtml
13
- .replaceAll(`src="${mediaDir}/`, 'src="/openpress/media/')
14
- .replaceAll(`src='${mediaDir}/`, "src='/openpress/media/");
15
- }
16
-
17
- export function pageToBlock(index, pageHtml, source, config, { idPrefix = "openpress-page", anchorPrefix = "page", titleFallback = "Page" } = {}) {
18
- const paddedIndex = String(index + 1).padStart(2, "0");
19
- const title = pageHtml.match(/data-page-title="([^"]*)"/)?.[1] ?? `${titleFallback} ${index + 1}`;
20
- const anchor = pageHtml.match(/\bid="([^"]+)"/)?.[1] ?? `${anchorPrefix}-${paddedIndex}`;
21
- return {
22
- id: `${idPrefix}-${paddedIndex}`,
23
- kind: "htmlPage",
24
- title,
25
- pageNumber: index + 1,
26
- source,
27
- html: rewriteAssetPaths(pageHtml, config),
28
- anchors: [anchor],
29
- };
30
- }
@@ -1,45 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { spawnSync } from "node:child_process";
4
-
5
- export async function optimizePdfMediaForStaticRoot(staticRoot) {
6
- await optimizePdfMedia(path.join(staticRoot, "openpress", "media"));
7
- }
8
-
9
- async function optimizePdfMedia(mediaDir) {
10
- const files = await listImageFiles(mediaDir);
11
- for (const file of files) {
12
- const stat = await fs.stat(file);
13
- if (stat.size < 320 * 1024) continue;
14
-
15
- const ext = path.extname(file).toLowerCase();
16
- const args =
17
- ext === ".jpg" || ext === ".jpeg"
18
- ? ["-Z", "1600", "--setProperty", "formatOptions", "78", file, "--out", file]
19
- : ["-Z", "1600", file, "--out", file];
20
- const result = spawnSync("sips", args, { stdio: "ignore" });
21
- if (result.status !== 0) {
22
- console.warn(`[pdf] skipped image optimization: ${path.basename(file)}`);
23
- }
24
- }
25
- }
26
-
27
- async function listImageFiles(dir) {
28
- let entries;
29
- try {
30
- entries = await fs.readdir(dir, { withFileTypes: true });
31
- } catch {
32
- return [];
33
- }
34
-
35
- const files = [];
36
- for (const entry of entries) {
37
- const fullPath = path.join(dir, entry.name);
38
- if (entry.isDirectory()) {
39
- files.push(...(await listImageFiles(fullPath)));
40
- } else if (/\.(jpe?g|png)$/i.test(entry.name)) {
41
- files.push(fullPath);
42
- }
43
- }
44
- return files;
45
- }
@@ -1,19 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { loadConfig } from "../runtime/config.mjs";
4
- import { copyDirectory, writeComponentsCss, writeContentCss } from "../runtime/file-utils.mjs";
5
- import { copyThemeFonts } from "./fonts.mjs";
6
- import { copyKatexFonts } from "./katex-assets.mjs";
7
-
8
- export async function syncPublicAssets(root, publicOutputDir, config) {
9
- config ??= await loadConfig(root);
10
- await fs.rm(path.join(publicOutputDir, "report.css"), { force: true });
11
- for (const name of ["tokens.css"]) {
12
- await fs.copyFile(path.join(config.paths.themeDir, name), path.join(publicOutputDir, name));
13
- }
14
- await writeContentCss(root, publicOutputDir, config);
15
- await copyThemeFonts(root, publicOutputDir, config);
16
- await copyKatexFonts(publicOutputDir);
17
- await writeComponentsCss(root, publicOutputDir, config);
18
- await copyDirectory(config.paths.mediaDir, path.join(publicOutputDir, "media"));
19
- }