UNPKG

50.2 kBJavaScriptView Raw
1import { c as getConfig, s as setAccTitle, g as getAccTitle, b as setAccDescription, a as getAccDescription, r as setDiagramTitle, t as getDiagramTitle, m as mermaidAPI, l as log, v as clear$1, u as utils, i as configureSvgSize, x as parseGenericTypes } from "./mermaid-a953d906.js";
2import * as graphlib from "dagre-d3-es/src/graphlib/index.js";
3import { select, line, curveBasis } from "d3";
4import { layout } from "dagre-d3-es/src/dagre/index.js";
5import { v5 } from "uuid";
6import "ts-dedent";
7import "dayjs/esm/index.js";
8import "@braintree/sanitize-url";
9import "dompurify";
10import "khroma";
11import "lodash-es/memoize.js";
12import "stylis";
13import "lodash-es/isEmpty.js";
14var parser = function() {
15 var o = function(k, v, o2, l) {
16 for (o2 = o2 || {}, l = k.length; l--; o2[k[l]] = v)
17 ;
18 return o2;
19 }, $V0 = [1, 2], $V1 = [1, 5], $V2 = [6, 9, 11, 23, 25, 27, 29, 30, 31, 52], $V3 = [1, 17], $V4 = [1, 18], $V5 = [1, 19], $V6 = [1, 20], $V7 = [1, 21], $V8 = [1, 22], $V9 = [1, 25], $Va = [1, 30], $Vb = [1, 31], $Vc = [1, 32], $Vd = [1, 33], $Ve = [1, 34], $Vf = [6, 9, 11, 15, 20, 23, 25, 27, 29, 30, 31, 44, 45, 46, 47, 48, 52], $Vg = [1, 46], $Vh = [30, 31, 49, 50], $Vi = [4, 6, 9, 11, 23, 25, 27, 29, 30, 31, 52], $Vj = [44, 45, 46, 47, 48], $Vk = [22, 37], $Vl = [1, 66], $Vm = [1, 65], $Vn = [22, 37, 39, 41];
20 var parser2 = {
21 trace: function trace() {
22 },
23 yy: {},
24 symbols_: { "error": 2, "start": 3, "ER_DIAGRAM": 4, "document": 5, "EOF": 6, "directive": 7, "line": 8, "SPACE": 9, "statement": 10, "NEWLINE": 11, "openDirective": 12, "typeDirective": 13, "closeDirective": 14, ":": 15, "argDirective": 16, "entityName": 17, "relSpec": 18, "role": 19, "BLOCK_START": 20, "attributes": 21, "BLOCK_STOP": 22, "title": 23, "title_value": 24, "acc_title": 25, "acc_title_value": 26, "acc_descr": 27, "acc_descr_value": 28, "acc_descr_multiline_value": 29, "ALPHANUM": 30, "ENTITY_NAME": 31, "attribute": 32, "attributeType": 33, "attributeName": 34, "attributeKeyTypeList": 35, "attributeComment": 36, "ATTRIBUTE_WORD": 37, "attributeKeyType": 38, "COMMA": 39, "ATTRIBUTE_KEY": 40, "COMMENT": 41, "cardinality": 42, "relType": 43, "ZERO_OR_ONE": 44, "ZERO_OR_MORE": 45, "ONE_OR_MORE": 46, "ONLY_ONE": 47, "MD_PARENT": 48, "NON_IDENTIFYING": 49, "IDENTIFYING": 50, "WORD": 51, "open_directive": 52, "type_directive": 53, "arg_directive": 54, "close_directive": 55, "$accept": 0, "$end": 1 },
25 terminals_: { 2: "error", 4: "ER_DIAGRAM", 6: "EOF", 9: "SPACE", 11: "NEWLINE", 15: ":", 20: "BLOCK_START", 22: "BLOCK_STOP", 23: "title", 24: "title_value", 25: "acc_title", 26: "acc_title_value", 27: "acc_descr", 28: "acc_descr_value", 29: "acc_descr_multiline_value", 30: "ALPHANUM", 31: "ENTITY_NAME", 37: "ATTRIBUTE_WORD", 39: "COMMA", 40: "ATTRIBUTE_KEY", 41: "COMMENT", 44: "ZERO_OR_ONE", 45: "ZERO_OR_MORE", 46: "ONE_OR_MORE", 47: "ONLY_ONE", 48: "MD_PARENT", 49: "NON_IDENTIFYING", 50: "IDENTIFYING", 51: "WORD", 52: "open_directive", 53: "type_directive", 54: "arg_directive", 55: "close_directive" },
26 productions_: [0, [3, 3], [3, 2], [5, 0], [5, 2], [8, 2], [8, 1], [8, 1], [8, 1], [7, 4], [7, 6], [10, 1], [10, 5], [10, 4], [10, 3], [10, 1], [10, 2], [10, 2], [10, 2], [10, 1], [17, 1], [17, 1], [21, 1], [21, 2], [32, 2], [32, 3], [32, 3], [32, 4], [33, 1], [34, 1], [35, 1], [35, 3], [38, 1], [36, 1], [18, 3], [42, 1], [42, 1], [42, 1], [42, 1], [42, 1], [43, 1], [43, 1], [19, 1], [19, 1], [19, 1], [12, 1], [13, 1], [16, 1], [14, 1]],
27 performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {
28 var $0 = $$.length - 1;
29 switch (yystate) {
30 case 1:
31 break;
32 case 3:
33 this.$ = [];
34 break;
35 case 4:
36 $$[$0 - 1].push($$[$0]);
37 this.$ = $$[$0 - 1];
38 break;
39 case 5:
40 case 6:
41 this.$ = $$[$0];
42 break;
43 case 7:
44 case 8:
45 this.$ = [];
46 break;
47 case 12:
48 yy.addEntity($$[$0 - 4]);
49 yy.addEntity($$[$0 - 2]);
50 yy.addRelationship($$[$0 - 4], $$[$0], $$[$0 - 2], $$[$0 - 3]);
51 break;
52 case 13:
53 yy.addEntity($$[$0 - 3]);
54 yy.addAttributes($$[$0 - 3], $$[$0 - 1]);
55 break;
56 case 14:
57 yy.addEntity($$[$0 - 2]);
58 break;
59 case 15:
60 yy.addEntity($$[$0]);
61 break;
62 case 16:
63 case 17:
64 this.$ = $$[$0].trim();
65 yy.setAccTitle(this.$);
66 break;
67 case 18:
68 case 19:
69 this.$ = $$[$0].trim();
70 yy.setAccDescription(this.$);
71 break;
72 case 20:
73 case 44:
74 this.$ = $$[$0];
75 break;
76 case 21:
77 case 42:
78 case 43:
79 this.$ = $$[$0].replace(/"/g, "");
80 break;
81 case 22:
82 case 30:
83 this.$ = [$$[$0]];
84 break;
85 case 23:
86 $$[$0].push($$[$0 - 1]);
87 this.$ = $$[$0];
88 break;
89 case 24:
90 this.$ = { attributeType: $$[$0 - 1], attributeName: $$[$0] };
91 break;
92 case 25:
93 this.$ = { attributeType: $$[$0 - 2], attributeName: $$[$0 - 1], attributeKeyTypeList: $$[$0] };
94 break;
95 case 26:
96 this.$ = { attributeType: $$[$0 - 2], attributeName: $$[$0 - 1], attributeComment: $$[$0] };
97 break;
98 case 27:
99 this.$ = { attributeType: $$[$0 - 3], attributeName: $$[$0 - 2], attributeKeyTypeList: $$[$0 - 1], attributeComment: $$[$0] };
100 break;
101 case 28:
102 case 29:
103 case 32:
104 this.$ = $$[$0];
105 break;
106 case 31:
107 $$[$0 - 2].push($$[$0]);
108 this.$ = $$[$0 - 2];
109 break;
110 case 33:
111 this.$ = $$[$0].replace(/"/g, "");
112 break;
113 case 34:
114 this.$ = { cardA: $$[$0], relType: $$[$0 - 1], cardB: $$[$0 - 2] };
115 break;
116 case 35:
117 this.$ = yy.Cardinality.ZERO_OR_ONE;
118 break;
119 case 36:
120 this.$ = yy.Cardinality.ZERO_OR_MORE;
121 break;
122 case 37:
123 this.$ = yy.Cardinality.ONE_OR_MORE;
124 break;
125 case 38:
126 this.$ = yy.Cardinality.ONLY_ONE;
127 break;
128 case 39:
129 this.$ = yy.Cardinality.MD_PARENT;
130 break;
131 case 40:
132 this.$ = yy.Identification.NON_IDENTIFYING;
133 break;
134 case 41:
135 this.$ = yy.Identification.IDENTIFYING;
136 break;
137 case 45:
138 yy.parseDirective("%%{", "open_directive");
139 break;
140 case 46:
141 yy.parseDirective($$[$0], "type_directive");
142 break;
143 case 47:
144 $$[$0] = $$[$0].trim().replace(/'/g, '"');
145 yy.parseDirective($$[$0], "arg_directive");
146 break;
147 case 48:
148 yy.parseDirective("}%%", "close_directive", "er");
149 break;
150 }
151 },
152 table: [{ 3: 1, 4: $V0, 7: 3, 12: 4, 52: $V1 }, { 1: [3] }, o($V2, [2, 3], { 5: 6 }), { 3: 7, 4: $V0, 7: 3, 12: 4, 52: $V1 }, { 13: 8, 53: [1, 9] }, { 53: [2, 45] }, { 6: [1, 10], 7: 15, 8: 11, 9: [1, 12], 10: 13, 11: [1, 14], 12: 4, 17: 16, 23: $V3, 25: $V4, 27: $V5, 29: $V6, 30: $V7, 31: $V8, 52: $V1 }, { 1: [2, 2] }, { 14: 23, 15: [1, 24], 55: $V9 }, o([15, 55], [2, 46]), o($V2, [2, 8], { 1: [2, 1] }), o($V2, [2, 4]), { 7: 15, 10: 26, 12: 4, 17: 16, 23: $V3, 25: $V4, 27: $V5, 29: $V6, 30: $V7, 31: $V8, 52: $V1 }, o($V2, [2, 6]), o($V2, [2, 7]), o($V2, [2, 11]), o($V2, [2, 15], { 18: 27, 42: 29, 20: [1, 28], 44: $Va, 45: $Vb, 46: $Vc, 47: $Vd, 48: $Ve }), { 24: [1, 35] }, { 26: [1, 36] }, { 28: [1, 37] }, o($V2, [2, 19]), o($Vf, [2, 20]), o($Vf, [2, 21]), { 11: [1, 38] }, { 16: 39, 54: [1, 40] }, { 11: [2, 48] }, o($V2, [2, 5]), { 17: 41, 30: $V7, 31: $V8 }, { 21: 42, 22: [1, 43], 32: 44, 33: 45, 37: $Vg }, { 43: 47, 49: [1, 48], 50: [1, 49] }, o($Vh, [2, 35]), o($Vh, [2, 36]), o($Vh, [2, 37]), o($Vh, [2, 38]), o($Vh, [2, 39]), o($V2, [2, 16]), o($V2, [2, 17]), o($V2, [2, 18]), o($Vi, [2, 9]), { 14: 50, 55: $V9 }, { 55: [2, 47] }, { 15: [1, 51] }, { 22: [1, 52] }, o($V2, [2, 14]), { 21: 53, 22: [2, 22], 32: 44, 33: 45, 37: $Vg }, { 34: 54, 37: [1, 55] }, { 37: [2, 28] }, { 42: 56, 44: $Va, 45: $Vb, 46: $Vc, 47: $Vd, 48: $Ve }, o($Vj, [2, 40]), o($Vj, [2, 41]), { 11: [1, 57] }, { 19: 58, 30: [1, 61], 31: [1, 60], 51: [1, 59] }, o($V2, [2, 13]), { 22: [2, 23] }, o($Vk, [2, 24], { 35: 62, 36: 63, 38: 64, 40: $Vl, 41: $Vm }), o([22, 37, 40, 41], [2, 29]), o([30, 31], [2, 34]), o($Vi, [2, 10]), o($V2, [2, 12]), o($V2, [2, 42]), o($V2, [2, 43]), o($V2, [2, 44]), o($Vk, [2, 25], { 36: 67, 39: [1, 68], 41: $Vm }), o($Vk, [2, 26]), o($Vn, [2, 30]), o($Vk, [2, 33]), o($Vn, [2, 32]), o($Vk, [2, 27]), { 38: 69, 40: $Vl }, o($Vn, [2, 31])],
153 defaultActions: { 5: [2, 45], 7: [2, 2], 25: [2, 48], 40: [2, 47], 46: [2, 28], 53: [2, 23] },
154 parseError: function parseError(str, hash) {
155 if (hash.recoverable) {
156 this.trace(str);
157 } else {
158 var error = new Error(str);
159 error.hash = hash;
160 throw error;
161 }
162 },
163 parse: function parse(input) {
164 var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, TERROR = 2, EOF = 1;
165 var args = lstack.slice.call(arguments, 1);
166 var lexer2 = Object.create(this.lexer);
167 var sharedState = { yy: {} };
168 for (var k in this.yy) {
169 if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
170 sharedState.yy[k] = this.yy[k];
171 }
172 }
173 lexer2.setInput(input, sharedState.yy);
174 sharedState.yy.lexer = lexer2;
175 sharedState.yy.parser = this;
176 if (typeof lexer2.yylloc == "undefined") {
177 lexer2.yylloc = {};
178 }
179 var yyloc = lexer2.yylloc;
180 lstack.push(yyloc);
181 var ranges = lexer2.options && lexer2.options.ranges;
182 if (typeof sharedState.yy.parseError === "function") {
183 this.parseError = sharedState.yy.parseError;
184 } else {
185 this.parseError = Object.getPrototypeOf(this).parseError;
186 }
187 function lex() {
188 var token;
189 token = tstack.pop() || lexer2.lex() || EOF;
190 if (typeof token !== "number") {
191 if (token instanceof Array) {
192 tstack = token;
193 token = tstack.pop();
194 }
195 token = self.symbols_[token] || token;
196 }
197 return token;
198 }
199 var symbol, state, action, r, yyval = {}, p, len, newState, expected;
200 while (true) {
201 state = stack[stack.length - 1];
202 if (this.defaultActions[state]) {
203 action = this.defaultActions[state];
204 } else {
205 if (symbol === null || typeof symbol == "undefined") {
206 symbol = lex();
207 }
208 action = table[state] && table[state][symbol];
209 }
210 if (typeof action === "undefined" || !action.length || !action[0]) {
211 var errStr = "";
212 expected = [];
213 for (p in table[state]) {
214 if (this.terminals_[p] && p > TERROR) {
215 expected.push("'" + this.terminals_[p] + "'");
216 }
217 }
218 if (lexer2.showPosition) {
219 errStr = "Parse error on line " + (yylineno + 1) + ":\n" + lexer2.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
220 } else {
221 errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == EOF ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
222 }
223 this.parseError(errStr, {
224 text: lexer2.match,
225 token: this.terminals_[symbol] || symbol,
226 line: lexer2.yylineno,
227 loc: yyloc,
228 expected
229 });
230 }
231 if (action[0] instanceof Array && action.length > 1) {
232 throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
233 }
234 switch (action[0]) {
235 case 1:
236 stack.push(symbol);
237 vstack.push(lexer2.yytext);
238 lstack.push(lexer2.yylloc);
239 stack.push(action[1]);
240 symbol = null;
241 {
242 yyleng = lexer2.yyleng;
243 yytext = lexer2.yytext;
244 yylineno = lexer2.yylineno;
245 yyloc = lexer2.yylloc;
246 }
247 break;
248 case 2:
249 len = this.productions_[action[1]][1];
250 yyval.$ = vstack[vstack.length - len];
251 yyval._$ = {
252 first_line: lstack[lstack.length - (len || 1)].first_line,
253 last_line: lstack[lstack.length - 1].last_line,
254 first_column: lstack[lstack.length - (len || 1)].first_column,
255 last_column: lstack[lstack.length - 1].last_column
256 };
257 if (ranges) {
258 yyval._$.range = [
259 lstack[lstack.length - (len || 1)].range[0],
260 lstack[lstack.length - 1].range[1]
261 ];
262 }
263 r = this.performAction.apply(yyval, [
264 yytext,
265 yyleng,
266 yylineno,
267 sharedState.yy,
268 action[1],
269 vstack,
270 lstack
271 ].concat(args));
272 if (typeof r !== "undefined") {
273 return r;
274 }
275 if (len) {
276 stack = stack.slice(0, -1 * len * 2);
277 vstack = vstack.slice(0, -1 * len);
278 lstack = lstack.slice(0, -1 * len);
279 }
280 stack.push(this.productions_[action[1]][0]);
281 vstack.push(yyval.$);
282 lstack.push(yyval._$);
283 newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
284 stack.push(newState);
285 break;
286 case 3:
287 return true;
288 }
289 }
290 return true;
291 }
292 };
293 var lexer = function() {
294 var lexer2 = {
295 EOF: 1,
296 parseError: function parseError(str, hash) {
297 if (this.yy.parser) {
298 this.yy.parser.parseError(str, hash);
299 } else {
300 throw new Error(str);
301 }
302 },
303 // resets the lexer, sets new input
304 setInput: function(input, yy) {
305 this.yy = yy || this.yy || {};
306 this._input = input;
307 this._more = this._backtrack = this.done = false;
308 this.yylineno = this.yyleng = 0;
309 this.yytext = this.matched = this.match = "";
310 this.conditionStack = ["INITIAL"];
311 this.yylloc = {
312 first_line: 1,
313 first_column: 0,
314 last_line: 1,
315 last_column: 0
316 };
317 if (this.options.ranges) {
318 this.yylloc.range = [0, 0];
319 }
320 this.offset = 0;
321 return this;
322 },
323 // consumes and returns one char from the input
324 input: function() {
325 var ch = this._input[0];
326 this.yytext += ch;
327 this.yyleng++;
328 this.offset++;
329 this.match += ch;
330 this.matched += ch;
331 var lines = ch.match(/(?:\r\n?|\n).*/g);
332 if (lines) {
333 this.yylineno++;
334 this.yylloc.last_line++;
335 } else {
336 this.yylloc.last_column++;
337 }
338 if (this.options.ranges) {
339 this.yylloc.range[1]++;
340 }
341 this._input = this._input.slice(1);
342 return ch;
343 },
344 // unshifts one char (or a string) into the input
345 unput: function(ch) {
346 var len = ch.length;
347 var lines = ch.split(/(?:\r\n?|\n)/g);
348 this._input = ch + this._input;
349 this.yytext = this.yytext.substr(0, this.yytext.length - len);
350 this.offset -= len;
351 var oldLines = this.match.split(/(?:\r\n?|\n)/g);
352 this.match = this.match.substr(0, this.match.length - 1);
353 this.matched = this.matched.substr(0, this.matched.length - 1);
354 if (lines.length - 1) {
355 this.yylineno -= lines.length - 1;
356 }
357 var r = this.yylloc.range;
358 this.yylloc = {
359 first_line: this.yylloc.first_line,
360 last_line: this.yylineno + 1,
361 first_column: this.yylloc.first_column,
362 last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
363 };
364 if (this.options.ranges) {
365 this.yylloc.range = [r[0], r[0] + this.yyleng - len];
366 }
367 this.yyleng = this.yytext.length;
368 return this;
369 },
370 // When called from action, caches matched text and appends it on next action
371 more: function() {
372 this._more = true;
373 return this;
374 },
375 // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
376 reject: function() {
377 if (this.options.backtrack_lexer) {
378 this._backtrack = true;
379 } else {
380 return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n" + this.showPosition(), {
381 text: "",
382 token: null,
383 line: this.yylineno
384 });
385 }
386 return this;
387 },
388 // retain first n characters of the match
389 less: function(n) {
390 this.unput(this.match.slice(n));
391 },
392 // displays already matched input, i.e. for error messages
393 pastInput: function() {
394 var past = this.matched.substr(0, this.matched.length - this.match.length);
395 return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
396 },
397 // displays upcoming input, i.e. for error messages
398 upcomingInput: function() {
399 var next = this.match;
400 if (next.length < 20) {
401 next += this._input.substr(0, 20 - next.length);
402 }
403 return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
404 },
405 // displays the character position where the lexing error occurred, i.e. for error messages
406 showPosition: function() {
407 var pre = this.pastInput();
408 var c = new Array(pre.length + 1).join("-");
409 return pre + this.upcomingInput() + "\n" + c + "^";
410 },
411 // test the lexed token: return FALSE when not a match, otherwise return token
412 test_match: function(match, indexed_rule) {
413 var token, lines, backup;
414 if (this.options.backtrack_lexer) {
415 backup = {
416 yylineno: this.yylineno,
417 yylloc: {
418 first_line: this.yylloc.first_line,
419 last_line: this.last_line,
420 first_column: this.yylloc.first_column,
421 last_column: this.yylloc.last_column
422 },
423 yytext: this.yytext,
424 match: this.match,
425 matches: this.matches,
426 matched: this.matched,
427 yyleng: this.yyleng,
428 offset: this.offset,
429 _more: this._more,
430 _input: this._input,
431 yy: this.yy,
432 conditionStack: this.conditionStack.slice(0),
433 done: this.done
434 };
435 if (this.options.ranges) {
436 backup.yylloc.range = this.yylloc.range.slice(0);
437 }
438 }
439 lines = match[0].match(/(?:\r\n?|\n).*/g);
440 if (lines) {
441 this.yylineno += lines.length;
442 }
443 this.yylloc = {
444 first_line: this.yylloc.last_line,
445 last_line: this.yylineno + 1,
446 first_column: this.yylloc.last_column,
447 last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
448 };
449 this.yytext += match[0];
450 this.match += match[0];
451 this.matches = match;
452 this.yyleng = this.yytext.length;
453 if (this.options.ranges) {
454 this.yylloc.range = [this.offset, this.offset += this.yyleng];
455 }
456 this._more = false;
457 this._backtrack = false;
458 this._input = this._input.slice(match[0].length);
459 this.matched += match[0];
460 token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
461 if (this.done && this._input) {
462 this.done = false;
463 }
464 if (token) {
465 return token;
466 } else if (this._backtrack) {
467 for (var k in backup) {
468 this[k] = backup[k];
469 }
470 return false;
471 }
472 return false;
473 },
474 // return next match in input
475 next: function() {
476 if (this.done) {
477 return this.EOF;
478 }
479 if (!this._input) {
480 this.done = true;
481 }
482 var token, match, tempMatch, index;
483 if (!this._more) {
484 this.yytext = "";
485 this.match = "";
486 }
487 var rules = this._currentRules();
488 for (var i = 0; i < rules.length; i++) {
489 tempMatch = this._input.match(this.rules[rules[i]]);
490 if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
491 match = tempMatch;
492 index = i;
493 if (this.options.backtrack_lexer) {
494 token = this.test_match(tempMatch, rules[i]);
495 if (token !== false) {
496 return token;
497 } else if (this._backtrack) {
498 match = false;
499 continue;
500 } else {
501 return false;
502 }
503 } else if (!this.options.flex) {
504 break;
505 }
506 }
507 }
508 if (match) {
509 token = this.test_match(match, rules[index]);
510 if (token !== false) {
511 return token;
512 }
513 return false;
514 }
515 if (this._input === "") {
516 return this.EOF;
517 } else {
518 return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
519 text: "",
520 token: null,
521 line: this.yylineno
522 });
523 }
524 },
525 // return next match that has a token
526 lex: function lex() {
527 var r = this.next();
528 if (r) {
529 return r;
530 } else {
531 return this.lex();
532 }
533 },
534 // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
535 begin: function begin(condition) {
536 this.conditionStack.push(condition);
537 },
538 // pop the previously active lexer condition state off the condition stack
539 popState: function popState() {
540 var n = this.conditionStack.length - 1;
541 if (n > 0) {
542 return this.conditionStack.pop();
543 } else {
544 return this.conditionStack[0];
545 }
546 },
547 // produce the lexer rule set which is active for the currently active lexer condition state
548 _currentRules: function _currentRules() {
549 if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
550 return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
551 } else {
552 return this.conditions["INITIAL"].rules;
553 }
554 },
555 // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
556 topState: function topState(n) {
557 n = this.conditionStack.length - 1 - Math.abs(n || 0);
558 if (n >= 0) {
559 return this.conditionStack[n];
560 } else {
561 return "INITIAL";
562 }
563 },
564 // alias for begin(condition)
565 pushState: function pushState(condition) {
566 this.begin(condition);
567 },
568 // return the number of states currently on the stack
569 stateStackSize: function stateStackSize() {
570 return this.conditionStack.length;
571 },
572 options: { "case-insensitive": true },
573 performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
574 switch ($avoiding_name_collisions) {
575 case 0:
576 this.begin("acc_title");
577 return 25;
578 case 1:
579 this.popState();
580 return "acc_title_value";
581 case 2:
582 this.begin("acc_descr");
583 return 27;
584 case 3:
585 this.popState();
586 return "acc_descr_value";
587 case 4:
588 this.begin("acc_descr_multiline");
589 break;
590 case 5:
591 this.popState();
592 break;
593 case 6:
594 return "acc_descr_multiline_value";
595 case 7:
596 this.begin("open_directive");
597 return 52;
598 case 8:
599 this.begin("type_directive");
600 return 53;
601 case 9:
602 this.popState();
603 this.begin("arg_directive");
604 return 15;
605 case 10:
606 this.popState();
607 this.popState();
608 return 55;
609 case 11:
610 return 54;
611 case 12:
612 return 11;
613 case 13:
614 break;
615 case 14:
616 return 9;
617 case 15:
618 return 31;
619 case 16:
620 return 51;
621 case 17:
622 return 4;
623 case 18:
624 this.begin("block");
625 return 20;
626 case 19:
627 return 39;
628 case 20:
629 break;
630 case 21:
631 return 40;
632 case 22:
633 return 37;
634 case 23:
635 return 37;
636 case 24:
637 return 41;
638 case 25:
639 break;
640 case 26:
641 this.popState();
642 return 22;
643 case 27:
644 return yy_.yytext[0];
645 case 28:
646 return 44;
647 case 29:
648 return 46;
649 case 30:
650 return 46;
651 case 31:
652 return 46;
653 case 32:
654 return 44;
655 case 33:
656 return 44;
657 case 34:
658 return 45;
659 case 35:
660 return 45;
661 case 36:
662 return 45;
663 case 37:
664 return 45;
665 case 38:
666 return 45;
667 case 39:
668 return 46;
669 case 40:
670 return 45;
671 case 41:
672 return 46;
673 case 42:
674 return 47;
675 case 43:
676 return 47;
677 case 44:
678 return 47;
679 case 45:
680 return 47;
681 case 46:
682 return 44;
683 case 47:
684 return 45;
685 case 48:
686 return 46;
687 case 49:
688 return 48;
689 case 50:
690 return 49;
691 case 51:
692 return 50;
693 case 52:
694 return 50;
695 case 53:
696 return 49;
697 case 54:
698 return 49;
699 case 55:
700 return 49;
701 case 56:
702 return 30;
703 case 57:
704 return yy_.yytext[0];
705 case 58:
706 return 6;
707 }
708 },
709 rules: [/^(?:accTitle\s*:\s*)/i, /^(?:(?!\n||)*[^\n]*)/i, /^(?:accDescr\s*:\s*)/i, /^(?:(?!\n||)*[^\n]*)/i, /^(?:accDescr\s*\{\s*)/i, /^(?:[\}])/i, /^(?:[^\}]*)/i, /^(?:%%\{)/i, /^(?:((?:(?!\}%%)[^:.])*))/i, /^(?::)/i, /^(?:\}%%)/i, /^(?:((?:(?!\}%%).|\n)*))/i, /^(?:[\n]+)/i, /^(?:\s+)/i, /^(?:[\s]+)/i, /^(?:"[^"%\r\n\v\b\\]+")/i, /^(?:"[^"]*")/i, /^(?:erDiagram\b)/i, /^(?:\{)/i, /^(?:,)/i, /^(?:\s+)/i, /^(?:\b((?:PK)|(?:FK)|(?:UK))\b)/i, /^(?:(.*?)[~](.*?)*[~])/i, /^(?:[A-Za-z_][A-Za-z0-9\-_\[\]\(\)]*)/i, /^(?:"[^"]*")/i, /^(?:[\n]+)/i, /^(?:\})/i, /^(?:.)/i, /^(?:one or zero\b)/i, /^(?:one or more\b)/i, /^(?:one or many\b)/i, /^(?:1\+)/i, /^(?:\|o\b)/i, /^(?:zero or one\b)/i, /^(?:zero or more\b)/i, /^(?:zero or many\b)/i, /^(?:0\+)/i, /^(?:\}o\b)/i, /^(?:many\(0\))/i, /^(?:many\(1\))/i, /^(?:many\b)/i, /^(?:\}\|)/i, /^(?:one\b)/i, /^(?:only one\b)/i, /^(?:1\b)/i, /^(?:\|\|)/i, /^(?:o\|)/i, /^(?:o\{)/i, /^(?:\|\{)/i, /^(?:\s*u\b)/i, /^(?:\.\.)/i, /^(?:--)/i, /^(?:to\b)/i, /^(?:optionally to\b)/i, /^(?:\.-)/i, /^(?:-\.)/i, /^(?:[A-Za-z][A-Za-z0-9\-_]*)/i, /^(?:.)/i, /^(?:$)/i],
710 conditions: { "acc_descr_multiline": { "rules": [5, 6], "inclusive": false }, "acc_descr": { "rules": [3], "inclusive": false }, "acc_title": { "rules": [1], "inclusive": false }, "open_directive": { "rules": [8], "inclusive": false }, "type_directive": { "rules": [9, 10], "inclusive": false }, "arg_directive": { "rules": [10, 11], "inclusive": false }, "block": { "rules": [19, 20, 21, 22, 23, 24, 25, 26, 27], "inclusive": false }, "INITIAL": { "rules": [0, 2, 4, 7, 12, 13, 14, 15, 16, 17, 18, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], "inclusive": true } }
711 };
712 return lexer2;
713 }();
714 parser2.lexer = lexer;
715 function Parser() {
716 this.yy = {};
717 }
718 Parser.prototype = parser2;
719 parser2.Parser = Parser;
720 return new Parser();
721}();
722parser.parser = parser;
723const erParser = parser;
724let entities = {};
725let relationships = [];
726const Cardinality = {
727 ZERO_OR_ONE: "ZERO_OR_ONE",
728 ZERO_OR_MORE: "ZERO_OR_MORE",
729 ONE_OR_MORE: "ONE_OR_MORE",
730 ONLY_ONE: "ONLY_ONE",
731 MD_PARENT: "MD_PARENT"
732};
733const Identification = {
734 NON_IDENTIFYING: "NON_IDENTIFYING",
735 IDENTIFYING: "IDENTIFYING"
736};
737const parseDirective = function(statement, context, type) {
738 mermaidAPI.parseDirective(this, statement, context, type);
739};
740const addEntity = function(name) {
741 if (entities[name] === void 0) {
742 entities[name] = { attributes: [] };
743 log.info("Added new entity :", name);
744 }
745 return entities[name];
746};
747const getEntities = () => entities;
748const addAttributes = function(entityName, attribs) {
749 let entity = addEntity(entityName);
750 let i;
751 for (i = attribs.length - 1; i >= 0; i--) {
752 entity.attributes.push(attribs[i]);
753 log.debug("Added attribute ", attribs[i].attributeName);
754 }
755};
756const addRelationship = function(entA, rolA, entB, rSpec) {
757 let rel = {
758 entityA: entA,
759 roleA: rolA,
760 entityB: entB,
761 relSpec: rSpec
762 };
763 relationships.push(rel);
764 log.debug("Added new relationship :", rel);
765};
766const getRelationships = () => relationships;
767const clear = function() {
768 entities = {};
769 relationships = [];
770 clear$1();
771};
772const erDb = {
773 Cardinality,
774 Identification,
775 parseDirective,
776 getConfig: () => getConfig().er,
777 addEntity,
778 addAttributes,
779 getEntities,
780 addRelationship,
781 getRelationships,
782 clear,
783 setAccTitle,
784 getAccTitle,
785 setAccDescription,
786 getAccDescription,
787 setDiagramTitle,
788 getDiagramTitle
789};
790const ERMarkers = {
791 ONLY_ONE_START: "ONLY_ONE_START",
792 ONLY_ONE_END: "ONLY_ONE_END",
793 ZERO_OR_ONE_START: "ZERO_OR_ONE_START",
794 ZERO_OR_ONE_END: "ZERO_OR_ONE_END",
795 ONE_OR_MORE_START: "ONE_OR_MORE_START",
796 ONE_OR_MORE_END: "ONE_OR_MORE_END",
797 ZERO_OR_MORE_START: "ZERO_OR_MORE_START",
798 ZERO_OR_MORE_END: "ZERO_OR_MORE_END",
799 MD_PARENT_END: "MD_PARENT_END",
800 MD_PARENT_START: "MD_PARENT_START"
801};
802const insertMarkers = function(elem, conf2) {
803 let marker;
804 elem.append("defs").append("marker").attr("id", ERMarkers.MD_PARENT_START).attr("refX", 0).attr("refY", 7).attr("markerWidth", 190).attr("markerHeight", 240).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
805 elem.append("defs").append("marker").attr("id", ERMarkers.MD_PARENT_END).attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 18,7 L9,13 L1,7 L9,1 Z");
806 elem.append("defs").append("marker").attr("id", ERMarkers.ONLY_ONE_START).attr("refX", 0).attr("refY", 9).attr("markerWidth", 18).attr("markerHeight", 18).attr("orient", "auto").append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M9,0 L9,18 M15,0 L15,18");
807 elem.append("defs").append("marker").attr("id", ERMarkers.ONLY_ONE_END).attr("refX", 18).attr("refY", 9).attr("markerWidth", 18).attr("markerHeight", 18).attr("orient", "auto").append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M3,0 L3,18 M9,0 L9,18");
808 marker = elem.append("defs").append("marker").attr("id", ERMarkers.ZERO_OR_ONE_START).attr("refX", 0).attr("refY", 9).attr("markerWidth", 30).attr("markerHeight", 18).attr("orient", "auto");
809 marker.append("circle").attr("stroke", conf2.stroke).attr("fill", "white").attr("cx", 21).attr("cy", 9).attr("r", 6);
810 marker.append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M9,0 L9,18");
811 marker = elem.append("defs").append("marker").attr("id", ERMarkers.ZERO_OR_ONE_END).attr("refX", 30).attr("refY", 9).attr("markerWidth", 30).attr("markerHeight", 18).attr("orient", "auto");
812 marker.append("circle").attr("stroke", conf2.stroke).attr("fill", "white").attr("cx", 9).attr("cy", 9).attr("r", 6);
813 marker.append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M21,0 L21,18");
814 elem.append("defs").append("marker").attr("id", ERMarkers.ONE_OR_MORE_START).attr("refX", 18).attr("refY", 18).attr("markerWidth", 45).attr("markerHeight", 36).attr("orient", "auto").append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M0,18 Q 18,0 36,18 Q 18,36 0,18 M42,9 L42,27");
815 elem.append("defs").append("marker").attr("id", ERMarkers.ONE_OR_MORE_END).attr("refX", 27).attr("refY", 18).attr("markerWidth", 45).attr("markerHeight", 36).attr("orient", "auto").append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M3,9 L3,27 M9,18 Q27,0 45,18 Q27,36 9,18");
816 marker = elem.append("defs").append("marker").attr("id", ERMarkers.ZERO_OR_MORE_START).attr("refX", 18).attr("refY", 18).attr("markerWidth", 57).attr("markerHeight", 36).attr("orient", "auto");
817 marker.append("circle").attr("stroke", conf2.stroke).attr("fill", "white").attr("cx", 48).attr("cy", 18).attr("r", 6);
818 marker.append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M0,18 Q18,0 36,18 Q18,36 0,18");
819 marker = elem.append("defs").append("marker").attr("id", ERMarkers.ZERO_OR_MORE_END).attr("refX", 39).attr("refY", 18).attr("markerWidth", 57).attr("markerHeight", 36).attr("orient", "auto");
820 marker.append("circle").attr("stroke", conf2.stroke).attr("fill", "white").attr("cx", 9).attr("cy", 18).attr("r", 6);
821 marker.append("path").attr("stroke", conf2.stroke).attr("fill", "none").attr("d", "M21,18 Q39,0 57,18 Q39,36 21,18");
822 return;
823};
824const erMarkers = {
825 ERMarkers,
826 insertMarkers
827};
828const BAD_ID_CHARS_REGEXP = /[^\dA-Za-z](\W)*/g;
829let conf = {};
830let entityNameIds = /* @__PURE__ */ new Map();
831const setConf = function(cnf) {
832 const keys = Object.keys(cnf);
833 for (const key of keys) {
834 conf[key] = cnf[key];
835 }
836};
837const drawAttributes = (groupNode, entityTextNode, attributes) => {
838 const heightPadding = conf.entityPadding / 3;
839 const widthPadding = conf.entityPadding / 3;
840 const attrFontSize = conf.fontSize * 0.85;
841 const labelBBox = entityTextNode.node().getBBox();
842 const attributeNodes = [];
843 let hasKeyType = false;
844 let hasComment = false;
845 let maxTypeWidth = 0;
846 let maxNameWidth = 0;
847 let maxKeyWidth = 0;
848 let maxCommentWidth = 0;
849 let cumulativeHeight = labelBBox.height + heightPadding * 2;
850 let attrNum = 1;
851 attributes.forEach((item) => {
852 if (item.attributeKeyTypeList !== void 0 && item.attributeKeyTypeList.length > 0) {
853 hasKeyType = true;
854 }
855 if (item.attributeComment !== void 0) {
856 hasComment = true;
857 }
858 });
859 attributes.forEach((item) => {
860 const attrPrefix = `${entityTextNode.node().id}-attr-${attrNum}`;
861 let nodeHeight = 0;
862 const attributeType = parseGenericTypes(item.attributeType);
863 const typeNode = groupNode.append("text").classed("er entityLabel", true).attr("id", `${attrPrefix}-type`).attr("x", 0).attr("y", 0).style("dominant-baseline", "middle").style("text-anchor", "left").style("font-family", getConfig().fontFamily).style("font-size", attrFontSize + "px").text(attributeType);
864 const nameNode = groupNode.append("text").classed("er entityLabel", true).attr("id", `${attrPrefix}-name`).attr("x", 0).attr("y", 0).style("dominant-baseline", "middle").style("text-anchor", "left").style("font-family", getConfig().fontFamily).style("font-size", attrFontSize + "px").text(item.attributeName);
865 const attributeNode = {};
866 attributeNode.tn = typeNode;
867 attributeNode.nn = nameNode;
868 const typeBBox = typeNode.node().getBBox();
869 const nameBBox = nameNode.node().getBBox();
870 maxTypeWidth = Math.max(maxTypeWidth, typeBBox.width);
871 maxNameWidth = Math.max(maxNameWidth, nameBBox.width);
872 nodeHeight = Math.max(typeBBox.height, nameBBox.height);
873 if (hasKeyType) {
874 const keyTypeNodeText = item.attributeKeyTypeList !== void 0 ? item.attributeKeyTypeList.join(",") : "";
875 const keyTypeNode = groupNode.append("text").classed("er entityLabel", true).attr("id", `${attrPrefix}-key`).attr("x", 0).attr("y", 0).style("dominant-baseline", "middle").style("text-anchor", "left").style("font-family", getConfig().fontFamily).style("font-size", attrFontSize + "px").text(keyTypeNodeText);
876 attributeNode.kn = keyTypeNode;
877 const keyTypeBBox = keyTypeNode.node().getBBox();
878 maxKeyWidth = Math.max(maxKeyWidth, keyTypeBBox.width);
879 nodeHeight = Math.max(nodeHeight, keyTypeBBox.height);
880 }
881 if (hasComment) {
882 const commentNode = groupNode.append("text").classed("er entityLabel", true).attr("id", `${attrPrefix}-comment`).attr("x", 0).attr("y", 0).style("dominant-baseline", "middle").style("text-anchor", "left").style("font-family", getConfig().fontFamily).style("font-size", attrFontSize + "px").text(item.attributeComment || "");
883 attributeNode.cn = commentNode;
884 const commentNodeBBox = commentNode.node().getBBox();
885 maxCommentWidth = Math.max(maxCommentWidth, commentNodeBBox.width);
886 nodeHeight = Math.max(nodeHeight, commentNodeBBox.height);
887 }
888 attributeNode.height = nodeHeight;
889 attributeNodes.push(attributeNode);
890 cumulativeHeight += nodeHeight + heightPadding * 2;
891 attrNum += 1;
892 });
893 let widthPaddingFactor = 4;
894 if (hasKeyType) {
895 widthPaddingFactor += 2;
896 }
897 if (hasComment) {
898 widthPaddingFactor += 2;
899 }
900 const maxWidth = maxTypeWidth + maxNameWidth + maxKeyWidth + maxCommentWidth;
901 const bBox = {
902 width: Math.max(
903 conf.minEntityWidth,
904 Math.max(
905 labelBBox.width + conf.entityPadding * 2,
906 maxWidth + widthPadding * widthPaddingFactor
907 )
908 ),
909 height: attributes.length > 0 ? cumulativeHeight : Math.max(conf.minEntityHeight, labelBBox.height + conf.entityPadding * 2)
910 };
911 if (attributes.length > 0) {
912 const spareColumnWidth = Math.max(
913 0,
914 (bBox.width - maxWidth - widthPadding * widthPaddingFactor) / (widthPaddingFactor / 2)
915 );
916 entityTextNode.attr(
917 "transform",
918 "translate(" + bBox.width / 2 + "," + (heightPadding + labelBBox.height / 2) + ")"
919 );
920 let heightOffset = labelBBox.height + heightPadding * 2;
921 let attribStyle = "attributeBoxOdd";
922 attributeNodes.forEach((attributeNode) => {
923 const alignY = heightOffset + heightPadding + attributeNode.height / 2;
924 attributeNode.tn.attr("transform", "translate(" + widthPadding + "," + alignY + ")");
925 const typeRect = groupNode.insert("rect", "#" + attributeNode.tn.node().id).classed(`er ${attribStyle}`, true).attr("x", 0).attr("y", heightOffset).attr("width", maxTypeWidth + widthPadding * 2 + spareColumnWidth).attr("height", attributeNode.height + heightPadding * 2);
926 const nameXOffset = parseFloat(typeRect.attr("x")) + parseFloat(typeRect.attr("width"));
927 attributeNode.nn.attr(
928 "transform",
929 "translate(" + (nameXOffset + widthPadding) + "," + alignY + ")"
930 );
931 const nameRect = groupNode.insert("rect", "#" + attributeNode.nn.node().id).classed(`er ${attribStyle}`, true).attr("x", nameXOffset).attr("y", heightOffset).attr("width", maxNameWidth + widthPadding * 2 + spareColumnWidth).attr("height", attributeNode.height + heightPadding * 2);
932 let keyTypeAndCommentXOffset = parseFloat(nameRect.attr("x")) + parseFloat(nameRect.attr("width"));
933 if (hasKeyType) {
934 attributeNode.kn.attr(
935 "transform",
936 "translate(" + (keyTypeAndCommentXOffset + widthPadding) + "," + alignY + ")"
937 );
938 const keyTypeRect = groupNode.insert("rect", "#" + attributeNode.kn.node().id).classed(`er ${attribStyle}`, true).attr("x", keyTypeAndCommentXOffset).attr("y", heightOffset).attr("width", maxKeyWidth + widthPadding * 2 + spareColumnWidth).attr("height", attributeNode.height + heightPadding * 2);
939 keyTypeAndCommentXOffset = parseFloat(keyTypeRect.attr("x")) + parseFloat(keyTypeRect.attr("width"));
940 }
941 if (hasComment) {
942 attributeNode.cn.attr(
943 "transform",
944 "translate(" + (keyTypeAndCommentXOffset + widthPadding) + "," + alignY + ")"
945 );
946 groupNode.insert("rect", "#" + attributeNode.cn.node().id).classed(`er ${attribStyle}`, "true").attr("x", keyTypeAndCommentXOffset).attr("y", heightOffset).attr("width", maxCommentWidth + widthPadding * 2 + spareColumnWidth).attr("height", attributeNode.height + heightPadding * 2);
947 }
948 heightOffset += attributeNode.height + heightPadding * 2;
949 attribStyle = attribStyle === "attributeBoxOdd" ? "attributeBoxEven" : "attributeBoxOdd";
950 });
951 } else {
952 bBox.height = Math.max(conf.minEntityHeight, cumulativeHeight);
953 entityTextNode.attr("transform", "translate(" + bBox.width / 2 + "," + bBox.height / 2 + ")");
954 }
955 return bBox;
956};
957const drawEntities = function(svgNode, entities2, graph) {
958 const keys = Object.keys(entities2);
959 let firstOne;
960 keys.forEach(function(entityName) {
961 const entityId = generateId(entityName, "entity");
962 entityNameIds.set(entityName, entityId);
963 const groupNode = svgNode.append("g").attr("id", entityId);
964 firstOne = firstOne === void 0 ? entityId : firstOne;
965 const textId = "text-" + entityId;
966 const textNode = groupNode.append("text").classed("er entityLabel", true).attr("id", textId).attr("x", 0).attr("y", 0).style("dominant-baseline", "middle").style("text-anchor", "middle").style("font-family", getConfig().fontFamily).style("font-size", conf.fontSize + "px").text(entityName);
967 const { width: entityWidth, height: entityHeight } = drawAttributes(
968 groupNode,
969 textNode,
970 entities2[entityName].attributes
971 );
972 const rectNode = groupNode.insert("rect", "#" + textId).classed("er entityBox", true).attr("x", 0).attr("y", 0).attr("width", entityWidth).attr("height", entityHeight);
973 const rectBBox = rectNode.node().getBBox();
974 graph.setNode(entityId, {
975 width: rectBBox.width,
976 height: rectBBox.height,
977 shape: "rect",
978 id: entityId
979 });
980 });
981 return firstOne;
982};
983const adjustEntities = function(svgNode, graph) {
984 graph.nodes().forEach(function(v) {
985 if (v !== void 0 && graph.node(v) !== void 0) {
986 svgNode.select("#" + v).attr(
987 "transform",
988 "translate(" + (graph.node(v).x - graph.node(v).width / 2) + "," + (graph.node(v).y - graph.node(v).height / 2) + " )"
989 );
990 }
991 });
992};
993const getEdgeName = function(rel) {
994 return (rel.entityA + rel.roleA + rel.entityB).replace(/\s/g, "");
995};
996const addRelationships = function(relationships2, g) {
997 relationships2.forEach(function(r) {
998 g.setEdge(
999 entityNameIds.get(r.entityA),
1000 entityNameIds.get(r.entityB),
1001 { relationship: r },
1002 getEdgeName(r)
1003 );
1004 });
1005 return relationships2;
1006};
1007let relCnt = 0;
1008const drawRelationshipFromLayout = function(svg, rel, g, insert, diagObj) {
1009 relCnt++;
1010 const edge = g.edge(
1011 entityNameIds.get(rel.entityA),
1012 entityNameIds.get(rel.entityB),
1013 getEdgeName(rel)
1014 );
1015 const lineFunction = line().x(function(d) {
1016 return d.x;
1017 }).y(function(d) {
1018 return d.y;
1019 }).curve(curveBasis);
1020 const svgPath = svg.insert("path", "#" + insert).classed("er relationshipLine", true).attr("d", lineFunction(edge.points)).style("stroke", conf.stroke).style("fill", "none");
1021 if (rel.relSpec.relType === diagObj.db.Identification.NON_IDENTIFYING) {
1022 svgPath.attr("stroke-dasharray", "8,8");
1023 }
1024 let url = "";
1025 if (conf.arrowMarkerAbsolute) {
1026 url = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search;
1027 url = url.replace(/\(/g, "\\(");
1028 url = url.replace(/\)/g, "\\)");
1029 }
1030 switch (rel.relSpec.cardA) {
1031 case diagObj.db.Cardinality.ZERO_OR_ONE:
1032 svgPath.attr("marker-end", "url(" + url + "#" + erMarkers.ERMarkers.ZERO_OR_ONE_END + ")");
1033 break;
1034 case diagObj.db.Cardinality.ZERO_OR_MORE:
1035 svgPath.attr("marker-end", "url(" + url + "#" + erMarkers.ERMarkers.ZERO_OR_MORE_END + ")");
1036 break;
1037 case diagObj.db.Cardinality.ONE_OR_MORE:
1038 svgPath.attr("marker-end", "url(" + url + "#" + erMarkers.ERMarkers.ONE_OR_MORE_END + ")");
1039 break;
1040 case diagObj.db.Cardinality.ONLY_ONE:
1041 svgPath.attr("marker-end", "url(" + url + "#" + erMarkers.ERMarkers.ONLY_ONE_END + ")");
1042 break;
1043 case diagObj.db.Cardinality.MD_PARENT:
1044 svgPath.attr("marker-end", "url(" + url + "#" + erMarkers.ERMarkers.MD_PARENT_END + ")");
1045 break;
1046 }
1047 switch (rel.relSpec.cardB) {
1048 case diagObj.db.Cardinality.ZERO_OR_ONE:
1049 svgPath.attr(
1050 "marker-start",
1051 "url(" + url + "#" + erMarkers.ERMarkers.ZERO_OR_ONE_START + ")"
1052 );
1053 break;
1054 case diagObj.db.Cardinality.ZERO_OR_MORE:
1055 svgPath.attr(
1056 "marker-start",
1057 "url(" + url + "#" + erMarkers.ERMarkers.ZERO_OR_MORE_START + ")"
1058 );
1059 break;
1060 case diagObj.db.Cardinality.ONE_OR_MORE:
1061 svgPath.attr(
1062 "marker-start",
1063 "url(" + url + "#" + erMarkers.ERMarkers.ONE_OR_MORE_START + ")"
1064 );
1065 break;
1066 case diagObj.db.Cardinality.ONLY_ONE:
1067 svgPath.attr("marker-start", "url(" + url + "#" + erMarkers.ERMarkers.ONLY_ONE_START + ")");
1068 break;
1069 case diagObj.db.Cardinality.MD_PARENT:
1070 svgPath.attr("marker-start", "url(" + url + "#" + erMarkers.ERMarkers.MD_PARENT_START + ")");
1071 break;
1072 }
1073 const len = svgPath.node().getTotalLength();
1074 const labelPoint = svgPath.node().getPointAtLength(len * 0.5);
1075 const labelId = "rel" + relCnt;
1076 const labelNode = svg.append("text").classed("er relationshipLabel", true).attr("id", labelId).attr("x", labelPoint.x).attr("y", labelPoint.y).style("text-anchor", "middle").style("dominant-baseline", "middle").style("font-family", getConfig().fontFamily).style("font-size", conf.fontSize + "px").text(rel.roleA);
1077 const labelBBox = labelNode.node().getBBox();
1078 svg.insert("rect", "#" + labelId).classed("er relationshipLabelBox", true).attr("x", labelPoint.x - labelBBox.width / 2).attr("y", labelPoint.y - labelBBox.height / 2).attr("width", labelBBox.width).attr("height", labelBBox.height);
1079};
1080const draw = function(text, id, _version, diagObj) {
1081 conf = getConfig().er;
1082 log.info("Drawing ER diagram");
1083 const securityLevel = getConfig().securityLevel;
1084 let sandboxElement;
1085 if (securityLevel === "sandbox") {
1086 sandboxElement = select("#i" + id);
1087 }
1088 const root = securityLevel === "sandbox" ? select(sandboxElement.nodes()[0].contentDocument.body) : select("body");
1089 const svg = root.select(`[id='${id}']`);
1090 erMarkers.insertMarkers(svg, conf);
1091 let g;
1092 g = new graphlib.Graph({
1093 multigraph: true,
1094 directed: true,
1095 compound: false
1096 }).setGraph({
1097 rankdir: conf.layoutDirection,
1098 marginx: 20,
1099 marginy: 20,
1100 nodesep: 100,
1101 edgesep: 100,
1102 ranksep: 100
1103 }).setDefaultEdgeLabel(function() {
1104 return {};
1105 });
1106 const firstEntity = drawEntities(svg, diagObj.db.getEntities(), g);
1107 const relationships2 = addRelationships(diagObj.db.getRelationships(), g);
1108 layout(g);
1109 adjustEntities(svg, g);
1110 relationships2.forEach(function(rel) {
1111 drawRelationshipFromLayout(svg, rel, g, firstEntity, diagObj);
1112 });
1113 const padding = conf.diagramPadding;
1114 utils.insertTitle(svg, "entityTitleText", conf.titleTopMargin, diagObj.db.getDiagramTitle());
1115 const svgBounds = svg.node().getBBox();
1116 const width = svgBounds.width + padding * 2;
1117 const height = svgBounds.height + padding * 2;
1118 configureSvgSize(svg, height, width, conf.useMaxWidth);
1119 svg.attr("viewBox", `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`);
1120};
1121const MERMAID_ERDIAGRAM_UUID = "28e9f9db-3c8d-5aa5-9faf-44286ae5937c";
1122function generateId(str = "", prefix = "") {
1123 const simplifiedStr = str.replace(BAD_ID_CHARS_REGEXP, "");
1124 return `${strWithHyphen(prefix)}${strWithHyphen(simplifiedStr)}${v5(
1125 str,
1126 MERMAID_ERDIAGRAM_UUID
1127 )}`;
1128}
1129function strWithHyphen(str = "") {
1130 return str.length > 0 ? `${str}-` : "";
1131}
1132const erRenderer = {
1133 setConf,
1134 draw
1135};
1136const getStyles = (options) => `
1137 .entityBox {
1138 fill: ${options.mainBkg};
1139 stroke: ${options.nodeBorder};
1140 }
1141
1142 .attributeBoxOdd {
1143 fill: ${options.attributeBackgroundColorOdd};
1144 stroke: ${options.nodeBorder};
1145 }
1146
1147 .attributeBoxEven {
1148 fill: ${options.attributeBackgroundColorEven};
1149 stroke: ${options.nodeBorder};
1150 }
1151
1152 .relationshipLabelBox {
1153 fill: ${options.tertiaryColor};
1154 opacity: 0.7;
1155 background-color: ${options.tertiaryColor};
1156 rect {
1157 opacity: 0.5;
1158 }
1159 }
1160
1161 .relationshipLine {
1162 stroke: ${options.lineColor};
1163 }
1164
1165 .entityTitleText {
1166 text-anchor: middle;
1167 font-size: 18px;
1168 fill: ${options.textColor};
1169 }
1170 #MD_PARENT_START {
1171 fill: #f5f5f5 !important;
1172 stroke: ${options.lineColor} !important;
1173 stroke-width: 1;
1174 }
1175 #MD_PARENT_END {
1176 fill: #f5f5f5 !important;
1177 stroke: ${options.lineColor} !important;
1178 stroke-width: 1;
1179 }
1180
1181`;
1182const erStyles = getStyles;
1183const diagram = {
1184 parser: erParser,
1185 db: erDb,
1186 renderer: erRenderer,
1187 styles: erStyles
1188};
1189export {
1190 diagram
1191};