1 | import { p as parser, d as db, s as styles } from "./styles-36a1a2e8.js";
|
2 | import { l as log, c as getConfig, j as d3select, A as utils, t as setupGraphViewbox, o as getStylesFromArray, q as interpolateToCurve, n as curveLinear, f as common } from "./mermaid-dcacb631.js";
|
3 | import { G as Graph } from "./graph-fe24fab6.js";
|
4 | import { r as render } from "./index-fc479858.js";
|
5 | import "./layout-163b9689.js";
|
6 | import "./clone-9ea6bfeb.js";
|
7 | import "./edges-ce5cfb7c.js";
|
8 | import "./createText-b70fe78a.js";
|
9 | import "./line-87f517ef.js";
|
10 | import "./array-b7dcf730.js";
|
11 | import "./path-39bad7e2.js";
|
12 | const sanitizeText = (txt) => common.sanitizeText(txt, getConfig());
|
13 | let conf = {
|
14 | dividerMargin: 10,
|
15 | padding: 5,
|
16 | textHeight: 10,
|
17 | curve: void 0
|
18 | };
|
19 | const addNamespaces = function(namespaces, g, _id, diagObj) {
|
20 | const keys = Object.keys(namespaces);
|
21 | log.info("keys:", keys);
|
22 | log.info(namespaces);
|
23 | keys.forEach(function(id) {
|
24 | var _a, _b;
|
25 | const vertex = namespaces[id];
|
26 | const shape = "rect";
|
27 | const node = {
|
28 | shape,
|
29 | id: vertex.id,
|
30 | domId: vertex.domId,
|
31 | labelText: sanitizeText(vertex.id),
|
32 | labelStyle: "",
|
33 | style: "fill: none; stroke: black",
|
34 |
|
35 | padding: ((_a = getConfig().flowchart) == null ? void 0 : _a.padding) ?? ((_b = getConfig().class) == null ? void 0 : _b.padding)
|
36 | };
|
37 | g.setNode(vertex.id, node);
|
38 | addClasses(vertex.classes, g, _id, diagObj, vertex.id);
|
39 | log.info("setNode", node);
|
40 | });
|
41 | };
|
42 | const addClasses = function(classes, g, _id, diagObj, parent) {
|
43 | const keys = Object.keys(classes);
|
44 | log.info("keys:", keys);
|
45 | log.info(classes);
|
46 | keys.filter((id) => classes[id].parent == parent).forEach(function(id) {
|
47 | var _a, _b;
|
48 | const vertex = classes[id];
|
49 | const cssClassStr = vertex.cssClasses.join(" ");
|
50 | const styles2 = getStylesFromArray(vertex.styles);
|
51 | const vertexText = vertex.label ?? vertex.id;
|
52 | const radius = 0;
|
53 | const shape = "class_box";
|
54 | const node = {
|
55 | labelStyle: styles2.labelStyle,
|
56 | shape,
|
57 | labelText: sanitizeText(vertexText),
|
58 | classData: vertex,
|
59 | rx: radius,
|
60 | ry: radius,
|
61 | class: cssClassStr,
|
62 | style: styles2.style,
|
63 | id: vertex.id,
|
64 | domId: vertex.domId,
|
65 | tooltip: diagObj.db.getTooltip(vertex.id, parent) || "",
|
66 | haveCallback: vertex.haveCallback,
|
67 | link: vertex.link,
|
68 | width: vertex.type === "group" ? 500 : void 0,
|
69 | type: vertex.type,
|
70 |
|
71 | padding: ((_a = getConfig().flowchart) == null ? void 0 : _a.padding) ?? ((_b = getConfig().class) == null ? void 0 : _b.padding)
|
72 | };
|
73 | g.setNode(vertex.id, node);
|
74 | if (parent) {
|
75 | g.setParent(vertex.id, parent);
|
76 | }
|
77 | log.info("setNode", node);
|
78 | });
|
79 | };
|
80 | const addNotes = function(notes, g, startEdgeId, classes) {
|
81 | log.info(notes);
|
82 | notes.forEach(function(note, i) {
|
83 | var _a, _b;
|
84 | const vertex = note;
|
85 | const cssNoteStr = "";
|
86 | const styles2 = { labelStyle: "", style: "" };
|
87 | const vertexText = vertex.text;
|
88 | const radius = 0;
|
89 | const shape = "note";
|
90 | const node = {
|
91 | labelStyle: styles2.labelStyle,
|
92 | shape,
|
93 | labelText: sanitizeText(vertexText),
|
94 | noteData: vertex,
|
95 | rx: radius,
|
96 | ry: radius,
|
97 | class: cssNoteStr,
|
98 | style: styles2.style,
|
99 | id: vertex.id,
|
100 | domId: vertex.id,
|
101 | tooltip: "",
|
102 | type: "note",
|
103 |
|
104 | padding: ((_a = getConfig().flowchart) == null ? void 0 : _a.padding) ?? ((_b = getConfig().class) == null ? void 0 : _b.padding)
|
105 | };
|
106 | g.setNode(vertex.id, node);
|
107 | log.info("setNode", node);
|
108 | if (!vertex.class || !(vertex.class in classes)) {
|
109 | return;
|
110 | }
|
111 | const edgeId = startEdgeId + i;
|
112 | const edgeData = {
|
113 | id: `edgeNote${edgeId}`,
|
114 |
|
115 | classes: "relation",
|
116 | pattern: "dotted",
|
117 |
|
118 | arrowhead: "none",
|
119 |
|
120 | startLabelRight: "",
|
121 | endLabelLeft: "",
|
122 |
|
123 | arrowTypeStart: "none",
|
124 | arrowTypeEnd: "none",
|
125 | style: "fill:none",
|
126 | labelStyle: "",
|
127 | curve: interpolateToCurve(conf.curve, curveLinear)
|
128 | };
|
129 | g.setEdge(vertex.id, vertex.class, edgeData, edgeId);
|
130 | });
|
131 | };
|
132 | const addRelations = function(relations, g) {
|
133 | const conf2 = getConfig().flowchart;
|
134 | let cnt = 0;
|
135 | relations.forEach(function(edge) {
|
136 | var _a;
|
137 | cnt++;
|
138 | const edgeData = {
|
139 |
|
140 | classes: "relation",
|
141 | pattern: edge.relation.lineType == 1 ? "dashed" : "solid",
|
142 | id: `id_${edge.id1}_${edge.id2}_${cnt}`,
|
143 |
|
144 | arrowhead: edge.type === "arrow_open" ? "none" : "normal",
|
145 |
|
146 | startLabelRight: edge.relationTitle1 === "none" ? "" : edge.relationTitle1,
|
147 | endLabelLeft: edge.relationTitle2 === "none" ? "" : edge.relationTitle2,
|
148 |
|
149 | arrowTypeStart: getArrowMarker(edge.relation.type1),
|
150 | arrowTypeEnd: getArrowMarker(edge.relation.type2),
|
151 | style: "fill:none",
|
152 | labelStyle: "",
|
153 | curve: interpolateToCurve(conf2 == null ? void 0 : conf2.curve, curveLinear)
|
154 | };
|
155 | log.info(edgeData, edge);
|
156 | if (edge.style !== void 0) {
|
157 | const styles2 = getStylesFromArray(edge.style);
|
158 | edgeData.style = styles2.style;
|
159 | edgeData.labelStyle = styles2.labelStyle;
|
160 | }
|
161 | edge.text = edge.title;
|
162 | if (edge.text === void 0) {
|
163 | if (edge.style !== void 0) {
|
164 | edgeData.arrowheadStyle = "fill: #333";
|
165 | }
|
166 | } else {
|
167 | edgeData.arrowheadStyle = "fill: #333";
|
168 | edgeData.labelpos = "c";
|
169 | if (((_a = getConfig().flowchart) == null ? void 0 : _a.htmlLabels) ?? getConfig().htmlLabels) {
|
170 | edgeData.labelType = "html";
|
171 | edgeData.label = '<span class="edgeLabel">' + edge.text + "</span>";
|
172 | } else {
|
173 | edgeData.labelType = "text";
|
174 | edgeData.label = edge.text.replace(common.lineBreakRegex, "\n");
|
175 | if (edge.style === void 0) {
|
176 | edgeData.style = edgeData.style || "stroke: #333; stroke-width: 1.5px;fill:none";
|
177 | }
|
178 | edgeData.labelStyle = edgeData.labelStyle.replace("color:", "fill:");
|
179 | }
|
180 | }
|
181 | g.setEdge(edge.id1, edge.id2, edgeData, cnt);
|
182 | });
|
183 | };
|
184 | const setConf = function(cnf) {
|
185 | conf = {
|
186 | ...conf,
|
187 | ...cnf
|
188 | };
|
189 | };
|
190 | const draw = async function(text, id, _version, diagObj) {
|
191 | log.info("Drawing class - ", id);
|
192 | const conf2 = getConfig().flowchart ?? getConfig().class;
|
193 | const securityLevel = getConfig().securityLevel;
|
194 | log.info("config:", conf2);
|
195 | const nodeSpacing = (conf2 == null ? void 0 : conf2.nodeSpacing) ?? 50;
|
196 | const rankSpacing = (conf2 == null ? void 0 : conf2.rankSpacing) ?? 50;
|
197 | const g = new Graph({
|
198 | multigraph: true,
|
199 | compound: true
|
200 | }).setGraph({
|
201 | rankdir: diagObj.db.getDirection(),
|
202 | nodesep: nodeSpacing,
|
203 | ranksep: rankSpacing,
|
204 | marginx: 8,
|
205 | marginy: 8
|
206 | }).setDefaultEdgeLabel(function() {
|
207 | return {};
|
208 | });
|
209 | const namespaces = diagObj.db.getNamespaces();
|
210 | const classes = diagObj.db.getClasses();
|
211 | const relations = diagObj.db.getRelations();
|
212 | const notes = diagObj.db.getNotes();
|
213 | log.info(relations);
|
214 | addNamespaces(namespaces, g, id, diagObj);
|
215 | addClasses(classes, g, id, diagObj);
|
216 | addRelations(relations, g);
|
217 | addNotes(notes, g, relations.length + 1, classes);
|
218 | let sandboxElement;
|
219 | if (securityLevel === "sandbox") {
|
220 | sandboxElement = d3select("#i" + id);
|
221 | }
|
222 | const root = securityLevel === "sandbox" ? d3select(sandboxElement.nodes()[0].contentDocument.body) : d3select("body");
|
223 | const svg = root.select(`[id="${id}"]`);
|
224 | const element = root.select("#" + id + " g");
|
225 | await render(
|
226 | element,
|
227 | g,
|
228 | ["aggregation", "extension", "composition", "dependency", "lollipop"],
|
229 | "classDiagram",
|
230 | id
|
231 | );
|
232 | utils.insertTitle(svg, "classTitleText", (conf2 == null ? void 0 : conf2.titleTopMargin) ?? 5, diagObj.db.getDiagramTitle());
|
233 | setupGraphViewbox(g, svg, conf2 == null ? void 0 : conf2.diagramPadding, conf2 == null ? void 0 : conf2.useMaxWidth);
|
234 | if (!(conf2 == null ? void 0 : conf2.htmlLabels)) {
|
235 | const doc = securityLevel === "sandbox" ? sandboxElement.nodes()[0].contentDocument : document;
|
236 | const labels = doc.querySelectorAll('[id="' + id + '"] .edgeLabel .label');
|
237 | for (const label of labels) {
|
238 | const dim = label.getBBox();
|
239 | const rect = doc.createElementNS("http://www.w3.org/2000/svg", "rect");
|
240 | rect.setAttribute("rx", 0);
|
241 | rect.setAttribute("ry", 0);
|
242 | rect.setAttribute("width", dim.width);
|
243 | rect.setAttribute("height", dim.height);
|
244 | label.insertBefore(rect, label.firstChild);
|
245 | }
|
246 | }
|
247 | };
|
248 | function getArrowMarker(type) {
|
249 | let marker;
|
250 | switch (type) {
|
251 | case 0:
|
252 | marker = "aggregation";
|
253 | break;
|
254 | case 1:
|
255 | marker = "extension";
|
256 | break;
|
257 | case 2:
|
258 | marker = "composition";
|
259 | break;
|
260 | case 3:
|
261 | marker = "dependency";
|
262 | break;
|
263 | case 4:
|
264 | marker = "lollipop";
|
265 | break;
|
266 | default:
|
267 | marker = "none";
|
268 | }
|
269 | return marker;
|
270 | }
|
271 | const renderer = {
|
272 | setConf,
|
273 | draw
|
274 | };
|
275 | const diagram = {
|
276 | parser,
|
277 | db,
|
278 | renderer,
|
279 | styles,
|
280 | init: (cnf) => {
|
281 | if (!cnf.class) {
|
282 | cnf.class = {};
|
283 | }
|
284 | cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
285 | db.clear();
|
286 | }
|
287 | };
|
288 | export {
|
289 | diagram
|
290 | };
|