@open-press/cli 1.0.0 → 1.1.1

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 (175) hide show
  1. package/README.md +11 -12
  2. package/dist/cli.js +298 -79
  3. package/package.json +9 -7
  4. package/template/core/AGENTS.md +0 -130
  5. package/template/core/CHANGELOG.md +0 -218
  6. package/template/core/README.md +0 -43
  7. package/template/core/engine/cli.mjs +0 -96
  8. package/template/core/engine/commands/_shared.mjs +0 -199
  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/image.mjs +0 -29
  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/skills-sync.mjs +0 -71
  21. package/template/core/engine/commands/typecheck.mjs +0 -67
  22. package/template/core/engine/commands/upgrade.mjs +0 -159
  23. package/template/core/engine/commands/validate.mjs +0 -17
  24. package/template/core/engine/document-export.mjs +0 -15
  25. package/template/core/engine/output/chrome-pdf.d.mts +0 -34
  26. package/template/core/engine/output/chrome-pdf.mjs +0 -450
  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 -571
  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 -331
  39. package/template/core/engine/react/document-export.mjs +0 -512
  40. package/template/core/engine/react/http-json.mjs +0 -24
  41. package/template/core/engine/react/mdx-compile.mjs +0 -629
  42. package/template/core/engine/react/measurement-css.mjs +0 -157
  43. package/template/core/engine/react/object-entities.mjs +0 -204
  44. package/template/core/engine/react/pagination/allocator.mjs +0 -167
  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 -217
  49. package/template/core/engine/react/pipeline/final-render.mjs +0 -94
  50. package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -306
  51. package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
  52. package/template/core/engine/react/press-tree-inspection.mjs +0 -172
  53. package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
  54. package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
  55. package/template/core/engine/react/section-css.mjs +0 -56
  56. package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
  57. package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
  58. package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
  59. package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
  60. package/template/core/engine/react/style-discovery.mjs +0 -160
  61. package/template/core/engine/runtime/config.d.mts +0 -48
  62. package/template/core/engine/runtime/config.mjs +0 -172
  63. package/template/core/engine/runtime/file-utils.mjs +0 -114
  64. package/template/core/engine/runtime/file-walk.mjs +0 -22
  65. package/template/core/engine/runtime/inspection.mjs +0 -328
  66. package/template/core/engine/runtime/issue-report.mjs +0 -44
  67. package/template/core/engine/runtime/page-geometry.mjs +0 -131
  68. package/template/core/engine/runtime/path-utils.mjs +0 -20
  69. package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
  70. package/template/core/engine/runtime/source-text-tools.mjs +0 -832
  71. package/template/core/engine/runtime/source-workspace.mjs +0 -168
  72. package/template/core/engine/runtime/validation.mjs +0 -183
  73. package/template/core/index.html +0 -13
  74. package/template/core/openpress.config.mjs +0 -8
  75. package/template/core/package.json +0 -89
  76. package/template/core/src/main.tsx +0 -16
  77. package/template/core/src/openpress/app/OpenPressApp.tsx +0 -296
  78. package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -102
  79. package/template/core/src/openpress/app/WorkspaceGalleryPage.tsx +0 -219
  80. package/template/core/src/openpress/app/index.ts +0 -2
  81. package/template/core/src/openpress/core/Frame.tsx +0 -91
  82. package/template/core/src/openpress/core/FrameContext.tsx +0 -26
  83. package/template/core/src/openpress/core/MdxArea.tsx +0 -34
  84. package/template/core/src/openpress/core/Press.tsx +0 -55
  85. package/template/core/src/openpress/core/Workspace.tsx +0 -36
  86. package/template/core/src/openpress/core/cn.ts +0 -4
  87. package/template/core/src/openpress/core/index.tsx +0 -47
  88. package/template/core/src/openpress/core/primitives.tsx +0 -91
  89. package/template/core/src/openpress/core/types.ts +0 -236
  90. package/template/core/src/openpress/core/useSource.ts +0 -28
  91. package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
  92. package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
  93. package/template/core/src/openpress/document-model/documentTypes.ts +0 -147
  94. package/template/core/src/openpress/document-model/index.ts +0 -7
  95. package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -55
  96. package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
  97. package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
  98. package/template/core/src/openpress/document-model/workspaceManifestModel.ts +0 -57
  99. package/template/core/src/openpress/manuscript/index.tsx +0 -238
  100. package/template/core/src/openpress/mdx/index.ts +0 -96
  101. package/template/core/src/openpress/numbering/index.ts +0 -294
  102. package/template/core/src/openpress/reader/PageThumbnailsPanel.tsx +0 -168
  103. package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
  104. package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
  105. package/template/core/src/openpress/reader/index.ts +0 -11
  106. package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
  107. package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
  108. package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
  109. package/template/core/src/openpress/reader/readerScroll.ts +0 -92
  110. package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
  111. package/template/core/src/openpress/reader/readerTypes.ts +0 -4
  112. package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
  113. package/template/core/src/openpress/reader/usePanelState.ts +0 -56
  114. package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
  115. package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
  116. package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
  117. package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
  118. package/template/core/src/openpress/shared/Panel.tsx +0 -77
  119. package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
  120. package/template/core/src/openpress/shared/index.ts +0 -4
  121. package/template/core/src/openpress/shared/numberUtils.ts +0 -3
  122. package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
  123. package/template/core/src/openpress/workbench/Workbench.tsx +0 -506
  124. package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
  125. package/template/core/src/openpress/workbench/actions/ExportImageControl.tsx +0 -96
  126. package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
  127. package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
  128. package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
  129. package/template/core/src/openpress/workbench/actions/index.ts +0 -6
  130. package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
  131. package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
  132. package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
  133. package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
  134. package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
  135. package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
  136. package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
  137. package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
  138. package/template/core/src/openpress/workbench/document/index.ts +0 -10
  139. package/template/core/src/openpress/workbench/index.ts +0 -2
  140. package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
  141. package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
  142. package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
  143. package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
  144. package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
  145. package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -254
  146. package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
  147. package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
  148. package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
  149. package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
  150. package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -80
  151. package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
  152. package/template/core/src/openpress/workbench/panels/index.ts +0 -3
  153. package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -525
  154. package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
  155. package/template/core/src/openpress/workbench/project/index.ts +0 -2
  156. package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
  157. package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
  158. package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
  159. package/template/core/src/openpress/workbench/shell/index.ts +0 -1
  160. package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
  161. package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
  162. package/template/core/src/styles/openpress/app-shell.css +0 -251
  163. package/template/core/src/styles/openpress/media-workspace.css +0 -230
  164. package/template/core/src/styles/openpress/print-route.css +0 -184
  165. package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
  166. package/template/core/src/styles/openpress/public-viewer.css +0 -688
  167. package/template/core/src/styles/openpress/reader-runtime.css +0 -989
  168. package/template/core/src/styles/openpress/responsive.css +0 -245
  169. package/template/core/src/styles/openpress/workbench-panels.css +0 -707
  170. package/template/core/src/styles/openpress/workbench.css +0 -1255
  171. package/template/core/src/styles/openpress/workspace-gallery.css +0 -300
  172. package/template/core/src/styles/openpress.css +0 -15
  173. package/template/core/src/vite-env.d.ts +0 -9
  174. package/template/core/tsconfig.json +0 -40
  175. package/template/core/vite.config.ts +0 -584
