@dooc-dev/dooc 0.0.5 → 0.0.7
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.
- package/dist/cli.js +162 -67
- package/dist/code-worker.global.js +152 -0
- package/dist/code.global.js +101 -101
- package/dist/compiler/bundle-urls.js +2 -0
- package/dist/compiler/check.js +2 -0
- package/dist/compiler/compile.js +13 -3
- package/dist/compiler/dxf.d.ts +1 -0
- package/dist/compiler/dxf.js +81 -0
- package/dist/compiler/export.js +22 -15
- package/dist/compiler/figures.js +39 -10
- package/dist/compiler/files.js +2 -0
- package/dist/compiler/ignored-files.d.ts +2 -0
- package/dist/compiler/ignored-files.js +30 -0
- package/dist/compiler/ops.js +1 -1
- package/dist/compiler/subformat-schema.d.ts +14 -0
- package/dist/compiler/subformat-schema.js +92 -0
- package/dist/compiler/subformats.d.ts +5 -7
- package/dist/compiler/subformats.js +115 -75
- package/dist/core/code-file.js +7 -5
- package/dist/core/code-grammars.d.ts +5 -0
- package/dist/core/code-grammars.js +34 -0
- package/dist/core/content-metadata.d.ts +2 -1
- package/dist/core/content-metadata.js +7 -2
- package/dist/core/content-types.d.ts +1 -1
- package/dist/core/escape-html.d.ts +1 -0
- package/dist/core/escape-html.js +1 -0
- package/dist/core/figure-frame.js +1 -1
- package/dist/core/file-embed.js +7 -3
- package/dist/core/html.d.ts +4 -1
- package/dist/core/html.js +8 -7
- package/dist/core/language.js +5 -2
- package/dist/core/markdown.js +3 -1
- package/dist/core/previewers.d.ts +8 -0
- package/dist/core/previewers.js +2 -0
- package/dist/core/schema-fields.d.ts +13 -0
- package/dist/core/schema-fields.js +175 -0
- package/dist/core/schema-graph-mount.js +26 -3
- package/dist/core/schema-refs.d.ts +8 -0
- package/dist/core/schema-refs.js +82 -0
- package/dist/core/toc-ui.js +1 -1
- package/dist/edit.global.js +266 -285
- package/dist/flow.global.js +1031 -1057
- package/dist/graph/abnfDiagram-S7VZAUFO-GAGCW2J5.js +1 -0
- package/dist/graph/architecture-WOLXFQ4H-AWAC3VBS.js +1 -0
- package/dist/graph/architectureDiagram-YGSQEFNW-WQ7QKSUJ.js +36 -0
- package/dist/graph/blockDiagram-APKKGZFW-H7ZNJMOM.js +140 -0
- package/dist/graph/bpmnIcons-APHXDYXF-EAVPNTFE.js +1 -0
- package/dist/graph/c4Diagram-KJ2TOQU5-3IYS34YL.js +38 -0
- package/dist/graph/chunk-3CJU2RDX.js +1 -0
- package/dist/graph/chunk-3LU66YMI.js +1 -0
- package/dist/graph/chunk-3Y2PDVDE.js +1 -0
- package/dist/graph/chunk-4KILFWYV.js +339 -0
- package/dist/graph/chunk-4QDE4SUK.js +1 -0
- package/dist/graph/chunk-5N2X2DXU.js +1 -0
- package/dist/graph/chunk-5OO6DATX.js +1 -0
- package/dist/graph/chunk-67BPVAXC.js +1 -0
- package/dist/graph/chunk-6CDZONCA.js +1 -0
- package/dist/graph/chunk-7ASYMKN2.js +1 -0
- package/dist/graph/chunk-7JQUFVT4.js +10 -0
- package/dist/graph/chunk-7LSMJ4VU.js +72 -0
- package/dist/graph/chunk-7UKJADAE.js +213 -0
- package/dist/graph/chunk-AARGNXTW.js +32 -0
- package/dist/graph/chunk-ARAJTKOH.js +2 -0
- package/dist/graph/chunk-BOXAA5AP.js +62 -0
- package/dist/graph/chunk-BTMPKSGF.js +1 -0
- package/dist/graph/chunk-BVXT562I.js +1 -0
- package/dist/graph/chunk-DIDARDST.js +1 -0
- package/dist/graph/chunk-EWYECPNJ.js +1 -0
- package/dist/graph/chunk-FD7ZFC7R.js +3 -0
- package/dist/graph/chunk-GF4TOPUK.js +1 -0
- package/dist/graph/chunk-GWYODWCE.js +1 -0
- package/dist/graph/chunk-HKRJKXEE.js +1 -0
- package/dist/graph/chunk-I5LEUF24.js +1 -0
- package/dist/graph/chunk-ICJPOOXG.js +1 -0
- package/dist/graph/chunk-IVZHB6RS.js +135 -0
- package/dist/graph/chunk-JSHWCPFJ.js +1 -0
- package/dist/graph/chunk-JZGXHT3J.js +1 -0
- package/dist/graph/chunk-K4I76XBX.js +14 -0
- package/dist/graph/chunk-LSRL537V.js +88 -0
- package/dist/graph/chunk-LT6LXKCR.js +136 -0
- package/dist/graph/chunk-MPR575IN.js +1 -0
- package/dist/graph/chunk-N44XPVUD.js +15 -0
- package/dist/graph/chunk-NDAMZVXQ.js +1 -0
- package/dist/graph/chunk-O656ZI37.js +1 -0
- package/dist/graph/chunk-PDH25ALM.js +2 -0
- package/dist/graph/chunk-QLS7NIYR.js +2 -0
- package/dist/graph/chunk-QQIGL7OP.js +1 -0
- package/dist/graph/chunk-QYAXYFNI.js +1 -0
- package/dist/graph/chunk-QYTM6GY3.js +1 -0
- package/dist/graph/chunk-RJFVWYCA.js +1 -0
- package/dist/graph/chunk-SCEY3ZPT.js +1 -0
- package/dist/graph/chunk-SQE76S5B.js +1 -0
- package/dist/graph/chunk-WQHTQAFY.js +1 -0
- package/dist/graph/chunk-XQS73SBQ.js +1 -0
- package/dist/graph/chunk-Z4FIZ7CR.js +1 -0
- package/dist/graph/chunk-ZSZXN4BT.js +2 -0
- package/dist/graph/classDiagram-v2-L25IHNXF-HNTCDTNK.js +217 -0
- package/dist/graph/cose-bilkent-JH36ORCC-2GVA7XKO.js +1 -0
- package/dist/graph/cynefin-EF2NZ3EQ-TCI65RAQ.js +1 -0
- package/dist/graph/cynefinDiagram-L36ESFBY-OKQ5BLVF.js +62 -0
- package/dist/graph/dagre-SPEB5RXH-KZEBD52K.js +4 -0
- package/dist/graph/diagram-3B7GL73J-ESCBJM3O.js +200 -0
- package/dist/graph/diagram-DNEMPZML-ZIBUSQZI.js +24 -0
- package/dist/graph/diagram-L3MUGCDN-IGK62IPN.js +41 -0
- package/dist/graph/diagram-LA4NIPWU-2KZCOFJ5.js +24 -0
- package/dist/graph/diagram-MHCOC4E2-EYAAB236.js +3 -0
- package/dist/graph/diagram-XPFHEONP-OZ5ARGMG.js +30 -0
- package/dist/graph/ebnfDiagram-UZSYDL2S-M3XJHARD.js +1 -0
- package/dist/graph/erDiagram-EYBAPDEH-Y7KUBH7A.js +99 -0
- package/dist/graph/eventmodeling-K75KTNOO-ROLYRDEP.js +1 -0
- package/dist/graph/flowDiagram-MALGAFMO-AAUEIPCR.js +1 -0
- package/dist/graph/ganttDiagram-23REXITY-JSBTFSSJ.js +292 -0
- package/dist/graph/gitGraph-VSP46ZUC-ZCBCDVNF.js +1 -0
- package/dist/graph/gitGraphDiagram-STJD7YCW-3ZA5FT3G.js +106 -0
- package/dist/graph/info-OHQRW6UA-JKJGOQNY.js +1 -0
- package/dist/graph/infoDiagram-KBXO4MBG-6LFMPP2O.js +2 -0
- package/dist/graph/ishikawaDiagram-M35NCXHK-YLEU44DY.js +70 -0
- package/dist/graph/journeyDiagram-OPLOXDXO-ZHJV66ZT.js +139 -0
- package/dist/graph/kanban-definition-BZKZHSQY-SDU25WUM.js +89 -0
- package/dist/graph/katex-WSLZOTY7.js +257 -0
- package/dist/graph/mindmap-definition-I2QAS2VK-XQNBCYHN.js +98 -0
- package/dist/graph/packet-JDAUHWVQ-Y3H77ERD.js +1 -0
- package/dist/graph/pegDiagram-FD4XPPHP-YO4VWH6V.js +1 -0
- package/dist/graph/pie-XZMESJXO-PRER4XL5.js +1 -0
- package/dist/graph/pieDiagram-J4AKIIQI-TJ5WOOSV.js +39 -0
- package/dist/graph/quadrantDiagram-XTYBLID2-G6MSSZLW.js +7 -0
- package/dist/graph/radar-ABXABTNO-M6MV34GM.js +1 -0
- package/dist/graph/railroad-I3PHUGI6-YIWPGN6Q.js +1 -0
- package/dist/graph/railroad-abnf-LNEFI6M7-7JHLZ2R7.js +1 -0
- package/dist/graph/railroad-ebnf-DWYD2UWJ-V55BXEWY.js +1 -0
- package/dist/graph/railroad-peg-JR7BVNR7-XCGKDRMK.js +1 -0
- package/dist/graph/railroadDiagram-MRQ6NCDL-RACSFXC4.js +1 -0
- package/dist/graph/requirementDiagram-Y7LWUY3S-4LQIQWHQ.js +84 -0
- package/dist/graph/sankeyDiagram-WGJFYUXA-K3RXG5FB.js +40 -0
- package/dist/graph/schema-graph-global.js +639 -0
- package/dist/graph/sequenceDiagram-5NDRBG5M-Y6RBHRS3.js +169 -0
- package/dist/graph/sizeCapture-INFHLROL-TJW3VUGH.js +1 -0
- package/dist/graph/stateDiagram-v2-FJ4FJNEA-4M5WZORG.js +291 -0
- package/dist/graph/swimlanes-UMQ2AFYF-O4W6U4RO.js +1 -0
- package/dist/graph/swimlanesDiagram-OMPLPG4O-HZAKM45N.js +8 -0
- package/dist/graph/timeline-definition-SEUHKTQE-IHISQ4Q7.js +120 -0
- package/dist/graph/treeView-D4JQ5SDB-EVGY4VYS.js +1 -0
- package/dist/graph/treemap-SAJKECNS-LN3SMFRX.js +1 -0
- package/dist/graph/usecaseDiagram-AFA6YXN4-B645A3J6.js +370 -0
- package/dist/graph/vennDiagram-NNMJR3RB-K3HWMON6.js +34 -0
- package/dist/graph/wardley-7MLQ67FV-RRWOELC6.js +1 -0
- package/dist/graph/wardleyDiagram-S7YFUSEH-DMMWKJEK.js +78 -0
- package/dist/graph/xychartDiagram-GGNKY7IX-K6MUQVXR.js +7 -0
- package/dist/mcp.js +5 -4
- package/dist/plugins.global.js +71 -104
- package/dist/subformats.global.js +6 -112
- package/dist/ui.global.js +75 -108
- package/dist/viewer/build.d.ts +2 -0
- package/dist/viewer/build.js +22 -8
- package/dist/viewer/code-file.js +7 -2
- package/dist/viewer/figure-preview.d.ts +4 -0
- package/dist/viewer/figure-preview.js +54 -0
- package/dist/viewer/hmr.js +4 -3
- package/dist/viewer/lazy-preview.d.ts +2 -0
- package/dist/viewer/lazy-preview.js +43 -0
- package/dist/viewer/locales/eng.json +26 -3
- package/dist/viewer/locales/jpn.json +26 -3
- package/dist/viewer/locales/zho.json +26 -3
- package/dist/viewer/plugin-blocks.js +1 -1
- package/dist/viewer/plugins.js +1 -1
- package/dist/viewer/resource-library.d.ts +1 -1
- package/dist/viewer/resource-library.js +5 -4
- package/dist/viewer/serve.d.ts +2 -1
- package/dist/viewer/serve.js +148 -41
- package/dist/viewer/textfile.d.ts +2 -0
- package/dist/viewer/textfile.js +20 -5
- package/package.json +14 -4
- package/dist/viewer/lazy-graph.d.ts +0 -2
- package/dist/viewer/lazy-graph.js +0 -30
package/dist/compiler/check.js
CHANGED
|
@@ -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);
|
package/dist/compiler/compile.js
CHANGED
|
@@ -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)
|
|
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
|
+
};
|
package/dist/compiler/export.js
CHANGED
|
@@ -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
|
|
94
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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()) {
|
package/dist/compiler/figures.js
CHANGED
|
@@ -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 =
|
|
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) =>
|
|
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
|
|
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 (/\.(
|
|
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)) {
|
package/dist/compiler/files.js
CHANGED
|
@@ -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")) ||
|
package/dist/compiler/ops.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
15
|
-
export declare const
|
|
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;
|