@open-document/core 0.3.0 → 0.5.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 (38) hide show
  1. package/README.md +1 -0
  2. package/README.zh-TW.md +1 -0
  3. package/dist/{build-C3pMGxJN.js → build-BzhYQKev.js} +1 -1
  4. package/dist/{check-Dtwb1wvU.js → check-CCAaXofH.js} +3 -3
  5. package/dist/cli/bin.js +33 -21
  6. package/dist/{config-CSC5lHsR.d.ts → config-P61niZMf.d.ts} +6 -0
  7. package/dist/{context-FoX0afRf.js → context-CJpdjYfU.js} +3 -14
  8. package/dist/{dev-Cdd7NZRQ.js → dev-BhXgunme.js} +1 -1
  9. package/dist/{export-ClJ4T1uU.js → export-B69kDkyp.js} +3 -3
  10. package/dist/{import-D7Psi8WK.js → import-DBhCpUsl.js} +3 -2
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +2 -40
  13. package/dist/ops/index.d.ts +2 -2
  14. package/dist/ops/index.js +4 -3
  15. package/dist/{ops-Ci5Xw6QG.js → ops-BCBmRMCS.js} +7 -2
  16. package/dist/{preview-BhbCiAKC.js → preview-Da4Aq9yF.js} +1 -1
  17. package/dist/{sdk-CWMsH9Ms.d.ts → sdk-C9nl30dW.d.ts} +13 -7
  18. package/dist/sdk-DhcqZdAw.js +50 -0
  19. package/dist/vite/index.d.ts +1 -1
  20. package/dist/vite/index.js +1 -1
  21. package/package.json +1 -1
  22. package/skills/create-doc/SKILL.md +1 -1
  23. package/skills/create-theme/SKILL.md +1 -1
  24. package/skills/doc-authoring/SKILL.md +7 -6
  25. package/skills/doc-authoring/references/pagination.md +2 -1
  26. package/src/app/components/doc-search.tsx +248 -0
  27. package/src/app/components/themes/theme-preview.tsx +2 -2
  28. package/src/app/components/ui/menu.tsx +4 -0
  29. package/src/app/lib/export-dom.ts +183 -0
  30. package/src/app/lib/export-html.ts +12 -183
  31. package/src/app/lib/export-image.ts +226 -0
  32. package/src/app/lib/page-range.test.ts +95 -0
  33. package/src/app/lib/page-range.ts +90 -0
  34. package/src/app/lib/sdk.test.ts +15 -9
  35. package/src/app/lib/sdk.ts +34 -11
  36. package/src/app/routes/doc.tsx +352 -114
  37. package/src/app/styles.css +25 -0
  38. package/dist/{config-Dg1AMP0r.js → config-CNr8hd5X.js} +1 -1
package/README.md CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  type DocMeta,
25
25
  type DocPage,
26
26
  ImagePlaceholder,
27
+ PAGE_SIZE_NAMES,
27
28
  PAGE_SIZES,
28
29
  TableOfContents,
29
30
  resolvePageGeometry,
package/README.zh-TW.md CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  type DocMeta,
25
25
  type DocPage,
26
26
  ImagePlaceholder,
27
+ PAGE_SIZE_NAMES,
27
28
  PAGE_SIZES,
28
29
  TableOfContents,
29
30
  resolvePageGeometry,
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-Dg1AMP0r.js";
1
+ import { t as createViteConfig } from "./config-CNr8hd5X.js";
2
2
  import path from "node:path";
3
3
  import { build as build$1, mergeConfig } from "vite";
4
4
  //#region src/cli/build.ts
@@ -1,6 +1,6 @@
1
- import { g as listDocIds } from "./config-Dg1AMP0r.js";
2
- import { m as closeRenderSession, p as checkLayout } from "./ops-Ci5Xw6QG.js";
3
- import { t as cliContext } from "./context-FoX0afRf.js";
1
+ import { g as listDocIds } from "./config-CNr8hd5X.js";
2
+ import { m as closeRenderSession, p as checkLayout } from "./ops-BCBmRMCS.js";
3
+ import { t as cliContext } from "./context-CJpdjYfU.js";
4
4
  import chalk from "chalk";
5
5
  //#region src/cli/check.ts
