@dooc-dev/dooc 0.0.4 → 0.0.6

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 (231) hide show
  1. package/dist/cli.js +157 -58
  2. package/dist/code-worker.global.js +152 -0
  3. package/dist/code.global.js +101 -101
  4. package/dist/compiler/asset-references.d.ts +4 -0
  5. package/dist/compiler/asset-references.js +117 -0
  6. package/dist/compiler/bundle-urls.d.ts +1 -1
  7. package/dist/compiler/bundle-urls.js +17 -5
  8. package/dist/compiler/check.js +10 -5
  9. package/dist/compiler/code-languages.js +7 -2
  10. package/dist/compiler/compile.d.ts +5 -0
  11. package/dist/compiler/compile.js +117 -12
  12. package/dist/compiler/config.js +2 -1
  13. package/dist/compiler/dxf.d.ts +1 -0
  14. package/dist/compiler/dxf.js +81 -0
  15. package/dist/compiler/export.d.ts +4 -0
  16. package/dist/compiler/export.js +147 -0
  17. package/dist/compiler/figures.js +43 -10
  18. package/dist/compiler/files.js +82 -41
  19. package/dist/compiler/fonts.js +4 -1
  20. package/dist/compiler/icons.d.ts +1 -1
  21. package/dist/compiler/icons.js +11 -2
  22. package/dist/compiler/ignored-files.d.ts +5 -0
  23. package/dist/compiler/ignored-files.js +98 -0
  24. package/dist/compiler/locales.js +13 -8
  25. package/dist/compiler/ops.d.ts +6 -0
  26. package/dist/compiler/ops.js +99 -8
  27. package/dist/compiler/subformat-schema.d.ts +14 -0
  28. package/dist/compiler/subformat-schema.js +92 -0
  29. package/dist/compiler/subformats.d.ts +22 -0
  30. package/dist/compiler/subformats.js +339 -0
  31. package/dist/compiler/textfile.js +3 -0
  32. package/dist/compiler/theme-variants.js +5 -2
  33. package/dist/core/code-file.js +7 -5
  34. package/dist/core/code-grammars.d.ts +5 -0
  35. package/dist/core/code-grammars.js +34 -0
  36. package/dist/core/content-metadata.d.ts +16 -6
  37. package/dist/core/content-metadata.js +283 -17
  38. package/dist/core/content-types.d.ts +4 -2
  39. package/dist/core/escape-html.d.ts +1 -0
  40. package/dist/core/escape-html.js +1 -0
  41. package/dist/core/figure-frame.js +20 -2
  42. package/dist/core/file-embed.js +7 -3
  43. package/dist/core/files.d.ts +2 -1
  44. package/dist/core/files.js +6 -8
  45. package/dist/core/flow-base-css.generated.js +1 -1
  46. package/dist/core/html.d.ts +4 -1
  47. package/dist/core/html.js +11 -10
  48. package/dist/core/icons.d.ts +3 -0
  49. package/dist/core/icons.js +3 -0
  50. package/dist/core/json-tools.d.ts +1 -0
  51. package/dist/core/json-tools.js +12 -0
  52. package/dist/core/language.js +5 -2
  53. package/dist/core/markdown.js +3 -1
  54. package/dist/core/previewers.d.ts +8 -0
  55. package/dist/core/previewers.js +2 -0
  56. package/dist/core/routing.d.ts +5 -2
  57. package/dist/core/routing.js +17 -5
  58. package/dist/core/schema-fields.d.ts +13 -0
  59. package/dist/core/schema-fields.js +175 -0
  60. package/dist/core/schema-graph-mount.js +26 -3
  61. package/dist/core/schema-refs.d.ts +8 -0
  62. package/dist/core/schema-refs.js +82 -0
  63. package/dist/core/subformat-record.d.ts +3 -0
  64. package/dist/core/subformat-record.js +131 -0
  65. package/dist/core/subformats.d.ts +43 -0
  66. package/dist/core/subformats.js +81 -0
  67. package/dist/core/toc-ui.js +26 -24
  68. package/dist/edit.global.js +326 -118
  69. package/dist/flow.global.js +3 -3
  70. package/dist/graph/abnfDiagram-S7VZAUFO-ASBULSKE.js +1 -0
  71. package/dist/graph/architecture-WOLXFQ4H-V57EDXXY.js +1 -0
  72. package/dist/graph/architectureDiagram-YGSQEFNW-GIMP347N.js +36 -0
  73. package/dist/graph/blockDiagram-APKKGZFW-RDL2T4JW.js +140 -0
  74. package/dist/graph/bpmnIcons-APHXDYXF-TWOSQNUQ.js +1 -0
  75. package/dist/graph/c4Diagram-KJ2TOQU5-75LIUC4F.js +38 -0
  76. package/dist/graph/chunk-26TUJSYJ.js +1 -0
  77. package/dist/graph/chunk-3LU66YMI.js +1 -0
  78. package/dist/graph/chunk-3RNHDNP5.js +1 -0
  79. package/dist/graph/chunk-3Y2PDVDE.js +1 -0
  80. package/dist/graph/chunk-3YJHMOOA.js +3 -0
  81. package/dist/graph/chunk-4KILFWYV.js +339 -0
  82. package/dist/graph/chunk-4QDE4SUK.js +1 -0
  83. package/dist/graph/chunk-5OO6DATX.js +1 -0
  84. package/dist/graph/chunk-5UUEAHTN.js +1 -0
  85. package/dist/graph/chunk-6T55RVVR.js +1 -0
  86. package/dist/graph/chunk-ARAJTKOH.js +2 -0
  87. package/dist/graph/chunk-BBD5CEDC.js +72 -0
  88. package/dist/graph/chunk-BVXT562I.js +1 -0
  89. package/dist/graph/chunk-BZAMCJ6B.js +32 -0
  90. package/dist/graph/chunk-C6J4A356.js +15 -0
  91. package/dist/graph/chunk-EG5UVNOC.js +213 -0
  92. package/dist/graph/chunk-GF4TOPUK.js +1 -0
  93. package/dist/graph/chunk-GYT4IYBZ.js +1 -0
  94. package/dist/graph/chunk-HJG2HUYJ.js +88 -0
  95. package/dist/graph/chunk-HOPPTA6H.js +62 -0
  96. package/dist/graph/chunk-I3DMZIHV.js +1 -0
  97. package/dist/graph/chunk-IC23EEF6.js +1 -0
  98. package/dist/graph/chunk-ISO77HML.js +1 -0
  99. package/dist/graph/chunk-JD7ZBJD2.js +1 -0
  100. package/dist/graph/chunk-JRSH5GNS.js +1 -0
  101. package/dist/graph/chunk-JSHWCPFJ.js +1 -0
  102. package/dist/graph/chunk-K2KLZU7M.js +10 -0
  103. package/dist/graph/chunk-K4I76XBX.js +14 -0
  104. package/dist/graph/chunk-KT4VPQD5.js +135 -0
  105. package/dist/graph/chunk-KU6GTEMS.js +1 -0
  106. package/dist/graph/chunk-LT6LXKCR.js +136 -0
  107. package/dist/graph/chunk-MPR575IN.js +1 -0
  108. package/dist/graph/chunk-N3OHKGRZ.js +1 -0
  109. package/dist/graph/chunk-O656ZI37.js +1 -0
  110. package/dist/graph/chunk-OFZLK5G4.js +1 -0
  111. package/dist/graph/chunk-PDH25ALM.js +2 -0
  112. package/dist/graph/chunk-PW2RGZ3O.js +1 -0
  113. package/dist/graph/chunk-QCJUF4YA.js +1 -0
  114. package/dist/graph/chunk-QEEA3KYY.js +2 -0
  115. package/dist/graph/chunk-QYAXYFNI.js +1 -0
  116. package/dist/graph/chunk-QYTM6GY3.js +1 -0
  117. package/dist/graph/chunk-R63JUMUK.js +1 -0
  118. package/dist/graph/chunk-SCEY3ZPT.js +1 -0
  119. package/dist/graph/chunk-VM2H7G2R.js +1 -0
  120. package/dist/graph/chunk-XQS73SBQ.js +1 -0
  121. package/dist/graph/chunk-YCRLJT2S.js +1 -0
  122. package/dist/graph/chunk-Z4FIZ7CR.js +1 -0
  123. package/dist/graph/chunk-ZMCB7VP2.js +1 -0
  124. package/dist/graph/chunk-ZSZXN4BT.js +2 -0
  125. package/dist/graph/classDiagram-v2-L25IHNXF-JL7LVDZH.js +217 -0
  126. package/dist/graph/cose-bilkent-JH36ORCC-PNM3EYPB.js +1 -0
  127. package/dist/graph/cynefin-EF2NZ3EQ-PSXP3DXL.js +1 -0
  128. package/dist/graph/cynefinDiagram-L36ESFBY-QVY54CXO.js +62 -0
  129. package/dist/graph/dagre-SPEB5RXH-HPGQXBZJ.js +4 -0
  130. package/dist/graph/diagram-3B7GL73J-DWH5WS2P.js +200 -0
  131. package/dist/graph/diagram-DNEMPZML-TEGH2U5I.js +24 -0
  132. package/dist/graph/diagram-L3MUGCDN-X4MREUWR.js +41 -0
  133. package/dist/graph/diagram-LA4NIPWU-NXT746HG.js +24 -0
  134. package/dist/graph/diagram-MHCOC4E2-JGHXSAGS.js +3 -0
  135. package/dist/graph/diagram-XPFHEONP-ZHZPBLT4.js +30 -0
  136. package/dist/graph/ebnfDiagram-UZSYDL2S-SMF6KJ43.js +1 -0
  137. package/dist/graph/elk-XV6XMXQE-AZ4HLCWI.js +27 -0
  138. package/dist/graph/erDiagram-EYBAPDEH-B3JNJ357.js +99 -0
  139. package/dist/graph/eventmodeling-K75KTNOO-WG6DDYMC.js +1 -0
  140. package/dist/graph/flowDiagram-MALGAFMO-2R7EYAQI.js +1 -0
  141. package/dist/graph/ganttDiagram-23REXITY-YXBYWFOJ.js +292 -0
  142. package/dist/graph/gitGraph-VSP46ZUC-VBFWJBBT.js +1 -0
  143. package/dist/graph/gitGraphDiagram-STJD7YCW-4FZDCFGV.js +106 -0
  144. package/dist/graph/info-OHQRW6UA-ALVDUVYV.js +1 -0
  145. package/dist/graph/infoDiagram-KBXO4MBG-7EHX2GQG.js +2 -0
  146. package/dist/graph/ishikawaDiagram-M35NCXHK-FRZD2PWQ.js +70 -0
  147. package/dist/graph/journeyDiagram-OPLOXDXO-7Z66JCPR.js +139 -0
  148. package/dist/graph/kanban-definition-BZKZHSQY-NN5AIKTE.js +89 -0
  149. package/dist/graph/katex-DXDNVO6V.js +257 -0
  150. package/dist/graph/mindmap-definition-I2QAS2VK-HDPCABN2.js +98 -0
  151. package/dist/graph/packet-JDAUHWVQ-5MQIBWAH.js +1 -0
  152. package/dist/graph/pegDiagram-FD4XPPHP-H2BFNCKT.js +1 -0
  153. package/dist/graph/pie-XZMESJXO-T5VRKHVT.js +1 -0
  154. package/dist/graph/pieDiagram-J4AKIIQI-O3NJSVD3.js +39 -0
  155. package/dist/graph/quadrantDiagram-XTYBLID2-TMTZJI3P.js +7 -0
  156. package/dist/graph/radar-ABXABTNO-C6FXIBYW.js +1 -0
  157. package/dist/graph/railroad-I3PHUGI6-ZSO5JXB3.js +1 -0
  158. package/dist/graph/railroad-abnf-LNEFI6M7-CI4GQRHB.js +1 -0
  159. package/dist/graph/railroad-ebnf-DWYD2UWJ-MUENNCGK.js +1 -0
  160. package/dist/graph/railroad-peg-JR7BVNR7-N3X5GGIX.js +1 -0
  161. package/dist/graph/railroadDiagram-MRQ6NCDL-JHWS23UO.js +1 -0
  162. package/dist/graph/requirementDiagram-Y7LWUY3S-7DVLPO4B.js +84 -0
  163. package/dist/graph/sankeyDiagram-WGJFYUXA-Z5L4R5TR.js +40 -0
  164. package/dist/graph/schema-graph-global.js +639 -0
  165. package/dist/graph/sequenceDiagram-5NDRBG5M-RCTU25NT.js +169 -0
  166. package/dist/graph/sizeCapture-INFHLROL-RROY32P5.js +1 -0
  167. package/dist/graph/stateDiagram-v2-FJ4FJNEA-BXUSPWDK.js +291 -0
  168. package/dist/graph/swimlanes-UMQ2AFYF-LDD74Q2S.js +1 -0
  169. package/dist/graph/swimlanesDiagram-OMPLPG4O-ZYULLJSU.js +8 -0
  170. package/dist/graph/timeline-definition-SEUHKTQE-ZQSMIVAS.js +120 -0
  171. package/dist/graph/treeView-D4JQ5SDB-42S7U73N.js +1 -0
  172. package/dist/graph/treemap-SAJKECNS-RUBYQ7XF.js +1 -0
  173. package/dist/graph/usecaseDiagram-AFA6YXN4-57RDRYXF.js +370 -0
  174. package/dist/graph/vennDiagram-NNMJR3RB-5C3LVAV6.js +34 -0
  175. package/dist/graph/wardley-7MLQ67FV-NV5HXTTC.js +1 -0
  176. package/dist/graph/wardleyDiagram-S7YFUSEH-6D5BKXHM.js +78 -0
  177. package/dist/graph/xychartDiagram-GGNKY7IX-6ET3ZM67.js +7 -0
  178. package/dist/mcp.js +54 -12
  179. package/dist/plugins/index.d.ts +1 -0
  180. package/dist/plugins/transport.d.ts +22 -0
  181. package/dist/plugins/transport.js +1 -0
  182. package/dist/plugins.global.js +95 -0
  183. package/dist/subformats.global.js +21 -0
  184. package/dist/ui.global.js +80 -60
  185. package/dist/viewer/build-plugins.d.ts +7 -0
  186. package/dist/viewer/build-plugins.js +70 -0
  187. package/dist/viewer/build.d.ts +11 -0
  188. package/dist/viewer/build.js +52 -11
  189. package/dist/viewer/code-file.js +7 -2
  190. package/dist/viewer/editor-tools.d.ts +7 -7
  191. package/dist/viewer/editor-tools.js +36 -5
  192. package/dist/viewer/figure-preview.d.ts +4 -0
  193. package/dist/viewer/figure-preview.js +54 -0
  194. package/dist/viewer/font-picker.js +5 -1
  195. package/dist/viewer/git-diff.d.ts +3 -0
  196. package/dist/viewer/git-diff.js +47 -0
  197. package/dist/viewer/hmr.js +8 -4
  198. package/dist/viewer/i18n.js +7 -5
  199. package/dist/viewer/language-picker.d.ts +2 -2
  200. package/dist/viewer/language-picker.js +26 -9
  201. package/dist/viewer/lazy-preview.d.ts +2 -0
  202. package/dist/viewer/lazy-preview.js +43 -0
  203. package/dist/viewer/locales/eng.json +95 -10
  204. package/dist/viewer/locales/jpn.json +96 -11
  205. package/dist/viewer/locales/zho.json +96 -11
  206. package/dist/viewer/nav-focus.js +8 -1
  207. package/dist/viewer/nav-update.d.ts +2 -0
  208. package/dist/viewer/nav-update.js +117 -0
  209. package/dist/viewer/plugin-blocks.js +1 -1
  210. package/dist/viewer/plugin-style.d.ts +1 -0
  211. package/dist/viewer/plugin-style.js +82 -0
  212. package/dist/viewer/plugins.js +1 -1
  213. package/dist/viewer/resize.d.ts +0 -2
  214. package/dist/viewer/resize.js +2 -98
  215. package/dist/viewer/resource-library.d.ts +11 -9
  216. package/dist/viewer/resource-library.js +181 -31
  217. package/dist/viewer/search.d.ts +4 -2
  218. package/dist/viewer/search.js +252 -53
  219. package/dist/viewer/serve.d.ts +11 -5
  220. package/dist/viewer/serve.js +913 -295
  221. package/dist/viewer/site-icon.js +13 -6
  222. package/dist/viewer/site-title.js +15 -2
  223. package/dist/viewer/textfile.d.ts +5 -0
  224. package/dist/viewer/textfile.js +34 -2
  225. package/dist/viewer/theme-picker.d.ts +2 -0
  226. package/dist/viewer/theme-picker.js +24 -8
  227. package/dist/viewer/workspace.d.ts +2 -0
  228. package/dist/viewer/workspace.js +46 -1
  229. package/package.json +27 -10
  230. package/dist/compiler/bundle.d.ts +0 -2
  231. package/dist/compiler/bundle.js +0 -100
