@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.
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/README.zh-TW.md +50 -0
- package/bin.js +2 -0
- package/dist/build-BWZJ1gvL.js +18 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +86 -0
- package/dist/config-DBp4mOOf.js +1121 -0
- package/dist/config-EBFfKtWH.d.ts +17 -0
- package/dist/design-BJLvOcCO.js +53 -0
- package/dist/dev-CZtw1oqs.js +24 -0
- package/dist/edit-ops-DSdUroVO.js +1225 -0
- package/dist/index.d.ts +206 -0
- package/dist/index.js +240 -0
- package/dist/ops/index.d.ts +160 -0
- package/dist/ops/index.js +202 -0
- package/dist/preview-DUfQl7Ij.js +23 -0
- package/dist/sync-6GTPAt2t.js +86 -0
- package/dist/sync-C6CsPmyK.js +3 -0
- package/dist/vite/index.d.ts +22 -0
- package/dist/vite/index.js +5 -0
- package/env.d.ts +51 -0
- package/package.json +91 -0
- package/skills/apply-comments/SKILL.md +74 -0
- package/skills/create-doc/SKILL.md +102 -0
- package/skills/create-theme/SKILL.md +184 -0
- package/skills/doc-authoring/SKILL.md +354 -0
- package/skills/doc-authoring/references/assets.md +47 -0
- package/skills/doc-authoring/references/design-system.md +81 -0
- package/skills/doc-authoring/references/pagination.md +117 -0
- package/skills/doc-authoring/references/tables-and-charts.md +161 -0
- package/src/app/app.tsx +42 -0
- package/src/app/components/design-panel/design-panel.tsx +318 -0
- package/src/app/components/design-panel/design-provider.tsx +121 -0
- package/src/app/components/design-panel/use-design.ts +85 -0
- package/src/app/components/doc-assets.tsx +129 -0
- package/src/app/components/doc-sidebar.tsx +162 -0
- package/src/app/components/flow-page.tsx +50 -0
- package/src/app/components/image-placeholder.tsx +50 -0
- package/src/app/components/inspector/inspector.tsx +426 -0
- package/src/app/components/page-frame.tsx +70 -0
- package/src/app/components/sidebar/folder-item.tsx +212 -0
- package/src/app/components/sidebar/icon-picker.tsx +99 -0
- package/src/app/components/sidebar/sidebar.tsx +252 -0
- package/src/app/components/table-of-contents.tsx +81 -0
- package/src/app/components/theme-toggle.tsx +50 -0
- package/src/app/components/themes/markdown.tsx +249 -0
- package/src/app/components/themes/theme-preview.tsx +74 -0
- package/src/app/components/ui/menu.tsx +139 -0
- package/src/app/index.html +12 -0
- package/src/app/lib/assets.ts +151 -0
- package/src/app/lib/design-presets.ts +109 -0
- package/src/app/lib/design.ts +88 -0
- package/src/app/lib/doc-preview.tsx +29 -0
- package/src/app/lib/docs.ts +26 -0
- package/src/app/lib/export-html.ts +309 -0
- package/src/app/lib/export-pdf.ts +166 -0
- package/src/app/lib/flow-measure.ts +109 -0
- package/src/app/lib/flow.test.ts +64 -0
- package/src/app/lib/flow.ts +111 -0
- package/src/app/lib/folders.ts +192 -0
- package/src/app/lib/inspector/fiber.ts +99 -0
- package/src/app/lib/outline.ts +109 -0
- package/src/app/lib/page-context.tsx +38 -0
- package/src/app/lib/print-ready.ts +69 -0
- package/src/app/lib/sdk.test.ts +24 -0
- package/src/app/lib/sdk.ts +86 -0
- package/src/app/lib/themes.ts +31 -0
- package/src/app/lib/use-doc-module.ts +53 -0
- package/src/app/lib/use-doc-pages.ts +99 -0
- package/src/app/lib/utils.ts +6 -0
- package/src/app/main.tsx +14 -0
- package/src/app/routes/assets.tsx +257 -0
- package/src/app/routes/doc.tsx +480 -0
- package/src/app/routes/home-shell.tsx +203 -0
- package/src/app/routes/home.tsx +269 -0
- package/src/app/routes/themes.tsx +121 -0
- package/src/app/styles.css +72 -0
- package/src/app/virtual.d.ts +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Simon Liu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @open-document/core
|
|
2
|
+
|
|
3
|
+
**English** · [繁體中文](README.zh-TW.md)
|
|
4
|
+
|
|
5
|
+
Runtime and CLI for [open-doc](https://github.com/simonliu-ai-product/open-doc) — write documents in `docs/`, we handle the pages, the outline, and the export.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @open-document/cli init my-docs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What's in here
|
|
12
|
+
|
|
13
|
+
- **Runtime** — document browser, paged viewer with outline sidebar and zoom, PDF export (true `@page` size), self-contained HTML export.
|
|
14
|
+
- **Vite plugin** — discovers `docs/*/index.tsx`, serves them through a virtual module, hot-reloads edits.
|
|
15
|
+
- **CLI** — `open-doc dev | build | preview | sync:skills`. `dev --mcp` also mounts [`@open-document/mcp`](../mcp) at `/mcp`.
|
|
16
|
+
- **Ops layer** — `@open-document/core/ops`: document, theme, asset, and folder operations independent of transport. The dev API and the MCP server both call these, so validation and conflict checks exist once.
|
|
17
|
+
- **Skills** — `create-doc` and `doc-authoring`, synced into your workspace so your coding agent knows the rules.
|
|
18
|
+
|
|
19
|
+
## Public API
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import {
|
|
23
|
+
type DesignSystem,
|
|
24
|
+
type DocMeta,
|
|
25
|
+
type DocPage,
|
|
26
|
+
ImagePlaceholder,
|
|
27
|
+
PAGE_SIZES,
|
|
28
|
+
TableOfContents,
|
|
29
|
+
resolvePageGeometry,
|
|
30
|
+
useDocOutline,
|
|
31
|
+
useDocPageCount,
|
|
32
|
+
useDocPageNumber,
|
|
33
|
+
} from '@open-document/core';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Config
|
|
37
|
+
|
|
38
|
+
`open-doc.config.ts` at the workspace root:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import type { OpenDocConfig } from '@open-document/core';
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
docsDir: 'docs',
|
|
45
|
+
assetsDir: 'assets',
|
|
46
|
+
port: 5273,
|
|
47
|
+
} satisfies OpenDocConfig;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
MIT
|
package/README.zh-TW.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @open-document/core
|
|
2
|
+
|
|
3
|
+
[English](README.md) · **繁體中文**
|
|
4
|
+
|
|
5
|
+
[open-doc](https://github.com/simonliu-ai-product/open-doc) 的 runtime 與 CLI——文件寫在 `docs/` 裡,頁面、大綱與匯出交給我們處理。
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @open-document/cli init my-docs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 內容物
|
|
12
|
+
|
|
13
|
+
- **Runtime** — 文件瀏覽器、帶大綱側欄與縮放的分頁檢視器、PDF 匯出(真實的 `@page` 尺寸)、自足的 HTML 匯出。
|
|
14
|
+
- **Vite plugin** — 探索 `docs/*/index.tsx`,透過 virtual module 提供,並對編輯做熱更新。
|
|
15
|
+
- **CLI** — `open-doc dev | build | preview | sync:skills`。`dev --mcp` 另會把 [`@open-document/mcp`](../mcp) 掛在 `/mcp`。
|
|
16
|
+
- **Ops 層** — `@open-document/core/ops`:與傳輸無關的文件、theme、asset 與資料夾操作。Dev API 與 MCP server 都呼叫這一層,因此驗證與衝突檢查只存在一份。
|
|
17
|
+
- **Skills** — `create-doc` 與 `doc-authoring`,會同步進你的工作區,讓 coding agent 知道規則。
|
|
18
|
+
|
|
19
|
+
## 公開 API
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import {
|
|
23
|
+
type DesignSystem,
|
|
24
|
+
type DocMeta,
|
|
25
|
+
type DocPage,
|
|
26
|
+
ImagePlaceholder,
|
|
27
|
+
PAGE_SIZES,
|
|
28
|
+
TableOfContents,
|
|
29
|
+
resolvePageGeometry,
|
|
30
|
+
useDocOutline,
|
|
31
|
+
useDocPageCount,
|
|
32
|
+
useDocPageNumber,
|
|
33
|
+
} from '@open-document/core';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 設定
|
|
37
|
+
|
|
38
|
+
工作區根目錄的 `open-doc.config.ts`:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import type { OpenDocConfig } from '@open-document/core';
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
docsDir: 'docs',
|
|
45
|
+
assetsDir: 'assets',
|
|
46
|
+
port: 5273,
|
|
47
|
+
} satisfies OpenDocConfig;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
MIT
|
package/bin.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "./design-BJLvOcCO.js";
|
|
2
|
+
import "./edit-ops-DSdUroVO.js";
|
|
3
|
+
import { createViteConfig } from "./config-DBp4mOOf.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { build as build$1, mergeConfig } from "vite";
|
|
6
|
+
|
|
7
|
+
//#region src/cli/build.ts
|
|
8
|
+
async function build(opts = {}) {
|
|
9
|
+
const base = await createViteConfig({
|
|
10
|
+
userCwd: process.cwd(),
|
|
11
|
+
mode: "build"
|
|
12
|
+
});
|
|
13
|
+
const config = mergeConfig(base, { build: { ...opts.outDir !== void 0 ? { outDir: path.resolve(process.cwd(), opts.outDir) } : {} } });
|
|
14
|
+
await build$1(config);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { build };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { detectSkillsDrift, syncSkills } from "../sync-6GTPAt2t.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import * as readline from "node:readline/promises";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { Command, Option } from "commander";
|
|
9
|
+
|
|
10
|
+
//#region src/cli/run.ts
|
|
11
|
+
async function readVersion() {
|
|
12
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const pkgPath = path.resolve(here, "..", "..", "package.json");
|
|
14
|
+
const raw = await readFile(pkgPath, "utf8");
|
|
15
|
+
return JSON.parse(raw).version;
|
|
16
|
+
}
|
|
17
|
+
function parsePort(value) {
|
|
18
|
+
const n = Number(value);
|
|
19
|
+
if (!Number.isInteger(n) || n < 0 || n > 65535) throw new Error(`Invalid port: ${value}`);
|
|
20
|
+
return n;
|
|
21
|
+
}
|
|
22
|
+
function resolveBuiltinSkillsDir() {
|
|
23
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
return path.resolve(here, "..", "..", "skills");
|
|
25
|
+
}
|
|
26
|
+
async function runSkillsDriftCheck(skillsDir) {
|
|
27
|
+
if (process.env.OPEN_DOC_SKIP_SKILLS_CHECK === "1") return;
|
|
28
|
+
let drift;
|
|
29
|
+
try {
|
|
30
|
+
drift = await detectSkillsDrift(skillsDir);
|
|
31
|
+
} catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const stale = drift.filter((d) => d.status !== "unchanged");
|
|
35
|
+
if (stale.length === 0) return;
|
|
36
|
+
const names = stale.map((d) => d.name).join(", ");
|
|
37
|
+
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
38
|
+
if (!interactive) {
|
|
39
|
+
process.stderr.write(`${chalk.yellow("!")} Skills out of date (${names}). Run \`open-doc sync:skills\` to update.\n`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const rl = readline.createInterface({
|
|
43
|
+
input: process.stdin,
|
|
44
|
+
output: process.stdout
|
|
45
|
+
});
|
|
46
|
+
try {
|
|
47
|
+
const answer = (await rl.question(`${chalk.yellow("!")} Skills out of date: ${chalk.bold(names)}. Sync now? ${chalk.dim("(Y/n) ")}`)).trim().toLowerCase();
|
|
48
|
+
if (answer === "" || answer === "y" || answer === "yes") await syncSkills(skillsDir);
|
|
49
|
+
else process.stdout.write(chalk.dim("Skipped. Run `open-doc sync:skills` later to update.\n"));
|
|
50
|
+
} finally {
|
|
51
|
+
rl.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function run(argv) {
|
|
55
|
+
const version = await readVersion();
|
|
56
|
+
const program = new Command();
|
|
57
|
+
program.name("open-doc").description("Author documents — we handle the Vite/React stack, pagination, and export.").version(version, "-v, --version", "print version").helpOption("-h, --help", "show help").showHelpAfterError(chalk.dim("(run `open-doc --help` for usage)"));
|
|
58
|
+
program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").option("--no-skills-check", "skip the built-in skills drift check").option("--mcp", "serve an MCP endpoint at /mcp (requires @open-document/mcp)").action(async (flags) => {
|
|
59
|
+
if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
|
|
60
|
+
const { dev } = await import("../dev-CZtw1oqs.js");
|
|
61
|
+
await dev(flags);
|
|
62
|
+
});
|
|
63
|
+
program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
|
|
64
|
+
const { build } = await import("../build-BWZJ1gvL.js");
|
|
65
|
+
await build(flags);
|
|
66
|
+
});
|
|
67
|
+
program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
|
|
68
|
+
const { preview } = await import("../preview-DUfQl7Ij.js");
|
|
69
|
+
await preview(flags);
|
|
70
|
+
});
|
|
71
|
+
program.command("sync:skills").description("Sync built-in skills from @open-document/core into this workspace").option("--dry-run", "show what would change without writing").action(async (flags) => {
|
|
72
|
+
const { syncSkills: syncSkills$1 } = await import("../sync-C6CsPmyK.js");
|
|
73
|
+
await syncSkills$1(resolveBuiltinSkillsDir(), flags);
|
|
74
|
+
});
|
|
75
|
+
await program.parseAsync(argv, { from: "user" });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/cli/bin.ts
|
|
80
|
+
run(process.argv.slice(2)).catch((err) => {
|
|
81
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
82
|
+
process.stderr.write(`${chalk.red("error:")} ${message}\n`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
//#endregion
|