@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,328 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { evaluateUrlWithChrome, stopChildProcess } from "../output/chrome-pdf.mjs";
|
|
4
|
-
import { buildReactStatic, startStaticServer } from "../commands/_shared.mjs";
|
|
5
|
-
import { walkFiles } from "./file-walk.mjs";
|
|
6
|
-
import { createIssue, createIssueReport } from "./issue-report.mjs";
|
|
7
|
-
import { collectActiveContentFiles, resolveActiveSourceWorkspace } from "./source-workspace.mjs";
|
|
8
|
-
|
|
9
|
-
const MEDIA_EXTENSIONS = new Set([".avif", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".webp"]);
|
|
10
|
-
const SOURCE_EXTENSIONS = new Set([".css", ".html", ".js", ".json", ".md", ".mjs", ".ts", ".tsx"]);
|
|
11
|
-
|
|
12
|
-
export async function inspectWorkspace({ root, config, options = {}, recurse = null }) {
|
|
13
|
-
const checked = [];
|
|
14
|
-
const issues = [];
|
|
15
|
-
|
|
16
|
-
const sourceScan = await collectInspectionSources(config);
|
|
17
|
-
checked.push(sourceScan.checkedName);
|
|
18
|
-
sourceScan.contentFiles.forEach((file) => {
|
|
19
|
-
if (!file.text.trim()) {
|
|
20
|
-
issues.push(createIssue({
|
|
21
|
-
level: "warning",
|
|
22
|
-
code: "react-source.empty-file",
|
|
23
|
-
message: `${sourceScan.contentLabel} \`${file.relativePath}\` is empty.`,
|
|
24
|
-
path: file.absolutePath,
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
checked.push("media");
|
|
30
|
-
const mediaFiles = await readMediaFiles(sourceScan.config.paths.mediaDir);
|
|
31
|
-
const sourceText = sourceScan.sourceFiles.map((file) => file.text).join("\n");
|
|
32
|
-
const unusedMedia = mediaFiles.filter((file) => !sourceText.includes(file.name) && !sourceText.includes(file.relativePath));
|
|
33
|
-
unusedMedia.forEach((file) => {
|
|
34
|
-
issues.push(createIssue({
|
|
35
|
-
level: "warning",
|
|
36
|
-
code: "media.unused",
|
|
37
|
-
message: `Media asset \`${file.relativePath}\` is not referenced by document sources.`,
|
|
38
|
-
path: file.absolutePath,
|
|
39
|
-
detail: {
|
|
40
|
-
file: file.name,
|
|
41
|
-
relativePath: file.relativePath,
|
|
42
|
-
},
|
|
43
|
-
}));
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
checked.push("components");
|
|
47
|
-
const componentUsage = sourceScan.componentUsage;
|
|
48
|
-
|
|
49
|
-
const summary = {
|
|
50
|
-
...sourceScan.summary,
|
|
51
|
-
mediaFiles: mediaFiles.length,
|
|
52
|
-
unusedMedia: unusedMedia.length,
|
|
53
|
-
componentUsage,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
checked.push("overflow");
|
|
57
|
-
const renderCode = await buildReactStatic({
|
|
58
|
-
root,
|
|
59
|
-
noBuild: options.noBuild,
|
|
60
|
-
recurse,
|
|
61
|
-
silent: options.json,
|
|
62
|
-
});
|
|
63
|
-
if (renderCode !== 0) {
|
|
64
|
-
issues.push(createIssue({
|
|
65
|
-
level: "error",
|
|
66
|
-
code: "inspect.render",
|
|
67
|
-
message: `React render failed before overflow inspection (exit code ${renderCode}).`,
|
|
68
|
-
path: config.configPath,
|
|
69
|
-
}));
|
|
70
|
-
return createIssueReport({
|
|
71
|
-
kind: "inspection",
|
|
72
|
-
checked,
|
|
73
|
-
issues,
|
|
74
|
-
summary,
|
|
75
|
-
okMessage: "OpenPress inspection OK",
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const overflowMeasurements = await inspectRenderedOverflow({
|
|
80
|
-
root,
|
|
81
|
-
config,
|
|
82
|
-
host: options.host ?? "127.0.0.1",
|
|
83
|
-
port: options.port ?? "5186",
|
|
84
|
-
});
|
|
85
|
-
issues.push(...overflowIssuesFromMeasurements(overflowMeasurements));
|
|
86
|
-
summary.pages = overflowMeasurements.length;
|
|
87
|
-
summary.overflowPages = overflowMeasurements.filter((page) => (page.overflows ?? []).length > 0).length;
|
|
88
|
-
|
|
89
|
-
return createIssueReport({
|
|
90
|
-
kind: "inspection",
|
|
91
|
-
checked,
|
|
92
|
-
issues,
|
|
93
|
-
summary,
|
|
94
|
-
okMessage: "OpenPress inspection OK",
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function collectInspectionSources(config) {
|
|
99
|
-
const sourceWorkspace = await resolveActiveSourceWorkspace(config);
|
|
100
|
-
const sourceConfig = sourceWorkspace.config;
|
|
101
|
-
const contentFiles = await collectActiveContentFiles(sourceWorkspace);
|
|
102
|
-
const sourceFiles = [
|
|
103
|
-
...contentFiles,
|
|
104
|
-
...await readSourceFiles(sourceConfig.paths.componentsDir),
|
|
105
|
-
...await readSingleFile(sourceConfig.paths.designDoc),
|
|
106
|
-
];
|
|
107
|
-
const componentUsage = summarizeComponentUsage(contentFiles);
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
sourceKind: sourceWorkspace.kind,
|
|
111
|
-
checkedName: sourceWorkspace.checkedName,
|
|
112
|
-
contentLabel: sourceWorkspace.contentLabel,
|
|
113
|
-
config: sourceConfig,
|
|
114
|
-
contentFiles,
|
|
115
|
-
sourceFiles,
|
|
116
|
-
componentUsage,
|
|
117
|
-
summary: {
|
|
118
|
-
sourceKind: sourceWorkspace.kind,
|
|
119
|
-
sourceFiles: contentFiles.length,
|
|
120
|
-
mdxFiles: contentFiles.length,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function inspectRenderedOverflow({ root, config, host = "127.0.0.1", port = "5186" }) {
|
|
126
|
-
const server = await startStaticServer(root, config, host, port);
|
|
127
|
-
try {
|
|
128
|
-
return await evaluateUrlWithChrome({
|
|
129
|
-
root,
|
|
130
|
-
url: `http://${host}:${port}/?print=1`,
|
|
131
|
-
debuggingPortBase: 9900,
|
|
132
|
-
debuggingPortRange: 600,
|
|
133
|
-
profilePrefix: "chrome-inspect",
|
|
134
|
-
emulatedMedia: "print",
|
|
135
|
-
evaluate: waitForInspectionReady,
|
|
136
|
-
});
|
|
137
|
-
} finally {
|
|
138
|
-
await stopChildProcess(server);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export async function waitForInspectionReady(client) {
|
|
143
|
-
const deadline = Date.now() + 30000;
|
|
144
|
-
while (Date.now() < deadline) {
|
|
145
|
-
const result = await client.send("Runtime.evaluate", {
|
|
146
|
-
returnByValue: true,
|
|
147
|
-
awaitPromise: true,
|
|
148
|
-
expression: inspectionExpression(),
|
|
149
|
-
});
|
|
150
|
-
const value = result.result?.value;
|
|
151
|
-
if (Array.isArray(value)) return value;
|
|
152
|
-
await delay(100);
|
|
153
|
-
}
|
|
154
|
-
throw new Error("Timed out waiting for OpenPress pagination before inspection.");
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function overflowIssuesFromMeasurements(measurements) {
|
|
158
|
-
return measurements.flatMap((page) => {
|
|
159
|
-
const pageLabel = String(page.pageNumber).padStart(2, "0");
|
|
160
|
-
return (page.overflows ?? []).map((overflow) => createIssue({
|
|
161
|
-
level: "warning",
|
|
162
|
-
code: `overflow.${overflow.code}`,
|
|
163
|
-
message: `Page ${pageLabel} exceeds ${humanOverflowTarget(overflow.code)} by ${Math.ceil(overflow.overflowPx)}px.`,
|
|
164
|
-
path: page.source?.path,
|
|
165
|
-
detail: {
|
|
166
|
-
pageNumber: page.pageNumber,
|
|
167
|
-
title: page.title,
|
|
168
|
-
sourceFile: page.source?.file,
|
|
169
|
-
selector: overflow.selector,
|
|
170
|
-
tagName: overflow.tagName,
|
|
171
|
-
text: overflow.text,
|
|
172
|
-
overflowPx: Math.ceil(overflow.overflowPx),
|
|
173
|
-
},
|
|
174
|
-
}));
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async function readSourceFiles(directory, extension = null) {
|
|
179
|
-
const files = [];
|
|
180
|
-
await walkFiles(directory, async (absolutePath) => {
|
|
181
|
-
if (extension && path.extname(absolutePath) !== extension) return;
|
|
182
|
-
if (!SOURCE_EXTENSIONS.has(path.extname(absolutePath))) return;
|
|
183
|
-
files.push({
|
|
184
|
-
absolutePath,
|
|
185
|
-
relativePath: path.relative(directory, absolutePath).replaceAll("\\", "/"),
|
|
186
|
-
text: await fs.readFile(absolutePath, "utf8"),
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
files.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
190
|
-
return files;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async function readSingleFile(absolutePath) {
|
|
194
|
-
try {
|
|
195
|
-
const text = await fs.readFile(absolutePath, "utf8");
|
|
196
|
-
return [{
|
|
197
|
-
absolutePath,
|
|
198
|
-
relativePath: path.basename(absolutePath),
|
|
199
|
-
text,
|
|
200
|
-
}];
|
|
201
|
-
} catch (error) {
|
|
202
|
-
if (error?.code === "ENOENT") return [];
|
|
203
|
-
throw error;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async function readMediaFiles(directory) {
|
|
208
|
-
const files = [];
|
|
209
|
-
await walkFiles(directory, async (absolutePath) => {
|
|
210
|
-
if (!MEDIA_EXTENSIONS.has(path.extname(absolutePath).toLowerCase())) return;
|
|
211
|
-
files.push({
|
|
212
|
-
absolutePath,
|
|
213
|
-
name: path.basename(absolutePath),
|
|
214
|
-
relativePath: path.relative(directory, absolutePath).replaceAll("\\", "/"),
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
files.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
218
|
-
return files;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function summarizeComponentUsage(contentFiles) {
|
|
222
|
-
const usages = new Map();
|
|
223
|
-
for (const file of contentFiles) {
|
|
224
|
-
for (const match of file.text.matchAll(/<([A-Z][A-Za-z0-9]*)\b/g)) {
|
|
225
|
-
const name = match[1];
|
|
226
|
-
const current = usages.get(name) ?? { name, count: 0, files: [] };
|
|
227
|
-
current.count += 1;
|
|
228
|
-
if (!current.files.includes(file.relativePath)) current.files.push(file.relativePath);
|
|
229
|
-
usages.set(name, current);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return Array.from(usages.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function humanOverflowTarget(code) {
|
|
236
|
-
if (code === "page-body") return "page body";
|
|
237
|
-
if (code === "page-frame") return "page frame";
|
|
238
|
-
return code.replaceAll("-", " ");
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function inspectionExpression() {
|
|
242
|
-
return `Promise.resolve().then(async () => {
|
|
243
|
-
const root = document.querySelector('[data-openpress-print-document="true"]');
|
|
244
|
-
if (!root || root.querySelectorAll('.openpress-html-page').length === 0) return null;
|
|
245
|
-
|
|
246
|
-
await document.fonts?.ready;
|
|
247
|
-
await Promise.all(Array.from(document.images).map(async (img) => {
|
|
248
|
-
if (!img.complete) {
|
|
249
|
-
await new Promise((resolve) => {
|
|
250
|
-
const settle = () => {
|
|
251
|
-
img.removeEventListener('load', settle);
|
|
252
|
-
img.removeEventListener('error', settle);
|
|
253
|
-
resolve();
|
|
254
|
-
};
|
|
255
|
-
img.addEventListener('load', settle, { once: true });
|
|
256
|
-
img.addEventListener('error', settle, { once: true });
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
await img.decode?.().catch(() => undefined);
|
|
260
|
-
}));
|
|
261
|
-
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
262
|
-
|
|
263
|
-
const textFor = (element) => (element?.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 120);
|
|
264
|
-
const overflowAmount = (outer, inner) => {
|
|
265
|
-
if (!outer || !inner) return 0;
|
|
266
|
-
const outerRect = outer.getBoundingClientRect();
|
|
267
|
-
const innerRect = inner.getBoundingClientRect();
|
|
268
|
-
return Math.max(0, innerRect.bottom - outerRect.bottom, innerRect.right - outerRect.right);
|
|
269
|
-
};
|
|
270
|
-
const contentBottomOverflow = (body) => {
|
|
271
|
-
if (!body) return 0;
|
|
272
|
-
const bodyRect = body.getBoundingClientRect();
|
|
273
|
-
const contentBottom = Array.from(body.children).reduce((bottom, child) => {
|
|
274
|
-
if (getComputedStyle(child).display === 'none') return bottom;
|
|
275
|
-
const marginBottom = Number.parseFloat(getComputedStyle(child).marginBottom) || 0;
|
|
276
|
-
return Math.max(bottom, child.getBoundingClientRect().bottom + marginBottom);
|
|
277
|
-
}, bodyRect.top);
|
|
278
|
-
return Math.max(0, contentBottom - bodyRect.bottom);
|
|
279
|
-
};
|
|
280
|
-
const addElementOverflow = (overflows, code, selector, container, element) => {
|
|
281
|
-
const px = overflowAmount(container, element);
|
|
282
|
-
if (px <= 1) return;
|
|
283
|
-
overflows.push({
|
|
284
|
-
code,
|
|
285
|
-
selector,
|
|
286
|
-
overflowPx: Math.ceil(px),
|
|
287
|
-
tagName: element.tagName,
|
|
288
|
-
text: textFor(element),
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
const wrappers = Array.from(document.querySelectorAll('.openpress-public-page > .openpress-html-page'));
|
|
293
|
-
if (wrappers.length === 0) return null;
|
|
294
|
-
return wrappers.map((wrapper, index) => {
|
|
295
|
-
const page = wrapper.querySelector('.reader-page') || wrapper;
|
|
296
|
-
const frame = page.querySelector('.page-frame') || page;
|
|
297
|
-
const body = page.querySelector('.page-body') || frame;
|
|
298
|
-
const sourcePath = wrapper.getAttribute('data-source-path') || undefined;
|
|
299
|
-
const sourceFile = wrapper.getAttribute('data-source-file') || sourcePath?.split('/').pop();
|
|
300
|
-
const overflows = [];
|
|
301
|
-
const bodyOverflow = contentBottomOverflow(body);
|
|
302
|
-
if (bodyOverflow > 1) {
|
|
303
|
-
overflows.push({
|
|
304
|
-
code: 'page-body',
|
|
305
|
-
selector: '.page-body',
|
|
306
|
-
overflowPx: Math.ceil(bodyOverflow),
|
|
307
|
-
tagName: body.tagName,
|
|
308
|
-
text: textFor(body),
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
addElementOverflow(overflows, 'page-frame', '.page-frame', page, frame);
|
|
312
|
-
body.querySelectorAll('table, img, pre, figure, [data-openpress-component]').forEach((element) => {
|
|
313
|
-
const tag = element.tagName.toLowerCase();
|
|
314
|
-
addElementOverflow(overflows, tag, tag, body, element);
|
|
315
|
-
});
|
|
316
|
-
return {
|
|
317
|
-
pageNumber: index + 1,
|
|
318
|
-
title: page.getAttribute('data-page-title') || wrapper.getAttribute('aria-label') || '',
|
|
319
|
-
source: sourcePath ? { file: sourceFile, path: sourcePath } : undefined,
|
|
320
|
-
overflows,
|
|
321
|
-
};
|
|
322
|
-
});
|
|
323
|
-
})`;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function delay(ms) {
|
|
327
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
328
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export function createIssue({ level = "warning", code, message, path = null, detail = undefined }) {
|
|
2
|
-
return {
|
|
3
|
-
level,
|
|
4
|
-
code,
|
|
5
|
-
message,
|
|
6
|
-
...(path ? { path } : {}),
|
|
7
|
-
...(detail !== undefined ? { detail } : {}),
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function createIssueReport({ kind, checked = [], issues = [], summary = undefined, okMessage = undefined }) {
|
|
12
|
-
const report = {
|
|
13
|
-
kind,
|
|
14
|
-
ok: issues.every((issue) => issue.level !== "error"),
|
|
15
|
-
checked,
|
|
16
|
-
issues,
|
|
17
|
-
...(summary !== undefined ? { summary } : {}),
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
...report,
|
|
21
|
-
format() {
|
|
22
|
-
return formatIssueReport(report, { okMessage });
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function exitCodeForIssueReport(report) {
|
|
28
|
-
return report.ok ? 0 : 1;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function formatIssueReport(report, { okMessage } = {}) {
|
|
32
|
-
if (report.issues.length === 0) return okMessage ?? `${capitalize(report.kind)} OK`;
|
|
33
|
-
return report.issues.map(formatIssue).join("\n");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function formatIssue(issue) {
|
|
37
|
-
const suffix = issue.path ? ` (${issue.path})` : "";
|
|
38
|
-
return `[${issue.level}] ${issue.code}: ${issue.message}${suffix}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function capitalize(value) {
|
|
42
|
-
const text = String(value ?? "");
|
|
43
|
-
return text ? `${text.charAt(0).toUpperCase()}${text.slice(1)}` : "Report";
|
|
44
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
export function rootRelativePath(config, absolutePath) {
|
|
4
|
-
return path.relative(config.root, absolutePath).replaceAll("\\", "/");
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function documentRelativePath(absolutePath, documentRoot) {
|
|
8
|
-
return path.relative(documentRoot, absolutePath).split(path.sep).join("/");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function resolveDocumentRelativePath(documentRoot, rel, label) {
|
|
12
|
-
if (typeof rel !== "string" || !rel.trim()) throw new Error(`${label} must be a non-empty document-relative path.`);
|
|
13
|
-
if (rel.includes("..")) throw new Error(`${label} contains "..", rejected.`);
|
|
14
|
-
const absolutePath = path.resolve(documentRoot, rel);
|
|
15
|
-
const relCheck = path.relative(documentRoot, absolutePath);
|
|
16
|
-
if (relCheck.startsWith("..") || path.isAbsolute(relCheck)) {
|
|
17
|
-
throw new Error(`${label} escapes the document root.`);
|
|
18
|
-
}
|
|
19
|
-
return absolutePath;
|
|
20
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type { ResolvedConfig } from "./config.mjs";
|
|
2
|
-
|
|
3
|
-
export type SourceTextScope = "content" | "all";
|
|
4
|
-
|
|
5
|
-
export type SourceTextMatch = {
|
|
6
|
-
id: string;
|
|
7
|
-
scope: string;
|
|
8
|
-
file: string;
|
|
9
|
-
path: string;
|
|
10
|
-
line: number;
|
|
11
|
-
column: number;
|
|
12
|
-
index: number;
|
|
13
|
-
text: string;
|
|
14
|
-
preview: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type SourceTextFileSummary = {
|
|
18
|
-
scope: string;
|
|
19
|
-
file: string;
|
|
20
|
-
path: string;
|
|
21
|
-
matchCount: number;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type SourceSearchReport = {
|
|
25
|
-
kind: "search";
|
|
26
|
-
query: string;
|
|
27
|
-
scope: SourceTextScope;
|
|
28
|
-
caseSensitive: boolean;
|
|
29
|
-
matchCount: number;
|
|
30
|
-
files: Array<SourceTextFileSummary>;
|
|
31
|
-
matches: Array<SourceTextMatch>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type SourceBlockTextEditInput = {
|
|
35
|
-
config: ResolvedConfig;
|
|
36
|
-
path: string;
|
|
37
|
-
source: {
|
|
38
|
-
line: number;
|
|
39
|
-
column?: number;
|
|
40
|
-
endLine?: number;
|
|
41
|
-
endColumn?: number;
|
|
42
|
-
};
|
|
43
|
-
text: string;
|
|
44
|
-
kind?: string;
|
|
45
|
-
name?: string;
|
|
46
|
-
blockId?: string;
|
|
47
|
-
cellIndex?: number;
|
|
48
|
-
sourceMode?: boolean;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export type SourceBlockTextEdit = {
|
|
52
|
-
blockId?: string;
|
|
53
|
-
path: string;
|
|
54
|
-
requestedPath: string;
|
|
55
|
-
file: string;
|
|
56
|
-
line: number;
|
|
57
|
-
column: number;
|
|
58
|
-
endLine: number;
|
|
59
|
-
endColumn: number;
|
|
60
|
-
before: string;
|
|
61
|
-
after: string;
|
|
62
|
-
text: string;
|
|
63
|
-
cellIndex?: number;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export function searchSourceText(options: {
|
|
67
|
-
config: ResolvedConfig;
|
|
68
|
-
query: string;
|
|
69
|
-
scope?: SourceTextScope;
|
|
70
|
-
caseSensitive?: boolean;
|
|
71
|
-
}): Promise<SourceSearchReport>;
|
|
72
|
-
|
|
73
|
-
export function applySourceBlockTextEdit(options: SourceBlockTextEditInput): Promise<SourceBlockTextEdit>;
|
|
74
|
-
|
|
75
|
-
export function applySourceBlockTextEditToText(documentText: string, options: Omit<SourceBlockTextEditInput, "config" | "path">): {
|
|
76
|
-
text: string;
|
|
77
|
-
edit: Omit<SourceBlockTextEdit, "path" | "requestedPath" | "file">;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export function readSourceBlockText(options: Pick<SourceBlockTextEditInput, "config" | "path" | "source">): Promise<{
|
|
81
|
-
path: string;
|
|
82
|
-
requestedPath: string;
|
|
83
|
-
file: string;
|
|
84
|
-
text: string;
|
|
85
|
-
}>;
|
|
86
|
-
|
|
87
|
-
export function readSourceBlockTextFromText(documentText: string, options: Pick<SourceBlockTextEditInput, "source">): string;
|
|
88
|
-
|
|
89
|
-
export function applySourceBlockSourceEditToText(documentText: string, options: Pick<SourceBlockTextEditInput, "source" | "text" | "blockId">): {
|
|
90
|
-
text: string;
|
|
91
|
-
edit: Omit<SourceBlockTextEdit, "path" | "requestedPath" | "file">;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export function collectSourceTextFiles(config: ResolvedConfig, options?: {
|
|
95
|
-
scope?: SourceTextScope;
|
|
96
|
-
}): Promise<Array<{
|
|
97
|
-
scope: string;
|
|
98
|
-
name: string;
|
|
99
|
-
absolutePath: string;
|
|
100
|
-
relativePath: string;
|
|
101
|
-
text: string;
|
|
102
|
-
}>>;
|