6
6
  function line(finding) {
package/dist/cli/bin.js CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ import { a as PAGE_SIZE_NAMES, r as ORIENTATIONS } from "../sdk-DhcqZdAw.js";
2
3
  import chalk from "chalk";
3
- import fs, { readFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import * as readline from "node:readline/promises";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { Command, Option } from "commander";
8
+ import fs, { readFile } from "node:fs/promises";
8
9
  import { existsSync } from "node:fs";
9
10
  //#region \0rolldown/runtime.js
10
11
  var __defProp = Object.defineProperty;
@@ -18,6 +19,28 @@ var __exportAll = (all, no_symbols) => {
18
19
  return target;
19
20
  };
20
21
  //#endregion
22
+ //#region src/cli/package-version.ts
23
+ const PACKAGE_NAME = "@open-document/core";
24
+ /**
25
+ * Walks up for this package's own `package.json` instead of assuming a fixed
26
+ * depth: the bundler decides which chunk a module lands in, so `../../` is
27
+ * right from `dist/cli/` and wrong from `dist/`. Getting that wrong is silent —
28
+ * it reports `0.0.0` rather than failing.
29
+ */
30
+ async function readCoreVersion() {
31
+ let dir = path.dirname(fileURLToPath(import.meta.url));
32
+ for (let up = 0; up < 6; up += 1) {
33
+ try {
34
+ const pkg = JSON.parse(await readFile(path.join(dir, "package.json"), "utf8"));
35
+ if (pkg.name === PACKAGE_NAME && pkg.version !== void 0) return pkg.version;
36
+ } catch {}
37
+ const parent = path.dirname(dir);
38
+ if (parent === dir) break;
39
+ dir = parent;
40
+ }
41
+ return "0.0.0";
42
+ }
43
+ //#endregion
21
44
  //#region src/cli/sync.ts
22
45
  var sync_exports = /* @__PURE__ */ __exportAll({
23
46
  detectSkillsDrift: () => detectSkillsDrift,
@@ -100,12 +123,6 @@ async function syncSkills(builtinDir, opts = {}, userCwd = process.cwd()) {
100
123
  }
101
124
  //#endregion
102
125
  //#region src/cli/run.ts
103
- async function readVersion() {
104
- const here = path.dirname(fileURLToPath(import.meta.url));
105
- const pkgPath = path.resolve(here, "..", "..", "package.json");
106
- const raw = await readFile(pkgPath, "utf8");
107
- return JSON.parse(raw).version;
108
- }
109
126
  function parsePort(value) {
110
127
  const n = Number(value);
111
128
  if (!Number.isInteger(n) || n < 0 || n > 65535) throw new Error(`Invalid port: ${value}`);
@@ -143,20 +160,20 @@ async function runSkillsDriftCheck(skillsDir) {
143
160
  }
144
161
  }
145
162
  async function run(argv) {
146
- const version = await readVersion();
163
+ const version = await readCoreVersion();
147
164
  const program = new Command();
148
165
  program.name("open-doc").description("Author documents — we handle the Vite/React stack, pagination, and export.").version(version, "-v, --version", "print version").helpOption("-h, --help", "show help").showHelpAfterError(chalk.dim("(run `open-doc --help` for usage)"));
149
166
  program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").option("--no-skills-check", "skip the built-in skills drift check").option("--mcp", "serve an MCP endpoint at /mcp (requires @open-document/mcp)").action(async (flags) => {
150
167
  if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
151
- const { dev } = await import("../dev-Cdd7NZRQ.js");
168
+ const { dev } = await import("../dev-BhXgunme.js");
152
169
  await dev(flags);
153
170
  });
154
171
  program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
155
- const { build } = await import("../build-C3pMGxJN.js");
172
+ const { build } = await import("../build-BzhYQKev.js");
156
173
  await build(flags);
157
174
  });
158
175
  program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
159
- const { preview } = await import("../preview-BhbCiAKC.js");
176
+ const { preview } = await import("../preview-Da4Aq9yF.js");
160
177
  await preview(flags);
161
178
  });
