@webskill/sdk 0.21.0 → 0.22.0
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/abnfDiagram-O67JEVCF-DtYFjfqO.js +109 -0
- package/dist/agent.d.ts +3 -3
- package/dist/agent.js +1012 -130
- package/dist/{approval-DwN2o2QG.js → approval-DWQlDPbY.js} +102 -16
- package/dist/arc-8U_6NQWm.js +130 -0
- package/dist/architecture-7GRP2DOG-RTw1wpAq.js +4 -0
- package/dist/architectureDiagram-NJMV4G6O-XmmXrJAK.js +7473 -0
- package/dist/array-DQfpQNY8.js +8 -0
- package/dist/blockDiagram-BEXU5L5S-D4yjnCD1.js +2582 -0
- package/dist/browser.d.ts +444 -48
- package/dist/browser.js +1771 -91
- package/dist/c4Diagram-YGBWAQC7-BLmA_JSd.js +3668 -0
- package/dist/channel-CZxxLrG7.js +9 -0
- package/dist/chunk-2Q5K7J3B-Ck03gkFR.js +21 -0
- package/dist/chunk-3FUC2YCW-tr6jmbQf.js +530 -0
- package/dist/chunk-5DYCD2WN-Bt97YGTd.js +58 -0
- package/dist/chunk-5VM5RSS4-BBxa48HL.js +21 -0
- package/dist/chunk-6AEJRKK7-JXK89I-O.js +14 -0
- package/dist/chunk-742MDFTN-CPmgCGwC.js +466 -0
- package/dist/chunk-7INBJB4K-C9jq9o66.js +6552 -0
- package/dist/chunk-7M6MHVWA-BrKCWcR1.js +4894 -0
- package/dist/chunk-7PRAP22T-BHED6GVs.js +95 -0
- package/dist/chunk-DUW6YSOI-DoZj78PO.js +19 -0
- package/dist/chunk-FOHPRMQF-Dkbp819z.js +27189 -0
- package/dist/chunk-GNY47TPC-Bpvq1T49.js +87 -0
- package/dist/chunk-GTNCS2PH-CLmh4I2c.js +686 -0
- package/dist/chunk-GWA4HPMP-B6vN3fkL.js +95 -0
- package/dist/chunk-J5ZVWO5B-Bi_Pcobw.js +26 -0
- package/dist/chunk-JWPE2WC7-D1rC79GS.js +12 -0
- package/dist/chunk-LNGE3PJU-D5OIoe3Z.js +2582 -0
- package/dist/chunk-MBY4JIJT-C34L7a4f.js +2276 -0
- package/dist/chunk-NETBCI7D-Cg84k8N8.js +321 -0
- package/dist/chunk-O7XYJQB3-B6K0KOSL.js +8846 -0
- package/dist/chunk-UA2S7LBM-DxHM29_K.js +612 -0
- package/dist/chunk-WEXAMYUT-Ba6jFWhB.js +33 -0
- package/dist/chunk-XXDRQBXY-DPbSy4kg.js +12 -0
- package/dist/chunk-Y2CYZVJY-U3QOMqrW.js +15 -0
- package/dist/chunk-Z7XXMR3K-oLg1h8F3.js +1038 -0
- package/dist/chunk-ZIGJFQKS-DqEFBuHR.js +2215 -0
- package/dist/classDiagram-v2-NBCMYWYE-BqnOWIUt.js +3845 -0
- package/dist/cose-bilkent-JH36ORCC-C0dTAHVK.js +4270 -0
- package/dist/cynefin-OW5HDTMX-B2QvgEQj.js +4 -0
- package/dist/cynefinDiagram-VND7K2PF-yAWc6Z3W.js +479 -0
- package/dist/cytoscape.esm-C64mRh9B.js +28325 -0
- package/dist/dagre-6A5THRUB-D0w2W27v.js +4816 -0
- package/dist/defaultLocale-B_EoOkSF.js +249 -0
- package/dist/diagram-22UHCM2B-DvgzhUzP.js +6115 -0
- package/dist/diagram-3UASUU5V-DWgUB-ef.js +795 -0
- package/dist/diagram-ATOU4E4O-P1olqwIs.js +553 -0
- package/dist/diagram-CDSNMT55-BUlZuLUe.js +402 -0
- package/dist/diagram-MLGK6HIB-6w5qmkGt.js +186 -0
- package/dist/diagram-MPIPVDR6-DEFiSo8o.js +289 -0
- package/dist/dist-UajCDt3n.js +92 -0
- package/dist/ebnfDiagram-ZINNZB2B-CI8liCfR.js +123 -0
- package/dist/elk-276RUBZZ-3SvW6OAK.js +90034 -0
- package/dist/erDiagram-OPXOYQCR-CPTbKhwP.js +2301 -0
- package/dist/eventmodeling-NTZA5JFV-BlyuqGp0.js +4 -0
- package/dist/flowDiagram-KWPJA3E3-CcUJ6HbV.js +18 -0
- package/dist/ganttDiagram-FUAMR5RP-31UjY0KK.js +3939 -0
- package/dist/{toolSource-C9oNuKmr.js → geometry-wx5ZTYzi.js} +162 -12
- package/dist/gitGraph-4MIJSDKK-ChdVlrk7.js +4 -0
- package/dist/gitGraphDiagram-X574FWY7-DKuxJymB.js +1153 -0
- package/dist/governance.d.ts +3 -3
- package/dist/graphlib-tk9gQYuN.js +4194 -0
- package/dist/{index-B8Tgmpwh.d.ts → index-BiO9_XRk.d.ts} +2 -2
- package/dist/{index-CYLt5u4L.d.ts → index-CjwdZQOS.d.ts} +700 -12
- package/dist/{index-DHopiH_m.d.ts → index-YPd8ZSEa.d.ts} +156 -9
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/info-A6RAGUB7-CxRAt9S9.js +4 -0
- package/dist/infoDiagram-VRGFBTTK-pRspGfjZ.js +25 -0
- package/dist/init-CMOIWdg-.js +16 -0
- package/dist/ishikawaDiagram-OU5B5YK6-DKerAPAg.js +975 -0
- package/dist/journeyDiagram-ZHPQQLJL-C4MK-YO5.js +1227 -0
- package/dist/kanban-definition-PNTS6WVX-BqsZpMXx.js +1244 -0
- package/dist/katex-BcRRvyh_.js +26465 -0
- package/dist/{kind-DaKqLX2F.js → kind-Dc8x0HWz.js} +54 -7
- package/dist/line-LgV8iVMV.js +48 -0
- package/dist/linear-BWKR0Tqd.js +393 -0
- package/dist/linkedDocument-CIuh_Yp0.js +416 -0
- package/dist/mcp.d.ts +2 -2
- package/dist/{memoryArtifactStore-D6dLeY55.js → memoryArtifactStore-Bs7glPqm.js} +14 -0
- package/dist/mermaid-parser.core-pYR5siSx.js +754 -0
- package/dist/mermaid.core-DMtwGCHy.js +1756 -0
- package/dist/mindmap-definition-NLK3R4M7-CXbD-myG.js +1312 -0
- package/dist/node.d.ts +3 -3
- package/dist/node.js +2 -2
- package/dist/{openUiLibrary-b0i7F_oZ.js → openUiLibrary-B7j3rLrm.js} +1 -1
- package/dist/{openUiSpecLang-CLXJEeRU.js → openUiSpecLang-BSYYnjay.js} +1 -1
- package/dist/ordinal-CxA6GHQS.js +84 -0
- package/dist/packet-AYTQ26CC-BOm08cxl.js +4 -0
- package/dist/path-C27Z2Bjv.js +106 -0
- package/dist/pegDiagram-GJSIUBJH-BLGJOewQ.js +115 -0
- package/dist/pie-WAS4IAKB-Dvg7glpk.js +4 -0
- package/dist/pieDiagram-5QR66LMP-laoaV_PB.js +298 -0
- package/dist/quadrantDiagram-O4NWA36T-Db_wFBkT.js +2236 -0
- package/dist/radar-RG4KPBEZ-BZDaTu06.js +4 -0
- package/dist/railroad-74A4TZTK-C-UhjkOy.js +4 -0
- package/dist/railroad-abnf-HS5TGJTU-dUKVA4OS.js +4 -0
- package/dist/railroad-ebnf-LZEXJU2U-DzQumk18.js +4 -0
- package/dist/railroad-peg-WCYAUIDC-B3vvTWed.js +4 -0
- package/dist/railroadDiagram-XR7U4H2S-BY0sTM4X.js +89 -0
- package/dist/requirementDiagram-PLB6GJNP-3rkQfEhs.js +2474 -0
- package/dist/rough.cjs-AmDd_NQk.js +1395 -0
- package/dist/sankeyDiagram-IPEJSGJF-CGAJhyG2.js +3578 -0
- package/dist/sequenceDiagram-PO4LG4MO-9FJjFX06.js +5522 -0
- package/dist/sizeCapture-INFHLROL-D8PWxdOn.js +56 -0
- package/dist/{skillVersionStore-B24Jjjry-BkOk9wI_.d.ts → skillVersionStore-B24Jjjry-BY1H7Krp.d.ts} +1 -1
- package/dist/src-NkhI3UMl.js +2653 -0
- package/dist/stateDiagram-v2-GCMORJYK-B0O3wc1-.js +2715 -0
- package/dist/swimlanes-2SLR337P-D4EOnrpu.js +6637 -0
- package/dist/swimlanesDiagram-TC7HE7FX-BUx29EJ9.js +30 -0
- package/dist/testing.d.ts +2 -1
- package/dist/testing.js +1 -1
- package/dist/timeline-definition-EJHVYXUP-CrgiiB4C.js +1513 -0
- package/dist/treeView-Q6P3EWNA-C1by-Gzc.js +4 -0
- package/dist/treemap-WGGIJYW6-mC2NZ6ad.js +4 -0
- package/dist/{types-BvTV_05--BW8zDuEk.d.ts → types-CpDRZ0rA-BM5FI9oN.d.ts} +59 -8
- package/dist/ui-react.d.ts +3 -3
- package/dist/ui-react.js +3718 -77
- package/dist/ui-vue.d.ts +1 -1
- package/dist/ui.d.ts +3 -3
- package/dist/ui.js +2 -2
- package/dist/usecaseDiagram-POWQR4AR-BUt_TQOY.js +14397 -0
- package/dist/vennDiagram-UO4OBE2U-CwXr0wjA.js +2808 -0
- package/dist/wardley-WFR3VGLG-CVSYjq_S.js +4 -0
- package/dist/wardleyDiagram-VNRHLVJA-Cpfd47dQ.js +874 -0
- package/dist/{webSkillApi-Cib6G-94.js → webSkillApi-Dy-Zjv0y.js} +1 -1
- package/dist/{webskillLitCatalog-W06npwej.js → webskillLitCatalog-D5BCiMCU.js} +1 -1
- package/dist/xychartDiagram-PMCCYNJV-e1TeVoc6.js +2704 -0
- package/package.json +1 -1
- package/dist/linkedDocument-C0gj1sMq.js +0 -245
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
import { n as __name } from "./chunk-Y2CYZVJY-U3QOMqrW.js";
|
|
2
|
+
import { m as log } from "./src-NkhI3UMl.js";
|
|
3
|
+
import { D as getThemeVariables3, a as clear, b as getConfig, c as configureSvgSize, x as getConfig2, z as sanitizeText } from "./chunk-O7XYJQB3-B6K0KOSL.js";
|
|
4
|
+
import { t as selectSvgElement } from "./chunk-6AEJRKK7-JXK89I-O.js";
|
|
5
|
+
|
|
6
|
+
//#region ../../node_modules/.pnpm/mermaid@12.0.0/node_modules/mermaid/dist/chunks/mermaid.core/chunk-GTNCS2PH.mjs
|
|
7
|
+
var diagramTitle = "";
|
|
8
|
+
var accTitle = "";
|
|
9
|
+
var accDescription = "";
|
|
10
|
+
var rules = [];
|
|
11
|
+
var ruleMap = /* @__PURE__ */ new Map();
|
|
12
|
+
var sanitizeText2 = /* @__PURE__ */ __name((text) => {
|
|
13
|
+
return sanitizeText(text, getConfig2());
|
|
14
|
+
}, "sanitizeText");
|
|
15
|
+
var sanitizeAstNode = /* @__PURE__ */ __name((node) => {
|
|
16
|
+
switch (node.type) {
|
|
17
|
+
case "terminal": return {
|
|
18
|
+
...node,
|
|
19
|
+
value: sanitizeText2(node.value)
|
|
20
|
+
};
|
|
21
|
+
case "nonterminal": return {
|
|
22
|
+
...node,
|
|
23
|
+
name: sanitizeText2(node.name)
|
|
24
|
+
};
|
|
25
|
+
case "sequence": return {
|
|
26
|
+
...node,
|
|
27
|
+
elements: node.elements.map(sanitizeAstNode)
|
|
28
|
+
};
|
|
29
|
+
case "choice": return {
|
|
30
|
+
...node,
|
|
31
|
+
alternatives: node.alternatives.map(sanitizeAstNode)
|
|
32
|
+
};
|
|
33
|
+
case "optional": return {
|
|
34
|
+
...node,
|
|
35
|
+
element: sanitizeAstNode(node.element)
|
|
36
|
+
};
|
|
37
|
+
case "repetition": return {
|
|
38
|
+
...node,
|
|
39
|
+
element: sanitizeAstNode(node.element),
|
|
40
|
+
separator: node.separator ? sanitizeAstNode(node.separator) : void 0
|
|
41
|
+
};
|
|
42
|
+
case "special": return {
|
|
43
|
+
...node,
|
|
44
|
+
text: sanitizeText2(node.text)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}, "sanitizeAstNode");
|
|
48
|
+
var clear2 = /* @__PURE__ */ __name(() => {
|
|
49
|
+
diagramTitle = "";
|
|
50
|
+
accTitle = "";
|
|
51
|
+
accDescription = "";
|
|
52
|
+
rules.length = 0;
|
|
53
|
+
ruleMap.clear();
|
|
54
|
+
clear();
|
|
55
|
+
log.debug("[Railroad] Database cleared");
|
|
56
|
+
}, "clear");
|
|
57
|
+
var setTitle = /* @__PURE__ */ __name((text) => {
|
|
58
|
+
diagramTitle = sanitizeText2(text);
|
|
59
|
+
log.debug("[Railroad] Title set:", text);
|
|
60
|
+
}, "setTitle");
|
|
61
|
+
var getTitle = /* @__PURE__ */ __name(() => {
|
|
62
|
+
return diagramTitle;
|
|
63
|
+
}, "getTitle");
|
|
64
|
+
var db = {
|
|
65
|
+
clear: clear2,
|
|
66
|
+
setTitle,
|
|
67
|
+
getTitle,
|
|
68
|
+
addRule: /* @__PURE__ */ __name((rule) => {
|
|
69
|
+
const sanitizedRule = {
|
|
70
|
+
...rule,
|
|
71
|
+
name: sanitizeText2(rule.name),
|
|
72
|
+
definition: sanitizeAstNode(rule.definition),
|
|
73
|
+
comment: rule.comment ? sanitizeText2(rule.comment) : void 0
|
|
74
|
+
};
|
|
75
|
+
log.debug("[Railroad] Adding rule:", sanitizedRule.name);
|
|
76
|
+
if (ruleMap.has(sanitizedRule.name)) log.warn(`[Railroad] Rule '${sanitizedRule.name}' is already defined. Overwriting.`);
|
|
77
|
+
rules.push(sanitizedRule);
|
|
78
|
+
ruleMap.set(sanitizedRule.name, sanitizedRule);
|
|
79
|
+
}, "addRule"),
|
|
80
|
+
getRules: /* @__PURE__ */ __name(() => {
|
|
81
|
+
return rules;
|
|
82
|
+
}, "getRules"),
|
|
83
|
+
getRule: /* @__PURE__ */ __name((name) => {
|
|
84
|
+
return ruleMap.get(name);
|
|
85
|
+
}, "getRule"),
|
|
86
|
+
setAccTitle: /* @__PURE__ */ __name((text) => {
|
|
87
|
+
accTitle = sanitizeText2(text).replace(/^\s+/g, "");
|
|
88
|
+
log.debug("[Railroad] Accessibility title set:", text);
|
|
89
|
+
}, "setAccTitle"),
|
|
90
|
+
getAccTitle: /* @__PURE__ */ __name(() => {
|
|
91
|
+
return accTitle;
|
|
92
|
+
}, "getAccTitle"),
|
|
93
|
+
setAccDescription: /* @__PURE__ */ __name((text) => {
|
|
94
|
+
accDescription = sanitizeText2(text).replace(/\n\s+/g, "\n");
|
|
95
|
+
log.debug("[Railroad] Accessibility description set:", text);
|
|
96
|
+
}, "setAccDescription"),
|
|
97
|
+
getAccDescription: /* @__PURE__ */ __name(() => {
|
|
98
|
+
return accDescription;
|
|
99
|
+
}, "getAccDescription"),
|
|
100
|
+
setDiagramTitle: setTitle,
|
|
101
|
+
getDiagramTitle: getTitle
|
|
102
|
+
};
|
|
103
|
+
var DEFAULT_RAILROAD_CONFIG = {
|
|
104
|
+
compactMode: false,
|
|
105
|
+
padding: 10,
|
|
106
|
+
verticalSeparation: 8,
|
|
107
|
+
horizontalSeparation: 10,
|
|
108
|
+
arcRadius: 10,
|
|
109
|
+
fontSize: 14,
|
|
110
|
+
fontFamily: "monospace",
|
|
111
|
+
terminalFill: "#FFFFC0",
|
|
112
|
+
terminalStroke: "#000000",
|
|
113
|
+
terminalTextColor: "#000000",
|
|
114
|
+
nonTerminalFill: "#FFFFFF",
|
|
115
|
+
nonTerminalStroke: "#000000",
|
|
116
|
+
nonTerminalTextColor: "#000000",
|
|
117
|
+
lineColor: "#000000",
|
|
118
|
+
strokeWidth: 2,
|
|
119
|
+
markerFill: "#000000",
|
|
120
|
+
commentFill: "#E8E8E8",
|
|
121
|
+
commentStroke: "#888888",
|
|
122
|
+
commentTextColor: "#666666",
|
|
123
|
+
specialFill: "#F0E0FF",
|
|
124
|
+
specialStroke: "#8800CC",
|
|
125
|
+
ruleNameColor: "#000066",
|
|
126
|
+
showMarkers: true,
|
|
127
|
+
markerRadius: 5
|
|
128
|
+
};
|
|
129
|
+
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;
|
|
130
|
+
var FONT_FAMILY_PATTERN = /^[\w "',.-]+$/;
|
|
131
|
+
var RAILROAD_STYLE_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
132
|
+
"compactMode",
|
|
133
|
+
"padding",
|
|
134
|
+
"verticalSeparation",
|
|
135
|
+
"horizontalSeparation",
|
|
136
|
+
"arcRadius",
|
|
137
|
+
"fontSize",
|
|
138
|
+
"fontFamily",
|
|
139
|
+
"terminalFill",
|
|
140
|
+
"terminalStroke",
|
|
141
|
+
"terminalTextColor",
|
|
142
|
+
"nonTerminalFill",
|
|
143
|
+
"nonTerminalStroke",
|
|
144
|
+
"nonTerminalTextColor",
|
|
145
|
+
"lineColor",
|
|
146
|
+
"strokeWidth",
|
|
147
|
+
"markerFill",
|
|
148
|
+
"commentFill",
|
|
149
|
+
"commentStroke",
|
|
150
|
+
"commentTextColor",
|
|
151
|
+
"specialFill",
|
|
152
|
+
"specialStroke",
|
|
153
|
+
"ruleNameColor",
|
|
154
|
+
"showMarkers",
|
|
155
|
+
"markerRadius"
|
|
156
|
+
]);
|
|
157
|
+
var isRailroadStyleOptions = /* @__PURE__ */ __name((options) => {
|
|
158
|
+
if (!options) return false;
|
|
159
|
+
return Object.keys(options).every((key) => key === "railroad" || RAILROAD_STYLE_OPTION_KEYS.has(key));
|
|
160
|
+
}, "isRailroadStyleOptions");
|
|
161
|
+
var extractRailroadOverrides = /* @__PURE__ */ __name((options) => {
|
|
162
|
+
if (!options) return {};
|
|
163
|
+
if ("railroad" in options && options.railroad) return options.railroad;
|
|
164
|
+
return isRailroadStyleOptions(options) ? options : {};
|
|
165
|
+
}, "extractRailroadOverrides");
|
|
166
|
+
var extractThemeOverrides = /* @__PURE__ */ __name((options) => {
|
|
167
|
+
if (!options || isRailroadStyleOptions(options)) return {};
|
|
168
|
+
const { railroad: _railroad, svgId: _svgId, theme: _theme, look: _look, ...themeOverrides } = options;
|
|
169
|
+
return themeOverrides;
|
|
170
|
+
}, "extractThemeOverrides");
|
|
171
|
+
var sanitizeColorValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
172
|
+
if (typeof value !== "string") return fallback;
|
|
173
|
+
const normalized = value.trim();
|
|
174
|
+
return COLOR_VALUE_PATTERN.test(normalized) ? normalized : fallback;
|
|
175
|
+
}, "sanitizeColorValue");
|
|
176
|
+
var sanitizeFontFamilyValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
177
|
+
if (typeof value !== "string") return fallback;
|
|
178
|
+
const normalized = value.trim();
|
|
179
|
+
return FONT_FAMILY_PATTERN.test(normalized) ? normalized : fallback;
|
|
180
|
+
}, "sanitizeFontFamilyValue");
|
|
181
|
+
var sanitizeNumberValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
182
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : NaN;
|
|
183
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
184
|
+
}, "sanitizeNumberValue");
|
|
185
|
+
var parseThemeFontSize = /* @__PURE__ */ __name((value) => {
|
|
186
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : NaN;
|
|
187
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
|
|
188
|
+
}, "parseThemeFontSize");
|
|
189
|
+
var buildThemeDefaults = /* @__PURE__ */ __name((themeVariables) => {
|
|
190
|
+
const fontFamily = sanitizeFontFamilyValue(themeVariables.fontFamily, DEFAULT_RAILROAD_CONFIG.fontFamily);
|
|
191
|
+
const fontSize = parseThemeFontSize(themeVariables.fontSize) ?? DEFAULT_RAILROAD_CONFIG.fontSize;
|
|
192
|
+
return {
|
|
193
|
+
...DEFAULT_RAILROAD_CONFIG,
|
|
194
|
+
fontFamily,
|
|
195
|
+
fontSize,
|
|
196
|
+
terminalFill: sanitizeColorValue(themeVariables.secondBkg ?? themeVariables.secondaryColor, DEFAULT_RAILROAD_CONFIG.terminalFill),
|
|
197
|
+
terminalStroke: sanitizeColorValue(themeVariables.secondaryBorderColor ?? themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.terminalStroke),
|
|
198
|
+
terminalTextColor: sanitizeColorValue(themeVariables.secondaryTextColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.terminalTextColor),
|
|
199
|
+
nonTerminalFill: sanitizeColorValue(themeVariables.mainBkg ?? themeVariables.background, DEFAULT_RAILROAD_CONFIG.nonTerminalFill),
|
|
200
|
+
nonTerminalStroke: sanitizeColorValue(themeVariables.primaryBorderColor ?? themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.nonTerminalStroke),
|
|
201
|
+
nonTerminalTextColor: sanitizeColorValue(themeVariables.primaryTextColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.nonTerminalTextColor),
|
|
202
|
+
lineColor: sanitizeColorValue(themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.lineColor),
|
|
203
|
+
markerFill: sanitizeColorValue(themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.markerFill),
|
|
204
|
+
commentFill: sanitizeColorValue(themeVariables.labelBackground ?? themeVariables.tertiaryColor, DEFAULT_RAILROAD_CONFIG.commentFill),
|
|
205
|
+
commentStroke: sanitizeColorValue(themeVariables.tertiaryBorderColor ?? themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.commentStroke),
|
|
206
|
+
commentTextColor: sanitizeColorValue(themeVariables.tertiaryTextColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.commentTextColor),
|
|
207
|
+
specialFill: sanitizeColorValue(themeVariables.tertiaryColor ?? themeVariables.secondaryColor, DEFAULT_RAILROAD_CONFIG.specialFill),
|
|
208
|
+
specialStroke: sanitizeColorValue(themeVariables.tertiaryBorderColor ?? themeVariables.secondaryBorderColor, DEFAULT_RAILROAD_CONFIG.specialStroke),
|
|
209
|
+
ruleNameColor: sanitizeColorValue(themeVariables.titleColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.ruleNameColor)
|
|
210
|
+
};
|
|
211
|
+
}, "buildThemeDefaults");
|
|
212
|
+
var buildRailroadStyleOptions = /* @__PURE__ */ __name((options) => {
|
|
213
|
+
const currentConfig = getConfig();
|
|
214
|
+
const themeDefaults = buildThemeDefaults({
|
|
215
|
+
...getThemeVariables3(),
|
|
216
|
+
...currentConfig.themeVariables ?? {},
|
|
217
|
+
...extractThemeOverrides(options)
|
|
218
|
+
});
|
|
219
|
+
const railroadOptions = {
|
|
220
|
+
...currentConfig.railroad ?? {},
|
|
221
|
+
...extractRailroadOverrides(options)
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
compactMode: railroadOptions.compactMode ?? themeDefaults.compactMode,
|
|
225
|
+
padding: sanitizeNumberValue(railroadOptions.padding, themeDefaults.padding),
|
|
226
|
+
verticalSeparation: sanitizeNumberValue(railroadOptions.verticalSeparation, themeDefaults.verticalSeparation),
|
|
227
|
+
horizontalSeparation: sanitizeNumberValue(railroadOptions.horizontalSeparation, themeDefaults.horizontalSeparation),
|
|
228
|
+
arcRadius: sanitizeNumberValue(railroadOptions.arcRadius, themeDefaults.arcRadius),
|
|
229
|
+
fontSize: sanitizeNumberValue(railroadOptions.fontSize, themeDefaults.fontSize),
|
|
230
|
+
fontFamily: sanitizeFontFamilyValue(railroadOptions.fontFamily, themeDefaults.fontFamily),
|
|
231
|
+
terminalFill: sanitizeColorValue(railroadOptions.terminalFill, themeDefaults.terminalFill),
|
|
232
|
+
terminalStroke: sanitizeColorValue(railroadOptions.terminalStroke, themeDefaults.terminalStroke),
|
|
233
|
+
terminalTextColor: sanitizeColorValue(railroadOptions.terminalTextColor, themeDefaults.terminalTextColor),
|
|
234
|
+
nonTerminalFill: sanitizeColorValue(railroadOptions.nonTerminalFill, themeDefaults.nonTerminalFill),
|
|
235
|
+
nonTerminalStroke: sanitizeColorValue(railroadOptions.nonTerminalStroke, themeDefaults.nonTerminalStroke),
|
|
236
|
+
nonTerminalTextColor: sanitizeColorValue(railroadOptions.nonTerminalTextColor, themeDefaults.nonTerminalTextColor),
|
|
237
|
+
lineColor: sanitizeColorValue(railroadOptions.lineColor, themeDefaults.lineColor),
|
|
238
|
+
strokeWidth: sanitizeNumberValue(railroadOptions.strokeWidth, themeDefaults.strokeWidth),
|
|
239
|
+
markerFill: sanitizeColorValue(railroadOptions.markerFill, themeDefaults.markerFill),
|
|
240
|
+
commentFill: sanitizeColorValue(railroadOptions.commentFill, themeDefaults.commentFill),
|
|
241
|
+
commentStroke: sanitizeColorValue(railroadOptions.commentStroke, themeDefaults.commentStroke),
|
|
242
|
+
commentTextColor: sanitizeColorValue(railroadOptions.commentTextColor, themeDefaults.commentTextColor),
|
|
243
|
+
specialFill: sanitizeColorValue(railroadOptions.specialFill, themeDefaults.specialFill),
|
|
244
|
+
specialStroke: sanitizeColorValue(railroadOptions.specialStroke, themeDefaults.specialStroke),
|
|
245
|
+
ruleNameColor: sanitizeColorValue(railroadOptions.ruleNameColor, themeDefaults.ruleNameColor),
|
|
246
|
+
showMarkers: railroadOptions.showMarkers ?? themeDefaults.showMarkers,
|
|
247
|
+
markerRadius: sanitizeNumberValue(railroadOptions.markerRadius, themeDefaults.markerRadius)
|
|
248
|
+
};
|
|
249
|
+
}, "buildRailroadStyleOptions");
|
|
250
|
+
var getStyles = /* @__PURE__ */ __name((options) => {
|
|
251
|
+
const { fontFamily, fontSize, terminalFill, terminalStroke, terminalTextColor, nonTerminalFill, nonTerminalStroke, nonTerminalTextColor, lineColor, strokeWidth, markerFill, commentFill, commentStroke, commentTextColor, specialFill, specialStroke, ruleNameColor } = buildRailroadStyleOptions(options);
|
|
252
|
+
return `
|
|
253
|
+
.railroad-diagram {
|
|
254
|
+
font-family: ${fontFamily};
|
|
255
|
+
font-size: ${fontSize}px;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.railroad-terminal rect {
|
|
259
|
+
fill: ${terminalFill};
|
|
260
|
+
stroke: ${terminalStroke};
|
|
261
|
+
stroke-width: ${strokeWidth}px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.railroad-terminal text {
|
|
265
|
+
fill: ${terminalTextColor};
|
|
266
|
+
font-family: ${fontFamily};
|
|
267
|
+
font-size: ${fontSize}px;
|
|
268
|
+
text-anchor: middle;
|
|
269
|
+
dominant-baseline: middle;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.railroad-nonterminal rect {
|
|
273
|
+
fill: ${nonTerminalFill};
|
|
274
|
+
stroke: ${nonTerminalStroke};
|
|
275
|
+
stroke-width: ${strokeWidth}px;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.railroad-nonterminal text {
|
|
279
|
+
fill: ${nonTerminalTextColor};
|
|
280
|
+
font-family: ${fontFamily};
|
|
281
|
+
font-size: ${fontSize}px;
|
|
282
|
+
text-anchor: middle;
|
|
283
|
+
dominant-baseline: middle;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.railroad-line {
|
|
287
|
+
stroke: ${lineColor};
|
|
288
|
+
stroke-width: ${strokeWidth}px;
|
|
289
|
+
fill: none;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.railroad-start circle,
|
|
293
|
+
.railroad-end circle {
|
|
294
|
+
fill: ${markerFill};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.railroad-comment ellipse {
|
|
298
|
+
fill: ${commentFill};
|
|
299
|
+
stroke: ${commentStroke};
|
|
300
|
+
stroke-width: ${strokeWidth}px;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.railroad-comment text {
|
|
304
|
+
fill: ${commentTextColor};
|
|
305
|
+
font-style: italic;
|
|
306
|
+
font-family: ${fontFamily};
|
|
307
|
+
font-size: ${fontSize}px;
|
|
308
|
+
text-anchor: middle;
|
|
309
|
+
dominant-baseline: middle;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.railroad-special rect {
|
|
313
|
+
fill: ${specialFill};
|
|
314
|
+
stroke: ${specialStroke};
|
|
315
|
+
stroke-width: ${strokeWidth}px;
|
|
316
|
+
stroke-dasharray: 5,3;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.railroad-special text {
|
|
320
|
+
fill: ${nonTerminalTextColor};
|
|
321
|
+
font-family: ${fontFamily};
|
|
322
|
+
font-size: ${fontSize}px;
|
|
323
|
+
text-anchor: middle;
|
|
324
|
+
dominant-baseline: middle;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.railroad-rule-name {
|
|
328
|
+
font-weight: bold;
|
|
329
|
+
fill: ${ruleNameColor};
|
|
330
|
+
font-family: ${fontFamily};
|
|
331
|
+
font-size: ${fontSize}px;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.railroad-group {
|
|
335
|
+
/* Grouping container, no specific styles */
|
|
336
|
+
}
|
|
337
|
+
`;
|
|
338
|
+
}, "getStyles");
|
|
339
|
+
var PathBuilder = class {
|
|
340
|
+
constructor() {
|
|
341
|
+
this.d = "";
|
|
342
|
+
}
|
|
343
|
+
static {
|
|
344
|
+
__name(this, "PathBuilder");
|
|
345
|
+
}
|
|
346
|
+
moveTo(x, y) {
|
|
347
|
+
this.d += `M ${x} ${y} `;
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
lineTo(x, y) {
|
|
351
|
+
this.d += `L ${x} ${y} `;
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
horizontalTo(x) {
|
|
355
|
+
this.d += `H ${x} `;
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
verticalTo(y) {
|
|
359
|
+
this.d += `V ${y} `;
|
|
360
|
+
return this;
|
|
361
|
+
}
|
|
362
|
+
arcTo(rx, ry, rotation, largeArc, sweep, x, y) {
|
|
363
|
+
this.d += `A ${rx} ${ry} ${rotation} ${largeArc ? 1 : 0} ${sweep ? 1 : 0} ${x} ${y} `;
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
build() {
|
|
367
|
+
return this.d.trim();
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
var RailroadRenderer = class {
|
|
371
|
+
constructor(svg, config = buildRailroadStyleOptions()) {
|
|
372
|
+
this.textCache = /* @__PURE__ */ new Map();
|
|
373
|
+
this.svg = svg;
|
|
374
|
+
this.config = config;
|
|
375
|
+
}
|
|
376
|
+
static {
|
|
377
|
+
__name(this, "RailroadRenderer");
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Measure text dimensions
|
|
381
|
+
*/
|
|
382
|
+
measureText(text) {
|
|
383
|
+
if (this.textCache.has(text)) return this.textCache.get(text);
|
|
384
|
+
const tempText = this.svg.append("text").attr("font-family", this.config.fontFamily).attr("font-size", this.config.fontSize).text(text);
|
|
385
|
+
const bbox = tempText.node().getBBox();
|
|
386
|
+
const dimensions = {
|
|
387
|
+
width: bbox.width,
|
|
388
|
+
height: bbox.height
|
|
389
|
+
};
|
|
390
|
+
tempText.remove();
|
|
391
|
+
this.textCache.set(text, dimensions);
|
|
392
|
+
return dimensions;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Render terminal symbol (rounded rectangle)
|
|
396
|
+
*/
|
|
397
|
+
renderTerminal(parent, value) {
|
|
398
|
+
const textDim = this.measureText(value);
|
|
399
|
+
const width = textDim.width + this.config.padding * 2;
|
|
400
|
+
const height = textDim.height + this.config.padding * 2;
|
|
401
|
+
const group = parent.append("g").attr("class", "railroad-terminal");
|
|
402
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height).attr("rx", 10).attr("ry", 10);
|
|
403
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text(value);
|
|
404
|
+
return {
|
|
405
|
+
element: group.node(),
|
|
406
|
+
dimensions: {
|
|
407
|
+
width,
|
|
408
|
+
height,
|
|
409
|
+
up: height / 2,
|
|
410
|
+
down: height / 2
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Render non-terminal symbol (rectangle)
|
|
416
|
+
*/
|
|
417
|
+
renderNonTerminal(parent, name) {
|
|
418
|
+
const textDim = this.measureText(name);
|
|
419
|
+
const width = textDim.width + this.config.padding * 2;
|
|
420
|
+
const height = textDim.height + this.config.padding * 2;
|
|
421
|
+
const group = parent.append("g").attr("class", "railroad-nonterminal");
|
|
422
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
423
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text(name);
|
|
424
|
+
return {
|
|
425
|
+
element: group.node(),
|
|
426
|
+
dimensions: {
|
|
427
|
+
width,
|
|
428
|
+
height,
|
|
429
|
+
up: height / 2,
|
|
430
|
+
down: height / 2
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Render sequence (horizontal concatenation)
|
|
436
|
+
*/
|
|
437
|
+
renderSequence(parent, elements) {
|
|
438
|
+
const rendered = elements.map((e) => this.renderExpression(parent, e));
|
|
439
|
+
let totalWidth = 0;
|
|
440
|
+
let maxUp = 0;
|
|
441
|
+
let maxDown = 0;
|
|
442
|
+
for (const r of rendered) {
|
|
443
|
+
totalWidth += r.dimensions.width;
|
|
444
|
+
maxUp = Math.max(maxUp, r.dimensions.up);
|
|
445
|
+
maxDown = Math.max(maxDown, r.dimensions.down);
|
|
446
|
+
}
|
|
447
|
+
totalWidth += (rendered.length - 1) * this.config.horizontalSeparation;
|
|
448
|
+
const group = parent.append("g").attr("class", "railroad-sequence");
|
|
449
|
+
let x = 0;
|
|
450
|
+
for (let i = 0; i < rendered.length; i++) {
|
|
451
|
+
const r = rendered[i];
|
|
452
|
+
const y = maxUp - r.dimensions.up;
|
|
453
|
+
group.node().appendChild(r.element).setAttribute("transform", `translate(${x}, ${y})`);
|
|
454
|
+
if (i < rendered.length - 1) {
|
|
455
|
+
const lineX1 = x + r.dimensions.width;
|
|
456
|
+
const lineX2 = lineX1 + this.config.horizontalSeparation;
|
|
457
|
+
const lineY = maxUp;
|
|
458
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(lineX1, lineY).lineTo(lineX2, lineY).build());
|
|
459
|
+
}
|
|
460
|
+
x += r.dimensions.width + this.config.horizontalSeparation;
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
element: group.node(),
|
|
464
|
+
dimensions: {
|
|
465
|
+
width: totalWidth,
|
|
466
|
+
height: maxUp + maxDown,
|
|
467
|
+
up: maxUp,
|
|
468
|
+
down: maxDown
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Render choice (vertical alternatives)
|
|
474
|
+
*/
|
|
475
|
+
renderChoice(parent, alternatives) {
|
|
476
|
+
const rendered = alternatives.map((a) => this.renderExpression(parent, a));
|
|
477
|
+
let maxWidth = 0;
|
|
478
|
+
let totalHeight = 0;
|
|
479
|
+
for (const r of rendered) {
|
|
480
|
+
maxWidth = Math.max(maxWidth, r.dimensions.width);
|
|
481
|
+
totalHeight += r.dimensions.height;
|
|
482
|
+
}
|
|
483
|
+
totalHeight += (rendered.length - 1) * this.config.verticalSeparation;
|
|
484
|
+
const arcRadius = this.config.arcRadius;
|
|
485
|
+
const arcWidth = arcRadius * 4;
|
|
486
|
+
const totalWidth = maxWidth + arcWidth;
|
|
487
|
+
const group = parent.append("g").attr("class", "railroad-choice");
|
|
488
|
+
let y = 0;
|
|
489
|
+
const centerY = totalHeight / 2;
|
|
490
|
+
for (const r of rendered) {
|
|
491
|
+
const elemY = y;
|
|
492
|
+
const elemCenterY = elemY + r.dimensions.up;
|
|
493
|
+
const elemX = arcRadius * 2 + (maxWidth - r.dimensions.width) / 2;
|
|
494
|
+
group.node().appendChild(r.element).setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
495
|
+
const leftPath = new PathBuilder();
|
|
496
|
+
const isBelowCenter = elemCenterY > centerY;
|
|
497
|
+
if (elemCenterY === centerY) leftPath.moveTo(0, centerY).lineTo(elemX, elemCenterY);
|
|
498
|
+
else leftPath.moveTo(0, centerY).arcTo(arcRadius, arcRadius, 0, false, isBelowCenter, arcRadius, centerY + (isBelowCenter ? arcRadius : -arcRadius)).lineTo(arcRadius, elemCenterY - (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, !isBelowCenter, arcRadius * 2, elemCenterY).lineTo(elemX, elemCenterY);
|
|
499
|
+
group.append("path").attr("class", "railroad-line").attr("d", leftPath.build());
|
|
500
|
+
const rightPath = new PathBuilder();
|
|
501
|
+
const rightStart = elemX + r.dimensions.width;
|
|
502
|
+
const rightLaneX = totalWidth - arcRadius * 2;
|
|
503
|
+
if (elemCenterY === centerY) rightPath.moveTo(rightStart, elemCenterY).lineTo(totalWidth, centerY);
|
|
504
|
+
else rightPath.moveTo(rightStart, elemCenterY).lineTo(rightLaneX, elemCenterY).arcTo(arcRadius, arcRadius, 0, false, !isBelowCenter, totalWidth - arcRadius, elemCenterY + (isBelowCenter ? -arcRadius : arcRadius)).lineTo(totalWidth - arcRadius, centerY + (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, isBelowCenter, totalWidth, centerY);
|
|
505
|
+
group.append("path").attr("class", "railroad-line").attr("d", rightPath.build());
|
|
506
|
+
y += r.dimensions.height + this.config.verticalSeparation;
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
element: group.node(),
|
|
510
|
+
dimensions: {
|
|
511
|
+
width: totalWidth,
|
|
512
|
+
height: totalHeight,
|
|
513
|
+
up: centerY,
|
|
514
|
+
down: totalHeight - centerY
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Render optional (bypass path above)
|
|
520
|
+
*/
|
|
521
|
+
renderOptional(parent, element) {
|
|
522
|
+
const inner = this.renderExpression(parent, element);
|
|
523
|
+
const arcRadius = this.config.arcRadius;
|
|
524
|
+
const arcHeight = arcRadius * 2;
|
|
525
|
+
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
526
|
+
const totalHeight = inner.dimensions.height + arcHeight;
|
|
527
|
+
const group = parent.append("g").attr("class", "railroad-optional");
|
|
528
|
+
const elemX = arcRadius * 2;
|
|
529
|
+
const elemY = arcHeight;
|
|
530
|
+
group.node().appendChild(inner.element).setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
531
|
+
const centerY = elemY + inner.dimensions.up;
|
|
532
|
+
const lowerPath = new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY);
|
|
533
|
+
group.append("path").attr("class", "railroad-line").attr("d", lowerPath.build());
|
|
534
|
+
const lowerPath2 = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY);
|
|
535
|
+
group.append("path").attr("class", "railroad-line").attr("d", lowerPath2.build());
|
|
536
|
+
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);
|
|
537
|
+
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
538
|
+
return {
|
|
539
|
+
element: group.node(),
|
|
540
|
+
dimensions: {
|
|
541
|
+
width: totalWidth,
|
|
542
|
+
height: totalHeight,
|
|
543
|
+
up: centerY,
|
|
544
|
+
down: totalHeight - centerY
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Render repetition (loop back path)
|
|
550
|
+
*/
|
|
551
|
+
renderRepetition(parent, element, min) {
|
|
552
|
+
const inner = this.renderExpression(parent, element);
|
|
553
|
+
const arcRadius = this.config.arcRadius;
|
|
554
|
+
const arcHeight = arcRadius * 2;
|
|
555
|
+
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
556
|
+
const hasBypass = min === 0;
|
|
557
|
+
const totalHeight = inner.dimensions.height + arcHeight + (hasBypass ? arcHeight : 0);
|
|
558
|
+
const group = parent.append("g").attr("class", "railroad-repetition");
|
|
559
|
+
const elemX = arcRadius * 2;
|
|
560
|
+
const elemY = hasBypass ? arcHeight : 0;
|
|
561
|
+
group.node().appendChild(inner.element).setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
562
|
+
const centerY = elemY + inner.dimensions.up;
|
|
563
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY).build());
|
|
564
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY).build());
|
|
565
|
+
const loopY = elemY + inner.dimensions.height + arcRadius;
|
|
566
|
+
const loopPath = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).arcTo(arcRadius, arcRadius, 0, false, true, elemX + inner.dimensions.width + arcRadius, centerY + arcRadius).lineTo(elemX + inner.dimensions.width + arcRadius, loopY).arcTo(arcRadius, arcRadius, 0, false, true, elemX + inner.dimensions.width, loopY + arcRadius).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);
|
|
567
|
+
group.append("path").attr("class", "railroad-line").attr("d", loopPath.build());
|
|
568
|
+
if (hasBypass) {
|
|
569
|
+
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);
|
|
570
|
+
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
571
|
+
}
|
|
572
|
+
return {
|
|
573
|
+
element: group.node(),
|
|
574
|
+
dimensions: {
|
|
575
|
+
width: totalWidth,
|
|
576
|
+
height: totalHeight,
|
|
577
|
+
up: centerY,
|
|
578
|
+
down: totalHeight - centerY
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Render special sequence
|
|
584
|
+
*/
|
|
585
|
+
renderSpecial(parent, text) {
|
|
586
|
+
const textDim = this.measureText("? " + text + " ?");
|
|
587
|
+
const width = textDim.width + this.config.padding * 2;
|
|
588
|
+
const height = textDim.height + this.config.padding * 2;
|
|
589
|
+
const group = parent.append("g").attr("class", "railroad-special");
|
|
590
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
591
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text("? " + text + " ?");
|
|
592
|
+
return {
|
|
593
|
+
element: group.node(),
|
|
594
|
+
dimensions: {
|
|
595
|
+
width,
|
|
596
|
+
height,
|
|
597
|
+
up: height / 2,
|
|
598
|
+
down: height / 2
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Render an expression (recursive)
|
|
604
|
+
*/
|
|
605
|
+
renderExpression(parent, node) {
|
|
606
|
+
switch (node.type) {
|
|
607
|
+
case "terminal": return this.renderTerminal(parent, node.value);
|
|
608
|
+
case "nonterminal": return this.renderNonTerminal(parent, node.name);
|
|
609
|
+
case "sequence": return this.renderSequence(parent, node.elements);
|
|
610
|
+
case "choice": return this.renderChoice(parent, node.alternatives);
|
|
611
|
+
case "optional": return this.renderOptional(parent, node.element);
|
|
612
|
+
case "repetition": return this.renderRepetition(parent, node.element, node.min);
|
|
613
|
+
case "special": return this.renderSpecial(parent, node.text);
|
|
614
|
+
default: throw new Error(`Unknown node type: ${node.type}`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Render a single rule
|
|
619
|
+
*/
|
|
620
|
+
renderRule(rule, y) {
|
|
621
|
+
const group = this.svg.append("g").attr("class", "railroad-rule").attr("transform", `translate(0, ${y})`);
|
|
622
|
+
const ruleName = rule.name + " =";
|
|
623
|
+
const nameWidth = this.measureText(ruleName).width + 20;
|
|
624
|
+
const definitionX = nameWidth + 20;
|
|
625
|
+
const defGroup = group.append("g");
|
|
626
|
+
const result = this.renderExpression(defGroup, rule.definition);
|
|
627
|
+
const baselineY = Math.max(20, result.dimensions.up);
|
|
628
|
+
const definitionY = baselineY - result.dimensions.up;
|
|
629
|
+
defGroup.attr("transform", `translate(${definitionX}, ${definitionY})`);
|
|
630
|
+
group.append("g").attr("class", "railroad-rule-name-group").append("text").attr("class", "railroad-rule-name").attr("x", 0).attr("y", baselineY).text(ruleName);
|
|
631
|
+
group.append("g").attr("class", "railroad-start").append("circle").attr("cx", nameWidth).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
632
|
+
group.append("g").attr("class", "railroad-end").append("circle").attr("cx", definitionX + result.dimensions.width + 10).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
633
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(nameWidth + this.config.markerRadius, baselineY).lineTo(definitionX, baselineY).build());
|
|
634
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(definitionX + result.dimensions.width, baselineY).lineTo(definitionX + result.dimensions.width + 10 - this.config.markerRadius, baselineY).build());
|
|
635
|
+
return {
|
|
636
|
+
height: Math.max(40, definitionY + result.dimensions.height + this.config.padding * 2),
|
|
637
|
+
width: definitionX + result.dimensions.width + 10 + this.config.markerRadius
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Render all rules
|
|
642
|
+
*/
|
|
643
|
+
renderDiagram(rules2) {
|
|
644
|
+
let y = this.config.padding;
|
|
645
|
+
let maxWidth = 0;
|
|
646
|
+
for (const rule of rules2) {
|
|
647
|
+
const result = this.renderRule(rule, y);
|
|
648
|
+
y += result.height + this.config.verticalSeparation;
|
|
649
|
+
maxWidth = Math.max(maxWidth, result.width);
|
|
650
|
+
}
|
|
651
|
+
return {
|
|
652
|
+
width: maxWidth + this.config.padding * 2,
|
|
653
|
+
height: y + this.config.padding
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
var configureRailroadSvgSize = /* @__PURE__ */ __name((svg, dimensions, useMaxWidth) => {
|
|
658
|
+
configureSvgSize(svg, dimensions.height, dimensions.width, useMaxWidth);
|
|
659
|
+
svg.attr("viewBox", `0 0 ${dimensions.width} ${dimensions.height}`);
|
|
660
|
+
}, "configureRailroadSvgSize");
|
|
661
|
+
var renderer = { draw: /* @__PURE__ */ __name((text, id, _version) => {
|
|
662
|
+
log.debug("[Railroad] Rendering diagram\n" + text);
|
|
663
|
+
try {
|
|
664
|
+
const svg = selectSvgElement(id);
|
|
665
|
+
svg.attr("class", "railroad-diagram");
|
|
666
|
+
const useMaxWidth = getConfig().railroad?.useMaxWidth ?? true;
|
|
667
|
+
const rules2 = db.getRules();
|
|
668
|
+
log.debug(`[Railroad] Rendering ${rules2.length} rules`);
|
|
669
|
+
if (rules2.length === 0) {
|
|
670
|
+
log.warn("[Railroad] No rules to render");
|
|
671
|
+
configureRailroadSvgSize(svg, {
|
|
672
|
+
height: 100,
|
|
673
|
+
width: 200
|
|
674
|
+
}, useMaxWidth);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
configureRailroadSvgSize(svg, new RailroadRenderer(svg, buildRailroadStyleOptions()).renderDiagram(rules2), useMaxWidth);
|
|
678
|
+
log.debug("[Railroad] Render complete");
|
|
679
|
+
} catch (error) {
|
|
680
|
+
log.error("[Railroad] Render error:", error);
|
|
681
|
+
throw error;
|
|
682
|
+
}
|
|
683
|
+
}, "draw") };
|
|
684
|
+
|
|
685
|
+
//#endregion
|
|
686
|
+
export { getStyles as n, renderer as r, db as t };
|