@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.cjs CHANGED
@@ -20,10 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.js
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ FLOWCHART_COLOR_PRESETS: () => FLOWCHART_COLOR_PRESETS,
24
+ FLOWCHART_DISTRIBUTE_AXES: () => FLOWCHART_DISTRIBUTE_AXES,
23
25
  FLOWCHART_DOCUMENT_VERSION: () => FLOWCHART_DOCUMENT_VERSION,
24
26
  FLOWCHART_EDGE_MARKERS: () => FLOWCHART_EDGE_MARKERS,
25
27
  FLOWCHART_EDGE_ROUTES: () => FLOWCHART_EDGE_ROUTES,
28
+ FLOWCHART_EDGE_STROKE_STYLES: () => FLOWCHART_EDGE_STROKE_STYLES,
26
29
  FLOWCHART_KEYBOARD_SHORTCUTS: () => FLOWCHART_KEYBOARD_SHORTCUTS,
30
+ FLOWCHART_NODE_ALIGNMENTS: () => FLOWCHART_NODE_ALIGNMENTS,
27
31
  FLOWCHART_NODE_TYPES: () => FLOWCHART_NODE_TYPES,
28
32
  FLOWCHART_PORTS: () => FLOWCHART_PORTS,
29
33
  LAYOUT_MODES: () => LAYOUT_MODES,
@@ -483,6 +487,11 @@ var TOOLBAR_ICON_PATHS = {
483
487
  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",
484
488
  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",
485
489
  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",
490
+ 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",
491
+ "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",
492
+ "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",
493
+ 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",
494
+ 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",
486
495
  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"
487
496
  };
