UNPKG

7.23 kBJavaScriptView Raw
1import { p as R, d as N, s as B } from "./styles-83c6d4e6.js";
2import { l as c, c as r, j as k, x as G, t as _, r as D, o as E, p as z, f as A } from "./mermaid-9357f3d0.js";
3import { G as P } from "./layout-816c0a3e.js";
4import { r as $ } from "./index-b9fa59d5.js";
5import "./edges-9aecf713.js";
6import "./createText-8ca1146d.js";
7import "./svgDraw-c2b80d25.js";
8import "./line-a77fdd5a.js";
9import "./array-2ff2c7a6.js";
10import "./constant-2fe7eae5.js";
11const S = (o) => A.sanitizeText(o, r());
12let v = {
13 dividerMargin: 10,
14 padding: 5,
15 textHeight: 10,
16 curve: void 0
17};
18const q = function(o, t, p, n) {
19 const e = Object.keys(o);
20 c.info("keys:", e), c.info(o), e.forEach(function(s) {
21 var y, d;
22 const l = o[s], i = {
23 shape: "rect",
24 id: l.id,
25 domId: l.domId,
26 labelText: S(l.id),
27 labelStyle: "",
28 style: "fill: none; stroke: black",
29 // TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
30 padding: ((y = r().flowchart) == null ? void 0 : y.padding) ?? ((d = r().class) == null ? void 0 : d.padding)
31 };
32 t.setNode(l.id, i), I(l.classes, t, p, n, l.id), c.info("setNode", i);
33 });
34}, I = function(o, t, p, n, e) {
35 const s = Object.keys(o);
36 c.info("keys:", s), c.info(o), s.forEach(function(l) {
37 var m, h;
38 const a = o[l];
39 let i = "";
40 a.cssClasses.length > 0 && (i = i + " " + a.cssClasses.join(" "));
41 const y = { labelStyle: "", style: "" }, d = a.label ?? a.id, f = 0, u = "class_box", b = {
42 labelStyle: y.labelStyle,
43 shape: u,
44 labelText: S(d),
45 classData: a,
46 rx: f,
47 ry: f,
48 class: i,
49 style: y.style,
50 id: a.id,
51 domId: a.domId,
52 tooltip: n.db.getTooltip(a.id, e) || "",
53 haveCallback: a.haveCallback,
54 link: a.link,
55 width: a.type === "group" ? 500 : void 0,
56 type: a.type,
57 // TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
58 padding: ((m = r().flowchart) == null ? void 0 : m.padding) ?? ((h = r().class) == null ? void 0 : h.padding)
59 };
60 t.setNode(a.id, b), e && t.setParent(a.id, e), c.info("setNode", b);
61 });
62}, F = function(o, t, p, n) {
63 c.info(o), o.forEach(function(e, s) {
64 var h, x;
65 const l = e, a = "", i = { labelStyle: "", style: "" }, y = l.text, d = 0, f = "note", u = {
66 labelStyle: i.labelStyle,
67 shape: f,
68 labelText: S(y),
69 noteData: l,
70 rx: d,
71 ry: d,
72 class: a,
73 style: i.style,
74 id: l.id,
75 domId: l.id,
76 tooltip: "",
77 type: "note",
78 // TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
79 padding: ((h = r().flowchart) == null ? void 0 : h.padding) ?? ((x = r().class) == null ? void 0 : x.padding)
80 };
81 if (t.setNode(l.id, u), c.info("setNode", u), !l.class || !(l.class in n))
82 return;
83 const b = p + s, m = {
84 id: `edgeNote${b}`,
85 //Set relationship style and line type
86 classes: "relation",
87 pattern: "dotted",
88 // Set link type for rendering
89 arrowhead: "none",
90 //Set edge extra labels
91 startLabelRight: "",
92 endLabelLeft: "",
93 //Set relation arrow types
94 arrowTypeStart: "none",
95 arrowTypeEnd: "none",
96 style: "fill:none",
97 labelStyle: "",
98 curve: D(v.curve, E)
99 };
100 t.setEdge(l.id, l.class, m, b);
101 });
102}, H = function(o, t) {
103 const p = r().flowchart;
104 let n = 0;
105 o.forEach(function(e) {
106 var l;
107 n++;
108 const s = {
109 //Set relationship style and line type
110 classes: "relation",
111 pattern: e.relation.lineType == 1 ? "dashed" : "solid",
112 id: "id" + n,
113 // Set link type for rendering
114 arrowhead: e.type === "arrow_open" ? "none" : "normal",
115 //Set edge extra labels
116 startLabelRight: e.relationTitle1 === "none" ? "" : e.relationTitle1,
117 endLabelLeft: e.relationTitle2 === "none" ? "" : e.relationTitle2,
118 //Set relation arrow types
119 arrowTypeStart: C(e.relation.type1),
120 arrowTypeEnd: C(e.relation.type2),
121 style: "fill:none",
122 labelStyle: "",
123 curve: D(p == null ? void 0 : p.curve, E)
124 };
125 if (c.info(s, e), e.style !== void 0) {
126 const a = z(e.style);
127 s.style = a.style, s.labelStyle = a.labelStyle;
128 }
129 e.text = e.title, e.text === void 0 ? e.style !== void 0 && (s.arrowheadStyle = "fill: #333") : (s.arrowheadStyle = "fill: #333", s.labelpos = "c", ((l = r().flowchart) == null ? void 0 : l.htmlLabels) ?? r().htmlLabels ? (s.labelType = "html", s.label = '<span class="edgeLabel">' + e.text + "</span>") : (s.labelType = "text", s.label = e.text.replace(A.lineBreakRegex, `
130`), e.style === void 0 && (s.style = s.style || "stroke: #333; stroke-width: 1.5px;fill:none"), s.labelStyle = s.labelStyle.replace("color:", "fill:"))), t.setEdge(e.id1, e.id2, s, n);
131 });
132}, V = function(o) {
133 v = {
134 ...v,
135 ...o
136 };
137}, W = async function(o, t, p, n) {
138 c.info("Drawing class - ", t);
139 const e = r().flowchart ?? r().class, s = r().securityLevel;
140 c.info("config:", e);
141 const l = (e == null ? void 0 : e.nodeSpacing) ?? 50, a = (e == null ? void 0 : e.rankSpacing) ?? 50, i = new P({
142 multigraph: !0,
143 compound: !0
144 }).setGraph({
145 rankdir: n.db.getDirection(),
146 nodesep: l,
147 ranksep: a,
148 marginx: 8,
149 marginy: 8
150 }).setDefaultEdgeLabel(function() {
151 return {};
152 }), y = n.db.getNamespaces(), d = n.db.getClasses(), f = n.db.getRelations(), u = n.db.getNotes();
153 c.info(f), q(y, i, t, n), I(d, i, t, n), H(f, i), F(u, i, f.length + 1, d);
154 let b;
155 s === "sandbox" && (b = k("#i" + t));
156 const m = s === "sandbox" ? (
157 // @ts-ignore Ignore type error for now
158 k(b.nodes()[0].contentDocument.body)
159 ) : k("body"), h = m.select(`[id="${t}"]`), x = m.select("#" + t + " g");
160 if (await $(
161 x,
162 i,
163 ["aggregation", "extension", "composition", "dependency", "lollipop"],
164 "classDiagram",
165 t
166 ), G.insertTitle(h, "classTitleText", (e == null ? void 0 : e.titleTopMargin) ?? 5, n.db.getDiagramTitle()), _(i, h, e == null ? void 0 : e.diagramPadding, e == null ? void 0 : e.useMaxWidth), !(e != null && e.htmlLabels)) {
167 const T = s === "sandbox" ? b.nodes()[0].contentDocument : document, M = T.querySelectorAll('[id="' + t + '"] .edgeLabel .label');
168 for (const w of M) {
169 const L = w.getBBox(), g = T.createElementNS("http://www.w3.org/2000/svg", "rect");
170 g.setAttribute("rx", 0), g.setAttribute("ry", 0), g.setAttribute("width", L.width), g.setAttribute("height", L.height), w.insertBefore(g, w.firstChild);
171 }
172 }
173};
174function C(o) {
175 let t;
176 switch (o) {
177 case 0:
178 t = "aggregation";
179 break;
180 case 1:
181 t = "extension";
182 break;
183 case 2:
184 t = "composition";
185 break;
186 case 3:
187 t = "dependency";
188 break;
189 case 4:
190 t = "lollipop";
191 break;
192 default:
193 t = "none";
194 }
195 return t;
196}
197const J = {
198 setConf: V,
199 draw: W
200}, se = {
201 parser: R,
202 db: N,
203 renderer: J,
204 styles: B,
205 init: (o) => {
206 o.class || (o.class = {}), o.class.arrowMarkerAbsolute = o.arrowMarkerAbsolute, N.clear();
207 }
208};
209export {
210 se as diagram
211};