@dooc-dev/dooc 0.0.4 → 0.0.5

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 (95) hide show
  1. package/dist/cli.js +41 -3
  2. package/dist/compiler/asset-references.d.ts +4 -0
  3. package/dist/compiler/asset-references.js +117 -0
  4. package/dist/compiler/bundle-urls.d.ts +1 -1
  5. package/dist/compiler/bundle-urls.js +15 -5
  6. package/dist/compiler/check.js +8 -5
  7. package/dist/compiler/code-languages.js +7 -2
  8. package/dist/compiler/compile.d.ts +5 -0
  9. package/dist/compiler/compile.js +105 -10
  10. package/dist/compiler/config.js +2 -1
  11. package/dist/compiler/export.d.ts +4 -0
  12. package/dist/compiler/export.js +140 -0
  13. package/dist/compiler/figures.js +4 -0
  14. package/dist/compiler/files.js +80 -41
  15. package/dist/compiler/fonts.js +4 -1
  16. package/dist/compiler/icons.d.ts +1 -1
  17. package/dist/compiler/icons.js +11 -2
  18. package/dist/compiler/ignored-files.d.ts +3 -0
  19. package/dist/compiler/ignored-files.js +68 -0
  20. package/dist/compiler/locales.js +13 -8
  21. package/dist/compiler/ops.d.ts +6 -0
  22. package/dist/compiler/ops.js +98 -7
  23. package/dist/compiler/subformats.d.ts +24 -0
  24. package/dist/compiler/subformats.js +299 -0
  25. package/dist/compiler/textfile.js +3 -0
  26. package/dist/compiler/theme-variants.js +5 -2
  27. package/dist/core/content-metadata.d.ts +15 -6
  28. package/dist/core/content-metadata.js +278 -17
  29. package/dist/core/content-types.d.ts +3 -1
  30. package/dist/core/figure-frame.js +19 -1
  31. package/dist/core/files.d.ts +2 -1
  32. package/dist/core/files.js +6 -8
  33. package/dist/core/flow-base-css.generated.js +1 -1
  34. package/dist/core/html.js +3 -3
  35. package/dist/core/icons.d.ts +3 -0
  36. package/dist/core/icons.js +3 -0
  37. package/dist/core/json-tools.d.ts +1 -0
  38. package/dist/core/json-tools.js +12 -0
  39. package/dist/core/routing.d.ts +5 -2
  40. package/dist/core/routing.js +17 -5
  41. package/dist/core/subformat-record.d.ts +3 -0
  42. package/dist/core/subformat-record.js +131 -0
  43. package/dist/core/subformats.d.ts +43 -0
  44. package/dist/core/subformats.js +81 -0
  45. package/dist/core/toc-ui.js +25 -23
  46. package/dist/edit.global.js +322 -95
  47. package/dist/mcp.js +50 -9
  48. package/dist/plugins/index.d.ts +1 -0
  49. package/dist/plugins/transport.d.ts +22 -0
  50. package/dist/plugins/transport.js +1 -0
  51. package/dist/plugins.global.js +128 -0
  52. package/dist/subformats.global.js +127 -0
  53. package/dist/ui.global.js +91 -38
  54. package/dist/viewer/build-plugins.d.ts +7 -0
  55. package/dist/viewer/build-plugins.js +70 -0
  56. package/dist/viewer/build.d.ts +9 -0
  57. package/dist/viewer/build.js +32 -5
  58. package/dist/viewer/editor-tools.d.ts +7 -7
  59. package/dist/viewer/editor-tools.js +36 -5
  60. package/dist/viewer/font-picker.js +5 -1
  61. package/dist/viewer/git-diff.d.ts +3 -0
  62. package/dist/viewer/git-diff.js +47 -0
  63. package/dist/viewer/hmr.js +4 -1
  64. package/dist/viewer/i18n.js +7 -5
  65. package/dist/viewer/language-picker.d.ts +2 -2
  66. package/dist/viewer/language-picker.js +26 -9
  67. package/dist/viewer/lazy-graph.d.ts +2 -0
  68. package/dist/viewer/lazy-graph.js +30 -0
  69. package/dist/viewer/locales/eng.json +72 -10
  70. package/dist/viewer/locales/jpn.json +73 -11
  71. package/dist/viewer/locales/zho.json +73 -11
  72. package/dist/viewer/nav-focus.js +8 -1
  73. package/dist/viewer/nav-update.d.ts +2 -0
  74. package/dist/viewer/nav-update.js +117 -0
  75. package/dist/viewer/plugin-style.d.ts +1 -0
  76. package/dist/viewer/plugin-style.js +82 -0
  77. package/dist/viewer/resize.d.ts +0 -2
  78. package/dist/viewer/resize.js +2 -98
  79. package/dist/viewer/resource-library.d.ts +10 -8
  80. package/dist/viewer/resource-library.js +179 -30
  81. package/dist/viewer/search.d.ts +4 -2
  82. package/dist/viewer/search.js +252 -53
  83. package/dist/viewer/serve.d.ts +10 -5
  84. package/dist/viewer/serve.js +789 -278
  85. package/dist/viewer/site-icon.js +13 -6
  86. package/dist/viewer/site-title.js +15 -2
  87. package/dist/viewer/textfile.d.ts +3 -0
  88. package/dist/viewer/textfile.js +19 -2
  89. package/dist/viewer/theme-picker.d.ts +2 -0
  90. package/dist/viewer/theme-picker.js +24 -8
  91. package/dist/viewer/workspace.d.ts +2 -0
  92. package/dist/viewer/workspace.js +46 -1
  93. package/package.json +24 -9
  94. package/dist/compiler/bundle.d.ts +0 -2
  95. package/dist/compiler/bundle.js +0 -100
