@danielsimonjr/sciengjs 0.1.0 → 0.2.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 (59) hide show
  1. package/README.md +19 -3
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/assets/index_bg.wasm +0 -0
  4. package/assets/licenses/MIT-viz-js.txt +21 -0
  5. package/dist/assets.d.ts +12 -0
  6. package/dist/assets.js +63 -0
  7. package/dist/assets.js.map +1 -0
  8. package/dist/config.d.ts +4 -0
  9. package/dist/config.js +10 -10
  10. package/dist/config.js.map +1 -1
  11. package/dist/core.js +1 -1
  12. package/dist/core.js.map +1 -1
  13. package/dist/errors.d.ts +6 -0
  14. package/dist/errors.js +15 -0
  15. package/dist/errors.js.map +1 -1
  16. package/dist/graph/backend-png.d.ts +6 -1
  17. package/dist/graph/backend-png.js +25 -7
  18. package/dist/graph/backend-png.js.map +1 -1
  19. package/dist/mermaid/backend-png.d.ts +6 -0
  20. package/dist/mermaid/backend-png.js +13 -0
  21. package/dist/mermaid/backend-png.js.map +1 -0
  22. package/dist/mermaid/backend-svg.d.ts +3 -0
  23. package/dist/mermaid/backend-svg.js +8 -0
  24. package/dist/mermaid/backend-svg.js.map +1 -0
  25. package/dist/mermaid/class.d.ts +37 -0
  26. package/dist/mermaid/class.js +190 -0
  27. package/dist/mermaid/class.js.map +1 -0
  28. package/dist/mermaid/common.d.ts +43 -0
  29. package/dist/mermaid/common.js +112 -0
  30. package/dist/mermaid/common.js.map +1 -0
  31. package/dist/mermaid/index.d.ts +10 -0
  32. package/dist/mermaid/index.js +11 -0
  33. package/dist/mermaid/index.js.map +1 -0
  34. package/dist/mermaid/render.d.ts +10 -0
  35. package/dist/mermaid/render.js +24 -0
  36. package/dist/mermaid/render.js.map +1 -0
  37. package/dist/mermaid/sequence-layout.d.ts +6 -0
  38. package/dist/mermaid/sequence-layout.js +268 -0
  39. package/dist/mermaid/sequence-layout.js.map +1 -0
  40. package/dist/mermaid/sequence.d.ts +62 -0
  41. package/dist/mermaid/sequence.js +199 -0
  42. package/dist/mermaid/sequence.js.map +1 -0
  43. package/dist/mermaid/state.d.ts +24 -0
  44. package/dist/mermaid/state.js +132 -0
  45. package/dist/mermaid/state.js.map +1 -0
  46. package/dist/pairs.js +2 -2
  47. package/dist/pairs.js.map +1 -1
  48. package/dist/raster/index.d.ts +6 -0
  49. package/dist/raster/index.js +13 -7
  50. package/dist/raster/index.js.map +1 -1
  51. package/dist/registry.js +2 -0
  52. package/dist/registry.js.map +1 -1
  53. package/dist/version.d.ts +1 -0
  54. package/dist/version.js +3 -0
  55. package/dist/version.js.map +1 -0
  56. package/dist/worker/entry.js +2 -2
  57. package/dist/worker/entry.js.map +1 -1
  58. package/dist/worker/protocol.d.ts +2 -0
  59. package/package.json +6 -2
