@uigraph/sdk 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1779,6 +1779,53 @@ function syncBaseData(prev, next, options) {
1779
1779
  }
1780
1780
  return updated;
1781
1781
  }
1782
+ const LAYOUT_SPACING = {
1783
+ SUBGRAPH_HEADER_HEIGHT: 35,
1784
+ SUBGRAPH_PADDING: 8,
1785
+ SUBGRAPH_CONTENT_TOP_MARGIN: 10,
1786
+ NODE_SEPARATION_HORIZONTAL: 80,
1787
+ NODE_SEPARATION_VERTICAL: 100,
1788
+ CONTAINER_SEPARATION_HORIZONTAL: 120,
1789
+ CONTAINER_SEPARATION_VERTICAL: 160,
1790
+ NESTED_SUBGRAPH_SEPARATION_HORIZONTAL: 120,
1791
+ NESTED_SUBGRAPH_SEPARATION_VERTICAL: 140,
1792
+ META_GRAPH_MARGIN: 100,
1793
+ NESTED_CONTENT_MARGIN: 40,
1794
+ MIXED_CONTENT_VERTICAL_SPACING: 100,
1795
+ MIXED_CONTENT_HORIZONTAL_SPACING: 120
1796
+ };
1797
+ const LAYOUT_RANKERS = {
1798
+ NETWORK_SIMPLEX: "network-simplex",
1799
+ TIGHT_TREE: "tight-tree",
1800
+ LONGEST_PATH: "longest-path"
1801
+ };
1802
+ const DEFAULT_LAYOUT_RANKER = LAYOUT_RANKERS.TIGHT_TREE;
1803
+ const SEQUENCE_PARTICIPANT_COLOR = "#E2E8F0";
1804
+ const SEQUENCE_LAYOUT = {
1805
+ COLUMN_WIDTH: 360,
1806
+ ROW_HEIGHT: 60,
1807
+ HEADER_HEIGHT: 40,
1808
+ MESSAGE_NODE_WIDTH: 140,
1809
+ MESSAGE_NODE_HEIGHT: 32,
1810
+ SELF_LOOP_OFFSET: 48,
1811
+ PARTICIPANT_NODE_WIDTH: 10,
1812
+ MESSAGE_MAX_WIDTH: 240,
1813
+ MESSAGE_TARGET_WRAP_LINES: 2,
1814
+ MESSAGE_CHAR_WIDTH: 7,
1815
+ MESSAGE_LINE_HEIGHT: 20,
1816
+ MESSAGE_HORIZONTAL_PADDING: 24,
1817
+ MESSAGE_VERTICAL_PADDING: 8,
1818
+ ROW_VERTICAL_PADDING: 16,
1819
+ NOTE_OFFSET: 24,
1820
+ BLOCK_TOP_PADDING: 36,
1821
+ BLOCK_BOTTOM_PADDING: 16,
1822
+ BLOCK_SIDE_PADDING: 44,
1823
+ BLOCK_SECTION_PADDING: 22,
1824
+ BLOCK_CONTENT_INSET: 12,
1825
+ BLOCK_FRAME_GAP: 12,
1826
+ BOX_TOP_INSET: 26,
1827
+ BOX_BOTTOM_PADDING: 24
1828
+ };
1782
1829
  function sanitizeMermaidLabels(src) {
1783
1830
  if (!src) return src;
1784
1831
  const subgraphFixed = src.replace(/([A-Za-z0-9_]+)\[((?:(?![\"']).)*?)\]/g, (m, id, label) => {
@@ -1940,36 +1987,6 @@ function getComponentFieldByLabel(fields, label) {
1940
1987
  return ((_field$label = field.label) === null || _field$label === void 0 ? void 0 : _field$label.toLowerCase()) === label.toLowerCase();
1941
1988
  });
1942
1989
  }
1943
- const LAYOUT_SPACING = {
1944
- SUBGRAPH_HEADER_HEIGHT: 35,
1945
- SUBGRAPH_PADDING: 8,
1946
- SUBGRAPH_CONTENT_TOP_MARGIN: 10,
1947
- NODE_SEPARATION_HORIZONTAL: 80,
1948
- NODE_SEPARATION_VERTICAL: 100,
1949
- CONTAINER_SEPARATION_HORIZONTAL: 120,
1950
- CONTAINER_SEPARATION_VERTICAL: 160,
1951
- NESTED_SUBGRAPH_SEPARATION_HORIZONTAL: 120,
1952
- NESTED_SUBGRAPH_SEPARATION_VERTICAL: 140,
1953
- META_GRAPH_MARGIN: 100,
1954
- NESTED_CONTENT_MARGIN: 40,
1955
- MIXED_CONTENT_VERTICAL_SPACING: 100,
1956
- MIXED_CONTENT_HORIZONTAL_SPACING: 120
1957
- };
1958
- const LAYOUT_RANKERS = {
1959
- NETWORK_SIMPLEX: "network-simplex",
1960
- TIGHT_TREE: "tight-tree",
1961
- LONGEST_PATH: "longest-path"
1962
- };
1963
- const DEFAULT_LAYOUT_RANKER = LAYOUT_RANKERS.TIGHT_TREE;
1964
- const SEQUENCE_LAYOUT = {
1965
- COLUMN_WIDTH: 360,
1966
- ROW_HEIGHT: 60,
1967
- HEADER_HEIGHT: 40,
1968
- MESSAGE_NODE_WIDTH: 120,
1969
- MESSAGE_NODE_HEIGHT: 36,
1970
- SELF_LOOP_OFFSET: 80,
1971
- PARTICIPANT_NODE_WIDTH: 10
1972
- };
1973
1990
  const LABEL_TYPE_PREFIX = /^\s*type:(\w+)\s*[:|-]\s*/i;
1974
1991
  const TAG_TO_NODE_TYPE = {
1975
1992
  builder: "builder",
@@ -1997,6 +2014,1081 @@ function resolvePortalNodeType(hasImageUrl, tag) {
1997
2014
  if (tag && TAG_TO_NODE_TYPE[tag]) return TAG_TO_NODE_TYPE[tag];
1998
2015
  return "shape";
1999
2016
  }
2017
+ function estimateLines(words, charsPerLine) {
2018
+ let lines = 1;
2019
+ let current = 0;
2020
+ for (const word of words) {
2021
+ if (word.length > charsPerLine) {
2022
+ if (current > 0) lines += 1;
2023
+ const wordLines = Math.ceil(word.length / charsPerLine);
2024
+ lines += wordLines - 1;
2025
+ current = word.length - (wordLines - 1) * charsPerLine;
2026
+ continue;
2027
+ }
2028
+ const next = current === 0 ? word.length : current + 1 + word.length;
2029
+ if (next > charsPerLine) {
2030
+ lines += 1;
2031
+ current = word.length;
2032
+ } else current = next;
2033
+ }
2034
+ return lines;
2035
+ }
2036
+ function estimateSequenceMessageBoxSize(label) {
2037
+ const { MESSAGE_NODE_WIDTH, MESSAGE_NODE_HEIGHT, MESSAGE_MAX_WIDTH, MESSAGE_TARGET_WRAP_LINES, MESSAGE_CHAR_WIDTH, MESSAGE_LINE_HEIGHT, MESSAGE_HORIZONTAL_PADDING, MESSAGE_VERTICAL_PADDING } = SEQUENCE_LAYOUT;
2038
+ const text = label.trim();
2039
+ if (!text) return {
2040
+ width: MESSAGE_NODE_WIDTH,
2041
+ height: MESSAGE_NODE_HEIGHT
2042
+ };
2043
+ if (text.includes("\n")) {
2044
+ const segments = text.split("\n").map((segment) => estimateSequenceMessageBoxSize(segment));
2045
+ return {
2046
+ width: Math.max(...segments.map((segment) => segment.width)),
2047
+ height: segments.reduce((total, segment) => total + segment.height - Number(MESSAGE_VERTICAL_PADDING), Number(MESSAGE_VERTICAL_PADDING))
2048
+ };
2049
+ }
2050
+ const words = text.split(/\s+/).filter(Boolean);
2051
+ const longestWord = Math.max(1, ...words.map((w) => w.length));
2052
+ const idealCharsPerLine = Math.max(1, Math.ceil(text.length / MESSAGE_TARGET_WRAP_LINES));
2053
+ const charsPerLineNeeded = Math.max(idealCharsPerLine, longestWord);
2054
+ const width = Math.min(MESSAGE_MAX_WIDTH, Math.max(MESSAGE_NODE_WIDTH, MESSAGE_HORIZONTAL_PADDING + charsPerLineNeeded * MESSAGE_CHAR_WIDTH));
2055
+ const lines = estimateLines(words, Math.max(1, Math.floor((width - MESSAGE_HORIZONTAL_PADDING) / MESSAGE_CHAR_WIDTH)));
2056
+ return {
2057
+ width,
2058
+ height: Math.max(MESSAGE_NODE_HEIGHT, lines * MESSAGE_LINE_HEIGHT + MESSAGE_VERTICAL_PADDING)
2059
+ };
2060
+ }
2061
+ const ARROW_TOKENS = [
2062
+ {
2063
+ token: "<<-->>",
2064
+ lineStyle: "dashed",
2065
+ arrowType: "bidirectional"
2066
+ },
2067
+ {
2068
+ token: "<<->>",
2069
+ lineStyle: "solid",
2070
+ arrowType: "bidirectional"
2071
+ },
2072
+ {
2073
+ token: "--|\\",
2074
+ lineStyle: "dashed",
2075
+ arrowType: "half",
2076
+ half: "top"
2077
+ },
2078
+ {
2079
+ token: "-|\\",
2080
+ lineStyle: "solid",
2081
+ arrowType: "half",
2082
+ half: "top"
2083
+ },
2084
+ {
2085
+ token: "--|/",
2086
+ lineStyle: "dashed",
2087
+ arrowType: "half",
2088
+ half: "bottom"
2089
+ },
2090
+ {
2091
+ token: "-|/",
2092
+ lineStyle: "solid",
2093
+ arrowType: "half",
2094
+ half: "bottom"
2095
+ },
2096
+ {
2097
+ token: "/|--",
2098
+ lineStyle: "dashed",
2099
+ arrowType: "half",
2100
+ half: "top",
2101
+ reversed: true
2102
+ },
2103
+ {
2104
+ token: "/|-",
2105
+ lineStyle: "solid",
2106
+ arrowType: "half",
2107
+ half: "top",
2108
+ reversed: true
2109
+ },
2110
+ {
2111
+ token: "\\--",
2112
+ lineStyle: "dashed",
2113
+ arrowType: "half",
2114
+ half: "bottom",
2115
+ reversed: true
2116
+ },
2117
+ {
2118
+ token: "\\-",
2119
+ lineStyle: "solid",
2120
+ arrowType: "half",
2121
+ half: "bottom",
2122
+ reversed: true
2123
+ },
2124
+ {
2125
+ token: "//--",
2126
+ lineStyle: "dashed",
2127
+ arrowType: "stick",
2128
+ half: "top",
2129
+ reversed: true
2130
+ },
2131
+ {
2132
+ token: "//-",
2133
+ lineStyle: "solid",
2134
+ arrowType: "stick",
2135
+ half: "top",
2136
+ reversed: true
2137
+ },
2138
+ {
2139
+ token: "--//",
2140
+ lineStyle: "dashed",
2141
+ arrowType: "stick",
2142
+ half: "bottom"
2143
+ },
2144
+ {
2145
+ token: "-//",
2146
+ lineStyle: "solid",
2147
+ arrowType: "stick",
2148
+ half: "bottom"
2149
+ },
2150
+ {
2151
+ token: "--\\",
2152
+ lineStyle: "dashed",
2153
+ arrowType: "stick",
2154
+ half: "top"
2155
+ },
2156
+ {
2157
+ token: "-\\",
2158
+ lineStyle: "solid",
2159
+ arrowType: "stick",
2160
+ half: "top"
2161
+ },
2162
+ {
2163
+ token: "-->>",
2164
+ lineStyle: "dashed",
2165
+ arrowType: "filled"
2166
+ },
2167
+ {
2168
+ token: "->>",
2169
+ lineStyle: "solid",
2170
+ arrowType: "filled"
2171
+ },
2172
+ {
2173
+ token: "--x",
2174
+ lineStyle: "dashed",
2175
+ arrowType: "cross"
2176
+ },
2177
+ {
2178
+ token: "-x",
2179
+ lineStyle: "solid",
2180
+ arrowType: "cross"
2181
+ },
2182
+ {
2183
+ token: "--)",
2184
+ lineStyle: "dashed",
2185
+ arrowType: "open"
2186
+ },
2187
+ {
2188
+ token: "-)",
2189
+ lineStyle: "solid",
2190
+ arrowType: "open"
2191
+ },
2192
+ {
2193
+ token: "-->",
2194
+ lineStyle: "dashed",
2195
+ arrowType: "none"
2196
+ },
2197
+ {
2198
+ token: "->",
2199
+ lineStyle: "solid",
2200
+ arrowType: "none"
2201
+ }
2202
+ ];
2203
+ const BLOCK_OPENERS = [
2204
+ "loop",
2205
+ "alt",
2206
+ "opt",
2207
+ "par",
2208
+ "critical",
2209
+ "break",
2210
+ "rect"
2211
+ ];
2212
+ const SECTION_KEYWORDS = [
2213
+ "else",
2214
+ "and",
2215
+ "option"
2216
+ ];
2217
+ const CSS_COLOR_NAMES = new Set(`transparent aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue
2218
+ blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan
2219
+ darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen
2220
+ darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey
2221
+ darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite
2222
+ forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink
2223
+ indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral
2224
+ lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen
2225
+ lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta
2226
+ maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue
2227
+ mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin
2228
+ navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen
2229
+ paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red
2230
+ rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue
2231
+ slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white
2232
+ whitesmoke yellow yellowgreen`.split(/\s+/).filter(Boolean));
2233
+ const NAMED_ENTITIES = {
2234
+ amp: "&",
2235
+ lt: "<",
2236
+ gt: ">",
2237
+ quot: "\"",
2238
+ apos: "'",
2239
+ nbsp: " "
2240
+ };
2241
+ function decodeSequenceText(raw) {
2242
+ return raw.replace(/<br\s*\/?>/gi, "\n").replace(/&#x([0-9a-f]+);/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16))).replace(/&#(\d+);/g, (_, dec) => String.fromCodePoint(parseInt(dec, 10))).replace(/&([a-z]+);/gi, (match, name) => {
2243
+ const decoded = NAMED_ENTITIES[name.toLowerCase()];
2244
+ if (decoded === void 0) return match;
2245
+ return decoded;
2246
+ }).trim();
2247
+ }
2248
+ function findArrow(line) {
2249
+ for (let i = 0; i < line.length; i++) for (const arrow of ARROW_TOKENS) if (line.startsWith(arrow.token, i)) return {
2250
+ arrow,
2251
+ start: i,
2252
+ end: i + arrow.token.length
2253
+ };
2254
+ }
2255
+ function splitColorAndLabel(rest) {
2256
+ const trimmed = rest.trim();
2257
+ if (!trimmed) return { label: "" };
2258
+ const functional = trimmed.match(/^(rgba?|hsla?)\s*\([^)]*\)/i);
2259
+ if (functional) return {
2260
+ color: functional[0],
2261
+ label: trimmed.slice(functional[0].length).trim()
2262
+ };
2263
+ const [firstWord, ...restWords] = trimmed.split(/\s+/);
2264
+ if (CSS_COLOR_NAMES.has(firstWord.toLowerCase())) return {
2265
+ color: firstWord,
2266
+ label: restWords.join(" ")
2267
+ };
2268
+ return { label: trimmed };
2269
+ }
2270
+ function parseParticipantDeclaration(rest) {
2271
+ const trimmed = rest.trim();
2272
+ const configStart = trimmed.indexOf("@{");
2273
+ let id;
2274
+ let remainder;
2275
+ let type;
2276
+ let inlineAlias;
2277
+ if (configStart === -1) {
2278
+ const asMatch$1 = trimmed.match(/^(.*?)\s+as\s+(.+)$/i);
2279
+ id = (asMatch$1 ? asMatch$1[1] : trimmed).trim();
2280
+ remainder = asMatch$1 ? decodeSequenceText(asMatch$1[2]) : "";
2281
+ return {
2282
+ id,
2283
+ name: remainder || id,
2284
+ alias: remainder || void 0,
2285
+ type
2286
+ };
2287
+ }
2288
+ id = trimmed.slice(0, configStart).trim();
2289
+ const configEnd = trimmed.indexOf("}", configStart);
2290
+ const configText = configEnd === -1 ? "" : trimmed.slice(configStart + 1, configEnd + 1);
2291
+ remainder = configEnd === -1 ? "" : trimmed.slice(configEnd + 1).trim();
2292
+ try {
2293
+ const config = JSON.parse(configText);
2294
+ if (typeof config.type === "string") type = config.type;
2295
+ if (typeof config.alias === "string") inlineAlias = config.alias;
2296
+ } catch (_unused) {}
2297
+ const asMatch = remainder.match(/^as\s+(.+)$/i);
2298
+ const externalAlias = asMatch ? decodeSequenceText(asMatch[1]) : void 0;
2299
+ const alias = externalAlias !== null && externalAlias !== void 0 ? externalAlias : inlineAlias && decodeSequenceText(inlineAlias);
2300
+ return {
2301
+ id,
2302
+ name: alias !== null && alias !== void 0 ? alias : id,
2303
+ alias,
2304
+ type
2305
+ };
2306
+ }
2307
+ function parseSequenceDiagram(code) {
2308
+ const participants = [];
2309
+ const participantMap = /* @__PURE__ */ new Map();
2310
+ const messages = [];
2311
+ const notes = [];
2312
+ const blocks = [];
2313
+ const boxes = [];
2314
+ const activations = [];
2315
+ const openActivations = /* @__PURE__ */ new Map();
2316
+ const blockStack = [];
2317
+ const openStack = [];
2318
+ let openBox;
2319
+ let autonumber;
2320
+ let title;
2321
+ let accTitle;
2322
+ let accDescr;
2323
+ let row = 0;
2324
+ let pendingCreate;
2325
+ function ensureParticipant(id, options = {}) {
2326
+ var _options$name, _options$type;
2327
+ const existing = participantMap.get(id);
2328
+ if (existing) {
2329
+ if (options.alias !== void 0) {
2330
+ existing.alias = options.alias;
2331
+ existing.name = options.alias;
2332
+ }
2333
+ if (options.type !== void 0) existing.type = options.type;
2334
+ return existing;
2335
+ }
2336
+ const participant = {
2337
+ id,
2338
+ name: (_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : id,
2339
+ alias: options.alias,
2340
+ index: participants.length,
2341
+ type: (_options$type = options.type) !== null && _options$type !== void 0 ? _options$type : "participant",
2342
+ links: [],
2343
+ boxId: openBox === null || openBox === void 0 ? void 0 : openBox.id
2344
+ };
2345
+ participants.push(participant);
2346
+ participantMap.set(id, participant);
2347
+ if (openBox) openBox.participants.push(id);
2348
+ return participant;
2349
+ }
2350
+ function activate(id, atRow) {
2351
+ var _openActivations$get;
2352
+ const stack = (_openActivations$get = openActivations.get(id)) !== null && _openActivations$get !== void 0 ? _openActivations$get : [];
2353
+ stack.push(atRow);
2354
+ openActivations.set(id, stack);
2355
+ }
2356
+ function deactivate(id, atRow) {
2357
+ const stack = openActivations.get(id);
2358
+ if (!stack || stack.length === 0) return;
2359
+ const startRow = stack.pop();
2360
+ activations.push({
2361
+ participant: id,
2362
+ startRow,
2363
+ endRow: atRow
2364
+ });
2365
+ }
2366
+ const lines = code.split("\n");
2367
+ for (let index = 0; index < lines.length; index++) {
2368
+ const trimmed = lines[index].replace(/%%.*$/, "").trim();
2369
+ if (!trimmed) continue;
2370
+ if (/^sequencediagram\b/i.test(trimmed)) continue;
2371
+ if (trimmed.match(/^accDescr\s*\{$/i)) {
2372
+ const collected = [];
2373
+ index++;
2374
+ while (index < lines.length && !/^\s*\}\s*$/.test(lines[index])) {
2375
+ collected.push(lines[index].trim());
2376
+ index++;
2377
+ }
2378
+ accDescr = collected.join("\n");
2379
+ continue;
2380
+ }
2381
+ const titleMatch = trimmed.match(/^title\s*:?\s*(.*)$/i);
2382
+ if (titleMatch) {
2383
+ title = decodeSequenceText(titleMatch[1]);
2384
+ continue;
2385
+ }
2386
+ const accTitleMatch = trimmed.match(/^accTitle\s*:\s*(.*)$/i);
2387
+ if (accTitleMatch) {
2388
+ accTitle = decodeSequenceText(accTitleMatch[1]);
2389
+ continue;
2390
+ }
2391
+ const accDescrMatch = trimmed.match(/^accDescr\s*:\s*(.*)$/i);
2392
+ if (accDescrMatch) {
2393
+ accDescr = decodeSequenceText(accDescrMatch[1]);
2394
+ continue;
2395
+ }
2396
+ const autonumberMatch = trimmed.match(/^autonumber(?:\s+(off|[\d.]+))?(?:\s+([\d.]+))?$/i);
2397
+ if (autonumberMatch) {
2398
+ const [, first, second] = autonumberMatch;
2399
+ if ((first === null || first === void 0 ? void 0 : first.toLowerCase()) === "off") {
2400
+ autonumber = void 0;
2401
+ continue;
2402
+ }
2403
+ const start$1 = first === void 0 ? 1 : Number(first);
2404
+ autonumber = {
2405
+ start: start$1,
2406
+ step: second === void 0 ? 1 : Number(second),
2407
+ next: start$1,
2408
+ declaredStart: start$1
2409
+ };
2410
+ continue;
2411
+ }
2412
+ const boxMatch = trimmed.match(/^box\b\s*(.*)$/i);
2413
+ if (boxMatch) {
2414
+ const { color, label: label$1 } = splitColorAndLabel(boxMatch[1]);
2415
+ const box = {
2416
+ id: `box-${boxes.length}`,
2417
+ label: decodeSequenceText(label$1),
2418
+ color,
2419
+ participants: []
2420
+ };
2421
+ boxes.push(box);
2422
+ openBox = box;
2423
+ openStack.push({
2424
+ kind: "box",
2425
+ id: box.id
2426
+ });
2427
+ continue;
2428
+ }
2429
+ if (/^end$/i.test(trimmed)) {
2430
+ const open = openStack.pop();
2431
+ if ((open === null || open === void 0 ? void 0 : open.kind) === "box") {
2432
+ openBox = void 0;
2433
+ continue;
2434
+ }
2435
+ const block = blockStack.pop();
2436
+ if (block) {
2437
+ block.endRow = row - 1;
2438
+ const lastSection = block.sections[block.sections.length - 1];
2439
+ if (lastSection) lastSection.endRow = row - 1;
2440
+ }
2441
+ continue;
2442
+ }
2443
+ const blockOpener = BLOCK_OPENERS.find((keyword) => new RegExp(`^${keyword}\\b`, "i").test(trimmed));
2444
+ if (blockOpener) {
2445
+ const rest = trimmed.slice(blockOpener.length).trim();
2446
+ const { color, label: label$1 } = blockOpener === "rect" ? splitColorAndLabel(rest) : {
2447
+ color: void 0,
2448
+ label: rest
2449
+ };
2450
+ const parent = blockStack[blockStack.length - 1];
2451
+ const block = {
2452
+ id: `block-${blocks.length}`,
2453
+ type: blockOpener,
2454
+ label: decodeSequenceText(label$1),
2455
+ color,
2456
+ sections: [{
2457
+ label: decodeSequenceText(label$1),
2458
+ startRow: row,
2459
+ endRow: row
2460
+ }],
2461
+ startRow: row,
2462
+ endRow: row,
2463
+ depth: blockStack.length,
2464
+ parentId: parent === null || parent === void 0 ? void 0 : parent.id
2465
+ };
2466
+ blocks.push(block);
2467
+ blockStack.push(block);
2468
+ openStack.push({
2469
+ kind: "block",
2470
+ id: block.id
2471
+ });
2472
+ continue;
2473
+ }
2474
+ const sectionKeyword = SECTION_KEYWORDS.find((keyword) => new RegExp(`^${keyword}\\b`, "i").test(trimmed));
2475
+ if (sectionKeyword) {
2476
+ const block = blockStack[blockStack.length - 1];
2477
+ if (block) {
2478
+ const previous = block.sections[block.sections.length - 1];
2479
+ if (previous) previous.endRow = row - 1;
2480
+ block.sections.push({
2481
+ label: decodeSequenceText(trimmed.slice(sectionKeyword.length).trim()),
2482
+ startRow: row,
2483
+ endRow: row
2484
+ });
2485
+ }
2486
+ continue;
2487
+ }
2488
+ const createMatch = trimmed.match(/^create\s+(participant|actor)\s+(.+)$/i);
2489
+ if (createMatch) {
2490
+ pendingCreate = {
2491
+ type: createMatch[1].toLowerCase(),
2492
+ rest: createMatch[2]
2493
+ };
2494
+ continue;
2495
+ }
2496
+ const destroyMatch = trimmed.match(/^destroy\s+(.+)$/i);
2497
+ if (destroyMatch) {
2498
+ const target = ensureParticipant(destroyMatch[1].trim());
2499
+ target.destroyedAtRow = row;
2500
+ continue;
2501
+ }
2502
+ const participantMatch = trimmed.match(/^(participant|actor)\s+(.+)$/i);
2503
+ if (participantMatch) {
2504
+ var _declaration$type;
2505
+ const keyword = participantMatch[1].toLowerCase();
2506
+ const declaration = parseParticipantDeclaration(participantMatch[2]);
2507
+ ensureParticipant(declaration.id, {
2508
+ name: declaration.name,
2509
+ alias: declaration.alias,
2510
+ type: (_declaration$type = declaration.type) !== null && _declaration$type !== void 0 ? _declaration$type : keyword
2511
+ });
2512
+ continue;
2513
+ }
2514
+ const activateMatch = trimmed.match(/^(activate|deactivate)\s+(.+)$/i);
2515
+ if (activateMatch) {
2516
+ const target = ensureParticipant(activateMatch[2].trim());
2517
+ if (activateMatch[1].toLowerCase() === "activate") activate(target.id, row);
2518
+ else deactivate(target.id, row - 1);
2519
+ continue;
2520
+ }
2521
+ const noteMatch = trimmed.match(/^note\s+(right of|left of|over)\s+([^:]+):\s*(.*)$/i);
2522
+ if (noteMatch) {
2523
+ const noteParticipants = noteMatch[2].split(",").map((name) => name.trim()).filter(Boolean);
2524
+ noteParticipants.forEach((name) => ensureParticipant(name));
2525
+ notes.push({
2526
+ placement: noteMatch[1].toLowerCase(),
2527
+ participants: noteParticipants.map((name) => name),
2528
+ text: decodeSequenceText(noteMatch[3]),
2529
+ rowIndex: row
2530
+ });
2531
+ row++;
2532
+ continue;
2533
+ }
2534
+ const linksMatch = trimmed.match(/^links\s+([^:]+):\s*(\{.*\})$/i);
2535
+ if (linksMatch) {
2536
+ const target = ensureParticipant(linksMatch[1].trim());
2537
+ try {
2538
+ const parsed = JSON.parse(linksMatch[2]);
2539
+ for (const [label$1, url] of Object.entries(parsed)) target.links.push({
2540
+ label: label$1,
2541
+ url
2542
+ });
2543
+ } catch (_unused2) {}
2544
+ continue;
2545
+ }
2546
+ const linkMatch = trimmed.match(/^link\s+([^:]+):\s*(.+?)\s*@\s*(\S+)$/i);
2547
+ if (linkMatch) {
2548
+ ensureParticipant(linkMatch[1].trim()).links.push({
2549
+ label: linkMatch[2].trim(),
2550
+ url: linkMatch[3].trim()
2551
+ });
2552
+ continue;
2553
+ }
2554
+ const colonIndex = trimmed.indexOf(":");
2555
+ const arrowMatch = findArrow(colonIndex === -1 ? trimmed : trimmed.slice(0, colonIndex));
2556
+ if (!arrowMatch || colonIndex === -1) continue;
2557
+ const { arrow, start, end } = arrowMatch;
2558
+ let fromRaw = trimmed.slice(0, start).trim();
2559
+ let toRaw = trimmed.slice(end, colonIndex).trim();
2560
+ const label = decodeSequenceText(trimmed.slice(colonIndex + 1));
2561
+ const centralSource = fromRaw.endsWith("()");
2562
+ if (centralSource) fromRaw = fromRaw.slice(0, -2).trim();
2563
+ let activates = false;
2564
+ let deactivates = false;
2565
+ let centralTarget = false;
2566
+ let scanning = true;
2567
+ while (scanning) {
2568
+ scanning = false;
2569
+ if (toRaw.startsWith("+")) {
2570
+ activates = true;
2571
+ toRaw = toRaw.slice(1).trim();
2572
+ scanning = true;
2573
+ }
2574
+ if (toRaw.startsWith("-")) {
2575
+ deactivates = true;
2576
+ toRaw = toRaw.slice(1).trim();
2577
+ scanning = true;
2578
+ }
2579
+ if (toRaw.startsWith("()")) {
2580
+ centralTarget = true;
2581
+ toRaw = toRaw.slice(2).trim();
2582
+ scanning = true;
2583
+ }
2584
+ }
2585
+ if (!fromRaw || !toRaw) continue;
2586
+ ensureParticipant(fromRaw);
2587
+ if (pendingCreate) {
2588
+ var _declaration$type2;
2589
+ const declaration = parseParticipantDeclaration(pendingCreate.rest);
2590
+ const created = ensureParticipant(declaration.id, {
2591
+ name: declaration.name,
2592
+ alias: declaration.alias,
2593
+ type: (_declaration$type2 = declaration.type) !== null && _declaration$type2 !== void 0 ? _declaration$type2 : pendingCreate.type
2594
+ });
2595
+ created.createdAtRow = row;
2596
+ pendingCreate = void 0;
2597
+ toRaw = declaration.id;
2598
+ }
2599
+ const to = ensureParticipant(toRaw);
2600
+ const message = {
2601
+ from: fromRaw,
2602
+ to: to.id,
2603
+ label,
2604
+ lineStyle: arrow.lineStyle,
2605
+ arrowType: arrow.arrowType,
2606
+ rowIndex: row
2607
+ };
2608
+ if (arrow.half) message.half = arrow.half;
2609
+ if (arrow.reversed) message.reversed = true;
2610
+ if (centralSource) message.centralSource = true;
2611
+ if (centralTarget) message.centralTarget = true;
2612
+ if (activates) message.activates = true;
2613
+ if (deactivates) message.deactivates = true;
2614
+ if (autonumber) {
2615
+ message.sequenceNumber = autonumber.next;
2616
+ autonumber.next = Number((autonumber.next + autonumber.step).toFixed(2));
2617
+ }
2618
+ if (activates) activate(to.id, row);
2619
+ if (deactivates) deactivate(fromRaw, row);
2620
+ messages.push(message);
2621
+ row++;
2622
+ }
2623
+ for (const [participant, stack] of openActivations) for (const startRow of stack) activations.push({
2624
+ participant,
2625
+ startRow,
2626
+ endRow: Math.max(row - 1, startRow)
2627
+ });
2628
+ for (const block of blockStack) {
2629
+ block.endRow = row - 1;
2630
+ const lastSection = block.sections[block.sections.length - 1];
2631
+ if (lastSection) lastSection.endRow = row - 1;
2632
+ }
2633
+ activations.sort((a, b) => a.startRow - b.startRow);
2634
+ return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
2635
+ participants,
2636
+ messages,
2637
+ notes,
2638
+ blocks,
2639
+ boxes,
2640
+ activations
2641
+ }, autonumber ? { autonumber: {
2642
+ start: autonumber.declaredStart,
2643
+ step: autonumber.step
2644
+ } } : {}), title === void 0 ? {} : { title }), accTitle === void 0 ? {} : { accTitle }), accDescr === void 0 ? {} : { accDescr });
2645
+ }
2646
+ const BLOCK_STYLES = {
2647
+ loop: {
2648
+ border: "#64748B",
2649
+ background: "rgba(100, 116, 139, 0.06)"
2650
+ },
2651
+ alt: {
2652
+ border: "#6366F1",
2653
+ background: "rgba(99, 102, 241, 0.06)"
2654
+ },
2655
+ opt: {
2656
+ border: "#0EA5E9",
2657
+ background: "rgba(14, 165, 233, 0.06)"
2658
+ },
2659
+ par: {
2660
+ border: "#22C55E",
2661
+ background: "rgba(34, 197, 94, 0.06)"
2662
+ },
2663
+ critical: {
2664
+ border: "#F97316",
2665
+ background: "rgba(249, 115, 22, 0.06)"
2666
+ },
2667
+ break: {
2668
+ border: "#EF4444",
2669
+ background: "rgba(239, 68, 68, 0.06)"
2670
+ },
2671
+ rect: {
2672
+ border: "transparent",
2673
+ background: "rgba(148, 163, 184, 0.10)"
2674
+ }
2675
+ };
2676
+ function participantX(index) {
2677
+ const { COLUMN_WIDTH } = SEQUENCE_LAYOUT;
2678
+ return index * COLUMN_WIDTH + COLUMN_WIDTH / 2;
2679
+ }
2680
+ function rowHandleId(rowIndex, side, handleType) {
2681
+ return `row-${rowIndex}-${side}-${handleType}`;
2682
+ }
2683
+ function buildGrid(data) {
2684
+ const { ROW_HEIGHT, ROW_VERTICAL_PADDING, HEADER_HEIGHT } = SEQUENCE_LAYOUT;
2685
+ const { BLOCK_TOP_PADDING, BLOCK_BOTTOM_PADDING, BLOCK_SECTION_PADDING, BLOCK_FRAME_GAP } = SEQUENCE_LAYOUT;
2686
+ const items = [...data.messages.map((message) => ({
2687
+ kind: "message",
2688
+ parserRow: message.rowIndex,
2689
+ message
2690
+ })), ...data.notes.map((note) => ({
2691
+ kind: "note",
2692
+ parserRow: note.rowIndex,
2693
+ note
2694
+ }))].sort((a, b) => a.parserRow - b.parserRow);
2695
+ const sizes = /* @__PURE__ */ new Map();
2696
+ const layoutRowByParserRow = /* @__PURE__ */ new Map();
2697
+ const rowSpan = /* @__PURE__ */ new Map();
2698
+ let cursor = 0;
2699
+ for (const item of items) {
2700
+ const text = item.kind === "message" ? item.message.label : item.note.text;
2701
+ sizes.set(item.parserRow, estimateSequenceMessageBoxSize(text));
2702
+ layoutRowByParserRow.set(item.parserRow, cursor);
2703
+ const span = item.kind === "message" && item.message.from === item.message.to ? 2 : 1;
2704
+ rowSpan.set(item.parserRow, span);
2705
+ cursor += span;
2706
+ }
2707
+ const totalRows = Math.max(cursor, 1);
2708
+ const rowHeight = Math.max(ROW_HEIGHT, ...[...sizes.values()].map((size) => size.height + ROW_VERTICAL_PADDING));
2709
+ function toLayoutRow(parserRow) {
2710
+ for (let row = parserRow; row < parserRow + items.length + 1; row++) {
2711
+ const layoutRow = layoutRowByParserRow.get(row);
2712
+ if (layoutRow !== void 0) return layoutRow;
2713
+ }
2714
+ return totalRows;
2715
+ }
2716
+ function toLastLayoutRow(parserRow) {
2717
+ for (let row = parserRow; row >= 0; row--) {
2718
+ const layoutRow = layoutRowByParserRow.get(row);
2719
+ if (layoutRow !== void 0) return layoutRow + rowSpan.get(row) - 1;
2720
+ }
2721
+ return 0;
2722
+ }
2723
+ const padBefore = new Array(totalRows + 1).fill(0);
2724
+ const padAfter = new Array(totalRows + 1).fill(0);
2725
+ for (const block of data.blocks) {
2726
+ if (block.endRow < block.startRow) continue;
2727
+ padBefore[toLayoutRow(block.startRow)] += BLOCK_TOP_PADDING + BLOCK_FRAME_GAP;
2728
+ padAfter[toLastLayoutRow(block.endRow)] += BLOCK_BOTTOM_PADDING;
2729
+ for (const section of block.sections.slice(1)) {
2730
+ if (section.endRow < section.startRow) continue;
2731
+ padBefore[toLayoutRow(section.startRow)] += BLOCK_SECTION_PADDING;
2732
+ }
2733
+ }
2734
+ const rowTops = [];
2735
+ let y = HEADER_HEIGHT;
2736
+ for (let row = 0; row < totalRows; row++) {
2737
+ y += padBefore[row];
2738
+ rowTops.push(y);
2739
+ y += rowHeight + padAfter[row];
2740
+ }
2741
+ const contentHeight = y;
2742
+ return {
2743
+ items,
2744
+ sizes,
2745
+ rowHeight,
2746
+ totalRows,
2747
+ rowTops,
2748
+ rowCenters: rowTops.map((top) => top + rowHeight / 2),
2749
+ contentHeight,
2750
+ padBefore,
2751
+ padAfter,
2752
+ toLayoutRow,
2753
+ toLastLayoutRow,
2754
+ layoutRowByParserRow
2755
+ };
2756
+ }
2757
+ function messageBoxX(fromIndex, toIndex, width) {
2758
+ const { SELF_LOOP_OFFSET } = SEQUENCE_LAYOUT;
2759
+ if (fromIndex === toIndex) return participantX(fromIndex) + SELF_LOOP_OFFSET;
2760
+ return (participantX(fromIndex) + participantX(toIndex)) / 2 - width / 2;
2761
+ }
2762
+ function noteBox(note, grid, indexById) {
2763
+ const { NOTE_OFFSET, COLUMN_WIDTH } = SEQUENCE_LAYOUT;
2764
+ const indices = note.participants.map((id) => indexById.get(id)).filter((index) => index !== void 0);
2765
+ if (indices.length === 0) return void 0;
2766
+ const size = grid.sizes.get(note.rowIndex);
2767
+ const first = participantX(indices[0]);
2768
+ const last = participantX(indices[indices.length - 1]);
2769
+ if (note.placement === "right of") return {
2770
+ x: first + NOTE_OFFSET,
2771
+ width: size.width
2772
+ };
2773
+ if (note.placement === "left of") return {
2774
+ x: first - NOTE_OFFSET - size.width,
2775
+ width: size.width
2776
+ };
2777
+ if (indices.length > 1) {
2778
+ const width = Math.max(size.width, last - first + COLUMN_WIDTH / 2);
2779
+ return {
2780
+ x: (first + last) / 2 - width / 2,
2781
+ width
2782
+ };
2783
+ }
2784
+ return {
2785
+ x: first - size.width / 2,
2786
+ width: size.width
2787
+ };
2788
+ }
2789
+ function blockFrameNode(block, data, grid, indexById) {
2790
+ if (block.endRow < block.startRow) return void 0;
2791
+ const { BLOCK_SIDE_PADDING, BLOCK_TOP_PADDING, BLOCK_BOTTOM_PADDING, BLOCK_CONTENT_INSET } = SEQUENCE_LAYOUT;
2792
+ const involved = /* @__PURE__ */ new Set();
2793
+ const lefts = [];
2794
+ const rights = [];
2795
+ function boxInset(parserRow) {
2796
+ return BLOCK_CONTENT_INSET * (data.blocks.filter((other) => other.depth > block.depth && other.endRow >= other.startRow && other.startRow <= parserRow && other.endRow >= parserRow).length + 1);
2797
+ }
2798
+ for (const message of data.messages) {
2799
+ if (message.rowIndex < block.startRow || message.rowIndex > block.endRow) continue;
2800
+ const from = indexById.get(message.from);
2801
+ const to = indexById.get(message.to);
2802
+ if (from !== void 0) involved.add(from);
2803
+ if (to !== void 0) involved.add(to);
2804
+ if (from === void 0 || to === void 0) continue;
2805
+ const width$1 = grid.sizes.get(message.rowIndex).width;
2806
+ const x$1 = messageBoxX(from, to, width$1);
2807
+ const inset = boxInset(message.rowIndex);
2808
+ lefts.push(x$1 - inset);
2809
+ rights.push(x$1 + width$1 + inset);
2810
+ }
2811
+ for (const note of data.notes) {
2812
+ if (note.rowIndex < block.startRow || note.rowIndex > block.endRow) continue;
2813
+ note.participants.forEach((id) => {
2814
+ const index = indexById.get(id);
2815
+ if (index !== void 0) involved.add(index);
2816
+ });
2817
+ const box = noteBox(note, grid, indexById);
2818
+ if (box === void 0) continue;
2819
+ const inset = boxInset(note.rowIndex);
2820
+ lefts.push(box.x - inset);
2821
+ rights.push(box.x + box.width + inset);
2822
+ }
2823
+ if (involved.size === 0) data.participants.forEach((p) => involved.add(p.index));
2824
+ const minIndex = Math.min(...involved);
2825
+ const maxIndex = Math.max(...involved);
2826
+ const startRow = grid.toLayoutRow(block.startRow);
2827
+ const endRow = grid.toLastLayoutRow(block.endRow);
2828
+ const sidePadding = Math.max(BLOCK_CONTENT_INSET, BLOCK_SIDE_PADDING - block.depth * BLOCK_CONTENT_INSET);
2829
+ const nested = data.blocks.filter((other) => other.id !== block.id && other.depth > block.depth);
2830
+ const deeperAtTop = nested.filter((other) => other.endRow >= other.startRow && grid.toLayoutRow(other.startRow) === startRow).length;
2831
+ const deeperAtBottom = nested.filter((other) => other.endRow >= other.startRow && grid.toLastLayoutRow(other.endRow) === endRow).length;
2832
+ const x = Math.min(participantX(minIndex) - sidePadding, ...lefts);
2833
+ const width = Math.max(participantX(maxIndex) + sidePadding, ...rights) - x;
2834
+ const top = grid.rowTops[startRow] - BLOCK_TOP_PADDING * (deeperAtTop + 1);
2835
+ const height = grid.rowTops[endRow] + grid.rowHeight + BLOCK_BOTTOM_PADDING * (deeperAtBottom + 1) - top;
2836
+ const style = BLOCK_STYLES[block.type];
2837
+ return {
2838
+ id: `sequence-block-${block.id}`,
2839
+ type: "group",
2840
+ position: {
2841
+ x,
2842
+ y: top
2843
+ },
2844
+ width,
2845
+ height,
2846
+ zIndex: Math.min(-1, -10 + block.depth),
2847
+ selectable: true,
2848
+ data: {
2849
+ source: "mermaid",
2850
+ backgroundColor: style.background,
2851
+ borderColor: style.border,
2852
+ autoLayout: false,
2853
+ sequenceBlock: {
2854
+ type: block.type,
2855
+ label: block.label,
2856
+ color: block.color,
2857
+ depth: block.depth,
2858
+ startRow,
2859
+ endRow,
2860
+ sections: block.sections.map((section) => ({
2861
+ label: section.label,
2862
+ startRow: grid.toLayoutRow(section.startRow),
2863
+ endRow: grid.toLastLayoutRow(section.endRow)
2864
+ }))
2865
+ },
2866
+ componentFields: [generateComponentFieldNameInput(block.label ? `${block.type} ${block.label}` : block.type)]
2867
+ },
2868
+ style: {
2869
+ width,
2870
+ height
2871
+ }
2872
+ };
2873
+ }
2874
+ function noteNode(note, grid, indexById) {
2875
+ const box = noteBox(note, grid, indexById);
2876
+ if (box === void 0) return void 0;
2877
+ const { x, width } = box;
2878
+ const size = grid.sizes.get(note.rowIndex);
2879
+ const row = grid.toLayoutRow(note.rowIndex);
2880
+ return {
2881
+ id: `note-${note.rowIndex}`,
2882
+ type: "shape",
2883
+ position: {
2884
+ x,
2885
+ y: grid.rowCenters[row] - size.height / 2
2886
+ },
2887
+ width,
2888
+ height: size.height,
2889
+ data: {
2890
+ source: "mermaid",
2891
+ shape: "rectangle",
2892
+ fill: "#FEF3C7",
2893
+ stroke: "#F59E0B",
2894
+ strokeWidth: 1,
2895
+ textColor: "#1F2937",
2896
+ sequenceNote: {
2897
+ placement: note.placement,
2898
+ participants: note.participants,
2899
+ row
2900
+ },
2901
+ componentFields: [generateComponentFieldNameInput(note.text)]
2902
+ },
2903
+ style: {
2904
+ width,
2905
+ height: size.height
2906
+ }
2907
+ };
2908
+ }
2909
+ function messageMarkers(message, color) {
2910
+ const arrow = {
2911
+ width: 16,
2912
+ height: 16,
2913
+ color
2914
+ };
2915
+ if (message.arrowType === "none") return {};
2916
+ if (message.arrowType === "filled") return { markerEnd: _objectSpread2({ type: __xyflow_react.MarkerType.ArrowClosed }, arrow) };
2917
+ if (message.arrowType === "bidirectional") return {
2918
+ markerStart: _objectSpread2({ type: __xyflow_react.MarkerType.ArrowClosed }, arrow),
2919
+ markerEnd: _objectSpread2({ type: __xyflow_react.MarkerType.ArrowClosed }, arrow)
2920
+ };
2921
+ if (message.reversed) return { markerStart: _objectSpread2({ type: __xyflow_react.MarkerType.Arrow }, arrow) };
2922
+ return { markerEnd: _objectSpread2({ type: __xyflow_react.MarkerType.Arrow }, arrow) };
2923
+ }
2924
+ function convertSequenceDiagramToReactFlow(mermaidCode) {
2925
+ const data = parseSequenceDiagram(mermaidCode);
2926
+ const { PARTICIPANT_NODE_WIDTH, COLUMN_WIDTH, BOX_TOP_INSET, BOX_BOTTOM_PADDING, BLOCK_SIDE_PADDING } = SEQUENCE_LAYOUT;
2927
+ const grid = buildGrid(data);
2928
+ const indexById = new Map(data.participants.map((p) => [p.id, p.index]));
2929
+ const nodes = [];
2930
+ const edges = [];
2931
+ for (const box of data.boxes) {
2932
+ var _box$color;
2933
+ const indices = box.participants.map((id) => indexById.get(id)).filter((index) => index !== void 0);
2934
+ if (indices.length === 0) continue;
2935
+ const minIndex = Math.min(...indices);
2936
+ const maxIndex = Math.max(...indices);
2937
+ const x = participantX(minIndex) - COLUMN_WIDTH / 2 + 8;
2938
+ const width = participantX(maxIndex) - participantX(minIndex) + COLUMN_WIDTH - 16;
2939
+ nodes.push({
2940
+ id: `sequence-box-${box.id}`,
2941
+ type: "group",
2942
+ position: {
2943
+ x,
2944
+ y: -BOX_TOP_INSET
2945
+ },
2946
+ width,
2947
+ height: grid.contentHeight + BOX_TOP_INSET + BOX_BOTTOM_PADDING,
2948
+ zIndex: -20,
2949
+ data: {
2950
+ source: "mermaid",
2951
+ backgroundColor: (_box$color = box.color) !== null && _box$color !== void 0 ? _box$color : "rgba(148, 163, 184, 0.08)",
2952
+ borderColor: "#94A3B8",
2953
+ autoLayout: false,
2954
+ sequenceBox: {
2955
+ label: box.label,
2956
+ participants: box.participants
2957
+ },
2958
+ componentFields: [generateComponentFieldNameInput(box.label)]
2959
+ },
2960
+ style: {
2961
+ width,
2962
+ height: grid.contentHeight + BOX_TOP_INSET + BOX_BOTTOM_PADDING
2963
+ }
2964
+ });
2965
+ }
2966
+ for (const block of data.blocks) {
2967
+ const node = blockFrameNode(block, data, grid, indexById);
2968
+ if (node) nodes.push(node);
2969
+ }
2970
+ for (const participant of data.participants) {
2971
+ const activations = data.activations.filter((activation) => activation.participant === participant.id).map((activation) => ({
2972
+ startRow: grid.toLayoutRow(activation.startRow),
2973
+ endRow: grid.toLastLayoutRow(activation.endRow)
2974
+ }));
2975
+ nodes.push({
2976
+ id: `participant-${participant.id}`,
2977
+ type: "sequenceParticipant",
2978
+ position: {
2979
+ x: participantX(participant.index) - PARTICIPANT_NODE_WIDTH / 2,
2980
+ y: 0
2981
+ },
2982
+ data: _objectSpread2(_objectSpread2(_objectSpread2({
2983
+ source: "mermaid",
2984
+ label: participant.name,
2985
+ participantType: participant.type,
2986
+ rowCount: grid.totalRows,
2987
+ rowHeight: grid.rowHeight,
2988
+ rowYs: grid.rowCenters,
2989
+ lifelineHeight: grid.contentHeight,
2990
+ activations,
2991
+ links: participant.links
2992
+ }, participant.createdAtRow === void 0 ? {} : { lifelineStartRow: grid.toLayoutRow(participant.createdAtRow) }), participant.destroyedAtRow === void 0 ? {} : { lifelineEndRow: grid.toLastLayoutRow(participant.destroyedAtRow) }), {}, { componentFields: [generateComponentFieldNameInput(participant.name), generateComponentFieldInput({
2993
+ componentFieldId: "color",
2994
+ label: "Color",
2995
+ data: SEQUENCE_PARTICIPANT_COLOR,
2996
+ type: require_component_type.ComponentInputType.ColorPicker
2997
+ })] })
2998
+ });
2999
+ }
3000
+ for (const note of data.notes) {
3001
+ const node = noteNode(note, grid, indexById);
3002
+ if (node) nodes.push(node);
3003
+ }
3004
+ for (const message of data.messages) {
3005
+ const fromIndex = indexById.get(message.from);
3006
+ const toIndex = indexById.get(message.to);
3007
+ if (fromIndex === void 0 || toIndex === void 0) continue;
3008
+ const isSelf = fromIndex === toIndex;
3009
+ const goesRight = fromIndex < toIndex;
3010
+ const size = grid.sizes.get(message.rowIndex);
3011
+ const row = grid.toLayoutRow(message.rowIndex);
3012
+ const x = messageBoxX(fromIndex, toIndex, size.width);
3013
+ const messageId = `message-${message.rowIndex}`;
3014
+ nodes.push({
3015
+ id: messageId,
3016
+ type: "shape",
3017
+ position: {
3018
+ x,
3019
+ y: grid.rowCenters[row] - size.height / 2
3020
+ },
3021
+ width: size.width,
3022
+ height: size.height,
3023
+ data: _objectSpread2(_objectSpread2({
3024
+ source: "mermaid",
3025
+ shape: "rectangle",
3026
+ fill: "#1E293B",
3027
+ stroke: "#475569",
3028
+ strokeWidth: 1
3029
+ }, message.sequenceNumber === void 0 ? {} : { sequenceNumber: message.sequenceNumber }), {}, { componentFields: [generateComponentFieldNameInput(message.label)] }),
3030
+ style: {
3031
+ width: size.width,
3032
+ height: size.height
3033
+ }
3034
+ });
3035
+ const color = "#94a3b8";
3036
+ const edgeStyle = _objectSpread2({
3037
+ stroke: color,
3038
+ strokeWidth: 2
3039
+ }, message.lineStyle === "dashed" ? { strokeDasharray: "4 4" } : {});
3040
+ const sourceSide = goesRight || isSelf ? "right" : "left";
3041
+ const targetSide = isSelf ? "right" : goesRight ? "left" : "right";
3042
+ edges.push(_objectSpread2({
3043
+ id: `edge-${message.rowIndex}-a`,
3044
+ source: `participant-${message.from}`,
3045
+ target: messageId,
3046
+ sourceHandle: rowHandleId(row, sourceSide, "source"),
3047
+ targetHandle: isSelf ? "target-top" : sourceSide === "right" ? "target-left" : "target-right",
3048
+ type: "smoothstep",
3049
+ style: edgeStyle,
3050
+ data: _objectSpread2(_objectSpread2(_objectSpread2({
3051
+ source: "mermaid",
3052
+ arrowType: message.arrowType
3053
+ }, message.half ? { half: message.half } : {}), message.reversed ? { reversed: true } : {}), message.centralSource ? { centralSource: true } : {})
3054
+ }, message.reversed ? messageMarkers(message, color) : {}));
3055
+ edges.push(_objectSpread2({
3056
+ id: `edge-${message.rowIndex}-b`,
3057
+ source: messageId,
3058
+ target: `participant-${message.to}`,
3059
+ sourceHandle: isSelf ? "source-bottom" : goesRight ? "source-right" : "source-left",
3060
+ targetHandle: rowHandleId(row + (isSelf ? 1 : 0), targetSide, "target"),
3061
+ type: "smoothstep",
3062
+ style: edgeStyle,
3063
+ data: _objectSpread2(_objectSpread2({
3064
+ source: "mermaid",
3065
+ arrowType: message.arrowType
3066
+ }, message.half ? { half: message.half } : {}), message.centralTarget ? { centralTarget: true } : {})
3067
+ }, message.reversed ? {} : messageMarkers(message, color)));
3068
+ }
3069
+ if (data.title) nodes.push({
3070
+ id: "sequence-title",
3071
+ type: "text",
3072
+ position: {
3073
+ x: participantX(0) - COLUMN_WIDTH / 2,
3074
+ y: -BOX_TOP_INSET - BLOCK_SIDE_PADDING
3075
+ },
3076
+ data: {
3077
+ source: "mermaid",
3078
+ componentFields: [generateComponentFieldInput({
3079
+ componentFieldId: "text",
3080
+ label: "Text",
3081
+ type: require_component_type.ComponentInputType.TextBox,
3082
+ data: data.title,
3083
+ isReadonly: true
3084
+ })]
3085
+ }
3086
+ });
3087
+ return {
3088
+ nodes,
3089
+ edges
3090
+ };
3091
+ }
2000
3092
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
2001
3093
  try {
2002
3094
  var i = n[a](c), u = i.value;
@@ -2038,70 +3130,6 @@ function detectDiagramType(code) {
2038
3130
  }
2039
3131
  return "flowchart";
2040
3132
  }
