@vanduo-oss/vd3-flowchart 1.5.1 → 1.6.0

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.js CHANGED
@@ -447,6 +447,11 @@ var TOOLBAR_ICON_PATHS = {
447
447
  undo: "M224,128a96,96,0,0,1-94.71,96H128A95.38,95.38,0,0,1,62.1,197.8a8,8,0,0,1,11-11.63A80,80,0,1,0,71.43,71.39a3.07,3.07,0,0,1-.26.25L44.59,96H72a8,8,0,0,1,0,16H24a8,8,0,0,1-8-8V56a8,8,0,0,1,16,0V85.8L60.25,60A96,96,0,0,1,224,128Z",
448
448
  redo: "M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1,0-16H211.4L184.81,71.64l-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,0,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60L224,85.8V56a8,8,0,1,1,16,0Z",
449
449
  minimap: "M228.92,49.69a8,8,0,0,0-6.86-1.45L160.93,63.52,99.58,32.84a8,8,0,0,0-5.52-.6l-64,16A8,8,0,0,0,24,56V200a8,8,0,0,0,9.94,7.76l61.13-15.28,61.35,30.68A8.15,8.15,0,0,0,160,224a8,8,0,0,0,1.94-.24l64-16A8,8,0,0,0,232,200V56A8,8,0,0,0,228.92,49.69ZM104,52.94l48,24V203.06l-48-24ZM40,62.25l48-12v127.5l-48,12Zm176,131.5-48,12V78.25l48-12Z",
450
+ palette: "M200.77,53.89A103.27,103.27,0,0,0,128,24h-1.07A104,104,0,0,0,24,128c0,43,26.58,79.06,69.36,94.17A32,32,0,0,0,136,192a16,16,0,0,1,16-16h46.21a31.81,31.81,0,0,0,31.2-24.88,104.43,104.43,0,0,0,2.59-24A103.28,103.28,0,0,0,200.77,53.89Zm13,93.71A15.89,15.89,0,0,1,198.21,160H152a32,32,0,0,0-32,32,16,16,0,0,1-21.31,15.07C62.49,194.3,40,164,40,128a88,88,0,0,1,87.09-88h.9a88.35,88.35,0,0,1,88,87.25A88.86,88.86,0,0,1,213.81,147.6ZM140,76a12,12,0,1,1-12-12A12,12,0,0,1,140,76ZM96,100A12,12,0,1,1,84,88,12,12,0,0,1,96,100Zm0,56a12,12,0,1,1-12-12A12,12,0,0,1,96,156Zm88-56a12,12,0,1,1-12-12A12,12,0,0,1,184,100Z",
451
+ "bring-to-front": "M216,104H168V56a16,16,0,0,0-16-16H56A16,16,0,0,0,40,56v96a16,16,0,0,0,16,16h48v48a16,16,0,0,0,16,16h96a16,16,0,0,0,16-16V120A16,16,0,0,0,216,104ZM56,152V56h96v48H120a16,16,0,0,0-16,16v32Zm160,64H120V120h96Z",
452
+ "send-to-back": "M216,104H168V56a16,16,0,0,0-16-16H56A16,16,0,0,0,40,56v96a16,16,0,0,0,16,16h48v48a16,16,0,0,0,16,16h96a16,16,0,0,0,16-16V120A16,16,0,0,0,216,104ZM56,56h96v96H56Zm160,160H120V168h32a16,16,0,0,0,16-16V120h48Z",
453
+ lock: "M208,80H176V56a48,48,0,0,0-96,0V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80ZM96,56a32,32,0,0,1,64,0V80H96ZM208,208H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z",
454
+ unlock: "M208,80H96V56a32,32,0,0,1,32-32c15.37,0,29.2,11,32.16,25.59a8,8,0,0,0,15.68-3.18C171.32,24.15,151.32,8,128,8A48.05,48.05,0,0,0,80,56V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm0,128H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z",
450
455
  clear: "M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM96,40a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96Zm96,168H64V64H192ZM112,104v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Zm48,0v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Z"
451
456
  };