@@ -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,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;IAChE,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;I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,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,43 @@
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;
@@ -0,0 +1,112 @@
1
+ import { RenderError } from "../errors.js";
2
+ const HEADERS = new Map([
3
+ ["classDiagram", "class"],
4
+ ["classDiagram-v2", "class"],
5
+ ["stateDiagram-v2", "state"],
6
+ ["sequenceDiagram", "sequence"],
7
+ ]);
8
+ /** Mermaid types that the native layouts do not draw. They need the browser stage, which this release does not build. */
9
+ const OTHER_TYPES = new Set([
10
+ "flowchart", "graph", "stateDiagram", "erDiagram", "gantt", "pie", "journey", "gitGraph", "mindmap",
11
+ "timeline", "quadrantChart", "requirementDiagram", "C4Context", "C4Container", "C4Component",
12
+ "C4Dynamic", "C4Deployment", "sankey-beta", "xychart-beta", "block-beta", "packet-beta", "kanban",
13
+ "architecture-beta", "zenuml",
14
+ ]);
15
+ /**
16
+ * Reads the option `lenient` and checks the other keys. A key outside `lenient` and `extra` rejects with E_INPUT.
17
+ * An undefined value counts as an absent key.
18
+ */
19
+ export function readLenient(options, extra) {
20
+ let lenient = false;
21
+ for (const [key, value] of Object.entries(options)) {
22
+ if (value === undefined)
23
+ continue;
24
+ if (key === "lenient") {
25
+ if (typeof value !== "boolean") {
26
+ throw new RenderError("E_INPUT", "option lenient must be true or false");
27
+ }
28
+ lenient = value;
29
+ }
30
+ else if (!extra.includes(key)) {
31
+ throw new RenderError("E_INPUT", `mermaid takes no option ${key}`);
32
+ }
33
+ }
34
+ return lenient;
35
+ }
36
+ /** The text of a request. The source is text for every Mermaid request, and a byte source is read as UTF-8. */
37
+ export function sourceText(source) {
38
+ return typeof source === "string" ? source : new TextDecoder().decode(source);
39
+ }
40
+ /**
41
+ * Replaces each code point that XML 1.0 forbids with U+FFFD.
42
+ * Valid text, including surrogate pairs, stays unchanged.
43
+ */
44
+ export function xmlSafe(text) {
45
+ return text.replace(/[^\u{9}\u{A}\u{D}\u{20}-\u{D7FF}\u{E000}-\u{FFFD}\u{10000}-\u{10FFFF}]/gu, "\u{FFFD}");
46
+ }
47
+ /** An input error that names its source line. */
48
+ export function inputError(line, message) {
49
+ return new RenderError("E_INPUT", `line ${line}: ${message}`, { line });
50
+ }
51
+ /**
52
+ * Handles a construct that the grammar does not accept. Without lenient it rejects with E_INPUT on its line.
53
+ * With lenient it records a warning on its line and returns, so that the caller can skip the construct.
54
+ */
55
+ export function outside(ctx, line, text, why) {
56
+ if (!ctx.lenient) {
57
+ throw inputError(line, `${why}: "${text}"`);
58
+ }
59
+ ctx.warnings.push(`line ${line}: skipped the unsupported construct "${text}"`);
60
+ }
61
+ /**
62
+ * Prepares a source. It reads the options, removes blank lines, comment lines, directives and front matter,
63
+ * and reads the header. A whole Mermaid type that the native layouts do not draw rejects with E_UNSUPPORTED.
64
+ */
65
+ export function prepare(source, options, extra = []) {
66
+ const ctx = { lenient: readLenient(options, extra), warnings: [] };
67
+ const raw = source.split(/\r?\n/);
68
+ const content = [];
69
+ for (let index = 0; index < raw.length; index += 1) {
70
+ const number = index + 1;
71
+ const text = (raw[index] ?? "").trim();
72
+ if (text === "")
73
+ continue;
74
+ if (content.length === 0 && text === "---") {
75
+ const close = raw.findIndex((line, at) => at > index && line.trim() === "---");
76
+ if (close < 0) {
77
+ throw inputError(number, "the front matter is not closed by a line of three dashes");
78
+ }
79
+ outside(ctx, number, text, "the front matter is outside the supported grammar");
80
+ index = close;
81
+ continue;
82
+ }
83
+ if (text.startsWith("%%{")) {
84
+ outside(ctx, number, text, "a directive is outside the supported grammar");
85
+ continue;
86
+ }
87
+ if (text.startsWith("%%"))
88
+ continue;
89
+ if (xmlSafe(text) !== text) {
90
+ ctx.warnings.push(`line ${number}: each character outside the XML 1.0 range is shown as U+FFFD`);
91
+ }
92
+ content.push({ number, text });
93
+ }
94
+ const head = content[0];
95
+ if (head === undefined) {
96
+ throw new RenderError("E_INPUT", "the source names no Mermaid diagram type");
97
+ }
98
+ const word = head.text.split(/\s+/)[0] ?? "";
99
+ const kind = HEADERS.get(head.text);
100
+ if (kind !== undefined) {
101
+ return { kind, headerLine: head.number, lines: content.slice(1), lenient: ctx.lenient, warnings: ctx.warnings };
102
+ }
103
+ if (OTHER_TYPES.has(word)) {
104
+ throw new RenderError("E_UNSUPPORTED", `line ${head.number}: ${word} diagrams need the browser stage, which this release does not build; ` +
105
+ "the native layouts draw classDiagram, stateDiagram-v2 and sequenceDiagram", { line: head.number });
106
+ }
107
+ if (HEADERS.has(word)) {
108
+ throw inputError(head.number, `the header ${word} takes no other text on its line`);
109
+ }
110
+ throw inputError(head.number, `"${head.text}" does not name a Mermaid diagram type that this release draws`);
111
+ }
112
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/mermaid/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAwB3C,MAAM,OAAO,GAAqC,IAAI,GAAG,CAAC;IACxD,CAAC,cAAc,EAAE,OAAO,CAAC;IACzB,CAAC,iBAAiB,EAAE,OAAO,CAAC;IAC5B,CAAC,iBAAiB,EAAE,OAAO,CAAC;IAC5B,CAAC,iBAAiB,EAAE,UAAU,CAAC;CAChC,CAAC,CAAC;AAEH,yHAAyH;AACzH,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAC;IAC/C,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS;IACnG,UAAU,EAAE,eAAe,EAAE,oBAAoB,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa;IAC5F,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,cAA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EAAE,CAAC;IAClH,CAAC;IACD,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,WAAW,CACnB,eAAe,EACf,QAAQ,IAAI,CAAC,MAAM,KAAK,IAAI,uEAAuE;YACjG,2EAA2E,EAC7E,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CACtB,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,IAAI,kCAAkC,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,IAAI,gEAAgE,CAAC,CAAC;AAC/G,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The public surface of the Mermaid native layouts. It holds the header and option reader, the parsers,
3
+ * the DOT builders, the sequence layout and the SVG render.
4
+ */
5
+ export { prepare, type Source } from "./common.ts";
6
+ export { parseClassDiagram, classToDot, type ClassModel, type ClassDef, type ClassRelation, type ClassArrow, type Marker, } from "./class.ts";
7
+ export { parseStateDiagram, stateToDot, type StateModel, type StateDef, type StateTransition } from "./state.ts";
8
+ export { parseSequenceDiagram, type SequenceModel, type SeqEvent, type Participant, type MessageEvent, type NoteEvent, type ActivateEvent, type DeactivateEvent, type Branch, type BlockEvent, } from "./sequence.ts";
9
+ export { layoutSequence } from "./sequence-layout.ts";
10
+ export { renderMermaidSvg, type MermaidSvg } from "./render.ts";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The public surface of the Mermaid native layouts. It holds the header and option reader, the parsers,
3
+ * the DOT builders, the sequence layout and the SVG render.
4
+ */
5
+ export { prepare } from "./common.js";
6
+ export { parseClassDiagram, classToDot, } from "./class.js";
7
+ export { parseStateDiagram, stateToDot } from "./state.js";
8
+ export { parseSequenceDiagram, } from "./sequence.js";
9
+ export { layoutSequence } from "./sequence-layout.js";
10
+ export { renderMermaidSvg } from "./render.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mermaid/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAe,MAAM,aAAa,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,UAAU,GAMX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAwD,MAAM,YAAY,CAAC;AACjH,OAAO,EACL,oBAAoB,GAUrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** The SVG text and the warnings of one Mermaid render. */
2
+ export interface MermaidSvg {
3
+ svg: string;
4
+ warnings: string[];
5
+ }
6
+ /**
7
+ * Renders one Mermaid source to SVG. A class or state diagram goes through DOT and the graph stage.
8
+ * A sequence diagram is laid out here. The only option is lenient.
9
+ */
10
+ export declare function renderMermaidSvg(source: string, options: Record<string, unknown>): Promise<MermaidSvg>;
@@ -0,0 +1,24 @@
1
+ import { dotToSvg } from "../graph/dot.js";
2
+ import { classToDot, parseClassDiagram } from "./class.js";
3
+ import { prepare } from "./common.js";
4
+ import { parseSequenceDiagram } from "./sequence.js";
5
+ import { layoutSequence } from "./sequence-layout.js";
6
+ import { parseStateDiagram, stateToDot } from "./state.js";
7
+ /**
8
+ * Renders one Mermaid source to SVG. A class or state diagram goes through DOT and the graph stage.
9
+ * A sequence diagram is laid out here. The only option is lenient.
10
+ */
11
+ export async function renderMermaidSvg(source, options) {
12
+ const src = prepare(source, options);
13
+ if (src.kind === "class") {
14
+ const dot = await dotToSvg(classToDot(parseClassDiagram(src)));
15
+ return { svg: dot.svg, warnings: [...src.warnings, ...dot.warnings] };
16
+ }
17
+ if (src.kind === "state") {
18
+ const dot = await dotToSvg(stateToDot(parseStateDiagram(src)));
19
+ return { svg: dot.svg, warnings: [...src.warnings, ...dot.warnings] };
20
+ }
21
+ const svg = layoutSequence(parseSequenceDiagram(src));
22
+ return { svg, warnings: [...src.warnings] };
23
+ }
24
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/mermaid/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAQ3D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAc,EAAE,OAAgC;IACrF,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxE,CAAC;IACD,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxE,CAAC;IACD,MAAM,GAAG,GAAG,cAAc,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { SequenceModel } from "./sequence.ts";
2
+ /**
3
+ * Lays out one sequence model into one SVG document string.
4
+ * Returns the document with the root element first, one element per line and a final newline.
5
+ */
6
+ export declare function layoutSequence(model: SequenceModel): string;