@vanduo-oss/vd3-flowchart 1.5.1 → 1.6.1

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.1";
527
532
  var FLOWCHART_DOCUMENT_VERSION = "1.3.0";
528
533
  var FLOWCHART_NODE_TYPES = [
529
534
  "rounded-rect",
@@ -537,10 +542,105 @@ 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_COLOR_PRESET_DARK_FALLBACKS = {
592
+ primary: { fill: "#1e3a8a", stroke: "#60a5fa", text: "#dbeafe", edge: "#60a5fa" },
593
+ secondary: { fill: "#312e81", stroke: "#818cf8", text: "#e0e7ff", edge: "#818cf8" },
594
+ success: { fill: "#14532d", stroke: "#4ade80", text: "#dcfce7", edge: "#4ade80" },
595
+ warning: { fill: "#78350f", stroke: "#fbbf24", text: "#fef3c7", edge: "#fbbf24" },
596
+ danger: { fill: "#7f1d1d", stroke: "#f87171", text: "#fee2e2", edge: "#f87171" },
597
+ info: { fill: "#0c4a6e", stroke: "#38bdf8", text: "#e0f2fe", edge: "#38bdf8" },
598
+ violet: { fill: "#581c87", stroke: "#c084fc", text: "#f3e8ff", edge: "#c084fc" },
599
+ teal: { fill: "#134e4a", stroke: "#2dd4bf", text: "#ccfbf1", edge: "#2dd4bf" },
600
+ orange: { fill: "#7c2d12", stroke: "#fb923c", text: "#ffedd5", edge: "#fb923c" },
601
+ pink: { fill: "#831843", stroke: "#f472b6", text: "#fce7f3", edge: "#f472b6" },
602
+ neutral: { fill: "#1e293b", stroke: "#94a3b8", text: "#f1f5f9", edge: "#94a3b8" }
603
+ };
604
+ var FLOWCHART_EDGE_STROKE_STYLE_LABELS = {
605
+ solid: "Solid",
606
+ dashed: "Dashed",
607
+ dotted: "Dotted",
608
+ animated: "Animated flow"
609
+ };
541
610
  function normalizeKeyboardShortcuts(value) {
542
611
  return value === "basic" ? "basic" : "mindmap";
543
612
  }
613
+ function normalizeColorPreset(value) {
614
+ if (typeof value !== "string") return "";
615
+ const trimmed = value.trim().toLowerCase();
616
+ return FLOWCHART_COLOR_PRESETS.includes(trimmed) && trimmed !== "default" ? trimmed : "";
617
+ }
618
+ function sanitizeCssColor(value) {
619
+ if (typeof value !== "string") return "";
620
+ const trimmed = value.trim();
621
+ if (!trimmed || trimmed === "default") return "";
622
+ if (trimmed.length > 64 || /\\/.test(trimmed)) return "";
623
+ if (/[;{}<>"'`]/.test(trimmed) || /url\s*\(|expression\s*\(|javascript\s*:/i.test(trimmed)) {
624
+ return "";
625
+ }
626
+ if (!/^[#a-z0-9(),.%\s/+-]+$/i.test(trimmed)) return "";
627
+ return trimmed;
628
+ }
629
+ function normalizeEdgeColor(value) {
630
+ const preset = normalizeColorPreset(value);
631
+ if (preset) return preset;
632
+ return sanitizeCssColor(value);
633
+ }
634
+ function normalizeEdgeStrokeStyle(value) {
635
+ return FLOWCHART_EDGE_STROKE_STYLES.includes(value) && value !== "solid" ? value : "solid";
636
+ }
637
+ function resolveEdgeColorValue(color) {
638
+ if (!color || color === "default") return "var(--vd-flowchart-accent)";
639
+ if (FLOWCHART_COLOR_PRESETS.includes(color)) {
640
+ return `var(--vd-flowchart-palette-${color}-edge)`;
641
+ }
642
+ return color;
643
+ }
544
644
  var ARROW_DIRECTIONS = {
545
645
  ArrowRight: "right",
546
646
  ArrowLeft: "left",
@@ -581,6 +681,8 @@ function getShortcutRows(mode, readonly) {
581
681
  "Edit the connection label"
582
682
  ],
583
683
  ["Cmd/Ctrl + /", "Collapse or expand the branch"],
684
+ ["Cmd/Ctrl + ] or [", "Bring forward or send backward (Shift: front/back)"],
685
+ ["Cmd/Ctrl + L", "Lock or unlock the selected node"],
584
686
  ["Alt + Arrow", "Nudge the node (add Shift for 1 px)"],
585
687
  ["Delete or Backspace", "Delete the selection"],
586
688
  ["Cmd/Ctrl + D", "Duplicate the node"],
@@ -765,10 +867,12 @@ function clampNodeHeight(type, height, fallback, sizeBounds) {
765
867
  return clamp(toFiniteNumber(height, fallback), bounds.minHeight, bounds.maxHeight);
766
868
  }
767
869
  function isNodeResizable(nodeOrType) {
870
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
768
871
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
769
872
  return spec.resizable !== false;
770
873
  }
771
874
  function isNodeTextEditable(nodeOrType) {
875
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
772
876
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
773
877
  return spec.textEditable !== false;
774
878
  }
@@ -789,8 +893,8 @@ function normalizeViewport(viewport, scaleBounds) {
789
893
  const min = scaleBounds?.min ?? DEFAULT_MIN_SCALE;
790
894
  const max = scaleBounds?.max ?? DEFAULT_MAX_SCALE;
791
895
  return {
792
- x: toFiniteNumber(viewport?.x, 0),
793
- y: toFiniteNumber(viewport?.y, 0),
896
+ x: formatNumber(toFiniteNumber(viewport?.x, 0)),
897
+ y: formatNumber(toFiniteNumber(viewport?.y, 0)),
794
898
  scale: clamp(formatScale(toFiniteNumber(viewport?.scale, 1)), min, max)
795
899
  };
796
900
  }
@@ -800,14 +904,23 @@ function normalizeNode(rawNode, index, usedIds, sizeBounds) {
800
904
  const node = {
801
905
  id: ensureUniqueId(rawNode?.id, "node", usedIds),
802
906
  type,
803
- x: toFiniteNumber(rawNode?.x, index * 28),
804
- y: toFiniteNumber(rawNode?.y, index * 18),
805
- width: clampNodeWidth(type, rawNode?.width, spec.width, sizeBounds),
806
- height: clampNodeHeight(type, rawNode?.height, spec.height, sizeBounds),
907
+ x: formatNumber(toFiniteNumber(rawNode?.x, index * 28)),
908
+ y: formatNumber(toFiniteNumber(rawNode?.y, index * 18)),
909
+ width: formatNumber(clampNodeWidth(type, rawNode?.width, spec.width, sizeBounds)),
910
+ height: formatNumber(clampNodeHeight(type, rawNode?.height, spec.height, sizeBounds)),
807
911
  text: rawNode?.text == null ? spec.text : String(rawNode.text),
808
912
  data: isPlainObject(rawNode?.data) ? deepClone(rawNode.data) : {}
809
913
  };
810
914
  if (rawNode?.collapsed === true) node.collapsed = true;
915
+ const color = normalizeColorPreset(rawNode?.color ?? rawNode?.data?.color);
916
+ if (color) node.color = color;
917
+ const fill = sanitizeCssColor(rawNode?.fill ?? rawNode?.data?.fill);
918
+ if (fill) node.fill = fill;
919
+ const stroke = sanitizeCssColor(rawNode?.stroke ?? rawNode?.data?.stroke);
920
+ if (stroke) node.stroke = stroke;
921
+ const textColor = sanitizeCssColor(rawNode?.textColor ?? rawNode?.data?.textColor);
922
+ if (textColor) node.textColor = textColor;
923
+ if (rawNode?.locked === true || rawNode?.data?.locked === true) node.locked = true;
811
924
  return node;
812
925
  }
813
926
  function computeHiddenNodeIds(nodes, edges) {
@@ -840,6 +953,12 @@ function computeHiddenNodeIds(nodes, edges) {
840
953
  return candidates;
841
954
  }
842
955
  function normalizeEndpoint(rawEndpoint, fallbackPort) {
956
+ if (typeof rawEndpoint === "string") {
957
+ return {
958
+ nodeId: sanitizeId(rawEndpoint),
959
+ port: fallbackPort
960
+ };
961
+ }
843
962
  return {
844
963
  nodeId: sanitizeId(rawEndpoint?.nodeId),
845
964
  port: FLOWCHART_PORTS.includes(rawEndpoint?.port) ? rawEndpoint.port : fallbackPort
@@ -875,6 +994,10 @@ function normalizeEdge(rawEdge, index, nodeIds, usedIds) {
875
994
  label: rawEdge?.label == null ? "" : String(rawEdge.label),
876
995
  data: isPlainObject(rawEdge?.data) ? deepClone(rawEdge.data) : {}
877
996
  };
997
+ const color = normalizeEdgeColor(rawEdge?.color ?? rawEdge?.data?.color);
998
+ if (color) edge.color = color;
999
+ const strokeStyle = normalizeEdgeStrokeStyle(rawEdge?.strokeStyle ?? rawEdge?.data?.strokeStyle);
1000
+ if (strokeStyle !== "solid") edge.strokeStyle = strokeStyle;
878
1001
  syncEdgeKind(edge);
879
1002
  return edge;
880
1003
  }
@@ -1321,19 +1444,75 @@ function buildOrthogonalPath(fromPoint, toPoint, fromPort = "right", toPort = "l
1321
1444
  labelY: label.y
1322
1445
  };
1323
1446
  }
1447
+ function getPortOuterOffset(node, port) {
1448
+ if (!node || node.type === "label") return 0;
1449
+ const visual = nodeVisualScale(node);
1450
+ const baseStroke = node.type === "junction" ? 1.25 : 1.5;
1451
+ const halfStroke = Math.max(0.015, baseStroke * visual / 2);
1452
+ if (node.type === "diamond") {
1453
+ const w = Math.max(1, toFiniteNumber(node.width, 184));
1454
+ const h2 = Math.max(1, toFiniteNumber(node.height, 120));
1455
+ const diag = Math.hypot(w, h2);
1456
+ const miterFactor = isHorizontalPort(port) ? Math.min(4, diag / h2) : Math.min(4, diag / w);
1457
+ return halfStroke * miterFactor;
1458
+ }
1459
+ return halfStroke;
1460
+ }
1461
+ function getMarkerEndpointRetraction(markerType, strokeWidth, edgeScale = 1) {
1462
+ if (!markerType || markerType === "none") return 0;
1463
+ const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1464
+ const effective = Math.max(0.02, normalizeEdgeStrokeWidth(strokeWidth) * scale);
1465
+ if (markerType === "dot") {
1466
+ return formatNumber(Math.max(2.75 * scale, effective * 1.45));
1467
+ }
1468
+ return formatNumber(Math.max(1.5 * scale, effective * 0.85));
1469
+ }
1324
1470
  function buildEdgePath(edge, fromNode = null, toNode = null) {
1325
1471
  const fromPort = edge?.from?.port || edge?.fromPort || "right";
1326
1472
  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);
1473
+ const rawFromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
1474
+ const rawToPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
1329
1475
  const route = normalizeEdgeRoute(edge?.route);
1330
- const metrics = routeMetrics(edgeVisualScale(fromNode, toNode));
1331
- if (!fromPoint || !toPoint) {
1476
+ const visualScale = edgeVisualScale(fromNode, toNode);
1477
+ const metrics = routeMetrics(visualScale);
1478
+ if (!rawFromPoint || !rawToPoint) {
1332
1479
  return { d: "", labelX: 0, labelY: 0 };
1333
1480
  }
1481
+ const strokeWidth = normalizeEdgeStrokeWidth(edge?.strokeWidth);
1482
+ const startMarker = edge?.startMarker || "none";
1483
+ const endMarker = edge?.endMarker || "none";
1484
+ const rawDistance = Math.hypot(rawToPoint.x - rawFromPoint.x, rawToPoint.y - rawFromPoint.y);
1485
+ const maxRetract = rawDistance > 0 ? rawDistance * 0.45 : 0;
1486
+ const fromMarkerRetract = !edge?.fromPoint && fromNode && startMarker !== "none" ? getMarkerEndpointRetraction(startMarker, strokeWidth, visualScale) : 0;
1487
+ const fromBorderRetract = fromMarkerRetract > 0 ? getPortOuterOffset(fromNode, fromPort) : 0;
1488
+ const toMarkerRetract = !edge?.toPoint && toNode && endMarker !== "none" ? getMarkerEndpointRetraction(endMarker, strokeWidth, visualScale) : 0;
1489
+ const toBorderRetract = toMarkerRetract > 0 ? getPortOuterOffset(toNode, toPort) : 0;
1490
+ const fromRetract = Math.min(maxRetract, fromMarkerRetract + fromBorderRetract);
1491
+ const toRetract = Math.min(maxRetract, toMarkerRetract + toBorderRetract);
1334
1492
  if (route === "straight") {
1335
- return buildStraightPath(fromPoint, toPoint);
1493
+ const borderFrom = fromBorderRetract > 0 ? offsetPoint(
1494
+ rawFromPoint,
1495
+ getPortNormal(fromPort),
1496
+ Math.min(maxRetract, fromBorderRetract)
1497
+ ) : rawFromPoint;
1498
+ const borderTo = toBorderRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), Math.min(maxRetract, toBorderRetract)) : rawToPoint;
1499
+ const dx = borderTo.x - borderFrom.x;
1500
+ const dy = borderTo.y - borderFrom.y;
1501
+ const dist = Math.hypot(dx, dy);
1502
+ if (dist > 0.01) {
1503
+ const ux = dx / dist;
1504
+ const uy = dy / dist;
1505
+ const sRetract = Math.min(dist * 0.45, fromMarkerRetract);
1506
+ const eRetract = Math.min(dist * 0.45, toMarkerRetract);
1507
+ return buildStraightPath(
1508
+ { x: borderFrom.x + ux * sRetract, y: borderFrom.y + uy * sRetract },
1509
+ { x: borderTo.x - ux * eRetract, y: borderTo.y - uy * eRetract }
1510
+ );
1511
+ }
1512
+ return buildStraightPath(rawFromPoint, rawToPoint);
1336
1513
  }
1514
+ const fromPoint = fromRetract > 0 ? offsetPoint(rawFromPoint, getPortNormal(fromPort), fromRetract) : rawFromPoint;
1515
+ const toPoint = toRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), toRetract) : rawToPoint;
1337
1516
  if (route === "orthogonal") {
1338
1517
  const fromRect = !edge?.fromPoint && fromNode ? getNodeRectBounds(fromNode, metrics.clearance) : null;
1339
1518
  const toRect = !edge?.toPoint && toNode ? getNodeRectBounds(toNode, metrics.clearance) : null;
@@ -1341,7 +1520,7 @@ function buildEdgePath(edge, fromNode = null, toNode = null) {
1341
1520
  }
1342
1521
  return buildCurvePath(fromPoint, toPoint, fromPort, toPort, metrics);
1343
1522
  }
1344
- function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1523
+ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1345
1524
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1346
1525
  const effective = Math.max(0.02, strokeWidth * scale);
1347
1526
  const size = formatNumber(Math.max(9 * scale, effective * 4.4));
@@ -1358,12 +1537,12 @@ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1358
1537
  marker.appendChild(
1359
1538
  svgEl("path", {
1360
1539
  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)"
1540
+ fill
1362
1541
  })
1363
1542
  );
1364
1543
  return marker;
1365
1544
  }
1366
- function createDotMarker(id, strokeWidth, edgeScale = 1) {
1545
+ function createDotMarker(id, strokeWidth, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1367
1546
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1368
1547
  const effective = Math.max(0.02, strokeWidth * scale);
1369
1548
  const size = formatNumber(Math.max(8 * scale, effective * 3.3));
@@ -1382,7 +1561,7 @@ function createDotMarker(id, strokeWidth, edgeScale = 1) {
1382
1561
  cx: formatNumber(size / 2),
1383
1562
  cy: formatNumber(size / 2),
1384
1563
  r: radius,
1385
- fill: "var(--vd-flowchart-accent)"
1564
+ fill
1386
1565
  })
1387
1566
  );
1388
1567
  return marker;
@@ -1671,6 +1850,7 @@ var VdFlowchart = class {
1671
1850
  this.minimapFrame = 0;
1672
1851
  this.minimapDrag = null;
1673
1852
  this.shortcutsHelpOpen = false;
1853
+ this.colorPopoverOpen = false;
1674
1854
  this.autoFit = Boolean(options.autoFit);
1675
1855
  this.readyEmitted = false;
1676
1856
  this.resizeObserver = null;
@@ -1687,8 +1867,10 @@ var VdFlowchart = class {
1687
1867
  this.handleKeyDown = this.handleKeyDown.bind(this);
1688
1868
  this.handleSelectionFieldInput = this.handleSelectionFieldInput.bind(this);
1689
1869
  this.handleSelectionFieldChange = this.handleSelectionFieldChange.bind(this);
1870
+ this.handleSelectionActionClick = this.handleSelectionActionClick.bind(this);
1690
1871
  this.handleJsonActionClick = this.handleJsonActionClick.bind(this);
1691
1872
  this.handleResize = this.handleResize.bind(this);
1873
+ this.handleOutsidePointerDown = this.handleOutsidePointerDown.bind(this);
1692
1874
  this.buildShell();
1693
1875
  this.bindEvents();
1694
1876
  this.render();
@@ -1727,8 +1909,19 @@ var VdFlowchart = class {
1727
1909
  });
1728
1910
  this.resizeObserver.observe(this.canvasEl);
1729
1911
  }
1730
- const raf = typeof requestAnimationFrame === "function" ? requestAnimationFrame : (cb) => setTimeout(cb, 16);
1731
- raf(() => tryEmit());
1912
+ if (typeof requestAnimationFrame === "function") {
1913
+ this.readyFrameIsTimeout = false;
1914
+ this.readyFrame = requestAnimationFrame(() => {
1915
+ this.readyFrame = 0;
1916
+ tryEmit();
1917
+ });
1918
+ } else {
1919
+ this.readyFrameIsTimeout = true;
1920
+ this.readyFrame = setTimeout(() => {
1921
+ this.readyFrame = 0;
1922
+ tryEmit();
1923
+ }, 16);
1924
+ }
1732
1925
  };
