UNPKG

6.95 kBJavaScriptView Raw
1import { D as H, a as Q, S as X, b as Z, c as j, p as F, d as M, s as I } from "./styles-4ffad38c.js";
2import { G as tt } from "./layout-816c0a3e.js";
3import { l, c as g, j as $, x as et, k as st, f as w } from "./mermaid-9357f3d0.js";
4import { r as ot } 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 h = "rect", C = "rectWithTitle", nt = "start", ct = "end", it = "divider", rt = "roundedWithTitle", lt = "note", at = "noteGroup", u = "statediagram", dt = "state", Et = `${u}-${dt}`, U = "transition", St = "note", Tt = "note-edge", pt = `${U} ${Tt}`, ut = `${u}-${St}`, _t = "cluster", ft = `${u}-${_t}`, Dt = "cluster-alt", bt = `${u}-${Dt}`, V = "parent", Y = "note", At = "state", N = "----", ht = `${N}${Y}`, v = `${N}${V}`, W = "fill:none", z = "fill: #333", m = "c", q = "text", K = "normal";
12let y = {}, E = 0;
13const yt = function(t) {
14 const n = Object.keys(t);
15 for (const e of n)
16 t[e];
17}, gt = function(t, n) {
18 l.trace("Extracting classes"), n.db.clear();
19 try {
20 return n.parser.parse(t), n.db.extract(n.db.getRootDocV2()), n.db.getClasses();
21 } catch (e) {
22 return e;
23 }
24};
25function xt(t) {
26 return t == null ? "" : t.classes ? t.classes.join(" ") : "";
27}
28function R(t = "", n = 0, e = "", c = N) {
29 const i = e !== null && e.length > 0 ? `${c}${e}` : "";
30 return `${At}-${t}${i}-${n}`;
31}
32const A = (t, n, e, c, i, r) => {
33 const s = e.id, _ = xt(c[s]);
34 if (s !== "root") {
35 let T = h;
36 e.start === !0 && (T = nt), e.start === !1 && (T = ct), e.type !== H && (T = e.type), y[s] || (y[s] = {
37 id: s,
38 shape: T,
39 description: w.sanitizeText(s, g()),
40 classes: `${_} ${Et}`
41 });
42 const o = y[s];
43 e.description && (Array.isArray(o.description) ? (o.shape = C, o.description.push(e.description)) : o.description.length > 0 ? (o.shape = C, o.description === s ? o.description = [e.description] : o.description = [o.description, e.description]) : (o.shape = h, o.description = e.description), o.description = w.sanitizeTextOrArray(o.description, g())), o.description.length === 1 && o.shape === C && (o.shape = h), !o.type && e.doc && (l.info("Setting cluster for ", s, G(e)), o.type = "group", o.dir = G(e), o.shape = e.type === Q ? it : rt, o.classes = o.classes + " " + ft + " " + (r ? bt : ""));
44 const p = {
45 labelStyle: "",
46 shape: o.shape,
47 labelText: o.description,
48 // typeof newNode.description === 'object'
49 // ? newNode.description[0]
50 // : newNode.description,
51 classes: o.classes,
52 style: "",
53 //styles.style,
54 id: s,
55 dir: o.dir,
56 domId: R(s, E),
57 type: o.type,
58 padding: 15
59 //getConfig().flowchart.padding
60 };
61 if (p.centerLabel = !0, e.note) {
62 const a = {
63 labelStyle: "",
64 shape: lt,
65 labelText: e.note.text,
66 classes: ut,
67 // useHtmlLabels: false,
68 style: "",
69 // styles.style,
70 id: s + ht + "-" + E,
71 domId: R(s, E, Y),
72 type: o.type,
73 padding: 15
74 //getConfig().flowchart.padding
75 }, d = {
76 labelStyle: "",
77 shape: at,
78 labelText: e.note.text,
79 classes: o.classes,
80 style: "",
81 // styles.style,
82 id: s + v,
83 domId: R(s, E, V),
84 type: "group",
85 padding: 0
86 //getConfig().flowchart.padding
87 };
88 E++;
89 const f = s + v;
90 t.setNode(f, d), t.setNode(a.id, a), t.setNode(s, p), t.setParent(s, f), t.setParent(a.id, f);
91 let S = s, D = a.id;
92 e.note.position === "left of" && (S = a.id, D = s), t.setEdge(S, D, {
93 arrowhead: "none",
94 arrowType: "",
95 style: W,
96 labelStyle: "",
97 classes: pt,
98 arrowheadStyle: z,
99 labelpos: m,
100 labelType: q,
101 thickness: K
102 });
103 } else
104 t.setNode(s, p);
105 }
106 n && n.id !== "root" && (l.trace("Setting node ", s, " to be child of its parent ", n.id), t.setParent(s, n.id)), e.doc && (l.trace("Adding nodes children "), $t(t, e, e.doc, c, i, !r));
107}, $t = (t, n, e, c, i, r) => {
108 l.trace("items", e), e.forEach((s) => {
109 switch (s.stmt) {
110 case Z:
111 A(t, n, s, c, i, r);
112 break;
113 case H:
114 A(t, n, s, c, i, r);
115 break;
116 case X:
117 {
118 A(t, n, s.state1, c, i, r), A(t, n, s.state2, c, i, r);
119 const _ = {
120 id: "edge" + E,
121 arrowhead: "normal",
122 arrowTypeEnd: "arrow_barb",
123 style: W,
124 labelStyle: "",
125 label: w.sanitizeText(s.description, g()),
126 arrowheadStyle: z,
127 labelpos: m,
128 labelType: q,
129 thickness: K,
130 classes: U
131 };
132 t.setEdge(s.state1.id, s.state2.id, _, E), E++;
133 }
134 break;
135 }
136 });
137}, G = (t, n = j) => {
138 let e = n;
139 if (t.doc)
140 for (let c = 0; c < t.doc.length; c++) {
141 const i = t.doc[c];
142 i.stmt === "dir" && (e = i.value);
143 }
144 return e;
145}, Ct = async function(t, n, e, c) {
146 l.info("Drawing state diagram (v2)", n), y = {}, c.db.getDirection();
147 const { securityLevel: i, state: r } = g(), s = r.nodeSpacing || 50, _ = r.rankSpacing || 50;
148 l.info(c.db.getRootDocV2()), c.db.extract(c.db.getRootDocV2()), l.info(c.db.getRootDocV2());
149 const T = c.db.getStates(), o = new tt({
150 multigraph: !0,
151 compound: !0
152 }).setGraph({
153 rankdir: G(c.db.getRootDocV2()),
154 nodesep: s,
155 ranksep: _,
156 marginx: 8,
157 marginy: 8
158 }).setDefaultEdgeLabel(function() {
159 return {};
160 });
161 A(o, void 0, c.db.getRootDocV2(), T, c.db, !0);
162 let p;
163 i === "sandbox" && (p = $("#i" + n));
164 const a = i === "sandbox" ? $(p.nodes()[0].contentDocument.body) : $("body"), d = a.select(`[id="${n}"]`), f = a.select("#" + n + " g");
165 await ot(f, o, ["barb"], u, n);
166 const S = 8;
167 et.insertTitle(d, "statediagramTitleText", r.titleTopMargin, c.db.getDiagramTitle());
168 const D = d.node().getBBox(), L = D.width + S * 2, P = D.height + S * 2;
169 d.attr("class", u);
170 const k = d.node().getBBox();
171 st(d, P, L, r.useMaxWidth);
172 const O = `${k.x - S} ${k.y - S} ${L} ${P}`;
173 l.debug(`viewBox ${O}`), d.attr("viewBox", O);
174 const J = document.querySelectorAll('[id="' + n + '"] .edgeLabel .label');
175 for (const x of J) {
176 const B = x.getBBox(), b = document.createElementNS("http://www.w3.org/2000/svg", h);
177 b.setAttribute("rx", 0), b.setAttribute("ry", 0), b.setAttribute("width", B.width), b.setAttribute("height", B.height), x.insertBefore(b, x.firstChild);
178 }
179}, Rt = {
180 setConf: yt,
181 getClasses: gt,
182 draw: Ct
183}, Ht = {
184 parser: F,
185 db: M,
186 renderer: Rt,
187 styles: I,
188 init: (t) => {
189 t.state || (t.state = {}), t.state.arrowMarkerAbsolute = t.arrowMarkerAbsolute, M.clear();
190 }
191};
192export {
193 Ht as diagram
194};