-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigurations.html
267 lines (254 loc) · 10.1 KB
/
configurations.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Patchbay.js - Configurations</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 flex-col flex items-center space-y-12 h-screen py-6 px-4">
<section class="max-w-lg w-full">
<a href="../examples/index.html" class="text-blue-600 inline-block hover:underline mb-4">
← Back to examples
</a>
<div class="max-w-lg w-full mb-3">
<h2 class="mb-3 text-gray-700 text-2xl font-bold">Configuration</h2>
<p class="text-gray-500">
This example shows how all the configuration options of the library affect the behavior, appearance, and feel
of the patch bay.
</p>
</div>
<div class="bg-white p-4 rounded-lg border border-gray-300">
<form id="config-form" class="grid grid-cols-3 gap-4">
<div>
<label for="color" class="block text-sm font-medium text-gray-700">Cable Color</label>
<input
type="color"
id="color"
name="color"
value="#FF0000"
class="mt-1 block w-full rounded-md bg-white h-9 border border-gray-200"
/>
</div>
<div>
<label for="gravity" class="block text-sm font-medium text-gray-700">Gravity</label>
<input
type="number"
id="gravity"
name="gravity"
value="1"
step="0.1"
class="mt-1 block w-full rounded-md bg-white py-1 px-2 border border-gray-200 h-9"
/>
</div>
<div>
<label for="slack" class="block text-sm font-medium text-gray-700">Slack</label>
<input
type="number"
id="slack"
name="slack"
value="1.1"
step="0.1"
class="mt-1 block w-full rounded-md bg-white py-1 px-2 border border-gray-200 h-9"
/>
</div>
<div>
<label for="lineThickness" class="block text-sm font-medium text-gray-700">Line Thickness</label>
<input
type="number"
id="lineThickness"
name="lineThickness"
value="2"
class="mt-1 block w-full rounded-md bg-white py-1 px-2 border border-gray-200 h-9"
/>
</div>
<div>
<label for="iterations" class="block text-sm font-medium text-gray-700">Iterations</label>
<input
type="number"
id="iterations"
name="iterations"
value="5"
class="mt-1 block w-full rounded-md bg-white py-1 px-2 border border-gray-200 h-9"
/>
</div>
<div>
<label for="segments" class="block text-sm font-medium text-gray-700">Segments</label>
<input
type="number"
id="segments"
name="segments"
value="20"
class="mt-1 block w-full rounded-md bg-white py-1 px-2 border border-gray-200 h-9"
/>
</div>
<div>
<label for="dragHandleSize" class="block text-sm font-medium text-gray-700">Drag Handle Size</label>
<input
type="number"
id="dragHandleSize"
name="dragHandleSize"
value="20"
class="mt-1 block w-full rounded-md bg-white py-1 px-2 border border-gray-200 h-9"
/>
</div>
<div>
<label for="snapRadius" class="block text-sm font-medium text-gray-700">Snap Radius</label>
<input
type="number"
id="snapRadius"
name="snapRadius"
value="100"
class="mt-1 block w-full rounded-md bg-white py-1 px-2 border border-gray-200 h-9"
/>
</div>
<div class="col-span-full flex gap-2 justify-end mt-4">
<button
type="button"
id="move-cable"
class="bg-blue-600 text-sm text-white px-4 py-2 rounded-md hover:bg-blue-700 whitespace-nowrap"
>
Move Cable
</button>
<div class="w-full">
<!-- spacer -->
</div>
<button
type="button"
id="apply-config"
class="bg-blue-600 text-sm text-white px-4 py-2 rounded-md hover:bg-blue-700 whitespace-nowrap"
>
Apply Configuration
</button>
</div>
</form>
</div>
</section>
<section class="w-full max-w-lg">
<h2 class="mb-3 text-gray-700 text-2xl font-bold">Preview</h2>
<div class="bg-zinc-900 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>
</section>
<script src="../dist/patchbay.umd.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const patchbay = new Patchbay({
color: "#FF0000", // Default color
});
const start = document.getElementById("input-1");
const end = document.getElementById("output-6");
let cable = patchbay.connect(start, end);
patchbay.start();
document.getElementById("apply-config").addEventListener("click", function () {
const form = document.getElementById("config-form");
const formData = new FormData(form);
const color = formData.get("color");
const gravity = parseFloat(formData.get("gravity"));
const slack = parseFloat(formData.get("slack"));
const lineThickness = parseFloat(formData.get("lineThickness"));
const segments = parseInt(formData.get("segments"));
const dragHandleSize = parseInt(formData.get("dragHandleSize"));
const iterations = parseInt(formData.get("iterations"));
const snapRadius = parseInt(formData.get("snapRadius"));
patchbay.clear();
// Override the configuration
patchbay.config = Object.assign(patchbay.config, {
color,
gravity,
iterations,
slack,
lineThickness,
segments,
dragHandleSize,
snapRadius,
});
cable = patchbay.connect(start, end);
});
// Randomly move the "end" to a different slot on the lower side
document.getElementById("move-cable").addEventListener("click", function () {
const outputs = document.querySelectorAll("div[id^='output-']");
cable.end = outputs[Math.floor(Math.random() * outputs.length)];
});
});
</script>
</body>
</html>