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