@dooc-dev/dooc 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/cli.js +128 -67
  2. package/dist/code-worker.global.js +152 -0
  3. package/dist/code.global.js +101 -101
  4. package/dist/compiler/bundle-urls.js +2 -0
  5. package/dist/compiler/check.js +2 -0
  6. package/dist/compiler/compile.js +13 -3
  7. package/dist/compiler/dxf.d.ts +1 -0
  8. package/dist/compiler/dxf.js +81 -0
  9. package/dist/compiler/export.js +22 -15
  10. package/dist/compiler/figures.js +39 -10
  11. package/dist/compiler/files.js +2 -0
  12. package/dist/compiler/ignored-files.d.ts +2 -0
  13. package/dist/compiler/ignored-files.js +30 -0
  14. package/dist/compiler/ops.js +1 -1
  15. package/dist/compiler/subformat-schema.d.ts +14 -0
  16. package/dist/compiler/subformat-schema.js +92 -0
  17. package/dist/compiler/subformats.d.ts +5 -7
  18. package/dist/compiler/subformats.js +115 -75
  19. package/dist/core/code-file.js +7 -5
  20. package/dist/core/code-grammars.d.ts +5 -0
  21. package/dist/core/code-grammars.js +34 -0
  22. package/dist/core/content-metadata.d.ts +2 -1
  23. package/dist/core/content-metadata.js +7 -2
  24. package/dist/core/content-types.d.ts +1 -1
  25. package/dist/core/escape-html.d.ts +1 -0
  26. package/dist/core/escape-html.js +1 -0
  27. package/dist/core/figure-frame.js +1 -1
  28. package/dist/core/file-embed.js +7 -3
  29. package/dist/core/html.d.ts +4 -1
  30. package/dist/core/html.js +8 -7
  31. package/dist/core/language.js +5 -2
  32. package/dist/core/markdown.js +3 -1
  33. package/dist/core/previewers.d.ts +8 -0
  34. package/dist/core/previewers.js +2 -0
  35. package/dist/core/schema-fields.d.ts +13 -0
  36. package/dist/core/schema-fields.js +175 -0
  37. package/dist/core/schema-graph-mount.js +26 -3
  38. package/dist/core/schema-refs.d.ts +8 -0
  39. package/dist/core/schema-refs.js +82 -0
  40. package/dist/core/toc-ui.js +1 -1
  41. package/dist/edit.global.js +266 -285
  42. package/dist/flow.global.js +3 -3
  43. package/dist/graph/abnfDiagram-S7VZAUFO-ASBULSKE.js +1 -0
  44. package/dist/graph/architecture-WOLXFQ4H-V57EDXXY.js +1 -0
  45. package/dist/graph/architectureDiagram-YGSQEFNW-GIMP347N.js +36 -0
  46. package/dist/graph/blockDiagram-APKKGZFW-RDL2T4JW.js +140 -0
  47. package/dist/graph/bpmnIcons-APHXDYXF-TWOSQNUQ.js +1 -0
  48. package/dist/graph/c4Diagram-KJ2TOQU5-75LIUC4F.js +38 -0
  49. package/dist/graph/chunk-26TUJSYJ.js +1 -0
  50. package/dist/graph/chunk-3LU66YMI.js +1 -0
  51. package/dist/graph/chunk-3RNHDNP5.js +1 -0
  52. package/dist/graph/chunk-3Y2PDVDE.js +1 -0
  53. package/dist/graph/chunk-3YJHMOOA.js +3 -0
  54. package/dist/graph/chunk-4KILFWYV.js +339 -0
  55. package/dist/graph/chunk-4QDE4SUK.js +1 -0
  56. package/dist/graph/chunk-5OO6DATX.js +1 -0
  57. package/dist/graph/chunk-5UUEAHTN.js +1 -0
  58. package/dist/graph/chunk-6T55RVVR.js +1 -0
  59. package/dist/graph/chunk-ARAJTKOH.js +2 -0
  60. package/dist/graph/chunk-BBD5CEDC.js +72 -0
  61. package/dist/graph/chunk-BVXT562I.js +1 -0
  62. package/dist/graph/chunk-BZAMCJ6B.js +32 -0
  63. package/dist/graph/chunk-C6J4A356.js +15 -0
  64. package/dist/graph/chunk-EG5UVNOC.js +213 -0
  65. package/dist/graph/chunk-GF4TOPUK.js +1 -0
  66. package/dist/graph/chunk-GYT4IYBZ.js +1 -0
  67. package/dist/graph/chunk-HJG2HUYJ.js +88 -0
  68. package/dist/graph/chunk-HOPPTA6H.js +62 -0
  69. package/dist/graph/chunk-I3DMZIHV.js +1 -0
  70. package/dist/graph/chunk-IC23EEF6.js +1 -0
  71. package/dist/graph/chunk-ISO77HML.js +1 -0
  72. package/dist/graph/chunk-JD7ZBJD2.js +1 -0
  73. package/dist/graph/chunk-JRSH5GNS.js +1 -0
  74. package/dist/graph/chunk-JSHWCPFJ.js +1 -0
  75. package/dist/graph/chunk-K2KLZU7M.js +10 -0
  76. package/dist/graph/chunk-K4I76XBX.js +14 -0
  77. package/dist/graph/chunk-KT4VPQD5.js +135 -0
  78. package/dist/graph/chunk-KU6GTEMS.js +1 -0
  79. package/dist/graph/chunk-LT6LXKCR.js +136 -0
  80. package/dist/graph/chunk-MPR575IN.js +1 -0
  81. package/dist/graph/chunk-N3OHKGRZ.js +1 -0
  82. package/dist/graph/chunk-O656ZI37.js +1 -0
  83. package/dist/graph/chunk-OFZLK5G4.js +1 -0
  84. package/dist/graph/chunk-PDH25ALM.js +2 -0
  85. package/dist/graph/chunk-PW2RGZ3O.js +1 -0
  86. package/dist/graph/chunk-QCJUF4YA.js +1 -0
  87. package/dist/graph/chunk-QEEA3KYY.js +2 -0
  88. package/dist/graph/chunk-QYAXYFNI.js +1 -0
  89. package/dist/graph/chunk-QYTM6GY3.js +1 -0
  90. package/dist/graph/chunk-R63JUMUK.js +1 -0
  91. package/dist/graph/chunk-SCEY3ZPT.js +1 -0
  92. package/dist/graph/chunk-VM2H7G2R.js +1 -0
  93. package/dist/graph/chunk-XQS73SBQ.js +1 -0
  94. package/dist/graph/chunk-YCRLJT2S.js +1 -0
  95. package/dist/graph/chunk-Z4FIZ7CR.js +1 -0
  96. package/dist/graph/chunk-ZMCB7VP2.js +1 -0
  97. package/dist/graph/chunk-ZSZXN4BT.js +2 -0
  98. package/dist/graph/classDiagram-v2-L25IHNXF-JL7LVDZH.js +217 -0
  99. package/dist/graph/cose-bilkent-JH36ORCC-PNM3EYPB.js +1 -0
  100. package/dist/graph/cynefin-EF2NZ3EQ-PSXP3DXL.js +1 -0
  101. package/dist/graph/cynefinDiagram-L36ESFBY-QVY54CXO.js +62 -0
  102. package/dist/graph/dagre-SPEB5RXH-HPGQXBZJ.js +4 -0
  103. package/dist/graph/diagram-3B7GL73J-DWH5WS2P.js +200 -0
  104. package/dist/graph/diagram-DNEMPZML-TEGH2U5I.js +24 -0
  105. package/dist/graph/diagram-L3MUGCDN-X4MREUWR.js +41 -0
  106. package/dist/graph/diagram-LA4NIPWU-NXT746HG.js +24 -0
  107. package/dist/graph/diagram-MHCOC4E2-JGHXSAGS.js +3 -0
  108. package/dist/graph/diagram-XPFHEONP-ZHZPBLT4.js +30 -0
  109. package/dist/graph/ebnfDiagram-UZSYDL2S-SMF6KJ43.js +1 -0
  110. package/dist/graph/elk-XV6XMXQE-AZ4HLCWI.js +27 -0
  111. package/dist/graph/erDiagram-EYBAPDEH-B3JNJ357.js +99 -0
  112. package/dist/graph/eventmodeling-K75KTNOO-WG6DDYMC.js +1 -0
  113. package/dist/graph/flowDiagram-MALGAFMO-2R7EYAQI.js +1 -0
  114. package/dist/graph/ganttDiagram-23REXITY-YXBYWFOJ.js +292 -0
  115. package/dist/graph/gitGraph-VSP46ZUC-VBFWJBBT.js +1 -0
  116. package/dist/graph/gitGraphDiagram-STJD7YCW-4FZDCFGV.js +106 -0
  117. package/dist/graph/info-OHQRW6UA-ALVDUVYV.js +1 -0
  118. package/dist/graph/infoDiagram-KBXO4MBG-7EHX2GQG.js +2 -0
  119. package/dist/graph/ishikawaDiagram-M35NCXHK-FRZD2PWQ.js +70 -0
  120. package/dist/graph/journeyDiagram-OPLOXDXO-7Z66JCPR.js +139 -0
  121. package/dist/graph/kanban-definition-BZKZHSQY-NN5AIKTE.js +89 -0
  122. package/dist/graph/katex-DXDNVO6V.js +257 -0
  123. package/dist/graph/mindmap-definition-I2QAS2VK-HDPCABN2.js +98 -0
  124. package/dist/graph/packet-JDAUHWVQ-5MQIBWAH.js +1 -0
  125. package/dist/graph/pegDiagram-FD4XPPHP-H2BFNCKT.js +1 -0
  126. package/dist/graph/pie-XZMESJXO-T5VRKHVT.js +1 -0
  127. package/dist/graph/pieDiagram-J4AKIIQI-O3NJSVD3.js +39 -0
  128. package/dist/graph/quadrantDiagram-XTYBLID2-TMTZJI3P.js +7 -0
  129. package/dist/graph/radar-ABXABTNO-C6FXIBYW.js +1 -0
  130. package/dist/graph/railroad-I3PHUGI6-ZSO5JXB3.js +1 -0
  131. package/dist/graph/railroad-abnf-LNEFI6M7-CI4GQRHB.js +1 -0
  132. package/dist/graph/railroad-ebnf-DWYD2UWJ-MUENNCGK.js +1 -0
  133. package/dist/graph/railroad-peg-JR7BVNR7-N3X5GGIX.js +1 -0
  134. package/dist/graph/railroadDiagram-MRQ6NCDL-JHWS23UO.js +1 -0
  135. package/dist/graph/requirementDiagram-Y7LWUY3S-7DVLPO4B.js +84 -0
  136. package/dist/graph/sankeyDiagram-WGJFYUXA-Z5L4R5TR.js +40 -0
  137. package/dist/graph/schema-graph-global.js +639 -0
  138. package/dist/graph/sequenceDiagram-5NDRBG5M-RCTU25NT.js +169 -0
  139. package/dist/graph/sizeCapture-INFHLROL-RROY32P5.js +1 -0
  140. package/dist/graph/stateDiagram-v2-FJ4FJNEA-BXUSPWDK.js +291 -0
  141. package/dist/graph/swimlanes-UMQ2AFYF-LDD74Q2S.js +1 -0
  142. package/dist/graph/swimlanesDiagram-OMPLPG4O-ZYULLJSU.js +8 -0
  143. package/dist/graph/timeline-definition-SEUHKTQE-ZQSMIVAS.js +120 -0
  144. package/dist/graph/treeView-D4JQ5SDB-42S7U73N.js +1 -0
  145. package/dist/graph/treemap-SAJKECNS-RUBYQ7XF.js +1 -0
  146. package/dist/graph/usecaseDiagram-AFA6YXN4-57RDRYXF.js +370 -0
  147. package/dist/graph/vennDiagram-NNMJR3RB-5C3LVAV6.js +34 -0
  148. package/dist/graph/wardley-7MLQ67FV-NV5HXTTC.js +1 -0
  149. package/dist/graph/wardleyDiagram-S7YFUSEH-6D5BKXHM.js +78 -0
  150. package/dist/graph/xychartDiagram-GGNKY7IX-6ET3ZM67.js +7 -0
  151. package/dist/mcp.js +5 -4
  152. package/dist/plugins.global.js +71 -104
  153. package/dist/subformats.global.js +6 -112
  154. package/dist/ui.global.js +75 -108
  155. package/dist/viewer/build.d.ts +2 -0
  156. package/dist/viewer/build.js +22 -8
  157. package/dist/viewer/code-file.js +7 -2
  158. package/dist/viewer/figure-preview.d.ts +4 -0
  159. package/dist/viewer/figure-preview.js +54 -0
  160. package/dist/viewer/hmr.js +4 -3
  161. package/dist/viewer/lazy-preview.d.ts +2 -0
  162. package/dist/viewer/lazy-preview.js +43 -0
  163. package/dist/viewer/locales/eng.json +26 -3
  164. package/dist/viewer/locales/jpn.json +26 -3
  165. package/dist/viewer/locales/zho.json +26 -3
  166. package/dist/viewer/plugin-blocks.js +1 -1
  167. package/dist/viewer/plugins.js +1 -1
  168. package/dist/viewer/resource-library.d.ts +1 -1
  169. package/dist/viewer/resource-library.js +5 -4
  170. package/dist/viewer/serve.d.ts +2 -1
  171. package/dist/viewer/serve.js +148 -41
  172. package/dist/viewer/textfile.d.ts +2 -0
  173. package/dist/viewer/textfile.js +20 -5
  174. package/package.json +5 -3
  175. package/dist/viewer/lazy-graph.d.ts +0 -2
  176. package/dist/viewer/lazy-graph.js +0 -30
