@danielsimonjr/sciengjs 0.1.1 → 0.3.0

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 (94) hide show
  1. package/README.md +24 -4
  2. package/THIRD_PARTY_NOTICES.md +17 -1
  3. package/assets/licenses/MIT-mermaid.txt +21 -0
  4. package/assets/licenses/MIT-viz-js.txt +21 -0
  5. package/assets/licenses/mermaid-bundle.txt +2128 -0
  6. package/assets/mermaid.min.js +3636 -0
  7. package/dist/browser/backend-pdf.d.ts +3 -0
  8. package/dist/browser/backend-pdf.js +15 -0
  9. package/dist/browser/backend-pdf.js.map +1 -0
  10. package/dist/browser/backend-png.d.ts +3 -0
  11. package/dist/browser/backend-png.js +18 -0
  12. package/dist/browser/backend-png.js.map +1 -0
  13. package/dist/browser/cdp.d.ts +37 -0
  14. package/dist/browser/cdp.js +161 -0
  15. package/dist/browser/cdp.js.map +1 -0
  16. package/dist/browser/flags.d.ts +10 -0
  17. package/dist/browser/flags.js +33 -0
  18. package/dist/browser/flags.js.map +1 -0
  19. package/dist/browser/index.d.ts +5 -0
  20. package/dist/browser/index.js +6 -0
  21. package/dist/browser/index.js.map +1 -0
  22. package/dist/browser/input.d.ts +38 -0
  23. package/dist/browser/input.js +97 -0
  24. package/dist/browser/input.js.map +1 -0
  25. package/dist/browser/page.d.ts +10 -0
  26. package/dist/browser/page.js +33 -0
  27. package/dist/browser/page.js.map +1 -0
  28. package/dist/browser/pinned.d.ts +16 -0
  29. package/dist/browser/pinned.js +13 -0
  30. package/dist/browser/pinned.js.map +1 -0
  31. package/dist/browser/profile.d.ts +9 -0
  32. package/dist/browser/profile.js +33 -0
  33. package/dist/browser/profile.js.map +1 -0
  34. package/dist/browser/proxy.d.ts +14 -0
  35. package/dist/browser/proxy.js +64 -0
  36. package/dist/browser/proxy.js.map +1 -0
  37. package/dist/browser/render.d.ts +58 -0
  38. package/dist/browser/render.js +421 -0
  39. package/dist/browser/render.js.map +1 -0
  40. package/dist/core.js +10 -2
  41. package/dist/core.js.map +1 -1
  42. package/dist/graph/backend-pdf.d.ts +3 -0
  43. package/dist/graph/backend-pdf.js +14 -0
  44. package/dist/graph/backend-pdf.js.map +1 -0
  45. package/dist/graph/backend-png.d.ts +7 -0
  46. package/dist/graph/backend-png.js +30 -12
  47. package/dist/graph/backend-png.js.map +1 -1
  48. package/dist/mermaid/backend-pdf.d.ts +6 -0
  49. package/dist/mermaid/backend-pdf.js +19 -0
  50. package/dist/mermaid/backend-pdf.js.map +1 -0
  51. package/dist/mermaid/backend-png.d.ts +7 -0
  52. package/dist/mermaid/backend-png.js +27 -0
  53. package/dist/mermaid/backend-png.js.map +1 -0
  54. package/dist/mermaid/backend-svg.d.ts +6 -0
  55. package/dist/mermaid/backend-svg.js +18 -0
  56. package/dist/mermaid/backend-svg.js.map +1 -0
  57. package/dist/mermaid/browser.d.ts +30 -0
  58. package/dist/mermaid/browser.js +52 -0
  59. package/dist/mermaid/browser.js.map +1 -0
  60. package/dist/mermaid/class.d.ts +37 -0
  61. package/dist/mermaid/class.js +190 -0
  62. package/dist/mermaid/class.js.map +1 -0
  63. package/dist/mermaid/common.d.ts +50 -0
  64. package/dist/mermaid/common.js +144 -0
  65. package/dist/mermaid/common.js.map +1 -0
  66. package/dist/mermaid/index.d.ts +10 -0
  67. package/dist/mermaid/index.js +11 -0
  68. package/dist/mermaid/index.js.map +1 -0
  69. package/dist/mermaid/render.d.ts +10 -0
  70. package/dist/mermaid/render.js +24 -0
  71. package/dist/mermaid/render.js.map +1 -0
  72. package/dist/mermaid/sequence-layout.d.ts +6 -0
  73. package/dist/mermaid/sequence-layout.js +268 -0
  74. package/dist/mermaid/sequence-layout.js.map +1 -0
  75. package/dist/mermaid/sequence.d.ts +62 -0
  76. package/dist/mermaid/sequence.js +199 -0
  77. package/dist/mermaid/sequence.js.map +1 -0
  78. package/dist/mermaid/state.d.ts +24 -0
  79. package/dist/mermaid/state.js +132 -0
  80. package/dist/mermaid/state.js.map +1 -0
  81. package/dist/pairs.d.ts +2 -1
  82. package/dist/pairs.js +8 -6
  83. package/dist/pairs.js.map +1 -1
  84. package/dist/registry.js +6 -0
  85. package/dist/registry.js.map +1 -1
  86. package/dist/types.d.ts +2 -0
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/dist/worker/entry.js +1 -1
  90. package/dist/worker/entry.js.map +1 -1
  91. package/dist/worker/protocol.d.ts +7 -0
  92. package/dist/worker/run.js +1 -1
  93. package/dist/worker/run.js.map +1 -1
  94. package/package.json +10 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-pdf.js","sourceRoot":"","sources":["../../src/graph/backend-pdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEnD,6HAA6H;AAC7H,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAA6B;IACxD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACjD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,WAAW,CAAC,SAAS,EAAE,oCAAoC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3D,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC;AACrH,CAAC"}