162
179
  program.command("export [docIds...]").description("Render documents headlessly to PDF, HTML, or PNG").addOption(new Option("-f, --format <format>", "output format").choices([
@@ -164,20 +181,15 @@ async function run(argv) {
164
181
  "html",
165
182
  "png"
166
183
  ])).option("-o, --out-dir <dir>", "directory to write into (defaults to `out`)").option("--all", "export every document under docs/").action(async (docIds, flags) => {
167
- const { exportDocs } = await import("../export-ClJ4T1uU.js");
184
+ const { exportDocs } = await import("../export-B69kDkyp.js");
168
185
  await exportDocs(docIds, flags);
169
186
  });
170
187
  program.command("check [docIds...]").description("Report layout faults — clipped content, blank sheets, stranded headings").option("--json", "print the full report as JSON").action(async (docIds, flags) => {
171
- const { checkDocs } = await import("../check-Dtwb1wvU.js");
188
+ const { checkDocs } = await import("../check-CCAaXofH.js");
172
189
  await checkDocs(docIds, flags);
173
190
  });
174
- program.command("import <file>").description("Turn a Markdown file into a document under docs/").option("--id <id>", "document id (defaults to a slug of the title)").option("--title <title>", "override the title").option("--subtitle <subtitle>", "subtitle, also used as the cover eyebrow").option("--author <author>", "author line on the cover").option("--theme <theme>", "theme id to back-link from meta.theme").addOption(new Option("--page-size <size>", "page size").choices([
175
- "A4",
176
- "Letter",
177
- "A5",
178
- "Legal"
179
- ])).option("--no-cover", "skip the title page").option("--contents", "add a self-filling contents page").action(async (file, flags) => {
180
- const { importDoc } = await import("../import-D7Psi8WK.js");
191
+ program.command("import <file>").description("Turn a Markdown file into a document under docs/").option("--id <id>", "document id (defaults to a slug of the title)").option("--title <title>", "override the title").option("--subtitle <subtitle>", "subtitle, also used as the cover eyebrow").option("--author <author>", "author line on the cover").option("--theme <theme>", "theme id to back-link from meta.theme").addOption(new Option("--page-size <size>", "page size").choices(PAGE_SIZE_NAMES)).addOption(new Option("--orientation <orientation>", "page orientation").choices(ORIENTATIONS)).option("--no-cover", "skip the title page").option("--contents", "add a self-filling contents page").action(async (file, flags) => {
192
+ const { importDoc } = await import("../import-DBhCpUsl.js");
181
193
  await importDoc(file, flags);
182
194
  });
183
195
  program.command("sync:skills").description("Sync built-in skills from @open-document/core into this workspace").option("--dry-run", "show what would change without writing").action(async (flags) => {
@@ -194,4 +206,4 @@ run(process.argv.slice(2)).catch((err) => {
194
206
  process.exit(1);
195
207
  });
196
208
  //#endregion
197
- export {};
209
+ export { readCoreVersion as t };
@@ -7,6 +7,12 @@ type OpenDocBuildConfig = {
7
7
  };
8
8
  type OpenDocConfig = {
9
9
  base?: string;
10
+ /**
11
+ * Where the viewer's back affordance goes. Unset it points at this app's own
12
+ * document browser; set it to escape the app entirely — a viewer mounted
13
+ * under a larger site needs to return to that site, not to its own index.
14
+ */
15
+ home?: string;
10
16
  docsDir?: string;
11
17
  themesDir?: string;
12
18
  assetsDir?: string;
@@ -1,17 +1,6 @@
1
- import { D as makeContext, k as loadUserConfig } from "./config-Dg1AMP0r.js";
2
- import { readFile } from "node:fs/promises";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
1
+ import { t as readCoreVersion } from "./cli/bin.js";
2
+ import { D as makeContext, k as loadUserConfig } from "./config-CNr8hd5X.js";
5
3
  //#region src/cli/context.ts
6
- async function coreVersion() {
7
- try {
8
- const here = path.dirname(fileURLToPath(import.meta.url));
9
- const raw = await readFile(path.resolve(here, "..", "..", "package.json"), "utf8");
10
- return JSON.parse(raw).version ?? "0.0.0";
11
- } catch {
12
- return "0.0.0";
13
- }
14
- }
15
4
  /** The same context the dev API and the MCP server run on, for commands that call `ops/`. */
16
5
  async function cliContext(userCwd = process.cwd()) {
17
6
  const config = await loadUserConfig(userCwd);
@@ -19,7 +8,7 @@ async function cliContext(userCwd = process.cwd()) {
19
8
  userCwd,
20
9
  docsDir: config.docsDir ?? "docs",
21
10
  assetsDir: config.assetsDir ?? "assets",
22
- coreVersion: await coreVersion()
11
+ coreVersion: await readCoreVersion()
23
12
  });
24
13
  }
25
14
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-Dg1AMP0r.js";
1
+ import { t as createViteConfig } from "./config-CNr8hd5X.js";
2
2
  import { createServer, mergeConfig } from "vite";
3
3
  //#region src/cli/dev.ts
4
4
  async function dev(opts = {}) {
@@ -1,6 +1,6 @@
1
- import { g as listDocIds } from "./config-Dg1AMP0r.js";
2
- import { h as exportDocument, m as closeRenderSession } from "./ops-Ci5Xw6QG.js";
3
- import { t as cliContext } from "./context-FoX0afRf.js";
1
+ import { g as listDocIds } from "./config-CNr8hd5X.js";
2
+ import { h as exportDocument, m as closeRenderSession } from "./ops-BCBmRMCS.js";
3
+ import { t as cliContext } from "./context-CJpdjYfU.js";
4
4
  import chalk from "chalk";
5
5
  //#region src/cli/export.ts
6
6
  const FORMATS = [
@@ -1,5 +1,5 @@
1
- import { _ as importMarkdown } from "./ops-Ci5Xw6QG.js";
2
- import { t as cliContext } from "./context-FoX0afRf.js";
1
+ import { _ as importMarkdown } from "./ops-BCBmRMCS.js";
2
+ import { t as cliContext } from "./context-CJpdjYfU.js";
3
3
  import chalk from "chalk";
4
4
  import path from "node:path";
5
5
  //#region src/cli/import.ts
@@ -14,6 +14,7 @@ async function importDoc(file, opts = {}) {
14
14
  ...opts.author !== void 0 ? { author: opts.author } : {},
15
15
  ...opts.theme !== void 0 ? { theme: opts.theme } : {},
16
16
  ...opts.pageSize !== void 0 ? { pageSize: opts.pageSize } : {},
17
+ ...opts.orientation !== void 0 ? { orientation: opts.orientation } : {},
17
18
  ...opts.cover !== void 0 ? { cover: opts.cover } : {},
18
19
  ...opts.contents !== void 0 ? { contents: opts.contents } : {}
19
20
  });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as useDocLabels, S as useDocLabel, _ as defaultDesign, a as DocPage, b as LabelKind, c as PAGE_SIZES, d as resolvePageGeometry, f as DesignFonts, g as cssVarsToString, h as DesignTypeScale, i as DocModule, l as PageGeometry, m as DesignSystem, n as DocEntry, o as FlowSection, p as DesignPalette, r as DocMeta, s as Orientation, t as DEFAULT_PAGE_SIZE, u as PageSizeName, v as designToCssVars, x as LabelVocabulary, y as LabelEntry } from "./sdk-CWMsH9Ms.js";
2
- import { n as OpenDocConfig, t as OpenDocBuildConfig } from "./config-CSC5lHsR.js";
1
+ import { C as designToCssVars, D as useDocLabel, E as LabelVocabulary, O as useDocLabels, S as defaultDesign, T as LabelKind, _ as DesignFonts, a as DocModule, b as DesignTypeScale, c as ORIENTATIONS, d as PAGE_SIZE_NAMES, f as PageGeometry, g as resolvePageGeometry, h as isPageSizeName, i as DocMeta, l as Orientation, m as isOrientation, n as DEFAULT_PAGE_SIZE, o as DocPage, p as PageSizeName, r as DocEntry, s as FlowSection, t as DEFAULT_ORIENTATION, u as PAGE_SIZES, v as DesignPalette, w as LabelEntry, x as cssVarsToString, y as DesignSystem } from "./sdk-C9nl30dW.js";
2
+ import { n as OpenDocConfig, t as OpenDocBuildConfig } from "./config-P61niZMf.js";
3
3
  import { CSSProperties, ComponentType, ReactNode } from "react";
4
4
  //#region src/app/components/data-table.d.ts
5
5
  type DataAlign = 'left' | 'center' | 'right';
@@ -324,4 +324,4 @@ type CompileOptions = LayoutOptions & RenderOptions;
324
324
  /** Mermaid-flavoured text in, themed SVG out. One call, no browser. */
325
325
  declare function compileDiagram(source: string, options?: CompileOptions): CompiledDiagram;
326
326
  //#endregion
327
- export { type BlockMetrics, type CellValue, type CompileOptions, type CompiledDiagram, DEFAULT_PAGE_SIZE, type DataAlign, type DataColumn, type DataFormat, DataTable, type DataTableProps, type DelimitedTable, type DesignFonts, type DesignPalette, type DesignSystem, type DesignTypeScale, Diagram, type DiagramProps, type DiagramSource, DiagramSyntaxError, type DocEntry, type DocMeta, type DocModule, type DocPage, Figure, type FigureProps, type FlowSection, Footnote, type FootnoteProps, Footnotes, type FootnotesProps, ImagePlaceholder, type ImagePlaceholderProps, type LabelEntry, type LabelKind, type LabelVocabulary, ListOf, ListOfFigures, type ListOfProps, ListOfTables, type OpenDocBuildConfig, type OpenDocConfig, type Orientation, type OutlineEntry, PAGE_SIZES, type PageGeometry, type PageSizeName, type PaginationResult, Ref, type RefProps, TableOfContents, type TableOfContentsProps, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber };
327
+ export { type BlockMetrics, type CellValue, type CompileOptions, type CompiledDiagram, DEFAULT_ORIENTATION, DEFAULT_PAGE_SIZE, type DataAlign, type DataColumn, type DataFormat, DataTable, type DataTableProps, type DelimitedTable, type DesignFonts, type DesignPalette, type DesignSystem, type DesignTypeScale, Diagram, type DiagramProps, type DiagramSource, DiagramSyntaxError, type DocEntry, type DocMeta, type DocModule, type DocPage, Figure, type FigureProps, type FlowSection, Footnote, type FootnoteProps, Footnotes, type FootnotesProps, ImagePlaceholder, type ImagePlaceholderProps, type LabelEntry, type LabelKind, type LabelVocabulary, ListOf, ListOfFigures, type ListOfProps, ListOfTables, ORIENTATIONS, type OpenDocBuildConfig, type OpenDocConfig, type Orientation, type OutlineEntry, PAGE_SIZES, PAGE_SIZE_NAMES, type PageGeometry, type PageSizeName, type PaginationResult, Ref, type RefProps, TableOfContents, type TableOfContentsProps, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, isOrientation, isPageSizeName, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, t as compileDiagram } from "./diagram-xlVDekYk.js";
2
+ import { a as PAGE_SIZE_NAMES, c as resolvePageGeometry, i as PAGE_SIZES, n as DEFAULT_PAGE_SIZE, o as isOrientation, r as ORIENTATIONS, s as isPageSizeName, t as DEFAULT_ORIENTATION } from "./sdk-DhcqZdAw.js";
2
3
  import { Children, Fragment, createContext, isValidElement, useContext, useEffect, useId, useRef, useSyncExternalStore } from "react";
3
4
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
4
5
  //#region src/app/lib/outline.ts
@@ -657,43 +658,4 @@ function paginateBlocks(blocks, available, opts = {}) {
657
658
  };
658
659
  }
659
660
  //#endregion
660
- //#region src/app/lib/sdk.ts
661
- /**
662
- * Page dimensions in CSS pixels at 96dpi — the unit authors write in — paired
663
- * with the physical `@page size` used when printing. Keeping both means a page
664
- * laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
665
- */
666
- const PAGE_SIZES = {
667
- A4: {
668
- width: 794,
669
- height: 1123,
670
- css: "210mm 297mm"
671
- },
672
- Letter: {
673
- width: 816,
674
- height: 1056,
675
- css: "8.5in 11in"
676
- },
677
- A5: {
678
- width: 559,
679
- height: 794,
680
- css: "148mm 210mm"
681
- },
682
- Legal: {
683
- width: 816,
684
- height: 1344,
685
- css: "8.5in 14in"
686
- }
687
- };
688
- const DEFAULT_PAGE_SIZE = "A4";
689
- function resolvePageGeometry(meta) {
690
- const size = PAGE_SIZES[meta?.pageSize ?? "A4"] ?? PAGE_SIZES["A4"];
691
- const landscape = meta?.orientation === "landscape";
692
- return {
693
- width: landscape ? size.height : size.width,
694
- height: landscape ? size.width : size.height,
695
- css: landscape ? `${size.css} landscape` : size.css
696
- };
697
- }
698
- //#endregion
699
- export { DEFAULT_PAGE_SIZE, DataTable, Diagram, DiagramSyntaxError, Figure, Footnote, Footnotes, ImagePlaceholder, ListOf, ListOfFigures, ListOfTables, PAGE_SIZES, Ref, TableOfContents, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber };
661
+ export { DEFAULT_ORIENTATION, DEFAULT_PAGE_SIZE, DataTable, Diagram, DiagramSyntaxError, Figure, Footnote, Footnotes, ImagePlaceholder, ListOf, ListOfFigures, ListOfTables, ORIENTATIONS, PAGE_SIZES, PAGE_SIZE_NAMES, Ref, TableOfContents, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, isOrientation, isPageSizeName, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber };
@@ -1,4 +1,4 @@
1
- import "../sdk-CWMsH9Ms.js";
1
+ import { c as ORIENTATIONS, d as PAGE_SIZE_NAMES, l as Orientation, p as PageSizeName } from "../sdk-C9nl30dW.js";
2
2
  import "vite";
3
3
  //#region src/vite/routes/context.d.ts
4
4
  type ApiContext = {
@@ -247,4 +247,4 @@ declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: stri
247
247
  id: string;
248
248
  }>;
249
249
  //#endregion
250
- export { type ApiContext, type AssetSummary, type DocumentSummary, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, OpsError, type ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText };
250
+ export { type ApiContext, type AssetSummary, type DocumentSummary, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, ORIENTATIONS, OpsError, type Orientation, PAGE_SIZE_NAMES, type PageSizeName, type ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText };
package/dist/ops/index.js CHANGED
@@ -1,3 +1,4 @@
1
- import { D as makeContext, _ as listDocuments, b as resolveEntry, d as OpsError, f as createDocument, g as listDocIds, h as duplicateDocument, m as docDir, p as deleteDocument, v as readDocument, x as writeDocument, y as renameDocument } from "../config-Dg1AMP0r.js";
2
- import { _ as importMarkdown, a as deleteAsset, c as listAssets, d as readTheme, f as writeAsset, g as renderDocPage, h as exportDocument, i as createFolder, l as listFolders, m as closeRenderSession, n as readText, o as fileDocument, p as checkLayout, r as writeText, s as findAssetUsages, t as addComment, u as listThemes, v as slugify } from "../ops-Ci5Xw6QG.js";
3
- export { OpsError, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText };
1
+ import { a as PAGE_SIZE_NAMES, r as ORIENTATIONS } from "../sdk-DhcqZdAw.js";
2
+ import { D as makeContext, _ as listDocuments, b as resolveEntry, d as OpsError, f as createDocument, g as listDocIds, h as duplicateDocument, m as docDir, p as deleteDocument, v as readDocument, x as writeDocument, y as renameDocument } from "../config-CNr8hd5X.js";
3
+ import { _ as importMarkdown, a as deleteAsset, c as listAssets, d as readTheme, f as writeAsset, g as renderDocPage, h as exportDocument, i as createFolder, l as listFolders, m as closeRenderSession, n as readText, o as fileDocument, p as checkLayout, r as writeText, s as findAssetUsages, t as addComment, u as listThemes, v as slugify } from "../ops-BCBmRMCS.js";
4
+ export { ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText };
@@ -1,6 +1,7 @@
1
- import { C as readManifest, E as writeManifest, O as DOC_ID_RE, S as newFolderId, T as validateName, a as insertMarker, b as resolveEntry, c as resolveScopedAssetFile, d as OpsError, f as createDocument, g as listDocIds, i as resolveTextTarget, l as resolveScopedAssetsDir, n as parseFrontmatter$1, o as assetImportPath, r as replaceTextAt, s as countAssetUsages, t as createViteConfig, u as validateAssetName, w as validateIcon } from "./config-Dg1AMP0r.js";
2
- import fs from "node:fs/promises";
1
+ import { a as PAGE_SIZE_NAMES, o as isOrientation, r as ORIENTATIONS, s as isPageSizeName } from "./sdk-DhcqZdAw.js";
2
+ import { C as readManifest, E as writeManifest, O as DOC_ID_RE, S as newFolderId, T as validateName, a as insertMarker, b as resolveEntry, c as resolveScopedAssetFile, d as OpsError, f as createDocument, g as listDocIds, i as resolveTextTarget, l as resolveScopedAssetsDir, n as parseFrontmatter$1, o as assetImportPath, r as replaceTextAt, s as countAssetUsages, t as createViteConfig, u as validateAssetName, w as validateIcon } from "./config-CNr8hd5X.js";
3
3
  import path from "node:path";
4
+ import fs from "node:fs/promises";
4
5
  import { existsSync } from "node:fs";
5
6
  import fg from "fast-glob";
6
7
  import { createServer, mergeConfig } from "vite";
@@ -755,6 +756,10 @@ async function importMarkdown(ctx, opts) {
755
756
  }
756
757
  if (markdown.trim() === "") throw new OpsError(422, "the markdown is empty");
757
758
  const parsed = parseMarkdown(markdown);
759
+ const pageSize = opts.pageSize ?? parsed.frontmatter.pageSize;
760
+ if (pageSize !== void 0 && !isPageSizeName(pageSize)) throw new OpsError(422, `unsupported pageSize \`${pageSize}\` — use ${PAGE_SIZE_NAMES.join(", ")}`);
761
+ const orientation = opts.orientation ?? parsed.frontmatter.orientation;
762
+ if (orientation !== void 0 && !isOrientation(orientation)) throw new OpsError(422, `unsupported orientation \`${orientation}\` — use ${ORIENTATIONS.join(", ")}`);
758
763
  const fallbackName = sourceFile ? path.basename(sourceFile).replace(/\.mdx?$/i, "") : "document";
759
764
  const requestedId = opts.docId ?? slugify(opts.title ?? parsed.frontmatter.title ?? fallbackName);
760
765
  if (opts.docId && !DOC_ID_RE.test(opts.docId)) throw new OpsError(400, `invalid document id: ${opts.docId}`);
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-Dg1AMP0r.js";
1
+ import { t as createViteConfig } from "./config-CNr8hd5X.js";
2
2
  import { mergeConfig, preview as preview$1 } from "vite";
3
3
  //#region src/cli/preview.ts
4
4
  async function preview(opts = {}) {
@@ -66,19 +66,25 @@ declare function cssVarsToString(vars: Record<string, string>): string;
66
66
  declare const defaultDesign: DesignSystem;
67
67
  //#endregion
68
68
  //#region src/app/lib/sdk.d.ts
69
- type PageSizeName = 'A4' | 'Letter' | 'A5' | 'Legal';
70
- type Orientation = 'portrait' | 'landscape';
69
+ /** The only sheets a document may be laid out on. */
70
+ declare const PAGE_SIZE_NAMES: readonly ["A4", "B4", "A3"];
71
+ type PageSizeName = (typeof PAGE_SIZE_NAMES)[number];
72
+ declare const ORIENTATIONS: readonly ["portrait", "landscape"];
73
+ type Orientation = (typeof ORIENTATIONS)[number];
71
74
  /**
72
- * Page dimensions in CSS pixels at 96dpi — the unit authors write in — paired
73
- * with the physical `@page size` used when printing. Keeping both means a page
74
- * laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
75
+ * Portrait dimensions in CSS pixels at 96dpi — the unit authors write in —
76
+ * paired with the physical millimetres used when printing. Keeping both means a
77
+ * page laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
75
78
  */
76
79
  declare const PAGE_SIZES: Record<PageSizeName, {
77
80
  width: number;
78
81
  height: number;
79
- css: string;
82
+ mm: readonly [number, number];
80
83
  }>;
81
84
  declare const DEFAULT_PAGE_SIZE: PageSizeName;
85
+ declare const DEFAULT_ORIENTATION: Orientation;
86
+ declare function isPageSizeName(value: unknown): value is PageSizeName;
87
+ declare function isOrientation(value: unknown): value is Orientation;
82
88
  type PageGeometry = {
83
89
  width: number;
84
90
  height: number;
@@ -120,4 +126,4 @@ type DocModule = {
120
126
  };
121
127
  declare function resolvePageGeometry(meta?: DocMeta): PageGeometry;
122
128
  //#endregion
123
- export { useDocLabels as C, useDocLabel as S, defaultDesign as _, DocPage as a, LabelKind as b, PAGE_SIZES as c, resolvePageGeometry as d, DesignFonts as f, cssVarsToString as g, DesignTypeScale as h, DocModule as i, PageGeometry as l, DesignSystem as m, DocEntry as n, FlowSection as o, DesignPalette as p, DocMeta as r, Orientation as s, DEFAULT_PAGE_SIZE as t, PageSizeName as u, designToCssVars as v, LabelVocabulary as x, LabelEntry as y };
129
+ export { designToCssVars as C, useDocLabel as D, LabelVocabulary as E, useDocLabels as O, defaultDesign as S, LabelKind as T, DesignFonts as _, DocModule as a, DesignTypeScale as b, ORIENTATIONS as c, PAGE_SIZE_NAMES as d, PageGeometry as f, resolvePageGeometry as g, isPageSizeName as h, DocMeta as i, Orientation as l, isOrientation as m, DEFAULT_PAGE_SIZE as n, DocPage as o, PageSizeName as p, DocEntry as r, FlowSection as s, DEFAULT_ORIENTATION as t, PAGE_SIZES as u, DesignPalette as v, LabelEntry as w, cssVarsToString as x, DesignSystem as y };
@@ -0,0 +1,50 @@
1
+ //#region src/app/lib/sdk.ts
2
+ /** The only sheets a document may be laid out on. */
3
+ const PAGE_SIZE_NAMES = [
4
+ "A4",
5
+ "B4",
6
+ "A3"
7
+ ];
8
+ const ORIENTATIONS = ["portrait", "landscape"];
9
+ /**
10
+ * Portrait dimensions in CSS pixels at 96dpi — the unit authors write in —
11
+ * paired with the physical millimetres used when printing. Keeping both means a
12
+ * page laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
13
+ */
14
+ const PAGE_SIZES = {
15
+ A4: {
16
+ width: 794,
17
+ height: 1123,
18
+ mm: [210, 297]
19
+ },
20
+ B4: {
21
+ width: 971,
22
+ height: 1376,
23
+ mm: [257, 364]
24
+ },
25
+ A3: {
26
+ width: 1123,
27
+ height: 1587,
28
+ mm: [297, 420]
29
+ }
30
+ };
31
+ const DEFAULT_PAGE_SIZE = "A4";
32
+ const DEFAULT_ORIENTATION = "portrait";
33
+ function isPageSizeName(value) {
34
+ return typeof value === "string" && value in PAGE_SIZES;
35
+ }
36
+ function isOrientation(value) {
37
+ return value === "portrait" || value === "landscape";
38
+ }
39
+ function resolvePageGeometry(meta) {
40
+ const size = PAGE_SIZES[meta?.pageSize ?? "A4"] ?? PAGE_SIZES["A4"];
41
+ const landscape = meta?.orientation === "landscape";
42
+ const [across, down] = landscape ? [size.mm[1], size.mm[0]] : size.mm;
43
+ return {
44
+ width: landscape ? size.height : size.width,
45
+ height: landscape ? size.width : size.height,
46
+ css: `${across}mm ${down}mm`
47
+ };
48
+ }
49
+ //#endregion
50
+ export { PAGE_SIZE_NAMES as a, resolvePageGeometry as c, PAGE_SIZES as i, DEFAULT_PAGE_SIZE as n, isOrientation as o, ORIENTATIONS as r, isPageSizeName as s, DEFAULT_ORIENTATION as t };
@@ -1,4 +1,4 @@
1
- import { n as OpenDocConfig } from "../config-CSC5lHsR.js";
1
+ import { n as OpenDocConfig } from "../config-P61niZMf.js";
2
2
  import { InlineConfig, Plugin } from "vite";
3
3
  //#region src/vite/open-doc-plugin.d.ts
4
4
  type OpenDocPluginOptions = {
@@ -1,2 +1,2 @@
1
- import { A as openDocPlugin, t as createViteConfig } from "../config-Dg1AMP0r.js";
1
+ import { A as openDocPlugin, t as createViteConfig } from "../config-CNr8hd5X.js";
2
2
  export { createViteConfig, openDocPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-document/core",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Runtime and CLI for open-doc — write documents in docs/, we handle the pages, print layout, and export.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -37,7 +37,7 @@ Ask these in a single `AskUserQuestion` call (multi-question form). Skip a quest
37
37
  - *"our new product for enterprise buyers"* → **whitepaper** (problem, approach, evidence, references) · **sales proposal** (scope, deliverables, timeline, price) · **one-pager** (positioning + proof + CTA)
38
38
  Mark the best fit "(Recommended)".
39
39
  2. **Length** — offer brackets: 2–4 pages (brief), 5–10 (standard report), 11–25 (deep dive). The auto-added "Other" covers custom counts.
40
- 3. **Page size** — A4 (default, metric/international) · Letter (US) · A4 landscape (data-heavy, wide tables). Skip if the user already said.
40
+ 3. **Page size** — A4 portrait (default) · A4 landscape (data-heavy, wide tables) · B4 or A3 (plans, posters, very wide tables). The only sizes are A4, B4 and A3, each portrait or landscape. Skip if the user already said.
41
41
  4. **Visual direction** — 3 options tailored to the audience, each naming a palette + typographic cue: e.g. **corporate neutral** (near-white, single blue accent, sans throughout) · **editorial serif** (serif headings, generous leading, hairline rules) · **technical mono-accent** (mono labels, dense tables, monochrome + one signal color).
42
42
 
43
43
  Ask about brand colors, a logo, or required sections only if still unclear afterwards.
@@ -52,7 +52,7 @@ Keep this exact section order; adapt the bodies.
52
52
  ---
53
53
  name: <Human title, e.g. "Acme Corporate">
54
54
  description: <one-line elevator pitch>
55
- pageSize: <A4 | Letter>
55
+ pageSize: <A4 | B4 | A3>
56
56
  mode: <light | dark — light for anything that prints>
57
57
  ---
58
58
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: doc-authoring
3
- description: Technical reference for writing or editing open-doc pages — file contract, the A4/Letter page canvas, print type scale, the vertical budget that decides where a page breaks, tables, charts, table of contents, page numbers, running headers/footers, and assets. Consult this whenever you are about to write or modify any file under `docs/<id>/`, including from inside the `create-doc` workflow, or for any ad-hoc document edit. Triggers on phrases like "edit the report", "fix this page", "add a section", "change the margins", "add a table", "page numbers", "table of contents", "how do documents work here".
3
+ description: Technical reference for writing or editing open-doc pages — file contract, the A4/B4/A3 page canvas, print type scale, the vertical budget that decides where a page breaks, tables, charts, table of contents, page numbers, running headers/footers, and assets. Consult this whenever you are about to write or modify any file under `docs/<id>/`, including from inside the `create-doc` workflow, or for any ad-hoc document edit. Triggers on phrases like "edit the report", "fix this page", "add a section", "change the margins", "add a table", "page numbers", "table of contents", "how do documents work here".
4
4
  ---
5
5
 
6
6
  # Authoring open-doc pages
@@ -59,7 +59,7 @@ export default [Cover, Body] satisfies DocPage[];
59
59
 
60
60
  - `export default` is a **non-empty array of entries**. An entry is either a zero-prop React component (one fixed page) or a `flow(<>…</>)` section the framework paginates by measuring. Mix them freely — the usual shape is a fixed cover, a fixed contents page, then one flow section for the body.
61
61
  - **Default to `flow()` for body content.** Hand-splitting prose into fixed pages produces documents where every heading starts a half-empty page. Read `references/pagination.md` before writing either kind.
62
- - `meta.pageSize` is `'A4' | 'Letter' | 'A5' | 'Legal'` (default `'A4'`), `meta.orientation` is `'portrait' | 'landscape'` (default portrait). The same value drives the on-screen page, the `@page` size when printing, and the HTML export.
62
+ - `meta.pageSize` is `'A4' | 'B4' | 'A3'` (default `'A4'`) and `meta.orientation` is `'portrait' | 'landscape'` (default portrait). **These six combinations are the only sheets there are** — there is no Letter, no A5, no custom size, and no way to set a page's dimensions by hand. The same value drives the on-screen page, the `@page` size when printing, and the HTML export.
63
63
  - `meta.createdAt` is an **ISO 8601 string literal** set once when the doc is scaffolded — the home page sorts on it. **Immediately before writing the file, run `node -e "console.log(new Date().toISOString())"` and paste the exact output.** It must stay a plain string literal (no `new Date(...)`): the framework reads it with a regex at build time, it never evaluates the module.
64
64
 
65
65
  ## Two ways to fill pages
@@ -87,10 +87,11 @@ Fixed `DocPage` components remain the right tool for the cover, a contents page,
87
87
 
88
88
  | Size | Portrait px (96dpi) | Text block at 76px margins |
89
89
  | --- | --- | --- |
90
- | A4 | 794 × 1123 | 642 × 971 |
91
- | Letter | 816 × 1056 | 664 × 904 |
92
- | A5 | 559 × 794 | 407 × 642 |
93
- | Legal | 816 × 1344 | 664 × 1192 |
90
+ | A4 (210 × 297mm) | 794 × 1123 | 642 × 971 |
91
+ | B4 (JIS, 257 × 364mm) | 971 × 1376 | 819 × 1224 |
92
+ | A3 (297 × 420mm) | 1123 × 1587 | 971 × 1435 |
93
+
94
+ Landscape swaps the two numbers. B4 and A3 are for wide tables, plans, and posters — a body of prose set the full width of an A3 sheet is unreadable, so give a large sheet columns or wider margins.
94
95
 
95
96
  You design as if the viewport is literally the page in CSS pixels. The viewer only scales the whole sheet.
96
97
 
@@ -62,8 +62,9 @@ usable_height = page_height − 2 × margin
62
62
  | --- | --- | --- |
63
63
  | A4 portrait (1123px) | 76 | **971px** |
64
64
  | A4 portrait | 96 | 931px |
65
- | Letter portrait (1056px) | 76 | 904px |
66
65
  | A4 landscape (794px) | 76 | 642px |
66
+ | B4 portrait (1376px) | 76 | 1224px |
67
+ | A3 portrait (1587px) | 76 | 1435px |
67
68
 
68
69
  A running footer sits inside the margin band, so it costs nothing from the budget — but leave **24px of clearance** above it, i.e. treat the budget as ~947px on A4 when a footer is present.
69
70