@dooc-dev/dooc 0.0.3 → 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 (106) hide show
  1. package/dist/cli.js +98 -56
  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.d.ts +1 -0
  15. package/dist/compiler/files.js +96 -38
  16. package/dist/compiler/fonts.js +4 -1
  17. package/dist/compiler/icons.d.ts +1 -1
  18. package/dist/compiler/icons.js +11 -2
  19. package/dist/compiler/ignored-files.d.ts +3 -0
  20. package/dist/compiler/ignored-files.js +68 -0
  21. package/dist/compiler/locales.js +13 -8
  22. package/dist/compiler/manifest.d.ts +2 -0
  23. package/dist/compiler/manifest.js +9 -2
  24. package/dist/compiler/ops.d.ts +6 -0
  25. package/dist/compiler/ops.js +98 -7
  26. package/dist/compiler/subformats.d.ts +24 -0
  27. package/dist/compiler/subformats.js +299 -0
  28. package/dist/compiler/textfile.js +3 -0
  29. package/dist/compiler/theme-variants.js +5 -2
  30. package/dist/core/content-metadata.d.ts +15 -6
  31. package/dist/core/content-metadata.js +278 -17
  32. package/dist/core/content-types.d.ts +3 -1
  33. package/dist/core/figure-frame.js +19 -1
  34. package/dist/core/files.d.ts +2 -1
  35. package/dist/core/files.js +6 -8
  36. package/dist/core/flow-base-css.generated.js +1 -1
  37. package/dist/core/html.js +3 -3
  38. package/dist/core/icons.d.ts +3 -0
  39. package/dist/core/icons.js +3 -0
  40. package/dist/core/json-tools.d.ts +1 -0
  41. package/dist/core/json-tools.js +12 -0
  42. package/dist/core/routing.d.ts +5 -2
  43. package/dist/core/routing.js +17 -5
  44. package/dist/core/subformat-record.d.ts +3 -0
  45. package/dist/core/subformat-record.js +131 -0
  46. package/dist/core/subformats.d.ts +43 -0
  47. package/dist/core/subformats.js +81 -0
  48. package/dist/core/toc-ui.js +25 -23
  49. package/dist/edit.global.js +322 -95
  50. package/dist/mcp.js +50 -9
  51. package/dist/plugins/index.d.ts +1 -0
  52. package/dist/plugins/local-storage.js +3 -0
  53. package/dist/plugins/oauth.d.ts +1 -1
  54. package/dist/plugins/oauth.js +8 -2
  55. package/dist/plugins/runtime.d.ts +6 -0
  56. package/dist/plugins/runtime.js +166 -34
  57. package/dist/plugins/transport.d.ts +22 -0
  58. package/dist/plugins/transport.js +1 -0
  59. package/dist/plugins/types.d.ts +3 -1
  60. package/dist/plugins.global.js +128 -0
  61. package/dist/subformats.global.js +127 -0
  62. package/dist/ui.global.js +91 -38
  63. package/dist/viewer/build-plugins.d.ts +7 -0
  64. package/dist/viewer/build-plugins.js +70 -0
  65. package/dist/viewer/build.d.ts +9 -0
  66. package/dist/viewer/build.js +32 -5
  67. package/dist/viewer/editor-tools.d.ts +7 -7
  68. package/dist/viewer/editor-tools.js +36 -5
  69. package/dist/viewer/font-picker.js +5 -1
  70. package/dist/viewer/git-diff.d.ts +3 -0
  71. package/dist/viewer/git-diff.js +47 -0
  72. package/dist/viewer/hmr.js +4 -1
  73. package/dist/viewer/i18n.js +7 -5
  74. package/dist/viewer/language-picker.d.ts +2 -2
  75. package/dist/viewer/language-picker.js +26 -9
  76. package/dist/viewer/lazy-graph.d.ts +2 -0
  77. package/dist/viewer/lazy-graph.js +30 -0
  78. package/dist/viewer/locales/eng.json +74 -10
  79. package/dist/viewer/locales/jpn.json +75 -11
  80. package/dist/viewer/locales/zho.json +75 -11
  81. package/dist/viewer/nav-focus.js +8 -1
  82. package/dist/viewer/nav-update.d.ts +2 -0
  83. package/dist/viewer/nav-update.js +117 -0
  84. package/dist/viewer/plugin-style.d.ts +1 -0
  85. package/dist/viewer/plugin-style.js +82 -0
  86. package/dist/viewer/plugins.js +46 -3
  87. package/dist/viewer/resize.d.ts +0 -2
  88. package/dist/viewer/resize.js +2 -98
  89. package/dist/viewer/resource-library.d.ts +10 -8
  90. package/dist/viewer/resource-library.js +179 -30
  91. package/dist/viewer/search.d.ts +4 -2
  92. package/dist/viewer/search.js +252 -53
  93. package/dist/viewer/serve.d.ts +10 -5
  94. package/dist/viewer/serve.js +882 -287
  95. package/dist/viewer/site-icon.js +13 -6
  96. package/dist/viewer/site-title.d.ts +13 -0
  97. package/dist/viewer/site-title.js +50 -0
  98. package/dist/viewer/textfile.d.ts +3 -0
  99. package/dist/viewer/textfile.js +19 -2
  100. package/dist/viewer/theme-picker.d.ts +2 -0
  101. package/dist/viewer/theme-picker.js +24 -8
  102. package/dist/viewer/workspace.d.ts +2 -0
  103. package/dist/viewer/workspace.js +46 -1
  104. package/package.json +24 -9
  105. package/dist/compiler/bundle.d.ts +0 -2
  106. package/dist/compiler/bundle.js +0 -100