@@ -24,6 +24,8 @@ const types = {
24
24
  webp: "image/webp",
25
25
  mp4: "video/mp4",
26
26
  webm: "video/webm",
27
+ pdf: "application/pdf",
28
+ dxf: "image/vnd.dxf",
27
29
  woff: "font/woff",
28
30
  woff2: "font/woff2",
29
31
  ttf: "font/ttf",
@@ -175,6 +175,8 @@ export const checkSite = (root, options = {}) => {
175
175
  add("MANIFEST_INVALID", "error", MANIFEST_FILE, message);
176
176
  if (manifest.errors.length)
177
177
  return finish(report, options);
178
+ if (manifest.licence)
179
+ read(manifest.licence, { sourceFile: MANIFEST_FILE });
178
180
  let sourceLanguage;
179
181
  try {
180
182
  sourceLanguage = contentLanguageCode(manifest.defaultLang ?? DEFAULT_LANG);
@@ -1,6 +1,6 @@
1
1
  // Reads dooc.yaml and source files into validated, in-memory content for the viewer and HTML
2
2
  // bundles. createCompiler caches unchanged files; compileSite performs a one-shot compilation.
3
- import { existsSync, readdirSync } from "node:fs";
3
+ import { existsSync, readdirSync, statSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { walkBlocks } from "../core/blocks.js";
6
6
  import { docIdOfFile, flattenTree, MANIFEST_FILE } from "../core/content-metadata.js";
@@ -245,10 +245,20 @@ export const createCompiler = (root, options = {}) => {
245
245
  const paths = projectFiles(root);
246
246
  const visualFiles = paths
247
247
  .map((file) => file.path)
248
- .filter((file) => /\.(svg|html|png|webp|gif|mp4|webm|jpe?g)$/.test(file));
248
+ .filter((file) => /\.(svg|html|png|webp|gif|mp4|webm|jpe?g|pdf|dxf)$/i.test(file));
249
249
  const { figures, errors: figErrors } = figuresCache.get(dirSig(figuresDir) +
250
250
  visualFiles.map((file) => `${file}:${fileSig(textfilePath(root, file))}`).join("|"), () => loadFigures(figuresDir, visualFiles));
251
251
  const siteErrors = figErrors.filter((error) => error.startsWith("figures/"));
252
+ if (manifest.licence) {
253
+ try {
254
+ assertNotIgnored(root, manifest.licence);
255
+ if (!statSync(textfilePath(root, manifest.licence)).isFile())
256
+ throw new Error("expected a regular file");
257
+ }
258
+ catch (error) {
259
+ siteErrors.push(`${MANIFEST_FILE}: system.licence ${manifest.licence}: ${error instanceof Error ? error.message : error}`);
260
+ }
261
+ }
252
262
  if (!isLangTag(defaultLang)) {
253
263
  siteErrors.push("defaultLang must be a BCP 47 language tag");
254
264
  }
@@ -413,7 +423,7 @@ export const createCompiler = (root, options = {}) => {
413
423
  assertNotIgnored(root, config.schema);
414
424
  if (!paths.some((file) => file.path === config.schema))
415
425
  throw new Error("Subformat schema is not available in the workspace");
416
- const loaded = loadSubformat(root, config);
426
+ const loaded = loadSubformat(root, config, previews.domains);
417
427
  collection.fields = loaded.fields;
418
428
  collection.template = loaded.template;
419
429
  collection.defaultFolder = manifest.defaultSubformatFolder;
@@ -0,0 +1 @@
1
+ export declare const dxfSvg: (source: string) => string;
@@ -0,0 +1,81 @@
1
+ import { runInNewContext } from "node:vm";
2
+ import { Helper } from "dxf";
3
+ import { escapeHtml } from "../core/escape-html.js";
4
+ export const dxfSvg = (source) => {
5
+ source = source.replace(/\r\n?/g, "\n").trim();
6
+ if (source.includes("\0") ||
7
+ !/^\s*0\s*\nSECTION\s*$/m.test(source) ||
8
+ !/\n\s*0\s*\nEOF$/.test(source))
9
+ throw new Error("Expected an ASCII DXF file");
10
+ // Bound conversion time so malformed geometry cannot stall the synchronous compiler.
11
+ const output = runInNewContext("render()", {
12
+ render: () => {
13
+ const helper = new Helper(source);
14
+ return {
15
+ svg: helper.toSVG(),
16
+ texts: helper.parsed?.entities.filter((entity) => entity.type === "TEXT") ?? [],
17
+ };
18
+ },
19
+ }, { timeout: 2000 });
20
+ const svg = output.svg.replace(/^<\?xml[^>]*>\s*/, "");
21
+ const bounds = /viewBox="([^"]+)"/.exec(svg)?.[1]?.split(/\s+/).map(Number);
22
+ if (!bounds ||
23
+ bounds.length !== 4 ||
24
+ !bounds.every(Number.isFinite) ||
25
+ /NaN|Infinity/.test(svg))
26
+ throw new Error("DXF contains no supported 2D geometry");
27
+ const [x = 0, y = 0, width = 0, height = 0] = bounds;
28
+ const geometry = /<(?:path|circle|ellipse)\b/.test(svg);
29
+ let minX = geometry ? x : Number.POSITIVE_INFINITY;
30
+ let minY = geometry ? y : Number.POSITIVE_INFINITY;
31
+ let maxX = geometry ? x + width : Number.NEGATIVE_INFINITY;
32
+ let maxY = geometry ? y + height : Number.NEGATIVE_INFINITY;
33
+ const labels = [];
34
+ // shortcut: top-level TEXT uses a generic font; use a CAD renderer for block text, MTEXT and native dimensions.
35
+ for (const text of output.texts) {
36
+ if (!text.string || text.visible === false)
37
+ continue;
38
+ const aligned = text.hAlign || text.vAlign;
39
+ const tx = (aligned ? text.x2 : text.x) ?? text.x ?? 0;
40
+ const ty = -((aligned ? text.y2 : text.y) ?? text.y ?? 0);
41
+ const size = text.textHeight ?? 2.5;
42
+ const rotation = -(text.rotation ?? 0);
43
+ const scale = text.relScaleX ?? 1;
44
+ if (![tx, ty, size, rotation, scale].every(Number.isFinite) || size <= 0 || scale <= 0)
45
+ throw new Error("DXF text requires finite coordinates and a positive height and width scale");
46
+ const value = text.string.replace(/%%c/gi, "⌀").replace(/%%d/gi, "°").replace(/%%p/gi, "±");
47
+ const anchor = text.hAlign === 1 ? "middle" : text.hAlign === 2 ? "end" : "start";
48
+ const baseline = ["auto", "text-after-edge", "central", "text-before-edge"][text.vAlign ?? 0] ?? "auto";
49
+ const span = value.length * size * scale;
50
+ const left = anchor === "middle" ? -span / 2 : anchor === "end" ? -span : 0;
51
+ const angle = (rotation / 180) * Math.PI;
52
+ for (const dx of [left, left + span]) {
53
+ for (const dy of [-size, size]) {
54
+ const px = tx + dx * Math.cos(angle) - dy * Math.sin(angle);
55
+ const py = ty + dx * Math.sin(angle) + dy * Math.cos(angle);
56
+ minX = Math.min(minX, px);
57
+ minY = Math.min(minY, py);
58
+ maxX = Math.max(maxX, px);
59
+ maxY = Math.max(maxY, py);
60
+ }
61
+ }
62
+ labels.push(`<text transform="translate(${tx} ${ty}) rotate(${rotation}) scale(${scale} 1)" font-family="sans-serif" font-size="${size}" text-anchor="${anchor}" dominant-baseline="${baseline}" fill="var(--doc-fg, #000000)">${escapeHtml(value)}</text>`);
63
+ }
64
+ if (!geometry && !labels.length)
65
+ throw new Error("DXF contains no supported 2D geometry or text");
66
+ const padding = Math.max(maxX - minX, maxY - minY, 1) * 0.04;
67
+ const viewBox = [
68
+ minX - padding,
69
+ minY - padding,
70
+ maxX - minX + padding * 2,
71
+ maxY - minY + padding * 2,
72
+ ];
73
+ if (!viewBox.every(Number.isFinite))
74
+ throw new Error("DXF text exceeds finite preview bounds");
75
+ return svg
76
+ .replace(/viewBox="[^"]+"/, `viewBox="${viewBox.join(" ")}"`)
77
+ .replace('width="100%"', 'width="800"')
78
+ .replace(/<(path|circle|ellipse)\b/g, '<$1 vector-effect="non-scaling-stroke" stroke-width="1.25"')
79
+ .replace(/stroke="(?:#000000|rgb\(0, 0, 0\))"/g, 'stroke="var(--doc-fg, #000000)"')
80
+ .replace("</svg>", () => `${labels.join("")}</svg>`);
81
+ };
@@ -1,9 +1,11 @@
1
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
- import { posix } from "node:path";
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";
3
4
  import { visit } from "unist-util-visit";
4
5
  import { flattenTree, MANIFEST_FILE } from "../core/content-metadata.js";
5
6
  import { docFile, docIconFile, fileExtension, localFile } from "../core/files.js";
6
7
  import { contentLinks, parseMdast } from "../core/markdown.js";
8
+ import { visitSchema } from "../core/schema-refs.js";
7
9
  import { isRemoteTextfile, parseFileReference } from "../core/textfile.js";
8
10
  import { assetReferences } from "./asset-references.js";
9
11
  import { CODE_LANGUAGES_DIR } from "./code-languages.js";
@@ -44,6 +46,8 @@ export const exportEntries = (root) => {
44
46
  add(file);
45
47
  };
46
48
  add(MANIFEST_FILE);
49
+ if (manifest.licence)
50
+ add(manifest.licence);
47
51
  optional(CONFIG_FILE);
48
52
  for (const { id, subformat } of flattenTree(manifest.tree)) {
49
53
  const file = subformat ? undefined : docFile(id, manifest.files);
@@ -90,20 +94,23 @@ export const exportEntries = (root) => {
90
94
  };
91
95
  const schemas = new Set(manifest.subformats?.map((format) => format.schema));
92
96
  for (const file of schemas) {
93
- const refs = (value) => {
94
- if (!value || typeof value !== "object")
97
+ const document = JSON.parse(entries.get(file)?.data.toString("utf8") ?? "");
98
+ const baseUri = pathToFileURL(textfilePath(root, file)).href;
99
+ const resources = new Set([baseUri]);
100
+ visitSchema(document, baseUri, (_schema, base) => resources.add(base.split("#")[0] ?? base));
101
+ visitSchema(document, baseUri, (schema, base) => {
102
+ if (typeof schema.$ref !== "string")
95
103
  return;
96
- for (const [key, child] of Object.entries(value)) {
97
- if (key === "$ref" && typeof child === "string") {
98
- const dependency = relative(child, file);
99
- if (dependency)
100
- schemas.add(dependency);
101
- }
102
- else
103
- refs(child);
104
- }
105
- };
106
- refs(JSON.parse(entries.get(file)?.data.toString("utf8") ?? ""));
104
+ const uri = new URL(schema.$ref, base);
105
+ if (uri.protocol !== "file:")
106
+ return;
107
+ uri.hash = "";
108
+ if (resources.has(uri.href))
109
+ return;
110
+ const dependency = relativePath(realpathSync(root), fileURLToPath(uri)).replaceAll("\\", "/");
111
+ add(dependency);
112
+ schemas.add(dependency);
113
+ });
107
114
  }
108
115
  // Map iteration visits dependencies appended while walking the graph, once per path.
109
116
  for (const entry of entries.values()) {
@@ -22,11 +22,13 @@ import { createHash } from "node:crypto";
22
22
  // scheme (see the top of drawio.ts).
23
23
  import { readdirSync, readFileSync } from "node:fs";
24
24
  import { dirname } from "node:path";
25
+ import { escapeHtml } from "../core/escape-html.js";
25
26
  import { extractMxfile, isDrawioSvg, normalizeDrawioSvg } from "./drawio.js";
27
+ import { dxfSvg } from "./dxf.js";
26
28
  import { ignoredFiles } from "./ignored-files.js";
27
29
  import { textfilePath } from "./textfile.js";
28
- const EXT_RE = /\.(drawio\.svg|svg|html|png|webp|gif|mp4|webm|jpe?g)$/;
29
- const FILE_RE = /^[a-z0-9][a-z0-9_-]*\.(drawio\.svg|svg|html|png|webp|gif|mp4|webm|jpe?g)$/;
30
+ const EXT_RE = /\.(drawio\.svg|svg|html|png|webp|gif|mp4|webm|jpe?g|pdf|dxf)$/i;
31
+ const FILE_RE = /^[a-z0-9][a-z0-9_-]*\.(drawio\.svg|svg|html|png|webp|gif|mp4|webm|jpe?g|pdf|dxf)$/;
30
32
  const IMAGE_MIME = {
31
33
  png: "image/png",
32
34
  webp: "image/webp",
@@ -45,7 +47,7 @@ export const figureName = (file) => !FILE_RE.test(file.replace(/^figures\//, "")
45
47
  */
46
48
  export const figureUploadName = (raw) => {
47
49
  const lower = raw.toLowerCase().split(/[\\/]/).pop() ?? "";
48
- const ext = /\.(drawio\.svg|svg|html|png|webp|gif|mp4|webm|jpe?g)$/.exec(lower)?.[1];
50
+ const ext = EXT_RE.exec(lower)?.[1];
49
51
  if (ext == null) {
50
52
  return undefined;
51
53
  }
@@ -130,7 +132,7 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
130
132
  let files = [];
131
133
  try {
132
134
  files = readdirSync(figuresDir)
133
- .filter((f) => /\.(svg|html|png|webp|gif|mp4|webm|jpe?g)$/.test(f))
135
+ .filter((f) => EXT_RE.test(f))
134
136
  .sort();
135
137
  }
136
138
  catch {
@@ -145,7 +147,7 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
145
147
  if (file.startsWith("figures/") &&
146
148
  !file.slice(8).includes("/") &&
147
149
  !FILE_RE.test(file.slice(8))) {
148
- errors.push(`${file}: file name must be <name>.svg|.drawio.svg|.html|.png|.webp|.jpg|.jpeg ([a-z0-9_-])`);
150
+ errors.push(`${file}: file name must be <name>.<extension> using [a-z0-9_-] and a supported image, html, video, pdf or dxf extension`);
149
151
  continue;
150
152
  }
151
153
  const name = figureName(file);
@@ -154,7 +156,34 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
154
156
  errors.push(`${file}: duplicate name "${name}" (also used by ${dup.file})`);
155
157
  continue;
156
158
  }
157
- if (/\.(mp4|webm)$/.test(file)) {
159
+ if (/\.(pdf|dxf)$/i.test(file)) {
160
+ try {
161
+ const data = readFileSync(file.startsWith("figures/")
162
+ ? textfilePath(figuresDir, file.slice(8))
163
+ : textfilePath(dirname(figuresDir), file));
164
+ if (/\.dxf$/i.test(file)) {
165
+ const raw = new TextDecoder("utf-8", { fatal: true }).decode(data);
166
+ figures.push({ name, file, ...parseSvg(file, dxfSvg(raw), errors) });
167
+ }
168
+ else {
169
+ if (data.subarray(0, 5).toString("ascii") !== "%PDF-")
170
+ throw new Error("Expected a PDF file beginning with %PDF-");
171
+ const uri = `data:application/pdf;base64,${data.toString("base64")}`;
172
+ const download = `<a href="${uri}" download="${escapeHtml(file.split("/").at(-1) ?? "document.pdf")}" data-i18n="Download PDF">Download PDF</a>`;
173
+ figures.push({
174
+ name,
175
+ file,
176
+ kind: "pdf",
177
+ markup: `<object type="application/pdf" data="${uri}" aria-label="PDF preview" style="display:block;width:100%;height:640px;max-height:80vh;min-height:320px">${download}</object>${download}`,
178
+ });
179
+ }
180
+ }
181
+ catch (error) {
182
+ errors.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
183
+ }
184
+ continue;
185
+ }
186
+ if (/\.(mp4|webm)$/i.test(file)) {
158
187
  const data = readFileSync(file.startsWith("figures/")
159
188
  ? textfilePath(figuresDir, file.slice(8))
160
189
  : textfilePath(dirname(figuresDir), file));
@@ -162,11 +191,11 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
162
191
  name,
163
192
  file,
164
193
  kind: "video",
165
- markup: `<video data-dooc-video controls playsinline preload="metadata" aria-label="Video preview" src="data:video/${file.endsWith(".mp4") ? "mp4" : "webm"};base64,${data.toString("base64")}"></video>`,
194
+ markup: `<video data-dooc-video controls playsinline preload="metadata" aria-label="Video preview" src="data:video/${file.toLowerCase().endsWith(".mp4") ? "mp4" : "webm"};base64,${data.toString("base64")}"></video>`,
166
195
  });
167
196
  continue;
168
197
  }
169
- const mime = IMAGE_MIME[file.slice(file.lastIndexOf(".") + 1)];
198
+ const mime = IMAGE_MIME[file.slice(file.lastIndexOf(".") + 1).toLowerCase()];
170
199
  if (mime != null) {
171
200
  // Rasters are inlined as data URIs; Markdown embeds supply their alternative text.
172
201
  const data = readFileSync(file.startsWith("figures/")
@@ -185,11 +214,11 @@ export const loadFigures = (figuresDir, extraFiles = []) => {
185
214
  : textfilePath(dirname(figuresDir), file), "utf8");
186
215
  // The point of .drawio.svg is "can be reopened in draw.io", so the mxfile copy is required
187
216
  // (rejects an Export as > SVG output without the copy that was merely renamed).
188
- const editable = file.endsWith(".drawio.svg");
217
+ const editable = file.toLowerCase().endsWith(".drawio.svg");
189
218
  if (editable && !extractMxfile(raw)) {
190
219
  errors.push(`${file}: .drawio.svg doubles as the editable source, so it requires a copy of the mxfile (content=) (save it as .drawio.svg via File > Save as in draw.io)`);
191
220
  }
192
- const parsed = file.endsWith(".svg")
221
+ const parsed = file.toLowerCase().endsWith(".svg")
193
222
  ? parseSvg(file, editable || isDrawioSvg(raw) ? normalizeDrawioSvg(name, raw).markup : raw, errors)
194
223
  : parseHtml(file, raw, errors);
195
224
  if (/var\(--doc-[a-z0-9-]+\)/.test(parsed.markup)) {
@@ -352,6 +352,8 @@ export const updateFiles = (root, input) => {
352
352
  manifest.files = layout;
353
353
  if (manifest.icon && moves.has(manifest.icon))
354
354
  manifest.icon = moves.get(manifest.icon);
355
+ if (manifest.licence)
356
+ manifest.licence = moves.get(manifest.licence) ?? manifest.licence;
355
357
  if (manifest.themeIcons)
356
358
  for (const [theme, file] of Object.entries(manifest.themeIcons))
357
359
  manifest.themeIcons[theme] = moves.get(file) ?? file;
@@ -1,3 +1,5 @@
1
+ /** Share Git checks within one synchronous read, never across requests or writes. */
2
+ export declare const withIgnoredFilesCache: <T>(read: () => T) => T;
1
3
  /** Use Git's tracked-file and exclude rules; standalone folders use their .gitignore files. */
2
4
  export declare const ignoredFiles: (root: string, files: readonly string[]) => Set<string>;
3
5
  export declare const assertNotIgnored: (root: string, file: string) => void;
@@ -2,8 +2,38 @@ import { spawnSync } from "node:child_process";
2
2
  import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
3
3
  import { dirname, join, posix, relative, resolve, sep } from "node:path";
4
4
  import ignore, {} from "ignore";
5
+ let cached;
6
+ /** Share Git checks within one synchronous read, never across requests or writes. */
7
+ export const withIgnoredFilesCache = (read) => {
8
+ if (cached)
9
+ return read();
10
+ cached = new Map();
11
+ try {
12
+ return read();
13
+ }
14
+ finally {
15
+ cached = undefined;
16
+ }
17
+ };
5
18
  /** Use Git's tracked-file and exclude rules; standalone folders use their .gitignore files. */
6
19
  export const ignoredFiles = (root, files) => {
20
+ if (!cached)
21
+ return readIgnoredFiles(root, files);
22
+ const key = resolve(root);
23
+ let known = cached.get(key);
24
+ if (!known) {
25
+ known = new Map();
26
+ cached.set(key, known);
27
+ }
28
+ const missing = [...new Set(files.filter((file) => !known.has(file)))];
29
+ if (missing.length) {
30
+ const ignored = readIgnoredFiles(root, missing);
31
+ for (const file of missing)
32
+ known.set(file, ignored.has(file));
33
+ }
34
+ return new Set(files.filter((file) => known.get(file)));
35
+ };
36
+ const readIgnoredFiles = (root, files) => {
7
37
  if (!files.length)
8
38
  return new Set();
9
39
  const hasGit = (directory) => existsSync(join(directory, ".git", "HEAD")) ||
@@ -366,7 +366,7 @@ export const createDocOps = (root) => {
366
366
  const addFigure = (file, data) => {
367
367
  const upload = figureUploadName(file);
368
368
  if (!upload) {
369
- return { error: "specify an svg / png / webp / jpeg / html file", status: 400 };
369
+ return { error: "specify an image / html / video / pdf / dxf file", status: 400 };
370
370
  }
371
371
  if (data.length === 0 ||
372
372
  (upload.endsWith(".svg") && !data.toString("utf8").includes("<svg"))) {
@@ -0,0 +1,14 @@
1
+ import type { AnySchemaObject, ValidateFunction } from "ajv";
2
+ import { type SchemaContext } from "../core/schema-refs.js";
3
+ interface SchemaSource {
4
+ root: string;
5
+ file: string;
6
+ domains?: readonly string[];
7
+ }
8
+ export declare const compileSubformatSchema: (content: string, source?: SchemaSource) => {
9
+ schema: AnySchemaObject;
10
+ validate: ValidateFunction;
11
+ context: SchemaContext;
12
+ dependencies: Map<string, string>;
13
+ };
14
+ export {};
@@ -0,0 +1,92 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { relative } from "node:path";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
+ import { Ajv2020, MissingRefError } from "ajv/dist/2020.js";
5
+ import addFormats from "ajv-formats";
6
+ import { schemaObject } from "../core/schema-fields.js";
7
+ import { visitSchema } from "../core/schema-refs.js";
8
+ import { SUBFORMAT_SCHEMA_VERSION } from "../core/subformats.js";
9
+ import { readTextfile, textfilePath } from "./textfile.js";
10
+ const cache = new Map();
11
+ export const compileSubformatSchema = (content, source) => {
12
+ const uri = source
13
+ ? pathToFileURL(textfilePath(source.root, source.file)).href
14
+ : "file:///schema.json";
15
+ const key = JSON.stringify([uri, source?.domains ?? [], content]);
16
+ const read = (uri) => {
17
+ if (!source)
18
+ throw new Error("A schema file path is required to resolve external references");
19
+ try {
20
+ const url = new URL(uri);
21
+ if (url.protocol === "file:") {
22
+ if (url.search)
23
+ throw new Error("Local schema references cannot contain a query");
24
+ return readTextfile(source.root, relative(realpathSync(source.root), fileURLToPath(url)).replaceAll("\\", "/"));
25
+ }
26
+ if (!/^https?:$/.test(url.protocol))
27
+ throw new Error("Schema references require a local file or HTTPS URL");
28
+ return readTextfile(source.root, url.href, false, source.domains);
29
+ }
30
+ catch (error) {
31
+ throw new Error(`Cannot load schema ${uri}: ${error instanceof Error ? error.message : String(error)}`);
32
+ }
33
+ };
34
+ const cached = cache.get(key);
35
+ if (cached && [...cached.dependencies].every(([uri, text]) => read(uri) === text))
36
+ return cached;
37
+ const schema = JSON.parse(content);
38
+ if (!schemaObject(schema) || schema.$async)
39
+ throw new Error("Use a synchronous JSON object schema");
40
+ const context = { uri, schemas: {} };
41
+ const dependencies = new Map();
42
+ const ajv = new Ajv2020({ allErrors: true, strict: true, ownProperties: true });
43
+ addFormats.default(ajv);
44
+ // Ajv resolves anchors but omits their annotation keyword from the 2020-12 vocabulary.
45
+ ajv.addKeyword({ keyword: "$anchor", schemaType: "string" });
46
+ const add = (schema, uri) => {
47
+ if (typeof schema !== "boolean" && !schemaObject(schema))
48
+ throw new Error("Expected a JSON schema object or boolean");
49
+ visitSchema(schema, uri, (node, base) => {
50
+ if (node.$async)
51
+ throw new Error("Use a synchronous JSON object schema");
52
+ if (node.$schema !== undefined && node.$schema !== SUBFORMAT_SCHEMA_VERSION)
53
+ throw new Error(`Use JSON Schema 2020-12: ${SUBFORMAT_SCHEMA_VERSION}`);
54
+ if (/^https?:/.test(uri) &&
55
+ (new URL(base).protocol === "file:" ||
56
+ (typeof node.$ref === "string" &&
57
+ new URL(node.$ref, base).protocol === "file:")))
58
+ throw new Error("Remote schemas cannot reference local files");
59
+ });
60
+ context.schemas[uri] = schema;
61
+ const compiled = schemaObject(schema) && typeof schema.$id === "string"
62
+ ? { ...schema, $id: new URL(schema.$id, uri).href }
63
+ : schema;
64
+ ajv.addSchema(compiled, uri);
65
+ if (schemaObject(schema) && typeof schema.$anchor === "string")
66
+ ajv.addSchema(compiled, new URL(`#${schema.$anchor}`, schemaObject(compiled) && typeof compiled.$id === "string" ? compiled.$id : uri).href);
67
+ };
68
+ add(schema, uri);
69
+ let validate;
70
+ for (;;) {
71
+ try {
72
+ validate = ajv.getSchema(uri);
73
+ break;
74
+ }
75
+ catch (error) {
76
+ if (!(error instanceof MissingRefError) || ajv.refs[error.missingSchema])
77
+ throw error;
78
+ if (dependencies.size >= 64)
79
+ throw new Error("A schema may reference at most 64 external files");
80
+ const text = read(error.missingSchema);
81
+ dependencies.set(error.missingSchema, text);
82
+ add(JSON.parse(text), error.missingSchema);
83
+ }
84
+ }
85
+ if (!validate)
86
+ throw new Error("Schema could not be compiled");
87
+ const result = { schema, validate, context, dependencies };
88
+ if (cache.size >= 32)
89
+ cache.clear();
90
+ cache.set(key, result);
91
+ return result;
92
+ };
@@ -1,18 +1,16 @@
1
1
  import type { ValidateFunction } from "ajv";
2
2
  import { type Subformat, type SubformatCollection, type SubformatField } from "../core/subformats.js";
3
+ export { compileSubformatSchema } from "./subformat-schema.js";
3
4
  export interface LoadedSubformat extends Subformat {
4
5
  fields: SubformatField[];
5
6
  template: string;
6
7
  validate: ValidateFunction;
7
8
  }
8
- export declare const compileSubformatSchema: (content: string) => {
9
- schema: import("ajv").SchemaObject;
10
- validate: ValidateFunction<unknown>;
11
- };
12
- export declare const loadSubformat: (root: string, config: Subformat) => LoadedSubformat;
9
+ export declare const loadSubformat: (root: string, config: Subformat, domains?: readonly string[]) => LoadedSubformat;
13
10
  export declare const validateSubformatRecord: (format: LoadedSubformat, data: Record<string, unknown>) => void;
14
- export declare const validateSubformatFile: (root: string, file: string, content: string) => void;
15
- export declare const subformatResponse: (root: string, input: Record<string, unknown> | undefined) => {
11
+ export declare const isSubformatSchemaFile: (root: string, file: string, domains?: readonly string[]) => boolean;
12
+ export declare const validateSubformatFile: (root: string, file: string, content: string, domains?: readonly string[]) => void;
13
+ export declare const subformatResponse: (root: string, input: Record<string, unknown> | undefined, domains?: readonly string[]) => {
16
14
  status: number;
17
15
  body: {
18
16
  content?: string;