452
457
  var TOOLBAR_ACTIONS = [
@@ -523,7 +528,7 @@ var EDGE_STROKE_PRESETS = [
523
528
  { id: "medium", label: "Medium", width: DEFAULT_EDGE_STROKE_WIDTH },
524
529
  { id: "bold", label: "Bold", width: 3.5 }
525
530
  ];
526
- var VD_FLOWCHART_VERSION = "1.5.1";
531
+ var VD_FLOWCHART_VERSION = "1.6.0";
527
532
  var FLOWCHART_DOCUMENT_VERSION = "1.3.0";
528
533
  var FLOWCHART_NODE_TYPES = [
529
534
  "rounded-rect",
@@ -537,10 +542,92 @@ var FLOWCHART_NODE_TYPES = [
537
542
  var FLOWCHART_PORTS = ["top", "right", "bottom", "left"];
538
543
  var FLOWCHART_EDGE_MARKERS = ["none", "arrow", "dot"];
539
544
  var FLOWCHART_EDGE_ROUTES = ["curve", "straight", "orthogonal"];
545
+ var FLOWCHART_EDGE_STROKE_STYLES = ["solid", "dashed", "dotted", "animated"];
546
+ var FLOWCHART_COLOR_PRESETS = [
547
+ "default",
548
+ "primary",
549
+ "secondary",
550
+ "success",
551
+ "warning",
552
+ "danger",
553
+ "info",
554
+ "violet",
555
+ "teal",
556
+ "orange",
557
+ "pink",
558
+ "neutral"
559
+ ];
560
+ var FLOWCHART_NODE_ALIGNMENTS = ["left", "center", "right", "top", "middle", "bottom"];
561
+ var FLOWCHART_DISTRIBUTE_AXES = ["horizontal", "vertical"];
540
562
  var FLOWCHART_KEYBOARD_SHORTCUTS = ["mindmap", "basic"];
563
+ var FLOWCHART_COLOR_PRESET_LABELS = {
564
+ default: "Default",
565
+ primary: "Primary",
566
+ secondary: "Secondary",
567
+ success: "Success",
568
+ warning: "Warning",
569
+ danger: "Danger",
570
+ info: "Info",
571
+ violet: "Violet",
572
+ teal: "Teal",
573
+ orange: "Orange",
574
+ pink: "Pink",
575
+ neutral: "Neutral"
576
+ };
577
+ var FLOWCHART_COLOR_PRESET_SET = new Set(FLOWCHART_COLOR_PRESETS);
578
+ var FLOWCHART_COLOR_PRESET_FALLBACKS = {
579
+ primary: { fill: "#dbeafe", stroke: "#2563eb", text: "#1e3a8a", edge: "#2563eb" },
580
+ secondary: { fill: "#e0e7ff", stroke: "#4f46e5", text: "#312e81", edge: "#4f46e5" },
581
+ success: { fill: "#dcfce7", stroke: "#16a34a", text: "#14532d", edge: "#16a34a" },
582
+ warning: { fill: "#fef3c7", stroke: "#d97706", text: "#78350f", edge: "#d97706" },
583
+ danger: { fill: "#fee2e2", stroke: "#dc2626", text: "#7f1d1d", edge: "#dc2626" },
584
+ info: { fill: "#e0f2fe", stroke: "#0284c7", text: "#0c4a6e", edge: "#0284c7" },
585
+ violet: { fill: "#f3e8ff", stroke: "#9333ea", text: "#581c87", edge: "#9333ea" },
586
+ teal: { fill: "#ccfbf1", stroke: "#0d9488", text: "#134e4a", edge: "#0d9488" },
587
+ orange: { fill: "#ffedd5", stroke: "#ea580c", text: "#7c2d12", edge: "#ea580c" },
588
+ pink: { fill: "#fce7f3", stroke: "#db2777", text: "#831843", edge: "#db2777" },
589
+ neutral: { fill: "#f1f5f9", stroke: "#64748b", text: "#1e293b", edge: "#64748b" }
590
+ };
591
+ var FLOWCHART_EDGE_STROKE_STYLE_LABELS = {
592
+ solid: "Solid",
593
+ dashed: "Dashed",
594
+ dotted: "Dotted",
595
+ animated: "Animated flow"
596
+ };
541
597
  function normalizeKeyboardShortcuts(value) {
542
598
  return value === "basic" ? "basic" : "mindmap";
543
599
  }
600
+ function normalizeColorPreset(value) {
601
+ if (typeof value !== "string") return "";
602
+ const trimmed = value.trim().toLowerCase();
603
+ return FLOWCHART_COLOR_PRESETS.includes(trimmed) && trimmed !== "default" ? trimmed : "";
604
+ }
605
+ function sanitizeCssColor(value) {
606
+ if (typeof value !== "string") return "";
607
+ const trimmed = value.trim();
608
+ if (!trimmed || trimmed === "default") return "";
609
+ if (trimmed.length > 64 || /\\/.test(trimmed)) return "";
610
+ if (/[;{}<>"'`]/.test(trimmed) || /url\s*\(|expression\s*\(|javascript\s*:/i.test(trimmed)) {
611
+ return "";
612
+ }
613
+ if (!/^[#a-z0-9(),.%\s/+-]+$/i.test(trimmed)) return "";
614
+ return trimmed;
615
+ }
616
+ function normalizeEdgeColor(value) {
617
+ const preset = normalizeColorPreset(value);
618
+ if (preset) return preset;
619
+ return sanitizeCssColor(value);
620
+ }
621
+ function normalizeEdgeStrokeStyle(value) {
622
+ return FLOWCHART_EDGE_STROKE_STYLES.includes(value) && value !== "solid" ? value : "solid";
623
+ }
624
+ function resolveEdgeColorValue(color) {
625
+ if (!color || color === "default") return "var(--vd-flowchart-accent)";
626
+ if (FLOWCHART_COLOR_PRESETS.includes(color)) {
627
+ return `var(--vd-flowchart-palette-${color}-edge)`;
628
+ }
629
+ return color;
630
+ }
544
631
  var ARROW_DIRECTIONS = {
545
632
  ArrowRight: "right",
546
633
  ArrowLeft: "left",
@@ -581,6 +668,8 @@ function getShortcutRows(mode, readonly) {
581
668
  "Edit the connection label"
582
669
  ],
583
670
  ["Cmd/Ctrl + /", "Collapse or expand the branch"],
671
+ ["Cmd/Ctrl + ] or [", "Bring forward or send backward (Shift: front/back)"],
672
+ ["Cmd/Ctrl + L", "Lock or unlock the selected node"],
584
673
  ["Alt + Arrow", "Nudge the node (add Shift for 1 px)"],
585
674
  ["Delete or Backspace", "Delete the selection"],
586
675
  ["Cmd/Ctrl + D", "Duplicate the node"],
@@ -765,10 +854,12 @@ function clampNodeHeight(type, height, fallback, sizeBounds) {
765
854
  return clamp(toFiniteNumber(height, fallback), bounds.minHeight, bounds.maxHeight);
766
855
  }
767
856
  function isNodeResizable(nodeOrType) {
857
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
768
858
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
769
859
  return spec.resizable !== false;
770
860
  }
771
861
  function isNodeTextEditable(nodeOrType) {
862
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
772
863
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
773
864
  return spec.textEditable !== false;
774
865
  }
@@ -808,6 +899,15 @@ function normalizeNode(rawNode, index, usedIds, sizeBounds) {
808
899
  data: isPlainObject(rawNode?.data) ? deepClone(rawNode.data) : {}
809
900
  };
810
901
  if (rawNode?.collapsed === true) node.collapsed = true;
902
+ const color = normalizeColorPreset(rawNode?.color ?? rawNode?.data?.color);
903
+ if (color) node.color = color;
904
+ const fill = sanitizeCssColor(rawNode?.fill ?? rawNode?.data?.fill);
905
+ if (fill) node.fill = fill;
906
+ const stroke = sanitizeCssColor(rawNode?.stroke ?? rawNode?.data?.stroke);
907
+ if (stroke) node.stroke = stroke;
908
+ const textColor = sanitizeCssColor(rawNode?.textColor ?? rawNode?.data?.textColor);
909
+ if (textColor) node.textColor = textColor;
910
+ if (rawNode?.locked === true || rawNode?.data?.locked === true) node.locked = true;
811
911
  return node;
812
912
  }
813
913
  function computeHiddenNodeIds(nodes, edges) {
@@ -840,6 +940,12 @@ function computeHiddenNodeIds(nodes, edges) {
840
940
  return candidates;
841
941
  }
842
942
  function normalizeEndpoint(rawEndpoint, fallbackPort) {
943
+ if (typeof rawEndpoint === "string") {
944
+ return {
945
+ nodeId: sanitizeId(rawEndpoint),
946
+ port: fallbackPort
947
+ };
948
+ }
843
949
  return {
844
950
  nodeId: sanitizeId(rawEndpoint?.nodeId),
845
951
  port: FLOWCHART_PORTS.includes(rawEndpoint?.port) ? rawEndpoint.port : fallbackPort
@@ -875,6 +981,10 @@ function normalizeEdge(rawEdge, index, nodeIds, usedIds) {
875
981
  label: rawEdge?.label == null ? "" : String(rawEdge.label),
876
982
  data: isPlainObject(rawEdge?.data) ? deepClone(rawEdge.data) : {}
877
983
  };
984
+ const color = normalizeEdgeColor(rawEdge?.color ?? rawEdge?.data?.color);
985
+ if (color) edge.color = color;
986
+ const strokeStyle = normalizeEdgeStrokeStyle(rawEdge?.strokeStyle ?? rawEdge?.data?.strokeStyle);
987
+ if (strokeStyle !== "solid") edge.strokeStyle = strokeStyle;
878
988
  syncEdgeKind(edge);
879
989
  return edge;
880
990
  }
@@ -1321,19 +1431,75 @@ function buildOrthogonalPath(fromPoint, toPoint, fromPort = "right", toPort = "l
1321
1431
  labelY: label.y
1322
1432
  };
1323
1433
  }
1434
+ function getPortOuterOffset(node, port) {
1435
+ if (!node || node.type === "label") return 0;
1436
+ const visual = nodeVisualScale(node);
1437
+ const baseStroke = node.type === "junction" ? 1.25 : 1.5;
1438
+ const halfStroke = Math.max(0.015, baseStroke * visual / 2);
1439
+ if (node.type === "diamond") {
1440
+ const w = Math.max(1, toFiniteNumber(node.width, 184));
1441
+ const h2 = Math.max(1, toFiniteNumber(node.height, 120));
1442
+ const diag = Math.hypot(w, h2);
1443
+ const miterFactor = isHorizontalPort(port) ? Math.min(4, diag / h2) : Math.min(4, diag / w);
1444
+ return halfStroke * miterFactor;
1445
+ }
1446
+ return halfStroke;
1447
+ }
1448
+ function getMarkerEndpointRetraction(markerType, strokeWidth, edgeScale = 1) {
1449
+ if (!markerType || markerType === "none") return 0;
1450
+ const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1451
+ const effective = Math.max(0.02, normalizeEdgeStrokeWidth(strokeWidth) * scale);
1452
+ if (markerType === "dot") {
1453
+ return formatNumber(Math.max(2.75 * scale, effective * 1.45));
1454
+ }
1455
+ return formatNumber(Math.max(1.5 * scale, effective * 0.85));
1456
+ }
1324
1457
  function buildEdgePath(edge, fromNode = null, toNode = null) {
1325
1458
  const fromPort = edge?.from?.port || edge?.fromPort || "right";
1326
1459
  const toPort = edge?.to?.port || edge?.toPort || "left";
1327
- const fromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
1328
- const toPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
1460
+ const rawFromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
1461
+ const rawToPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
1329
1462
  const route = normalizeEdgeRoute(edge?.route);
1330
- const metrics = routeMetrics(edgeVisualScale(fromNode, toNode));
1331
- if (!fromPoint || !toPoint) {
1463
+ const visualScale = edgeVisualScale(fromNode, toNode);
1464
+ const metrics = routeMetrics(visualScale);
1465
+ if (!rawFromPoint || !rawToPoint) {
1332
1466
  return { d: "", labelX: 0, labelY: 0 };
1333
1467
  }
1468
+ const strokeWidth = normalizeEdgeStrokeWidth(edge?.strokeWidth);
1469
+ const startMarker = edge?.startMarker || "none";
1470
+ const endMarker = edge?.endMarker || "none";
1471
+ const rawDistance = Math.hypot(rawToPoint.x - rawFromPoint.x, rawToPoint.y - rawFromPoint.y);
1472
+ const maxRetract = rawDistance > 0 ? rawDistance * 0.45 : 0;
1473
+ const fromMarkerRetract = !edge?.fromPoint && fromNode && startMarker !== "none" ? getMarkerEndpointRetraction(startMarker, strokeWidth, visualScale) : 0;
1474
+ const fromBorderRetract = fromMarkerRetract > 0 ? getPortOuterOffset(fromNode, fromPort) : 0;
1475
+ const toMarkerRetract = !edge?.toPoint && toNode && endMarker !== "none" ? getMarkerEndpointRetraction(endMarker, strokeWidth, visualScale) : 0;
1476
+ const toBorderRetract = toMarkerRetract > 0 ? getPortOuterOffset(toNode, toPort) : 0;
1477
+ const fromRetract = Math.min(maxRetract, fromMarkerRetract + fromBorderRetract);
1478
+ const toRetract = Math.min(maxRetract, toMarkerRetract + toBorderRetract);
1334
1479
  if (route === "straight") {
1335
- return buildStraightPath(fromPoint, toPoint);
1480
+ const borderFrom = fromBorderRetract > 0 ? offsetPoint(
1481
+ rawFromPoint,
1482
+ getPortNormal(fromPort),
1483
+ Math.min(maxRetract, fromBorderRetract)
1484
+ ) : rawFromPoint;
1485
+ const borderTo = toBorderRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), Math.min(maxRetract, toBorderRetract)) : rawToPoint;
1486
+ const dx = borderTo.x - borderFrom.x;
1487
+ const dy = borderTo.y - borderFrom.y;
1488
+ const dist = Math.hypot(dx, dy);
1489
+ if (dist > 0.01) {
1490
+ const ux = dx / dist;
1491
+ const uy = dy / dist;
1492
+ const sRetract = Math.min(dist * 0.45, fromMarkerRetract);
1493
+ const eRetract = Math.min(dist * 0.45, toMarkerRetract);
1494
+ return buildStraightPath(
1495
+ { x: borderFrom.x + ux * sRetract, y: borderFrom.y + uy * sRetract },
1496
+ { x: borderTo.x - ux * eRetract, y: borderTo.y - uy * eRetract }
1497
+ );
1498
+ }
1499
+ return buildStraightPath(rawFromPoint, rawToPoint);
1336
1500
  }
1501
+ const fromPoint = fromRetract > 0 ? offsetPoint(rawFromPoint, getPortNormal(fromPort), fromRetract) : rawFromPoint;
1502
+ const toPoint = toRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), toRetract) : rawToPoint;
1337
1503
  if (route === "orthogonal") {
1338
1504
  const fromRect = !edge?.fromPoint && fromNode ? getNodeRectBounds(fromNode, metrics.clearance) : null;
1339
1505
  const toRect = !edge?.toPoint && toNode ? getNodeRectBounds(toNode, metrics.clearance) : null;
@@ -1341,7 +1507,7 @@ function buildEdgePath(edge, fromNode = null, toNode = null) {
1341
1507
  }
1342
1508
  return buildCurvePath(fromPoint, toPoint, fromPort, toPort, metrics);
1343
1509
  }
1344
- function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1510
+ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1345
1511
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1346
1512
  const effective = Math.max(0.02, strokeWidth * scale);
1347
1513
  const size = formatNumber(Math.max(9 * scale, effective * 4.4));
@@ -1358,12 +1524,12 @@ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1358
1524
  marker.appendChild(
1359
1525
  svgEl("path", {
1360
1526
  d: reversed ? `M ${formatNumber(size)} 0 L 0 ${formatNumber(size / 2)} L ${formatNumber(size)} ${formatNumber(size)} z` : `M 0 0 L ${formatNumber(size)} ${formatNumber(size / 2)} L 0 ${formatNumber(size)} z`,
1361
- fill: "var(--vd-flowchart-accent)"
1527
+ fill
1362
1528
  })
1363
1529
  );
1364
1530
  return marker;
1365
1531
  }
1366
- function createDotMarker(id, strokeWidth, edgeScale = 1) {
1532
+ function createDotMarker(id, strokeWidth, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1367
1533
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1368
1534
  const effective = Math.max(0.02, strokeWidth * scale);
1369
1535
  const size = formatNumber(Math.max(8 * scale, effective * 3.3));
@@ -1382,7 +1548,7 @@ function createDotMarker(id, strokeWidth, edgeScale = 1) {
1382
1548
  cx: formatNumber(size / 2),
1383
1549
  cy: formatNumber(size / 2),
1384
1550
  r: radius,
1385
- fill: "var(--vd-flowchart-accent)"
1551
+ fill
1386
1552
  })
1387
1553
  );
1388
1554
  return marker;
@@ -1671,6 +1837,7 @@ var VdFlowchart = class {
1671
1837
  this.minimapFrame = 0;
1672
1838
  this.minimapDrag = null;
1673
1839
  this.shortcutsHelpOpen = false;
1840
+ this.colorPopoverOpen = false;
1674
1841
  this.autoFit = Boolean(options.autoFit);
1675
1842
  this.readyEmitted = false;
1676
1843
  this.resizeObserver = null;
@@ -1687,8 +1854,10 @@ var VdFlowchart = class {
1687
1854
  this.handleKeyDown = this.handleKeyDown.bind(this);
1688
1855
  this.handleSelectionFieldInput = this.handleSelectionFieldInput.bind(this);
1689
1856
  this.handleSelectionFieldChange = this.handleSelectionFieldChange.bind(this);
1857
+ this.handleSelectionActionClick = this.handleSelectionActionClick.bind(this);
1690
1858
  this.handleJsonActionClick = this.handleJsonActionClick.bind(this);
1691
1859
  this.handleResize = this.handleResize.bind(this);
1860
+ this.handleOutsidePointerDown = this.handleOutsidePointerDown.bind(this);
1692
1861
  this.buildShell();
1693
1862
  this.bindEvents();
1694
1863
  this.render();
@@ -1772,6 +1941,32 @@ var VdFlowchart = class {
1772
1941
  this.arrangeSelect.appendChild(option);
1773
1942
  });
1774
1943
  this.arrangeSelect.value = this.layoutMode;
1944
+ this.colorPopoverWrap = createElement("div", { className: "vd-flowchart-color-popover-wrap" });
1945
+ this.colorButton = createToolbarButton({
1946
+ action: "color-popover",
1947
+ label: "Color selection",
1948
+ icon: "palette",
1949
+ disabled: this.readonly
1950
+ });
1951
+ this.colorButton.setAttribute("aria-expanded", "false");
1952
+ this.colorPopover = createElement("div", { className: "vd-flowchart-color-popover" });
1953
+ this.colorPopover.hidden = true;
1954
+ this.colorPopover.setAttribute("role", "dialog");
1955
+ this.colorPopover.setAttribute("aria-label", "Color presets");
1956
+ const popoverSwatches = createElement("div", { className: "vd-flowchart-swatch-grid" });
1957
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
1958
+ const swatch = createElement("button", {
1959
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}`,
1960
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset
1961
+ });
1962
+ swatch.setAttribute("type", "button");
1963
+ swatch.setAttribute("data-flowchart-color", preset);
1964
+ swatch.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
1965
+ popoverSwatches.appendChild(swatch);
1966
+ });
1967
+ this.colorPopover.appendChild(popoverSwatches);
1968
+ this.colorPopoverWrap.appendChild(this.colorButton);
1969
+ this.colorPopoverWrap.appendChild(this.colorPopover);
1775
1970
  this.clearButton = createToolbarButton({
1776
1971
  action: "clear",
1777
1972
  label: "Clear canvas",
@@ -1798,6 +1993,7 @@ var VdFlowchart = class {
1798
1993
  });
1799
1994
  this.minimapButton.setAttribute("aria-pressed", this.minimapEnabled ? "true" : "false");
1800
1995
  toolbarLeft.appendChild(this.arrangeSelect);
1996
+ toolbarLeft.appendChild(this.colorPopoverWrap);
1801
1997
  toolbarLeft.appendChild(this.clearButton);
1802
1998
  toolbarRight.appendChild(this.minimapButton);
1803
1999
  toolbarRight.appendChild(this.shortcutsButton);
@@ -2088,6 +2284,7 @@ var VdFlowchart = class {
2088
2284
  this.deleteButton.addEventListener("click", () => this.deleteSelection());
2089
2285
  this.selectionFields.addEventListener("input", this.handleSelectionFieldInput);
2090
2286
  this.selectionFields.addEventListener("change", this.handleSelectionFieldChange);
2287
+ this.selectionFields.addEventListener("click", this.handleSelectionActionClick);
2091
2288
  this.jsonActions.addEventListener("click", this.handleJsonActionClick);
2092
2289
  this.canvasEl.addEventListener("pointerdown", this.handlePointerDown);
2093
2290
  this.canvasEl.addEventListener("pointermove", this.handlePointerMove);
@@ -2099,6 +2296,7 @@ var VdFlowchart = class {
2099
2296
  this.canvasEl.addEventListener("blur", this.handleCanvasBlur);
2100
2297
  this.root.addEventListener("keydown", this.handleKeyDown, true);
2101
2298
  window.addEventListener("pointerup", this.handlePointerUp);
2299
+ window.addEventListener("pointerdown", this.handleOutsidePointerDown);
2102
2300
  window.addEventListener("resize", this.handleResize);
2103
2301
  }
2104
2302
  unbindEvents() {
@@ -2107,6 +2305,7 @@ var VdFlowchart = class {
2107
2305
  this.paletteGrid.removeEventListener("click", this.handlePaletteClick);
2108
2306
  this.selectionFields.removeEventListener("input", this.handleSelectionFieldInput);
2109
2307
  this.selectionFields.removeEventListener("change", this.handleSelectionFieldChange);
2308
+ this.selectionFields.removeEventListener("click", this.handleSelectionActionClick);
2110
2309
  this.jsonActions.removeEventListener("click", this.handleJsonActionClick);
2111
2310
  this.canvasEl.removeEventListener("pointerdown", this.handlePointerDown);
2112
2311
  this.canvasEl.removeEventListener("pointermove", this.handlePointerMove);
@@ -2118,8 +2317,14 @@ var VdFlowchart = class {
2118
2317
  this.canvasEl.removeEventListener("blur", this.handleCanvasBlur);
2119
2318
  this.root.removeEventListener("keydown", this.handleKeyDown, true);
2120
2319
  window.removeEventListener("pointerup", this.handlePointerUp);
2320
+ window.removeEventListener("pointerdown", this.handleOutsidePointerDown);
2121
2321
  window.removeEventListener("resize", this.handleResize);
2122
2322
  }
2323
+ handleOutsidePointerDown(event) {
2324
+ if (!this.colorPopoverOpen || this.destroyed) return;
2325
+ if (event.target?.closest?.(".vd-flowchart-color-popover-wrap")) return;
2326
+ this.toggleColorPopover(false);
2327
+ }
2123
2328
  handleResize() {
2124
2329
  if (this.destroyed) return;
2125
2330
  this.render({ inspector: false, json: false });
@@ -2158,7 +2363,24 @@ var VdFlowchart = class {
2158
2363
  this.updatePaletteState();
2159
2364
  this.render({ scene: true, inspector: false, json: false });
2160
2365
  }
2366
+ toggleColorPopover(force) {
2367
+ if (!this.colorPopover || !this.colorButton) return this;
2368
+ const open = typeof force === "boolean" ? force : !this.colorPopoverOpen;
2369
+ this.colorPopoverOpen = open && !this.readonly;
2370
+ this.colorPopover.hidden = !this.colorPopoverOpen;
2371
+ this.colorButton.setAttribute("aria-expanded", this.colorPopoverOpen ? "true" : "false");
2372
+ return this;
2373
+ }
2161
2374
  handleToolbarClick(event) {
2375
+ const colorSwatch = event.target.closest("[data-flowchart-color]");
2376
+ if (colorSwatch) {
2377
+ if (!this.readonly) {
2378
+ const preset = colorSwatch.getAttribute("data-flowchart-color");
2379
+ this.setSelectionColor(preset);
2380
+ }
2381
+ this.toggleColorPopover(false);
2382
+ return;
2383
+ }
2162
2384
  const actionButton = event.target.closest("[data-flowchart-action]");
2163
2385
  if (!actionButton) return;
2164
2386
  const action = actionButton.getAttribute("data-flowchart-action");
@@ -2168,6 +2390,7 @@ var VdFlowchart = class {
2168
2390
  if (action === "fit-view") this.fitView();
2169
2391
  if (action === "undo") this.undo();
2170
2392
  if (action === "redo") this.redo();
2393
+ if (action === "color-popover") this.toggleColorPopover();
2171
2394
  if (action === "clear" && !this.readonly) this.clear();
2172
2395
  if (action === "shortcuts") this.toggleShortcutsHelp();
2173
2396
  if (action === "minimap") this.setMinimapEnabled(!this.minimapEnabled);
@@ -2230,16 +2453,18 @@ var VdFlowchart = class {
2230
2453
  nodes.forEach((node) => {
2231
2454
  const point = map(node.x, node.y);
2232
2455
  const selected = this.isNodeSelected(node.id);
2233
- this.minimapSvg.appendChild(
2234
- svgEl("rect", {
2235
- class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
2236
- x: point.x,
2237
- y: point.y,
2238
- width: formatNumber(Math.max(1.5, node.width * transform.scale)),
2239
- height: formatNumber(Math.max(1.5, node.height * transform.scale)),
2240
- rx: 1.5
2241
- })
2242
- );
2456
+ const rectEl = svgEl("rect", {
2457
+ class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
2458
+ x: point.x,
2459
+ y: point.y,
2460
+ width: formatNumber(Math.max(1.5, node.width * transform.scale)),
2461
+ height: formatNumber(Math.max(1.5, node.height * transform.scale)),
2462
+ rx: 1.5
2463
+ });
2464
+ if (node.color) rectEl.setAttribute("data-color", node.color);
2465
+ if (node.fill) rectEl.style.fill = node.fill;
2466
+ if (node.stroke) rectEl.style.stroke = node.stroke;
2467
+ this.minimapSvg.appendChild(rectEl);
2243
2468
  });
2244
2469
  const corner = map(view.left, view.top);
2245
2470
  this.minimapSvg.appendChild(
@@ -2361,6 +2586,42 @@ var VdFlowchart = class {
2361
2586
  }
2362
2587
  }
2363
2588
  }
2589
+ handleSelectionActionClick(event) {
2590
+ if (this.readonly) return;
2591
+ const swatch = event.target.closest("[data-color-preset]");
2592
+ if (swatch) {
2593
+ this.setSelectionColor(swatch.getAttribute("data-color-preset"));
2594
+ return;
2595
+ }
2596
+ const resetBtn = event.target.closest("[data-color-reset]");
2597
+ if (resetBtn) {
2598
+ this.clearSelectionColor();
2599
+ return;
2600
+ }
2601
+ const arrangeBtn = event.target.closest("[data-arrange-action]");
2602
+ if (arrangeBtn) {
2603
+ const action = arrangeBtn.getAttribute("data-arrange-action");
2604
+ if (action === "bring-to-front") this.bringToFront();
2605
+ else if (action === "bring-forward") this.bringForward();
2606
+ else if (action === "send-backward") this.sendBackward();
2607
+ else if (action === "send-to-back") this.sendToBack();
2608
+ return;
2609
+ }
2610
+ const alignBtn = event.target.closest("[data-align-action]");
2611
+ if (alignBtn) {
2612
+ this.alignNodes(alignBtn.getAttribute("data-align-action"));
2613
+ return;
2614
+ }
2615
+ const distributeBtn = event.target.closest("[data-distribute-action]");
2616
+ if (distributeBtn) {
2617
+ this.distributeNodes(distributeBtn.getAttribute("data-distribute-action"));
2618
+ return;
2619
+ }
2620
+ const lockBtn = event.target.closest("[data-lock-toggle]");
2621
+ if (lockBtn) {
2622
+ this.toggleNodeLocked();
2623
+ }
2624
+ }
2364
2625
  handleSelectionFieldInput(event) {
2365
2626
  const field = event.target.getAttribute("data-field");
2366
2627
  if (!field) return;
@@ -2383,6 +2644,38 @@ var VdFlowchart = class {
2383
2644
  if (field === "node-width" || field === "node-height") {
2384
2645
  const patch = field === "node-width" ? { width: toFiniteNumber(event.target.value, void 0) } : { height: toFiniteNumber(event.target.value, void 0) };
2385
2646
  this.updateNode(this.selection?.id, patch, { inspector: false, reason: "node:update" });
2647
+ return;
2648
+ }
2649
+ if (field === "node-fill") {
2650
+ this.updateNode(
2651
+ this.selection?.id,
2652
+ { fill: event.target.value },
2653
+ { inspector: false, reason: "node:update" }
2654
+ );
2655
+ return;
2656
+ }
2657
+ if (field === "node-stroke") {
2658
+ this.updateNode(
2659
+ this.selection?.id,
2660
+ { stroke: event.target.value },
2661
+ { inspector: false, reason: "node:update" }
2662
+ );
2663
+ return;
2664
+ }
2665
+ if (field === "node-text-color") {
2666
+ this.updateNode(
2667
+ this.selection?.id,
2668
+ { textColor: event.target.value },
2669
+ { inspector: false, reason: "node:update" }
2670
+ );
2671
+ return;
2672
+ }
2673
+ if (field === "edge-color") {
2674
+ this.updateEdge(
2675
+ this.selection?.id,
2676
+ { color: event.target.value },
2677
+ { inspector: false, reason: "edge:update" }
2678
+ );
2386
2679
  }
2387
2680
  }
2388
2681
  handleSelectionFieldChange(event) {
@@ -2426,6 +2719,14 @@ var VdFlowchart = class {
2426
2719
  { strokeWidth: getStrokePresetWidth(event.target.value) },
2427
2720
  { inspector: true, reason: "edge:update" }
2428
2721
  );
2722
+ return;
2723
+ }
2724
+ if (field === "edge-stroke-style") {
2725
+ this.updateEdge(
2726
+ this.selection?.id,
2727
+ { strokeStyle: event.target.value },
2728
+ { inspector: true, reason: "edge:update" }
2729
+ );
2429
2730
  }
2430
2731
  }
2431
2732
  // Keys the editor consumes stop here, so page-level shortcuts (a docs
@@ -2448,6 +2749,11 @@ var VdFlowchart = class {
2448
2749
  this.toggleShortcutsHelp(false);
2449
2750
  return;
2450
2751
  }
2752
+ if (key === "Escape" && this.colorPopoverOpen) {
2753
+ event.preventDefault();
2754
+ this.toggleColorPopover(false);
2755
+ return;
2756
+ }
2451
2757
  if (target === this.canvasEl && this.handleCanvasKeyDown(event)) {
2452
2758
  event.preventDefault();
2453
2759
  return;
@@ -2470,6 +2776,29 @@ var VdFlowchart = class {
2470
2776
  }
2471
2777
  return;
2472
2778
  }
2779
+ if (modKey && (key === "l" || key === "L")) {
2780
+ if (this.selection?.kind === "node") {
2781
+ event.preventDefault();
2782
+ this.toggleNodeLocked();
2783
+ }
2784
+ return;
2785
+ }
2786
+ if (modKey && (key === "]" || key === "}" || event.code === "BracketRight")) {
2787
+ if (this.selection) {
2788
+ event.preventDefault();
2789
+ if (event.shiftKey || key === "}") this.bringToFront();
2790
+ else this.bringForward();
2791
+ }
2792
+ return;
2793
+ }
2794
+ if (modKey && (key === "[" || key === "{" || event.code === "BracketLeft")) {
2795
+ if (this.selection) {
2796
+ event.preventDefault();
2797
+ if (event.shiftKey || key === "{") this.sendToBack();
2798
+ else this.sendBackward();
2799
+ }
2800
+ return;
2801
+ }
2473
2802
  if (modKey && (event.key === "z" || event.key === "Z")) {
2474
2803
  event.preventDefault();
2475
2804
  if (event.shiftKey) {
@@ -2652,7 +2981,7 @@ var VdFlowchart = class {
2652
2981
  nudgeNodes(nodeIds, direction, distance) {
2653
2982
  const step = { right: [1, 0], left: [-1, 0], down: [0, 1], up: [0, -1] }[direction];
2654
2983
  if (this.readonly || !step) return [];
2655
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
2984
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
2656
2985
  if (!nodes.length) return [];
2657
2986
  nodes.forEach((node) => {
2658
2987
  node.x = formatNumber(node.x + step[0] * distance);
@@ -2791,6 +3120,14 @@ var VdFlowchart = class {
2791
3120
  this.emitChange("edge:add", { edge: deepClone(edge) });
2792
3121
  return true;
2793
3122
  }
3123
+ pasteSelection() {
3124
+ if (!this.pasteClipboard()) return null;
3125
+ if (this.hasMultiSelection()) {
3126
+ return this.getSelectedNodeIds().map((id) => this.findNode(id)).filter(Boolean).map((node) => deepClone(node));
3127
+ }
3128
+ const snap = this.getSelectionSnapshot();
3129
+ return snap?.node || snap?.edge || null;
3130
+ }
2794
3131
  cutSelection() {
2795
3132
  if (!this.copySelection()) return false;
2796
3133
  return this.deleteSelection();
@@ -2828,6 +3165,9 @@ var VdFlowchart = class {
2828
3165
  }
2829
3166
  handlePointerDown(event) {
2830
3167
  if (this.destroyed || event.button != null && event.button !== 0) return;
3168
+ if (this.colorPopoverOpen) {
3169
+ this.toggleColorPopover(false);
3170
+ }
2831
3171
  if (this.textEditor && !event.target.closest(".vd-flowchart-text-editor")) {
2832
3172
  this.stopTextEdit({ commit: true });
2833
3173
  }
@@ -2852,6 +3192,8 @@ var VdFlowchart = class {
2852
3192
  const fromNode = this.findNode(edge.from.nodeId);
2853
3193
  const toNode = this.findNode(edge.to.nodeId);
2854
3194
  if (!fromNode || !toNode) return;
3195
+ const endpointNode = endpoint === "from" ? fromNode : toNode;
3196
+ if (endpointNode.locked) return;
2855
3197
  this.reconnectEdgeId = edgeId;
2856
3198
  this.select({ kind: "edge", id: edgeId });
2857
3199
  this.interaction = {
@@ -2902,7 +3244,7 @@ var VdFlowchart = class {
2902
3244
  const nodeId = portTarget.getAttribute("data-node-id");
2903
3245
  const port = portTarget.getAttribute("data-port");
2904
3246
  const node = this.findNode(nodeId);
2905
- if (!node) return;
3247
+ if (!node || node.locked) return;
2906
3248
  const sourcePoint = getPortPosition(node, port);
2907
3249
  this.interaction = {
2908
3250
  kind: "connect",
@@ -2931,7 +3273,7 @@ var VdFlowchart = class {
2931
3273
  const nodeId = resizeTarget.getAttribute("data-node-id");
2932
3274
  const handle = resizeTarget.getAttribute("data-resize-handle");
2933
3275
  const node = this.findNode(nodeId);
2934
- if (!node || !RESIZE_HANDLES.includes(handle)) return;
3276
+ if (!node || !isNodeResizable(node) || !RESIZE_HANDLES.includes(handle)) return;
2935
3277
  this.select({ kind: "node", id: nodeId });
2936
3278
  this.interaction = {
2937
3279
  kind: "resize-node",
@@ -2964,8 +3306,11 @@ var VdFlowchart = class {
2964
3306
  if (groupIds.length > 1) this.selectNodes(groupIds, { primary: nodeId });
2965
3307
  else this.select({ kind: "node", id: nodeId });
2966
3308
  if (!this.readonly) {
2967
- this.interaction = this.createDragInteraction(event, nodeId, groupIds);
2968
- this.capturePointer(event.pointerId);
3309
+ const drag = this.createDragInteraction(event, nodeId, groupIds);
3310
+ if (drag) {
3311
+ this.interaction = drag;
3312
+ this.capturePointer(event.pointerId);
3313
+ }
2969
3314
  }
2970
3315
  return;
2971
3316
  }
@@ -2996,12 +3341,13 @@ var VdFlowchart = class {
2996
3341
  event.preventDefault();
2997
3342
  }
2998
3343
  createDragInteraction(event, nodeId, nodeIds) {
2999
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
3344
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
3345
+ if (!nodes.length) return null;
3000
3346
  const moving = new Set(nodes.map((node) => node.id));
3001
3347
  return {
3002
3348
  kind: "drag-node",
3003
3349
  pointerId: event.pointerId,
3004
- nodeId,
3350
+ nodeId: moving.has(nodeId) ? nodeId : nodes[0].id,
3005
3351
  nodeIds: nodes.map((node) => node.id),
3006
3352
  startWorld: this.clientToWorld(event.clientX, event.clientY),
3007
3353
  origins: new Map(nodes.map((node) => [node.id, { x: node.x, y: node.y }])),
@@ -3353,15 +3699,16 @@ var VdFlowchart = class {
3353
3699
  if (this.activeTool === "arrow") return true;
3354
3700
  return this.selection?.kind === "node" && this.selection.id === node.id && !this.hasMultiSelection();
3355
3701
  }
3356
- getMarkerId(markerType, position, strokeWidth, edgeScale = 1) {
3702
+ getMarkerId(markerType, position, strokeWidth, edgeScale = 1, color = "") {
3357
3703
  const width = normalizeEdgeStrokeWidth(strokeWidth);
3358
3704
  const scale = clamp(formatNumber(Math.max(edgeScale, 0.01)), 0.01, 1);
3359
- const key = `${markerType}:${position}:${width}:${scale}`;
3705
+ const fill = resolveEdgeColorValue(color);
3706
+ const key = `${markerType}:${position}:${width}:${scale}:${fill}`;
3360
3707
  if (this.markerIds.has(key)) {
3361
3708
  return this.markerIds.get(key);
3362
3709
  }
3363
3710
  const markerId = nextId(`flowchart-${markerType}-${position}`);
3364
- const marker = markerType === "dot" ? createDotMarker(markerId, width, scale) : createArrowMarker(markerId, width, position === "start", scale);
3711
+ const marker = markerType === "dot" ? createDotMarker(markerId, width, scale, fill) : createArrowMarker(markerId, width, position === "start", scale, fill);
3365
3712
  this.markerDefs.appendChild(marker);
3366
3713
  this.markerIds.set(key, markerId);
3367
3714
  return markerId;
@@ -3383,7 +3730,7 @@ var VdFlowchart = class {
3383
3730
  const snapPadding = CONNECTION_SNAP_PADDING / this.documentData.viewport.scale;
3384
3731
  const hysteresisMargin = CONNECTION_HYSTERESIS / this.documentData.viewport.scale;
3385
3732
  const best = this.getVisibleNodes().reduce((candidate, node) => {
3386
- if (node.id === excludeNodeId) return candidate;
3733
+ if (node.id === excludeNodeId || node.locked) return candidate;
3387
3734
  const distanceToBounds2 = getDistanceToNodeBounds(node, worldPoint);
3388
3735
  if (distanceToBounds2 > snapPadding) return candidate;
3389
3736
  const nearest = pickPortForNode(node, worldPoint, referencePoint);
@@ -3401,7 +3748,7 @@ var VdFlowchart = class {
3401
3748
  }, null);
3402
3749
  if (!previousSnap || !best) return best;
3403
3750
  const previousNode = this.findNode(previousSnap.nodeId);
3404
- if (!previousNode || previousNode.id === excludeNodeId) return best;
3751
+ if (!previousNode || previousNode.id === excludeNodeId || previousNode.locked) return best;
3405
3752
  const distanceToBounds = getDistanceToNodeBounds(previousNode, worldPoint);
3406
3753
  if (distanceToBounds > snapPadding) return best;
3407
3754
  if (best.node.id === previousSnap.nodeId && best.port === previousSnap.port) {
@@ -3816,16 +4163,17 @@ var VdFlowchart = class {
3816
4163
  }
3817
4164
  applyEdgeMarkers(pathElement, edge, edgeScale = 1) {
3818
4165
  const width = this.getEdgeStrokeWidth(edge);
4166
+ const color = edge.color || "";
3819
4167
  if (edge.startMarker && edge.startMarker !== "none") {
3820
4168
  pathElement.setAttribute(
3821
4169
  "marker-start",
3822
- `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale)})`
4170
+ `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale, color)})`
3823
4171
  );
3824
4172
  }
3825
4173
  if (edge.endMarker && edge.endMarker !== "none") {
3826
4174
  pathElement.setAttribute(
3827
4175
  "marker-end",
3828
- `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale)})`
4176
+ `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale, color)})`
3829
4177
  );
3830
4178
  }
3831
4179
  }
@@ -3837,10 +4185,19 @@ var VdFlowchart = class {
3837
4185
  const edgePath = buildEdgePath(edge, fromNode, toNode);
3838
4186
  const selected = this.selection?.kind === "edge" && this.selection.id === edge.id;
3839
4187
  const inReconnectMode = this.reconnectEdgeId === edge.id;
4188
+ const strokeStyle = normalizeEdgeStrokeStyle(edge.strokeStyle);
4189
+ const strokeClass = strokeStyle !== "solid" ? ` is-stroke-${strokeStyle}` : "";
3840
4190
  const group = svgEl("g", {
3841
- class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}`,
4191
+ class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}${strokeClass}`,
3842
4192
  "data-edge-id": edge.id
3843
4193
  });
4194
+ if (edge.color) {
4195
+ if (FLOWCHART_COLOR_PRESETS.includes(edge.color) && edge.color !== "default") {
4196
+ group.setAttribute("data-color", edge.color);
4197
+ } else {
4198
+ group.setAttribute("data-color", "custom");
4199
+ }
4200
+ }
3844
4201
  const baseStroke = this.getEdgeStrokeWidth(edge);
3845
4202
  const strokeWidth = visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke;
3846
4203
  if (selected) {
@@ -3858,6 +4215,20 @@ var VdFlowchart = class {
3858
4215
  "stroke-width": strokeWidth,
3859
4216
  "data-edge-id": edge.id
3860
4217
  });
4218
+ if (edge.color && !FLOWCHART_COLOR_PRESETS.includes(edge.color)) {
4219
+ visiblePath.style.stroke = edge.color;
4220
+ }
4221
+ if (strokeStyle === "dashed" || strokeStyle === "animated") {
4222
+ visiblePath.setAttribute(
4223
+ "stroke-dasharray",
4224
+ visual < 0.999 ? `${formatNumber(8 * visual)} ${formatNumber(5 * visual)}` : "8 5"
4225
+ );
4226
+ } else if (strokeStyle === "dotted") {
4227
+ visiblePath.setAttribute(
4228
+ "stroke-dasharray",
4229
+ visual < 0.999 ? `${formatNumber(2 * visual)} ${formatNumber(5 * visual)}` : "2 5"
4230
+ );
4231
+ }
3861
4232
  this.applyEdgeMarkers(visiblePath, edge, visual);
3862
4233
  const hitPath = svgEl("path", {
3863
4234
  class: "vd-flowchart-edge-hit",
@@ -3940,6 +4311,36 @@ var VdFlowchart = class {
3940
4311
  "stroke-width": visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke
3941
4312
  });
3942
4313
  }
4314
+ renderLockBadge(node) {
4315
+ const scale = this.documentData.viewport.scale || 1;
4316
+ const badgeSize = 16 / scale;
4317
+ const offsetX = node.width - badgeSize / 2 - 4 / scale;
4318
+ const offsetY = badgeSize / 2 + 4 / scale;
4319
+ const badge = svgEl("g", {
4320
+ class: "vd-flowchart-node-lock",
4321
+ transform: `translate(${formatNumber(offsetX)} ${formatNumber(offsetY)})`,
4322
+ "data-node-id": node.id
4323
+ });
4324
+ const title = svgEl("title");
4325
+ title.textContent = "Locked node";
4326
+ badge.appendChild(title);
4327
+ badge.appendChild(
4328
+ svgEl("circle", {
4329
+ cx: 0,
4330
+ cy: 0,
4331
+ r: formatNumber(badgeSize / 2)
4332
+ })
4333
+ );
4334
+ const iconScale = badgeSize * 0.62 / 256;
4335
+ const iconOffset = -128 * iconScale;
4336
+ badge.appendChild(
4337
+ svgEl("path", {
4338
+ d: TOOLBAR_ICON_PATHS.lock,
4339
+ transform: `translate(${formatNumber(iconOffset)} ${formatNumber(iconOffset)}) scale(${formatScale(iconScale)})`
4340
+ })
4341
+ );
4342
+ return badge;
4343
+ }
3943
4344
  renderNode(node) {
3944
4345
  const selected = this.isNodeSelected(node.id);
3945
4346
  const soloSelected = selected && !this.hasMultiSelection();
@@ -3947,10 +4348,13 @@ var VdFlowchart = class {
3947
4348
  const resizing = this.interaction?.kind === "resize-node" && this.interaction.nodeId === node.id;
3948
4349
  const editing = this.textEditor?.nodeId === node.id;
3949
4350
  const group = svgEl("g", {
3950
- class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}`,
4351
+ class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}${node.locked ? " is-locked" : ""}`,
3951
4352
  transform: `translate(${formatNumber(node.x)} ${formatNumber(node.y)})`,
3952
4353
  "data-node-id": node.id
3953
4354
  });
4355
+ if (node.color) {
4356
+ group.setAttribute("data-color", node.color);
4357
+ }
3954
4358
  const portsVisible = this.shouldShowNodePorts(node);
3955
4359
  const visual = nodeVisualScale(node);
3956
4360
  const corner = node.type === "rounded-rect" || node.type === "textbox" ? 16 : node.type === "junction" ? node.width / 2 : 6;
@@ -3966,8 +4370,15 @@ var VdFlowchart = class {
3966
4370
  group.appendChild(hitbox);
3967
4371
  const shape = this.renderNodeShape(node);
3968
4372
  this.applyScaledNodeShape(node, shape);
4373
+ if (node.fill) shape.style.fill = node.fill;
4374
+ if (node.stroke) shape.style.stroke = node.stroke;
3969
4375
  group.appendChild(shape);
3970
- group.appendChild(this.renderNodeText(node));
4376
+ const textEl = this.renderNodeText(node);
4377
+ if (node.textColor) textEl.style.fill = node.textColor;
4378
+ group.appendChild(textEl);
4379
+ if (node.locked) {
4380
+ group.appendChild(this.renderLockBadge(node));
4381
+ }
3971
4382
  const scale = this.documentData.viewport.scale || 1;
3972
4383
  if (soloSelected && !this.readonly && SELECTION_BOX_TYPES.has(node.type)) {
3973
4384
  const outset = SELECTION_OUTSET / scale;
@@ -4287,6 +4698,127 @@ var VdFlowchart = class {
4287
4698
  });
4288
4699
  return textElement;
4289
4700
  }
4701
+ buildInspectorColorSwatches(activePreset = "default", disabled = this.readonly) {
4702
+ const normalizedActive = activePreset || "default";
4703
+ const grid = createElement("div", { className: "vd-flowchart-swatch-grid" });
4704
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
4705
+ const active = preset === normalizedActive;
4706
+ const button = createElement("button", {
4707
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}${active ? " is-active" : ""}`,
4708
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset,
4709
+ disabled
4710
+ });
4711
+ button.setAttribute("type", "button");
4712
+ button.setAttribute("data-color-preset", preset);
4713
+ button.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
4714
+ button.setAttribute("aria-pressed", active ? "true" : "false");
4715
+ grid.appendChild(button);
4716
+ });
4717
+ return grid;
4718
+ }
4719
+ buildInspectorArrangeRow(disabled = this.readonly) {
4720
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4721
+ const actions = [
4722
+ {
4723
+ action: "bring-to-front",
4724
+ label: "Front",
4725
+ title: "Bring to front (Cmd/Ctrl+Shift+])"
4726
+ },
4727
+ {
4728
+ action: "bring-forward",
4729
+ label: "Forward",
4730
+ title: "Bring forward (Cmd/Ctrl+])"
4731
+ },
4732
+ {
4733
+ action: "send-backward",
4734
+ label: "Backward",
4735
+ title: "Send backward (Cmd/Ctrl+[)"
4736
+ },
4737
+ {
4738
+ action: "send-to-back",
4739
+ label: "Back",
4740
+ title: "Send to back (Cmd/Ctrl+Shift+[)"
4741
+ }
4742
+ ];
4743
+ actions.forEach((item) => {
4744
+ const btn = createElement("button", {
4745
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4746
+ text: item.label,
4747
+ title: item.title,
4748
+ disabled
4749
+ });
4750
+ btn.setAttribute("type", "button");
4751
+ btn.setAttribute("data-arrange-action", item.action);
4752
+ grid.appendChild(btn);
4753
+ });
4754
+ return grid;
4755
+ }
4756
+ buildInspectorAlignRow(nodeCount, disabled = this.readonly) {
4757
+ const wrap = createElement("div", { className: "vd-flowchart-inspector-stack" });
4758
+ const alignGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4759
+ const alignments = [
4760
+ { action: "left", label: "Left", title: "Align left edges" },
4761
+ { action: "center", label: "Center", title: "Align horizontal centers" },
4762
+ { action: "right", label: "Right", title: "Align right edges" },
4763
+ { action: "top", label: "Top", title: "Align top edges" },
4764
+ { action: "middle", label: "Middle", title: "Align vertical centers" },
4765
+ { action: "bottom", label: "Bottom", title: "Align bottom edges" }
4766
+ ];
4767
+ alignments.forEach((item) => {
4768
+ const btn = createElement("button", {
4769
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4770
+ text: item.label,
4771
+ title: item.title,
4772
+ disabled: disabled || nodeCount < 2
4773
+ });
4774
+ btn.setAttribute("type", "button");
4775
+ btn.setAttribute("data-align-action", item.action);
4776
+ alignGrid.appendChild(btn);
4777
+ });
4778
+ wrap.appendChild(createField("Align", alignGrid));
4779
+ const distributeGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4780
+ [
4781
+ { action: "horizontal", label: "Distribute H", title: "Distribute horizontally" },
4782
+ { action: "vertical", label: "Distribute V", title: "Distribute vertically" }
4783
+ ].forEach((item) => {
4784
+ const btn = createElement("button", {
4785
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4786
+ text: item.label,
4787
+ title: item.title,
4788
+ disabled: disabled || nodeCount < 3
4789
+ });
4790
+ btn.setAttribute("type", "button");
4791
+ btn.setAttribute("data-distribute-action", item.action);
4792
+ distributeGrid.appendChild(btn);
4793
+ });
4794
+ wrap.appendChild(createField("Distribute", distributeGrid));
4795
+ return wrap;
4796
+ }
4797
+ buildInspectorUtilityRow({ showLock = true, locked = false, disabled = this.readonly } = {}) {
4798
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4799
+ if (showLock) {
4800
+ const lockBtn = createElement("button", {
4801
+ className: `vd-flowchart-btn vd-flowchart-action-btn${locked ? " is-active" : ""}`,
4802
+ text: locked ? "Unlock" : "Lock",
4803
+ title: "Toggle node lock (Cmd/Ctrl+L)",
4804
+ disabled
4805
+ });
4806
+ lockBtn.setAttribute("type", "button");
4807
+ lockBtn.setAttribute("data-lock-toggle", "");
4808
+ lockBtn.setAttribute("aria-pressed", locked ? "true" : "false");
4809
+ grid.appendChild(lockBtn);
4810
+ }
4811
+ const resetBtn = createElement("button", {
4812
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4813
+ text: "Reset color",
4814
+ title: "Reset to theme default color",
4815
+ disabled
4816
+ });
4817
+ resetBtn.setAttribute("type", "button");
4818
+ resetBtn.setAttribute("data-color-reset", "");
4819
+ grid.appendChild(resetBtn);
4820
+ return grid;
4821
+ }
4290
4822
  renderSelectionPanel() {
4291
4823
  clearChildren(this.selectionFields);
4292
4824
  this.deleteButton.disabled = this.readonly || !this.selection;
@@ -4301,6 +4833,11 @@ var VdFlowchart = class {
4301
4833
  return;
4302
4834
  }
4303
4835
  if (this.hasMultiSelection()) {
4836
+ const selectedIds = this.getSelectedNodeIds();
4837
+ const selectedNodes = selectedIds.map((id) => this.findNode(id)).filter(Boolean);
4838
+ const allLocked = selectedNodes.length > 0 && selectedNodes.every((n) => n.locked);
4839
+ this.deleteButton.disabled = this.readonly || allLocked;
4840
+ const sharedColor = selectedNodes.length > 0 && selectedNodes.every((n) => (n.color || "default") === (selectedNodes[0].color || "default")) ? selectedNodes[0].color || "default" : "";
4304
4841
  this.selectionMeta.textContent = `${this.selectedNodeIds.size} nodes selected`;
4305
4842
  this.selectionFields.appendChild(
4306
4843
  createElement("p", {
@@ -4308,6 +4845,22 @@ var VdFlowchart = class {
4308
4845
  text: "Drag, nudge with Alt+Arrow, copy, duplicate, or delete them together."
4309
4846
  })
4310
4847
  );
4848
+ this.selectionFields.appendChild(
4849
+ createField("Color preset", this.buildInspectorColorSwatches(sharedColor, this.readonly))
4850
+ );
4851
+ this.selectionFields.appendChild(
4852
+ this.buildInspectorAlignRow(selectedNodes.length, this.readonly)
4853
+ );
4854
+ this.selectionFields.appendChild(
4855
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
4856
+ );
4857
+ this.selectionFields.appendChild(
4858
+ this.buildInspectorUtilityRow({
4859
+ showLock: true,
4860
+ locked: allLocked,
4861
+ disabled: this.readonly
4862
+ })
4863
+ );
4311
4864
  return;
4312
4865
  }
4313
4866
  if (this.selection.kind === "node") {
@@ -4317,8 +4870,10 @@ var VdFlowchart = class {
4317
4870
  this.renderSelectionPanel();
4318
4871
  return;
4319
4872
  }
4320
- this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}`;
4321
- const typeSelect = createElement("select");
4873
+ const isLocked = Boolean(node.locked);
4874
+ this.deleteButton.disabled = this.readonly || isLocked;
4875
+ this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}${isLocked ? " \xB7 locked" : ""}`;
4876
+ const typeSelect = createElement("select", { disabled: this.readonly || isLocked });
4322
4877
  typeSelect.setAttribute("data-field", "node-type");
4323
4878
  FLOWCHART_NODE_TYPES.forEach((type) => {
4324
4879
  const option = createElement("option", { value: type, text: type.replace("-", " ") });
@@ -4326,13 +4881,25 @@ var VdFlowchart = class {
4326
4881
  option.selected = type === node.type;
4327
4882
  typeSelect.appendChild(option);
4328
4883
  });
4329
- const textArea = createElement("textarea", { value: node.text, rows: 5 });
4884
+ const textArea = createElement("textarea", {
4885
+ value: node.text,
4886
+ rows: 5,
4887
+ disabled: this.readonly || isLocked
4888
+ });
4330
4889
  textArea.setAttribute("data-field", "node-text");
4331
- const widthInput = createElement("input", { value: node.width, type: "number" });
4890
+ const widthInput = createElement("input", {
4891
+ value: node.width,
4892
+ type: "number",
4893
+ disabled: this.readonly || isLocked
4894
+ });
4332
4895
  widthInput.setAttribute("data-field", "node-width");
4333
4896
  widthInput.setAttribute("min", String(this.minNodeSize));
4334
4897
  widthInput.setAttribute("max", String(this.maxNodeSize));
4335
- const heightInput = createElement("input", { value: node.height, type: "number" });
4898
+ const heightInput = createElement("input", {
4899
+ value: node.height,
4900
+ type: "number",
4901
+ disabled: this.readonly || isLocked
4902
+ });
4336
4903
  heightInput.setAttribute("data-field", "node-height");
4337
4904
  heightInput.setAttribute("min", String(this.minNodeSize));
4338
4905
  heightInput.setAttribute("max", String(this.maxNodeSize));
@@ -4353,6 +4920,48 @@ var VdFlowchart = class {
4353
4920
  })
4354
4921
  );
4355
4922
  }