package/dist/mcp.js CHANGED
@@ -8,10 +8,13 @@ import { createInterface } from "node:readline";
8
8
  import { checkSite } from "./compiler/check.js";
9
9
  import { CHECK_KINDS } from "./compiler/check-types.js";
10
10
  import { createCompiler } from "./compiler/compile.js";
11
+ import { exportBundle } from "./compiler/export.js";
11
12
  import { filesSnapshot, updateFiles, uploadFile } from "./compiler/files.js";
12
13
  import { addProjectFont, listProjectFonts, removeProjectFont } from "./compiler/fonts.js";
13
14
  import { createDocOps, isOpError } from "./compiler/ops.js";
15
+ import { validateSubformatFile } from "./compiler/subformats.js";
14
16
  import { readTextfile, textfilePath, writeTextfile } from "./compiler/textfile.js";
17
+ import { MANIFEST_FILE } from "./core/content-metadata.js";
15
18
  import { localFile } from "./core/files.js";
16
19
  import { docDisplayName } from "./core/taxonomy.js";
17
20
  import { buildBundle } from "./viewer/build.js";
@@ -40,11 +43,37 @@ export const createTools = (root, options = {}) => {
40
43
  return file ? (compiled.sources.get(file)?.errors ?? []) : [];
41
44
  };
