@m3ui-vue/m3ui-vue 1.3.3 → 1.3.4

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.
@@ -0,0 +1,204 @@
1
+ //#region src/composables/flowPaths.ts
2
+ var e = {
3
+ top: [0, -1],
4
+ right: [1, 0],
5
+ bottom: [0, 1],
6
+ left: [-1, 0]
7
+ }, t = (e, t) => Math.atan2(t, e), n = (e) => Math.round(e * 100) / 100;
8
+ function r(e) {
9
+ let { sourceX: r, sourceY: i, targetX: a, targetY: o } = e, s = t(a - r, o - i);
10
+ return {
11
+ path: `M${n(r)},${n(i)} L${n(a)},${n(o)}`,
12
+ labelX: (r + a) / 2,
13
+ labelY: (i + o) / 2,
14
+ sourceAngle: s,
15
+ targetAngle: s
16
+ };
17
+ }
18
+ function i(e, t) {
19
+ return e >= 0 ? .5 * e : t * 25 * Math.sqrt(-e);
20
+ }
21
+ function a(e, t, n, r, a, o) {
22
+ switch (e) {
23
+ case "left": return [t - i(t - r, o), n];
24
+ case "right": return [t + i(r - t, o), n];
25
+ case "top": return [t, n - i(n - a, o)];
26
+ default: return [t, n + i(a - n, o)];
27
+ }
28
+ }
29
+ function o(r) {
30
+ let { sourceX: i, sourceY: o, targetX: s, targetY: c } = r, l = r.sourcePosition ?? "bottom", u = r.targetPosition ?? "top", d = r.curvature ?? .25, [f, p] = a(l, i, o, s, c, d), [m, h] = a(u, s, c, i, o, d), g = .125 * i + .375 * f + .375 * m + .125 * s, _ = .125 * o + .375 * p + .375 * h + .125 * c;
31
+ return {
32
+ path: `M${n(i)},${n(o)} C${n(f)},${n(p)} ${n(m)},${n(h)} ${n(s)},${n(c)}`,
33
+ labelX: g,
34
+ labelY: _,
35
+ sourceAngle: t(...e[l]),
36
+ targetAngle: t(-e[u][0], -e[u][1])
37
+ };
38
+ }
39
+ function s(t) {
40
+ let { sourceX: n, sourceY: r, targetX: i, targetY: a } = t, o = t.sourcePosition ?? "bottom", s = t.targetPosition ?? "top", l = t.offset ?? 20, [u, d] = e[o], [f, p] = e[s], m = [n + u * l, r + d * l], h = [i + f * l, a + p * l], g = u !== 0, _ = f !== 0, v;
41
+ if (g && _) {
42
+ if (u === -f && (i - n) * u >= 2 * l) {
43
+ let e = (n + i) / 2;
44
+ v = [[e, r], [e, a]];
45
+ } else if (u === f) {
46
+ let e = u > 0 ? Math.max(m[0], h[0]) : Math.min(m[0], h[0]);
47
+ v = [[e, r], [e, a]];
48
+ } else {
49
+ let e = (r + a) / 2;
50
+ v = [
51
+ m,
52
+ [m[0], e],
53
+ [h[0], e],
54
+ h
55
+ ];
56
+ }
57
+ } else if (!g && !_) {
58
+ if (d === -p && (a - r) * d >= 2 * l) {
59
+ let e = (r + a) / 2;
60
+ v = [[n, e], [i, e]];
61
+ } else if (d === p) {
62
+ let e = d > 0 ? Math.max(m[1], h[1]) : Math.min(m[1], h[1]);
63
+ v = [[n, e], [i, e]];
64
+ } else {
65
+ let e = (n + i) / 2;
66
+ v = [
67
+ m,
68
+ [e, m[1]],
69
+ [e, h[1]],
70
+ h
71
+ ];
72
+ }
73
+ } else v = g ? (i - n) * u >= l && (a - r) * -p >= l ? [[i, r]] : [
74
+ m,
75
+ [m[0], h[1]],
76
+ h
77
+ ] : (a - r) * d >= l && (i - n) * -f >= l ? [[n, a]] : [
78
+ m,
79
+ [h[0], m[1]],
80
+ h
81
+ ];
82
+ return c([
83
+ [n, r],
84
+ ...v,
85
+ [i, a]
86
+ ]);
87
+ }
88
+ function c(e) {
89
+ let t = [];
90
+ for (let n of e) {
91
+ let e = t[t.length - 1];
92
+ if (e && Math.abs(e[0] - n[0]) < .01 && Math.abs(e[1] - n[1]) < .01) continue;
93
+ let r = t[t.length - 2];
94
+ if (e && r && (Math.abs(r[0] - e[0]) < .01 && Math.abs(e[0] - n[0]) < .01 || Math.abs(r[1] - e[1]) < .01 && Math.abs(e[1] - n[1]) < .01)) {
95
+ t[t.length - 1] = n;
96
+ continue;
97
+ }
98
+ t.push(n);
99
+ }
100
+ return t;
101
+ }
102
+ function l(e) {
103
+ let t = 0;
104
+ for (let n = 1; n < e.length; n++) t += Math.hypot(e[n][0] - e[n - 1][0], e[n][1] - e[n - 1][1]);
105
+ let n = t / 2;
106
+ for (let t = 1; t < e.length; t++) {
107
+ let [r, i] = e[t - 1], [a, o] = e[t], s = Math.hypot(a - r, o - i);
108
+ if (n <= s && s > 0) return [r + (a - r) * n / s, i + (o - i) * n / s];
109
+ n -= s;
110
+ }
111
+ return e[0] ?? [0, 0];
112
+ }
113
+ function u(t) {
114
+ let { sourceX: n, sourceY: r, targetX: i, targetY: a } = t, o = t.sourcePosition ?? "bottom", s = t.targetPosition ?? "top", l = e[o][0] !== 0, u = e[s][0] !== 0, d = [n, r], f = [d];
115
+ for (let e of t.route) d = l ? [e, d[1]] : [d[0], e], f.push(d), l = !l;
116
+ if (l === u) {
117
+ if (Math.abs(u ? d[1] - a : d[0] - i) > .01) {
118
+ if (u) {
119
+ let e = (d[0] + i) / 2;
120
+ f.push([e, d[1]], [e, a]);
121
+ } else {
122
+ let e = (d[1] + a) / 2;
123
+ f.push([d[0], e], [i, e]);
124
+ }
125
+ }
126
+ } else f.push(u ? [d[0], a] : [i, d[1]]);
127
+ return f.push([i, a]), c(f);
128
+ }
129
+ function d(t, n = "bottom", r) {
130
+ let i = c(t), a = [], o = e[n][0] !== 0, s = i[0];
131
+ if (!s) return a;
132
+ for (let t = 1; t < i.length - 1; t++) {
133
+ let n = i[t];
134
+ if (Math.abs(n[1] - s[1]) < .01 !== o && (a.push(o ? s[0] : s[1]), o = !o), t === i.length - 2 && r && e[r][0] !== 0 == !o) break;
135
+ a.push(o ? n[0] : n[1]), o = !o, s = n;
136
+ }
137
+ return a;
138
+ }
139
+ function f(e) {
140
+ return m(u(e), e.borderRadius ?? 8);
141
+ }
142
+ function p(e) {
143
+ return m(s(e), e.borderRadius ?? 8);
144
+ }
145
+ function m(e, r) {
146
+ let i = `M${n(e[0][0])},${n(e[0][1])}`;
147
+ for (let t = 1; t < e.length; t++) {
148
+ let [a, o] = e[t], s = e[t + 1];
149
+ if (!s || r <= 0) {
150
+ i += ` L${n(a)},${n(o)}`;
151
+ continue;
152
+ }
153
+ let [c, l] = e[t - 1], u = Math.min(r, Math.hypot(a - c, o - l) / 2, Math.hypot(s[0] - a, s[1] - o) / 2), d = Math.sign(a - c), f = Math.sign(o - l), p = Math.sign(s[0] - a), m = Math.sign(s[1] - o);
154
+ i += ` L${n(a - d * u)},${n(o - f * u)} Q${n(a)},${n(o)} ${n(a + p * u)},${n(o + m * u)}`;
155
+ }
156
+ let [a, o] = l(e), s = e[0], c = e[1] ?? s, u = e[e.length - 2] ?? s, d = e[e.length - 1];
157
+ return {
158
+ path: i,
159
+ labelX: a,
160
+ labelY: o,
161
+ sourceAngle: t(c[0] - s[0], c[1] - s[1]),
162
+ targetAngle: t(d[0] - u[0], d[1] - u[1])
163
+ };
164
+ }
165
+ function h(e, t) {
166
+ if (t.route && (e === "smoothstep" || e === "step")) return u({
167
+ ...t,
168
+ route: t.route
169
+ });
170
+ if (e === "straight") return [[t.sourceX, t.sourceY], [t.targetX, t.targetY]];
171
+ if (e === "smoothstep" || e === "step") return s(t);
172
+ let n = t.sourcePosition ?? "bottom", r = t.targetPosition ?? "top", [i, o] = a(n, t.sourceX, t.sourceY, t.targetX, t.targetY, .25), [c, l] = a(r, t.targetX, t.targetY, t.sourceX, t.sourceY, .25), d = [];
173
+ for (let e = 0; e <= 24; e++) {
174
+ let n = e / 24, r = 1 - n;
175
+ d.push([r * r * r * t.sourceX + 3 * r * r * n * i + 3 * r * n * n * c + n * n * n * t.targetX, r * r * r * t.sourceY + 3 * r * r * n * o + 3 * r * n * n * l + n * n * n * t.targetY]);
176
+ }
177
+ return d;
178
+ }
179
+ function g(e, t, n) {
180
+ let r = Infinity;
181
+ for (let i = 1; i < n.length; i++) {
182
+ let [a, o] = n[i - 1], [s, c] = n[i], l = s - a, u = c - o, d = l * l + u * u, f = d ? Math.max(0, Math.min(1, ((e - a) * l + (t - o) * u) / d)) : 0;
183
+ r = Math.min(r, Math.hypot(a + f * l - e, o + f * u - t));
184
+ }
185
+ return r;
186
+ }
187
+ function _(e) {
188
+ return e.route ? f({
189
+ ...e,
190
+ route: e.route,
191
+ borderRadius: 0
192
+ }) : p({
193
+ ...e,
194
+ borderRadius: 0
195
+ });
196
+ }
197
+ function v(e, t, r, i = 10, a = !1) {
198
+ let o = .45, s = e - i * Math.cos(r - o), c = t - i * Math.sin(r - o), l = e - i * Math.cos(r + o), u = t - i * Math.sin(r + o);
199
+ return a ? `M${n(e)},${n(t)} L${n(s)},${n(c)} L${n(l)},${n(u)} Z` : `M${n(s)},${n(c)} L${n(e)},${n(t)} L${n(l)},${n(u)}`;
200
+ }
201
+ //#endregion
202
+ export { f as a, r as c, s as d, o as i, d as l, g as n, p as o, h as r, _ as s, v as t, u };
203
+
204
+ //# sourceMappingURL=flowPaths-DzW-aiET.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowPaths-DzW-aiET.js","names":[],"sources":["../src/composables/flowPaths.ts"],"sourcesContent":["// Edge paths for MFlow, also exported for edges of your own (`#edge-<type>` slots). Every function takes the two\n// ends in flow coordinates plus the side of its node each end leaves from, and returns an SVG path, the point\n// where a label sits and the direction the path arrives in (for an arrowhead).\n\n/** A side of a node: where a handle sits and the direction an edge leaves it in */\nexport type FlowPosition = 'top' | 'right' | 'bottom' | 'left'\n\nexport interface FlowEdgePathParams {\n sourceX: number\n sourceY: number\n /** Default 'bottom' */\n sourcePosition?: FlowPosition\n targetX: number\n targetY: number\n /** Default 'top' */\n targetPosition?: FlowPosition\n}\n\nexport interface FlowEdgePath {\n /** The SVG path (`d`) */\n path: string\n /** Where the label goes: the path's middle */\n labelX: number\n labelY: number\n /** The direction the path leaves the source in, in radians (0 = right, π/2 = down) */\n sourceAngle: number\n /** The direction the path arrives at the target in, in radians: the way an arrowhead points */\n targetAngle: number\n}\n\nconst NORMAL: Record<FlowPosition, [number, number]> = {\n top: [0, -1],\n right: [1, 0],\n bottom: [0, 1],\n left: [-1, 0],\n}\nconst angleOf = (x: number, y: number) => Math.atan2(y, x)\nconst r = (n: number) => Math.round(n * 100) / 100\n\n/** A straight line between the ends */\nexport function getStraightPath(p: FlowEdgePathParams): FlowEdgePath {\n const { sourceX: sx, sourceY: sy, targetX: tx, targetY: ty } = p\n const a = angleOf(tx - sx, ty - sy)\n return { path: `M${r(sx)},${r(sy)} L${r(tx)},${r(ty)}`, labelX: (sx + tx) / 2, labelY: (sy + ty) / 2, sourceAngle: a, targetAngle: a }\n}\n\n// React Flow's control point distance: half the distance along the side's direction, or a curve that grows with\n// the square root of how far behind the node the other end is\nfunction controlOffset(distance: number, curvature: number) {\n return distance >= 0 ? 0.5 * distance : curvature * 25 * Math.sqrt(-distance)\n}\nfunction controlPoint(pos: FlowPosition, x1: number, y1: number, x2: number, y2: number, c: number): [number, number] {\n switch (pos) {\n case 'left': return [x1 - controlOffset(x1 - x2, c), y1]\n case 'right': return [x1 + controlOffset(x2 - x1, c), y1]\n case 'top': return [x1, y1 - controlOffset(y1 - y2, c)]\n default: return [x1, y1 + controlOffset(y2 - y1, c)]\n }\n}\n\n/** A cubic curve that leaves and arrives square to the nodes' sides. `curvature` (default 0.25) bends it more when the target is behind the source */\nexport function getBezierPath(p: FlowEdgePathParams & { curvature?: number }): FlowEdgePath {\n const { sourceX: sx, sourceY: sy, targetX: tx, targetY: ty } = p\n const sp = p.sourcePosition ?? 'bottom'\n const tp = p.targetPosition ?? 'top'\n const c = p.curvature ?? 0.25\n const [c1x, c1y] = controlPoint(sp, sx, sy, tx, ty, c)\n const [c2x, c2y] = controlPoint(tp, tx, ty, sx, sy, c)\n const labelX = 0.125 * sx + 0.375 * c1x + 0.375 * c2x + 0.125 * tx\n const labelY = 0.125 * sy + 0.375 * c1y + 0.375 * c2y + 0.125 * ty\n return {\n path: `M${r(sx)},${r(sy)} C${r(c1x)},${r(c1y)} ${r(c2x)},${r(c2y)} ${r(tx)},${r(ty)}`,\n labelX,\n labelY,\n sourceAngle: angleOf(...NORMAL[sp]),\n targetAngle: angleOf(-NORMAL[tp][0], -NORMAL[tp][1]),\n }\n}\n\ntype Pt = [number, number]\n\n/** The corners of an orthogonal route between the ends, leaving and arriving square to the sides */\nexport function smoothStepPoints(p: FlowEdgePathParams & { offset?: number }): Pt[] {\n const { sourceX: sx, sourceY: sy, targetX: tx, targetY: ty } = p\n const sp = p.sourcePosition ?? 'bottom'\n const tp = p.targetPosition ?? 'top'\n const off = p.offset ?? 20\n const [nsx, nsy] = NORMAL[sp]\n const [ntx, nty] = NORMAL[tp]\n const s1: Pt = [sx + nsx * off, sy + nsy * off]\n const t1: Pt = [tx + ntx * off, ty + nty * off]\n const sH = nsx !== 0\n const tH = ntx !== 0\n let mid: Pt[]\n if (sH && tH) {\n if (nsx === -ntx && (tx - sx) * nsx >= 2 * off) {\n // Facing each other with room: one vertical run halfway\n const mx = (sx + tx) / 2\n mid = [[mx, sy], [mx, ty]]\n } else if (nsx === ntx) {\n // Both sides look the same way: go round past the farther one\n const x = nsx > 0 ? Math.max(s1[0], t1[0]) : Math.min(s1[0], t1[0])\n mid = [[x, sy], [x, ty]]\n } else {\n // Behind: out, across halfway between the ends, and back in\n const my = (sy + ty) / 2\n mid = [s1, [s1[0], my], [t1[0], my], t1]\n }\n } else if (!sH && !tH) {\n if (nsy === -nty && (ty - sy) * nsy >= 2 * off) {\n const my = (sy + ty) / 2\n mid = [[sx, my], [tx, my]]\n } else if (nsy === nty) {\n const y = nsy > 0 ? Math.max(s1[1], t1[1]) : Math.min(s1[1], t1[1])\n mid = [[sx, y], [tx, y]]\n } else {\n const mx = (sx + tx) / 2\n mid = [s1, [mx, s1[1]], [mx, t1[1]], t1]\n }\n } else if (sH) {\n // Leaves sideways, arrives from above or below: one corner when both legs go the right way\n if ((tx - sx) * nsx >= off && (ty - sy) * -nty >= off) mid = [[tx, sy]]\n else mid = [s1, [s1[0], t1[1]], t1]\n } else {\n if ((ty - sy) * nsy >= off && (tx - sx) * -ntx >= off) mid = [[sx, ty]]\n else mid = [s1, [t1[0], s1[1]], t1]\n }\n return cleanPoints([[sx, sy], ...mid, [tx, ty]])\n}\n\n/** Drops repeated and collinear points from an orthogonal polyline */\nfunction cleanPoints(pts: Pt[]): Pt[] {\n const out: Pt[] = []\n for (const q of pts) {\n const a = out[out.length - 1]\n if (a && Math.abs(a[0] - q[0]) < 0.01 && Math.abs(a[1] - q[1]) < 0.01) continue\n const b = out[out.length - 2]\n if (a && b && ((Math.abs(b[0] - a[0]) < 0.01 && Math.abs(a[0] - q[0]) < 0.01) || (Math.abs(b[1] - a[1]) < 0.01 && Math.abs(a[1] - q[1]) < 0.01))) {\n out[out.length - 1] = q\n continue\n }\n out.push(q)\n }\n return out\n}\n\nfunction midpointAlong(pts: Pt[]): Pt {\n let total = 0\n for (let i = 1; i < pts.length; i++) total += Math.hypot(pts[i]![0] - pts[i - 1]![0], pts[i]![1] - pts[i - 1]![1])\n let left = total / 2\n for (let i = 1; i < pts.length; i++) {\n const [ax, ay] = pts[i - 1]!\n const [bx, by] = pts[i]!\n const len = Math.hypot(bx - ax, by - ay)\n if (left <= len && len > 0) return [ax + ((bx - ax) * left) / len, ay + ((by - ay) * left) / len]\n left -= len\n }\n return pts[0] ?? [0, 0]\n}\n\n/**\n * The corners of an orthogonal edge routed through `route`: the positions of its segments after the first, alternately\n * x and y, starting with where the leg leaving the source ends (an x when the source's side is left or right). The\n * legs at the ends stretch to wherever the nodes are, and a corner is added before the target when it's needed to\n * arrive square to its side, so the route stays orthogonal as the nodes move.\n */\nexport function routePoints(p: FlowEdgePathParams & { route: number[] }): Pt[] {\n const { sourceX: sx, sourceY: sy, targetX: tx, targetY: ty } = p\n const sp = p.sourcePosition ?? 'bottom'\n const tp = p.targetPosition ?? 'top'\n let horizontal = NORMAL[sp][0] !== 0\n const tH = NORMAL[tp][0] !== 0\n let cur: Pt = [sx, sy]\n const pts: Pt[] = [cur]\n for (const c of p.route) {\n cur = horizontal ? [c, cur[1]] : [cur[0], c]\n pts.push(cur)\n horizontal = !horizontal\n }\n if (horizontal === tH) {\n // The next leg runs the target's way: straight in when it's level with it, else a jog halfway\n if (Math.abs(tH ? cur[1] - ty : cur[0] - tx) > 0.01) {\n if (tH) {\n const mx = (cur[0] + tx) / 2\n pts.push([mx, cur[1]], [mx, ty])\n } else {\n const my = (cur[1] + ty) / 2\n pts.push([cur[0], my], [tx, my])\n }\n }\n } else pts.push(tH ? [cur[0], ty] : [tx, cur[1]])\n pts.push([tx, ty])\n return cleanPoints(pts)\n}\n\n/** The other way round: the `route` that runs an orthogonal edge through these corners (its ends first and last) */\nexport function pointsToRoute(points: Pt[], sourcePosition: FlowPosition = 'bottom', targetPosition?: FlowPosition): number[] {\n const pts = cleanPoints(points)\n const route: number[] = []\n let horizontal = NORMAL[sourcePosition][0] !== 0\n let cur = pts[0]\n if (!cur) return route\n for (let i = 1; i < pts.length - 1; i++) {\n const q = pts[i]!\n const segH = Math.abs(q[1] - cur[1]) < 0.01\n // A leg the other way first: a zero-length one keeps the axes alternating\n if (segH !== horizontal) {\n route.push(horizontal ? cur[0] : cur[1])\n horizontal = !horizontal\n }\n // The last corner follows the target (when the last leg arrives square to its side), so it isn't kept\n if (i === pts.length - 2 && targetPosition && (NORMAL[targetPosition][0] !== 0) === !horizontal) break\n route.push(horizontal ? q[0] : q[1])\n horizontal = !horizontal\n cur = q\n }\n return route\n}\n\n/** Right-angled steps through `route` (see `routePoints`), rounded like `getSmoothStepPath` */\nexport function getRoutedPath(p: FlowEdgePathParams & { route: number[]; borderRadius?: number }): FlowEdgePath {\n return roundedPath(routePoints(p), p.borderRadius ?? 8)\n}\n\n/** Right-angled steps with rounded corners (`borderRadius`, default 8; 0 gives sharp steps). `offset` (default 20) is how far it leaves a node before turning */\nexport function getSmoothStepPath(p: FlowEdgePathParams & { borderRadius?: number; offset?: number }): FlowEdgePath {\n return roundedPath(smoothStepPoints(p), p.borderRadius ?? 8)\n}\n\nfunction roundedPath(pts: Pt[], radius: number): FlowEdgePath {\n let d = `M${r(pts[0]![0])},${r(pts[0]![1])}`\n for (let i = 1; i < pts.length; i++) {\n const [x, y] = pts[i]!\n const next = pts[i + 1]\n if (!next || radius <= 0) {\n d += ` L${r(x)},${r(y)}`\n continue\n }\n const [px, py] = pts[i - 1]!\n const rad = Math.min(radius, Math.hypot(x - px, y - py) / 2, Math.hypot(next[0] - x, next[1] - y) / 2)\n const ux = Math.sign(x - px)\n const uy = Math.sign(y - py)\n const vx = Math.sign(next[0] - x)\n const vy = Math.sign(next[1] - y)\n d += ` L${r(x - ux * rad)},${r(y - uy * rad)} Q${r(x)},${r(y)} ${r(x + vx * rad)},${r(y + vy * rad)}`\n }\n const [labelX, labelY] = midpointAlong(pts)\n const a = pts[0]!\n const b = pts[1] ?? a\n const y = pts[pts.length - 2] ?? a\n const z = pts[pts.length - 1]!\n return { path: d, labelX, labelY, sourceAngle: angleOf(b[0] - a[0], b[1] - a[1]), targetAngle: angleOf(z[0] - y[0], z[1] - y[1]) }\n}\n\n/**\n * Points along an edge's path, close enough together to measure how far something is from it (bezier curves are\n * sampled; step paths are their corners)\n */\nexport function edgePathPoints(type: string | undefined, p: FlowEdgePathParams & { route?: number[] }): [number, number][] {\n if (p.route && (type === 'smoothstep' || type === 'step')) return routePoints({ ...p, route: p.route })\n if (type === 'straight') return [[p.sourceX, p.sourceY], [p.targetX, p.targetY]]\n if (type === 'smoothstep' || type === 'step') return smoothStepPoints(p)\n const sp = p.sourcePosition ?? 'bottom'\n const tp = p.targetPosition ?? 'top'\n const [c1x, c1y] = controlPoint(sp, p.sourceX, p.sourceY, p.targetX, p.targetY, 0.25)\n const [c2x, c2y] = controlPoint(tp, p.targetX, p.targetY, p.sourceX, p.sourceY, 0.25)\n const out: [number, number][] = []\n for (let i = 0; i <= 24; i++) {\n const t = i / 24\n const u = 1 - t\n out.push([\n u * u * u * p.sourceX + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * p.targetX,\n u * u * u * p.sourceY + 3 * u * u * t * c1y + 3 * u * t * t * c2y + t * t * t * p.targetY,\n ])\n }\n return out\n}\n\n/** The distance from a point to a polyline */\nexport function distanceToPoints(x: number, y: number, pts: [number, number][]): number {\n let best = Infinity\n for (let i = 1; i < pts.length; i++) {\n const [ax, ay] = pts[i - 1]!\n const [bx, by] = pts[i]!\n const dx = bx - ax\n const dy = by - ay\n const len = dx * dx + dy * dy\n const t = len ? Math.max(0, Math.min(1, ((x - ax) * dx + (y - ay) * dy) / len)) : 0\n best = Math.min(best, Math.hypot(ax + t * dx - x, ay + t * dy - y))\n }\n return best\n}\n\n/** `getSmoothStepPath` with sharp corners */\nexport function getStepPath(p: FlowEdgePathParams & { offset?: number; route?: number[] }): FlowEdgePath {\n return p.route ? getRoutedPath({ ...p, route: p.route, borderRadius: 0 }) : getSmoothStepPath({ ...p, borderRadius: 0 })\n}\n\n/** An arrowhead's path at (x, y) pointing along `angle`: open (two strokes) or closed (a filled triangle's outline) */\nexport function arrowPath(x: number, y: number, angle: number, size = 10, closed = false): string {\n const spread = 0.45\n const ax = x - size * Math.cos(angle - spread)\n const ay = y - size * Math.sin(angle - spread)\n const bx = x - size * Math.cos(angle + spread)\n const by = y - size * Math.sin(angle + spread)\n return closed\n ? `M${r(x)},${r(y)} L${r(ax)},${r(ay)} L${r(bx)},${r(by)} Z`\n : `M${r(ax)},${r(ay)} L${r(x)},${r(y)} L${r(bx)},${r(by)}`\n}\n"],"mappings":";AA8BA,IAAM,IAAiD;CACrD,KAAK,CAAC,GAAG,EAAE;CACX,OAAO,CAAC,GAAG,CAAC;CACZ,QAAQ,CAAC,GAAG,CAAC;CACb,MAAM,CAAC,IAAI,CAAC;AACd,GACM,KAAW,GAAW,MAAc,KAAK,MAAM,GAAG,CAAC,GACnD,KAAK,MAAc,KAAK,MAAM,IAAI,GAAG,IAAI;AAG/C,SAAgB,EAAgB,GAAqC;CACnE,IAAM,EAAE,SAAS,GAAI,SAAS,GAAI,SAAS,GAAI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f,IAAK,IAAK,GACV,IAAK,IAAK,GACV,IAAM,IAAK,IAAK,IAAK,GACrB,IAAI,IAAM,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,IAAI,KAAM,KAAM,IAAI,KAAM,KAAM,CAAG,CAAC,IAAI;EAClF,IAAO,KAAK,IAAI,GAAM,KAAK,MAAM,IAAK,IAAI,IAAK,GAAG,IAAK,IAAI,IAAK,CAAC,CAAC;CACpE;CACA,OAAO;AACT;AAGA,SAAgB,EAAY,GAA6E;CACvG,OAAO,EAAE,QAAQ,EAAc;EAAE,GAAG;EAAG,OAAO,EAAE;EAAO,cAAc;CAAE,CAAC,IAAI,EAAkB;EAAE,GAAG;EAAG,cAAc;CAAE,CAAC;AACzH;AAGA,SAAgB,EAAU,GAAW,GAAW,GAAe,IAAO,IAAI,IAAS,IAAe;CAChG,IAAM,IAAS,KACT,IAAK,IAAI,IAAO,KAAK,IAAI,IAAQ,CAAM,GACvC,IAAK,IAAI,IAAO,KAAK,IAAI,IAAQ,CAAM,GACvC,IAAK,IAAI,IAAO,KAAK,IAAI,IAAQ,CAAM,GACvC,IAAK,IAAI,IAAO,KAAK,IAAI,IAAQ,CAAM;CAC7C,OAAO,IACH,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAE,EAAE,GAAG,EAAE,CAAE,EAAE,IAAI,EAAE,CAAE,EAAE,GAAG,EAAE,CAAE,EAAE,MACvD,IAAI,EAAE,CAAE,EAAE,GAAG,EAAE,CAAE,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAE,EAAE,GAAG,EAAE,CAAE;AAC3D"}
package/dist/gantt.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { i as e } from "./useLocale-CaWwi-b6.js";
2
2
  import { f as t, l as n, t as r, u as i } from "./MIconButton-DoNotQ9v.js";
