@dooc-dev/dooc 0.0.7 → 0.0.8

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 (302) hide show
  1. package/dist/client.global.js +1 -0
  2. package/dist/code-worker.global.js +11 -11
  3. package/dist/code.global.js +75 -75
  4. package/dist/edit.global.js +234 -231
  5. package/dist/{compiler → engine/compiler}/bundle-urls.js +1 -4
  6. package/dist/{compiler → engine/compiler}/check-prose.d.ts +1 -1
  7. package/dist/{compiler → engine/compiler}/check-prose.js +1 -1
  8. package/dist/{compiler → engine/compiler}/check.js +15 -27
  9. package/dist/{compiler → engine/compiler}/code-blocks.js +3 -1
  10. package/dist/{compiler → engine/compiler}/code-languages.js +1 -2
  11. package/dist/{compiler → engine/compiler}/compile.d.ts +5 -4
  12. package/dist/{compiler → engine/compiler}/compile.js +91 -32
  13. package/dist/{compiler → engine/compiler}/config.js +1 -3
  14. package/dist/{compiler → engine/compiler}/dialect.d.ts +1 -3
  15. package/dist/{compiler → engine/compiler}/dialect.js +8 -52
  16. package/dist/{compiler → engine/compiler}/dxf.js +1 -1
  17. package/dist/{compiler → engine/compiler}/export.js +15 -8
  18. package/dist/{compiler → engine/compiler}/figures.js +26 -22
  19. package/dist/{compiler → engine/compiler}/file-cache.d.ts +1 -2
  20. package/dist/{compiler → engine/compiler}/file-cache.js +8 -15
  21. package/dist/{compiler → engine/compiler}/files.js +49 -38
  22. package/dist/{compiler → engine/compiler}/fonts.js +1 -3
  23. package/dist/{compiler → engine/compiler}/from-mdast.js +1 -1
  24. package/dist/engine/compiler/host.d.ts +10 -0
  25. package/dist/engine/compiler/host.js +16 -0
  26. package/dist/{compiler → engine/compiler}/icons.d.ts +3 -0
  27. package/dist/{compiler → engine/compiler}/icons.js +28 -10
  28. package/dist/{compiler → engine/compiler}/ignored-files.d.ts +2 -0
  29. package/dist/{compiler → engine/compiler}/ignored-files.js +12 -3
  30. package/dist/{compiler → engine/compiler}/locales.js +2 -8
  31. package/dist/{compiler → engine/compiler}/manifest.d.ts +3 -2
  32. package/dist/engine/compiler/manifest.js +46 -0
  33. package/dist/{compiler → engine/compiler}/ops.d.ts +4 -1
  34. package/dist/{compiler → engine/compiler}/ops.js +36 -21
  35. package/dist/engine/compiler/schema-file-references.d.ts +2 -0
  36. package/dist/engine/compiler/schema-file-references.js +82 -0
  37. package/dist/engine/compiler/serialize.d.ts +2 -0
  38. package/dist/engine/compiler/serialize.js +5 -0
  39. package/dist/{compiler → engine/compiler}/subformat-schema.js +1 -3
  40. package/dist/{compiler → engine/compiler}/subformats.d.ts +10 -0
  41. package/dist/{compiler → engine/compiler}/subformats.js +122 -18
  42. package/dist/{compiler → engine/compiler}/textfile-remote.js +1 -2
  43. package/dist/{compiler → engine/compiler}/textfile.js +4 -6
  44. package/dist/{compiler → engine/compiler}/theme-variants.js +1 -1
  45. package/dist/{compiler → engine/compiler}/zip.js +1 -1
  46. package/dist/{core → engine/core}/blocks.d.ts +6 -4
  47. package/dist/{core → engine/core}/content-metadata.d.ts +6 -1
  48. package/dist/{core → engine/core}/content-metadata.js +84 -18
  49. package/dist/{core → engine/core}/content-types.d.ts +4 -2
  50. package/dist/{core → engine/core}/html.d.ts +7 -0
  51. package/dist/{core → engine/core}/html.js +44 -3
  52. package/dist/{core → engine/core}/icons.d.ts +3 -0
  53. package/dist/engine/core/icons.js +20 -0
  54. package/dist/{core → engine/core}/routing.d.ts +2 -0
  55. package/dist/{core → engine/core}/routing.js +9 -0
  56. package/dist/{core → engine/core}/schema-refs.d.ts +1 -1
  57. package/dist/{core → engine/core}/schema-refs.js +3 -1
  58. package/dist/engine/core/subformat-references.d.ts +5 -0
  59. package/dist/engine/core/subformat-references.js +33 -0
  60. package/dist/{core → engine/core}/subformats.d.ts +7 -0
  61. package/dist/{core → engine/core}/subformats.js +5 -1
  62. package/dist/{core → engine/core}/taxonomy.d.ts +2 -3
  63. package/dist/{core → engine/core}/taxonomy.js +1 -5
  64. package/dist/flow.global.js +306 -306
  65. package/dist/frontend/application-request.d.ts +14 -0
  66. package/dist/frontend/application-request.js +36 -0
  67. package/dist/frontend/document-application.d.ts +200 -0
  68. package/dist/{viewer/serve.js → frontend/document-application.js} +1611 -1670
  69. package/dist/frontend/figure-preview.d.ts +4 -0
  70. package/dist/{viewer → frontend}/figure-preview.js +4 -4
  71. package/dist/{viewer → frontend}/file-references.d.ts +1 -1
  72. package/dist/{viewer → frontend}/file-references.js +3 -3
  73. package/dist/{viewer → frontend}/font-picker.d.ts +1 -1
  74. package/dist/{viewer → frontend}/font-settings.d.ts +1 -1
  75. package/dist/{viewer → frontend}/language-picker.js +112 -18
  76. package/dist/{viewer → frontend}/locales/eng.json +16 -2
  77. package/dist/{viewer → frontend}/locales/jpn.json +16 -2
  78. package/dist/{viewer → frontend}/locales/zho.json +16 -2
  79. package/dist/{viewer → frontend}/nav-focus.js +2 -0
  80. package/dist/{viewer → frontend}/plugin-blocks.js +2 -2
  81. package/dist/{viewer → frontend}/resize.js +14 -2
  82. package/dist/frontend/resource-download.d.ts +2 -0
  83. package/dist/frontend/resource-download.js +43 -0
  84. package/dist/{viewer → frontend}/resource-library.d.ts +9 -2
  85. package/dist/{viewer → frontend}/resource-library.js +133 -37
  86. package/dist/{core → frontend}/schema-graph-flow.d.ts +1 -1
  87. package/dist/{core → frontend}/schema-graph-flow.js +1 -1
  88. package/dist/{viewer → frontend}/search.d.ts +2 -2
  89. package/dist/{viewer → frontend}/search.js +26 -8
  90. package/dist/graph/schema-graph-global.js +17 -17
  91. package/dist/install.sh +68 -0
  92. package/dist/plugins.global.js +62 -62
  93. package/dist/{viewer → server}/assets.d.ts +2 -0
  94. package/dist/server/assets.js +7 -0
  95. package/dist/{viewer → server}/build-plugins.js +4 -4
  96. package/dist/{viewer → server}/build.d.ts +2 -1
  97. package/dist/{viewer → server}/build.js +31 -15
  98. package/dist/{cli.js → server/cli.js} +199 -66
  99. package/dist/server/editor-tools.d.ts +1 -0
  100. package/dist/server/editor-tools.js +1 -0
  101. package/dist/{viewer → server}/extension-pack.js +2 -2
  102. package/dist/{viewer → server}/extensions.d.ts +1 -1
  103. package/dist/{viewer → server}/extensions.js +3 -3
  104. package/dist/server/git-diff.d.ts +10 -0
  105. package/dist/{viewer → server}/git-diff.js +45 -10
  106. package/dist/server/git-origin.d.ts +4 -0
  107. package/dist/server/git-origin.js +103 -0
  108. package/dist/server/git.d.ts +9 -0
  109. package/dist/{viewer → server}/git.js +50 -6
  110. package/dist/server/history.d.ts +14 -0
  111. package/dist/server/history.js +205 -0
  112. package/dist/{viewer → server}/hmr.d.ts +0 -22
  113. package/dist/server/hmr.js +168 -0
  114. package/dist/server/index.d.ts +17 -0
  115. package/dist/{index.js → server/index.js} +16 -16
  116. package/dist/{viewer → server}/ja-lint.d.ts +1 -1
  117. package/dist/{viewer → server}/languages.d.ts +1 -1
  118. package/dist/{viewer → server}/languages.js +3 -3
  119. package/dist/{mcp.d.ts → server/mcp.d.ts} +2 -2
  120. package/dist/{mcp.js → server/mcp.js} +60 -21
  121. package/dist/{viewer → server}/plugin-config.d.ts +2 -2
  122. package/dist/{viewer → server}/plugin-config.js +2 -2
  123. package/dist/{plugins → server/plugins}/local-storage.d.ts +1 -1
  124. package/dist/{plugins → server/plugins}/local-storage.js +1 -1
  125. package/dist/{plugins → server/plugins}/runtime.d.ts +4 -4
  126. package/dist/{plugins → server/plugins}/runtime.js +4 -4
  127. package/dist/{viewer → server}/plugins.d.ts +3 -3
  128. package/dist/{viewer → server}/plugins.js +14 -13
  129. package/dist/server/resource-library.d.ts +1 -0
  130. package/dist/server/resource-library.js +1 -0
  131. package/dist/server/self.d.ts +5 -0
  132. package/dist/server/self.js +98 -0
  133. package/dist/server/serve.d.ts +61 -0
  134. package/dist/server/serve.js +503 -0
  135. package/dist/server/static-client.d.ts +4 -0
  136. package/dist/server/static-client.js +117 -0
  137. package/dist/server/workspace-server.d.ts +16 -0
  138. package/dist/server/workspace-server.js +266 -0
  139. package/dist/{viewer → server}/workspace.d.ts +6 -1
  140. package/dist/{viewer → server}/workspace.js +46 -0
  141. package/dist/subformats.global.js +92 -6
  142. package/dist/ui.global.js +85 -72
  143. package/dist/workspace/client.d.ts +13 -0
  144. package/dist/workspace/client.js +114 -0
  145. package/dist/{viewer → workspace}/code-file.d.ts +1 -1
  146. package/dist/{viewer → workspace}/code-file.js +7 -7
  147. package/dist/workspace/connection.d.ts +27 -0
  148. package/dist/workspace/connection.js +38 -0
  149. package/dist/{viewer → workspace}/editor-tools.d.ts +7 -1
  150. package/dist/{viewer → workspace}/editor-tools.js +12 -9
  151. package/dist/{viewer → workspace}/git-types.d.ts +7 -0
  152. package/dist/workspace/github.d.ts +4 -0
  153. package/dist/workspace/github.js +99 -0
  154. package/dist/workspace/history.d.ts +46 -0
  155. package/dist/workspace/history.js +86 -0
  156. package/dist/workspace/protocol.d.ts +38 -0
  157. package/dist/workspace/protocol.js +20 -0
  158. package/dist/workspace/resource-download.d.ts +1 -0
  159. package/dist/workspace/resource-download.js +8 -0
  160. package/dist/workspace/server.d.ts +9 -0
  161. package/dist/workspace/server.js +48 -0
  162. package/dist/{viewer → workspace}/site-icon.js +9 -10
  163. package/dist/{viewer → workspace}/site-title.js +6 -7
  164. package/dist/{viewer → workspace}/textfile.d.ts +1 -1
  165. package/dist/{viewer → workspace}/textfile.js +5 -5
  166. package/dist/workspace-worker.global.js +2859 -0
  167. package/package.json +34 -20
  168. package/dist/compiler/manifest.js +0 -37
  169. package/dist/compiler/serialize.d.ts +0 -3
  170. package/dist/compiler/serialize.js +0 -16
  171. package/dist/core/icons.js +0 -5
  172. package/dist/index.d.ts +0 -17
  173. package/dist/viewer/assets.js +0 -3
  174. package/dist/viewer/figure-preview.d.ts +0 -4
  175. package/dist/viewer/git-diff.d.ts +0 -6
  176. package/dist/viewer/git.d.ts +0 -5
  177. package/dist/viewer/hmr.js +0 -341
  178. package/dist/viewer/serve.d.ts +0 -216
  179. /package/dist/{compiler → engine/compiler}/asset-references.d.ts +0 -0
  180. /package/dist/{compiler → engine/compiler}/asset-references.js +0 -0
  181. /package/dist/{compiler → engine/compiler}/bundle-urls.d.ts +0 -0
  182. /package/dist/{compiler → engine/compiler}/check-types.d.ts +0 -0
  183. /package/dist/{compiler → engine/compiler}/check-types.js +0 -0
  184. /package/dist/{compiler → engine/compiler}/check.d.ts +0 -0
  185. /package/dist/{compiler → engine/compiler}/code-blocks.d.ts +0 -0
  186. /package/dist/{compiler → engine/compiler}/code-languages.d.ts +0 -0
  187. /package/dist/{compiler → engine/compiler}/config.d.ts +0 -0
  188. /package/dist/{compiler → engine/compiler}/drawio.d.ts +0 -0
  189. /package/dist/{compiler → engine/compiler}/drawio.js +0 -0
  190. /package/dist/{compiler → engine/compiler}/dxf.d.ts +0 -0
  191. /package/dist/{compiler → engine/compiler}/export.d.ts +0 -0
  192. /package/dist/{compiler → engine/compiler}/figures.d.ts +0 -0
  193. /package/dist/{compiler → engine/compiler}/files.d.ts +0 -0
  194. /package/dist/{compiler → engine/compiler}/fonts.d.ts +0 -0
  195. /package/dist/{compiler → engine/compiler}/format.d.ts +0 -0
  196. /package/dist/{compiler → engine/compiler}/format.js +0 -0
  197. /package/dist/{compiler → engine/compiler}/from-mdast.d.ts +0 -0
  198. /package/dist/{compiler → engine/compiler}/language-codes.d.ts +0 -0
  199. /package/dist/{compiler → engine/compiler}/language-codes.js +0 -0
  200. /package/dist/{compiler → engine/compiler}/locales.d.ts +0 -0
  201. /package/dist/{compiler → engine/compiler}/public-file.d.ts +0 -0
  202. /package/dist/{compiler → engine/compiler}/public-file.js +0 -0
  203. /package/dist/{compiler → engine/compiler}/subformat-schema.d.ts +0 -0
  204. /package/dist/{compiler → engine/compiler}/terms.d.ts +0 -0
  205. /package/dist/{compiler → engine/compiler}/terms.js +0 -0
  206. /package/dist/{compiler → engine/compiler}/textfile-remote.d.ts +0 -0
  207. /package/dist/{compiler → engine/compiler}/textfile.d.ts +0 -0
  208. /package/dist/{compiler → engine/compiler}/theme-variants.d.ts +0 -0
  209. /package/dist/{compiler → engine/compiler}/zip.d.ts +0 -0
  210. /package/dist/{core → engine/core}/blocks.js +0 -0
  211. /package/dist/{core → engine/core}/code-file.d.ts +0 -0
  212. /package/dist/{core → engine/core}/code-file.js +0 -0
  213. /package/dist/{core → engine/core}/code-grammars.d.ts +0 -0
  214. /package/dist/{core → engine/core}/code-grammars.js +0 -0
  215. /package/dist/{core → engine/core}/content-types.js +0 -0
  216. /package/dist/{core → engine/core}/escape-html.d.ts +0 -0
  217. /package/dist/{core → engine/core}/escape-html.js +0 -0
  218. /package/dist/{core → engine/core}/extension-package.d.ts +0 -0
  219. /package/dist/{core → engine/core}/extension-package.js +0 -0
  220. /package/dist/{core → engine/core}/figure-frame.d.ts +0 -0
  221. /package/dist/{core → engine/core}/figure-frame.js +0 -0
  222. /package/dist/{core → engine/core}/file-embed.d.ts +0 -0
  223. /package/dist/{core → engine/core}/file-embed.js +0 -0
  224. /package/dist/{core → engine/core}/files.d.ts +0 -0
  225. /package/dist/{core → engine/core}/files.js +0 -0
  226. /package/dist/{core → engine/core}/graph-common.d.ts +0 -0
  227. /package/dist/{core → engine/core}/graph-common.js +0 -0
  228. /package/dist/{core → engine/core}/graph.d.ts +0 -0
  229. /package/dist/{core → engine/core}/graph.js +0 -0
  230. /package/dist/{core → engine/core}/inline.d.ts +0 -0
  231. /package/dist/{core → engine/core}/inline.js +0 -0
  232. /package/dist/{core → engine/core}/json-tools.d.ts +0 -0
  233. /package/dist/{core → engine/core}/json-tools.js +0 -0
  234. /package/dist/{core → engine/core}/language.d.ts +0 -0
  235. /package/dist/{core → engine/core}/language.js +0 -0
  236. /package/dist/{core → engine/core}/languages/ja.d.ts +0 -0
  237. /package/dist/{core → engine/core}/languages/ja.js +0 -0
  238. /package/dist/{core → engine/core}/markdown.d.ts +0 -0
  239. /package/dist/{core → engine/core}/markdown.js +0 -0
  240. /package/dist/{core → engine/core}/previewers.d.ts +0 -0
  241. /package/dist/{core → engine/core}/previewers.js +0 -0
  242. /package/dist/{core → engine/core}/schema-comments.d.ts +0 -0
  243. /package/dist/{core → engine/core}/schema-comments.js +0 -0
  244. /package/dist/{core → engine/core}/schema-fields.d.ts +0 -0
  245. /package/dist/{core → engine/core}/schema-fields.js +0 -0
  246. /package/dist/{core → engine/core}/schema-graph.d.ts +0 -0
  247. /package/dist/{core → engine/core}/schema-graph.js +0 -0
  248. /package/dist/{core → engine/core}/subformat-record.d.ts +0 -0
  249. /package/dist/{core → engine/core}/subformat-record.js +0 -0
  250. /package/dist/{core → engine/core}/term-reference.d.ts +0 -0
  251. /package/dist/{core → engine/core}/term-reference.js +0 -0
  252. /package/dist/{core → engine/core}/textfile.d.ts +0 -0
  253. /package/dist/{core → engine/core}/textfile.js +0 -0
  254. /package/dist/{core → engine/core}/theme-variants.d.ts +0 -0
  255. /package/dist/{core → engine/core}/theme-variants.js +0 -0
  256. /package/dist/{core → engine/core}/workspace.d.ts +0 -0
  257. /package/dist/{core → engine/core}/workspace.js +0 -0
  258. /package/dist/{viewer → frontend}/bundle-network.d.ts +0 -0
  259. /package/dist/{viewer → frontend}/bundle-network.js +0 -0
  260. /package/dist/{core → frontend}/flow-base-css.generated.d.ts +0 -0
  261. /package/dist/{core → frontend}/flow-base-css.generated.js +0 -0
  262. /package/dist/{core → frontend}/flow-css.d.ts +0 -0
  263. /package/dist/{core → frontend}/flow-css.js +0 -0
  264. /package/dist/{viewer → frontend}/font-picker.js +0 -0
  265. /package/dist/{viewer → frontend}/font-settings.js +0 -0
  266. /package/dist/{viewer → frontend}/i18n.d.ts +0 -0
  267. /package/dist/{viewer → frontend}/i18n.js +0 -0
  268. /package/dist/{viewer → frontend}/language-picker.d.ts +0 -0
  269. /package/dist/{viewer → frontend}/lazy-preview.d.ts +0 -0
  270. /package/dist/{viewer → frontend}/lazy-preview.js +0 -0
  271. /package/dist/{viewer → frontend}/nav-focus.d.ts +0 -0
  272. /package/dist/{viewer → frontend}/nav-update.d.ts +0 -0
  273. /package/dist/{viewer → frontend}/nav-update.js +0 -0
  274. /package/dist/{viewer → frontend}/plugin-blocks.d.ts +0 -0
  275. /package/dist/{viewer → frontend}/plugin-style.d.ts +0 -0
  276. /package/dist/{viewer → frontend}/plugin-style.js +0 -0
  277. /package/dist/{viewer → frontend}/plugin-view.d.ts +0 -0
  278. /package/dist/{viewer → frontend}/plugin-view.js +0 -0
  279. /package/dist/{viewer → frontend}/resize.d.ts +0 -0
  280. /package/dist/{core → frontend}/schema-graph-mount.d.ts +0 -0
  281. /package/dist/{core → frontend}/schema-graph-mount.js +0 -0
  282. /package/dist/{core → frontend}/table-ui.d.ts +0 -0
  283. /package/dist/{core → frontend}/table-ui.js +0 -0
  284. /package/dist/{core → frontend}/terms-ui.d.ts +0 -0
  285. /package/dist/{core → frontend}/terms-ui.js +0 -0
  286. /package/dist/{viewer → frontend}/theme-picker.d.ts +0 -0
  287. /package/dist/{viewer → frontend}/theme-picker.js +0 -0
  288. /package/dist/{core → frontend}/toc-ui.d.ts +0 -0
  289. /package/dist/{core → frontend}/toc-ui.js +0 -0
  290. /package/dist/{core → frontend}/video-ui.d.ts +0 -0
  291. /package/dist/{core → frontend}/video-ui.js +0 -0
  292. /package/dist/{viewer → server}/build-plugins.d.ts +0 -0
  293. /package/dist/{cli.d.ts → server/cli.d.ts} +0 -0
  294. /package/dist/{viewer → server}/extension-pack.d.ts +0 -0
  295. /package/dist/{viewer → server}/fonts/LICENSE.txt +0 -0
  296. /package/dist/{viewer → server}/fonts/udev-gothic-regular.woff2 +0 -0
  297. /package/dist/{viewer → server}/fonts.d.ts +0 -0
  298. /package/dist/{viewer → server}/fonts.js +0 -0
  299. /package/dist/{viewer → server}/ja-lint.js +0 -0
  300. /package/dist/{viewer → workspace}/git-types.js +0 -0
  301. /package/dist/{viewer → workspace}/site-icon.d.ts +0 -0
  302. /package/dist/{viewer → workspace}/site-title.d.ts +0 -0
