@probelabs/visor 0.1.71 → 0.1.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- process.env.VISOR_VERSION = '0.1.71';
3
- process.env.PROBE_VERSION = '0.6.0-rc115';
2
+ process.env.VISOR_VERSION = '0.1.72';
3
+ process.env.PROBE_VERSION = '0.6.0-rc116';
4
4
  /******/ (() => { // webpackBootstrap
5
5
  /******/ var __webpack_modules__ = ({
6
6
 
@@ -94483,6 +94483,11 @@ ${prInfo.fullDiff ? this.escapeXml(prInfo.fullDiff) : ''}
94483
94483
  allowEdit: false, // We don't want the agent to modify files
94484
94484
  debug: this.config.debug || false,
94485
94485
  };
94486
+ // Wire MCP configuration when provided
94487
+ if (this.config.mcpServers && Object.keys(this.config.mcpServers).length > 0) {
94488
+ options.enableMcp = true;
94489
+ options.mcpConfig = { mcpServers: this.config.mcpServers };
94490
+ }
94486
94491
  // Add provider-specific options if configured
94487
94492
  if (this.config.provider) {
94488
94493
  // Map claude-code to anthropic for ProbeAgent compatibility
@@ -103963,13 +103968,13 @@ class AICheckProvider extends check_provider_interface_1.CheckProvider {
103963
103968
  }
103964
103969
  // Setup MCP tools if any servers are configured
103965
103970
  if (Object.keys(mcpServers).length > 0) {
103971
+ // Pass raw server config to AI service so it can enable MCP in ProbeAgent
103972
+ aiConfig.mcpServers = mcpServers;
103973
+ // Optional: attempt to enumerate tools for debug visibility (not required for functionality)
103966
103974
  const mcpConfig = { mcpServers };
103967
103975
  const mcpTools = await this.setupMcpTools(mcpConfig);
103968
- if (mcpTools.length > 0) {
103969
- aiConfig.tools = mcpTools;
103970
- if (aiConfig.debug) {
103971
- console.error(`🔧 Debug: AI check configured with ${mcpTools.length} MCP tools from ${Object.keys(mcpServers).length} servers`);
103972
- }
103976
+ if (aiConfig.debug) {
103977
+ console.error(`🔧 Debug: AI check MCP configured with ${Object.keys(mcpServers).length} servers; discovered ${mcpTools.length} tools`);
103973
103978
  }
103974
103979
  }
103975
103980
  // Process prompt with Liquid templates and file loading
@@ -168081,13 +168086,14 @@ function tokenize(text) {
168081
168086
  const lexResult = MermaidLexer.tokenize(text);
168082
168087
  return lexResult;
168083
168088
  }
168084
- 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;
168089
+ 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;
168085
168090
  var init_lexer2 = __esm({
168086
168091
  "node_modules/@probelabs/maid/out/diagrams/flowchart/lexer.js"() {
168087
168092
  init_api5();
168088
168093
  Identifier = createToken({
168089
168094
  name: "Identifier",
168090
- pattern: /[a-zA-Z_][a-zA-Z0-9_-]*/
168095
+ // e.g., id-2, _id, A1, but not A-- (that belongs to an arrow token)
168096
+ pattern: /[a-zA-Z_][a-zA-Z0-9_]*(?:-[a-zA-Z0-9_]+)*/
168091
168097
  });
168092
168098
  NumberLiteral = createToken({
168093
168099
  name: "NumberLiteral",
@@ -168228,6 +168234,8 @@ var init_lexer2 = __esm({
168228
168234
  AngleOpen = createToken({ name: "AngleOpen", pattern: />/ });
168229
168235
  AngleLess = createToken({ name: "AngleLess", pattern: /</ });
168230
168236
  Pipe = createToken({ name: "Pipe", pattern: /\|/ });
168237
+ ForwardSlash = createToken({ name: "ForwardSlash", pattern: /\// });
168238
+ Backslash = createToken({ name: "Backslash", pattern: /\\/ });
168231
168239
  QuotedString = createToken({
168232
168240
  name: "QuotedString",
168233
168241
  // Allow escaped characters within quotes (Mermaid accepts \" inside "...")
@@ -168311,6 +168319,8 @@ var init_lexer2 = __esm({
168311
168319
  DiamondClose,
168312
168320
  AngleOpen,
168313
168321
  AngleLess,
168322
+ ForwardSlash,
168323
+ Backslash,
168314
168324
  Pipe,
168315
168325
  TripleColon,
168316
168326
  Ampersand,
@@ -168503,6 +168513,8 @@ var init_parser2 = __esm({
168503
168513
  // Allow HTML-like tags (e.g., <br/>) inside labels
168504
168514
  { ALT: () => this.CONSUME(AngleLess) },
168505
168515
  { ALT: () => this.CONSUME(AngleOpen) },
168516
+ { ALT: () => this.CONSUME(ForwardSlash) },
168517
+ { ALT: () => this.CONSUME(Backslash) },
168506
168518
  { ALT: () => this.CONSUME(Comma) },
168507
168519
  { ALT: () => this.CONSUME(Colon) },
168508
168520
  // HTML entities and ampersands inside labels
@@ -169551,6 +169563,66 @@ ${br.example}`,
169551
169563
  length: len
169552
169564
  };
169553
169565
  }
169566
+ if (inRule("boxBlock") && (err.name === "NoViableAltException" || err.name === "MismatchedTokenException")) {
169567
+ const isMessage = /->|-->>|-->/.test(ltxt);
169568
+ const isNote = /note\s+(left|right|over)/i.test(ltxt);
169569
+ const isActivate = /activate\s+/i.test(ltxt);
169570
+ const isDeactivate = /deactivate\s+/i.test(ltxt);
169571
+ if (isMessage || isNote || isActivate || isDeactivate || tokType === "NoteKeyword" || tokType === "ActivateKeyword" || tokType === "DeactivateKeyword") {
169572
+ const lines2 = text.split(/\r?\n/);
169573
+ const boxLine = Math.max(0, line - 1);
169574
+ let hasEnd = false;
169575
+ let openIdx = -1;
169576
+ for (let i3 = boxLine; i3 >= 0; i3--) {
169577
+ if (/^\s*box\b/.test(lines2[i3] || "")) {
169578
+ openIdx = i3;
169579
+ break;
169580
+ }
169581
+ }
169582
+ if (openIdx !== -1) {
169583
+ for (let i3 = boxLine; i3 < lines2.length; i3++) {
169584
+ if (/^\s*end\s*$/.test(lines2[i3] || "")) {
169585
+ hasEnd = true;
169586
+ break;
169587
+ }
169588
+ if (i3 > boxLine && /^\s*(sequenceDiagram|box|alt|opt|loop|par|rect|critical|break)\b/.test(lines2[i3] || ""))
169589
+ break;
169590
+ }
169591
+ }
169592
+ if (hasEnd) {
169593
+ let hasParticipants = false;
169594
+ for (let i3 = openIdx + 1; i3 < lines2.length; i3++) {
169595
+ const raw = lines2[i3] || "";
169596
+ if (/^\s*end\s*$/.test(raw))
169597
+ break;
169598
+ if (/^\s*(participant|actor)\b/i.test(raw)) {
169599
+ hasParticipants = true;
169600
+ break;
169601
+ }
169602
+ }
169603
+ if (!hasParticipants) {
169604
+ return {
169605
+ line: openIdx + 1,
169606
+ column: 1,
169607
+ severity: "error",
169608
+ code: "SE-BOX-EMPTY",
169609
+ message: "Box block has no participant/actor declarations. Use 'rect' to group messages visually.",
169610
+ 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",
169611
+ length: 3
169612
+ };
169613
+ }
169614
+ return {
169615
+ line,
169616
+ column,
169617
+ severity: "error",
169618
+ code: "SE-BOX-INVALID-CONTENT",
169619
+ message: "Box blocks can only contain participant/actor declarations.",
169620
+ hint: 'Move messages, notes, and other statements outside the box block.\nExample:\nbox "Group"\n participant A\n participant B\nend\nA->>B: Message',
169621
+ length: len
169622
+ };
169623
+ }
169624
+ }
169625
+ }
169554
169626
  const blockRules = [
169555
169627
  { rule: "altBlock", label: "alt" },
169556
169628
  { rule: "optBlock", label: "opt" },
@@ -170450,9 +170522,15 @@ var init_parser4 = __esm({
170450
170522
  this.CONSUME(BoxKeyword);
170451
170523
  this.OPTION(() => this.SUBRULE(this.lineRemainder));
170452
170524
  this.AT_LEAST_ONE(() => this.CONSUME(Newline3));
170453
- this.MANY(() => this.SUBRULE(this.line));
170525
+ this.MANY(() => this.OR([
170526
+ { ALT: () => this.SUBRULE(this.participantDecl) },
170527
+ { ALT: () => this.SUBRULE(this.blankLine) }
170528
+ ]));
170454
170529
  this.CONSUME(EndKeyword2);
170455
- this.AT_LEAST_ONE2(() => this.CONSUME2(Newline3));
170530
+ this.OR2([
170531
+ { ALT: () => this.AT_LEAST_ONE2(() => this.CONSUME2(Newline3)) },
170532
+ { ALT: () => this.CONSUME2(EOF) }
170533
+ ]);
170456
170534
  });
170457
170535
  this.lineRemainder = this.RULE("lineRemainder", () => {
170458
170536
  this.AT_LEAST_ONE(() => this.OR([
@@ -172003,6 +172081,69 @@ function computeFixes(text, errors, level = "safe") {
172003
172081
  edits.push(replaceRange(text, at(e3), e3.length ?? 4, "option"));
172004
172082
  continue;
172005
172083
  }
172084
+ if (is("SE-BOX-EMPTY", e3)) {
172085
+ const lines = text.split(/\r?\n/);
172086
+ const boxIdx = Math.max(0, e3.line - 1);
172087
+ const boxLine = lines[boxIdx] || "";
172088
+ const labelMatch = /^\s*box\s+(.+)$/.exec(boxLine);
172089
+ if (labelMatch) {
172090
+ const indent = boxLine.match(/^\s*/)?.[0] || "";
172091
+ const newLine = `${indent}rect rgb(240, 240, 255)`;
172092
+ edits.push({ start: { line: e3.line, column: 1 }, end: { line: e3.line, column: boxLine.length + 1 }, newText: newLine });
172093
+ }
172094
+ continue;
172095
+ }
172096
+ if (is("SE-BOX-INVALID-CONTENT", e3)) {
172097
+ const lines = text.split(/\r?\n/);
172098
+ const curIdx = Math.max(0, e3.line - 1);
172099
+ const boxRe = /^(\s*)box\b/;
172100
+ let openIdx = -1;
172101
+ let openIndent = "";
172102
+ for (let i3 = curIdx; i3 >= 0; i3--) {
172103
+ const m3 = boxRe.exec(lines[i3] || "");
172104
+ if (m3) {
172105
+ openIdx = i3;
172106
+ openIndent = m3[1] || "";
172107
+ break;
172108
+ }
172109
+ }
172110
+ if (openIdx !== -1) {
172111
+ let endIdx = -1;
172112
+ for (let i3 = openIdx + 1; i3 < lines.length; i3++) {
172113
+ const trimmed = (lines[i3] || "").trim();
172114
+ if (trimmed === "end") {
172115
+ endIdx = i3;
172116
+ break;
172117
+ }
172118
+ }
172119
+ if (endIdx !== -1) {
172120
+ const invalidLines = [];
172121
+ for (let i3 = openIdx + 1; i3 < endIdx; i3++) {
172122
+ const raw = lines[i3] || "";
172123
+ const trimmed = raw.trim();
172124
+ if (trimmed === "")
172125
+ continue;
172126
+ if (!/^\s*(participant|actor)\b/i.test(raw)) {
172127
+ invalidLines.push(i3);
172128
+ }
172129
+ }
172130
+ if (invalidLines.length > 0) {
172131
+ const endIndent = openIndent;
172132
+ const movedContent = invalidLines.map((i3) => {
172133
+ const line = lines[i3] || "";
172134
+ const trimmed = line.trimStart();
172135
+ return endIndent + trimmed;
172136
+ }).join("\n") + "\n";
172137
+ for (let i3 = invalidLines.length - 1; i3 >= 0; i3--) {
172138
+ const idx = invalidLines[i3];
172139
+ edits.push({ start: { line: idx + 1, column: 1 }, end: { line: idx + 2, column: 1 }, newText: "" });
172140
+ }
172141
+ edits.push(insertAt(text, { line: endIdx + 2, column: 1 }, movedContent));
172142
+ }
172143
+ }
172144
+ }
172145
+ continue;
172146
+ }
172006
172147
  if (is("SE-BLOCK-MISSING-END", e3)) {
172007
172148
  const lines = text.split(/\r?\n/);
172008
172149
  const curIdx = Math.max(0, e3.line - 1);
@@ -172283,8 +172424,543 @@ var init_fixes = __esm({
172283
172424
  });
172284
172425
 
172285
172426
  // node_modules/@probelabs/maid/out/renderer/graph-builder.js
172427
+ var GraphBuilder;
172286
172428
  var init_graph_builder = __esm({
172287
172429
  "node_modules/@probelabs/maid/out/renderer/graph-builder.js"() {
172430
+ GraphBuilder = class {
172431
+ constructor() {
172432
+ this.nodes = /* @__PURE__ */ new Map();
172433
+ this.edges = [];
172434
+ this.nodeCounter = 0;
172435
+ this.edgeCounter = 0;
172436
+ this.subgraphs = [];
172437
+ this.currentSubgraphStack = [];
172438
+ this.classStyles = /* @__PURE__ */ new Map();
172439
+ this.nodeStyles = /* @__PURE__ */ new Map();
172440
+ this.nodeClasses = /* @__PURE__ */ new Map();
172441
+ }
172442
+ build(cst) {
172443
+ this.reset();
172444
+ if (!cst || !cst.children) {
172445
+ return {
172446
+ nodes: [],
172447
+ edges: [],
172448
+ direction: "TD",
172449
+ subgraphs: []
172450
+ };
172451
+ }
172452
+ const direction = this.extractDirection(cst);
172453
+ this.processStatements(cst);
172454
+ return {
172455
+ nodes: Array.from(this.nodes.values()),
172456
+ edges: this.edges,
172457
+ direction,
172458
+ subgraphs: this.subgraphs
172459
+ };
172460
+ }
172461
+ reset() {
172462
+ this.nodes.clear();
172463
+ this.edges = [];
172464
+ this.nodeCounter = 0;
172465
+ this.edgeCounter = 0;
172466
+ this.subgraphs = [];
172467
+ this.currentSubgraphStack = [];
172468
+ this.classStyles.clear();
172469
+ this.nodeStyles.clear();
172470
+ this.nodeClasses.clear();
172471
+ }
172472
+ extractDirection(cst) {
172473
+ const dirToken = cst.children?.Direction?.[0];
172474
+ const dir = dirToken?.image?.toUpperCase();
172475
+ switch (dir) {
172476
+ case "TB":
172477
+ case "TD":
172478
+ return "TD";
172479
+ case "BT":
172480
+ return "BT";
172481
+ case "LR":
172482
+ return "LR";
172483
+ case "RL":
172484
+ return "RL";
172485
+ default:
172486
+ return "TD";
172487
+ }
172488
+ }
172489
+ processStatements(cst) {
172490
+ const statements = cst.children?.statement;
172491
+ if (!statements)
172492
+ return;
172493
+ for (const stmt of statements) {
172494
+ if (stmt.children?.nodeStatement) {
172495
+ this.processNodeStatement(stmt.children.nodeStatement[0]);
172496
+ } else if (stmt.children?.subgraph) {
172497
+ this.processSubgraph(stmt.children.subgraph[0]);
172498
+ } else if (stmt.children?.classDefStatement) {
172499
+ this.processClassDef(stmt.children.classDefStatement[0]);
172500
+ } else if (stmt.children?.classStatement) {
172501
+ this.processClassAssign(stmt.children.classStatement[0]);
172502
+ } else if (stmt.children?.styleStatement) {
172503
+ this.processStyle(stmt.children.styleStatement[0]);
172504
+ }
172505
+ }
172506
+ }
172507
+ processNodeStatement(stmt) {
172508
+ const groups = stmt.children?.nodeOrParallelGroup;
172509
+ const links = stmt.children?.link;
172510
+ if (!groups || groups.length === 0)
172511
+ return;
172512
+ const sourceNodes = this.processNodeGroup(groups[0]);
172513
+ if (groups.length > 1 && links && links.length > 0) {
172514
+ const targetNodes = this.processNodeGroup(groups[1]);
172515
+ const linkInfo = this.extractLinkInfo(links[0]);
172516
+ for (const source of sourceNodes) {
172517
+ for (const target of targetNodes) {
172518
+ this.edges.push({
172519
+ id: `e${this.edgeCounter++}`,
172520
+ source,
172521
+ target,
172522
+ label: linkInfo.label,
172523
+ type: linkInfo.type,
172524
+ markerStart: linkInfo.markerStart,
172525
+ markerEnd: linkInfo.markerEnd
172526
+ });
172527
+ }
172528
+ }
172529
+ for (let i3 = 2; i3 < groups.length; i3++) {
172530
+ const nextNodes = this.processNodeGroup(groups[i3]);
172531
+ const nextLink = links[i3 - 1] ? this.extractLinkInfo(links[i3 - 1]) : linkInfo;
172532
+ for (const source of targetNodes) {
172533
+ for (const target of nextNodes) {
172534
+ this.edges.push({
172535
+ id: `e${this.edgeCounter++}`,
172536
+ source,
172537
+ target,
172538
+ label: nextLink.label,
172539
+ type: nextLink.type,
172540
+ markerStart: nextLink.markerStart,
172541
+ markerEnd: nextLink.markerEnd
172542
+ });
172543
+ }
172544
+ }
172545
+ targetNodes.length = 0;
172546
+ targetNodes.push(...nextNodes);
172547
+ }
172548
+ }
172549
+ }
172550
+ processNodeGroup(group) {
172551
+ const nodes = group.children?.node;
172552
+ if (!nodes)
172553
+ return [];
172554
+ const nodeIds = [];
172555
+ for (const node of nodes) {
172556
+ const nodeInfo = this.extractNodeInfo(node);
172557
+ if (nodeInfo) {
172558
+ const isSubgraph = this.subgraphs.some((sg) => sg.id === nodeInfo.id);
172559
+ if (!isSubgraph) {
172560
+ if (!this.nodes.has(nodeInfo.id)) {
172561
+ nodeInfo.style = this.computeNodeStyle(nodeInfo.id);
172562
+ this.nodes.set(nodeInfo.id, nodeInfo);
172563
+ } else {
172564
+ const existing = this.nodes.get(nodeInfo.id);
172565
+ if (nodeInfo.shape !== "rectangle" || nodeInfo.label !== nodeInfo.id) {
172566
+ if (nodeInfo.label !== nodeInfo.id) {
172567
+ existing.label = nodeInfo.label;
172568
+ }
172569
+ if (nodeInfo.shape !== "rectangle") {
172570
+ existing.shape = nodeInfo.shape;
172571
+ }
172572
+ }
172573
+ const merged = this.computeNodeStyle(nodeInfo.id);
172574
+ if (Object.keys(merged).length) {
172575
+ existing.style = { ...existing.style || {}, ...merged };
172576
+ }
172577
+ }
172578
+ if (this.currentSubgraphStack.length) {
172579
+ for (const sgId of this.currentSubgraphStack) {
172580
+ const subgraph = this.subgraphs.find((s3) => s3.id === sgId);
172581
+ if (subgraph && !subgraph.nodes.includes(nodeInfo.id)) {
172582
+ subgraph.nodes.push(nodeInfo.id);
172583
+ }
172584
+ }
172585
+ }
172586
+ }
172587
+ nodeIds.push(nodeInfo.id);
172588
+ }
172589
+ }
172590
+ return nodeIds;
172591
+ }
172592
+ extractNodeInfo(node) {
172593
+ const children = node.children;
172594
+ if (!children)
172595
+ return null;
172596
+ let id;
172597
+ if (children.nodeId) {
172598
+ id = children.nodeId[0].image;
172599
+ if (children.nodeIdSuffix) {
172600
+ id += children.nodeIdSuffix[0].image;
172601
+ }
172602
+ } else if (children.nodeIdNum) {
172603
+ id = children.nodeIdNum[0].image;
172604
+ } else if (children.Identifier) {
172605
+ id = children.Identifier[0].image;
172606
+ } else {
172607
+ return null;
172608
+ }
172609
+ let shape = "rectangle";
172610
+ let label = id;
172611
+ const shapeNode = children.nodeShape?.[0];
172612
+ if (shapeNode?.children) {
172613
+ const result = this.extractShapeAndLabel(shapeNode);
172614
+ shape = result.shape;
172615
+ if (result.label)
172616
+ label = result.label;
172617
+ }
172618
+ const clsTok = children.nodeClass?.[0];
172619
+ if (clsTok) {
172620
+ const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
172621
+ set.add(clsTok.image);
172622
+ this.nodeClasses.set(id, set);
172623
+ }
172624
+ return { id, label, shape };
172625
+ }
172626
+ extractShapeAndLabel(shapeNode) {
172627
+ const children = shapeNode.children;
172628
+ let shape = "rectangle";
172629
+ let label = "";
172630
+ const contentNodes = children?.nodeContent;
172631
+ if (contentNodes && contentNodes.length > 0) {
172632
+ label = this.extractTextContent(contentNodes[0]);
172633
+ }
172634
+ if (children?.SquareOpen) {
172635
+ shape = "rectangle";
172636
+ const contentNode = children.nodeContent?.[0];
172637
+ if (contentNode) {
172638
+ const c3 = contentNode.children;
172639
+ const tokTypes = ["ForwardSlash", "Backslash", "Identifier", "Text", "NumberLiteral", "RoundOpen", "RoundClose", "AngleLess", "AngleOpen", "Comma", "Colon", "Ampersand", "Semicolon", "TwoDashes", "Line", "ThickLine", "DottedLine"];
172640
+ const toks = [];
172641
+ for (const tt of tokTypes) {
172642
+ const arr = c3[tt];
172643
+ arr?.forEach((t3) => toks.push({ type: tt, t: t3, start: t3.startOffset ?? 0 }));
172644
+ }
172645
+ if (toks.length >= 2) {
172646
+ toks.sort((a3, b3) => a3.start - b3.start);
172647
+ const first2 = toks[0].type;
172648
+ const last2 = toks[toks.length - 1].type;
172649
+ if (first2 === "ForwardSlash" && last2 === "ForwardSlash" || first2 === "Backslash" && last2 === "Backslash") {
172650
+ shape = "parallelogram";
172651
+ } else if (first2 === "ForwardSlash" && last2 === "Backslash") {
172652
+ shape = "trapezoid";
172653
+ } else if (first2 === "Backslash" && last2 === "ForwardSlash") {
172654
+ shape = "trapezoidAlt";
172655
+ }
172656
+ }
172657
+ }
172658
+ } else if (children?.RoundOpen) {
172659
+ shape = "round";
172660
+ } else if (children?.DiamondOpen) {
172661
+ shape = "diamond";
172662
+ } else if (children?.DoubleRoundOpen) {
172663
+ shape = "circle";
172664
+ } else if (children?.StadiumOpen) {
172665
+ shape = "stadium";
172666
+ } else if (children?.HexagonOpen) {
172667
+ shape = "hexagon";
172668
+ } else if (children?.DoubleSquareOpen) {
172669
+ shape = "subroutine";
172670
+ } else if (children?.CylinderOpen) {
172671
+ shape = "cylinder";
172672
+ } else if (children?.TrapezoidOpen) {
172673
+ shape = "trapezoid";
172674
+ } else if (children?.ParallelogramOpen) {
172675
+ shape = "parallelogram";
172676
+ }
172677
+ return { shape, label };
172678
+ }
172679
+ extractTextContent(contentNode) {
172680
+ const children = contentNode.children;
172681
+ if (!children)
172682
+ return "";
172683
+ const tokenTypes = [
172684
+ "Text",
172685
+ "Identifier",
172686
+ "QuotedString",
172687
+ "NumberLiteral",
172688
+ "Ampersand",
172689
+ "Comma",
172690
+ "Colon",
172691
+ "Semicolon",
172692
+ "Dot",
172693
+ "Underscore",
172694
+ "Dash",
172695
+ "ForwardSlash",
172696
+ "Backslash",
172697
+ "AngleLess",
172698
+ "AngleOpen"
172699
+ ];
172700
+ const tokenWithPositions = [];
172701
+ for (const type of tokenTypes) {
172702
+ const tokens = children[type];
172703
+ if (tokens) {
172704
+ for (const token of tokens) {
172705
+ let text = token.image;
172706
+ if (type === "QuotedString" && text.startsWith('"') && text.endsWith('"')) {
172707
+ text = text.slice(1, -1);
172708
+ }
172709
+ if ((type === "ForwardSlash" || type === "Backslash") && tokenWithPositions.length === 0) {
172710
+ continue;
172711
+ }
172712
+ tokenWithPositions.push({
172713
+ text,
172714
+ startOffset: token.startOffset ?? 0,
172715
+ type
172716
+ });
172717
+ }
172718
+ }
172719
+ }
172720
+ tokenWithPositions.sort((a3, b3) => a3.startOffset - b3.startOffset);
172721
+ if (tokenWithPositions.length) {
172722
+ const first2 = tokenWithPositions[0];
172723
+ if (first2.type === "ForwardSlash" || first2.type === "Backslash") {
172724
+ tokenWithPositions.shift();
172725
+ }
172726
+ const last2 = tokenWithPositions[tokenWithPositions.length - 1];
172727
+ if (last2.type === "ForwardSlash" || last2.type === "Backslash") {
172728
+ tokenWithPositions.pop();
172729
+ }
172730
+ }
172731
+ const parts = tokenWithPositions.map((t3) => t3.text);
172732
+ if (children.Space) {
172733
+ return parts.join("");
172734
+ }
172735
+ return parts.join(" ").trim();
172736
+ }
172737
+ extractLinkInfo(link) {
172738
+ const children = link.children;
172739
+ let type = "arrow";
172740
+ let label;
172741
+ let markerStart = "none";
172742
+ let markerEnd = "none";
172743
+ if (children.BiDirectionalArrow) {
172744
+ type = "arrow";
172745
+ markerStart = "arrow";
172746
+ markerEnd = "arrow";
172747
+ } else if (children.CircleEndLine) {
172748
+ type = "open";
172749
+ markerStart = "circle";
172750
+ markerEnd = "circle";
172751
+ } else if (children.CrossEndLine) {
172752
+ type = "open";
172753
+ markerStart = "cross";
172754
+ markerEnd = "cross";
172755
+ } else if (children?.ArrowRight) {
172756
+ type = "arrow";
172757
+ markerEnd = "arrow";
172758
+ } else if (children?.ArrowLeft) {
172759
+ type = "arrow";
172760
+ markerStart = "arrow";
172761
+ } else if (children?.DottedArrowRight) {
172762
+ type = "dotted";
172763
+ markerEnd = "arrow";
172764
+ } else if (children?.DottedArrowLeft) {
172765
+ type = "dotted";
172766
+ markerStart = "arrow";
172767
+ } else if (children?.ThickArrowRight) {
172768
+ type = "thick";
172769
+ markerEnd = "arrow";
172770
+ } else if (children?.ThickArrowLeft) {
172771
+ type = "thick";
172772
+ markerStart = "arrow";
172773
+ } else if (children?.LinkRight || children?.LinkLeft || children?.Line || children?.TwoDashes || children?.DottedLine || children?.ThickLine) {
172774
+ if (children?.DottedLine)
172775
+ type = "dotted";
172776
+ else if (children?.ThickLine)
172777
+ type = "thick";
172778
+ else
172779
+ type = "open";
172780
+ } else if (children?.InvisibleLink) {
172781
+ type = "invisible";
172782
+ }
172783
+ if (markerEnd === "none" && (children?.ArrowRight || children.ThickArrowRight || children.DottedArrowRight)) {
172784
+ markerEnd = "arrow";
172785
+ }
172786
+ if (markerStart === "none" && (children?.ArrowLeft || children.ThickArrowLeft || children.DottedArrowLeft)) {
172787
+ markerStart = "arrow";
172788
+ }
172789
+ const textNode = children?.linkText?.[0];
172790
+ if (textNode) {
172791
+ label = this.extractTextContent(textNode);
172792
+ } else if (children.linkTextInline?.[0]) {
172793
+ label = this.extractTextContent(children.linkTextInline[0]);
172794
+ } else if (children.inlineCarrier?.[0]) {
172795
+ const token = children.inlineCarrier[0];
172796
+ const raw = token.image.trim();
172797
+ if (raw.startsWith("-.") && raw.endsWith(".-")) {
172798
+ type = "dotted";
172799
+ } else if (raw.startsWith("==") && raw.endsWith("==")) {
172800
+ type = "thick";
172801
+ } else if (raw.startsWith("--") && raw.endsWith("--")) {
172802
+ }
172803
+ if (children.ArrowRight || children.DottedArrowRight || children.ThickArrowRight) {
172804
+ markerEnd = "arrow";
172805
+ }
172806
+ if (children.ArrowLeft || children.DottedArrowLeft || children.ThickArrowLeft) {
172807
+ markerStart = "arrow";
172808
+ }
172809
+ const strip = (str) => {
172810
+ if (str.startsWith("-.") && str.endsWith(".-") || str.startsWith("==") && str.endsWith("==") || str.startsWith("--") && str.endsWith("--")) {
172811
+ return str.slice(2, -2).trim();
172812
+ }
172813
+ return str;
172814
+ };
172815
+ label = strip(raw);
172816
+ }
172817
+ return { type, label, markerStart, markerEnd };
172818
+ }
172819
+ processSubgraph(subgraph) {
172820
+ const children = subgraph.children;
172821
+ let id = `subgraph_${this.subgraphs.length}`;
172822
+ let label;
172823
+ const idToken = children?.subgraphId?.[0] || children?.Identifier?.[0];
172824
+ if (idToken) {
172825
+ id = idToken.image;
172826
+ }
172827
+ if (children?.SquareOpen && children?.nodeContent) {
172828
+ label = this.extractTextContent(children.nodeContent[0]);
172829
+ } else if (children.subgraphTitleQ?.[0]) {
172830
+ const qt = children.subgraphTitleQ[0];
172831
+ const img = qt.image;
172832
+ label = img && img.length >= 2 && (img.startsWith('"') || img.startsWith("'")) ? img.slice(1, -1) : img;
172833
+ } else if (children?.subgraphLabel) {
172834
+ label = this.extractTextContent(children.subgraphLabel[0]);
172835
+ }
172836
+ if (!label && id !== `subgraph_${this.subgraphs.length}`) {
172837
+ label = id;
172838
+ }
172839
+ const parent = this.currentSubgraphStack.length ? this.currentSubgraphStack[this.currentSubgraphStack.length - 1] : void 0;
172840
+ const sg = { id, label, nodes: [], parent };
172841
+ this.subgraphs.push(sg);
172842
+ this.currentSubgraphStack.push(id);
172843
+ const statements = children?.subgraphStatement;
172844
+ if (statements) {
172845
+ for (const stmt of statements) {
172846
+ if (stmt.children?.nodeStatement) {
172847
+ this.processNodeStatement(stmt.children.nodeStatement[0]);
172848
+ } else if (stmt.children?.subgraph) {
172849
+ this.processSubgraph(stmt.children.subgraph[0]);
172850
+ }
172851
+ }
172852
+ }
172853
+ this.currentSubgraphStack.pop();
172854
+ }
172855
+ // ---- Styling helpers ----
172856
+ processClassDef(cst) {
172857
+ const idTok = cst.children?.Identifier?.[0];
172858
+ if (!idTok)
172859
+ return;
172860
+ const className = idTok.image;
172861
+ const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
172862
+ if (Object.keys(props).length) {
172863
+ this.classStyles.set(className, props);
172864
+ for (const [nodeId, classes] of this.nodeClasses.entries()) {
172865
+ if (classes.has(className)) {
172866
+ const node = this.nodes.get(nodeId);
172867
+ if (node) {
172868
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
172869
+ }
172870
+ }
172871
+ }
172872
+ }
172873
+ }
172874
+ processClassAssign(cst) {
172875
+ const ids = cst.children?.Identifier || [];
172876
+ if (!ids.length)
172877
+ return;
172878
+ const classNameTok = cst.children.className?.[0];
172879
+ const className = classNameTok?.image || ids[ids.length - 1].image;
172880
+ const nodeIds = classNameTok ? ids.slice(0, -1) : ids.slice(0, -1);
172881
+ for (const tok of nodeIds) {
172882
+ const id = tok.image;
172883
+ const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
172884
+ set.add(className);
172885
+ this.nodeClasses.set(id, set);
172886
+ const node = this.nodes.get(id);
172887
+ if (node) {
172888
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(id) };
172889
+ }
172890
+ }
172891
+ }
172892
+ processStyle(cst) {
172893
+ const idTok = cst.children?.Identifier?.[0];
172894
+ if (!idTok)
172895
+ return;
172896
+ const nodeId = idTok.image;
172897
+ const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
172898
+ if (Object.keys(props).length) {
172899
+ this.nodeStyles.set(nodeId, props);
172900
+ const node = this.nodes.get(nodeId);
172901
+ if (node) {
172902
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
172903
+ }
172904
+ }
172905
+ }
172906
+ collectStyleProps(cst, opts = {}) {
172907
+ const tokens = [];
172908
+ const ch = cst.children || {};
172909
+ const push = (arr, type = "t") => arr?.forEach((t3) => tokens.push({ text: t3.image, startOffset: t3.startOffset ?? 0, type }));
172910
+ push(ch.Text, "Text");
172911
+ push(ch.Identifier, "Identifier");
172912
+ push(ch.ColorValue, "Color");
172913
+ push(ch.Colon, "Colon");
172914
+ push(ch.Comma, "Comma");
172915
+ push(ch.NumberLiteral, "Number");
172916
+ tokens.sort((a3, b3) => a3.startOffset - b3.startOffset);
172917
+ if (opts.skipFirstIdentifier) {
172918
+ const idx = tokens.findIndex((t3) => t3.type === "Identifier");
172919
+ if (idx >= 0)
172920
+ tokens.splice(idx, 1);
172921
+ }
172922
+ const joined = tokens.map((t3) => t3.text).join("");
172923
+ const props = {};
172924
+ for (const seg of joined.split(",").map((s3) => s3.trim()).filter(Boolean)) {
172925
+ const [k3, v3] = seg.split(":");
172926
+ if (k3 && v3)
172927
+ props[k3.trim()] = v3.trim();
172928
+ }
172929
+ return props;
172930
+ }
172931
+ computeNodeStyle(nodeId) {
172932
+ const out = {};
172933
+ const classes = this.nodeClasses.get(nodeId);
172934
+ if (classes) {
172935
+ for (const c3 of classes) {
172936
+ const s3 = this.classStyles.get(c3);
172937
+ if (s3)
172938
+ Object.assign(out, this.normalizeStyle(s3));
172939
+ }
172940
+ }
172941
+ const direct = this.nodeStyles.get(nodeId);
172942
+ if (direct)
172943
+ Object.assign(out, this.normalizeStyle(direct));
172944
+ return out;
172945
+ }
172946
+ normalizeStyle(s3) {
172947
+ const out = {};
172948
+ for (const [kRaw, vRaw] of Object.entries(s3)) {
172949
+ const k3 = kRaw.trim().toLowerCase();
172950
+ const v3 = vRaw.trim();
172951
+ if (k3 === "stroke-width") {
172952
+ const num = parseFloat(v3);
172953
+ if (!Number.isNaN(num))
172954
+ out.strokeWidth = num;
172955
+ } else if (k3 === "stroke") {
172956
+ out.stroke = v3;
172957
+ } else if (k3 === "fill") {
172958
+ out.fill = v3;
172959
+ }
172960
+ }
172961
+ return out;
172962
+ }
172963
+ };
172288
172964
  }
172289
172965
  });
172290
172966
 
@@ -179967,16 +180643,2435 @@ var require_dagre = __commonJS({
179967
180643
  });
179968
180644
 
179969
180645
  // node_modules/@probelabs/maid/out/renderer/layout.js
179970
- var import_dagre;
180646
+ var import_dagre, DagreLayoutEngine;
179971
180647
  var init_layout = __esm({
179972
180648
  "node_modules/@probelabs/maid/out/renderer/layout.js"() {
179973
180649
  import_dagre = __toESM(require_dagre(), 1);
180650
+ DagreLayoutEngine = class {
180651
+ constructor() {
180652
+ this.nodeWidth = 120;
180653
+ this.nodeHeight = 50;
180654
+ this.rankSep = 50;
180655
+ this.nodeSep = 50;
180656
+ this.edgeSep = 10;
180657
+ }
180658
+ layout(graph) {
180659
+ const g3 = new import_dagre.default.graphlib.Graph();
180660
+ const hasClusters = !!(graph.subgraphs && graph.subgraphs.length > 0);
180661
+ const dir = this.mapDirection(graph.direction);
180662
+ let ranksep = this.rankSep;
180663
+ let nodesep = this.nodeSep;
180664
+ if (hasClusters) {
180665
+ if (dir === "LR" || dir === "RL") {
180666
+ ranksep += 20;
180667
+ nodesep += 70;
180668
+ } else {
180669
+ ranksep += 70;
180670
+ nodesep += 20;
180671
+ }
180672
+ }
180673
+ const graphConfig = {
180674
+ rankdir: dir,
180675
+ ranksep,
180676
+ nodesep,
180677
+ edgesep: this.edgeSep,
180678
+ marginx: 20,
180679
+ marginy: 20
180680
+ };
180681
+ if (hasClusters && (dir === "LR" || dir === "RL")) {
180682
+ graphConfig.ranker = "longest-path";
180683
+ graphConfig.acyclicer = "greedy";
180684
+ }
180685
+ if (hasClusters) {
180686
+ graphConfig.compound = true;
180687
+ }
180688
+ g3.setGraph(graphConfig);
180689
+ g3.setDefaultEdgeLabel(() => ({}));
180690
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
180691
+ for (const subgraph of graph.subgraphs) {
180692
+ g3.setNode(subgraph.id, { label: subgraph.label || subgraph.id, clusterLabelPos: "top" });
180693
+ }
180694
+ }
180695
+ for (const node of graph.nodes) {
180696
+ const dimensions = this.calculateNodeDimensions(node.label, node.shape);
180697
+ g3.setNode(node.id, {
180698
+ width: dimensions.width,
180699
+ height: dimensions.height,
180700
+ label: node.label,
180701
+ shape: node.shape
180702
+ });
180703
+ }
180704
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
180705
+ for (const subgraph of graph.subgraphs) {
180706
+ for (const nodeId of subgraph.nodes) {
180707
+ if (g3.hasNode(nodeId)) {
180708
+ try {
180709
+ g3.setParent(nodeId, subgraph.id);
180710
+ } catch {
180711
+ }
180712
+ }
180713
+ }
180714
+ if (subgraph.parent && g3.hasNode(subgraph.parent)) {
180715
+ try {
180716
+ g3.setParent(subgraph.id, subgraph.parent);
180717
+ } catch {
180718
+ }
180719
+ }
180720
+ }
180721
+ }
180722
+ for (const edge of graph.edges) {
180723
+ g3.setEdge(edge.source, edge.target, {
180724
+ label: edge.label,
180725
+ width: edge.label ? edge.label.length * 8 : 0,
180726
+ height: edge.label ? 20 : 0
180727
+ });
180728
+ }
180729
+ import_dagre.default.layout(g3);
180730
+ const graphInfo = g3.graph();
180731
+ const layoutNodes = [];
180732
+ const layoutEdges = [];
180733
+ for (const node of graph.nodes) {
180734
+ const nodeLayout = g3.node(node.id);
180735
+ if (nodeLayout) {
180736
+ layoutNodes.push({
180737
+ ...node,
180738
+ x: nodeLayout.x - nodeLayout.width / 2,
180739
+ y: nodeLayout.y - nodeLayout.height / 2,
180740
+ width: nodeLayout.width,
180741
+ height: nodeLayout.height
180742
+ });
180743
+ }
180744
+ }
180745
+ const layoutSubgraphs = [];
180746
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
180747
+ for (const sg of graph.subgraphs) {
180748
+ const members = layoutNodes.filter((nd) => sg.nodes.includes(nd.id));
180749
+ if (members.length) {
180750
+ const minX = Math.min(...members.map((m3) => m3.x));
180751
+ const minY = Math.min(...members.map((m3) => m3.y));
180752
+ const maxX = Math.max(...members.map((m3) => m3.x + m3.width));
180753
+ const maxY = Math.max(...members.map((m3) => m3.y + m3.height));
180754
+ const pad = 30;
180755
+ layoutSubgraphs.push({
180756
+ id: sg.id,
180757
+ label: sg.label || sg.id,
180758
+ x: minX - pad,
180759
+ y: minY - pad - 18,
180760
+ // space for title
180761
+ width: maxX - minX + pad * 2,
180762
+ height: maxY - minY + pad * 2 + 18,
180763
+ parent: sg.parent
180764
+ });
180765
+ }
180766
+ }
180767
+ const byId = Object.fromEntries(layoutSubgraphs.map((s3) => [s3.id, s3]));
180768
+ for (const sg of layoutSubgraphs) {
180769
+ if (!sg.parent)
180770
+ continue;
180771
+ const p3 = byId[sg.parent];
180772
+ if (!p3)
180773
+ continue;
180774
+ const minX = Math.min(p3.x, sg.x);
180775
+ const minY = Math.min(p3.y, sg.y);
180776
+ const maxX = Math.max(p3.x + p3.width, sg.x + sg.width);
180777
+ const maxY = Math.max(p3.y + p3.height, sg.y + sg.height);
180778
+ p3.x = minX;
180779
+ p3.y = minY;
180780
+ p3.width = maxX - minX;
180781
+ p3.height = maxY - minY;
180782
+ }
180783
+ }
180784
+ const subgraphById = Object.fromEntries(layoutSubgraphs.map((sg) => [sg.id, sg]));
180785
+ for (const edge of graph.edges) {
180786
+ const edgeLayout = g3.edge(edge.source, edge.target);
180787
+ let pts = edgeLayout && Array.isArray(edgeLayout.points) ? edgeLayout.points.slice() : [];
180788
+ const hasNaN = pts.some((p3) => !Number.isFinite(p3.x) || !Number.isFinite(p3.y));
180789
+ const srcSg = subgraphById[edge.source];
180790
+ const dstSg = subgraphById[edge.target];
180791
+ let synthesized = false;
180792
+ if (!pts.length || hasNaN || srcSg || dstSg) {
180793
+ const rankdir = this.mapDirection(graph.direction);
180794
+ const getNode = (id) => {
180795
+ const n3 = g3.node(id);
180796
+ if (!n3)
180797
+ return void 0;
180798
+ return {
180799
+ id,
180800
+ label: n3.label || id,
180801
+ shape: n3.shape || "rectangle",
180802
+ x: n3.x - n3.width / 2,
180803
+ y: n3.y - n3.height / 2,
180804
+ width: n3.width,
180805
+ height: n3.height,
180806
+ style: {}
180807
+ };
180808
+ };
180809
+ const start = srcSg ? this.clusterAnchor(srcSg, rankdir, "out") : this.nodeAnchor(getNode(edge.source), rankdir, "out");
180810
+ const end = dstSg ? this.clusterAnchor(dstSg, rankdir, "in") : this.nodeAnchor(getNode(edge.target), rankdir, "in");
180811
+ if (start && end) {
180812
+ const PAD = 20;
180813
+ const horizontallyAdjacent = srcSg && dstSg && Math.abs(srcSg.x - dstSg.x) > Math.abs(srcSg.y - dstSg.y);
180814
+ const horizontalSubgraphs = horizontallyAdjacent;
180815
+ if (rankdir === "LR" || rankdir === "RL") {
180816
+ const outX = start.x + (rankdir === "LR" ? PAD : -PAD);
180817
+ const inX = end.x + (rankdir === "LR" ? -PAD : PAD);
180818
+ const startOut = { x: srcSg ? outX : start.x, y: start.y };
180819
+ const endPre = { x: dstSg ? inX : end.x, y: end.y };
180820
+ const alpha = 0.68;
180821
+ const midX = startOut.x + (endPre.x - startOut.x) * alpha;
180822
+ const m1 = { x: midX, y: startOut.y };
180823
+ const m22 = { x: midX, y: endPre.y };
180824
+ pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
180825
+ } else {
180826
+ if (horizontalSubgraphs && srcSg && dstSg) {
180827
+ const midY = (srcSg.y + srcSg.height / 2 + dstSg.y + dstSg.height / 2) / 2;
180828
+ if (srcSg.x < dstSg.x) {
180829
+ const startX = srcSg.x + srcSg.width;
180830
+ const endX = dstSg.x;
180831
+ pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
180832
+ } else {
180833
+ const startX = srcSg.x;
180834
+ const endX = dstSg.x + dstSg.width;
180835
+ pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
180836
+ }
180837
+ } else {
180838
+ const outY = start.y + (rankdir === "TD" ? PAD : -PAD);
180839
+ const inY = end.y + (rankdir === "TD" ? -PAD : PAD);
180840
+ const startOut = { x: start.x, y: srcSg ? outY : start.y };
180841
+ const endPre = { x: end.x, y: dstSg ? inY : end.y };
180842
+ const alpha = 0.68;
180843
+ const midY = startOut.y + (endPre.y - startOut.y) * alpha;
180844
+ const m1 = { x: startOut.x, y: midY };
180845
+ const m22 = { x: endPre.x, y: midY };
180846
+ pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
180847
+ }
180848
+ }
180849
+ synthesized = true;
180850
+ }
180851
+ }
180852
+ if (pts.length) {
180853
+ layoutEdges.push({ ...edge, points: pts, pathMode: synthesized ? "orthogonal" : "smooth" });
180854
+ }
180855
+ }
180856
+ const rawW = graphInfo.width;
180857
+ const rawH = graphInfo.height;
180858
+ const w3 = Number.isFinite(rawW) && rawW > 0 ? rawW : 800;
180859
+ const h3 = Number.isFinite(rawH) && rawH > 0 ? rawH : 600;
180860
+ return {
180861
+ nodes: layoutNodes,
180862
+ edges: layoutEdges,
180863
+ width: w3,
180864
+ height: h3,
180865
+ subgraphs: layoutSubgraphs
180866
+ };
180867
+ }
180868
+ mapDirection(direction) {
180869
+ switch (direction) {
180870
+ case "TB":
180871
+ case "TD":
180872
+ return "TB";
180873
+ case "BT":
180874
+ return "BT";
180875
+ case "LR":
180876
+ return "LR";
180877
+ case "RL":
180878
+ return "RL";
180879
+ default:
180880
+ return "TB";
180881
+ }
180882
+ }
180883
+ calculateNodeDimensions(label, shape) {
180884
+ const charWidth = 7;
180885
+ const padding = 20;
180886
+ const minWidth = 80;
180887
+ const minHeight = 40;
180888
+ const maxWidth = 240;
180889
+ const lineHeight = 18;
180890
+ const explicitLines = label.split(/<\s*br\s*\/?\s*>/i);
180891
+ const hasExplicitBreaks = explicitLines.length > 1;
180892
+ let width;
180893
+ let lines;
180894
+ if (hasExplicitBreaks) {
180895
+ const maxLineLength = Math.max(...explicitLines.map((line) => line.length));
180896
+ width = Math.min(Math.max(maxLineLength * charWidth + padding * 2, minWidth), maxWidth);
180897
+ lines = explicitLines.length;
180898
+ } else {
180899
+ width = Math.min(Math.max(label.length * charWidth + padding * 2, minWidth), maxWidth);
180900
+ const charsPerLine = Math.max(1, Math.floor((width - padding * 2) / charWidth));
180901
+ lines = Math.ceil(label.length / charsPerLine);
180902
+ }
180903
+ let height = Math.max(lines * lineHeight + padding, minHeight);
180904
+ switch (shape) {
180905
+ case "circle":
180906
+ const size = Math.max(width, height);
180907
+ width = size;
180908
+ height = size;
180909
+ break;
180910
+ case "diamond": {
180911
+ const size2 = Math.max(width, height) * 1.2;
180912
+ width = size2;
180913
+ height = size2;
180914
+ break;
180915
+ }
180916
+ case "hexagon":
180917
+ width *= 1.3;
180918
+ height *= 1.2;
180919
+ break;
180920
+ case "stadium":
180921
+ width *= 1.2;
180922
+ break;
180923
+ case "cylinder":
180924
+ height *= 1.5;
180925
+ break;
180926
+ case "subroutine":
180927
+ case "double":
180928
+ width += 10;
180929
+ height += 10;
180930
+ break;
180931
+ case "parallelogram":
180932
+ case "trapezoid":
180933
+ width *= 1.3;
180934
+ break;
180935
+ }
180936
+ return { width: Math.round(width), height: Math.round(height) };
180937
+ }
180938
+ clusterAnchor(sg, rankdir, mode) {
180939
+ switch (rankdir) {
180940
+ case "LR":
180941
+ return { x: mode === "out" ? sg.x + sg.width : sg.x, y: sg.y + sg.height / 2 };
180942
+ case "RL":
180943
+ return { x: mode === "out" ? sg.x : sg.x + sg.width, y: sg.y + sg.height / 2 };
180944
+ case "BT":
180945
+ return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y : sg.y + sg.height };
180946
+ case "TB":
180947
+ default:
180948
+ return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y + sg.height : sg.y };
180949
+ }
180950
+ }
180951
+ nodeAnchor(n3, rankdir, mode) {
180952
+ if (!n3)
180953
+ return { x: 0, y: 0 };
180954
+ switch (rankdir) {
180955
+ case "LR":
180956
+ return { x: mode === "in" ? n3.x : n3.x + n3.width, y: n3.y + n3.height / 2 };
180957
+ case "RL":
180958
+ return { x: mode === "in" ? n3.x + n3.width : n3.x, y: n3.y + n3.height / 2 };
180959
+ case "BT":
180960
+ return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y + n3.height : n3.y };
180961
+ case "TB":
180962
+ default:
180963
+ return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y : n3.y + n3.height };
180964
+ }
180965
+ }
180966
+ };
180967
+ }
180968
+ });
180969
+
180970
+ // node_modules/@probelabs/maid/out/renderer/arrow-utils.js
180971
+ function triangleAtEnd(start, end, color = "#333", length = 8, width = 6) {
180972
+ const vx = end.x - start.x;
180973
+ const vy = end.y - start.y;
180974
+ const len = Math.hypot(vx, vy) || 1;
180975
+ const ux = vx / len;
180976
+ const uy = vy / len;
180977
+ const nx = -uy;
180978
+ const ny = ux;
180979
+ const baseX = end.x - ux * length;
180980
+ const baseY = end.y - uy * length;
180981
+ const p2x = baseX + nx * (width / 2), p2y = baseY + ny * (width / 2);
180982
+ const p3x = baseX - nx * (width / 2), p3y = baseY - ny * (width / 2);
180983
+ return `<path d="M${end.x},${end.y} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
180984
+ }
180985
+ function triangleAtStart(first2, second, color = "#333", length = 8, width = 6) {
180986
+ const vx = second.x - first2.x;
180987
+ const vy = second.y - first2.y;
180988
+ const len = Math.hypot(vx, vy) || 1;
180989
+ const ux = vx / len;
180990
+ const uy = vy / len;
180991
+ const nx = -uy;
180992
+ const ny = ux;
180993
+ const tipX = first2.x - ux * length;
180994
+ const tipY = first2.y - uy * length;
180995
+ const p2x = first2.x + nx * (width / 2), p2y = first2.y + ny * (width / 2);
180996
+ const p3x = first2.x - nx * (width / 2), p3y = first2.y - ny * (width / 2);
180997
+ return `<path d="M${tipX},${tipY} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
180998
+ }
180999
+ var init_arrow_utils = __esm({
181000
+ "node_modules/@probelabs/maid/out/renderer/arrow-utils.js"() {
181001
+ }
181002
+ });
181003
+
181004
+ // node_modules/@probelabs/maid/out/renderer/styles.js
181005
+ function buildSharedCss(opts = {}) {
181006
+ const fontFamily = opts.fontFamily || "Arial, sans-serif";
181007
+ const fontSize = opts.fontSize ?? 14;
181008
+ const nodeFill = opts.nodeFill || "#eef0ff";
181009
+ const nodeStroke = opts.nodeStroke || "#3f3f3f";
181010
+ const edgeStroke = opts.edgeStroke || "#555555";
181011
+ return `
181012
+ .node-shape { fill: ${nodeFill}; stroke: ${nodeStroke}; stroke-width: 1px; }
181013
+ .node-label { fill: #333; font-family: ${fontFamily}; font-size: ${fontSize}px; }
181014
+ .edge-path { stroke: ${edgeStroke}; stroke-width: 2px; fill: none; }
181015
+ .edge-label-bg { fill: rgba(232,232,232, 0.8); opacity: 0.5; }
181016
+ .edge-label-text { fill: #333; font-family: ${fontFamily}; font-size: ${Math.max(10, fontSize - 2)}px; }
181017
+
181018
+ /* Cluster (flowchart + sequence blocks) */
181019
+ .cluster-bg { fill: #ffffde; }
181020
+ .cluster-border { fill: none; stroke: #aaaa33; stroke-width: 1px; }
181021
+ .cluster-title-bg { fill: rgba(255,255,255,0.8); }
181022
+ .cluster-label-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
181023
+
181024
+ /* Notes */
181025
+ .note { fill: #fff5ad; stroke: #aaaa33; stroke-width: 1px; }
181026
+ .note-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
181027
+
181028
+ /* Sequence-specific add-ons (safe for flowcharts too) */
181029
+ .actor-rect { fill: #eaeaea; stroke: #666; stroke-width: 1.5px; }
181030
+ .actor-label { fill: #111; font-family: ${fontFamily}; font-size: 16px; }
181031
+ .lifeline { stroke: #999; stroke-width: 0.5px; }
181032
+ .activation { fill: #f4f4f4; stroke: #666; stroke-width: 1px; }
181033
+ .msg-line { stroke: #333; stroke-width: 1.5px; fill: none; }
181034
+ .msg-line.dotted { stroke-dasharray: 2 2; }
181035
+ .msg-line.thick { stroke-width: 3px; }
181036
+ .msg-label { fill: #333; font-family: ${fontFamily}; font-size: 12px; dominant-baseline: middle; }
181037
+ .msg-label-bg { fill: #ffffff; stroke: #cccccc; stroke-width: 1px; rx: 3; }
181038
+ `;
181039
+ }
181040
+ var init_styles = __esm({
181041
+ "node_modules/@probelabs/maid/out/renderer/styles.js"() {
181042
+ }
181043
+ });
181044
+
181045
+ // node_modules/@probelabs/maid/out/renderer/utils.js
181046
+ function escapeXml(text) {
181047
+ return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&apos;");
181048
+ }
181049
+ function measureText(text, fontSize = 12) {
181050
+ const avg = 0.6 * fontSize;
181051
+ return Math.max(0, Math.round(text.length * avg));
181052
+ }
181053
+ function palette(index) {
181054
+ if (index < DEFAULT_PALETTE.length)
181055
+ return DEFAULT_PALETTE[index];
181056
+ const i3 = index - DEFAULT_PALETTE.length;
181057
+ const hue = i3 * 47 % 360;
181058
+ return `hsl(${hue} 60% 55%)`;
181059
+ }
181060
+ function formatNumber(n3) {
181061
+ if (Number.isInteger(n3))
181062
+ return String(n3);
181063
+ return (Math.round(n3 * 100) / 100).toString();
181064
+ }
181065
+ function formatPercent(value, total) {
181066
+ if (!(total > 0))
181067
+ return "0%";
181068
+ const p3 = value / total * 100;
181069
+ return `${Math.round(p3)}%`;
181070
+ }
181071
+ var DEFAULT_PALETTE;
181072
+ var init_utils4 = __esm({
181073
+ "node_modules/@probelabs/maid/out/renderer/utils.js"() {
181074
+ DEFAULT_PALETTE = [
181075
+ "#ECECFF",
181076
+ "#ffffde",
181077
+ "hsl(80, 100%, 56.2745098039%)",
181078
+ "hsl(240, 100%, 86.2745098039%)",
181079
+ "hsl(60, 100%, 63.5294117647%)",
181080
+ "hsl(80, 100%, 76.2745098039%)",
181081
+ "hsl(300, 100%, 76.2745098039%)",
181082
+ "hsl(180, 100%, 56.2745098039%)",
181083
+ "hsl(0, 100%, 56.2745098039%)",
181084
+ "hsl(300, 100%, 56.2745098039%)",
181085
+ "hsl(150, 100%, 56.2745098039%)",
181086
+ "hsl(0, 100%, 66.2745098039%)"
181087
+ ];
181088
+ }
181089
+ });
181090
+
181091
+ // node_modules/@probelabs/maid/out/renderer/block-utils.js
181092
+ function blockBackground(x3, y2, width, height, radius = 0) {
181093
+ return `<g class="cluster-bg-layer" transform="translate(${x3},${y2})">
181094
+ <rect class="cluster-bg" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>
181095
+ </g>`;
181096
+ }
181097
+ function blockOverlay(x3, y2, width, height, title, branchYs = [], titleYOffset = 0, align = "center", branchAlign = "left", radius = 0) {
181098
+ const parts = [];
181099
+ parts.push(`<g class="cluster-overlay" transform="translate(${x3},${y2})">`);
181100
+ parts.push(`<rect class="cluster-border" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>`);
181101
+ const titleText = title ? escapeXml(title) : "";
181102
+ if (titleText) {
181103
+ const titleW = Math.max(24, measureText(titleText, 12) + 10);
181104
+ const yBg = -2 + titleYOffset;
181105
+ const yText = 11 + titleYOffset;
181106
+ if (align === "left") {
181107
+ const xBg = 6;
181108
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
181109
+ parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yText}" text-anchor="start">${titleText}</text>`);
181110
+ } else {
181111
+ const xBg = 6;
181112
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
181113
+ parts.push(`<text class="cluster-label-text" x="${xBg + titleW / 2}" y="${yText}" text-anchor="middle">${titleText}</text>`);
181114
+ }
181115
+ }
181116
+ for (const br of branchYs) {
181117
+ const yRel = br.y - y2;
181118
+ parts.push(`<line x1="0" y1="${yRel}" x2="${width}" y2="${yRel}" class="cluster-border" />`);
181119
+ if (br.title) {
181120
+ const text = escapeXml(br.title);
181121
+ const bw = Math.max(24, measureText(text, 12) + 10);
181122
+ const xBg = 6;
181123
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yRel - 10}" width="${bw}" height="18" rx="3"/>`);
181124
+ if (branchAlign === "left") {
181125
+ parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yRel + 1}" text-anchor="start">${text}</text>`);
181126
+ } else {
181127
+ parts.push(`<text class="cluster-label-text" x="${xBg + bw / 2}" y="${yRel + 1}" text-anchor="middle">${text}</text>`);
181128
+ }
181129
+ }
181130
+ }
181131
+ parts.push("</g>");
181132
+ return parts.join("\n");
181133
+ }
181134
+ var init_block_utils = __esm({
181135
+ "node_modules/@probelabs/maid/out/renderer/block-utils.js"() {
181136
+ init_utils4();
179974
181137
  }
179975
181138
  });
179976
181139
 
179977
181140
  // node_modules/@probelabs/maid/out/renderer/svg-generator.js
181141
+ var SVGRenderer;
179978
181142
  var init_svg_generator = __esm({
179979
181143
  "node_modules/@probelabs/maid/out/renderer/svg-generator.js"() {
181144
+ init_arrow_utils();
181145
+ init_styles();
181146
+ init_block_utils();
181147
+ SVGRenderer = class {
181148
+ constructor() {
181149
+ this.padding = 20;
181150
+ this.fontSize = 14;
181151
+ this.fontFamily = "Arial, sans-serif";
181152
+ this.defaultStroke = "#3f3f3f";
181153
+ this.defaultFill = "#eef0ff";
181154
+ this.arrowStroke = "#555555";
181155
+ this.arrowMarkerSize = 9;
181156
+ }
181157
+ render(layout) {
181158
+ let minX = Infinity;
181159
+ let minY = Infinity;
181160
+ let maxX = -Infinity;
181161
+ let maxY = -Infinity;
181162
+ for (const n3 of layout.nodes) {
181163
+ minX = Math.min(minX, n3.x);
181164
+ minY = Math.min(minY, n3.y);
181165
+ maxX = Math.max(maxX, n3.x + n3.width);
181166
+ maxY = Math.max(maxY, n3.y + n3.height);
181167
+ }
181168
+ if (layout.subgraphs) {
181169
+ for (const sg of layout.subgraphs) {
181170
+ minX = Math.min(minX, sg.x);
181171
+ minY = Math.min(minY, sg.y);
181172
+ maxX = Math.max(maxX, sg.x + sg.width);
181173
+ maxY = Math.max(maxY, sg.y + sg.height);
181174
+ }
181175
+ }
181176
+ for (const e3 of layout.edges) {
181177
+ if (e3.points)
181178
+ for (const p3 of e3.points) {
181179
+ minX = Math.min(minX, p3.x);
181180
+ minY = Math.min(minY, p3.y);
181181
+ maxX = Math.max(maxX, p3.x);
181182
+ maxY = Math.max(maxY, p3.y);
181183
+ }
181184
+ }
181185
+ if (!isFinite(minX)) {
181186
+ minX = 0;
181187
+ }
181188
+ if (!isFinite(minY)) {
181189
+ minY = 0;
181190
+ }
181191
+ if (!isFinite(maxX)) {
181192
+ maxX = layout.width;
181193
+ }
181194
+ if (!isFinite(maxY)) {
181195
+ maxY = layout.height;
181196
+ }
181197
+ const extraPadX = Math.max(0, -Math.floor(minX) + 1);
181198
+ const extraPadY = Math.max(0, -Math.floor(minY) + 1);
181199
+ const padX = this.padding + extraPadX;
181200
+ const padY = this.padding + extraPadY;
181201
+ const bboxWidth = Math.ceil(maxX) - Math.min(0, Math.floor(minX));
181202
+ const bboxHeight = Math.ceil(maxY) - Math.min(0, Math.floor(minY));
181203
+ const width = bboxWidth + this.padding * 2 + extraPadX;
181204
+ const height = bboxHeight + this.padding * 2 + extraPadY;
181205
+ const elements = [];
181206
+ const overlays = [];
181207
+ elements.push(this.generateDefs());
181208
+ if (layout.subgraphs && layout.subgraphs.length) {
181209
+ const sgs = layout.subgraphs;
181210
+ const order = sgs.slice().sort((a3, b3) => (a3.parent ? 1 : 0) - (b3.parent ? 1 : 0));
181211
+ const map4 = new Map(order.map((o3) => [o3.id, o3]));
181212
+ const depthOf = (sg) => {
181213
+ let d3 = 0;
181214
+ let p3 = sg.parent;
181215
+ while (p3) {
181216
+ d3++;
181217
+ p3 = map4.get(p3)?.parent;
181218
+ }
181219
+ return d3;
181220
+ };
181221
+ const bgs = [];
181222
+ for (const sg of order) {
181223
+ const x3 = sg.x + padX;
181224
+ const y2 = sg.y + padY;
181225
+ bgs.push(blockBackground(x3, y2, sg.width, sg.height, 0));
181226
+ const depth = depthOf(sg);
181227
+ const title = sg.label ? this.escapeXml(sg.label) : void 0;
181228
+ const titleYOffset = 7 + depth * 12;
181229
+ overlays.push(blockOverlay(x3, y2, sg.width, sg.height, title, [], titleYOffset, "center", "left", 0));
181230
+ }
181231
+ elements.push(`<g class="subgraph-bg">${bgs.join("")}</g>`);
181232
+ }
181233
+ const nodeMap = {};
181234
+ for (const n3 of layout.nodes) {
181235
+ nodeMap[n3.id] = { x: n3.x + padX, y: n3.y + padY, width: n3.width, height: n3.height, shape: n3.shape };
181236
+ }
181237
+ if (layout.subgraphs && layout.subgraphs.length) {
181238
+ for (const sg of layout.subgraphs) {
181239
+ nodeMap[sg.id] = { x: sg.x + padX, y: sg.y + padY, width: sg.width, height: sg.height, shape: "rectangle" };
181240
+ }
181241
+ }
181242
+ for (const node of layout.nodes) {
181243
+ elements.push(this.generateNodeWithPad(node, padX, padY));
181244
+ }
181245
+ for (const edge of layout.edges) {
181246
+ const { path: path6, overlay } = this.generateEdge(edge, padX, padY, nodeMap);
181247
+ elements.push(path6);
181248
+ if (overlay)
181249
+ overlays.push(overlay);
181250
+ }
181251
+ const bg = `<rect x="0" y="0" width="${width}" height="${height}" fill="#ffffff" />`;
181252
+ const sharedCss = buildSharedCss({
181253
+ fontFamily: this.fontFamily,
181254
+ fontSize: this.fontSize,
181255
+ nodeFill: this.defaultFill,
181256
+ nodeStroke: this.defaultStroke,
181257
+ edgeStroke: this.arrowStroke
181258
+ });
181259
+ const css = `<style>${sharedCss}</style>`;
181260
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
181261
+ ${bg}
181262
+ ${css}
181263
+ ${elements.join("\n ")}
181264
+ ${overlays.join("\n ")}
181265
+ </svg>`;
181266
+ }
181267
+ buildNodeStyleAttrs(style) {
181268
+ const decs = [];
181269
+ if (style.fill)
181270
+ decs.push(`fill:${style.fill}`);
181271
+ if (style.stroke)
181272
+ decs.push(`stroke:${style.stroke}`);
181273
+ if (style.strokeWidth != null)
181274
+ decs.push(`stroke-width:${style.strokeWidth}`);
181275
+ return decs.length ? `style="${decs.join(";")}"` : "";
181276
+ }
181277
+ buildNodeStrokeStyle(style) {
181278
+ const decs = [];
181279
+ if (style.stroke)
181280
+ decs.push(`stroke:${style.stroke}`);
181281
+ if (style.strokeWidth != null)
181282
+ decs.push(`stroke-width:${style.strokeWidth}`);
181283
+ return decs.length ? `style="${decs.join(";")}"` : "";
181284
+ }
181285
+ generateDefs() {
181286
+ const aw = Math.max(8, this.arrowMarkerSize + 2);
181287
+ const ah = Math.max(8, this.arrowMarkerSize + 2);
181288
+ const arefX = Math.max(6, aw);
181289
+ const arefY = Math.max(4, Math.round(ah / 2));
181290
+ return `<defs>
181291
+ <marker id="arrow" viewBox="0 0 ${aw} ${ah}" markerWidth="${aw}" markerHeight="${ah}" refX="${arefX}" refY="${arefY}" orient="auto" markerUnits="userSpaceOnUse">
181292
+ <path d="M0,0 L0,${ah} L${aw},${arefY} z" fill="${this.arrowStroke}" />
181293
+ </marker>
181294
+ <marker id="circle-marker" viewBox="0 0 9 9" markerWidth="9" markerHeight="9" refX="4.5" refY="4.5" orient="auto" markerUnits="userSpaceOnUse">
181295
+ <circle cx="4.5" cy="4.5" r="4.5" fill="${this.arrowStroke}" />
181296
+ </marker>
181297
+ <marker id="cross-marker" viewBox="0 0 12 12" markerWidth="12" markerHeight="12" refX="6" refY="6" orient="auto" markerUnits="userSpaceOnUse">
181298
+ <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" />
181299
+ </marker>
181300
+ </defs>`;
181301
+ }
181302
+ generateNodeWithPad(node, padX, padY) {
181303
+ const x3 = node.x + padX;
181304
+ const y2 = node.y + padY;
181305
+ const cx = x3 + node.width / 2;
181306
+ const cy = y2 + node.height / 2;
181307
+ let shape = "";
181308
+ let labelCenterY = cy;
181309
+ const strokeWidth = node.style?.strokeWidth ?? void 0;
181310
+ const stroke = node.style?.stroke ?? void 0;
181311
+ const fill = node.style?.fill ?? void 0;
181312
+ const styleAttr = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
181313
+ switch (node.shape) {
181314
+ case "rectangle":
181315
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
181316
+ break;
181317
+ case "round":
181318
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="5" ry="5" />`;
181319
+ break;
181320
+ case "stadium":
181321
+ const radius = node.height / 2;
181322
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="${radius}" ry="${radius}" />`;
181323
+ break;
181324
+ case "circle":
181325
+ const r3 = Math.min(node.width, node.height) / 2;
181326
+ shape = `<circle class="node-shape" ${styleAttr} cx="${cx}" cy="${cy}" r="${r3}" />`;
181327
+ break;
181328
+ case "diamond": {
181329
+ const points = [
181330
+ `${cx},${y2}`,
181331
+ // top
181332
+ `${x3 + node.width},${cy}`,
181333
+ // right
181334
+ `${cx},${y2 + node.height}`,
181335
+ // bottom
181336
+ `${x3},${cy}`
181337
+ // left
181338
+ ].join(" ");
181339
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
181340
+ break;
181341
+ }
181342
+ case "hexagon": {
181343
+ const dx = node.width * 0.25;
181344
+ const points = [
181345
+ `${x3 + dx},${y2}`,
181346
+ // top-left
181347
+ `${x3 + node.width - dx},${y2}`,
181348
+ // top-right
181349
+ `${x3 + node.width},${cy}`,
181350
+ // right
181351
+ `${x3 + node.width - dx},${y2 + node.height}`,
181352
+ // bottom-right
181353
+ `${x3 + dx},${y2 + node.height}`,
181354
+ // bottom-left
181355
+ `${x3},${cy}`
181356
+ // left
181357
+ ].join(" ");
181358
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
181359
+ break;
181360
+ }
181361
+ case "parallelogram": {
181362
+ const skew = node.width * 0.15;
181363
+ const points = [
181364
+ `${x3 + skew},${y2}`,
181365
+ // top-left
181366
+ `${x3 + node.width},${y2}`,
181367
+ // top-right
181368
+ `${x3 + node.width - skew},${y2 + node.height}`,
181369
+ // bottom-right
181370
+ `${x3},${y2 + node.height}`
181371
+ // bottom-left
181372
+ ].join(" ");
181373
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
181374
+ break;
181375
+ }
181376
+ case "trapezoid": {
181377
+ const inset = node.width * 0.15;
181378
+ const points = [
181379
+ `${x3 + inset},${y2}`,
181380
+ // top-left
181381
+ `${x3 + node.width - inset},${y2}`,
181382
+ // top-right
181383
+ `${x3 + node.width},${y2 + node.height}`,
181384
+ // bottom-right
181385
+ `${x3},${y2 + node.height}`
181386
+ // bottom-left
181387
+ ].join(" ");
181388
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
181389
+ break;
181390
+ }
181391
+ case "trapezoidAlt": {
181392
+ const inset = node.width * 0.15;
181393
+ const points = [
181394
+ `${x3},${y2}`,
181395
+ // top-left (full width)
181396
+ `${x3 + node.width},${y2}`,
181397
+ // top-right
181398
+ `${x3 + node.width - inset},${y2 + node.height}`,
181399
+ // bottom-right (narrow)
181400
+ `${x3 + inset},${y2 + node.height}`
181401
+ // bottom-left (narrow)
181402
+ ].join(" ");
181403
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
181404
+ break;
181405
+ }
181406
+ case "cylinder": {
181407
+ const rx = Math.max(8, node.width / 2);
181408
+ const ry = Math.max(6, Math.min(node.height * 0.22, node.width * 0.25));
181409
+ const topCY = y2 + ry;
181410
+ const botCY = y2 + node.height - ry;
181411
+ const bodyH = Math.max(0, node.height - ry * 2);
181412
+ const strokeOnly = this.buildNodeStrokeStyle({ stroke, strokeWidth });
181413
+ shape = `<g>
181414
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${topCY}" width="${node.width}" height="${bodyH}" />
181415
+ <ellipse class="node-shape" ${styleAttr} cx="${cx}" cy="${topCY}" rx="${node.width / 2}" ry="${ry}" />
181416
+ <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" />
181417
+ </g>`;
181418
+ labelCenterY = topCY + bodyH / 2;
181419
+ break;
181420
+ }
181421
+ case "subroutine":
181422
+ const insetX = 5;
181423
+ const strokeOnly2 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
181424
+ shape = `<g>
181425
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
181426
+ <line class="node-shape" ${strokeOnly2} x1="${x3 + insetX}" y1="${y2}" x2="${x3 + insetX}" y2="${y2 + node.height}" />
181427
+ <line class="node-shape" ${strokeOnly2} x1="${x3 + node.width - insetX}" y1="${y2}" x2="${x3 + node.width - insetX}" y2="${y2 + node.height}" />
181428
+ </g>`;
181429
+ break;
181430
+ case "double":
181431
+ const gap = 4;
181432
+ const strokeOnly3 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
181433
+ shape = `<g>
181434
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
181435
+ <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" />
181436
+ </g>`;
181437
+ break;
181438
+ default:
181439
+ const s3 = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
181440
+ shape = `<rect ${s3} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
181441
+ }
181442
+ const text = this.generateWrappedText(node.label, cx, labelCenterY, node.width - 20);
181443
+ return `<g id="${node.id}">
181444
+ ${shape}
181445
+ ${text}
181446
+ </g>`;
181447
+ }
181448
+ generateWrappedText(text, x3, y2, maxWidth) {
181449
+ if (text.includes("<")) {
181450
+ return this.generateRichText(text, x3, y2, maxWidth);
181451
+ }
181452
+ const charWidth = 7;
181453
+ const maxCharsPerLine = Math.floor(maxWidth / charWidth);
181454
+ if (maxCharsPerLine <= 0 || text.length <= maxCharsPerLine) {
181455
+ const dyOffset = this.fontSize * 0.35;
181456
+ return `<text class="node-label" x="${x3}" y="${y2 + dyOffset}" text-anchor="middle">${this.escapeXml(text)}</text>`;
181457
+ }
181458
+ const words = text.split(" ");
181459
+ const lines = [];
181460
+ let currentLine = "";
181461
+ for (const word of words) {
181462
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
181463
+ if (testLine.length > maxCharsPerLine && currentLine) {
181464
+ lines.push(currentLine);
181465
+ currentLine = word;
181466
+ } else {
181467
+ currentLine = testLine;
181468
+ }
181469
+ }
181470
+ if (currentLine) {
181471
+ lines.push(currentLine);
181472
+ }
181473
+ const lineHeight = 18;
181474
+ const totalHeight = (lines.length - 1) * lineHeight;
181475
+ const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
181476
+ const tspans = lines.map((line, i3) => {
181477
+ const lineY = startY + i3 * lineHeight;
181478
+ return `<tspan x="${x3}" y="${lineY}" text-anchor="middle">${this.escapeXml(line)}</tspan>`;
181479
+ }).join("\n ");
181480
+ return `<text class="node-label">
181481
+ ${tspans}
181482
+ </text>`;
181483
+ }
181484
+ // Basic HTML-aware text renderer supporting <br>, <b>/<strong>, <i>/<em>, <u>
181485
+ generateRichText(html, x3, y2, maxWidth) {
181486
+ html = this.normalizeHtml(html);
181487
+ const segments = [];
181488
+ const re = /<\/?(br|b|strong|i|em|u)\s*\/?\s*>/gi;
181489
+ let lastIndex = 0;
181490
+ const state2 = { bold: false, italic: false, underline: false };
181491
+ const pushText = (t3) => {
181492
+ if (!t3)
181493
+ return;
181494
+ segments.push({ text: this.htmlDecode(t3), bold: state2.bold, italic: state2.italic, underline: state2.underline });
181495
+ };
181496
+ let m3;
181497
+ while (m3 = re.exec(html)) {
181498
+ pushText(html.slice(lastIndex, m3.index));
181499
+ const tag2 = m3[0].toLowerCase();
181500
+ const name14 = m3[1].toLowerCase();
181501
+ const isClose = tag2.startsWith("</");
181502
+ if (name14 === "br") {
181503
+ segments.push({ text: "", br: true });
181504
+ } else if (name14 === "b" || name14 === "strong") {
181505
+ state2.bold = !isClose ? true : false;
181506
+ } else if (name14 === "i" || name14 === "em") {
181507
+ state2.italic = !isClose ? true : false;
181508
+ } else if (name14 === "u") {
181509
+ state2.underline = !isClose ? true : false;
181510
+ }
181511
+ lastIndex = re.lastIndex;
181512
+ }
181513
+ pushText(html.slice(lastIndex));
181514
+ const lines = [];
181515
+ const charWidth = 7;
181516
+ const maxCharsPerLine = Math.max(1, Math.floor(maxWidth / charWidth));
181517
+ let current = [];
181518
+ let currentLen = 0;
181519
+ const flush = () => {
181520
+ if (current.length) {
181521
+ lines.push(current);
181522
+ current = [];
181523
+ currentLen = 0;
181524
+ }
181525
+ };
181526
+ const splitWords = (s3) => {
181527
+ if (!s3.text)
181528
+ return [s3];
181529
+ const words = s3.text.split(/(\s+)/);
181530
+ return words.map((w3) => ({ ...s3, text: w3 }));
181531
+ };
181532
+ for (const seg of segments) {
181533
+ if (seg.br) {
181534
+ flush();
181535
+ continue;
181536
+ }
181537
+ for (const w3 of splitWords(seg)) {
181538
+ const wlen = w3.text.length;
181539
+ if (currentLen + wlen > maxCharsPerLine && currentLen > 0) {
181540
+ flush();
181541
+ }
181542
+ current.push(w3);
181543
+ currentLen += wlen;
181544
+ }
181545
+ }
181546
+ flush();
181547
+ const lineHeight = 18;
181548
+ const totalHeight = (lines.length - 1) * lineHeight;
181549
+ const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
181550
+ const tspans = [];
181551
+ for (let i3 = 0; i3 < lines.length; i3++) {
181552
+ const lineY = startY + i3 * lineHeight;
181553
+ let acc = "";
181554
+ let cursorX = x3;
181555
+ const inner = [];
181556
+ let buffer = "";
181557
+ let style = { bold: false, italic: false, underline: false };
181558
+ const flushInline = () => {
181559
+ if (!buffer)
181560
+ return;
181561
+ const styleAttr = `${style.bold ? 'font-weight="bold" ' : ""}${style.italic ? 'font-style="italic" ' : ""}${style.underline ? 'text-decoration="underline" ' : ""}`;
181562
+ inner.push(`<tspan ${styleAttr}>${this.escapeXml(buffer)}</tspan>`);
181563
+ buffer = "";
181564
+ };
181565
+ for (const w3 of lines[i3]) {
181566
+ const wStyle = { bold: !!w3.bold, italic: !!w3.italic, underline: !!w3.underline };
181567
+ if (wStyle.bold !== style.bold || wStyle.italic !== style.italic || wStyle.underline !== style.underline) {
181568
+ flushInline();
181569
+ style = wStyle;
181570
+ }
181571
+ buffer += w3.text;
181572
+ }
181573
+ flushInline();
181574
+ tspans.push(`<tspan x="${x3}" y="${lineY}" text-anchor="middle">${inner.join("")}</tspan>`);
181575
+ }
181576
+ return `<text font-family="${this.fontFamily}" font-size="${this.fontSize}" fill="#333">${tspans.join("\n ")}</text>`;
181577
+ }
181578
+ normalizeHtml(s3) {
181579
+ let out = s3.replace(/<\s+/g, "<").replace(/\s+>/g, ">").replace(/<\s*\//g, "</").replace(/\s*\/\s*>/g, "/>").replace(/<\s*(br)\s*>/gi, "<$1/>");
181580
+ return out;
181581
+ }
181582
+ htmlDecode(s3) {
181583
+ return s3.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#39;/g, "'");
181584
+ }
181585
+ generateEdge(edge, padX, padY, nodeMap) {
181586
+ if (!edge.points || edge.points.length < 2) {
181587
+ return { path: "" };
181588
+ }
181589
+ const points = edge.points.map((p3) => ({ x: p3.x + padX, y: p3.y + padY }));
181590
+ const segData = this.buildSmoothSegments(points);
181591
+ let strokeDasharray = "";
181592
+ let strokeWidth = 1.5;
181593
+ let markerEnd = "";
181594
+ let markerStart = "";
181595
+ switch (edge.type) {
181596
+ case "open":
181597
+ markerEnd = "";
181598
+ break;
181599
+ case "dotted":
181600
+ strokeDasharray = "3,3";
181601
+ break;
181602
+ case "thick":
181603
+ strokeWidth = 3;
181604
+ break;
181605
+ case "invisible":
181606
+ strokeDasharray = "0,100000";
181607
+ markerEnd = "";
181608
+ break;
181609
+ }
181610
+ const mStart = edge.markerStart;
181611
+ const mEnd = edge.markerEnd;
181612
+ const sourceNode = nodeMap[edge.source];
181613
+ const targetNode = nodeMap[edge.target];
181614
+ let boundaryStart = points[0];
181615
+ let boundaryEnd = points[points.length - 1];
181616
+ if (sourceNode && points.length >= 2) {
181617
+ const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
181618
+ boundaryStart = this.intersectSegmentsStart(pseudo, sourceNode).start;
181619
+ }
181620
+ if (targetNode && points.length >= 2) {
181621
+ const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
181622
+ const after = this.intersectSegmentsEnd(pseudo, targetNode);
181623
+ boundaryEnd = after.segs.length ? after.segs[after.segs.length - 1].to : boundaryEnd;
181624
+ }
181625
+ const pathParts = [];
181626
+ pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
181627
+ let startFlat = points.length >= 2 ? points[1] : boundaryStart;
181628
+ if (points.length >= 2) {
181629
+ const svx = points[1].x - boundaryStart.x;
181630
+ const svy = points[1].y - boundaryStart.y;
181631
+ const slen = Math.hypot(svx, svy) || 1;
181632
+ const SFLAT = Math.min(22, Math.max(10, slen * 0.15));
181633
+ startFlat = { x: boundaryStart.x + svx / slen * SFLAT, y: boundaryStart.y + svy / slen * SFLAT };
181634
+ pathParts.push(`L${startFlat.x},${startFlat.y}`);
181635
+ }
181636
+ const orthogonal = edge.pathMode === "orthogonal";
181637
+ if (points.length >= 4 && !orthogonal) {
181638
+ const pts = [points[0], ...points, points[points.length - 1]];
181639
+ for (let i3 = 1; i3 < pts.length - 3; i3++) {
181640
+ const p0 = pts[i3 - 1];
181641
+ const p1 = pts[i3];
181642
+ const p22 = pts[i3 + 1];
181643
+ const p3 = pts[i3 + 2];
181644
+ const c1x = p1.x + (p22.x - p0.x) / 6;
181645
+ const c1y = p1.y + (p22.y - p0.y) / 6;
181646
+ const c2x = p22.x - (p3.x - p1.x) / 6;
181647
+ const c2y = p22.y - (p3.y - p1.y) / 6;
181648
+ pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${p22.x},${p22.y}`);
181649
+ }
181650
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
181651
+ } else if (points.length === 3 && !orthogonal) {
181652
+ const p0 = boundaryStart, p1 = points[1], p22 = boundaryEnd;
181653
+ const ax = boundaryEnd.x - p1.x;
181654
+ const ay = boundaryEnd.y - p1.y;
181655
+ const alen = Math.hypot(ax, ay) || 1;
181656
+ const FLAT_IN = Math.min(20, Math.max(10, alen * 0.15));
181657
+ const preEnd = { x: boundaryEnd.x - ax / alen * FLAT_IN, y: boundaryEnd.y - ay / alen * FLAT_IN };
181658
+ const sdx = startFlat.x - boundaryStart.x;
181659
+ const sdy = startFlat.y - boundaryStart.y;
181660
+ const sdirx = sdx === 0 && sdy === 0 ? p1.x - p0.x : sdx;
181661
+ const sdiry = sdx === 0 && sdy === 0 ? p1.y - p0.y : sdy;
181662
+ const sdlen = Math.hypot(sdirx, sdiry) || 1;
181663
+ const c1len = Math.min(40, Math.max(12, sdlen * 1.2));
181664
+ const c1x = startFlat.x + sdirx / sdlen * c1len;
181665
+ const c1y = startFlat.y + sdiry / sdlen * c1len;
181666
+ const dirx = (boundaryEnd.x - p1.x) / alen;
181667
+ const diry = (boundaryEnd.y - p1.y) / alen;
181668
+ const c2x = preEnd.x - dirx * (FLAT_IN * 0.6);
181669
+ const c2y = preEnd.y - diry * (FLAT_IN * 0.6);
181670
+ pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${preEnd.x},${preEnd.y}`);
181671
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
181672
+ } else {
181673
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
181674
+ }
181675
+ if (orthogonal) {
181676
+ pathParts.length = 0;
181677
+ pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
181678
+ for (const p3 of points.slice(1, -1))
181679
+ pathParts.push(`L${p3.x},${p3.y}`);
181680
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
181681
+ }
181682
+ const pathData = pathParts.join(" ");
181683
+ let edgeElement = `<path class="edge-path" d="${pathData}" stroke-linecap="round" stroke-linejoin="round"`;
181684
+ if (strokeDasharray) {
181685
+ edgeElement += ` stroke-dasharray="${strokeDasharray}"`;
181686
+ }
181687
+ const startMarkUrl = mStart === "arrow" ? "url(#arrow)" : mStart === "circle" ? "url(#circle-marker)" : mStart === "cross" ? "url(#cross-marker)" : "";
181688
+ const endMarkUrl = mEnd === "arrow" ? "url(#arrow)" : mEnd === "circle" ? "url(#circle-marker)" : mEnd === "cross" ? "url(#cross-marker)" : markerEnd || "";
181689
+ if (startMarkUrl && mStart !== "arrow")
181690
+ edgeElement += ` marker-start="${startMarkUrl}"`;
181691
+ if (endMarkUrl && mEnd !== "arrow")
181692
+ edgeElement += ` marker-end="${endMarkUrl}"`;
181693
+ edgeElement += " />";
181694
+ if (edge.label) {
181695
+ const pos = this.pointAtRatio(points, 0.55);
181696
+ const text = this.escapeXml(edge.label);
181697
+ const padding = 4;
181698
+ const fontSize = this.fontSize - 3;
181699
+ const width = Math.max(18, Math.min(220, text.length * 6 + padding * 2));
181700
+ const height = 14;
181701
+ const x3 = pos.x - width / 2;
181702
+ const y2 = pos.y - height / 2;
181703
+ const labelBg = `<rect class="edge-label-bg" x="${x3}" y="${y2}" width="${width}" height="${height}" rx="3" />`;
181704
+ const labelText = `<text class="edge-label-text" x="${pos.x}" y="${pos.y}" text-anchor="middle" dominant-baseline="middle">${text}</text>`;
181705
+ let overlay2 = "";
181706
+ const prevEndL = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
181707
+ const vxl = boundaryEnd.x - prevEndL.x;
181708
+ const vyl = boundaryEnd.y - prevEndL.y;
181709
+ const vlenl = Math.hypot(vxl, vyl) || 1;
181710
+ const uxl = vxl / vlenl;
181711
+ const uyl = vyl / vlenl;
181712
+ const nxl = -uyl;
181713
+ const nyl = uxl;
181714
+ const triLenL = 8;
181715
+ const triWL = 6;
181716
+ const p1xL = boundaryEnd.x, p1yL = boundaryEnd.y;
181717
+ const baseXL = boundaryEnd.x - uxl * triLenL;
181718
+ const baseYL = boundaryEnd.y - uyl * triLenL;
181719
+ const p2xL = baseXL + nxl * (triWL / 2), p2yL = baseYL + nyl * (triWL / 2);
181720
+ const p3xL = baseXL - nxl * (triWL / 2), p3yL = baseYL - nyl * (triWL / 2);
181721
+ overlay2 += triangleAtEnd(prevEndL, boundaryEnd, this.arrowStroke);
181722
+ if (mStart === "arrow" && points.length >= 2) {
181723
+ const firstLeg = points[1];
181724
+ const svx = boundaryStart.x - firstLeg.x;
181725
+ const svy = boundaryStart.y - firstLeg.y;
181726
+ const slen = Math.hypot(svx, svy) || 1;
181727
+ const sux = svx / slen;
181728
+ const suy = svy / slen;
181729
+ const snx = -suy;
181730
+ const sny = sux;
181731
+ const sbaseX = boundaryStart.x - sux * triLenL;
181732
+ const sbaseY = boundaryStart.y - suy * triLenL;
181733
+ overlay2 += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
181734
+ }
181735
+ const pathGroup = `<g>
181736
+ ${edgeElement}
181737
+ ${labelBg}
181738
+ ${labelText}
181739
+ ${overlay2}
181740
+ </g>`;
181741
+ return { path: pathGroup };
181742
+ }
181743
+ let overlay = "";
181744
+ const prevEnd = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
181745
+ const vx = boundaryEnd.x - prevEnd.x;
181746
+ const vy = boundaryEnd.y - prevEnd.y;
181747
+ const vlen = Math.hypot(vx, vy) || 1;
181748
+ const ux = vx / vlen;
181749
+ const uy = vy / vlen;
181750
+ const nx = -uy;
181751
+ const ny = ux;
181752
+ const triLen = 8;
181753
+ const triW = 6;
181754
+ const p1x = boundaryEnd.x, p1y = boundaryEnd.y;
181755
+ const baseX = boundaryEnd.x - ux * triLen;
181756
+ const baseY = boundaryEnd.y - uy * triLen;
181757
+ const p2x = baseX + nx * (triW / 2), p2y = baseY + ny * (triW / 2);
181758
+ const p3x = baseX - nx * (triW / 2), p3y = baseY - ny * (triW / 2);
181759
+ if (mEnd === "arrow")
181760
+ overlay += triangleAtEnd(prevEnd, boundaryEnd, this.arrowStroke);
181761
+ if (mStart === "arrow" && points.length >= 2) {
181762
+ const firstLeg = points[1];
181763
+ const svx = boundaryStart.x - firstLeg.x;
181764
+ const svy = boundaryStart.y - firstLeg.y;
181765
+ const slen = Math.hypot(svx, svy) || 1;
181766
+ const sux = svx / slen;
181767
+ const suy = svy / slen;
181768
+ const snx = -suy;
181769
+ const sny = sux;
181770
+ overlay += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
181771
+ }
181772
+ if (overlay) {
181773
+ const grouped = `<g>${edgeElement}
181774
+ ${overlay}</g>`;
181775
+ return { path: grouped };
181776
+ }
181777
+ return { path: edgeElement };
181778
+ }
181779
+ // --- helpers ---
181780
+ buildSmoothSegments(points) {
181781
+ if (points.length < 2) {
181782
+ const p3 = points[0] || { x: 0, y: 0 };
181783
+ return { start: p3, segs: [] };
181784
+ }
181785
+ if (points.length === 2) {
181786
+ const p0 = points[0];
181787
+ const p1 = points[1];
181788
+ const c1 = { x: p0.x + (p1.x - p0.x) / 3, y: p0.y + (p1.y - p0.y) / 3 };
181789
+ const c22 = { x: p0.x + 2 * (p1.x - p0.x) / 3, y: p0.y + 2 * (p1.y - p0.y) / 3 };
181790
+ return { start: p0, segs: [{ c1, c2: c22, to: p1 }] };
181791
+ }
181792
+ const pts = [points[0], ...points, points[points.length - 1]];
181793
+ const segs = [];
181794
+ const firstIdx = 1;
181795
+ const lastIdx = pts.length - 3;
181796
+ const midFactor = 1;
181797
+ const endFactor = 0.35;
181798
+ const FLAT_LEN = 28;
181799
+ for (let i3 = 1; i3 < pts.length - 2; i3++) {
181800
+ const p0 = pts[i3 - 1];
181801
+ const p1 = pts[i3];
181802
+ const p22 = pts[i3 + 1];
181803
+ const p3 = pts[i3 + 2];
181804
+ const f1 = i3 === firstIdx ? endFactor : midFactor;
181805
+ const f22 = i3 === lastIdx ? endFactor : midFactor;
181806
+ let c1 = { x: p1.x + (p22.x - p0.x) / 6 * f1, y: p1.y + (p22.y - p0.y) / 6 * f1 };
181807
+ let c22 = { x: p22.x - (p3.x - p1.x) / 6 * f22, y: p22.y - (p3.y - p1.y) / 6 * f22 };
181808
+ if (i3 === firstIdx) {
181809
+ const dx = p22.x - p1.x, dy = p22.y - p1.y;
181810
+ const len = Math.hypot(dx, dy) || 1;
181811
+ const t3 = Math.min(FLAT_LEN, len * 0.5);
181812
+ c1 = { x: p1.x + dx / len * t3, y: p1.y + dy / len * t3 };
181813
+ }
181814
+ if (i3 === lastIdx) {
181815
+ const dx = p22.x - p1.x, dy = p22.y - p1.y;
181816
+ const len = Math.hypot(dx, dy) || 1;
181817
+ const t3 = Math.min(FLAT_LEN, len * 0.5);
181818
+ c22 = { x: p22.x - dx / len * t3, y: p22.y - dy / len * t3 };
181819
+ }
181820
+ segs.push({ c1, c2: c22, to: { x: p22.x, y: p22.y } });
181821
+ }
181822
+ return { start: pts[1], segs };
181823
+ }
181824
+ pathFromSegments(data2) {
181825
+ let d3 = `M${data2.start.x},${data2.start.y}`;
181826
+ for (const s3 of data2.segs) {
181827
+ d3 += ` C${s3.c1.x},${s3.c1.y} ${s3.c2.x},${s3.c2.y} ${s3.to.x},${s3.to.y}`;
181828
+ }
181829
+ return d3;
181830
+ }
181831
+ trimSegmentsEnd(data2, cut) {
181832
+ const segs = data2.segs.slice();
181833
+ if (!segs.length)
181834
+ return data2;
181835
+ const last2 = { ...segs[segs.length - 1] };
181836
+ const vx = last2.to.x - last2.c2.x;
181837
+ const vy = last2.to.y - last2.c2.y;
181838
+ const len = Math.hypot(vx, vy) || 1;
181839
+ const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
181840
+ const nx = vx / len;
181841
+ const ny = vy / len;
181842
+ const newTo = { x: last2.to.x - nx * eff, y: last2.to.y - ny * eff };
181843
+ last2.to = newTo;
181844
+ segs[segs.length - 1] = last2;
181845
+ return { start: data2.start, segs };
181846
+ }
181847
+ trimSegmentsStart(data2, cut) {
181848
+ const segs = data2.segs.slice();
181849
+ if (!segs.length)
181850
+ return data2;
181851
+ const first2 = { ...segs[0] };
181852
+ const vx = first2.c1.x - data2.start.x;
181853
+ const vy = first2.c1.y - data2.start.y;
181854
+ const len = Math.hypot(vx, vy) || 1;
181855
+ const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
181856
+ const nx = vx / len;
181857
+ const ny = vy / len;
181858
+ const newStart = { x: data2.start.x + nx * eff, y: data2.start.y + ny * eff };
181859
+ return { start: newStart, segs };
181860
+ }
181861
+ // ---- shape intersections ----
181862
+ intersectSegmentsEnd(data2, node) {
181863
+ if (!data2.segs.length)
181864
+ return data2;
181865
+ const last2 = data2.segs[data2.segs.length - 1];
181866
+ const p1 = last2.c2;
181867
+ const p22 = last2.to;
181868
+ const hit = this.intersectLineWithNode(p1, p22, node);
181869
+ if (hit) {
181870
+ const segs = data2.segs.slice();
181871
+ segs[segs.length - 1] = { ...last2, to: hit };
181872
+ return { start: data2.start, segs };
181873
+ }
181874
+ return data2;
181875
+ }
181876
+ intersectSegmentsStart(data2, node) {
181877
+ if (!data2.segs.length)
181878
+ return data2;
181879
+ const first2 = data2.segs[0];
181880
+ const p1 = data2.start;
181881
+ const p22 = first2.c1;
181882
+ const hit = this.intersectLineWithNode(p1, p22, node);
181883
+ if (hit) {
181884
+ return { start: hit, segs: data2.segs };
181885
+ }
181886
+ return data2;
181887
+ }
181888
+ intersectLineWithNode(p1, p22, node) {
181889
+ const shape = node.shape;
181890
+ const rectPoly = () => [
181891
+ { x: node.x, y: node.y },
181892
+ { x: node.x + node.width, y: node.y },
181893
+ { x: node.x + node.width, y: node.y + node.height },
181894
+ { x: node.x, y: node.y + node.height }
181895
+ ];
181896
+ switch (shape) {
181897
+ case "circle": {
181898
+ const cx = node.x + node.width / 2;
181899
+ const cy = node.y + node.height / 2;
181900
+ const r3 = Math.min(node.width, node.height) / 2;
181901
+ return this.lineCircleIntersection(p1, p22, { cx, cy, r: r3 });
181902
+ }
181903
+ case "diamond": {
181904
+ const cx = node.x + node.width / 2;
181905
+ const cy = node.y + node.height / 2;
181906
+ 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 }];
181907
+ return this.linePolygonIntersection(p1, p22, poly);
181908
+ }
181909
+ case "hexagon": {
181910
+ const s3 = Math.max(10, node.width * 0.2);
181911
+ const poly = [
181912
+ { x: node.x + s3, y: node.y },
181913
+ { x: node.x + node.width - s3, y: node.y },
181914
+ { x: node.x + node.width, y: node.y + node.height / 2 },
181915
+ { x: node.x + node.width - s3, y: node.y + node.height },
181916
+ { x: node.x + s3, y: node.y + node.height },
181917
+ { x: node.x, y: node.y + node.height / 2 }
181918
+ ];
181919
+ return this.linePolygonIntersection(p1, p22, poly);
181920
+ }
181921
+ case "parallelogram": {
181922
+ const o3 = Math.min(node.width * 0.25, node.height * 0.6);
181923
+ const poly = [
181924
+ { x: node.x + o3, y: node.y },
181925
+ { x: node.x + node.width, y: node.y },
181926
+ { x: node.x + node.width - o3, y: node.y + node.height },
181927
+ { x: node.x, y: node.y + node.height }
181928
+ ];
181929
+ return this.linePolygonIntersection(p1, p22, poly);
181930
+ }
181931
+ case "trapezoid": {
181932
+ const o3 = Math.min(node.width * 0.2, node.height * 0.5);
181933
+ const poly = [
181934
+ { x: node.x + o3, y: node.y },
181935
+ { x: node.x + node.width - o3, y: node.y },
181936
+ { x: node.x + node.width, y: node.y + node.height },
181937
+ { x: node.x, y: node.y + node.height }
181938
+ ];
181939
+ return this.linePolygonIntersection(p1, p22, poly);
181940
+ }
181941
+ case "trapezoidAlt": {
181942
+ const o3 = Math.min(node.width * 0.2, node.height * 0.5);
181943
+ const poly = [
181944
+ { x: node.x, y: node.y },
181945
+ { x: node.x + node.width, y: node.y },
181946
+ { x: node.x + node.width - o3, y: node.y + node.height },
181947
+ { x: node.x + o3, y: node.y + node.height }
181948
+ ];
181949
+ return this.linePolygonIntersection(p1, p22, poly);
181950
+ }
181951
+ case "stadium": {
181952
+ const r3 = Math.min(node.height / 2, node.width / 2);
181953
+ const rect = [
181954
+ { x: node.x + r3, y: node.y },
181955
+ { x: node.x + node.width - r3, y: node.y },
181956
+ { x: node.x + node.width - r3, y: node.y + node.height },
181957
+ { x: node.x + r3, y: node.y + node.height }
181958
+ ];
181959
+ const hitRect = this.linePolygonIntersection(p1, p22, rect);
181960
+ if (hitRect)
181961
+ return hitRect;
181962
+ const left = this.lineCircleIntersection(p1, p22, { cx: node.x + r3, cy: node.y + node.height / 2, r: r3 });
181963
+ const right = this.lineCircleIntersection(p1, p22, { cx: node.x + node.width - r3, cy: node.y + node.height / 2, r: r3 });
181964
+ const pick = (...pts) => {
181965
+ let best = null;
181966
+ let bestd = -Infinity;
181967
+ for (const pt of pts)
181968
+ if (pt) {
181969
+ const d3 = -((pt.x - p22.x) ** 2 + (pt.y - p22.y) ** 2);
181970
+ if (d3 > bestd) {
181971
+ bestd = d3;
181972
+ best = pt;
181973
+ }
181974
+ }
181975
+ return best;
181976
+ };
181977
+ return pick(left, right);
181978
+ }
181979
+ default: {
181980
+ return this.linePolygonIntersection(p1, p22, rectPoly());
181981
+ }
181982
+ }
181983
+ }
181984
+ lineCircleIntersection(p1, p22, c3) {
181985
+ const dx = p22.x - p1.x;
181986
+ const dy = p22.y - p1.y;
181987
+ const fx = p1.x - c3.cx;
181988
+ const fy = p1.y - c3.cy;
181989
+ const a3 = dx * dx + dy * dy;
181990
+ const b3 = 2 * (fx * dx + fy * dy);
181991
+ const cc2 = fx * fx + fy * fy - c3.r * c3.r;
181992
+ const disc = b3 * b3 - 4 * a3 * cc2;
181993
+ if (disc < 0)
181994
+ return null;
181995
+ const s3 = Math.sqrt(disc);
181996
+ const t1 = (-b3 - s3) / (2 * a3);
181997
+ const t22 = (-b3 + s3) / (2 * a3);
181998
+ const ts = [t1, t22].filter((t4) => t4 >= 0 && t4 <= 1);
181999
+ if (!ts.length)
182000
+ return null;
182001
+ const t3 = Math.max(...ts);
182002
+ return { x: p1.x + dx * t3, y: p1.y + dy * t3 };
182003
+ }
182004
+ linePolygonIntersection(p1, p22, poly) {
182005
+ let bestT = -Infinity;
182006
+ let best = null;
182007
+ for (let i3 = 0; i3 < poly.length; i3++) {
182008
+ const a3 = poly[i3];
182009
+ const b3 = poly[(i3 + 1) % poly.length];
182010
+ const hit = this.segmentIntersection(p1, p22, a3, b3);
182011
+ if (hit && hit.t >= 0 && hit.t <= 1 && hit.u >= 0 && hit.u <= 1) {
182012
+ if (hit.t > bestT) {
182013
+ bestT = hit.t;
182014
+ best = { x: hit.x, y: hit.y };
182015
+ }
182016
+ }
182017
+ }
182018
+ return best;
182019
+ }
182020
+ segmentIntersection(p3, p22, q3, q22) {
182021
+ const r3 = { x: p22.x - p3.x, y: p22.y - p3.y };
182022
+ const s3 = { x: q22.x - q3.x, y: q22.y - q3.y };
182023
+ const rxs = r3.x * s3.y - r3.y * s3.x;
182024
+ if (Math.abs(rxs) < 1e-6)
182025
+ return null;
182026
+ const q_p = { x: q3.x - p3.x, y: q3.y - p3.y };
182027
+ const t3 = (q_p.x * s3.y - q_p.y * s3.x) / rxs;
182028
+ const u3 = (q_p.x * r3.y - q_p.y * r3.x) / rxs;
182029
+ const x3 = p3.x + t3 * r3.x;
182030
+ const y2 = p3.y + t3 * r3.y;
182031
+ return { x: x3, y: y2, t: t3, u: u3 };
182032
+ }
182033
+ pointAtRatio(points, ratio) {
182034
+ const clampRatio = Math.max(0, Math.min(1, ratio));
182035
+ let total = 0;
182036
+ const segs = [];
182037
+ for (let i3 = 0; i3 < points.length - 1; i3++) {
182038
+ const dx = points[i3 + 1].x - points[i3].x;
182039
+ const dy = points[i3 + 1].y - points[i3].y;
182040
+ const len = Math.hypot(dx, dy);
182041
+ segs.push(len);
182042
+ total += len;
182043
+ }
182044
+ if (total === 0)
182045
+ return points[Math.floor(points.length / 2)];
182046
+ let target = total * clampRatio;
182047
+ for (let i3 = 0; i3 < segs.length; i3++) {
182048
+ if (target <= segs[i3]) {
182049
+ const t3 = segs[i3] === 0 ? 0 : target / segs[i3];
182050
+ return {
182051
+ x: points[i3].x + (points[i3 + 1].x - points[i3].x) * t3,
182052
+ y: points[i3].y + (points[i3 + 1].y - points[i3].y) * t3
182053
+ };
182054
+ }
182055
+ target -= segs[i3];
182056
+ }
182057
+ return points[points.length - 1];
182058
+ }
182059
+ escapeXml(text) {
182060
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
182061
+ }
182062
+ };
182063
+ }
182064
+ });
182065
+
182066
+ // node_modules/@probelabs/maid/out/renderer/pie-builder.js
182067
+ function unquote(s3) {
182068
+ if (!s3)
182069
+ return s3;
182070
+ const first2 = s3.charAt(0);
182071
+ const last2 = s3.charAt(s3.length - 1);
182072
+ if (first2 === '"' && last2 === '"' || first2 === "'" && last2 === "'") {
182073
+ const inner = s3.slice(1, -1);
182074
+ return inner.replace(/\\(["'])/g, "$1");
182075
+ }
182076
+ return s3;
182077
+ }
182078
+ function buildPieModel(text) {
182079
+ const errors = [];
182080
+ const lex = tokenize2(text);
182081
+ for (const e3 of lex.errors) {
182082
+ errors.push({
182083
+ line: e3.line ?? 1,
182084
+ column: e3.column ?? 1,
182085
+ message: e3.message,
182086
+ code: "PIE_LEX",
182087
+ severity: "error"
182088
+ });
182089
+ }
182090
+ parserInstance2.reset();
182091
+ parserInstance2.input = lex.tokens;
182092
+ const cst = parserInstance2.diagram();
182093
+ for (const e3 of parserInstance2.errors) {
182094
+ const t3 = e3.token;
182095
+ errors.push({
182096
+ line: t3?.startLine ?? 1,
182097
+ column: t3?.startColumn ?? 1,
182098
+ message: e3.message,
182099
+ code: "PIE_PARSE",
182100
+ severity: "error"
182101
+ });
182102
+ }
182103
+ const model = { title: void 0, showData: false, slices: [] };
182104
+ if (!cst || !cst.children)
182105
+ return { model, errors };
182106
+ if (cst.children.ShowDataKeyword && cst.children.ShowDataKeyword.length > 0) {
182107
+ model.showData = true;
182108
+ }
182109
+ const statements = cst.children.statement ?? [];
182110
+ for (const st of statements) {
182111
+ if (st.children?.titleStmt) {
182112
+ const tnode = st.children.titleStmt[0];
182113
+ const parts = [];
182114
+ const collect = (k3) => {
182115
+ const arr = tnode.children?.[k3] ?? [];
182116
+ for (const tok of arr)
182117
+ parts.push(unquote(tok.image));
182118
+ };
182119
+ collect("QuotedString");
182120
+ collect("Text");
182121
+ collect("NumberLiteral");
182122
+ const title = parts.join(" ").trim();
182123
+ if (title)
182124
+ model.title = title;
182125
+ } else if (st.children?.sliceStmt) {
182126
+ const snode = st.children.sliceStmt[0];
182127
+ const labelTok = snode.children?.sliceLabel?.[0]?.children?.QuotedString?.[0];
182128
+ const numTok = snode.children?.NumberLiteral?.[0];
182129
+ if (labelTok && numTok) {
182130
+ const label = unquote(labelTok.image).trim();
182131
+ const value = Number(numTok.image);
182132
+ if (!Number.isNaN(value)) {
182133
+ model.slices.push({ label, value });
182134
+ }
182135
+ }
182136
+ }
182137
+ }
182138
+ return { model, errors };
182139
+ }
182140
+ var init_pie_builder = __esm({
182141
+ "node_modules/@probelabs/maid/out/renderer/pie-builder.js"() {
182142
+ init_lexer3();
182143
+ init_parser3();
182144
+ }
182145
+ });
182146
+
182147
+ // node_modules/@probelabs/maid/out/renderer/pie-renderer.js
182148
+ function polarToCartesian(cx, cy, r3, angleRad) {
182149
+ return { x: cx + r3 * Math.cos(angleRad), y: cy + r3 * Math.sin(angleRad) };
182150
+ }
182151
+ function renderPie(model, opts = {}) {
182152
+ let width = Math.max(320, Math.floor(opts.width ?? 640));
182153
+ const height = Math.max(240, Math.floor(opts.height ?? 400));
182154
+ const pad = 24;
182155
+ const titleH = model.title ? 28 : 0;
182156
+ let cx = width / 2;
182157
+ const cy = (height + titleH) / 2 + (model.title ? 8 : 0);
182158
+ const baseRadius = Math.max(40, Math.min(width, height - titleH) / 2 - pad);
182159
+ const slices = model.slices.filter((s3) => Math.max(0, s3.value) > 0);
182160
+ const total = slices.reduce((a3, s3) => a3 + Math.max(0, s3.value), 0);
182161
+ const LEG_SW = 12;
182162
+ const LEG_GAP = 8;
182163
+ const LEG_VSPACE = 18;
182164
+ const legendItems = slices.map((s3) => `${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
182165
+ const legendTextWidth = legendItems.length ? Math.max(...legendItems.map((t3) => measureText(t3, 12))) : 0;
182166
+ const legendBlockWidth = legendItems.length ? LEG_SW + LEG_GAP + legendTextWidth + pad : 0;
182167
+ if (legendItems.length) {
182168
+ const neededWidth = pad + baseRadius * 2 + legendBlockWidth + pad;
182169
+ if (neededWidth > width)
182170
+ width = Math.ceil(neededWidth);
182171
+ }
182172
+ let radius = baseRadius;
182173
+ if (legendItems.length) {
182174
+ const leftPad = Math.max(pad, (width - legendBlockWidth - radius * 2) / 2);
182175
+ cx = leftPad + radius;
182176
+ }
182177
+ let start = -Math.PI / 2;
182178
+ let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`;
182179
+ svg += `
182180
+ <style>
182181
+ .pie-title { font-family: Arial, sans-serif; font-size: 16px; font-weight: 600; fill: #222; }
182182
+ .slice-label { font-family: Arial, sans-serif; font-size: 12px; fill: #222; dominant-baseline: middle; }
182183
+ .leader { stroke: #444; stroke-width: 1; fill: none; }
182184
+ .pieCircle { stroke: black; stroke-width: 2px; opacity: 0.7; }
182185
+ .pieOuterCircle { stroke: black; stroke-width: 2px; fill: none; }
182186
+ </style>`;
182187
+ if (model.title) {
182188
+ svg += `
182189
+ <text class="pie-title" x="${cx}" y="${pad + 8}" text-anchor="middle">${escapeXml(model.title)}</text>`;
182190
+ }
182191
+ svg += `
182192
+ <g class="pie" aria-label="pie">`;
182193
+ const minOutsideAngle = 0.35;
182194
+ slices.forEach((s3, i3) => {
182195
+ const pct = total > 0 ? Math.max(0, s3.value) / total : 0;
182196
+ const angle = 2 * Math.PI * pct;
182197
+ const end = start + angle;
182198
+ const large = angle > Math.PI ? 1 : 0;
182199
+ const c0 = polarToCartesian(cx, cy, radius, start);
182200
+ const c1 = polarToCartesian(cx, cy, radius, end);
182201
+ const d3 = [
182202
+ `M ${cx} ${cy}`,
182203
+ `L ${c0.x.toFixed(2)} ${c0.y.toFixed(2)}`,
182204
+ `A ${radius} ${radius} 0 ${large} 1 ${c1.x.toFixed(2)} ${c1.y.toFixed(2)}`,
182205
+ "Z"
182206
+ ].join(" ");
182207
+ const fill = s3.color || palette(i3);
182208
+ svg += `
182209
+ <path d="${d3}" class="pieCircle" fill="${fill}" />`;
182210
+ const mid = (start + end) / 2;
182211
+ const cos = Math.cos(mid);
182212
+ const sin = Math.sin(mid);
182213
+ const percentLabel = escapeXml(formatPercent(s3.value, total));
182214
+ if (angle < minOutsideAngle) {
182215
+ const r1 = radius * 0.9;
182216
+ const r22 = radius * 1.06;
182217
+ const p1 = polarToCartesian(cx, cy, r1, mid);
182218
+ const p22 = polarToCartesian(cx, cy, r22, mid);
182219
+ const hlen = 12;
182220
+ const anchorLeft = cos < 0;
182221
+ const hx = anchorLeft ? p22.x - hlen : p22.x + hlen;
182222
+ const hy = p22.y;
182223
+ svg += `
182224
+ <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)}" />`;
182225
+ const tx = anchorLeft ? hx - 2 : hx + 2;
182226
+ const tAnchor = anchorLeft ? "end" : "start";
182227
+ svg += `
182228
+ <text class="slice-label" x="${tx.toFixed(2)}" y="${hy.toFixed(2)}" text-anchor="${tAnchor}">${percentLabel}</text>`;
182229
+ } else {
182230
+ const lr = radius * 0.62;
182231
+ const lp = { x: cx + lr * cos, y: cy + lr * sin };
182232
+ const tAnchor = Math.abs(cos) < 0.2 ? "middle" : cos > 0 ? "start" : "end";
182233
+ const avail = lr;
182234
+ const textW = measureText(percentLabel, 12);
182235
+ const anchor = textW > avail * 1.2 ? "middle" : tAnchor;
182236
+ svg += `
182237
+ <text class="slice-label" x="${lp.x.toFixed(2)}" y="${lp.y.toFixed(2)}" text-anchor="${anchor}">${percentLabel}</text>`;
182238
+ }
182239
+ start = end;
182240
+ });
182241
+ const rimStroke = opts.rimStroke || "black";
182242
+ const rimWidth = opts.rimStrokeWidth != null ? String(opts.rimStrokeWidth) : "2px";
182243
+ svg += `
182244
+ </g>
182245
+ <circle class="pie-rim pieOuterCircle" cx="${cx}" cy="${cy}" r="${radius}" stroke="${rimStroke}" stroke-width="${rimWidth}" fill="none" />`;
182246
+ if (legendItems.length) {
182247
+ const legendX = cx + radius + pad / 2;
182248
+ const totalH = legendItems.length * LEG_VSPACE;
182249
+ let legendY = cy - totalH / 2 + 10;
182250
+ svg += `
182251
+ <g class="legend">`;
182252
+ slices.forEach((s3, i3) => {
182253
+ const y2 = legendY + i3 * LEG_VSPACE;
182254
+ const fill = s3.color || palette(i3);
182255
+ const text = escapeXml(`${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
182256
+ svg += `
182257
+ <rect x="${legendX}" y="${y2 - LEG_SW + 6}" width="${LEG_SW}" height="${LEG_SW}" fill="${fill}" stroke="${fill}" stroke-width="1" />`;
182258
+ svg += `
182259
+ <text class="slice-label legend-text" x="${legendX + LEG_SW + LEG_GAP}" y="${y2}" text-anchor="start">${text}</text>`;
182260
+ });
182261
+ svg += `
182262
+ </g>`;
182263
+ }
182264
+ svg += `
182265
+ </svg>`;
182266
+ return svg;
182267
+ }
182268
+ var init_pie_renderer = __esm({
182269
+ "node_modules/@probelabs/maid/out/renderer/pie-renderer.js"() {
182270
+ init_utils4();
182271
+ }
182272
+ });
182273
+
182274
+ // node_modules/@probelabs/maid/out/renderer/sequence-builder.js
182275
+ function textFromTokens(tokens) {
182276
+ if (!tokens || tokens.length === 0)
182277
+ return "";
182278
+ const parts = [];
182279
+ for (const t3 of tokens) {
182280
+ const img = t3.image;
182281
+ if (!img)
182282
+ continue;
182283
+ if (t3.tokenType && t3.tokenType.name === "QuotedString") {
182284
+ if (img.startsWith('"') && img.endsWith('"'))
182285
+ parts.push(img.slice(1, -1));
182286
+ else if (img.startsWith("'") && img.endsWith("'"))
182287
+ parts.push(img.slice(1, -1));
182288
+ else
182289
+ parts.push(img);
182290
+ } else {
182291
+ parts.push(img);
182292
+ }
182293
+ }
182294
+ return parts.join(" ").replace(/\s+/g, " ").trim();
182295
+ }
182296
+ function actorRefToText(refCst) {
182297
+ const ch = refCst.children || {};
182298
+ const toks = [];
182299
+ ["Identifier", "QuotedString", "NumberLiteral", "Text"].forEach((k3) => {
182300
+ const a3 = ch[k3];
182301
+ a3?.forEach((t3) => toks.push(t3));
182302
+ });
182303
+ toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
182304
+ return textFromTokens(toks);
182305
+ }
182306
+ function lineRemainderToText(lineRem) {
182307
+ if (!lineRem)
182308
+ return void 0;
182309
+ const ch = lineRem.children || {};
182310
+ const toks = [];
182311
+ const order = [
182312
+ "Identifier",
182313
+ "NumberLiteral",
182314
+ "QuotedString",
182315
+ "Text",
182316
+ "Plus",
182317
+ "Minus",
182318
+ "Comma",
182319
+ "Colon",
182320
+ "LParen",
182321
+ "RParen",
182322
+ "AndKeyword",
182323
+ "ElseKeyword",
182324
+ "OptKeyword",
182325
+ "OptionKeyword",
182326
+ "LoopKeyword",
182327
+ "ParKeyword",
182328
+ "RectKeyword",
182329
+ "CriticalKeyword",
182330
+ "BreakKeyword",
182331
+ "BoxKeyword",
182332
+ "EndKeyword",
182333
+ "NoteKeyword",
182334
+ "LeftKeyword",
182335
+ "RightKeyword",
182336
+ "OverKeyword",
182337
+ "OfKeyword",
182338
+ "AutonumberKeyword",
182339
+ "OffKeyword",
182340
+ "LinkKeyword",
182341
+ "LinksKeyword",
182342
+ "CreateKeyword",
182343
+ "DestroyKeyword",
182344
+ "ParticipantKeyword",
182345
+ "ActorKeyword",
182346
+ "ActivateKeyword",
182347
+ "DeactivateKeyword"
182348
+ ];
182349
+ for (const k3 of order)
182350
+ ch[k3]?.forEach((t3) => toks.push(t3));
182351
+ toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
182352
+ return textFromTokens(toks) || void 0;
182353
+ }
182354
+ function canonicalId(raw) {
182355
+ const t3 = raw.trim().replace(/\s+/g, "_");
182356
+ return t3;
182357
+ }
182358
+ function ensureParticipant(map4, byDisplay, idLike, display) {
182359
+ const idGuess = canonicalId(idLike);
182360
+ const existing = map4.get(idGuess) || (byDisplay.get(idLike) ? map4.get(byDisplay.get(idLike)) : void 0);
182361
+ if (existing)
182362
+ return existing;
182363
+ const p3 = { id: idGuess, display: display || idLike };
182364
+ map4.set(p3.id, p3);
182365
+ byDisplay.set(p3.display, p3.id);
182366
+ return p3;
182367
+ }
182368
+ function msgFromArrow(arrowCst) {
182369
+ const ch = arrowCst.children || {};
182370
+ if (ch.BidirAsyncDotted)
182371
+ return { line: "dotted", start: "arrow", end: "arrow", async: true };
182372
+ if (ch.BidirAsync)
182373
+ return { line: "solid", start: "arrow", end: "arrow", async: true };
182374
+ if (ch.DottedAsync)
182375
+ return { line: "dotted", start: "none", end: "arrow", async: true };
182376
+ if (ch.Async)
182377
+ return { line: "solid", start: "none", end: "arrow", async: true };
182378
+ if (ch.Dotted)
182379
+ return { line: "dotted", start: "none", end: "arrow" };
182380
+ if (ch.Solid)
182381
+ return { line: "solid", start: "none", end: "arrow" };
182382
+ if (ch.DottedCross)
182383
+ return { line: "dotted", start: "none", end: "cross" };
182384
+ if (ch.Cross)
182385
+ return { line: "solid", start: "none", end: "cross" };
182386
+ if (ch.DottedOpen)
182387
+ return { line: "dotted", start: "none", end: "open" };
182388
+ if (ch.Open)
182389
+ return { line: "solid", start: "none", end: "open" };
182390
+ return { line: "solid", start: "none", end: "arrow" };
182391
+ }
182392
+ function buildSequenceModel(text) {
182393
+ const { tokens } = tokenize3(text);
182394
+ parserInstance3.input = tokens;
182395
+ const cst = parserInstance3.diagram();
182396
+ const participantsMap = /* @__PURE__ */ new Map();
182397
+ const byDisplay = /* @__PURE__ */ new Map();
182398
+ const events = [];
182399
+ let autonumber = { on: false };
182400
+ const diagramChildren = cst.children || {};
182401
+ const lines = diagramChildren.line || [];
182402
+ const openBlocks = [];
182403
+ function processLineNode(ln) {
182404
+ const ch = ln.children || {};
182405
+ if (ch.participantDecl) {
182406
+ const decl = ch.participantDecl[0];
182407
+ const dch = decl.children || {};
182408
+ const ref1 = dch.actorRef?.[0];
182409
+ const ref2 = dch.actorRef?.[1];
182410
+ const idText = actorRefToText(ref1);
182411
+ const aliasText = ref2 ? actorRefToText(ref2) : void 0;
182412
+ const id = canonicalId(idText);
182413
+ const display = aliasText || idText;
182414
+ const p3 = ensureParticipant(participantsMap, byDisplay, id, display);
182415
+ events.push({ kind: "create", actor: p3.id, display: p3.display });
182416
+ return;
182417
+ }
182418
+ if (ch.autonumberStmt) {
182419
+ const stmt = ch.autonumberStmt[0];
182420
+ const sch = stmt.children || {};
182421
+ autonumber = { on: true };
182422
+ const nums = sch.NumberLiteral || [];
182423
+ if (nums.length >= 1)
182424
+ autonumber.start = Number(nums[0].image);
182425
+ if (nums.length >= 2)
182426
+ autonumber.step = Number(nums[1].image);
182427
+ if (sch.OffKeyword)
182428
+ autonumber = { on: false };
182429
+ return;
182430
+ }
182431
+ if (ch.activateStmt) {
182432
+ const st = ch.activateStmt[0];
182433
+ const sch = st.children || {};
182434
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
182435
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
182436
+ events.push({ kind: "activate", actor: p3.id });
182437
+ return;
182438
+ }
182439
+ if (ch.deactivateStmt) {
182440
+ const st = ch.deactivateStmt[0];
182441
+ const sch = st.children || {};
182442
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
182443
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
182444
+ events.push({ kind: "deactivate", actor: p3.id });
182445
+ return;
182446
+ }
182447
+ if (ch.createStmt) {
182448
+ const st = ch.createStmt[0];
182449
+ const sch = st.children || {};
182450
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
182451
+ const alias = sch.lineRemainder ? lineRemainderToText(sch.lineRemainder[0]) : void 0;
182452
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt, alias || idTxt);
182453
+ events.push({ kind: "create", actor: p3.id, display: p3.display });
182454
+ return;
182455
+ }
182456
+ if (ch.destroyStmt) {
182457
+ const st = ch.destroyStmt[0];
182458
+ const sch = st.children || {};
182459
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
182460
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
182461
+ events.push({ kind: "destroy", actor: p3.id });
182462
+ return;
182463
+ }
182464
+ if (ch.noteStmt) {
182465
+ const st = ch.noteStmt[0];
182466
+ const sch = st.children || {};
182467
+ const text2 = lineRemainderToText(sch.lineRemainder?.[0]) || "";
182468
+ if (sch.LeftKeyword || sch.RightKeyword) {
182469
+ const pos = sch.LeftKeyword ? "leftOf" : "rightOf";
182470
+ const actorTxt = actorRefToText(sch.actorRef?.[0]);
182471
+ const p3 = ensureParticipant(participantsMap, byDisplay, actorTxt);
182472
+ const note = { pos, actors: [p3.id], text: text2 };
182473
+ events.push({ kind: "note", note });
182474
+ } else if (sch.OverKeyword) {
182475
+ const a1 = actorRefToText(sch.actorRef?.[0]);
182476
+ const a22 = sch.actorRef?.[1] ? actorRefToText(sch.actorRef?.[1]) : void 0;
182477
+ const p1 = ensureParticipant(participantsMap, byDisplay, a1);
182478
+ const ids = [p1.id];
182479
+ if (a22) {
182480
+ const p22 = ensureParticipant(participantsMap, byDisplay, a22);
182481
+ ids.push(p22.id);
182482
+ }
182483
+ events.push({ kind: "note", note: { pos: "over", actors: ids, text: text2 } });
182484
+ }
182485
+ return;
182486
+ }
182487
+ const blockKinds = [
182488
+ { key: "altBlock", type: "alt", branchKeys: [{ key: "ElseKeyword", kind: "else" }] },
182489
+ { key: "optBlock", type: "opt" },
182490
+ { key: "loopBlock", type: "loop" },
182491
+ { key: "parBlock", type: "par", branchKeys: [{ key: "AndKeyword", kind: "and" }] },
182492
+ { key: "criticalBlock", type: "critical", branchKeys: [{ key: "OptionKeyword", kind: "option" }] },
182493
+ { key: "breakBlock", type: "break" },
182494
+ { key: "rectBlock", type: "rect" },
182495
+ { key: "boxBlock", type: "box" }
182496
+ ];
182497
+ let handledBlock = false;
182498
+ for (const spec of blockKinds) {
182499
+ if (ch[spec.key]) {
182500
+ handledBlock = true;
182501
+ const bnode = ch[spec.key][0];
182502
+ const bch = bnode.children || {};
182503
+ const title = lineRemainderToText(bch.lineRemainder?.[0]);
182504
+ const block = { type: spec.type, title, branches: spec.branchKeys ? [] : void 0 };
182505
+ openBlocks.push(block);
182506
+ events.push({ kind: "block-start", block });
182507
+ if (spec.branchKeys) {
182508
+ const newlines = bch.Newline || [];
182509
+ const branchKey = spec.branchKeys[0].key;
182510
+ const branchTokArr = bch[branchKey];
182511
+ const lrArr = bch.lineRemainder;
182512
+ if (branchTokArr && branchTokArr.length) {
182513
+ const lr = (lrArr || []).slice(1);
182514
+ for (let i3 = 0; i3 < branchTokArr.length; i3++) {
182515
+ const title2 = lr[i3] ? lineRemainderToText(lr[i3]) : void 0;
182516
+ const br = { kind: spec.branchKeys[0].kind, title: title2 };
182517
+ block.branches.push(br);
182518
+ events.push({ kind: "block-branch", block, branch: br });
182519
+ }
182520
+ }
182521
+ }
182522
+ events.push({ kind: "block-end", block });
182523
+ openBlocks.pop();
182524
+ break;
182525
+ }
182526
+ }
182527
+ if (handledBlock)
182528
+ return;
182529
+ if (ch.messageStmt) {
182530
+ const st = ch.messageStmt[0];
182531
+ const sch = st.children || {};
182532
+ const fromTxt = actorRefToText(sch.actorRef?.[0]);
182533
+ const toTxt = actorRefToText(sch.actorRef?.[1]);
182534
+ const from = ensureParticipant(participantsMap, byDisplay, fromTxt).id;
182535
+ const to = ensureParticipant(participantsMap, byDisplay, toTxt).id;
182536
+ const arrow = msgFromArrow(sch.arrow?.[0]);
182537
+ const text2 = lineRemainderToText(sch.lineRemainder?.[0]);
182538
+ const activateTarget = !!sch.Plus;
182539
+ const deactivateTarget = !!sch.Minus;
182540
+ const msg = { from, to, text: text2, line: arrow.line, startMarker: arrow.start, endMarker: arrow.end, async: arrow.async, activateTarget, deactivateTarget };
182541
+ events.push({ kind: "message", msg });
182542
+ return;
182543
+ }
182544
+ if (ch.linkStmt) {
182545
+ events.push({ kind: "noop" });
182546
+ return;
182547
+ }
182548
+ events.push({ kind: "noop" });
182549
+ }
182550
+ function collectInnerLines(blockNode) {
182551
+ const out = [];
182552
+ const ch = blockNode.children || {};
182553
+ for (const key of Object.keys(ch)) {
182554
+ const arr = ch[key];
182555
+ if (Array.isArray(arr)) {
182556
+ for (const node of arr) {
182557
+ if (node && typeof node === "object" && node.name === "line")
182558
+ out.push(node);
182559
+ }
182560
+ }
182561
+ }
182562
+ return out;
182563
+ }
182564
+ for (const ln of lines) {
182565
+ processLineNode(ln);
182566
+ const ch = ln.children || {};
182567
+ 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];
182568
+ if (block) {
182569
+ for (const inner of collectInnerLines(block))
182570
+ processLineNode(inner);
182571
+ }
182572
+ }
182573
+ return {
182574
+ participants: Array.from(participantsMap.values()),
182575
+ events,
182576
+ autonumber: autonumber.on === true || autonumber.on === false ? autonumber : { on: false }
182577
+ };
182578
+ }
182579
+ var init_sequence_builder = __esm({
182580
+ "node_modules/@probelabs/maid/out/renderer/sequence-builder.js"() {
182581
+ init_lexer4();
182582
+ init_parser4();
182583
+ }
182584
+ });
182585
+
182586
+ // node_modules/@probelabs/maid/out/renderer/sequence-layout.js
182587
+ function layoutSequence(model) {
182588
+ const order = [];
182589
+ const seen = /* @__PURE__ */ new Set();
182590
+ const partById = new Map(model.participants.map((p3) => [p3.id, p3]));
182591
+ function touch(id) {
182592
+ if (!seen.has(id)) {
182593
+ seen.add(id);
182594
+ order.push(id);
182595
+ }
182596
+ }
182597
+ for (const ev of model.events) {
182598
+ if (ev.kind === "message") {
182599
+ touch(ev.msg.from);
182600
+ touch(ev.msg.to);
182601
+ }
182602
+ if (ev.kind === "note") {
182603
+ ev.note.actors.forEach(touch);
182604
+ }
182605
+ if (ev.kind === "activate" || ev.kind === "deactivate" || ev.kind === "create" || ev.kind === "destroy")
182606
+ touch(ev.actor);
182607
+ }
182608
+ for (const p3 of model.participants)
182609
+ touch(p3.id);
182610
+ const participants = [];
182611
+ let x3 = MARGIN_X;
182612
+ for (const id of order) {
182613
+ const p3 = partById.get(id) || { id, display: id };
182614
+ const w3 = Math.max(COL_MIN, measureText(p3.display, ACTOR_FONT_SIZE) + ACTOR_PAD_X * 2);
182615
+ participants.push({ id, display: p3.display, x: x3, y: MARGIN_Y, width: w3, height: ACTOR_H });
182616
+ x3 += w3 + MARGIN_X;
182617
+ }
182618
+ const width = Math.max(320, x3);
182619
+ const rowIndexForEvent = /* @__PURE__ */ new Map();
182620
+ let row = 0;
182621
+ const openBlocks = [];
182622
+ function consumeRow(idx) {
182623
+ rowIndexForEvent.set(idx, row++);
182624
+ }
182625
+ model.events.forEach((ev, idx) => {
182626
+ switch (ev.kind) {
182627
+ case "message":
182628
+ consumeRow(idx);
182629
+ break;
182630
+ case "note":
182631
+ consumeRow(idx);
182632
+ break;
182633
+ case "block-start":
182634
+ openBlocks.push({ block: ev.block, startRow: row, branches: [] });
182635
+ consumeRow(idx);
182636
+ break;
182637
+ case "block-branch": {
182638
+ const top = openBlocks[openBlocks.length - 1];
182639
+ if (top)
182640
+ top.branches.push({ title: ev.branch.title, row });
182641
+ consumeRow(idx);
182642
+ break;
182643
+ }
182644
+ case "block-end":
182645
+ break;
182646
+ case "activate":
182647
+ case "deactivate":
182648
+ case "create":
182649
+ case "destroy":
182650
+ case "noop":
182651
+ break;
182652
+ }
182653
+ });
182654
+ const lifelineTop = MARGIN_Y + ACTOR_H + LIFELINE_GAP;
182655
+ const contentHeight = row * ROW_H;
182656
+ const height = lifelineTop + contentHeight + MARGIN_Y + ACTOR_H;
182657
+ const lifelines = participants.map((p3) => ({ x: p3.x + p3.width / 2, y1: lifelineTop, y2: height - MARGIN_Y - ACTOR_H }));
182658
+ function yForRow(r3) {
182659
+ return lifelineTop + r3 * ROW_H + ROW_H / 2;
182660
+ }
182661
+ const col = new Map(participants.map((p3) => [p3.id, p3]));
182662
+ const messages = [];
182663
+ const notes = [];
182664
+ const blocks = [];
182665
+ const activations = [];
182666
+ const actStack = /* @__PURE__ */ new Map();
182667
+ const startAct = (actor, r3) => {
182668
+ const arr = actStack.get(actor) || [];
182669
+ arr.push(r3);
182670
+ actStack.set(actor, arr);
182671
+ };
182672
+ const endAct = (actor, r3) => {
182673
+ const arr = actStack.get(actor) || [];
182674
+ const start = arr.pop();
182675
+ if (start != null) {
182676
+ const p3 = col.get(actor);
182677
+ if (p3) {
182678
+ activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(r3) - yForRow(start) });
182679
+ }
182680
+ }
182681
+ actStack.set(actor, arr);
182682
+ };
182683
+ const openForLayout = [];
182684
+ model.events.forEach((ev, idx) => {
182685
+ const r3 = rowIndexForEvent.has(idx) ? rowIndexForEvent.get(idx) : null;
182686
+ switch (ev.kind) {
182687
+ case "message": {
182688
+ const p1 = col.get(ev.msg.from), p22 = col.get(ev.msg.to);
182689
+ if (p1 && p22 && r3 != null) {
182690
+ const y2 = yForRow(r3);
182691
+ const x1 = p1.x + p1.width / 2;
182692
+ const x22 = p22.x + p22.width / 2;
182693
+ 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 });
182694
+ if (ev.msg.activateTarget)
182695
+ startAct(ev.msg.to, r3);
182696
+ if (ev.msg.deactivateTarget)
182697
+ endAct(ev.msg.to, r3);
182698
+ const top = openForLayout[openForLayout.length - 1];
182699
+ if (top)
182700
+ top.lastRow = r3;
182701
+ }
182702
+ break;
182703
+ }
182704
+ case "note": {
182705
+ if (r3 == null)
182706
+ break;
182707
+ const estLines = (text, width2) => {
182708
+ const charsPerLine = Math.max(8, Math.floor((width2 - NOTE_PAD * 2) / 7));
182709
+ const length = text ? text.length : 0;
182710
+ return Math.max(1, Math.ceil(length / charsPerLine));
182711
+ };
182712
+ const y2 = yForRow(r3) - NOTE_PAD;
182713
+ if (ev.note.pos === "over") {
182714
+ const [a3, b3] = ev.note.actors;
182715
+ const p1 = col.get(a3), p22 = b3 ? col.get(b3) : p1;
182716
+ if (p1 && p22) {
182717
+ const left = Math.min(p1.x + p1.width / 2, p22.x + p22.width / 2);
182718
+ const right = Math.max(p1.x + p1.width / 2, p22.x + p22.width / 2);
182719
+ const w3 = right - left + NOTE_PAD * 2;
182720
+ const lines = estLines(ev.note.text, w3);
182721
+ const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
182722
+ notes.push({ x: left - NOTE_PAD, y: y2, width: w3, height: h3, text: ev.note.text, anchor: "over" });
182723
+ }
182724
+ } else {
182725
+ const actor = ev.note.actors[0];
182726
+ const p3 = col.get(actor);
182727
+ if (p3) {
182728
+ const leftSide = ev.note.pos === "leftOf";
182729
+ const x4 = leftSide ? p3.x - NOTE_W - 10 : p3.x + p3.width + 10;
182730
+ const lines = estLines(ev.note.text, NOTE_W);
182731
+ const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
182732
+ notes.push({ x: x4, y: y2, width: NOTE_W, height: h3, text: ev.note.text, anchor: leftSide ? "left" : "right" });
182733
+ }
182734
+ }
182735
+ const top = openForLayout[openForLayout.length - 1];
182736
+ if (top && r3 != null)
182737
+ top.lastRow = r3;
182738
+ break;
182739
+ }
182740
+ case "activate":
182741
+ if (r3 != null)
182742
+ startAct(ev.actor, r3);
182743
+ break;
182744
+ case "deactivate":
182745
+ if (r3 != null)
182746
+ endAct(ev.actor, r3);
182747
+ break;
182748
+ case "block-start": {
182749
+ const startRow = r3 != null ? r3 : row;
182750
+ openForLayout.push({ block: ev.block, startRow, branches: [] });
182751
+ break;
182752
+ }
182753
+ case "block-branch": {
182754
+ const top = openForLayout[openForLayout.length - 1];
182755
+ if (top && r3 != null) {
182756
+ top.branches.push({ title: ev.branch.title, row: r3 });
182757
+ top.lastRow = r3;
182758
+ }
182759
+ break;
182760
+ }
182761
+ case "block-end": {
182762
+ const top = openForLayout.pop();
182763
+ if (top) {
182764
+ const first2 = participants.length > 0 ? participants[0] : void 0;
182765
+ const last2 = participants.length > 0 ? participants[participants.length - 1] : void 0;
182766
+ const left = first2 ? first2.x : MARGIN_X;
182767
+ const right = last2 ? last2.x + last2.width : left + 200;
182768
+ const yTop = yForRow(top.startRow) - ROW_H / 2 - (BLOCK_PAD + TITLE_EXTRA_TOP);
182769
+ const endRow = top.lastRow != null ? top.lastRow : top.startRow;
182770
+ const yBot = yForRow(endRow) + ROW_H / 2 + BLOCK_PAD;
182771
+ 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 };
182772
+ if (top.branches.length)
182773
+ layout.branches = top.branches.map((b3) => ({ title: b3.title, y: yForRow(b3.row) - ROW_H / 2 }));
182774
+ blocks.push(layout);
182775
+ }
182776
+ break;
182777
+ }
182778
+ default:
182779
+ break;
182780
+ }
182781
+ });
182782
+ const lastRow = row;
182783
+ for (const [actor, arr] of actStack.entries()) {
182784
+ while (arr.length) {
182785
+ const start = arr.pop();
182786
+ const p3 = col.get(actor);
182787
+ if (p3)
182788
+ activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(lastRow) - yForRow(start) });
182789
+ }
182790
+ }
182791
+ return { width, height, participants, lifelines, messages, notes, blocks, activations };
182792
+ }
182793
+ 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;
182794
+ var init_sequence_layout = __esm({
182795
+ "node_modules/@probelabs/maid/out/renderer/sequence-layout.js"() {
182796
+ init_utils4();
182797
+ MARGIN_X = 24;
182798
+ MARGIN_Y = 24;
182799
+ ACTOR_FONT_SIZE = 16;
182800
+ ACTOR_H = 32;
182801
+ LIFELINE_GAP = 4;
182802
+ ACTOR_PAD_X = 12;
182803
+ COL_MIN = 110;
182804
+ ROW_H = 36;
182805
+ NOTE_W = 160;
182806
+ NOTE_PAD = 8;
182807
+ BLOCK_PAD = 8;
182808
+ TITLE_EXTRA_TOP = 12;
182809
+ }
182810
+ });
182811
+
182812
+ // node_modules/@probelabs/maid/out/renderer/sequence-renderer.js
182813
+ function renderSequence(model, opts = {}) {
182814
+ const layout = layoutSequence(model);
182815
+ const svgParts = [];
182816
+ const width = Math.ceil(layout.width);
182817
+ const height = Math.ceil(layout.height);
182818
+ svgParts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width + 50}" height="${height + 40}" viewBox="-50 -10 ${width + 50} ${height + 40}">`);
182819
+ const sharedCss = buildSharedCss({
182820
+ fontFamily: "Arial, sans-serif",
182821
+ fontSize: 14,
182822
+ nodeFill: "#eef0ff",
182823
+ nodeStroke: "#3f3f3f",
182824
+ edgeStroke: "#555555"
182825
+ });
182826
+ svgParts.push(` <style>${sharedCss}</style>`);
182827
+ for (const p3 of layout.participants)
182828
+ drawParticipant(svgParts, p3);
182829
+ for (const b3 of layout.blocks)
182830
+ svgParts.push(blockBackground(b3.x, b3.y, b3.width, b3.height, 0));
182831
+ for (const l3 of layout.lifelines)
182832
+ svgParts.push(` <line class="lifeline" x1="${l3.x}" y1="${l3.y1}" x2="${l3.x}" y2="${l3.y2}"/>`);
182833
+ for (const a3 of layout.activations)
182834
+ svgParts.push(` <rect class="activation" x="${a3.x}" y="${a3.y}" width="${a3.width}" height="${a3.height}" />`);
182835
+ let counter = model.autonumber?.on ? model.autonumber.start ?? 1 : void 0;
182836
+ const step = model.autonumber?.on ? model.autonumber.step ?? 1 : void 0;
182837
+ for (const m3 of layout.messages) {
182838
+ drawMessage(svgParts, m3);
182839
+ const label = formatMessageLabel(m3.text, counter);
182840
+ if (label)
182841
+ drawMessageLabel(svgParts, m3, label, counter);
182842
+ if (counter != null)
182843
+ counter += step;
182844
+ }
182845
+ for (const n3 of layout.notes)
182846
+ drawNote(svgParts, n3);
182847
+ for (const b3 of layout.blocks) {
182848
+ const title = b3.title ? `${b3.type}: ${b3.title}` : b3.type;
182849
+ const branches = (b3.branches || []).map((br) => ({ y: br.y, title: br.title }));
182850
+ svgParts.push(blockOverlay(b3.x, b3.y, b3.width, b3.height, title, branches, 0, "left", "left", 0));
182851
+ }
182852
+ for (const p3 of layout.participants)
182853
+ drawParticipantBottom(svgParts, p3, layout);
182854
+ svgParts.push("</svg>");
182855
+ let svg = svgParts.join("\n");
182856
+ if (opts.theme)
182857
+ svg = applySequenceTheme(svg, opts.theme);
182858
+ return svg;
182859
+ }
182860
+ function drawParticipant(out, p3) {
182861
+ out.push(` <g class="actor" transform="translate(${p3.x},${p3.y})">`);
182862
+ out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
182863
+ out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
182864
+ out.push(" </g>");
182865
+ }
182866
+ function drawParticipantBottom(out, p3, layout) {
182867
+ const lifeline = layout.lifelines.find((l3) => Math.abs(l3.x - (p3.x + p3.width / 2)) < 1e-3);
182868
+ const y2 = lifeline ? lifeline.y2 : layout.height - 28;
182869
+ out.push(` <g class="actor" transform="translate(${p3.x},${y2})">`);
182870
+ out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
182871
+ out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
182872
+ out.push(" </g>");
182873
+ }
182874
+ function drawMessage(out, m3) {
182875
+ const cls = `msg-line ${m3.line}`.trim();
182876
+ const x1 = m3.x1, x22 = m3.x2, y2 = m3.y;
182877
+ out.push(` <path class="${cls}" d="M ${x1} ${y2} L ${x22} ${y2}" />`);
182878
+ const start = { x: x1, y: y2 };
182879
+ const end = { x: x22, y: y2 };
182880
+ if (m3.endMarker === "arrow")
182881
+ out.push(" " + triangleAtEnd(start, end));
182882
+ if (m3.startMarker === "arrow")
182883
+ out.push(" " + triangleAtStart(start, end));
182884
+ if (m3.endMarker === "open")
182885
+ out.push(` <circle class="openhead" cx="${x22}" cy="${y2}" r="4" />`);
182886
+ if (m3.startMarker === "open")
182887
+ out.push(` <circle class="openhead" cx="${x1}" cy="${y2}" r="4" />`);
182888
+ if (m3.endMarker === "cross")
182889
+ 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>`);
182890
+ if (m3.startMarker === "cross")
182891
+ 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>`);
182892
+ }
182893
+ function formatMessageLabel(text, counter) {
182894
+ if (!text && counter == null)
182895
+ return void 0;
182896
+ if (counter != null && text)
182897
+ return `${counter}: ${text}`;
182898
+ if (counter != null)
182899
+ return String(counter);
182900
+ return text;
182901
+ }
182902
+ function drawMessageLabel(out, m3, label, _counter) {
182903
+ const xMid = (m3.x1 + m3.x2) / 2;
182904
+ const h3 = 16;
182905
+ const w3 = Math.max(20, measureText(label, 12) + 10);
182906
+ const x3 = xMid - w3 / 2;
182907
+ const y2 = m3.y - 10 - h3 / 2;
182908
+ out.push(` <rect class="msg-label-bg" x="${x3}" y="${y2}" width="${w3}" height="${h3}" rx="0"/>`);
182909
+ out.push(` <text class="msg-label" x="${xMid}" y="${y2 + h3 / 2}" text-anchor="middle">${escapeXml(label)}</text>`);
182910
+ }
182911
+ function drawNote(out, n3) {
182912
+ out.push(` <g class="note" transform="translate(${n3.x},${n3.y})">`);
182913
+ out.push(` <rect width="${n3.width}" height="${n3.height}" rx="0"/>`);
182914
+ out.push(` <text class="note-text" x="${n3.width / 2}" y="${n3.height / 2 + 4}" text-anchor="middle">${escapeXml(n3.text)}</text>`);
182915
+ out.push(" </g>");
182916
+ }
182917
+ function applySequenceTheme(svg, theme) {
182918
+ let out = svg;
182919
+ if (theme.actorBkg)
182920
+ out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorBkg)};`));
182921
+ if (theme.actorBorder)
182922
+ out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.actorBorder)};`));
182923
+ if (theme.actorTextColor)
182924
+ out = out.replace(/\.actor-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorTextColor)};`));
182925
+ if (theme.lifelineColor)
182926
+ out = out.replace(/\.lifeline\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lifelineColor)};`));
182927
+ if (theme.lineColor)
182928
+ out = out.replace(/\.msg-line\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
182929
+ if (theme.arrowheadColor) {
182930
+ out = out.replace(/\.arrowhead\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.arrowheadColor)};`));
182931
+ out = out.replace(/\.openhead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
182932
+ out = out.replace(/\.crosshead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
182933
+ }
182934
+ if (theme.noteBkg)
182935
+ out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteBkg)};`));
182936
+ if (theme.noteBorder)
182937
+ out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.noteBorder)};`));
182938
+ if (theme.noteTextColor)
182939
+ out = out.replace(/\.note-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteTextColor)};`));
182940
+ if (theme.activationBkg)
182941
+ out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.activationBkg)};`));
182942
+ if (theme.activationBorder)
182943
+ out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.activationBorder)};`));
182944
+ return out;
182945
+ }
182946
+ var init_sequence_renderer = __esm({
182947
+ "node_modules/@probelabs/maid/out/renderer/sequence-renderer.js"() {
182948
+ init_sequence_layout();
182949
+ init_utils4();
182950
+ init_arrow_utils();
182951
+ init_block_utils();
182952
+ init_styles();
182953
+ }
182954
+ });
182955
+
182956
+ // node_modules/@probelabs/maid/out/core/frontmatter.js
182957
+ function parseFrontmatter(input) {
182958
+ const text = input.startsWith("\uFEFF") ? input.slice(1) : input;
182959
+ const lines = text.split(/\r?\n/);
182960
+ if (lines.length < 3 || lines[0].trim() !== "---")
182961
+ return null;
182962
+ let i3 = 1;
182963
+ const block = [];
182964
+ while (i3 < lines.length && lines[i3].trim() !== "---") {
182965
+ block.push(lines[i3]);
182966
+ i3++;
182967
+ }
182968
+ if (i3 >= lines.length)
182969
+ return null;
182970
+ const body = lines.slice(i3 + 1).join("\n");
182971
+ const raw = block.join("\n");
182972
+ const config = {};
182973
+ const themeVars = {};
182974
+ let themeUnderConfig = false;
182975
+ let ctx = "root";
182976
+ for (const line of block) {
182977
+ if (!line.trim())
182978
+ continue;
182979
+ const indent = line.match(/^\s*/)?.[0].length ?? 0;
182980
+ const mKey = line.match(/^\s*([A-Za-z0-9_\-]+):\s*(.*)$/);
182981
+ if (!mKey)
182982
+ continue;
182983
+ const key = mKey[1];
182984
+ let value = mKey[2] || "";
182985
+ if (indent === 0) {
182986
+ if (key === "config") {
182987
+ ctx = "config";
182988
+ continue;
182989
+ }
182990
+ if (key === "themeVariables") {
182991
+ ctx = "theme";
182992
+ continue;
182993
+ }
182994
+ ctx = "root";
182995
+ continue;
182996
+ }
182997
+ if (ctx === "config") {
182998
+ if (indent <= 2 && key !== "pie" && key !== "themeVariables")
182999
+ continue;
183000
+ if (key === "pie") {
183001
+ ctx = "config.pie";
183002
+ ensure(config, "pie", {});
183003
+ continue;
183004
+ }
183005
+ if (key === "themeVariables") {
183006
+ ctx = "theme";
183007
+ themeUnderConfig = true;
183008
+ continue;
183009
+ }
183010
+ continue;
183011
+ }
183012
+ if (ctx === "config.pie") {
183013
+ if (indent < 4) {
183014
+ if (key === "pie") {
183015
+ ctx = "config.pie";
183016
+ ensure(config, "pie", {});
183017
+ continue;
183018
+ }
183019
+ if (key === "themeVariables") {
183020
+ ctx = "theme";
183021
+ themeUnderConfig = true;
183022
+ continue;
183023
+ }
183024
+ ctx = "config";
183025
+ continue;
183026
+ }
183027
+ setKV(config.pie, key, value);
183028
+ continue;
183029
+ }
183030
+ if (ctx === "theme") {
183031
+ if (indent < 2) {
183032
+ ctx = "root";
183033
+ continue;
183034
+ }
183035
+ setKV(themeVars, key, value);
183036
+ continue;
183037
+ }
183038
+ }
183039
+ if (themeUnderConfig && Object.keys(themeVars).length) {
183040
+ ensure(config, "themeVariables", {});
183041
+ Object.assign(config.themeVariables, themeVars);
183042
+ }
183043
+ return { raw, body, config: Object.keys(config).length ? config : void 0, themeVariables: Object.keys(themeVars).length ? themeVars : void 0 };
183044
+ }
183045
+ function ensure(obj, key, def) {
183046
+ if (obj[key] == null)
183047
+ obj[key] = def;
183048
+ }
183049
+ function unquote2(val) {
183050
+ const v3 = val.trim();
183051
+ if (v3.startsWith('"') && v3.endsWith('"') || v3.startsWith("'") && v3.endsWith("'")) {
183052
+ return v3.slice(1, -1);
183053
+ }
183054
+ return v3;
183055
+ }
183056
+ function setKV(target, key, rawValue) {
183057
+ const v3 = unquote2(rawValue);
183058
+ if (v3 === "") {
183059
+ target[key] = "";
183060
+ return;
183061
+ }
183062
+ const num = Number(v3);
183063
+ if (!Number.isNaN(num) && /^-?[0-9]+(\.[0-9]+)?$/.test(v3)) {
183064
+ target[key] = num;
183065
+ return;
183066
+ }
183067
+ if (/^(true|false)$/i.test(v3)) {
183068
+ target[key] = /^true$/i.test(v3);
183069
+ return;
183070
+ }
183071
+ target[key] = v3;
183072
+ }
183073
+ var init_frontmatter = __esm({
183074
+ "node_modules/@probelabs/maid/out/core/frontmatter.js"() {
179980
183075
  }
179981
183076
  });
179982
183077
 
@@ -179987,6 +183082,102 @@ var init_dot_renderer = __esm({
179987
183082
  });
179988
183083
 
179989
183084
  // node_modules/@probelabs/maid/out/renderer/index.js
183085
+ function applyPieTheme(svg, theme) {
183086
+ if (!theme)
183087
+ return svg;
183088
+ let out = svg;
183089
+ if (theme.pieOuterStrokeWidth != null || theme.pieStrokeColor) {
183090
+ out = out.replace(/\.pieOuterCircle\s*\{[^}]*\}/, (m3) => {
183091
+ let rule = m3;
183092
+ if (theme.pieStrokeColor)
183093
+ rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`);
183094
+ if (theme.pieOuterStrokeWidth != null)
183095
+ rule = rule.replace(/stroke-width:\s*[^;]+;/, `stroke-width: ${String(theme.pieOuterStrokeWidth)};`);
183096
+ return rule;
183097
+ });
183098
+ if (theme.pieStrokeColor) {
183099
+ out = out.replace(/\.pieCircle\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`));
183100
+ }
183101
+ }
183102
+ if (theme.pieSectionTextColor) {
183103
+ const c3 = String(theme.pieSectionTextColor);
183104
+ out = out.replace(/\.slice-label \{[^}]*\}/, (m3) => m3.replace(/fill:\s*#[0-9A-Fa-f]{3,8}|fill:\s*rgb\([^)]*\)/, `fill: ${c3}`));
183105
+ out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 fill="${c3}">`);
183106
+ }
183107
+ if (theme.pieTitleTextColor) {
183108
+ const c3 = String(theme.pieTitleTextColor);
183109
+ out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 fill="${c3}">`);
183110
+ }
183111
+ if (theme.pieSectionTextSize) {
183112
+ const size = String(theme.pieSectionTextSize);
183113
+ out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 font-size="${size}">`);
183114
+ }
183115
+ if (theme.pieTitleTextSize) {
183116
+ const size = String(theme.pieTitleTextSize);
183117
+ out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 font-size="${size}">`);
183118
+ }
183119
+ const colors = [];
183120
+ for (let i3 = 1; i3 <= 24; i3++) {
183121
+ const key = "pie" + i3;
183122
+ if (theme[key])
183123
+ colors.push(String(theme[key]));
183124
+ }
183125
+ if (colors.length) {
183126
+ let idx = 0;
183127
+ out = out.replace(/<path[^>]*class="pieCircle"[^>]*\sfill="([^"]+)"/g, (_m2) => {
183128
+ const color = colors[idx] ?? null;
183129
+ idx++;
183130
+ if (color)
183131
+ return _m2.replace(/fill="([^"]+)"/, `fill="${color}"`);
183132
+ return _m2;
183133
+ });
183134
+ }
183135
+ return out;
183136
+ }
183137
+ function applyFlowchartTheme(svg, theme) {
183138
+ if (!theme)
183139
+ return svg;
183140
+ let out = svg;
183141
+ if (theme.nodeBkg || theme.nodeBorder) {
183142
+ out = out.replace(/\.node-shape\s*\{[^}]*\}/, (m3) => {
183143
+ let rule = m3;
183144
+ if (theme.nodeBkg)
183145
+ rule = rule.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeBkg)};`);
183146
+ if (theme.nodeBorder)
183147
+ rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.nodeBorder)};`);
183148
+ return rule;
183149
+ });
183150
+ }
183151
+ if (theme.nodeTextColor) {
183152
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeTextColor)};`));
183153
+ }
183154
+ if (theme.lineColor) {
183155
+ out = out.replace(/\.edge-path\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
183156
+ }
183157
+ if (theme.arrowheadColor) {
183158
+ 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)}"`);
183159
+ out = out.replace(/(<circle cx="4\.5" cy="4\.5" r="4\.5"[^>]*)(fill="[^"]*")/g, (_m2, p1) => `${p1}fill="${String(theme.arrowheadColor)}"`);
183160
+ }
183161
+ if (theme.clusterBkg) {
183162
+ out = out.replace(/\.cluster-bg\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterBkg)};`));
183163
+ }
183164
+ if (theme.clusterBorder) {
183165
+ out = out.replace(/\.cluster-border\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.clusterBorder)};`));
183166
+ }
183167
+ if (theme.clusterTextColor) {
183168
+ out = out.replace(/\.cluster-label-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterTextColor)};`));
183169
+ }
183170
+ if (theme.fontFamily)
183171
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-family:\s*[^;]+;/, `font-family: ${String(theme.fontFamily)};`));
183172
+ if (theme.fontSize)
183173
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-size:\s*[^;]+;/, `font-size: ${String(theme.fontSize)};`));
183174
+ return out;
183175
+ }
183176
+ function renderMermaid(text, options = {}) {
183177
+ const renderer = new MermaidRenderer(options.layoutEngine, options.renderer);
183178
+ return renderer.renderAny(text, options);
183179
+ }
183180
+ var MermaidRenderer;
179990
183181
  var init_renderer = __esm({
179991
183182
  "node_modules/@probelabs/maid/out/renderer/index.js"() {
179992
183183
  init_lexer2();
@@ -179994,9 +183185,244 @@ var init_renderer = __esm({
179994
183185
  init_graph_builder();
179995
183186
  init_layout();
179996
183187
  init_svg_generator();
183188
+ init_pie_builder();
183189
+ init_pie_renderer();
183190
+ init_sequence_builder();
183191
+ init_sequence_renderer();
183192
+ init_frontmatter();
179997
183193
  init_layout();
179998
183194
  init_svg_generator();
179999
183195
  init_dot_renderer();
183196
+ MermaidRenderer = class {
183197
+ constructor(layoutEngine, renderer) {
183198
+ this.graphBuilder = new GraphBuilder();
183199
+ this.layoutEngine = layoutEngine || new DagreLayoutEngine();
183200
+ this.renderer = renderer || new SVGRenderer();
183201
+ }
183202
+ /**
183203
+ * Renders a Mermaid flowchart diagram
183204
+ */
183205
+ render(text, options = {}) {
183206
+ const errors = [];
183207
+ const layoutEngine = options.layoutEngine || this.layoutEngine;
183208
+ const renderer = options.renderer || this.renderer;
183209
+ try {
183210
+ const lexResult = tokenize(text);
183211
+ if (lexResult.errors && lexResult.errors.length > 0) {
183212
+ for (const error2 of lexResult.errors) {
183213
+ errors.push({
183214
+ line: error2.line || 1,
183215
+ column: error2.column || 1,
183216
+ message: error2.message,
183217
+ severity: "error",
183218
+ code: "LEXER_ERROR"
183219
+ });
183220
+ }
183221
+ }
183222
+ parserInstance.reset();
183223
+ parserInstance.input = lexResult.tokens;
183224
+ const cst = parserInstance.diagram();
183225
+ if (parserInstance.errors && parserInstance.errors.length > 0) {
183226
+ for (const error2 of parserInstance.errors) {
183227
+ const token = error2.token;
183228
+ errors.push({
183229
+ line: token?.startLine || 1,
183230
+ column: token?.startColumn || 1,
183231
+ message: error2.message,
183232
+ severity: "error",
183233
+ code: "PARSER_ERROR"
183234
+ });
183235
+ }
183236
+ }
183237
+ const graph = this.graphBuilder.build(cst);
183238
+ let layout;
183239
+ try {
183240
+ layout = layoutEngine.layout(graph);
183241
+ } catch (layoutError) {
183242
+ errors.push({
183243
+ line: 1,
183244
+ column: 1,
183245
+ message: layoutError.message || "Layout calculation failed",
183246
+ severity: "error",
183247
+ code: "LAYOUT_ERROR"
183248
+ });
183249
+ return {
183250
+ svg: this.generateErrorSvg(layoutError.message || "Layout calculation failed"),
183251
+ graph,
183252
+ errors
183253
+ };
183254
+ }
183255
+ let svg = renderer.render(layout);
183256
+ if (options.showErrors && errors.length > 0) {
183257
+ svg = this.addErrorOverlays(svg, errors);
183258
+ }
183259
+ return {
183260
+ svg,
183261
+ graph,
183262
+ errors
183263
+ };
183264
+ } catch (error2) {
183265
+ const errorSvg = this.generateErrorSvg(error2.message || "Unknown error occurred");
183266
+ errors.push({
183267
+ line: 1,
183268
+ column: 1,
183269
+ message: error2.message || "Unknown error occurred",
183270
+ severity: "error",
183271
+ code: "RENDER_ERROR"
183272
+ });
183273
+ return {
183274
+ svg: errorSvg,
183275
+ graph: { nodes: [], edges: [], direction: "TD" },
183276
+ errors
183277
+ };
183278
+ }
183279
+ }
183280
+ /**
183281
+ * Renders supported diagram types (flowchart + pie for now)
183282
+ */
183283
+ renderAny(text, options = {}) {
183284
+ let content = text;
183285
+ let theme;
183286
+ if (text.trimStart().startsWith("---")) {
183287
+ const fm = parseFrontmatter(text);
183288
+ if (fm) {
183289
+ content = fm.body;
183290
+ theme = fm.themeVariables || fm.config && fm.config.themeVariables || void 0;
183291
+ }
183292
+ }
183293
+ const firstLine = content.trim().split("\n")[0];
183294
+ if (/^(flowchart|graph)\s+/i.test(firstLine)) {
183295
+ const res = this.render(content, options);
183296
+ const svg2 = theme ? applyFlowchartTheme(res.svg, theme) : res.svg;
183297
+ return { svg: svg2, graph: res.graph, errors: res.errors };
183298
+ }
183299
+ if (/^pie\b/i.test(firstLine)) {
183300
+ try {
183301
+ const { model, errors } = buildPieModel(content);
183302
+ const svg = renderPie(model, {
183303
+ width: options.width,
183304
+ height: options.height,
183305
+ rimStroke: theme?.pieStrokeColor,
183306
+ rimStrokeWidth: theme?.pieOuterStrokeWidth
183307
+ });
183308
+ const themedSvg = applyPieTheme(svg, theme);
183309
+ return { svg: themedSvg, graph: { nodes: [], edges: [], direction: "TD" }, errors };
183310
+ } catch (e3) {
183311
+ const msg = e3?.message || "Pie render error";
183312
+ const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "PIE_RENDER" }];
183313
+ return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
183314
+ }
183315
+ }
183316
+ if (/^sequenceDiagram\b/.test(firstLine)) {
183317
+ try {
183318
+ const model = buildSequenceModel(content);
183319
+ const svg = renderSequence(model, { theme });
183320
+ return { svg, graph: { nodes: [], edges: [], direction: "TD" }, errors: [] };
183321
+ } catch (e3) {
183322
+ const msg = e3?.message || "Sequence render error";
183323
+ const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "SEQUENCE_RENDER" }];
183324
+ return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
183325
+ }
183326
+ }
183327
+ const errorSvg = this.generateErrorSvg("Unsupported diagram type. Rendering supports flowchart, pie, and sequence for now.");
183328
+ return {
183329
+ svg: errorSvg,
183330
+ graph: { nodes: [], edges: [], direction: "TD" },
183331
+ errors: [{
183332
+ line: 1,
183333
+ column: 1,
183334
+ message: "Unsupported diagram type",
183335
+ severity: "error",
183336
+ code: "UNSUPPORTED_TYPE"
183337
+ }]
183338
+ };
183339
+ }
183340
+ addErrorOverlays(svg, errors) {
183341
+ const errorStyle = `
183342
+ <style>
183343
+ .error-indicator {
183344
+ fill: #ff0000;
183345
+ opacity: 0.8;
183346
+ }
183347
+ .error-text {
183348
+ fill: white;
183349
+ font-family: Arial, sans-serif;
183350
+ font-size: 12px;
183351
+ font-weight: bold;
183352
+ }
183353
+ </style>`;
183354
+ const errorIndicator = `
183355
+ <g id="errors">
183356
+ <rect x="5" y="5" width="100" height="25" rx="3" class="error-indicator" />
183357
+ <text x="55" y="20" text-anchor="middle" class="error-text">${errors.length} error${errors.length !== 1 ? "s" : ""}</text>
183358
+ </g>`;
183359
+ return svg.replace("</svg>", `${errorStyle}${errorIndicator}</svg>`);
183360
+ }
183361
+ generateErrorSvg(message) {
183362
+ const width = 400;
183363
+ const height = 200;
183364
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
183365
+ <rect width="${width}" height="${height}" fill="#fee" stroke="#c00" stroke-width="2" />
183366
+ <text x="${width / 2}" y="${height / 2 - 20}" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#c00">
183367
+ Render Error
183368
+ </text>
183369
+ <text x="${width / 2}" y="${height / 2 + 10}" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#666">
183370
+ ${this.wrapText(message, 40).map((line, i3) => `<tspan x="${width / 2}" dy="${i3 === 0 ? 0 : 15}">${this.escapeXml(line)}</tspan>`).join("")}
183371
+ </text>
183372
+ </svg>`;
183373
+ }
183374
+ wrapText(text, maxLength) {
183375
+ const words = text.split(" ");
183376
+ const lines = [];
183377
+ let currentLine = "";
183378
+ for (const word of words) {
183379
+ if (currentLine.length + word.length + 1 <= maxLength) {
183380
+ currentLine += (currentLine ? " " : "") + word;
183381
+ } else {
183382
+ if (currentLine)
183383
+ lines.push(currentLine);
183384
+ currentLine = word;
183385
+ }
183386
+ }
183387
+ if (currentLine)
183388
+ lines.push(currentLine);
183389
+ return lines.slice(0, 3);
183390
+ }
183391
+ escapeXml(text) {
183392
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
183393
+ }
183394
+ };
183395
+ }
183396
+ });
183397
+
183398
+ // node_modules/@probelabs/maid/out/mermaid-compat.js
183399
+ function createMermaidAPI() {
183400
+ return {
183401
+ initialize(_config) {
183402
+ },
183403
+ async render(_id, text, options) {
183404
+ try {
183405
+ const result = renderMermaid(text, options);
183406
+ return { svg: result.svg };
183407
+ } catch (error2) {
183408
+ throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
183409
+ }
183410
+ },
183411
+ renderSync(_id, text, options) {
183412
+ try {
183413
+ const result = renderMermaid(text, options);
183414
+ return { svg: result.svg };
183415
+ } catch (error2) {
183416
+ throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
183417
+ }
183418
+ }
183419
+ };
183420
+ }
183421
+ var maid;
183422
+ var init_mermaid_compat = __esm({
183423
+ "node_modules/@probelabs/maid/out/mermaid-compat.js"() {
183424
+ init_renderer();
183425
+ maid = createMermaidAPI();
180000
183426
  }
180001
183427
  });
180002
183428
 
@@ -180030,6 +183456,7 @@ var init_out = __esm({
180030
183456
  init_edits();
180031
183457
  init_fixes();
180032
183458
  init_renderer();
183459
+ init_mermaid_compat();
180033
183460
  init_router();
180034
183461
  init_fixes();
180035
183462
  init_edits();
@@ -213361,7 +216788,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
213361
216788
  /***/ ((module) => {
213362
216789
 
213363
216790
  "use strict";
213364
- module.exports = {"rE":"0.1.71"};
216791
+ module.exports = {"rE":"0.1.72"};
213365
216792
 
213366
216793
  /***/ })
213367
216794