erDiagram-762WSSOR.mjs 51 KB

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