@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,136 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import { createRequire } from "node:module";
3
- import path from "node:path";
4
- import { pathToFileURL } from "node:url";
5
- import { buildComponentsCss, buildContentCss } from "../runtime/file-utils.mjs";
6
- import { buildSectionScopedCss } from "./section-css.mjs";
7
-
8
- const require = createRequire(import.meta.url);
9
-
10
- export async function buildReactMeasurementCss(root, config, workspace) {
11
- const parts = [];
12
- await appendOptionalFile(parts, path.join(config.paths.themeDir, "fonts.css"), "theme/fonts.css");
13
- await appendOptionalFile(parts, path.join(config.paths.themeDir, "tokens.css"), "theme/tokens.css");
14
- parts.push("/* === public/openpress/content.css === */\n");
15
- parts.push(await buildContentCss(root, config));
16
- parts.push("\n/* === public/openpress/components.css === */\n");
17
- parts.push(await buildComponentsCss(root, config));
18
- const chapterCss = await buildSectionScopedCss(workspace);
19
- if (chapterCss.trim()) {
20
- parts.push("\n/* === public/openpress/chapter-scoped.css === */\n");
21
- parts.push(chapterCss);
22
- }
23
- return rewriteAssetUrls(stripViewportMediaQueries(parts.join("\n")), config);
24
- }
25
-
26
- async function appendOptionalFile(parts, filePath, label) {
27
- try {
28
- const css = await fs.readFile(filePath, "utf8");
29
- parts.push(`/* === ${label} === */\n`);
30
- parts.push(css.trimEnd());
31
- parts.push("\n");
32
- } catch (error) {
33
- if (error?.code !== "ENOENT") throw error;
34
- }
35
- }
36
-
37
- function rewriteAssetUrls(css, config) {
38
- const themeFontsDir = pathToFileURL(path.join(config.paths.themeDir, "fonts") + path.sep).href;
39
- const katexFont = require.resolve("katex/dist/fonts/KaTeX_Main-Regular.woff2");
40
- const katexFontsDir = pathToFileURL(path.dirname(katexFont) + path.sep).href;
41
- return css
42
- .replace(/url\((["'])?\/openpress\/fonts\//g, `url($1${themeFontsDir}`)
43
- .replace(/url\((["'])?\/openpress\/katex-fonts\//g, `url($1${katexFontsDir}`);
44
- }
45
-
46
- function stripViewportMediaQueries(css) {
47
- let output = "";
48
- let cursor = 0;
49
-
50
- while (cursor < css.length) {
51
- const mediaIndex = css.indexOf("@media", cursor);
52
- if (mediaIndex < 0) {
53
- output += css.slice(cursor);
54
- break;
55
- }
56
-
57
- output += css.slice(cursor, mediaIndex);
58
- const blockStart = css.indexOf("{", mediaIndex);
59
- if (blockStart < 0) {
60
- output += css.slice(mediaIndex);
61
- break;
62
- }
63
-
64
- const prelude = css.slice(mediaIndex + "@media".length, blockStart);
65
- const blockEnd = findCssBlockEnd(css, blockStart);
66
- if (blockEnd < 0) {
67
- output += css.slice(mediaIndex);
68
- break;
69
- }
70
-
71
- if (!isViewportMediaPrelude(prelude)) {
72
- output += css.slice(mediaIndex, blockEnd + 1);
73
- }
74
- cursor = blockEnd + 1;
75
- }
76
-
77
- return output;
78
- }
79
-
80
- function isViewportMediaPrelude(prelude) {
81
- if (/\bprint\b/i.test(prelude)) return false;
82
- return /\(\s*(?:min-|max-)?(?:device-)?(?:width|height)\s*:/i.test(prelude)
83
- || /\(\s*orientation\s*:/i.test(prelude)
84
- || /\(\s*(?:min-|max-)?aspect-ratio\s*:/i.test(prelude);
85
- }
86
-
87
- function findCssBlockEnd(css, blockStart) {
88
- let depth = 0;
89
- let quote = "";
90
- let inComment = false;
91
-
92
- for (let index = blockStart; index < css.length; index += 1) {
93
- const current = css[index];
94
- const next = css[index + 1];
95
-
96
- if (inComment) {
97
- if (current === "*" && next === "/") {
98
- inComment = false;
99
- index += 1;
100
- }
101
- continue;
102
- }
103
-
104
- if (quote) {
105
- if (current === "\\") {
106
- index += 1;
107
- continue;
108
- }
109
- if (current === quote) quote = "";
110
- continue;
111
- }
112
-
113
- if (current === "/" && next === "*") {
114
- inComment = true;
115
- index += 1;
116
- continue;
117
- }
118
-
119
- if (current === "\"" || current === "'") {
120
- quote = current;
121
- continue;
122
- }
123
-
124
- if (current === "{") {
125
- depth += 1;
126
- continue;
127
- }
128
-
129
- if (current === "}") {
130
- depth -= 1;
131
- if (depth === 0) return index;
132
- }
133
- }
134
-
135
- return -1;
136
- }
@@ -1,119 +0,0 @@
1
- export function createObjectEntityId(kind, ...parts) {
2
- return [kind, ...parts.map((part) => encodeURIComponent(String(part)))].join(":");
3
- }
4
-
5
- export function createBlockObjectEntityId(blockId) {
6
- return createObjectEntityId("mdx-block", blockId);
7
- }
8
-
9
- export function createPageObjectEntityId(frameKey) {
10
- return createObjectEntityId("page", frameKey);
11
- }
12
-
13
- export function createFrameObjectEntityId(frameKey) {
14
- return createObjectEntityId("frame", frameKey);
15
- }
16
-
17
- export function createMdxAreaObjectEntityId(frameKey, chainId, indexInFrame) {
18
- return createObjectEntityId("mdx-area", frameKey, chainId, indexInFrame);
19
- }
20
-
21
- export function buildObjectEntities({ frames, blocks, blockMap }) {
22
- const entities = {};
23
- const blockParentIdByBlockId = new Map();
24
-
25
- for (const block of blocks) {
26
- const frameKey = block.frameKey ?? block.id;
27
- const sourcePath = block.source?.path;
28
- const pageId = createPageObjectEntityId(frameKey);
29
- const base = {
30
- frameKey,
31
- pageId,
32
- source: sourcePath
33
- ? {
34
- path: sourcePath,
35
- file: block.source?.file,
36
- line: 1,
37
- column: 1,
38
- }
39
- : undefined,
40
- };
41
-
42
- entities[pageId] = {
43
- id: pageId,
44
- kind: "page",
45
- label: block.title || `Page ${block.pageNumber}`,
46
- ...base,
47
- };
48
-
49
- const frameId = createFrameObjectEntityId(frameKey);
50
- entities[frameId] = {
51
- id: frameId,
52
- kind: "frame",
53
- label: block.role || block.title || frameKey,
54
- ...base,
55
- parentId: pageId,
56
- metadata: { role: block.role ?? null, chrome: block.chrome ?? null },
57
- };
58
- }
59
-
60
- for (const frame of frames) {
61
- const pageId = createPageObjectEntityId(frame.frameKey);
62
- const frameId = createFrameObjectEntityId(frame.frameKey);
63
- for (const area of frame.mdxAreas ?? []) {
64
- const id = createMdxAreaObjectEntityId(frame.frameKey, area.chainId, area.indexInFrame);
65
- const firstEditableBlock = (area.blockIds ?? [])
66
- .map((blockId) => blockMap[blockId])
67
- .find((block) => block?.path);
68
- for (const blockId of area.blockIds ?? []) blockParentIdByBlockId.set(blockId, id);
69
- entities[id] = {
70
- id,
71
- kind: "mdx-area",
72
- label: `${area.chainId} area ${area.indexInFrame + 1}`,
73
- parentId: frameId,
74
- pageId,
75
- frameKey: frame.frameKey,
76
- chainId: area.chainId,
77
- source: firstEditableBlock
78
- ? {
79
- path: firstEditableBlock.path,
80
- source: firstEditableBlock.source,
81
- line: firstEditableBlock.source?.line,
82
- column: firstEditableBlock.source?.column,
83
- }
84
- : undefined,
85
- metadata: { blockCount: area.blockIds?.length ?? 0 },
86
- };
87
- }
88
- }
89
-
90
- for (const block of Object.values(blockMap)) {
91
- if (!block?.id) continue;
92
- const id = createBlockObjectEntityId(block.id);
93
- const pageId = block.frameKey ? createPageObjectEntityId(block.frameKey) : undefined;
94
- entities[id] = {
95
- id,
96
- kind: "mdx-block",
97
- label: block.name ? `${block.name} ${block.id}` : block.id,
98
- parentId: blockParentIdByBlockId.get(block.id),
99
- pageId,
100
- blockId: block.id,
101
- frameKey: block.frameKey,
102
- chainId: block.chainId,
103
- source: block.path
104
- ? {
105
- path: block.path,
106
- source: block.source,
107
- line: block.source?.line,
108
- column: block.source?.column,
109
- }
110
- : undefined,
111
- metadata: {
112
- blockKind: block.kind ?? null,
113
- componentName: block.kind === "component" ? block.name ?? null : null,
114
- },
115
- };
116
- }
117
-
118
- return entities;
119
- }
@@ -1,122 +0,0 @@
1
- import { DEFAULT_PAGE_SAFE_HEIGHT_PX } from "../pagination-constants.mjs";
2
- import { singleColumnRegionStream } from "./regions.mjs";
3
-
4
- // Pure region-based block allocator.
5
- //
6
- // Greedy bin-packing: walk measured blocks in order, append to the current
7
- // region until adding the next block would exceed capacity, then advance to
8
- // the next region. Pages are a derived view (grouping by pageIndex), so the
9
- // same code paginates single-column, multi-column, and heterogeneous layouts.
10
- export function allocateBlocksToRegions(measuredBlocks, regionStream) {
11
- const filled = [];
12
- const warnings = [];
13
- let current = regionStream.next();
14
- if (!current) {
15
- return { regions: filled, warnings: [{ code: "out-of-regions" }] };
16
- }
17
- let currentBlockIds = [];
18
- let currentHeight = 0;
19
-
20
- const flush = () => {
21
- if (currentBlockIds.length === 0) return;
22
- filled.push({
23
- regionId: current.id,
24
- pageIndex: current.pageIndex,
25
- columnIndex: current.columnIndex,
26
- blockIds: currentBlockIds,
27
- });
28
- currentBlockIds = [];
29
- currentHeight = 0;
30
- };
31
-
32
- for (const block of measuredBlocks ?? []) {
33
- const id = String(block?.id ?? "");
34
- if (!id) continue;
35
- const height = Math.max(0, Number(block.height) || 0);
36
-
37
- if (height > current.capacity) {
38
- warnings.push({
39
- code: "block-overflows-region",
40
- blockId: id,
41
- height,
42
- regionCapacity: current.capacity,
43
- regionId: current.id,
44
- pageIndex: current.pageIndex,
45
- });
46
- }
47
-
48
- if (currentBlockIds.length > 0 && currentHeight + height > current.capacity) {
49
- flush();
50
- const next = regionStream.next();
51
- if (!next) {
52
- warnings.push({ code: "out-of-regions", blockId: id });
53
- break;
54
- }
55
- current = next;
56
- }
57
-
58
- currentBlockIds.push(id);
59
- currentHeight += height;
60
- }
61
-
62
- flush();
63
- return { regions: filled, warnings };
64
- }
65
-
66
- // Derive a flat pages[] view from filled regions. Blocks within a page are
67
- // emitted in column order (col 0, col 1, ...) — matching how readers consume
68
- // a multi-column page (left-to-right, top-to-bottom).
69
- export function pagesFromRegions(filledRegions) {
70
- const byPage = new Map();
71
- for (const region of filledRegions) {
72
- if (!byPage.has(region.pageIndex)) byPage.set(region.pageIndex, []);
73
- byPage.get(region.pageIndex).push(region);
74
- }
75
- const pages = [];
76
- for (const [pageIndex, regionsOnPage] of [...byPage.entries()].sort((a, b) => a[0] - b[0])) {
77
- const sorted = regionsOnPage.slice().sort((a, b) => a.columnIndex - b.columnIndex);
78
- const blockIds = sorted.flatMap((r) => r.blockIds);
79
- pages.push({
80
- pageIndex,
81
- blockIds,
82
- breakAfter: blockIds.at(-1),
83
- });
84
- }
85
- return pages;
86
- }
87
-
88
- // Public wrapper preserving the legacy (blocks, { pageSafeHeightPx }) signature.
89
- // New code can pass a `regions` stream directly to opt into multi-column or
90
- // heterogeneous layouts.
91
- export function paginateMeasuredBlocks(measuredBlocks, options = {}) {
92
- const { pageSafeHeightPx = DEFAULT_PAGE_SAFE_HEIGHT_PX, regions } = options;
93
- const safeHeight = positiveNumber(pageSafeHeightPx, DEFAULT_PAGE_SAFE_HEIGHT_PX);
94
- const stream = regions ?? singleColumnRegionStream({ pageSafeHeightPx: safeHeight });
95
- const { regions: filledRegions, warnings } = allocateBlocksToRegions(measuredBlocks, stream);
96
- const pages = pagesFromRegions(filledRegions);
97
- return {
98
- pages,
99
- regions: filledRegions,
100
- warnings: warnings.map((w) => mapWarning(w, safeHeight)),
101
- };
102
- }
103
-
104
- // Translate the new region-shaped warnings back to the legacy
105
- // `block-overflows-page` schema that document-export.mjs and downstream
106
- // consumers expect. Once consumers migrate, this can drop.
107
- function mapWarning(warning, pageSafeHeightPx) {
108
- if (warning.code === "block-overflows-region") {
109
- return {
110
- code: "block-overflows-page",
111
- blockId: warning.blockId,
112
- height: warning.height,
113
- pageSafeHeightPx,
114
- };
115
- }
116
- return warning;
117
- }
118
-
119
- function positiveNumber(value, fallback) {
120
- const number = Number(value);
121
- return Number.isFinite(number) && number > 0 ? number : fallback;
122
- }
@@ -1,81 +0,0 @@
1
- // A Region is a fillable area on a page — the engine treats pagination as a
2
- // stream of regions consumed in order. One single-column page is "one region";
3
- // a two-column page is two regions on the same pageIndex; a newspaper page
4
- // could be three (main-left, main-right, sidebar).
5
- //
6
- // A RegionStream is a lazy iterator that yields regions on demand. The
7
- // allocator pulls the next region when the current one is full. This makes
8
- // "multi-column" and "newspaper-style mixed layout" the same code path as
9
- // single-column — only the stream differs.
10
- //
11
- // Shape:
12
- // Region = { id: string, capacity: number, pageIndex: number, columnIndex: number }
13
- // RegionStream = { next(): Region } | Iterable<Region>
14
-
15
- /**
16
- * Default region stream: an infinite sequence of single-column pages.
17
- * Equivalent to today's "one safe-height page after another" behavior.
18
- */
19
- export function singleColumnRegionStream({ pageSafeHeightPx }) {
20
- return iteratorFromGenerator(function* () {
21
- let pageIndex = 0;
22
- while (true) {
23
- yield {
24
- id: `page-${pageIndex}-col-0`,
25
- capacity: pageSafeHeightPx,
26
- pageIndex,
27
- columnIndex: 0,
28
- };
29
- pageIndex++;
30
- }
31
- });
32
- }
33
-
34
- /**
35
- * Multi-column region stream: each page yields `columnCount` regions in order,
36
- * all sharing the same pageIndex but with increasing columnIndex.
37
- *
38
- * Blocks fill column 0 first, then column 1, then advance to the next page's
39
- * column 0 — same greedy semantics as single-column, just more regions per page.
40
- */
41
- export function multiColumnRegionStream({ pageSafeHeightPx, columnCount }) {
42
- const cols = Math.max(1, Math.floor(columnCount) || 1);
43
- return iteratorFromGenerator(function* () {
44
- let pageIndex = 0;
45
- while (true) {
46
- for (let col = 0; col < cols; col++) {
47
- yield {
48
- id: `page-${pageIndex}-col-${col}`,
49
- capacity: pageSafeHeightPx,
50
- pageIndex,
51
- columnIndex: col,
52
- };
53
- }
54
- pageIndex++;
55
- }
56
- });
57
- }
58
-
59
- /**
60
- * Build a region stream from an explicit list of regions. Useful for
61
- * heterogeneous layouts (e.g. a research-article first page with a wide
62
- * abstract region on top + two narrow columns below). Stream ends when
63
- * the list is exhausted — the caller is responsible for providing enough
64
- * regions; the allocator emits an `out-of-regions` warning otherwise.
65
- */
66
- export function fixedRegionStream(regions) {
67
- const list = Array.isArray(regions) ? regions : [];
68
- return iteratorFromGenerator(function* () {
69
- for (const region of list) yield region;
70
- });
71
- }
72
-
73
- function iteratorFromGenerator(genFn) {
74
- const iter = genFn();
75
- return {
76
- next() {
77
- const { value, done } = iter.next();
78
- return done ? null : value;
79
- },
80
- };
81
- }
@@ -1,3 +0,0 @@
1
- export const DEFAULT_PAGE_SAFE_HEIGHT_PX = 930;
2
- export const PAGE_BODY_FIT_SAFETY_RATIO = 0.08;
3
- export const PAGE_BODY_FIT_SAFETY_MAX_PX = 96;
@@ -1,9 +0,0 @@
1
- // Public surface for the build-time region allocator.
2
- //
3
- // The Press Tree pipeline measures MdxArea capacities and block heights in
4
- // `engine/react/pipeline/frame-measurement.mjs` and runs allocation through
5
- // these helpers. The region kernel is also usable on its own for custom
6
- // pipelines or unit tests.
7
-
8
- export { paginateMeasuredBlocks, allocateBlocksToRegions, pagesFromRegions } from "./pagination/allocator.mjs";
9
- export { singleColumnRegionStream, multiColumnRegionStream, fixedRegionStream } from "./pagination/regions.mjs";