@probelabs/probe 0.6.0-rc115 → 0.6.0-rc117

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/cjs/index.cjs CHANGED
@@ -30339,14 +30339,53 @@ var init_probeTool = __esm({
30339
30339
  if (!targetDir.startsWith(secureBaseDir + import_path7.default.sep) && targetDir !== secureBaseDir) {
30340
30340
  throw new Error("Path traversal attempt detected. Access denied.");
30341
30341
  }
30342
+ const debug = process.env.DEBUG === "1";
30343
+ if (debug) {
30344
+ console.log(`[DEBUG] Listing files in directory: ${targetDir}`);
30345
+ }
30342
30346
  try {
30343
- const files = await listFilesByLevel({
30344
- directory: targetDir,
30345
- maxFiles: 100,
30346
- respectGitignore: !process.env.PROBE_NO_GITIGNORE || process.env.PROBE_NO_GITIGNORE === "",
30347
- cwd: secureBaseDir
30347
+ const files = await import_fs4.promises.readdir(targetDir, { withFileTypes: true });
30348
+ const formatSize = (size) => {
30349
+ if (size < 1024) return `${size}B`;
30350
+ if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)}K`;
30351
+ if (size < 1024 * 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)}M`;
30352
+ return `${(size / (1024 * 1024 * 1024)).toFixed(1)}G`;
30353
+ };
30354
+ const entries = await Promise.all(files.map(async (file) => {
30355
+ const isDirectory = file.isDirectory();
30356
+ const fullPath = import_path7.default.join(targetDir, file.name);
30357
+ let size = 0;
30358
+ try {
30359
+ const stats = await import_fs4.promises.stat(fullPath);
30360
+ size = stats.size;
30361
+ } catch (statError) {
30362
+ if (debug) {
30363
+ console.log(`[DEBUG] Could not stat file ${file.name}:`, statError.message);
30364
+ }
30365
+ }
30366
+ return {
30367
+ name: file.name,
30368
+ isDirectory,
30369
+ size
30370
+ };
30371
+ }));
30372
+ entries.sort((a3, b3) => {
30373
+ if (a3.isDirectory && !b3.isDirectory) return -1;
30374
+ if (!a3.isDirectory && b3.isDirectory) return 1;
30375
+ return a3.name.localeCompare(b3.name);
30348
30376
  });
30349
- return files;
30377
+ const formatted = entries.map((entry) => {
30378
+ const type = entry.isDirectory ? "dir " : "file";
30379
+ const sizeStr = formatSize(entry.size).padStart(8);
30380
+ return `${type} ${sizeStr} ${entry.name}`;
30381
+ });
30382
+ if (debug) {
30383
+ console.log(`[DEBUG] Found ${entries.length} files/directories in ${targetDir}`);
30384
+ }
30385
+ const header = `${targetDir}:
30386
+ `;
30387
+ const output = header + formatted.join("\n");
30388
+ return output;
30350
30389
  } catch (error2) {
30351
30390
  throw new Error(`Failed to list files: ${error2.message}`);
30352
30391
  }
@@ -30364,6 +30403,9 @@ var init_probeTool = __esm({
30364
30403
  if (!targetDir.startsWith(secureBaseDir + import_path7.default.sep) && targetDir !== secureBaseDir) {
30365
30404
  throw new Error("Path traversal attempt detected. Access denied.");
30366
30405
  }
30406
+ if (pattern.includes("**/**") || pattern.split("*").length > 10) {
30407
+ throw new Error("Pattern too complex. Please use a simpler glob pattern.");
30408
+ }
30367
30409
  try {
30368
30410
  const options = {
30369
30411
  cwd: targetDir,
@@ -30373,7 +30415,17 @@ var init_probeTool = __esm({
30373
30415
  if (!recursive) {
30374
30416
  options.deep = 1;
30375
30417
  }
30376
- const files = await (0, import_glob.glob)(pattern, options);
30418
+ const timeoutPromise = new Promise((_2, reject2) => {
30419
+ setTimeout(() => reject2(new Error("Search operation timed out after 10 seconds")), 1e4);
30420
+ });
30421
+ const files = await Promise.race([
30422
+ (0, import_glob.glob)(pattern, options),
30423
+ timeoutPromise
30424
+ ]);
30425
+ const maxResults = 1e3;
30426
+ if (files.length > maxResults) {
30427
+ return files.slice(0, maxResults);
30428
+ }
30377
30429
  return files;
30378
30430
  } catch (error2) {
30379
30431
  throw new Error(`Failed to search files: ${error2.message}`);
@@ -41691,13 +41743,14 @@ function tokenize(text) {
41691
41743
  const lexResult = MermaidLexer.tokenize(text);
41692
41744
  return lexResult;
41693
41745
  }
41694
- 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;
41746
+ 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;
41695
41747
  var init_lexer2 = __esm({
41696
41748
  "node_modules/@probelabs/maid/out/diagrams/flowchart/lexer.js"() {
41697
41749
  init_api5();
41698
41750
  Identifier = createToken({
41699
41751
  name: "Identifier",
41700
- pattern: /[a-zA-Z_][a-zA-Z0-9_-]*/
41752
+ // e.g., id-2, _id, A1, but not A-- (that belongs to an arrow token)
41753
+ pattern: /[a-zA-Z_][a-zA-Z0-9_]*(?:-[a-zA-Z0-9_]+)*/
41701
41754
  });
41702
41755
  NumberLiteral = createToken({
41703
41756
  name: "NumberLiteral",
@@ -41838,6 +41891,8 @@ var init_lexer2 = __esm({
41838
41891
  AngleOpen = createToken({ name: "AngleOpen", pattern: />/ });
41839
41892
  AngleLess = createToken({ name: "AngleLess", pattern: /</ });
41840
41893
  Pipe = createToken({ name: "Pipe", pattern: /\|/ });
41894
+ ForwardSlash = createToken({ name: "ForwardSlash", pattern: /\// });
41895
+ Backslash = createToken({ name: "Backslash", pattern: /\\/ });
41841
41896
  QuotedString = createToken({
41842
41897
  name: "QuotedString",
41843
41898
  // Allow escaped characters within quotes (Mermaid accepts \" inside "...")
@@ -41921,6 +41976,8 @@ var init_lexer2 = __esm({
41921
41976
  DiamondClose,
41922
41977
  AngleOpen,
41923
41978
  AngleLess,
41979
+ ForwardSlash,
41980
+ Backslash,
41924
41981
  Pipe,
41925
41982
  TripleColon,
41926
41983
  Ampersand,
@@ -42113,6 +42170,8 @@ var init_parser2 = __esm({
42113
42170
  // Allow HTML-like tags (e.g., <br/>) inside labels
42114
42171
  { ALT: () => this.CONSUME(AngleLess) },
42115
42172
  { ALT: () => this.CONSUME(AngleOpen) },
42173
+ { ALT: () => this.CONSUME(ForwardSlash) },
42174
+ { ALT: () => this.CONSUME(Backslash) },
42116
42175
  { ALT: () => this.CONSUME(Comma) },
42117
42176
  { ALT: () => this.CONSUME(Colon) },
42118
42177
  // HTML entities and ampersands inside labels
@@ -43161,6 +43220,66 @@ ${br.example}`,
43161
43220
  length: len
43162
43221
  };
43163
43222
  }
43223
+ if (inRule("boxBlock") && (err.name === "NoViableAltException" || err.name === "MismatchedTokenException")) {
43224
+ const isMessage = /->|-->>|-->/.test(ltxt);
43225
+ const isNote = /note\s+(left|right|over)/i.test(ltxt);
43226
+ const isActivate = /activate\s+/i.test(ltxt);
43227
+ const isDeactivate = /deactivate\s+/i.test(ltxt);
43228
+ if (isMessage || isNote || isActivate || isDeactivate || tokType === "NoteKeyword" || tokType === "ActivateKeyword" || tokType === "DeactivateKeyword") {
43229
+ const lines2 = text.split(/\r?\n/);
43230
+ const boxLine = Math.max(0, line - 1);
43231
+ let hasEnd = false;
43232
+ let openIdx = -1;
43233
+ for (let i3 = boxLine; i3 >= 0; i3--) {
43234
+ if (/^\s*box\b/.test(lines2[i3] || "")) {
43235
+ openIdx = i3;
43236
+ break;
43237
+ }
43238
+ }
43239
+ if (openIdx !== -1) {
43240
+ for (let i3 = boxLine; i3 < lines2.length; i3++) {
43241
+ if (/^\s*end\s*$/.test(lines2[i3] || "")) {
43242
+ hasEnd = true;
43243
+ break;
43244
+ }
43245
+ if (i3 > boxLine && /^\s*(sequenceDiagram|box|alt|opt|loop|par|rect|critical|break)\b/.test(lines2[i3] || ""))
43246
+ break;
43247
+ }
43248
+ }
43249
+ if (hasEnd) {
43250
+ let hasParticipants = false;
43251
+ for (let i3 = openIdx + 1; i3 < lines2.length; i3++) {
43252
+ const raw = lines2[i3] || "";
43253
+ if (/^\s*end\s*$/.test(raw))
43254
+ break;
43255
+ if (/^\s*(participant|actor)\b/i.test(raw)) {
43256
+ hasParticipants = true;
43257
+ break;
43258
+ }
43259
+ }
43260
+ if (!hasParticipants) {
43261
+ return {
43262
+ line: openIdx + 1,
43263
+ column: 1,
43264
+ severity: "error",
43265
+ code: "SE-BOX-EMPTY",
43266
+ message: "Box block has no participant/actor declarations. Use 'rect' to group messages visually.",
43267
+ 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",
43268
+ length: 3
43269
+ };
43270
+ }
43271
+ return {
43272
+ line,
43273
+ column,
43274
+ severity: "error",
43275
+ code: "SE-BOX-INVALID-CONTENT",
43276
+ message: "Box blocks can only contain participant/actor declarations.",
43277
+ hint: 'Move messages, notes, and other statements outside the box block.\nExample:\nbox "Group"\n participant A\n participant B\nend\nA->>B: Message',
43278
+ length: len
43279
+ };
43280
+ }
43281
+ }
43282
+ }
43164
43283
  const blockRules = [
43165
43284
  { rule: "altBlock", label: "alt" },
43166
43285
  { rule: "optBlock", label: "opt" },
@@ -44060,9 +44179,15 @@ var init_parser4 = __esm({
44060
44179
  this.CONSUME(BoxKeyword);
44061
44180
  this.OPTION(() => this.SUBRULE(this.lineRemainder));
44062
44181
  this.AT_LEAST_ONE(() => this.CONSUME(Newline3));
44063
- this.MANY(() => this.SUBRULE(this.line));
44182
+ this.MANY(() => this.OR([
44183
+ { ALT: () => this.SUBRULE(this.participantDecl) },
44184
+ { ALT: () => this.SUBRULE(this.blankLine) }
44185
+ ]));
44064
44186
  this.CONSUME(EndKeyword2);
44065
- this.AT_LEAST_ONE2(() => this.CONSUME2(Newline3));
44187
+ this.OR2([
44188
+ { ALT: () => this.AT_LEAST_ONE2(() => this.CONSUME2(Newline3)) },
44189
+ { ALT: () => this.CONSUME2(EOF) }
44190
+ ]);
44066
44191
  });
44067
44192
  this.lineRemainder = this.RULE("lineRemainder", () => {
44068
44193
  this.AT_LEAST_ONE(() => this.OR([
@@ -45613,6 +45738,69 @@ function computeFixes(text, errors, level = "safe") {
45613
45738
  edits.push(replaceRange(text, at(e3), e3.length ?? 4, "option"));
45614
45739
  continue;
45615
45740
  }
45741
+ if (is("SE-BOX-EMPTY", e3)) {
45742
+ const lines = text.split(/\r?\n/);
45743
+ const boxIdx = Math.max(0, e3.line - 1);
45744
+ const boxLine = lines[boxIdx] || "";
45745
+ const labelMatch = /^\s*box\s+(.+)$/.exec(boxLine);
45746
+ if (labelMatch) {
45747
+ const indent = boxLine.match(/^\s*/)?.[0] || "";
45748
+ const newLine = `${indent}rect rgb(240, 240, 255)`;
45749
+ edits.push({ start: { line: e3.line, column: 1 }, end: { line: e3.line, column: boxLine.length + 1 }, newText: newLine });
45750
+ }
45751
+ continue;
45752
+ }
45753
+ if (is("SE-BOX-INVALID-CONTENT", e3)) {
45754
+ const lines = text.split(/\r?\n/);
45755
+ const curIdx = Math.max(0, e3.line - 1);
45756
+ const boxRe = /^(\s*)box\b/;
45757
+ let openIdx = -1;
45758
+ let openIndent = "";
45759
+ for (let i3 = curIdx; i3 >= 0; i3--) {
45760
+ const m3 = boxRe.exec(lines[i3] || "");
45761
+ if (m3) {
45762
+ openIdx = i3;
45763
+ openIndent = m3[1] || "";
45764
+ break;
45765
+ }
45766
+ }
45767
+ if (openIdx !== -1) {
45768
+ let endIdx = -1;
45769
+ for (let i3 = openIdx + 1; i3 < lines.length; i3++) {
45770
+ const trimmed = (lines[i3] || "").trim();
45771
+ if (trimmed === "end") {
45772
+ endIdx = i3;
45773
+ break;
45774
+ }
45775
+ }
45776
+ if (endIdx !== -1) {
45777
+ const invalidLines = [];
45778
+ for (let i3 = openIdx + 1; i3 < endIdx; i3++) {
45779
+ const raw = lines[i3] || "";
45780
+ const trimmed = raw.trim();
45781
+ if (trimmed === "")
45782
+ continue;
45783
+ if (!/^\s*(participant|actor)\b/i.test(raw)) {
45784
+ invalidLines.push(i3);
45785
+ }
45786
+ }
45787
+ if (invalidLines.length > 0) {
45788
+ const endIndent = openIndent;
45789
+ const movedContent = invalidLines.map((i3) => {
45790
+ const line = lines[i3] || "";
45791
+ const trimmed = line.trimStart();
45792
+ return endIndent + trimmed;
45793
+ }).join("\n") + "\n";
45794
+ for (let i3 = invalidLines.length - 1; i3 >= 0; i3--) {
45795
+ const idx = invalidLines[i3];
45796
+ edits.push({ start: { line: idx + 1, column: 1 }, end: { line: idx + 2, column: 1 }, newText: "" });
45797
+ }
45798
+ edits.push(insertAt(text, { line: endIdx + 2, column: 1 }, movedContent));
45799
+ }
45800
+ }
45801
+ }
45802
+ continue;
45803
+ }
45616
45804
  if (is("SE-BLOCK-MISSING-END", e3)) {
45617
45805
  const lines = text.split(/\r?\n/);
45618
45806
  const curIdx = Math.max(0, e3.line - 1);
@@ -45893,8 +46081,543 @@ var init_fixes = __esm({
45893
46081
  });
45894
46082
 
45895
46083
  // node_modules/@probelabs/maid/out/renderer/graph-builder.js
46084
+ var GraphBuilder;
45896
46085
  var init_graph_builder = __esm({
45897
46086
  "node_modules/@probelabs/maid/out/renderer/graph-builder.js"() {
46087
+ GraphBuilder = class {
46088
+ constructor() {
46089
+ this.nodes = /* @__PURE__ */ new Map();
46090
+ this.edges = [];
46091
+ this.nodeCounter = 0;
46092
+ this.edgeCounter = 0;
46093
+ this.subgraphs = [];
46094
+ this.currentSubgraphStack = [];
46095
+ this.classStyles = /* @__PURE__ */ new Map();
46096
+ this.nodeStyles = /* @__PURE__ */ new Map();
46097
+ this.nodeClasses = /* @__PURE__ */ new Map();
46098
+ }
46099
+ build(cst) {
46100
+ this.reset();
46101
+ if (!cst || !cst.children) {
46102
+ return {
46103
+ nodes: [],
46104
+ edges: [],
46105
+ direction: "TD",
46106
+ subgraphs: []
46107
+ };
46108
+ }
46109
+ const direction = this.extractDirection(cst);
46110
+ this.processStatements(cst);
46111
+ return {
46112
+ nodes: Array.from(this.nodes.values()),
46113
+ edges: this.edges,
46114
+ direction,
46115
+ subgraphs: this.subgraphs
46116
+ };
46117
+ }
46118
+ reset() {
46119
+ this.nodes.clear();
46120
+ this.edges = [];
46121
+ this.nodeCounter = 0;
46122
+ this.edgeCounter = 0;
46123
+ this.subgraphs = [];
46124
+ this.currentSubgraphStack = [];
46125
+ this.classStyles.clear();
46126
+ this.nodeStyles.clear();
46127
+ this.nodeClasses.clear();
46128
+ }
46129
+ extractDirection(cst) {
46130
+ const dirToken = cst.children?.Direction?.[0];
46131
+ const dir = dirToken?.image?.toUpperCase();
46132
+ switch (dir) {
46133
+ case "TB":
46134
+ case "TD":
46135
+ return "TD";
46136
+ case "BT":
46137
+ return "BT";
46138
+ case "LR":
46139
+ return "LR";
46140
+ case "RL":
46141
+ return "RL";
46142
+ default:
46143
+ return "TD";
46144
+ }
46145
+ }
46146
+ processStatements(cst) {
46147
+ const statements = cst.children?.statement;
46148
+ if (!statements)
46149
+ return;
46150
+ for (const stmt of statements) {
46151
+ if (stmt.children?.nodeStatement) {
46152
+ this.processNodeStatement(stmt.children.nodeStatement[0]);
46153
+ } else if (stmt.children?.subgraph) {
46154
+ this.processSubgraph(stmt.children.subgraph[0]);
46155
+ } else if (stmt.children?.classDefStatement) {
46156
+ this.processClassDef(stmt.children.classDefStatement[0]);
46157
+ } else if (stmt.children?.classStatement) {
46158
+ this.processClassAssign(stmt.children.classStatement[0]);
46159
+ } else if (stmt.children?.styleStatement) {
46160
+ this.processStyle(stmt.children.styleStatement[0]);
46161
+ }
46162
+ }
46163
+ }
46164
+ processNodeStatement(stmt) {
46165
+ const groups = stmt.children?.nodeOrParallelGroup;
46166
+ const links = stmt.children?.link;
46167
+ if (!groups || groups.length === 0)
46168
+ return;
46169
+ const sourceNodes = this.processNodeGroup(groups[0]);
46170
+ if (groups.length > 1 && links && links.length > 0) {
46171
+ const targetNodes = this.processNodeGroup(groups[1]);
46172
+ const linkInfo = this.extractLinkInfo(links[0]);
46173
+ for (const source of sourceNodes) {
46174
+ for (const target of targetNodes) {
46175
+ this.edges.push({
46176
+ id: `e${this.edgeCounter++}`,
46177
+ source,
46178
+ target,
46179
+ label: linkInfo.label,
46180
+ type: linkInfo.type,
46181
+ markerStart: linkInfo.markerStart,
46182
+ markerEnd: linkInfo.markerEnd
46183
+ });
46184
+ }
46185
+ }
46186
+ for (let i3 = 2; i3 < groups.length; i3++) {
46187
+ const nextNodes = this.processNodeGroup(groups[i3]);
46188
+ const nextLink = links[i3 - 1] ? this.extractLinkInfo(links[i3 - 1]) : linkInfo;
46189
+ for (const source of targetNodes) {
46190
+ for (const target of nextNodes) {
46191
+ this.edges.push({
46192
+ id: `e${this.edgeCounter++}`,
46193
+ source,
46194
+ target,
46195
+ label: nextLink.label,
46196
+ type: nextLink.type,
46197
+ markerStart: nextLink.markerStart,
46198
+ markerEnd: nextLink.markerEnd
46199
+ });
46200
+ }
46201
+ }
46202
+ targetNodes.length = 0;
46203
+ targetNodes.push(...nextNodes);
46204
+ }
46205
+ }
46206
+ }
46207
+ processNodeGroup(group) {
46208
+ const nodes = group.children?.node;
46209
+ if (!nodes)
46210
+ return [];
46211
+ const nodeIds = [];
46212
+ for (const node of nodes) {
46213
+ const nodeInfo = this.extractNodeInfo(node);
46214
+ if (nodeInfo) {
46215
+ const isSubgraph = this.subgraphs.some((sg) => sg.id === nodeInfo.id);
46216
+ if (!isSubgraph) {
46217
+ if (!this.nodes.has(nodeInfo.id)) {
46218
+ nodeInfo.style = this.computeNodeStyle(nodeInfo.id);
46219
+ this.nodes.set(nodeInfo.id, nodeInfo);
46220
+ } else {
46221
+ const existing = this.nodes.get(nodeInfo.id);
46222
+ if (nodeInfo.shape !== "rectangle" || nodeInfo.label !== nodeInfo.id) {
46223
+ if (nodeInfo.label !== nodeInfo.id) {
46224
+ existing.label = nodeInfo.label;
46225
+ }
46226
+ if (nodeInfo.shape !== "rectangle") {
46227
+ existing.shape = nodeInfo.shape;
46228
+ }
46229
+ }
46230
+ const merged = this.computeNodeStyle(nodeInfo.id);
46231
+ if (Object.keys(merged).length) {
46232
+ existing.style = { ...existing.style || {}, ...merged };
46233
+ }
46234
+ }
46235
+ if (this.currentSubgraphStack.length) {
46236
+ for (const sgId of this.currentSubgraphStack) {
46237
+ const subgraph = this.subgraphs.find((s3) => s3.id === sgId);
46238
+ if (subgraph && !subgraph.nodes.includes(nodeInfo.id)) {
46239
+ subgraph.nodes.push(nodeInfo.id);
46240
+ }
46241
+ }
46242
+ }
46243
+ }
46244
+ nodeIds.push(nodeInfo.id);
46245
+ }
46246
+ }
46247
+ return nodeIds;
46248
+ }
46249
+ extractNodeInfo(node) {
46250
+ const children = node.children;
46251
+ if (!children)
46252
+ return null;
46253
+ let id;
46254
+ if (children.nodeId) {
46255
+ id = children.nodeId[0].image;
46256
+ if (children.nodeIdSuffix) {
46257
+ id += children.nodeIdSuffix[0].image;
46258
+ }
46259
+ } else if (children.nodeIdNum) {
46260
+ id = children.nodeIdNum[0].image;
46261
+ } else if (children.Identifier) {
46262
+ id = children.Identifier[0].image;
46263
+ } else {
46264
+ return null;
46265
+ }
46266
+ let shape = "rectangle";
46267
+ let label = id;
46268
+ const shapeNode = children.nodeShape?.[0];
46269
+ if (shapeNode?.children) {
46270
+ const result = this.extractShapeAndLabel(shapeNode);
46271
+ shape = result.shape;
46272
+ if (result.label)
46273
+ label = result.label;
46274
+ }
46275
+ const clsTok = children.nodeClass?.[0];
46276
+ if (clsTok) {
46277
+ const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
46278
+ set.add(clsTok.image);
46279
+ this.nodeClasses.set(id, set);
46280
+ }
46281
+ return { id, label, shape };
46282
+ }
46283
+ extractShapeAndLabel(shapeNode) {
46284
+ const children = shapeNode.children;
46285
+ let shape = "rectangle";
46286
+ let label = "";
46287
+ const contentNodes = children?.nodeContent;
46288
+ if (contentNodes && contentNodes.length > 0) {
46289
+ label = this.extractTextContent(contentNodes[0]);
46290
+ }
46291
+ if (children?.SquareOpen) {
46292
+ shape = "rectangle";
46293
+ const contentNode = children.nodeContent?.[0];
46294
+ if (contentNode) {
46295
+ const c3 = contentNode.children;
46296
+ const tokTypes = ["ForwardSlash", "Backslash", "Identifier", "Text", "NumberLiteral", "RoundOpen", "RoundClose", "AngleLess", "AngleOpen", "Comma", "Colon", "Ampersand", "Semicolon", "TwoDashes", "Line", "ThickLine", "DottedLine"];
46297
+ const toks = [];
46298
+ for (const tt of tokTypes) {
46299
+ const arr = c3[tt];
46300
+ arr?.forEach((t3) => toks.push({ type: tt, t: t3, start: t3.startOffset ?? 0 }));
46301
+ }
46302
+ if (toks.length >= 2) {
46303
+ toks.sort((a3, b3) => a3.start - b3.start);
46304
+ const first2 = toks[0].type;
46305
+ const last2 = toks[toks.length - 1].type;
46306
+ if (first2 === "ForwardSlash" && last2 === "ForwardSlash" || first2 === "Backslash" && last2 === "Backslash") {
46307
+ shape = "parallelogram";
46308
+ } else if (first2 === "ForwardSlash" && last2 === "Backslash") {
46309
+ shape = "trapezoid";
46310
+ } else if (first2 === "Backslash" && last2 === "ForwardSlash") {
46311
+ shape = "trapezoidAlt";
46312
+ }
46313
+ }
46314
+ }
46315
+ } else if (children?.RoundOpen) {
46316
+ shape = "round";
46317
+ } else if (children?.DiamondOpen) {
46318
+ shape = "diamond";
46319
+ } else if (children?.DoubleRoundOpen) {
46320
+ shape = "circle";
46321
+ } else if (children?.StadiumOpen) {
46322
+ shape = "stadium";
46323
+ } else if (children?.HexagonOpen) {
46324
+ shape = "hexagon";
46325
+ } else if (children?.DoubleSquareOpen) {
46326
+ shape = "subroutine";
46327
+ } else if (children?.CylinderOpen) {
46328
+ shape = "cylinder";
46329
+ } else if (children?.TrapezoidOpen) {
46330
+ shape = "trapezoid";
46331
+ } else if (children?.ParallelogramOpen) {
46332
+ shape = "parallelogram";
46333
+ }
46334
+ return { shape, label };
46335
+ }
46336
+ extractTextContent(contentNode) {
46337
+ const children = contentNode.children;
46338
+ if (!children)
46339
+ return "";
46340
+ const tokenTypes = [
46341
+ "Text",
46342
+ "Identifier",
46343
+ "QuotedString",
46344
+ "NumberLiteral",
46345
+ "Ampersand",
46346
+ "Comma",
46347
+ "Colon",
46348
+ "Semicolon",
46349
+ "Dot",
46350
+ "Underscore",
46351
+ "Dash",
46352
+ "ForwardSlash",
46353
+ "Backslash",
46354
+ "AngleLess",
46355
+ "AngleOpen"
46356
+ ];
46357
+ const tokenWithPositions = [];
46358
+ for (const type of tokenTypes) {
46359
+ const tokens = children[type];
46360
+ if (tokens) {
46361
+ for (const token of tokens) {
46362
+ let text = token.image;
46363
+ if (type === "QuotedString" && text.startsWith('"') && text.endsWith('"')) {
46364
+ text = text.slice(1, -1);
46365
+ }
46366
+ if ((type === "ForwardSlash" || type === "Backslash") && tokenWithPositions.length === 0) {
46367
+ continue;
46368
+ }
46369
+ tokenWithPositions.push({
46370
+ text,
46371
+ startOffset: token.startOffset ?? 0,
46372
+ type
46373
+ });
46374
+ }
46375
+ }
46376
+ }
46377
+ tokenWithPositions.sort((a3, b3) => a3.startOffset - b3.startOffset);
46378
+ if (tokenWithPositions.length) {
46379
+ const first2 = tokenWithPositions[0];
46380
+ if (first2.type === "ForwardSlash" || first2.type === "Backslash") {
46381
+ tokenWithPositions.shift();
46382
+ }
46383
+ const last2 = tokenWithPositions[tokenWithPositions.length - 1];
46384
+ if (last2.type === "ForwardSlash" || last2.type === "Backslash") {
46385
+ tokenWithPositions.pop();
46386
+ }
46387
+ }
46388
+ const parts = tokenWithPositions.map((t3) => t3.text);
46389
+ if (children.Space) {
46390
+ return parts.join("");
46391
+ }
46392
+ return parts.join(" ").trim();
46393
+ }
46394
+ extractLinkInfo(link) {
46395
+ const children = link.children;
46396
+ let type = "arrow";
46397
+ let label;
46398
+ let markerStart = "none";
46399
+ let markerEnd = "none";
46400
+ if (children.BiDirectionalArrow) {
46401
+ type = "arrow";
46402
+ markerStart = "arrow";
46403
+ markerEnd = "arrow";
46404
+ } else if (children.CircleEndLine) {
46405
+ type = "open";
46406
+ markerStart = "circle";
46407
+ markerEnd = "circle";
46408
+ } else if (children.CrossEndLine) {
46409
+ type = "open";
46410
+ markerStart = "cross";
46411
+ markerEnd = "cross";
46412
+ } else if (children?.ArrowRight) {
46413
+ type = "arrow";
46414
+ markerEnd = "arrow";
46415
+ } else if (children?.ArrowLeft) {
46416
+ type = "arrow";
46417
+ markerStart = "arrow";
46418
+ } else if (children?.DottedArrowRight) {
46419
+ type = "dotted";
46420
+ markerEnd = "arrow";
46421
+ } else if (children?.DottedArrowLeft) {
46422
+ type = "dotted";
46423
+ markerStart = "arrow";
46424
+ } else if (children?.ThickArrowRight) {
46425
+ type = "thick";
46426
+ markerEnd = "arrow";
46427
+ } else if (children?.ThickArrowLeft) {
46428
+ type = "thick";
46429
+ markerStart = "arrow";
46430
+ } else if (children?.LinkRight || children?.LinkLeft || children?.Line || children?.TwoDashes || children?.DottedLine || children?.ThickLine) {
46431
+ if (children?.DottedLine)
46432
+ type = "dotted";
46433
+ else if (children?.ThickLine)
46434
+ type = "thick";
46435
+ else
46436
+ type = "open";
46437
+ } else if (children?.InvisibleLink) {
46438
+ type = "invisible";
46439
+ }
46440
+ if (markerEnd === "none" && (children?.ArrowRight || children.ThickArrowRight || children.DottedArrowRight)) {
46441
+ markerEnd = "arrow";
46442
+ }
46443
+ if (markerStart === "none" && (children?.ArrowLeft || children.ThickArrowLeft || children.DottedArrowLeft)) {
46444
+ markerStart = "arrow";
46445
+ }
46446
+ const textNode = children?.linkText?.[0];
46447
+ if (textNode) {
46448
+ label = this.extractTextContent(textNode);
46449
+ } else if (children.linkTextInline?.[0]) {
46450
+ label = this.extractTextContent(children.linkTextInline[0]);
46451
+ } else if (children.inlineCarrier?.[0]) {
46452
+ const token = children.inlineCarrier[0];
46453
+ const raw = token.image.trim();
46454
+ if (raw.startsWith("-.") && raw.endsWith(".-")) {
46455
+ type = "dotted";
46456
+ } else if (raw.startsWith("==") && raw.endsWith("==")) {
46457
+ type = "thick";
46458
+ } else if (raw.startsWith("--") && raw.endsWith("--")) {
46459
+ }
46460
+ if (children.ArrowRight || children.DottedArrowRight || children.ThickArrowRight) {
46461
+ markerEnd = "arrow";
46462
+ }
46463
+ if (children.ArrowLeft || children.DottedArrowLeft || children.ThickArrowLeft) {
46464
+ markerStart = "arrow";
46465
+ }
46466
+ const strip = (str) => {
46467
+ if (str.startsWith("-.") && str.endsWith(".-") || str.startsWith("==") && str.endsWith("==") || str.startsWith("--") && str.endsWith("--")) {
46468
+ return str.slice(2, -2).trim();
46469
+ }
46470
+ return str;
46471
+ };
46472
+ label = strip(raw);
46473
+ }
46474
+ return { type, label, markerStart, markerEnd };
46475
+ }
46476
+ processSubgraph(subgraph) {
46477
+ const children = subgraph.children;
46478
+ let id = `subgraph_${this.subgraphs.length}`;
46479
+ let label;
46480
+ const idToken = children?.subgraphId?.[0] || children?.Identifier?.[0];
46481
+ if (idToken) {
46482
+ id = idToken.image;
46483
+ }
46484
+ if (children?.SquareOpen && children?.nodeContent) {
46485
+ label = this.extractTextContent(children.nodeContent[0]);
46486
+ } else if (children.subgraphTitleQ?.[0]) {
46487
+ const qt = children.subgraphTitleQ[0];
46488
+ const img = qt.image;
46489
+ label = img && img.length >= 2 && (img.startsWith('"') || img.startsWith("'")) ? img.slice(1, -1) : img;
46490
+ } else if (children?.subgraphLabel) {
46491
+ label = this.extractTextContent(children.subgraphLabel[0]);
46492
+ }
46493
+ if (!label && id !== `subgraph_${this.subgraphs.length}`) {
46494
+ label = id;
46495
+ }
46496
+ const parent = this.currentSubgraphStack.length ? this.currentSubgraphStack[this.currentSubgraphStack.length - 1] : void 0;
46497
+ const sg = { id, label, nodes: [], parent };
46498
+ this.subgraphs.push(sg);
46499
+ this.currentSubgraphStack.push(id);
46500
+ const statements = children?.subgraphStatement;
46501
+ if (statements) {
46502
+ for (const stmt of statements) {
46503
+ if (stmt.children?.nodeStatement) {
46504
+ this.processNodeStatement(stmt.children.nodeStatement[0]);
46505
+ } else if (stmt.children?.subgraph) {
46506
+ this.processSubgraph(stmt.children.subgraph[0]);
46507
+ }
46508
+ }
46509
+ }
46510
+ this.currentSubgraphStack.pop();
46511
+ }
46512
+ // ---- Styling helpers ----
46513
+ processClassDef(cst) {
46514
+ const idTok = cst.children?.Identifier?.[0];
46515
+ if (!idTok)
46516
+ return;
46517
+ const className = idTok.image;
46518
+ const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
46519
+ if (Object.keys(props).length) {
46520
+ this.classStyles.set(className, props);
46521
+ for (const [nodeId, classes] of this.nodeClasses.entries()) {
46522
+ if (classes.has(className)) {
46523
+ const node = this.nodes.get(nodeId);
46524
+ if (node) {
46525
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
46526
+ }
46527
+ }
46528
+ }
46529
+ }
46530
+ }
46531
+ processClassAssign(cst) {
46532
+ const ids = cst.children?.Identifier || [];
46533
+ if (!ids.length)
46534
+ return;
46535
+ const classNameTok = cst.children.className?.[0];
46536
+ const className = classNameTok?.image || ids[ids.length - 1].image;
46537
+ const nodeIds = classNameTok ? ids.slice(0, -1) : ids.slice(0, -1);
46538
+ for (const tok of nodeIds) {
46539
+ const id = tok.image;
46540
+ const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
46541
+ set.add(className);
46542
+ this.nodeClasses.set(id, set);
46543
+ const node = this.nodes.get(id);
46544
+ if (node) {
46545
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(id) };
46546
+ }
46547
+ }
46548
+ }
46549
+ processStyle(cst) {
46550
+ const idTok = cst.children?.Identifier?.[0];
46551
+ if (!idTok)
46552
+ return;
46553
+ const nodeId = idTok.image;
46554
+ const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
46555
+ if (Object.keys(props).length) {
46556
+ this.nodeStyles.set(nodeId, props);
46557
+ const node = this.nodes.get(nodeId);
46558
+ if (node) {
46559
+ node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
46560
+ }
46561
+ }
46562
+ }
46563
+ collectStyleProps(cst, opts = {}) {
46564
+ const tokens = [];
46565
+ const ch = cst.children || {};
46566
+ const push = (arr, type = "t") => arr?.forEach((t3) => tokens.push({ text: t3.image, startOffset: t3.startOffset ?? 0, type }));
46567
+ push(ch.Text, "Text");
46568
+ push(ch.Identifier, "Identifier");
46569
+ push(ch.ColorValue, "Color");
46570
+ push(ch.Colon, "Colon");
46571
+ push(ch.Comma, "Comma");
46572
+ push(ch.NumberLiteral, "Number");
46573
+ tokens.sort((a3, b3) => a3.startOffset - b3.startOffset);
46574
+ if (opts.skipFirstIdentifier) {
46575
+ const idx = tokens.findIndex((t3) => t3.type === "Identifier");
46576
+ if (idx >= 0)
46577
+ tokens.splice(idx, 1);
46578
+ }
46579
+ const joined = tokens.map((t3) => t3.text).join("");
46580
+ const props = {};
46581
+ for (const seg of joined.split(",").map((s3) => s3.trim()).filter(Boolean)) {
46582
+ const [k3, v3] = seg.split(":");
46583
+ if (k3 && v3)
46584
+ props[k3.trim()] = v3.trim();
46585
+ }
46586
+ return props;
46587
+ }
46588
+ computeNodeStyle(nodeId) {
46589
+ const out = {};
46590
+ const classes = this.nodeClasses.get(nodeId);
46591
+ if (classes) {
46592
+ for (const c3 of classes) {
46593
+ const s3 = this.classStyles.get(c3);
46594
+ if (s3)
46595
+ Object.assign(out, this.normalizeStyle(s3));
46596
+ }
46597
+ }
46598
+ const direct = this.nodeStyles.get(nodeId);
46599
+ if (direct)
46600
+ Object.assign(out, this.normalizeStyle(direct));
46601
+ return out;
46602
+ }
46603
+ normalizeStyle(s3) {
46604
+ const out = {};
46605
+ for (const [kRaw, vRaw] of Object.entries(s3)) {
46606
+ const k3 = kRaw.trim().toLowerCase();
46607
+ const v3 = vRaw.trim();
46608
+ if (k3 === "stroke-width") {
46609
+ const num = parseFloat(v3);
46610
+ if (!Number.isNaN(num))
46611
+ out.strokeWidth = num;
46612
+ } else if (k3 === "stroke") {
46613
+ out.stroke = v3;
46614
+ } else if (k3 === "fill") {
46615
+ out.fill = v3;
46616
+ }
46617
+ }
46618
+ return out;
46619
+ }
46620
+ };
45898
46621
  }
45899
46622
  });
45900
46623
 
@@ -53577,49 +54300,2799 @@ var require_dagre = __commonJS({
53577
54300
  });
53578
54301
 
53579
54302
  // node_modules/@probelabs/maid/out/renderer/layout.js
53580
- var import_dagre;
54303
+ var import_dagre, DagreLayoutEngine;
53581
54304
  var init_layout = __esm({
53582
54305
  "node_modules/@probelabs/maid/out/renderer/layout.js"() {
53583
54306
  import_dagre = __toESM(require_dagre(), 1);
54307
+ DagreLayoutEngine = class {
54308
+ constructor() {
54309
+ this.nodeWidth = 120;
54310
+ this.nodeHeight = 50;
54311
+ this.rankSep = 50;
54312
+ this.nodeSep = 50;
54313
+ this.edgeSep = 10;
54314
+ }
54315
+ layout(graph) {
54316
+ const g3 = new import_dagre.default.graphlib.Graph();
54317
+ const hasClusters = !!(graph.subgraphs && graph.subgraphs.length > 0);
54318
+ const dir = this.mapDirection(graph.direction);
54319
+ let ranksep = this.rankSep;
54320
+ let nodesep = this.nodeSep;
54321
+ if (hasClusters) {
54322
+ if (dir === "LR" || dir === "RL") {
54323
+ ranksep += 20;
54324
+ nodesep += 70;
54325
+ } else {
54326
+ ranksep += 70;
54327
+ nodesep += 20;
54328
+ }
54329
+ }
54330
+ const graphConfig = {
54331
+ rankdir: dir,
54332
+ ranksep,
54333
+ nodesep,
54334
+ edgesep: this.edgeSep,
54335
+ marginx: 20,
54336
+ marginy: 20
54337
+ };
54338
+ if (hasClusters && (dir === "LR" || dir === "RL")) {
54339
+ graphConfig.ranker = "longest-path";
54340
+ graphConfig.acyclicer = "greedy";
54341
+ }
54342
+ if (hasClusters) {
54343
+ graphConfig.compound = true;
54344
+ }
54345
+ g3.setGraph(graphConfig);
54346
+ g3.setDefaultEdgeLabel(() => ({}));
54347
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
54348
+ for (const subgraph of graph.subgraphs) {
54349
+ g3.setNode(subgraph.id, { label: subgraph.label || subgraph.id, clusterLabelPos: "top" });
54350
+ }
54351
+ }
54352
+ for (const node of graph.nodes) {
54353
+ const dimensions = this.calculateNodeDimensions(node.label, node.shape);
54354
+ g3.setNode(node.id, {
54355
+ width: dimensions.width,
54356
+ height: dimensions.height,
54357
+ label: node.label,
54358
+ shape: node.shape
54359
+ });
54360
+ }
54361
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
54362
+ for (const subgraph of graph.subgraphs) {
54363
+ for (const nodeId of subgraph.nodes) {
54364
+ if (g3.hasNode(nodeId)) {
54365
+ try {
54366
+ g3.setParent(nodeId, subgraph.id);
54367
+ } catch {
54368
+ }
54369
+ }
54370
+ }
54371
+ if (subgraph.parent && g3.hasNode(subgraph.parent)) {
54372
+ try {
54373
+ g3.setParent(subgraph.id, subgraph.parent);
54374
+ } catch {
54375
+ }
54376
+ }
54377
+ }
54378
+ }
54379
+ for (const edge of graph.edges) {
54380
+ g3.setEdge(edge.source, edge.target, {
54381
+ label: edge.label,
54382
+ width: edge.label ? edge.label.length * 8 : 0,
54383
+ height: edge.label ? 20 : 0
54384
+ });
54385
+ }
54386
+ import_dagre.default.layout(g3);
54387
+ const graphInfo = g3.graph();
54388
+ const layoutNodes = [];
54389
+ const layoutEdges = [];
54390
+ for (const node of graph.nodes) {
54391
+ const nodeLayout = g3.node(node.id);
54392
+ if (nodeLayout) {
54393
+ layoutNodes.push({
54394
+ ...node,
54395
+ x: nodeLayout.x - nodeLayout.width / 2,
54396
+ y: nodeLayout.y - nodeLayout.height / 2,
54397
+ width: nodeLayout.width,
54398
+ height: nodeLayout.height
54399
+ });
54400
+ }
54401
+ }
54402
+ const layoutSubgraphs = [];
54403
+ if (graph.subgraphs && graph.subgraphs.length > 0) {
54404
+ for (const sg of graph.subgraphs) {
54405
+ const members = layoutNodes.filter((nd) => sg.nodes.includes(nd.id));
54406
+ if (members.length) {
54407
+ const minX = Math.min(...members.map((m3) => m3.x));
54408
+ const minY = Math.min(...members.map((m3) => m3.y));
54409
+ const maxX = Math.max(...members.map((m3) => m3.x + m3.width));
54410
+ const maxY = Math.max(...members.map((m3) => m3.y + m3.height));
54411
+ const pad = 30;
54412
+ layoutSubgraphs.push({
54413
+ id: sg.id,
54414
+ label: sg.label || sg.id,
54415
+ x: minX - pad,
54416
+ y: minY - pad - 18,
54417
+ // space for title
54418
+ width: maxX - minX + pad * 2,
54419
+ height: maxY - minY + pad * 2 + 18,
54420
+ parent: sg.parent
54421
+ });
54422
+ }
54423
+ }
54424
+ const byId = Object.fromEntries(layoutSubgraphs.map((s3) => [s3.id, s3]));
54425
+ for (const sg of layoutSubgraphs) {
54426
+ if (!sg.parent)
54427
+ continue;
54428
+ const p3 = byId[sg.parent];
54429
+ if (!p3)
54430
+ continue;
54431
+ const minX = Math.min(p3.x, sg.x);
54432
+ const minY = Math.min(p3.y, sg.y);
54433
+ const maxX = Math.max(p3.x + p3.width, sg.x + sg.width);
54434
+ const maxY = Math.max(p3.y + p3.height, sg.y + sg.height);
54435
+ p3.x = minX;
54436
+ p3.y = minY;
54437
+ p3.width = maxX - minX;
54438
+ p3.height = maxY - minY;
54439
+ }
54440
+ }
54441
+ const subgraphById = Object.fromEntries(layoutSubgraphs.map((sg) => [sg.id, sg]));
54442
+ for (const edge of graph.edges) {
54443
+ const edgeLayout = g3.edge(edge.source, edge.target);
54444
+ let pts = edgeLayout && Array.isArray(edgeLayout.points) ? edgeLayout.points.slice() : [];
54445
+ const hasNaN = pts.some((p3) => !Number.isFinite(p3.x) || !Number.isFinite(p3.y));
54446
+ const srcSg = subgraphById[edge.source];
54447
+ const dstSg = subgraphById[edge.target];
54448
+ let synthesized = false;
54449
+ if (!pts.length || hasNaN || srcSg || dstSg) {
54450
+ const rankdir = this.mapDirection(graph.direction);
54451
+ const getNode = (id) => {
54452
+ const n3 = g3.node(id);
54453
+ if (!n3)
54454
+ return void 0;
54455
+ return {
54456
+ id,
54457
+ label: n3.label || id,
54458
+ shape: n3.shape || "rectangle",
54459
+ x: n3.x - n3.width / 2,
54460
+ y: n3.y - n3.height / 2,
54461
+ width: n3.width,
54462
+ height: n3.height,
54463
+ style: {}
54464
+ };
54465
+ };
54466
+ const start = srcSg ? this.clusterAnchor(srcSg, rankdir, "out") : this.nodeAnchor(getNode(edge.source), rankdir, "out");
54467
+ const end = dstSg ? this.clusterAnchor(dstSg, rankdir, "in") : this.nodeAnchor(getNode(edge.target), rankdir, "in");
54468
+ if (start && end) {
54469
+ const PAD = 20;
54470
+ const horizontallyAdjacent = srcSg && dstSg && Math.abs(srcSg.x - dstSg.x) > Math.abs(srcSg.y - dstSg.y);
54471
+ const horizontalSubgraphs = horizontallyAdjacent;
54472
+ if (rankdir === "LR" || rankdir === "RL") {
54473
+ const outX = start.x + (rankdir === "LR" ? PAD : -PAD);
54474
+ const inX = end.x + (rankdir === "LR" ? -PAD : PAD);
54475
+ const startOut = { x: srcSg ? outX : start.x, y: start.y };
54476
+ const endPre = { x: dstSg ? inX : end.x, y: end.y };
54477
+ const alpha = 0.68;
54478
+ const midX = startOut.x + (endPre.x - startOut.x) * alpha;
54479
+ const m1 = { x: midX, y: startOut.y };
54480
+ const m22 = { x: midX, y: endPre.y };
54481
+ pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
54482
+ } else {
54483
+ if (horizontalSubgraphs && srcSg && dstSg) {
54484
+ const midY = (srcSg.y + srcSg.height / 2 + dstSg.y + dstSg.height / 2) / 2;
54485
+ if (srcSg.x < dstSg.x) {
54486
+ const startX = srcSg.x + srcSg.width;
54487
+ const endX = dstSg.x;
54488
+ pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
54489
+ } else {
54490
+ const startX = srcSg.x;
54491
+ const endX = dstSg.x + dstSg.width;
54492
+ pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
54493
+ }
54494
+ } else {
54495
+ const outY = start.y + (rankdir === "TD" ? PAD : -PAD);
54496
+ const inY = end.y + (rankdir === "TD" ? -PAD : PAD);
54497
+ const startOut = { x: start.x, y: srcSg ? outY : start.y };
54498
+ const endPre = { x: end.x, y: dstSg ? inY : end.y };
54499
+ const alpha = 0.68;
54500
+ const midY = startOut.y + (endPre.y - startOut.y) * alpha;
54501
+ const m1 = { x: startOut.x, y: midY };
54502
+ const m22 = { x: endPre.x, y: midY };
54503
+ pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
54504
+ }
54505
+ }
54506
+ synthesized = true;
54507
+ }
54508
+ }
54509
+ if (pts.length) {
54510
+ layoutEdges.push({ ...edge, points: pts, pathMode: synthesized ? "orthogonal" : "smooth" });
54511
+ }
54512
+ }
54513
+ const rawW = graphInfo.width;
54514
+ const rawH = graphInfo.height;
54515
+ const w3 = Number.isFinite(rawW) && rawW > 0 ? rawW : 800;
54516
+ const h3 = Number.isFinite(rawH) && rawH > 0 ? rawH : 600;
54517
+ return {
54518
+ nodes: layoutNodes,
54519
+ edges: layoutEdges,
54520
+ width: w3,
54521
+ height: h3,
54522
+ subgraphs: layoutSubgraphs
54523
+ };
54524
+ }
54525
+ mapDirection(direction) {
54526
+ switch (direction) {
54527
+ case "TB":
54528
+ case "TD":
54529
+ return "TB";
54530
+ case "BT":
54531
+ return "BT";
54532
+ case "LR":
54533
+ return "LR";
54534
+ case "RL":
54535
+ return "RL";
54536
+ default:
54537
+ return "TB";
54538
+ }
54539
+ }
54540
+ calculateNodeDimensions(label, shape) {
54541
+ const charWidth = 7;
54542
+ const padding = 20;
54543
+ const minWidth = 80;
54544
+ const minHeight = 40;
54545
+ const maxWidth = 240;
54546
+ const lineHeight = 18;
54547
+ const explicitLines = label.split(/<\s*br\s*\/?\s*>/i);
54548
+ const hasExplicitBreaks = explicitLines.length > 1;
54549
+ let width;
54550
+ let lines;
54551
+ if (hasExplicitBreaks) {
54552
+ const maxLineLength = Math.max(...explicitLines.map((line) => line.length));
54553
+ width = Math.min(Math.max(maxLineLength * charWidth + padding * 2, minWidth), maxWidth);
54554
+ lines = explicitLines.length;
54555
+ } else {
54556
+ width = Math.min(Math.max(label.length * charWidth + padding * 2, minWidth), maxWidth);
54557
+ const charsPerLine = Math.max(1, Math.floor((width - padding * 2) / charWidth));
54558
+ lines = Math.ceil(label.length / charsPerLine);
54559
+ }
54560
+ let height = Math.max(lines * lineHeight + padding, minHeight);
54561
+ switch (shape) {
54562
+ case "circle":
54563
+ const size = Math.max(width, height);
54564
+ width = size;
54565
+ height = size;
54566
+ break;
54567
+ case "diamond": {
54568
+ const size2 = Math.max(width, height) * 1.2;
54569
+ width = size2;
54570
+ height = size2;
54571
+ break;
54572
+ }
54573
+ case "hexagon":
54574
+ width *= 1.3;
54575
+ height *= 1.2;
54576
+ break;
54577
+ case "stadium":
54578
+ width *= 1.2;
54579
+ break;
54580
+ case "cylinder":
54581
+ height *= 1.5;
54582
+ break;
54583
+ case "subroutine":
54584
+ case "double":
54585
+ width += 10;
54586
+ height += 10;
54587
+ break;
54588
+ case "parallelogram":
54589
+ case "trapezoid":
54590
+ width *= 1.3;
54591
+ break;
54592
+ }
54593
+ return { width: Math.round(width), height: Math.round(height) };
54594
+ }
54595
+ clusterAnchor(sg, rankdir, mode) {
54596
+ switch (rankdir) {
54597
+ case "LR":
54598
+ return { x: mode === "out" ? sg.x + sg.width : sg.x, y: sg.y + sg.height / 2 };
54599
+ case "RL":
54600
+ return { x: mode === "out" ? sg.x : sg.x + sg.width, y: sg.y + sg.height / 2 };
54601
+ case "BT":
54602
+ return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y : sg.y + sg.height };
54603
+ case "TB":
54604
+ default:
54605
+ return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y + sg.height : sg.y };
54606
+ }
54607
+ }
54608
+ nodeAnchor(n3, rankdir, mode) {
54609
+ if (!n3)
54610
+ return { x: 0, y: 0 };
54611
+ switch (rankdir) {
54612
+ case "LR":
54613
+ return { x: mode === "in" ? n3.x : n3.x + n3.width, y: n3.y + n3.height / 2 };
54614
+ case "RL":
54615
+ return { x: mode === "in" ? n3.x + n3.width : n3.x, y: n3.y + n3.height / 2 };
54616
+ case "BT":
54617
+ return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y + n3.height : n3.y };
54618
+ case "TB":
54619
+ default:
54620
+ return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y : n3.y + n3.height };
54621
+ }
54622
+ }
54623
+ };
54624
+ }
54625
+ });
54626
+
54627
+ // node_modules/@probelabs/maid/out/renderer/arrow-utils.js
54628
+ function triangleAtEnd(start, end, color = "#333", length = 8, width = 6) {
54629
+ const vx = end.x - start.x;
54630
+ const vy = end.y - start.y;
54631
+ const len = Math.hypot(vx, vy) || 1;
54632
+ const ux = vx / len;
54633
+ const uy = vy / len;
54634
+ const nx = -uy;
54635
+ const ny = ux;
54636
+ const baseX = end.x - ux * length;
54637
+ const baseY = end.y - uy * length;
54638
+ const p2x = baseX + nx * (width / 2), p2y = baseY + ny * (width / 2);
54639
+ const p3x = baseX - nx * (width / 2), p3y = baseY - ny * (width / 2);
54640
+ return `<path d="M${end.x},${end.y} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
54641
+ }
54642
+ function triangleAtStart(first2, second, color = "#333", length = 8, width = 6) {
54643
+ const vx = second.x - first2.x;
54644
+ const vy = second.y - first2.y;
54645
+ const len = Math.hypot(vx, vy) || 1;
54646
+ const ux = vx / len;
54647
+ const uy = vy / len;
54648
+ const nx = -uy;
54649
+ const ny = ux;
54650
+ const tipX = first2.x - ux * length;
54651
+ const tipY = first2.y - uy * length;
54652
+ const p2x = first2.x + nx * (width / 2), p2y = first2.y + ny * (width / 2);
54653
+ const p3x = first2.x - nx * (width / 2), p3y = first2.y - ny * (width / 2);
54654
+ return `<path d="M${tipX},${tipY} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
54655
+ }
54656
+ var init_arrow_utils = __esm({
54657
+ "node_modules/@probelabs/maid/out/renderer/arrow-utils.js"() {
54658
+ }
54659
+ });
54660
+
54661
+ // node_modules/@probelabs/maid/out/renderer/styles.js
54662
+ function buildSharedCss(opts = {}) {
54663
+ const fontFamily = opts.fontFamily || "Arial, sans-serif";
54664
+ const fontSize = opts.fontSize ?? 14;
54665
+ const nodeFill = opts.nodeFill || "#eef0ff";
54666
+ const nodeStroke = opts.nodeStroke || "#3f3f3f";
54667
+ const edgeStroke = opts.edgeStroke || "#555555";
54668
+ return `
54669
+ .node-shape { fill: ${nodeFill}; stroke: ${nodeStroke}; stroke-width: 1px; }
54670
+ .node-label { fill: #333; font-family: ${fontFamily}; font-size: ${fontSize}px; }
54671
+ .edge-path { stroke: ${edgeStroke}; stroke-width: 2px; fill: none; }
54672
+ .edge-label-bg { fill: rgba(232,232,232, 0.8); opacity: 0.5; }
54673
+ .edge-label-text { fill: #333; font-family: ${fontFamily}; font-size: ${Math.max(10, fontSize - 2)}px; }
54674
+
54675
+ /* Cluster (flowchart + sequence blocks) */
54676
+ .cluster-bg { fill: #ffffde; }
54677
+ .cluster-border { fill: none; stroke: #aaaa33; stroke-width: 1px; }
54678
+ .cluster-title-bg { fill: rgba(255,255,255,0.8); }
54679
+ .cluster-label-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
54680
+
54681
+ /* Notes */
54682
+ .note { fill: #fff5ad; stroke: #aaaa33; stroke-width: 1px; }
54683
+ .note-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
54684
+
54685
+ /* Sequence-specific add-ons (safe for flowcharts too) */
54686
+ .actor-rect { fill: #eaeaea; stroke: #666; stroke-width: 1.5px; }
54687
+ .actor-label { fill: #111; font-family: ${fontFamily}; font-size: 16px; }
54688
+ .lifeline { stroke: #999; stroke-width: 0.5px; }
54689
+ .activation { fill: #f4f4f4; stroke: #666; stroke-width: 1px; }
54690
+ .msg-line { stroke: #333; stroke-width: 1.5px; fill: none; }
54691
+ .msg-line.dotted { stroke-dasharray: 2 2; }
54692
+ .msg-line.thick { stroke-width: 3px; }
54693
+ .msg-label { fill: #333; font-family: ${fontFamily}; font-size: 12px; dominant-baseline: middle; }
54694
+ .msg-label-bg { fill: #ffffff; stroke: #cccccc; stroke-width: 1px; rx: 3; }
54695
+ `;
54696
+ }
54697
+ var init_styles = __esm({
54698
+ "node_modules/@probelabs/maid/out/renderer/styles.js"() {
54699
+ }
54700
+ });
54701
+
54702
+ // node_modules/@probelabs/maid/out/renderer/utils.js
54703
+ function escapeXml(text) {
54704
+ return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&apos;");
54705
+ }
54706
+ function measureText(text, fontSize = 12) {
54707
+ const avg = 0.6 * fontSize;
54708
+ return Math.max(0, Math.round(text.length * avg));
54709
+ }
54710
+ function palette(index) {
54711
+ if (index < DEFAULT_PALETTE.length)
54712
+ return DEFAULT_PALETTE[index];
54713
+ const i3 = index - DEFAULT_PALETTE.length;
54714
+ const hue = i3 * 47 % 360;
54715
+ return `hsl(${hue} 60% 55%)`;
54716
+ }
54717
+ function formatNumber(n3) {
54718
+ if (Number.isInteger(n3))
54719
+ return String(n3);
54720
+ return (Math.round(n3 * 100) / 100).toString();
54721
+ }
54722
+ function formatPercent(value, total) {
54723
+ if (!(total > 0))
54724
+ return "0%";
54725
+ const p3 = value / total * 100;
54726
+ return `${Math.round(p3)}%`;
54727
+ }
54728
+ var DEFAULT_PALETTE;
54729
+ var init_utils4 = __esm({
54730
+ "node_modules/@probelabs/maid/out/renderer/utils.js"() {
54731
+ DEFAULT_PALETTE = [
54732
+ "#ECECFF",
54733
+ "#ffffde",
54734
+ "hsl(80, 100%, 56.2745098039%)",
54735
+ "hsl(240, 100%, 86.2745098039%)",
54736
+ "hsl(60, 100%, 63.5294117647%)",
54737
+ "hsl(80, 100%, 76.2745098039%)",
54738
+ "hsl(300, 100%, 76.2745098039%)",
54739
+ "hsl(180, 100%, 56.2745098039%)",
54740
+ "hsl(0, 100%, 56.2745098039%)",
54741
+ "hsl(300, 100%, 56.2745098039%)",
54742
+ "hsl(150, 100%, 56.2745098039%)",
54743
+ "hsl(0, 100%, 66.2745098039%)"
54744
+ ];
53584
54745
  }
53585
54746
  });
53586
54747
 
53587
- // node_modules/@probelabs/maid/out/renderer/svg-generator.js
53588
- var init_svg_generator = __esm({
53589
- "node_modules/@probelabs/maid/out/renderer/svg-generator.js"() {
53590
- }
53591
- });
53592
-
53593
- // node_modules/@probelabs/maid/out/renderer/dot-renderer.js
53594
- var init_dot_renderer = __esm({
53595
- "node_modules/@probelabs/maid/out/renderer/dot-renderer.js"() {
54748
+ // node_modules/@probelabs/maid/out/renderer/block-utils.js
54749
+ function blockBackground(x3, y2, width, height, radius = 0) {
54750
+ return `<g class="cluster-bg-layer" transform="translate(${x3},${y2})">
54751
+ <rect class="cluster-bg" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>
54752
+ </g>`;
54753
+ }
54754
+ function blockOverlay(x3, y2, width, height, title, branchYs = [], titleYOffset = 0, align = "center", branchAlign = "left", radius = 0) {
54755
+ const parts = [];
54756
+ parts.push(`<g class="cluster-overlay" transform="translate(${x3},${y2})">`);
54757
+ parts.push(`<rect class="cluster-border" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>`);
54758
+ const titleText = title ? escapeXml(title) : "";
54759
+ if (titleText) {
54760
+ const titleW = Math.max(24, measureText(titleText, 12) + 10);
54761
+ const yBg = -2 + titleYOffset;
54762
+ const yText = 11 + titleYOffset;
54763
+ if (align === "left") {
54764
+ const xBg = 6;
54765
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
54766
+ parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yText}" text-anchor="start">${titleText}</text>`);
54767
+ } else {
54768
+ const xBg = 6;
54769
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
54770
+ parts.push(`<text class="cluster-label-text" x="${xBg + titleW / 2}" y="${yText}" text-anchor="middle">${titleText}</text>`);
54771
+ }
54772
+ }
54773
+ for (const br of branchYs) {
54774
+ const yRel = br.y - y2;
54775
+ parts.push(`<line x1="0" y1="${yRel}" x2="${width}" y2="${yRel}" class="cluster-border" />`);
54776
+ if (br.title) {
54777
+ const text = escapeXml(br.title);
54778
+ const bw = Math.max(24, measureText(text, 12) + 10);
54779
+ const xBg = 6;
54780
+ parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yRel - 10}" width="${bw}" height="18" rx="3"/>`);
54781
+ if (branchAlign === "left") {
54782
+ parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yRel + 1}" text-anchor="start">${text}</text>`);
54783
+ } else {
54784
+ parts.push(`<text class="cluster-label-text" x="${xBg + bw / 2}" y="${yRel + 1}" text-anchor="middle">${text}</text>`);
54785
+ }
54786
+ }
53596
54787
  }
53597
- });
53598
-
53599
- // node_modules/@probelabs/maid/out/renderer/index.js
53600
- var init_renderer = __esm({
53601
- "node_modules/@probelabs/maid/out/renderer/index.js"() {
53602
- init_lexer2();
53603
- init_parser2();
53604
- init_graph_builder();
53605
- init_layout();
53606
- init_svg_generator();
53607
- init_layout();
53608
- init_svg_generator();
53609
- init_dot_renderer();
54788
+ parts.push("</g>");
54789
+ return parts.join("\n");
54790
+ }
54791
+ var init_block_utils = __esm({
54792
+ "node_modules/@probelabs/maid/out/renderer/block-utils.js"() {
54793
+ init_utils4();
53610
54794
  }
53611
54795
  });
53612
54796
 
53613
- // node_modules/@probelabs/maid/out/index.js
53614
- function fixText(text, options = {}) {
53615
- const { strict = false, level = "safe" } = options;
53616
- let current = text;
53617
- for (let i3 = 0; i3 < 5; i3++) {
53618
- const res = validate(current, { strict });
53619
- const edits = computeFixes(current, res.errors, level);
53620
- if (edits.length === 0)
53621
- return { fixed: current, errors: res.errors };
53622
- const next = applyEdits(current, edits);
54797
+ // node_modules/@probelabs/maid/out/renderer/svg-generator.js
54798
+ var SVGRenderer;
54799
+ var init_svg_generator = __esm({
54800
+ "node_modules/@probelabs/maid/out/renderer/svg-generator.js"() {
54801
+ init_arrow_utils();
54802
+ init_styles();
54803
+ init_block_utils();
54804
+ SVGRenderer = class {
54805
+ constructor() {
54806
+ this.padding = 20;
54807
+ this.fontSize = 14;
54808
+ this.fontFamily = "Arial, sans-serif";
54809
+ this.defaultStroke = "#3f3f3f";
54810
+ this.defaultFill = "#eef0ff";
54811
+ this.arrowStroke = "#555555";
54812
+ this.arrowMarkerSize = 9;
54813
+ }
54814
+ render(layout) {
54815
+ let minX = Infinity;
54816
+ let minY = Infinity;
54817
+ let maxX = -Infinity;
54818
+ let maxY = -Infinity;
54819
+ for (const n3 of layout.nodes) {
54820
+ minX = Math.min(minX, n3.x);
54821
+ minY = Math.min(minY, n3.y);
54822
+ maxX = Math.max(maxX, n3.x + n3.width);
54823
+ maxY = Math.max(maxY, n3.y + n3.height);
54824
+ }
54825
+ if (layout.subgraphs) {
54826
+ for (const sg of layout.subgraphs) {
54827
+ minX = Math.min(minX, sg.x);
54828
+ minY = Math.min(minY, sg.y);
54829
+ maxX = Math.max(maxX, sg.x + sg.width);
54830
+ maxY = Math.max(maxY, sg.y + sg.height);
54831
+ }
54832
+ }
54833
+ for (const e3 of layout.edges) {
54834
+ if (e3.points)
54835
+ for (const p3 of e3.points) {
54836
+ minX = Math.min(minX, p3.x);
54837
+ minY = Math.min(minY, p3.y);
54838
+ maxX = Math.max(maxX, p3.x);
54839
+ maxY = Math.max(maxY, p3.y);
54840
+ }
54841
+ }
54842
+ if (!isFinite(minX)) {
54843
+ minX = 0;
54844
+ }
54845
+ if (!isFinite(minY)) {
54846
+ minY = 0;
54847
+ }
54848
+ if (!isFinite(maxX)) {
54849
+ maxX = layout.width;
54850
+ }
54851
+ if (!isFinite(maxY)) {
54852
+ maxY = layout.height;
54853
+ }
54854
+ const extraPadX = Math.max(0, -Math.floor(minX) + 1);
54855
+ const extraPadY = Math.max(0, -Math.floor(minY) + 1);
54856
+ const padX = this.padding + extraPadX;
54857
+ const padY = this.padding + extraPadY;
54858
+ const bboxWidth = Math.ceil(maxX) - Math.min(0, Math.floor(minX));
54859
+ const bboxHeight = Math.ceil(maxY) - Math.min(0, Math.floor(minY));
54860
+ const width = bboxWidth + this.padding * 2 + extraPadX;
54861
+ const height = bboxHeight + this.padding * 2 + extraPadY;
54862
+ const elements = [];
54863
+ const overlays = [];
54864
+ elements.push(this.generateDefs());
54865
+ if (layout.subgraphs && layout.subgraphs.length) {
54866
+ const sgs = layout.subgraphs;
54867
+ const order = sgs.slice().sort((a3, b3) => (a3.parent ? 1 : 0) - (b3.parent ? 1 : 0));
54868
+ const map4 = new Map(order.map((o3) => [o3.id, o3]));
54869
+ const depthOf = (sg) => {
54870
+ let d3 = 0;
54871
+ let p3 = sg.parent;
54872
+ while (p3) {
54873
+ d3++;
54874
+ p3 = map4.get(p3)?.parent;
54875
+ }
54876
+ return d3;
54877
+ };
54878
+ const bgs = [];
54879
+ for (const sg of order) {
54880
+ const x3 = sg.x + padX;
54881
+ const y2 = sg.y + padY;
54882
+ bgs.push(blockBackground(x3, y2, sg.width, sg.height, 0));
54883
+ const depth = depthOf(sg);
54884
+ const title = sg.label ? this.escapeXml(sg.label) : void 0;
54885
+ const titleYOffset = 7 + depth * 12;
54886
+ overlays.push(blockOverlay(x3, y2, sg.width, sg.height, title, [], titleYOffset, "center", "left", 0));
54887
+ }
54888
+ elements.push(`<g class="subgraph-bg">${bgs.join("")}</g>`);
54889
+ }
54890
+ const nodeMap = {};
54891
+ for (const n3 of layout.nodes) {
54892
+ nodeMap[n3.id] = { x: n3.x + padX, y: n3.y + padY, width: n3.width, height: n3.height, shape: n3.shape };
54893
+ }
54894
+ if (layout.subgraphs && layout.subgraphs.length) {
54895
+ for (const sg of layout.subgraphs) {
54896
+ nodeMap[sg.id] = { x: sg.x + padX, y: sg.y + padY, width: sg.width, height: sg.height, shape: "rectangle" };
54897
+ }
54898
+ }
54899
+ for (const node of layout.nodes) {
54900
+ elements.push(this.generateNodeWithPad(node, padX, padY));
54901
+ }
54902
+ for (const edge of layout.edges) {
54903
+ const { path: path6, overlay } = this.generateEdge(edge, padX, padY, nodeMap);
54904
+ elements.push(path6);
54905
+ if (overlay)
54906
+ overlays.push(overlay);
54907
+ }
54908
+ const bg = `<rect x="0" y="0" width="${width}" height="${height}" fill="#ffffff" />`;
54909
+ const sharedCss = buildSharedCss({
54910
+ fontFamily: this.fontFamily,
54911
+ fontSize: this.fontSize,
54912
+ nodeFill: this.defaultFill,
54913
+ nodeStroke: this.defaultStroke,
54914
+ edgeStroke: this.arrowStroke
54915
+ });
54916
+ const css = `<style>${sharedCss}</style>`;
54917
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
54918
+ ${bg}
54919
+ ${css}
54920
+ ${elements.join("\n ")}
54921
+ ${overlays.join("\n ")}
54922
+ </svg>`;
54923
+ }
54924
+ buildNodeStyleAttrs(style) {
54925
+ const decs = [];
54926
+ if (style.fill)
54927
+ decs.push(`fill:${style.fill}`);
54928
+ if (style.stroke)
54929
+ decs.push(`stroke:${style.stroke}`);
54930
+ if (style.strokeWidth != null)
54931
+ decs.push(`stroke-width:${style.strokeWidth}`);
54932
+ return decs.length ? `style="${decs.join(";")}"` : "";
54933
+ }
54934
+ buildNodeStrokeStyle(style) {
54935
+ const decs = [];
54936
+ if (style.stroke)
54937
+ decs.push(`stroke:${style.stroke}`);
54938
+ if (style.strokeWidth != null)
54939
+ decs.push(`stroke-width:${style.strokeWidth}`);
54940
+ return decs.length ? `style="${decs.join(";")}"` : "";
54941
+ }
54942
+ generateDefs() {
54943
+ const aw = Math.max(8, this.arrowMarkerSize + 2);
54944
+ const ah = Math.max(8, this.arrowMarkerSize + 2);
54945
+ const arefX = Math.max(6, aw);
54946
+ const arefY = Math.max(4, Math.round(ah / 2));
54947
+ return `<defs>
54948
+ <marker id="arrow" viewBox="0 0 ${aw} ${ah}" markerWidth="${aw}" markerHeight="${ah}" refX="${arefX}" refY="${arefY}" orient="auto" markerUnits="userSpaceOnUse">
54949
+ <path d="M0,0 L0,${ah} L${aw},${arefY} z" fill="${this.arrowStroke}" />
54950
+ </marker>
54951
+ <marker id="circle-marker" viewBox="0 0 9 9" markerWidth="9" markerHeight="9" refX="4.5" refY="4.5" orient="auto" markerUnits="userSpaceOnUse">
54952
+ <circle cx="4.5" cy="4.5" r="4.5" fill="${this.arrowStroke}" />
54953
+ </marker>
54954
+ <marker id="cross-marker" viewBox="0 0 12 12" markerWidth="12" markerHeight="12" refX="6" refY="6" orient="auto" markerUnits="userSpaceOnUse">
54955
+ <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" />
54956
+ </marker>
54957
+ </defs>`;
54958
+ }
54959
+ generateNodeWithPad(node, padX, padY) {
54960
+ const x3 = node.x + padX;
54961
+ const y2 = node.y + padY;
54962
+ const cx = x3 + node.width / 2;
54963
+ const cy = y2 + node.height / 2;
54964
+ let shape = "";
54965
+ let labelCenterY = cy;
54966
+ const strokeWidth = node.style?.strokeWidth ?? void 0;
54967
+ const stroke = node.style?.stroke ?? void 0;
54968
+ const fill = node.style?.fill ?? void 0;
54969
+ const styleAttr = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
54970
+ switch (node.shape) {
54971
+ case "rectangle":
54972
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
54973
+ break;
54974
+ case "round":
54975
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="5" ry="5" />`;
54976
+ break;
54977
+ case "stadium":
54978
+ const radius = node.height / 2;
54979
+ shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="${radius}" ry="${radius}" />`;
54980
+ break;
54981
+ case "circle":
54982
+ const r3 = Math.min(node.width, node.height) / 2;
54983
+ shape = `<circle class="node-shape" ${styleAttr} cx="${cx}" cy="${cy}" r="${r3}" />`;
54984
+ break;
54985
+ case "diamond": {
54986
+ const points = [
54987
+ `${cx},${y2}`,
54988
+ // top
54989
+ `${x3 + node.width},${cy}`,
54990
+ // right
54991
+ `${cx},${y2 + node.height}`,
54992
+ // bottom
54993
+ `${x3},${cy}`
54994
+ // left
54995
+ ].join(" ");
54996
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
54997
+ break;
54998
+ }
54999
+ case "hexagon": {
55000
+ const dx = node.width * 0.25;
55001
+ const points = [
55002
+ `${x3 + dx},${y2}`,
55003
+ // top-left
55004
+ `${x3 + node.width - dx},${y2}`,
55005
+ // top-right
55006
+ `${x3 + node.width},${cy}`,
55007
+ // right
55008
+ `${x3 + node.width - dx},${y2 + node.height}`,
55009
+ // bottom-right
55010
+ `${x3 + dx},${y2 + node.height}`,
55011
+ // bottom-left
55012
+ `${x3},${cy}`
55013
+ // left
55014
+ ].join(" ");
55015
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
55016
+ break;
55017
+ }
55018
+ case "parallelogram": {
55019
+ const skew = node.width * 0.15;
55020
+ const points = [
55021
+ `${x3 + skew},${y2}`,
55022
+ // top-left
55023
+ `${x3 + node.width},${y2}`,
55024
+ // top-right
55025
+ `${x3 + node.width - skew},${y2 + node.height}`,
55026
+ // bottom-right
55027
+ `${x3},${y2 + node.height}`
55028
+ // bottom-left
55029
+ ].join(" ");
55030
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
55031
+ break;
55032
+ }
55033
+ case "trapezoid": {
55034
+ const inset = node.width * 0.15;
55035
+ const points = [
55036
+ `${x3 + inset},${y2}`,
55037
+ // top-left
55038
+ `${x3 + node.width - inset},${y2}`,
55039
+ // top-right
55040
+ `${x3 + node.width},${y2 + node.height}`,
55041
+ // bottom-right
55042
+ `${x3},${y2 + node.height}`
55043
+ // bottom-left
55044
+ ].join(" ");
55045
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
55046
+ break;
55047
+ }
55048
+ case "trapezoidAlt": {
55049
+ const inset = node.width * 0.15;
55050
+ const points = [
55051
+ `${x3},${y2}`,
55052
+ // top-left (full width)
55053
+ `${x3 + node.width},${y2}`,
55054
+ // top-right
55055
+ `${x3 + node.width - inset},${y2 + node.height}`,
55056
+ // bottom-right (narrow)
55057
+ `${x3 + inset},${y2 + node.height}`
55058
+ // bottom-left (narrow)
55059
+ ].join(" ");
55060
+ shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
55061
+ break;
55062
+ }
55063
+ case "cylinder": {
55064
+ const rx = Math.max(8, node.width / 2);
55065
+ const ry = Math.max(6, Math.min(node.height * 0.22, node.width * 0.25));
55066
+ const topCY = y2 + ry;
55067
+ const botCY = y2 + node.height - ry;
55068
+ const bodyH = Math.max(0, node.height - ry * 2);
55069
+ const strokeOnly = this.buildNodeStrokeStyle({ stroke, strokeWidth });
55070
+ shape = `<g>
55071
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${topCY}" width="${node.width}" height="${bodyH}" />
55072
+ <ellipse class="node-shape" ${styleAttr} cx="${cx}" cy="${topCY}" rx="${node.width / 2}" ry="${ry}" />
55073
+ <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" />
55074
+ </g>`;
55075
+ labelCenterY = topCY + bodyH / 2;
55076
+ break;
55077
+ }
55078
+ case "subroutine":
55079
+ const insetX = 5;
55080
+ const strokeOnly2 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
55081
+ shape = `<g>
55082
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
55083
+ <line class="node-shape" ${strokeOnly2} x1="${x3 + insetX}" y1="${y2}" x2="${x3 + insetX}" y2="${y2 + node.height}" />
55084
+ <line class="node-shape" ${strokeOnly2} x1="${x3 + node.width - insetX}" y1="${y2}" x2="${x3 + node.width - insetX}" y2="${y2 + node.height}" />
55085
+ </g>`;
55086
+ break;
55087
+ case "double":
55088
+ const gap = 4;
55089
+ const strokeOnly3 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
55090
+ shape = `<g>
55091
+ <rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
55092
+ <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" />
55093
+ </g>`;
55094
+ break;
55095
+ default:
55096
+ const s3 = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
55097
+ shape = `<rect ${s3} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
55098
+ }
55099
+ const text = this.generateWrappedText(node.label, cx, labelCenterY, node.width - 20);
55100
+ return `<g id="${node.id}">
55101
+ ${shape}
55102
+ ${text}
55103
+ </g>`;
55104
+ }
55105
+ generateWrappedText(text, x3, y2, maxWidth) {
55106
+ if (text.includes("<")) {
55107
+ return this.generateRichText(text, x3, y2, maxWidth);
55108
+ }
55109
+ const charWidth = 7;
55110
+ const maxCharsPerLine = Math.floor(maxWidth / charWidth);
55111
+ if (maxCharsPerLine <= 0 || text.length <= maxCharsPerLine) {
55112
+ const dyOffset = this.fontSize * 0.35;
55113
+ return `<text class="node-label" x="${x3}" y="${y2 + dyOffset}" text-anchor="middle">${this.escapeXml(text)}</text>`;
55114
+ }
55115
+ const words = text.split(" ");
55116
+ const lines = [];
55117
+ let currentLine = "";
55118
+ for (const word of words) {
55119
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
55120
+ if (testLine.length > maxCharsPerLine && currentLine) {
55121
+ lines.push(currentLine);
55122
+ currentLine = word;
55123
+ } else {
55124
+ currentLine = testLine;
55125
+ }
55126
+ }
55127
+ if (currentLine) {
55128
+ lines.push(currentLine);
55129
+ }
55130
+ const lineHeight = 18;
55131
+ const totalHeight = (lines.length - 1) * lineHeight;
55132
+ const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
55133
+ const tspans = lines.map((line, i3) => {
55134
+ const lineY = startY + i3 * lineHeight;
55135
+ return `<tspan x="${x3}" y="${lineY}" text-anchor="middle">${this.escapeXml(line)}</tspan>`;
55136
+ }).join("\n ");
55137
+ return `<text class="node-label">
55138
+ ${tspans}
55139
+ </text>`;
55140
+ }
55141
+ // Basic HTML-aware text renderer supporting <br>, <b>/<strong>, <i>/<em>, <u>
55142
+ generateRichText(html, x3, y2, maxWidth) {
55143
+ html = this.normalizeHtml(html);
55144
+ const segments = [];
55145
+ const re = /<\/?(br|b|strong|i|em|u)\s*\/?\s*>/gi;
55146
+ let lastIndex = 0;
55147
+ const state2 = { bold: false, italic: false, underline: false };
55148
+ const pushText = (t3) => {
55149
+ if (!t3)
55150
+ return;
55151
+ segments.push({ text: this.htmlDecode(t3), bold: state2.bold, italic: state2.italic, underline: state2.underline });
55152
+ };
55153
+ let m3;
55154
+ while (m3 = re.exec(html)) {
55155
+ pushText(html.slice(lastIndex, m3.index));
55156
+ const tag2 = m3[0].toLowerCase();
55157
+ const name14 = m3[1].toLowerCase();
55158
+ const isClose = tag2.startsWith("</");
55159
+ if (name14 === "br") {
55160
+ segments.push({ text: "", br: true });
55161
+ } else if (name14 === "b" || name14 === "strong") {
55162
+ state2.bold = !isClose ? true : false;
55163
+ } else if (name14 === "i" || name14 === "em") {
55164
+ state2.italic = !isClose ? true : false;
55165
+ } else if (name14 === "u") {
55166
+ state2.underline = !isClose ? true : false;
55167
+ }
55168
+ lastIndex = re.lastIndex;
55169
+ }
55170
+ pushText(html.slice(lastIndex));
55171
+ const lines = [];
55172
+ const charWidth = 7;
55173
+ const maxCharsPerLine = Math.max(1, Math.floor(maxWidth / charWidth));
55174
+ let current = [];
55175
+ let currentLen = 0;
55176
+ const flush = () => {
55177
+ if (current.length) {
55178
+ lines.push(current);
55179
+ current = [];
55180
+ currentLen = 0;
55181
+ }
55182
+ };
55183
+ const splitWords = (s3) => {
55184
+ if (!s3.text)
55185
+ return [s3];
55186
+ const words = s3.text.split(/(\s+)/);
55187
+ return words.map((w3) => ({ ...s3, text: w3 }));
55188
+ };
55189
+ for (const seg of segments) {
55190
+ if (seg.br) {
55191
+ flush();
55192
+ continue;
55193
+ }
55194
+ for (const w3 of splitWords(seg)) {
55195
+ const wlen = w3.text.length;
55196
+ if (currentLen + wlen > maxCharsPerLine && currentLen > 0) {
55197
+ flush();
55198
+ }
55199
+ current.push(w3);
55200
+ currentLen += wlen;
55201
+ }
55202
+ }
55203
+ flush();
55204
+ const lineHeight = 18;
55205
+ const totalHeight = (lines.length - 1) * lineHeight;
55206
+ const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
55207
+ const tspans = [];
55208
+ for (let i3 = 0; i3 < lines.length; i3++) {
55209
+ const lineY = startY + i3 * lineHeight;
55210
+ let acc = "";
55211
+ let cursorX = x3;
55212
+ const inner = [];
55213
+ let buffer = "";
55214
+ let style = { bold: false, italic: false, underline: false };
55215
+ const flushInline = () => {
55216
+ if (!buffer)
55217
+ return;
55218
+ const styleAttr = `${style.bold ? 'font-weight="bold" ' : ""}${style.italic ? 'font-style="italic" ' : ""}${style.underline ? 'text-decoration="underline" ' : ""}`;
55219
+ inner.push(`<tspan ${styleAttr}>${this.escapeXml(buffer)}</tspan>`);
55220
+ buffer = "";
55221
+ };
55222
+ for (const w3 of lines[i3]) {
55223
+ const wStyle = { bold: !!w3.bold, italic: !!w3.italic, underline: !!w3.underline };
55224
+ if (wStyle.bold !== style.bold || wStyle.italic !== style.italic || wStyle.underline !== style.underline) {
55225
+ flushInline();
55226
+ style = wStyle;
55227
+ }
55228
+ buffer += w3.text;
55229
+ }
55230
+ flushInline();
55231
+ tspans.push(`<tspan x="${x3}" y="${lineY}" text-anchor="middle">${inner.join("")}</tspan>`);
55232
+ }
55233
+ return `<text font-family="${this.fontFamily}" font-size="${this.fontSize}" fill="#333">${tspans.join("\n ")}</text>`;
55234
+ }
55235
+ normalizeHtml(s3) {
55236
+ let out = s3.replace(/<\s+/g, "<").replace(/\s+>/g, ">").replace(/<\s*\//g, "</").replace(/\s*\/\s*>/g, "/>").replace(/<\s*(br)\s*>/gi, "<$1/>");
55237
+ return out;
55238
+ }
55239
+ htmlDecode(s3) {
55240
+ return s3.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#39;/g, "'");
55241
+ }
55242
+ generateEdge(edge, padX, padY, nodeMap) {
55243
+ if (!edge.points || edge.points.length < 2) {
55244
+ return { path: "" };
55245
+ }
55246
+ const points = edge.points.map((p3) => ({ x: p3.x + padX, y: p3.y + padY }));
55247
+ const segData = this.buildSmoothSegments(points);
55248
+ let strokeDasharray = "";
55249
+ let strokeWidth = 1.5;
55250
+ let markerEnd = "";
55251
+ let markerStart = "";
55252
+ switch (edge.type) {
55253
+ case "open":
55254
+ markerEnd = "";
55255
+ break;
55256
+ case "dotted":
55257
+ strokeDasharray = "3,3";
55258
+ break;
55259
+ case "thick":
55260
+ strokeWidth = 3;
55261
+ break;
55262
+ case "invisible":
55263
+ strokeDasharray = "0,100000";
55264
+ markerEnd = "";
55265
+ break;
55266
+ }
55267
+ const mStart = edge.markerStart;
55268
+ const mEnd = edge.markerEnd;
55269
+ const sourceNode = nodeMap[edge.source];
55270
+ const targetNode = nodeMap[edge.target];
55271
+ let boundaryStart = points[0];
55272
+ let boundaryEnd = points[points.length - 1];
55273
+ if (sourceNode && points.length >= 2) {
55274
+ const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
55275
+ boundaryStart = this.intersectSegmentsStart(pseudo, sourceNode).start;
55276
+ }
55277
+ if (targetNode && points.length >= 2) {
55278
+ const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
55279
+ const after = this.intersectSegmentsEnd(pseudo, targetNode);
55280
+ boundaryEnd = after.segs.length ? after.segs[after.segs.length - 1].to : boundaryEnd;
55281
+ }
55282
+ const pathParts = [];
55283
+ pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
55284
+ let startFlat = points.length >= 2 ? points[1] : boundaryStart;
55285
+ if (points.length >= 2) {
55286
+ const svx = points[1].x - boundaryStart.x;
55287
+ const svy = points[1].y - boundaryStart.y;
55288
+ const slen = Math.hypot(svx, svy) || 1;
55289
+ const SFLAT = Math.min(22, Math.max(10, slen * 0.15));
55290
+ startFlat = { x: boundaryStart.x + svx / slen * SFLAT, y: boundaryStart.y + svy / slen * SFLAT };
55291
+ pathParts.push(`L${startFlat.x},${startFlat.y}`);
55292
+ }
55293
+ const orthogonal = edge.pathMode === "orthogonal";
55294
+ if (points.length >= 4 && !orthogonal) {
55295
+ const pts = [points[0], ...points, points[points.length - 1]];
55296
+ for (let i3 = 1; i3 < pts.length - 3; i3++) {
55297
+ const p0 = pts[i3 - 1];
55298
+ const p1 = pts[i3];
55299
+ const p22 = pts[i3 + 1];
55300
+ const p3 = pts[i3 + 2];
55301
+ const c1x = p1.x + (p22.x - p0.x) / 6;
55302
+ const c1y = p1.y + (p22.y - p0.y) / 6;
55303
+ const c2x = p22.x - (p3.x - p1.x) / 6;
55304
+ const c2y = p22.y - (p3.y - p1.y) / 6;
55305
+ pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${p22.x},${p22.y}`);
55306
+ }
55307
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55308
+ } else if (points.length === 3 && !orthogonal) {
55309
+ const p0 = boundaryStart, p1 = points[1], p22 = boundaryEnd;
55310
+ const ax = boundaryEnd.x - p1.x;
55311
+ const ay = boundaryEnd.y - p1.y;
55312
+ const alen = Math.hypot(ax, ay) || 1;
55313
+ const FLAT_IN = Math.min(20, Math.max(10, alen * 0.15));
55314
+ const preEnd = { x: boundaryEnd.x - ax / alen * FLAT_IN, y: boundaryEnd.y - ay / alen * FLAT_IN };
55315
+ const sdx = startFlat.x - boundaryStart.x;
55316
+ const sdy = startFlat.y - boundaryStart.y;
55317
+ const sdirx = sdx === 0 && sdy === 0 ? p1.x - p0.x : sdx;
55318
+ const sdiry = sdx === 0 && sdy === 0 ? p1.y - p0.y : sdy;
55319
+ const sdlen = Math.hypot(sdirx, sdiry) || 1;
55320
+ const c1len = Math.min(40, Math.max(12, sdlen * 1.2));
55321
+ const c1x = startFlat.x + sdirx / sdlen * c1len;
55322
+ const c1y = startFlat.y + sdiry / sdlen * c1len;
55323
+ const dirx = (boundaryEnd.x - p1.x) / alen;
55324
+ const diry = (boundaryEnd.y - p1.y) / alen;
55325
+ const c2x = preEnd.x - dirx * (FLAT_IN * 0.6);
55326
+ const c2y = preEnd.y - diry * (FLAT_IN * 0.6);
55327
+ pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${preEnd.x},${preEnd.y}`);
55328
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55329
+ } else {
55330
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55331
+ }
55332
+ if (orthogonal) {
55333
+ pathParts.length = 0;
55334
+ pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
55335
+ for (const p3 of points.slice(1, -1))
55336
+ pathParts.push(`L${p3.x},${p3.y}`);
55337
+ pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
55338
+ }
55339
+ const pathData = pathParts.join(" ");
55340
+ let edgeElement = `<path class="edge-path" d="${pathData}" stroke-linecap="round" stroke-linejoin="round"`;
55341
+ if (strokeDasharray) {
55342
+ edgeElement += ` stroke-dasharray="${strokeDasharray}"`;
55343
+ }
55344
+ const startMarkUrl = mStart === "arrow" ? "url(#arrow)" : mStart === "circle" ? "url(#circle-marker)" : mStart === "cross" ? "url(#cross-marker)" : "";
55345
+ const endMarkUrl = mEnd === "arrow" ? "url(#arrow)" : mEnd === "circle" ? "url(#circle-marker)" : mEnd === "cross" ? "url(#cross-marker)" : markerEnd || "";
55346
+ if (startMarkUrl && mStart !== "arrow")
55347
+ edgeElement += ` marker-start="${startMarkUrl}"`;
55348
+ if (endMarkUrl && mEnd !== "arrow")
55349
+ edgeElement += ` marker-end="${endMarkUrl}"`;
55350
+ edgeElement += " />";
55351
+ if (edge.label) {
55352
+ const pos = this.pointAtRatio(points, 0.55);
55353
+ const text = this.escapeXml(edge.label);
55354
+ const padding = 4;
55355
+ const fontSize = this.fontSize - 3;
55356
+ const width = Math.max(18, Math.min(220, text.length * 6 + padding * 2));
55357
+ const height = 14;
55358
+ const x3 = pos.x - width / 2;
55359
+ const y2 = pos.y - height / 2;
55360
+ const labelBg = `<rect class="edge-label-bg" x="${x3}" y="${y2}" width="${width}" height="${height}" rx="3" />`;
55361
+ const labelText = `<text class="edge-label-text" x="${pos.x}" y="${pos.y}" text-anchor="middle" dominant-baseline="middle">${text}</text>`;
55362
+ let overlay2 = "";
55363
+ const prevEndL = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
55364
+ const vxl = boundaryEnd.x - prevEndL.x;
55365
+ const vyl = boundaryEnd.y - prevEndL.y;
55366
+ const vlenl = Math.hypot(vxl, vyl) || 1;
55367
+ const uxl = vxl / vlenl;
55368
+ const uyl = vyl / vlenl;
55369
+ const nxl = -uyl;
55370
+ const nyl = uxl;
55371
+ const triLenL = 8;
55372
+ const triWL = 6;
55373
+ const p1xL = boundaryEnd.x, p1yL = boundaryEnd.y;
55374
+ const baseXL = boundaryEnd.x - uxl * triLenL;
55375
+ const baseYL = boundaryEnd.y - uyl * triLenL;
55376
+ const p2xL = baseXL + nxl * (triWL / 2), p2yL = baseYL + nyl * (triWL / 2);
55377
+ const p3xL = baseXL - nxl * (triWL / 2), p3yL = baseYL - nyl * (triWL / 2);
55378
+ overlay2 += triangleAtEnd(prevEndL, boundaryEnd, this.arrowStroke);
55379
+ if (mStart === "arrow" && points.length >= 2) {
55380
+ const firstLeg = points[1];
55381
+ const svx = boundaryStart.x - firstLeg.x;
55382
+ const svy = boundaryStart.y - firstLeg.y;
55383
+ const slen = Math.hypot(svx, svy) || 1;
55384
+ const sux = svx / slen;
55385
+ const suy = svy / slen;
55386
+ const snx = -suy;
55387
+ const sny = sux;
55388
+ const sbaseX = boundaryStart.x - sux * triLenL;
55389
+ const sbaseY = boundaryStart.y - suy * triLenL;
55390
+ overlay2 += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
55391
+ }
55392
+ const pathGroup = `<g>
55393
+ ${edgeElement}
55394
+ ${labelBg}
55395
+ ${labelText}
55396
+ ${overlay2}
55397
+ </g>`;
55398
+ return { path: pathGroup };
55399
+ }
55400
+ let overlay = "";
55401
+ const prevEnd = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
55402
+ const vx = boundaryEnd.x - prevEnd.x;
55403
+ const vy = boundaryEnd.y - prevEnd.y;
55404
+ const vlen = Math.hypot(vx, vy) || 1;
55405
+ const ux = vx / vlen;
55406
+ const uy = vy / vlen;
55407
+ const nx = -uy;
55408
+ const ny = ux;
55409
+ const triLen = 8;
55410
+ const triW = 6;
55411
+ const p1x = boundaryEnd.x, p1y = boundaryEnd.y;
55412
+ const baseX = boundaryEnd.x - ux * triLen;
55413
+ const baseY = boundaryEnd.y - uy * triLen;
55414
+ const p2x = baseX + nx * (triW / 2), p2y = baseY + ny * (triW / 2);
55415
+ const p3x = baseX - nx * (triW / 2), p3y = baseY - ny * (triW / 2);
55416
+ if (mEnd === "arrow")
55417
+ overlay += triangleAtEnd(prevEnd, boundaryEnd, this.arrowStroke);
55418
+ if (mStart === "arrow" && points.length >= 2) {
55419
+ const firstLeg = points[1];
55420
+ const svx = boundaryStart.x - firstLeg.x;
55421
+ const svy = boundaryStart.y - firstLeg.y;
55422
+ const slen = Math.hypot(svx, svy) || 1;
55423
+ const sux = svx / slen;
55424
+ const suy = svy / slen;
55425
+ const snx = -suy;
55426
+ const sny = sux;
55427
+ overlay += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
55428
+ }
55429
+ if (overlay) {
55430
+ const grouped = `<g>${edgeElement}
55431
+ ${overlay}</g>`;
55432
+ return { path: grouped };
55433
+ }
55434
+ return { path: edgeElement };
55435
+ }
55436
+ // --- helpers ---
55437
+ buildSmoothSegments(points) {
55438
+ if (points.length < 2) {
55439
+ const p3 = points[0] || { x: 0, y: 0 };
55440
+ return { start: p3, segs: [] };
55441
+ }
55442
+ if (points.length === 2) {
55443
+ const p0 = points[0];
55444
+ const p1 = points[1];
55445
+ const c1 = { x: p0.x + (p1.x - p0.x) / 3, y: p0.y + (p1.y - p0.y) / 3 };
55446
+ const c22 = { x: p0.x + 2 * (p1.x - p0.x) / 3, y: p0.y + 2 * (p1.y - p0.y) / 3 };
55447
+ return { start: p0, segs: [{ c1, c2: c22, to: p1 }] };
55448
+ }
55449
+ const pts = [points[0], ...points, points[points.length - 1]];
55450
+ const segs = [];
55451
+ const firstIdx = 1;
55452
+ const lastIdx = pts.length - 3;
55453
+ const midFactor = 1;
55454
+ const endFactor = 0.35;
55455
+ const FLAT_LEN = 28;
55456
+ for (let i3 = 1; i3 < pts.length - 2; i3++) {
55457
+ const p0 = pts[i3 - 1];
55458
+ const p1 = pts[i3];
55459
+ const p22 = pts[i3 + 1];
55460
+ const p3 = pts[i3 + 2];
55461
+ const f1 = i3 === firstIdx ? endFactor : midFactor;
55462
+ const f22 = i3 === lastIdx ? endFactor : midFactor;
55463
+ let c1 = { x: p1.x + (p22.x - p0.x) / 6 * f1, y: p1.y + (p22.y - p0.y) / 6 * f1 };
55464
+ let c22 = { x: p22.x - (p3.x - p1.x) / 6 * f22, y: p22.y - (p3.y - p1.y) / 6 * f22 };
55465
+ if (i3 === firstIdx) {
55466
+ const dx = p22.x - p1.x, dy = p22.y - p1.y;
55467
+ const len = Math.hypot(dx, dy) || 1;
55468
+ const t3 = Math.min(FLAT_LEN, len * 0.5);
55469
+ c1 = { x: p1.x + dx / len * t3, y: p1.y + dy / len * t3 };
55470
+ }
55471
+ if (i3 === lastIdx) {
55472
+ const dx = p22.x - p1.x, dy = p22.y - p1.y;
55473
+ const len = Math.hypot(dx, dy) || 1;
55474
+ const t3 = Math.min(FLAT_LEN, len * 0.5);
55475
+ c22 = { x: p22.x - dx / len * t3, y: p22.y - dy / len * t3 };
55476
+ }
55477
+ segs.push({ c1, c2: c22, to: { x: p22.x, y: p22.y } });
55478
+ }
55479
+ return { start: pts[1], segs };
55480
+ }
55481
+ pathFromSegments(data2) {
55482
+ let d3 = `M${data2.start.x},${data2.start.y}`;
55483
+ for (const s3 of data2.segs) {
55484
+ d3 += ` C${s3.c1.x},${s3.c1.y} ${s3.c2.x},${s3.c2.y} ${s3.to.x},${s3.to.y}`;
55485
+ }
55486
+ return d3;
55487
+ }
55488
+ trimSegmentsEnd(data2, cut) {
55489
+ const segs = data2.segs.slice();
55490
+ if (!segs.length)
55491
+ return data2;
55492
+ const last2 = { ...segs[segs.length - 1] };
55493
+ const vx = last2.to.x - last2.c2.x;
55494
+ const vy = last2.to.y - last2.c2.y;
55495
+ const len = Math.hypot(vx, vy) || 1;
55496
+ const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
55497
+ const nx = vx / len;
55498
+ const ny = vy / len;
55499
+ const newTo = { x: last2.to.x - nx * eff, y: last2.to.y - ny * eff };
55500
+ last2.to = newTo;
55501
+ segs[segs.length - 1] = last2;
55502
+ return { start: data2.start, segs };
55503
+ }
55504
+ trimSegmentsStart(data2, cut) {
55505
+ const segs = data2.segs.slice();
55506
+ if (!segs.length)
55507
+ return data2;
55508
+ const first2 = { ...segs[0] };
55509
+ const vx = first2.c1.x - data2.start.x;
55510
+ const vy = first2.c1.y - data2.start.y;
55511
+ const len = Math.hypot(vx, vy) || 1;
55512
+ const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
55513
+ const nx = vx / len;
55514
+ const ny = vy / len;
55515
+ const newStart = { x: data2.start.x + nx * eff, y: data2.start.y + ny * eff };
55516
+ return { start: newStart, segs };
55517
+ }
55518
+ // ---- shape intersections ----
55519
+ intersectSegmentsEnd(data2, node) {
55520
+ if (!data2.segs.length)
55521
+ return data2;
55522
+ const last2 = data2.segs[data2.segs.length - 1];
55523
+ const p1 = last2.c2;
55524
+ const p22 = last2.to;
55525
+ const hit = this.intersectLineWithNode(p1, p22, node);
55526
+ if (hit) {
55527
+ const segs = data2.segs.slice();
55528
+ segs[segs.length - 1] = { ...last2, to: hit };
55529
+ return { start: data2.start, segs };
55530
+ }
55531
+ return data2;
55532
+ }
55533
+ intersectSegmentsStart(data2, node) {
55534
+ if (!data2.segs.length)
55535
+ return data2;
55536
+ const first2 = data2.segs[0];
55537
+ const p1 = data2.start;
55538
+ const p22 = first2.c1;
55539
+ const hit = this.intersectLineWithNode(p1, p22, node);
55540
+ if (hit) {
55541
+ return { start: hit, segs: data2.segs };
55542
+ }
55543
+ return data2;
55544
+ }
55545
+ intersectLineWithNode(p1, p22, node) {
55546
+ const shape = node.shape;
55547
+ const rectPoly = () => [
55548
+ { x: node.x, y: node.y },
55549
+ { x: node.x + node.width, y: node.y },
55550
+ { x: node.x + node.width, y: node.y + node.height },
55551
+ { x: node.x, y: node.y + node.height }
55552
+ ];
55553
+ switch (shape) {
55554
+ case "circle": {
55555
+ const cx = node.x + node.width / 2;
55556
+ const cy = node.y + node.height / 2;
55557
+ const r3 = Math.min(node.width, node.height) / 2;
55558
+ return this.lineCircleIntersection(p1, p22, { cx, cy, r: r3 });
55559
+ }
55560
+ case "diamond": {
55561
+ const cx = node.x + node.width / 2;
55562
+ const cy = node.y + node.height / 2;
55563
+ 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 }];
55564
+ return this.linePolygonIntersection(p1, p22, poly);
55565
+ }
55566
+ case "hexagon": {
55567
+ const s3 = Math.max(10, node.width * 0.2);
55568
+ const poly = [
55569
+ { x: node.x + s3, y: node.y },
55570
+ { x: node.x + node.width - s3, y: node.y },
55571
+ { x: node.x + node.width, y: node.y + node.height / 2 },
55572
+ { x: node.x + node.width - s3, y: node.y + node.height },
55573
+ { x: node.x + s3, y: node.y + node.height },
55574
+ { x: node.x, y: node.y + node.height / 2 }
55575
+ ];
55576
+ return this.linePolygonIntersection(p1, p22, poly);
55577
+ }
55578
+ case "parallelogram": {
55579
+ const o3 = Math.min(node.width * 0.25, node.height * 0.6);
55580
+ const poly = [
55581
+ { x: node.x + o3, y: node.y },
55582
+ { x: node.x + node.width, y: node.y },
55583
+ { x: node.x + node.width - o3, y: node.y + node.height },
55584
+ { x: node.x, y: node.y + node.height }
55585
+ ];
55586
+ return this.linePolygonIntersection(p1, p22, poly);
55587
+ }
55588
+ case "trapezoid": {
55589
+ const o3 = Math.min(node.width * 0.2, node.height * 0.5);
55590
+ const poly = [
55591
+ { x: node.x + o3, y: node.y },
55592
+ { x: node.x + node.width - o3, y: node.y },
55593
+ { x: node.x + node.width, y: node.y + node.height },
55594
+ { x: node.x, y: node.y + node.height }
55595
+ ];
55596
+ return this.linePolygonIntersection(p1, p22, poly);
55597
+ }
55598
+ case "trapezoidAlt": {
55599
+ const o3 = Math.min(node.width * 0.2, node.height * 0.5);
55600
+ const poly = [
55601
+ { x: node.x, y: node.y },
55602
+ { x: node.x + node.width, y: node.y },
55603
+ { x: node.x + node.width - o3, y: node.y + node.height },
55604
+ { x: node.x + o3, y: node.y + node.height }
55605
+ ];
55606
+ return this.linePolygonIntersection(p1, p22, poly);
55607
+ }
55608
+ case "stadium": {
55609
+ const r3 = Math.min(node.height / 2, node.width / 2);
55610
+ const rect = [
55611
+ { x: node.x + r3, y: node.y },
55612
+ { x: node.x + node.width - r3, y: node.y },
55613
+ { x: node.x + node.width - r3, y: node.y + node.height },
55614
+ { x: node.x + r3, y: node.y + node.height }
55615
+ ];
55616
+ const hitRect = this.linePolygonIntersection(p1, p22, rect);
55617
+ if (hitRect)
55618
+ return hitRect;
55619
+ const left = this.lineCircleIntersection(p1, p22, { cx: node.x + r3, cy: node.y + node.height / 2, r: r3 });
55620
+ const right = this.lineCircleIntersection(p1, p22, { cx: node.x + node.width - r3, cy: node.y + node.height / 2, r: r3 });
55621
+ const pick = (...pts) => {
55622
+ let best = null;
55623
+ let bestd = -Infinity;
55624
+ for (const pt of pts)
55625
+ if (pt) {
55626
+ const d3 = -((pt.x - p22.x) ** 2 + (pt.y - p22.y) ** 2);
55627
+ if (d3 > bestd) {
55628
+ bestd = d3;
55629
+ best = pt;
55630
+ }
55631
+ }
55632
+ return best;
55633
+ };
55634
+ return pick(left, right);
55635
+ }
55636
+ default: {
55637
+ return this.linePolygonIntersection(p1, p22, rectPoly());
55638
+ }
55639
+ }
55640
+ }
55641
+ lineCircleIntersection(p1, p22, c3) {
55642
+ const dx = p22.x - p1.x;
55643
+ const dy = p22.y - p1.y;
55644
+ const fx = p1.x - c3.cx;
55645
+ const fy = p1.y - c3.cy;
55646
+ const a3 = dx * dx + dy * dy;
55647
+ const b3 = 2 * (fx * dx + fy * dy);
55648
+ const cc2 = fx * fx + fy * fy - c3.r * c3.r;
55649
+ const disc = b3 * b3 - 4 * a3 * cc2;
55650
+ if (disc < 0)
55651
+ return null;
55652
+ const s3 = Math.sqrt(disc);
55653
+ const t1 = (-b3 - s3) / (2 * a3);
55654
+ const t22 = (-b3 + s3) / (2 * a3);
55655
+ const ts = [t1, t22].filter((t4) => t4 >= 0 && t4 <= 1);
55656
+ if (!ts.length)
55657
+ return null;
55658
+ const t3 = Math.max(...ts);
55659
+ return { x: p1.x + dx * t3, y: p1.y + dy * t3 };
55660
+ }
55661
+ linePolygonIntersection(p1, p22, poly) {
55662
+ let bestT = -Infinity;
55663
+ let best = null;
55664
+ for (let i3 = 0; i3 < poly.length; i3++) {
55665
+ const a3 = poly[i3];
55666
+ const b3 = poly[(i3 + 1) % poly.length];
55667
+ const hit = this.segmentIntersection(p1, p22, a3, b3);
55668
+ if (hit && hit.t >= 0 && hit.t <= 1 && hit.u >= 0 && hit.u <= 1) {
55669
+ if (hit.t > bestT) {
55670
+ bestT = hit.t;
55671
+ best = { x: hit.x, y: hit.y };
55672
+ }
55673
+ }
55674
+ }
55675
+ return best;
55676
+ }
55677
+ segmentIntersection(p3, p22, q3, q22) {
55678
+ const r3 = { x: p22.x - p3.x, y: p22.y - p3.y };
55679
+ const s3 = { x: q22.x - q3.x, y: q22.y - q3.y };
55680
+ const rxs = r3.x * s3.y - r3.y * s3.x;
55681
+ if (Math.abs(rxs) < 1e-6)
55682
+ return null;
55683
+ const q_p = { x: q3.x - p3.x, y: q3.y - p3.y };
55684
+ const t3 = (q_p.x * s3.y - q_p.y * s3.x) / rxs;
55685
+ const u3 = (q_p.x * r3.y - q_p.y * r3.x) / rxs;
55686
+ const x3 = p3.x + t3 * r3.x;
55687
+ const y2 = p3.y + t3 * r3.y;
55688
+ return { x: x3, y: y2, t: t3, u: u3 };
55689
+ }
55690
+ pointAtRatio(points, ratio) {
55691
+ const clampRatio = Math.max(0, Math.min(1, ratio));
55692
+ let total = 0;
55693
+ const segs = [];
55694
+ for (let i3 = 0; i3 < points.length - 1; i3++) {
55695
+ const dx = points[i3 + 1].x - points[i3].x;
55696
+ const dy = points[i3 + 1].y - points[i3].y;
55697
+ const len = Math.hypot(dx, dy);
55698
+ segs.push(len);
55699
+ total += len;
55700
+ }
55701
+ if (total === 0)
55702
+ return points[Math.floor(points.length / 2)];
55703
+ let target = total * clampRatio;
55704
+ for (let i3 = 0; i3 < segs.length; i3++) {
55705
+ if (target <= segs[i3]) {
55706
+ const t3 = segs[i3] === 0 ? 0 : target / segs[i3];
55707
+ return {
55708
+ x: points[i3].x + (points[i3 + 1].x - points[i3].x) * t3,
55709
+ y: points[i3].y + (points[i3 + 1].y - points[i3].y) * t3
55710
+ };
55711
+ }
55712
+ target -= segs[i3];
55713
+ }
55714
+ return points[points.length - 1];
55715
+ }
55716
+ escapeXml(text) {
55717
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
55718
+ }
55719
+ };
55720
+ }
55721
+ });
55722
+
55723
+ // node_modules/@probelabs/maid/out/renderer/pie-builder.js
55724
+ function unquote(s3) {
55725
+ if (!s3)
55726
+ return s3;
55727
+ const first2 = s3.charAt(0);
55728
+ const last2 = s3.charAt(s3.length - 1);
55729
+ if (first2 === '"' && last2 === '"' || first2 === "'" && last2 === "'") {
55730
+ const inner = s3.slice(1, -1);
55731
+ return inner.replace(/\\(["'])/g, "$1");
55732
+ }
55733
+ return s3;
55734
+ }
55735
+ function buildPieModel(text) {
55736
+ const errors = [];
55737
+ const lex = tokenize2(text);
55738
+ for (const e3 of lex.errors) {
55739
+ errors.push({
55740
+ line: e3.line ?? 1,
55741
+ column: e3.column ?? 1,
55742
+ message: e3.message,
55743
+ code: "PIE_LEX",
55744
+ severity: "error"
55745
+ });
55746
+ }
55747
+ parserInstance2.reset();
55748
+ parserInstance2.input = lex.tokens;
55749
+ const cst = parserInstance2.diagram();
55750
+ for (const e3 of parserInstance2.errors) {
55751
+ const t3 = e3.token;
55752
+ errors.push({
55753
+ line: t3?.startLine ?? 1,
55754
+ column: t3?.startColumn ?? 1,
55755
+ message: e3.message,
55756
+ code: "PIE_PARSE",
55757
+ severity: "error"
55758
+ });
55759
+ }
55760
+ const model = { title: void 0, showData: false, slices: [] };
55761
+ if (!cst || !cst.children)
55762
+ return { model, errors };
55763
+ if (cst.children.ShowDataKeyword && cst.children.ShowDataKeyword.length > 0) {
55764
+ model.showData = true;
55765
+ }
55766
+ const statements = cst.children.statement ?? [];
55767
+ for (const st of statements) {
55768
+ if (st.children?.titleStmt) {
55769
+ const tnode = st.children.titleStmt[0];
55770
+ const parts = [];
55771
+ const collect = (k3) => {
55772
+ const arr = tnode.children?.[k3] ?? [];
55773
+ for (const tok of arr)
55774
+ parts.push(unquote(tok.image));
55775
+ };
55776
+ collect("QuotedString");
55777
+ collect("Text");
55778
+ collect("NumberLiteral");
55779
+ const title = parts.join(" ").trim();
55780
+ if (title)
55781
+ model.title = title;
55782
+ } else if (st.children?.sliceStmt) {
55783
+ const snode = st.children.sliceStmt[0];
55784
+ const labelTok = snode.children?.sliceLabel?.[0]?.children?.QuotedString?.[0];
55785
+ const numTok = snode.children?.NumberLiteral?.[0];
55786
+ if (labelTok && numTok) {
55787
+ const label = unquote(labelTok.image).trim();
55788
+ const value = Number(numTok.image);
55789
+ if (!Number.isNaN(value)) {
55790
+ model.slices.push({ label, value });
55791
+ }
55792
+ }
55793
+ }
55794
+ }
55795
+ return { model, errors };
55796
+ }
55797
+ var init_pie_builder = __esm({
55798
+ "node_modules/@probelabs/maid/out/renderer/pie-builder.js"() {
55799
+ init_lexer3();
55800
+ init_parser3();
55801
+ }
55802
+ });
55803
+
55804
+ // node_modules/@probelabs/maid/out/renderer/pie-renderer.js
55805
+ function polarToCartesian(cx, cy, r3, angleRad) {
55806
+ return { x: cx + r3 * Math.cos(angleRad), y: cy + r3 * Math.sin(angleRad) };
55807
+ }
55808
+ function renderPie(model, opts = {}) {
55809
+ let width = Math.max(320, Math.floor(opts.width ?? 640));
55810
+ const height = Math.max(240, Math.floor(opts.height ?? 400));
55811
+ const pad = 24;
55812
+ const titleH = model.title ? 28 : 0;
55813
+ let cx = width / 2;
55814
+ const cy = (height + titleH) / 2 + (model.title ? 8 : 0);
55815
+ const baseRadius = Math.max(40, Math.min(width, height - titleH) / 2 - pad);
55816
+ const slices = model.slices.filter((s3) => Math.max(0, s3.value) > 0);
55817
+ const total = slices.reduce((a3, s3) => a3 + Math.max(0, s3.value), 0);
55818
+ const LEG_SW = 12;
55819
+ const LEG_GAP = 8;
55820
+ const LEG_VSPACE = 18;
55821
+ const legendItems = slices.map((s3) => `${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
55822
+ const legendTextWidth = legendItems.length ? Math.max(...legendItems.map((t3) => measureText(t3, 12))) : 0;
55823
+ const legendBlockWidth = legendItems.length ? LEG_SW + LEG_GAP + legendTextWidth + pad : 0;
55824
+ if (legendItems.length) {
55825
+ const neededWidth = pad + baseRadius * 2 + legendBlockWidth + pad;
55826
+ if (neededWidth > width)
55827
+ width = Math.ceil(neededWidth);
55828
+ }
55829
+ let radius = baseRadius;
55830
+ if (legendItems.length) {
55831
+ const leftPad = Math.max(pad, (width - legendBlockWidth - radius * 2) / 2);
55832
+ cx = leftPad + radius;
55833
+ }
55834
+ let start = -Math.PI / 2;
55835
+ let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`;
55836
+ svg += `
55837
+ <style>
55838
+ .pie-title { font-family: Arial, sans-serif; font-size: 16px; font-weight: 600; fill: #222; }
55839
+ .slice-label { font-family: Arial, sans-serif; font-size: 12px; fill: #222; dominant-baseline: middle; }
55840
+ .leader { stroke: #444; stroke-width: 1; fill: none; }
55841
+ .pieCircle { stroke: black; stroke-width: 2px; opacity: 0.7; }
55842
+ .pieOuterCircle { stroke: black; stroke-width: 2px; fill: none; }
55843
+ </style>`;
55844
+ if (model.title) {
55845
+ svg += `
55846
+ <text class="pie-title" x="${cx}" y="${pad + 8}" text-anchor="middle">${escapeXml(model.title)}</text>`;
55847
+ }
55848
+ svg += `
55849
+ <g class="pie" aria-label="pie">`;
55850
+ const minOutsideAngle = 0.35;
55851
+ slices.forEach((s3, i3) => {
55852
+ const pct = total > 0 ? Math.max(0, s3.value) / total : 0;
55853
+ const angle = 2 * Math.PI * pct;
55854
+ const end = start + angle;
55855
+ const large = angle > Math.PI ? 1 : 0;
55856
+ const c0 = polarToCartesian(cx, cy, radius, start);
55857
+ const c1 = polarToCartesian(cx, cy, radius, end);
55858
+ const d3 = [
55859
+ `M ${cx} ${cy}`,
55860
+ `L ${c0.x.toFixed(2)} ${c0.y.toFixed(2)}`,
55861
+ `A ${radius} ${radius} 0 ${large} 1 ${c1.x.toFixed(2)} ${c1.y.toFixed(2)}`,
55862
+ "Z"
55863
+ ].join(" ");
55864
+ const fill = s3.color || palette(i3);
55865
+ svg += `
55866
+ <path d="${d3}" class="pieCircle" fill="${fill}" />`;
55867
+ const mid = (start + end) / 2;
55868
+ const cos = Math.cos(mid);
55869
+ const sin = Math.sin(mid);
55870
+ const percentLabel = escapeXml(formatPercent(s3.value, total));
55871
+ if (angle < minOutsideAngle) {
55872
+ const r1 = radius * 0.9;
55873
+ const r22 = radius * 1.06;
55874
+ const p1 = polarToCartesian(cx, cy, r1, mid);
55875
+ const p22 = polarToCartesian(cx, cy, r22, mid);
55876
+ const hlen = 12;
55877
+ const anchorLeft = cos < 0;
55878
+ const hx = anchorLeft ? p22.x - hlen : p22.x + hlen;
55879
+ const hy = p22.y;
55880
+ svg += `
55881
+ <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)}" />`;
55882
+ const tx = anchorLeft ? hx - 2 : hx + 2;
55883
+ const tAnchor = anchorLeft ? "end" : "start";
55884
+ svg += `
55885
+ <text class="slice-label" x="${tx.toFixed(2)}" y="${hy.toFixed(2)}" text-anchor="${tAnchor}">${percentLabel}</text>`;
55886
+ } else {
55887
+ const lr = radius * 0.62;
55888
+ const lp = { x: cx + lr * cos, y: cy + lr * sin };
55889
+ const tAnchor = Math.abs(cos) < 0.2 ? "middle" : cos > 0 ? "start" : "end";
55890
+ const avail = lr;
55891
+ const textW = measureText(percentLabel, 12);
55892
+ const anchor = textW > avail * 1.2 ? "middle" : tAnchor;
55893
+ svg += `
55894
+ <text class="slice-label" x="${lp.x.toFixed(2)}" y="${lp.y.toFixed(2)}" text-anchor="${anchor}">${percentLabel}</text>`;
55895
+ }
55896
+ start = end;
55897
+ });
55898
+ const rimStroke = opts.rimStroke || "black";
55899
+ const rimWidth = opts.rimStrokeWidth != null ? String(opts.rimStrokeWidth) : "2px";
55900
+ svg += `
55901
+ </g>
55902
+ <circle class="pie-rim pieOuterCircle" cx="${cx}" cy="${cy}" r="${radius}" stroke="${rimStroke}" stroke-width="${rimWidth}" fill="none" />`;
55903
+ if (legendItems.length) {
55904
+ const legendX = cx + radius + pad / 2;
55905
+ const totalH = legendItems.length * LEG_VSPACE;
55906
+ let legendY = cy - totalH / 2 + 10;
55907
+ svg += `
55908
+ <g class="legend">`;
55909
+ slices.forEach((s3, i3) => {
55910
+ const y2 = legendY + i3 * LEG_VSPACE;
55911
+ const fill = s3.color || palette(i3);
55912
+ const text = escapeXml(`${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
55913
+ svg += `
55914
+ <rect x="${legendX}" y="${y2 - LEG_SW + 6}" width="${LEG_SW}" height="${LEG_SW}" fill="${fill}" stroke="${fill}" stroke-width="1" />`;
55915
+ svg += `
55916
+ <text class="slice-label legend-text" x="${legendX + LEG_SW + LEG_GAP}" y="${y2}" text-anchor="start">${text}</text>`;
55917
+ });
55918
+ svg += `
55919
+ </g>`;
55920
+ }
55921
+ svg += `
55922
+ </svg>`;
55923
+ return svg;
55924
+ }
55925
+ var init_pie_renderer = __esm({
55926
+ "node_modules/@probelabs/maid/out/renderer/pie-renderer.js"() {
55927
+ init_utils4();
55928
+ }
55929
+ });
55930
+
55931
+ // node_modules/@probelabs/maid/out/renderer/sequence-builder.js
55932
+ function textFromTokens(tokens) {
55933
+ if (!tokens || tokens.length === 0)
55934
+ return "";
55935
+ const parts = [];
55936
+ for (const t3 of tokens) {
55937
+ const img = t3.image;
55938
+ if (!img)
55939
+ continue;
55940
+ if (t3.tokenType && t3.tokenType.name === "QuotedString") {
55941
+ if (img.startsWith('"') && img.endsWith('"'))
55942
+ parts.push(img.slice(1, -1));
55943
+ else if (img.startsWith("'") && img.endsWith("'"))
55944
+ parts.push(img.slice(1, -1));
55945
+ else
55946
+ parts.push(img);
55947
+ } else {
55948
+ parts.push(img);
55949
+ }
55950
+ }
55951
+ return parts.join(" ").replace(/\s+/g, " ").trim();
55952
+ }
55953
+ function actorRefToText(refCst) {
55954
+ const ch = refCst.children || {};
55955
+ const toks = [];
55956
+ ["Identifier", "QuotedString", "NumberLiteral", "Text"].forEach((k3) => {
55957
+ const a3 = ch[k3];
55958
+ a3?.forEach((t3) => toks.push(t3));
55959
+ });
55960
+ toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
55961
+ return textFromTokens(toks);
55962
+ }
55963
+ function lineRemainderToText(lineRem) {
55964
+ if (!lineRem)
55965
+ return void 0;
55966
+ const ch = lineRem.children || {};
55967
+ const toks = [];
55968
+ const order = [
55969
+ "Identifier",
55970
+ "NumberLiteral",
55971
+ "QuotedString",
55972
+ "Text",
55973
+ "Plus",
55974
+ "Minus",
55975
+ "Comma",
55976
+ "Colon",
55977
+ "LParen",
55978
+ "RParen",
55979
+ "AndKeyword",
55980
+ "ElseKeyword",
55981
+ "OptKeyword",
55982
+ "OptionKeyword",
55983
+ "LoopKeyword",
55984
+ "ParKeyword",
55985
+ "RectKeyword",
55986
+ "CriticalKeyword",
55987
+ "BreakKeyword",
55988
+ "BoxKeyword",
55989
+ "EndKeyword",
55990
+ "NoteKeyword",
55991
+ "LeftKeyword",
55992
+ "RightKeyword",
55993
+ "OverKeyword",
55994
+ "OfKeyword",
55995
+ "AutonumberKeyword",
55996
+ "OffKeyword",
55997
+ "LinkKeyword",
55998
+ "LinksKeyword",
55999
+ "CreateKeyword",
56000
+ "DestroyKeyword",
56001
+ "ParticipantKeyword",
56002
+ "ActorKeyword",
56003
+ "ActivateKeyword",
56004
+ "DeactivateKeyword"
56005
+ ];
56006
+ for (const k3 of order)
56007
+ ch[k3]?.forEach((t3) => toks.push(t3));
56008
+ toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
56009
+ return textFromTokens(toks) || void 0;
56010
+ }
56011
+ function canonicalId(raw) {
56012
+ const t3 = raw.trim().replace(/\s+/g, "_");
56013
+ return t3;
56014
+ }
56015
+ function ensureParticipant(map4, byDisplay, idLike, display) {
56016
+ const idGuess = canonicalId(idLike);
56017
+ const existing = map4.get(idGuess) || (byDisplay.get(idLike) ? map4.get(byDisplay.get(idLike)) : void 0);
56018
+ if (existing)
56019
+ return existing;
56020
+ const p3 = { id: idGuess, display: display || idLike };
56021
+ map4.set(p3.id, p3);
56022
+ byDisplay.set(p3.display, p3.id);
56023
+ return p3;
56024
+ }
56025
+ function msgFromArrow(arrowCst) {
56026
+ const ch = arrowCst.children || {};
56027
+ if (ch.BidirAsyncDotted)
56028
+ return { line: "dotted", start: "arrow", end: "arrow", async: true };
56029
+ if (ch.BidirAsync)
56030
+ return { line: "solid", start: "arrow", end: "arrow", async: true };
56031
+ if (ch.DottedAsync)
56032
+ return { line: "dotted", start: "none", end: "arrow", async: true };
56033
+ if (ch.Async)
56034
+ return { line: "solid", start: "none", end: "arrow", async: true };
56035
+ if (ch.Dotted)
56036
+ return { line: "dotted", start: "none", end: "arrow" };
56037
+ if (ch.Solid)
56038
+ return { line: "solid", start: "none", end: "arrow" };
56039
+ if (ch.DottedCross)
56040
+ return { line: "dotted", start: "none", end: "cross" };
56041
+ if (ch.Cross)
56042
+ return { line: "solid", start: "none", end: "cross" };
56043
+ if (ch.DottedOpen)
56044
+ return { line: "dotted", start: "none", end: "open" };
56045
+ if (ch.Open)
56046
+ return { line: "solid", start: "none", end: "open" };
56047
+ return { line: "solid", start: "none", end: "arrow" };
56048
+ }
56049
+ function buildSequenceModel(text) {
56050
+ const { tokens } = tokenize3(text);
56051
+ parserInstance3.input = tokens;
56052
+ const cst = parserInstance3.diagram();
56053
+ const participantsMap = /* @__PURE__ */ new Map();
56054
+ const byDisplay = /* @__PURE__ */ new Map();
56055
+ const events = [];
56056
+ let autonumber = { on: false };
56057
+ const diagramChildren = cst.children || {};
56058
+ const lines = diagramChildren.line || [];
56059
+ const openBlocks = [];
56060
+ function processLineNode(ln) {
56061
+ const ch = ln.children || {};
56062
+ if (ch.participantDecl) {
56063
+ const decl = ch.participantDecl[0];
56064
+ const dch = decl.children || {};
56065
+ const ref1 = dch.actorRef?.[0];
56066
+ const ref2 = dch.actorRef?.[1];
56067
+ const idText = actorRefToText(ref1);
56068
+ const aliasText = ref2 ? actorRefToText(ref2) : void 0;
56069
+ const id = canonicalId(idText);
56070
+ const display = aliasText || idText;
56071
+ const p3 = ensureParticipant(participantsMap, byDisplay, id, display);
56072
+ events.push({ kind: "create", actor: p3.id, display: p3.display });
56073
+ return;
56074
+ }
56075
+ if (ch.autonumberStmt) {
56076
+ const stmt = ch.autonumberStmt[0];
56077
+ const sch = stmt.children || {};
56078
+ autonumber = { on: true };
56079
+ const nums = sch.NumberLiteral || [];
56080
+ if (nums.length >= 1)
56081
+ autonumber.start = Number(nums[0].image);
56082
+ if (nums.length >= 2)
56083
+ autonumber.step = Number(nums[1].image);
56084
+ if (sch.OffKeyword)
56085
+ autonumber = { on: false };
56086
+ return;
56087
+ }
56088
+ if (ch.activateStmt) {
56089
+ const st = ch.activateStmt[0];
56090
+ const sch = st.children || {};
56091
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
56092
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
56093
+ events.push({ kind: "activate", actor: p3.id });
56094
+ return;
56095
+ }
56096
+ if (ch.deactivateStmt) {
56097
+ const st = ch.deactivateStmt[0];
56098
+ const sch = st.children || {};
56099
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
56100
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
56101
+ events.push({ kind: "deactivate", actor: p3.id });
56102
+ return;
56103
+ }
56104
+ if (ch.createStmt) {
56105
+ const st = ch.createStmt[0];
56106
+ const sch = st.children || {};
56107
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
56108
+ const alias = sch.lineRemainder ? lineRemainderToText(sch.lineRemainder[0]) : void 0;
56109
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt, alias || idTxt);
56110
+ events.push({ kind: "create", actor: p3.id, display: p3.display });
56111
+ return;
56112
+ }
56113
+ if (ch.destroyStmt) {
56114
+ const st = ch.destroyStmt[0];
56115
+ const sch = st.children || {};
56116
+ const idTxt = actorRefToText(sch.actorRef?.[0]);
56117
+ const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
56118
+ events.push({ kind: "destroy", actor: p3.id });
56119
+ return;
56120
+ }
56121
+ if (ch.noteStmt) {
56122
+ const st = ch.noteStmt[0];
56123
+ const sch = st.children || {};
56124
+ const text2 = lineRemainderToText(sch.lineRemainder?.[0]) || "";
56125
+ if (sch.LeftKeyword || sch.RightKeyword) {
56126
+ const pos = sch.LeftKeyword ? "leftOf" : "rightOf";
56127
+ const actorTxt = actorRefToText(sch.actorRef?.[0]);
56128
+ const p3 = ensureParticipant(participantsMap, byDisplay, actorTxt);
56129
+ const note = { pos, actors: [p3.id], text: text2 };
56130
+ events.push({ kind: "note", note });
56131
+ } else if (sch.OverKeyword) {
56132
+ const a1 = actorRefToText(sch.actorRef?.[0]);
56133
+ const a22 = sch.actorRef?.[1] ? actorRefToText(sch.actorRef?.[1]) : void 0;
56134
+ const p1 = ensureParticipant(participantsMap, byDisplay, a1);
56135
+ const ids = [p1.id];
56136
+ if (a22) {
56137
+ const p22 = ensureParticipant(participantsMap, byDisplay, a22);
56138
+ ids.push(p22.id);
56139
+ }
56140
+ events.push({ kind: "note", note: { pos: "over", actors: ids, text: text2 } });
56141
+ }
56142
+ return;
56143
+ }
56144
+ const blockKinds = [
56145
+ { key: "altBlock", type: "alt", branchKeys: [{ key: "ElseKeyword", kind: "else" }] },
56146
+ { key: "optBlock", type: "opt" },
56147
+ { key: "loopBlock", type: "loop" },
56148
+ { key: "parBlock", type: "par", branchKeys: [{ key: "AndKeyword", kind: "and" }] },
56149
+ { key: "criticalBlock", type: "critical", branchKeys: [{ key: "OptionKeyword", kind: "option" }] },
56150
+ { key: "breakBlock", type: "break" },
56151
+ { key: "rectBlock", type: "rect" },
56152
+ { key: "boxBlock", type: "box" }
56153
+ ];
56154
+ let handledBlock = false;
56155
+ for (const spec of blockKinds) {
56156
+ if (ch[spec.key]) {
56157
+ handledBlock = true;
56158
+ const bnode = ch[spec.key][0];
56159
+ const bch = bnode.children || {};
56160
+ const title = lineRemainderToText(bch.lineRemainder?.[0]);
56161
+ const block = { type: spec.type, title, branches: spec.branchKeys ? [] : void 0 };
56162
+ openBlocks.push(block);
56163
+ events.push({ kind: "block-start", block });
56164
+ if (spec.branchKeys) {
56165
+ const newlines = bch.Newline || [];
56166
+ const branchKey = spec.branchKeys[0].key;
56167
+ const branchTokArr = bch[branchKey];
56168
+ const lrArr = bch.lineRemainder;
56169
+ if (branchTokArr && branchTokArr.length) {
56170
+ const lr = (lrArr || []).slice(1);
56171
+ for (let i3 = 0; i3 < branchTokArr.length; i3++) {
56172
+ const title2 = lr[i3] ? lineRemainderToText(lr[i3]) : void 0;
56173
+ const br = { kind: spec.branchKeys[0].kind, title: title2 };
56174
+ block.branches.push(br);
56175
+ events.push({ kind: "block-branch", block, branch: br });
56176
+ }
56177
+ }
56178
+ }
56179
+ events.push({ kind: "block-end", block });
56180
+ openBlocks.pop();
56181
+ break;
56182
+ }
56183
+ }
56184
+ if (handledBlock)
56185
+ return;
56186
+ if (ch.messageStmt) {
56187
+ const st = ch.messageStmt[0];
56188
+ const sch = st.children || {};
56189
+ const fromTxt = actorRefToText(sch.actorRef?.[0]);
56190
+ const toTxt = actorRefToText(sch.actorRef?.[1]);
56191
+ const from = ensureParticipant(participantsMap, byDisplay, fromTxt).id;
56192
+ const to = ensureParticipant(participantsMap, byDisplay, toTxt).id;
56193
+ const arrow = msgFromArrow(sch.arrow?.[0]);
56194
+ const text2 = lineRemainderToText(sch.lineRemainder?.[0]);
56195
+ const activateTarget = !!sch.Plus;
56196
+ const deactivateTarget = !!sch.Minus;
56197
+ const msg = { from, to, text: text2, line: arrow.line, startMarker: arrow.start, endMarker: arrow.end, async: arrow.async, activateTarget, deactivateTarget };
56198
+ events.push({ kind: "message", msg });
56199
+ return;
56200
+ }
56201
+ if (ch.linkStmt) {
56202
+ events.push({ kind: "noop" });
56203
+ return;
56204
+ }
56205
+ events.push({ kind: "noop" });
56206
+ }
56207
+ function collectInnerLines(blockNode) {
56208
+ const out = [];
56209
+ const ch = blockNode.children || {};
56210
+ for (const key of Object.keys(ch)) {
56211
+ const arr = ch[key];
56212
+ if (Array.isArray(arr)) {
56213
+ for (const node of arr) {
56214
+ if (node && typeof node === "object" && node.name === "line")
56215
+ out.push(node);
56216
+ }
56217
+ }
56218
+ }
56219
+ return out;
56220
+ }
56221
+ for (const ln of lines) {
56222
+ processLineNode(ln);
56223
+ const ch = ln.children || {};
56224
+ 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];
56225
+ if (block) {
56226
+ for (const inner of collectInnerLines(block))
56227
+ processLineNode(inner);
56228
+ }
56229
+ }
56230
+ return {
56231
+ participants: Array.from(participantsMap.values()),
56232
+ events,
56233
+ autonumber: autonumber.on === true || autonumber.on === false ? autonumber : { on: false }
56234
+ };
56235
+ }
56236
+ var init_sequence_builder = __esm({
56237
+ "node_modules/@probelabs/maid/out/renderer/sequence-builder.js"() {
56238
+ init_lexer4();
56239
+ init_parser4();
56240
+ }
56241
+ });
56242
+
56243
+ // node_modules/@probelabs/maid/out/renderer/sequence-layout.js
56244
+ function layoutSequence(model) {
56245
+ const order = [];
56246
+ const seen = /* @__PURE__ */ new Set();
56247
+ const partById = new Map(model.participants.map((p3) => [p3.id, p3]));
56248
+ function touch(id) {
56249
+ if (!seen.has(id)) {
56250
+ seen.add(id);
56251
+ order.push(id);
56252
+ }
56253
+ }
56254
+ for (const ev of model.events) {
56255
+ if (ev.kind === "message") {
56256
+ touch(ev.msg.from);
56257
+ touch(ev.msg.to);
56258
+ }
56259
+ if (ev.kind === "note") {
56260
+ ev.note.actors.forEach(touch);
56261
+ }
56262
+ if (ev.kind === "activate" || ev.kind === "deactivate" || ev.kind === "create" || ev.kind === "destroy")
56263
+ touch(ev.actor);
56264
+ }
56265
+ for (const p3 of model.participants)
56266
+ touch(p3.id);
56267
+ const participants = [];
56268
+ let x3 = MARGIN_X;
56269
+ for (const id of order) {
56270
+ const p3 = partById.get(id) || { id, display: id };
56271
+ const w3 = Math.max(COL_MIN, measureText(p3.display, ACTOR_FONT_SIZE) + ACTOR_PAD_X * 2);
56272
+ participants.push({ id, display: p3.display, x: x3, y: MARGIN_Y, width: w3, height: ACTOR_H });
56273
+ x3 += w3 + MARGIN_X;
56274
+ }
56275
+ const width = Math.max(320, x3);
56276
+ const rowIndexForEvent = /* @__PURE__ */ new Map();
56277
+ let row = 0;
56278
+ const openBlocks = [];
56279
+ function consumeRow(idx) {
56280
+ rowIndexForEvent.set(idx, row++);
56281
+ }
56282
+ model.events.forEach((ev, idx) => {
56283
+ switch (ev.kind) {
56284
+ case "message":
56285
+ consumeRow(idx);
56286
+ break;
56287
+ case "note":
56288
+ consumeRow(idx);
56289
+ break;
56290
+ case "block-start":
56291
+ openBlocks.push({ block: ev.block, startRow: row, branches: [] });
56292
+ consumeRow(idx);
56293
+ break;
56294
+ case "block-branch": {
56295
+ const top = openBlocks[openBlocks.length - 1];
56296
+ if (top)
56297
+ top.branches.push({ title: ev.branch.title, row });
56298
+ consumeRow(idx);
56299
+ break;
56300
+ }
56301
+ case "block-end":
56302
+ break;
56303
+ case "activate":
56304
+ case "deactivate":
56305
+ case "create":
56306
+ case "destroy":
56307
+ case "noop":
56308
+ break;
56309
+ }
56310
+ });
56311
+ const lifelineTop = MARGIN_Y + ACTOR_H + LIFELINE_GAP;
56312
+ const contentHeight = row * ROW_H;
56313
+ const height = lifelineTop + contentHeight + MARGIN_Y + ACTOR_H;
56314
+ const lifelines = participants.map((p3) => ({ x: p3.x + p3.width / 2, y1: lifelineTop, y2: height - MARGIN_Y - ACTOR_H }));
56315
+ function yForRow(r3) {
56316
+ return lifelineTop + r3 * ROW_H + ROW_H / 2;
56317
+ }
56318
+ const col = new Map(participants.map((p3) => [p3.id, p3]));
56319
+ const messages = [];
56320
+ const notes = [];
56321
+ const blocks = [];
56322
+ const activations = [];
56323
+ const actStack = /* @__PURE__ */ new Map();
56324
+ const startAct = (actor, r3) => {
56325
+ const arr = actStack.get(actor) || [];
56326
+ arr.push(r3);
56327
+ actStack.set(actor, arr);
56328
+ };
56329
+ const endAct = (actor, r3) => {
56330
+ const arr = actStack.get(actor) || [];
56331
+ const start = arr.pop();
56332
+ if (start != null) {
56333
+ const p3 = col.get(actor);
56334
+ if (p3) {
56335
+ activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(r3) - yForRow(start) });
56336
+ }
56337
+ }
56338
+ actStack.set(actor, arr);
56339
+ };
56340
+ const openForLayout = [];
56341
+ model.events.forEach((ev, idx) => {
56342
+ const r3 = rowIndexForEvent.has(idx) ? rowIndexForEvent.get(idx) : null;
56343
+ switch (ev.kind) {
56344
+ case "message": {
56345
+ const p1 = col.get(ev.msg.from), p22 = col.get(ev.msg.to);
56346
+ if (p1 && p22 && r3 != null) {
56347
+ const y2 = yForRow(r3);
56348
+ const x1 = p1.x + p1.width / 2;
56349
+ const x22 = p22.x + p22.width / 2;
56350
+ 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 });
56351
+ if (ev.msg.activateTarget)
56352
+ startAct(ev.msg.to, r3);
56353
+ if (ev.msg.deactivateTarget)
56354
+ endAct(ev.msg.to, r3);
56355
+ const top = openForLayout[openForLayout.length - 1];
56356
+ if (top)
56357
+ top.lastRow = r3;
56358
+ }
56359
+ break;
56360
+ }
56361
+ case "note": {
56362
+ if (r3 == null)
56363
+ break;
56364
+ const estLines = (text, width2) => {
56365
+ const charsPerLine = Math.max(8, Math.floor((width2 - NOTE_PAD * 2) / 7));
56366
+ const length = text ? text.length : 0;
56367
+ return Math.max(1, Math.ceil(length / charsPerLine));
56368
+ };
56369
+ const y2 = yForRow(r3) - NOTE_PAD;
56370
+ if (ev.note.pos === "over") {
56371
+ const [a3, b3] = ev.note.actors;
56372
+ const p1 = col.get(a3), p22 = b3 ? col.get(b3) : p1;
56373
+ if (p1 && p22) {
56374
+ const left = Math.min(p1.x + p1.width / 2, p22.x + p22.width / 2);
56375
+ const right = Math.max(p1.x + p1.width / 2, p22.x + p22.width / 2);
56376
+ const w3 = right - left + NOTE_PAD * 2;
56377
+ const lines = estLines(ev.note.text, w3);
56378
+ const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
56379
+ notes.push({ x: left - NOTE_PAD, y: y2, width: w3, height: h3, text: ev.note.text, anchor: "over" });
56380
+ }
56381
+ } else {
56382
+ const actor = ev.note.actors[0];
56383
+ const p3 = col.get(actor);
56384
+ if (p3) {
56385
+ const leftSide = ev.note.pos === "leftOf";
56386
+ const x4 = leftSide ? p3.x - NOTE_W - 10 : p3.x + p3.width + 10;
56387
+ const lines = estLines(ev.note.text, NOTE_W);
56388
+ const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
56389
+ notes.push({ x: x4, y: y2, width: NOTE_W, height: h3, text: ev.note.text, anchor: leftSide ? "left" : "right" });
56390
+ }
56391
+ }
56392
+ const top = openForLayout[openForLayout.length - 1];
56393
+ if (top && r3 != null)
56394
+ top.lastRow = r3;
56395
+ break;
56396
+ }
56397
+ case "activate":
56398
+ if (r3 != null)
56399
+ startAct(ev.actor, r3);
56400
+ break;
56401
+ case "deactivate":
56402
+ if (r3 != null)
56403
+ endAct(ev.actor, r3);
56404
+ break;
56405
+ case "block-start": {
56406
+ const startRow = r3 != null ? r3 : row;
56407
+ openForLayout.push({ block: ev.block, startRow, branches: [] });
56408
+ break;
56409
+ }
56410
+ case "block-branch": {
56411
+ const top = openForLayout[openForLayout.length - 1];
56412
+ if (top && r3 != null) {
56413
+ top.branches.push({ title: ev.branch.title, row: r3 });
56414
+ top.lastRow = r3;
56415
+ }
56416
+ break;
56417
+ }
56418
+ case "block-end": {
56419
+ const top = openForLayout.pop();
56420
+ if (top) {
56421
+ const first2 = participants.length > 0 ? participants[0] : void 0;
56422
+ const last2 = participants.length > 0 ? participants[participants.length - 1] : void 0;
56423
+ const left = first2 ? first2.x : MARGIN_X;
56424
+ const right = last2 ? last2.x + last2.width : left + 200;
56425
+ const yTop = yForRow(top.startRow) - ROW_H / 2 - (BLOCK_PAD + TITLE_EXTRA_TOP);
56426
+ const endRow = top.lastRow != null ? top.lastRow : top.startRow;
56427
+ const yBot = yForRow(endRow) + ROW_H / 2 + BLOCK_PAD;
56428
+ 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 };
56429
+ if (top.branches.length)
56430
+ layout.branches = top.branches.map((b3) => ({ title: b3.title, y: yForRow(b3.row) - ROW_H / 2 }));
56431
+ blocks.push(layout);
56432
+ }
56433
+ break;
56434
+ }
56435
+ default:
56436
+ break;
56437
+ }
56438
+ });
56439
+ const lastRow = row;
56440
+ for (const [actor, arr] of actStack.entries()) {
56441
+ while (arr.length) {
56442
+ const start = arr.pop();
56443
+ const p3 = col.get(actor);
56444
+ if (p3)
56445
+ activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(lastRow) - yForRow(start) });
56446
+ }
56447
+ }
56448
+ return { width, height, participants, lifelines, messages, notes, blocks, activations };
56449
+ }
56450
+ 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;
56451
+ var init_sequence_layout = __esm({
56452
+ "node_modules/@probelabs/maid/out/renderer/sequence-layout.js"() {
56453
+ init_utils4();
56454
+ MARGIN_X = 24;
56455
+ MARGIN_Y = 24;
56456
+ ACTOR_FONT_SIZE = 16;
56457
+ ACTOR_H = 32;
56458
+ LIFELINE_GAP = 4;
56459
+ ACTOR_PAD_X = 12;
56460
+ COL_MIN = 110;
56461
+ ROW_H = 36;
56462
+ NOTE_W = 160;
56463
+ NOTE_PAD = 8;
56464
+ BLOCK_PAD = 8;
56465
+ TITLE_EXTRA_TOP = 12;
56466
+ }
56467
+ });
56468
+
56469
+ // node_modules/@probelabs/maid/out/renderer/sequence-renderer.js
56470
+ function renderSequence(model, opts = {}) {
56471
+ const layout = layoutSequence(model);
56472
+ const svgParts = [];
56473
+ const width = Math.ceil(layout.width);
56474
+ const height = Math.ceil(layout.height);
56475
+ svgParts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width + 50}" height="${height + 40}" viewBox="-50 -10 ${width + 50} ${height + 40}">`);
56476
+ const sharedCss = buildSharedCss({
56477
+ fontFamily: "Arial, sans-serif",
56478
+ fontSize: 14,
56479
+ nodeFill: "#eef0ff",
56480
+ nodeStroke: "#3f3f3f",
56481
+ edgeStroke: "#555555"
56482
+ });
56483
+ svgParts.push(` <style>${sharedCss}</style>`);
56484
+ for (const p3 of layout.participants)
56485
+ drawParticipant(svgParts, p3);
56486
+ for (const b3 of layout.blocks)
56487
+ svgParts.push(blockBackground(b3.x, b3.y, b3.width, b3.height, 0));
56488
+ for (const l3 of layout.lifelines)
56489
+ svgParts.push(` <line class="lifeline" x1="${l3.x}" y1="${l3.y1}" x2="${l3.x}" y2="${l3.y2}"/>`);
56490
+ for (const a3 of layout.activations)
56491
+ svgParts.push(` <rect class="activation" x="${a3.x}" y="${a3.y}" width="${a3.width}" height="${a3.height}" />`);
56492
+ let counter = model.autonumber?.on ? model.autonumber.start ?? 1 : void 0;
56493
+ const step = model.autonumber?.on ? model.autonumber.step ?? 1 : void 0;
56494
+ for (const m3 of layout.messages) {
56495
+ drawMessage(svgParts, m3);
56496
+ const label = formatMessageLabel(m3.text, counter);
56497
+ if (label)
56498
+ drawMessageLabel(svgParts, m3, label, counter);
56499
+ if (counter != null)
56500
+ counter += step;
56501
+ }
56502
+ for (const n3 of layout.notes)
56503
+ drawNote(svgParts, n3);
56504
+ for (const b3 of layout.blocks) {
56505
+ const title = b3.title ? `${b3.type}: ${b3.title}` : b3.type;
56506
+ const branches = (b3.branches || []).map((br) => ({ y: br.y, title: br.title }));
56507
+ svgParts.push(blockOverlay(b3.x, b3.y, b3.width, b3.height, title, branches, 0, "left", "left", 0));
56508
+ }
56509
+ for (const p3 of layout.participants)
56510
+ drawParticipantBottom(svgParts, p3, layout);
56511
+ svgParts.push("</svg>");
56512
+ let svg = svgParts.join("\n");
56513
+ if (opts.theme)
56514
+ svg = applySequenceTheme(svg, opts.theme);
56515
+ return svg;
56516
+ }
56517
+ function drawParticipant(out, p3) {
56518
+ out.push(` <g class="actor" transform="translate(${p3.x},${p3.y})">`);
56519
+ out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
56520
+ out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
56521
+ out.push(" </g>");
56522
+ }
56523
+ function drawParticipantBottom(out, p3, layout) {
56524
+ const lifeline = layout.lifelines.find((l3) => Math.abs(l3.x - (p3.x + p3.width / 2)) < 1e-3);
56525
+ const y2 = lifeline ? lifeline.y2 : layout.height - 28;
56526
+ out.push(` <g class="actor" transform="translate(${p3.x},${y2})">`);
56527
+ out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
56528
+ out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
56529
+ out.push(" </g>");
56530
+ }
56531
+ function drawMessage(out, m3) {
56532
+ const cls = `msg-line ${m3.line}`.trim();
56533
+ const x1 = m3.x1, x22 = m3.x2, y2 = m3.y;
56534
+ out.push(` <path class="${cls}" d="M ${x1} ${y2} L ${x22} ${y2}" />`);
56535
+ const start = { x: x1, y: y2 };
56536
+ const end = { x: x22, y: y2 };
56537
+ if (m3.endMarker === "arrow")
56538
+ out.push(" " + triangleAtEnd(start, end));
56539
+ if (m3.startMarker === "arrow")
56540
+ out.push(" " + triangleAtStart(start, end));
56541
+ if (m3.endMarker === "open")
56542
+ out.push(` <circle class="openhead" cx="${x22}" cy="${y2}" r="4" />`);
56543
+ if (m3.startMarker === "open")
56544
+ out.push(` <circle class="openhead" cx="${x1}" cy="${y2}" r="4" />`);
56545
+ if (m3.endMarker === "cross")
56546
+ 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>`);
56547
+ if (m3.startMarker === "cross")
56548
+ 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>`);
56549
+ }
56550
+ function formatMessageLabel(text, counter) {
56551
+ if (!text && counter == null)
56552
+ return void 0;
56553
+ if (counter != null && text)
56554
+ return `${counter}: ${text}`;
56555
+ if (counter != null)
56556
+ return String(counter);
56557
+ return text;
56558
+ }
56559
+ function drawMessageLabel(out, m3, label, _counter) {
56560
+ const xMid = (m3.x1 + m3.x2) / 2;
56561
+ const h3 = 16;
56562
+ const w3 = Math.max(20, measureText(label, 12) + 10);
56563
+ const x3 = xMid - w3 / 2;
56564
+ const y2 = m3.y - 10 - h3 / 2;
56565
+ out.push(` <rect class="msg-label-bg" x="${x3}" y="${y2}" width="${w3}" height="${h3}" rx="0"/>`);
56566
+ out.push(` <text class="msg-label" x="${xMid}" y="${y2 + h3 / 2}" text-anchor="middle">${escapeXml(label)}</text>`);
56567
+ }
56568
+ function drawNote(out, n3) {
56569
+ out.push(` <g class="note" transform="translate(${n3.x},${n3.y})">`);
56570
+ out.push(` <rect width="${n3.width}" height="${n3.height}" rx="0"/>`);
56571
+ out.push(` <text class="note-text" x="${n3.width / 2}" y="${n3.height / 2 + 4}" text-anchor="middle">${escapeXml(n3.text)}</text>`);
56572
+ out.push(" </g>");
56573
+ }
56574
+ function applySequenceTheme(svg, theme) {
56575
+ let out = svg;
56576
+ if (theme.actorBkg)
56577
+ out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorBkg)};`));
56578
+ if (theme.actorBorder)
56579
+ out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.actorBorder)};`));
56580
+ if (theme.actorTextColor)
56581
+ out = out.replace(/\.actor-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorTextColor)};`));
56582
+ if (theme.lifelineColor)
56583
+ out = out.replace(/\.lifeline\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lifelineColor)};`));
56584
+ if (theme.lineColor)
56585
+ out = out.replace(/\.msg-line\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
56586
+ if (theme.arrowheadColor) {
56587
+ out = out.replace(/\.arrowhead\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.arrowheadColor)};`));
56588
+ out = out.replace(/\.openhead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
56589
+ out = out.replace(/\.crosshead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
56590
+ }
56591
+ if (theme.noteBkg)
56592
+ out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteBkg)};`));
56593
+ if (theme.noteBorder)
56594
+ out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.noteBorder)};`));
56595
+ if (theme.noteTextColor)
56596
+ out = out.replace(/\.note-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteTextColor)};`));
56597
+ if (theme.activationBkg)
56598
+ out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.activationBkg)};`));
56599
+ if (theme.activationBorder)
56600
+ out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.activationBorder)};`));
56601
+ return out;
56602
+ }
56603
+ var init_sequence_renderer = __esm({
56604
+ "node_modules/@probelabs/maid/out/renderer/sequence-renderer.js"() {
56605
+ init_sequence_layout();
56606
+ init_utils4();
56607
+ init_arrow_utils();
56608
+ init_block_utils();
56609
+ init_styles();
56610
+ }
56611
+ });
56612
+
56613
+ // node_modules/@probelabs/maid/out/core/frontmatter.js
56614
+ function parseFrontmatter(input) {
56615
+ const text = input.startsWith("\uFEFF") ? input.slice(1) : input;
56616
+ const lines = text.split(/\r?\n/);
56617
+ if (lines.length < 3 || lines[0].trim() !== "---")
56618
+ return null;
56619
+ let i3 = 1;
56620
+ const block = [];
56621
+ while (i3 < lines.length && lines[i3].trim() !== "---") {
56622
+ block.push(lines[i3]);
56623
+ i3++;
56624
+ }
56625
+ if (i3 >= lines.length)
56626
+ return null;
56627
+ const body = lines.slice(i3 + 1).join("\n");
56628
+ const raw = block.join("\n");
56629
+ const config = {};
56630
+ const themeVars = {};
56631
+ let themeUnderConfig = false;
56632
+ let ctx = "root";
56633
+ for (const line of block) {
56634
+ if (!line.trim())
56635
+ continue;
56636
+ const indent = line.match(/^\s*/)?.[0].length ?? 0;
56637
+ const mKey = line.match(/^\s*([A-Za-z0-9_\-]+):\s*(.*)$/);
56638
+ if (!mKey)
56639
+ continue;
56640
+ const key = mKey[1];
56641
+ let value = mKey[2] || "";
56642
+ if (indent === 0) {
56643
+ if (key === "config") {
56644
+ ctx = "config";
56645
+ continue;
56646
+ }
56647
+ if (key === "themeVariables") {
56648
+ ctx = "theme";
56649
+ continue;
56650
+ }
56651
+ ctx = "root";
56652
+ continue;
56653
+ }
56654
+ if (ctx === "config") {
56655
+ if (indent <= 2 && key !== "pie" && key !== "themeVariables")
56656
+ continue;
56657
+ if (key === "pie") {
56658
+ ctx = "config.pie";
56659
+ ensure(config, "pie", {});
56660
+ continue;
56661
+ }
56662
+ if (key === "themeVariables") {
56663
+ ctx = "theme";
56664
+ themeUnderConfig = true;
56665
+ continue;
56666
+ }
56667
+ continue;
56668
+ }
56669
+ if (ctx === "config.pie") {
56670
+ if (indent < 4) {
56671
+ if (key === "pie") {
56672
+ ctx = "config.pie";
56673
+ ensure(config, "pie", {});
56674
+ continue;
56675
+ }
56676
+ if (key === "themeVariables") {
56677
+ ctx = "theme";
56678
+ themeUnderConfig = true;
56679
+ continue;
56680
+ }
56681
+ ctx = "config";
56682
+ continue;
56683
+ }
56684
+ setKV(config.pie, key, value);
56685
+ continue;
56686
+ }
56687
+ if (ctx === "theme") {
56688
+ if (indent < 2) {
56689
+ ctx = "root";
56690
+ continue;
56691
+ }
56692
+ setKV(themeVars, key, value);
56693
+ continue;
56694
+ }
56695
+ }
56696
+ if (themeUnderConfig && Object.keys(themeVars).length) {
56697
+ ensure(config, "themeVariables", {});
56698
+ Object.assign(config.themeVariables, themeVars);
56699
+ }
56700
+ return { raw, body, config: Object.keys(config).length ? config : void 0, themeVariables: Object.keys(themeVars).length ? themeVars : void 0 };
56701
+ }
56702
+ function ensure(obj, key, def) {
56703
+ if (obj[key] == null)
56704
+ obj[key] = def;
56705
+ }
56706
+ function unquote2(val) {
56707
+ const v3 = val.trim();
56708
+ if (v3.startsWith('"') && v3.endsWith('"') || v3.startsWith("'") && v3.endsWith("'")) {
56709
+ return v3.slice(1, -1);
56710
+ }
56711
+ return v3;
56712
+ }
56713
+ function setKV(target, key, rawValue) {
56714
+ const v3 = unquote2(rawValue);
56715
+ if (v3 === "") {
56716
+ target[key] = "";
56717
+ return;
56718
+ }
56719
+ const num = Number(v3);
56720
+ if (!Number.isNaN(num) && /^-?[0-9]+(\.[0-9]+)?$/.test(v3)) {
56721
+ target[key] = num;
56722
+ return;
56723
+ }
56724
+ if (/^(true|false)$/i.test(v3)) {
56725
+ target[key] = /^true$/i.test(v3);
56726
+ return;
56727
+ }
56728
+ target[key] = v3;
56729
+ }
56730
+ var init_frontmatter = __esm({
56731
+ "node_modules/@probelabs/maid/out/core/frontmatter.js"() {
56732
+ }
56733
+ });
56734
+
56735
+ // node_modules/@probelabs/maid/out/renderer/dot-renderer.js
56736
+ var init_dot_renderer = __esm({
56737
+ "node_modules/@probelabs/maid/out/renderer/dot-renderer.js"() {
56738
+ }
56739
+ });
56740
+
56741
+ // node_modules/@probelabs/maid/out/renderer/index.js
56742
+ function applyPieTheme(svg, theme) {
56743
+ if (!theme)
56744
+ return svg;
56745
+ let out = svg;
56746
+ if (theme.pieOuterStrokeWidth != null || theme.pieStrokeColor) {
56747
+ out = out.replace(/\.pieOuterCircle\s*\{[^}]*\}/, (m3) => {
56748
+ let rule = m3;
56749
+ if (theme.pieStrokeColor)
56750
+ rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`);
56751
+ if (theme.pieOuterStrokeWidth != null)
56752
+ rule = rule.replace(/stroke-width:\s*[^;]+;/, `stroke-width: ${String(theme.pieOuterStrokeWidth)};`);
56753
+ return rule;
56754
+ });
56755
+ if (theme.pieStrokeColor) {
56756
+ out = out.replace(/\.pieCircle\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`));
56757
+ }
56758
+ }
56759
+ if (theme.pieSectionTextColor) {
56760
+ const c3 = String(theme.pieSectionTextColor);
56761
+ out = out.replace(/\.slice-label \{[^}]*\}/, (m3) => m3.replace(/fill:\s*#[0-9A-Fa-f]{3,8}|fill:\s*rgb\([^)]*\)/, `fill: ${c3}`));
56762
+ out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 fill="${c3}">`);
56763
+ }
56764
+ if (theme.pieTitleTextColor) {
56765
+ const c3 = String(theme.pieTitleTextColor);
56766
+ out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 fill="${c3}">`);
56767
+ }
56768
+ if (theme.pieSectionTextSize) {
56769
+ const size = String(theme.pieSectionTextSize);
56770
+ out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 font-size="${size}">`);
56771
+ }
56772
+ if (theme.pieTitleTextSize) {
56773
+ const size = String(theme.pieTitleTextSize);
56774
+ out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 font-size="${size}">`);
56775
+ }
56776
+ const colors = [];
56777
+ for (let i3 = 1; i3 <= 24; i3++) {
56778
+ const key = "pie" + i3;
56779
+ if (theme[key])
56780
+ colors.push(String(theme[key]));
56781
+ }
56782
+ if (colors.length) {
56783
+ let idx = 0;
56784
+ out = out.replace(/<path[^>]*class="pieCircle"[^>]*\sfill="([^"]+)"/g, (_m2) => {
56785
+ const color = colors[idx] ?? null;
56786
+ idx++;
56787
+ if (color)
56788
+ return _m2.replace(/fill="([^"]+)"/, `fill="${color}"`);
56789
+ return _m2;
56790
+ });
56791
+ }
56792
+ return out;
56793
+ }
56794
+ function applyFlowchartTheme(svg, theme) {
56795
+ if (!theme)
56796
+ return svg;
56797
+ let out = svg;
56798
+ if (theme.nodeBkg || theme.nodeBorder) {
56799
+ out = out.replace(/\.node-shape\s*\{[^}]*\}/, (m3) => {
56800
+ let rule = m3;
56801
+ if (theme.nodeBkg)
56802
+ rule = rule.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeBkg)};`);
56803
+ if (theme.nodeBorder)
56804
+ rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.nodeBorder)};`);
56805
+ return rule;
56806
+ });
56807
+ }
56808
+ if (theme.nodeTextColor) {
56809
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeTextColor)};`));
56810
+ }
56811
+ if (theme.lineColor) {
56812
+ out = out.replace(/\.edge-path\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
56813
+ }
56814
+ if (theme.arrowheadColor) {
56815
+ 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)}"`);
56816
+ out = out.replace(/(<circle cx="4\.5" cy="4\.5" r="4\.5"[^>]*)(fill="[^"]*")/g, (_m2, p1) => `${p1}fill="${String(theme.arrowheadColor)}"`);
56817
+ }
56818
+ if (theme.clusterBkg) {
56819
+ out = out.replace(/\.cluster-bg\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterBkg)};`));
56820
+ }
56821
+ if (theme.clusterBorder) {
56822
+ out = out.replace(/\.cluster-border\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.clusterBorder)};`));
56823
+ }
56824
+ if (theme.clusterTextColor) {
56825
+ out = out.replace(/\.cluster-label-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterTextColor)};`));
56826
+ }
56827
+ if (theme.fontFamily)
56828
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-family:\s*[^;]+;/, `font-family: ${String(theme.fontFamily)};`));
56829
+ if (theme.fontSize)
56830
+ out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-size:\s*[^;]+;/, `font-size: ${String(theme.fontSize)};`));
56831
+ return out;
56832
+ }
56833
+ function renderMermaid(text, options = {}) {
56834
+ const renderer = new MermaidRenderer(options.layoutEngine, options.renderer);
56835
+ return renderer.renderAny(text, options);
56836
+ }
56837
+ var MermaidRenderer;
56838
+ var init_renderer = __esm({
56839
+ "node_modules/@probelabs/maid/out/renderer/index.js"() {
56840
+ init_lexer2();
56841
+ init_parser2();
56842
+ init_graph_builder();
56843
+ init_layout();
56844
+ init_svg_generator();
56845
+ init_pie_builder();
56846
+ init_pie_renderer();
56847
+ init_sequence_builder();
56848
+ init_sequence_renderer();
56849
+ init_frontmatter();
56850
+ init_layout();
56851
+ init_svg_generator();
56852
+ init_dot_renderer();
56853
+ MermaidRenderer = class {
56854
+ constructor(layoutEngine, renderer) {
56855
+ this.graphBuilder = new GraphBuilder();
56856
+ this.layoutEngine = layoutEngine || new DagreLayoutEngine();
56857
+ this.renderer = renderer || new SVGRenderer();
56858
+ }
56859
+ /**
56860
+ * Renders a Mermaid flowchart diagram
56861
+ */
56862
+ render(text, options = {}) {
56863
+ const errors = [];
56864
+ const layoutEngine = options.layoutEngine || this.layoutEngine;
56865
+ const renderer = options.renderer || this.renderer;
56866
+ try {
56867
+ const lexResult = tokenize(text);
56868
+ if (lexResult.errors && lexResult.errors.length > 0) {
56869
+ for (const error2 of lexResult.errors) {
56870
+ errors.push({
56871
+ line: error2.line || 1,
56872
+ column: error2.column || 1,
56873
+ message: error2.message,
56874
+ severity: "error",
56875
+ code: "LEXER_ERROR"
56876
+ });
56877
+ }
56878
+ }
56879
+ parserInstance.reset();
56880
+ parserInstance.input = lexResult.tokens;
56881
+ const cst = parserInstance.diagram();
56882
+ if (parserInstance.errors && parserInstance.errors.length > 0) {
56883
+ for (const error2 of parserInstance.errors) {
56884
+ const token = error2.token;
56885
+ errors.push({
56886
+ line: token?.startLine || 1,
56887
+ column: token?.startColumn || 1,
56888
+ message: error2.message,
56889
+ severity: "error",
56890
+ code: "PARSER_ERROR"
56891
+ });
56892
+ }
56893
+ }
56894
+ const graph = this.graphBuilder.build(cst);
56895
+ let layout;
56896
+ try {
56897
+ layout = layoutEngine.layout(graph);
56898
+ } catch (layoutError) {
56899
+ errors.push({
56900
+ line: 1,
56901
+ column: 1,
56902
+ message: layoutError.message || "Layout calculation failed",
56903
+ severity: "error",
56904
+ code: "LAYOUT_ERROR"
56905
+ });
56906
+ return {
56907
+ svg: this.generateErrorSvg(layoutError.message || "Layout calculation failed"),
56908
+ graph,
56909
+ errors
56910
+ };
56911
+ }
56912
+ let svg = renderer.render(layout);
56913
+ if (options.showErrors && errors.length > 0) {
56914
+ svg = this.addErrorOverlays(svg, errors);
56915
+ }
56916
+ return {
56917
+ svg,
56918
+ graph,
56919
+ errors
56920
+ };
56921
+ } catch (error2) {
56922
+ const errorSvg = this.generateErrorSvg(error2.message || "Unknown error occurred");
56923
+ errors.push({
56924
+ line: 1,
56925
+ column: 1,
56926
+ message: error2.message || "Unknown error occurred",
56927
+ severity: "error",
56928
+ code: "RENDER_ERROR"
56929
+ });
56930
+ return {
56931
+ svg: errorSvg,
56932
+ graph: { nodes: [], edges: [], direction: "TD" },
56933
+ errors
56934
+ };
56935
+ }
56936
+ }
56937
+ /**
56938
+ * Renders supported diagram types (flowchart + pie for now)
56939
+ */
56940
+ renderAny(text, options = {}) {
56941
+ let content = text;
56942
+ let theme;
56943
+ if (text.trimStart().startsWith("---")) {
56944
+ const fm = parseFrontmatter(text);
56945
+ if (fm) {
56946
+ content = fm.body;
56947
+ theme = fm.themeVariables || fm.config && fm.config.themeVariables || void 0;
56948
+ }
56949
+ }
56950
+ const firstLine = content.trim().split("\n")[0];
56951
+ if (/^(flowchart|graph)\s+/i.test(firstLine)) {
56952
+ const res = this.render(content, options);
56953
+ const svg2 = theme ? applyFlowchartTheme(res.svg, theme) : res.svg;
56954
+ return { svg: svg2, graph: res.graph, errors: res.errors };
56955
+ }
56956
+ if (/^pie\b/i.test(firstLine)) {
56957
+ try {
56958
+ const { model, errors } = buildPieModel(content);
56959
+ const svg = renderPie(model, {
56960
+ width: options.width,
56961
+ height: options.height,
56962
+ rimStroke: theme?.pieStrokeColor,
56963
+ rimStrokeWidth: theme?.pieOuterStrokeWidth
56964
+ });
56965
+ const themedSvg = applyPieTheme(svg, theme);
56966
+ return { svg: themedSvg, graph: { nodes: [], edges: [], direction: "TD" }, errors };
56967
+ } catch (e3) {
56968
+ const msg = e3?.message || "Pie render error";
56969
+ const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "PIE_RENDER" }];
56970
+ return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
56971
+ }
56972
+ }
56973
+ if (/^sequenceDiagram\b/.test(firstLine)) {
56974
+ try {
56975
+ const model = buildSequenceModel(content);
56976
+ const svg = renderSequence(model, { theme });
56977
+ return { svg, graph: { nodes: [], edges: [], direction: "TD" }, errors: [] };
56978
+ } catch (e3) {
56979
+ const msg = e3?.message || "Sequence render error";
56980
+ const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "SEQUENCE_RENDER" }];
56981
+ return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
56982
+ }
56983
+ }
56984
+ const errorSvg = this.generateErrorSvg("Unsupported diagram type. Rendering supports flowchart, pie, and sequence for now.");
56985
+ return {
56986
+ svg: errorSvg,
56987
+ graph: { nodes: [], edges: [], direction: "TD" },
56988
+ errors: [{
56989
+ line: 1,
56990
+ column: 1,
56991
+ message: "Unsupported diagram type",
56992
+ severity: "error",
56993
+ code: "UNSUPPORTED_TYPE"
56994
+ }]
56995
+ };
56996
+ }
56997
+ addErrorOverlays(svg, errors) {
56998
+ const errorStyle = `
56999
+ <style>
57000
+ .error-indicator {
57001
+ fill: #ff0000;
57002
+ opacity: 0.8;
57003
+ }
57004
+ .error-text {
57005
+ fill: white;
57006
+ font-family: Arial, sans-serif;
57007
+ font-size: 12px;
57008
+ font-weight: bold;
57009
+ }
57010
+ </style>`;
57011
+ const errorIndicator = `
57012
+ <g id="errors">
57013
+ <rect x="5" y="5" width="100" height="25" rx="3" class="error-indicator" />
57014
+ <text x="55" y="20" text-anchor="middle" class="error-text">${errors.length} error${errors.length !== 1 ? "s" : ""}</text>
57015
+ </g>`;
57016
+ return svg.replace("</svg>", `${errorStyle}${errorIndicator}</svg>`);
57017
+ }
57018
+ generateErrorSvg(message) {
57019
+ const width = 400;
57020
+ const height = 200;
57021
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
57022
+ <rect width="${width}" height="${height}" fill="#fee" stroke="#c00" stroke-width="2" />
57023
+ <text x="${width / 2}" y="${height / 2 - 20}" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#c00">
57024
+ Render Error
57025
+ </text>
57026
+ <text x="${width / 2}" y="${height / 2 + 10}" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#666">
57027
+ ${this.wrapText(message, 40).map((line, i3) => `<tspan x="${width / 2}" dy="${i3 === 0 ? 0 : 15}">${this.escapeXml(line)}</tspan>`).join("")}
57028
+ </text>
57029
+ </svg>`;
57030
+ }
57031
+ wrapText(text, maxLength) {
57032
+ const words = text.split(" ");
57033
+ const lines = [];
57034
+ let currentLine = "";
57035
+ for (const word of words) {
57036
+ if (currentLine.length + word.length + 1 <= maxLength) {
57037
+ currentLine += (currentLine ? " " : "") + word;
57038
+ } else {
57039
+ if (currentLine)
57040
+ lines.push(currentLine);
57041
+ currentLine = word;
57042
+ }
57043
+ }
57044
+ if (currentLine)
57045
+ lines.push(currentLine);
57046
+ return lines.slice(0, 3);
57047
+ }
57048
+ escapeXml(text) {
57049
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
57050
+ }
57051
+ };
57052
+ }
57053
+ });
57054
+
57055
+ // node_modules/@probelabs/maid/out/mermaid-compat.js
57056
+ function createMermaidAPI() {
57057
+ return {
57058
+ initialize(_config) {
57059
+ },
57060
+ async render(_id, text, options) {
57061
+ try {
57062
+ const result = renderMermaid(text, options);
57063
+ return { svg: result.svg };
57064
+ } catch (error2) {
57065
+ throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
57066
+ }
57067
+ },
57068
+ renderSync(_id, text, options) {
57069
+ try {
57070
+ const result = renderMermaid(text, options);
57071
+ return { svg: result.svg };
57072
+ } catch (error2) {
57073
+ throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
57074
+ }
57075
+ }
57076
+ };
57077
+ }
57078
+ var maid;
57079
+ var init_mermaid_compat = __esm({
57080
+ "node_modules/@probelabs/maid/out/mermaid-compat.js"() {
57081
+ init_renderer();
57082
+ maid = createMermaidAPI();
57083
+ }
57084
+ });
57085
+
57086
+ // node_modules/@probelabs/maid/out/index.js
57087
+ function fixText(text, options = {}) {
57088
+ const { strict = false, level = "safe" } = options;
57089
+ let current = text;
57090
+ for (let i3 = 0; i3 < 5; i3++) {
57091
+ const res = validate(current, { strict });
57092
+ const edits = computeFixes(current, res.errors, level);
57093
+ if (edits.length === 0)
57094
+ return { fixed: current, errors: res.errors };
57095
+ const next = applyEdits(current, edits);
53623
57096
  if (next === current)
53624
57097
  return { fixed: current, errors: res.errors };
53625
57098
  current = next;
@@ -53640,6 +57113,7 @@ var init_out = __esm({
53640
57113
  init_edits();
53641
57114
  init_fixes();
53642
57115
  init_renderer();
57116
+ init_mermaid_compat();
53643
57117
  init_router();
53644
57118
  init_fixes();
53645
57119
  init_edits();
@@ -54355,8 +57829,8 @@ When presented with a broken Mermaid diagram, analyze it thoroughly and provide
54355
57829
  debug: this.options.debug,
54356
57830
  tracer: this.options.tracer,
54357
57831
  allowEdit: this.options.allowEdit,
54358
- maxIterations: 2,
54359
- // Limit mermaid fixing to 2 iterations to prevent long loops
57832
+ maxIterations: 10,
57833
+ // Allow more iterations for mermaid fixing to handle complex diagrams
54360
57834
  disableMermaidValidation: true
54361
57835
  // CRITICAL: Disable mermaid validation in nested agent to prevent infinite recursion
54362
57836
  });
@@ -55256,6 +58730,18 @@ var init_ProbeAgent = __esm({
55256
58730
  this.toolImplementations.bash = wrappedTools.bashToolInstance;
55257
58731
  }
55258
58732
  this.wrappedTools = wrappedTools;
58733
+ if (this.debug) {
58734
+ console.error("\n[DEBUG] ========================================");
58735
+ console.error("[DEBUG] ProbeAgent Tools Initialized");
58736
+ console.error("[DEBUG] Session ID:", this.sessionId);
58737
+ console.error("[DEBUG] Available tools:");
58738
+ for (const toolName of Object.keys(this.toolImplementations)) {
58739
+ console.error(`[DEBUG] - ${toolName}`);
58740
+ }
58741
+ console.error("[DEBUG] Allowed folders:", this.allowedFolders);
58742
+ console.error("[DEBUG] Outline mode:", this.outline);
58743
+ console.error("[DEBUG] ========================================\n");
58744
+ }
55259
58745
  }
55260
58746
  /**
55261
58747
  * Initialize the AI model based on available API keys and forced provider setting
@@ -56026,12 +59512,28 @@ You are working with a repository located at: ${searchDirectory}
56026
59512
  const { type } = parsedTool;
56027
59513
  if (type === "mcp" && this.mcpBridge && this.mcpBridge.isMcpTool(toolName)) {
56028
59514
  try {
56029
- if (this.debug) console.log(`[DEBUG] Executing MCP tool '${toolName}' with params:`, params);
59515
+ if (this.debug) {
59516
+ console.error(`
59517
+ [DEBUG] ========================================`);
59518
+ console.error(`[DEBUG] Executing MCP tool: ${toolName}`);
59519
+ console.error(`[DEBUG] Arguments:`);
59520
+ for (const [key, value] of Object.entries(params)) {
59521
+ const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
59522
+ console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
59523
+ }
59524
+ console.error(`[DEBUG] ========================================
59525
+ `);
59526
+ }
56030
59527
  const executionResult = await this.mcpBridge.mcpTools[toolName].execute(params);
56031
59528
  const toolResultContent = typeof executionResult === "string" ? executionResult : JSON.stringify(executionResult, null, 2);
56032
- const preview = createMessagePreview(toolResultContent);
56033
59529
  if (this.debug) {
56034
- console.log(`[DEBUG] MCP tool '${toolName}' executed successfully. Result preview: ${preview}`);
59530
+ const preview = toolResultContent.length > 500 ? toolResultContent.substring(0, 500) + "..." : toolResultContent;
59531
+ console.error(`[DEBUG] ========================================`);
59532
+ console.error(`[DEBUG] MCP tool '${toolName}' completed successfully`);
59533
+ console.error(`[DEBUG] Result preview:`);
59534
+ console.error(preview);
59535
+ console.error(`[DEBUG] ========================================
59536
+ `);
56035
59537
  }
56036
59538
  currentMessages.push({ role: "user", content: `<tool_result>
56037
59539
  ${toolResultContent}
@@ -56039,7 +59541,13 @@ ${toolResultContent}
56039
59541
  } catch (error2) {
56040
59542
  console.error(`Error executing MCP tool ${toolName}:`, error2);
56041
59543
  const toolResultContent = `Error executing MCP tool ${toolName}: ${error2.message}`;
56042
- if (this.debug) console.log(`[DEBUG] MCP tool '${toolName}' execution FAILED.`);
59544
+ if (this.debug) {
59545
+ console.error(`[DEBUG] ========================================`);
59546
+ console.error(`[DEBUG] MCP tool '${toolName}' failed with error:`);
59547
+ console.error(`[DEBUG] ${error2.message}`);
59548
+ console.error(`[DEBUG] ========================================
59549
+ `);
59550
+ }
56043
59551
  currentMessages.push({ role: "user", content: `<tool_result>
56044
59552
  ${toolResultContent}
56045
59553
  </tool_result>` });
@@ -56051,6 +59559,18 @@ ${toolResultContent}
56051
59559
  sessionId: this.sessionId,
56052
59560
  workingDirectory: this.allowedFolders && this.allowedFolders[0] || process.cwd()
56053
59561
  };
59562
+ if (this.debug) {
59563
+ console.error(`
59564
+ [DEBUG] ========================================`);
59565
+ console.error(`[DEBUG] Executing tool: ${toolName}`);
59566
+ console.error(`[DEBUG] Arguments:`);
59567
+ for (const [key, value] of Object.entries(params)) {
59568
+ const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
59569
+ console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
59570
+ }
59571
+ console.error(`[DEBUG] ========================================
59572
+ `);
59573
+ }
56054
59574
  this.events.emit("toolCall", {
56055
59575
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
56056
59576
  name: toolName,
@@ -56092,6 +59612,15 @@ ${toolResultContent}
56092
59612
  } else {
56093
59613
  toolResult = await executeToolCall();
56094
59614
  }
59615
+ if (this.debug) {
59616
+ const resultPreview = typeof toolResult === "string" ? toolResult.length > 500 ? toolResult.substring(0, 500) + "..." : toolResult : toolResult ? JSON.stringify(toolResult, null, 2).substring(0, 500) + "..." : "No Result";
59617
+ console.error(`[DEBUG] ========================================`);
59618
+ console.error(`[DEBUG] Tool '${toolName}' completed successfully`);
59619
+ console.error(`[DEBUG] Result preview:`);
59620
+ console.error(resultPreview);
59621
+ console.error(`[DEBUG] ========================================
59622
+ `);
59623
+ }
56095
59624
  this.events.emit("toolCall", {
56096
59625
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
56097
59626
  name: toolName,
@@ -56100,6 +59629,13 @@ ${toolResultContent}
56100
59629
  status: "completed"
56101
59630
  });
56102
59631
  } catch (toolError) {
59632
+ if (this.debug) {
59633
+ console.error(`[DEBUG] ========================================`);
59634
+ console.error(`[DEBUG] Tool '${toolName}' failed with error:`);
59635
+ console.error(`[DEBUG] ${toolError.message}`);
59636
+ console.error(`[DEBUG] ========================================
59637
+ `);
59638
+ }
56103
59639
  this.events.emit("toolCall", {
56104
59640
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
56105
59641
  name: toolName,
@@ -56149,6 +59685,16 @@ Error: Unknown tool '${toolName}'. Available tools: ${allAvailableTools.join(",
56149
59685
  }
56150
59686
  }
56151
59687
  } else {
59688
+ const hasMermaidCodeBlock = /```mermaid\s*\n[\s\S]*?\n```/.test(assistantResponseContent);
59689
+ const hasNoSchemaOrTools = !options.schema && validTools.length === 0;
59690
+ if (hasMermaidCodeBlock && hasNoSchemaOrTools) {
59691
+ finalResult = assistantResponseContent;
59692
+ completionAttempted = true;
59693
+ if (this.debug) {
59694
+ console.error(`[DEBUG] Accepting mermaid code block as valid completion (no schema, no tools)`);
59695
+ }
59696
+ break;
59697
+ }
56152
59698
  currentMessages.push({ role: "assistant", content: assistantResponseContent });
56153
59699
  let reminderContent;
56154
59700
  if (options.schema) {
@@ -56862,12 +60408,14 @@ __export(index_exports, {
56862
60408
  getBinaryPath: () => getBinaryPath,
56863
60409
  initializeSimpleTelemetryFromOptions: () => initializeSimpleTelemetryFromOptions,
56864
60410
  listFilesByLevel: () => listFilesByLevel,
60411
+ listFilesToolInstance: () => listFilesToolInstance,
56865
60412
  parseXmlToolCall: () => parseXmlToolCall,
56866
60413
  query: () => query,
56867
60414
  querySchema: () => querySchema,
56868
60415
  queryTool: () => queryTool,
56869
60416
  queryToolDefinition: () => queryToolDefinition,
56870
60417
  search: () => search,
60418
+ searchFilesToolInstance: () => searchFilesToolInstance,
56871
60419
  searchSchema: () => searchSchema,
56872
60420
  searchTool: () => searchTool,
56873
60421
  searchToolDefinition: () => searchToolDefinition,
@@ -56890,6 +60438,7 @@ var init_index = __esm({
56890
60438
  init_bash();
56891
60439
  init_ProbeAgent();
56892
60440
  init_simpleTelemetry();
60441
+ init_probeTool();
56893
60442
  }
56894
60443
  });
56895
60444
  init_index();
@@ -56915,12 +60464,14 @@ init_index();
56915
60464
  getBinaryPath,
56916
60465
  initializeSimpleTelemetryFromOptions,
56917
60466
  listFilesByLevel,
60467
+ listFilesToolInstance,
56918
60468
  parseXmlToolCall,
56919
60469
  query,
56920
60470
  querySchema,
56921
60471
  queryTool,
56922
60472
  queryToolDefinition,
56923
60473
  search,
60474
+ searchFilesToolInstance,
56924
60475
  searchSchema,
56925
60476
  searchTool,
56926
60477
  searchToolDefinition,