package/dist/cli.js CHANGED
@@ -1,36 +1,39 @@
1
1
  #!/usr/bin/env node
2
- // CLI entry shared by npx and mise. Root defaults to cwd; relative paths resolve against cwd.
3
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ // CLI entry shared by npx and mise. The manifest defaults to ./dooc.yaml; project paths use its parent directory.
3
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { basename, dirname, join, resolve } from "node:path";
5
5
  import { parseArgs } from "node:util";
6
+ import { projectRoot } from "./compiler/manifest.js";
6
7
  import { prebuilt } from "./viewer/assets.js";
7
8
  process.env.NODE_ENV = prebuilt ? "production" : "development";
8
9
  const USAGE = `usage: dooc <command>
9
10
 
10
- edit [root] [port] open dooc in edit mode
11
- view [root] [port] open dooc in view mode
12
- --viewer-plugins <module> inject an external viewer plugin module
13
- build html [root] [out-dir] build bundle.html (default <root>/dist)
14
- build zip [root] [out-dir] build bundle.zip (default <root>/dist)
15
- --url_preview embed|network URL handling for either format (default: embed)
16
- check [root] [options] JSON consistency report (check --help for options)
17
- plugin pack <built-dir> [zip] package bundled JS and assets as a plugin ZIP
18
- plugin add <zip> [root] [port] install a local plugin and print login links
19
- plugin login <id> [root] [port] open a local login flow for an installed plugin
20
- font add <file> [root] register a font in the project (.dooc/fonts/)
21
- font list [root] list registered project fonts
22
- font remove <name> [root] remove a registered project font
23
- mcp [root] stdio MCP server (all read / write operations)
24
- --git-origin <module> inject gitOrigin from an external viewer plugin module
25
- help, --help, -h show this help`;
11
+ edit [dooc.yaml] [port] open dooc in edit mode
12
+ view [dooc.yaml] [port] open dooc in view mode
13
+ --viewer-plugins <module> inject an external viewer plugin module
14
+ build html [dooc.yaml] [out-dir] build bundle.html (default <project>/dist)
15
+ export [dooc.yaml] [out-dir] collect source dependencies into bundle.zip
16
+ build zip [dooc.yaml] [out-dir] build bundle.zip (default <project>/dist)
17
+ --url_preview embed|network URL handling for either format (default: embed)
18
+ --mode static|live HTML snapshot or runtime plugin API
19
+ --auth external host supplies live HTML authentication and transport
20
+ --source-url <url> source directory URL for card copy links in HTML
21
+ check [dooc.yaml] [options] JSON consistency report (check --help for options)
22
+ plugin pack <built-dir> [zip] package bundled JS and assets as a plugin ZIP
23
+ plugin add <zip> [dooc.yaml] [port] install a local plugin and print login links
24
+ plugin login <id> [dooc.yaml] [port] open a local login flow for an installed plugin
25
+ font add <file> [dooc.yaml] register a font in the project (.dooc/fonts/)
26
+ font list [dooc.yaml] list registered project fonts
27
+ font remove <name> [dooc.yaml] remove a registered project font
28
+ mcp [dooc.yaml] stdio MCP server (all read / write operations)
29
+ --git-origin <module> inject gitOrigin from an external viewer plugin module
30
+ help, --help, -h show this help
31
+
32
+ Default manifest: ./dooc.yaml. Paths and .dooc/ are relative to its directory.`;
26
33
  const fail = (message) => {
27
34
  console.error(message);
28
35
  process.exit(1);
29
36
  };
30
- const docsRoot = (arg) => {
31
- const root = resolve(arg ?? ".");
32
- return existsSync(root) ? root : fail(`${root} does not exist`);
33
- };
34
37
  const writeOut = (out, data) => {
35
38
  mkdirSync(dirname(out), { recursive: true });
36
39
  writeFileSync(out, data);
@@ -47,13 +50,13 @@ switch (command) {
47
50
  const [action, value, rootArg, portArg] = positionals;
48
51
  if (values.help) {
49
52
  console.log(`usage: dooc plugin pack <built-dir> [output.zip]
