UNPKG

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