@open-document/core 0.3.0 → 0.4.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.
- package/README.md +1 -0
- package/README.zh-TW.md +1 -0
- package/dist/{build-C3pMGxJN.js → build-BzhYQKev.js} +1 -1
- package/dist/{check-Dtwb1wvU.js → check-CCAaXofH.js} +3 -3
- package/dist/cli/bin.js +33 -21
- package/dist/{config-CSC5lHsR.d.ts → config-P61niZMf.d.ts} +6 -0
- package/dist/{context-FoX0afRf.js → context-CJpdjYfU.js} +3 -14
- package/dist/{dev-Cdd7NZRQ.js → dev-BhXgunme.js} +1 -1
- package/dist/{export-ClJ4T1uU.js → export-B69kDkyp.js} +3 -3
- package/dist/{import-D7Psi8WK.js → import-DBhCpUsl.js} +3 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -40
- package/dist/ops/index.d.ts +2 -2
- package/dist/ops/index.js +4 -3
- package/dist/{ops-Ci5Xw6QG.js → ops-BCBmRMCS.js} +7 -2
- package/dist/{preview-BhbCiAKC.js → preview-Da4Aq9yF.js} +1 -1
- package/dist/{sdk-CWMsH9Ms.d.ts → sdk-C9nl30dW.d.ts} +13 -7
- package/dist/sdk-DhcqZdAw.js +50 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/skills/create-doc/SKILL.md +1 -1
- package/skills/create-theme/SKILL.md +1 -1
- package/skills/doc-authoring/SKILL.md +7 -6
- package/skills/doc-authoring/references/pagination.md +2 -1
- package/src/app/components/themes/theme-preview.tsx +2 -2
- package/src/app/lib/sdk.test.ts +15 -9
- package/src/app/lib/sdk.ts +34 -11
- package/src/app/routes/doc.tsx +151 -111
- package/dist/{config-Dg1AMP0r.js → config-CNr8hd5X.js} +1 -1
package/README.md
CHANGED
package/README.zh-TW.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as listDocIds } from "./config-
|
|
2
|
-
import { m as closeRenderSession, p as checkLayout } from "./ops-
|
|
3
|
-
import { t as cliContext } from "./context-
|
|
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
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
-
"
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
|
11
|
+
coreVersion: await readCoreVersion()
|
|
23
12
|
});
|
|
24
13
|
}
|
|
25
14
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as listDocIds } from "./config-
|
|
2
|
-
import { h as exportDocument, m as closeRenderSession } from "./ops-
|
|
3
|
-
import { t as cliContext } from "./context-
|
|
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-
|
|
2
|
-
import { t as cliContext } from "./context-
|
|
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
|
|
2
|
-
import { n as OpenDocConfig, t as OpenDocBuildConfig } from "./config-
|
|
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
|
-
|
|
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 };
|
package/dist/ops/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../sdk-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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 {
|
|
2
|
-
import
|
|
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}`);
|
|
@@ -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
|
-
|
|
70
|
-
|
|
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
|
-
*
|
|
73
|
-
* with the physical
|
|
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
|
-
|
|
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 {
|
|
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 };
|
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as openDocPlugin, t as createViteConfig } from "../config-
|
|
1
|
+
import { A as openDocPlugin, t as createViteConfig } from "../config-CNr8hd5X.js";
|
|
2
2
|
export { createViteConfig, openDocPlugin };
|
package/package.json
CHANGED
|
@@ -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
|
|
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 |
|
|
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/
|
|
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' | '
|
|
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
|
-
|
|
|
92
|
-
|
|
|
93
|
-
|
|
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
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { type DocPage, resolvePageGeometry } from '../../lib/sdk';
|
|
2
|
+
import { type DocPage, isPageSizeName, resolvePageGeometry } from '../../lib/sdk';
|
|
3
3
|
import { loadThemeDemo, type ThemeDemoModule, type ThemeMeta } from '../../lib/themes';
|
|
4
4
|
import { PageFrame } from '../page-frame';
|
|
5
5
|
|
|
@@ -29,7 +29,7 @@ export function ThemePreview({ theme, width, all = false }: Props) {
|
|
|
29
29
|
}, [theme.id, theme.hasDemo]);
|
|
30
30
|
|
|
31
31
|
const geometry = resolvePageGeometry(
|
|
32
|
-
theme.pageSize ? { pageSize: theme.pageSize
|
|
32
|
+
isPageSizeName(theme.pageSize) ? { pageSize: theme.pageSize } : undefined,
|
|
33
33
|
);
|
|
34
34
|
const scale = width / geometry.width;
|
|
35
35
|
const pages = (demo?.default ?? []).filter(
|
package/src/app/lib/sdk.test.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { PAGE_SIZES, resolvePageGeometry } from './sdk.ts';
|
|
2
|
+
import { PAGE_SIZE_NAMES, PAGE_SIZES, resolvePageGeometry } from './sdk.ts';
|
|
3
3
|
|
|
4
4
|
describe('resolvePageGeometry', () => {
|
|
5
5
|
it('defaults to portrait A4', () => {
|
|
6
6
|
expect(resolvePageGeometry()).toEqual({
|
|
7
7
|
width: PAGE_SIZES.A4.width,
|
|
8
8
|
height: PAGE_SIZES.A4.height,
|
|
9
|
-
css:
|
|
9
|
+
css: '210mm 297mm',
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
it('
|
|
14
|
-
|
|
15
|
-
expect(
|
|
16
|
-
expect(geo.height).toBe(PAGE_SIZES.Letter.width);
|
|
17
|
-
expect(geo.css).toBe(`${PAGE_SIZES.Letter.css} landscape`);
|
|
13
|
+
it('offers A4, B4 and A3 and nothing else', () => {
|
|
14
|
+
expect([...PAGE_SIZE_NAMES]).toEqual(['A4', 'B4', 'A3']);
|
|
15
|
+
expect(Object.keys(PAGE_SIZES)).toEqual([...PAGE_SIZE_NAMES]);
|
|
18
16
|
});
|
|
19
17
|
|
|
20
|
-
it('
|
|
21
|
-
const geo = resolvePageGeometry({ pageSize: 'B4'
|
|
18
|
+
it('swaps both the pixel axes and the @page descriptor for landscape', () => {
|
|
19
|
+
const geo = resolvePageGeometry({ pageSize: 'B4', orientation: 'landscape' });
|
|
20
|
+
expect(geo.width).toBe(PAGE_SIZES.B4.height);
|
|
21
|
+
expect(geo.height).toBe(PAGE_SIZES.B4.width);
|
|
22
|
+
// Chromium drops `<mm> <mm> landscape` entirely — the axes must be swapped.
|
|
23
|
+
expect(geo.css).toBe('364mm 257mm');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('falls back to A4 for a page size that is no longer offered', () => {
|
|
27
|
+
const geo = resolvePageGeometry({ pageSize: 'Letter' as never });
|
|
22
28
|
expect(geo.width).toBe(PAGE_SIZES.A4.width);
|
|
23
29
|
});
|
|
24
30
|
});
|
package/src/app/lib/sdk.ts
CHANGED
|
@@ -2,24 +2,43 @@ import type { ComponentType, ReactNode } from 'react';
|
|
|
2
2
|
import type { DesignSystem } from './design.ts';
|
|
3
3
|
import type { LabelVocabulary } from './labels.ts';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/** The only sheets a document may be laid out on. */
|
|
6
|
+
export const PAGE_SIZE_NAMES = ['A4', 'B4', 'A3'] as const;
|
|
6
7
|
|
|
7
|
-
export type
|
|
8
|
+
export type PageSizeName = (typeof PAGE_SIZE_NAMES)[number];
|
|
9
|
+
|
|
10
|
+
export const ORIENTATIONS = ['portrait', 'landscape'] as const;
|
|
11
|
+
|
|
12
|
+
export type Orientation = (typeof ORIENTATIONS)[number];
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
|
-
*
|
|
11
|
-
* with the physical
|
|
12
|
-
* laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
|
|
15
|
+
* Portrait dimensions in CSS pixels at 96dpi — the unit authors write in —
|
|
16
|
+
* paired with the physical millimetres used when printing. Keeping both means a
|
|
17
|
+
* page laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
|
|
13
18
|
*/
|
|
14
|
-
export const PAGE_SIZES: Record<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
export const PAGE_SIZES: Record<
|
|
20
|
+
PageSizeName,
|
|
21
|
+
{ width: number; height: number; mm: readonly [number, number] }
|
|
22
|
+
> = {
|
|
23
|
+
A4: { width: 794, height: 1123, mm: [210, 297] },
|
|
24
|
+
// JIS B4, not the ISO B4 (250×353mm) that the CSS `size: B4` keyword means —
|
|
25
|
+
// which is why the descriptor is written in millimetres rather than by name.
|
|
26
|
+
B4: { width: 971, height: 1376, mm: [257, 364] },
|
|
27
|
+
A3: { width: 1123, height: 1587, mm: [297, 420] },
|
|
19
28
|
};
|
|
20
29
|
|
|
21
30
|
export const DEFAULT_PAGE_SIZE: PageSizeName = 'A4';
|
|
22
31
|
|
|
32
|
+
export const DEFAULT_ORIENTATION: Orientation = 'portrait';
|
|
33
|
+
|
|
34
|
+
export function isPageSizeName(value: unknown): value is PageSizeName {
|
|
35
|
+
return typeof value === 'string' && value in PAGE_SIZES;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function isOrientation(value: unknown): value is Orientation {
|
|
39
|
+
return value === 'portrait' || value === 'landscape';
|
|
40
|
+
}
|
|
41
|
+
|
|
23
42
|
export type PageGeometry = {
|
|
24
43
|
width: number;
|
|
25
44
|
height: number;
|
|
@@ -81,9 +100,13 @@ export type DocModule = {
|
|
|
81
100
|
export function resolvePageGeometry(meta?: DocMeta): PageGeometry {
|
|
82
101
|
const size = PAGE_SIZES[meta?.pageSize ?? DEFAULT_PAGE_SIZE] ?? PAGE_SIZES[DEFAULT_PAGE_SIZE];
|
|
83
102
|
const landscape = meta?.orientation === 'landscape';
|
|
103
|
+
const [across, down] = landscape ? [size.mm[1], size.mm[0]] : size.mm;
|
|
84
104
|
return {
|
|
85
105
|
width: landscape ? size.height : size.width,
|
|
86
106
|
height: landscape ? size.width : size.height,
|
|
87
|
-
|
|
107
|
+
// Not `<mm> <mm> landscape`: the `landscape` keyword is only valid next to a
|
|
108
|
+
// page-size *name*, and Chromium drops the whole descriptor if it sees both,
|
|
109
|
+
// which silently prints a landscape sheet at the dialog's default size.
|
|
110
|
+
css: `${across}mm ${down}mm`,
|
|
88
111
|
};
|
|
89
112
|
}
|
package/src/app/routes/doc.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import appConfig from 'virtual:open-doc/config';
|
|
1
2
|
import {
|
|
2
3
|
ArrowLeft,
|
|
3
4
|
Check,
|
|
@@ -21,6 +22,7 @@ import { DesignProvider } from '../components/design-panel/design-provider';
|
|
|
21
22
|
import { DocSidebar } from '../components/doc-sidebar';
|
|
22
23
|
import { Inspector } from '../components/inspector/inspector';
|
|
23
24
|
import { PageFrame } from '../components/page-frame';
|
|
25
|
+
import { ThemeToggle } from '../components/theme-toggle';
|
|
24
26
|
import { Menu, MenuItem } from '../components/ui/menu';
|
|
25
27
|
import { useAgentBridge } from '../lib/agent-bridge';
|
|
26
28
|
import { exportDocAsHtml } from '../lib/export-html';
|
|
@@ -52,6 +54,34 @@ const MIN_SCALE = 0.25;
|
|
|
52
54
|
const MAX_SCALE = 2;
|
|
53
55
|
const PAGE_GAP = 24;
|
|
54
56
|
|
|
57
|
+
const BACK_CLASS =
|
|
58
|
+
'flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* `config.home` leaves the router on purpose. A `<Link>` resolves inside the
|
|
62
|
+
* app's basename, which is exactly wrong when the viewer is mounted under a
|
|
63
|
+
* larger site and "back" means that site.
|
|
64
|
+
*
|
|
65
|
+
* With no `home` and no document browser there is nowhere to go: `/` renders
|
|
66
|
+
* "not found". A control that leads nowhere is worse than no control, and a
|
|
67
|
+
* host that mounts the viewer this way is providing its own way back.
|
|
68
|
+
*/
|
|
69
|
+
const HeaderBackLink = () => {
|
|
70
|
+
if (appConfig.home !== undefined) {
|
|
71
|
+
return (
|
|
72
|
+
<a href={appConfig.home} className={BACK_CLASS} aria-label="Back to workspace">
|
|
73
|
+
<ArrowLeft className="size-4" />
|
|
74
|
+
</a>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (!appConfig.build.showDocBrowser) return null;
|
|
78
|
+
return (
|
|
79
|
+
<Link to="/" className={BACK_CLASS} aria-label="Back to documents">
|
|
80
|
+
<ArrowLeft className="size-4" />
|
|
81
|
+
</Link>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
55
85
|
export function Doc() {
|
|
56
86
|
const { docId } = useParams<{ docId: string }>();
|
|
57
87
|
const state = useDocModule(docId);
|
|
@@ -280,129 +310,134 @@ export function Doc() {
|
|
|
280
310
|
|
|
281
311
|
const view = (
|
|
282
312
|
<div ref={rootRef} className="flex h-screen flex-col bg-background text-foreground">
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
<h1 className="truncate font-medium text-sm">{doc.meta?.title ?? docId}</h1>
|
|
293
|
-
{doc.meta?.subtitle && (
|
|
294
|
-
<p className="truncate text-muted-foreground text-xs">{doc.meta.subtitle}</p>
|
|
295
|
-
)}
|
|
313
|
+
{/* Equal `1fr` rails put the title at the true centre of the bar rather
|
|
314
|
+
than the centre of what is left over, which is where a flex row would
|
|
315
|
+
drop it — the control cluster is many times wider than the back link.
|
|
316
|
+
The control rail keeps its automatic minimum — no `min-w-0` — so when
|
|
317
|
+
it outgrows its share the title truncates and slides instead of being
|
|
318
|
+
overlapped by it. */}
|
|
319
|
+
<header className="grid h-12 flex-none grid-cols-[1fr_minmax(0,auto)_1fr] items-center gap-3 border-b border-border px-3">
|
|
320
|
+
<div className="flex min-w-0 items-center">
|
|
321
|
+
<HeaderBackLink />
|
|
296
322
|
</div>
|
|
297
323
|
|
|
298
|
-
<
|
|
299
|
-
|
|
300
|
-
|
|
324
|
+
<h1 className="truncate text-center font-medium text-sm">{doc.meta?.title ?? docId}</h1>
|
|
325
|
+
|
|
326
|
+
<div className="flex items-center justify-end gap-3">
|
|
327
|
+
<span className="hidden whitespace-nowrap font-mono text-muted-foreground text-xs tabular-nums sm:inline">
|
|
328
|
+
{currentPage} / {pages.length}
|
|
329
|
+
</span>
|
|
330
|
+
|
|
331
|
+
<div className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
332
|
+
<IconButton label="Zoom out" onClick={() => zoom(-0.1)}>
|
|
333
|
+
<Minus className="size-3.5" />
|
|
334
|
+
</IconButton>
|
|
335
|
+
<button
|
|
336
|
+
type="button"
|
|
337
|
+
onClick={actualSize}
|
|
338
|
+
title="Actual size (100%)"
|
|
339
|
+
className="w-11 rounded text-center font-mono text-[11px] tabular-nums transition-colors hover:bg-accent"
|
|
340
|
+
>
|
|
341
|
+
{Math.round(scale * 100)}%
|
|
342
|
+
</button>
|
|
343
|
+
<IconButton label="Zoom in" onClick={() => zoom(0.1)}>
|
|
344
|
+
<Plus className="size-3.5" />
|
|
345
|
+
</IconButton>
|
|
346
|
+
<IconButton
|
|
347
|
+
label="Fit width"
|
|
348
|
+
onClick={() => fitTo('fit-width')}
|
|
349
|
+
active={manualScale === null && zoomMode === 'fit-width'}
|
|
350
|
+
>
|
|
351
|
+
<MoveHorizontal className="size-3.5" />
|
|
352
|
+
</IconButton>
|
|
353
|
+
<IconButton
|
|
354
|
+
label="Fit page"
|
|
355
|
+
onClick={() => fitTo('fit-page')}
|
|
356
|
+
active={manualScale === null && zoomMode === 'fit-page'}
|
|
357
|
+
>
|
|
358
|
+
<Scan className="size-3.5" />
|
|
359
|
+
</IconButton>
|
|
360
|
+
</div>
|
|
301
361
|
|
|
302
|
-
<div className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
303
|
-
<IconButton label="Zoom out" onClick={() => zoom(-0.1)}>
|
|
304
|
-
<Minus className="size-3.5" />
|
|
305
|
-
</IconButton>
|
|
306
|
-
<button
|
|
307
|
-
type="button"
|
|
308
|
-
onClick={actualSize}
|
|
309
|
-
title="Actual size (100%)"
|
|
310
|
-
className="w-11 rounded text-center font-mono text-[11px] tabular-nums transition-colors hover:bg-accent"
|
|
311
|
-
>
|
|
312
|
-
{Math.round(scale * 100)}%
|
|
313
|
-
</button>
|
|
314
|
-
<IconButton label="Zoom in" onClick={() => zoom(0.1)}>
|
|
315
|
-
<Plus className="size-3.5" />
|
|
316
|
-
</IconButton>
|
|
317
|
-
<IconButton
|
|
318
|
-
label="Fit width"
|
|
319
|
-
onClick={() => fitTo('fit-width')}
|
|
320
|
-
active={manualScale === null && zoomMode === 'fit-width'}
|
|
321
|
-
>
|
|
322
|
-
<MoveHorizontal className="size-3.5" />
|
|
323
|
-
</IconButton>
|
|
324
362
|
<IconButton
|
|
325
|
-
label=
|
|
326
|
-
onClick={
|
|
327
|
-
active={manualScale === null && zoomMode === 'fit-page'}
|
|
363
|
+
label={isFullscreen ? 'Exit fullscreen (F)' : 'Fullscreen (F)'}
|
|
364
|
+
onClick={toggleFullscreen}
|
|
328
365
|
>
|
|
329
|
-
<
|
|
366
|
+
{isFullscreen ? <Minimize className="size-4" /> : <Maximize className="size-4" />}
|
|
330
367
|
</IconButton>
|
|
331
|
-
</div>
|
|
332
368
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
{import.meta.env.DEV && (
|
|
341
|
-
<button
|
|
342
|
-
type="button"
|
|
343
|
-
onClick={() => setInspecting((on) => !on)}
|
|
344
|
-
title="Inspect and edit on the page"
|
|
345
|
-
className={cn(
|
|
346
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
347
|
-
inspecting && 'border-transparent bg-[#3b82f6] text-white hover:bg-[#3b82f6]',
|
|
348
|
-
)}
|
|
349
|
-
>
|
|
350
|
-
<MousePointerClick className="size-3.5" />
|
|
351
|
-
Inspect
|
|
352
|
-
</button>
|
|
353
|
-
)}
|
|
354
|
-
{import.meta.env.DEV && (
|
|
355
|
-
<button
|
|
356
|
-
type="button"
|
|
357
|
-
onClick={() => setDesignOpen((open) => !open)}
|
|
358
|
-
className={cn(
|
|
359
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
360
|
-
designOpen && 'bg-accent',
|
|
361
|
-
)}
|
|
362
|
-
>
|
|
363
|
-
<Palette className="size-3.5" />
|
|
364
|
-
Design
|
|
365
|
-
</button>
|
|
366
|
-
)}
|
|
367
|
-
<Menu
|
|
368
|
-
trigger={(props) => (
|
|
369
|
+
{/* The document browser normally carries this. A viewer mounted with
|
|
370
|
+
`showDocBrowser: false` never shows that shell, and without it a
|
|
371
|
+
reader has no way to change the theme at all. */}
|
|
372
|
+
{!appConfig.build.showDocBrowser && <ThemeToggle />}
|
|
373
|
+
|
|
374
|
+
{import.meta.env.DEV && (
|
|
369
375
|
<button
|
|
370
376
|
type="button"
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
{
|
|
377
|
+
onClick={() => setInspecting((on) => !on)}
|
|
378
|
+
title="Inspect and edit on the page"
|
|
379
|
+
className={cn(
|
|
380
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
381
|
+
inspecting && 'border-transparent bg-[#3b82f6] text-white hover:bg-[#3b82f6]',
|
|
382
|
+
)}
|
|
374
383
|
>
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
384
|
+
<MousePointerClick className="size-3.5" />
|
|
385
|
+
Inspect
|
|
386
|
+
</button>
|
|
387
|
+
)}
|
|
388
|
+
{import.meta.env.DEV && (
|
|
389
|
+
<button
|
|
390
|
+
type="button"
|
|
391
|
+
onClick={() => setDesignOpen((open) => !open)}
|
|
392
|
+
className={cn(
|
|
393
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
394
|
+
designOpen && 'bg-accent',
|
|
381
395
|
)}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
396
|
+
>
|
|
397
|
+
<Palette className="size-3.5" />
|
|
398
|
+
Design
|
|
385
399
|
</button>
|
|
386
400
|
)}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
void runDownload(format);
|
|
395
|
-
}}
|
|
401
|
+
<Menu
|
|
402
|
+
trigger={(props) => (
|
|
403
|
+
<button
|
|
404
|
+
type="button"
|
|
405
|
+
disabled={download !== null}
|
|
406
|
+
className="flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
407
|
+
{...props}
|
|
396
408
|
>
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
<
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
409
|
+
{download ? (
|
|
410
|
+
<Loader2 className="size-3.5 animate-spin" />
|
|
411
|
+
) : downloaded ? (
|
|
412
|
+
<Check className="size-3.5" />
|
|
413
|
+
) : (
|
|
414
|
+
<Download className="size-3.5" />
|
|
415
|
+
)}
|
|
416
|
+
{download
|
|
417
|
+
? `${DOWNLOAD_LABEL[download.format]} ${Math.round(download.percent)}%`
|
|
418
|
+
: 'Download'}
|
|
419
|
+
</button>
|
|
420
|
+
)}
|
|
421
|
+
>
|
|
422
|
+
{(close) =>
|
|
423
|
+
DOWNLOAD_FORMATS.map(({ format, label, hint, icon: Icon }) => (
|
|
424
|
+
<MenuItem
|
|
425
|
+
key={format}
|
|
426
|
+
onClick={() => {
|
|
427
|
+
close();
|
|
428
|
+
void runDownload(format);
|
|
429
|
+
}}
|
|
430
|
+
>
|
|
431
|
+
<Icon className="size-3.5 flex-none" />
|
|
432
|
+
<span className="flex-1">
|
|
433
|
+
{label}
|
|
434
|
+
<span className="block text-[10px] text-muted-foreground">{hint}</span>
|
|
435
|
+
</span>
|
|
436
|
+
</MenuItem>
|
|
437
|
+
))
|
|
438
|
+
}
|
|
439
|
+
</Menu>
|
|
440
|
+
</div>
|
|
406
441
|
</header>
|
|
407
442
|
|
|
408
443
|
<div className="flex min-h-0 flex-1">
|
|
@@ -492,9 +527,14 @@ function Centered({ children }: { children: React.ReactNode }) {
|
|
|
492
527
|
}
|
|
493
528
|
|
|
494
529
|
function BackLink() {
|
|
495
|
-
|
|
496
|
-
|
|
530
|
+
const className = 'mt-4 inline-block text-muted-foreground text-xs underline';
|
|
531
|
+
return appConfig.home === undefined ? (
|
|
532
|
+
<Link to="/" className={className}>
|
|
497
533
|
Back to documents
|
|
498
534
|
</Link>
|
|
535
|
+
) : (
|
|
536
|
+
<a href={appConfig.home} className={className}>
|
|
537
|
+
Back to workspace
|
|
538
|
+
</a>
|
|
499
539
|
);
|
|
500
540
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as defaultDesign, n as DiagramSyntaxError, r as parseDelimited, t as compileDiagram } from "./diagram-xlVDekYk.js";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
7
|
import fg from "fast-glob";
|
|
8
8
|
import { loadConfigFromFile, normalizePath } from "vite";
|