50
- dooc plugin add <zip> [root] [port]
51
- dooc plugin login <plugin-id> [root] [port]
53
+ dooc plugin add <zip> [dooc.yaml] [port]
54
+ dooc plugin login <plugin-id> [dooc.yaml] [port]
52
55
 
53
56
  ZIP root: package.json with name, version, type: module and main pointing to bundled .js/.mjs.
54
57
  Optional icon: path to a bundled SVG asset up to 64 KiB.
55
58
  Include relative assets (SVG, JSON, etc.); dependencies must already be bundled. Limit: 16 MiB / 256 files.
56
- Default output: <built-dir>.zip. Installed ZIPs: <root>/.dooc/plugins/.
59
+ Default output: <built-dir>.zip. Installed ZIPs: <project>/.dooc/plugins/.
57
60
  Personal logins and plugin approvals: ~/.dooc/plugins/ (override with DOOC_USER_DIR).
58
61
  Add/login starts a local editor and prints browser login links. Keep it running while signing in.
59
62
  Tokens stay on this computer and never enter exported documents.`);
@@ -74,7 +77,7 @@ Tokens stay on this computer and never enter exported documents.`);
74
77
  const port = Number(portArg ?? 5179);
75
78
  if (!Number.isInteger(port) || port < 1024 || port > 65535)
76
79
  throw new Error("Choose a local port between 1024 and 65535");
77
- process.env.DOCS_ROOT = docsRoot(rootArg);
80
+ process.env.DOCS_ROOT = projectRoot(rootArg);
78
81
  process.env.DOCS_HMR = "1";
79
82
  const { startServer } = await import("./viewer/serve.js");
80
83
  if (action === "add") {
@@ -94,7 +97,7 @@ Tokens stay on this computer and never enter exported documents.`);
94
97
  }
95
98
  }
96
99
  else
97
- throw new Error("usage: dooc plugin pack <built-dir> [zip] | add <zip> [root] [port] | login <id> [root] [port]");
100
+ throw new Error("usage: dooc plugin pack <built-dir> [zip] | add <zip> [dooc.yaml] [port] | login <id> [dooc.yaml] [port]");
98
101
  }
99
102
  catch (error) {
100
103
  fail(error instanceof Error ? error.message : String(error));
@@ -110,22 +113,22 @@ Tokens stay on this computer and never enter exported documents.`);
110
113
  options: { help: { type: "boolean", short: "h" } },
111
114
  });
112
115
  if (values.help) {
113
- console.log("usage: dooc font add <file> [root] | list [root] | remove <name> [root]\n\nFonts are copied to <root>/.dooc/fonts/ and included in ZIP and HTML bundles.\nSupported formats: TTF, OTF, WOFF, WOFF2. Existing names are never overwritten.\nReload the viewer after changing registered fonts. Default root: current directory.");
116
+ console.log("usage: dooc font add <file> [dooc.yaml] | list [dooc.yaml] | remove <name> [dooc.yaml]\n\nFonts are copied to <project>/.dooc/fonts/ and included in ZIP and HTML bundles.\nSupported formats: TTF, OTF, WOFF, WOFF2. Existing names are never overwritten.\nReload the viewer after changing registered fonts. Default manifest: ./dooc.yaml.");
114
117
  break;
115
118
  }
116
119
  const [action, value, rootArg] = positionals;
117
120
  if (action === "list" && positionals.length <= 2) {
118
- console.log(JSON.stringify(listProjectFonts(docsRoot(value)), null, 2));
121
+ console.log(JSON.stringify(listProjectFonts(projectRoot(value)), null, 2));
119
122
  }
120
123
  else if (action === "add" && value && positionals.length <= 3) {
121
- console.log(addProjectFont(docsRoot(rootArg), resolve(value)));
124
+ console.log(addProjectFont(projectRoot(rootArg), resolve(value)));
122
125
  }
