@8btc/xcanvas 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +70 -0
  2. package/dist/Tableau10-BqnYsPR6.js +9 -0
  3. package/dist/XCanvas-BxdLBkBz.js +27732 -0
  4. package/dist/_commonjs-dynamic-modules-TGKdzP3c.js +6 -0
  5. package/dist/ar-SA-G6X2FPQ2-DjqDLLYL.js +41 -0
  6. package/dist/arc-D1qX5GFf.js +132 -0
  7. package/dist/array-DgktLKBx.js +6 -0
  8. package/dist/az-AZ-76LH7QW2-D7LOsF3_.js +32 -0
  9. package/dist/bg-BG-XCXSNQG7-WI4tFn23.js +36 -0
  10. package/dist/blockDiagram-38ab4fdb-DtemKfEh.js +1811 -0
  11. package/dist/bn-BD-2XOGV67Q-Bugx_8fy.js +36 -0
  12. package/dist/c4Diagram-3d4e48cf-Byd2vU9K.js +2463 -0
  13. package/dist/ca-ES-6MX7JW3Y-6rFwKGsQ.js +39 -0
  14. package/dist/channel-BT_3Ze-Y.js +7 -0
  15. package/dist/chunk-EIO257PC-C7qD7hGu.js +1641 -0
  16. package/dist/classDiagram-70f12bd4-CwfYadk-.js +354 -0
  17. package/dist/classDiagram-v2-f2320105-B28MuM8f.js +284 -0
  18. package/dist/clone-D2FUK8WY.js +8 -0
  19. package/dist/createText-2e5e7dd3-Ca1JfQaJ.js +4914 -0
  20. package/dist/cs-CZ-2BRQDIVT-Dhd8XszK.js +42 -0
  21. package/dist/da-DK-5WZEPLOC-BhL87sSs.js +36 -0
  22. package/dist/de-DE-XR44H4JA-xSrZSV0J.js +39 -0
  23. package/dist/directory-open-01563666-XowynPwH.js +14 -0
  24. package/dist/directory-open-4ed118d0-BwYbu9dw.js +55 -0
  25. package/dist/edges-e0da2a9e-9VbVapWU.js +1840 -0
  26. package/dist/el-GR-BZB4AONW-DQORZ_pY.js +41 -0
  27. package/dist/en-B4ZKOASM-D2BVbEdz.js +39 -0
  28. package/dist/erDiagram-9861fffd-D4S9QDes.js +1318 -0
  29. package/dist/es-ES-U4NZUMDT-C0Q89-0V.js +40 -0
  30. package/dist/eu-ES-A7QVB2H4-BwBW3cEw.js +42 -0
  31. package/dist/fa-IR-HGAKTJCU-DtZ74rm4.js +39 -0
  32. package/dist/fi-FI-Z5N7JZ37-QvQan48z.js +37 -0
  33. package/dist/file-open-002ab408-BNIYSKAV.js +18 -0
  34. package/dist/file-open-7c801643-B_l1UXdI.js +15 -0
  35. package/dist/file-save-3189631c-vzijizFw.js +23 -0
  36. package/dist/file-save-745eba88-B5-wM56X.js +25 -0
  37. package/dist/flowDb-956e92f1-S6T8ppJw.js +1713 -0
  38. package/dist/flowDiagram-66a62f08-C6TTwS5_.js +1264 -0
  39. package/dist/flowDiagram-v2-96b9c2cf-CzfeUNGP.js +24 -0
  40. package/dist/flowchart-elk-definition-4a651766-CRv1kWtk.js +92922 -0
  41. package/dist/fr-FR-RHASNOE6-CZFiweNU.js +40 -0
  42. package/dist/ganttDiagram-c361ad54-CAnfd8Sw.js +3420 -0
  43. package/dist/gitGraphDiagram-72cf32ee-CSGI-xRI.js +1790 -0
  44. package/dist/gl-ES-HMX3MZ6V-Bqv2xL-V.js +41 -0
  45. package/dist/graph-Ct2tKpKj.js +1253 -0
  46. package/dist/he-IL-6SHJWFNN-kso30jhn.js +41 -0
  47. package/dist/hi-IN-IWLTKZ5I-Busk5oaa.js +35 -0
  48. package/dist/hu-HU-A5ZG7DT2-xSR2C2H0.js +38 -0
  49. package/dist/id-ID-SAP4L64H-BQQZYm1L.js +41 -0
  50. package/dist/image-EDRW2JGV-Cx7o2kxD.js +6 -0
  51. package/dist/image-blob-reduce.esm-BKPqMdie.js +2396 -0
  52. package/dist/index-3862675e-B3j3w-v_.js +663 -0
  53. package/dist/index-CLOU2Ikr.js +14364 -0
  54. package/dist/index.css +450 -0
  55. package/dist/index.d.ts +40 -0
  56. package/dist/index.js +7 -0
  57. package/dist/index.umd.cjs +235477 -0
  58. package/dist/infoDiagram-f8f76790-NqA75uBo.js +510 -0
  59. package/dist/init-ZxktEp_H.js +16 -0
  60. package/dist/it-IT-JPQ66NNP-CAMVZrYt.js +42 -0
  61. package/dist/ja-JP-DBVTYXUO-CAX8A_Uj.js +39 -0
  62. package/dist/journeyDiagram-49397b02-By5oBzsZ.js +1182 -0
  63. package/dist/kaa-6HZHGXH3-4-o94cPY.js +32 -0
  64. package/dist/kab-KAB-ZGHBKWFO-CgyjjBvZ.js +39 -0
  65. package/dist/katex-C-jAQc2m.js +14516 -0
  66. package/dist/kk-KZ-P5N5QNE5-BEqZcwLA.js +32 -0
  67. package/dist/km-KH-HSX4SM5Z-DvKDbeH4.js +42 -0
  68. package/dist/ko-KR-MTYHY66A-DKCuAbKE.js +40 -0
  69. package/dist/ku-TR-6OUDTVRD-CNUs4cCe.js +40 -0
  70. package/dist/layout-AJxYKqQV.js +2292 -0
  71. package/dist/line-DJIf5OM8.js +45 -0
  72. package/dist/linear-Cfj4s4vI.js +539 -0
  73. package/dist/lt-LT-XHIRWOB4-gouzGdoW.js +34 -0
  74. package/dist/lv-LV-5QDEKY6T-CTvg1XFv.js +38 -0
  75. package/dist/mindmap-definition-fc14e90a-CBlwH_UF.js +35283 -0
  76. package/dist/mr-IN-CRQNXWMA-QeYm06Kq.js +44 -0
  77. package/dist/my-MM-5M5IBNSE-DG3k9ORf.js +32 -0
  78. package/dist/nb-NO-T6EIAALU-Cj995Nmg.js +41 -0
  79. package/dist/nl-NL-IS3SIHDZ-B-2H7xey.js +39 -0
  80. package/dist/nn-NO-6E72VCQL-DrAwKKTN.js +39 -0
  81. package/dist/oc-FR-POXYY2M6-CeyJD7tq.js +39 -0
  82. package/dist/ordinal-DSZU4PqD.js +76 -0
  83. package/dist/pa-IN-N4M65BXN-DHzi6mjo.js +35 -0
  84. package/dist/path-Cp2qmpkd.js +109 -0
  85. package/dist/percentages-BXMCSKIN-CDYsTuua.js +6 -0
  86. package/dist/pica-CzzcRNRD.js +1702 -0
  87. package/dist/pieDiagram-8a3498a8-DueGoZOh.js +768 -0
  88. package/dist/pl-PL-T2D74RX3-BBNEV2c6.js +40 -0
  89. package/dist/pt-BR-5N22H2LF-D2cTx_F0.js +40 -0
  90. package/dist/pt-PT-UZXXM6DQ-BddvLLsF.js +40 -0
  91. package/dist/quadrantDiagram-120e2f19-Tb6_oGIn.js +1198 -0
  92. package/dist/requirementDiagram-deff3bca-CEeg0ep-.js +1089 -0
  93. package/dist/ro-RO-JPDTUUEW-DynuW50i.js +42 -0
  94. package/dist/roundRect-CjfubgrN.js +152 -0
  95. package/dist/ru-RU-B4JR7IUQ-B5Hecrew.js +40 -0
  96. package/dist/sankeyDiagram-04a897e0-CGTLQ8Gm.js +1172 -0
  97. package/dist/sequenceDiagram-704730f1-CZ72D-Nd.js +3336 -0
  98. package/dist/si-LK-N5RQ5JYF-BGMa93tc.js +32 -0
  99. package/dist/sk-SK-C5VTKIMK-BttCAlBm.js +37 -0
  100. package/dist/sl-SI-NN7IZMDC-DTC59nzG.js +37 -0
  101. package/dist/stateDiagram-587899a1-XISZzz_f.js +451 -0
  102. package/dist/stateDiagram-v2-d93cdb3a-DbCcmzTc.js +319 -0
  103. package/dist/styles-6aaf32cf-CyfdkEib.js +1363 -0
  104. package/dist/styles-9a916d00-zQ92RrTB.js +1483 -0
  105. package/dist/styles-c10674c1-BWmkigmR.js +571 -0
  106. package/dist/subset-shared.chunk-BuFt2PpZ.js +8 -0
  107. package/dist/subset-worker.chunk-CgaFXU4O.js +14 -0
  108. package/dist/sv-SE-XGPEYMSR-BPDlPxC1.js +41 -0
  109. package/dist/svgDrawCommon-08f97a94-CJ0lufOi.js +100 -0
  110. package/dist/ta-IN-2NMHFXQM-CI1ZsNk9.js +40 -0
  111. package/dist/th-TH-HPSO5L25-CUM-w2Qt.js +33 -0
  112. package/dist/timeline-definition-85554ec2-DV6084Gl.js +1210 -0
  113. package/dist/tr-TR-DEFEU3FU-CGpyf_vD.js +38 -0
  114. package/dist/uk-UA-QMV73CPH-Bg15Mv3J.js +37 -0
  115. package/dist/vi-VN-M7AON7JQ-AYmca9so.js +36 -0
  116. package/dist/vite.svg +1 -0
  117. package/dist/xychartDiagram-e933f94c-P1e6EEaH.js +1796 -0
  118. package/dist/zh-CN-LNUGB5OW-Dem2Cc-c.js +41 -0
  119. package/dist/zh-HK-E62DVLB3-BjsDyiLI.js +32 -0
  120. package/dist/zh-TW-RAJ6MFWO-IDAsc9Pz.js +40 -0
  121. package/package.json +52 -0
