@lupinum/board-connections 0.1.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/LICENSE +21 -0
- package/README.md +63 -0
- package/dist/colors-CI4AZ9tI.js +553 -0
- package/dist/colors.d.ts +10 -0
- package/dist/connection-actions.d.ts +41 -0
- package/dist/connection-label.d.ts +99 -0
- package/dist/connection-toolbar.d.ts +19 -0
- package/dist/controller.d.ts +50 -0
- package/dist/directionality.d.ts +8 -0
- package/dist/geometry.d.ts +23 -0
- package/dist/hit-testing.d.ts +11 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +298 -0
- package/dist/layer-helpers.d.ts +26 -0
- package/dist/layer.d.ts +38 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/renderer.d.ts +32 -0
- package/dist/routing/arc.d.ts +11 -0
- package/dist/types.d.ts +113 -0
- package/dist/vue.d.ts +2 -0
- package/dist/vue.js +1479 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Lupinum OG and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/lupinum-dev/nuxt-board/main/docs/public/app-icon.svg" width="128" alt="Nuxt Board icon"></p>
|
|
2
|
+
|
|
3
|
+
<h1 align="center">@lupinum/board-connections</h1>
|
|
4
|
+
|
|
5
|
+
<p align="center">Add typed edges, anchors, labels, routing, and connection rendering to a board.</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@lupinum/board-connections"><img src="https://img.shields.io/npm/v/@lupinum/board-connections?label=npm" alt="npm version"></a>
|
|
9
|
+
<a href="https://github.com/lupinum-dev/nuxt-board/actions/workflows/ci.yml"><img src="https://github.com/lupinum-dev/nuxt-board/actions/workflows/ci.yml/badge.svg" alt="CI status"></a>
|
|
10
|
+
<a href="https://github.com/lupinum-dev/nuxt-board/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT license"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
> [!WARNING]
|
|
14
|
+
> This package has not reached a stable release. Review the changelog before each upgrade.
|
|
15
|
+
|
|
16
|
+
## Purpose
|
|
17
|
+
|
|
18
|
+
Use this plugin when nodes must connect to each other. The plugin owns connection state and provides a Vue SVG layer for rendering.
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
Install the same version of this package, `@lupinum/board-core`, and `@lupinum/vue-board`. The fixed-version release keeps the plugin ABI aligned.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add @lupinum/board-connections @lupinum/board-core @lupinum/vue-board
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { connectionsPlugin } from '@lupinum/board-connections'
|
|
34
|
+
import { createBoardEngine } from '@lupinum/board-core'
|
|
35
|
+
|
|
36
|
+
const engine = createBoardEngine({ plugins: [connectionsPlugin()] })
|
|
37
|
+
const first = engine.createNode({ type: 'text', text: 'First' })
|
|
38
|
+
const second = engine.createNode({ type: 'text', x: 280, text: 'Second' })
|
|
39
|
+
|
|
40
|
+
engine.plugins.connections.createEdge({
|
|
41
|
+
from: first.id,
|
|
42
|
+
to: second.id,
|
|
43
|
+
data: {},
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Render `BoardConnectionLayer` below `BoardRoot`. It reads the board context and positions its SVG layer against the board root.
|
|
48
|
+
|
|
49
|
+
## Exports
|
|
50
|
+
|
|
51
|
+
The package exports the connections plugin and the Vue connection layer.
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
Read the [connections reference](https://nuxt-board.lupinum.com/docs/reference/connections).
|
|
56
|
+
|
|
57
|
+
## Support and security
|
|
58
|
+
|
|
59
|
+
Open a [GitHub issue](https://github.com/lupinum-dev/nuxt-board/issues) for support. Report vulnerabilities through the [private security process](https://github.com/lupinum-dev/nuxt-board/security/policy).
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
This package uses the [MIT License](https://github.com/lupinum-dev/nuxt-board/blob/main/LICENSE).
|
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { boundsIntersect as bt, BOARD_COLOR_PRESETS as $t, colorForPreset as St } from "@lupinum/board-core";
|
|
2
|
+
function Kt(t) {
|
|
3
|
+
switch (t) {
|
|
4
|
+
case "start":
|
|
5
|
+
return { fromEnd: "arrow", toEnd: "none" };
|
|
6
|
+
case "both":
|
|
7
|
+
return { fromEnd: "arrow", toEnd: "arrow" };
|
|
8
|
+
case "none":
|
|
9
|
+
return { fromEnd: "none", toEnd: "none" };
|
|
10
|
+
case "end":
|
|
11
|
+
return { fromEnd: "none", toEnd: "arrow" };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const R = Math.PI;
|
|
15
|
+
function Et(t, n, e, o = !1) {
|
|
16
|
+
const [s, r] = n, [i, u] = e, c = i + (t - s) / (r - s) * (u - i);
|
|
17
|
+
return o ? i < u ? Math.max(Math.min(c, u), i) : Math.max(Math.min(c, i), u) : c;
|
|
18
|
+
}
|
|
19
|
+
function B(t, n, e, o) {
|
|
20
|
+
return Math.atan2(o - n, e - t);
|
|
21
|
+
}
|
|
22
|
+
function Pt(t, n, e, o) {
|
|
23
|
+
return Math.hypot(e - t, o - n);
|
|
24
|
+
}
|
|
25
|
+
function z(t, n, e) {
|
|
26
|
+
return t + (n - t) * e;
|
|
27
|
+
}
|
|
28
|
+
function wt(t, n) {
|
|
29
|
+
return !(t.x > n.x + n.w || t.x + t.w < n.x || t.y > n.y + n.h || t.y + t.h < n.y);
|
|
30
|
+
}
|
|
31
|
+
function tt(t, n) {
|
|
32
|
+
return {
|
|
33
|
+
x: t.x - n,
|
|
34
|
+
y: t.y - n,
|
|
35
|
+
w: t.w + n * 2,
|
|
36
|
+
h: t.h + n * 2
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function At(t, n, e, o, s, r, i, u, c = {}) {
|
|
40
|
+
const f = c.bow ?? 0, x = c.stretch ?? 0.25, y = c.stretchMin ?? 50, P = c.stretchMax ?? 420, l = c.padStart ?? 0, p = c.padEnd ?? 20, C = c.flip ?? !1, O = c.straights ?? !0, w = { x: t, y: n, w: e, h: o }, A = { x: s, y: r, w: i, h: u }, H = tt(w, l), q = tt(A, p), d = t + e / 2, a = n + o / 2, g = s + i / 2, M = r + u / 2, j = B(d, a, g, M);
|
|
41
|
+
let [b, $] = [d, a], [S, E] = [g, M];
|
|
42
|
+
if (wt(H, q)) {
|
|
43
|
+
const D = B(d, a, g, M);
|
|
44
|
+
b = d + Math.cos(D) * (e / 2 + l), $ = a + Math.sin(D) * (o / 2 + l), S = g - Math.cos(D) * (i / 2 + p), E = M - Math.sin(D) * (u / 2 + p);
|
|
45
|
+
const [Mt, pt] = [
|
|
46
|
+
z(b, S, 0.5),
|
|
47
|
+
z($, E, 0.5)
|
|
48
|
+
];
|
|
49
|
+
return [b, $, Mt, pt, S, E, D + R, D + R];
|
|
50
|
+
}
|
|
51
|
+
const T = e / 2, v = o / 2, I = i / 2, X = u / 2, Y = Math.tan(j), K = Math.abs(Y), ht = v / T, lt = X / I;
|
|
52
|
+
K > ht ? ($ = a + (M > a ? v + l : -(v + l)), b = d + (M > a ? v + l : -(v + l)) / Y) : (b = d + (g > d ? T + l : -(T + l)), $ = a + (g > d ? T + l : -(T + l)) * Y), K > lt ? (E = M + (a > M ? X + p : -(X + p)), S = g + (a > M ? X + p : -(X + p)) / Y) : (S = g + (d > g ? I + p : -(I + p)), E = M + (d > g ? I + p : -(I + p)) * Y);
|
|
53
|
+
const J = Pt(b, $, S, E), dt = Et(J, [y, P], [1, 0], !0) * x + f, N = B(b, $, S, E), W = z(b, S, 0.5), k = z($, E, 0.5), V = J * dt, Z = N + R / 2, m = C ? -1 : 1, _ = W + Math.cos(Z) * V * m, L = k + Math.sin(Z) * V * m;
|
|
54
|
+
if (O && Math.abs(_ - W) < 1 && Math.abs(L - k) < 1)
|
|
55
|
+
return [b, $, W, k, S, E, N + R, N];
|
|
56
|
+
const at = B(b, $, _, L) + R, gt = B(S, E, _, L);
|
|
57
|
+
return [b, $, _, L, S, E, at, gt];
|
|
58
|
+
}
|
|
59
|
+
function G(t, n, e, o) {
|
|
60
|
+
const s = 1 - o;
|
|
61
|
+
return s * s * t + 2 * s * o * n + o * o * e;
|
|
62
|
+
}
|
|
63
|
+
function Ct(t, n, e) {
|
|
64
|
+
const o = /* @__PURE__ */ new Set([0, 1]);
|
|
65
|
+
for (const c of ["x", "y"]) {
|
|
66
|
+
const f = t[c], x = n[c], y = e[c], P = f - 2 * x + y;
|
|
67
|
+
if (Math.abs(P) > 1e-9) {
|
|
68
|
+
const l = (f - x) / P;
|
|
69
|
+
l > 0 && l < 1 && o.add(l);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let s = 1 / 0, r = 1 / 0, i = -1 / 0, u = -1 / 0;
|
|
73
|
+
for (const c of o) {
|
|
74
|
+
const f = G(t.x, n.x, e.x, c), x = G(t.y, n.y, e.y, c);
|
|
75
|
+
f < s && (s = f), x < r && (r = x), f > i && (i = f), x > u && (u = x);
|
|
76
|
+
}
|
|
77
|
+
return { minX: s, minY: r, maxX: i, maxY: u };
|
|
78
|
+
}
|
|
79
|
+
function Ot(t, n, e) {
|
|
80
|
+
return {
|
|
81
|
+
x: G(t.x, n.x, e.x, 0.5),
|
|
82
|
+
y: G(t.y, n.y, e.y, 0.5)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function Dt(t, n, e = {}) {
|
|
86
|
+
const [o, s, r, i, u, c] = At(
|
|
87
|
+
t.node.x,
|
|
88
|
+
t.node.y,
|
|
89
|
+
t.node.width,
|
|
90
|
+
t.node.height,
|
|
91
|
+
n.node.x,
|
|
92
|
+
n.node.y,
|
|
93
|
+
n.node.width,
|
|
94
|
+
n.node.height,
|
|
95
|
+
{
|
|
96
|
+
bow: e.bow ?? 0,
|
|
97
|
+
stretch: e.stretch ?? 0.25,
|
|
98
|
+
stretchMin: e.stretchMin ?? 50,
|
|
99
|
+
stretchMax: e.stretchMax ?? 420,
|
|
100
|
+
padStart: e.padStart ?? 0,
|
|
101
|
+
padEnd: e.padEnd ?? 0,
|
|
102
|
+
flip: e.flip ?? !1,
|
|
103
|
+
straights: !0
|
|
104
|
+
}
|
|
105
|
+
), f = { x: o, y: s }, x = { x: r, y: i }, y = { x: u, y: c };
|
|
106
|
+
return {
|
|
107
|
+
routing: "arc",
|
|
108
|
+
path: `M${o},${s} Q${r},${i} ${u},${c}`,
|
|
109
|
+
labelPoint: Ot(f, x, y),
|
|
110
|
+
bounds: Ct(f, x, y),
|
|
111
|
+
waypoints: [f, y],
|
|
112
|
+
segments: [
|
|
113
|
+
{
|
|
114
|
+
type: "cubic",
|
|
115
|
+
from: f,
|
|
116
|
+
control1: x,
|
|
117
|
+
control2: x,
|
|
118
|
+
to: y
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const Tt = 24, vt = 0.5, It = 24, Xt = 10, nt = {
|
|
124
|
+
top: { x: 0, y: -1 },
|
|
125
|
+
right: { x: 1, y: 0 },
|
|
126
|
+
bottom: { x: 0, y: 1 },
|
|
127
|
+
left: { x: -1, y: 0 }
|
|
128
|
+
};
|
|
129
|
+
function Q(t, n, e) {
|
|
130
|
+
return Math.min(e, Math.max(n, t));
|
|
131
|
+
}
|
|
132
|
+
function Yt(t) {
|
|
133
|
+
return t === "left" || t === "right" ? "horizontal" : "vertical";
|
|
134
|
+
}
|
|
135
|
+
function h(t, n) {
|
|
136
|
+
return { x: t, y: n };
|
|
137
|
+
}
|
|
138
|
+
function ot(t) {
|
|
139
|
+
return {
|
|
140
|
+
x: t.x + t.width / 2,
|
|
141
|
+
y: t.y + t.height / 2
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function et(t, n) {
|
|
145
|
+
const e = Q(n.offset, 0, 1);
|
|
146
|
+
switch (n.side) {
|
|
147
|
+
case "top":
|
|
148
|
+
return { x: t.x + t.width * e, y: t.y };
|
|
149
|
+
case "bottom":
|
|
150
|
+
return { x: t.x + t.width * e, y: t.y + t.height };
|
|
151
|
+
case "left":
|
|
152
|
+
return { x: t.x, y: t.y + t.height * e };
|
|
153
|
+
default:
|
|
154
|
+
return { x: t.x + t.width, y: t.y + t.height * e };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function ft(t, n, e, o) {
|
|
158
|
+
const s = ot(t), r = ot(n), i = r.x - s.x, u = r.y - s.y, c = Math.abs(i), f = Math.abs(u);
|
|
159
|
+
if (c < 1e-3 && f < 1e-3)
|
|
160
|
+
return o || "right";
|
|
161
|
+
let x = c >= f ? "horizontal" : "vertical";
|
|
162
|
+
if (o) {
|
|
163
|
+
const y = Yt(o), P = Math.abs(c - f);
|
|
164
|
+
y !== x && P < Tt && (x = y);
|
|
165
|
+
}
|
|
166
|
+
return x === "horizontal" ? i >= 0 ? "right" : "left" : u >= 0 ? "bottom" : "top";
|
|
167
|
+
}
|
|
168
|
+
function it(t, n, e, o, s) {
|
|
169
|
+
const r = o === "source" ? t.fromAnchor : t.toAnchor;
|
|
170
|
+
if (r)
|
|
171
|
+
return {
|
|
172
|
+
nodeId: n.id,
|
|
173
|
+
node: n,
|
|
174
|
+
side: r.side,
|
|
175
|
+
offset: Q(r.offset, 0, 1),
|
|
176
|
+
point: et(n, r),
|
|
177
|
+
kind: "explicit"
|
|
178
|
+
};
|
|
179
|
+
const i = ft(n, e, o, s), u = vt;
|
|
180
|
+
return {
|
|
181
|
+
nodeId: n.id,
|
|
182
|
+
node: n,
|
|
183
|
+
side: i,
|
|
184
|
+
offset: u,
|
|
185
|
+
point: et(n, { side: i, offset: u }),
|
|
186
|
+
kind: "auto"
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function Jt(t, n, e, o) {
|
|
190
|
+
const s = {
|
|
191
|
+
id: `floating-${e}`,
|
|
192
|
+
x: t.x,
|
|
193
|
+
y: t.y,
|
|
194
|
+
width: 0,
|
|
195
|
+
height: 0
|
|
196
|
+
}, r = {
|
|
197
|
+
x: n.x,
|
|
198
|
+
y: n.y,
|
|
199
|
+
width: 0,
|
|
200
|
+
height: 0
|
|
201
|
+
}, i = ft(s, r, e, o);
|
|
202
|
+
return {
|
|
203
|
+
nodeId: s.id,
|
|
204
|
+
node: s,
|
|
205
|
+
side: i,
|
|
206
|
+
offset: 0.5,
|
|
207
|
+
point: t,
|
|
208
|
+
kind: "auto"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function U(t) {
|
|
212
|
+
return t.reduce(
|
|
213
|
+
(n, e) => ({
|
|
214
|
+
minX: Math.min(n.minX, e.x),
|
|
215
|
+
minY: Math.min(n.minY, e.y),
|
|
216
|
+
maxX: Math.max(n.maxX, e.x),
|
|
217
|
+
maxY: Math.max(n.maxY, e.y)
|
|
218
|
+
}),
|
|
219
|
+
{ minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 }
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
function st(t, n, e, o, s) {
|
|
223
|
+
const r = 1 - s;
|
|
224
|
+
return r ** 3 * t + 3 * r ** 2 * s * n + 3 * r * s ** 2 * e + s ** 3 * o;
|
|
225
|
+
}
|
|
226
|
+
function rt(t, n, e, o) {
|
|
227
|
+
const s = -t + 3 * n - 3 * e + o, r = 2 * (t - 2 * n + e), i = n - t, u = [];
|
|
228
|
+
if (Math.abs(s) < 1e-9) {
|
|
229
|
+
if (Math.abs(r) < 1e-9)
|
|
230
|
+
return u;
|
|
231
|
+
const y = -i / r;
|
|
232
|
+
return y > 0 && y < 1 && u.push(y), u;
|
|
233
|
+
}
|
|
234
|
+
const c = r * r - 4 * s * i;
|
|
235
|
+
if (c < 0)
|
|
236
|
+
return u;
|
|
237
|
+
const f = Math.sqrt(c), x = [(-r + f) / (2 * s), (-r - f) / (2 * s)];
|
|
238
|
+
for (const y of x)
|
|
239
|
+
y > 0 && y < 1 && u.push(y);
|
|
240
|
+
return u;
|
|
241
|
+
}
|
|
242
|
+
function Rt(t, n, e, o) {
|
|
243
|
+
const s = /* @__PURE__ */ new Set([0, 1]);
|
|
244
|
+
for (const i of rt(
|
|
245
|
+
t.x,
|
|
246
|
+
n.x,
|
|
247
|
+
e.x,
|
|
248
|
+
o.x
|
|
249
|
+
))
|
|
250
|
+
s.add(i);
|
|
251
|
+
for (const i of rt(
|
|
252
|
+
t.y,
|
|
253
|
+
n.y,
|
|
254
|
+
e.y,
|
|
255
|
+
o.y
|
|
256
|
+
))
|
|
257
|
+
s.add(i);
|
|
258
|
+
const r = [...s].map(
|
|
259
|
+
(i) => h(
|
|
260
|
+
st(t.x, n.x, e.x, o.x, i),
|
|
261
|
+
st(t.y, n.y, e.y, o.y, i)
|
|
262
|
+
)
|
|
263
|
+
);
|
|
264
|
+
return U(r);
|
|
265
|
+
}
|
|
266
|
+
function Bt(t) {
|
|
267
|
+
return {
|
|
268
|
+
x: t.sourceX * 0.125 + t.sourceControlX * 0.375 + t.targetControlX * 0.375 + t.targetX * 0.125,
|
|
269
|
+
y: t.sourceY * 0.125 + t.sourceControlY * 0.375 + t.targetControlY * 0.375 + t.targetY * 0.125
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const _t = 400, Lt = 0.35;
|
|
273
|
+
function F(t, n) {
|
|
274
|
+
const e = Q(1 - Math.abs(t) / _t, 0, 1), o = e * e * Lt;
|
|
275
|
+
return t >= 0 ? (0.5 + o) * t : (n + o) * 25 * Math.sqrt(-t);
|
|
276
|
+
}
|
|
277
|
+
function ct(t) {
|
|
278
|
+
switch (t.pos) {
|
|
279
|
+
case "left":
|
|
280
|
+
return h(
|
|
281
|
+
t.x1 - F(t.x1 - t.x2, t.curvature),
|
|
282
|
+
t.y1
|
|
283
|
+
);
|
|
284
|
+
case "right":
|
|
285
|
+
return h(
|
|
286
|
+
t.x1 + F(t.x2 - t.x1, t.curvature),
|
|
287
|
+
t.y1
|
|
288
|
+
);
|
|
289
|
+
case "top":
|
|
290
|
+
return h(
|
|
291
|
+
t.x1,
|
|
292
|
+
t.y1 - F(t.y1 - t.y2, t.curvature)
|
|
293
|
+
);
|
|
294
|
+
default:
|
|
295
|
+
return h(
|
|
296
|
+
t.x1,
|
|
297
|
+
t.y1 + F(t.y2 - t.y1, t.curvature)
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function zt(t, n) {
|
|
302
|
+
const e = ct({
|
|
303
|
+
pos: t.side,
|
|
304
|
+
x1: t.point.x,
|
|
305
|
+
y1: t.point.y,
|
|
306
|
+
x2: n.point.x,
|
|
307
|
+
y2: n.point.y,
|
|
308
|
+
curvature: 0.25
|
|
309
|
+
}), o = ct({
|
|
310
|
+
pos: n.side,
|
|
311
|
+
x1: n.point.x,
|
|
312
|
+
y1: n.point.y,
|
|
313
|
+
x2: t.point.x,
|
|
314
|
+
y2: t.point.y,
|
|
315
|
+
curvature: 0.25
|
|
316
|
+
});
|
|
317
|
+
return {
|
|
318
|
+
routing: "bezier",
|
|
319
|
+
path: `M${t.point.x},${t.point.y} C${e.x},${e.y} ${o.x},${o.y} ${n.point.x},${n.point.y}`,
|
|
320
|
+
labelPoint: Bt({
|
|
321
|
+
sourceX: t.point.x,
|
|
322
|
+
sourceY: t.point.y,
|
|
323
|
+
targetX: n.point.x,
|
|
324
|
+
targetY: n.point.y,
|
|
325
|
+
sourceControlX: e.x,
|
|
326
|
+
sourceControlY: e.y,
|
|
327
|
+
targetControlX: o.x,
|
|
328
|
+
targetControlY: o.y
|
|
329
|
+
}),
|
|
330
|
+
bounds: Rt(t.point, e, o, n.point),
|
|
331
|
+
waypoints: [t.point, n.point],
|
|
332
|
+
segments: [
|
|
333
|
+
{
|
|
334
|
+
type: "cubic",
|
|
335
|
+
from: t.point,
|
|
336
|
+
control1: e,
|
|
337
|
+
control2: o,
|
|
338
|
+
to: n.point
|
|
339
|
+
}
|
|
340
|
+
]
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function ut(t, n) {
|
|
344
|
+
return Math.hypot(n.x - t.x, n.y - t.y);
|
|
345
|
+
}
|
|
346
|
+
function Ft(t) {
|
|
347
|
+
return t.sourcePosition === "left" || t.sourcePosition === "right" ? t.source.x < t.target.x ? h(1, 0) : h(-1, 0) : t.source.y < t.target.y ? h(0, 1) : h(0, -1);
|
|
348
|
+
}
|
|
349
|
+
function yt(t, n) {
|
|
350
|
+
return {
|
|
351
|
+
x: (t.x + n.x) / 2,
|
|
352
|
+
y: (t.y + n.y) / 2
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function Gt(t) {
|
|
356
|
+
const n = nt[t.sourcePosition], e = nt[t.targetPosition], o = h(
|
|
357
|
+
t.source.x + n.x * t.offset,
|
|
358
|
+
t.source.y + n.y * t.offset
|
|
359
|
+
), s = h(
|
|
360
|
+
t.target.x + e.x * t.offset,
|
|
361
|
+
t.target.y + e.y * t.offset
|
|
362
|
+
), r = Ft({
|
|
363
|
+
source: o,
|
|
364
|
+
sourcePosition: t.sourcePosition,
|
|
365
|
+
target: s
|
|
366
|
+
}), i = r.x !== 0 ? "x" : "y", u = r[i];
|
|
367
|
+
let c = [], f = yt(t.source, t.target);
|
|
368
|
+
const x = h(0, 0), y = h(0, 0);
|
|
369
|
+
if (n[i] * e[i] === -1) {
|
|
370
|
+
const C = i === "x" ? o.x + (s.x - o.x) * t.stepPosition : (o.x + s.x) / 2, O = i === "y" ? o.y + (s.y - o.y) * t.stepPosition : (o.y + s.y) / 2, w = [
|
|
371
|
+
h(C, o.y),
|
|
372
|
+
h(C, s.y)
|
|
373
|
+
], A = [
|
|
374
|
+
h(o.x, O),
|
|
375
|
+
h(s.x, O)
|
|
376
|
+
];
|
|
377
|
+
n[i] === u ? c = i === "x" ? w : A : c = i === "x" ? A : w;
|
|
378
|
+
} else {
|
|
379
|
+
const C = [h(o.x, s.y)], O = [h(s.x, o.y)];
|
|
380
|
+
if (i === "x" ? c = n.x === u ? O : C : c = n.y === u ? C : O, t.sourcePosition === t.targetPosition) {
|
|
381
|
+
const d = Math.abs(
|
|
382
|
+
t.source[i] - t.target[i]
|
|
383
|
+
);
|
|
384
|
+
if (d <= t.offset) {
|
|
385
|
+
const a = Math.min(t.offset - 1, t.offset - d);
|
|
386
|
+
n[i] === u ? x[i] = (o[i] > t.source[i] ? -1 : 1) * a : y[i] = (s[i] > t.target[i] ? -1 : 1) * a;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (t.sourcePosition !== t.targetPosition) {
|
|
390
|
+
const d = i === "x" ? "y" : "x", a = n[i] === e[d], g = o[d] > s[d], M = o[d] < s[d];
|
|
391
|
+
(n[i] === 1 && (!a && g || a && M) || n[i] !== 1 && (!a && M || a && g)) && (c = i === "x" ? C : O);
|
|
392
|
+
}
|
|
393
|
+
const w = h(
|
|
394
|
+
o.x + x.x,
|
|
395
|
+
o.y + x.y
|
|
396
|
+
), A = h(
|
|
397
|
+
s.x + y.x,
|
|
398
|
+
s.y + y.y
|
|
399
|
+
), H = Math.max(
|
|
400
|
+
Math.abs(w.x - c[0].x),
|
|
401
|
+
Math.abs(A.x - c[0].x)
|
|
402
|
+
), q = Math.max(
|
|
403
|
+
Math.abs(w.y - c[0].y),
|
|
404
|
+
Math.abs(A.y - c[0].y)
|
|
405
|
+
);
|
|
406
|
+
f = H >= q ? h((w.x + A.x) / 2, c[0].y) : h(c[0].x, (w.y + A.y) / 2);
|
|
407
|
+
}
|
|
408
|
+
const P = h(
|
|
409
|
+
o.x + x.x,
|
|
410
|
+
o.y + x.y
|
|
411
|
+
), l = h(
|
|
412
|
+
s.x + y.x,
|
|
413
|
+
s.y + y.y
|
|
414
|
+
);
|
|
415
|
+
return [[
|
|
416
|
+
t.source,
|
|
417
|
+
...P.x !== c[0].x || P.y !== c[0].y ? [P] : [],
|
|
418
|
+
...c,
|
|
419
|
+
...l.x !== c[c.length - 1].x || l.y !== c[c.length - 1].y ? [l] : [],
|
|
420
|
+
t.target
|
|
421
|
+
], f];
|
|
422
|
+
}
|
|
423
|
+
function Ht(t, n, e, o) {
|
|
424
|
+
if (o <= 0)
|
|
425
|
+
return `L${n.x} ${n.y}`;
|
|
426
|
+
const s = Math.min(ut(t, n) / 2, ut(n, e) / 2, o), { x: r, y: i } = n;
|
|
427
|
+
if (t.x === r && r === e.x || t.y === i && i === e.y)
|
|
428
|
+
return `L${r} ${i}`;
|
|
429
|
+
if (t.y === i) {
|
|
430
|
+
const f = t.x < e.x ? -1 : 1, x = t.y < e.y ? 1 : -1;
|
|
431
|
+
return `L${r + s * f},${i}Q${r},${i} ${r},${i + s * x}`;
|
|
432
|
+
}
|
|
433
|
+
const u = t.x < e.x ? 1 : -1, c = t.y < e.y ? -1 : 1;
|
|
434
|
+
return `L${r},${i + s * c}Q${r},${i} ${r + s * u},${i}`;
|
|
435
|
+
}
|
|
436
|
+
function xt(t, n, e) {
|
|
437
|
+
const [o, s] = Gt({
|
|
438
|
+
source: t.point,
|
|
439
|
+
sourcePosition: t.side,
|
|
440
|
+
target: n.point,
|
|
441
|
+
targetPosition: n.side,
|
|
442
|
+
offset: It,
|
|
443
|
+
stepPosition: 0.5
|
|
444
|
+
});
|
|
445
|
+
let r = `M${o[0].x} ${o[0].y}`;
|
|
446
|
+
for (let i = 1; i < o.length - 1; i += 1)
|
|
447
|
+
r += Ht(
|
|
448
|
+
o[i - 1],
|
|
449
|
+
o[i],
|
|
450
|
+
o[i + 1],
|
|
451
|
+
e === "smooth-step" ? Xt : 0
|
|
452
|
+
);
|
|
453
|
+
return r += `L${o[o.length - 1].x} ${o[o.length - 1].y}`, {
|
|
454
|
+
routing: e,
|
|
455
|
+
path: r,
|
|
456
|
+
labelPoint: s,
|
|
457
|
+
bounds: U(o),
|
|
458
|
+
waypoints: o,
|
|
459
|
+
segments: o.slice(0, -1).map((i, u) => ({
|
|
460
|
+
type: "line",
|
|
461
|
+
from: i,
|
|
462
|
+
to: o[u + 1]
|
|
463
|
+
}))
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function qt(t, n) {
|
|
467
|
+
return {
|
|
468
|
+
routing: "straight",
|
|
469
|
+
path: `M${t.point.x} ${t.point.y} L${n.point.x} ${n.point.y}`,
|
|
470
|
+
labelPoint: yt(t.point, n.point),
|
|
471
|
+
bounds: U([t.point, n.point]),
|
|
472
|
+
waypoints: [t.point, n.point],
|
|
473
|
+
segments: [{ type: "line", from: t.point, to: n.point }]
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function Nt(t) {
|
|
477
|
+
switch (t.routing ?? "bezier") {
|
|
478
|
+
case "straight":
|
|
479
|
+
return qt(t.source, t.target);
|
|
480
|
+
case "step":
|
|
481
|
+
return xt(t.source, t.target, "step");
|
|
482
|
+
case "smooth-step":
|
|
483
|
+
return xt(t.source, t.target, "smooth-step");
|
|
484
|
+
case "arc":
|
|
485
|
+
return Dt(t.source, t.target);
|
|
486
|
+
default:
|
|
487
|
+
return zt(t.source, t.target);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function Wt(t, n, e, o = {}) {
|
|
491
|
+
const s = it(
|
|
492
|
+
t,
|
|
493
|
+
n,
|
|
494
|
+
e,
|
|
495
|
+
"source",
|
|
496
|
+
o.previousSourceSide
|
|
497
|
+
), r = it(
|
|
498
|
+
t,
|
|
499
|
+
e,
|
|
500
|
+
n,
|
|
501
|
+
"target",
|
|
502
|
+
o.previousTargetSide
|
|
503
|
+
);
|
|
504
|
+
return {
|
|
505
|
+
source: s,
|
|
506
|
+
target: r,
|
|
507
|
+
route: Nt({
|
|
508
|
+
source: s,
|
|
509
|
+
target: r,
|
|
510
|
+
routing: o.routing
|
|
511
|
+
})
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function Vt(t, n, e) {
|
|
515
|
+
const o = t.$nodes.get();
|
|
516
|
+
return t.plugins.connections.getEdges().filter((s) => {
|
|
517
|
+
const r = o.get(s.from), i = o.get(s.to);
|
|
518
|
+
if (!r || !i)
|
|
519
|
+
return !1;
|
|
520
|
+
const { route: u } = Wt(s, r, i, {
|
|
521
|
+
routing: e
|
|
522
|
+
});
|
|
523
|
+
return bt(n, u.bounds);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
const kt = $t;
|
|
527
|
+
function Qt(t) {
|
|
528
|
+
return St(t);
|
|
529
|
+
}
|
|
530
|
+
function Zt(t) {
|
|
531
|
+
if (!t)
|
|
532
|
+
return null;
|
|
533
|
+
const n = t.toLowerCase();
|
|
534
|
+
return kt.find((e) => e.hex.toLowerCase() === n)?.preset ?? null;
|
|
535
|
+
}
|
|
536
|
+
function mt(t) {
|
|
537
|
+
return t ? /^[1-6]$/.test(t) ? Qt(t) : t : "";
|
|
538
|
+
}
|
|
539
|
+
export {
|
|
540
|
+
kt as E,
|
|
541
|
+
Nt as a,
|
|
542
|
+
Dt as b,
|
|
543
|
+
Qt as c,
|
|
544
|
+
ft as d,
|
|
545
|
+
Kt as e,
|
|
546
|
+
it as f,
|
|
547
|
+
Vt as g,
|
|
548
|
+
Wt as h,
|
|
549
|
+
Jt as i,
|
|
550
|
+
mt as j,
|
|
551
|
+
Zt as p,
|
|
552
|
+
et as r
|
|
553
|
+
};
|
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type BoardColorOption, type BoardColorPreset } from '@lupinum/board-core';
|
|
2
|
+
/** JSON Canvas color preset shared by nodes and edges. */
|
|
3
|
+
export type EdgeColorPreset = BoardColorPreset;
|
|
4
|
+
/** Edge-facing alias for the canonical board color option. */
|
|
5
|
+
export type EdgeColorOption = BoardColorOption;
|
|
6
|
+
/** Canonical JSON Canvas palette; edges and nodes intentionally share semantics. */
|
|
7
|
+
export declare const EDGE_COLOR_PRESETS: readonly EdgeColorOption[];
|
|
8
|
+
export declare function colorForPreset(preset: EdgeColorPreset): string;
|
|
9
|
+
export declare function presetForColor(color: string | undefined): EdgeColorPreset | null;
|
|
10
|
+
export declare function resolvePresetColor(color: string | undefined): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import { type BoardEngine, type BoardNode } from '@lupinum/board-core';
|
|
3
|
+
import type { ConnectionNodeHandle } from './hit-testing.js';
|
|
4
|
+
import type { ConnectionDragState, DragEnd } from './controller.js';
|
|
5
|
+
import type { BoardEdge, ConnectionEndpointMode, ConnectionsApi, ConnectionsEventMap, CreateNodeForConnectionContext } from './types.js';
|
|
6
|
+
type ConnectionEngine = BoardEngine<{
|
|
7
|
+
connections: ConnectionsApi;
|
|
8
|
+
}, ConnectionsEventMap>;
|
|
9
|
+
interface ConnectionActionsState {
|
|
10
|
+
hoveredEdgeId: Ref<string | null>;
|
|
11
|
+
hoveredNodeHandle: Ref<ConnectionNodeHandle | null>;
|
|
12
|
+
selectedEdgeId: Ref<string | null>;
|
|
13
|
+
editingEdgeId: Ref<string | null>;
|
|
14
|
+
labelDraft: Ref<string>;
|
|
15
|
+
colorMenuEdgeId: Ref<string | null>;
|
|
16
|
+
directionMenuEdgeId: Ref<string | null>;
|
|
17
|
+
}
|
|
18
|
+
interface ConnectionActionsDeps {
|
|
19
|
+
getEngine(): ConnectionEngine;
|
|
20
|
+
getEntry(edgeId: string): {
|
|
21
|
+
edge: BoardEdge;
|
|
22
|
+
} | undefined;
|
|
23
|
+
getRootElement(): HTMLElement | null;
|
|
24
|
+
getEndpointMode(): ConnectionEndpointMode;
|
|
25
|
+
createNodeForConnection(): ((context: CreateNodeForConnectionContext) => BoardNode | null) | null;
|
|
26
|
+
state: ConnectionActionsState;
|
|
27
|
+
}
|
|
28
|
+
/** Own edge editing and commit policy; the Vue layer only wires input/rendering. */
|
|
29
|
+
export declare function createConnectionActions(deps: ConnectionActionsDeps): {
|
|
30
|
+
onEdgePointerDown: (edgeId: string, event: PointerEvent) => void;
|
|
31
|
+
beginLabelEdit: (edgeId: string) => void;
|
|
32
|
+
commitLabelEdit: () => void;
|
|
33
|
+
clearLabel: (edgeId: string) => void;
|
|
34
|
+
cancelLabelEdit: () => void;
|
|
35
|
+
setDirectionality: (edgeId: string, direction: "none" | "to" | "both") => void;
|
|
36
|
+
applyEdgeColor: (edgeId: string, color: string | undefined) => void;
|
|
37
|
+
resetEndpointAnchor: (edgeId: string, end: DragEnd | "both") => void;
|
|
38
|
+
deleteEdge: (edgeId: string) => void;
|
|
39
|
+
commitDrag: (active: ConnectionDragState) => void;
|
|
40
|
+
};
|
|
41
|
+
export {};
|