@yorz/cli 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +133 -53
- package/dist/gui/assets/{abnfDiagram-VRR7QNED-BlILeZZA.js → abnfDiagram-VRR7QNED-Dk823f-p.js} +1 -1
- package/dist/gui/assets/{arc-C-xJpbjF.js → arc-CsAcQvy9.js} +1 -1
- package/dist/gui/assets/{architectureDiagram-ZJ3FMSHR-QdzNii0b.js → architectureDiagram-ZJ3FMSHR-9d29EB_v.js} +1 -1
- package/dist/gui/assets/{blockDiagram-677ZJIJ3-BQTAKTET.js → blockDiagram-677ZJIJ3-C_BdniYG.js} +1 -1
- package/dist/gui/assets/{c4Diagram-LMCZKHZV-YRh3fqeb.js → c4Diagram-LMCZKHZV-COHS5O60.js} +1 -1
- package/dist/gui/assets/channel-Cdj31qNd.js +1 -0
- package/dist/gui/assets/{chunk-2Q5K7J3B-Bgu-eeCS.js → chunk-2Q5K7J3B-CdpNMJAI.js} +1 -1
- package/dist/gui/assets/{chunk-32BRIVSS-DTLd8wsP.js → chunk-32BRIVSS-C-5zZ7Xl.js} +1 -1
- package/dist/gui/assets/{chunk-5VM5RSS4-Cct8HJoz.js → chunk-5VM5RSS4-DNMuZJaP.js} +1 -1
- package/dist/gui/assets/{chunk-EX3LRPZG-DBgaA_1N.js → chunk-EX3LRPZG-BGPzkMUB.js} +1 -1
- package/dist/gui/assets/{chunk-JWPE2WC7-DELoF8bV.js → chunk-JWPE2WC7-DKHh8QvM.js} +1 -1
- package/dist/gui/assets/{chunk-MOJQB5TN-Du6uREYs.js → chunk-MOJQB5TN-DjfrUCo1.js} +1 -1
- package/dist/gui/assets/{chunk-RYQCIY6F-CxO6cQdM.js → chunk-RYQCIY6F-CAOzG_fF.js} +1 -1
- package/dist/gui/assets/{chunk-V7JOEXUC-BiILBcGA.js → chunk-V7JOEXUC-CiYl0Zr6.js} +1 -1
- package/dist/gui/assets/{chunk-VR4S4FIN-BfY2RvG4.js → chunk-VR4S4FIN-C9R15N13.js} +1 -1
- package/dist/gui/assets/{chunk-XXDRQBXY-DmsZw6tB.js → chunk-XXDRQBXY-D08V--b4.js} +1 -1
- package/dist/gui/assets/classDiagram-OUVF2IWQ-BiCCYKL9.js +1 -0
- package/dist/gui/assets/classDiagram-v2-EOCWNBFH-BiCCYKL9.js +1 -0
- package/dist/gui/assets/{cose-bilkent-JH36ORCC-gX-8DSxS.js → cose-bilkent-JH36ORCC-h3WvWy31.js} +1 -1
- package/dist/gui/assets/{cynefin-VYW2F7L2-vOfRo7cL.js → cynefin-VYW2F7L2-BJJROAhw.js} +1 -1
- package/dist/gui/assets/{cynefinDiagram-TSTJHNR4-Dv66a7Rh.js → cynefinDiagram-TSTJHNR4-Cowr6YON.js} +1 -1
- package/dist/gui/assets/{dagre-VKFMJZFB-Rk64dDvT.js → dagre-VKFMJZFB-CHQSayFl.js} +1 -1
- package/dist/gui/assets/{diagram-FQU43EPY-CyW3IjmQ.js → diagram-FQU43EPY-Dkjm-gpD.js} +1 -1
- package/dist/gui/assets/{diagram-G47NLZAW-Caav47lW.js → diagram-G47NLZAW-CWzLjtMq.js} +1 -1
- package/dist/gui/assets/{diagram-NH7WQ7WH-_X3ihqNf.js → diagram-NH7WQ7WH-CJEfCmpn.js} +1 -1
- package/dist/gui/assets/{diagram-OA4YK3LP-CjbverOE.js → diagram-OA4YK3LP-DKXL4ZCg.js} +1 -1
- package/dist/gui/assets/{diagram-WEI45ONY-B93ZeTtT.js → diagram-WEI45ONY-CLvc8CSB.js} +1 -1
- package/dist/gui/assets/{ebnfDiagram-CCIWWBDH-CdDt4bWx.js → ebnfDiagram-CCIWWBDH-D6NViEZ2.js} +1 -1
- package/dist/gui/assets/{erDiagram-Q63AITRT-Bypq-rvj.js → erDiagram-Q63AITRT-B2mRc5jq.js} +1 -1
- package/dist/gui/assets/{flowDiagram-23GEKE2U-b-l8_7KP.js → flowDiagram-23GEKE2U-Bu2CgXeG.js} +1 -1
- package/dist/gui/assets/{ganttDiagram-NO4QXBWP-BeZFHLhX.js → ganttDiagram-NO4QXBWP-CLqVFiRj.js} +1 -1
- package/dist/gui/assets/{gitGraphDiagram-IHSO6WYX-C0siPGLA.js → gitGraphDiagram-IHSO6WYX-BCeVlEhg.js} +1 -1
- package/dist/gui/assets/index-BCf1jTQa.css +1 -0
- package/dist/gui/assets/index-BYq7_4Z-.js +663 -0
- package/dist/gui/assets/{infoDiagram-FWYZ7A6U-Bk8DNKgG.js → infoDiagram-FWYZ7A6U-CaGDhrD8.js} +1 -1
- package/dist/gui/assets/{ishikawaDiagram-FXEZZL3T-DyS4wmJu.js → ishikawaDiagram-FXEZZL3T-D-IBVo_N.js} +1 -1
- package/dist/gui/assets/{journeyDiagram-5HDEW3XC-4jUY7Bzi.js → journeyDiagram-5HDEW3XC-lxFR0Z8q.js} +1 -1
- package/dist/gui/assets/{kanban-definition-HUTT4EX6-BRiI4KbM.js → kanban-definition-HUTT4EX6-C1Quf86J.js} +1 -1
- package/dist/gui/assets/{linear-C5JkbjyJ.js → linear-BmiZLs2L.js} +1 -1
- package/dist/gui/assets/{mermaid.core-ImB_5gdE.js → mermaid.core-Qqp0pI8e.js} +4 -4
- package/dist/gui/assets/{mindmap-definition-LN4V7U3C-9_Awmd2W.js → mindmap-definition-LN4V7U3C-CiuAQSSr.js} +1 -1
- package/dist/gui/assets/{pegDiagram-2B236MQR-DF_vIYzp.js → pegDiagram-2B236MQR-BWjeZxVp.js} +1 -1
- package/dist/gui/assets/{pieDiagram-ENE6RG2P-3TPwXSjQ.js → pieDiagram-ENE6RG2P-C2aubU3s.js} +1 -1
- package/dist/gui/assets/{quadrantDiagram-ABIIQ3AL-jzJ30mNi.js → quadrantDiagram-ABIIQ3AL-l-nU_0aa.js} +1 -1
- package/dist/gui/assets/{railroadDiagram-RFXS5EU6-B-29q3CI.js → railroadDiagram-RFXS5EU6-CLs3ePNd.js} +1 -1
- package/dist/gui/assets/{requirementDiagram-TGXJPOKE-BanWpS6g.js → requirementDiagram-TGXJPOKE-noC5_aOI.js} +1 -1
- package/dist/gui/assets/{sankeyDiagram-HTMAVEWB-B_sxc9IV.js → sankeyDiagram-HTMAVEWB-CrVWROCY.js} +1 -1
- package/dist/gui/assets/{sequenceDiagram-DBY2YBRQ-BNVav9DA.js → sequenceDiagram-DBY2YBRQ-rrdT6eIu.js} +1 -1
- package/dist/gui/assets/{sizeCapture-X5ZJPWSS-DbaiKjno.js → sizeCapture-X5ZJPWSS-DvpoOhEJ.js} +1 -1
- package/dist/gui/assets/{stateDiagram-2N3HPSRC-jU5WBm6c.js → stateDiagram-2N3HPSRC-B2ui4ZZN.js} +1 -1
- package/dist/gui/assets/stateDiagram-v2-6OUMAXLB-B_Wcpq2b.js +1 -0
- package/dist/gui/assets/{swimlanes-5IMT3BWC-Dcmb64x2.js → swimlanes-5IMT3BWC-DRhf5jKL.js} +2 -2
- package/dist/gui/assets/swimlanesDiagram-G3AALYLV-C2fsQgny.js +8 -0
- package/dist/gui/assets/{timeline-definition-FHXFAJF6-COm9ow7j.js → timeline-definition-FHXFAJF6-rm68zqM2.js} +1 -1
- package/dist/gui/assets/{vennDiagram-L72KCM5P-DliDuTVY.js → vennDiagram-L72KCM5P-BKVMfPvL.js} +1 -1
- package/dist/gui/assets/{wardleyDiagram-EHGQE667-C2O_2cpw.js → wardleyDiagram-EHGQE667-eXN3NRZ7.js} +1 -1
- package/dist/gui/assets/{xychartDiagram-FW5EYKEG-Ldmt9hoc.js → xychartDiagram-FW5EYKEG-3VtYytF2.js} +1 -1
- package/dist/gui/index.html +2 -2
- package/package.json +13 -1
- package/dist/_commonjsHelpers-DyI1JsEH.js +0 -34
- package/dist/abnfDiagram-VRR7QNED-UQS77aUi.js +0 -119
- package/dist/api-DrYc_Ds_.js +0 -129852
- package/dist/arc-B1cAL3U1.js +0 -132
- package/dist/architectureDiagram-ZJ3FMSHR-CfWOhs-q.js +0 -8816
- package/dist/blockDiagram-677ZJIJ3-CLOAAFZa.js +0 -3796
- package/dist/c4Diagram-LMCZKHZV-BGdELGkb.js +0 -2483
- package/dist/certs-BeimSwB3.js +0 -14071
- package/dist/certs-C4t5lAmJ.js +0 -14071
- package/dist/certs-CLLngjpY.js +0 -14071
- package/dist/certs-D3fTB-0_.js +0 -14071
- package/dist/channel-_gQD3mZ8.js +0 -8
- package/dist/chunk-2Q5K7J3B-DIJkMPWD.js +0 -20
- package/dist/chunk-32BRIVSS-CIQb7-9I.js +0 -117
- package/dist/chunk-5VM5RSS4-DmlAsh6o.js +0 -20
- package/dist/chunk-EX3LRPZG-BEXyn5R-.js +0 -1989
- package/dist/chunk-JWPE2WC7-XiIefccF.js +0 -17
- package/dist/chunk-MOJQB5TN-CC5OBDWw.js +0 -861
- package/dist/chunk-RYQCIY6F-DQacsGpB.js +0 -475
- package/dist/chunk-V7JOEXUC-TLRsIUvf.js +0 -2027
- package/dist/chunk-VR4S4FIN-9AfN7RDF.js +0 -25
- package/dist/chunk-XXDRQBXY-DhWucSRr.js +0 -14
- package/dist/classDiagram-OUVF2IWQ-CN55rRkB.js +0 -20
- package/dist/classDiagram-v2-EOCWNBFH-CN55rRkB.js +0 -20
- package/dist/cose-bilkent-JH36ORCC-8uGYe6_d.js +0 -4944
- package/dist/cynefin-VYW2F7L2-BwTeE-TI.js +0 -32061
- package/dist/cynefinDiagram-TSTJHNR4-DM7ixE-v.js +0 -454
- package/dist/cytoscape.esm-BTopYfIb.js +0 -30347
- package/dist/dagre-VKFMJZFB-blEDoYen.js +0 -522
- package/dist/defaultLocale-wHUL1xE2.js +0 -207
- package/dist/diagram-FQU43EPY-MEZlmmdi.js +0 -633
- package/dist/diagram-G47NLZAW-DZOZvHqp.js +0 -857
- package/dist/diagram-NH7WQ7WH-ChpmPbZz.js +0 -213
- package/dist/diagram-OA4YK3LP-oy4yvrnL.js +0 -489
- package/dist/diagram-WEI45ONY-B3nx1cYt.js +0 -305
- package/dist/ebnfDiagram-CCIWWBDH-BASj7BoO.js +0 -139
- package/dist/erDiagram-Q63AITRT-lujHq-S9.js +0 -1239
- package/dist/flowDiagram-23GEKE2U-BdsAVPgU.js +0 -2349
- package/dist/ganttDiagram-NO4QXBWP-DUUP4lsu.js +0 -3733
- package/dist/gitGraphDiagram-IHSO6WYX-BdIPAtb0.js +0 -1374
- package/dist/graph-CE8jV7cI.js +0 -2043
- package/dist/gui/assets/channel-DGoXAS0B.js +0 -1
- package/dist/gui/assets/classDiagram-OUVF2IWQ-B4zeZ0PC.js +0 -1
- package/dist/gui/assets/classDiagram-v2-EOCWNBFH-B4zeZ0PC.js +0 -1
- package/dist/gui/assets/index-Bp9JnkhK.css +0 -1
- package/dist/gui/assets/index-DKVgyltQ.js +0 -21
- package/dist/gui/assets/stateDiagram-v2-6OUMAXLB-GXq_r-DG.js +0 -1
- package/dist/gui/assets/swimlanesDiagram-G3AALYLV-DDE-INgq.js +0 -8
- package/dist/index--GoVvfUP.js +0 -5447
- package/dist/index-3-WDiDAh.js +0 -5466
- package/dist/index-CHBXZAxg.js +0 -5460
- package/dist/index-DeCq8xn7.js +0 -5460
- package/dist/infoDiagram-FWYZ7A6U-D9wo93kg.js +0 -32
- package/dist/init-DDGa2CQM.js +0 -17
- package/dist/ishikawaDiagram-FXEZZL3T-DZh3_kt2.js +0 -968
- package/dist/journeyDiagram-5HDEW3XC-C8RWHIn0.js +0 -1256
- package/dist/kanban-definition-HUTT4EX6-B7qQtB5a.js +0 -1053
- package/dist/katex-WjDlQEfU.js +0 -14500
- package/dist/layout-DQAYh_L7.js +0 -2360
- package/dist/linear-C_kZRZXS.js +0 -341
- package/dist/map-BElV7BMC.js +0 -299
- package/dist/mermaid.core-Dy_tFRs7.js +0 -26495
- package/dist/mindmap-definition-LN4V7U3C-BzHCd5Ab.js +0 -1181
- package/dist/ordinal-C2kkg180.js +0 -77
- package/dist/pegDiagram-2B236MQR-B046bQWM.js +0 -127
- package/dist/pieDiagram-ENE6RG2P-B5_W2CZy.js +0 -316
- package/dist/quadrantDiagram-ABIIQ3AL-Bbpt496h.js +0 -1342
- package/dist/railroadDiagram-RFXS5EU6-10XIH3X0.js +0 -93
- package/dist/requirementDiagram-TGXJPOKE-Dt1QyccY.js +0 -1205
- package/dist/sankeyDiagram-HTMAVEWB-CnqRAq7M.js +0 -1274
- package/dist/sequenceDiagram-DBY2YBRQ-DtJLSXoz.js +0 -4515
- package/dist/sizeCapture-X5ZJPWSS-DUl5ZEo3.js +0 -63
- package/dist/stateDiagram-2N3HPSRC-b-qzcVNj.js +0 -449
- package/dist/stateDiagram-v2-6OUMAXLB-KjDlRfc7.js +0 -20
- package/dist/swimlanes-5IMT3BWC-CAjGnQLa.js +0 -8553
- package/dist/swimlanesDiagram-G3AALYLV-DiOi9bzU.js +0 -16
- package/dist/timeline-definition-FHXFAJF6-Bme2FWbh.js +0 -1597
- package/dist/vennDiagram-L72KCM5P-BUQgnZDB.js +0 -2516
- package/dist/wardleyDiagram-EHGQE667-DHR2Avlu.js +0 -976
- package/dist/xychartDiagram-FW5EYKEG-V4K5eBMS.js +0 -2000
|
@@ -1,861 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { _ as __name, l as log, D as selectSvgElement, y as getConfig, p as clear, E as getThemeVariables3, e as configureSvgSize, i as sanitizeText, c as getConfig2 } from "./mermaid.core-Dy_tFRs7.js";
|
|
3
|
-
var diagramTitle = "";
|
|
4
|
-
var accTitle = "";
|
|
5
|
-
var accDescription = "";
|
|
6
|
-
var rules = [];
|
|
7
|
-
var ruleMap = /* @__PURE__ */ new Map();
|
|
8
|
-
var sanitizeText2 = /* @__PURE__ */ __name((text) => {
|
|
9
|
-
return sanitizeText(text, getConfig2());
|
|
10
|
-
}, "sanitizeText");
|
|
11
|
-
var sanitizeAstNode = /* @__PURE__ */ __name((node) => {
|
|
12
|
-
switch (node.type) {
|
|
13
|
-
case "terminal":
|
|
14
|
-
return { ...node, value: sanitizeText2(node.value) };
|
|
15
|
-
case "nonterminal":
|
|
16
|
-
return { ...node, name: sanitizeText2(node.name) };
|
|
17
|
-
case "sequence":
|
|
18
|
-
return { ...node, elements: node.elements.map(sanitizeAstNode) };
|
|
19
|
-
case "choice":
|
|
20
|
-
return { ...node, alternatives: node.alternatives.map(sanitizeAstNode) };
|
|
21
|
-
case "optional":
|
|
22
|
-
return { ...node, element: sanitizeAstNode(node.element) };
|
|
23
|
-
case "repetition":
|
|
24
|
-
return {
|
|
25
|
-
...node,
|
|
26
|
-
element: sanitizeAstNode(node.element),
|
|
27
|
-
separator: node.separator ? sanitizeAstNode(node.separator) : void 0
|
|
28
|
-
};
|
|
29
|
-
case "special":
|
|
30
|
-
return { ...node, text: sanitizeText2(node.text) };
|
|
31
|
-
}
|
|
32
|
-
}, "sanitizeAstNode");
|
|
33
|
-
var clear2 = /* @__PURE__ */ __name(() => {
|
|
34
|
-
diagramTitle = "";
|
|
35
|
-
accTitle = "";
|
|
36
|
-
accDescription = "";
|
|
37
|
-
rules.length = 0;
|
|
38
|
-
ruleMap.clear();
|
|
39
|
-
clear();
|
|
40
|
-
log.debug("[Railroad] Database cleared");
|
|
41
|
-
}, "clear");
|
|
42
|
-
var setTitle = /* @__PURE__ */ __name((text) => {
|
|
43
|
-
diagramTitle = sanitizeText2(text);
|
|
44
|
-
log.debug("[Railroad] Title set:", text);
|
|
45
|
-
}, "setTitle");
|
|
46
|
-
var getTitle = /* @__PURE__ */ __name(() => {
|
|
47
|
-
return diagramTitle;
|
|
48
|
-
}, "getTitle");
|
|
49
|
-
var addRule = /* @__PURE__ */ __name((rule) => {
|
|
50
|
-
const sanitizedRule = {
|
|
51
|
-
...rule,
|
|
52
|
-
name: sanitizeText2(rule.name),
|
|
53
|
-
definition: sanitizeAstNode(rule.definition),
|
|
54
|
-
comment: rule.comment ? sanitizeText2(rule.comment) : void 0
|
|
55
|
-
};
|
|
56
|
-
log.debug("[Railroad] Adding rule:", sanitizedRule.name);
|
|
57
|
-
if (ruleMap.has(sanitizedRule.name)) {
|
|
58
|
-
log.warn(`[Railroad] Rule '${sanitizedRule.name}' is already defined. Overwriting.`);
|
|
59
|
-
}
|
|
60
|
-
rules.push(sanitizedRule);
|
|
61
|
-
ruleMap.set(sanitizedRule.name, sanitizedRule);
|
|
62
|
-
}, "addRule");
|
|
63
|
-
var getRules = /* @__PURE__ */ __name(() => {
|
|
64
|
-
return rules;
|
|
65
|
-
}, "getRules");
|
|
66
|
-
var getRule = /* @__PURE__ */ __name((name) => {
|
|
67
|
-
return ruleMap.get(name);
|
|
68
|
-
}, "getRule");
|
|
69
|
-
var setAccTitle = /* @__PURE__ */ __name((text) => {
|
|
70
|
-
accTitle = sanitizeText2(text).replace(/^\s+/g, "");
|
|
71
|
-
log.debug("[Railroad] Accessibility title set:", text);
|
|
72
|
-
}, "setAccTitle");
|
|
73
|
-
var getAccTitle = /* @__PURE__ */ __name(() => {
|
|
74
|
-
return accTitle;
|
|
75
|
-
}, "getAccTitle");
|
|
76
|
-
var setAccDescription = /* @__PURE__ */ __name((text) => {
|
|
77
|
-
accDescription = sanitizeText2(text).replace(/\n\s+/g, "\n");
|
|
78
|
-
log.debug("[Railroad] Accessibility description set:", text);
|
|
79
|
-
}, "setAccDescription");
|
|
80
|
-
var getAccDescription = /* @__PURE__ */ __name(() => {
|
|
81
|
-
return accDescription;
|
|
82
|
-
}, "getAccDescription");
|
|
83
|
-
var setDiagramTitle = setTitle;
|
|
84
|
-
var getDiagramTitle = getTitle;
|
|
85
|
-
var db = {
|
|
86
|
-
clear: clear2,
|
|
87
|
-
setTitle,
|
|
88
|
-
getTitle,
|
|
89
|
-
addRule,
|
|
90
|
-
getRules,
|
|
91
|
-
getRule,
|
|
92
|
-
setAccTitle,
|
|
93
|
-
getAccTitle,
|
|
94
|
-
setAccDescription,
|
|
95
|
-
getAccDescription,
|
|
96
|
-
setDiagramTitle,
|
|
97
|
-
getDiagramTitle
|
|
98
|
-
};
|
|
99
|
-
var DEFAULT_RAILROAD_CONFIG = {
|
|
100
|
-
// Layout
|
|
101
|
-
compactMode: false,
|
|
102
|
-
// Spacing
|
|
103
|
-
padding: 10,
|
|
104
|
-
verticalSeparation: 8,
|
|
105
|
-
horizontalSeparation: 10,
|
|
106
|
-
arcRadius: 10,
|
|
107
|
-
// Typography
|
|
108
|
-
fontSize: 14,
|
|
109
|
-
fontFamily: "monospace",
|
|
110
|
-
// Colors - Terminal
|
|
111
|
-
terminalFill: "#FFFFC0",
|
|
112
|
-
terminalStroke: "#000000",
|
|
113
|
-
terminalTextColor: "#000000",
|
|
114
|
-
// Colors - Non-terminal
|
|
115
|
-
nonTerminalFill: "#FFFFFF",
|
|
116
|
-
nonTerminalStroke: "#000000",
|
|
117
|
-
nonTerminalTextColor: "#000000",
|
|
118
|
-
// Colors - Lines
|
|
119
|
-
lineColor: "#000000",
|
|
120
|
-
strokeWidth: 2,
|
|
121
|
-
// Colors - Markers
|
|
122
|
-
markerFill: "#000000",
|
|
123
|
-
// Colors - Comment
|
|
124
|
-
commentFill: "#E8E8E8",
|
|
125
|
-
commentStroke: "#888888",
|
|
126
|
-
commentTextColor: "#666666",
|
|
127
|
-
// Colors - Special
|
|
128
|
-
specialFill: "#F0E0FF",
|
|
129
|
-
specialStroke: "#8800CC",
|
|
130
|
-
// Other
|
|
131
|
-
ruleNameColor: "#000066",
|
|
132
|
-
showMarkers: true,
|
|
133
|
-
markerRadius: 5
|
|
134
|
-
};
|
|
135
|
-
var COLOR_VALUE_PATTERN = /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$|^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch)\([\d\s%+,./-]+\)$|^[a-z]+$/i;
|
|
136
|
-
var FONT_FAMILY_PATTERN = /^[\w "',.-]+$/;
|
|
137
|
-
var RAILROAD_STYLE_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
138
|
-
"compactMode",
|
|
139
|
-
"padding",
|
|
140
|
-
"verticalSeparation",
|
|
141
|
-
"horizontalSeparation",
|
|
142
|
-
"arcRadius",
|
|
143
|
-
"fontSize",
|
|
144
|
-
"fontFamily",
|
|
145
|
-
"terminalFill",
|
|
146
|
-
"terminalStroke",
|
|
147
|
-
"terminalTextColor",
|
|
148
|
-
"nonTerminalFill",
|
|
149
|
-
"nonTerminalStroke",
|
|
150
|
-
"nonTerminalTextColor",
|
|
151
|
-
"lineColor",
|
|
152
|
-
"strokeWidth",
|
|
153
|
-
"markerFill",
|
|
154
|
-
"commentFill",
|
|
155
|
-
"commentStroke",
|
|
156
|
-
"commentTextColor",
|
|
157
|
-
"specialFill",
|
|
158
|
-
"specialStroke",
|
|
159
|
-
"ruleNameColor",
|
|
160
|
-
"showMarkers",
|
|
161
|
-
"markerRadius"
|
|
162
|
-
]);
|
|
163
|
-
var isRailroadStyleOptions = /* @__PURE__ */ __name((options) => {
|
|
164
|
-
if (!options) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
return Object.keys(options).every(
|
|
168
|
-
(key) => key === "railroad" || RAILROAD_STYLE_OPTION_KEYS.has(key)
|
|
169
|
-
);
|
|
170
|
-
}, "isRailroadStyleOptions");
|
|
171
|
-
var extractRailroadOverrides = /* @__PURE__ */ __name((options) => {
|
|
172
|
-
if (!options) {
|
|
173
|
-
return {};
|
|
174
|
-
}
|
|
175
|
-
if ("railroad" in options && options.railroad) {
|
|
176
|
-
return options.railroad;
|
|
177
|
-
}
|
|
178
|
-
return isRailroadStyleOptions(options) ? options : {};
|
|
179
|
-
}, "extractRailroadOverrides");
|
|
180
|
-
var extractThemeOverrides = /* @__PURE__ */ __name((options) => {
|
|
181
|
-
if (!options || isRailroadStyleOptions(options)) {
|
|
182
|
-
return {};
|
|
183
|
-
}
|
|
184
|
-
const {
|
|
185
|
-
railroad: _railroad,
|
|
186
|
-
svgId: _svgId,
|
|
187
|
-
theme: _theme,
|
|
188
|
-
look: _look,
|
|
189
|
-
...themeOverrides
|
|
190
|
-
} = options;
|
|
191
|
-
return themeOverrides;
|
|
192
|
-
}, "extractThemeOverrides");
|
|
193
|
-
var sanitizeColorValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
194
|
-
if (typeof value !== "string") {
|
|
195
|
-
return fallback;
|
|
196
|
-
}
|
|
197
|
-
const normalized = value.trim();
|
|
198
|
-
return COLOR_VALUE_PATTERN.test(normalized) ? normalized : fallback;
|
|
199
|
-
}, "sanitizeColorValue");
|
|
200
|
-
var sanitizeFontFamilyValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
201
|
-
if (typeof value !== "string") {
|
|
202
|
-
return fallback;
|
|
203
|
-
}
|
|
204
|
-
const normalized = value.trim();
|
|
205
|
-
return FONT_FAMILY_PATTERN.test(normalized) ? normalized : fallback;
|
|
206
|
-
}, "sanitizeFontFamilyValue");
|
|
207
|
-
var sanitizeNumberValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
208
|
-
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : Number.NaN;
|
|
209
|
-
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
210
|
-
}, "sanitizeNumberValue");
|
|
211
|
-
var parseThemeFontSize = /* @__PURE__ */ __name((value) => {
|
|
212
|
-
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : Number.NaN;
|
|
213
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
|
|
214
|
-
}, "parseThemeFontSize");
|
|
215
|
-
var buildThemeDefaults = /* @__PURE__ */ __name((themeVariables) => {
|
|
216
|
-
const fontFamily = sanitizeFontFamilyValue(
|
|
217
|
-
themeVariables.fontFamily,
|
|
218
|
-
DEFAULT_RAILROAD_CONFIG.fontFamily
|
|
219
|
-
);
|
|
220
|
-
const fontSize = parseThemeFontSize(themeVariables.fontSize) ?? DEFAULT_RAILROAD_CONFIG.fontSize;
|
|
221
|
-
return {
|
|
222
|
-
...DEFAULT_RAILROAD_CONFIG,
|
|
223
|
-
fontFamily,
|
|
224
|
-
fontSize,
|
|
225
|
-
terminalFill: sanitizeColorValue(
|
|
226
|
-
themeVariables.secondBkg ?? themeVariables.secondaryColor,
|
|
227
|
-
DEFAULT_RAILROAD_CONFIG.terminalFill
|
|
228
|
-
),
|
|
229
|
-
terminalStroke: sanitizeColorValue(
|
|
230
|
-
themeVariables.secondaryBorderColor ?? themeVariables.lineColor,
|
|
231
|
-
DEFAULT_RAILROAD_CONFIG.terminalStroke
|
|
232
|
-
),
|
|
233
|
-
terminalTextColor: sanitizeColorValue(
|
|
234
|
-
themeVariables.secondaryTextColor ?? themeVariables.textColor,
|
|
235
|
-
DEFAULT_RAILROAD_CONFIG.terminalTextColor
|
|
236
|
-
),
|
|
237
|
-
nonTerminalFill: sanitizeColorValue(
|
|
238
|
-
themeVariables.mainBkg ?? themeVariables.background,
|
|
239
|
-
DEFAULT_RAILROAD_CONFIG.nonTerminalFill
|
|
240
|
-
),
|
|
241
|
-
nonTerminalStroke: sanitizeColorValue(
|
|
242
|
-
themeVariables.primaryBorderColor ?? themeVariables.lineColor,
|
|
243
|
-
DEFAULT_RAILROAD_CONFIG.nonTerminalStroke
|
|
244
|
-
),
|
|
245
|
-
nonTerminalTextColor: sanitizeColorValue(
|
|
246
|
-
themeVariables.primaryTextColor ?? themeVariables.textColor,
|
|
247
|
-
DEFAULT_RAILROAD_CONFIG.nonTerminalTextColor
|
|
248
|
-
),
|
|
249
|
-
lineColor: sanitizeColorValue(themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.lineColor),
|
|
250
|
-
markerFill: sanitizeColorValue(themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.markerFill),
|
|
251
|
-
commentFill: sanitizeColorValue(
|
|
252
|
-
themeVariables.labelBackground ?? themeVariables.tertiaryColor,
|
|
253
|
-
DEFAULT_RAILROAD_CONFIG.commentFill
|
|
254
|
-
),
|
|
255
|
-
commentStroke: sanitizeColorValue(
|
|
256
|
-
themeVariables.tertiaryBorderColor ?? themeVariables.lineColor,
|
|
257
|
-
DEFAULT_RAILROAD_CONFIG.commentStroke
|
|
258
|
-
),
|
|
259
|
-
commentTextColor: sanitizeColorValue(
|
|
260
|
-
themeVariables.tertiaryTextColor ?? themeVariables.textColor,
|
|
261
|
-
DEFAULT_RAILROAD_CONFIG.commentTextColor
|
|
262
|
-
),
|
|
263
|
-
specialFill: sanitizeColorValue(
|
|
264
|
-
themeVariables.tertiaryColor ?? themeVariables.secondaryColor,
|
|
265
|
-
DEFAULT_RAILROAD_CONFIG.specialFill
|
|
266
|
-
),
|
|
267
|
-
specialStroke: sanitizeColorValue(
|
|
268
|
-
themeVariables.tertiaryBorderColor ?? themeVariables.secondaryBorderColor,
|
|
269
|
-
DEFAULT_RAILROAD_CONFIG.specialStroke
|
|
270
|
-
),
|
|
271
|
-
ruleNameColor: sanitizeColorValue(
|
|
272
|
-
themeVariables.titleColor ?? themeVariables.textColor,
|
|
273
|
-
DEFAULT_RAILROAD_CONFIG.ruleNameColor
|
|
274
|
-
)
|
|
275
|
-
};
|
|
276
|
-
}, "buildThemeDefaults");
|
|
277
|
-
var buildRailroadStyleOptions = /* @__PURE__ */ __name((options) => {
|
|
278
|
-
const currentConfig = getConfig();
|
|
279
|
-
const themeVariables = {
|
|
280
|
-
...getThemeVariables3(),
|
|
281
|
-
...currentConfig.themeVariables ?? {},
|
|
282
|
-
...extractThemeOverrides(options)
|
|
283
|
-
};
|
|
284
|
-
const themeDefaults = buildThemeDefaults(themeVariables);
|
|
285
|
-
const railroadOptions = {
|
|
286
|
-
...currentConfig.railroad ?? {},
|
|
287
|
-
...extractRailroadOverrides(options)
|
|
288
|
-
};
|
|
289
|
-
return {
|
|
290
|
-
compactMode: railroadOptions.compactMode ?? themeDefaults.compactMode,
|
|
291
|
-
padding: sanitizeNumberValue(railroadOptions.padding, themeDefaults.padding),
|
|
292
|
-
verticalSeparation: sanitizeNumberValue(
|
|
293
|
-
railroadOptions.verticalSeparation,
|
|
294
|
-
themeDefaults.verticalSeparation
|
|
295
|
-
),
|
|
296
|
-
horizontalSeparation: sanitizeNumberValue(
|
|
297
|
-
railroadOptions.horizontalSeparation,
|
|
298
|
-
themeDefaults.horizontalSeparation
|
|
299
|
-
),
|
|
300
|
-
arcRadius: sanitizeNumberValue(railroadOptions.arcRadius, themeDefaults.arcRadius),
|
|
301
|
-
fontSize: sanitizeNumberValue(railroadOptions.fontSize, themeDefaults.fontSize),
|
|
302
|
-
fontFamily: sanitizeFontFamilyValue(railroadOptions.fontFamily, themeDefaults.fontFamily),
|
|
303
|
-
terminalFill: sanitizeColorValue(railroadOptions.terminalFill, themeDefaults.terminalFill),
|
|
304
|
-
terminalStroke: sanitizeColorValue(
|
|
305
|
-
railroadOptions.terminalStroke,
|
|
306
|
-
themeDefaults.terminalStroke
|
|
307
|
-
),
|
|
308
|
-
terminalTextColor: sanitizeColorValue(
|
|
309
|
-
railroadOptions.terminalTextColor,
|
|
310
|
-
themeDefaults.terminalTextColor
|
|
311
|
-
),
|
|
312
|
-
nonTerminalFill: sanitizeColorValue(
|
|
313
|
-
railroadOptions.nonTerminalFill,
|
|
314
|
-
themeDefaults.nonTerminalFill
|
|
315
|
-
),
|
|
316
|
-
nonTerminalStroke: sanitizeColorValue(
|
|
317
|
-
railroadOptions.nonTerminalStroke,
|
|
318
|
-
themeDefaults.nonTerminalStroke
|
|
319
|
-
),
|
|
320
|
-
nonTerminalTextColor: sanitizeColorValue(
|
|
321
|
-
railroadOptions.nonTerminalTextColor,
|
|
322
|
-
themeDefaults.nonTerminalTextColor
|
|
323
|
-
),
|
|
324
|
-
lineColor: sanitizeColorValue(railroadOptions.lineColor, themeDefaults.lineColor),
|
|
325
|
-
strokeWidth: sanitizeNumberValue(railroadOptions.strokeWidth, themeDefaults.strokeWidth),
|
|
326
|
-
markerFill: sanitizeColorValue(railroadOptions.markerFill, themeDefaults.markerFill),
|
|
327
|
-
commentFill: sanitizeColorValue(railroadOptions.commentFill, themeDefaults.commentFill),
|
|
328
|
-
commentStroke: sanitizeColorValue(railroadOptions.commentStroke, themeDefaults.commentStroke),
|
|
329
|
-
commentTextColor: sanitizeColorValue(
|
|
330
|
-
railroadOptions.commentTextColor,
|
|
331
|
-
themeDefaults.commentTextColor
|
|
332
|
-
),
|
|
333
|
-
specialFill: sanitizeColorValue(railroadOptions.specialFill, themeDefaults.specialFill),
|
|
334
|
-
specialStroke: sanitizeColorValue(railroadOptions.specialStroke, themeDefaults.specialStroke),
|
|
335
|
-
ruleNameColor: sanitizeColorValue(railroadOptions.ruleNameColor, themeDefaults.ruleNameColor),
|
|
336
|
-
showMarkers: railroadOptions.showMarkers ?? themeDefaults.showMarkers,
|
|
337
|
-
markerRadius: sanitizeNumberValue(railroadOptions.markerRadius, themeDefaults.markerRadius)
|
|
338
|
-
};
|
|
339
|
-
}, "buildRailroadStyleOptions");
|
|
340
|
-
var getStyles = /* @__PURE__ */ __name((options) => {
|
|
341
|
-
const {
|
|
342
|
-
fontFamily,
|
|
343
|
-
fontSize,
|
|
344
|
-
terminalFill,
|
|
345
|
-
terminalStroke,
|
|
346
|
-
terminalTextColor,
|
|
347
|
-
nonTerminalFill,
|
|
348
|
-
nonTerminalStroke,
|
|
349
|
-
nonTerminalTextColor,
|
|
350
|
-
lineColor,
|
|
351
|
-
strokeWidth,
|
|
352
|
-
markerFill,
|
|
353
|
-
commentFill,
|
|
354
|
-
commentStroke,
|
|
355
|
-
commentTextColor,
|
|
356
|
-
specialFill,
|
|
357
|
-
specialStroke,
|
|
358
|
-
ruleNameColor
|
|
359
|
-
} = buildRailroadStyleOptions(options);
|
|
360
|
-
return `
|
|
361
|
-
.railroad-diagram {
|
|
362
|
-
font-family: ${fontFamily};
|
|
363
|
-
font-size: ${fontSize}px;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
.railroad-terminal rect {
|
|
367
|
-
fill: ${terminalFill};
|
|
368
|
-
stroke: ${terminalStroke};
|
|
369
|
-
stroke-width: ${strokeWidth}px;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
.railroad-terminal text {
|
|
373
|
-
fill: ${terminalTextColor};
|
|
374
|
-
font-family: ${fontFamily};
|
|
375
|
-
font-size: ${fontSize}px;
|
|
376
|
-
text-anchor: middle;
|
|
377
|
-
dominant-baseline: middle;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
.railroad-nonterminal rect {
|
|
381
|
-
fill: ${nonTerminalFill};
|
|
382
|
-
stroke: ${nonTerminalStroke};
|
|
383
|
-
stroke-width: ${strokeWidth}px;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
.railroad-nonterminal text {
|
|
387
|
-
fill: ${nonTerminalTextColor};
|
|
388
|
-
font-family: ${fontFamily};
|
|
389
|
-
font-size: ${fontSize}px;
|
|
390
|
-
text-anchor: middle;
|
|
391
|
-
dominant-baseline: middle;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
.railroad-line {
|
|
395
|
-
stroke: ${lineColor};
|
|
396
|
-
stroke-width: ${strokeWidth}px;
|
|
397
|
-
fill: none;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
.railroad-start circle,
|
|
401
|
-
.railroad-end circle {
|
|
402
|
-
fill: ${markerFill};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
.railroad-comment ellipse {
|
|
406
|
-
fill: ${commentFill};
|
|
407
|
-
stroke: ${commentStroke};
|
|
408
|
-
stroke-width: ${strokeWidth}px;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
.railroad-comment text {
|
|
412
|
-
fill: ${commentTextColor};
|
|
413
|
-
font-style: italic;
|
|
414
|
-
font-family: ${fontFamily};
|
|
415
|
-
font-size: ${fontSize}px;
|
|
416
|
-
text-anchor: middle;
|
|
417
|
-
dominant-baseline: middle;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
.railroad-special rect {
|
|
421
|
-
fill: ${specialFill};
|
|
422
|
-
stroke: ${specialStroke};
|
|
423
|
-
stroke-width: ${strokeWidth}px;
|
|
424
|
-
stroke-dasharray: 5,3;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
.railroad-special text {
|
|
428
|
-
fill: ${nonTerminalTextColor};
|
|
429
|
-
font-family: ${fontFamily};
|
|
430
|
-
font-size: ${fontSize}px;
|
|
431
|
-
text-anchor: middle;
|
|
432
|
-
dominant-baseline: middle;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
.railroad-rule-name {
|
|
436
|
-
font-weight: bold;
|
|
437
|
-
fill: ${ruleNameColor};
|
|
438
|
-
font-family: ${fontFamily};
|
|
439
|
-
font-size: ${fontSize}px;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
.railroad-group {
|
|
443
|
-
/* Grouping container, no specific styles */
|
|
444
|
-
}
|
|
445
|
-
`;
|
|
446
|
-
}, "getStyles");
|
|
447
|
-
var PathBuilder = class {
|
|
448
|
-
constructor() {
|
|
449
|
-
this.d = "";
|
|
450
|
-
}
|
|
451
|
-
static {
|
|
452
|
-
__name(this, "PathBuilder");
|
|
453
|
-
}
|
|
454
|
-
moveTo(x, y) {
|
|
455
|
-
this.d += `M ${x} ${y} `;
|
|
456
|
-
return this;
|
|
457
|
-
}
|
|
458
|
-
lineTo(x, y) {
|
|
459
|
-
this.d += `L ${x} ${y} `;
|
|
460
|
-
return this;
|
|
461
|
-
}
|
|
462
|
-
horizontalTo(x) {
|
|
463
|
-
this.d += `H ${x} `;
|
|
464
|
-
return this;
|
|
465
|
-
}
|
|
466
|
-
verticalTo(y) {
|
|
467
|
-
this.d += `V ${y} `;
|
|
468
|
-
return this;
|
|
469
|
-
}
|
|
470
|
-
arcTo(rx, ry, rotation, largeArc, sweep, x, y) {
|
|
471
|
-
this.d += `A ${rx} ${ry} ${rotation} ${largeArc ? 1 : 0} ${sweep ? 1 : 0} ${x} ${y} `;
|
|
472
|
-
return this;
|
|
473
|
-
}
|
|
474
|
-
build() {
|
|
475
|
-
return this.d.trim();
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
var RailroadRenderer = class {
|
|
479
|
-
constructor(svg, config = buildRailroadStyleOptions()) {
|
|
480
|
-
this.textCache = /* @__PURE__ */ new Map();
|
|
481
|
-
this.svg = svg;
|
|
482
|
-
this.config = config;
|
|
483
|
-
}
|
|
484
|
-
static {
|
|
485
|
-
__name(this, "RailroadRenderer");
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Measure text dimensions
|
|
489
|
-
*/
|
|
490
|
-
measureText(text) {
|
|
491
|
-
if (this.textCache.has(text)) {
|
|
492
|
-
return this.textCache.get(text);
|
|
493
|
-
}
|
|
494
|
-
const tempText = this.svg.append("text").attr("font-family", this.config.fontFamily).attr("font-size", this.config.fontSize).text(text);
|
|
495
|
-
const bbox = tempText.node().getBBox();
|
|
496
|
-
const dimensions = { width: bbox.width, height: bbox.height };
|
|
497
|
-
tempText.remove();
|
|
498
|
-
this.textCache.set(text, dimensions);
|
|
499
|
-
return dimensions;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Render terminal symbol (rounded rectangle)
|
|
503
|
-
*/
|
|
504
|
-
renderTerminal(parent, value) {
|
|
505
|
-
const textDim = this.measureText(value);
|
|
506
|
-
const width = textDim.width + this.config.padding * 2;
|
|
507
|
-
const height = textDim.height + this.config.padding * 2;
|
|
508
|
-
const group = parent.append("g").attr("class", "railroad-terminal");
|
|
509
|
-
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height).attr("rx", 10).attr("ry", 10);
|
|
510
|
-
group.append("text").attr("x", width / 2).attr("y", height / 2).text(value);
|
|
511
|
-
return {
|
|
512
|
-
element: group.node(),
|
|
513
|
-
dimensions: {
|
|
514
|
-
width,
|
|
515
|
-
height,
|
|
516
|
-
up: height / 2,
|
|
517
|
-
down: height / 2
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Render non-terminal symbol (rectangle)
|
|
523
|
-
*/
|
|
524
|
-
renderNonTerminal(parent, name) {
|
|
525
|
-
const textDim = this.measureText(name);
|
|
526
|
-
const width = textDim.width + this.config.padding * 2;
|
|
527
|
-
const height = textDim.height + this.config.padding * 2;
|
|
528
|
-
const group = parent.append("g").attr("class", "railroad-nonterminal");
|
|
529
|
-
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
530
|
-
group.append("text").attr("x", width / 2).attr("y", height / 2).text(name);
|
|
531
|
-
return {
|
|
532
|
-
element: group.node(),
|
|
533
|
-
dimensions: {
|
|
534
|
-
width,
|
|
535
|
-
height,
|
|
536
|
-
up: height / 2,
|
|
537
|
-
down: height / 2
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Render sequence (horizontal concatenation)
|
|
543
|
-
*/
|
|
544
|
-
renderSequence(parent, elements) {
|
|
545
|
-
const rendered = elements.map((e) => this.renderExpression(parent, e));
|
|
546
|
-
let totalWidth = 0;
|
|
547
|
-
let maxUp = 0;
|
|
548
|
-
let maxDown = 0;
|
|
549
|
-
for (const r of rendered) {
|
|
550
|
-
totalWidth += r.dimensions.width;
|
|
551
|
-
maxUp = Math.max(maxUp, r.dimensions.up);
|
|
552
|
-
maxDown = Math.max(maxDown, r.dimensions.down);
|
|
553
|
-
}
|
|
554
|
-
totalWidth += (rendered.length - 1) * this.config.horizontalSeparation;
|
|
555
|
-
const group = parent.append("g").attr("class", "railroad-sequence");
|
|
556
|
-
let x = 0;
|
|
557
|
-
for (let i = 0; i < rendered.length; i++) {
|
|
558
|
-
const r = rendered[i];
|
|
559
|
-
const y = maxUp - r.dimensions.up;
|
|
560
|
-
const elem = group.node().appendChild(r.element);
|
|
561
|
-
elem.setAttribute("transform", `translate(${x}, ${y})`);
|
|
562
|
-
if (i < rendered.length - 1) {
|
|
563
|
-
const lineX1 = x + r.dimensions.width;
|
|
564
|
-
const lineX2 = lineX1 + this.config.horizontalSeparation;
|
|
565
|
-
const lineY = maxUp;
|
|
566
|
-
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(lineX1, lineY).lineTo(lineX2, lineY).build());
|
|
567
|
-
}
|
|
568
|
-
x += r.dimensions.width + this.config.horizontalSeparation;
|
|
569
|
-
}
|
|
570
|
-
return {
|
|
571
|
-
element: group.node(),
|
|
572
|
-
dimensions: {
|
|
573
|
-
width: totalWidth,
|
|
574
|
-
height: maxUp + maxDown,
|
|
575
|
-
up: maxUp,
|
|
576
|
-
down: maxDown
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* Render choice (vertical alternatives)
|
|
582
|
-
*/
|
|
583
|
-
renderChoice(parent, alternatives) {
|
|
584
|
-
const rendered = alternatives.map((a) => this.renderExpression(parent, a));
|
|
585
|
-
let maxWidth = 0;
|
|
586
|
-
let totalHeight = 0;
|
|
587
|
-
for (const r of rendered) {
|
|
588
|
-
maxWidth = Math.max(maxWidth, r.dimensions.width);
|
|
589
|
-
totalHeight += r.dimensions.height;
|
|
590
|
-
}
|
|
591
|
-
totalHeight += (rendered.length - 1) * this.config.verticalSeparation;
|
|
592
|
-
const arcRadius = this.config.arcRadius;
|
|
593
|
-
const arcWidth = arcRadius * 4;
|
|
594
|
-
const totalWidth = maxWidth + arcWidth;
|
|
595
|
-
const group = parent.append("g").attr("class", "railroad-choice");
|
|
596
|
-
let y = 0;
|
|
597
|
-
const centerY = totalHeight / 2;
|
|
598
|
-
for (const r of rendered) {
|
|
599
|
-
const elemY = y;
|
|
600
|
-
const elemCenterY = elemY + r.dimensions.up;
|
|
601
|
-
const elemX = arcRadius * 2 + (maxWidth - r.dimensions.width) / 2;
|
|
602
|
-
const elem = group.node().appendChild(r.element);
|
|
603
|
-
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
604
|
-
const leftPath = new PathBuilder();
|
|
605
|
-
const isBelowCenter = elemCenterY > centerY;
|
|
606
|
-
if (elemCenterY === centerY) {
|
|
607
|
-
leftPath.moveTo(0, centerY).lineTo(elemX, elemCenterY);
|
|
608
|
-
} else {
|
|
609
|
-
leftPath.moveTo(0, centerY).arcTo(
|
|
610
|
-
arcRadius,
|
|
611
|
-
arcRadius,
|
|
612
|
-
0,
|
|
613
|
-
false,
|
|
614
|
-
isBelowCenter,
|
|
615
|
-
arcRadius,
|
|
616
|
-
centerY + (isBelowCenter ? arcRadius : -arcRadius)
|
|
617
|
-
).lineTo(arcRadius, elemCenterY - (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, !isBelowCenter, arcRadius * 2, elemCenterY).lineTo(elemX, elemCenterY);
|
|
618
|
-
}
|
|
619
|
-
group.append("path").attr("class", "railroad-line").attr("d", leftPath.build());
|
|
620
|
-
const rightPath = new PathBuilder();
|
|
621
|
-
const rightStart = elemX + r.dimensions.width;
|
|
622
|
-
const rightLaneX = totalWidth - arcRadius * 2;
|
|
623
|
-
if (elemCenterY === centerY) {
|
|
624
|
-
rightPath.moveTo(rightStart, elemCenterY).lineTo(totalWidth, centerY);
|
|
625
|
-
} else {
|
|
626
|
-
rightPath.moveTo(rightStart, elemCenterY).lineTo(rightLaneX, elemCenterY).arcTo(
|
|
627
|
-
arcRadius,
|
|
628
|
-
arcRadius,
|
|
629
|
-
0,
|
|
630
|
-
false,
|
|
631
|
-
!isBelowCenter,
|
|
632
|
-
totalWidth - arcRadius,
|
|
633
|
-
elemCenterY + (isBelowCenter ? -arcRadius : arcRadius)
|
|
634
|
-
).lineTo(totalWidth - arcRadius, centerY + (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, isBelowCenter, totalWidth, centerY);
|
|
635
|
-
}
|
|
636
|
-
group.append("path").attr("class", "railroad-line").attr("d", rightPath.build());
|
|
637
|
-
y += r.dimensions.height + this.config.verticalSeparation;
|
|
638
|
-
}
|
|
639
|
-
return {
|
|
640
|
-
element: group.node(),
|
|
641
|
-
dimensions: {
|
|
642
|
-
width: totalWidth,
|
|
643
|
-
height: totalHeight,
|
|
644
|
-
up: centerY,
|
|
645
|
-
down: totalHeight - centerY
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Render optional (bypass path above)
|
|
651
|
-
*/
|
|
652
|
-
renderOptional(parent, element) {
|
|
653
|
-
const inner = this.renderExpression(parent, element);
|
|
654
|
-
const arcRadius = this.config.arcRadius;
|
|
655
|
-
const arcHeight = arcRadius * 2;
|
|
656
|
-
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
657
|
-
const totalHeight = inner.dimensions.height + arcHeight;
|
|
658
|
-
const group = parent.append("g").attr("class", "railroad-optional");
|
|
659
|
-
const elemX = arcRadius * 2;
|
|
660
|
-
const elemY = arcHeight;
|
|
661
|
-
const elem = group.node().appendChild(inner.element);
|
|
662
|
-
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
663
|
-
const centerY = elemY + inner.dimensions.up;
|
|
664
|
-
const lowerPath = new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY);
|
|
665
|
-
group.append("path").attr("class", "railroad-line").attr("d", lowerPath.build());
|
|
666
|
-
const lowerPath2 = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY);
|
|
667
|
-
group.append("path").attr("class", "railroad-line").attr("d", lowerPath2.build());
|
|
668
|
-
const bypassPath = new PathBuilder().moveTo(0, centerY).arcTo(arcRadius, arcRadius, 0, false, false, arcRadius, centerY - arcRadius).lineTo(arcRadius, arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius * 2, 0).lineTo(totalWidth - arcRadius * 2, 0).arcTo(arcRadius, arcRadius, 0, false, true, totalWidth - arcRadius, arcRadius).lineTo(totalWidth - arcRadius, centerY - arcRadius).arcTo(arcRadius, arcRadius, 0, false, false, totalWidth, centerY);
|
|
669
|
-
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
670
|
-
return {
|
|
671
|
-
element: group.node(),
|
|
672
|
-
dimensions: {
|
|
673
|
-
width: totalWidth,
|
|
674
|
-
height: totalHeight,
|
|
675
|
-
up: centerY,
|
|
676
|
-
down: totalHeight - centerY
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
/**
|
|
681
|
-
* Render repetition (loop back path)
|
|
682
|
-
*/
|
|
683
|
-
renderRepetition(parent, element, min) {
|
|
684
|
-
const inner = this.renderExpression(parent, element);
|
|
685
|
-
const arcRadius = this.config.arcRadius;
|
|
686
|
-
const arcHeight = arcRadius * 2;
|
|
687
|
-
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
688
|
-
const hasBypass = min === 0;
|
|
689
|
-
const totalHeight = inner.dimensions.height + arcHeight + (hasBypass ? arcHeight : 0);
|
|
690
|
-
const group = parent.append("g").attr("class", "railroad-repetition");
|
|
691
|
-
const elemX = arcRadius * 2;
|
|
692
|
-
const elemY = hasBypass ? arcHeight : 0;
|
|
693
|
-
const elem = group.node().appendChild(inner.element);
|
|
694
|
-
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
695
|
-
const centerY = elemY + inner.dimensions.up;
|
|
696
|
-
group.append("path").attr("class", "railroad-line").attr(
|
|
697
|
-
"d",
|
|
698
|
-
new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY).build()
|
|
699
|
-
);
|
|
700
|
-
group.append("path").attr("class", "railroad-line").attr(
|
|
701
|
-
"d",
|
|
702
|
-
new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY).build()
|
|
703
|
-
);
|
|
704
|
-
const loopY = elemY + inner.dimensions.height + arcRadius;
|
|
705
|
-
const loopPath = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).arcTo(
|
|
706
|
-
arcRadius,
|
|
707
|
-
arcRadius,
|
|
708
|
-
0,
|
|
709
|
-
false,
|
|
710
|
-
true,
|
|
711
|
-
elemX + inner.dimensions.width + arcRadius,
|
|
712
|
-
centerY + arcRadius
|
|
713
|
-
).lineTo(elemX + inner.dimensions.width + arcRadius, loopY).arcTo(
|
|
714
|
-
arcRadius,
|
|
715
|
-
arcRadius,
|
|
716
|
-
0,
|
|
717
|
-
false,
|
|
718
|
-
true,
|
|
719
|
-
elemX + inner.dimensions.width,
|
|
720
|
-
loopY + arcRadius
|
|
721
|
-
).lineTo(arcRadius * 2, loopY + arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius, loopY).lineTo(arcRadius, centerY + arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius * 2, centerY);
|
|
722
|
-
group.append("path").attr("class", "railroad-line").attr("d", loopPath.build());
|
|
723
|
-
if (hasBypass) {
|
|
724
|
-
const bypassPath = new PathBuilder().moveTo(0, centerY).arcTo(arcRadius, arcRadius, 0, false, false, arcRadius, centerY - arcRadius).lineTo(arcRadius, arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius * 2, 0).lineTo(totalWidth - arcRadius * 2, 0).arcTo(arcRadius, arcRadius, 0, false, true, totalWidth - arcRadius, arcRadius).lineTo(totalWidth - arcRadius, centerY - arcRadius).arcTo(arcRadius, arcRadius, 0, false, false, totalWidth, centerY);
|
|
725
|
-
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
726
|
-
}
|
|
727
|
-
return {
|
|
728
|
-
element: group.node(),
|
|
729
|
-
dimensions: {
|
|
730
|
-
width: totalWidth,
|
|
731
|
-
height: totalHeight,
|
|
732
|
-
up: centerY,
|
|
733
|
-
down: totalHeight - centerY
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Render special sequence
|
|
739
|
-
*/
|
|
740
|
-
renderSpecial(parent, text) {
|
|
741
|
-
const textDim = this.measureText("? " + text + " ?");
|
|
742
|
-
const width = textDim.width + this.config.padding * 2;
|
|
743
|
-
const height = textDim.height + this.config.padding * 2;
|
|
744
|
-
const group = parent.append("g").attr("class", "railroad-special");
|
|
745
|
-
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
746
|
-
group.append("text").attr("x", width / 2).attr("y", height / 2).text("? " + text + " ?");
|
|
747
|
-
return {
|
|
748
|
-
element: group.node(),
|
|
749
|
-
dimensions: {
|
|
750
|
-
width,
|
|
751
|
-
height,
|
|
752
|
-
up: height / 2,
|
|
753
|
-
down: height / 2
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Render an expression (recursive)
|
|
759
|
-
*/
|
|
760
|
-
renderExpression(parent, node) {
|
|
761
|
-
switch (node.type) {
|
|
762
|
-
case "terminal":
|
|
763
|
-
return this.renderTerminal(parent, node.value);
|
|
764
|
-
case "nonterminal":
|
|
765
|
-
return this.renderNonTerminal(parent, node.name);
|
|
766
|
-
case "sequence":
|
|
767
|
-
return this.renderSequence(parent, node.elements);
|
|
768
|
-
case "choice":
|
|
769
|
-
return this.renderChoice(parent, node.alternatives);
|
|
770
|
-
case "optional":
|
|
771
|
-
return this.renderOptional(parent, node.element);
|
|
772
|
-
case "repetition":
|
|
773
|
-
return this.renderRepetition(parent, node.element, node.min);
|
|
774
|
-
case "special":
|
|
775
|
-
return this.renderSpecial(parent, node.text);
|
|
776
|
-
default:
|
|
777
|
-
throw new Error(`Unknown node type: ${node.type}`);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* Render a single rule
|
|
782
|
-
*/
|
|
783
|
-
renderRule(rule, y) {
|
|
784
|
-
const group = this.svg.append("g").attr("class", "railroad-rule").attr("transform", `translate(0, ${y})`);
|
|
785
|
-
const ruleName = rule.name + " =";
|
|
786
|
-
const nameWidth = this.measureText(ruleName).width + 20;
|
|
787
|
-
const definitionX = nameWidth + 20;
|
|
788
|
-
const defGroup = group.append("g");
|
|
789
|
-
const result = this.renderExpression(defGroup, rule.definition);
|
|
790
|
-
const baselineY = Math.max(20, result.dimensions.up);
|
|
791
|
-
const definitionY = baselineY - result.dimensions.up;
|
|
792
|
-
defGroup.attr("transform", `translate(${definitionX}, ${definitionY})`);
|
|
793
|
-
const nameGroup = group.append("g").attr("class", "railroad-rule-name-group");
|
|
794
|
-
nameGroup.append("text").attr("class", "railroad-rule-name").attr("x", 0).attr("y", baselineY).text(ruleName);
|
|
795
|
-
const startMarker = group.append("g").attr("class", "railroad-start");
|
|
796
|
-
startMarker.append("circle").attr("cx", nameWidth).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
797
|
-
const endMarker = group.append("g").attr("class", "railroad-end");
|
|
798
|
-
endMarker.append("circle").attr("cx", definitionX + result.dimensions.width + 10).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
799
|
-
group.append("path").attr("class", "railroad-line").attr(
|
|
800
|
-
"d",
|
|
801
|
-
new PathBuilder().moveTo(nameWidth + this.config.markerRadius, baselineY).lineTo(definitionX, baselineY).build()
|
|
802
|
-
);
|
|
803
|
-
group.append("path").attr("class", "railroad-line").attr(
|
|
804
|
-
"d",
|
|
805
|
-
new PathBuilder().moveTo(definitionX + result.dimensions.width, baselineY).lineTo(definitionX + result.dimensions.width + 10 - this.config.markerRadius, baselineY).build()
|
|
806
|
-
);
|
|
807
|
-
return {
|
|
808
|
-
height: Math.max(40, definitionY + result.dimensions.height + this.config.padding * 2),
|
|
809
|
-
width: definitionX + result.dimensions.width + 10 + this.config.markerRadius
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Render all rules
|
|
814
|
-
*/
|
|
815
|
-
renderDiagram(rules2) {
|
|
816
|
-
let y = this.config.padding;
|
|
817
|
-
let maxWidth = 0;
|
|
818
|
-
for (const rule of rules2) {
|
|
819
|
-
const result = this.renderRule(rule, y);
|
|
820
|
-
y += result.height + this.config.verticalSeparation;
|
|
821
|
-
maxWidth = Math.max(maxWidth, result.width);
|
|
822
|
-
}
|
|
823
|
-
return {
|
|
824
|
-
width: maxWidth + this.config.padding * 2,
|
|
825
|
-
height: y + this.config.padding
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
var configureRailroadSvgSize = /* @__PURE__ */ __name((svg, dimensions, useMaxWidth) => {
|
|
830
|
-
configureSvgSize(svg, dimensions.height, dimensions.width, useMaxWidth);
|
|
831
|
-
svg.attr("viewBox", `0 0 ${dimensions.width} ${dimensions.height}`);
|
|
832
|
-
}, "configureRailroadSvgSize");
|
|
833
|
-
var draw = /* @__PURE__ */ __name((text, id, _version) => {
|
|
834
|
-
log.debug("[Railroad] Rendering diagram\n" + text);
|
|
835
|
-
try {
|
|
836
|
-
const svg = selectSvgElement(id);
|
|
837
|
-
svg.attr("class", "railroad-diagram");
|
|
838
|
-
const railroadConfig = getConfig().railroad;
|
|
839
|
-
const useMaxWidth = railroadConfig?.useMaxWidth ?? true;
|
|
840
|
-
const rules2 = db.getRules();
|
|
841
|
-
log.debug(`[Railroad] Rendering ${rules2.length} rules`);
|
|
842
|
-
if (rules2.length === 0) {
|
|
843
|
-
log.warn("[Railroad] No rules to render");
|
|
844
|
-
configureRailroadSvgSize(svg, { height: 100, width: 200 }, useMaxWidth);
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
const renderer2 = new RailroadRenderer(svg, buildRailroadStyleOptions());
|
|
848
|
-
const dimensions = renderer2.renderDiagram(rules2);
|
|
849
|
-
configureRailroadSvgSize(svg, dimensions, useMaxWidth);
|
|
850
|
-
log.debug("[Railroad] Render complete");
|
|
851
|
-
} catch (error) {
|
|
852
|
-
log.error("[Railroad] Render error:", error);
|
|
853
|
-
throw error;
|
|
854
|
-
}
|
|
855
|
-
}, "draw");
|
|
856
|
-
var renderer = { draw };
|
|
857
|
-
export {
|
|
858
|
-
db as d,
|
|
859
|
-
getStyles as g,
|
|
860
|
-
renderer as r
|
|
861
|
-
};
|