-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapping.html
120 lines (116 loc) · 4.63 KB
/
snapping.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Patchbay.js - Snapping</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-white flex flex-col justify-center items-center h-screen">
<div class="max-w-lg w-full text-left pb-12 mb-12 border-b border-gray-200">
<a href="../examples/index.html" class="text-blue-600 inline-block hover:underline mb-4">
← Back to examples
</a>
<h1 class="mb-4 text-2xl font-bold">Snap - Cable ends are snapped to the closest port</h1>
<p class="text-gray-500">
By setting the <code>snapRadius</code> option, we can make the cable ends snap to the closest port.
</p>
</div>
<div class="bg-zinc-900 w-full max-w-lg flex flex-col gap-4 p-4 rounded-lg shadow-md">
<!-- Upper side -->
<div class="grid grid-cols-6 gap-2">
<div
id="input-1"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-2"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-3"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-4"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-5"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-6"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
</div>
<hr class="border-zinc-800" />
<!-- Lower side -->
<div class="grid grid-cols-6 gap-2">
<div
id="output-1"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-2"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-3"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-4"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-5"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-6"
class="cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
</div>
</div>
<script src="../dist/patchbay.umd.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const patchbay = new Patchbay({
snapRadius: 100,
});
patchbay.connect(document.getElementById("input-1"), document.getElementById("output-2"), {
color: "#FF0000",
});
patchbay.connect(document.getElementById("input-6"), document.getElementById("output-1"), {
color: "#00FF00",
});
patchbay.start();
});
</script>
</body>
</html>