UNPKG

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