@vanduo-oss/vd3-flowchart 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,6 +8,8 @@ var DIRECTIONS = {
8
8
  down: { main: "y", sign: 1 },
9
9
  up: { main: "y", sign: -1 }
10
10
  };
11
+ var DEFAULT_LEVEL_EDGE_GAP = 88;
12
+ var DEFAULT_SIBLING_EDGE_GAP = 64;
11
13
  function num(value, fallback) {
12
14
  const next = Number(value);
13
15
  return Number.isFinite(next) ? next : fallback;
@@ -32,60 +34,182 @@ function pickRoots(nodes, indegree, optRoot) {
32
34
  }
33
35
  function spanningForest(allIds, roots, children) {
34
36
  const visited = /* @__PURE__ */ new Set();
35
- const depth = /* @__PURE__ */ new Map();
36
- const tree = /* @__PURE__ */ new Map();
37
+ const active = /* @__PURE__ */ new Set();
37
38
  const forestRoots = [];
38
- const walk = (id, d) => {
39
+ const forwardParents = new Map(allIds.map((id) => [id, []]));
40
+ const dfs = (id) => {
39
41
  visited.add(id);
40
- depth.set(id, d);
41
- const kids = [];
42
+ active.add(id);
42
43
  (children.get(id) || []).forEach((child) => {
43
- if (!visited.has(child)) {
44
- kids.push(child);
45
- walk(child, d + 1);
46
- }
44
+ if (active.has(child)) return;
45
+ const list = forwardParents.get(child);
46
+ if (list && !list.includes(id)) list.push(id);
47
+ if (!visited.has(child)) dfs(child);
47
48
  });
48
- tree.set(id, kids);
49
+ active.delete(id);
49
50
  };
50
51
  roots.forEach((root) => {
51
52
  if (!visited.has(root)) {
52
53
  forestRoots.push(root);
53
- walk(root, 0);
54
+ dfs(root);
54
55
  }
55
56
  });
56
57
  allIds.forEach((id) => {
57
58
  if (!visited.has(id)) {
58
59
  forestRoots.push(id);
59
- walk(id, 0);
60
+ dfs(id);
60
61
  }
61
62
  });
63
+ const depth = new Map(allIds.map((id) => [id, 0]));
64
+ const limit = Math.max(1, allIds.length);
65
+ for (let pass = 0; pass < limit; pass += 1) {
66
+ let changed = false;
67
+ for (const id of allIds) {
68
+ const parents = forwardParents.get(id) || [];
69
+ for (const parent of parents) {
70
+ const nextDepth = Math.min(limit, (depth.get(parent) || 0) + 1);
71
+ if (nextDepth > (depth.get(id) || 0)) {
72
+ depth.set(id, nextDepth);
73
+ changed = true;
74
+ }
75
+ }
76
+ }
77
+ if (!changed) break;
78
+ }
79
+ const tree = new Map(allIds.map((id) => [id, []]));
80
+ const rootSet = new Set(forestRoots);
81
+ const chosenParent = /* @__PURE__ */ new Map();
82
+ for (const id of allIds) {
83
+ if (rootSet.has(id)) continue;
84
+ const parents = forwardParents.get(id) || [];
85
+ if (!parents.length) continue;
86
+ let bestParent = parents[0];
87
+ let bestDepth = depth.get(bestParent) ?? -1;
88
+ for (let index = 1; index < parents.length; index += 1) {
89
+ const candidate = parents[index];
90
+ const candidateDepth = depth.get(candidate) ?? -1;
91
+ if (candidateDepth > bestDepth) {
92
+ bestDepth = candidateDepth;
93
+ bestParent = candidate;
94
+ }
95
+ }
96
+ chosenParent.set(id, bestParent);
97
+ }
98
+ const placedChild = /* @__PURE__ */ new Set();
99
+ for (const parentId of allIds) {
100
+ const out = tree.get(parentId);
101
+ for (const childId of children.get(parentId) || []) {
102
+ if (chosenParent.get(childId) === parentId && !placedChild.has(childId)) {
103
+ placedChild.add(childId);
104
+ out.push(childId);
105
+ }
106
+ }
107
+ }
62
108
  return { depth, tree, forestRoots };
63
109
  }
64
110
  function treeCenters(forestRoots, tree, depth, sizeOf, options) {
65
111
  const dir = DIRECTIONS[options.direction] || DIRECTIONS.right;
66
- const levelGap = num(options.levelGap, 220);
67
- const siblingGap = num(options.siblingGap, 140);
112
+ const hasExplicitLevel = Number.isFinite(Number(options.levelGap));
113
+ const hasExplicitSibling = Number.isFinite(Number(options.siblingGap));
114
+ const explicitLevelGap = num(options.levelGap, 220);
115
+ const explicitSiblingGap = num(options.siblingGap, 140);
116
+ const edgeSiblingGap = hasExplicitSibling ? Math.max(16, explicitSiblingGap - 96) : DEFAULT_SIBLING_EDGE_GAP;
117
+ const crossSpan = (id) => {
118
+ const size = sizeOf(id);
119
+ return dir.main === "x" ? size.height : size.width;
120
+ };
121
+ const mainSpan = (id) => {
122
+ const size = sizeOf(id);
123
+ return dir.main === "x" ? size.width : size.height;
124
+ };
125
+ const subtreeSpan = /* @__PURE__ */ new Map();
126
+ const subtreeCount = /* @__PURE__ */ new Map();
127
+ const measure = (id) => {
128
+ const selfSpan = crossSpan(id);
129
+ const kids = tree.get(id) || [];
130
+ if (!kids.length) {
131
+ subtreeSpan.set(id, selfSpan);
132
+ subtreeCount.set(id, 1);
133
+ return selfSpan;
134
+ }
135
+ let childTotal = 0;
136
+ let totalCount = 1;
137
+ kids.forEach((kid, index) => {
138
+ if (index > 0) childTotal += edgeSiblingGap;
139
+ childTotal += measure(kid);
140
+ totalCount += subtreeCount.get(kid) || 1;
141
+ });
142
+ const span = Math.max(selfSpan, childTotal);
143
+ subtreeSpan.set(id, span);
144
+ subtreeCount.set(id, totalCount);
145
+ return span;
146
+ };
147
+ forestRoots.forEach(measure);
68
148
  const crossOf = /* @__PURE__ */ new Map();
69
- let cursor = 0;
70
- const place = (id) => {
149
+ const place = (id, startCross) => {
150
+ const span = subtreeSpan.get(id) || crossSpan(id);
71
151
  const kids = tree.get(id) || [];
72
152
  if (!kids.length) {
73
- crossOf.set(id, cursor);
74
- cursor += siblingGap;
75
- return crossOf.get(id);
153
+ const center2 = startCross + span / 2;
154
+ crossOf.set(id, center2);
155
+ return center2;
156
+ }
157
+ let childTotal = 0;
158
+ const kidSpans = kids.map((kid, index) => {
159
+ const kidSpan = subtreeSpan.get(kid) || crossSpan(kid);
160
+ if (index > 0) childTotal += edgeSiblingGap;
161
+ childTotal += kidSpan;
162
+ return kidSpan;
163
+ });
164
+ let cursor = startCross + (span - childTotal) / 2;
165
+ const childCenters = kids.map((kid, index) => {
166
+ const kidSpan = kidSpans[index];
167
+ const center2 = place(kid, cursor);
168
+ cursor += kidSpan + edgeSiblingGap;
169
+ return center2;
170
+ });
171
+ if (kids.length >= 2) {
172
+ const counts = kids.map((kid) => subtreeCount.get(kid) || 1);
173
+ const maxCount = Math.max(...counts);
174
+ const minCount = Math.min(...counts);
175
+ if (maxCount > minCount) {
176
+ const primaryIndex = counts.indexOf(maxCount);
177
+ const center2 = childCenters[primaryIndex];
178
+ crossOf.set(id, center2);
179
+ return center2;
180
+ }
76
181
  }
77
- const childCenters = kids.map(place);
78
182
  const center = (childCenters[0] + childCenters[childCenters.length - 1]) / 2;
79
183
  crossOf.set(id, center);
80
184
  return center;
81
185
  };
82
- forestRoots.forEach((root) => {
83
- place(root);
84
- cursor += siblingGap;
186
+ let rootCursor = 0;
187
+ forestRoots.forEach((root, index) => {
188
+ if (index > 0) rootCursor += edgeSiblingGap;
189
+ const span = subtreeSpan.get(root) || crossSpan(root);
190
+ place(root, rootCursor);
191
+ rootCursor += span;
192
+ });
193
+ let maxDepth = 0;
194
+ const maxMainAtDepth = /* @__PURE__ */ new Map();
195
+ crossOf.forEach((_cross, id) => {
196
+ const d = depth.get(id) || 0;
197
+ if (d > maxDepth) maxDepth = d;
198
+ const current = maxMainAtDepth.get(d) || 0;
199
+ const span = mainSpan(id);
200
+ if (span > current) maxMainAtDepth.set(d, span);
85
201
  });
202
+ const mainCenterAtDepth = /* @__PURE__ */ new Map([[0, 0]]);
203
+ for (let d = 1; d <= maxDepth; d += 1) {
204
+ const prevCenter = mainCenterAtDepth.get(d - 1) || 0;
205
+ const prevSpan = maxMainAtDepth.get(d - 1) || 160;
206
+ const currSpan = maxMainAtDepth.get(d) || 160;
207
+ const step = hasExplicitLevel ? Math.max(explicitLevelGap, (prevSpan + currSpan) / 2 + 24) : (prevSpan + currSpan) / 2 + DEFAULT_LEVEL_EDGE_GAP;
208
+ mainCenterAtDepth.set(d, prevCenter + step * dir.sign);
209
+ }
86
210
  const centers = /* @__PURE__ */ new Map();
87
211
  crossOf.forEach((cross, id) => {
88
- const main = (depth.get(id) || 0) * levelGap * dir.sign;
212
+ const main = mainCenterAtDepth.get(depth.get(id) || 0) || 0;
89
213
  centers.set(
90
214
  id,
91
215
  dir.main === "x" ? { centerX: main, centerY: cross } : { centerX: cross, centerY: main }
@@ -323,6 +447,11 @@ var TOOLBAR_ICON_PATHS = {
323
447
  undo: "M224,128a96,96,0,0,1-94.71,96H128A95.38,95.38,0,0,1,62.1,197.8a8,8,0,0,1,11-11.63A80,80,0,1,0,71.43,71.39a3.07,3.07,0,0,1-.26.25L44.59,96H72a8,8,0,0,1,0,16H24a8,8,0,0,1-8-8V56a8,8,0,0,1,16,0V85.8L60.25,60A96,96,0,0,1,224,128Z",
324
448
  redo: "M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1,0-16H211.4L184.81,71.64l-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,0,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60L224,85.8V56a8,8,0,1,1,16,0Z",
325
449
  minimap: "M228.92,49.69a8,8,0,0,0-6.86-1.45L160.93,63.52,99.58,32.84a8,8,0,0,0-5.52-.6l-64,16A8,8,0,0,0,24,56V200a8,8,0,0,0,9.94,7.76l61.13-15.28,61.35,30.68A8.15,8.15,0,0,0,160,224a8,8,0,0,0,1.94-.24l64-16A8,8,0,0,0,232,200V56A8,8,0,0,0,228.92,49.69ZM104,52.94l48,24V203.06l-48-24ZM40,62.25l48-12v127.5l-48,12Zm176,131.5-48,12V78.25l48-12Z",
450
+ palette: "M200.77,53.89A103.27,103.27,0,0,0,128,24h-1.07A104,104,0,0,0,24,128c0,43,26.58,79.06,69.36,94.17A32,32,0,0,0,136,192a16,16,0,0,1,16-16h46.21a31.81,31.81,0,0,0,31.2-24.88,104.43,104.43,0,0,0,2.59-24A103.28,103.28,0,0,0,200.77,53.89Zm13,93.71A15.89,15.89,0,0,1,198.21,160H152a32,32,0,0,0-32,32,16,16,0,0,1-21.31,15.07C62.49,194.3,40,164,40,128a88,88,0,0,1,87.09-88h.9a88.35,88.35,0,0,1,88,87.25A88.86,88.86,0,0,1,213.81,147.6ZM140,76a12,12,0,1,1-12-12A12,12,0,0,1,140,76ZM96,100A12,12,0,1,1,84,88,12,12,0,0,1,96,100Zm0,56a12,12,0,1,1-12-12A12,12,0,0,1,96,156Zm88-56a12,12,0,1,1-12-12A12,12,0,0,1,184,100Z",
451
+ "bring-to-front": "M216,104H168V56a16,16,0,0,0-16-16H56A16,16,0,0,0,40,56v96a16,16,0,0,0,16,16h48v48a16,16,0,0,0,16,16h96a16,16,0,0,0,16-16V120A16,16,0,0,0,216,104ZM56,152V56h96v48H120a16,16,0,0,0-16,16v32Zm160,64H120V120h96Z",
452
+ "send-to-back": "M216,104H168V56a16,16,0,0,0-16-16H56A16,16,0,0,0,40,56v96a16,16,0,0,0,16,16h48v48a16,16,0,0,0,16,16h96a16,16,0,0,0,16-16V120A16,16,0,0,0,216,104ZM56,56h96v96H56Zm160,160H120V168h32a16,16,0,0,0,16-16V120h48Z",
453
+ lock: "M208,80H176V56a48,48,0,0,0-96,0V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80ZM96,56a32,32,0,0,1,64,0V80H96ZM208,208H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z",
454
+ unlock: "M208,80H96V56a32,32,0,0,1,32-32c15.37,0,29.2,11,32.16,25.59a8,8,0,0,0,15.68-3.18C171.32,24.15,151.32,8,128,8A48.05,48.05,0,0,0,80,56V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm0,128H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z",
326
455
  clear: "M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM96,40a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96Zm96,168H64V64H192ZM112,104v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Zm48,0v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Z"
327
456
  };
328
457
  var TOOLBAR_ACTIONS = [
@@ -399,7 +528,7 @@ var EDGE_STROKE_PRESETS = [
399
528
  { id: "medium", label: "Medium", width: DEFAULT_EDGE_STROKE_WIDTH },
400
529
  { id: "bold", label: "Bold", width: 3.5 }
401
530
  ];
402
- var VD_FLOWCHART_VERSION = "1.5.0";
531
+ var VD_FLOWCHART_VERSION = "1.6.0";
403
532
  var FLOWCHART_DOCUMENT_VERSION = "1.3.0";
404
533
  var FLOWCHART_NODE_TYPES = [
405
534
  "rounded-rect",
@@ -413,10 +542,92 @@ var FLOWCHART_NODE_TYPES = [
413
542
  var FLOWCHART_PORTS = ["top", "right", "bottom", "left"];
414
543
  var FLOWCHART_EDGE_MARKERS = ["none", "arrow", "dot"];
415
544
  var FLOWCHART_EDGE_ROUTES = ["curve", "straight", "orthogonal"];
545
+ var FLOWCHART_EDGE_STROKE_STYLES = ["solid", "dashed", "dotted", "animated"];
546
+ var FLOWCHART_COLOR_PRESETS = [
547
+ "default",
548
+ "primary",
549
+ "secondary",
550
+ "success",
551
+ "warning",
552
+ "danger",
553
+ "info",
554
+ "violet",
555
+ "teal",
556
+ "orange",
557
+ "pink",
558
+ "neutral"
559
+ ];
560
+ var FLOWCHART_NODE_ALIGNMENTS = ["left", "center", "right", "top", "middle", "bottom"];
561
+ var FLOWCHART_DISTRIBUTE_AXES = ["horizontal", "vertical"];
416
562
  var FLOWCHART_KEYBOARD_SHORTCUTS = ["mindmap", "basic"];
563
+ var FLOWCHART_COLOR_PRESET_LABELS = {
564
+ default: "Default",
565
+ primary: "Primary",
566
+ secondary: "Secondary",
567
+ success: "Success",
568
+ warning: "Warning",
569
+ danger: "Danger",
570
+ info: "Info",
571
+ violet: "Violet",
572
+ teal: "Teal",
573
+ orange: "Orange",
574
+ pink: "Pink",
575
+ neutral: "Neutral"
576
+ };
577
+ var FLOWCHART_COLOR_PRESET_SET = new Set(FLOWCHART_COLOR_PRESETS);
578
+ var FLOWCHART_COLOR_PRESET_FALLBACKS = {
579
+ primary: { fill: "#dbeafe", stroke: "#2563eb", text: "#1e3a8a", edge: "#2563eb" },
580
+ secondary: { fill: "#e0e7ff", stroke: "#4f46e5", text: "#312e81", edge: "#4f46e5" },
581
+ success: { fill: "#dcfce7", stroke: "#16a34a", text: "#14532d", edge: "#16a34a" },
582
+ warning: { fill: "#fef3c7", stroke: "#d97706", text: "#78350f", edge: "#d97706" },
583
+ danger: { fill: "#fee2e2", stroke: "#dc2626", text: "#7f1d1d", edge: "#dc2626" },
584
+ info: { fill: "#e0f2fe", stroke: "#0284c7", text: "#0c4a6e", edge: "#0284c7" },
585
+ violet: { fill: "#f3e8ff", stroke: "#9333ea", text: "#581c87", edge: "#9333ea" },
586
+ teal: { fill: "#ccfbf1", stroke: "#0d9488", text: "#134e4a", edge: "#0d9488" },
587
+ orange: { fill: "#ffedd5", stroke: "#ea580c", text: "#7c2d12", edge: "#ea580c" },
588
+ pink: { fill: "#fce7f3", stroke: "#db2777", text: "#831843", edge: "#db2777" },
589
+ neutral: { fill: "#f1f5f9", stroke: "#64748b", text: "#1e293b", edge: "#64748b" }
590
+ };
591
+ var FLOWCHART_EDGE_STROKE_STYLE_LABELS = {
592
+ solid: "Solid",
593
+ dashed: "Dashed",
594
+ dotted: "Dotted",
595
+ animated: "Animated flow"
596
+ };
417
597
  function normalizeKeyboardShortcuts(value) {
418
598
  return value === "basic" ? "basic" : "mindmap";
419
599
  }
600
+ function normalizeColorPreset(value) {
601
+ if (typeof value !== "string") return "";
602
+ const trimmed = value.trim().toLowerCase();
603
+ return FLOWCHART_COLOR_PRESETS.includes(trimmed) && trimmed !== "default" ? trimmed : "";
604
+ }
605
+ function sanitizeCssColor(value) {
606
+ if (typeof value !== "string") return "";
607
+ const trimmed = value.trim();
608
+ if (!trimmed || trimmed === "default") return "";
609
+ if (trimmed.length > 64 || /\\/.test(trimmed)) return "";
610
+ if (/[;{}<>"'`]/.test(trimmed) || /url\s*\(|expression\s*\(|javascript\s*:/i.test(trimmed)) {
611
+ return "";
612
+ }
613
+ if (!/^[#a-z0-9(),.%\s/+-]+$/i.test(trimmed)) return "";
614
+ return trimmed;
615
+ }
616
+ function normalizeEdgeColor(value) {
617
+ const preset = normalizeColorPreset(value);
618
+ if (preset) return preset;
619
+ return sanitizeCssColor(value);
620
+ }
621
+ function normalizeEdgeStrokeStyle(value) {
622
+ return FLOWCHART_EDGE_STROKE_STYLES.includes(value) && value !== "solid" ? value : "solid";
623
+ }
624
+ function resolveEdgeColorValue(color) {
625
+ if (!color || color === "default") return "var(--vd-flowchart-accent)";
626
+ if (FLOWCHART_COLOR_PRESETS.includes(color)) {
627
+ return `var(--vd-flowchart-palette-${color}-edge)`;
628
+ }
629
+ return color;
630
+ }
420
631
  var ARROW_DIRECTIONS = {
421
632
  ArrowRight: "right",
422
633
  ArrowLeft: "left",
@@ -457,6 +668,8 @@ function getShortcutRows(mode, readonly) {
457
668
  "Edit the connection label"
458
669
  ],
459
670
  ["Cmd/Ctrl + /", "Collapse or expand the branch"],
671
+ ["Cmd/Ctrl + ] or [", "Bring forward or send backward (Shift: front/back)"],
672
+ ["Cmd/Ctrl + L", "Lock or unlock the selected node"],
460
673
  ["Alt + Arrow", "Nudge the node (add Shift for 1 px)"],
461
674
  ["Delete or Backspace", "Delete the selection"],
462
675
  ["Cmd/Ctrl + D", "Duplicate the node"],
@@ -641,10 +854,12 @@ function clampNodeHeight(type, height, fallback, sizeBounds) {
641
854
  return clamp(toFiniteNumber(height, fallback), bounds.minHeight, bounds.maxHeight);
642
855
  }
643
856
  function isNodeResizable(nodeOrType) {
857
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
644
858
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
645
859
  return spec.resizable !== false;
646
860
  }
647
861
  function isNodeTextEditable(nodeOrType) {
862
+ if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
648
863
  const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
649
864
  return spec.textEditable !== false;
650
865
  }
@@ -684,6 +899,15 @@ function normalizeNode(rawNode, index, usedIds, sizeBounds) {
684
899
  data: isPlainObject(rawNode?.data) ? deepClone(rawNode.data) : {}
685
900
  };
686
901
  if (rawNode?.collapsed === true) node.collapsed = true;
902
+ const color = normalizeColorPreset(rawNode?.color ?? rawNode?.data?.color);
903
+ if (color) node.color = color;
904
+ const fill = sanitizeCssColor(rawNode?.fill ?? rawNode?.data?.fill);
905
+ if (fill) node.fill = fill;
906
+ const stroke = sanitizeCssColor(rawNode?.stroke ?? rawNode?.data?.stroke);
907
+ if (stroke) node.stroke = stroke;
908
+ const textColor = sanitizeCssColor(rawNode?.textColor ?? rawNode?.data?.textColor);
909
+ if (textColor) node.textColor = textColor;
910
+ if (rawNode?.locked === true || rawNode?.data?.locked === true) node.locked = true;
687
911
  return node;
688
912
  }
689
913
  function computeHiddenNodeIds(nodes, edges) {
@@ -716,6 +940,12 @@ function computeHiddenNodeIds(nodes, edges) {
716
940
  return candidates;
717
941
  }
718
942
  function normalizeEndpoint(rawEndpoint, fallbackPort) {
943
+ if (typeof rawEndpoint === "string") {
944
+ return {
945
+ nodeId: sanitizeId(rawEndpoint),
946
+ port: fallbackPort
947
+ };
948
+ }
719
949
  return {
720
950
  nodeId: sanitizeId(rawEndpoint?.nodeId),
721
951
  port: FLOWCHART_PORTS.includes(rawEndpoint?.port) ? rawEndpoint.port : fallbackPort
@@ -751,6 +981,10 @@ function normalizeEdge(rawEdge, index, nodeIds, usedIds) {
751
981
  label: rawEdge?.label == null ? "" : String(rawEdge.label),
752
982
  data: isPlainObject(rawEdge?.data) ? deepClone(rawEdge.data) : {}
753
983
  };
984
+ const color = normalizeEdgeColor(rawEdge?.color ?? rawEdge?.data?.color);
985
+ if (color) edge.color = color;
986
+ const strokeStyle = normalizeEdgeStrokeStyle(rawEdge?.strokeStyle ?? rawEdge?.data?.strokeStyle);
987
+ if (strokeStyle !== "solid") edge.strokeStyle = strokeStyle;
754
988
  syncEdgeKind(edge);
755
989
  return edge;
756
990
  }
@@ -1106,10 +1340,37 @@ function getOrthogonalMidpoints(fromStub, toStub, fromPort, toPort) {
1106
1340
  function getOrthogonalPoints(fromPoint, toPoint, fromPort, toPort, fromRect, toRect, metrics = routeMetrics(1)) {
1107
1341
  const fromNormal = getPortNormal(fromPort);
1108
1342
  const toNormal = getPortNormal(toPort);
1109
- const fromStub = offsetPoint(fromPoint, fromNormal, metrics.stub);
1110
- const toStub = offsetPoint(toPoint, toNormal, metrics.stub);
1111
1343
  const sourceHorizontal = isHorizontalPort(fromPort);
1112
1344
  const targetHorizontal = isHorizontalPort(toPort);
1345
+ const minStub = 4 * (metrics.scale || 1);
1346
+ let fromStubLen = metrics.stub;
1347
+ let toStubLen = metrics.stub;
1348
+ if (sourceHorizontal && targetHorizontal && fromNormal.x === -toNormal.x) {
1349
+ const span = (toPoint.x - fromPoint.x) * fromNormal.x;
1350
+ if (span > 0) {
1351
+ const fitted = Math.min(metrics.stub, span * 0.45, span / 2);
1352
+ fromStubLen = fitted;
1353
+ toStubLen = fitted;
1354
+ }
1355
+ } else if (!sourceHorizontal && !targetHorizontal && fromNormal.y === -toNormal.y) {
1356
+ const span = (toPoint.y - fromPoint.y) * fromNormal.y;
1357
+ if (span > 0) {
1358
+ const fitted = Math.min(metrics.stub, span * 0.45, span / 2);
1359
+ fromStubLen = fitted;
1360
+ toStubLen = fitted;
1361
+ }
1362
+ } else if (sourceHorizontal !== targetHorizontal) {
1363
+ const spanFrom = sourceHorizontal ? (toPoint.x - fromPoint.x) * fromNormal.x : (toPoint.y - fromPoint.y) * fromNormal.y;
1364
+ const spanTo = targetHorizontal ? (fromPoint.x - toPoint.x) * toNormal.x : (fromPoint.y - toPoint.y) * toNormal.y;
1365
+ if (spanFrom > 0 && spanFrom < metrics.stub) {
1366
+ fromStubLen = Math.min(spanFrom / 2, Math.max(minStub, spanFrom * 0.5));
1367
+ }
1368
+ if (spanTo > 0 && spanTo < metrics.stub) {
1369
+ toStubLen = Math.min(spanTo / 2, Math.max(minStub, spanTo * 0.5));
1370
+ }
1371
+ }
1372
+ const fromStub = offsetPoint(fromPoint, fromNormal, fromStubLen);
1373
+ const toStub = offsetPoint(toPoint, toNormal, toStubLen);
1113
1374
  const mids = [];
1114
1375
  if (sourceHorizontal && targetHorizontal) {
1115
1376
  const facing = fromNormal.x === -toNormal.x;
@@ -1170,19 +1431,75 @@ function buildOrthogonalPath(fromPoint, toPoint, fromPort = "right", toPort = "l
1170
1431
  labelY: label.y
1171
1432
  };
1172
1433
  }
1434
+ function getPortOuterOffset(node, port) {
1435
+ if (!node || node.type === "label") return 0;
1436
+ const visual = nodeVisualScale(node);
1437
+ const baseStroke = node.type === "junction" ? 1.25 : 1.5;
1438
+ const halfStroke = Math.max(0.015, baseStroke * visual / 2);
1439
+ if (node.type === "diamond") {
1440
+ const w = Math.max(1, toFiniteNumber(node.width, 184));
1441
+ const h2 = Math.max(1, toFiniteNumber(node.height, 120));
1442
+ const diag = Math.hypot(w, h2);
1443
+ const miterFactor = isHorizontalPort(port) ? Math.min(4, diag / h2) : Math.min(4, diag / w);
1444
+ return halfStroke * miterFactor;
1445
+ }
1446
+ return halfStroke;
1447
+ }
1448
+ function getMarkerEndpointRetraction(markerType, strokeWidth, edgeScale = 1) {
1449
+ if (!markerType || markerType === "none") return 0;
1450
+ const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1451
+ const effective = Math.max(0.02, normalizeEdgeStrokeWidth(strokeWidth) * scale);
1452
+ if (markerType === "dot") {
1453
+ return formatNumber(Math.max(2.75 * scale, effective * 1.45));
1454
+ }
1455
+ return formatNumber(Math.max(1.5 * scale, effective * 0.85));
1456
+ }
1173
1457
  function buildEdgePath(edge, fromNode = null, toNode = null) {
1174
1458
  const fromPort = edge?.from?.port || edge?.fromPort || "right";
1175
1459
  const toPort = edge?.to?.port || edge?.toPort || "left";
1176
- const fromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
1177
- const toPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
1460
+ const rawFromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
1461
+ const rawToPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
1178
1462
  const route = normalizeEdgeRoute(edge?.route);
1179
- const metrics = routeMetrics(edgeVisualScale(fromNode, toNode));
1180
- if (!fromPoint || !toPoint) {
1463
+ const visualScale = edgeVisualScale(fromNode, toNode);
1464
+ const metrics = routeMetrics(visualScale);
1465
+ if (!rawFromPoint || !rawToPoint) {
1181
1466
  return { d: "", labelX: 0, labelY: 0 };
1182
1467
  }
1468
+ const strokeWidth = normalizeEdgeStrokeWidth(edge?.strokeWidth);
1469
+ const startMarker = edge?.startMarker || "none";
1470
+ const endMarker = edge?.endMarker || "none";
1471
+ const rawDistance = Math.hypot(rawToPoint.x - rawFromPoint.x, rawToPoint.y - rawFromPoint.y);
1472
+ const maxRetract = rawDistance > 0 ? rawDistance * 0.45 : 0;
1473
+ const fromMarkerRetract = !edge?.fromPoint && fromNode && startMarker !== "none" ? getMarkerEndpointRetraction(startMarker, strokeWidth, visualScale) : 0;
1474
+ const fromBorderRetract = fromMarkerRetract > 0 ? getPortOuterOffset(fromNode, fromPort) : 0;
1475
+ const toMarkerRetract = !edge?.toPoint && toNode && endMarker !== "none" ? getMarkerEndpointRetraction(endMarker, strokeWidth, visualScale) : 0;
1476
+ const toBorderRetract = toMarkerRetract > 0 ? getPortOuterOffset(toNode, toPort) : 0;
1477
+ const fromRetract = Math.min(maxRetract, fromMarkerRetract + fromBorderRetract);
1478
+ const toRetract = Math.min(maxRetract, toMarkerRetract + toBorderRetract);
1183
1479
  if (route === "straight") {
1184
- return buildStraightPath(fromPoint, toPoint);
1480
+ const borderFrom = fromBorderRetract > 0 ? offsetPoint(
1481
+ rawFromPoint,
1482
+ getPortNormal(fromPort),
1483
+ Math.min(maxRetract, fromBorderRetract)
1484
+ ) : rawFromPoint;
1485
+ const borderTo = toBorderRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), Math.min(maxRetract, toBorderRetract)) : rawToPoint;
1486
+ const dx = borderTo.x - borderFrom.x;
1487
+ const dy = borderTo.y - borderFrom.y;
1488
+ const dist = Math.hypot(dx, dy);
1489
+ if (dist > 0.01) {
1490
+ const ux = dx / dist;
1491
+ const uy = dy / dist;
1492
+ const sRetract = Math.min(dist * 0.45, fromMarkerRetract);
1493
+ const eRetract = Math.min(dist * 0.45, toMarkerRetract);
1494
+ return buildStraightPath(
1495
+ { x: borderFrom.x + ux * sRetract, y: borderFrom.y + uy * sRetract },
1496
+ { x: borderTo.x - ux * eRetract, y: borderTo.y - uy * eRetract }
1497
+ );
1498
+ }
1499
+ return buildStraightPath(rawFromPoint, rawToPoint);
1185
1500
  }
1501
+ const fromPoint = fromRetract > 0 ? offsetPoint(rawFromPoint, getPortNormal(fromPort), fromRetract) : rawFromPoint;
1502
+ const toPoint = toRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), toRetract) : rawToPoint;
1186
1503
  if (route === "orthogonal") {
1187
1504
  const fromRect = !edge?.fromPoint && fromNode ? getNodeRectBounds(fromNode, metrics.clearance) : null;
1188
1505
  const toRect = !edge?.toPoint && toNode ? getNodeRectBounds(toNode, metrics.clearance) : null;
@@ -1190,7 +1507,7 @@ function buildEdgePath(edge, fromNode = null, toNode = null) {
1190
1507
  }
1191
1508
  return buildCurvePath(fromPoint, toPoint, fromPort, toPort, metrics);
1192
1509
  }
1193
- function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1510
+ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1194
1511
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1195
1512
  const effective = Math.max(0.02, strokeWidth * scale);
1196
1513
  const size = formatNumber(Math.max(9 * scale, effective * 4.4));
@@ -1207,12 +1524,12 @@ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
1207
1524
  marker.appendChild(
1208
1525
  svgEl("path", {
1209
1526
  d: reversed ? `M ${formatNumber(size)} 0 L 0 ${formatNumber(size / 2)} L ${formatNumber(size)} ${formatNumber(size)} z` : `M 0 0 L ${formatNumber(size)} ${formatNumber(size / 2)} L 0 ${formatNumber(size)} z`,
1210
- fill: "var(--vd-flowchart-accent)"
1527
+ fill
1211
1528
  })
1212
1529
  );
1213
1530
  return marker;
1214
1531
  }
1215
- function createDotMarker(id, strokeWidth, edgeScale = 1) {
1532
+ function createDotMarker(id, strokeWidth, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
1216
1533
  const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
1217
1534
  const effective = Math.max(0.02, strokeWidth * scale);
1218
1535
  const size = formatNumber(Math.max(8 * scale, effective * 3.3));
@@ -1231,7 +1548,7 @@ function createDotMarker(id, strokeWidth, edgeScale = 1) {
1231
1548
  cx: formatNumber(size / 2),
1232
1549
  cy: formatNumber(size / 2),
1233
1550
  r: radius,
1234
- fill: "var(--vd-flowchart-accent)"
1551
+ fill
1235
1552
  })
1236
1553
  );
1237
1554
  return marker;
@@ -1520,6 +1837,7 @@ var VdFlowchart = class {
1520
1837
  this.minimapFrame = 0;
1521
1838
  this.minimapDrag = null;
1522
1839
  this.shortcutsHelpOpen = false;
1840
+ this.colorPopoverOpen = false;
1523
1841
  this.autoFit = Boolean(options.autoFit);
1524
1842
  this.readyEmitted = false;
1525
1843
  this.resizeObserver = null;
@@ -1532,11 +1850,14 @@ var VdFlowchart = class {
1532
1850
  this.handleClick = this.handleClick.bind(this);
1533
1851
  this.handleDoubleClick = this.handleDoubleClick.bind(this);
1534
1852
  this.handleWheel = this.handleWheel.bind(this);
1853
+ this.handleCanvasBlur = this.handleCanvasBlur.bind(this);
1535
1854
  this.handleKeyDown = this.handleKeyDown.bind(this);
1536
1855
  this.handleSelectionFieldInput = this.handleSelectionFieldInput.bind(this);
1537
1856
  this.handleSelectionFieldChange = this.handleSelectionFieldChange.bind(this);
1857
+ this.handleSelectionActionClick = this.handleSelectionActionClick.bind(this);
1538
1858
  this.handleJsonActionClick = this.handleJsonActionClick.bind(this);
1539
1859
  this.handleResize = this.handleResize.bind(this);
1860
+ this.handleOutsidePointerDown = this.handleOutsidePointerDown.bind(this);
1540
1861
  this.buildShell();
1541
1862
  this.bindEvents();
1542
1863
  this.render();
@@ -1620,6 +1941,32 @@ var VdFlowchart = class {
1620
1941
  this.arrangeSelect.appendChild(option);
1621
1942
  });
1622
1943
  this.arrangeSelect.value = this.layoutMode;
1944
+ this.colorPopoverWrap = createElement("div", { className: "vd-flowchart-color-popover-wrap" });
1945
+ this.colorButton = createToolbarButton({
1946
+ action: "color-popover",
1947
+ label: "Color selection",
1948
+ icon: "palette",
1949
+ disabled: this.readonly
1950
+ });
1951
+ this.colorButton.setAttribute("aria-expanded", "false");
1952
+ this.colorPopover = createElement("div", { className: "vd-flowchart-color-popover" });
1953
+ this.colorPopover.hidden = true;
1954
+ this.colorPopover.setAttribute("role", "dialog");
1955
+ this.colorPopover.setAttribute("aria-label", "Color presets");
1956
+ const popoverSwatches = createElement("div", { className: "vd-flowchart-swatch-grid" });
1957
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
1958
+ const swatch = createElement("button", {
1959
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}`,
1960
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset
1961
+ });
1962
+ swatch.setAttribute("type", "button");
1963
+ swatch.setAttribute("data-flowchart-color", preset);
1964
+ swatch.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
1965
+ popoverSwatches.appendChild(swatch);
1966
+ });
1967
+ this.colorPopover.appendChild(popoverSwatches);
1968
+ this.colorPopoverWrap.appendChild(this.colorButton);
1969
+ this.colorPopoverWrap.appendChild(this.colorPopover);
1623
1970
  this.clearButton = createToolbarButton({
1624
1971
  action: "clear",
1625
1972
  label: "Clear canvas",
@@ -1646,6 +1993,7 @@ var VdFlowchart = class {
1646
1993
  });
1647
1994
  this.minimapButton.setAttribute("aria-pressed", this.minimapEnabled ? "true" : "false");
1648
1995
  toolbarLeft.appendChild(this.arrangeSelect);
1996
+ toolbarLeft.appendChild(this.colorPopoverWrap);
1649
1997
  toolbarLeft.appendChild(this.clearButton);
1650
1998
  toolbarRight.appendChild(this.minimapButton);
1651
1999
  toolbarRight.appendChild(this.shortcutsButton);
@@ -1936,6 +2284,7 @@ var VdFlowchart = class {
1936
2284
  this.deleteButton.addEventListener("click", () => this.deleteSelection());
1937
2285
  this.selectionFields.addEventListener("input", this.handleSelectionFieldInput);
1938
2286
  this.selectionFields.addEventListener("change", this.handleSelectionFieldChange);
2287
+ this.selectionFields.addEventListener("click", this.handleSelectionActionClick);
1939
2288
  this.jsonActions.addEventListener("click", this.handleJsonActionClick);
1940
2289
  this.canvasEl.addEventListener("pointerdown", this.handlePointerDown);
1941
2290
  this.canvasEl.addEventListener("pointermove", this.handlePointerMove);
@@ -1944,8 +2293,10 @@ var VdFlowchart = class {
1944
2293
  this.canvasEl.addEventListener("click", this.handleClick);
1945
2294
  this.canvasEl.addEventListener("dblclick", this.handleDoubleClick);
1946
2295
  this.canvasEl.addEventListener("wheel", this.handleWheel, { passive: false });
2296
+ this.canvasEl.addEventListener("blur", this.handleCanvasBlur);
1947
2297
  this.root.addEventListener("keydown", this.handleKeyDown, true);
1948
2298
  window.addEventListener("pointerup", this.handlePointerUp);
2299
+ window.addEventListener("pointerdown", this.handleOutsidePointerDown);
1949
2300
  window.addEventListener("resize", this.handleResize);
1950
2301
  }
1951
2302
  unbindEvents() {
@@ -1954,6 +2305,7 @@ var VdFlowchart = class {
1954
2305
  this.paletteGrid.removeEventListener("click", this.handlePaletteClick);
1955
2306
  this.selectionFields.removeEventListener("input", this.handleSelectionFieldInput);
1956
2307
  this.selectionFields.removeEventListener("change", this.handleSelectionFieldChange);
2308
+ this.selectionFields.removeEventListener("click", this.handleSelectionActionClick);
1957
2309
  this.jsonActions.removeEventListener("click", this.handleJsonActionClick);
1958
2310
  this.canvasEl.removeEventListener("pointerdown", this.handlePointerDown);
1959
2311
  this.canvasEl.removeEventListener("pointermove", this.handlePointerMove);
@@ -1962,14 +2314,34 @@ var VdFlowchart = class {
1962
2314
  this.canvasEl.removeEventListener("click", this.handleClick);
1963
2315
  this.canvasEl.removeEventListener("dblclick", this.handleDoubleClick);
1964
2316
  this.canvasEl.removeEventListener("wheel", this.handleWheel);
2317
+ this.canvasEl.removeEventListener("blur", this.handleCanvasBlur);
1965
2318
  this.root.removeEventListener("keydown", this.handleKeyDown, true);
1966
2319
  window.removeEventListener("pointerup", this.handlePointerUp);
2320
+ window.removeEventListener("pointerdown", this.handleOutsidePointerDown);
1967
2321
  window.removeEventListener("resize", this.handleResize);
1968
2322
  }
2323
+ handleOutsidePointerDown(event) {
2324
+ if (!this.colorPopoverOpen || this.destroyed) return;
2325
+ if (event.target?.closest?.(".vd-flowchart-color-popover-wrap")) return;
2326
+ this.toggleColorPopover(false);
2327
+ }
1969
2328
  handleResize() {
1970
2329
  if (this.destroyed) return;
1971
2330
  this.render({ inspector: false, json: false });
1972
2331
  }
2332
+ /**
2333
+ * Focus the diagram canvas. Quiet focus returns from an inline editor without
2334
+ * painting the full-canvas `:focus-visible` ring (see `.is-quiet-focus`).
2335
+ */
2336
+ focusCanvas(options = {}) {
2337
+ if (!this.canvasEl || this.destroyed) return;
2338
+ const quiet = options.quiet === true;
2339
+ this.canvasEl.classList.toggle("is-quiet-focus", quiet);
2340
+ this.canvasEl.focus({ preventScroll: true });
2341
+ }
2342
+ handleCanvasBlur() {
2343
+ this.canvasEl?.classList.remove("is-quiet-focus");
2344
+ }
1973
2345
  updatePaletteState() {
1974
2346
  const arrowArmed = this.activeTool === "arrow";
1975
2347
  this.paletteGrid.querySelectorAll(".vd-flowchart-palette-btn").forEach((button) => {
@@ -1991,7 +2363,24 @@ var VdFlowchart = class {
1991
2363
  this.updatePaletteState();
1992
2364
  this.render({ scene: true, inspector: false, json: false });
1993
2365
  }
2366
+ toggleColorPopover(force) {
2367
+ if (!this.colorPopover || !this.colorButton) return this;
2368
+ const open = typeof force === "boolean" ? force : !this.colorPopoverOpen;
2369
+ this.colorPopoverOpen = open && !this.readonly;
2370
+ this.colorPopover.hidden = !this.colorPopoverOpen;
2371
+ this.colorButton.setAttribute("aria-expanded", this.colorPopoverOpen ? "true" : "false");
2372
+ return this;
2373
+ }
1994
2374
  handleToolbarClick(event) {
2375
+ const colorSwatch = event.target.closest("[data-flowchart-color]");
2376
+ if (colorSwatch) {
2377
+ if (!this.readonly) {
2378
+ const preset = colorSwatch.getAttribute("data-flowchart-color");
2379
+ this.setSelectionColor(preset);
2380
+ }
2381
+ this.toggleColorPopover(false);
2382
+ return;
2383
+ }
1995
2384
  const actionButton = event.target.closest("[data-flowchart-action]");
1996
2385
  if (!actionButton) return;
1997
2386
  const action = actionButton.getAttribute("data-flowchart-action");
@@ -2001,6 +2390,7 @@ var VdFlowchart = class {
2001
2390
  if (action === "fit-view") this.fitView();
2002
2391
  if (action === "undo") this.undo();
2003
2392
  if (action === "redo") this.redo();
2393
+ if (action === "color-popover") this.toggleColorPopover();
2004
2394
  if (action === "clear" && !this.readonly) this.clear();
2005
2395
  if (action === "shortcuts") this.toggleShortcutsHelp();
2006
2396
  if (action === "minimap") this.setMinimapEnabled(!this.minimapEnabled);
@@ -2063,16 +2453,18 @@ var VdFlowchart = class {
2063
2453
  nodes.forEach((node) => {
2064
2454
  const point = map(node.x, node.y);
2065
2455
  const selected = this.isNodeSelected(node.id);
2066
- this.minimapSvg.appendChild(
2067
- svgEl("rect", {
2068
- class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
2069
- x: point.x,
2070
- y: point.y,
2071
- width: formatNumber(Math.max(1.5, node.width * transform.scale)),
2072
- height: formatNumber(Math.max(1.5, node.height * transform.scale)),
2073
- rx: 1.5
2074
- })
2075
- );
2456
+ const rectEl = svgEl("rect", {
2457
+ class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
2458
+ x: point.x,
2459
+ y: point.y,
2460
+ width: formatNumber(Math.max(1.5, node.width * transform.scale)),
2461
+ height: formatNumber(Math.max(1.5, node.height * transform.scale)),
2462
+ rx: 1.5
2463
+ });
2464
+ if (node.color) rectEl.setAttribute("data-color", node.color);
2465
+ if (node.fill) rectEl.style.fill = node.fill;
2466
+ if (node.stroke) rectEl.style.stroke = node.stroke;
2467
+ this.minimapSvg.appendChild(rectEl);
2076
2468
  });
2077
2469
  const corner = map(view.left, view.top);
2078
2470
  this.minimapSvg.appendChild(
@@ -2194,6 +2586,42 @@ var VdFlowchart = class {
2194
2586
  }
2195
2587
  }
2196
2588
  }
2589
+ handleSelectionActionClick(event) {
2590
+ if (this.readonly) return;
2591
+ const swatch = event.target.closest("[data-color-preset]");
2592
+ if (swatch) {
2593
+ this.setSelectionColor(swatch.getAttribute("data-color-preset"));
2594
+ return;
2595
+ }
2596
+ const resetBtn = event.target.closest("[data-color-reset]");
2597
+ if (resetBtn) {
2598
+ this.clearSelectionColor();
2599
+ return;
2600
+ }
2601
+ const arrangeBtn = event.target.closest("[data-arrange-action]");
2602
+ if (arrangeBtn) {
2603
+ const action = arrangeBtn.getAttribute("data-arrange-action");
2604
+ if (action === "bring-to-front") this.bringToFront();
2605
+ else if (action === "bring-forward") this.bringForward();
2606
+ else if (action === "send-backward") this.sendBackward();
2607
+ else if (action === "send-to-back") this.sendToBack();
2608
+ return;
2609
+ }
2610
+ const alignBtn = event.target.closest("[data-align-action]");
2611
+ if (alignBtn) {
2612
+ this.alignNodes(alignBtn.getAttribute("data-align-action"));
2613
+ return;
2614
+ }
2615
+ const distributeBtn = event.target.closest("[data-distribute-action]");
2616
+ if (distributeBtn) {
2617
+ this.distributeNodes(distributeBtn.getAttribute("data-distribute-action"));
2618
+ return;
2619
+ }
2620
+ const lockBtn = event.target.closest("[data-lock-toggle]");
2621
+ if (lockBtn) {
2622
+ this.toggleNodeLocked();
2623
+ }
2624
+ }
2197
2625
  handleSelectionFieldInput(event) {
2198
2626
  const field = event.target.getAttribute("data-field");
2199
2627
  if (!field) return;
@@ -2216,6 +2644,38 @@ var VdFlowchart = class {
2216
2644
  if (field === "node-width" || field === "node-height") {
2217
2645
  const patch = field === "node-width" ? { width: toFiniteNumber(event.target.value, void 0) } : { height: toFiniteNumber(event.target.value, void 0) };
2218
2646
  this.updateNode(this.selection?.id, patch, { inspector: false, reason: "node:update" });
2647
+ return;
2648
+ }
2649
+ if (field === "node-fill") {
2650
+ this.updateNode(
2651
+ this.selection?.id,
2652
+ { fill: event.target.value },
2653
+ { inspector: false, reason: "node:update" }
2654
+ );
2655
+ return;
2656
+ }
2657
+ if (field === "node-stroke") {
2658
+ this.updateNode(
2659
+ this.selection?.id,
2660
+ { stroke: event.target.value },
2661
+ { inspector: false, reason: "node:update" }
2662
+ );
2663
+ return;
2664
+ }
2665
+ if (field === "node-text-color") {
2666
+ this.updateNode(
2667
+ this.selection?.id,
2668
+ { textColor: event.target.value },
2669
+ { inspector: false, reason: "node:update" }
2670
+ );
2671
+ return;
2672
+ }
2673
+ if (field === "edge-color") {
2674
+ this.updateEdge(
2675
+ this.selection?.id,
2676
+ { color: event.target.value },
2677
+ { inspector: false, reason: "edge:update" }
2678
+ );
2219
2679
  }
2220
2680
  }
2221
2681
  handleSelectionFieldChange(event) {
@@ -2259,6 +2719,14 @@ var VdFlowchart = class {
2259
2719
  { strokeWidth: getStrokePresetWidth(event.target.value) },
2260
2720
  { inspector: true, reason: "edge:update" }
2261
2721
  );
2722
+ return;
2723
+ }
2724
+ if (field === "edge-stroke-style") {
2725
+ this.updateEdge(
2726
+ this.selection?.id,
2727
+ { strokeStyle: event.target.value },
2728
+ { inspector: true, reason: "edge:update" }
2729
+ );
2262
2730
  }
2263
2731
  }
2264
2732
  // Keys the editor consumes stop here, so page-level shortcuts (a docs
@@ -2281,6 +2749,11 @@ var VdFlowchart = class {
2281
2749
  this.toggleShortcutsHelp(false);
2282
2750
  return;
2283
2751
  }
2752
+ if (key === "Escape" && this.colorPopoverOpen) {
2753
+ event.preventDefault();
2754
+ this.toggleColorPopover(false);
2755
+ return;
2756
+ }
2284
2757
  if (target === this.canvasEl && this.handleCanvasKeyDown(event)) {
2285
2758
  event.preventDefault();
2286
2759
  return;
@@ -2303,6 +2776,29 @@ var VdFlowchart = class {
2303
2776
  }
2304
2777
  return;
2305
2778
  }
2779
+ if (modKey && (key === "l" || key === "L")) {
2780
+ if (this.selection?.kind === "node") {
2781
+ event.preventDefault();
2782
+ this.toggleNodeLocked();
2783
+ }
2784
+ return;
2785
+ }
2786
+ if (modKey && (key === "]" || key === "}" || event.code === "BracketRight")) {
2787
+ if (this.selection) {
2788
+ event.preventDefault();
2789
+ if (event.shiftKey || key === "}") this.bringToFront();
2790
+ else this.bringForward();
2791
+ }
2792
+ return;
2793
+ }
2794
+ if (modKey && (key === "[" || key === "{" || event.code === "BracketLeft")) {
2795
+ if (this.selection) {
2796
+ event.preventDefault();
2797
+ if (event.shiftKey || key === "{") this.sendToBack();
2798
+ else this.sendBackward();
2799
+ }
2800
+ return;
2801
+ }
2306
2802
  if (modKey && (event.key === "z" || event.key === "Z")) {
2307
2803
  event.preventDefault();
2308
2804
  if (event.shiftKey) {
@@ -2485,7 +2981,7 @@ var VdFlowchart = class {
2485
2981
  nudgeNodes(nodeIds, direction, distance) {
2486
2982
  const step = { right: [1, 0], left: [-1, 0], down: [0, 1], up: [0, -1] }[direction];
2487
2983
  if (this.readonly || !step) return [];
2488
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
2984
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
2489
2985
  if (!nodes.length) return [];
2490
2986
  nodes.forEach((node) => {
2491
2987
  node.x = formatNumber(node.x + step[0] * distance);
@@ -2624,6 +3120,14 @@ var VdFlowchart = class {
2624
3120
  this.emitChange("edge:add", { edge: deepClone(edge) });
2625
3121
  return true;
2626
3122
  }
3123
+ pasteSelection() {
3124
+ if (!this.pasteClipboard()) return null;
3125
+ if (this.hasMultiSelection()) {
3126
+ return this.getSelectedNodeIds().map((id) => this.findNode(id)).filter(Boolean).map((node) => deepClone(node));
3127
+ }
3128
+ const snap = this.getSelectionSnapshot();
3129
+ return snap?.node || snap?.edge || null;
3130
+ }
2627
3131
  cutSelection() {
2628
3132
  if (!this.copySelection()) return false;
2629
3133
  return this.deleteSelection();
@@ -2661,6 +3165,9 @@ var VdFlowchart = class {
2661
3165
  }
2662
3166
  handlePointerDown(event) {
2663
3167
  if (this.destroyed || event.button != null && event.button !== 0) return;
3168
+ if (this.colorPopoverOpen) {
3169
+ this.toggleColorPopover(false);
3170
+ }
2664
3171
  if (this.textEditor && !event.target.closest(".vd-flowchart-text-editor")) {
2665
3172
  this.stopTextEdit({ commit: true });
2666
3173
  }
@@ -2685,6 +3192,8 @@ var VdFlowchart = class {
2685
3192
  const fromNode = this.findNode(edge.from.nodeId);
2686
3193
  const toNode = this.findNode(edge.to.nodeId);
2687
3194
  if (!fromNode || !toNode) return;
3195
+ const endpointNode = endpoint === "from" ? fromNode : toNode;
3196
+ if (endpointNode.locked) return;
2688
3197
  this.reconnectEdgeId = edgeId;
2689
3198
  this.select({ kind: "edge", id: edgeId });
2690
3199
  this.interaction = {
@@ -2735,7 +3244,7 @@ var VdFlowchart = class {
2735
3244
  const nodeId = portTarget.getAttribute("data-node-id");
2736
3245
  const port = portTarget.getAttribute("data-port");
2737
3246
  const node = this.findNode(nodeId);
2738
- if (!node) return;
3247
+ if (!node || node.locked) return;
2739
3248
  const sourcePoint = getPortPosition(node, port);
2740
3249
  this.interaction = {
2741
3250
  kind: "connect",
@@ -2764,7 +3273,7 @@ var VdFlowchart = class {
2764
3273
  const nodeId = resizeTarget.getAttribute("data-node-id");
2765
3274
  const handle = resizeTarget.getAttribute("data-resize-handle");
2766
3275
  const node = this.findNode(nodeId);
2767
- if (!node || !RESIZE_HANDLES.includes(handle)) return;
3276
+ if (!node || !isNodeResizable(node) || !RESIZE_HANDLES.includes(handle)) return;
2768
3277
  this.select({ kind: "node", id: nodeId });
2769
3278
  this.interaction = {
2770
3279
  kind: "resize-node",
@@ -2797,8 +3306,11 @@ var VdFlowchart = class {
2797
3306
  if (groupIds.length > 1) this.selectNodes(groupIds, { primary: nodeId });
2798
3307
  else this.select({ kind: "node", id: nodeId });
2799
3308
  if (!this.readonly) {
2800
- this.interaction = this.createDragInteraction(event, nodeId, groupIds);
2801
- this.capturePointer(event.pointerId);
3309
+ const drag = this.createDragInteraction(event, nodeId, groupIds);
3310
+ if (drag) {
3311
+ this.interaction = drag;
3312
+ this.capturePointer(event.pointerId);
3313
+ }
2802
3314
  }
2803
3315
  return;
2804
3316
  }
@@ -2829,12 +3341,13 @@ var VdFlowchart = class {
2829
3341
  event.preventDefault();
2830
3342
  }
2831
3343
  createDragInteraction(event, nodeId, nodeIds) {
2832
- const nodes = nodeIds.map((id) => this.findNode(id)).filter(Boolean);
3344
+ const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
3345
+ if (!nodes.length) return null;
2833
3346
  const moving = new Set(nodes.map((node) => node.id));
2834
3347
  return {
2835
3348
  kind: "drag-node",
2836
3349
  pointerId: event.pointerId,
2837
- nodeId,
3350
+ nodeId: moving.has(nodeId) ? nodeId : nodes[0].id,
2838
3351
  nodeIds: nodes.map((node) => node.id),
2839
3352
  startWorld: this.clientToWorld(event.clientX, event.clientY),
2840
3353
  origins: new Map(nodes.map((node) => [node.id, { x: node.x, y: node.y }])),
@@ -3186,15 +3699,16 @@ var VdFlowchart = class {
3186
3699
  if (this.activeTool === "arrow") return true;
3187
3700
  return this.selection?.kind === "node" && this.selection.id === node.id && !this.hasMultiSelection();
3188
3701
  }
3189
- getMarkerId(markerType, position, strokeWidth, edgeScale = 1) {
3702
+ getMarkerId(markerType, position, strokeWidth, edgeScale = 1, color = "") {
3190
3703
  const width = normalizeEdgeStrokeWidth(strokeWidth);
3191
3704
  const scale = clamp(formatNumber(Math.max(edgeScale, 0.01)), 0.01, 1);
3192
- const key = `${markerType}:${position}:${width}:${scale}`;
3705
+ const fill = resolveEdgeColorValue(color);
3706
+ const key = `${markerType}:${position}:${width}:${scale}:${fill}`;
3193
3707
  if (this.markerIds.has(key)) {
3194
3708
  return this.markerIds.get(key);
3195
3709
  }
3196
3710
  const markerId = nextId(`flowchart-${markerType}-${position}`);
3197
- const marker = markerType === "dot" ? createDotMarker(markerId, width, scale) : createArrowMarker(markerId, width, position === "start", scale);
3711
+ const marker = markerType === "dot" ? createDotMarker(markerId, width, scale, fill) : createArrowMarker(markerId, width, position === "start", scale, fill);
3198
3712
  this.markerDefs.appendChild(marker);
3199
3713
  this.markerIds.set(key, markerId);
3200
3714
  return markerId;
@@ -3216,7 +3730,7 @@ var VdFlowchart = class {
3216
3730
  const snapPadding = CONNECTION_SNAP_PADDING / this.documentData.viewport.scale;
3217
3731
  const hysteresisMargin = CONNECTION_HYSTERESIS / this.documentData.viewport.scale;
3218
3732
  const best = this.getVisibleNodes().reduce((candidate, node) => {
3219
- if (node.id === excludeNodeId) return candidate;
3733
+ if (node.id === excludeNodeId || node.locked) return candidate;
3220
3734
  const distanceToBounds2 = getDistanceToNodeBounds(node, worldPoint);
3221
3735
  if (distanceToBounds2 > snapPadding) return candidate;
3222
3736
  const nearest = pickPortForNode(node, worldPoint, referencePoint);
@@ -3234,7 +3748,7 @@ var VdFlowchart = class {
3234
3748
  }, null);
3235
3749
  if (!previousSnap || !best) return best;
3236
3750
  const previousNode = this.findNode(previousSnap.nodeId);
3237
- if (!previousNode || previousNode.id === excludeNodeId) return best;
3751
+ if (!previousNode || previousNode.id === excludeNodeId || previousNode.locked) return best;
3238
3752
  const distanceToBounds = getDistanceToNodeBounds(previousNode, worldPoint);
3239
3753
  if (distanceToBounds > snapPadding) return best;
3240
3754
  if (best.node.id === previousSnap.nodeId && best.port === previousSnap.port) {
@@ -3425,7 +3939,7 @@ var VdFlowchart = class {
3425
3939
  if (event.key === "Escape" || event.key === "Enter") {
3426
3940
  event.preventDefault();
3427
3941
  this.stopTextEdit({ commit: event.key === "Enter" });
3428
- this.canvasEl.focus();
3942
+ this.focusCanvas({ quiet: true });
3429
3943
  }
3430
3944
  });
3431
3945
  textarea.addEventListener("blur", () => {
@@ -3452,7 +3966,7 @@ var VdFlowchart = class {
3452
3966
  if (event.key === "Escape") {
3453
3967
  event.preventDefault();
3454
3968
  this.stopTextEdit({ commit: false });
3455
- this.canvasEl.focus();
3969
+ this.focusCanvas({ quiet: true });
3456
3970
  return;
3457
3971
  }
3458
3972
  if (event.key === "Enter") {
@@ -3461,13 +3975,12 @@ var VdFlowchart = class {
3461
3975
  if (!commits) return;
3462
3976
  event.preventDefault();
3463
3977
  this.stopTextEdit({ commit: true });
3464
- this.canvasEl.focus();
3978
+ this.focusCanvas({ quiet: true });
3465
3979
  return;
3466
3980
  }
3467
3981
  if (event.key === "Tab" && mindmap && !event.shiftKey && !event.altKey && !event.ctrlKey) {
3468
3982
  event.preventDefault();
3469
3983
  this.stopTextEdit({ commit: true });
3470
- this.canvasEl.focus();
3471
3984
  this.insertBranchNode(node.id, { edit: true });
3472
3985
  }
3473
3986
  }
@@ -3650,16 +4163,17 @@ var VdFlowchart = class {
3650
4163
  }
3651
4164
  applyEdgeMarkers(pathElement, edge, edgeScale = 1) {
3652
4165
  const width = this.getEdgeStrokeWidth(edge);
4166
+ const color = edge.color || "";
3653
4167
  if (edge.startMarker && edge.startMarker !== "none") {
3654
4168
  pathElement.setAttribute(
3655
4169
  "marker-start",
3656
- `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale)})`
4170
+ `url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale, color)})`
3657
4171
  );
3658
4172
  }
3659
4173
  if (edge.endMarker && edge.endMarker !== "none") {
3660
4174
  pathElement.setAttribute(
3661
4175
  "marker-end",
3662
- `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale)})`
4176
+ `url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale, color)})`
3663
4177
  );
3664
4178
  }
3665
4179
  }
@@ -3671,10 +4185,19 @@ var VdFlowchart = class {
3671
4185
  const edgePath = buildEdgePath(edge, fromNode, toNode);
3672
4186
  const selected = this.selection?.kind === "edge" && this.selection.id === edge.id;
3673
4187
  const inReconnectMode = this.reconnectEdgeId === edge.id;
4188
+ const strokeStyle = normalizeEdgeStrokeStyle(edge.strokeStyle);
4189
+ const strokeClass = strokeStyle !== "solid" ? ` is-stroke-${strokeStyle}` : "";
3674
4190
  const group = svgEl("g", {
3675
- class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}`,
4191
+ class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}${strokeClass}`,
3676
4192
  "data-edge-id": edge.id
3677
4193
  });
4194
+ if (edge.color) {
4195
+ if (FLOWCHART_COLOR_PRESETS.includes(edge.color) && edge.color !== "default") {
4196
+ group.setAttribute("data-color", edge.color);
4197
+ } else {
4198
+ group.setAttribute("data-color", "custom");
4199
+ }
4200
+ }
3678
4201
  const baseStroke = this.getEdgeStrokeWidth(edge);
3679
4202
  const strokeWidth = visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke;
3680
4203
  if (selected) {
@@ -3692,6 +4215,20 @@ var VdFlowchart = class {
3692
4215
  "stroke-width": strokeWidth,
3693
4216
  "data-edge-id": edge.id
3694
4217
  });
4218
+ if (edge.color && !FLOWCHART_COLOR_PRESETS.includes(edge.color)) {
4219
+ visiblePath.style.stroke = edge.color;
4220
+ }
4221
+ if (strokeStyle === "dashed" || strokeStyle === "animated") {
4222
+ visiblePath.setAttribute(
4223
+ "stroke-dasharray",
4224
+ visual < 0.999 ? `${formatNumber(8 * visual)} ${formatNumber(5 * visual)}` : "8 5"
4225
+ );
4226
+ } else if (strokeStyle === "dotted") {
4227
+ visiblePath.setAttribute(
4228
+ "stroke-dasharray",
4229
+ visual < 0.999 ? `${formatNumber(2 * visual)} ${formatNumber(5 * visual)}` : "2 5"
4230
+ );
4231
+ }
3695
4232
  this.applyEdgeMarkers(visiblePath, edge, visual);
3696
4233
  const hitPath = svgEl("path", {
3697
4234
  class: "vd-flowchart-edge-hit",
@@ -3774,6 +4311,36 @@ var VdFlowchart = class {
3774
4311
  "stroke-width": visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke
3775
4312
  });
3776
4313
  }
4314
+ renderLockBadge(node) {
4315
+ const scale = this.documentData.viewport.scale || 1;
4316
+ const badgeSize = 16 / scale;
4317
+ const offsetX = node.width - badgeSize / 2 - 4 / scale;
4318
+ const offsetY = badgeSize / 2 + 4 / scale;
4319
+ const badge = svgEl("g", {
4320
+ class: "vd-flowchart-node-lock",
4321
+ transform: `translate(${formatNumber(offsetX)} ${formatNumber(offsetY)})`,
4322
+ "data-node-id": node.id
4323
+ });
4324
+ const title = svgEl("title");
4325
+ title.textContent = "Locked node";
4326
+ badge.appendChild(title);
4327
+ badge.appendChild(
4328
+ svgEl("circle", {
4329
+ cx: 0,
4330
+ cy: 0,
4331
+ r: formatNumber(badgeSize / 2)
4332
+ })
4333
+ );
4334
+ const iconScale = badgeSize * 0.62 / 256;
4335
+ const iconOffset = -128 * iconScale;
4336
+ badge.appendChild(
4337
+ svgEl("path", {
4338
+ d: TOOLBAR_ICON_PATHS.lock,
4339
+ transform: `translate(${formatNumber(iconOffset)} ${formatNumber(iconOffset)}) scale(${formatScale(iconScale)})`
4340
+ })
4341
+ );
4342
+ return badge;
4343
+ }
3777
4344
  renderNode(node) {
3778
4345
  const selected = this.isNodeSelected(node.id);
3779
4346
  const soloSelected = selected && !this.hasMultiSelection();
@@ -3781,10 +4348,13 @@ var VdFlowchart = class {
3781
4348
  const resizing = this.interaction?.kind === "resize-node" && this.interaction.nodeId === node.id;
3782
4349
  const editing = this.textEditor?.nodeId === node.id;
3783
4350
  const group = svgEl("g", {
3784
- class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}`,
4351
+ class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}${node.locked ? " is-locked" : ""}`,
3785
4352
  transform: `translate(${formatNumber(node.x)} ${formatNumber(node.y)})`,
3786
4353
  "data-node-id": node.id
3787
4354
  });
4355
+ if (node.color) {
4356
+ group.setAttribute("data-color", node.color);
4357
+ }
3788
4358
  const portsVisible = this.shouldShowNodePorts(node);
3789
4359
  const visual = nodeVisualScale(node);
3790
4360
  const corner = node.type === "rounded-rect" || node.type === "textbox" ? 16 : node.type === "junction" ? node.width / 2 : 6;
@@ -3800,8 +4370,15 @@ var VdFlowchart = class {
3800
4370
  group.appendChild(hitbox);
3801
4371
  const shape = this.renderNodeShape(node);
3802
4372
  this.applyScaledNodeShape(node, shape);
4373
+ if (node.fill) shape.style.fill = node.fill;
4374
+ if (node.stroke) shape.style.stroke = node.stroke;
3803
4375
  group.appendChild(shape);
3804
- group.appendChild(this.renderNodeText(node));
4376
+ const textEl = this.renderNodeText(node);
4377
+ if (node.textColor) textEl.style.fill = node.textColor;
4378
+ group.appendChild(textEl);
4379
+ if (node.locked) {
4380
+ group.appendChild(this.renderLockBadge(node));
4381
+ }
3805
4382
  const scale = this.documentData.viewport.scale || 1;
3806
4383
  if (soloSelected && !this.readonly && SELECTION_BOX_TYPES.has(node.type)) {
3807
4384
  const outset = SELECTION_OUTSET / scale;
@@ -4121,6 +4698,127 @@ var VdFlowchart = class {
4121
4698
  });
4122
4699
  return textElement;
4123
4700
  }
4701
+ buildInspectorColorSwatches(activePreset = "default", disabled = this.readonly) {
4702
+ const normalizedActive = activePreset || "default";
4703
+ const grid = createElement("div", { className: "vd-flowchart-swatch-grid" });
4704
+ FLOWCHART_COLOR_PRESETS.forEach((preset) => {
4705
+ const active = preset === normalizedActive;
4706
+ const button = createElement("button", {
4707
+ className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}${active ? " is-active" : ""}`,
4708
+ title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset,
4709
+ disabled
4710
+ });
4711
+ button.setAttribute("type", "button");
4712
+ button.setAttribute("data-color-preset", preset);
4713
+ button.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
4714
+ button.setAttribute("aria-pressed", active ? "true" : "false");
4715
+ grid.appendChild(button);
4716
+ });
4717
+ return grid;
4718
+ }
4719
+ buildInspectorArrangeRow(disabled = this.readonly) {
4720
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4721
+ const actions = [
4722
+ {
4723
+ action: "bring-to-front",
4724
+ label: "Front",
4725
+ title: "Bring to front (Cmd/Ctrl+Shift+])"
4726
+ },
4727
+ {
4728
+ action: "bring-forward",
4729
+ label: "Forward",
4730
+ title: "Bring forward (Cmd/Ctrl+])"
4731
+ },
4732
+ {
4733
+ action: "send-backward",
4734
+ label: "Backward",
4735
+ title: "Send backward (Cmd/Ctrl+[)"
4736
+ },
4737
+ {
4738
+ action: "send-to-back",
4739
+ label: "Back",
4740
+ title: "Send to back (Cmd/Ctrl+Shift+[)"
4741
+ }
4742
+ ];
4743
+ actions.forEach((item) => {
4744
+ const btn = createElement("button", {
4745
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4746
+ text: item.label,
4747
+ title: item.title,
4748
+ disabled
4749
+ });
4750
+ btn.setAttribute("type", "button");
4751
+ btn.setAttribute("data-arrange-action", item.action);
4752
+ grid.appendChild(btn);
4753
+ });
4754
+ return grid;
4755
+ }
4756
+ buildInspectorAlignRow(nodeCount, disabled = this.readonly) {
4757
+ const wrap = createElement("div", { className: "vd-flowchart-inspector-stack" });
4758
+ const alignGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4759
+ const alignments = [
4760
+ { action: "left", label: "Left", title: "Align left edges" },
4761
+ { action: "center", label: "Center", title: "Align horizontal centers" },
4762
+ { action: "right", label: "Right", title: "Align right edges" },
4763
+ { action: "top", label: "Top", title: "Align top edges" },
4764
+ { action: "middle", label: "Middle", title: "Align vertical centers" },
4765
+ { action: "bottom", label: "Bottom", title: "Align bottom edges" }
4766
+ ];
4767
+ alignments.forEach((item) => {
4768
+ const btn = createElement("button", {
4769
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4770
+ text: item.label,
4771
+ title: item.title,
4772
+ disabled: disabled || nodeCount < 2
4773
+ });
4774
+ btn.setAttribute("type", "button");
4775
+ btn.setAttribute("data-align-action", item.action);
4776
+ alignGrid.appendChild(btn);
4777
+ });
4778
+ wrap.appendChild(createField("Align", alignGrid));
4779
+ const distributeGrid = createElement("div", { className: "vd-flowchart-action-grid" });
4780
+ [
4781
+ { action: "horizontal", label: "Distribute H", title: "Distribute horizontally" },
4782
+ { action: "vertical", label: "Distribute V", title: "Distribute vertically" }
4783
+ ].forEach((item) => {
4784
+ const btn = createElement("button", {
4785
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4786
+ text: item.label,
4787
+ title: item.title,
4788
+ disabled: disabled || nodeCount < 3
4789
+ });
4790
+ btn.setAttribute("type", "button");
4791
+ btn.setAttribute("data-distribute-action", item.action);
4792
+ distributeGrid.appendChild(btn);
4793
+ });
4794
+ wrap.appendChild(createField("Distribute", distributeGrid));
4795
+ return wrap;
4796
+ }
4797
+ buildInspectorUtilityRow({ showLock = true, locked = false, disabled = this.readonly } = {}) {
4798
+ const grid = createElement("div", { className: "vd-flowchart-action-grid" });
4799
+ if (showLock) {
4800
+ const lockBtn = createElement("button", {
4801
+ className: `vd-flowchart-btn vd-flowchart-action-btn${locked ? " is-active" : ""}`,
4802
+ text: locked ? "Unlock" : "Lock",
4803
+ title: "Toggle node lock (Cmd/Ctrl+L)",
4804
+ disabled
4805
+ });
4806
+ lockBtn.setAttribute("type", "button");
4807
+ lockBtn.setAttribute("data-lock-toggle", "");
4808
+ lockBtn.setAttribute("aria-pressed", locked ? "true" : "false");
4809
+ grid.appendChild(lockBtn);
4810
+ }
4811
+ const resetBtn = createElement("button", {
4812
+ className: "vd-flowchart-btn vd-flowchart-action-btn",
4813
+ text: "Reset color",
4814
+ title: "Reset to theme default color",
4815
+ disabled
4816
+ });
4817
+ resetBtn.setAttribute("type", "button");
4818
+ resetBtn.setAttribute("data-color-reset", "");
4819
+ grid.appendChild(resetBtn);
4820
+ return grid;
4821
+ }
4124
4822
  renderSelectionPanel() {
4125
4823
  clearChildren(this.selectionFields);
4126
4824
  this.deleteButton.disabled = this.readonly || !this.selection;
@@ -4135,6 +4833,11 @@ var VdFlowchart = class {
4135
4833
  return;
4136
4834
  }
4137
4835
  if (this.hasMultiSelection()) {
4836
+ const selectedIds = this.getSelectedNodeIds();
4837
+ const selectedNodes = selectedIds.map((id) => this.findNode(id)).filter(Boolean);
4838
+ const allLocked = selectedNodes.length > 0 && selectedNodes.every((n) => n.locked);
4839
+ this.deleteButton.disabled = this.readonly || allLocked;
4840
+ const sharedColor = selectedNodes.length > 0 && selectedNodes.every((n) => (n.color || "default") === (selectedNodes[0].color || "default")) ? selectedNodes[0].color || "default" : "";
4138
4841
  this.selectionMeta.textContent = `${this.selectedNodeIds.size} nodes selected`;
4139
4842
  this.selectionFields.appendChild(
4140
4843
  createElement("p", {
@@ -4142,6 +4845,22 @@ var VdFlowchart = class {
4142
4845
  text: "Drag, nudge with Alt+Arrow, copy, duplicate, or delete them together."
4143
4846
  })
4144
4847
  );
4848
+ this.selectionFields.appendChild(
4849
+ createField("Color preset", this.buildInspectorColorSwatches(sharedColor, this.readonly))
4850
+ );
4851
+ this.selectionFields.appendChild(
4852
+ this.buildInspectorAlignRow(selectedNodes.length, this.readonly)
4853
+ );
4854
+ this.selectionFields.appendChild(
4855
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
4856
+ );
4857
+ this.selectionFields.appendChild(
4858
+ this.buildInspectorUtilityRow({
4859
+ showLock: true,
4860
+ locked: allLocked,
4861
+ disabled: this.readonly
4862
+ })
4863
+ );
4145
4864
  return;
4146
4865
  }
4147
4866
  if (this.selection.kind === "node") {
@@ -4151,8 +4870,10 @@ var VdFlowchart = class {
4151
4870
  this.renderSelectionPanel();
4152
4871
  return;
4153
4872
  }
4154
- this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}`;
4155
- const typeSelect = createElement("select");
4873
+ const isLocked = Boolean(node.locked);
4874
+ this.deleteButton.disabled = this.readonly || isLocked;
4875
+ this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}${isLocked ? " \xB7 locked" : ""}`;
4876
+ const typeSelect = createElement("select", { disabled: this.readonly || isLocked });
4156
4877
  typeSelect.setAttribute("data-field", "node-type");
4157
4878
  FLOWCHART_NODE_TYPES.forEach((type) => {
4158
4879
  const option = createElement("option", { value: type, text: type.replace("-", " ") });
@@ -4160,13 +4881,25 @@ var VdFlowchart = class {
4160
4881
  option.selected = type === node.type;
4161
4882
  typeSelect.appendChild(option);
4162
4883
  });
4163
- const textArea = createElement("textarea", { value: node.text, rows: 5 });
4884
+ const textArea = createElement("textarea", {
4885
+ value: node.text,
4886
+ rows: 5,
4887
+ disabled: this.readonly || isLocked
4888
+ });
4164
4889
  textArea.setAttribute("data-field", "node-text");
4165
- const widthInput = createElement("input", { value: node.width, type: "number" });
4890
+ const widthInput = createElement("input", {
4891
+ value: node.width,
4892
+ type: "number",
4893
+ disabled: this.readonly || isLocked
4894
+ });
4166
4895
  widthInput.setAttribute("data-field", "node-width");
4167
4896
  widthInput.setAttribute("min", String(this.minNodeSize));
4168
4897
  widthInput.setAttribute("max", String(this.maxNodeSize));
4169
- const heightInput = createElement("input", { value: node.height, type: "number" });
4898
+ const heightInput = createElement("input", {
4899
+ value: node.height,
4900
+ type: "number",
4901
+ disabled: this.readonly || isLocked
4902
+ });
4170
4903
  heightInput.setAttribute("data-field", "node-height");
4171
4904
  heightInput.setAttribute("min", String(this.minNodeSize));
4172
4905
  heightInput.setAttribute("max", String(this.maxNodeSize));
@@ -4187,6 +4920,48 @@ var VdFlowchart = class {
4187
4920
  })
4188
4921
  );
4189
4922
  }
