@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.
- package/README.md +33 -23
- package/dist/cli.js +320 -252
- package/package.json +9 -8
- package/template/core/AGENTS.md +0 -126
- package/template/core/CHANGELOG.md +0 -215
- package/template/core/README.md +0 -40
- package/template/core/engine/cli.mjs +0 -96
- package/template/core/engine/commands/_shared.mjs +0 -177
- package/template/core/engine/commands/deploy.mjs +0 -31
- package/template/core/engine/commands/dev.mjs +0 -49
- package/template/core/engine/commands/doctor.mjs +0 -229
- package/template/core/engine/commands/export.mjs +0 -8
- package/template/core/engine/commands/init.mjs +0 -24
- package/template/core/engine/commands/inspect.mjs +0 -35
- package/template/core/engine/commands/pdf.mjs +0 -26
- package/template/core/engine/commands/preview.mjs +0 -26
- package/template/core/engine/commands/render.mjs +0 -17
- package/template/core/engine/commands/replace.mjs +0 -41
- package/template/core/engine/commands/search.mjs +0 -33
- package/template/core/engine/commands/typecheck.mjs +0 -5
- package/template/core/engine/commands/upgrade.mjs +0 -159
- package/template/core/engine/commands/validate.mjs +0 -17
- package/template/core/engine/document-export.mjs +0 -15
- package/template/core/engine/init.mjs +0 -90
- package/template/core/engine/output/chrome-pdf.d.mts +0 -34
- package/template/core/engine/output/chrome-pdf.mjs +0 -358
- package/template/core/engine/output/deploy-sync.mjs +0 -15
- package/template/core/engine/output/fonts.mjs +0 -62
- package/template/core/engine/output/katex-assets.mjs +0 -45
- package/template/core/engine/output/page-block.mjs +0 -30
- package/template/core/engine/output/pdf-media.mjs +0 -45
- package/template/core/engine/output/public-assets.mjs +0 -19
- package/template/core/engine/output/static-server.mjs +0 -532
- package/template/core/engine/react/caption-numbering.mjs +0 -73
- package/template/core/engine/react/comment-endpoint.d.mts +0 -11
- package/template/core/engine/react/comment-endpoint.mjs +0 -102
- package/template/core/engine/react/comment-marker.mjs +0 -374
- package/template/core/engine/react/document-entry.mjs +0 -324
- package/template/core/engine/react/document-export.mjs +0 -373
- package/template/core/engine/react/http-json.mjs +0 -24
- package/template/core/engine/react/mdx-compile.mjs +0 -599
- package/template/core/engine/react/measurement-css.mjs +0 -136
- package/template/core/engine/react/object-entities.mjs +0 -119
- package/template/core/engine/react/pagination/allocator.mjs +0 -122
- package/template/core/engine/react/pagination/regions.mjs +0 -81
- package/template/core/engine/react/pagination-constants.mjs +0 -3
- package/template/core/engine/react/pagination.mjs +0 -9
- package/template/core/engine/react/pipeline/allocate.mjs +0 -251
- package/template/core/engine/react/pipeline/final-render.mjs +0 -94
- package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -302
- package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
- package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
- package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
- package/template/core/engine/react/section-css.mjs +0 -56
- package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
- package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
- package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
- package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
- package/template/core/engine/react/style-discovery.mjs +0 -142
- package/template/core/engine/runtime/config.d.mts +0 -40
- package/template/core/engine/runtime/config.mjs +0 -175
- package/template/core/engine/runtime/file-utils.mjs +0 -106
- package/template/core/engine/runtime/file-walk.mjs +0 -22
- package/template/core/engine/runtime/inspection.mjs +0 -328
- package/template/core/engine/runtime/issue-report.mjs +0 -44
- package/template/core/engine/runtime/path-utils.mjs +0 -20
- package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
- package/template/core/engine/runtime/source-text-tools.mjs +0 -832
- package/template/core/engine/runtime/source-workspace.mjs +0 -159
- package/template/core/engine/runtime/validation.mjs +0 -174
- package/template/core/index.html +0 -13
- package/template/core/openpress.config.mjs +0 -12
- package/template/core/package.json +0 -91
- package/template/core/src/main.tsx +0 -16
- package/template/core/src/openpress/app/OpenPressApp.tsx +0 -140
- package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -94
- package/template/core/src/openpress/app/index.ts +0 -2
- package/template/core/src/openpress/core/Frame.tsx +0 -78
- package/template/core/src/openpress/core/FrameContext.tsx +0 -24
- package/template/core/src/openpress/core/MdxArea.tsx +0 -34
- package/template/core/src/openpress/core/Press.tsx +0 -34
- package/template/core/src/openpress/core/cn.ts +0 -4
- package/template/core/src/openpress/core/index.tsx +0 -40
- package/template/core/src/openpress/core/primitives.tsx +0 -44
- package/template/core/src/openpress/core/types.ts +0 -191
- package/template/core/src/openpress/core/useSource.ts +0 -28
- package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
- package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
- package/template/core/src/openpress/document-model/documentTypes.ts +0 -138
- package/template/core/src/openpress/document-model/index.ts +0 -6
- package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -51
- package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
- package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
- package/template/core/src/openpress/manuscript/index.tsx +0 -238
- package/template/core/src/openpress/mdx/index.ts +0 -88
- package/template/core/src/openpress/numbering/index.ts +0 -294
- package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
- package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
- package/template/core/src/openpress/reader/index.ts +0 -10
- package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
- package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
- package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
- package/template/core/src/openpress/reader/readerScroll.ts +0 -92
- package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
- package/template/core/src/openpress/reader/readerTypes.ts +0 -4
- package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
- package/template/core/src/openpress/reader/usePanelState.ts +0 -56
- package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
- package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
- package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
- package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
- package/template/core/src/openpress/shared/Panel.tsx +0 -77
- package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
- package/template/core/src/openpress/shared/index.ts +0 -4
- package/template/core/src/openpress/shared/numberUtils.ts +0 -3
- package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
- package/template/core/src/openpress/workbench/Workbench.tsx +0 -407
- package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
- package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
- package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
- package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
- package/template/core/src/openpress/workbench/actions/index.ts +0 -5
- package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
- package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
- package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
- package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
- package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
- package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
- package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
- package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
- package/template/core/src/openpress/workbench/document/index.ts +0 -10
- package/template/core/src/openpress/workbench/index.ts +0 -2
- package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
- package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
- package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
- package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
- package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
- package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -248
- package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
- package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
- package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
- package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
- package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -76
- package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
- package/template/core/src/openpress/workbench/panels/index.ts +0 -3
- package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -523
- package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
- package/template/core/src/openpress/workbench/project/index.ts +0 -2
- package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
- package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
- package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
- package/template/core/src/openpress/workbench/shell/index.ts +0 -1
- package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
- package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
- package/template/core/src/styles/openpress/app-shell.css +0 -251
- package/template/core/src/styles/openpress/media-workspace.css +0 -230
- package/template/core/src/styles/openpress/print-route.css +0 -184
- package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
- package/template/core/src/styles/openpress/public-viewer.css +0 -688
- package/template/core/src/styles/openpress/reader-runtime.css +0 -980
- package/template/core/src/styles/openpress/responsive.css +0 -245
- package/template/core/src/styles/openpress/workbench-panels.css +0 -594
- package/template/core/src/styles/openpress/workbench.css +0 -1255
- package/template/core/src/styles/openpress.css +0 -14
- package/template/core/src/vite-env.d.ts +0 -9
- package/template/core/tsconfig.json +0 -40
- package/template/core/vite.config.ts +0 -584
- package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +0 -35
- package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +0 -50
- package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +0 -47
- package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +0 -26
- package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +0 -32
- package/template/packs/academic-paper/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/academic-paper/document/components/Page.tsx +0 -60
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/academic-paper/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/academic-paper/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/academic-paper/document/design.md +0 -279
- package/template/packs/academic-paper/document/index.tsx +0 -123
- package/template/packs/academic-paper/document/media/README.md +0 -13
- package/template/packs/academic-paper/document/media/figure-placeholder.svg +0 -9
- package/template/packs/academic-paper/document/openpress.config.mjs +0 -26
- package/template/packs/academic-paper/document/theme/README.md +0 -11
- package/template/packs/academic-paper/document/theme/base/page-contract.css +0 -522
- package/template/packs/academic-paper/document/theme/base/print.css +0 -93
- package/template/packs/academic-paper/document/theme/base/typography.css +0 -333
- package/template/packs/academic-paper/document/theme/fonts.css +0 -3
- package/template/packs/academic-paper/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/academic-paper/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +0 -294
- package/template/packs/academic-paper/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/academic-paper/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/academic-paper/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/academic-paper/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/academic-paper/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/academic-paper/document/theme/tokens.css +0 -80
- package/template/packs/academic-paper/openpress.config.mjs +0 -5
- package/template/packs/claude-document/document/chapters/01-document-shape/content/01-document-shape.mdx +0 -51
- package/template/packs/claude-document/document/chapters/02-review-loop/content/01-review-loop.mdx +0 -31
- package/template/packs/claude-document/document/components/ChapterOpenerVisual.tsx +0 -96
- package/template/packs/claude-document/document/components/Page.tsx +0 -37
- package/template/packs/claude-document/document/design.md +0 -142
- package/template/packs/claude-document/document/index.tsx +0 -94
- package/template/packs/claude-document/document/media/README.md +0 -13
- package/template/packs/claude-document/document/openpress.config.mjs +0 -26
- package/template/packs/claude-document/document/theme/README.md +0 -15
- package/template/packs/claude-document/document/theme/base/page-contract.css +0 -525
- package/template/packs/claude-document/document/theme/base/print.css +0 -93
- package/template/packs/claude-document/document/theme/base/typography.css +0 -612
- package/template/packs/claude-document/document/theme/fonts.css +0 -4
- package/template/packs/claude-document/document/theme/page-surfaces/back-cover.css +0 -72
- package/template/packs/claude-document/document/theme/page-surfaces/chapter-opener.css +0 -236
- package/template/packs/claude-document/document/theme/page-surfaces/cover.css +0 -309
- package/template/packs/claude-document/document/theme/page-surfaces/toc.css +0 -225
- package/template/packs/claude-document/document/theme/patterns/_chart-frame.css +0 -53
- package/template/packs/claude-document/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/claude-document/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/claude-document/document/theme/shell/reader-controls.css +0 -789
- package/template/packs/claude-document/document/theme/tokens.css +0 -89
- package/template/packs/claude-document/openpress.config.mjs +0 -5
- package/template/packs/editorial-monograph/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +0 -31
- package/template/packs/editorial-monograph/document/chapters/02-workflow/content/01-workflow.mdx +0 -89
- package/template/packs/editorial-monograph/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +0 -51
- package/template/packs/editorial-monograph/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +0 -39
- package/template/packs/editorial-monograph/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/editorial-monograph/document/components/Page.tsx +0 -37
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/editorial-monograph/document/design.md +0 -279
- package/template/packs/editorial-monograph/document/index.tsx +0 -97
- package/template/packs/editorial-monograph/document/media/README.md +0 -13
- package/template/packs/editorial-monograph/document/openpress.config.mjs +0 -26
- package/template/packs/editorial-monograph/document/theme/README.md +0 -11
- package/template/packs/editorial-monograph/document/theme/base/page-contract.css +0 -505
- package/template/packs/editorial-monograph/document/theme/base/print.css +0 -93
- package/template/packs/editorial-monograph/document/theme/base/typography.css +0 -336
- package/template/packs/editorial-monograph/document/theme/fonts.css +0 -3
- package/template/packs/editorial-monograph/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/editorial-monograph/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/editorial-monograph/document/theme/page-surfaces/cover.css +0 -147
- package/template/packs/editorial-monograph/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/editorial-monograph/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/editorial-monograph/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/editorial-monograph/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/editorial-monograph/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/editorial-monograph/document/theme/tokens.css +0 -80
- 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
|
-
}
|