@@ -1,5 +1,12 @@
1
1
  import type { BackendOutput, WorkerJob } from "../worker/protocol.ts";
2
+ /** Reads the option scale of a png. An absent value gives 1. A value that is not a finite number above 0 rejects with E_INPUT. */
3
+ export declare function readScale(options: Record<string, unknown>): number;
2
4
  /** Renders dot to png: the SVG of the graph, then the PNG of that SVG at the option scale. The bundled font comes from the assets folder named in the settings. */
3
5
  export declare function render(request: WorkerJob["request"]): Promise<BackendOutput>;
4
6
  /** Renders dot to png with the bundled font at the given path. The path is a parameter so that a test can name a missing or invalid bundled font. */
5
7
  export declare function renderPng(request: WorkerJob["request"], bundledFontPath: string): Promise<BackendOutput>;
8
+ /**
9
+ * Rasterizes one SVG document to PNG at the given scale. The font follows render: the rasterFont setting when set,
10
+ * else the bundled font in the assets folder. The Mermaid PNG backend uses this function.
11
+ */
12
+ export declare function svgDocumentToPng(svg: string, request: WorkerJob["request"], scale?: number): Promise<BackendOutput>;
@@ -21,6 +21,20 @@ function readFont(path, bundled) {
21
21
  }
22
22
  return bytes;
23
23
  }
24
+ /** Reads the font of a render: the rasterFont setting when set, else the bundled font at the given path. */
25
+ function fontOf(settings, bundledFontPath) {
26
+ const rasterFont = settings.rasterFont;
27
+ return readFont(rasterFont ?? bundledFontPath, rasterFont === undefined);
28
+ }
29
+ /** Reads the option scale of a png. An absent value gives 1. A value that is not a finite number above 0 rejects with E_INPUT. */
30
+ export function readScale(options) {
31
+ const value = options.scale;
32
+ if (value === undefined)
33
+ return 1;
34
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
35
+ return value;
36
+ throw new RenderError("E_INPUT", "option scale must be a finite number greater than 0");
37
+ }
24
38
  /** Renders dot to png: the SVG of the graph, then the PNG of that SVG at the option scale. The bundled font comes from the assets folder named in the settings. */
25
39
  export async function render(request) {
26
40
  return renderPng(request, bundledFontPathIn(request.settings.assetsUrl));
@@ -33,18 +47,8 @@ export async function renderPng(request, bundledFontPath) {
33
47
  throw new RenderError("E_INPUT", "dot to png takes no option " + key);
34
48
  }
35
49
  }
36
- let scale = 1;
37
- if ("scale" in options) {
38
- const value = options.scale;
39
- if (typeof value === "number" && Number.isFinite(value) && value > 0) {
40
- scale = value;
41
- }
42
- else {
43
- throw new RenderError("E_INPUT", "option scale must be a finite number greater than 0");
44
- }
45
- }
46
- const rasterFont = request.settings.rasterFont;
47
- const font = readFont(rasterFont ?? bundledFontPath, rasterFont === undefined);
50
+ const scale = readScale(options);
51
+ const font = fontOf(request.settings, bundledFontPath);
48
52
  const dot = await dotToSvg(dotSourceText(request.source));
