@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.
Files changed (52) hide show
  1. package/dist/{build-BWZJ1gvL.js → build-C3pMGxJN.js} +2 -6
  2. package/dist/check-Dtwb1wvU.js +42 -0
  3. package/dist/cli/bin.d.ts +1 -1
  4. package/dist/cli/bin.js +124 -13
  5. package/dist/{config-EBFfKtWH.d.ts → config-CSC5lHsR.d.ts} +3 -2
  6. package/dist/config-Dg1AMP0r.js +2461 -0
  7. package/dist/context-FoX0afRf.js +26 -0
  8. package/dist/{dev-CZtw1oqs.js → dev-Cdd7NZRQ.js} +2 -6
  9. package/dist/diagram-xlVDekYk.js +763 -0
  10. package/dist/export-ClJ4T1uU.js +36 -0
  11. package/dist/import-D7Psi8WK.js +25 -0
  12. package/dist/index.d.ts +238 -117
  13. package/dist/index.js +516 -57
  14. package/dist/ops/index.d.ts +98 -8
  15. package/dist/ops/index.js +3 -202
  16. package/dist/ops-Ci5Xw6QG.js +1270 -0
  17. package/dist/{preview-DUfQl7Ij.js → preview-BhbCiAKC.js} +2 -6
  18. package/dist/sdk-CWMsH9Ms.d.ts +123 -0
  19. package/dist/vite/index.d.ts +9 -4
  20. package/dist/vite/index.js +2 -5
  21. package/env.d.ts +33 -1
  22. package/package.json +17 -6
  23. package/skills/create-doc/SKILL.md +6 -2
  24. package/skills/current-doc/SKILL.md +120 -0
  25. package/skills/doc-authoring/SKILL.md +79 -0
  26. package/skills/doc-authoring/references/long-form.md +131 -0
  27. package/src/app/components/data-table.tsx +196 -0
  28. package/src/app/components/diagram.tsx +76 -0
  29. package/src/app/components/flow-page.tsx +20 -3
  30. package/src/app/components/footnote.tsx +196 -0
  31. package/src/app/components/inspector/inspector.tsx +16 -0
  32. package/src/app/components/numbering.tsx +208 -0
  33. package/src/app/lib/agent-bridge.ts +128 -0
  34. package/src/app/lib/diagnostics.ts +282 -0
  35. package/src/app/lib/export-html.ts +35 -11
  36. package/src/app/lib/export-pdf.ts +54 -19
  37. package/src/app/lib/flow-measure.ts +100 -31
  38. package/src/app/lib/flow.test.ts +46 -0
  39. package/src/app/lib/flow.ts +28 -3
  40. package/src/app/lib/footnotes.test.tsx +102 -0
  41. package/src/app/lib/footnotes.ts +94 -0
  42. package/src/app/lib/labels.ts +175 -0
  43. package/src/app/lib/page-context.tsx +6 -1
  44. package/src/app/lib/scan.ts +26 -0
  45. package/src/app/lib/sdk.ts +3 -0
  46. package/src/app/lib/use-doc-pages.ts +50 -15
  47. package/src/app/routes/doc.tsx +25 -5
  48. package/dist/config-DBp4mOOf.js +0 -1121
  49. package/dist/design-BJLvOcCO.js +0 -53
  50. package/dist/edit-ops-DSdUroVO.js +0 -1225
  51. package/dist/sync-6GTPAt2t.js +0 -86
  52. package/dist/sync-C6CsPmyK.js +0 -3
@@ -1,6 +1,5 @@
1
+ import "../sdk-CWMsH9Ms.js";
1
2
  import "vite";
2
- import "node:http";
3
-
4
3
  //#region src/vite/routes/context.d.ts