4923
+ this.selectionFields.appendChild(
4924
+ createField(
4925
+ "Color preset",
4926
+ this.buildInspectorColorSwatches(node.color || "default", this.readonly || isLocked)
4927
+ )
4928
+ );
4929
+ const customColorsGrid = createElement("div", { className: "vd-flowchart-field-grid" });
4930
+ const fillInput = createElement("input", {
4931
+ value: node.fill || "",
4932
+ type: "text",
4933
+ disabled: this.readonly || isLocked
4934
+ });
4935
+ fillInput.setAttribute("data-field", "node-fill");
4936
+ fillInput.setAttribute("placeholder", "Fill (e.g. #dbeafe)");
4937
+ const strokeInput = createElement("input", {
4938
+ value: node.stroke || "",
4939
+ type: "text",
4940
+ disabled: this.readonly || isLocked
4941
+ });
4942
+ strokeInput.setAttribute("data-field", "node-stroke");
4943
+ strokeInput.setAttribute("placeholder", "Stroke (e.g. #2563eb)");
4944
+ const textColorInput = createElement("input", {
4945
+ value: node.textColor || "",
4946
+ type: "text",
4947
+ disabled: this.readonly || isLocked
4948
+ });
4949
+ textColorInput.setAttribute("data-field", "node-text-color");
4950
+ textColorInput.setAttribute("placeholder", "Text (e.g. #1e3a8a)");
4951
+ customColorsGrid.appendChild(createField("Fill", fillInput));
4952
+ customColorsGrid.appendChild(createField("Border", strokeInput));
4953
+ this.selectionFields.appendChild(customColorsGrid);
4954
+ this.selectionFields.appendChild(createField("Text color", textColorInput));
4955
+ this.selectionFields.appendChild(
4956
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
4957
+ );
4958
+ this.selectionFields.appendChild(
4959
+ this.buildInspectorUtilityRow({
4960
+ showLock: true,
4961
+ locked: isLocked,
4962
+ disabled: this.readonly
4963
+ })
4964
+ );
4190
4965
  return;