123
126
  else if (action === "remove" && value && positionals.length <= 3) {
124
- removeProjectFont(docsRoot(rootArg), value);
127
+ removeProjectFont(projectRoot(rootArg), value);
125
128
  console.log(`Removed font: ${value}`);
126
129
  }
127
130
  else
128
- throw new Error("usage: dooc font add <file> [root] | list [root] | remove <name> [root]");
131
+ throw new Error("usage: dooc font add <file> [dooc.yaml] | list [dooc.yaml] | remove <name> [dooc.yaml]");
129
132
  }
130
133
  catch (error) {
131
134
  fail(error instanceof Error ? error.message : String(error));
@@ -147,7 +150,7 @@ Tokens stay on this computer and never enter exported documents.`);
147
150
  },
148
151
  });
149
152
  if (values.help) {
150
- console.log(`usage: dooc check [root] [options]
153
+ console.log(`usage: dooc check [dooc.yaml] [options]
151
154
 
152
155
  --only render,languages,themes select checks (default: all three)
153
156
  manifest validity is always checked
@@ -173,8 +176,8 @@ Node API: import { checkSite } from "@dooc-dev/dooc/check".`);
173
176
  break;
174
177
  }
175
178
  if (positionals.length > 1)
176
- throw new Error("check accepts at most one root path");
177
- report = checkSite(resolve(positionals[0] ?? "."), {
179
+ throw new Error("check accepts at most one dooc.yaml path");
180
+ report = checkSite(projectRoot(positionals[0]), {
178
181
  ...(values.only
179
182
  ? {
180
183
  only: values.only.flatMap((value) => value.split(",")),
@@ -210,16 +213,36 @@ Node API: import { checkSite } from "@dooc-dev/dooc/check".`);
210
213
  }
211
214
  case "view":
212
215
  case "edit": {
213
- const { positionals, values } = parseArgs({
214
- args,
215
- allowPositionals: true,
216
- options: { "viewer-plugins": { type: "string" } },
217
- });
218
- process.env.DOCS_ROOT = docsRoot(positionals[0]);
219
- process.env.DOCS_HMR = "1";
220
- // serve.ts reads DOCS_ROOT at import time, so import it after the env is set.
221
- const { startServer } = await import("./viewer/serve.js");
222
- await startServer(command === "view" ? "preview" : "edit", Number(positionals[1] ?? 5179), values["viewer-plugins"] ?? process.env.DOOC_VIEWER_PLUGINS);
216
+ try {
217
+ const { positionals, values } = parseArgs({
218
+ args,
219
+ allowPositionals: true,
220
+ options: { "viewer-plugins": { type: "string" } },
221
+ });
222
+ process.env.DOCS_ROOT = projectRoot(positionals[0]);
223
+ process.env.DOCS_HMR = "1";
224
+ // serve.ts reads DOCS_ROOT at import time, so import it after the env is set.
225
+ const { startServer } = await import("./viewer/serve.js");
226
+ await startServer(command === "view" ? "preview" : "edit", Number(positionals[1] ?? 5179), values["viewer-plugins"] ?? process.env.DOOC_VIEWER_PLUGINS);
227
+ }
228
+ catch (error) {
229
+ fail(error instanceof Error ? error.message : String(error));
230
+ }
231
+ break;
232
+ }
233
+ case "export": {
234
+ try {
235
+ if (args.length > 2)
236
+ throw new Error("export accepts a dooc.yaml path and an output directory");
237
+ const root = projectRoot(args[0]);
238
+ const out = join(resolve(args[1] ?? join(root, "dist")), "bundle.zip");
239
+ const { exportBundle } = await import("./compiler/export.js");
240
+ writeOut(out, exportBundle(root));
241
+ console.log(out);
242
+ }
243
+ catch (error) {
244
+ fail(error instanceof Error ? error.message : String(error));
245
+ }
223
246
  break;
224
247
  }
225
248
  case "build": {
@@ -228,16 +251,28 @@ Node API: import { checkSite } from "@dooc-dev/dooc/check".`);
228
251
  args,
229
252
  allowPositionals: true,
230
253
  options: {
231
- url_preview: { type: "string", default: "embed" },
254
+ url_preview: { type: "string" },
255
+ mode: { type: "string" },
256
+ auth: { type: "string" },
257
+ "viewer-plugins": { type: "string" },
258
+ "source-url": { type: "string" },
232
259
  help: { type: "boolean", short: "h" },
233
260
  },
234
261
  });
235
262
  if (values.help) {
236
- console.log(`usage: dooc build html [root] [out-dir] [--url_preview embed|network]
237
- dooc build zip [root] [out-dir] [--url_preview embed|network]
263
+ console.log(`usage: dooc build html [dooc.yaml] [out-dir] [--url_preview embed|network]
264
+ dooc build html [dooc.yaml] [out-dir] --mode static
265
+ dooc build html [dooc.yaml] [out-dir] --mode live --auth external
266
+ dooc build zip [dooc.yaml] [out-dir] [--url_preview embed|network]
238
267
 
239
268
  A bundle is dooc.yaml and its managed content. Builds only the selected format.
240
- Default output directory: <root>/dist. Source files are never rewritten.
269
+ Default output directory: <project>/dist. Source files are never rewritten.
270
+ Static builds resolve enabled local plugins using build-time credentials and embed their views.
271
+ Live HTML exposes window.dooc.setPluginTransport(request), without a login UI or credentials.
272
+ Use --viewer-plugins <module> to inject trusted build plugins; installed, enabled packages are discovered automatically.
273
+ Use dooc export for source dependencies without plugin execution or remote downloads.
274
+ --source-url <url> inject an HTTP(S) directory URL for card copy links (HTML only)
275
+ paths are relative to dooc.yaml; overrides GitHub origin/HEAD discovery
241
276
  --url_preview embed snapshot URL content and assets into the selected artifact (default)
242
277
  --url_preview network preserve URL references without downloading them at build time
243
278
 
@@ -256,14 +291,21 @@ Use --url_preview network with either format to build without downloading URL co
256
291
  if (format !== "html" && format !== "zip")
257
292
  throw new Error("build format must be html | zip");
258
293
  if (positionals.length > 3)
259
- throw new Error(`build ${format} accepts a root and an output directory`);
260
- const urlPreview = values.url_preview;
294
+ throw new Error(`build ${format} accepts a dooc.yaml path and an output directory`);
295
+ const urlPreview = values.url_preview ?? (values.mode === "live" ? "network" : "embed");
261
296
  if (urlPreview !== "embed" && urlPreview !== "network")
262
297
  throw new Error("--url_preview must be embed | network");
263
- const root = docsRoot(rootArg);
298
+ const root = projectRoot(rootArg);
264
299
  const out = join(resolve(outArg ?? join(root, "dist")), `bundle.${format}`);
265
300
  const { buildBundle } = await import("./viewer/build.js");
266
- const bundle = await buildBundle(root, { format, urlPreview });
301
+ const bundle = await buildBundle(root, {
302
+ format,
303
+ urlPreview,
304
+ mode: values.mode,
305
+ auth: values.auth,
306
+ pluginModule: values["viewer-plugins"],
307
+ sourceUrl: values["source-url"],
308
+ });
267
309
  writeOut(out, bundle.data);
268
310
  console.log(`${out} — ${bundle.docs} docs (url_preview=${urlPreview})`);
269
311
  }
@@ -283,17 +325,17 @@ Use --url_preview network with either format to build without downloading URL co
283
325
  },
284
326
  });
285
327
  if (values.help) {
286
- console.log("usage: dooc mcp [root] [--git-origin <module>]\n\nExposes docs, files, Statics, fonts, check, build and Git over stdio.\nBuild accepts format=html|zip and url_preview=embed|network (default embed).\nThe external module's default export must contain gitOrigin (the same provider used by edit/view).\nOnly gitOrigin is used; viewer setup and data plugins are not started. Authentication stays in the provider.");
328
+ console.log("usage: dooc mcp [dooc.yaml] [--git-origin <module>]\n\nExposes docs, files, Statics, fonts, check, build and Git over stdio.\nBuild accepts format=html|zip and url_preview=embed|network (default embed).\nThe external module's default export must contain gitOrigin (the same provider used by edit/view).\nOnly gitOrigin is used; viewer setup and data plugins are not started. Authentication stays in the provider.");
287
329
  break;
288
330
  }
289
331
  if (positionals.length > 1)
290
- throw new Error("mcp accepts at most one root path");
332
+ throw new Error("mcp accepts at most one dooc.yaml path");
291
333
  const { startMcp } = await import("./mcp.js");
292
334
  const { loadViewerPlugins } = await import("./viewer/plugin-config.js");
293
335
  const { gitOrigin } = await loadViewerPlugins(values["git-origin"]);
294
336
  if (values["git-origin"] && !gitOrigin)
295
337
  throw new Error("Module must provide gitOrigin");
296
- await startMcp(docsRoot(positionals[0]), { gitOrigin });
338
+ await startMcp(projectRoot(positionals[0]), { gitOrigin });
297
339
  }