3
3
  import { t as a } from "./MSegmentedButton-DL9JtJFX.js";
4
- import { t as o } from "./flowPaths-CUc6X373.js";
4
+ import { t as o } from "./flowPaths-DzW-aiET.js";
5
5
  import { Fragment as s, Teleport as c, computed as l, createBlock as u, createCommentVNode as d, createElementBlock as f, createElementVNode as p, createTextVNode as m, createVNode as h, defineComponent as g, inject as _, nextTick as ee, normalizeClass as v, normalizeStyle as y, onBeforeUnmount as te, onBeforeUpdate as ne, onMounted as re, onUpdated as ie, openBlock as b, provide as ae, ref as x, renderList as S, renderSlot as oe, shallowRef as se, toDisplayString as C, toRaw as ce, unref as w, useSlots as le, vModelText as ue, watch as de, withDirectives as fe, withKeys as pe, withModifiers as me } from "vue";
6
6
  //#region src/composables/useGantt.ts
7
7
  var he = Symbol("m3-gantt"), ge = Symbol("m3-timeline-controls");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m3ui-vue/m3ui-vue",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Material 3 component library for Vue 3 + Tailwind CSS v4",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -2,7 +2,9 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
2
2
  import { mount, flushPromises } from '@vue/test-utils'
3
3
  import { nextTick } from 'vue'
