@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/build/agent/ProbeAgent.js +100 -10
- package/build/agent/index.js +3853 -306
- package/build/agent/probeTool.js +93 -18
- package/build/agent/schemaUtils.js +1 -1
- package/build/index.js +4 -0
- package/cjs/agent/ProbeAgent.cjs +3856 -309
- package/cjs/index.cjs +3601 -50
- package/package.json +2 -2
- package/src/agent/ProbeAgent.js +100 -10
- package/src/agent/probeTool.js +93 -18
- package/src/agent/schemaUtils.js +1 -1
- package/src/index.js +4 -0
package/build/agent/index.js
CHANGED
|
@@ -30026,6 +30026,268 @@ var init_simpleTelemetry = __esm({
|
|
|
30026
30026
|
}
|
|
30027
30027
|
});
|
|
30028
30028
|
|
|
30029
|
+
// src/agent/probeTool.js
|
|
30030
|
+
import { exec as exec6 } from "child_process";
|
|
30031
|
+
import { promisify as promisify6 } from "util";
|
|
30032
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
30033
|
+
import { EventEmitter } from "events";
|
|
30034
|
+
import fs5 from "fs";
|
|
30035
|
+
import { promises as fsPromises } from "fs";
|
|
30036
|
+
import path5 from "path";
|
|
30037
|
+
import { glob } from "glob";
|
|
30038
|
+
function isSessionCancelled(sessionId) {
|
|
30039
|
+
return activeToolExecutions.get(sessionId)?.cancelled || false;
|
|
30040
|
+
}
|
|
30041
|
+
function registerToolExecution(sessionId) {
|
|
30042
|
+
if (!sessionId) return;
|
|
30043
|
+
if (!activeToolExecutions.has(sessionId)) {
|
|
30044
|
+
activeToolExecutions.set(sessionId, { cancelled: false });
|
|
30045
|
+
} else {
|
|
30046
|
+
activeToolExecutions.get(sessionId).cancelled = false;
|
|
30047
|
+
}
|
|
30048
|
+
}
|
|
30049
|
+
function clearToolExecutionData(sessionId) {
|
|
30050
|
+
if (!sessionId) return;
|
|
30051
|
+
if (activeToolExecutions.has(sessionId)) {
|
|
30052
|
+
activeToolExecutions.delete(sessionId);
|
|
30053
|
+
if (process.env.DEBUG === "1") {
|
|
30054
|
+
console.log(`Cleared tool execution data for session: ${sessionId}`);
|
|
30055
|
+
}
|
|
30056
|
+
}
|
|
30057
|
+
}
|
|
30058
|
+
function createWrappedTools(baseTools) {
|
|
30059
|
+
const wrappedTools = {};
|
|
30060
|
+
if (baseTools.searchTool) {
|
|
30061
|
+
wrappedTools.searchToolInstance = wrapToolWithEmitter(
|
|
30062
|
+
baseTools.searchTool,
|
|
30063
|
+
"search",
|
|
30064
|
+
baseTools.searchTool.execute
|
|
30065
|
+
);
|
|
30066
|
+
}
|
|
30067
|
+
if (baseTools.queryTool) {
|
|
30068
|
+
wrappedTools.queryToolInstance = wrapToolWithEmitter(
|
|
30069
|
+
baseTools.queryTool,
|
|
30070
|
+
"query",
|
|
30071
|
+
baseTools.queryTool.execute
|
|
30072
|
+
);
|
|
30073
|
+
}
|
|
30074
|
+
if (baseTools.extractTool) {
|
|
30075
|
+
wrappedTools.extractToolInstance = wrapToolWithEmitter(
|
|
30076
|
+
baseTools.extractTool,
|
|
30077
|
+
"extract",
|
|
30078
|
+
baseTools.extractTool.execute
|
|
30079
|
+
);
|
|
30080
|
+
}
|
|
30081
|
+
if (baseTools.delegateTool) {
|
|
30082
|
+
wrappedTools.delegateToolInstance = wrapToolWithEmitter(
|
|
30083
|
+
baseTools.delegateTool,
|
|
30084
|
+
"delegate",
|
|
30085
|
+
baseTools.delegateTool.execute
|
|
30086
|
+
);
|
|
30087
|
+
}
|
|
30088
|
+
if (baseTools.bashTool) {
|
|
30089
|
+
wrappedTools.bashToolInstance = wrapToolWithEmitter(
|
|
30090
|
+
baseTools.bashTool,
|
|
30091
|
+
"bash",
|
|
30092
|
+
baseTools.bashTool.execute
|
|
30093
|
+
);
|
|
30094
|
+
}
|
|
30095
|
+
return wrappedTools;
|
|
30096
|
+
}
|
|
30097
|
+
var toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
|
|
30098
|
+
var init_probeTool = __esm({
|
|
30099
|
+
"src/agent/probeTool.js"() {
|
|
30100
|
+
"use strict";
|
|
30101
|
+
init_index();
|
|
30102
|
+
toolCallEmitter = new EventEmitter();
|
|
30103
|
+
activeToolExecutions = /* @__PURE__ */ new Map();
|
|
30104
|
+
wrapToolWithEmitter = (tool3, toolName, baseExecute) => {
|
|
30105
|
+
return {
|
|
30106
|
+
...tool3,
|
|
30107
|
+
// Spread schema, description etc.
|
|
30108
|
+
execute: async (params) => {
|
|
30109
|
+
const debug = process.env.DEBUG === "1";
|
|
30110
|
+
const toolSessionId = params.sessionId || randomUUID2();
|
|
30111
|
+
if (debug) {
|
|
30112
|
+
console.log(`[DEBUG] probeTool: Executing ${toolName} for session ${toolSessionId}`);
|
|
30113
|
+
}
|
|
30114
|
+
registerToolExecution(toolSessionId);
|
|
30115
|
+
let executionError = null;
|
|
30116
|
+
let result = null;
|
|
30117
|
+
try {
|
|
30118
|
+
const toolCallStartData = {
|
|
30119
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30120
|
+
name: toolName,
|
|
30121
|
+
args: params,
|
|
30122
|
+
status: "started"
|
|
30123
|
+
};
|
|
30124
|
+
if (debug) {
|
|
30125
|
+
console.log(`[DEBUG] probeTool: Emitting toolCallStart:${toolSessionId}`);
|
|
30126
|
+
}
|
|
30127
|
+
toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallStartData);
|
|
30128
|
+
if (isSessionCancelled(toolSessionId)) {
|
|
30129
|
+
if (debug) {
|
|
30130
|
+
console.log(`Tool execution cancelled before start for ${toolSessionId}`);
|
|
30131
|
+
}
|
|
30132
|
+
throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
|
|
30133
|
+
}
|
|
30134
|
+
result = await baseExecute(params);
|
|
30135
|
+
if (isSessionCancelled(toolSessionId)) {
|
|
30136
|
+
if (debug) {
|
|
30137
|
+
console.log(`Tool execution cancelled after completion for ${toolSessionId}`);
|
|
30138
|
+
}
|
|
30139
|
+
throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
|
|
30140
|
+
}
|
|
30141
|
+
} catch (error2) {
|
|
30142
|
+
executionError = error2;
|
|
30143
|
+
if (debug) {
|
|
30144
|
+
console.error(`[DEBUG] probeTool: Error in ${toolName}:`, error2);
|
|
30145
|
+
}
|
|
30146
|
+
}
|
|
30147
|
+
if (executionError) {
|
|
30148
|
+
const toolCallErrorData = {
|
|
30149
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30150
|
+
name: toolName,
|
|
30151
|
+
args: params,
|
|
30152
|
+
error: executionError.message || "Unknown error",
|
|
30153
|
+
status: "error"
|
|
30154
|
+
};
|
|
30155
|
+
if (debug) {
|
|
30156
|
+
console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (error)`);
|
|
30157
|
+
}
|
|
30158
|
+
toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallErrorData);
|
|
30159
|
+
throw executionError;
|
|
30160
|
+
} else {
|
|
30161
|
+
if (isSessionCancelled(toolSessionId)) {
|
|
30162
|
+
if (process.env.DEBUG === "1") {
|
|
30163
|
+
console.log(`Tool execution finished but session was cancelled for ${toolSessionId}`);
|
|
30164
|
+
}
|
|
30165
|
+
throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
|
|
30166
|
+
}
|
|
30167
|
+
const toolCallData = {
|
|
30168
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30169
|
+
name: toolName,
|
|
30170
|
+
args: params,
|
|
30171
|
+
// Safely preview result
|
|
30172
|
+
resultPreview: typeof result === "string" ? result.length > 200 ? result.substring(0, 200) + "..." : result : result ? JSON.stringify(result).substring(0, 200) + "..." : "No Result",
|
|
30173
|
+
status: "completed"
|
|
30174
|
+
};
|
|
30175
|
+
if (debug) {
|
|
30176
|
+
console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (completed)`);
|
|
30177
|
+
}
|
|
30178
|
+
toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallData);
|
|
30179
|
+
return result;
|
|
30180
|
+
}
|
|
30181
|
+
}
|
|
30182
|
+
};
|
|
30183
|
+
};
|
|
30184
|
+
listFilesTool = {
|
|
30185
|
+
execute: async (params) => {
|
|
30186
|
+
const { directory = ".", workingDirectory } = params;
|
|
30187
|
+
const baseCwd = workingDirectory || process.cwd();
|
|
30188
|
+
const secureBaseDir = path5.resolve(baseCwd);
|
|
30189
|
+
const targetDir = path5.resolve(secureBaseDir, directory);
|
|
30190
|
+
if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
|
|
30191
|
+
throw new Error("Path traversal attempt detected. Access denied.");
|
|
30192
|
+
}
|
|
30193
|
+
const debug = process.env.DEBUG === "1";
|
|
30194
|
+
if (debug) {
|
|
30195
|
+
console.log(`[DEBUG] Listing files in directory: ${targetDir}`);
|
|
30196
|
+
}
|
|
30197
|
+
try {
|
|
30198
|
+
const files = await fsPromises.readdir(targetDir, { withFileTypes: true });
|
|
30199
|
+
const formatSize = (size) => {
|
|
30200
|
+
if (size < 1024) return `${size}B`;
|
|
30201
|
+
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)}K`;
|
|
30202
|
+
if (size < 1024 * 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)}M`;
|
|
30203
|
+
return `${(size / (1024 * 1024 * 1024)).toFixed(1)}G`;
|
|
30204
|
+
};
|
|
30205
|
+
const entries = await Promise.all(files.map(async (file) => {
|
|
30206
|
+
const isDirectory = file.isDirectory();
|
|
30207
|
+
const fullPath = path5.join(targetDir, file.name);
|
|
30208
|
+
let size = 0;
|
|
30209
|
+
try {
|
|
30210
|
+
const stats = await fsPromises.stat(fullPath);
|
|
30211
|
+
size = stats.size;
|
|
30212
|
+
} catch (statError) {
|
|
30213
|
+
if (debug) {
|
|
30214
|
+
console.log(`[DEBUG] Could not stat file ${file.name}:`, statError.message);
|
|
30215
|
+
}
|
|
30216
|
+
}
|
|
30217
|
+
return {
|
|
30218
|
+
name: file.name,
|
|
30219
|
+
isDirectory,
|
|
30220
|
+
size
|
|
30221
|
+
};
|
|
30222
|
+
}));
|
|
30223
|
+
entries.sort((a3, b3) => {
|
|
30224
|
+
if (a3.isDirectory && !b3.isDirectory) return -1;
|
|
30225
|
+
if (!a3.isDirectory && b3.isDirectory) return 1;
|
|
30226
|
+
return a3.name.localeCompare(b3.name);
|
|
30227
|
+
});
|
|
30228
|
+
const formatted = entries.map((entry) => {
|
|
30229
|
+
const type = entry.isDirectory ? "dir " : "file";
|
|
30230
|
+
const sizeStr = formatSize(entry.size).padStart(8);
|
|
30231
|
+
return `${type} ${sizeStr} ${entry.name}`;
|
|
30232
|
+
});
|
|
30233
|
+
if (debug) {
|
|
30234
|
+
console.log(`[DEBUG] Found ${entries.length} files/directories in ${targetDir}`);
|
|
30235
|
+
}
|
|
30236
|
+
const header = `${targetDir}:
|
|
30237
|
+
`;
|
|
30238
|
+
const output = header + formatted.join("\n");
|
|
30239
|
+
return output;
|
|
30240
|
+
} catch (error2) {
|
|
30241
|
+
throw new Error(`Failed to list files: ${error2.message}`);
|
|
30242
|
+
}
|
|
30243
|
+
}
|
|
30244
|
+
};
|
|
30245
|
+
searchFilesTool = {
|
|
30246
|
+
execute: async (params) => {
|
|
30247
|
+
const { pattern, directory = ".", recursive = true, workingDirectory } = params;
|
|
30248
|
+
if (!pattern) {
|
|
30249
|
+
throw new Error("Pattern is required for file search");
|
|
30250
|
+
}
|
|
30251
|
+
const baseCwd = workingDirectory || process.cwd();
|
|
30252
|
+
const secureBaseDir = path5.resolve(baseCwd);
|
|
30253
|
+
const targetDir = path5.resolve(secureBaseDir, directory);
|
|
30254
|
+
if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
|
|
30255
|
+
throw new Error("Path traversal attempt detected. Access denied.");
|
|
30256
|
+
}
|
|
30257
|
+
if (pattern.includes("**/**") || pattern.split("*").length > 10) {
|
|
30258
|
+
throw new Error("Pattern too complex. Please use a simpler glob pattern.");
|
|
30259
|
+
}
|
|
30260
|
+
try {
|
|
30261
|
+
const options = {
|
|
30262
|
+
cwd: targetDir,
|
|
30263
|
+
ignore: ["node_modules/**", ".git/**"],
|
|
30264
|
+
absolute: false
|
|
30265
|
+
};
|
|
30266
|
+
if (!recursive) {
|
|
30267
|
+
options.deep = 1;
|
|
30268
|
+
}
|
|
30269
|
+
const timeoutPromise = new Promise((_2, reject2) => {
|
|
30270
|
+
setTimeout(() => reject2(new Error("Search operation timed out after 10 seconds")), 1e4);
|
|
30271
|
+
});
|
|
30272
|
+
const files = await Promise.race([
|
|
30273
|
+
glob(pattern, options),
|
|
30274
|
+
timeoutPromise
|
|
30275
|
+
]);
|
|
30276
|
+
const maxResults = 1e3;
|
|
30277
|
+
if (files.length > maxResults) {
|
|
30278
|
+
return files.slice(0, maxResults);
|
|
30279
|
+
}
|
|
30280
|
+
return files;
|
|
30281
|
+
} catch (error2) {
|
|
30282
|
+
throw new Error(`Failed to search files: ${error2.message}`);
|
|
30283
|
+
}
|
|
30284
|
+
}
|
|
30285
|
+
};
|
|
30286
|
+
listFilesToolInstance = wrapToolWithEmitter(listFilesTool, "listFiles", listFilesTool.execute);
|
|
30287
|
+
searchFilesToolInstance = wrapToolWithEmitter(searchFilesTool, "searchFiles", searchFilesTool.execute);
|
|
30288
|
+
}
|
|
30289
|
+
});
|
|
30290
|
+
|
|
30029
30291
|
// src/index.js
|
|
30030
30292
|
var init_index = __esm({
|
|
30031
30293
|
"src/index.js"() {
|
|
@@ -30043,6 +30305,7 @@ var init_index = __esm({
|
|
|
30043
30305
|
init_bash();
|
|
30044
30306
|
init_ProbeAgent();
|
|
30045
30307
|
init_simpleTelemetry();
|
|
30308
|
+
init_probeTool();
|
|
30046
30309
|
}
|
|
30047
30310
|
});
|
|
30048
30311
|
|
|
@@ -30146,7 +30409,7 @@ var init_xmlParsingUtils = __esm({
|
|
|
30146
30409
|
});
|
|
30147
30410
|
|
|
30148
30411
|
// src/agent/tools.js
|
|
30149
|
-
import { randomUUID as
|
|
30412
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
30150
30413
|
function createTools(configOptions) {
|
|
30151
30414
|
const tools2 = {
|
|
30152
30415
|
searchTool: searchTool(configOptions),
|
|
@@ -30249,216 +30512,6 @@ User: Find all markdown files in the docs directory, but only at the top level.
|
|
|
30249
30512
|
}
|
|
30250
30513
|
});
|
|
30251
30514
|
|
|
30252
|
-
// src/agent/probeTool.js
|
|
30253
|
-
import { exec as exec6 } from "child_process";
|
|
30254
|
-
import { promisify as promisify6 } from "util";
|
|
30255
|
-
import { randomUUID as randomUUID3 } from "crypto";
|
|
30256
|
-
import { EventEmitter } from "events";
|
|
30257
|
-
import fs5 from "fs";
|
|
30258
|
-
import { promises as fsPromises } from "fs";
|
|
30259
|
-
import path5 from "path";
|
|
30260
|
-
import { glob } from "glob";
|
|
30261
|
-
function isSessionCancelled(sessionId) {
|
|
30262
|
-
return activeToolExecutions.get(sessionId)?.cancelled || false;
|
|
30263
|
-
}
|
|
30264
|
-
function registerToolExecution(sessionId) {
|
|
30265
|
-
if (!sessionId) return;
|
|
30266
|
-
if (!activeToolExecutions.has(sessionId)) {
|
|
30267
|
-
activeToolExecutions.set(sessionId, { cancelled: false });
|
|
30268
|
-
} else {
|
|
30269
|
-
activeToolExecutions.get(sessionId).cancelled = false;
|
|
30270
|
-
}
|
|
30271
|
-
}
|
|
30272
|
-
function clearToolExecutionData(sessionId) {
|
|
30273
|
-
if (!sessionId) return;
|
|
30274
|
-
if (activeToolExecutions.has(sessionId)) {
|
|
30275
|
-
activeToolExecutions.delete(sessionId);
|
|
30276
|
-
if (process.env.DEBUG === "1") {
|
|
30277
|
-
console.log(`Cleared tool execution data for session: ${sessionId}`);
|
|
30278
|
-
}
|
|
30279
|
-
}
|
|
30280
|
-
}
|
|
30281
|
-
function createWrappedTools(baseTools) {
|
|
30282
|
-
const wrappedTools = {};
|
|
30283
|
-
if (baseTools.searchTool) {
|
|
30284
|
-
wrappedTools.searchToolInstance = wrapToolWithEmitter(
|
|
30285
|
-
baseTools.searchTool,
|
|
30286
|
-
"search",
|
|
30287
|
-
baseTools.searchTool.execute
|
|
30288
|
-
);
|
|
30289
|
-
}
|
|
30290
|
-
if (baseTools.queryTool) {
|
|
30291
|
-
wrappedTools.queryToolInstance = wrapToolWithEmitter(
|
|
30292
|
-
baseTools.queryTool,
|
|
30293
|
-
"query",
|
|
30294
|
-
baseTools.queryTool.execute
|
|
30295
|
-
);
|
|
30296
|
-
}
|
|
30297
|
-
if (baseTools.extractTool) {
|
|
30298
|
-
wrappedTools.extractToolInstance = wrapToolWithEmitter(
|
|
30299
|
-
baseTools.extractTool,
|
|
30300
|
-
"extract",
|
|
30301
|
-
baseTools.extractTool.execute
|
|
30302
|
-
);
|
|
30303
|
-
}
|
|
30304
|
-
if (baseTools.delegateTool) {
|
|
30305
|
-
wrappedTools.delegateToolInstance = wrapToolWithEmitter(
|
|
30306
|
-
baseTools.delegateTool,
|
|
30307
|
-
"delegate",
|
|
30308
|
-
baseTools.delegateTool.execute
|
|
30309
|
-
);
|
|
30310
|
-
}
|
|
30311
|
-
if (baseTools.bashTool) {
|
|
30312
|
-
wrappedTools.bashToolInstance = wrapToolWithEmitter(
|
|
30313
|
-
baseTools.bashTool,
|
|
30314
|
-
"bash",
|
|
30315
|
-
baseTools.bashTool.execute
|
|
30316
|
-
);
|
|
30317
|
-
}
|
|
30318
|
-
return wrappedTools;
|
|
30319
|
-
}
|
|
30320
|
-
var toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
|
|
30321
|
-
var init_probeTool = __esm({
|
|
30322
|
-
"src/agent/probeTool.js"() {
|
|
30323
|
-
"use strict";
|
|
30324
|
-
init_index();
|
|
30325
|
-
toolCallEmitter = new EventEmitter();
|
|
30326
|
-
activeToolExecutions = /* @__PURE__ */ new Map();
|
|
30327
|
-
wrapToolWithEmitter = (tool3, toolName, baseExecute) => {
|
|
30328
|
-
return {
|
|
30329
|
-
...tool3,
|
|
30330
|
-
// Spread schema, description etc.
|
|
30331
|
-
execute: async (params) => {
|
|
30332
|
-
const debug = process.env.DEBUG === "1";
|
|
30333
|
-
const toolSessionId = params.sessionId || randomUUID3();
|
|
30334
|
-
if (debug) {
|
|
30335
|
-
console.log(`[DEBUG] probeTool: Executing ${toolName} for session ${toolSessionId}`);
|
|
30336
|
-
}
|
|
30337
|
-
registerToolExecution(toolSessionId);
|
|
30338
|
-
let executionError = null;
|
|
30339
|
-
let result = null;
|
|
30340
|
-
try {
|
|
30341
|
-
const toolCallStartData = {
|
|
30342
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30343
|
-
name: toolName,
|
|
30344
|
-
args: params,
|
|
30345
|
-
status: "started"
|
|
30346
|
-
};
|
|
30347
|
-
if (debug) {
|
|
30348
|
-
console.log(`[DEBUG] probeTool: Emitting toolCallStart:${toolSessionId}`);
|
|
30349
|
-
}
|
|
30350
|
-
toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallStartData);
|
|
30351
|
-
if (isSessionCancelled(toolSessionId)) {
|
|
30352
|
-
if (debug) {
|
|
30353
|
-
console.log(`Tool execution cancelled before start for ${toolSessionId}`);
|
|
30354
|
-
}
|
|
30355
|
-
throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
|
|
30356
|
-
}
|
|
30357
|
-
result = await baseExecute(params);
|
|
30358
|
-
if (isSessionCancelled(toolSessionId)) {
|
|
30359
|
-
if (debug) {
|
|
30360
|
-
console.log(`Tool execution cancelled after completion for ${toolSessionId}`);
|
|
30361
|
-
}
|
|
30362
|
-
throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
|
|
30363
|
-
}
|
|
30364
|
-
} catch (error2) {
|
|
30365
|
-
executionError = error2;
|
|
30366
|
-
if (debug) {
|
|
30367
|
-
console.error(`[DEBUG] probeTool: Error in ${toolName}:`, error2);
|
|
30368
|
-
}
|
|
30369
|
-
}
|
|
30370
|
-
if (executionError) {
|
|
30371
|
-
const toolCallErrorData = {
|
|
30372
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30373
|
-
name: toolName,
|
|
30374
|
-
args: params,
|
|
30375
|
-
error: executionError.message || "Unknown error",
|
|
30376
|
-
status: "error"
|
|
30377
|
-
};
|
|
30378
|
-
if (debug) {
|
|
30379
|
-
console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (error)`);
|
|
30380
|
-
}
|
|
30381
|
-
toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallErrorData);
|
|
30382
|
-
throw executionError;
|
|
30383
|
-
} else {
|
|
30384
|
-
if (isSessionCancelled(toolSessionId)) {
|
|
30385
|
-
if (process.env.DEBUG === "1") {
|
|
30386
|
-
console.log(`Tool execution finished but session was cancelled for ${toolSessionId}`);
|
|
30387
|
-
}
|
|
30388
|
-
throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
|
|
30389
|
-
}
|
|
30390
|
-
const toolCallData = {
|
|
30391
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30392
|
-
name: toolName,
|
|
30393
|
-
args: params,
|
|
30394
|
-
// Safely preview result
|
|
30395
|
-
resultPreview: typeof result === "string" ? result.length > 200 ? result.substring(0, 200) + "..." : result : result ? JSON.stringify(result).substring(0, 200) + "..." : "No Result",
|
|
30396
|
-
status: "completed"
|
|
30397
|
-
};
|
|
30398
|
-
if (debug) {
|
|
30399
|
-
console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (completed)`);
|
|
30400
|
-
}
|
|
30401
|
-
toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallData);
|
|
30402
|
-
return result;
|
|
30403
|
-
}
|
|
30404
|
-
}
|
|
30405
|
-
};
|
|
30406
|
-
};
|
|
30407
|
-
listFilesTool = {
|
|
30408
|
-
execute: async (params) => {
|
|
30409
|
-
const { directory = ".", workingDirectory } = params;
|
|
30410
|
-
const baseCwd = workingDirectory || process.cwd();
|
|
30411
|
-
const secureBaseDir = path5.resolve(baseCwd);
|
|
30412
|
-
const targetDir = path5.resolve(secureBaseDir, directory);
|
|
30413
|
-
if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
|
|
30414
|
-
throw new Error("Path traversal attempt detected. Access denied.");
|
|
30415
|
-
}
|
|
30416
|
-
try {
|
|
30417
|
-
const files = await listFilesByLevel({
|
|
30418
|
-
directory: targetDir,
|
|
30419
|
-
maxFiles: 100,
|
|
30420
|
-
respectGitignore: !process.env.PROBE_NO_GITIGNORE || process.env.PROBE_NO_GITIGNORE === "",
|
|
30421
|
-
cwd: secureBaseDir
|
|
30422
|
-
});
|
|
30423
|
-
return files;
|
|
30424
|
-
} catch (error2) {
|
|
30425
|
-
throw new Error(`Failed to list files: ${error2.message}`);
|
|
30426
|
-
}
|
|
30427
|
-
}
|
|
30428
|
-
};
|
|
30429
|
-
searchFilesTool = {
|
|
30430
|
-
execute: async (params) => {
|
|
30431
|
-
const { pattern, directory = ".", recursive = true, workingDirectory } = params;
|
|
30432
|
-
if (!pattern) {
|
|
30433
|
-
throw new Error("Pattern is required for file search");
|
|
30434
|
-
}
|
|
30435
|
-
const baseCwd = workingDirectory || process.cwd();
|
|
30436
|
-
const secureBaseDir = path5.resolve(baseCwd);
|
|
30437
|
-
const targetDir = path5.resolve(secureBaseDir, directory);
|
|
30438
|
-
if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
|
|
30439
|
-
throw new Error("Path traversal attempt detected. Access denied.");
|
|
30440
|
-
}
|
|
30441
|
-
try {
|
|
30442
|
-
const options = {
|
|
30443
|
-
cwd: targetDir,
|
|
30444
|
-
ignore: ["node_modules/**", ".git/**"],
|
|
30445
|
-
absolute: false
|
|
30446
|
-
};
|
|
30447
|
-
if (!recursive) {
|
|
30448
|
-
options.deep = 1;
|
|
30449
|
-
}
|
|
30450
|
-
const files = await glob(pattern, options);
|
|
30451
|
-
return files;
|
|
30452
|
-
} catch (error2) {
|
|
30453
|
-
throw new Error(`Failed to search files: ${error2.message}`);
|
|
30454
|
-
}
|
|
30455
|
-
}
|
|
30456
|
-
};
|
|
30457
|
-
listFilesToolInstance = wrapToolWithEmitter(listFilesTool, "listFiles", listFilesTool.execute);
|
|
30458
|
-
searchFilesToolInstance = wrapToolWithEmitter(searchFilesTool, "searchFiles", searchFilesTool.execute);
|
|
30459
|
-
}
|
|
30460
|
-
});
|
|
30461
|
-
|
|
30462
30515
|
// src/agent/mockProvider.js
|
|
30463
30516
|
function createMockProvider() {
|
|
30464
30517
|
return {
|
|
@@ -41765,13 +41818,14 @@ function tokenize(text) {
|
|
|
41765
41818
|
const lexResult = MermaidLexer.tokenize(text);
|
|
41766
41819
|
return lexResult;
|
|
41767
41820
|
}
|
|
41768
|
-
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;
|
|
41821
|
+
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;
|
|
41769
41822
|
var init_lexer2 = __esm({
|
|
41770
41823
|
"node_modules/@probelabs/maid/out/diagrams/flowchart/lexer.js"() {
|
|
41771
41824
|
init_api5();
|
|
41772
41825
|
Identifier = createToken({
|
|
41773
41826
|
name: "Identifier",
|
|
41774
|
-
|
|
41827
|
+
// e.g., id-2, _id, A1, but not A-- (that belongs to an arrow token)
|
|
41828
|
+
pattern: /[a-zA-Z_][a-zA-Z0-9_]*(?:-[a-zA-Z0-9_]+)*/
|
|
41775
41829
|
});
|
|
41776
41830
|
NumberLiteral = createToken({
|
|
41777
41831
|
name: "NumberLiteral",
|
|
@@ -41912,6 +41966,8 @@ var init_lexer2 = __esm({
|
|
|
41912
41966
|
AngleOpen = createToken({ name: "AngleOpen", pattern: />/ });
|
|
41913
41967
|
AngleLess = createToken({ name: "AngleLess", pattern: /</ });
|
|
41914
41968
|
Pipe = createToken({ name: "Pipe", pattern: /\|/ });
|
|
41969
|
+
ForwardSlash = createToken({ name: "ForwardSlash", pattern: /\// });
|
|
41970
|
+
Backslash = createToken({ name: "Backslash", pattern: /\\/ });
|
|
41915
41971
|
QuotedString = createToken({
|
|
41916
41972
|
name: "QuotedString",
|
|
41917
41973
|
// Allow escaped characters within quotes (Mermaid accepts \" inside "...")
|
|
@@ -41995,6 +42051,8 @@ var init_lexer2 = __esm({
|
|
|
41995
42051
|
DiamondClose,
|
|
41996
42052
|
AngleOpen,
|
|
41997
42053
|
AngleLess,
|
|
42054
|
+
ForwardSlash,
|
|
42055
|
+
Backslash,
|
|
41998
42056
|
Pipe,
|
|
41999
42057
|
TripleColon,
|
|
42000
42058
|
Ampersand,
|
|
@@ -42187,6 +42245,8 @@ var init_parser2 = __esm({
|
|
|
42187
42245
|
// Allow HTML-like tags (e.g., <br/>) inside labels
|
|
42188
42246
|
{ ALT: () => this.CONSUME(AngleLess) },
|
|
42189
42247
|
{ ALT: () => this.CONSUME(AngleOpen) },
|
|
42248
|
+
{ ALT: () => this.CONSUME(ForwardSlash) },
|
|
42249
|
+
{ ALT: () => this.CONSUME(Backslash) },
|
|
42190
42250
|
{ ALT: () => this.CONSUME(Comma) },
|
|
42191
42251
|
{ ALT: () => this.CONSUME(Colon) },
|
|
42192
42252
|
// HTML entities and ampersands inside labels
|
|
@@ -43235,6 +43295,66 @@ ${br.example}`,
|
|
|
43235
43295
|
length: len
|
|
43236
43296
|
};
|
|
43237
43297
|
}
|
|
43298
|
+
if (inRule("boxBlock") && (err.name === "NoViableAltException" || err.name === "MismatchedTokenException")) {
|
|
43299
|
+
const isMessage = /->|-->>|-->/.test(ltxt);
|
|
43300
|
+
const isNote = /note\s+(left|right|over)/i.test(ltxt);
|
|
43301
|
+
const isActivate = /activate\s+/i.test(ltxt);
|
|
43302
|
+
const isDeactivate = /deactivate\s+/i.test(ltxt);
|
|
43303
|
+
if (isMessage || isNote || isActivate || isDeactivate || tokType === "NoteKeyword" || tokType === "ActivateKeyword" || tokType === "DeactivateKeyword") {
|
|
43304
|
+
const lines2 = text.split(/\r?\n/);
|
|
43305
|
+
const boxLine = Math.max(0, line - 1);
|
|
43306
|
+
let hasEnd = false;
|
|
43307
|
+
let openIdx = -1;
|
|
43308
|
+
for (let i3 = boxLine; i3 >= 0; i3--) {
|
|
43309
|
+
if (/^\s*box\b/.test(lines2[i3] || "")) {
|
|
43310
|
+
openIdx = i3;
|
|
43311
|
+
break;
|
|
43312
|
+
}
|
|
43313
|
+
}
|
|
43314
|
+
if (openIdx !== -1) {
|
|
43315
|
+
for (let i3 = boxLine; i3 < lines2.length; i3++) {
|
|
43316
|
+
if (/^\s*end\s*$/.test(lines2[i3] || "")) {
|
|
43317
|
+
hasEnd = true;
|
|
43318
|
+
break;
|
|
43319
|
+
}
|
|
43320
|
+
if (i3 > boxLine && /^\s*(sequenceDiagram|box|alt|opt|loop|par|rect|critical|break)\b/.test(lines2[i3] || ""))
|
|
43321
|
+
break;
|
|
43322
|
+
}
|
|
43323
|
+
}
|
|
43324
|
+
if (hasEnd) {
|
|
43325
|
+
let hasParticipants = false;
|
|
43326
|
+
for (let i3 = openIdx + 1; i3 < lines2.length; i3++) {
|
|
43327
|
+
const raw = lines2[i3] || "";
|
|
43328
|
+
if (/^\s*end\s*$/.test(raw))
|
|
43329
|
+
break;
|
|
43330
|
+
if (/^\s*(participant|actor)\b/i.test(raw)) {
|
|
43331
|
+
hasParticipants = true;
|
|
43332
|
+
break;
|
|
43333
|
+
}
|
|
43334
|
+
}
|
|
43335
|
+
if (!hasParticipants) {
|
|
43336
|
+
return {
|
|
43337
|
+
line: openIdx + 1,
|
|
43338
|
+
column: 1,
|
|
43339
|
+
severity: "error",
|
|
43340
|
+
code: "SE-BOX-EMPTY",
|
|
43341
|
+
message: "Box block has no participant/actor declarations. Use 'rect' to group messages visually.",
|
|
43342
|
+
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",
|
|
43343
|
+
length: 3
|
|
43344
|
+
};
|
|
43345
|
+
}
|
|
43346
|
+
return {
|
|
43347
|
+
line,
|
|
43348
|
+
column,
|
|
43349
|
+
severity: "error",
|
|
43350
|
+
code: "SE-BOX-INVALID-CONTENT",
|
|
43351
|
+
message: "Box blocks can only contain participant/actor declarations.",
|
|
43352
|
+
hint: 'Move messages, notes, and other statements outside the box block.\nExample:\nbox "Group"\n participant A\n participant B\nend\nA->>B: Message',
|
|
43353
|
+
length: len
|
|
43354
|
+
};
|
|
43355
|
+
}
|
|
43356
|
+
}
|
|
43357
|
+
}
|
|
43238
43358
|
const blockRules = [
|
|
43239
43359
|
{ rule: "altBlock", label: "alt" },
|
|
43240
43360
|
{ rule: "optBlock", label: "opt" },
|
|
@@ -44134,9 +44254,15 @@ var init_parser4 = __esm({
|
|
|
44134
44254
|
this.CONSUME(BoxKeyword);
|
|
44135
44255
|
this.OPTION(() => this.SUBRULE(this.lineRemainder));
|
|
44136
44256
|
this.AT_LEAST_ONE(() => this.CONSUME(Newline3));
|
|
44137
|
-
this.MANY(() => this.
|
|
44257
|
+
this.MANY(() => this.OR([
|
|
44258
|
+
{ ALT: () => this.SUBRULE(this.participantDecl) },
|
|
44259
|
+
{ ALT: () => this.SUBRULE(this.blankLine) }
|
|
44260
|
+
]));
|
|
44138
44261
|
this.CONSUME(EndKeyword2);
|
|
44139
|
-
this.
|
|
44262
|
+
this.OR2([
|
|
44263
|
+
{ ALT: () => this.AT_LEAST_ONE2(() => this.CONSUME2(Newline3)) },
|
|
44264
|
+
{ ALT: () => this.CONSUME2(EOF) }
|
|
44265
|
+
]);
|
|
44140
44266
|
});
|
|
44141
44267
|
this.lineRemainder = this.RULE("lineRemainder", () => {
|
|
44142
44268
|
this.AT_LEAST_ONE(() => this.OR([
|
|
@@ -45687,6 +45813,69 @@ function computeFixes(text, errors, level = "safe") {
|
|
|
45687
45813
|
edits.push(replaceRange(text, at(e3), e3.length ?? 4, "option"));
|
|
45688
45814
|
continue;
|
|
45689
45815
|
}
|
|
45816
|
+
if (is("SE-BOX-EMPTY", e3)) {
|
|
45817
|
+
const lines = text.split(/\r?\n/);
|
|
45818
|
+
const boxIdx = Math.max(0, e3.line - 1);
|
|
45819
|
+
const boxLine = lines[boxIdx] || "";
|
|
45820
|
+
const labelMatch = /^\s*box\s+(.+)$/.exec(boxLine);
|
|
45821
|
+
if (labelMatch) {
|
|
45822
|
+
const indent = boxLine.match(/^\s*/)?.[0] || "";
|
|
45823
|
+
const newLine = `${indent}rect rgb(240, 240, 255)`;
|
|
45824
|
+
edits.push({ start: { line: e3.line, column: 1 }, end: { line: e3.line, column: boxLine.length + 1 }, newText: newLine });
|
|
45825
|
+
}
|
|
45826
|
+
continue;
|
|
45827
|
+
}
|
|
45828
|
+
if (is("SE-BOX-INVALID-CONTENT", e3)) {
|
|
45829
|
+
const lines = text.split(/\r?\n/);
|
|
45830
|
+
const curIdx = Math.max(0, e3.line - 1);
|
|
45831
|
+
const boxRe = /^(\s*)box\b/;
|
|
45832
|
+
let openIdx = -1;
|
|
45833
|
+
let openIndent = "";
|
|
45834
|
+
for (let i3 = curIdx; i3 >= 0; i3--) {
|
|
45835
|
+
const m3 = boxRe.exec(lines[i3] || "");
|
|
45836
|
+
if (m3) {
|
|
45837
|
+
openIdx = i3;
|
|
45838
|
+
openIndent = m3[1] || "";
|
|
45839
|
+
break;
|
|
45840
|
+
}
|
|
45841
|
+
}
|
|
45842
|
+
if (openIdx !== -1) {
|
|
45843
|
+
let endIdx = -1;
|
|
45844
|
+
for (let i3 = openIdx + 1; i3 < lines.length; i3++) {
|
|
45845
|
+
const trimmed = (lines[i3] || "").trim();
|
|
45846
|
+
if (trimmed === "end") {
|
|
45847
|
+
endIdx = i3;
|
|
45848
|
+
break;
|
|
45849
|
+
}
|
|
45850
|
+
}
|
|
45851
|
+
if (endIdx !== -1) {
|
|
45852
|
+
const invalidLines = [];
|
|
45853
|
+
for (let i3 = openIdx + 1; i3 < endIdx; i3++) {
|
|
45854
|
+
const raw = lines[i3] || "";
|
|
45855
|
+
const trimmed = raw.trim();
|
|
45856
|
+
if (trimmed === "")
|
|
45857
|
+
continue;
|
|
45858
|
+
if (!/^\s*(participant|actor)\b/i.test(raw)) {
|
|
45859
|
+
invalidLines.push(i3);
|
|
45860
|
+
}
|
|
45861
|
+
}
|
|
45862
|
+
if (invalidLines.length > 0) {
|
|
45863
|
+
const endIndent = openIndent;
|
|
45864
|
+
const movedContent = invalidLines.map((i3) => {
|
|
45865
|
+
const line = lines[i3] || "";
|
|
45866
|
+
const trimmed = line.trimStart();
|
|
45867
|
+
return endIndent + trimmed;
|
|
45868
|
+
}).join("\n") + "\n";
|
|
45869
|
+
for (let i3 = invalidLines.length - 1; i3 >= 0; i3--) {
|
|
45870
|
+
const idx = invalidLines[i3];
|
|
45871
|
+
edits.push({ start: { line: idx + 1, column: 1 }, end: { line: idx + 2, column: 1 }, newText: "" });
|
|
45872
|
+
}
|
|
45873
|
+
edits.push(insertAt(text, { line: endIdx + 2, column: 1 }, movedContent));
|
|
45874
|
+
}
|
|
45875
|
+
}
|
|
45876
|
+
}
|
|
45877
|
+
continue;
|
|
45878
|
+
}
|
|
45690
45879
|
if (is("SE-BLOCK-MISSING-END", e3)) {
|
|
45691
45880
|
const lines = text.split(/\r?\n/);
|
|
45692
45881
|
const curIdx = Math.max(0, e3.line - 1);
|
|
@@ -45967,24 +46156,559 @@ var init_fixes = __esm({
|
|
|
45967
46156
|
});
|
|
45968
46157
|
|
|
45969
46158
|
// node_modules/@probelabs/maid/out/renderer/graph-builder.js
|
|
46159
|
+
var GraphBuilder;
|
|
45970
46160
|
var init_graph_builder = __esm({
|
|
45971
46161
|
"node_modules/@probelabs/maid/out/renderer/graph-builder.js"() {
|
|
45972
|
-
|
|
45973
|
-
|
|
45974
|
-
|
|
45975
|
-
|
|
45976
|
-
|
|
45977
|
-
|
|
45978
|
-
|
|
45979
|
-
|
|
45980
|
-
|
|
45981
|
-
|
|
45982
|
-
|
|
45983
|
-
|
|
45984
|
-
|
|
45985
|
-
|
|
45986
|
-
|
|
45987
|
-
|
|
46162
|
+
GraphBuilder = class {
|
|
46163
|
+
constructor() {
|
|
46164
|
+
this.nodes = /* @__PURE__ */ new Map();
|
|
46165
|
+
this.edges = [];
|
|
46166
|
+
this.nodeCounter = 0;
|
|
46167
|
+
this.edgeCounter = 0;
|
|
46168
|
+
this.subgraphs = [];
|
|
46169
|
+
this.currentSubgraphStack = [];
|
|
46170
|
+
this.classStyles = /* @__PURE__ */ new Map();
|
|
46171
|
+
this.nodeStyles = /* @__PURE__ */ new Map();
|
|
46172
|
+
this.nodeClasses = /* @__PURE__ */ new Map();
|
|
46173
|
+
}
|
|
46174
|
+
build(cst) {
|
|
46175
|
+
this.reset();
|
|
46176
|
+
if (!cst || !cst.children) {
|
|
46177
|
+
return {
|
|
46178
|
+
nodes: [],
|
|
46179
|
+
edges: [],
|
|
46180
|
+
direction: "TD",
|
|
46181
|
+
subgraphs: []
|
|
46182
|
+
};
|
|
46183
|
+
}
|
|
46184
|
+
const direction = this.extractDirection(cst);
|
|
46185
|
+
this.processStatements(cst);
|
|
46186
|
+
return {
|
|
46187
|
+
nodes: Array.from(this.nodes.values()),
|
|
46188
|
+
edges: this.edges,
|
|
46189
|
+
direction,
|
|
46190
|
+
subgraphs: this.subgraphs
|
|
46191
|
+
};
|
|
46192
|
+
}
|
|
46193
|
+
reset() {
|
|
46194
|
+
this.nodes.clear();
|
|
46195
|
+
this.edges = [];
|
|
46196
|
+
this.nodeCounter = 0;
|
|
46197
|
+
this.edgeCounter = 0;
|
|
46198
|
+
this.subgraphs = [];
|
|
46199
|
+
this.currentSubgraphStack = [];
|
|
46200
|
+
this.classStyles.clear();
|
|
46201
|
+
this.nodeStyles.clear();
|
|
46202
|
+
this.nodeClasses.clear();
|
|
46203
|
+
}
|
|
46204
|
+
extractDirection(cst) {
|
|
46205
|
+
const dirToken = cst.children?.Direction?.[0];
|
|
46206
|
+
const dir = dirToken?.image?.toUpperCase();
|
|
46207
|
+
switch (dir) {
|
|
46208
|
+
case "TB":
|
|
46209
|
+
case "TD":
|
|
46210
|
+
return "TD";
|
|
46211
|
+
case "BT":
|
|
46212
|
+
return "BT";
|
|
46213
|
+
case "LR":
|
|
46214
|
+
return "LR";
|
|
46215
|
+
case "RL":
|
|
46216
|
+
return "RL";
|
|
46217
|
+
default:
|
|
46218
|
+
return "TD";
|
|
46219
|
+
}
|
|
46220
|
+
}
|
|
46221
|
+
processStatements(cst) {
|
|
46222
|
+
const statements = cst.children?.statement;
|
|
46223
|
+
if (!statements)
|
|
46224
|
+
return;
|
|
46225
|
+
for (const stmt of statements) {
|
|
46226
|
+
if (stmt.children?.nodeStatement) {
|
|
46227
|
+
this.processNodeStatement(stmt.children.nodeStatement[0]);
|
|
46228
|
+
} else if (stmt.children?.subgraph) {
|
|
46229
|
+
this.processSubgraph(stmt.children.subgraph[0]);
|
|
46230
|
+
} else if (stmt.children?.classDefStatement) {
|
|
46231
|
+
this.processClassDef(stmt.children.classDefStatement[0]);
|
|
46232
|
+
} else if (stmt.children?.classStatement) {
|
|
46233
|
+
this.processClassAssign(stmt.children.classStatement[0]);
|
|
46234
|
+
} else if (stmt.children?.styleStatement) {
|
|
46235
|
+
this.processStyle(stmt.children.styleStatement[0]);
|
|
46236
|
+
}
|
|
46237
|
+
}
|
|
46238
|
+
}
|
|
46239
|
+
processNodeStatement(stmt) {
|
|
46240
|
+
const groups = stmt.children?.nodeOrParallelGroup;
|
|
46241
|
+
const links = stmt.children?.link;
|
|
46242
|
+
if (!groups || groups.length === 0)
|
|
46243
|
+
return;
|
|
46244
|
+
const sourceNodes = this.processNodeGroup(groups[0]);
|
|
46245
|
+
if (groups.length > 1 && links && links.length > 0) {
|
|
46246
|
+
const targetNodes = this.processNodeGroup(groups[1]);
|
|
46247
|
+
const linkInfo = this.extractLinkInfo(links[0]);
|
|
46248
|
+
for (const source of sourceNodes) {
|
|
46249
|
+
for (const target of targetNodes) {
|
|
46250
|
+
this.edges.push({
|
|
46251
|
+
id: `e${this.edgeCounter++}`,
|
|
46252
|
+
source,
|
|
46253
|
+
target,
|
|
46254
|
+
label: linkInfo.label,
|
|
46255
|
+
type: linkInfo.type,
|
|
46256
|
+
markerStart: linkInfo.markerStart,
|
|
46257
|
+
markerEnd: linkInfo.markerEnd
|
|
46258
|
+
});
|
|
46259
|
+
}
|
|
46260
|
+
}
|
|
46261
|
+
for (let i3 = 2; i3 < groups.length; i3++) {
|
|
46262
|
+
const nextNodes = this.processNodeGroup(groups[i3]);
|
|
46263
|
+
const nextLink = links[i3 - 1] ? this.extractLinkInfo(links[i3 - 1]) : linkInfo;
|
|
46264
|
+
for (const source of targetNodes) {
|
|
46265
|
+
for (const target of nextNodes) {
|
|
46266
|
+
this.edges.push({
|
|
46267
|
+
id: `e${this.edgeCounter++}`,
|
|
46268
|
+
source,
|
|
46269
|
+
target,
|
|
46270
|
+
label: nextLink.label,
|
|
46271
|
+
type: nextLink.type,
|
|
46272
|
+
markerStart: nextLink.markerStart,
|
|
46273
|
+
markerEnd: nextLink.markerEnd
|
|
46274
|
+
});
|
|
46275
|
+
}
|
|
46276
|
+
}
|
|
46277
|
+
targetNodes.length = 0;
|
|
46278
|
+
targetNodes.push(...nextNodes);
|
|
46279
|
+
}
|
|
46280
|
+
}
|
|
46281
|
+
}
|
|
46282
|
+
processNodeGroup(group) {
|
|
46283
|
+
const nodes = group.children?.node;
|
|
46284
|
+
if (!nodes)
|
|
46285
|
+
return [];
|
|
46286
|
+
const nodeIds = [];
|
|
46287
|
+
for (const node of nodes) {
|
|
46288
|
+
const nodeInfo = this.extractNodeInfo(node);
|
|
46289
|
+
if (nodeInfo) {
|
|
46290
|
+
const isSubgraph = this.subgraphs.some((sg) => sg.id === nodeInfo.id);
|
|
46291
|
+
if (!isSubgraph) {
|
|
46292
|
+
if (!this.nodes.has(nodeInfo.id)) {
|
|
46293
|
+
nodeInfo.style = this.computeNodeStyle(nodeInfo.id);
|
|
46294
|
+
this.nodes.set(nodeInfo.id, nodeInfo);
|
|
46295
|
+
} else {
|
|
46296
|
+
const existing = this.nodes.get(nodeInfo.id);
|
|
46297
|
+
if (nodeInfo.shape !== "rectangle" || nodeInfo.label !== nodeInfo.id) {
|
|
46298
|
+
if (nodeInfo.label !== nodeInfo.id) {
|
|
46299
|
+
existing.label = nodeInfo.label;
|
|
46300
|
+
}
|
|
46301
|
+
if (nodeInfo.shape !== "rectangle") {
|
|
46302
|
+
existing.shape = nodeInfo.shape;
|
|
46303
|
+
}
|
|
46304
|
+
}
|
|
46305
|
+
const merged = this.computeNodeStyle(nodeInfo.id);
|
|
46306
|
+
if (Object.keys(merged).length) {
|
|
46307
|
+
existing.style = { ...existing.style || {}, ...merged };
|
|
46308
|
+
}
|
|
46309
|
+
}
|
|
46310
|
+
if (this.currentSubgraphStack.length) {
|
|
46311
|
+
for (const sgId of this.currentSubgraphStack) {
|
|
46312
|
+
const subgraph = this.subgraphs.find((s3) => s3.id === sgId);
|
|
46313
|
+
if (subgraph && !subgraph.nodes.includes(nodeInfo.id)) {
|
|
46314
|
+
subgraph.nodes.push(nodeInfo.id);
|
|
46315
|
+
}
|
|
46316
|
+
}
|
|
46317
|
+
}
|
|
46318
|
+
}
|
|
46319
|
+
nodeIds.push(nodeInfo.id);
|
|
46320
|
+
}
|
|
46321
|
+
}
|
|
46322
|
+
return nodeIds;
|
|
46323
|
+
}
|
|
46324
|
+
extractNodeInfo(node) {
|
|
46325
|
+
const children = node.children;
|
|
46326
|
+
if (!children)
|
|
46327
|
+
return null;
|
|
46328
|
+
let id;
|
|
46329
|
+
if (children.nodeId) {
|
|
46330
|
+
id = children.nodeId[0].image;
|
|
46331
|
+
if (children.nodeIdSuffix) {
|
|
46332
|
+
id += children.nodeIdSuffix[0].image;
|
|
46333
|
+
}
|
|
46334
|
+
} else if (children.nodeIdNum) {
|
|
46335
|
+
id = children.nodeIdNum[0].image;
|
|
46336
|
+
} else if (children.Identifier) {
|
|
46337
|
+
id = children.Identifier[0].image;
|
|
46338
|
+
} else {
|
|
46339
|
+
return null;
|
|
46340
|
+
}
|
|
46341
|
+
let shape = "rectangle";
|
|
46342
|
+
let label = id;
|
|
46343
|
+
const shapeNode = children.nodeShape?.[0];
|
|
46344
|
+
if (shapeNode?.children) {
|
|
46345
|
+
const result = this.extractShapeAndLabel(shapeNode);
|
|
46346
|
+
shape = result.shape;
|
|
46347
|
+
if (result.label)
|
|
46348
|
+
label = result.label;
|
|
46349
|
+
}
|
|
46350
|
+
const clsTok = children.nodeClass?.[0];
|
|
46351
|
+
if (clsTok) {
|
|
46352
|
+
const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
|
|
46353
|
+
set.add(clsTok.image);
|
|
46354
|
+
this.nodeClasses.set(id, set);
|
|
46355
|
+
}
|
|
46356
|
+
return { id, label, shape };
|
|
46357
|
+
}
|
|
46358
|
+
extractShapeAndLabel(shapeNode) {
|
|
46359
|
+
const children = shapeNode.children;
|
|
46360
|
+
let shape = "rectangle";
|
|
46361
|
+
let label = "";
|
|
46362
|
+
const contentNodes = children?.nodeContent;
|
|
46363
|
+
if (contentNodes && contentNodes.length > 0) {
|
|
46364
|
+
label = this.extractTextContent(contentNodes[0]);
|
|
46365
|
+
}
|
|
46366
|
+
if (children?.SquareOpen) {
|
|
46367
|
+
shape = "rectangle";
|
|
46368
|
+
const contentNode = children.nodeContent?.[0];
|
|
46369
|
+
if (contentNode) {
|
|
46370
|
+
const c3 = contentNode.children;
|
|
46371
|
+
const tokTypes = ["ForwardSlash", "Backslash", "Identifier", "Text", "NumberLiteral", "RoundOpen", "RoundClose", "AngleLess", "AngleOpen", "Comma", "Colon", "Ampersand", "Semicolon", "TwoDashes", "Line", "ThickLine", "DottedLine"];
|
|
46372
|
+
const toks = [];
|
|
46373
|
+
for (const tt of tokTypes) {
|
|
46374
|
+
const arr = c3[tt];
|
|
46375
|
+
arr?.forEach((t3) => toks.push({ type: tt, t: t3, start: t3.startOffset ?? 0 }));
|
|
46376
|
+
}
|
|
46377
|
+
if (toks.length >= 2) {
|
|
46378
|
+
toks.sort((a3, b3) => a3.start - b3.start);
|
|
46379
|
+
const first2 = toks[0].type;
|
|
46380
|
+
const last2 = toks[toks.length - 1].type;
|
|
46381
|
+
if (first2 === "ForwardSlash" && last2 === "ForwardSlash" || first2 === "Backslash" && last2 === "Backslash") {
|
|
46382
|
+
shape = "parallelogram";
|
|
46383
|
+
} else if (first2 === "ForwardSlash" && last2 === "Backslash") {
|
|
46384
|
+
shape = "trapezoid";
|
|
46385
|
+
} else if (first2 === "Backslash" && last2 === "ForwardSlash") {
|
|
46386
|
+
shape = "trapezoidAlt";
|
|
46387
|
+
}
|
|
46388
|
+
}
|
|
46389
|
+
}
|
|
46390
|
+
} else if (children?.RoundOpen) {
|
|
46391
|
+
shape = "round";
|
|
46392
|
+
} else if (children?.DiamondOpen) {
|
|
46393
|
+
shape = "diamond";
|
|
46394
|
+
} else if (children?.DoubleRoundOpen) {
|
|
46395
|
+
shape = "circle";
|
|
46396
|
+
} else if (children?.StadiumOpen) {
|
|
46397
|
+
shape = "stadium";
|
|
46398
|
+
} else if (children?.HexagonOpen) {
|
|
46399
|
+
shape = "hexagon";
|
|
46400
|
+
} else if (children?.DoubleSquareOpen) {
|
|
46401
|
+
shape = "subroutine";
|
|
46402
|
+
} else if (children?.CylinderOpen) {
|
|
46403
|
+
shape = "cylinder";
|
|
46404
|
+
} else if (children?.TrapezoidOpen) {
|
|
46405
|
+
shape = "trapezoid";
|
|
46406
|
+
} else if (children?.ParallelogramOpen) {
|
|
46407
|
+
shape = "parallelogram";
|
|
46408
|
+
}
|
|
46409
|
+
return { shape, label };
|
|
46410
|
+
}
|
|
46411
|
+
extractTextContent(contentNode) {
|
|
46412
|
+
const children = contentNode.children;
|
|
46413
|
+
if (!children)
|
|
46414
|
+
return "";
|
|
46415
|
+
const tokenTypes = [
|
|
46416
|
+
"Text",
|
|
46417
|
+
"Identifier",
|
|
46418
|
+
"QuotedString",
|
|
46419
|
+
"NumberLiteral",
|
|
46420
|
+
"Ampersand",
|
|
46421
|
+
"Comma",
|
|
46422
|
+
"Colon",
|
|
46423
|
+
"Semicolon",
|
|
46424
|
+
"Dot",
|
|
46425
|
+
"Underscore",
|
|
46426
|
+
"Dash",
|
|
46427
|
+
"ForwardSlash",
|
|
46428
|
+
"Backslash",
|
|
46429
|
+
"AngleLess",
|
|
46430
|
+
"AngleOpen"
|
|
46431
|
+
];
|
|
46432
|
+
const tokenWithPositions = [];
|
|
46433
|
+
for (const type of tokenTypes) {
|
|
46434
|
+
const tokens = children[type];
|
|
46435
|
+
if (tokens) {
|
|
46436
|
+
for (const token of tokens) {
|
|
46437
|
+
let text = token.image;
|
|
46438
|
+
if (type === "QuotedString" && text.startsWith('"') && text.endsWith('"')) {
|
|
46439
|
+
text = text.slice(1, -1);
|
|
46440
|
+
}
|
|
46441
|
+
if ((type === "ForwardSlash" || type === "Backslash") && tokenWithPositions.length === 0) {
|
|
46442
|
+
continue;
|
|
46443
|
+
}
|
|
46444
|
+
tokenWithPositions.push({
|
|
46445
|
+
text,
|
|
46446
|
+
startOffset: token.startOffset ?? 0,
|
|
46447
|
+
type
|
|
46448
|
+
});
|
|
46449
|
+
}
|
|
46450
|
+
}
|
|
46451
|
+
}
|
|
46452
|
+
tokenWithPositions.sort((a3, b3) => a3.startOffset - b3.startOffset);
|
|
46453
|
+
if (tokenWithPositions.length) {
|
|
46454
|
+
const first2 = tokenWithPositions[0];
|
|
46455
|
+
if (first2.type === "ForwardSlash" || first2.type === "Backslash") {
|
|
46456
|
+
tokenWithPositions.shift();
|
|
46457
|
+
}
|
|
46458
|
+
const last2 = tokenWithPositions[tokenWithPositions.length - 1];
|
|
46459
|
+
if (last2.type === "ForwardSlash" || last2.type === "Backslash") {
|
|
46460
|
+
tokenWithPositions.pop();
|
|
46461
|
+
}
|
|
46462
|
+
}
|
|
46463
|
+
const parts = tokenWithPositions.map((t3) => t3.text);
|
|
46464
|
+
if (children.Space) {
|
|
46465
|
+
return parts.join("");
|
|
46466
|
+
}
|
|
46467
|
+
return parts.join(" ").trim();
|
|
46468
|
+
}
|
|
46469
|
+
extractLinkInfo(link) {
|
|
46470
|
+
const children = link.children;
|
|
46471
|
+
let type = "arrow";
|
|
46472
|
+
let label;
|
|
46473
|
+
let markerStart = "none";
|
|
46474
|
+
let markerEnd = "none";
|
|
46475
|
+
if (children.BiDirectionalArrow) {
|
|
46476
|
+
type = "arrow";
|
|
46477
|
+
markerStart = "arrow";
|
|
46478
|
+
markerEnd = "arrow";
|
|
46479
|
+
} else if (children.CircleEndLine) {
|
|
46480
|
+
type = "open";
|
|
46481
|
+
markerStart = "circle";
|
|
46482
|
+
markerEnd = "circle";
|
|
46483
|
+
} else if (children.CrossEndLine) {
|
|
46484
|
+
type = "open";
|
|
46485
|
+
markerStart = "cross";
|
|
46486
|
+
markerEnd = "cross";
|
|
46487
|
+
} else if (children?.ArrowRight) {
|
|
46488
|
+
type = "arrow";
|
|
46489
|
+
markerEnd = "arrow";
|
|
46490
|
+
} else if (children?.ArrowLeft) {
|
|
46491
|
+
type = "arrow";
|
|
46492
|
+
markerStart = "arrow";
|
|
46493
|
+
} else if (children?.DottedArrowRight) {
|
|
46494
|
+
type = "dotted";
|
|
46495
|
+
markerEnd = "arrow";
|
|
46496
|
+
} else if (children?.DottedArrowLeft) {
|
|
46497
|
+
type = "dotted";
|
|
46498
|
+
markerStart = "arrow";
|
|
46499
|
+
} else if (children?.ThickArrowRight) {
|
|
46500
|
+
type = "thick";
|
|
46501
|
+
markerEnd = "arrow";
|
|
46502
|
+
} else if (children?.ThickArrowLeft) {
|
|
46503
|
+
type = "thick";
|
|
46504
|
+
markerStart = "arrow";
|
|
46505
|
+
} else if (children?.LinkRight || children?.LinkLeft || children?.Line || children?.TwoDashes || children?.DottedLine || children?.ThickLine) {
|
|
46506
|
+
if (children?.DottedLine)
|
|
46507
|
+
type = "dotted";
|
|
46508
|
+
else if (children?.ThickLine)
|
|
46509
|
+
type = "thick";
|
|
46510
|
+
else
|
|
46511
|
+
type = "open";
|
|
46512
|
+
} else if (children?.InvisibleLink) {
|
|
46513
|
+
type = "invisible";
|
|
46514
|
+
}
|
|
46515
|
+
if (markerEnd === "none" && (children?.ArrowRight || children.ThickArrowRight || children.DottedArrowRight)) {
|
|
46516
|
+
markerEnd = "arrow";
|
|
46517
|
+
}
|
|
46518
|
+
if (markerStart === "none" && (children?.ArrowLeft || children.ThickArrowLeft || children.DottedArrowLeft)) {
|
|
46519
|
+
markerStart = "arrow";
|
|
46520
|
+
}
|
|
46521
|
+
const textNode = children?.linkText?.[0];
|
|
46522
|
+
if (textNode) {
|
|
46523
|
+
label = this.extractTextContent(textNode);
|
|
46524
|
+
} else if (children.linkTextInline?.[0]) {
|
|
46525
|
+
label = this.extractTextContent(children.linkTextInline[0]);
|
|
46526
|
+
} else if (children.inlineCarrier?.[0]) {
|
|
46527
|
+
const token = children.inlineCarrier[0];
|
|
46528
|
+
const raw = token.image.trim();
|
|
46529
|
+
if (raw.startsWith("-.") && raw.endsWith(".-")) {
|
|
46530
|
+
type = "dotted";
|
|
46531
|
+
} else if (raw.startsWith("==") && raw.endsWith("==")) {
|
|
46532
|
+
type = "thick";
|
|
46533
|
+
} else if (raw.startsWith("--") && raw.endsWith("--")) {
|
|
46534
|
+
}
|
|
46535
|
+
if (children.ArrowRight || children.DottedArrowRight || children.ThickArrowRight) {
|
|
46536
|
+
markerEnd = "arrow";
|
|
46537
|
+
}
|
|
46538
|
+
if (children.ArrowLeft || children.DottedArrowLeft || children.ThickArrowLeft) {
|
|
46539
|
+
markerStart = "arrow";
|
|
46540
|
+
}
|
|
46541
|
+
const strip = (str) => {
|
|
46542
|
+
if (str.startsWith("-.") && str.endsWith(".-") || str.startsWith("==") && str.endsWith("==") || str.startsWith("--") && str.endsWith("--")) {
|
|
46543
|
+
return str.slice(2, -2).trim();
|
|
46544
|
+
}
|
|
46545
|
+
return str;
|
|
46546
|
+
};
|
|
46547
|
+
label = strip(raw);
|
|
46548
|
+
}
|
|
46549
|
+
return { type, label, markerStart, markerEnd };
|
|
46550
|
+
}
|
|
46551
|
+
processSubgraph(subgraph) {
|
|
46552
|
+
const children = subgraph.children;
|
|
46553
|
+
let id = `subgraph_${this.subgraphs.length}`;
|
|
46554
|
+
let label;
|
|
46555
|
+
const idToken = children?.subgraphId?.[0] || children?.Identifier?.[0];
|
|
46556
|
+
if (idToken) {
|
|
46557
|
+
id = idToken.image;
|
|
46558
|
+
}
|
|
46559
|
+
if (children?.SquareOpen && children?.nodeContent) {
|
|
46560
|
+
label = this.extractTextContent(children.nodeContent[0]);
|
|
46561
|
+
} else if (children.subgraphTitleQ?.[0]) {
|
|
46562
|
+
const qt = children.subgraphTitleQ[0];
|
|
46563
|
+
const img = qt.image;
|
|
46564
|
+
label = img && img.length >= 2 && (img.startsWith('"') || img.startsWith("'")) ? img.slice(1, -1) : img;
|
|
46565
|
+
} else if (children?.subgraphLabel) {
|
|
46566
|
+
label = this.extractTextContent(children.subgraphLabel[0]);
|
|
46567
|
+
}
|
|
46568
|
+
if (!label && id !== `subgraph_${this.subgraphs.length}`) {
|
|
46569
|
+
label = id;
|
|
46570
|
+
}
|
|
46571
|
+
const parent = this.currentSubgraphStack.length ? this.currentSubgraphStack[this.currentSubgraphStack.length - 1] : void 0;
|
|
46572
|
+
const sg = { id, label, nodes: [], parent };
|
|
46573
|
+
this.subgraphs.push(sg);
|
|
46574
|
+
this.currentSubgraphStack.push(id);
|
|
46575
|
+
const statements = children?.subgraphStatement;
|
|
46576
|
+
if (statements) {
|
|
46577
|
+
for (const stmt of statements) {
|
|
46578
|
+
if (stmt.children?.nodeStatement) {
|
|
46579
|
+
this.processNodeStatement(stmt.children.nodeStatement[0]);
|
|
46580
|
+
} else if (stmt.children?.subgraph) {
|
|
46581
|
+
this.processSubgraph(stmt.children.subgraph[0]);
|
|
46582
|
+
}
|
|
46583
|
+
}
|
|
46584
|
+
}
|
|
46585
|
+
this.currentSubgraphStack.pop();
|
|
46586
|
+
}
|
|
46587
|
+
// ---- Styling helpers ----
|
|
46588
|
+
processClassDef(cst) {
|
|
46589
|
+
const idTok = cst.children?.Identifier?.[0];
|
|
46590
|
+
if (!idTok)
|
|
46591
|
+
return;
|
|
46592
|
+
const className = idTok.image;
|
|
46593
|
+
const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
|
|
46594
|
+
if (Object.keys(props).length) {
|
|
46595
|
+
this.classStyles.set(className, props);
|
|
46596
|
+
for (const [nodeId, classes] of this.nodeClasses.entries()) {
|
|
46597
|
+
if (classes.has(className)) {
|
|
46598
|
+
const node = this.nodes.get(nodeId);
|
|
46599
|
+
if (node) {
|
|
46600
|
+
node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
|
|
46601
|
+
}
|
|
46602
|
+
}
|
|
46603
|
+
}
|
|
46604
|
+
}
|
|
46605
|
+
}
|
|
46606
|
+
processClassAssign(cst) {
|
|
46607
|
+
const ids = cst.children?.Identifier || [];
|
|
46608
|
+
if (!ids.length)
|
|
46609
|
+
return;
|
|
46610
|
+
const classNameTok = cst.children.className?.[0];
|
|
46611
|
+
const className = classNameTok?.image || ids[ids.length - 1].image;
|
|
46612
|
+
const nodeIds = classNameTok ? ids.slice(0, -1) : ids.slice(0, -1);
|
|
46613
|
+
for (const tok of nodeIds) {
|
|
46614
|
+
const id = tok.image;
|
|
46615
|
+
const set = this.nodeClasses.get(id) || /* @__PURE__ */ new Set();
|
|
46616
|
+
set.add(className);
|
|
46617
|
+
this.nodeClasses.set(id, set);
|
|
46618
|
+
const node = this.nodes.get(id);
|
|
46619
|
+
if (node) {
|
|
46620
|
+
node.style = { ...node.style || {}, ...this.computeNodeStyle(id) };
|
|
46621
|
+
}
|
|
46622
|
+
}
|
|
46623
|
+
}
|
|
46624
|
+
processStyle(cst) {
|
|
46625
|
+
const idTok = cst.children?.Identifier?.[0];
|
|
46626
|
+
if (!idTok)
|
|
46627
|
+
return;
|
|
46628
|
+
const nodeId = idTok.image;
|
|
46629
|
+
const props = this.collectStyleProps(cst, { skipFirstIdentifier: true });
|
|
46630
|
+
if (Object.keys(props).length) {
|
|
46631
|
+
this.nodeStyles.set(nodeId, props);
|
|
46632
|
+
const node = this.nodes.get(nodeId);
|
|
46633
|
+
if (node) {
|
|
46634
|
+
node.style = { ...node.style || {}, ...this.computeNodeStyle(nodeId) };
|
|
46635
|
+
}
|
|
46636
|
+
}
|
|
46637
|
+
}
|
|
46638
|
+
collectStyleProps(cst, opts = {}) {
|
|
46639
|
+
const tokens = [];
|
|
46640
|
+
const ch = cst.children || {};
|
|
46641
|
+
const push = (arr, type = "t") => arr?.forEach((t3) => tokens.push({ text: t3.image, startOffset: t3.startOffset ?? 0, type }));
|
|
46642
|
+
push(ch.Text, "Text");
|
|
46643
|
+
push(ch.Identifier, "Identifier");
|
|
46644
|
+
push(ch.ColorValue, "Color");
|
|
46645
|
+
push(ch.Colon, "Colon");
|
|
46646
|
+
push(ch.Comma, "Comma");
|
|
46647
|
+
push(ch.NumberLiteral, "Number");
|
|
46648
|
+
tokens.sort((a3, b3) => a3.startOffset - b3.startOffset);
|
|
46649
|
+
if (opts.skipFirstIdentifier) {
|
|
46650
|
+
const idx = tokens.findIndex((t3) => t3.type === "Identifier");
|
|
46651
|
+
if (idx >= 0)
|
|
46652
|
+
tokens.splice(idx, 1);
|
|
46653
|
+
}
|
|
46654
|
+
const joined = tokens.map((t3) => t3.text).join("");
|
|
46655
|
+
const props = {};
|
|
46656
|
+
for (const seg of joined.split(",").map((s3) => s3.trim()).filter(Boolean)) {
|
|
46657
|
+
const [k3, v3] = seg.split(":");
|
|
46658
|
+
if (k3 && v3)
|
|
46659
|
+
props[k3.trim()] = v3.trim();
|
|
46660
|
+
}
|
|
46661
|
+
return props;
|
|
46662
|
+
}
|
|
46663
|
+
computeNodeStyle(nodeId) {
|
|
46664
|
+
const out = {};
|
|
46665
|
+
const classes = this.nodeClasses.get(nodeId);
|
|
46666
|
+
if (classes) {
|
|
46667
|
+
for (const c3 of classes) {
|
|
46668
|
+
const s3 = this.classStyles.get(c3);
|
|
46669
|
+
if (s3)
|
|
46670
|
+
Object.assign(out, this.normalizeStyle(s3));
|
|
46671
|
+
}
|
|
46672
|
+
}
|
|
46673
|
+
const direct = this.nodeStyles.get(nodeId);
|
|
46674
|
+
if (direct)
|
|
46675
|
+
Object.assign(out, this.normalizeStyle(direct));
|
|
46676
|
+
return out;
|
|
46677
|
+
}
|
|
46678
|
+
normalizeStyle(s3) {
|
|
46679
|
+
const out = {};
|
|
46680
|
+
for (const [kRaw, vRaw] of Object.entries(s3)) {
|
|
46681
|
+
const k3 = kRaw.trim().toLowerCase();
|
|
46682
|
+
const v3 = vRaw.trim();
|
|
46683
|
+
if (k3 === "stroke-width") {
|
|
46684
|
+
const num = parseFloat(v3);
|
|
46685
|
+
if (!Number.isNaN(num))
|
|
46686
|
+
out.strokeWidth = num;
|
|
46687
|
+
} else if (k3 === "stroke") {
|
|
46688
|
+
out.stroke = v3;
|
|
46689
|
+
} else if (k3 === "fill") {
|
|
46690
|
+
out.fill = v3;
|
|
46691
|
+
}
|
|
46692
|
+
}
|
|
46693
|
+
return out;
|
|
46694
|
+
}
|
|
46695
|
+
};
|
|
46696
|
+
}
|
|
46697
|
+
});
|
|
46698
|
+
|
|
46699
|
+
// node_modules/lodash/_listCacheClear.js
|
|
46700
|
+
var require_listCacheClear = __commonJS({
|
|
46701
|
+
"node_modules/lodash/_listCacheClear.js"(exports2, module2) {
|
|
46702
|
+
function listCacheClear2() {
|
|
46703
|
+
this.__data__ = [];
|
|
46704
|
+
this.size = 0;
|
|
46705
|
+
}
|
|
46706
|
+
module2.exports = listCacheClear2;
|
|
46707
|
+
}
|
|
46708
|
+
});
|
|
46709
|
+
|
|
46710
|
+
// node_modules/lodash/eq.js
|
|
46711
|
+
var require_eq = __commonJS({
|
|
45988
46712
|
"node_modules/lodash/eq.js"(exports2, module2) {
|
|
45989
46713
|
function eq2(value, other) {
|
|
45990
46714
|
return value === other || value !== value && other !== other;
|
|
@@ -53582,85 +54306,2504 @@ var require_layout = __commonJS({
|
|
|
53582
54306
|
}
|
|
53583
54307
|
});
|
|
53584
54308
|
}
|
|
53585
|
-
function selectNumberAttrs(obj, attrs) {
|
|
53586
|
-
return _2.mapValues(_2.pick(obj, attrs), Number);
|
|
54309
|
+
function selectNumberAttrs(obj, attrs) {
|
|
54310
|
+
return _2.mapValues(_2.pick(obj, attrs), Number);
|
|
54311
|
+
}
|
|
54312
|
+
function canonicalize(attrs) {
|
|
54313
|
+
var newAttrs = {};
|
|
54314
|
+
_2.forEach(attrs, function(v3, k3) {
|
|
54315
|
+
newAttrs[k3.toLowerCase()] = v3;
|
|
54316
|
+
});
|
|
54317
|
+
return newAttrs;
|
|
54318
|
+
}
|
|
54319
|
+
}
|
|
54320
|
+
});
|
|
54321
|
+
|
|
54322
|
+
// node_modules/dagre/lib/debug.js
|
|
54323
|
+
var require_debug = __commonJS({
|
|
54324
|
+
"node_modules/dagre/lib/debug.js"(exports2, module2) {
|
|
54325
|
+
var _2 = require_lodash2();
|
|
54326
|
+
var util = require_util();
|
|
54327
|
+
var Graph = require_graphlib2().Graph;
|
|
54328
|
+
module2.exports = {
|
|
54329
|
+
debugOrdering
|
|
54330
|
+
};
|
|
54331
|
+
function debugOrdering(g3) {
|
|
54332
|
+
var layerMatrix = util.buildLayerMatrix(g3);
|
|
54333
|
+
var h3 = new Graph({ compound: true, multigraph: true }).setGraph({});
|
|
54334
|
+
_2.forEach(g3.nodes(), function(v3) {
|
|
54335
|
+
h3.setNode(v3, { label: v3 });
|
|
54336
|
+
h3.setParent(v3, "layer" + g3.node(v3).rank);
|
|
54337
|
+
});
|
|
54338
|
+
_2.forEach(g3.edges(), function(e3) {
|
|
54339
|
+
h3.setEdge(e3.v, e3.w, {}, e3.name);
|
|
54340
|
+
});
|
|
54341
|
+
_2.forEach(layerMatrix, function(layer, i3) {
|
|
54342
|
+
var layerV = "layer" + i3;
|
|
54343
|
+
h3.setNode(layerV, { rank: "same" });
|
|
54344
|
+
_2.reduce(layer, function(u3, v3) {
|
|
54345
|
+
h3.setEdge(u3, v3, { style: "invis" });
|
|
54346
|
+
return v3;
|
|
54347
|
+
});
|
|
54348
|
+
});
|
|
54349
|
+
return h3;
|
|
54350
|
+
}
|
|
54351
|
+
}
|
|
54352
|
+
});
|
|
54353
|
+
|
|
54354
|
+
// node_modules/dagre/lib/version.js
|
|
54355
|
+
var require_version2 = __commonJS({
|
|
54356
|
+
"node_modules/dagre/lib/version.js"(exports2, module2) {
|
|
54357
|
+
module2.exports = "0.8.5";
|
|
54358
|
+
}
|
|
54359
|
+
});
|
|
54360
|
+
|
|
54361
|
+
// node_modules/dagre/index.js
|
|
54362
|
+
var require_dagre = __commonJS({
|
|
54363
|
+
"node_modules/dagre/index.js"(exports2, module2) {
|
|
54364
|
+
module2.exports = {
|
|
54365
|
+
graphlib: require_graphlib2(),
|
|
54366
|
+
layout: require_layout(),
|
|
54367
|
+
debug: require_debug(),
|
|
54368
|
+
util: {
|
|
54369
|
+
time: require_util().time,
|
|
54370
|
+
notime: require_util().notime
|
|
54371
|
+
},
|
|
54372
|
+
version: require_version2()
|
|
54373
|
+
};
|
|
54374
|
+
}
|
|
54375
|
+
});
|
|
54376
|
+
|
|
54377
|
+
// node_modules/@probelabs/maid/out/renderer/layout.js
|
|
54378
|
+
var import_dagre, DagreLayoutEngine;
|
|
54379
|
+
var init_layout = __esm({
|
|
54380
|
+
"node_modules/@probelabs/maid/out/renderer/layout.js"() {
|
|
54381
|
+
import_dagre = __toESM(require_dagre(), 1);
|
|
54382
|
+
DagreLayoutEngine = class {
|
|
54383
|
+
constructor() {
|
|
54384
|
+
this.nodeWidth = 120;
|
|
54385
|
+
this.nodeHeight = 50;
|
|
54386
|
+
this.rankSep = 50;
|
|
54387
|
+
this.nodeSep = 50;
|
|
54388
|
+
this.edgeSep = 10;
|
|
54389
|
+
}
|
|
54390
|
+
layout(graph) {
|
|
54391
|
+
const g3 = new import_dagre.default.graphlib.Graph();
|
|
54392
|
+
const hasClusters = !!(graph.subgraphs && graph.subgraphs.length > 0);
|
|
54393
|
+
const dir = this.mapDirection(graph.direction);
|
|
54394
|
+
let ranksep = this.rankSep;
|
|
54395
|
+
let nodesep = this.nodeSep;
|
|
54396
|
+
if (hasClusters) {
|
|
54397
|
+
if (dir === "LR" || dir === "RL") {
|
|
54398
|
+
ranksep += 20;
|
|
54399
|
+
nodesep += 70;
|
|
54400
|
+
} else {
|
|
54401
|
+
ranksep += 70;
|
|
54402
|
+
nodesep += 20;
|
|
54403
|
+
}
|
|
54404
|
+
}
|
|
54405
|
+
const graphConfig = {
|
|
54406
|
+
rankdir: dir,
|
|
54407
|
+
ranksep,
|
|
54408
|
+
nodesep,
|
|
54409
|
+
edgesep: this.edgeSep,
|
|
54410
|
+
marginx: 20,
|
|
54411
|
+
marginy: 20
|
|
54412
|
+
};
|
|
54413
|
+
if (hasClusters && (dir === "LR" || dir === "RL")) {
|
|
54414
|
+
graphConfig.ranker = "longest-path";
|
|
54415
|
+
graphConfig.acyclicer = "greedy";
|
|
54416
|
+
}
|
|
54417
|
+
if (hasClusters) {
|
|
54418
|
+
graphConfig.compound = true;
|
|
54419
|
+
}
|
|
54420
|
+
g3.setGraph(graphConfig);
|
|
54421
|
+
g3.setDefaultEdgeLabel(() => ({}));
|
|
54422
|
+
if (graph.subgraphs && graph.subgraphs.length > 0) {
|
|
54423
|
+
for (const subgraph of graph.subgraphs) {
|
|
54424
|
+
g3.setNode(subgraph.id, { label: subgraph.label || subgraph.id, clusterLabelPos: "top" });
|
|
54425
|
+
}
|
|
54426
|
+
}
|
|
54427
|
+
for (const node of graph.nodes) {
|
|
54428
|
+
const dimensions = this.calculateNodeDimensions(node.label, node.shape);
|
|
54429
|
+
g3.setNode(node.id, {
|
|
54430
|
+
width: dimensions.width,
|
|
54431
|
+
height: dimensions.height,
|
|
54432
|
+
label: node.label,
|
|
54433
|
+
shape: node.shape
|
|
54434
|
+
});
|
|
54435
|
+
}
|
|
54436
|
+
if (graph.subgraphs && graph.subgraphs.length > 0) {
|
|
54437
|
+
for (const subgraph of graph.subgraphs) {
|
|
54438
|
+
for (const nodeId of subgraph.nodes) {
|
|
54439
|
+
if (g3.hasNode(nodeId)) {
|
|
54440
|
+
try {
|
|
54441
|
+
g3.setParent(nodeId, subgraph.id);
|
|
54442
|
+
} catch {
|
|
54443
|
+
}
|
|
54444
|
+
}
|
|
54445
|
+
}
|
|
54446
|
+
if (subgraph.parent && g3.hasNode(subgraph.parent)) {
|
|
54447
|
+
try {
|
|
54448
|
+
g3.setParent(subgraph.id, subgraph.parent);
|
|
54449
|
+
} catch {
|
|
54450
|
+
}
|
|
54451
|
+
}
|
|
54452
|
+
}
|
|
54453
|
+
}
|
|
54454
|
+
for (const edge of graph.edges) {
|
|
54455
|
+
g3.setEdge(edge.source, edge.target, {
|
|
54456
|
+
label: edge.label,
|
|
54457
|
+
width: edge.label ? edge.label.length * 8 : 0,
|
|
54458
|
+
height: edge.label ? 20 : 0
|
|
54459
|
+
});
|
|
54460
|
+
}
|
|
54461
|
+
import_dagre.default.layout(g3);
|
|
54462
|
+
const graphInfo = g3.graph();
|
|
54463
|
+
const layoutNodes = [];
|
|
54464
|
+
const layoutEdges = [];
|
|
54465
|
+
for (const node of graph.nodes) {
|
|
54466
|
+
const nodeLayout = g3.node(node.id);
|
|
54467
|
+
if (nodeLayout) {
|
|
54468
|
+
layoutNodes.push({
|
|
54469
|
+
...node,
|
|
54470
|
+
x: nodeLayout.x - nodeLayout.width / 2,
|
|
54471
|
+
y: nodeLayout.y - nodeLayout.height / 2,
|
|
54472
|
+
width: nodeLayout.width,
|
|
54473
|
+
height: nodeLayout.height
|
|
54474
|
+
});
|
|
54475
|
+
}
|
|
54476
|
+
}
|
|
54477
|
+
const layoutSubgraphs = [];
|
|
54478
|
+
if (graph.subgraphs && graph.subgraphs.length > 0) {
|
|
54479
|
+
for (const sg of graph.subgraphs) {
|
|
54480
|
+
const members = layoutNodes.filter((nd) => sg.nodes.includes(nd.id));
|
|
54481
|
+
if (members.length) {
|
|
54482
|
+
const minX = Math.min(...members.map((m3) => m3.x));
|
|
54483
|
+
const minY = Math.min(...members.map((m3) => m3.y));
|
|
54484
|
+
const maxX = Math.max(...members.map((m3) => m3.x + m3.width));
|
|
54485
|
+
const maxY = Math.max(...members.map((m3) => m3.y + m3.height));
|
|
54486
|
+
const pad = 30;
|
|
54487
|
+
layoutSubgraphs.push({
|
|
54488
|
+
id: sg.id,
|
|
54489
|
+
label: sg.label || sg.id,
|
|
54490
|
+
x: minX - pad,
|
|
54491
|
+
y: minY - pad - 18,
|
|
54492
|
+
// space for title
|
|
54493
|
+
width: maxX - minX + pad * 2,
|
|
54494
|
+
height: maxY - minY + pad * 2 + 18,
|
|
54495
|
+
parent: sg.parent
|
|
54496
|
+
});
|
|
54497
|
+
}
|
|
54498
|
+
}
|
|
54499
|
+
const byId = Object.fromEntries(layoutSubgraphs.map((s3) => [s3.id, s3]));
|
|
54500
|
+
for (const sg of layoutSubgraphs) {
|
|
54501
|
+
if (!sg.parent)
|
|
54502
|
+
continue;
|
|
54503
|
+
const p3 = byId[sg.parent];
|
|
54504
|
+
if (!p3)
|
|
54505
|
+
continue;
|
|
54506
|
+
const minX = Math.min(p3.x, sg.x);
|
|
54507
|
+
const minY = Math.min(p3.y, sg.y);
|
|
54508
|
+
const maxX = Math.max(p3.x + p3.width, sg.x + sg.width);
|
|
54509
|
+
const maxY = Math.max(p3.y + p3.height, sg.y + sg.height);
|
|
54510
|
+
p3.x = minX;
|
|
54511
|
+
p3.y = minY;
|
|
54512
|
+
p3.width = maxX - minX;
|
|
54513
|
+
p3.height = maxY - minY;
|
|
54514
|
+
}
|
|
54515
|
+
}
|
|
54516
|
+
const subgraphById = Object.fromEntries(layoutSubgraphs.map((sg) => [sg.id, sg]));
|
|
54517
|
+
for (const edge of graph.edges) {
|
|
54518
|
+
const edgeLayout = g3.edge(edge.source, edge.target);
|
|
54519
|
+
let pts = edgeLayout && Array.isArray(edgeLayout.points) ? edgeLayout.points.slice() : [];
|
|
54520
|
+
const hasNaN = pts.some((p3) => !Number.isFinite(p3.x) || !Number.isFinite(p3.y));
|
|
54521
|
+
const srcSg = subgraphById[edge.source];
|
|
54522
|
+
const dstSg = subgraphById[edge.target];
|
|
54523
|
+
let synthesized = false;
|
|
54524
|
+
if (!pts.length || hasNaN || srcSg || dstSg) {
|
|
54525
|
+
const rankdir = this.mapDirection(graph.direction);
|
|
54526
|
+
const getNode = (id) => {
|
|
54527
|
+
const n3 = g3.node(id);
|
|
54528
|
+
if (!n3)
|
|
54529
|
+
return void 0;
|
|
54530
|
+
return {
|
|
54531
|
+
id,
|
|
54532
|
+
label: n3.label || id,
|
|
54533
|
+
shape: n3.shape || "rectangle",
|
|
54534
|
+
x: n3.x - n3.width / 2,
|
|
54535
|
+
y: n3.y - n3.height / 2,
|
|
54536
|
+
width: n3.width,
|
|
54537
|
+
height: n3.height,
|
|
54538
|
+
style: {}
|
|
54539
|
+
};
|
|
54540
|
+
};
|
|
54541
|
+
const start = srcSg ? this.clusterAnchor(srcSg, rankdir, "out") : this.nodeAnchor(getNode(edge.source), rankdir, "out");
|
|
54542
|
+
const end = dstSg ? this.clusterAnchor(dstSg, rankdir, "in") : this.nodeAnchor(getNode(edge.target), rankdir, "in");
|
|
54543
|
+
if (start && end) {
|
|
54544
|
+
const PAD = 20;
|
|
54545
|
+
const horizontallyAdjacent = srcSg && dstSg && Math.abs(srcSg.x - dstSg.x) > Math.abs(srcSg.y - dstSg.y);
|
|
54546
|
+
const horizontalSubgraphs = horizontallyAdjacent;
|
|
54547
|
+
if (rankdir === "LR" || rankdir === "RL") {
|
|
54548
|
+
const outX = start.x + (rankdir === "LR" ? PAD : -PAD);
|
|
54549
|
+
const inX = end.x + (rankdir === "LR" ? -PAD : PAD);
|
|
54550
|
+
const startOut = { x: srcSg ? outX : start.x, y: start.y };
|
|
54551
|
+
const endPre = { x: dstSg ? inX : end.x, y: end.y };
|
|
54552
|
+
const alpha = 0.68;
|
|
54553
|
+
const midX = startOut.x + (endPre.x - startOut.x) * alpha;
|
|
54554
|
+
const m1 = { x: midX, y: startOut.y };
|
|
54555
|
+
const m22 = { x: midX, y: endPre.y };
|
|
54556
|
+
pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
|
|
54557
|
+
} else {
|
|
54558
|
+
if (horizontalSubgraphs && srcSg && dstSg) {
|
|
54559
|
+
const midY = (srcSg.y + srcSg.height / 2 + dstSg.y + dstSg.height / 2) / 2;
|
|
54560
|
+
if (srcSg.x < dstSg.x) {
|
|
54561
|
+
const startX = srcSg.x + srcSg.width;
|
|
54562
|
+
const endX = dstSg.x;
|
|
54563
|
+
pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
|
|
54564
|
+
} else {
|
|
54565
|
+
const startX = srcSg.x;
|
|
54566
|
+
const endX = dstSg.x + dstSg.width;
|
|
54567
|
+
pts = [{ x: startX, y: midY }, { x: endX, y: midY }];
|
|
54568
|
+
}
|
|
54569
|
+
} else {
|
|
54570
|
+
const outY = start.y + (rankdir === "TD" ? PAD : -PAD);
|
|
54571
|
+
const inY = end.y + (rankdir === "TD" ? -PAD : PAD);
|
|
54572
|
+
const startOut = { x: start.x, y: srcSg ? outY : start.y };
|
|
54573
|
+
const endPre = { x: end.x, y: dstSg ? inY : end.y };
|
|
54574
|
+
const alpha = 0.68;
|
|
54575
|
+
const midY = startOut.y + (endPre.y - startOut.y) * alpha;
|
|
54576
|
+
const m1 = { x: startOut.x, y: midY };
|
|
54577
|
+
const m22 = { x: endPre.x, y: midY };
|
|
54578
|
+
pts = dstSg ? [start, startOut, m1, m22, endPre] : [start, startOut, m1, m22, endPre, end];
|
|
54579
|
+
}
|
|
54580
|
+
}
|
|
54581
|
+
synthesized = true;
|
|
54582
|
+
}
|
|
54583
|
+
}
|
|
54584
|
+
if (pts.length) {
|
|
54585
|
+
layoutEdges.push({ ...edge, points: pts, pathMode: synthesized ? "orthogonal" : "smooth" });
|
|
54586
|
+
}
|
|
54587
|
+
}
|
|
54588
|
+
const rawW = graphInfo.width;
|
|
54589
|
+
const rawH = graphInfo.height;
|
|
54590
|
+
const w3 = Number.isFinite(rawW) && rawW > 0 ? rawW : 800;
|
|
54591
|
+
const h3 = Number.isFinite(rawH) && rawH > 0 ? rawH : 600;
|
|
54592
|
+
return {
|
|
54593
|
+
nodes: layoutNodes,
|
|
54594
|
+
edges: layoutEdges,
|
|
54595
|
+
width: w3,
|
|
54596
|
+
height: h3,
|
|
54597
|
+
subgraphs: layoutSubgraphs
|
|
54598
|
+
};
|
|
54599
|
+
}
|
|
54600
|
+
mapDirection(direction) {
|
|
54601
|
+
switch (direction) {
|
|
54602
|
+
case "TB":
|
|
54603
|
+
case "TD":
|
|
54604
|
+
return "TB";
|
|
54605
|
+
case "BT":
|
|
54606
|
+
return "BT";
|
|
54607
|
+
case "LR":
|
|
54608
|
+
return "LR";
|
|
54609
|
+
case "RL":
|
|
54610
|
+
return "RL";
|
|
54611
|
+
default:
|
|
54612
|
+
return "TB";
|
|
54613
|
+
}
|
|
54614
|
+
}
|
|
54615
|
+
calculateNodeDimensions(label, shape) {
|
|
54616
|
+
const charWidth = 7;
|
|
54617
|
+
const padding = 20;
|
|
54618
|
+
const minWidth = 80;
|
|
54619
|
+
const minHeight = 40;
|
|
54620
|
+
const maxWidth = 240;
|
|
54621
|
+
const lineHeight = 18;
|
|
54622
|
+
const explicitLines = label.split(/<\s*br\s*\/?\s*>/i);
|
|
54623
|
+
const hasExplicitBreaks = explicitLines.length > 1;
|
|
54624
|
+
let width;
|
|
54625
|
+
let lines;
|
|
54626
|
+
if (hasExplicitBreaks) {
|
|
54627
|
+
const maxLineLength = Math.max(...explicitLines.map((line) => line.length));
|
|
54628
|
+
width = Math.min(Math.max(maxLineLength * charWidth + padding * 2, minWidth), maxWidth);
|
|
54629
|
+
lines = explicitLines.length;
|
|
54630
|
+
} else {
|
|
54631
|
+
width = Math.min(Math.max(label.length * charWidth + padding * 2, minWidth), maxWidth);
|
|
54632
|
+
const charsPerLine = Math.max(1, Math.floor((width - padding * 2) / charWidth));
|
|
54633
|
+
lines = Math.ceil(label.length / charsPerLine);
|
|
54634
|
+
}
|
|
54635
|
+
let height = Math.max(lines * lineHeight + padding, minHeight);
|
|
54636
|
+
switch (shape) {
|
|
54637
|
+
case "circle":
|
|
54638
|
+
const size = Math.max(width, height);
|
|
54639
|
+
width = size;
|
|
54640
|
+
height = size;
|
|
54641
|
+
break;
|
|
54642
|
+
case "diamond": {
|
|
54643
|
+
const size2 = Math.max(width, height) * 1.2;
|
|
54644
|
+
width = size2;
|
|
54645
|
+
height = size2;
|
|
54646
|
+
break;
|
|
54647
|
+
}
|
|
54648
|
+
case "hexagon":
|
|
54649
|
+
width *= 1.3;
|
|
54650
|
+
height *= 1.2;
|
|
54651
|
+
break;
|
|
54652
|
+
case "stadium":
|
|
54653
|
+
width *= 1.2;
|
|
54654
|
+
break;
|
|
54655
|
+
case "cylinder":
|
|
54656
|
+
height *= 1.5;
|
|
54657
|
+
break;
|
|
54658
|
+
case "subroutine":
|
|
54659
|
+
case "double":
|
|
54660
|
+
width += 10;
|
|
54661
|
+
height += 10;
|
|
54662
|
+
break;
|
|
54663
|
+
case "parallelogram":
|
|
54664
|
+
case "trapezoid":
|
|
54665
|
+
width *= 1.3;
|
|
54666
|
+
break;
|
|
54667
|
+
}
|
|
54668
|
+
return { width: Math.round(width), height: Math.round(height) };
|
|
54669
|
+
}
|
|
54670
|
+
clusterAnchor(sg, rankdir, mode) {
|
|
54671
|
+
switch (rankdir) {
|
|
54672
|
+
case "LR":
|
|
54673
|
+
return { x: mode === "out" ? sg.x + sg.width : sg.x, y: sg.y + sg.height / 2 };
|
|
54674
|
+
case "RL":
|
|
54675
|
+
return { x: mode === "out" ? sg.x : sg.x + sg.width, y: sg.y + sg.height / 2 };
|
|
54676
|
+
case "BT":
|
|
54677
|
+
return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y : sg.y + sg.height };
|
|
54678
|
+
case "TB":
|
|
54679
|
+
default:
|
|
54680
|
+
return { x: sg.x + sg.width / 2, y: mode === "out" ? sg.y + sg.height : sg.y };
|
|
54681
|
+
}
|
|
54682
|
+
}
|
|
54683
|
+
nodeAnchor(n3, rankdir, mode) {
|
|
54684
|
+
if (!n3)
|
|
54685
|
+
return { x: 0, y: 0 };
|
|
54686
|
+
switch (rankdir) {
|
|
54687
|
+
case "LR":
|
|
54688
|
+
return { x: mode === "in" ? n3.x : n3.x + n3.width, y: n3.y + n3.height / 2 };
|
|
54689
|
+
case "RL":
|
|
54690
|
+
return { x: mode === "in" ? n3.x + n3.width : n3.x, y: n3.y + n3.height / 2 };
|
|
54691
|
+
case "BT":
|
|
54692
|
+
return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y + n3.height : n3.y };
|
|
54693
|
+
case "TB":
|
|
54694
|
+
default:
|
|
54695
|
+
return { x: n3.x + n3.width / 2, y: mode === "in" ? n3.y : n3.y + n3.height };
|
|
54696
|
+
}
|
|
54697
|
+
}
|
|
54698
|
+
};
|
|
54699
|
+
}
|
|
54700
|
+
});
|
|
54701
|
+
|
|
54702
|
+
// node_modules/@probelabs/maid/out/renderer/arrow-utils.js
|
|
54703
|
+
function triangleAtEnd(start, end, color = "#333", length = 8, width = 6) {
|
|
54704
|
+
const vx = end.x - start.x;
|
|
54705
|
+
const vy = end.y - start.y;
|
|
54706
|
+
const len = Math.hypot(vx, vy) || 1;
|
|
54707
|
+
const ux = vx / len;
|
|
54708
|
+
const uy = vy / len;
|
|
54709
|
+
const nx = -uy;
|
|
54710
|
+
const ny = ux;
|
|
54711
|
+
const baseX = end.x - ux * length;
|
|
54712
|
+
const baseY = end.y - uy * length;
|
|
54713
|
+
const p2x = baseX + nx * (width / 2), p2y = baseY + ny * (width / 2);
|
|
54714
|
+
const p3x = baseX - nx * (width / 2), p3y = baseY - ny * (width / 2);
|
|
54715
|
+
return `<path d="M${end.x},${end.y} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
|
|
54716
|
+
}
|
|
54717
|
+
function triangleAtStart(first2, second, color = "#333", length = 8, width = 6) {
|
|
54718
|
+
const vx = second.x - first2.x;
|
|
54719
|
+
const vy = second.y - first2.y;
|
|
54720
|
+
const len = Math.hypot(vx, vy) || 1;
|
|
54721
|
+
const ux = vx / len;
|
|
54722
|
+
const uy = vy / len;
|
|
54723
|
+
const nx = -uy;
|
|
54724
|
+
const ny = ux;
|
|
54725
|
+
const tipX = first2.x - ux * length;
|
|
54726
|
+
const tipY = first2.y - uy * length;
|
|
54727
|
+
const p2x = first2.x + nx * (width / 2), p2y = first2.y + ny * (width / 2);
|
|
54728
|
+
const p3x = first2.x - nx * (width / 2), p3y = first2.y - ny * (width / 2);
|
|
54729
|
+
return `<path d="M${tipX},${tipY} L${p2x},${p2y} L${p3x},${p3y} Z" fill="${color}" />`;
|
|
54730
|
+
}
|
|
54731
|
+
var init_arrow_utils = __esm({
|
|
54732
|
+
"node_modules/@probelabs/maid/out/renderer/arrow-utils.js"() {
|
|
54733
|
+
}
|
|
54734
|
+
});
|
|
54735
|
+
|
|
54736
|
+
// node_modules/@probelabs/maid/out/renderer/styles.js
|
|
54737
|
+
function buildSharedCss(opts = {}) {
|
|
54738
|
+
const fontFamily = opts.fontFamily || "Arial, sans-serif";
|
|
54739
|
+
const fontSize = opts.fontSize ?? 14;
|
|
54740
|
+
const nodeFill = opts.nodeFill || "#eef0ff";
|
|
54741
|
+
const nodeStroke = opts.nodeStroke || "#3f3f3f";
|
|
54742
|
+
const edgeStroke = opts.edgeStroke || "#555555";
|
|
54743
|
+
return `
|
|
54744
|
+
.node-shape { fill: ${nodeFill}; stroke: ${nodeStroke}; stroke-width: 1px; }
|
|
54745
|
+
.node-label { fill: #333; font-family: ${fontFamily}; font-size: ${fontSize}px; }
|
|
54746
|
+
.edge-path { stroke: ${edgeStroke}; stroke-width: 2px; fill: none; }
|
|
54747
|
+
.edge-label-bg { fill: rgba(232,232,232, 0.8); opacity: 0.5; }
|
|
54748
|
+
.edge-label-text { fill: #333; font-family: ${fontFamily}; font-size: ${Math.max(10, fontSize - 2)}px; }
|
|
54749
|
+
|
|
54750
|
+
/* Cluster (flowchart + sequence blocks) */
|
|
54751
|
+
.cluster-bg { fill: #ffffde; }
|
|
54752
|
+
.cluster-border { fill: none; stroke: #aaaa33; stroke-width: 1px; }
|
|
54753
|
+
.cluster-title-bg { fill: rgba(255,255,255,0.8); }
|
|
54754
|
+
.cluster-label-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
|
|
54755
|
+
|
|
54756
|
+
/* Notes */
|
|
54757
|
+
.note { fill: #fff5ad; stroke: #aaaa33; stroke-width: 1px; }
|
|
54758
|
+
.note-text { fill: #333; font-family: ${fontFamily}; font-size: 12px; }
|
|
54759
|
+
|
|
54760
|
+
/* Sequence-specific add-ons (safe for flowcharts too) */
|
|
54761
|
+
.actor-rect { fill: #eaeaea; stroke: #666; stroke-width: 1.5px; }
|
|
54762
|
+
.actor-label { fill: #111; font-family: ${fontFamily}; font-size: 16px; }
|
|
54763
|
+
.lifeline { stroke: #999; stroke-width: 0.5px; }
|
|
54764
|
+
.activation { fill: #f4f4f4; stroke: #666; stroke-width: 1px; }
|
|
54765
|
+
.msg-line { stroke: #333; stroke-width: 1.5px; fill: none; }
|
|
54766
|
+
.msg-line.dotted { stroke-dasharray: 2 2; }
|
|
54767
|
+
.msg-line.thick { stroke-width: 3px; }
|
|
54768
|
+
.msg-label { fill: #333; font-family: ${fontFamily}; font-size: 12px; dominant-baseline: middle; }
|
|
54769
|
+
.msg-label-bg { fill: #ffffff; stroke: #cccccc; stroke-width: 1px; rx: 3; }
|
|
54770
|
+
`;
|
|
54771
|
+
}
|
|
54772
|
+
var init_styles = __esm({
|
|
54773
|
+
"node_modules/@probelabs/maid/out/renderer/styles.js"() {
|
|
54774
|
+
}
|
|
54775
|
+
});
|
|
54776
|
+
|
|
54777
|
+
// node_modules/@probelabs/maid/out/renderer/utils.js
|
|
54778
|
+
function escapeXml(text) {
|
|
54779
|
+
return String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\"/g, """).replace(/'/g, "'");
|
|
54780
|
+
}
|
|
54781
|
+
function measureText(text, fontSize = 12) {
|
|
54782
|
+
const avg = 0.6 * fontSize;
|
|
54783
|
+
return Math.max(0, Math.round(text.length * avg));
|
|
54784
|
+
}
|
|
54785
|
+
function palette(index) {
|
|
54786
|
+
if (index < DEFAULT_PALETTE.length)
|
|
54787
|
+
return DEFAULT_PALETTE[index];
|
|
54788
|
+
const i3 = index - DEFAULT_PALETTE.length;
|
|
54789
|
+
const hue = i3 * 47 % 360;
|
|
54790
|
+
return `hsl(${hue} 60% 55%)`;
|
|
54791
|
+
}
|
|
54792
|
+
function formatNumber(n3) {
|
|
54793
|
+
if (Number.isInteger(n3))
|
|
54794
|
+
return String(n3);
|
|
54795
|
+
return (Math.round(n3 * 100) / 100).toString();
|
|
54796
|
+
}
|
|
54797
|
+
function formatPercent(value, total) {
|
|
54798
|
+
if (!(total > 0))
|
|
54799
|
+
return "0%";
|
|
54800
|
+
const p3 = value / total * 100;
|
|
54801
|
+
return `${Math.round(p3)}%`;
|
|
54802
|
+
}
|
|
54803
|
+
var DEFAULT_PALETTE;
|
|
54804
|
+
var init_utils4 = __esm({
|
|
54805
|
+
"node_modules/@probelabs/maid/out/renderer/utils.js"() {
|
|
54806
|
+
DEFAULT_PALETTE = [
|
|
54807
|
+
"#ECECFF",
|
|
54808
|
+
"#ffffde",
|
|
54809
|
+
"hsl(80, 100%, 56.2745098039%)",
|
|
54810
|
+
"hsl(240, 100%, 86.2745098039%)",
|
|
54811
|
+
"hsl(60, 100%, 63.5294117647%)",
|
|
54812
|
+
"hsl(80, 100%, 76.2745098039%)",
|
|
54813
|
+
"hsl(300, 100%, 76.2745098039%)",
|
|
54814
|
+
"hsl(180, 100%, 56.2745098039%)",
|
|
54815
|
+
"hsl(0, 100%, 56.2745098039%)",
|
|
54816
|
+
"hsl(300, 100%, 56.2745098039%)",
|
|
54817
|
+
"hsl(150, 100%, 56.2745098039%)",
|
|
54818
|
+
"hsl(0, 100%, 66.2745098039%)"
|
|
54819
|
+
];
|
|
54820
|
+
}
|
|
54821
|
+
});
|
|
54822
|
+
|
|
54823
|
+
// node_modules/@probelabs/maid/out/renderer/block-utils.js
|
|
54824
|
+
function blockBackground(x3, y2, width, height, radius = 0) {
|
|
54825
|
+
return `<g class="cluster-bg-layer" transform="translate(${x3},${y2})">
|
|
54826
|
+
<rect class="cluster-bg" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>
|
|
54827
|
+
</g>`;
|
|
54828
|
+
}
|
|
54829
|
+
function blockOverlay(x3, y2, width, height, title, branchYs = [], titleYOffset = 0, align = "center", branchAlign = "left", radius = 0) {
|
|
54830
|
+
const parts = [];
|
|
54831
|
+
parts.push(`<g class="cluster-overlay" transform="translate(${x3},${y2})">`);
|
|
54832
|
+
parts.push(`<rect class="cluster-border" x="0" y="0" width="${width}" height="${height}" rx="${radius}"/>`);
|
|
54833
|
+
const titleText = title ? escapeXml(title) : "";
|
|
54834
|
+
if (titleText) {
|
|
54835
|
+
const titleW = Math.max(24, measureText(titleText, 12) + 10);
|
|
54836
|
+
const yBg = -2 + titleYOffset;
|
|
54837
|
+
const yText = 11 + titleYOffset;
|
|
54838
|
+
if (align === "left") {
|
|
54839
|
+
const xBg = 6;
|
|
54840
|
+
parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
|
|
54841
|
+
parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yText}" text-anchor="start">${titleText}</text>`);
|
|
54842
|
+
} else {
|
|
54843
|
+
const xBg = 6;
|
|
54844
|
+
parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yBg}" width="${titleW}" height="18" rx="3"/>`);
|
|
54845
|
+
parts.push(`<text class="cluster-label-text" x="${xBg + titleW / 2}" y="${yText}" text-anchor="middle">${titleText}</text>`);
|
|
54846
|
+
}
|
|
54847
|
+
}
|
|
54848
|
+
for (const br of branchYs) {
|
|
54849
|
+
const yRel = br.y - y2;
|
|
54850
|
+
parts.push(`<line x1="0" y1="${yRel}" x2="${width}" y2="${yRel}" class="cluster-border" />`);
|
|
54851
|
+
if (br.title) {
|
|
54852
|
+
const text = escapeXml(br.title);
|
|
54853
|
+
const bw = Math.max(24, measureText(text, 12) + 10);
|
|
54854
|
+
const xBg = 6;
|
|
54855
|
+
parts.push(`<rect class="cluster-title-bg" x="${xBg}" y="${yRel - 10}" width="${bw}" height="18" rx="3"/>`);
|
|
54856
|
+
if (branchAlign === "left") {
|
|
54857
|
+
parts.push(`<text class="cluster-label-text" x="${xBg + 6}" y="${yRel + 1}" text-anchor="start">${text}</text>`);
|
|
54858
|
+
} else {
|
|
54859
|
+
parts.push(`<text class="cluster-label-text" x="${xBg + bw / 2}" y="${yRel + 1}" text-anchor="middle">${text}</text>`);
|
|
54860
|
+
}
|
|
54861
|
+
}
|
|
54862
|
+
}
|
|
54863
|
+
parts.push("</g>");
|
|
54864
|
+
return parts.join("\n");
|
|
54865
|
+
}
|
|
54866
|
+
var init_block_utils = __esm({
|
|
54867
|
+
"node_modules/@probelabs/maid/out/renderer/block-utils.js"() {
|
|
54868
|
+
init_utils4();
|
|
54869
|
+
}
|
|
54870
|
+
});
|
|
54871
|
+
|
|
54872
|
+
// node_modules/@probelabs/maid/out/renderer/svg-generator.js
|
|
54873
|
+
var SVGRenderer;
|
|
54874
|
+
var init_svg_generator = __esm({
|
|
54875
|
+
"node_modules/@probelabs/maid/out/renderer/svg-generator.js"() {
|
|
54876
|
+
init_arrow_utils();
|
|
54877
|
+
init_styles();
|
|
54878
|
+
init_block_utils();
|
|
54879
|
+
SVGRenderer = class {
|
|
54880
|
+
constructor() {
|
|
54881
|
+
this.padding = 20;
|
|
54882
|
+
this.fontSize = 14;
|
|
54883
|
+
this.fontFamily = "Arial, sans-serif";
|
|
54884
|
+
this.defaultStroke = "#3f3f3f";
|
|
54885
|
+
this.defaultFill = "#eef0ff";
|
|
54886
|
+
this.arrowStroke = "#555555";
|
|
54887
|
+
this.arrowMarkerSize = 9;
|
|
54888
|
+
}
|
|
54889
|
+
render(layout) {
|
|
54890
|
+
let minX = Infinity;
|
|
54891
|
+
let minY = Infinity;
|
|
54892
|
+
let maxX = -Infinity;
|
|
54893
|
+
let maxY = -Infinity;
|
|
54894
|
+
for (const n3 of layout.nodes) {
|
|
54895
|
+
minX = Math.min(minX, n3.x);
|
|
54896
|
+
minY = Math.min(minY, n3.y);
|
|
54897
|
+
maxX = Math.max(maxX, n3.x + n3.width);
|
|
54898
|
+
maxY = Math.max(maxY, n3.y + n3.height);
|
|
54899
|
+
}
|
|
54900
|
+
if (layout.subgraphs) {
|
|
54901
|
+
for (const sg of layout.subgraphs) {
|
|
54902
|
+
minX = Math.min(minX, sg.x);
|
|
54903
|
+
minY = Math.min(minY, sg.y);
|
|
54904
|
+
maxX = Math.max(maxX, sg.x + sg.width);
|
|
54905
|
+
maxY = Math.max(maxY, sg.y + sg.height);
|
|
54906
|
+
}
|
|
54907
|
+
}
|
|
54908
|
+
for (const e3 of layout.edges) {
|
|
54909
|
+
if (e3.points)
|
|
54910
|
+
for (const p3 of e3.points) {
|
|
54911
|
+
minX = Math.min(minX, p3.x);
|
|
54912
|
+
minY = Math.min(minY, p3.y);
|
|
54913
|
+
maxX = Math.max(maxX, p3.x);
|
|
54914
|
+
maxY = Math.max(maxY, p3.y);
|
|
54915
|
+
}
|
|
54916
|
+
}
|
|
54917
|
+
if (!isFinite(minX)) {
|
|
54918
|
+
minX = 0;
|
|
54919
|
+
}
|
|
54920
|
+
if (!isFinite(minY)) {
|
|
54921
|
+
minY = 0;
|
|
54922
|
+
}
|
|
54923
|
+
if (!isFinite(maxX)) {
|
|
54924
|
+
maxX = layout.width;
|
|
54925
|
+
}
|
|
54926
|
+
if (!isFinite(maxY)) {
|
|
54927
|
+
maxY = layout.height;
|
|
54928
|
+
}
|
|
54929
|
+
const extraPadX = Math.max(0, -Math.floor(minX) + 1);
|
|
54930
|
+
const extraPadY = Math.max(0, -Math.floor(minY) + 1);
|
|
54931
|
+
const padX = this.padding + extraPadX;
|
|
54932
|
+
const padY = this.padding + extraPadY;
|
|
54933
|
+
const bboxWidth = Math.ceil(maxX) - Math.min(0, Math.floor(minX));
|
|
54934
|
+
const bboxHeight = Math.ceil(maxY) - Math.min(0, Math.floor(minY));
|
|
54935
|
+
const width = bboxWidth + this.padding * 2 + extraPadX;
|
|
54936
|
+
const height = bboxHeight + this.padding * 2 + extraPadY;
|
|
54937
|
+
const elements = [];
|
|
54938
|
+
const overlays = [];
|
|
54939
|
+
elements.push(this.generateDefs());
|
|
54940
|
+
if (layout.subgraphs && layout.subgraphs.length) {
|
|
54941
|
+
const sgs = layout.subgraphs;
|
|
54942
|
+
const order = sgs.slice().sort((a3, b3) => (a3.parent ? 1 : 0) - (b3.parent ? 1 : 0));
|
|
54943
|
+
const map4 = new Map(order.map((o3) => [o3.id, o3]));
|
|
54944
|
+
const depthOf = (sg) => {
|
|
54945
|
+
let d3 = 0;
|
|
54946
|
+
let p3 = sg.parent;
|
|
54947
|
+
while (p3) {
|
|
54948
|
+
d3++;
|
|
54949
|
+
p3 = map4.get(p3)?.parent;
|
|
54950
|
+
}
|
|
54951
|
+
return d3;
|
|
54952
|
+
};
|
|
54953
|
+
const bgs = [];
|
|
54954
|
+
for (const sg of order) {
|
|
54955
|
+
const x3 = sg.x + padX;
|
|
54956
|
+
const y2 = sg.y + padY;
|
|
54957
|
+
bgs.push(blockBackground(x3, y2, sg.width, sg.height, 0));
|
|
54958
|
+
const depth = depthOf(sg);
|
|
54959
|
+
const title = sg.label ? this.escapeXml(sg.label) : void 0;
|
|
54960
|
+
const titleYOffset = 7 + depth * 12;
|
|
54961
|
+
overlays.push(blockOverlay(x3, y2, sg.width, sg.height, title, [], titleYOffset, "center", "left", 0));
|
|
54962
|
+
}
|
|
54963
|
+
elements.push(`<g class="subgraph-bg">${bgs.join("")}</g>`);
|
|
54964
|
+
}
|
|
54965
|
+
const nodeMap = {};
|
|
54966
|
+
for (const n3 of layout.nodes) {
|
|
54967
|
+
nodeMap[n3.id] = { x: n3.x + padX, y: n3.y + padY, width: n3.width, height: n3.height, shape: n3.shape };
|
|
54968
|
+
}
|
|
54969
|
+
if (layout.subgraphs && layout.subgraphs.length) {
|
|
54970
|
+
for (const sg of layout.subgraphs) {
|
|
54971
|
+
nodeMap[sg.id] = { x: sg.x + padX, y: sg.y + padY, width: sg.width, height: sg.height, shape: "rectangle" };
|
|
54972
|
+
}
|
|
54973
|
+
}
|
|
54974
|
+
for (const node of layout.nodes) {
|
|
54975
|
+
elements.push(this.generateNodeWithPad(node, padX, padY));
|
|
54976
|
+
}
|
|
54977
|
+
for (const edge of layout.edges) {
|
|
54978
|
+
const { path: path6, overlay } = this.generateEdge(edge, padX, padY, nodeMap);
|
|
54979
|
+
elements.push(path6);
|
|
54980
|
+
if (overlay)
|
|
54981
|
+
overlays.push(overlay);
|
|
54982
|
+
}
|
|
54983
|
+
const bg = `<rect x="0" y="0" width="${width}" height="${height}" fill="#ffffff" />`;
|
|
54984
|
+
const sharedCss = buildSharedCss({
|
|
54985
|
+
fontFamily: this.fontFamily,
|
|
54986
|
+
fontSize: this.fontSize,
|
|
54987
|
+
nodeFill: this.defaultFill,
|
|
54988
|
+
nodeStroke: this.defaultStroke,
|
|
54989
|
+
edgeStroke: this.arrowStroke
|
|
54990
|
+
});
|
|
54991
|
+
const css = `<style>${sharedCss}</style>`;
|
|
54992
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
|
|
54993
|
+
${bg}
|
|
54994
|
+
${css}
|
|
54995
|
+
${elements.join("\n ")}
|
|
54996
|
+
${overlays.join("\n ")}
|
|
54997
|
+
</svg>`;
|
|
54998
|
+
}
|
|
54999
|
+
buildNodeStyleAttrs(style) {
|
|
55000
|
+
const decs = [];
|
|
55001
|
+
if (style.fill)
|
|
55002
|
+
decs.push(`fill:${style.fill}`);
|
|
55003
|
+
if (style.stroke)
|
|
55004
|
+
decs.push(`stroke:${style.stroke}`);
|
|
55005
|
+
if (style.strokeWidth != null)
|
|
55006
|
+
decs.push(`stroke-width:${style.strokeWidth}`);
|
|
55007
|
+
return decs.length ? `style="${decs.join(";")}"` : "";
|
|
55008
|
+
}
|
|
55009
|
+
buildNodeStrokeStyle(style) {
|
|
55010
|
+
const decs = [];
|
|
55011
|
+
if (style.stroke)
|
|
55012
|
+
decs.push(`stroke:${style.stroke}`);
|
|
55013
|
+
if (style.strokeWidth != null)
|
|
55014
|
+
decs.push(`stroke-width:${style.strokeWidth}`);
|
|
55015
|
+
return decs.length ? `style="${decs.join(";")}"` : "";
|
|
55016
|
+
}
|
|
55017
|
+
generateDefs() {
|
|
55018
|
+
const aw = Math.max(8, this.arrowMarkerSize + 2);
|
|
55019
|
+
const ah = Math.max(8, this.arrowMarkerSize + 2);
|
|
55020
|
+
const arefX = Math.max(6, aw);
|
|
55021
|
+
const arefY = Math.max(4, Math.round(ah / 2));
|
|
55022
|
+
return `<defs>
|
|
55023
|
+
<marker id="arrow" viewBox="0 0 ${aw} ${ah}" markerWidth="${aw}" markerHeight="${ah}" refX="${arefX}" refY="${arefY}" orient="auto" markerUnits="userSpaceOnUse">
|
|
55024
|
+
<path d="M0,0 L0,${ah} L${aw},${arefY} z" fill="${this.arrowStroke}" />
|
|
55025
|
+
</marker>
|
|
55026
|
+
<marker id="circle-marker" viewBox="0 0 9 9" markerWidth="9" markerHeight="9" refX="4.5" refY="4.5" orient="auto" markerUnits="userSpaceOnUse">
|
|
55027
|
+
<circle cx="4.5" cy="4.5" r="4.5" fill="${this.arrowStroke}" />
|
|
55028
|
+
</marker>
|
|
55029
|
+
<marker id="cross-marker" viewBox="0 0 12 12" markerWidth="12" markerHeight="12" refX="6" refY="6" orient="auto" markerUnits="userSpaceOnUse">
|
|
55030
|
+
<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" />
|
|
55031
|
+
</marker>
|
|
55032
|
+
</defs>`;
|
|
55033
|
+
}
|
|
55034
|
+
generateNodeWithPad(node, padX, padY) {
|
|
55035
|
+
const x3 = node.x + padX;
|
|
55036
|
+
const y2 = node.y + padY;
|
|
55037
|
+
const cx = x3 + node.width / 2;
|
|
55038
|
+
const cy = y2 + node.height / 2;
|
|
55039
|
+
let shape = "";
|
|
55040
|
+
let labelCenterY = cy;
|
|
55041
|
+
const strokeWidth = node.style?.strokeWidth ?? void 0;
|
|
55042
|
+
const stroke = node.style?.stroke ?? void 0;
|
|
55043
|
+
const fill = node.style?.fill ?? void 0;
|
|
55044
|
+
const styleAttr = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
|
|
55045
|
+
switch (node.shape) {
|
|
55046
|
+
case "rectangle":
|
|
55047
|
+
shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
|
|
55048
|
+
break;
|
|
55049
|
+
case "round":
|
|
55050
|
+
shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="5" ry="5" />`;
|
|
55051
|
+
break;
|
|
55052
|
+
case "stadium":
|
|
55053
|
+
const radius = node.height / 2;
|
|
55054
|
+
shape = `<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="${radius}" ry="${radius}" />`;
|
|
55055
|
+
break;
|
|
55056
|
+
case "circle":
|
|
55057
|
+
const r3 = Math.min(node.width, node.height) / 2;
|
|
55058
|
+
shape = `<circle class="node-shape" ${styleAttr} cx="${cx}" cy="${cy}" r="${r3}" />`;
|
|
55059
|
+
break;
|
|
55060
|
+
case "diamond": {
|
|
55061
|
+
const points = [
|
|
55062
|
+
`${cx},${y2}`,
|
|
55063
|
+
// top
|
|
55064
|
+
`${x3 + node.width},${cy}`,
|
|
55065
|
+
// right
|
|
55066
|
+
`${cx},${y2 + node.height}`,
|
|
55067
|
+
// bottom
|
|
55068
|
+
`${x3},${cy}`
|
|
55069
|
+
// left
|
|
55070
|
+
].join(" ");
|
|
55071
|
+
shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
|
|
55072
|
+
break;
|
|
55073
|
+
}
|
|
55074
|
+
case "hexagon": {
|
|
55075
|
+
const dx = node.width * 0.25;
|
|
55076
|
+
const points = [
|
|
55077
|
+
`${x3 + dx},${y2}`,
|
|
55078
|
+
// top-left
|
|
55079
|
+
`${x3 + node.width - dx},${y2}`,
|
|
55080
|
+
// top-right
|
|
55081
|
+
`${x3 + node.width},${cy}`,
|
|
55082
|
+
// right
|
|
55083
|
+
`${x3 + node.width - dx},${y2 + node.height}`,
|
|
55084
|
+
// bottom-right
|
|
55085
|
+
`${x3 + dx},${y2 + node.height}`,
|
|
55086
|
+
// bottom-left
|
|
55087
|
+
`${x3},${cy}`
|
|
55088
|
+
// left
|
|
55089
|
+
].join(" ");
|
|
55090
|
+
shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
|
|
55091
|
+
break;
|
|
55092
|
+
}
|
|
55093
|
+
case "parallelogram": {
|
|
55094
|
+
const skew = node.width * 0.15;
|
|
55095
|
+
const points = [
|
|
55096
|
+
`${x3 + skew},${y2}`,
|
|
55097
|
+
// top-left
|
|
55098
|
+
`${x3 + node.width},${y2}`,
|
|
55099
|
+
// top-right
|
|
55100
|
+
`${x3 + node.width - skew},${y2 + node.height}`,
|
|
55101
|
+
// bottom-right
|
|
55102
|
+
`${x3},${y2 + node.height}`
|
|
55103
|
+
// bottom-left
|
|
55104
|
+
].join(" ");
|
|
55105
|
+
shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
|
|
55106
|
+
break;
|
|
55107
|
+
}
|
|
55108
|
+
case "trapezoid": {
|
|
55109
|
+
const inset = node.width * 0.15;
|
|
55110
|
+
const points = [
|
|
55111
|
+
`${x3 + inset},${y2}`,
|
|
55112
|
+
// top-left
|
|
55113
|
+
`${x3 + node.width - inset},${y2}`,
|
|
55114
|
+
// top-right
|
|
55115
|
+
`${x3 + node.width},${y2 + node.height}`,
|
|
55116
|
+
// bottom-right
|
|
55117
|
+
`${x3},${y2 + node.height}`
|
|
55118
|
+
// bottom-left
|
|
55119
|
+
].join(" ");
|
|
55120
|
+
shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
|
|
55121
|
+
break;
|
|
55122
|
+
}
|
|
55123
|
+
case "trapezoidAlt": {
|
|
55124
|
+
const inset = node.width * 0.15;
|
|
55125
|
+
const points = [
|
|
55126
|
+
`${x3},${y2}`,
|
|
55127
|
+
// top-left (full width)
|
|
55128
|
+
`${x3 + node.width},${y2}`,
|
|
55129
|
+
// top-right
|
|
55130
|
+
`${x3 + node.width - inset},${y2 + node.height}`,
|
|
55131
|
+
// bottom-right (narrow)
|
|
55132
|
+
`${x3 + inset},${y2 + node.height}`
|
|
55133
|
+
// bottom-left (narrow)
|
|
55134
|
+
].join(" ");
|
|
55135
|
+
shape = `<polygon class="node-shape" ${styleAttr} points="${points}" />`;
|
|
55136
|
+
break;
|
|
55137
|
+
}
|
|
55138
|
+
case "cylinder": {
|
|
55139
|
+
const rx = Math.max(8, node.width / 2);
|
|
55140
|
+
const ry = Math.max(6, Math.min(node.height * 0.22, node.width * 0.25));
|
|
55141
|
+
const topCY = y2 + ry;
|
|
55142
|
+
const botCY = y2 + node.height - ry;
|
|
55143
|
+
const bodyH = Math.max(0, node.height - ry * 2);
|
|
55144
|
+
const strokeOnly = this.buildNodeStrokeStyle({ stroke, strokeWidth });
|
|
55145
|
+
shape = `<g>
|
|
55146
|
+
<rect class="node-shape" ${styleAttr} x="${x3}" y="${topCY}" width="${node.width}" height="${bodyH}" />
|
|
55147
|
+
<ellipse class="node-shape" ${styleAttr} cx="${cx}" cy="${topCY}" rx="${node.width / 2}" ry="${ry}" />
|
|
55148
|
+
<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" />
|
|
55149
|
+
</g>`;
|
|
55150
|
+
labelCenterY = topCY + bodyH / 2;
|
|
55151
|
+
break;
|
|
55152
|
+
}
|
|
55153
|
+
case "subroutine":
|
|
55154
|
+
const insetX = 5;
|
|
55155
|
+
const strokeOnly2 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
|
|
55156
|
+
shape = `<g>
|
|
55157
|
+
<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
|
|
55158
|
+
<line class="node-shape" ${strokeOnly2} x1="${x3 + insetX}" y1="${y2}" x2="${x3 + insetX}" y2="${y2 + node.height}" />
|
|
55159
|
+
<line class="node-shape" ${strokeOnly2} x1="${x3 + node.width - insetX}" y1="${y2}" x2="${x3 + node.width - insetX}" y2="${y2 + node.height}" />
|
|
55160
|
+
</g>`;
|
|
55161
|
+
break;
|
|
55162
|
+
case "double":
|
|
55163
|
+
const gap = 4;
|
|
55164
|
+
const strokeOnly3 = this.buildNodeStrokeStyle({ stroke, strokeWidth });
|
|
55165
|
+
shape = `<g>
|
|
55166
|
+
<rect class="node-shape" ${styleAttr} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />
|
|
55167
|
+
<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" />
|
|
55168
|
+
</g>`;
|
|
55169
|
+
break;
|
|
55170
|
+
default:
|
|
55171
|
+
const s3 = this.buildNodeStyleAttrs({ stroke, strokeWidth, fill });
|
|
55172
|
+
shape = `<rect ${s3} x="${x3}" y="${y2}" width="${node.width}" height="${node.height}" rx="0" ry="0" />`;
|
|
55173
|
+
}
|
|
55174
|
+
const text = this.generateWrappedText(node.label, cx, labelCenterY, node.width - 20);
|
|
55175
|
+
return `<g id="${node.id}">
|
|
55176
|
+
${shape}
|
|
55177
|
+
${text}
|
|
55178
|
+
</g>`;
|
|
55179
|
+
}
|
|
55180
|
+
generateWrappedText(text, x3, y2, maxWidth) {
|
|
55181
|
+
if (text.includes("<")) {
|
|
55182
|
+
return this.generateRichText(text, x3, y2, maxWidth);
|
|
55183
|
+
}
|
|
55184
|
+
const charWidth = 7;
|
|
55185
|
+
const maxCharsPerLine = Math.floor(maxWidth / charWidth);
|
|
55186
|
+
if (maxCharsPerLine <= 0 || text.length <= maxCharsPerLine) {
|
|
55187
|
+
const dyOffset = this.fontSize * 0.35;
|
|
55188
|
+
return `<text class="node-label" x="${x3}" y="${y2 + dyOffset}" text-anchor="middle">${this.escapeXml(text)}</text>`;
|
|
55189
|
+
}
|
|
55190
|
+
const words = text.split(" ");
|
|
55191
|
+
const lines = [];
|
|
55192
|
+
let currentLine = "";
|
|
55193
|
+
for (const word of words) {
|
|
55194
|
+
const testLine = currentLine ? `${currentLine} ${word}` : word;
|
|
55195
|
+
if (testLine.length > maxCharsPerLine && currentLine) {
|
|
55196
|
+
lines.push(currentLine);
|
|
55197
|
+
currentLine = word;
|
|
55198
|
+
} else {
|
|
55199
|
+
currentLine = testLine;
|
|
55200
|
+
}
|
|
55201
|
+
}
|
|
55202
|
+
if (currentLine) {
|
|
55203
|
+
lines.push(currentLine);
|
|
55204
|
+
}
|
|
55205
|
+
const lineHeight = 18;
|
|
55206
|
+
const totalHeight = (lines.length - 1) * lineHeight;
|
|
55207
|
+
const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
|
|
55208
|
+
const tspans = lines.map((line, i3) => {
|
|
55209
|
+
const lineY = startY + i3 * lineHeight;
|
|
55210
|
+
return `<tspan x="${x3}" y="${lineY}" text-anchor="middle">${this.escapeXml(line)}</tspan>`;
|
|
55211
|
+
}).join("\n ");
|
|
55212
|
+
return `<text class="node-label">
|
|
55213
|
+
${tspans}
|
|
55214
|
+
</text>`;
|
|
55215
|
+
}
|
|
55216
|
+
// Basic HTML-aware text renderer supporting <br>, <b>/<strong>, <i>/<em>, <u>
|
|
55217
|
+
generateRichText(html, x3, y2, maxWidth) {
|
|
55218
|
+
html = this.normalizeHtml(html);
|
|
55219
|
+
const segments = [];
|
|
55220
|
+
const re = /<\/?(br|b|strong|i|em|u)\s*\/?\s*>/gi;
|
|
55221
|
+
let lastIndex = 0;
|
|
55222
|
+
const state2 = { bold: false, italic: false, underline: false };
|
|
55223
|
+
const pushText = (t3) => {
|
|
55224
|
+
if (!t3)
|
|
55225
|
+
return;
|
|
55226
|
+
segments.push({ text: this.htmlDecode(t3), bold: state2.bold, italic: state2.italic, underline: state2.underline });
|
|
55227
|
+
};
|
|
55228
|
+
let m3;
|
|
55229
|
+
while (m3 = re.exec(html)) {
|
|
55230
|
+
pushText(html.slice(lastIndex, m3.index));
|
|
55231
|
+
const tag2 = m3[0].toLowerCase();
|
|
55232
|
+
const name14 = m3[1].toLowerCase();
|
|
55233
|
+
const isClose = tag2.startsWith("</");
|
|
55234
|
+
if (name14 === "br") {
|
|
55235
|
+
segments.push({ text: "", br: true });
|
|
55236
|
+
} else if (name14 === "b" || name14 === "strong") {
|
|
55237
|
+
state2.bold = !isClose ? true : false;
|
|
55238
|
+
} else if (name14 === "i" || name14 === "em") {
|
|
55239
|
+
state2.italic = !isClose ? true : false;
|
|
55240
|
+
} else if (name14 === "u") {
|
|
55241
|
+
state2.underline = !isClose ? true : false;
|
|
55242
|
+
}
|
|
55243
|
+
lastIndex = re.lastIndex;
|
|
55244
|
+
}
|
|
55245
|
+
pushText(html.slice(lastIndex));
|
|
55246
|
+
const lines = [];
|
|
55247
|
+
const charWidth = 7;
|
|
55248
|
+
const maxCharsPerLine = Math.max(1, Math.floor(maxWidth / charWidth));
|
|
55249
|
+
let current = [];
|
|
55250
|
+
let currentLen = 0;
|
|
55251
|
+
const flush = () => {
|
|
55252
|
+
if (current.length) {
|
|
55253
|
+
lines.push(current);
|
|
55254
|
+
current = [];
|
|
55255
|
+
currentLen = 0;
|
|
55256
|
+
}
|
|
55257
|
+
};
|
|
55258
|
+
const splitWords = (s3) => {
|
|
55259
|
+
if (!s3.text)
|
|
55260
|
+
return [s3];
|
|
55261
|
+
const words = s3.text.split(/(\s+)/);
|
|
55262
|
+
return words.map((w3) => ({ ...s3, text: w3 }));
|
|
55263
|
+
};
|
|
55264
|
+
for (const seg of segments) {
|
|
55265
|
+
if (seg.br) {
|
|
55266
|
+
flush();
|
|
55267
|
+
continue;
|
|
55268
|
+
}
|
|
55269
|
+
for (const w3 of splitWords(seg)) {
|
|
55270
|
+
const wlen = w3.text.length;
|
|
55271
|
+
if (currentLen + wlen > maxCharsPerLine && currentLen > 0) {
|
|
55272
|
+
flush();
|
|
55273
|
+
}
|
|
55274
|
+
current.push(w3);
|
|
55275
|
+
currentLen += wlen;
|
|
55276
|
+
}
|
|
55277
|
+
}
|
|
55278
|
+
flush();
|
|
55279
|
+
const lineHeight = 18;
|
|
55280
|
+
const totalHeight = (lines.length - 1) * lineHeight;
|
|
55281
|
+
const startY = y2 - totalHeight / 2 + this.fontSize * 0.35;
|
|
55282
|
+
const tspans = [];
|
|
55283
|
+
for (let i3 = 0; i3 < lines.length; i3++) {
|
|
55284
|
+
const lineY = startY + i3 * lineHeight;
|
|
55285
|
+
let acc = "";
|
|
55286
|
+
let cursorX = x3;
|
|
55287
|
+
const inner = [];
|
|
55288
|
+
let buffer = "";
|
|
55289
|
+
let style = { bold: false, italic: false, underline: false };
|
|
55290
|
+
const flushInline = () => {
|
|
55291
|
+
if (!buffer)
|
|
55292
|
+
return;
|
|
55293
|
+
const styleAttr = `${style.bold ? 'font-weight="bold" ' : ""}${style.italic ? 'font-style="italic" ' : ""}${style.underline ? 'text-decoration="underline" ' : ""}`;
|
|
55294
|
+
inner.push(`<tspan ${styleAttr}>${this.escapeXml(buffer)}</tspan>`);
|
|
55295
|
+
buffer = "";
|
|
55296
|
+
};
|
|
55297
|
+
for (const w3 of lines[i3]) {
|
|
55298
|
+
const wStyle = { bold: !!w3.bold, italic: !!w3.italic, underline: !!w3.underline };
|
|
55299
|
+
if (wStyle.bold !== style.bold || wStyle.italic !== style.italic || wStyle.underline !== style.underline) {
|
|
55300
|
+
flushInline();
|
|
55301
|
+
style = wStyle;
|
|
55302
|
+
}
|
|
55303
|
+
buffer += w3.text;
|
|
55304
|
+
}
|
|
55305
|
+
flushInline();
|
|
55306
|
+
tspans.push(`<tspan x="${x3}" y="${lineY}" text-anchor="middle">${inner.join("")}</tspan>`);
|
|
55307
|
+
}
|
|
55308
|
+
return `<text font-family="${this.fontFamily}" font-size="${this.fontSize}" fill="#333">${tspans.join("\n ")}</text>`;
|
|
55309
|
+
}
|
|
55310
|
+
normalizeHtml(s3) {
|
|
55311
|
+
let out = s3.replace(/<\s+/g, "<").replace(/\s+>/g, ">").replace(/<\s*\//g, "</").replace(/\s*\/\s*>/g, "/>").replace(/<\s*(br)\s*>/gi, "<$1/>");
|
|
55312
|
+
return out;
|
|
55313
|
+
}
|
|
55314
|
+
htmlDecode(s3) {
|
|
55315
|
+
return s3.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'");
|
|
55316
|
+
}
|
|
55317
|
+
generateEdge(edge, padX, padY, nodeMap) {
|
|
55318
|
+
if (!edge.points || edge.points.length < 2) {
|
|
55319
|
+
return { path: "" };
|
|
55320
|
+
}
|
|
55321
|
+
const points = edge.points.map((p3) => ({ x: p3.x + padX, y: p3.y + padY }));
|
|
55322
|
+
const segData = this.buildSmoothSegments(points);
|
|
55323
|
+
let strokeDasharray = "";
|
|
55324
|
+
let strokeWidth = 1.5;
|
|
55325
|
+
let markerEnd = "";
|
|
55326
|
+
let markerStart = "";
|
|
55327
|
+
switch (edge.type) {
|
|
55328
|
+
case "open":
|
|
55329
|
+
markerEnd = "";
|
|
55330
|
+
break;
|
|
55331
|
+
case "dotted":
|
|
55332
|
+
strokeDasharray = "3,3";
|
|
55333
|
+
break;
|
|
55334
|
+
case "thick":
|
|
55335
|
+
strokeWidth = 3;
|
|
55336
|
+
break;
|
|
55337
|
+
case "invisible":
|
|
55338
|
+
strokeDasharray = "0,100000";
|
|
55339
|
+
markerEnd = "";
|
|
55340
|
+
break;
|
|
55341
|
+
}
|
|
55342
|
+
const mStart = edge.markerStart;
|
|
55343
|
+
const mEnd = edge.markerEnd;
|
|
55344
|
+
const sourceNode = nodeMap[edge.source];
|
|
55345
|
+
const targetNode = nodeMap[edge.target];
|
|
55346
|
+
let boundaryStart = points[0];
|
|
55347
|
+
let boundaryEnd = points[points.length - 1];
|
|
55348
|
+
if (sourceNode && points.length >= 2) {
|
|
55349
|
+
const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
|
|
55350
|
+
boundaryStart = this.intersectSegmentsStart(pseudo, sourceNode).start;
|
|
55351
|
+
}
|
|
55352
|
+
if (targetNode && points.length >= 2) {
|
|
55353
|
+
const pseudo = { start: points[0], segs: [{ c1: points[1], c2: points[Math.max(0, points.length - 2)], to: points[points.length - 1] }] };
|
|
55354
|
+
const after = this.intersectSegmentsEnd(pseudo, targetNode);
|
|
55355
|
+
boundaryEnd = after.segs.length ? after.segs[after.segs.length - 1].to : boundaryEnd;
|
|
55356
|
+
}
|
|
55357
|
+
const pathParts = [];
|
|
55358
|
+
pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
|
|
55359
|
+
let startFlat = points.length >= 2 ? points[1] : boundaryStart;
|
|
55360
|
+
if (points.length >= 2) {
|
|
55361
|
+
const svx = points[1].x - boundaryStart.x;
|
|
55362
|
+
const svy = points[1].y - boundaryStart.y;
|
|
55363
|
+
const slen = Math.hypot(svx, svy) || 1;
|
|
55364
|
+
const SFLAT = Math.min(22, Math.max(10, slen * 0.15));
|
|
55365
|
+
startFlat = { x: boundaryStart.x + svx / slen * SFLAT, y: boundaryStart.y + svy / slen * SFLAT };
|
|
55366
|
+
pathParts.push(`L${startFlat.x},${startFlat.y}`);
|
|
55367
|
+
}
|
|
55368
|
+
const orthogonal = edge.pathMode === "orthogonal";
|
|
55369
|
+
if (points.length >= 4 && !orthogonal) {
|
|
55370
|
+
const pts = [points[0], ...points, points[points.length - 1]];
|
|
55371
|
+
for (let i3 = 1; i3 < pts.length - 3; i3++) {
|
|
55372
|
+
const p0 = pts[i3 - 1];
|
|
55373
|
+
const p1 = pts[i3];
|
|
55374
|
+
const p22 = pts[i3 + 1];
|
|
55375
|
+
const p3 = pts[i3 + 2];
|
|
55376
|
+
const c1x = p1.x + (p22.x - p0.x) / 6;
|
|
55377
|
+
const c1y = p1.y + (p22.y - p0.y) / 6;
|
|
55378
|
+
const c2x = p22.x - (p3.x - p1.x) / 6;
|
|
55379
|
+
const c2y = p22.y - (p3.y - p1.y) / 6;
|
|
55380
|
+
pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${p22.x},${p22.y}`);
|
|
55381
|
+
}
|
|
55382
|
+
pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
|
|
55383
|
+
} else if (points.length === 3 && !orthogonal) {
|
|
55384
|
+
const p0 = boundaryStart, p1 = points[1], p22 = boundaryEnd;
|
|
55385
|
+
const ax = boundaryEnd.x - p1.x;
|
|
55386
|
+
const ay = boundaryEnd.y - p1.y;
|
|
55387
|
+
const alen = Math.hypot(ax, ay) || 1;
|
|
55388
|
+
const FLAT_IN = Math.min(20, Math.max(10, alen * 0.15));
|
|
55389
|
+
const preEnd = { x: boundaryEnd.x - ax / alen * FLAT_IN, y: boundaryEnd.y - ay / alen * FLAT_IN };
|
|
55390
|
+
const sdx = startFlat.x - boundaryStart.x;
|
|
55391
|
+
const sdy = startFlat.y - boundaryStart.y;
|
|
55392
|
+
const sdirx = sdx === 0 && sdy === 0 ? p1.x - p0.x : sdx;
|
|
55393
|
+
const sdiry = sdx === 0 && sdy === 0 ? p1.y - p0.y : sdy;
|
|
55394
|
+
const sdlen = Math.hypot(sdirx, sdiry) || 1;
|
|
55395
|
+
const c1len = Math.min(40, Math.max(12, sdlen * 1.2));
|
|
55396
|
+
const c1x = startFlat.x + sdirx / sdlen * c1len;
|
|
55397
|
+
const c1y = startFlat.y + sdiry / sdlen * c1len;
|
|
55398
|
+
const dirx = (boundaryEnd.x - p1.x) / alen;
|
|
55399
|
+
const diry = (boundaryEnd.y - p1.y) / alen;
|
|
55400
|
+
const c2x = preEnd.x - dirx * (FLAT_IN * 0.6);
|
|
55401
|
+
const c2y = preEnd.y - diry * (FLAT_IN * 0.6);
|
|
55402
|
+
pathParts.push(`C${c1x},${c1y} ${c2x},${c2y} ${preEnd.x},${preEnd.y}`);
|
|
55403
|
+
pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
|
|
55404
|
+
} else {
|
|
55405
|
+
pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
|
|
55406
|
+
}
|
|
55407
|
+
if (orthogonal) {
|
|
55408
|
+
pathParts.length = 0;
|
|
55409
|
+
pathParts.push(`M${boundaryStart.x},${boundaryStart.y}`);
|
|
55410
|
+
for (const p3 of points.slice(1, -1))
|
|
55411
|
+
pathParts.push(`L${p3.x},${p3.y}`);
|
|
55412
|
+
pathParts.push(`L${boundaryEnd.x},${boundaryEnd.y}`);
|
|
55413
|
+
}
|
|
55414
|
+
const pathData = pathParts.join(" ");
|
|
55415
|
+
let edgeElement = `<path class="edge-path" d="${pathData}" stroke-linecap="round" stroke-linejoin="round"`;
|
|
55416
|
+
if (strokeDasharray) {
|
|
55417
|
+
edgeElement += ` stroke-dasharray="${strokeDasharray}"`;
|
|
55418
|
+
}
|
|
55419
|
+
const startMarkUrl = mStart === "arrow" ? "url(#arrow)" : mStart === "circle" ? "url(#circle-marker)" : mStart === "cross" ? "url(#cross-marker)" : "";
|
|
55420
|
+
const endMarkUrl = mEnd === "arrow" ? "url(#arrow)" : mEnd === "circle" ? "url(#circle-marker)" : mEnd === "cross" ? "url(#cross-marker)" : markerEnd || "";
|
|
55421
|
+
if (startMarkUrl && mStart !== "arrow")
|
|
55422
|
+
edgeElement += ` marker-start="${startMarkUrl}"`;
|
|
55423
|
+
if (endMarkUrl && mEnd !== "arrow")
|
|
55424
|
+
edgeElement += ` marker-end="${endMarkUrl}"`;
|
|
55425
|
+
edgeElement += " />";
|
|
55426
|
+
if (edge.label) {
|
|
55427
|
+
const pos = this.pointAtRatio(points, 0.55);
|
|
55428
|
+
const text = this.escapeXml(edge.label);
|
|
55429
|
+
const padding = 4;
|
|
55430
|
+
const fontSize = this.fontSize - 3;
|
|
55431
|
+
const width = Math.max(18, Math.min(220, text.length * 6 + padding * 2));
|
|
55432
|
+
const height = 14;
|
|
55433
|
+
const x3 = pos.x - width / 2;
|
|
55434
|
+
const y2 = pos.y - height / 2;
|
|
55435
|
+
const labelBg = `<rect class="edge-label-bg" x="${x3}" y="${y2}" width="${width}" height="${height}" rx="3" />`;
|
|
55436
|
+
const labelText = `<text class="edge-label-text" x="${pos.x}" y="${pos.y}" text-anchor="middle" dominant-baseline="middle">${text}</text>`;
|
|
55437
|
+
let overlay2 = "";
|
|
55438
|
+
const prevEndL = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
|
|
55439
|
+
const vxl = boundaryEnd.x - prevEndL.x;
|
|
55440
|
+
const vyl = boundaryEnd.y - prevEndL.y;
|
|
55441
|
+
const vlenl = Math.hypot(vxl, vyl) || 1;
|
|
55442
|
+
const uxl = vxl / vlenl;
|
|
55443
|
+
const uyl = vyl / vlenl;
|
|
55444
|
+
const nxl = -uyl;
|
|
55445
|
+
const nyl = uxl;
|
|
55446
|
+
const triLenL = 8;
|
|
55447
|
+
const triWL = 6;
|
|
55448
|
+
const p1xL = boundaryEnd.x, p1yL = boundaryEnd.y;
|
|
55449
|
+
const baseXL = boundaryEnd.x - uxl * triLenL;
|
|
55450
|
+
const baseYL = boundaryEnd.y - uyl * triLenL;
|
|
55451
|
+
const p2xL = baseXL + nxl * (triWL / 2), p2yL = baseYL + nyl * (triWL / 2);
|
|
55452
|
+
const p3xL = baseXL - nxl * (triWL / 2), p3yL = baseYL - nyl * (triWL / 2);
|
|
55453
|
+
overlay2 += triangleAtEnd(prevEndL, boundaryEnd, this.arrowStroke);
|
|
55454
|
+
if (mStart === "arrow" && points.length >= 2) {
|
|
55455
|
+
const firstLeg = points[1];
|
|
55456
|
+
const svx = boundaryStart.x - firstLeg.x;
|
|
55457
|
+
const svy = boundaryStart.y - firstLeg.y;
|
|
55458
|
+
const slen = Math.hypot(svx, svy) || 1;
|
|
55459
|
+
const sux = svx / slen;
|
|
55460
|
+
const suy = svy / slen;
|
|
55461
|
+
const snx = -suy;
|
|
55462
|
+
const sny = sux;
|
|
55463
|
+
const sbaseX = boundaryStart.x - sux * triLenL;
|
|
55464
|
+
const sbaseY = boundaryStart.y - suy * triLenL;
|
|
55465
|
+
overlay2 += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
|
|
55466
|
+
}
|
|
55467
|
+
const pathGroup = `<g>
|
|
55468
|
+
${edgeElement}
|
|
55469
|
+
${labelBg}
|
|
55470
|
+
${labelText}
|
|
55471
|
+
${overlay2}
|
|
55472
|
+
</g>`;
|
|
55473
|
+
return { path: pathGroup };
|
|
55474
|
+
}
|
|
55475
|
+
let overlay = "";
|
|
55476
|
+
const prevEnd = points.length >= 2 ? points[points.length - 2] : boundaryEnd;
|
|
55477
|
+
const vx = boundaryEnd.x - prevEnd.x;
|
|
55478
|
+
const vy = boundaryEnd.y - prevEnd.y;
|
|
55479
|
+
const vlen = Math.hypot(vx, vy) || 1;
|
|
55480
|
+
const ux = vx / vlen;
|
|
55481
|
+
const uy = vy / vlen;
|
|
55482
|
+
const nx = -uy;
|
|
55483
|
+
const ny = ux;
|
|
55484
|
+
const triLen = 8;
|
|
55485
|
+
const triW = 6;
|
|
55486
|
+
const p1x = boundaryEnd.x, p1y = boundaryEnd.y;
|
|
55487
|
+
const baseX = boundaryEnd.x - ux * triLen;
|
|
55488
|
+
const baseY = boundaryEnd.y - uy * triLen;
|
|
55489
|
+
const p2x = baseX + nx * (triW / 2), p2y = baseY + ny * (triW / 2);
|
|
55490
|
+
const p3x = baseX - nx * (triW / 2), p3y = baseY - ny * (triW / 2);
|
|
55491
|
+
if (mEnd === "arrow")
|
|
55492
|
+
overlay += triangleAtEnd(prevEnd, boundaryEnd, this.arrowStroke);
|
|
55493
|
+
if (mStart === "arrow" && points.length >= 2) {
|
|
55494
|
+
const firstLeg = points[1];
|
|
55495
|
+
const svx = boundaryStart.x - firstLeg.x;
|
|
55496
|
+
const svy = boundaryStart.y - firstLeg.y;
|
|
55497
|
+
const slen = Math.hypot(svx, svy) || 1;
|
|
55498
|
+
const sux = svx / slen;
|
|
55499
|
+
const suy = svy / slen;
|
|
55500
|
+
const snx = -suy;
|
|
55501
|
+
const sny = sux;
|
|
55502
|
+
overlay += triangleAtStart(boundaryStart, firstLeg, this.arrowStroke);
|
|
55503
|
+
}
|
|
55504
|
+
if (overlay) {
|
|
55505
|
+
const grouped = `<g>${edgeElement}
|
|
55506
|
+
${overlay}</g>`;
|
|
55507
|
+
return { path: grouped };
|
|
55508
|
+
}
|
|
55509
|
+
return { path: edgeElement };
|
|
55510
|
+
}
|
|
55511
|
+
// --- helpers ---
|
|
55512
|
+
buildSmoothSegments(points) {
|
|
55513
|
+
if (points.length < 2) {
|
|
55514
|
+
const p3 = points[0] || { x: 0, y: 0 };
|
|
55515
|
+
return { start: p3, segs: [] };
|
|
55516
|
+
}
|
|
55517
|
+
if (points.length === 2) {
|
|
55518
|
+
const p0 = points[0];
|
|
55519
|
+
const p1 = points[1];
|
|
55520
|
+
const c1 = { x: p0.x + (p1.x - p0.x) / 3, y: p0.y + (p1.y - p0.y) / 3 };
|
|
55521
|
+
const c22 = { x: p0.x + 2 * (p1.x - p0.x) / 3, y: p0.y + 2 * (p1.y - p0.y) / 3 };
|
|
55522
|
+
return { start: p0, segs: [{ c1, c2: c22, to: p1 }] };
|
|
55523
|
+
}
|
|
55524
|
+
const pts = [points[0], ...points, points[points.length - 1]];
|
|
55525
|
+
const segs = [];
|
|
55526
|
+
const firstIdx = 1;
|
|
55527
|
+
const lastIdx = pts.length - 3;
|
|
55528
|
+
const midFactor = 1;
|
|
55529
|
+
const endFactor = 0.35;
|
|
55530
|
+
const FLAT_LEN = 28;
|
|
55531
|
+
for (let i3 = 1; i3 < pts.length - 2; i3++) {
|
|
55532
|
+
const p0 = pts[i3 - 1];
|
|
55533
|
+
const p1 = pts[i3];
|
|
55534
|
+
const p22 = pts[i3 + 1];
|
|
55535
|
+
const p3 = pts[i3 + 2];
|
|
55536
|
+
const f1 = i3 === firstIdx ? endFactor : midFactor;
|
|
55537
|
+
const f22 = i3 === lastIdx ? endFactor : midFactor;
|
|
55538
|
+
let c1 = { x: p1.x + (p22.x - p0.x) / 6 * f1, y: p1.y + (p22.y - p0.y) / 6 * f1 };
|
|
55539
|
+
let c22 = { x: p22.x - (p3.x - p1.x) / 6 * f22, y: p22.y - (p3.y - p1.y) / 6 * f22 };
|
|
55540
|
+
if (i3 === firstIdx) {
|
|
55541
|
+
const dx = p22.x - p1.x, dy = p22.y - p1.y;
|
|
55542
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
55543
|
+
const t3 = Math.min(FLAT_LEN, len * 0.5);
|
|
55544
|
+
c1 = { x: p1.x + dx / len * t3, y: p1.y + dy / len * t3 };
|
|
55545
|
+
}
|
|
55546
|
+
if (i3 === lastIdx) {
|
|
55547
|
+
const dx = p22.x - p1.x, dy = p22.y - p1.y;
|
|
55548
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
55549
|
+
const t3 = Math.min(FLAT_LEN, len * 0.5);
|
|
55550
|
+
c22 = { x: p22.x - dx / len * t3, y: p22.y - dy / len * t3 };
|
|
55551
|
+
}
|
|
55552
|
+
segs.push({ c1, c2: c22, to: { x: p22.x, y: p22.y } });
|
|
55553
|
+
}
|
|
55554
|
+
return { start: pts[1], segs };
|
|
55555
|
+
}
|
|
55556
|
+
pathFromSegments(data2) {
|
|
55557
|
+
let d3 = `M${data2.start.x},${data2.start.y}`;
|
|
55558
|
+
for (const s3 of data2.segs) {
|
|
55559
|
+
d3 += ` C${s3.c1.x},${s3.c1.y} ${s3.c2.x},${s3.c2.y} ${s3.to.x},${s3.to.y}`;
|
|
55560
|
+
}
|
|
55561
|
+
return d3;
|
|
55562
|
+
}
|
|
55563
|
+
trimSegmentsEnd(data2, cut) {
|
|
55564
|
+
const segs = data2.segs.slice();
|
|
55565
|
+
if (!segs.length)
|
|
55566
|
+
return data2;
|
|
55567
|
+
const last2 = { ...segs[segs.length - 1] };
|
|
55568
|
+
const vx = last2.to.x - last2.c2.x;
|
|
55569
|
+
const vy = last2.to.y - last2.c2.y;
|
|
55570
|
+
const len = Math.hypot(vx, vy) || 1;
|
|
55571
|
+
const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
|
|
55572
|
+
const nx = vx / len;
|
|
55573
|
+
const ny = vy / len;
|
|
55574
|
+
const newTo = { x: last2.to.x - nx * eff, y: last2.to.y - ny * eff };
|
|
55575
|
+
last2.to = newTo;
|
|
55576
|
+
segs[segs.length - 1] = last2;
|
|
55577
|
+
return { start: data2.start, segs };
|
|
55578
|
+
}
|
|
55579
|
+
trimSegmentsStart(data2, cut) {
|
|
55580
|
+
const segs = data2.segs.slice();
|
|
55581
|
+
if (!segs.length)
|
|
55582
|
+
return data2;
|
|
55583
|
+
const first2 = { ...segs[0] };
|
|
55584
|
+
const vx = first2.c1.x - data2.start.x;
|
|
55585
|
+
const vy = first2.c1.y - data2.start.y;
|
|
55586
|
+
const len = Math.hypot(vx, vy) || 1;
|
|
55587
|
+
const eff = Math.max(0.1, Math.min(cut, Math.max(0, len - 0.2)));
|
|
55588
|
+
const nx = vx / len;
|
|
55589
|
+
const ny = vy / len;
|
|
55590
|
+
const newStart = { x: data2.start.x + nx * eff, y: data2.start.y + ny * eff };
|
|
55591
|
+
return { start: newStart, segs };
|
|
55592
|
+
}
|
|
55593
|
+
// ---- shape intersections ----
|
|
55594
|
+
intersectSegmentsEnd(data2, node) {
|
|
55595
|
+
if (!data2.segs.length)
|
|
55596
|
+
return data2;
|
|
55597
|
+
const last2 = data2.segs[data2.segs.length - 1];
|
|
55598
|
+
const p1 = last2.c2;
|
|
55599
|
+
const p22 = last2.to;
|
|
55600
|
+
const hit = this.intersectLineWithNode(p1, p22, node);
|
|
55601
|
+
if (hit) {
|
|
55602
|
+
const segs = data2.segs.slice();
|
|
55603
|
+
segs[segs.length - 1] = { ...last2, to: hit };
|
|
55604
|
+
return { start: data2.start, segs };
|
|
55605
|
+
}
|
|
55606
|
+
return data2;
|
|
55607
|
+
}
|
|
55608
|
+
intersectSegmentsStart(data2, node) {
|
|
55609
|
+
if (!data2.segs.length)
|
|
55610
|
+
return data2;
|
|
55611
|
+
const first2 = data2.segs[0];
|
|
55612
|
+
const p1 = data2.start;
|
|
55613
|
+
const p22 = first2.c1;
|
|
55614
|
+
const hit = this.intersectLineWithNode(p1, p22, node);
|
|
55615
|
+
if (hit) {
|
|
55616
|
+
return { start: hit, segs: data2.segs };
|
|
55617
|
+
}
|
|
55618
|
+
return data2;
|
|
55619
|
+
}
|
|
55620
|
+
intersectLineWithNode(p1, p22, node) {
|
|
55621
|
+
const shape = node.shape;
|
|
55622
|
+
const rectPoly = () => [
|
|
55623
|
+
{ x: node.x, y: node.y },
|
|
55624
|
+
{ x: node.x + node.width, y: node.y },
|
|
55625
|
+
{ x: node.x + node.width, y: node.y + node.height },
|
|
55626
|
+
{ x: node.x, y: node.y + node.height }
|
|
55627
|
+
];
|
|
55628
|
+
switch (shape) {
|
|
55629
|
+
case "circle": {
|
|
55630
|
+
const cx = node.x + node.width / 2;
|
|
55631
|
+
const cy = node.y + node.height / 2;
|
|
55632
|
+
const r3 = Math.min(node.width, node.height) / 2;
|
|
55633
|
+
return this.lineCircleIntersection(p1, p22, { cx, cy, r: r3 });
|
|
55634
|
+
}
|
|
55635
|
+
case "diamond": {
|
|
55636
|
+
const cx = node.x + node.width / 2;
|
|
55637
|
+
const cy = node.y + node.height / 2;
|
|
55638
|
+
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 }];
|
|
55639
|
+
return this.linePolygonIntersection(p1, p22, poly);
|
|
55640
|
+
}
|
|
55641
|
+
case "hexagon": {
|
|
55642
|
+
const s3 = Math.max(10, node.width * 0.2);
|
|
55643
|
+
const poly = [
|
|
55644
|
+
{ x: node.x + s3, y: node.y },
|
|
55645
|
+
{ x: node.x + node.width - s3, y: node.y },
|
|
55646
|
+
{ x: node.x + node.width, y: node.y + node.height / 2 },
|
|
55647
|
+
{ x: node.x + node.width - s3, y: node.y + node.height },
|
|
55648
|
+
{ x: node.x + s3, y: node.y + node.height },
|
|
55649
|
+
{ x: node.x, y: node.y + node.height / 2 }
|
|
55650
|
+
];
|
|
55651
|
+
return this.linePolygonIntersection(p1, p22, poly);
|
|
55652
|
+
}
|
|
55653
|
+
case "parallelogram": {
|
|
55654
|
+
const o3 = Math.min(node.width * 0.25, node.height * 0.6);
|
|
55655
|
+
const poly = [
|
|
55656
|
+
{ x: node.x + o3, y: node.y },
|
|
55657
|
+
{ x: node.x + node.width, y: node.y },
|
|
55658
|
+
{ x: node.x + node.width - o3, y: node.y + node.height },
|
|
55659
|
+
{ x: node.x, y: node.y + node.height }
|
|
55660
|
+
];
|
|
55661
|
+
return this.linePolygonIntersection(p1, p22, poly);
|
|
55662
|
+
}
|
|
55663
|
+
case "trapezoid": {
|
|
55664
|
+
const o3 = Math.min(node.width * 0.2, node.height * 0.5);
|
|
55665
|
+
const poly = [
|
|
55666
|
+
{ x: node.x + o3, y: node.y },
|
|
55667
|
+
{ x: node.x + node.width - o3, y: node.y },
|
|
55668
|
+
{ x: node.x + node.width, y: node.y + node.height },
|
|
55669
|
+
{ x: node.x, y: node.y + node.height }
|
|
55670
|
+
];
|
|
55671
|
+
return this.linePolygonIntersection(p1, p22, poly);
|
|
55672
|
+
}
|
|
55673
|
+
case "trapezoidAlt": {
|
|
55674
|
+
const o3 = Math.min(node.width * 0.2, node.height * 0.5);
|
|
55675
|
+
const poly = [
|
|
55676
|
+
{ x: node.x, y: node.y },
|
|
55677
|
+
{ x: node.x + node.width, y: node.y },
|
|
55678
|
+
{ x: node.x + node.width - o3, y: node.y + node.height },
|
|
55679
|
+
{ x: node.x + o3, y: node.y + node.height }
|
|
55680
|
+
];
|
|
55681
|
+
return this.linePolygonIntersection(p1, p22, poly);
|
|
55682
|
+
}
|
|
55683
|
+
case "stadium": {
|
|
55684
|
+
const r3 = Math.min(node.height / 2, node.width / 2);
|
|
55685
|
+
const rect = [
|
|
55686
|
+
{ x: node.x + r3, y: node.y },
|
|
55687
|
+
{ x: node.x + node.width - r3, y: node.y },
|
|
55688
|
+
{ x: node.x + node.width - r3, y: node.y + node.height },
|
|
55689
|
+
{ x: node.x + r3, y: node.y + node.height }
|
|
55690
|
+
];
|
|
55691
|
+
const hitRect = this.linePolygonIntersection(p1, p22, rect);
|
|
55692
|
+
if (hitRect)
|
|
55693
|
+
return hitRect;
|
|
55694
|
+
const left = this.lineCircleIntersection(p1, p22, { cx: node.x + r3, cy: node.y + node.height / 2, r: r3 });
|
|
55695
|
+
const right = this.lineCircleIntersection(p1, p22, { cx: node.x + node.width - r3, cy: node.y + node.height / 2, r: r3 });
|
|
55696
|
+
const pick = (...pts) => {
|
|
55697
|
+
let best = null;
|
|
55698
|
+
let bestd = -Infinity;
|
|
55699
|
+
for (const pt of pts)
|
|
55700
|
+
if (pt) {
|
|
55701
|
+
const d3 = -((pt.x - p22.x) ** 2 + (pt.y - p22.y) ** 2);
|
|
55702
|
+
if (d3 > bestd) {
|
|
55703
|
+
bestd = d3;
|
|
55704
|
+
best = pt;
|
|
55705
|
+
}
|
|
55706
|
+
}
|
|
55707
|
+
return best;
|
|
55708
|
+
};
|
|
55709
|
+
return pick(left, right);
|
|
55710
|
+
}
|
|
55711
|
+
default: {
|
|
55712
|
+
return this.linePolygonIntersection(p1, p22, rectPoly());
|
|
55713
|
+
}
|
|
55714
|
+
}
|
|
55715
|
+
}
|
|
55716
|
+
lineCircleIntersection(p1, p22, c3) {
|
|
55717
|
+
const dx = p22.x - p1.x;
|
|
55718
|
+
const dy = p22.y - p1.y;
|
|
55719
|
+
const fx = p1.x - c3.cx;
|
|
55720
|
+
const fy = p1.y - c3.cy;
|
|
55721
|
+
const a3 = dx * dx + dy * dy;
|
|
55722
|
+
const b3 = 2 * (fx * dx + fy * dy);
|
|
55723
|
+
const cc2 = fx * fx + fy * fy - c3.r * c3.r;
|
|
55724
|
+
const disc = b3 * b3 - 4 * a3 * cc2;
|
|
55725
|
+
if (disc < 0)
|
|
55726
|
+
return null;
|
|
55727
|
+
const s3 = Math.sqrt(disc);
|
|
55728
|
+
const t1 = (-b3 - s3) / (2 * a3);
|
|
55729
|
+
const t22 = (-b3 + s3) / (2 * a3);
|
|
55730
|
+
const ts = [t1, t22].filter((t4) => t4 >= 0 && t4 <= 1);
|
|
55731
|
+
if (!ts.length)
|
|
55732
|
+
return null;
|
|
55733
|
+
const t3 = Math.max(...ts);
|
|
55734
|
+
return { x: p1.x + dx * t3, y: p1.y + dy * t3 };
|
|
55735
|
+
}
|
|
55736
|
+
linePolygonIntersection(p1, p22, poly) {
|
|
55737
|
+
let bestT = -Infinity;
|
|
55738
|
+
let best = null;
|
|
55739
|
+
for (let i3 = 0; i3 < poly.length; i3++) {
|
|
55740
|
+
const a3 = poly[i3];
|
|
55741
|
+
const b3 = poly[(i3 + 1) % poly.length];
|
|
55742
|
+
const hit = this.segmentIntersection(p1, p22, a3, b3);
|
|
55743
|
+
if (hit && hit.t >= 0 && hit.t <= 1 && hit.u >= 0 && hit.u <= 1) {
|
|
55744
|
+
if (hit.t > bestT) {
|
|
55745
|
+
bestT = hit.t;
|
|
55746
|
+
best = { x: hit.x, y: hit.y };
|
|
55747
|
+
}
|
|
55748
|
+
}
|
|
55749
|
+
}
|
|
55750
|
+
return best;
|
|
55751
|
+
}
|
|
55752
|
+
segmentIntersection(p3, p22, q3, q22) {
|
|
55753
|
+
const r3 = { x: p22.x - p3.x, y: p22.y - p3.y };
|
|
55754
|
+
const s3 = { x: q22.x - q3.x, y: q22.y - q3.y };
|
|
55755
|
+
const rxs = r3.x * s3.y - r3.y * s3.x;
|
|
55756
|
+
if (Math.abs(rxs) < 1e-6)
|
|
55757
|
+
return null;
|
|
55758
|
+
const q_p = { x: q3.x - p3.x, y: q3.y - p3.y };
|
|
55759
|
+
const t3 = (q_p.x * s3.y - q_p.y * s3.x) / rxs;
|
|
55760
|
+
const u3 = (q_p.x * r3.y - q_p.y * r3.x) / rxs;
|
|
55761
|
+
const x3 = p3.x + t3 * r3.x;
|
|
55762
|
+
const y2 = p3.y + t3 * r3.y;
|
|
55763
|
+
return { x: x3, y: y2, t: t3, u: u3 };
|
|
55764
|
+
}
|
|
55765
|
+
pointAtRatio(points, ratio) {
|
|
55766
|
+
const clampRatio = Math.max(0, Math.min(1, ratio));
|
|
55767
|
+
let total = 0;
|
|
55768
|
+
const segs = [];
|
|
55769
|
+
for (let i3 = 0; i3 < points.length - 1; i3++) {
|
|
55770
|
+
const dx = points[i3 + 1].x - points[i3].x;
|
|
55771
|
+
const dy = points[i3 + 1].y - points[i3].y;
|
|
55772
|
+
const len = Math.hypot(dx, dy);
|
|
55773
|
+
segs.push(len);
|
|
55774
|
+
total += len;
|
|
55775
|
+
}
|
|
55776
|
+
if (total === 0)
|
|
55777
|
+
return points[Math.floor(points.length / 2)];
|
|
55778
|
+
let target = total * clampRatio;
|
|
55779
|
+
for (let i3 = 0; i3 < segs.length; i3++) {
|
|
55780
|
+
if (target <= segs[i3]) {
|
|
55781
|
+
const t3 = segs[i3] === 0 ? 0 : target / segs[i3];
|
|
55782
|
+
return {
|
|
55783
|
+
x: points[i3].x + (points[i3 + 1].x - points[i3].x) * t3,
|
|
55784
|
+
y: points[i3].y + (points[i3 + 1].y - points[i3].y) * t3
|
|
55785
|
+
};
|
|
55786
|
+
}
|
|
55787
|
+
target -= segs[i3];
|
|
55788
|
+
}
|
|
55789
|
+
return points[points.length - 1];
|
|
55790
|
+
}
|
|
55791
|
+
escapeXml(text) {
|
|
55792
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
55793
|
+
}
|
|
55794
|
+
};
|
|
55795
|
+
}
|
|
55796
|
+
});
|
|
55797
|
+
|
|
55798
|
+
// node_modules/@probelabs/maid/out/renderer/pie-builder.js
|
|
55799
|
+
function unquote(s3) {
|
|
55800
|
+
if (!s3)
|
|
55801
|
+
return s3;
|
|
55802
|
+
const first2 = s3.charAt(0);
|
|
55803
|
+
const last2 = s3.charAt(s3.length - 1);
|
|
55804
|
+
if (first2 === '"' && last2 === '"' || first2 === "'" && last2 === "'") {
|
|
55805
|
+
const inner = s3.slice(1, -1);
|
|
55806
|
+
return inner.replace(/\\(["'])/g, "$1");
|
|
55807
|
+
}
|
|
55808
|
+
return s3;
|
|
55809
|
+
}
|
|
55810
|
+
function buildPieModel(text) {
|
|
55811
|
+
const errors = [];
|
|
55812
|
+
const lex = tokenize2(text);
|
|
55813
|
+
for (const e3 of lex.errors) {
|
|
55814
|
+
errors.push({
|
|
55815
|
+
line: e3.line ?? 1,
|
|
55816
|
+
column: e3.column ?? 1,
|
|
55817
|
+
message: e3.message,
|
|
55818
|
+
code: "PIE_LEX",
|
|
55819
|
+
severity: "error"
|
|
55820
|
+
});
|
|
55821
|
+
}
|
|
55822
|
+
parserInstance2.reset();
|
|
55823
|
+
parserInstance2.input = lex.tokens;
|
|
55824
|
+
const cst = parserInstance2.diagram();
|
|
55825
|
+
for (const e3 of parserInstance2.errors) {
|
|
55826
|
+
const t3 = e3.token;
|
|
55827
|
+
errors.push({
|
|
55828
|
+
line: t3?.startLine ?? 1,
|
|
55829
|
+
column: t3?.startColumn ?? 1,
|
|
55830
|
+
message: e3.message,
|
|
55831
|
+
code: "PIE_PARSE",
|
|
55832
|
+
severity: "error"
|
|
55833
|
+
});
|
|
55834
|
+
}
|
|
55835
|
+
const model = { title: void 0, showData: false, slices: [] };
|
|
55836
|
+
if (!cst || !cst.children)
|
|
55837
|
+
return { model, errors };
|
|
55838
|
+
if (cst.children.ShowDataKeyword && cst.children.ShowDataKeyword.length > 0) {
|
|
55839
|
+
model.showData = true;
|
|
55840
|
+
}
|
|
55841
|
+
const statements = cst.children.statement ?? [];
|
|
55842
|
+
for (const st of statements) {
|
|
55843
|
+
if (st.children?.titleStmt) {
|
|
55844
|
+
const tnode = st.children.titleStmt[0];
|
|
55845
|
+
const parts = [];
|
|
55846
|
+
const collect = (k3) => {
|
|
55847
|
+
const arr = tnode.children?.[k3] ?? [];
|
|
55848
|
+
for (const tok of arr)
|
|
55849
|
+
parts.push(unquote(tok.image));
|
|
55850
|
+
};
|
|
55851
|
+
collect("QuotedString");
|
|
55852
|
+
collect("Text");
|
|
55853
|
+
collect("NumberLiteral");
|
|
55854
|
+
const title = parts.join(" ").trim();
|
|
55855
|
+
if (title)
|
|
55856
|
+
model.title = title;
|
|
55857
|
+
} else if (st.children?.sliceStmt) {
|
|
55858
|
+
const snode = st.children.sliceStmt[0];
|
|
55859
|
+
const labelTok = snode.children?.sliceLabel?.[0]?.children?.QuotedString?.[0];
|
|
55860
|
+
const numTok = snode.children?.NumberLiteral?.[0];
|
|
55861
|
+
if (labelTok && numTok) {
|
|
55862
|
+
const label = unquote(labelTok.image).trim();
|
|
55863
|
+
const value = Number(numTok.image);
|
|
55864
|
+
if (!Number.isNaN(value)) {
|
|
55865
|
+
model.slices.push({ label, value });
|
|
55866
|
+
}
|
|
55867
|
+
}
|
|
55868
|
+
}
|
|
55869
|
+
}
|
|
55870
|
+
return { model, errors };
|
|
55871
|
+
}
|
|
55872
|
+
var init_pie_builder = __esm({
|
|
55873
|
+
"node_modules/@probelabs/maid/out/renderer/pie-builder.js"() {
|
|
55874
|
+
init_lexer3();
|
|
55875
|
+
init_parser3();
|
|
55876
|
+
}
|
|
55877
|
+
});
|
|
55878
|
+
|
|
55879
|
+
// node_modules/@probelabs/maid/out/renderer/pie-renderer.js
|
|
55880
|
+
function polarToCartesian(cx, cy, r3, angleRad) {
|
|
55881
|
+
return { x: cx + r3 * Math.cos(angleRad), y: cy + r3 * Math.sin(angleRad) };
|
|
55882
|
+
}
|
|
55883
|
+
function renderPie(model, opts = {}) {
|
|
55884
|
+
let width = Math.max(320, Math.floor(opts.width ?? 640));
|
|
55885
|
+
const height = Math.max(240, Math.floor(opts.height ?? 400));
|
|
55886
|
+
const pad = 24;
|
|
55887
|
+
const titleH = model.title ? 28 : 0;
|
|
55888
|
+
let cx = width / 2;
|
|
55889
|
+
const cy = (height + titleH) / 2 + (model.title ? 8 : 0);
|
|
55890
|
+
const baseRadius = Math.max(40, Math.min(width, height - titleH) / 2 - pad);
|
|
55891
|
+
const slices = model.slices.filter((s3) => Math.max(0, s3.value) > 0);
|
|
55892
|
+
const total = slices.reduce((a3, s3) => a3 + Math.max(0, s3.value), 0);
|
|
55893
|
+
const LEG_SW = 12;
|
|
55894
|
+
const LEG_GAP = 8;
|
|
55895
|
+
const LEG_VSPACE = 18;
|
|
55896
|
+
const legendItems = slices.map((s3) => `${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
|
|
55897
|
+
const legendTextWidth = legendItems.length ? Math.max(...legendItems.map((t3) => measureText(t3, 12))) : 0;
|
|
55898
|
+
const legendBlockWidth = legendItems.length ? LEG_SW + LEG_GAP + legendTextWidth + pad : 0;
|
|
55899
|
+
if (legendItems.length) {
|
|
55900
|
+
const neededWidth = pad + baseRadius * 2 + legendBlockWidth + pad;
|
|
55901
|
+
if (neededWidth > width)
|
|
55902
|
+
width = Math.ceil(neededWidth);
|
|
55903
|
+
}
|
|
55904
|
+
let radius = baseRadius;
|
|
55905
|
+
if (legendItems.length) {
|
|
55906
|
+
const leftPad = Math.max(pad, (width - legendBlockWidth - radius * 2) / 2);
|
|
55907
|
+
cx = leftPad + radius;
|
|
55908
|
+
}
|
|
55909
|
+
let start = -Math.PI / 2;
|
|
55910
|
+
let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`;
|
|
55911
|
+
svg += `
|
|
55912
|
+
<style>
|
|
55913
|
+
.pie-title { font-family: Arial, sans-serif; font-size: 16px; font-weight: 600; fill: #222; }
|
|
55914
|
+
.slice-label { font-family: Arial, sans-serif; font-size: 12px; fill: #222; dominant-baseline: middle; }
|
|
55915
|
+
.leader { stroke: #444; stroke-width: 1; fill: none; }
|
|
55916
|
+
.pieCircle { stroke: black; stroke-width: 2px; opacity: 0.7; }
|
|
55917
|
+
.pieOuterCircle { stroke: black; stroke-width: 2px; fill: none; }
|
|
55918
|
+
</style>`;
|
|
55919
|
+
if (model.title) {
|
|
55920
|
+
svg += `
|
|
55921
|
+
<text class="pie-title" x="${cx}" y="${pad + 8}" text-anchor="middle">${escapeXml(model.title)}</text>`;
|
|
55922
|
+
}
|
|
55923
|
+
svg += `
|
|
55924
|
+
<g class="pie" aria-label="pie">`;
|
|
55925
|
+
const minOutsideAngle = 0.35;
|
|
55926
|
+
slices.forEach((s3, i3) => {
|
|
55927
|
+
const pct = total > 0 ? Math.max(0, s3.value) / total : 0;
|
|
55928
|
+
const angle = 2 * Math.PI * pct;
|
|
55929
|
+
const end = start + angle;
|
|
55930
|
+
const large = angle > Math.PI ? 1 : 0;
|
|
55931
|
+
const c0 = polarToCartesian(cx, cy, radius, start);
|
|
55932
|
+
const c1 = polarToCartesian(cx, cy, radius, end);
|
|
55933
|
+
const d3 = [
|
|
55934
|
+
`M ${cx} ${cy}`,
|
|
55935
|
+
`L ${c0.x.toFixed(2)} ${c0.y.toFixed(2)}`,
|
|
55936
|
+
`A ${radius} ${radius} 0 ${large} 1 ${c1.x.toFixed(2)} ${c1.y.toFixed(2)}`,
|
|
55937
|
+
"Z"
|
|
55938
|
+
].join(" ");
|
|
55939
|
+
const fill = s3.color || palette(i3);
|
|
55940
|
+
svg += `
|
|
55941
|
+
<path d="${d3}" class="pieCircle" fill="${fill}" />`;
|
|
55942
|
+
const mid = (start + end) / 2;
|
|
55943
|
+
const cos = Math.cos(mid);
|
|
55944
|
+
const sin = Math.sin(mid);
|
|
55945
|
+
const percentLabel = escapeXml(formatPercent(s3.value, total));
|
|
55946
|
+
if (angle < minOutsideAngle) {
|
|
55947
|
+
const r1 = radius * 0.9;
|
|
55948
|
+
const r22 = radius * 1.06;
|
|
55949
|
+
const p1 = polarToCartesian(cx, cy, r1, mid);
|
|
55950
|
+
const p22 = polarToCartesian(cx, cy, r22, mid);
|
|
55951
|
+
const hlen = 12;
|
|
55952
|
+
const anchorLeft = cos < 0;
|
|
55953
|
+
const hx = anchorLeft ? p22.x - hlen : p22.x + hlen;
|
|
55954
|
+
const hy = p22.y;
|
|
55955
|
+
svg += `
|
|
55956
|
+
<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)}" />`;
|
|
55957
|
+
const tx = anchorLeft ? hx - 2 : hx + 2;
|
|
55958
|
+
const tAnchor = anchorLeft ? "end" : "start";
|
|
55959
|
+
svg += `
|
|
55960
|
+
<text class="slice-label" x="${tx.toFixed(2)}" y="${hy.toFixed(2)}" text-anchor="${tAnchor}">${percentLabel}</text>`;
|
|
55961
|
+
} else {
|
|
55962
|
+
const lr = radius * 0.62;
|
|
55963
|
+
const lp = { x: cx + lr * cos, y: cy + lr * sin };
|
|
55964
|
+
const tAnchor = Math.abs(cos) < 0.2 ? "middle" : cos > 0 ? "start" : "end";
|
|
55965
|
+
const avail = lr;
|
|
55966
|
+
const textW = measureText(percentLabel, 12);
|
|
55967
|
+
const anchor = textW > avail * 1.2 ? "middle" : tAnchor;
|
|
55968
|
+
svg += `
|
|
55969
|
+
<text class="slice-label" x="${lp.x.toFixed(2)}" y="${lp.y.toFixed(2)}" text-anchor="${anchor}">${percentLabel}</text>`;
|
|
55970
|
+
}
|
|
55971
|
+
start = end;
|
|
55972
|
+
});
|
|
55973
|
+
const rimStroke = opts.rimStroke || "black";
|
|
55974
|
+
const rimWidth = opts.rimStrokeWidth != null ? String(opts.rimStrokeWidth) : "2px";
|
|
55975
|
+
svg += `
|
|
55976
|
+
</g>
|
|
55977
|
+
<circle class="pie-rim pieOuterCircle" cx="${cx}" cy="${cy}" r="${radius}" stroke="${rimStroke}" stroke-width="${rimWidth}" fill="none" />`;
|
|
55978
|
+
if (legendItems.length) {
|
|
55979
|
+
const legendX = cx + radius + pad / 2;
|
|
55980
|
+
const totalH = legendItems.length * LEG_VSPACE;
|
|
55981
|
+
let legendY = cy - totalH / 2 + 10;
|
|
55982
|
+
svg += `
|
|
55983
|
+
<g class="legend">`;
|
|
55984
|
+
slices.forEach((s3, i3) => {
|
|
55985
|
+
const y2 = legendY + i3 * LEG_VSPACE;
|
|
55986
|
+
const fill = s3.color || palette(i3);
|
|
55987
|
+
const text = escapeXml(`${s3.label}${model.showData ? ` ${formatNumber(Number(s3.value))}` : ""}`);
|
|
55988
|
+
svg += `
|
|
55989
|
+
<rect x="${legendX}" y="${y2 - LEG_SW + 6}" width="${LEG_SW}" height="${LEG_SW}" fill="${fill}" stroke="${fill}" stroke-width="1" />`;
|
|
55990
|
+
svg += `
|
|
55991
|
+
<text class="slice-label legend-text" x="${legendX + LEG_SW + LEG_GAP}" y="${y2}" text-anchor="start">${text}</text>`;
|
|
55992
|
+
});
|
|
55993
|
+
svg += `
|
|
55994
|
+
</g>`;
|
|
55995
|
+
}
|
|
55996
|
+
svg += `
|
|
55997
|
+
</svg>`;
|
|
55998
|
+
return svg;
|
|
55999
|
+
}
|
|
56000
|
+
var init_pie_renderer = __esm({
|
|
56001
|
+
"node_modules/@probelabs/maid/out/renderer/pie-renderer.js"() {
|
|
56002
|
+
init_utils4();
|
|
56003
|
+
}
|
|
56004
|
+
});
|
|
56005
|
+
|
|
56006
|
+
// node_modules/@probelabs/maid/out/renderer/sequence-builder.js
|
|
56007
|
+
function textFromTokens(tokens) {
|
|
56008
|
+
if (!tokens || tokens.length === 0)
|
|
56009
|
+
return "";
|
|
56010
|
+
const parts = [];
|
|
56011
|
+
for (const t3 of tokens) {
|
|
56012
|
+
const img = t3.image;
|
|
56013
|
+
if (!img)
|
|
56014
|
+
continue;
|
|
56015
|
+
if (t3.tokenType && t3.tokenType.name === "QuotedString") {
|
|
56016
|
+
if (img.startsWith('"') && img.endsWith('"'))
|
|
56017
|
+
parts.push(img.slice(1, -1));
|
|
56018
|
+
else if (img.startsWith("'") && img.endsWith("'"))
|
|
56019
|
+
parts.push(img.slice(1, -1));
|
|
56020
|
+
else
|
|
56021
|
+
parts.push(img);
|
|
56022
|
+
} else {
|
|
56023
|
+
parts.push(img);
|
|
56024
|
+
}
|
|
56025
|
+
}
|
|
56026
|
+
return parts.join(" ").replace(/\s+/g, " ").trim();
|
|
56027
|
+
}
|
|
56028
|
+
function actorRefToText(refCst) {
|
|
56029
|
+
const ch = refCst.children || {};
|
|
56030
|
+
const toks = [];
|
|
56031
|
+
["Identifier", "QuotedString", "NumberLiteral", "Text"].forEach((k3) => {
|
|
56032
|
+
const a3 = ch[k3];
|
|
56033
|
+
a3?.forEach((t3) => toks.push(t3));
|
|
56034
|
+
});
|
|
56035
|
+
toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
|
|
56036
|
+
return textFromTokens(toks);
|
|
56037
|
+
}
|
|
56038
|
+
function lineRemainderToText(lineRem) {
|
|
56039
|
+
if (!lineRem)
|
|
56040
|
+
return void 0;
|
|
56041
|
+
const ch = lineRem.children || {};
|
|
56042
|
+
const toks = [];
|
|
56043
|
+
const order = [
|
|
56044
|
+
"Identifier",
|
|
56045
|
+
"NumberLiteral",
|
|
56046
|
+
"QuotedString",
|
|
56047
|
+
"Text",
|
|
56048
|
+
"Plus",
|
|
56049
|
+
"Minus",
|
|
56050
|
+
"Comma",
|
|
56051
|
+
"Colon",
|
|
56052
|
+
"LParen",
|
|
56053
|
+
"RParen",
|
|
56054
|
+
"AndKeyword",
|
|
56055
|
+
"ElseKeyword",
|
|
56056
|
+
"OptKeyword",
|
|
56057
|
+
"OptionKeyword",
|
|
56058
|
+
"LoopKeyword",
|
|
56059
|
+
"ParKeyword",
|
|
56060
|
+
"RectKeyword",
|
|
56061
|
+
"CriticalKeyword",
|
|
56062
|
+
"BreakKeyword",
|
|
56063
|
+
"BoxKeyword",
|
|
56064
|
+
"EndKeyword",
|
|
56065
|
+
"NoteKeyword",
|
|
56066
|
+
"LeftKeyword",
|
|
56067
|
+
"RightKeyword",
|
|
56068
|
+
"OverKeyword",
|
|
56069
|
+
"OfKeyword",
|
|
56070
|
+
"AutonumberKeyword",
|
|
56071
|
+
"OffKeyword",
|
|
56072
|
+
"LinkKeyword",
|
|
56073
|
+
"LinksKeyword",
|
|
56074
|
+
"CreateKeyword",
|
|
56075
|
+
"DestroyKeyword",
|
|
56076
|
+
"ParticipantKeyword",
|
|
56077
|
+
"ActorKeyword",
|
|
56078
|
+
"ActivateKeyword",
|
|
56079
|
+
"DeactivateKeyword"
|
|
56080
|
+
];
|
|
56081
|
+
for (const k3 of order)
|
|
56082
|
+
ch[k3]?.forEach((t3) => toks.push(t3));
|
|
56083
|
+
toks.sort((a3, b3) => (a3.startOffset ?? 0) - (b3.startOffset ?? 0));
|
|
56084
|
+
return textFromTokens(toks) || void 0;
|
|
56085
|
+
}
|
|
56086
|
+
function canonicalId(raw) {
|
|
56087
|
+
const t3 = raw.trim().replace(/\s+/g, "_");
|
|
56088
|
+
return t3;
|
|
56089
|
+
}
|
|
56090
|
+
function ensureParticipant(map4, byDisplay, idLike, display) {
|
|
56091
|
+
const idGuess = canonicalId(idLike);
|
|
56092
|
+
const existing = map4.get(idGuess) || (byDisplay.get(idLike) ? map4.get(byDisplay.get(idLike)) : void 0);
|
|
56093
|
+
if (existing)
|
|
56094
|
+
return existing;
|
|
56095
|
+
const p3 = { id: idGuess, display: display || idLike };
|
|
56096
|
+
map4.set(p3.id, p3);
|
|
56097
|
+
byDisplay.set(p3.display, p3.id);
|
|
56098
|
+
return p3;
|
|
56099
|
+
}
|
|
56100
|
+
function msgFromArrow(arrowCst) {
|
|
56101
|
+
const ch = arrowCst.children || {};
|
|
56102
|
+
if (ch.BidirAsyncDotted)
|
|
56103
|
+
return { line: "dotted", start: "arrow", end: "arrow", async: true };
|
|
56104
|
+
if (ch.BidirAsync)
|
|
56105
|
+
return { line: "solid", start: "arrow", end: "arrow", async: true };
|
|
56106
|
+
if (ch.DottedAsync)
|
|
56107
|
+
return { line: "dotted", start: "none", end: "arrow", async: true };
|
|
56108
|
+
if (ch.Async)
|
|
56109
|
+
return { line: "solid", start: "none", end: "arrow", async: true };
|
|
56110
|
+
if (ch.Dotted)
|
|
56111
|
+
return { line: "dotted", start: "none", end: "arrow" };
|
|
56112
|
+
if (ch.Solid)
|
|
56113
|
+
return { line: "solid", start: "none", end: "arrow" };
|
|
56114
|
+
if (ch.DottedCross)
|
|
56115
|
+
return { line: "dotted", start: "none", end: "cross" };
|
|
56116
|
+
if (ch.Cross)
|
|
56117
|
+
return { line: "solid", start: "none", end: "cross" };
|
|
56118
|
+
if (ch.DottedOpen)
|
|
56119
|
+
return { line: "dotted", start: "none", end: "open" };
|
|
56120
|
+
if (ch.Open)
|
|
56121
|
+
return { line: "solid", start: "none", end: "open" };
|
|
56122
|
+
return { line: "solid", start: "none", end: "arrow" };
|
|
56123
|
+
}
|
|
56124
|
+
function buildSequenceModel(text) {
|
|
56125
|
+
const { tokens } = tokenize3(text);
|
|
56126
|
+
parserInstance3.input = tokens;
|
|
56127
|
+
const cst = parserInstance3.diagram();
|
|
56128
|
+
const participantsMap = /* @__PURE__ */ new Map();
|
|
56129
|
+
const byDisplay = /* @__PURE__ */ new Map();
|
|
56130
|
+
const events = [];
|
|
56131
|
+
let autonumber = { on: false };
|
|
56132
|
+
const diagramChildren = cst.children || {};
|
|
56133
|
+
const lines = diagramChildren.line || [];
|
|
56134
|
+
const openBlocks = [];
|
|
56135
|
+
function processLineNode(ln) {
|
|
56136
|
+
const ch = ln.children || {};
|
|
56137
|
+
if (ch.participantDecl) {
|
|
56138
|
+
const decl = ch.participantDecl[0];
|
|
56139
|
+
const dch = decl.children || {};
|
|
56140
|
+
const ref1 = dch.actorRef?.[0];
|
|
56141
|
+
const ref2 = dch.actorRef?.[1];
|
|
56142
|
+
const idText = actorRefToText(ref1);
|
|
56143
|
+
const aliasText = ref2 ? actorRefToText(ref2) : void 0;
|
|
56144
|
+
const id = canonicalId(idText);
|
|
56145
|
+
const display = aliasText || idText;
|
|
56146
|
+
const p3 = ensureParticipant(participantsMap, byDisplay, id, display);
|
|
56147
|
+
events.push({ kind: "create", actor: p3.id, display: p3.display });
|
|
56148
|
+
return;
|
|
56149
|
+
}
|
|
56150
|
+
if (ch.autonumberStmt) {
|
|
56151
|
+
const stmt = ch.autonumberStmt[0];
|
|
56152
|
+
const sch = stmt.children || {};
|
|
56153
|
+
autonumber = { on: true };
|
|
56154
|
+
const nums = sch.NumberLiteral || [];
|
|
56155
|
+
if (nums.length >= 1)
|
|
56156
|
+
autonumber.start = Number(nums[0].image);
|
|
56157
|
+
if (nums.length >= 2)
|
|
56158
|
+
autonumber.step = Number(nums[1].image);
|
|
56159
|
+
if (sch.OffKeyword)
|
|
56160
|
+
autonumber = { on: false };
|
|
56161
|
+
return;
|
|
56162
|
+
}
|
|
56163
|
+
if (ch.activateStmt) {
|
|
56164
|
+
const st = ch.activateStmt[0];
|
|
56165
|
+
const sch = st.children || {};
|
|
56166
|
+
const idTxt = actorRefToText(sch.actorRef?.[0]);
|
|
56167
|
+
const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
|
|
56168
|
+
events.push({ kind: "activate", actor: p3.id });
|
|
56169
|
+
return;
|
|
56170
|
+
}
|
|
56171
|
+
if (ch.deactivateStmt) {
|
|
56172
|
+
const st = ch.deactivateStmt[0];
|
|
56173
|
+
const sch = st.children || {};
|
|
56174
|
+
const idTxt = actorRefToText(sch.actorRef?.[0]);
|
|
56175
|
+
const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
|
|
56176
|
+
events.push({ kind: "deactivate", actor: p3.id });
|
|
56177
|
+
return;
|
|
56178
|
+
}
|
|
56179
|
+
if (ch.createStmt) {
|
|
56180
|
+
const st = ch.createStmt[0];
|
|
56181
|
+
const sch = st.children || {};
|
|
56182
|
+
const idTxt = actorRefToText(sch.actorRef?.[0]);
|
|
56183
|
+
const alias = sch.lineRemainder ? lineRemainderToText(sch.lineRemainder[0]) : void 0;
|
|
56184
|
+
const p3 = ensureParticipant(participantsMap, byDisplay, idTxt, alias || idTxt);
|
|
56185
|
+
events.push({ kind: "create", actor: p3.id, display: p3.display });
|
|
56186
|
+
return;
|
|
56187
|
+
}
|
|
56188
|
+
if (ch.destroyStmt) {
|
|
56189
|
+
const st = ch.destroyStmt[0];
|
|
56190
|
+
const sch = st.children || {};
|
|
56191
|
+
const idTxt = actorRefToText(sch.actorRef?.[0]);
|
|
56192
|
+
const p3 = ensureParticipant(participantsMap, byDisplay, idTxt);
|
|
56193
|
+
events.push({ kind: "destroy", actor: p3.id });
|
|
56194
|
+
return;
|
|
56195
|
+
}
|
|
56196
|
+
if (ch.noteStmt) {
|
|
56197
|
+
const st = ch.noteStmt[0];
|
|
56198
|
+
const sch = st.children || {};
|
|
56199
|
+
const text2 = lineRemainderToText(sch.lineRemainder?.[0]) || "";
|
|
56200
|
+
if (sch.LeftKeyword || sch.RightKeyword) {
|
|
56201
|
+
const pos = sch.LeftKeyword ? "leftOf" : "rightOf";
|
|
56202
|
+
const actorTxt = actorRefToText(sch.actorRef?.[0]);
|
|
56203
|
+
const p3 = ensureParticipant(participantsMap, byDisplay, actorTxt);
|
|
56204
|
+
const note = { pos, actors: [p3.id], text: text2 };
|
|
56205
|
+
events.push({ kind: "note", note });
|
|
56206
|
+
} else if (sch.OverKeyword) {
|
|
56207
|
+
const a1 = actorRefToText(sch.actorRef?.[0]);
|
|
56208
|
+
const a22 = sch.actorRef?.[1] ? actorRefToText(sch.actorRef?.[1]) : void 0;
|
|
56209
|
+
const p1 = ensureParticipant(participantsMap, byDisplay, a1);
|
|
56210
|
+
const ids = [p1.id];
|
|
56211
|
+
if (a22) {
|
|
56212
|
+
const p22 = ensureParticipant(participantsMap, byDisplay, a22);
|
|
56213
|
+
ids.push(p22.id);
|
|
56214
|
+
}
|
|
56215
|
+
events.push({ kind: "note", note: { pos: "over", actors: ids, text: text2 } });
|
|
56216
|
+
}
|
|
56217
|
+
return;
|
|
56218
|
+
}
|
|
56219
|
+
const blockKinds = [
|
|
56220
|
+
{ key: "altBlock", type: "alt", branchKeys: [{ key: "ElseKeyword", kind: "else" }] },
|
|
56221
|
+
{ key: "optBlock", type: "opt" },
|
|
56222
|
+
{ key: "loopBlock", type: "loop" },
|
|
56223
|
+
{ key: "parBlock", type: "par", branchKeys: [{ key: "AndKeyword", kind: "and" }] },
|
|
56224
|
+
{ key: "criticalBlock", type: "critical", branchKeys: [{ key: "OptionKeyword", kind: "option" }] },
|
|
56225
|
+
{ key: "breakBlock", type: "break" },
|
|
56226
|
+
{ key: "rectBlock", type: "rect" },
|
|
56227
|
+
{ key: "boxBlock", type: "box" }
|
|
56228
|
+
];
|
|
56229
|
+
let handledBlock = false;
|
|
56230
|
+
for (const spec of blockKinds) {
|
|
56231
|
+
if (ch[spec.key]) {
|
|
56232
|
+
handledBlock = true;
|
|
56233
|
+
const bnode = ch[spec.key][0];
|
|
56234
|
+
const bch = bnode.children || {};
|
|
56235
|
+
const title = lineRemainderToText(bch.lineRemainder?.[0]);
|
|
56236
|
+
const block = { type: spec.type, title, branches: spec.branchKeys ? [] : void 0 };
|
|
56237
|
+
openBlocks.push(block);
|
|
56238
|
+
events.push({ kind: "block-start", block });
|
|
56239
|
+
if (spec.branchKeys) {
|
|
56240
|
+
const newlines = bch.Newline || [];
|
|
56241
|
+
const branchKey = spec.branchKeys[0].key;
|
|
56242
|
+
const branchTokArr = bch[branchKey];
|
|
56243
|
+
const lrArr = bch.lineRemainder;
|
|
56244
|
+
if (branchTokArr && branchTokArr.length) {
|
|
56245
|
+
const lr = (lrArr || []).slice(1);
|
|
56246
|
+
for (let i3 = 0; i3 < branchTokArr.length; i3++) {
|
|
56247
|
+
const title2 = lr[i3] ? lineRemainderToText(lr[i3]) : void 0;
|
|
56248
|
+
const br = { kind: spec.branchKeys[0].kind, title: title2 };
|
|
56249
|
+
block.branches.push(br);
|
|
56250
|
+
events.push({ kind: "block-branch", block, branch: br });
|
|
56251
|
+
}
|
|
56252
|
+
}
|
|
56253
|
+
}
|
|
56254
|
+
events.push({ kind: "block-end", block });
|
|
56255
|
+
openBlocks.pop();
|
|
56256
|
+
break;
|
|
56257
|
+
}
|
|
56258
|
+
}
|
|
56259
|
+
if (handledBlock)
|
|
56260
|
+
return;
|
|
56261
|
+
if (ch.messageStmt) {
|
|
56262
|
+
const st = ch.messageStmt[0];
|
|
56263
|
+
const sch = st.children || {};
|
|
56264
|
+
const fromTxt = actorRefToText(sch.actorRef?.[0]);
|
|
56265
|
+
const toTxt = actorRefToText(sch.actorRef?.[1]);
|
|
56266
|
+
const from = ensureParticipant(participantsMap, byDisplay, fromTxt).id;
|
|
56267
|
+
const to = ensureParticipant(participantsMap, byDisplay, toTxt).id;
|
|
56268
|
+
const arrow = msgFromArrow(sch.arrow?.[0]);
|
|
56269
|
+
const text2 = lineRemainderToText(sch.lineRemainder?.[0]);
|
|
56270
|
+
const activateTarget = !!sch.Plus;
|
|
56271
|
+
const deactivateTarget = !!sch.Minus;
|
|
56272
|
+
const msg = { from, to, text: text2, line: arrow.line, startMarker: arrow.start, endMarker: arrow.end, async: arrow.async, activateTarget, deactivateTarget };
|
|
56273
|
+
events.push({ kind: "message", msg });
|
|
56274
|
+
return;
|
|
56275
|
+
}
|
|
56276
|
+
if (ch.linkStmt) {
|
|
56277
|
+
events.push({ kind: "noop" });
|
|
56278
|
+
return;
|
|
56279
|
+
}
|
|
56280
|
+
events.push({ kind: "noop" });
|
|
56281
|
+
}
|
|
56282
|
+
function collectInnerLines(blockNode) {
|
|
56283
|
+
const out = [];
|
|
56284
|
+
const ch = blockNode.children || {};
|
|
56285
|
+
for (const key of Object.keys(ch)) {
|
|
56286
|
+
const arr = ch[key];
|
|
56287
|
+
if (Array.isArray(arr)) {
|
|
56288
|
+
for (const node of arr) {
|
|
56289
|
+
if (node && typeof node === "object" && node.name === "line")
|
|
56290
|
+
out.push(node);
|
|
56291
|
+
}
|
|
56292
|
+
}
|
|
56293
|
+
}
|
|
56294
|
+
return out;
|
|
56295
|
+
}
|
|
56296
|
+
for (const ln of lines) {
|
|
56297
|
+
processLineNode(ln);
|
|
56298
|
+
const ch = ln.children || {};
|
|
56299
|
+
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];
|
|
56300
|
+
if (block) {
|
|
56301
|
+
for (const inner of collectInnerLines(block))
|
|
56302
|
+
processLineNode(inner);
|
|
56303
|
+
}
|
|
56304
|
+
}
|
|
56305
|
+
return {
|
|
56306
|
+
participants: Array.from(participantsMap.values()),
|
|
56307
|
+
events,
|
|
56308
|
+
autonumber: autonumber.on === true || autonumber.on === false ? autonumber : { on: false }
|
|
56309
|
+
};
|
|
56310
|
+
}
|
|
56311
|
+
var init_sequence_builder = __esm({
|
|
56312
|
+
"node_modules/@probelabs/maid/out/renderer/sequence-builder.js"() {
|
|
56313
|
+
init_lexer4();
|
|
56314
|
+
init_parser4();
|
|
56315
|
+
}
|
|
56316
|
+
});
|
|
56317
|
+
|
|
56318
|
+
// node_modules/@probelabs/maid/out/renderer/sequence-layout.js
|
|
56319
|
+
function layoutSequence(model) {
|
|
56320
|
+
const order = [];
|
|
56321
|
+
const seen = /* @__PURE__ */ new Set();
|
|
56322
|
+
const partById = new Map(model.participants.map((p3) => [p3.id, p3]));
|
|
56323
|
+
function touch(id) {
|
|
56324
|
+
if (!seen.has(id)) {
|
|
56325
|
+
seen.add(id);
|
|
56326
|
+
order.push(id);
|
|
56327
|
+
}
|
|
56328
|
+
}
|
|
56329
|
+
for (const ev of model.events) {
|
|
56330
|
+
if (ev.kind === "message") {
|
|
56331
|
+
touch(ev.msg.from);
|
|
56332
|
+
touch(ev.msg.to);
|
|
56333
|
+
}
|
|
56334
|
+
if (ev.kind === "note") {
|
|
56335
|
+
ev.note.actors.forEach(touch);
|
|
56336
|
+
}
|
|
56337
|
+
if (ev.kind === "activate" || ev.kind === "deactivate" || ev.kind === "create" || ev.kind === "destroy")
|
|
56338
|
+
touch(ev.actor);
|
|
56339
|
+
}
|
|
56340
|
+
for (const p3 of model.participants)
|
|
56341
|
+
touch(p3.id);
|
|
56342
|
+
const participants = [];
|
|
56343
|
+
let x3 = MARGIN_X;
|
|
56344
|
+
for (const id of order) {
|
|
56345
|
+
const p3 = partById.get(id) || { id, display: id };
|
|
56346
|
+
const w3 = Math.max(COL_MIN, measureText(p3.display, ACTOR_FONT_SIZE) + ACTOR_PAD_X * 2);
|
|
56347
|
+
participants.push({ id, display: p3.display, x: x3, y: MARGIN_Y, width: w3, height: ACTOR_H });
|
|
56348
|
+
x3 += w3 + MARGIN_X;
|
|
56349
|
+
}
|
|
56350
|
+
const width = Math.max(320, x3);
|
|
56351
|
+
const rowIndexForEvent = /* @__PURE__ */ new Map();
|
|
56352
|
+
let row = 0;
|
|
56353
|
+
const openBlocks = [];
|
|
56354
|
+
function consumeRow(idx) {
|
|
56355
|
+
rowIndexForEvent.set(idx, row++);
|
|
56356
|
+
}
|
|
56357
|
+
model.events.forEach((ev, idx) => {
|
|
56358
|
+
switch (ev.kind) {
|
|
56359
|
+
case "message":
|
|
56360
|
+
consumeRow(idx);
|
|
56361
|
+
break;
|
|
56362
|
+
case "note":
|
|
56363
|
+
consumeRow(idx);
|
|
56364
|
+
break;
|
|
56365
|
+
case "block-start":
|
|
56366
|
+
openBlocks.push({ block: ev.block, startRow: row, branches: [] });
|
|
56367
|
+
consumeRow(idx);
|
|
56368
|
+
break;
|
|
56369
|
+
case "block-branch": {
|
|
56370
|
+
const top = openBlocks[openBlocks.length - 1];
|
|
56371
|
+
if (top)
|
|
56372
|
+
top.branches.push({ title: ev.branch.title, row });
|
|
56373
|
+
consumeRow(idx);
|
|
56374
|
+
break;
|
|
56375
|
+
}
|
|
56376
|
+
case "block-end":
|
|
56377
|
+
break;
|
|
56378
|
+
case "activate":
|
|
56379
|
+
case "deactivate":
|
|
56380
|
+
case "create":
|
|
56381
|
+
case "destroy":
|
|
56382
|
+
case "noop":
|
|
56383
|
+
break;
|
|
56384
|
+
}
|
|
56385
|
+
});
|
|
56386
|
+
const lifelineTop = MARGIN_Y + ACTOR_H + LIFELINE_GAP;
|
|
56387
|
+
const contentHeight = row * ROW_H;
|
|
56388
|
+
const height = lifelineTop + contentHeight + MARGIN_Y + ACTOR_H;
|
|
56389
|
+
const lifelines = participants.map((p3) => ({ x: p3.x + p3.width / 2, y1: lifelineTop, y2: height - MARGIN_Y - ACTOR_H }));
|
|
56390
|
+
function yForRow(r3) {
|
|
56391
|
+
return lifelineTop + r3 * ROW_H + ROW_H / 2;
|
|
56392
|
+
}
|
|
56393
|
+
const col = new Map(participants.map((p3) => [p3.id, p3]));
|
|
56394
|
+
const messages = [];
|
|
56395
|
+
const notes = [];
|
|
56396
|
+
const blocks = [];
|
|
56397
|
+
const activations = [];
|
|
56398
|
+
const actStack = /* @__PURE__ */ new Map();
|
|
56399
|
+
const startAct = (actor, r3) => {
|
|
56400
|
+
const arr = actStack.get(actor) || [];
|
|
56401
|
+
arr.push(r3);
|
|
56402
|
+
actStack.set(actor, arr);
|
|
56403
|
+
};
|
|
56404
|
+
const endAct = (actor, r3) => {
|
|
56405
|
+
const arr = actStack.get(actor) || [];
|
|
56406
|
+
const start = arr.pop();
|
|
56407
|
+
if (start != null) {
|
|
56408
|
+
const p3 = col.get(actor);
|
|
56409
|
+
if (p3) {
|
|
56410
|
+
activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(r3) - yForRow(start) });
|
|
56411
|
+
}
|
|
53587
56412
|
}
|
|
53588
|
-
|
|
53589
|
-
|
|
53590
|
-
|
|
53591
|
-
|
|
53592
|
-
|
|
53593
|
-
|
|
56413
|
+
actStack.set(actor, arr);
|
|
56414
|
+
};
|
|
56415
|
+
const openForLayout = [];
|
|
56416
|
+
model.events.forEach((ev, idx) => {
|
|
56417
|
+
const r3 = rowIndexForEvent.has(idx) ? rowIndexForEvent.get(idx) : null;
|
|
56418
|
+
switch (ev.kind) {
|
|
56419
|
+
case "message": {
|
|
56420
|
+
const p1 = col.get(ev.msg.from), p22 = col.get(ev.msg.to);
|
|
56421
|
+
if (p1 && p22 && r3 != null) {
|
|
56422
|
+
const y2 = yForRow(r3);
|
|
56423
|
+
const x1 = p1.x + p1.width / 2;
|
|
56424
|
+
const x22 = p22.x + p22.width / 2;
|
|
56425
|
+
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 });
|
|
56426
|
+
if (ev.msg.activateTarget)
|
|
56427
|
+
startAct(ev.msg.to, r3);
|
|
56428
|
+
if (ev.msg.deactivateTarget)
|
|
56429
|
+
endAct(ev.msg.to, r3);
|
|
56430
|
+
const top = openForLayout[openForLayout.length - 1];
|
|
56431
|
+
if (top)
|
|
56432
|
+
top.lastRow = r3;
|
|
56433
|
+
}
|
|
56434
|
+
break;
|
|
56435
|
+
}
|
|
56436
|
+
case "note": {
|
|
56437
|
+
if (r3 == null)
|
|
56438
|
+
break;
|
|
56439
|
+
const estLines = (text, width2) => {
|
|
56440
|
+
const charsPerLine = Math.max(8, Math.floor((width2 - NOTE_PAD * 2) / 7));
|
|
56441
|
+
const length = text ? text.length : 0;
|
|
56442
|
+
return Math.max(1, Math.ceil(length / charsPerLine));
|
|
56443
|
+
};
|
|
56444
|
+
const y2 = yForRow(r3) - NOTE_PAD;
|
|
56445
|
+
if (ev.note.pos === "over") {
|
|
56446
|
+
const [a3, b3] = ev.note.actors;
|
|
56447
|
+
const p1 = col.get(a3), p22 = b3 ? col.get(b3) : p1;
|
|
56448
|
+
if (p1 && p22) {
|
|
56449
|
+
const left = Math.min(p1.x + p1.width / 2, p22.x + p22.width / 2);
|
|
56450
|
+
const right = Math.max(p1.x + p1.width / 2, p22.x + p22.width / 2);
|
|
56451
|
+
const w3 = right - left + NOTE_PAD * 2;
|
|
56452
|
+
const lines = estLines(ev.note.text, w3);
|
|
56453
|
+
const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
|
|
56454
|
+
notes.push({ x: left - NOTE_PAD, y: y2, width: w3, height: h3, text: ev.note.text, anchor: "over" });
|
|
56455
|
+
}
|
|
56456
|
+
} else {
|
|
56457
|
+
const actor = ev.note.actors[0];
|
|
56458
|
+
const p3 = col.get(actor);
|
|
56459
|
+
if (p3) {
|
|
56460
|
+
const leftSide = ev.note.pos === "leftOf";
|
|
56461
|
+
const x4 = leftSide ? p3.x - NOTE_W - 10 : p3.x + p3.width + 10;
|
|
56462
|
+
const lines = estLines(ev.note.text, NOTE_W);
|
|
56463
|
+
const h3 = Math.max(ROW_H - NOTE_PAD, lines * 16 + NOTE_PAD);
|
|
56464
|
+
notes.push({ x: x4, y: y2, width: NOTE_W, height: h3, text: ev.note.text, anchor: leftSide ? "left" : "right" });
|
|
56465
|
+
}
|
|
56466
|
+
}
|
|
56467
|
+
const top = openForLayout[openForLayout.length - 1];
|
|
56468
|
+
if (top && r3 != null)
|
|
56469
|
+
top.lastRow = r3;
|
|
56470
|
+
break;
|
|
56471
|
+
}
|
|
56472
|
+
case "activate":
|
|
56473
|
+
if (r3 != null)
|
|
56474
|
+
startAct(ev.actor, r3);
|
|
56475
|
+
break;
|
|
56476
|
+
case "deactivate":
|
|
56477
|
+
if (r3 != null)
|
|
56478
|
+
endAct(ev.actor, r3);
|
|
56479
|
+
break;
|
|
56480
|
+
case "block-start": {
|
|
56481
|
+
const startRow = r3 != null ? r3 : row;
|
|
56482
|
+
openForLayout.push({ block: ev.block, startRow, branches: [] });
|
|
56483
|
+
break;
|
|
56484
|
+
}
|
|
56485
|
+
case "block-branch": {
|
|
56486
|
+
const top = openForLayout[openForLayout.length - 1];
|
|
56487
|
+
if (top && r3 != null) {
|
|
56488
|
+
top.branches.push({ title: ev.branch.title, row: r3 });
|
|
56489
|
+
top.lastRow = r3;
|
|
56490
|
+
}
|
|
56491
|
+
break;
|
|
56492
|
+
}
|
|
56493
|
+
case "block-end": {
|
|
56494
|
+
const top = openForLayout.pop();
|
|
56495
|
+
if (top) {
|
|
56496
|
+
const first2 = participants.length > 0 ? participants[0] : void 0;
|
|
56497
|
+
const last2 = participants.length > 0 ? participants[participants.length - 1] : void 0;
|
|
56498
|
+
const left = first2 ? first2.x : MARGIN_X;
|
|
56499
|
+
const right = last2 ? last2.x + last2.width : left + 200;
|
|
56500
|
+
const yTop = yForRow(top.startRow) - ROW_H / 2 - (BLOCK_PAD + TITLE_EXTRA_TOP);
|
|
56501
|
+
const endRow = top.lastRow != null ? top.lastRow : top.startRow;
|
|
56502
|
+
const yBot = yForRow(endRow) + ROW_H / 2 + BLOCK_PAD;
|
|
56503
|
+
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 };
|
|
56504
|
+
if (top.branches.length)
|
|
56505
|
+
layout.branches = top.branches.map((b3) => ({ title: b3.title, y: yForRow(b3.row) - ROW_H / 2 }));
|
|
56506
|
+
blocks.push(layout);
|
|
56507
|
+
}
|
|
56508
|
+
break;
|
|
56509
|
+
}
|
|
56510
|
+
default:
|
|
56511
|
+
break;
|
|
53594
56512
|
}
|
|
56513
|
+
});
|
|
56514
|
+
const lastRow = row;
|
|
56515
|
+
for (const [actor, arr] of actStack.entries()) {
|
|
56516
|
+
while (arr.length) {
|
|
56517
|
+
const start = arr.pop();
|
|
56518
|
+
const p3 = col.get(actor);
|
|
56519
|
+
if (p3)
|
|
56520
|
+
activations.push({ actor, x: p3.x + p3.width / 2 - 4, y: yForRow(start) - ROW_H / 2, width: 8, height: yForRow(lastRow) - yForRow(start) });
|
|
56521
|
+
}
|
|
56522
|
+
}
|
|
56523
|
+
return { width, height, participants, lifelines, messages, notes, blocks, activations };
|
|
56524
|
+
}
|
|
56525
|
+
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;
|
|
56526
|
+
var init_sequence_layout = __esm({
|
|
56527
|
+
"node_modules/@probelabs/maid/out/renderer/sequence-layout.js"() {
|
|
56528
|
+
init_utils4();
|
|
56529
|
+
MARGIN_X = 24;
|
|
56530
|
+
MARGIN_Y = 24;
|
|
56531
|
+
ACTOR_FONT_SIZE = 16;
|
|
56532
|
+
ACTOR_H = 32;
|
|
56533
|
+
LIFELINE_GAP = 4;
|
|
56534
|
+
ACTOR_PAD_X = 12;
|
|
56535
|
+
COL_MIN = 110;
|
|
56536
|
+
ROW_H = 36;
|
|
56537
|
+
NOTE_W = 160;
|
|
56538
|
+
NOTE_PAD = 8;
|
|
56539
|
+
BLOCK_PAD = 8;
|
|
56540
|
+
TITLE_EXTRA_TOP = 12;
|
|
56541
|
+
}
|
|
56542
|
+
});
|
|
56543
|
+
|
|
56544
|
+
// node_modules/@probelabs/maid/out/renderer/sequence-renderer.js
|
|
56545
|
+
function renderSequence(model, opts = {}) {
|
|
56546
|
+
const layout = layoutSequence(model);
|
|
56547
|
+
const svgParts = [];
|
|
56548
|
+
const width = Math.ceil(layout.width);
|
|
56549
|
+
const height = Math.ceil(layout.height);
|
|
56550
|
+
svgParts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width + 50}" height="${height + 40}" viewBox="-50 -10 ${width + 50} ${height + 40}">`);
|
|
56551
|
+
const sharedCss = buildSharedCss({
|
|
56552
|
+
fontFamily: "Arial, sans-serif",
|
|
56553
|
+
fontSize: 14,
|
|
56554
|
+
nodeFill: "#eef0ff",
|
|
56555
|
+
nodeStroke: "#3f3f3f",
|
|
56556
|
+
edgeStroke: "#555555"
|
|
56557
|
+
});
|
|
56558
|
+
svgParts.push(` <style>${sharedCss}</style>`);
|
|
56559
|
+
for (const p3 of layout.participants)
|
|
56560
|
+
drawParticipant(svgParts, p3);
|
|
56561
|
+
for (const b3 of layout.blocks)
|
|
56562
|
+
svgParts.push(blockBackground(b3.x, b3.y, b3.width, b3.height, 0));
|
|
56563
|
+
for (const l3 of layout.lifelines)
|
|
56564
|
+
svgParts.push(` <line class="lifeline" x1="${l3.x}" y1="${l3.y1}" x2="${l3.x}" y2="${l3.y2}"/>`);
|
|
56565
|
+
for (const a3 of layout.activations)
|
|
56566
|
+
svgParts.push(` <rect class="activation" x="${a3.x}" y="${a3.y}" width="${a3.width}" height="${a3.height}" />`);
|
|
56567
|
+
let counter = model.autonumber?.on ? model.autonumber.start ?? 1 : void 0;
|
|
56568
|
+
const step = model.autonumber?.on ? model.autonumber.step ?? 1 : void 0;
|
|
56569
|
+
for (const m3 of layout.messages) {
|
|
56570
|
+
drawMessage(svgParts, m3);
|
|
56571
|
+
const label = formatMessageLabel(m3.text, counter);
|
|
56572
|
+
if (label)
|
|
56573
|
+
drawMessageLabel(svgParts, m3, label, counter);
|
|
56574
|
+
if (counter != null)
|
|
56575
|
+
counter += step;
|
|
56576
|
+
}
|
|
56577
|
+
for (const n3 of layout.notes)
|
|
56578
|
+
drawNote(svgParts, n3);
|
|
56579
|
+
for (const b3 of layout.blocks) {
|
|
56580
|
+
const title = b3.title ? `${b3.type}: ${b3.title}` : b3.type;
|
|
56581
|
+
const branches = (b3.branches || []).map((br) => ({ y: br.y, title: br.title }));
|
|
56582
|
+
svgParts.push(blockOverlay(b3.x, b3.y, b3.width, b3.height, title, branches, 0, "left", "left", 0));
|
|
56583
|
+
}
|
|
56584
|
+
for (const p3 of layout.participants)
|
|
56585
|
+
drawParticipantBottom(svgParts, p3, layout);
|
|
56586
|
+
svgParts.push("</svg>");
|
|
56587
|
+
let svg = svgParts.join("\n");
|
|
56588
|
+
if (opts.theme)
|
|
56589
|
+
svg = applySequenceTheme(svg, opts.theme);
|
|
56590
|
+
return svg;
|
|
56591
|
+
}
|
|
56592
|
+
function drawParticipant(out, p3) {
|
|
56593
|
+
out.push(` <g class="actor" transform="translate(${p3.x},${p3.y})">`);
|
|
56594
|
+
out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
|
|
56595
|
+
out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
|
|
56596
|
+
out.push(" </g>");
|
|
56597
|
+
}
|
|
56598
|
+
function drawParticipantBottom(out, p3, layout) {
|
|
56599
|
+
const lifeline = layout.lifelines.find((l3) => Math.abs(l3.x - (p3.x + p3.width / 2)) < 1e-3);
|
|
56600
|
+
const y2 = lifeline ? lifeline.y2 : layout.height - 28;
|
|
56601
|
+
out.push(` <g class="actor" transform="translate(${p3.x},${y2})">`);
|
|
56602
|
+
out.push(` <rect class="node-shape" width="${p3.width}" height="${p3.height}" rx="0"/>`);
|
|
56603
|
+
out.push(` <text class="node-label" x="${p3.width / 2}" y="${p3.height / 2}" text-anchor="middle" dominant-baseline="middle">${escapeXml(p3.display)}</text>`);
|
|
56604
|
+
out.push(" </g>");
|
|
56605
|
+
}
|
|
56606
|
+
function drawMessage(out, m3) {
|
|
56607
|
+
const cls = `msg-line ${m3.line}`.trim();
|
|
56608
|
+
const x1 = m3.x1, x22 = m3.x2, y2 = m3.y;
|
|
56609
|
+
out.push(` <path class="${cls}" d="M ${x1} ${y2} L ${x22} ${y2}" />`);
|
|
56610
|
+
const start = { x: x1, y: y2 };
|
|
56611
|
+
const end = { x: x22, y: y2 };
|
|
56612
|
+
if (m3.endMarker === "arrow")
|
|
56613
|
+
out.push(" " + triangleAtEnd(start, end));
|
|
56614
|
+
if (m3.startMarker === "arrow")
|
|
56615
|
+
out.push(" " + triangleAtStart(start, end));
|
|
56616
|
+
if (m3.endMarker === "open")
|
|
56617
|
+
out.push(` <circle class="openhead" cx="${x22}" cy="${y2}" r="4" />`);
|
|
56618
|
+
if (m3.startMarker === "open")
|
|
56619
|
+
out.push(` <circle class="openhead" cx="${x1}" cy="${y2}" r="4" />`);
|
|
56620
|
+
if (m3.endMarker === "cross")
|
|
56621
|
+
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>`);
|
|
56622
|
+
if (m3.startMarker === "cross")
|
|
56623
|
+
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>`);
|
|
56624
|
+
}
|
|
56625
|
+
function formatMessageLabel(text, counter) {
|
|
56626
|
+
if (!text && counter == null)
|
|
56627
|
+
return void 0;
|
|
56628
|
+
if (counter != null && text)
|
|
56629
|
+
return `${counter}: ${text}`;
|
|
56630
|
+
if (counter != null)
|
|
56631
|
+
return String(counter);
|
|
56632
|
+
return text;
|
|
56633
|
+
}
|
|
56634
|
+
function drawMessageLabel(out, m3, label, _counter) {
|
|
56635
|
+
const xMid = (m3.x1 + m3.x2) / 2;
|
|
56636
|
+
const h3 = 16;
|
|
56637
|
+
const w3 = Math.max(20, measureText(label, 12) + 10);
|
|
56638
|
+
const x3 = xMid - w3 / 2;
|
|
56639
|
+
const y2 = m3.y - 10 - h3 / 2;
|
|
56640
|
+
out.push(` <rect class="msg-label-bg" x="${x3}" y="${y2}" width="${w3}" height="${h3}" rx="0"/>`);
|
|
56641
|
+
out.push(` <text class="msg-label" x="${xMid}" y="${y2 + h3 / 2}" text-anchor="middle">${escapeXml(label)}</text>`);
|
|
56642
|
+
}
|
|
56643
|
+
function drawNote(out, n3) {
|
|
56644
|
+
out.push(` <g class="note" transform="translate(${n3.x},${n3.y})">`);
|
|
56645
|
+
out.push(` <rect width="${n3.width}" height="${n3.height}" rx="0"/>`);
|
|
56646
|
+
out.push(` <text class="note-text" x="${n3.width / 2}" y="${n3.height / 2 + 4}" text-anchor="middle">${escapeXml(n3.text)}</text>`);
|
|
56647
|
+
out.push(" </g>");
|
|
56648
|
+
}
|
|
56649
|
+
function applySequenceTheme(svg, theme) {
|
|
56650
|
+
let out = svg;
|
|
56651
|
+
if (theme.actorBkg)
|
|
56652
|
+
out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorBkg)};`));
|
|
56653
|
+
if (theme.actorBorder)
|
|
56654
|
+
out = out.replace(/\.actor-rect\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.actorBorder)};`));
|
|
56655
|
+
if (theme.actorTextColor)
|
|
56656
|
+
out = out.replace(/\.actor-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.actorTextColor)};`));
|
|
56657
|
+
if (theme.lifelineColor)
|
|
56658
|
+
out = out.replace(/\.lifeline\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lifelineColor)};`));
|
|
56659
|
+
if (theme.lineColor)
|
|
56660
|
+
out = out.replace(/\.msg-line\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
|
|
56661
|
+
if (theme.arrowheadColor) {
|
|
56662
|
+
out = out.replace(/\.arrowhead\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.arrowheadColor)};`));
|
|
56663
|
+
out = out.replace(/\.openhead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
|
|
56664
|
+
out = out.replace(/\.crosshead\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.arrowheadColor)};`));
|
|
56665
|
+
}
|
|
56666
|
+
if (theme.noteBkg)
|
|
56667
|
+
out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteBkg)};`));
|
|
56668
|
+
if (theme.noteBorder)
|
|
56669
|
+
out = out.replace(/\.note\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.noteBorder)};`));
|
|
56670
|
+
if (theme.noteTextColor)
|
|
56671
|
+
out = out.replace(/\.note-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.noteTextColor)};`));
|
|
56672
|
+
if (theme.activationBkg)
|
|
56673
|
+
out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.activationBkg)};`));
|
|
56674
|
+
if (theme.activationBorder)
|
|
56675
|
+
out = out.replace(/\.activation\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.activationBorder)};`));
|
|
56676
|
+
return out;
|
|
56677
|
+
}
|
|
56678
|
+
var init_sequence_renderer = __esm({
|
|
56679
|
+
"node_modules/@probelabs/maid/out/renderer/sequence-renderer.js"() {
|
|
56680
|
+
init_sequence_layout();
|
|
56681
|
+
init_utils4();
|
|
56682
|
+
init_arrow_utils();
|
|
56683
|
+
init_block_utils();
|
|
56684
|
+
init_styles();
|
|
53595
56685
|
}
|
|
53596
56686
|
});
|
|
53597
56687
|
|
|
53598
|
-
// node_modules/
|
|
53599
|
-
|
|
53600
|
-
"
|
|
53601
|
-
|
|
53602
|
-
|
|
53603
|
-
|
|
53604
|
-
|
|
53605
|
-
|
|
53606
|
-
|
|
53607
|
-
|
|
53608
|
-
|
|
53609
|
-
|
|
53610
|
-
|
|
53611
|
-
|
|
53612
|
-
|
|
53613
|
-
|
|
53614
|
-
|
|
53615
|
-
|
|
53616
|
-
|
|
53617
|
-
|
|
53618
|
-
|
|
53619
|
-
|
|
53620
|
-
|
|
53621
|
-
|
|
53622
|
-
|
|
53623
|
-
|
|
53624
|
-
|
|
53625
|
-
|
|
56688
|
+
// node_modules/@probelabs/maid/out/core/frontmatter.js
|
|
56689
|
+
function parseFrontmatter(input) {
|
|
56690
|
+
const text = input.startsWith("\uFEFF") ? input.slice(1) : input;
|
|
56691
|
+
const lines = text.split(/\r?\n/);
|
|
56692
|
+
if (lines.length < 3 || lines[0].trim() !== "---")
|
|
56693
|
+
return null;
|
|
56694
|
+
let i3 = 1;
|
|
56695
|
+
const block = [];
|
|
56696
|
+
while (i3 < lines.length && lines[i3].trim() !== "---") {
|
|
56697
|
+
block.push(lines[i3]);
|
|
56698
|
+
i3++;
|
|
56699
|
+
}
|
|
56700
|
+
if (i3 >= lines.length)
|
|
56701
|
+
return null;
|
|
56702
|
+
const body = lines.slice(i3 + 1).join("\n");
|
|
56703
|
+
const raw = block.join("\n");
|
|
56704
|
+
const config = {};
|
|
56705
|
+
const themeVars = {};
|
|
56706
|
+
let themeUnderConfig = false;
|
|
56707
|
+
let ctx = "root";
|
|
56708
|
+
for (const line of block) {
|
|
56709
|
+
if (!line.trim())
|
|
56710
|
+
continue;
|
|
56711
|
+
const indent = line.match(/^\s*/)?.[0].length ?? 0;
|
|
56712
|
+
const mKey = line.match(/^\s*([A-Za-z0-9_\-]+):\s*(.*)$/);
|
|
56713
|
+
if (!mKey)
|
|
56714
|
+
continue;
|
|
56715
|
+
const key = mKey[1];
|
|
56716
|
+
let value = mKey[2] || "";
|
|
56717
|
+
if (indent === 0) {
|
|
56718
|
+
if (key === "config") {
|
|
56719
|
+
ctx = "config";
|
|
56720
|
+
continue;
|
|
56721
|
+
}
|
|
56722
|
+
if (key === "themeVariables") {
|
|
56723
|
+
ctx = "theme";
|
|
56724
|
+
continue;
|
|
56725
|
+
}
|
|
56726
|
+
ctx = "root";
|
|
56727
|
+
continue;
|
|
56728
|
+
}
|
|
56729
|
+
if (ctx === "config") {
|
|
56730
|
+
if (indent <= 2 && key !== "pie" && key !== "themeVariables")
|
|
56731
|
+
continue;
|
|
56732
|
+
if (key === "pie") {
|
|
56733
|
+
ctx = "config.pie";
|
|
56734
|
+
ensure(config, "pie", {});
|
|
56735
|
+
continue;
|
|
56736
|
+
}
|
|
56737
|
+
if (key === "themeVariables") {
|
|
56738
|
+
ctx = "theme";
|
|
56739
|
+
themeUnderConfig = true;
|
|
56740
|
+
continue;
|
|
56741
|
+
}
|
|
56742
|
+
continue;
|
|
56743
|
+
}
|
|
56744
|
+
if (ctx === "config.pie") {
|
|
56745
|
+
if (indent < 4) {
|
|
56746
|
+
if (key === "pie") {
|
|
56747
|
+
ctx = "config.pie";
|
|
56748
|
+
ensure(config, "pie", {});
|
|
56749
|
+
continue;
|
|
56750
|
+
}
|
|
56751
|
+
if (key === "themeVariables") {
|
|
56752
|
+
ctx = "theme";
|
|
56753
|
+
themeUnderConfig = true;
|
|
56754
|
+
continue;
|
|
56755
|
+
}
|
|
56756
|
+
ctx = "config";
|
|
56757
|
+
continue;
|
|
56758
|
+
}
|
|
56759
|
+
setKV(config.pie, key, value);
|
|
56760
|
+
continue;
|
|
56761
|
+
}
|
|
56762
|
+
if (ctx === "theme") {
|
|
56763
|
+
if (indent < 2) {
|
|
56764
|
+
ctx = "root";
|
|
56765
|
+
continue;
|
|
56766
|
+
}
|
|
56767
|
+
setKV(themeVars, key, value);
|
|
56768
|
+
continue;
|
|
53626
56769
|
}
|
|
53627
56770
|
}
|
|
53628
|
-
|
|
53629
|
-
|
|
53630
|
-
|
|
53631
|
-
var require_version2 = __commonJS({
|
|
53632
|
-
"node_modules/dagre/lib/version.js"(exports2, module2) {
|
|
53633
|
-
module2.exports = "0.8.5";
|
|
56771
|
+
if (themeUnderConfig && Object.keys(themeVars).length) {
|
|
56772
|
+
ensure(config, "themeVariables", {});
|
|
56773
|
+
Object.assign(config.themeVariables, themeVars);
|
|
53634
56774
|
}
|
|
53635
|
-
}
|
|
53636
|
-
|
|
53637
|
-
|
|
53638
|
-
|
|
53639
|
-
|
|
53640
|
-
|
|
53641
|
-
|
|
53642
|
-
|
|
53643
|
-
|
|
53644
|
-
|
|
53645
|
-
time: require_util().time,
|
|
53646
|
-
notime: require_util().notime
|
|
53647
|
-
},
|
|
53648
|
-
version: require_version2()
|
|
53649
|
-
};
|
|
56775
|
+
return { raw, body, config: Object.keys(config).length ? config : void 0, themeVariables: Object.keys(themeVars).length ? themeVars : void 0 };
|
|
56776
|
+
}
|
|
56777
|
+
function ensure(obj, key, def) {
|
|
56778
|
+
if (obj[key] == null)
|
|
56779
|
+
obj[key] = def;
|
|
56780
|
+
}
|
|
56781
|
+
function unquote2(val) {
|
|
56782
|
+
const v3 = val.trim();
|
|
56783
|
+
if (v3.startsWith('"') && v3.endsWith('"') || v3.startsWith("'") && v3.endsWith("'")) {
|
|
56784
|
+
return v3.slice(1, -1);
|
|
53650
56785
|
}
|
|
53651
|
-
|
|
53652
|
-
|
|
53653
|
-
|
|
53654
|
-
|
|
53655
|
-
|
|
53656
|
-
|
|
53657
|
-
|
|
56786
|
+
return v3;
|
|
56787
|
+
}
|
|
56788
|
+
function setKV(target, key, rawValue) {
|
|
56789
|
+
const v3 = unquote2(rawValue);
|
|
56790
|
+
if (v3 === "") {
|
|
56791
|
+
target[key] = "";
|
|
56792
|
+
return;
|
|
53658
56793
|
}
|
|
53659
|
-
|
|
53660
|
-
|
|
53661
|
-
|
|
53662
|
-
|
|
53663
|
-
|
|
56794
|
+
const num = Number(v3);
|
|
56795
|
+
if (!Number.isNaN(num) && /^-?[0-9]+(\.[0-9]+)?$/.test(v3)) {
|
|
56796
|
+
target[key] = num;
|
|
56797
|
+
return;
|
|
56798
|
+
}
|
|
56799
|
+
if (/^(true|false)$/i.test(v3)) {
|
|
56800
|
+
target[key] = /^true$/i.test(v3);
|
|
56801
|
+
return;
|
|
56802
|
+
}
|
|
56803
|
+
target[key] = v3;
|
|
56804
|
+
}
|
|
56805
|
+
var init_frontmatter = __esm({
|
|
56806
|
+
"node_modules/@probelabs/maid/out/core/frontmatter.js"() {
|
|
53664
56807
|
}
|
|
53665
56808
|
});
|
|
53666
56809
|
|
|
@@ -53671,6 +56814,102 @@ var init_dot_renderer = __esm({
|
|
|
53671
56814
|
});
|
|
53672
56815
|
|
|
53673
56816
|
// node_modules/@probelabs/maid/out/renderer/index.js
|
|
56817
|
+
function applyPieTheme(svg, theme) {
|
|
56818
|
+
if (!theme)
|
|
56819
|
+
return svg;
|
|
56820
|
+
let out = svg;
|
|
56821
|
+
if (theme.pieOuterStrokeWidth != null || theme.pieStrokeColor) {
|
|
56822
|
+
out = out.replace(/\.pieOuterCircle\s*\{[^}]*\}/, (m3) => {
|
|
56823
|
+
let rule = m3;
|
|
56824
|
+
if (theme.pieStrokeColor)
|
|
56825
|
+
rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`);
|
|
56826
|
+
if (theme.pieOuterStrokeWidth != null)
|
|
56827
|
+
rule = rule.replace(/stroke-width:\s*[^;]+;/, `stroke-width: ${String(theme.pieOuterStrokeWidth)};`);
|
|
56828
|
+
return rule;
|
|
56829
|
+
});
|
|
56830
|
+
if (theme.pieStrokeColor) {
|
|
56831
|
+
out = out.replace(/\.pieCircle\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.pieStrokeColor)};`));
|
|
56832
|
+
}
|
|
56833
|
+
}
|
|
56834
|
+
if (theme.pieSectionTextColor) {
|
|
56835
|
+
const c3 = String(theme.pieSectionTextColor);
|
|
56836
|
+
out = out.replace(/\.slice-label \{[^}]*\}/, (m3) => m3.replace(/fill:\s*#[0-9A-Fa-f]{3,8}|fill:\s*rgb\([^)]*\)/, `fill: ${c3}`));
|
|
56837
|
+
out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 fill="${c3}">`);
|
|
56838
|
+
}
|
|
56839
|
+
if (theme.pieTitleTextColor) {
|
|
56840
|
+
const c3 = String(theme.pieTitleTextColor);
|
|
56841
|
+
out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 fill="${c3}">`);
|
|
56842
|
+
}
|
|
56843
|
+
if (theme.pieSectionTextSize) {
|
|
56844
|
+
const size = String(theme.pieSectionTextSize);
|
|
56845
|
+
out = out.replace(/<text class="slice-label"([^>]*)>/g, `<text class="slice-label"$1 font-size="${size}">`);
|
|
56846
|
+
}
|
|
56847
|
+
if (theme.pieTitleTextSize) {
|
|
56848
|
+
const size = String(theme.pieTitleTextSize);
|
|
56849
|
+
out = out.replace(/<text class="pie-title"([^>]*)>/g, `<text class="pie-title"$1 font-size="${size}">`);
|
|
56850
|
+
}
|
|
56851
|
+
const colors = [];
|
|
56852
|
+
for (let i3 = 1; i3 <= 24; i3++) {
|
|
56853
|
+
const key = "pie" + i3;
|
|
56854
|
+
if (theme[key])
|
|
56855
|
+
colors.push(String(theme[key]));
|
|
56856
|
+
}
|
|
56857
|
+
if (colors.length) {
|
|
56858
|
+
let idx = 0;
|
|
56859
|
+
out = out.replace(/<path[^>]*class="pieCircle"[^>]*\sfill="([^"]+)"/g, (_m2) => {
|
|
56860
|
+
const color = colors[idx] ?? null;
|
|
56861
|
+
idx++;
|
|
56862
|
+
if (color)
|
|
56863
|
+
return _m2.replace(/fill="([^"]+)"/, `fill="${color}"`);
|
|
56864
|
+
return _m2;
|
|
56865
|
+
});
|
|
56866
|
+
}
|
|
56867
|
+
return out;
|
|
56868
|
+
}
|
|
56869
|
+
function applyFlowchartTheme(svg, theme) {
|
|
56870
|
+
if (!theme)
|
|
56871
|
+
return svg;
|
|
56872
|
+
let out = svg;
|
|
56873
|
+
if (theme.nodeBkg || theme.nodeBorder) {
|
|
56874
|
+
out = out.replace(/\.node-shape\s*\{[^}]*\}/, (m3) => {
|
|
56875
|
+
let rule = m3;
|
|
56876
|
+
if (theme.nodeBkg)
|
|
56877
|
+
rule = rule.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeBkg)};`);
|
|
56878
|
+
if (theme.nodeBorder)
|
|
56879
|
+
rule = rule.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.nodeBorder)};`);
|
|
56880
|
+
return rule;
|
|
56881
|
+
});
|
|
56882
|
+
}
|
|
56883
|
+
if (theme.nodeTextColor) {
|
|
56884
|
+
out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.nodeTextColor)};`));
|
|
56885
|
+
}
|
|
56886
|
+
if (theme.lineColor) {
|
|
56887
|
+
out = out.replace(/\.edge-path\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.lineColor)};`));
|
|
56888
|
+
}
|
|
56889
|
+
if (theme.arrowheadColor) {
|
|
56890
|
+
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)}"`);
|
|
56891
|
+
out = out.replace(/(<circle cx="4\.5" cy="4\.5" r="4\.5"[^>]*)(fill="[^"]*")/g, (_m2, p1) => `${p1}fill="${String(theme.arrowheadColor)}"`);
|
|
56892
|
+
}
|
|
56893
|
+
if (theme.clusterBkg) {
|
|
56894
|
+
out = out.replace(/\.cluster-bg\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterBkg)};`));
|
|
56895
|
+
}
|
|
56896
|
+
if (theme.clusterBorder) {
|
|
56897
|
+
out = out.replace(/\.cluster-border\s*\{[^}]*\}/, (m3) => m3.replace(/stroke:\s*[^;]+;/, `stroke: ${String(theme.clusterBorder)};`));
|
|
56898
|
+
}
|
|
56899
|
+
if (theme.clusterTextColor) {
|
|
56900
|
+
out = out.replace(/\.cluster-label-text\s*\{[^}]*\}/, (m3) => m3.replace(/fill:\s*[^;]+;/, `fill: ${String(theme.clusterTextColor)};`));
|
|
56901
|
+
}
|
|
56902
|
+
if (theme.fontFamily)
|
|
56903
|
+
out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-family:\s*[^;]+;/, `font-family: ${String(theme.fontFamily)};`));
|
|
56904
|
+
if (theme.fontSize)
|
|
56905
|
+
out = out.replace(/\.node-label\s*\{[^}]*\}/, (m3) => m3.replace(/font-size:\s*[^;]+;/, `font-size: ${String(theme.fontSize)};`));
|
|
56906
|
+
return out;
|
|
56907
|
+
}
|
|
56908
|
+
function renderMermaid(text, options = {}) {
|
|
56909
|
+
const renderer = new MermaidRenderer(options.layoutEngine, options.renderer);
|
|
56910
|
+
return renderer.renderAny(text, options);
|
|
56911
|
+
}
|
|
56912
|
+
var MermaidRenderer;
|
|
53674
56913
|
var init_renderer = __esm({
|
|
53675
56914
|
"node_modules/@probelabs/maid/out/renderer/index.js"() {
|
|
53676
56915
|
init_lexer2();
|
|
@@ -53678,9 +56917,244 @@ var init_renderer = __esm({
|
|
|
53678
56917
|
init_graph_builder();
|
|
53679
56918
|
init_layout();
|
|
53680
56919
|
init_svg_generator();
|
|
56920
|
+
init_pie_builder();
|
|
56921
|
+
init_pie_renderer();
|
|
56922
|
+
init_sequence_builder();
|
|
56923
|
+
init_sequence_renderer();
|
|
56924
|
+
init_frontmatter();
|
|
53681
56925
|
init_layout();
|
|
53682
56926
|
init_svg_generator();
|
|
53683
56927
|
init_dot_renderer();
|
|
56928
|
+
MermaidRenderer = class {
|
|
56929
|
+
constructor(layoutEngine, renderer) {
|
|
56930
|
+
this.graphBuilder = new GraphBuilder();
|
|
56931
|
+
this.layoutEngine = layoutEngine || new DagreLayoutEngine();
|
|
56932
|
+
this.renderer = renderer || new SVGRenderer();
|
|
56933
|
+
}
|
|
56934
|
+
/**
|
|
56935
|
+
* Renders a Mermaid flowchart diagram
|
|
56936
|
+
*/
|
|
56937
|
+
render(text, options = {}) {
|
|
56938
|
+
const errors = [];
|
|
56939
|
+
const layoutEngine = options.layoutEngine || this.layoutEngine;
|
|
56940
|
+
const renderer = options.renderer || this.renderer;
|
|
56941
|
+
try {
|
|
56942
|
+
const lexResult = tokenize(text);
|
|
56943
|
+
if (lexResult.errors && lexResult.errors.length > 0) {
|
|
56944
|
+
for (const error2 of lexResult.errors) {
|
|
56945
|
+
errors.push({
|
|
56946
|
+
line: error2.line || 1,
|
|
56947
|
+
column: error2.column || 1,
|
|
56948
|
+
message: error2.message,
|
|
56949
|
+
severity: "error",
|
|
56950
|
+
code: "LEXER_ERROR"
|
|
56951
|
+
});
|
|
56952
|
+
}
|
|
56953
|
+
}
|
|
56954
|
+
parserInstance.reset();
|
|
56955
|
+
parserInstance.input = lexResult.tokens;
|
|
56956
|
+
const cst = parserInstance.diagram();
|
|
56957
|
+
if (parserInstance.errors && parserInstance.errors.length > 0) {
|
|
56958
|
+
for (const error2 of parserInstance.errors) {
|
|
56959
|
+
const token = error2.token;
|
|
56960
|
+
errors.push({
|
|
56961
|
+
line: token?.startLine || 1,
|
|
56962
|
+
column: token?.startColumn || 1,
|
|
56963
|
+
message: error2.message,
|
|
56964
|
+
severity: "error",
|
|
56965
|
+
code: "PARSER_ERROR"
|
|
56966
|
+
});
|
|
56967
|
+
}
|
|
56968
|
+
}
|
|
56969
|
+
const graph = this.graphBuilder.build(cst);
|
|
56970
|
+
let layout;
|
|
56971
|
+
try {
|
|
56972
|
+
layout = layoutEngine.layout(graph);
|
|
56973
|
+
} catch (layoutError) {
|
|
56974
|
+
errors.push({
|
|
56975
|
+
line: 1,
|
|
56976
|
+
column: 1,
|
|
56977
|
+
message: layoutError.message || "Layout calculation failed",
|
|
56978
|
+
severity: "error",
|
|
56979
|
+
code: "LAYOUT_ERROR"
|
|
56980
|
+
});
|
|
56981
|
+
return {
|
|
56982
|
+
svg: this.generateErrorSvg(layoutError.message || "Layout calculation failed"),
|
|
56983
|
+
graph,
|
|
56984
|
+
errors
|
|
56985
|
+
};
|
|
56986
|
+
}
|
|
56987
|
+
let svg = renderer.render(layout);
|
|
56988
|
+
if (options.showErrors && errors.length > 0) {
|
|
56989
|
+
svg = this.addErrorOverlays(svg, errors);
|
|
56990
|
+
}
|
|
56991
|
+
return {
|
|
56992
|
+
svg,
|
|
56993
|
+
graph,
|
|
56994
|
+
errors
|
|
56995
|
+
};
|
|
56996
|
+
} catch (error2) {
|
|
56997
|
+
const errorSvg = this.generateErrorSvg(error2.message || "Unknown error occurred");
|
|
56998
|
+
errors.push({
|
|
56999
|
+
line: 1,
|
|
57000
|
+
column: 1,
|
|
57001
|
+
message: error2.message || "Unknown error occurred",
|
|
57002
|
+
severity: "error",
|
|
57003
|
+
code: "RENDER_ERROR"
|
|
57004
|
+
});
|
|
57005
|
+
return {
|
|
57006
|
+
svg: errorSvg,
|
|
57007
|
+
graph: { nodes: [], edges: [], direction: "TD" },
|
|
57008
|
+
errors
|
|
57009
|
+
};
|
|
57010
|
+
}
|
|
57011
|
+
}
|
|
57012
|
+
/**
|
|
57013
|
+
* Renders supported diagram types (flowchart + pie for now)
|
|
57014
|
+
*/
|
|
57015
|
+
renderAny(text, options = {}) {
|
|
57016
|
+
let content = text;
|
|
57017
|
+
let theme;
|
|
57018
|
+
if (text.trimStart().startsWith("---")) {
|
|
57019
|
+
const fm = parseFrontmatter(text);
|
|
57020
|
+
if (fm) {
|
|
57021
|
+
content = fm.body;
|
|
57022
|
+
theme = fm.themeVariables || fm.config && fm.config.themeVariables || void 0;
|
|
57023
|
+
}
|
|
57024
|
+
}
|
|
57025
|
+
const firstLine = content.trim().split("\n")[0];
|
|
57026
|
+
if (/^(flowchart|graph)\s+/i.test(firstLine)) {
|
|
57027
|
+
const res = this.render(content, options);
|
|
57028
|
+
const svg2 = theme ? applyFlowchartTheme(res.svg, theme) : res.svg;
|
|
57029
|
+
return { svg: svg2, graph: res.graph, errors: res.errors };
|
|
57030
|
+
}
|
|
57031
|
+
if (/^pie\b/i.test(firstLine)) {
|
|
57032
|
+
try {
|
|
57033
|
+
const { model, errors } = buildPieModel(content);
|
|
57034
|
+
const svg = renderPie(model, {
|
|
57035
|
+
width: options.width,
|
|
57036
|
+
height: options.height,
|
|
57037
|
+
rimStroke: theme?.pieStrokeColor,
|
|
57038
|
+
rimStrokeWidth: theme?.pieOuterStrokeWidth
|
|
57039
|
+
});
|
|
57040
|
+
const themedSvg = applyPieTheme(svg, theme);
|
|
57041
|
+
return { svg: themedSvg, graph: { nodes: [], edges: [], direction: "TD" }, errors };
|
|
57042
|
+
} catch (e3) {
|
|
57043
|
+
const msg = e3?.message || "Pie render error";
|
|
57044
|
+
const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "PIE_RENDER" }];
|
|
57045
|
+
return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
|
|
57046
|
+
}
|
|
57047
|
+
}
|
|
57048
|
+
if (/^sequenceDiagram\b/.test(firstLine)) {
|
|
57049
|
+
try {
|
|
57050
|
+
const model = buildSequenceModel(content);
|
|
57051
|
+
const svg = renderSequence(model, { theme });
|
|
57052
|
+
return { svg, graph: { nodes: [], edges: [], direction: "TD" }, errors: [] };
|
|
57053
|
+
} catch (e3) {
|
|
57054
|
+
const msg = e3?.message || "Sequence render error";
|
|
57055
|
+
const err = [{ line: 1, column: 1, message: msg, severity: "error", code: "SEQUENCE_RENDER" }];
|
|
57056
|
+
return { svg: this.generateErrorSvg(msg), graph: { nodes: [], edges: [], direction: "TD" }, errors: err };
|
|
57057
|
+
}
|
|
57058
|
+
}
|
|
57059
|
+
const errorSvg = this.generateErrorSvg("Unsupported diagram type. Rendering supports flowchart, pie, and sequence for now.");
|
|
57060
|
+
return {
|
|
57061
|
+
svg: errorSvg,
|
|
57062
|
+
graph: { nodes: [], edges: [], direction: "TD" },
|
|
57063
|
+
errors: [{
|
|
57064
|
+
line: 1,
|
|
57065
|
+
column: 1,
|
|
57066
|
+
message: "Unsupported diagram type",
|
|
57067
|
+
severity: "error",
|
|
57068
|
+
code: "UNSUPPORTED_TYPE"
|
|
57069
|
+
}]
|
|
57070
|
+
};
|
|
57071
|
+
}
|
|
57072
|
+
addErrorOverlays(svg, errors) {
|
|
57073
|
+
const errorStyle = `
|
|
57074
|
+
<style>
|
|
57075
|
+
.error-indicator {
|
|
57076
|
+
fill: #ff0000;
|
|
57077
|
+
opacity: 0.8;
|
|
57078
|
+
}
|
|
57079
|
+
.error-text {
|
|
57080
|
+
fill: white;
|
|
57081
|
+
font-family: Arial, sans-serif;
|
|
57082
|
+
font-size: 12px;
|
|
57083
|
+
font-weight: bold;
|
|
57084
|
+
}
|
|
57085
|
+
</style>`;
|
|
57086
|
+
const errorIndicator = `
|
|
57087
|
+
<g id="errors">
|
|
57088
|
+
<rect x="5" y="5" width="100" height="25" rx="3" class="error-indicator" />
|
|
57089
|
+
<text x="55" y="20" text-anchor="middle" class="error-text">${errors.length} error${errors.length !== 1 ? "s" : ""}</text>
|
|
57090
|
+
</g>`;
|
|
57091
|
+
return svg.replace("</svg>", `${errorStyle}${errorIndicator}</svg>`);
|
|
57092
|
+
}
|
|
57093
|
+
generateErrorSvg(message) {
|
|
57094
|
+
const width = 400;
|
|
57095
|
+
const height = 200;
|
|
57096
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
|
|
57097
|
+
<rect width="${width}" height="${height}" fill="#fee" stroke="#c00" stroke-width="2" />
|
|
57098
|
+
<text x="${width / 2}" y="${height / 2 - 20}" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#c00">
|
|
57099
|
+
Render Error
|
|
57100
|
+
</text>
|
|
57101
|
+
<text x="${width / 2}" y="${height / 2 + 10}" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#666">
|
|
57102
|
+
${this.wrapText(message, 40).map((line, i3) => `<tspan x="${width / 2}" dy="${i3 === 0 ? 0 : 15}">${this.escapeXml(line)}</tspan>`).join("")}
|
|
57103
|
+
</text>
|
|
57104
|
+
</svg>`;
|
|
57105
|
+
}
|
|
57106
|
+
wrapText(text, maxLength) {
|
|
57107
|
+
const words = text.split(" ");
|
|
57108
|
+
const lines = [];
|
|
57109
|
+
let currentLine = "";
|
|
57110
|
+
for (const word of words) {
|
|
57111
|
+
if (currentLine.length + word.length + 1 <= maxLength) {
|
|
57112
|
+
currentLine += (currentLine ? " " : "") + word;
|
|
57113
|
+
} else {
|
|
57114
|
+
if (currentLine)
|
|
57115
|
+
lines.push(currentLine);
|
|
57116
|
+
currentLine = word;
|
|
57117
|
+
}
|
|
57118
|
+
}
|
|
57119
|
+
if (currentLine)
|
|
57120
|
+
lines.push(currentLine);
|
|
57121
|
+
return lines.slice(0, 3);
|
|
57122
|
+
}
|
|
57123
|
+
escapeXml(text) {
|
|
57124
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
57125
|
+
}
|
|
57126
|
+
};
|
|
57127
|
+
}
|
|
57128
|
+
});
|
|
57129
|
+
|
|
57130
|
+
// node_modules/@probelabs/maid/out/mermaid-compat.js
|
|
57131
|
+
function createMermaidAPI() {
|
|
57132
|
+
return {
|
|
57133
|
+
initialize(_config) {
|
|
57134
|
+
},
|
|
57135
|
+
async render(_id, text, options) {
|
|
57136
|
+
try {
|
|
57137
|
+
const result = renderMermaid(text, options);
|
|
57138
|
+
return { svg: result.svg };
|
|
57139
|
+
} catch (error2) {
|
|
57140
|
+
throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
|
|
57141
|
+
}
|
|
57142
|
+
},
|
|
57143
|
+
renderSync(_id, text, options) {
|
|
57144
|
+
try {
|
|
57145
|
+
const result = renderMermaid(text, options);
|
|
57146
|
+
return { svg: result.svg };
|
|
57147
|
+
} catch (error2) {
|
|
57148
|
+
throw new Error(`Maid render failed: ${error2.message || "Unknown error"}`);
|
|
57149
|
+
}
|
|
57150
|
+
}
|
|
57151
|
+
};
|
|
57152
|
+
}
|
|
57153
|
+
var maid;
|
|
57154
|
+
var init_mermaid_compat = __esm({
|
|
57155
|
+
"node_modules/@probelabs/maid/out/mermaid-compat.js"() {
|
|
57156
|
+
init_renderer();
|
|
57157
|
+
maid = createMermaidAPI();
|
|
53684
57158
|
}
|
|
53685
57159
|
});
|
|
53686
57160
|
|
|
@@ -53714,6 +57188,7 @@ var init_out = __esm({
|
|
|
53714
57188
|
init_edits();
|
|
53715
57189
|
init_fixes();
|
|
53716
57190
|
init_renderer();
|
|
57191
|
+
init_mermaid_compat();
|
|
53717
57192
|
init_router();
|
|
53718
57193
|
init_fixes();
|
|
53719
57194
|
init_edits();
|
|
@@ -54488,8 +57963,8 @@ When presented with a broken Mermaid diagram, analyze it thoroughly and provide
|
|
|
54488
57963
|
debug: this.options.debug,
|
|
54489
57964
|
tracer: this.options.tracer,
|
|
54490
57965
|
allowEdit: this.options.allowEdit,
|
|
54491
|
-
maxIterations:
|
|
54492
|
-
//
|
|
57966
|
+
maxIterations: 10,
|
|
57967
|
+
// Allow more iterations for mermaid fixing to handle complex diagrams
|
|
54493
57968
|
disableMermaidValidation: true
|
|
54494
57969
|
// CRITICAL: Disable mermaid validation in nested agent to prevent infinite recursion
|
|
54495
57970
|
});
|
|
@@ -55389,6 +58864,18 @@ var init_ProbeAgent = __esm({
|
|
|
55389
58864
|
this.toolImplementations.bash = wrappedTools.bashToolInstance;
|
|
55390
58865
|
}
|
|
55391
58866
|
this.wrappedTools = wrappedTools;
|
|
58867
|
+
if (this.debug) {
|
|
58868
|
+
console.error("\n[DEBUG] ========================================");
|
|
58869
|
+
console.error("[DEBUG] ProbeAgent Tools Initialized");
|
|
58870
|
+
console.error("[DEBUG] Session ID:", this.sessionId);
|
|
58871
|
+
console.error("[DEBUG] Available tools:");
|
|
58872
|
+
for (const toolName of Object.keys(this.toolImplementations)) {
|
|
58873
|
+
console.error(`[DEBUG] - ${toolName}`);
|
|
58874
|
+
}
|
|
58875
|
+
console.error("[DEBUG] Allowed folders:", this.allowedFolders);
|
|
58876
|
+
console.error("[DEBUG] Outline mode:", this.outline);
|
|
58877
|
+
console.error("[DEBUG] ========================================\n");
|
|
58878
|
+
}
|
|
55392
58879
|
}
|
|
55393
58880
|
/**
|
|
55394
58881
|
* Initialize the AI model based on available API keys and forced provider setting
|
|
@@ -56159,12 +59646,28 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
56159
59646
|
const { type } = parsedTool;
|
|
56160
59647
|
if (type === "mcp" && this.mcpBridge && this.mcpBridge.isMcpTool(toolName)) {
|
|
56161
59648
|
try {
|
|
56162
|
-
if (this.debug)
|
|
59649
|
+
if (this.debug) {
|
|
59650
|
+
console.error(`
|
|
59651
|
+
[DEBUG] ========================================`);
|
|
59652
|
+
console.error(`[DEBUG] Executing MCP tool: ${toolName}`);
|
|
59653
|
+
console.error(`[DEBUG] Arguments:`);
|
|
59654
|
+
for (const [key, value] of Object.entries(params)) {
|
|
59655
|
+
const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
|
|
59656
|
+
console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
|
|
59657
|
+
}
|
|
59658
|
+
console.error(`[DEBUG] ========================================
|
|
59659
|
+
`);
|
|
59660
|
+
}
|
|
56163
59661
|
const executionResult = await this.mcpBridge.mcpTools[toolName].execute(params);
|
|
56164
59662
|
const toolResultContent = typeof executionResult === "string" ? executionResult : JSON.stringify(executionResult, null, 2);
|
|
56165
|
-
const preview = createMessagePreview(toolResultContent);
|
|
56166
59663
|
if (this.debug) {
|
|
56167
|
-
|
|
59664
|
+
const preview = toolResultContent.length > 500 ? toolResultContent.substring(0, 500) + "..." : toolResultContent;
|
|
59665
|
+
console.error(`[DEBUG] ========================================`);
|
|
59666
|
+
console.error(`[DEBUG] MCP tool '${toolName}' completed successfully`);
|
|
59667
|
+
console.error(`[DEBUG] Result preview:`);
|
|
59668
|
+
console.error(preview);
|
|
59669
|
+
console.error(`[DEBUG] ========================================
|
|
59670
|
+
`);
|
|
56168
59671
|
}
|
|
56169
59672
|
currentMessages.push({ role: "user", content: `<tool_result>
|
|
56170
59673
|
${toolResultContent}
|
|
@@ -56172,7 +59675,13 @@ ${toolResultContent}
|
|
|
56172
59675
|
} catch (error2) {
|
|
56173
59676
|
console.error(`Error executing MCP tool ${toolName}:`, error2);
|
|
56174
59677
|
const toolResultContent = `Error executing MCP tool ${toolName}: ${error2.message}`;
|
|
56175
|
-
if (this.debug)
|
|
59678
|
+
if (this.debug) {
|
|
59679
|
+
console.error(`[DEBUG] ========================================`);
|
|
59680
|
+
console.error(`[DEBUG] MCP tool '${toolName}' failed with error:`);
|
|
59681
|
+
console.error(`[DEBUG] ${error2.message}`);
|
|
59682
|
+
console.error(`[DEBUG] ========================================
|
|
59683
|
+
`);
|
|
59684
|
+
}
|
|
56176
59685
|
currentMessages.push({ role: "user", content: `<tool_result>
|
|
56177
59686
|
${toolResultContent}
|
|
56178
59687
|
</tool_result>` });
|
|
@@ -56184,6 +59693,18 @@ ${toolResultContent}
|
|
|
56184
59693
|
sessionId: this.sessionId,
|
|
56185
59694
|
workingDirectory: this.allowedFolders && this.allowedFolders[0] || process.cwd()
|
|
56186
59695
|
};
|
|
59696
|
+
if (this.debug) {
|
|
59697
|
+
console.error(`
|
|
59698
|
+
[DEBUG] ========================================`);
|
|
59699
|
+
console.error(`[DEBUG] Executing tool: ${toolName}`);
|
|
59700
|
+
console.error(`[DEBUG] Arguments:`);
|
|
59701
|
+
for (const [key, value] of Object.entries(params)) {
|
|
59702
|
+
const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
|
|
59703
|
+
console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
|
|
59704
|
+
}
|
|
59705
|
+
console.error(`[DEBUG] ========================================
|
|
59706
|
+
`);
|
|
59707
|
+
}
|
|
56187
59708
|
this.events.emit("toolCall", {
|
|
56188
59709
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56189
59710
|
name: toolName,
|
|
@@ -56225,6 +59746,15 @@ ${toolResultContent}
|
|
|
56225
59746
|
} else {
|
|
56226
59747
|
toolResult = await executeToolCall();
|
|
56227
59748
|
}
|
|
59749
|
+
if (this.debug) {
|
|
59750
|
+
const resultPreview = typeof toolResult === "string" ? toolResult.length > 500 ? toolResult.substring(0, 500) + "..." : toolResult : toolResult ? JSON.stringify(toolResult, null, 2).substring(0, 500) + "..." : "No Result";
|
|
59751
|
+
console.error(`[DEBUG] ========================================`);
|
|
59752
|
+
console.error(`[DEBUG] Tool '${toolName}' completed successfully`);
|
|
59753
|
+
console.error(`[DEBUG] Result preview:`);
|
|
59754
|
+
console.error(resultPreview);
|
|
59755
|
+
console.error(`[DEBUG] ========================================
|
|
59756
|
+
`);
|
|
59757
|
+
}
|
|
56228
59758
|
this.events.emit("toolCall", {
|
|
56229
59759
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56230
59760
|
name: toolName,
|
|
@@ -56233,6 +59763,13 @@ ${toolResultContent}
|
|
|
56233
59763
|
status: "completed"
|
|
56234
59764
|
});
|
|
56235
59765
|
} catch (toolError) {
|
|
59766
|
+
if (this.debug) {
|
|
59767
|
+
console.error(`[DEBUG] ========================================`);
|
|
59768
|
+
console.error(`[DEBUG] Tool '${toolName}' failed with error:`);
|
|
59769
|
+
console.error(`[DEBUG] ${toolError.message}`);
|
|
59770
|
+
console.error(`[DEBUG] ========================================
|
|
59771
|
+
`);
|
|
59772
|
+
}
|
|
56236
59773
|
this.events.emit("toolCall", {
|
|
56237
59774
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56238
59775
|
name: toolName,
|
|
@@ -56282,6 +59819,16 @@ Error: Unknown tool '${toolName}'. Available tools: ${allAvailableTools.join(",
|
|
|
56282
59819
|
}
|
|
56283
59820
|
}
|
|
56284
59821
|
} else {
|
|
59822
|
+
const hasMermaidCodeBlock = /```mermaid\s*\n[\s\S]*?\n```/.test(assistantResponseContent);
|
|
59823
|
+
const hasNoSchemaOrTools = !options.schema && validTools.length === 0;
|
|
59824
|
+
if (hasMermaidCodeBlock && hasNoSchemaOrTools) {
|
|
59825
|
+
finalResult = assistantResponseContent;
|
|
59826
|
+
completionAttempted = true;
|
|
59827
|
+
if (this.debug) {
|
|
59828
|
+
console.error(`[DEBUG] Accepting mermaid code block as valid completion (no schema, no tools)`);
|
|
59829
|
+
}
|
|
59830
|
+
break;
|
|
59831
|
+
}
|
|
56285
59832
|
currentMessages.push({ role: "assistant", content: assistantResponseContent });
|
|
56286
59833
|
let reminderContent;
|
|
56287
59834
|
if (options.schema) {
|