@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,206 @@
1
+ import { OpenDocBuildConfig, OpenDocConfig } from "./config-EBFfKtWH.js";
2
+ import * as react0 from "react";
3
+ import * as react2 from "react";
4
+ import { CSSProperties, ComponentType, ReactNode } from "react";
5
+
6
+ //#region src/app/components/image-placeholder.d.ts
7
+ type ImagePlaceholderProps = {
8
+ /** What the final image should show — the user reads this when replacing it. */
9
+ hint: string;
10
+ width?: number | string;
11
+ height?: number | string;
12
+ style?: CSSProperties;
13
+ className?: string;
14
+ };
15
+ /**
16
+ * Stands in for an image the user has to supply (a chart from their data, a
17
+ * product screenshot). Use it instead of inventing filler — never for
18
+ * decoration.
19
+ */
20
+ declare function ImagePlaceholder({
21
+ hint,
22
+ width,
23
+ height,
24
+ style,
25
+ className
26
+ }: ImagePlaceholderProps): react0.JSX.Element;
27
+
28
+ //#endregion
29
+ //#region src/app/components/table-of-contents.d.ts
30
+ type TableOfContentsProps = {
31
+ /** Deepest heading level to list. Defaults to 2 (h1 + h2). */
32
+ maxLevel?: number;
33
+ /** Show the page number column with dot leaders. Defaults to true. */
34
+ showPageNumbers?: boolean;
35
+ /** List headings that sit on the same page as the TOC itself. Defaults to false. */
36
+ includeOwnPage?: boolean;
37
+ /** Indent per heading level, in px. Defaults to 20. */
38
+ indent?: number;
39
+ style?: CSSProperties;
40
+ className?: string;
41
+ };
42
+ /**
43
+ * Renders the document's headings as a contents list. The outline is filled in
44
+ * by a DOM scan after the pages render, so this component is empty on the very
45
+ * first pass and populated on the next — including during PDF/HTML export,
46
+ * which scans before serializing.
47
+ */
48
+ declare function TableOfContents({
49
+ maxLevel,
50
+ showPageNumbers,
51
+ includeOwnPage,
52
+ indent,
53
+ style,
54
+ className
55
+ }: TableOfContentsProps): react2.JSX.Element;
56
+
57
+ //#endregion
58
+ //#region src/app/lib/design.d.ts
59
+ type DesignPalette = {
60
+ bg: string;
61
+ text: string;
62
+ muted: string;
63
+ accent: string;
64
+ rule: string;
65
+ };
66
+ type DesignFonts = {
67
+ heading: string;
68
+ body: string;
69
+ mono: string;
70
+ };
71
+ type DesignTypeScale = {
72
+ title: number;
73
+ h1: number;
74
+ h2: number;
75
+ h3: number;
76
+ body: number;
77
+ caption: number;
78
+ };
79
+ type DesignSystem = {
80
+ palette: DesignPalette;
81
+ fonts: DesignFonts;
82
+ typeScale: DesignTypeScale;
83
+ /** Page margin in CSS px — the printable text block's inset from the sheet edge. */
84
+ margin: number;
85
+ /** Body line-height multiplier. Headings tighten this themselves. */
86
+ leading: number;
87
+ radius: number;
88
+ };
89
+ declare function designToCssVars(d: DesignSystem): Record<string, string>;
90
+ declare function cssVarsToString(vars: Record<string, string>): string;
91
+ declare const defaultDesign: DesignSystem;
92
+
93
+ //#endregion
94
+ //#region src/app/lib/sdk.d.ts
95
+ type PageSizeName = 'A4' | 'Letter' | 'A5' | 'Legal';
96
+ type Orientation = 'portrait' | 'landscape';
97
+ /**
98
+ * Page dimensions in CSS pixels at 96dpi — the unit authors write in — paired
99
+ * with the physical `@page size` used when printing. Keeping both means a page
100
+ * laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
101
+ */
102
+ declare const PAGE_SIZES: Record<PageSizeName, {
103
+ width: number;
104
+ height: number;
105
+ css: string;
106
+ }>;
107
+ declare const DEFAULT_PAGE_SIZE: PageSizeName;
108
+ type PageGeometry = {
109
+ width: number;
110
+ height: number;
111
+ /** Value for the `@page { size: … }` descriptor, orientation included. */
112
+ css: string;
113
+ };
114
+ type DocPage = ComponentType;
115
+ /**
116
+ * A run of continuous content the framework paginates itself. Build one with
117
+ * `flow(...)` and put it in the page array alongside fixed pages.
118
+ */
119
+ type FlowSection = {
120
+ readonly __odFlow: true;
121
+ blocks: ReactNode[];
122
+ /** Rendered on every page the section expands into. */
123
+ footer?: ComponentType;
124
+ /** Page padding override in px; defaults to the design's `margin`. */
125
+ padding?: number;
126
+ };
127
+ /** What a document's default export may contain: fixed pages, flow sections, or both. */
128
+ type DocEntry = DocPage | FlowSection;
129
+ type DocMeta = {
130
+ title?: string;
131
+ subtitle?: string;
132
+ author?: string;
133
+ pageSize?: PageSizeName;
134
+ orientation?: Orientation;
135
+ /** Id of a theme under `themes/` this document was built from. Adds a back-link. */
136
+ theme?: string;
137
+ /** ISO 8601 timestamp. Set once at scaffold time; used to sort the doc list. */
138
+ createdAt?: string;
139
+ };
140
+ type DocModule = {
141
+ default: DocEntry[];
142
+ meta?: DocMeta;
143
+ design?: DesignSystem;
144
+ };
145
+ declare function resolvePageGeometry(meta?: DocMeta): PageGeometry;
146
+
147
+ //#endregion
148
+ //#region src/app/lib/flow.d.ts
149
+ /**
150
+ * Wraps continuous content so the framework paginates it, instead of the author
151
+ * hand-splitting sections into fixed pages. Each direct child is one atomic
152
+ * block — a heading, a paragraph, a table — that never straddles a page break.
153
+ */
154
+ declare function flow(children: ReactNode, opts?: {
155
+ footer?: ComponentType;
156
+ padding?: number;
157
+ }): FlowSection;
158
+ declare function isFlowSection(entry: DocEntry): entry is FlowSection;
159
+ type BlockMetrics = {
160
+ height: number;
161
+ /** A heading must not be the last block on a page. */
162
+ keepWithNext?: boolean;
163
+ /** A caption must not open a page without the figure it belongs to. */
164
+ keepWithPrevious?: boolean;
165
+ /** Always start a new page before this block. */
166
+ breakBefore?: boolean;
167
+ };
168
+ type PaginationResult = {
169
+ /** Block indices per page, in order. */
170
+ pages: number[][];
171
+ /** Blocks taller than one page — they stay whole and overflow. */
172
+ overflowing: number[];
173
+ };
174
+ /**
175
+ * Greedy top-to-bottom packing: fill a page until the next block would cross
176
+ * the bottom edge, then push that block — plus anything glued to it — onto the
177
+ * next page. Blocks are atomic; nothing is split mid-block.
178
+ */
179
+ declare function paginateBlocks(blocks: BlockMetrics[], available: number): PaginationResult;
180
+
181
+ //#endregion
182
+ //#region src/app/lib/outline.d.ts
183
+ /** Blocks of the first flow section, for thumbnails that skip measurement. */
184
+ type OutlineEntry = {
185
+ id: string;
186
+ text: string;
187
+ level: number;
188
+ /** 1-based page the heading sits on. */
189
+ page: number;
190
+ };
191
+ /**
192
+ * The document's headings, filled in after the pages render. Empty on the first
193
+ * pass — a `<TableOfContents>` renders its rows on the second, once the scan
194
+ * has run.
195
+ */
196
+ declare function useDocOutline(): OutlineEntry[];
197
+
198
+ //#endregion
199
+ //#region src/app/lib/page-context.d.ts
200
+ /** 1-based page number of the page currently rendering. `0` outside a page. */
201
+ declare function useDocPageNumber(): number;
202
+ /** Total page count of the document being rendered. `0` outside a page. */
203
+ declare function useDocPageCount(): number;
204
+
205
+ //#endregion
206
+ export { BlockMetrics, DEFAULT_PAGE_SIZE, DesignFonts, DesignPalette, DesignSystem, DesignTypeScale, DocEntry, DocMeta, DocModule, DocPage, FlowSection, ImagePlaceholder, ImagePlaceholderProps, OpenDocBuildConfig, OpenDocConfig, Orientation, OutlineEntry, PAGE_SIZES, PageGeometry, PageSizeName, PaginationResult, TableOfContents, TableOfContentsProps, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, resolvePageGeometry, useDocOutline, useDocPageCount, useDocPageNumber };
package/dist/index.js ADDED
@@ -0,0 +1,240 @@
1
+ import { cssVarsToString, defaultDesign, designToCssVars } from "./design-BJLvOcCO.js";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { Children, Fragment as Fragment$1, createContext, isValidElement, useContext, useSyncExternalStore } from "react";
4
+
5
+ //#region src/app/components/image-placeholder.tsx
6
+ /**
7
+ * Stands in for an image the user has to supply (a chart from their data, a
8
+ * product screenshot). Use it instead of inventing filler — never for
9
+ * decoration.
10
+ */
11
+ function ImagePlaceholder({ hint, width = "100%", height = 200, style, className }) {
12
+ return /* @__PURE__ */ jsx("div", {
13
+ "data-od-image-placeholder": "",
14
+ className,
15
+ style: {
16
+ width,
17
+ height,
18
+ display: "flex",
19
+ alignItems: "center",
20
+ justifyContent: "center",
21
+ textAlign: "center",
22
+ padding: 16,
23
+ boxSizing: "border-box",
24
+ border: "1px dashed var(--od-rule, #d4d4d8)",
25
+ borderRadius: "var(--od-radius, 6px)",
26
+ background: "repeating-linear-gradient(45deg, rgba(0,0,0,.02) 0 8px, transparent 8px 16px)",
27
+ color: "var(--od-muted, #6b7280)",
28
+ fontFamily: "var(--od-font-body, system-ui, sans-serif)",
29
+ fontSize: "var(--od-size-caption, 10px)",
30
+ lineHeight: 1.4,
31
+ ...style
32
+ },
33
+ children: hint
34
+ });
35
+ }
36
+
37
+ //#endregion
38
+ //#region src/app/lib/outline.ts
39
+ const GLOBAL_KEY$1 = "__open_doc_outline_store__";
40
+ const g$1 = globalThis;
41
+ if (!g$1[GLOBAL_KEY$1]) g$1[GLOBAL_KEY$1] = {
42
+ snapshot: [],
43
+ listeners: new Set()
44
+ };
45
+ const store = g$1[GLOBAL_KEY$1];
46
+ function getOutline() {
47
+ return store.snapshot;
48
+ }
49
+ function subscribe(listener) {
50
+ store.listeners.add(listener);
51
+ return () => store.listeners.delete(listener);
52
+ }
53
+ /**
54
+ * The document's headings, filled in after the pages render. Empty on the first
55
+ * pass — a `<TableOfContents>` renders its rows on the second, once the scan
56
+ * has run.
57
+ */
58
+ function useDocOutline() {
59
+ return useSyncExternalStore(subscribe, getOutline, getOutline);
60
+ }
61
+
62
+ //#endregion
63
+ //#region src/app/lib/page-context.tsx
64
+ const GLOBAL_KEY = "__open_doc_page_context__";
65
+ const g = globalThis;
66
+ if (!g[GLOBAL_KEY]) g[GLOBAL_KEY] = createContext(null);
67
+ const PageContext = g[GLOBAL_KEY];
68
+ /** 1-based page number of the page currently rendering. `0` outside a page. */
69
+ function useDocPageNumber() {
70
+ const ctx = useContext(PageContext);
71
+ return ctx ? ctx.index + 1 : 0;
72
+ }
73
+ /** Total page count of the document being rendered. `0` outside a page. */
74
+ function useDocPageCount() {
75
+ const ctx = useContext(PageContext);
76
+ return ctx ? ctx.total : 0;
77
+ }
78
+
79
+ //#endregion
80
+ //#region src/app/components/table-of-contents.tsx
81
+ /**
82
+ * Renders the document's headings as a contents list. The outline is filled in
83
+ * by a DOM scan after the pages render, so this component is empty on the very
84
+ * first pass and populated on the next — including during PDF/HTML export,
85
+ * which scans before serializing.
86
+ */
87
+ function TableOfContents({ maxLevel = 2, showPageNumbers = true, includeOwnPage = false, indent = 20, style, className }) {
88
+ const outline = useDocOutline();
89
+ const ownPage = useDocPageNumber();
90
+ const entries = outline.filter((entry) => entry.level <= maxLevel && (includeOwnPage || entry.page !== ownPage));
91
+ return /* @__PURE__ */ jsx("div", {
92
+ "data-od-toc": "",
93
+ className,
94
+ style: {
95
+ fontFamily: "var(--od-font-body)",
96
+ fontSize: "var(--od-size-body)",
97
+ color: "var(--od-text)",
98
+ ...style
99
+ },
100
+ children: entries.map((entry) => /* @__PURE__ */ jsxs("div", {
101
+ style: {
102
+ display: "flex",
103
+ alignItems: "baseline",
104
+ gap: 8,
105
+ paddingLeft: (entry.level - 1) * indent,
106
+ marginBottom: entry.level === 1 ? 10 : 6,
107
+ fontWeight: entry.level === 1 ? 600 : 400,
108
+ color: entry.level === 1 ? "var(--od-text)" : "var(--od-muted)"
109
+ },
110
+ children: [/* @__PURE__ */ jsx("span", { children: entry.text }), showPageNumbers && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
111
+ "aria-hidden": true,
112
+ style: {
113
+ flex: 1,
114
+ borderBottom: "1px dotted var(--od-rule)",
115
+ transform: "translateY(-3px)"
116
+ }
117
+ }), /* @__PURE__ */ jsx("span", {
118
+ style: { fontVariantNumeric: "tabular-nums" },
119
+ children: entry.page
120
+ })] })]
121
+ }, entry.id))
122
+ });
123
+ }
124
+
125
+ //#endregion
126
+ //#region src/app/lib/flow.ts
127
+ /**
128
+ * Flattens fragments so `flow(<>…</>)` yields one block per element the author
129
+ * wrote, not a single block containing the whole fragment.
130
+ */
131
+ function toBlocks(node) {
132
+ const out = [];
133
+ for (const child of Children.toArray(node)) {
134
+ if (!isValidElement(child)) continue;
135
+ if (child.type === Fragment$1) {
136
+ out.push(...toBlocks(child.props.children));
137
+ continue;
138
+ }
139
+ out.push(child);
140
+ }
141
+ return out;
142
+ }
143
+ /**
144
+ * Wraps continuous content so the framework paginates it, instead of the author
145
+ * hand-splitting sections into fixed pages. Each direct child is one atomic
146
+ * block — a heading, a paragraph, a table — that never straddles a page break.
147
+ */
148
+ function flow(children, opts = {}) {
149
+ return {
150
+ __odFlow: true,
151
+ blocks: toBlocks(children),
152
+ ...opts
153
+ };
154
+ }
155
+ function isFlowSection(entry) {
156
+ return typeof entry === "object" && entry !== null && entry.__odFlow === true;
157
+ }
158
+ /**
159
+ * Greedy top-to-bottom packing: fill a page until the next block would cross
160
+ * the bottom edge, then push that block — plus anything glued to it — onto the
161
+ * next page. Blocks are atomic; nothing is split mid-block.
162
+ */
163
+ function paginateBlocks(blocks, available) {
164
+ const pages = [];
165
+ const overflowing = [];
166
+ let current = [];
167
+ let used = 0;
168
+ const heightOf = (indices) => indices.reduce((sum, index) => sum + (blocks[index]?.height ?? 0), 0);
169
+ const closePage = () => {
170
+ if (current.length === 0) return;
171
+ pages.push(current);
172
+ current = [];
173
+ used = 0;
174
+ };
175
+ blocks.forEach((block, index) => {
176
+ if (block.height > available) overflowing.push(index);
177
+ if (block.breakBefore) closePage();
178
+ if (current.length > 0 && used + block.height > available) {
179
+ let splitAt = current.length;
180
+ while (splitAt > 0 && blocks[current[splitAt - 1]]?.keepWithNext) splitAt--;
181
+ if (block.keepWithPrevious && splitAt === current.length) splitAt--;
182
+ if (splitAt > 0 && splitAt < current.length) {
183
+ const moved = current.slice(splitAt);
184
+ pages.push(current.slice(0, splitAt));
185
+ current = moved;
186
+ used = heightOf(moved);
187
+ } else closePage();
188
+ }
189
+ current.push(index);
190
+ used += block.height;
191
+ });
192
+ closePage();
193
+ return {
194
+ pages,
195
+ overflowing
196
+ };
197
+ }
198
+
199
+ //#endregion
200
+ //#region src/app/lib/sdk.ts
201
+ /**
202
+ * Page dimensions in CSS pixels at 96dpi — the unit authors write in — paired
203
+ * with the physical `@page size` used when printing. Keeping both means a page
204
+ * laid out at 794×1123 on screen maps to a real A4 sheet with no rescaling.
205
+ */
206
+ const PAGE_SIZES = {
207
+ A4: {
208
+ width: 794,
209
+ height: 1123,
210
+ css: "210mm 297mm"
211
+ },
212
+ Letter: {
213
+ width: 816,
214
+ height: 1056,
215
+ css: "8.5in 11in"
216
+ },
217
+ A5: {
218
+ width: 559,
219
+ height: 794,
220
+ css: "148mm 210mm"
221
+ },
222
+ Legal: {
223
+ width: 816,
224
+ height: 1344,
225
+ css: "8.5in 14in"
226
+ }
227
+ };
228
+ const DEFAULT_PAGE_SIZE = "A4";
229
+ function resolvePageGeometry(meta) {
230
+ const size = PAGE_SIZES[meta?.pageSize ?? DEFAULT_PAGE_SIZE] ?? PAGE_SIZES[DEFAULT_PAGE_SIZE];
231
+ const landscape = meta?.orientation === "landscape";
232
+ return {
233
+ width: landscape ? size.height : size.width,
234
+ height: landscape ? size.width : size.height,
235
+ css: landscape ? `${size.css} landscape` : size.css
236
+ };
237
+ }
238
+
239
+ //#endregion
240
+ export { DEFAULT_PAGE_SIZE, ImagePlaceholder, PAGE_SIZES, TableOfContents, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, resolvePageGeometry, useDocOutline, useDocPageCount, useDocPageNumber };
@@ -0,0 +1,160 @@
1
+ import "vite";
2
+ import "node:http";
3
+
4
+ //#region src/vite/routes/context.d.ts
5
+ type ApiContext = {
6
+ userCwd: string;
7
+ docsDir: string;
8
+ docsRoot: string;
9
+ globalAssetsRoot: string;
10
+ /** `docs/.folders.json` — the folder manifest, versioned alongside the docs. */
11
+ manifestPath: string;
12
+ coreVersion: string;
13
+ };
14
+ type ApiPluginOptions = {
15
+ userCwd: string;
16
+ docsDir?: string;
17
+ assetsDir?: string;
18
+ coreVersion: string;
19
+ };
20
+ declare function makeContext(opts: ApiPluginOptions): ApiContext; //#endregion
21
+ //#region src/ops/documents.d.ts
22
+ /**
23
+ * Operations shared by the dev API and the MCP server. Everything here takes an
24
+ * `ApiContext` and touches disk directly — no HTTP, so an agent calling a tool
25
+ * and a browser calling `/__docs` end up in exactly the same code.
26
+ */
27
+ declare class OpsError extends Error {
28
+ readonly status: number;
29
+ constructor(status: number, message: string);
30
+ }
31
+ declare function docDir(ctx: ApiContext, docId: string): string;
32
+ declare function resolveEntry(ctx: ApiContext, docId: string): string | null;
33
+ declare function listDocIds(ctx: ApiContext): Promise<string[]>;
34
+ type DocumentSummary = {
35
+ id: string;
36
+ title: string | null;
37
+ subtitle?: string;
38
+ theme?: string;
39
+ createdAt?: string;
40
+ folder?: string;
41
+ entry: string | null;
42
+ };
43
+ declare function listDocuments(ctx: ApiContext): Promise<DocumentSummary[]>;
44
+ declare function readDocument(ctx: ApiContext, docId: string): Promise<{
45
+ id: string;
46
+ entry: string;
47
+ source: string;
48
+ }>;
49
+ declare function createDocument(ctx: ApiContext, docId: string, source: string): Promise<{
50
+ id: string;
51
+ entry: string;
52
+ }>;
53
+ /**
54
+ * Whole-file overwrite. `expected` is the source the caller believes is on
55
+ * disk; passing it turns a blind overwrite into a conflict check, which is what
56
+ * keeps two agents (or an agent and a person) from clobbering each other.
57
+ */
58
+ declare function writeDocument(ctx: ApiContext, docId: string, source: string, expected?: string): Promise<{
59
+ id: string;
60
+ entry: string;
61
+ }>;
62
+ declare function renameDocument(ctx: ApiContext, docId: string, rawTitle: unknown): Promise<{
63
+ id: string;
64
+ title: string;
65
+ }>;
66
+ declare function duplicateDocument(ctx: ApiContext, docId: string, newId?: string): Promise<{
67
+ id: string;
68
+ }>;
69
+ declare function deleteDocument(ctx: ApiContext, docId: string): Promise<void>;
70
+
71
+ //#endregion
72
+ //#region src/files/folders.d.ts
73
+ type FolderIcon = {
74
+ type: 'emoji';
75
+ value: string;
76
+ } | {
77
+ type: 'color';
78
+ value: string;
79
+ };
80
+ type Folder = {
81
+ id: string;
82
+ name: string;
83
+ icon: FolderIcon;
84
+ };
85
+
86
+ //#endregion
87
+ //#region src/ops/library.d.ts
88
+ /** Themes, assets, and folders — the material a document is written against. */
89
+ type ThemeSummary = {
90
+ id: string;
91
+ name: string;
92
+ description?: string;
93
+ pageSize?: string;
94
+ mode?: string;
95
+ hasDemo: boolean;
96
+ };
97
+ declare function listThemes(ctx: ApiContext, themesDir?: string): Promise<ThemeSummary[]>;
98
+ /**
99
+ * The full theme document. This is what an agent reads before writing a doc —
100
+ * the palette, type scale, and paste-ready components live in the body.
101
+ */
102
+ declare function readTheme(ctx: ApiContext, themeId: string, themesDir?: string): Promise<{
103
+ id: string;
104
+ frontmatter: unknown;
105
+ body: string;
106
+ demo?: string;
107
+ }>;
108
+ type AssetSummary = {
109
+ scope: string;
110
+ filename: string;
111
+ bytes: number;
112
+ importPath: string;
113
+ };
114
+ /** `scope` is a document id, or `global` for the shared assets directory. */
115
+ declare function listAssets(ctx: ApiContext, scope: string): Promise<AssetSummary[]>;
116
+ declare function writeAsset(ctx: ApiContext, scope: string, filename: unknown, data: Buffer): Promise<AssetSummary>;
117
+ declare function deleteAsset(ctx: ApiContext, scope: string, filename: string): Promise<void>;
118
+ /** Which documents import this asset — check before deleting one. */
119
+ declare function findAssetUsages(ctx: ApiContext, scope: string, filename: string): Promise<{
120
+ docId: string;
121
+ count: number;
122
+ }[]>;
123
+ declare function listFolders(ctx: ApiContext): Promise<{
124
+ folders: Folder[];
125
+ assignments: Record<string, string>;
126
+ }>;
127
+ declare function createFolder(ctx: ApiContext, rawName: unknown, rawIcon?: unknown): Promise<Folder>;
128
+ /** Filing only edits assignments — a document id never moves on disk. */
129
+ declare function fileDocument(ctx: ApiContext, docId: string, folderId: string | null): Promise<void>;
130
+
131
+ //#endregion
132
+ //#region src/ops/text.d.ts
133
+ type Loc = {
134
+ line: number;
135
+ column: number;
136
+ };
137
+ /**
138
+ * Resolves a `line:column` (or several candidates) to the editable text runs at
139
+ * that spot. `shown` is the rendered text — when a clicked element belongs to a
140
+ * local helper component, it is what decides which candidate was really meant.
141
+ */
142
+ declare function readText(ctx: ApiContext, docId: string, locs: Loc[], shown?: string): Promise<unknown>;
143
+ /**
144
+ * `expected` is the text the caller believes is there; when it no longer
145
+ * matches the write is refused rather than silently overwriting someone else's
146
+ * edit. `index` picks a run when the element mixes text and markup.
147
+ */
148
+ declare function writeText(ctx: ApiContext, docId: string, loc: Loc, text: string, opts?: {
149
+ index?: number;
150
+ expected?: string;
151
+ }): Promise<{
152
+ ok: true;
153
+ }>;
154
+ /** Leaves a `@doc-comment` marker in the source for a later agent pass to act on. */
155
+ declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: string, hint?: string): Promise<{
156
+ id: string;
157
+ }>;
158
+
159
+ //#endregion
160
+ export { ApiContext, AssetSummary, DocumentSummary, Loc, OpsError, ThemeSummary, addComment, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, fileDocument, findAssetUsages, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, resolveEntry, writeAsset, writeDocument, writeText };