@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,10 +1,13 @@
1
1
  import { type FileLayout } from "./files.js";
2
2
  import { type Subformat } from "./subformats.js";
3
3
  export declare const MANIFEST_FILE = "dooc.yaml";
4
+ export declare const isManifestFile: (name: string) => boolean;
4
5
  export interface DocNode {
5
6
  id: string;
6
7
  file?: string;
7
8
  subformat?: string;
9
+ /** Library page: a block format (`schemath`), `urls` or `url-previews`. */
10
+ library?: string;
8
11
  title?: string;
9
12
  children: DocNode[];
10
13
  }
@@ -28,6 +31,8 @@ export interface ParsedManifest {
28
31
  }
29
32
  export declare const DOC_ID_RE: RegExp;
30
33
  export declare const isDocId: (s: string) => boolean;
34
+ export declare const libraryPageId: (view: string) => string;
35
+ export declare const isLibraryView: (view: unknown) => view is string;
31
36
  export declare const subformatPageId: (ext: string) => string;
32
37
  /** Doc file name directly under content/ (`<id>.md`) → id. undefined if the shape differs. */
33
38
  export declare const docIdOfFile: (name: string) => string | undefined;
@@ -45,7 +50,7 @@ export declare const flattenTree: (tree: readonly DocNode[]) => (Omit<DocNode, "
45
50
  depth: number;
46
51
  })[];
47
52
  /** Append a new doc to the end of parent's children. Duplicate id / missing parent → undefined. */
48
- export declare const insertDoc: (tree: readonly DocNode[], id: string, parent?: string, page?: Pick<DocNode, "subformat" | "title">) => DocNode[] | undefined;
53
+ export declare const insertDoc: (tree: readonly DocNode[], id: string, parent?: string, page?: Pick<DocNode, "subformat" | "library" | "title">) => DocNode[] | undefined;
49
54
  /**
50
55
  * Move a doc (with its children) to position index under parent. It can't be moved under
51
56
  * itself or its own descendants (that would create a cycle). An invalid move returns undefined
@@ -5,8 +5,11 @@ import { docFile, fileDocumentId, localFile, parseFileLayout } from "./files.js"
5
5
  import { contentLanguageCode, DEFAULT_LANG, isLangTag } from "./language.js";
6
6
  import { parseSubformats } from "./subformats.js";
7
7
  export const MANIFEST_FILE = "dooc.yaml";
8
+ export const isManifestFile = (name) => /^(?:[^/\\]+\.)?dooc\.yaml$/.test(name);
8
9
  export const DOC_ID_RE = /^[a-z0-9][a-z0-9-]*$/;
9
10
  export const isDocId = (s) => DOC_ID_RE.test(s);
11
+ export const libraryPageId = (view) => `library-${fileDocumentId(view)}`;
12
+ export const isLibraryView = (view) => typeof view === "string" && /^[a-z0-9][a-z0-9+#-]*$/.test(view);
10
13
  export const subformatPageId = (ext) => `subformat-${fileDocumentId(ext)}`;
11
14
  /** Doc file name directly under content/ (`<id>.md`) → id. undefined if the shape differs. */
