@vanduo-oss/vd3-flowchart 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/README.md +18 -167
- package/SKILL.md +57 -15
- package/dist/core.d.ts +89 -2
- package/dist/index.cjs +1449 -86
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1449 -86
- package/dist/index.js.map +3 -3
- package/dist/meta.json +19 -15
- package/dist/vd3-flowchart.css +546 -4
- 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,
|
|
@@ -44,6 +48,8 @@ var DIRECTIONS = {
|
|
|
44
48
|
down: { main: "y", sign: 1 },
|
|
45
49
|
up: { main: "y", sign: -1 }
|
|
46
50
|
};
|
|
51
|
+
var DEFAULT_LEVEL_EDGE_GAP = 88;
|
|
52
|
+
var DEFAULT_SIBLING_EDGE_GAP = 64;
|
|
47
53
|
function num(value, fallback) {
|
|
48
54
|
const next = Number(value);
|
|
49
55
|
return Number.isFinite(next) ? next : fallback;
|
|
@@ -68,60 +74,182 @@ function pickRoots(nodes, indegree, optRoot) {
|
|
|
68
74
|
}
|
|
69
75
|
function spanningForest(allIds, roots, children) {
|
|
70
76
|
const visited = /* @__PURE__ */ new Set();
|
|
71
|
-
const
|
|
72
|
-
const tree = /* @__PURE__ */ new Map();
|
|
77
|
+
const active = /* @__PURE__ */ new Set();
|
|
73
78
|
const forestRoots = [];
|
|
74
|
-
const
|
|
79
|
+
const forwardParents = new Map(allIds.map((id) => [id, []]));
|
|
80
|
+
const dfs = (id) => {
|
|
75
81
|
visited.add(id);
|
|
76
|
-
|
|
77
|
-
const kids = [];
|
|
82
|
+
active.add(id);
|
|
78
83
|
(children.get(id) || []).forEach((child) => {
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
if (active.has(child)) return;
|
|
85
|
+
const list = forwardParents.get(child);
|
|
86
|
+
if (list && !list.includes(id)) list.push(id);
|
|
87
|
+
if (!visited.has(child)) dfs(child);
|
|
83
88
|
});
|
|
84
|
-
|
|
89
|
+
active.delete(id);
|
|
85
90
|
};
|
|
86
91
|
roots.forEach((root) => {
|
|
87
92
|
if (!visited.has(root)) {
|
|
88
93
|
forestRoots.push(root);
|
|
89
|
-
|
|
94
|
+
dfs(root);
|
|
90
95
|
}
|
|
91
96
|
});
|
|
92
97
|
allIds.forEach((id) => {
|
|
93
98
|
if (!visited.has(id)) {
|
|
94
99
|
forestRoots.push(id);
|
|
95
|
-
|
|
100
|
+
dfs(id);
|
|
96
101
|
}
|
|
97
102
|
});
|
|
103
|
+
const depth = new Map(allIds.map((id) => [id, 0]));
|
|
104
|
+
const limit = Math.max(1, allIds.length);
|
|
105
|
+
for (let pass = 0; pass < limit; pass += 1) {
|
|
106
|
+
let changed = false;
|
|
107
|
+
for (const id of allIds) {
|
|
108
|
+
const parents = forwardParents.get(id) || [];
|
|
109
|
+
for (const parent of parents) {
|
|
110
|
+
const nextDepth = Math.min(limit, (depth.get(parent) || 0) + 1);
|
|
111
|
+
if (nextDepth > (depth.get(id) || 0)) {
|
|
112
|
+
depth.set(id, nextDepth);
|
|
113
|
+
changed = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!changed) break;
|
|
118
|
+
}
|
|
119
|
+
const tree = new Map(allIds.map((id) => [id, []]));
|
|
120
|
+
const rootSet = new Set(forestRoots);
|
|
121
|
+
const chosenParent = /* @__PURE__ */ new Map();
|
|
122
|
+
for (const id of allIds) {
|
|
123
|
+
if (rootSet.has(id)) continue;
|
|
124
|
+
const parents = forwardParents.get(id) || [];
|
|
125
|
+
if (!parents.length) continue;
|
|
126
|
+
let bestParent = parents[0];
|
|
127
|
+
let bestDepth = depth.get(bestParent) ?? -1;
|
|
128
|
+
for (let index = 1; index < parents.length; index += 1) {
|
|
129
|
+
const candidate = parents[index];
|
|
130
|
+
const candidateDepth = depth.get(candidate) ?? -1;
|
|
131
|
+
if (candidateDepth > bestDepth) {
|
|
132
|
+
bestDepth = candidateDepth;
|
|
133
|
+
bestParent = candidate;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
chosenParent.set(id, bestParent);
|
|
137
|
+
}
|
|
138
|
+
const placedChild = /* @__PURE__ */ new Set();
|
|
139
|
+
for (const parentId of allIds) {
|
|
140
|
+
const out = tree.get(parentId);
|
|
141
|
+
for (const childId of children.get(parentId) || []) {
|
|
142
|
+
if (chosenParent.get(childId) === parentId && !placedChild.has(childId)) {
|
|
143
|
+
placedChild.add(childId);
|
|
144
|
+
out.push(childId);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
98
148
|
return { depth, tree, forestRoots };
|
|
99
149
|
}
|
|
100
150
|
function treeCenters(forestRoots, tree, depth, sizeOf, options) {
|
|
101
151
|
const dir = DIRECTIONS[options.direction] || DIRECTIONS.right;
|
|
102
|
-
const
|
|
103
|
-
const
|
|
152
|
+
const hasExplicitLevel = Number.isFinite(Number(options.levelGap));
|
|
153
|
+
const hasExplicitSibling = Number.isFinite(Number(options.siblingGap));
|
|
154
|
+
const explicitLevelGap = num(options.levelGap, 220);
|
|
155
|
+
const explicitSiblingGap = num(options.siblingGap, 140);
|
|
156
|
+
const edgeSiblingGap = hasExplicitSibling ? Math.max(16, explicitSiblingGap - 96) : DEFAULT_SIBLING_EDGE_GAP;
|
|
157
|
+
const crossSpan = (id) => {
|
|
158
|
+
const size = sizeOf(id);
|
|
159
|
+
return dir.main === "x" ? size.height : size.width;
|
|
160
|
+
};
|
|
161
|
+
const mainSpan = (id) => {
|
|
162
|
+
const size = sizeOf(id);
|
|
163
|
+
return dir.main === "x" ? size.width : size.height;
|
|
164
|
+
};
|
|
165
|
+
const subtreeSpan = /* @__PURE__ */ new Map();
|
|
166
|
+
const subtreeCount = /* @__PURE__ */ new Map();
|
|
167
|
+
const measure = (id) => {
|
|
168
|
+
const selfSpan = crossSpan(id);
|
|
169
|
+
const kids = tree.get(id) || [];
|
|
170
|
+
if (!kids.length) {
|
|
171
|
+
subtreeSpan.set(id, selfSpan);
|
|
172
|
+
subtreeCount.set(id, 1);
|
|
173
|
+
return selfSpan;
|
|
174
|
+
}
|
|
175
|
+
let childTotal = 0;
|
|
176
|
+
let totalCount = 1;
|
|
177
|
+
kids.forEach((kid, index) => {
|
|
178
|
+
if (index > 0) childTotal += edgeSiblingGap;
|
|
179
|
+
childTotal += measure(kid);
|
|
180
|
+
totalCount += subtreeCount.get(kid) || 1;
|
|
181
|
+
});
|
|
182
|
+
const span = Math.max(selfSpan, childTotal);
|
|
183
|
+
subtreeSpan.set(id, span);
|
|
184
|
+
subtreeCount.set(id, totalCount);
|
|
185
|
+
return span;
|
|
186
|
+
};
|
|
187
|
+
forestRoots.forEach(measure);
|
|
104
188
|
const crossOf = /* @__PURE__ */ new Map();
|
|
105
|
-
|
|
106
|
-
|
|
189
|
+
const place = (id, startCross) => {
|
|
190
|
+
const span = subtreeSpan.get(id) || crossSpan(id);
|
|
107
191
|
const kids = tree.get(id) || [];
|
|
108
192
|
if (!kids.length) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return
|
|
193
|
+
const center2 = startCross + span / 2;
|
|
194
|
+
crossOf.set(id, center2);
|
|
195
|
+
return center2;
|
|
196
|
+
}
|
|
197
|
+
let childTotal = 0;
|
|
198
|
+
const kidSpans = kids.map((kid, index) => {
|
|
199
|
+
const kidSpan = subtreeSpan.get(kid) || crossSpan(kid);
|
|
200
|
+
if (index > 0) childTotal += edgeSiblingGap;
|
|
201
|
+
childTotal += kidSpan;
|
|
202
|
+
return kidSpan;
|
|
203
|
+
});
|
|
204
|
+
let cursor = startCross + (span - childTotal) / 2;
|
|
205
|
+
const childCenters = kids.map((kid, index) => {
|
|
206
|
+
const kidSpan = kidSpans[index];
|
|
207
|
+
const center2 = place(kid, cursor);
|
|
208
|
+
cursor += kidSpan + edgeSiblingGap;
|
|
209
|
+
return center2;
|
|
210
|
+
});
|
|
211
|
+
if (kids.length >= 2) {
|
|
212
|
+
const counts = kids.map((kid) => subtreeCount.get(kid) || 1);
|
|
213
|
+
const maxCount = Math.max(...counts);
|
|
214
|
+
const minCount = Math.min(...counts);
|
|
215
|
+
if (maxCount > minCount) {
|
|
216
|
+
const primaryIndex = counts.indexOf(maxCount);
|
|
217
|
+
const center2 = childCenters[primaryIndex];
|
|
218
|
+
crossOf.set(id, center2);
|
|
219
|
+
return center2;
|
|
220
|
+
}
|
|
112
221
|
}
|
|
113
|
-
const childCenters = kids.map(place);
|
|
114
222
|
const center = (childCenters[0] + childCenters[childCenters.length - 1]) / 2;
|
|
115
223
|
crossOf.set(id, center);
|
|
116
224
|
return center;
|
|
117
225
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
226
|
+
let rootCursor = 0;
|
|
227
|
+
forestRoots.forEach((root, index) => {
|
|
228
|
+
if (index > 0) rootCursor += edgeSiblingGap;
|
|
229
|
+
const span = subtreeSpan.get(root) || crossSpan(root);
|
|
230
|
+
place(root, rootCursor);
|
|
231
|
+
rootCursor += span;
|
|
232
|
+
});
|
|
233
|
+
let maxDepth = 0;
|
|
234
|
+
const maxMainAtDepth = /* @__PURE__ */ new Map();
|
|
235
|
+
crossOf.forEach((_cross, id) => {
|
|
236
|
+
const d = depth.get(id) || 0;
|
|
237
|
+
if (d > maxDepth) maxDepth = d;
|
|
238
|
+
const current = maxMainAtDepth.get(d) || 0;
|
|
239
|
+
const span = mainSpan(id);
|
|
240
|
+
if (span > current) maxMainAtDepth.set(d, span);
|
|
121
241
|
});
|
|
242
|
+
const mainCenterAtDepth = /* @__PURE__ */ new Map([[0, 0]]);
|
|
243
|
+
for (let d = 1; d <= maxDepth; d += 1) {
|
|
244
|
+
const prevCenter = mainCenterAtDepth.get(d - 1) || 0;
|
|
245
|
+
const prevSpan = maxMainAtDepth.get(d - 1) || 160;
|
|
246
|
+
const currSpan = maxMainAtDepth.get(d) || 160;
|
|
247
|
+
const step = hasExplicitLevel ? Math.max(explicitLevelGap, (prevSpan + currSpan) / 2 + 24) : (prevSpan + currSpan) / 2 + DEFAULT_LEVEL_EDGE_GAP;
|
|
248
|
+
mainCenterAtDepth.set(d, prevCenter + step * dir.sign);
|
|
249
|
+
}
|
|
122
250
|
const centers = /* @__PURE__ */ new Map();
|
|
123
251
|
crossOf.forEach((cross, id) => {
|
|
124
|
-
const main = (depth.get(id) || 0)
|
|
252
|
+
const main = mainCenterAtDepth.get(depth.get(id) || 0) || 0;
|
|
125
253
|
centers.set(
|
|
126
254
|
id,
|
|
127
255
|
dir.main === "x" ? { centerX: main, centerY: cross } : { centerX: cross, centerY: main }
|
|
@@ -359,6 +487,11 @@ var TOOLBAR_ICON_PATHS = {
|
|
|
359
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",
|
|
360
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",
|
|
361
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",
|
|
362
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"
|
|
363
496
|
};
|
|
364
497
|
var TOOLBAR_ACTIONS = [
|
|
@@ -435,7 +568,7 @@ var EDGE_STROKE_PRESETS = [
|
|
|
435
568
|
{ id: "medium", label: "Medium", width: DEFAULT_EDGE_STROKE_WIDTH },
|
|
436
569
|
{ id: "bold", label: "Bold", width: 3.5 }
|
|
437
570
|
];
|
|
438
|
-
var VD_FLOWCHART_VERSION = "1.
|
|
571
|
+
var VD_FLOWCHART_VERSION = "1.6.0";
|
|
439
572
|
var FLOWCHART_DOCUMENT_VERSION = "1.3.0";
|
|
440
573
|
var FLOWCHART_NODE_TYPES = [
|
|
441
574
|
"rounded-rect",
|
|
@@ -449,10 +582,92 @@ var FLOWCHART_NODE_TYPES = [
|
|
|
449
582
|
var FLOWCHART_PORTS = ["top", "right", "bottom", "left"];
|
|
450
583
|
var FLOWCHART_EDGE_MARKERS = ["none", "arrow", "dot"];
|
|
451
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"];
|
|
452
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
|
+
};
|
|
453
637
|
function normalizeKeyboardShortcuts(value) {
|
|
454
638
|
return value === "basic" ? "basic" : "mindmap";
|
|
455
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
|
+
}
|
|
456
671
|
var ARROW_DIRECTIONS = {
|
|
457
672
|
ArrowRight: "right",
|
|
458
673
|
ArrowLeft: "left",
|
|
@@ -493,6 +708,8 @@ function getShortcutRows(mode, readonly) {
|
|
|
493
708
|
"Edit the connection label"
|
|
494
709
|
],
|
|
495
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"],
|
|
496
713
|
["Alt + Arrow", "Nudge the node (add Shift for 1 px)"],
|
|
497
714
|
["Delete or Backspace", "Delete the selection"],
|
|
498
715
|
["Cmd/Ctrl + D", "Duplicate the node"],
|
|
@@ -677,10 +894,12 @@ function clampNodeHeight(type, height, fallback, sizeBounds) {
|
|
|
677
894
|
return clamp(toFiniteNumber(height, fallback), bounds.minHeight, bounds.maxHeight);
|
|
678
895
|
}
|
|
679
896
|
function isNodeResizable(nodeOrType) {
|
|
897
|
+
if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
|
|
680
898
|
const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
|
|
681
899
|
return spec.resizable !== false;
|
|
682
900
|
}
|
|
683
901
|
function isNodeTextEditable(nodeOrType) {
|
|
902
|
+
if (isPlainObject(nodeOrType) && nodeOrType.locked) return false;
|
|
684
903
|
const spec = typeof nodeOrType === "string" ? getNodeSpec(nodeOrType) : getNodeSpec(nodeOrType?.type);
|
|
685
904
|
return spec.textEditable !== false;
|
|
686
905
|
}
|
|
@@ -720,6 +939,15 @@ function normalizeNode(rawNode, index, usedIds, sizeBounds) {
|
|
|
720
939
|
data: isPlainObject(rawNode?.data) ? deepClone(rawNode.data) : {}
|
|
721
940
|
};
|
|
722
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;
|
|
723
951
|
return node;
|
|
724
952
|
}
|
|
725
953
|
function computeHiddenNodeIds(nodes, edges) {
|
|
@@ -752,6 +980,12 @@ function computeHiddenNodeIds(nodes, edges) {
|
|
|
752
980
|
return candidates;
|
|
753
981
|
}
|
|
754
982
|
function normalizeEndpoint(rawEndpoint, fallbackPort) {
|
|
983
|
+
if (typeof rawEndpoint === "string") {
|
|
984
|
+
return {
|
|
985
|
+
nodeId: sanitizeId(rawEndpoint),
|
|
986
|
+
port: fallbackPort
|
|
987
|
+
};
|
|
988
|
+
}
|
|
755
989
|
return {
|
|
756
990
|
nodeId: sanitizeId(rawEndpoint?.nodeId),
|
|
757
991
|
port: FLOWCHART_PORTS.includes(rawEndpoint?.port) ? rawEndpoint.port : fallbackPort
|
|
@@ -787,6 +1021,10 @@ function normalizeEdge(rawEdge, index, nodeIds, usedIds) {
|
|
|
787
1021
|
label: rawEdge?.label == null ? "" : String(rawEdge.label),
|
|
788
1022
|
data: isPlainObject(rawEdge?.data) ? deepClone(rawEdge.data) : {}
|
|
789
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;
|
|
790
1028
|
syncEdgeKind(edge);
|
|
791
1029
|
return edge;
|
|
792
1030
|
}
|
|
@@ -1142,10 +1380,37 @@ function getOrthogonalMidpoints(fromStub, toStub, fromPort, toPort) {
|
|
|
1142
1380
|
function getOrthogonalPoints(fromPoint, toPoint, fromPort, toPort, fromRect, toRect, metrics = routeMetrics(1)) {
|
|
1143
1381
|
const fromNormal = getPortNormal(fromPort);
|
|
1144
1382
|
const toNormal = getPortNormal(toPort);
|
|
1145
|
-
const fromStub = offsetPoint(fromPoint, fromNormal, metrics.stub);
|
|
1146
|
-
const toStub = offsetPoint(toPoint, toNormal, metrics.stub);
|
|
1147
1383
|
const sourceHorizontal = isHorizontalPort(fromPort);
|
|
1148
1384
|
const targetHorizontal = isHorizontalPort(toPort);
|
|
1385
|
+
const minStub = 4 * (metrics.scale || 1);
|
|
1386
|
+
let fromStubLen = metrics.stub;
|
|
1387
|
+
let toStubLen = metrics.stub;
|
|
1388
|
+
if (sourceHorizontal && targetHorizontal && fromNormal.x === -toNormal.x) {
|
|
1389
|
+
const span = (toPoint.x - fromPoint.x) * fromNormal.x;
|
|
1390
|
+
if (span > 0) {
|
|
1391
|
+
const fitted = Math.min(metrics.stub, span * 0.45, span / 2);
|
|
1392
|
+
fromStubLen = fitted;
|
|
1393
|
+
toStubLen = fitted;
|
|
1394
|
+
}
|
|
1395
|
+
} else if (!sourceHorizontal && !targetHorizontal && fromNormal.y === -toNormal.y) {
|
|
1396
|
+
const span = (toPoint.y - fromPoint.y) * fromNormal.y;
|
|
1397
|
+
if (span > 0) {
|
|
1398
|
+
const fitted = Math.min(metrics.stub, span * 0.45, span / 2);
|
|
1399
|
+
fromStubLen = fitted;
|
|
1400
|
+
toStubLen = fitted;
|
|
1401
|
+
}
|
|
1402
|
+
} else if (sourceHorizontal !== targetHorizontal) {
|
|
1403
|
+
const spanFrom = sourceHorizontal ? (toPoint.x - fromPoint.x) * fromNormal.x : (toPoint.y - fromPoint.y) * fromNormal.y;
|
|
1404
|
+
const spanTo = targetHorizontal ? (fromPoint.x - toPoint.x) * toNormal.x : (fromPoint.y - toPoint.y) * toNormal.y;
|
|
1405
|
+
if (spanFrom > 0 && spanFrom < metrics.stub) {
|
|
1406
|
+
fromStubLen = Math.min(spanFrom / 2, Math.max(minStub, spanFrom * 0.5));
|
|
1407
|
+
}
|
|
1408
|
+
if (spanTo > 0 && spanTo < metrics.stub) {
|
|
1409
|
+
toStubLen = Math.min(spanTo / 2, Math.max(minStub, spanTo * 0.5));
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
const fromStub = offsetPoint(fromPoint, fromNormal, fromStubLen);
|
|
1413
|
+
const toStub = offsetPoint(toPoint, toNormal, toStubLen);
|
|
1149
1414
|
const mids = [];
|
|
1150
1415
|
if (sourceHorizontal && targetHorizontal) {
|
|
1151
1416
|
const facing = fromNormal.x === -toNormal.x;
|
|
@@ -1206,19 +1471,75 @@ function buildOrthogonalPath(fromPoint, toPoint, fromPort = "right", toPort = "l
|
|
|
1206
1471
|
labelY: label.y
|
|
1207
1472
|
};
|
|
1208
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
|
+
}
|
|
1209
1497
|
function buildEdgePath(edge, fromNode = null, toNode = null) {
|
|
1210
1498
|
const fromPort = edge?.from?.port || edge?.fromPort || "right";
|
|
1211
1499
|
const toPort = edge?.to?.port || edge?.toPort || "left";
|
|
1212
|
-
const
|
|
1213
|
-
const
|
|
1500
|
+
const rawFromPoint = edge?.fromPoint || (fromNode ? getPortPosition(fromNode, fromPort) : null);
|
|
1501
|
+
const rawToPoint = edge?.toPoint || (toNode ? getPortPosition(toNode, toPort) : null);
|
|
1214
1502
|
const route = normalizeEdgeRoute(edge?.route);
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1503
|
+
const visualScale = edgeVisualScale(fromNode, toNode);
|
|
1504
|
+
const metrics = routeMetrics(visualScale);
|
|
1505
|
+
if (!rawFromPoint || !rawToPoint) {
|
|
1217
1506
|
return { d: "", labelX: 0, labelY: 0 };
|
|
1218
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);
|
|
1219
1519
|
if (route === "straight") {
|
|
1220
|
-
|
|
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);
|
|
1221
1540
|
}
|
|
1541
|
+
const fromPoint = fromRetract > 0 ? offsetPoint(rawFromPoint, getPortNormal(fromPort), fromRetract) : rawFromPoint;
|
|
1542
|
+
const toPoint = toRetract > 0 ? offsetPoint(rawToPoint, getPortNormal(toPort), toRetract) : rawToPoint;
|
|
1222
1543
|
if (route === "orthogonal") {
|
|
1223
1544
|
const fromRect = !edge?.fromPoint && fromNode ? getNodeRectBounds(fromNode, metrics.clearance) : null;
|
|
1224
1545
|
const toRect = !edge?.toPoint && toNode ? getNodeRectBounds(toNode, metrics.clearance) : null;
|
|
@@ -1226,7 +1547,7 @@ function buildEdgePath(edge, fromNode = null, toNode = null) {
|
|
|
1226
1547
|
}
|
|
1227
1548
|
return buildCurvePath(fromPoint, toPoint, fromPort, toPort, metrics);
|
|
1228
1549
|
}
|
|
1229
|
-
function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
|
|
1550
|
+
function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
|
|
1230
1551
|
const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
|
|
1231
1552
|
const effective = Math.max(0.02, strokeWidth * scale);
|
|
1232
1553
|
const size = formatNumber(Math.max(9 * scale, effective * 4.4));
|
|
@@ -1243,12 +1564,12 @@ function createArrowMarker(id, strokeWidth, reversed = false, edgeScale = 1) {
|
|
|
1243
1564
|
marker.appendChild(
|
|
1244
1565
|
svgEl("path", {
|
|
1245
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`,
|
|
1246
|
-
fill
|
|
1567
|
+
fill
|
|
1247
1568
|
})
|
|
1248
1569
|
);
|
|
1249
1570
|
return marker;
|
|
1250
1571
|
}
|
|
1251
|
-
function createDotMarker(id, strokeWidth, edgeScale = 1) {
|
|
1572
|
+
function createDotMarker(id, strokeWidth, edgeScale = 1, fill = "var(--vd-flowchart-accent)") {
|
|
1252
1573
|
const scale = clamp(toFiniteNumber(edgeScale, 1), 0.01, 1);
|
|
1253
1574
|
const effective = Math.max(0.02, strokeWidth * scale);
|
|
1254
1575
|
const size = formatNumber(Math.max(8 * scale, effective * 3.3));
|
|
@@ -1267,7 +1588,7 @@ function createDotMarker(id, strokeWidth, edgeScale = 1) {
|
|
|
1267
1588
|
cx: formatNumber(size / 2),
|
|
1268
1589
|
cy: formatNumber(size / 2),
|
|
1269
1590
|
r: radius,
|
|
1270
|
-
fill
|
|
1591
|
+
fill
|
|
1271
1592
|
})
|
|
1272
1593
|
);
|
|
1273
1594
|
return marker;
|
|
@@ -1556,6 +1877,7 @@ var VdFlowchart = class {
|
|
|
1556
1877
|
this.minimapFrame = 0;
|
|
1557
1878
|
this.minimapDrag = null;
|
|
1558
1879
|
this.shortcutsHelpOpen = false;
|
|
1880
|
+
this.colorPopoverOpen = false;
|
|
1559
1881
|
this.autoFit = Boolean(options.autoFit);
|
|
1560
1882
|
this.readyEmitted = false;
|
|
1561
1883
|
this.resizeObserver = null;
|
|
@@ -1568,11 +1890,14 @@ var VdFlowchart = class {
|
|
|
1568
1890
|
this.handleClick = this.handleClick.bind(this);
|
|
1569
1891
|
this.handleDoubleClick = this.handleDoubleClick.bind(this);
|
|
1570
1892
|
this.handleWheel = this.handleWheel.bind(this);
|
|
1893
|
+
this.handleCanvasBlur = this.handleCanvasBlur.bind(this);
|
|
1571
1894
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
1572
1895
|
this.handleSelectionFieldInput = this.handleSelectionFieldInput.bind(this);
|
|
1573
1896
|
this.handleSelectionFieldChange = this.handleSelectionFieldChange.bind(this);
|
|
1897
|
+
this.handleSelectionActionClick = this.handleSelectionActionClick.bind(this);
|
|
1574
1898
|
this.handleJsonActionClick = this.handleJsonActionClick.bind(this);
|
|
1575
1899
|
this.handleResize = this.handleResize.bind(this);
|
|
1900
|
+
this.handleOutsidePointerDown = this.handleOutsidePointerDown.bind(this);
|
|
1576
1901
|
this.buildShell();
|
|
1577
1902
|
this.bindEvents();
|
|
1578
1903
|
this.render();
|
|
@@ -1656,6 +1981,32 @@ var VdFlowchart = class {
|
|
|
1656
1981
|
this.arrangeSelect.appendChild(option);
|
|
1657
1982
|
});
|
|
1658
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);
|
|
1659
2010
|
this.clearButton = createToolbarButton({
|
|
1660
2011
|
action: "clear",
|
|
1661
2012
|
label: "Clear canvas",
|
|
@@ -1682,6 +2033,7 @@ var VdFlowchart = class {
|
|
|
1682
2033
|
});
|
|
1683
2034
|
this.minimapButton.setAttribute("aria-pressed", this.minimapEnabled ? "true" : "false");
|
|
1684
2035
|
toolbarLeft.appendChild(this.arrangeSelect);
|
|
2036
|
+
toolbarLeft.appendChild(this.colorPopoverWrap);
|
|
1685
2037
|
toolbarLeft.appendChild(this.clearButton);
|
|
1686
2038
|
toolbarRight.appendChild(this.minimapButton);
|
|
1687
2039
|
toolbarRight.appendChild(this.shortcutsButton);
|
|
@@ -1972,6 +2324,7 @@ var VdFlowchart = class {
|
|
|
1972
2324
|
this.deleteButton.addEventListener("click", () => this.deleteSelection());
|
|
1973
2325
|
this.selectionFields.addEventListener("input", this.handleSelectionFieldInput);
|
|
1974
2326
|
this.selectionFields.addEventListener("change", this.handleSelectionFieldChange);
|
|
2327
|
+
this.selectionFields.addEventListener("click", this.handleSelectionActionClick);
|
|
1975
2328
|
this.jsonActions.addEventListener("click", this.handleJsonActionClick);
|
|
1976
2329
|
this.canvasEl.addEventListener("pointerdown", this.handlePointerDown);
|
|
1977
2330
|
this.canvasEl.addEventListener("pointermove", this.handlePointerMove);
|
|
@@ -1980,8 +2333,10 @@ var VdFlowchart = class {
|
|
|
1980
2333
|
this.canvasEl.addEventListener("click", this.handleClick);
|
|
1981
2334
|
this.canvasEl.addEventListener("dblclick", this.handleDoubleClick);
|
|
1982
2335
|
this.canvasEl.addEventListener("wheel", this.handleWheel, { passive: false });
|
|
2336
|
+
this.canvasEl.addEventListener("blur", this.handleCanvasBlur);
|
|
1983
2337
|
this.root.addEventListener("keydown", this.handleKeyDown, true);
|
|
1984
2338
|
window.addEventListener("pointerup", this.handlePointerUp);
|
|
2339
|
+
window.addEventListener("pointerdown", this.handleOutsidePointerDown);
|
|
1985
2340
|
window.addEventListener("resize", this.handleResize);
|
|
1986
2341
|
}
|
|
1987
2342
|
unbindEvents() {
|
|
@@ -1990,6 +2345,7 @@ var VdFlowchart = class {
|
|
|
1990
2345
|
this.paletteGrid.removeEventListener("click", this.handlePaletteClick);
|
|
1991
2346
|
this.selectionFields.removeEventListener("input", this.handleSelectionFieldInput);
|
|
1992
2347
|
this.selectionFields.removeEventListener("change", this.handleSelectionFieldChange);
|
|
2348
|
+
this.selectionFields.removeEventListener("click", this.handleSelectionActionClick);
|
|
1993
2349
|
this.jsonActions.removeEventListener("click", this.handleJsonActionClick);
|
|
1994
2350
|
this.canvasEl.removeEventListener("pointerdown", this.handlePointerDown);
|
|
1995
2351
|
this.canvasEl.removeEventListener("pointermove", this.handlePointerMove);
|
|
@@ -1998,14 +2354,34 @@ var VdFlowchart = class {
|
|
|
1998
2354
|
this.canvasEl.removeEventListener("click", this.handleClick);
|
|
1999
2355
|
this.canvasEl.removeEventListener("dblclick", this.handleDoubleClick);
|
|
2000
2356
|
this.canvasEl.removeEventListener("wheel", this.handleWheel);
|
|
2357
|
+
this.canvasEl.removeEventListener("blur", this.handleCanvasBlur);
|
|
2001
2358
|
this.root.removeEventListener("keydown", this.handleKeyDown, true);
|
|
2002
2359
|
window.removeEventListener("pointerup", this.handlePointerUp);
|
|
2360
|
+
window.removeEventListener("pointerdown", this.handleOutsidePointerDown);
|
|
2003
2361
|
window.removeEventListener("resize", this.handleResize);
|
|
2004
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
|
+
}
|
|
2005
2368
|
handleResize() {
|
|
2006
2369
|
if (this.destroyed) return;
|
|
2007
2370
|
this.render({ inspector: false, json: false });
|
|
2008
2371
|
}
|
|
2372
|
+
/**
|
|
2373
|
+
* Focus the diagram canvas. Quiet focus returns from an inline editor without
|
|
2374
|
+
* painting the full-canvas `:focus-visible` ring (see `.is-quiet-focus`).
|
|
2375
|
+
*/
|
|
2376
|
+
focusCanvas(options = {}) {
|
|
2377
|
+
if (!this.canvasEl || this.destroyed) return;
|
|
2378
|
+
const quiet = options.quiet === true;
|
|
2379
|
+
this.canvasEl.classList.toggle("is-quiet-focus", quiet);
|
|
2380
|
+
this.canvasEl.focus({ preventScroll: true });
|
|
2381
|
+
}
|
|
2382
|
+
handleCanvasBlur() {
|
|
2383
|
+
this.canvasEl?.classList.remove("is-quiet-focus");
|
|
2384
|
+
}
|
|
2009
2385
|
updatePaletteState() {
|
|
2010
2386
|
const arrowArmed = this.activeTool === "arrow";
|
|
2011
2387
|
this.paletteGrid.querySelectorAll(".vd-flowchart-palette-btn").forEach((button) => {
|
|
@@ -2027,7 +2403,24 @@ var VdFlowchart = class {
|
|
|
2027
2403
|
this.updatePaletteState();
|
|
2028
2404
|
this.render({ scene: true, inspector: false, json: false });
|
|
2029
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
|
+
}
|
|
2030
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
|
+
}
|
|
2031
2424
|
const actionButton = event.target.closest("[data-flowchart-action]");
|
|
2032
2425
|
if (!actionButton) return;
|
|
2033
2426
|
const action = actionButton.getAttribute("data-flowchart-action");
|
|
@@ -2037,6 +2430,7 @@ var VdFlowchart = class {
|
|
|
2037
2430
|
if (action === "fit-view") this.fitView();
|
|
2038
2431
|
if (action === "undo") this.undo();
|
|
2039
2432
|
if (action === "redo") this.redo();
|
|
2433
|
+
if (action === "color-popover") this.toggleColorPopover();
|
|
2040
2434
|
if (action === "clear" && !this.readonly) this.clear();
|
|
2041
2435
|
if (action === "shortcuts") this.toggleShortcutsHelp();
|
|
2042
2436
|
if (action === "minimap") this.setMinimapEnabled(!this.minimapEnabled);
|
|
@@ -2099,16 +2493,18 @@ var VdFlowchart = class {
|
|
|
2099
2493
|
nodes.forEach((node) => {
|
|
2100
2494
|
const point = map(node.x, node.y);
|
|
2101
2495
|
const selected = this.isNodeSelected(node.id);
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
);
|
|
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);
|
|
2112
2508
|
});
|
|
2113
2509
|
const corner = map(view.left, view.top);
|
|
2114
2510
|
this.minimapSvg.appendChild(
|
|
@@ -2230,6 +2626,42 @@ var VdFlowchart = class {
|
|
|
2230
2626
|
}
|
|
2231
2627
|
}
|
|
2232
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
|
+
}
|
|
2233
2665
|
handleSelectionFieldInput(event) {
|
|
2234
2666
|
const field = event.target.getAttribute("data-field");
|
|
2235
2667
|
if (!field) return;
|
|
@@ -2252,6 +2684,38 @@ var VdFlowchart = class {
|
|
|
2252
2684
|
if (field === "node-width" || field === "node-height") {
|
|
2253
2685
|
const patch = field === "node-width" ? { width: toFiniteNumber(event.target.value, void 0) } : { height: toFiniteNumber(event.target.value, void 0) };
|
|
2254
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
|
+
);
|
|
2255
2719
|
}
|
|
2256
2720
|
}
|
|
2257
2721
|
handleSelectionFieldChange(event) {
|
|
@@ -2295,6 +2759,14 @@ var VdFlowchart = class {
|
|
|
2295
2759
|
{ strokeWidth: getStrokePresetWidth(event.target.value) },
|
|
2296
2760
|
{ inspector: true, reason: "edge:update" }
|
|
2297
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
|
+
);
|
|
2298
2770
|
}
|
|
2299
2771
|
}
|
|
2300
2772
|
// Keys the editor consumes stop here, so page-level shortcuts (a docs
|
|
@@ -2317,6 +2789,11 @@ var VdFlowchart = class {
|
|
|
2317
2789
|
this.toggleShortcutsHelp(false);
|
|
2318
2790
|
return;
|
|
2319
2791
|
}
|
|
2792
|
+
if (key === "Escape" && this.colorPopoverOpen) {
|
|
2793
|
+
event.preventDefault();
|
|
2794
|
+
this.toggleColorPopover(false);
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2320
2797
|
if (target === this.canvasEl && this.handleCanvasKeyDown(event)) {
|
|
2321
2798
|
event.preventDefault();
|
|
2322
2799
|
return;
|
|
@@ -2339,6 +2816,29 @@ var VdFlowchart = class {
|
|
|
2339
2816
|
}
|
|
2340
2817
|
return;
|
|
2341
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
|
+
}
|
|
2342
2842
|
if (modKey && (event.key === "z" || event.key === "Z")) {
|
|
2343
2843
|
event.preventDefault();
|
|
2344
2844
|
if (event.shiftKey) {
|
|
@@ -2521,7 +3021,7 @@ var VdFlowchart = class {
|
|
|
2521
3021
|
nudgeNodes(nodeIds, direction, distance) {
|
|
2522
3022
|
const step = { right: [1, 0], left: [-1, 0], down: [0, 1], up: [0, -1] }[direction];
|
|
2523
3023
|
if (this.readonly || !step) return [];
|
|
2524
|
-
const nodes = nodeIds.map((id) => this.findNode(id)).filter(
|
|
3024
|
+
const nodes = nodeIds.map((id) => this.findNode(id)).filter((node) => node && !node.locked);
|
|
2525
3025
|
if (!nodes.length) return [];
|
|
2526
3026
|
nodes.forEach((node) => {
|
|
2527
3027
|
node.x = formatNumber(node.x + step[0] * distance);
|
|
@@ -2660,6 +3160,14 @@ var VdFlowchart = class {
|
|
|
2660
3160
|
this.emitChange("edge:add", { edge: deepClone(edge) });
|
|
2661
3161
|
return true;
|
|
2662
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
|
+
}
|
|
2663
3171
|
cutSelection() {
|
|
2664
3172
|
if (!this.copySelection()) return false;
|
|
2665
3173
|
return this.deleteSelection();
|
|
@@ -2697,6 +3205,9 @@ var VdFlowchart = class {
|
|
|
2697
3205
|
}
|
|
2698
3206
|
handlePointerDown(event) {
|
|
2699
3207
|
if (this.destroyed || event.button != null && event.button !== 0) return;
|
|
3208
|
+
if (this.colorPopoverOpen) {
|
|
3209
|
+
this.toggleColorPopover(false);
|
|
3210
|
+
}
|
|
2700
3211
|
if (this.textEditor && !event.target.closest(".vd-flowchart-text-editor")) {
|
|
2701
3212
|
this.stopTextEdit({ commit: true });
|
|
2702
3213
|
}
|
|
@@ -2721,6 +3232,8 @@ var VdFlowchart = class {
|
|
|
2721
3232
|
const fromNode = this.findNode(edge.from.nodeId);
|
|
2722
3233
|
const toNode = this.findNode(edge.to.nodeId);
|
|
2723
3234
|
if (!fromNode || !toNode) return;
|
|
3235
|
+
const endpointNode = endpoint === "from" ? fromNode : toNode;
|
|
3236
|
+
if (endpointNode.locked) return;
|
|
2724
3237
|
this.reconnectEdgeId = edgeId;
|
|
2725
3238
|
this.select({ kind: "edge", id: edgeId });
|
|
2726
3239
|
this.interaction = {
|
|
@@ -2771,7 +3284,7 @@ var VdFlowchart = class {
|
|
|
2771
3284
|
const nodeId = portTarget.getAttribute("data-node-id");
|
|
2772
3285
|
const port = portTarget.getAttribute("data-port");
|
|
2773
3286
|
const node = this.findNode(nodeId);
|
|
2774
|
-
if (!node) return;
|
|
3287
|
+
if (!node || node.locked) return;
|
|
2775
3288
|
const sourcePoint = getPortPosition(node, port);
|
|
2776
3289
|
this.interaction = {
|
|
2777
3290
|
kind: "connect",
|
|
@@ -2800,7 +3313,7 @@ var VdFlowchart = class {
|
|
|
2800
3313
|
const nodeId = resizeTarget.getAttribute("data-node-id");
|
|
2801
3314
|
const handle = resizeTarget.getAttribute("data-resize-handle");
|
|
2802
3315
|
const node = this.findNode(nodeId);
|
|
2803
|
-
if (!node || !RESIZE_HANDLES.includes(handle)) return;
|
|
3316
|
+
if (!node || !isNodeResizable(node) || !RESIZE_HANDLES.includes(handle)) return;
|
|
2804
3317
|
this.select({ kind: "node", id: nodeId });
|
|
2805
3318
|
this.interaction = {
|
|
2806
3319
|
kind: "resize-node",
|
|
@@ -2833,8 +3346,11 @@ var VdFlowchart = class {
|
|
|
2833
3346
|
if (groupIds.length > 1) this.selectNodes(groupIds, { primary: nodeId });
|
|
2834
3347
|
else this.select({ kind: "node", id: nodeId });
|
|
2835
3348
|
if (!this.readonly) {
|
|
2836
|
-
|
|
2837
|
-
|
|
3349
|
+
const drag = this.createDragInteraction(event, nodeId, groupIds);
|
|
3350
|
+
if (drag) {
|
|
3351
|
+
this.interaction = drag;
|
|
3352
|
+
this.capturePointer(event.pointerId);
|
|
3353
|
+
}
|
|
2838
3354
|
}
|
|
2839
3355
|
return;
|
|
2840
3356
|
}
|
|
@@ -2865,12 +3381,13 @@ var VdFlowchart = class {
|
|
|
2865
3381
|
event.preventDefault();
|
|
2866
3382
|
}
|
|
2867
3383
|
createDragInteraction(event, nodeId, nodeIds) {
|
|
2868
|
-
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;
|
|
2869
3386
|
const moving = new Set(nodes.map((node) => node.id));
|
|
2870
3387
|
return {
|
|
2871
3388
|
kind: "drag-node",
|
|
2872
3389
|
pointerId: event.pointerId,
|
|
2873
|
-
nodeId,
|
|
3390
|
+
nodeId: moving.has(nodeId) ? nodeId : nodes[0].id,
|
|
2874
3391
|
nodeIds: nodes.map((node) => node.id),
|
|
2875
3392
|
startWorld: this.clientToWorld(event.clientX, event.clientY),
|
|
2876
3393
|
origins: new Map(nodes.map((node) => [node.id, { x: node.x, y: node.y }])),
|
|
@@ -3222,15 +3739,16 @@ var VdFlowchart = class {
|
|
|
3222
3739
|
if (this.activeTool === "arrow") return true;
|
|
3223
3740
|
return this.selection?.kind === "node" && this.selection.id === node.id && !this.hasMultiSelection();
|
|
3224
3741
|
}
|
|
3225
|
-
getMarkerId(markerType, position, strokeWidth, edgeScale = 1) {
|
|
3742
|
+
getMarkerId(markerType, position, strokeWidth, edgeScale = 1, color = "") {
|
|
3226
3743
|
const width = normalizeEdgeStrokeWidth(strokeWidth);
|
|
3227
3744
|
const scale = clamp(formatNumber(Math.max(edgeScale, 0.01)), 0.01, 1);
|
|
3228
|
-
const
|
|
3745
|
+
const fill = resolveEdgeColorValue(color);
|
|
3746
|
+
const key = `${markerType}:${position}:${width}:${scale}:${fill}`;
|
|
3229
3747
|
if (this.markerIds.has(key)) {
|
|
3230
3748
|
return this.markerIds.get(key);
|
|
3231
3749
|
}
|
|
3232
3750
|
const markerId = nextId(`flowchart-${markerType}-${position}`);
|
|
3233
|
-
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);
|
|
3234
3752
|
this.markerDefs.appendChild(marker);
|
|
3235
3753
|
this.markerIds.set(key, markerId);
|
|
3236
3754
|
return markerId;
|
|
@@ -3252,7 +3770,7 @@ var VdFlowchart = class {
|
|
|
3252
3770
|
const snapPadding = CONNECTION_SNAP_PADDING / this.documentData.viewport.scale;
|
|
3253
3771
|
const hysteresisMargin = CONNECTION_HYSTERESIS / this.documentData.viewport.scale;
|
|
3254
3772
|
const best = this.getVisibleNodes().reduce((candidate, node) => {
|
|
3255
|
-
if (node.id === excludeNodeId) return candidate;
|
|
3773
|
+
if (node.id === excludeNodeId || node.locked) return candidate;
|
|
3256
3774
|
const distanceToBounds2 = getDistanceToNodeBounds(node, worldPoint);
|
|
3257
3775
|
if (distanceToBounds2 > snapPadding) return candidate;
|
|
3258
3776
|
const nearest = pickPortForNode(node, worldPoint, referencePoint);
|
|
@@ -3270,7 +3788,7 @@ var VdFlowchart = class {
|
|
|
3270
3788
|
}, null);
|
|
3271
3789
|
if (!previousSnap || !best) return best;
|
|
3272
3790
|
const previousNode = this.findNode(previousSnap.nodeId);
|
|
3273
|
-
if (!previousNode || previousNode.id === excludeNodeId) return best;
|
|
3791
|
+
if (!previousNode || previousNode.id === excludeNodeId || previousNode.locked) return best;
|
|
3274
3792
|
const distanceToBounds = getDistanceToNodeBounds(previousNode, worldPoint);
|
|
3275
3793
|
if (distanceToBounds > snapPadding) return best;
|
|
3276
3794
|
if (best.node.id === previousSnap.nodeId && best.port === previousSnap.port) {
|
|
@@ -3461,7 +3979,7 @@ var VdFlowchart = class {
|
|
|
3461
3979
|
if (event.key === "Escape" || event.key === "Enter") {
|
|
3462
3980
|
event.preventDefault();
|
|
3463
3981
|
this.stopTextEdit({ commit: event.key === "Enter" });
|
|
3464
|
-
this.
|
|
3982
|
+
this.focusCanvas({ quiet: true });
|
|
3465
3983
|
}
|
|
3466
3984
|
});
|
|
3467
3985
|
textarea.addEventListener("blur", () => {
|
|
@@ -3488,7 +4006,7 @@ var VdFlowchart = class {
|
|
|
3488
4006
|
if (event.key === "Escape") {
|
|
3489
4007
|
event.preventDefault();
|
|
3490
4008
|
this.stopTextEdit({ commit: false });
|
|
3491
|
-
this.
|
|
4009
|
+
this.focusCanvas({ quiet: true });
|
|
3492
4010
|
return;
|
|
3493
4011
|
}
|
|
3494
4012
|
if (event.key === "Enter") {
|
|
@@ -3497,13 +4015,12 @@ var VdFlowchart = class {
|
|
|
3497
4015
|
if (!commits) return;
|
|
3498
4016
|
event.preventDefault();
|
|
3499
4017
|
this.stopTextEdit({ commit: true });
|
|
3500
|
-
this.
|
|
4018
|
+
this.focusCanvas({ quiet: true });
|
|
3501
4019
|
return;
|
|
3502
4020
|
}
|
|
3503
4021
|
if (event.key === "Tab" && mindmap && !event.shiftKey && !event.altKey && !event.ctrlKey) {
|
|
3504
4022
|
event.preventDefault();
|
|
3505
4023
|
this.stopTextEdit({ commit: true });
|
|
3506
|
-
this.canvasEl.focus();
|
|
3507
4024
|
this.insertBranchNode(node.id, { edit: true });
|
|
3508
4025
|
}
|
|
3509
4026
|
}
|
|
@@ -3686,16 +4203,17 @@ var VdFlowchart = class {
|
|
|
3686
4203
|
}
|
|
3687
4204
|
applyEdgeMarkers(pathElement, edge, edgeScale = 1) {
|
|
3688
4205
|
const width = this.getEdgeStrokeWidth(edge);
|
|
4206
|
+
const color = edge.color || "";
|
|
3689
4207
|
if (edge.startMarker && edge.startMarker !== "none") {
|
|
3690
4208
|
pathElement.setAttribute(
|
|
3691
4209
|
"marker-start",
|
|
3692
|
-
`url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale)})`
|
|
4210
|
+
`url(#${this.getMarkerId(edge.startMarker, "start", width, edgeScale, color)})`
|
|
3693
4211
|
);
|
|
3694
4212
|
}
|
|
3695
4213
|
if (edge.endMarker && edge.endMarker !== "none") {
|
|
3696
4214
|
pathElement.setAttribute(
|
|
3697
4215
|
"marker-end",
|
|
3698
|
-
`url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale)})`
|
|
4216
|
+
`url(#${this.getMarkerId(edge.endMarker, "end", width, edgeScale, color)})`
|
|
3699
4217
|
);
|
|
3700
4218
|
}
|
|
3701
4219
|
}
|
|
@@ -3707,10 +4225,19 @@ var VdFlowchart = class {
|
|
|
3707
4225
|
const edgePath = buildEdgePath(edge, fromNode, toNode);
|
|
3708
4226
|
const selected = this.selection?.kind === "edge" && this.selection.id === edge.id;
|
|
3709
4227
|
const inReconnectMode = this.reconnectEdgeId === edge.id;
|
|
4228
|
+
const strokeStyle = normalizeEdgeStrokeStyle(edge.strokeStyle);
|
|
4229
|
+
const strokeClass = strokeStyle !== "solid" ? ` is-stroke-${strokeStyle}` : "";
|
|
3710
4230
|
const group = svgEl("g", {
|
|
3711
|
-
class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}`,
|
|
4231
|
+
class: `vd-flowchart-edge${selected ? " is-selected" : ""}${inReconnectMode ? " is-reconnecting" : ""}${strokeClass}`,
|
|
3712
4232
|
"data-edge-id": edge.id
|
|
3713
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
|
+
}
|
|
3714
4241
|
const baseStroke = this.getEdgeStrokeWidth(edge);
|
|
3715
4242
|
const strokeWidth = visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke;
|
|
3716
4243
|
if (selected) {
|
|
@@ -3728,6 +4255,20 @@ var VdFlowchart = class {
|
|
|
3728
4255
|
"stroke-width": strokeWidth,
|
|
3729
4256
|
"data-edge-id": edge.id
|
|
3730
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
|
+
}
|
|
3731
4272
|
this.applyEdgeMarkers(visiblePath, edge, visual);
|
|
3732
4273
|
const hitPath = svgEl("path", {
|
|
3733
4274
|
class: "vd-flowchart-edge-hit",
|
|
@@ -3810,6 +4351,36 @@ var VdFlowchart = class {
|
|
|
3810
4351
|
"stroke-width": visual < 0.999 ? formatNumber(Math.max(0.02, baseStroke * visual)) : baseStroke
|
|
3811
4352
|
});
|
|
3812
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
|
+
}
|
|
3813
4384
|
renderNode(node) {
|
|
3814
4385
|
const selected = this.isNodeSelected(node.id);
|
|
3815
4386
|
const soloSelected = selected && !this.hasMultiSelection();
|
|
@@ -3817,10 +4388,13 @@ var VdFlowchart = class {
|
|
|
3817
4388
|
const resizing = this.interaction?.kind === "resize-node" && this.interaction.nodeId === node.id;
|
|
3818
4389
|
const editing = this.textEditor?.nodeId === node.id;
|
|
3819
4390
|
const group = svgEl("g", {
|
|
3820
|
-
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" : ""}`,
|
|
3821
4392
|
transform: `translate(${formatNumber(node.x)} ${formatNumber(node.y)})`,
|
|
3822
4393
|
"data-node-id": node.id
|
|
3823
4394
|
});
|
|
4395
|
+
if (node.color) {
|
|
4396
|
+
group.setAttribute("data-color", node.color);
|
|
4397
|
+
}
|
|
3824
4398
|
const portsVisible = this.shouldShowNodePorts(node);
|
|
3825
4399
|
const visual = nodeVisualScale(node);
|
|
3826
4400
|
const corner = node.type === "rounded-rect" || node.type === "textbox" ? 16 : node.type === "junction" ? node.width / 2 : 6;
|
|
@@ -3836,8 +4410,15 @@ var VdFlowchart = class {
|
|
|
3836
4410
|
group.appendChild(hitbox);
|
|
3837
4411
|
const shape = this.renderNodeShape(node);
|
|
3838
4412
|
this.applyScaledNodeShape(node, shape);
|
|
4413
|
+
if (node.fill) shape.style.fill = node.fill;
|
|
4414
|
+
if (node.stroke) shape.style.stroke = node.stroke;
|
|
3839
4415
|
group.appendChild(shape);
|
|
3840
|
-
|
|
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
|
+
}
|
|
3841
4422
|
const scale = this.documentData.viewport.scale || 1;
|
|
3842
4423
|
if (soloSelected && !this.readonly && SELECTION_BOX_TYPES.has(node.type)) {
|
|
3843
4424
|
const outset = SELECTION_OUTSET / scale;
|
|
@@ -4157,6 +4738,127 @@ var VdFlowchart = class {
|
|
|
4157
4738
|
});
|
|
4158
4739
|
return textElement;
|
|
4159
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
|
+
}
|
|
4160
4862
|
renderSelectionPanel() {
|
|
4161
4863
|
clearChildren(this.selectionFields);
|
|
4162
4864
|
this.deleteButton.disabled = this.readonly || !this.selection;
|
|
@@ -4171,6 +4873,11 @@ var VdFlowchart = class {
|
|
|
4171
4873
|
return;
|
|
4172
4874
|
}
|
|
4173
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" : "";
|
|
4174
4881
|
this.selectionMeta.textContent = `${this.selectedNodeIds.size} nodes selected`;
|
|
4175
4882
|
this.selectionFields.appendChild(
|
|
4176
4883
|
createElement("p", {
|
|
@@ -4178,6 +4885,22 @@ var VdFlowchart = class {
|
|
|
4178
4885
|
text: "Drag, nudge with Alt+Arrow, copy, duplicate, or delete them together."
|
|
4179
4886
|
})
|
|
4180
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
|
+
);
|
|
4181
4904
|
return;
|
|
4182
4905
|
}
|
|
4183
4906
|
if (this.selection.kind === "node") {
|
|
@@ -4187,8 +4910,10 @@ var VdFlowchart = class {
|
|
|
4187
4910
|
this.renderSelectionPanel();
|
|
4188
4911
|
return;
|
|
4189
4912
|
}
|
|
4190
|
-
|
|
4191
|
-
|
|
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 });
|
|
4192
4917
|
typeSelect.setAttribute("data-field", "node-type");
|
|
4193
4918
|
FLOWCHART_NODE_TYPES.forEach((type) => {
|
|
4194
4919
|
const option = createElement("option", { value: type, text: type.replace("-", " ") });
|
|
@@ -4196,13 +4921,25 @@ var VdFlowchart = class {
|
|
|
4196
4921
|
option.selected = type === node.type;
|
|
4197
4922
|
typeSelect.appendChild(option);
|
|
4198
4923
|
});
|
|
4199
|
-
const textArea = createElement("textarea", {
|
|
4924
|
+
const textArea = createElement("textarea", {
|
|
4925
|
+
value: node.text,
|
|
4926
|
+
rows: 5,
|
|
4927
|
+
disabled: this.readonly || isLocked
|
|
4928
|
+
});
|
|
4200
4929
|
textArea.setAttribute("data-field", "node-text");
|
|
4201
|
-
const widthInput = createElement("input", {
|
|
4930
|
+
const widthInput = createElement("input", {
|
|
4931
|
+
value: node.width,
|
|
4932
|
+
type: "number",
|
|
4933
|
+
disabled: this.readonly || isLocked
|
|
4934
|
+
});
|
|
4202
4935
|
widthInput.setAttribute("data-field", "node-width");
|
|
4203
4936
|
widthInput.setAttribute("min", String(this.minNodeSize));
|
|
4204
4937
|
widthInput.setAttribute("max", String(this.maxNodeSize));
|
|
4205
|
-
const heightInput = createElement("input", {
|
|
4938
|
+
const heightInput = createElement("input", {
|
|
4939
|
+
value: node.height,
|
|
4940
|
+
type: "number",
|
|
4941
|
+
disabled: this.readonly || isLocked
|
|
4942
|
+
});
|
|
4206
4943
|
heightInput.setAttribute("data-field", "node-height");
|
|
4207
4944
|
heightInput.setAttribute("min", String(this.minNodeSize));
|
|
4208
4945
|
heightInput.setAttribute("max", String(this.maxNodeSize));
|
|
@@ -4223,6 +4960,48 @@ var VdFlowchart = class {
|
|
|
4223
4960
|
})
|
|
4224
4961
|
);
|
|
4225
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
|
+
);
|
|
4226
5005
|
return;
|
|
4227
5006
|
}
|
|
4228
5007
|
const edge = this.findEdge(this.selection.id);
|
|
@@ -4231,8 +5010,9 @@ var VdFlowchart = class {
|
|
|
4231
5010
|
this.renderSelectionPanel();
|
|
4232
5011
|
return;
|
|
4233
5012
|
}
|
|
5013
|
+
const edgeStyleName = normalizeEdgeStrokeStyle(edge.strokeStyle);
|
|
4234
5014
|
this.selectionMeta.textContent = `Edge ${edge.id} \xB7 ${edge.route} \xB7 ${formatNumber(edge.strokeWidth)}px \xB7 ${edge.startMarker} \u2192 ${edge.endMarker}`;
|
|
4235
|
-
const routeSelect = createElement("select");
|
|
5015
|
+
const routeSelect = createElement("select", { disabled: this.readonly });
|
|
4236
5016
|
routeSelect.setAttribute("data-field", "edge-route");
|
|
4237
5017
|
FLOWCHART_EDGE_ROUTES.forEach((route) => {
|
|
4238
5018
|
const option = createElement("option", {
|
|
@@ -4243,7 +5023,7 @@ var VdFlowchart = class {
|
|
|
4243
5023
|
option.selected = route === edge.route;
|
|
4244
5024
|
routeSelect.appendChild(option);
|
|
4245
5025
|
});
|
|
4246
|
-
const startSelect = createElement("select");
|
|
5026
|
+
const startSelect = createElement("select", { disabled: this.readonly });
|
|
4247
5027
|
startSelect.setAttribute("data-field", "edge-start-marker");
|
|
4248
5028
|
FLOWCHART_EDGE_MARKERS.forEach((marker) => {
|
|
4249
5029
|
const option = createElement("option", { value: marker, text: marker });
|
|
@@ -4251,7 +5031,7 @@ var VdFlowchart = class {
|
|
|
4251
5031
|
option.selected = marker === edge.startMarker;
|
|
4252
5032
|
startSelect.appendChild(option);
|
|
4253
5033
|
});
|
|
4254
|
-
const endSelect = createElement("select");
|
|
5034
|
+
const endSelect = createElement("select", { disabled: this.readonly });
|
|
4255
5035
|
endSelect.setAttribute("data-field", "edge-end-marker");
|
|
4256
5036
|
FLOWCHART_EDGE_MARKERS.forEach((marker) => {
|
|
4257
5037
|
const option = createElement("option", { value: marker, text: marker });
|
|
@@ -4259,7 +5039,7 @@ var VdFlowchart = class {
|
|
|
4259
5039
|
option.selected = marker === edge.endMarker;
|
|
4260
5040
|
endSelect.appendChild(option);
|
|
4261
5041
|
});
|
|
4262
|
-
const widthSelect = createElement("select");
|
|
5042
|
+
const widthSelect = createElement("select", { disabled: this.readonly });
|
|
4263
5043
|
widthSelect.setAttribute("data-field", "edge-stroke-preset");
|
|
4264
5044
|
EDGE_STROKE_PRESETS.forEach((preset) => {
|
|
4265
5045
|
const option = createElement("option", { value: preset.id, text: preset.label });
|
|
@@ -4267,15 +5047,52 @@ var VdFlowchart = class {
|
|
|
4267
5047
|
option.selected = preset.id === getStrokePresetId(edge.strokeWidth);
|
|
4268
5048
|
widthSelect.appendChild(option);
|
|
4269
5049
|
});
|
|
4270
|
-
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
|
+
});
|
|
4271
5066
|
labelInput.setAttribute("data-field", "edge-label");
|
|
4272
5067
|
const markerGrid = createElement("div", { className: "vd-flowchart-field-grid" });
|
|
4273
5068
|
markerGrid.appendChild(createField("Route", routeSelect));
|
|
4274
5069
|
markerGrid.appendChild(createField("Weight", widthSelect));
|
|
5070
|
+
markerGrid.appendChild(createField("Style", strokeStyleSelect));
|
|
4275
5071
|
markerGrid.appendChild(createField("Start", startSelect));
|
|
4276
5072
|
markerGrid.appendChild(createField("End", endSelect));
|
|
4277
5073
|
this.selectionFields.appendChild(markerGrid);
|
|
4278
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
|
+
);
|
|
4279
5096
|
}
|
|
4280
5097
|
syncJsonTextarea(force = false) {
|
|
4281
5098
|
if (!force && document.activeElement === this.jsonTextarea) {
|
|
@@ -4681,7 +5498,14 @@ var VdFlowchart = class {
|
|
|
4681
5498
|
// the parent's box shape, falling back to a rounded step.
|
|
4682
5499
|
getBranchTemplate(parent, sibling) {
|
|
4683
5500
|
const source = sibling || (["rounded-rect", "rect", "textbox"].includes(parent.type) ? parent : null) || null;
|
|
4684
|
-
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
|
+
}
|
|
4685
5509
|
const spec = DEFAULT_NODE_SPECS["rounded-rect"];
|
|
4686
5510
|
return { type: "rounded-rect", width: spec.width, height: spec.height };
|
|
4687
5511
|
}
|
|
@@ -4717,7 +5541,9 @@ var VdFlowchart = class {
|
|
|
4717
5541
|
route: styleSource.route,
|
|
4718
5542
|
strokeWidth: styleSource.strokeWidth,
|
|
4719
5543
|
startMarker: styleSource.startMarker,
|
|
4720
|
-
endMarker: styleSource.endMarker
|
|
5544
|
+
endMarker: styleSource.endMarker,
|
|
5545
|
+
...styleSource.color ? { color: styleSource.color } : {},
|
|
5546
|
+
...styleSource.strokeStyle ? { strokeStyle: styleSource.strokeStyle } : {}
|
|
4721
5547
|
} : { endMarker: "arrow" };
|
|
4722
5548
|
const result = this.batchHistory("node:insert", () => {
|
|
4723
5549
|
if (parent.collapsed) delete parent.collapsed;
|
|
@@ -4811,7 +5637,7 @@ var VdFlowchart = class {
|
|
|
4811
5637
|
changed = true;
|
|
4812
5638
|
}
|
|
4813
5639
|
});
|
|
4814
|
-
const rerouted = options.reroutePorts === false ? false : this.rerouteEdgePorts();
|
|
5640
|
+
const rerouted = options.reroutePorts === false ? false : this.rerouteEdgePorts(resolvedMode === "tree" ? options.direction || "right" : null);
|
|
4815
5641
|
if (!changed && !rerouted) return this;
|
|
4816
5642
|
this.render();
|
|
4817
5643
|
this.emitChange("layout", { mode: resolvedMode });
|
|
@@ -4824,8 +5650,16 @@ var VdFlowchart = class {
|
|
|
4824
5650
|
// Re-pick each edge's from/to port from the nodes' current centers, so a
|
|
4825
5651
|
// freshly laid-out graph attaches connectors on sensible sides. Returns
|
|
4826
5652
|
// whether any port actually changed.
|
|
4827
|
-
rerouteEdgePorts() {
|
|
5653
|
+
rerouteEdgePorts(flowDirection = null) {
|
|
4828
5654
|
let changed = false;
|
|
5655
|
+
const flow = flowDirection === "down" || flowDirection === "up" || flowDirection === "left" || flowDirection === "right" ? flowDirection : null;
|
|
5656
|
+
const outDegree = /* @__PURE__ */ new Map();
|
|
5657
|
+
if (flow) {
|
|
5658
|
+
this.documentData.edges.forEach((edge) => {
|
|
5659
|
+
const fromId = edge?.from?.nodeId;
|
|
5660
|
+
if (fromId) outDegree.set(fromId, (outDegree.get(fromId) || 0) + 1);
|
|
5661
|
+
});
|
|
5662
|
+
}
|
|
4829
5663
|
this.documentData.edges.forEach((edge) => {
|
|
4830
5664
|
const fromNode = this.findNode(edge.from.nodeId);
|
|
4831
5665
|
const toNode = this.findNode(edge.to.nodeId);
|
|
@@ -4835,8 +5669,82 @@ var VdFlowchart = class {
|
|
|
4835
5669
|
y: fromNode.y + fromNode.height / 2
|
|
4836
5670
|
};
|
|
4837
5671
|
const toCenter = { x: toNode.x + toNode.width / 2, y: toNode.y + toNode.height / 2 };
|
|
4838
|
-
|
|
4839
|
-
|
|
5672
|
+
let nextFrom;
|
|
5673
|
+
let nextTo;
|
|
5674
|
+
if (flow) {
|
|
5675
|
+
const dx = toCenter.x - fromCenter.x;
|
|
5676
|
+
const dy = toCenter.y - fromCenter.y;
|
|
5677
|
+
const vertical = flow === "down" || flow === "up";
|
|
5678
|
+
const sign = flow === "up" || flow === "left" ? -1 : 1;
|
|
5679
|
+
const mainDelta = (vertical ? dy : dx) * sign;
|
|
5680
|
+
const crossDelta = vertical ? dx : dy;
|
|
5681
|
+
const isDiamondBranch = fromNode.type === "diamond" && (outDegree.get(fromNode.id) || 0) >= 2;
|
|
5682
|
+
if (mainDelta < -8) {
|
|
5683
|
+
const allNodes = this.documentData.nodes;
|
|
5684
|
+
if (vertical) {
|
|
5685
|
+
const minX = Math.min(fromNode.x, toNode.x);
|
|
5686
|
+
const maxRight = Math.max(fromNode.x + fromNode.width, toNode.x + toNode.width);
|
|
5687
|
+
const minY = Math.min(fromCenter.y, toCenter.y) - 8;
|
|
5688
|
+
const maxY = Math.max(fromCenter.y, toCenter.y) + 8;
|
|
5689
|
+
let rightCount = 0;
|
|
5690
|
+
let leftCount = 0;
|
|
5691
|
+
allNodes.forEach((n) => {
|
|
5692
|
+
if (!n || n.id === fromNode.id || n.id === toNode.id) return;
|
|
5693
|
+
const ny = n.y + n.height / 2;
|
|
5694
|
+
if (ny < minY || ny > maxY) return;
|
|
5695
|
+
const nx = n.x + n.width / 2;
|
|
5696
|
+
if (nx >= maxRight - 20) rightCount += 1;
|
|
5697
|
+
if (nx <= minX + 20) leftCount += 1;
|
|
5698
|
+
});
|
|
5699
|
+
const side = leftCount < rightCount ? "left" : rightCount < leftCount ? "right" : crossDelta < -8 ? "left" : "right";
|
|
5700
|
+
nextFrom = side;
|
|
5701
|
+
nextTo = side;
|
|
5702
|
+
} else {
|
|
5703
|
+
const minY = Math.min(fromNode.y, toNode.y);
|
|
5704
|
+
const maxBottom = Math.max(fromNode.y + fromNode.height, toNode.y + toNode.height);
|
|
5705
|
+
const minX = Math.min(fromCenter.x, toCenter.x) - 8;
|
|
5706
|
+
const maxX = Math.max(fromCenter.x, toCenter.x) + 8;
|
|
5707
|
+
let bottomCount = 0;
|
|
5708
|
+
let topCount = 0;
|
|
5709
|
+
allNodes.forEach((n) => {
|
|
5710
|
+
if (!n || n.id === fromNode.id || n.id === toNode.id) return;
|
|
5711
|
+
const nx = n.x + n.width / 2;
|
|
5712
|
+
if (nx < minX || nx > maxX) return;
|
|
5713
|
+
const ny = n.y + n.height / 2;
|
|
5714
|
+
if (ny >= maxBottom - 20) bottomCount += 1;
|
|
5715
|
+
if (ny <= minY + 20) topCount += 1;
|
|
5716
|
+
});
|
|
5717
|
+
const side = topCount < bottomCount ? "top" : bottomCount < topCount ? "bottom" : crossDelta < -8 ? "top" : "bottom";
|
|
5718
|
+
nextFrom = side;
|
|
5719
|
+
nextTo = side;
|
|
5720
|
+
}
|
|
5721
|
+
} else if (mainDelta >= 12) {
|
|
5722
|
+
if (vertical) {
|
|
5723
|
+
nextTo = sign > 0 ? "top" : "bottom";
|
|
5724
|
+
if (isDiamondBranch && Math.abs(crossDelta) >= fromNode.width * 0.45) {
|
|
5725
|
+
nextFrom = crossDelta > 0 ? "right" : "left";
|
|
5726
|
+
} else {
|
|
5727
|
+
nextFrom = sign > 0 ? "bottom" : "top";
|
|
5728
|
+
}
|
|
5729
|
+
} else {
|
|
5730
|
+
nextTo = sign > 0 ? "left" : "right";
|
|
5731
|
+
if (isDiamondBranch && Math.abs(crossDelta) >= fromNode.height * 0.45) {
|
|
5732
|
+
nextFrom = crossDelta > 0 ? "bottom" : "top";
|
|
5733
|
+
} else {
|
|
5734
|
+
nextFrom = sign > 0 ? "right" : "left";
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5737
|
+
} else if (vertical) {
|
|
5738
|
+
nextFrom = dx >= 0 ? "right" : "left";
|
|
5739
|
+
nextTo = dx >= 0 ? "left" : "right";
|
|
5740
|
+
} else {
|
|
5741
|
+
nextFrom = dy >= 0 ? "bottom" : "top";
|
|
5742
|
+
nextTo = dy >= 0 ? "top" : "bottom";
|
|
5743
|
+
}
|
|
5744
|
+
} else {
|
|
5745
|
+
nextFrom = getPortByDirection(fromNode, toCenter).port;
|
|
5746
|
+
nextTo = getPortByDirection(toNode, fromCenter).port;
|
|
5747
|
+
}
|
|
4840
5748
|
if (nextFrom !== edge.from.port || nextTo !== edge.to.port) {
|
|
4841
5749
|
edge.from.port = nextFrom;
|
|
4842
5750
|
edge.to.port = nextTo;
|
|
@@ -4853,6 +5761,30 @@ var VdFlowchart = class {
|
|
|
4853
5761
|
node.text = isNodeTextEditable(nextType) ? patch.text == null ? node.text : String(patch.text) : getNodeSpec(nextType).text;
|
|
4854
5762
|
node.width = clampNodeWidth(nextType, patch.width, node.width, this.nodeSizeBounds());
|
|
4855
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
|
+
}
|
|
4856
5788
|
if (isPlainObject(patch.data)) {
|
|
4857
5789
|
node.data = deepClone(patch.data);
|
|
4858
5790
|
}
|
|
@@ -4860,6 +5792,11 @@ var VdFlowchart = class {
|
|
|
4860
5792
|
updateNode(nodeId, patch = {}, options = {}) {
|
|
4861
5793
|
const node = this.findNode(nodeId);
|
|
4862
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
|
+
}
|
|
4863
5800
|
const previousType = node.type;
|
|
4864
5801
|
const previousSpec = DEFAULT_NODE_SPECS[previousType];
|
|
4865
5802
|
this.applyNodePatch(node, patch);
|
|
@@ -4964,6 +5901,16 @@ var VdFlowchart = class {
|
|
|
4964
5901
|
if (patch.label != null) {
|
|
4965
5902
|
edge.label = String(patch.label);
|
|
4966
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
|
+
}
|
|
4967
5914
|
if (isPlainObject(patch.data)) {
|
|
4968
5915
|
edge.data = deepClone(patch.data);
|
|
4969
5916
|
}
|
|
@@ -5036,11 +5983,405 @@ var VdFlowchart = class {
|
|
|
5036
5983
|
deleteSelection() {
|
|
5037
5984
|
if (!this.selection || this.readonly) return false;
|
|
5038
5985
|
if (this.hasMultiSelection()) {
|
|
5039
|
-
|
|
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);
|
|
5040
5994
|
}
|
|
5041
|
-
if (this.selection.kind === "node") return this.removeNode(this.selection.id);
|
|
5042
5995
|
return this.removeEdge(this.selection.id);
|
|
5043
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
|
+
}
|
|
5044
6385
|
nodeSizeBounds() {
|
|
5045
6386
|
return { min: this.minNodeSize, max: this.maxNodeSize };
|
|
5046
6387
|
}
|
|
@@ -5186,8 +6527,12 @@ var VdFlowchart = class {
|
|
|
5186
6527
|
this.reconnectEdgeId = null;
|
|
5187
6528
|
}
|
|
5188
6529
|
this.readonly = Boolean(options.readonly);
|
|
6530
|
+
if (this.readonly && this.colorPopoverOpen) {
|
|
6531
|
+
this.toggleColorPopover(false);
|
|
6532
|
+
}
|
|
5189
6533
|
this.root.classList.toggle("vd-flowchart-readonly", this.readonly);
|
|
5190
6534
|
this.arrangeSelect.disabled = this.readonly;
|
|
6535
|
+
if (this.colorButton) this.colorButton.disabled = this.readonly;
|
|
5191
6536
|
this.clearButton.disabled = this.readonly;
|
|
5192
6537
|
this.loadJsonButton.disabled = this.readonly;
|
|
5193
6538
|
}
|
|
@@ -5410,7 +6755,25 @@ var VdFlowchart2 = (0, import_vue.defineComponent)({
|
|
|
5410
6755
|
canUndo: () => Boolean(instance?.canUndo()),
|
|
5411
6756
|
canRedo: () => Boolean(instance?.canRedo()),
|
|
5412
6757
|
layout: (mode, options) => instance?.layout(mode, options),
|
|
5413
|
-
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) ?? ""
|
|
5414
6777
|
});
|
|
5415
6778
|
return () => (0, import_vue.h)("div", { ref: el, class: "vd-flowchart" });
|
|
5416
6779
|
}
|