5
4
  type ApiContext = {
6
5
  userCwd: string;
@@ -10,14 +9,21 @@ type ApiContext = {
10
9
  /** `docs/.folders.json` — the folder manifest, versioned alongside the docs. */
11
10
  manifestPath: string;
12
11
  coreVersion: string;
12
+ /**
13
+ * Origin of a dev server already serving this workspace. Headless rendering
14
+ * reuses it instead of booting a second one; absent, it boots its own.
15
+ */
16
+ serverOrigin?: string;
13
17
  };
14
18
  type ApiPluginOptions = {
15
19
  userCwd: string;
16
20
  docsDir?: string;
17
21
  assetsDir?: string;
18
22
  coreVersion: string;
23
+ serverOrigin?: string;
19
24
  };
20
- declare function makeContext(opts: ApiPluginOptions): ApiContext; //#endregion
25
+ declare function makeContext(opts: ApiPluginOptions): ApiContext;
26
+ //#endregion
21
27
  //#region src/ops/documents.d.ts
22
28
  /**
23
29
  * Operations shared by the dev API and the MCP server. Everything here takes an
@@ -67,7 +73,94 @@ declare function duplicateDocument(ctx: ApiContext, docId: string, newId?: strin
67
73
  id: string;
68
74
  }>;
69
75
  declare function deleteDocument(ctx: ApiContext, docId: string): Promise<void>;
70
-
76
+ //#endregion
77
+ //#region src/ops/import.d.ts
78
+ type ImportMarkdownOptions = {
79
+ /** Markdown text. One of `markdown` or `file` is required. */
80
+ markdown?: string;
81
+ /** Path to a `.md` file, relative to the workspace root. */
82
+ file?: string;
83
+ docId?: string;
84
+ title?: string;
85
+ subtitle?: string;
86
+ author?: string;
87
+ theme?: string;
88
+ pageSize?: string;
89
+ orientation?: string;
90
+ /** Open with a title page. Defaults to true. */
91
+ cover?: boolean;
92
+ /** Insert a self-filling contents page. Defaults to false. */
93
+ contents?: boolean;
94
+ };
95
+ type ImportResult = {
96
+ id: string;
97
+ entry: string;
98
+ title: string;
99
+ blocks: number;
100
+ /** Local images copied into `docs/<id>/assets/`. */
101
+ assets: string[];
102
+ /** Image references that could not be resolved and were left as written. */
103
+ missingAssets: string[];
104
+ };
105
+ declare function slugify(value: string, fallback?: string): string;
106
+ /**
107
+ * Reads markdown and writes a real open-doc document: `flow()` body, inline
108
+ * styles, a cover, and any local images copied into the document's own assets
109
+ * folder. Nothing about the result is special-cased — it is the same shape an
110
+ * agent would have written by hand, and every editing surface works on it.
111
+ */
112
+ declare function importMarkdown(ctx: ApiContext, opts: ImportMarkdownOptions): Promise<ImportResult>;
113
+ //#endregion
114
+ //#region src/app/lib/diagnostics.d.ts
115
+ type LayoutRule = 'unresolved-ref' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
116
+ type LayoutSeverity = 'error' | 'warn';
117
+ type LayoutFinding = {
118
+ /** 1-based sheet the problem is on. */
119
+ page: number;
120
+ rule: LayoutRule;
121
+ severity: LayoutSeverity;
122
+ message: string;
123
+ /** Tag plus a text snippet, so the caller can recognise the element. */
124
+ element?: string;
125
+ /** `line:column` in the document source, from the inspector's `data-od-loc`. */
126
+ loc?: string;
127
+ };
128
+ //#endregion
129
+ //#region src/ops/layout.d.ts
130
+ type LayoutReport = {
131
+ docId: string;
132
+ title: string;
133
+ pageCount: number;
134
+ errors: number;
135
+ warnings: number;
136
+ findings: LayoutFinding[];
137
+ };
138
+ type ExportFormat = 'pdf' | 'html' | 'png';
139
+ type ExportResult = {
140
+ docId: string;
141
+ format: ExportFormat;
142
+ pageCount: number;
143
+ /** Written paths, relative to the workspace root. */
144
+ files: string[];
145
+ };
146
+ /** Closes the warm browser. Call before the process exits so nothing lingers. */
147
+ declare function closeRenderSession(): Promise<void>;
148
+ /**
149
+ * Renders the document headlessly at true page size and reports what is wrong
150
+ * with the layout — the part of a document an agent writing React cannot see.
151
+ */
152
+ declare function checkLayout(ctx: ApiContext, docId: string): Promise<LayoutReport>;
153
+ declare function renderDocPage(ctx: ApiContext, docId: string, page: number): Promise<{
154
+ docId: string;
155
+ page: number;
156
+ pageCount: number;
157
+ mimeType: string;
158
+ base64: string;
159
+ }>;
160
+ declare function exportDocument(ctx: ApiContext, docId: string, opts?: {
161
+ format?: ExportFormat;
162
+ outDir?: string;
163
+ }): Promise<ExportResult>;
71
164
  //#endregion