@@ -0,0 +1,1264 @@
1
+ import { f as flowDb, p as parser$1 } from "./flowDb-956e92f1-S6T8ppJw.js";
2
+ import { h as has, f as forEach, G as Graph } from "./graph-Ct2tKpKj.js";
3
+ import { d as select, a1 as curveLinear, l as log$1, g as getConfig, _ as setupGraphViewbox$1, $ as getStylesFromArray, a0 as interpolateToCurve, v as evaluate, W as renderKatex, k as common$1 } from "./index-CLOU2Ikr.js";
4
+ import { u as uniqueId, r as range, p as pick, l as layout, d as defaults } from "./layout-AJxYKqQV.js";
5
+ import { b as applyStyle, c as addHtmlLabel, i as isSubgraph, d as applyTransition, e as edgeToId, g as applyClass, f as flowStyles, a as flowRendererV2, s as selectAll } from "./styles-c10674c1-BWmkigmR.js";
6
+ import { l as line } from "./line-DJIf5OM8.js";
7
+ function responseText(response) {
8
+ if (!response.ok) throw new Error(response.status + " " + response.statusText);
9
+ return response.text();
10
+ }
11
+ function text(input, init) {
12
+ return fetch(input, init).then(responseText);
13
+ }
14
+ function parser(type) {
15
+ return (input, init) => text(input, init).then((text2) => new DOMParser().parseFromString(text2, type));
16
+ }
17
+ var svg = parser("image/svg+xml");
18
+ var arrows = {
19
+ normal,
20
+ vee,
21
+ undirected
22
+ };
23
+ function setArrows(value) {
24
+ arrows = value;
25
+ }
26
+ function normal(parent, id, edge, type) {
27
+ var marker = parent.append("marker").attr("id", id).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto");
28
+ var path = marker.append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").style("stroke-width", 1).style("stroke-dasharray", "1,0");
29
+ applyStyle(path, edge[type + "Style"]);
30
+ if (edge[type + "Class"]) {
31
+ path.attr("class", edge[type + "Class"]);
32
+ }
33
+ }
34
+ function vee(parent, id, edge, type) {
35
+ var marker = parent.append("marker").attr("id", id).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto");
36
+ var path = marker.append("path").attr("d", "M 0 0 L 10 5 L 0 10 L 4 5 z").style("stroke-width", 1).style("stroke-dasharray", "1,0");
37
+ applyStyle(path, edge[type + "Style"]);
38
+ if (edge[type + "Class"]) {
39
+ path.attr("class", edge[type + "Class"]);
40
+ }
41
+ }
42
+ function undirected(parent, id, edge, type) {
43
+ var marker = parent.append("marker").attr("id", id).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto");
44
+ var path = marker.append("path").attr("d", "M 0 5 L 10 5").style("stroke-width", 1).style("stroke-dasharray", "1,0");
45
+ applyStyle(path, edge[type + "Style"]);
46
+ if (edge[type + "Class"]) {
47
+ path.attr("class", edge[type + "Class"]);
48
+ }
49
+ }
50
+ function addSVGLabel(root, node) {
51
+ var domNode = root;
52
+ domNode.node().appendChild(node.label);
53
+ applyStyle(domNode, node.labelStyle);
54
+ return domNode;
55
+ }
56
+ function addTextLabel(root, node) {
57
+ var domNode = root.append("text");
58
+ var lines = processEscapeSequences(node.label).split("\n");
59
+ for (var i = 0; i < lines.length; i++) {
60
+ domNode.append("tspan").attr("xml:space", "preserve").attr("dy", "1em").attr("x", "1").text(lines[i]);
61
+ }
62
+ applyStyle(domNode, node.labelStyle);
63
+ return domNode;
64
+ }
65
+ function processEscapeSequences(text2) {
66
+ var newText = "";
67
+ var escaped = false;
68
+ var ch;
69
+ for (var i = 0; i < text2.length; ++i) {
70
+ ch = text2[i];
71
+ if (escaped) {
72
+ switch (ch) {
73
+ case "n":
74
+ newText += "\n";
75
+ break;
76
+ default:
77
+ newText += ch;
78
+ }
79
+ escaped = false;
80
+ } else if (ch === "\\") {
81
+ escaped = true;
82
+ } else {
83
+ newText += ch;
84
+ }
85
+ }
86
+ return newText;
87
+ }
88
+ function addLabel(root, node, location2) {
89
+ var label = node.label;
90
+ var labelSvg = root.append("g");
91
+ if (node.labelType === "svg") {
92
+ addSVGLabel(labelSvg, node);
93
+ } else if (typeof label !== "string" || node.labelType === "html") {
94
+ addHtmlLabel(labelSvg, node);
95
+ } else {
96
+ addTextLabel(labelSvg, node);
97
+ }
98
+ var labelBBox = labelSvg.node().getBBox();
99
+ var y;
100
+ switch (location2) {
101
+ case "top":
102
+ y = -node.height / 2;
103
+ break;
104
+ case "bottom":
105
+ y = node.height / 2 - labelBBox.height;
106
+ break;
107
+ default:
108
+ y = -labelBBox.height / 2;
109
+ }
110
+ labelSvg.attr("transform", "translate(" + -labelBBox.width / 2 + "," + y + ")");
111
+ return labelSvg;
112
+ }
113
+ var createClusters = function(selection, g) {
114
+ var clusters = g.nodes().filter(function(v) {
115
+ return isSubgraph(g, v);
116
+ });
117
+ var svgClusters = selection.selectAll("g.cluster").data(clusters, function(v) {
118
+ return v;
119
+ });
120
+ applyTransition(svgClusters.exit(), g).style("opacity", 0).remove();
121
+ var enterSelection = svgClusters.enter().append("g").attr("class", "cluster").attr("id", function(v) {
122
+ var node = g.node(v);
123
+ return node.id;
124
+ }).style("opacity", 0).each(function(v) {
125
+ var node = g.node(v);
126
+ var thisGroup = select(this);
127
+ select(this).append("rect");
128
+ var labelGroup = thisGroup.append("g").attr("class", "label");
129
+ addLabel(labelGroup, node, node.clusterLabelPos);
130
+ });
131
+ svgClusters = svgClusters.merge(enterSelection);
132
+ svgClusters = applyTransition(svgClusters, g).style("opacity", 1);
133
+ svgClusters.selectAll("rect").each(function(c) {
134
+ var node = g.node(c);
135
+ var domCluster = select(this);
136
+ applyStyle(domCluster, node.style);
137
+ });
138
+ return svgClusters;
139
+ };
140
+ function setCreateClusters(value) {
141
+ createClusters = value;
142
+ }
143
+ let createEdgeLabels = function(selection, g) {
144
+ var svgEdgeLabels = selection.selectAll("g.edgeLabel").data(g.edges(), function(e) {
145
+ return edgeToId(e);
146
+ }).classed("update", true);
147
+ svgEdgeLabels.exit().remove();
148
+ svgEdgeLabels.enter().append("g").classed("edgeLabel", true).style("opacity", 0);
149
+ svgEdgeLabels = selection.selectAll("g.edgeLabel");
150
+ svgEdgeLabels.each(function(e) {
151
+ var root = select(this);
152
+ root.select(".label").remove();
153
+ var edge = g.edge(e);
154
+ var label = addLabel(root, g.edge(e), 0).classed("label", true);
155
+ var bbox = label.node().getBBox();
156
+ if (edge.labelId) {
157
+ label.attr("id", edge.labelId);
158
+ }
159
+ if (!has(edge, "width")) {
160
+ edge.width = bbox.width;
161
+ }
162
+ if (!has(edge, "height")) {
163
+ edge.height = bbox.height;
164
+ }
165
+ });
166
+ var exitSelection;
167
+ if (svgEdgeLabels.exit) {
168
+ exitSelection = svgEdgeLabels.exit();
169
+ } else {
170
+ exitSelection = svgEdgeLabels.selectAll(null);
171
+ }
172
+ applyTransition(exitSelection, g).style("opacity", 0).remove();
173
+ return svgEdgeLabels;
174
+ };
175
+ function setCreateEdgeLabels(value) {
176
+ createEdgeLabels = value;
177
+ }
178
+ function intersectNode(node, point) {
179
+ return node.intersect(point);
180
+ }
181
+ var createEdgePaths = function(selection, g, arrows2) {
182
+ var previousPaths = selection.selectAll("g.edgePath").data(g.edges(), function(e) {
183
+ return edgeToId(e);
184
+ }).classed("update", true);
185
+ var newPaths = enter(previousPaths, g);
186
+ exit(previousPaths, g);
187
+ var svgPaths = previousPaths.merge !== void 0 ? previousPaths.merge(newPaths) : previousPaths;
188
+ applyTransition(svgPaths, g).style("opacity", 1);
189
+ svgPaths.each(function(e) {
190
+ var domEdge = select(this);
191
+ var edge = g.edge(e);
192
+ edge.elem = this;
193
+ if (edge.id) {
194
+ domEdge.attr("id", edge.id);
195
+ }
196
+ applyClass(
197
+ domEdge,
198
+ edge["class"],
199
+ (domEdge.classed("update") ? "update " : "") + "edgePath"
200
+ );
201
+ });
202
+ svgPaths.selectAll("path.path").each(function(e) {
203
+ var edge = g.edge(e);
204
+ edge.arrowheadId = uniqueId("arrowhead");
205
+ var domEdge = select(this).attr("marker-end", function() {
206
+ return "url(" + makeFragmentRef(location.href, edge.arrowheadId) + ")";
207
+ }).style("fill", "none");
208
+ applyTransition(domEdge, g).attr("d", function(e2) {
209
+ return calcPoints(g, e2);
210
+ });
211
+ applyStyle(domEdge, edge.style);
212
+ });
213
+ svgPaths.selectAll("defs *").remove();
214
+ svgPaths.selectAll("defs").each(function(e) {
215
+ var edge = g.edge(e);
216
+ var arrowhead = arrows2[edge.arrowhead];
217
+ arrowhead(select(this), edge.arrowheadId, edge, "arrowhead");
218
+ });
219
+ return svgPaths;
220
+ };
221
+ function setCreateEdgePaths(value) {
222
+ createEdgePaths = value;
223
+ }
224
+ function makeFragmentRef(url, fragmentId) {
225
+ var baseUrl = url.split("#")[0];
226
+ return baseUrl + "#" + fragmentId;
227
+ }
228
+ function calcPoints(g, e) {
229
+ var edge = g.edge(e);
230
+ var tail = g.node(e.v);
231
+ var head = g.node(e.w);
232
+ var points = edge.points.slice(1, edge.points.length - 1);
233
+ points.unshift(intersectNode(tail, points[0]));
234
+ points.push(intersectNode(head, points[points.length - 1]));
235
+ return createLine(edge, points);
236
+ }
237
+ function createLine(edge, points) {
238
+ var line$1 = (line || svg.line)().x(function(d) {
239
+ return d.x;
240
+ }).y(function(d) {
241
+ return d.y;
242
+ });
243
+ (line$1.curve || line$1.interpolate)(edge.curve);
244
+ return line$1(points);
245
+ }
246
+ function getCoords(elem) {
247
+ var bbox = elem.getBBox();
248
+ var matrix = elem.ownerSVGElement.getScreenCTM().inverse().multiply(elem.getScreenCTM()).translate(bbox.width / 2, bbox.height / 2);
249
+ return { x: matrix.e, y: matrix.f };
250
+ }
251
+ function enter(svgPaths, g) {
252
+ var svgPathsEnter = svgPaths.enter().append("g").attr("class", "edgePath").style("opacity", 0);
253
+ svgPathsEnter.append("path").attr("class", "path").attr("d", function(e) {
254
+ var edge = g.edge(e);
255
+ var sourceElem = g.node(e.v).elem;
256
+ var points = range(edge.points.length).map(function() {
257
+ return getCoords(sourceElem);
258
+ });
259
+ return createLine(edge, points);
260
+ });
261
+ svgPathsEnter.append("defs");
262
+ return svgPathsEnter;
263
+ }
264
+ function exit(svgPaths, g) {
265
+ var svgPathExit = svgPaths.exit();
266
+ applyTransition(svgPathExit, g).style("opacity", 0).remove();
267
+ }
268
+ var createNodes = function(selection, g, shapes2) {
269
+ var simpleNodes = g.nodes().filter(function(v) {
270
+ return !isSubgraph(g, v);
271
+ });
272
+ var svgNodes = selection.selectAll("g.node").data(simpleNodes, function(v) {
273
+ return v;
274
+ }).classed("update", true);
275
+ svgNodes.exit().remove();
276
+ svgNodes.enter().append("g").attr("class", "node").style("opacity", 0);
277
+ svgNodes = selection.selectAll("g.node");
278
+ svgNodes.each(function(v) {
279
+ var node = g.node(v);
280
+ var thisGroup = select(this);
281
+ applyClass(
282
+ thisGroup,
283
+ node["class"],
284
+ (thisGroup.classed("update") ? "update " : "") + "node"
285
+ );
286
+ thisGroup.select("g.label").remove();
287
+ var labelGroup = thisGroup.append("g").attr("class", "label");
288
+ var labelDom = addLabel(labelGroup, node);
289
+ var shape = shapes2[node.shape];
290
+ var bbox = pick(labelDom.node().getBBox(), "width", "height");
291
+ node.elem = this;
292
+ if (node.id) {
293
+ thisGroup.attr("id", node.id);
294
+ }
295
+ if (node.labelId) {
296
+ labelGroup.attr("id", node.labelId);
297
+ }
298
+ if (has(node, "width")) {
299
+ bbox.width = node.width;
300
+ }
301
+ if (has(node, "height")) {
302
+ bbox.height = node.height;
303
+ }
304
+ bbox.width += node.paddingLeft + node.paddingRight;
305
+ bbox.height += node.paddingTop + node.paddingBottom;
306
+ labelGroup.attr(
307
+ "transform",
308
+ "translate(" + (node.paddingLeft - node.paddingRight) / 2 + "," + (node.paddingTop - node.paddingBottom) / 2 + ")"
309
+ );
310
+ var root = select(this);
311
+ root.select(".label-container").remove();
312
+ var shapeSvg = shape(root, bbox, node).classed("label-container", true);
313
+ applyStyle(shapeSvg, node.style);
314
+ var shapeBBox = shapeSvg.node().getBBox();
315
+ node.width = shapeBBox.width;
316
+ node.height = shapeBBox.height;
317
+ });
318
+ var exitSelection;
319
+ if (svgNodes.exit) {
320
+ exitSelection = svgNodes.exit();
321
+ } else {
322
+ exitSelection = svgNodes.selectAll(null);
323
+ }
324
+ applyTransition(exitSelection, g).style("opacity", 0).remove();
325
+ return svgNodes;
326
+ };
327
+ function setCreateNodes(value) {
328
+ createNodes = value;
329
+ }
330
+ function positionClusters(selection, g) {
331
+ var created = selection.filter(function() {
332
+ return !select(this).classed("update");
333
+ });
334
+ function translate(v) {
335
+ var node = g.node(v);
336
+ return "translate(" + node.x + "," + node.y + ")";
337
+ }
338
+ created.attr("transform", translate);
339
+ applyTransition(selection, g).style("opacity", 1).attr("transform", translate);
340
+ applyTransition(created.selectAll("rect"), g).attr("width", function(v) {
341
+ return g.node(v).width;
342
+ }).attr("height", function(v) {
343
+ return g.node(v).height;
344
+ }).attr("x", function(v) {
345
+ var node = g.node(v);
346
+ return -node.width / 2;
347
+ }).attr("y", function(v) {
348
+ var node = g.node(v);
349
+ return -node.height / 2;
350
+ });
351
+ }
352
+ function positionEdgeLabels(selection, g) {
353
+ var created = selection.filter(function() {
354
+ return !select(this).classed("update");
355
+ });
356
+ function translate(e) {
357
+ var edge = g.edge(e);
358
+ return has(edge, "x") ? "translate(" + edge.x + "," + edge.y + ")" : "";
359
+ }
360
+ created.attr("transform", translate);
361
+ applyTransition(selection, g).style("opacity", 1).attr("transform", translate);
362
+ }
363
+ function positionNodes(selection, g) {
364
+ var created = selection.filter(function() {
365
+ return !select(this).classed("update");
366
+ });
367
+ function translate(v) {
368
+ var node = g.node(v);
369
+ return "translate(" + node.x + "," + node.y + ")";
370
+ }
371
+ created.attr("transform", translate);
372
+ applyTransition(selection, g).style("opacity", 1).attr("transform", translate);
373
+ }
374
+ function intersectEllipse(node, rx, ry, point) {
375
+ var cx = node.x;
376
+ var cy = node.y;
377
+ var px = cx - point.x;
378
+ var py = cy - point.y;
379
+ var det = Math.sqrt(rx * rx * py * py + ry * ry * px * px);
380
+ var dx = Math.abs(rx * ry * px / det);
381
+ if (point.x < cx) {
382
+ dx = -dx;
383
+ }
384
+ var dy = Math.abs(rx * ry * py / det);
385
+ if (point.y < cy) {
386
+ dy = -dy;
387
+ }
388
+ return { x: cx + dx, y: cy + dy };
389
+ }
390
+ function intersectCircle(node, rx, point) {
391
+ return intersectEllipse(node, rx, rx, point);
392
+ }
393
+ function intersectLine(p1, p2, q1, q2) {
394
+ var a1, a2, b1, b2, c1, c2;
395
+ var r1, r2, r3, r4;
396
+ var denom, offset, num;
397
+ var x, y;
398
+ a1 = p2.y - p1.y;
399
+ b1 = p1.x - p2.x;
400
+ c1 = p2.x * p1.y - p1.x * p2.y;
401
+ r3 = a1 * q1.x + b1 * q1.y + c1;
402
+ r4 = a1 * q2.x + b1 * q2.y + c1;
403
+ if (r3 !== 0 && r4 !== 0 && sameSign(r3, r4)) {
404
+ return;
405
+ }
406
+ a2 = q2.y - q1.y;
407
+ b2 = q1.x - q2.x;
408
+ c2 = q2.x * q1.y - q1.x * q2.y;
409
+ r1 = a2 * p1.x + b2 * p1.y + c2;
410
+ r2 = a2 * p2.x + b2 * p2.y + c2;
411
+ if (r1 !== 0 && r2 !== 0 && sameSign(r1, r2)) {
412
+ return;
413
+ }
414
+ denom = a1 * b2 - a2 * b1;
415
+ if (denom === 0) {
416
+ return;
417
+ }
418
+ offset = Math.abs(denom / 2);
419
+ num = b1 * c2 - b2 * c1;
420
+ x = num < 0 ? (num - offset) / denom : (num + offset) / denom;
421
+ num = a2 * c1 - a1 * c2;
422
+ y = num < 0 ? (num - offset) / denom : (num + offset) / denom;
423
+ return { x, y };
424
+ }
425
+ function sameSign(r1, r2) {
426
+ return r1 * r2 > 0;
427
+ }
428
+ function intersectPolygon(node, polyPoints, point) {
429
+ var x1 = node.x;
430
+ var y1 = node.y;
431
+ var intersections = [];
432
+ var minX = Number.POSITIVE_INFINITY;
433
+ var minY = Number.POSITIVE_INFINITY;
434
+ polyPoints.forEach(function(entry) {
435
+ minX = Math.min(minX, entry.x);
436
+ minY = Math.min(minY, entry.y);
437
+ });
438
+ var left = x1 - node.width / 2 - minX;
439
+ var top = y1 - node.height / 2 - minY;
440
+ for (var i = 0; i < polyPoints.length; i++) {
441
+ var p1 = polyPoints[i];
442
+ var p2 = polyPoints[i < polyPoints.length - 1 ? i + 1 : 0];
443
+ var intersect = intersectLine(
444
+ node,
445
+ point,
446
+ { x: left + p1.x, y: top + p1.y },
447
+ { x: left + p2.x, y: top + p2.y }
448
+ );
449
+ if (intersect) {
450
+ intersections.push(intersect);
451
+ }
452
+ }
453
+ if (!intersections.length) {
454
+ console.log("NO INTERSECTION FOUND, RETURN NODE CENTER", node);
455
+ return node;
456
+ }
457
+ if (intersections.length > 1) {
458
+ intersections.sort(function(p, q) {
459
+ var pdx = p.x - point.x;
460
+ var pdy = p.y - point.y;
461
+ var distp = Math.sqrt(pdx * pdx + pdy * pdy);
462
+ var qdx = q.x - point.x;
463
+ var qdy = q.y - point.y;
464
+ var distq = Math.sqrt(qdx * qdx + qdy * qdy);
465
+ return distp < distq ? -1 : distp === distq ? 0 : 1;
466
+ });
467
+ }
468
+ return intersections[0];
469
+ }
470
+ function intersectRect(node, point) {
471
+ var x = node.x;
472
+ var y = node.y;
473
+ var dx = point.x - x;
474
+ var dy = point.y - y;
475
+ var w = node.width / 2;
476
+ var h = node.height / 2;
477
+ var sx, sy;
478
+ if (Math.abs(dy) * w > Math.abs(dx) * h) {
479
+ if (dy < 0) {
480
+ h = -h;
481
+ }
482
+ sx = dy === 0 ? 0 : h * dx / dy;
483
+ sy = h;
484
+ } else {
485
+ if (dx < 0) {
486
+ w = -w;
487
+ }
488
+ sx = w;
489
+ sy = dx === 0 ? 0 : w * dy / dx;
490
+ }
491
+ return { x: x + sx, y: y + sy };
492
+ }
493
+ var shapes = {
494
+ rect,
495
+ ellipse,
496
+ circle,
497
+ diamond
498
+ };
499
+ function setShapes(value) {
500
+ shapes = value;
501
+ }
502
+ function rect(parent, bbox, node) {
503
+ var shapeSvg = parent.insert("rect", ":first-child").attr("rx", node.rx).attr("ry", node.ry).attr("x", -bbox.width / 2).attr("y", -bbox.height / 2).attr("width", bbox.width).attr("height", bbox.height);
504
+ node.intersect = function(point) {
505
+ return intersectRect(node, point);
506
+ };
507
+ return shapeSvg;
508
+ }
509
+ function ellipse(parent, bbox, node) {
510
+ var rx = bbox.width / 2;
511
+ var ry = bbox.height / 2;
512
+ var shapeSvg = parent.insert("ellipse", ":first-child").attr("x", -bbox.width / 2).attr("y", -bbox.height / 2).attr("rx", rx).attr("ry", ry);
513
+ node.intersect = function(point) {
514
+ return intersectEllipse(node, rx, ry, point);
515
+ };
516
+ return shapeSvg;
517
+ }
518
+ function circle(parent, bbox, node) {
519
+ var r = Math.max(bbox.width, bbox.height) / 2;
520
+ var shapeSvg = parent.insert("circle", ":first-child").attr("x", -bbox.width / 2).attr("y", -bbox.height / 2).attr("r", r);
521
+ node.intersect = function(point) {
522
+ return intersectCircle(node, r, point);
523
+ };
524
+ return shapeSvg;
525
+ }
526
+ function diamond(parent, bbox, node) {
527
+ var w = bbox.width * Math.SQRT2 / 2;
528
+ var h = bbox.height * Math.SQRT2 / 2;
529
+ var points = [
530
+ { x: 0, y: -h },
531
+ { x: -w, y: 0 },
532
+ { x: 0, y: h },
533
+ { x: w, y: 0 }
534
+ ];
535
+ var shapeSvg = parent.insert("polygon", ":first-child").attr(
536
+ "points",
537
+ points.map(function(p) {
538
+ return p.x + "," + p.y;
539
+ }).join(" ")
540
+ );
541
+ node.intersect = function(p) {
542
+ return intersectPolygon(node, points, p);
543
+ };
544
+ return shapeSvg;
545
+ }
546
+ function render() {
547
+ var fn = function(svg2, g) {
548
+ preProcessGraph(g);
549
+ var outputGroup = createOrSelectGroup(svg2, "output");
550
+ var clustersGroup = createOrSelectGroup(outputGroup, "clusters");
551
+ var edgePathsGroup = createOrSelectGroup(outputGroup, "edgePaths");
552
+ var edgeLabels = createEdgeLabels(createOrSelectGroup(outputGroup, "edgeLabels"), g);
553
+ var nodes = createNodes(createOrSelectGroup(outputGroup, "nodes"), g, shapes);
554
+ layout(g);
555
+ positionNodes(nodes, g);
556
+ positionEdgeLabels(edgeLabels, g);
557
+ createEdgePaths(edgePathsGroup, g, arrows);
558
+ var clusters = createClusters(clustersGroup, g);
559
+ positionClusters(clusters, g);
560
+ postProcessGraph(g);
561
+ };
562
+ fn.createNodes = function(value) {
563
+ if (!arguments.length) return createNodes;
564
+ setCreateNodes(value);
565
+ return fn;
566
+ };
567
+ fn.createClusters = function(value) {
568
+ if (!arguments.length) return createClusters;
569
+ setCreateClusters(value);
570
+ return fn;
571
+ };
572
+ fn.createEdgeLabels = function(value) {
573
+ if (!arguments.length) return createEdgeLabels;
574
+ setCreateEdgeLabels(value);
575
+ return fn;
576
+ };
577
+ fn.createEdgePaths = function(value) {
578
+ if (!arguments.length) return createEdgePaths;
579
+ setCreateEdgePaths(value);
580
+ return fn;
581
+ };
582
+ fn.shapes = function(value) {
583
+ if (!arguments.length) return shapes;
584
+ setShapes(value);
585
+ return fn;
586
+ };
587
+ fn.arrows = function(value) {
588
+ if (!arguments.length) return arrows;
589
+ setArrows(value);
590
+ return fn;
591
+ };
592
+ return fn;
593
+ }
594
+ var NODE_DEFAULT_ATTRS = {
595
+ paddingLeft: 10,
596
+ paddingRight: 10,
597
+ paddingTop: 10,
598
+ paddingBottom: 10,
599
+ rx: 0,
600
+ ry: 0,
601
+ shape: "rect"
602
+ };
603
+ var EDGE_DEFAULT_ATTRS = {
604
+ arrowhead: "normal",
605
+ curve: curveLinear
606
+ };
607
+ function preProcessGraph(g) {
608
+ g.nodes().forEach(function(v) {
609
+ var node = g.node(v);
610
+ if (!has(node, "label") && !g.children(v).length) {
611
+ node.label = v;
612
+ }
613
+ if (has(node, "paddingX")) {
614
+ defaults(node, {
615
+ paddingLeft: node.paddingX,
616
+ paddingRight: node.paddingX
617
+ });
618
+ }
619
+ if (has(node, "paddingY")) {
620
+ defaults(node, {
621
+ paddingTop: node.paddingY,
622
+ paddingBottom: node.paddingY
623
+ });
624
+ }
625
+ if (has(node, "padding")) {
626
+ defaults(node, {
627
+ paddingLeft: node.padding,
628
+ paddingRight: node.padding,
629
+ paddingTop: node.padding,
630
+ paddingBottom: node.padding
631
+ });
632
+ }
633
+ defaults(node, NODE_DEFAULT_ATTRS);
634
+ forEach(["paddingLeft", "paddingRight", "paddingTop", "paddingBottom"], function(k) {
635
+ node[k] = Number(node[k]);
636
+ });
637
+ if (has(node, "width")) {
638
+ node._prevWidth = node.width;
639
+ }
640
+ if (has(node, "height")) {
641
+ node._prevHeight = node.height;
642
+ }
643
+ });
644
+ g.edges().forEach(function(e) {
645
+ var edge = g.edge(e);
646
+ if (!has(edge, "label")) {
647
+ edge.label = "";
648
+ }
649
+ defaults(edge, EDGE_DEFAULT_ATTRS);
650
+ });
651
+ }
652
+ function postProcessGraph(g) {
653
+ forEach(g.nodes(), function(v) {
654
+ var node = g.node(v);
655
+ if (has(node, "_prevWidth")) {
656
+ node.width = node._prevWidth;
657
+ } else {
658
+ delete node.width;
659
+ }
660
+ if (has(node, "_prevHeight")) {
661
+ node.height = node._prevHeight;
662
+ } else {
663
+ delete node.height;
664
+ }
665
+ delete node._prevWidth;
666
+ delete node._prevHeight;
667
+ });
668
+ }
669
+ function createOrSelectGroup(root, name) {
670
+ var selection = root.select("g." + name);
671
+ if (selection.empty()) {
672
+ selection = root.append("g").attr("class", name);
673
+ }
674
+ return selection;
675
+ }
676
+ function question(parent, bbox, node) {
677
+ const w = bbox.width;
678
+ const h = bbox.height;
679
+ const s = (w + h) * 0.9;
680
+ const points = [
681
+ { x: s / 2, y: 0 },
682
+ { x: s, y: -s / 2 },
683
+ { x: s / 2, y: -s },
684
+ { x: 0, y: -s / 2 }
685
+ ];
686
+ const shapeSvg = insertPolygonShape(parent, s, s, points);
687
+ node.intersect = function(point) {
688
+ return intersectPolygon(node, points, point);
689
+ };
690
+ return shapeSvg;
691
+ }
692
+ function hexagon(parent, bbox, node) {
693
+ const f = 4;
694
+ const h = bbox.height;
695
+ const m = h / f;
696
+ const w = bbox.width + 2 * m;
697
+ const points = [
698
+ { x: m, y: 0 },
699
+ { x: w - m, y: 0 },
700
+ { x: w, y: -h / 2 },
701
+ { x: w - m, y: -h },
702
+ { x: m, y: -h },
703
+ { x: 0, y: -h / 2 }
704
+ ];
705
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
706
+ node.intersect = function(point) {
707
+ return intersectPolygon(node, points, point);
708
+ };
709
+ return shapeSvg;
710
+ }
711
+ function rect_left_inv_arrow(parent, bbox, node) {
712
+ const w = bbox.width;
713
+ const h = bbox.height;
714
+ const points = [
715
+ { x: -h / 2, y: 0 },
716
+ { x: w, y: 0 },
717
+ { x: w, y: -h },
718
+ { x: -h / 2, y: -h },
719
+ { x: 0, y: -h / 2 }
720
+ ];
721
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
722
+ node.intersect = function(point) {
723
+ return intersectPolygon(node, points, point);
724
+ };
725
+ return shapeSvg;
726
+ }
727
+ function lean_right(parent, bbox, node) {
728
+ const w = bbox.width;
729
+ const h = bbox.height;
730
+ const points = [
731
+ { x: -2 * h / 6, y: 0 },
732
+ { x: w - h / 6, y: 0 },
733
+ { x: w + 2 * h / 6, y: -h },
734
+ { x: h / 6, y: -h }
735
+ ];
736
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
737
+ node.intersect = function(point) {
738
+ return intersectPolygon(node, points, point);
739
+ };
740
+ return shapeSvg;
741
+ }
742
+ function lean_left(parent, bbox, node) {
743
+ const w = bbox.width;
744
+ const h = bbox.height;
745
+ const points = [
746
+ { x: 2 * h / 6, y: 0 },
747
+ { x: w + h / 6, y: 0 },
748
+ { x: w - 2 * h / 6, y: -h },
749
+ { x: -h / 6, y: -h }
750
+ ];
751
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
752
+ node.intersect = function(point) {
753
+ return intersectPolygon(node, points, point);
754
+ };
755
+ return shapeSvg;
756
+ }
757
+ function trapezoid(parent, bbox, node) {
758
+ const w = bbox.width;
759
+ const h = bbox.height;
760
+ const points = [
761
+ { x: -2 * h / 6, y: 0 },
762
+ { x: w + 2 * h / 6, y: 0 },
763
+ { x: w - h / 6, y: -h },
764
+ { x: h / 6, y: -h }
765
+ ];
766
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
767
+ node.intersect = function(point) {
768
+ return intersectPolygon(node, points, point);
769
+ };
770
+ return shapeSvg;
771
+ }
772
+ function inv_trapezoid(parent, bbox, node) {
773
+ const w = bbox.width;
774
+ const h = bbox.height;
775
+ const points = [
776
+ { x: h / 6, y: 0 },
777
+ { x: w - h / 6, y: 0 },
778
+ { x: w + 2 * h / 6, y: -h },
779
+ { x: -2 * h / 6, y: -h }
780
+ ];
781
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
782
+ node.intersect = function(point) {
783
+ return intersectPolygon(node, points, point);
784
+ };
785
+ return shapeSvg;
786
+ }
787
+ function rect_right_inv_arrow(parent, bbox, node) {
788
+ const w = bbox.width;
789
+ const h = bbox.height;
790
+ const points = [
791
+ { x: 0, y: 0 },
792
+ { x: w + h / 2, y: 0 },
793
+ { x: w, y: -h / 2 },
794
+ { x: w + h / 2, y: -h },
795
+ { x: 0, y: -h }
796
+ ];
797
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
798
+ node.intersect = function(point) {
799
+ return intersectPolygon(node, points, point);
800
+ };
801
+ return shapeSvg;
802
+ }
803
+ function stadium(parent, bbox, node) {
804
+ const h = bbox.height;
805
+ const w = bbox.width + h / 4;
806
+ const shapeSvg = parent.insert("rect", ":first-child").attr("rx", h / 2).attr("ry", h / 2).attr("x", -w / 2).attr("y", -h / 2).attr("width", w).attr("height", h);
807
+ node.intersect = function(point) {
808
+ return intersectRect(node, point);
809
+ };
810
+ return shapeSvg;
811
+ }
812
+ function subroutine(parent, bbox, node) {
813
+ const w = bbox.width;
814
+ const h = bbox.height;
815
+ const points = [
816
+ { x: 0, y: 0 },
817
+ { x: w, y: 0 },
818
+ { x: w, y: -h },
819
+ { x: 0, y: -h },
820
+ { x: 0, y: 0 },
821
+ { x: -8, y: 0 },
822
+ { x: w + 8, y: 0 },
823
+ { x: w + 8, y: -h },
824
+ { x: -8, y: -h },
825
+ { x: -8, y: 0 }
826
+ ];
827
+ const shapeSvg = insertPolygonShape(parent, w, h, points);
828
+ node.intersect = function(point) {
829
+ return intersectPolygon(node, points, point);
830
+ };
831
+ return shapeSvg;
832
+ }
833
+ function cylinder(parent, bbox, node) {
834
+ const w = bbox.width;
835
+ const rx = w / 2;
836
+ const ry = rx / (2.5 + w / 50);
837
+ const h = bbox.height + ry;
838
+ const shape = "M 0," + ry + " a " + rx + "," + ry + " 0,0,0 " + w + " 0 a " + rx + "," + ry + " 0,0,0 " + -w + " 0 l 0," + h + " a " + rx + "," + ry + " 0,0,0 " + w + " 0 l 0," + -h;
839
+ const shapeSvg = parent.attr("label-offset-y", ry).insert("path", ":first-child").attr("d", shape).attr("transform", "translate(" + -w / 2 + "," + -(h / 2 + ry) + ")");
840
+ node.intersect = function(point) {
841
+ const pos = intersectRect(node, point);
842
+ const x = pos.x - node.x;
843
+ if (rx != 0 && (Math.abs(x) < node.width / 2 || Math.abs(x) == node.width / 2 && Math.abs(pos.y - node.y) > node.height / 2 - ry)) {
844
+ let y = ry * ry * (1 - x * x / (rx * rx));
845
+ if (y != 0) {
846
+ y = Math.sqrt(y);
847
+ }
848
+ y = ry - y;
849
+ if (point.y - node.y > 0) {
850
+ y = -y;
851
+ }
852
+ pos.y += y;
853
+ }
854
+ return pos;
855
+ };
856
+ return shapeSvg;
857
+ }
858
+ function addToRender(render2) {
859
+ render2.shapes().question = question;
860
+ render2.shapes().hexagon = hexagon;
861
+ render2.shapes().stadium = stadium;
862
+ render2.shapes().subroutine = subroutine;
863
+ render2.shapes().cylinder = cylinder;
864
+ render2.shapes().rect_left_inv_arrow = rect_left_inv_arrow;
865
+ render2.shapes().lean_right = lean_right;
866
+ render2.shapes().lean_left = lean_left;
867
+ render2.shapes().trapezoid = trapezoid;
868
+ render2.shapes().inv_trapezoid = inv_trapezoid;
869
+ render2.shapes().rect_right_inv_arrow = rect_right_inv_arrow;
870
+ }
871
+ function addToRenderV2(addShape) {
872
+ addShape({ question });
873
+ addShape({ hexagon });
874
+ addShape({ stadium });
875
+ addShape({ subroutine });
876
+ addShape({ cylinder });
877
+ addShape({ rect_left_inv_arrow });
878
+ addShape({ lean_right });
879
+ addShape({ lean_left });
880
+ addShape({ trapezoid });
881
+ addShape({ inv_trapezoid });
882
+ addShape({ rect_right_inv_arrow });
883
+ }
884
+ function insertPolygonShape(parent, w, h, points) {
885
+ return parent.insert("polygon", ":first-child").attr(
886
+ "points",
887
+ points.map(function(d) {
888
+ return d.x + "," + d.y;
889
+ }).join(" ")
890
+ ).attr("transform", "translate(" + -w / 2 + "," + h / 2 + ")");
891
+ }
892
+ const flowChartShapes = {
893
+ addToRender,
894
+ addToRenderV2
895
+ };
896
+ const conf = {};
897
+ const setConf = function(cnf) {
898
+ const keys = Object.keys(cnf);
899
+ for (const key of keys) {
900
+ conf[key] = cnf[key];
901
+ }
902
+ };
903
+ const addVertices = async function(vert, g, svgId, root, _doc, diagObj) {
904
+ const svg2 = !root ? select(`[id="${svgId}"]`) : root.select(`[id="${svgId}"]`);
905
+ const doc = !_doc ? document : _doc;
906
+ const keys = Object.keys(vert);
907
+ for (const id of keys) {
908
+ const vertex = vert[id];
909
+ let classStr = "default";
910
+ if (vertex.classes.length > 0) {
911
+ classStr = vertex.classes.join(" ");
912
+ }
913
+ const styles = getStylesFromArray(vertex.styles);
914
+ let vertexText = vertex.text !== void 0 ? vertex.text : vertex.id;
915
+ let vertexNode;
916
+ if (evaluate(getConfig().flowchart.htmlLabels)) {
917
+ const node = {
918
+ label: await renderKatex(
919
+ vertexText.replace(
920
+ /fa[blrs]?:fa-[\w-]+/g,
921
+ // cspell:disable-line
922
+ (s) => `<i class='${s.replace(":", " ")}'></i>`
923
+ ),
924
+ getConfig()
925
+ )
926
+ };
927
+ vertexNode = addHtmlLabel(svg2, node).node();
928
+ vertexNode.parentNode.removeChild(vertexNode);
929
+ } else {
930
+ const svgLabel = doc.createElementNS("http://www.w3.org/2000/svg", "text");
931
+ svgLabel.setAttribute("style", styles.labelStyle.replace("color:", "fill:"));
932
+ const rows = vertexText.split(common$1.lineBreakRegex);
933
+ for (const row of rows) {
934
+ const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
935
+ tspan.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
936
+ tspan.setAttribute("dy", "1em");
937
+ tspan.setAttribute("x", "1");
938
+ tspan.textContent = row;
939
+ svgLabel.appendChild(tspan);
940
+ }
941
+ vertexNode = svgLabel;
942
+ }
943
+ let radius = 0;
944
+ let _shape = "";
945
+ switch (vertex.type) {
946
+ case "round":
947
+ radius = 5;
948
+ _shape = "rect";
949
+ break;
950
+ case "square":
951
+ _shape = "rect";
952
+ break;
953
+ case "diamond":
954
+ _shape = "question";
955
+ break;
956
+ case "hexagon":
957
+ _shape = "hexagon";
958
+ break;
959
+ case "odd":
960
+ _shape = "rect_left_inv_arrow";
961
+ break;
962
+ case "lean_right":
963
+ _shape = "lean_right";
964
+ break;
965
+ case "lean_left":
966
+ _shape = "lean_left";
967
+ break;
968
+ case "trapezoid":
969
+ _shape = "trapezoid";
970
+ break;
971
+ case "inv_trapezoid":
972
+ _shape = "inv_trapezoid";
973
+ break;
974
+ case "odd_right":
975
+ _shape = "rect_left_inv_arrow";
976
+ break;
977
+ case "circle":
978
+ _shape = "circle";
979
+ break;
980
+ case "ellipse":
981
+ _shape = "ellipse";
982
+ break;
983
+ case "stadium":
984
+ _shape = "stadium";
985
+ break;
986
+ case "subroutine":
987
+ _shape = "subroutine";
988
+ break;
989
+ case "cylinder":
990
+ _shape = "cylinder";
991
+ break;
992
+ case "group":
993
+ _shape = "rect";
994
+ break;
995
+ default:
996
+ _shape = "rect";
997
+ }
998
+ log$1.warn("Adding node", vertex.id, vertex.domId);
999
+ g.setNode(diagObj.db.lookUpDomId(vertex.id), {
1000
+ labelType: "svg",
1001
+ labelStyle: styles.labelStyle,
1002
+ shape: _shape,
1003
+ label: vertexNode,
1004
+ rx: radius,
1005
+ ry: radius,
1006
+ class: classStr,
1007
+ style: styles.style,
1008
+ id: diagObj.db.lookUpDomId(vertex.id)
1009
+ });
1010
+ }
1011
+ };
1012
+ const addEdges = async function(edges, g, diagObj) {
1013
+ let cnt = 0;
1014
+ let defaultStyle;
1015
+ let defaultLabelStyle;
1016
+ if (edges.defaultStyle !== void 0) {
1017
+ const defaultStyles = getStylesFromArray(edges.defaultStyle);
1018
+ defaultStyle = defaultStyles.style;
1019
+ defaultLabelStyle = defaultStyles.labelStyle;
1020
+ }
1021
+ for (const edge of edges) {
1022
+ cnt++;
1023
+ const linkId = "L-" + edge.start + "-" + edge.end;
1024
+ const linkNameStart = "LS-" + edge.start;
1025
+ const linkNameEnd = "LE-" + edge.end;
1026
+ const edgeData = {};
1027
+ if (edge.type === "arrow_open") {
1028
+ edgeData.arrowhead = "none";
1029
+ } else {
1030
+ edgeData.arrowhead = "normal";
1031
+ }
1032
+ let style = "";
1033
+ let labelStyle = "";
1034
+ if (edge.style !== void 0) {
1035
+ const styles = getStylesFromArray(edge.style);
1036
+ style = styles.style;
1037
+ labelStyle = styles.labelStyle;
1038
+ } else {
1039
+ switch (edge.stroke) {
1040
+ case "normal":
1041
+ style = "fill:none";
1042
+ if (defaultStyle !== void 0) {
1043
+ style = defaultStyle;
1044
+ }
1045
+ if (defaultLabelStyle !== void 0) {
1046
+ labelStyle = defaultLabelStyle;
1047
+ }
1048
+ break;
1049
+ case "dotted":
1050
+ style = "fill:none;stroke-width:2px;stroke-dasharray:3;";
1051
+ break;
1052
+ case "thick":
1053
+ style = " stroke-width: 3.5px;fill:none";
1054
+ break;
1055
+ }
1056
+ }
1057
+ edgeData.style = style;
1058
+ edgeData.labelStyle = labelStyle;
1059
+ if (edge.interpolate !== void 0) {
1060
+ edgeData.curve = interpolateToCurve(edge.interpolate, curveLinear);
1061
+ } else if (edges.defaultInterpolate !== void 0) {
1062
+ edgeData.curve = interpolateToCurve(edges.defaultInterpolate, curveLinear);
1063
+ } else {
1064
+ edgeData.curve = interpolateToCurve(conf.curve, curveLinear);
1065
+ }
1066
+ if (edge.text === void 0) {
1067
+ if (edge.style !== void 0) {
1068
+ edgeData.arrowheadStyle = "fill: #333";
1069
+ }
1070
+ } else {
1071
+ edgeData.arrowheadStyle = "fill: #333";
1072
+ edgeData.labelpos = "c";
1073
+ if (evaluate(getConfig().flowchart.htmlLabels)) {
1074
+ edgeData.labelType = "html";
1075
+ edgeData.label = `<span id="L-${linkId}" class="edgeLabel L-${linkNameStart}' L-${linkNameEnd}" style="${edgeData.labelStyle}">${await renderKatex(
1076
+ edge.text.replace(
1077
+ /fa[blrs]?:fa-[\w-]+/g,
1078
+ // cspell:disable-line
1079
+ (s) => `<i class='${s.replace(":", " ")}'></i>`
1080
+ ),
1081
+ getConfig()
1082
+ )}</span>`;
1083
+ } else {
1084
+ edgeData.labelType = "text";
1085
+ edgeData.label = edge.text.replace(common$1.lineBreakRegex, "\n");
1086
+ if (edge.style === void 0) {
1087
+ edgeData.style = edgeData.style || "stroke: #333; stroke-width: 1.5px;fill:none";
1088
+ }
1089
+ edgeData.labelStyle = edgeData.labelStyle.replace("color:", "fill:");
1090
+ }
1091
+ }
1092
+ edgeData.id = linkId;
1093
+ edgeData.class = linkNameStart + " " + linkNameEnd;
1094
+ edgeData.minlen = edge.length || 1;
1095
+ g.setEdge(diagObj.db.lookUpDomId(edge.start), diagObj.db.lookUpDomId(edge.end), edgeData, cnt);
1096
+ }
1097
+ };
1098
+ const getClasses = function(text2, diagObj) {
1099
+ log$1.info("Extracting classes");
1100
+ return diagObj.db.getClasses();
1101
+ };
1102
+ const draw = async function(text2, id, _version, diagObj) {
1103
+ log$1.info("Drawing flowchart");
1104
+ const { securityLevel, flowchart: conf2 } = getConfig();
1105
+ let sandboxElement;
1106
+ if (securityLevel === "sandbox") {
1107
+ sandboxElement = select("#i" + id);
1108
+ }
1109
+ const root = securityLevel === "sandbox" ? select(sandboxElement.nodes()[0].contentDocument.body) : select("body");
1110
+ const doc = securityLevel === "sandbox" ? sandboxElement.nodes()[0].contentDocument : document;
1111
+ let dir = diagObj.db.getDirection();
1112
+ if (dir === void 0) {
1113
+ dir = "TD";
1114
+ }
1115
+ const nodeSpacing = conf2.nodeSpacing || 50;
1116
+ const rankSpacing = conf2.rankSpacing || 50;
1117
+ const g = new Graph({
1118
+ multigraph: true,
1119
+ compound: true
1120
+ }).setGraph({
1121
+ rankdir: dir,
1122
+ nodesep: nodeSpacing,
1123
+ ranksep: rankSpacing,
1124
+ marginx: 8,
1125
+ marginy: 8
1126
+ }).setDefaultEdgeLabel(function() {
1127
+ return {};
1128
+ });
1129
+ let subG;
1130
+ const subGraphs = diagObj.db.getSubGraphs();
1131
+ for (let i2 = subGraphs.length - 1; i2 >= 0; i2--) {
1132
+ subG = subGraphs[i2];
1133
+ diagObj.db.addVertex(subG.id, subG.title, "group", void 0, subG.classes);
1134
+ }
1135
+ const vert = diagObj.db.getVertices();
1136
+ log$1.warn("Get vertices", vert);
1137
+ const edges = diagObj.db.getEdges();
1138
+ let i = 0;
1139
+ for (i = subGraphs.length - 1; i >= 0; i--) {
1140
+ subG = subGraphs[i];
1141
+ selectAll("cluster").append("text");
1142
+ for (let j = 0; j < subG.nodes.length; j++) {
1143
+ log$1.warn(
1144
+ "Setting subgraph",
1145
+ subG.nodes[j],
1146
+ diagObj.db.lookUpDomId(subG.nodes[j]),
1147
+ diagObj.db.lookUpDomId(subG.id)
1148
+ );
1149
+ g.setParent(diagObj.db.lookUpDomId(subG.nodes[j]), diagObj.db.lookUpDomId(subG.id));
1150
+ }
1151
+ }
1152
+ await addVertices(vert, g, id, root, doc, diagObj);
1153
+ await addEdges(edges, g, diagObj);
1154
+ const render$1 = new render();
1155
+ flowChartShapes.addToRender(render$1);
1156
+ render$1.arrows().none = function normal2(parent, id2, edge, type) {
1157
+ const marker = parent.append("marker").attr("id", id2).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto");
1158
+ const path = marker.append("path").attr("d", "M 0 0 L 0 0 L 0 0 z");
1159
+ applyStyle(path, edge[type + "Style"]);
1160
+ };
1161
+ render$1.arrows().normal = function normal2(parent, id2) {
1162
+ const marker = parent.append("marker").attr("id", id2).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto");
1163
+ marker.append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("class", "arrowheadPath").style("stroke-width", 1).style("stroke-dasharray", "1,0");
1164
+ };
1165
+ const svg2 = root.select(`[id="${id}"]`);
1166
+ const element = root.select("#" + id + " g");
1167
+ render$1(element, g);
1168
+ element.selectAll("g.node").attr("title", function() {
1169
+ return diagObj.db.getTooltip(this.id);
1170
+ });
1171
+ diagObj.db.indexNodes("subGraph" + i);
1172
+ for (i = 0; i < subGraphs.length; i++) {
1173
+ subG = subGraphs[i];
1174
+ if (subG.title !== "undefined") {
1175
+ const clusterRects = doc.querySelectorAll(
1176
+ "#" + id + ' [id="' + diagObj.db.lookUpDomId(subG.id) + '"] rect'
1177
+ );
1178
+ const clusterEl = doc.querySelectorAll(
1179
+ "#" + id + ' [id="' + diagObj.db.lookUpDomId(subG.id) + '"]'
1180
+ );
1181
+ const xPos = clusterRects[0].x.baseVal.value;
1182
+ const yPos = clusterRects[0].y.baseVal.value;
1183
+ const _width = clusterRects[0].width.baseVal.value;
1184
+ const cluster = select(clusterEl[0]);
1185
+ const te = cluster.select(".label");
1186
+ te.attr("transform", `translate(${xPos + _width / 2}, ${yPos + 14})`);
1187
+ te.attr("id", id + "Text");
1188
+ for (let j = 0; j < subG.classes.length; j++) {
1189
+ clusterEl[0].classList.add(subG.classes[j]);
1190
+ }
1191
+ }
1192
+ }
1193
+ if (!conf2.htmlLabels) {
1194
+ const labels = doc.querySelectorAll('[id="' + id + '"] .edgeLabel .label');
1195
+ for (const label of labels) {
1196
+ const dim = label.getBBox();
1197
+ const rect2 = doc.createElementNS("http://www.w3.org/2000/svg", "rect");
1198
+ rect2.setAttribute("rx", 0);
1199
+ rect2.setAttribute("ry", 0);
1200
+ rect2.setAttribute("width", dim.width);
1201
+ rect2.setAttribute("height", dim.height);
1202
+ label.insertBefore(rect2, label.firstChild);
1203
+ }
1204
+ }
1205
+ setupGraphViewbox$1(g, svg2, conf2.diagramPadding, conf2.useMaxWidth);
1206
+ const keys = Object.keys(vert);
1207
+ keys.forEach(function(key) {
1208
+ const vertex = vert[key];
1209
+ if (vertex.link) {
1210
+ const node = root.select("#" + id + ' [id="' + diagObj.db.lookUpDomId(key) + '"]');
1211
+ if (node) {
1212
+ const link = doc.createElementNS("http://www.w3.org/2000/svg", "a");
1213
+ link.setAttributeNS("http://www.w3.org/2000/svg", "class", vertex.classes.join(" "));
1214
+ link.setAttributeNS("http://www.w3.org/2000/svg", "href", vertex.link);
1215
+ link.setAttributeNS("http://www.w3.org/2000/svg", "rel", "noopener");
1216
+ if (securityLevel === "sandbox") {
1217
+ link.setAttributeNS("http://www.w3.org/2000/svg", "target", "_top");
1218
+ } else if (vertex.linkTarget) {
1219
+ link.setAttributeNS("http://www.w3.org/2000/svg", "target", vertex.linkTarget);
1220
+ }
1221
+ const linkNode = node.insert(function() {
1222
+ return link;
1223
+ }, ":first-child");
1224
+ const shape = node.select(".label-container");
1225
+ if (shape) {
1226
+ linkNode.append(function() {
1227
+ return shape.node();
1228
+ });
1229
+ }
1230
+ const label = node.select(".label");
1231
+ if (label) {
1232
+ linkNode.append(function() {
1233
+ return label.node();
1234
+ });
1235
+ }
1236
+ }
1237
+ }
1238
+ });
1239
+ };
1240
+ const flowRenderer = {
1241
+ setConf,
1242
+ addVertices,
1243
+ addEdges,
1244
+ getClasses,
1245
+ draw
1246
+ };
1247
+ const diagram = {
1248
+ parser: parser$1,
1249
+ db: flowDb,
1250
+ renderer: flowRendererV2,
1251
+ styles: flowStyles,
1252
+ init: (cnf) => {
1253
+ if (!cnf.flowchart) {
1254
+ cnf.flowchart = {};
1255
+ }
1256
+ cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
1257
+ flowRenderer.setConf(cnf.flowchart);
1258
+ flowDb.clear();
1259
+ flowDb.setGen("gen-1");
1260
+ }
1261
+ };
1262
+ export {
1263
+ diagram
1264
+ };