UNPKG

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