@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
@@ -21,11 +21,15 @@ export const siteIconResponse = (root, input) => {
21
21
  const manifest = parseManifestText(raw ?? "[]");
22
22
  if (manifest.errors.length)
23
23
  return { status: 409, body: { error: manifest.errors.join("\n") } };
24
- const file = manifest.icon ??
24
+ const theme = input?.theme ?? "light";
25
+ if (theme !== "light" && theme !== "dark")
26
+ throw new Error("Expected a light or dark theme");
27
+ const file = (manifest.format === "nested" ? manifest.themeIcons?.[theme] : manifest.icon) ??
25
28
  (manifest.files?.defaultLayout !== false
26
- ? defaultFilePath("_site.svg")
27
- : `${ICONS_DIR}/_site.svg`);
28
- if (!manifest.icon && existsSync(textfilePath(root, file)))
29
+ ? defaultFilePath(manifest.format === "nested" ? `_site-${theme}.svg` : "_site.svg")
30
+ : `${ICONS_DIR}/_site${manifest.format === "nested" ? `-${theme}` : ""}.svg`);
31
+ const configured = manifest.format === "nested" ? manifest.themeIcons?.[theme] : manifest.icon;
32
+ if (!configured && existsSync(textfilePath(root, file)))
29
33
  return {
30
34
  status: 409,
31
35
  body: { error: `${file} already exists; set dooc.yaml's icon to use it` },
@@ -33,12 +37,15 @@ export const siteIconResponse = (root, input) => {
33
37
  const base = existsSync(textfilePath(root, file)) ? readTextfile(root, file) : null;
34
38
  if (!writeTextfile(root, file, svg, base))
35
39
  return { status: 409, body: { error: "Icon changed externally. Try again." } };
36
- if (!manifest.icon) {
40
+ if (!configured) {
37
41
  const parsed = parseDocument(raw ?? "docs: []\n");
38
42
  const document = isSeq(parsed.contents) || parsed.contents == null
39
43
  ? new Document({ docs: parsed.toJS() ?? [] })
40
44
  : parsed;
41
- document.set("icon", file);
45
+ if (manifest.format === "nested")
46
+ document.setIn(["left_sidebar", "icon", theme], file);
47
+ else
48
+ document.set("icon", file);
42
49
  if (!writeTextfile(root, MANIFEST_FILE, document.toString(), raw))
43
50
  return { status: 409, body: { error: "Manifest changed externally. Try again." } };
44
51
  }
@@ -2,6 +2,7 @@ import { Document, isSeq, parseDocument } from "yaml";
2
2
  import { parseManifestText } from "../compiler/manifest.js";
3
3
  import { readTextfile, writeTextfile } from "../compiler/textfile.js";
4
4
  import { MANIFEST_FILE } from "../core/content-metadata.js";
5
+ import { contentLanguageCode, DEFAULT_LANG } from "../core/language.js";
5
6
  export const siteTitleResponse = (root, input) => {
6
7
  if (typeof input?.title !== "string" ||
7
8
  !input.title.trim() ||
@@ -14,7 +15,12 @@ export const siteTitleResponse = (root, input) => {
14
15
  const manifest = parseManifestText(raw);
15
16
  if (manifest.errors.length)
16
17
  return { status: 409, body: { error: manifest.errors.join("\n") } };
17
- if ((manifest.title ?? null) !== input.baseTitle)
18
+ const language = contentLanguageCode(typeof input.language === "string"
19
+ ? input.language
20
+ : (manifest.defaultLang ?? DEFAULT_LANG));
21
+ if (manifest.languages && !manifest.languages.includes(language))
22
+ throw new Error("Language is not declared in system.languages");
23
+ if ((manifest.titles?.[language] ?? manifest.title ?? null) !== input.baseTitle)
18
24
  return { status: 409, body: { error: "Site title changed externally. Try again." } };
19
25
  const parsed = parseDocument(raw);
20
26
  const document = isSeq(parsed.contents) || parsed.contents == null
@@ -23,7 +29,14 @@ export const siteTitleResponse = (root, input) => {
23
29
  if (document !== parsed)
24
30
  document.commentBefore = parsed.commentBefore;
25
31
  const title = input.title.trim();
26
- document.set("title", title);
32
+ if (manifest.format === "nested") {
33
+ const titles = document.toJS().left_sidebar?.title ?? {};
34
+ const key = Object.keys(titles).find((tag) => contentLanguageCode(tag) === language) ??
35
+ language;
36
+ document.setIn(["left_sidebar", "title", key], title);
37
+ }
38
+ else
39
+ document.set("title", title);
27
40
  if (!writeTextfile(root, MANIFEST_FILE, document.toString(), raw))
28
41
  return { status: 409, body: { error: "Manifest changed externally. Try again." } };
29
42
  return { status: 200, body: { title } };
@@ -1,3 +1,4 @@
1
+ import type { SchemaContext } from "../core/schema-refs.js";
1
2
  export declare const previewTextfiles: (root: string, input: unknown) => ReadonlyMap<string, string>;
2
3
  export declare const textfileResponse: (root: string, input: Record<string, unknown> | undefined, domains?: readonly string[]) => Promise<{
3
4
  status: number;
@@ -5,5 +6,9 @@ export declare const textfileResponse: (root: string, input: Record<string, unkn
5
6
  content?: string | null;
6
7
  error?: string;
7
8
  gitBase?: string | null;
9
+ language?: string;
10
+ schema?: object;
11
+ schemaDocument?: boolean;
12
+ schemaContext?: SchemaContext;
8
13
  };
9
14
  }>;
@@ -1,4 +1,6 @@
1
- import { readTextfileAsync, textfilePath, writeTextfile } from "../compiler/textfile.js";
1
+ import { readManifest } from "../compiler/manifest.js";
2
+ import { compileSubformatSchema, isSubformatSchemaFile, validateSubformatFile, } from "../compiler/subformats.js";
3
+ import { readTextfile, readTextfileAsync, textfilePath, writeTextfile, } from "../compiler/textfile.js";
2
4
  import { TextfileUnavailable } from "../compiler/textfile-remote.js";
3
5
  import { isRemoteTextfile } from "../core/textfile.js";
4
6
  export const previewTextfiles = (root, input) => {
@@ -25,6 +27,7 @@ export const textfileResponse = async (root, input, domains = []) => {
25
27
  if (typeof input.content !== "string" ||
26
28
  (input.base !== null && typeof input.base !== "string"))
27
29
  return { status: 400, body: { error: "Content and original text are required" } };
30
+ validateSubformatFile(root, input.file, input.content, domains);
28
31
  if (!writeTextfile(root, input.file, input.content, input.base))
29
32
  return {
30
33
  status: 409,
@@ -32,9 +35,38 @@ export const textfileResponse = async (root, input, domains = []) => {
32
35
  };
33
36
  return { status: 200, body: { content: input.content } };
34
37
  }
38
+ const configs = isRemoteTextfile(input.file) ? [] : (readManifest(root).subformats ?? []);
39
+ const extension = input.file.split(".").at(-1);
40
+ const format = configs.find((config) => config.ext === extension);
41
+ const compiled = format
42
+ ? compileSubformatSchema(readTextfile(root, format.schema), {
43
+ root,
44
+ file: format.schema,
45
+ domains,
46
+ })
47
+ : undefined;
48
+ const content = await readTextfileAsync(root, input.file, true, domains).catch((error) => {
49
+ if (error.code === "ENOENT" ||
50
+ (error instanceof TextfileUnavailable && error.reason === "missing"))
51
+ return null;
52
+ throw error;
53
+ });
35
54
  return {
36
55
  status: 200,
37
- body: { content: await readTextfileAsync(root, input.file, true, domains) },
56
+ body: {
57
+ content,
58
+ ...(format
59
+ ? {
60
+ language: format.format,
61
+ schema: compiled?.schema,
62
+ schemaContext: compiled?.context,
63
+ }
64
+ : {}),
65
+ ...(!isRemoteTextfile(input.file) &&
66
+ isSubformatSchemaFile(root, input.file, domains)
67
+ ? { schemaDocument: true }
68
+ : {}),
69
+ },
38
70
  };
39
71
  }
40
72
  catch (error) {
@@ -1,2 +1,4 @@
1
+ /** Run in the head before any themed content can be painted. */
2
+ export declare const initializeThemes: (themes?: string[]) => void;
1
3
  /** Self-contained because published viewers embed this function directly. */
2
4
  export declare const mountThemePickers: (icons: Record<string, string>, themes?: string[]) => void;
@@ -1,7 +1,6 @@
1
- /** Self-contained because published viewers embed this function directly. */
2
- export const mountThemePickers = (icons, themes = ["light", "dark"]) => {
1
+ /** Run in the head before any themed content can be painted. */
2
+ export const initializeThemes = (themes = ["light", "dark"]) => {
3
3
  const root = document.documentElement;
4
- const documentChoices = themes.length === 1 ? themes : ["auto", ...themes];
5
4
  const read = (key) => {
6
5
  try {
7
6
  const value = localStorage.getItem(key);
@@ -11,11 +10,20 @@ export const mountThemePickers = (icons, themes = ["light", "dark"]) => {
11
10
  return "auto";
12
11
  }
13
12
  };
14
- let documentDefault = read("docs-preview:theme");
13
+ const stored = read("docs-preview:theme");
14
+ root.dataset.theme =
15
+ themes.length === 1 ? (themes[0] ?? "auto") : themes.includes(stored) ? stored : "auto";
16
+ root.dataset.editorTheme = read("docs-editor:theme");
17
+ };
18
+ /** Self-contained because published viewers embed this function directly. */
19
+ export const mountThemePickers = (icons, themes = ["light", "dark"]) => {
20
+ const root = document.documentElement;
21
+ const documentChoices = themes.length === 1 ? themes : ["auto", ...themes];
22
+ let documentDefault = root.dataset.theme ?? "auto";
15
23
  if (!documentChoices.includes(documentDefault))
16
24
  documentDefault = documentChoices[0] ?? "auto";
17
25
  root.dataset.theme = documentDefault;
18
- root.dataset.editorTheme = read("docs-editor:theme");
26
+ root.dataset.editorTheme ??= "auto";
19
27
  const t = (key) => window.__docsTranslate?.(key) ??
20
28
  key;
21
29
  const popup = document.createElement("div");
@@ -32,7 +40,7 @@ export const mountThemePickers = (icons, themes = ["light", "dark"]) => {
32
40
  ? (root.dataset.editorTheme ?? "auto")
33
41
  : (target(button).dataset.theme ?? "auto");
34
42
  const sync = () => {
35
- for (const pane of document.querySelectorAll(".resources-pane"))
43
+ for (const pane of document.querySelectorAll(".resources-pane, #sidebar, #panel"))
36
44
  if (pane.dataset.theme !== root.dataset.editorTheme)
37
45
  pane.dataset.theme = root.dataset.editorTheme;
38
46
  for (const pane of document.querySelectorAll(".preview-pane:not(.resources-pane)"))
@@ -41,12 +49,20 @@ export const mountThemePickers = (icons, themes = ["light", "dark"]) => {
41
49
  for (const button of document.querySelectorAll("[data-theme-picker]")) {
42
50
  const value = current(button);
43
51
  const markup = icons[value === "auto" ? "" : value] ?? "";
52
+ const valueLabel = button.querySelector("[data-picker-value]");
44
53
  if (button.dataset.themeIcon !== value) {
45
- button.innerHTML = markup;
54
+ const icon = valueLabel
55
+ ? button.closest(".editor-setting")?.querySelector("[data-setting-theme-icon]")
56
+ : button;
57
+ if (icon)
58
+ icon.innerHTML = markup;
46
59
  button.dataset.themeIcon = value;
47
60
  }
61
+ const name = t(value === "auto" ? "Auto" : value === "light" ? "Light" : "Dark");
62
+ if (valueLabel && valueLabel.textContent !== name)
63
+ valueLabel.textContent = name;
48
64
  const label = t(button.dataset.themePicker === "editor" ? "Editor theme" : "Preview theme");
49
- button.title = `${label}: ${t(value === "auto" ? "Auto" : value === "light" ? "Light" : "Dark")}`;
65
+ button.title = `${label}: ${name}`;
50
66
  button.setAttribute("aria-label", button.title);
51
67
  button.setAttribute("aria-haspopup", "menu");
52
68
  button.setAttribute("aria-controls", popup.id);
@@ -2,3 +2,5 @@ import type { WorkspaceSource } from "../core/workspace.js";
2
2
  export declare const gitHeadFile: (root: string) => string | undefined;
3
3
  /** Read only local metadata; no Git commands, credentials or network access are needed. */
4
4
  export declare const readWorkspaceSource: (root: string) => WorkspaceSource;
5
+ /** Resolve source links locally; published HTML must not depend on Git or the build directory. */
6
+ export declare const sourceFileBase: (root: string, sourceUrl?: string) => string;
@@ -1,5 +1,6 @@
1
+ import { execFileSync } from "node:child_process";
1
2
  import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
2
- import { basename, dirname, join, resolve } from "node:path";
3
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
3
4
  /** Git worktrees use a .git file pointing at their own metadata directory. */
4
5
  const gitMetadata = (root) => {
5
6
  let directory = realpathSync(root);
@@ -45,3 +46,47 @@ export const readWorkspaceSource = (root) => {
45
46
  }
46
47
  return { protocol: "storage", folder: basename(resolve(root)) || root, service: "Local" };
47
48
  };
49
+ /** Resolve source links locally; published HTML must not depend on Git or the build directory. */
50
+ export const sourceFileBase = (root, sourceUrl) => {
51
+ if (sourceUrl !== undefined) {
52
+ const url = new URL(sourceUrl);
53
+ if (!["https:", "http:"].includes(url.protocol) ||
54
+ url.username ||
55
+ url.password ||
56
+ url.search ||
57
+ url.hash)
58
+ throw new Error("Source URL must be an HTTP(S) directory URL without credentials, query or fragment");
59
+ url.pathname = `${url.pathname.replace(/\/+$/, "")}/`;
60
+ return url.href;
61
+ }
62
+ const directory = realpathSync(root);
63
+ const metadata = gitMetadata(directory);
64
+ const workspace = readWorkspaceSource(directory);
65
+ const prefix = metadata ? relative(metadata.directory, directory).split(sep).join("/") : "";
66
+ const fallback = `${[
67
+ workspace.protocol === "git" ? workspace.repo : basename(metadata?.directory ?? directory),
68
+ prefix,
69
+ ]
70
+ .filter(Boolean)
71
+ .join("/")}/`;
72
+ if (!metadata)
73
+ return fallback;
74
+ try {
75
+ const git = (...args) => execFileSync("git", ["-C", directory, ...args], {
76
+ encoding: "utf8",
77
+ stdio: ["ignore", "pipe", "ignore"],
78
+ timeout: 2_000,
79
+ }).trim();
80
+ const remote = new URL(git("config", "--get", "remote.origin.url").replace(/^git@github\.com:/, "https://github.com/"));
81
+ const repository = /^\/([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/.exec(remote.pathname);
82
+ if (remote.hostname !== "github.com" || !repository)
83
+ return fallback;
84
+ const head = git("rev-parse", "HEAD");
85
+ if (!/^(?:[a-f\d]{40}|[a-f\d]{64})$/i.test(head))
86
+ return fallback;
87
+ return `https://github.com/${repository[1]}/${repository[2]}/blob/${head}/${prefix ? `${prefix.split("/").map(encodeURIComponent).join("/")}/` : ""}`;
88
+ }
89
+ catch {
90
+ return fallback;
91
+ }
92
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooc-dev/dooc",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "View and edit source files with dooc.yaml configuration, and share them as source ZIPs or standalone HTML.",
5
5
  "type": "module",
6
6
  "files": [
@@ -30,7 +30,15 @@
30
30
  "types": "./dist/core/schema-graph-mount.d.ts",
31
31
  "default": "./dist/core/schema-graph-mount.js"
32
32
  },
33
- "./flow.global.js": "./dist/flow.global.js"
33
+ "./flow.global.js": "./dist/flow.global.js",
34
+ "./build": {
35
+ "types": "./dist/viewer/build.d.ts",
36
+ "default": "./dist/viewer/build.js"
37
+ },
38
+ "./export": {
39
+ "types": "./dist/compiler/export.d.ts",
40
+ "default": "./dist/compiler/export.js"
41
+ }
34
42
  },
35
43
  "peerDependencies": {
36
44
  "@xyflow/react": ">=12",
@@ -54,19 +62,19 @@
54
62
  },
55
63
  "scripts": {
56
64
  "build:plugin": "node -e \"require('node:fs').rmSync('packages/dooc-plugin/dist', {recursive:true, force:true})\" && tsc -p tsconfig.plugin.json",
57
- "test:plugin-package": "node --import tsx scripts/test-plugin-package.mjs",
65
+ "test:plugin-package": "node --import tsx scripts/test/plugin-package.mjs",
58
66
  "build": "node -e \"require('node:fs').rmSync('dist', {recursive:true, force:true})\" && pnpm run build:css && pnpm run build:fonts && tsc -p tsconfig.build.json && pnpm run build:flow && pnpm run build:edit",
59
- "build:binary": "bun scripts/build-binary.mjs",
60
- "build:css": "node --import tsx src/core/build-flow-css.ts",
61
- "build:flow": "esbuild src/core/schema-graph-global.tsx --bundle --format=iife --target=es2022 --minify --outfile=dist/flow.global.js",
62
- "build:edit": "esbuild src/viewer/edit-client.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/edit.global.js && esbuild src/viewer/ui-client.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/ui.global.js && esbuild src/viewer/code-highlight.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/code.global.js",
67
+ "build:binary": "bun scripts/build/binary.mjs",
68
+ "build:css": "node --import tsx scripts/build/flow-css.ts",
69
+ "build:flow": "esbuild src/core/schema-graph-global.tsx --bundle --format=iife --target=es2022 --minify --outfile=dist/flow.global.js && esbuild src/core/schema-graph-global.tsx --bundle --splitting --format=esm --target=es2022 --minify --outdir=dist/graph",
70
+ "build:edit": "esbuild src/viewer/edit-client.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/edit.global.js && esbuild src/viewer/ui-client.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/ui.global.js && esbuild src/viewer/code-highlight.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/code.global.js && esbuild src/viewer/code-worker.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/code-worker.global.js && esbuild src/viewer/published-plugins.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/plugins.global.js && esbuild src/viewer/published-subformats.ts --bundle --format=iife --target=es2022 --minify --outfile=dist/subformats.global.js",
63
71
  "test": "vitest run",
64
- "test:binary": "node scripts/test-binary.mjs",
65
- "test:install": "node scripts/test-install.mjs",
72
+ "test:binary": "node scripts/test/binary.mjs",
73
+ "test:install": "node scripts/test/install.mjs",
66
74
  "check": "biome check . && tsc --noEmit && pnpm run build && vitest run && pnpm run test:install && pnpm run test:plugin-package",
67
75
  "fix": "biome check --write .",
68
76
  "build:fonts": "node -e \"require('node:fs').cpSync('src/viewer/fonts', 'dist/viewer/fonts', {recursive:true})\"",
69
- "build:sample-extension": "node --import tsx scripts/build-sample-extension.mjs"
77
+ "build:sample-extension": "node --import tsx scripts/build/sample-extension.mjs"
70
78
  },
71
79
  "devDependencies": {
72
80
  "@biomejs/biome": "2.4.15",
@@ -81,6 +89,7 @@
81
89
  "@lezer/common": "^1.5.4",
82
90
  "@lezer/highlight": "^1.2.5",
83
91
  "@shikijs/themes": "^4.5.0",
92
+ "@types/dxf": "4.6.10",
84
93
  "@types/mdast": "^4.0.4",
85
94
  "@types/node": "^22.10.0",
86
95
  "@types/react": "^19.2.17",
@@ -101,7 +110,11 @@
101
110
  "@textlint/kernel": "^15.8.0",
102
111
  "@textlint/module-interop": "^15.8.0",
103
112
  "@textlint/textlint-plugin-markdown": "^15.8.0",
113
+ "ajv": "8.20.0",
114
+ "ajv-formats": "3.0.1",
115
+ "dxf": "5.3.1",
104
116
  "franc": "^6.2.0",
117
+ "ignore": "^7.0.14",
105
118
  "iso-639-3": "^3.0.1",
106
119
  "mermaid": "^12.3.0",
107
120
  "parse5": "8.0.0",
@@ -112,10 +125,14 @@
112
125
  "remark-parse": "^11.0.0",
113
126
  "remark-stringify": "11.0.0",
114
127
  "shiki": "^4.5.0",
128
+ "smol-toml": "1.9.1",
115
129
  "string-width": "4.2.3",
116
130
  "textlint-rule-preset-ja-technical-writing": "^12.0.2",
131
+ "toml-eslint-parser": "^0.10.0",
117
132
  "unified": "^11.0.5",
118
133
  "unist-util-visit": "^5.0.0",
134
+ "vscode-json-languageservice": "5.7.2",
135
+ "vscode-languageserver-textdocument": "1.0.16",
119
136
  "yaml": "^2.7.0"
120
137
  },
121
138
  "repository": {
@@ -1,2 +0,0 @@
1
- import type { ZipEntry } from "./zip.js";
2
- export declare const bundleEntries: (root: string) => ZipEntry[];
@@ -1,100 +0,0 @@
1
- // A bundle contains dooc.yaml and its managed source files, assets and local configuration.
2
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
3
- import { join, posix } from "node:path";
4
- import { MANIFEST_FILE } from "../core/content-metadata.js";
5
- import { isRemoteTextfile } from "../core/textfile.js";
6
- import { CODE_LANGUAGES_DIR } from "./code-languages.js";
7
- import { CONFIG_FILE } from "./config.js";
8
- import { collectRefs, parseDoc } from "./dialect.js";
9
- import { projectFiles } from "./files.js";
10
- import { PROJECT_FONTS_DIR } from "./fonts.js";
11
- import { readManifest } from "./manifest.js";
12
- import { readTextfile, textfilePath } from "./textfile.js";
13
- const LAYOUT_DIRS = [
14
- "content",
15
- "figures",
16
- "icons",
17
- "locales",
18
- "themes",
19
- ".dooc/editor-tools",
20
- PROJECT_FONTS_DIR,
21
- ];
22
- export const bundleEntries = (root) => {
23
- const entries = [
24
- ...[CONFIG_FILE, MANIFEST_FILE]
25
- .filter((name) => existsSync(join(root, name)))
26
- .map((name) => ({ name, data: readFileSync(join(root, name)) })),
27
- ...(existsSync(join(root, CODE_LANGUAGES_DIR))
28
- ? readdirSync(join(root, CODE_LANGUAGES_DIR))
29
- .filter((file) => !file.startsWith(".") &&
30
- file.endsWith(".json") &&
31
- statSync(join(root, CODE_LANGUAGES_DIR, file)).isFile())
32
- .sort()
33
- .map((file) => ({
34
- name: `${CODE_LANGUAGES_DIR}/${file}`,
35
- data: readFileSync(join(root, CODE_LANGUAGES_DIR, file)),
36
- }))
37
- : []),
38
- ...LAYOUT_DIRS.filter((dir) => existsSync(join(root, dir))).flatMap((dir) => readdirSync(join(root, dir), { recursive: true, encoding: "utf8" })
39
- .filter((rel) => !rel
40
- .replaceAll("\\", "/")
41
- .split("/")
42
- .some((seg) => seg.startsWith(".")))
43
- .map((rel) => `${dir}/${rel.replaceAll("\\", "/")}`)
44
- .filter((name) => statSync(join(root, name)).isFile())
45
- .sort()
46
- .map((name) => ({ name, data: readFileSync(textfilePath(root, name)) }))),
47
- ];
48
- const known = new Set(entries.map((entry) => entry.name));
49
- const layout = readManifest(root).files;
50
- const mapped = new Set([...(layout?.order ?? []), ...Object.values(layout?.documents ?? {})]);
51
- for (const file of projectFiles(root))
52
- if ((file.path.startsWith("files/") || mapped.has(file.path)) && !known.has(file.path))
53
- entries.push({ name: file.path, data: readFileSync(join(root, file.path)) });
54
- const bodies = entries
55
- .filter((entry) => /\.(md|callouth)$/.test(entry.name))
56
- .map((entry) => entry.data.toString("utf8"));
57
- const included = new Set(entries.map((entry) => entry.name));
58
- const { icon } = readManifest(root);
59
- if (icon && !included.has(posix.normalize(icon))) {
60
- const name = posix.normalize(icon);
61
- entries.push({ name, data: Buffer.from(readTextfile(root, icon), "utf8") });
62
- included.add(name);
63
- }
64
- for (const body of bodies) {
65
- const refs = collectRefs(parseDoc(body).root);
66
- for (const file of refs.figures) {
67
- if (included.has(file))
68
- continue;
69
- try {
70
- entries.push({ name: file, data: readFileSync(textfilePath(root, file)) });
71
- included.add(file);
72
- }
73
- catch (error) {
74
- if (error.code !== "ENOENT")
75
- throw error;
76
- }
77
- }
78
- for (const file of [...refs.textfiles, ...refs.terms]) {
79
- if (isRemoteTextfile(file))
80
- continue;
81
- let text;
82
- try {
83
- text = readTextfile(root, file);
84
- }
85
- catch (error) {
86
- if (error.code === "ENOENT")
87
- continue;
88
- throw error;
89
- }
90
- const name = posix.normalize(file);
91
- if (included.has(name))
92
- continue;
93
- entries.push({ name, data: Buffer.from(text, "utf8") });
94
- included.add(name);
95
- if (name.endsWith(".callouth"))
96
- bodies.push(text);
97
- }
98
- }
99
- return entries;
100
- };