72
165
  //#region src/files/folders.d.ts
73
166
  type FolderIcon = {
@@ -82,7 +175,6 @@ type Folder = {
82
175
  name: string;
83
176
  icon: FolderIcon;
84
177
  };
85
-
86
178
  //#endregion
87
179
  //#region src/ops/library.d.ts
88
180
  /** Themes, assets, and folders — the material a document is written against. */
@@ -127,7 +219,6 @@ declare function listFolders(ctx: ApiContext): Promise<{
127
219
  declare function createFolder(ctx: ApiContext, rawName: unknown, rawIcon?: unknown): Promise<Folder>;
128
220
  /** Filing only edits assignments — a document id never moves on disk. */
129
221
  declare function fileDocument(ctx: ApiContext, docId: string, folderId: string | null): Promise<void>;
130
-
131
222
  //#endregion
132
223
  //#region src/ops/text.d.ts
133
224
  type Loc = {
@@ -155,6 +246,5 @@ declare function writeText(ctx: ApiContext, docId: string, loc: Loc, text: strin
155
246
  declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: string, hint?: string): Promise<{
156
247
  id: string;
157
248
  }>;
158
-
159
249
  //#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 };
250
+ export { type ApiContext, type AssetSummary, type DocumentSummary, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, OpsError, type ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText };
package/dist/ops/index.js CHANGED
@@ -1,202 +1,3 @@
1
- import { OpsError, assetImportPath, countAssetUsages, createDocument, deleteDocument, docDir, duplicateDocument, insertMarker, listDocIds, listDocuments, makeContext, newFolderId, parseFrontmatter, readDocument, readManifest, renameDocument, replaceTextAt, resolveEntry, resolveScopedAssetFile, resolveScopedAssetsDir, resolveTextTarget, validateAssetName, validateIcon, validateName, writeDocument, writeManifest } from "../edit-ops-DSdUroVO.js";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import { existsSync } from "node:fs";
5
- import fg from "fast-glob";
6
-
7
- //#region src/ops/library.ts
8
- function themesRoot(ctx, themesDir = "themes") {
9
- return path.resolve(ctx.userCwd, themesDir);
10
- }
11
- async function themeFiles(root) {
12
- if (!existsSync(root)) return [];
13
- return (await fg("*.md", {
14
- cwd: root,
15
- absolute: true,
16
- onlyFiles: true
17
- })).sort();
18
- }
19
- function demoFor(root, id) {
20
- for (const cand of [
21
- `${id}.demo.tsx`,
22
- `${id}.demo.jsx`,
23
- `${id}.demo.ts`,
24
- `${id}.demo.js`
25
- ]) {
26
- const p = path.join(root, cand);
27
- if (existsSync(p)) return p;
28
- }
29
- return null;
30
- }
31
- async function listThemes(ctx, themesDir) {
32
- const root = themesRoot(ctx, themesDir);
33
- const out = [];
34
- for (const file of await themeFiles(root)) {
35
- const id = path.basename(file, ".md");
36
- const { fm } = parseFrontmatter(await fs.readFile(file, "utf8"), id);
37
- out.push({
38
- id,
39
- name: fm.name,
40
- description: fm.description,
41
- pageSize: fm.pageSize,
42
- mode: fm.mode,
43
- hasDemo: demoFor(root, id) !== null
44
- });
45
- }
46
- return out;
47
- }
48
- /**
49
- * The full theme document. This is what an agent reads before writing a doc —
50
- * the palette, type scale, and paste-ready components live in the body.
51
- */
52
- async function readTheme(ctx, themeId, themesDir) {
53
- const root = themesRoot(ctx, themesDir);
54
- const file = path.join(root, `${themeId}.md`);
55
- if (!file.startsWith(root + path.sep) || !existsSync(file)) throw new OpsError(404, `theme not found: ${themeId}`);
56
- const { fm, body } = parseFrontmatter(await fs.readFile(file, "utf8"), themeId);
57
- const demoAbs = demoFor(root, themeId);
58
- return {
59
- id: themeId,
60
- frontmatter: fm,
61
- body,
62
- demo: demoAbs ? await fs.readFile(demoAbs, "utf8") : void 0
63
- };
64
- }
65
- /** `scope` is a document id, or `global` for the shared assets directory. */
66
- async function listAssets(ctx, scope) {
67
- const dir = resolveScopedAssetsDir(ctx.docsRoot, ctx.globalAssetsRoot, scope);
68
- if (!dir) throw new OpsError(400, `invalid scope: ${scope}`);
69
- if (!existsSync(dir)) return [];
70
- const names = await fs.readdir(dir);
71
- const out = [];
72
- for (const filename of names.sort()) {
73
- const stat = await fs.stat(path.join(dir, filename)).catch(() => null);
74
- if (!stat?.isFile()) continue;
75
- out.push({
76
- scope,
77
- filename,
78
- bytes: stat.size,
79
- importPath: assetImportPath(scope, filename)
80
- });
81
- }
82
- return out;
83
- }
84
- async function writeAsset(ctx, scope, filename, data) {
85
- const name = validateAssetName(filename);
86
- if (!name) throw new OpsError(400, "invalid filename");
87
- const dir = resolveScopedAssetsDir(ctx.docsRoot, ctx.globalAssetsRoot, scope);
88
- if (!dir) throw new OpsError(400, `invalid scope: ${scope}`);
89
- await fs.mkdir(dir, { recursive: true });
90
- const file = resolveScopedAssetFile(ctx.docsRoot, ctx.globalAssetsRoot, scope, name);
91
- if (!file) throw new OpsError(400, "invalid filename");
92
- await fs.writeFile(file, data);
93
- return {
94
- scope,
95
- filename: name,
96
- bytes: data.byteLength,
97
- importPath: assetImportPath(scope, name)
98
- };
99
- }
100
- async function deleteAsset(ctx, scope, filename) {
101
- const file = resolveScopedAssetFile(ctx.docsRoot, ctx.globalAssetsRoot, scope, filename);
102
- if (!file) throw new OpsError(400, "invalid filename");
103
- if (!existsSync(file)) throw new OpsError(404, `asset not found: ${scope}/${filename}`);
104
- await fs.rm(file);
105
- }
106
- /** Which documents import this asset — check before deleting one. */
107
- async function findAssetUsages(ctx, scope, filename) {
108
- const importPath = assetImportPath(scope, filename);
109
- const out = [];
110
- for (const id of await listDocIds(ctx)) {
111
- const entry = resolveEntry(ctx, id);
112
- if (!entry) continue;
113
- const count = countAssetUsages(await fs.readFile(entry, "utf8"), importPath);
114
- if (count > 0) out.push({
115
- docId: id,
116
- count
117
- });
118
- }
119
- return out;
120
- }
121
- async function listFolders(ctx) {
122
- const manifest = await readManifest(ctx.manifestPath);
123
- return {
124
- folders: manifest.folders,
125
- assignments: manifest.assignments
126
- };
127
- }
128
- /** Folders always carry an icon; agents rarely care, so this is the fallback. */
129
- const DEFAULT_FOLDER_ICON = {
130
- type: "color",
131
- value: "#6b7280"
132
- };
133
- async function createFolder(ctx, rawName, rawIcon) {
134
- const name = validateName(rawName);
135
- if (!name) throw new OpsError(400, "invalid folder name");
136
- const icon = validateIcon(rawIcon ?? DEFAULT_FOLDER_ICON);
137
- if (!icon) throw new OpsError(400, "invalid icon");
138
- const manifest = await readManifest(ctx.manifestPath);
139
- const folder = {
140
- id: newFolderId(),
141
- name,
142
- icon
143
- };
144
- manifest.folders.push(folder);
145
- await writeManifest(ctx.manifestPath, manifest);
146
- return folder;
147
- }
148
- /** Filing only edits assignments — a document id never moves on disk. */
149
- async function fileDocument(ctx, docId, folderId) {
150
- const manifest = await readManifest(ctx.manifestPath);
151
- if (folderId !== null && !manifest.folders.some((f) => f.id === folderId)) throw new OpsError(404, `folder not found: ${folderId}`);
152
- if (folderId === null) delete manifest.assignments[docId];
153
- else manifest.assignments[docId] = folderId;
154
- await writeManifest(ctx.manifestPath, manifest);
155
- }
156
-
157
- //#endregion
158
- //#region src/ops/text.ts
159
- async function sourceOf(ctx, docId) {
160
- const entry = resolveEntry(ctx, docId);
161
- if (!entry) throw new OpsError(404, `document not found: ${docId}`);
162
- return {
163
- entry,
164
- source: await fs.readFile(entry, "utf8")
165
- };
166
- }
167
- /**
168
- * Resolves a `line:column` (or several candidates) to the editable text runs at
169
- * that spot. `shown` is the rendered text — when a clicked element belongs to a
170
- * local helper component, it is what decides which candidate was really meant.
171
- */
172
- async function readText(ctx, docId, locs, shown) {
173
- if (locs.length === 0) throw new OpsError(400, "at least one loc is required");
174
- const { source } = await sourceOf(ctx, docId);
175
- const resolved = resolveTextTarget(source, locs, shown);
176
- if (!resolved) throw new OpsError(404, "no editable text at that location");
177
- return resolved;
178
- }
179
- /**
180
- * `expected` is the text the caller believes is there; when it no longer
181
- * matches the write is refused rather than silently overwriting someone else's
182
- * edit. `index` picks a run when the element mixes text and markup.
183
- */
184
- async function writeText(ctx, docId, loc, text, opts = {}) {
185
- const { entry, source } = await sourceOf(ctx, docId);
186
- const result = replaceTextAt(source, loc, text, opts);
187
- if (!result.ok) throw new OpsError(result.status, result.error);
188
- if (result.source !== source) await fs.writeFile(entry, result.source, "utf8");
189
- return { ok: true };
190
- }
191
- /** Leaves a `@doc-comment` marker in the source for a later agent pass to act on. */
192
- async function addComment(ctx, docId, loc, note, hint) {
193
- if (note.trim() === "") throw new OpsError(400, "note is empty");
194
- const { entry, source } = await sourceOf(ctx, docId);
195
- const inserted = insertMarker(source, loc, note.trim(), hint);
196
- if (!inserted) throw new OpsError(422, "cannot anchor a comment here — pick the surrounding element");
197
- await fs.writeFile(entry, inserted.source, "utf8");
198
- return { id: inserted.id };
199
- }
200
-
201
- //#endregion
202
- export { OpsError, addComment, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, fileDocument, findAssetUsages, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, resolveEntry, writeAsset, writeDocument, writeText };
1
+ import { D as makeContext, _ as listDocuments, b as resolveEntry, d as OpsError, f as createDocument, g as listDocIds, h as duplicateDocument, m as docDir, p as deleteDocument, v as readDocument, x as writeDocument, y as renameDocument } from "../config-Dg1AMP0r.js";
2
+ import { _ as importMarkdown, a as deleteAsset, c as listAssets, d as readTheme, f as writeAsset, g as renderDocPage, h as exportDocument, i as createFolder, l as listFolders, m as closeRenderSession, n as readText, o as fileDocument, p as checkLayout, r as writeText, s as findAssetUsages, t as addComment, u as listThemes, v as slugify } from "../ops-Ci5Xw6QG.js";
3
+ export { OpsError, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText };