@probelabs/probe 0.6.0-rc115 → 0.6.0-rc116

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.
@@ -41546,13 +41546,14 @@ function tokenize(text) {
41546
41546
  const lexResult = MermaidLexer.tokenize(text);
41547
41547
  return lexResult;
41548
41548
  }
41549
- var Identifier, NumberLiteral, FlowchartKeyword, GraphKeyword, Direction, SubgraphKeyword, EndKeyword, ClassKeyword, StyleKeyword, ClassDefKeyword, Ampersand, Comma, Semicolon, Colon, TripleColon, BiDirectionalArrow, CircleEndLine, CrossEndLine, DottedArrowRight, DottedArrowLeft, ThickArrowRight, ThickArrowLeft, ArrowRight, ArrowLeft, DottedLine, ThickLine, Line, TwoDashes, InvalidArrow, DoubleSquareOpen, DoubleSquareClose, DoubleRoundOpen, DoubleRoundClose, HexagonOpen, HexagonClose, StadiumOpen, StadiumClose, CylinderOpen, CylinderClose, SquareOpen, SquareClose, RoundOpen, RoundClose, DiamondOpen, DiamondClose, AngleOpen, AngleLess, Pipe, QuotedString, MultilineText, Comment, ColorValue, Text, WhiteSpace, Newline, allTokens, MermaidLexer;
41549
+ var Identifier, NumberLiteral, FlowchartKeyword, GraphKeyword, Direction, SubgraphKeyword, EndKeyword, ClassKeyword, StyleKeyword, ClassDefKeyword, Ampersand, Comma, Semicolon, Colon, TripleColon, BiDirectionalArrow, CircleEndLine, CrossEndLine, DottedArrowRight, DottedArrowLeft, ThickArrowRight, ThickArrowLeft, ArrowRight, ArrowLeft, DottedLine, ThickLine, Line, TwoDashes, InvalidArrow, DoubleSquareOpen, DoubleSquareClose, DoubleRoundOpen, DoubleRoundClose, HexagonOpen, HexagonClose, StadiumOpen, StadiumClose, CylinderOpen, CylinderClose, SquareOpen, SquareClose, RoundOpen, RoundClose, DiamondOpen, DiamondClose, AngleOpen, AngleLess, Pipe, ForwardSlash, Backslash, QuotedString, MultilineText, Comment, ColorValue, Text, WhiteSpace, Newline, allTokens, MermaidLexer;
41550
41550
  var init_lexer2 = __esm({
41551
41551
  "node_modules/@probelabs/maid/out/diagrams/flowchart/lexer.js"() {
41552
41552
  init_api5();
41553
41553
  Identifier = createToken({
41554
41554
  name: "Identifier",
41555
- pattern: /[a-zA-Z_][a-zA-Z0-9_-]*/
41555
+ // e.g., id-2, _id, A1, but not A-- (that belongs to an arrow token)
41556
+ pattern: /[a-zA-Z_][a-zA-Z0-9_]*(?:-[a-zA-Z0-9_]+)*/
41556
41557
  });
41557
41558
  NumberLiteral = createToken({
41558
41559
  name: "NumberLiteral",
@@ -41693,6 +41694,8 @@ var init_lexer2 = __esm({
41693
41694
  AngleOpen = createToken({ name: "AngleOpen", pattern: />/ });
41694
41695
  AngleLess = createToken({ name: "AngleLess", pattern: /</ });
41695
41696
  Pipe = createToken({ name: "Pipe", pattern: /\|/ });
41697
+ ForwardSlash = createToken({ name: "ForwardSlash", pattern: /\// });
41698
+ Backslash = createToken({ name: "Backslash", pattern: /\\/ });
41696
41699
  QuotedString = createToken({
41697
41700
  name: "QuotedString",
41698
41701
  // Allow escaped characters within quotes (Mermaid accepts \" inside "...")
@@ -41776,6 +41779,8 @@ var init_lexer2 = __esm({
41776
41779
  DiamondClose,
41777
41780
  AngleOpen,
41778
41781
  AngleLess,
41782
+ ForwardSlash,
41783
+ Backslash,
41779
41784
  Pipe,
41780
41785
  TripleColon,
41781
41786
  Ampersand,
@@ -41968,6 +41973,8 @@ var init_parser2 = __esm({
41968
41973
  // Allow HTML-like tags (e.g., <br/>) inside labels
41969
41974
  { ALT: () => this.CONSUME(AngleLess) },
41970
41975
  { ALT: () => this.CONSUME(AngleOpen) },
41976
+ { ALT: () => this.CONSUME(ForwardSlash) },
41977
+ { ALT: () => this.CONSUME(Backslash) },
41971
41978
  { ALT: () => this.CONSUME(Comma) },
41972
41979
  { ALT: () => this.CONSUME(Colon) },
41973
41980
  // HTML entities and ampersands inside labels
@@ -43016,6 +43023,66 @@ ${br.example}`,
43016
43023
  length: len
43017
43024
  };
43018
43025
  }
43026
+ if (inRule("boxBlock") && (err.name === "NoViableAltException" || err.name === "MismatchedTokenException")) {
43027
+ const isMessage = /->|-->>|-->/.test(ltxt);
43028
+ const isNote = /note\s+(left|right|over)/i.test(ltxt);
43029
+ const isActivate = /activate\s+/i.test(ltxt);
43030
+ const isDeactivate = /deactivate\s+/i.test(ltxt);
43031
+ if (isMessage || isNote || isActivate || isDeactivate || tokType === "NoteKeyword" || tokType === "ActivateKeyword" || tokType === "DeactivateKeyword") {
43032
+ const lines2 = text.split(/\r?\n/);
43033
+ const boxLine = Math.max(0, line - 1);
43034
+ let hasEnd = false;
43035
+ let openIdx = -1;
43036
+ for (let i3 = boxLine; i3 >= 0; i3--) {
43037
+ if (/^\s*box\b/.test(lines2[i3] || "")) {
43038
+ openIdx = i3;
43039
+ break;
43040
+ }
43041
+ }
43042
+ if (openIdx !== -1) {
43043
+ for (let i3 = boxLine; i3 < lines2.length; i3++) {
43044
+ if (/^\s*end\s*$/.test(lines2[i3] || "")) {
43045
+ hasEnd = true;
43046
+ break;
43047
+ }
43048
+ if (i3 > boxLine && /^\s*(sequenceDiagram|box|alt|opt|loop|par|rect|critical|break)\b/.test(lines2[i3] || ""))
43049
+ break;
43050
+ }
43051
+ }
43052
+ if (hasEnd) {
43053
+ let hasParticipants = false;
43054
+ for (let i3 = openIdx + 1; i3 < lines2.length; i3++) {
43055
+ const raw = lines2[i3] || "";
43056
+ if (/^\s*end\s*$/.test(raw))
43057
+ break;
43058
+ if (/^\s*(participant|actor)\b/i.test(raw)) {
43059
+ hasParticipants = true;
43060
+ break;
43061
+ }
43062
+ }
43063
+ if (!hasParticipants) {
43064
+ return {
43065
+ line: openIdx + 1,
43066
+ column: 1,
43067
+ severity: "error",
43068
+ code: "SE-BOX-EMPTY",
43069
+ message: "Box block has no participant/actor declarations. Use 'rect' to group messages visually.",
43070
+ hint: "Replace 'box' with 'rect' if you want to group messages:\nrect rgb(240, 240, 255)\n A->>B: Message\n Note over A: Info\nend",
43071
+ length: 3
43072
+ };
43073
+ }
43074
+ return {
43075
+ line,
43076
+ column,
43077
+ severity: "error",
43078
+ code: "SE-BOX-INVALID-CONTENT",
43079
+ message: "Box blocks can only contain participant/actor declarations.",
43080
+ hint: 'Move messages, notes, and other statements outside the box block.\nExample:\nbox "Group"\n participant A\n participant B\nend\nA->>B: Message',
43081
+ length: len
43082
+ };
43083
+ }
43084
+ }
43085
+ }
43019
43086
  const blockRules = [
43020
43087
  { rule: "altBlock", label: "alt" },
43021
43088
  { rule: "optBlock", label: "opt" },
@@ -43915,9 +43982,15 @@ var init_parser4 = __esm({
43915
43982
  this.CONSUME(BoxKeyword);
43916
43983
  this.OPTION(() => this.SUBRULE(this.lineRemainder));
43917
43984
  this.AT_LEAST_ONE(() => this.CONSUME(Newline3));
43918
- this.MANY(() => this.SUBRULE(this.line));
43985
+ this.MANY(() => this.OR([
43986
+ { ALT: () => this.SUBRULE(this.participantDecl) },
43987
+ { ALT: () => this.SUBRULE(this.blankLine) }
43988
+ ]));
43919
43989
  this.CONSUME(EndKeyword2);
43920
- this.AT_LEAST_ONE2(() => this.CONSUME2(Newline3));
43990
+ this.OR2([
43991
+ { ALT: () => this.AT_LEAST_ONE2(() => this.CONSUME2(Newline3)) },
43992
+ { ALT: () => this.CONSUME2(EOF) }
43993
+ ]);
43921
43994
  });
43922
43995
  this.lineRemainder = this.RULE("lineRemainder", () => {
43923
43996
  this.AT_LEAST_ONE(() => this.OR([
@@ -45468,6 +45541,69 @@ function computeFixes(text, errors, level = "safe") {
45468
45541
  edits.push(replaceRange(text, at(e3), e3.length ?? 4, "option"));
45469
45542
  continue;
45470
45543
  }
45544
+ if (is("SE-BOX-EMPTY", e3)) {
45545
+ const lines = text.split(/\r?\n/);
45546
+ const boxIdx = Math.max(0, e3.line - 1);
45547
+ const boxLine = lines[boxIdx] || "";
45548
+ const labelMatch = /^\s*box\s+(.+)$/.exec(boxLine);
45549
+ if (labelMatch) {
45550
+ const indent = boxLine.match(/^\s*/)?.[0] || "";
45551
+ const newLine = `${indent}rect rgb(240, 240, 255)`;
45552
+ edits.push({ start: { line: e3.line, column: 1 }, end: { line: e3.line, column: boxLine.length + 1 }, newText: newLine });
45553
+ }
45554
+ continue;
45555
+ }
45556
+ if (is("SE-BOX-INVALID-CONTENT", e3)) {
45557
+ const lines = text.split(/\r?\n/);
45558
+ const curIdx = Math.max(0, e3.line - 1);
45559
+ const boxRe = /^(\s*)box\b/;
45560
+ let openIdx = -1;
45561
+ let openIndent = "";
45562
+ for (let i3 = curIdx; i3 >= 0; i3--) {
45563
+ const m3 = boxRe.exec(lines[i3] || "");
45564
+ if (m3) {
45565
+ openIdx = i3;
45566
+ openIndent = m3[1] || "";
45567
+ break;
45568
+ }
45569
+ }
45570
+ if (openIdx !== -1) {
45571
+ let endIdx = -1;
45572
+ for (let i3 = openIdx + 1; i3 < lines.length; i3++) {
45573
+ const trimmed = (lines[i3] || "").trim();
45574
+ if (trimmed === "end") {
45575
+ endIdx = i3;
45576
+ break;
45577
+ }
45578
+ }
45579
+ if (endIdx !== -1) {
45580
+ const invalidLines = [];
45581
+ for (let i3 = openIdx + 1; i3 < endIdx; i3++) {
45582
+ const raw = lines[i3] || "";
45583
+ const trimmed = raw.trim();
45584
+ if (trimmed === "")
45585
+ continue;
45586
+ if (!/^\s*(participant|actor)\b/i.test(raw)) {
45587
+ invalidLines.push(i3);
45588
+ }
45589
+ }
45590
+ if (invalidLines.length > 0) {
45591
+ const endIndent = openIndent;
45592
+ const movedContent = invalidLines.map((i3) => {
45593
+ const line = lines[i3] || "";
45594
+ const trimmed = line.trimStart();
45595
+ return endIndent + trimmed;
45596
+ }).join("\n") + "\n";
45597
+ for (let i3 = invalidLines.length - 1; i3 >= 0; i3--) {
45598
+ const idx = invalidLines[i3];
45599
+ edits.push({ start: { line: idx + 1, column: 1 }, end: { line: idx + 2, column: 1 }, newText: "" });
45600
+ }
45601
+ edits.push(insertAt(text, { line: endIdx + 2, column: 1 }, movedContent));
45602
+ }
45603
+ }
45604
+ }
45605
+ continue;
45606
+ }
45471
45607
  if (is("SE-BLOCK-MISSING-END", e3)) {
45472
45608
  const lines = text.split(/\r?\n/);
45473
45609
  const curIdx = Math.max(0, e3.line - 1);
@@ -45748,8 +45884,543 @@ var init_fixes = __esm({
45748
45884
  });
45749
45885
 
45750
45886
  // node_modules/@probelabs/maid/out/renderer/graph-builder.js
45887
+ var GraphBuilder;
45751
45888
  var init_graph_builder = __esm({
45752
45889
  "node_modules/@probelabs/maid/out/renderer/graph-builder.js"() {
45890
+ GraphBuilder = class {
45891
+ constructor() {
45892
+ this.nodes = /* @__PURE__ */ new Map();
45893
+ this.edges = [];
45894
+ this.nodeCounter = 0;
45895
+ this.edgeCounter = 0;
45896
+ this.subgraphs = [];
45897
+ this.currentSubgraphStack = [];
45898
+ this.classStyles = /* @__PURE__ */ new Map();
45899
+ this.nodeStyles = /* @__PURE__ */ new Map();
45900
+ this.nodeClasses = /* @__PURE__ */ new Map();
45901
+ }
45902
+ build(cst) {
45903
+ this.reset();
45904
+ if (!cst || !cst.children) {
45905
+ return {
45906
+ nodes: [],
45907
+ edges: [],
45908
+ direction: "TD",
45909
+ subgraphs: []
45910
+ };
45911
+ }
45912
+ const direction = this.extractDirection(cst);
45913
+ this.processStatements(cst);
45914
+ return {
45915
+ nodes: Array.from(this.nodes.values()),
45916
+ edges: this.edges,
45917
+ direction,
45918
+ subgraphs: this.subgraphs
45919
+ };
45920
+ }
45921
+ reset() {
45922
+ this.nodes.clear();
45923
+ this.edges = [];
45924
+ this.nodeCounter = 0;
45925
+ this.edgeCounter = 0;
45926
+ this.subgraphs = [];
45927
+ this.currentSubgraphStack = [];
45928
+ this.classStyles.clear();
45929
+ this.nodeStyles.clear();
45930
+ this.nodeClasses.clear();
45931
+ }
45932
+ extractDirection(cst) {
45933
+ const dirToken = cst.children?.Direction?.[0];
45934
+ const dir = dirToken?.image?.toUpperCase();
45935
+ switch (dir) {
45936
+ case "TB":
45937
+ case "TD":
45938
+ return "TD";
45939
+ case "BT":
45940
+ return "BT";
45941
+ case "LR":
45942
+ return "LR";
45943
+ case "RL":
45944
+ return "RL";
45945
+ default:
45946
+ return "TD";
45947
+ }
45948
+ }
45949
+ processStatements(cst) {
45950
+ const statements = cst.children?.statement;
45951
+ if (!statements)
45952
+ return;
45953
+ for (const stmt of statements) {
45954
+ if (stmt.children?.nodeStatement) {
45955
+ this.processNodeStatement(stmt.children.nodeStatement[0]);
45956
+ } else if (stmt.children?.subgraph) {
45957
+ this.processSubgraph(stmt.children.subgraph[0]);
45958
+ } else if (stmt.children?.classDefStatement) {
45959
+ this.processClassDef(stmt.children.classDefStatement[0]);
45960
+ } else if (stmt.children?.classStatement) {
45961
+ this.processClassAssign(stmt.children.classStatement[0]);
45962
+ } else if (stmt.children?.styleStatement) {
45963
+ this.processStyle(stmt.children.styleStatement[0]);
45964
+ }
45965
+ }
45966
+ }
45967
+ processNodeStatement(stmt) {
45968
+ const groups = stmt.children?.nodeOrParallelGroup;
45969
+ const links = stmt.children?.link;
45970
+ if (!groups || groups.length === 0)
45971
+ return;
45972
+ const sourceNodes = this.processNodeGroup(groups[0]);
45973
+ if (groups.length > 1 && links && links.length > 0) {
45974
+ const targetNodes = this.processNodeGroup(groups[1]);
45975
+ const linkInfo = this.extractLinkInfo(links[0]);
45976
+ for (const source of sourceNodes) {
45977
+ for (const target of targetNodes) {
45978
+ this.edges.push({
45979
+ id: `e${this.edgeCounter++}`,
45980
+ source,
45981
+ target,
45982
+ label: linkInfo.label,
45983
+ type: linkInfo.type,
45984
+ markerStart: linkInfo.markerStart,
45985
+ markerEnd: linkInfo.markerEnd
45986
+ });
45987
+ }
45988
+ }
45989
+ for (let i3 = 2; i3 < groups.length; i3++) {
45990
+ const nextNodes = this.processNodeGroup(groups[i3]);
45991
+ const nextLink = links[i3 - 1] ? this.extractLinkInfo(links[i3 - 1]) : linkInfo;
45992
+ for (const source of targetNodes) {
45993
+ for (const target of nextNodes) {
45994
+ this.edges.push({
45995
+ id: `e${this.edgeCounter++}`,
45996
+ source,
45997
+ target,
45998
+ label: nextLink.label,
45999
+ type: nextLink.type,
46000
+ markerStart: nextLink.markerStart,
46001
+ markerEnd: nextLink.markerEnd
46002
+ });
46003
+ }
46004
+ }
46005
+ targetNodes.length = 0;
46006
+ targetNodes.push(...nextNodes);
46007
+ }
46008
+ }
46009
+ }
46010
+ processNodeGroup(group) {
46011
+ const nodes = group.children?.node;
46012
+ if (!nodes)
46013
+ return [];
46014
+ const nodeIds = [];
46015
+ for (const node of nodes) {
46016
+ const nodeInfo = this.extractNodeInfo(node);
46017
+ if (nodeInfo) {
46018
+ const isSubgraph = this.subgraphs.some((sg) => sg.id === nodeInfo.id);
46019
+ if (!isSubgraph) {
46020
+ if (!this.nodes.has(nodeInfo.id)) {
46021
+ nodeInfo.style = this.computeNodeStyle(nodeInfo.id);
46022
+ this.nodes.set(nodeInfo.id, nodeInfo);
46023
+ } else {
46024
+ const existing = this.nodes.get(nodeInfo.id);
46025
+ if (nodeInfo.shape !== "rectangle" || nodeInfo.label !== nodeInfo.id) {
46026
+ if (nodeInfo.label !== nodeInfo.id) {
46027
+ existing.label = nodeInfo.label;
46028
+ }
46029
+ if (nodeInfo.shape !== "rectangle") {
46030
+ existing.shape = nodeInfo.shape;
46031
+ }
46032
+ }
46033
+ const merged = this.computeNodeStyle(nodeInfo.id);
46034
+ if (Object.keys(merged).length) {
46035
+ existing.style = { ...existing.style || {}, ...merged };
46036
+ }
46037
+ }
46038
+ if (this.currentSubgraphStack.length) {
46039
+ for (const sgId of this.currentSubgraphStack) {
46040
+ const subgraph = this.subgraphs.find((s3) => s3.id === sgId);
46041
+ if (subgraph && !subgraph.nodes.includes(nodeInfo.id)) {
46042
+ subgraph.nodes.push(nodeInfo.id);
46043
+ }
46044
+ }
46045
+ }
46046
+ }
46047
+ nodeIds.push(nodeInfo.id);
46048
+ }
46049
+ }
46050
+ return nodeIds;
46051
+ }
46052
+ extractNodeInfo(node) {
46053
+ const children = node.children;
46054
+ if (!children)
46055
+ return null;
46056
+ let id;
46057
+ if (children.nodeId) {
46058
+ id = children.nodeId[0].image;
46059
+ if (children.nodeIdSuffix) {
46060
+ id += children.nodeIdSuffix[0].image;
46061
+ }
46062
+ } else if (children.nodeIdNum) {
46063
+ id = children.nodeIdNum[0].image;
46064
+ } else if (children.Identifier) {
46065
+ id = children.Identifier[0].image;
46066
+ } else {
46067
+ return null;
46068
+ }
46069
+ let shape = "rectangle";
46070
+ let label = id;
46071
+ const shapeNode = children.nodeShape?.[0];
46072
+ if (shapeNode?.children) {
46073
+ const result = this.extractShapeAndLabel(shapeNode);
46074
+ shape = result.shape;
46075
+ if (result.label)
46076
+ label = result.label;
46077
+ }
46078
+ const clsTok = children.nodeClass?.[0];
46079
+ if (clsTok) {
46080
+ const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
46081
+ set.add(clsTok.image);
46082
+ this.nodeClasses.set(id, set);
46083
+ }
46084
+ return { id, label, shape };
46085
+ }
46086
+ extractShapeAndLabel(shapeNode) {
46087
+ const children = shapeNode.children;
46088
+ let shape = "rectangle";
46089
+ let label = "";
46090
+ const contentNodes = children?.nodeContent;
46091
+ if (contentNodes && contentNodes.length > 0) {
46092
+ label = this.extractTextContent(contentNodes[0]);
46093
+ }
46094
+ if (children?.SquareOpen) {
46095
+ shape = "rectangle";
46096
+ const contentNode = children.nodeContent?.[0];
46097
+ if (contentNode) {
46098
+ const c3 = contentNode.children;
46099
+ const tokTypes = ["ForwardSlash", "Backslash", "Identifier", "Text", "NumberLiteral", "RoundOpen", "RoundClose", "AngleLess", "AngleOpen", "Comma", "Colon", "Ampersand", "Semicolon", "TwoDashes", "Line", "ThickLine", "DottedLine"];
46100
+ const toks = [];
46101
+ for (const tt of tokTypes) {
46102
+ const arr = c3[tt];
46103
+ arr?.forEach((t3) => toks.push({ type: tt, t: t3, start: t3.startOffset ?? 0 }));
46104
+ }
46105
+ if (toks.length >= 2) {
46106
+ toks.sort((a3, b3) => a3.start - b3.start);
46107
+ const first2 = toks[0].type;
46108
+ const last2 = toks[toks.length - 1].type;
46109
+ if (first2 === "ForwardSlash" && last2 === "ForwardSlash" || first2 === "Backslash" && last2 === "Backslash") {
46110
+ shape = "parallelogram";
46111
+ } else if (first2 === "ForwardSlash" && last2 === "Backslash") {
46112
+ shape = "trapezoid";
46113
+ } else if (first2 === "Backslash" && last2 === "ForwardSlash") {
46114
+ shape = "trapezoidAlt";
46115
+ }
46116
+ }
46117
+ }
46118
+ } else if (children?.RoundOpen) {
46119
+ shape = "round";
46120
+ } else if (children?.DiamondOpen) {
46121
+ shape = "diamond";
46122
+ } else if (children?.DoubleRoundOpen) {
46123
+ shape = "circle";
46124
+ } else if (children?.StadiumOpen) {
46125
+ shape = "stadium";
46126
+ } else if (children?.HexagonOpen) {
46127
+ shape = "hexagon";
46128
+ } else if (children?.DoubleSquareOpen) {
46129
+ shape = "subroutine";
46130
+ } else if (children?.CylinderOpen) {
46131
+ shape = "cylinder";
46132
+ } else if (children?.TrapezoidOpen) {
46133
+ shape = "trapezoid";
46134
+ } else if (children?.ParallelogramOpen) {
46135
+ shape = "parallelogram";
46136
+ }
46137
+ return { shape, label };
46138
+ }
46139
+ extractTextContent(contentNode) {
46140
+ const children = contentNode.children;
46141
+ if (!children)
46142
+ return "";
46143
+ const tokenTypes = [
46144
+ "Text",
46145
+ "Identifier",
46146
+ "QuotedString",
46147
+ "NumberLiteral",
46148
+ "Ampersand",
46149
+ "Comma",
46150
+ "Colon",
46151
+ "Semicolon",
46152
+ "Dot",
46153
+ "Underscore",
46154
+ "Dash",
46155
+ "ForwardSlash",
46156
+ "Backslash",
46157
+ "AngleLess",
46158
+ "AngleOpen"
46159
+ ];
46160
+ const tokenWithPositions = [];
46161
+ for (const type of tokenTypes) {
46162
+ const tokens = children[type];
46163
+ if (tokens) {
46164
+ for (const token of tokens) {
46165
+ let text = token.image;
46166
+ if (type === "QuotedString" && text.startsWith('"') && text.endsWith('"')) {
46167
+ text = text.slice(1, -1);
46168
+ }
46169
+ if ((type === "ForwardSlash" || type === "Backslash") && tokenWithPositions.length === 0) {
46170
+ continue;
46171
+ }
46172
+ tokenWithPositions.push({
46173
+ text,
46174
+ startOffset: token.startOffset ?? 0,
46175
+ type
46176
+ });
46177
+ }
46178
+ }
46179
+ }
46180
+ tokenWithPositions.sort((a3, b3) => a3.startOffset - b3.startOffset);
46181
+ if (tokenWithPositions.length) {
46182
+ const first2 = tokenWithPositions[0];
46183
+ if (first2.type === "ForwardSlash" || first2.type === "Backslash") {
46184
+ tokenWithPositions.shift();
46185
+ }
46186
+ const last2 = tokenWithPositions[tokenWithPositions.length - 1];
46187
+ if (last2.type === "ForwardSlash" || last2.type === "Backslash") {
46188
+ tokenWithPositions.pop();
46189
+ }
46190
+ }
46191
+ const parts = tokenWithPositions.map((t3) => t3.text);
46192
+ if (children.Space) {
46193
+ return parts.join("");
46194
+ }
46195
+ return parts.join(" ").trim();
46196
+ }
46197
+ extractLinkInfo(link) {
46198
+ const children = link.children;
46199
+ let type = "arrow";
46200
+ let label;
46201
+ let markerStart = "none";
46202
+ let markerEnd = "none";
46203
+ if (children.BiDirectionalArrow) {
46204
+ type = "arrow";
46205
+ markerStart = "arrow";
46206
+ markerEnd = "arrow";
46207
+ } else if (children.CircleEndLine) {
46208
+ type = "open";
46209
+ markerStart = "circle";
46210
+ markerEnd = "circle";
46211
+ } else if (children.CrossEndLine) {
46212
+ type = "open";
46213
+ markerStart = "cross";
46214
+ markerEnd = "cross";
46215
+ } else if (children?.ArrowRight) {
46216
+ type = "arrow";
46217
+ markerEnd = "arrow";
46218
+ } else if (children?.ArrowLeft) {
46219
+ type = "arrow";
46220
+ markerStart = "arrow";
46221
+ } else if (children?.DottedArrowRight) {
46222
+ type = "dotted";
46223
+ markerEnd = "arrow";
46224
+ } else if (children?.DottedArrowLeft) {
46225
+ type = "dotted";
46226
+ markerStart = "arrow";
46227
+ } else if (children?.ThickArrowRight) {
46228
+ type = "thick";
46229
+ markerEnd = "arrow";
46230
+ } else if (children?.ThickArrowLeft) {
46231
+ type = "thick";
46232
+ markerStart = "arrow";
46233
+ } else if (children?.LinkRight || children?.LinkLeft || children?.Line || children?.TwoDashes || children?.DottedLine || children?.ThickLine) {
46234
+ if (children?.DottedLine)
46235
+ type = "dotted";
46236
+ else if (children?.ThickLine)
46237
+ type = "thick";
46238
+ else
46239
+ type = "open";
46240
+ } else if (children?.InvisibleLink) {
46241
+ type = "invisible";
46242
+ }
46243
+ if (markerEnd === "none" && (children?.ArrowRight || children.ThickArrowRight || children.DottedArrowRight)) {
46244
+ markerEnd = "arrow";
46245
+ }
46246
+ if (markerStart === "none" && (children?.ArrowLeft || children.ThickArrowLeft || children.DottedArrowLeft)) {
46247
+ markerStart = "arrow";
46248
+ }
46249
+ const textNode = children?.linkText?.[0];
46250
+ if (textNode) {
46251
+ label = this.extractTextContent(textNode);
46252
+ } else if (children.linkTextInline?.[0]) {
46253
+ label = this.extractTextContent(children.linkTextInline[0]);
46254
+ } else if (children.inlineCarrier?.[0]) {
46255
+ const token = children.inlineCarrier[0];
46256
+ const raw = token.image.trim();
46257
+ if (raw.startsWith("-.") && raw.endsWith(".-")) {
46258
+ type = "dotted";
46259
+ } else if (raw.startsWith("==") && raw.endsWith("==")) {
46260
+ type = "thick";
46261
+ } else if (raw.startsWith("--") && raw.endsWith("--")) {
46262
+ }
46263
+ if (children.ArrowRight || children.DottedArrowRight || children.ThickArrowRight) {
46264
+ markerEnd = "arrow";
46265
+ }
46266
+ if (children.ArrowLeft || children.DottedArrowLeft || children.ThickArrowLeft) {
46267
+ markerStart = "arrow";
46268
+ }
46269
+ const strip = (str) => {
46270
+ if (str.startsWith("-.") && str.endsWith(".-") || str.startsWith("==") && str.endsWith("==") || str.startsWith("--") && str.endsWith("--")) {
46271
+ return str.slice(2, -2).trim();
46272
+ }
46273
+ return str;
46274
+ };
46275
+ label = strip(raw);
46276
+ }
46277
+ return { type, label, markerStart, markerEnd };
46278
+ }
46279
+ processSubgraph(subgraph) {
46280
+ const children = subgraph.children;
46281
+ let id = `subgraph_${this.subgraphs.length}`;
46282
+ let label;
46283
+ const idToken = children?.subgraphId?.[0] || children?.Identifier?.[0];
46284
+ if (idToken) {
46285
+ id = idToken.image;
46286
+ }
46287
+ if (children?.SquareOpen && children?.nodeContent) {
46288
+ label = this.extractTextContent(children.nodeContent[0]);
46289
+ } else if (children.subgraphTitleQ?.[0]) {
46290
+ const qt = children.subgraphTitleQ[0];
46291
+ const img = qt.image;
46292
+ label = img && img.length >= 2 && (img.startsWith('"') || img.startsWith("'")) ? img.slice(1, -1) : img;
46293
+ } else if (children?.subgraphLabel) {
46294
+ label = this.extractTextContent(children.subgraphLabel[0]);
46295
+ }
46296
+ if (!label && id !== `subgraph_${this.subgraphs.length}`) {
46297
+ label = id;
46298
+ }
46299
+ const parent = this.currentSubgraphStack.length ? this.currentSubgraphStack[this.currentSubgraphStack.length - 1] : void 0;
46300
+ const sg = { id, label, nodes: [], parent };
46301
+ this.subgraphs.push(sg);
46302
+ this.currentSubgraphStack.push(id);
46303
+ const statements = children?.subgraphStatement;
46304
+ if (statements) {
46305
+ for (const stmt of statements) {
46306
+ if (stmt.children?.nodeStatement) {
46307
+ this.processNodeStatement(stmt.children.nodeStatement[0]);
46308
+ } else if (stmt.children?.subgraph) {
46309
+ this.processSubgraph(stmt.children.subgraph[0]);
46310
+ }
46311
+ }
46312
+ }
46313
+ this.currentSubgraphStack.pop();
46314
+ }
46315
+ // ---- Styling helpers ----
46316
+ processClassDef(cst) {
46317
+ const idTok = cst.children?.Identifier?.[0];
46318
+ if (!idTok)
46319
+ return;
46320
+ const className = idTok.image;
46321
+ const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
46322
+ if (Object.keys(props).length) {
46323
+ this.classStyles.set(className, props);
46324
+ for (const [nodeId, classes] of this.nodeClasses.entries()) {
46325
+ if (classes.has(className)) {
46326
+ const node = this.nodes.get(nodeId);
46327
+ if (node) {
46328
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
46329
+ }
46330
+ }
46331
+ }
46332
+ }
46333
+ }
46334
+ processClassAssign(cst) {
46335
+ const ids = cst.children?.Identifier || [];
46336
+ if (!ids.length)
46337
+ return;
46338
+ const classNameTok = cst.children.className?.[0];
46339
+ const className = classNameTok?.image || ids[ids.length - 1].image;
46340
+ const nodeIds = classNameTok ? ids.slice(0, -1) : ids.slice(0, -1);
46341
+ for (const tok of nodeIds) {
46342
+ const id = tok.image;
46343
+ const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
46344
+ set.add(className);
46345
+ this.nodeClasses.set(id, set);
46346
+ const node = this.nodes.get(id);
46347
+ if (node) {
46348
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(id) };
46349
+ }
46350
+ }
46351
+ }
46352
+ processStyle(cst) {
46353
+ const idTok = cst.children?.Identifier?.[0];
46354
+ if (!idTok)
46355
+ return;
46356
+ const nodeId = idTok.image;
46357
+ const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
46358
+ if (Object.keys(props).length) {
46359
+ this.nodeStyles.set(nodeId, props);
46360
+ const node = this.nodes.get(nodeId);
46361
+ if (node) {
46362
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
46363
+ }
46364
+ }
46365
+ }
46366
+ collectStyleProps(cst, opts = {}) {
46367
+ const tokens = [];
46368
+ const ch = cst.children || {};
46369
+ const push = (arr, type = "t") => arr?.forEach((t3) => tokens.push({ text: t3.image, startOffset: t3.startOffset ?? 0, type }));
46370
+ push(ch.Text, "Text");
46371
+ push(ch.Identifier, "Identifier");
46372
+ push(ch.ColorValue, "Color");
46373
+ push(ch.Colon, "Colon");
46374
+ push(ch.Comma, "Comma");
46375
+ push(ch.NumberLiteral, "Number");
46376
+ tokens.sort((a3, b3) => a3.startOffset - b3.startOffset);
46377
+ if (opts.skipFirstIdentifier) {
46378
+ const idx = tokens.findIndex((t3) => t3.type === "Identifier");
46379
+ if (idx >= 0)
46380
+ tokens.splice(idx, 1);
46381
+ }
46382
+ const joined = tokens.map((t3) => t3.text).join("");
46383
+ const props = {};
46384
+ for (const seg of joined.split(",").map((s3) => s3.trim()).filter(Boolean)) {
46385
+ const [k3, v3] = seg.split(":");
46386
+ if (k3 && v3)
46387
+ props[k3.trim()] = v3.trim();
46388
+ }
46389
+ return props;
46390
+ }
46391
+ computeNodeStyle(nodeId) {
46392
+ const out = {};
46393
+ const classes = this.nodeClasses.get(nodeId);
46394
+ if (classes) {
46395
+ for (const c3 of classes) {
46396
+ const s3 = this.classStyles.get(c3);
46397
+ if (s3)
46398
+ Object.assign(out, this.normalizeStyle(s3));
46399
+ }
46400
+ }
46401
+ const direct = this.nodeStyles.get(nodeId);
46402
+ if (direct)
46403
+ Object.assign(out, this.normalizeStyle(direct));
46404
+ return out;
46405
+ }
46406
+ normalizeStyle(s3) {
46407
+ const out = {};
46408
+ for (const [kRaw, vRaw] of Object.entries(s3)) {
46409
+ const k3 = kRaw.trim().toLowerCase();
46410
+ const v3 = vRaw.trim();
46411
+ if (k3 === "stroke-width") {
46412
+ const num = parseFloat(v3);
46413
+ if (!Number.isNaN(num))
46414
+ out.strokeWidth = num;
46415
+ } else if (k3 === "stroke") {
46416
+ out.stroke = v3;
46417
+ } else if (k3 === "fill") {
46418
+ out.fill = v3;
46419
+ }
46420
+ }
46421
+ return out;
46422
+ }
46423
+ };
45753
46424
  }
45754
46425
  });
45755
46426
 
@@ -53432,36 +54103,2786 @@ var require_dagre = __commonJS({
53432
54103
  });
53433
54104
 
53434
54105
  // node_modules/@probelabs/maid/out/renderer/layout.js
53435
- var import_dagre;
54106
+ var import_dagre, DagreLayoutEngine;
53436
54107
  var init_layout = __esm({
53437
54108
  "node_modules/@probelabs/maid/out/renderer/layout.js"() {
53438
54109
  import_dagre = __toESM(require_dagre(), 1);
54110
+ DagreLayoutEngine = class {
54111
+ constructor() {
54112
+ this.nodeWidth = 120;
54113
+ this.nodeHeight = 50;
54114
+ this.rankSep = 50;
54115
+ this.nodeSep = 50;
54116
+ this.edgeSep = 10;
54117
+ }
54118
+ layout(graph) {
54119
+ const g3 = new import_dagre.default.graphlib.Graph();
54120
+ const hasClusters = !!(graph.subgraphs && graph.subgraphs.length > 0);
54121
+ const dir = this.mapDirection(graph.direction);
54122
+ let ranksep = this.rankSep;
54123
+ let nodesep = this.nodeSep;
54124
+ if (hasClusters) {
54125
+ if (dir === "LR" || dir === "RL") {
54126
+ ranksep += 20;
54127
+ nodesep += 70;
54128
+ } else {
54129
+ ranksep += 70;
54130
+ nodesep += 20;
54131
+ }
54132
+ }
54133
+ const graphConfig = {
54134
+ rankdir: dir,
54135
+ ranksep,
54136
+ nodesep,
54137
+ edgesep: this.edgeSep,
54138
+ marginx: 20,
54139
+ marginy: 20
54140
+ };
54141
+ if (hasClusters && (dir === "LR" || dir === "RL")) {
54142
+ graphConfig.ranker = "longest-path";
54143
+ graphConfig.acyclicer = "greedy";
54144
+ }
54145
+ if (hasClusters) {
54146
+ graphConfig.compound = true;
54147
+ }
54148
+ g3.setGraph(graphConfig);
54149
+ g3.setDefaultEdgeLabel(() => ({}));
54150
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
54151
+ for (const subgraph of graph.subgraphs) {
54152
+ g3.setNode(subgraph.id, { label: subgraph.label || subgraph.id, clusterLabelPos: "top" });
54153
+ }
54154
+ }
54155
+ for (const node of graph.nodes) {
54156
+ const dimensions = this.calculateNodeDimensions(node.label, node.shape);
54157
+ g3.setNode(node.id, {
54158
+ width: dimensions.width,
54159
+ height: dimensions.height,
54160
+ label: node.label,
54161
+ shape: node.shape
54162
+ });
54163
+ }
54164
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
54165
+ for (const subgraph of graph.subgraphs) {
54166
+ for (const nodeId of subgraph.nodes) {
54167
+ if (g3.hasNode(nodeId)) {
54168
+ try {
54169
+ g3.setParent(nodeId, subgraph.id);
54170
+ } catch {
54171
+ }
54172
+ }
54173
+ }
54174
+ if (subgraph.parent && g3.hasNode(subgraph.parent)) {
54175
+ try {
54176
+ g3.setParent(subgraph.id, subgraph.parent);
54177
+ } catch {
54178
+ }
54179
+ }
54180
+ }
54181
+ }
54182
+ for (const edge of graph.edges) {
54183
+ g3.setEdge(edge.source, edge.target, {
54184
+ label: edge.label,
54185
+ width: edge.label ? edge.label.length * 8 : 0,
54186
+ height: edge.label ? 20 : 0
54187
+ });
54188
+ }
54189
+ import_dagre.default.layout(g3);
54190
+ const graphInfo = g3.graph();
54191
+ const layoutNodes = [];
54192
+ const layoutEdges = [];
54193
+ for (const node of graph.nodes) {
54194
+ const nodeLayout = g3.node(node.id);
54195
+ if (nodeLayout) {
54196
+ layoutNodes.push({
54197
+ ...node,
54198
+ x: nodeLayout.x - nodeLayout.width / 2,
54199
+ y: nodeLayout.y - nodeLayout.height / 2,
54200
+ width: nodeLayout.width,
54201
+ height: nodeLayout.height
54202
+ });
54203
+ }
54204
+ }
54205
+ const layoutSubgraphs = [];
54206
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
54207
+ for (const sg of graph.subgraphs) {
54208
+ const members = layoutNodes.filter((nd) => sg.nodes.includes(nd.id));
54209
+ if (members.length) {
54210
+ const minX = Math.min(...members.map((m3) => m3.x));
54211
+ const minY = Math.min(...members.map((m3) => m3.y));
54212
+ const maxX = Math.max(...members.map((m3) => m3.x + m3.width));
54213
+ const maxY = Math.max(...members.map((m3) => m3.y + m3.height));
54214
+ const pad = 30;
54215
+ layoutSubgraphs.push({
54216
+ id: sg.id,
54217
+ label: sg.label || sg.id,
54218
+ x: minX - pad,
54219
+ y: minY - pad - 18,
54220
+ // space for title
54221
+ width: maxX - minX + pad * 2,
54222
+ height: maxY - minY + pad * 2 + 18,
54223
+ parent: sg.parent
54224
+ });
54225
+ }
54226
+ }
54227
+ const byId = Object.fromEntries(layoutSubgraphs.map((s3) => [s3.id, s3]));
54228
+ for (const sg of layoutSubgraphs) {
54229
+ if (!sg.parent)
54230
+ continue;
54231
+ const p3 = byId[sg.parent];
54232
+ if (!p3)
54233
+ continue;
54234
+ const minX = Math.min(p3.x, sg.x);
54235
+ const minY = Math.min(p3.y, sg.y);
54236
+ const maxX = Math.max(p3.x + p3.width, sg.x + sg.width);
54237
+ const maxY = Math.max(p3.y + p3.height, sg.y + sg.height);
54238
+ p3.x = minX;
54239
+ p3.y = minY;
54240
+ p3.width = maxX - minX;
54241
+ p3.height = maxY - minY;
54242
+ }
54243
+ }
54244
+ const subgraphById = Object.fromEntries(layoutSubgraphs.map((sg) => [sg.id, sg]));
54245
+ for (const edge of graph.edges) {
54246
+ const edgeLayout = g3.edge(edge.source, edge.target);
54247
+ let pts = edgeLayout && Array.isArray(edgeLayout.points) ? edgeLayout.points.slice() : [];
54248
+ const hasNaN = pts.some((p3) => !Number.isFinite(p3.x) || !Number.isFinite(p3.y));
54249
+ const srcSg = subgraphById[edge.source];
54250
+ const dstSg = subgraphById[edge.target];
54251
+ let synthesized = false;
54252
+ if (!pts.length || hasNaN || srcSg || dstSg) {
54253
+ const rankdir = this.mapDirection(graph.direction);
54254
+ const getNode = (id) => {
54255
+ const n3 = g3.node(id);
54256
+ if (!n3)
54257
+ return void 0;
54258
+ return {
54259
+ id,
54260
+ label: n3.label || id,
54261
+ shape: n3.shape || "rectangle",
54262
+ x: n3.x - n3.width / 2,
54263
+ y: n3.y - n3.height / 2,
54264
+ width: n3.width,
54265
+ height: n3.height,
54266
+ style: {}
54267
+ };
54268
+ };
54269
+ const start = srcSg ? this.clusterAnchor(srcSg, rankdir, "out") : this.nodeAnchor(getNode(edge.source), rankdir, "out");
54270
+ const end = dstSg ? this.clusterAnchor(dstSg, rankdir, "in") : this.nodeAnchor(getNode(edge.target), rankdir, "in");
54271
+ if (start && end) {
54272
+ const PAD = 20;
54273
+ const horizontallyAdjacent = srcSg && dstSg && Math.abs(srcSg.x - dstSg.x) > Math.abs(srcSg.y - dstSg.y);
54274
+ const horizontalSubgraphs = horizontallyAdjacent;
54275
+ if (rankdir === "LR" || rankdir === "RL") {
54276
+ const outX = start.x + (rankdir === "LR" ? PAD : -PAD);
54277
+ const inX = end.x + (rankdir === "LR" ? -PAD : PAD);
54278
+ const startOut = { x: srcSg ? outX : start.x, y: start.y };
54279
+ const endPre = { x: dstSg ? inX : end.x, y: end.y };
54280
+ const alpha = 0.68;
54281
+ const midX = startOut.x + (endPre.x - startOut.x) * alpha;
54282
+ const m1 = { x: midX, y: startOut.y };
54283
+ const m22 = { x: midX, y: endPre.y };
54284
+ pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
54285
+ } else {
54286
+ if (horizontalSubgraphs && srcSg && dstSg) {
54287
+ const midY = (srcSg.y + srcSg.height / 2 + dstSg.y + dstSg.height / 2) / 2;
54288
+ if (srcSg.x < dstSg.x) {
54289
+ const startX = srcSg.x + srcSg.width;
54290
+ const endX = dstSg.x;
54291
+ pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
54292
+ } else {
54293
+ const startX = srcSg.x;
54294
+ const endX = dstSg.x + dstSg.width;
54295
+ pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
54296
+ }
54297
+ } else {
54298
+ const outY = start.y + (rankdir === "TD" ? PAD : -PAD);
54299
+ const inY = end.y + (rankdir === "TD" ? -PAD : PAD);
54300
+ const startOut = { x: start.x, y: srcSg ? outY : start.y };
54301
+ const endPre = { x: end.x, y: dstSg ? inY : end.y };
54302
+ const alpha = 0.68;
54303
+ const midY = startOut.y + (endPre.y - startOut.y) * alpha;
54304
+ const m1 = { x: startOut.x, y: midY };
54305
+ const m22 = { x: endPre.x, y: midY };
54306
+ pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
54307
+ }
54308
+ }
54309
+ synthesized = true;
54310
+ }
54311
+ }
54312
+ if (pts.length) {
54313
+ layoutEdges.push({ ...edge, points: pts, pathMode: synthesized ? "orthogonal" : "smooth" });
54314
+ }
54315
+ }
54316
+ const rawW = graphInfo.width;
54317
+ const rawH = graphInfo.height;
54318
+ const w3 = Number.isFinite(rawW) && rawW > 0 ? rawW : 800;
54319
+ const h3 = Number.isFinite(rawH) && rawH > 0 ? rawH : 600;
54320
+ return {
54321
+ nodes: layoutNodes,
54322
+ edges: layoutEdges,
54323
+ width: w3,
54324
+ height: h3,
54325
+ subgraphs: layoutSubgraphs
54326
+ };
54327
+ }
54328
+ mapDirection(direction) {
54329
+ switch (direction) {
54330
+ case "TB":
54331
+ case "TD":
54332
+ return "TB";
54333
+ case "BT":
54334
+ return "BT";
54335
+ case "LR":
54336
+ return "LR";
54337
+ case "RL":
54338
+ return "RL";
54339
+ default:
54340
+ return "TB";
54341
+ }
54342
+ }
54343
+ calculateNodeDimensions(label, shape) {
54344
+ const charWidth = 7;
54345
+ const padding = 20;
54346
+ const minWidth = 80;
54347
+ const minHeight = 40;
54348
+ const maxWidth = 240;
54349
+ const lineHeight = 18;
54350
+ const explicitLines = label.split(/<\s*br\s*\/?\s*>/i);
54351
+ const hasExplicitBreaks = explicitLines.length > 1;
54352
+ let width;
54353
+ let lines;
54354
+ if (hasExplicitBreaks) {
54355
+ const maxLineLength = Math.max(...explicitLines.map((line) => line.length));
54356
+ width = Math.min(Math.max(maxLineLength * charWidth + padding * 2, minWidth), maxWidth);
54357
+ lines = explicitLines.length;
54358
+ } else {
54359
+ width = Math.min(Math.max(label.length * charWidth + padding * 2, minWidth), maxWidth);
54360
+ const charsPerLine = Math.max(1, Math.floor((width - padding * 2) / charWidth));
54361
+ lines = Math.ceil(label.length / charsPerLine);
54362
+ }
54363
+ let height = Math.max(lines * lineHeight + padding, minHeight);
54364
+ switch (shape) {
54365
+ case "circle":
54366
+ const size = Math.max(width, height);
54367
+ width = size;
54368
+ height = size;
54369
+ break;
54370
+ case "diamond": {
54371
+ const size2 = Math.max(width, height) * 1.2;
54372
+ width = size2;
54373
+ height = size2;
54374
+ break;
54375
+ }
54376
+ case "hexagon":
54377
+ width *= 1.3;
54378
+ height *= 1.2;
54379
+ break;
54380
+ case "stadium":
54381
+ width *= 1.2;
54382
+ break;
54383
+ case "cylinder":
54384
+ height *= 1.5;
54385
+ break;
54386
+ case "subroutine":
54387
+ case "double":
54388
+ width += 10;
54389
+ height += 10;
54390
+ break;
54391
+ case "parallelogram":
54392
+ case "trapezoid":
54393
+ width *= 1.3;
54394
+ break;
54395
+ }
54396
+ return { width: Math.round(width), height: Math.round(height) };
54397
+ }
54398
+ clusterAnchor(sg, rankdir, mode) {
54399
+ switch (rankdir) {
54400
+ case "LR":
54401
+ return { x: mode === "out" ? sg.x + sg.width : sg.x, y: sg.y + sg.height / 2 };
54402
+ case "RL":
54403
+ return { x: mode === "out" ? sg.x : sg.x + sg.width, y: sg.y + sg.height / 2 };
54404
+ case "BT":
54405
+ return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y : sg.y + sg.height };
54406
+ case "TB":
54407
+ default:
54408
+ return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y + sg.height : sg.y };
54409
+ }
54410
+ }
54411
+ nodeAnchor(n3, rankdir, mode) {
54412
+ if (!n3)
54413
+ return { x: 0, y: 0 };
54414
+ switch (rankdir) {
54415
+ case "LR":
54416
+ return { x: mode === "in" ? n3.x : n3.x + n3.width, y: n3.y + n3.height / 2 };
54417
+ case "RL":
54418
+ return { x: mode === "in" ? n3.x + n3.width : n3.x, y: n3.y + n3.height / 2 };
54419
+ case "BT":
54420
+ return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y + n3.height : n3.y };
54421
+ case "TB":
54422
+ default:
54423
+ return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y : n3.y + n3.height };
54424
+ }
54425
+ }
54426
+ };
54427
+ }
54428
+ });
54429
+
54430
+ // node_modules/@probelabs/maid/out/renderer/arrow-utils.js
54431
+ function triangleAtEnd(start, end, color = "#333", length = 8, width = 6) {
54432
+ const vx = end.x - start.x;
54433
+ const vy = end.y - start.y;
54434
+ const len = Math.hypot(vx, vy) || 1;
54435
+ const ux = vx / len;
54436
+ const uy = vy / len;
54437
+ const nx = -uy;
54438
+ const ny = ux;
54439
+ const baseX = end.x - ux * length;
54440
+ const baseY = end.y - uy * length;
54441
+ const p2x = baseX + nx * (width / 2), p2y = baseY + ny * (width / 2);
54442
+ const p3x = baseX - nx * (width / 2), p3y = baseY - ny * (width / 2);
54443
+ return `<path d="M${end.x},${end.y} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
54444
+ }
54445
+ function triangleAtStart(first2, second, color = "#333", length = 8, width = 6) {
54446
+ const vx = second.x - first2.x;
54447
+ const vy = second.y - first2.y;
54448
+ const len = Math.hypot(vx, vy) || 1;
54449
+ const ux = vx / len;
54450
+ const uy = vy / len;
54451
+ const nx = -uy;
54452
+ const ny = ux;
54453
+ const tipX = first2.x - ux * length;
54454
+ const tipY = first2.y - uy * length;
54455
+ const p2x = first2.x + nx * (width / 2), p2y = first2.y + ny * (width / 2);
54456
+ const p3x = first2.x - nx * (width / 2), p3y = first2.y - ny * (width / 2);
54457
+ return `<path d="M${tipX},${tipY} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
54458
+ }
54459
+ var init_arrow_utils = __esm({
54460
+ "node_modules/@probelabs/maid/out/renderer/arrow-utils.js"() {
54461
+ }
54462
+ });
54463
+
54464
+ // node_modules/@probelabs/maid/out/renderer/styles.js
54465
+ function buildSharedCss(opts = {}) {
54466
+ const fontFamily = opts.fontFamily || "Arial, sans-serif";
54467
+ const fontSize = opts.fontSize ?? 14;
54468
+ const nodeFill = opts.nodeFill || "#eef0ff";
54469
+ const nodeStroke = opts.nodeStroke || "#3f3f3f";
54470
+ const edgeStroke = opts.edgeStroke || "#555555";
54471
+ return `
54472
+ .node-shape { fill: ${nodeFill}; stroke: ${nodeStroke}; stroke-width: 1px; }
54473
+ .node-label { fill: #333; font-family: ${fontFamily}; font-size: ${fontSize}px; }
54474
+ .edge-path { stroke: ${edgeStroke}; stroke-width: 2px; fill: none; }
54475
+ .edge-label-bg { fill: rgba(232,232,232, 0.8); opacity: 0.5; }
54476
+ .edge-label-text { fill: #333; font-family: ${fontFamily}; font-size: ${Math.max(10, fontSize - 2)}px; }
54477
+
54478
+ /* Cluster (flowchart + sequence blocks) */
54479
+ .cluster-bg { fill: #ffffde; }
54480
+ .cluster-border { fill: none; stroke: #aaaa33; stroke-width: 1px; }
54481
+ .cluster-title-bg { fill: rgba(255,255,255,0.8); }
54482
+ .cluster-label-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
54483
+
54484
+ /* Notes */
54485
+ .note { fill: #fff5ad; stroke: #aaaa33; stroke-width: 1px; }
54486
+ .note-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
54487
+
54488
+ /* Sequence-specific add-ons (safe for flowcharts too) */
54489
+ .actor-rect { fill: #eaeaea; stroke: #666; stroke-width: 1.5px; }
54490
+ .actor-label { fill: #111; font-family: ${fontFamily}; font-size: 16px; }
54491
+ .lifeline { stroke: #999; stroke-width: 0.5px; }
54492
+ .activation { fill: #f4f4f4; stroke: #666; stroke-width: 1px; }
54493
+ .msg-line { stroke: #333; stroke-width: 1.5px; fill: none; }
54494
+ .msg-line.dotted { stroke-dasharray: 2 2; }
54495
+ .msg-line.thick { stroke-width: 3px; }
54496
+ .msg-label { fill: #333; font-family: ${fontFamily}; font-size: 12px; dominant-baseline: middle; }
54497
+ .msg-label-bg { fill: #ffffff; stroke: #cccccc; stroke-width: 1px; rx: 3; }
54498
+ `;
54499
+ }
54500
+ var init_styles = __esm({
54501
+ "node_modules/@probelabs/maid/out/renderer/styles.js"() {
54502
+ }
54503
+ });
54504
+
54505
+ // node_modules/@probelabs/maid/out/renderer/utils.js
54506
+ function escapeXml(text) {
54507
+ return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&apos;");
54508
+ }
54509
+ function measureText(text, fontSize = 12) {
54510
+ const avg = 0.6 * fontSize;
54511
+ return Math.max(0, Math.round(text.length * avg));
54512
+ }
54513
+ function palette(index) {
54514
+ if (index < DEFAULT_PALETTE.length)
54515
+ return DEFAULT_PALETTE[index];
54516
+ const i3 = index - DEFAULT_PALETTE.length;
54517
+ const hue = i3 * 47 % 360;
54518
+ return `hsl(${hue} 60% 55%)`;
54519
+ }
54520
+ function formatNumber(n3) {
54521
+ if (Number.isInteger(n3))
54522
+ return String(n3);
54523
+ return (Math.round(n3 * 100) / 100).toString();
54524
+ }
54525
+ function formatPercent(value, total) {
54526
+ if (!(total > 0))
54527
+ return "0%";
54528
+ const p3 = value / total * 100;
54529
+ return `${Math.round(p3)}%`;
54530
+ }
54531
+ var DEFAULT_PALETTE;
54532
+ var init_utils4 = __esm({
54533
+ "node_modules/@probelabs/maid/out/renderer/utils.js"() {
54534
+ DEFAULT_PALETTE = [
54535
+ "#ECECFF",
54536
+ "#ffffde",
54537
+ "hsl(80, 100%, 56.2745098039%)",
54538
+ "hsl(240, 100%, 86.2745098039%)",
54539
+ "hsl(60, 100%, 63.5294117647%)",
54540
+ "hsl(80, 100%, 76.2745098039%)",
54541
+ "hsl(300, 100%, 76.2745098039%)",
54542
+ "hsl(180, 100%, 56.2745098039%)",
54543
+ "hsl(0, 100%, 56.2745098039%)",
54544
+ "hsl(300, 100%, 56.2745098039%)",
54545
+ "hsl(150, 100%, 56.2745098039%)",
54546
+ "hsl(0, 100%, 66.2745098039%)"
54547
+ ];
53439
54548
  }
53440
54549
  });
53441
54550
 
53442
- // node_modules/@probelabs/maid/out/renderer/svg-generator.js
53443
- var init_svg_generator = __esm({
53444
- "node_modules/@probelabs/maid/out/renderer/svg-generator.js"() {
54551
+ // node_modules/@probelabs/maid/out/renderer/block-utils.js
54552
+ function blockBackground(x3, y2, width, height, radius = 0) {
54553
+ return `<g class="cluster-bg-layer" transform="translate(${x3},${y2})">
54554
+ <rect class="cluster-bg" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>
54555
+ </g>`;
54556
+ }
54557
+ function blockOverlay(x3, y2, width, height, title, branchYs = [], titleYOffset = 0, align = "center", branchAlign = "left", radius = 0) {
54558
+ const parts = [];
54559
+ parts.push(`<g class="cluster-overlay" transform="translate(${x3},${y2})">`);
54560
+ parts.push(`<rect class="cluster-border" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>`);
54561
+ const titleText = title ? escapeXml(title) : "";
54562
+ if (titleText) {
54563
+ const titleW = Math.max(24, measureText(titleText, 12) + 10);
54564
+ const yBg = -2 + titleYOffset;
54565
+ const yText = 11 + titleYOffset;
54566
+ if (align === "left") {
54567
+ const xBg = 6;
54568
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
54569
+ parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yText}" text-anchor="start">${titleText}</text>`);
54570
+ } else {
54571
+ const xBg = 6;
54572
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
54573
+ parts.push(`<text class="cluster-label-text" x="${xBg + titleW / 2}" y="${yText}" text-anchor="middle">${titleText}</text>`);
54574
+ }
54575
+ }
54576
+ for (const br of branchYs) {
54577
+ const yRel = br.y - y2;
54578
+ parts.push(`<line x1="0" y1="${yRel}" x2="${width}" y2="${yRel}" class="cluster-border" />`);
54579
+ if (br.title) {
54580
+ const text = escapeXml(br.title);
54581
+ const bw = Math.max(24, measureText(text, 12) + 10);
54582
+ const xBg = 6;
54583
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yRel - 10}" width="${bw}" height="18" rx="3"/>`);
54584
+ if (branchAlign === "left") {
54585
+ parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yRel + 1}" text-anchor="start">${text}</text>`);
54586
+ } else {
54587
+ parts.push(`<text class="cluster-label-text" x="${xBg + bw / 2}" y="${yRel + 1}" text-anchor="middle">${text}</text>`);
54588
+ }
54589
+ }
53445
54590
  }
53446
- });
53447
-
53448
- // node_modules/@probelabs/maid/out/renderer/dot-renderer.js
53449
- var init_dot_renderer = __esm({
53450
- "node_modules/@probelabs/maid/out/renderer/dot-renderer.js"() {
54591
+ parts.push("</g>");
54592
+ return parts.join("\n");
54593
+ }
54594
+ var init_block_utils = __esm({
54595
+ "node_modules/@probelabs/maid/out/renderer/block-utils.js"() {
54596
+ init_utils4();
53451
54597
  }
53452
54598
  });
53453
54599
 
53454
- // node_modules/@probelabs/maid/out/renderer/index.js
53455
- var init_renderer = __esm({
53456
- "node_modules/@probelabs/maid/out/renderer/index.js"() {
53457
- init_lexer2();
53458
- init_parser2();
53459
- init_graph_builder();
53460
- init_layout();
53461
- init_svg_generator();
53462
- init_layout();
53463
- init_svg_generator();
53464
- init_dot_renderer();
54600
+ // node_modules/@probelabs/maid/out/renderer/svg-generator.js
54601
+ var SVGRenderer;
54602
+ var init_svg_generator = __esm({
54603
+ "node_modules/@probelabs/maid/out/renderer/svg-generator.js"() {
54604
+ init_arrow_utils();
54605
+ init_styles();
54606
+ init_block_utils();
54607
+ SVGRenderer = class {
54608
+ constructor() {
54609
+ this.padding = 20;
54610
+ this.fontSize = 14;
54611
+ this.fontFamily = "Arial, sans-serif";
54612
+ this.defaultStroke = "#3f3f3f";
54613
+ this.defaultFill = "#eef0ff";
54614
+ this.arrowStroke = "#555555";
54615
+ this.arrowMarkerSize = 9;
54616
+ }
54617
+ render(layout) {
54618
+ let minX = Infinity;
54619
+ let minY = Infinity;
54620
+ let maxX = -Infinity;
54621
+ let maxY = -Infinity;
54622
+ for (const n3 of layout.nodes) {
54623
+ minX = Math.min(minX, n3.x);
54624
+ minY = Math.min(minY, n3.y);
54625
+ maxX = Math.max(maxX, n3.x + n3.width);
54626
+ maxY = Math.max(maxY, n3.y + n3.height);
54627
+ }
54628
+ if (layout.subgraphs) {
54629
+ for (const sg of layout.subgraphs) {
54630
+ minX = Math.min(minX, sg.x);
54631
+ minY = Math.min(minY, sg.y);
54632
+ maxX = Math.max(maxX, sg.x + sg.width);
54633
+ maxY = Math.max(maxY, sg.y + sg.height);
54634
+ }
54635
+ }
54636
+ for (const e3 of layout.edges) {
54637
+ if (e3.points)
54638
+ for (const p3 of e3.points) {
54639
+ minX = Math.min(minX, p3.x);
54640
+ minY = Math.min(minY, p3.y);
54641
+ maxX = Math.max(maxX, p3.x);
54642
+ maxY = Math.max(maxY, p3.y);
54643
+ }
54644
+ }
54645
+ if (!isFinite(minX)) {
54646
+ minX = 0;
54647
+ }
54648
+ if (!isFinite(minY)) {
54649
+ minY = 0;
54650
+ }
54651
+ if (!isFinite(maxX)) {
54652
+ maxX = layout.width;
54653
+ }
54654
+ if (!isFinite(maxY)) {
54655
+ maxY = layout.height;
54656
+ }
54657
+ const extraPadX = Math.max(0, -Math.floor(minX) + 1);
54658
+ const extraPadY = Math.max(0, -Math.floor(minY) + 1);
54659
+ const padX = this.padding + extraPadX;
54660
+ const padY = this.padding + extraPadY;
54661
+ const bboxWidth = Math.ceil(maxX) - Math.min(0, Math.floor(minX));
54662
+ const bboxHeight = Math.ceil(maxY) - Math.min(0, Math.floor(minY));
54663
+ const width = bboxWidth + this.padding * 2 + extraPadX;
54664
+ const height = bboxHeight + this.padding * 2 + extraPadY;
54665
+ const elements = [];
54666
+ const overlays = [];
54667
+ elements.push(this.generateDefs());
54668
+ if (layout.subgraphs && layout.subgraphs.length) {
54669
+ const sgs = layout.subgraphs;
54670
+ const order = sgs.slice().sort((a3, b3) => (a3.parent ? 1 : 0) - (b3.parent ? 1 : 0));
54671
+ const map4 = new Map(order.map((o3) => [o3.id, o3]));
54672
+ const depthOf = (sg) => {
54673
+ let d3 = 0;
54674
+ let p3 = sg.parent;
54675
+ while (p3) {
54676
+ d3++;
54677
+ p3 = map4.get(p3)?.parent;
54678
+ }
54679
+ return d3;
54680
+ };
54681
+ const bgs = [];
54682
+ for (const sg of order) {
54683
+ const x3 = sg.x + padX;
54684
+ const y2 = sg.y + padY;
54685
+ bgs.push(blockBackground(x3, y2, sg.width, sg.height, 0));
54686
+ const depth = depthOf(sg);
54687
+ const title = sg.label ? this.escapeXml(sg.label) : void 0;
54688
+ const titleYOffset = 7 + depth * 12;
54689
+ overlays.push(blockOverlay(x3, y2, sg.width, sg.height, title, [], titleYOffset, "center", "left", 0));
54690
+ }
54691
+ elements.push(`<g class="subgraph-bg">${bgs.join("")}</g>`);
54692
+ }
54693
+ const nodeMap = {};
54694
+ for (const n3 of layout.nodes) {
54695
+ nodeMap[n3.id] = { x: n3.x + padX, y: n3.y + padY, width: n3.width, height: n3.height, shape: n3.shape };
54696
+ }
54697
+ if (layout.subgraphs && layout.subgraphs.length) {
54698
+ for (const sg of layout.subgraphs) {
54699
+ nodeMap[sg.id] = { x: sg.x + padX, y: sg.y + padY, width: sg.width, height: sg.height, shape: "rectangle" };
54700
+ }
54701
+ }
54702
+ for (const node of layout.nodes) {
54703
+ elements.push(this.generateNodeWithPad(node, padX, padY));
54704
+ }
54705
+ for (const edge of layout.edges) {
54706
+ const { path: path6, overlay } = this.generateEdge(edge, padX, padY, nodeMap);
54707
+ elements.push(path6);
54708
+ if (overlay)
54709
+ overlays.push(overlay);
54710
+ }
54711
+ const bg = `<rect x="0" y="0" width="${width}" height="${height}" fill="#ffffff" />`;
54712
+ const sharedCss = buildSharedCss({
54713
+ fontFamily: this.fontFamily,
54714
+ fontSize: this.fontSize,
54715
+ nodeFill: this.defaultFill,
54716
+ nodeStroke: this.defaultStroke,
54717
+ edgeStroke: this.arrowStroke
54718
+ });
54719
+ const css = `<style>${sharedCss}</style>`;
54720
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
54721
+ ${bg}
54722
+ ${css}
54723
+ ${elements.join("\n ")}
54724
+ ${overlays.join("\n ")}
54725
+ </svg>`;
54726
+ }
54727
+ buildNodeStyleAttrs(style) {
54728
+ const decs = [];
54729
+ if (style.fill)
54730
+ decs.push(`fill:${style.fill}`);
54731
+ if (style.stroke)
54732
+ decs.push(`stroke:${style.stroke}`);
54733
+ if (style.strokeWidth != null)
54734
+ decs.push(`stroke-width:${style.strokeWidth}`);
54735
+ return decs.length ? `style="${decs.join(";")}"` : "";
54736
+ }
54737
+ buildNodeStrokeStyle(style) {
54738
+ const decs = [];
54739
+ if (style.stroke)
54740
+ decs.push(`stroke:${style.stroke}`);
54741
+ if (style.strokeWidth != null)
54742
+ decs.push(`stroke-width:${style.strokeWidth}`);
54743
+ return decs.length ? `style="${decs.join(";")}"` : "";
54744
+ }
54745
+ generateDefs() {
54746
+ const aw = Math.max(8, this.arrowMarkerSize + 2);
54747
+ const ah = Math.max(8, this.arrowMarkerSize + 2);
54748
+ const arefX = Math.max(6, aw);
54749
+ const arefY = Math.max(4, Math.round(ah / 2));
54750
+ return `<defs>
54751
+ <marker id="arrow" viewBox="0 0 ${aw} ${ah}" markerWidth="${aw}" markerHeight="${ah}" refX="${arefX}" refY="${arefY}" orient="auto" markerUnits="userSpaceOnUse">
54752
+ <path d="M0,0 L0,${ah} L${aw},${arefY} z" fill="${this.arrowStroke}" />
54753
+ </marker>
54754
+ <marker id="circle-marker" viewBox="0 0 9 9" markerWidth="9" markerHeight="9" refX="4.5" refY="4.5" orient="auto" markerUnits="userSpaceOnUse">
54755
+ <circle cx="4.5" cy="4.5" r="4.5" fill="${this.arrowStroke}" />
54756
+ </marker>
54757
+ <marker id="cross-marker" viewBox="0 0 12 12" markerWidth="12" markerHeight="12" refX="6" refY="6" orient="auto" markerUnits="userSpaceOnUse">
54758
+ <path d="M1.5,1.5 L10.5,10.5 M10.5,1.5 L1.5,10.5" stroke="${this.arrowStroke}" stroke-width="2.25" />
54759
+ </marker>
54760
+ </defs>`;
54761
+ }
54762
+ generateNodeWithPad(node, padX, padY) {
54763
+ const x3 = node.x + padX;
54764
+ const y2 = node.y + padY;
54765
+ const cx = x3 + node.width / 2;
54766
+ const cy = y2 + node.height / 2;
54767
+ let shape = "";
54768
+ let labelCenterY = cy;
54769
+ const strokeWidth = node.style?.strokeWidth ?? void 0;
54770
+ const stroke = node.style?.stroke ?? void 0;
54771
+ const fill = node.style?.fill ?? void 0;
54772
+ const styleAttr = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
54773
+ switch (node.shape) {
54774
+ case "rectangle":
54775
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
54776
+ break;
54777
+ case "round":
54778
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="5" ry="5" />`;
54779
+ break;
54780
+ case "stadium":
54781
+ const radius = node.height / 2;
54782
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="${radius}" ry="${radius}" />`;
54783
+ break;
54784
+ case "circle":
54785
+ const r3 = Math.min(node.width, node.height) / 2;
54786
+ shape = `<circle class="node-shape" ${styleAttr} cx="${cx}" cy="${cy}" r="${r3}" />`;
54787
+ break;
54788
+ case "diamond": {
54789
+ const points = [
54790
+ `${cx},${y2}`,
54791
+ // top
54792
+ `${x3 + node.width},${cy}`,
54793
+ // right
54794
+ `${cx},${y2 + node.height}`,
54795
+ // bottom
54796
+ `${x3},${cy}`
54797
+ // left
54798
+ ].join(" ");
54799
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
54800
+ break;
54801
+ }
54802
+ case "hexagon": {
54803
+ const dx = node.width * 0.25;
54804
+ const points = [
54805
+ `${x3 + dx},${y2}`,
54806
+ // top-left
54807
+ `${x3 + node.width - dx},${y2}`,
54808
+ // top-right
54809
+ `${x3 + node.width},${cy}`,
54810
+ // right
54811
+ `${x3 + node.width - dx},${y2 + node.height}`,
54812
+ // bottom-right
54813
+ `${x3 + dx},${y2 + node.height}`,
54814
+ // bottom-left
54815
+ `${x3},${cy}`
54816
+ // left
54817
+ ].join(" ");
54818
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
54819
+ break;
54820
+ }
54821
+ case "parallelogram": {
54822
+ const skew = node.width * 0.15;
54823
+ const points = [
54824
+ `${x3 + skew},${y2}`,
54825
+ // top-left
54826
+ `${x3 + node.width},${y2}`,
54827
+ // top-right
54828
+ `${x3 + node.width - skew},${y2 + node.height}`,
54829
+ // bottom-right
54830
+ `${x3},${y2 + node.height}`
54831
+ // bottom-left
54832
+ ].join(" ");
54833
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
54834
+ break;
54835
+ }
54836
+ case "trapezoid": {
54837
+ const inset = node.width * 0.15;
54838
+ const points = [
54839
+ `${x3 + inset},${y2}`,
54840
+ // top-left
54841
+ `${x3 + node.width - inset},${y2}`,
54842
+ // top-right
54843
+ `${x3 + node.width},${y2 + node.height}`,
54844
+ // bottom-right
54845
+ `${x3},${y2 + node.height}`
54846
+ // bottom-left
54847
+ ].join(" ");
54848
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
54849
+ break;
54850
+ }
54851
+ case "trapezoidAlt": {
54852
+ const inset = node.width * 0.15;
54853
+ const points = [
54854
+ `${x3},${y2}`,
54855
+ // top-left (full width)
54856
+ `${x3 + node.width},${y2}`,
54857
+ // top-right
54858
+ `${x3 + node.width - inset},${y2 + node.height}`,
54859
+ // bottom-right (narrow)
54860
+ `${x3 + inset},${y2 + node.height}`
54861
+ // bottom-left (narrow)
54862
+ ].join(" ");
54863
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
54864
+ break;
54865
+ }
54866
+ case "cylinder": {
54867
+ const rx = Math.max(8, node.width / 2);
54868
+ const ry = Math.max(6, Math.min(node.height * 0.22, node.width * 0.25));
54869
+ const topCY = y2 + ry;
54870
+ const botCY = y2 + node.height - ry;
54871
+ const bodyH = Math.max(0, node.height - ry * 2);
54872
+ const strokeOnly = this.buildNodeStrokeStyle({ stroke, strokeWidth });
54873
+ shape = `<g>
54874
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${topCY}" width="${node.width}" height="${bodyH}" />
54875
+ <ellipse class="node-shape" ${styleAttr} cx="${cx}" cy="${topCY}" rx="${node.width / 2}" ry="${ry}" />
54876
+ <path class="node-shape" ${strokeOnly} d="M${x3},${topCY} L${x3},${botCY} A${node.width / 2},${ry} 0 0,0 ${x3 + node.width},${botCY} L${x3 + node.width},${topCY}" fill="none" />
54877
+ </g>`;
54878
+ labelCenterY = topCY + bodyH / 2;
54879
+ break;
54880
+ }
54881
+ case "subroutine":
54882
+ const insetX = 5;
54883
+ const strokeOnly2 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
54884
+ shape = `<g>
54885
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
54886
+ <line class="node-shape" ${strokeOnly2} x1="${x3 + insetX}" y1="${y2}" x2="${x3 + insetX}" y2="${y2 + node.height}" />
54887
+ <line class="node-shape" ${strokeOnly2} x1="${x3 + node.width - insetX}" y1="${y2}" x2="${x3 + node.width - insetX}" y2="${y2 + node.height}" />
54888
+ </g>`;
54889
+ break;
54890
+ case "double":
54891
+ const gap = 4;
54892
+ const strokeOnly3 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
54893
+ shape = `<g>
54894
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
54895
+ <rect class="node-shape" ${strokeOnly3} x="${x3 + gap}" y="${y2 + gap}" width="${node.width - gap * 2}" height="${node.height - gap * 2}" rx="0" ry="0" fill="none" />
54896
+ </g>`;
54897
+ break;
54898
+ default:
54899
+ const s3 = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
54900
+ shape = `<rect ${s3} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
54901
+ }
54902
+ const text = this.generateWrappedText(node.label, cx, labelCenterY, node.width - 20);
54903
+ return `<g id="${node.id}">
54904
+ ${shape}
54905
+ ${text}
54906
+ </g>`;
54907
+ }
54908
+ generateWrappedText(text, x3, y2, maxWidth) {
54909
+ if (text.includes("<")) {
54910
+ return this.generateRichText(text, x3, y2, maxWidth);
54911
+ }
54912
+ const charWidth = 7;
54913
+ const maxCharsPerLine = Math.floor(maxWidth / charWidth);
54914
+ if (maxCharsPerLine <= 0 || text.length <= maxCharsPerLine) {
54915
+ const dyOffset = this.fontSize * 0.35;
54916
+ return `<text class="node-label" x="${x3}" y="${y2 + dyOffset}" text-anchor="middle">${this.escapeXml(text)}</text>`;
54917
+ }
54918
+ const words = text.split(" ");
54919
+ const lines = [];
54920
+ let currentLine = "";
54921
+ for (const word of words) {
54922
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
54923
+ if (testLine.length > maxCharsPerLine && currentLine) {
54924
+ lines.push(currentLine);
54925
+ currentLine = word;
54926
+ } else {
54927
+ currentLine = testLine;
54928
+ }
54929
+ }
54930
+ if (currentLine) {
54931
+ lines.push(currentLine);
54932
+ }
54933
+ const lineHeight = 18;
54934
+ const totalHeight = (lines.length - 1) * lineHeight;
54935
+ const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
54936
+ const tspans = lines.map((line, i3) => {
54937
+ const lineY = startY + i3 * lineHeight;
54938
+ return `<tspan x="${x3}" y="${lineY}" text-anchor="middle">${this.escapeXml(line)}</tspan>`;
54939
+ }).join("\n ");
54940
+ return `<text class="node-label">
54941
+ ${tspans}
54942
+ </text>`;
54943
+ }
54944
+ // Basic HTML-aware text renderer supporting <br>, <b>/<strong>, <i>/<em>, <u>
54945
+ generateRichText(html, x3, y2, maxWidth) {
54946
+ html = this.normalizeHtml(html);
54947
+ const segments = [];
54948
+ const re = /<\/?(br|b|strong|i|em|u)\s*\/?\s*>/gi;
54949
+ let lastIndex = 0;
54950
+ const state2 = { bold: false, italic: false, underline: false };
54951
+ const pushText = (t3) => {
54952
+ if (!t3)
54953
+ return;
54954
+ segments.push({ text: this.htmlDecode(t3), bold: state2.bold, italic: state2.italic, underline: state2.underline });
54955
+ };
54956
+ let m3;
54957
+ while (m3 = re.exec(html)) {
54958
+ pushText(html.slice(lastIndex, m3.index));
54959
+ const tag2 = m3[0].toLowerCase();
54960
+ const name14 = m3[1].toLowerCase();
54961
+ const isClose = tag2.startsWith("</");
54962
+ if (name14 === "br") {
54963
+ segments.push({ text: "", br: true });
54964
+ } else if (name14 === "b" || name14 === "strong") {
54965
+ state2.bold = !isClose ? true : false;
54966
+ } else if (name14 === "i" || name14 === "em") {
54967
+ state2.italic = !isClose ? true : false;
54968
+ } else if (name14 === "u") {
54969
+ state2.underline = !isClose ? true : false;
54970
+ }
54971
+ lastIndex = re.lastIndex;
54972
+ }
54973
+ pushText(html.slice(lastIndex));
54974
+ const lines = [];
54975
+ const charWidth = 7;
54976
+ const maxCharsPerLine = Math.max(1, Math.floor(maxWidth / charWidth));
54977
+ let current = [];
54978
+ let currentLen = 0;
54979
+ const flush = () => {
54980
+ if (current.length) {
54981
+ lines.push(current);
54982
+ current = [];
54983
+ currentLen = 0;
54984
+ }
54985
+ };
54986
+ const splitWords = (s3) => {
54987
+ if (!s3.text)
54988
+ return [s3];
54989
+ const words = s3.text.split(/(\s+)/);
54990
+ return words.map((w3) => ({ ...s3, text: w3 }));
54991
+ };
54992
+ for (const seg of segments) {
54993
+ if (seg.br) {
54994
+ flush();
54995
+ continue;
54996
+ }
54997
+ for (const w3 of splitWords(seg)) {
54998
+ const wlen = w3.text.length;
54999
+ if (currentLen + wlen > maxCharsPerLine && currentLen > 0) {
55000
+ flush();
55001
+ }
55002
+ current.push(w3);
55003
+ currentLen += wlen;
55004
+ }
55005
+ }
55006
+ flush();
55007
+ const lineHeight = 18;
55008
+ const totalHeight = (lines.length - 1) * lineHeight;
55009
+ const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
55010
+ const tspans = [];
55011
+ for (let i3 = 0; i3 < lines.length; i3++) {
55012
+ const lineY = startY + i3 * lineHeight;
55013
+ let acc = "";
55014
+ let cursorX = x3;
55015
+ const inner = [];
55016
+ let buffer = "";
55017
+ let style = { bold: false, italic: false, underline: false };
55018
+ const flushInline = () => {
55019
+ if (!buffer)
55020
+ return;
55021
+ const styleAttr = `${style.bold ? 'font-weight="bold" ' : ""}${style.italic ? 'font-style="italic" ' : ""}${style.underline ? 'text-decoration="underline" ' : ""}`;
55022
+ inner.push(`<tspan ${styleAttr}>${this.escapeXml(buffer)}</tspan>`);
55023
+ buffer = "";
55024
+ };
55025
+ for (const w3 of lines[i3]) {
55026
+ const wStyle = { bold: !!w3.bold, italic: !!w3.italic, underline: !!w3.underline };
55027
+ if (wStyle.bold !== style.bold || wStyle.italic !== style.italic || wStyle.underline !== style.underline) {
55028
+ flushInline();
55029
+ style = wStyle;
55030
+ }
55031
+ buffer += w3.text;
55032
+ }
55033
+ flushInline();
55034
+ tspans.push(`<tspan x="${x3}" y="${lineY}" text-anchor="middle">${inner.join("")}</tspan>`);
55035
+ }
55036
+ return `<text font-family="${this.fontFamily}" font-size="${this.fontSize}" fill="#333">${tspans.join("\n ")}</text>`;
55037
+ }
55038
+ normalizeHtml(s3) {
55039
+ let out = s3.replace(/<\s+/g, "<").replace(/\s+>/g, ">").replace(/<\s*\//g, "</").replace(/\s*\/\s*>/g, "/>").replace(/<\s*(br)\s*>/gi, "<$1/>");
55040
+ return out;
55041
+ }
55042
+ htmlDecode(s3) {
55043
+ return s3.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#39;/g, "'");
55044
+ }
55045
+ generateEdge(edge, padX, padY, nodeMap) {
55046
+ if (!edge.points || edge.points.length < 2) {
55047
+ return { path: "" };
55048
+ }
55049
+ const points = edge.points.map((p3) => ({ x: p3.x + padX, y: p3.y + padY }));
55050
+ const segData = this.buildSmoothSegments(points);
55051
+ let strokeDasharray = "";
55052
+ let strokeWidth = 1.5;
55053
+ let markerEnd = "";
55054
+ let markerStart = "";
55055
+ switch (edge.type) {
55056
+ case "open":
55057
+ markerEnd = "";
55058
+ break;
55059
+ case "dotted":
55060
+ strokeDasharray = "3,3";
55061
+ break;
55062
+ case "thick":
55063
+ strokeWidth = 3;
55064
+ break;
55065
+ case "invisible":
55066
+ strokeDasharray = "0,100000";
55067
+ markerEnd = "";
55068
+ break;
55069
+ }
55070
+ const mStart = edge.markerStart;
55071
+ const mEnd = edge.markerEnd;
55072
+ const sourceNode = nodeMap[edge.source];
55073
+ const targetNode = nodeMap[edge.target];
55074
+ let boundaryStart = points[0];
55075
+ let boundaryEnd = points[points.length - 1];
55076
+ if (sourceNode && points.length >= 2) {
55077
+ const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
55078
+ boundaryStart = this.intersectSegmentsStart(pseudo, sourceNode).start;
55079
+ }
55080
+ if (targetNode && points.length >= 2) {
55081
+ const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
55082
+ const after = this.intersectSegmentsEnd(pseudo, targetNode);
55083
+ boundaryEnd = after.segs.length ? after.segs[after.segs.length - 1].to : boundaryEnd;
55084
+ }
55085
+ const pathParts = [];
55086
+ pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
55087
+ let startFlat = points.length >= 2 ? points[1] : boundaryStart;
55088
+ if (points.length >= 2) {
55089
+ const svx = points[1].x - boundaryStart.x;
55090
+ const svy = points[1].y - boundaryStart.y;
55091
+ const slen = Math.hypot(svx, svy) || 1;
55092
+ const SFLAT = Math.min(22, Math.max(10, slen * 0.15));
55093
+ startFlat = { x: boundaryStart.x + svx / slen * SFLAT, y: boundaryStart.y + svy / slen * SFLAT };
55094
+ pathParts.push(`L${startFlat.x},${startFlat.y}`);
55095
+ }
55096
+ const orthogonal = edge.pathMode === "orthogonal";
55097
+ if (points.length >= 4 && !orthogonal) {
55098
+ const pts = [points[0], ...points, points[points.length - 1]];
55099
+ for (let i3 = 1; i3 < pts.length - 3; i3++) {
55100
+ const p0 = pts[i3 - 1];
55101
+ const p1 = pts[i3];
55102
+ const p22 = pts[i3 + 1];
55103
+ const p3 = pts[i3 + 2];
55104
+ const c1x = p1.x + (p22.x - p0.x) / 6;
55105
+ const c1y = p1.y + (p22.y - p0.y) / 6;
55106
+ const c2x = p22.x - (p3.x - p1.x) / 6;
55107
+ const c2y = p22.y - (p3.y - p1.y) / 6;
55108
+ pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${p22.x},${p22.y}`);
55109
+ }
55110
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55111
+ } else if (points.length === 3 && !orthogonal) {
55112
+ const p0 = boundaryStart, p1 = points[1], p22 = boundaryEnd;
55113
+ const ax = boundaryEnd.x - p1.x;
55114
+ const ay = boundaryEnd.y - p1.y;
55115
+ const alen = Math.hypot(ax, ay) || 1;
55116
+ const FLAT_IN = Math.min(20, Math.max(10, alen * 0.15));
55117
+ const preEnd = { x: boundaryEnd.x - ax / alen * FLAT_IN, y: boundaryEnd.y - ay / alen * FLAT_IN };
55118
+ const sdx = startFlat.x - boundaryStart.x;
55119
+ const sdy = startFlat.y - boundaryStart.y;
55120
+ const sdirx = sdx === 0 && sdy === 0 ? p1.x - p0.x : sdx;
55121
+ const sdiry = sdx === 0 && sdy === 0 ? p1.y - p0.y : sdy;
55122
+ const sdlen = Math.hypot(sdirx, sdiry) || 1;
55123
+ const c1len = Math.min(40, Math.max(12, sdlen * 1.2));
55124
+ const c1x = startFlat.x + sdirx / sdlen * c1len;
55125
+ const c1y = startFlat.y + sdiry / sdlen * c1len;
55126
+ const dirx = (boundaryEnd.x - p1.x) / alen;
55127
+ const diry = (boundaryEnd.y - p1.y) / alen;
55128
+ const c2x = preEnd.x - dirx * (FLAT_IN * 0.6);
55129
+ const c2y = preEnd.y - diry * (FLAT_IN * 0.6);
55130
+ pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${preEnd.x},${preEnd.y}`);
55131
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55132
+ } else {
55133
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55134
+ }
55135
+ if (orthogonal) {
55136
+ pathParts.length = 0;
55137
+ pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
55138
+ for (const p3 of points.slice(1, -1))
55139
+ pathParts.push(`L${p3.x},${p3.y}`);
55140
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55141
+ }
55142
+ const pathData = pathParts.join(" ");
55143
+ let edgeElement = `<path class="edge-path" d="${pathData}" stroke-linecap="round" stroke-linejoin="round"`;
55144
+ if (strokeDasharray) {
55145
+ edgeElement += ` stroke-dasharray="${strokeDasharray}"`;
55146
+ }
55147
+ const startMarkUrl = mStart === "arrow" ? "url(#arrow)" : mStart === "circle" ? "url(#circle-marker)" : mStart === "cross" ? "url(#cross-marker)" : "";
55148
+ const endMarkUrl = mEnd === "arrow" ? "url(#arrow)" : mEnd === "circle" ? "url(#circle-marker)" : mEnd === "cross" ? "url(#cross-marker)" : markerEnd || "";
55149
+ if (startMarkUrl && mStart !== "arrow")
55150
+ edgeElement += ` marker-start="${startMarkUrl}"`;
55151
+ if (endMarkUrl && mEnd !== "arrow")
55152
+ edgeElement += ` marker-end="${endMarkUrl}"`;
55153
+ edgeElement += " />";
55154
+ if (edge.label) {
55155
+ const pos = this.pointAtRatio(points, 0.55);
55156
+ const text = this.escapeXml(edge.label);
55157
+ const padding = 4;
55158
+ const fontSize = this.fontSize - 3;
55159
+ const width = Math.max(18, Math.min(220, text.length * 6 + padding * 2));
55160
+ const height = 14;
55161
+ const x3 = pos.x - width / 2;
55162
+ const y2 = pos.y - height / 2;
55163
+ const labelBg = `<rect class="edge-label-bg" x="${x3}" y="${y2}" width="${width}" height="${height}" rx="3" />`;
55164
+ const labelText = `<text class="edge-label-text" x="${pos.x}" y="${pos.y}" text-anchor="middle" dominant-baseline="middle">${text}</text>`;
55165
+ let overlay2 = "";
55166
+ const prevEndL = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
55167
+ const vxl = boundaryEnd.x - prevEndL.x;
55168
+ const vyl = boundaryEnd.y - prevEndL.y;
55169
+ const vlenl = Math.hypot(vxl, vyl) || 1;
55170
+ const uxl = vxl / vlenl;
55171
+ const uyl = vyl / vlenl;
55172
+ const nxl = -uyl;
55173
+ const nyl = uxl;
55174
+ const triLenL = 8;
55175
+ const triWL = 6;
55176
+ const p1xL = boundaryEnd.x, p1yL = boundaryEnd.y;
55177
+ const baseXL = boundaryEnd.x - uxl * triLenL;
55178
+ const baseYL = boundaryEnd.y - uyl * triLenL;
55179
+ const p2xL = baseXL + nxl * (triWL / 2), p2yL = baseYL + nyl * (triWL / 2);
55180
+ const p3xL = baseXL - nxl * (triWL / 2), p3yL = baseYL - nyl * (triWL / 2);
55181
+ overlay2 += triangleAtEnd(prevEndL, boundaryEnd, this.arrowStroke);
55182
+ if (mStart === "arrow" && points.length >= 2) {
55183
+ const firstLeg = points[1];
55184
+ const svx = boundaryStart.x - firstLeg.x;
55185
+ const svy = boundaryStart.y - firstLeg.y;
55186
+ const slen = Math.hypot(svx, svy) || 1;
55187
+ const sux = svx / slen;
55188
+ const suy = svy / slen;
55189
+ const snx = -suy;
55190
+ const sny = sux;
55191
+ const sbaseX = boundaryStart.x - sux * triLenL;
55192
+ const sbaseY = boundaryStart.y - suy * triLenL;
55193
+ overlay2 += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
55194
+ }
55195
+ const pathGroup = `<g>
55196
+ ${edgeElement}
55197
+ ${labelBg}
55198
+ ${labelText}
55199
+ ${overlay2}
55200
+ </g>`;
55201
+ return { path: pathGroup };
55202
+ }
55203
+ let overlay = "";
55204
+ const prevEnd = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
55205
+ const vx = boundaryEnd.x - prevEnd.x;
55206
+ const vy = boundaryEnd.y - prevEnd.y;
55207
+ const vlen = Math.hypot(vx, vy) || 1;
55208
+ const ux = vx / vlen;
55209
+ const uy = vy / vlen;
55210
+ const nx = -uy;
55211
+ const ny = ux;
55212
+ const triLen = 8;
55213
+ const triW = 6;
55214
+ const p1x = boundaryEnd.x, p1y = boundaryEnd.y;
55215
+ const baseX = boundaryEnd.x - ux * triLen;
55216
+ const baseY = boundaryEnd.y - uy * triLen;
55217
+ const p2x = baseX + nx * (triW / 2), p2y = baseY + ny * (triW / 2);
55218
+ const p3x = baseX - nx * (triW / 2), p3y = baseY - ny * (triW / 2);
55219
+ if (mEnd === "arrow")
55220
+ overlay += triangleAtEnd(prevEnd, boundaryEnd, this.arrowStroke);
55221
+ if (mStart === "arrow" && points.length >= 2) {
55222
+ const firstLeg = points[1];
55223
+ const svx = boundaryStart.x - firstLeg.x;
55224
+ const svy = boundaryStart.y - firstLeg.y;
55225
+ const slen = Math.hypot(svx, svy) || 1;
55226
+ const sux = svx / slen;
55227
+ const suy = svy / slen;
55228
+ const snx = -suy;
55229
+ const sny = sux;
55230
+ overlay += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
55231
+ }
55232
+ if (overlay) {
55233
+ const grouped = `<g>${edgeElement}
55234
+ ${overlay}</g>`;
55235
+ return { path: grouped };
55236
+ }
55237
+ return { path: edgeElement };
55238
+ }
55239
+ // --- helpers ---
55240
+ buildSmoothSegments(points) {
55241
+ if (points.length < 2) {
55242
+ const p3 = points[0] || { x: 0, y: 0 };
55243
+ return { start: p3, segs: [] };
55244
+ }
55245
+ if (points.length === 2) {
55246
+ const p0 = points[0];
55247
+ const p1 = points[1];
55248
+ const c1 = { x: p0.x + (p1.x - p0.x) / 3, y: p0.y + (p1.y - p0.y) / 3 };
55249
+ const c22 = { x: p0.x + 2 * (p1.x - p0.x) / 3, y: p0.y + 2 * (p1.y - p0.y) / 3 };
55250
+ return { start: p0, segs: [{ c1, c2: c22, to: p1 }] };
55251
+ }
55252
+ const pts = [points[0], ...points, points[points.length - 1]];
55253
+ const segs = [];
55254
+ const firstIdx = 1;
55255
+ const lastIdx = pts.length - 3;
55256
+ const midFactor = 1;
55257
+ const endFactor = 0.35;
55258
+ const FLAT_LEN = 28;
55259
+ for (let i3 = 1; i3 < pts.length - 2; i3++) {
55260
+ const p0 = pts[i3 - 1];
55261
+ const p1 = pts[i3];
55262
+ const p22 = pts[i3 + 1];
55263
+ const p3 = pts[i3 + 2];
55264
+ const f1 = i3 === firstIdx ? endFactor : midFactor;
55265
+ const f22 = i3 === lastIdx ? endFactor : midFactor;
55266
+ let c1 = { x: p1.x + (p22.x - p0.x) / 6 * f1, y: p1.y + (p22.y - p0.y) / 6 * f1 };
55267
+ let c22 = { x: p22.x - (p3.x - p1.x) / 6 * f22, y: p22.y - (p3.y - p1.y) / 6 * f22 };
55268
+ if (i3 === firstIdx) {
55269
+ const dx = p22.x - p1.x, dy = p22.y - p1.y;
55270
+ const len = Math.hypot(dx, dy) || 1;
55271
+ const t3 = Math.min(FLAT_LEN, len * 0.5);
55272
+ c1 = { x: p1.x + dx / len * t3, y: p1.y + dy / len * t3 };
55273
+ }
55274
+ if (i3 === lastIdx) {
55275
+ const dx = p22.x - p1.x, dy = p22.y - p1.y;
55276
+ const len = Math.hypot(dx, dy) || 1;
55277
+ const t3 = Math.min(FLAT_LEN, len * 0.5);
55278
+ c22 = { x: p22.x - dx / len * t3, y: p22.y - dy / len * t3 };
55279
+ }
55280
+ segs.push({ c1, c2: c22, to: { x: p22.x, y: p22.y } });
55281
+ }
55282
+ return { start: pts[1], segs };
55283
+ }
55284
+ pathFromSegments(data2) {
55285
+ let d3 = `M${data2.start.x},${data2.start.y}`;
55286
+ for (const s3 of data2.segs) {
55287
+ d3 += ` C${s3.c1.x},${s3.c1.y} ${s3.c2.x},${s3.c2.y} ${s3.to.x},${s3.to.y}`;
55288
+ }
55289
+ return d3;
55290
+ }
55291
+ trimSegmentsEnd(data2, cut) {
55292
+ const segs = data2.segs.slice();
55293
+ if (!segs.length)
55294
+ return data2;
55295
+ const last2 = { ...segs[segs.length - 1] };
55296
+ const vx = last2.to.x - last2.c2.x;
55297
+ const vy = last2.to.y - last2.c2.y;
55298
+ const len = Math.hypot(vx, vy) || 1;
55299
+ const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
55300
+ const nx = vx / len;
55301
+ const ny = vy / len;
55302
+ const newTo = { x: last2.to.x - nx * eff, y: last2.to.y - ny * eff };
55303
+ last2.to = newTo;
55304
+ segs[segs.length - 1] = last2;
55305
+ return { start: data2.start, segs };
55306
+ }
55307
+ trimSegmentsStart(data2, cut) {
55308
+ const segs = data2.segs.slice();
55309
+ if (!segs.length)
55310
+ return data2;
55311
+ const first2 = { ...segs[0] };
55312
+ const vx = first2.c1.x - data2.start.x;
55313
+ const vy = first2.c1.y - data2.start.y;
55314
+ const len = Math.hypot(vx, vy) || 1;
55315
+ const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
55316
+ const nx = vx / len;
55317
+ const ny = vy / len;
55318
+ const newStart = { x: data2.start.x + nx * eff, y: data2.start.y + ny * eff };
55319
+ return { start: newStart, segs };
55320
+ }
55321
+ // ---- shape intersections ----
55322
+ intersectSegmentsEnd(data2, node) {
55323
+ if (!data2.segs.length)
55324
+ return data2;
55325
+ const last2 = data2.segs[data2.segs.length - 1];
55326
+ const p1 = last2.c2;
55327
+ const p22 = last2.to;
55328
+ const hit = this.intersectLineWithNode(p1, p22, node);
55329
+ if (hit) {
55330
+ const segs = data2.segs.slice();
55331
+ segs[segs.length - 1] = { ...last2, to: hit };
55332
+ return { start: data2.start, segs };
55333
+ }
55334
+ return data2;
55335
+ }
55336
+ intersectSegmentsStart(data2, node) {
55337
+ if (!data2.segs.length)
55338
+ return data2;
55339
+ const first2 = data2.segs[0];
55340
+ const p1 = data2.start;
55341
+ const p22 = first2.c1;
55342
+ const hit = this.intersectLineWithNode(p1, p22, node);
55343
+ if (hit) {
55344
+ return { start: hit, segs: data2.segs };
55345
+ }
55346
+ return data2;
55347
+ }
55348
+ intersectLineWithNode(p1, p22, node) {
55349
+ const shape = node.shape;
55350
+ const rectPoly = () => [
55351
+ { x: node.x, y: node.y },
55352
+ { x: node.x + node.width, y: node.y },
55353
+ { x: node.x + node.width, y: node.y + node.height },
55354
+ { x: node.x, y: node.y + node.height }
55355
+ ];
55356
+ switch (shape) {
55357
+ case "circle": {
55358
+ const cx = node.x + node.width / 2;
55359
+ const cy = node.y + node.height / 2;
55360
+ const r3 = Math.min(node.width, node.height) / 2;
55361
+ return this.lineCircleIntersection(p1, p22, { cx, cy, r: r3 });
55362
+ }
55363
+ case "diamond": {
55364
+ const cx = node.x + node.width / 2;
55365
+ const cy = node.y + node.height / 2;
55366
+ const poly = [{ x: cx, y: node.y }, { x: node.x + node.width, y: cy }, { x: cx, y: node.y + node.height }, { x: node.x, y: cy }];
55367
+ return this.linePolygonIntersection(p1, p22, poly);
55368
+ }
55369
+ case "hexagon": {
55370
+ const s3 = Math.max(10, node.width * 0.2);
55371
+ const poly = [
55372
+ { x: node.x + s3, y: node.y },
55373
+ { x: node.x + node.width - s3, y: node.y },
55374
+ { x: node.x + node.width, y: node.y + node.height / 2 },
55375
+ { x: node.x + node.width - s3, y: node.y + node.height },
55376
+ { x: node.x + s3, y: node.y + node.height },
55377
+ { x: node.x, y: node.y + node.height / 2 }
55378
+ ];
55379
+ return this.linePolygonIntersection(p1, p22, poly);
55380
+ }
55381
+ case "parallelogram": {
55382
+ const o3 = Math.min(node.width * 0.25, node.height * 0.6);
55383
+ const poly = [
55384
+ { x: node.x + o3, y: node.y },
55385
+ { x: node.x + node.width, y: node.y },
55386
+ { x: node.x + node.width - o3, y: node.y + node.height },
55387
+ { x: node.x, y: node.y + node.height }
55388
+ ];
55389
+ return this.linePolygonIntersection(p1, p22, poly);
55390
+ }
55391
+ case "trapezoid": {
55392
+ const o3 = Math.min(node.width * 0.2, node.height * 0.5);
55393
+ const poly = [
55394
+ { x: node.x + o3, y: node.y },
55395
+ { x: node.x + node.width - o3, y: node.y },
55396
+ { x: node.x + node.width, y: node.y + node.height },
55397
+ { x: node.x, y: node.y + node.height }
55398
+ ];
55399
+ return this.linePolygonIntersection(p1, p22, poly);
55400
+ }
55401
+ case "trapezoidAlt": {
55402
+ const o3 = Math.min(node.width * 0.2, node.height * 0.5);
55403
+ const poly = [
55404
+ { x: node.x, y: node.y },
55405
+ { x: node.x + node.width, y: node.y },
55406
+ { x: node.x + node.width - o3, y: node.y + node.height },
55407
+ { x: node.x + o3, y: node.y + node.height }
55408
+ ];
55409
+ return this.linePolygonIntersection(p1, p22, poly);
55410
+ }
55411
+ case "stadium": {
55412
+ const r3 = Math.min(node.height / 2, node.width / 2);
55413
+ const rect = [
55414
+ { x: node.x + r3, y: node.y },
55415
+ { x: node.x + node.width - r3, y: node.y },
55416
+ { x: node.x + node.width - r3, y: node.y + node.height },
55417
+ { x: node.x + r3, y: node.y + node.height }
55418
+ ];
55419
+ const hitRect = this.linePolygonIntersection(p1, p22, rect);
55420
+ if (hitRect)
55421
+ return hitRect;
55422
+ const left = this.lineCircleIntersection(p1, p22, { cx: node.x + r3, cy: node.y + node.height / 2, r: r3 });
55423
+ const right = this.lineCircleIntersection(p1, p22, { cx: node.x + node.width - r3, cy: node.y + node.height / 2, r: r3 });
55424
+ const pick = (...pts) => {
55425
+ let best = null;
55426
+ let bestd = -Infinity;
55427
+ for (const pt of pts)
55428
+ if (pt) {
55429
+ const d3 = -((pt.x - p22.x) ** 2 + (pt.y - p22.y) ** 2);
55430
+ if (d3 > bestd) {
55431
+ bestd = d3;
55432
+ best = pt;
55433
+ }
55434
+ }
55435
+ return best;
55436
+ };
55437
+ return pick(left, right);
55438
+ }
55439
+ default: {
55440
+ return this.linePolygonIntersection(p1, p22, rectPoly());
55441
+ }
55442
+ }
55443
+ }
55444
+ lineCircleIntersection(p1, p22, c3) {
55445
+ const dx = p22.x - p1.x;
55446
+ const dy = p22.y - p1.y;
55447
+ const fx = p1.x - c3.cx;
55448
+ const fy = p1.y - c3.cy;
55449
+ const a3 = dx * dx + dy * dy;
55450
+ const b3 = 2 * (fx * dx + fy * dy);
55451
+ const cc2 = fx * fx + fy * fy - c3.r * c3.r;
55452
+ const disc = b3 * b3 - 4 * a3 * cc2;
55453
+ if (disc < 0)
55454
+ return null;
55455
+ const s3 = Math.sqrt(disc);
55456
+ const t1 = (-b3 - s3) / (2 * a3);
55457
+ const t22 = (-b3 + s3) / (2 * a3);
55458
+ const ts = [t1, t22].filter((t4) => t4 >= 0 && t4 <= 1);
55459
+ if (!ts.length)
55460
+ return null;
55461
+ const t3 = Math.max(...ts);
55462
+ return { x: p1.x + dx * t3, y: p1.y + dy * t3 };
55463
+ }
55464
+ linePolygonIntersection(p1, p22, poly) {
55465
+ let bestT = -Infinity;
55466
+ let best = null;
55467
+ for (let i3 = 0; i3 < poly.length; i3++) {
55468
+ const a3 = poly[i3];
55469
+ const b3 = poly[(i3 + 1) % poly.length];
55470
+ const hit = this.segmentIntersection(p1, p22, a3, b3);
55471
+ if (hit && hit.t >= 0 && hit.t <= 1 && hit.u >= 0 && hit.u <= 1) {
55472
+ if (hit.t > bestT) {
55473
+ bestT = hit.t;
55474
+ best = { x: hit.x, y: hit.y };
55475
+ }
55476
+ }
55477
+ }
55478
+ return best;
55479
+ }
55480
+ segmentIntersection(p3, p22, q3, q22) {
55481
+ const r3 = { x: p22.x - p3.x, y: p22.y - p3.y };
55482
+ const s3 = { x: q22.x - q3.x, y: q22.y - q3.y };
55483
+ const rxs = r3.x * s3.y - r3.y * s3.x;
55484
+ if (Math.abs(rxs) < 1e-6)
55485
+ return null;
55486
+ const q_p = { x: q3.x - p3.x, y: q3.y - p3.y };
55487
+ const t3 = (q_p.x * s3.y - q_p.y * s3.x) / rxs;
55488
+ const u3 = (q_p.x * r3.y - q_p.y * r3.x) / rxs;
55489
+ const x3 = p3.x + t3 * r3.x;
55490
+ const y2 = p3.y + t3 * r3.y;
55491
+ return { x: x3, y: y2, t: t3, u: u3 };
55492
+ }
55493
+ pointAtRatio(points, ratio) {
55494
+ const clampRatio = Math.max(0, Math.min(1, ratio));
55495
+ let total = 0;
55496
+ const segs = [];
55497
+ for (let i3 = 0; i3 < points.length - 1; i3++) {
55498
+ const dx = points[i3 + 1].x - points[i3].x;
55499
+ const dy = points[i3 + 1].y - points[i3].y;
55500
+ const len = Math.hypot(dx, dy);
55501
+ segs.push(len);
55502
+ total += len;
55503
+ }
55504
+ if (total === 0)
55505
+ return points[Math.floor(points.length / 2)];
55506
+ let target = total * clampRatio;
55507
+ for (let i3 = 0; i3 < segs.length; i3++) {
55508
+ if (target <= segs[i3]) {
55509
+ const t3 = segs[i3] === 0 ? 0 : target / segs[i3];
55510
+ return {
55511
+ x: points[i3].x + (points[i3 + 1].x - points[i3].x) * t3,
55512
+ y: points[i3].y + (points[i3 + 1].y - points[i3].y) * t3
55513
+ };
55514
+ }
55515
+ target -= segs[i3];
55516
+ }
55517
+ return points[points.length - 1];
55518
+ }
55519
+ escapeXml(text) {
55520
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
55521
+ }
55522
+ };
55523
+ }
55524
+ });
55525
+
55526
+ // node_modules/@probelabs/maid/out/renderer/pie-builder.js
55527
+ function unquote(s3) {
55528
+ if (!s3)
55529
+ return s3;
55530
+ const first2 = s3.charAt(0);
55531
+ const last2 = s3.charAt(s3.length - 1);
55532
+ if (first2 === '"' && last2 === '"' || first2 === "'" && last2 === "'") {
55533
+ const inner = s3.slice(1, -1);
55534
+ return inner.replace(/\\(["'])/g, "$1");
55535
+ }
55536
+ return s3;
55537
+ }
55538
+ function buildPieModel(text) {
55539
+ const errors = [];
55540
+ const lex = tokenize2(text);
55541
+ for (const e3 of lex.errors) {
55542
+ errors.push({
55543
+ line: e3.line ?? 1,
55544
+ column: e3.column ?? 1,
55545
+ message: e3.message,
55546
+ code: "PIE_LEX",
55547
+ severity: "error"
55548
+ });
55549
+ }
55550
+ parserInstance2.reset();
55551
+ parserInstance2.input = lex.tokens;
55552
+ const cst = parserInstance2.diagram();
55553
+ for (const e3 of parserInstance2.errors) {
55554
+ const t3 = e3.token;
55555
+ errors.push({
55556
+ line: t3?.startLine ?? 1,
55557
+ column: t3?.startColumn ?? 1,
55558
+ message: e3.message,
55559
+ code: "PIE_PARSE",
55560
+ severity: "error"
55561
+ });
55562
+ }
55563
+ const model = { title: void 0, showData: false, slices: [] };
55564
+ if (!cst || !cst.children)
55565
+ return { model, errors };
55566
+ if (cst.children.ShowDataKeyword && cst.children.ShowDataKeyword.length > 0) {
55567
+ model.showData = true;
55568
+ }
55569
+ const statements = cst.children.statement ?? [];
55570
+ for (const st of statements) {
55571
+ if (st.children?.titleStmt) {
55572
+ const tnode = st.children.titleStmt[0];
55573
+ const parts = [];
55574
+ const collect = (k3) => {
55575
+ const arr = tnode.children?.[k3] ?? [];
55576
+ for (const tok of arr)
55577
+ parts.push(unquote(tok.image));
55578
+ };
55579
+ collect("QuotedString");
55580
+ collect("Text");
55581
+ collect("NumberLiteral");
55582
+ const title = parts.join(" ").trim();
55583
+ if (title)
55584
+ model.title = title;
55585
+ } else if (st.children?.sliceStmt) {
55586
+ const snode = st.children.sliceStmt[0];
55587
+ const labelTok = snode.children?.sliceLabel?.[0]?.children?.QuotedString?.[0];
55588
+ const numTok = snode.children?.NumberLiteral?.[0];
55589
+ if (labelTok && numTok) {
55590
+ const label = unquote(labelTok.image).trim();
55591
+ const value = Number(numTok.image);
55592
+ if (!Number.isNaN(value)) {
55593
+ model.slices.push({ label, value });
55594
+ }
55595
+ }
55596
+ }
55597
+ }
55598
+ return { model, errors };
55599
+ }
55600
+ var init_pie_builder = __esm({
55601
+ "node_modules/@probelabs/maid/out/renderer/pie-builder.js"() {
55602
+ init_lexer3();
55603
+ init_parser3();
55604
+ }
55605
+ });
55606
+
55607
+ // node_modules/@probelabs/maid/out/renderer/pie-renderer.js
55608
+ function polarToCartesian(cx, cy, r3, angleRad) {
55609
+ return { x: cx + r3 * Math.cos(angleRad), y: cy + r3 * Math.sin(angleRad) };
55610
+ }
55611
+ function renderPie(model, opts = {}) {
55612
+ let width = Math.max(320, Math.floor(opts.width ?? 640));
55613
+ const height = Math.max(240, Math.floor(opts.height ?? 400));
55614
+ const pad = 24;
55615
+ const titleH = model.title ? 28 : 0;
55616
+ let cx = width / 2;
55617
+ const cy = (height + titleH) / 2 + (model.title ? 8 : 0);
55618
+ const baseRadius = Math.max(40, Math.min(width, height - titleH) / 2 - pad);
55619
+ const slices = model.slices.filter((s3) => Math.max(0, s3.value) > 0);
55620
+ const total = slices.reduce((a3, s3) => a3 + Math.max(0, s3.value), 0);
55621
+ const LEG_SW = 12;
55622
+ const LEG_GAP = 8;
55623
+ const LEG_VSPACE = 18;
55624
+ const legendItems = slices.map((s3) => `${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
55625
+ const legendTextWidth = legendItems.length ? Math.max(...legendItems.map((t3) => measureText(t3, 12))) : 0;
55626
+ const legendBlockWidth = legendItems.length ? LEG_SW + LEG_GAP + legendTextWidth + pad : 0;
55627
+ if (legendItems.length) {
55628
+ const neededWidth = pad + baseRadius * 2 + legendBlockWidth + pad;
55629
+ if (neededWidth > width)
55630
+ width = Math.ceil(neededWidth);
55631
+ }
55632
+ let radius = baseRadius;
55633
+ if (legendItems.length) {
55634
+ const leftPad = Math.max(pad, (width - legendBlockWidth - radius * 2) / 2);
55635
+ cx = leftPad + radius;
55636
+ }
55637
+ let start = -Math.PI / 2;
55638
+ let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`;
55639
+ svg += `
55640
+ <style>
55641
+ .pie-title { font-family: Arial, sans-serif; font-size: 16px; font-weight: 600; fill: #222; }
55642
+ .slice-label { font-family: Arial, sans-serif; font-size: 12px; fill: #222; dominant-baseline: middle; }
55643
+ .leader { stroke: #444; stroke-width: 1; fill: none; }
55644
+ .pieCircle { stroke: black; stroke-width: 2px; opacity: 0.7; }
55645
+ .pieOuterCircle { stroke: black; stroke-width: 2px; fill: none; }
55646
+ </style>`;
55647
+ if (model.title) {
55648
+ svg += `
55649
+ <text class="pie-title" x="${cx}" y="${pad + 8}" text-anchor="middle">${escapeXml(model.title)}</text>`;
55650
+ }
55651
+ svg += `
55652
+ <g class="pie" aria-label="pie">`;
55653
+ const minOutsideAngle = 0.35;
55654
+ slices.forEach((s3, i3) => {
55655
+ const pct = total > 0 ? Math.max(0, s3.value) / total : 0;
55656
+ const angle = 2 * Math.PI * pct;
55657
+ const end = start + angle;
55658
+ const large = angle > Math.PI ? 1 : 0;
55659
+ const c0 = polarToCartesian(cx, cy, radius, start);
55660
+ const c1 = polarToCartesian(cx, cy, radius, end);
55661
+ const d3 = [
55662
+ `M ${cx} ${cy}`,
55663
+ `L ${c0.x.toFixed(2)} ${c0.y.toFixed(2)}`,
55664
+ `A ${radius} ${radius} 0 ${large} 1 ${c1.x.toFixed(2)} ${c1.y.toFixed(2)}`,
55665
+ "Z"
55666
+ ].join(" ");
55667
+ const fill = s3.color || palette(i3);
55668
+ svg += `
55669
+ <path d="${d3}" class="pieCircle" fill="${fill}" />`;
55670
+ const mid = (start + end) / 2;
55671
+ const cos = Math.cos(mid);
55672
+ const sin = Math.sin(mid);
55673
+ const percentLabel = escapeXml(formatPercent(s3.value, total));
55674
+ if (angle < minOutsideAngle) {
55675
+ const r1 = radius * 0.9;
55676
+ const r22 = radius * 1.06;
55677
+ const p1 = polarToCartesian(cx, cy, r1, mid);
55678
+ const p22 = polarToCartesian(cx, cy, r22, mid);
55679
+ const hlen = 12;
55680
+ const anchorLeft = cos < 0;
55681
+ const hx = anchorLeft ? p22.x - hlen : p22.x + hlen;
55682
+ const hy = p22.y;
55683
+ svg += `
55684
+ <path class="leader" d="M ${p1.x.toFixed(2)} ${p1.y.toFixed(2)} L ${p22.x.toFixed(2)} ${p22.y.toFixed(2)} L ${hx.toFixed(2)} ${hy.toFixed(2)}" />`;
55685
+ const tx = anchorLeft ? hx - 2 : hx + 2;
55686
+ const tAnchor = anchorLeft ? "end" : "start";
55687
+ svg += `
55688
+ <text class="slice-label" x="${tx.toFixed(2)}" y="${hy.toFixed(2)}" text-anchor="${tAnchor}">${percentLabel}</text>`;
55689
+ } else {
55690
+ const lr = radius * 0.62;
55691
+ const lp = { x: cx + lr * cos, y: cy + lr * sin };
55692
+ const tAnchor = Math.abs(cos) < 0.2 ? "middle" : cos > 0 ? "start" : "end";
55693
+ const avail = lr;
55694
+ const textW = measureText(percentLabel, 12);
55695
+ const anchor = textW > avail * 1.2 ? "middle" : tAnchor;
55696
+ svg += `
55697
+ <text class="slice-label" x="${lp.x.toFixed(2)}" y="${lp.y.toFixed(2)}" text-anchor="${anchor}">${percentLabel}</text>`;
55698
+ }
55699
+ start = end;
55700
+ });
55701
+ const rimStroke = opts.rimStroke || "black";
55702
+ const rimWidth = opts.rimStrokeWidth != null ? String(opts.rimStrokeWidth) : "2px";
55703
+ svg += `
55704
+ </g>
55705
+ <circle class="pie-rim pieOuterCircle" cx="${cx}" cy="${cy}" r="${radius}" stroke="${rimStroke}" stroke-width="${rimWidth}" fill="none" />`;
55706
+ if (legendItems.length) {
55707
+ const legendX = cx + radius + pad / 2;
55708
+ const totalH = legendItems.length * LEG_VSPACE;
55709
+ let legendY = cy - totalH / 2 + 10;
55710
+ svg += `
55711
+ <g class="legend">`;
55712
+ slices.forEach((s3, i3) => {
55713
+ const y2 = legendY + i3 * LEG_VSPACE;
55714
+ const fill = s3.color || palette(i3);
55715
+ const text = escapeXml(`${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
55716
+ svg += `
55717
+ <rect x="${legendX}" y="${y2 - LEG_SW + 6}" width="${LEG_SW}" height="${LEG_SW}" fill="${fill}" stroke="${fill}" stroke-width="1" />`;
55718
+ svg += `
55719
+ <text class="slice-label legend-text" x="${legendX + LEG_SW + LEG_GAP}" y="${y2}" text-anchor="start">${text}</text>`;
55720
+ });
55721
+ svg += `
55722
+ </g>`;
55723
+ }
55724
+ svg += `
55725
+ </svg>`;
55726
+ return svg;
55727
+ }
55728
+ var init_pie_renderer = __esm({
55729
+ "node_modules/@probelabs/maid/out/renderer/pie-renderer.js"() {
55730
+ init_utils4();
55731
+ }
55732
+ });
55733
+
55734
+ // node_modules/@probelabs/maid/out/renderer/sequence-builder.js
55735
+ function textFromTokens(tokens) {
55736
+ if (!tokens || tokens.length === 0)
55737
+ return "";
55738
+ const parts = [];
55739
+ for (const t3 of tokens) {
55740
+ const img = t3.image;
55741
+ if (!img)
55742
+ continue;
55743
+ if (t3.tokenType && t3.tokenType.name === "QuotedString") {
55744
+ if (img.startsWith('"') && img.endsWith('"'))
55745
+ parts.push(img.slice(1, -1));
55746
+ else if (img.startsWith("'") && img.endsWith("'"))
55747
+ parts.push(img.slice(1, -1));
55748
+ else
55749
+ parts.push(img);
55750
+ } else {
55751
+ parts.push(img);
55752
+ }
55753
+ }
55754
+ return parts.join(" ").replace(/\s+/g, " ").trim();
55755
+ }
55756
+ function actorRefToText(refCst) {
55757
+ const ch = refCst.children || {};
55758
+ const toks = [];
55759
+ ["Identifier", "QuotedString", "NumberLiteral", "Text"].forEach((k3) => {
55760
+ const a3 = ch[k3];
55761
+ a3?.forEach((t3) => toks.push(t3));
55762
+ });
55763
+ toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
55764
+ return textFromTokens(toks);
55765
+ }
55766
+ function lineRemainderToText(lineRem) {
55767
+ if (!lineRem)
55768
+ return void 0;
55769
+ const ch = lineRem.children || {};
55770
+ const toks = [];
55771
+ const order = [
55772
+ "Identifier",
55773
+ "NumberLiteral",
55774
+ "QuotedString",
55775
+ "Text",
55776
+ "Plus",
55777
+ "Minus",
55778
+ "Comma",
55779
+ "Colon",
55780
+ "LParen",
55781
+ "RParen",
55782
+ "AndKeyword",
55783
+ "ElseKeyword",
55784
+ "OptKeyword",
55785
+ "OptionKeyword",
55786
+ "LoopKeyword",
55787
+ "ParKeyword",
55788
+ "RectKeyword",
55789
+ "CriticalKeyword",
55790
+ "BreakKeyword",
55791
+ "BoxKeyword",
55792
+ "EndKeyword",
55793
+ "NoteKeyword",
55794
+ "LeftKeyword",
55795
+ "RightKeyword",
55796
+ "OverKeyword",
55797
+ "OfKeyword",
55798
+ "AutonumberKeyword",
55799
+ "OffKeyword",
55800
+ "LinkKeyword",
55801
+ "LinksKeyword",
55802
+ "CreateKeyword",
55803
+ "DestroyKeyword",
55804
+ "ParticipantKeyword",
55805
+ "ActorKeyword",
55806
+ "ActivateKeyword",
55807
+ "DeactivateKeyword"
55808
+ ];
55809
+ for (const k3 of order)
55810
+ ch[k3]?.forEach((t3) => toks.push(t3));
55811
+ toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
55812
+ return textFromTokens(toks) || void 0;
55813
+ }
55814
+ function canonicalId(raw) {
55815
+ const t3 = raw.trim().replace(/\s+/g, "_");
55816
+ return t3;
55817
+ }
55818
+ function ensureParticipant(map4, byDisplay, idLike, display) {
55819
+ const idGuess = canonicalId(idLike);
55820
+ const existing = map4.get(idGuess) || (byDisplay.get(idLike) ? map4.get(byDisplay.get(idLike)) : void 0);
55821
+ if (existing)
55822
+ return existing;
55823
+ const p3 = { id: idGuess, display: display || idLike };
55824
+ map4.set(p3.id, p3);
55825
+ byDisplay.set(p3.display, p3.id);
55826
+ return p3;
55827
+ }
55828
+ function msgFromArrow(arrowCst) {
55829
+ const ch = arrowCst.children || {};
55830
+ if (ch.BidirAsyncDotted)
55831
+ return { line: "dotted", start: "arrow", end: "arrow", async: true };
55832
+ if (ch.BidirAsync)
55833
+ return { line: "solid", start: "arrow", end: "arrow", async: true };
55834
+ if (ch.DottedAsync)
55835
+ return { line: "dotted", start: "none", end: "arrow", async: true };
55836
+ if (ch.Async)
55837
+ return { line: "solid", start: "none", end: "arrow", async: true };
55838
+ if (ch.Dotted)
55839
+ return { line: "dotted", start: "none", end: "arrow" };
55840
+ if (ch.Solid)
55841
+ return { line: "solid", start: "none", end: "arrow" };
55842
+ if (ch.DottedCross)
55843
+ return { line: "dotted", start: "none", end: "cross" };
55844
+ if (ch.Cross)
55845
+ return { line: "solid", start: "none", end: "cross" };
55846
+ if (ch.DottedOpen)
55847
+ return { line: "dotted", start: "none", end: "open" };
55848
+ if (ch.Open)
55849
+ return { line: "solid", start: "none", end: "open" };
55850
+ return { line: "solid", start: "none", end: "arrow" };
55851
+ }
55852
+ function buildSequenceModel(text) {
55853
+ const { tokens } = tokenize3(text);
55854
+ parserInstance3.input = tokens;
55855
+ const cst = parserInstance3.diagram();
55856
+ const participantsMap = /* @__PURE__ */ new Map();
55857
+ const byDisplay = /* @__PURE__ */ new Map();
55858
+ const events = [];
55859
+ let autonumber = { on: false };
55860
+ const diagramChildren = cst.children || {};
55861
+ const lines = diagramChildren.line || [];
55862
+ const openBlocks = [];
55863
+ function processLineNode(ln) {
55864
+ const ch = ln.children || {};
55865
+ if (ch.participantDecl) {
55866
+ const decl = ch.participantDecl[0];
55867
+ const dch = decl.children || {};
55868
+ const ref1 = dch.actorRef?.[0];
55869
+ const ref2 = dch.actorRef?.[1];
55870
+ const idText = actorRefToText(ref1);
55871
+ const aliasText = ref2 ? actorRefToText(ref2) : void 0;
55872
+ const id = canonicalId(idText);
55873
+ const display = aliasText || idText;
55874
+ const p3 = ensureParticipant(participantsMap, byDisplay, id, display);
55875
+ events.push({ kind: "create", actor: p3.id, display: p3.display });
55876
+ return;
55877
+ }
55878
+ if (ch.autonumberStmt) {
55879
+ const stmt = ch.autonumberStmt[0];
55880
+ const sch = stmt.children || {};
55881
+ autonumber = { on: true };
55882
+ const nums = sch.NumberLiteral || [];
55883
+ if (nums.length >= 1)
55884
+ autonumber.start = Number(nums[0].image);
55885
+ if (nums.length >= 2)
55886
+ autonumber.step = Number(nums[1].image);
55887
+ if (sch.OffKeyword)
55888
+ autonumber = { on: false };
55889
+ return;
55890
+ }
55891
+ if (ch.activateStmt) {
55892
+ const st = ch.activateStmt[0];
55893
+ const sch = st.children || {};
55894
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
55895
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
55896
+ events.push({ kind: "activate", actor: p3.id });
55897
+ return;
55898
+ }
55899
+ if (ch.deactivateStmt) {
55900
+ const st = ch.deactivateStmt[0];
55901
+ const sch = st.children || {};
55902
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
55903
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
55904
+ events.push({ kind: "deactivate", actor: p3.id });
55905
+ return;
55906
+ }
55907
+ if (ch.createStmt) {
55908
+ const st = ch.createStmt[0];
55909
+ const sch = st.children || {};
55910
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
55911
+ const alias = sch.lineRemainder ? lineRemainderToText(sch.lineRemainder[0]) : void 0;
55912
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt, alias || idTxt);
55913
+ events.push({ kind: "create", actor: p3.id, display: p3.display });
55914
+ return;
55915
+ }
55916
+ if (ch.destroyStmt) {
55917
+ const st = ch.destroyStmt[0];
55918
+ const sch = st.children || {};
55919
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
55920
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
55921
+ events.push({ kind: "destroy", actor: p3.id });
55922
+ return;
55923
+ }
55924
+ if (ch.noteStmt) {
55925
+ const st = ch.noteStmt[0];
55926
+ const sch = st.children || {};
55927
+ const text2 = lineRemainderToText(sch.lineRemainder?.[0]) || "";
55928
+ if (sch.LeftKeyword || sch.RightKeyword) {
55929
+ const pos = sch.LeftKeyword ? "leftOf" : "rightOf";
55930
+ const actorTxt = actorRefToText(sch.actorRef?.[0]);
55931
+ const p3 = ensureParticipant(participantsMap, byDisplay, actorTxt);
55932
+ const note = { pos, actors: [p3.id], text: text2 };
55933
+ events.push({ kind: "note", note });
55934
+ } else if (sch.OverKeyword) {
55935
+ const a1 = actorRefToText(sch.actorRef?.[0]);
55936
+ const a22 = sch.actorRef?.[1] ? actorRefToText(sch.actorRef?.[1]) : void 0;
55937
+ const p1 = ensureParticipant(participantsMap, byDisplay, a1);
55938
+ const ids = [p1.id];
55939
+ if (a22) {
55940
+ const p22 = ensureParticipant(participantsMap, byDisplay, a22);
55941
+ ids.push(p22.id);
55942
+ }
55943
+ events.push({ kind: "note", note: { pos: "over", actors: ids, text: text2 } });
55944
+ }
55945
+ return;
55946
+ }
55947
+ const blockKinds = [
55948
+ { key: "altBlock", type: "alt", branchKeys: [{ key: "ElseKeyword", kind: "else" }] },
55949
+ { key: "optBlock", type: "opt" },
55950
+ { key: "loopBlock", type: "loop" },
55951
+ { key: "parBlock", type: "par", branchKeys: [{ key: "AndKeyword", kind: "and" }] },
55952
+ { key: "criticalBlock", type: "critical", branchKeys: [{ key: "OptionKeyword", kind: "option" }] },
55953
+ { key: "breakBlock", type: "break" },
55954
+ { key: "rectBlock", type: "rect" },
55955
+ { key: "boxBlock", type: "box" }
55956
+ ];
55957
+ let handledBlock = false;
55958
+ for (const spec of blockKinds) {
55959
+ if (ch[spec.key]) {
55960
+ handledBlock = true;
55961
+ const bnode = ch[spec.key][0];
55962
+ const bch = bnode.children || {};
55963
+ const title = lineRemainderToText(bch.lineRemainder?.[0]);
55964
+ const block = { type: spec.type, title, branches: spec.branchKeys ? [] : void 0 };
55965
+ openBlocks.push(block);
55966
+ events.push({ kind: "block-start", block });
55967
+ if (spec.branchKeys) {
55968
+ const newlines = bch.Newline || [];
55969
+ const branchKey = spec.branchKeys[0].key;
55970
+ const branchTokArr = bch[branchKey];
55971
+ const lrArr = bch.lineRemainder;
55972
+ if (branchTokArr && branchTokArr.length) {
55973
+ const lr = (lrArr || []).slice(1);
55974
+ for (let i3 = 0; i3 < branchTokArr.length; i3++) {
55975
+ const title2 = lr[i3] ? lineRemainderToText(lr[i3]) : void 0;
55976
+ const br = { kind: spec.branchKeys[0].kind, title: title2 };
55977
+ block.branches.push(br);
55978
+ events.push({ kind: "block-branch", block, branch: br });
55979
+ }
55980
+ }
55981
+ }
55982
+ events.push({ kind: "block-end", block });
55983
+ openBlocks.pop();
55984
+ break;
55985
+ }
55986
+ }
55987
+ if (handledBlock)
55988
+ return;
55989
+ if (ch.messageStmt) {
55990
+ const st = ch.messageStmt[0];
55991
+ const sch = st.children || {};
55992
+ const fromTxt = actorRefToText(sch.actorRef?.[0]);
55993
+ const toTxt = actorRefToText(sch.actorRef?.[1]);
55994
+ const from = ensureParticipant(participantsMap, byDisplay, fromTxt).id;
55995
+ const to = ensureParticipant(participantsMap, byDisplay, toTxt).id;
55996
+ const arrow = msgFromArrow(sch.arrow?.[0]);
55997
+ const text2 = lineRemainderToText(sch.lineRemainder?.[0]);
55998
+ const activateTarget = !!sch.Plus;
55999
+ const deactivateTarget = !!sch.Minus;
56000
+ const msg = { from, to, text: text2, line: arrow.line, startMarker: arrow.start, endMarker: arrow.end, async: arrow.async, activateTarget, deactivateTarget };
56001
+ events.push({ kind: "message", msg });
56002
+ return;
56003
+ }
56004
+ if (ch.linkStmt) {
56005
+ events.push({ kind: "noop" });
56006
+ return;
56007
+ }
56008
+ events.push({ kind: "noop" });
56009
+ }
56010
+ function collectInnerLines(blockNode) {
56011
+ const out = [];
56012
+ const ch = blockNode.children || {};
56013
+ for (const key of Object.keys(ch)) {
56014
+ const arr = ch[key];
56015
+ if (Array.isArray(arr)) {
56016
+ for (const node of arr) {
56017
+ if (node && typeof node === "object" && node.name === "line")
56018
+ out.push(node);
56019
+ }
56020
+ }
56021
+ }
56022
+ return out;
56023
+ }
56024
+ for (const ln of lines) {
56025
+ processLineNode(ln);
56026
+ const ch = ln.children || {};
56027
+ const block = ch.altBlock?.[0] || ch.optBlock?.[0] || ch.loopBlock?.[0] || ch.parBlock?.[0] || ch.criticalBlock?.[0] || ch.breakBlock?.[0] || ch.rectBlock?.[0] || ch.boxBlock?.[0];
56028
+ if (block) {
56029
+ for (const inner of collectInnerLines(block))
56030
+ processLineNode(inner);
56031
+ }
56032
+ }
56033
+ return {
56034
+ participants: Array.from(participantsMap.values()),
56035
+ events,
56036
+ autonumber: autonumber.on === true || autonumber.on === false ? autonumber : { on: false }
56037
+ };
56038
+ }
56039
+ var init_sequence_builder = __esm({
56040
+ "node_modules/@probelabs/maid/out/renderer/sequence-builder.js"() {
56041
+ init_lexer4();
56042
+ init_parser4();
56043
+ }
56044
+ });
56045
+
56046
+ // node_modules/@probelabs/maid/out/renderer/sequence-layout.js
56047
+ function layoutSequence(model) {
56048
+ const order = [];
56049
+ const seen = /* @__PURE__ */ new Set();
56050
+ const partById = new Map(model.participants.map((p3) => [p3.id, p3]));
56051
+ function touch(id) {
56052
+ if (!seen.has(id)) {
56053
+ seen.add(id);
56054
+ order.push(id);
56055
+ }
56056
+ }
56057
+ for (const ev of model.events) {
56058
+ if (ev.kind === "message") {
56059
+ touch(ev.msg.from);
56060
+ touch(ev.msg.to);
56061
+ }
56062
+ if (ev.kind === "note") {
56063
+ ev.note.actors.forEach(touch);
56064
+ }
56065
+ if (ev.kind === "activate" || ev.kind === "deactivate" || ev.kind === "create" || ev.kind === "destroy")
56066
+ touch(ev.actor);
56067
+ }
56068
+ for (const p3 of model.participants)
56069
+ touch(p3.id);
56070
+ const participants = [];
56071
+ let x3 = MARGIN_X;
56072
+ for (const id of order) {
56073
+ const p3 = partById.get(id) || { id, display: id };
56074
+ const w3 = Math.max(COL_MIN, measureText(p3.display, ACTOR_FONT_SIZE) + ACTOR_PAD_X * 2);
56075
+ participants.push({ id, display: p3.display, x: x3, y: MARGIN_Y, width: w3, height: ACTOR_H });
56076
+ x3 += w3 + MARGIN_X;
56077
+ }
56078
+ const width = Math.max(320, x3);
56079
+ const rowIndexForEvent = /* @__PURE__ */ new Map();
56080
+ let row = 0;
56081
+ const openBlocks = [];
56082
+ function consumeRow(idx) {
56083
+ rowIndexForEvent.set(idx, row++);
56084
+ }
56085
+ model.events.forEach((ev, idx) => {
56086
+ switch (ev.kind) {
56087
+ case "message":
56088
+ consumeRow(idx);
56089
+ break;
56090
+ case "note":
56091
+ consumeRow(idx);
56092
+ break;
56093
+ case "block-start":
56094
+ openBlocks.push({ block: ev.block, startRow: row, branches: [] });
56095
+ consumeRow(idx);
56096
+ break;
56097
+ case "block-branch": {
56098
+ const top = openBlocks[openBlocks.length - 1];
56099
+ if (top)
56100
+ top.branches.push({ title: ev.branch.title, row });
56101
+ consumeRow(idx);
56102
+ break;
56103
+ }
56104
+ case "block-end":
56105
+ break;
56106
+ case "activate":
56107
+ case "deactivate":
56108
+ case "create":
56109
+ case "destroy":
56110
+ case "noop":
56111
+ break;
56112
+ }
56113
+ });
56114
+ const lifelineTop = MARGIN_Y + ACTOR_H + LIFELINE_GAP;
56115
+ const contentHeight = row * ROW_H;
56116
+ const height = lifelineTop + contentHeight + MARGIN_Y + ACTOR_H;
56117
+ const lifelines = participants.map((p3) => ({ x: p3.x + p3.width / 2, y1: lifelineTop, y2: height - MARGIN_Y - ACTOR_H }));
56118
+ function yForRow(r3) {
56119
+ return lifelineTop + r3 * ROW_H + ROW_H / 2;
56120
+ }
56121
+ const col = new Map(participants.map((p3) => [p3.id, p3]));
56122
+ const messages = [];
56123
+ const notes = [];
56124
+ const blocks = [];
56125
+ const activations = [];
56126
+ const actStack = /* @__PURE__ */ new Map();
56127
+ const startAct = (actor, r3) => {
56128
+ const arr = actStack.get(actor) || [];
56129
+ arr.push(r3);
56130
+ actStack.set(actor, arr);
56131
+ };
56132
+ const endAct = (actor, r3) => {
56133
+ const arr = actStack.get(actor) || [];
56134
+ const start = arr.pop();
56135
+ if (start != null) {
56136
+ const p3 = col.get(actor);
56137
+ if (p3) {
56138
+ activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(r3) - yForRow(start) });
56139
+ }
56140
+ }
56141
+ actStack.set(actor, arr);
56142
+ };
56143
+ const openForLayout = [];
56144
+ model.events.forEach((ev, idx) => {
56145
+ const r3 = rowIndexForEvent.has(idx) ? rowIndexForEvent.get(idx) : null;
56146
+ switch (ev.kind) {
56147
+ case "message": {
56148
+ const p1 = col.get(ev.msg.from), p22 = col.get(ev.msg.to);
56149
+ if (p1 && p22 && r3 != null) {
56150
+ const y2 = yForRow(r3);
56151
+ const x1 = p1.x + p1.width / 2;
56152
+ const x22 = p22.x + p22.width / 2;
56153
+ messages.push({ from: p1.id, to: p22.id, text: ev.msg.text, y: y2, x1, x2: x22, line: ev.msg.line, startMarker: ev.msg.startMarker, endMarker: ev.msg.endMarker, async: ev.msg.async });
56154
+ if (ev.msg.activateTarget)
56155
+ startAct(ev.msg.to, r3);
56156
+ if (ev.msg.deactivateTarget)
56157
+ endAct(ev.msg.to, r3);
56158
+ const top = openForLayout[openForLayout.length - 1];
56159
+ if (top)
56160
+ top.lastRow = r3;
56161
+ }
56162
+ break;
56163
+ }
56164
+ case "note": {
56165
+ if (r3 == null)
56166
+ break;
56167
+ const estLines = (text, width2) => {
56168
+ const charsPerLine = Math.max(8, Math.floor((width2 - NOTE_PAD * 2) / 7));
56169
+ const length = text ? text.length : 0;
56170
+ return Math.max(1, Math.ceil(length / charsPerLine));
56171
+ };
56172
+ const y2 = yForRow(r3) - NOTE_PAD;
56173
+ if (ev.note.pos === "over") {
56174
+ const [a3, b3] = ev.note.actors;
56175
+ const p1 = col.get(a3), p22 = b3 ? col.get(b3) : p1;
56176
+ if (p1 && p22) {
56177
+ const left = Math.min(p1.x + p1.width / 2, p22.x + p22.width / 2);
56178
+ const right = Math.max(p1.x + p1.width / 2, p22.x + p22.width / 2);
56179
+ const w3 = right - left + NOTE_PAD * 2;
56180
+ const lines = estLines(ev.note.text, w3);
56181
+ const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
56182
+ notes.push({ x: left - NOTE_PAD, y: y2, width: w3, height: h3, text: ev.note.text, anchor: "over" });
56183
+ }
56184
+ } else {
56185
+ const actor = ev.note.actors[0];
56186
+ const p3 = col.get(actor);
56187
+ if (p3) {
56188
+ const leftSide = ev.note.pos === "leftOf";
56189
+ const x4 = leftSide ? p3.x - NOTE_W - 10 : p3.x + p3.width + 10;
56190
+ const lines = estLines(ev.note.text, NOTE_W);
56191
+ const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
56192
+ notes.push({ x: x4, y: y2, width: NOTE_W, height: h3, text: ev.note.text, anchor: leftSide ? "left" : "right" });
56193
+ }
56194
+ }
56195
+ const top = openForLayout[openForLayout.length - 1];
56196
+ if (top && r3 != null)
56197
+ top.lastRow = r3;
56198
+ break;
56199
+ }
56200
+ case "activate":
56201
+ if (r3 != null)
56202
+ startAct(ev.actor, r3);
56203
+ break;
56204
+ case "deactivate":
56205
+ if (r3 != null)
56206
+ endAct(ev.actor, r3);
56207
+ break;
56208
+ case "block-start": {
56209
+ const startRow = r3 != null ? r3 : row;
56210
+ openForLayout.push({ block: ev.block, startRow, branches: [] });
56211
+ break;
56212
+ }
56213
+ case "block-branch": {
56214
+ const top = openForLayout[openForLayout.length - 1];
56215
+ if (top && r3 != null) {
56216
+ top.branches.push({ title: ev.branch.title, row: r3 });
56217
+ top.lastRow = r3;
56218
+ }
56219
+ break;
56220
+ }
56221
+ case "block-end": {
56222
+ const top = openForLayout.pop();
56223
+ if (top) {
56224
+ const first2 = participants.length > 0 ? participants[0] : void 0;
56225
+ const last2 = participants.length > 0 ? participants[participants.length - 1] : void 0;
56226
+ const left = first2 ? first2.x : MARGIN_X;
56227
+ const right = last2 ? last2.x + last2.width : left + 200;
56228
+ const yTop = yForRow(top.startRow) - ROW_H / 2 - (BLOCK_PAD + TITLE_EXTRA_TOP);
56229
+ const endRow = top.lastRow != null ? top.lastRow : top.startRow;
56230
+ const yBot = yForRow(endRow) + ROW_H / 2 + BLOCK_PAD;
56231
+ const layout = { type: top.block.type, title: top.block.title, x: left - BLOCK_PAD, y: yTop, width: right - left + BLOCK_PAD * 2, height: yBot - yTop };
56232
+ if (top.branches.length)
56233
+ layout.branches = top.branches.map((b3) => ({ title: b3.title, y: yForRow(b3.row) - ROW_H / 2 }));
56234
+ blocks.push(layout);
56235
+ }
56236
+ break;
56237
+ }
56238
+ default:
56239
+ break;
56240
+ }
56241
+ });
56242
+ const lastRow = row;
56243
+ for (const [actor, arr] of actStack.entries()) {
56244
+ while (arr.length) {
56245
+ const start = arr.pop();
56246
+ const p3 = col.get(actor);
56247
+ if (p3)
56248
+ activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(lastRow) - yForRow(start) });
56249
+ }
56250
+ }
56251
+ return { width, height, participants, lifelines, messages, notes, blocks, activations };
56252
+ }
56253
+ var MARGIN_X, MARGIN_Y, ACTOR_FONT_SIZE, ACTOR_H, LIFELINE_GAP, ACTOR_PAD_X, COL_MIN, ROW_H, NOTE_W, NOTE_PAD, BLOCK_PAD, TITLE_EXTRA_TOP;
56254
+ var init_sequence_layout = __esm({
56255
+ "node_modules/@probelabs/maid/out/renderer/sequence-layout.js"() {
56256
+ init_utils4();
56257
+ MARGIN_X = 24;
56258
+ MARGIN_Y = 24;
56259
+ ACTOR_FONT_SIZE = 16;
56260
+ ACTOR_H = 32;
56261
+ LIFELINE_GAP = 4;
56262
+ ACTOR_PAD_X = 12;
56263
+ COL_MIN = 110;
56264
+ ROW_H = 36;
56265
+ NOTE_W = 160;
56266
+ NOTE_PAD = 8;
56267
+ BLOCK_PAD = 8;
56268
+ TITLE_EXTRA_TOP = 12;
56269
+ }
56270
+ });
56271
+
56272
+ // node_modules/@probelabs/maid/out/renderer/sequence-renderer.js
56273
+ function renderSequence(model, opts = {}) {
56274
+ const layout = layoutSequence(model);
56275
+ const svgParts = [];
56276
+ const width = Math.ceil(layout.width);
56277
+ const height = Math.ceil(layout.height);
56278
+ svgParts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width + 50}" height="${height + 40}" viewBox="-50 -10 ${width + 50} ${height + 40}">`);
56279
+ const sharedCss = buildSharedCss({
56280
+ fontFamily: "Arial, sans-serif",
56281
+ fontSize: 14,
56282
+ nodeFill: "#eef0ff",
56283
+ nodeStroke: "#3f3f3f",
56284
+ edgeStroke: "#555555"
56285
+ });
56286
+ svgParts.push(` <style>${sharedCss}</style>`);
56287
+ for (const p3 of layout.participants)
56288
+ drawParticipant(svgParts, p3);
56289
+ for (const b3 of layout.blocks)
56290
+ svgParts.push(blockBackground(b3.x, b3.y, b3.width, b3.height, 0));
56291
+ for (const l3 of layout.lifelines)
56292
+ svgParts.push(` <line class="lifeline" x1="${l3.x}" y1="${l3.y1}" x2="${l3.x}" y2="${l3.y2}"/>`);
56293
+ for (const a3 of layout.activations)
56294
+ svgParts.push(` <rect class="activation" x="${a3.x}" y="${a3.y}" width="${a3.width}" height="${a3.height}" />`);
56295
+ let counter = model.autonumber?.on ? model.autonumber.start ?? 1 : void 0;
56296
+ const step = model.autonumber?.on ? model.autonumber.step ?? 1 : void 0;
56297
+ for (const m3 of layout.messages) {
56298
+ drawMessage(svgParts, m3);
56299
+ const label = formatMessageLabel(m3.text, counter);
56300
+ if (label)
56301
+ drawMessageLabel(svgParts, m3, label, counter);
56302
+ if (counter != null)
56303
+ counter += step;
56304
+ }
56305
+ for (const n3 of layout.notes)
56306
+ drawNote(svgParts, n3);
56307
+ for (const b3 of layout.blocks) {
56308
+ const title = b3.title ? `${b3.type}: ${b3.title}` : b3.type;
56309
+ const branches = (b3.branches || []).map((br) => ({ y: br.y, title: br.title }));
56310
+ svgParts.push(blockOverlay(b3.x, b3.y, b3.width, b3.height, title, branches, 0, "left", "left", 0));
56311
+ }
56312
+ for (const p3 of layout.participants)
56313
+ drawParticipantBottom(svgParts, p3, layout);
56314
+ svgParts.push("</svg>");
56315
+ let svg = svgParts.join("\n");
56316
+ if (opts.theme)
56317
+ svg = applySequenceTheme(svg, opts.theme);
56318
+ return svg;
56319
+ }
56320
+ function drawParticipant(out, p3) {
56321
+ out.push(` <g class="actor" transform="translate(${p3.x},${p3.y})">`);
56322
+ out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
56323
+ out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
56324
+ out.push(" </g>");
56325
+ }
56326
+ function drawParticipantBottom(out, p3, layout) {
56327
+ const lifeline = layout.lifelines.find((l3) => Math.abs(l3.x - (p3.x + p3.width / 2)) < 1e-3);
56328
+ const y2 = lifeline ? lifeline.y2 : layout.height - 28;
56329
+ out.push(` <g class="actor" transform="translate(${p3.x},${y2})">`);
56330
+ out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
56331
+ out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
56332
+ out.push(" </g>");
56333
+ }
56334
+ function drawMessage(out, m3) {
56335
+ const cls = `msg-line ${m3.line}`.trim();
56336
+ const x1 = m3.x1, x22 = m3.x2, y2 = m3.y;
56337
+ out.push(` <path class="${cls}" d="M ${x1} ${y2} L ${x22} ${y2}" />`);
56338
+ const start = { x: x1, y: y2 };
56339
+ const end = { x: x22, y: y2 };
56340
+ if (m3.endMarker === "arrow")
56341
+ out.push(" " + triangleAtEnd(start, end));
56342
+ if (m3.startMarker === "arrow")
56343
+ out.push(" " + triangleAtStart(start, end));
56344
+ if (m3.endMarker === "open")
56345
+ out.push(` <circle class="openhead" cx="${x22}" cy="${y2}" r="4" />`);
56346
+ if (m3.startMarker === "open")
56347
+ out.push(` <circle class="openhead" cx="${x1}" cy="${y2}" r="4" />`);
56348
+ if (m3.endMarker === "cross")
56349
+ out.push(` <g class="crosshead" transform="translate(${x22},${y2})"><path d="M -4 -4 L 4 4"/><path d="M -4 4 L 4 -4"/></g>`);
56350
+ if (m3.startMarker === "cross")
56351
+ out.push(` <g class="crosshead" transform="translate(${x1},${y2})"><path d="M -4 -4 L 4 4"/><path d="M -4 4 L 4 -4"/></g>`);
56352
+ }
56353
+ function formatMessageLabel(text, counter) {
56354
+ if (!text && counter == null)
56355
+ return void 0;
56356
+ if (counter != null && text)
56357
+ return `${counter}: ${text}`;
56358
+ if (counter != null)
56359
+ return String(counter);
56360
+ return text;
56361
+ }
56362
+ function drawMessageLabel(out, m3, label, _counter) {
56363
+ const xMid = (m3.x1 + m3.x2) / 2;
56364
+ const h3 = 16;
56365
+ const w3 = Math.max(20, measureText(label, 12) + 10);
56366
+ const x3 = xMid - w3 / 2;
56367
+ const y2 = m3.y - 10 - h3 / 2;
56368
+ out.push(` <rect class="msg-label-bg" x="${x3}" y="${y2}" width="${w3}" height="${h3}" rx="0"/>`);
56369
+ out.push(` <text class="msg-label" x="${xMid}" y="${y2 + h3 / 2}" text-anchor="middle">${escapeXml(label)}</text>`);
56370
+ }
56371
+ function drawNote(out, n3) {
56372
+ out.push(` <g class="note" transform="translate(${n3.x},${n3.y})">`);
56373
+ out.push(` <rect width="${n3.width}" height="${n3.height}" rx="0"/>`);
56374
+ out.push(` <text class="note-text" x="${n3.width / 2}" y="${n3.height / 2 + 4}" text-anchor="middle">${escapeXml(n3.text)}</text>`);
56375
+ out.push(" </g>");
56376
+ }
56377
+ function applySequenceTheme(svg, theme) {
56378
+ let out = svg;
56379
+ if (theme.actorBkg)
56380
+ out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorBkg)};`));
56381
+ if (theme.actorBorder)
56382
+ out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.actorBorder)};`));
56383
+ if (theme.actorTextColor)
56384
+ out = out.replace(/\.actor-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorTextColor)};`));
56385
+ if (theme.lifelineColor)
56386
+ out = out.replace(/\.lifeline\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lifelineColor)};`));
56387
+ if (theme.lineColor)
56388
+ out = out.replace(/\.msg-line\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
56389
+ if (theme.arrowheadColor) {
56390
+ out = out.replace(/\.arrowhead\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.arrowheadColor)};`));
56391
+ out = out.replace(/\.openhead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
56392
+ out = out.replace(/\.crosshead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
56393
+ }
56394
+ if (theme.noteBkg)
56395
+ out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteBkg)};`));
56396
+ if (theme.noteBorder)
56397
+ out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.noteBorder)};`));
56398
+ if (theme.noteTextColor)
56399
+ out = out.replace(/\.note-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteTextColor)};`));
56400
+ if (theme.activationBkg)
56401
+ out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.activationBkg)};`));
56402
+ if (theme.activationBorder)
56403
+ out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.activationBorder)};`));
56404
+ return out;
56405
+ }
56406
+ var init_sequence_renderer = __esm({
56407
+ "node_modules/@probelabs/maid/out/renderer/sequence-renderer.js"() {
56408
+ init_sequence_layout();
56409
+ init_utils4();
56410
+ init_arrow_utils();
56411
+ init_block_utils();
56412
+ init_styles();
56413
+ }
56414
+ });
56415
+
56416
+ // node_modules/@probelabs/maid/out/core/frontmatter.js
56417
+ function parseFrontmatter(input) {
56418
+ const text = input.startsWith("\uFEFF") ? input.slice(1) : input;
56419
+ const lines = text.split(/\r?\n/);
56420
+ if (lines.length < 3 || lines[0].trim() !== "---")
56421
+ return null;
56422
+ let i3 = 1;
56423
+ const block = [];
56424
+ while (i3 < lines.length && lines[i3].trim() !== "---") {
56425
+ block.push(lines[i3]);
56426
+ i3++;
56427
+ }
56428
+ if (i3 >= lines.length)
56429
+ return null;
56430
+ const body = lines.slice(i3 + 1).join("\n");
56431
+ const raw = block.join("\n");
56432
+ const config = {};
56433
+ const themeVars = {};
56434
+ let themeUnderConfig = false;
56435
+ let ctx = "root";
56436
+ for (const line of block) {
56437
+ if (!line.trim())
56438
+ continue;
56439
+ const indent = line.match(/^\s*/)?.[0].length ?? 0;
56440
+ const mKey = line.match(/^\s*([A-Za-z0-9_\-]+):\s*(.*)$/);
56441
+ if (!mKey)
56442
+ continue;
56443
+ const key = mKey[1];
56444
+ let value = mKey[2] || "";
56445
+ if (indent === 0) {
56446
+ if (key === "config") {
56447
+ ctx = "config";
56448
+ continue;
56449
+ }
56450
+ if (key === "themeVariables") {
56451
+ ctx = "theme";
56452
+ continue;
56453
+ }
56454
+ ctx = "root";
56455
+ continue;
56456
+ }
56457
+ if (ctx === "config") {
56458
+ if (indent <= 2 && key !== "pie" && key !== "themeVariables")
56459
+ continue;
56460
+ if (key === "pie") {
56461
+ ctx = "config.pie";
56462
+ ensure(config, "pie", {});
56463
+ continue;
56464
+ }
56465
+ if (key === "themeVariables") {
56466
+ ctx = "theme";
56467
+ themeUnderConfig = true;
56468
+ continue;
56469
+ }
56470
+ continue;
56471
+ }
56472
+ if (ctx === "config.pie") {
56473
+ if (indent < 4) {
56474
+ if (key === "pie") {
56475
+ ctx = "config.pie";
56476
+ ensure(config, "pie", {});
56477
+ continue;
56478
+ }
56479
+ if (key === "themeVariables") {
56480
+ ctx = "theme";
56481
+ themeUnderConfig = true;
56482
+ continue;
56483
+ }
56484
+ ctx = "config";
56485
+ continue;
56486
+ }
56487
+ setKV(config.pie, key, value);
56488
+ continue;
56489
+ }
56490
+ if (ctx === "theme") {
56491
+ if (indent < 2) {
56492
+ ctx = "root";
56493
+ continue;
56494
+ }
56495
+ setKV(themeVars, key, value);
56496
+ continue;
56497
+ }
56498
+ }
56499
+ if (themeUnderConfig && Object.keys(themeVars).length) {
56500
+ ensure(config, "themeVariables", {});
56501
+ Object.assign(config.themeVariables, themeVars);
56502
+ }
56503
+ return { raw, body, config: Object.keys(config).length ? config : void 0, themeVariables: Object.keys(themeVars).length ? themeVars : void 0 };
56504
+ }
56505
+ function ensure(obj, key, def) {
56506
+ if (obj[key] == null)
56507
+ obj[key] = def;
56508
+ }
56509
+ function unquote2(val) {
56510
+ const v3 = val.trim();
56511
+ if (v3.startsWith('"') && v3.endsWith('"') || v3.startsWith("'") && v3.endsWith("'")) {
56512
+ return v3.slice(1, -1);
56513
+ }
56514
+ return v3;
56515
+ }
56516
+ function setKV(target, key, rawValue) {
56517
+ const v3 = unquote2(rawValue);
56518
+ if (v3 === "") {
56519
+ target[key] = "";
56520
+ return;
56521
+ }
56522
+ const num = Number(v3);
56523
+ if (!Number.isNaN(num) && /^-?[0-9]+(\.[0-9]+)?$/.test(v3)) {
56524
+ target[key] = num;
56525
+ return;
56526
+ }
56527
+ if (/^(true|false)$/i.test(v3)) {
56528
+ target[key] = /^true$/i.test(v3);
56529
+ return;
56530
+ }
56531
+ target[key] = v3;
56532
+ }
56533
+ var init_frontmatter = __esm({
56534
+ "node_modules/@probelabs/maid/out/core/frontmatter.js"() {
56535
+ }
56536
+ });
56537
+
56538
+ // node_modules/@probelabs/maid/out/renderer/dot-renderer.js
56539
+ var init_dot_renderer = __esm({
56540
+ "node_modules/@probelabs/maid/out/renderer/dot-renderer.js"() {
56541
+ }
56542
+ });
56543
+
56544
+ // node_modules/@probelabs/maid/out/renderer/index.js
56545
+ function applyPieTheme(svg, theme) {
56546
+ if (!theme)
56547
+ return svg;
56548
+ let out = svg;
56549
+ if (theme.pieOuterStrokeWidth != null || theme.pieStrokeColor) {
56550
+ out = out.replace(/\.pieOuterCircle\s*\{[^}]*\}/, (m3) => {
56551
+ let rule = m3;
56552
+ if (theme.pieStrokeColor)
56553
+ rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`);
56554
+ if (theme.pieOuterStrokeWidth != null)
56555
+ rule = rule.replace(/stroke-width:\s*[^;]+;/, `stroke-width: ${String(theme.pieOuterStrokeWidth)};`);
56556
+ return rule;
56557
+ });
56558
+ if (theme.pieStrokeColor) {
56559
+ out = out.replace(/\.pieCircle\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`));
56560
+ }
56561
+ }
56562
+ if (theme.pieSectionTextColor) {
56563
+ const c3 = String(theme.pieSectionTextColor);
56564
+ out = out.replace(/\.slice-label \{[^}]*\}/, (m3) => m3.replace(/fill:\s*#[0-9A-Fa-f]{3,8}|fill:\s*rgb\([^)]*\)/, `fill: ${c3}`));
56565
+ out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 fill="${c3}">`);
56566
+ }
56567
+ if (theme.pieTitleTextColor) {
56568
+ const c3 = String(theme.pieTitleTextColor);
56569
+ out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 fill="${c3}">`);
56570
+ }
56571
+ if (theme.pieSectionTextSize) {
56572
+ const size = String(theme.pieSectionTextSize);
56573
+ out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 font-size="${size}">`);
56574
+ }
56575
+ if (theme.pieTitleTextSize) {
56576
+ const size = String(theme.pieTitleTextSize);
56577
+ out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 font-size="${size}">`);
56578
+ }
56579
+ const colors = [];
56580
+ for (let i3 = 1; i3 <= 24; i3++) {
56581
+ const key = "pie" + i3;
56582
+ if (theme[key])
56583
+ colors.push(String(theme[key]));
56584
+ }
56585
+ if (colors.length) {
56586
+ let idx = 0;
56587
+ out = out.replace(/<path[^>]*class="pieCircle"[^>]*\sfill="([^"]+)"/g, (_m2) => {
56588
+ const color = colors[idx] ?? null;
56589
+ idx++;
56590
+ if (color)
56591
+ return _m2.replace(/fill="([^"]+)"/, `fill="${color}"`);
56592
+ return _m2;
56593
+ });
56594
+ }
56595
+ return out;
56596
+ }
56597
+ function applyFlowchartTheme(svg, theme) {
56598
+ if (!theme)
56599
+ return svg;
56600
+ let out = svg;
56601
+ if (theme.nodeBkg || theme.nodeBorder) {
56602
+ out = out.replace(/\.node-shape\s*\{[^}]*\}/, (m3) => {
56603
+ let rule = m3;
56604
+ if (theme.nodeBkg)
56605
+ rule = rule.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeBkg)};`);
56606
+ if (theme.nodeBorder)
56607
+ rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.nodeBorder)};`);
56608
+ return rule;
56609
+ });
56610
+ }
56611
+ if (theme.nodeTextColor) {
56612
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeTextColor)};`));
56613
+ }
56614
+ if (theme.lineColor) {
56615
+ out = out.replace(/\.edge-path\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
56616
+ }
56617
+ if (theme.arrowheadColor) {
56618
+ out = out.replace(/(<path d="M0,0 L0,[0-9.]+ L[0-9.]+,[0-9.]+ z"[^>]*)(fill="[^"]*")/g, (_m2, p1) => `${p1}fill="${String(theme.arrowheadColor)}"`);
56619
+ out = out.replace(/(<circle cx="4\.5" cy="4\.5" r="4\.5"[^>]*)(fill="[^"]*")/g, (_m2, p1) => `${p1}fill="${String(theme.arrowheadColor)}"`);
56620
+ }
56621
+ if (theme.clusterBkg) {
56622
+ out = out.replace(/\.cluster-bg\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterBkg)};`));
56623
+ }
56624
+ if (theme.clusterBorder) {
56625
+ out = out.replace(/\.cluster-border\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.clusterBorder)};`));
56626
+ }
56627
+ if (theme.clusterTextColor) {
56628
+ out = out.replace(/\.cluster-label-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterTextColor)};`));
56629
+ }
56630
+ if (theme.fontFamily)
56631
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-family:\s*[^;]+;/, `font-family: ${String(theme.fontFamily)};`));
56632
+ if (theme.fontSize)
56633
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-size:\s*[^;]+;/, `font-size: ${String(theme.fontSize)};`));
56634
+ return out;
56635
+ }
56636
+ function renderMermaid(text, options = {}) {
56637
+ const renderer = new MermaidRenderer(options.layoutEngine, options.renderer);
56638
+ return renderer.renderAny(text, options);
56639
+ }
56640
+ var MermaidRenderer;
56641
+ var init_renderer = __esm({
56642
+ "node_modules/@probelabs/maid/out/renderer/index.js"() {
56643
+ init_lexer2();
56644
+ init_parser2();
56645
+ init_graph_builder();
56646
+ init_layout();
56647
+ init_svg_generator();
56648
+ init_pie_builder();
56649
+ init_pie_renderer();
56650
+ init_sequence_builder();
56651
+ init_sequence_renderer();
56652
+ init_frontmatter();
56653
+ init_layout();
56654
+ init_svg_generator();
56655
+ init_dot_renderer();
56656
+ MermaidRenderer = class {
56657
+ constructor(layoutEngine, renderer) {
56658
+ this.graphBuilder = new GraphBuilder();
56659
+ this.layoutEngine = layoutEngine || new DagreLayoutEngine();
56660
+ this.renderer = renderer || new SVGRenderer();
56661
+ }
56662
+ /**
56663
+ * Renders a Mermaid flowchart diagram
56664
+ */
56665
+ render(text, options = {}) {
56666
+ const errors = [];
56667
+ const layoutEngine = options.layoutEngine || this.layoutEngine;
56668
+ const renderer = options.renderer || this.renderer;
56669
+ try {
56670
+ const lexResult = tokenize(text);
56671
+ if (lexResult.errors && lexResult.errors.length > 0) {
56672
+ for (const error2 of lexResult.errors) {
56673
+ errors.push({
56674
+ line: error2.line || 1,
56675
+ column: error2.column || 1,
56676
+ message: error2.message,
56677
+ severity: "error",
56678
+ code: "LEXER_ERROR"
56679
+ });
56680
+ }
56681
+ }
56682
+ parserInstance.reset();
56683
+ parserInstance.input = lexResult.tokens;
56684
+ const cst = parserInstance.diagram();
56685
+ if (parserInstance.errors && parserInstance.errors.length > 0) {
56686
+ for (const error2 of parserInstance.errors) {
56687
+ const token = error2.token;
56688
+ errors.push({
56689
+ line: token?.startLine || 1,
56690
+ column: token?.startColumn || 1,
56691
+ message: error2.message,
56692
+ severity: "error",
56693
+ code: "PARSER_ERROR"
56694
+ });
56695
+ }
56696
+ }
56697
+ const graph = this.graphBuilder.build(cst);
56698
+ let layout;
56699
+ try {
56700
+ layout = layoutEngine.layout(graph);
56701
+ } catch (layoutError) {
56702
+ errors.push({
56703
+ line: 1,
56704
+ column: 1,
56705
+ message: layoutError.message || "Layout calculation failed",
56706
+ severity: "error",
56707
+ code: "LAYOUT_ERROR"
56708
+ });
56709
+ return {
56710
+ svg: this.generateErrorSvg(layoutError.message || "Layout calculation failed"),
56711
+ graph,
56712
+ errors
56713
+ };
56714
+ }
56715
+ let svg = renderer.render(layout);
56716
+ if (options.showErrors && errors.length > 0) {
56717
+ svg = this.addErrorOverlays(svg, errors);
56718
+ }
56719
+ return {
56720
+ svg,
56721
+ graph,
56722
+ errors
56723
+ };
56724
+ } catch (error2) {
56725
+ const errorSvg = this.generateErrorSvg(error2.message || "Unknown error occurred");
56726
+ errors.push({
56727
+ line: 1,
56728
+ column: 1,
56729
+ message: error2.message || "Unknown error occurred",
56730
+ severity: "error",
56731
+ code: "RENDER_ERROR"
56732
+ });
56733
+ return {
56734
+ svg: errorSvg,
56735
+ graph: { nodes: [], edges: [], direction: "TD" },
56736
+ errors
56737
+ };
56738
+ }
56739
+ }
56740
+ /**
56741
+ * Renders supported diagram types (flowchart + pie for now)
56742
+ */
56743
+ renderAny(text, options = {}) {
56744
+ let content = text;
56745
+ let theme;
56746
+ if (text.trimStart().startsWith("---")) {
56747
+ const fm = parseFrontmatter(text);
56748
+ if (fm) {
56749
+ content = fm.body;
56750
+ theme = fm.themeVariables || fm.config && fm.config.themeVariables || void 0;
56751
+ }
56752
+ }
56753
+ const firstLine = content.trim().split("\n")[0];
56754
+ if (/^(flowchart|graph)\s+/i.test(firstLine)) {
56755
+ const res = this.render(content, options);
56756
+ const svg2 = theme ? applyFlowchartTheme(res.svg, theme) : res.svg;
56757
+ return { svg: svg2, graph: res.graph, errors: res.errors };
56758
+ }
56759
+ if (/^pie\b/i.test(firstLine)) {
56760
+ try {
56761
+ const { model, errors } = buildPieModel(content);
56762
+ const svg = renderPie(model, {
56763
+ width: options.width,
56764
+ height: options.height,
56765
+ rimStroke: theme?.pieStrokeColor,
56766
+ rimStrokeWidth: theme?.pieOuterStrokeWidth
56767
+ });
56768
+ const themedSvg = applyPieTheme(svg, theme);
56769
+ return { svg: themedSvg, graph: { nodes: [], edges: [], direction: "TD" }, errors };
56770
+ } catch (e3) {
56771
+ const msg = e3?.message || "Pie render error";
56772
+ const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "PIE_RENDER" }];
56773
+ return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
56774
+ }
56775
+ }
56776
+ if (/^sequenceDiagram\b/.test(firstLine)) {
56777
+ try {
56778
+ const model = buildSequenceModel(content);
56779
+ const svg = renderSequence(model, { theme });
56780
+ return { svg, graph: { nodes: [], edges: [], direction: "TD" }, errors: [] };
56781
+ } catch (e3) {
56782
+ const msg = e3?.message || "Sequence render error";
56783
+ const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "SEQUENCE_RENDER" }];
56784
+ return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
56785
+ }
56786
+ }
56787
+ const errorSvg = this.generateErrorSvg("Unsupported diagram type. Rendering supports flowchart, pie, and sequence for now.");
56788
+ return {
56789
+ svg: errorSvg,
56790
+ graph: { nodes: [], edges: [], direction: "TD" },
56791
+ errors: [{
56792
+ line: 1,
56793
+ column: 1,
56794
+ message: "Unsupported diagram type",
56795
+ severity: "error",
56796
+ code: "UNSUPPORTED_TYPE"
56797
+ }]
56798
+ };
56799
+ }
56800
+ addErrorOverlays(svg, errors) {
56801
+ const errorStyle = `
56802
+ <style>
56803
+ .error-indicator {
56804
+ fill: #ff0000;
56805
+ opacity: 0.8;
56806
+ }
56807
+ .error-text {
56808
+ fill: white;
56809
+ font-family: Arial, sans-serif;
56810
+ font-size: 12px;
56811
+ font-weight: bold;
56812
+ }
56813
+ </style>`;
56814
+ const errorIndicator = `
56815
+ <g id="errors">
56816
+ <rect x="5" y="5" width="100" height="25" rx="3" class="error-indicator" />
56817
+ <text x="55" y="20" text-anchor="middle" class="error-text">${errors.length} error${errors.length !== 1 ? "s" : ""}</text>
56818
+ </g>`;
56819
+ return svg.replace("</svg>", `${errorStyle}${errorIndicator}</svg>`);
56820
+ }
56821
+ generateErrorSvg(message) {
56822
+ const width = 400;
56823
+ const height = 200;
56824
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
56825
+ <rect width="${width}" height="${height}" fill="#fee" stroke="#c00" stroke-width="2" />
56826
+ <text x="${width / 2}" y="${height / 2 - 20}" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#c00">
56827
+ Render Error
56828
+ </text>
56829
+ <text x="${width / 2}" y="${height / 2 + 10}" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#666">
56830
+ ${this.wrapText(message, 40).map((line, i3) => `<tspan x="${width / 2}" dy="${i3 === 0 ? 0 : 15}">${this.escapeXml(line)}</tspan>`).join("")}
56831
+ </text>
56832
+ </svg>`;
56833
+ }
56834
+ wrapText(text, maxLength) {
56835
+ const words = text.split(" ");
56836
+ const lines = [];
56837
+ let currentLine = "";
56838
+ for (const word of words) {
56839
+ if (currentLine.length + word.length + 1 <= maxLength) {
56840
+ currentLine += (currentLine ? " " : "") + word;
56841
+ } else {
56842
+ if (currentLine)
56843
+ lines.push(currentLine);
56844
+ currentLine = word;
56845
+ }
56846
+ }
56847
+ if (currentLine)
56848
+ lines.push(currentLine);
56849
+ return lines.slice(0, 3);
56850
+ }
56851
+ escapeXml(text) {
56852
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
56853
+ }
56854
+ };
56855
+ }
56856
+ });
56857
+
56858
+ // node_modules/@probelabs/maid/out/mermaid-compat.js
56859
+ function createMermaidAPI() {
56860
+ return {
56861
+ initialize(_config) {
56862
+ },
56863
+ async render(_id, text, options) {
56864
+ try {
56865
+ const result = renderMermaid(text, options);
56866
+ return { svg: result.svg };
56867
+ } catch (error2) {
56868
+ throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
56869
+ }
56870
+ },
56871
+ renderSync(_id, text, options) {
56872
+ try {
56873
+ const result = renderMermaid(text, options);
56874
+ return { svg: result.svg };
56875
+ } catch (error2) {
56876
+ throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
56877
+ }
56878
+ }
56879
+ };
56880
+ }
56881
+ var maid;
56882
+ var init_mermaid_compat = __esm({
56883
+ "node_modules/@probelabs/maid/out/mermaid-compat.js"() {
56884
+ init_renderer();
56885
+ maid = createMermaidAPI();
53465
56886
  }
53466
56887
  });
53467
56888
 
@@ -53495,6 +56916,7 @@ var init_out = __esm({
53495
56916
  init_edits();
53496
56917
  init_fixes();
53497
56918
  init_renderer();
56919
+ init_mermaid_compat();
53498
56920
  init_router();
53499
56921
  init_fixes();
53500
56922
  init_edits();