42
45
  return {
46
+ export: {
47
+ description: "Collect dooc.yaml and its source dependencies into dist/bundle.zip, without executing plugins or fetching remote data.",
48
+ props: {},
49
+ required: [],
50
+ run: () => {
51
+ const file = "dist/bundle.zip";
52
+ const data = exportBundle(root);
53
+ const path = textfilePath(root, file);
54
+ mkdirSync(dirname(path), { recursive: true });
55
+ const temp = join(dirname(path), `.export-${randomUUID()}.tmp`);
56
+ try {
57
+ writeFileSync(temp, data, { flag: "wx" });
58
+ renameSync(temp, path);
59
+ }
60
+ finally {
61
+ rmSync(temp, { force: true });
62
+ }
63
+ return { file, path, bytes: data.length };
64
+ },
65
+ },
43
66
  build: {
44
67
  description: "Build dist/bundle.html or dist/bundle.zip. url_preview=embed snapshots embedded URL content; network preserves URL references. Defaults to embed. Returns the output path, byte count and document count.",
45
68
  props: {
46
69
  format: { ...str, enum: ["html", "zip"] },
47
70
  url_preview: { ...str, enum: ["embed", "network"] },
71
+ mode: { ...str, enum: ["static", "live"] },
72
+ auth: { ...str, enum: ["external"] },
73
+ source_url: {
74
+ ...str,
75
+ description: "Public source directory URL for card copy links in HTML, relative to dooc.yaml.",
76
+ },
48
77
  },
49
78
  required: ["format"],
50
79
  run: async (a) => {
@@ -52,7 +81,10 @@ export const createTools = (root, options = {}) => {
52
81
  textfilePath(root, file);
53
82
  const bundle = await buildBundle(root, {
54
83
  format: a.format,
55
- urlPreview: (a.url_preview ?? "embed"),
84
+ urlPreview: (a.url_preview ?? (a.mode === "live" ? "network" : "embed")),
85
+ mode: a.mode,
86
+ auth: a.auth,
87
+ sourceUrl: a.source_url,
56
88
  });
57
89
  const path = textfilePath(root, file);
58
90
  mkdirSync(dirname(path), { recursive: true });
@@ -69,7 +101,7 @@ export const createTools = (root, options = {}) => {
69
101
  path,
70
102
  bytes: Buffer.byteLength(bundle.data),
71
103
  docs: bundle.docs,
72
- url_preview: a.url_preview ?? "embed",
104
+ url_preview: a.url_preview ?? (a.mode === "live" ? "network" : "embed"),
73
105
  };
74
106
  },
75
107
  },
@@ -88,9 +120,12 @@ export const createTools = (root, options = {}) => {
88
120
  description: "Create or update a local UTF-8 bundle file. base must equal the content from read_file, or null to create a new file. Conflicting edits are never overwritten.",
89
121
  props: { file: str, content: str, base: { type: ["string", "null"] } },
90
122
  required: ["file", "content", "base"],
91
- run: (a) => writeTextfile(root, fileArg(a.file), a.content, a.base)
92
- ? { file: a.file, ok: true }
93
- : { error: "File changed. Read it again before writing.", status: 409 },
123
+ run: (a) => {
124
+ validateSubformatFile(root, fileArg(a.file), a.content);
125
+ return writeTextfile(root, fileArg(a.file), a.content, a.base)
126
+ ? { file: a.file, ok: true }
127
+ : { error: "File changed. Read it again before writing.", status: 409 };
128
+ },
94
129
  },
95
130
  upload_file: {
96
131
  description: "Import a binary or text file from base64 data using the bundle file layout. Existing files are preserved with a unique name. Maximum 64 MiB.",
@@ -99,7 +134,7 @@ export const createTools = (root, options = {}) => {
99
134
  run: (a) => uploadFile(root, a),
100
135
  },
101
136
  update_files: {
102
- description: "Rename a file (file, name), move files/folders (paths, directory, optional before), change automatic layout (enabled), or restructure by extension. Updates document references and variants. Requires revision from list_files.",
137
+ description: "Rename a file (file, name), move files/folders (paths, directory), change automatic layout (enabled), or restructure by extension. Updates document references and variants. Requires revision from list_files.",
103
138
  props: {
104
139
  action: { ...str, enum: ["rename", "move", "layout", "restructure"] },
105
140
  revision: str,
@@ -107,14 +142,13 @@ export const createTools = (root, options = {}) => {
107
142
  name: str,
108
143
  paths: strings,
109
144
  directory: str,
110
- before: str,
111
145
  enabled: bool,
112
146
  },
113
147
  required: ["action", "revision"],
114
148
  run: (a) => updateFiles(root, a),
115
149
  },
116
150
  list_resources: {
117
- description: "List Statics: dictionary terms, code blocks and external URLs with their source files and line numbers.",
151
+ description: "List Statics: codeblocks (including term definitions and local text-file embeds, with normalized format and reference locations), URLs from Markdown links, and URL previews from Markdown images, with source files and line numbers.",
118
152
  props: {},
119
153
  run: () => resourceIndex(root, filesSnapshot(root).files.map((file) => file.path)),
120
154
  },
@@ -190,7 +224,8 @@ export const createTools = (root, options = {}) => {
190
224
  depth.set(d.id, dep);
191
225
  return {
192
226
  id: d.id,
193
- file: d.file,
227
+ file: d.subformat ? MANIFEST_FILE : d.file,
228
+ ...(d.subformat ? { subformat: d.subformat.ext } : {}),
194
229
  title: docDisplayName(d, d.id),
195
230
  parent: d.parent,
196
231
  depth: dep,
@@ -229,6 +264,12 @@ export const createTools = (root, options = {}) => {
229
264
  const id = String(a.id);
230
265
  const compiled = compiler.compile();
231
266
  const doc = compiled.docs.find((d) => d.id === id);
267
+ if (doc?.subformat)
268
+ return {
269
+ file: MANIFEST_FILE,
270
+ subformat: doc.subformat,
271
+ errors: compiled.sources.get(doc.file)?.errors ?? [],
272
+ };
232
273
  return doc
233
274
  ? {
234
275
  file: doc.file,
@@ -1,4 +1,5 @@
1
1
  export type { PluginAction, PluginActionContext, PluginActionField, PluginActionRequest, PluginActionResult, } from "./actions.js";
2
2
  export type { PluginBlock, PluginBlockContent, PluginCell, PluginEdit, PluginIcon, PluginInline, PluginTone, } from "./blocks.js";
3
3
  export { PluginError, parseOAuthToken } from "./oauth.js";
4
+ export type { PluginRequest, PluginResponse, PluginTransport } from "./transport.js";
4
5
  export type { DataPlugin, OAuthToken, PluginContent, PluginContext, PluginOAuth, PluginUser, PluginView, } from "./types.js";
@@ -0,0 +1,22 @@
1
+ import type { PluginAction, PluginActionRequest, PluginActionResult } from "./actions.js";
2
+ import type { PluginUser } from "./types.js";
3
+ import type { PluginView } from "./view.js";
4
+ export interface PluginRequest {
5
+ action: string;
6
+ plugin?: string;
7
+ url?: string;
8
+ operation?: PluginActionRequest;
9
+ requestId?: string;
10
+ }
11
+ export interface PluginResponse {
12
+ plugin?: string;
13
+ connected?: boolean;
14
+ autoConnect?: boolean;
15
+ user?: PluginUser | null;
16
+ view?: PluginView;
17
+ actions?: PluginAction[];
18
+ result?: PluginActionResult;
19
+ url?: string;
20
+ }
21
+ /** The host authenticates requests; rejecting with status 401/403 clears the plugin's views. */
22
+ export type PluginTransport = (request: PluginRequest) => Promise<PluginResponse>;
@@ -0,0 +1 @@
1
+ export {};