298
340
  catch (error) {
299
341
  fail(error instanceof Error ? error.message : String(error));
@@ -0,0 +1,4 @@
1
+ type Replace = (url: string, embedded: boolean) => string;
2
+ /** Visit real asset URLs and preserve surrounding markup, examples and scripts. */
3
+ export declare const assetReferences: (source: string, extension: string, replace: Replace) => string;
4
+ export {};
@@ -0,0 +1,117 @@
1
+ import { parseFragment } from "parse5";
2
+ import postcss from "postcss";
3
+ import valueParser from "postcss-value-parser";
4
+ const cssReferences = (source, replace) => {
5
+ const tree = postcss.parse(source);
6
+ const value = (source, imports = false) => {
7
+ const parsed = valueParser(source);
8
+ parsed.walk((node) => {
9
+ if (node.type === "function" && node.value.toLowerCase() === "url") {
10
+ const before = valueParser.stringify(node.nodes).replace(/^(['"])(.*)\1$/, "$2");
11
+ const next = replace(before, true);
12
+ if (next !== before)
13
+ node.nodes = valueParser(JSON.stringify(next)).nodes;
14
+ return false;
15
+ }
16
+ if (node.type === "function" && /^(?:-webkit-)?image-set$/i.test(node.value))
17
+ for (const child of node.nodes)
18
+ if (child.type === "string")
19
+ child.value = replace(child.value, true);
20
+ });
21
+ const first = parsed.nodes.find((node) => node.type !== "space" && node.type !== "comment");
22
+ if (imports && first?.type === "string")
23
+ first.value = replace(first.value, true);
24
+ return parsed.toString();
25
+ };
26
+ tree.walkDecls((node) => {
27
+ node.value = value(node.value);
28
+ });
29
+ tree.walkAtRules((node) => {
30
+ node.params = value(node.params, node.name.toLowerCase() === "import");
31
+ });
32
+ return tree.toString();
33
+ };
34
+ /** Visit real asset URLs and preserve surrounding markup, examples and scripts. */
35
+ export const assetReferences = (source, extension, replace) => {
36
+ if (extension === "css")
37
+ return cssReferences(source, replace);
38
+ const changes = [];
39
+ const walk = (parent) => {
40
+ for (const node of parent.childNodes) {
41
+ if (!("tagName" in node))
42
+ continue;
43
+ for (const attr of node.attrs) {
44
+ let next = attr.value;
45
+ if (["src", "poster", "background"].includes(attr.name) ||
46
+ (attr.name === "data" && node.tagName === "object") ||
47
+ ["href", "xlink:href"].includes(attr.name))
48
+ next = replace(attr.value, !["a", "area", "base"].includes(node.tagName));
49
+ else if (attr.name === "srcdoc")
50
+ next = assetReferences(attr.value, "html", replace);
51
+ else if (attr.name === "style")
52
+ next = cssReferences(attr.value, replace);
53
+ else if (["srcset", "imagesrcset"].includes(attr.name)) {
54
+ let rest = attr.value;
55
+ next = "";
56
+ while (rest) {
57
+ const space = /^[\s,]*/.exec(rest)?.[0] ?? "";
58
+ next += space;
59
+ rest = rest.slice(space.length);
60
+ const token = /^\S+/.exec(rest)?.[0];
61
+ if (!token)
62
+ break;
63
+ const url = token.replace(/,+$/, "");
64
+ next += replace(url, true) + token.slice(url.length);
65
+ rest = rest.slice(token.length);
66
+ if (!token.endsWith(",")) {
67
+ const descriptor = /^[^,]*,?/.exec(rest)?.[0] ?? "";
68
+ next += descriptor;
69
+ rest = rest.slice(descriptor.length);
70
+ }
71
+ }
72
+ }
73
+ if (next === attr.value)
74
+ continue;
75
+ const name = attr.prefix ? `${attr.prefix}:${attr.name}` : attr.name;
76
+ const location = node.sourceCodeLocation?.attrs?.[name];
77
+ if (!location)
78
+ throw new Error(`Cannot update attribute: ${name}`);
79
+ const raw = source.slice(location.startOffset, location.endOffset);
80
+ const head = /^[^=]+\s*=\s*/.exec(raw)?.[0];
81
+ if (!head)
82
+ throw new Error(`Cannot update attribute: ${name}`);
83
+ const quote = raw[head.length] === "'" ? "'" : '"';
84
+ const escaped = next
85
+ .replaceAll("&", "&amp;")
86
+ .replaceAll("<", "&lt;")
87
+ .replaceAll(quote, quote === '"' ? "&quot;" : "&#39;");
88
+ changes.push({
89
+ from: location.startOffset,
90
+ to: location.endOffset,
91
+ text: head + quote + escaped + quote,
92
+ });
93
+ }
94
+ if (node.tagName === "style")
95
+ for (const child of node.childNodes) {
96
+ if (!("value" in child))
97
+ continue;
98
+ const next = cssReferences(child.value, replace);
99
+ if (next === child.value)
100
+ continue;
101
+ const location = child.sourceCodeLocation;
102
+ if (!location)
103
+ throw new Error("Cannot update style content");
104
+ changes.push({
105
+ from: location.startOffset,
106
+ to: location.endOffset,
107
+ text: next,
108
+ });
109
+ }
110
+ walk("content" in node ? node.content : node);
111
+ }
112
+ };
113
+ walk(parseFragment(source, { sourceCodeLocationInfo: true }));
114
+ for (const change of changes.sort((a, b) => b.from - a.from))
115
+ source = source.slice(0, change.from) + change.text + source.slice(change.to);
116
+ return source;
117
+ };
@@ -1,3 +1,3 @@
1
1
  import type { ZipEntry } from "./zip.js";
2
2
  /** Snapshot embedded URLs and their declarative assets without changing the source bundle. */
3
- export declare const embedBundleUrls: (root: string, entries: readonly ZipEntry[]) => Promise<ZipEntry[]>;
3
+ export declare const embedBundleUrls: (root: string, entries: readonly ZipEntry[], resolvePlugin?: (url: string) => Promise<string | undefined>) => Promise<ZipEntry[]>;
@@ -7,6 +7,7 @@ import valueParser from "postcss-value-parser";
7
7
  import { embeddedImages, parseMdast } from "../core/markdown.js";
8
8
  import { isRemoteTextfile } from "../core/textfile.js";
9
9
  import { collectRefs } from "./dialect.js";
10
+ import { assertNotIgnored } from "./ignored-files.js";
10
11
  import { readManifest } from "./manifest.js";
11
12
  import { fetchPublicFile } from "./public-file.js";
12
13
  import { textfilePath } from "./textfile.js";
@@ -32,14 +33,15 @@ const types = {
32
33
  const extension = (source) => posix.extname(new URL(source).pathname).slice(1).toLowerCase();
33
34
  const decode = (data) => new TextDecoder("utf-8", { fatal: true }).decode(data);
34
35
  /** Snapshot embedded URLs and their declarative assets without changing the source bundle. */
35
- export const embedBundleUrls = async (root, entries) => {
36
+ export const embedBundleUrls = async (root, entries, resolvePlugin) => {
36
37
  const result = new Map(entries.map((entry) => [entry.name, { ...entry }]));
37
38
  const figures = new Set(entries
38
39
  .filter((entry) => /\.(md|callouth)$/.test(entry.name))
39
40
  .flatMap((entry) => collectRefs(parseMdast(decode(entry.data))).figures));
40
- const siteIcon = readManifest(root).icon;
41
- if (siteIcon)
42
- figures.add(siteIcon);
41
+ const manifest = readManifest(root);
42
+ for (const file of [manifest.icon, ...Object.values(manifest.themeIcons ?? {})])
43
+ if (file)
44
+ figures.add(file);
43
45
  const cache = new Map();
44
46
  const sources = new Map();
45
47
  const pending = new Set();
@@ -68,6 +70,8 @@ export const embedBundleUrls = async (root, entries) => {
68
70
  try {
69
71
  let source = sources.get(key);
70
72
  if (!source) {
73
+ if (url.protocol === "bundle:")
74
+ assertNotIgnored(root, decodeURIComponent(url.pathname.slice(1)));
71
75
  if (url.protocol === "https:" && ++downloads > 256)
72
76
  throw new Error("Bundle exceeds 256 remote assets");
73
77
  let type = "";
@@ -263,7 +267,13 @@ export const embedBundleUrls = async (root, entries) => {
263
267
  if (remote.ref)
264
268
  throw new Error("Git URL embeds require a public HTTPS file URL");
265
269
  const url = keyOf(remote.url, image.url);
266
- const asset = await resource(url, false);
270
+ const plugin = await resolvePlugin?.(url.href);
271
+ const asset = plugin === undefined
272
+ ? await resource(url, false)
273
+ : {
274
+ data: Buffer.from(await markup(plugin, url.href)),
275
+ type: "text/html",
276
+ };
267
277
  const ext = Object.entries(types).find(([, type]) => type === asset.type)?.[0] ??
268
278
  (extension(url.href) || "txt");
269
279
  const name = `files/bundle/${createHash("sha256").update(url.href).digest("hex")}.${ext}`;
@@ -199,7 +199,9 @@ export const checkSite = (root, options = {}) => {
199
199
  else if (!report.themes.includes(theme))
200
200
  add("THEME_UNDECLARED", "warning", `themes/${theme}`, "Theme variant is not enabled by the site declaration and will not be displayed.", { theme });
201
201
  }
202
- const docs = new Map(flattenTree(manifest.tree).map(({ id }) => [docFile(id, manifest.files), id]));
202
+ const docs = new Map(flattenTree(manifest.tree)
203
+ .filter((node) => !node.subformat)
204
+ .map(({ id }) => [docFile(id, manifest.files), id]));
203
205
  const visited = new Set();
204
206
  const checkedThemes = new Set();
205
207
  const checkAsset = (file, context, withThemes = true) => {
@@ -410,10 +412,11 @@ export const checkSite = (root, options = {}) => {
410
412
  add("FILE_UNREADABLE", "error", file, messageOf(error));
411
413
  }
412
414
  }
413
- for (const file of manifest.files?.order ?? [])
414
- if (!docs.has(file))
415
- checkAsset(file, { language: sourceLanguage });
416
- for (const file of [manifest.icon, ...Object.values(manifest.files?.icons ?? {})])
415
+ for (const file of [
416
+ manifest.icon,
417
+ ...Object.values(manifest.themeIcons ?? {}),
418
+ ...Object.values(manifest.files?.icons ?? {}),
419
+ ])
417
420
  if (file)
418
421
  checkAsset(file, { language: sourceLanguage }, false);
419
422
  if (has("render")) {
@@ -3,6 +3,7 @@ import { join, relative, resolve } from "node:path";
3
3
  import { languageAliasNames, languageNames } from "@shikijs/langs";
4
4
  import { bundledLanguages } from "shiki/langs";
5
5
  import { CODE_LANGS, CODE_TEMPLATES } from "../core/taxonomy.js";
6
+ import { ignoredFiles } from "./ignored-files.js";
6
7
  export const CODE_LANGUAGES_DIR = ".dooc/code-languages";
7
8
  const supported = new Set([
8
9
  ...languageNames,
@@ -79,9 +80,13 @@ export const loadCodeGrammars = async (names) => {
79
80
  /** Renderer-owned registrations; Markdown content is never changed. */
80
81
  export const loadCodeLanguages = async (root) => {
81
82
  const directory = join(root, CODE_LANGUAGES_DIR);
83
+ const files = existsSync(directory)
84
+ ? readdirSync(directory).filter((file) => file.endsWith(".json"))
85
+ : [];
86
+ const ignored = ignoredFiles(root, files.map((file) => `${CODE_LANGUAGES_DIR}/${file}`));
82
87
  const extra = existsSync(directory)
83
- ? readdirSync(directory)
84
- .filter((file) => file.endsWith(".json"))
88
+ ? files
89
+ .filter((file) => !ignored.has(`${CODE_LANGUAGES_DIR}/${file}`))
85
90
  .sort()
86
91
  .flatMap((file) => readGrammars(join(directory, file)))
87
92
  : [];
@@ -9,6 +9,8 @@ export declare const collectDocLinks: (body: string) => string[];
9
9
  /** Source text and diagnostics for editing. key = CompiledDoc.file. */
10
10
  export interface DocSource {
11
11
  terms: TermEntry[];
12
+ /** Files already discovered during parsing, used by the viewer's change watcher. */
13
+ referencedFiles: string[];
12
14
  /**
13
15
  * Raw text on disk (including front-matter). The editor's initial value and the base for
14
16
  * detecting external changes.
@@ -28,9 +30,12 @@ export interface DocSource {
28
30
  errors: string[];
29
31
  }
30
32
  export interface Compiled {
33
+ subformats?: import("../core/subformats.js").Subformat[];
31
34
  previews: PreviewSettings;
32
35
  title?: string;
33
36
  icon?: string;
37
+ /** Theme name → site icon from themes/<theme>/<icon file>. */
38
+ iconVariants?: Record<string, string>;
34
39
  /** Display order follows dooc.yaml. Invalid sources retain their diagnostics for editing. */
35
40
  docs: CompiledDoc[];
36
41
  terms: TermEntry[];