@open-document/core 0.2.0 → 0.3.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/dist/{build-U81g9Hnk.js → build-C3pMGxJN.js} +1 -1
- package/dist/check-Dtwb1wvU.js +42 -0
- package/dist/cli/bin.js +24 -3
- package/dist/config-Dg1AMP0r.js +2461 -0
- package/dist/context-FoX0afRf.js +26 -0
- package/dist/{dev-DwwFT6uX.js → dev-Cdd7NZRQ.js} +1 -1
- package/dist/diagram-xlVDekYk.js +763 -0
- package/dist/export-ClJ4T1uU.js +36 -0
- package/dist/import-D7Psi8WK.js +25 -0
- package/dist/index.d.ts +235 -90
- package/dist/index.js +515 -49
- package/dist/ops/index.d.ts +96 -1
- package/dist/ops/index.js +3 -199
- package/dist/ops-Ci5Xw6QG.js +1270 -0
- package/dist/{preview-C_jbySle.js → preview-BhbCiAKC.js} +1 -1
- package/dist/sdk-CWMsH9Ms.d.ts +123 -0
- package/dist/vite/index.d.ts +6 -0
- package/dist/vite/index.js +1 -2
- package/env.d.ts +33 -1
- package/package.json +10 -1
- package/skills/create-doc/SKILL.md +6 -2
- package/skills/doc-authoring/SKILL.md +79 -0
- package/skills/doc-authoring/references/long-form.md +131 -0
- package/src/app/components/data-table.tsx +196 -0
- package/src/app/components/diagram.tsx +76 -0
- package/src/app/components/flow-page.tsx +20 -3
- package/src/app/components/footnote.tsx +196 -0
- package/src/app/components/numbering.tsx +208 -0
- package/src/app/lib/agent-bridge.ts +128 -0
- package/src/app/lib/diagnostics.ts +282 -0
- package/src/app/lib/export-html.ts +35 -11
- package/src/app/lib/export-pdf.ts +54 -19
- package/src/app/lib/flow-measure.ts +100 -31
- package/src/app/lib/flow.test.ts +46 -0
- package/src/app/lib/flow.ts +28 -3
- package/src/app/lib/footnotes.test.tsx +102 -0
- package/src/app/lib/footnotes.ts +94 -0
- package/src/app/lib/labels.ts +175 -0
- package/src/app/lib/page-context.tsx +6 -1
- package/src/app/lib/scan.ts +26 -0
- package/src/app/lib/sdk.ts +3 -0
- package/src/app/lib/use-doc-pages.ts +50 -15
- package/src/app/routes/doc.tsx +7 -4
- package/dist/config-8zkUElGq.js +0 -1169
- package/dist/design-IyRSwCtK.js +0 -52
- package/dist/edit-ops-D2W2plpc.js +0 -1190
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from "react";
|
|
2
|
+
//#region src/app/lib/labels.d.ts
|
|
3
|
+
type LabelKind = 'figure' | 'table' | 'footnote';
|
|
4
|
+
type LabelEntry = {
|
|
5
|
+
/** Author-supplied id for `<Ref to>`, or a generated one. */
|
|
6
|
+
id: string;
|
|
7
|
+
kind: LabelKind;
|
|
8
|
+
/** 1-based, counted per kind across the whole document. */
|
|
9
|
+
number: number;
|
|
10
|
+
/** Caption text, for a list of figures. */
|
|
11
|
+
text: string;
|
|
12
|
+
/** 1-based page the item sits on. */
|
|
13
|
+
page: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The words wrapped around a number. Numbering is structural; what it is
|
|
17
|
+
* *called* is a document's own business — `圖 3` and `Figure 3` are the same
|
|
18
|
+
* entry. Set it once in `meta.labels`.
|
|
19
|
+
*/
|
|
20
|
+
type LabelVocabulary = {
|
|
21
|
+
figure: string;
|
|
22
|
+
table: string;
|
|
23
|
+
/** Heading above a page's footnotes. Empty string renders no heading. */
|
|
24
|
+
footnotes: string;
|
|
25
|
+
/** Page suffix for a cross-reference. `{page}` is replaced. */
|
|
26
|
+
onPage: string;
|
|
27
|
+
};
|
|
28
|
+
/** The document's numbered items of one kind, in order. Empty on the first render pass. */
|
|
29
|
+
declare function useDocLabels(kind: LabelKind): LabelEntry[];
|
|
30
|
+
/** One numbered item by id, once the scan has run. */
|
|
31
|
+
declare function useDocLabel(id: string): LabelEntry | null;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/app/lib/design.d.ts
|
|
34
|
+
type DesignPalette = {
|
|
35
|
+
bg: string;
|
|
36
|
+
text: string;
|
|
37
|
+
muted: string;
|
|
38
|
+
accent: string;
|
|
39
|
+
rule: string;
|
|
40
|
+
};
|
|
41
|
+
type DesignFonts = {
|
|
42
|
+
heading: string;
|
|
43
|
+
body: string;
|
|
44
|
+
mono: string;
|
|
45
|
+
};
|
|
46
|
+
type DesignTypeScale = {
|
|
47
|
+
title: number;
|
|
48
|
+
h1: number;
|
|
49
|
+
h2: number;
|
|
50
|
+
h3: number;
|
|
51
|
+
body: number;
|
|
52
|
+
caption: number;
|
|
53
|
+
};
|
|
54
|
+
type DesignSystem = {
|
|
55
|
+
palette: DesignPalette;
|
|
56
|
+
fonts: DesignFonts;
|
|
57
|
+
typeScale: DesignTypeScale;
|
|
58
|
+
/** Page margin in CSS px — the printable text block's inset from the sheet edge. */
|
|
59
|
+
margin: number;
|
|
60
|
+
/** Body line-height multiplier. Headings tighten this themselves. */
|
|
61
|
+
leading: number;
|
|
62
|
+
radius: number;
|
|
63
|
+
};
|
|
64
|
+
declare function designToCssVars(d: DesignSystem): Record<string, string>;
|
|
65
|
+
declare function cssVarsToString(vars: Record<string, string>): string;
|
|
66
|
+
declare const defaultDesign: DesignSystem;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/app/lib/sdk.d.ts
|
|
69
|
+
type PageSizeName = 'A4' | 'Letter' | 'A5' | 'Legal';
|
|
70
|
+
type Orientation = 'portrait' | 'landscape';
|
|
71
|
+
/**
|
|
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
|
+
*/
|
|
76
|
+
declare const PAGE_SIZES: Record<PageSizeName, {
|
|
77
|
+
width: number;
|
|
78
|
+
height: number;
|
|
79
|
+
css: string;
|
|
80
|
+
}>;
|
|
81
|
+
declare const DEFAULT_PAGE_SIZE: PageSizeName;
|
|
82
|
+
type PageGeometry = {
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
/** Value for the `@page { size: … }` descriptor, orientation included. */
|
|
86
|
+
css: string;
|
|
87
|
+
};
|
|
88
|
+
type DocPage = ComponentType;
|
|
89
|
+
/**
|
|
90
|
+
* A run of continuous content the framework paginates itself. Build one with
|
|
91
|
+
* `flow(...)` and put it in the page array alongside fixed pages.
|
|
92
|
+
*/
|
|
93
|
+
type FlowSection = {
|
|
94
|
+
readonly __odFlow: true;
|
|
95
|
+
blocks: ReactNode[];
|
|
96
|
+
/** Rendered on every page the section expands into. */
|
|
97
|
+
footer?: ComponentType;
|
|
98
|
+
/** Page padding override in px; defaults to the design's `margin`. */
|
|
99
|
+
padding?: number;
|
|
100
|
+
};
|
|
101
|
+
/** What a document's default export may contain: fixed pages, flow sections, or both. */
|
|
102
|
+
type DocEntry = DocPage | FlowSection;
|
|
103
|
+
type DocMeta = {
|
|
104
|
+
title?: string;
|
|
105
|
+
subtitle?: string;
|
|
106
|
+
author?: string;
|
|
107
|
+
pageSize?: PageSizeName;
|
|
108
|
+
orientation?: Orientation;
|
|
109
|
+
/** Id of a theme under `themes/` this document was built from. Adds a back-link. */
|
|
110
|
+
theme?: string;
|
|
111
|
+
/** ISO 8601 timestamp. Set once at scaffold time; used to sort the doc list. */
|
|
112
|
+
createdAt?: string;
|
|
113
|
+
/** What numbered items are called — `圖`/`表` instead of `Figure`/`Table`. */
|
|
114
|
+
labels?: Partial<LabelVocabulary>;
|
|
115
|
+
};
|
|
116
|
+
type DocModule = {
|
|
117
|
+
default: DocEntry[];
|
|
118
|
+
meta?: DocMeta;
|
|
119
|
+
design?: DesignSystem;
|
|
120
|
+
};
|
|
121
|
+
declare function resolvePageGeometry(meta?: DocMeta): PageGeometry;
|
|
122
|
+
//#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 };
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ type CreateViteConfigOptions = {
|
|
|
15
15
|
mcp?: boolean;
|
|
16
16
|
config?: OpenDocConfig;
|
|
17
17
|
mode?: 'serve' | 'build';
|
|
18
|
+
/**
|
|
19
|
+
* Drive the app from a headless browser rather than a person. Leaves out the
|
|
20
|
+
* plugins that exist to serve a reader — chiefly the one publishing the
|
|
21
|
+
* reading position, which an export would otherwise overwrite.
|
|
22
|
+
*/
|
|
23
|
+
headless?: boolean;
|
|
18
24
|
};
|
|
19
25
|
declare function createViteConfig(opts: CreateViteConfigOptions): Promise<InlineConfig>;
|
|
20
26
|
//#endregion
|
package/dist/vite/index.js
CHANGED
package/env.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// Ambient module declarations for assets imported from `docs/<id>/assets
|
|
1
|
+
// Ambient module declarations for assets imported from `docs/<id>/assets/`
|
|
2
|
+
// and for the data files the framework parses at build time.
|
|
2
3
|
// Mirrors Vite's default asset handling (default export = resolved URL).
|
|
3
4
|
//
|
|
4
5
|
// Consumers opt in via tsconfig:
|
|
@@ -49,3 +50,34 @@ declare module '*.otf' {
|
|
|
49
50
|
const src: string;
|
|
50
51
|
export default src;
|
|
51
52
|
}
|
|
53
|
+
|
|
54
|
+
// Parsed by the `open-doc:data` Vite plugin — the default export is the rows.
|
|
55
|
+
declare module '*.csv' {
|
|
56
|
+
type CellValue = string | number | null;
|
|
57
|
+
export const columns: string[];
|
|
58
|
+
export const rows: Array<Record<string, CellValue>>;
|
|
59
|
+
export default rows;
|
|
60
|
+
}
|
|
61
|
+
declare module '*.tsv' {
|
|
62
|
+
type CellValue = string | number | null;
|
|
63
|
+
export const columns: string[];
|
|
64
|
+
export const rows: Array<Record<string, CellValue>>;
|
|
65
|
+
export default rows;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Compiled by the `open-doc:diagram` Vite plugin — the default export is the
|
|
69
|
+
// themed SVG and its natural size, ready for `<Diagram chart={…} />`.
|
|
70
|
+
declare module '*.mmd' {
|
|
71
|
+
export const svg: string;
|
|
72
|
+
export const width: number;
|
|
73
|
+
export const height: number;
|
|
74
|
+
const chart: { svg: string; width: number; height: number };
|
|
75
|
+
export default chart;
|
|
76
|
+
}
|
|
77
|
+
declare module '*.mermaid' {
|
|
78
|
+
export const svg: string;
|
|
79
|
+
export const width: number;
|
|
80
|
+
export const height: number;
|
|
81
|
+
const chart: { svg: string; width: number; height: number };
|
|
82
|
+
export default chart;
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-document/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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": {
|
|
@@ -82,9 +82,18 @@
|
|
|
82
82
|
"@types/node": "^22.19.17",
|
|
83
83
|
"@types/react": "^18.3.12",
|
|
84
84
|
"@types/react-dom": "^18.3.1",
|
|
85
|
+
"playwright": "~1.56.1",
|
|
85
86
|
"tsdown": "^0.22.14",
|
|
86
87
|
"typescript": "^5.9.3"
|
|
87
88
|
},
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"playwright": "*"
|
|
91
|
+
},
|
|
92
|
+
"peerDependenciesMeta": {
|
|
93
|
+
"playwright": {
|
|
94
|
+
"optional": true
|
|
95
|
+
}
|
|
96
|
+
},
|
|
88
97
|
"scripts": {
|
|
89
98
|
"build": "tsdown",
|
|
90
99
|
"typecheck": "tsc --noEmit",
|
|
@@ -9,6 +9,8 @@ This skill owns the **workflow** for drafting a new document. The technical refe
|
|
|
9
9
|
|
|
10
10
|
You only write files under `docs/<id>/`. Never modify `package.json`, `open-doc.config.ts`, or existing documents.
|
|
11
11
|
|
|
12
|
+
**If the user already has the content written as Markdown, don't retype it into JSX.** `open-doc import <file.md> --id <id>` produces a real document — `flow()` body, cover, contents, local images copied into the document's assets — which you then refine. Steps 0–2 still apply for the parts the import cannot know (theme, page size, visual direction).
|
|
13
|
+
|
|
12
14
|
## Step 0 — Pick a theme
|
|
13
15
|
|
|
14
16
|
List files under `themes/`. If any theme markdown exists (anything other than `README.md`), call `AskUserQuestion` with each theme id as an option plus a final **"no theme — design from scratch"** option. (`AskUserQuestion` holds at most 4 options — with 4+ themes, offer the 3 most relevant plus "no theme"; the auto-added "Other" lets the user name an omitted one.)
|
|
@@ -87,7 +89,9 @@ While writing:
|
|
|
87
89
|
|
|
88
90
|
## Step 7 — Self-review
|
|
89
91
|
|
|
90
|
-
Run the
|
|
92
|
+
**Run `open-doc check <id>` first.** You cannot see the sheets you produced; it renders them at true page size and reports clipped content, blank pages, stranded headings, and unreadable type, each with a source location. Fix every error before moving on. (Driving the MCP server instead? `check_layout`, and `render_page` when you need to look at a sheet.)
|
|
93
|
+
|
|
94
|
+
Then run the checklist in `doc-authoring` ("Self-review before finishing"), and re-read the prose once as a reader: does the summary state the conclusion? Does every claim have a source?
|
|
91
95
|
|
|
92
96
|
## Step 8 — Hand off
|
|
93
97
|
|
|
@@ -96,7 +100,7 @@ Tell the user:
|
|
|
96
100
|
- The doc id and file path.
|
|
97
101
|
- That the dev server hot-reloads — open `http://localhost:5273/d/<id>` (or refresh the home page).
|
|
98
102
|
- **Every placeholder and `TODO:` you left**, and what data each one needs.
|
|
99
|
-
- That "Export PDF" in the toolbar prints at the true page size, and "HTML" downloads a self-contained copy.
|
|
103
|
+
- That "Export PDF" in the toolbar prints at the true page size, and "HTML" downloads a self-contained copy — or `open-doc export <id>` for the same files without a browser.
|
|
100
104
|
- That the **Design** button live-tweaks the palette and type scale and writes the result back to the source, and that images they want to drop in go through the **Assets** page.
|
|
101
105
|
|
|
102
106
|
Don't run the dev server yourself unless asked.
|
|
@@ -21,6 +21,7 @@ Read the matching reference **before** using a primitive:
|
|
|
21
21
|
| Vertical budget (fixed pages) | laying out a cover or divider by hand | `references/pagination.md` |
|
|
22
22
|
| Tables, stat rows, inline charts | rendering data of any kind | `references/tables-and-charts.md` |
|
|
23
23
|
| Assets + `<ImagePlaceholder>` | importing images or leaving a placeholder | `references/assets.md` |
|
|
24
|
+
| Footnotes, `<Figure>`, `<Ref>`, `<DataTable>` | any note, numbered figure, cross-reference, or `.csv` | `references/long-form.md` |
|
|
24
25
|
|
|
25
26
|
## Themes
|
|
26
27
|
|
|
@@ -96,6 +97,7 @@ You design as if the viewport is literally the page in CSS pixels. The viewer on
|
|
|
96
97
|
- Use **absolute pixel values** for `font-size`, padding, and positioning. No `rem`, no `vw`/`vh`, no `%` for type.
|
|
97
98
|
- Each page's root element must fill the sheet: `width: '100%'; height: '100%'`.
|
|
98
99
|
- Prefer inline `style={{ … }}`. Any CSS you load is global — scope classnames carefully.
|
|
100
|
+
- The viewer's CSS reset strips list markers. A `<ul>`/`<ol>` needs an explicit `listStyle: 'disc outside'` / `'decimal outside'` or it renders as unindented plain lines.
|
|
99
101
|
- **1pt ≈ 1.333px.** Body copy at 14px prints as ~10.5pt; anything under 12px (9pt) is uncomfortable in print, and under 10px (7.5pt) is unreadable.
|
|
100
102
|
|
|
101
103
|
### Print type scale (start here)
|
|
@@ -135,6 +137,59 @@ The framework builds the document outline by scanning rendered pages for `h1`, `
|
|
|
135
137
|
- **The cover title and the word "Contents" both carry `data-od-outline="skip"`.** A contents list that opens with the cover and lists itself reads as a bug.
|
|
136
138
|
- Override the listed text with `data-od-heading="Short title"` when the visible heading is long or contains markup.
|
|
137
139
|
|
|
140
|
+
## Footnotes, numbering, and data
|
|
141
|
+
|
|
142
|
+
Four primitives resolve themselves from the rendered pages, the same way the
|
|
143
|
+
contents list does. Read `references/long-form.md` before using any of them.
|
|
144
|
+
|
|
145
|
+
- **`<Footnote>`** — numbered by position, printed at the foot of the page its
|
|
146
|
+
marker landed on, and its height is taken out of that page's budget before the
|
|
147
|
+
packer breaks. On a fixed page, add `<Footnotes />` where they should print.
|
|
148
|
+
- **`<Figure caption id>`** — a numbered figure (or `kind="table"`), caption and
|
|
149
|
+
content in one unbreakable block. `<ListOfFigures />` / `<ListOfTables />`
|
|
150
|
+
build the lists.
|
|
151
|
+
- **`<Ref to="id" />`** — "Figure 3", plus the page when the target is elsewhere.
|
|
152
|
+
- **`<DataTable rows={…}>`** — a print-shaped table from an imported `.csv`.
|
|
153
|
+
- **`<Diagram chart={…} caption>`** — an architecture or flow drawing from an
|
|
154
|
+
imported `.mmd`. Given a caption it numbers as a figure, like `<Figure>`.
|
|
155
|
+
|
|
156
|
+
`meta.labels` sets what they are called (`圖`, `表`) — the numbering itself is
|
|
157
|
+
structural.
|
|
158
|
+
|
|
159
|
+
## Diagrams
|
|
160
|
+
|
|
161
|
+
Write the drawing as Mermaid-flavoured text in `docs/<id>/<name>.mmd`, import
|
|
162
|
+
it, and hand it to `<Diagram>`:
|
|
163
|
+
|
|
164
|
+
```mermaid
|
|
165
|
+
%% docs/my-doc/architecture.mmd
|
|
166
|
+
flowchart TD
|
|
167
|
+
Client[使用者] -->|HTTPS| Gate{驗證}
|
|
168
|
+
Gate -->|通過| App[應用伺服器]
|
|
169
|
+
Gate -.->|拒絕| Deny([401])
|
|
170
|
+
App --> DB[資料庫]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
import { Diagram } from '@open-document/core';
|
|
175
|
+
import architecture from './architecture.mmd';
|
|
176
|
+
|
|
177
|
+
<Diagram chart={architecture} caption="請求路徑" width={420} />
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
It is compiled to SVG at build time and drawn with the document's own theme
|
|
181
|
+
variables, so it prints with the same ink and faces as the prose around it.
|
|
182
|
+
Never reach for an image of a diagram when the diagram can be written.
|
|
183
|
+
|
|
184
|
+
Supported: `flowchart`/`graph` with `TD` or `LR`; nodes as `A[box]`, `A(round)`,
|
|
185
|
+
`A([stadium])`, `A{decision}`, `A((circle))`; links `-->`, `---`, `-.->`, `==>`
|
|
186
|
+
with optional `|labels|`; chains `A --> B --> C`; `%%` comments. Anything else
|
|
187
|
+
in Mermaid's syntax — subgraphs, class diagrams, sequence diagrams — is not
|
|
188
|
+
supported, and a bad diagram fails the build with the line to fix.
|
|
189
|
+
|
|
190
|
+
Keep `width` inside the text block: a drawing wider than the column is a layout
|
|
191
|
+
fault, and `open-doc check` reports it as one.
|
|
192
|
+
|
|
138
193
|
## Table of contents
|
|
139
194
|
|
|
140
195
|
```tsx
|
|
@@ -302,6 +357,7 @@ A document is not a slide deck. Long-form copy is the point — but it still has
|
|
|
302
357
|
- **Assets panel** (`/assets` in the dev UI): upload, rename, and delete files in the global `assets/` folder or any document's `assets/` folder, with an "unused" badge and a copy-ready import line. Files you reference in source are what it scans, so an import you write by hand shows up there immediately.
|
|
303
358
|
- **Inspect mode** (the "Inspect" button, dev only): click any element on a page to edit its text in place — the change is written straight back into `docs/<id>/index.tsx` — or leave a note for the agent, which is stored as a `@doc-comment` marker and processed by the `apply-comments` skill.
|
|
304
359
|
- **Download menu** — PDF (true page size) and self-contained HTML.
|
|
360
|
+
- **Headless render** — `open-doc export <id> --format pdf|html|png` produces the same output from a script, and `open-doc check <id>` reports layout faults. Both drive the real viewer in a headless browser, so what they produce is what the Download menu produces.
|
|
305
361
|
- **Design panel** (the "Design" button in the document view, dev only): live-tweaks the `design` const — palette, fonts, type scale, margin, leading, radius — previewing on the real pages and writing the values back into `docs/<id>/index.tsx` on save.
|
|
306
362
|
|
|
307
363
|
### Writing for the inspector
|
|
@@ -325,8 +381,27 @@ The panel rewrites the `design` object in place through an AST edit, so keep its
|
|
|
325
381
|
- Values you want tweakable live *in* the const. A hex you inline into a style is invisible to the panel.
|
|
326
382
|
- If the document has no `design` const, saving from the panel creates one (and adds the `DesignSystem` type import). Anything the panel can't parse is reported in the panel instead of being silently overwritten.
|
|
327
383
|
|
|
384
|
+
## Check the layout before you call it done
|
|
385
|
+
|
|
386
|
+
You cannot see the pages you just wrote. The framework can:
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
open-doc check <id> # every document if you omit the id; exits non-zero on errors
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
It renders each sheet at true page size and reports what a reader would call a
|
|
393
|
+
mistake — content clipped by the page edge, a blank sheet, a heading stranded at
|
|
394
|
+
the foot of a page, type too small to print, an image that never loaded — each
|
|
395
|
+
with the `line:column` in your source. Agents driving the MCP server call
|
|
396
|
+
`check_layout` for the same report, and `render_page` for a PNG of one sheet.
|
|
397
|
+
|
|
398
|
+
**Run it after writing a document and after any edit that changes how much text
|
|
399
|
+
is on a page.** The checklist below is what you reason about; `check` is what
|
|
400
|
+
confirms it.
|
|
401
|
+
|
|
328
402
|
## Self-review before finishing
|
|
329
403
|
|
|
404
|
+
- [ ] `open-doc check <id>` reports no errors.
|
|
330
405
|
- [ ] `docs/<id>/index.tsx` `export default`s a non-empty `DocEntry[]`, with body content in a `flow()` section rather than hand-split pages.
|
|
331
406
|
- [ ] Every page's root fills `100% × 100%` and sets `boxSizing: 'border-box'` with the margin as padding.
|
|
332
407
|
- [ ] **For every fixed page, sum (font_size × line_height × lines) + gaps + 2×margin ≤ page height.** If close, split — or move the content into the flow section. No `overflow: auto` escape hatches.
|
|
@@ -337,6 +412,8 @@ The panel rewrites the `design` object in place through an AST edit, so keep its
|
|
|
337
412
|
- [ ] Page numbers come from `useDocPageNumber()` / `useDocPageCount()`.
|
|
338
413
|
- [ ] Document declares a top-level `export const design: DesignSystem` and pages consume `var(--od-*)`.
|
|
339
414
|
- [ ] Tables have a header row, aligned numerals (`fontVariantNumeric: 'tabular-nums'`), and fit the text block width.
|
|
415
|
+
- [ ] Numbers that refer to other things — figures, tables, notes, pages — come from `<Ref>` / `<Figure>` / `<Footnote>`, never typed in.
|
|
416
|
+
- [ ] Any data that exists as a file is imported, not retyped into JSX.
|
|
340
417
|
- [ ] All imported assets exist on disk (`docs/<id>/assets/`, or root `assets/` via `@assets/...`).
|
|
341
418
|
- [ ] Every `<ImagePlaceholder>` marks a real image the user must supply — not decorative filler.
|
|
342
419
|
- [ ] Nothing outside `docs/<id>/` was edited.
|
|
@@ -347,6 +424,8 @@ The panel rewrites the `design` object in place through an AST edit, so keep its
|
|
|
347
424
|
- ❌ `overflow: auto` / `scroll` / `hidden` to "fit" more. The sheet doesn't scroll; you've hidden the bug.
|
|
348
425
|
- ❌ Shrinking body type below 13px or margins below 60px to cram content in.
|
|
349
426
|
- ❌ Hand-written contents lists or hardcoded page numbers — they go stale the moment a page is added.
|
|
427
|
+
- ❌ "See Figure 3 on page 12" written by hand, or a figure caption numbered `Figure 3` in the copy. Use `<Ref>` and `<Figure>`.
|
|
428
|
+
- ❌ Retyping a CSV the user already has into a JSX table.
|
|
350
429
|
- ❌ Fake headings (`<div>` styled like a title) — they vanish from the outline.
|
|
351
430
|
- ❌ A slide-deck voice: 6-word bullets and 100px type. This is a document.
|
|
352
431
|
- ❌ Tables built from `%` widths that overflow the text block, or with more than ~7 columns on portrait A4.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Footnotes, numbering, cross-references, and data
|
|
2
|
+
|
|
3
|
+
Everything here shares one mechanism: the framework **scans the rendered pages**
|
|
4
|
+
and fills in what only the finished layout knows. That is why none of these
|
|
5
|
+
numbers are written by hand, and why they are all correct after a page is
|
|
6
|
+
inserted in the middle of the document.
|
|
7
|
+
|
|
8
|
+
The trade is the same one `<TableOfContents>` makes: values are empty on the
|
|
9
|
+
first render pass and filled on the next. Both exporters scan their own copy
|
|
10
|
+
before serializing, so a PDF never contains a blank number.
|
|
11
|
+
|
|
12
|
+
## Footnotes
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Footnote } from '@open-document/core';
|
|
16
|
+
|
|
17
|
+
<p style={p}>
|
|
18
|
+
Spend grew 8% quarter over quarter
|
|
19
|
+
<Footnote>Billing export, 2026-10-02. Excludes the edge tier.</Footnote>, driven
|
|
20
|
+
almost entirely by one service.
|
|
21
|
+
</p>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- The marker is numbered by position in the document — across fixed pages and
|
|
25
|
+
flow sections alike. Insert a note anywhere and everything after it renumbers.
|
|
26
|
+
- Inside a `flow()` section the note prints at the **foot of whatever page its
|
|
27
|
+
marker landed on**, and the space it takes is subtracted from that page's
|
|
28
|
+
budget before the packer decides where to break. You do not reserve anything.
|
|
29
|
+
- Give a note an `id` when something needs to point at it: `<Footnote id="src-1">`.
|
|
30
|
+
|
|
31
|
+
**On a fixed page, add `<Footnotes />` where the notes should print.** A fixed
|
|
32
|
+
page is your layout, so the framework does not inject anything into it:
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
const Cover: DocPage = () => (
|
|
36
|
+
<div style={page}>
|
|
37
|
+
<p>Q3 2026<Footnote>Covers the platform tier only.</Footnote></p>
|
|
38
|
+
<Footnotes />
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Put `<Footnote>` in the JSX you hand to `flow()`.** The notes are lifted out of
|
|
44
|
+
the blocks before measurement, by walking the element tree you wrote. One hidden
|
|
45
|
+
inside a helper component's own body is invisible to that walk and will render
|
|
46
|
+
inline instead of at the foot of the page.
|
|
47
|
+
|
|
48
|
+
## Figures and tables
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { Figure } from '@open-document/core';
|
|
52
|
+
|
|
53
|
+
<Figure id="topology" caption="Service topology, Q3 2026">
|
|
54
|
+
<img src={diagram} alt="Service topology" style={{ width: '100%', display: 'block' }} />
|
|
55
|
+
</Figure>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- `kind="table"` numbers it with the tables instead, and captions above rather
|
|
59
|
+
than below.
|
|
60
|
+
- Content and caption are **one block**, so a flow section never separates them.
|
|
61
|
+
- `caption` may carry markup; pass `captionText` as well when it does, so the
|
|
62
|
+
list of figures has plain text to print.
|
|
63
|
+
|
|
64
|
+
`<ListOfFigures />` and `<ListOfTables />` build the lists, exactly like
|
|
65
|
+
`<TableOfContents />` builds the contents.
|
|
66
|
+
|
|
67
|
+
## Cross-references
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { Ref } from '@open-document/core';
|
|
71
|
+
|
|
72
|
+
<p style={p}>The shape in <Ref to="topology" /> is what the table hides.</p>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Renders `Figure 3`, and appends the page — `Figure 3 (p. 12)` — only when the
|
|
76
|
+
target sits on another sheet. Force it either way with `showPage`.
|
|
77
|
+
|
|
78
|
+
**Never write "see Figure 3 on page 12" by hand.** Both numbers move.
|
|
79
|
+
|
|
80
|
+
A reference to an id nothing declares renders `[?the-id]` on the page and is
|
|
81
|
+
reported by `open-doc check` as an error. That is deliberate: a silent blank is
|
|
82
|
+
worse than a visible hole.
|
|
83
|
+
|
|
84
|
+
## What things are called
|
|
85
|
+
|
|
86
|
+
Numbering is structural; the words around it are the document's own business.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
export const meta: DocMeta = {
|
|
90
|
+
title: '平台可靠度回顧',
|
|
91
|
+
labels: { figure: '圖', table: '表', onPage: '(第 {page} 頁)' },
|
|
92
|
+
};
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`footnotes` adds a heading above a page's notes; leave it empty for none.
|
|
96
|
+
|
|
97
|
+
## Data
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { DataTable } from '@open-document/core';
|
|
101
|
+
import services from './data/services.csv';
|
|
102
|
+
|
|
103
|
+
<DataTable
|
|
104
|
+
id="service-table"
|
|
105
|
+
caption="Platform tier, Q3 2026"
|
|
106
|
+
rows={services}
|
|
107
|
+
columns={[
|
|
108
|
+
{ key: 'service', label: 'Service' },
|
|
109
|
+
{ key: 'requests', label: 'Requests', format: 'integer' },
|
|
110
|
+
{ key: 'error_rate', label: 'Errors', format: 'percent' },
|
|
111
|
+
]}
|
|
112
|
+
/>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- `.csv` and `.tsv` under the document resolve to an array of objects **at build
|
|
116
|
+
time**. Quoted fields, embedded commas and newlines, and CRLF all work; a
|
|
117
|
+
numeric cell becomes a number, an empty cell becomes `null`.
|
|
118
|
+
- Data is never fetched at render time, and must not be: the packer measures the
|
|
119
|
+
real DOM to decide where pages break, so anything that arrives a tick later
|
|
120
|
+
arrives after the layout is decided.
|
|
121
|
+
- Columns default to the keys of the first row. A column whose values are all
|
|
122
|
+
numbers aligns right and gets `tabular-nums` without being told.
|
|
123
|
+
- `format`: `'integer'`, `'number'`, `'percent'`, `'text'`, or your own
|
|
124
|
+
`(value, row) => ReactNode`.
|
|
125
|
+
- `caption` numbers the table and prints the caption above it; without one you
|
|
126
|
+
get a plain table.
|
|
127
|
+
- `limit` prints the first N rows and says how many were left out — never
|
|
128
|
+
truncate a table silently.
|
|
129
|
+
|
|
130
|
+
**Retyping numbers into JSX is the thing this replaces.** If the user has the
|
|
131
|
+
data in a file, import the file.
|