UNPKG

13.1 kBJavaScriptView Raw
1import { d as N, p as C, s as U } from "./styles-4ffad38c.js";
2import { c as t, D as F, x as O, f as L, l as b, j as H, k as X } from "./mermaid-9357f3d0.js";
3import { G as P, l as J } from "./layout-816c0a3e.js";
4import { l as Y } from "./line-a77fdd5a.js";
5import "./array-2ff2c7a6.js";
6import "./constant-2fe7eae5.js";
7const T = {}, $ = (e, n) => {
8 T[e] = n;
9}, v = (e) => T[e], R = () => Object.keys(T), I = () => R().length, _ = {
10 get: v,
11 set: $,
12 keys: R,
13 size: I
14}, j = (e) => e.append("circle").attr("class", "start-state").attr("r", t().state.sizeUnit).attr("cx", t().state.padding + t().state.sizeUnit).attr("cy", t().state.padding + t().state.sizeUnit), q = (e) => e.append("line").style("stroke", "grey").style("stroke-dasharray", "3").attr("x1", t().state.textHeight).attr("class", "divider").attr("x2", t().state.textHeight * 2).attr("y1", 0).attr("y2", 0), D = (e, n) => {
15 const o = e.append("text").attr("x", 2 * t().state.padding).attr("y", t().state.textHeight + 2 * t().state.padding).attr("font-size", t().state.fontSize).attr("class", "state-title").text(n.id), d = o.node().getBBox();
16 return e.insert("rect", ":first-child").attr("x", t().state.padding).attr("y", t().state.padding).attr("width", d.width + 2 * t().state.padding).attr("height", d.height + 2 * t().state.padding).attr("rx", t().state.radius), o;
17}, Z = (e, n) => {
18 const o = function(c, m, f) {
19 const S = c.append("tspan").attr("x", 2 * t().state.padding).text(m);
20 f || S.attr("dy", t().state.textHeight);
21 }, s = e.append("text").attr("x", 2 * t().state.padding).attr("y", t().state.textHeight + 1.3 * t().state.padding).attr("font-size", t().state.fontSize).attr("class", "state-title").text(n.descriptions[0]).node().getBBox(), g = s.height, p = e.append("text").attr("x", t().state.padding).attr(
22 "y",
23 g + t().state.padding * 0.4 + t().state.dividerMargin + t().state.textHeight
24 ).attr("class", "state-description");
25 let a = !0, r = !0;
26 n.descriptions.forEach(function(c) {
27 a || (o(p, c, r), r = !1), a = !1;
28 });
29 const w = e.append("line").attr("x1", t().state.padding).attr("y1", t().state.padding + g + t().state.dividerMargin / 2).attr("y2", t().state.padding + g + t().state.dividerMargin / 2).attr("class", "descr-divider"), x = p.node().getBBox(), l = Math.max(x.width, s.width);
30 return w.attr("x2", l + 3 * t().state.padding), e.insert("rect", ":first-child").attr("x", t().state.padding).attr("y", t().state.padding).attr("width", l + 2 * t().state.padding).attr("height", x.height + g + 2 * t().state.padding).attr("rx", t().state.radius), e;
31}, K = (e, n, o) => {
32 const d = t().state.padding, s = 2 * t().state.padding, g = e.node().getBBox(), p = g.width, a = g.x, r = e.append("text").attr("x", 0).attr("y", t().state.titleShift).attr("font-size", t().state.fontSize).attr("class", "state-title").text(n.id), x = r.node().getBBox().width + s;
33 let l = Math.max(x, p);
34 l === p && (l = l + s);
35 let c;
36 const m = e.node().getBBox();
37 n.doc, c = a - d, x > p && (c = (p - l) / 2 + d), Math.abs(a - m.x) < d && x > p && (c = a - (x - p) / 2);
38 const f = 1 - t().state.textHeight;
39 return e.insert("rect", ":first-child").attr("x", c).attr("y", f).attr("class", o ? "alt-composit" : "composit").attr("width", l).attr(
40 "height",
41 m.height + t().state.textHeight + t().state.titleShift + 1
42 ).attr("rx", "0"), r.attr("x", c + d), x <= p && r.attr("x", a + (l - s) / 2 - x / 2 + d), e.insert("rect", ":first-child").attr("x", c).attr(
43 "y",
44 t().state.titleShift - t().state.textHeight - t().state.padding
45 ).attr("width", l).attr("height", t().state.textHeight * 3).attr("rx", t().state.radius), e.insert("rect", ":first-child").attr("x", c).attr(
46 "y",
47 t().state.titleShift - t().state.textHeight - t().state.padding
48 ).attr("width", l).attr("height", m.height + 3 + 2 * t().state.textHeight).attr("rx", t().state.radius), e;
49}, Q = (e) => (e.append("circle").attr("class", "end-state-outer").attr("r", t().state.sizeUnit + t().state.miniPadding).attr(
50 "cx",
51 t().state.padding + t().state.sizeUnit + t().state.miniPadding
52).attr(
53 "cy",
54 t().state.padding + t().state.sizeUnit + t().state.miniPadding
55), e.append("circle").attr("class", "end-state-inner").attr("r", t().state.sizeUnit).attr("cx", t().state.padding + t().state.sizeUnit + 2).attr("cy", t().state.padding + t().state.sizeUnit + 2)), V = (e, n) => {
56 let o = t().state.forkWidth, d = t().state.forkHeight;
57 if (n.parentId) {
58 let s = o;
59 o = d, d = s;
60 }
61 return e.append("rect").style("stroke", "black").style("fill", "black").attr("width", o).attr("height", d).attr("x", t().state.padding).attr("y", t().state.padding);
62}, tt = (e, n, o, d) => {
63 let s = 0;
64 const g = d.append("text");
65 g.style("text-anchor", "start"), g.attr("class", "noteText");
66 let p = e.replace(/\r\n/g, "<br/>");
67 p = p.replace(/\n/g, "<br/>");
68 const a = p.split(L.lineBreakRegex);
69 let r = 1.25 * t().state.noteMargin;
70 for (const w of a) {
71 const x = w.trim();
72 if (x.length > 0) {
73 const l = g.append("tspan");
74 if (l.text(x), r === 0) {
75 const c = l.node().getBBox();
76 r += c.height;
77 }
78 s += r, l.attr("x", n + t().state.noteMargin), l.attr("y", o + s + 1.25 * t().state.noteMargin);
79 }
80 }
81 return { textWidth: g.node().getBBox().width, textHeight: s };
82}, et = (e, n) => {
83 n.attr("class", "state-note");
84 const o = n.append("rect").attr("x", 0).attr("y", t().state.padding), d = n.append("g"), { textWidth: s, textHeight: g } = tt(e, 0, 0, d);
85 return o.attr("height", g + 2 * t().state.noteMargin), o.attr("width", s + t().state.noteMargin * 2), o;
86}, G = function(e, n) {
87 const o = n.id, d = {
88 id: o,
89 label: n.id,
90 width: 0,
91 height: 0
92 }, s = e.append("g").attr("id", o).attr("class", "stateGroup");
93 n.type === "start" && j(s), n.type === "end" && Q(s), (n.type === "fork" || n.type === "join") && V(s, n), n.type === "note" && et(n.note.text, s), n.type === "divider" && q(s), n.type === "default" && n.descriptions.length === 0 && D(s, n), n.type === "default" && n.descriptions.length > 0 && Z(s, n);
94 const g = s.node().getBBox();
95 return d.width = g.width + 2 * t().state.padding, d.height = g.height + 2 * t().state.padding, _.set(o, d), d;
96};
97let A = 0;
98const at = function(e, n, o) {
99 const d = function(r) {
100 switch (r) {
101 case N.relationType.AGGREGATION:
102 return "aggregation";
103 case N.relationType.EXTENSION:
104 return "extension";
105 case N.relationType.COMPOSITION:
106 return "composition";
107 case N.relationType.DEPENDENCY:
108 return "dependency";
109 }
110 };
111 n.points = n.points.filter((r) => !Number.isNaN(r.y));
112 const s = n.points, g = Y().x(function(r) {
113 return r.x;
114 }).y(function(r) {
115 return r.y;
116 }).curve(F), p = e.append("path").attr("d", g(s)).attr("id", "edge" + A).attr("class", "transition");
117 let a = "";
118 if (t().state.arrowMarkerAbsolute && (a = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search, a = a.replace(/\(/g, "\\("), a = a.replace(/\)/g, "\\)")), p.attr(
119 "marker-end",
120 "url(" + a + "#" + d(N.relationType.DEPENDENCY) + "End)"
121 ), o.title !== void 0) {
122 const r = e.append("g").attr("class", "stateLabel"), { x: w, y: x } = O.calcLabelPosition(n.points), l = L.getRows(o.title);
123 let c = 0;
124 const m = [];
125 let f = 0, S = 0;
126 for (let u = 0; u <= l.length; u++) {
127 const h = r.append("text").attr("text-anchor", "middle").text(l[u]).attr("x", w).attr("y", x + c), y = h.node().getBBox();
128 f = Math.max(f, y.width), S = Math.min(S, y.x), b.info(y.x, w, x + c), c === 0 && (c = h.node().getBBox().height, b.info("Title height", c, x)), m.push(h);
129 }
130 let E = c * l.length;
131 if (l.length > 1) {
132 const u = (l.length - 1) * c * 0.5;
133 m.forEach((h, y) => h.attr("y", x + y * c - u)), E = c * l.length;
134 }
135 const i = r.node().getBBox();
136 r.insert("rect", ":first-child").attr("class", "box").attr("x", w - f / 2 - t().state.padding / 2).attr("y", x - E / 2 - t().state.padding / 2 - 3.5).attr("width", f + t().state.padding).attr("height", E + t().state.padding), b.info(i);
137 }
138 A++;
139};
140let B;
141const z = {}, nt = function() {
142}, it = function(e) {
143 e.append("defs").append("marker").attr("id", "dependencyEnd").attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 19,7 L9,13 L14,7 L9,1 Z");
144}, st = function(e, n, o, d) {
145 B = t().state;
146 const s = t().securityLevel;
147 let g;
148 s === "sandbox" && (g = H("#i" + n));
149 const p = s === "sandbox" ? H(g.nodes()[0].contentDocument.body) : H("body"), a = s === "sandbox" ? g.nodes()[0].contentDocument : document;
150 b.debug("Rendering diagram " + e);
151 const r = p.select(`[id='${n}']`);
152 it(r), new P({
153 multigraph: !0,
154 compound: !0,
155 // acyclicer: 'greedy',
156 rankdir: "RL"
157 // ranksep: '20'
158 }).setDefaultEdgeLabel(function() {
159 return {};
160 });
161 const x = d.db.getRootDoc();
162 W(x, r, void 0, !1, p, a, d);
163 const l = B.padding, c = r.node().getBBox(), m = c.width + l * 2, f = c.height + l * 2, S = m * 1.75;
164 X(r, f, S, B.useMaxWidth), r.attr(
165 "viewBox",
166 `${c.x - B.padding} ${c.y - B.padding} ` + m + " " + f
167 );
168}, rt = (e) => e ? e.length * B.fontSizeFactor : 1, W = (e, n, o, d, s, g, p) => {
169 const a = new P({
170 compound: !0,
171 multigraph: !0
172 });
173 let r, w = !0;
174 for (r = 0; r < e.length; r++)
175 if (e[r].stmt === "relation") {
176 w = !1;
177 break;
178 }
179 o ? a.setGraph({
180 rankdir: "LR",
181 multigraph: !0,
182 compound: !0,
183 // acyclicer: 'greedy',
184 ranker: "tight-tree",
185 ranksep: w ? 1 : B.edgeLengthFactor,
186 nodeSep: w ? 1 : 50,
187 isMultiGraph: !0
188 // ranksep: 5,
189 // nodesep: 1
190 }) : a.setGraph({
191 rankdir: "TB",
192 multigraph: !0,
193 compound: !0,
194 // isCompound: true,
195 // acyclicer: 'greedy',
196 // ranker: 'longest-path'
197 ranksep: w ? 1 : B.edgeLengthFactor,
198 nodeSep: w ? 1 : 50,
199 ranker: "tight-tree",
200 // ranker: 'network-simplex'
201 isMultiGraph: !0
202 }), a.setDefaultEdgeLabel(function() {
203 return {};
204 }), p.db.extract(e);
205 const x = p.db.getStates(), l = p.db.getRelations(), c = Object.keys(x);
206 for (const i of c) {
207 const u = x[i];
208 o && (u.parentId = o);
209 let h;
210 if (u.doc) {
211 let y = n.append("g").attr("id", u.id).attr("class", "stateGroup");
212 h = W(u.doc, y, u.id, !d, s, g, p);
213 {
214 y = K(y, u, d);
215 let k = y.node().getBBox();
216 h.width = k.width, h.height = k.height + B.padding / 2, z[u.id] = { y: B.compositTitleSize };
217 }
218 } else
219 h = G(n, u);
220 if (u.note) {
221 const y = {
222 descriptions: [],
223 id: u.id + "-note",
224 note: u.note,
225 type: "note"
226 }, k = G(n, y);
227 u.note.position === "left of" ? (a.setNode(h.id + "-note", k), a.setNode(h.id, h)) : (a.setNode(h.id, h), a.setNode(h.id + "-note", k)), a.setParent(h.id, h.id + "-group"), a.setParent(h.id + "-note", h.id + "-group");
228 } else
229 a.setNode(h.id, h);
230 }
231 b.debug("Count=", a.nodeCount(), a);
232 let m = 0;
233 l.forEach(function(i) {
234 m++, b.debug("Setting edge", i), a.setEdge(
235 i.id1,
236 i.id2,
237 {
238 relation: i,
239 width: rt(i.title),
240 height: B.labelHeight * L.getRows(i.title).length,
241 labelpos: "c"
242 },
243 "id" + m
244 );
245 }), J(a), b.debug("Graph after layout", a.nodes());
246 const f = n.node();
247 a.nodes().forEach(function(i) {
248 i !== void 0 && a.node(i) !== void 0 ? (b.warn("Node " + i + ": " + JSON.stringify(a.node(i))), s.select("#" + f.id + " #" + i).attr(
249 "transform",
250 "translate(" + (a.node(i).x - a.node(i).width / 2) + "," + (a.node(i).y + (z[i] ? z[i].y : 0) - a.node(i).height / 2) + " )"
251 ), s.select("#" + f.id + " #" + i).attr("data-x-shift", a.node(i).x - a.node(i).width / 2), g.querySelectorAll("#" + f.id + " #" + i + " .divider").forEach((h) => {
252 const y = h.parentElement;
253 let k = 0, M = 0;
254 y && (y.parentElement && (k = y.parentElement.getBBox().width), M = parseInt(y.getAttribute("data-x-shift"), 10), Number.isNaN(M) && (M = 0)), h.setAttribute("x1", 0 - M + 8), h.setAttribute("x2", k - M - 8);
255 })) : b.debug("No Node " + i + ": " + JSON.stringify(a.node(i)));
256 });
257 let S = f.getBBox();
258 a.edges().forEach(function(i) {
259 i !== void 0 && a.edge(i) !== void 0 && (b.debug("Edge " + i.v + " -> " + i.w + ": " + JSON.stringify(a.edge(i))), at(n, a.edge(i), a.edge(i).relation));
260 }), S = f.getBBox();
261 const E = {
262 id: o || "root",
263 label: o || "root",
264 width: 0,
265 height: 0
266 };
267 return E.width = S.width + 2 * B.padding, E.height = S.height + 2 * B.padding, b.debug("Doc rendered", E, a), E;
268}, ot = {
269 setConf: nt,
270 draw: st
271}, xt = {
272 parser: C,
273 db: N,
274 renderer: ot,
275 styles: U,
276 init: (e) => {
277 e.state || (e.state = {}), e.state.arrowMarkerAbsolute = e.arrowMarkerAbsolute, N.clear();
278 }
279};
280export {
281 xt as diagram
282};