1733
1926
  if (typeof queueMicrotask === "function") {
1734
1927
  queueMicrotask(startObserving);
@@ -1772,6 +1965,32 @@ var VdFlowchart = class {
1772
1965
  this.arrangeSelect.appendChild(option);
1773
1966
  });
1774
1967
  this.arrangeSelect.value = this.layoutMode;
1968
+ this.colorPopoverWrap = createElement("div", { className: "vd-flowchart-color-popover-wrap" });
1969
+ this.colorButton = createToolbarButton({
1970
+ action: "color-popover",
1971
+ label: "Color selection",
1972
+ icon: "palette",
1973
+ disabled: this.readonly
1974
+ });
1975
+ this.colorButton.setAttribute("aria-expanded", "false");
1976
+ this.colorPopover = createElement("div", { className: "vd-flowchart-color-popover" });
1977
+ this.colorPopover.hidden = true;
1978
+ this.colorPopover.setAttribute("role", "dialog");
1979
+ this.colorPopover.setAttribute("aria-label", "Color presets");
1980
+ const popoverSwatches = createElement("div", { className: "vd-flowchart-swatch-grid" });
1981
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
1982
+ const swatch = createElement("button", {
1983
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}`,
1984
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset
1985
+ });
1986
+ swatch.setAttribute("type", "button");
1987
+ swatch.setAttribute("data-flowchart-color", preset);
1988
+ swatch.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
1989
+ popoverSwatches.appendChild(swatch);
1990
+ });
1991
+ this.colorPopover.appendChild(popoverSwatches);
1992
+ this.colorPopoverWrap.appendChild(this.colorButton);
1993
+ this.colorPopoverWrap.appendChild(this.colorPopover);
1775
1994
  this.clearButton = createToolbarButton({
1776
1995
  action: "clear",
1777
1996
  label: "Clear canvas",
@@ -1798,6 +2017,7 @@ var VdFlowchart = class {
1798
2017
  });
1799
2018
  this.minimapButton.setAttribute("aria-pressed", this.minimapEnabled ? "true" : "false");
1800
2019
  toolbarLeft.appendChild(this.arrangeSelect);
2020
+ toolbarLeft.appendChild(this.colorPopoverWrap);
1801
2021
  toolbarLeft.appendChild(this.clearButton);
1802
2022
  toolbarRight.appendChild(this.minimapButton);
1803
2023
  toolbarRight.appendChild(this.shortcutsButton);
@@ -2082,12 +2302,14 @@ var VdFlowchart = class {
2082
2302
  this.graphEditButton.disabled = this.readonly || nodes.length === 0;
2083
2303
  }
2084
2304
  bindEvents() {
2305
+ this.handleDeleteClick = () => this.deleteSelection();
2085
2306
  this.toolbar.addEventListener("click", this.handleToolbarClick);
2086
2307
  this.arrangeSelect.addEventListener("change", this.handleArrangeChange);
2087
2308
  this.paletteGrid.addEventListener("click", this.handlePaletteClick);
2088
- this.deleteButton.addEventListener("click", () => this.deleteSelection());
2309
+ this.deleteButton.addEventListener("click", this.handleDeleteClick);
2089
2310
  this.selectionFields.addEventListener("input", this.handleSelectionFieldInput);
2090
2311
  this.selectionFields.addEventListener("change", this.handleSelectionFieldChange);
2312
+ this.selectionFields.addEventListener("click", this.handleSelectionActionClick);
2091
2313
  this.jsonActions.addEventListener("click", this.handleJsonActionClick);
2092
2314
  this.canvasEl.addEventListener("pointerdown", this.handlePointerDown);
2093
2315
  this.canvasEl.addEventListener("pointermove", this.handlePointerMove);
@@ -2099,14 +2321,24 @@ var VdFlowchart = class {
2099
2321
  this.canvasEl.addEventListener("blur", this.handleCanvasBlur);
2100
2322
  this.root.addEventListener("keydown", this.handleKeyDown, true);
2101
2323
  window.addEventListener("pointerup", this.handlePointerUp);
2324
+ window.addEventListener("pointerdown", this.handleOutsidePointerDown);
2102
2325
  window.addEventListener("resize", this.handleResize);
2103
2326
  }
2104
2327
  unbindEvents() {
2105
2328
  this.toolbar.removeEventListener("click", this.handleToolbarClick);
2106
2329
  this.arrangeSelect.removeEventListener("change", this.handleArrangeChange);
2107
2330
  this.paletteGrid.removeEventListener("click", this.handlePaletteClick);
2331
+ if (this.handleDeleteClick) {
2332
+ this.deleteButton.removeEventListener("click", this.handleDeleteClick);
2333
+ this.handleDeleteClick = null;
2334
+ }
2335
+ if (this.handleDeleteClick) {
2336
+ this.deleteButton.removeEventListener("click", this.handleDeleteClick);
2337
+ this.handleDeleteClick = null;
2338
+ }
2108
2339
  this.selectionFields.removeEventListener("input", this.handleSelectionFieldInput);
2109
2340
  this.selectionFields.removeEventListener("change", this.handleSelectionFieldChange);
2341
+ this.selectionFields.removeEventListener("click", this.handleSelectionActionClick);
2110
2342
  this.jsonActions.removeEventListener("click", this.handleJsonActionClick);
2111
2343
  this.canvasEl.removeEventListener("pointerdown", this.handlePointerDown);
2112
2344
  this.canvasEl.removeEventListener("pointermove", this.handlePointerMove);
@@ -2118,8 +2350,14 @@ var VdFlowchart = class {
2118
2350
  this.canvasEl.removeEventListener("blur", this.handleCanvasBlur);
2119
2351
  this.root.removeEventListener("keydown", this.handleKeyDown, true);
2120
2352
  window.removeEventListener("pointerup", this.handlePointerUp);
2353
+ window.removeEventListener("pointerdown", this.handleOutsidePointerDown);
2121
2354
  window.removeEventListener("resize", this.handleResize);
2122
2355
  }
2356
+ handleOutsidePointerDown(event) {
2357
+ if (!this.colorPopoverOpen || this.destroyed) return;
2358
+ if (event.target?.closest?.(".vd-flowchart-color-popover-wrap")) return;
2359
+ this.toggleColorPopover(false);
2360
+ }
2123
2361
  handleResize() {
2124
2362
  if (this.destroyed) return;
2125
2363
  this.render({ inspector: false, json: false });
@@ -2158,7 +2396,24 @@ var VdFlowchart = class {
2158
2396
  this.updatePaletteState();
2159
2397
  this.render({ scene: true, inspector: false, json: false });
2160
2398
  }
2399
+ toggleColorPopover(force) {
2400
+ if (!this.colorPopover || !this.colorButton) return this;
2401
+ const open = typeof force === "boolean" ? force : !this.colorPopoverOpen;
2402
+ this.colorPopoverOpen = open && !this.readonly;
2403
+ this.colorPopover.hidden = !this.colorPopoverOpen;
2404
+ this.colorButton.setAttribute("aria-expanded", this.colorPopoverOpen ? "true" : "false");
2405
+ return this;
2406
+ }
2161
2407
  handleToolbarClick(event) {
2408
+ const colorSwatch = event.target.closest("[data-flowchart-color]");
2409
+ if (colorSwatch) {
2410
+ if (!this.readonly) {
2411
+ const preset = colorSwatch.getAttribute("data-flowchart-color");
2412
+ this.setSelectionColor(preset);
2413
+ }
2414
+ this.toggleColorPopover(false);
2415
+ return;
2416
+ }
2162
2417
  const actionButton = event.target.closest("[data-flowchart-action]");
2163
2418
  if (!actionButton) return;
2164
2419
  const action = actionButton.getAttribute("data-flowchart-action");
@@ -2168,6 +2423,7 @@ var VdFlowchart = class {
2168
2423
  if (action === "fit-view") this.fitView();
2169
2424
  if (action === "undo") this.undo();
2170
2425
  if (action === "redo") this.redo();
2426
+ if (action === "color-popover") this.toggleColorPopover();
2171
2427
  if (action === "clear" && !this.readonly) this.clear();
2172
2428
  if (action === "shortcuts") this.toggleShortcutsHelp();
2173
2429
  if (action === "minimap") this.setMinimapEnabled(!this.minimapEnabled);
@@ -2230,16 +2486,18 @@ var VdFlowchart = class {
2230
2486
  nodes.forEach((node) => {
2231
2487
  const point = map(node.x, node.y);
2232
2488
  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
- );
2489
+ const rectEl = svgEl("rect", {
2490
+ class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
2491
+ x: point.x,
2492
+ y: point.y,
2493
+ width: formatNumber(Math.max(1.5, node.width * transform.scale)),
2494
+ height: formatNumber(Math.max(1.5, node.height * transform.scale)),
2495
+ rx: 1.5
2496
+ });
2497
+ if (node.color) rectEl.setAttribute("data-color", node.color);
2498
+ if (node.fill) rectEl.style.fill = node.fill;
2499
+ if (node.stroke) rectEl.style.stroke = node.stroke;
2500
+ this.minimapSvg.appendChild(rectEl);
2243
2501
  });
2244
2502
  const corner = map(view.left, view.top);
2245
2503
  this.minimapSvg.appendChild(
@@ -2361,6 +2619,42 @@ var VdFlowchart = class {
2361
2619
  }
2362
2620
  }
2363
2621
  }
2622
+ handleSelectionActionClick(event) {
2623
+ if (this.readonly) return;
2624
+ const swatch = event.target.closest("[data-color-preset]");
2625
+ if (swatch) {
2626
+ this.setSelectionColor(swatch.getAttribute("data-color-preset"));
2627
+ return;
2628
+ }
2629
+ const resetBtn = event.target.closest("[data-color-reset]");
2630
+ if (resetBtn) {
2631
+ this.clearSelectionColor();
2632
+ return;
2633
+ }
2634
+ const arrangeBtn = event.target.closest("[data-arrange-action]");
2635
+ if (arrangeBtn) {
2636
+ const action = arrangeBtn.getAttribute("data-arrange-action");
2637
+ if (action === "bring-to-front") this.bringToFront();
2638
+ else if (action === "bring-forward") this.bringForward();
2639
+ else if (action === "send-backward") this.sendBackward();
2640
+ else if (action === "send-to-back") this.sendToBack();
2641
+ return;
2642
+ }
2643
+ const alignBtn = event.target.closest("[data-align-action]");
2644
+ if (alignBtn) {
2645
+ this.alignNodes(alignBtn.getAttribute("data-align-action"));
2646
+ return;
2647
+ }
2648
+ const distributeBtn = event.target.closest("[data-distribute-action]");
2649
+ if (distributeBtn) {
2650
+ this.distributeNodes(distributeBtn.getAttribute("data-distribute-action"));
2651
+ return;
2652
+ }
2653
+ const lockBtn = event.target.closest("[data-lock-toggle]");
2654
+ if (lockBtn) {
2655
+ this.toggleNodeLocked();
2656
+ }
2657
+ }
2364
2658
  handleSelectionFieldInput(event) {
2365
2659
  const field = event.target.getAttribute("data-field");
2366
2660
  if (!field) return;
@@ -2383,6 +2677,38 @@ var VdFlowchart = class {
2383
2677
  if (field === "node-width" || field === "node-height") {
2384
2678
  const patch = field === "node-width" ? { width: toFiniteNumber(event.target.value, void 0) } : { height: toFiniteNumber(event.target.value, void 0) };
2385
2679
  this.updateNode(this.selection?.id, patch, { inspector: false, reason: "node:update" });
2680
+ return;
2681
+ }
2682
+ if (field === "node-fill") {
2683
+ this.updateNode(
2684
+ this.selection?.id,
2685
+ { fill: event.target.value },
2686
+ { inspector: false, reason: "node:update" }
2687
+ );
2688
+ return;
2689
+ }
2690
+ if (field === "node-stroke") {
2691
+ this.updateNode(
2692
+ this.selection?.id,
2693
+ { stroke: event.target.value },
2694
+ { inspector: false, reason: "node:update" }
2695
+ );
2696
+ return;
2697
+ }
2698
+ if (field === "node-text-color") {
2699
+ this.updateNode(
2700
+ this.selection?.id,
2701
+ { textColor: event.target.value },
2702
+ { inspector: false, reason: "node:update" }
2703
+ );
2704
+ return;
2705
+ }
2706
+ if (field === "edge-color") {
2707
+ this.updateEdge(
2708
+ this.selection?.id,
2709
+ { color: event.target.value },
2710
+ { inspector: false, reason: "edge:update" }
2711
+ );
2386
2712
  }
2387
2713
  }
2388
2714
  handleSelectionFieldChange(event) {
@@ -2426,6 +2752,14 @@ var VdFlowchart = class {
2426
2752
  { strokeWidth: getStrokePresetWidth(event.target.value) },
2427
2753
  { inspector: true, reason: "edge:update" }
2428
2754
  );
2755
+ return;
2756
+ }
2757
+ if (field === "edge-stroke-style") {
2758
+ this.updateEdge(
2759
+ this.selection?.id,
2760
+ { strokeStyle: event.target.value },
2761
+ { inspector: true, reason: "edge:update" }
2762
+ );
2429
2763
  }
2430
2764
  }
2431
2765
  // Keys the editor consumes stop here, so page-level shortcuts (a docs
@@ -2448,6 +2782,11 @@ var VdFlowchart = class {
2448
2782
  this.toggleShortcutsHelp(false);
2449
2783
  return;
2450
2784
  }
2785
+ if (key === "Escape" && this.colorPopoverOpen) {
2786
+ event.preventDefault();
2787
+ this.toggleColorPopover(false);
2788
+ return;
2789
+ }
2451
2790
  if (target === this.canvasEl && this.handleCanvasKeyDown(event)) {
2452
2791
  event.preventDefault();
2453
2792
  return;
@@ -2470,6 +2809,29 @@ var VdFlowchart = class {
2470
2809
  }
2471
2810
  return;
2472
2811
  }
2812
+ if (modKey && (key === "l" || key === "L")) {
2813
+ if (this.selection?.kind === "node") {
2814
+ event.preventDefault();
2815
+ this.toggleNodeLocked();
2816
+ }
2817
+ return;
2818
+ }
2819
+ if (modKey && (key === "]" || key === "}" || event.code === "BracketRight")) {
2820
+ if (this.selection) {
2821
+ event.preventDefault();
2822
+ if (event.shiftKey || key === "}") this.bringToFront();
2823
+ else this.bringForward();
2824
+ }
2825
+ return;
2826
+ }
2827
+ if (modKey && (key === "[" || key === "{" || event.code === "BracketLeft")) {
2828
+ if (this.selection) {
2829
+ event.preventDefault();
2830
+ if (event.shiftKey || key === "{") this.sendToBack();
2831
+ else this.sendBackward();
2832
+ }
2833
+ return;
2834
+ }
2473
2835
  if (modKey && (event.key === "z" || event.key === "Z")) {
2474
2836
  event.preventDefault();
2475
2837
  if (event.shiftKey) {
@@ -2652,7 +3014,7 @@ var VdFlowchart = class {
2652
3014
  nudgeNodes(nodeIds, direction, distance) {
2653
3015
  const step = { right: [1, 0], left: [-1, 0], down: [0, 1], up: [0, -1] }[direction];
2654
3016
  if (this.readonly || !step) return [];
2655
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
3017
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
2656
3018
  if (!nodes.length) return [];
2657
3019
  nodes.forEach((node) => {
2658
3020
  node.x = formatNumber(node.x + step[0] * distance);
@@ -2791,7 +3153,32 @@ var VdFlowchart = class {
2791
3153
  this.emitChange("edge:add", { edge: deepClone(edge) });
2792
3154
  return true;
2793
3155
  }
3156
+ pasteSelection() {
3157
+ if (!this.pasteClipboard()) return null;
3158
+ if (this.hasMultiSelection()) {
3159
+ return this.getSelectedNodeIds().map((id) => this.findNode(id)).filter(Boolean).map((node) => deepClone(node));
3160
+ }
3161
+ const snap = this.getSelectionSnapshot();
3162
+ return snap?.node || snap?.edge || null;
3163
+ }
2794
3164
  cutSelection() {
3165
+ if (!this.selection || this.readonly) return false;
3166
+ if (this.hasMultiSelection()) {
3167
+ const unlockedIds = this.getSelectedNodeIds().filter((id) => {
3168
+ const node = this.findNode(id);
3169
+ return node && !node.locked;
3170
+ });
3171
+ if (!unlockedIds.length) return false;
3172
+ const unlockedSet = new Set(unlockedIds);
3173
+ const nodes = unlockedIds.map((id) => deepClone(this.findNode(id)));
3174
+ const edges = this.documentData.edges.filter((edge) => unlockedSet.has(edge.from.nodeId) && unlockedSet.has(edge.to.nodeId)).map((edge) => deepClone(edge));
3175
+ this.clipboard = { kind: "nodes", data: { nodes, edges } };
3176
+ return this.deleteSelection();
3177
+ }
3178
+ if (this.selection.kind === "node") {
3179
+ const node = this.findNode(this.selection.id);
3180
+ if (!node || node.locked) return false;
3181
+ }
2795
3182
  if (!this.copySelection()) return false;
2796
3183
  return this.deleteSelection();
2797
3184
  }
@@ -2828,6 +3215,9 @@ var VdFlowchart = class {
2828
3215
  }
2829
3216
  handlePointerDown(event) {
2830
3217
  if (this.destroyed || event.button != null && event.button !== 0) return;
3218
+ if (this.colorPopoverOpen) {
3219
+ this.toggleColorPopover(false);
3220
+ }
2831
3221
  if (this.textEditor && !event.target.closest(".vd-flowchart-text-editor")) {
2832
3222
  this.stopTextEdit({ commit: true });
2833
3223
  }
@@ -2852,6 +3242,8 @@ var VdFlowchart = class {
2852
3242
  const fromNode = this.findNode(edge.from.nodeId);
2853
3243
  const toNode = this.findNode(edge.to.nodeId);
2854
3244
  if (!fromNode || !toNode) return;
3245
+ const endpointNode = endpoint === "from" ? fromNode : toNode;
3246
+ if (endpointNode.locked) return;
2855
3247
  this.reconnectEdgeId = edgeId;
2856
3248
  this.select({ kind: "edge", id: edgeId });
2857
3249
  this.interaction = {
@@ -2902,7 +3294,7 @@ var VdFlowchart = class {
2902
3294
  const nodeId = portTarget.getAttribute("data-node-id");
2903
3295
  const port = portTarget.getAttribute("data-port");
2904
3296
  const node = this.findNode(nodeId);
2905
- if (!node) return;
3297
+ if (!node || node.locked) return;
2906
3298
  const sourcePoint = getPortPosition(node, port);
2907
3299
  this.interaction = {
2908
3300
  kind: "connect",
@@ -2931,7 +3323,7 @@ var VdFlowchart = class {
2931
3323
  const nodeId = resizeTarget.getAttribute("data-node-id");
2932
3324
  const handle = resizeTarget.getAttribute("data-resize-handle");
2933
3325
  const node = this.findNode(nodeId);
2934
- if (!node || !RESIZE_HANDLES.includes(handle)) return;
3326
+ if (!node || !isNodeResizable(node) || !RESIZE_HANDLES.includes(handle)) return;
2935
3327
  this.select({ kind: "node", id: nodeId });
2936
3328
  this.interaction = {
2937
3329
  kind: "resize-node",
@@ -2964,8 +3356,11 @@ var VdFlowchart = class {
2964
3356
  if (groupIds.length > 1) this.selectNodes(groupIds, { primary: nodeId });
2965
3357
  else this.select({ kind: "node", id: nodeId });
2966
3358
  if (!this.readonly) {
2967
- this.interaction = this.createDragInteraction(event, nodeId, groupIds);
2968
- this.capturePointer(event.pointerId);
3359
+ const drag = this.createDragInteraction(event, nodeId, groupIds);
3360
+ if (drag) {
3361
+ this.interaction = drag;
3362
+ this.capturePointer(event.pointerId);
3363
+ }
2969
3364
  }
2970
3365
  return;
2971
3366
  }
@@ -2996,12 +3391,13 @@ var VdFlowchart = class {
2996
3391
  event.preventDefault();
2997
3392
  }
2998
3393
  createDragInteraction(event, nodeId, nodeIds) {
2999
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
3394
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
3395
+ if (!nodes.length) return null;
3000
3396
  const moving = new Set(nodes.map((node) => node.id));
3001
3397
  return {
3002
3398
  kind: "drag-node",
3003
3399
  pointerId: event.pointerId,
3004
- nodeId,
3400
+ nodeId: moving.has(nodeId) ? nodeId : nodes[0].id,
3005
3401
  nodeIds: nodes.map((node) => node.id),
3006
3402
  startWorld: this.clientToWorld(event.clientX, event.clientY),
3007
3403
  origins: new Map(nodes.map((node) => [node.id, { x: node.x, y: node.y }])),
@@ -3353,15 +3749,16 @@ var VdFlowchart = class {
3353
3749
  if (this.activeTool === "arrow") return true;
3354
3750
  return this.selection?.kind === "node" && this.selection.id === node.id && !this.hasMultiSelection();
3355
3751
  }
3356
- getMarkerId(markerType, position, strokeWidth, edgeScale = 1) {
3752
+ getMarkerId(markerType, position, strokeWidth, edgeScale = 1, color = "") {
3357
3753
  const width = normalizeEdgeStrokeWidth(strokeWidth);
3358
3754
  const scale = clamp(formatNumber(Math.max(edgeScale, 0.01)), 0.01, 1);
3359
- const key = `${markerType}:${position}:${width}:${scale}`;
3755
+ const fill = resolveEdgeColorValue(color);
3756
+ const key = `${markerType}:${position}:${width}:${scale}:${fill}`;
3360
3757
  if (this.markerIds.has(key)) {
3361
3758
  return this.markerIds.get(key);
3362
3759
  }
3363
3760
  const markerId = nextId(`flowchart-${markerType}-${position}`);
3364
- const marker = markerType === "dot" ? createDotMarker(markerId, width, scale) : createArrowMarker(markerId, width, position === "start", scale);
3761
+ const marker = markerType === "dot" ? createDotMarker(markerId, width, scale, fill) : createArrowMarker(markerId, width, position === "start", scale, fill);
3365
3762
  this.markerDefs.appendChild(marker);
3366
3763
  this.markerIds.set(key, markerId);
3367
3764
  return markerId;
@@ -3383,7 +3780,7 @@ var VdFlowchart = class {
3383
3780
  const snapPadding = CONNECTION_SNAP_PADDING / this.documentData.viewport.scale;
3384
3781
  const hysteresisMargin = CONNECTION_HYSTERESIS / this.documentData.viewport.scale;
3385
3782
  const best = this.getVisibleNodes().reduce((candidate, node) => {
3386
- if (node.id === excludeNodeId) return candidate;
3783
+ if (node.id === excludeNodeId || node.locked) return candidate;
3387
3784
  const distanceToBounds2 = getDistanceToNodeBounds(node, worldPoint);
3388
3785
  if (distanceToBounds2 > snapPadding) return candidate;
3389
3786
  const nearest = pickPortForNode(node, worldPoint, referencePoint);
@@ -3401,7 +3798,7 @@ var VdFlowchart = class {
3401
3798
  }, null);
3402
3799
  if (!previousSnap || !best) return best;
3403
3800
  const previousNode = this.findNode(previousSnap.nodeId);
3404
- if (!previousNode || previousNode.id === excludeNodeId) return best;
3801
+ if (!previousNode || previousNode.id === excludeNodeId || previousNode.locked) return best;
3405
3802
  const distanceToBounds = getDistanceToNodeBounds(previousNode, worldPoint);
3406
3803
  if (distanceToBounds > snapPadding) return best;
3407
3804
  if (best.node.id === previousSnap.nodeId && best.port === previousSnap.port) {
@@ -3816,16 +4213,17 @@ var VdFlowchart = class {
3816
4213
  }
3817
4214
  applyEdgeMarkers(pathElement, edge, edgeScale = 1) {
3818
4215
  const width = this.getEdgeStrokeWidth(edge);
4216
+ const color = edge.color || "";
3819
4217
  if (edge.startMarker && edge.startMarker !== "none") {
3820
4218
  pathElement.setAttribute(
3821
4219
  "marker-start",
3822
- `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale)})`
4220
+ `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale, color)})`
3823
4221
  );
3824
4222
  }
3825
4223
  if (edge.endMarker && edge.endMarker !== "none") {
3826
4224
  pathElement.setAttribute(
3827
4225
  "marker-end",
3828
- `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale)})`
4226
+ `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale, color)})`
3829
4227
  );
3830
4228
  }
3831
4229
  }
@@ -3837,10 +4235,19 @@ var VdFlowchart = class {
3837
4235
  const edgePath = buildEdgePath(edge, fromNode, toNode);
3838
4236
  const selected = this.selection?.kind === "edge" && this.selection.id === edge.id;
3839
4237
  const inReconnectMode = this.reconnectEdgeId === edge.id;
4238
+ const strokeStyle = normalizeEdgeStrokeStyle(edge.strokeStyle);
4239
+ const strokeClass = strokeStyle !== "solid" ? ` is-stroke-${strokeStyle}` : "";
3840
4240
  const group = svgEl("g", {
3841
- class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}`,
4241
+ class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}${strokeClass}`,
3842
4242
  "data-edge-id": edge.id
3843
4243
  });
4244
+ if (edge.color) {
4245
+ if (FLOWCHART_COLOR_PRESETS.includes(edge.color) && edge.color !== "default") {
4246
+ group.setAttribute("data-color", edge.color);
4247
+ } else {
4248
+ group.setAttribute("data-color", "custom");
4249
+ }
4250
+ }
3844
4251
  const baseStroke = this.getEdgeStrokeWidth(edge);
3845
4252
  const strokeWidth = visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke;
3846
4253
  if (selected) {
@@ -3858,6 +4265,20 @@ var VdFlowchart = class {
3858
4265
  "stroke-width": strokeWidth,
3859
4266
  "data-edge-id": edge.id
3860
4267
  });
4268
+ if (edge.color && !FLOWCHART_COLOR_PRESETS.includes(edge.color)) {
4269
+ visiblePath.style.stroke = edge.color;
4270
+ }
4271
+ if (strokeStyle === "dashed" || strokeStyle === "animated") {
4272
+ visiblePath.setAttribute(
4273
+ "stroke-dasharray",
4274
+ visual < 0.999 ? `${formatNumber(8 * visual)} ${formatNumber(5 * visual)}` : "8 5"
4275
+ );
4276
+ } else if (strokeStyle === "dotted") {
4277
+ visiblePath.setAttribute(
4278
+ "stroke-dasharray",
4279
+ visual < 0.999 ? `${formatNumber(2 * visual)} ${formatNumber(5 * visual)}` : "2 5"
4280
+ );
4281
+ }
3861
4282
  this.applyEdgeMarkers(visiblePath, edge, visual);
3862
4283
  const hitPath = svgEl("path", {
3863
4284
  class: "vd-flowchart-edge-hit",
@@ -3940,6 +4361,36 @@ var VdFlowchart = class {
3940
4361
  "stroke-width": visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke
3941
4362
  });
3942
4363
  }
4364
+ renderLockBadge(node) {
4365
+ const scale = this.documentData.viewport.scale || 1;
4366
+ const badgeSize = 16 / scale;
4367
+ const offsetX = node.width - badgeSize / 2 - 4 / scale;
4368
+ const offsetY = badgeSize / 2 + 4 / scale;
4369
+ const badge = svgEl("g", {
4370
+ class: "vd-flowchart-node-lock",
4371
+ transform: `translate(${formatNumber(offsetX)} ${formatNumber(offsetY)})`,
4372
+ "data-node-id": node.id
4373
+ });
4374
+ const title = svgEl("title");
4375
+ title.textContent = "Locked node";
4376
+ badge.appendChild(title);
4377
+ badge.appendChild(
4378
+ svgEl("circle", {
4379
+ cx: 0,
4380
+ cy: 0,
4381
+ r: formatNumber(badgeSize / 2)
4382
+ })
4383
+ );
4384
+ const iconScale = badgeSize * 0.62 / 256;
4385
+ const iconOffset = -128 * iconScale;
4386
+ badge.appendChild(
4387
+ svgEl("path", {
4388
+ d: TOOLBAR_ICON_PATHS.lock,
4389
+ transform: `translate(${formatNumber(iconOffset)} ${formatNumber(iconOffset)}) scale(${formatScale(iconScale)})`
4390
+ })
4391
+ );
4392
+ return badge;
4393
+ }
3943
4394
  renderNode(node) {
3944
4395
  const selected = this.isNodeSelected(node.id);
3945
4396
  const soloSelected = selected && !this.hasMultiSelection();
@@ -3947,10 +4398,13 @@ var VdFlowchart = class {
3947
4398
  const resizing = this.interaction?.kind === "resize-node" && this.interaction.nodeId === node.id;
3948
4399
  const editing = this.textEditor?.nodeId === node.id;
3949
4400
  const group = svgEl("g", {
3950
- class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}`,
4401
+ class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}${node.locked ? " is-locked" : ""}`,
3951
4402
  transform: `translate(${formatNumber(node.x)} ${formatNumber(node.y)})`,
3952
4403
  "data-node-id": node.id
3953
4404
  });
4405
+ if (node.color) {
4406
+ group.setAttribute("data-color", node.color);
4407
+ }
3954
4408
  const portsVisible = this.shouldShowNodePorts(node);
3955
4409
  const visual = nodeVisualScale(node);
3956
4410
  const corner = node.type === "rounded-rect" || node.type === "textbox" ? 16 : node.type === "junction" ? node.width / 2 : 6;
@@ -3966,8 +4420,15 @@ var VdFlowchart = class {
3966
4420
  group.appendChild(hitbox);
3967
4421
  const shape = this.renderNodeShape(node);
3968
4422
  this.applyScaledNodeShape(node, shape);
4423
+ if (node.fill) shape.style.fill = node.fill;
4424
+ if (node.stroke) shape.style.stroke = node.stroke;
3969
4425
  group.appendChild(shape);
3970
- group.appendChild(this.renderNodeText(node));
4426
+ const textEl = this.renderNodeText(node);
4427
+ if (node.textColor) textEl.style.fill = node.textColor;
4428
+ group.appendChild(textEl);
4429
+ if (node.locked) {
4430
+ group.appendChild(this.renderLockBadge(node));
4431
+ }
3971
4432
  const scale = this.documentData.viewport.scale || 1;
3972
4433
  if (soloSelected && !this.readonly && SELECTION_BOX_TYPES.has(node.type)) {
3973
4434
  const outset = SELECTION_OUTSET / scale;
@@ -4287,6 +4748,127 @@ var VdFlowchart = class {
4287
4748
  });
4288
4749
  return textElement;
4289
4750
  }
4751
+ buildInspectorColorSwatches(activePreset = "default", disabled = this.readonly) {
4752
+ const normalizedActive = activePreset || "default";
4753
+ const grid = createElement("div", { className: "vd-flowchart-swatch-grid" });
4754
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
4755
+ const active = preset === normalizedActive;
4756
+ const button = createElement("button", {
4757
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}${active ? " is-active" : ""}`,
4758
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset,
4759
+ disabled
4760
+ });
4761
+ button.setAttribute("type", "button");
4762
+ button.setAttribute("data-color-preset", preset);
4763
+ button.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
4764
+ button.setAttribute("aria-pressed", active ? "true" : "false");
4765
+ grid.appendChild(button);
4766
+ });
4767
+ return grid;
4768
+ }
4769
+ buildInspectorArrangeRow(disabled = this.readonly) {
4770
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4771
+ const actions = [
4772
+ {
4773
+ action: "bring-to-front",
4774
+ label: "Front",
4775
+ title: "Bring to front (Cmd/Ctrl+Shift+])"
4776
+ },
4777
+ {
4778
+ action: "bring-forward",
4779
+ label: "Forward",
4780
+ title: "Bring forward (Cmd/Ctrl+])"
4781
+ },
4782
+ {
4783
+ action: "send-backward",
4784
+ label: "Backward",
4785
+ title: "Send backward (Cmd/Ctrl+[)"
4786
+ },
4787
+ {
4788
+ action: "send-to-back",
4789
+ label: "Back",
4790
+ title: "Send to back (Cmd/Ctrl+Shift+[)"
4791
+ }
4792
+ ];
4793
+ actions.forEach((item) => {
4794
+ const btn = createElement("button", {
4795
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4796
+ text: item.label,
4797
+ title: item.title,
4798
+ disabled
4799
+ });
4800
+ btn.setAttribute("type", "button");
4801
+ btn.setAttribute("data-arrange-action", item.action);
4802
+ grid.appendChild(btn);
4803
+ });
4804
+ return grid;
4805
+ }
4806
+ buildInspectorAlignRow(nodeCount, disabled = this.readonly) {
4807
+ const wrap = createElement("div", { className: "vd-flowchart-inspector-stack" });
4808
+ const alignGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4809
+ const alignments = [
4810
+ { action: "left", label: "Left", title: "Align left edges" },
4811
+ { action: "center", label: "Center", title: "Align horizontal centers" },
4812
+ { action: "right", label: "Right", title: "Align right edges" },
4813
+ { action: "top", label: "Top", title: "Align top edges" },
4814
+ { action: "middle", label: "Middle", title: "Align vertical centers" },
4815
+ { action: "bottom", label: "Bottom", title: "Align bottom edges" }
4816
+ ];
4817
+ alignments.forEach((item) => {
4818
+ const btn = createElement("button", {
4819
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4820
+ text: item.label,
4821
+ title: item.title,
4822
+ disabled: disabled || nodeCount < 2
4823
+ });
4824
+ btn.setAttribute("type", "button");
4825
+ btn.setAttribute("data-align-action", item.action);
4826
+ alignGrid.appendChild(btn);
4827
+ });
4828
+ wrap.appendChild(createField("Align", alignGrid));
4829
+ const distributeGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4830
+ [
4831
+ { action: "horizontal", label: "Distribute H", title: "Distribute horizontally" },
4832
+ { action: "vertical", label: "Distribute V", title: "Distribute vertically" }
4833
+ ].forEach((item) => {
4834
+ const btn = createElement("button", {
4835
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4836
+ text: item.label,
4837
+ title: item.title,
4838
+ disabled: disabled || nodeCount < 3
4839
+ });
4840
+ btn.setAttribute("type", "button");
4841
+ btn.setAttribute("data-distribute-action", item.action);
4842
+ distributeGrid.appendChild(btn);
4843
+ });
4844
+ wrap.appendChild(createField("Distribute", distributeGrid));
4845
+ return wrap;
4846
+ }
4847
+ buildInspectorUtilityRow({ showLock = true, locked = false, disabled = this.readonly } = {}) {
4848
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4849
+ if (showLock) {
4850
+ const lockBtn = createElement("button", {
4851
+ className: `vd-flowchart-btn vd-flowchart-action-btn${locked ? " is-active" : ""}`,
4852
+ text: locked ? "Unlock" : "Lock",
4853
+ title: "Toggle node lock (Cmd/Ctrl+L)",
4854
+ disabled
4855
+ });
4856
+ lockBtn.setAttribute("type", "button");
4857
+ lockBtn.setAttribute("data-lock-toggle", "");
4858
+ lockBtn.setAttribute("aria-pressed", locked ? "true" : "false");
4859
+ grid.appendChild(lockBtn);
4860
+ }
4861
+ const resetBtn = createElement("button", {
4862
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4863
+ text: "Reset color",
4864
+ title: "Reset to theme default color",
4865
+ disabled
4866
+ });
4867
+ resetBtn.setAttribute("type", "button");
4868
+ resetBtn.setAttribute("data-color-reset", "");
4869
+ grid.appendChild(resetBtn);
4870
+ return grid;
4871
+ }
4290
4872
  renderSelectionPanel() {
4291
4873
  clearChildren(this.selectionFields);
4292
4874
  this.deleteButton.disabled = this.readonly || !this.selection;
@@ -4301,6 +4883,11 @@ var VdFlowchart = class {
4301
4883
  return;
4302
4884
  }
4303
4885
  if (this.hasMultiSelection()) {
4886
+ const selectedIds = this.getSelectedNodeIds();
4887
+ const selectedNodes = selectedIds.map((id) => this.findNode(id)).filter(Boolean);
4888
+ const allLocked = selectedNodes.length > 0 && selectedNodes.every((n) => n.locked);
4889
+ this.deleteButton.disabled = this.readonly || allLocked;
4890
+ const sharedColor = selectedNodes.length > 0 && selectedNodes.every((n) => (n.color || "default") === (selectedNodes[0].color || "default")) ? selectedNodes[0].color || "default" : "";
4304
4891
  this.selectionMeta.textContent = `${this.selectedNodeIds.size} nodes selected`;
4305
4892
  this.selectionFields.appendChild(
4306
4893
  createElement("p", {
@@ -4308,6 +4895,22 @@ var VdFlowchart = class {
4308
4895
  text: "Drag, nudge with Alt+Arrow, copy, duplicate, or delete them together."
4309
4896
  })
4310
4897
  );
4898
+ this.selectionFields.appendChild(
4899
+ createField("Color preset", this.buildInspectorColorSwatches(sharedColor, this.readonly))
4900
+ );
4901
+ this.selectionFields.appendChild(
4902
+ this.buildInspectorAlignRow(selectedNodes.length, this.readonly)
4903
+ );
4904
+ this.selectionFields.appendChild(
4905
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
4906
+ );
4907
+ this.selectionFields.appendChild(
4908
+ this.buildInspectorUtilityRow({
4909
+ showLock: true,
4910
+ locked: allLocked,
4911
+ disabled: this.readonly
4912
+ })
4913
+ );
4311
4914
  return;
4312
4915
  }
4313
4916
  if (this.selection.kind === "node") {
@@ -4317,8 +4920,10 @@ var VdFlowchart = class {
4317
4920
  this.renderSelectionPanel();
4318
4921
  return;
4319
4922
  }
4320
- this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}`;
4321
- const typeSelect = createElement("select");
4923
+ const isLocked = Boolean(node.locked);
4924
+ this.deleteButton.disabled = this.readonly || isLocked;
4925
+ this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}${isLocked ? " \xB7 locked" : ""}`;
4926
+ const typeSelect = createElement("select", { disabled: this.readonly || isLocked });
4322
4927
  typeSelect.setAttribute("data-field", "node-type");
4323
4928
  FLOWCHART_NODE_TYPES.forEach((type) => {
4324
4929
  const option = createElement("option", { value: type, text: type.replace("-", " ") });
@@ -4326,13 +4931,25 @@ var VdFlowchart = class {
4326
4931
  option.selected = type === node.type;
4327
4932
  typeSelect.appendChild(option);
4328
4933
  });
4329
- const textArea = createElement("textarea", { value: node.text, rows: 5 });
4934
+ const textArea = createElement("textarea", {
4935
+ value: node.text,
4936
+ rows: 5,
4937
+ disabled: this.readonly || isLocked
4938
+ });
4330
4939
  textArea.setAttribute("data-field", "node-text");
4331
- const widthInput = createElement("input", { value: node.width, type: "number" });
4940
+ const widthInput = createElement("input", {
4941
+ value: node.width,
4942
+ type: "number",
4943
+ disabled: this.readonly || isLocked
4944
+ });
4332
4945
  widthInput.setAttribute("data-field", "node-width");
4333
4946
  widthInput.setAttribute("min", String(this.minNodeSize));
4334
4947
  widthInput.setAttribute("max", String(this.maxNodeSize));
4335
- const heightInput = createElement("input", { value: node.height, type: "number" });
4948
+ const heightInput = createElement("input", {
4949
+ value: node.height,
4950
+ type: "number",
4951
+ disabled: this.readonly || isLocked
4952
+ });
4336
4953
  heightInput.setAttribute("data-field", "node-height");
4337
4954
  heightInput.setAttribute("min", String(this.minNodeSize));
4338
4955
  heightInput.setAttribute("max", String(this.maxNodeSize));
@@ -4353,6 +4970,48 @@ var VdFlowchart = class {
4353
4970
  })
4354
4971
  );
4355
4972
  }
