@open-document/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/README.zh-TW.md +50 -0
  4. package/bin.js +2 -0
  5. package/dist/build-BWZJ1gvL.js +18 -0
  6. package/dist/cli/bin.d.ts +1 -0
  7. package/dist/cli/bin.js +86 -0
  8. package/dist/config-DBp4mOOf.js +1121 -0
  9. package/dist/config-EBFfKtWH.d.ts +17 -0
  10. package/dist/design-BJLvOcCO.js +53 -0
  11. package/dist/dev-CZtw1oqs.js +24 -0
  12. package/dist/edit-ops-DSdUroVO.js +1225 -0
  13. package/dist/index.d.ts +206 -0
  14. package/dist/index.js +240 -0
  15. package/dist/ops/index.d.ts +160 -0
  16. package/dist/ops/index.js +202 -0
  17. package/dist/preview-DUfQl7Ij.js +23 -0
  18. package/dist/sync-6GTPAt2t.js +86 -0
  19. package/dist/sync-C6CsPmyK.js +3 -0
  20. package/dist/vite/index.d.ts +22 -0
  21. package/dist/vite/index.js +5 -0
  22. package/env.d.ts +51 -0
  23. package/package.json +91 -0
  24. package/skills/apply-comments/SKILL.md +74 -0
  25. package/skills/create-doc/SKILL.md +102 -0
  26. package/skills/create-theme/SKILL.md +184 -0
  27. package/skills/doc-authoring/SKILL.md +354 -0
  28. package/skills/doc-authoring/references/assets.md +47 -0
  29. package/skills/doc-authoring/references/design-system.md +81 -0
  30. package/skills/doc-authoring/references/pagination.md +117 -0
  31. package/skills/doc-authoring/references/tables-and-charts.md +161 -0
  32. package/src/app/app.tsx +42 -0
  33. package/src/app/components/design-panel/design-panel.tsx +318 -0
  34. package/src/app/components/design-panel/design-provider.tsx +121 -0
  35. package/src/app/components/design-panel/use-design.ts +85 -0
  36. package/src/app/components/doc-assets.tsx +129 -0
  37. package/src/app/components/doc-sidebar.tsx +162 -0
  38. package/src/app/components/flow-page.tsx +50 -0
  39. package/src/app/components/image-placeholder.tsx +50 -0
  40. package/src/app/components/inspector/inspector.tsx +426 -0
  41. package/src/app/components/page-frame.tsx +70 -0
  42. package/src/app/components/sidebar/folder-item.tsx +212 -0
  43. package/src/app/components/sidebar/icon-picker.tsx +99 -0
  44. package/src/app/components/sidebar/sidebar.tsx +252 -0
  45. package/src/app/components/table-of-contents.tsx +81 -0
  46. package/src/app/components/theme-toggle.tsx +50 -0
  47. package/src/app/components/themes/markdown.tsx +249 -0
  48. package/src/app/components/themes/theme-preview.tsx +74 -0
  49. package/src/app/components/ui/menu.tsx +139 -0
  50. package/src/app/index.html +12 -0
  51. package/src/app/lib/assets.ts +151 -0
  52. package/src/app/lib/design-presets.ts +109 -0
  53. package/src/app/lib/design.ts +88 -0
  54. package/src/app/lib/doc-preview.tsx +29 -0
  55. package/src/app/lib/docs.ts +26 -0
  56. package/src/app/lib/export-html.ts +309 -0
  57. package/src/app/lib/export-pdf.ts +166 -0
  58. package/src/app/lib/flow-measure.ts +109 -0
  59. package/src/app/lib/flow.test.ts +64 -0
  60. package/src/app/lib/flow.ts +111 -0
  61. package/src/app/lib/folders.ts +192 -0
  62. package/src/app/lib/inspector/fiber.ts +99 -0
  63. package/src/app/lib/outline.ts +109 -0
  64. package/src/app/lib/page-context.tsx +38 -0
  65. package/src/app/lib/print-ready.ts +69 -0
  66. package/src/app/lib/sdk.test.ts +24 -0
  67. package/src/app/lib/sdk.ts +86 -0
  68. package/src/app/lib/themes.ts +31 -0
  69. package/src/app/lib/use-doc-module.ts +53 -0
  70. package/src/app/lib/use-doc-pages.ts +99 -0
  71. package/src/app/lib/utils.ts +6 -0
  72. package/src/app/main.tsx +14 -0
  73. package/src/app/routes/assets.tsx +257 -0
  74. package/src/app/routes/doc.tsx +480 -0
  75. package/src/app/routes/home-shell.tsx +203 -0
  76. package/src/app/routes/home.tsx +269 -0
  77. package/src/app/routes/themes.tsx +121 -0
  78. package/src/app/styles.css +72 -0
  79. package/src/app/virtual.d.ts +30 -0