4191
4966
  }
4192
4967
  const edge = this.findEdge(this.selection.id);
@@ -4195,8 +4970,9 @@ var VdFlowchart = class {
4195
4970
  this.renderSelectionPanel();
4196
4971
  return;
4197
4972
  }
4973
+ const edgeStyleName = normalizeEdgeStrokeStyle(edge.strokeStyle);
4198
4974
  this.selectionMeta.textContent = `Edge ${edge.id} \xB7 ${edge.route} \xB7 ${formatNumber(edge.strokeWidth)}px \xB7 ${edge.startMarker} \u2192 ${edge.endMarker}`;
4199
- const routeSelect = createElement("select");
4975
+ const routeSelect = createElement("select", { disabled: this.readonly });
4200
4976
  routeSelect.setAttribute("data-field", "edge-route");
4201
4977
  FLOWCHART_EDGE_ROUTES.forEach((route) => {
4202
4978
  const option = createElement("option", {
@@ -4207,7 +4983,7 @@ var VdFlowchart = class {
4207
4983
  option.selected = route === edge.route;
4208
4984
  routeSelect.appendChild(option);
4209
4985
  });
4210
- const startSelect = createElement("select");
4986
+ const startSelect = createElement("select", { disabled: this.readonly });
4211
4987
  startSelect.setAttribute("data-field", "edge-start-marker");
4212
4988
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4213
4989
  const option = createElement("option", { value: marker, text: marker });
@@ -4215,7 +4991,7 @@ var VdFlowchart = class {
4215
4991
  option.selected = marker === edge.startMarker;
4216
4992
  startSelect.appendChild(option);
4217
4993
  });
4218
- const endSelect = createElement("select");
4994
+ const endSelect = createElement("select", { disabled: this.readonly });
4219
4995
  endSelect.setAttribute("data-field", "edge-end-marker");
4220
4996
  FLOWCHART_EDGE_MARKERS.forEach((marker) => {
4221
4997
  const option = createElement("option", { value: marker, text: marker });
@@ -4223,7 +4999,7 @@ var VdFlowchart = class {
4223
4999
  option.selected = marker === edge.endMarker;
4224
5000
  endSelect.appendChild(option);
4225
5001
  });
4226
- const widthSelect = createElement("select");
5002
+ const widthSelect = createElement("select", { disabled: this.readonly });
4227
5003
  widthSelect.setAttribute("data-field", "edge-stroke-preset");
4228
5004
  EDGE_STROKE_PRESETS.forEach((preset) => {
4229
5005
  const option = createElement("option", { value: preset.id, text: preset.label });
@@ -4231,15 +5007,52 @@ var VdFlowchart = class {
4231
5007
  option.selected = preset.id === getStrokePresetId(edge.strokeWidth);
4232
5008
  widthSelect.appendChild(option);
4233
5009
  });
4234
- const labelInput = createElement("textarea", { value: edge.label, rows: 4 });
5010
+ const strokeStyleSelect = createElement("select", { disabled: this.readonly });
5011
+ strokeStyleSelect.setAttribute("data-field", "edge-stroke-style");
5012
+ FLOWCHART_EDGE_STROKE_STYLES.forEach((style) => {
5013
+ const option = createElement("option", {
5014
+ value: style,
5015
+ text: FLOWCHART_EDGE_STROKE_STYLE_LABELS[style] || style
5016
+ });
5017
+ option.value = style;
5018
+ option.selected = style === edgeStyleName;
5019
+ strokeStyleSelect.appendChild(option);
5020
+ });
5021
+ const labelInput = createElement("textarea", {
5022
+ value: edge.label,
5023
+ rows: 4,
5024
+ disabled: this.readonly
5025
+ });
4235
5026
  labelInput.setAttribute("data-field", "edge-label");
4236
5027
  const markerGrid = createElement("div", { className: "vd-flowchart-field-grid" });
4237
5028
  markerGrid.appendChild(createField("Route", routeSelect));
4238
5029
  markerGrid.appendChild(createField("Weight", widthSelect));
5030
+ markerGrid.appendChild(createField("Style", strokeStyleSelect));
4239
5031
  markerGrid.appendChild(createField("Start", startSelect));
4240
5032
  markerGrid.appendChild(createField("End", endSelect));
4241
5033
  this.selectionFields.appendChild(markerGrid);
4242
5034
  this.selectionFields.appendChild(createField("Label", labelInput));
5035
+ const activeEdgePreset = edge.color && FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "default";
5036
+ this.selectionFields.appendChild(
5037
+ createField(
5038
+ "Color preset",
5039
+ this.buildInspectorColorSwatches(activeEdgePreset, this.readonly)
5040
+ )
5041
+ );
5042
+ const edgeColorInput = createElement("input", {
5043
+ value: edge.color && !FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "",
5044
+ type: "text",
5045
+ disabled: this.readonly
5046
+ });
5047
+ edgeColorInput.setAttribute("data-field", "edge-color");
5048
+ edgeColorInput.setAttribute("placeholder", "Custom color (e.g. #2563eb)");
5049
+ this.selectionFields.appendChild(createField("Custom color", edgeColorInput));
5050
+ this.selectionFields.appendChild(
5051
+ createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
5052
+ );
5053
+ this.selectionFields.appendChild(
5054
+ this.buildInspectorUtilityRow({ showLock: false, disabled: this.readonly })
5055
+ );
4243
5056
  }
4244
5057
  syncJsonTextarea(force = false) {
4245
5058
  if (!force && document.activeElement === this.jsonTextarea) {
@@ -4645,7 +5458,14 @@ var VdFlowchart = class {
4645
5458
  // the parent's box shape, falling back to a rounded step.
4646
5459
  getBranchTemplate(parent, sibling) {
4647
5460
  const source = sibling || (["rounded-rect", "rect", "textbox"].includes(parent.type) ? parent : null) || null;
4648
- if (source) return { type: source.type, width: source.width, height: source.height };
5461
+ if (source) {
5462
+ const template = { type: source.type, width: source.width, height: source.height };
5463
+ if (source.color) template.color = source.color;
5464
+ if (source.fill) template.fill = source.fill;
5465
+ if (source.stroke) template.stroke = source.stroke;
5466
+ if (source.textColor) template.textColor = source.textColor;
5467
+ return template;
5468
+ }
4649
5469
  const spec = DEFAULT_NODE_SPECS["rounded-rect"];
4650
5470
  return { type: "rounded-rect", width: spec.width, height: spec.height };
4651
5471
  }
@@ -4681,7 +5501,9 @@ var VdFlowchart = class {
4681
5501
  route: styleSource.route,
4682
5502
  strokeWidth: styleSource.strokeWidth,
4683
5503
  startMarker: styleSource.startMarker,
4684
- endMarker: styleSource.endMarker
5504
+ endMarker: styleSource.endMarker,
5505
+ ...styleSource.color ? { color: styleSource.color } : {},
5506
+ ...styleSource.strokeStyle ? { strokeStyle: styleSource.strokeStyle } : {}
4685
5507
  } : { endMarker: "arrow" };
4686
5508
  const result = this.batchHistory("node:insert", () => {
4687
5509
  if (parent.collapsed) delete parent.collapsed;
@@ -4775,7 +5597,7 @@ var VdFlowchart = class {
4775
5597
  changed = true;
4776
5598
  }
4777
5599
  });
4778
- const rerouted = options.reroutePorts === false ? false : this.rerouteEdgePorts();
5600
+ const rerouted = options.reroutePorts === false ? false : this.rerouteEdgePorts(resolvedMode === "tree" ? options.direction || "right" : null);
4779
5601
  if (!changed && !rerouted) return this;
4780
5602
  this.render();
4781
5603
  this.emitChange("layout", { mode: resolvedMode });
@@ -4788,8 +5610,16 @@ var VdFlowchart = class {
4788
5610
  // Re-pick each edge's from/to port from the nodes' current centers, so a
4789
5611
  // freshly laid-out graph attaches connectors on sensible sides. Returns
4790
5612
  // whether any port actually changed.
4791
- rerouteEdgePorts() {
5613
+ rerouteEdgePorts(flowDirection = null) {
4792
5614
  let changed = false;
5615
+ const flow = flowDirection === "down" || flowDirection === "up" || flowDirection === "left" || flowDirection === "right" ? flowDirection : null;
5616
+ const outDegree = /* @__PURE__ */ new Map();
5617
+ if (flow) {
5618
+ this.documentData.edges.forEach((edge) => {
5619
+ const fromId = edge?.from?.nodeId;
5620
+ if (fromId) outDegree.set(fromId, (outDegree.get(fromId) || 0) + 1);
5621
+ });
5622
+ }
4793
5623
  this.documentData.edges.forEach((edge) => {
4794
5624
  const fromNode = this.findNode(edge.from.nodeId);
4795
5625
  const toNode = this.findNode(edge.to.nodeId);
@@ -4799,8 +5629,82 @@ var VdFlowchart = class {
4799
5629
  y: fromNode.y + fromNode.height / 2
4800
5630
  };
4801
5631
  const toCenter = { x: toNode.x + toNode.width / 2, y: toNode.y + toNode.height / 2 };
4802
- const nextFrom = getPortByDirection(fromNode, toCenter).port;
4803
- const nextTo = getPortByDirection(toNode, fromCenter).port;
5632
+ let nextFrom;
5633
+ let nextTo;
5634
+ if (flow) {
5635
+ const dx = toCenter.x - fromCenter.x;
5636
+ const dy = toCenter.y - fromCenter.y;
5637
+ const vertical = flow === "down" || flow === "up";
5638
+ const sign = flow === "up" || flow === "left" ? -1 : 1;
5639
+ const mainDelta = (vertical ? dy : dx) * sign;
5640
+ const crossDelta = vertical ? dx : dy;
5641
+ const isDiamondBranch = fromNode.type === "diamond" && (outDegree.get(fromNode.id) || 0) >= 2;
5642
+ if (mainDelta < -8) {
5643
+ const allNodes = this.documentData.nodes;
5644
+ if (vertical) {
5645
+ const minX = Math.min(fromNode.x, toNode.x);
5646
+ const maxRight = Math.max(fromNode.x + fromNode.width, toNode.x + toNode.width);
5647
+ const minY = Math.min(fromCenter.y, toCenter.y) - 8;
5648
+ const maxY = Math.max(fromCenter.y, toCenter.y) + 8;
5649
+ let rightCount = 0;
5650
+ let leftCount = 0;
5651
+ allNodes.forEach((n) => {
5652
+ if (!n || n.id === fromNode.id || n.id === toNode.id) return;
5653
+ const ny = n.y + n.height / 2;
5654
+ if (ny < minY || ny > maxY) return;
5655
+ const nx = n.x + n.width / 2;
5656
+ if (nx >= maxRight - 20) rightCount += 1;
5657
+ if (nx <= minX + 20) leftCount += 1;
5658
+ });
5659
+ const side = leftCount < rightCount ? "left" : rightCount < leftCount ? "right" : crossDelta < -8 ? "left" : "right";
5660
+ nextFrom = side;
5661
+ nextTo = side;
5662
+ } else {
5663
+ const minY = Math.min(fromNode.y, toNode.y);
5664
+ const maxBottom = Math.max(fromNode.y + fromNode.height, toNode.y + toNode.height);
5665
+ const minX = Math.min(fromCenter.x, toCenter.x) - 8;
5666
+ const maxX = Math.max(fromCenter.x, toCenter.x) + 8;
5667
+ let bottomCount = 0;
5668
+ let topCount = 0;
5669
+ allNodes.forEach((n) => {
5670
+ if (!n || n.id === fromNode.id || n.id === toNode.id) return;
5671
+ const nx = n.x + n.width / 2;
5672
+ if (nx < minX || nx > maxX) return;
5673
+ const ny = n.y + n.height / 2;
5674
+ if (ny >= maxBottom - 20) bottomCount += 1;
5675
+ if (ny <= minY + 20) topCount += 1;
5676
+ });
5677
+ const side = topCount < bottomCount ? "top" : bottomCount < topCount ? "bottom" : crossDelta < -8 ? "top" : "bottom";
5678
+ nextFrom = side;
5679
+ nextTo = side;
5680
+ }
5681
+ } else if (mainDelta >= 12) {
5682
+ if (vertical) {
5683
+ nextTo = sign > 0 ? "top" : "bottom";
5684
+ if (isDiamondBranch && Math.abs(crossDelta) >= fromNode.width * 0.45) {
5685
+ nextFrom = crossDelta > 0 ? "right" : "left";
5686
+ } else {
5687
+ nextFrom = sign > 0 ? "bottom" : "top";
5688
+ }
5689
+ } else {
5690
+ nextTo = sign > 0 ? "left" : "right";
5691
+ if (isDiamondBranch && Math.abs(crossDelta) >= fromNode.height * 0.45) {
5692
+ nextFrom = crossDelta > 0 ? "bottom" : "top";
5693
+ } else {
5694
+ nextFrom = sign > 0 ? "right" : "left";
5695
+ }
5696
+ }
5697
+ } else if (vertical) {
5698
+ nextFrom = dx >= 0 ? "right" : "left";
5699
+ nextTo = dx >= 0 ? "left" : "right";
5700
+ } else {
5701
+ nextFrom = dy >= 0 ? "bottom" : "top";
5702
+ nextTo = dy >= 0 ? "top" : "bottom";
5703
+ }
5704
+ } else {
5705
+ nextFrom = getPortByDirection(fromNode, toCenter).port;
5706
+ nextTo = getPortByDirection(toNode, fromCenter).port;
5707
+ }
4804
5708
  if (nextFrom !== edge.from.port || nextTo !== edge.to.port) {
4805
5709
  edge.from.port = nextFrom;
4806
5710
  edge.to.port = nextTo;
@@ -4817,6 +5721,30 @@ var VdFlowchart = class {
4817
5721
  node.text = isNodeTextEditable(nextType) ? patch.text == null ? node.text : String(patch.text) : getNodeSpec(nextType).text;
4818
5722
  node.width = clampNodeWidth(nextType, patch.width, node.width, this.nodeSizeBounds());
4819
5723
  node.height = clampNodeHeight(nextType, patch.height, node.height, this.nodeSizeBounds());
5724
+ if ("color" in patch) {
5725
+ const nextColor = normalizeColorPreset(patch.color);
5726
+ if (nextColor) node.color = nextColor;
5727
+ else delete node.color;
5728
+ }
5729
+ if ("fill" in patch) {
5730
+ const nextFill = sanitizeCssColor(patch.fill);
5731
+ if (nextFill) node.fill = nextFill;
5732
+ else delete node.fill;
5733
+ }
5734
+ if ("stroke" in patch) {
5735
+ const nextStroke = sanitizeCssColor(patch.stroke);
5736
+ if (nextStroke) node.stroke = nextStroke;
5737
+ else delete node.stroke;
5738
+ }
5739
+ if ("textColor" in patch) {
5740
+ const nextTextColor = sanitizeCssColor(patch.textColor);
5741
+ if (nextTextColor) node.textColor = nextTextColor;
5742
+ else delete node.textColor;
5743
+ }
5744
+ if ("locked" in patch) {
5745
+ if (patch.locked) node.locked = true;
5746
+ else delete node.locked;
5747
+ }
4820
5748
  if (isPlainObject(patch.data)) {
4821
5749
  node.data = deepClone(patch.data);
4822
5750
  }
@@ -4824,6 +5752,11 @@ var VdFlowchart = class {
4824
5752
  updateNode(nodeId, patch = {}, options = {}) {
4825
5753
  const node = this.findNode(nodeId);
4826
5754
  if (!node) return null;
5755
+ if (node.locked) {
5756
+ const keys = Object.keys(patch);
5757
+ const unlocking = keys.length > 0 && keys.every((key) => key === "locked") && !patch.locked;
5758
+ if (!unlocking) return null;
5759
+ }
4827
5760
  const previousType = node.type;
4828
5761
  const previousSpec = DEFAULT_NODE_SPECS[previousType];
4829
5762
  this.applyNodePatch(node, patch);
@@ -4928,6 +5861,16 @@ var VdFlowchart = class {
4928
5861
  if (patch.label != null) {
4929
5862
  edge.label = String(patch.label);
4930
5863
  }
5864
+ if ("color" in patch) {
5865
+ const nextColor = normalizeEdgeColor(patch.color);
5866
+ if (nextColor) edge.color = nextColor;
5867
+ else delete edge.color;
5868
+ }
5869
+ if ("strokeStyle" in patch) {
5870
+ const nextStrokeStyle = normalizeEdgeStrokeStyle(patch.strokeStyle);
5871
+ if (nextStrokeStyle && nextStrokeStyle !== "solid") edge.strokeStyle = nextStrokeStyle;
5872
+ else delete edge.strokeStyle;
5873
+ }
4931
5874
  if (isPlainObject(patch.data)) {
4932
5875
  edge.data = deepClone(patch.data);
4933
5876
  }
@@ -5000,11 +5943,405 @@ var VdFlowchart = class {
5000
5943
  deleteSelection() {
5001
5944
  if (!this.selection || this.readonly) return false;
5002
5945
  if (this.hasMultiSelection()) {
5003
- return this.removeNodeIds(new Set(this.getSelectedNodeIds()), "node:remove");
5946
+ const unlockedIds = this.getSelectedNodeIds().filter((id) => !this.findNode(id)?.locked);
5947
+ if (!unlockedIds.length) return false;
5948
+ return this.removeNodeIds(new Set(unlockedIds), "node:remove");
5949
+ }
5950
+ if (this.selection.kind === "node") {
5951
+ const node = this.findNode(this.selection.id);
5952
+ if (node?.locked) return false;
5953
+ return this.removeNode(this.selection.id);
5004
5954
  }
5005
- if (this.selection.kind === "node") return this.removeNode(this.selection.id);
5006
5955
  return this.removeEdge(this.selection.id);
5007
5956
  }
5957
+ // --- Coloring, Layer Order, Align/Distribute, Locking, SVG Export ---------
5958
+ setNodeColor(nodeId, colorOrPatch) {
5959
+ if (this.readonly) return null;
5960
+ const id = sanitizeId(nodeId);
5961
+ if (!this.findNode(id)) return null;
5962
+ let patch;
5963
+ if (isPlainObject(colorOrPatch)) {
5964
+ patch = {};
5965
+ if ("color" in colorOrPatch) patch.color = colorOrPatch.color;
5966
+ if ("fill" in colorOrPatch) patch.fill = colorOrPatch.fill;
5967
+ if ("stroke" in colorOrPatch) patch.stroke = colorOrPatch.stroke;
5968
+ if ("textColor" in colorOrPatch) patch.textColor = colorOrPatch.textColor;
5969
+ } else if (colorOrPatch == null || colorOrPatch === "" || colorOrPatch === "default") {
5970
+ patch = { color: null, fill: null, stroke: null, textColor: null };
5971
+ } else {
5972
+ const token = String(colorOrPatch).trim();
5973
+ if (FLOWCHART_COLOR_PRESET_SET.has(token)) {
5974
+ patch = { color: token, fill: null, stroke: null, textColor: null };
5975
+ } else {
5976
+ const css = sanitizeCssColor(token);
5977
+ if (!css) return null;
5978
+ patch = { fill: css };
5979
+ }
5980
+ }
5981
+ return this.updateNode(id, patch, { reason: "node:color" });
5982
+ }
5983
+ setEdgeColor(edgeId, color) {
5984
+ if (this.readonly) return null;
5985
+ const id = sanitizeId(edgeId);
5986
+ if (!this.findEdge(id)) return null;
5987
+ const nextColor = color == null || color === "" || color === "default" ? null : isPlainObject(color) ? normalizeEdgeColor(color.color ?? color.stroke) : normalizeEdgeColor(color);
5988
+ return this.updateEdge(id, { color: nextColor }, { reason: "edge:color" });
5989
+ }
5990
+ setSelectionColor(colorOrPatch) {
5991
+ if (this.readonly || !this.selection) return this;
5992
+ if (this.selection.kind === "edge") {
5993
+ this.setEdgeColor(this.selection.id, colorOrPatch);
5994
+ return this;
5995
+ }
5996
+ const ids = this.getSelectedNodeIds();
5997
+ if (!ids.length) return this;
5998
+ this.batchHistory("node:color", () => {
5999
+ ids.forEach((id) => {
6000
+ this.setNodeColor(id, colorOrPatch);
6001
+ });
6002
+ });
6003
+ return this;
6004
+ }
6005
+ clearSelectionColor() {
6006
+ return this.setSelectionColor(null);
6007
+ }
6008
+ reorderArrayLayer(items, targetIds, direction) {
6009
+ const idSet = new Set(targetIds);
6010
+ if (!idSet.size || items.length < 2) return null;
6011
+ let next;
6012
+ if (direction === "front") {
6013
+ next = [
6014
+ ...items.filter((item) => !idSet.has(item.id)),
6015
+ ...items.filter((item) => idSet.has(item.id))
6016
+ ];
6017
+ } else if (direction === "back") {
6018
+ next = [
6019
+ ...items.filter((item) => idSet.has(item.id)),
6020
+ ...items.filter((item) => !idSet.has(item.id))
6021
+ ];
6022
+ } else if (direction === "forward") {
6023
+ next = [...items];
6024
+ for (let i = next.length - 2; i >= 0; i -= 1) {
6025
+ if (idSet.has(next[i].id) && !idSet.has(next[i + 1].id)) {
6026
+ const temp = next[i];
6027
+ next[i] = next[i + 1];
6028
+ next[i + 1] = temp;
6029
+ }
6030
+ }
6031
+ } else if (direction === "backward") {
6032
+ next = [...items];
6033
+ for (let i = 1; i < next.length; i += 1) {
6034
+ if (idSet.has(next[i].id) && !idSet.has(next[i - 1].id)) {
6035
+ const temp = next[i];
6036
+ next[i] = next[i - 1];
6037
+ next[i - 1] = temp;
6038
+ }
6039
+ }
6040
+ } else {
6041
+ return null;
6042
+ }
6043
+ const changed = next.some((item, index) => item.id !== items[index].id);
6044
+ return changed ? next : null;
6045
+ }
6046
+ reorderLayer(direction, targetId) {
6047
+ if (this.readonly) return this;
6048
+ let explicitIds = [];
6049
+ if (Array.isArray(targetId)) {
6050
+ explicitIds = targetId.map(sanitizeId).filter(Boolean);
6051
+ } else if (typeof targetId === "string" && targetId.trim()) {
6052
+ explicitIds = [sanitizeId(targetId)];
6053
+ }
6054
+ if (explicitIds.length) {
6055
+ const nodeIdSet = new Set(this.documentData.nodes.map((n) => n.id));
6056
+ const matchingNodes = explicitIds.filter((id) => nodeIdSet.has(id));
6057
+ if (matchingNodes.length) {
6058
+ const reordered2 = this.reorderArrayLayer(this.documentData.nodes, matchingNodes, direction);
6059
+ if (reordered2) {
6060
+ this.documentData.nodes = reordered2;
6061
+ this.render();
6062
+ this.emitChange("node:order", { direction, nodeIds: matchingNodes });
6063
+ }
6064
+ return this;
6065
+ }
6066
+ const edgeIdSet = new Set(this.documentData.edges.map((e) => e.id));
6067
+ const matchingEdges = explicitIds.filter((id) => edgeIdSet.has(id));
6068
+ if (matchingEdges.length) {
6069
+ const reordered2 = this.reorderArrayLayer(this.documentData.edges, matchingEdges, direction);
6070
+ if (reordered2) {
6071
+ this.documentData.edges = reordered2;
6072
+ this.render();
6073
+ this.emitChange("edge:order", { direction, edgeIds: matchingEdges });
6074
+ }
6075
+ }
6076
+ return this;
6077
+ }
6078
+ if (!this.selection) return this;
6079
+ if (this.selection.kind === "edge") {
6080
+ const reordered2 = this.reorderArrayLayer(
6081
+ this.documentData.edges,
6082
+ [this.selection.id],
6083
+ direction
6084
+ );
6085
+ if (reordered2) {
6086
+ this.documentData.edges = reordered2;
6087
+ this.render();
6088
+ this.emitChange("edge:order", { direction, edgeIds: [this.selection.id] });
6089
+ }
6090
+ return this;
6091
+ }
6092
+ const ids = this.getSelectedNodeIds();
6093
+ const reordered = this.reorderArrayLayer(this.documentData.nodes, ids, direction);
6094
+ if (reordered) {
6095
+ this.documentData.nodes = reordered;
6096
+ this.render();
6097
+ this.emitChange("node:order", { direction, nodeIds: ids });
6098
+ }
6099
+ return this;
6100
+ }
6101
+ bringToFront(targetId) {
6102
+ return this.reorderLayer("front", targetId);
6103
+ }
6104
+ bringForward(targetId) {
6105
+ return this.reorderLayer("forward", targetId);
6106
+ }
6107
+ sendBackward(targetId) {
6108
+ return this.reorderLayer("backward", targetId);
6109
+ }
6110
+ sendToBack(targetId) {
6111
+ return this.reorderLayer("back", targetId);
6112
+ }
6113
+ alignNodes(alignment = "left", nodeIds) {
6114
+ if (this.readonly || !FLOWCHART_NODE_ALIGNMENTS.includes(alignment)) return this;
6115
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6116
+ const hidden = this.getHiddenNodeIds();
6117
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6118
+ if (nodes.length < 2) return this;
6119
+ const bounds = getBounds(nodes);
6120
+ const centerX = (bounds.left + bounds.right) / 2;
6121
+ const centerY = (bounds.top + bounds.bottom) / 2;
6122
+ const movedIds = [];
6123
+ nodes.forEach((node) => {
6124
+ if (node.locked) return;
6125
+ let nextX = node.x;
6126
+ let nextY = node.y;
6127
+ if (alignment === "left") nextX = formatNumber(bounds.left);
6128
+ else if (alignment === "center") nextX = formatNumber(centerX - node.width / 2);
6129
+ else if (alignment === "right") nextX = formatNumber(bounds.right - node.width);
6130
+ else if (alignment === "top") nextY = formatNumber(bounds.top);
6131
+ else if (alignment === "middle") nextY = formatNumber(centerY - node.height / 2);
6132
+ else if (alignment === "bottom") nextY = formatNumber(bounds.bottom - node.height);
6133
+ if (nextX !== node.x || nextY !== node.y) {
6134
+ node.x = nextX;
6135
+ node.y = nextY;
6136
+ movedIds.push(node.id);
6137
+ }
6138
+ });
6139
+ if (movedIds.length) {
6140
+ this.render();
6141
+ this.emitChange("node:align", { alignment, nodeIds: movedIds });
6142
+ }
6143
+ return this;
6144
+ }
6145
+ distributeNodes(axis = "horizontal", nodeIds) {
6146
+ if (this.readonly || !FLOWCHART_DISTRIBUTE_AXES.includes(axis)) return this;
6147
+ const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6148
+ const hidden = this.getHiddenNodeIds();
6149
+ const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
6150
+ if (nodes.length < 3) return this;
6151
+ const sorted = [...nodes].sort(
6152
+ (a, b) => axis === "horizontal" ? a.x + a.width / 2 - (b.x + b.width / 2) : a.y + a.height / 2 - (b.y + b.height / 2)
6153
+ );
6154
+ const first = sorted[0];
6155
+ const last = sorted[sorted.length - 1];
6156
+ const movedIds = [];
6157
+ if (axis === "horizontal") {
6158
+ const totalSpan = last.x + last.width - first.x;
6159
+ const totalSize = sorted.reduce((sum, node) => sum + node.width, 0);
6160
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6161
+ let cursor = first.x;
6162
+ sorted.forEach((node, index) => {
6163
+ if (index > 0 && index < sorted.length - 1 && !node.locked) {
6164
+ const nextX = formatNumber(cursor);
6165
+ if (nextX !== node.x) {
6166
+ node.x = nextX;
6167
+ movedIds.push(node.id);
6168
+ }
6169
+ }
6170
+ cursor += node.width + gap;
6171
+ });
6172
+ } else {
6173
+ const totalSpan = last.y + last.height - first.y;
6174
+ const totalSize = sorted.reduce((sum, node) => sum + node.height, 0);
6175
+ const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
6176
+ let cursor = first.y;
6177
+ sorted.forEach((node, index) => {
6178
+ if (index > 0 && index < sorted.length - 1 && !node.locked) {
6179
+ const nextY = formatNumber(cursor);
6180
+ if (nextY !== node.y) {
6181
+ node.y = nextY;
6182
+ movedIds.push(node.id);
6183
+ }
6184
+ }
6185
+ cursor += node.height + gap;
6186
+ });
6187
+ }
6188
+ if (movedIds.length) {
6189
+ this.render();
6190
+ this.emitChange("node:distribute", { axis, nodeIds: movedIds });
6191
+ }
6192
+ return this;
6193
+ }
6194
+ setNodeLocked(nodeId, locked = true) {
6195
+ if (this.readonly) return false;
6196
+ let targetIds;
6197
+ let nextLocked = Boolean(locked);
6198
+ if (typeof nodeId === "boolean") {
6199
+ nextLocked = nodeId;
6200
+ targetIds = this.getSelectedNodeIds();
6201
+ } else if (Array.isArray(nodeId)) {
6202
+ targetIds = nodeId.map(sanitizeId).filter(Boolean);
6203
+ } else if (nodeId == null) {
6204
+ targetIds = this.getSelectedNodeIds();
6205
+ } else {
6206
+ targetIds = [sanitizeId(nodeId)];
6207
+ }
6208
+ const changedNodes = [];
6209
+ targetIds.forEach((id) => {
6210
+ const node = this.findNode(id);
6211
+ if (!node || Boolean(node.locked) === nextLocked) return;
6212
+ if (nextLocked) node.locked = true;
6213
+ else delete node.locked;
6214
+ changedNodes.push(deepClone(node));
6215
+ });
6216
+ if (!changedNodes.length) return false;
6217
+ if (nextLocked && this.textEditor && targetIds.includes(this.textEditor.nodeId)) {
6218
+ this.stopTextEdit({ commit: true });
6219
+ }
6220
+ this.render();
6221
+ this.emitChange("node:lock", {
6222
+ node: changedNodes[0],
6223
+ nodes: changedNodes,
6224
+ locked: nextLocked
6225
+ });
6226
+ return true;
6227
+ }
6228
+ toggleNodeLocked(nodeId) {
6229
+ if (this.readonly) return false;
6230
+ if (nodeId != null && typeof nodeId !== "boolean" && !Array.isArray(nodeId)) {
6231
+ const node = this.findNode(sanitizeId(nodeId));
6232
+ return node ? this.setNodeLocked(node.id, !node.locked) : false;
6233
+ }
6234
+ const ids = Array.isArray(nodeId) ? nodeId.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
6235
+ const nodes = ids.map((id) => this.findNode(id)).filter(Boolean);
6236
+ if (!nodes.length) return false;
6237
+ const shouldLock = nodes.some((node) => !node.locked);
6238
+ return this.setNodeLocked(ids, shouldLock);
6239
+ }
6240
+ exportSvg(options = {}) {
6241
+ const padding = Math.max(0, toFiniteNumber(options.padding, 32));
6242
+ const visibleNodes = this.getVisibleNodes();
6243
+ let viewX = 0;
6244
+ let viewY = 0;
6245
+ let viewWidth = 800;
6246
+ let viewHeight = 560;
6247
+ if (visibleNodes.length) {
6248
+ const bounds = getBounds(visibleNodes);
6249
+ viewX = formatNumber(bounds.left - padding);
6250
+ viewY = formatNumber(bounds.top - padding);
6251
+ viewWidth = formatNumber(Math.max(1, bounds.right - bounds.left + padding * 2));
6252
+ viewHeight = formatNumber(Math.max(1, bounds.bottom - bounds.top + padding * 2));
6253
+ }
6254
+ const exportRoot = svgEl("svg", {
6255
+ xmlns: SVG_NS,
6256
+ viewBox: `${viewX} ${viewY} ${viewWidth} ${viewHeight}`,
6257
+ width: viewWidth,
6258
+ height: viewHeight,
6259
+ class: "vd-flowchart-export"
6260
+ });
6261
+ const styleEl = svgEl("style");
6262
+ styleEl.textContent = [
6263
+ '.vd-flowchart-export { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }',
6264
+ ".vd-flowchart-node-shape { fill: #ffffff; stroke: #475569; stroke-width: 2px; }",
6265
+ ".vd-flowchart-node--textbox .vd-flowchart-node-shape { stroke-dasharray: 6 4; }",
6266
+ ".vd-flowchart-node--junction .vd-flowchart-node-shape { fill: #2563eb; stroke: #ffffff; }",
6267
+ ".vd-flowchart-node-text { fill: #0f172a; font-size: 14px; font-weight: 600; dominant-baseline: middle; text-anchor: middle; }",
6268
+ ".vd-flowchart-edge-path { fill: none; stroke: #475569; stroke-linecap: round; stroke-linejoin: round; }",
6269
+ ".vd-flowchart-edge-label { fill: #0f172a; font-size: 12px; font-weight: 600; paint-order: stroke; stroke: #ffffff; stroke-width: 5px; }"
6270
+ ].join("\n");
6271
+ exportRoot.appendChild(styleEl);
6272
+ if (this.markerDefs) {
6273
+ const defsClone = this.markerDefs.cloneNode(true);
6274
+ defsClone.querySelectorAll("path, circle").forEach((shape) => {
6275
+ const fill = shape.getAttribute("fill") || "";
6276
+ const preset = fill.match(/--vd-flowchart-palette-([a-z]+)-edge/);
6277
+ if (preset) {
6278
+ const fallback = FLOWCHART_COLOR_PRESET_FALLBACKS[preset[1]]?.edge;
6279
+ if (fallback) {
6280
+ shape.setAttribute("fill", fallback);
6281
+ return;
6282
+ }
6283
+ }
6284
+ if (fill.includes("var(")) shape.setAttribute("fill", "#475569");
6285
+ });
6286
+ exportRoot.appendChild(defsClone);
6287
+ }
6288
+ if (typeof options.background === "string" && options.background.trim() && options.background.trim() !== "transparent") {
6289
+ const bgColor = options.background.trim() === "theme" ? "#ffffff" : sanitizeCssColor(options.background.trim()) || "#ffffff";
6290
+ exportRoot.appendChild(
6291
+ svgEl("rect", {
6292
+ x: viewX,
6293
+ y: viewY,
6294
+ width: viewWidth,
6295
+ height: viewHeight,
6296
+ fill: bgColor
6297
+ })
6298
+ );
6299
+ }
6300
+ const sceneGroup = svgEl("g", { class: "vd-flowchart-export-scene" });
6301
+ const edgesClone = this.edgesLayer.cloneNode(true);
6302
+ edgesClone.querySelectorAll(".vd-flowchart-edge-hit, .vd-flowchart-edge-selection").forEach((el) => el.remove());
6303
+ edgesClone.querySelectorAll(".vd-flowchart-edge").forEach((edgeGroup) => {
6304
+ edgeGroup.classList.remove("is-selected", "is-reconnecting");
6305
+ const edgeId = edgeGroup.getAttribute("data-edge-id");
6306
+ const edge = this.findEdge(edgeId);
6307
+ const pathEl = edgeGroup.querySelector(".vd-flowchart-edge-path");
6308
+ if (edge && pathEl) {
6309
+ const stroke = edge.color ? FLOWCHART_COLOR_PRESET_FALLBACKS[edge.color]?.edge || edge.color : "#475569";
6310
+ pathEl.setAttribute("stroke", stroke);
6311
+ pathEl.style.stroke = stroke;
6312
+ }
6313
+ });
6314
+ const nodesClone = this.nodesLayer.cloneNode(true);
6315
+ nodesClone.querySelectorAll(
6316
+ ".vd-flowchart-ports, .vd-flowchart-resize-handles, .vd-flowchart-node-lock, .vd-flowchart-collapse-badge, .vd-flowchart-selection-box"
6317
+ ).forEach((el) => el.remove());
6318
+ nodesClone.querySelectorAll(".vd-flowchart-node").forEach((nodeGroup) => {
6319
+ nodeGroup.classList.remove("is-selected", "is-multi-selected", "is-dragging");
6320
+ const nodeId = nodeGroup.getAttribute("data-node-id");
6321
+ const node = this.findNode(nodeId);
6322
+ if (!node) return;
6323
+ const shapeEl = nodeGroup.querySelector(".vd-flowchart-node-shape");
6324
+ const labelEl = nodeGroup.querySelector(".vd-flowchart-node-text");
6325
+ const presetColors = node.color ? FLOWCHART_COLOR_PRESET_FALLBACKS[node.color] : null;
6326
+ if (shapeEl) {
6327
+ const fill = node.fill || presetColors?.fill || (node.type === "junction" ? "#2563eb" : "#ffffff");
6328
+ const stroke = node.stroke || presetColors?.stroke || (node.type === "junction" ? "#ffffff" : "#475569");
6329
+ shapeEl.setAttribute("fill", fill);
6330
+ shapeEl.setAttribute("stroke", stroke);
6331
+ shapeEl.style.fill = fill;
6332
+ shapeEl.style.stroke = stroke;
6333
+ }
6334
+ if (labelEl) {
6335
+ const textColor = node.textColor || presetColors?.text || "#0f172a";
6336
+ labelEl.setAttribute("fill", textColor);
6337
+ labelEl.style.fill = textColor;
6338
+ }
6339
+ });
6340
+ sceneGroup.appendChild(edgesClone);
6341
+ sceneGroup.appendChild(nodesClone);
6342
+ exportRoot.appendChild(sceneGroup);
6343
+ return exportRoot.outerHTML;
6344
+ }
5008
6345
  nodeSizeBounds() {
5009
6346
  return { min: this.minNodeSize, max: this.maxNodeSize };
5010
6347
  }
@@ -5150,8 +6487,12 @@ var VdFlowchart = class {
5150
6487
  this.reconnectEdgeId = null;
5151
6488
  }
5152
6489
  this.readonly = Boolean(options.readonly);
6490
+ if (this.readonly && this.colorPopoverOpen) {
6491
+ this.toggleColorPopover(false);
6492
+ }
5153
6493
  this.root.classList.toggle("vd-flowchart-readonly", this.readonly);
5154
6494
  this.arrangeSelect.disabled = this.readonly;
6495
+ if (this.colorButton) this.colorButton.disabled = this.readonly;
5155
6496
  this.clearButton.disabled = this.readonly;
5156
6497
  this.loadJsonButton.disabled = this.readonly;
5157
6498
  }
@@ -5374,16 +6715,38 @@ var VdFlowchart2 = defineComponent({
5374
6715
  canUndo: () => Boolean(instance?.canUndo()),
5375
6716
  canRedo: () => Boolean(instance?.canRedo()),
5376
6717
  layout: (mode, options) => instance?.layout(mode, options),
5377
- fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding)
6718
+ fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding),
6719
+ setNodeColor: (nodeId, colorOrPatch) => instance?.setNodeColor(nodeId, colorOrPatch) ?? null,
6720
+ setEdgeColor: (edgeId, color) => instance?.setEdgeColor(edgeId, color) ?? null,
6721
+ setSelectionColor: (colorOrPatch) => instance?.setSelectionColor(colorOrPatch),
6722
+ clearSelectionColor: () => instance?.clearSelectionColor(),
6723
+ bringToFront: (targetId) => instance?.bringToFront(targetId),
6724
+ bringForward: (targetId) => instance?.bringForward(targetId),
6725
+ sendBackward: (targetId) => instance?.sendBackward(targetId),
6726
+ sendToBack: (targetId) => instance?.sendToBack(targetId),
6727
+ alignNodes: (alignment, nodeIds) => instance?.alignNodes(alignment, nodeIds),
6728
+ distributeNodes: (axis, nodeIds) => instance?.distributeNodes(axis, nodeIds),
6729
+ setNodeLocked: (nodeId, locked) => Boolean(instance?.setNodeLocked(nodeId, locked)),
6730
+ toggleNodeLocked: (nodeId) => Boolean(instance?.toggleNodeLocked(nodeId)),
6731
+ duplicateSelection: () => instance?.duplicateSelection() ?? null,
6732
+ copySelection: () => Boolean(instance?.copySelection()),
6733
+ pasteClipboard: () => Boolean(instance?.pasteClipboard()),
6734
+ pasteSelection: () => instance?.pasteSelection() ?? null,
6735
+ cutSelection: () => Boolean(instance?.cutSelection()),
6736
+ exportSvg: (options) => instance?.exportSvg(options) ?? ""
5378
6737
  });
5379
6738
  return () => h("div", { ref: el, class: "vd-flowchart" });
5380
6739
  }
5381
6740
  });
5382
6741
  export {
6742
+ FLOWCHART_COLOR_PRESETS,
6743
+ FLOWCHART_DISTRIBUTE_AXES,
5383
6744
  FLOWCHART_DOCUMENT_VERSION,
5384
6745
  FLOWCHART_EDGE_MARKERS,
5385
6746
  FLOWCHART_EDGE_ROUTES,
6747
+ FLOWCHART_EDGE_STROKE_STYLES,
5386
6748
  FLOWCHART_KEYBOARD_SHORTCUTS,
6749
+ FLOWCHART_NODE_ALIGNMENTS,
5387
6750
  FLOWCHART_NODE_TYPES,
5388
6751
  FLOWCHART_PORTS,
5389
6752
  LAYOUT_MODES,