2041
- function parseSequenceDiagram(code) {
2042
- const participants = [];
2043
- const messages = [];
2044
- const participantMap = /* @__PURE__ */ new Map();
2045
- const lines = code.split("\n");
2046
- let messageRow = 0;
2047
- for (const line of lines) {
2048
- const trimmed = line.trim();
2049
- if (!trimmed || trimmed.toLowerCase() === "sequencediagram") continue;
2050
- const participantMatch = trimmed.match(/^(?:participant|actor)\s+(\S+)(?:\s+as\s+(.+))?$/i);
2051
- if (participantMatch) {
2052
- var _participantMatch$;
2053
- const id = participantMatch[1];
2054
- const alias = (_participantMatch$ = participantMatch[2]) === null || _participantMatch$ === void 0 ? void 0 : _participantMatch$.trim();
2055
- if (!participantMap.has(id)) {
2056
- const index = participants.length;
2057
- participantMap.set(id, index);
2058
- participants.push({
2059
- id,
2060
- name: alias !== null && alias !== void 0 ? alias : id,
2061
- alias,
2062
- index
2063
- });
2064
- }
2065
- continue;
2066
- }
2067
- const messageMatch = trimmed.match(/^([A-Za-z0-9_]+)\s*(-->>|-->|--\)|->>|->|-\))\s*([A-Za-z0-9_]+)\s*:\s*(.*)$/);
2068
- if (messageMatch) {
2069
- const [, from, arrow, to, label] = messageMatch;
2070
- if (!participantMap.has(from)) {
2071
- const index = participants.length;
2072
- participantMap.set(from, index);
2073
- participants.push({
2074
- id: from,
2075
- name: from,
2076
- index
2077
- });
2078
- }
2079
- if (!participantMap.has(to)) {
2080
- const index = participants.length;
2081
- participantMap.set(to, index);
2082
- participants.push({
2083
- id: to,
2084
- name: to,
2085
- index
2086
- });
2087
- }
2088
- const lineStyle = arrow.startsWith("--") ? "dashed" : "solid";
2089
- const arrowType = arrow.includes(">>") ? "filled" : arrow.includes(")") ? "open" : "none";
2090
- messages.push({
2091
- from,
2092
- to,
2093
- label: label.trim(),
2094
- lineStyle,
2095
- arrowType,
2096
- rowIndex: messageRow++
2097
- });
2098
- }
2099
- }
2100
- return {
2101
- participants,
2102
- messages
2103
- };
2104
- }
2105
3133
  const MERMAID_TO_PORTAL_SHAPE = {
2106
3134
  rect: "rectangle",
2107
3135
  round: "rounded-rect",
@@ -3377,120 +4405,7 @@ function layoutGraph(nodes, edges, subgraphs, direction) {
3377
4405
  adjustParentSizesAfterPositioning(subgraphLayouts, subgraphPositions, processSubgraphsInHierarchicalOrder(subgraphs), direction);
3378
4406
  return createReactFlowElements(nodes, edges, subgraphs, subgraphLayouts, subgraphPositions, standalonePositions, direction);
3379
4407
  }
3380
- function getParticipantX(index) {
3381
- const { COLUMN_WIDTH } = SEQUENCE_LAYOUT;
3382
- return index * COLUMN_WIDTH + COLUMN_WIDTH / 2;
3383
- }
3384
- function getRowY(rowIndex) {
3385
- const { HEADER_HEIGHT, ROW_HEIGHT } = SEQUENCE_LAYOUT;
3386
- return HEADER_HEIGHT + rowIndex * ROW_HEIGHT + ROW_HEIGHT / 2;
3387
- }
3388
- function rowHandleId(rowIndex, side, handleType) {
3389
- return `row-${rowIndex}-${side}-${handleType}`;
3390
- }
3391
- function convertSequenceDiagramToReactFlow(_x2) {
3392
- return _convertSequenceDiagramToReactFlow.apply(this, arguments);
3393
- }
3394
- function _convertSequenceDiagramToReactFlow() {
3395
- _convertSequenceDiagramToReactFlow = _asyncToGenerator(function* (mermaidCode) {
3396
- const { participants, messages } = parseSequenceDiagram(mermaidCode);
3397
- const { PARTICIPANT_NODE_WIDTH, MESSAGE_NODE_WIDTH, MESSAGE_NODE_HEIGHT, SELF_LOOP_OFFSET } = SEQUENCE_LAYOUT;
3398
- const hasSelfLoop = messages.some((m) => m.from === m.to);
3399
- const rowCount = messages.length + (hasSelfLoop ? 1 : 0);
3400
- const nodes = [];
3401
- const edges = [];
3402
- for (const p of participants) nodes.push({
3403
- id: `participant-${p.id}`,
3404
- type: "sequenceParticipant",
3405
- position: {
3406
- x: getParticipantX(p.index) - PARTICIPANT_NODE_WIDTH / 2,
3407
- y: 0
3408
- },
3409
- data: {
3410
- source: "mermaid",
3411
- label: p.name,
3412
- rowCount,
3413
- componentFields: [generateComponentFieldNameInput(p.name), generateComponentFieldInput({
3414
- componentFieldId: "color",
3415
- label: "Color",
3416
- data: "#E2E8F0",
3417
- type: require_component_type.ComponentInputType.ColorPicker
3418
- })]
3419
- }
3420
- });
3421
- for (const m of messages) {
3422
- const fromParticipant = participants.find((p) => p.id === m.from);
3423
- const toParticipant = participants.find((p) => p.id === m.to);
3424
- if (!fromParticipant || !toParticipant) continue;
3425
- const fromIndex = fromParticipant.index;
3426
- const toIndex = toParticipant.index;
3427
- const isSelf = fromIndex === toIndex;
3428
- const goesRight = fromIndex < toIndex;
3429
- const centerX = isSelf ? getParticipantX(fromIndex) + SELF_LOOP_OFFSET : (getParticipantX(fromIndex) + getParticipantX(toIndex)) / 2;
3430
- const messageId = `message-${m.rowIndex}`;
3431
- nodes.push({
3432
- id: messageId,
3433
- type: "shape",
3434
- position: {
3435
- x: centerX - MESSAGE_NODE_WIDTH / 2,
3436
- y: getRowY(m.rowIndex) - MESSAGE_NODE_HEIGHT / 2
3437
- },
3438
- data: {
3439
- source: "mermaid",
3440
- shape: "rectangle",
3441
- fill: "#1E293B",
3442
- stroke: "#475569",
3443
- strokeWidth: 1,
3444
- componentFields: [generateComponentFieldNameInput(m.label)]
3445
- },
3446
- style: {
3447
- width: MESSAGE_NODE_WIDTH,
3448
- height: MESSAGE_NODE_HEIGHT
3449
- }
3450
- });
3451
- const edgeStyle = _objectSpread2({
3452
- stroke: "#94a3b8",
3453
- strokeWidth: 2
3454
- }, m.lineStyle === "dashed" ? { strokeDasharray: "4 4" } : {});
3455
- const markerEnd = m.arrowType !== "none" ? {
3456
- type: m.arrowType === "filled" ? __xyflow_react.MarkerType.ArrowClosed : __xyflow_react.MarkerType.Arrow,
3457
- width: 16,
3458
- height: 16,
3459
- color: "#94a3b8"
3460
- } : void 0;
3461
- const sourceSide = goesRight || isSelf ? "right" : "left";
3462
- const targetSide = isSelf ? "right" : goesRight ? "left" : "right";
3463
- edges.push({
3464
- id: `edge-${m.rowIndex}-a`,
3465
- source: `participant-${m.from}`,
3466
- target: messageId,
3467
- sourceHandle: rowHandleId(m.rowIndex, sourceSide, "source"),
3468
- targetHandle: isSelf ? "target-top" : sourceSide === "right" ? "target-left" : "target-right",
3469
- type: "smoothstep",
3470
- style: edgeStyle,
3471
- data: { source: "mermaid" }
3472
- });
3473
- edges.push(_objectSpread2(_objectSpread2({
3474
- id: `edge-${m.rowIndex}-b`,
3475
- source: messageId,
3476
- target: `participant-${m.to}`,
3477
- sourceHandle: isSelf ? "source-bottom" : goesRight ? "source-right" : "source-left",
3478
- targetHandle: rowHandleId(m.rowIndex + (isSelf ? 1 : 0), targetSide, "target"),
3479
- type: "smoothstep",
3480
- style: m.lineStyle === "dashed" ? edgeStyle : {
3481
- stroke: "#94a3b8",
3482
- strokeWidth: 2
3483
- }
3484
- }, markerEnd ? { markerEnd } : {}), {}, { data: { source: "mermaid" } }));
3485
- }
3486
- return {
3487
- nodes,
3488
- edges
3489
- };
3490
- });
3491
- return _convertSequenceDiagramToReactFlow.apply(this, arguments);
3492
- }
3493
- function convertFlowchartToReactFlow(_x3) {
4408
+ function convertFlowchartToReactFlow(_x2) {
3494
4409
  return _convertFlowchartToReactFlow.apply(this, arguments);
3495
4410
  }
3496
4411
  function _convertFlowchartToReactFlow() {
@@ -3514,7 +4429,7 @@ function _convertFlowchartToReactFlow() {
3514
4429
  });
3515
4430
  return _convertFlowchartToReactFlow.apply(this, arguments);
3516
4431
  }
3517
- function convertMermaidToReactFlow(_x4) {
4432
+ function convertMermaidToReactFlow(_x3) {
3518
4433
  return _convertMermaidToReactFlow.apply(this, arguments);
3519
4434
  }
3520
4435
  function _convertMermaidToReactFlow() {
@@ -4635,6 +5550,8 @@ exports.MongoIndexSchema = MongoIndexSchema;
4635
5550
  exports.MongoNestedFieldSchema = MongoNestedFieldSchema;
4636
5551
  exports.NestedFieldSchema = NestedFieldSchema;
4637
5552
  exports.NoSqlFieldSchema = NoSqlFieldSchema;
5553
+ exports.SEQUENCE_LAYOUT = SEQUENCE_LAYOUT;
5554
+ exports.SEQUENCE_PARTICIPANT_COLOR = SEQUENCE_PARTICIPANT_COLOR;
4638
5555
  exports.SqlToAstParser = SqlToAstParser;
4639
5556
  exports.buildMetaData = buildMetaData;
4640
5557
  exports.contextSchema = require_headless.contextSchema;
@@ -4645,6 +5562,7 @@ exports.convertMermaidToReactFlowWithContext = convertMermaidToReactFlowWithCont
4645
5562
  exports.convertMongoSchemaToAst = convertMongoSchemaToAst;
4646
5563
  exports.convertNoSQLToAst = convertNoSQLToAst;
4647
5564
  exports.convertUiGraphToMermaid = convertUiGraphToMermaid;
5565
+ exports.estimateSequenceMessageBoxSize = estimateSequenceMessageBoxSize;
4648
5566
  exports.flattenMetaData = flattenMetaData;
4649
5567
  exports.generateTableNodeId = generateTableNodeId;
4650
5568
  exports.generateUUID = generateUUID;