@@ -0,0 +1,7 @@
1
+ import type { PluginTransport } from "../plugins/transport.js";
2
+ /** Only previously enabled packages execute; personal credentials never enter the artifact. */
3
+ export declare const loadBuildPlugins: (root: string, module?: string) => Promise<{
4
+ request: PluginTransport;
5
+ dispose: () => void;
6
+ }>;
7
+ export declare const pluginSnapshot: (request: PluginTransport) => (url: string) => Promise<string | undefined>;
@@ -0,0 +1,70 @@
1
+ import { createLocalPluginStorage } from "../plugins/local-storage.js";
2
+ import { createPluginRuntime } from "../plugins/runtime.js";
3
+ import { createExtensionManager } from "./extensions.js";
4
+ import { loadViewerPlugins } from "./plugin-config.js";
5
+ import { PLUGIN_BLOCK_CSS } from "./plugin-style.js";
6
+ import { pluginViewHtml } from "./plugin-view.js";
7
+ /** Only previously enabled packages execute; personal credentials never enter the artifact. */
8
+ export const loadBuildPlugins = async (root, module) => {
9
+ const initial = await loadViewerPlugins(module);
10
+ if (initial.setup)
11
+ throw new Error("Build plugins must be declared without a viewer setup callback");
12
+ const personal = createLocalPluginStorage();
13
+ let config = initial;
14
+ const manager = createExtensionManager(root, {
15
+ configuration: () => config,
16
+ register(plugin, options) {
17
+ config = {
18
+ ...config,
19
+ plugins: [...config.plugins, plugin],
20
+ mocks: {
21
+ ...config.mocks,
22
+ ...(options?.mock ? { [plugin.id]: options.mock } : {}),
23
+ },
24
+ };
25
+ },
26
+ unregister(id) {
27
+ config = {
28
+ ...config,
29
+ plugins: config.plugins.filter((plugin) => plugin.id !== id),
30
+ };
31
+ },
32
+ }, initial, personal);
33
+ try {
34
+ const errors = await manager.restore();
35
+ if (errors.length)
36
+ throw new Error(errors.join("\n"));
37
+ const runtime = createPluginRuntime(config.plugins, async (input, init) => {
38
+ const request = new Request(input, init);
39
+ const mock = Object.values(config.mocks).find((mock) => mock.origin === new URL(request.url).origin);
40
+ return mock ? mock.handle(request) : fetch(request);
41
+ }, personal.credentials);
42
+ const session = runtime.createSession();
43
+ const request = async (input) => {
44
+ if (input.action === "resolve")
45
+ return { plugin: runtime.resolve(input.url) };
46
+ if (input.action === "read" && input.plugin)
47
+ return runtime.read(session, input.plugin, input.url);
48
+ throw new Error("Static builds only resolve and read plugins");
49
+ };
50
+ return { request, dispose: () => manager.dispose() };
51
+ }
52
+ catch (error) {
53
+ manager.dispose();
54
+ throw error;
55
+ }
56
+ };
57
+ export const pluginSnapshot = (request) => async (url) => {
58
+ const { plugin } = await request({ action: "resolve", url });
59
+ if (!plugin)
60
+ return undefined;
61
+ const { view } = await request({ action: "read", plugin, url });
62
+ if (!view)
63
+ throw new Error(`Plugin ${plugin} returned no view for ${url}`);
64
+ const html = pluginViewHtml(view).replace(/<button\b/g, "<button disabled");
65
+ return `<div class="plugin"><style>${PLUGIN_BLOCK_CSS}
66
+ .plugin { container-type: inline-size; color: var(--doc-fg, #000000); --doc-mono: ui-monospace, monospace; }
67
+ .plugin-copy { display: none; }
68
+ .plugin button:disabled { cursor: default; }
69
+ </style><div class="plugin-content">${html}</div></div>`;
70
+ };
@@ -1,6 +1,17 @@
1
+ import { type PreviewSettings } from "../core/previewers.js";
2
+ import type { PluginTransport } from "../plugins/transport.js";
1
3
  export interface BuildOptions {
2
4
  format: "html" | "zip";
3
5
  urlPreview?: "embed" | "network";
6
+ mode?: "static" | "live";
7
+ auth?: "external";
8
+ /** Public directory URL corresponding to the manifest directory, embedded in HTML. */
9
+ sourceUrl?: string;
10
+ /** Trusted server module used for static snapshots, never serialized into HTML. */
11
+ pluginModule?: string;
12
+ /** Build-time authenticated reads; live HTML receives its transport at runtime. */
13
+ pluginTransport?: PluginTransport;
14
+ previews?: PreviewSettings;
4
15
  }
