whipped 0.8.0 → 0.9.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/cli.js +1294 -259
- package/dist/mcp-server.js +150 -2
- package/dist/migrations/014_companion_sessions.sql +34 -0
- package/dist/migrations/015_companion_worktree_mode.sql +45 -0
- package/dist/migrations/016_companion_plans.sql +22 -0
- package/dist/migrations/017_companion_saved_plans.sql +23 -0
- package/dist/migrations/018_generalize_plan_session_ref.sql +29 -0
- package/dist/migrations/019_rename_plan_to_canvas.sql +20 -0
- package/dist/web-ui/assets/abnfDiagram-VRR7QNED-RwOyl_Kz.js +119 -0
- package/dist/web-ui/assets/arc-DmDBHE0H.js +131 -0
- package/dist/web-ui/assets/architectureDiagram-ZJ3FMSHR-RTwadm6J.js +8821 -0
- package/dist/web-ui/assets/blockDiagram-677ZJIJ3-Dvv5uMUE.js +3801 -0
- package/dist/web-ui/assets/c4Diagram-LMCZKHZV-bvr9R9cD.js +2479 -0
- package/dist/web-ui/assets/channel-BGhlETgZ.js +7 -0
- package/dist/web-ui/assets/chunk-2Q5K7J3B-BRq-Qbau.js +17 -0
- package/dist/web-ui/assets/chunk-32BRIVSS-Dy1BUZGx.js +116 -0
- package/dist/web-ui/assets/chunk-5VM5RSS4-DCUiIwIc.js +19 -0
- package/dist/web-ui/assets/chunk-EX3LRPZG-Cg_Vtzwz.js +1996 -0
- package/dist/web-ui/assets/chunk-JWPE2WC7-BW4n_ZhH.js +17 -0
- package/dist/web-ui/assets/chunk-MOJQB5TN-BykRa615.js +855 -0
- package/dist/web-ui/assets/chunk-RYQCIY6F-D4F7oV1d.js +476 -0
- package/dist/web-ui/assets/chunk-V7JOEXUC-DD4mm30h.js +2022 -0
- package/dist/web-ui/assets/chunk-VR4S4FIN-Fgvcluvk.js +25 -0
- package/dist/web-ui/assets/chunk-XXDRQBXY-C4FVmO5r.js +13 -0
- package/dist/web-ui/assets/classDiagram-OUVF2IWQ-DD4KIYF1.js +24 -0
- package/dist/web-ui/assets/classDiagram-v2-EOCWNBFH-DD4KIYF1.js +24 -0
- package/dist/web-ui/assets/cose-bilkent-JH36ORCC-ekFwvYt9.js +4943 -0
- package/dist/web-ui/assets/cynefin-VYW2F7L2-DTNV7gvQ.js +31527 -0
- package/dist/web-ui/assets/cynefinDiagram-TSTJHNR4-koYialeC.js +454 -0
- package/dist/web-ui/assets/cytoscape.esm-CaQ7Fomf.js +30346 -0
- package/dist/web-ui/assets/dagre-VKFMJZFB-Do43FV3o.js +526 -0
- package/dist/web-ui/assets/defaultLocale-B2RvLBDe.js +206 -0
- package/dist/web-ui/assets/diagram-FQU43EPY-D0STdny6.js +636 -0
- package/dist/web-ui/assets/diagram-G47NLZAW-D9g6BdZT.js +858 -0
- package/dist/web-ui/assets/diagram-NH7WQ7WH-zLW6CAmi.js +212 -0
- package/dist/web-ui/assets/diagram-OA4YK3LP-CA5tvsYw.js +492 -0
- package/dist/web-ui/assets/diagram-WEI45ONY-CLmYUHR0.js +309 -0
- package/dist/web-ui/assets/ebnfDiagram-CCIWWBDH-KkHubBI6.js +139 -0
- package/dist/web-ui/assets/erDiagram-Q63AITRT-BJna2u1n.js +1238 -0
- package/dist/web-ui/assets/flowDiagram-23GEKE2U-DVJKalah.js +2353 -0
- package/dist/web-ui/assets/ganttDiagram-NO4QXBWP-D9HwNV4u.js +3733 -0
- package/dist/web-ui/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/web-ui/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/web-ui/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/web-ui/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/web-ui/assets/geist-mono-cyrillic-ext-wght-normal-I4S5GZfc.woff2 +0 -0
- package/dist/web-ui/assets/geist-mono-cyrillic-wght-normal-BmXc_FBt.woff2 +0 -0
- package/dist/web-ui/assets/geist-mono-latin-ext-wght-normal-DrnZ1wKl.woff2 +0 -0
- package/dist/web-ui/assets/geist-mono-latin-wght-normal-B_7UjwxQ.woff2 +0 -0
- package/dist/web-ui/assets/geist-mono-symbols2-wght-normal-GZpp1pK2.woff2 +0 -0
- package/dist/web-ui/assets/geist-mono-vietnamese-wght-normal-D8KDMBhC.woff2 +0 -0
- package/dist/web-ui/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/web-ui/assets/gitGraphDiagram-IHSO6WYX-B7wnoO0J.js +1385 -0
- package/dist/web-ui/assets/graph-BMLV0goG.js +2042 -0
- package/dist/web-ui/assets/{index-CRXPsGTP.css → index-DPjATOCj.css} +800 -1207
- package/dist/web-ui/assets/{index-CuGz83Sg.js → index-DZ7I8r_C.js} +41629 -39831
- package/dist/web-ui/assets/infoDiagram-FWYZ7A6U-BY6XoiF8.js +32 -0
- package/dist/web-ui/assets/init-ZxktEp_H.js +16 -0
- package/dist/web-ui/assets/ishikawaDiagram-FXEZZL3T-BaZVnO8j.js +967 -0
- package/dist/web-ui/assets/journeyDiagram-5HDEW3XC-CUA6DUAQ.js +1256 -0
- package/dist/web-ui/assets/kanban-definition-HUTT4EX6-5W5tiWrd.js +1055 -0
- package/dist/web-ui/assets/katex-CqNtglxf.js +14499 -0
- package/dist/web-ui/assets/layout-BNmRhaUB.js +2359 -0
- package/dist/web-ui/assets/linear-CfvGIyDE.js +340 -0
- package/dist/web-ui/assets/map-BEO0Bu8q.js +298 -0
- package/dist/web-ui/assets/mermaid.core-BRk3IzY2.js +26639 -0
- package/dist/web-ui/assets/mindmap-definition-LN4V7U3C-2GmLg6ou.js +1183 -0
- package/dist/web-ui/assets/ordinal-DSZU4PqD.js +76 -0
- package/dist/web-ui/assets/pegDiagram-2B236MQR-gTEdrkJg.js +127 -0
- package/dist/web-ui/assets/pieDiagram-ENE6RG2P-CYXjIhqC.js +318 -0
- package/dist/web-ui/assets/quadrantDiagram-ABIIQ3AL-BStRZxwf.js +1341 -0
- package/dist/web-ui/assets/railroadDiagram-RFXS5EU6-btveDRG2.js +93 -0
- package/dist/web-ui/assets/requirementDiagram-TGXJPOKE-Cy_155rE.js +1205 -0
- package/dist/web-ui/assets/sankeyDiagram-HTMAVEWB-Chtvw3_G.js +1264 -0
- package/dist/web-ui/assets/sequenceDiagram-DBY2YBRQ-DDuMVEX1.js +4523 -0
- package/dist/web-ui/assets/sizeCapture-X5ZJPWSS-Bylf0o6J.js +64 -0
- package/dist/web-ui/assets/stateDiagram-2N3HPSRC-DIzLeR5G.js +453 -0
- package/dist/web-ui/assets/stateDiagram-v2-6OUMAXLB-zG_WjT1-.js +23 -0
- package/dist/web-ui/assets/swimlanes-5IMT3BWC-TKaCmVta.js +8575 -0
- package/dist/web-ui/assets/swimlanesDiagram-G3AALYLV-C5eB3qqS.js +21 -0
- package/dist/web-ui/assets/timeline-definition-FHXFAJF6-CC5Ujpcu.js +1606 -0
- package/dist/web-ui/assets/vennDiagram-L72KCM5P-DUSVXSYT.js +2523 -0
- package/dist/web-ui/assets/wardleyDiagram-EHGQE667-CoP9xn89.js +978 -0
- package/dist/web-ui/assets/xychartDiagram-FW5EYKEG-B9FqP_kk.js +1972 -0
- package/dist/web-ui/index.html +2 -2
- package/package.json +14 -16
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
var _a, _b;
|
|
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-BRk3IzY2.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 = (_a = class {
|
|
448
|
+
constructor() {
|
|
449
|
+
this.d = "";
|
|
450
|
+
}
|
|
451
|
+
moveTo(x, y) {
|
|
452
|
+
this.d += `M ${x} ${y} `;
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
lineTo(x, y) {
|
|
456
|
+
this.d += `L ${x} ${y} `;
|
|
457
|
+
return this;
|
|
458
|
+
}
|
|
459
|
+
horizontalTo(x) {
|
|
460
|
+
this.d += `H ${x} `;
|
|
461
|
+
return this;
|
|
462
|
+
}
|
|
463
|
+
verticalTo(y) {
|
|
464
|
+
this.d += `V ${y} `;
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
arcTo(rx, ry, rotation, largeArc, sweep, x, y) {
|
|
468
|
+
this.d += `A ${rx} ${ry} ${rotation} ${largeArc ? 1 : 0} ${sweep ? 1 : 0} ${x} ${y} `;
|
|
469
|
+
return this;
|
|
470
|
+
}
|
|
471
|
+
build() {
|
|
472
|
+
return this.d.trim();
|
|
473
|
+
}
|
|
474
|
+
}, __name(_a, "PathBuilder"), _a);
|
|
475
|
+
var RailroadRenderer = (_b = class {
|
|
476
|
+
constructor(svg, config = buildRailroadStyleOptions()) {
|
|
477
|
+
this.textCache = /* @__PURE__ */ new Map();
|
|
478
|
+
this.svg = svg;
|
|
479
|
+
this.config = config;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Measure text dimensions
|
|
483
|
+
*/
|
|
484
|
+
measureText(text) {
|
|
485
|
+
if (this.textCache.has(text)) {
|
|
486
|
+
return this.textCache.get(text);
|
|
487
|
+
}
|
|
488
|
+
const tempText = this.svg.append("text").attr("font-family", this.config.fontFamily).attr("font-size", this.config.fontSize).text(text);
|
|
489
|
+
const bbox = tempText.node().getBBox();
|
|
490
|
+
const dimensions = { width: bbox.width, height: bbox.height };
|
|
491
|
+
tempText.remove();
|
|
492
|
+
this.textCache.set(text, dimensions);
|
|
493
|
+
return dimensions;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Render terminal symbol (rounded rectangle)
|
|
497
|
+
*/
|
|
498
|
+
renderTerminal(parent, value) {
|
|
499
|
+
const textDim = this.measureText(value);
|
|
500
|
+
const width = textDim.width + this.config.padding * 2;
|
|
501
|
+
const height = textDim.height + this.config.padding * 2;
|
|
502
|
+
const group = parent.append("g").attr("class", "railroad-terminal");
|
|
503
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height).attr("rx", 10).attr("ry", 10);
|
|
504
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text(value);
|
|
505
|
+
return {
|
|
506
|
+
element: group.node(),
|
|
507
|
+
dimensions: {
|
|
508
|
+
width,
|
|
509
|
+
height,
|
|
510
|
+
up: height / 2,
|
|
511
|
+
down: height / 2
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Render non-terminal symbol (rectangle)
|
|
517
|
+
*/
|
|
518
|
+
renderNonTerminal(parent, name) {
|
|
519
|
+
const textDim = this.measureText(name);
|
|
520
|
+
const width = textDim.width + this.config.padding * 2;
|
|
521
|
+
const height = textDim.height + this.config.padding * 2;
|
|
522
|
+
const group = parent.append("g").attr("class", "railroad-nonterminal");
|
|
523
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
524
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text(name);
|
|
525
|
+
return {
|
|
526
|
+
element: group.node(),
|
|
527
|
+
dimensions: {
|
|
528
|
+
width,
|
|
529
|
+
height,
|
|
530
|
+
up: height / 2,
|
|
531
|
+
down: height / 2
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Render sequence (horizontal concatenation)
|
|
537
|
+
*/
|
|
538
|
+
renderSequence(parent, elements) {
|
|
539
|
+
const rendered = elements.map((e) => this.renderExpression(parent, e));
|
|
540
|
+
let totalWidth = 0;
|
|
541
|
+
let maxUp = 0;
|
|
542
|
+
let maxDown = 0;
|
|
543
|
+
for (const r of rendered) {
|
|
544
|
+
totalWidth += r.dimensions.width;
|
|
545
|
+
maxUp = Math.max(maxUp, r.dimensions.up);
|
|
546
|
+
maxDown = Math.max(maxDown, r.dimensions.down);
|
|
547
|
+
}
|
|
548
|
+
totalWidth += (rendered.length - 1) * this.config.horizontalSeparation;
|
|
549
|
+
const group = parent.append("g").attr("class", "railroad-sequence");
|
|
550
|
+
let x = 0;
|
|
551
|
+
for (let i = 0; i < rendered.length; i++) {
|
|
552
|
+
const r = rendered[i];
|
|
553
|
+
const y = maxUp - r.dimensions.up;
|
|
554
|
+
const elem = group.node().appendChild(r.element);
|
|
555
|
+
elem.setAttribute("transform", `translate(${x}, ${y})`);
|
|
556
|
+
if (i < rendered.length - 1) {
|
|
557
|
+
const lineX1 = x + r.dimensions.width;
|
|
558
|
+
const lineX2 = lineX1 + this.config.horizontalSeparation;
|
|
559
|
+
const lineY = maxUp;
|
|
560
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(lineX1, lineY).lineTo(lineX2, lineY).build());
|
|
561
|
+
}
|
|
562
|
+
x += r.dimensions.width + this.config.horizontalSeparation;
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
element: group.node(),
|
|
566
|
+
dimensions: {
|
|
567
|
+
width: totalWidth,
|
|
568
|
+
height: maxUp + maxDown,
|
|
569
|
+
up: maxUp,
|
|
570
|
+
down: maxDown
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Render choice (vertical alternatives)
|
|
576
|
+
*/
|
|
577
|
+
renderChoice(parent, alternatives) {
|
|
578
|
+
const rendered = alternatives.map((a) => this.renderExpression(parent, a));
|
|
579
|
+
let maxWidth = 0;
|
|
580
|
+
let totalHeight = 0;
|
|
581
|
+
for (const r of rendered) {
|
|
582
|
+
maxWidth = Math.max(maxWidth, r.dimensions.width);
|
|
583
|
+
totalHeight += r.dimensions.height;
|
|
584
|
+
}
|
|
585
|
+
totalHeight += (rendered.length - 1) * this.config.verticalSeparation;
|
|
586
|
+
const arcRadius = this.config.arcRadius;
|
|
587
|
+
const arcWidth = arcRadius * 4;
|
|
588
|
+
const totalWidth = maxWidth + arcWidth;
|
|
589
|
+
const group = parent.append("g").attr("class", "railroad-choice");
|
|
590
|
+
let y = 0;
|
|
591
|
+
const centerY = totalHeight / 2;
|
|
592
|
+
for (const r of rendered) {
|
|
593
|
+
const elemY = y;
|
|
594
|
+
const elemCenterY = elemY + r.dimensions.up;
|
|
595
|
+
const elemX = arcRadius * 2 + (maxWidth - r.dimensions.width) / 2;
|
|
596
|
+
const elem = group.node().appendChild(r.element);
|
|
597
|
+
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
598
|
+
const leftPath = new PathBuilder();
|
|
599
|
+
const isBelowCenter = elemCenterY > centerY;
|
|
600
|
+
if (elemCenterY === centerY) {
|
|
601
|
+
leftPath.moveTo(0, centerY).lineTo(elemX, elemCenterY);
|
|
602
|
+
} else {
|
|
603
|
+
leftPath.moveTo(0, centerY).arcTo(
|
|
604
|
+
arcRadius,
|
|
605
|
+
arcRadius,
|
|
606
|
+
0,
|
|
607
|
+
false,
|
|
608
|
+
isBelowCenter,
|
|
609
|
+
arcRadius,
|
|
610
|
+
centerY + (isBelowCenter ? arcRadius : -arcRadius)
|
|
611
|
+
).lineTo(arcRadius, elemCenterY - (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, !isBelowCenter, arcRadius * 2, elemCenterY).lineTo(elemX, elemCenterY);
|
|
612
|
+
}
|
|
613
|
+
group.append("path").attr("class", "railroad-line").attr("d", leftPath.build());
|
|
614
|
+
const rightPath = new PathBuilder();
|
|
615
|
+
const rightStart = elemX + r.dimensions.width;
|
|
616
|
+
const rightLaneX = totalWidth - arcRadius * 2;
|
|
617
|
+
if (elemCenterY === centerY) {
|
|
618
|
+
rightPath.moveTo(rightStart, elemCenterY).lineTo(totalWidth, centerY);
|
|
619
|
+
} else {
|
|
620
|
+
rightPath.moveTo(rightStart, elemCenterY).lineTo(rightLaneX, elemCenterY).arcTo(
|
|
621
|
+
arcRadius,
|
|
622
|
+
arcRadius,
|
|
623
|
+
0,
|
|
624
|
+
false,
|
|
625
|
+
!isBelowCenter,
|
|
626
|
+
totalWidth - arcRadius,
|
|
627
|
+
elemCenterY + (isBelowCenter ? -arcRadius : arcRadius)
|
|
628
|
+
).lineTo(totalWidth - arcRadius, centerY + (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, isBelowCenter, totalWidth, centerY);
|
|
629
|
+
}
|
|
630
|
+
group.append("path").attr("class", "railroad-line").attr("d", rightPath.build());
|
|
631
|
+
y += r.dimensions.height + this.config.verticalSeparation;
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
element: group.node(),
|
|
635
|
+
dimensions: {
|
|
636
|
+
width: totalWidth,
|
|
637
|
+
height: totalHeight,
|
|
638
|
+
up: centerY,
|
|
639
|
+
down: totalHeight - centerY
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Render optional (bypass path above)
|
|
645
|
+
*/
|
|
646
|
+
renderOptional(parent, element) {
|
|
647
|
+
const inner = this.renderExpression(parent, element);
|
|
648
|
+
const arcRadius = this.config.arcRadius;
|
|
649
|
+
const arcHeight = arcRadius * 2;
|
|
650
|
+
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
651
|
+
const totalHeight = inner.dimensions.height + arcHeight;
|
|
652
|
+
const group = parent.append("g").attr("class", "railroad-optional");
|
|
653
|
+
const elemX = arcRadius * 2;
|
|
654
|
+
const elemY = arcHeight;
|
|
655
|
+
const elem = group.node().appendChild(inner.element);
|
|
656
|
+
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
657
|
+
const centerY = elemY + inner.dimensions.up;
|
|
658
|
+
const lowerPath = new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY);
|
|
659
|
+
group.append("path").attr("class", "railroad-line").attr("d", lowerPath.build());
|
|
660
|
+
const lowerPath2 = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY);
|
|
661
|
+
group.append("path").attr("class", "railroad-line").attr("d", lowerPath2.build());
|
|
662
|
+
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);
|
|
663
|
+
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
664
|
+
return {
|
|
665
|
+
element: group.node(),
|
|
666
|
+
dimensions: {
|
|
667
|
+
width: totalWidth,
|
|
668
|
+
height: totalHeight,
|
|
669
|
+
up: centerY,
|
|
670
|
+
down: totalHeight - centerY
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Render repetition (loop back path)
|
|
676
|
+
*/
|
|
677
|
+
renderRepetition(parent, element, min) {
|
|
678
|
+
const inner = this.renderExpression(parent, element);
|
|
679
|
+
const arcRadius = this.config.arcRadius;
|
|
680
|
+
const arcHeight = arcRadius * 2;
|
|
681
|
+
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
682
|
+
const hasBypass = min === 0;
|
|
683
|
+
const totalHeight = inner.dimensions.height + arcHeight + (hasBypass ? arcHeight : 0);
|
|
684
|
+
const group = parent.append("g").attr("class", "railroad-repetition");
|
|
685
|
+
const elemX = arcRadius * 2;
|
|
686
|
+
const elemY = hasBypass ? arcHeight : 0;
|
|
687
|
+
const elem = group.node().appendChild(inner.element);
|
|
688
|
+
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
689
|
+
const centerY = elemY + inner.dimensions.up;
|
|
690
|
+
group.append("path").attr("class", "railroad-line").attr(
|
|
691
|
+
"d",
|
|
692
|
+
new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY).build()
|
|
693
|
+
);
|
|
694
|
+
group.append("path").attr("class", "railroad-line").attr(
|
|
695
|
+
"d",
|
|
696
|
+
new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY).build()
|
|
697
|
+
);
|
|
698
|
+
const loopY = elemY + inner.dimensions.height + arcRadius;
|
|
699
|
+
const loopPath = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).arcTo(
|
|
700
|
+
arcRadius,
|
|
701
|
+
arcRadius,
|
|
702
|
+
0,
|
|
703
|
+
false,
|
|
704
|
+
true,
|
|
705
|
+
elemX + inner.dimensions.width + arcRadius,
|
|
706
|
+
centerY + arcRadius
|
|
707
|
+
).lineTo(elemX + inner.dimensions.width + arcRadius, loopY).arcTo(
|
|
708
|
+
arcRadius,
|
|
709
|
+
arcRadius,
|
|
710
|
+
0,
|
|
711
|
+
false,
|
|
712
|
+
true,
|
|
713
|
+
elemX + inner.dimensions.width,
|
|
714
|
+
loopY + arcRadius
|
|
715
|
+
).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);
|
|
716
|
+
group.append("path").attr("class", "railroad-line").attr("d", loopPath.build());
|
|
717
|
+
if (hasBypass) {
|
|
718
|
+
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);
|
|
719
|
+
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
element: group.node(),
|
|
723
|
+
dimensions: {
|
|
724
|
+
width: totalWidth,
|
|
725
|
+
height: totalHeight,
|
|
726
|
+
up: centerY,
|
|
727
|
+
down: totalHeight - centerY
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Render special sequence
|
|
733
|
+
*/
|
|
734
|
+
renderSpecial(parent, text) {
|
|
735
|
+
const textDim = this.measureText("? " + text + " ?");
|
|
736
|
+
const width = textDim.width + this.config.padding * 2;
|
|
737
|
+
const height = textDim.height + this.config.padding * 2;
|
|
738
|
+
const group = parent.append("g").attr("class", "railroad-special");
|
|
739
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
740
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text("? " + text + " ?");
|
|
741
|
+
return {
|
|
742
|
+
element: group.node(),
|
|
743
|
+
dimensions: {
|
|
744
|
+
width,
|
|
745
|
+
height,
|
|
746
|
+
up: height / 2,
|
|
747
|
+
down: height / 2
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Render an expression (recursive)
|
|
753
|
+
*/
|
|
754
|
+
renderExpression(parent, node) {
|
|
755
|
+
switch (node.type) {
|
|
756
|
+
case "terminal":
|
|
757
|
+
return this.renderTerminal(parent, node.value);
|
|
758
|
+
case "nonterminal":
|
|
759
|
+
return this.renderNonTerminal(parent, node.name);
|
|
760
|
+
case "sequence":
|
|
761
|
+
return this.renderSequence(parent, node.elements);
|
|
762
|
+
case "choice":
|
|
763
|
+
return this.renderChoice(parent, node.alternatives);
|
|
764
|
+
case "optional":
|
|
765
|
+
return this.renderOptional(parent, node.element);
|
|
766
|
+
case "repetition":
|
|
767
|
+
return this.renderRepetition(parent, node.element, node.min);
|
|
768
|
+
case "special":
|
|
769
|
+
return this.renderSpecial(parent, node.text);
|
|
770
|
+
default:
|
|
771
|
+
throw new Error(`Unknown node type: ${node.type}`);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Render a single rule
|
|
776
|
+
*/
|
|
777
|
+
renderRule(rule, y) {
|
|
778
|
+
const group = this.svg.append("g").attr("class", "railroad-rule").attr("transform", `translate(0, ${y})`);
|
|
779
|
+
const ruleName = rule.name + " =";
|
|
780
|
+
const nameWidth = this.measureText(ruleName).width + 20;
|
|
781
|
+
const definitionX = nameWidth + 20;
|
|
782
|
+
const defGroup = group.append("g");
|
|
783
|
+
const result = this.renderExpression(defGroup, rule.definition);
|
|
784
|
+
const baselineY = Math.max(20, result.dimensions.up);
|
|
785
|
+
const definitionY = baselineY - result.dimensions.up;
|
|
786
|
+
defGroup.attr("transform", `translate(${definitionX}, ${definitionY})`);
|
|
787
|
+
const nameGroup = group.append("g").attr("class", "railroad-rule-name-group");
|
|
788
|
+
nameGroup.append("text").attr("class", "railroad-rule-name").attr("x", 0).attr("y", baselineY).text(ruleName);
|
|
789
|
+
const startMarker = group.append("g").attr("class", "railroad-start");
|
|
790
|
+
startMarker.append("circle").attr("cx", nameWidth).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
791
|
+
const endMarker = group.append("g").attr("class", "railroad-end");
|
|
792
|
+
endMarker.append("circle").attr("cx", definitionX + result.dimensions.width + 10).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
793
|
+
group.append("path").attr("class", "railroad-line").attr(
|
|
794
|
+
"d",
|
|
795
|
+
new PathBuilder().moveTo(nameWidth + this.config.markerRadius, baselineY).lineTo(definitionX, baselineY).build()
|
|
796
|
+
);
|
|
797
|
+
group.append("path").attr("class", "railroad-line").attr(
|
|
798
|
+
"d",
|
|
799
|
+
new PathBuilder().moveTo(definitionX + result.dimensions.width, baselineY).lineTo(definitionX + result.dimensions.width + 10 - this.config.markerRadius, baselineY).build()
|
|
800
|
+
);
|
|
801
|
+
return {
|
|
802
|
+
height: Math.max(40, definitionY + result.dimensions.height + this.config.padding * 2),
|
|
803
|
+
width: definitionX + result.dimensions.width + 10 + this.config.markerRadius
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Render all rules
|
|
808
|
+
*/
|
|
809
|
+
renderDiagram(rules2) {
|
|
810
|
+
let y = this.config.padding;
|
|
811
|
+
let maxWidth = 0;
|
|
812
|
+
for (const rule of rules2) {
|
|
813
|
+
const result = this.renderRule(rule, y);
|
|
814
|
+
y += result.height + this.config.verticalSeparation;
|
|
815
|
+
maxWidth = Math.max(maxWidth, result.width);
|
|
816
|
+
}
|
|
817
|
+
return {
|
|
818
|
+
width: maxWidth + this.config.padding * 2,
|
|
819
|
+
height: y + this.config.padding
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
}, __name(_b, "RailroadRenderer"), _b);
|
|
823
|
+
var configureRailroadSvgSize = /* @__PURE__ */ __name((svg, dimensions, useMaxWidth) => {
|
|
824
|
+
configureSvgSize(svg, dimensions.height, dimensions.width, useMaxWidth);
|
|
825
|
+
svg.attr("viewBox", `0 0 ${dimensions.width} ${dimensions.height}`);
|
|
826
|
+
}, "configureRailroadSvgSize");
|
|
827
|
+
var draw = /* @__PURE__ */ __name((text, id, _version) => {
|
|
828
|
+
log.debug("[Railroad] Rendering diagram\n" + text);
|
|
829
|
+
try {
|
|
830
|
+
const svg = selectSvgElement(id);
|
|
831
|
+
svg.attr("class", "railroad-diagram");
|
|
832
|
+
const railroadConfig = getConfig().railroad;
|
|
833
|
+
const useMaxWidth = (railroadConfig == null ? void 0 : railroadConfig.useMaxWidth) ?? true;
|
|
834
|
+
const rules2 = db.getRules();
|
|
835
|
+
log.debug(`[Railroad] Rendering ${rules2.length} rules`);
|
|
836
|
+
if (rules2.length === 0) {
|
|
837
|
+
log.warn("[Railroad] No rules to render");
|
|
838
|
+
configureRailroadSvgSize(svg, { height: 100, width: 200 }, useMaxWidth);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const renderer2 = new RailroadRenderer(svg, buildRailroadStyleOptions());
|
|
842
|
+
const dimensions = renderer2.renderDiagram(rules2);
|
|
843
|
+
configureRailroadSvgSize(svg, dimensions, useMaxWidth);
|
|
844
|
+
log.debug("[Railroad] Render complete");
|
|
845
|
+
} catch (error) {
|
|
846
|
+
log.error("[Railroad] Render error:", error);
|
|
847
|
+
throw error;
|
|
848
|
+
}
|
|
849
|
+
}, "draw");
|
|
850
|
+
var renderer = { draw };
|
|
851
|
+
export {
|
|
852
|
+
db as d,
|
|
853
|
+
getStyles as g,
|
|
854
|
+
renderer as r
|
|
855
|
+
};
|