@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,439 +0,0 @@
1
- // MDX source resolver — Layer 1 of the Press pipeline.
2
- //
3
- // Takes a normalized `mdxSource()` descriptor and produces:
4
- // 1. A public `ResolvedSource` consumed by `useSource()` in user code.
5
- // 2. A private `RenderRegistry` consumed by Layer 5 to render specific
6
- // block-id subsets into React nodes.
7
- //
8
- // Both halves come from the same MDX compile so block IDs stay consistent.
9
-
10
- import fs from "node:fs/promises";
11
- import path from "node:path";
12
- import React from "react";
13
- import { documentRelativePath, resolveDocumentRelativePath } from "../../runtime/path-utils.mjs";
14
- import { compileMdx } from "../mdx-compile.mjs";
15
- import { createHeadingState, fallbackOutlineItems, headingAttributesForBlock } from "./heading-numbering.mjs";
16
-
17
- const MDX_EXT = ".mdx";
18
-
19
- /**
20
- * Resolve all sources registered in `press/index.tsx`.
21
- *
22
- * @param {object} opts
23
- * @param {Record<string, object>} opts.sources The raw `sources` export.
24
- * @param {string} opts.documentRoot Absolute path to document/.
25
- * @param {Record<string, Function>} opts.globalComponents Pre-resolved global components.
26
- * @returns {Promise<{ resolved: Record<string, object>, renderData: Map<string, object> }>}
27
- */
28
- export async function resolveAllSources({ sources, documentRoot, globalComponents }) {
29
- validateSourcesShape(sources);
30
-
31
- const resolved = {};
32
- const renderData = new Map();
33
-
34
- for (const [sourceId, descriptor] of Object.entries(sources)) {
35
- validateSourceKey(sourceId);
36
- const { resolved: source, renderData: rd } = await resolveSource({
37
- sourceId,
38
- descriptor,
39
- documentRoot,
40
- globalComponents,
41
- });
42
- resolved[sourceId] = source;
43
- renderData.set(sourceId, rd);
44
- }
45
-
46
- return { resolved, renderData };
47
- }
48
-
49
- async function resolveSource({ sourceId, descriptor, documentRoot, globalComponents }) {
50
- if (!descriptor || typeof descriptor !== "object") {
51
- throw new Error(`Source "${sourceId}" descriptor must be an object.`);
52
- }
53
- if (descriptor.type !== "mdx") {
54
- throw new Error(`Source "${sourceId}" type must be "mdx" in v0.6. Got "${descriptor.type}".`);
55
- }
56
-
57
- const sections = await collectSections({ descriptor, documentRoot, sourceId });
58
-
59
- const tree = [];
60
- const outline = [];
61
- const chains = {};
62
- const files = [];
63
- const sectionRenderData = new Map();
64
-
65
- for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex += 1) {
66
- const section = sections[sectionIndex];
67
- const chainId = `${sourceId}:${section.slug}`;
68
- const blocks = [];
69
- const fileRenderData = [];
70
- const outlineItems = [];
71
- const chapterNumber = sectionIndex + 1;
72
- const chapterLabel = String(chapterNumber).padStart(2, "0");
73
- let resolvedSectionTitle = section.title ?? section.slug;
74
- const headingState = createHeadingState();
75
-
76
- for (const file of section.files) {
77
- const source = await fs.readFile(file.absolutePath, "utf8");
78
- const compiled = await compileMdx({
79
- source,
80
- filePath: file.absolutePath,
81
- components: globalComponents,
82
- chapterSlug: section.slug,
83
- });
84
-
85
- const fileBlockIds = [];
86
- const fileBlockAttributes = {};
87
- for (const block of compiled.blocks) {
88
- const headingAttributes = headingAttributesForBlock({
89
- block,
90
- sourceId,
91
- section,
92
- outlineItems,
93
- chapterNumber,
94
- chapterLabel,
95
- headingState,
96
- });
97
- if (headingAttributes) {
98
- fileBlockAttributes[block.id] = headingAttributes.attributes;
99
- if (headingAttributes.sectionTitle) resolvedSectionTitle = headingAttributes.sectionTitle;
100
- }
101
-
102
- const record = {
103
- id: block.id,
104
- kind: block.kind,
105
- name: block.name,
106
- text: block.text,
107
- layout: block.layout,
108
- chainId,
109
- sectionSlug: section.slug,
110
- path: documentRelative(file.absolutePath, documentRoot),
111
- source: {
112
- file: path.basename(file.absolutePath),
113
- line: block.source?.line,
114
- column: block.source?.column,
115
- endLine: block.source?.endLine,
116
- endColumn: block.source?.endColumn,
117
- },
118
- };
119
- blocks.push(record);
120
- fileBlockIds.push(block.id);
121
- }
122
-
123
- files.push({
124
- path: documentRelative(file.absolutePath, documentRoot),
125
- absolutePath: file.absolutePath,
126
- sectionSlug: section.slug,
127
- });
128
-
129
- fileRenderData.push({
130
- filePath: file.absolutePath,
131
- source,
132
- blockIds: fileBlockIds,
133
- blockAttributes: fileBlockAttributes,
134
- });
135
- }
136
-
137
- chains[chainId] = blocks;
138
- tree.push({
139
- id: section.slug,
140
- slug: section.slug,
141
- title: resolvedSectionTitle,
142
- meta: section.meta ?? {},
143
- });
144
- outline.push(...(outlineItems.length > 0 ? outlineItems : fallbackOutlineItems({
145
- sourceId,
146
- section,
147
- chapterLabel,
148
- title: resolvedSectionTitle,
149
- blocks,
150
- })));
151
-
152
- sectionRenderData.set(section.slug, {
153
- slug: section.slug,
154
- chainId,
155
- contents: fileRenderData,
156
- });
157
- }
158
-
159
- const tocChainId = `toc:${sourceId}`;
160
- const tocBlocks = outline.map((item) => ({
161
- id: item.tocId,
162
- kind: "toc-entry",
163
- name: "toc-entry",
164
- chainId: tocChainId,
165
- sectionSlug: item.sectionSlug,
166
- targetBlockId: item.blockId,
167
- path: "index.tsx",
168
- source: {
169
- file: "index.tsx",
170
- },
171
- title: item.title,
172
- href: item.href,
173
- level: item.depth <= 0 ? 2 : 3,
174
- label: item.label,
175
- }));
176
- const h2TocChainId = `${tocChainId}:h2`;
177
- const h2TocBlocks = tocBlocks.filter((block) => block.level <= 2);
178
- chains[tocChainId] = tocBlocks;
179
- chains[h2TocChainId] = h2TocBlocks;
180
-
181
- return {
182
- resolved: {
183
- id: sourceId,
184
- type: "mdx",
185
- tree,
186
- outline,
187
- chains,
188
- files,
189
- },
190
- renderData: {
191
- sourceId,
192
- sections: sectionRenderData,
193
- tocChains: new Map([[tocChainId, tocBlocks], [h2TocChainId, h2TocBlocks]]),
194
- globalComponents,
195
- },
196
- };
197
- }
198
-
199
- async function collectSections({ descriptor, documentRoot, sourceId }) {
200
- if (descriptor.preset === "section-folders") {
201
- const root = resolveDocumentRelativePath(documentRoot, descriptor.root ?? "chapters", `Source "${sourceId}" section-folders root`);
202
- return collectSectionFolders(root);
203
- }
204
- if (descriptor.preset === "section-files") {
205
- const root = resolveDocumentRelativePath(documentRoot, descriptor.root ?? "content", `Source "${sourceId}" section-files root`);
206
- return collectSectionFiles(root);
207
- }
208
- if (descriptor.preset === "file-list") {
209
- return collectFileList(descriptor.files, documentRoot, sourceId);
210
- }
211
- throw new Error(`Source "${sourceId}" has unknown preset "${descriptor.preset}".`);
212
- }
213
-
214
- async function collectSectionFolders(root) {
215
- const entries = await readDir(root);
216
- const dirs = entries.filter((e) => e.isDirectory()).sort(compareOrderPrefix);
217
- const sections = [];
218
- for (const dir of dirs) {
219
- const dirPath = path.join(root, dir.name);
220
- const contentDir = path.join(dirPath, "content");
221
- const mdxFiles = await listMdxFiles(contentDir);
222
- if (mdxFiles.length === 0) continue;
223
- sections.push({
224
- slug: stripOrderPrefix(dir.name),
225
- title: deriveTitleFromDirName(dir.name),
226
- files: mdxFiles.map((name) => ({ absolutePath: path.join(contentDir, name) })),
227
- });
228
- }
229
- return sections;
230
- }
231
-
232
- async function collectSectionFiles(root) {
233
- const files = await listMdxFiles(root);
234
- return files.map((name) => ({
235
- slug: stripOrderPrefix(stripExtension(name)),
236
- title: deriveTitleFromDirName(stripExtension(name)),
237
- files: [{ absolutePath: path.join(root, name) }],
238
- }));
239
- }
240
-
241
- async function collectFileList(filePaths, documentRoot, sourceId) {
242
- const sections = [];
243
- const slugs = new Set();
244
- for (const rel of filePaths) {
245
- if (typeof rel !== "string" || !rel.trim()) {
246
- throw new Error(`Source "${sourceId}" file-list contains an empty or invalid entry.`);
247
- }
248
- const norm = rel.replace(/^[./]+/, "");
249
- if (rel.includes("..")) {
250
- throw new Error(`Source "${sourceId}" file-list path "${rel}" contains "..", rejected.`);
251
- }
252
- if (!rel.endsWith(MDX_EXT)) {
253
- throw new Error(`Source "${sourceId}" file-list path "${rel}" must end with .mdx.`);
254
- }
255
- const absolute = path.resolve(documentRoot, rel);
256
- const relCheck = path.relative(documentRoot, absolute);
257
- if (relCheck.startsWith("..") || path.isAbsolute(relCheck)) {
258
- throw new Error(`Source "${sourceId}" file-list path "${rel}" escapes the document root.`);
259
- }
260
- const slug = stripOrderPrefix(stripExtension(path.basename(rel)));
261
- if (slugs.has(slug)) {
262
- throw new Error(`Source "${sourceId}" file-list produces duplicate section slug "${slug}".`);
263
- }
264
- slugs.add(slug);
265
- sections.push({
266
- slug,
267
- title: deriveTitleFromDirName(stripExtension(path.basename(rel))),
268
- files: [{ absolutePath: absolute }],
269
- });
270
- }
271
- return sections;
272
- }
273
-
274
- // ---------------------------------------------------------------------------
275
- // Layer 5 helper — render specific blocks for a chain
276
- // ---------------------------------------------------------------------------
277
-
278
- /**
279
- * For a chain, given the block IDs to include, return a list of React nodes
280
- * to inject into MdxArea(s).
281
- *
282
- * @returns {Promise<Array<{ Content: React.FC, blockIds: string[] }>>}
283
- * One entry per source file participating in the chain. Caller can wrap
284
- * each Content in a fragment or distribute across MdxAreas.
285
- */
286
- export async function compileChainBlocks({ renderData, chainId, blockIds, toc = null }) {
287
- const ids = new Set(blockIds);
288
- if (ids.size === 0) return [];
289
- const tocBlocks = renderData?.tocChains?.get(chainId);
290
- if (tocBlocks) {
291
- return compileTocBlocks({ tocBlocks, chainId, blockIds, toc });
292
- }
293
- const section = locateSection(renderData, chainId);
294
- const out = [];
295
- for (const fileData of section.contents) {
296
- const fileIds = fileData.blockIds.filter((id) => ids.has(id));
297
- if (fileIds.length === 0) continue;
298
- const compiled = await compileMdx({
299
- source: fileData.source,
300
- filePath: fileData.filePath,
301
- components: renderData.globalComponents,
302
- chapterSlug: section.slug,
303
- includeBlockIds: fileIds,
304
- blockAttributes: fileData.blockAttributes,
305
- });
306
- out.push({ Content: compiled.Content, blockIds: fileIds });
307
- }
308
- return out;
309
- }
310
-
311
- function compileTocBlocks({ tocBlocks, chainId, blockIds, toc }) {
312
- const ids = new Set(blockIds);
313
- const pageNumberByBlockId = new Map();
314
- for (const entry of toc?.[chainId] ?? []) {
315
- pageNumberByBlockId.set(entry.blockId, entry.pageNumber);
316
- }
317
- const selected = tocBlocks.filter((block) => ids.has(block.id));
318
- return selected.map((block) => ({
319
- Content: function TocEntry() {
320
- const pageNumber = pageNumberByBlockId.get(block.id);
321
- const pageLabel = Number.isFinite(pageNumber) ? String(pageNumber).padStart(2, "0") : "00";
322
- const className = `toc-level-${block.level}`;
323
- return React.createElement(
324
- "li",
325
- {
326
- className,
327
- "data-openpress-block-id": block.id,
328
- "data-openpress-object-id": createBlockObjectEntityId(block.id),
329
- "data-openpress-toc-entry": block.sectionSlug,
330
- },
331
- React.createElement(
332
- "a",
333
- {
334
- href: block.href,
335
- "data-openpress-anchor": block.href.replace(/^#/, ""),
336
- "data-openpress-target-page-index": Number.isFinite(pageNumber) ? String(pageNumber - 1) : undefined,
337
- },
338
- React.createElement("span", { className: "toc-index", "data-toc-index": block.label }, block.label),
339
- React.createElement("span", { className: "toc-title" }, block.title),
340
- React.createElement("span", { className: "toc-page" }, pageLabel),
341
- ),
342
- );
343
- },
344
- blockIds: [block.id],
345
- }));
346
- }
347
-
348
- function locateSection(renderData, chainId) {
349
- if (!renderData) {
350
- throw new Error(`No render data for chainId "${chainId}".`);
351
- }
352
- for (const section of renderData.sections.values()) {
353
- if (section.chainId === chainId) return section;
354
- }
355
- throw new Error(`No section found for chainId "${chainId}" in source "${renderData.sourceId}".`);
356
- }
357
-
358
- function createObjectEntityId(kind, ...parts) {
359
- return [kind, ...parts.map((part) => encodeURIComponent(String(part)))].join(":");
360
- }
361
-
362
- function createBlockObjectEntityId(blockId) {
363
- return createObjectEntityId("mdx-block", blockId);
364
- }
365
-
366
- // ---------------------------------------------------------------------------
367
- // Validation
368
- // ---------------------------------------------------------------------------
369
-
370
- const SOURCE_KEY_RE = /^[a-z][a-z0-9-]*$/;
371
-
372
- function validateSourcesShape(sources) {
373
- if (sources == null) return;
374
- if (typeof sources !== "object" || Array.isArray(sources)) {
375
- throw new Error("`export const sources` must be an object literal of sourceId -> descriptor.");
376
- }
377
- }
378
-
379
- function validateSourceKey(sourceId) {
380
- if (!SOURCE_KEY_RE.test(sourceId)) {
381
- throw new Error(
382
- `Source key "${sourceId}" is invalid. Source keys must match /^[a-z][a-z0-9-]*$/ ` +
383
- `(lowercase letter, then lowercase letters, digits, or hyphens). ` +
384
- `Colons are reserved for chain ID separators.`,
385
- );
386
- }
387
- }
388
-
389
- // ---------------------------------------------------------------------------
390
- // IO helpers
391
- // ---------------------------------------------------------------------------
392
-
393
- async function readDir(dir) {
394
- try {
395
- return await fs.readdir(dir, { withFileTypes: true });
396
- } catch (error) {
397
- if (error?.code === "ENOENT") return [];
398
- throw error;
399
- }
400
- }
401
-
402
- async function listMdxFiles(dir) {
403
- const entries = await readDir(dir);
404
- return entries
405
- .filter((e) => e.isFile() && e.name.endsWith(MDX_EXT))
406
- .map((e) => e.name)
407
- .sort((a, b) => a.localeCompare(b));
408
- }
409
-
410
- function compareOrderPrefix(a, b) {
411
- const left = orderKey(a.name);
412
- const right = orderKey(b.name);
413
- if (left.order !== right.order) return left.order - right.order;
414
- return left.rest.localeCompare(right.rest);
415
- }
416
-
417
- function orderKey(name) {
418
- const match = name.match(/^(\d+)[-_]?(.*)$/);
419
- if (!match) return { order: Number.POSITIVE_INFINITY, rest: name };
420
- return { order: Number.parseInt(match[1], 10), rest: match[2] || name };
421
- }
422
-
423
- function stripOrderPrefix(name) {
424
- return name.replace(/^\d+[-_]?/, "");
425
- }
426
-
427
- function stripExtension(name) {
428
- return name.replace(/\.[^.]+$/, "");
429
- }
430
-
431
- function deriveTitleFromDirName(name) {
432
- return stripOrderPrefix(name)
433
- .split(/[-_]/)
434
- .filter(Boolean)
435
- .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
436
- .join(" ");
437
- }
438
-
439
- const documentRelative = documentRelativePath;
@@ -1,160 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { documentRelativePath } from "../runtime/path-utils.mjs";
4
-
5
- // Style discovery — only used to find per-section CSS files for the
6
- // section-folders preset. MDX content discovery lives in `sources/mdx-resolver`.
7
- // This module exists because section-scoped CSS (`[data-section-id]`) needs
8
- // to know which section slugs exist before the source descriptor pass.
9
-
10
- const COMPONENT_EXT = ".tsx";
11
-
12
- export async function discoverSectionStyles(root = ".", config = {}, { sectionRoots } = {}) {
13
- const workspaceRoot = path.resolve(root);
14
- const documentRoot = config.paths?.documentRoot ?? path.join(workspaceRoot, "press");
15
- const componentsRoot = config.paths?.componentsDir ?? path.join(documentRoot, "components");
16
- const globalComponents = await discoverComponents(componentsRoot, documentRoot, "global");
17
-
18
- // Multi-Press workspaces can place their chapters under per-Press
19
- // subfolders (e.g. press/userstory/chapters/, press/slidepack/chapters/).
20
- // The caller passes each Press's resolved section-folders root; we
21
- // discover sections in every root and merge. Duplicate paths are
22
- // de-duplicated by absolutePath. Falls back to the workspace-default
23
- // root (press/chapters/) when no roots are passed in.
24
- const effectiveRoots = sectionRoots && sectionRoots.length > 0
25
- ? sectionRoots
26
- : [config.paths?.chaptersDir ?? config.paths?.sourceDir ?? path.join(documentRoot, "chapters")];
27
- const seen = new Set();
28
- const sections = [];
29
- for (const sectionsRoot of effectiveRoots) {
30
- const found = await discoverSections(documentRoot, sectionsRoot);
31
- for (const section of found) {
32
- if (seen.has(section.absolutePath)) continue;
33
- seen.add(section.absolutePath);
34
- sections.push(section);
35
- }
36
- }
37
-
38
- return {
39
- root: workspaceRoot,
40
- documentRoot,
41
- globalComponents,
42
- sections,
43
- // Back-compat: `chapters` alias for callers that still expect the old shape.
44
- chapters: sections,
45
- };
46
- }
47
-
48
- async function discoverSections(documentRoot, sectionsDir) {
49
- const entries = await readDirectoryEntries(sectionsDir);
50
- const sectionDirs = entries.filter((entry) => entry.isDirectory()).sort(compareSectionDirectories);
51
-
52
- const sections = [];
53
- for (const entry of sectionDirs) {
54
- const sectionPath = path.join(sectionsDir, entry.name);
55
- const contentFiles = await discoverContentFiles(path.join(sectionPath, "content"), documentRoot);
56
- const styleFiles = await discoverStyleFiles(path.join(sectionPath, "styles"), documentRoot);
57
-
58
- sections.push({
59
- directoryName: entry.name,
60
- slug: sectionSlugFromDirectory(entry.name),
61
- absolutePath: sectionPath,
62
- documentPath: documentRelativePath(sectionPath, documentRoot),
63
- contentFiles,
64
- styleFiles,
65
- });
66
- }
67
-
68
- return sections;
69
- }
70
-
71
- async function discoverComponents(componentsDir, documentRoot, scope) {
72
- const entries = await readDirectoryEntries(componentsDir);
73
- const components = [];
74
-
75
- for (const entry of entries) {
76
- if (entry.isFile() && path.extname(entry.name) === COMPONENT_EXT) {
77
- const absolutePath = path.join(componentsDir, entry.name);
78
- components.push(componentRecord(path.basename(entry.name, COMPONENT_EXT), absolutePath, documentRoot, scope));
79
- continue;
80
- }
81
-
82
- if (entry.isDirectory()) {
83
- const indexPath = path.join(componentsDir, entry.name, `index${COMPONENT_EXT}`);
84
- if (await fileExists(indexPath)) {
85
- components.push(componentRecord(entry.name, indexPath, documentRoot, scope));
86
- }
87
- }
88
- }
89
-
90
- return components.sort((a, b) => a.name.localeCompare(b.name) || a.documentPath.localeCompare(b.documentPath));
91
- }
92
-
93
- async function discoverContentFiles(contentDir, documentRoot) {
94
- return discoverFilesByExtension(contentDir, documentRoot, ".mdx");
95
- }
96
-
97
- async function discoverStyleFiles(stylesDir, documentRoot) {
98
- return discoverFilesByExtension(stylesDir, documentRoot, ".css");
99
- }
100
-
101
- async function discoverFilesByExtension(directory, documentRoot, extension) {
102
- const entries = await readDirectoryEntries(directory);
103
- return entries
104
- .filter((entry) => entry.isFile() && path.extname(entry.name) === extension)
105
- .sort((a, b) => a.name.localeCompare(b.name))
106
- .map((entry) => pathRecord(path.join(directory, entry.name), documentRoot));
107
- }
108
-
109
- function componentRecord(name, absolutePath, documentRoot, scope) {
110
- return {
111
- name,
112
- scope,
113
- ...pathRecord(absolutePath, documentRoot),
114
- };
115
- }
116
-
117
- function pathRecord(absolutePath, documentRoot) {
118
- return {
119
- absolutePath,
120
- documentPath: documentRelativePath(absolutePath, documentRoot),
121
- };
122
- }
123
-
124
- function compareSectionDirectories(a, b) {
125
- const left = sectionSortKey(a.name);
126
- const right = sectionSortKey(b.name);
127
- if (left.order !== right.order) return left.order - right.order;
128
- return left.name.localeCompare(right.name);
129
- }
130
-
131
- function sectionSortKey(directoryName) {
132
- const match = directoryName.match(/^(\d+)[-_]?(.*)$/);
133
- if (!match) {
134
- return { order: Number.POSITIVE_INFINITY, name: directoryName };
135
- }
136
- return { order: Number.parseInt(match[1], 10), name: match[2] || directoryName };
137
- }
138
-
139
- function sectionSlugFromDirectory(directoryName) {
140
- return directoryName.replace(/^\d+[-_]?/, "");
141
- }
142
-
143
- async function readDirectoryEntries(directory) {
144
- try {
145
- return await fs.readdir(directory, { withFileTypes: true });
146
- } catch (error) {
147
- if (error?.code === "ENOENT") return [];
148
- throw error;
149
- }
150
- }
151
-
152
- async function fileExists(filePath) {
153
- try {
154
- const stat = await fs.stat(filePath);
155
- return stat.isFile();
156
- } catch (error) {
157
- if (error?.code === "ENOENT") return false;
158
- throw error;
159
- }
160
- }
@@ -1,48 +0,0 @@
1
- export interface ResolvedConfig {
2
- root: string;
3
- configPath: string;
4
- title: string;
5
- documentDir: string;
6
- sourceDir: string;
7
- mediaDir: string;
8
- themeDir: string;
9
- designDoc: string;
10
- componentsDir: string;
11
- publicDir: string;
12
- outputDir: string;
13
- page: null | {
14
- id: string;
15
- label: string;
16
- width: string;
17
- height: string;
18
- aspectRatio?: string;
19
- heightRatio?: string;
20
- };
21
- pdf: {
22
- filename: string;
23
- };
24
- deploy: {
25
- adapter: string;
26
- source: string;
27
- projectName: string | null;
28
- commitDirty: boolean;
29
- requiresConfirmation: boolean;
30
- };
31
- paths: {
32
- documentRoot: string;
33
- sourceDir: string;
34
- mediaDir: string;
35
- themeDir: string;
36
- designDoc: string;
37
- componentsDir: string;
38
- publicDir: string;
39
- outputDir: string;
40
- pdf: string;
41
- deploySource: string;
42
- deployMetadata: string;
43
- };
44
- }
45
-
46
- export function loadConfig(root?: string): Promise<ResolvedConfig>;
47
- export function normalizeConfig(root: string, userConfig?: Record<string, unknown>, configPath?: string): ResolvedConfig;
48
- export function publicPdfHref(config: ResolvedConfig): string;