49
53
  const bytes = await svgToPng(dot.svg, {
50
54
  scale,
@@ -54,4 +58,18 @@ export async function renderPng(request, bundledFontPath) {
54
58
  });
55
59
  return { bytes, warnings: [...dot.warnings, ...rasterWarnings(dot.svg, font)] };
56
60
  }
61
+ /**
62
+ * Rasterizes one SVG document to PNG at the given scale. The font follows render: the rasterFont setting when set,
63
+ * else the bundled font in the assets folder. The Mermaid PNG backend uses this function.
64
+ */
65
+ export async function svgDocumentToPng(svg, request, scale = 1) {
66
+ const font = fontOf(request.settings, bundledFontPathIn(request.settings.assetsUrl));
67
+ const bytes = await svgToPng(svg, {
68
+ scale,
69
+ maxMemoryMb: request.settings.maxMemoryMb,
70
+ font,
71
+ assetsUrl: request.settings.assetsUrl,
72
+ });
73
+ return { bytes, warnings: rasterWarnings(svg, font) };
74
+ }
57
75
  //# sourceMappingURL=backend-png.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"backend-png.js","sourceRoot":"","sources":["../../src/graph/backend-png.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAA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E,IAAI,CAAC,CAAC,EAAE,CAAC;AAClF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAW,EAAE,OAA6B,EAAE,KAAK,GAAG,CAAC;IAC1F,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACrF,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE;QAChC,KAAK;QACL,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW;QACzC,IAAI;QACJ,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,SAAS;KACtC,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { BackendOutput, WorkerJob } from "../worker/protocol.ts";