@@ -1,11 +1,9 @@
1
- import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
2
- import { posix, relative as relativePath } from "node:path";
3
- import { fileURLToPath, pathToFileURL } from "node:url";
4
1
  import { visit } from "unist-util-visit";
5
- import { flattenTree, MANIFEST_FILE } from "../core/content-metadata.js";
2
+ import { flattenTree } from "../core/content-metadata.js";
6
3
  import { docFile, docIconFile, fileExtension, localFile } from "../core/files.js";
7
4
  import { contentLinks, parseMdast } from "../core/markdown.js";
8
5
  import { visitSchema } from "../core/schema-refs.js";
6
+ import { CODE_TEMPLATES } from "../core/taxonomy.js";
9
7
  import { isRemoteTextfile, parseFileReference } from "../core/textfile.js";
10
8
  import { assetReferences } from "./asset-references.js";
11
9
  import { CODE_LANGUAGES_DIR } from "./code-languages.js";
@@ -13,9 +11,10 @@ import { CONFIG_FILE } from "./config.js";
13
11
  import { collectRefs } from "./dialect.js";
14
12
  import { projectFiles } from "./files.js";
15
13
  import { PROJECT_FONTS_DIR } from "./fonts.js";
14
+ import { existsSync, fileURLToPath, pathToFileURL, posix, readdirSync, readFileSync, realpathSync, relative as relativePath, statSync, } from "./host.js";
16
15
  import { assertNotIgnored, ignoredFiles } from "./ignored-files.js";
