@uigraph/sdk 1.2.6 → 1.2.8

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.mjs CHANGED
@@ -2558,6 +2558,7 @@ function convertC4ToReactFlow(data) {
2558
2558
  },
2559
2559
  data: {
2560
2560
  source: "mermaid",
2561
+ c4DiagramType: data.type,
2561
2562
  c4BoundaryKind: boundary.kind,
2562
2563
  boundaryType: boundary.type,
2563
2564
  description: boundary.description,
@@ -2597,6 +2598,7 @@ function convertC4ToReactFlow(data) {
2597
2598
  source: "mermaid",
2598
2599
  diagramId: element.subDiagramId,
2599
2600
  diagramName: element.label,
2601
+ c4DiagramType: data.type,
2600
2602
  c4Kind: element.kind,
2601
2603
  c4Shape: element.shape,
2602
2604
  isExternal: element.isExternal,
@@ -2660,6 +2662,9 @@ function convertC4ToReactFlow(data) {
2660
2662
  },
2661
2663
  data: {
2662
2664
  source: "mermaid",
2665
+ c4RelDirection: rel.direction,
2666
+ c4RelTechnology: rel.technology,
2667
+ c4RelDescription: rel.description,
2663
2668
  labelColor: style === null || style === void 0 ? void 0 : style.textColor,
2664
2669
  labelOffsetX: style === null || style === void 0 ? void 0 : style.offsetX,
2665
2670
  labelOffsetY: style === null || style === void 0 ? void 0 : style.offsetY
@@ -5192,1048 +5197,1282 @@ function _convertMermaidToReactFlow() {
5192
5197
  });
5193
5198
  return _convertMermaidToReactFlow.apply(this, arguments);
5194
5199
  }
5195
- function sanitizeMermaidLabels(src) {
5196
- if (!src) return src;
5197
- const subgraphFixed = src.replace(/([A-Za-z0-9_]+)\[((?:(?![\"']).)*?)\]/g, (m, id, label) => {
5198
- if (/^[\"']/.test(label)) return m;
5199
- if (/[()\"\[\],:;]/.test(label)) return `${id}[\"${String(label).replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"]`;
5200
- return m;
5201
- }).replace(/^([ \t]*subgraph\s+)([^\n\r]+)(\|[^\n\r]*)?$/gim, (m, pre, title, rest) => {
5202
- const t = String(title).trim();
5203
- if (/^[\"']/.test(t)) return m;
5204
- if (/[()\"\[\],:;]/.test(t)) return `${pre}\"${t.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"${rest || ""}`;
5205
- return m;
5206
- });
5207
- const diagRegex = /\b(graph|flowchart|sequenceDiagram|stateDiagram|classDiagram|gantt|journey|erDiagram|gitGraph|pie|timeline|infoDiagram)\b/i;
5208
- const allStarts = [];
5209
- let mm;
5210
- const globalRegex = new RegExp(diagRegex.source, "gim");
5211
- while ((mm = globalRegex.exec(subgraphFixed)) !== null) {
5212
- allStarts.push(mm.index);
5213
- if (globalRegex.lastIndex === mm.index) globalRegex.lastIndex++;
5214
- }
5215
- if (allStarts.length <= 1) return subgraphFixed;
5216
- const first = allStarts[0];
5217
- const second = allStarts[1];
5218
- return subgraphFixed.slice(first, second).trim();
5219
- }
5220
- function isSequenceDiagram(nodes) {
5221
- return nodes.some((node) => node.type === "sequenceParticipant");
5200
+ const CONTEXT_SHAPES = new Set([
5201
+ "rectangle",
5202
+ "rounded-rect",
5203
+ "ellipse",
5204
+ "diamond",
5205
+ "triangle",
5206
+ "parallelogram",
5207
+ "trapezoid",
5208
+ "hexagon",
5209
+ "document",
5210
+ "cylinder",
5211
+ "delay",
5212
+ "off-page-connector",
5213
+ "display",
5214
+ "collate",
5215
+ "sort",
5216
+ "terminator",
5217
+ "or",
5218
+ "database",
5219
+ "multiple-documents",
5220
+ "subroutine",
5221
+ "manual-input",
5222
+ "summing-junction",
5223
+ "internal-storage"
5224
+ ]);
5225
+ const COMPONENT_INPUT_TYPES = new Set(Object.values(ComponentInputType));
5226
+ const INLINE_MERMAID_LABEL_MAX_LENGTH = 32;
5227
+ const KNOWN_NODE_DATA_KEYS = new Set([
5228
+ "componentFields",
5229
+ "shape",
5230
+ "fill",
5231
+ "stroke",
5232
+ "strokeWidth",
5233
+ "strokeStyle",
5234
+ "borderRadius",
5235
+ "borderAnimationEnabled",
5236
+ "strokeAnimation",
5237
+ "src",
5238
+ "animatedIcon",
5239
+ "iconSrc",
5240
+ "componentId",
5241
+ "serviceTable",
5242
+ "title",
5243
+ "columns",
5244
+ "rows",
5245
+ "name",
5246
+ "label",
5247
+ "value",
5248
+ "cloud",
5249
+ "service",
5250
+ "childNodes"
5251
+ ]);
5252
+ function isComponentInputType(value) {
5253
+ return COMPONENT_INPUT_TYPES.has(value);
5222
5254
  }
5223
- function fieldValue(node, componentFieldId) {
5224
- var _node$data, _field$data;
5225
- const fields = (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.componentFields;
5226
- if (!Array.isArray(fields)) return void 0;
5227
- const field = fields.find((candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.componentFieldId) === componentFieldId);
5228
- const value = field === null || field === void 0 || (_field$data = field.data) === null || _field$data === void 0 || (_field$data = _field$data[0]) === null || _field$data === void 0 ? void 0 : _field$data.value;
5229
- if (typeof value !== "string") return void 0;
5230
- if (!value.trim()) return void 0;
5255
+ function toRecord(value) {
5256
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
5231
5257
  return value;
5232
5258
  }
5233
- function nodeLabel(node) {
5234
- var _node$data2;
5235
- const fromField = fieldValue(node, "name");
5236
- if (fromField !== void 0) return fromField;
5237
- const label = (_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.label;
5238
- if (typeof label === "string") return label;
5239
- return "";
5259
+ function pickString(value) {
5260
+ if (typeof value !== "string") return;
5261
+ const trimmed = value.trim();
5262
+ if (!trimmed) return;
5263
+ return trimmed;
5240
5264
  }
5241
- function encodeLabel(text) {
5242
- return text.replace(/#/g, "&#35;").replace(/\r\n?/g, "\n").replace(/\n/g, "<br/>").trim();
5265
+ function pickPosition(value) {
5266
+ const position = toRecord(value);
5267
+ if (!position) return;
5268
+ if (typeof position.x !== "number" || !Number.isFinite(position.x)) return;
5269
+ if (typeof position.y !== "number" || !Number.isFinite(position.y)) return;
5270
+ return {
5271
+ x: position.x,
5272
+ y: position.y
5273
+ };
5243
5274
  }
5244
- function toMermaidId(name, index, used) {
5245
- const base = name.replace(/[^A-Za-z0-9_]/g, "") || `P${index}`;
5246
- let candidate = base;
5247
- let suffix = 2;
5248
- while (used.has(candidate)) {
5249
- candidate = `${base}_${suffix}`;
5250
- suffix++;
5251
- }
5252
- used.add(candidate);
5253
- return candidate;
5275
+ function getFieldValue(fieldData) {
5276
+ if (!Array.isArray(fieldData) || fieldData.length !== 1) return fieldData;
5277
+ const first = toRecord(fieldData[0]);
5278
+ if (!first) return fieldData;
5279
+ if (!("value" in first)) return first;
5280
+ return first.value;
5254
5281
  }
5255
- function collectParticipants(nodes) {
5256
- const used = /* @__PURE__ */ new Set();
5257
- return nodes.filter((node) => node.type === "sequenceParticipant").sort((a, b) => a.position.x - b.position.x).map((node, index) => {
5258
- var _node$data3, _node$data4, _node$data5, _node$data6, _node$data7;
5259
- const name = nodeLabel(node) || `Participant ${index + 1}`;
5260
- const rawType = (_node$data3 = node.data) === null || _node$data3 === void 0 ? void 0 : _node$data3.participantType;
5261
- const activations = (_node$data4 = node.data) === null || _node$data4 === void 0 ? void 0 : _node$data4.activations;
5262
- const links = (_node$data5 = node.data) === null || _node$data5 === void 0 ? void 0 : _node$data5.links;
5263
- const createdRow = (_node$data6 = node.data) === null || _node$data6 === void 0 ? void 0 : _node$data6.lifelineStartRow;
5264
- const destroyedRow = (_node$data7 = node.data) === null || _node$data7 === void 0 ? void 0 : _node$data7.lifelineEndRow;
5265
- return _objectSpread2(_objectSpread2(_objectSpread2({
5266
- nodeId: node.id,
5267
- mermaidId: toMermaidId(name, index, used),
5268
- name,
5269
- type: typeof rawType === "string" ? rawType : "participant",
5270
- links: Array.isArray(links) ? links : [],
5271
- activations: Array.isArray(activations) ? activations : []
5272
- }, typeof createdRow === "number" ? { createdRow } : {}), typeof destroyedRow === "number" ? { destroyedRow } : {}), {}, { x: node.position.x });
5282
+ function getFieldByLabel(fields, label) {
5283
+ return fields.find((field) => {
5284
+ var _pickString;
5285
+ return ((_pickString = pickString(field.label)) === null || _pickString === void 0 ? void 0 : _pickString.toLowerCase()) === label.toLowerCase() && pickString(field.type);
5273
5286
  });
5274
5287
  }
5275
- function buildMessageLinks(edges, participantNodeIds) {
5276
- const links = /* @__PURE__ */ new Map();
5277
- for (const edge of edges) {
5278
- if (participantNodeIds.has(edge.source)) links.set(edge.target, _objectSpread2(_objectSpread2({}, links.get(edge.target)), {}, { from: edge.source }));
5279
- if (participantNodeIds.has(edge.target)) links.set(edge.source, _objectSpread2(_objectSpread2({}, links.get(edge.source)), {}, { to: edge.target }));
5280
- }
5281
- return links;
5288
+ function getFieldString(fields, label) {
5289
+ const field = getFieldByLabel(fields, label);
5290
+ if (!field) return;
5291
+ return pickString(getFieldValue(field.data));
5282
5292
  }
5283
- function arrowTokenOf(edgeFrom, edgeTo) {
5284
- var _edgeTo$data$arrowTyp, _edgeTo$data, _edgeFrom$data, _edgeTo$data$half, _edgeTo$data2, _edgeFrom$data2, _edgeFrom$data3, _ref, _ref2;
5285
- const arrowType = (_edgeTo$data$arrowTyp = edgeTo === null || edgeTo === void 0 || (_edgeTo$data = edgeTo.data) === null || _edgeTo$data === void 0 ? void 0 : _edgeTo$data.arrowType) !== null && _edgeTo$data$arrowTyp !== void 0 ? _edgeTo$data$arrowTyp : edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data = edgeFrom.data) === null || _edgeFrom$data === void 0 ? void 0 : _edgeFrom$data.arrowType;
5286
- const half = (_edgeTo$data$half = edgeTo === null || edgeTo === void 0 || (_edgeTo$data2 = edgeTo.data) === null || _edgeTo$data2 === void 0 ? void 0 : _edgeTo$data2.half) !== null && _edgeTo$data$half !== void 0 ? _edgeTo$data$half : edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data2 = edgeFrom.data) === null || _edgeFrom$data2 === void 0 ? void 0 : _edgeFrom$data2.half;
5287
- const reversed = (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data3 = edgeFrom.data) === null || _edgeFrom$data3 === void 0 ? void 0 : _edgeFrom$data3.reversed) === true;
5288
- return findArrowTokenFor(_objectSpread2(_objectSpread2({
5289
- lineStyle: (edgeTo === null || edgeTo === void 0 || (_ref = edgeTo.style) === null || _ref === void 0 ? void 0 : _ref.strokeDasharray) !== void 0 || (edgeFrom === null || edgeFrom === void 0 || (_ref2 = edgeFrom.style) === null || _ref2 === void 0 ? void 0 : _ref2.strokeDasharray) !== void 0 ? "dashed" : "solid",
5290
- arrowType: arrowType !== null && arrowType !== void 0 ? arrowType : "filled"
5291
- }, half ? { half } : {}), {}, { reversed }));
5293
+ function isEmptyFieldValue(value) {
5294
+ if (typeof value === "string") return value.trim().length === 0;
5295
+ return value === void 0 || value === null;
5292
5296
  }
5293
- function noteParticipantNodeIds(note, participants, noteNode$1) {
5294
- const byImportedId = (Array.isArray(note.participants) ? note.participants.filter((value) => typeof value === "string") : []).map((id) => participants.find((participant) => participant.nodeId === `participant-${id}`)).filter((participant) => Boolean(participant));
5295
- if (byImportedId.length > 0) return byImportedId.map((participant) => participant.nodeId);
5296
- if (participants.length === 0) return [];
5297
- const noteCenter = noteNode$1.position.x + (Number(noteNode$1.width) || 0) / 2;
5298
- return [[...participants].sort((a, b) => Math.abs(a.x - noteCenter) - Math.abs(b.x - noteCenter))[0].nodeId];
5297
+ function parseStrokeStyle(dashArray) {
5298
+ if (typeof dashArray !== "string" || !dashArray.trim()) return;
5299
+ const normalized = dashArray.replaceAll(",", " ").replace(/\s+/g, " ").trim();
5300
+ if (normalized === "1 2") return "dotted";
5301
+ if (normalized === "4 2" || normalized === "4 4" || normalized === "8 4") return "dashed";
5302
+ return "solid";
5299
5303
  }
5300
- function collectRowItems(nodes, edges, participants) {
5301
- const participantNodeIds = new Set(participants.map((p) => p.nodeId));
5302
- const links = buildMessageLinks(edges, participantNodeIds);
5303
- const items = [];
5304
- for (const node of nodes) {
5305
- var _node$data8, _node$data9, _edgeFrom$data4, _edgeTo$data3;
5306
- if (participantNodeIds.has(node.id)) continue;
5307
- const note = (_node$data8 = node.data) === null || _node$data8 === void 0 ? void 0 : _node$data8.sequenceNote;
5308
- if (note) {
5309
- var _note$placement;
5310
- items.push({
5311
- item: {
5312
- kind: "note",
5313
- nodeId: node.id,
5314
- text: nodeLabel(node),
5315
- placement: (_note$placement = note.placement) !== null && _note$placement !== void 0 ? _note$placement : "over",
5316
- participantNodeIds: noteParticipantNodeIds(note, participants, node)
5317
- },
5318
- y: node.position.y
5319
- });
5320
- continue;
5321
- }
5322
- const link = links.get(node.id);
5323
- if (!(link === null || link === void 0 ? void 0 : link.from) || !link.to) continue;
5324
- const edgeFrom = edges.find((edge) => edge.target === node.id && edge.source === link.from);
5325
- const edgeTo = edges.find((edge) => edge.source === node.id && edge.target === link.to);
5326
- const sequenceNumber = (_node$data9 = node.data) === null || _node$data9 === void 0 ? void 0 : _node$data9.sequenceNumber;
5327
- items.push({
5328
- item: _objectSpread2({
5329
- kind: "message",
5330
- nodeId: node.id,
5331
- fromNodeId: link.from,
5332
- toNodeId: link.to,
5333
- label: nodeLabel(node),
5334
- token: arrowTokenOf(edgeFrom, edgeTo),
5335
- centralSource: (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data4 = edgeFrom.data) === null || _edgeFrom$data4 === void 0 ? void 0 : _edgeFrom$data4.centralSource) === true,
5336
- centralTarget: (edgeTo === null || edgeTo === void 0 || (_edgeTo$data3 = edgeTo.data) === null || _edgeTo$data3 === void 0 ? void 0 : _edgeTo$data3.centralTarget) === true
5337
- }, typeof sequenceNumber === "number" ? { sequenceNumber } : {}),
5338
- y: node.position.y
5339
- });
5340
- }
5341
- return items.sort((a, b) => a.y - b.y).map((entry) => entry.item);
5304
+ function normalizeMarker(marker) {
5305
+ if (typeof marker === "string") return { type: marker };
5306
+ const markerRecord = toRecord(marker);
5307
+ if (!markerRecord) return;
5308
+ const type = pickString(markerRecord.type);
5309
+ if (!type) return;
5310
+ const color = pickString(markerRecord.color);
5311
+ if (color) return {
5312
+ type,
5313
+ color
5314
+ };
5315
+ return { type };
5342
5316
  }
5343
- function collectBlocks(nodes) {
5344
- const blocks = [];
5345
- for (const node of nodes) {
5346
- var _node$data10, _block$type, _block$label, _block$depth, _block$sections;
5347
- const block = (_node$data10 = node.data) === null || _node$data10 === void 0 ? void 0 : _node$data10.sequenceBlock;
5348
- if (!block) continue;
5349
- if (typeof block.startRow !== "number") continue;
5350
- if (typeof block.endRow !== "number") continue;
5351
- blocks.push(_objectSpread2(_objectSpread2({
5352
- type: (_block$type = block.type) !== null && _block$type !== void 0 ? _block$type : "rect",
5353
- label: (_block$label = block.label) !== null && _block$label !== void 0 ? _block$label : ""
5354
- }, block.color ? { color: block.color } : {}), {}, {
5355
- depth: (_block$depth = block.depth) !== null && _block$depth !== void 0 ? _block$depth : 0,
5356
- startRow: block.startRow,
5357
- endRow: block.endRow,
5358
- sections: ((_block$sections = block.sections) !== null && _block$sections !== void 0 ? _block$sections : []).filter((section) => typeof section.startRow === "number" && typeof section.endRow === "number").map((section) => {
5359
- var _section$label;
5360
- return {
5361
- label: (_section$label = section.label) !== null && _section$label !== void 0 ? _section$label : "",
5362
- startRow: section.startRow,
5363
- endRow: section.endRow
5364
- };
5365
- })
5366
- }));
5367
- }
5368
- return blocks;
5317
+ function escapeMermaidText(value) {
5318
+ return value.replaceAll("\"", "\\\"");
5369
5319
  }
5370
- function collectBoxes(nodes, participants) {
5371
- const boxes = [];
5372
- for (const node of nodes) {
5373
- var _node$data11, _node$data12, _box$label;
5374
- const box = (_node$data11 = node.data) === null || _node$data11 === void 0 ? void 0 : _node$data11.sequenceBox;
5375
- if (!box) continue;
5376
- const byImportedId = (Array.isArray(box.participants) ? box.participants.filter((value) => typeof value === "string") : []).map((id) => participants.find((participant) => participant.nodeId === `participant-${id}`)).filter((participant) => Boolean(participant));
5377
- const left = node.position.x;
5378
- const right = node.position.x + (Number(node.width) || 0);
5379
- const contained = byImportedId.length > 0 ? byImportedId : participants.filter((participant) => participant.x >= left && participant.x <= right);
5380
- if (contained.length === 0) continue;
5381
- const backgroundColor = (_node$data12 = node.data) === null || _node$data12 === void 0 ? void 0 : _node$data12.backgroundColor;
5382
- boxes.push(_objectSpread2(_objectSpread2({ label: (_box$label = box.label) !== null && _box$label !== void 0 ? _box$label : "" }, typeof backgroundColor === "string" ? { color: backgroundColor } : {}), {}, { participantNodeIds: contained.map((participant) => participant.nodeId) }));
5383
- }
5384
- return boxes;
5320
+ function canInlineMermaidLabel(value) {
5321
+ if (value.length > INLINE_MERMAID_LABEL_MAX_LENGTH) return false;
5322
+ if (value.includes("\n") || value.includes("\r")) return false;
5323
+ return true;
5385
5324
  }
5386
- function participantDeclaration(participant, keyword) {
5387
- const stereotype = participant.type === "participant" || participant.type === "actor" ? "" : `@{ "type": "${participant.type}" }`;
5388
- const alias = participant.mermaidId === participant.name ? "" : ` as ${encodeLabel(participant.name)}`;
5389
- return `${keyword} ${participant.mermaidId}${stereotype}${alias}`;
5325
+ function normalizeDetailedMermaidLabel(value) {
5326
+ return value.split(/\r?\n/).map((line) => line.replace(/\s+/g, " ").trim()).filter((line) => line.length > 0).join("\n");
5390
5327
  }
5391
- function convertReactFlowToSequenceMermaid(nodes, edges) {
5392
- const participants = collectParticipants(nodes);
5393
- const items = collectRowItems(nodes, edges, participants);
5394
- const blocks = collectBlocks(nodes);
5395
- const boxes = collectBoxes(nodes, participants);
5396
- const participantByNodeId = new Map(participants.map((participant) => [participant.nodeId, participant]));
5397
- const rowByItemId = /* @__PURE__ */ new Map();
5398
- const lastRowByItemId = /* @__PURE__ */ new Map();
5399
- let row = 0;
5400
- for (const item of items) {
5401
- rowByItemId.set(item.nodeId, row);
5402
- const isSelf = item.kind === "message" && item.fromNodeId === item.toNodeId;
5403
- lastRowByItemId.set(item.nodeId, isSelf ? row + 1 : row);
5404
- row += isSelf ? 2 : 1;
5405
- }
5406
- const rowCount = row;
5407
- const lines = ["sequenceDiagram"];
5408
- const titleNode = nodes.find((node) => node.id === "sequence-title");
5409
- if (titleNode) {
5410
- var _fieldValue;
5411
- const text = (_fieldValue = fieldValue(titleNode, "text")) !== null && _fieldValue !== void 0 ? _fieldValue : nodeLabel(titleNode);
5412
- if (text) lines.push(` title ${encodeLabel(text)}`);
5328
+ function toComponentFields(value) {
5329
+ if (!Array.isArray(value)) return [];
5330
+ return value.map((field) => toRecord(field)).filter((field) => field !== void 0);
5331
+ }
5332
+ function buildContextEdges(edges, nodeIdMap) {
5333
+ const contextEdges = {};
5334
+ const ordinals = /* @__PURE__ */ new Map();
5335
+ for (const edge of edges) {
5336
+ var _ordinals$get, _toRecord, _toRecord2;
5337
+ const source = nodeIdMap.get(edge.source);
5338
+ const target = nodeIdMap.get(edge.target);
5339
+ if (!source || !target) continue;
5340
+ const pair = `${source}-${target}`;
5341
+ const ordinal = (_ordinals$get = ordinals.get(pair)) !== null && _ordinals$get !== void 0 ? _ordinals$get : 0;
5342
+ ordinals.set(pair, ordinal + 1);
5343
+ const edgeContext = {};
5344
+ const edgeType = pickString(edge.type);
5345
+ if (edgeType) edgeContext.type = edgeType;
5346
+ const sourceHandle = pickString(edge.sourceHandle);
5347
+ if (sourceHandle) edgeContext.sourceHandle = sourceHandle;
5348
+ const targetHandle = pickString(edge.targetHandle);
5349
+ if (targetHandle) edgeContext.targetHandle = targetHandle;
5350
+ const edgeLabel = pickString(edge.label);
5351
+ if (edgeLabel) edgeContext.label = edgeLabel;
5352
+ const edgeStyleRecord = (_toRecord = toRecord(edge.style)) !== null && _toRecord !== void 0 ? _toRecord : {};
5353
+ const edgeStyle = {};
5354
+ const stroke = pickString(edgeStyleRecord.stroke);
5355
+ if (stroke) edgeStyle.stroke = stroke;
5356
+ if (typeof edgeStyleRecord.strokeWidth === "number") edgeStyle.strokeWidth = edgeStyleRecord.strokeWidth;
5357
+ const strokeStyle = parseStrokeStyle(edgeStyleRecord.strokeDasharray);
5358
+ if (strokeStyle) edgeStyle.strokeStyle = strokeStyle;
5359
+ if (typeof edge.animated === "boolean") edgeStyle.borderAnimationEnabled = edge.animated;
5360
+ if (Object.keys(edgeStyle).length > 0) edgeContext.style = edgeStyle;
5361
+ const markerStart = normalizeMarker(edge.markerStart);
5362
+ if (markerStart) edgeContext.markerStart = markerStart;
5363
+ const markerEnd = normalizeMarker(edge.markerEnd);
5364
+ if (markerEnd) edgeContext.markerEnd = markerEnd;
5365
+ const edgeData$1 = (_toRecord2 = toRecord(edge.data)) !== null && _toRecord2 !== void 0 ? _toRecord2 : {};
5366
+ if (Object.keys(edgeData$1).length > 0) edgeContext.___internal = edgeData$1;
5367
+ if (Object.keys(edgeContext).length > 0) if (ordinal === 0) contextEdges[pair] = edgeContext;
5368
+ else contextEdges[`${pair}#${ordinal}`] = edgeContext;
5413
5369
  }
5414
- const boxByFirstParticipant = /* @__PURE__ */ new Map();
5415
- const boxEndByParticipant = /* @__PURE__ */ new Map();
5416
- for (const box of boxes) {
5417
- var _boxEndByParticipant$;
5418
- const ordered = participants.filter((participant) => box.participantNodeIds.includes(participant.nodeId));
5419
- if (ordered.length === 0) continue;
5420
- boxByFirstParticipant.set(ordered[0].nodeId, box);
5421
- boxEndByParticipant.set(ordered[ordered.length - 1].nodeId, ((_boxEndByParticipant$ = boxEndByParticipant.get(ordered[ordered.length - 1].nodeId)) !== null && _boxEndByParticipant$ !== void 0 ? _boxEndByParticipant$ : 0) + 1);
5370
+ return contextEdges;
5371
+ }
5372
+ function buildContextGroups(groupNodes, nodeIdMap) {
5373
+ const contextGroups = {};
5374
+ for (const groupNode of groupNodes) {
5375
+ var _toRecord;
5376
+ const groupData = (_toRecord = toRecord(groupNode.data)) !== null && _toRecord !== void 0 ? _toRecord : {};
5377
+ const childNodes = Array.isArray(groupData.childNodes) ? groupData.childNodes.map((childId) => typeof childId === "string" ? nodeIdMap.get(childId) : void 0).filter((childId) => childId !== void 0) : [];
5378
+ const name = getFieldString(Array.isArray(groupData.componentFields) ? groupData.componentFields.map((field) => toRecord(field)).filter((field) => field !== void 0) : [], "Name");
5379
+ if (!name && childNodes.length === 0) continue;
5380
+ contextGroups[groupNode.id] = {
5381
+ name: name !== null && name !== void 0 ? name : void 0,
5382
+ nodes: childNodes
5383
+ };
5422
5384
  }
5423
- for (const participant of participants) {
5424
- var _boxEndByParticipant$2;
5425
- const box = boxByFirstParticipant.get(participant.nodeId);
5426
- if (box) {
5427
- const color = box.color ? `${box.color} ` : "";
5428
- lines.push(` box ${color}${encodeLabel(box.label)}`.trimEnd());
5385
+ return contextGroups;
5386
+ }
5387
+ function buildContextNodes(graphNodes, nodeIdMap) {
5388
+ const contextNodes = {};
5389
+ for (const node of graphNodes) {
5390
+ var _toRecord, _toRecord2, _pickString, _pickString2;
5391
+ const mappedNodeId = nodeIdMap.get(node.id);
5392
+ if (!mappedNodeId) continue;
5393
+ const nodeData$1 = (_toRecord = toRecord(node.data)) !== null && _toRecord !== void 0 ? _toRecord : {};
5394
+ const nodeStyle = (_toRecord2 = toRecord(node.style)) !== null && _toRecord2 !== void 0 ? _toRecord2 : {};
5395
+ const componentFields = Array.isArray(nodeData$1.componentFields) ? nodeData$1.componentFields.map((field) => toRecord(field)).filter((field) => field !== void 0) : [];
5396
+ const nodeContext = {};
5397
+ const nodeType = pickString(node.type);
5398
+ if (nodeType) nodeContext.type = nodeType;
5399
+ const nameField = getFieldByLabel(componentFields, "Name");
5400
+ const nameRawValue = nameField ? getFieldValue(nameField.data) : void 0;
5401
+ const name = pickString(nameRawValue);
5402
+ if (name) nodeContext.name = name;
5403
+ const textField = nodeType === "text" ? getFieldByLabel(componentFields, "Text") : void 0;
5404
+ const textRawValue = textField ? getFieldValue(textField.data) : void 0;
5405
+ const textValue = pickString(textRawValue);
5406
+ if (nodeType === "text") {
5407
+ if (textValue) nodeContext.value = textValue;
5429
5408
  }
5430
- if (participant.createdRow === void 0) {
5431
- const keyword = participant.type === "actor" ? "actor" : "participant";
5432
- lines.push(` ${participantDeclaration(participant, keyword)}`);
5409
+ const codeField = nodeType === "code" ? getFieldByLabel(componentFields, "Code") : void 0;
5410
+ const codeRawValue = codeField ? getFieldValue(codeField.data) : void 0;
5411
+ const codeValue = pickString(codeRawValue);
5412
+ if (nodeType === "code") {
5413
+ if (codeValue) nodeContext.value = codeValue;
5433
5414
  }
5434
- const boxEnds = (_boxEndByParticipant$2 = boxEndByParticipant.get(participant.nodeId)) !== null && _boxEndByParticipant$2 !== void 0 ? _boxEndByParticipant$2 : 0;
5435
- for (let index = 0; index < boxEnds; index++) lines.push(" end");
5436
- }
5437
- for (const participant of participants) for (const link of participant.links) lines.push(` link ${participant.mermaidId}: ${link.label} @ ${link.url}`);
5438
- const numbered = items.filter((item) => item.kind === "message" && item.sequenceNumber !== void 0);
5439
- if (numbered.length > 0) {
5440
- const start = numbered[0].sequenceNumber;
5441
- const step = numbered.length > 1 ? numbered[1].sequenceNumber - numbered[0].sequenceNumber : 1;
5442
- lines.push(` autonumber ${start} ${step}`);
5443
- }
5444
- const openBlocks = [];
5445
- function indent() {
5446
- return " ".repeat(openBlocks.length + 1);
5447
- }
5448
- for (let currentRow = 0; currentRow < rowCount; currentRow++) {
5449
- const opening = blocks.filter((block) => block.startRow === currentRow).sort((a, b) => a.depth - b.depth);
5450
- for (const block of opening) {
5451
- const label = encodeLabel(block.label);
5452
- const color = block.type === "rect" && block.color ? `${block.color} ` : "";
5453
- lines.push(`${indent()}${block.type} ${color}${label}`.trimEnd());
5454
- openBlocks.push(block);
5415
+ const src = pickString(nodeData$1.src);
5416
+ if (src) nodeContext.src = src;
5417
+ const animatedIcon = pickString(nodeData$1.animatedIcon);
5418
+ if (animatedIcon) nodeContext.animatedIcon = animatedIcon;
5419
+ const cloud = pickString(nodeData$1.cloud);
5420
+ if (cloud) nodeContext.cloud = cloud;
5421
+ const service = pickString(nodeData$1.service);
5422
+ if (service) nodeContext.service = service;
5423
+ const componentId = pickString(nodeData$1.componentId);
5424
+ if (componentId) nodeContext.componentId = componentId;
5425
+ const shape = pickString(nodeData$1.shape);
5426
+ if (shape && CONTEXT_SHAPES.has(shape)) nodeContext.shape = shape;
5427
+ const style = {};
5428
+ const width = typeof node.width === "number" ? node.width : typeof nodeStyle.width === "number" ? nodeStyle.width : void 0;
5429
+ if (typeof width === "number") style.width = width;
5430
+ const height = typeof node.height === "number" ? node.height : typeof nodeStyle.height === "number" ? nodeStyle.height : void 0;
5431
+ if (typeof height === "number") style.height = height;
5432
+ const fill = (_pickString = pickString(nodeData$1.fill)) !== null && _pickString !== void 0 ? _pickString : pickString(nodeStyle.fill);
5433
+ if (fill) style.fill = fill;
5434
+ const stroke = (_pickString2 = pickString(nodeData$1.stroke)) !== null && _pickString2 !== void 0 ? _pickString2 : pickString(nodeStyle.stroke);
5435
+ if (stroke) style.stroke = stroke;
5436
+ const strokeWidth = typeof nodeData$1.strokeWidth === "number" ? nodeData$1.strokeWidth : typeof nodeStyle.strokeWidth === "number" ? nodeStyle.strokeWidth : void 0;
5437
+ if (typeof strokeWidth === "number") style.strokeWidth = strokeWidth;
5438
+ const borderRadius = typeof nodeData$1.borderRadius === "number" ? nodeData$1.borderRadius : typeof nodeStyle.borderRadius === "number" ? nodeStyle.borderRadius : void 0;
5439
+ if (typeof borderRadius === "number") style.borderRadius = borderRadius;
5440
+ const strokeStyleFromData = pickString(nodeData$1.strokeStyle);
5441
+ if (strokeStyleFromData === "solid" || strokeStyleFromData === "dashed" || strokeStyleFromData === "dotted") style.strokeStyle = strokeStyleFromData;
5442
+ else {
5443
+ const strokeStyleFromDash = parseStrokeStyle(nodeStyle.strokeDasharray);
5444
+ if (strokeStyleFromDash) style.strokeStyle = strokeStyleFromDash;
5455
5445
  }
5456
- for (const [depth, block] of openBlocks.entries()) for (const section of block.sections.slice(1)) {
5457
- if (section.startRow !== currentRow) continue;
5458
- const keyword = block.type === "par" ? "and" : block.type === "critical" ? "option" : "else";
5459
- lines.push(`${" ".repeat(depth + 1)}${keyword} ${encodeLabel(section.label)}`.trimEnd());
5446
+ const borderAnimationEnabled = typeof nodeData$1.borderAnimationEnabled === "boolean" ? nodeData$1.borderAnimationEnabled : nodeData$1.strokeAnimation === "dash" ? true : void 0;
5447
+ if (typeof borderAnimationEnabled === "boolean") style.borderAnimationEnabled = borderAnimationEnabled;
5448
+ if (Object.keys(style).length > 0) nodeContext.style = style;
5449
+ const tableColumns = Array.isArray(nodeData$1.columns) ? nodeData$1.columns.filter((value) => typeof value === "string") : void 0;
5450
+ const tableRows = Array.isArray(nodeData$1.rows) ? nodeData$1.rows.map((row) => Array.isArray(row) ? row.filter((value) => typeof value === "string") : void 0).filter((row) => row !== void 0) : void 0;
5451
+ if (tableColumns || tableRows) nodeContext.table = {
5452
+ columns: tableColumns !== null && tableColumns !== void 0 ? tableColumns : [],
5453
+ rows: tableRows !== null && tableRows !== void 0 ? tableRows : []
5454
+ };
5455
+ const serviceTable = toRecord(nodeData$1.serviceTable);
5456
+ const serviceName = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.serviceName);
5457
+ const databaseName = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.databaseName);
5458
+ const tableName = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.tableName);
5459
+ if (serviceName && databaseName && tableName) nodeContext.dbConfig = {
5460
+ serviceName,
5461
+ databaseName,
5462
+ tableName
5463
+ };
5464
+ const dynamicData = {};
5465
+ for (const field of componentFields) {
5466
+ const label$1 = pickString(field.label);
5467
+ const type = pickString(field.type);
5468
+ if (!label$1 || !type || !isComponentInputType(type)) continue;
5469
+ const componentType = type;
5470
+ const normalizedLabel = label$1.toLowerCase();
5471
+ if (normalizedLabel === "name") continue;
5472
+ if (nodeType === "text" && normalizedLabel === "text") continue;
5473
+ if (nodeType === "code" && normalizedLabel === "code") continue;
5474
+ const options = Array.isArray(field.options) ? field.options.filter((option) => typeof option === "string") : void 0;
5475
+ dynamicData[label$1] = {
5476
+ type: componentType,
5477
+ value: getFieldValue(field.data),
5478
+ options: options && options.length > 0 ? options : void 0
5479
+ };
5460
5480
  }
5461
- const item = items.find((entry) => rowByItemId.get(entry.nodeId) === currentRow);
5462
- if (item) {
5463
- for (const participant of participants) {
5464
- if (participant.createdRow !== currentRow) continue;
5465
- const keyword = participant.type === "actor" ? "actor" : "participant";
5466
- lines.push(`${indent()}create ${participantDeclaration(participant, keyword)}`);
5467
- }
5468
- for (const participant of participants) {
5469
- if (participant.destroyedRow !== currentRow) continue;
5470
- lines.push(`${indent()}destroy ${participant.mermaidId}`);
5481
+ if (nameField && !name && isEmptyFieldValue(nameRawValue)) {
5482
+ const nameType = pickString(nameField.type);
5483
+ if (nameType && isComponentInputType(nameType)) {
5484
+ const nameOptions = Array.isArray(nameField.options) ? nameField.options.filter((option) => typeof option === "string") : void 0;
5485
+ dynamicData.Name = {
5486
+ type: nameType,
5487
+ value: "",
5488
+ options: nameOptions && nameOptions.length > 0 ? nameOptions : void 0
5489
+ };
5471
5490
  }
5472
- for (const participant of participants) for (const activation of participant.activations) {
5473
- if (activation.startRow !== currentRow) continue;
5474
- lines.push(`${indent()}activate ${participant.mermaidId}`);
5491
+ }
5492
+ if (textField && !textValue && isEmptyFieldValue(textRawValue)) {
5493
+ const textType = pickString(textField.type);
5494
+ if (textType && isComponentInputType(textType)) {
5495
+ const textOptions = Array.isArray(textField.options) ? textField.options.filter((option) => typeof option === "string") : void 0;
5496
+ dynamicData.Text = {
5497
+ type: textType,
5498
+ value: "",
5499
+ options: textOptions && textOptions.length > 0 ? textOptions : void 0
5500
+ };
5475
5501
  }
5476
- if (item.kind === "message") {
5477
- const from = participantByNodeId.get(item.fromNodeId);
5478
- const to = participantByNodeId.get(item.toNodeId);
5479
- if (from && to) {
5480
- const source = item.centralSource ? `${from.mermaidId}()` : from.mermaidId;
5481
- const target = item.centralTarget ? `()${to.mermaidId}` : to.mermaidId;
5482
- lines.push(`${indent()}${source}${item.token}${target}: ${encodeLabel(item.label)}`);
5483
- }
5484
- }
5485
- if (item.kind === "note") {
5486
- const names = item.participantNodeIds.map((nodeId) => {
5487
- var _participantByNodeId$;
5488
- return (_participantByNodeId$ = participantByNodeId.get(nodeId)) === null || _participantByNodeId$ === void 0 ? void 0 : _participantByNodeId$.mermaidId;
5489
- }).filter((id) => id !== void 0);
5490
- if (names.length > 0) lines.push(`${indent()}Note ${item.placement} ${names.join(",")}: ${encodeLabel(item.text)}`);
5491
- }
5492
- }
5493
- const rowEnd = item ? lastRowByItemId.get(item.nodeId) : currentRow;
5494
- for (const participant of participants) for (const activation of participant.activations) {
5495
- if (activation.endRow !== rowEnd) continue;
5496
- lines.push(`${indent()}deactivate ${participant.mermaidId}`);
5497
5502
  }
5498
- while (openBlocks.length > 0 && openBlocks[openBlocks.length - 1].endRow <= rowEnd) {
5499
- openBlocks.pop();
5500
- lines.push(`${indent()}end`);
5503
+ if (codeField && !codeValue && isEmptyFieldValue(codeRawValue)) {
5504
+ const codeType = pickString(codeField.type);
5505
+ if (codeType && isComponentInputType(codeType)) {
5506
+ const codeOptions = Array.isArray(codeField.options) ? codeField.options.filter((option) => typeof option === "string") : void 0;
5507
+ dynamicData.Code = {
5508
+ type: codeType,
5509
+ value: "",
5510
+ options: codeOptions && codeOptions.length > 0 ? codeOptions : void 0
5511
+ };
5512
+ }
5501
5513
  }
5514
+ if (Object.keys(dynamicData).length > 0) nodeContext.data = dynamicData;
5515
+ const position = pickPosition(node.position);
5516
+ if (position) nodeContext.___position = position;
5517
+ const internalData = Object.entries(nodeData$1).reduce((acc, [key, value]) => {
5518
+ if (KNOWN_NODE_DATA_KEYS.has(key)) return acc;
5519
+ acc[key] = value;
5520
+ return acc;
5521
+ }, {});
5522
+ if (nodeType === "builder" && Array.isArray(nodeData$1.componentFields)) internalData.componentFields = nodeData$1.componentFields;
5523
+ const iconSrc = pickString(nodeData$1.iconSrc);
5524
+ if (iconSrc) internalData.iconSrc = iconSrc;
5525
+ const label = pickString(nodeData$1.label);
5526
+ if (label) internalData.label = label;
5527
+ const internalCloud = pickString(nodeData$1.cloud);
5528
+ if (internalCloud) internalData.cloud = internalCloud;
5529
+ if (Object.keys(internalData).length > 0) nodeContext.___internal = internalData;
5530
+ if (Object.keys(nodeContext).length > 0) contextNodes[mappedNodeId] = nodeContext;
5502
5531
  }
5503
- while (openBlocks.length > 0) {
5504
- openBlocks.pop();
5505
- lines.push(`${indent()}end`);
5532
+ return contextNodes;
5533
+ }
5534
+ function buildValidatedContext(graphNodes, edges, groupNodes, nodeIdMap) {
5535
+ const contextNodes = buildContextNodes(graphNodes, nodeIdMap);
5536
+ const contextEdges = buildContextEdges(edges, nodeIdMap);
5537
+ const contextGroups = buildContextGroups(groupNodes, nodeIdMap);
5538
+ const context = {};
5539
+ if (Object.keys(contextNodes).length > 0) context.nodes = contextNodes;
5540
+ if (Object.keys(contextEdges).length > 0) context.edges = contextEdges;
5541
+ if (Object.keys(contextGroups).length > 0) context.groups = contextGroups;
5542
+ return contextSchema.parse(context);
5543
+ }
5544
+ function nodeData(node) {
5545
+ var _node$data;
5546
+ return (_node$data = node.data) !== null && _node$data !== void 0 ? _node$data : {};
5547
+ }
5548
+ function edgeData(edge) {
5549
+ var _edge$data;
5550
+ return (_edge$data = edge.data) !== null && _edge$data !== void 0 ? _edge$data : {};
5551
+ }
5552
+ function isC4ReactFlowDiagram(nodes) {
5553
+ return nodes.some((node) => node.type === "c4" || node.type === "c4Boundary");
5554
+ }
5555
+ function isC4Element(node) {
5556
+ if (node.type !== "c4" && node.type !== "subDiagram") return false;
5557
+ const kind = nodeData(node).c4Kind;
5558
+ return kind === "person" || kind === "system" || kind === "container" || kind === "component";
5559
+ }
5560
+ function isC4Boundary(node) {
5561
+ return node.type === "c4Boundary";
5562
+ }
5563
+ function quoteC4Value(value) {
5564
+ return `"${value.replace(/"/g, "\\\"").replace(/\r\n?/g, "\n").replace(/\n/g, "<br/>").trim()}"`;
5565
+ }
5566
+ function nodeName(node) {
5567
+ var _node$data2;
5568
+ const fields = (_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.componentFields;
5569
+ if (Array.isArray(fields)) {
5570
+ var _field$data;
5571
+ const field = fields.find((candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.componentFieldId) === "name");
5572
+ const value = field === null || field === void 0 || (_field$data = field.data) === null || _field$data === void 0 || (_field$data = _field$data[0]) === null || _field$data === void 0 ? void 0 : _field$data.value;
5573
+ if (typeof value === "string" && value.trim()) return value;
5574
+ }
5575
+ const diagramName = nodeData(node).diagramName;
5576
+ if (typeof diagramName === "string" && diagramName) return diagramName;
5577
+ return node.id;
5578
+ }
5579
+ function c4ElementKeyword(kind, shape, isExternal) {
5580
+ let keyword;
5581
+ if (kind === "person") keyword = "Person";
5582
+ else if (kind === "system") keyword = "System";
5583
+ else if (kind === "container") keyword = "Container";
5584
+ else if (kind === "component") keyword = "Component";
5585
+ else throw new Error(`Unsupported C4 element kind: ${String(kind)}`);
5586
+ if (shape === "db") keyword += "Db";
5587
+ if (shape === "queue") keyword += "Queue";
5588
+ if (isExternal) keyword += "_Ext";
5589
+ return keyword;
5590
+ }
5591
+ function c4BoundaryKeyword(kind, nodeType) {
5592
+ if (kind === "enterprise") return "Enterprise_Boundary";
5593
+ if (kind === "system") return "System_Boundary";
5594
+ if (kind === "container") return "Container_Boundary";
5595
+ if (kind === "node") {
5596
+ if (nodeType === "nodeL") return "Node_L";
5597
+ if (nodeType === "nodeR") return "Node_R";
5598
+ return "Deployment_Node";
5599
+ }
5600
+ return "Boundary";
5601
+ }
5602
+ function c4RelationshipKeyword(direction) {
5603
+ if (direction === "default") return "Rel";
5604
+ if (direction === "bi") return "BiRel";
5605
+ if (direction === "back") return "Rel_Back";
5606
+ if (direction === "up") return "Rel_U";
5607
+ if (direction === "down") return "Rel_D";
5608
+ if (direction === "left") return "Rel_L";
5609
+ if (direction === "right") return "Rel_R";
5610
+ throw new Error(`Unsupported C4 relationship direction: ${String(direction)}`);
5611
+ }
5612
+ function resolveRelDirection(edge) {
5613
+ const stored = edgeData(edge).c4RelDirection;
5614
+ if (stored) return stored;
5615
+ if (edge.markerStart) return "bi";
5616
+ if (edge.sourceHandle === "source-top") return "up";
5617
+ if (edge.sourceHandle === "source-bottom") return "down";
5618
+ if (edge.sourceHandle === "source-left") return "left";
5619
+ if (edge.sourceHandle === "source-right") return "right";
5620
+ return "default";
5621
+ }
5622
+ function relationshipLabel(edge, technology) {
5623
+ const label = typeof edge.label === "string" ? edge.label : "";
5624
+ if (!technology) return label;
5625
+ const suffix = ` [${technology}]`;
5626
+ if (label.endsWith(suffix)) return label.slice(0, -suffix.length);
5627
+ return label;
5628
+ }
5629
+ function resolveDiagramType(c4Nodes) {
5630
+ for (const node of c4Nodes) {
5631
+ const stored = nodeData(node).c4DiagramType;
5632
+ if (stored) return stored;
5633
+ }
5634
+ if (c4Nodes.some((node) => nodeData(node).c4Kind === "component")) return "C4Component";
5635
+ if (c4Nodes.some((node) => nodeData(node).c4Kind === "container")) return "C4Container";
5636
+ return "C4Context";
5637
+ }
5638
+ function trimTrailingSlots(values, keep) {
5639
+ const trimmed = [...values];
5640
+ while (trimmed.length > keep && trimmed[trimmed.length - 1] === "") trimmed.pop();
5641
+ return trimmed;
5642
+ }
5643
+ function emitC4Mermaid(nodes, edges) {
5644
+ const c4Nodes = nodes.filter((node) => isC4Element(node) || isC4Boundary(node));
5645
+ const c4NodeIds = new Set(c4Nodes.map((node) => node.id));
5646
+ const boundaryIds = new Set(c4Nodes.filter((node) => isC4Boundary(node)).map((node) => node.id));
5647
+ function parentOf(node) {
5648
+ if (node.parentId && boundaryIds.has(node.parentId)) return node.parentId;
5649
+ }
5650
+ function renderNode(node, indentation) {
5651
+ const data = nodeData(node);
5652
+ const name = quoteC4Value(nodeName(node));
5653
+ if (isC4Element(node)) {
5654
+ const values$1 = [node.id, name];
5655
+ if (data.c4Kind === "container" || data.c4Kind === "component") values$1.push(data.technology ? quoteC4Value(data.technology) : "");
5656
+ values$1.push(data.description ? quoteC4Value(data.description) : "");
5657
+ const trimmed$1 = trimTrailingSlots(values$1, 2);
5658
+ const link = data.diagramId ? `uig:${data.diagramId}` : data.link;
5659
+ if (link) trimmed$1.push(`$link=${quoteC4Value(link)}`);
5660
+ return `${indentation}${c4ElementKeyword(data.c4Kind, data.c4Shape, data.isExternal === true)}(${trimmed$1.join(", ")})`;
5661
+ }
5662
+ const keyword = c4BoundaryKeyword(data.c4BoundaryKind, data.c4NodeType);
5663
+ const values = [node.id, name];
5664
+ if (keyword === "Boundary" && data.boundaryType) values.push(quoteC4Value(data.boundaryType));
5665
+ if (data.c4BoundaryKind === "node") {
5666
+ values.push(data.boundaryType ? quoteC4Value(data.boundaryType) : "\"node\"");
5667
+ values.push(data.description ? quoteC4Value(data.description) : "");
5668
+ }
5669
+ const trimmed = trimTrailingSlots(values, 2);
5670
+ if (data.link) trimmed.push(`$link=${quoteC4Value(data.link)}`);
5671
+ return `${indentation}${keyword}(${trimmed.join(", ")}) {`;
5672
+ }
5673
+ function renderChildren(parentId, indentation) {
5674
+ const lines = [];
5675
+ for (const node of c4Nodes) {
5676
+ if (parentOf(node) !== parentId) continue;
5677
+ lines.push(renderNode(node, indentation));
5678
+ if (isC4Boundary(node)) {
5679
+ lines.push(...renderChildren(node.id, `${indentation} `));
5680
+ lines.push(`${indentation}}`);
5681
+ }
5682
+ }
5683
+ return lines;
5506
5684
  }
5507
- return lines.join("\n");
5685
+ const relationships = edges.flatMap((edge) => {
5686
+ if (!c4NodeIds.has(edge.source) || !c4NodeIds.has(edge.target)) return [];
5687
+ const data = edgeData(edge);
5688
+ const direction = resolveRelDirection(edge);
5689
+ const isBack = direction === "back";
5690
+ const values = [
5691
+ isBack ? edge.target : edge.source,
5692
+ isBack ? edge.source : edge.target,
5693
+ quoteC4Value(relationshipLabel(edge, data.c4RelTechnology)),
5694
+ data.c4RelTechnology ? quoteC4Value(data.c4RelTechnology) : "",
5695
+ data.c4RelDescription ? quoteC4Value(data.c4RelDescription) : ""
5696
+ ];
5697
+ return `${c4RelationshipKeyword(direction)}(${trimTrailingSlots(values, 3).join(", ")})`;
5698
+ });
5699
+ return {
5700
+ mermaid: [
5701
+ resolveDiagramType(c4Nodes),
5702
+ ...renderChildren(void 0, ""),
5703
+ ...relationships
5704
+ ].join("\n"),
5705
+ nodeIdMap: new Map(c4Nodes.map((node) => [node.id, node.id]))
5706
+ };
5508
5707
  }
5509
- const BOUND_PADDING = 20;
5510
- function createGroupNode(options) {
5511
- var _options$id, _options$name;
5708
+ function convertReactFlowToC4Mermaid(nodes, edges) {
5709
+ return emitC4Mermaid(nodes, edges).mermaid;
5710
+ }
5711
+ function convertReactFlowToC4UiGraph(nodes, edges) {
5712
+ const { mermaid: mermaid$1, nodeIdMap } = emitC4Mermaid(nodes, edges);
5512
5713
  return {
5513
- id: (_options$id = options.id) !== null && _options$id !== void 0 ? _options$id : generateUUID$1(),
5514
- type: "group",
5515
- position: {
5516
- x: options.bounds.x,
5517
- y: options.bounds.y
5518
- },
5519
- data: {
5520
- childNodes: options.nodes,
5521
- autoLayout: true,
5522
- componentFields: [generateComponentFieldNameInput((_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : "Group")]
5523
- },
5524
- style: {
5525
- width: options.bounds.width + 20,
5526
- height: options.bounds.height + 50
5527
- }
5714
+ mermaid: mermaid$1,
5715
+ context: buildValidatedContext(nodes, edges, [], nodeIdMap)
5528
5716
  };
5529
5717
  }
5530
- function generateGroupNodeFromNodes(id, name, nodes) {
5531
- const bounds = nodes.map((node) => {
5532
- var _ref, _ref2, _node$height, _node$style, _node$measured, _ref3, _ref4, _node$width, _node$style2, _node$measured2;
5533
- return {
5534
- top: node.position.y,
5535
- left: node.position.x,
5536
- bottom: node.position.y + ((_ref = (_ref2 = (_node$height = node.height) !== null && _node$height !== void 0 ? _node$height : (_node$style = node.style) === null || _node$style === void 0 ? void 0 : _node$style.height) !== null && _ref2 !== void 0 ? _ref2 : (_node$measured = node.measured) === null || _node$measured === void 0 ? void 0 : _node$measured.height) !== null && _ref !== void 0 ? _ref : 0),
5537
- right: node.position.x + ((_ref3 = (_ref4 = (_node$width = node.width) !== null && _node$width !== void 0 ? _node$width : (_node$style2 = node.style) === null || _node$style2 === void 0 ? void 0 : _node$style2.width) !== null && _ref4 !== void 0 ? _ref4 : (_node$measured2 = node.measured) === null || _node$measured2 === void 0 ? void 0 : _node$measured2.width) !== null && _ref3 !== void 0 ? _ref3 : 0)
5538
- };
5539
- });
5540
- const minX = Math.min(...bounds.map((b) => b.left));
5541
- const minY = Math.min(...bounds.map((b) => b.top));
5542
- const maxX = Math.max(...bounds.map((b) => b.right));
5543
- const maxY = Math.max(...bounds.map((b) => b.bottom));
5544
- return createGroupNode({
5545
- id,
5546
- name,
5547
- nodes: nodes.map((node) => node.id),
5548
- bounds: {
5549
- x: minX - BOUND_PADDING,
5550
- y: minY - BOUND_PADDING,
5551
- width: maxX - minX + BOUND_PADDING * 2,
5552
- height: maxY - minY + BOUND_PADDING * 2
5553
- }
5718
+ function sanitizeMermaidLabels(src) {
5719
+ if (!src) return src;
5720
+ const subgraphFixed = src.replace(/([A-Za-z0-9_]+)\[((?:(?![\"']).)*?)\]/g, (m, id, label) => {
5721
+ if (/^[\"']/.test(label)) return m;
5722
+ if (/[()\"\[\],:;]/.test(label)) return `${id}[\"${String(label).replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"]`;
5723
+ return m;
5724
+ }).replace(/^([ \t]*subgraph\s+)([^\n\r]+)(\|[^\n\r]*)?$/gim, (m, pre, title, rest) => {
5725
+ const t = String(title).trim();
5726
+ if (/^[\"']/.test(t)) return m;
5727
+ if (/[()\"\[\],:;]/.test(t)) return `${pre}\"${t.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"")}\"${rest || ""}`;
5728
+ return m;
5554
5729
  });
5730
+ const diagRegex = /\b(graph|flowchart|sequenceDiagram|stateDiagram|classDiagram|gantt|journey|erDiagram|gitGraph|pie|timeline|infoDiagram)\b/i;
5731
+ const allStarts = [];
5732
+ let mm;
5733
+ const globalRegex = new RegExp(diagRegex.source, "gim");
5734
+ while ((mm = globalRegex.exec(subgraphFixed)) !== null) {
5735
+ allStarts.push(mm.index);
5736
+ if (globalRegex.lastIndex === mm.index) globalRegex.lastIndex++;
5737
+ }
5738
+ if (allStarts.length <= 1) return subgraphFixed;
5739
+ const first = allStarts[0];
5740
+ const second = allStarts[1];
5741
+ return subgraphFixed.slice(first, second).trim();
5555
5742
  }
5556
- function resolveCloudIcon(_x, _x2) {
5557
- return _resolveCloudIcon.apply(this, arguments);
5743
+ function isSequenceDiagram(nodes) {
5744
+ return nodes.some((node) => node.type === "sequenceParticipant");
5558
5745
  }
5559
- function _resolveCloudIcon() {
5560
- _resolveCloudIcon = _asyncToGenerator(function* (cloud, serviceName) {
5561
- const cloudName = cloud === null || cloud === void 0 ? void 0 : cloud.toLowerCase();
5562
- const icon = (cloudName === "azure" ? [...(yield import("./__azure-icons.DgR1F6C6.mjs")).default] : cloudName === "aws" ? [...(yield import("./__aws-icons.agWBtDk7.mjs")).default] : [...(yield import("./__aws-icons.agWBtDk7.mjs")).default, ...(yield import("./__azure-icons.DgR1F6C6.mjs")).default]).find((icon$1) => icon$1.name.toLowerCase() === serviceName.toLowerCase());
5563
- if (!icon) return null;
5564
- return `/${icon.cloud.toLowerCase()}-icons/${icon.relativePath}`;
5565
- });
5566
- return _resolveCloudIcon.apply(this, arguments);
5746
+ function fieldValue(node, componentFieldId) {
5747
+ var _node$data, _field$data;
5748
+ const fields = (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.componentFields;
5749
+ if (!Array.isArray(fields)) return void 0;
5750
+ const field = fields.find((candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.componentFieldId) === componentFieldId);
5751
+ const value = field === null || field === void 0 || (_field$data = field.data) === null || _field$data === void 0 || (_field$data = _field$data[0]) === null || _field$data === void 0 ? void 0 : _field$data.value;
5752
+ if (typeof value !== "string") return void 0;
5753
+ if (!value.trim()) return void 0;
5754
+ return value;
5567
5755
  }
5568
- function resolveAnimatedNode(_x3) {
5569
- return _resolveAnimatedNode.apply(this, arguments);
5756
+ function nodeLabel(node) {
5757
+ var _node$data2;
5758
+ const fromField = fieldValue(node, "name");
5759
+ if (fromField !== void 0) return fromField;
5760
+ const label = (_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.label;
5761
+ if (typeof label === "string") return label;
5762
+ return "";
5570
5763
  }
5571
- function _resolveAnimatedNode() {
5572
- _resolveAnimatedNode = _asyncToGenerator(function* (animatedIcon) {
5573
- const node = (yield import("./__animated-nodes.DI0XYTuw.mjs")).default.find((node$1) => node$1.name.toLowerCase() === animatedIcon.toLowerCase());
5574
- if (!node) return null;
5575
- return `/animated-nodes/${node.fileName}`;
5764
+ function encodeLabel(text) {
5765
+ return text.replace(/#/g, "&#35;").replace(/\r\n?/g, "\n").replace(/\n/g, "<br/>").trim();
5766
+ }
5767
+ function toMermaidId(name, index, used) {
5768
+ const base = name.replace(/[^A-Za-z0-9_]/g, "") || `P${index}`;
5769
+ let candidate = base;
5770
+ let suffix = 2;
5771
+ while (used.has(candidate)) {
5772
+ candidate = `${base}_${suffix}`;
5773
+ suffix++;
5774
+ }
5775
+ used.add(candidate);
5776
+ return candidate;
5777
+ }
5778
+ function collectParticipants(nodes) {
5779
+ const used = /* @__PURE__ */ new Set();
5780
+ return nodes.filter((node) => node.type === "sequenceParticipant").sort((a, b) => a.position.x - b.position.x).map((node, index) => {
5781
+ var _node$data3, _node$data4, _node$data5, _node$data6, _node$data7;
5782
+ const name = nodeLabel(node) || `Participant ${index + 1}`;
5783
+ const rawType = (_node$data3 = node.data) === null || _node$data3 === void 0 ? void 0 : _node$data3.participantType;
5784
+ const activations = (_node$data4 = node.data) === null || _node$data4 === void 0 ? void 0 : _node$data4.activations;
5785
+ const links = (_node$data5 = node.data) === null || _node$data5 === void 0 ? void 0 : _node$data5.links;
5786
+ const createdRow = (_node$data6 = node.data) === null || _node$data6 === void 0 ? void 0 : _node$data6.lifelineStartRow;
5787
+ const destroyedRow = (_node$data7 = node.data) === null || _node$data7 === void 0 ? void 0 : _node$data7.lifelineEndRow;
5788
+ return _objectSpread2(_objectSpread2(_objectSpread2({
5789
+ nodeId: node.id,
5790
+ mermaidId: toMermaidId(name, index, used),
5791
+ name,
5792
+ type: typeof rawType === "string" ? rawType : "participant",
5793
+ links: Array.isArray(links) ? links : [],
5794
+ activations: Array.isArray(activations) ? activations : []
5795
+ }, typeof createdRow === "number" ? { createdRow } : {}), typeof destroyedRow === "number" ? { destroyedRow } : {}), {}, { x: node.position.x });
5576
5796
  });
5577
- return _resolveAnimatedNode.apply(this, arguments);
5578
5797
  }
5579
- const EXPECTED_NODE_SIZE = {
5580
- databaseTableSQL: {
5581
- width: 500,
5582
- height: 400
5583
- },
5584
- table: {
5585
- width: 600,
5586
- height: 400
5587
- },
5588
- code: {
5589
- width: 300,
5590
- height: 400
5798
+ function buildMessageLinks(edges, participantNodeIds) {
5799
+ const links = /* @__PURE__ */ new Map();
5800
+ for (const edge of edges) {
5801
+ if (participantNodeIds.has(edge.source)) links.set(edge.target, _objectSpread2(_objectSpread2({}, links.get(edge.target)), {}, { from: edge.source }));
5802
+ if (participantNodeIds.has(edge.target)) links.set(edge.source, _objectSpread2(_objectSpread2({}, links.get(edge.source)), {}, { to: edge.target }));
5591
5803
  }
5592
- };
5593
- const GROUP_BOUND_PADDING = 20;
5594
- const GROUP_WIDTH_PADDING = 20;
5595
- const GROUP_HEIGHT_PADDING = 50;
5596
- const MIN_HORIZONTAL_GAP = 140;
5597
- const ROW_ALIGNMENT_TOLERANCE = 80;
5598
- function resolveDimension(value) {
5599
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
5804
+ return links;
5600
5805
  }
5601
- function getNodeSize(node) {
5602
- var _ref, _ref2, _ref3, _resolveDimension, _node$style, _node$measured, _ref4, _ref5, _ref6, _resolveDimension2, _node$style2, _node$measured2;
5603
- const expectedSize = node.type ? EXPECTED_NODE_SIZE[node.type] : void 0;
5604
- return {
5605
- width: (_ref = (_ref2 = (_ref3 = (_resolveDimension = resolveDimension(node.width)) !== null && _resolveDimension !== void 0 ? _resolveDimension : resolveDimension((_node$style = node.style) === null || _node$style === void 0 ? void 0 : _node$style.width)) !== null && _ref3 !== void 0 ? _ref3 : resolveDimension((_node$measured = node.measured) === null || _node$measured === void 0 ? void 0 : _node$measured.width)) !== null && _ref2 !== void 0 ? _ref2 : expectedSize === null || expectedSize === void 0 ? void 0 : expectedSize.width) !== null && _ref !== void 0 ? _ref : 0,
5606
- height: (_ref4 = (_ref5 = (_ref6 = (_resolveDimension2 = resolveDimension(node.height)) !== null && _resolveDimension2 !== void 0 ? _resolveDimension2 : resolveDimension((_node$style2 = node.style) === null || _node$style2 === void 0 ? void 0 : _node$style2.height)) !== null && _ref6 !== void 0 ? _ref6 : resolveDimension((_node$measured2 = node.measured) === null || _node$measured2 === void 0 ? void 0 : _node$measured2.height)) !== null && _ref5 !== void 0 ? _ref5 : expectedSize === null || expectedSize === void 0 ? void 0 : expectedSize.height) !== null && _ref4 !== void 0 ? _ref4 : 0
5607
- };
5806
+ function arrowTokenOf(edgeFrom, edgeTo) {
5807
+ var _edgeTo$data$arrowTyp, _edgeTo$data, _edgeFrom$data, _edgeTo$data$half, _edgeTo$data2, _edgeFrom$data2, _edgeFrom$data3, _ref, _ref2;
5808
+ const arrowType = (_edgeTo$data$arrowTyp = edgeTo === null || edgeTo === void 0 || (_edgeTo$data = edgeTo.data) === null || _edgeTo$data === void 0 ? void 0 : _edgeTo$data.arrowType) !== null && _edgeTo$data$arrowTyp !== void 0 ? _edgeTo$data$arrowTyp : edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data = edgeFrom.data) === null || _edgeFrom$data === void 0 ? void 0 : _edgeFrom$data.arrowType;
5809
+ const half = (_edgeTo$data$half = edgeTo === null || edgeTo === void 0 || (_edgeTo$data2 = edgeTo.data) === null || _edgeTo$data2 === void 0 ? void 0 : _edgeTo$data2.half) !== null && _edgeTo$data$half !== void 0 ? _edgeTo$data$half : edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data2 = edgeFrom.data) === null || _edgeFrom$data2 === void 0 ? void 0 : _edgeFrom$data2.half;
5810
+ const reversed = (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data3 = edgeFrom.data) === null || _edgeFrom$data3 === void 0 ? void 0 : _edgeFrom$data3.reversed) === true;
5811
+ return findArrowTokenFor(_objectSpread2(_objectSpread2({
5812
+ lineStyle: (edgeTo === null || edgeTo === void 0 || (_ref = edgeTo.style) === null || _ref === void 0 ? void 0 : _ref.strokeDasharray) !== void 0 || (edgeFrom === null || edgeFrom === void 0 || (_ref2 = edgeFrom.style) === null || _ref2 === void 0 ? void 0 : _ref2.strokeDasharray) !== void 0 ? "dashed" : "solid",
5813
+ arrowType: arrowType !== null && arrowType !== void 0 ? arrowType : "filled"
5814
+ }, half ? { half } : {}), {}, { reversed }));
5608
5815
  }
5609
- function resizeNodesLayouts(nodes) {
5610
- const resizeRules = nodes.map((node) => {
5611
- if (!node.type) return;
5612
- const expectedSize = EXPECTED_NODE_SIZE[node.type];
5613
- if (!expectedSize) return;
5614
- const size = getNodeSize(node);
5615
- return {
5616
- startX: node.position.x + expectedSize.width,
5617
- startY: node.position.y + expectedSize.height,
5618
- deltaX: Math.max(0, size.width - expectedSize.width),
5619
- deltaY: Math.max(0, size.height - expectedSize.height)
5620
- };
5621
- }).filter((rule) => Boolean(rule));
5622
- const resizedNodes = nodes.map((node) => {
5623
- var _node$data;
5624
- const childNodeIds = (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.childNodes;
5625
- if (Array.isArray(childNodeIds)) return _objectSpread2({}, node);
5626
- const offsetX = resizeRules.reduce((total, rule) => {
5627
- if (!rule || rule.deltaX === 0 || node.position.x < rule.startX) return total;
5628
- return total + rule.deltaX;
5629
- }, 0);
5630
- const offsetY = resizeRules.reduce((total, rule) => {
5631
- if (!rule || rule.deltaY === 0 || node.position.y < rule.startY) return total;
5632
- return total + rule.deltaY;
5633
- }, 0);
5634
- if (offsetX === 0 && offsetY === 0) return node;
5635
- return _objectSpread2(_objectSpread2({}, node), {}, { position: {
5636
- x: node.position.x + offsetX,
5637
- y: node.position.y + offsetY
5638
- } });
5639
- });
5640
- const resizedNodesById = new Map(resizedNodes.map((node) => [node.id, node]));
5641
- const rowNodes = resizedNodes.filter((node) => {
5642
- var _node$data2;
5643
- return !Array.isArray((_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.childNodes);
5644
- }).sort((a, b) => a.position.y === b.position.y ? a.position.x - b.position.x : a.position.y - b.position.y);
5645
- const rows = [];
5646
- for (const node of rowNodes) {
5647
- const row = rows.find((currentRow) => Math.abs(currentRow[0].position.y - node.position.y) <= ROW_ALIGNMENT_TOLERANCE);
5648
- if (row) {
5649
- row.push(node);
5816
+ function noteParticipantNodeIds(note, participants, noteNode$1) {
5817
+ const byImportedId = (Array.isArray(note.participants) ? note.participants.filter((value) => typeof value === "string") : []).map((id) => participants.find((participant) => participant.nodeId === `participant-${id}`)).filter((participant) => Boolean(participant));
5818
+ if (byImportedId.length > 0) return byImportedId.map((participant) => participant.nodeId);
5819
+ if (participants.length === 0) return [];
5820
+ const noteCenter = noteNode$1.position.x + (Number(noteNode$1.width) || 0) / 2;
5821
+ return [[...participants].sort((a, b) => Math.abs(a.x - noteCenter) - Math.abs(b.x - noteCenter))[0].nodeId];
5822
+ }
5823
+ function collectRowItems(nodes, edges, participants) {
5824
+ const participantNodeIds = new Set(participants.map((p) => p.nodeId));
5825
+ const links = buildMessageLinks(edges, participantNodeIds);
5826
+ const items = [];
5827
+ for (const node of nodes) {
5828
+ var _node$data8, _node$data9, _edgeFrom$data4, _edgeTo$data3;
5829
+ if (participantNodeIds.has(node.id)) continue;
5830
+ const note = (_node$data8 = node.data) === null || _node$data8 === void 0 ? void 0 : _node$data8.sequenceNote;
5831
+ if (note) {
5832
+ var _note$placement;
5833
+ items.push({
5834
+ item: {
5835
+ kind: "note",
5836
+ nodeId: node.id,
5837
+ text: nodeLabel(node),
5838
+ placement: (_note$placement = note.placement) !== null && _note$placement !== void 0 ? _note$placement : "over",
5839
+ participantNodeIds: noteParticipantNodeIds(note, participants, node)
5840
+ },
5841
+ y: node.position.y
5842
+ });
5650
5843
  continue;
5651
5844
  }
5652
- rows.push([node]);
5653
- }
5654
- for (const row of rows) {
5655
- row.sort((a, b) => a.position.x - b.position.x);
5656
- for (let index = 1; index < row.length; index += 1) {
5657
- const previousNode = row[index - 1];
5658
- const currentNode = row[index];
5659
- const previousNodeSize = getNodeSize(previousNode);
5660
- const minimumX = previousNode.position.x + previousNodeSize.width + MIN_HORIZONTAL_GAP;
5661
- if (currentNode.position.x >= minimumX) continue;
5662
- const shiftedNode = _objectSpread2(_objectSpread2({}, currentNode), {}, { position: {
5663
- x: minimumX,
5664
- y: currentNode.position.y
5665
- } });
5666
- row[index] = shiftedNode;
5667
- resizedNodesById.set(shiftedNode.id, shiftedNode);
5668
- }
5669
- }
5670
- return resizedNodes.map((node) => {
5671
- var _resizedNodesById$get, _node$data3;
5672
- const shiftedNode = (_resizedNodesById$get = resizedNodesById.get(node.id)) !== null && _resizedNodesById$get !== void 0 ? _resizedNodesById$get : node;
5673
- const childNodeIds = (_node$data3 = node.data) === null || _node$data3 === void 0 ? void 0 : _node$data3.childNodes;
5674
- if (!Array.isArray(childNodeIds)) return shiftedNode;
5675
- const childNodes = childNodeIds.map((childNodeId) => typeof childNodeId === "string" ? resizedNodesById.get(childNodeId) : void 0).filter((childNode) => Boolean(childNode));
5676
- if (childNodes.length === 0) return shiftedNode;
5677
- const bounds = childNodes.map((childNode) => {
5678
- const size = getNodeSize(childNode);
5679
- return {
5680
- left: childNode.position.x,
5681
- top: childNode.position.y,
5682
- right: childNode.position.x + size.width,
5683
- bottom: childNode.position.y + size.height
5684
- };
5685
- });
5686
- const minX = Math.min(...bounds.map((bound) => bound.left));
5687
- const minY = Math.min(...bounds.map((bound) => bound.top));
5688
- const maxX = Math.max(...bounds.map((bound) => bound.right));
5689
- const maxY = Math.max(...bounds.map((bound) => bound.bottom));
5690
- return _objectSpread2(_objectSpread2({}, shiftedNode), {}, {
5691
- position: {
5692
- x: minX - GROUP_BOUND_PADDING,
5693
- y: minY - GROUP_BOUND_PADDING
5694
- },
5695
- style: _objectSpread2(_objectSpread2({}, shiftedNode.style), {}, {
5696
- width: maxX - minX + GROUP_BOUND_PADDING * 2 + GROUP_WIDTH_PADDING,
5697
- height: maxY - minY + GROUP_BOUND_PADDING * 2 + GROUP_HEIGHT_PADDING
5698
- })
5845
+ const link = links.get(node.id);
5846
+ if (!(link === null || link === void 0 ? void 0 : link.from) || !link.to) continue;
5847
+ const edgeFrom = edges.find((edge) => edge.target === node.id && edge.source === link.from);
5848
+ const edgeTo = edges.find((edge) => edge.source === node.id && edge.target === link.to);
5849
+ const sequenceNumber = (_node$data9 = node.data) === null || _node$data9 === void 0 ? void 0 : _node$data9.sequenceNumber;
5850
+ items.push({
5851
+ item: _objectSpread2({
5852
+ kind: "message",
5853
+ nodeId: node.id,
5854
+ fromNodeId: link.from,
5855
+ toNodeId: link.to,
5856
+ label: nodeLabel(node),
5857
+ token: arrowTokenOf(edgeFrom, edgeTo),
5858
+ centralSource: (edgeFrom === null || edgeFrom === void 0 || (_edgeFrom$data4 = edgeFrom.data) === null || _edgeFrom$data4 === void 0 ? void 0 : _edgeFrom$data4.centralSource) === true,
5859
+ centralTarget: (edgeTo === null || edgeTo === void 0 || (_edgeTo$data3 = edgeTo.data) === null || _edgeTo$data3 === void 0 ? void 0 : _edgeTo$data3.centralTarget) === true
5860
+ }, typeof sequenceNumber === "number" ? { sequenceNumber } : {}),
5861
+ y: node.position.y
5699
5862
  });
5700
- });
5863
+ }
5864
+ return items.sort((a, b) => a.y - b.y).map((entry) => entry.item);
5701
5865
  }
5702
- function hasValidPosition(position) {
5703
- if (!position) return false;
5704
- return Number.isFinite(position.x) && Number.isFinite(position.y);
5866
+ function collectBlocks(nodes) {
5867
+ const blocks = [];
5868
+ for (const node of nodes) {
5869
+ var _node$data10, _block$type, _block$label, _block$depth, _block$sections;
5870
+ const block = (_node$data10 = node.data) === null || _node$data10 === void 0 ? void 0 : _node$data10.sequenceBlock;
5871
+ if (!block) continue;
5872
+ if (typeof block.startRow !== "number") continue;
5873
+ if (typeof block.endRow !== "number") continue;
5874
+ blocks.push(_objectSpread2(_objectSpread2({
5875
+ nodeId: node.id,
5876
+ type: (_block$type = block.type) !== null && _block$type !== void 0 ? _block$type : "rect",
5877
+ label: (_block$label = block.label) !== null && _block$label !== void 0 ? _block$label : ""
5878
+ }, block.color ? { color: block.color } : {}), {}, {
5879
+ depth: (_block$depth = block.depth) !== null && _block$depth !== void 0 ? _block$depth : 0,
5880
+ startRow: block.startRow,
5881
+ endRow: block.endRow,
5882
+ sections: ((_block$sections = block.sections) !== null && _block$sections !== void 0 ? _block$sections : []).filter((section) => typeof section.startRow === "number" && typeof section.endRow === "number").map((section) => {
5883
+ var _section$label;
5884
+ return {
5885
+ label: (_section$label = section.label) !== null && _section$label !== void 0 ? _section$label : "",
5886
+ startRow: section.startRow,
5887
+ endRow: section.endRow
5888
+ };
5889
+ })
5890
+ }));
5891
+ }
5892
+ return blocks;
5705
5893
  }
5706
- function normalizeContextMarker(marker) {
5707
- if (!marker) return;
5708
- const markerType = marker.type.trim().toLowerCase();
5709
- let type;
5710
- if (markerType === "arrow") type = MarkerType.Arrow;
5711
- else if (markerType === "arrowclosed" || markerType === "arrow-closed" || markerType === "arrow_closed") type = MarkerType.ArrowClosed;
5712
- if (!type) return;
5713
- if (marker.color) return {
5714
- type,
5715
- color: marker.color
5716
- };
5717
- return { type };
5894
+ function collectBoxes(nodes, participants) {
5895
+ const boxes = [];
5896
+ for (const node of nodes) {
5897
+ var _node$data11, _node$data12, _box$label;
5898
+ const box = (_node$data11 = node.data) === null || _node$data11 === void 0 ? void 0 : _node$data11.sequenceBox;
5899
+ if (!box) continue;
5900
+ const byImportedId = (Array.isArray(box.participants) ? box.participants.filter((value) => typeof value === "string") : []).map((id) => participants.find((participant) => participant.nodeId === `participant-${id}`)).filter((participant) => Boolean(participant));
5901
+ const left = node.position.x;
5902
+ const right = node.position.x + (Number(node.width) || 0);
5903
+ const contained = byImportedId.length > 0 ? byImportedId : participants.filter((participant) => participant.x >= left && participant.x <= right);
5904
+ if (contained.length === 0) continue;
5905
+ const backgroundColor = (_node$data12 = node.data) === null || _node$data12 === void 0 ? void 0 : _node$data12.backgroundColor;
5906
+ boxes.push(_objectSpread2(_objectSpread2({
5907
+ nodeId: node.id,
5908
+ label: (_box$label = box.label) !== null && _box$label !== void 0 ? _box$label : ""
5909
+ }, typeof backgroundColor === "string" ? { color: backgroundColor } : {}), {}, { participantNodeIds: contained.map((participant) => participant.nodeId) }));
5910
+ }
5911
+ return boxes;
5718
5912
  }
5719
- function convertMermaidToReactFlowWithContext(_x3, _x4, _x5) {
5720
- return _convertMermaidToReactFlowWithContext.apply(this, arguments);
5913
+ function participantDeclaration(participant, keyword) {
5914
+ const stereotype = participant.type === "participant" || participant.type === "actor" ? "" : `@{ "type": "${participant.type}" }`;
5915
+ const alias = participant.mermaidId === participant.name ? "" : ` as ${encodeLabel(participant.name)}`;
5916
+ return `${keyword} ${participant.mermaidId}${stereotype}${alias}`;
5721
5917
  }
5722
- function _convertMermaidToReactFlowWithContext() {
5723
- _convertMermaidToReactFlowWithContext = _asyncToGenerator(function* (mermaidCode, context, options) {
5724
- var _context$groups;
5725
- const validatedContext = contextSchema.parse(context);
5726
- const reactFlowData = yield convertMermaidToReactFlow(mermaidCode);
5727
- const rfNodesPromises = reactFlowData.nodes.map(function() {
5728
- var _ref = _asyncToGenerator(function* (node) {
5729
- var _validatedContext$nod, _clonedNode$data$comp, _ctx$data, _clonedNode$data, _ctx$style, _ctx$style2, _ctx$style3, _ctx$style4;
5730
- const ctx = (_validatedContext$nod = validatedContext.nodes) === null || _validatedContext$nod === void 0 ? void 0 : _validatedContext$nod[node.id];
5731
- if (!ctx) return node;
5732
- const clonedNode = JSON.parse(JSON.stringify(node));
5733
- const componentFields = (_clonedNode$data$comp = clonedNode.data.componentFields) !== null && _clonedNode$data$comp !== void 0 ? _clonedNode$data$comp : [];
5734
- (_ctx$data = ctx.data) !== null && _ctx$data !== void 0 || (ctx.data = {});
5735
- (_clonedNode$data = clonedNode.data) !== null && _clonedNode$data !== void 0 || (clonedNode.data = {});
5736
- if (hasValidPosition(ctx.___position)) clonedNode.position = {
5737
- x: ctx.___position.x,
5738
- y: ctx.___position.y
5739
- };
5740
- if (ctx.type) {
5741
- clonedNode.type = ctx.type;
5742
- delete clonedNode.style;
5743
- if (ctx.type === "cloud") {
5744
- clonedNode.height = 150;
5745
- clonedNode.width = 150;
5746
- if (ctx.service) {
5747
- const cloudIcon = (options === null || options === void 0 ? void 0 : options.resolveCloudIcon) ? yield options.resolveCloudIcon(ctx.cloud, ctx.service) : yield resolveCloudIcon(ctx.cloud, ctx.service);
5748
- if (cloudIcon) clonedNode.data.iconSrc = cloudIcon;
5749
- }
5750
- }
5751
- if (ctx.type === "image" && ctx.src) clonedNode.data = _objectSpread2(_objectSpread2({}, clonedNode.data), {}, { src: ctx.src });
5752
- if (ctx.type === "gif") {
5753
- if (ctx.animatedIcon) {
5754
- const animatedNodeSrc = yield resolveAnimatedNode(ctx.animatedIcon);
5755
- if (animatedNodeSrc) clonedNode.data = _objectSpread2(_objectSpread2({}, clonedNode.data), {}, { src: animatedNodeSrc });
5756
- } else if (ctx.src) clonedNode.data = _objectSpread2(_objectSpread2({}, clonedNode.data), {}, { src: ctx.src });
5757
- }
5758
- if (ctx.type === "text" && (ctx.value || ctx.name)) {
5759
- const textComponentField = generateComponentFieldInput({
5760
- type: ComponentInputType.TextInput,
5761
- componentFieldId: "text",
5762
- label: "Text",
5763
- data: ctx.value || ctx.name,
5764
- isReadonly: true
5765
- });
5766
- componentFields.unshift(textComponentField);
5767
- }
5768
- if (ctx.type === "code" && ctx.value) {
5769
- const textComponentField = generateComponentFieldInput({
5770
- type: ComponentInputType.CodeEditor,
5771
- componentFieldId: "code",
5772
- label: "Code",
5773
- data: ctx.value,
5774
- isReadonly: true
5775
- });
5776
- componentFields.unshift(textComponentField);
5777
- }
5778
- if (ctx.type === "table" && ctx.table) {
5779
- var _ctx$table$rows, _ctx$table$columns;
5780
- clonedNode.data.title = ctx.name;
5781
- clonedNode.data.rows = (_ctx$table$rows = ctx.table.rows) !== null && _ctx$table$rows !== void 0 ? _ctx$table$rows : [];
5782
- clonedNode.data.columns = (_ctx$table$columns = ctx.table.columns) !== null && _ctx$table$columns !== void 0 ? _ctx$table$columns : [];
5783
- }
5784
- if (ctx.type === "data-source" || ctx.type === "db-table") {
5785
- ctx.type = "databaseTableSQL";
5786
- clonedNode.type = "databaseTableSQL";
5787
- }
5788
- if (ctx.type === "component") {
5789
- ctx.type = "builder";
5790
- clonedNode.type = "builder";
5791
- clonedNode.data.componentId = ctx.componentId;
5792
- }
5793
- if (ctx.type === "shape" && ctx.shape) {
5794
- clonedNode.data.shape = ctx.shape;
5795
- if (ctx.shape === "or" || ctx.shape === "summing-junction") {
5796
- var _clonedNode$width, _clonedNode$height;
5797
- const maxSize = Math.max((_clonedNode$width = clonedNode.width) !== null && _clonedNode$width !== void 0 ? _clonedNode$width : 0, (_clonedNode$height = clonedNode.height) !== null && _clonedNode$height !== void 0 ? _clonedNode$height : 0, 200);
5798
- clonedNode.width = maxSize;
5799
- clonedNode.height = maxSize;
5800
- }
5801
- }
5918
+ function emitSequenceMermaid(nodes, edges) {
5919
+ const nodeIdMap = /* @__PURE__ */ new Map();
5920
+ const participants = collectParticipants(nodes);
5921
+ const items = collectRowItems(nodes, edges, participants);
5922
+ const blocks = collectBlocks(nodes);
5923
+ const boxes = collectBoxes(nodes, participants);
5924
+ const participantByNodeId = new Map(participants.map((participant) => [participant.nodeId, participant]));
5925
+ for (const participant of participants) nodeIdMap.set(participant.nodeId, `participant-${participant.mermaidId}`);
5926
+ const rowByItemId = /* @__PURE__ */ new Map();
5927
+ const lastRowByItemId = /* @__PURE__ */ new Map();
5928
+ let row = 0;
5929
+ for (const item of items) {
5930
+ rowByItemId.set(item.nodeId, row);
5931
+ const isSelf = item.kind === "message" && item.fromNodeId === item.toNodeId;
5932
+ lastRowByItemId.set(item.nodeId, isSelf ? row + 1 : row);
5933
+ row += isSelf ? 2 : 1;
5934
+ }
5935
+ const rowCount = row;
5936
+ const lines = ["sequenceDiagram"];
5937
+ const titleNode = nodes.find((node) => node.id === "sequence-title");
5938
+ if (titleNode) {
5939
+ var _fieldValue;
5940
+ const text = (_fieldValue = fieldValue(titleNode, "text")) !== null && _fieldValue !== void 0 ? _fieldValue : nodeLabel(titleNode);
5941
+ if (text) {
5942
+ lines.push(` title ${encodeLabel(text)}`);
5943
+ nodeIdMap.set(titleNode.id, "sequence-title");
5944
+ }
5945
+ }
5946
+ const boxByFirstParticipant = /* @__PURE__ */ new Map();
5947
+ const boxEndByParticipant = /* @__PURE__ */ new Map();
5948
+ for (const box of boxes) {
5949
+ var _boxEndByParticipant$;
5950
+ const ordered = participants.filter((participant) => box.participantNodeIds.includes(participant.nodeId));
5951
+ if (ordered.length === 0) continue;
5952
+ boxByFirstParticipant.set(ordered[0].nodeId, box);
5953
+ boxEndByParticipant.set(ordered[ordered.length - 1].nodeId, ((_boxEndByParticipant$ = boxEndByParticipant.get(ordered[ordered.length - 1].nodeId)) !== null && _boxEndByParticipant$ !== void 0 ? _boxEndByParticipant$ : 0) + 1);
5954
+ }
5955
+ let boxIndex = 0;
5956
+ for (const participant of participants) {
5957
+ var _boxEndByParticipant$2;
5958
+ const box = boxByFirstParticipant.get(participant.nodeId);
5959
+ if (box) {
5960
+ const color = box.color ? `${box.color} ` : "";
5961
+ lines.push(` box ${color}${encodeLabel(box.label)}`.trimEnd());
5962
+ nodeIdMap.set(box.nodeId, `sequence-box-box-${boxIndex}`);
5963
+ boxIndex++;
5964
+ }
5965
+ if (participant.createdRow === void 0) {
5966
+ const keyword = participant.type === "actor" ? "actor" : "participant";
5967
+ lines.push(` ${participantDeclaration(participant, keyword)}`);
5968
+ }
5969
+ const boxEnds = (_boxEndByParticipant$2 = boxEndByParticipant.get(participant.nodeId)) !== null && _boxEndByParticipant$2 !== void 0 ? _boxEndByParticipant$2 : 0;
5970
+ for (let index = 0; index < boxEnds; index++) lines.push(" end");
5971
+ }
5972
+ for (const participant of participants) for (const link of participant.links) lines.push(` link ${participant.mermaidId}: ${link.label} @ ${link.url}`);
5973
+ const numbered = items.filter((item) => item.kind === "message" && item.sequenceNumber !== void 0);
5974
+ if (numbered.length > 0) {
5975
+ const start = numbered[0].sequenceNumber;
5976
+ const step = numbered.length > 1 ? numbered[1].sequenceNumber - numbered[0].sequenceNumber : 1;
5977
+ lines.push(` autonumber ${start} ${step}`);
5978
+ }
5979
+ const openBlocks = [];
5980
+ let blockIndex = 0;
5981
+ let parserRow = 0;
5982
+ function indent() {
5983
+ return " ".repeat(openBlocks.length + 1);
5984
+ }
5985
+ for (let currentRow = 0; currentRow < rowCount; currentRow++) {
5986
+ const opening = blocks.filter((block) => block.startRow === currentRow).sort((a, b) => a.depth - b.depth);
5987
+ for (const block of opening) {
5988
+ const label = encodeLabel(block.label);
5989
+ const color = block.type === "rect" && block.color ? `${block.color} ` : "";
5990
+ lines.push(`${indent()}${block.type} ${color}${label}`.trimEnd());
5991
+ nodeIdMap.set(block.nodeId, `sequence-block-block-${blockIndex}`);
5992
+ blockIndex++;
5993
+ openBlocks.push(block);
5994
+ }
5995
+ for (const [depth, block] of openBlocks.entries()) for (const section of block.sections.slice(1)) {
5996
+ if (section.startRow !== currentRow) continue;
5997
+ const keyword = block.type === "par" ? "and" : block.type === "critical" ? "option" : "else";
5998
+ lines.push(`${" ".repeat(depth + 1)}${keyword} ${encodeLabel(section.label)}`.trimEnd());
5999
+ }
6000
+ const item = items.find((entry) => rowByItemId.get(entry.nodeId) === currentRow);
6001
+ if (item) {
6002
+ for (const participant of participants) {
6003
+ if (participant.createdRow !== currentRow) continue;
6004
+ const keyword = participant.type === "actor" ? "actor" : "participant";
6005
+ lines.push(`${indent()}create ${participantDeclaration(participant, keyword)}`);
6006
+ }
6007
+ for (const participant of participants) {
6008
+ if (participant.destroyedRow !== currentRow) continue;
6009
+ lines.push(`${indent()}destroy ${participant.mermaidId}`);
6010
+ }
6011
+ for (const participant of participants) for (const activation of participant.activations) {
6012
+ if (activation.startRow !== currentRow) continue;
6013
+ lines.push(`${indent()}activate ${participant.mermaidId}`);
6014
+ }
6015
+ if (item.kind === "message") {
6016
+ const from = participantByNodeId.get(item.fromNodeId);
6017
+ const to = participantByNodeId.get(item.toNodeId);
6018
+ if (from && to) {
6019
+ const source = item.centralSource ? `${from.mermaidId}()` : from.mermaidId;
6020
+ const target = item.centralTarget ? `()${to.mermaidId}` : to.mermaidId;
6021
+ lines.push(`${indent()}${source}${item.token}${target}: ${encodeLabel(item.label)}`);
6022
+ nodeIdMap.set(item.nodeId, `message-${parserRow}`);
6023
+ parserRow++;
5802
6024
  }
5803
- if (ctx.name) ctx.data["Name"] = {
5804
- type: ComponentInputType.TextInput,
5805
- value: ctx.name
5806
- };
5807
- for (const key in ctx.data) {
5808
- const metaInput = ctx.data[key];
5809
- if (metaInput === void 0) continue;
5810
- const componentField = getComponentFieldByLabel(componentFields, key);
5811
- const newComponentField = generateComponentFieldInput({
5812
- label: key,
5813
- type: metaInput.type,
5814
- data: metaInput.value,
5815
- options: metaInput.options
5816
- });
5817
- if (!componentField) componentFields.push(newComponentField);
5818
- else {
5819
- componentField.type = newComponentField.type;
5820
- componentField.data = newComponentField.data;
5821
- }
6025
+ }
6026
+ if (item.kind === "note") {
6027
+ const names = item.participantNodeIds.map((nodeId) => {
6028
+ var _participantByNodeId$;
6029
+ return (_participantByNodeId$ = participantByNodeId.get(nodeId)) === null || _participantByNodeId$ === void 0 ? void 0 : _participantByNodeId$.mermaidId;
6030
+ }).filter((id) => id !== void 0);
6031
+ if (names.length > 0) {
6032
+ lines.push(`${indent()}Note ${item.placement} ${names.join(",")}: ${encodeLabel(item.text)}`);
6033
+ nodeIdMap.set(item.nodeId, `note-${parserRow}`);
6034
+ parserRow++;
5822
6035
  }
5823
- if (ctx.dbConfig) clonedNode.data.serviceTable = {
5824
- serviceName: ctx.dbConfig.serviceName,
5825
- databaseName: ctx.dbConfig.databaseName,
5826
- tableName: ctx.dbConfig.tableName
5827
- };
5828
- if ((_ctx$style = ctx.style) === null || _ctx$style === void 0 ? void 0 : _ctx$style.height) clonedNode.height = ctx.style.height;
5829
- if ((_ctx$style2 = ctx.style) === null || _ctx$style2 === void 0 ? void 0 : _ctx$style2.width) clonedNode.width = ctx.style.width;
5830
- clonedNode.data = _objectSpread2(_objectSpread2(_objectSpread2({}, clonedNode.data), objectPick((_ctx$style3 = ctx.style) !== null && _ctx$style3 !== void 0 ? _ctx$style3 : {}, [
5831
- "color",
5832
- "fill",
5833
- "stroke",
5834
- "strokeWidth",
5835
- "strokeStyle",
5836
- "borderRadius",
5837
- "borderAnimationEnabled"
5838
- ])), {}, {
5839
- componentFields,
5840
- strokeAnimation: ((_ctx$style4 = ctx.style) === null || _ctx$style4 === void 0 ? void 0 : _ctx$style4.borderAnimationEnabled) ? "dash" : void 0
5841
- }, ctx === null || ctx === void 0 ? void 0 : ctx.___internal);
5842
- return clonedNode;
5843
- });
5844
- return function(_x) {
5845
- return _ref.apply(this, arguments);
5846
- };
5847
- }());
5848
- const resolvedNodes = yield Promise.all(rfNodesPromises);
5849
- const groupNodes = Object.entries((_context$groups = context.groups) !== null && _context$groups !== void 0 ? _context$groups : {}).map(([nodeId, groupCtx]) => {
5850
- var _groupCtx$nodes, _groupCtx$name;
5851
- const childNodes = arrayNonNullable(((_groupCtx$nodes = groupCtx.nodes) !== null && _groupCtx$nodes !== void 0 ? _groupCtx$nodes : []).map((nodeId$1) => resolvedNodes.find((n) => n.id === nodeId$1)));
5852
- return generateGroupNodeFromNodes(nodeId, (_groupCtx$name = groupCtx.name) !== null && _groupCtx$name !== void 0 ? _groupCtx$name : "Group", childNodes);
5853
- });
5854
- const rfEdgesPromises = reactFlowData.edges.map(function() {
5855
- var _ref2 = _asyncToGenerator(function* (edge) {
5856
- var _validatedContext$edg, _ctx$type, _ctx$sourceHandle, _ctx$targetHandle, _normalizeContextMark, _normalizeContextMark2, _ctx$label, _ctx$style$borderAnim, _ctx$style5, _ctx$style$stroke, _ctx$style6, _edge$style, _ctx$style$strokeWidt, _ctx$style7, _edge$style2, _ctx$style8, _ctx$style9, _ctx$style10, _edge$style3;
5857
- const ctx = (_validatedContext$edg = validatedContext.edges) === null || _validatedContext$edg === void 0 ? void 0 : _validatedContext$edg[`${edge.source}-${edge.target}`];
5858
- if (!ctx) return edge;
5859
- return _objectSpread2(_objectSpread2({}, edge), {}, {
5860
- type: (_ctx$type = ctx.type) !== null && _ctx$type !== void 0 ? _ctx$type : edge.type,
5861
- sourceHandle: (_ctx$sourceHandle = ctx.sourceHandle) !== null && _ctx$sourceHandle !== void 0 ? _ctx$sourceHandle : edge.sourceHandle,
5862
- targetHandle: (_ctx$targetHandle = ctx.targetHandle) !== null && _ctx$targetHandle !== void 0 ? _ctx$targetHandle : edge.targetHandle,
5863
- markerStart: (_normalizeContextMark = normalizeContextMarker(ctx.markerStart)) !== null && _normalizeContextMark !== void 0 ? _normalizeContextMark : edge.markerStart,
5864
- markerEnd: (_normalizeContextMark2 = normalizeContextMarker(ctx.markerEnd)) !== null && _normalizeContextMark2 !== void 0 ? _normalizeContextMark2 : edge.markerEnd,
5865
- data: _objectSpread2(_objectSpread2({}, edge.data), ctx === null || ctx === void 0 ? void 0 : ctx.___internal),
5866
- label: (_ctx$label = ctx.label) !== null && _ctx$label !== void 0 ? _ctx$label : edge.label,
5867
- animated: (_ctx$style$borderAnim = (_ctx$style5 = ctx.style) === null || _ctx$style5 === void 0 ? void 0 : _ctx$style5.borderAnimationEnabled) !== null && _ctx$style$borderAnim !== void 0 ? _ctx$style$borderAnim : edge.animated,
5868
- style: _objectSpread2(_objectSpread2({}, edge.style), {}, {
5869
- stroke: (_ctx$style$stroke = (_ctx$style6 = ctx.style) === null || _ctx$style6 === void 0 ? void 0 : _ctx$style6.stroke) !== null && _ctx$style$stroke !== void 0 ? _ctx$style$stroke : (_edge$style = edge.style) === null || _edge$style === void 0 ? void 0 : _edge$style.stroke,
5870
- strokeWidth: (_ctx$style$strokeWidt = (_ctx$style7 = ctx.style) === null || _ctx$style7 === void 0 ? void 0 : _ctx$style7.strokeWidth) !== null && _ctx$style$strokeWidt !== void 0 ? _ctx$style$strokeWidt : (_edge$style2 = edge.style) === null || _edge$style2 === void 0 ? void 0 : _edge$style2.strokeWidth,
5871
- strokeDasharray: ((_ctx$style8 = ctx.style) === null || _ctx$style8 === void 0 ? void 0 : _ctx$style8.strokeStyle) === "dashed" ? "4 2" : ((_ctx$style9 = ctx.style) === null || _ctx$style9 === void 0 ? void 0 : _ctx$style9.strokeStyle) === "dotted" ? "1 2" : ((_ctx$style10 = ctx.style) === null || _ctx$style10 === void 0 ? void 0 : _ctx$style10.strokeStyle) === "solid" ? void 0 : (_edge$style3 = edge.style) === null || _edge$style3 === void 0 ? void 0 : _edge$style3.strokeDasharray
5872
- })
5873
- });
5874
- });
5875
- return function(_x2) {
5876
- return _ref2.apply(this, arguments);
5877
- };
5878
- }());
5879
- const resolvedEdges = yield Promise.all(rfEdgesPromises);
5880
- const combinedNodes = [...groupNodes, ...resolvedNodes.map((node) => {
5881
- const nodeParent = groupNodes.find((groupNode) => {
5882
- var _groupNode$data$child;
5883
- return (_groupNode$data$child = groupNode.data.childNodes) === null || _groupNode$data$child === void 0 ? void 0 : _groupNode$data$child.includes(node.id);
5884
- });
5885
- if (nodeParent) return _objectSpread2(_objectSpread2({}, node), {}, { parentId: nodeParent.id });
5886
- return node;
5887
- })];
5888
- if (isSequenceDiagram(combinedNodes)) return {
5889
- edges: resolvedEdges,
5890
- nodes: combinedNodes
5891
- };
6036
+ }
6037
+ }
6038
+ const rowEnd = item ? lastRowByItemId.get(item.nodeId) : currentRow;
6039
+ for (const participant of participants) for (const activation of participant.activations) {
6040
+ if (activation.endRow !== rowEnd) continue;
6041
+ lines.push(`${indent()}deactivate ${participant.mermaidId}`);
6042
+ }
6043
+ while (openBlocks.length > 0 && openBlocks[openBlocks.length - 1].endRow <= rowEnd) {
6044
+ openBlocks.pop();
6045
+ lines.push(`${indent()}end`);
6046
+ }
6047
+ }
6048
+ while (openBlocks.length > 0) {
6049
+ openBlocks.pop();
6050
+ lines.push(`${indent()}end`);
6051
+ }
6052
+ return {
6053
+ mermaid: lines.join("\n"),
6054
+ nodeIdMap
6055
+ };
6056
+ }
6057
+ function convertReactFlowToSequenceMermaid(nodes, edges) {
6058
+ return emitSequenceMermaid(nodes, edges).mermaid;
6059
+ }
6060
+ function convertReactFlowToSequenceUiGraph(nodes, edges) {
6061
+ const { mermaid: mermaid$1, nodeIdMap } = emitSequenceMermaid(nodes, edges);
6062
+ return {
6063
+ mermaid: mermaid$1,
6064
+ context: buildValidatedContext(nodes, edges, [], nodeIdMap)
6065
+ };
6066
+ }
6067
+ const BOUND_PADDING = 20;
6068
+ function createGroupNode(options) {
6069
+ var _options$id, _options$name;
6070
+ return {
6071
+ id: (_options$id = options.id) !== null && _options$id !== void 0 ? _options$id : generateUUID$1(),
6072
+ type: "group",
6073
+ position: {
6074
+ x: options.bounds.x,
6075
+ y: options.bounds.y
6076
+ },
6077
+ data: {
6078
+ childNodes: options.nodes,
6079
+ autoLayout: true,
6080
+ componentFields: [generateComponentFieldNameInput((_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : "Group")]
6081
+ },
6082
+ style: {
6083
+ width: options.bounds.width + 20,
6084
+ height: options.bounds.height + 50
6085
+ }
6086
+ };
6087
+ }
6088
+ function generateGroupNodeFromNodes(id, name, nodes) {
6089
+ const bounds = nodes.map((node) => {
6090
+ var _ref, _ref2, _node$height, _node$style, _node$measured, _ref3, _ref4, _node$width, _node$style2, _node$measured2;
5892
6091
  return {
5893
- edges: resolvedEdges,
5894
- nodes: (options === null || options === void 0 ? void 0 : options.repositionNodes) ? resizeNodesLayouts(combinedNodes) : combinedNodes
6092
+ top: node.position.y,
6093
+ left: node.position.x,
6094
+ bottom: node.position.y + ((_ref = (_ref2 = (_node$height = node.height) !== null && _node$height !== void 0 ? _node$height : (_node$style = node.style) === null || _node$style === void 0 ? void 0 : _node$style.height) !== null && _ref2 !== void 0 ? _ref2 : (_node$measured = node.measured) === null || _node$measured === void 0 ? void 0 : _node$measured.height) !== null && _ref !== void 0 ? _ref : 0),
6095
+ right: node.position.x + ((_ref3 = (_ref4 = (_node$width = node.width) !== null && _node$width !== void 0 ? _node$width : (_node$style2 = node.style) === null || _node$style2 === void 0 ? void 0 : _node$style2.width) !== null && _ref4 !== void 0 ? _ref4 : (_node$measured2 = node.measured) === null || _node$measured2 === void 0 ? void 0 : _node$measured2.width) !== null && _ref3 !== void 0 ? _ref3 : 0)
5895
6096
  };
5896
6097
  });
5897
- return _convertMermaidToReactFlowWithContext.apply(this, arguments);
5898
- }
5899
- const CONTEXT_SHAPES = new Set([
5900
- "rectangle",
5901
- "rounded-rect",
5902
- "ellipse",
5903
- "diamond",
5904
- "triangle",
5905
- "parallelogram",
5906
- "trapezoid",
5907
- "hexagon",
5908
- "document",
5909
- "cylinder",
5910
- "delay",
5911
- "off-page-connector",
5912
- "display",
5913
- "collate",
5914
- "sort",
5915
- "terminator",
5916
- "or",
5917
- "database",
5918
- "multiple-documents",
5919
- "subroutine",
5920
- "manual-input",
5921
- "summing-junction",
5922
- "internal-storage"
5923
- ]);
5924
- const COMPONENT_INPUT_TYPES = new Set(Object.values(ComponentInputType));
5925
- const INLINE_MERMAID_LABEL_MAX_LENGTH = 32;
5926
- const KNOWN_NODE_DATA_KEYS = new Set([
5927
- "componentFields",
5928
- "shape",
5929
- "fill",
5930
- "stroke",
5931
- "strokeWidth",
5932
- "strokeStyle",
5933
- "borderRadius",
5934
- "borderAnimationEnabled",
5935
- "strokeAnimation",
5936
- "src",
5937
- "animatedIcon",
5938
- "iconSrc",
5939
- "componentId",
5940
- "serviceTable",
5941
- "title",
5942
- "columns",
5943
- "rows",
5944
- "name",
5945
- "label",
5946
- "value",
5947
- "cloud",
5948
- "service",
5949
- "childNodes"
5950
- ]);
5951
- function isComponentInputType(value) {
5952
- return COMPONENT_INPUT_TYPES.has(value);
5953
- }
5954
- function toRecord(value) {
5955
- if (!value || typeof value !== "object" || Array.isArray(value)) return;
5956
- return value;
5957
- }
5958
- function pickString(value) {
5959
- if (typeof value !== "string") return;
5960
- const trimmed = value.trim();
5961
- if (!trimmed) return;
5962
- return trimmed;
5963
- }
5964
- function pickPosition(value) {
5965
- const position = toRecord(value);
5966
- if (!position) return;
5967
- if (typeof position.x !== "number" || !Number.isFinite(position.x)) return;
5968
- if (typeof position.y !== "number" || !Number.isFinite(position.y)) return;
5969
- return {
5970
- x: position.x,
5971
- y: position.y
5972
- };
6098
+ const minX = Math.min(...bounds.map((b) => b.left));
6099
+ const minY = Math.min(...bounds.map((b) => b.top));
6100
+ const maxX = Math.max(...bounds.map((b) => b.right));
6101
+ const maxY = Math.max(...bounds.map((b) => b.bottom));
6102
+ return createGroupNode({
6103
+ id,
6104
+ name,
6105
+ nodes: nodes.map((node) => node.id),
6106
+ bounds: {
6107
+ x: minX - BOUND_PADDING,
6108
+ y: minY - BOUND_PADDING,
6109
+ width: maxX - minX + BOUND_PADDING * 2,
6110
+ height: maxY - minY + BOUND_PADDING * 2
6111
+ }
6112
+ });
5973
6113
  }
5974
- function getFieldValue(fieldData) {
5975
- if (!Array.isArray(fieldData) || fieldData.length !== 1) return fieldData;
5976
- const first = toRecord(fieldData[0]);
5977
- if (!first) return fieldData;
5978
- if (!("value" in first)) return first;
5979
- return first.value;
6114
+ function resolveCloudIcon(_x, _x2) {
6115
+ return _resolveCloudIcon.apply(this, arguments);
5980
6116
  }
5981
- function getFieldByLabel(fields, label) {
5982
- return fields.find((field) => {
5983
- var _pickString;
5984
- return ((_pickString = pickString(field.label)) === null || _pickString === void 0 ? void 0 : _pickString.toLowerCase()) === label.toLowerCase() && pickString(field.type);
6117
+ function _resolveCloudIcon() {
6118
+ _resolveCloudIcon = _asyncToGenerator(function* (cloud, serviceName) {
6119
+ const cloudName = cloud === null || cloud === void 0 ? void 0 : cloud.toLowerCase();
6120
+ const icon = (cloudName === "azure" ? [...(yield import("./__azure-icons.DgR1F6C6.mjs")).default] : cloudName === "aws" ? [...(yield import("./__aws-icons.agWBtDk7.mjs")).default] : [...(yield import("./__aws-icons.agWBtDk7.mjs")).default, ...(yield import("./__azure-icons.DgR1F6C6.mjs")).default]).find((icon$1) => icon$1.name.toLowerCase() === serviceName.toLowerCase());
6121
+ if (!icon) return null;
6122
+ return `/${icon.cloud.toLowerCase()}-icons/${icon.relativePath}`;
5985
6123
  });
6124
+ return _resolveCloudIcon.apply(this, arguments);
5986
6125
  }
5987
- function getFieldString(fields, label) {
5988
- const field = getFieldByLabel(fields, label);
5989
- if (!field) return;
5990
- return pickString(getFieldValue(field.data));
6126
+ function resolveAnimatedNode(_x3) {
6127
+ return _resolveAnimatedNode.apply(this, arguments);
5991
6128
  }
5992
- function isEmptyFieldValue(value) {
5993
- if (typeof value === "string") return value.trim().length === 0;
5994
- return value === void 0 || value === null;
6129
+ function _resolveAnimatedNode() {
6130
+ _resolveAnimatedNode = _asyncToGenerator(function* (animatedIcon) {
6131
+ const node = (yield import("./__animated-nodes.DI0XYTuw.mjs")).default.find((node$1) => node$1.name.toLowerCase() === animatedIcon.toLowerCase());
6132
+ if (!node) return null;
6133
+ return `/animated-nodes/${node.fileName}`;
6134
+ });
6135
+ return _resolveAnimatedNode.apply(this, arguments);
5995
6136
  }
5996
- function parseStrokeStyle(dashArray) {
5997
- if (typeof dashArray !== "string" || !dashArray.trim()) return;
5998
- const normalized = dashArray.replaceAll(",", " ").replace(/\s+/g, " ").trim();
5999
- if (normalized === "1 2") return "dotted";
6000
- if (normalized === "4 2" || normalized === "4 4" || normalized === "8 4") return "dashed";
6001
- return "solid";
6137
+ const EXPECTED_NODE_SIZE = {
6138
+ databaseTableSQL: {
6139
+ width: 500,
6140
+ height: 400
6141
+ },
6142
+ table: {
6143
+ width: 600,
6144
+ height: 400
6145
+ },
6146
+ code: {
6147
+ width: 300,
6148
+ height: 400
6149
+ }
6150
+ };
6151
+ const GROUP_BOUND_PADDING = 20;
6152
+ const GROUP_WIDTH_PADDING = 20;
6153
+ const GROUP_HEIGHT_PADDING = 50;
6154
+ const MIN_HORIZONTAL_GAP = 140;
6155
+ const ROW_ALIGNMENT_TOLERANCE = 80;
6156
+ function resolveDimension(value) {
6157
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
6002
6158
  }
6003
- function normalizeMarker(marker) {
6004
- if (typeof marker === "string") return { type: marker };
6005
- const markerRecord = toRecord(marker);
6006
- if (!markerRecord) return;
6007
- const type = pickString(markerRecord.type);
6008
- if (!type) return;
6009
- const color = pickString(markerRecord.color);
6010
- if (color) return {
6011
- type,
6012
- color
6159
+ function getNodeSize(node) {
6160
+ var _ref, _ref2, _ref3, _resolveDimension, _node$style, _node$measured, _ref4, _ref5, _ref6, _resolveDimension2, _node$style2, _node$measured2;
6161
+ const expectedSize = node.type ? EXPECTED_NODE_SIZE[node.type] : void 0;
6162
+ return {
6163
+ width: (_ref = (_ref2 = (_ref3 = (_resolveDimension = resolveDimension(node.width)) !== null && _resolveDimension !== void 0 ? _resolveDimension : resolveDimension((_node$style = node.style) === null || _node$style === void 0 ? void 0 : _node$style.width)) !== null && _ref3 !== void 0 ? _ref3 : resolveDimension((_node$measured = node.measured) === null || _node$measured === void 0 ? void 0 : _node$measured.width)) !== null && _ref2 !== void 0 ? _ref2 : expectedSize === null || expectedSize === void 0 ? void 0 : expectedSize.width) !== null && _ref !== void 0 ? _ref : 0,
6164
+ height: (_ref4 = (_ref5 = (_ref6 = (_resolveDimension2 = resolveDimension(node.height)) !== null && _resolveDimension2 !== void 0 ? _resolveDimension2 : resolveDimension((_node$style2 = node.style) === null || _node$style2 === void 0 ? void 0 : _node$style2.height)) !== null && _ref6 !== void 0 ? _ref6 : resolveDimension((_node$measured2 = node.measured) === null || _node$measured2 === void 0 ? void 0 : _node$measured2.height)) !== null && _ref5 !== void 0 ? _ref5 : expectedSize === null || expectedSize === void 0 ? void 0 : expectedSize.height) !== null && _ref4 !== void 0 ? _ref4 : 0
6013
6165
  };
6014
- return { type };
6015
- }
6016
- function escapeMermaidText(value) {
6017
- return value.replaceAll("\"", "\\\"");
6018
- }
6019
- function canInlineMermaidLabel(value) {
6020
- if (value.length > INLINE_MERMAID_LABEL_MAX_LENGTH) return false;
6021
- if (value.includes("\n") || value.includes("\r")) return false;
6022
- return true;
6023
- }
6024
- function normalizeDetailedMermaidLabel(value) {
6025
- return value.split(/\r?\n/).map((line) => line.replace(/\s+/g, " ").trim()).filter((line) => line.length > 0).join("\n");
6026
- }
6027
- function toComponentFields(value) {
6028
- if (!Array.isArray(value)) return [];
6029
- return value.map((field) => toRecord(field)).filter((field) => field !== void 0);
6030
- }
6031
- function buildContextEdges(edges, nodeIdMap) {
6032
- const contextEdges = {};
6033
- for (const edge of edges) {
6034
- var _toRecord, _toRecord2;
6035
- const source = nodeIdMap.get(edge.source);
6036
- const target = nodeIdMap.get(edge.target);
6037
- if (!source || !target) continue;
6038
- const edgeContext = {};
6039
- const edgeType = pickString(edge.type);
6040
- if (edgeType) edgeContext.type = edgeType;
6041
- const sourceHandle = pickString(edge.sourceHandle);
6042
- if (sourceHandle) edgeContext.sourceHandle = sourceHandle;
6043
- const targetHandle = pickString(edge.targetHandle);
6044
- if (targetHandle) edgeContext.targetHandle = targetHandle;
6045
- const edgeLabel = pickString(edge.label);
6046
- if (edgeLabel) edgeContext.label = edgeLabel;
6047
- const edgeStyleRecord = (_toRecord = toRecord(edge.style)) !== null && _toRecord !== void 0 ? _toRecord : {};
6048
- const edgeStyle = {};
6049
- const stroke = pickString(edgeStyleRecord.stroke);
6050
- if (stroke) edgeStyle.stroke = stroke;
6051
- if (typeof edgeStyleRecord.strokeWidth === "number") edgeStyle.strokeWidth = edgeStyleRecord.strokeWidth;
6052
- const strokeStyle = parseStrokeStyle(edgeStyleRecord.strokeDasharray);
6053
- if (strokeStyle) edgeStyle.strokeStyle = strokeStyle;
6054
- if (typeof edge.animated === "boolean") edgeStyle.borderAnimationEnabled = edge.animated;
6055
- if (Object.keys(edgeStyle).length > 0) edgeContext.style = edgeStyle;
6056
- const markerStart = normalizeMarker(edge.markerStart);
6057
- if (markerStart) edgeContext.markerStart = markerStart;
6058
- const markerEnd = normalizeMarker(edge.markerEnd);
6059
- if (markerEnd) edgeContext.markerEnd = markerEnd;
6060
- const edgeData = (_toRecord2 = toRecord(edge.data)) !== null && _toRecord2 !== void 0 ? _toRecord2 : {};
6061
- if (Object.keys(edgeData).length > 0) edgeContext.___internal = edgeData;
6062
- if (Object.keys(edgeContext).length > 0) contextEdges[`${source}-${target}`] = edgeContext;
6063
- }
6064
- return contextEdges;
6065
6166
  }
6066
- function buildContextGroups(groupNodes, nodeIdMap) {
6067
- const contextGroups = {};
6068
- for (const groupNode of groupNodes) {
6069
- var _toRecord;
6070
- const groupData = (_toRecord = toRecord(groupNode.data)) !== null && _toRecord !== void 0 ? _toRecord : {};
6071
- const childNodes = Array.isArray(groupData.childNodes) ? groupData.childNodes.map((childId) => typeof childId === "string" ? nodeIdMap.get(childId) : void 0).filter((childId) => childId !== void 0) : [];
6072
- const name = getFieldString(Array.isArray(groupData.componentFields) ? groupData.componentFields.map((field) => toRecord(field)).filter((field) => field !== void 0) : [], "Name");
6073
- if (!name && childNodes.length === 0) continue;
6074
- contextGroups[groupNode.id] = {
6075
- name: name !== null && name !== void 0 ? name : void 0,
6076
- nodes: childNodes
6167
+ function resizeNodesLayouts(nodes) {
6168
+ const resizeRules = nodes.map((node) => {
6169
+ if (!node.type) return;
6170
+ const expectedSize = EXPECTED_NODE_SIZE[node.type];
6171
+ if (!expectedSize) return;
6172
+ const size = getNodeSize(node);
6173
+ return {
6174
+ startX: node.position.x + expectedSize.width,
6175
+ startY: node.position.y + expectedSize.height,
6176
+ deltaX: Math.max(0, size.width - expectedSize.width),
6177
+ deltaY: Math.max(0, size.height - expectedSize.height)
6077
6178
  };
6078
- }
6079
- return contextGroups;
6080
- }
6081
- function buildContextNodes(graphNodes, nodeIdMap) {
6082
- const contextNodes = {};
6083
- for (const node of graphNodes) {
6084
- var _toRecord, _toRecord2, _pickString, _pickString2;
6085
- const mappedNodeId = nodeIdMap.get(node.id);
6086
- if (!mappedNodeId) continue;
6087
- const nodeData = (_toRecord = toRecord(node.data)) !== null && _toRecord !== void 0 ? _toRecord : {};
6088
- const nodeStyle = (_toRecord2 = toRecord(node.style)) !== null && _toRecord2 !== void 0 ? _toRecord2 : {};
6089
- const componentFields = Array.isArray(nodeData.componentFields) ? nodeData.componentFields.map((field) => toRecord(field)).filter((field) => field !== void 0) : [];
6090
- const nodeContext = {};
6091
- const nodeType = pickString(node.type);
6092
- if (nodeType) nodeContext.type = nodeType;
6093
- const nameField = getFieldByLabel(componentFields, "Name");
6094
- const nameRawValue = nameField ? getFieldValue(nameField.data) : void 0;
6095
- const name = pickString(nameRawValue);
6096
- if (name) nodeContext.name = name;
6097
- const textField = nodeType === "text" ? getFieldByLabel(componentFields, "Text") : void 0;
6098
- const textRawValue = textField ? getFieldValue(textField.data) : void 0;
6099
- const textValue = pickString(textRawValue);
6100
- if (nodeType === "text") {
6101
- if (textValue) nodeContext.value = textValue;
6102
- }
6103
- const codeField = nodeType === "code" ? getFieldByLabel(componentFields, "Code") : void 0;
6104
- const codeRawValue = codeField ? getFieldValue(codeField.data) : void 0;
6105
- const codeValue = pickString(codeRawValue);
6106
- if (nodeType === "code") {
6107
- if (codeValue) nodeContext.value = codeValue;
6179
+ }).filter((rule) => Boolean(rule));
6180
+ const resizedNodes = nodes.map((node) => {
6181
+ var _node$data;
6182
+ const childNodeIds = (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.childNodes;
6183
+ if (Array.isArray(childNodeIds)) return _objectSpread2({}, node);
6184
+ const offsetX = resizeRules.reduce((total, rule) => {
6185
+ if (!rule || rule.deltaX === 0 || node.position.x < rule.startX) return total;
6186
+ return total + rule.deltaX;
6187
+ }, 0);
6188
+ const offsetY = resizeRules.reduce((total, rule) => {
6189
+ if (!rule || rule.deltaY === 0 || node.position.y < rule.startY) return total;
6190
+ return total + rule.deltaY;
6191
+ }, 0);
6192
+ if (offsetX === 0 && offsetY === 0) return node;
6193
+ return _objectSpread2(_objectSpread2({}, node), {}, { position: {
6194
+ x: node.position.x + offsetX,
6195
+ y: node.position.y + offsetY
6196
+ } });
6197
+ });
6198
+ const resizedNodesById = new Map(resizedNodes.map((node) => [node.id, node]));
6199
+ const rowNodes = resizedNodes.filter((node) => {
6200
+ var _node$data2;
6201
+ return !Array.isArray((_node$data2 = node.data) === null || _node$data2 === void 0 ? void 0 : _node$data2.childNodes);
6202
+ }).sort((a, b) => a.position.y === b.position.y ? a.position.x - b.position.x : a.position.y - b.position.y);
6203
+ const rows = [];
6204
+ for (const node of rowNodes) {
6205
+ const row = rows.find((currentRow) => Math.abs(currentRow[0].position.y - node.position.y) <= ROW_ALIGNMENT_TOLERANCE);
6206
+ if (row) {
6207
+ row.push(node);
6208
+ continue;
6108
6209
  }
6109
- const src = pickString(nodeData.src);
6110
- if (src) nodeContext.src = src;
6111
- const animatedIcon = pickString(nodeData.animatedIcon);
6112
- if (animatedIcon) nodeContext.animatedIcon = animatedIcon;
6113
- const cloud = pickString(nodeData.cloud);
6114
- if (cloud) nodeContext.cloud = cloud;
6115
- const service = pickString(nodeData.service);
6116
- if (service) nodeContext.service = service;
6117
- const componentId = pickString(nodeData.componentId);
6118
- if (componentId) nodeContext.componentId = componentId;
6119
- const shape = pickString(nodeData.shape);
6120
- if (shape && CONTEXT_SHAPES.has(shape)) nodeContext.shape = shape;
6121
- const style = {};
6122
- const width = typeof node.width === "number" ? node.width : typeof nodeStyle.width === "number" ? nodeStyle.width : void 0;
6123
- if (typeof width === "number") style.width = width;
6124
- const height = typeof node.height === "number" ? node.height : typeof nodeStyle.height === "number" ? nodeStyle.height : void 0;
6125
- if (typeof height === "number") style.height = height;
6126
- const fill = (_pickString = pickString(nodeData.fill)) !== null && _pickString !== void 0 ? _pickString : pickString(nodeStyle.fill);
6127
- if (fill) style.fill = fill;
6128
- const stroke = (_pickString2 = pickString(nodeData.stroke)) !== null && _pickString2 !== void 0 ? _pickString2 : pickString(nodeStyle.stroke);
6129
- if (stroke) style.stroke = stroke;
6130
- const strokeWidth = typeof nodeData.strokeWidth === "number" ? nodeData.strokeWidth : typeof nodeStyle.strokeWidth === "number" ? nodeStyle.strokeWidth : void 0;
6131
- if (typeof strokeWidth === "number") style.strokeWidth = strokeWidth;
6132
- const borderRadius = typeof nodeData.borderRadius === "number" ? nodeData.borderRadius : typeof nodeStyle.borderRadius === "number" ? nodeStyle.borderRadius : void 0;
6133
- if (typeof borderRadius === "number") style.borderRadius = borderRadius;
6134
- const strokeStyleFromData = pickString(nodeData.strokeStyle);
6135
- if (strokeStyleFromData === "solid" || strokeStyleFromData === "dashed" || strokeStyleFromData === "dotted") style.strokeStyle = strokeStyleFromData;
6136
- else {
6137
- const strokeStyleFromDash = parseStrokeStyle(nodeStyle.strokeDasharray);
6138
- if (strokeStyleFromDash) style.strokeStyle = strokeStyleFromDash;
6210
+ rows.push([node]);
6211
+ }
6212
+ for (const row of rows) {
6213
+ row.sort((a, b) => a.position.x - b.position.x);
6214
+ for (let index = 1; index < row.length; index += 1) {
6215
+ const previousNode = row[index - 1];
6216
+ const currentNode = row[index];
6217
+ const previousNodeSize = getNodeSize(previousNode);
6218
+ const minimumX = previousNode.position.x + previousNodeSize.width + MIN_HORIZONTAL_GAP;
6219
+ if (currentNode.position.x >= minimumX) continue;
6220
+ const shiftedNode = _objectSpread2(_objectSpread2({}, currentNode), {}, { position: {
6221
+ x: minimumX,
6222
+ y: currentNode.position.y
6223
+ } });
6224
+ row[index] = shiftedNode;
6225
+ resizedNodesById.set(shiftedNode.id, shiftedNode);
6139
6226
  }
6140
- const borderAnimationEnabled = typeof nodeData.borderAnimationEnabled === "boolean" ? nodeData.borderAnimationEnabled : nodeData.strokeAnimation === "dash" ? true : void 0;
6141
- if (typeof borderAnimationEnabled === "boolean") style.borderAnimationEnabled = borderAnimationEnabled;
6142
- if (Object.keys(style).length > 0) nodeContext.style = style;
6143
- const tableColumns = Array.isArray(nodeData.columns) ? nodeData.columns.filter((value) => typeof value === "string") : void 0;
6144
- const tableRows = Array.isArray(nodeData.rows) ? nodeData.rows.map((row) => Array.isArray(row) ? row.filter((value) => typeof value === "string") : void 0).filter((row) => row !== void 0) : void 0;
6145
- if (tableColumns || tableRows) nodeContext.table = {
6146
- columns: tableColumns !== null && tableColumns !== void 0 ? tableColumns : [],
6147
- rows: tableRows !== null && tableRows !== void 0 ? tableRows : []
6148
- };
6149
- const serviceTable = toRecord(nodeData.serviceTable);
6150
- const serviceName = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.serviceName);
6151
- const databaseName = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.databaseName);
6152
- const tableName = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.tableName);
6153
- if (serviceName && databaseName && tableName) nodeContext.dbConfig = {
6154
- serviceName,
6155
- databaseName,
6156
- tableName
6157
- };
6158
- const dynamicData = {};
6159
- for (const field of componentFields) {
6160
- const label$1 = pickString(field.label);
6161
- const type = pickString(field.type);
6162
- if (!label$1 || !type || !isComponentInputType(type)) continue;
6163
- const componentType = type;
6164
- const normalizedLabel = label$1.toLowerCase();
6165
- if (normalizedLabel === "name") continue;
6166
- if (nodeType === "text" && normalizedLabel === "text") continue;
6167
- if (nodeType === "code" && normalizedLabel === "code") continue;
6168
- const options = Array.isArray(field.options) ? field.options.filter((option) => typeof option === "string") : void 0;
6169
- dynamicData[label$1] = {
6170
- type: componentType,
6171
- value: getFieldValue(field.data),
6172
- options: options && options.length > 0 ? options : void 0
6227
+ }
6228
+ return resizedNodes.map((node) => {
6229
+ var _resizedNodesById$get, _node$data3;
6230
+ const shiftedNode = (_resizedNodesById$get = resizedNodesById.get(node.id)) !== null && _resizedNodesById$get !== void 0 ? _resizedNodesById$get : node;
6231
+ const childNodeIds = (_node$data3 = node.data) === null || _node$data3 === void 0 ? void 0 : _node$data3.childNodes;
6232
+ if (!Array.isArray(childNodeIds)) return shiftedNode;
6233
+ const childNodes = childNodeIds.map((childNodeId) => typeof childNodeId === "string" ? resizedNodesById.get(childNodeId) : void 0).filter((childNode) => Boolean(childNode));
6234
+ if (childNodes.length === 0) return shiftedNode;
6235
+ const bounds = childNodes.map((childNode) => {
6236
+ const size = getNodeSize(childNode);
6237
+ return {
6238
+ left: childNode.position.x,
6239
+ top: childNode.position.y,
6240
+ right: childNode.position.x + size.width,
6241
+ bottom: childNode.position.y + size.height
6173
6242
  };
6174
- }
6175
- if (nameField && !name && isEmptyFieldValue(nameRawValue)) {
6176
- const nameType = pickString(nameField.type);
6177
- if (nameType && isComponentInputType(nameType)) {
6178
- const nameOptions = Array.isArray(nameField.options) ? nameField.options.filter((option) => typeof option === "string") : void 0;
6179
- dynamicData.Name = {
6180
- type: nameType,
6181
- value: "",
6182
- options: nameOptions && nameOptions.length > 0 ? nameOptions : void 0
6243
+ });
6244
+ const minX = Math.min(...bounds.map((bound) => bound.left));
6245
+ const minY = Math.min(...bounds.map((bound) => bound.top));
6246
+ const maxX = Math.max(...bounds.map((bound) => bound.right));
6247
+ const maxY = Math.max(...bounds.map((bound) => bound.bottom));
6248
+ return _objectSpread2(_objectSpread2({}, shiftedNode), {}, {
6249
+ position: {
6250
+ x: minX - GROUP_BOUND_PADDING,
6251
+ y: minY - GROUP_BOUND_PADDING
6252
+ },
6253
+ style: _objectSpread2(_objectSpread2({}, shiftedNode.style), {}, {
6254
+ width: maxX - minX + GROUP_BOUND_PADDING * 2 + GROUP_WIDTH_PADDING,
6255
+ height: maxY - minY + GROUP_BOUND_PADDING * 2 + GROUP_HEIGHT_PADDING
6256
+ })
6257
+ });
6258
+ });
6259
+ }
6260
+ function hasValidPosition(position) {
6261
+ if (!position) return false;
6262
+ return Number.isFinite(position.x) && Number.isFinite(position.y);
6263
+ }
6264
+ function normalizeContextMarker(marker) {
6265
+ if (!marker) return;
6266
+ const markerType = marker.type.trim().toLowerCase();
6267
+ let type;
6268
+ if (markerType === "arrow") type = MarkerType.Arrow;
6269
+ else if (markerType === "arrowclosed" || markerType === "arrow-closed" || markerType === "arrow_closed") type = MarkerType.ArrowClosed;
6270
+ if (!type) return;
6271
+ if (marker.color) return {
6272
+ type,
6273
+ color: marker.color
6274
+ };
6275
+ return { type };
6276
+ }
6277
+ function convertMermaidToReactFlowWithContext(_x4, _x5, _x6) {
6278
+ return _convertMermaidToReactFlowWithContext.apply(this, arguments);
6279
+ }
6280
+ function _convertMermaidToReactFlowWithContext() {
6281
+ _convertMermaidToReactFlowWithContext = _asyncToGenerator(function* (mermaidCode, context, options) {
6282
+ var _context$groups;
6283
+ const validatedContext = contextSchema.parse(context);
6284
+ const reactFlowData = yield convertMermaidToReactFlow(mermaidCode);
6285
+ const rfNodesPromises = reactFlowData.nodes.map(function() {
6286
+ var _ref = _asyncToGenerator(function* (node) {
6287
+ var _validatedContext$nod, _clonedNode$data$comp, _ctx$data, _clonedNode$data, _ctx$style, _ctx$style2, _ctx$style3, _ctx$style4;
6288
+ const ctx = (_validatedContext$nod = validatedContext.nodes) === null || _validatedContext$nod === void 0 ? void 0 : _validatedContext$nod[node.id];
6289
+ if (!ctx) return node;
6290
+ const clonedNode = JSON.parse(JSON.stringify(node));
6291
+ const componentFields = (_clonedNode$data$comp = clonedNode.data.componentFields) !== null && _clonedNode$data$comp !== void 0 ? _clonedNode$data$comp : [];
6292
+ (_ctx$data = ctx.data) !== null && _ctx$data !== void 0 || (ctx.data = {});
6293
+ (_clonedNode$data = clonedNode.data) !== null && _clonedNode$data !== void 0 || (clonedNode.data = {});
6294
+ if (hasValidPosition(ctx.___position)) clonedNode.position = {
6295
+ x: ctx.___position.x,
6296
+ y: ctx.___position.y
6183
6297
  };
6184
- }
6185
- }
6186
- if (textField && !textValue && isEmptyFieldValue(textRawValue)) {
6187
- const textType = pickString(textField.type);
6188
- if (textType && isComponentInputType(textType)) {
6189
- const textOptions = Array.isArray(textField.options) ? textField.options.filter((option) => typeof option === "string") : void 0;
6190
- dynamicData.Text = {
6191
- type: textType,
6192
- value: "",
6193
- options: textOptions && textOptions.length > 0 ? textOptions : void 0
6298
+ if (ctx.type) {
6299
+ clonedNode.type = ctx.type;
6300
+ delete clonedNode.style;
6301
+ if (ctx.type === "cloud") {
6302
+ clonedNode.height = 150;
6303
+ clonedNode.width = 150;
6304
+ if (ctx.service) {
6305
+ const cloudIcon = (options === null || options === void 0 ? void 0 : options.resolveCloudIcon) ? yield options.resolveCloudIcon(ctx.cloud, ctx.service) : yield resolveCloudIcon(ctx.cloud, ctx.service);
6306
+ if (cloudIcon) clonedNode.data.iconSrc = cloudIcon;
6307
+ }
6308
+ }
6309
+ if (ctx.type === "image" && ctx.src) clonedNode.data = _objectSpread2(_objectSpread2({}, clonedNode.data), {}, { src: ctx.src });
6310
+ if (ctx.type === "gif") {
6311
+ if (ctx.animatedIcon) {
6312
+ const animatedNodeSrc = yield resolveAnimatedNode(ctx.animatedIcon);
6313
+ if (animatedNodeSrc) clonedNode.data = _objectSpread2(_objectSpread2({}, clonedNode.data), {}, { src: animatedNodeSrc });
6314
+ } else if (ctx.src) clonedNode.data = _objectSpread2(_objectSpread2({}, clonedNode.data), {}, { src: ctx.src });
6315
+ }
6316
+ if (ctx.type === "text" && (ctx.value || ctx.name)) {
6317
+ const textComponentField = generateComponentFieldInput({
6318
+ type: ComponentInputType.TextInput,
6319
+ componentFieldId: "text",
6320
+ label: "Text",
6321
+ data: ctx.value || ctx.name,
6322
+ isReadonly: true
6323
+ });
6324
+ componentFields.unshift(textComponentField);
6325
+ }
6326
+ if (ctx.type === "code" && ctx.value) {
6327
+ const textComponentField = generateComponentFieldInput({
6328
+ type: ComponentInputType.CodeEditor,
6329
+ componentFieldId: "code",
6330
+ label: "Code",
6331
+ data: ctx.value,
6332
+ isReadonly: true
6333
+ });
6334
+ componentFields.unshift(textComponentField);
6335
+ }
6336
+ if (ctx.type === "table" && ctx.table) {
6337
+ var _ctx$table$rows, _ctx$table$columns;
6338
+ clonedNode.data.title = ctx.name;
6339
+ clonedNode.data.rows = (_ctx$table$rows = ctx.table.rows) !== null && _ctx$table$rows !== void 0 ? _ctx$table$rows : [];
6340
+ clonedNode.data.columns = (_ctx$table$columns = ctx.table.columns) !== null && _ctx$table$columns !== void 0 ? _ctx$table$columns : [];
6341
+ }
6342
+ if (ctx.type === "data-source" || ctx.type === "db-table") {
6343
+ ctx.type = "databaseTableSQL";
6344
+ clonedNode.type = "databaseTableSQL";
6345
+ }
6346
+ if (ctx.type === "component") {
6347
+ ctx.type = "builder";
6348
+ clonedNode.type = "builder";
6349
+ clonedNode.data.componentId = ctx.componentId;
6350
+ }
6351
+ if (ctx.type === "shape" && ctx.shape) {
6352
+ clonedNode.data.shape = ctx.shape;
6353
+ if (ctx.shape === "or" || ctx.shape === "summing-junction") {
6354
+ var _clonedNode$width, _clonedNode$height;
6355
+ const maxSize = Math.max((_clonedNode$width = clonedNode.width) !== null && _clonedNode$width !== void 0 ? _clonedNode$width : 0, (_clonedNode$height = clonedNode.height) !== null && _clonedNode$height !== void 0 ? _clonedNode$height : 0, 200);
6356
+ clonedNode.width = maxSize;
6357
+ clonedNode.height = maxSize;
6358
+ }
6359
+ }
6360
+ }
6361
+ if (ctx.name) ctx.data["Name"] = {
6362
+ type: ComponentInputType.TextInput,
6363
+ value: ctx.name
6194
6364
  };
6195
- }
6196
- }
6197
- if (codeField && !codeValue && isEmptyFieldValue(codeRawValue)) {
6198
- const codeType = pickString(codeField.type);
6199
- if (codeType && isComponentInputType(codeType)) {
6200
- const codeOptions = Array.isArray(codeField.options) ? codeField.options.filter((option) => typeof option === "string") : void 0;
6201
- dynamicData.Code = {
6202
- type: codeType,
6203
- value: "",
6204
- options: codeOptions && codeOptions.length > 0 ? codeOptions : void 0
6365
+ for (const key in ctx.data) {
6366
+ const metaInput = ctx.data[key];
6367
+ if (metaInput === void 0) continue;
6368
+ const componentField = getComponentFieldByLabel(componentFields, key);
6369
+ const newComponentField = generateComponentFieldInput({
6370
+ label: key,
6371
+ type: metaInput.type,
6372
+ data: metaInput.value,
6373
+ options: metaInput.options
6374
+ });
6375
+ if (!componentField) componentFields.push(newComponentField);
6376
+ else {
6377
+ componentField.type = newComponentField.type;
6378
+ componentField.data = newComponentField.data;
6379
+ }
6380
+ }
6381
+ if (ctx.dbConfig) clonedNode.data.serviceTable = {
6382
+ serviceName: ctx.dbConfig.serviceName,
6383
+ databaseName: ctx.dbConfig.databaseName,
6384
+ tableName: ctx.dbConfig.tableName
6205
6385
  };
6206
- }
6207
- }
6208
- if (Object.keys(dynamicData).length > 0) nodeContext.data = dynamicData;
6209
- const position = pickPosition(node.position);
6210
- if (position) nodeContext.___position = position;
6211
- const internalData = Object.entries(nodeData).reduce((acc, [key, value]) => {
6212
- if (KNOWN_NODE_DATA_KEYS.has(key)) return acc;
6213
- acc[key] = value;
6214
- return acc;
6215
- }, {});
6216
- if (nodeType === "builder" && Array.isArray(nodeData.componentFields)) internalData.componentFields = nodeData.componentFields;
6217
- const iconSrc = pickString(nodeData.iconSrc);
6218
- if (iconSrc) internalData.iconSrc = iconSrc;
6219
- const label = pickString(nodeData.label);
6220
- if (label) internalData.label = label;
6221
- const internalCloud = pickString(nodeData.cloud);
6222
- if (internalCloud) internalData.cloud = internalCloud;
6223
- if (Object.keys(internalData).length > 0) nodeContext.___internal = internalData;
6224
- if (Object.keys(nodeContext).length > 0) contextNodes[mappedNodeId] = nodeContext;
6225
- }
6226
- return contextNodes;
6227
- }
6228
- function buildValidatedContext(graphNodes, edges, groupNodes, nodeIdMap) {
6229
- const contextNodes = buildContextNodes(graphNodes, nodeIdMap);
6230
- const contextEdges = buildContextEdges(edges, nodeIdMap);
6231
- const contextGroups = buildContextGroups(groupNodes, nodeIdMap);
6232
- const context = {};
6233
- if (Object.keys(contextNodes).length > 0) context.nodes = contextNodes;
6234
- if (Object.keys(contextEdges).length > 0) context.edges = contextEdges;
6235
- if (Object.keys(contextGroups).length > 0) context.groups = contextGroups;
6236
- return contextSchema.parse(context);
6386
+ if ((_ctx$style = ctx.style) === null || _ctx$style === void 0 ? void 0 : _ctx$style.height) clonedNode.height = ctx.style.height;
6387
+ if ((_ctx$style2 = ctx.style) === null || _ctx$style2 === void 0 ? void 0 : _ctx$style2.width) clonedNode.width = ctx.style.width;
6388
+ clonedNode.data = _objectSpread2(_objectSpread2(_objectSpread2({}, clonedNode.data), objectPick((_ctx$style3 = ctx.style) !== null && _ctx$style3 !== void 0 ? _ctx$style3 : {}, [
6389
+ "color",
6390
+ "fill",
6391
+ "stroke",
6392
+ "strokeWidth",
6393
+ "strokeStyle",
6394
+ "borderRadius",
6395
+ "borderAnimationEnabled"
6396
+ ])), {}, {
6397
+ componentFields,
6398
+ strokeAnimation: ((_ctx$style4 = ctx.style) === null || _ctx$style4 === void 0 ? void 0 : _ctx$style4.borderAnimationEnabled) ? "dash" : void 0
6399
+ }, ctx === null || ctx === void 0 ? void 0 : ctx.___internal);
6400
+ return clonedNode;
6401
+ });
6402
+ return function(_x) {
6403
+ return _ref.apply(this, arguments);
6404
+ };
6405
+ }());
6406
+ const resolvedNodes = yield Promise.all(rfNodesPromises);
6407
+ const groupNodes = Object.entries((_context$groups = context.groups) !== null && _context$groups !== void 0 ? _context$groups : {}).map(([nodeId, groupCtx]) => {
6408
+ var _groupCtx$nodes, _groupCtx$name;
6409
+ const childNodes = arrayNonNullable(((_groupCtx$nodes = groupCtx.nodes) !== null && _groupCtx$nodes !== void 0 ? _groupCtx$nodes : []).map((nodeId$1) => resolvedNodes.find((n) => n.id === nodeId$1)));
6410
+ return generateGroupNodeFromNodes(nodeId, (_groupCtx$name = groupCtx.name) !== null && _groupCtx$name !== void 0 ? _groupCtx$name : "Group", childNodes);
6411
+ });
6412
+ const edgeOrdinals = /* @__PURE__ */ new Map();
6413
+ const edgeContextKeys = reactFlowData.edges.map((edge) => {
6414
+ var _edgeOrdinals$get;
6415
+ const pair = `${edge.source}-${edge.target}`;
6416
+ const ordinal = (_edgeOrdinals$get = edgeOrdinals.get(pair)) !== null && _edgeOrdinals$get !== void 0 ? _edgeOrdinals$get : 0;
6417
+ edgeOrdinals.set(pair, ordinal + 1);
6418
+ if (ordinal === 0) return {
6419
+ pair,
6420
+ key: pair
6421
+ };
6422
+ return {
6423
+ pair,
6424
+ key: `${pair}#${ordinal}`
6425
+ };
6426
+ });
6427
+ const rfEdgesPromises = reactFlowData.edges.map(function() {
6428
+ var _ref3 = _asyncToGenerator(function* (edge, index) {
6429
+ var _ref2, _validatedContext$edg, _validatedContext$edg2, _validatedContext$edg3, _ctx$type, _ctx$sourceHandle, _ctx$targetHandle, _normalizeContextMark, _normalizeContextMark2, _ctx$label, _ctx$style$borderAnim, _ctx$style5, _ctx$style$stroke, _ctx$style6, _edge$style, _ctx$style$strokeWidt, _ctx$style7, _edge$style2, _ctx$style8, _ctx$style9, _ctx$style10, _edge$style3;
6430
+ const { pair, key } = edgeContextKeys[index];
6431
+ const ctx = (_ref2 = (_validatedContext$edg = (_validatedContext$edg2 = validatedContext.edges) === null || _validatedContext$edg2 === void 0 ? void 0 : _validatedContext$edg2[key]) !== null && _validatedContext$edg !== void 0 ? _validatedContext$edg : (_validatedContext$edg3 = validatedContext.edges) === null || _validatedContext$edg3 === void 0 ? void 0 : _validatedContext$edg3[pair]) !== null && _ref2 !== void 0 ? _ref2 : null;
6432
+ if (!ctx) return edge;
6433
+ return _objectSpread2(_objectSpread2({}, edge), {}, {
6434
+ type: (_ctx$type = ctx.type) !== null && _ctx$type !== void 0 ? _ctx$type : edge.type,
6435
+ sourceHandle: (_ctx$sourceHandle = ctx.sourceHandle) !== null && _ctx$sourceHandle !== void 0 ? _ctx$sourceHandle : edge.sourceHandle,
6436
+ targetHandle: (_ctx$targetHandle = ctx.targetHandle) !== null && _ctx$targetHandle !== void 0 ? _ctx$targetHandle : edge.targetHandle,
6437
+ markerStart: (_normalizeContextMark = normalizeContextMarker(ctx.markerStart)) !== null && _normalizeContextMark !== void 0 ? _normalizeContextMark : edge.markerStart,
6438
+ markerEnd: (_normalizeContextMark2 = normalizeContextMarker(ctx.markerEnd)) !== null && _normalizeContextMark2 !== void 0 ? _normalizeContextMark2 : edge.markerEnd,
6439
+ data: _objectSpread2(_objectSpread2({}, edge.data), ctx === null || ctx === void 0 ? void 0 : ctx.___internal),
6440
+ label: (_ctx$label = ctx.label) !== null && _ctx$label !== void 0 ? _ctx$label : edge.label,
6441
+ animated: (_ctx$style$borderAnim = (_ctx$style5 = ctx.style) === null || _ctx$style5 === void 0 ? void 0 : _ctx$style5.borderAnimationEnabled) !== null && _ctx$style$borderAnim !== void 0 ? _ctx$style$borderAnim : edge.animated,
6442
+ style: _objectSpread2(_objectSpread2({}, edge.style), {}, {
6443
+ stroke: (_ctx$style$stroke = (_ctx$style6 = ctx.style) === null || _ctx$style6 === void 0 ? void 0 : _ctx$style6.stroke) !== null && _ctx$style$stroke !== void 0 ? _ctx$style$stroke : (_edge$style = edge.style) === null || _edge$style === void 0 ? void 0 : _edge$style.stroke,
6444
+ strokeWidth: (_ctx$style$strokeWidt = (_ctx$style7 = ctx.style) === null || _ctx$style7 === void 0 ? void 0 : _ctx$style7.strokeWidth) !== null && _ctx$style$strokeWidt !== void 0 ? _ctx$style$strokeWidt : (_edge$style2 = edge.style) === null || _edge$style2 === void 0 ? void 0 : _edge$style2.strokeWidth,
6445
+ strokeDasharray: ((_ctx$style8 = ctx.style) === null || _ctx$style8 === void 0 ? void 0 : _ctx$style8.strokeStyle) === "dashed" ? "4 2" : ((_ctx$style9 = ctx.style) === null || _ctx$style9 === void 0 ? void 0 : _ctx$style9.strokeStyle) === "dotted" ? "1 2" : ((_ctx$style10 = ctx.style) === null || _ctx$style10 === void 0 ? void 0 : _ctx$style10.strokeStyle) === "solid" ? void 0 : (_edge$style3 = edge.style) === null || _edge$style3 === void 0 ? void 0 : _edge$style3.strokeDasharray
6446
+ })
6447
+ });
6448
+ });
6449
+ return function(_x2, _x3) {
6450
+ return _ref3.apply(this, arguments);
6451
+ };
6452
+ }());
6453
+ const resolvedEdges = yield Promise.all(rfEdgesPromises);
6454
+ const combinedNodes = [...groupNodes, ...resolvedNodes.map((node) => {
6455
+ const nodeParent = groupNodes.find((groupNode) => {
6456
+ var _groupNode$data$child;
6457
+ return (_groupNode$data$child = groupNode.data.childNodes) === null || _groupNode$data$child === void 0 ? void 0 : _groupNode$data$child.includes(node.id);
6458
+ });
6459
+ if (nodeParent) return _objectSpread2(_objectSpread2({}, node), {}, { parentId: nodeParent.id });
6460
+ return node;
6461
+ })];
6462
+ if (isSequenceDiagram(combinedNodes)) return {
6463
+ edges: resolvedEdges,
6464
+ nodes: combinedNodes
6465
+ };
6466
+ if (isC4ReactFlowDiagram(combinedNodes)) return {
6467
+ edges: resolvedEdges,
6468
+ nodes: combinedNodes
6469
+ };
6470
+ return {
6471
+ edges: resolvedEdges,
6472
+ nodes: (options === null || options === void 0 ? void 0 : options.repositionNodes) ? resizeNodesLayouts(combinedNodes) : combinedNodes
6473
+ };
6474
+ });
6475
+ return _convertMermaidToReactFlowWithContext.apply(this, arguments);
6237
6476
  }
6238
6477
  function inferDirection(nodes, edges) {
6239
6478
  const nodeMap = new Map(nodes.map((node) => [node.id, node]));
@@ -6288,8 +6527,8 @@ function buildNodeIdMap(graphNodes) {
6288
6527
  }
6289
6528
  function resolveMermaidNodeLabel(node) {
6290
6529
  const nodeType = node.type;
6291
- const nodeData = toRecord(node.data);
6292
- const componentFields = Array.isArray(nodeData === null || nodeData === void 0 ? void 0 : nodeData.componentFields) ? nodeData.componentFields.map((field) => toRecord(field)).filter((field) => field !== void 0) : [];
6530
+ const nodeData$1 = toRecord(node.data);
6531
+ const componentFields = Array.isArray(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.componentFields) ? nodeData$1.componentFields.map((field) => toRecord(field)).filter((field) => field !== void 0) : [];
6293
6532
  const name = getFieldString(componentFields, "Name");
6294
6533
  if (nodeType === "text") return getFieldString(componentFields, "Text");
6295
6534
  if (nodeType === "code") return getFieldString(componentFields, "Code");
@@ -6385,9 +6624,9 @@ function formatDetailValue(value) {
6385
6624
  return entries.join(",");
6386
6625
  }
6387
6626
  }
6388
- function getNodeName(nodeData, componentFields) {
6627
+ function getNodeName(nodeData$1, componentFields) {
6389
6628
  var _getFieldString;
6390
- return (_getFieldString = getFieldString(componentFields, "Name")) !== null && _getFieldString !== void 0 ? _getFieldString : pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.name);
6629
+ return (_getFieldString = getFieldString(componentFields, "Name")) !== null && _getFieldString !== void 0 ? _getFieldString : pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.name);
6391
6630
  }
6392
6631
  function buildFieldLines(componentFields, excludedLabels) {
6393
6632
  const lines = [];
@@ -6419,25 +6658,25 @@ function buildDetailedLabel(lines) {
6419
6658
  }
6420
6659
  function resolveMermaidDetailedNodeLabel(node) {
6421
6660
  const nodeType = pickString(node.type);
6422
- const nodeData = toRecord(node.data);
6423
- const componentFields = toComponentFields(nodeData === null || nodeData === void 0 ? void 0 : nodeData.componentFields);
6424
- const name = getNodeName(nodeData, componentFields);
6661
+ const nodeData$1 = toRecord(node.data);
6662
+ const componentFields = toComponentFields(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.componentFields);
6663
+ const name = getNodeName(nodeData$1, componentFields);
6425
6664
  if (nodeType === "text") {
6426
6665
  var _getFieldString2;
6427
- const text = (_getFieldString2 = getFieldString(componentFields, "Text")) !== null && _getFieldString2 !== void 0 ? _getFieldString2 : pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.value);
6666
+ const text = (_getFieldString2 = getFieldString(componentFields, "Text")) !== null && _getFieldString2 !== void 0 ? _getFieldString2 : pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.value);
6428
6667
  return buildDetailedLabel([text ? `Text: ${text}` : "Text", ...buildFieldLines(componentFields, new Set(["name", "text"]))]);
6429
6668
  }
6430
6669
  if (nodeType === "code") {
6431
6670
  var _getFieldString3, _code$split$;
6432
- const code = (_getFieldString3 = getFieldString(componentFields, "Code")) !== null && _getFieldString3 !== void 0 ? _getFieldString3 : pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.value);
6671
+ const code = (_getFieldString3 = getFieldString(componentFields, "Code")) !== null && _getFieldString3 !== void 0 ? _getFieldString3 : pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.value);
6433
6672
  const firstLine = code === null || code === void 0 || (_code$split$ = code.split(/\r?\n/)[0]) === null || _code$split$ === void 0 ? void 0 : _code$split$.trim();
6434
6673
  return buildDetailedLabel([firstLine ? `Code: ${firstLine}` : "Code", ...buildFieldLines(componentFields, new Set(["name", "code"]))]);
6435
6674
  }
6436
6675
  if (nodeType === "data-source" || nodeType === "databaseTableSQL") {
6437
6676
  var _pickString, _pickString2, _pickString3;
6438
6677
  const lines = [];
6439
- const serviceTable = toRecord(nodeData === null || nodeData === void 0 ? void 0 : nodeData.serviceTable);
6440
- const dbConfig = toRecord(nodeData === null || nodeData === void 0 ? void 0 : nodeData.dbConfig);
6678
+ const serviceTable = toRecord(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.serviceTable);
6679
+ const dbConfig = toRecord(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.dbConfig);
6441
6680
  const database = (_pickString = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.databaseName)) !== null && _pickString !== void 0 ? _pickString : pickString(dbConfig === null || dbConfig === void 0 ? void 0 : dbConfig.databaseName);
6442
6681
  const tableName = (_pickString2 = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.tableName)) !== null && _pickString2 !== void 0 ? _pickString2 : pickString(dbConfig === null || dbConfig === void 0 ? void 0 : dbConfig.tableName);
6443
6682
  const dbService = (_pickString3 = pickString(serviceTable === null || serviceTable === void 0 ? void 0 : serviceTable.serviceName)) !== null && _pickString3 !== void 0 ? _pickString3 : pickString(dbConfig === null || dbConfig === void 0 ? void 0 : dbConfig.serviceName);
@@ -6451,9 +6690,9 @@ function resolveMermaidDetailedNodeLabel(node) {
6451
6690
  if (nodeType === "cloud") {
6452
6691
  const lines = [];
6453
6692
  lines.push(name ? `Cloud: ${name}` : "Cloud");
6454
- const cloud = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.cloud);
6693
+ const cloud = pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.cloud);
6455
6694
  if (cloud) lines.push(`provider: ${cloud}`);
6456
- const service = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.service);
6695
+ const service = pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.service);
6457
6696
  if (service) lines.push(`service: ${service}`);
6458
6697
  lines.push(...buildFieldLines(componentFields, new Set(["name"])));
6459
6698
  return buildDetailedLabel(lines);
@@ -6461,11 +6700,11 @@ function resolveMermaidDetailedNodeLabel(node) {
6461
6700
  if (nodeType === "table" || nodeType === "dataTableInterface") {
6462
6701
  var _pickString4;
6463
6702
  const lines = [];
6464
- const table = toRecord(nodeData === null || nodeData === void 0 ? void 0 : nodeData.table);
6703
+ const table = toRecord(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.table);
6465
6704
  const tableName = (_pickString4 = pickString(table === null || table === void 0 ? void 0 : table.name)) !== null && _pickString4 !== void 0 ? _pickString4 : name;
6466
6705
  lines.push(tableName ? `Table: ${tableName}` : "Table");
6467
- const columns = Array.isArray(nodeData === null || nodeData === void 0 ? void 0 : nodeData.columns) ? nodeData.columns.filter((value) => typeof value === "string").length : Array.isArray(table === null || table === void 0 ? void 0 : table.columns) ? table.columns.length : 0;
6468
- const rows = Array.isArray(nodeData === null || nodeData === void 0 ? void 0 : nodeData.rows) ? nodeData.rows.filter((value) => Array.isArray(value)).length : Array.isArray(table === null || table === void 0 ? void 0 : table.rows) ? table.rows.length : 0;
6706
+ const columns = Array.isArray(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.columns) ? nodeData$1.columns.filter((value) => typeof value === "string").length : Array.isArray(table === null || table === void 0 ? void 0 : table.columns) ? table.columns.length : 0;
6707
+ const rows = Array.isArray(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.rows) ? nodeData$1.rows.filter((value) => Array.isArray(value)).length : Array.isArray(table === null || table === void 0 ? void 0 : table.rows) ? table.rows.length : 0;
6469
6708
  lines.push(`columns: ${columns}`);
6470
6709
  lines.push(`rows: ${rows}`);
6471
6710
  lines.push(...buildFieldLines(componentFields, new Set(["name"])));
@@ -6478,7 +6717,7 @@ function resolveMermaidDetailedNodeLabel(node) {
6478
6717
  return;
6479
6718
  }
6480
6719
  if (nodeType === "gif") {
6481
- const src = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.src);
6720
+ const src = pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.src);
6482
6721
  return buildDetailedLabel([
6483
6722
  name ? `Gif: ${name}` : src ? `Gif: ${src}` : "Gif",
6484
6723
  ...src ? [`src: ${src}`] : [],
@@ -6486,7 +6725,7 @@ function resolveMermaidDetailedNodeLabel(node) {
6486
6725
  ]);
6487
6726
  }
6488
6727
  if (nodeType === "image") {
6489
- const src = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.src);
6728
+ const src = pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.src);
6490
6729
  return buildDetailedLabel([
6491
6730
  name ? `Image: ${name}` : src ? `Image: ${src}` : "Image",
6492
6731
  ...src ? [`src: ${src}`] : [],
@@ -6494,7 +6733,7 @@ function resolveMermaidDetailedNodeLabel(node) {
6494
6733
  ]);
6495
6734
  }
6496
6735
  if (nodeType === "group") {
6497
- const childCount = Array.isArray(nodeData === null || nodeData === void 0 ? void 0 : nodeData.childNodes) ? nodeData.childNodes.length : 0;
6736
+ const childCount = Array.isArray(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.childNodes) ? nodeData$1.childNodes.length : 0;
6498
6737
  return buildDetailedLabel([
6499
6738
  name ? `Group: ${name}` : "Group",
6500
6739
  `children: ${childCount}`,
@@ -6503,10 +6742,10 @@ function resolveMermaidDetailedNodeLabel(node) {
6503
6742
  }
6504
6743
  if (nodeType === "sequenceParticipant") {
6505
6744
  var _getFieldString4;
6506
- const label = (_getFieldString4 = getFieldString(componentFields, "Label")) !== null && _getFieldString4 !== void 0 ? _getFieldString4 : pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.label);
6745
+ const label = (_getFieldString4 = getFieldString(componentFields, "Label")) !== null && _getFieldString4 !== void 0 ? _getFieldString4 : pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.label);
6507
6746
  const participantName = name !== null && name !== void 0 ? name : label;
6508
- const rowCount = typeof (nodeData === null || nodeData === void 0 ? void 0 : nodeData.rowCount) === "number" ? nodeData.rowCount : void 0;
6509
- const color = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.color);
6747
+ const rowCount = typeof (nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.rowCount) === "number" ? nodeData$1.rowCount : void 0;
6748
+ const color = pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.color);
6510
6749
  return buildDetailedLabel([
6511
6750
  participantName ? `SequenceParticipant: ${participantName}` : "SequenceParticipant",
6512
6751
  ...typeof rowCount === "number" ? [`rows: ${rowCount}`] : [],
@@ -6514,9 +6753,9 @@ function resolveMermaidDetailedNodeLabel(node) {
6514
6753
  ...buildFieldLines(componentFields, new Set(["name", "label"]))
6515
6754
  ]);
6516
6755
  }
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"]))]);
6756
+ if (nodeType === "comment") return buildDetailedLabel([`Comment: ${(typeof (nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.isResolved) === "boolean" ? nodeData$1.isResolved : void 0) ? "Resolved" : "Open"}`, ...buildFieldLines(componentFields, new Set(["name"]))]);
6518
6757
  if (nodeType === "builder") {
6519
- const componentId = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.componentId);
6758
+ const componentId = pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.componentId);
6520
6759
  return buildDetailedLabel([
6521
6760
  name ? `Builder: ${name}` : "Builder",
6522
6761
  ...componentId ? [`componentId: ${componentId}`] : [],
@@ -6533,7 +6772,7 @@ function resolveMermaidDetailedNodeLabel(node) {
6533
6772
  ])));
6534
6773
  return buildDetailedLabel(lines);
6535
6774
  }
6536
- const fallbackLabel = pickString(nodeData === null || nodeData === void 0 ? void 0 : nodeData.label);
6775
+ const fallbackLabel = pickString(nodeData$1 === null || nodeData$1 === void 0 ? void 0 : nodeData$1.label);
6537
6776
  if (fallbackLabel) return `${nodeType ? nodeType.charAt(0).toUpperCase() + nodeType.slice(1) : "Node"}: ${fallbackLabel}`;
6538
6777
  }
6539
6778
  function escapeMermaidEdgeLabelText(value) {
@@ -6591,4 +6830,4 @@ function convertUiGraphToMermaid(input, options) {
6591
6830
  context
6592
6831
  };
6593
6832
  }
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 };
6833
+ 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, convertReactFlowToC4Mermaid, convertReactFlowToC4UiGraph, convertReactFlowToSequenceMermaid, convertReactFlowToSequenceUiGraph, convertUiGraphToMermaid, estimateSequenceMessageBoxSize, flattenMetaData, generateTableNodeId, generateUUID, getC4ElementColors, isC4Diagram, isC4ReactFlowDiagram, isSequenceDiagram, parseC4Diagram, sanitizeMermaidLabels, syncBaseData };