@@ -1,157 +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 { pageGeometryToTheme } from "../runtime/page-geometry.mjs";
7
- import { buildSectionScopedCss } from "./section-css.mjs";
8
-
9
- const require = createRequire(import.meta.url);
10
-
11
- export async function buildReactMeasurementCss(root, config, workspace) {
12
- const parts = [];
13
- await appendOptionalFile(parts, path.join(config.paths.themeDir, "fonts.css"), "theme/fonts.css");
14
- await appendOptionalFile(parts, path.join(config.paths.themeDir, "tokens.css"), "theme/tokens.css");
15
- appendPageGeometryCss(parts, config.page);
16
- parts.push("/* === public/openpress/content.css === */\n");
17
- parts.push(await buildContentCss(root, config));
18
- parts.push("\n/* === public/openpress/components.css === */\n");
19
- parts.push(await buildComponentsCss(root, config));
20
- const chapterCss = await buildSectionScopedCss(workspace);
21
- if (chapterCss.trim()) {
22
- parts.push("\n/* === public/openpress/chapter-scoped.css === */\n");
23
- parts.push(chapterCss);
24
- }
25
- return rewriteAssetUrls(stripViewportMediaQueries(parts.join("\n")), config);
26
- }
27
-
28
- function appendPageGeometryCss(parts, page) {
29
- const theme = pageGeometryToTheme(page);
30
- if (!theme) return;
31
-
32
- const declarations = [
33
- ["--openpress-page-width", theme.pageWidth],
34
- ["--openpress-page-height", theme.pageHeight],
35
- ["--openpress-page-aspect-ratio", theme.pageAspectRatio],
36
- ["--openpress-page-height-ratio", theme.pageHeightRatio],
37
- ].filter(([, value]) => value);
38
-
39
- parts.push("/* === openpress page geometry === */\n");
40
- parts.push(":root {\n");
41
- for (const [name, value] of declarations) {
42
- parts.push(` ${name}: ${value};\n`);
43
- }
44
- parts.push("}\n\n");
45
- }
46
-
47
- async function appendOptionalFile(parts, filePath, label) {
48
- try {
49
- const css = await fs.readFile(filePath, "utf8");
50
- parts.push(`/* === ${label} === */\n`);
51
- parts.push(css.trimEnd());
52
- parts.push("\n");
53
- } catch (error) {
54
- if (error?.code !== "ENOENT") throw error;
55
- }
56
- }
57
-
58
- function rewriteAssetUrls(css, config) {
59
- const themeFontsDir = pathToFileURL(path.join(config.paths.themeDir, "fonts") + path.sep).href;
60
- const katexFont = require.resolve("katex/dist/fonts/KaTeX_Main-Regular.woff2");
61
- const katexFontsDir = pathToFileURL(path.dirname(katexFont) + path.sep).href;
62
- return css
63
- .replace(/url\((["'])?\/openpress\/fonts\//g, `url($1${themeFontsDir}`)
64
- .replace(/url\((["'])?\/openpress\/katex-fonts\//g, `url($1${katexFontsDir}`);
65
- }
66
-
67
- function stripViewportMediaQueries(css) {
68
- let output = "";
69
- let cursor = 0;
70
-
71
- while (cursor < css.length) {
72
- const mediaIndex = css.indexOf("@media", cursor);
73
- if (mediaIndex < 0) {
74
- output += css.slice(cursor);
75
- break;
76
- }
77
-
78
- output += css.slice(cursor, mediaIndex);
79
- const blockStart = css.indexOf("{", mediaIndex);
80
- if (blockStart < 0) {
81
- output += css.slice(mediaIndex);
82
- break;
83
- }
84
-
85
- const prelude = css.slice(mediaIndex + "@media".length, blockStart);
86
- const blockEnd = findCssBlockEnd(css, blockStart);
87
- if (blockEnd < 0) {
88
- output += css.slice(mediaIndex);
89
- break;
90
- }
91
-
92
- if (!isViewportMediaPrelude(prelude)) {
93
- output += css.slice(mediaIndex, blockEnd + 1);
94
- }
95
- cursor = blockEnd + 1;
96
- }
97
-
98
- return output;
99
- }
100
-
101
- function isViewportMediaPrelude(prelude) {
102
- if (/\bprint\b/i.test(prelude)) return false;
103
- return /\(\s*(?:min-|max-)?(?:device-)?(?:width|height)\s*:/i.test(prelude)
104
- || /\(\s*orientation\s*:/i.test(prelude)
105
- || /\(\s*(?:min-|max-)?aspect-ratio\s*:/i.test(prelude);
106
- }
107
-
108
- function findCssBlockEnd(css, blockStart) {
109
- let depth = 0;
110
- let quote = "";
111
- let inComment = false;
112
-
113
- for (let index = blockStart; index < css.length; index += 1) {
114
- const current = css[index];
115
- const next = css[index + 1];
116
-
117
- if (inComment) {
118
- if (current === "*" && next === "/") {
119
- inComment = false;
120
- index += 1;
121
- }
122
- continue;
123
- }
124
-
125
- if (quote) {
126
- if (current === "\\") {
127
- index += 1;
128
- continue;
129
- }
130
- if (current === quote) quote = "";
131
- continue;
132
- }
133
-
134
- if (current === "/" && next === "*") {
135
- inComment = true;
136
- index += 1;
137
- continue;
138
- }
139
-
140
- if (current === "\"" || current === "'") {
141
- quote = current;
142
- continue;
143
- }
144
-
145
- if (current === "{") {
146
- depth += 1;
147
- continue;
148
- }
149
-
150
- if (current === "}") {
151
- depth -= 1;
152
- if (depth === 0) return index;
153
- }
154
- }
155
-
156
- return -1;
157
- }
@@ -1,204 +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 createScopedObjectEntityId(kind, parentId, objectId) {
18
- return parentId ? createObjectEntityId(kind, parentId, objectId) : createObjectEntityId(kind, objectId);
19
- }
20
-
21
- export function createMdxAreaObjectEntityId(frameKey, chainId, indexInFrame) {
22
- return createObjectEntityId("mdx-area", frameKey, chainId, indexInFrame);
23
- }
24
-
25
- export function buildObjectEntities({ frames, blocks, blockMap }) {
26
- const entities = {};
27
- const blockParentIdByBlockId = new Map();
28
-
29
- for (const block of blocks) {
30
- const frameKey = block.frameKey ?? block.id;
31
- const sourcePath = block.source?.path;
32
- const pageId = createPageObjectEntityId(frameKey);
33
- const base = {
34
- frameKey,
35
- pageId,
36
- source: sourcePath
37
- ? {
38
- path: sourcePath,
39
- file: block.source?.file,
40
- line: 1,
41
- column: 1,
42
- }
43
- : undefined,
44
- };
45
-
46
- entities[pageId] = {
47
- id: pageId,
48
- kind: "page",
49
- label: block.title || `Page ${block.pageNumber}`,
50
- ...base,
51
- };
52
-
53
- const frameId = createFrameObjectEntityId(frameKey);
54
- entities[frameId] = {
55
- id: frameId,
56
- kind: "frame",
57
- label: block.role || block.title || frameKey,
58
- ...base,
59
- parentId: pageId,
60
- metadata: { role: block.role ?? null, chrome: block.chrome ?? null },
61
- };
62
- }
63
-
64
- for (const frame of frames) {
65
- const pageId = createPageObjectEntityId(frame.frameKey);
66
- const frameId = createFrameObjectEntityId(frame.frameKey);
67
- for (const area of frame.mdxAreas ?? []) {
68
- const id = createMdxAreaObjectEntityId(frame.frameKey, area.chainId, area.indexInFrame);
69
- const firstEditableBlock = (area.blockIds ?? [])
70
- .map((blockId) => blockMap[blockId])
71
- .find((block) => block?.path);
72
- for (const blockId of area.blockIds ?? []) blockParentIdByBlockId.set(blockId, id);
73
- entities[id] = {
74
- id,
75
- kind: "mdx-area",
76
- label: `${area.chainId} area ${area.indexInFrame + 1}`,
77
- parentId: frameId,
78
- pageId,
79
- frameKey: frame.frameKey,
80
- chainId: area.chainId,
81
- source: firstEditableBlock
82
- ? {
83
- path: firstEditableBlock.path,
84
- source: firstEditableBlock.source,
85
- line: firstEditableBlock.source?.line,
86
- column: firstEditableBlock.source?.column,
87
- }
88
- : undefined,
89
- metadata: { blockCount: area.blockIds?.length ?? 0 },
90
- };
91
- }
92
- }
93
-
94
- for (const block of Object.values(blockMap)) {
95
- if (!block?.id) continue;
96
- const id = createBlockObjectEntityId(block.id);
97
- const pageId = block.frameKey ? createPageObjectEntityId(block.frameKey) : undefined;
98
- entities[id] = {
99
- id,
100
- kind: "mdx-block",
101
- label: block.name ? `${block.name} ${block.id}` : block.id,
102
- parentId: blockParentIdByBlockId.get(block.id),
103
- pageId,
104
- blockId: block.id,
105
- frameKey: block.frameKey,
106
- chainId: block.chainId,
107
- source: block.path
108
- ? {
109
- path: block.path,
110
- source: block.source,
111
- line: block.source?.line,
112
- column: block.source?.column,
113
- }
114
- : undefined,
115
- metadata: {
116
- blockKind: block.kind ?? null,
117
- componentName: block.kind === "component" ? block.name ?? null : null,
118
- },
119
- };
120
- }
121
-
122
- for (const entity of collectRenderedObjectEntities(frames)) {
123
- if (!entity.id || entities[entity.id]) continue;
124
- const pageId = entity.pageId || createPageObjectEntityId(entity.frameKey);
125
- const frameId = createFrameObjectEntityId(entity.frameKey);
126
- entities[entity.id] = {
127
- id: entity.id,
128
- kind: entity.kind,
129
- label: entity.label || entity.id,
130
- parentId: entity.parentId || (entity.id === frameId ? pageId : frameId),
131
- pageId,
132
- blockId: entity.blockId,
133
- frameKey: entity.frameKey,
134
- chainId: entity.chainId,
135
- source: entity.source,
136
- metadata: entity.metadata,
137
- };
138
- }
139
-
140
- return entities;
141
- }
142
-
143
- const OBJECT_OPEN_RE = /<([a-z][a-z0-9-]*)\b([^>]*)\bdata-openpress-object-id="([^"]+)"([^>]*)>/gi;
144
- const ATTR_RE = (name) => new RegExp(`\\b${name}="([^"]*)"`);
145
-
146
- function collectRenderedObjectEntities(frames) {
147
- const entities = [];
148
- for (const frame of frames) {
149
- const pageId = createPageObjectEntityId(frame.frameKey);
150
- const frameId = createFrameObjectEntityId(frame.frameKey);
151
- const html = String(frame.html ?? "");
152
- let match;
153
- OBJECT_OPEN_RE.lastIndex = 0;
154
- while ((match = OBJECT_OPEN_RE.exec(html)) !== null) {
155
- const attrs = `${match[2] ?? ""} data-openpress-object-id="${match[3] ?? ""}" ${match[4] ?? ""}`;
156
- const id = htmlDecode(match[3] ?? "");
157
- const kind = htmlDecode(pickAttr(attrs, "data-openpress-object-kind")) || objectKindFromId(id);
158
- if (!id || !kind) continue;
159
- entities.push({
160
- id,
161
- kind,
162
- label: htmlDecode(pickAttr(attrs, "data-openpress-object-label")) || id,
163
- parentId: htmlDecode(pickAttr(attrs, "data-openpress-object-parent-id")) || (id === frameId ? pageId : frameId),
164
- pageId: htmlDecode(pickAttr(attrs, "data-openpress-object-page-id")) || pageId,
165
- blockId: htmlDecode(pickAttr(attrs, "data-openpress-block-id")) || undefined,
166
- frameKey: htmlDecode(pickAttr(attrs, "data-openpress-object-frame-key")) || frame.frameKey,
167
- chainId: htmlDecode(pickAttr(attrs, "data-openpress-object-chain-id")) || undefined,
168
- source: parseJsonAttribute(pickAttr(attrs, "data-openpress-object-source")),
169
- metadata: parseJsonAttribute(pickAttr(attrs, "data-openpress-object-metadata")),
170
- });
171
- }
172
- }
173
- return entities;
174
- }
175
-
176
- function pickAttr(attrs, name) {
177
- const match = ATTR_RE(name).exec(attrs);
178
- return match ? match[1] : "";
179
- }
180
-
181
- function objectKindFromId(id) {
182
- const separator = id.indexOf(":");
183
- return separator === -1 ? "" : id.slice(0, separator);
184
- }
185
-
186
- function parseJsonAttribute(value) {
187
- const decoded = htmlDecode(value);
188
- if (!decoded) return undefined;
189
- try {
190
- return JSON.parse(decoded);
191
- } catch {
192
- return undefined;
193
- }
194
- }
195
-
196
- function htmlDecode(value) {
197
- return String(value ?? "")
198
- .replaceAll("&quot;", '"')
199
- .replaceAll("&#x27;", "'")
200
- .replaceAll("&#39;", "'")
201
- .replaceAll("&lt;", "<")
202
- .replaceAll("&gt;", ">")
203
- .replaceAll("&amp;", "&");
204
- }
@@ -1,167 +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, options = {}) {
11
- const keepWithNext = typeof options.keepWithNext === "function" ? options.keepWithNext : null;
12
- const filled = [];
13
- const warnings = [];
14
- let current = regionStream.next();
15
- if (!current) {
16
- return { regions: filled, warnings: [{ code: "out-of-regions" }] };
17
- }
18
- let currentBlockIds = [];
19
- let currentHeight = 0;
20
- let consumedCount = 0;
21
-
22
- const flush = () => {
23
- if (currentBlockIds.length === 0) return;
24
- filled.push({
25
- regionId: current.id,
26
- pageIndex: current.pageIndex,
27
- columnIndex: current.columnIndex,
28
- blockIds: currentBlockIds,
29
- });
30
- currentBlockIds = [];
31
- currentHeight = 0;
32
- };
33
-
34
- const blocks = measuredBlocks ?? [];
35
- for (let blockIndex = 0; blockIndex < blocks.length; blockIndex += 1) {
36
- const block = blocks[blockIndex];
37
- const id = String(block?.id ?? "");
38
- if (!id) continue;
39
- const height = Math.max(0, Number(block.height) || 0);
40
-
41
- if (height > current.capacity) {
42
- warnings.push({
43
- code: "block-overflows-region",
44
- blockId: id,
45
- height,
46
- regionCapacity: current.capacity,
47
- regionId: current.id,
48
- pageIndex: current.pageIndex,
49
- });
50
- }
51
-
52
- const nextBlock = blocks[blockIndex + 1];
53
- const nextHeight = Math.max(0, Number(nextBlock?.height) || 0);
54
- const keepWithNextHeight = keepWithNext?.(block, nextBlock) ? height + nextHeight : 0;
55
-
56
- if (
57
- currentBlockIds.length > 0 &&
58
- keepWithNextHeight > 0 &&
59
- currentHeight + keepWithNextHeight > current.capacity
60
- ) {
61
- flush();
62
- const next = regionStream.next();
63
- if (!next) {
64
- warnings.push({ code: "out-of-regions", blockId: id });
65
- break;
66
- }
67
- current = next;
68
- }
69
-
70
- if (currentBlockIds.length > 0 && currentHeight + height > current.capacity) {
71
- flush();
72
- const next = regionStream.next();
73
- if (!next) {
74
- warnings.push({ code: "out-of-regions", blockId: id });
75
- break;
76
- }
77
- current = next;
78
- }
79
-
80
- currentBlockIds.push(id);
81
- currentHeight += height;
82
- consumedCount += 1;
83
- }
84
-
85
- flush();
86
- return { regions: filled, warnings, consumedCount };
87
- }
88
-
89
- export function estimateRegionsNeeded(measuredBlocks, regionCapacity, options = {}) {
90
- const capacity = positiveNumber(regionCapacity, DEFAULT_PAGE_SAFE_HEIGHT_PX);
91
- const result = allocateBlocksToRegions(measuredBlocks, infiniteFixedCapacityRegionStream(capacity), options);
92
- return result.regions.length;
93
- }
94
-
95
- // Derive a flat pages[] view from filled regions. Blocks within a page are
96
- // emitted in column order (col 0, col 1, ...) — matching how readers consume
97
- // a multi-column page (left-to-right, top-to-bottom).
98
- export function pagesFromRegions(filledRegions) {
99
- const byPage = new Map();
100
- for (const region of filledRegions) {
101
- if (!byPage.has(region.pageIndex)) byPage.set(region.pageIndex, []);
102
- byPage.get(region.pageIndex).push(region);
103
- }
104
- const pages = [];
105
- for (const [pageIndex, regionsOnPage] of [...byPage.entries()].sort((a, b) => a[0] - b[0])) {
106
- const sorted = regionsOnPage.slice().sort((a, b) => a.columnIndex - b.columnIndex);
107
- const blockIds = sorted.flatMap((r) => r.blockIds);
108
- pages.push({
109
- pageIndex,
110
- blockIds,
111
- breakAfter: blockIds.at(-1),
112
- });
113
- }
114
- return pages;
115
- }
116
-
117
- // Public wrapper preserving the legacy (blocks, { pageSafeHeightPx }) signature.
118
- // New code can pass a `regions` stream directly to opt into multi-column or
119
- // heterogeneous layouts.
120
- export function paginateMeasuredBlocks(measuredBlocks, options = {}) {
121
- const { pageSafeHeightPx = DEFAULT_PAGE_SAFE_HEIGHT_PX, regions } = options;
122
- const safeHeight = positiveNumber(pageSafeHeightPx, DEFAULT_PAGE_SAFE_HEIGHT_PX);
123
- const stream = regions ?? singleColumnRegionStream({ pageSafeHeightPx: safeHeight });
124
- const { regions: filledRegions, warnings } = allocateBlocksToRegions(measuredBlocks, stream);
125
- const pages = pagesFromRegions(filledRegions);
126
- return {
127
- pages,
128
- regions: filledRegions,
129
- warnings: warnings.map((w) => mapWarning(w, safeHeight)),
130
- };
131
- }
132
-
133
- function infiniteFixedCapacityRegionStream(capacity) {
134
- let index = 0;
135
- return {
136
- next() {
137
- const region = {
138
- id: `estimate-region-${index}`,
139
- capacity,
140
- pageIndex: index,
141
- columnIndex: 0,
142
- };
143
- index += 1;
144
- return region;
145
- },
146
- };
147
- }
148
-
149
- // Translate the new region-shaped warnings back to the legacy
150
- // `block-overflows-page` schema that document-export.mjs and downstream
151
- // consumers expect. Once consumers migrate, this can drop.
152
- function mapWarning(warning, pageSafeHeightPx) {
153
- if (warning.code === "block-overflows-region") {
154
- return {
155
- code: "block-overflows-page",
156
- blockId: warning.blockId,
157
- height: warning.height,
158
- pageSafeHeightPx,
159
- };
160
- }
161
- return warning;
162
- }
163
-
164
- function positiveNumber(value, fallback) {
165
- const number = Number(value);
166
- return Number.isFinite(number) && number > 0 ? number : fallback;
167
- }
@@ -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, estimateRegionsNeeded, pagesFromRegions } from "./pagination/allocator.mjs";
9
- export { singleColumnRegionStream, multiColumnRegionStream, fixedRegionStream } from "./pagination/regions.mjs";