17
16
  import { siteContentLanguages, translationFile } from "./locales.js";
18
- import { readManifest } from "./manifest.js";
17
+ import { manifestFile, readManifest } from "./manifest.js";
19
18
  import { readTextfile, textfilePath } from "./textfile.js";
20
19
  import { themeVariants } from "./theme-variants.js";
21
20
  import { zip } from "./zip.js";
@@ -45,12 +44,12 @@ export const exportEntries = (root) => {
45
44
  if (existsSync(textfilePath(root, file)) && !ignoredFiles(root, [file]).has(file))
46
45
  add(file);
47
46
  };
48
- add(MANIFEST_FILE);
47
+ add(manifestFile(root));
49
48
  if (manifest.licence)
50
49
  add(manifest.licence);
51
50
  optional(CONFIG_FILE);
52
- for (const { id, subformat } of flattenTree(manifest.tree)) {
53
- const file = subformat ? undefined : docFile(id, manifest.files);
51
+ for (const { id, subformat, library } of flattenTree(manifest.tree)) {
52
+ const file = subformat || library ? undefined : docFile(id, manifest.files);
54
53
  if (file)
55
54
  add(file);
56
55
  if (manifest.files?.icons?.[id])
@@ -66,8 +65,16 @@ export const exportEntries = (root) => {
66
65
  if (file)
67
66
  add(file);
68
67
  const files = projectFiles(root);
68
+ const libraries = new Set(flattenTree(manifest.tree).flatMap((node) => node.library ?? []));
69
+ if (libraries.size)
70
+ for (const file of files)
71
+ if (file.extension === "md" ||
72
+ (libraries.has(file.extension) && Object.hasOwn(CODE_TEMPLATES, file.extension)))
73
+ add(file.path);
69
74
  for (const format of manifest.subformats ?? []) {
70
75
  add(format.schema);
76
+ if (format.icon)
77
+ add(format.icon);
71
78
  for (const file of files)
72
79
  if (file.extension === format.ext)
73
80
  add(file.path);
@@ -1,4 +1,6 @@
1
- import { createHash } from "node:crypto";
1
+ import { escapeHtml } from "../core/escape-html.js";
2
+ import { extractMxfile, isDrawioSvg, normalizeDrawioSvg } from "./drawio.js";
3
+ import { dxfSvg } from "./dxf.js";
2
4
  // figures/ = the SoT for HTML-based Figs (figures). Two formats:
3
5
  // - <name>.svg : self-contained SVG (xmlns + viewBox + <title>Fig.<name></title> +
4
6
  // optional <desc>description</desc>)
@@ -20,12 +22,8 @@ import { createHash } from "node:crypto";
20
22
  // Both go through drawio.ts normalization (stripping prolog / mxfile copy / external links,
21
23
  // injecting title) before the same validation as hand-written SVGs. Colors stay in draw.io's
22
24
  // scheme (see the top of drawio.ts).
23
- import { readdirSync, readFileSync } from "node:fs";
24
- import { dirname } from "node:path";
25
- import { escapeHtml } from "../core/escape-html.js";
26
- import { extractMxfile, isDrawioSvg, normalizeDrawioSvg } from "./drawio.js";
27
- import { dxfSvg } from "./dxf.js";
28
- import { ignoredFiles } from "./ignored-files.js";
25
+ import { basename, createHash, dirname, readdirSync, readFileSync } from "./host.js";
26
+ import { assertNotIgnored, ignoredFiles } from "./ignored-files.js";
29
27
  import { textfilePath } from "./textfile.js";
30
28
  const EXT_RE = /\.(drawio\.svg|svg|html|png|webp|gif|mp4|webm|jpe?g|pdf|dxf)$/i;
31
29
  const FILE_RE = /^[a-z0-9][a-z0-9_-]*\.(drawio\.svg|svg|html|png|webp|gif|mp4|webm|jpe?g|pdf|dxf)$/;
@@ -129,14 +127,16 @@ const parseHtml = (file, raw, errors) => {
129
127
  export const loadFigures = (figuresDir, extraFiles = []) => {
130
128
  const errors = [];
131
129
  const figures = [];
130
+ const root = dirname(figuresDir);
132
131
  let files = [];
133
132
  try {
134
- files = readdirSync(figuresDir)
133
+ files = readdirSync(textfilePath(root, basename(figuresDir)))
135
134
  .filter((f) => EXT_RE.test(f))
136
135
  .sort();
137
136
  }
138
- catch {
139
- // A missing figures/ is valid.
137
+ catch (error) {
138
+ if (error.code !== "ENOENT")
139
+ errors.push(`figures/: ${error instanceof Error ? error.message : error}`);
140
140
  }
141
141
  files = [...new Set([...files.map((file) => `figures/${file}`), ...extraFiles])];
142
142
  const ignored = ignoredFiles(dirname(figuresDir), files);
@@ -156,11 +156,21 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
156
156
  errors.push(`${file}: duplicate name "${name}" (also used by ${dup.file})`);
157
157
  continue;
158
158
  }
159
+ let path;
160
+ try {
161
+ const relative = file.startsWith("figures/")
162
+ ? `${basename(figuresDir)}/${file.slice(8)}`
163
+ : file;
164
+ path = textfilePath(root, relative);
165
+ assertNotIgnored(root, relative);
166
+ }
167
+ catch (error) {
168
+ errors.push(`${file}: ${error instanceof Error ? error.message : error}`);
169
+ continue;
170
+ }
159
171
  if (/\.(pdf|dxf)$/i.test(file)) {
160
172
  try {
161
- const data = readFileSync(file.startsWith("figures/")
162
- ? textfilePath(figuresDir, file.slice(8))
163
- : textfilePath(dirname(figuresDir), file));
173
+ const data = readFileSync(path);
164
174
  if (/\.dxf$/i.test(file)) {
165
175
  const raw = new TextDecoder("utf-8", { fatal: true }).decode(data);
166
176
  figures.push({ name, file, ...parseSvg(file, dxfSvg(raw), errors) });
@@ -184,9 +194,7 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
184
194
  continue;
185
195
  }
186
196
  if (/\.(mp4|webm)$/i.test(file)) {
187
- const data = readFileSync(file.startsWith("figures/")
188
- ? textfilePath(figuresDir, file.slice(8))
189
- : textfilePath(dirname(figuresDir), file));
197
+ const data = readFileSync(path);
190
198
  figures.push({
191
199
  name,
192
200
  file,
@@ -198,9 +206,7 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
198
206
  const mime = IMAGE_MIME[file.slice(file.lastIndexOf(".") + 1).toLowerCase()];
199
207
  if (mime != null) {
200
208
  // Rasters are inlined as data URIs; Markdown embeds supply their alternative text.
201
- const data = readFileSync(file.startsWith("figures/")
202
- ? textfilePath(figuresDir, file.slice(8))
203
- : textfilePath(dirname(figuresDir), file)).toString("base64");
209
+ const data = readFileSync(path).toString("base64");
204
210
  figures.push({
205
211
  name,
206
212
  file,
@@ -209,9 +215,7 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
209
215
  });
210
216
  continue;
211
217
  }
212
- const raw = readFileSync(file.startsWith("figures/")
213
- ? textfilePath(figuresDir, file.slice(8))
214
- : textfilePath(dirname(figuresDir), file), "utf8");
218
+ const raw = readFileSync(path, "utf8");
215
219
  // The point of .drawio.svg is "can be reopened in draw.io", so the mxfile copy is required
216
220
  // (rejects an Export as > SVG output without the copy that was merely renamed).
217
221
  const editable = file.toLowerCase().endsWith(".drawio.svg");
@@ -1,7 +1,6 @@
1
1
  export declare const fileSig: (path: string) => string;
2
2
  /**
3
- * Memoizes a single file. If the signature matches, returns the previous value (same reference)
4
- * without reading/computing.
3
+ * Reuses parsed values when the source contents match, even if metadata changes.
5
4
  */
6
5
  export declare const createFileCache: <T>() => {
7
6
  get: (path: string, compute: (raw: string) => T) => T;
@@ -1,7 +1,6 @@
1
- // Makes the compiler incremental (even when the viewer calls compile() in full on every
2
- // keystroke / save, files unchanged on disk aren't re-read/re-parsed). signature = mtimeMs + size.
3
- import { readdirSync, readFileSync, statSync } from "node:fs";
4
- import { join } from "node:path";
1
+ // File metadata speeds up directory checks; parsed text is cached by contents because
2
+ // consecutive equal-size writes can have identical timestamps.
3
+ import { join, readdirSync, readFileSync, statSync } from "./host.js";
5
4
  export const fileSig = (path) => {
6
5
  let st;
7
6
  try {
@@ -13,25 +12,19 @@ export const fileSig = (path) => {
13
12
  return `${st.mtimeMs}:${st.size}`;
14
13
  };
15
14
  /**
16
- * Memoizes a single file. If the signature matches, returns the previous value (same reference)
17
- * without reading/computing.
15
+ * Reuses parsed values when the source contents match, even if metadata changes.
18
16
  */
19
17
  export const createFileCache = () => {
20
18
  const store = new Map();
21
19
  return {
22
20
  get: (path, compute) => {
23
- const sig = fileSig(path);
21
+ const raw = readFileSync(path, "utf8");
24
22
  const hit = store.get(path);
25
- if (sig !== "-" && hit?.sig === sig) {
23
+ if (hit?.raw === raw) {
26
24
  return hit.value;
27
25
  }
28
- const value = compute(readFileSync(path, "utf8"));
29
- if (sig === "-") {
30
- store.delete(path);
31
- }
32
- else {
33
- store.set(path, { sig, value });
34
- }
26
+ const value = compute(raw);
27
+ store.set(path, { raw, value });
35
28
  return value;
36
29
  },
37
30
  };
@@ -1,9 +1,6 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
3
- import { dirname, join, posix } from "node:path";
4
1
  import { visit } from "unist-util-visit";
5
2
  import { Document, isSeq, parseDocument } from "yaml";
6
- import { flattenTree, MANIFEST_FILE, serializeManifest } from "../core/content-metadata.js";
3
+ import { flattenTree, isManifestFile, serializeManifest } from "../core/content-metadata.js";
7
4
  import { defaultFilePath, docFile, docIconFile, fileExtension, isDocumentFileName, localFile, MAX_FILE_UPLOAD_BYTES, parseFileLayout, } from "../core/files.js";
8
5
  import { codeBlockAt, parseMdast } from "../core/markdown.js";
9
6
  import { docPath } from "../core/routing.js";
@@ -11,14 +8,18 @@ import { termFileUrl } from "../core/term-reference.js";
11
8
  import { isRemoteTextfile, parseFileReference } from "../core/textfile.js";
12
9
  import { assetReferences } from "./asset-references.js";
13
10
  import { fileSig } from "./file-cache.js";
14
- import { ignoredFiles } from "./ignored-files.js";
11
+ import { createHash, dirname, existsSync, join, linkSync, mkdirSync, posix, randomUUID, readdirSync, readFileSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from "./host.js";
12
+ import { ignoredFiles, withinRead } from "./ignored-files.js";
15
13
  import { translationFile, translationFiles, translationLanguages } from "./locales.js";
16
- import { readManifest } from "./manifest.js";
14
+ import { manifestFile, readManifest } from "./manifest.js";
15
+ import { rewriteSchemaFiles } from "./schema-file-references.js";
17
16
  import { textfilePath, writeTextfile } from "./textfile.js";
18
17
  import { themeNames, themeVariants } from "./theme-variants.js";
19
18
  // Project settings and translations have their own layout, outside file restructuring.
20
- const reserved = new Set([MANIFEST_FILE, "docs.config.mjs", "node_modules", "dist", "locales"]);
21
- export const managedFile = (file) => localFile(file) && !reserved.has(file.split("/")[0] ?? "");
19
+ const reserved = new Set(["docs.config.mjs", "node_modules", "dist", "locales"]);
20
+ export const managedFile = (file) => localFile(file) &&
21
+ !isManifestFile(file.split("/")[0] ?? "") &&
22
+ !reserved.has(file.split("/")[0] ?? "");
22
23
  const names = new Intl.Collator("en", { numeric: true });
23
24
  const compareFilePaths = (a, b) => {
24
25
  const left = a.split("/");
@@ -56,7 +57,10 @@ export const completeFilePaths = (root, prefix) => {
56
57
  .sort(compareFilePaths)
57
58
  .slice(0, 200);
58
59
  };
59
- export const projectFiles = (root) => {
60
+ export const projectFiles = (root) => [
61
+ ...withinRead(`files\0${root}`, () => walkProjectFiles(root)),
62
+ ];
63
+ const walkProjectFiles = (root) => {
60
64
  const result = [];
61
65
  const walk = (directory) => {
62
66
  for (const entry of readdirSync(join(root, directory), { withFileTypes: true })) {
@@ -86,7 +90,9 @@ export const filesSnapshot = (root) => {
86
90
  const files = projectFiles(root);
87
91
  const layout = manifest.files ?? parseFileLayout({});
88
92
  const hash = createHash("sha256");
89
- hash.update(existsSync(join(root, MANIFEST_FILE)) ? readFileSync(join(root, MANIFEST_FILE)) : "");
93
+ hash.update(existsSync(join(root, manifestFile(root)))
94
+ ? readFileSync(join(root, manifestFile(root)))
95
+ : "");
90
96
  for (const file of files)
91
97
  hash.update(file.path)
92
98
  .update(String(statSync(textfilePath(root, file.path)).mtimeMs))
@@ -99,7 +105,7 @@ export const filesSnapshot = (root) => {
99
105
  layout,
100
106
  revision: hash.digest("hex"),
101
107
  documents: Object.fromEntries(docs
102
- .filter((node) => !node.subformat)
108
+ .filter((node) => !node.subformat && !node.library)
103
109
  .map(({ id }) => [docFile(id, layout), docPath(docs, id)])),
104
110
  };
105
111
  };
@@ -336,16 +342,16 @@ export const updateFiles = (root, input) => {
336
342
  if (subformat)
337
343
  continue;
338
344
  const file = docFile(id, layout);
345
+ const icon = docIconFile(id, layout);
339
346
  if (moves.has(file))
340
347
  layout.documents[id] = moves.get(file);
341
- const icon = docIconFile(id, layout);
342
- if (moves.has(icon)) {
348
+ if (moves.has(icon) || (moves.has(file) && existsSync(textfilePath(root, icon)))) {
343
349
  layout.icons ??= {};
344
- layout.icons[id] = moves.get(icon);
350
+ layout.icons[id] = moves.get(icon) ?? icon;
345
351
  }
346
352
  }
347
- const rawManifest = existsSync(join(root, MANIFEST_FILE))
348
- ? readFileSync(join(root, MANIFEST_FILE), "utf8")
353
+ const rawManifest = existsSync(join(root, manifestFile(root)))
354
+ ? readFileSync(join(root, manifestFile(root)), "utf8")
349
355
  : null;
350
356
  const parsed = parseDocument(rawManifest ?? "docs: []\n");
351
357
  const yaml = isSeq(parsed.contents) ? new Document({ docs: parsed.toJS() }) : parsed;
@@ -357,8 +363,12 @@ export const updateFiles = (root, input) => {
357
363
  if (manifest.themeIcons)
358
364
  for (const [theme, file] of Object.entries(manifest.themeIcons))
359
365
  manifest.themeIcons[theme] = moves.get(file) ?? file;
360
- for (const subformat of manifest.subformats ?? [])
366
+ const schemaWrites = rewriteSchemaFiles(root, (manifest.subformats ?? []).map((subformat) => subformat.schema), paths, moves);
367
+ for (const subformat of manifest.subformats ?? []) {
361
368
  subformat.schema = moves.get(subformat.schema) ?? subformat.schema;
369
+ if (subformat.icon)
370
+ subformat.icon = moves.get(subformat.icon) ?? subformat.icon;
371
+ }
362
372
  if (manifest.format !== "nested") {
363
373
  yaml.set("files", layout);
364
374
  if (manifest.icon)
@@ -370,28 +380,29 @@ export const updateFiles = (root, input) => {
370
380
  }
371
381
  const writes = [];
372
382
  const links = new Map(moves);
373
- for (const file of [...paths, ...translated].filter((file) => /\.(md|callouth|html|htm|svg|css)$/.test(file))) {
383
+ for (const file of [...paths, ...translated].filter((file) => /\.(md|callouth|html|htm|svg|css)$/.test(file) || schemaWrites.has(file))) {
374
384
  const base = readFileSync(textfilePath(root, file));
375
385
  const raw = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(base);
376
- const next = /\.(md|callouth)$/.test(file)
377
- ? rewriteFileLinks(raw, moves)
378
- : moves.size
379
- ? assetReferences(raw, fileExtension(file), (url) => {
380
- if (!url || /^(?:[a-z][\w+.-]*:|[/#])/i.test(url))
381
- return url;
382
- const path = decodeURIComponent(url.split(/[?#]/)[0] ?? "");
383
- if (!path)
384
- return url;
385
- const source = posix.normalize(posix.join(posix.dirname(file), path));
386
- const target = moves.get(source) ?? source;
387
- const owner = moves.get(file) ?? file;
388
- if (target === source && posix.dirname(owner) === posix.dirname(file))
389
- return url;
390
- const relative = posix.relative(posix.dirname(owner), target);
391
- return (relative.split("/").map(encodeURIComponent).join("/") +
392
- url.slice(url.search(/[?#]|$/)));
393
- })
394
- : raw;
386
+ const next = schemaWrites.get(file) ??
387
+ (/\.(md|callouth)$/.test(file)
388
+ ? rewriteFileLinks(raw, moves)
389
+ : moves.size
390
+ ? assetReferences(raw, fileExtension(file), (url) => {
391
+ if (!url || /^(?:[a-z][\w+.-]*:|[/#])/i.test(url))
392
+ return url;
393
+ const path = decodeURIComponent(url.split(/[?#]/)[0] ?? "");
394
+ if (!path)
395
+ return url;
396
+ const source = posix.normalize(posix.join(posix.dirname(file), path));
397
+ const target = moves.get(source) ?? source;
398
+ const owner = moves.get(file) ?? file;
399
+ if (target === source && posix.dirname(owner) === posix.dirname(file))
400
+ return url;
401
+ const relative = posix.relative(posix.dirname(owner), target);
402
+ return (relative.split("/").map(encodeURIComponent).join("/") +
403
+ url.slice(url.search(/[?#]|$/)));
404
+ })
405
+ : raw);
395
406
  const data = Buffer.from(next);
396
407
  if (base.equals(data))
397
408
  continue;
@@ -405,7 +416,7 @@ export const updateFiles = (root, input) => {
405
416
  });
406
417
  }
407
418
  writes.push({
408
- file: MANIFEST_FILE,
419
+ file: manifestFile(root),
409
420
  base: rawManifest === null ? null : Buffer.from(rawManifest),
410
421
  data: Buffer.from(manifest.format === "nested"
411
422
  ? serializeManifest(manifest.tree, manifest)
@@ -1,7 +1,5 @@
1
- import { createHash } from "node:crypto";
2
- import { lstatSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
3
- import { basename, extname } from "node:path";
4
1
  import { localFile } from "../core/files.js";
2
+ import { basename, createHash, extname, lstatSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from "./host.js";
5
3
  import { ignoredFiles } from "./ignored-files.js";
6
4
  import { textfilePath } from "./textfile.js";
7
5
  export const PROJECT_FONTS_DIR = ".dooc/fonts";
@@ -1,7 +1,6 @@
1
1
  // Converter from dialect mdast → normalized Block AST (internal module for build / preview only,
2
2
  // outside the publish surface). The consumer contract (Block / TocEntry / slugify) lives in
3
3
  // blocks.ts; validation is handled by dialect.ts.
4
- import { basename, extname } from "node:path";
5
4
  import { slugify } from "../core/blocks.js";
6
5
  import { parseFileEmbed } from "../core/file-embed.js";
7
6
  import { inlineSegmenter } from "../core/inline.js";
@@ -9,6 +8,7 @@ import { inlineToText, listItems, standaloneImages } from "../core/markdown.js";
9
8
  import { textfileName } from "../core/textfile.js";
10
9
  import { parseContentCode } from "./code-blocks.js";
11
10
  import { figureName } from "./figures.js";
11
+ import { basename, extname } from "./host.js";
12
12
  const tableBlock = (t) => {
13
13
  const [head, ...rows] = t.children;
14
14
  return {
@@ -0,0 +1,10 @@
1
+ export { execFile, execFileSync, spawnSync } from "node:child_process";
2
+ export { createHash, randomUUID } from "node:crypto";
3
+ export { existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
4
+ export { open, readFile, stat } from "node:fs/promises";
5
+ export { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep, } from "node:path";
6
+ export { fileURLToPath, pathToFileURL } from "node:url";
7
+ export { isDeepStrictEqual } from "node:util";
8
+ export { runInNewContext } from "node:vm";
9
+ export { crc32, deflateRawSync } from "node:zlib";
10
+ export { fetchPublicFile } from "./public-file.js";
@@ -0,0 +1,16 @@
1
+ // The only door between the engine and the machine it runs on. Engine modules import the
2
+ // platform through this file and nothing else, so a browser build swaps in another host module
3
+ // (bundler substitution of this path) and the rest runs unchanged. Under Node this is a plain
4
+ // re-export, which keeps module mocks and stack traces exactly as they were.
5
+ // Keep the list minimal: every name here is one a browser host has to provide.
6
+ export { execFile, execFileSync, spawnSync } from "node:child_process";
7
+ export { createHash, randomUUID } from "node:crypto";
8
+ export { existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
9
+ export { open, readFile, stat } from "node:fs/promises";
10
+ export { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep, } from "node:path";
11
+ export { fileURLToPath, pathToFileURL } from "node:url";
12
+ export { isDeepStrictEqual } from "node:util";
13
+ export { runInNewContext } from "node:vm";
14
+ export { crc32, deflateRawSync } from "node:zlib";
15
+ // Network access with its address checks is the host's business too.
16
+ export { fetchPublicFile } from "./public-file.js";
@@ -1,5 +1,8 @@
1
+ import type { ParsedManifest } from "../core/content-metadata.js";
1
2
  import { type FileLayout } from "../core/files.js";
2
3
  export declare const ICONS_DIR = "icons";
4
+ /** Only implicit, unshared icon files belong to a page's lifecycle. */
5
+ export declare const ownsDocIcon: (id: string, manifest: ParsedManifest) => boolean;
3
6
  /**
4
7
  * Normalize an SVG to 1:1 (padding is added automatically = the shorter side is widened, centered;
5
8
  * nothing is cropped). Builds a square viewBox from the root's viewBox (or width / height if it has
@@ -1,11 +1,20 @@
1
1
  // A doc's icon (1:1 SVG shown on its sidebar row). It lives at icons/<docId>.svg in the docs root.
2
2
  // Separate from body-text figures (figures/): one per doc, following the doc's rename / deletion.
3
- import { existsSync, readdirSync, readFileSync } from "node:fs";
4
- import { join } from "node:path";
5
3
  import { docIconFile } from "../core/files.js";
4
+ import { existsSync, readdirSync, readFileSync } from "./host.js";
6
5
  import { assertNotIgnored, ignoredFiles } from "./ignored-files.js";
7
- import { textfilePath } from "./textfile.js";
6
+ import { readTextfile, textfilePath } from "./textfile.js";
8
7
  export const ICONS_DIR = "icons";
8
+ /** Only implicit, unshared icon files belong to a page's lifecycle. */
9
+ export const ownsDocIcon = (id, manifest) => {
10
+ const file = docIconFile(id, manifest.files);
11
+ return (!Object.hasOwn(manifest.files?.icons ?? {}, id) &&
12
+ ![
13
+ manifest.icon,
14
+ ...Object.values(manifest.themeIcons ?? {}),
15
+ ...Object.values(manifest.files?.icons ?? {}),
16
+ ].includes(file));
17
+ };
9
18
  const ROOT_SVG_RE = /<svg\b[^>]*>/i;
10
19
  const num = (v) => {
11
20
  const n = v == null ? Number.NaN : Number.parseFloat(v);
@@ -46,10 +55,16 @@ export const squareSvg = (svg) => {
46
55
  };
47
56
  /** Read icons/ (docId → svg markup). An icon with no doc is an error (missed rename / delete). */
48
57
  export const loadIcons = (root, docIds, siteIconFile, layout, siteIcons = []) => {
49
- const dir = join(root, ICONS_DIR);
50
58
  const icons = new Map();
51
59
  const errors = [];
52
- const files = existsSync(dir) ? readdirSync(dir) : [];
60
+ let files = [];
61
+ try {
62
+ const dir = textfilePath(root, ICONS_DIR);
63
+ files = existsSync(dir) ? readdirSync(dir) : [];
64
+ }
65
+ catch (error) {
66
+ errors.push(`${ICONS_DIR}: ${error}`);
67
+ }
53
68
  const ignored = ignoredFiles(root, files.map((file) => `${ICONS_DIR}/${file}`));
54
69
  for (const f of files) {
55
70
  if (ignored.has(`${ICONS_DIR}/${f}`))
@@ -67,12 +82,15 @@ export const loadIcons = (root, docIds, siteIconFile, layout, siteIcons = []) =>
67
82
  errors.push(`${ICONS_DIR}/${f}: no matching doc (content/${id || f}.md)`);
68
83
  continue;
69
84
  }
70
- const svg = readFileSync(join(dir, f), "utf8");
71
- if (!ROOT_SVG_RE.test(svg)) {
72
- errors.push(`${ICONS_DIR}/${f}: not an svg`);
73
- continue;
85
+ try {
86
+ const svg = readTextfile(root, `${ICONS_DIR}/${f}`);
87
+ if (!ROOT_SVG_RE.test(svg))
88
+ throw new Error("not an svg");
89
+ icons.set(id, svg);
90
+ }
91
+ catch (error) {
92
+ errors.push(`${ICONS_DIR}/${f}: ${error instanceof Error ? error.message : error}`);
74
93
  }
75
- icons.set(id, svg);
76
94
  }
77
95
  for (const id of docIds)
78
96
  if (layout?.icons?.[id]) {
@@ -1,5 +1,7 @@
1
1
  /** Share Git checks within one synchronous read, never across requests or writes. */
2
2
  export declare const withIgnoredFilesCache: <T>(read: () => T) => T;
3
+ /** Reuse one disk answer inside withIgnoredFilesCache; outside it every call reads again. */
4
+ export declare const withinRead: <T>(key: string, read: () => T) => T;
3
5
  /** Use Git's tracked-file and exclude rules; standalone folders use their .gitignore files. */
4
6
  export declare const ignoredFiles: (root: string, files: readonly string[]) => Set<string>;
5
7
  export declare const assertNotIgnored: (root: string, file: string) => void;
@@ -1,20 +1,29 @@
1
- import { spawnSync } from "node:child_process";
2
- import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
3
- import { dirname, join, posix, relative, resolve, sep } from "node:path";
4
1
  import ignore, {} from "ignore";
2
+ import { dirname, existsSync, join, posix, readFileSync, realpathSync, relative, resolve, sep, spawnSync, statSync, } from "./host.js";
5
3
  let cached;
4
+ let scope;
6
5
  /** Share Git checks within one synchronous read, never across requests or writes. */
7
6
  export const withIgnoredFilesCache = (read) => {
8
7
  if (cached)
9
8
  return read();
10
9
  cached = new Map();
10
+ scope = new Map();
11
11
  try {
12
12
  return read();
13
13
  }
14
14
  finally {
15
15
  cached = undefined;
16
+ scope = undefined;
16
17
  }
17
18
  };
19
+ /** Reuse one disk answer inside withIgnoredFilesCache; outside it every call reads again. */
20
+ export const withinRead = (key, read) => {
21
+ if (!scope)
22
+ return read();
23
+ if (!scope.has(key))
24
+ scope.set(key, read());
25
+ return scope.get(key);
26
+ };
18
27
  /** Use Git's tracked-file and exclude rules; standalone folders use their .gitignore files. */
19
28
  export const ignoredFiles = (root, files) => {
20
29
  if (!cached)
@@ -1,14 +1,11 @@
1
1
  // Translations mirror source paths under locales/<ISO 639-3>/ as ordinary Markdown files.
2
- import { existsSync, readdirSync, unlinkSync } from "node:fs";
3
- import { join, relative } from "node:path";
4
2
  import { isDocId } from "../core/content-metadata.js";
5
3
  import { localFile } from "../core/files.js";
6
4
  import { contentLanguageCode, DEFAULT_LANG } from "../core/language.js";
7
- import { parseDoc } from "./dialect.js";
5
+ import { existsSync, join, readdirSync, relative, unlinkSync } from "./host.js";
8
6
  import { ignoredFiles } from "./ignored-files.js";
9
7
  import { isContentLanguage } from "./language-codes.js";
10
8
  import { docFile, readManifest } from "./manifest.js";
11
- import { assembleDoc } from "./serialize.js";
12
9
  import { readTextfile, textfilePath, writeTextfile } from "./textfile.js";
13
10
  export const translationFile = (file, language) => {
14
11
  if (!isContentLanguage(language))
@@ -62,10 +59,7 @@ export const setDocTranslation = (root, sourceLanguage, id, language, added) =>
62
59
  if (added === existsSync(path))
63
60
  return;
64
61
  if (added) {
65
- const doc = parseDoc(source);
66
- if (!doc.frontmatter)
67
- throw new Error("Fix the source front-matter before translating");
68
- writeTextfile(root, translated, assembleDoc({ ...doc.frontmatter, lang: language }, doc.body), null);
62
+ writeTextfile(root, translated, source, null);
69
63
  }
70
64
  else
71
65
  unlinkSync(path);
@@ -1,7 +1,8 @@
1
1
  import { type DocNode, type ParsedManifest } from "../core/content-metadata.js";
2
- /** CLI paths select a manifest; every project path is relative to its parent. */
2
+ export declare const manifestFile: (root: string) => string;
3
+ /** Select the manifest for subsequent operations on its parent directory. */
3
4
  export declare const projectRoot: (input?: string) => string;
4
- export declare const parseManifestText: (raw: string) => ParsedManifest;
5
+ export declare const parseManifestText: (raw: string, file?: string) => ParsedManifest;
5
6
  /** Empty tree if missing (a new docs root with zero docs). */
6
7
  export declare const readManifest: (root: string) => ParsedManifest;
7
8
  export declare const writeManifest: (root: string, tree: readonly DocNode[], metadata?: Omit<ParsedManifest, "tree" | "errors">) => void;
@@ -0,0 +1,46 @@
1
+ // Reads/writes dooc.yaml (node-dependent). Tree validation and manipulation live in
2
+ // core/content-metadata.ts.
3
+ import { parse } from "yaml";
4
+ import { isManifestFile, MANIFEST_FILE, parseManifest, serializeManifest, } from "../core/content-metadata.js";
5
+ import { createFileCache } from "./file-cache.js";
6
+ import { basename, dirname, existsSync, join, resolve, statSync, writeFileSync } from "./host.js";
7
+ const manifests = new Map();
8
+ const parsed = createFileCache();
9
+ export const manifestFile = (root) => manifests.get(resolve(root)) ?? MANIFEST_FILE;
10
+ /** Select the manifest for subsequent operations on its parent directory. */
11
+ export const projectRoot = (input = MANIFEST_FILE) => {
12
+ const file = resolve(input);
13
+ if (!isManifestFile(basename(file)) || !existsSync(file) || !statSync(file).isFile())
14
+ throw new Error(`Specify an existing dooc.yaml or <name>.dooc.yaml file: ${file}`);
15
+ const root = dirname(file);
16
+ manifests.set(root, basename(file));
17
+ return root;
18
+ };
19
+ export const parseManifestText = (raw, file = MANIFEST_FILE) => {
20
+ let value;
21
+ try {
22
+ value = parse(raw);
23
+ }
24
+ catch (e) {
25
+ return {
26
+ tree: [],
27
+ errors: [`${file}: invalid YAML (${e instanceof Error ? e.message : e})`],
28
+ };
29
+ }
30
+ const manifest = parseManifest(value);
31
+ manifest.errors = manifest.errors.map((error) => error.replace(/^dooc\.yaml(?=:)/, () => file));
32
+ return manifest;
33
+ };
34
+ /** Empty tree if missing (a new docs root with zero docs). */
35
+ export const readManifest = (root) => {
36
+ const file = manifestFile(root);
37
+ const path = join(root, file);
38
+ // Callers may edit the result before writing it back, so each gets its own copy.
39
+ return existsSync(path)
40
+ ? structuredClone(parsed.get(path, (raw) => parseManifestText(raw, file)))
41
+ : { tree: [], errors: [] };
42
+ };
43
+ export const writeManifest = (root, tree, metadata = {}) => {
44
+ writeFileSync(join(root, manifestFile(root)), serializeManifest(tree, metadata));
45
+ };
46
+ export { docFile } from "../core/files.js";