4
4
  import MFlow from '../components/MFlow.vue'
5
- import type { FlowEdge, FlowNode } from '../composables/useFlow'
5
+ import MFlowHandle from '../components/MFlowHandle.vue'
6
+ import type { FlowEdge, FlowNode, FlowXY } from '../composables/useFlow'
7
+ import { routePoints, pointsToRoute } from '../composables/flowPaths'
6
8
 
7
9
  // happy-dom has no layout: the canvas is 800×600 at the page's corner, every node 180×60
8
10
  beforeEach(() => {
@@ -16,7 +18,7 @@ beforeEach(() => {
16
18
  if (this.classList.contains('m3-flow')) return r(0, 0, 800, 600)
17
19
  if (this.classList.contains('m3-flow-handle')) {
18
20
  const c = this.className
19
- const [x, y] = c.includes('right-0') ? [180, 30] : c.includes('bottom-0') ? [90, 60] : c.includes('top-1/2') ? [0, 30] : [90, 0]
21
+ const [x, y] = c.includes('left-1/2') && c.includes('top-1/2') ? [90, 30] : c.includes('right-0') ? [180, 30] : c.includes('bottom-0') ? [90, 60] : c.includes('top-1/2') ? [0, 30] : [90, 0]
20
22
  return r(x - 5, y - 5, 10, 10)
21
23
  }
22
24
  return r(0, 0, 0, 0)
@@ -379,6 +381,112 @@ describe('MFlow', () => {
379
381
  expect(w.emitted('update:viewport')!.at(-1)![0]).toEqual({ x: start.x + 60, y: start.y, zoom })
380
382
  touch(window, 'pointerup', 3, 460, 400)
381
383
  })
384
+ it('edgesReroutable: dragging a selected step edge\'s segment gives it a route, which moves with both its nodes', async () => {
385
+ const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
386
+ const w = await flow({ edges, edgesReroutable: true, selection: { nodes: [], edges: ['e1'] } })
387
+ await nextTick()
388
+ const grip = w.find('[data-flow-segment="0"]')
389
+ expect(grip.exists()).toBe(true)
390
+ pointer(grip.element, 'pointerdown', 240, 30)
391
+ pointer(window, 'pointermove', 240, 60)
392
+ pointer(window, 'pointermove', 240, 90)
393
+ pointer(window, 'pointerup', 240, 90)
394
+ const out = w.emitted('update:edges')!.at(-1)![0] as FlowEdge[]
395
+ // A jog a grid step from each handle, running where the pointer let go
396
+ expect(out[0]!.route).toEqual([200, 90, 280])
397
+ expect(w.emitted('reroute')![0]![0]).toMatchObject({ id: 'e1', route: [200, 90, 280] })
398
+ await w.setProps({ edges: out })
399
+ expect(w.find('.m3-flow-edge-line').attributes('d')).toMatch(/^M180,30 L/)
400
+ })
401
+ it('a segment grip moves out from under the delete button', async () => {
402
+ const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
403
+ const w = await flow({ edges, edgesReroutable: true, selection: { nodes: [], edges: ['e1'] } })
404
+ await nextTick()
405
+ // The × sits at (240, 30), 40px wide with its hit area: the grip of the one segment (180 → 300) slides clear of it
406
+ const grip = w.find('[data-flow-segment="0"]')
407
+ const cx = Number(grip.attributes('x')) + 9
408
+ expect(Math.abs(cx - 240)).toBeGreaterThanOrEqual(20 + 9)
409
+ expect(cx).toBeGreaterThan(180)
410
+ expect(cx).toBeLessThan(300)
411
+ })
412
+ it('snapToGrid puts a node\'s position plus its gridOffset on the grid', async () => {
413
+ const w = await flow({ nodes: [N('a', 10, 10, { gridOffset: { x: 10, y: 10 } }), N('b', 300, 0)], snapToGrid: true, gridSize: 20 })
414
+ pointer(node(w, 'a'), 'pointerdown', 100, 40)
415
+ pointer(window, 'pointermove', 140, 80)
416
+ pointer(window, 'pointermove', 203, 143)
417
+ pointer(window, 'pointerup', 203, 143)
418
+ const nodes = w.emitted('update:nodes')!.at(-1)![0] as FlowNode[]
419
+ // Its middle (position + 10) sits on the 20px grid
420
+ expect(nodes.find((n) => n.id === 'a')!.position).toEqual({ x: 110, y: 110 })
421
+ })
422
+ it('getEdgeAt finds the edge under a point, where on it, and which way it runs', async () => {
423
+ const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
424
+ const w = await flow({ edges, snapToGrid: true, gridSize: 20 })
425
+ const ctx = w.vm as unknown as { getEdgeAt: (p: FlowXY, o?: object) => unknown }
426
+ expect(ctx.getEdgeAt({ x: 243, y: 34 })).toMatchObject({ edge: { id: 'e1' }, position: { x: 240, y: 30 }, direction: 'right' })
427
+ expect(ctx.getEdgeAt({ x: 243, y: 60 })).toBeNull()
428
+ expect(ctx.getEdgeAt({ x: 243, y: 34 }, { ignore: (e: FlowEdge) => e.id === 'e1' })).toBeNull()
429
+ })
430
+ it('a tap on a handle selects its node; a drag from it still connects', async () => {
431
+ const w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 0), N('c', 300, 200)] })
432
+ const out = w.find('[data-flow-node="a"] [data-flow-handle="source"]').element
433
+ pointer(out, 'pointerdown', 180, 30)
434
+ pointer(window, 'pointerup', 181, 30)
435
+ expect(w.emitted('update:selection')!.at(-1)![0]).toEqual({ nodes: ['a'], edges: [] })
436
+ expect(w.emitted('connect')).toBeUndefined()
437
+ // b's input already has e1: tapped (not pulled), it selects b and leaves e1 alone
438
+ pointer(w.find('[data-flow-node="b"] [data-flow-handle="target"]').element, 'pointerdown', 300, 30)
439
+ pointer(window, 'pointerup', 300, 30)
440
+ expect(w.emitted('update:selection')!.at(-1)![0]).toEqual({ nodes: ['b'], edges: [] })
441
+ expect(w.emitted('update:edges')).toBeUndefined()
442
+ })
443
+ it("a handle at position 'auto' leaves on the side facing the edge's other end", async () => {
444
+ const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'step', markerEnd: 'none' }]
445
+ const w = mount(MFlow, {
446
+ props: { nodes: [N('a', 0, 0, { type: 'dot' }), N('b', 300, 200)], edges, animate: false },
447
+ slots: { 'node-dot': `<template #node-dot><div style="width:180px;height:60px"><MFlowHandle type="source" position="auto" /></div></template>` },
448
+ global: { components: { MFlowHandle } },
449
+ attachTo: document.body,
450
+ })
451
+ await flushPromises()
452
+ await nextTick()
453
+ // From the middle of a (90, 30) toward b's left side (300, 230): it goes right first
454
+ expect(w.find('.m3-flow-edge-line').attributes('d')).toMatch(/^M90,30 L\d+/)
455
+ const first = () => w.find('.m3-flow-edge-line').attributes('d').match(/^M90,30 L(-?[\d.]+),(-?[\d.]+)/)!
456
+ expect(Number(first()[1])).toBeGreaterThan(90)
457
+ // b far below and only a little to the right: it goes down first
458
+ await w.setProps({ nodes: [N('a', 0, 0, { type: 'dot' }), N('b', 120, 600)] })
459
+ await nextTick()
460
+ expect(Number(first()[1])).toBe(90)
461
+ expect(Number(first()[2])).toBeGreaterThan(30)
462
+ // An edge can ask for its side: up first, whatever the other end
463
+ await w.setProps({ edges: [{ ...edges[0]!, sourcePosition: 'top' as const }] })
464
+ await nextTick()
465
+ expect(Number(first()[1])).toBe(90)
466
+ expect(Number(first()[2])).toBeLessThan(30)
467
+ })
468
+ it('routePoints / pointsToRoute round-trip, and the ends stretch when a node moves', () => {
469
+ const ends = { sourceX: 0, sourceY: 0, sourcePosition: 'right' as const, targetX: 200, targetY: 100, targetPosition: 'left' as const }
470
+ const pts = routePoints({ ...ends, route: [60, 40, 140] })
471
+ expect(pts).toEqual([[0, 0], [60, 0], [60, 40], [140, 40], [140, 100], [200, 100]])
472
+ expect(pointsToRoute(pts, 'right', 'left')).toEqual([60, 40, 140])
473
+ expect(pointsToRoute(pts, 'right')).toEqual([60, 40, 140, 100])
474
+ // The target went up: the last leg still arrives level with it
475
+ expect(routePoints({ ...ends, targetY: -20, route: [60, 40, 140] }).at(-2)).toEqual([140, -20])
476
+ })
477
+ it('a pinch that starts on a node zooms without selecting it; a tap on a node still selects it', async () => {
478
+ const w = await flow()
479
+ const touch = (el: EventTarget, type: string, id: number, x: number, y: number) => pointer(el, type, x, y, { pointerType: 'touch', pointerId: id })
480
+ touch(node(w, 'a'), 'pointerdown', 1, 60, 30)
481
+ touch(w.element, 'pointerdown', 2, 260, 30)
482
+ touch(window, 'pointermove', 2, 460, 30)
483
+ touch(window, 'pointerup', 1, 60, 30)
484
+ touch(window, 'pointerup', 2, 460, 30)
485
+ expect(w.emitted('update:selection')).toBeUndefined()
486
+ touch(node(w, 'b'), 'pointerdown', 3, 360, 30)
487
+ touch(window, 'pointerup', 3, 360, 30)
488
+ expect(w.emitted('update:selection')!.at(-1)![0]).toEqual({ nodes: ['b'], edges: [] })
489
+ })
382
490
  it('a node spliced in without room pushes the next one, and what comes after it, along', async () => {
383
491
  // a (0..180) → c (260..440) → d (600..): b (180 wide) can't fit between a and c with 48px each side
384
492
  const nodes = [N('a', 0, 0), N('c', 260, 0), N('d', 600, 0), N('b', 100, 300)]
@@ -523,6 +631,35 @@ describe('MFlow', () => {
523
631
  // The view didn't pan meanwhile
524
632
  expect(w.emitted('update:viewport')).toBeUndefined()
525
633
  })
634
+ it("edgeBranching 'junction': adds nothing, and tells where on the edge the branch was grabbed", async () => {
635
+ const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
636
+ const w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 0), N('c', 300, 200)], edges, edgeBranching: 'junction', snapToGrid: true, gridSize: 20 })
637
+ pointer(w.find('[data-flow-edge="e1"] path').element, 'pointerdown', 243, 34)
638
+ pointer(window, 'pointermove', 340, 220)
639
+ pointer(window, 'pointerup', 340, 220)
640
+ // On the edge (y 30) and on the grid along it (x 240)
641
+ expect(w.emitted('branch')![0]![0]).toMatchObject({ edge: { id: 'e1' }, connection: { source: 'a', target: 'c' }, position: { x: 240, y: 30 }, direction: 'right', end: { x: 340, y: 220 } })
642
+ expect(w.emitted('connect')).toBeUndefined()
643
+ expect(w.emitted('update:edges')).toBeUndefined()
644
+ // Dropped on nothing: still a branch, with no connection
645
+ pointer(w.find('[data-flow-edge="e1"] path').element, 'pointerdown', 260, 30)
646
+ pointer(window, 'pointermove', 500, 500)
647
+ pointer(window, 'pointerup', 500, 500)
648
+ expect(w.emitted('branch')![1]![0]).toMatchObject({ connection: null, position: { x: 260, y: 30 } })
649
+ })
650
+ it("edgeBranching 'junction': on a vertical run, says it runs down, and splits an edge's own route in two", async () => {
651
+ // a's right (180, 30) → over at x 240 → down to b's left (300, 230)
652
+ const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep', route: [240] }]
653
+ const w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 200), N('c', 600, 400)], edges, edgeBranching: 'junction', snapToGrid: true, gridSize: 20 })
654
+ pointer(w.find('[data-flow-edge="e1"] path').element, 'pointerdown', 243, 128)
655
+ pointer(window, 'pointermove', 500, 500)
656
+ pointer(window, 'pointerup', 500, 500)
657
+ const ev = w.emitted('branch')![0]![0] as { position: FlowXY; direction: string; routes: { before: number[]; after: number[] } }
658
+ expect(ev.position).toEqual({ x: 240, y: 120 })
659
+ expect(ev.direction).toBe('bottom')
660
+ expect(routePoints({ sourceX: 180, sourceY: 30, sourcePosition: 'right', targetX: 240, targetY: 120, targetPosition: 'top', route: ev.routes.before })).toEqual([[180, 30], [240, 30], [240, 120]])
661
+ expect(routePoints({ sourceX: 240, sourceY: 120, sourcePosition: 'bottom', targetX: 300, targetY: 230, targetPosition: 'left', route: ev.routes.after })).toEqual([[240, 120], [240, 230], [300, 230]])
662
+ })
526
663
  it('edgeBranching: a click still selects; off (the default), a drag from an edge pans; a finger only branches a selected edge', async () => {
527
664
  let w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 0), N('c', 300, 200)], edgeBranching: true })
528
665
  let hit = w.find('[data-flow-edge="e1"] path').element