@open-document/core 0.1.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-BWZJ1gvL.js → build-C3pMGxJN.js} +2 -6
- package/dist/check-Dtwb1wvU.js +42 -0
- package/dist/cli/bin.d.ts +1 -1
- package/dist/cli/bin.js +124 -13
- package/dist/{config-EBFfKtWH.d.ts → config-CSC5lHsR.d.ts} +3 -2
- package/dist/config-Dg1AMP0r.js +2461 -0
- package/dist/context-FoX0afRf.js +26 -0
- package/dist/{dev-CZtw1oqs.js → dev-Cdd7NZRQ.js} +2 -6
- 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 +238 -117
- package/dist/index.js +516 -57
- package/dist/ops/index.d.ts +98 -8
- package/dist/ops/index.js +3 -202
- package/dist/ops-Ci5Xw6QG.js +1270 -0
- package/dist/{preview-DUfQl7Ij.js → preview-BhbCiAKC.js} +2 -6
- package/dist/sdk-CWMsH9Ms.d.ts +123 -0
- package/dist/vite/index.d.ts +9 -4
- package/dist/vite/index.js +2 -5
- package/env.d.ts +33 -1
- package/package.json +17 -6
- package/skills/create-doc/SKILL.md +6 -2
- package/skills/current-doc/SKILL.md +120 -0
- 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/inspector/inspector.tsx +16 -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 +25 -5
- package/dist/config-DBp4mOOf.js +0 -1121
- package/dist/design-BJLvOcCO.js +0 -53
- package/dist/edit-ops-DSdUroVO.js +0 -1225
- package/dist/sync-6GTPAt2t.js +0 -86
- package/dist/sync-C6CsPmyK.js +0 -3
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./edit-ops-DSdUroVO.js";
|
|
3
|
-
import { createViteConfig } from "./config-DBp4mOOf.js";
|
|
1
|
+
import { t as createViteConfig } from "./config-Dg1AMP0r.js";
|
|
4
2
|
import { mergeConfig, preview as preview$1 } from "vite";
|
|
5
|
-
|
|
6
3
|
//#region src/cli/preview.ts
|
|
7
4
|
async function preview(opts = {}) {
|
|
8
5
|
const base = await createViteConfig({
|
|
@@ -18,6 +15,5 @@ async function preview(opts = {}) {
|
|
|
18
15
|
server.printUrls();
|
|
19
16
|
server.bindCLIShortcuts({ print: true });
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
//#endregion
|
|
23
|
-
export { preview };
|
|
19
|
+
export { preview };
|
|
@@ -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
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { OpenDocConfig } from "../config-
|
|
1
|
+
import { n as OpenDocConfig } from "../config-CSC5lHsR.js";
|
|
2
2
|
import { InlineConfig, Plugin } from "vite";
|
|
3
|
-
|
|
4
3
|
//#region src/vite/open-doc-plugin.d.ts
|
|
5
4
|
type OpenDocPluginOptions = {
|
|
6
5
|
userCwd: string;
|
|
7
6
|
config: OpenDocConfig;
|
|
8
7
|
coreVersion: string;
|
|
9
8
|
};
|
|
10
|
-
declare function openDocPlugin(opts: OpenDocPluginOptions): Plugin;
|
|
9
|
+
declare function openDocPlugin(opts: OpenDocPluginOptions): Plugin;
|
|
10
|
+
//#endregion
|
|
11
11
|
//#region src/vite/config.d.ts
|
|
12
12
|
type CreateViteConfigOptions = {
|
|
13
13
|
userCwd: string;
|
|
@@ -15,8 +15,13 @@ 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
|
-
|
|
21
26
|
//#endregion
|
|
22
27
|
export { createViteConfig, openDocPlugin };
|
package/dist/vite/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
|
|
3
|
-
import { createViteConfig } from "../config-DBp4mOOf.js";
|
|
4
|
-
|
|
5
|
-
export { createViteConfig, openDocPlugin };
|
|
1
|
+
import { A as openDocPlugin, t as createViteConfig } from "../config-Dg1AMP0r.js";
|
|
2
|
+
export { createViteConfig, openDocPlugin };
|
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": {
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@babel/parser": "^
|
|
63
|
+
"@babel/parser": "^8.0.4",
|
|
64
64
|
"@tailwindcss/vite": "^4.3.3",
|
|
65
|
-
"@vitejs/plugin-react": "^
|
|
65
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
66
66
|
"chalk": "^6.0.0",
|
|
67
67
|
"clsx": "^2.1.1",
|
|
68
68
|
"commander": "^15.0.0",
|
|
@@ -75,17 +75,28 @@
|
|
|
75
75
|
"react-router-dom": "^7.18.1",
|
|
76
76
|
"tailwind-merge": "^3.5.0",
|
|
77
77
|
"tailwindcss": "^4.2.2",
|
|
78
|
-
"vite": "^
|
|
78
|
+
"vite": "^8.2.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
+
"@playwright/test": "~1.56.1",
|
|
81
82
|
"@types/node": "^22.19.17",
|
|
82
83
|
"@types/react": "^18.3.12",
|
|
83
84
|
"@types/react-dom": "^18.3.1",
|
|
84
|
-
"
|
|
85
|
+
"playwright": "~1.56.1",
|
|
86
|
+
"tsdown": "^0.22.14",
|
|
85
87
|
"typescript": "^5.9.3"
|
|
86
88
|
},
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"playwright": "*"
|
|
91
|
+
},
|
|
92
|
+
"peerDependenciesMeta": {
|
|
93
|
+
"playwright": {
|
|
94
|
+
"optional": true
|
|
95
|
+
}
|
|
96
|
+
},
|
|
87
97
|
"scripts": {
|
|
88
98
|
"build": "tsdown",
|
|
89
|
-
"typecheck": "tsc --noEmit"
|
|
99
|
+
"typecheck": "tsc --noEmit",
|
|
100
|
+
"test:e2e": "pnpm run build && playwright test"
|
|
90
101
|
}
|
|
91
102
|
}
|
|
@@ -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.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: current-doc
|
|
3
|
+
description: Resolve which document, page, and (optionally) selected element the user is currently viewing in the open-doc dev server. Consult this whenever the user references "this page", "this document", "this element", "the page I'm on", "the report I'm looking at", or any deictic reference to document content without naming it. Re-read `node_modules/.open-doc/current.json` at the start of every such turn — the user navigates between turns, so a value you read earlier in the conversation is almost certainly stale.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Where is the user right now?
|
|
7
|
+
|
|
8
|
+
When the user says "fix this page", "tighten this heading", or "the report I'm looking at", they almost never name the document id, page number, or element — they mean wherever they are in the dev viewer. Before asking "which document?" or "which element?", check the file the dev server writes on every navigation and inspector pick.
|
|
9
|
+
|
|
10
|
+
## Re-read on every deictic turn — never reuse a prior read
|
|
11
|
+
|
|
12
|
+
`current.json` is a live cursor, not a fact about the conversation. The user moves between documents, pages, and elements freely between your turns — including while you were doing other work. **Read the file fresh at the start of every new turn that uses a deictic reference**, even if:
|
|
13
|
+
|
|
14
|
+
- you already read it earlier in this same conversation,
|
|
15
|
+
- you just finished editing the document it pointed to,
|
|
16
|
+
- the user's new message sounds like a continuation ("now make it bigger", "also fix this one", "keep going").
|
|
17
|
+
|
|
18
|
+
A "continue editing" follow-up is exactly the case where the user has likely just scrolled to a different page or picked a different element. Trusting your last read here will silently edit the wrong sheet. Re-read, compare `docId` / `pageIndex` / `selection` against what you used last time, and act on the new values.
|
|
19
|
+
|
|
20
|
+
## How to read it
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
node_modules/.open-doc/current.json
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Path is relative to the project root (the user's `cwd`, the directory that contains `docs/` and `package.json`). Use the `Read` tool. The file is JSON.
|
|
27
|
+
|
|
28
|
+
## What you get
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"docId": "q3-review",
|
|
33
|
+
"pageIndex": 2,
|
|
34
|
+
"pageNumber": 3,
|
|
35
|
+
"totalPages": 8,
|
|
36
|
+
"docTitle": "Q3 Review",
|
|
37
|
+
"pagePath": "docs/q3-review/index.tsx",
|
|
38
|
+
"selection": {
|
|
39
|
+
"line": 42,
|
|
40
|
+
"column": 6,
|
|
41
|
+
"tagName": "h2",
|
|
42
|
+
"text": "Availability"
|
|
43
|
+
},
|
|
44
|
+
"updatedAt": "2026-08-17T14:32:11.123Z"
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- `docId` — folder name under `docs/`. Use as-is for any `/__docs/<id>/...` API or as the URL segment (`/d/<docId>`).
|
|
49
|
+
- `pageIndex` — 0-based **rendered** page index.
|
|
50
|
+
- `pageNumber` — 1-based, for talking to the user ("page 3 of 8").
|
|
51
|
+
- `totalPages` — how many sheets the document currently renders to.
|
|
52
|
+
- `pagePath` — relative path to the document source. Hand straight to `Read` / `Edit`.
|
|
53
|
+
- `selection` — `null` if nothing is selected. Otherwise, the JSX element the user picked in the inspector overlay:
|
|
54
|
+
- `line` (1-indexed) and `column` (0-indexed) point to the JSX opening tag inside `pagePath`. This is the canonical handle — match against the source line, not the rendered DOM.
|
|
55
|
+
- `tagName` is the rendered DOM tag, lowercased (`"h1"`, `"p"`, `"td"`).
|
|
56
|
+
- `text` is a trimmed snippet (≤120 chars) of the element's `textContent`, useful to confirm you are looking at the right node.
|
|
57
|
+
- Selection auto-clears whenever the user moves to a different document or page.
|
|
58
|
+
- `updatedAt` — ISO timestamp of the last navigation or selection change. Use it to detect staleness.
|
|
59
|
+
|
|
60
|
+
## Rendered pages are not entries in the default export
|
|
61
|
+
|
|
62
|
+
This is the one thing that differs from a slide deck, and getting it wrong means editing the wrong thing.
|
|
63
|
+
|
|
64
|
+
`export default [Cover, Contents, flow(<>…</>)]` has three *entries*, but may render to twelve *sheets* — the framework measures a `flow()` section and packs it across as many pages as it needs. So:
|
|
65
|
+
|
|
66
|
+
- **`pageIndex` indexes rendered sheets, not the array.** Do not use it to subscript the default export.
|
|
67
|
+
- To find what to edit, prefer `selection` (it points at real source coordinates), then the page's visible text, then the surrounding heading.
|
|
68
|
+
- If the user is on a flow page and there is no selection, identify the content by what they can see — read the source and match the prose — rather than counting array entries.
|
|
69
|
+
- A fixed `DocPage` component *is* one sheet, so for documents made only of fixed pages the index does line up. Confirm with `pagePath` before relying on that.
|
|
70
|
+
|
|
71
|
+
## When to use this
|
|
72
|
+
|
|
73
|
+
- The user references the current document/page deictically: "this", "here", "the page I'm on", "what I'm looking at".
|
|
74
|
+
- The user references a specific element: "this heading", "this table", "tighten this", "make this smaller". If `selection` is non-null, that's the element they mean.
|
|
75
|
+
- Before asking "which document?" or "which page?" as a clarifying question — check this file first.
|
|
76
|
+
- Before guessing from `git log`, recently-edited files, or the newest folder under `docs/`.
|
|
77
|
+
|
|
78
|
+
## When NOT to use this
|
|
79
|
+
|
|
80
|
+
- The user names a document explicitly ("edit `q3-review`") — use that name directly.
|
|
81
|
+
- The `apply-comments` workflow already finds its own targets via `@doc-comment` markers; it does not need this skill.
|
|
82
|
+
- For listing or discovering documents — read `docs/` directly.
|
|
83
|
+
|
|
84
|
+
## Staleness — verify before acting
|
|
85
|
+
|
|
86
|
+
`updatedAt` is the last time the user navigated. Treat it like a cache:
|
|
87
|
+
|
|
88
|
+
- **Fresh (under ~5 minutes old)**: trust it. Open `pagePath`, do the work.
|
|
89
|
+
- **Older than ~5 minutes**: confirm with the user before editing. The dev server may not be running; the user may have switched contexts.
|
|
90
|
+
- **Hours/days old**: ignore it. Ask which document they mean.
|
|
91
|
+
|
|
92
|
+
A *newer* `updatedAt` than the one you saw last turn is the normal signal that the user has moved — switch to the new `docId` / `pageIndex` / `selection` without asking.
|
|
93
|
+
|
|
94
|
+
## When the file is missing
|
|
95
|
+
|
|
96
|
+
- The dev server has not been opened on a document yet, or has never run. A static build never writes it.
|
|
97
|
+
- Don't create the file or guess. Ask which document they mean, or suggest they open it in the dev server first.
|
|
98
|
+
|
|
99
|
+
## Example — page-level reference
|
|
100
|
+
|
|
101
|
+
User: "tighten the spacing on this page"
|
|
102
|
+
|
|
103
|
+
1. Read `node_modules/.open-doc/current.json`.
|
|
104
|
+
2. Check `updatedAt` is recent.
|
|
105
|
+
3. Read `pagePath` (e.g. `docs/q3-review/index.tsx`).
|
|
106
|
+
4. Work out what is on `pageNumber` — by the selection, or by matching visible content, remembering that a flow section spans many sheets.
|
|
107
|
+
5. Consult the `doc-authoring` skill for the spacing and vertical-budget rules, then edit in place.
|
|
108
|
+
|
|
109
|
+
If `current.json` is missing or stale, ask: "Which document and page should I tighten? The dev server hasn't published a current page recently."
|
|
110
|
+
|
|
111
|
+
## Example — element-level reference
|
|
112
|
+
|
|
113
|
+
User: "make this bigger"
|
|
114
|
+
|
|
115
|
+
1. Read `node_modules/.open-doc/current.json`.
|
|
116
|
+
2. If `selection` is non-null, that is the element. Read `pagePath`, jump to `selection.line`, and find the JSX opening tag near that line/column. Confirm against `selection.text` and `tagName`.
|
|
117
|
+
3. Consult `doc-authoring` for the print type scale before editing — a size that looks fine on screen can print below the legibility floor.
|
|
118
|
+
4. Edit the JSX node in place.
|
|
119
|
+
|
|
120
|
+
If `selection` is null, fall back to the page-level flow above — and consider asking "which element?", since the user used a deictic but hasn't picked one in the inspector.
|
|
@@ -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.
|