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