5
16
  /** Build one artifact from the manifest and its managed content. */
6
17
  export declare const buildBundle: (root: string, options: BuildOptions) => Promise<{
@@ -1,31 +1,63 @@
1
1
  import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
3
  import { dirname, join } from "node:path";
4
- import { bundleEntries } from "../compiler/bundle.js";
5
4
  import { embedBundleUrls } from "../compiler/bundle-urls.js";
6
5
  import { compileSite } from "../compiler/compile.js";
6
+ import { exportEntries } from "../compiler/export.js";
7
7
  import { loadProjectFonts } from "../compiler/fonts.js";
8
8
  import { textfilePath } from "../compiler/textfile.js";
9
9
  import { zip } from "../compiler/zip.js";
10
+ import { walkBlocks } from "../core/blocks.js";
11
+ import { selectCodeGrammars } from "../core/code-grammars.js";
12
+ import { parsePreviewSettings } from "../core/previewers.js";
13
+ import { loadBuildPlugins, pluginSnapshot } from "./build-plugins.js";
10
14
  import { loadSiteLanguages } from "./languages.js";
15
+ import { loadViewerPlugins } from "./plugin-config.js";
16
+ import { sourceFileBase } from "./workspace.js";
11
17
  /** Build one artifact from the manifest and its managed content. */
12
18
  export const buildBundle = async (root, options) => {
13
19
  const { format } = options;
14
- const urlPreview = options.urlPreview ?? "embed";
20
+ if (options.sourceUrl !== undefined && format !== "html")
21
+ throw new Error("Source URL applies to HTML builds only");
22
+ const sourceBase = format === "html" ? sourceFileBase(root, options.sourceUrl) : undefined;
23
+ const urlPreview = options.urlPreview ?? (options.mode === "live" ? "network" : "embed");
24
+ if (options.mode !== undefined && !["static", "live"].includes(options.mode))
25
+ throw new Error("build mode must be static | live");
26
+ if (options.mode && format !== "html")
27
+ throw new Error("Build modes apply to HTML; use export for source ZIPs");
28
+ if (options.auth !== undefined && (options.auth !== "external" || options.mode !== "live"))
29
+ throw new Error("External authentication requires live HTML");
30
+ if (options.mode === "static" && urlPreview !== "embed")
31
+ throw new Error("Static HTML requires embedded resources");
32
+ if (options.mode === "live" && urlPreview !== "network")
33
+ throw new Error("Live HTML requires network resources");
15
34
  if (format !== "html" && format !== "zip")
16
35
  throw new Error("build format must be html | zip");
17
36
  if (urlPreview !== "embed" && urlPreview !== "network")
18
37
  throw new Error("--url_preview must be embed | network");
38
+ const previews = options.previews ??
39
+ parsePreviewSettings({
40
+ domains: (await loadViewerPlugins(options.pluginModule)).allowedDomains ?? [],
41
+ });
19
42
  const validate = (path) => {
20
- const compiled = compileSite(path);
43
+ const compiled = compileSite(path, { previews });
21
44
  if (compiled.errors.length)
22
45
  throw new Error(`Content validation failed:\n${compiled.errors.join("\n")}`);
23
46
  return compiled;
24
47
  };
48
+ let entries = exportEntries(root);
25
49
  let compiled = validate(root);
26
- let entries = format === "zip" || urlPreview === "embed" ? bundleEntries(root) : [];
27
50
  if (urlPreview === "embed") {
28
- entries = await embedBundleUrls(root, entries);
51
+ const plugins = format === "html" && !options.pluginTransport
52
+ ? await loadBuildPlugins(root, options.pluginModule)
53
+ : undefined;
54
+ try {
55
+ const request = options.pluginTransport ?? plugins?.request;
56
+ entries = await embedBundleUrls(root, entries, request ? pluginSnapshot(request) : undefined);
57
+ }
58
+ finally {
59
+ plugins?.dispose();
60
+ }
29
61
  const temp = mkdtempSync(join(tmpdir(), "dooc-bundle-"));
30
62
  try {
31
63
  for (const entry of entries) {
@@ -43,13 +75,22 @@ export const buildBundle = async (root, options) => {
43
75
  return { data: zip(entries), docs: compiled.docs.length };
44
76
  const config = await loadSiteLanguages(root);
45
77
  const { bundleClient, publishHtml, siteFrom } = await import("./serve.js");
78
+ const site = {
79
+ ...siteFrom(compiled, config.languages, config),
80
+ sourceBase,
81
+ fonts: loadProjectFonts(root),
82
+ };
83
+ const blocks = walkBlocks(site.entries.flatMap((entry) => entry.blocks));
84
+ const code = blocks.flatMap((block) => block.type === "code" && block.lang !== "mermaid" && !block.unavailable ? [block] : []);
85
+ site.codeGrammars = selectCodeGrammars(site.codeGrammars ?? [], code.map((block) => block.lang ?? "text"));
86
+ const diagrams = blocks.some((block) => block.type === "schemaGraph" ||
87
+ (block.type === "code" && block.lang === "mermaid" && !block.unavailable));
46
88
  return {
47
- data: publishHtml({
48
- ...siteFrom(compiled, config.languages),
49
- fonts: loadProjectFonts(root),
50
- codeLanguages: config.codeLanguages,
51
- codeGrammars: config.codeGrammars,
52
- }, await bundleClient("core/schema-graph-global.tsx", true), undefined, await bundleClient("viewer/code-highlight.ts", true), urlPreview === "embed" ? "static" : "network"),
89
+ data: publishHtml(site, diagrams ? await bundleClient("core/schema-graph-global.tsx") : "", undefined, code.length ? await bundleClient("viewer/code-highlight.ts") : "", options.mode === "live" ? "live" : urlPreview === "embed" ? "static" : "network", options.mode === "live" && blocks.some((block) => block.type === "external")
90
+ ? await bundleClient("viewer/published-plugins.ts")
91
+ : "", compiled.docs.some((doc) => doc.subformat)
92
+ ? await bundleClient("viewer/published-subformats.ts")
93
+ : ""),
53
94
  docs: compiled.docs.length,
54
95
  };
55
96
  };
@@ -1,5 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { readManifest } from "../compiler/manifest.js";
3
+ import { validateSubformatFile } from "../compiler/subformats.js";
3
4
  import { textfilePath, writeTextfile } from "../compiler/textfile.js";
4
5
  import { codeFileName, codeFilePlan } from "../core/code-file.js";
5
6
  import { isDocId } from "../core/content-metadata.js";
@@ -20,8 +21,12 @@ export const codeFileResponse = (root, input, previews) => {
20
21
  ? defaultFilePath(codeFileName(input.body, input.position, input.documentId))
21
22
  : input.file;
22
23
  let plan = codeFilePlan(input.body, input.position, target, previews);
23
- const create = () => !existsSync(textfilePath(root, plan.file)) &&
24
- writeTextfile(root, plan.file, plan.content, null);
24
+ const create = () => {
25
+ if (existsSync(textfilePath(root, plan.file)))
26
+ return false;
27
+ validateSubformatFile(root, plan.file, plan.content, previews?.domains);
28
+ return writeTextfile(root, plan.file, plan.content, null);
29
+ };
25
30
  if (automatic) {
26
31
  for (let index = 2; !create(); index++) {
27
32
  const dot = target.lastIndexOf(".");
@@ -1,19 +1,19 @@
1
1
  export { codeBlockAt } from "../core/markdown.js";
2
2
  export declare function isLocalToolRequest(host: string, origin: string | undefined, contentType: string | undefined): boolean;
3
3
  export declare function runCodeTool(root: string, body: string, position: number, action: "format" | "lint"): Promise<{
4
- change: {
5
- from: number;
6
- to: number;
7
- insert: string;
8
- };
9
- findings?: undefined;
10
- } | {
11
4
  findings: {
12
5
  range: [number, number];
13
6
  message: string;
14
7
  ruleId: string;
15
8
  }[];
16
9
  change?: undefined;
10
+ } | {
11
+ change: {
12
+ from: number;
13
+ to: number;
14
+ insert: string;
15
+ };
16
+ findings?: undefined;
17
17
  }>;
18
18
  export declare function validateCodeTools(root: string, body: string): Promise<{
19
19
  changes: {
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { visit } from "unist-util-visit";
5
+ import { formatJson } from "../core/json-tools.js";
5
6
  import { codeBlockAt, offsetAt, parseMdast } from "../core/markdown.js";
6
7
  export { codeBlockAt } from "../core/markdown.js";
7
8
  import { formatMarkdown } from "../compiler/format.js";
@@ -49,12 +50,39 @@ export async function runCodeTool(root, body, position, action) {
49
50
  try {
50
51
  config = JSON.parse(await readFile(path, "utf8"));
51
52
  }
52
- catch {
53
- throw new Error(`Create .dooc/editor-tools/${block.language}.json to configure this language`);
53
+ catch (error) {
54
+ if (error.code !== "ENOENT")
55
+ throw error;
56
+ if (block.language !== "json")
57
+ throw new Error(`Create .dooc/editor-tools/${block.language}.json to configure this language`);
58
+ config = {};
54
59
  }
55
60
  if (!config || typeof config !== "object")
56
61
  throw new Error("Invalid editor tool configuration");
57
- const output = await execute(command(config[action === "format" ? "formatter" : "linter"]), root, `${block.code}\n`, action === "lint");
62
+ const tool = config[action === "format" ? "formatter" : "linter"];
63
+ let output;
64
+ if (block.language === "json" && tool == null) {
65
+ if (action === "lint") {
66
+ try {
67
+ JSON.parse(block.code);
68
+ return { findings: [] };
69
+ }
70
+ catch (error) {
71
+ return {
72
+ findings: [
73
+ {
74
+ range: [block.from, block.to],
75
+ message: String(error),
76
+ ruleId: "error",
77
+ },
78
+ ],
79
+ };
80
+ }
81
+ }
82
+ output = formatJson(block.code);
83
+ }
84
+ else
85
+ output = await execute(command(tool), root, `${block.code}\n`, action === "lint");
58
86
  if (action === "format") {
59
87
  const normalized = output.replace(/\r\n/g, "\n").replace(/\n$/, "");
60
88
  if (!normalized && block.code.trim())
@@ -134,14 +162,17 @@ export async function validateCodeTools(root, body) {
134
162
  raw = await readFile(join(root, ".dooc/editor-tools", `${node.lang}.json`), "utf8");
135
163
  }
136
164
  catch (error) {
137
- if (error.code === "ENOENT")
165
+ if (error.code === "ENOENT") {
166
+ if (node.lang === "json")
167
+ blocks.push(node.position.start.offset);
138
168
  continue;
169
+ }
139
170
  throw error;
140
171
  }
141
172
  const config = JSON.parse(raw);
142
173
  if (!config || typeof config !== "object")
143
174
  throw new Error("Invalid editor tool configuration");
144
- if (config[tool] != null)
175
+ if (config[tool] != null || node.lang === "json")
145
176
  blocks.push(offsetAt(text, node.position.start.line, node.position.start.column));
146
177
  }
147
178
  return blocks;
@@ -0,0 +1,4 @@
1
+ import type { FigureEntry } from "../core/content-types.js";
2
+ export declare const deferredFigureHtml: (fig: FigureEntry, cls?: string, label?: string) => string;
3
+ /** Delegated so previews inserted by navigation or HMR use the same loading state. */
4
+ export declare function mountFigurePreviews(): void;
@@ -0,0 +1,54 @@
1
+ import { escapeHtml } from "../core/escape-html.js";
2
+ import { figureFrameHtml } from "../core/figure-frame.js";
3
+ export const deferredFigureHtml = (fig, cls = "fig-frame", label) => {
4
+ if (fig.markup.length <= 100_000)
5
+ return figureFrameHtml(fig, cls, label);
6
+ if (cls.includes("figpop-frame"))
7
+ return escapeHtml(fig.title ?? fig.file);
8
+ const url = `/api/figure-preview?file=${encodeURIComponent(fig.file)}${label === undefined ? "" : `&label=${encodeURIComponent(label)}`}`;
9
+ return `<div class="figure-placeholder" data-figure-preview="${escapeHtml(url)}"><span>${escapeHtml(label || fig.title || fig.file)}</span><button type="button" data-i18n="Load preview">Load preview</button><span role="status"></span></div>`;
10
+ };
11
+ /** Delegated so previews inserted by navigation or HMR use the same loading state. */
12
+ export function mountFigurePreviews() {
13
+ document.addEventListener("click", async (event) => {
14
+ const button = event.target instanceof Element
15
+ ? event.target.closest("[data-figure-preview] > button")
16
+ : null;
17
+ const host = button?.parentElement;
18
+ const url = host?.dataset.figurePreview;
19
+ const status = host?.querySelector('[role="status"]');
20
+ if (!button || !host || !url || !status)
21
+ return;
22
+ const translate = (key) => window.__docsTranslate?.(key) ?? key;
23
+ button.disabled = true;
24
+ host.setAttribute("aria-busy", "true");
25
+ status.textContent = translate("Loading");
26
+ try {
27
+ const response = await fetch(url);
28
+ if (!response.ok)
29
+ throw new Error(translate("Preview unavailable"));
30
+ const html = await response.text();
31
+ if (!host.isConnected)
32
+ return;
33
+ const focused = document.activeElement === button;
34
+ host.innerHTML = html;
35
+ host.classList.remove("figure-placeholder");
36
+ delete host.dataset.figurePreview;
37
+ if (focused) {
38
+ host.tabIndex = -1;
39
+ host.focus({ preventScroll: true });
40
+ }
41
+ }
42
+ catch (error) {
43
+ if (!host.isConnected)
44
+ return;
45
+ status.textContent = error instanceof Error ? error.message : String(error);
46
+ button.textContent = translate("Retry");
47
+ button.dataset.i18n = "Retry";
48
+ }
49
+ finally {
50
+ button.disabled = false;
51
+ host.removeAttribute("aria-busy");
52
+ }
53
+ });
54
+ }
@@ -46,8 +46,12 @@ export const mountFontPickers = async (createSettings, registered) => {
46
46
  const names = choices();
47
47
  for (const button of document.querySelectorAll("[data-font-picker]")) {
48
48
  const kind = target(button);
49
+ const name = names.get(settings.selected[kind]) ?? t("Default font");
50
+ const valueLabel = button.querySelector("[data-picker-value]");
51
+ if (valueLabel && valueLabel.textContent !== name)
52
+ valueLabel.textContent = name;
49
53
  button.disabled = busy;
50
- button.title = `${t(kind === "editor" ? "Editor font" : "Viewer font")}: ${names.get(settings.selected[kind]) ?? t("Default font")}`;
54
+ button.title = `${t(kind === "editor" ? "Editor font" : "Viewer font")}: ${name}`;
51
55
  button.setAttribute("aria-label", button.title);
52
56
  button.setAttribute("aria-controls", popup.id);
53
57
  button.setAttribute("popovertarget", popup.id);
@@ -1,3 +1,6 @@
1
+ import type { SubformatCollection } from "../core/subformats.js";
2
+ export declare const gitFileChanges: (root: string) => Map<string, "added" | "modified">;
1
3
  /** Compare against HEAD so saving or staging does not clear the editor's changes. */
2
4
  export declare const gitBaseText: (root: string, file: string) => string | null;
3
5
  export declare const gitBaseBody: (root: string, file: string) => string | null;
6
+ export declare const setSubformatChanges: (root: string, collections: SubformatCollection[]) => void;
@@ -1,6 +1,32 @@
1
1
  import { execFileSync } from "node:child_process";
2
+ import { isDeepStrictEqual } from "node:util";
2
3
  import { parseDoc } from "../compiler/dialect.js";
4
+ import { parseManifestText } from "../compiler/manifest.js";
3
5
  import { textfilePath } from "../compiler/textfile.js";
6
+ import { MANIFEST_FILE } from "../core/content-metadata.js";
7
+ import { parseGitChanges } from "./git.js";
8
+ export const gitFileChanges = (root) => {
9
+ const changes = new Map();
10
+ const git = (...args) => execFileSync("git", ["--no-optional-locks", "-C", root, ...args], {
11
+ encoding: "utf8",
12
+ stdio: ["ignore", "pipe", "ignore"],
13
+ timeout: 2_000,
14
+ maxBuffer: 5_000_000,
15
+ });
16
+ try {
17
+ const prefix = git("rev-parse", "--show-prefix").trim();
18
+ const status = git("status", "--porcelain=v1", "-z", "--untracked-files=all", "--no-renames", "--", ".");
19
+ for (const change of parseGitChanges(status)) {
20
+ if (!change.path.startsWith(prefix))
21
+ continue;
22
+ changes.set(change.path.slice(prefix.length), /[?A]/.test(change.index + change.worktree) ? "added" : "modified");
23
+ }
24
+ }
25
+ catch {
26
+ // Git metadata is optional; unavailable repositories keep neutral cards.
27
+ }
28
+ return changes;
29
+ };
4
30
  /** Compare against HEAD so saving or staging does not clear the editor's changes. */
5
31
  export const gitBaseText = (root, file) => {
6
32
  const git = (...args) => execFileSync("git", ["-C", root, ...args], {
@@ -31,3 +57,24 @@ export const gitBaseBody = (root, file) => {
31
57
  const raw = gitBaseText(root, file);
32
58
  return raw === null ? null : parseDoc(raw).body;
33
59
  };
60
+ export const setSubformatChanges = (root, collections) => {
61
+ const changes = gitFileChanges(root);
62
+ const raw = gitBaseText(root, MANIFEST_FILE);
63
+ const base = raw === null ? undefined : parseManifestText(raw);
64
+ for (const collection of collections) {
65
+ const previous = base?.subformats?.find((item) => item.ext === collection.ext);
66
+ collection.baseLayouts =
67
+ base && !base.errors.length ? (previous?.layouts ?? {}) : undefined;
68
+ collection.change =
69
+ base && !base.errors.length && !previous
70
+ ? "added"
71
+ : previous &&
72
+ (previous.format !== collection.format ||
73
+ previous.schema !== collection.schema ||
74
+ !isDeepStrictEqual(previous.layouts ?? {}, collection.layouts ?? {}))
75
+ ? "modified"
76
+ : changes.get(collection.schema);
77
+ for (const record of collection.records)
78
+ record.change = changes.get(record.file);
79
+ }
80
+ };
@@ -20,6 +20,7 @@ import { textfilePath } from "../compiler/textfile.js";
20
20
  import { MANIFEST_FILE } from "../core/content-metadata.js";
21
21
  import { isRemoteTextfile } from "../core/textfile.js";
22
22
  import { prebuilt } from "./assets.js";
23
+ import { updateNav } from "./nav-update.js";
23
24
  import { gitHeadFile } from "./workspace.js";
24
25
  /** SSE endpoint. SoT for the server route and the client script's connection target. */
25
26
  export const HMR_PATH = "/api/hmr";
@@ -37,6 +38,7 @@ export const classifyChange = (rel) => {
37
38
  if (p === "src/viewer/edit-client.ts" ||
38
39
  p === "src/viewer/files-ui.ts" ||
39
40
  p === "src/viewer/resource-library-ui.ts" ||
41
+ p === "src/viewer/subformats-ui.ts" ||
40
42
  p === "src/viewer/edit-code-file.ts" ||
41
43
  p === "src/core/code-file.ts" ||
42
44
  p === "src/core/files.ts" ||
@@ -55,6 +57,7 @@ export const classifyChange = (rel) => {
55
57
  p === "src/viewer/edit-code-highlight.ts" ||
56
58
  p === "src/viewer/edit-git-diff.ts" ||
57
59
  p === "src/viewer/code-tokens.ts" ||
60
+ p === "src/viewer/code-worker.ts" ||
58
61
  p === "src/viewer/i18n.ts" ||
59
62
  p === "src/viewer/language-picker.ts" ||
60
63
  p === "src/viewer/theme-picker.ts" ||
@@ -67,6 +70,7 @@ export const classifyChange = (rel) => {
67
70
  p === "src/viewer/preview-update.ts" ||
68
71
  p === "src/plugins/view.ts" ||
69
72
  p === "src/viewer/nav-focus.ts" ||
73
+ p === "src/viewer/nav-update.ts" ||
70
74
  p === "src/viewer/code-highlight.ts" ||
71
75
  (p.startsWith("src/viewer/locales/") && p.endsWith(".json")) ||
72
76
  (p.startsWith("src/core/") && p.endsWith(".tsx"))) {
@@ -279,7 +283,7 @@ export const hmrClientScript = (mode) => `
279
283
  const main = document.querySelector("main");
280
284
  const nextMain = next.querySelector("main");
281
285
  if (!main || !nextMain) { reload(); return; }
282
- const y = window.scrollY;
286
+ const y = main.scrollTop;
283
287
  document.title = next.title;
284
288
  const title = document.getElementById("site-title");
285
289
  const nextTitle = next.getElementById("site-title");
@@ -296,10 +300,10 @@ export const hmrClientScript = (mode) => `
296
300
  const nav = document.getElementById("nav-groups");
297
301
  const nextNav = next.getElementById("nav-groups");
298
302
  if (nav && nextNav) {
299
- nav.innerHTML = nextNav.innerHTML;
303
+ (${updateNav.toString()})(nav, nextNav.innerHTML);
300
304
  if (window.__docsNavRestore) window.__docsNavRestore();
301
305
  }
302
- window.scrollTo(0, y);
306
+ main.scrollTo(0, y);
303
307
  };
304
308
 
305
309
  // Notification hooks for the edit client (src/viewer/edit-client.ts). edit-client.ts may run
@@ -321,7 +325,7 @@ export const hmrClientScript = (mode) => `
321
325
  });
322
326
  es.addEventListener("change", (ev) => {
323
327
  const { kind, files } = JSON.parse(ev.data);
324
- if (MODE === "preview") { if (kind === "content") void swap(); return; }
328
+ if (MODE === "preview" && kind === "content") { void swap(); return; }
325
329
  if (kind === "content") {
326
330
  const onContent = window.__docsHmr && window.__docsHmr.onContent;
327
331
  // If registered, leave it to the in-place update and don't reload (the editor swaps
@@ -1,5 +1,5 @@
1
1
  import { iso6393To1 } from "iso-639-3";
2
- import { mountLanguagePickers } from "./language-picker.js";
2
+ import { mountSelectPickers } from "./language-picker.js";
3
3
  import eng from "./locales/eng.json" with { type: "json" };
4
4
  import jpn from "./locales/jpn.json" with { type: "json" };
5
5
  import zho from "./locales/zho.json" with { type: "json" };
@@ -25,9 +25,11 @@ export const applyUiLanguage = () => {
25
25
  const marker = attr === "text" ? "data-i18n" : `data-i18n-${attr}`;
26
26
  for (const element of document.querySelectorAll(`[${marker}]`)) {
27
27
  const value = t(element.getAttribute(marker) ?? "");
28
- if (attr === "text")
29
- element.textContent = value;
30
- else
28
+ if (attr === "text") {
29
+ if (element.textContent !== value)
30
+ element.textContent = value;
31
+ }
32
+ else if (element.getAttribute(attr) !== value)
31
33
  element.setAttribute(attr, value);
32
34
  }
33
35
  }
@@ -61,5 +63,5 @@ export const mountUiLanguage = () => {
61
63
  }
62
64
  });
63
65
  document.addEventListener("docs:ui-refresh", applyUiLanguage);
64
- mountLanguagePickers(t);
66
+ mountSelectPickers(t);
65
67
  };
@@ -1,2 +1,2 @@
1
- /** Keep the native select as the language enum and change-event source. */
2
- export declare const mountLanguagePickers: (t: (key: string) => string) => void;
1
+ /** Keep the native select as the value and change-event source. */
2
+ export declare const mountSelectPickers: (t: (key: string) => string, selects?: Iterable<HTMLSelectElement>) => (() => void);
@@ -1,6 +1,7 @@
1
- /** Keep the native select as the language enum and change-event source. */
2
- export const mountLanguagePickers = (t) => {
3
- for (const select of document.querySelectorAll("#fm-lang, #ui-language")) {
1
+ /** Keep the native select as the value and change-event source. */
2
+ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-lang, #ui-language")) => {
3
+ const disposers = [];
4
+ for (const select of selects) {
4
5
  const translations = select.id === "fm-lang";
5
6
  const trigger = select
6
7
  .closest(".fm-language")
@@ -115,7 +116,7 @@ export const mountLanguagePickers = (t) => {
115
116
  if (trigger)
116
117
  trigger.disabled = select.disabled;
117
118
  input.setAttribute("aria-disabled", String(select.disabled));
118
- input.placeholder = t("Search languages");
119
+ input.placeholder = select.dataset.placeholder ?? t("Search languages");
119
120
  input.setAttribute("aria-label", select.getAttribute("aria-label") ?? t("Language"));
120
121
  if (translations)
121
122
  input.setAttribute("aria-description", t("Enter to edit; Ctrl+Enter to add or remove translation"));
@@ -213,21 +214,37 @@ export const mountLanguagePickers = (t) => {
213
214
  !(event.relatedTarget instanceof Node && wrapper.contains(event.relatedTarget)))
214
215
  popup.hidePopover();
215
216
  });
216
- document.addEventListener("pointerdown", (event) => {
217
+ const outside = (event) => {
217
218
  if (isOpen() && event.target instanceof Node && !wrapper.contains(event.target))
218
219
  popup.hidePopover();
219
- });
220
- new ResizeObserver(() => {
220
+ };
221
+ document.addEventListener("pointerdown", outside);
222
+ const resize = new ResizeObserver(() => {
221
223
  if (isOpen())
222
224
  position();
223
- }).observe(input);
225
+ });
226
+ resize.observe(input);
224
227
  select.addEventListener("change", sync);
225
- new MutationObserver(sync).observe(select, {
228
+ const observer = new MutationObserver(sync);
229
+ observer.observe(select, {
226
230
  childList: true,
227
231
  subtree: true,
228
232
  attributes: true,
229
233
  });
230
234
  document.addEventListener("docs:ui-language", sync);
235
+ disposers.push(() => {
236
+ document.removeEventListener("pointerdown", outside);
237
+ document.removeEventListener("docs:ui-language", sync);
238
+ select.removeEventListener("change", sync);
239
+ resize.disconnect();
240
+ observer.disconnect();
241
+ wrapper.replaceWith(select);
242
+ select.hidden = false;
243
+ });
231
244
  sync();
232
245
  }
246
+ return () => {
247
+ for (const dispose of disposers)
248
+ dispose();
249
+ };
233
250
  };
@@ -0,0 +1,2 @@
1
+ /** Load enhancement scripts only when their content is near the viewport. */
2
+ export declare const loadPreviewScript: (src: string, selector: string, type?: string) => void;