2
+ /**
3
+ * Renders one Mermaid source to pdf in the browser stage. A native diagram is laid out first, then its SVG is
4
+ * drawn. Any other Mermaid type is drawn by the pinned Mermaid build in the page. The worker calls this function.
5
+ */
6
+ export declare function render(request: WorkerJob["request"]): Promise<BackendOutput>;
@@ -0,0 +1,19 @@
1
+ import { readLenient, routesToBrowser, sourceText } from "./common.js";
2
+ import { drawMermaidInBrowser, drawSvgToPdf, MERMAID_NATIVE_PDF_BACKEND } from "./browser.js";
3
+ import { renderMermaidSvg } from "./render.js";
4
+ /**
5
+ * Renders one Mermaid source to pdf in the browser stage. A native diagram is laid out first, then its SVG is
6
+ * drawn. Any other Mermaid type is drawn by the pinned Mermaid build in the page. The worker calls this function.
7
+ */
8
+ export async function render(request) {
9
+ const source = sourceText(request.source);
10
+ if (routesToBrowser(source)) {
11
+ readLenient(request.options, []);
12
+ const out = await drawMermaidInBrowser(source, "pdf", request.settings);
13
+ return { bytes: out.bytes, warnings: out.warnings, backend: out.backend };
14
+ }
15
+ const svg = await renderMermaidSvg(source, request.options);
16
+ const draw = await drawSvgToPdf(svg.svg, request.settings);
17
+ return { bytes: draw.bytes, warnings: [...svg.warnings, ...draw.warnings], backend: MERMAID_NATIVE_PDF_BACKEND };
18
+ }
19
+ //# sourceMappingURL=backend-pdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-pdf.js","sourceRoot":"","sources":["../../src/mermaid/backend-pdf.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAA6B;IACxD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxE,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAC5E,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3D,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACnH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { BackendOutput, WorkerJob } from "../worker/protocol.ts";
2
+ /**
3
+ * Renders one Mermaid source to PNG. A native diagram is drawn to SVG and then to PNG by the raster stage.
4
+ * Any other Mermaid type is drawn by a browser screenshot. Both routes take the options lenient and scale. The scale
5
+ * multiplies the pixel size of the diagram. The worker calls this function for the mermaid:png pair.
6
+ */
7
+ export declare function render(request: WorkerJob["request"]): Promise<BackendOutput>;
@@ -0,0 +1,27 @@
1
+ import { MAX_SCALE } from "../browser/input.js";
2
+ import { RenderError } from "../errors.js";
3
+ import { readScale, svgDocumentToPng } from "../graph/backend-png.js";
4
+ import { readLenient, routesToBrowser, sourceText } from "./common.js";
5
+ import { drawMermaidInBrowser } from "./browser.js";
6
+ import { renderMermaidSvg } from "./render.js";
7
+ /**
8
+ * Renders one Mermaid source to PNG. A native diagram is drawn to SVG and then to PNG by the raster stage.
9
+ * Any other Mermaid type is drawn by a browser screenshot. Both routes take the options lenient and scale. The scale
10
+ * multiplies the pixel size of the diagram. The worker calls this function for the mermaid:png pair.
11
+ */
12
+ export async function render(request) {
13
+ const source = sourceText(request.source);
14
+ const { scale: _scale, ...rest } = request.options;
15
+ const scale = readScale(request.options);
16
+ if (scale > MAX_SCALE)
17
+ throw new RenderError("E_INPUT", `option scale must not be more than ${MAX_SCALE}`);
18
+ if (routesToBrowser(source)) {
19
+ readLenient(rest, []);
20
+ const out = await drawMermaidInBrowser(source, "png", request.settings, scale);
21
+ return { bytes: out.bytes, warnings: out.warnings, backend: out.backend };
22
+ }
23
+ const svg = await renderMermaidSvg(source, rest);
24
+ const png = await svgDocumentToPng(svg.svg, request, scale);
25
+ return { bytes: png.bytes, warnings: [...svg.warnings, ...(png.warnings ?? [])] };
26
+ }
27
+ //# sourceMappingURL=back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CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5D,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;AACpF,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { BackendOutput, WorkerJob } from "../worker/protocol.ts";
2
+ /**
3
+ * Renders one Mermaid source to SVG. A native diagram goes through the native layouts. Any other Mermaid type goes
4
+ * through the browser stage. The worker calls this function for the mermaid:svg pair.
5
+ */
6
+ export declare function render(request: WorkerJob["request"]): Promise<BackendOutput>;
@@ -0,0 +1,18 @@
1
+ import { readLenient, routesToBrowser, sourceText } from "./common.js";
2
+ import { drawMermaidInBrowser } from "./browser.js";
3
+ import { renderMermaidSvg } from "./render.js";
4
+ /**
5
+ * Renders one Mermaid source to SVG. A native diagram goes through the native layouts. Any other Mermaid type goes
6
+ * through the browser stage. The worker calls this function for the mermaid:svg pair.
7
+ */
8
+ export async function render(request) {
9
+ const source = sourceText(request.source);
10
+ if (routesToBrowser(source)) {
11
+ readLenient(request.options, []);
12
+ const out = await drawMermaidInBrowser(source, "svg", request.settings);
13
+ return { bytes: out.bytes, warnings: out.warnings, backend: out.backend };
14
+ }
15
+ const result = await renderMermaidSvg(source, request.options);
16
+ return { bytes: new TextEncoder().encode(result.svg), warnings: result.warnings };
17
+ }
18
+ //# sourceMappingURL=backend-svg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-svg.js","sourceRoot":"","sources":["../../src/mermaid/backend-svg.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAA6B;IACxD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxE,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAC5E,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/D,OAAO,EAAE,KAAK,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;AACpF,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type HtmlFormat, type PinnedBytes } from "../browser/render.ts";
2
+ /** The backend name of a Mermaid type that the browser stage draws. */
3
+ export declare const MERMAID_BROWSER_BACKEND = "mermaid/browser/chromium";
4
+ /** The backend name of a native Mermaid diagram that is then drawn to pdf in the browser. */
5
+ export declare const MERMAID_NATIVE_PDF_BACKEND = "mermaid/native+browser/chromium";
6
+ /** The settings of one browser render that a Mermaid backend reads. */
7
+ export interface BrowserSettings {
8
+ browser: string | undefined;
9
+ timeoutMs: number;
10
+ assetsUrl: string;
11
+ }
12
+ /** The bytes and the warnings of one browser render. */
13
+ export interface BrowserDraw {
14
+ bytes: Uint8Array;
15
+ warnings: string[];
16
+ }
17
+ /**
18
+ * Draws one Mermaid source of a browser type through the browser stage. The page names the pinned Mermaid URL.
19
+ * The client fulfils that URL from the pinned build in the assets folder, so no request leaves the process.
20
+ */
21
+ export declare function drawMermaidInBrowser(source: string, format: HtmlFormat, settings: BrowserSettings, scale?: number): Promise<BrowserDraw & {
22
+ backend: string;
23
+ }>;
24
+ /** Draws the SVG of a native Mermaid diagram to pdf in the browser. */
25
+ export declare function drawSvgToPdf(svg: string, settings: BrowserSettings): Promise<BrowserDraw>;
26
+ /**
27
+ * Reads the pinned Mermaid build from the assets folder and checks its SHA-256. A missing file rejects with
28
+ * E_STAGE_MISSING. A file with other bytes rejects with E_INTEGRITY, so a changed copy never runs in a page.
29
+ */
30
+ export declare function pinnedMermaid(assetsUrl: string): ReadonlyMap<string, PinnedBytes>;
@@ -0,0 +1,52 @@
1
+ import { blockedWarnings, browserPathOf } from "../browser/input.js";
2
+ import { createHash } from "node:crypto";
3
+ import { MERMAID_CDN_URL, MERMAID_FILE, MERMAID_SHA256 } from "../browser/pinned.js";
4
+ import { RenderError } from "../errors.js";
5
+ import { mermaidPageHtml, svgPageHtml } from "../browser/page.js";
6
+ import { renderHtmlPage } from "../browser/render.js";
7
+ import { readAsset } from "../assets.js";
8
+ /** The backend name of a Mermaid type that the browser stage draws. */
9
+ export const MERMAID_BROWSER_BACKEND = "mermaid/browser/chromium";
10
+ /** The backend name of a native Mermaid diagram that is then drawn to pdf in the browser. */
11
+ export const MERMAID_NATIVE_PDF_BACKEND = "mermaid/native+browser/chromium";
12
+ /**
13
+ * Draws one Mermaid source of a browser type through the browser stage. The page names the pinned Mermaid URL.
14
+ * The client fulfils that URL from the pinned build in the assets folder, so no request leaves the process.
15
+ */
16
+ export async function drawMermaidInBrowser(source, format, settings, scale = 1) {
17
+ const browser = browserPathOf(settings.browser);
18
+ const base = {
19
+ html: mermaidPageHtml(source, MERMAID_CDN_URL),
20
+ browser,
21
+ timeoutMs: settings.timeoutMs,
22
+ pinned: pinnedMermaid(settings.assetsUrl),
23
+ awaitDone: true,
24
+ };
25
+ // A png of a page that reports done is sized from the diagram box. The scale is the device scale of the screenshot.
26
+ const request = format === "png"
27
+ ? { ...base, format: "png", width: 0, height: 0, scale }
28
+ : format === "pdf"
29
+ ? { ...base, format: "pdf" }
30
+ : { ...base, format: "svg" };
31
+ const out = await renderHtmlPage(request);
32
+ return { bytes: out.bytes, warnings: blockedWarnings(out.blocked), backend: MERMAID_BROWSER_BACKEND };
33
+ }
34
+ /** Draws the SVG of a native Mermaid diagram to pdf in the browser. */
35
+ export async function drawSvgToPdf(svg, settings) {
36
+ const browser = browserPathOf(settings.browser);
37
+ const out = await renderHtmlPage({ html: svgPageHtml(svg), format: "pdf", browser, timeoutMs: settings.timeoutMs });
38
+ return { bytes: out.bytes, warnings: blockedWarnings(out.blocked) };
39
+ }
40
+ /**
41
+ * Reads the pinned Mermaid build from the assets folder and checks its SHA-256. A missing file rejects with
42
+ * E_STAGE_MISSING. A file with other bytes rejects with E_INTEGRITY, so a changed copy never runs in a page.
43
+ */
44
+ export function pinnedMermaid(assetsUrl) {
45
+ const bytes = readAsset(assetsUrl, MERMAID_FILE);
46
+ const hash = createHash("sha256").update(bytes).digest("hex");
47
+ if (hash !== MERMAID_SHA256) {
48
+ throw new RenderError("E_INTEGRITY", `${MERMAID_FILE} has the SHA-256 ${hash}, not the pinned ${MERMAID_SHA256}`);
49
+ }
50
+ return new Map([[MERMAID_CDN_URL, { bytes, mime: "application/javascript" }]]);
51
+ }
52
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/mermaid/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sB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QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;AACxG,CAAC;AAED,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW,EAAE,QAAyB;IACvE,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;IACpH,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9D,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;QAC5B,MAAM,IAAI,WAAW,CAAC,aAAa,EAAE,GAAG,YAAY,oBAAoB,IAAI,oBAAoB,cAAc,EAAE,CAAC,CAAC;IACpH,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC,CAAC,CAAC;AACjF,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { type Source } from "./common.ts";
2
+ /** The shape at one end of a class relation: none, an open arrow, a triangle, or a diamond that is filled or open. */
3
+ export type Marker = "none" | "arrow" | "triangle" | "diamond" | "filled-diamond";
4
+ /** The line style of a class relation and the marker at each end. The tail is the end at the first class. */
5
+ export interface ClassArrow {
6
+ dashed: boolean;
7
+ tail: Marker;
8
+ head: Marker;
9
+ }
10
+ /** One class of the diagram: its name, its generic parameter, its members and the line that declares it. */
11
+ export interface ClassDef {
12
+ name: string;
13
+ generic: string | undefined;
14
+ members: string[];
15
+ line: number;
16
+ }
17
+ /** One relation between two classes. It holds the arrow, the cardinality at each end, the label and the source line. */
18
+ export interface ClassRelation {
19
+ from: string;
20
+ to: string;
21
+ token: string;
22
+ arrow: ClassArrow;
23
+ fromCardinality: string | undefined;
24
+ toCardinality: string | undefined;
25
+ label: string | undefined;
26
+ line: number;
27
+ }
28
+ /** A parsed class diagram: its direction, its classes and its relations. */
29
+ export interface ClassModel {
30
+ direction: "TB" | "BT" | "LR" | "RL";
31
+ classes: ClassDef[];
32
+ relations: ClassRelation[];
33
+ }
34
+ /** Parses the content lines of a class diagram. A line outside the grammar rejects with E_INPUT. In lenient mode the line is skipped and a warning names it. */
35
+ export declare function parseClassDiagram(src: Source): ClassModel;
36
+ /** Builds the DOT source of a parsed class diagram. Each class is a record node. */
37
+ export declare function classToDot(model: ClassModel): string;
@@ -0,0 +1,190 @@
1
+ import { inputError, outside, xmlSafe } from "./common.js";
2
+ const ARROW_SPECS = [
3
+ ["<|--", { dashed: false, tail: "triangle", head: "none" }],
4
+ ["*--", { dashed: false, tail: "filled-diamond", head: "none" }],
5
+ ["o--", { dashed: false, tail: "diamond", head: "none" }],
6
+ ["<--", { dashed: false, tail: "arrow", head: "none" }],
7
+ ["<|..", { dashed: true, tail: "triangle", head: "none" }],
8
+ ["<..", { dashed: true, tail: "arrow", head: "none" }],
9
+ ["--|>", { dashed: false, tail: "none", head: "triangle" }],
10
+ ["--*", { dashed: false, tail: "none", head: "filled-diamond" }],
11
+ ["--o", { dashed: false, tail: "none", head: "diamond" }],
12
+ ["-->", { dashed: false, tail: "none", head: "arrow" }],
13
+ ["..|>", { dashed: true, tail: "none", head: "triangle" }],
14
+ ["..>", { dashed: true, tail: "none", head: "arrow" }],
15
+ ["--", { dashed: false, tail: "none", head: "none" }],
16
+ ["..", { dashed: true, tail: "none", head: "none" }],
17
+ ];
18
+ const ARROW_TABLE = new Map(ARROW_SPECS);
19
+ const ARROW_PATTERN = [...ARROW_SPECS]
20
+ .sort((left, right) => right[0].length - left[0].length)
21
+ .map(([token]) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
22
+ .join("|");
23
+ const IDENT_SOURCE = "[A-Za-z_][A-Za-z0-9_]*";
24
+ const RELATION_PATTERN = new RegExp(`^(${IDENT_SOURCE}) +(?:"([^"]*)" )?(${ARROW_PATTERN}) +(?:"([^"]*)" )?(${IDENT_SOURCE})(?: *: *(.+))?$`);
25
+ const MEMBER_PATTERN = /^([A-Za-z_][A-Za-z0-9_]*) *:(.*)$/;
26
+ const CLASS_PATTERN = /^class ([A-Za-z_][A-Za-z0-9_]*)(?:~([A-Za-z0-9_ ,]+)~)?( *\{)?$/;
27
+ const DIRECTION_PATTERN = /^direction (TB|BT|LR|RL)$/;
28
+ /** Parses the content lines of a class diagram. A line outside the grammar rejects with E_INPUT. In lenient mode the line is skipped and a warning names it. */
29
+ export function parseClassDiagram(src) {
30
+ let direction = "TB";
31
+ let sawDirection = false;
32
+ const classes = [];
33
+ const relations = [];
34
+ const byName = new Map();
35
+ let open;
36
+ const ensureClass = (name, line) => {
37
+ const existing = byName.get(name);
38
+ if (existing !== undefined) {
39
+ return existing;
40
+ }
41
+ const created = { name, generic: undefined, members: [], line };
42
+ byName.set(name, created);
43
+ classes.push(created);
44
+ return created;
45
+ };
46
+ const lines = src.lines;
47
+ for (const line of lines) {
48
+ const text = line.text;
49
+ if (open !== undefined) {
50
+ if (text === "}") {
51
+ open = undefined;
52
+ }
53
+ else if (text.includes("{") || text.includes("}")) {
54
+ outside(src, line.number, text, "a brace inside a class body is outside the supported grammar");
55
+ }
56
+ else {
57
+ byName.get(open.name).members.push(text.trim());
58
+ }
59
+ continue;
60
+ }
61
+ const relation = RELATION_PATTERN.exec(text);
62
+ if (relation !== null) {
63
+ const from = relation[1];
64
+ const to = relation[5];
65
+ const token = relation[3];
66
+ const arrow = ARROW_TABLE.get(token);
67
+ const rawLabel = relation[6];
68
+ relations.push({
69
+ from,
70
+ to,
71
+ token,
72
+ arrow: { dashed: arrow.dashed, tail: arrow.tail, head: arrow.head },
73
+ fromCardinality: relation[2],
74
+ toCardinality: relation[4],
75
+ label: rawLabel === undefined ? undefined : rawLabel.trim(),
76
+ line: line.number,
77
+ });
78
+ ensureClass(from, line.number);
79
+ ensureClass(to, line.number);
80
+ continue;
81
+ }
82
+ const member = MEMBER_PATTERN.exec(text);
83
+ if (member !== null) {
84
+ const memberText = member[2].trim();
85
+ if (memberText !== "") {
86
+ ensureClass(member[1], line.number).members.push(memberText);
87
+ continue;
88
+ }
89
+ }
90
+ const declaration = CLASS_PATTERN.exec(text);
91
+ if (declaration !== null) {
92
+ const name = declaration[1];
93
+ const generic = declaration[2];
94
+ const existing = byName.get(name);
95
+ if (existing === undefined) {
96
+ const created = { name, generic, members: [], line: line.number };
97
+ byName.set(name, created);
98
+ classes.push(created);
99
+ }
100
+ else if (generic !== undefined) {
101
+ existing.generic = generic;
102
+ }
103
+ if (declaration[3] !== undefined) {
104
+ open = { name, line: line.number };
105
+ }
106
+ continue;
107
+ }
108
+ const directionLine = DIRECTION_PATTERN.exec(text);
109
+ if (directionLine !== null) {
110
+ if (sawDirection) {
111
+ outside(src, line.number, text, "a second direction line is outside the supported grammar");
112
+ continue;
113
+ }
114
+ const value = directionLine[1];
115
+ if (value === "TB" || value === "BT" || value === "LR" || value === "RL") {
116
+ direction = value;
117
+ sawDirection = true;
118
+ }
119
+ continue;
120
+ }
121
+ outside(src, line.number, text, "a construct is outside the supported grammar");
122
+ }
123
+ if (open !== undefined) {
124
+ if (src.lenient) {
125
+ src.warnings.push(`line ${open.line}: the body of class ${open.name} is not closed by a line with }; its members run to the end of the source`);
126
+ }
127
+ else {
128
+ throw inputError(open.line, `the body of class ${open.name} is not closed by a line with }`);
129
+ }
130
+ }
131
+ if (classes.length === 0 && relations.length === 0) {
132
+ throw inputError(src.headerLine, "the diagram holds no class or relation");
133
+ }
134
+ return { direction, classes, relations };
135
+ }
136
+ const DOT_MARKERS = {
137
+ none: "none",
138
+ arrow: "normal",
139
+ triangle: "empty",
140
+ diamond: "odiamond",
141
+ "filled-diamond": "diamond",
142
+ };
143
+ function escapeDot(text) {
144
+ return xmlSafe(text).replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
145
+ }
146
+ function escapeRecord(text) {
147
+ return xmlSafe(text).replace(/\\/g, "\\\\").replace(/[{}|<>"]/g, "\\$&");
148
+ }
149
+ function memberDisplay(text) {
150
+ return escapeRecord(text.replace(/~([^~]*)~/g, "<$1>"));
151
+ }
152
+ /** Builds the DOT source of a parsed class diagram. Each class is a record node. */
153
+ export function classToDot(model) {
154
+ const out = [];
155
+ out.push("digraph classDiagram {");
156
+ out.push(` rankdir=${model.direction};`);
157
+ out.push(" node [shape=record];");
158
+ for (const cls of model.classes) {
159
+ const display = cls.generic === undefined ? cls.name : `${cls.name}<${cls.generic}>`;
160
+ const label = cls.members.length === 0
161
+ ? escapeRecord(display)
162
+ : `${escapeRecord(display)}|${cls.members.map((member) => `${memberDisplay(member)}\\l`).join("")}`;
163
+ out.push(` "${escapeDot(cls.name)}" [label="{${label}}"];`);
164
+ }
165
+ for (const rel of model.relations) {
166
+ const attrs = [];
167
+ if (rel.arrow.dashed) {
168
+ attrs.push("style=dashed");
169
+ }
170
+ if (rel.arrow.tail === "none" && rel.arrow.head === "none") {
171
+ attrs.push("dir=none");
172
+ }
173
+ else {
174
+ attrs.push("dir=both", `arrowtail=${DOT_MARKERS[rel.arrow.tail]}`, `arrowhead=${DOT_MARKERS[rel.arrow.head]}`);
175
+ }
176
+ if (rel.fromCardinality !== undefined) {
177
+ attrs.push(`taillabel="${escapeDot(rel.fromCardinality)}"`);
178
+ }
179
+ if (rel.toCardinality !== undefined) {
180
+ attrs.push(`headlabel="${escapeDot(rel.toCardinality)}"`);
181
+ }
182
+ if (rel.label !== undefined) {
183
+ attrs.push(`label="${escapeDot(rel.label)}"`);
184
+ }
185
+ out.push(` "${escapeDot(rel.from)}" -> "${escapeDot(rel.to)}" [${attrs.join(", ")}];`);
186
+ }
187
+ out.push("}");
188
+ return out.join("\n") + "\n";
189
+ }
190
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sourceRoot":"","sources":["../../src/mermaid/class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAiC,MAAM,aAAa,CAAC;AAuC1F,MAAM,WAAW,GAA6D;IAC5E,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC3D,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAChE,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACzD,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACvD,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1D,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACtD,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IAC3D,CAAC,KAAK,E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I,CAAC,cAAc,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,UAAU,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChD,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1F,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACd,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { RenderError } from "../errors.ts";
2
+ /** The three Mermaid diagram kinds that the native layouts draw. */
3
+ export type DiagramKind = "class" | "state" | "sequence";
4
+ /** One content line of a source: its one-based number and its trimmed text. */
5
+ export interface ContentLine {
6
+ readonly number: number;
7
+ readonly text: string;
8
+ }
9
+ /** The lenient flag and the warnings that a parse shares. A skipped construct adds a warning. */
10
+ export interface Context {
11
+ readonly lenient: boolean;
12
+ readonly warnings: string[];
13
+ }
14
+ /** A source after the header. Comments, blank lines and skipped constructs are absent from `lines`. */
15
+ export interface Source extends Context {
16
+ readonly kind: DiagramKind;
17
+ readonly headerLine: number;
18
+ readonly lines: ContentLine[];
19
+ }
20
+ /**
21
+ * Reads the option `lenient` and checks the other keys. A key outside `lenient` and `extra` rejects with E_INPUT.
22
+ * An undefined value counts as an absent key.
23
+ */
24
+ export declare function readLenient(options: Record<string, unknown>, extra: readonly string[]): boolean;
25
+ /** The text of a request. The source is text for every Mermaid request, and a byte source is read as UTF-8. */
26
+ export declare function sourceText(source: string | Uint8Array): string;
27
+ /**
28
+ * Replaces each code point that XML 1.0 forbids with U+FFFD.
29
+ * Valid text, including surrogate pairs, stays unchanged.
30
+ */
31
+ export declare function xmlSafe(text: string): string;
32
+ /** An input error that names its source line. */
33
+ export declare function inputError(line: number, message: string): RenderError;
34
+ /**
35
+ * Handles a construct that the grammar does not accept. Without lenient it rejects with E_INPUT on its line.
36
+ * With lenient it records a warning on its line and returns, so that the caller can skip the construct.
37
+ */
38
+ export declare function outside(ctx: Context, line: number, text: string, why: string): void;
39
+ /**
40
+ * Prepares a source. It reads the options, removes blank lines, comment lines, directives and front matter,
41
+ * and reads the header. A whole Mermaid type that the native layouts do not draw rejects with E_UNSUPPORTED.
42
+ */
43
+ export declare function prepare(source: string, options: Record<string, unknown>, extra?: readonly string[]): Source;
44
+ /**
45
+ * Tells whether a source routes to the browser stage. A source routes there when the first word of its first
46
+ * content line is a Mermaid type of OTHER_TYPES. The scan skips blank lines, comment lines, directives and a
47
+ * leading front matter block, and it never throws: an unclosed front matter or an unknown header stays on the
48
+ * native path, which rejects it with E_INPUT.
49
+ */
50
+ export declare function routesToBrowser(source: string): boolean;