4973
+ this.selectionFields.appendChild(
4974
+ createField(
4975
+ "Color preset",
4976
+ this.buildInspectorColorSwatches(node.color || "default", this.readonly || isLocked)
4977
+ )
4978
+ );
4979
+ const customColorsGrid = createElement("div", { className: "vd-flowchart-field-grid" });
4980
+ const fillInput = createElement("input", {
4981
+ value: node.fill || "",
4982
+ type: "text",
4983
+ disabled: this.readonly || isLocked
4984
+ });
4985
+ fillInput.setAttribute("data-field", "node-fill");
4986
+ fillInput.setAttribute("placeholder", "Fill (e.g. #dbeafe)");
4987
+ const strokeInput = createElement("input", {
4988
+ value: node.stroke || "",
4989
+ type: "text",
4990
+ disabled: this.readonly || isLocked
4991
+ });
4992
+ strokeInput.setAttribute("data-field", "node-stroke");
4993
+ strokeInput.setAttribute("placeholder", "Stroke (e.g. #2563eb)");
4994
+ const textColorInput = createElement("input", {
4995
+ value: node.textColor || "",
4996
+ type: "text",
4997
+ disabled: this.readonly || isLocked
4998
+ });
4999
+ textColorInput.setAttribute("data-field", "node-text-color");
5000
+ textColorInput.setAttribute("placeholder", "Text (e.g. #1e3a8a)");
5001
+ customColorsGrid.appendChild(createField("Fill", fillInput));
5002
+ customColorsGrid.appendChild(createField("Border", strokeInput));
5003
+ this.selectionFields.appendChild(customColorsGrid);
5004
+ this.selectionFields.appendChild(createField("Text color", textColorInput));
5005
+ this.selectionFields.appendChild(
5006
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
5007
+ );
5008
+ this.selectionFields.appendChild(
5009
+ this.buildInspectorUtilityRow({
5010
+ showLock: true,
5011
+ locked: isLocked,
5012
+ disabled: this.readonly
5013
+ })
5014
+ );
4356
5015
  return;
