@uigraph/sdk 1.2.4 → 1.2.5
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/{__headless.BLqB7VsJ.d.mts → __headless.CnrU6aAA.d.mts} +1 -0
- package/dist/{__headless.DfSqiw4X.d.cts → __headless.D9VUj46t.d.cts} +1 -0
- package/dist/{__headless.DGmyg-me.cjs → __headless.DbTnxFi3.cjs} +1 -0
- package/dist/{__headless.DpdtlCFx.mjs → __headless.bq_YVz7q.mjs} +1 -0
- package/dist/{__index.Bvdu5Kox.d.mts → __index.BQQp_uAt.d.mts} +119 -1
- package/dist/{__index.YhKZQgFP.d.cts → __index.BVDt3Nmx.d.cts} +119 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.mts +1 -1
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.cts +1 -1
- package/dist/headless.d.mts +1 -1
- package/dist/headless.mjs +1 -1
- package/dist/index.cjs +863 -87
- package/dist/index.d.cts +97 -5
- package/dist/index.d.mts +97 -5
- package/dist/index.mjs +856 -86
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as ComponentInputType } from "./__component-type.CYmD-KIu.mjs";
|
|
2
|
-
import { t as contextSchema } from "./__headless.
|
|
2
|
+
import { t as contextSchema } from "./__headless.bq_YVz7q.mjs";
|
|
3
3
|
import { arrayNonNullable, generateUUID as generateUUID$1, objectPick } from "daily-code";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { MarkerType, Position } from "@xyflow/react";
|
|
6
|
+
import markdownToDelta from "markdown-to-quill-delta";
|
|
6
7
|
import dagre from "dagre";
|
|
7
8
|
import mermaid from "mermaid";
|
|
8
|
-
import markdownToDelta from "markdown-to-quill-delta";
|
|
9
9
|
function mapDynamoTypeToAstType(dynamoType) {
|
|
10
10
|
switch (dynamoType) {
|
|
11
11
|
case "S": return "string";
|
|
@@ -1773,76 +1773,433 @@ function syncBaseData(prev, next, options) {
|
|
|
1773
1773
|
}
|
|
1774
1774
|
return updated;
|
|
1775
1775
|
}
|
|
1776
|
-
const
|
|
1777
|
-
|
|
1778
|
-
|
|
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
|
|
1776
|
+
const DEFAULT_C4_LAYOUT = {
|
|
1777
|
+
c4ShapeInRow: 4,
|
|
1778
|
+
c4BoundaryInRow: 2
|
|
1790
1779
|
};
|
|
1791
|
-
({
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
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
|
|
1780
|
+
function buildStereotype(keyword) {
|
|
1781
|
+
const suffix = keyword.shape === "db" ? "_db" : keyword.shape === "queue" ? "_queue" : "";
|
|
1782
|
+
return `${keyword.isExternal ? "external_" : ""}${keyword.kind}${suffix}`;
|
|
1783
|
+
}
|
|
1784
|
+
const C4_DIAGRAM_TYPES = [
|
|
1785
|
+
"C4Context",
|
|
1786
|
+
"C4Container",
|
|
1787
|
+
"C4Component",
|
|
1788
|
+
"C4Dynamic",
|
|
1789
|
+
"C4Deployment"
|
|
1790
|
+
];
|
|
1791
|
+
const ELEMENT_KINDS = {
|
|
1792
|
+
Person: "person",
|
|
1793
|
+
System: "system",
|
|
1794
|
+
Container: "container",
|
|
1795
|
+
Component: "component"
|
|
1821
1796
|
};
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1797
|
+
const BOUNDARY_KEYWORDS = {
|
|
1798
|
+
Boundary: { kind: "generic" },
|
|
1799
|
+
Enterprise_Boundary: {
|
|
1800
|
+
kind: "enterprise",
|
|
1801
|
+
fixedType: "ENTERPRISE"
|
|
1802
|
+
},
|
|
1803
|
+
System_Boundary: {
|
|
1804
|
+
kind: "system",
|
|
1805
|
+
fixedType: "SYSTEM"
|
|
1806
|
+
},
|
|
1807
|
+
Container_Boundary: {
|
|
1808
|
+
kind: "container",
|
|
1809
|
+
fixedType: "CONTAINER"
|
|
1810
|
+
},
|
|
1811
|
+
Deployment_Node: {
|
|
1812
|
+
kind: "node",
|
|
1813
|
+
nodeType: "node"
|
|
1814
|
+
},
|
|
1815
|
+
Node: {
|
|
1816
|
+
kind: "node",
|
|
1817
|
+
nodeType: "node"
|
|
1818
|
+
},
|
|
1819
|
+
Node_L: {
|
|
1820
|
+
kind: "node",
|
|
1821
|
+
nodeType: "nodeL"
|
|
1822
|
+
},
|
|
1823
|
+
Node_R: {
|
|
1824
|
+
kind: "node",
|
|
1825
|
+
nodeType: "nodeR"
|
|
1841
1826
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1827
|
+
};
|
|
1828
|
+
const REL_DIRECTIONS = {
|
|
1829
|
+
Rel: "default",
|
|
1830
|
+
RelIndex: "default",
|
|
1831
|
+
BiRel: "bi",
|
|
1832
|
+
Rel_Back: "back",
|
|
1833
|
+
Rel_U: "up",
|
|
1834
|
+
Rel_Up: "up",
|
|
1835
|
+
Rel_D: "down",
|
|
1836
|
+
Rel_Down: "down",
|
|
1837
|
+
Rel_L: "left",
|
|
1838
|
+
Rel_Left: "left",
|
|
1839
|
+
Rel_R: "right",
|
|
1840
|
+
Rel_Right: "right",
|
|
1841
|
+
Rel_Neighbor: "default",
|
|
1842
|
+
BiRel_Neighbor: "bi"
|
|
1843
|
+
};
|
|
1844
|
+
const DIRECTIONS = [
|
|
1845
|
+
"TB",
|
|
1846
|
+
"BT",
|
|
1847
|
+
"LR",
|
|
1848
|
+
"RL"
|
|
1849
|
+
];
|
|
1850
|
+
function parseElementKeyword(keyword) {
|
|
1851
|
+
let rest = keyword;
|
|
1852
|
+
let isExternal = false;
|
|
1853
|
+
if (rest.endsWith("_Ext")) {
|
|
1854
|
+
isExternal = true;
|
|
1855
|
+
rest = rest.slice(0, -4);
|
|
1856
|
+
}
|
|
1857
|
+
let shape = "default";
|
|
1858
|
+
if (rest.endsWith("Db")) {
|
|
1859
|
+
shape = "db";
|
|
1860
|
+
rest = rest.slice(0, -2);
|
|
1861
|
+
} else if (rest.endsWith("Queue")) {
|
|
1862
|
+
shape = "queue";
|
|
1863
|
+
rest = rest.slice(0, -5);
|
|
1864
|
+
}
|
|
1865
|
+
const kind = ELEMENT_KINDS[rest];
|
|
1866
|
+
if (!kind) return null;
|
|
1867
|
+
return {
|
|
1868
|
+
kind,
|
|
1869
|
+
shape,
|
|
1870
|
+
isExternal
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
function splitArguments(raw) {
|
|
1874
|
+
if (!raw.trim()) return [];
|
|
1875
|
+
const args = [];
|
|
1876
|
+
let current = "";
|
|
1877
|
+
let inQuotes = false;
|
|
1878
|
+
let depth = 0;
|
|
1879
|
+
for (let i = 0; i < raw.length; i++) {
|
|
1880
|
+
const char = raw[i];
|
|
1881
|
+
if (char === "\"" && raw[i - 1] !== "\\") {
|
|
1882
|
+
inQuotes = !inQuotes;
|
|
1883
|
+
current += char;
|
|
1884
|
+
continue;
|
|
1885
|
+
}
|
|
1886
|
+
if (!inQuotes && (char === "(" || char === "[")) depth++;
|
|
1887
|
+
if (!inQuotes && (char === ")" || char === "]")) depth--;
|
|
1888
|
+
if (char === "," && !inQuotes && depth === 0) {
|
|
1889
|
+
args.push(current.trim());
|
|
1890
|
+
current = "";
|
|
1891
|
+
continue;
|
|
1892
|
+
}
|
|
1893
|
+
current += char;
|
|
1894
|
+
}
|
|
1895
|
+
args.push(current.trim());
|
|
1896
|
+
return args;
|
|
1897
|
+
}
|
|
1898
|
+
function unquote(value) {
|
|
1899
|
+
const trimmed = value.trim();
|
|
1900
|
+
if (trimmed.startsWith("\"") && trimmed.endsWith("\"") && trimmed.length >= 2) return trimmed.slice(1, -1).replace(/\\"/g, "\"").replace(/<br\s*\/?>/gi, "\n").trim();
|
|
1901
|
+
return trimmed.replace(/<br\s*\/?>/gi, "\n");
|
|
1902
|
+
}
|
|
1903
|
+
function partitionArguments(args) {
|
|
1904
|
+
const positional = [];
|
|
1905
|
+
const named = {};
|
|
1906
|
+
for (const arg of args) {
|
|
1907
|
+
const match = arg.match(/^\$([A-Za-z0-9_]+)\s*=\s*([\s\S]*)$/);
|
|
1908
|
+
if (match) {
|
|
1909
|
+
named[match[1]] = unquote(match[2]);
|
|
1910
|
+
continue;
|
|
1911
|
+
}
|
|
1912
|
+
positional.push(unquote(arg));
|
|
1913
|
+
}
|
|
1914
|
+
return {
|
|
1915
|
+
positional,
|
|
1916
|
+
named
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
function slot(positional, index) {
|
|
1920
|
+
const value = positional[index];
|
|
1921
|
+
if (value === void 0) return void 0;
|
|
1922
|
+
if (value === "") return void 0;
|
|
1923
|
+
return value;
|
|
1924
|
+
}
|
|
1925
|
+
function isC4Diagram(code) {
|
|
1926
|
+
for (const line of code.split("\n")) {
|
|
1927
|
+
const trimmed = line.trim();
|
|
1928
|
+
if (!trimmed || trimmed.startsWith("%%")) continue;
|
|
1929
|
+
return C4_DIAGRAM_TYPES.some((type) => trimmed.toLowerCase().startsWith(type.toLowerCase()));
|
|
1930
|
+
}
|
|
1931
|
+
return false;
|
|
1932
|
+
}
|
|
1933
|
+
function toStatements(code) {
|
|
1934
|
+
const statements = [];
|
|
1935
|
+
let buffer = "";
|
|
1936
|
+
let depth = 0;
|
|
1937
|
+
for (const rawLine of code.split("\n")) {
|
|
1938
|
+
const line = rawLine.replace(/%%.*$/, "").trim();
|
|
1939
|
+
if (!line) continue;
|
|
1940
|
+
buffer = buffer ? `${buffer} ${line}` : line;
|
|
1941
|
+
let inQuotes = false;
|
|
1942
|
+
for (let i = 0; i < line.length; i++) {
|
|
1943
|
+
const char = line[i];
|
|
1944
|
+
if (char === "\"" && line[i - 1] !== "\\") inQuotes = !inQuotes;
|
|
1945
|
+
if (inQuotes) continue;
|
|
1946
|
+
if (char === "(") depth++;
|
|
1947
|
+
if (char === ")") depth--;
|
|
1948
|
+
}
|
|
1949
|
+
if (depth > 0) continue;
|
|
1950
|
+
depth = 0;
|
|
1951
|
+
statements.push(...splitOnBraces(buffer));
|
|
1952
|
+
buffer = "";
|
|
1953
|
+
}
|
|
1954
|
+
if (buffer) statements.push(...splitOnBraces(buffer));
|
|
1955
|
+
return statements;
|
|
1956
|
+
}
|
|
1957
|
+
function splitOnBraces(buffer) {
|
|
1958
|
+
const statements = [];
|
|
1959
|
+
let current = "";
|
|
1960
|
+
let inQuotes = false;
|
|
1961
|
+
let depth = 0;
|
|
1962
|
+
function flush() {
|
|
1963
|
+
if (current.trim()) statements.push(current.trim());
|
|
1964
|
+
current = "";
|
|
1965
|
+
}
|
|
1966
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
1967
|
+
const char = buffer[i];
|
|
1968
|
+
if (char === "\"" && buffer[i - 1] !== "\\") inQuotes = !inQuotes;
|
|
1969
|
+
if (!inQuotes && char === "(") depth++;
|
|
1970
|
+
if (!inQuotes && char === ")") depth--;
|
|
1971
|
+
if (!inQuotes && depth === 0 && char === "{") {
|
|
1972
|
+
current += char;
|
|
1973
|
+
flush();
|
|
1974
|
+
continue;
|
|
1975
|
+
}
|
|
1976
|
+
if (!inQuotes && depth === 0 && char === "}") {
|
|
1977
|
+
flush();
|
|
1978
|
+
statements.push("}");
|
|
1979
|
+
continue;
|
|
1980
|
+
}
|
|
1981
|
+
current += char;
|
|
1982
|
+
}
|
|
1983
|
+
flush();
|
|
1984
|
+
return statements;
|
|
1985
|
+
}
|
|
1986
|
+
function parseC4Diagram(code) {
|
|
1987
|
+
const elements = [];
|
|
1988
|
+
const boundaries = [];
|
|
1989
|
+
const relationships = [];
|
|
1990
|
+
const elementStyles = {};
|
|
1991
|
+
const boundaryStyles = {};
|
|
1992
|
+
const relStyles = {};
|
|
1993
|
+
const layout = _objectSpread2({}, DEFAULT_C4_LAYOUT);
|
|
1994
|
+
let type = "C4Context";
|
|
1995
|
+
let title;
|
|
1996
|
+
let accTitle;
|
|
1997
|
+
let accDescription;
|
|
1998
|
+
let direction;
|
|
1999
|
+
const boundaryStack = [];
|
|
2000
|
+
let anonymousBoundaryCount = 0;
|
|
2001
|
+
let accDescrLines;
|
|
2002
|
+
function currentParentId() {
|
|
2003
|
+
return boundaryStack[boundaryStack.length - 1];
|
|
2004
|
+
}
|
|
2005
|
+
function registerChild(childId) {
|
|
2006
|
+
const parentId = currentParentId();
|
|
2007
|
+
if (!parentId) return;
|
|
2008
|
+
const parent = boundaries.find((boundary) => boundary.id === parentId);
|
|
2009
|
+
if (!parent) return;
|
|
2010
|
+
if (parent.childIds.includes(childId)) return;
|
|
2011
|
+
parent.childIds.push(childId);
|
|
2012
|
+
}
|
|
2013
|
+
for (const statement of toStatements(code)) {
|
|
2014
|
+
if (accDescrLines) {
|
|
2015
|
+
if (statement === "}") {
|
|
2016
|
+
accDescription = accDescrLines.join("\n").trim();
|
|
2017
|
+
accDescrLines = void 0;
|
|
2018
|
+
continue;
|
|
2019
|
+
}
|
|
2020
|
+
accDescrLines.push(statement);
|
|
2021
|
+
continue;
|
|
2022
|
+
}
|
|
2023
|
+
const detectedType = C4_DIAGRAM_TYPES.find((candidate) => statement.toLowerCase().startsWith(candidate.toLowerCase()));
|
|
2024
|
+
if (detectedType) {
|
|
2025
|
+
type = detectedType;
|
|
2026
|
+
continue;
|
|
2027
|
+
}
|
|
2028
|
+
if (statement === "}") {
|
|
2029
|
+
boundaryStack.pop();
|
|
2030
|
+
continue;
|
|
2031
|
+
}
|
|
2032
|
+
const directionMatch = statement.match(/^direction\s+(TB|BT|LR|RL)$/i);
|
|
2033
|
+
if (directionMatch) {
|
|
2034
|
+
direction = DIRECTIONS.find((candidate) => candidate === directionMatch[1].toUpperCase());
|
|
2035
|
+
continue;
|
|
2036
|
+
}
|
|
2037
|
+
const accTitleMatch = statement.match(/^accTitle\s*:\s*(.*)$/i);
|
|
2038
|
+
if (accTitleMatch) {
|
|
2039
|
+
accTitle = unquote(accTitleMatch[1]);
|
|
2040
|
+
continue;
|
|
2041
|
+
}
|
|
2042
|
+
if (/^accDescr\s*\{$/i.test(statement)) {
|
|
2043
|
+
accDescrLines = [];
|
|
2044
|
+
continue;
|
|
2045
|
+
}
|
|
2046
|
+
const accDescrMatch = statement.match(/^accDescr\s*:\s*(.*)$/i);
|
|
2047
|
+
if (accDescrMatch) {
|
|
2048
|
+
accDescription = unquote(accDescrMatch[1]);
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
const titleMatch = statement.match(/^title\s+(.*)$/i);
|
|
2052
|
+
if (titleMatch) {
|
|
2053
|
+
title = unquote(titleMatch[1]);
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
const callMatch = statement.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)\s*(\{)?\s*$/);
|
|
2057
|
+
if (!callMatch) continue;
|
|
2058
|
+
const [, keyword, rawArgs, openBrace] = callMatch;
|
|
2059
|
+
const { positional, named } = partitionArguments(splitArguments(rawArgs));
|
|
2060
|
+
if (keyword === "UpdateLayoutConfig") {
|
|
2061
|
+
var _named$c4ShapeInRow, _named$c4BoundaryInRo;
|
|
2062
|
+
const inRow = (_named$c4ShapeInRow = named.c4ShapeInRow) !== null && _named$c4ShapeInRow !== void 0 ? _named$c4ShapeInRow : slot(positional, 0);
|
|
2063
|
+
const boundaryInRow = (_named$c4BoundaryInRo = named.c4BoundaryInRow) !== null && _named$c4BoundaryInRo !== void 0 ? _named$c4BoundaryInRo : slot(positional, 1);
|
|
2064
|
+
if (inRow) layout.c4ShapeInRow = Number(inRow) || layout.c4ShapeInRow;
|
|
2065
|
+
if (boundaryInRow) layout.c4BoundaryInRow = Number(boundaryInRow) || layout.c4BoundaryInRow;
|
|
2066
|
+
continue;
|
|
2067
|
+
}
|
|
2068
|
+
if (keyword === "UpdateElementStyle" || keyword === "UpdateBoundaryStyle") {
|
|
2069
|
+
var _named$shadowing, _named$bgColor, _named$fontColor, _named$borderColor, _named$shape, _named$sprite, _named$techn, _named$legendText, _named$legendSprite;
|
|
2070
|
+
const target = slot(positional, 0);
|
|
2071
|
+
if (!target) continue;
|
|
2072
|
+
const shadowing = (_named$shadowing = named.shadowing) !== null && _named$shadowing !== void 0 ? _named$shadowing : slot(positional, 4);
|
|
2073
|
+
const style = {
|
|
2074
|
+
bgColor: (_named$bgColor = named.bgColor) !== null && _named$bgColor !== void 0 ? _named$bgColor : slot(positional, 1),
|
|
2075
|
+
fontColor: (_named$fontColor = named.fontColor) !== null && _named$fontColor !== void 0 ? _named$fontColor : slot(positional, 2),
|
|
2076
|
+
borderColor: (_named$borderColor = named.borderColor) !== null && _named$borderColor !== void 0 ? _named$borderColor : slot(positional, 3),
|
|
2077
|
+
shadowing: shadowing === void 0 ? void 0 : shadowing === "true",
|
|
2078
|
+
shape: (_named$shape = named.shape) !== null && _named$shape !== void 0 ? _named$shape : slot(positional, 5),
|
|
2079
|
+
sprite: (_named$sprite = named.sprite) !== null && _named$sprite !== void 0 ? _named$sprite : slot(positional, 6),
|
|
2080
|
+
techn: (_named$techn = named.techn) !== null && _named$techn !== void 0 ? _named$techn : slot(positional, 7),
|
|
2081
|
+
legendText: (_named$legendText = named.legendText) !== null && _named$legendText !== void 0 ? _named$legendText : slot(positional, 8),
|
|
2082
|
+
legendSprite: (_named$legendSprite = named.legendSprite) !== null && _named$legendSprite !== void 0 ? _named$legendSprite : slot(positional, 9)
|
|
2083
|
+
};
|
|
2084
|
+
if (keyword === "UpdateBoundaryStyle") boundaryStyles[target] = style;
|
|
2085
|
+
else elementStyles[target] = style;
|
|
2086
|
+
continue;
|
|
2087
|
+
}
|
|
2088
|
+
if (keyword === "UpdateRelStyle") {
|
|
2089
|
+
var _named$offsetX, _named$offsetY, _named$textColor, _named$lineColor;
|
|
2090
|
+
const from = slot(positional, 0);
|
|
2091
|
+
const to = slot(positional, 1);
|
|
2092
|
+
if (!from || !to) continue;
|
|
2093
|
+
const offsetX = (_named$offsetX = named.offsetX) !== null && _named$offsetX !== void 0 ? _named$offsetX : slot(positional, 4);
|
|
2094
|
+
const offsetY = (_named$offsetY = named.offsetY) !== null && _named$offsetY !== void 0 ? _named$offsetY : slot(positional, 5);
|
|
2095
|
+
const lineWidth = named.lineWidth;
|
|
2096
|
+
relStyles[`${from}->${to}`] = {
|
|
2097
|
+
textColor: (_named$textColor = named.textColor) !== null && _named$textColor !== void 0 ? _named$textColor : slot(positional, 2),
|
|
2098
|
+
lineColor: (_named$lineColor = named.lineColor) !== null && _named$lineColor !== void 0 ? _named$lineColor : slot(positional, 3),
|
|
2099
|
+
offsetX: offsetX === void 0 ? void 0 : Number(offsetX),
|
|
2100
|
+
offsetY: offsetY === void 0 ? void 0 : Number(offsetY),
|
|
2101
|
+
lineWidth: lineWidth === void 0 ? void 0 : Number(lineWidth),
|
|
2102
|
+
lineStyle: named.lineStyle
|
|
2103
|
+
};
|
|
2104
|
+
continue;
|
|
2105
|
+
}
|
|
2106
|
+
if (/^(SHOW_|HIDE_)/.test(keyword)) continue;
|
|
2107
|
+
const boundaryKeyword = BOUNDARY_KEYWORDS[keyword];
|
|
2108
|
+
if (boundaryKeyword) {
|
|
2109
|
+
var _slot, _ref, _ref2, _boundaryKeyword$fixe, _slot2, _named$descr, _named$sprite2, _named$tags;
|
|
2110
|
+
const id = (_slot = slot(positional, 0)) !== null && _slot !== void 0 ? _slot : `boundary-${++anonymousBoundaryCount}`;
|
|
2111
|
+
const isNode = boundaryKeyword.nodeType !== void 0;
|
|
2112
|
+
const defaultType = isNode ? "node" : "system";
|
|
2113
|
+
const boundaryType = (_ref = (_ref2 = (_boundaryKeyword$fixe = boundaryKeyword.fixedType) !== null && _boundaryKeyword$fixe !== void 0 ? _boundaryKeyword$fixe : named.type) !== null && _ref2 !== void 0 ? _ref2 : slot(positional, 2)) !== null && _ref !== void 0 ? _ref : defaultType;
|
|
2114
|
+
const tagsIndex = boundaryKeyword.fixedType ? 2 : isNode ? 5 : 3;
|
|
2115
|
+
const boundary = {
|
|
2116
|
+
id,
|
|
2117
|
+
label: (_slot2 = slot(positional, 1)) !== null && _slot2 !== void 0 ? _slot2 : id,
|
|
2118
|
+
kind: boundaryKeyword.kind,
|
|
2119
|
+
type: boundaryType,
|
|
2120
|
+
description: isNode ? (_named$descr = named.descr) !== null && _named$descr !== void 0 ? _named$descr : slot(positional, 3) : named.descr,
|
|
2121
|
+
nodeType: boundaryKeyword.nodeType,
|
|
2122
|
+
parentId: currentParentId(),
|
|
2123
|
+
childIds: [],
|
|
2124
|
+
sprite: (_named$sprite2 = named.sprite) !== null && _named$sprite2 !== void 0 ? _named$sprite2 : isNode ? slot(positional, 4) : void 0,
|
|
2125
|
+
tags: (_named$tags = named.tags) !== null && _named$tags !== void 0 ? _named$tags : slot(positional, tagsIndex),
|
|
2126
|
+
link: named.link
|
|
2127
|
+
};
|
|
2128
|
+
registerChild(id);
|
|
2129
|
+
const existing = boundaries.findIndex((entry) => entry.id === id);
|
|
2130
|
+
if (existing === -1) boundaries.push(boundary);
|
|
2131
|
+
else boundaries[existing] = _objectSpread2(_objectSpread2({}, boundary), {}, { childIds: boundaries[existing].childIds });
|
|
2132
|
+
if (openBrace) boundaryStack.push(id);
|
|
2133
|
+
continue;
|
|
2134
|
+
}
|
|
2135
|
+
const relDirection = REL_DIRECTIONS[keyword];
|
|
2136
|
+
if (relDirection) {
|
|
2137
|
+
var _slot3, _named$techn2, _named$descr2, _named$sprite3, _named$tags2;
|
|
2138
|
+
const args = keyword === "RelIndex" ? positional.slice(1) : positional;
|
|
2139
|
+
const from = slot(args, 0);
|
|
2140
|
+
const to = slot(args, 1);
|
|
2141
|
+
if (!from || !to) continue;
|
|
2142
|
+
const relationship = {
|
|
2143
|
+
from,
|
|
2144
|
+
to,
|
|
2145
|
+
label: (_slot3 = slot(args, 2)) !== null && _slot3 !== void 0 ? _slot3 : "",
|
|
2146
|
+
technology: (_named$techn2 = named.techn) !== null && _named$techn2 !== void 0 ? _named$techn2 : slot(args, 3),
|
|
2147
|
+
description: (_named$descr2 = named.descr) !== null && _named$descr2 !== void 0 ? _named$descr2 : slot(args, 4),
|
|
2148
|
+
direction: relDirection,
|
|
2149
|
+
index: relationships.length,
|
|
2150
|
+
sprite: (_named$sprite3 = named.sprite) !== null && _named$sprite3 !== void 0 ? _named$sprite3 : slot(args, 5),
|
|
2151
|
+
tags: (_named$tags2 = named.tags) !== null && _named$tags2 !== void 0 ? _named$tags2 : slot(args, 6),
|
|
2152
|
+
link: named.link
|
|
2153
|
+
};
|
|
2154
|
+
const existing = relationships.findIndex((entry) => entry.from === from && entry.to === to);
|
|
2155
|
+
if (existing === -1) relationships.push(relationship);
|
|
2156
|
+
else relationships[existing] = _objectSpread2(_objectSpread2({}, relationship), {}, { index: relationships[existing].index });
|
|
2157
|
+
continue;
|
|
2158
|
+
}
|
|
2159
|
+
const elementKeyword = parseElementKeyword(keyword);
|
|
2160
|
+
if (elementKeyword) {
|
|
2161
|
+
var _slot4, _named$techn3, _named$descr3, _named$sprite4, _named$tags3;
|
|
2162
|
+
const id = slot(positional, 0);
|
|
2163
|
+
if (!id) continue;
|
|
2164
|
+
const hasTechnologySlot = elementKeyword.kind === "container" || elementKeyword.kind === "component";
|
|
2165
|
+
const descrIndex = hasTechnologySlot ? 3 : 2;
|
|
2166
|
+
const link = named.link;
|
|
2167
|
+
const element = {
|
|
2168
|
+
id,
|
|
2169
|
+
label: (_slot4 = slot(positional, 1)) !== null && _slot4 !== void 0 ? _slot4 : id,
|
|
2170
|
+
technology: (_named$techn3 = named.techn) !== null && _named$techn3 !== void 0 ? _named$techn3 : hasTechnologySlot ? slot(positional, 2) : void 0,
|
|
2171
|
+
description: (_named$descr3 = named.descr) !== null && _named$descr3 !== void 0 ? _named$descr3 : slot(positional, descrIndex),
|
|
2172
|
+
kind: elementKeyword.kind,
|
|
2173
|
+
shape: elementKeyword.shape,
|
|
2174
|
+
isExternal: elementKeyword.isExternal,
|
|
2175
|
+
stereotype: buildStereotype(elementKeyword),
|
|
2176
|
+
parentId: currentParentId(),
|
|
2177
|
+
sprite: (_named$sprite4 = named.sprite) !== null && _named$sprite4 !== void 0 ? _named$sprite4 : slot(positional, descrIndex + 1),
|
|
2178
|
+
tags: (_named$tags3 = named.tags) !== null && _named$tags3 !== void 0 ? _named$tags3 : slot(positional, descrIndex + 2),
|
|
2179
|
+
link,
|
|
2180
|
+
subDiagramId: (link === null || link === void 0 ? void 0 : link.startsWith("uig:")) ? link.slice(4) : void 0
|
|
2181
|
+
};
|
|
2182
|
+
registerChild(id);
|
|
2183
|
+
const existing = elements.findIndex((entry) => entry.id === id);
|
|
2184
|
+
if (existing === -1) elements.push(element);
|
|
2185
|
+
else elements[existing] = element;
|
|
2186
|
+
continue;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return {
|
|
2190
|
+
type,
|
|
2191
|
+
title,
|
|
2192
|
+
accTitle,
|
|
2193
|
+
accDescription,
|
|
2194
|
+
direction,
|
|
2195
|
+
elements,
|
|
2196
|
+
boundaries,
|
|
2197
|
+
relationships,
|
|
2198
|
+
elementStyles,
|
|
2199
|
+
boundaryStyles,
|
|
2200
|
+
relStyles,
|
|
2201
|
+
layout
|
|
2202
|
+
};
|
|
1846
2203
|
}
|
|
1847
2204
|
function flattenMetaData(fields, fieldsValues) {
|
|
1848
2205
|
const output = {};
|
|
@@ -1980,6 +2337,422 @@ function getComponentFieldByLabel(fields, label) {
|
|
|
1980
2337
|
return ((_field$label = field.label) === null || _field$label === void 0 ? void 0 : _field$label.toLowerCase()) === label.toLowerCase();
|
|
1981
2338
|
});
|
|
1982
2339
|
}
|
|
2340
|
+
const C4_LAYOUT = {
|
|
2341
|
+
WIDTH: 240,
|
|
2342
|
+
MIN_HEIGHT: 80,
|
|
2343
|
+
SHAPE_MARGIN: 90,
|
|
2344
|
+
ROW_MARGIN: 80,
|
|
2345
|
+
SHAPE_PADDING: 24,
|
|
2346
|
+
BOUNDARY_HEADER: 72,
|
|
2347
|
+
BOUNDARY_PADDING: 48,
|
|
2348
|
+
BOUNDARY_MARGIN: 60,
|
|
2349
|
+
DIAGRAM_MARGIN_X: 60,
|
|
2350
|
+
DIAGRAM_MARGIN_Y: 40
|
|
2351
|
+
};
|
|
2352
|
+
const C4_COLORS = {
|
|
2353
|
+
person: {
|
|
2354
|
+
fill: "#08427B",
|
|
2355
|
+
stroke: "#052E56"
|
|
2356
|
+
},
|
|
2357
|
+
personExternal: {
|
|
2358
|
+
fill: "#686868",
|
|
2359
|
+
stroke: "#4D4D4D"
|
|
2360
|
+
},
|
|
2361
|
+
system: {
|
|
2362
|
+
fill: "#1168BD",
|
|
2363
|
+
stroke: "#0B4884"
|
|
2364
|
+
},
|
|
2365
|
+
systemExternal: {
|
|
2366
|
+
fill: "#999999",
|
|
2367
|
+
stroke: "#6B6B6B"
|
|
2368
|
+
},
|
|
2369
|
+
container: {
|
|
2370
|
+
fill: "#438DD5",
|
|
2371
|
+
stroke: "#2E6295"
|
|
2372
|
+
},
|
|
2373
|
+
containerExternal: {
|
|
2374
|
+
fill: "#B3B3B3",
|
|
2375
|
+
stroke: "#8A8A8A"
|
|
2376
|
+
},
|
|
2377
|
+
component: {
|
|
2378
|
+
fill: "#85BBF0",
|
|
2379
|
+
stroke: "#5D82A8"
|
|
2380
|
+
},
|
|
2381
|
+
componentExternal: {
|
|
2382
|
+
fill: "#CCCCCC",
|
|
2383
|
+
stroke: "#A6A6A6"
|
|
2384
|
+
},
|
|
2385
|
+
node: {
|
|
2386
|
+
fill: "#1F2937",
|
|
2387
|
+
stroke: "#4B5563"
|
|
2388
|
+
},
|
|
2389
|
+
nodeExternal: {
|
|
2390
|
+
fill: "#374151",
|
|
2391
|
+
stroke: "#6B7280"
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
const BOUNDARY_BORDER = "#828DA3";
|
|
2395
|
+
function getC4ElementColors(element) {
|
|
2396
|
+
var _C4_COLORS$key;
|
|
2397
|
+
return (_C4_COLORS$key = C4_COLORS[element.isExternal ? `${element.kind}External` : element.kind]) !== null && _C4_COLORS$key !== void 0 ? _C4_COLORS$key : C4_COLORS.system;
|
|
2398
|
+
}
|
|
2399
|
+
const NAME_LINE_HEIGHT = 22;
|
|
2400
|
+
const SMALL_LINE_HEIGHT = 18;
|
|
2401
|
+
const PERSON_GLYPH = 30;
|
|
2402
|
+
const CYLINDER_LIPS = 34;
|
|
2403
|
+
const QUEUE_CAPS = 68;
|
|
2404
|
+
function wrappedLines(text, usableWidth, charWidth) {
|
|
2405
|
+
if (!text) return 0;
|
|
2406
|
+
const charsPerLine = Math.max(6, Math.floor(usableWidth / charWidth));
|
|
2407
|
+
return text.split("\n").reduce((total, line) => total + Math.max(1, Math.ceil(line.length / charsPerLine)), 0);
|
|
2408
|
+
}
|
|
2409
|
+
function measureElement(element) {
|
|
2410
|
+
let usableWidth = C4_LAYOUT.WIDTH - C4_LAYOUT.SHAPE_PADDING * 2;
|
|
2411
|
+
if (element.shape === "queue") usableWidth -= QUEUE_CAPS;
|
|
2412
|
+
let height = C4_LAYOUT.SHAPE_PADDING * 2;
|
|
2413
|
+
height += SMALL_LINE_HEIGHT;
|
|
2414
|
+
if (element.kind === "person") height += PERSON_GLYPH;
|
|
2415
|
+
height += wrappedLines(element.label, usableWidth, 8.6) * NAME_LINE_HEIGHT;
|
|
2416
|
+
if (element.technology) height += SMALL_LINE_HEIGHT;
|
|
2417
|
+
height += wrappedLines(element.description, usableWidth, 5.9) * SMALL_LINE_HEIGHT;
|
|
2418
|
+
if (element.shape === "db") height += CYLINDER_LIPS;
|
|
2419
|
+
return {
|
|
2420
|
+
width: C4_LAYOUT.WIDTH,
|
|
2421
|
+
height: Math.max(C4_LAYOUT.MIN_HEIGHT, height)
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
function layoutContainer(containerId, data, childrenOf, elementById, placements) {
|
|
2425
|
+
var _childrenOf$get;
|
|
2426
|
+
const childIds = (_childrenOf$get = childrenOf.get(containerId)) !== null && _childrenOf$get !== void 0 ? _childrenOf$get : [];
|
|
2427
|
+
const shapeIds = childIds.filter((id) => elementById.has(id));
|
|
2428
|
+
const boundaryIds = childIds.filter((id) => !elementById.has(id));
|
|
2429
|
+
const originX = containerId ? C4_LAYOUT.BOUNDARY_PADDING : C4_LAYOUT.DIAGRAM_MARGIN_X;
|
|
2430
|
+
const originY = containerId ? C4_LAYOUT.BOUNDARY_HEADER : C4_LAYOUT.DIAGRAM_MARGIN_Y;
|
|
2431
|
+
let cursorY = originY;
|
|
2432
|
+
let maxX = originX;
|
|
2433
|
+
let lastMargin = 0;
|
|
2434
|
+
const perRow = Math.max(1, data.layout.c4ShapeInRow);
|
|
2435
|
+
for (let index = 0; index < shapeIds.length; index += perRow) {
|
|
2436
|
+
const row = shapeIds.slice(index, index + perRow);
|
|
2437
|
+
let rowHeight = 0;
|
|
2438
|
+
row.forEach((id, column) => {
|
|
2439
|
+
const size = measureElement(elementById.get(id));
|
|
2440
|
+
const x = originX + column * (C4_LAYOUT.WIDTH + C4_LAYOUT.SHAPE_MARGIN);
|
|
2441
|
+
placements.set(id, {
|
|
2442
|
+
x,
|
|
2443
|
+
y: cursorY,
|
|
2444
|
+
width: size.width,
|
|
2445
|
+
height: size.height
|
|
2446
|
+
});
|
|
2447
|
+
rowHeight = Math.max(rowHeight, size.height);
|
|
2448
|
+
maxX = Math.max(maxX, x + size.width);
|
|
2449
|
+
});
|
|
2450
|
+
cursorY += rowHeight + C4_LAYOUT.ROW_MARGIN;
|
|
2451
|
+
lastMargin = C4_LAYOUT.ROW_MARGIN;
|
|
2452
|
+
}
|
|
2453
|
+
const boundarySizes = /* @__PURE__ */ new Map();
|
|
2454
|
+
for (const id of boundaryIds) boundarySizes.set(id, layoutContainer(id, data, childrenOf, elementById, placements));
|
|
2455
|
+
const boundariesPerRow = Math.max(1, data.layout.c4BoundaryInRow);
|
|
2456
|
+
for (let index = 0; index < boundaryIds.length; index += boundariesPerRow) {
|
|
2457
|
+
const row = boundaryIds.slice(index, index + boundariesPerRow);
|
|
2458
|
+
let rowHeight = 0;
|
|
2459
|
+
let cursorX = originX;
|
|
2460
|
+
for (const id of row) {
|
|
2461
|
+
const size = boundarySizes.get(id);
|
|
2462
|
+
placements.set(id, {
|
|
2463
|
+
x: cursorX,
|
|
2464
|
+
y: cursorY,
|
|
2465
|
+
width: size.width,
|
|
2466
|
+
height: size.height
|
|
2467
|
+
});
|
|
2468
|
+
cursorX += size.width + C4_LAYOUT.BOUNDARY_MARGIN;
|
|
2469
|
+
rowHeight = Math.max(rowHeight, size.height);
|
|
2470
|
+
maxX = Math.max(maxX, cursorX - C4_LAYOUT.BOUNDARY_MARGIN);
|
|
2471
|
+
}
|
|
2472
|
+
cursorY += rowHeight + C4_LAYOUT.BOUNDARY_MARGIN;
|
|
2473
|
+
lastMargin = C4_LAYOUT.BOUNDARY_MARGIN;
|
|
2474
|
+
}
|
|
2475
|
+
const hasChildren = shapeIds.length > 0 || boundaryIds.length > 0;
|
|
2476
|
+
const trailing = containerId ? C4_LAYOUT.BOUNDARY_PADDING : C4_LAYOUT.DIAGRAM_MARGIN_Y;
|
|
2477
|
+
if (!hasChildren) return {
|
|
2478
|
+
width: C4_LAYOUT.WIDTH + originX + trailing,
|
|
2479
|
+
height: C4_LAYOUT.MIN_HEIGHT + originY + trailing
|
|
2480
|
+
};
|
|
2481
|
+
return {
|
|
2482
|
+
width: maxX + originX,
|
|
2483
|
+
height: cursorY - lastMargin + trailing
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
function resolveSide(direction, from, to) {
|
|
2487
|
+
if (direction === "up") return {
|
|
2488
|
+
source: "top",
|
|
2489
|
+
target: "bottom"
|
|
2490
|
+
};
|
|
2491
|
+
if (direction === "down") return {
|
|
2492
|
+
source: "bottom",
|
|
2493
|
+
target: "top"
|
|
2494
|
+
};
|
|
2495
|
+
if (direction === "left") return {
|
|
2496
|
+
source: "left",
|
|
2497
|
+
target: "right"
|
|
2498
|
+
};
|
|
2499
|
+
if (direction === "right") return {
|
|
2500
|
+
source: "right",
|
|
2501
|
+
target: "left"
|
|
2502
|
+
};
|
|
2503
|
+
const dx = to.x - from.x;
|
|
2504
|
+
const dy = to.y - from.y;
|
|
2505
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
2506
|
+
if (dx >= 0) return {
|
|
2507
|
+
source: "right",
|
|
2508
|
+
target: "left"
|
|
2509
|
+
};
|
|
2510
|
+
return {
|
|
2511
|
+
source: "left",
|
|
2512
|
+
target: "right"
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
if (dy >= 0) return {
|
|
2516
|
+
source: "bottom",
|
|
2517
|
+
target: "top"
|
|
2518
|
+
};
|
|
2519
|
+
return {
|
|
2520
|
+
source: "top",
|
|
2521
|
+
target: "bottom"
|
|
2522
|
+
};
|
|
2523
|
+
}
|
|
2524
|
+
function applyElementStyle(base, style) {
|
|
2525
|
+
var _style$bgColor, _style$borderColor;
|
|
2526
|
+
return {
|
|
2527
|
+
fill: (_style$bgColor = style === null || style === void 0 ? void 0 : style.bgColor) !== null && _style$bgColor !== void 0 ? _style$bgColor : base.fill,
|
|
2528
|
+
stroke: (_style$borderColor = style === null || style === void 0 ? void 0 : style.borderColor) !== null && _style$borderColor !== void 0 ? _style$borderColor : base.stroke,
|
|
2529
|
+
fontColor: style === null || style === void 0 ? void 0 : style.fontColor
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
function convertC4ToReactFlow(data) {
|
|
2533
|
+
const elementById = new Map(data.elements.map((el) => [el.id, el]));
|
|
2534
|
+
const boundaryById = new Map(data.boundaries.map((b) => [b.id, b]));
|
|
2535
|
+
const childrenOf = /* @__PURE__ */ new Map();
|
|
2536
|
+
function attach(id, parentId) {
|
|
2537
|
+
var _childrenOf$get2;
|
|
2538
|
+
const siblings = (_childrenOf$get2 = childrenOf.get(parentId)) !== null && _childrenOf$get2 !== void 0 ? _childrenOf$get2 : [];
|
|
2539
|
+
siblings.push(id);
|
|
2540
|
+
childrenOf.set(parentId, siblings);
|
|
2541
|
+
}
|
|
2542
|
+
for (const boundary of data.boundaries) attach(boundary.id, boundary.parentId);
|
|
2543
|
+
for (const element of data.elements) attach(element.id, element.parentId);
|
|
2544
|
+
const placements = /* @__PURE__ */ new Map();
|
|
2545
|
+
layoutContainer(void 0, data, childrenOf, elementById, placements);
|
|
2546
|
+
const nodes = [];
|
|
2547
|
+
for (const boundary of data.boundaries) {
|
|
2548
|
+
var _data$boundaryStyles$, _style$bgColor2, _style$borderColor2;
|
|
2549
|
+
const placement = placements.get(boundary.id);
|
|
2550
|
+
if (!placement) continue;
|
|
2551
|
+
const style = (_data$boundaryStyles$ = data.boundaryStyles[boundary.id]) !== null && _data$boundaryStyles$ !== void 0 ? _data$boundaryStyles$ : data.elementStyles[boundary.id];
|
|
2552
|
+
nodes.push({
|
|
2553
|
+
id: boundary.id,
|
|
2554
|
+
type: "c4Boundary",
|
|
2555
|
+
position: {
|
|
2556
|
+
x: placement.x,
|
|
2557
|
+
y: placement.y
|
|
2558
|
+
},
|
|
2559
|
+
data: {
|
|
2560
|
+
source: "mermaid",
|
|
2561
|
+
c4BoundaryKind: boundary.kind,
|
|
2562
|
+
boundaryType: boundary.type,
|
|
2563
|
+
description: boundary.description,
|
|
2564
|
+
c4NodeType: boundary.nodeType,
|
|
2565
|
+
link: boundary.link,
|
|
2566
|
+
backgroundColor: (_style$bgColor2 = style === null || style === void 0 ? void 0 : style.bgColor) !== null && _style$bgColor2 !== void 0 ? _style$bgColor2 : "transparent",
|
|
2567
|
+
borderColor: (_style$borderColor2 = style === null || style === void 0 ? void 0 : style.borderColor) !== null && _style$borderColor2 !== void 0 ? _style$borderColor2 : BOUNDARY_BORDER,
|
|
2568
|
+
fontColor: style === null || style === void 0 ? void 0 : style.fontColor,
|
|
2569
|
+
componentFields: [generateComponentFieldNameInput(boundary.label)]
|
|
2570
|
+
},
|
|
2571
|
+
style: {
|
|
2572
|
+
width: placement.width,
|
|
2573
|
+
height: placement.height
|
|
2574
|
+
},
|
|
2575
|
+
width: placement.width,
|
|
2576
|
+
height: placement.height,
|
|
2577
|
+
parentId: boundary.parentId,
|
|
2578
|
+
extent: boundary.parentId ? "parent" : void 0,
|
|
2579
|
+
selectable: true,
|
|
2580
|
+
draggable: true
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
for (const element of data.elements) {
|
|
2584
|
+
const placement = placements.get(element.id);
|
|
2585
|
+
if (!placement) continue;
|
|
2586
|
+
const colors = applyElementStyle(getC4ElementColors(element), data.elementStyles[element.id]);
|
|
2587
|
+
nodes.push({
|
|
2588
|
+
id: element.id,
|
|
2589
|
+
type: element.subDiagramId ? "subDiagram" : "c4",
|
|
2590
|
+
position: {
|
|
2591
|
+
x: placement.x,
|
|
2592
|
+
y: placement.y
|
|
2593
|
+
},
|
|
2594
|
+
width: placement.width,
|
|
2595
|
+
height: placement.height,
|
|
2596
|
+
data: {
|
|
2597
|
+
source: "mermaid",
|
|
2598
|
+
diagramId: element.subDiagramId,
|
|
2599
|
+
diagramName: element.label,
|
|
2600
|
+
c4Kind: element.kind,
|
|
2601
|
+
c4Shape: element.shape,
|
|
2602
|
+
isExternal: element.isExternal,
|
|
2603
|
+
technology: element.technology,
|
|
2604
|
+
description: element.description,
|
|
2605
|
+
link: element.link,
|
|
2606
|
+
fill: colors.fill,
|
|
2607
|
+
stroke: colors.stroke,
|
|
2608
|
+
fontColor: colors.fontColor,
|
|
2609
|
+
componentFields: [generateComponentFieldNameInput(element.label)]
|
|
2610
|
+
},
|
|
2611
|
+
style: {
|
|
2612
|
+
width: placement.width,
|
|
2613
|
+
height: placement.height
|
|
2614
|
+
},
|
|
2615
|
+
parentId: element.parentId,
|
|
2616
|
+
extent: element.parentId ? "parent" : void 0
|
|
2617
|
+
});
|
|
2618
|
+
}
|
|
2619
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
2620
|
+
for (const boundary of data.boundaries) parentOf.set(boundary.id, boundary.parentId);
|
|
2621
|
+
for (const element of data.elements) parentOf.set(element.id, element.parentId);
|
|
2622
|
+
function absoluteCenter(id) {
|
|
2623
|
+
const placement = placements.get(id);
|
|
2624
|
+
let x = placement.x + placement.width / 2;
|
|
2625
|
+
let y = placement.y + placement.height / 2;
|
|
2626
|
+
let parentId = parentOf.get(id);
|
|
2627
|
+
while (parentId) {
|
|
2628
|
+
const parent = placements.get(parentId);
|
|
2629
|
+
x += parent.x;
|
|
2630
|
+
y += parent.y;
|
|
2631
|
+
parentId = parentOf.get(parentId);
|
|
2632
|
+
}
|
|
2633
|
+
return {
|
|
2634
|
+
x,
|
|
2635
|
+
y
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
return {
|
|
2639
|
+
nodes,
|
|
2640
|
+
edges: data.relationships.filter((rel) => (elementById.has(rel.from) || boundaryById.has(rel.from)) && (elementById.has(rel.to) || boundaryById.has(rel.to))).map((rel) => {
|
|
2641
|
+
var _style$lineColor, _style$lineWidth;
|
|
2642
|
+
const isBack = rel.direction === "back";
|
|
2643
|
+
const source = isBack ? rel.to : rel.from;
|
|
2644
|
+
const target = isBack ? rel.from : rel.to;
|
|
2645
|
+
const style = data.relStyles[`${rel.from}->${rel.to}`];
|
|
2646
|
+
const lineColor = (_style$lineColor = style === null || style === void 0 ? void 0 : style.lineColor) !== null && _style$lineColor !== void 0 ? _style$lineColor : BOUNDARY_BORDER;
|
|
2647
|
+
const label = [rel.label, rel.technology ? `[${rel.technology}]` : ""].filter(Boolean).join(" ");
|
|
2648
|
+
const side = resolveSide(rel.direction, absoluteCenter(source), absoluteCenter(target));
|
|
2649
|
+
return {
|
|
2650
|
+
id: `c4-rel-${rel.from}-${rel.to}-${rel.index}`,
|
|
2651
|
+
source,
|
|
2652
|
+
target,
|
|
2653
|
+
sourceHandle: `source-${side.source}`,
|
|
2654
|
+
targetHandle: `target-${side.target}`,
|
|
2655
|
+
label,
|
|
2656
|
+
type: "simplebezier",
|
|
2657
|
+
style: {
|
|
2658
|
+
stroke: lineColor,
|
|
2659
|
+
strokeWidth: (_style$lineWidth = style === null || style === void 0 ? void 0 : style.lineWidth) !== null && _style$lineWidth !== void 0 ? _style$lineWidth : 1.5
|
|
2660
|
+
},
|
|
2661
|
+
data: {
|
|
2662
|
+
source: "mermaid",
|
|
2663
|
+
labelColor: style === null || style === void 0 ? void 0 : style.textColor,
|
|
2664
|
+
labelOffsetX: style === null || style === void 0 ? void 0 : style.offsetX,
|
|
2665
|
+
labelOffsetY: style === null || style === void 0 ? void 0 : style.offsetY
|
|
2666
|
+
},
|
|
2667
|
+
markerEnd: {
|
|
2668
|
+
type: MarkerType.ArrowClosed,
|
|
2669
|
+
width: 14,
|
|
2670
|
+
height: 14,
|
|
2671
|
+
color: lineColor
|
|
2672
|
+
},
|
|
2673
|
+
markerStart: rel.direction === "bi" ? {
|
|
2674
|
+
type: MarkerType.ArrowClosed,
|
|
2675
|
+
width: 14,
|
|
2676
|
+
height: 14,
|
|
2677
|
+
color: lineColor
|
|
2678
|
+
} : void 0
|
|
2679
|
+
};
|
|
2680
|
+
})
|
|
2681
|
+
};
|
|
2682
|
+
}
|
|
2683
|
+
function convertC4MermaidToReactFlow(code) {
|
|
2684
|
+
return convertC4ToReactFlow(parseC4Diagram(code));
|
|
2685
|
+
}
|
|
2686
|
+
const LAYOUT_SPACING = {
|
|
2687
|
+
SUBGRAPH_HEADER_HEIGHT: 35,
|
|
2688
|
+
SUBGRAPH_PADDING: 8,
|
|
2689
|
+
SUBGRAPH_CONTENT_TOP_MARGIN: 10,
|
|
2690
|
+
NODE_SEPARATION_HORIZONTAL: 80,
|
|
2691
|
+
NODE_SEPARATION_VERTICAL: 100,
|
|
2692
|
+
CONTAINER_SEPARATION_HORIZONTAL: 120,
|
|
2693
|
+
CONTAINER_SEPARATION_VERTICAL: 160,
|
|
2694
|
+
NESTED_SUBGRAPH_SEPARATION_HORIZONTAL: 120,
|
|
2695
|
+
NESTED_SUBGRAPH_SEPARATION_VERTICAL: 140,
|
|
2696
|
+
META_GRAPH_MARGIN: 100,
|
|
2697
|
+
NESTED_CONTENT_MARGIN: 40,
|
|
2698
|
+
MIXED_CONTENT_VERTICAL_SPACING: 100,
|
|
2699
|
+
MIXED_CONTENT_HORIZONTAL_SPACING: 120
|
|
2700
|
+
};
|
|
2701
|
+
({
|
|
2702
|
+
NETWORK_SIMPLEX: "network-simplex",
|
|
2703
|
+
TIGHT_TREE: "tight-tree",
|
|
2704
|
+
LONGEST_PATH: "longest-path"
|
|
2705
|
+
}).TIGHT_TREE;
|
|
2706
|
+
const SEQUENCE_LAYOUT = {
|
|
2707
|
+
COLUMN_WIDTH: 360,
|
|
2708
|
+
ROW_HEIGHT: 60,
|
|
2709
|
+
HEADER_HEIGHT: 40,
|
|
2710
|
+
MESSAGE_NODE_WIDTH: 140,
|
|
2711
|
+
MESSAGE_NODE_HEIGHT: 32,
|
|
2712
|
+
SELF_LOOP_OFFSET: 48,
|
|
2713
|
+
PARTICIPANT_NODE_WIDTH: 10,
|
|
2714
|
+
MESSAGE_MAX_WIDTH: 240,
|
|
2715
|
+
MESSAGE_TARGET_WRAP_LINES: 2,
|
|
2716
|
+
MESSAGE_CHAR_WIDTH: 7,
|
|
2717
|
+
MESSAGE_LINE_HEIGHT: 20,
|
|
2718
|
+
MESSAGE_HORIZONTAL_PADDING: 24,
|
|
2719
|
+
MESSAGE_VERTICAL_PADDING: 8,
|
|
2720
|
+
ROW_VERTICAL_PADDING: 16,
|
|
2721
|
+
NOTE_OFFSET: 24,
|
|
2722
|
+
BLOCK_TOP_PADDING: 36,
|
|
2723
|
+
BLOCK_BOTTOM_PADDING: 16,
|
|
2724
|
+
BLOCK_SIDE_PADDING: 44,
|
|
2725
|
+
BLOCK_SECTION_PADDING: 22,
|
|
2726
|
+
BLOCK_CONTENT_INSET: 12,
|
|
2727
|
+
BLOCK_FRAME_GAP: 12,
|
|
2728
|
+
BOX_TOP_INSET: 26,
|
|
2729
|
+
BOX_BOTTOM_PADDING: 24
|
|
2730
|
+
};
|
|
2731
|
+
function sanitizeMermaidLabels(src) {
|
|
2732
|
+
if (!src) return src;
|
|
2733
|
+
const subgraphFixed = src.replace(/([A-Za-z0-9_]+)\[((?:(?![\"']).)*?)\]/g, (m, id, label) => {
|
|
2734
|
+
if (/^[\"']/.test(label)) return m;
|
|
2735
|
+
if (/[()\"\[\],:;]/.test(label)) return `${id}[\"${String(label).replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"]`;
|
|
2736
|
+
return m;
|
|
2737
|
+
}).replace(/^([ \t]*subgraph\s+)([^\n\r]+)(\|[^\n\r]*)?$/gim, (m, pre, title, rest) => {
|
|
2738
|
+
const t = String(title).trim();
|
|
2739
|
+
if (/^[\"']/.test(t)) return m;
|
|
2740
|
+
if (/[()\"\[\],:;]/.test(t)) return `${pre}\"${t.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"${rest || ""}`;
|
|
2741
|
+
return m;
|
|
2742
|
+
});
|
|
2743
|
+
const diagRegex = /\b(graph|flowchart|sequenceDiagram|stateDiagram|classDiagram|gantt|journey|erDiagram|gitGraph|pie|timeline|infoDiagram)\b/i;
|
|
2744
|
+
const allStarts = [];
|
|
2745
|
+
let mm;
|
|
2746
|
+
const globalRegex = new RegExp(diagRegex.source, "gim");
|
|
2747
|
+
while ((mm = globalRegex.exec(subgraphFixed)) !== null) {
|
|
2748
|
+
allStarts.push(mm.index);
|
|
2749
|
+
if (globalRegex.lastIndex === mm.index) globalRegex.lastIndex++;
|
|
2750
|
+
}
|
|
2751
|
+
if (allStarts.length <= 1) return subgraphFixed;
|
|
2752
|
+
const first = allStarts[0];
|
|
2753
|
+
const second = allStarts[1];
|
|
2754
|
+
return subgraphFixed.slice(first, second).trim();
|
|
2755
|
+
}
|
|
1983
2756
|
const LABEL_TYPE_PREFIX = /^\s*type:(\w+)\s*[:|-]\s*/i;
|
|
1984
2757
|
const TAG_TO_NODE_TYPE = {
|
|
1985
2758
|
builder: "builder",
|
|
@@ -2990,12 +3763,7 @@ function convertSequenceDiagramToReactFlow(mermaidCode) {
|
|
|
2990
3763
|
lifelineHeight: grid.contentHeight,
|
|
2991
3764
|
activations,
|
|
2992
3765
|
links: participant.links
|
|
2993
|
-
}, participant.createdAtRow === void 0 ? {} : { lifelineStartRow: grid.toLayoutRow(participant.createdAtRow) }), participant.destroyedAtRow === void 0 ? {} : { lifelineEndRow: grid.toLastLayoutRow(participant.destroyedAtRow) }), {}, { componentFields: [generateComponentFieldNameInput(participant.name)
|
|
2994
|
-
componentFieldId: "color",
|
|
2995
|
-
label: "Color",
|
|
2996
|
-
data: SEQUENCE_PARTICIPANT_COLOR,
|
|
2997
|
-
type: ComponentInputType.ColorPicker
|
|
2998
|
-
})] })
|
|
3766
|
+
}, participant.createdAtRow === void 0 ? {} : { lifelineStartRow: grid.toLayoutRow(participant.createdAtRow) }), participant.destroyedAtRow === void 0 ? {} : { lifelineEndRow: grid.toLastLayoutRow(participant.destroyedAtRow) }), {}, { componentFields: [generateComponentFieldNameInput(participant.name)] })
|
|
2999
3767
|
});
|
|
3000
3768
|
}
|
|
3001
3769
|
for (const note of data.notes) {
|
|
@@ -3127,6 +3895,7 @@ function detectDiagramType(code) {
|
|
|
3127
3895
|
for (const line of lines) {
|
|
3128
3896
|
const trimmed = line.trim().toLowerCase();
|
|
3129
3897
|
if (trimmed.startsWith("sequencediagram")) return "sequence";
|
|
3898
|
+
if (trimmed.startsWith("c4")) return "c4";
|
|
3130
3899
|
if (trimmed.startsWith("flowchart") || trimmed.startsWith("graph")) return "flowchart";
|
|
3131
3900
|
}
|
|
3132
3901
|
return "flowchart";
|
|
@@ -4354,7 +5123,6 @@ function createReactFlowElements(nodes, edges, subgraphs, subgraphLayouts, subgr
|
|
|
4354
5123
|
edges: edges.map((edge, index) => {
|
|
4355
5124
|
const edgeStyle = { strokeWidth: 2.5 };
|
|
4356
5125
|
const edgeType = "default";
|
|
4357
|
-
const animated = true;
|
|
4358
5126
|
switch (edge.type) {
|
|
4359
5127
|
case "-->":
|
|
4360
5128
|
case "->": break;
|
|
@@ -4377,7 +5145,6 @@ function createReactFlowElements(nodes, edges, subgraphs, subgraphLayouts, subgr
|
|
|
4377
5145
|
target: targetId,
|
|
4378
5146
|
label: edge.label,
|
|
4379
5147
|
type: edgeType,
|
|
4380
|
-
animated,
|
|
4381
5148
|
style: edgeStyle,
|
|
4382
5149
|
labelStyle: {
|
|
4383
5150
|
fontSize: "12px",
|
|
@@ -4436,7 +5203,9 @@ function convertMermaidToReactFlow(_x3) {
|
|
|
4436
5203
|
function _convertMermaidToReactFlow() {
|
|
4437
5204
|
_convertMermaidToReactFlow = _asyncToGenerator(function* (mermaidCode) {
|
|
4438
5205
|
try {
|
|
4439
|
-
|
|
5206
|
+
const diagramType = detectDiagramType(mermaidCode);
|
|
5207
|
+
if (diagramType === "sequence") return convertSequenceDiagramToReactFlow(mermaidCode);
|
|
5208
|
+
if (diagramType === "c4") return convertC4MermaidToReactFlow(mermaidCode);
|
|
4440
5209
|
return convertFlowchartToReactFlow(mermaidCode);
|
|
4441
5210
|
} catch (error) {
|
|
4442
5211
|
console.error("Error converting Mermaid to React Flow:", error);
|
|
@@ -5059,6 +5828,7 @@ function _convertMermaidToReactFlowWithContext() {
|
|
|
5059
5828
|
if ((_ctx$style = ctx.style) === null || _ctx$style === void 0 ? void 0 : _ctx$style.height) clonedNode.height = ctx.style.height;
|
|
5060
5829
|
if ((_ctx$style2 = ctx.style) === null || _ctx$style2 === void 0 ? void 0 : _ctx$style2.width) clonedNode.width = ctx.style.width;
|
|
5061
5830
|
clonedNode.data = _objectSpread2(_objectSpread2(_objectSpread2({}, clonedNode.data), objectPick((_ctx$style3 = ctx.style) !== null && _ctx$style3 !== void 0 ? _ctx$style3 : {}, [
|
|
5831
|
+
"color",
|
|
5062
5832
|
"fill",
|
|
5063
5833
|
"stroke",
|
|
5064
5834
|
"strokeWidth",
|
|
@@ -5115,6 +5885,10 @@ function _convertMermaidToReactFlowWithContext() {
|
|
|
5115
5885
|
if (nodeParent) return _objectSpread2(_objectSpread2({}, node), {}, { parentId: nodeParent.id });
|
|
5116
5886
|
return node;
|
|
5117
5887
|
})];
|
|
5888
|
+
if (isSequenceDiagram(combinedNodes)) return {
|
|
5889
|
+
edges: resolvedEdges,
|
|
5890
|
+
nodes: combinedNodes
|
|
5891
|
+
};
|
|
5118
5892
|
return {
|
|
5119
5893
|
edges: resolvedEdges,
|
|
5120
5894
|
nodes: (options === null || options === void 0 ? void 0 : options.repositionNodes) ? resizeNodesLayouts(combinedNodes) : combinedNodes
|
|
@@ -5728,20 +6502,16 @@ function resolveMermaidDetailedNodeLabel(node) {
|
|
|
5728
6502
|
]);
|
|
5729
6503
|
}
|
|
5730
6504
|
if (nodeType === "sequenceParticipant") {
|
|
5731
|
-
var _getFieldString4
|
|
6505
|
+
var _getFieldString4;
|
|
5732
6506
|
const label = (_getFieldString4 = getFieldString(componentFields, "Label")) !== null && _getFieldString4 !== void 0 ? _getFieldString4 : pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.label);
|
|
5733
6507
|
const participantName = name !== null && name !== void 0 ? name : label;
|
|
5734
6508
|
const rowCount = typeof (nodeData === null || nodeData === void 0 ? void 0 : nodeData.rowCount) === "number" ? nodeData.rowCount : void 0;
|
|
5735
|
-
const color =
|
|
6509
|
+
const color = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.color);
|
|
5736
6510
|
return buildDetailedLabel([
|
|
5737
6511
|
participantName ? `SequenceParticipant: ${participantName}` : "SequenceParticipant",
|
|
5738
6512
|
...typeof rowCount === "number" ? [`rows: ${rowCount}`] : [],
|
|
5739
6513
|
...color ? [`color: ${color}`] : [],
|
|
5740
|
-
...buildFieldLines(componentFields, new Set([
|
|
5741
|
-
"name",
|
|
5742
|
-
"label",
|
|
5743
|
-
"color"
|
|
5744
|
-
]))
|
|
6514
|
+
...buildFieldLines(componentFields, new Set(["name", "label"]))
|
|
5745
6515
|
]);
|
|
5746
6516
|
}
|
|
5747
6517
|
if (nodeType === "comment") return buildDetailedLabel([`Comment: ${(typeof (nodeData === null || nodeData === void 0 ? void 0 : nodeData.isResolved) === "boolean" ? nodeData.isResolved : void 0) ? "Resolved" : "Open"}`, ...buildFieldLines(componentFields, new Set(["name"]))]);
|
|
@@ -5821,4 +6591,4 @@ function convertUiGraphToMermaid(input, options) {
|
|
|
5821
6591
|
context
|
|
5822
6592
|
};
|
|
5823
6593
|
}
|
|
5824
|
-
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, ComponentInputType, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, JsonEditorSchema, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, SEQUENCE_LAYOUT,
|
|
6594
|
+
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, C4_COLORS, C4_LAYOUT, ComponentInputType, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, JsonEditorSchema, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, SEQUENCE_LAYOUT, SqlToAstParser, buildMetaData, contextSchema, convertC4MermaidToReactFlow, convertC4ToReactFlow, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertReactFlowToSequenceMermaid, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, getC4ElementColors, isC4Diagram, isSequenceDiagram, parseC4Diagram, sanitizeMermaidLabels, syncBaseData };
|