12
15
  export const docIdOfFile = (name) => {
@@ -85,6 +88,7 @@ export const parseManifest = (value) => {
85
88
  if (manifest.default_subformat_folder !== undefined) {
86
89
  const folder = manifest.default_subformat_folder;
87
90
  if (!localFile(folder) ||
91
+ isManifestFile(folder.split("/")[0] ?? "") ||
88
92
  ["node_modules", "dist", "locales", MANIFEST_FILE, "docs.config.mjs"].includes(folder.split("/")[0] ?? ""))
89
93
  errors.push(`${MANIFEST_FILE}: default_subformat_folder must be a local project folder`);
90
94
  else
@@ -133,6 +137,28 @@ export const parseManifest = (value) => {
133
137
  const at = `${path}[${i}]`;
134
138
  let id;
135
139
  let children;
140
+ if (item && typeof item === "object" && !Array.isArray(item) && "library" in item) {
141
+ const id = isLibraryView(item.library) ? libraryPageId(item.library) : "";
142
+ if (!id ||
143
+ Object.keys(item).some((key) => !["library", "title", "children"].includes(key)) ||
144
+ (item.title !== undefined &&
145
+ (typeof item.title !== "string" || !item.title.trim()))) {
146
+ errors.push(`${MANIFEST_FILE}: ${at} requires a library view and a non-empty title`);
147
+ continue;
148
+ }
149
+ if (seen.has(id)) {
150
+ errors.push(`${MANIFEST_FILE}: duplicate id "${id}"`);
151
+ continue;
152
+ }
153
+ seen.add(id);
154
+ nodes.push({
155
+ id,
156
+ library: item.library,
157
+ title: item.title?.trim() ?? item.library,
158
+ children: walk(item.children, `${at}.children`),
159
+ });
160
+ continue;
161
+ }
136
162
  if (item && typeof item === "object" && !Array.isArray(item) && "subformat" in item) {
137
163
  const config = subformats?.find((format) => format.ext === item.subformat);
138
164
  if (!config ||
@@ -188,7 +214,7 @@ export const parseManifest = (value) => {
188
214
  if (!seen.has(id))
189
215
  errors.push(`${MANIFEST_FILE}: files references unknown document "${id}"`);
190
216
  const paths = flattenTree(tree)
191
- .filter((node) => !node.subformat)
217
+ .filter((node) => !node.subformat && !node.library)
192
218
  .map(({ id }) => docFile(id, files));
193
219
  if (new Set(paths).size !== paths.length)
194
220
  errors.push(`${MANIFEST_FILE}: documents must use distinct files`);
@@ -257,10 +283,27 @@ const parseNestedManifest = (input) => {
257
283
  if (!Array.isArray(value))
258
284
  throw new Error("center_contents and children must be lists");
259
285
  return value.map((entry) => {
260
- const node = object(entry, ["file", "icon", "children", "subformat", "title"], "center_contents");
286
+ const node = object(entry, ["file", "icon", "children", "subformat", "library", "title"], "center_contents");
261
287
  if (node.icon !== undefined &&
262
288
  (!localFile(node.icon) || !node.icon.endsWith(".svg")))
263
289
  throw new Error("Document icons must be local SVG files");
290
+ if (node.library !== undefined) {
291
+ if (!isLibraryView(node.library) ||
292
+ node.file !== undefined ||
293
+ node.subformat !== undefined ||
294
+ (node.title !== undefined &&
295
+ (typeof node.title !== "string" || !node.title.trim())))
296
+ throw new Error("Library pages require a view and a non-empty title");
297
+ const id = libraryPageId(node.library);
298
+ if (typeof node.icon === "string")
299
+ icons[id] = node.icon;
300
+ return {
301
+ id,
302
+ library: node.library,
303
+ title: typeof node.title === "string" ? node.title.trim() : node.library,
304
+ children: node.children === undefined ? [] : walk(node.children),
305
+ };
306
+ }
264
307
  if (node.subformat !== undefined) {
265
308
  const config = parseSubformats(root.json_subformats ?? []).find((format) => format.ext === node.subformat);
266
309
  if (!config ||
@@ -280,6 +323,9 @@ const parseNestedManifest = (input) => {
280
323
  }
281
324
  if (!localFile(node.file) || !node.file.endsWith(".md"))
282
325
  throw new Error("Each document requires a local .md file");
326
+ if (node.title !== undefined &&
327
+ (typeof node.title !== "string" || !node.title.trim()))
328
+ throw new Error("Document titles must be non-empty strings");
283
329
  const id = fileDocumentId(node.file);
284
330
  if (Object.hasOwn(documents, id))
285
331
  throw new Error(`Duplicate document: ${node.file}`);
@@ -289,6 +335,7 @@ const parseNestedManifest = (input) => {
289
335
  return {
290
336
  id,
291
337
  file: node.file,
338
+ ...(typeof node.title === "string" ? { title: node.title.trim() } : {}),
292
339
  children: node.children === undefined ? [] : walk(node.children),
293
340
  };
294
341
  });
@@ -300,15 +347,21 @@ const parseNestedManifest = (input) => {
300
347
  const source = contentLanguageCode(language);
301
348
  if (sidebar.title !== undefined && !titles[source])
302
349
  throw new Error("left_sidebar.title must include system.default_lang");
303
- const legacyTree = (nodes) => nodes.map((node) => node.subformat
350
+ const legacyTree = (nodes) => nodes.map((node) => node.library
304
351
  ? {
305
- subformat: node.subformat,
352
+ library: node.library,
306
353
  title: node.title,
307
- children: legacyTree(node.children),
354
+ ...(node.children.length ? { children: legacyTree(node.children) } : {}),
308
355
  }
309
- : node.children.length
310
- ? { [node.id]: legacyTree(node.children) }
311
- : node.id);
356
+ : node.subformat
357
+ ? {
358
+ subformat: node.subformat,
359
+ title: node.title,
360
+ children: legacyTree(node.children),
361
+ }
362
+ : node.children.length
363
+ ? { [node.id]: legacyTree(node.children) }
364
+ : node.id);
312
365
  const parsed = parseManifest({
313
366
  docs: legacyTree(tree),
314
367
  defaultLang: language,
@@ -349,9 +402,14 @@ const parseNestedManifest = (input) => {
349
402
  export const serializeManifest = (tree, { format, titles, themeIcons, title, icon, defaultLang, licence, files, languages, themes, subformats, defaultSubformatFolder, } = {}) => {
350
403
  if (format === "nested") {
351
404
  const contents = (nodes) => nodes.map((node) => ({
352
- ...(node.subformat
353
- ? { subformat: node.subformat, title: node.title }
354
- : { file: docFile(node.id, files) }),
405
+ ...(node.library
406
+ ? { library: node.library, title: node.title }
407
+ : node.subformat
408
+ ? { subformat: node.subformat, title: node.title }
409
+ : {
410
+ file: docFile(node.id, files),
411
+ ...(node.title ? { title: node.title } : {}),
412
+ }),
355
413
  ...(files?.icons?.[node.id] ? { icon: files.icons[node.id] } : {}),
356
414
  ...(node.children.length ? { children: contents(node.children) } : {}),
357
415
  }));
@@ -392,16 +450,22 @@ export const serializeManifest = (tree, { format, titles, themeIcons, title, ico
392
450
  : {}),
393
451
  }, { lineWidth: 0 });
394
452
  }
395
- if (flattenTree(tree).some((node) => node.subformat)) {
396
- const contents = (nodes) => nodes.map((node) => node.subformat
453
+ if (flattenTree(tree).some((node) => node.subformat || node.library)) {
454
+ const contents = (nodes) => nodes.map((node) => node.library
397
455
  ? {
398
- subformat: node.subformat,
456
+ library: node.library,
399
457
  title: node.title,
400
458
  ...(node.children.length ? { children: contents(node.children) } : {}),
401
459
  }
402
- : node.children.length
403
- ? { [node.id]: contents(node.children) }
404
- : node.id);
460
+ : node.subformat
461
+ ? {
462
+ subformat: node.subformat,
463
+ title: node.title,
464
+ ...(node.children.length ? { children: contents(node.children) } : {}),
465
+ }
466
+ : node.children.length
467
+ ? { [node.id]: contents(node.children) }
468
+ : node.id);
405
469
  return stringify({
406
470
  ...(title ? { title } : {}),
407
471
  ...(icon ? { icon } : {}),
@@ -440,7 +504,9 @@ export const flattenTree = (tree) => {
440
504
  out.push({
441
505
  id: n.id,
442
506
  ...(n.file ? { file: n.file } : {}),
443
- ...(n.subformat ? { subformat: n.subformat, title: n.title } : {}),
507
+ ...(n.subformat ? { subformat: n.subformat } : {}),
508
+ ...(n.library ? { library: n.library } : {}),
509
+ ...(n.title ? { title: n.title } : {}),
444
510
  ...(parent == null ? {} : { parent }),
445
511
  depth,
446
512
  });
@@ -26,15 +26,17 @@ export interface FigureEntry {
26
26
  export type CompiledDoc = Frontmatter & {
27
27
  id: string;
28
28
  subformat?: SubformatCollection;
29
+ /** Library view shown by a display page (`schemath`, `urls`, ...). */
30
+ library?: string;
29
31
  /** Parent doc id (SoT: dooc.yaml). Omitted = top level. docs[] is in pre-order. */
30
32
  parent?: string;
31
33
  /** Project-relative Markdown source path, or subformat:<ext> for a display page. */
32
34
  file: string;
33
- /** Resolved language (BCP 47): front-matter `lang`, else the site default (language.ts). */
35
+ /** Resolved language (BCP 47): the translation language, else the site default (language.ts). */
34
36
  lang: string;
35
37
  /** Sidebar icon (full content of icons/<id>.svg, 1:1). Omitted if there is none. */
36
38
  icon?: string;
37
- /** Source md (excluding front-matter). For MCP / copy; rendering uses blocks. */
39
+ /** Source md. For MCP / copy; rendering uses blocks. */
38
40
  body: string;
39
41
  /** Normalized Block AST (the blocks.ts contract). Consumers just map it to rendering. */
40
42
  blocks: Block[];
@@ -5,6 +5,7 @@ import { type LanguageAdapter } from "./language.js";
5
5
  import { type Frontmatter } from "./taxonomy.js";
6
6
  export { escapeHtml } from "./escape-html.js";
7
7
  export interface RenderCtx {
8
+ downloads?: ReadonlyMap<string, string>;
8
9
  /** Source file to published document route. */
9
10
  docLinks?: ReadonlyMap<string, string>;
10
11
  /** Figures including their markup (name → entry). */
@@ -17,6 +18,11 @@ export interface RenderCtx {
17
18
  lang?: string;
18
19
  /** Localized in-page table of contents title. Default: Contents. */
19
20
  tocTitle?: string;
21
+ /** Download URL of the page's own source, shown beside its title. */
22
+ pageDownload?: {
23
+ file: string;
24
+ href: string;
25
+ };
20
26
  /** Document URL for the viewer's section-copy buttons. */
21
27
  sectionUrl?: string;
22
28
  /**
@@ -28,5 +34,6 @@ export interface RenderCtx {
28
34
  export declare const emptyCtx: RenderCtx;
29
35
  /** Shared dictionary entries for definitions and the Resources list. */
30
36
  export declare const termsHtml: (terms: readonly TermEntry[], language?: LanguageAdapter, sortable?: boolean) => string;
37
+ export declare const resourceDownloadHtml: (file: string, href: string) => string;
31
38
  export declare const blocksHtml: (blocks: Block[], ctx?: RenderCtx) => string;
32
39
  export declare const docHtml: (fm: Frontmatter, blocks: Block[], errors: string[], ctx?: RenderCtx, toc?: TocEntry[]) => string;
@@ -5,15 +5,16 @@
5
5
  import { escapeHtml } from "./escape-html.js";
6
6
  import { figureFrameHtml } from "./figure-frame.js";
7
7
  import { parseFigureLink } from "./file-embed.js";
8
+ import { localFile } from "./files.js";
8
9
  import { GRAPH_LAYOUT_MARGIN, GRAPH_LEGEND, graphUid, layoutGraph, } from "./graph.js";
9
10
  import { CHECK_ICON } from "./icons.js";
10
11
  import { inlineSegmenter, termMap } from "./inline.js";
11
12
  import { termComparator } from "./language.js";
12
- import { parseDocLink } from "./routing.js";
13
+ import { isReferenceUrl, parseDocLink } from "./routing.js";
13
14
  import { layoutSchemaGraph, SCHEMA_LAYOUT_MARGIN, schemaGraphClientData, schemaGraphUid, } from "./schema-graph.js";
14
15
  import { docDisplayName } from "./taxonomy.js";
15
16
  import { termAnchor } from "./term-reference.js";
16
- import { textfileName } from "./textfile.js";
17
+ import { parseFileReference, textfileName } from "./textfile.js";
17
18
  export { escapeHtml } from "./escape-html.js";
18
19
  export const emptyCtx = { figures: new Map(), terms: [] };
19
20
  // File links open their resource page; SVGs and terms also have hover previews.
@@ -31,6 +32,8 @@ const inlineHtml = (segments, ctx) => segments
31
32
  return `<em>${inlineHtml(s.children, ctx)}</em>`;
32
33
  case "link": {
33
34
  const label = s.children ? inlineHtml(s.children, ctx) : escapeHtml(s.text);
35
+ if (!isReferenceUrl(s.url))
36
+ return label;
34
37
  let href = s.url;
35
38
  try {
36
39
  const ref = parseDocLink(s.url);
@@ -39,6 +42,15 @@ const inlineHtml = (segments, ctx) => segments
39
42
  href =
40
43
  target +
41
44
  (ref.fragment ? `#${encodeURIComponent(ref.fragment)}` : "");
45
+ // Other local files open their resource page instead of a dead relative URL.
46
+ if (!ref && !/^(?:[a-z][a-z\d+.-]*:|[/#])/i.test(s.url)) {
47
+ const { file, range } = parseFileReference(s.url);
48
+ const local = file.replace(/^(\.\/)+/, "");
49
+ if (localFile(local))
50
+ href =
51
+ `/_files/file/${encodeURIComponent(local)}` +
52
+ (range ? `#${encodeURIComponent(range.slice(1))}` : "");
53
+ }
42
54
  const figureRef = parseFigureLink(s.url);
43
55
  const fig = figureRef &&
44
56
  [...ctx.figures.values()].find((fig) => fig.file === figureRef.file);
@@ -334,7 +346,36 @@ export const termsHtml = (terms, language, sortable = false) => {
334
346
  .map((e, i) => `<fieldset class="dict-card" data-source-order="${e.sourceOrder}" data-sort-order="${i}" data-term="${escapeHtml(e.id)}"><legend id="${termAnchor(e.id)}">${TERM_ICON}<a class="term-name" href="/_files/terms#${encodeURIComponent(termAnchor(e.id))}"${e.description ? ` aria-describedby="term-description-${encodeURIComponent(e.id)}"` : ""}>${escapeHtml(e.name)}${e.description ? `<span class="term-description" role="tooltip" id="term-description-${encodeURIComponent(e.id)}">${escapeHtml(e.description)}</span>` : ""}</a></legend><p class="term-definition">${escapeHtml(e.definition)}</p></fieldset>`)
335
347
  .join("")}</div></section>`;
336
348
  };
349
+ export const resourceDownloadHtml = (file, href) => `<a class="resource-download" href="${escapeHtml(href)}" download="${escapeHtml(textfileName(file))}" data-resource-download title="${escapeHtml(`Download ${textfileName(file)}`)}" aria-label="${escapeHtml(`Download ${textfileName(file)}`)}"><svg viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 2v10m-4-4 4 4 4-4M3 13v4h14v-4"/></svg></a>`;
337
350
  const blockHtml = (b, ctx, seg) => {
351
+ const html = blockContentHtml(b, ctx, seg);
352
+ if (!ctx.downloads || (b.type === "code" && b.unavailable))
353
+ return html;
354
+ const file = b.sourceFile ??
355
+ (b.type === "code"
356
+ ? b.filename
357
+ : b.type === "figureRef"
358
+ ? ctx.figures.get(b.name)?.file
359
+ : b.type === "external"
360
+ ? b.url
361
+ : undefined);
362
+ if (!file)
363
+ return html;
364
+ const remote = b.type === "external" ? new URL(file) : undefined;
365
+ const href = ctx.downloads.get(file.replace(/^(\.\/)+/, "")) ??
366
+ (remote && /^https?:$/.test(remote.protocol) && !remote.username && !remote.password
367
+ ? file
368
+ : undefined);
369
+ if (!href)
370
+ return html;
371
+ const link = resourceDownloadHtml(file, href);
372
+ // Code blocks carry the download beside their copy button; other blocks get a corner overlay.
373
+ const copy = '<button class="codecopy"';
374
+ if (b.type === "code" && html.includes(copy))
375
+ return html.replace(copy, link + copy);
376
+ return `<div class="downloadable-resource"><div class="resource-download-tools">${link}</div>${html}</div>`;
377
+ };
378
+ const blockContentHtml = (b, ctx, seg) => {
338
379
  switch (b.type) {
339
380
  case "themeVariants":
340
381
  return `<div data-theme-variants><div data-theme-variant="">${blockHtml(b.default, ctx, seg)}</div>${Object.entries(b.variants)
@@ -441,5 +482,5 @@ export const docHtml = (fm, blocks, errors, ctx = emptyCtx, toc = []) => {
441
482
  ? `<div class="errors">${errors.map((e) => `<div>${escapeHtml(e)}</div>`).join("")}</div>`
442
483
  : "";
443
484
  const lang = ctx.lang ? ` lang="${escapeHtml(ctx.lang)}"` : "";
444
- return `<article${lang}>${errBox}<header class="doc-title"><h1>${escapeHtml(docDisplayName(fm, ""))}</h1>${inPageTocHtml(toc, ctx.tocTitle)}</header>${blocksHtml(blocks, ctx)}</article>`;
485
+ return `<article${lang}>${errBox}<header class="doc-title"><h1>${escapeHtml(docDisplayName(fm, ""))}</h1>${ctx.pageDownload ? resourceDownloadHtml(ctx.pageDownload.file, ctx.pageDownload.href) : ""}${inPageTocHtml(toc, ctx.tocTitle)}</header>${blocksHtml(blocks, ctx)}</article>`;
445
486
  };
@@ -3,3 +3,6 @@ export declare const RELOAD_ICON_PATH = "M17 8a7 7 0 1 0 0 5M17 3v5h-5";
3
3
  export declare const SEARCH_ICON_PATH = "M14 14l4 4M15 9a6 6 0 1 1-12 0 6 6 0 0 1 12 0";
4
4
  export declare const CHECK_ICON = "<svg class=\"ic-ok\" viewBox=\"0 0 20 20\" width=\"14\" height=\"14\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m4 10 4 4 8-8\"/></svg>";
5
5
  export declare const PLUGINS_ICON = "<svg class=\"nav-icon\" viewBox=\"0 0 20 20\" width=\"18\" height=\"18\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m10 2 4 2v5l-4 2-4-2V4Zm-4 2 4 2 4-2m-4 2v5M6 9l-4 2v5l4 2 4-2v-5m-8 0 4 2 4-2m-4 2v5m8-9 4 2v5l-4 2-4-2m0-5 4 2 4-2m-4 2v5\"/></svg>";
6
+ /** One glyph per Library view, so views are told apart without reading their names. */
7
+ export declare const LIBRARY_ICONS: Readonly<Record<string, string>>;
8
+ export declare const libraryIcon: (view: string) => string | undefined;
@@ -0,0 +1,20 @@
1
+ export const FOLDER_ICON_PATH = "M2 5h6l2 2h8v10H2Z";
2
+ export const RELOAD_ICON_PATH = "M17 8a7 7 0 1 0 0 5M17 3v5h-5";
3
+ export const SEARCH_ICON_PATH = "M14 14l4 4M15 9a6 6 0 1 1-12 0 6 6 0 0 1 12 0";
4
+ export const CHECK_ICON = '<svg class="ic-ok" viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 10 4 4 8-8"/></svg>';
5
+ export const PLUGINS_ICON = '<svg class="nav-icon" viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m10 2 4 2v5l-4 2-4-2V4Zm-4 2 4 2 4-2m-4 2v5M6 9l-4 2v5l4 2 4-2v-5m-8 0 4 2 4-2m-4 2v5m8-9 4 2v5l-4 2-4-2m0-5 4 2 4-2m-4 2v5"/></svg>';
6
+ const glyph = (paths) => `<svg class="nav-icon" viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths}</svg>`;
7
+ /** One glyph per Library view, so views are told apart without reading their names. */
8
+ export const LIBRARY_ICONS = {
9
+ codeblocks: glyph('<path d="m7 6-4 4 4 4M13 6l4 4-4 4"/>'),
10
+ urls: glyph('<path d="M8.5 11.5a3 3 0 0 0 4.2 0l3-3a3 3 0 0 0-4.2-4.2l-1 1M11.5 8.5a3 3 0 0 0-4.2 0l-3 3a3 3 0 0 0 4.2 4.2l1-1"/>'),
11
+ "url-previews": glyph('<rect x="3" y="4" width="14" height="12" rx="1.5"/><path d="M3 8h14M6 12.5h5"/>'),
12
+ csv: glyph('<rect x="3" y="4" width="14" height="12" rx="1"/><path d="M3 8h14M3 12h14M8 4v12"/>'),
13
+ tsv: glyph('<path d="M3 6h8M3 10h8M3 14h8M13.5 7l3 3-3 3M17 5v10"/>'),
14
+ mermaid: glyph('<rect x="3" y="3" width="6" height="4" rx="1"/><rect x="11" y="13" width="6" height="4" rx="1"/><path d="M6 7v6a2 2 0 0 0 2 2h3"/>'),
15
+ callouth: glyph('<path d="M4 4h12v9H9l-4 3v-3H4Z"/>'),
16
+ schemath: glyph('<ellipse cx="10" cy="5" rx="6" ry="2.5"/><path d="M4 5v10c0 1.4 2.7 2.5 6 2.5s6-1.1 6-2.5V5M4 10c0 1.4 2.7 2.5 6 2.5s6-1.1 6-2.5"/>'),
17
+ graphth: glyph('<circle cx="5" cy="10" r="2"/><circle cx="15" cy="5" r="2"/><circle cx="15" cy="15" r="2"/><path d="m6.8 9.1 6.4-3.2M6.8 10.9l6.4 3.2"/>'),
18
+ termth: glyph('<path d="M5 3h10v14H5Z"/><path d="m8 12 2-5 2 5M8.7 10.5h2.6"/>'),
19
+ };
20
+ export const libraryIcon = (view) => Object.hasOwn(LIBRARY_ICONS, view) ? LIBRARY_ICONS[view] : undefined;
@@ -6,6 +6,8 @@ export type DocRef = Pick<CompiledDoc, "id" | "parent"> & {
6
6
  };
7
7
  /** Parse `<docId>` (leading/trailing `/` are ignored). undefined if the shape differs. */
8
8
  export declare const parseRoutePath: (path: string) => string | undefined;
9
+ /** Authored links navigate to references; they cannot execute code or launch other protocols. */
10
+ export declare const isReferenceUrl: (url: string) => boolean;
9
11
  /** Document links use paths relative to the docs root and optional heading fragments. */
10
12
  export declare const parseDocLink: (url: string) => {
11
13
  file: string;
@@ -13,6 +13,15 @@ export const parseRoutePath = (path) => {
13
13
  const [id] = seg;
14
14
  return id != null && seg.length === 1 && isDocId(id) ? id : undefined;
15
15
  };
16
+ /** Authored links navigate to references; they cannot execute code or launch other protocols. */
17
+ export const isReferenceUrl = (url) => {
18
+ try {
19
+ return ["http:", "https:", "mailto:"].includes(new URL(url, "https://dooc.invalid/").protocol);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ };
16
25
  /** Document links use paths relative to the docs root and optional heading fragments. */
17
26
  export const parseDocLink = (url) => {
18
27
  if (/^(?:[a-z][a-z\d+.-]*:|\/)/i.test(url))
@@ -5,4 +5,4 @@ export interface SchemaContext {
5
5
  }
6
6
  /** Visit schema positions only; defaults, examples and enum values are data. */
7
7
  export declare const visitSchema: (schema: unknown, base: string, visit: (schema: SchemaObject, base: string) => void) => void;
8
- export declare const schemaResolver: (schema: SchemaObject, context?: SchemaContext) => (definition: unknown) => SchemaObject;
8
+ export declare const schemaResolver: (schema: SchemaObject, context?: SchemaContext) => (definition: unknown, onRef?: (uri: string) => void) => SchemaObject;
@@ -49,13 +49,15 @@ export const schemaResolver = (schema, context) => {
49
49
  resources.set(`${resolved.split("#")[0]}#${node[key]}`, node);
50
50
  });
51
51
  }
52
- return (definition) => {
52
+ /** `onRef` receives the absolute URI of every `$ref` hop followed. */
53
+ return (definition, onRef) => {
53
54
  let current = schemaObject(definition) ? definition : {};
54
55
  let result = current;
55
56
  const seen = new Set();
56
57
  while (typeof current.$ref === "string" && !seen.has(current)) {
57
58
  seen.add(current);
58
59
  const uri = new URL(current.$ref, bases.get(current) ?? base);
60
+ onRef?.(uri.href);
59
61
  let target = resources.get(uri.href);
60
62
  if (target === undefined) {
61
63
  const fragment = decodeURIComponent(uri.hash.slice(1));
@@ -0,0 +1,5 @@
1
+ import type { Root } from "mdast";
2
+ export declare const subformatReferences: (tree: Root) => {
3
+ file: string;
4
+ line: number;
5
+ }[];
@@ -0,0 +1,33 @@
1
+ import { visit } from "unist-util-visit";
2
+ import { localFile } from "./files.js";
3
+ import { parseMdast } from "./markdown.js";
4
+ import { parseFileReference } from "./textfile.js";
5
+ export const subformatReferences = (tree) => {
6
+ const references = [];
7
+ const definitions = new Map();
8
+ visit(tree, "definition", (node) => {
9
+ definitions.set(node.identifier, node.url);
10
+ });
11
+ visit(tree, (node) => {
12
+ if (node.type === "code" && node.lang?.toLowerCase() === "callouth") {
13
+ for (const ref of subformatReferences(parseMdast(node.value)))
14
+ references.push({ ...ref, line: ref.line + (node.position?.start.line ?? 1) });
15
+ }
16
+ const target = node.type === "link" || node.type === "image"
17
+ ? node.url
18
+ : node.type === "linkReference" || node.type === "imageReference"
19
+ ? definitions.get(node.identifier)
20
+ : undefined;
21
+ if (!target || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(target))
22
+ return;
23
+ try {
24
+ const file = parseFileReference(target).file.replace(/^(\.\/)+/, "");
25
+ if (localFile(file))
26
+ references.push({ file, line: node.position?.start.line ?? 1 });
27
+ }
28
+ catch {
29
+ // Invalid references are reported by the compiler.
30
+ }
31
+ });
32
+ return references;
33
+ };
@@ -4,6 +4,8 @@ export interface Subformat {
4
4
  ext: string;
5
5
  format: "yaml" | "json" | "toml";
6
6
  schema: string;
7
+ /** Local SVG file shown wherever the subformat is listed. */
8
+ icon?: string;
7
9
  layouts?: {
8
10
  card_title?: string;
9
11
  group_by?: string;
@@ -18,6 +20,8 @@ export interface SubformatField {
18
20
  enum?: (string | number | boolean | null)[];
19
21
  format?: "date" | "date-time";
20
22
  readOnly?: boolean;
23
+ /** Record files a reference field may point to (its pattern ends with `\\.<ext>$`). */
24
+ options?: string[];
21
25
  }
22
26
  export interface SubformatRecord {
23
27
  file: string;
@@ -27,11 +31,14 @@ export interface SubformatRecord {
27
31
  references?: {
28
32
  file: string;
29
33
  line: number;
34
+ href?: string;
30
35
  }[];
31
36
  }
32
37
  export interface SubformatCollection extends Subformat {
33
38
  change?: "added" | "modified";
34
39
  baseLayouts?: NonNullable<Subformat["layouts"]>;
40
+ /** Markup of `icon`, normalized to a square. */
41
+ iconSvg?: string;
35
42
  fields: SubformatField[];
36
43
  template?: string;
37
44
  defaultFolder?: string;
@@ -21,7 +21,7 @@ export const parseSubformats = (input) => {
21
21
  if (!value ||
22
22
  typeof value !== "object" ||
23
23
  Array.isArray(value) ||
24
- Object.keys(value).some((key) => !["ext", "format", "schema", "layouts"].includes(key)) ||
24
+ Object.keys(value).some((key) => !["ext", "format", "schema", "icon", "layouts"].includes(key)) ||
25
25
  typeof value.ext !== "string" ||
26
26
  !/^[a-z0-9][a-z0-9_-]*$/.test(value.ext) ||
27
27
  !["yaml", "json", "toml"].includes(value.format) ||
@@ -36,6 +36,9 @@ export const parseSubformats = (input) => {
36
36
  : !["card_title", "group_by", "sort_by"].includes(key) ||
37
37
  typeof item !== "string")))
38
38
  throw new Error("Subformat layouts accept card_title, group_by, sort_by field names and sort_order (asc or desc)");
39
+ if (value.icon !== undefined &&
40
+ (!localFile(value.icon) || !value.icon.toLowerCase().endsWith(".svg")))
41
+ throw new Error("Subformat icon must be a local .svg file path");
39
42
  if (seen.has(value.ext))
40
43
  throw new Error(`Duplicate subformat extension: ${value.ext}`);
41
44
  seen.add(value.ext);
@@ -43,6 +46,7 @@ export const parseSubformats = (input) => {
43
46
  ext: value.ext,
44
47
  format: value.format,
45
48
  schema: value.schema,
49
+ ...(value.icon === undefined ? {} : { icon: value.icon }),
46
50
  ...(value.layouts === undefined ? {} : { layouts: { ...value.layouts } }),
47
51
  };
48
52
  });
@@ -1,12 +1,11 @@
1
1
  export declare const CODE_TEMPLATES: Readonly<Record<string, string>>;
2
2
  export declare const CODE_LANGS: readonly ["javascript", "typescript", "jsx", "tsx", "python", "java", "c", "cpp", "csharp", "go", "rust", "ruby", "php", "swift", "kotlin", "bash", "powershell", "html", "css", "json", "yaml", "toml", "sql", "markdown", "dockerfile", "diff", "graphql", "terraform", ...string[]];
3
3
  export type CodeLang = string;
4
- export declare const FM_REQUIRED: readonly ["title"];
5
- export declare const FM_OPTIONAL: readonly ["lang"];
4
+ /** Document metadata; the title comes from the manifest, never from the Markdown file. */
6
5
  export interface Frontmatter {
7
6
  title: string;
8
7
  /** BCP 47 tag of the doc's language (language.ts). Omitted = the site default. */
9
8
  lang?: string;
10
9
  }
11
- /** Display name of a doc (nav / headings / listings). Falls back if front-matter is broken. */
10
+ /** Display name of a doc (nav / headings / listings). */
12
11
  export declare const docDisplayName: (fm: Frontmatter | undefined, fallback: string) => string;
@@ -41,9 +41,5 @@ export const CODE_LANGS = [
41
41
  "terraform",
42
42
  ...Object.keys(CODE_TEMPLATES),
43
43
  ];
44
- // Front-matter schema (the hierarchy's SoT is dooc.yaml, so it is not written in
45
- // front-matter; writing it there is an unknown-key error).
46
- export const FM_REQUIRED = ["title"];
47
- export const FM_OPTIONAL = ["lang"];
48
- /** Display name of a doc (nav / headings / listings). Falls back if front-matter is broken. */
44
+ /** Display name of a doc (nav / headings / listings). */
49
45
  export const docDisplayName = (fm, fallback) => fm?.title ?? fallback;