4357
5016
  }
4358
5017
  const edge = this.findEdge(this.selection.id);
@@ -4361,8 +5020,9 @@ var VdFlowchart = class {
4361
5020
  this.renderSelectionPanel();
4362
5021
  return;
4363
5022
  }
5023
+ const edgeStyleName = normalizeEdgeStrokeStyle(edge.strokeStyle);
4364
5024
  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");
5025
+ const routeSelect = createElement("select", { disabled: this.readonly });
4366
5026
  routeSelect.setAttribute("data-field", "edge-route");
4367
5027
  FLOWCHART_EDGE_ROUTES.forEach((route) => {
4368
5028
  const option = createElement("option", {
@@ -4373,7 +5033,7 @@ var VdFlowchart = class {
4373
5033
  option.selected = route === edge.route;
4374
5034
  routeSelect.appendChild(option);
4375
5035
  });
4376
- const startSelect = createElement("select");
5036
+ const startSelect = createElement("select", { disabled: this.readonly });
4377
5037
  startSelect.setAttribute("data-field", "edge-start-marker");
4378
5038
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4379
5039
  const option = createElement("option", { value: marker, text: marker });
@@ -4381,7 +5041,7 @@ var VdFlowchart = class {
4381
5041
  option.selected = marker === edge.startMarker;
4382
5042
  startSelect.appendChild(option);
4383
5043
  });
4384
- const endSelect = createElement("select");
5044
+ const endSelect = createElement("select", { disabled: this.readonly });
4385
5045
  endSelect.setAttribute("data-field", "edge-end-marker");
4386
5046
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4387
5047
  const option = createElement("option", { value: marker, text: marker });
@@ -4389,7 +5049,7 @@ var VdFlowchart = class {
4389
5049
  option.selected = marker === edge.endMarker;
4390
5050
  endSelect.appendChild(option);
4391
5051
  });
4392
- const widthSelect = createElement("select");
5052
+ const widthSelect = createElement("select", { disabled: this.readonly });
4393
5053
  widthSelect.setAttribute("data-field", "edge-stroke-preset");
4394
5054
  EDGE_STROKE_PRESETS.forEach((preset) => {
4395
5055
  const option = createElement("option", { value: preset.id, text: preset.label });
@@ -4397,15 +5057,52 @@ var VdFlowchart = class {
4397
5057
  option.selected = preset.id === getStrokePresetId(edge.strokeWidth);
4398
5058
  widthSelect.appendChild(option);
4399
5059
  });
4400
- const labelInput = createElement("textarea", { value: edge.label, rows: 4 });
5060
+ const strokeStyleSelect = createElement("select", { disabled: this.readonly });
5061
+ strokeStyleSelect.setAttribute("data-field", "edge-stroke-style");
5062
+ FLOWCHART_EDGE_STROKE_STYLES.forEach((style) => {
5063
+ const option = createElement("option", {
5064
+ value: style,
5065
+ text: FLOWCHART_EDGE_STROKE_STYLE_LABELS[style] || style
5066
+ });
5067
+ option.value = style;
5068
+ option.selected = style === edgeStyleName;
5069
+ strokeStyleSelect.appendChild(option);
5070
+ });
5071
+ const labelInput = createElement("textarea", {
5072
+ value: edge.label,
5073
+ rows: 4,
5074
+ disabled: this.readonly
5075
+ });
4401
5076
  labelInput.setAttribute("data-field", "edge-label");
4402
5077
  const markerGrid = createElement("div", { className: "vd-flowchart-field-grid" });
4403
5078
  markerGrid.appendChild(createField("Route", routeSelect));
4404
5079
  markerGrid.appendChild(createField("Weight", widthSelect));
5080
+ markerGrid.appendChild(createField("Style", strokeStyleSelect));
4405
5081
  markerGrid.appendChild(createField("Start", startSelect));
4406
5082
  markerGrid.appendChild(createField("End", endSelect));
4407
5083
  this.selectionFields.appendChild(markerGrid);
4408
5084
  this.selectionFields.appendChild(createField("Label", labelInput));
5085
+ const activeEdgePreset = edge.color && FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "default";
5086
+ this.selectionFields.appendChild(
5087
+ createField(
5088
+ "Color preset",
5089
+ this.buildInspectorColorSwatches(activeEdgePreset, this.readonly)
5090
+ )
5091
+ );
5092
+ const edgeColorInput = createElement("input", {
5093
+ value: edge.color && !FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "",
5094
+ type: "text",
5095
+ disabled: this.readonly
5096
+ });
5097
+ edgeColorInput.setAttribute("data-field", "edge-color");
5098
+ edgeColorInput.setAttribute("placeholder", "Custom color (e.g. #2563eb)");
5099
+ this.selectionFields.appendChild(createField("Custom color", edgeColorInput));
5100
+ this.selectionFields.appendChild(
5101
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
5102
+ );
5103
+ this.selectionFields.appendChild(
5104
+ this.buildInspectorUtilityRow({ showLock: false, disabled: this.readonly })
5105
+ );
4409
5106
  }
4410
5107
  syncJsonTextarea(force = false) {
4411
5108
  if (!force && document.activeElement === this.jsonTextarea) {
@@ -4811,7 +5508,14 @@ var VdFlowchart = class {
4811
5508
  // the parent's box shape, falling back to a rounded step.
4812
5509
  getBranchTemplate(parent, sibling) {
4813
5510
  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 };
5511
+ if (source) {
5512
+ const template = { type: source.type, width: source.width, height: source.height };
5513
+ if (source.color) template.color = source.color;
5514
+ if (source.fill) template.fill = source.fill;
5515
+ if (source.stroke) template.stroke = source.stroke;
5516
+ if (source.textColor) template.textColor = source.textColor;
5517
+ return template;
5518
+ }
4815
5519
  const spec = DEFAULT_NODE_SPECS["rounded-rect"];
4816
5520
  return { type: "rounded-rect", width: spec.width, height: spec.height };
4817
5521
  }
@@ -4847,7 +5551,9 @@ var VdFlowchart = class {
4847
5551
  route: styleSource.route,
4848
5552
  strokeWidth: styleSource.strokeWidth,
4849
5553
  startMarker: styleSource.startMarker,
4850
- endMarker: styleSource.endMarker
5554
+ endMarker: styleSource.endMarker,
5555
+ ...styleSource.color ? { color: styleSource.color } : {},
5556
+ ...styleSource.strokeStyle ? { strokeStyle: styleSource.strokeStyle } : {}
4851
5557
  } : { endMarker: "arrow" };
4852
5558
  const result = this.batchHistory("node:insert", () => {
4853
5559
  if (parent.collapsed) delete parent.collapsed;
@@ -5065,6 +5771,30 @@ var VdFlowchart = class {
5065
5771
  node.text = isNodeTextEditable(nextType) ? patch.text == null ? node.text : String(patch.text) : getNodeSpec(nextType).text;
5066
5772
  node.width = clampNodeWidth(nextType, patch.width, node.width, this.nodeSizeBounds());
5067
5773
  node.height = clampNodeHeight(nextType, patch.height, node.height, this.nodeSizeBounds());
5774
+ if ("color" in patch) {
5775
+ const nextColor = normalizeColorPreset(patch.color);
5776
+ if (nextColor) node.color = nextColor;
5777
+ else delete node.color;
5778
+ }
5779
+ if ("fill" in patch) {
5780
+ const nextFill = sanitizeCssColor(patch.fill);
5781
+ if (nextFill) node.fill = nextFill;
5782
+ else delete node.fill;
5783
+ }
5784
+ if ("stroke" in patch) {
5785
+ const nextStroke = sanitizeCssColor(patch.stroke);
5786
+ if (nextStroke) node.stroke = nextStroke;
5787
+ else delete node.stroke;
5788
+ }
5789
+ if ("textColor" in patch) {
5790
+ const nextTextColor = sanitizeCssColor(patch.textColor);
5791
+ if (nextTextColor) node.textColor = nextTextColor;
5792
+ else delete node.textColor;
5793
+ }
5794
+ if ("locked" in patch) {
5795
+ if (patch.locked) node.locked = true;
5796
+ else delete node.locked;
5797
+ }
5068
5798
  if (isPlainObject(patch.data)) {
5069
5799
  node.data = deepClone(patch.data);
5070
5800
  }
@@ -5072,6 +5802,11 @@ var VdFlowchart = class {
5072
5802
  updateNode(nodeId, patch = {}, options = {}) {
5073
5803
  const node = this.findNode(nodeId);
5074
5804
  if (!node) return null;
5805
+ if (node.locked) {
5806
+ const keys = Object.keys(patch);
5807
+ const unlocking = keys.length > 0 && keys.every((key) => key === "locked") && !patch.locked;
5808
+ if (!unlocking) return null;
5809
+ }
5075
5810
  const previousType = node.type;
5076
5811
  const previousSpec = DEFAULT_NODE_SPECS[previousType];
5077
5812
  this.applyNodePatch(node, patch);
@@ -5176,6 +5911,16 @@ var VdFlowchart = class {
5176
5911
  if (patch.label != null) {
5177
5912
  edge.label = String(patch.label);
5178
5913
  }
5914
+ if ("color" in patch) {
5915
+ const nextColor = normalizeEdgeColor(patch.color);
5916
+ if (nextColor) edge.color = nextColor;
5917
+ else delete edge.color;
5918
+ }
5919
+ if ("strokeStyle" in patch) {
5920
+ const nextStrokeStyle = normalizeEdgeStrokeStyle(patch.strokeStyle);
5921
+ if (nextStrokeStyle && nextStrokeStyle !== "solid") edge.strokeStyle = nextStrokeStyle;
5922
+ else delete edge.strokeStyle;
5923
+ }
5179
5924
  if (isPlainObject(patch.data)) {
5180
5925
  edge.data = deepClone(patch.data);
5181
5926
  }
@@ -5248,11 +5993,461 @@ var VdFlowchart = class {
5248
5993
  deleteSelection() {
5249
5994
  if (!this.selection || this.readonly) return false;
5250
5995
  if (this.hasMultiSelection()) {
5251
- return this.removeNodeIds(new Set(this.getSelectedNodeIds()), "node:remove");
5996
+ const unlockedIds = this.getSelectedNodeIds().filter((id) => !this.findNode(id)?.locked);
5997
+ if (!unlockedIds.length) return false;
5998
+ return this.removeNodeIds(new Set(unlockedIds), "node:remove");
5999
+ }
6000
+ if (this.selection.kind === "node") {
6001
+ const node = this.findNode(this.selection.id);
6002
+ if (node?.locked) return false;
6003
+ return this.removeNode(this.selection.id);
5252
6004
  }
5253
- if (this.selection.kind === "node") return this.removeNode(this.selection.id);
5254
6005
  return this.removeEdge(this.selection.id);
5255
6006
  }
6007
+ // --- Coloring, Layer Order, Align/Distribute, Locking, SVG Export ---------
6008
+ setNodeColor(nodeId, colorOrPatch) {
6009
+ if (this.readonly) return null;
6010
+ const id = sanitizeId(nodeId);
6011
+ if (!this.findNode(id)) return null;
6012
+ let patch;
6013
+ if (isPlainObject(colorOrPatch)) {
6014
+ patch = {};
6015
+ if ("color" in colorOrPatch) patch.color = colorOrPatch.color;
6016
+ if ("fill" in colorOrPatch) patch.fill = colorOrPatch.fill;
6017
+ if ("stroke" in colorOrPatch) patch.stroke = colorOrPatch.stroke;
6018
+ if ("textColor" in colorOrPatch) patch.textColor = colorOrPatch.textColor;
6019
+ } else if (colorOrPatch == null || colorOrPatch === "" || colorOrPatch === "default") {
6020
+ patch = { color: null, fill: null, stroke: null, textColor: null };
6021
+ } else {
6022
+ const token = String(colorOrPatch).trim();
6023
+ if (FLOWCHART_COLOR_PRESET_SET.has(token)) {
6024
+ patch = { color: token, fill: null, stroke: null, textColor: null };
6025
+ } else {
6026
+ const css = sanitizeCssColor(token);
6027
+ if (!css) return null;
6028
+ patch = { fill: css };
6029
+ }
6030
+ }
6031
+ return this.updateNode(id, patch, { reason: "node:color" });
6032
+ }
6033
+ setEdgeColor(edgeId, color) {
6034
+ if (this.readonly) return null;
6035
+ const id = sanitizeId(edgeId);
6036
+ if (!this.findEdge(id)) return null;
6037
+ const nextColor = color == null || color === "" || color === "default" ? null : isPlainObject(color) ? normalizeEdgeColor(color.color ?? color.stroke) : normalizeEdgeColor(color);
6038
+ return this.updateEdge(id, { color: nextColor }, { reason: "edge:color" });
6039
+ }
6040
+ setSelectionColor(colorOrPatch) {
6041
+ if (this.readonly || !this.selection) return this;
6042
+ if (this.selection.kind === "edge") {
6043
+ this.setEdgeColor(this.selection.id, colorOrPatch);
6044
+ return this;
6045
+ }
6046
+ const ids = this.getSelectedNodeIds();
6047
+ if (!ids.length) return this;
6048
+ this.batchHistory("node:color", () => {
6049
+ ids.forEach((id) => {
6050
+ this.setNodeColor(id, colorOrPatch);
6051
+ });
6052
+ });
6053
+ return this;
6054
+ }
6055
+ clearSelectionColor() {
6056
+ return this.setSelectionColor(null);
6057
+ }
6058
+ reorderArrayLayer(items, targetIds, direction) {
6059
+ const idSet = new Set(targetIds);
6060
+ if (!idSet.size || items.length < 2) return null;
6061
+ let next;
6062
+ if (direction === "front") {
6063
+ next = [
6064
+ ...items.filter((item) => !idSet.has(item.id)),
6065
+ ...items.filter((item) => idSet.has(item.id))
6066
+ ];
6067
+ } else if (direction === "back") {
6068
+ next = [
6069
+ ...items.filter((item) => idSet.has(item.id)),
6070
+ ...items.filter((item) => !idSet.has(item.id))
6071
+ ];
6072
+ } else if (direction === "forward") {
6073
+ next = [...items];
6074
+ for (let i = next.length - 2; i >= 0; i -= 1) {
6075
+ if (idSet.has(next[i].id) && !idSet.has(next[i + 1].id)) {
6076
+ const temp = next[i];
6077
+ next[i] = next[i + 1];
6078
+ next[i + 1] = temp;
6079
+ }
6080
+ }
6081
+ } else if (direction === "backward") {
6082
+ next = [...items];
6083
+ for (let i = 1; i < next.length; i += 1) {
6084
+ if (idSet.has(next[i].id) && !idSet.has(next[i - 1].id)) {
6085
+ const temp = next[i];
6086
+ next[i] = next[i - 1];
6087
+ next[i - 1] = temp;
6088
+ }
6089
+ }
6090
+ } else {
6091
+ return null;
6092
+ }
6093
+ const changed = next.some((item, index) => item.id !== items[index].id);
6094
+ return changed ? next : null;
6095
+ }
6096
+ reorderLayer(direction, targetId) {
6097
+ if (this.readonly) return this;
6098
+ let explicitIds = [];
6099
+ if (Array.isArray(targetId)) {
6100
+ explicitIds = targetId.map(sanitizeId).filter(Boolean);
6101
+ } else if (typeof targetId === "string" && targetId.trim()) {
6102
+ explicitIds = [sanitizeId(targetId)];
6103
+ }
6104
+ if (explicitIds.length) {
6105
+ const nodeIdSet = new Set(this.documentData.nodes.map((n) => n.id));
6106
+ const matchingNodes = explicitIds.filter((id) => nodeIdSet.has(id));
6107
+ if (matchingNodes.length) {
6108
+ const reordered2 = this.reorderArrayLayer(this.documentData.nodes, matchingNodes, direction);
6109
+ if (reordered2) {
6110
+ this.documentData.nodes = reordered2;
6111
+ this.render();
6112
+ this.emitChange("node:order", { direction, nodeIds: matchingNodes });
6113
+ }
6114
+ return this;
6115
+ }
6116
+ const edgeIdSet = new Set(this.documentData.edges.map((e) => e.id));
6117
+ const matchingEdges = explicitIds.filter((id) => edgeIdSet.has(id));
6118
+ if (matchingEdges.length) {
6119
+ const reordered2 = this.reorderArrayLayer(this.documentData.edges, matchingEdges, direction);
6120
+ if (reordered2) {
6121
+ this.documentData.edges = reordered2;
6122
+ this.render();
6123
+ this.emitChange("edge:order", { direction, edgeIds: matchingEdges });
6124
+ }
6125
+ }
6126
+ return this;
6127
+ }
6128
+ if (!this.selection) return this;
6129
+ if (this.selection.kind === "edge") {
6130
+ const reordered2 = this.reorderArrayLayer(
6131
+ this.documentData.edges,
6132
+ [this.selection.id],
6133
+ direction
6134
+ );
6135
+ if (reordered2) {
6136
+ this.documentData.edges = reordered2;
6137
+ this.render();
6138
+ this.emitChange("edge:order", { direction, edgeIds: [this.selection.id] });
6139
+ }
6140
+ return this;
6141
+ }
6142
+ const ids = this.getSelectedNodeIds();
6143
+ const reordered = this.reorderArrayLayer(this.documentData.nodes, ids, direction);
6144
+ if (reordered) {
6145
+ this.documentData.nodes = reordered;
6146
+ this.render();
6147
+ this.emitChange("node:order", { direction, nodeIds: ids });
6148
+ }
6149
+ return this;
6150
+ }
6151
+ bringToFront(targetId) {
6152
+ return this.reorderLayer("front", targetId);
6153
+ }
6154
+ bringForward(targetId) {
6155
+ return this.reorderLayer("forward", targetId);
6156
+ }
6157
+ sendBackward(targetId) {
6158
+ return this.reorderLayer("backward", targetId);
6159
+ }
6160
+ sendToBack(targetId) {
6161
+ return this.reorderLayer("back", targetId);
6162
+ }
6163
+ alignNodes(alignment = "left", nodeIds) {
6164
+ if (this.readonly || !FLOWCHART_NODE_ALIGNMENTS.includes(alignment)) return this;
6165
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6166
+ const hidden = this.getHiddenNodeIds();
6167
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6168
+ if (nodes.length < 2) return this;
6169
+ const bounds = getBounds(nodes);
6170
+ const centerX = (bounds.left + bounds.right) / 2;
6171
+ const centerY = (bounds.top + bounds.bottom) / 2;
6172
+ const movedIds = [];
6173
+ nodes.forEach((node) => {
6174
+ if (node.locked) return;
6175
+ let nextX = node.x;
6176
+ let nextY = node.y;
6177
+ if (alignment === "left") nextX = formatNumber(bounds.left);
6178
+ else if (alignment === "center") nextX = formatNumber(centerX - node.width / 2);
6179
+ else if (alignment === "right") nextX = formatNumber(bounds.right - node.width);
6180
+ else if (alignment === "top") nextY = formatNumber(bounds.top);
6181
+ else if (alignment === "middle") nextY = formatNumber(centerY - node.height / 2);
6182
+ else if (alignment === "bottom") nextY = formatNumber(bounds.bottom - node.height);
6183
+ if (nextX !== node.x || nextY !== node.y) {
6184
+ node.x = nextX;
6185
+ node.y = nextY;
6186
+ movedIds.push(node.id);
6187
+ }
6188
+ });
6189
+ if (movedIds.length) {
6190
+ this.render();
6191
+ this.emitChange("node:align", { alignment, nodeIds: movedIds });
6192
+ }
6193
+ return this;
6194
+ }
6195
+ distributeNodes(axis = "horizontal", nodeIds) {
6196
+ if (this.readonly || !FLOWCHART_DISTRIBUTE_AXES.includes(axis)) return this;
6197
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6198
+ const hidden = this.getHiddenNodeIds();
6199
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6200
+ if (nodes.length < 3) return this;
6201
+ const sorted = [...nodes].sort(
6202
+ (a, b) => axis === "horizontal" ? a.x + a.width / 2 - (b.x + b.width / 2) : a.y + a.height / 2 - (b.y + b.height / 2)
6203
+ );
6204
+ const first = sorted[0];
6205
+ const last = sorted[sorted.length - 1];
6206
+ const movedIds = [];
6207
+ if (axis === "horizontal") {
6208
+ const totalSpan = last.x + last.width - first.x;
6209
+ const totalSize = sorted.reduce((sum, node) => sum + node.width, 0);
6210
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6211
+ let cursor = first.x;
6212
+ sorted.forEach((node, index) => {
6213
+ if (index > 0 && index < sorted.length - 1) {
6214
+ if (node.locked) {
6215
+ cursor = node.x + node.width + gap;
6216
+ return;
6217
+ }
6218
+ const nextX = formatNumber(cursor);
6219
+ if (nextX !== node.x) {
6220
+ node.x = nextX;
6221
+ movedIds.push(node.id);
6222
+ }
6223
+ }
6224
+ cursor += node.width + gap;
6225
+ });
6226
+ } else {
6227
+ const totalSpan = last.y + last.height - first.y;
6228
+ const totalSize = sorted.reduce((sum, node) => sum + node.height, 0);
6229
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6230
+ let cursor = first.y;
6231
+ sorted.forEach((node, index) => {
6232
+ if (index > 0 && index < sorted.length - 1) {
6233
+ if (node.locked) {
6234
+ cursor = node.y + node.height + gap;
6235
+ return;
6236
+ }
6237
+ const nextY = formatNumber(cursor);
6238
+ if (nextY !== node.y) {
6239
+ node.y = nextY;
6240
+ movedIds.push(node.id);
6241
+ }
6242
+ }
6243
+ cursor += node.height + gap;
6244
+ });
6245
+ }
6246
+ if (movedIds.length) {
6247
+ this.render();
6248
+ this.emitChange("node:distribute", { axis, nodeIds: movedIds });
6249
+ }
6250
+ return this;
6251
+ }
6252
+ setNodeLocked(nodeId, locked = true) {
6253
+ if (this.readonly) return false;
6254
+ let targetIds;
6255
+ let nextLocked = Boolean(locked);
6256
+ if (typeof nodeId === "boolean") {
6257
+ nextLocked = nodeId;
6258
+ targetIds = this.getSelectedNodeIds();
6259
+ } else if (Array.isArray(nodeId)) {
6260
+ targetIds = nodeId.map(sanitizeId).filter(Boolean);
6261
+ } else if (nodeId == null) {
6262
+ targetIds = this.getSelectedNodeIds();
6263
+ } else {
6264
+ targetIds = [sanitizeId(nodeId)];
6265
+ }
6266
+ const changedNodes = [];
6267
+ targetIds.forEach((id) => {
6268
+ const node = this.findNode(id);
6269
+ if (!node || Boolean(node.locked) === nextLocked) return;
6270
+ if (nextLocked) node.locked = true;
6271
+ else delete node.locked;
6272
+ changedNodes.push(deepClone(node));
6273
+ });
6274
+ if (!changedNodes.length) return false;
6275
+ if (nextLocked && this.textEditor && targetIds.includes(this.textEditor.nodeId)) {
6276
+ this.stopTextEdit({ commit: true });
6277
+ }
6278
+ this.render();
6279
+ this.emitChange("node:lock", {
6280
+ node: changedNodes[0],
6281
+ nodes: changedNodes,
6282
+ locked: nextLocked
6283
+ });
6284
+ return true;
6285
+ }
6286
+ toggleNodeLocked(nodeId) {
6287
+ if (this.readonly) return false;
6288
+ if (nodeId != null && typeof nodeId !== "boolean" && !Array.isArray(nodeId)) {
6289
+ const node = this.findNode(sanitizeId(nodeId));
6290
+ return node ? this.setNodeLocked(node.id, !node.locked) : false;
6291
+ }
6292
+ const ids = Array.isArray(nodeId) ? nodeId.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6293
+ const nodes = ids.map((id) => this.findNode(id)).filter(Boolean);
6294
+ if (!nodes.length) return false;
6295
+ const shouldLock = nodes.some((node) => !node.locked);
6296
+ return this.setNodeLocked(ids, shouldLock);
6297
+ }
6298
+ exportSvg(options = {}) {
6299
+ const padding = Math.max(0, toFiniteNumber(options.padding, 32));
6300
+ const visibleNodes = this.getVisibleNodes();
6301
+ let viewX = 0;
6302
+ let viewY = 0;
6303
+ let viewWidth = 800;
6304
+ let viewHeight = 560;
6305
+ if (visibleNodes.length) {
6306
+ const bounds = getBounds(visibleNodes);
6307
+ viewX = formatNumber(bounds.left - padding);
6308
+ viewY = formatNumber(bounds.top - padding);
6309
+ viewWidth = formatNumber(Math.max(1, bounds.right - bounds.left + padding * 2));
6310
+ viewHeight = formatNumber(Math.max(1, bounds.bottom - bounds.top + padding * 2));
6311
+ }
6312
+ const exportRoot = svgEl("svg", {
6313
+ xmlns: SVG_NS,
6314
+ viewBox: `${viewX} ${viewY} ${viewWidth} ${viewHeight}`,
6315
+ width: viewWidth,
6316
+ height: viewHeight,
6317
+ class: "vd-flowchart-export"
6318
+ });
6319
+ const isDarkTheme = (() => {
6320
+ const explicitTheme = this.element?.closest?.("[data-theme]")?.getAttribute("data-theme") || document.documentElement?.getAttribute("data-theme");
6321
+ if (explicitTheme === "dark") return true;
6322
+ if (explicitTheme === "light") return false;
6323
+ return Boolean(window.matchMedia?.("(prefers-color-scheme: dark)")?.matches);
6324
+ })();
6325
+ const presetFallbacks = isDarkTheme ? FLOWCHART_COLOR_PRESET_DARK_FALLBACKS : FLOWCHART_COLOR_PRESET_FALLBACKS;
6326
+ const computedStyle = typeof window.getComputedStyle === "function" ? window.getComputedStyle(this.root || this.element) : null;
6327
+ const readCssVar = (name, fallback) => {
6328
+ const val = computedStyle?.getPropertyValue(name)?.trim();
6329
+ return val && !val.includes("var(") ? val : fallback;
6330
+ };
6331
+ const defaultSurface = readCssVar(
6332
+ "--vd-flowchart-surface",
6333
+ readCssVar("--vd-bg-primary", isDarkTheme ? "#0f172a" : "#ffffff")
6334
+ );
6335
+ const defaultNodeFill = readCssVar(
6336
+ "--vd-flowchart-node-fill",
6337
+ isDarkTheme ? "#1e293b" : "#ffffff"
6338
+ );
6339
+ const defaultNodeStroke = readCssVar(
6340
+ "--vd-flowchart-node-stroke",
6341
+ isDarkTheme ? "#94a3b8" : "#475569"
6342
+ );
6343
+ const defaultNodeText = readCssVar(
6344
+ "--vd-flowchart-node-text",
6345
+ isDarkTheme ? "#f1f5f9" : "#0f172a"
6346
+ );
6347
+ const defaultEdgeStroke = readCssVar(
6348
+ "--vd-flowchart-edge-stroke",
6349
+ isDarkTheme ? "#94a3b8" : "#475569"
6350
+ );
6351
+ const resolvePresetColor = (presetName, slot) => {
6352
+ const fallback = presetFallbacks[presetName]?.[slot];
6353
+ if (!fallback) return null;
6354
+ return readCssVar(`--vd-flowchart-palette-${presetName}-${slot}`, fallback);
6355
+ };
6356
+ const hasAnimatedEdge = this.documentData.edges.some((edge) => edge.strokeStyle === "animated");
6357
+ const styleEl = svgEl("style");
6358
+ const styleRules = [
6359
+ '.vd-flowchart-export { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }',
6360
+ `.vd-flowchart-node-shape { fill: ${defaultNodeFill}; stroke: ${defaultNodeStroke}; stroke-width: 2px; }`,
6361
+ ".vd-flowchart-node--textbox .vd-flowchart-node-shape { stroke-dasharray: 6 4; }",
6362
+ `.vd-flowchart-node--junction .vd-flowchart-node-shape { fill: #2563eb; stroke: ${defaultNodeFill}; }`,
6363
+ `.vd-flowchart-node-text { fill: ${defaultNodeText}; font-size: 14px; font-weight: 600; dominant-baseline: middle; text-anchor: middle; }`,
6364
+ `.vd-flowchart-edge-path { fill: none; stroke: ${defaultEdgeStroke}; stroke-linecap: round; stroke-linejoin: round; }`,
6365
+ `.vd-flowchart-edge-label { fill: ${defaultNodeText}; font-size: 12px; font-weight: 600; paint-order: stroke; stroke: ${defaultSurface}; stroke-width: 5px; }`
6366
+ ];
6367
+ if (hasAnimatedEdge) {
6368
+ styleRules.push(
6369
+ "@keyframes vd-flowchart-edge-flow { to { stroke-dashoffset: -26; } }",
6370
+ ".vd-flowchart-edge.is-stroke-animated .vd-flowchart-edge-path { animation: vd-flowchart-edge-flow 900ms linear infinite; }",
6371
+ "@media (prefers-reduced-motion: reduce) { .vd-flowchart-edge.is-stroke-animated .vd-flowchart-edge-path { animation: none; } }"
6372
+ );
6373
+ }
6374
+ styleEl.textContent = styleRules.join("\n");
6375
+ exportRoot.appendChild(styleEl);
6376
+ if (this.markerDefs) {
6377
+ const defsClone = this.markerDefs.cloneNode(true);
6378
+ defsClone.querySelectorAll("path, circle").forEach((shape) => {
6379
+ const fill = shape.getAttribute("fill") || "";
6380
+ const preset = fill.match(/--vd-flowchart-palette-([a-z]+)-edge/);
6381
+ if (preset) {
6382
+ const resolved = resolvePresetColor(preset[1], "edge");
6383
+ if (resolved) {
6384
+ shape.setAttribute("fill", resolved);
6385
+ return;
6386
+ }
6387
+ }
6388
+ if (fill.includes("var(")) shape.setAttribute("fill", defaultEdgeStroke);
6389
+ });
6390
+ exportRoot.appendChild(defsClone);
6391
+ }
6392
+ if (typeof options.background === "string" && options.background.trim() && options.background.trim() !== "transparent") {
6393
+ const bgColor = options.background.trim() === "theme" ? defaultSurface : sanitizeCssColor(options.background.trim()) || defaultSurface;
6394
+ exportRoot.appendChild(
6395
+ svgEl("rect", {
6396
+ x: viewX,
6397
+ y: viewY,
6398
+ width: viewWidth,
6399
+ height: viewHeight,
6400
+ fill: bgColor
6401
+ })
6402
+ );
6403
+ }
6404
+ const sceneGroup = svgEl("g", { class: "vd-flowchart-export-scene" });
6405
+ const edgesClone = this.edgesLayer.cloneNode(true);
6406
+ edgesClone.querySelectorAll(".vd-flowchart-edge-hit, .vd-flowchart-edge-selection").forEach((el) => el.remove());
6407
+ edgesClone.querySelectorAll(".vd-flowchart-edge").forEach((edgeGroup) => {
6408
+ edgeGroup.classList.remove("is-selected", "is-reconnecting");
6409
+ const edgeId = edgeGroup.getAttribute("data-edge-id");
6410
+ const edge = this.findEdge(edgeId);
6411
+ const pathEl = edgeGroup.querySelector(".vd-flowchart-edge-path");
6412
+ if (edge && pathEl) {
6413
+ const stroke = edge.color ? resolvePresetColor(edge.color, "edge") || edge.color : defaultEdgeStroke;
6414
+ pathEl.setAttribute("stroke", stroke);
6415
+ pathEl.style.stroke = stroke;
6416
+ }
6417
+ });
6418
+ const nodesClone = this.nodesLayer.cloneNode(true);
6419
+ nodesClone.querySelectorAll(
6420
+ ".vd-flowchart-ports, .vd-flowchart-resize-handles, .vd-flowchart-node-lock, .vd-flowchart-collapse-badge, .vd-flowchart-selection-box"
6421
+ ).forEach((el) => el.remove());
6422
+ nodesClone.querySelectorAll(".vd-flowchart-node").forEach((nodeGroup) => {
6423
+ nodeGroup.classList.remove("is-selected", "is-multi-selected", "is-dragging");
6424
+ const nodeId = nodeGroup.getAttribute("data-node-id");
6425
+ const node = this.findNode(nodeId);
6426
+ if (!node) return;
6427
+ const shapeEl = nodeGroup.querySelector(".vd-flowchart-node-shape");
6428
+ const labelEl = nodeGroup.querySelector(".vd-flowchart-node-text");
6429
+ const presetFill = node.color ? resolvePresetColor(node.color, "fill") : null;
6430
+ const presetStroke = node.color ? resolvePresetColor(node.color, "stroke") : null;
6431
+ const presetText = node.color ? resolvePresetColor(node.color, "text") : null;
6432
+ if (shapeEl) {
6433
+ const fill = node.fill || presetFill || (node.type === "junction" ? "#2563eb" : defaultNodeFill);
6434
+ const stroke = node.stroke || presetStroke || (node.type === "junction" ? defaultNodeFill : defaultNodeStroke);
6435
+ shapeEl.setAttribute("fill", fill);
6436
+ shapeEl.setAttribute("stroke", stroke);
6437
+ shapeEl.style.fill = fill;
6438
+ shapeEl.style.stroke = stroke;
6439
+ }
6440
+ if (labelEl) {
6441
+ const textColor = node.textColor || presetText || defaultNodeText;
6442
+ labelEl.setAttribute("fill", textColor);
6443
+ labelEl.style.fill = textColor;
6444
+ }
6445
+ });
6446
+ sceneGroup.appendChild(edgesClone);
6447
+ sceneGroup.appendChild(nodesClone);
6448
+ exportRoot.appendChild(sceneGroup);
6449
+ return exportRoot.outerHTML;
6450
+ }
5256
6451
  nodeSizeBounds() {
5257
6452
  return { min: this.minNodeSize, max: this.maxNodeSize };
5258
6453
  }
@@ -5393,13 +6588,45 @@ var VdFlowchart = class {
5393
6588
  if ("readonly" in options) {
5394
6589
  if (options.readonly && !this.readonly) {
5395
6590
  this.stopTextEdit({ commit: true });
5396
- this.interaction = null;
6591
+ if (this.interaction) {
6592
+ const active = this.interaction;
6593
+ if (active.kind === "drag-node" && active.origins) {
6594
+ active.origins.forEach((origin, id) => {
6595
+ const node = this.findNode(id);
6596
+ if (node) {
6597
+ node.x = origin.x;
6598
+ node.y = origin.y;
6599
+ }
6600
+ });
6601
+ } else if (active.kind === "resize-node" && active.original) {
6602
+ const node = this.findNode(active.nodeId);
6603
+ if (node) {
6604
+ node.x = active.original.x;
6605
+ node.y = active.original.y;
6606
+ node.width = active.original.width;
6607
+ node.height = active.original.height;
6608
+ }
6609
+ }
6610
+ if (active.pointerId != null && typeof this.canvasEl?.releasePointerCapture === "function") {
6611
+ try {
6612
+ this.canvasEl.releasePointerCapture(active.pointerId);
6613
+ } catch {
6614
+ }
6615
+ }
6616
+ this.renderGuides([]);
6617
+ this.interaction = null;
6618
+ this.render({ inspector: false, json: false });
6619
+ }
5397
6620
  this.activeTool = null;
5398
6621
  this.reconnectEdgeId = null;
5399
6622
  }
5400
6623
  this.readonly = Boolean(options.readonly);
6624
+ if (this.readonly && this.colorPopoverOpen) {
6625
+ this.toggleColorPopover(false);
6626
+ }
5401
6627
  this.root.classList.toggle("vd-flowchart-readonly", this.readonly);
5402
6628
  this.arrangeSelect.disabled = this.readonly;
6629
+ if (this.colorButton) this.colorButton.disabled = this.readonly;
5403
6630
  this.clearButton.disabled = this.readonly;
5404
6631
  this.loadJsonButton.disabled = this.readonly;
5405
6632
  }
@@ -5502,6 +6729,14 @@ var VdFlowchart = class {
5502
6729
  cancelAnimationFrame(this.minimapFrame);
5503
6730
  }
5504
6731
  this.minimapFrame = 0;
6732
+ if (this.readyFrame) {
6733
+ if (this.readyFrameIsTimeout) {
6734
+ clearTimeout(this.readyFrame);
6735
+ } else if (typeof cancelAnimationFrame === "function") {
6736
+ cancelAnimationFrame(this.readyFrame);
6737
+ }
6738
+ this.readyFrame = 0;
6739
+ }
5505
6740
  this.activeTool = null;
5506
6741
  this.stopTextEdit({ commit: false });
5507
6742
  this.resizeObserver?.disconnect();
@@ -5517,7 +6752,7 @@ var VdFlowchart = class {
5517
6752
  };
5518
6753
 
5519
6754
  // src/vue.js
5520
- var FORWARDED_EVENTS = ["change", "select", "viewport", "connect", "ready"];
6755
+ var FORWARDED_EVENTS = ["change", "select", "viewport", "connect", "ready", "history"];
5521
6756
  var EDITOR_OPTION_KEYS = [
5522
6757
  "readonly",
5523
6758
  "gridSize",
@@ -5622,16 +6857,38 @@ var VdFlowchart2 = defineComponent({
5622
6857
  canUndo: () => Boolean(instance?.canUndo()),
5623
6858
  canRedo: () => Boolean(instance?.canRedo()),
5624
6859
  layout: (mode, options) => instance?.layout(mode, options),
5625
- fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding)
6860
+ fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding),
6861
+ setNodeColor: (nodeId, colorOrPatch) => instance?.setNodeColor(nodeId, colorOrPatch) ?? null,
6862
+ setEdgeColor: (edgeId, color) => instance?.setEdgeColor(edgeId, color) ?? null,
6863
+ setSelectionColor: (colorOrPatch) => instance?.setSelectionColor(colorOrPatch),
6864
+ clearSelectionColor: () => instance?.clearSelectionColor(),
6865
+ bringToFront: (targetId) => instance?.bringToFront(targetId),
6866
+ bringForward: (targetId) => instance?.bringForward(targetId),
6867
+ sendBackward: (targetId) => instance?.sendBackward(targetId),
6868
+ sendToBack: (targetId) => instance?.sendToBack(targetId),
6869
+ alignNodes: (alignment, nodeIds) => instance?.alignNodes(alignment, nodeIds),
6870
+ distributeNodes: (axis, nodeIds) => instance?.distributeNodes(axis, nodeIds),
6871
+ setNodeLocked: (nodeId, locked) => Boolean(instance?.setNodeLocked(nodeId, locked)),
6872
+ toggleNodeLocked: (nodeId) => Boolean(instance?.toggleNodeLocked(nodeId)),
6873
+ duplicateSelection: () => instance?.duplicateSelection() ?? null,
6874
+ copySelection: () => Boolean(instance?.copySelection()),
6875
+ pasteClipboard: () => Boolean(instance?.pasteClipboard()),
6876
+ pasteSelection: () => instance?.pasteSelection() ?? null,
6877
+ cutSelection: () => Boolean(instance?.cutSelection()),
6878
+ exportSvg: (options) => instance?.exportSvg(options) ?? ""
5626
6879
  });
5627
6880
  return () => h("div", { ref: el, class: "vd-flowchart" });
5628
6881
  }
5629
6882
  });
5630
6883
  export {
6884
+ FLOWCHART_COLOR_PRESETS,
6885
+ FLOWCHART_DISTRIBUTE_AXES,
5631
6886
  FLOWCHART_DOCUMENT_VERSION,
5632
6887
  FLOWCHART_EDGE_MARKERS,
5633
6888
  FLOWCHART_EDGE_ROUTES,
6889
+ FLOWCHART_EDGE_STROKE_STYLES,
5634
6890
  FLOWCHART_KEYBOARD_SHORTCUTS,
6891
+ FLOWCHART_NODE_ALIGNMENTS,
5635
6892
  FLOWCHART_NODE_TYPES,
5636
6893
  FLOWCHART_PORTS,
5637
6894
  LAYOUT_MODES,