@umami/shiso 1.12.0 → 1.13.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/chunks/App.js +76 -49
- package/dist/chunks/abnfDiagram-VCTEODGH.js +109 -0
- package/dist/chunks/arc.js +130 -0
- package/dist/chunks/architecture-7GRP2DOG.js +4 -0
- package/dist/chunks/architectureDiagram-5GKGNRK7.js +7466 -0
- package/dist/chunks/array.js +8 -0
- package/dist/chunks/blockDiagram-I7D4REHJ.js +2546 -0
- package/dist/chunks/c4Diagram-7LVT6UL2.js +3654 -0
- package/dist/chunks/channel.js +9 -0
- package/dist/chunks/chunk-2Q5K7J3B.js +21 -0
- package/dist/chunks/chunk-4HAMMTFA.js +6106 -0
- package/dist/chunks/chunk-5VM5RSS4.js +21 -0
- package/dist/chunks/chunk-75Z2AOVW.js +2185 -0
- package/dist/chunks/chunk-DU6HZSFF.js +8729 -0
- package/dist/chunks/chunk-F27PBJKO.js +95 -0
- package/dist/chunks/chunk-FOHPRMQF.js +27162 -0
- package/dist/chunks/chunk-GMAD6QVW.js +2369 -0
- package/dist/chunks/chunk-GVQU2GXP.js +58 -0
- package/dist/chunks/chunk-IMKFNOWR.js +2593 -0
- package/dist/chunks/chunk-JWPE2WC7.js +12 -0
- package/dist/chunks/chunk-L3NEJ4N5.js +420 -0
- package/dist/chunks/chunk-OSK3NFVY.js +1029 -0
- package/dist/chunks/chunk-P2QGCYS3.js +95 -0
- package/dist/chunks/chunk-POPQ4Y6H.js +33 -0
- package/dist/chunks/chunk-PWAF6VOD.js +467 -0
- package/dist/chunks/chunk-SHT3W25Y.js +4813 -0
- package/dist/chunks/chunk-SVP7TREG.js +686 -0
- package/dist/chunks/chunk-TICWLB2K.js +3800 -0
- package/dist/chunks/chunk-XXDRQBXY.js +12 -0
- package/dist/chunks/chunk-Y2CYZVJY.js +15 -0
- package/dist/chunks/classDiagram-ZZMXUADV.js +33 -0
- package/dist/chunks/classDiagram-v2-VYDZK3BY.js +33 -0
- package/dist/chunks/cose-bilkent-JH36ORCC.js +4268 -0
- package/dist/chunks/cynefin-OW5HDTMX.js +4 -0
- package/dist/chunks/cynefinDiagram-5FMLGOSQ.js +482 -0
- package/dist/chunks/cytoscape.esm.js +28282 -0
- package/dist/chunks/dagre-GXQ25YYZ.js +583 -0
- package/dist/chunks/dagre.js +4235 -0
- package/dist/chunks/defaultLocale.js +246 -0
- package/dist/chunks/diagram-S7CK7UJ4.js +402 -0
- package/dist/chunks/diagram-UQ7AKVKN.js +291 -0
- package/dist/chunks/diagram-VSXAHHWV.js +553 -0
- package/dist/chunks/diagram-VX7I27RA.js +798 -0
- package/dist/chunks/diagram-Z3DM3KII.js +186 -0
- package/dist/chunks/dist.js +92 -0
- package/dist/chunks/docs.js +987 -91
- package/dist/chunks/ebnfDiagram-PWID7BFC.js +123 -0
- package/dist/chunks/erDiagram-RLTQ6QDP.js +2295 -0
- package/dist/chunks/eventmodeling-NTZA5JFV.js +4 -0
- package/dist/chunks/flowDiagram-HODETNUW.js +17 -0
- package/dist/chunks/ganttDiagram-EL5Y4UJY.js +3928 -0
- package/dist/chunks/gitGraph-4MIJSDKK.js +4 -0
- package/dist/chunks/gitGraphDiagram-WWUBYQGX.js +1153 -0
- package/dist/chunks/graphlib.js +4194 -0
- package/dist/chunks/info-A6RAGUB7.js +4 -0
- package/dist/chunks/infoDiagram-27XIBGKW.js +25 -0
- package/dist/chunks/init.js +14 -0
- package/dist/chunks/ishikawaDiagram-5VMMS53U.js +971 -0
- package/dist/chunks/journeyDiagram-3NMN7TZE.js +1226 -0
- package/dist/chunks/kanban-definition-UXKFOSKX.js +1241 -0
- package/dist/chunks/katex.js +26463 -0
- package/dist/chunks/line.js +48 -0
- package/dist/chunks/linear.js +391 -0
- package/dist/chunks/mermaid-parser.core.js +754 -0
- package/dist/chunks/mermaid.core.js +4898 -0
- package/dist/chunks/mindmap-definition-YA3MSWOX.js +1309 -0
- package/dist/chunks/ordinal.js +84 -0
- package/dist/chunks/packet-AYTQ26CC.js +4 -0
- package/dist/chunks/path.js +106 -0
- package/dist/chunks/pegDiagram-XKGWAZYB.js +115 -0
- package/dist/chunks/pie-WAS4IAKB.js +4 -0
- package/dist/chunks/pieDiagram-E7YTZNPT.js +297 -0
- package/dist/chunks/quadrantDiagram-AXDQQJYC.js +2234 -0
- package/dist/chunks/radar-RG4KPBEZ.js +4 -0
- package/dist/chunks/railroad-74A4TZTK.js +4 -0
- package/dist/chunks/railroad-abnf-HS5TGJTU.js +4 -0
- package/dist/chunks/railroad-ebnf-LZEXJU2U.js +4 -0
- package/dist/chunks/railroad-peg-WCYAUIDC.js +4 -0
- package/dist/chunks/railroadDiagram-O6MQD6OU.js +89 -0
- package/dist/chunks/requirementDiagram-BXWQKSXE.js +2464 -0
- package/dist/chunks/rough.esm.js +1396 -0
- package/dist/chunks/sankeyDiagram-P5KCCOFB.js +1308 -0
- package/dist/chunks/sequenceDiagram-WJ2MYXX4.js +5445 -0
- package/dist/chunks/sizeCapture-INFHLROL.js +56 -0
- package/dist/chunks/src.js +2653 -0
- package/dist/chunks/stateDiagram-D77RDMKH.js +368 -0
- package/dist/chunks/stateDiagram-v2-MP3YSRHH.js +33 -0
- package/dist/chunks/swimlanes-42K2YHIH.js +6925 -0
- package/dist/chunks/swimlanesDiagram-VR7AAH4N.js +32 -0
- package/dist/chunks/timeline-definition-24CTP7MA.js +1507 -0
- package/dist/chunks/treeView-Q6P3EWNA.js +4 -0
- package/dist/chunks/treemap-WGGIJYW6.js +4 -0
- package/dist/chunks/vennDiagram-4TSXK5OY.js +2803 -0
- package/dist/chunks/wardley-WFR3VGLG.js +4 -0
- package/dist/chunks/wardleyDiagram-VM6X3IG4.js +877 -0
- package/dist/chunks/xychartDiagram-S5SC5T6Z.js +2698 -0
- package/dist/components.js +2 -2
- package/dist/entry-client.js +1 -1
- package/dist/entry-server.js +1 -1
- package/docs.schema.json +1 -1
- package/package.json +2 -1
- package/scripts/expand-navigation-globs.mjs +77 -8
- package/src/components/CodeBlock.tsx +36 -0
- package/src/components/Docs.tsx +44 -21
- package/src/components/OpenApiOperation.tsx +28 -20
- package/src/components/SideNav.tsx +8 -3
- package/src/components/docs/Changelog.tsx +163 -0
- package/src/components/docs/Mermaid.tsx +164 -0
- package/src/components/docs/Panel.tsx +23 -0
- package/src/components/docs/ParamField.tsx +17 -5
- package/src/components/docs/PropertiesTable.tsx +2 -2
- package/src/components/docs/ResponseField.tsx +17 -5
- package/src/components/docs/Tiles.tsx +59 -0
- package/src/components/docs/Tree.tsx +359 -0
- package/src/components/docs/Update.tsx +72 -0
- package/src/components/docs/index.ts +7 -0
- package/src/components/docs/panel-context.tsx +25 -0
- package/src/components/docs/styles.ts +49 -0
- package/src/components/icons/index.ts +4 -0
- package/src/lib/rehype-shiki.ts +18 -1
- package/types/components.d.ts +79 -0
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
import { n as __name } from "./chunk-Y2CYZVJY.js";
|
|
2
|
+
import { m as log } from "./src.js";
|
|
3
|
+
import { D as getThemeVariables3, a as clear, b as getConfig, c as configureSvgSize, x as getConfig2, z as sanitizeText } from "./chunk-DU6HZSFF.js";
|
|
4
|
+
import { f as selectSvgElement } from "./mermaid.core.js";
|
|
5
|
+
|
|
6
|
+
//#region ../../node_modules/.pnpm/mermaid@11.17.2/node_modules/mermaid/dist/chunks/mermaid.core/chunk-SVP7TREG.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 };
|