488
497
  var TOOLBAR_ACTIONS = [
@@ -559,7 +568,7 @@ var EDGE_STROKE_PRESETS = [
559
568
  { id: "medium", label: "Medium", width: DEFAULT_EDGE_STROKE_WIDTH },
560
569
  { id: "bold", label: "Bold", width: 3.5 }
561
570
  ];
562
- var VD_FLOWCHART_VERSION = "1.5.1";
571
+ var VD_FLOWCHART_VERSION = "1.6.1";
563
572
  var FLOWCHART_DOCUMENT_VERSION = "1.3.0";
564
573
  var FLOWCHART_NODE_TYPES = [
565
574
  "rounded-rect",
@@ -573,10 +582,105 @@ var FLOWCHART_NODE_TYPES = [
573
582
  var FLOWCHART_PORTS = ["top", "right", "bottom", "left"];
574
583
  var FLOWCHART_EDGE_MARKERS = ["none", "arrow", "dot"];
575
584
  var FLOWCHART_EDGE_ROUTES = ["curve", "straight", "orthogonal"];
585
+ var FLOWCHART_EDGE_STROKE_STYLES = ["solid", "dashed", "dotted", "animated"];
586
+ var FLOWCHART_COLOR_PRESETS = [
587
+ "default",
588
+ "primary",
589
+ "secondary",
590
+ "success",
591
+ "warning",
592
+ "danger",
593
+ "info",
594
+ "violet",
595
+ "teal",
596
+ "orange",
597
+ "pink",
598
+ "neutral"
599
+ ];
600
+ var FLOWCHART_NODE_ALIGNMENTS = ["left", "center", "right", "top", "middle", "bottom"];
601
+ var FLOWCHART_DISTRIBUTE_AXES = ["horizontal", "vertical"];
576
602
  var FLOWCHART_KEYBOARD_SHORTCUTS = ["mindmap", "basic"];
603
+ var FLOWCHART_COLOR_PRESET_LABELS = {
604
+ default: "Default",
605
+ primary: "Primary",
606
+ secondary: "Secondary",
607
+ success: "Success",
608
+ warning: "Warning",
609
+ danger: "Danger",
610
+ info: "Info",
611
+ violet: "Violet",
612
+ teal: "Teal",
613
+ orange: "Orange",
614
+ pink: "Pink",
615
+ neutral: "Neutral"
616
+ };
617
+ var FLOWCHART_COLOR_PRESET_SET = new Set(FLOWCHART_COLOR_PRESETS);
618
+ var FLOWCHART_COLOR_PRESET_FALLBACKS = {
619
+ primary: { fill: "#dbeafe", stroke: "#2563eb", text: "#1e3a8a", edge: "#2563eb" },
620
+ secondary: { fill: "#e0e7ff", stroke: "#4f46e5", text: "#312e81", edge: "#4f46e5" },
621
+ success: { fill: "#dcfce7", stroke: "#16a34a", text: "#14532d", edge: "#16a34a" },
622
+ warning: { fill: "#fef3c7", stroke: "#d97706", text: "#78350f", edge: "#d97706" },
623
+ danger: { fill: "#fee2e2", stroke: "#dc2626", text: "#7f1d1d", edge: "#dc2626" },
624
+ info: { fill: "#e0f2fe", stroke: "#0284c7", text: "#0c4a6e", edge: "#0284c7" },
625
+ violet: { fill: "#f3e8ff", stroke: "#9333ea", text: "#581c87", edge: "#9333ea" },
626
+ teal: { fill: "#ccfbf1", stroke: "#0d9488", text: "#134e4a", edge: "#0d9488" },
627
+ orange: { fill: "#ffedd5", stroke: "#ea580c", text: "#7c2d12", edge: "#ea580c" },
628
+ pink: { fill: "#fce7f3", stroke: "#db2777", text: "#831843", edge: "#db2777" },
629
+ neutral: { fill: "#f1f5f9", stroke: "#64748b", text: "#1e293b", edge: "#64748b" }
630
+ };
631
+ var FLOWCHART_COLOR_PRESET_DARK_FALLBACKS = {
632
+ primary: { fill: "#1e3a8a", stroke: "#60a5fa", text: "#dbeafe", edge: "#60a5fa" },
633
+ secondary: { fill: "#312e81", stroke: "#818cf8", text: "#e0e7ff", edge: "#818cf8" },
634
+ success: { fill: "#14532d", stroke: "#4ade80", text: "#dcfce7", edge: "#4ade80" },
635
+ warning: { fill: "#78350f", stroke: "#fbbf24", text: "#fef3c7", edge: "#fbbf24" },
636
+ danger: { fill: "#7f1d1d", stroke: "#f87171", text: "#fee2e2", edge: "#f87171" },
637
+ info: { fill: "#0c4a6e", stroke: "#38bdf8", text: "#e0f2fe", edge: "#38bdf8" },
638
+ violet: { fill: "#581c87", stroke: "#c084fc", text: "#f3e8ff", edge: "#c084fc" },
639
+ teal: { fill: "#134e4a", stroke: "#2dd4bf", text: "#ccfbf1", edge: "#2dd4bf" },
640
+ orange: { fill: "#7c2d12", stroke: "#fb923c", text: "#ffedd5", edge: "#fb923c" },
641
+ pink: { fill: "#831843", stroke: "#f472b6", text: "#fce7f3", edge: "#f472b6" },
642
+ neutral: { fill: "#1e293b", stroke: "#94a3b8", text: "#f1f5f9", edge: "#94a3b8" }
643
+ };
644
+ var FLOWCHART_EDGE_STROKE_STYLE_LABELS = {
645
+ solid: "Solid",
646
+ dashed: "Dashed",
647
+ dotted: "Dotted",
648
+ animated: "Animated flow"
649
+ };
577
650
  function normalizeKeyboardShortcuts(value) {
578
651
  return value === "basic" ? "basic" : "mindmap";
579
652
  }
653
+ function normalizeColorPreset(value) {
654
+ if (typeof value !== "string") return "";
655
+ const trimmed = value.trim().toLowerCase();
656
+ return FLOWCHART_COLOR_PRESETS.includes(trimmed) && trimmed !== "default" ? trimmed : "";
657
+ }
658
+ function sanitizeCssColor(value) {
659
+ if (typeof value !== "string") return "";
660
+ const trimmed = value.trim();
661
+ if (!trimmed || trimmed === "default") return "";
662
+ if (trimmed.length > 64 || /\\/.test(trimmed)) return "";
663
+ if (/[;{}<>"'`]/.test(trimmed) || /url\s*\(|expression\s*\(|javascript\s*:/i.test(trimmed)) {
664
+ return "";
665
+ }
666
+ if (!/^[#a-z0-9(),.%\s/+-]+$/i.test(trimmed)) return "";
667
+ return trimmed;
668
+ }
669
+ function normalizeEdgeColor(value) {
670
+ const preset = normalizeColorPreset(value);
671
+ if (preset) return preset;
672
+ return sanitizeCssColor(value);
673
+ }
674
+ function normalizeEdgeStrokeStyle(value) {
675
+ return FLOWCHART_EDGE_STROKE_STYLES.includes(value) && value !== "solid" ? value : "solid";
676
+ }
677
+ function resolveEdgeColorValue(color) {
678
+ if (!color || color === "default") return "var(--vd-flowchart-accent)";
679
+ if (FLOWCHART_COLOR_PRESETS.includes(color)) {
680
+ return `var(--vd-flowchart-palette-${color}-edge)`;
681
+ }
682
+ return color;
683
+ }
580
684
  var ARROW_DIRECTIONS = {
581
685
  ArrowRight: "right",
582
686
  ArrowLeft: "left",
@@ -617,6 +721,8 @@ function getShortcutRows(mode, readonly) {
617
721
  "Edit the connection label"
618
722
  ],
619
723
  ["Cmd/Ctrl + /", "Collapse or expand the branch"],
724
+ ["Cmd/Ctrl + ] or [", "Bring forward or send backward (Shift: front/back)"],
725
+ ["Cmd/Ctrl + L", "Lock or unlock the selected node"],
620
726
  ["Alt + Arrow", "Nudge the node (add Shift for 1 px)"],
621
727
  ["Delete or Backspace", "Delete the selection"],
622
728
  ["Cmd/Ctrl + D", "Duplicate the node"],
@@ -801,10 +907,12 @@ function clampNodeHeight(type, height, fallback, sizeBounds) {
801
907
  return clamp(toFiniteNumber(height, fallback), bounds.minHeight, bounds.maxHeight);
802
908
  }
803
909
  function isNodeResizable(nodeOrType) {
910
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
804
911
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
805
912
  return spec.resizable !== false;
806
913
  }
807
914
  function isNodeTextEditable(nodeOrType) {
915
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
808
916
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
809
917
  return spec.textEditable !== false;
810
918
  }
@@ -825,8 +933,8 @@ function normalizeViewport(viewport, scaleBounds) {
825
933
  const min = scaleBounds?.min ?? DEFAULT_MIN_SCALE;
826
934
  const max = scaleBounds?.max ?? DEFAULT_MAX_SCALE;
827
935
  return {
828
- x: toFiniteNumber(viewport?.x, 0),
829
- y: toFiniteNumber(viewport?.y, 0),
936
+ x: formatNumber(toFiniteNumber(viewport?.x, 0)),
937
+ y: formatNumber(toFiniteNumber(viewport?.y, 0)),
830
938
  scale: clamp(formatScale(toFiniteNumber(viewport?.scale, 1)), min, max)
831
939
  };
832
940
  }
@@ -836,14 +944,23 @@ function normalizeNode(rawNode, index, usedIds, sizeBounds) {
836
944
  const node = {
837
945
  id: ensureUniqueId(rawNode?.id, "node", usedIds),
838
946
  type,
839
- x: toFiniteNumber(rawNode?.x, index * 28),
840
- y: toFiniteNumber(rawNode?.y, index * 18),
841
- width: clampNodeWidth(type, rawNode?.width, spec.width, sizeBounds),
842
- height: clampNodeHeight(type, rawNode?.height, spec.height, sizeBounds),
947
+ x: formatNumber(toFiniteNumber(rawNode?.x, index * 28)),
948
+ y: formatNumber(toFiniteNumber(rawNode?.y, index * 18)),
949
+ width: formatNumber(clampNodeWidth(type, rawNode?.width, spec.width, sizeBounds)),
950
+ height: formatNumber(clampNodeHeight(type, rawNode?.height, spec.height, sizeBounds)),
843
951
  text: rawNode?.text == null ? spec.text : String(rawNode.text),
844
952
  data: isPlainObject(rawNode?.data) ? deepClone(rawNode.data) : {}
845
953
  };
846
954
  if (rawNode?.collapsed === true) node.collapsed = true;
955
+ const color = normalizeColorPreset(rawNode?.color ?? rawNode?.data?.color);
956
+ if (color) node.color = color;
957
+ const fill = sanitizeCssColor(rawNode?.fill ?? rawNode?.data?.fill);
958
+ if (fill) node.fill = fill;
959
+ const stroke = sanitizeCssColor(rawNode?.stroke ?? rawNode?.data?.stroke);
960
+ if (stroke) node.stroke = stroke;
961
+ const textColor = sanitizeCssColor(rawNode?.textColor ?? rawNode?.data?.textColor);
962
+ if (textColor) node.textColor = textColor;
963
+ if (rawNode?.locked === true || rawNode?.data?.locked === true) node.locked = true;
847
964
  return node;
848
965
  }
849
966
  function computeHiddenNodeIds(nodes, edges) {
@@ -876,6 +993,12 @@ function computeHiddenNodeIds(nodes, edges) {
876
993
  return candidates;
877
994
  }
878
995
  function normalizeEndpoint(rawEndpoint, fallbackPort) {
996
+ if (typeof rawEndpoint === "string") {
997
+ return {
998
+ nodeId: sanitizeId(rawEndpoint),
999
+ port: fallbackPort
1000
+ };
1001
+ }
879
1002
  return {
880
1003
  nodeId: sanitizeId(rawEndpoint?.nodeId),
881
1004
  port: FLOWCHART_PORTS.includes(rawEndpoint?.port) ? rawEndpoint.port : fallbackPort
@@ -911,6 +1034,10 @@ function normalizeEdge(rawEdge, index, nodeIds, usedIds) {
911
1034
  label: rawEdge?.label == null ? "" : String(rawEdge.label),
912
1035
  data: isPlainObject(rawEdge?.data) ? deepClone(rawEdge.data) : {}
913
1036
  };
1037
+ const color = normalizeEdgeColor(rawEdge?.color ?? rawEdge?.data?.color);
1038
+ if (color) edge.color = color;
1039
+ const strokeStyle = normalizeEdgeStrokeStyle(rawEdge?.strokeStyle ?? rawEdge?.data?.strokeStyle);
1040
+ if (strokeStyle !== "solid") edge.strokeStyle = strokeStyle;
914
1041
  syncEdgeKind(edge);
915
1042
  return edge;
916
1043
  }
@@ -1357,19 +1484,75 @@ function buildOrthogonalPath(fromPoint, toPoint, fromPort = "right", toPort = "l
1357
1484
  labelY: label.y
1358
1485
  };
1359
1486
  }
1487
+ function getPortOuterOffset(node, port) {
1488
+ if (!node || node.type === "label") return 0;
1489
+ const visual = nodeVisualScale(node);
1490
+ const baseStroke = node.type === "junction" ? 1.25 : 1.5;
1491
+ const halfStroke = Math.max(0.015, baseStroke * visual / 2);
1492
+ if (node.type === "diamond") {
1493
+ const w = Math.max(1, toFiniteNumber(node.width, 184));
1494
+ const h2 = Math.max(1, toFiniteNumber(node.height, 120));
1495
+ const diag = Math.hypot(w, h2);
1496
+ const miterFactor = isHorizontalPort(port) ? Math.min(4, diag / h2) : Math.min(4, diag / w);
1497
+ return halfStroke * miterFactor;
1498
+ }
1499
+ return halfStroke;
1500
+ }
1501
+ function getMarkerEndpointRetraction(markerType, strokeWidth, edgeScale = 1) {
1502
+ if (!markerType || markerType === "none") return 0;
1503
+ const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1504
+ const effective = Math.max(0.02, normalizeEdgeStrokeWidth(strokeWidth) * scale);
1505
+ if (markerType === "dot") {
1506
+ return formatNumber(Math.max(2.75 * scale, effective * 1.45));
1507
+ }
1508
+ return formatNumber(Math.max(1.5 * scale, effective * 0.85));
1509
+ }
1360
1510
  function buildEdgePath(edge, fromNode = null, toNode = null) {
1361
1511
  const fromPort = edge?.from?.port || edge?.fromPort || "right";
1362
1512
  const toPort = edge?.to?.port || edge?.toPort || "left";
1363
- const fromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
1364
- const toPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
1513
+ const rawFromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
1514
+ const rawToPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
1365
1515
  const route = normalizeEdgeRoute(edge?.route);
1366
- const metrics = routeMetrics(edgeVisualScale(fromNode, toNode));
1367
- if (!fromPoint || !toPoint) {
1516
+ const visualScale = edgeVisualScale(fromNode, toNode);
1517
+ const metrics = routeMetrics(visualScale);
1518
+ if (!rawFromPoint || !rawToPoint) {
1368
1519
  return { d: "", labelX: 0, labelY: 0 };
1369
1520
  }
1521
+ const strokeWidth = normalizeEdgeStrokeWidth(edge?.strokeWidth);
1522
+ const startMarker = edge?.startMarker || "none";
1523
+ const endMarker = edge?.endMarker || "none";
1524
+ const rawDistance = Math.hypot(rawToPoint.x - rawFromPoint.x, rawToPoint.y - rawFromPoint.y);
1525
+ const maxRetract = rawDistance > 0 ? rawDistance * 0.45 : 0;
1526
+ const fromMarkerRetract = !edge?.fromPoint && fromNode && startMarker !== "none" ? getMarkerEndpointRetraction(startMarker, strokeWidth, visualScale) : 0;
1527
+ const fromBorderRetract = fromMarkerRetract > 0 ? getPortOuterOffset(fromNode, fromPort) : 0;
1528
+ const toMarkerRetract = !edge?.toPoint && toNode && endMarker !== "none" ? getMarkerEndpointRetraction(endMarker, strokeWidth, visualScale) : 0;
1529
+ const toBorderRetract = toMarkerRetract > 0 ? getPortOuterOffset(toNode, toPort) : 0;
1530
+ const fromRetract = Math.min(maxRetract, fromMarkerRetract + fromBorderRetract);
1531
+ const toRetract = Math.min(maxRetract, toMarkerRetract + toBorderRetract);
1370
1532
  if (route === "straight") {
1371
- return buildStraightPath(fromPoint, toPoint);
1533
+ const borderFrom = fromBorderRetract > 0 ? offsetPoint(
1534
+ rawFromPoint,
1535
+ getPortNormal(fromPort),
1536
+ Math.min(maxRetract, fromBorderRetract)
1537
+ ) : rawFromPoint;
1538
+ const borderTo = toBorderRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), Math.min(maxRetract, toBorderRetract)) : rawToPoint;
1539
+ const dx = borderTo.x - borderFrom.x;
1540
+ const dy = borderTo.y - borderFrom.y;
1541
+ const dist = Math.hypot(dx, dy);
1542
+ if (dist > 0.01) {
1543
+ const ux = dx / dist;
1544
+ const uy = dy / dist;
1545
+ const sRetract = Math.min(dist * 0.45, fromMarkerRetract);
1546
+ const eRetract = Math.min(dist * 0.45, toMarkerRetract);
1547
+ return buildStraightPath(
1548
+ { x: borderFrom.x + ux * sRetract, y: borderFrom.y + uy * sRetract },
1549
+ { x: borderTo.x - ux * eRetract, y: borderTo.y - uy * eRetract }
1550
+ );
1551
+ }
1552
+ return buildStraightPath(rawFromPoint, rawToPoint);
1372
1553
  }
1554
+ const fromPoint = fromRetract > 0 ? offsetPoint(rawFromPoint, getPortNormal(fromPort), fromRetract) : rawFromPoint;
1555
+ const toPoint = toRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), toRetract) : rawToPoint;
1373
1556
  if (route === "orthogonal") {
1374
1557
  const fromRect = !edge?.fromPoint && fromNode ? getNodeRectBounds(fromNode, metrics.clearance) : null;
1375
1558
  const toRect = !edge?.toPoint && toNode ? getNodeRectBounds(toNode, metrics.clearance) : null;
@@ -1377,7 +1560,7 @@ function buildEdgePath(edge, fromNode = null, toNode = null) {
1377
1560
  }
1378
1561
  return buildCurvePath(fromPoint, toPoint, fromPort, toPort, metrics);
1379
1562
  }
1380
- function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1563
+ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1381
1564
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1382
1565
  const effective = Math.max(0.02, strokeWidth * scale);
1383
1566
  const size = formatNumber(Math.max(9 * scale, effective * 4.4));
@@ -1394,12 +1577,12 @@ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1394
1577
  marker.appendChild(
1395
1578
  svgEl("path", {
1396
1579
  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`,
1397
- fill: "var(--vd-flowchart-accent)"
1580
+ fill
1398
1581
  })
1399
1582
  );
1400
1583
  return marker;
1401
1584
  }
1402
- function createDotMarker(id, strokeWidth, edgeScale = 1) {
1585
+ function createDotMarker(id, strokeWidth, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1403
1586
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1404
1587
  const effective = Math.max(0.02, strokeWidth * scale);
1405
1588
  const size = formatNumber(Math.max(8 * scale, effective * 3.3));
@@ -1418,7 +1601,7 @@ function createDotMarker(id, strokeWidth, edgeScale = 1) {
1418
1601
  cx: formatNumber(size / 2),
1419
1602
  cy: formatNumber(size / 2),
1420
1603
  r: radius,
1421
- fill: "var(--vd-flowchart-accent)"
1604
+ fill
1422
1605
  })
1423
1606
  );
1424
1607
  return marker;
@@ -1707,6 +1890,7 @@ var VdFlowchart = class {
1707
1890
  this.minimapFrame = 0;
1708
1891
  this.minimapDrag = null;
1709
1892
  this.shortcutsHelpOpen = false;
1893
+ this.colorPopoverOpen = false;
1710
1894
  this.autoFit = Boolean(options.autoFit);
1711
1895
  this.readyEmitted = false;
1712
1896
  this.resizeObserver = null;
@@ -1723,8 +1907,10 @@ var VdFlowchart = class {
1723
1907
  this.handleKeyDown = this.handleKeyDown.bind(this);
1724
1908
  this.handleSelectionFieldInput = this.handleSelectionFieldInput.bind(this);
1725
1909
  this.handleSelectionFieldChange = this.handleSelectionFieldChange.bind(this);
1910
+ this.handleSelectionActionClick = this.handleSelectionActionClick.bind(this);
1726
1911
  this.handleJsonActionClick = this.handleJsonActionClick.bind(this);
1727
1912
  this.handleResize = this.handleResize.bind(this);
1913
+ this.handleOutsidePointerDown = this.handleOutsidePointerDown.bind(this);
1728
1914
  this.buildShell();
1729
1915
  this.bindEvents();
1730
1916
  this.render();
@@ -1763,8 +1949,19 @@ var VdFlowchart = class {
1763
1949
  });
1764
1950
  this.resizeObserver.observe(this.canvasEl);
1765
1951
  }
1766
- const raf = typeof requestAnimationFrame === "function" ? requestAnimationFrame : (cb) => setTimeout(cb, 16);
1767
- raf(() => tryEmit());
1952
+ if (typeof requestAnimationFrame === "function") {
1953
+ this.readyFrameIsTimeout = false;
1954
+ this.readyFrame = requestAnimationFrame(() => {
1955
+ this.readyFrame = 0;
1956
+ tryEmit();
1957
+ });
1958
+ } else {
1959
+ this.readyFrameIsTimeout = true;
1960
+ this.readyFrame = setTimeout(() => {
1961
+ this.readyFrame = 0;
1962
+ tryEmit();
1963
+ }, 16);
1964
+ }
1768
1965
  };
1769
1966
  if (typeof queueMicrotask === "function") {
1770
1967
  queueMicrotask(startObserving);
@@ -1808,6 +2005,32 @@ var VdFlowchart = class {
1808
2005
  this.arrangeSelect.appendChild(option);
1809
2006
  });
1810
2007
  this.arrangeSelect.value = this.layoutMode;
2008
+ this.colorPopoverWrap = createElement("div", { className: "vd-flowchart-color-popover-wrap" });
2009
+ this.colorButton = createToolbarButton({
2010
+ action: "color-popover",
2011
+ label: "Color selection",
2012
+ icon: "palette",
2013
+ disabled: this.readonly
2014
+ });
2015
+ this.colorButton.setAttribute("aria-expanded", "false");
2016
+ this.colorPopover = createElement("div", { className: "vd-flowchart-color-popover" });
2017
+ this.colorPopover.hidden = true;
2018
+ this.colorPopover.setAttribute("role", "dialog");
2019
+ this.colorPopover.setAttribute("aria-label", "Color presets");
2020
+ const popoverSwatches = createElement("div", { className: "vd-flowchart-swatch-grid" });
2021
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
2022
+ const swatch = createElement("button", {
2023
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}`,
2024
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset
2025
+ });
2026
+ swatch.setAttribute("type", "button");
2027
+ swatch.setAttribute("data-flowchart-color", preset);
2028
+ swatch.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
2029
+ popoverSwatches.appendChild(swatch);
2030
+ });
2031
+ this.colorPopover.appendChild(popoverSwatches);
2032
+ this.colorPopoverWrap.appendChild(this.colorButton);
2033
+ this.colorPopoverWrap.appendChild(this.colorPopover);
1811
2034
  this.clearButton = createToolbarButton({
1812
2035
  action: "clear",
1813
2036
  label: "Clear canvas",
@@ -1834,6 +2057,7 @@ var VdFlowchart = class {
1834
2057
  });
1835
2058
  this.minimapButton.setAttribute("aria-pressed", this.minimapEnabled ? "true" : "false");
1836
2059
  toolbarLeft.appendChild(this.arrangeSelect);
2060
+ toolbarLeft.appendChild(this.colorPopoverWrap);
1837
2061
  toolbarLeft.appendChild(this.clearButton);
1838
2062
  toolbarRight.appendChild(this.minimapButton);
1839
2063
  toolbarRight.appendChild(this.shortcutsButton);
@@ -2118,12 +2342,14 @@ var VdFlowchart = class {
2118
2342
  this.graphEditButton.disabled = this.readonly || nodes.length === 0;
2119
2343
  }
2120
2344
  bindEvents() {
2345
+ this.handleDeleteClick = () => this.deleteSelection();
2121
2346
  this.toolbar.addEventListener("click", this.handleToolbarClick);
2122
2347
  this.arrangeSelect.addEventListener("change", this.handleArrangeChange);
2123
2348
  this.paletteGrid.addEventListener("click", this.handlePaletteClick);
2124
- this.deleteButton.addEventListener("click", () => this.deleteSelection());
2349
+ this.deleteButton.addEventListener("click", this.handleDeleteClick);
2125
2350
  this.selectionFields.addEventListener("input", this.handleSelectionFieldInput);
2126
2351
  this.selectionFields.addEventListener("change", this.handleSelectionFieldChange);
2352
+ this.selectionFields.addEventListener("click", this.handleSelectionActionClick);
2127
2353
  this.jsonActions.addEventListener("click", this.handleJsonActionClick);
2128
2354
  this.canvasEl.addEventListener("pointerdown", this.handlePointerDown);
2129
2355
  this.canvasEl.addEventListener("pointermove", this.handlePointerMove);
@@ -2135,14 +2361,24 @@ var VdFlowchart = class {
2135
2361
  this.canvasEl.addEventListener("blur", this.handleCanvasBlur);
2136
2362
  this.root.addEventListener("keydown", this.handleKeyDown, true);
2137
2363
  window.addEventListener("pointerup", this.handlePointerUp);
2364
+ window.addEventListener("pointerdown", this.handleOutsidePointerDown);
2138
2365
  window.addEventListener("resize", this.handleResize);
2139
2366
  }
2140
2367
  unbindEvents() {
2141
2368
  this.toolbar.removeEventListener("click", this.handleToolbarClick);
2142
2369
  this.arrangeSelect.removeEventListener("change", this.handleArrangeChange);
2143
2370
  this.paletteGrid.removeEventListener("click", this.handlePaletteClick);
2371
+ if (this.handleDeleteClick) {
2372
+ this.deleteButton.removeEventListener("click", this.handleDeleteClick);
2373
+ this.handleDeleteClick = null;
2374
+ }
2375
+ if (this.handleDeleteClick) {
2376
+ this.deleteButton.removeEventListener("click", this.handleDeleteClick);
2377
+ this.handleDeleteClick = null;
2378
+ }
2144
2379
  this.selectionFields.removeEventListener("input", this.handleSelectionFieldInput);
2145
2380
  this.selectionFields.removeEventListener("change", this.handleSelectionFieldChange);
2381
+ this.selectionFields.removeEventListener("click", this.handleSelectionActionClick);
2146
2382
  this.jsonActions.removeEventListener("click", this.handleJsonActionClick);
2147
2383
  this.canvasEl.removeEventListener("pointerdown", this.handlePointerDown);
2148
2384
  this.canvasEl.removeEventListener("pointermove", this.handlePointerMove);
@@ -2154,8 +2390,14 @@ var VdFlowchart = class {
2154
2390
  this.canvasEl.removeEventListener("blur", this.handleCanvasBlur);
2155
2391
  this.root.removeEventListener("keydown", this.handleKeyDown, true);
2156
2392
  window.removeEventListener("pointerup", this.handlePointerUp);
2393
+ window.removeEventListener("pointerdown", this.handleOutsidePointerDown);
2157
2394
  window.removeEventListener("resize", this.handleResize);
2158
2395
  }
2396
+ handleOutsidePointerDown(event) {
2397
+ if (!this.colorPopoverOpen || this.destroyed) return;
2398
+ if (event.target?.closest?.(".vd-flowchart-color-popover-wrap")) return;
2399
+ this.toggleColorPopover(false);
2400
+ }
2159
2401
  handleResize() {
2160
2402
  if (this.destroyed) return;
2161
2403
  this.render({ inspector: false, json: false });
@@ -2194,7 +2436,24 @@ var VdFlowchart = class {
2194
2436
  this.updatePaletteState();
2195
2437
  this.render({ scene: true, inspector: false, json: false });
2196
2438
  }
2439
+ toggleColorPopover(force) {
2440
+ if (!this.colorPopover || !this.colorButton) return this;
2441
+ const open = typeof force === "boolean" ? force : !this.colorPopoverOpen;
2442
+ this.colorPopoverOpen = open && !this.readonly;
2443
+ this.colorPopover.hidden = !this.colorPopoverOpen;
2444
+ this.colorButton.setAttribute("aria-expanded", this.colorPopoverOpen ? "true" : "false");
2445
+ return this;
2446
+ }
2197
2447
  handleToolbarClick(event) {
2448
+ const colorSwatch = event.target.closest("[data-flowchart-color]");
2449
+ if (colorSwatch) {
2450
+ if (!this.readonly) {
2451
+ const preset = colorSwatch.getAttribute("data-flowchart-color");
2452
+ this.setSelectionColor(preset);
2453
+ }
2454
+ this.toggleColorPopover(false);
2455
+ return;
2456
+ }
2198
2457
  const actionButton = event.target.closest("[data-flowchart-action]");
2199
2458
  if (!actionButton) return;
2200
2459
  const action = actionButton.getAttribute("data-flowchart-action");
@@ -2204,6 +2463,7 @@ var VdFlowchart = class {
2204
2463
  if (action === "fit-view") this.fitView();
2205
2464
  if (action === "undo") this.undo();
2206
2465
  if (action === "redo") this.redo();
2466
+ if (action === "color-popover") this.toggleColorPopover();
2207
2467
  if (action === "clear" && !this.readonly) this.clear();
2208
2468
  if (action === "shortcuts") this.toggleShortcutsHelp();
2209
2469
  if (action === "minimap") this.setMinimapEnabled(!this.minimapEnabled);
@@ -2266,16 +2526,18 @@ var VdFlowchart = class {
2266
2526
  nodes.forEach((node) => {
2267
2527
  const point = map(node.x, node.y);
2268
2528
  const selected = this.isNodeSelected(node.id);
2269
- this.minimapSvg.appendChild(
2270
- svgEl("rect", {
2271
- class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
2272
- x: point.x,
2273
- y: point.y,
2274
- width: formatNumber(Math.max(1.5, node.width * transform.scale)),
2275
- height: formatNumber(Math.max(1.5, node.height * transform.scale)),
2276
- rx: 1.5
2277
- })
2278
- );
2529
+ const rectEl = svgEl("rect", {
2530
+ class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
2531
+ x: point.x,
2532
+ y: point.y,
2533
+ width: formatNumber(Math.max(1.5, node.width * transform.scale)),
2534
+ height: formatNumber(Math.max(1.5, node.height * transform.scale)),
2535
+ rx: 1.5
2536
+ });
2537
+ if (node.color) rectEl.setAttribute("data-color", node.color);
2538
+ if (node.fill) rectEl.style.fill = node.fill;
2539
+ if (node.stroke) rectEl.style.stroke = node.stroke;
2540
+ this.minimapSvg.appendChild(rectEl);
2279
2541
  });
2280
2542
  const corner = map(view.left, view.top);
2281
2543
  this.minimapSvg.appendChild(
@@ -2397,6 +2659,42 @@ var VdFlowchart = class {
2397
2659
  }
2398
2660
  }
2399
2661
  }
2662
+ handleSelectionActionClick(event) {
2663
+ if (this.readonly) return;
2664
+ const swatch = event.target.closest("[data-color-preset]");
2665
+ if (swatch) {
2666
+ this.setSelectionColor(swatch.getAttribute("data-color-preset"));
2667
+ return;
2668
+ }
2669
+ const resetBtn = event.target.closest("[data-color-reset]");
2670
+ if (resetBtn) {
2671
+ this.clearSelectionColor();
2672
+ return;
2673
+ }
2674
+ const arrangeBtn = event.target.closest("[data-arrange-action]");
2675
+ if (arrangeBtn) {
2676
+ const action = arrangeBtn.getAttribute("data-arrange-action");
2677
+ if (action === "bring-to-front") this.bringToFront();
2678
+ else if (action === "bring-forward") this.bringForward();
2679
+ else if (action === "send-backward") this.sendBackward();
2680
+ else if (action === "send-to-back") this.sendToBack();
2681
+ return;
2682
+ }
2683
+ const alignBtn = event.target.closest("[data-align-action]");
2684
+ if (alignBtn) {
2685
+ this.alignNodes(alignBtn.getAttribute("data-align-action"));
2686
+ return;
2687
+ }
2688
+ const distributeBtn = event.target.closest("[data-distribute-action]");
2689
+ if (distributeBtn) {
2690
+ this.distributeNodes(distributeBtn.getAttribute("data-distribute-action"));
2691
+ return;
2692
+ }
2693
+ const lockBtn = event.target.closest("[data-lock-toggle]");
2694
+ if (lockBtn) {
2695
+ this.toggleNodeLocked();
2696
+ }
2697
+ }
2400
2698
  handleSelectionFieldInput(event) {
2401
2699
  const field = event.target.getAttribute("data-field");
2402
2700
  if (!field) return;
@@ -2419,6 +2717,38 @@ var VdFlowchart = class {
2419
2717
  if (field === "node-width" || field === "node-height") {
2420
2718
  const patch = field === "node-width" ? { width: toFiniteNumber(event.target.value, void 0) } : { height: toFiniteNumber(event.target.value, void 0) };
2421
2719
  this.updateNode(this.selection?.id, patch, { inspector: false, reason: "node:update" });
2720
+ return;
2721
+ }
2722
+ if (field === "node-fill") {
2723
+ this.updateNode(
2724
+ this.selection?.id,
2725
+ { fill: event.target.value },
2726
+ { inspector: false, reason: "node:update" }
2727
+ );
2728
+ return;
2729
+ }
2730
+ if (field === "node-stroke") {
2731
+ this.updateNode(
2732
+ this.selection?.id,
2733
+ { stroke: event.target.value },
2734
+ { inspector: false, reason: "node:update" }
2735
+ );
2736
+ return;
2737
+ }
2738
+ if (field === "node-text-color") {
2739
+ this.updateNode(
2740
+ this.selection?.id,
2741
+ { textColor: event.target.value },
2742
+ { inspector: false, reason: "node:update" }
2743
+ );
2744
+ return;
2745
+ }
2746
+ if (field === "edge-color") {
2747
+ this.updateEdge(
2748
+ this.selection?.id,
2749
+ { color: event.target.value },
2750
+ { inspector: false, reason: "edge:update" }
2751
+ );
2422
2752
  }
2423
2753
  }
2424
2754
  handleSelectionFieldChange(event) {
@@ -2462,6 +2792,14 @@ var VdFlowchart = class {
2462
2792
  { strokeWidth: getStrokePresetWidth(event.target.value) },
2463
2793
  { inspector: true, reason: "edge:update" }
2464
2794
  );
2795
+ return;
2796
+ }
2797
+ if (field === "edge-stroke-style") {
2798
+ this.updateEdge(
2799
+ this.selection?.id,
2800
+ { strokeStyle: event.target.value },
2801
+ { inspector: true, reason: "edge:update" }
2802
+ );
2465
2803
  }
2466
2804
  }
2467
2805
  // Keys the editor consumes stop here, so page-level shortcuts (a docs
@@ -2484,6 +2822,11 @@ var VdFlowchart = class {
2484
2822
  this.toggleShortcutsHelp(false);
2485
2823
  return;
2486
2824
  }
2825
+ if (key === "Escape" && this.colorPopoverOpen) {
2826
+ event.preventDefault();
2827
+ this.toggleColorPopover(false);
2828
+ return;
2829
+ }
2487
2830
  if (target === this.canvasEl && this.handleCanvasKeyDown(event)) {
2488
2831
  event.preventDefault();
2489
2832
  return;
@@ -2506,6 +2849,29 @@ var VdFlowchart = class {
2506
2849
  }
2507
2850
  return;
2508
2851
  }
2852
+ if (modKey && (key === "l" || key === "L")) {
2853
+ if (this.selection?.kind === "node") {
2854
+ event.preventDefault();
2855
+ this.toggleNodeLocked();
2856
+ }
2857
+ return;
2858
+ }
2859
+ if (modKey && (key === "]" || key === "}" || event.code === "BracketRight")) {
2860
+ if (this.selection) {
2861
+ event.preventDefault();
2862
+ if (event.shiftKey || key === "}") this.bringToFront();
2863
+ else this.bringForward();
2864
+ }
2865
+ return;
2866
+ }
2867
+ if (modKey && (key === "[" || key === "{" || event.code === "BracketLeft")) {
2868
+ if (this.selection) {
2869
+ event.preventDefault();
2870
+ if (event.shiftKey || key === "{") this.sendToBack();
2871
+ else this.sendBackward();
2872
+ }
2873
+ return;
2874
+ }
2509
2875
  if (modKey && (event.key === "z" || event.key === "Z")) {
2510
2876
  event.preventDefault();
2511
2877
  if (event.shiftKey) {
@@ -2688,7 +3054,7 @@ var VdFlowchart = class {
2688
3054
  nudgeNodes(nodeIds, direction, distance) {
2689
3055
  const step = { right: [1, 0], left: [-1, 0], down: [0, 1], up: [0, -1] }[direction];
2690
3056
  if (this.readonly || !step) return [];
2691
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
3057
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
2692
3058
  if (!nodes.length) return [];
2693
3059
  nodes.forEach((node) => {
2694
3060
  node.x = formatNumber(node.x + step[0] * distance);
@@ -2827,7 +3193,32 @@ var VdFlowchart = class {
2827
3193
  this.emitChange("edge:add", { edge: deepClone(edge) });
2828
3194
  return true;
2829
3195
  }
3196
+ pasteSelection() {
3197
+ if (!this.pasteClipboard()) return null;
3198
+ if (this.hasMultiSelection()) {
3199
+ return this.getSelectedNodeIds().map((id) => this.findNode(id)).filter(Boolean).map((node) => deepClone(node));
3200
+ }
3201
+ const snap = this.getSelectionSnapshot();
3202
+ return snap?.node || snap?.edge || null;
3203
+ }
2830
3204
  cutSelection() {
3205
+ if (!this.selection || this.readonly) return false;
3206
+ if (this.hasMultiSelection()) {
3207
+ const unlockedIds = this.getSelectedNodeIds().filter((id) => {
3208
+ const node = this.findNode(id);
3209
+ return node && !node.locked;
3210
+ });
3211
+ if (!unlockedIds.length) return false;
3212
+ const unlockedSet = new Set(unlockedIds);
3213
+ const nodes = unlockedIds.map((id) => deepClone(this.findNode(id)));
3214
+ const edges = this.documentData.edges.filter((edge) => unlockedSet.has(edge.from.nodeId) && unlockedSet.has(edge.to.nodeId)).map((edge) => deepClone(edge));
3215
+ this.clipboard = { kind: "nodes", data: { nodes, edges } };
3216
+ return this.deleteSelection();
3217
+ }
3218
+ if (this.selection.kind === "node") {
3219
+ const node = this.findNode(this.selection.id);
3220
+ if (!node || node.locked) return false;
3221
+ }
2831
3222
  if (!this.copySelection()) return false;
2832
3223
  return this.deleteSelection();
2833
3224
  }
@@ -2864,6 +3255,9 @@ var VdFlowchart = class {
2864
3255
  }
2865
3256
  handlePointerDown(event) {
2866
3257
  if (this.destroyed || event.button != null && event.button !== 0) return;
3258
+ if (this.colorPopoverOpen) {
3259
+ this.toggleColorPopover(false);
3260
+ }
2867
3261
  if (this.textEditor && !event.target.closest(".vd-flowchart-text-editor")) {
2868
3262
  this.stopTextEdit({ commit: true });
2869
3263
  }
@@ -2888,6 +3282,8 @@ var VdFlowchart = class {
2888
3282
  const fromNode = this.findNode(edge.from.nodeId);
2889
3283
  const toNode = this.findNode(edge.to.nodeId);
2890
3284
  if (!fromNode || !toNode) return;
3285
+ const endpointNode = endpoint === "from" ? fromNode : toNode;
3286
+ if (endpointNode.locked) return;
2891
3287
  this.reconnectEdgeId = edgeId;
2892
3288
  this.select({ kind: "edge", id: edgeId });
2893
3289
  this.interaction = {
@@ -2938,7 +3334,7 @@ var VdFlowchart = class {
2938
3334
  const nodeId = portTarget.getAttribute("data-node-id");
2939
3335
  const port = portTarget.getAttribute("data-port");
2940
3336
  const node = this.findNode(nodeId);
2941
- if (!node) return;
3337
+ if (!node || node.locked) return;
2942
3338
  const sourcePoint = getPortPosition(node, port);
2943
3339
  this.interaction = {
2944
3340
  kind: "connect",
@@ -2967,7 +3363,7 @@ var VdFlowchart = class {
2967
3363
  const nodeId = resizeTarget.getAttribute("data-node-id");
2968
3364
  const handle = resizeTarget.getAttribute("data-resize-handle");
2969
3365
  const node = this.findNode(nodeId);
2970
- if (!node || !RESIZE_HANDLES.includes(handle)) return;
3366
+ if (!node || !isNodeResizable(node) || !RESIZE_HANDLES.includes(handle)) return;
2971
3367
  this.select({ kind: "node", id: nodeId });
2972
3368
  this.interaction = {
2973
3369
  kind: "resize-node",
@@ -3000,8 +3396,11 @@ var VdFlowchart = class {
3000
3396
  if (groupIds.length > 1) this.selectNodes(groupIds, { primary: nodeId });
3001
3397
  else this.select({ kind: "node", id: nodeId });
3002
3398
  if (!this.readonly) {
3003
- this.interaction = this.createDragInteraction(event, nodeId, groupIds);
3004
- this.capturePointer(event.pointerId);
3399
+ const drag = this.createDragInteraction(event, nodeId, groupIds);
3400
+ if (drag) {
3401
+ this.interaction = drag;
3402
+ this.capturePointer(event.pointerId);
3403
+ }
3005
3404
  }
3006
3405
  return;
3007
3406
  }
@@ -3032,12 +3431,13 @@ var VdFlowchart = class {
3032
3431
  event.preventDefault();
3033
3432
  }
3034
3433
  createDragInteraction(event, nodeId, nodeIds) {
3035
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
3434
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
3435
+ if (!nodes.length) return null;
3036
3436
  const moving = new Set(nodes.map((node) => node.id));
3037
3437
  return {
3038
3438
  kind: "drag-node",
3039
3439
  pointerId: event.pointerId,
3040
- nodeId,
3440
+ nodeId: moving.has(nodeId) ? nodeId : nodes[0].id,
3041
3441
  nodeIds: nodes.map((node) => node.id),
3042
3442
  startWorld: this.clientToWorld(event.clientX, event.clientY),
3043
3443
  origins: new Map(nodes.map((node) => [node.id, { x: node.x, y: node.y }])),
@@ -3389,15 +3789,16 @@ var VdFlowchart = class {
3389
3789
  if (this.activeTool === "arrow") return true;
3390
3790
  return this.selection?.kind === "node" && this.selection.id === node.id && !this.hasMultiSelection();
3391
3791
  }
3392
- getMarkerId(markerType, position, strokeWidth, edgeScale = 1) {
3792
+ getMarkerId(markerType, position, strokeWidth, edgeScale = 1, color = "") {
3393
3793
  const width = normalizeEdgeStrokeWidth(strokeWidth);
3394
3794
  const scale = clamp(formatNumber(Math.max(edgeScale, 0.01)), 0.01, 1);
3395
- const key = `${markerType}:${position}:${width}:${scale}`;
3795
+ const fill = resolveEdgeColorValue(color);
3796
+ const key = `${markerType}:${position}:${width}:${scale}:${fill}`;
3396
3797
  if (this.markerIds.has(key)) {
3397
3798
  return this.markerIds.get(key);
3398
3799
  }
3399
3800
  const markerId = nextId(`flowchart-${markerType}-${position}`);
3400
- const marker = markerType === "dot" ? createDotMarker(markerId, width, scale) : createArrowMarker(markerId, width, position === "start", scale);
3801
+ const marker = markerType === "dot" ? createDotMarker(markerId, width, scale, fill) : createArrowMarker(markerId, width, position === "start", scale, fill);
3401
3802
  this.markerDefs.appendChild(marker);
3402
3803
  this.markerIds.set(key, markerId);
3403
3804
  return markerId;
@@ -3419,7 +3820,7 @@ var VdFlowchart = class {
3419
3820
  const snapPadding = CONNECTION_SNAP_PADDING / this.documentData.viewport.scale;
3420
3821
  const hysteresisMargin = CONNECTION_HYSTERESIS / this.documentData.viewport.scale;
3421
3822
  const best = this.getVisibleNodes().reduce((candidate, node) => {
3422
- if (node.id === excludeNodeId) return candidate;
3823
+ if (node.id === excludeNodeId || node.locked) return candidate;
3423
3824
  const distanceToBounds2 = getDistanceToNodeBounds(node, worldPoint);
3424
3825
  if (distanceToBounds2 > snapPadding) return candidate;
3425
3826
  const nearest = pickPortForNode(node, worldPoint, referencePoint);
@@ -3437,7 +3838,7 @@ var VdFlowchart = class {
3437
3838
  }, null);
3438
3839
  if (!previousSnap || !best) return best;
3439
3840
  const previousNode = this.findNode(previousSnap.nodeId);
3440
- if (!previousNode || previousNode.id === excludeNodeId) return best;
3841
+ if (!previousNode || previousNode.id === excludeNodeId || previousNode.locked) return best;
3441
3842
  const distanceToBounds = getDistanceToNodeBounds(previousNode, worldPoint);
3442
3843
  if (distanceToBounds > snapPadding) return best;
3443
3844
  if (best.node.id === previousSnap.nodeId && best.port === previousSnap.port) {
@@ -3852,16 +4253,17 @@ var VdFlowchart = class {
3852
4253
  }
3853
4254
  applyEdgeMarkers(pathElement, edge, edgeScale = 1) {
3854
4255
  const width = this.getEdgeStrokeWidth(edge);
4256
+ const color = edge.color || "";
3855
4257
  if (edge.startMarker && edge.startMarker !== "none") {
3856
4258
  pathElement.setAttribute(
3857
4259
  "marker-start",
3858
- `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale)})`
4260
+ `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale, color)})`
3859
4261
  );
3860
4262
  }
3861
4263
  if (edge.endMarker && edge.endMarker !== "none") {
3862
4264
  pathElement.setAttribute(
3863
4265
  "marker-end",
3864
- `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale)})`
4266
+ `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale, color)})`
3865
4267
  );
3866
4268
  }
3867
4269
  }
@@ -3873,10 +4275,19 @@ var VdFlowchart = class {
3873
4275
  const edgePath = buildEdgePath(edge, fromNode, toNode);
3874
4276
  const selected = this.selection?.kind === "edge" && this.selection.id === edge.id;
3875
4277
  const inReconnectMode = this.reconnectEdgeId === edge.id;
4278
+ const strokeStyle = normalizeEdgeStrokeStyle(edge.strokeStyle);
4279
+ const strokeClass = strokeStyle !== "solid" ? ` is-stroke-${strokeStyle}` : "";
3876
4280
  const group = svgEl("g", {
3877
- class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}`,
4281
+ class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}${strokeClass}`,
3878
4282
  "data-edge-id": edge.id
3879
4283
  });
4284
+ if (edge.color) {
4285
+ if (FLOWCHART_COLOR_PRESETS.includes(edge.color) && edge.color !== "default") {
4286
+ group.setAttribute("data-color", edge.color);
4287
+ } else {
4288
+ group.setAttribute("data-color", "custom");
4289
+ }
4290
+ }
3880
4291
  const baseStroke = this.getEdgeStrokeWidth(edge);
3881
4292
  const strokeWidth = visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke;
3882
4293
  if (selected) {
@@ -3894,6 +4305,20 @@ var VdFlowchart = class {
3894
4305
  "stroke-width": strokeWidth,
3895
4306
  "data-edge-id": edge.id
3896
4307
  });
4308
+ if (edge.color && !FLOWCHART_COLOR_PRESETS.includes(edge.color)) {
4309
+ visiblePath.style.stroke = edge.color;
4310
+ }
4311
+ if (strokeStyle === "dashed" || strokeStyle === "animated") {
4312
+ visiblePath.setAttribute(
4313
+ "stroke-dasharray",
4314
+ visual < 0.999 ? `${formatNumber(8 * visual)} ${formatNumber(5 * visual)}` : "8 5"
4315
+ );
4316
+ } else if (strokeStyle === "dotted") {
4317
+ visiblePath.setAttribute(
4318
+ "stroke-dasharray",
4319
+ visual < 0.999 ? `${formatNumber(2 * visual)} ${formatNumber(5 * visual)}` : "2 5"
4320
+ );
4321
+ }
3897
4322
  this.applyEdgeMarkers(visiblePath, edge, visual);
3898
4323
  const hitPath = svgEl("path", {
3899
4324
  class: "vd-flowchart-edge-hit",
@@ -3976,6 +4401,36 @@ var VdFlowchart = class {
3976
4401
  "stroke-width": visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke
3977
4402
  });
3978
4403
  }
4404
+ renderLockBadge(node) {
4405
+ const scale = this.documentData.viewport.scale || 1;
4406
+ const badgeSize = 16 / scale;
4407
+ const offsetX = node.width - badgeSize / 2 - 4 / scale;
4408
+ const offsetY = badgeSize / 2 + 4 / scale;
4409
+ const badge = svgEl("g", {
4410
+ class: "vd-flowchart-node-lock",
4411
+ transform: `translate(${formatNumber(offsetX)} ${formatNumber(offsetY)})`,
4412
+ "data-node-id": node.id
4413
+ });
4414
+ const title = svgEl("title");
4415
+ title.textContent = "Locked node";
4416
+ badge.appendChild(title);
4417
+ badge.appendChild(
4418
+ svgEl("circle", {
4419
+ cx: 0,
4420
+ cy: 0,
4421
+ r: formatNumber(badgeSize / 2)
4422
+ })
4423
+ );
4424
+ const iconScale = badgeSize * 0.62 / 256;
4425
+ const iconOffset = -128 * iconScale;
4426
+ badge.appendChild(
4427
+ svgEl("path", {
4428
+ d: TOOLBAR_ICON_PATHS.lock,
4429
+ transform: `translate(${formatNumber(iconOffset)} ${formatNumber(iconOffset)}) scale(${formatScale(iconScale)})`
4430
+ })
4431
+ );
4432
+ return badge;
4433
+ }
3979
4434
  renderNode(node) {
3980
4435
  const selected = this.isNodeSelected(node.id);
3981
4436
  const soloSelected = selected && !this.hasMultiSelection();
@@ -3983,10 +4438,13 @@ var VdFlowchart = class {
3983
4438
  const resizing = this.interaction?.kind === "resize-node" && this.interaction.nodeId === node.id;
3984
4439
  const editing = this.textEditor?.nodeId === node.id;
3985
4440
  const group = svgEl("g", {
3986
- class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}`,
4441
+ class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}${node.locked ? " is-locked" : ""}`,
3987
4442
  transform: `translate(${formatNumber(node.x)} ${formatNumber(node.y)})`,
3988
4443
  "data-node-id": node.id
3989
4444
  });
4445
+ if (node.color) {
4446
+ group.setAttribute("data-color", node.color);
4447
+ }
3990
4448
  const portsVisible = this.shouldShowNodePorts(node);
3991
4449
  const visual = nodeVisualScale(node);
3992
4450
  const corner = node.type === "rounded-rect" || node.type === "textbox" ? 16 : node.type === "junction" ? node.width / 2 : 6;
@@ -4002,8 +4460,15 @@ var VdFlowchart = class {
4002
4460
  group.appendChild(hitbox);
4003
4461
  const shape = this.renderNodeShape(node);
4004
4462
  this.applyScaledNodeShape(node, shape);
4463
+ if (node.fill) shape.style.fill = node.fill;
4464
+ if (node.stroke) shape.style.stroke = node.stroke;
4005
4465
  group.appendChild(shape);
4006
- group.appendChild(this.renderNodeText(node));
4466
+ const textEl = this.renderNodeText(node);
4467
+ if (node.textColor) textEl.style.fill = node.textColor;
4468
+ group.appendChild(textEl);
4469
+ if (node.locked) {
4470
+ group.appendChild(this.renderLockBadge(node));
4471
+ }
4007
4472
  const scale = this.documentData.viewport.scale || 1;
4008
4473
  if (soloSelected && !this.readonly && SELECTION_BOX_TYPES.has(node.type)) {
4009
4474
  const outset = SELECTION_OUTSET / scale;
@@ -4323,6 +4788,127 @@ var VdFlowchart = class {
4323
4788
  });
4324
4789
  return textElement;
4325
4790
  }
4791
+ buildInspectorColorSwatches(activePreset = "default", disabled = this.readonly) {
4792
+ const normalizedActive = activePreset || "default";
4793
+ const grid = createElement("div", { className: "vd-flowchart-swatch-grid" });
4794
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
4795
+ const active = preset === normalizedActive;
4796
+ const button = createElement("button", {
4797
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}${active ? " is-active" : ""}`,
4798
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset,
4799
+ disabled
4800
+ });
4801
+ button.setAttribute("type", "button");
4802
+ button.setAttribute("data-color-preset", preset);
4803
+ button.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
4804
+ button.setAttribute("aria-pressed", active ? "true" : "false");
4805
+ grid.appendChild(button);
4806
+ });
4807
+ return grid;
4808
+ }
4809
+ buildInspectorArrangeRow(disabled = this.readonly) {
4810
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4811
+ const actions = [
4812
+ {
4813
+ action: "bring-to-front",
4814
+ label: "Front",
4815
+ title: "Bring to front (Cmd/Ctrl+Shift+])"
4816
+ },
4817
+ {
4818
+ action: "bring-forward",
4819
+ label: "Forward",
4820
+ title: "Bring forward (Cmd/Ctrl+])"
4821
+ },
4822
+ {
4823
+ action: "send-backward",
4824
+ label: "Backward",
4825
+ title: "Send backward (Cmd/Ctrl+[)"
4826
+ },
4827
+ {
4828
+ action: "send-to-back",
4829
+ label: "Back",
4830
+ title: "Send to back (Cmd/Ctrl+Shift+[)"
4831
+ }
4832
+ ];
4833
+ actions.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
4839
+ });
4840
+ btn.setAttribute("type", "button");
4841
+ btn.setAttribute("data-arrange-action", item.action);
4842
+ grid.appendChild(btn);
4843
+ });
4844
+ return grid;
4845
+ }
4846
+ buildInspectorAlignRow(nodeCount, disabled = this.readonly) {
4847
+ const wrap = createElement("div", { className: "vd-flowchart-inspector-stack" });
4848
+ const alignGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4849
+ const alignments = [
4850
+ { action: "left", label: "Left", title: "Align left edges" },
4851
+ { action: "center", label: "Center", title: "Align horizontal centers" },
4852
+ { action: "right", label: "Right", title: "Align right edges" },
4853
+ { action: "top", label: "Top", title: "Align top edges" },
4854
+ { action: "middle", label: "Middle", title: "Align vertical centers" },
4855
+ { action: "bottom", label: "Bottom", title: "Align bottom edges" }
4856
+ ];
4857
+ alignments.forEach((item) => {
4858
+ const btn = createElement("button", {
4859
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4860
+ text: item.label,
4861
+ title: item.title,
4862
+ disabled: disabled || nodeCount < 2
4863
+ });
4864
+ btn.setAttribute("type", "button");
4865
+ btn.setAttribute("data-align-action", item.action);
4866
+ alignGrid.appendChild(btn);
4867
+ });
4868
+ wrap.appendChild(createField("Align", alignGrid));
4869
+ const distributeGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4870
+ [
4871
+ { action: "horizontal", label: "Distribute H", title: "Distribute horizontally" },
4872
+ { action: "vertical", label: "Distribute V", title: "Distribute vertically" }
4873
+ ].forEach((item) => {
4874
+ const btn = createElement("button", {
4875
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4876
+ text: item.label,
4877
+ title: item.title,
4878
+ disabled: disabled || nodeCount < 3
4879
+ });
4880
+ btn.setAttribute("type", "button");
4881
+ btn.setAttribute("data-distribute-action", item.action);
4882
+ distributeGrid.appendChild(btn);
4883
+ });
4884
+ wrap.appendChild(createField("Distribute", distributeGrid));
4885
+ return wrap;
4886
+ }
4887
+ buildInspectorUtilityRow({ showLock = true, locked = false, disabled = this.readonly } = {}) {
4888
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4889
+ if (showLock) {
4890
+ const lockBtn = createElement("button", {
4891
+ className: `vd-flowchart-btn vd-flowchart-action-btn${locked ? " is-active" : ""}`,
4892
+ text: locked ? "Unlock" : "Lock",
4893
+ title: "Toggle node lock (Cmd/Ctrl+L)",
4894
+ disabled
4895
+ });
4896
+ lockBtn.setAttribute("type", "button");
4897
+ lockBtn.setAttribute("data-lock-toggle", "");
4898
+ lockBtn.setAttribute("aria-pressed", locked ? "true" : "false");
4899
+ grid.appendChild(lockBtn);
4900
+ }
4901
+ const resetBtn = createElement("button", {
4902
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4903
+ text: "Reset color",
4904
+ title: "Reset to theme default color",
4905
+ disabled
4906
+ });
4907
+ resetBtn.setAttribute("type", "button");
4908
+ resetBtn.setAttribute("data-color-reset", "");
4909
+ grid.appendChild(resetBtn);
4910
+ return grid;
4911
+ }
4326
4912
  renderSelectionPanel() {
4327
4913
  clearChildren(this.selectionFields);
4328
4914
  this.deleteButton.disabled = this.readonly || !this.selection;
@@ -4337,6 +4923,11 @@ var VdFlowchart = class {
4337
4923
  return;
4338
4924
  }
4339
4925
  if (this.hasMultiSelection()) {
4926
+ const selectedIds = this.getSelectedNodeIds();
4927
+ const selectedNodes = selectedIds.map((id) => this.findNode(id)).filter(Boolean);
4928
+ const allLocked = selectedNodes.length > 0 && selectedNodes.every((n) => n.locked);
4929
+ this.deleteButton.disabled = this.readonly || allLocked;
4930
+ const sharedColor = selectedNodes.length > 0 && selectedNodes.every((n) => (n.color || "default") === (selectedNodes[0].color || "default")) ? selectedNodes[0].color || "default" : "";
4340
4931
  this.selectionMeta.textContent = `${this.selectedNodeIds.size} nodes selected`;
4341
4932
  this.selectionFields.appendChild(
4342
4933
  createElement("p", {
@@ -4344,6 +4935,22 @@ var VdFlowchart = class {
4344
4935
  text: "Drag, nudge with Alt+Arrow, copy, duplicate, or delete them together."
4345
4936
  })
4346
4937
  );
4938
+ this.selectionFields.appendChild(
4939
+ createField("Color preset", this.buildInspectorColorSwatches(sharedColor, this.readonly))
4940
+ );
4941
+ this.selectionFields.appendChild(
4942
+ this.buildInspectorAlignRow(selectedNodes.length, this.readonly)
4943
+ );
4944
+ this.selectionFields.appendChild(
4945
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
4946
+ );
4947
+ this.selectionFields.appendChild(
4948
+ this.buildInspectorUtilityRow({
4949
+ showLock: true,
4950
+ locked: allLocked,
4951
+ disabled: this.readonly
4952
+ })
4953
+ );
4347
4954
  return;
4348
4955
  }
4349
4956
  if (this.selection.kind === "node") {
@@ -4353,8 +4960,10 @@ var VdFlowchart = class {
4353
4960
  this.renderSelectionPanel();
4354
4961
  return;
4355
4962
  }
4356
- this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}`;
4357
- const typeSelect = createElement("select");
4963
+ const isLocked = Boolean(node.locked);
4964
+ this.deleteButton.disabled = this.readonly || isLocked;
4965
+ this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}${isLocked ? " \xB7 locked" : ""}`;
4966
+ const typeSelect = createElement("select", { disabled: this.readonly || isLocked });
4358
4967
  typeSelect.setAttribute("data-field", "node-type");
4359
4968
  FLOWCHART_NODE_TYPES.forEach((type) => {
4360
4969
  const option = createElement("option", { value: type, text: type.replace("-", " ") });
@@ -4362,13 +4971,25 @@ var VdFlowchart = class {
4362
4971
  option.selected = type === node.type;
4363
4972
  typeSelect.appendChild(option);
4364
4973
  });
4365
- const textArea = createElement("textarea", { value: node.text, rows: 5 });
4974
+ const textArea = createElement("textarea", {
4975
+ value: node.text,
4976
+ rows: 5,
4977
+ disabled: this.readonly || isLocked
4978
+ });
4366
4979
  textArea.setAttribute("data-field", "node-text");
4367
- const widthInput = createElement("input", { value: node.width, type: "number" });
4980
+ const widthInput = createElement("input", {
4981
+ value: node.width,
4982
+ type: "number",
4983
+ disabled: this.readonly || isLocked
4984
+ });
4368
4985
  widthInput.setAttribute("data-field", "node-width");
4369
4986
  widthInput.setAttribute("min", String(this.minNodeSize));
4370
4987
  widthInput.setAttribute("max", String(this.maxNodeSize));
4371
- const heightInput = createElement("input", { value: node.height, type: "number" });
4988
+ const heightInput = createElement("input", {
4989
+ value: node.height,
4990
+ type: "number",
4991
+ disabled: this.readonly || isLocked
4992
+ });
4372
4993
  heightInput.setAttribute("data-field", "node-height");
4373
4994
  heightInput.setAttribute("min", String(this.minNodeSize));
4374
4995
  heightInput.setAttribute("max", String(this.maxNodeSize));
@@ -4389,6 +5010,48 @@ var VdFlowchart = class {
4389
5010
  })
4390
5011
  );
4391
5012
  }
5013
+ this.selectionFields.appendChild(
5014
+ createField(
5015
+ "Color preset",
5016
+ this.buildInspectorColorSwatches(node.color || "default", this.readonly || isLocked)
5017
+ )
5018
+ );
5019
+ const customColorsGrid = createElement("div", { className: "vd-flowchart-field-grid" });
5020
+ const fillInput = createElement("input", {
5021
+ value: node.fill || "",
5022
+ type: "text",
5023
+ disabled: this.readonly || isLocked
5024
+ });
5025
+ fillInput.setAttribute("data-field", "node-fill");
5026
+ fillInput.setAttribute("placeholder", "Fill (e.g. #dbeafe)");
5027
+ const strokeInput = createElement("input", {
5028
+ value: node.stroke || "",
5029
+ type: "text",
5030
+ disabled: this.readonly || isLocked
5031
+ });
5032
+ strokeInput.setAttribute("data-field", "node-stroke");
5033
+ strokeInput.setAttribute("placeholder", "Stroke (e.g. #2563eb)");
5034
+ const textColorInput = createElement("input", {
5035
+ value: node.textColor || "",
5036
+ type: "text",
5037
+ disabled: this.readonly || isLocked
5038
+ });
5039
+ textColorInput.setAttribute("data-field", "node-text-color");
5040
+ textColorInput.setAttribute("placeholder", "Text (e.g. #1e3a8a)");
5041
+ customColorsGrid.appendChild(createField("Fill", fillInput));
5042
+ customColorsGrid.appendChild(createField("Border", strokeInput));
5043
+ this.selectionFields.appendChild(customColorsGrid);
5044
+ this.selectionFields.appendChild(createField("Text color", textColorInput));
5045
+ this.selectionFields.appendChild(
5046
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
5047
+ );
5048
+ this.selectionFields.appendChild(
5049
+ this.buildInspectorUtilityRow({
5050
+ showLock: true,
5051
+ locked: isLocked,
5052
+ disabled: this.readonly
5053
+ })
5054
+ );
4392
5055
  return;
4393
5056
  }
4394
5057
  const edge = this.findEdge(this.selection.id);
@@ -4397,8 +5060,9 @@ var VdFlowchart = class {
4397
5060
  this.renderSelectionPanel();
4398
5061
  return;
4399
5062
  }
5063
+ const edgeStyleName = normalizeEdgeStrokeStyle(edge.strokeStyle);
4400
5064
  this.selectionMeta.textContent = `Edge ${edge.id} \xB7 ${edge.route} \xB7 ${formatNumber(edge.strokeWidth)}px \xB7 ${edge.startMarker} \u2192 ${edge.endMarker}`;
4401
- const routeSelect = createElement("select");
5065
+ const routeSelect = createElement("select", { disabled: this.readonly });
4402
5066
  routeSelect.setAttribute("data-field", "edge-route");
4403
5067
  FLOWCHART_EDGE_ROUTES.forEach((route) => {
4404
5068
  const option = createElement("option", {
@@ -4409,7 +5073,7 @@ var VdFlowchart = class {
4409
5073
  option.selected = route === edge.route;
4410
5074
  routeSelect.appendChild(option);
4411
5075
  });
4412
- const startSelect = createElement("select");
5076
+ const startSelect = createElement("select", { disabled: this.readonly });
4413
5077
  startSelect.setAttribute("data-field", "edge-start-marker");
4414
5078
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4415
5079
  const option = createElement("option", { value: marker, text: marker });
@@ -4417,7 +5081,7 @@ var VdFlowchart = class {
4417
5081
  option.selected = marker === edge.startMarker;
4418
5082
  startSelect.appendChild(option);
4419
5083
  });
4420
- const endSelect = createElement("select");
5084
+ const endSelect = createElement("select", { disabled: this.readonly });
4421
5085
  endSelect.setAttribute("data-field", "edge-end-marker");
4422
5086
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4423
5087
  const option = createElement("option", { value: marker, text: marker });
@@ -4425,7 +5089,7 @@ var VdFlowchart = class {
4425
5089
  option.selected = marker === edge.endMarker;
4426
5090
  endSelect.appendChild(option);
4427
5091
  });
4428
- const widthSelect = createElement("select");
5092
+ const widthSelect = createElement("select", { disabled: this.readonly });
4429
5093
  widthSelect.setAttribute("data-field", "edge-stroke-preset");
4430
5094
  EDGE_STROKE_PRESETS.forEach((preset) => {
4431
5095
  const option = createElement("option", { value: preset.id, text: preset.label });
@@ -4433,15 +5097,52 @@ var VdFlowchart = class {
4433
5097
  option.selected = preset.id === getStrokePresetId(edge.strokeWidth);
4434
5098
  widthSelect.appendChild(option);
4435
5099
  });
4436
- const labelInput = createElement("textarea", { value: edge.label, rows: 4 });
5100
+ const strokeStyleSelect = createElement("select", { disabled: this.readonly });
5101
+ strokeStyleSelect.setAttribute("data-field", "edge-stroke-style");
5102
+ FLOWCHART_EDGE_STROKE_STYLES.forEach((style) => {
5103
+ const option = createElement("option", {
5104
+ value: style,
5105
+ text: FLOWCHART_EDGE_STROKE_STYLE_LABELS[style] || style
5106
+ });
5107
+ option.value = style;
5108
+ option.selected = style === edgeStyleName;
5109
+ strokeStyleSelect.appendChild(option);
5110
+ });
5111
+ const labelInput = createElement("textarea", {
5112
+ value: edge.label,
5113
+ rows: 4,
5114
+ disabled: this.readonly
5115
+ });
4437
5116
  labelInput.setAttribute("data-field", "edge-label");
4438
5117
  const markerGrid = createElement("div", { className: "vd-flowchart-field-grid" });
4439
5118
  markerGrid.appendChild(createField("Route", routeSelect));
4440
5119
  markerGrid.appendChild(createField("Weight", widthSelect));
5120
+ markerGrid.appendChild(createField("Style", strokeStyleSelect));
4441
5121
  markerGrid.appendChild(createField("Start", startSelect));
4442
5122
  markerGrid.appendChild(createField("End", endSelect));
4443
5123
  this.selectionFields.appendChild(markerGrid);
4444
5124
  this.selectionFields.appendChild(createField("Label", labelInput));
5125
+ const activeEdgePreset = edge.color && FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "default";
5126
+ this.selectionFields.appendChild(
5127
+ createField(
5128
+ "Color preset",
5129
+ this.buildInspectorColorSwatches(activeEdgePreset, this.readonly)
5130
+ )
5131
+ );
5132
+ const edgeColorInput = createElement("input", {
5133
+ value: edge.color && !FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "",
5134
+ type: "text",
5135
+ disabled: this.readonly
5136
+ });
5137
+ edgeColorInput.setAttribute("data-field", "edge-color");
5138
+ edgeColorInput.setAttribute("placeholder", "Custom color (e.g. #2563eb)");
5139
+ this.selectionFields.appendChild(createField("Custom color", edgeColorInput));
5140
+ this.selectionFields.appendChild(
5141
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
5142
+ );
5143
+ this.selectionFields.appendChild(
5144
+ this.buildInspectorUtilityRow({ showLock: false, disabled: this.readonly })
5145
+ );
4445
5146
  }
4446
5147
  syncJsonTextarea(force = false) {
4447
5148
  if (!force && document.activeElement === this.jsonTextarea) {
@@ -4847,7 +5548,14 @@ var VdFlowchart = class {
4847
5548
  // the parent's box shape, falling back to a rounded step.
4848
5549
  getBranchTemplate(parent, sibling) {
4849
5550
  const source = sibling || (["rounded-rect", "rect", "textbox"].includes(parent.type) ? parent : null) || null;
4850
- if (source) return { type: source.type, width: source.width, height: source.height };
5551
+ if (source) {
5552
+ const template = { type: source.type, width: source.width, height: source.height };
5553
+ if (source.color) template.color = source.color;
5554
+ if (source.fill) template.fill = source.fill;
5555
+ if (source.stroke) template.stroke = source.stroke;
5556
+ if (source.textColor) template.textColor = source.textColor;
5557
+ return template;
5558
+ }
4851
5559
  const spec = DEFAULT_NODE_SPECS["rounded-rect"];
4852
5560
  return { type: "rounded-rect", width: spec.width, height: spec.height };
4853
5561
  }
@@ -4883,7 +5591,9 @@ var VdFlowchart = class {
4883
5591
  route: styleSource.route,
4884
5592
  strokeWidth: styleSource.strokeWidth,
4885
5593
  startMarker: styleSource.startMarker,
4886
- endMarker: styleSource.endMarker
5594
+ endMarker: styleSource.endMarker,
5595
+ ...styleSource.color ? { color: styleSource.color } : {},
5596
+ ...styleSource.strokeStyle ? { strokeStyle: styleSource.strokeStyle } : {}
4887
5597
  } : { endMarker: "arrow" };
4888
5598
  const result = this.batchHistory("node:insert", () => {
4889
5599
  if (parent.collapsed) delete parent.collapsed;
@@ -5101,6 +5811,30 @@ var VdFlowchart = class {
5101
5811
  node.text = isNodeTextEditable(nextType) ? patch.text == null ? node.text : String(patch.text) : getNodeSpec(nextType).text;
5102
5812
  node.width = clampNodeWidth(nextType, patch.width, node.width, this.nodeSizeBounds());
5103
5813
  node.height = clampNodeHeight(nextType, patch.height, node.height, this.nodeSizeBounds());
5814
+ if ("color" in patch) {
5815
+ const nextColor = normalizeColorPreset(patch.color);
5816
+ if (nextColor) node.color = nextColor;
5817
+ else delete node.color;
5818
+ }
5819
+ if ("fill" in patch) {
5820
+ const nextFill = sanitizeCssColor(patch.fill);
5821
+ if (nextFill) node.fill = nextFill;
5822
+ else delete node.fill;
5823
+ }
5824
+ if ("stroke" in patch) {
5825
+ const nextStroke = sanitizeCssColor(patch.stroke);
5826
+ if (nextStroke) node.stroke = nextStroke;
5827
+ else delete node.stroke;
5828
+ }
5829
+ if ("textColor" in patch) {
5830
+ const nextTextColor = sanitizeCssColor(patch.textColor);
5831
+ if (nextTextColor) node.textColor = nextTextColor;
5832
+ else delete node.textColor;
5833
+ }
5834
+ if ("locked" in patch) {
5835
+ if (patch.locked) node.locked = true;
5836
+ else delete node.locked;
5837
+ }
5104
5838
  if (isPlainObject(patch.data)) {
5105
5839
  node.data = deepClone(patch.data);
5106
5840
  }
@@ -5108,6 +5842,11 @@ var VdFlowchart = class {
5108
5842
  updateNode(nodeId, patch = {}, options = {}) {
5109
5843
  const node = this.findNode(nodeId);
5110
5844
  if (!node) return null;
5845
+ if (node.locked) {
5846
+ const keys = Object.keys(patch);
5847
+ const unlocking = keys.length > 0 && keys.every((key) => key === "locked") && !patch.locked;
5848
+ if (!unlocking) return null;
5849
+ }
5111
5850
  const previousType = node.type;
5112
5851
  const previousSpec = DEFAULT_NODE_SPECS[previousType];
5113
5852
  this.applyNodePatch(node, patch);
@@ -5212,6 +5951,16 @@ var VdFlowchart = class {
5212
5951
  if (patch.label != null) {
5213
5952
  edge.label = String(patch.label);
5214
5953
  }
5954
+ if ("color" in patch) {
5955
+ const nextColor = normalizeEdgeColor(patch.color);
5956
+ if (nextColor) edge.color = nextColor;
5957
+ else delete edge.color;
5958
+ }
5959
+ if ("strokeStyle" in patch) {
5960
+ const nextStrokeStyle = normalizeEdgeStrokeStyle(patch.strokeStyle);
5961
+ if (nextStrokeStyle && nextStrokeStyle !== "solid") edge.strokeStyle = nextStrokeStyle;
5962
+ else delete edge.strokeStyle;
5963
+ }
5215
5964
  if (isPlainObject(patch.data)) {
5216
5965
  edge.data = deepClone(patch.data);
5217
5966
  }
@@ -5284,11 +6033,461 @@ var VdFlowchart = class {
5284
6033
  deleteSelection() {
5285
6034
  if (!this.selection || this.readonly) return false;
5286
6035
  if (this.hasMultiSelection()) {
5287
- return this.removeNodeIds(new Set(this.getSelectedNodeIds()), "node:remove");
6036
+ const unlockedIds = this.getSelectedNodeIds().filter((id) => !this.findNode(id)?.locked);
6037
+ if (!unlockedIds.length) return false;
6038
+ return this.removeNodeIds(new Set(unlockedIds), "node:remove");
6039
+ }
6040
+ if (this.selection.kind === "node") {
6041
+ const node = this.findNode(this.selection.id);
6042
+ if (node?.locked) return false;
6043
+ return this.removeNode(this.selection.id);
5288
6044
  }
5289
- if (this.selection.kind === "node") return this.removeNode(this.selection.id);
5290
6045
  return this.removeEdge(this.selection.id);
5291
6046
  }
6047
+ // --- Coloring, Layer Order, Align/Distribute, Locking, SVG Export ---------
6048
+ setNodeColor(nodeId, colorOrPatch) {
6049
+ if (this.readonly) return null;
6050
+ const id = sanitizeId(nodeId);
6051
+ if (!this.findNode(id)) return null;
6052
+ let patch;
6053
+ if (isPlainObject(colorOrPatch)) {
6054
+ patch = {};
6055
+ if ("color" in colorOrPatch) patch.color = colorOrPatch.color;
6056
+ if ("fill" in colorOrPatch) patch.fill = colorOrPatch.fill;
6057
+ if ("stroke" in colorOrPatch) patch.stroke = colorOrPatch.stroke;
6058
+ if ("textColor" in colorOrPatch) patch.textColor = colorOrPatch.textColor;
6059
+ } else if (colorOrPatch == null || colorOrPatch === "" || colorOrPatch === "default") {
6060
+ patch = { color: null, fill: null, stroke: null, textColor: null };
6061
+ } else {
6062
+ const token = String(colorOrPatch).trim();
6063
+ if (FLOWCHART_COLOR_PRESET_SET.has(token)) {
6064
+ patch = { color: token, fill: null, stroke: null, textColor: null };
6065
+ } else {
6066
+ const css = sanitizeCssColor(token);
6067
+ if (!css) return null;
6068
+ patch = { fill: css };
6069
+ }
6070
+ }
6071
+ return this.updateNode(id, patch, { reason: "node:color" });
6072
+ }
6073
+ setEdgeColor(edgeId, color) {
6074
+ if (this.readonly) return null;
6075
+ const id = sanitizeId(edgeId);
6076
+ if (!this.findEdge(id)) return null;
6077
+ const nextColor = color == null || color === "" || color === "default" ? null : isPlainObject(color) ? normalizeEdgeColor(color.color ?? color.stroke) : normalizeEdgeColor(color);
6078
+ return this.updateEdge(id, { color: nextColor }, { reason: "edge:color" });
6079
+ }
6080
+ setSelectionColor(colorOrPatch) {
6081
+ if (this.readonly || !this.selection) return this;
6082
+ if (this.selection.kind === "edge") {
6083
+ this.setEdgeColor(this.selection.id, colorOrPatch);
6084
+ return this;
6085
+ }
6086
+ const ids = this.getSelectedNodeIds();
6087
+ if (!ids.length) return this;
6088
+ this.batchHistory("node:color", () => {
6089
+ ids.forEach((id) => {
6090
+ this.setNodeColor(id, colorOrPatch);
6091
+ });
6092
+ });
6093
+ return this;
6094
+ }
6095
+ clearSelectionColor() {
6096
+ return this.setSelectionColor(null);
6097
+ }
6098
+ reorderArrayLayer(items, targetIds, direction) {
6099
+ const idSet = new Set(targetIds);
6100
+ if (!idSet.size || items.length < 2) return null;
6101
+ let next;
6102
+ if (direction === "front") {
6103
+ next = [
6104
+ ...items.filter((item) => !idSet.has(item.id)),
6105
+ ...items.filter((item) => idSet.has(item.id))
6106
+ ];
6107
+ } else if (direction === "back") {
6108
+ next = [
6109
+ ...items.filter((item) => idSet.has(item.id)),
6110
+ ...items.filter((item) => !idSet.has(item.id))
6111
+ ];
6112
+ } else if (direction === "forward") {
6113
+ next = [...items];
6114
+ for (let i = next.length - 2; i >= 0; i -= 1) {
6115
+ if (idSet.has(next[i].id) && !idSet.has(next[i + 1].id)) {
6116
+ const temp = next[i];
6117
+ next[i] = next[i + 1];
6118
+ next[i + 1] = temp;
6119
+ }
6120
+ }
6121
+ } else if (direction === "backward") {
6122
+ next = [...items];
6123
+ for (let i = 1; i < next.length; i += 1) {
6124
+ if (idSet.has(next[i].id) && !idSet.has(next[i - 1].id)) {
6125
+ const temp = next[i];
6126
+ next[i] = next[i - 1];
6127
+ next[i - 1] = temp;
6128
+ }
6129
+ }
6130
+ } else {
6131
+ return null;
6132
+ }
6133
+ const changed = next.some((item, index) => item.id !== items[index].id);
6134
+ return changed ? next : null;
6135
+ }
6136
+ reorderLayer(direction, targetId) {
6137
+ if (this.readonly) return this;
6138
+ let explicitIds = [];
6139
+ if (Array.isArray(targetId)) {
6140
+ explicitIds = targetId.map(sanitizeId).filter(Boolean);
6141
+ } else if (typeof targetId === "string" && targetId.trim()) {
6142
+ explicitIds = [sanitizeId(targetId)];
6143
+ }
6144
+ if (explicitIds.length) {
6145
+ const nodeIdSet = new Set(this.documentData.nodes.map((n) => n.id));
6146
+ const matchingNodes = explicitIds.filter((id) => nodeIdSet.has(id));
6147
+ if (matchingNodes.length) {
6148
+ const reordered2 = this.reorderArrayLayer(this.documentData.nodes, matchingNodes, direction);
6149
+ if (reordered2) {
6150
+ this.documentData.nodes = reordered2;
6151
+ this.render();
6152
+ this.emitChange("node:order", { direction, nodeIds: matchingNodes });
6153
+ }
6154
+ return this;
6155
+ }
6156
+ const edgeIdSet = new Set(this.documentData.edges.map((e) => e.id));
6157
+ const matchingEdges = explicitIds.filter((id) => edgeIdSet.has(id));
6158
+ if (matchingEdges.length) {
6159
+ const reordered2 = this.reorderArrayLayer(this.documentData.edges, matchingEdges, direction);
6160
+ if (reordered2) {
6161
+ this.documentData.edges = reordered2;
6162
+ this.render();
6163
+ this.emitChange("edge:order", { direction, edgeIds: matchingEdges });
6164
+ }
6165
+ }
6166
+ return this;
6167
+ }
6168
+ if (!this.selection) return this;
6169
+ if (this.selection.kind === "edge") {
6170
+ const reordered2 = this.reorderArrayLayer(
6171
+ this.documentData.edges,
6172
+ [this.selection.id],
6173
+ direction
6174
+ );
6175
+ if (reordered2) {
6176
+ this.documentData.edges = reordered2;
6177
+ this.render();
6178
+ this.emitChange("edge:order", { direction, edgeIds: [this.selection.id] });
6179
+ }
6180
+ return this;
6181
+ }
6182
+ const ids = this.getSelectedNodeIds();
6183
+ const reordered = this.reorderArrayLayer(this.documentData.nodes, ids, direction);
6184
+ if (reordered) {
6185
+ this.documentData.nodes = reordered;
6186
+ this.render();
6187
+ this.emitChange("node:order", { direction, nodeIds: ids });
6188
+ }
6189
+ return this;
6190
+ }
6191
+ bringToFront(targetId) {
6192
+ return this.reorderLayer("front", targetId);
6193
+ }
6194
+ bringForward(targetId) {
6195
+ return this.reorderLayer("forward", targetId);
6196
+ }
6197
+ sendBackward(targetId) {
6198
+ return this.reorderLayer("backward", targetId);
6199
+ }
6200
+ sendToBack(targetId) {
6201
+ return this.reorderLayer("back", targetId);
6202
+ }
6203
+ alignNodes(alignment = "left", nodeIds) {
6204
+ if (this.readonly || !FLOWCHART_NODE_ALIGNMENTS.includes(alignment)) return this;
6205
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6206
+ const hidden = this.getHiddenNodeIds();
6207
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6208
+ if (nodes.length < 2) return this;
6209
+ const bounds = getBounds(nodes);
6210
+ const centerX = (bounds.left + bounds.right) / 2;
6211
+ const centerY = (bounds.top + bounds.bottom) / 2;
6212
+ const movedIds = [];
6213
+ nodes.forEach((node) => {
6214
+ if (node.locked) return;
6215
+ let nextX = node.x;
6216
+ let nextY = node.y;
6217
+ if (alignment === "left") nextX = formatNumber(bounds.left);
6218
+ else if (alignment === "center") nextX = formatNumber(centerX - node.width / 2);
6219
+ else if (alignment === "right") nextX = formatNumber(bounds.right - node.width);
6220
+ else if (alignment === "top") nextY = formatNumber(bounds.top);
6221
+ else if (alignment === "middle") nextY = formatNumber(centerY - node.height / 2);
6222
+ else if (alignment === "bottom") nextY = formatNumber(bounds.bottom - node.height);
6223
+ if (nextX !== node.x || nextY !== node.y) {
6224
+ node.x = nextX;
6225
+ node.y = nextY;
6226
+ movedIds.push(node.id);
6227
+ }
6228
+ });
6229
+ if (movedIds.length) {
6230
+ this.render();
6231
+ this.emitChange("node:align", { alignment, nodeIds: movedIds });
6232
+ }
6233
+ return this;
6234
+ }
6235
+ distributeNodes(axis = "horizontal", nodeIds) {
6236
+ if (this.readonly || !FLOWCHART_DISTRIBUTE_AXES.includes(axis)) return this;
6237
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6238
+ const hidden = this.getHiddenNodeIds();
6239
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6240
+ if (nodes.length < 3) return this;
6241
+ const sorted = [...nodes].sort(
6242
+ (a, b) => axis === "horizontal" ? a.x + a.width / 2 - (b.x + b.width / 2) : a.y + a.height / 2 - (b.y + b.height / 2)
6243
+ );
6244
+ const first = sorted[0];
6245
+ const last = sorted[sorted.length - 1];
6246
+ const movedIds = [];
6247
+ if (axis === "horizontal") {
6248
+ const totalSpan = last.x + last.width - first.x;
6249
+ const totalSize = sorted.reduce((sum, node) => sum + node.width, 0);
6250
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6251
+ let cursor = first.x;
6252
+ sorted.forEach((node, index) => {
6253
+ if (index > 0 && index < sorted.length - 1) {
6254
+ if (node.locked) {
6255
+ cursor = node.x + node.width + gap;
6256
+ return;
6257
+ }
6258
+ const nextX = formatNumber(cursor);
6259
+ if (nextX !== node.x) {
6260
+ node.x = nextX;
6261
+ movedIds.push(node.id);
6262
+ }
6263
+ }
6264
+ cursor += node.width + gap;
6265
+ });
6266
+ } else {
6267
+ const totalSpan = last.y + last.height - first.y;
6268
+ const totalSize = sorted.reduce((sum, node) => sum + node.height, 0);
6269
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6270
+ let cursor = first.y;
6271
+ sorted.forEach((node, index) => {
6272
+ if (index > 0 && index < sorted.length - 1) {
6273
+ if (node.locked) {
6274
+ cursor = node.y + node.height + gap;
6275
+ return;
6276
+ }
6277
+ const nextY = formatNumber(cursor);
6278
+ if (nextY !== node.y) {
6279
+ node.y = nextY;
6280
+ movedIds.push(node.id);
6281
+ }
6282
+ }
6283
+ cursor += node.height + gap;
6284
+ });
6285
+ }
6286
+ if (movedIds.length) {
6287
+ this.render();
6288
+ this.emitChange("node:distribute", { axis, nodeIds: movedIds });
6289
+ }
6290
+ return this;
6291
+ }
6292
+ setNodeLocked(nodeId, locked = true) {
6293
+ if (this.readonly) return false;
6294
+ let targetIds;
6295
+ let nextLocked = Boolean(locked);
6296
+ if (typeof nodeId === "boolean") {
6297
+ nextLocked = nodeId;
6298
+ targetIds = this.getSelectedNodeIds();
6299
+ } else if (Array.isArray(nodeId)) {
6300
+ targetIds = nodeId.map(sanitizeId).filter(Boolean);
6301
+ } else if (nodeId == null) {
6302
+ targetIds = this.getSelectedNodeIds();
6303
+ } else {
6304
+ targetIds = [sanitizeId(nodeId)];
6305
+ }
6306
+ const changedNodes = [];
6307
+ targetIds.forEach((id) => {
6308
+ const node = this.findNode(id);
6309
+ if (!node || Boolean(node.locked) === nextLocked) return;
6310
+ if (nextLocked) node.locked = true;
6311
+ else delete node.locked;
6312
+ changedNodes.push(deepClone(node));
6313
+ });
6314
+ if (!changedNodes.length) return false;
6315
+ if (nextLocked && this.textEditor && targetIds.includes(this.textEditor.nodeId)) {
6316
+ this.stopTextEdit({ commit: true });
6317
+ }
6318
+ this.render();
6319
+ this.emitChange("node:lock", {
6320
+ node: changedNodes[0],
6321
+ nodes: changedNodes,
6322
+ locked: nextLocked
6323
+ });
6324
+ return true;
6325
+ }
6326
+ toggleNodeLocked(nodeId) {
6327
+ if (this.readonly) return false;
6328
+ if (nodeId != null && typeof nodeId !== "boolean" && !Array.isArray(nodeId)) {
6329
+ const node = this.findNode(sanitizeId(nodeId));
6330
+ return node ? this.setNodeLocked(node.id, !node.locked) : false;
6331
+ }
6332
+ const ids = Array.isArray(nodeId) ? nodeId.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6333
+ const nodes = ids.map((id) => this.findNode(id)).filter(Boolean);
6334
+ if (!nodes.length) return false;
6335
+ const shouldLock = nodes.some((node) => !node.locked);
6336
+ return this.setNodeLocked(ids, shouldLock);
6337
+ }
6338
+ exportSvg(options = {}) {
6339
+ const padding = Math.max(0, toFiniteNumber(options.padding, 32));
6340
+ const visibleNodes = this.getVisibleNodes();
6341
+ let viewX = 0;
6342
+ let viewY = 0;
6343
+ let viewWidth = 800;
6344
+ let viewHeight = 560;
6345
+ if (visibleNodes.length) {
6346
+ const bounds = getBounds(visibleNodes);
6347
+ viewX = formatNumber(bounds.left - padding);
6348
+ viewY = formatNumber(bounds.top - padding);
6349
+ viewWidth = formatNumber(Math.max(1, bounds.right - bounds.left + padding * 2));
6350
+ viewHeight = formatNumber(Math.max(1, bounds.bottom - bounds.top + padding * 2));
6351
+ }
6352
+ const exportRoot = svgEl("svg", {
6353
+ xmlns: SVG_NS,
6354
+ viewBox: `${viewX} ${viewY} ${viewWidth} ${viewHeight}`,
6355
+ width: viewWidth,
6356
+ height: viewHeight,
6357
+ class: "vd-flowchart-export"
6358
+ });
6359
+ const isDarkTheme = (() => {
6360
+ const explicitTheme = this.element?.closest?.("[data-theme]")?.getAttribute("data-theme") || document.documentElement?.getAttribute("data-theme");
6361
+ if (explicitTheme === "dark") return true;
6362
+ if (explicitTheme === "light") return false;
6363
+ return Boolean(window.matchMedia?.("(prefers-color-scheme: dark)")?.matches);
6364
+ })();
6365
+ const presetFallbacks = isDarkTheme ? FLOWCHART_COLOR_PRESET_DARK_FALLBACKS : FLOWCHART_COLOR_PRESET_FALLBACKS;
6366
+ const computedStyle = typeof window.getComputedStyle === "function" ? window.getComputedStyle(this.root || this.element) : null;
6367
+ const readCssVar = (name, fallback) => {
6368
+ const val = computedStyle?.getPropertyValue(name)?.trim();
6369
+ return val && !val.includes("var(") ? val : fallback;
6370
+ };
6371
+ const defaultSurface = readCssVar(
6372
+ "--vd-flowchart-surface",
6373
+ readCssVar("--vd-bg-primary", isDarkTheme ? "#0f172a" : "#ffffff")
6374
+ );
6375
+ const defaultNodeFill = readCssVar(
6376
+ "--vd-flowchart-node-fill",
6377
+ isDarkTheme ? "#1e293b" : "#ffffff"
6378
+ );
6379
+ const defaultNodeStroke = readCssVar(
6380
+ "--vd-flowchart-node-stroke",
6381
+ isDarkTheme ? "#94a3b8" : "#475569"
6382
+ );
6383
+ const defaultNodeText = readCssVar(
6384
+ "--vd-flowchart-node-text",
6385
+ isDarkTheme ? "#f1f5f9" : "#0f172a"
6386
+ );
6387
+ const defaultEdgeStroke = readCssVar(
6388
+ "--vd-flowchart-edge-stroke",
6389
+ isDarkTheme ? "#94a3b8" : "#475569"
6390
+ );
6391
+ const resolvePresetColor = (presetName, slot) => {
6392
+ const fallback = presetFallbacks[presetName]?.[slot];
6393
+ if (!fallback) return null;
6394
+ return readCssVar(`--vd-flowchart-palette-${presetName}-${slot}`, fallback);
6395
+ };
6396
+ const hasAnimatedEdge = this.documentData.edges.some((edge) => edge.strokeStyle === "animated");
6397
+ const styleEl = svgEl("style");
6398
+ const styleRules = [
6399
+ '.vd-flowchart-export { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }',
6400
+ `.vd-flowchart-node-shape { fill: ${defaultNodeFill}; stroke: ${defaultNodeStroke}; stroke-width: 2px; }`,
6401
+ ".vd-flowchart-node--textbox .vd-flowchart-node-shape { stroke-dasharray: 6 4; }",
6402
+ `.vd-flowchart-node--junction .vd-flowchart-node-shape { fill: #2563eb; stroke: ${defaultNodeFill}; }`,
6403
+ `.vd-flowchart-node-text { fill: ${defaultNodeText}; font-size: 14px; font-weight: 600; dominant-baseline: middle; text-anchor: middle; }`,
6404
+ `.vd-flowchart-edge-path { fill: none; stroke: ${defaultEdgeStroke}; stroke-linecap: round; stroke-linejoin: round; }`,
6405
+ `.vd-flowchart-edge-label { fill: ${defaultNodeText}; font-size: 12px; font-weight: 600; paint-order: stroke; stroke: ${defaultSurface}; stroke-width: 5px; }`
6406
+ ];
6407
+ if (hasAnimatedEdge) {
6408
+ styleRules.push(
6409
+ "@keyframes vd-flowchart-edge-flow { to { stroke-dashoffset: -26; } }",
6410
+ ".vd-flowchart-edge.is-stroke-animated .vd-flowchart-edge-path { animation: vd-flowchart-edge-flow 900ms linear infinite; }",
6411
+ "@media (prefers-reduced-motion: reduce) { .vd-flowchart-edge.is-stroke-animated .vd-flowchart-edge-path { animation: none; } }"
6412
+ );
6413
+ }
6414
+ styleEl.textContent = styleRules.join("\n");
6415
+ exportRoot.appendChild(styleEl);
6416
+ if (this.markerDefs) {
6417
+ const defsClone = this.markerDefs.cloneNode(true);
6418
+ defsClone.querySelectorAll("path, circle").forEach((shape) => {
6419
+ const fill = shape.getAttribute("fill") || "";
6420
+ const preset = fill.match(/--vd-flowchart-palette-([a-z]+)-edge/);
6421
+ if (preset) {
6422
+ const resolved = resolvePresetColor(preset[1], "edge");
6423
+ if (resolved) {
6424
+ shape.setAttribute("fill", resolved);
6425
+ return;
6426
+ }
6427
+ }
6428
+ if (fill.includes("var(")) shape.setAttribute("fill", defaultEdgeStroke);
6429
+ });
6430
+ exportRoot.appendChild(defsClone);
6431
+ }
6432
+ if (typeof options.background === "string" && options.background.trim() && options.background.trim() !== "transparent") {
6433
+ const bgColor = options.background.trim() === "theme" ? defaultSurface : sanitizeCssColor(options.background.trim()) || defaultSurface;
6434
+ exportRoot.appendChild(
6435
+ svgEl("rect", {
6436
+ x: viewX,
6437
+ y: viewY,
6438
+ width: viewWidth,
6439
+ height: viewHeight,
6440
+ fill: bgColor
6441
+ })
6442
+ );
6443
+ }
6444
+ const sceneGroup = svgEl("g", { class: "vd-flowchart-export-scene" });
6445
+ const edgesClone = this.edgesLayer.cloneNode(true);
6446
+ edgesClone.querySelectorAll(".vd-flowchart-edge-hit, .vd-flowchart-edge-selection").forEach((el) => el.remove());
6447
+ edgesClone.querySelectorAll(".vd-flowchart-edge").forEach((edgeGroup) => {
6448
+ edgeGroup.classList.remove("is-selected", "is-reconnecting");
6449
+ const edgeId = edgeGroup.getAttribute("data-edge-id");
6450
+ const edge = this.findEdge(edgeId);
6451
+ const pathEl = edgeGroup.querySelector(".vd-flowchart-edge-path");
6452
+ if (edge && pathEl) {
6453
+ const stroke = edge.color ? resolvePresetColor(edge.color, "edge") || edge.color : defaultEdgeStroke;
6454
+ pathEl.setAttribute("stroke", stroke);
6455
+ pathEl.style.stroke = stroke;
6456
+ }
6457
+ });
6458
+ const nodesClone = this.nodesLayer.cloneNode(true);
6459
+ nodesClone.querySelectorAll(
6460
+ ".vd-flowchart-ports, .vd-flowchart-resize-handles, .vd-flowchart-node-lock, .vd-flowchart-collapse-badge, .vd-flowchart-selection-box"
6461
+ ).forEach((el) => el.remove());
6462
+ nodesClone.querySelectorAll(".vd-flowchart-node").forEach((nodeGroup) => {
6463
+ nodeGroup.classList.remove("is-selected", "is-multi-selected", "is-dragging");
6464
+ const nodeId = nodeGroup.getAttribute("data-node-id");
6465
+ const node = this.findNode(nodeId);
6466
+ if (!node) return;
6467
+ const shapeEl = nodeGroup.querySelector(".vd-flowchart-node-shape");
6468
+ const labelEl = nodeGroup.querySelector(".vd-flowchart-node-text");
6469
+ const presetFill = node.color ? resolvePresetColor(node.color, "fill") : null;
6470
+ const presetStroke = node.color ? resolvePresetColor(node.color, "stroke") : null;
6471
+ const presetText = node.color ? resolvePresetColor(node.color, "text") : null;
6472
+ if (shapeEl) {
6473
+ const fill = node.fill || presetFill || (node.type === "junction" ? "#2563eb" : defaultNodeFill);
6474
+ const stroke = node.stroke || presetStroke || (node.type === "junction" ? defaultNodeFill : defaultNodeStroke);
6475
+ shapeEl.setAttribute("fill", fill);
6476
+ shapeEl.setAttribute("stroke", stroke);
6477
+ shapeEl.style.fill = fill;
6478
+ shapeEl.style.stroke = stroke;
6479
+ }
6480
+ if (labelEl) {
6481
+ const textColor = node.textColor || presetText || defaultNodeText;
6482
+ labelEl.setAttribute("fill", textColor);
6483
+ labelEl.style.fill = textColor;
6484
+ }
6485
+ });
6486
+ sceneGroup.appendChild(edgesClone);
6487
+ sceneGroup.appendChild(nodesClone);
6488
+ exportRoot.appendChild(sceneGroup);
6489
+ return exportRoot.outerHTML;
6490
+ }
5292
6491
  nodeSizeBounds() {
5293
6492
  return { min: this.minNodeSize, max: this.maxNodeSize };
5294
6493
  }
@@ -5429,13 +6628,45 @@ var VdFlowchart = class {
5429
6628
  if ("readonly" in options) {
5430
6629
  if (options.readonly && !this.readonly) {
5431
6630
  this.stopTextEdit({ commit: true });
5432
- this.interaction = null;
6631
+ if (this.interaction) {
6632
+ const active = this.interaction;
6633
+ if (active.kind === "drag-node" && active.origins) {
6634
+ active.origins.forEach((origin, id) => {
6635
+ const node = this.findNode(id);
6636
+ if (node) {
6637
+ node.x = origin.x;
6638
+ node.y = origin.y;
6639
+ }
6640
+ });
6641
+ } else if (active.kind === "resize-node" && active.original) {
6642
+ const node = this.findNode(active.nodeId);
6643
+ if (node) {
6644
+ node.x = active.original.x;
6645
+ node.y = active.original.y;
6646
+ node.width = active.original.width;
6647
+ node.height = active.original.height;
6648
+ }
6649
+ }
6650
+ if (active.pointerId != null && typeof this.canvasEl?.releasePointerCapture === "function") {
6651
+ try {
6652
+ this.canvasEl.releasePointerCapture(active.pointerId);
6653
+ } catch {
6654
+ }
6655
+ }
6656
+ this.renderGuides([]);
6657
+ this.interaction = null;
6658
+ this.render({ inspector: false, json: false });
6659
+ }
5433
6660
  this.activeTool = null;
5434
6661
  this.reconnectEdgeId = null;
5435
6662
  }
5436
6663
  this.readonly = Boolean(options.readonly);
6664
+ if (this.readonly && this.colorPopoverOpen) {
6665
+ this.toggleColorPopover(false);
6666
+ }
5437
6667
  this.root.classList.toggle("vd-flowchart-readonly", this.readonly);
5438
6668
  this.arrangeSelect.disabled = this.readonly;
6669
+ if (this.colorButton) this.colorButton.disabled = this.readonly;
5439
6670
  this.clearButton.disabled = this.readonly;
5440
6671
  this.loadJsonButton.disabled = this.readonly;
5441
6672
  }
@@ -5538,6 +6769,14 @@ var VdFlowchart = class {
5538
6769
  cancelAnimationFrame(this.minimapFrame);
5539
6770
  }
5540
6771
  this.minimapFrame = 0;
6772
+ if (this.readyFrame) {
6773
+ if (this.readyFrameIsTimeout) {
6774
+ clearTimeout(this.readyFrame);
6775
+ } else if (typeof cancelAnimationFrame === "function") {
6776
+ cancelAnimationFrame(this.readyFrame);
6777
+ }
6778
+ this.readyFrame = 0;
6779
+ }
5541
6780
  this.activeTool = null;
5542
6781
  this.stopTextEdit({ commit: false });
5543
6782
  this.resizeObserver?.disconnect();
@@ -5553,7 +6792,7 @@ var VdFlowchart = class {
5553
6792
  };
5554
6793
 
5555
6794
  // src/vue.js
5556
- var FORWARDED_EVENTS = ["change", "select", "viewport", "connect", "ready"];
6795
+ var FORWARDED_EVENTS = ["change", "select", "viewport", "connect", "ready", "history"];
5557
6796
  var EDITOR_OPTION_KEYS = [
5558
6797
  "readonly",
5559
6798
  "gridSize",
@@ -5658,7 +6897,25 @@ var VdFlowchart2 = (0, import_vue.defineComponent)({
5658
6897
  canUndo: () => Boolean(instance?.canUndo()),
5659
6898
  canRedo: () => Boolean(instance?.canRedo()),
5660
6899
  layout: (mode, options) => instance?.layout(mode, options),
5661
- fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding)
6900
+ fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding),
6901
+ setNodeColor: (nodeId, colorOrPatch) => instance?.setNodeColor(nodeId, colorOrPatch) ?? null,
6902
+ setEdgeColor: (edgeId, color) => instance?.setEdgeColor(edgeId, color) ?? null,
6903
+ setSelectionColor: (colorOrPatch) => instance?.setSelectionColor(colorOrPatch),
6904
+ clearSelectionColor: () => instance?.clearSelectionColor(),
6905
+ bringToFront: (targetId) => instance?.bringToFront(targetId),
6906
+ bringForward: (targetId) => instance?.bringForward(targetId),
6907
+ sendBackward: (targetId) => instance?.sendBackward(targetId),
6908
+ sendToBack: (targetId) => instance?.sendToBack(targetId),
6909
+ alignNodes: (alignment, nodeIds) => instance?.alignNodes(alignment, nodeIds),
6910
+ distributeNodes: (axis, nodeIds) => instance?.distributeNodes(axis, nodeIds),
6911
+ setNodeLocked: (nodeId, locked) => Boolean(instance?.setNodeLocked(nodeId, locked)),
6912
+ toggleNodeLocked: (nodeId) => Boolean(instance?.toggleNodeLocked(nodeId)),
6913
+ duplicateSelection: () => instance?.duplicateSelection() ?? null,
6914
+ copySelection: () => Boolean(instance?.copySelection()),
6915
+ pasteClipboard: () => Boolean(instance?.pasteClipboard()),
6916
+ pasteSelection: () => instance?.pasteSelection() ?? null,
6917
+ cutSelection: () => Boolean(instance?.cutSelection()),
6918
+ exportSvg: (options) => instance?.exportSvg(options) ?? ""
5662
6919
  });
5663
6920
  return () => (0, import_vue.h)("div", { ref: el, class: "vd-flowchart" });
5664
6921
  }