1 | import { b as j, a as m, m as D, G, l as A } from "./layout-816c0a3e.js";
|
2 | import { c as O, i as X, a as M, b as _, d as $, u as H, s as V, e as q, f as U, p as B, g as W, h as Y } from "./edges-9aecf713.js";
|
3 | import { l as i, q as N, c as E, j as L } from "./mermaid-9357f3d0.js";
|
4 | import { c as z } from "./createText-8ca1146d.js";
|
5 | var K = 4;
|
6 | function Q(e) {
|
7 | return j(e, K);
|
8 | }
|
9 | function y(e) {
|
10 | var t = {
|
11 | options: {
|
12 | directed: e.isDirected(),
|
13 | multigraph: e.isMultigraph(),
|
14 | compound: e.isCompound()
|
15 | },
|
16 | nodes: Z(e),
|
17 | edges: I(e)
|
18 | };
|
19 | return m(e.graph()) || (t.value = Q(e.graph())), t;
|
20 | }
|
21 | function Z(e) {
|
22 | return D(e.nodes(), function(t) {
|
23 | var n = e.node(t), r = e.parent(t), s = { v: t };
|
24 | return m(n) || (s.value = n), m(r) || (s.parent = r), s;
|
25 | });
|
26 | }
|
27 | function I(e) {
|
28 | return D(e.edges(), function(t) {
|
29 | var n = e.edge(t), r = { v: t.v, w: t.w };
|
30 | return m(t.name) || (r.name = t.name), m(n) || (r.value = n), r;
|
31 | });
|
32 | }
|
33 | let f = {}, x = {}, T = {};
|
34 | const tt = () => {
|
35 | x = {}, T = {}, f = {};
|
36 | }, S = (e, t) => (i.trace("In isDecendant", t, " ", e, " = ", x[t].includes(e)), !!x[t].includes(e)), et = (e, t) => (i.info("Decendants of ", t, " is ", x[t]), i.info("Edge is ", e), e.v === t || e.w === t ? !1 : x[t] ? x[t].includes(e.v) || S(e.v, t) || S(e.w, t) || x[t].includes(e.w) : (i.debug("Tilt, ", t, ",not in decendants"), !1)), J = (e, t, n, r) => {
|
37 | i.warn(
|
38 | "Copying children of ",
|
39 | e,
|
40 | "root",
|
41 | r,
|
42 | "data",
|
43 | t.node(e),
|
44 | r
|
45 | );
|
46 | const s = t.children(e) || [];
|
47 | e !== r && s.push(e), i.warn("Copying (nodes) clusterId", e, "nodes", s), s.forEach((a) => {
|
48 | if (t.children(a).length > 0)
|
49 | J(a, t, n, r);
|
50 | else {
|
51 | const u = t.node(a);
|
52 | i.info("cp ", a, " to ", r, " with parent ", e), n.setNode(a, u), r !== t.parent(a) && (i.warn("Setting parent", a, t.parent(a)), n.setParent(a, t.parent(a))), e !== r && a !== e ? (i.debug("Setting parent", a, e), n.setParent(a, e)) : (i.info("In copy ", e, "root", r, "data", t.node(e), r), i.debug(
|
53 | "Not Setting parent for node=",
|
54 | a,
|
55 | "cluster!==rootId",
|
56 | e !== r,
|
57 | "node!==clusterId",
|
58 | a !== e
|
59 | ));
|
60 | const l = t.edges(a);
|
61 | i.debug("Copying Edges", l), l.forEach((d) => {
|
62 | i.info("Edge", d);
|
63 | const w = t.edge(d.v, d.w, d.name);
|
64 | i.info("Edge data", w, r);
|
65 | try {
|
66 | et(d, r) ? (i.info("Copying as ", d.v, d.w, w, d.name), n.setEdge(d.v, d.w, w, d.name), i.info("newGraph edges ", n.edges(), n.edge(n.edges()[0]))) : i.info(
|
67 | "Skipping copy of edge ",
|
68 | d.v,
|
69 | "-->",
|
70 | d.w,
|
71 | " rootId: ",
|
72 | r,
|
73 | " clusterId:",
|
74 | e
|
75 | );
|
76 | } catch (g) {
|
77 | i.error(g);
|
78 | }
|
79 | });
|
80 | }
|
81 | i.debug("Removing node", a), t.removeNode(a);
|
82 | });
|
83 | }, p = (e, t) => {
|
84 | const n = t.children(e);
|
85 | let r = [...n];
|
86 | for (const s of n)
|
87 | T[s] = e, r = [...r, ...p(s, t)];
|
88 | return r;
|
89 | }, b = (e, t) => {
|
90 | i.trace("Searching", e);
|
91 | const n = t.children(e);
|
92 | if (i.trace("Searching children of id ", e, n), n.length < 1)
|
93 | return i.trace("This is a valid node", e), e;
|
94 | for (const r of n) {
|
95 | const s = b(r, t);
|
96 | if (s)
|
97 | return i.trace("Found replacement for", e, " => ", s), s;
|
98 | }
|
99 | }, v = (e) => !f[e] || !f[e].externalConnections ? e : f[e] ? f[e].id : e, nt = (e, t) => {
|
100 | if (!e || t > 10) {
|
101 | i.debug("Opting out, no graph ");
|
102 | return;
|
103 | } else
|
104 | i.debug("Opting in, graph ");
|
105 | e.nodes().forEach(function(n) {
|
106 | e.children(n).length > 0 && (i.warn(
|
107 | "Cluster identified",
|
108 | n,
|
109 | " Replacement id in edges: ",
|
110 | b(n, e)
|
111 | ), x[n] = p(n, e), f[n] = { id: b(n, e), clusterData: e.node(n) });
|
112 | }), e.nodes().forEach(function(n) {
|
113 | const r = e.children(n), s = e.edges();
|
114 | r.length > 0 ? (i.debug("Cluster identified", n, x), s.forEach((a) => {
|
115 | if (a.v !== n && a.w !== n) {
|
116 | const u = S(a.v, n), l = S(a.w, n);
|
117 | u ^ l && (i.warn("Edge: ", a, " leaves cluster ", n), i.warn("Decendants of XXX ", n, ": ", x[n]), f[n].externalConnections = !0);
|
118 | }
|
119 | })) : i.debug("Not a cluster ", n, x);
|
120 | }), e.edges().forEach(function(n) {
|
121 | const r = e.edge(n);
|
122 | i.warn("Edge " + n.v + " -> " + n.w + ": " + JSON.stringify(n)), i.warn("Edge " + n.v + " -> " + n.w + ": " + JSON.stringify(e.edge(n)));
|
123 | let s = n.v, a = n.w;
|
124 | if (i.warn(
|
125 | "Fix XXX",
|
126 | f,
|
127 | "ids:",
|
128 | n.v,
|
129 | n.w,
|
130 | "Translating: ",
|
131 | f[n.v],
|
132 | " --- ",
|
133 | f[n.w]
|
134 | ), f[n.v] && f[n.w] && f[n.v] === f[n.w]) {
|
135 | i.warn("Fixing and trixing link to self - removing XXX", n.v, n.w, n.name), i.warn("Fixing and trixing - removing XXX", n.v, n.w, n.name), s = v(n.v), a = v(n.w), e.removeEdge(n.v, n.w, n.name);
|
136 | const u = n.w + "---" + n.v;
|
137 | e.setNode(u, {
|
138 | domId: u,
|
139 | id: u,
|
140 | labelStyle: "",
|
141 | labelText: r.label,
|
142 | padding: 0,
|
143 | shape: "labelRect",
|
144 | style: ""
|
145 | });
|
146 | const l = JSON.parse(JSON.stringify(r)), d = JSON.parse(JSON.stringify(r));
|
147 | l.label = "", l.arrowTypeEnd = "none", d.label = "", l.fromCluster = n.v, d.toCluster = n.v, e.setEdge(s, u, l, n.name + "-cyclic-special"), e.setEdge(u, a, d, n.name + "-cyclic-special");
|
148 | } else
|
149 | (f[n.v] || f[n.w]) && (i.warn("Fixing and trixing - removing XXX", n.v, n.w, n.name), s = v(n.v), a = v(n.w), e.removeEdge(n.v, n.w, n.name), s !== n.v && (r.fromCluster = n.v), a !== n.w && (r.toCluster = n.w), i.warn("Fix Replacing with XXX", s, a, n.name), e.setEdge(s, a, r, n.name));
|
150 | }), i.warn("Adjusted Graph", y(e)), R(e, 0), i.trace(f);
|
151 | }, R = (e, t) => {
|
152 | if (i.warn("extractor - ", t, y(e), e.children("D")), t > 10) {
|
153 | i.error("Bailing out");
|
154 | return;
|
155 | }
|
156 | let n = e.nodes(), r = !1;
|
157 | for (const s of n) {
|
158 | const a = e.children(s);
|
159 | r = r || a.length > 0;
|
160 | }
|
161 | if (!r) {
|
162 | i.debug("Done, no node has children", e.nodes());
|
163 | return;
|
164 | }
|
165 | i.debug("Nodes = ", n, t);
|
166 | for (const s of n)
|
167 | if (i.debug(
|
168 | "Extracting node",
|
169 | s,
|
170 | f,
|
171 | f[s] && !f[s].externalConnections,
|
172 | !e.parent(s),
|
173 | e.node(s),
|
174 | e.children("D"),
|
175 | " Depth ",
|
176 | t
|
177 | ), !f[s])
|
178 | i.debug("Not a cluster", s, t);
|
179 | else if (!f[s].externalConnections &&
|
180 | e.children(s) && e.children(s).length > 0) {
|
181 | i.warn(
|
182 | "Cluster without external connections, without a parent and with children",
|
183 | s,
|
184 | t
|
185 | );
|
186 | let u = e.graph().rankdir === "TB" ? "LR" : "TB";
|
187 | f[s] && f[s].clusterData && f[s].clusterData.dir && (u = f[s].clusterData.dir, i.warn("Fixing dir", f[s].clusterData.dir, u));
|
188 | const l = new G({
|
189 | multigraph: !0,
|
190 | compound: !0
|
191 | }).setGraph({
|
192 | rankdir: u,
|
193 |
|
194 | nodesep: 50,
|
195 | ranksep: 50,
|
196 | marginx: 8,
|
197 | marginy: 8
|
198 | }).setDefaultEdgeLabel(function() {
|
199 | return {};
|
200 | });
|
201 | i.warn("Old graph before copy", y(e)), J(s, e, l, s), e.setNode(s, {
|
202 | clusterNode: !0,
|
203 | id: s,
|
204 | clusterData: f[s].clusterData,
|
205 | labelText: f[s].labelText,
|
206 | graph: l
|
207 | }), i.warn("New graph after copy node: (", s, ")", y(l)), i.debug("Old graph after copy", y(e));
|
208 | } else
|
209 | i.warn(
|
210 | "Cluster ** ",
|
211 | s,
|
212 | " **not meeting the criteria !externalConnections:",
|
213 | !f[s].externalConnections,
|
214 | " no parent: ",
|
215 | !e.parent(s),
|
216 | " children ",
|
217 | e.children(s) && e.children(s).length > 0,
|
218 | e.children("D"),
|
219 | t
|
220 | ), i.debug(f);
|
221 | n = e.nodes(), i.warn("New list of nodes", n);
|
222 | for (const s of n) {
|
223 | const a = e.node(s);
|
224 | i.warn(" Now next level", s, a), a.clusterNode && R(a.graph, t + 1);
|
225 | }
|
226 | }, P = (e, t) => {
|
227 | if (t.length === 0)
|
228 | return [];
|
229 | let n = Object.assign(t);
|
230 | return t.forEach((r) => {
|
231 | const s = e.children(r), a = P(e, s);
|
232 | n = [...n, ...a];
|
233 | }), n;
|
234 | }, it = (e) => P(e, e.children()), st = (e, t) => {
|
235 | i.info("Creating subgraph rect for ", t.id, t);
|
236 | const n = e.insert("g").attr("class", "cluster" + (t.class ? " " + t.class : "")).attr("id", t.id), r = n.insert("rect", ":first-child"), s = N(E().flowchart.htmlLabels), a = n.insert("g").attr("class", "cluster-label"), u = t.labelType === "markdown" ? z(a, t.labelText, { style: t.labelStyle, useHtmlLabels: s }) : a.node().appendChild(O(t.labelText, t.labelStyle, void 0, !0));
|
237 | let l = u.getBBox();
|
238 | if (N(E().flowchart.htmlLabels)) {
|
239 | const o = u.children[0], h = L(u);
|
240 | l = o.getBoundingClientRect(), h.attr("width", l.width), h.attr("height", l.height);
|
241 | }
|
242 | const d = 0 * t.padding, w = d / 2, g = t.width <= l.width + d ? l.width + d : t.width;
|
243 | t.width <= l.width + d ? t.diff = (l.width - t.width) / 2 - t.padding / 2 : t.diff = -t.padding / 2, i.trace("Data ", t, JSON.stringify(t)), r.attr("style", t.style).attr("rx", t.rx).attr("ry", t.ry).attr("x", t.x - g / 2).attr("y", t.y - t.height / 2 - w).attr("width", g).attr("height", t.height + d), s ? a.attr(
|
244 | "transform",
|
245 |
|
246 | "translate(" + (t.x - l.width / 2) + ", " + (t.y - t.height / 2) + ")"
|
247 | ) : a.attr(
|
248 | "transform",
|
249 |
|
250 | "translate(" + t.x + ", " + (t.y - t.height / 2) + ")"
|
251 | );
|
252 | const c = r.node().getBBox();
|
253 | return t.width = c.width, t.height = c.height, t.intersect = function(o) {
|
254 | return X(t, o);
|
255 | }, n;
|
256 | }, rt = (e, t) => {
|
257 | const n = e.insert("g").attr("class", "note-cluster").attr("id", t.id), r = n.insert("rect", ":first-child"), s = 0 * t.padding, a = s / 2;
|
258 | r.attr("rx", t.rx).attr("ry", t.ry).attr("x", t.x - t.width / 2 - a).attr("y", t.y - t.height / 2 - a).attr("width", t.width + s).attr("height", t.height + s).attr("fill", "none");
|
259 | const u = r.node().getBBox();
|
260 | return t.width = u.width, t.height = u.height, t.intersect = function(l) {
|
261 | return X(t, l);
|
262 | }, n;
|
263 | }, at = (e, t) => {
|
264 | const n = e.insert("g").attr("class", t.classes).attr("id", t.id), r = n.insert("rect", ":first-child"), s = n.insert("g").attr("class", "cluster-label"), a = n.append("rect"), u = s.node().appendChild(O(t.labelText, t.labelStyle, void 0, !0));
|
265 | let l = u.getBBox();
|
266 | if (N(E().flowchart.htmlLabels)) {
|
267 | const o = u.children[0], h = L(u);
|
268 | l = o.getBoundingClientRect(), h.attr("width", l.width), h.attr("height", l.height);
|
269 | }
|
270 | l = u.getBBox();
|
271 | const d = 0 * t.padding, w = d / 2, g = t.width <= l.width + t.padding ? l.width + t.padding : t.width;
|
272 | t.width <= l.width + t.padding ? t.diff = (l.width + t.padding * 0 - t.width) / 2 : t.diff = -t.padding / 2, r.attr("class", "outer").attr("x", t.x - g / 2 - w).attr("y", t.y - t.height / 2 - w).attr("width", g + d).attr("height", t.height + d), a.attr("class", "inner").attr("x", t.x - g / 2 - w).attr("y", t.y - t.height / 2 - w + l.height - 1).attr("width", g + d).attr("height", t.height + d - l.height - 3), s.attr(
|
273 | "transform",
|
274 | "translate(" + (t.x - l.width / 2) + ", " + (t.y - t.height / 2 - t.padding / 3 + (N(E().flowchart.htmlLabels) ? 5 : 3)) + ")"
|
275 | );
|
276 | const c = r.node().getBBox();
|
277 | return t.height = c.height, t.intersect = function(o) {
|
278 | return X(t, o);
|
279 | }, n;
|
280 | }, ct = (e, t) => {
|
281 | const n = e.insert("g").attr("class", t.classes).attr("id", t.id), r = n.insert("rect", ":first-child"), s = 0 * t.padding, a = s / 2;
|
282 | r.attr("class", "divider").attr("x", t.x - t.width / 2 - a).attr("y", t.y - t.height / 2).attr("width", t.width + s).attr("height", t.height + s);
|
283 | const u = r.node().getBBox();
|
284 | return t.width = u.width, t.height = u.height, t.diff = -t.padding / 2, t.intersect = function(l) {
|
285 | return X(t, l);
|
286 | }, n;
|
287 | }, ot = { rect: st, roundedWithTitle: at, noteGroup: rt, divider: ct };
|
288 | let F = {};
|
289 | const lt = (e, t) => {
|
290 | i.trace("Inserting cluster");
|
291 | const n = t.shape || "rect";
|
292 | F[t.id] = ot[n](e, t);
|
293 | }, ft = () => {
|
294 | F = {};
|
295 | }, k = async (e, t, n, r) => {
|
296 | i.info("Graph in recursive render: XXX", y(t), r);
|
297 | const s = t.graph().rankdir;
|
298 | i.trace("Dir in recursive render - dir:", s);
|
299 | const a = e.insert("g").attr("class", "root");
|
300 | t.nodes() ? i.info("Recursive render XXX", t.nodes()) : i.info("No nodes found for", t), t.edges().length > 0 && i.trace("Recursive edges", t.edge(t.edges()[0]));
|
301 | const u = a.insert("g").attr("class", "clusters"), l = a.insert("g").attr("class", "edgePaths"), d = a.insert("g").attr("class", "edgeLabels"), w = a.insert("g").attr("class", "nodes");
|
302 | await Promise.all(
|
303 | t.nodes().map(async function(c) {
|
304 | const o = t.node(c);
|
305 | if (r !== void 0) {
|
306 | const h = JSON.parse(JSON.stringify(r.clusterData));
|
307 | i.info("Setting data for cluster XXX (", c, ") ", h, r), t.setNode(r.id, h), t.parent(c) || (i.trace("Setting parent", c, r.id), t.setParent(c, r.id, h));
|
308 | }
|
309 | if (i.info("(Insert) Node XXX" + c + ": " + JSON.stringify(t.node(c))), o && o.clusterNode) {
|
310 | i.info("Cluster identified", c, o.width, t.node(c));
|
311 | const h = await k(w, o.graph, n, t.node(c)), C = h.elem;
|
312 | H(o, C), o.diff = h.diff || 0, i.info("Node bounds (abc123)", c, o, o.width, o.x, o.y), V(C, o), i.warn("Recursive render complete ", C, o);
|
313 | } else
|
314 | t.children(c).length > 0 ? (i.info("Cluster - the non recursive path XXX", c, o.id, o, t), i.info(b(o.id, t)), f[o.id] = { id: b(o.id, t), node: o }) : (i.info("Node - the non recursive path", c, o.id, o), await q(w, t.node(c), s));
|
315 | })
|
316 | ), t.edges().forEach(function(c) {
|
317 | const o = t.edge(c.v, c.w, c.name);
|
318 | i.info("Edge " + c.v + " -> " + c.w + ": " + JSON.stringify(c)), i.info("Edge " + c.v + " -> " + c.w + ": ", c, " ", JSON.stringify(t.edge(c))), i.info("Fix", f, "ids:", c.v, c.w, "Translateing: ", f[c.v], f[c.w]), U(d, o);
|
319 | }), t.edges().forEach(function(c) {
|
320 | i.info("Edge " + c.v + " -> " + c.w + ": " + JSON.stringify(c));
|
321 | }), i.info("#############################################"), i.info("### Layout ###"), i.info("#############################################"), i.info(t), A(t), i.info("Graph after layout:", y(t));
|
322 | let g = 0;
|
323 | return it(t).forEach(function(c) {
|
324 | const o = t.node(c);
|
325 | i.info("Position " + c + ": " + JSON.stringify(t.node(c))), i.info(
|
326 | "Position " + c + ": (" + o.x,
|
327 | "," + o.y,
|
328 | ") width: ",
|
329 | o.width,
|
330 | " height: ",
|
331 | o.height
|
332 | ), o && o.clusterNode ? B(o) : t.children(c).length > 0 ? (lt(u, o), f[o.id].node = o) : B(o);
|
333 | }), t.edges().forEach(function(c) {
|
334 | const o = t.edge(c);
|
335 | i.info("Edge " + c.v + " -> " + c.w + ": " + JSON.stringify(o), o);
|
336 | const h = W(l, c, o, f, n, t);
|
337 | Y(o, h);
|
338 | }), t.nodes().forEach(function(c) {
|
339 | const o = t.node(c);
|
340 | i.info(c, o.type, o.diff), o.type === "group" && (g = o.diff);
|
341 | }), { elem: a, diff: g };
|
342 | }, gt = async (e, t, n, r, s) => {
|
343 | M(e, n, r, s), _(), $(), ft(), tt(), i.warn("Graph at first:", y(t)), nt(t), i.warn("Graph after:", y(t)), await k(e, t, r);
|
344 | };
|
345 | export {
|
346 | gt as r
|
347 | };
|