@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,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
- }>>;