@@ -0,0 +1,184 @@
1
+ ---
2
+ name: create-theme
3
+ description: Use this skill when the user wants to create, draft, author, or extract a document theme in this open-doc repo — a reusable house style for reports, proposals, or memos. Triggers on phrases like "create a theme", "make a company template", "extract a theme from <doc>", "match our brand guidelines". Produces two paired files under `themes/` — `<id>.md` (palette, typography, page setup, paste-ready Title/Footer/Table components) and `<id>.demo.tsx` (a runnable two-page demo the Themes gallery previews). Do NOT use for editing real documents — only for authoring the theme bundle.
4
+ ---
5
+
6
+ # Create a document theme
7
+
8
+ A **theme bundle** under `themes/` is two paired files describing a reusable house style:
9
+
10
+ 1. `themes/<id>.md` — agent-facing documentation: palette, typography, page setup, paste-ready components. This is what `create-doc` reads when the author picks the theme.
11
+ 2. `themes/<id>.demo.tsx` — a runnable two-page mini-document (a normal document module: `export default DocPage[]`) that shows the theme in use. The Themes gallery renders it as the live preview.
12
+
13
+ Both files share the same stem so the runtime pairs them automatically.
14
+
15
+ A theme is **distinct from a document's `design` const**:
16
+
17
+ | | What it is | Who reads it |
18
+ | --- | --- | --- |
19
+ | `themes/<id>.md` | Authoring-time direction, copied into a real document | `create-doc`, you |
20
+ | `themes/<id>.demo.tsx` | A preview, not a real document (never appears in the documents list) | The Themes gallery |
21
+ | `export const design` in `docs/<id>/index.tsx` | Runtime tokens the Design panel can live-tweak and write back | The runtime |
22
+
23
+ You only write `themes/<id>.md` and `themes/<id>.demo.tsx`. Never modify real documents or config. Read the **`doc-authoring`** skill first — the page canvas, print type scale, and vertical budget it defines are what your overrides are stated against.
24
+
25
+ ## Step 1 — Identify the input source
26
+
27
+ A theme can come from any combination of:
28
+
29
+ - **Brand material** — a style guide PDF, brand colors, a letterhead, existing reports (paths or URLs).
30
+ - **Free-text description** — prose describing palette, fonts, and feel.
31
+ - **An existing document** — `docs/<id>/index.tsx` whose look should be lifted into a reusable theme.
32
+
33
+ If the user's message already names the inputs, proceed. Otherwise call `AskUserQuestion` (multi-select) and ask follow-ups (paths, doc id, prose) only as needed.
34
+
35
+ ## Step 2 — Gather raw inputs
36
+
37
+ - **Images / PDFs**: read each path with `Read` (it accepts images and PDFs). Note hex colors, heading/body faces and weights, margin rhythm, rule weights, table styling, and any recurring chrome (letterhead, footer rule, page-number position).
38
+ - **Text**: extract explicit tokens (hex codes, font names, "20mm margins") and implicit tone ("conservative", "editorial", "technical"). Resolve vague language into concrete numbers before writing.
39
+ - **Existing document**: read `docs/<id>/index.tsx` and pull the `design` const, the shared `page`/`h1`/`h2` style objects, the running `Footer`, table cell components, and the callout style.
40
+
41
+ When inputs disagree (brand deck says navy, the sample report is black), ask which wins.
42
+
43
+ ## Step 3 — Pick a theme id
44
+
45
+ **kebab-case**, short, descriptive: `acme-corporate`, `editorial-serif`, `technical-brief`, `board-memo`. Check `themes/` for collisions.
46
+
47
+ ## Step 4 — Write `themes/<id>.md`
48
+
49
+ Keep this exact section order; adapt the bodies.
50
+
51
+ ````markdown
52
+ ---
53
+ name: <Human title, e.g. "Acme Corporate">
54
+ description: <one-line elevator pitch>
55
+ pageSize: <A4 | Letter>
56
+ mode: <light | dark — light for anything that prints>
57
+ ---
58
+
59
+ # <Theme name>
60
+
61
+ ## When to use
62
+
63
+ <Two sentences: which document types this fits, and which it doesn't.>
64
+
65
+ ## Palette
66
+
67
+ | Role | Value | Notes |
68
+ | ------ | --------- | --------------------------------------- |
69
+ | bg | `#ffffff` | sheet background — keep near-white |
70
+ | text | `#16181d` | body copy |
71
+ | muted | `#6b7280` | captions, footers, secondary cells |
72
+ | accent | `#1d4ed8` | section numbers, rules, chart series |
73
+ | rule | `#e5e7eb` | table borders, hairlines, dot leaders |
74
+
75
+ Extra colors outside the `DesignSystem` shape (status green/amber/red, chart series) go in a
76
+ "Supporting colors" list below the table.
77
+
78
+ ## Typography
79
+
80
+ - Heading font: `<stack>` — weight <n>.
81
+ - Body font: `<stack>` — weight 400.
82
+ - Mono font: `<stack>` — tables of code/IDs only.
83
+ - Webfont import (omit for system stacks): `<stylesheet URL>` — load per `references/design-system.md` in `doc-authoring`.
84
+ - Type scale (px at 96dpi): title <n> · h1 <n> · h2 <n> · h3 <n> · body <n> · caption <n>.
85
+
86
+ ## Page setup
87
+
88
+ - Page size: A4 portrait (794 × 1123 px).
89
+ - Margin: <n> px on all sides (<n> mm).
90
+ - Leading: <n>.
91
+ - Running footer: <what it shows, where it sits>.
92
+ - Cover: <centered / bottom-aligned, what it carries>.
93
+
94
+ ## Design const
95
+
96
+ Paste-ready — this is what a document using the theme declares:
97
+
98
+ ```tsx
99
+ export const design: DesignSystem = {
100
+ palette: { bg: '…', text: '…', muted: '…', accent: '…', rule: '…' },
101
+ fonts: { heading: '…', body: '…', mono: '…' },
102
+ typeScale: { title: 44, h1: 28, h2: 20, h3: 16, body: 14, caption: 10 },
103
+ margin: 76,
104
+ leading: 1.55,
105
+ radius: 6,
106
+ };
107
+ ```
108
+
109
+ ## Fixed components
110
+
111
+ Paste-ready. Copy verbatim into a document using this theme.
112
+
113
+ ### Page shell + headings
114
+
115
+ ```tsx
116
+ const page = { /* … */ } as const;
117
+ const h1 = { /* … */ } as const;
118
+ const h2 = { /* … */ } as const;
119
+ ```
120
+
121
+ ### Running footer
122
+
123
+ Read the page number from `useDocPageNumber()` / `useDocPageCount()` — never hardcode it.
124
+
125
+ ```tsx
126
+ const Footer = () => { /* … */ };
127
+ ```
128
+
129
+ ### Table
130
+
131
+ ```tsx
132
+ const Th = ({ children }: { children: React.ReactNode }) => /* … */;
133
+ const Td = ({ children }: { children: React.ReactNode }) => /* … */;
134
+ ```
135
+
136
+ Include a callout and a stat component when the theme calls for them.
137
+
138
+ ## Rules
139
+
140
+ - <3–6 bullets a document must follow to stay on-theme: what never appears, how sections are numbered, whether the cover carries a logo, table style, figure captions.>
141
+ ````
142
+
143
+ ## Step 5 — Write `themes/<id>.demo.tsx`
144
+
145
+ A normal document module — **two pages**: a cover and one content page that exercises the theme's headings, body copy, a table, and the running footer.
146
+
147
+ ```tsx
148
+ import { type DesignSystem, type DocPage, useDocPageCount, useDocPageNumber } from '@open-document/core';
149
+
150
+ export const design: DesignSystem = { /* the same const as in the .md */ };
151
+
152
+ const Cover: DocPage = () => ( /* … */ );
153
+ const Content: DocPage = () => ( /* … */ );
154
+
155
+ export default [Cover, Content] satisfies DocPage[];
156
+ ```
157
+
158
+ Rules for the demo:
159
+
160
+ - **No `meta` export** — the demo is not a real document and must not carry `createdAt` or a title that implies it is.
161
+ - Two pages, no more. The gallery renders the first; the theme detail page renders both.
162
+ - Use placeholder copy that shows the type scale honestly (a real heading, a real paragraph, a real 4-row table) — not lorem ipsum blocks that hide how the theme handles wrapping.
163
+ - Respect the vertical budget from `doc-authoring` → `references/pagination.md`. A demo that overflows teaches the wrong lesson.
164
+ - Keep it self-contained: no asset imports, no webfont the `.md` didn't declare.
165
+
166
+ ## Step 6 — Self-review
167
+
168
+ - [ ] Both files exist and share the same stem.
169
+ - [ ] Frontmatter has `name`, `description`, `pageSize`, `mode`.
170
+ - [ ] The `design` const in the `.md` and in the demo are identical.
171
+ - [ ] The palette background is white or near-white (see `references/design-system.md` — dark documents print badly).
172
+ - [ ] Body type ≥ 13px; caption ≥ 9px.
173
+ - [ ] The footer pulls page numbers from the hooks.
174
+ - [ ] Every "paste-ready" component actually compiles as written — no `…` left in the code blocks.
175
+ - [ ] The demo fits its pages.
176
+ - [ ] Nothing outside `themes/` was written.
177
+
178
+ ## Step 7 — Hand off
179
+
180
+ Tell the user:
181
+
182
+ - The theme id and both file paths.
183
+ - That it shows up under **Themes** in the dev UI (`http://localhost:5273/themes/<id>`).
184
+ - That new documents can adopt it by setting `meta.theme: '<id>'`, which adds the back-link chip — and that `create-doc` will now offer it as a choice.
@@ -0,0 +1,354 @@
1
+ ---
2
+ name: doc-authoring
3
+ description: Technical reference for writing or editing open-doc pages — file contract, the A4/Letter page canvas, print type scale, the vertical budget that decides where a page breaks, tables, charts, table of contents, page numbers, running headers/footers, and assets. Consult this whenever you are about to write or modify any file under `docs/<id>/`, including from inside the `create-doc` workflow, or for any ad-hoc document edit. Triggers on phrases like "edit the report", "fix this page", "add a section", "change the margins", "add a table", "page numbers", "table of contents", "how do documents work here".
4
+ ---
5
+
6
+ # Authoring open-doc pages
7
+
8
+ This skill is the **technical reference** for everything inside `docs/<id>/index.tsx`. It owns no workflow:
9
+
10
+ - `create-doc` owns "draft a new document" — it asks the scoping questions, then delegates the *how* to this skill.
11
+ - Any ad-hoc edit (fix a table, retitle a section, adjust margins) should also read this first.
12
+
13
+ ## Primitive references
14
+
15
+ Read the matching reference **before** using a primitive:
16
+
17
+ | Primitive | Read before | File |
18
+ | --- | --- | --- |
19
+ | `design` const + `var(--od-*)` tokens | writing any new document | `references/design-system.md` |
20
+ | `flow()` auto-pagination | any body content (the default) | `references/pagination.md` |
21
+ | Vertical budget (fixed pages) | laying out a cover or divider by hand | `references/pagination.md` |
22
+ | Tables, stat rows, inline charts | rendering data of any kind | `references/tables-and-charts.md` |
23
+ | Assets + `<ImagePlaceholder>` | importing images or leaving a placeholder | `references/assets.md` |
24
+
25
+ ## Themes
26
+
27
+ If `themes/<id>.md` exists at the project root and the document is meant to follow it, **the theme file overrides the defaults in this skill** — its palette, typography, page setup, and paste-ready components are authoritative. Read the theme file end-to-end before applying anything else here, and set `meta.theme: '<id>'` so the document back-links to it (chip on the document card, listing on `/themes/<id>`).
28
+
29
+ Themes are produced by the `create-theme` skill and are pure documentation: copy the `design` const and the Title / Footer / Table components straight into the document. `mode: dark` in a theme's frontmatter applies to its cover, not to body pages — anything that prints stays light.
30
+
31
+ ## Hard rules
32
+
33
+ - Put the document under `docs/<kebab-case-id>/`.
34
+ - Entry is `docs/<id>/index.tsx`. Images/fonts go under `docs/<id>/assets/`.
35
+ - Do **not** touch `package.json`, `open-doc.config.ts`, or other documents.
36
+ - Do not add dependencies. Only `react`, `@open-document/core`, and standard web APIs are available.
37
+ - A document is **one `index.tsx` plus `assets/`** — nothing else. Helper components and constants live inside `index.tsx`; no sibling `.tsx` files, no `README.md`.
38
+
39
+ ## File contract
40
+
41
+ ```tsx
42
+ // docs/<id>/index.tsx
43
+ import type { DocMeta, DocPage } from '@open-document/core';
44
+
45
+ const Cover: DocPage = () => <div>…</div>;
46
+ const Body: DocPage = () => <div>…</div>;
47
+
48
+ export const meta: DocMeta = {
49
+ title: 'Q3 Infrastructure Review',
50
+ subtitle: 'Platform team',
51
+ author: 'Platform Engineering',
52
+ pageSize: 'A4',
53
+ orientation: 'portrait',
54
+ createdAt: '2026-08-15T13:44:40.268Z',
55
+ };
56
+ export default [Cover, Body] satisfies DocPage[];
57
+ ```
58
+
59
+ - `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.
60
+ - **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.
61
+ - `meta.pageSize` is `'A4' | 'Letter' | 'A5' | 'Legal'` (default `'A4'`), `meta.orientation` is `'portrait' | 'landscape'` (default portrait). The same value drives the on-screen page, the `@page` size when printing, and the HTML export.
62
+ - `meta.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.
63
+
64
+ ## Two ways to fill pages
65
+
66
+ ```tsx
67
+ import { flow, type DocEntry } from '@open-document/core';
68
+
69
+ const Body = flow(
70
+ <>
71
+ <h1 style={h1}>1. Findings</h1>
72
+ <p style={p}>…</p>
73
+ <Table>…</Table>
74
+ </>,
75
+ { footer: Footer },
76
+ );
77
+
78
+ export default [Cover, Contents, Body] satisfies DocEntry[];
79
+ ```
80
+
81
+ Each direct child of the fragment is one atomic block. Blocks never split across pages; headings glue to what follows them; a caption marked `data-od-keep-with-previous` stays with its figure. Everything else — where the breaks land, how many pages the section becomes, the running footer on each — is the framework's job.
82
+
83
+ Fixed `DocPage` components remain the right tool for the cover, a contents page, or a divider whose layout *is* the content. Those pages are subject to the vertical budget below.
84
+
85
+ ## The page canvas
86
+
87
+ | Size | Portrait px (96dpi) | Text block at 76px margins |
88
+ | --- | --- | --- |
89
+ | A4 | 794 × 1123 | 642 × 971 |
90
+ | Letter | 816 × 1056 | 664 × 904 |
91
+ | A5 | 559 × 794 | 407 × 642 |
92
+ | Legal | 816 × 1344 | 664 × 1192 |
93
+
94
+ You design as if the viewport is literally the page in CSS pixels. The viewer only scales the whole sheet.
95
+
96
+ - Use **absolute pixel values** for `font-size`, padding, and positioning. No `rem`, no `vw`/`vh`, no `%` for type.
97
+ - Each page's root element must fill the sheet: `width: '100%'; height: '100%'`.
98
+ - Prefer inline `style={{ … }}`. Any CSS you load is global — scope classnames carefully.
99
+ - **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
+
101
+ ### Print type scale (start here)
102
+
103
+ | Element | Size | Notes |
104
+ | --- | --- | --- |
105
+ | Cover title | 40–52px | Cover page only |
106
+ | H1 / section opener | 26–32px | One per section |
107
+ | H2 / subsection | 18–22px | |
108
+ | H3 / run-in heading | 15–17px | Often bold body size |
109
+ | Body | 13–15px | 1.5–1.65 line-height |
110
+ | Caption / table cell | 10–12px | Tables can go to 11px |
111
+ | Footnote / footer | 9–10px | |
112
+
113
+ ### Margins
114
+
115
+ - Standard report: **72–96px** (19–25mm) on all four sides.
116
+ - Bound/printed double-sided: add ~24px to the inner edge.
117
+ - Running header/footer live **inside** the margin band, not in the text block.
118
+
119
+ ## Vertical budget — for fixed pages only
120
+
121
+ A `DocPage` does **not** scroll or reflow: anything past the bottom edge is silently cropped, so do the math before writing JSX. (Inside a `flow()` section the framework measures for you — this arithmetic is exactly what it removes.)
122
+
123
+ **Usable height** = `page_height − 2 × margin` (A4 @ 76px margins → **971px**).
124
+ **Text height** = `font_size × line_height × line_count`. A paragraph that wraps to 4 lines counts as 4.
125
+ **Lines per page** ≈ `971 / (14 × 1.55)` ≈ **44 lines of body copy** on A4 — that is the whole budget for one page.
126
+
127
+ `references/pagination.md` has the worked example, the character-count estimate for how many lines a paragraph will wrap to, and the rules for where to split.
128
+
129
+ ## Headings and the outline
130
+
131
+ The framework builds the document outline by scanning rendered pages for `h1`, `h2`, `h3` (or any element carrying `data-od-heading`). That outline powers the sidebar **and** `<TableOfContents />`.
132
+
133
+ - Use real `<h1>/<h2>/<h3>` elements for section titles, styled inline. Don't fake a heading with a `<div>` — it disappears from the outline and the TOC.
134
+ - Conversely, don't use heading tags for decorative text (a cover eyebrow, a stat label). Mark those `<div data-od-outline="skip">` if you must use a heading tag for styling reasons.
135
+ - **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
+ - Override the listed text with `data-od-heading="Short title"` when the visible heading is long or contains markup.
137
+
138
+ ## Table of contents
139
+
140
+ ```tsx
141
+ import { TableOfContents } from '@open-document/core';
142
+
143
+ const Contents: DocPage = () => (
144
+ <div style={page}>
145
+ <h1 style={h1}>Contents</h1>
146
+ <TableOfContents maxLevel={2} />
147
+ </div>
148
+ );
149
+ ```
150
+
151
+ Page numbers come from the scan, so they are always correct — **never hand-write a contents list**. The outline fills in after the first render pass; that is expected and it is resolved before PDF/HTML export serializes the pages.
152
+
153
+ ## Page numbers, headers, footers
154
+
155
+ ```tsx
156
+ import { useDocPageCount, useDocPageNumber } from '@open-document/core';
157
+
158
+ const Footer = () => {
159
+ const page = useDocPageNumber();
160
+ const total = useDocPageCount();
161
+ return (
162
+ <div style={{ position: 'absolute', left: 76, right: 76, bottom: 40, display: 'flex', justifyContent: 'space-between', fontSize: 10, color: 'var(--od-muted)' }}>
163
+ <span>Q3 Infrastructure Review</span>
164
+ <span style={{ fontVariantNumeric: 'tabular-nums' }}>{page} / {total}</span>
165
+ </div>
166
+ );
167
+ };
168
+ ```
169
+
170
+ - **Never hardcode** `3 / 12`. Both hooks are 1-based and return `0` outside a page.
171
+ - Define the header/footer once as a local component and drop it into every page that needs it. Cover pages normally omit it.
172
+ - Footers are absolutely positioned inside the margin band; they do not consume the text block's vertical budget — but keep at least 24px of clearance between the last line of body copy and the footer.
173
+
174
+ ## Starter template
175
+
176
+ ```tsx
177
+ import { type DesignSystem, type DocMeta, type DocPage, useDocPageCount, useDocPageNumber } from '@open-document/core';
178
+
179
+ export const design: DesignSystem = {
180
+ palette: {
181
+ bg: '#ffffff',
182
+ text: '#16181d',
183
+ muted: '#6b7280',
184
+ accent: '#1d4ed8',
185
+ rule: '#e5e7eb',
186
+ },
187
+ fonts: {
188
+ heading: '-apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif',
189
+ body: '-apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif',
190
+ mono: 'ui-monospace, "SF Mono", Menlo, monospace',
191
+ },
192
+ typeScale: { title: 44, h1: 28, h2: 20, h3: 16, body: 14, caption: 10 },
193
+ margin: 76,
194
+ leading: 1.55,
195
+ radius: 6,
196
+ };
197
+
198
+ const page = {
199
+ width: '100%',
200
+ height: '100%',
201
+ boxSizing: 'border-box' as const,
202
+ padding: 'var(--od-margin)',
203
+ background: 'var(--od-bg)',
204
+ color: 'var(--od-text)',
205
+ fontFamily: 'var(--od-font-body)',
206
+ fontSize: 'var(--od-size-body)',
207
+ lineHeight: 'var(--od-leading)',
208
+ position: 'relative' as const,
209
+ };
210
+
211
+ const h1 = {
212
+ fontFamily: 'var(--od-font-heading)',
213
+ fontSize: 'var(--od-size-h1)',
214
+ lineHeight: 1.2,
215
+ fontWeight: 650,
216
+ margin: '0 0 20px',
217
+ };
218
+
219
+ const Footer = () => {
220
+ const n = useDocPageNumber();
221
+ const total = useDocPageCount();
222
+ return (
223
+ <div
224
+ style={{
225
+ position: 'absolute',
226
+ left: 'var(--od-margin)',
227
+ right: 'var(--od-margin)',
228
+ bottom: 40,
229
+ display: 'flex',
230
+ justifyContent: 'space-between',
231
+ fontSize: 'var(--od-size-caption)',
232
+ color: 'var(--od-muted)',
233
+ }}
234
+ >
235
+ <span>Q3 Infrastructure Review</span>
236
+ <span style={{ fontVariantNumeric: 'tabular-nums' }}>
237
+ {n} / {total}
238
+ </span>
239
+ </div>
240
+ );
241
+ };
242
+
243
+ const Cover: DocPage = () => (
244
+ <div style={{ ...page, display: 'flex', flexDirection: 'column', justifyContent: 'flex-end' }}>
245
+ <p style={{ fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--od-accent)', margin: 0 }}>
246
+ Platform Engineering
247
+ </p>
248
+ <h1 style={{ ...h1, fontSize: 'var(--od-size-title)', margin: '16px 0 12px' }}>
249
+ Q3 Infrastructure Review
250
+ </h1>
251
+ <p style={{ color: 'var(--od-muted)', margin: 0 }}>August 2026</p>
252
+ </div>
253
+ );
254
+
255
+ const Section: DocPage = () => (
256
+ <div style={page}>
257
+ <h1 style={h1}>1. Summary</h1>
258
+ <p style={{ margin: '0 0 14px' }}>
259
+ One paragraph per idea. Keep the page inside its vertical budget.
260
+ </p>
261
+ <Footer />
262
+ </div>
263
+ );
264
+
265
+ export const meta: DocMeta = {
266
+ title: 'Q3 Infrastructure Review',
267
+ subtitle: 'Platform team',
268
+ pageSize: 'A4',
269
+ createdAt: '2026-08-15T13:44:40.268Z',
270
+ };
271
+ export default [Cover, Section] satisfies DocPage[];
272
+ ```
273
+
274
+ ## Editing an existing document
275
+
276
+ A finished report commonly runs 800–2000 lines. When you only need one page, **don't read the whole file** — locate it first:
277
+
278
+ ```bash
279
+ grep -n ": DocPage = " docs/<id>/index.tsx
280
+ ```
281
+
282
+ Then `Read` with `offset` + `limit` (~150 lines covers a page plus its helpers). Read the whole file only for cross-page work (renumbering sections, palette audit, reordering).
283
+
284
+ **Renumbering is a real cost.** If sections are numbered ("3.2 Findings"), inserting a page means editing every downstream heading. Prefer appending, or use unnumbered headings when the document is still churning.
285
+
286
+ ## Prose discipline
287
+
288
+ A document is not a slide deck. Long-form copy is the point — but it still has rules:
289
+
290
+ - One idea per paragraph, 2–5 sentences. A paragraph over ~8 lines should be split.
291
+ - Lead each section with its conclusion, then the evidence. Readers skim reports.
292
+ - Tables beat bullet lists for anything with two or more dimensions.
293
+ - Cite numbers with their source and date inline (`Q3 billing export, 2026-08-01`) — a report that can't be traced gets ignored.
294
+ - Don't invent data. If a number must come from the user, leave `<ImagePlaceholder>` for a chart or an explicit `TODO:` marker in the copy and tell them at hand-off.
295
+
296
+ ## Runtime behavior you get for free
297
+
298
+ - Home page lists every folder under `docs/` with a live thumbnail of page 1.
299
+ - Document view: vertical scroll of real-size pages, a left rail that switches between page thumbnails, the outline, and the document's assets, zoom (actual size / fit width / fit page), page counter, and fullscreen reading (`F`).
300
+ - Export PDF (print pipeline, correct `@page` size) and export HTML (self-contained, printable).
301
+ - Hot reload: edit `index.tsx` and the pages update live.
302
+ - **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
+ - **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
+ - **Download menu** — PDF (true page size) and self-contained HTML.
305
+ - **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
+
307
+ ### Writing for the inspector
308
+
309
+ Inspect mode edits the **literal text runs** of an element, and nothing else:
310
+
311
+ - A single run (`<p style={p}>copy</p>`) is editable in place.
312
+ - Mixed content (`<p>對外端點為 <code>/mcp</code>,另外自訂 …</p>`) is split into one field per run, with the markup shown as read-only chips. Each run is written back on its own, so the markup between them survives untouched.
313
+ - Text passed into a local helper (`<Td>FastMCP</Td>`) **is** editable: the inspector walks the React tree to the call site, which is where the words actually live. The helper's own definition stays untouched.
314
+ - Text produced by code (`{entry.text}`, a `map`, a hook) is refused — there is nothing literal to rewrite. Edit whatever feeds it.
315
+ - Every resolution is checked against the text on screen, and every write against the text the panel read. A mismatch is refused rather than guessed at, because the alternative is silently rewriting a different element.
316
+ - Comments anchor **inside** the clicked element, so self-closing elements (`<img />`, `<ImagePlaceholder />`) cannot host one; the user has to click the wrapper.
317
+
318
+ Practical consequence for authors: **put text in its own element**. `<Td>{value}</Td>` renders the same as `<Td>text</Td>` but only the latter can be edited from the page.
319
+
320
+ ### Writing for the Design panel
321
+
322
+ The panel rewrites the `design` object in place through an AST edit, so keep its initializer in the shape it can read:
323
+
324
+ - `export const design: DesignSystem = { … }` (or `const design = …`) at module level, **object literal only** — string/number literals, nested objects. No spreads, no `satisfies` on the inner object, no computed keys, no values pulled from other constants.
325
+ - Values you want tweakable live *in* the const. A hex you inline into a style is invisible to the panel.
326
+ - 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
+
328
+ ## Self-review before finishing
329
+
330
+ - [ ] `docs/<id>/index.tsx` `export default`s a non-empty `DocEntry[]`, with body content in a `flow()` section rather than hand-split pages.
331
+ - [ ] Every page's root fills `100% × 100%` and sets `boxSizing: 'border-box'` with the margin as padding.
332
+ - [ ] **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.
333
+ - [ ] No block inside a `flow()` section is taller than one page (a long table has to be split by hand — the framework never splits a block).
334
+ - [ ] Body type ≥ 13px; nothing on the page under 9px.
335
+ - [ ] Section titles are real `h1`/`h2`/`h3` elements, so the outline and TOC pick them up.
336
+ - [ ] Contents page uses `<TableOfContents />`, not a hand-written list.
337
+ - [ ] Page numbers come from `useDocPageNumber()` / `useDocPageCount()`.
338
+ - [ ] Document declares a top-level `export const design: DesignSystem` and pages consume `var(--od-*)`.
339
+ - [ ] Tables have a header row, aligned numerals (`fontVariantNumeric: 'tabular-nums'`), and fit the text block width.
340
+ - [ ] All imported assets exist on disk (`docs/<id>/assets/`, or root `assets/` via `@assets/...`).
341
+ - [ ] Every `<ImagePlaceholder>` marks a real image the user must supply — not decorative filler.
342
+ - [ ] Nothing outside `docs/<id>/` was edited.
343
+
344
+ ## Anti-patterns
345
+
346
+ - ❌ Overflowing the page. Cropped content is invisible — split instead.
347
+ - ❌ `overflow: auto` / `scroll` / `hidden` to "fit" more. The sheet doesn't scroll; you've hidden the bug.
348
+ - ❌ Shrinking body type below 13px or margins below 60px to cram content in.
349
+ - ❌ Hand-written contents lists or hardcoded page numbers — they go stale the moment a page is added.
350
+ - ❌ Fake headings (`<div>` styled like a title) — they vanish from the outline.
351
+ - ❌ A slide-deck voice: 6-word bullets and 100px type. This is a document.
352
+ - ❌ Tables built from `%` widths that overflow the text block, or with more than ~7 columns on portrait A4.
353
+ - ❌ Installing packages, editing `package.json` / `open-doc.config.ts` / other documents.
354
+ - ❌ Inventing data, sources, or citations.
@@ -0,0 +1,47 @@
1
+ # Assets and image placeholders
2
+
3
+ ## Where files live
4
+
5
+ | Scope | Path | Import |
6
+ | --- | --- | --- |
7
+ | One document | `docs/<id>/assets/chart.png` | `import chart from './assets/chart.png'` |
8
+ | Shared across documents | `assets/logo.svg` (project root) | `import logo from '@assets/logo.svg'` |
9
+
10
+ Both resolve to a URL string at build time. For a pure-text document, don't create an `assets/` folder at all.
11
+
12
+ ```tsx
13
+ import logo from '@assets/logo.svg';
14
+ import diagram from './assets/architecture.png';
15
+
16
+ <img src={logo} alt="Acme" style={{ height: 28 }} />
17
+ <img src={diagram} alt="Service topology" style={{ width: 642, display: 'block' }} />
18
+ ```
19
+
20
+ Rules:
21
+
22
+ - Always size images in absolute px, never `%` — a percentage resolves against the page, and the printed result stops matching the screen.
23
+ - Set `display: 'block'` on figures so the line-box descender doesn't add a stray few pixels to your vertical budget.
24
+ - Prefer SVG for logos, diagrams, and anything with type in it. A raster diagram at page width needs ≥1280px of source to survive print.
25
+ - Photos: keep them under ~1600px wide. The PDF export embeds them at full resolution, and a 6000px photo makes a 40MB PDF.
26
+ - Every image needs an `alt`. Figures need a caption below at `--od-size-caption`, muted, on the same page as the image.
27
+
28
+ ## `<ImagePlaceholder>`
29
+
30
+ When a page needs a real image **the user has to provide** — a chart from their data, a product screenshot, a signed diagram — leave a typed placeholder instead of inventing a stand-in:
31
+
32
+ ```tsx
33
+ import { ImagePlaceholder } from '@open-document/core';
34
+
35
+ <ImagePlaceholder hint="Revenue by segment, Q1–Q3 2026 — export from the finance dashboard" height={200} />
36
+ ```
37
+
38
+ - The `hint` is what the user reads when replacing it. Name the exact artifact and where it comes from — "chart here" is useless.
39
+ - Size it to the space it will occupy so the page's vertical budget stays honest after the real image lands.
40
+ - **Do not** use placeholders for decoration or stock-photo filler. If type, a table, or an inline SVG can carry the page, do that instead.
41
+ - List every placeholder for the user at hand-off — those are the blockers between the draft and a sendable document.
42
+
43
+ ## Export behavior
44
+
45
+ - **PDF**: images are embedded. The exporter waits for every `<img>` to finish loading before printing, so a slow asset delays the export rather than producing a blank frame.
46
+ - **HTML**: same-origin assets are collected and rewritten to a local `assets/` folder; the download becomes a `.zip` when the document references any. A document with no assets downloads as a single `.html`.
47
+ - Remote images (a URL on another origin) are left as-is — they render only while that host is reachable, and they may be missing from the PDF if the fetch is slow. Import files into the project instead.
@@ -0,0 +1,81 @@
1
+ # Design system
2
+
3
+ Every document declares typed design tokens at the top of `index.tsx` and consumes them through CSS variables. The framework injects the variables at the page root, so both the on-screen page and the exported PDF/HTML read the same values.
4
+
5
+ ## The shape
6
+
7
+ ```tsx
8
+ import type { DesignSystem } from '@open-document/core';
9
+
10
+ export const design: DesignSystem = {
11
+ palette: {
12
+ bg: '#ffffff', // sheet background — keep near-white for print
13
+ text: '#16181d', // body copy
14
+ muted: '#6b7280', // captions, footers, secondary cells
15
+ accent: '#1d4ed8', // section numbers, rules, links, chart series
16
+ rule: '#e5e7eb', // hairlines, table borders, dot leaders
17
+ },
18
+ fonts: {
19
+ heading: '…',
20
+ body: '…',
21
+ mono: '…',
22
+ },
23
+ typeScale: { title: 44, h1: 28, h2: 20, h3: 16, body: 14, caption: 10 },
24
+ margin: 76, // px inset from the sheet edge
25
+ leading: 1.55, // body line-height multiplier
26
+ radius: 6,
27
+ };
28
+ ```
29
+
30
+ ## Tokens available in CSS
31
+
32
+ | Token | From |
33
+ | --- | --- |
34
+ | `var(--od-bg)` `--od-text` `--od-muted` `--od-accent` `--od-rule` | `palette` |
35
+ | `var(--od-font-heading)` `--od-font-body` `--od-font-mono` | `fonts` |
36
+ | `var(--od-size-title)` `--od-size-h1` `--od-size-h2` `--od-size-h3` `--od-size-body` `--od-size-caption` | `typeScale` |
37
+ | `var(--od-margin)` `--od-leading` `--od-radius` | top-level |
38
+
39
+ Read the tokens through `var(--od-*)` in inline styles. Read `design.typeScale.body` directly only when you need a **number** for arithmetic (e.g. computing a fixed row height).
40
+
41
+ ## Print-specific palette rules
42
+
43
+ - **Background must be white or near-white.** A dark report burns toner, and most print pipelines drop background colors by default — a dark-mode document silently prints as white-on-white. If the user insists on a dark cover, make the cover page dark and keep body pages light.
44
+ - **Body text at least `#333`-dark.** Grey body copy (#666) that looks refined on screen prints washed out.
45
+ - **One accent.** Section numbers, rules, chart series, links. Two accents means a color system nobody asked for.
46
+ - `rule` should be barely visible — `#e5e7eb` on white. Heavy table borders make a report look like a spreadsheet.
47
+ - Anything conveying meaning by color (status cells, chart series) needs a second cue — a label, a shape, a weight — because the report will be printed in mono somewhere.
48
+
49
+ ## Colors outside the shape
50
+
51
+ Extra colors (status green/amber/red, chart series beyond the accent) stay as plain module constants:
52
+
53
+ ```tsx
54
+ const positive = '#15803d';
55
+ const warning = '#b45309';
56
+ const negative = '#b91c1c';
57
+ ```
58
+
59
+ Keep them next to the `design` const so a future edit finds the whole palette in one place.
60
+
61
+ ## Fonts
62
+
63
+ The default is a system stack — prefer it. A webfont is warranted for a brand face, or for CJK/Thai/Arabic where system coverage differs across machines.
64
+
65
+ Load it **at module level**, once per document:
66
+
67
+ ```tsx
68
+ const FONT_CSS = 'https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;700&display=swap';
69
+
70
+ if (typeof document !== 'undefined' && !document.getElementById('od-font-noto-serif-tc')) {
71
+ const link = document.createElement('link');
72
+ link.id = 'od-font-noto-serif-tc';
73
+ link.rel = 'stylesheet';
74
+ link.href = FONT_CSS;
75
+ document.head.appendChild(link);
76
+ }
77
+ ```
78
+
79
+ - Give the `<link>` a stable `id` and guard on it — every page component mounts separately, and during export all pages mount at once.
80
+ - The PDF export waits on `document.fonts.ready`, so a webfont is safe to use — but a CJK family is megabytes; subset it or accept a slow first export.
81
+ - Never rely on a font installed only on your machine. If it isn't loaded by the document, it won't be there in the export.