4923
+ this.selectionFields.appendChild(
4924
+ createField(
4925
+ "Color preset",
4926
+ this.buildInspectorColorSwatches(node.color || "default", this.readonly || isLocked)
4927
+ )
4928
+ );
4929
+ const customColorsGrid = createElement("div", { className: "vd-flowchart-field-grid" });
4930
+ const fillInput = createElement("input", {
4931
+ value: node.fill || "",
4932
+ type: "text",
4933
+ disabled: this.readonly || isLocked
4934
+ });
4935
+ fillInput.setAttribute("data-field", "node-fill");
4936
+ fillInput.setAttribute("placeholder", "Fill (e.g. #dbeafe)");
4937
+ const strokeInput = createElement("input", {
4938
+ value: node.stroke || "",
4939
+ type: "text",
4940
+ disabled: this.readonly || isLocked
4941
+ });
4942
+ strokeInput.setAttribute("data-field", "node-stroke");
4943
+ strokeInput.setAttribute("placeholder", "Stroke (e.g. #2563eb)");
4944
+ const textColorInput = createElement("input", {
4945
+ value: node.textColor || "",
4946
+ type: "text",
4947
+ disabled: this.readonly || isLocked
4948
+ });
4949
+ textColorInput.setAttribute("data-field", "node-text-color");
4950
+ textColorInput.setAttribute("placeholder", "Text (e.g. #1e3a8a)");
4951
+ customColorsGrid.appendChild(createField("Fill", fillInput));
4952
+ customColorsGrid.appendChild(createField("Border", strokeInput));
4953
+ this.selectionFields.appendChild(customColorsGrid);
4954
+ this.selectionFields.appendChild(createField("Text color", textColorInput));
4955
+ this.selectionFields.appendChild(
4956
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
4957
+ );
4958
+ this.selectionFields.appendChild(
4959
+ this.buildInspectorUtilityRow({
4960
+ showLock: true,
4961
+ locked: isLocked,
4962
+ disabled: this.readonly
4963
+ })
4964
+ );
4356
4965
  return;
