@vanduo-oss/vd3-flowchart 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +16 -170
- package/SKILL.md +57 -15
- package/dist/core.d.ts +89 -2
- package/dist/index.cjs +1167 -52
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1167 -52
- package/dist/index.js.map +3 -3
- package/dist/meta.json +16 -12
- package/dist/vd3-flowchart.css +496 -0
- package/dist/vue.d.ts +33 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,10 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.js
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
FLOWCHART_COLOR_PRESETS: () => FLOWCHART_COLOR_PRESETS,
|
|
24
|
+
FLOWCHART_DISTRIBUTE_AXES: () => FLOWCHART_DISTRIBUTE_AXES,
|
|
23
25
|
FLOWCHART_DOCUMENT_VERSION: () => FLOWCHART_DOCUMENT_VERSION,
|
|
24
26
|
FLOWCHART_EDGE_MARKERS: () => FLOWCHART_EDGE_MARKERS,
|
|
25
27
|
FLOWCHART_EDGE_ROUTES: () => FLOWCHART_EDGE_ROUTES,
|
|
28
|
+
FLOWCHART_EDGE_STROKE_STYLES: () => FLOWCHART_EDGE_STROKE_STYLES,
|
|
26
29
|
FLOWCHART_KEYBOARD_SHORTCUTS: () => FLOWCHART_KEYBOARD_SHORTCUTS,
|
|
30
|
+
FLOWCHART_NODE_ALIGNMENTS: () => FLOWCHART_NODE_ALIGNMENTS,
|
|
27
31
|
FLOWCHART_NODE_TYPES: () => FLOWCHART_NODE_TYPES,
|
|
28
32
|
FLOWCHART_PORTS: () => FLOWCHART_PORTS,
|
|
29
33
|
LAYOUT_MODES: () => LAYOUT_MODES,
|
|
@@ -483,6 +487,11 @@ var TOOLBAR_ICON_PATHS = {
|
|
|
483
487
|
undo: "M224,128a96,96,0,0,1-94.71,96H128A95.38,95.38,0,0,1,62.1,197.8a8,8,0,0,1,11-11.63A80,80,0,1,0,71.43,71.39a3.07,3.07,0,0,1-.26.25L44.59,96H72a8,8,0,0,1,0,16H24a8,8,0,0,1-8-8V56a8,8,0,0,1,16,0V85.8L60.25,60A96,96,0,0,1,224,128Z",
|
|
484
488
|
redo: "M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1,0-16H211.4L184.81,71.64l-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,0,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60L224,85.8V56a8,8,0,1,1,16,0Z",
|
|
485
489
|
minimap: "M228.92,49.69a8,8,0,0,0-6.86-1.45L160.93,63.52,99.58,32.84a8,8,0,0,0-5.52-.6l-64,16A8,8,0,0,0,24,56V200a8,8,0,0,0,9.94,7.76l61.13-15.28,61.35,30.68A8.15,8.15,0,0,0,160,224a8,8,0,0,0,1.94-.24l64-16A8,8,0,0,0,232,200V56A8,8,0,0,0,228.92,49.69ZM104,52.94l48,24V203.06l-48-24ZM40,62.25l48-12v127.5l-48,12Zm176,131.5-48,12V78.25l48-12Z",
|
|
490
|
+
palette: "M200.77,53.89A103.27,103.27,0,0,0,128,24h-1.07A104,104,0,0,0,24,128c0,43,26.58,79.06,69.36,94.17A32,32,0,0,0,136,192a16,16,0,0,1,16-16h46.21a31.81,31.81,0,0,0,31.2-24.88,104.43,104.43,0,0,0,2.59-24A103.28,103.28,0,0,0,200.77,53.89Zm13,93.71A15.89,15.89,0,0,1,198.21,160H152a32,32,0,0,0-32,32,16,16,0,0,1-21.31,15.07C62.49,194.3,40,164,40,128a88,88,0,0,1,87.09-88h.9a88.35,88.35,0,0,1,88,87.25A88.86,88.86,0,0,1,213.81,147.6ZM140,76a12,12,0,1,1-12-12A12,12,0,0,1,140,76ZM96,100A12,12,0,1,1,84,88,12,12,0,0,1,96,100Zm0,56a12,12,0,1,1-12-12A12,12,0,0,1,96,156Zm88-56a12,12,0,1,1-12-12A12,12,0,0,1,184,100Z",
|
|
491
|
+
"bring-to-front": "M216,104H168V56a16,16,0,0,0-16-16H56A16,16,0,0,0,40,56v96a16,16,0,0,0,16,16h48v48a16,16,0,0,0,16,16h96a16,16,0,0,0,16-16V120A16,16,0,0,0,216,104ZM56,152V56h96v48H120a16,16,0,0,0-16,16v32Zm160,64H120V120h96Z",
|
|
492
|
+
"send-to-back": "M216,104H168V56a16,16,0,0,0-16-16H56A16,16,0,0,0,40,56v96a16,16,0,0,0,16,16h48v48a16,16,0,0,0,16,16h96a16,16,0,0,0,16-16V120A16,16,0,0,0,216,104ZM56,56h96v96H56Zm160,160H120V168h32a16,16,0,0,0,16-16V120h48Z",
|
|
493
|
+
lock: "M208,80H176V56a48,48,0,0,0-96,0V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80ZM96,56a32,32,0,0,1,64,0V80H96ZM208,208H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z",
|
|
494
|
+
unlock: "M208,80H96V56a32,32,0,0,1,32-32c15.37,0,29.2,11,32.16,25.59a8,8,0,0,0,15.68-3.18C171.32,24.15,151.32,8,128,8A48.05,48.05,0,0,0,80,56V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm0,128H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z",
|
|
486
495
|
clear: "M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM96,40a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96Zm96,168H64V64H192ZM112,104v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Zm48,0v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Z"
|
|
487
496
|
};
|
|
488
497
|
var TOOLBAR_ACTIONS = [
|
|
@@ -559,7 +568,7 @@ var EDGE_STROKE_PRESETS = [
|
|
|
559
568
|
{ id: "medium", label: "Medium", width: DEFAULT_EDGE_STROKE_WIDTH },
|
|
560
569
|
{ id: "bold", label: "Bold", width: 3.5 }
|
|
561
570
|
];
|
|
562
|
-
var VD_FLOWCHART_VERSION = "1.
|
|
571
|
+
var VD_FLOWCHART_VERSION = "1.6.0";
|
|
563
572
|
var FLOWCHART_DOCUMENT_VERSION = "1.3.0";
|
|
564
573
|
var FLOWCHART_NODE_TYPES = [
|
|
565
574
|
"rounded-rect",
|
|
@@ -573,10 +582,92 @@ var FLOWCHART_NODE_TYPES = [
|
|
|
573
582
|
var FLOWCHART_PORTS = ["top", "right", "bottom", "left"];
|
|
574
583
|
var FLOWCHART_EDGE_MARKERS = ["none", "arrow", "dot"];
|
|
575
584
|
var FLOWCHART_EDGE_ROUTES = ["curve", "straight", "orthogonal"];
|
|
585
|
+
var FLOWCHART_EDGE_STROKE_STYLES = ["solid", "dashed", "dotted", "animated"];
|
|
586
|
+
var FLOWCHART_COLOR_PRESETS = [
|
|
587
|
+
"default",
|
|
588
|
+
"primary",
|
|
589
|
+
"secondary",
|
|
590
|
+
"success",
|
|
591
|
+
"warning",
|
|
592
|
+
"danger",
|
|
593
|
+
"info",
|
|
594
|
+
"violet",
|
|
595
|
+
"teal",
|
|
596
|
+
"orange",
|
|
597
|
+
"pink",
|
|
598
|
+
"neutral"
|
|
599
|
+
];
|
|
600
|
+
var FLOWCHART_NODE_ALIGNMENTS = ["left", "center", "right", "top", "middle", "bottom"];
|
|
601
|
+
var FLOWCHART_DISTRIBUTE_AXES = ["horizontal", "vertical"];
|
|
576
602
|
var FLOWCHART_KEYBOARD_SHORTCUTS = ["mindmap", "basic"];
|
|
603
|
+
var FLOWCHART_COLOR_PRESET_LABELS = {
|
|
604
|
+
default: "Default",
|
|
605
|
+
primary: "Primary",
|
|
606
|
+
secondary: "Secondary",
|
|
607
|
+
success: "Success",
|
|
608
|
+
warning: "Warning",
|
|
609
|
+
danger: "Danger",
|
|
610
|
+
info: "Info",
|
|
611
|
+
violet: "Violet",
|
|
612
|
+
teal: "Teal",
|
|
613
|
+
orange: "Orange",
|
|
614
|
+
pink: "Pink",
|
|
615
|
+
neutral: "Neutral"
|
|
616
|
+
};
|
|
617
|
+
var FLOWCHART_COLOR_PRESET_SET = new Set(FLOWCHART_COLOR_PRESETS);
|
|
618
|
+
var FLOWCHART_COLOR_PRESET_FALLBACKS = {
|
|
619
|
+
primary: { fill: "#dbeafe", stroke: "#2563eb", text: "#1e3a8a", edge: "#2563eb" },
|
|
620
|
+
secondary: { fill: "#e0e7ff", stroke: "#4f46e5", text: "#312e81", edge: "#4f46e5" },
|
|
621
|
+
success: { fill: "#dcfce7", stroke: "#16a34a", text: "#14532d", edge: "#16a34a" },
|
|
622
|
+
warning: { fill: "#fef3c7", stroke: "#d97706", text: "#78350f", edge: "#d97706" },
|
|
623
|
+
danger: { fill: "#fee2e2", stroke: "#dc2626", text: "#7f1d1d", edge: "#dc2626" },
|
|
624
|
+
info: { fill: "#e0f2fe", stroke: "#0284c7", text: "#0c4a6e", edge: "#0284c7" },
|
|
625
|
+
violet: { fill: "#f3e8ff", stroke: "#9333ea", text: "#581c87", edge: "#9333ea" },
|
|
626
|
+
teal: { fill: "#ccfbf1", stroke: "#0d9488", text: "#134e4a", edge: "#0d9488" },
|
|
627
|
+
orange: { fill: "#ffedd5", stroke: "#ea580c", text: "#7c2d12", edge: "#ea580c" },
|
|
628
|
+
pink: { fill: "#fce7f3", stroke: "#db2777", text: "#831843", edge: "#db2777" },
|
|
629
|
+
neutral: { fill: "#f1f5f9", stroke: "#64748b", text: "#1e293b", edge: "#64748b" }
|
|
630
|
+
};
|
|
631
|
+
var FLOWCHART_EDGE_STROKE_STYLE_LABELS = {
|
|
632
|
+
solid: "Solid",
|
|
633
|
+
dashed: "Dashed",
|
|
634
|
+
dotted: "Dotted",
|
|
635
|
+
animated: "Animated flow"
|
|
636
|
+
};
|
|
577
637
|
function normalizeKeyboardShortcuts(value) {
|
|
578
638
|
return value === "basic" ? "basic" : "mindmap";
|
|
579
639
|
}
|
|
640
|
+
function normalizeColorPreset(value) {
|
|
641
|
+
if (typeof value !== "string") return "";
|
|
642
|
+
const trimmed = value.trim().toLowerCase();
|
|
643
|
+
return FLOWCHART_COLOR_PRESETS.includes(trimmed) && trimmed !== "default" ? trimmed : "";
|
|
644
|
+
}
|
|
645
|
+
function sanitizeCssColor(value) {
|
|
646
|
+
if (typeof value !== "string") return "";
|
|
647
|
+
const trimmed = value.trim();
|
|
648
|
+
if (!trimmed || trimmed === "default") return "";
|
|
649
|
+
if (trimmed.length > 64 || /\\/.test(trimmed)) return "";
|
|
650
|
+
if (/[;{}<>"'`]/.test(trimmed) || /url\s*\(|expression\s*\(|javascript\s*:/i.test(trimmed)) {
|
|
651
|
+
return "";
|
|
652
|
+
}
|
|
653
|
+
if (!/^[#a-z0-9(),.%\s/+-]+$/i.test(trimmed)) return "";
|
|
654
|
+
return trimmed;
|
|
655
|
+
}
|
|
656
|
+
function normalizeEdgeColor(value) {
|
|
657
|
+
const preset = normalizeColorPreset(value);
|
|
658
|
+
if (preset) return preset;
|
|
659
|
+
return sanitizeCssColor(value);
|
|
660
|
+
}
|
|
661
|
+
function normalizeEdgeStrokeStyle(value) {
|
|
662
|
+
return FLOWCHART_EDGE_STROKE_STYLES.includes(value) && value !== "solid" ? value : "solid";
|
|
663
|
+
}
|
|
664
|
+
function resolveEdgeColorValue(color) {
|
|
665
|
+
if (!color || color === "default") return "var(--vd-flowchart-accent)";
|
|
666
|
+
if (FLOWCHART_COLOR_PRESETS.includes(color)) {
|
|
667
|
+
return `var(--vd-flowchart-palette-${color}-edge)`;
|
|
668
|
+
}
|
|
669
|
+
return color;
|
|
670
|
+
}
|
|
580
671
|
var ARROW_DIRECTIONS = {
|
|
581
672
|
ArrowRight: "right",
|
|
582
673
|
ArrowLeft: "left",
|
|
@@ -617,6 +708,8 @@ function getShortcutRows(mode, readonly) {
|
|
|
617
708
|
"Edit the connection label"
|
|
618
709
|
],
|
|
619
710
|
["Cmd/Ctrl + /", "Collapse or expand the branch"],
|
|
711
|
+
["Cmd/Ctrl + ] or [", "Bring forward or send backward (Shift: front/back)"],
|
|
712
|
+
["Cmd/Ctrl + L", "Lock or unlock the selected node"],
|
|
620
713
|
["Alt + Arrow", "Nudge the node (add Shift for 1 px)"],
|
|
621
714
|
["Delete or Backspace", "Delete the selection"],
|
|
622
715
|
["Cmd/Ctrl + D", "Duplicate the node"],
|
|
@@ -801,10 +894,12 @@ function clampNodeHeight(type, height, fallback, sizeBounds) {
|
|
|
801
894
|
return clamp(toFiniteNumber(height, fallback), bounds.minHeight, bounds.maxHeight);
|
|
802
895
|
}
|
|
803
896
|
function isNodeResizable(nodeOrType) {
|
|
897
|
+
if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
|
|
804
898
|
const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
|
|
805
899
|
return spec.resizable !== false;
|
|
806
900
|
}
|
|
807
901
|
function isNodeTextEditable(nodeOrType) {
|
|
902
|
+
if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
|
|
808
903
|
const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
|
|
809
904
|
return spec.textEditable !== false;
|
|
810
905
|
}
|
|
@@ -844,6 +939,15 @@ function normalizeNode(rawNode, index, usedIds, sizeBounds) {
|
|
|
844
939
|
data: isPlainObject(rawNode?.data) ? deepClone(rawNode.data) : {}
|
|
845
940
|
};
|
|
846
941
|
if (rawNode?.collapsed === true) node.collapsed = true;
|
|
942
|
+
const color = normalizeColorPreset(rawNode?.color ?? rawNode?.data?.color);
|
|
943
|
+
if (color) node.color = color;
|
|
944
|
+
const fill = sanitizeCssColor(rawNode?.fill ?? rawNode?.data?.fill);
|
|
945
|
+
if (fill) node.fill = fill;
|
|
946
|
+
const stroke = sanitizeCssColor(rawNode?.stroke ?? rawNode?.data?.stroke);
|
|
947
|
+
if (stroke) node.stroke = stroke;
|
|
948
|
+
const textColor = sanitizeCssColor(rawNode?.textColor ?? rawNode?.data?.textColor);
|
|
949
|
+
if (textColor) node.textColor = textColor;
|
|
950
|
+
if (rawNode?.locked === true || rawNode?.data?.locked === true) node.locked = true;
|
|
847
951
|
return node;
|
|
848
952
|
}
|
|
849
953
|
function computeHiddenNodeIds(nodes, edges) {
|
|
@@ -876,6 +980,12 @@ function computeHiddenNodeIds(nodes, edges) {
|
|
|
876
980
|
return candidates;
|
|
877
981
|
}
|
|
878
982
|
function normalizeEndpoint(rawEndpoint, fallbackPort) {
|
|
983
|
+
if (typeof rawEndpoint === "string") {
|
|
984
|
+
return {
|
|
985
|
+
nodeId: sanitizeId(rawEndpoint),
|
|
986
|
+
port: fallbackPort
|
|
987
|
+
};
|
|
988
|
+
}
|
|
879
989
|
return {
|
|
880
990
|
nodeId: sanitizeId(rawEndpoint?.nodeId),
|
|
881
991
|
port: FLOWCHART_PORTS.includes(rawEndpoint?.port) ? rawEndpoint.port : fallbackPort
|
|
@@ -911,6 +1021,10 @@ function normalizeEdge(rawEdge, index, nodeIds, usedIds) {
|
|
|
911
1021
|
label: rawEdge?.label == null ? "" : String(rawEdge.label),
|
|
912
1022
|
data: isPlainObject(rawEdge?.data) ? deepClone(rawEdge.data) : {}
|
|
913
1023
|
};
|
|
1024
|
+
const color = normalizeEdgeColor(rawEdge?.color ?? rawEdge?.data?.color);
|
|
1025
|
+
if (color) edge.color = color;
|
|
1026
|
+
const strokeStyle = normalizeEdgeStrokeStyle(rawEdge?.strokeStyle ?? rawEdge?.data?.strokeStyle);
|
|
1027
|
+
if (strokeStyle !== "solid") edge.strokeStyle = strokeStyle;
|
|
914
1028
|
syncEdgeKind(edge);
|
|
915
1029
|
return edge;
|
|
916
1030
|
}
|
|
@@ -1357,19 +1471,75 @@ function buildOrthogonalPath(fromPoint, toPoint, fromPort = "right", toPort = "l
|
|
|
1357
1471
|
labelY: label.y
|
|
1358
1472
|
};
|
|
1359
1473
|
}
|
|
1474
|
+
function getPortOuterOffset(node, port) {
|
|
1475
|
+
if (!node || node.type === "label") return 0;
|
|
1476
|
+
const visual = nodeVisualScale(node);
|
|
1477
|
+
const baseStroke = node.type === "junction" ? 1.25 : 1.5;
|
|
1478
|
+
const halfStroke = Math.max(0.015, baseStroke * visual / 2);
|
|
1479
|
+
if (node.type === "diamond") {
|
|
1480
|
+
const w = Math.max(1, toFiniteNumber(node.width, 184));
|
|
1481
|
+
const h2 = Math.max(1, toFiniteNumber(node.height, 120));
|
|
1482
|
+
const diag = Math.hypot(w, h2);
|
|
1483
|
+
const miterFactor = isHorizontalPort(port) ? Math.min(4, diag / h2) : Math.min(4, diag / w);
|
|
1484
|
+
return halfStroke * miterFactor;
|
|
1485
|
+
}
|
|
1486
|
+
return halfStroke;
|
|
1487
|
+
}
|
|
1488
|
+
function getMarkerEndpointRetraction(markerType, strokeWidth, edgeScale = 1) {
|
|
1489
|
+
if (!markerType || markerType === "none") return 0;
|
|
1490
|
+
const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
|
|
1491
|
+
const effective = Math.max(0.02, normalizeEdgeStrokeWidth(strokeWidth) * scale);
|
|
1492
|
+
if (markerType === "dot") {
|
|
1493
|
+
return formatNumber(Math.max(2.75 * scale, effective * 1.45));
|
|
1494
|
+
}
|
|
1495
|
+
return formatNumber(Math.max(1.5 * scale, effective * 0.85));
|
|
1496
|
+
}
|
|
1360
1497
|
function buildEdgePath(edge, fromNode = null, toNode = null) {
|
|
1361
1498
|
const fromPort = edge?.from?.port || edge?.fromPort || "right";
|
|
1362
1499
|
const toPort = edge?.to?.port || edge?.toPort || "left";
|
|
1363
|
-
const
|
|
1364
|
-
const
|
|
1500
|
+
const rawFromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
|
|
1501
|
+
const rawToPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
|
|
1365
1502
|
const route = normalizeEdgeRoute(edge?.route);
|
|
1366
|
-
const
|
|
1367
|
-
|
|
1503
|
+
const visualScale = edgeVisualScale(fromNode, toNode);
|
|
1504
|
+
const metrics = routeMetrics(visualScale);
|
|
1505
|
+
if (!rawFromPoint || !rawToPoint) {
|
|
1368
1506
|
return { d: "", labelX: 0, labelY: 0 };
|
|
1369
1507
|
}
|
|
1508
|
+
const strokeWidth = normalizeEdgeStrokeWidth(edge?.strokeWidth);
|
|
1509
|
+
const startMarker = edge?.startMarker || "none";
|
|
1510
|
+
const endMarker = edge?.endMarker || "none";
|
|
1511
|
+
const rawDistance = Math.hypot(rawToPoint.x - rawFromPoint.x, rawToPoint.y - rawFromPoint.y);
|
|
1512
|
+
const maxRetract = rawDistance > 0 ? rawDistance * 0.45 : 0;
|
|
1513
|
+
const fromMarkerRetract = !edge?.fromPoint && fromNode && startMarker !== "none" ? getMarkerEndpointRetraction(startMarker, strokeWidth, visualScale) : 0;
|
|
1514
|
+
const fromBorderRetract = fromMarkerRetract > 0 ? getPortOuterOffset(fromNode, fromPort) : 0;
|
|
1515
|
+
const toMarkerRetract = !edge?.toPoint && toNode && endMarker !== "none" ? getMarkerEndpointRetraction(endMarker, strokeWidth, visualScale) : 0;
|
|
1516
|
+
const toBorderRetract = toMarkerRetract > 0 ? getPortOuterOffset(toNode, toPort) : 0;
|
|
1517
|
+
const fromRetract = Math.min(maxRetract, fromMarkerRetract + fromBorderRetract);
|
|
1518
|
+
const toRetract = Math.min(maxRetract, toMarkerRetract + toBorderRetract);
|
|
1370
1519
|
if (route === "straight") {
|
|
1371
|
-
|
|
1520
|
+
const borderFrom = fromBorderRetract > 0 ? offsetPoint(
|
|
1521
|
+
rawFromPoint,
|
|
1522
|
+
getPortNormal(fromPort),
|
|
1523
|
+
Math.min(maxRetract, fromBorderRetract)
|
|
1524
|
+
) : rawFromPoint;
|
|
1525
|
+
const borderTo = toBorderRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), Math.min(maxRetract, toBorderRetract)) : rawToPoint;
|
|
1526
|
+
const dx = borderTo.x - borderFrom.x;
|
|
1527
|
+
const dy = borderTo.y - borderFrom.y;
|
|
1528
|
+
const dist = Math.hypot(dx, dy);
|
|
1529
|
+
if (dist > 0.01) {
|
|
1530
|
+
const ux = dx / dist;
|
|
1531
|
+
const uy = dy / dist;
|
|
1532
|
+
const sRetract = Math.min(dist * 0.45, fromMarkerRetract);
|
|
1533
|
+
const eRetract = Math.min(dist * 0.45, toMarkerRetract);
|
|
1534
|
+
return buildStraightPath(
|
|
1535
|
+
{ x: borderFrom.x + ux * sRetract, y: borderFrom.y + uy * sRetract },
|
|
1536
|
+
{ x: borderTo.x - ux * eRetract, y: borderTo.y - uy * eRetract }
|
|
1537
|
+
);
|
|
1538
|
+
}
|
|
1539
|
+
return buildStraightPath(rawFromPoint, rawToPoint);
|
|
1372
1540
|
}
|
|
1541
|
+
const fromPoint = fromRetract > 0 ? offsetPoint(rawFromPoint, getPortNormal(fromPort), fromRetract) : rawFromPoint;
|
|
1542
|
+
const toPoint = toRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), toRetract) : rawToPoint;
|
|
1373
1543
|
if (route === "orthogonal") {
|
|
1374
1544
|
const fromRect = !edge?.fromPoint && fromNode ? getNodeRectBounds(fromNode, metrics.clearance) : null;
|
|
1375
1545
|
const toRect = !edge?.toPoint && toNode ? getNodeRectBounds(toNode, metrics.clearance) : null;
|
|
@@ -1377,7 +1547,7 @@ function buildEdgePath(edge, fromNode = null, toNode = null) {
|
|
|
1377
1547
|
}
|
|
1378
1548
|
return buildCurvePath(fromPoint, toPoint, fromPort, toPort, metrics);
|
|
1379
1549
|
}
|
|
1380
|
-
function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
|
|
1550
|
+
function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
|
|
1381
1551
|
const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
|
|
1382
1552
|
const effective = Math.max(0.02, strokeWidth * scale);
|
|
1383
1553
|
const size = formatNumber(Math.max(9 * scale, effective * 4.4));
|
|
@@ -1394,12 +1564,12 @@ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
|
|
|
1394
1564
|
marker.appendChild(
|
|
1395
1565
|
svgEl("path", {
|
|
1396
1566
|
d: reversed ? `M ${formatNumber(size)} 0 L 0 ${formatNumber(size / 2)} L ${formatNumber(size)} ${formatNumber(size)} z` : `M 0 0 L ${formatNumber(size)} ${formatNumber(size / 2)} L 0 ${formatNumber(size)} z`,
|
|
1397
|
-
fill
|
|
1567
|
+
fill
|
|
1398
1568
|
})
|
|
1399
1569
|
);
|
|
1400
1570
|
return marker;
|
|
1401
1571
|
}
|
|
1402
|
-
function createDotMarker(id, strokeWidth, edgeScale = 1) {
|
|
1572
|
+
function createDotMarker(id, strokeWidth, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
|
|
1403
1573
|
const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
|
|
1404
1574
|
const effective = Math.max(0.02, strokeWidth * scale);
|
|
1405
1575
|
const size = formatNumber(Math.max(8 * scale, effective * 3.3));
|
|
@@ -1418,7 +1588,7 @@ function createDotMarker(id, strokeWidth, edgeScale = 1) {
|
|
|
1418
1588
|
cx: formatNumber(size / 2),
|
|
1419
1589
|
cy: formatNumber(size / 2),
|
|
1420
1590
|
r: radius,
|
|
1421
|
-
fill
|
|
1591
|
+
fill
|
|
1422
1592
|
})
|
|
1423
1593
|
);
|
|
1424
1594
|
return marker;
|
|
@@ -1707,6 +1877,7 @@ var VdFlowchart = class {
|
|
|
1707
1877
|
this.minimapFrame = 0;
|
|
1708
1878
|
this.minimapDrag = null;
|
|
1709
1879
|
this.shortcutsHelpOpen = false;
|
|
1880
|
+
this.colorPopoverOpen = false;
|
|
1710
1881
|
this.autoFit = Boolean(options.autoFit);
|
|
1711
1882
|
this.readyEmitted = false;
|
|
1712
1883
|
this.resizeObserver = null;
|
|
@@ -1723,8 +1894,10 @@ var VdFlowchart = class {
|
|
|
1723
1894
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
1724
1895
|
this.handleSelectionFieldInput = this.handleSelectionFieldInput.bind(this);
|
|
1725
1896
|
this.handleSelectionFieldChange = this.handleSelectionFieldChange.bind(this);
|
|
1897
|
+
this.handleSelectionActionClick = this.handleSelectionActionClick.bind(this);
|
|
1726
1898
|
this.handleJsonActionClick = this.handleJsonActionClick.bind(this);
|
|
1727
1899
|
this.handleResize = this.handleResize.bind(this);
|
|
1900
|
+
this.handleOutsidePointerDown = this.handleOutsidePointerDown.bind(this);
|
|
1728
1901
|
this.buildShell();
|
|
1729
1902
|
this.bindEvents();
|
|
1730
1903
|
this.render();
|
|
@@ -1808,6 +1981,32 @@ var VdFlowchart = class {
|
|
|
1808
1981
|
this.arrangeSelect.appendChild(option);
|
|
1809
1982
|
});
|
|
1810
1983
|
this.arrangeSelect.value = this.layoutMode;
|
|
1984
|
+
this.colorPopoverWrap = createElement("div", { className: "vd-flowchart-color-popover-wrap" });
|
|
1985
|
+
this.colorButton = createToolbarButton({
|
|
1986
|
+
action: "color-popover",
|
|
1987
|
+
label: "Color selection",
|
|
1988
|
+
icon: "palette",
|
|
1989
|
+
disabled: this.readonly
|
|
1990
|
+
});
|
|
1991
|
+
this.colorButton.setAttribute("aria-expanded", "false");
|
|
1992
|
+
this.colorPopover = createElement("div", { className: "vd-flowchart-color-popover" });
|
|
1993
|
+
this.colorPopover.hidden = true;
|
|
1994
|
+
this.colorPopover.setAttribute("role", "dialog");
|
|
1995
|
+
this.colorPopover.setAttribute("aria-label", "Color presets");
|
|
1996
|
+
const popoverSwatches = createElement("div", { className: "vd-flowchart-swatch-grid" });
|
|
1997
|
+
FLOWCHART_COLOR_PRESETS.forEach((preset) => {
|
|
1998
|
+
const swatch = createElement("button", {
|
|
1999
|
+
className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}`,
|
|
2000
|
+
title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset
|
|
2001
|
+
});
|
|
2002
|
+
swatch.setAttribute("type", "button");
|
|
2003
|
+
swatch.setAttribute("data-flowchart-color", preset);
|
|
2004
|
+
swatch.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
|
|
2005
|
+
popoverSwatches.appendChild(swatch);
|
|
2006
|
+
});
|
|
2007
|
+
this.colorPopover.appendChild(popoverSwatches);
|
|
2008
|
+
this.colorPopoverWrap.appendChild(this.colorButton);
|
|
2009
|
+
this.colorPopoverWrap.appendChild(this.colorPopover);
|
|
1811
2010
|
this.clearButton = createToolbarButton({
|
|
1812
2011
|
action: "clear",
|
|
1813
2012
|
label: "Clear canvas",
|
|
@@ -1834,6 +2033,7 @@ var VdFlowchart = class {
|
|
|
1834
2033
|
});
|
|
1835
2034
|
this.minimapButton.setAttribute("aria-pressed", this.minimapEnabled ? "true" : "false");
|
|
1836
2035
|
toolbarLeft.appendChild(this.arrangeSelect);
|
|
2036
|
+
toolbarLeft.appendChild(this.colorPopoverWrap);
|
|
1837
2037
|
toolbarLeft.appendChild(this.clearButton);
|
|
1838
2038
|
toolbarRight.appendChild(this.minimapButton);
|
|
1839
2039
|
toolbarRight.appendChild(this.shortcutsButton);
|
|
@@ -2124,6 +2324,7 @@ var VdFlowchart = class {
|
|
|
2124
2324
|
this.deleteButton.addEventListener("click", () => this.deleteSelection());
|
|
2125
2325
|
this.selectionFields.addEventListener("input", this.handleSelectionFieldInput);
|
|
2126
2326
|
this.selectionFields.addEventListener("change", this.handleSelectionFieldChange);
|
|
2327
|
+
this.selectionFields.addEventListener("click", this.handleSelectionActionClick);
|
|
2127
2328
|
this.jsonActions.addEventListener("click", this.handleJsonActionClick);
|
|
2128
2329
|
this.canvasEl.addEventListener("pointerdown", this.handlePointerDown);
|
|
2129
2330
|
this.canvasEl.addEventListener("pointermove", this.handlePointerMove);
|
|
@@ -2135,6 +2336,7 @@ var VdFlowchart = class {
|
|
|
2135
2336
|
this.canvasEl.addEventListener("blur", this.handleCanvasBlur);
|
|
2136
2337
|
this.root.addEventListener("keydown", this.handleKeyDown, true);
|
|
2137
2338
|
window.addEventListener("pointerup", this.handlePointerUp);
|
|
2339
|
+
window.addEventListener("pointerdown", this.handleOutsidePointerDown);
|
|
2138
2340
|
window.addEventListener("resize", this.handleResize);
|
|
2139
2341
|
}
|
|
2140
2342
|
unbindEvents() {
|
|
@@ -2143,6 +2345,7 @@ var VdFlowchart = class {
|
|
|
2143
2345
|
this.paletteGrid.removeEventListener("click", this.handlePaletteClick);
|
|
2144
2346
|
this.selectionFields.removeEventListener("input", this.handleSelectionFieldInput);
|
|
2145
2347
|
this.selectionFields.removeEventListener("change", this.handleSelectionFieldChange);
|
|
2348
|
+
this.selectionFields.removeEventListener("click", this.handleSelectionActionClick);
|
|
2146
2349
|
this.jsonActions.removeEventListener("click", this.handleJsonActionClick);
|
|
2147
2350
|
this.canvasEl.removeEventListener("pointerdown", this.handlePointerDown);
|
|
2148
2351
|
this.canvasEl.removeEventListener("pointermove", this.handlePointerMove);
|
|
@@ -2154,8 +2357,14 @@ var VdFlowchart = class {
|
|
|
2154
2357
|
this.canvasEl.removeEventListener("blur", this.handleCanvasBlur);
|
|
2155
2358
|
this.root.removeEventListener("keydown", this.handleKeyDown, true);
|
|
2156
2359
|
window.removeEventListener("pointerup", this.handlePointerUp);
|
|
2360
|
+
window.removeEventListener("pointerdown", this.handleOutsidePointerDown);
|
|
2157
2361
|
window.removeEventListener("resize", this.handleResize);
|
|
2158
2362
|
}
|
|
2363
|
+
handleOutsidePointerDown(event) {
|
|
2364
|
+
if (!this.colorPopoverOpen || this.destroyed) return;
|
|
2365
|
+
if (event.target?.closest?.(".vd-flowchart-color-popover-wrap")) return;
|
|
2366
|
+
this.toggleColorPopover(false);
|
|
2367
|
+
}
|
|
2159
2368
|
handleResize() {
|
|
2160
2369
|
if (this.destroyed) return;
|
|
2161
2370
|
this.render({ inspector: false, json: false });
|
|
@@ -2194,7 +2403,24 @@ var VdFlowchart = class {
|
|
|
2194
2403
|
this.updatePaletteState();
|
|
2195
2404
|
this.render({ scene: true, inspector: false, json: false });
|
|
2196
2405
|
}
|
|
2406
|
+
toggleColorPopover(force) {
|
|
2407
|
+
if (!this.colorPopover || !this.colorButton) return this;
|
|
2408
|
+
const open = typeof force === "boolean" ? force : !this.colorPopoverOpen;
|
|
2409
|
+
this.colorPopoverOpen = open && !this.readonly;
|
|
2410
|
+
this.colorPopover.hidden = !this.colorPopoverOpen;
|
|
2411
|
+
this.colorButton.setAttribute("aria-expanded", this.colorPopoverOpen ? "true" : "false");
|
|
2412
|
+
return this;
|
|
2413
|
+
}
|
|
2197
2414
|
handleToolbarClick(event) {
|
|
2415
|
+
const colorSwatch = event.target.closest("[data-flowchart-color]");
|
|
2416
|
+
if (colorSwatch) {
|
|
2417
|
+
if (!this.readonly) {
|
|
2418
|
+
const preset = colorSwatch.getAttribute("data-flowchart-color");
|
|
2419
|
+
this.setSelectionColor(preset);
|
|
2420
|
+
}
|
|
2421
|
+
this.toggleColorPopover(false);
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2198
2424
|
const actionButton = event.target.closest("[data-flowchart-action]");
|
|
2199
2425
|
if (!actionButton) return;
|
|
2200
2426
|
const action = actionButton.getAttribute("data-flowchart-action");
|
|
@@ -2204,6 +2430,7 @@ var VdFlowchart = class {
|
|
|
2204
2430
|
if (action === "fit-view") this.fitView();
|
|
2205
2431
|
if (action === "undo") this.undo();
|
|
2206
2432
|
if (action === "redo") this.redo();
|
|
2433
|
+
if (action === "color-popover") this.toggleColorPopover();
|
|
2207
2434
|
if (action === "clear" && !this.readonly) this.clear();
|
|
2208
2435
|
if (action === "shortcuts") this.toggleShortcutsHelp();
|
|
2209
2436
|
if (action === "minimap") this.setMinimapEnabled(!this.minimapEnabled);
|
|
@@ -2266,16 +2493,18 @@ var VdFlowchart = class {
|
|
|
2266
2493
|
nodes.forEach((node) => {
|
|
2267
2494
|
const point = map(node.x, node.y);
|
|
2268
2495
|
const selected = this.isNodeSelected(node.id);
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
);
|
|
2496
|
+
const rectEl = svgEl("rect", {
|
|
2497
|
+
class: `vd-flowchart-minimap-node${selected ? " is-selected" : ""}`,
|
|
2498
|
+
x: point.x,
|
|
2499
|
+
y: point.y,
|
|
2500
|
+
width: formatNumber(Math.max(1.5, node.width * transform.scale)),
|
|
2501
|
+
height: formatNumber(Math.max(1.5, node.height * transform.scale)),
|
|
2502
|
+
rx: 1.5
|
|
2503
|
+
});
|
|
2504
|
+
if (node.color) rectEl.setAttribute("data-color", node.color);
|
|
2505
|
+
if (node.fill) rectEl.style.fill = node.fill;
|
|
2506
|
+
if (node.stroke) rectEl.style.stroke = node.stroke;
|
|
2507
|
+
this.minimapSvg.appendChild(rectEl);
|
|
2279
2508
|
});
|
|
2280
2509
|
const corner = map(view.left, view.top);
|
|
2281
2510
|
this.minimapSvg.appendChild(
|
|
@@ -2397,6 +2626,42 @@ var VdFlowchart = class {
|
|
|
2397
2626
|
}
|
|
2398
2627
|
}
|
|
2399
2628
|
}
|
|
2629
|
+
handleSelectionActionClick(event) {
|
|
2630
|
+
if (this.readonly) return;
|
|
2631
|
+
const swatch = event.target.closest("[data-color-preset]");
|
|
2632
|
+
if (swatch) {
|
|
2633
|
+
this.setSelectionColor(swatch.getAttribute("data-color-preset"));
|
|
2634
|
+
return;
|
|
2635
|
+
}
|
|
2636
|
+
const resetBtn = event.target.closest("[data-color-reset]");
|
|
2637
|
+
if (resetBtn) {
|
|
2638
|
+
this.clearSelectionColor();
|
|
2639
|
+
return;
|
|
2640
|
+
}
|
|
2641
|
+
const arrangeBtn = event.target.closest("[data-arrange-action]");
|
|
2642
|
+
if (arrangeBtn) {
|
|
2643
|
+
const action = arrangeBtn.getAttribute("data-arrange-action");
|
|
2644
|
+
if (action === "bring-to-front") this.bringToFront();
|
|
2645
|
+
else if (action === "bring-forward") this.bringForward();
|
|
2646
|
+
else if (action === "send-backward") this.sendBackward();
|
|
2647
|
+
else if (action === "send-to-back") this.sendToBack();
|
|
2648
|
+
return;
|
|
2649
|
+
}
|
|
2650
|
+
const alignBtn = event.target.closest("[data-align-action]");
|
|
2651
|
+
if (alignBtn) {
|
|
2652
|
+
this.alignNodes(alignBtn.getAttribute("data-align-action"));
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
const distributeBtn = event.target.closest("[data-distribute-action]");
|
|
2656
|
+
if (distributeBtn) {
|
|
2657
|
+
this.distributeNodes(distributeBtn.getAttribute("data-distribute-action"));
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
const lockBtn = event.target.closest("[data-lock-toggle]");
|
|
2661
|
+
if (lockBtn) {
|
|
2662
|
+
this.toggleNodeLocked();
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2400
2665
|
handleSelectionFieldInput(event) {
|
|
2401
2666
|
const field = event.target.getAttribute("data-field");
|
|
2402
2667
|
if (!field) return;
|
|
@@ -2419,6 +2684,38 @@ var VdFlowchart = class {
|
|
|
2419
2684
|
if (field === "node-width" || field === "node-height") {
|
|
2420
2685
|
const patch = field === "node-width" ? { width: toFiniteNumber(event.target.value, void 0) } : { height: toFiniteNumber(event.target.value, void 0) };
|
|
2421
2686
|
this.updateNode(this.selection?.id, patch, { inspector: false, reason: "node:update" });
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2689
|
+
if (field === "node-fill") {
|
|
2690
|
+
this.updateNode(
|
|
2691
|
+
this.selection?.id,
|
|
2692
|
+
{ fill: event.target.value },
|
|
2693
|
+
{ inspector: false, reason: "node:update" }
|
|
2694
|
+
);
|
|
2695
|
+
return;
|
|
2696
|
+
}
|
|
2697
|
+
if (field === "node-stroke") {
|
|
2698
|
+
this.updateNode(
|
|
2699
|
+
this.selection?.id,
|
|
2700
|
+
{ stroke: event.target.value },
|
|
2701
|
+
{ inspector: false, reason: "node:update" }
|
|
2702
|
+
);
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
if (field === "node-text-color") {
|
|
2706
|
+
this.updateNode(
|
|
2707
|
+
this.selection?.id,
|
|
2708
|
+
{ textColor: event.target.value },
|
|
2709
|
+
{ inspector: false, reason: "node:update" }
|
|
2710
|
+
);
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
if (field === "edge-color") {
|
|
2714
|
+
this.updateEdge(
|
|
2715
|
+
this.selection?.id,
|
|
2716
|
+
{ color: event.target.value },
|
|
2717
|
+
{ inspector: false, reason: "edge:update" }
|
|
2718
|
+
);
|
|
2422
2719
|
}
|
|
2423
2720
|
}
|
|
2424
2721
|
handleSelectionFieldChange(event) {
|
|
@@ -2462,6 +2759,14 @@ var VdFlowchart = class {
|
|
|
2462
2759
|
{ strokeWidth: getStrokePresetWidth(event.target.value) },
|
|
2463
2760
|
{ inspector: true, reason: "edge:update" }
|
|
2464
2761
|
);
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
if (field === "edge-stroke-style") {
|
|
2765
|
+
this.updateEdge(
|
|
2766
|
+
this.selection?.id,
|
|
2767
|
+
{ strokeStyle: event.target.value },
|
|
2768
|
+
{ inspector: true, reason: "edge:update" }
|
|
2769
|
+
);
|
|
2465
2770
|
}
|
|
2466
2771
|
}
|
|
2467
2772
|
// Keys the editor consumes stop here, so page-level shortcuts (a docs
|
|
@@ -2484,6 +2789,11 @@ var VdFlowchart = class {
|
|
|
2484
2789
|
this.toggleShortcutsHelp(false);
|
|
2485
2790
|
return;
|
|
2486
2791
|
}
|
|
2792
|
+
if (key === "Escape" && this.colorPopoverOpen) {
|
|
2793
|
+
event.preventDefault();
|
|
2794
|
+
this.toggleColorPopover(false);
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2487
2797
|
if (target === this.canvasEl && this.handleCanvasKeyDown(event)) {
|
|
2488
2798
|
event.preventDefault();
|
|
2489
2799
|
return;
|
|
@@ -2506,6 +2816,29 @@ var VdFlowchart = class {
|
|
|
2506
2816
|
}
|
|
2507
2817
|
return;
|
|
2508
2818
|
}
|
|
2819
|
+
if (modKey && (key === "l" || key === "L")) {
|
|
2820
|
+
if (this.selection?.kind === "node") {
|
|
2821
|
+
event.preventDefault();
|
|
2822
|
+
this.toggleNodeLocked();
|
|
2823
|
+
}
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2826
|
+
if (modKey && (key === "]" || key === "}" || event.code === "BracketRight")) {
|
|
2827
|
+
if (this.selection) {
|
|
2828
|
+
event.preventDefault();
|
|
2829
|
+
if (event.shiftKey || key === "}") this.bringToFront();
|
|
2830
|
+
else this.bringForward();
|
|
2831
|
+
}
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
if (modKey && (key === "[" || key === "{" || event.code === "BracketLeft")) {
|
|
2835
|
+
if (this.selection) {
|
|
2836
|
+
event.preventDefault();
|
|
2837
|
+
if (event.shiftKey || key === "{") this.sendToBack();
|
|
2838
|
+
else this.sendBackward();
|
|
2839
|
+
}
|
|
2840
|
+
return;
|
|
2841
|
+
}
|
|
2509
2842
|
if (modKey && (event.key === "z" || event.key === "Z")) {
|
|
2510
2843
|
event.preventDefault();
|
|
2511
2844
|
if (event.shiftKey) {
|
|
@@ -2688,7 +3021,7 @@ var VdFlowchart = class {
|
|
|
2688
3021
|
nudgeNodes(nodeIds, direction, distance) {
|
|
2689
3022
|
const step = { right: [1, 0], left: [-1, 0], down: [0, 1], up: [0, -1] }[direction];
|
|
2690
3023
|
if (this.readonly || !step) return [];
|
|
2691
|
-
const nodes = nodeIds.map((id) => this.findNode(id)).filter(
|
|
3024
|
+
const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
|
|
2692
3025
|
if (!nodes.length) return [];
|
|
2693
3026
|
nodes.forEach((node) => {
|
|
2694
3027
|
node.x = formatNumber(node.x + step[0] * distance);
|
|
@@ -2827,6 +3160,14 @@ var VdFlowchart = class {
|
|
|
2827
3160
|
this.emitChange("edge:add", { edge: deepClone(edge) });
|
|
2828
3161
|
return true;
|
|
2829
3162
|
}
|
|
3163
|
+
pasteSelection() {
|
|
3164
|
+
if (!this.pasteClipboard()) return null;
|
|
3165
|
+
if (this.hasMultiSelection()) {
|
|
3166
|
+
return this.getSelectedNodeIds().map((id) => this.findNode(id)).filter(Boolean).map((node) => deepClone(node));
|
|
3167
|
+
}
|
|
3168
|
+
const snap = this.getSelectionSnapshot();
|
|
3169
|
+
return snap?.node || snap?.edge || null;
|
|
3170
|
+
}
|
|
2830
3171
|
cutSelection() {
|
|
2831
3172
|
if (!this.copySelection()) return false;
|
|
2832
3173
|
return this.deleteSelection();
|
|
@@ -2864,6 +3205,9 @@ var VdFlowchart = class {
|
|
|
2864
3205
|
}
|
|
2865
3206
|
handlePointerDown(event) {
|
|
2866
3207
|
if (this.destroyed || event.button != null && event.button !== 0) return;
|
|
3208
|
+
if (this.colorPopoverOpen) {
|
|
3209
|
+
this.toggleColorPopover(false);
|
|
3210
|
+
}
|
|
2867
3211
|
if (this.textEditor && !event.target.closest(".vd-flowchart-text-editor")) {
|
|
2868
3212
|
this.stopTextEdit({ commit: true });
|
|
2869
3213
|
}
|
|
@@ -2888,6 +3232,8 @@ var VdFlowchart = class {
|
|
|
2888
3232
|
const fromNode = this.findNode(edge.from.nodeId);
|
|
2889
3233
|
const toNode = this.findNode(edge.to.nodeId);
|
|
2890
3234
|
if (!fromNode || !toNode) return;
|
|
3235
|
+
const endpointNode = endpoint === "from" ? fromNode : toNode;
|
|
3236
|
+
if (endpointNode.locked) return;
|
|
2891
3237
|
this.reconnectEdgeId = edgeId;
|
|
2892
3238
|
this.select({ kind: "edge", id: edgeId });
|
|
2893
3239
|
this.interaction = {
|
|
@@ -2938,7 +3284,7 @@ var VdFlowchart = class {
|
|
|
2938
3284
|
const nodeId = portTarget.getAttribute("data-node-id");
|
|
2939
3285
|
const port = portTarget.getAttribute("data-port");
|
|
2940
3286
|
const node = this.findNode(nodeId);
|
|
2941
|
-
if (!node) return;
|
|
3287
|
+
if (!node || node.locked) return;
|
|
2942
3288
|
const sourcePoint = getPortPosition(node, port);
|
|
2943
3289
|
this.interaction = {
|
|
2944
3290
|
kind: "connect",
|
|
@@ -2967,7 +3313,7 @@ var VdFlowchart = class {
|
|
|
2967
3313
|
const nodeId = resizeTarget.getAttribute("data-node-id");
|
|
2968
3314
|
const handle = resizeTarget.getAttribute("data-resize-handle");
|
|
2969
3315
|
const node = this.findNode(nodeId);
|
|
2970
|
-
if (!node || !RESIZE_HANDLES.includes(handle)) return;
|
|
3316
|
+
if (!node || !isNodeResizable(node) || !RESIZE_HANDLES.includes(handle)) return;
|
|
2971
3317
|
this.select({ kind: "node", id: nodeId });
|
|
2972
3318
|
this.interaction = {
|
|
2973
3319
|
kind: "resize-node",
|
|
@@ -3000,8 +3346,11 @@ var VdFlowchart = class {
|
|
|
3000
3346
|
if (groupIds.length > 1) this.selectNodes(groupIds, { primary: nodeId });
|
|
3001
3347
|
else this.select({ kind: "node", id: nodeId });
|
|
3002
3348
|
if (!this.readonly) {
|
|
3003
|
-
|
|
3004
|
-
|
|
3349
|
+
const drag = this.createDragInteraction(event, nodeId, groupIds);
|
|
3350
|
+
if (drag) {
|
|
3351
|
+
this.interaction = drag;
|
|
3352
|
+
this.capturePointer(event.pointerId);
|
|
3353
|
+
}
|
|
3005
3354
|
}
|
|
3006
3355
|
return;
|
|
3007
3356
|
}
|
|
@@ -3032,12 +3381,13 @@ var VdFlowchart = class {
|
|
|
3032
3381
|
event.preventDefault();
|
|
3033
3382
|
}
|
|
3034
3383
|
createDragInteraction(event, nodeId, nodeIds) {
|
|
3035
|
-
const nodes = nodeIds.map((id) => this.findNode(id)).filter(
|
|
3384
|
+
const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
|
|
3385
|
+
if (!nodes.length) return null;
|
|
3036
3386
|
const moving = new Set(nodes.map((node) => node.id));
|
|
3037
3387
|
return {
|
|
3038
3388
|
kind: "drag-node",
|
|
3039
3389
|
pointerId: event.pointerId,
|
|
3040
|
-
nodeId,
|
|
3390
|
+
nodeId: moving.has(nodeId) ? nodeId : nodes[0].id,
|
|
3041
3391
|
nodeIds: nodes.map((node) => node.id),
|
|
3042
3392
|
startWorld: this.clientToWorld(event.clientX, event.clientY),
|
|
3043
3393
|
origins: new Map(nodes.map((node) => [node.id, { x: node.x, y: node.y }])),
|
|
@@ -3389,15 +3739,16 @@ var VdFlowchart = class {
|
|
|
3389
3739
|
if (this.activeTool === "arrow") return true;
|
|
3390
3740
|
return this.selection?.kind === "node" && this.selection.id === node.id && !this.hasMultiSelection();
|
|
3391
3741
|
}
|
|
3392
|
-
getMarkerId(markerType, position, strokeWidth, edgeScale = 1) {
|
|
3742
|
+
getMarkerId(markerType, position, strokeWidth, edgeScale = 1, color = "") {
|
|
3393
3743
|
const width = normalizeEdgeStrokeWidth(strokeWidth);
|
|
3394
3744
|
const scale = clamp(formatNumber(Math.max(edgeScale, 0.01)), 0.01, 1);
|
|
3395
|
-
const
|
|
3745
|
+
const fill = resolveEdgeColorValue(color);
|
|
3746
|
+
const key = `${markerType}:${position}:${width}:${scale}:${fill}`;
|
|
3396
3747
|
if (this.markerIds.has(key)) {
|
|
3397
3748
|
return this.markerIds.get(key);
|
|
3398
3749
|
}
|
|
3399
3750
|
const markerId = nextId(`flowchart-${markerType}-${position}`);
|
|
3400
|
-
const marker = markerType === "dot" ? createDotMarker(markerId, width, scale) : createArrowMarker(markerId, width, position === "start", scale);
|
|
3751
|
+
const marker = markerType === "dot" ? createDotMarker(markerId, width, scale, fill) : createArrowMarker(markerId, width, position === "start", scale, fill);
|
|
3401
3752
|
this.markerDefs.appendChild(marker);
|
|
3402
3753
|
this.markerIds.set(key, markerId);
|
|
3403
3754
|
return markerId;
|
|
@@ -3419,7 +3770,7 @@ var VdFlowchart = class {
|
|
|
3419
3770
|
const snapPadding = CONNECTION_SNAP_PADDING / this.documentData.viewport.scale;
|
|
3420
3771
|
const hysteresisMargin = CONNECTION_HYSTERESIS / this.documentData.viewport.scale;
|
|
3421
3772
|
const best = this.getVisibleNodes().reduce((candidate, node) => {
|
|
3422
|
-
if (node.id === excludeNodeId) return candidate;
|
|
3773
|
+
if (node.id === excludeNodeId || node.locked) return candidate;
|
|
3423
3774
|
const distanceToBounds2 = getDistanceToNodeBounds(node, worldPoint);
|
|
3424
3775
|
if (distanceToBounds2 > snapPadding) return candidate;
|
|
3425
3776
|
const nearest = pickPortForNode(node, worldPoint, referencePoint);
|
|
@@ -3437,7 +3788,7 @@ var VdFlowchart = class {
|
|
|
3437
3788
|
}, null);
|
|
3438
3789
|
if (!previousSnap || !best) return best;
|
|
3439
3790
|
const previousNode = this.findNode(previousSnap.nodeId);
|
|
3440
|
-
if (!previousNode || previousNode.id === excludeNodeId) return best;
|
|
3791
|
+
if (!previousNode || previousNode.id === excludeNodeId || previousNode.locked) return best;
|
|
3441
3792
|
const distanceToBounds = getDistanceToNodeBounds(previousNode, worldPoint);
|
|
3442
3793
|
if (distanceToBounds > snapPadding) return best;
|
|
3443
3794
|
if (best.node.id === previousSnap.nodeId && best.port === previousSnap.port) {
|
|
@@ -3852,16 +4203,17 @@ var VdFlowchart = class {
|
|
|
3852
4203
|
}
|
|
3853
4204
|
applyEdgeMarkers(pathElement, edge, edgeScale = 1) {
|
|
3854
4205
|
const width = this.getEdgeStrokeWidth(edge);
|
|
4206
|
+
const color = edge.color || "";
|
|
3855
4207
|
if (edge.startMarker && edge.startMarker !== "none") {
|
|
3856
4208
|
pathElement.setAttribute(
|
|
3857
4209
|
"marker-start",
|
|
3858
|
-
`url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale)})`
|
|
4210
|
+
`url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale, color)})`
|
|
3859
4211
|
);
|
|
3860
4212
|
}
|
|
3861
4213
|
if (edge.endMarker && edge.endMarker !== "none") {
|
|
3862
4214
|
pathElement.setAttribute(
|
|
3863
4215
|
"marker-end",
|
|
3864
|
-
`url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale)})`
|
|
4216
|
+
`url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale, color)})`
|
|
3865
4217
|
);
|
|
3866
4218
|
}
|
|
3867
4219
|
}
|
|
@@ -3873,10 +4225,19 @@ var VdFlowchart = class {
|
|
|
3873
4225
|
const edgePath = buildEdgePath(edge, fromNode, toNode);
|
|
3874
4226
|
const selected = this.selection?.kind === "edge" && this.selection.id === edge.id;
|
|
3875
4227
|
const inReconnectMode = this.reconnectEdgeId === edge.id;
|
|
4228
|
+
const strokeStyle = normalizeEdgeStrokeStyle(edge.strokeStyle);
|
|
4229
|
+
const strokeClass = strokeStyle !== "solid" ? ` is-stroke-${strokeStyle}` : "";
|
|
3876
4230
|
const group = svgEl("g", {
|
|
3877
|
-
class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}`,
|
|
4231
|
+
class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}${strokeClass}`,
|
|
3878
4232
|
"data-edge-id": edge.id
|
|
3879
4233
|
});
|
|
4234
|
+
if (edge.color) {
|
|
4235
|
+
if (FLOWCHART_COLOR_PRESETS.includes(edge.color) && edge.color !== "default") {
|
|
4236
|
+
group.setAttribute("data-color", edge.color);
|
|
4237
|
+
} else {
|
|
4238
|
+
group.setAttribute("data-color", "custom");
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
3880
4241
|
const baseStroke = this.getEdgeStrokeWidth(edge);
|
|
3881
4242
|
const strokeWidth = visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke;
|
|
3882
4243
|
if (selected) {
|
|
@@ -3894,6 +4255,20 @@ var VdFlowchart = class {
|
|
|
3894
4255
|
"stroke-width": strokeWidth,
|
|
3895
4256
|
"data-edge-id": edge.id
|
|
3896
4257
|
});
|
|
4258
|
+
if (edge.color && !FLOWCHART_COLOR_PRESETS.includes(edge.color)) {
|
|
4259
|
+
visiblePath.style.stroke = edge.color;
|
|
4260
|
+
}
|
|
4261
|
+
if (strokeStyle === "dashed" || strokeStyle === "animated") {
|
|
4262
|
+
visiblePath.setAttribute(
|
|
4263
|
+
"stroke-dasharray",
|
|
4264
|
+
visual < 0.999 ? `${formatNumber(8 * visual)} ${formatNumber(5 * visual)}` : "8 5"
|
|
4265
|
+
);
|
|
4266
|
+
} else if (strokeStyle === "dotted") {
|
|
4267
|
+
visiblePath.setAttribute(
|
|
4268
|
+
"stroke-dasharray",
|
|
4269
|
+
visual < 0.999 ? `${formatNumber(2 * visual)} ${formatNumber(5 * visual)}` : "2 5"
|
|
4270
|
+
);
|
|
4271
|
+
}
|
|
3897
4272
|
this.applyEdgeMarkers(visiblePath, edge, visual);
|
|
3898
4273
|
const hitPath = svgEl("path", {
|
|
3899
4274
|
class: "vd-flowchart-edge-hit",
|
|
@@ -3976,6 +4351,36 @@ var VdFlowchart = class {
|
|
|
3976
4351
|
"stroke-width": visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke
|
|
3977
4352
|
});
|
|
3978
4353
|
}
|
|
4354
|
+
renderLockBadge(node) {
|
|
4355
|
+
const scale = this.documentData.viewport.scale || 1;
|
|
4356
|
+
const badgeSize = 16 / scale;
|
|
4357
|
+
const offsetX = node.width - badgeSize / 2 - 4 / scale;
|
|
4358
|
+
const offsetY = badgeSize / 2 + 4 / scale;
|
|
4359
|
+
const badge = svgEl("g", {
|
|
4360
|
+
class: "vd-flowchart-node-lock",
|
|
4361
|
+
transform: `translate(${formatNumber(offsetX)} ${formatNumber(offsetY)})`,
|
|
4362
|
+
"data-node-id": node.id
|
|
4363
|
+
});
|
|
4364
|
+
const title = svgEl("title");
|
|
4365
|
+
title.textContent = "Locked node";
|
|
4366
|
+
badge.appendChild(title);
|
|
4367
|
+
badge.appendChild(
|
|
4368
|
+
svgEl("circle", {
|
|
4369
|
+
cx: 0,
|
|
4370
|
+
cy: 0,
|
|
4371
|
+
r: formatNumber(badgeSize / 2)
|
|
4372
|
+
})
|
|
4373
|
+
);
|
|
4374
|
+
const iconScale = badgeSize * 0.62 / 256;
|
|
4375
|
+
const iconOffset = -128 * iconScale;
|
|
4376
|
+
badge.appendChild(
|
|
4377
|
+
svgEl("path", {
|
|
4378
|
+
d: TOOLBAR_ICON_PATHS.lock,
|
|
4379
|
+
transform: `translate(${formatNumber(iconOffset)} ${formatNumber(iconOffset)}) scale(${formatScale(iconScale)})`
|
|
4380
|
+
})
|
|
4381
|
+
);
|
|
4382
|
+
return badge;
|
|
4383
|
+
}
|
|
3979
4384
|
renderNode(node) {
|
|
3980
4385
|
const selected = this.isNodeSelected(node.id);
|
|
3981
4386
|
const soloSelected = selected && !this.hasMultiSelection();
|
|
@@ -3983,10 +4388,13 @@ var VdFlowchart = class {
|
|
|
3983
4388
|
const resizing = this.interaction?.kind === "resize-node" && this.interaction.nodeId === node.id;
|
|
3984
4389
|
const editing = this.textEditor?.nodeId === node.id;
|
|
3985
4390
|
const group = svgEl("g", {
|
|
3986
|
-
class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}`,
|
|
4391
|
+
class: `vd-flowchart-node${selected ? " is-selected" : ""}${dragging ? " is-dragging" : ""}${resizing ? " is-resizing" : ""}${editing ? " is-editing" : ""}${node.locked ? " is-locked" : ""}`,
|
|
3987
4392
|
transform: `translate(${formatNumber(node.x)} ${formatNumber(node.y)})`,
|
|
3988
4393
|
"data-node-id": node.id
|
|
3989
4394
|
});
|
|
4395
|
+
if (node.color) {
|
|
4396
|
+
group.setAttribute("data-color", node.color);
|
|
4397
|
+
}
|
|
3990
4398
|
const portsVisible = this.shouldShowNodePorts(node);
|
|
3991
4399
|
const visual = nodeVisualScale(node);
|
|
3992
4400
|
const corner = node.type === "rounded-rect" || node.type === "textbox" ? 16 : node.type === "junction" ? node.width / 2 : 6;
|
|
@@ -4002,8 +4410,15 @@ var VdFlowchart = class {
|
|
|
4002
4410
|
group.appendChild(hitbox);
|
|
4003
4411
|
const shape = this.renderNodeShape(node);
|
|
4004
4412
|
this.applyScaledNodeShape(node, shape);
|
|
4413
|
+
if (node.fill) shape.style.fill = node.fill;
|
|
4414
|
+
if (node.stroke) shape.style.stroke = node.stroke;
|
|
4005
4415
|
group.appendChild(shape);
|
|
4006
|
-
|
|
4416
|
+
const textEl = this.renderNodeText(node);
|
|
4417
|
+
if (node.textColor) textEl.style.fill = node.textColor;
|
|
4418
|
+
group.appendChild(textEl);
|
|
4419
|
+
if (node.locked) {
|
|
4420
|
+
group.appendChild(this.renderLockBadge(node));
|
|
4421
|
+
}
|
|
4007
4422
|
const scale = this.documentData.viewport.scale || 1;
|
|
4008
4423
|
if (soloSelected && !this.readonly && SELECTION_BOX_TYPES.has(node.type)) {
|
|
4009
4424
|
const outset = SELECTION_OUTSET / scale;
|
|
@@ -4323,6 +4738,127 @@ var VdFlowchart = class {
|
|
|
4323
4738
|
});
|
|
4324
4739
|
return textElement;
|
|
4325
4740
|
}
|
|
4741
|
+
buildInspectorColorSwatches(activePreset = "default", disabled = this.readonly) {
|
|
4742
|
+
const normalizedActive = activePreset || "default";
|
|
4743
|
+
const grid = createElement("div", { className: "vd-flowchart-swatch-grid" });
|
|
4744
|
+
FLOWCHART_COLOR_PRESETS.forEach((preset) => {
|
|
4745
|
+
const active = preset === normalizedActive;
|
|
4746
|
+
const button = createElement("button", {
|
|
4747
|
+
className: `vd-flowchart-swatch vd-flowchart-swatch--${preset}${active ? " is-active" : ""}`,
|
|
4748
|
+
title: FLOWCHART_COLOR_PRESET_LABELS[preset] || preset,
|
|
4749
|
+
disabled
|
|
4750
|
+
});
|
|
4751
|
+
button.setAttribute("type", "button");
|
|
4752
|
+
button.setAttribute("data-color-preset", preset);
|
|
4753
|
+
button.setAttribute("aria-label", `Color ${FLOWCHART_COLOR_PRESET_LABELS[preset] || preset}`);
|
|
4754
|
+
button.setAttribute("aria-pressed", active ? "true" : "false");
|
|
4755
|
+
grid.appendChild(button);
|
|
4756
|
+
});
|
|
4757
|
+
return grid;
|
|
4758
|
+
}
|
|
4759
|
+
buildInspectorArrangeRow(disabled = this.readonly) {
|
|
4760
|
+
const grid = createElement("div", { className: "vd-flowchart-action-grid" });
|
|
4761
|
+
const actions = [
|
|
4762
|
+
{
|
|
4763
|
+
action: "bring-to-front",
|
|
4764
|
+
label: "Front",
|
|
4765
|
+
title: "Bring to front (Cmd/Ctrl+Shift+])"
|
|
4766
|
+
},
|
|
4767
|
+
{
|
|
4768
|
+
action: "bring-forward",
|
|
4769
|
+
label: "Forward",
|
|
4770
|
+
title: "Bring forward (Cmd/Ctrl+])"
|
|
4771
|
+
},
|
|
4772
|
+
{
|
|
4773
|
+
action: "send-backward",
|
|
4774
|
+
label: "Backward",
|
|
4775
|
+
title: "Send backward (Cmd/Ctrl+[)"
|
|
4776
|
+
},
|
|
4777
|
+
{
|
|
4778
|
+
action: "send-to-back",
|
|
4779
|
+
label: "Back",
|
|
4780
|
+
title: "Send to back (Cmd/Ctrl+Shift+[)"
|
|
4781
|
+
}
|
|
4782
|
+
];
|
|
4783
|
+
actions.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
|
|
4789
|
+
});
|
|
4790
|
+
btn.setAttribute("type", "button");
|
|
4791
|
+
btn.setAttribute("data-arrange-action", item.action);
|
|
4792
|
+
grid.appendChild(btn);
|
|
4793
|
+
});
|
|
4794
|
+
return grid;
|
|
4795
|
+
}
|
|
4796
|
+
buildInspectorAlignRow(nodeCount, disabled = this.readonly) {
|
|
4797
|
+
const wrap = createElement("div", { className: "vd-flowchart-inspector-stack" });
|
|
4798
|
+
const alignGrid = createElement("div", { className: "vd-flowchart-action-grid" });
|
|
4799
|
+
const alignments = [
|
|
4800
|
+
{ action: "left", label: "Left", title: "Align left edges" },
|
|
4801
|
+
{ action: "center", label: "Center", title: "Align horizontal centers" },
|
|
4802
|
+
{ action: "right", label: "Right", title: "Align right edges" },
|
|
4803
|
+
{ action: "top", label: "Top", title: "Align top edges" },
|
|
4804
|
+
{ action: "middle", label: "Middle", title: "Align vertical centers" },
|
|
4805
|
+
{ action: "bottom", label: "Bottom", title: "Align bottom edges" }
|
|
4806
|
+
];
|
|
4807
|
+
alignments.forEach((item) => {
|
|
4808
|
+
const btn = createElement("button", {
|
|
4809
|
+
className: "vd-flowchart-btn vd-flowchart-action-btn",
|
|
4810
|
+
text: item.label,
|
|
4811
|
+
title: item.title,
|
|
4812
|
+
disabled: disabled || nodeCount < 2
|
|
4813
|
+
});
|
|
4814
|
+
btn.setAttribute("type", "button");
|
|
4815
|
+
btn.setAttribute("data-align-action", item.action);
|
|
4816
|
+
alignGrid.appendChild(btn);
|
|
4817
|
+
});
|
|
4818
|
+
wrap.appendChild(createField("Align", alignGrid));
|
|
4819
|
+
const distributeGrid = createElement("div", { className: "vd-flowchart-action-grid" });
|
|
4820
|
+
[
|
|
4821
|
+
{ action: "horizontal", label: "Distribute H", title: "Distribute horizontally" },
|
|
4822
|
+
{ action: "vertical", label: "Distribute V", title: "Distribute vertically" }
|
|
4823
|
+
].forEach((item) => {
|
|
4824
|
+
const btn = createElement("button", {
|
|
4825
|
+
className: "vd-flowchart-btn vd-flowchart-action-btn",
|
|
4826
|
+
text: item.label,
|
|
4827
|
+
title: item.title,
|
|
4828
|
+
disabled: disabled || nodeCount < 3
|
|
4829
|
+
});
|
|
4830
|
+
btn.setAttribute("type", "button");
|
|
4831
|
+
btn.setAttribute("data-distribute-action", item.action);
|
|
4832
|
+
distributeGrid.appendChild(btn);
|
|
4833
|
+
});
|
|
4834
|
+
wrap.appendChild(createField("Distribute", distributeGrid));
|
|
4835
|
+
return wrap;
|
|
4836
|
+
}
|
|
4837
|
+
buildInspectorUtilityRow({ showLock = true, locked = false, disabled = this.readonly } = {}) {
|
|
4838
|
+
const grid = createElement("div", { className: "vd-flowchart-action-grid" });
|
|
4839
|
+
if (showLock) {
|
|
4840
|
+
const lockBtn = createElement("button", {
|
|
4841
|
+
className: `vd-flowchart-btn vd-flowchart-action-btn${locked ? " is-active" : ""}`,
|
|
4842
|
+
text: locked ? "Unlock" : "Lock",
|
|
4843
|
+
title: "Toggle node lock (Cmd/Ctrl+L)",
|
|
4844
|
+
disabled
|
|
4845
|
+
});
|
|
4846
|
+
lockBtn.setAttribute("type", "button");
|
|
4847
|
+
lockBtn.setAttribute("data-lock-toggle", "");
|
|
4848
|
+
lockBtn.setAttribute("aria-pressed", locked ? "true" : "false");
|
|
4849
|
+
grid.appendChild(lockBtn);
|
|
4850
|
+
}
|
|
4851
|
+
const resetBtn = createElement("button", {
|
|
4852
|
+
className: "vd-flowchart-btn vd-flowchart-action-btn",
|
|
4853
|
+
text: "Reset color",
|
|
4854
|
+
title: "Reset to theme default color",
|
|
4855
|
+
disabled
|
|
4856
|
+
});
|
|
4857
|
+
resetBtn.setAttribute("type", "button");
|
|
4858
|
+
resetBtn.setAttribute("data-color-reset", "");
|
|
4859
|
+
grid.appendChild(resetBtn);
|
|
4860
|
+
return grid;
|
|
4861
|
+
}
|
|
4326
4862
|
renderSelectionPanel() {
|
|
4327
4863
|
clearChildren(this.selectionFields);
|
|
4328
4864
|
this.deleteButton.disabled = this.readonly || !this.selection;
|
|
@@ -4337,6 +4873,11 @@ var VdFlowchart = class {
|
|
|
4337
4873
|
return;
|
|
4338
4874
|
}
|
|
4339
4875
|
if (this.hasMultiSelection()) {
|
|
4876
|
+
const selectedIds = this.getSelectedNodeIds();
|
|
4877
|
+
const selectedNodes = selectedIds.map((id) => this.findNode(id)).filter(Boolean);
|
|
4878
|
+
const allLocked = selectedNodes.length > 0 && selectedNodes.every((n) => n.locked);
|
|
4879
|
+
this.deleteButton.disabled = this.readonly || allLocked;
|
|
4880
|
+
const sharedColor = selectedNodes.length > 0 && selectedNodes.every((n) => (n.color || "default") === (selectedNodes[0].color || "default")) ? selectedNodes[0].color || "default" : "";
|
|
4340
4881
|
this.selectionMeta.textContent = `${this.selectedNodeIds.size} nodes selected`;
|
|
4341
4882
|
this.selectionFields.appendChild(
|
|
4342
4883
|
createElement("p", {
|
|
@@ -4344,6 +4885,22 @@ var VdFlowchart = class {
|
|
|
4344
4885
|
text: "Drag, nudge with Alt+Arrow, copy, duplicate, or delete them together."
|
|
4345
4886
|
})
|
|
4346
4887
|
);
|
|
4888
|
+
this.selectionFields.appendChild(
|
|
4889
|
+
createField("Color preset", this.buildInspectorColorSwatches(sharedColor, this.readonly))
|
|
4890
|
+
);
|
|
4891
|
+
this.selectionFields.appendChild(
|
|
4892
|
+
this.buildInspectorAlignRow(selectedNodes.length, this.readonly)
|
|
4893
|
+
);
|
|
4894
|
+
this.selectionFields.appendChild(
|
|
4895
|
+
createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
|
|
4896
|
+
);
|
|
4897
|
+
this.selectionFields.appendChild(
|
|
4898
|
+
this.buildInspectorUtilityRow({
|
|
4899
|
+
showLock: true,
|
|
4900
|
+
locked: allLocked,
|
|
4901
|
+
disabled: this.readonly
|
|
4902
|
+
})
|
|
4903
|
+
);
|
|
4347
4904
|
return;
|
|
4348
4905
|
}
|
|
4349
4906
|
if (this.selection.kind === "node") {
|
|
@@ -4353,8 +4910,10 @@ var VdFlowchart = class {
|
|
|
4353
4910
|
this.renderSelectionPanel();
|
|
4354
4911
|
return;
|
|
4355
4912
|
}
|
|
4356
|
-
|
|
4357
|
-
|
|
4913
|
+
const isLocked = Boolean(node.locked);
|
|
4914
|
+
this.deleteButton.disabled = this.readonly || isLocked;
|
|
4915
|
+
this.selectionMeta.textContent = `Node ${node.id} \xB7 ${node.type} \xB7 ${Math.round(node.x)}, ${Math.round(node.y)}${isLocked ? " \xB7 locked" : ""}`;
|
|
4916
|
+
const typeSelect = createElement("select", { disabled: this.readonly || isLocked });
|
|
4358
4917
|
typeSelect.setAttribute("data-field", "node-type");
|
|
4359
4918
|
FLOWCHART_NODE_TYPES.forEach((type) => {
|
|
4360
4919
|
const option = createElement("option", { value: type, text: type.replace("-", " ") });
|
|
@@ -4362,13 +4921,25 @@ var VdFlowchart = class {
|
|
|
4362
4921
|
option.selected = type === node.type;
|
|
4363
4922
|
typeSelect.appendChild(option);
|
|
4364
4923
|
});
|
|
4365
|
-
const textArea = createElement("textarea", {
|
|
4924
|
+
const textArea = createElement("textarea", {
|
|
4925
|
+
value: node.text,
|
|
4926
|
+
rows: 5,
|
|
4927
|
+
disabled: this.readonly || isLocked
|
|
4928
|
+
});
|
|
4366
4929
|
textArea.setAttribute("data-field", "node-text");
|
|
4367
|
-
const widthInput = createElement("input", {
|
|
4930
|
+
const widthInput = createElement("input", {
|
|
4931
|
+
value: node.width,
|
|
4932
|
+
type: "number",
|
|
4933
|
+
disabled: this.readonly || isLocked
|
|
4934
|
+
});
|
|
4368
4935
|
widthInput.setAttribute("data-field", "node-width");
|
|
4369
4936
|
widthInput.setAttribute("min", String(this.minNodeSize));
|
|
4370
4937
|
widthInput.setAttribute("max", String(this.maxNodeSize));
|
|
4371
|
-
const heightInput = createElement("input", {
|
|
4938
|
+
const heightInput = createElement("input", {
|
|
4939
|
+
value: node.height,
|
|
4940
|
+
type: "number",
|
|
4941
|
+
disabled: this.readonly || isLocked
|
|
4942
|
+
});
|
|
4372
4943
|
heightInput.setAttribute("data-field", "node-height");
|
|
4373
4944
|
heightInput.setAttribute("min", String(this.minNodeSize));
|
|
4374
4945
|
heightInput.setAttribute("max", String(this.maxNodeSize));
|
|
@@ -4389,6 +4960,48 @@ var VdFlowchart = class {
|
|
|
4389
4960
|
})
|
|
4390
4961
|
);
|
|
4391
4962
|
}
|
|
4963
|
+
this.selectionFields.appendChild(
|
|
4964
|
+
createField(
|
|
4965
|
+
"Color preset",
|
|
4966
|
+
this.buildInspectorColorSwatches(node.color || "default", this.readonly || isLocked)
|
|
4967
|
+
)
|
|
4968
|
+
);
|
|
4969
|
+
const customColorsGrid = createElement("div", { className: "vd-flowchart-field-grid" });
|
|
4970
|
+
const fillInput = createElement("input", {
|
|
4971
|
+
value: node.fill || "",
|
|
4972
|
+
type: "text",
|
|
4973
|
+
disabled: this.readonly || isLocked
|
|
4974
|
+
});
|
|
4975
|
+
fillInput.setAttribute("data-field", "node-fill");
|
|
4976
|
+
fillInput.setAttribute("placeholder", "Fill (e.g. #dbeafe)");
|
|
4977
|
+
const strokeInput = createElement("input", {
|
|
4978
|
+
value: node.stroke || "",
|
|
4979
|
+
type: "text",
|
|
4980
|
+
disabled: this.readonly || isLocked
|
|
4981
|
+
});
|
|
4982
|
+
strokeInput.setAttribute("data-field", "node-stroke");
|
|
4983
|
+
strokeInput.setAttribute("placeholder", "Stroke (e.g. #2563eb)");
|
|
4984
|
+
const textColorInput = createElement("input", {
|
|
4985
|
+
value: node.textColor || "",
|
|
4986
|
+
type: "text",
|
|
4987
|
+
disabled: this.readonly || isLocked
|
|
4988
|
+
});
|
|
4989
|
+
textColorInput.setAttribute("data-field", "node-text-color");
|
|
4990
|
+
textColorInput.setAttribute("placeholder", "Text (e.g. #1e3a8a)");
|
|
4991
|
+
customColorsGrid.appendChild(createField("Fill", fillInput));
|
|
4992
|
+
customColorsGrid.appendChild(createField("Border", strokeInput));
|
|
4993
|
+
this.selectionFields.appendChild(customColorsGrid);
|
|
4994
|
+
this.selectionFields.appendChild(createField("Text color", textColorInput));
|
|
4995
|
+
this.selectionFields.appendChild(
|
|
4996
|
+
createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
|
|
4997
|
+
);
|
|
4998
|
+
this.selectionFields.appendChild(
|
|
4999
|
+
this.buildInspectorUtilityRow({
|
|
5000
|
+
showLock: true,
|
|
5001
|
+
locked: isLocked,
|
|
5002
|
+
disabled: this.readonly
|
|
5003
|
+
})
|
|
5004
|
+
);
|
|
4392
5005
|
return;
|
|
4393
5006
|
}
|
|
4394
5007
|
const edge = this.findEdge(this.selection.id);
|
|
@@ -4397,8 +5010,9 @@ var VdFlowchart = class {
|
|
|
4397
5010
|
this.renderSelectionPanel();
|
|
4398
5011
|
return;
|
|
4399
5012
|
}
|
|
5013
|
+
const edgeStyleName = normalizeEdgeStrokeStyle(edge.strokeStyle);
|
|
4400
5014
|
this.selectionMeta.textContent = `Edge ${edge.id} \xB7 ${edge.route} \xB7 ${formatNumber(edge.strokeWidth)}px \xB7 ${edge.startMarker} \u2192 ${edge.endMarker}`;
|
|
4401
|
-
const routeSelect = createElement("select");
|
|
5015
|
+
const routeSelect = createElement("select", { disabled: this.readonly });
|
|
4402
5016
|
routeSelect.setAttribute("data-field", "edge-route");
|
|
4403
5017
|
FLOWCHART_EDGE_ROUTES.forEach((route) => {
|
|
4404
5018
|
const option = createElement("option", {
|
|
@@ -4409,7 +5023,7 @@ var VdFlowchart = class {
|
|
|
4409
5023
|
option.selected = route === edge.route;
|
|
4410
5024
|
routeSelect.appendChild(option);
|
|
4411
5025
|
});
|
|
4412
|
-
const startSelect = createElement("select");
|
|
5026
|
+
const startSelect = createElement("select", { disabled: this.readonly });
|
|
4413
5027
|
startSelect.setAttribute("data-field", "edge-start-marker");
|
|
4414
5028
|
FLOWCHART_EDGE_MARKERS.forEach((marker) => {
|
|
4415
5029
|
const option = createElement("option", { value: marker, text: marker });
|
|
@@ -4417,7 +5031,7 @@ var VdFlowchart = class {
|
|
|
4417
5031
|
option.selected = marker === edge.startMarker;
|
|
4418
5032
|
startSelect.appendChild(option);
|
|
4419
5033
|
});
|
|
4420
|
-
const endSelect = createElement("select");
|
|
5034
|
+
const endSelect = createElement("select", { disabled: this.readonly });
|
|
4421
5035
|
endSelect.setAttribute("data-field", "edge-end-marker");
|
|
4422
5036
|
FLOWCHART_EDGE_MARKERS.forEach((marker) => {
|
|
4423
5037
|
const option = createElement("option", { value: marker, text: marker });
|
|
@@ -4425,7 +5039,7 @@ var VdFlowchart = class {
|
|
|
4425
5039
|
option.selected = marker === edge.endMarker;
|
|
4426
5040
|
endSelect.appendChild(option);
|
|
4427
5041
|
});
|
|
4428
|
-
const widthSelect = createElement("select");
|
|
5042
|
+
const widthSelect = createElement("select", { disabled: this.readonly });
|
|
4429
5043
|
widthSelect.setAttribute("data-field", "edge-stroke-preset");
|
|
4430
5044
|
EDGE_STROKE_PRESETS.forEach((preset) => {
|
|
4431
5045
|
const option = createElement("option", { value: preset.id, text: preset.label });
|
|
@@ -4433,15 +5047,52 @@ var VdFlowchart = class {
|
|
|
4433
5047
|
option.selected = preset.id === getStrokePresetId(edge.strokeWidth);
|
|
4434
5048
|
widthSelect.appendChild(option);
|
|
4435
5049
|
});
|
|
4436
|
-
const
|
|
5050
|
+
const strokeStyleSelect = createElement("select", { disabled: this.readonly });
|
|
5051
|
+
strokeStyleSelect.setAttribute("data-field", "edge-stroke-style");
|
|
5052
|
+
FLOWCHART_EDGE_STROKE_STYLES.forEach((style) => {
|
|
5053
|
+
const option = createElement("option", {
|
|
5054
|
+
value: style,
|
|
5055
|
+
text: FLOWCHART_EDGE_STROKE_STYLE_LABELS[style] || style
|
|
5056
|
+
});
|
|
5057
|
+
option.value = style;
|
|
5058
|
+
option.selected = style === edgeStyleName;
|
|
5059
|
+
strokeStyleSelect.appendChild(option);
|
|
5060
|
+
});
|
|
5061
|
+
const labelInput = createElement("textarea", {
|
|
5062
|
+
value: edge.label,
|
|
5063
|
+
rows: 4,
|
|
5064
|
+
disabled: this.readonly
|
|
5065
|
+
});
|
|
4437
5066
|
labelInput.setAttribute("data-field", "edge-label");
|
|
4438
5067
|
const markerGrid = createElement("div", { className: "vd-flowchart-field-grid" });
|
|
4439
5068
|
markerGrid.appendChild(createField("Route", routeSelect));
|
|
4440
5069
|
markerGrid.appendChild(createField("Weight", widthSelect));
|
|
5070
|
+
markerGrid.appendChild(createField("Style", strokeStyleSelect));
|
|
4441
5071
|
markerGrid.appendChild(createField("Start", startSelect));
|
|
4442
5072
|
markerGrid.appendChild(createField("End", endSelect));
|
|
4443
5073
|
this.selectionFields.appendChild(markerGrid);
|
|
4444
5074
|
this.selectionFields.appendChild(createField("Label", labelInput));
|
|
5075
|
+
const activeEdgePreset = edge.color && FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "default";
|
|
5076
|
+
this.selectionFields.appendChild(
|
|
5077
|
+
createField(
|
|
5078
|
+
"Color preset",
|
|
5079
|
+
this.buildInspectorColorSwatches(activeEdgePreset, this.readonly)
|
|
5080
|
+
)
|
|
5081
|
+
);
|
|
5082
|
+
const edgeColorInput = createElement("input", {
|
|
5083
|
+
value: edge.color && !FLOWCHART_COLOR_PRESET_SET.has(edge.color) ? edge.color : "",
|
|
5084
|
+
type: "text",
|
|
5085
|
+
disabled: this.readonly
|
|
5086
|
+
});
|
|
5087
|
+
edgeColorInput.setAttribute("data-field", "edge-color");
|
|
5088
|
+
edgeColorInput.setAttribute("placeholder", "Custom color (e.g. #2563eb)");
|
|
5089
|
+
this.selectionFields.appendChild(createField("Custom color", edgeColorInput));
|
|
5090
|
+
this.selectionFields.appendChild(
|
|
5091
|
+
createField("Layer order", this.buildInspectorArrangeRow(this.readonly))
|
|
5092
|
+
);
|
|
5093
|
+
this.selectionFields.appendChild(
|
|
5094
|
+
this.buildInspectorUtilityRow({ showLock: false, disabled: this.readonly })
|
|
5095
|
+
);
|
|
4445
5096
|
}
|
|
4446
5097
|
syncJsonTextarea(force = false) {
|
|
4447
5098
|
if (!force && document.activeElement === this.jsonTextarea) {
|
|
@@ -4847,7 +5498,14 @@ var VdFlowchart = class {
|
|
|
4847
5498
|
// the parent's box shape, falling back to a rounded step.
|
|
4848
5499
|
getBranchTemplate(parent, sibling) {
|
|
4849
5500
|
const source = sibling || (["rounded-rect", "rect", "textbox"].includes(parent.type) ? parent : null) || null;
|
|
4850
|
-
if (source)
|
|
5501
|
+
if (source) {
|
|
5502
|
+
const template = { type: source.type, width: source.width, height: source.height };
|
|
5503
|
+
if (source.color) template.color = source.color;
|
|
5504
|
+
if (source.fill) template.fill = source.fill;
|
|
5505
|
+
if (source.stroke) template.stroke = source.stroke;
|
|
5506
|
+
if (source.textColor) template.textColor = source.textColor;
|
|
5507
|
+
return template;
|
|
5508
|
+
}
|
|
4851
5509
|
const spec = DEFAULT_NODE_SPECS["rounded-rect"];
|
|
4852
5510
|
return { type: "rounded-rect", width: spec.width, height: spec.height };
|
|
4853
5511
|
}
|
|
@@ -4883,7 +5541,9 @@ var VdFlowchart = class {
|
|
|
4883
5541
|
route: styleSource.route,
|
|
4884
5542
|
strokeWidth: styleSource.strokeWidth,
|
|
4885
5543
|
startMarker: styleSource.startMarker,
|
|
4886
|
-
endMarker: styleSource.endMarker
|
|
5544
|
+
endMarker: styleSource.endMarker,
|
|
5545
|
+
...styleSource.color ? { color: styleSource.color } : {},
|
|
5546
|
+
...styleSource.strokeStyle ? { strokeStyle: styleSource.strokeStyle } : {}
|
|
4887
5547
|
} : { endMarker: "arrow" };
|
|
4888
5548
|
const result = this.batchHistory("node:insert", () => {
|
|
4889
5549
|
if (parent.collapsed) delete parent.collapsed;
|
|
@@ -5101,6 +5761,30 @@ var VdFlowchart = class {
|
|
|
5101
5761
|
node.text = isNodeTextEditable(nextType) ? patch.text == null ? node.text : String(patch.text) : getNodeSpec(nextType).text;
|
|
5102
5762
|
node.width = clampNodeWidth(nextType, patch.width, node.width, this.nodeSizeBounds());
|
|
5103
5763
|
node.height = clampNodeHeight(nextType, patch.height, node.height, this.nodeSizeBounds());
|
|
5764
|
+
if ("color" in patch) {
|
|
5765
|
+
const nextColor = normalizeColorPreset(patch.color);
|
|
5766
|
+
if (nextColor) node.color = nextColor;
|
|
5767
|
+
else delete node.color;
|
|
5768
|
+
}
|
|
5769
|
+
if ("fill" in patch) {
|
|
5770
|
+
const nextFill = sanitizeCssColor(patch.fill);
|
|
5771
|
+
if (nextFill) node.fill = nextFill;
|
|
5772
|
+
else delete node.fill;
|
|
5773
|
+
}
|
|
5774
|
+
if ("stroke" in patch) {
|
|
5775
|
+
const nextStroke = sanitizeCssColor(patch.stroke);
|
|
5776
|
+
if (nextStroke) node.stroke = nextStroke;
|
|
5777
|
+
else delete node.stroke;
|
|
5778
|
+
}
|
|
5779
|
+
if ("textColor" in patch) {
|
|
5780
|
+
const nextTextColor = sanitizeCssColor(patch.textColor);
|
|
5781
|
+
if (nextTextColor) node.textColor = nextTextColor;
|
|
5782
|
+
else delete node.textColor;
|
|
5783
|
+
}
|
|
5784
|
+
if ("locked" in patch) {
|
|
5785
|
+
if (patch.locked) node.locked = true;
|
|
5786
|
+
else delete node.locked;
|
|
5787
|
+
}
|
|
5104
5788
|
if (isPlainObject(patch.data)) {
|
|
5105
5789
|
node.data = deepClone(patch.data);
|
|
5106
5790
|
}
|
|
@@ -5108,6 +5792,11 @@ var VdFlowchart = class {
|
|
|
5108
5792
|
updateNode(nodeId, patch = {}, options = {}) {
|
|
5109
5793
|
const node = this.findNode(nodeId);
|
|
5110
5794
|
if (!node) return null;
|
|
5795
|
+
if (node.locked) {
|
|
5796
|
+
const keys = Object.keys(patch);
|
|
5797
|
+
const unlocking = keys.length > 0 && keys.every((key) => key === "locked") && !patch.locked;
|
|
5798
|
+
if (!unlocking) return null;
|
|
5799
|
+
}
|
|
5111
5800
|
const previousType = node.type;
|
|
5112
5801
|
const previousSpec = DEFAULT_NODE_SPECS[previousType];
|
|
5113
5802
|
this.applyNodePatch(node, patch);
|
|
@@ -5212,6 +5901,16 @@ var VdFlowchart = class {
|
|
|
5212
5901
|
if (patch.label != null) {
|
|
5213
5902
|
edge.label = String(patch.label);
|
|
5214
5903
|
}
|
|
5904
|
+
if ("color" in patch) {
|
|
5905
|
+
const nextColor = normalizeEdgeColor(patch.color);
|
|
5906
|
+
if (nextColor) edge.color = nextColor;
|
|
5907
|
+
else delete edge.color;
|
|
5908
|
+
}
|
|
5909
|
+
if ("strokeStyle" in patch) {
|
|
5910
|
+
const nextStrokeStyle = normalizeEdgeStrokeStyle(patch.strokeStyle);
|
|
5911
|
+
if (nextStrokeStyle && nextStrokeStyle !== "solid") edge.strokeStyle = nextStrokeStyle;
|
|
5912
|
+
else delete edge.strokeStyle;
|
|
5913
|
+
}
|
|
5215
5914
|
if (isPlainObject(patch.data)) {
|
|
5216
5915
|
edge.data = deepClone(patch.data);
|
|
5217
5916
|
}
|
|
@@ -5284,11 +5983,405 @@ var VdFlowchart = class {
|
|
|
5284
5983
|
deleteSelection() {
|
|
5285
5984
|
if (!this.selection || this.readonly) return false;
|
|
5286
5985
|
if (this.hasMultiSelection()) {
|
|
5287
|
-
|
|
5986
|
+
const unlockedIds = this.getSelectedNodeIds().filter((id) => !this.findNode(id)?.locked);
|
|
5987
|
+
if (!unlockedIds.length) return false;
|
|
5988
|
+
return this.removeNodeIds(new Set(unlockedIds), "node:remove");
|
|
5989
|
+
}
|
|
5990
|
+
if (this.selection.kind === "node") {
|
|
5991
|
+
const node = this.findNode(this.selection.id);
|
|
5992
|
+
if (node?.locked) return false;
|
|
5993
|
+
return this.removeNode(this.selection.id);
|
|
5288
5994
|
}
|
|
5289
|
-
if (this.selection.kind === "node") return this.removeNode(this.selection.id);
|
|
5290
5995
|
return this.removeEdge(this.selection.id);
|
|
5291
5996
|
}
|
|
5997
|
+
// --- Coloring, Layer Order, Align/Distribute, Locking, SVG Export ---------
|
|
5998
|
+
setNodeColor(nodeId, colorOrPatch) {
|
|
5999
|
+
if (this.readonly) return null;
|
|
6000
|
+
const id = sanitizeId(nodeId);
|
|
6001
|
+
if (!this.findNode(id)) return null;
|
|
6002
|
+
let patch;
|
|
6003
|
+
if (isPlainObject(colorOrPatch)) {
|
|
6004
|
+
patch = {};
|
|
6005
|
+
if ("color" in colorOrPatch) patch.color = colorOrPatch.color;
|
|
6006
|
+
if ("fill" in colorOrPatch) patch.fill = colorOrPatch.fill;
|
|
6007
|
+
if ("stroke" in colorOrPatch) patch.stroke = colorOrPatch.stroke;
|
|
6008
|
+
if ("textColor" in colorOrPatch) patch.textColor = colorOrPatch.textColor;
|
|
6009
|
+
} else if (colorOrPatch == null || colorOrPatch === "" || colorOrPatch === "default") {
|
|
6010
|
+
patch = { color: null, fill: null, stroke: null, textColor: null };
|
|
6011
|
+
} else {
|
|
6012
|
+
const token = String(colorOrPatch).trim();
|
|
6013
|
+
if (FLOWCHART_COLOR_PRESET_SET.has(token)) {
|
|
6014
|
+
patch = { color: token, fill: null, stroke: null, textColor: null };
|
|
6015
|
+
} else {
|
|
6016
|
+
const css = sanitizeCssColor(token);
|
|
6017
|
+
if (!css) return null;
|
|
6018
|
+
patch = { fill: css };
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
return this.updateNode(id, patch, { reason: "node:color" });
|
|
6022
|
+
}
|
|
6023
|
+
setEdgeColor(edgeId, color) {
|
|
6024
|
+
if (this.readonly) return null;
|
|
6025
|
+
const id = sanitizeId(edgeId);
|
|
6026
|
+
if (!this.findEdge(id)) return null;
|
|
6027
|
+
const nextColor = color == null || color === "" || color === "default" ? null : isPlainObject(color) ? normalizeEdgeColor(color.color ?? color.stroke) : normalizeEdgeColor(color);
|
|
6028
|
+
return this.updateEdge(id, { color: nextColor }, { reason: "edge:color" });
|
|
6029
|
+
}
|
|
6030
|
+
setSelectionColor(colorOrPatch) {
|
|
6031
|
+
if (this.readonly || !this.selection) return this;
|
|
6032
|
+
if (this.selection.kind === "edge") {
|
|
6033
|
+
this.setEdgeColor(this.selection.id, colorOrPatch);
|
|
6034
|
+
return this;
|
|
6035
|
+
}
|
|
6036
|
+
const ids = this.getSelectedNodeIds();
|
|
6037
|
+
if (!ids.length) return this;
|
|
6038
|
+
this.batchHistory("node:color", () => {
|
|
6039
|
+
ids.forEach((id) => {
|
|
6040
|
+
this.setNodeColor(id, colorOrPatch);
|
|
6041
|
+
});
|
|
6042
|
+
});
|
|
6043
|
+
return this;
|
|
6044
|
+
}
|
|
6045
|
+
clearSelectionColor() {
|
|
6046
|
+
return this.setSelectionColor(null);
|
|
6047
|
+
}
|
|
6048
|
+
reorderArrayLayer(items, targetIds, direction) {
|
|
6049
|
+
const idSet = new Set(targetIds);
|
|
6050
|
+
if (!idSet.size || items.length < 2) return null;
|
|
6051
|
+
let next;
|
|
6052
|
+
if (direction === "front") {
|
|
6053
|
+
next = [
|
|
6054
|
+
...items.filter((item) => !idSet.has(item.id)),
|
|
6055
|
+
...items.filter((item) => idSet.has(item.id))
|
|
6056
|
+
];
|
|
6057
|
+
} else if (direction === "back") {
|
|
6058
|
+
next = [
|
|
6059
|
+
...items.filter((item) => idSet.has(item.id)),
|
|
6060
|
+
...items.filter((item) => !idSet.has(item.id))
|
|
6061
|
+
];
|
|
6062
|
+
} else if (direction === "forward") {
|
|
6063
|
+
next = [...items];
|
|
6064
|
+
for (let i = next.length - 2; i >= 0; i -= 1) {
|
|
6065
|
+
if (idSet.has(next[i].id) && !idSet.has(next[i + 1].id)) {
|
|
6066
|
+
const temp = next[i];
|
|
6067
|
+
next[i] = next[i + 1];
|
|
6068
|
+
next[i + 1] = temp;
|
|
6069
|
+
}
|
|
6070
|
+
}
|
|
6071
|
+
} else if (direction === "backward") {
|
|
6072
|
+
next = [...items];
|
|
6073
|
+
for (let i = 1; i < next.length; i += 1) {
|
|
6074
|
+
if (idSet.has(next[i].id) && !idSet.has(next[i - 1].id)) {
|
|
6075
|
+
const temp = next[i];
|
|
6076
|
+
next[i] = next[i - 1];
|
|
6077
|
+
next[i - 1] = temp;
|
|
6078
|
+
}
|
|
6079
|
+
}
|
|
6080
|
+
} else {
|
|
6081
|
+
return null;
|
|
6082
|
+
}
|
|
6083
|
+
const changed = next.some((item, index) => item.id !== items[index].id);
|
|
6084
|
+
return changed ? next : null;
|
|
6085
|
+
}
|
|
6086
|
+
reorderLayer(direction, targetId) {
|
|
6087
|
+
if (this.readonly) return this;
|
|
6088
|
+
let explicitIds = [];
|
|
6089
|
+
if (Array.isArray(targetId)) {
|
|
6090
|
+
explicitIds = targetId.map(sanitizeId).filter(Boolean);
|
|
6091
|
+
} else if (typeof targetId === "string" && targetId.trim()) {
|
|
6092
|
+
explicitIds = [sanitizeId(targetId)];
|
|
6093
|
+
}
|
|
6094
|
+
if (explicitIds.length) {
|
|
6095
|
+
const nodeIdSet = new Set(this.documentData.nodes.map((n) => n.id));
|
|
6096
|
+
const matchingNodes = explicitIds.filter((id) => nodeIdSet.has(id));
|
|
6097
|
+
if (matchingNodes.length) {
|
|
6098
|
+
const reordered2 = this.reorderArrayLayer(this.documentData.nodes, matchingNodes, direction);
|
|
6099
|
+
if (reordered2) {
|
|
6100
|
+
this.documentData.nodes = reordered2;
|
|
6101
|
+
this.render();
|
|
6102
|
+
this.emitChange("node:order", { direction, nodeIds: matchingNodes });
|
|
6103
|
+
}
|
|
6104
|
+
return this;
|
|
6105
|
+
}
|
|
6106
|
+
const edgeIdSet = new Set(this.documentData.edges.map((e) => e.id));
|
|
6107
|
+
const matchingEdges = explicitIds.filter((id) => edgeIdSet.has(id));
|
|
6108
|
+
if (matchingEdges.length) {
|
|
6109
|
+
const reordered2 = this.reorderArrayLayer(this.documentData.edges, matchingEdges, direction);
|
|
6110
|
+
if (reordered2) {
|
|
6111
|
+
this.documentData.edges = reordered2;
|
|
6112
|
+
this.render();
|
|
6113
|
+
this.emitChange("edge:order", { direction, edgeIds: matchingEdges });
|
|
6114
|
+
}
|
|
6115
|
+
}
|
|
6116
|
+
return this;
|
|
6117
|
+
}
|
|
6118
|
+
if (!this.selection) return this;
|
|
6119
|
+
if (this.selection.kind === "edge") {
|
|
6120
|
+
const reordered2 = this.reorderArrayLayer(
|
|
6121
|
+
this.documentData.edges,
|
|
6122
|
+
[this.selection.id],
|
|
6123
|
+
direction
|
|
6124
|
+
);
|
|
6125
|
+
if (reordered2) {
|
|
6126
|
+
this.documentData.edges = reordered2;
|
|
6127
|
+
this.render();
|
|
6128
|
+
this.emitChange("edge:order", { direction, edgeIds: [this.selection.id] });
|
|
6129
|
+
}
|
|
6130
|
+
return this;
|
|
6131
|
+
}
|
|
6132
|
+
const ids = this.getSelectedNodeIds();
|
|
6133
|
+
const reordered = this.reorderArrayLayer(this.documentData.nodes, ids, direction);
|
|
6134
|
+
if (reordered) {
|
|
6135
|
+
this.documentData.nodes = reordered;
|
|
6136
|
+
this.render();
|
|
6137
|
+
this.emitChange("node:order", { direction, nodeIds: ids });
|
|
6138
|
+
}
|
|
6139
|
+
return this;
|
|
6140
|
+
}
|
|
6141
|
+
bringToFront(targetId) {
|
|
6142
|
+
return this.reorderLayer("front", targetId);
|
|
6143
|
+
}
|
|
6144
|
+
bringForward(targetId) {
|
|
6145
|
+
return this.reorderLayer("forward", targetId);
|
|
6146
|
+
}
|
|
6147
|
+
sendBackward(targetId) {
|
|
6148
|
+
return this.reorderLayer("backward", targetId);
|
|
6149
|
+
}
|
|
6150
|
+
sendToBack(targetId) {
|
|
6151
|
+
return this.reorderLayer("back", targetId);
|
|
6152
|
+
}
|
|
6153
|
+
alignNodes(alignment = "left", nodeIds) {
|
|
6154
|
+
if (this.readonly || !FLOWCHART_NODE_ALIGNMENTS.includes(alignment)) return this;
|
|
6155
|
+
const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
|
|
6156
|
+
const hidden = this.getHiddenNodeIds();
|
|
6157
|
+
const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
|
|
6158
|
+
if (nodes.length < 2) return this;
|
|
6159
|
+
const bounds = getBounds(nodes);
|
|
6160
|
+
const centerX = (bounds.left + bounds.right) / 2;
|
|
6161
|
+
const centerY = (bounds.top + bounds.bottom) / 2;
|
|
6162
|
+
const movedIds = [];
|
|
6163
|
+
nodes.forEach((node) => {
|
|
6164
|
+
if (node.locked) return;
|
|
6165
|
+
let nextX = node.x;
|
|
6166
|
+
let nextY = node.y;
|
|
6167
|
+
if (alignment === "left") nextX = formatNumber(bounds.left);
|
|
6168
|
+
else if (alignment === "center") nextX = formatNumber(centerX - node.width / 2);
|
|
6169
|
+
else if (alignment === "right") nextX = formatNumber(bounds.right - node.width);
|
|
6170
|
+
else if (alignment === "top") nextY = formatNumber(bounds.top);
|
|
6171
|
+
else if (alignment === "middle") nextY = formatNumber(centerY - node.height / 2);
|
|
6172
|
+
else if (alignment === "bottom") nextY = formatNumber(bounds.bottom - node.height);
|
|
6173
|
+
if (nextX !== node.x || nextY !== node.y) {
|
|
6174
|
+
node.x = nextX;
|
|
6175
|
+
node.y = nextY;
|
|
6176
|
+
movedIds.push(node.id);
|
|
6177
|
+
}
|
|
6178
|
+
});
|
|
6179
|
+
if (movedIds.length) {
|
|
6180
|
+
this.render();
|
|
6181
|
+
this.emitChange("node:align", { alignment, nodeIds: movedIds });
|
|
6182
|
+
}
|
|
6183
|
+
return this;
|
|
6184
|
+
}
|
|
6185
|
+
distributeNodes(axis = "horizontal", nodeIds) {
|
|
6186
|
+
if (this.readonly || !FLOWCHART_DISTRIBUTE_AXES.includes(axis)) return this;
|
|
6187
|
+
const ids = Array.isArray(nodeIds) ? nodeIds.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
|
|
6188
|
+
const hidden = this.getHiddenNodeIds();
|
|
6189
|
+
const nodes = ids.map((id) => this.findNode(id)).filter((node) => node && !hidden.has(node.id));
|
|
6190
|
+
if (nodes.length < 3) return this;
|
|
6191
|
+
const sorted = [...nodes].sort(
|
|
6192
|
+
(a, b) => axis === "horizontal" ? a.x + a.width / 2 - (b.x + b.width / 2) : a.y + a.height / 2 - (b.y + b.height / 2)
|
|
6193
|
+
);
|
|
6194
|
+
const first = sorted[0];
|
|
6195
|
+
const last = sorted[sorted.length - 1];
|
|
6196
|
+
const movedIds = [];
|
|
6197
|
+
if (axis === "horizontal") {
|
|
6198
|
+
const totalSpan = last.x + last.width - first.x;
|
|
6199
|
+
const totalSize = sorted.reduce((sum, node) => sum + node.width, 0);
|
|
6200
|
+
const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
|
|
6201
|
+
let cursor = first.x;
|
|
6202
|
+
sorted.forEach((node, index) => {
|
|
6203
|
+
if (index > 0 && index < sorted.length - 1 && !node.locked) {
|
|
6204
|
+
const nextX = formatNumber(cursor);
|
|
6205
|
+
if (nextX !== node.x) {
|
|
6206
|
+
node.x = nextX;
|
|
6207
|
+
movedIds.push(node.id);
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6210
|
+
cursor += node.width + gap;
|
|
6211
|
+
});
|
|
6212
|
+
} else {
|
|
6213
|
+
const totalSpan = last.y + last.height - first.y;
|
|
6214
|
+
const totalSize = sorted.reduce((sum, node) => sum + node.height, 0);
|
|
6215
|
+
const gap = Math.max(0, (totalSpan - totalSize) / (sorted.length - 1));
|
|
6216
|
+
let cursor = first.y;
|
|
6217
|
+
sorted.forEach((node, index) => {
|
|
6218
|
+
if (index > 0 && index < sorted.length - 1 && !node.locked) {
|
|
6219
|
+
const nextY = formatNumber(cursor);
|
|
6220
|
+
if (nextY !== node.y) {
|
|
6221
|
+
node.y = nextY;
|
|
6222
|
+
movedIds.push(node.id);
|
|
6223
|
+
}
|
|
6224
|
+
}
|
|
6225
|
+
cursor += node.height + gap;
|
|
6226
|
+
});
|
|
6227
|
+
}
|
|
6228
|
+
if (movedIds.length) {
|
|
6229
|
+
this.render();
|
|
6230
|
+
this.emitChange("node:distribute", { axis, nodeIds: movedIds });
|
|
6231
|
+
}
|
|
6232
|
+
return this;
|
|
6233
|
+
}
|
|
6234
|
+
setNodeLocked(nodeId, locked = true) {
|
|
6235
|
+
if (this.readonly) return false;
|
|
6236
|
+
let targetIds;
|
|
6237
|
+
let nextLocked = Boolean(locked);
|
|
6238
|
+
if (typeof nodeId === "boolean") {
|
|
6239
|
+
nextLocked = nodeId;
|
|
6240
|
+
targetIds = this.getSelectedNodeIds();
|
|
6241
|
+
} else if (Array.isArray(nodeId)) {
|
|
6242
|
+
targetIds = nodeId.map(sanitizeId).filter(Boolean);
|
|
6243
|
+
} else if (nodeId == null) {
|
|
6244
|
+
targetIds = this.getSelectedNodeIds();
|
|
6245
|
+
} else {
|
|
6246
|
+
targetIds = [sanitizeId(nodeId)];
|
|
6247
|
+
}
|
|
6248
|
+
const changedNodes = [];
|
|
6249
|
+
targetIds.forEach((id) => {
|
|
6250
|
+
const node = this.findNode(id);
|
|
6251
|
+
if (!node || Boolean(node.locked) === nextLocked) return;
|
|
6252
|
+
if (nextLocked) node.locked = true;
|
|
6253
|
+
else delete node.locked;
|
|
6254
|
+
changedNodes.push(deepClone(node));
|
|
6255
|
+
});
|
|
6256
|
+
if (!changedNodes.length) return false;
|
|
6257
|
+
if (nextLocked && this.textEditor && targetIds.includes(this.textEditor.nodeId)) {
|
|
6258
|
+
this.stopTextEdit({ commit: true });
|
|
6259
|
+
}
|
|
6260
|
+
this.render();
|
|
6261
|
+
this.emitChange("node:lock", {
|
|
6262
|
+
node: changedNodes[0],
|
|
6263
|
+
nodes: changedNodes,
|
|
6264
|
+
locked: nextLocked
|
|
6265
|
+
});
|
|
6266
|
+
return true;
|
|
6267
|
+
}
|
|
6268
|
+
toggleNodeLocked(nodeId) {
|
|
6269
|
+
if (this.readonly) return false;
|
|
6270
|
+
if (nodeId != null && typeof nodeId !== "boolean" && !Array.isArray(nodeId)) {
|
|
6271
|
+
const node = this.findNode(sanitizeId(nodeId));
|
|
6272
|
+
return node ? this.setNodeLocked(node.id, !node.locked) : false;
|
|
6273
|
+
}
|
|
6274
|
+
const ids = Array.isArray(nodeId) ? nodeId.map(sanitizeId).filter(Boolean) : this.getSelectedNodeIds();
|
|
6275
|
+
const nodes = ids.map((id) => this.findNode(id)).filter(Boolean);
|
|
6276
|
+
if (!nodes.length) return false;
|
|
6277
|
+
const shouldLock = nodes.some((node) => !node.locked);
|
|
6278
|
+
return this.setNodeLocked(ids, shouldLock);
|
|
6279
|
+
}
|
|
6280
|
+
exportSvg(options = {}) {
|
|
6281
|
+
const padding = Math.max(0, toFiniteNumber(options.padding, 32));
|
|
6282
|
+
const visibleNodes = this.getVisibleNodes();
|
|
6283
|
+
let viewX = 0;
|
|
6284
|
+
let viewY = 0;
|
|
6285
|
+
let viewWidth = 800;
|
|
6286
|
+
let viewHeight = 560;
|
|
6287
|
+
if (visibleNodes.length) {
|
|
6288
|
+
const bounds = getBounds(visibleNodes);
|
|
6289
|
+
viewX = formatNumber(bounds.left - padding);
|
|
6290
|
+
viewY = formatNumber(bounds.top - padding);
|
|
6291
|
+
viewWidth = formatNumber(Math.max(1, bounds.right - bounds.left + padding * 2));
|
|
6292
|
+
viewHeight = formatNumber(Math.max(1, bounds.bottom - bounds.top + padding * 2));
|
|
6293
|
+
}
|
|
6294
|
+
const exportRoot = svgEl("svg", {
|
|
6295
|
+
xmlns: SVG_NS,
|
|
6296
|
+
viewBox: `${viewX} ${viewY} ${viewWidth} ${viewHeight}`,
|
|
6297
|
+
width: viewWidth,
|
|
6298
|
+
height: viewHeight,
|
|
6299
|
+
class: "vd-flowchart-export"
|
|
6300
|
+
});
|
|
6301
|
+
const styleEl = svgEl("style");
|
|
6302
|
+
styleEl.textContent = [
|
|
6303
|
+
'.vd-flowchart-export { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }',
|
|
6304
|
+
".vd-flowchart-node-shape { fill: #ffffff; stroke: #475569; stroke-width: 2px; }",
|
|
6305
|
+
".vd-flowchart-node--textbox .vd-flowchart-node-shape { stroke-dasharray: 6 4; }",
|
|
6306
|
+
".vd-flowchart-node--junction .vd-flowchart-node-shape { fill: #2563eb; stroke: #ffffff; }",
|
|
6307
|
+
".vd-flowchart-node-text { fill: #0f172a; font-size: 14px; font-weight: 600; dominant-baseline: middle; text-anchor: middle; }",
|
|
6308
|
+
".vd-flowchart-edge-path { fill: none; stroke: #475569; stroke-linecap: round; stroke-linejoin: round; }",
|
|
6309
|
+
".vd-flowchart-edge-label { fill: #0f172a; font-size: 12px; font-weight: 600; paint-order: stroke; stroke: #ffffff; stroke-width: 5px; }"
|
|
6310
|
+
].join("\n");
|
|
6311
|
+
exportRoot.appendChild(styleEl);
|
|
6312
|
+
if (this.markerDefs) {
|
|
6313
|
+
const defsClone = this.markerDefs.cloneNode(true);
|
|
6314
|
+
defsClone.querySelectorAll("path, circle").forEach((shape) => {
|
|
6315
|
+
const fill = shape.getAttribute("fill") || "";
|
|
6316
|
+
const preset = fill.match(/--vd-flowchart-palette-([a-z]+)-edge/);
|
|
6317
|
+
if (preset) {
|
|
6318
|
+
const fallback = FLOWCHART_COLOR_PRESET_FALLBACKS[preset[1]]?.edge;
|
|
6319
|
+
if (fallback) {
|
|
6320
|
+
shape.setAttribute("fill", fallback);
|
|
6321
|
+
return;
|
|
6322
|
+
}
|
|
6323
|
+
}
|
|
6324
|
+
if (fill.includes("var(")) shape.setAttribute("fill", "#475569");
|
|
6325
|
+
});
|
|
6326
|
+
exportRoot.appendChild(defsClone);
|
|
6327
|
+
}
|
|
6328
|
+
if (typeof options.background === "string" && options.background.trim() && options.background.trim() !== "transparent") {
|
|
6329
|
+
const bgColor = options.background.trim() === "theme" ? "#ffffff" : sanitizeCssColor(options.background.trim()) || "#ffffff";
|
|
6330
|
+
exportRoot.appendChild(
|
|
6331
|
+
svgEl("rect", {
|
|
6332
|
+
x: viewX,
|
|
6333
|
+
y: viewY,
|
|
6334
|
+
width: viewWidth,
|
|
6335
|
+
height: viewHeight,
|
|
6336
|
+
fill: bgColor
|
|
6337
|
+
})
|
|
6338
|
+
);
|
|
6339
|
+
}
|
|
6340
|
+
const sceneGroup = svgEl("g", { class: "vd-flowchart-export-scene" });
|
|
6341
|
+
const edgesClone = this.edgesLayer.cloneNode(true);
|
|
6342
|
+
edgesClone.querySelectorAll(".vd-flowchart-edge-hit, .vd-flowchart-edge-selection").forEach((el) => el.remove());
|
|
6343
|
+
edgesClone.querySelectorAll(".vd-flowchart-edge").forEach((edgeGroup) => {
|
|
6344
|
+
edgeGroup.classList.remove("is-selected", "is-reconnecting");
|
|
6345
|
+
const edgeId = edgeGroup.getAttribute("data-edge-id");
|
|
6346
|
+
const edge = this.findEdge(edgeId);
|
|
6347
|
+
const pathEl = edgeGroup.querySelector(".vd-flowchart-edge-path");
|
|
6348
|
+
if (edge && pathEl) {
|
|
6349
|
+
const stroke = edge.color ? FLOWCHART_COLOR_PRESET_FALLBACKS[edge.color]?.edge || edge.color : "#475569";
|
|
6350
|
+
pathEl.setAttribute("stroke", stroke);
|
|
6351
|
+
pathEl.style.stroke = stroke;
|
|
6352
|
+
}
|
|
6353
|
+
});
|
|
6354
|
+
const nodesClone = this.nodesLayer.cloneNode(true);
|
|
6355
|
+
nodesClone.querySelectorAll(
|
|
6356
|
+
".vd-flowchart-ports, .vd-flowchart-resize-handles, .vd-flowchart-node-lock, .vd-flowchart-collapse-badge, .vd-flowchart-selection-box"
|
|
6357
|
+
).forEach((el) => el.remove());
|
|
6358
|
+
nodesClone.querySelectorAll(".vd-flowchart-node").forEach((nodeGroup) => {
|
|
6359
|
+
nodeGroup.classList.remove("is-selected", "is-multi-selected", "is-dragging");
|
|
6360
|
+
const nodeId = nodeGroup.getAttribute("data-node-id");
|
|
6361
|
+
const node = this.findNode(nodeId);
|
|
6362
|
+
if (!node) return;
|
|
6363
|
+
const shapeEl = nodeGroup.querySelector(".vd-flowchart-node-shape");
|
|
6364
|
+
const labelEl = nodeGroup.querySelector(".vd-flowchart-node-text");
|
|
6365
|
+
const presetColors = node.color ? FLOWCHART_COLOR_PRESET_FALLBACKS[node.color] : null;
|
|
6366
|
+
if (shapeEl) {
|
|
6367
|
+
const fill = node.fill || presetColors?.fill || (node.type === "junction" ? "#2563eb" : "#ffffff");
|
|
6368
|
+
const stroke = node.stroke || presetColors?.stroke || (node.type === "junction" ? "#ffffff" : "#475569");
|
|
6369
|
+
shapeEl.setAttribute("fill", fill);
|
|
6370
|
+
shapeEl.setAttribute("stroke", stroke);
|
|
6371
|
+
shapeEl.style.fill = fill;
|
|
6372
|
+
shapeEl.style.stroke = stroke;
|
|
6373
|
+
}
|
|
6374
|
+
if (labelEl) {
|
|
6375
|
+
const textColor = node.textColor || presetColors?.text || "#0f172a";
|
|
6376
|
+
labelEl.setAttribute("fill", textColor);
|
|
6377
|
+
labelEl.style.fill = textColor;
|
|
6378
|
+
}
|
|
6379
|
+
});
|
|
6380
|
+
sceneGroup.appendChild(edgesClone);
|
|
6381
|
+
sceneGroup.appendChild(nodesClone);
|
|
6382
|
+
exportRoot.appendChild(sceneGroup);
|
|
6383
|
+
return exportRoot.outerHTML;
|
|
6384
|
+
}
|
|
5292
6385
|
nodeSizeBounds() {
|
|
5293
6386
|
return { min: this.minNodeSize, max: this.maxNodeSize };
|
|
5294
6387
|
}
|
|
@@ -5434,8 +6527,12 @@ var VdFlowchart = class {
|
|
|
5434
6527
|
this.reconnectEdgeId = null;
|
|
5435
6528
|
}
|
|
5436
6529
|
this.readonly = Boolean(options.readonly);
|
|
6530
|
+
if (this.readonly && this.colorPopoverOpen) {
|
|
6531
|
+
this.toggleColorPopover(false);
|
|
6532
|
+
}
|
|
5437
6533
|
this.root.classList.toggle("vd-flowchart-readonly", this.readonly);
|
|
5438
6534
|
this.arrangeSelect.disabled = this.readonly;
|
|
6535
|
+
if (this.colorButton) this.colorButton.disabled = this.readonly;
|
|
5439
6536
|
this.clearButton.disabled = this.readonly;
|
|
5440
6537
|
this.loadJsonButton.disabled = this.readonly;
|
|
5441
6538
|
}
|
|
@@ -5658,7 +6755,25 @@ var VdFlowchart2 = (0, import_vue.defineComponent)({
|
|
|
5658
6755
|
canUndo: () => Boolean(instance?.canUndo()),
|
|
5659
6756
|
canRedo: () => Boolean(instance?.canRedo()),
|
|
5660
6757
|
layout: (mode, options) => instance?.layout(mode, options),
|
|
5661
|
-
fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding)
|
|
6758
|
+
fitNode: (nodeId, padding) => instance?.fitNode(nodeId, padding),
|
|
6759
|
+
setNodeColor: (nodeId, colorOrPatch) => instance?.setNodeColor(nodeId, colorOrPatch) ?? null,
|
|
6760
|
+
setEdgeColor: (edgeId, color) => instance?.setEdgeColor(edgeId, color) ?? null,
|
|
6761
|
+
setSelectionColor: (colorOrPatch) => instance?.setSelectionColor(colorOrPatch),
|
|
6762
|
+
clearSelectionColor: () => instance?.clearSelectionColor(),
|
|
6763
|
+
bringToFront: (targetId) => instance?.bringToFront(targetId),
|
|
6764
|
+
bringForward: (targetId) => instance?.bringForward(targetId),
|
|
6765
|
+
sendBackward: (targetId) => instance?.sendBackward(targetId),
|
|
6766
|
+
sendToBack: (targetId) => instance?.sendToBack(targetId),
|
|
6767
|
+
alignNodes: (alignment, nodeIds) => instance?.alignNodes(alignment, nodeIds),
|
|
6768
|
+
distributeNodes: (axis, nodeIds) => instance?.distributeNodes(axis, nodeIds),
|
|
6769
|
+
setNodeLocked: (nodeId, locked) => Boolean(instance?.setNodeLocked(nodeId, locked)),
|
|
6770
|
+
toggleNodeLocked: (nodeId) => Boolean(instance?.toggleNodeLocked(nodeId)),
|
|
6771
|
+
duplicateSelection: () => instance?.duplicateSelection() ?? null,
|
|
6772
|
+
copySelection: () => Boolean(instance?.copySelection()),
|
|
6773
|
+
pasteClipboard: () => Boolean(instance?.pasteClipboard()),
|
|
6774
|
+
pasteSelection: () => instance?.pasteSelection() ?? null,
|
|
6775
|
+
cutSelection: () => Boolean(instance?.cutSelection()),
|
|
6776
|
+
exportSvg: (options) => instance?.exportSvg(options) ?? ""
|
|
5662
6777
|
});
|
|
5663
6778
|
return () => (0, import_vue.h)("div", { ref: el, class: "vd-flowchart" });
|
|
5664
6779
|
}
|