4357
4966
  }
4358
4967
  const edge = this.findEdge(this.selection.id);
@@ -4361,8 +4970,9 @@ var VdFlowchart = class {
4361
4970
  this.renderSelectionPanel();
4362
4971
  return;
4363
4972
  }
4973
+ const edgeStyleName = normalizeEdgeStrokeStyle(edge.strokeStyle);
4364
4974
  this.selectionMeta.textContent = `Edge ${edge.id} \xB7 ${edge.route} \xB7 ${formatNumber(edge.strokeWidth)}px \xB7 ${edge.startMarker} \u2192 ${edge.endMarker}`;
4365
- const routeSelect = createElement("select");
4975
+ const routeSelect = createElement("select", { disabled: this.readonly });
4366
4976
  routeSelect.setAttribute("data-field", "edge-route");
4367
4977
  FLOWCHART_EDGE_ROUTES.forEach((route) => {
4368
4978
  const option = createElement("option", {
@@ -4373,7 +4983,7 @@ var VdFlowchart = class {
4373
4983
  option.selected = route === edge.route;
4374
4984
  routeSelect.appendChild(option);
4375
4985
  });
4376
- const startSelect = createElement("select");
4986
+ const startSelect = createElement("select", { disabled: this.readonly });
4377
4987
  startSelect.setAttribute("data-field", "edge-start-marker");
4378
4988
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4379
4989
  const option = createElement("option", { value: marker, text: marker });
@@ -4381,7 +4991,7 @@ var VdFlowchart = class {
4381
4991
  option.selected = marker === edge.startMarker;
4382
4992
  startSelect.appendChild(option);
4383
4993
  });
4384
- const endSelect = createElement("select");
4994
+ const endSelect = createElement("select", { disabled: this.readonly });
4385
4995
  endSelect.setAttribute("data-field", "edge-end-marker");
4386
4996
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4387
4997
  const option = createElement("option", { value: marker, text: marker });
@@ -4389,7 +4999,7 @@ var VdFlowchart = class {
4389
4999
  option.selected = marker === edge.endMarker;
4390
5000
  endSelect.appendChild(option);
4391
5001
  });
4392
- const widthSelect = createElement("select");
5002
+ const widthSelect = createElement("select", { disabled: this.readonly });
4393
5003
  widthSelect.setAttribute("data-field", "edge-stroke-preset");
4394
5004
  EDGE_STROKE_PRESETS.forEach((preset) => {
4395
5005
  const option = createElement("option", { value: preset.id, text: preset.label });
@@ -4397,15 +5007,52 @@ var VdFlowchart = class {
4397
5007
  option.selected = preset.id === getStrokePresetId(edge.strokeWidth);
4398
5008
  widthSelect.appendChild(option);
4399
5009
  });
4400
- const labelInput = createElement("textarea", { value: edge.label, rows: 4 });
5010
+ const strokeStyleSelect = createElement("select", { disabled: this.readonly });
5011
+ strokeStyleSelect.setAttribute("data-field", "edge-stroke-style");
5012
+ FLOWCHART_EDGE_STROKE_STYLES.forEach((style) => {
5013
+ const option = createElement("option", {
5014
+ value: style,
5015
+ text: FLOWCHART_EDGE_STROKE_STYLE_LABELS[style] || style
5016
+ });
5017
+ option.value = style;
5018
+ option.selected = style === edgeStyleName;
5019
+ strokeStyleSelect.appendChild(option);
5020
+ });
5021
+ const labelInput = createElement("textarea", {
5022
+ value: edge.label,
5023
+ rows: 4,
5024
+ disabled: this.readonly
5025
+ });
4401
5026
  labelInput.setAttribute("data-field", "edge-label");
4402
5027
  const markerGrid = createElement("div", { className: "vd-flowchart-field-grid" });
4403
5028
  markerGrid.appendChild(createField("Route", routeSelect));
4404
5029
  markerGrid.appendChild(createField("Weight", widthSelect));
5030
+ markerGrid.appendChild(createField("Style", strokeStyleSelect));
4405
5031
  markerGrid.appendChild(createField("Start", startSelect));
4406
5032
  markerGrid.appendChild(createField("End", endSelect));
4407
5033
  this.selectionFields.appendChild(markerGrid);
4408
5034
  this.selectionFields.appendChild(createField("Label", labelInput));
5035
+ const activeEdgePreset = edge.color && FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "default";
5036
+ this.selectionFields.appendChild(
5037
+ createField(
5038
+ "Color preset",
5039
+ this.buildInspectorColorSwatches(activeEdgePreset, this.readonly)
5040
+ )
5041
+ );
5042
+ const edgeColorInput = createElement("input", {
5043
+ value: edge.color && !FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "",
5044
+ type: "text",
5045
+ disabled: this.readonly
5046
+ });
5047
+ edgeColorInput.setAttribute("data-field", "edge-color");
5048
+ edgeColorInput.setAttribute("placeholder", "Custom color (e.g. #2563eb)");
5049
+ this.selectionFields.appendChild(createField("Custom color", edgeColorInput));
5050
+ this.selectionFields.appendChild(
5051
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
5052
+ );
5053
+ this.selectionFields.appendChild(
5054
+ this.buildInspectorUtilityRow({ showLock: false, disabled: this.readonly })
5055
+ );
4409
5056
  }
4410
5057
  syncJsonTextarea(force = false) {
4411
5058
  if (!force && document.activeElement === this.jsonTextarea) {
@@ -4811,7 +5458,14 @@ var VdFlowchart = class {
4811
5458
  // the parent's box shape, falling back to a rounded step.
4812
5459
  getBranchTemplate(parent, sibling) {
4813
5460
  const source = sibling || (["rounded-rect", "rect", "textbox"].includes(parent.type) ? parent : null) || null;
4814
- if (source) return { type: source.type, width: source.width, height: source.height };
5461
+ if (source) {
5462
+ const template = { type: source.type, width: source.width, height: source.height };
5463
+ if (source.color) template.color = source.color;
5464
+ if (source.fill) template.fill = source.fill;
5465
+ if (source.stroke) template.stroke = source.stroke;
5466
+ if (source.textColor) template.textColor = source.textColor;
5467
+ return template;
5468
+ }
4815
5469
  const spec = DEFAULT_NODE_SPECS["rounded-rect"];
4816
5470
  return { type: "rounded-rect", width: spec.width, height: spec.height };
4817
5471
  }
@@ -4847,7 +5501,9 @@ var VdFlowchart = class {
4847
5501
  route: styleSource.route,
4848
5502
  strokeWidth: styleSource.strokeWidth,
4849
5503
  startMarker: styleSource.startMarker,
4850
- endMarker: styleSource.endMarker
5504
+ endMarker: styleSource.endMarker,
5505
+ ...styleSource.color ? { color: styleSource.color } : {},
5506
+ ...styleSource.strokeStyle ? { strokeStyle: styleSource.strokeStyle } : {}
4851
5507
  } : { endMarker: "arrow" };
4852
5508
  const result = this.batchHistory("node:insert", () => {
4853
5509
  if (parent.collapsed) delete parent.collapsed;
@@ -5065,6 +5721,30 @@ var VdFlowchart = class {
5065
5721
  node.text = isNodeTextEditable(nextType) ? patch.text == null ? node.text : String(patch.text) : getNodeSpec(nextType).text;
5066
5722
  node.width = clampNodeWidth(nextType, patch.width, node.width, this.nodeSizeBounds());
5067
5723
  node.height = clampNodeHeight(nextType, patch.height, node.height, this.nodeSizeBounds());
5724
+ if ("color" in patch) {
5725
+ const nextColor = normalizeColorPreset(patch.color);
5726
+ if (nextColor) node.color = nextColor;
5727
+ else delete node.color;
5728
+ }
5729
+ if ("fill" in patch) {
5730
+ const nextFill = sanitizeCssColor(patch.fill);
5731
+ if (nextFill) node.fill = nextFill;
5732
+ else delete node.fill;
5733
+ }
5734
+ if ("stroke" in patch) {
5735
+ const nextStroke = sanitizeCssColor(patch.stroke);
5736
+ if (nextStroke) node.stroke = nextStroke;
5737
+ else delete node.stroke;
5738
+ }
5739
+ if ("textColor" in patch) {
5740
+ const nextTextColor = sanitizeCssColor(patch.textColor);
5741
+ if (nextTextColor) node.textColor = nextTextColor;
5742
+ else delete node.textColor;
5743
+ }
5744
+ if ("locked" in patch) {
5745
+ if (patch.locked) node.locked = true;
5746
+ else delete node.locked;
5747
+ }
5068
5748
  if (isPlainObject(patch.data)) {
5069
5749
  node.data = deepClone(patch.data);
5070
5750
  }
@@ -5072,6 +5752,11 @@ var VdFlowchart = class {
5072
5752
  updateNode(nodeId, patch = {}, options = {}) {
5073
5753
  const node = this.findNode(nodeId);
5074
5754
  if (!node) return null;
5755
+ if (node.locked) {
5756
+ const keys = Object.keys(patch);
5757
+ const unlocking = keys.length > 0 && keys.every((key) => key === "locked") && !patch.locked;
5758
+ if (!unlocking) return null;
5759
+ }
5075
5760
  const previousType = node.type;
5076
5761
  const previousSpec = DEFAULT_NODE_SPECS[previousType];
5077
5762
  this.applyNodePatch(node, patch);
@@ -5176,6 +5861,16 @@ var VdFlowchart = class {
5176
5861
  if (patch.label != null) {
5177
5862
  edge.label = String(patch.label);
5178
5863
  }
5864
+ if ("color" in patch) {
5865
+ const nextColor = normalizeEdgeColor(patch.color);
5866
+ if (nextColor) edge.color = nextColor;
5867
+ else delete edge.color;
5868
+ }
5869
+ if ("strokeStyle" in patch) {
5870
+ const nextStrokeStyle = normalizeEdgeStrokeStyle(patch.strokeStyle);
5871
+ if (nextStrokeStyle && nextStrokeStyle !== "solid") edge.strokeStyle = nextStrokeStyle;
5872
+ else delete edge.strokeStyle;
5873
+ }
5179
5874
  if (isPlainObject(patch.data)) {
5180
5875
  edge.data = deepClone(patch.data);
5181
5876
  }
@@ -5248,11 +5943,405 @@ var VdFlowchart = class {
5248
5943
  deleteSelection() {
5249
5944
  if (!this.selection || this.readonly) return false;
5250
5945
  if (this.hasMultiSelection()) {
5251
- return this.removeNodeIds(new Set(this.getSelectedNodeIds()), "node:remove");
5946
+ const unlockedIds = this.getSelectedNodeIds().filter((id) => !this.findNode(id)?.locked);
5947
+ if (!unlockedIds.length) return false;
5948
+ return this.removeNodeIds(new Set(unlockedIds), "node:remove");
5949
+ }
5950
+ if (this.selection.kind === "node") {
5951
+ const node = this.findNode(this.selection.id);
5952
+ if (node?.locked) return false;
5953
+ return this.removeNode(this.selection.id);
5252
5954
  }
5253
- if (this.selection.kind === "node") return this.removeNode(this.selection.id);
5254
5955
  return this.removeEdge(this.selection.id);
5255
5956
  }
5957
+ // --- Coloring, Layer Order, Align/Distribute, Locking, SVG Export ---------
5958
+ setNodeColor(nodeId, colorOrPatch) {
5959
+ if (this.readonly) return null;
5960
+ const id = sanitizeId(nodeId);
5961
+ if (!this.findNode(id)) return null;
5962
+ let patch;
5963
+ if (isPlainObject(colorOrPatch)) {
5964
+ patch = {};
5965
+ if ("color" in colorOrPatch) patch.color = colorOrPatch.color;
5966
+ if ("fill" in colorOrPatch) patch.fill = colorOrPatch.fill;
5967
+ if ("stroke" in colorOrPatch) patch.stroke = colorOrPatch.stroke;
5968
+ if ("textColor" in colorOrPatch) patch.textColor = colorOrPatch.textColor;
5969
+ } else if (colorOrPatch == null || colorOrPatch === "" || colorOrPatch === "default") {
5970
+ patch = { color: null, fill: null, stroke: null, textColor: null };
5971
+ } else {
5972
+ const token = String(colorOrPatch).trim();
5973
+ if (FLOWCHART_COLOR_PRESET_SET.has(token)) {
5974
+ patch = { color: token, fill: null, stroke: null, textColor: null };
5975
+ } else {
5976
+ const css = sanitizeCssColor(token);
5977
+ if (!css) return null;
5978
+ patch = { fill: css };
5979
+ }
5980
+ }
5981
+ return this.updateNode(id, patch, { reason: "node:color" });
5982
+ }
5983
+ setEdgeColor(edgeId, color) {
5984
+ if (this.readonly) return null;
5985
+ const id = sanitizeId(edgeId);
5986
+ if (!this.findEdge(id)) return null;
5987
+ const nextColor = color == null || color === "" || color === "default" ? null : isPlainObject(color) ? normalizeEdgeColor(color.color ?? color.stroke) : normalizeEdgeColor(color);
5988
+ return this.updateEdge(id, { color: nextColor }, { reason: "edge:color" });
5989
+ }
5990
+ setSelectionColor(colorOrPatch) {
5991
+ if (this.readonly || !this.selection) return this;
5992
+ if (this.selection.kind === "edge") {
5993
+ this.setEdgeColor(this.selection.id, colorOrPatch);
5994
+ return this;
5995
+ }
5996
+ const ids = this.getSelectedNodeIds();
5997
+ if (!ids.length) return this;
5998
+ this.batchHistory("node:color", () => {
5999
+ ids.forEach((id) => {
6000
+ this.setNodeColor(id, colorOrPatch);
6001
+ });
6002
+ });
6003
+ return this;
6004
+ }
6005
+ clearSelectionColor() {
6006
+ return this.setSelectionColor(null);
6007
+ }
6008
+ reorderArrayLayer(items, targetIds, direction) {
6009
+ const idSet = new Set(targetIds);
6010
+ if (!idSet.size || items.length < 2) return null;
6011
+ let next;
6012
+ if (direction === "front") {
6013
+ next = [
6014
+ ...items.filter((item) => !idSet.has(item.id)),
6015
+ ...items.filter((item) => idSet.has(item.id))
6016
+ ];
6017
+ } else if (direction === "back") {
6018
+ next = [
6019
+ ...items.filter((item) => idSet.has(item.id)),
6020
+ ...items.filter((item) => !idSet.has(item.id))
6021
+ ];
6022
+ } else if (direction === "forward") {
6023
+ next = [...items];
6024
+ for (let i = next.length - 2; i >= 0; i -= 1) {
6025
+ if (idSet.has(next[i].id) && !idSet.has(next[i + 1].id)) {
6026
+ const temp = next[i];
6027
+ next[i] = next[i + 1];
6028
+ next[i + 1] = temp;
6029
+ }
6030
+ }
6031
+ } else if (direction === "backward") {
6032
+ next = [...items];
6033
+ for (let i = 1; i < next.length; i += 1) {
6034
+ if (idSet.has(next[i].id) && !idSet.has(next[i - 1].id)) {
6035
+ const temp = next[i];
6036
+ next[i] = next[i - 1];
6037
+ next[i - 1] = temp;
6038
+ }
6039
+ }
6040
+ } else {
6041
+ return null;
6042
+ }
6043
+ const changed = next.some((item, index) => item.id !== items[index].id);
6044
+ return changed ? next : null;
6045
+ }
6046
+ reorderLayer(direction, targetId) {
6047
+ if (this.readonly) return this;
6048
+ let explicitIds = [];
6049
+ if (Array.isArray(targetId)) {
6050
+ explicitIds = targetId.map(sanitizeId).filter(Boolean);
6051
+ } else if (typeof targetId === "string" && targetId.trim()) {
6052
+ explicitIds = [sanitizeId(targetId)];
6053
+ }
6054
+ if (explicitIds.length) {
6055
+ const nodeIdSet = new Set(this.documentData.nodes.map((n) => n.id));
6056
+ const matchingNodes = explicitIds.filter((id) => nodeIdSet.has(id));
6057
+ if (matchingNodes.length) {
6058
+ const reordered2 = this.reorderArrayLayer(this.documentData.nodes, matchingNodes, direction);
6059
+ if (reordered2) {
6060
+ this.documentData.nodes = reordered2;
6061
+ this.render();
6062
+ this.emitChange("node:order", { direction, nodeIds: matchingNodes });
6063
+ }
6064
+ return this;
6065
+ }
6066
+ const edgeIdSet = new Set(this.documentData.edges.map((e) => e.id));
6067
+ const matchingEdges = explicitIds.filter((id) => edgeIdSet.has(id));
6068
+ if (matchingEdges.length) {
6069
+ const reordered2 = this.reorderArrayLayer(this.documentData.edges, matchingEdges, direction);
6070
+ if (reordered2) {
6071
+ this.documentData.edges = reordered2;
6072
+ this.render();
6073
+ this.emitChange("edge:order", { direction, edgeIds: matchingEdges });
6074
+ }
6075
+ }
6076
+ return this;
6077
+ }
6078
+ if (!this.selection) return this;
6079
+ if (this.selection.kind === "edge") {
6080
+ const reordered2 = this.reorderArrayLayer(
6081
+ this.documentData.edges,
6082
+ [this.selection.id],
6083
+ direction
6084
+ );
6085
+ if (reordered2) {
6086
+ this.documentData.edges = reordered2;
6087
+ this.render();
6088
+ this.emitChange("edge:order", { direction, edgeIds: [this.selection.id] });
6089
+ }
6090
+ return this;
6091
+ }
6092
+ const ids = this.getSelectedNodeIds();
6093
+ const reordered = this.reorderArrayLayer(this.documentData.nodes, ids, direction);
6094
+ if (reordered) {
6095
+ this.documentData.nodes = reordered;
6096
+ this.render();
6097
+ this.emitChange("node:order", { direction, nodeIds: ids });
6098
+ }
6099
+ return this;
6100
+ }
6101
+ bringToFront(targetId) {
6102
+ return this.reorderLayer("front", targetId);
6103
+ }
6104
+ bringForward(targetId) {
6105
+ return this.reorderLayer("forward", targetId);
6106
+ }
6107
+ sendBackward(targetId) {
6108
+ return this.reorderLayer("backward", targetId);
6109
+ }
6110
+ sendToBack(targetId) {
6111
+ return this.reorderLayer("back", targetId);
6112
+ }
6113
+ alignNodes(alignment = "left", nodeIds) {
6114
+ if (this.readonly || !FLOWCHART_NODE_ALIGNMENTS.includes(alignment)) return this;
6115
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6116
+ const hidden = this.getHiddenNodeIds();
6117
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6118
+ if (nodes.length < 2) return this;
6119
+ const bounds = getBounds(nodes);
6120
+ const centerX = (bounds.left + bounds.right) / 2;
6121
+ const centerY = (bounds.top + bounds.bottom) / 2;
6122
+ const movedIds = [];
6123
+ nodes.forEach((node) => {
6124
+ if (node.locked) return;
6125
+ let nextX = node.x;
6126
+ let nextY = node.y;
6127
+ if (alignment === "left") nextX = formatNumber(bounds.left);
6128
+ else if (alignment === "center") nextX = formatNumber(centerX - node.width / 2);
6129
+ else if (alignment === "right") nextX = formatNumber(bounds.right - node.width);
6130
+ else if (alignment === "top") nextY = formatNumber(bounds.top);
6131
+ else if (alignment === "middle") nextY = formatNumber(centerY - node.height / 2);
6132
+ else if (alignment === "bottom") nextY = formatNumber(bounds.bottom - node.height);
6133
+ if (nextX !== node.x || nextY !== node.y) {
6134
+ node.x = nextX;
6135
+ node.y = nextY;
6136
+ movedIds.push(node.id);
6137
+ }
6138
+ });
6139
+ if (movedIds.length) {
6140
+ this.render();
6141
+ this.emitChange("node:align", { alignment, nodeIds: movedIds });
6142
+ }
6143
+ return this;
6144
+ }
6145
+ distributeNodes(axis = "horizontal", nodeIds) {
6146
+ if (this.readonly || !FLOWCHART_DISTRIBUTE_AXES.includes(axis)) return this;
6147
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6148
+ const hidden = this.getHiddenNodeIds();
6149
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6150
+ if (nodes.length < 3) return this;
6151
+ const sorted = [...nodes].sort(
6152
+ (a, b) => axis === "horizontal" ? a.x + a.width / 2 - (b.x + b.width / 2) : a.y + a.height / 2 - (b.y + b.height / 2)
6153
+ );
6154
+ const first = sorted[0];
6155
+ const last = sorted[sorted.length - 1];
6156
+ const movedIds = [];
6157
+ if (axis === "horizontal") {
6158
+ const totalSpan = last.x + last.width - first.x;
6159
+ const totalSize = sorted.reduce((sum, node) => sum + node.width, 0);
6160
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6161
+ let cursor = first.x;
6162
+ sorted.forEach((node, index) => {
6163
+ if (index > 0 && index < sorted.length - 1 && !node.locked) {
6164
+ const nextX = formatNumber(cursor);
6165
+ if (nextX !== node.x) {
6166
+ node.x = nextX;
6167
+ movedIds.push(node.id);
6168
+ }
6169
+ }
6170
+ cursor += node.width + gap;
6171
+ });
6172
+ } else {
6173
+ const totalSpan = last.y + last.height - first.y;
6174
+ const totalSize = sorted.reduce((sum, node) => sum + node.height, 0);
6175
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6176
+ let cursor = first.y;
6177
+ sorted.forEach((node, index) => {
6178
+ if (index > 0 && index < sorted.length - 1 && !node.locked) {
6179
+ const nextY = formatNumber(cursor);
6180
+ if (nextY !== node.y) {
6181
+ node.y = nextY;
6182
+ movedIds.push(node.id);
6183
+ }
6184
+ }
6185
+ cursor += node.height + gap;
6186
+ });
6187
+ }
6188
+ if (movedIds.length) {
6189
+ this.render();
6190
+ this.emitChange("node:distribute", { axis, nodeIds: movedIds });
6191
+ }
6192
+ return this;
6193
+ }
6194
+ setNodeLocked(nodeId, locked = true) {
6195
+ if (this.readonly) return false;
6196
+ let targetIds;
6197
+ let nextLocked = Boolean(locked);
6198
+ if (typeof nodeId === "boolean") {
6199
+ nextLocked = nodeId;
6200
+ targetIds = this.getSelectedNodeIds();
6201
+ } else if (Array.isArray(nodeId)) {
6202
+ targetIds = nodeId.map(sanitizeId).filter(Boolean);
6203
+ } else if (nodeId == null) {
6204
+ targetIds = this.getSelectedNodeIds();
6205
+ } else {
6206
+ targetIds = [sanitizeId(nodeId)];
6207
+ }
6208
+ const changedNodes = [];
6209
+ targetIds.forEach((id) => {
6210
+ const node = this.findNode(id);
6211
+ if (!node || Boolean(node.locked) === nextLocked) return;
6212
+ if (nextLocked) node.locked = true;
6213
+ else delete node.locked;
6214
+ changedNodes.push(deepClone(node));
6215
+ });
6216
+ if (!changedNodes.length) return false;
6217
+ if (nextLocked && this.textEditor && targetIds.includes(this.textEditor.nodeId)) {
6218
+ this.stopTextEdit({ commit: true });
6219
+ }
6220
+ this.render();
6221
+ this.emitChange("node:lock", {
6222
+ node: changedNodes[0],
6223
+ nodes: changedNodes,
6224
+ locked: nextLocked
6225
+ });
6226
+ return true;
6227
+ }
6228
+ toggleNodeLocked(nodeId) {
6229
+ if (this.readonly) return false;
6230
+ if (nodeId != null && typeof nodeId !== "boolean" && !Array.isArray(nodeId)) {
6231
+ const node = this.findNode(sanitizeId(nodeId));
6232
+ return node ? this.setNodeLocked(node.id, !node.locked) : false;
6233
+ }
6234
+ const ids = Array.isArray(nodeId) ? nodeId.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6235
+ const nodes = ids.map((id) => this.findNode(id)).filter(Boolean);
6236
+ if (!nodes.length) return false;
6237
+ const shouldLock = nodes.some((node) => !node.locked);
6238
+ return this.setNodeLocked(ids, shouldLock);
6239
+ }
6240
+ exportSvg(options = {}) {
6241
+ const padding = Math.max(0, toFiniteNumber(options.padding, 32));
6242
+ const visibleNodes = this.getVisibleNodes();
6243
+ let viewX = 0;
6244
+ let viewY = 0;
6245
+ let viewWidth = 800;
6246
+ let viewHeight = 560;
6247
+ if (visibleNodes.length) {
6248
+ const bounds = getBounds(visibleNodes);
6249
+ viewX = formatNumber(bounds.left - padding);
6250
+ viewY = formatNumber(bounds.top - padding);
6251
+ viewWidth = formatNumber(Math.max(1, bounds.right - bounds.left + padding * 2));
6252
+ viewHeight = formatNumber(Math.max(1, bounds.bottom - bounds.top + padding * 2));
6253
+ }
6254
+ const exportRoot = svgEl("svg", {
6255
+ xmlns: SVG_NS,
6256
+ viewBox: `${viewX} ${viewY} ${viewWidth} ${viewHeight}`,
6257
+ width: viewWidth,
6258
+ height: viewHeight,
6259
+ class: "vd-flowchart-export"
6260
+ });
6261
+ const styleEl = svgEl("style");
6262
+ styleEl.textContent = [
6263
+ '.vd-flowchart-export { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }',
6264
+ ".vd-flowchart-node-shape { fill: #ffffff; stroke: #475569; stroke-width: 2px; }",
6265
+ ".vd-flowchart-node--textbox .vd-flowchart-node-shape { stroke-dasharray: 6 4; }",
6266
+ ".vd-flowchart-node--junction .vd-flowchart-node-shape { fill: #2563eb; stroke: #ffffff; }",
6267
+ ".vd-flowchart-node-text { fill: #0f172a; font-size: 14px; font-weight: 600; dominant-baseline: middle; text-anchor: middle; }",
6268
+ ".vd-flowchart-edge-path { fill: none; stroke: #475569; stroke-linecap: round; stroke-linejoin: round; }",
6269
+ ".vd-flowchart-edge-label { fill: #0f172a; font-size: 12px; font-weight: 600; paint-order: stroke; stroke: #ffffff; stroke-width: 5px; }"
6270
+ ].join("\n");
6271
+ exportRoot.appendChild(styleEl);
6272
+ if (this.markerDefs) {
6273
+ const defsClone = this.markerDefs.cloneNode(true);
6274
+ defsClone.querySelectorAll("path, circle").forEach((shape) => {
6275
+ const fill = shape.getAttribute("fill") || "";
6276
+ const preset = fill.match(/--vd-flowchart-palette-([a-z]+)-edge/);
6277
+ if (preset) {
6278
+ const fallback = FLOWCHART_COLOR_PRESET_FALLBACKS[preset[1]]?.edge;
6279
+ if (fallback) {
6280
+ shape.setAttribute("fill", fallback);
6281
+ return;
6282
+ }
6283
+ }
6284
+ if (fill.includes("var(")) shape.setAttribute("fill", "#475569");
6285
+ });
6286
+ exportRoot.appendChild(defsClone);
6287
+ }
6288
+ if (typeof options.background === "string" && options.background.trim() && options.background.trim() !== "transparent") {
6289
+ const bgColor = options.background.trim() === "theme" ? "#ffffff" : sanitizeCssColor(options.background.trim()) || "#ffffff";
6290
+ exportRoot.appendChild(
6291
+ svgEl("rect", {
6292
+ x: viewX,
6293
+ y: viewY,
6294
+ width: viewWidth,
6295
+ height: viewHeight,
6296
+ fill: bgColor
6297
+ })
6298
+ );
6299
+ }
6300
+ const sceneGroup = svgEl("g", { class: "vd-flowchart-export-scene" });
6301
+ const edgesClone = this.edgesLayer.cloneNode(true);
6302
+ edgesClone.querySelectorAll(".vd-flowchart-edge-hit, .vd-flowchart-edge-selection").forEach((el) => el.remove());
6303
+ edgesClone.querySelectorAll(".vd-flowchart-edge").forEach((edgeGroup) => {
6304
+ edgeGroup.classList.remove("is-selected", "is-reconnecting");
6305
+ const edgeId = edgeGroup.getAttribute("data-edge-id");
6306
+ const edge = this.findEdge(edgeId);
6307
+ const pathEl = edgeGroup.querySelector(".vd-flowchart-edge-path");
6308
+ if (edge && pathEl) {
6309
+ const stroke = edge.color ? FLOWCHART_COLOR_PRESET_FALLBACKS[edge.color]?.edge || edge.color : "#475569";
6310
+ pathEl.setAttribute("stroke", stroke);
6311
+ pathEl.style.stroke = stroke;
6312
+ }
6313
+ });
6314
+ const nodesClone = this.nodesLayer.cloneNode(true);
6315
+ nodesClone.querySelectorAll(
6316
+ ".vd-flowchart-ports, .vd-flowchart-resize-handles, .vd-flowchart-node-lock, .vd-flowchart-collapse-badge, .vd-flowchart-selection-box"
6317
+ ).forEach((el) => el.remove());
6318
+ nodesClone.querySelectorAll(".vd-flowchart-node").forEach((nodeGroup) => {
6319
+ nodeGroup.classList.remove("is-selected", "is-multi-selected", "is-dragging");
6320
+ const nodeId = nodeGroup.getAttribute("data-node-id");
6321
+ const node = this.findNode(nodeId);
6322
+ if (!node) return;
6323
+ const shapeEl = nodeGroup.querySelector(".vd-flowchart-node-shape");
6324
+ const labelEl = nodeGroup.querySelector(".vd-flowchart-node-text");
6325
+ const presetColors = node.color ? FLOWCHART_COLOR_PRESET_FALLBACKS[node.color] : null;
6326
+ if (shapeEl) {
6327
+ const fill = node.fill || presetColors?.fill || (node.type === "junction" ? "#2563eb" : "#ffffff");
6328
+ const stroke = node.stroke || presetColors?.stroke || (node.type === "junction" ? "#ffffff" : "#475569");
6329
+ shapeEl.setAttribute("fill", fill);
6330
+ shapeEl.setAttribute("stroke", stroke);
6331
+ shapeEl.style.fill = fill;
6332
+ shapeEl.style.stroke = stroke;
6333
+ }
6334
+ if (labelEl) {
6335
+ const textColor = node.textColor || presetColors?.text || "#0f172a";
6336
+ labelEl.setAttribute("fill", textColor);
6337
+ labelEl.style.fill = textColor;
6338
+ }
6339
+ });
6340
+ sceneGroup.appendChild(edgesClone);
6341
+ sceneGroup.appendChild(nodesClone);
6342
+ exportRoot.appendChild(sceneGroup);
6343
+ return exportRoot.outerHTML;
6344
+ }
5256
6345
  nodeSizeBounds() {
5257
6346
  return { min: this.minNodeSize, max: this.maxNodeSize };
5258
6347
  }
@@ -5398,8 +6487,12 @@ var VdFlowchart = class {
5398
6487
  this.reconnectEdgeId = null;
5399
6488
  }
5400
6489
  this.readonly = Boolean(options.readonly);
6490
+ if (this.readonly && this.colorPopoverOpen) {
6491
+ this.toggleColorPopover(false);
6492
+ }
5401
6493
  this.root.classList.toggle("vd-flowchart-readonly", this.readonly);
5402
6494
  this.arrangeSelect.disabled = this.readonly;
6495
+ if (this.colorButton) this.colorButton.disabled = this.readonly;
5403
6496
  this.clearButton.disabled = this.readonly;
5404
6497
  this.loadJsonButton.disabled = this.readonly;
5405
6498
  }
@@ -5622,16 +6715,38 @@ var VdFlowchart2 = defineComponent({
5622
6715
  canUndo: () => Boolean(instance?.canUndo()),
5623
6716
  canRedo: () => Boolean(instance?.canRedo()),
5624
6717
  layout: (mode, options) => instance?.layout(mode, options),
5625
- fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding)
6718
+ fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding),
6719
+ setNodeColor: (nodeId, colorOrPatch) => instance?.setNodeColor(nodeId, colorOrPatch) ?? null,
6720
+ setEdgeColor: (edgeId, color) => instance?.setEdgeColor(edgeId, color) ?? null,
6721
+ setSelectionColor: (colorOrPatch) => instance?.setSelectionColor(colorOrPatch),
6722
+ clearSelectionColor: () => instance?.clearSelectionColor(),
6723
+ bringToFront: (targetId) => instance?.bringToFront(targetId),
6724
+ bringForward: (targetId) => instance?.bringForward(targetId),
6725
+ sendBackward: (targetId) => instance?.sendBackward(targetId),
6726
+ sendToBack: (targetId) => instance?.sendToBack(targetId),
6727
+ alignNodes: (alignment, nodeIds) => instance?.alignNodes(alignment, nodeIds),
6728
+ distributeNodes: (axis, nodeIds) => instance?.distributeNodes(axis, nodeIds),
6729
+ setNodeLocked: (nodeId, locked) => Boolean(instance?.setNodeLocked(nodeId, locked)),
6730
+ toggleNodeLocked: (nodeId) => Boolean(instance?.toggleNodeLocked(nodeId)),
6731
+ duplicateSelection: () => instance?.duplicateSelection() ?? null,
6732
+ copySelection: () => Boolean(instance?.copySelection()),
6733
+ pasteClipboard: () => Boolean(instance?.pasteClipboard()),
6734
+ pasteSelection: () => instance?.pasteSelection() ?? null,
6735
+ cutSelection: () => Boolean(instance?.cutSelection()),
6736
+ exportSvg: (options) => instance?.exportSvg(options) ?? ""
5626
6737
  });
5627
6738
  return () => h("div", { ref: el, class: "vd-flowchart" });
5628
6739
  }
5629
6740
  });
5630
6741
  export {
6742
+ FLOWCHART_COLOR_PRESETS,
6743
+ FLOWCHART_DISTRIBUTE_AXES,
5631
6744
  FLOWCHART_DOCUMENT_VERSION,
5632
6745
  FLOWCHART_EDGE_MARKERS,
5633
6746
  FLOWCHART_EDGE_ROUTES,
6747
+ FLOWCHART_EDGE_STROKE_STYLES,
5634
6748
  FLOWCHART_KEYBOARD_SHORTCUTS,
6749
+ FLOWCHART_NODE_ALIGNMENTS,
5635
6750
  FLOWCHART_NODE_TYPES,
5636
6751
  FLOWCHART_PORTS,
5637
6752
  LAYOUT_MODES,