@digitalmeadow/control-panel 1.0.6 → 1.0.8
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/dist/ControlPanel.d.ts +6 -0
- package/dist/ControlPanel.d.ts.map +1 -1
- package/dist/controllers/ButtonController.d.ts.map +1 -1
- package/dist/controllers/GradientController.d.ts.map +1 -1
- package/dist/controllers/NumberController.d.ts +0 -33
- package/dist/controllers/NumberController.d.ts.map +1 -1
- package/dist/controllers/RangeController.d.ts +42 -0
- package/dist/controllers/RangeController.d.ts.map +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +473 -284
- package/dist/index.umd.cjs +184 -62
- package/dist/signals/SignalHandler.d.ts.map +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/index.umd.cjs
CHANGED
|
@@ -1,50 +1,90 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(h,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(h=typeof globalThis<"u"?globalThis:h||self,L(h.ControlPanel={}))})(this,(function(h){"use strict";const L=`
|
|
2
2
|
.cp-root {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
--cp-color-1: rgba(255, 255, 255, 0.15);
|
|
4
|
+
--cp-color-2: rgba(255, 255, 255, 0.25);
|
|
5
|
+
--cp-color-3: rgba(255, 255, 255, 0.35);
|
|
6
|
+
--cp-color-4: rgba(255, 255, 255, 0.45);
|
|
7
|
+
--cp-border-radius: 0px;
|
|
8
|
+
--cp-swatch-size: 14px;
|
|
9
|
+
--cp-font-size-main: 10px;
|
|
10
|
+
--cp-font-size-details: 1.0em;
|
|
11
|
+
--cp-font-weight-bold: 500;
|
|
12
|
+
--cp-padding-v: 4px;
|
|
13
|
+
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 0;
|
|
16
|
+
right: 0;
|
|
17
|
+
width: min(280px, 90%);
|
|
7
18
|
max-height: 90vh;
|
|
8
19
|
overflow: auto;
|
|
9
20
|
background: transparent;
|
|
21
|
+
resize: both;
|
|
10
22
|
color: #fff;
|
|
11
|
-
|
|
23
|
+
min-width: 200px;
|
|
24
|
+
min-height: 50px;
|
|
12
25
|
font-family:
|
|
13
|
-
-
|
|
26
|
+
var(--cp-font-family), monospace,
|
|
14
27
|
sans-serif;
|
|
15
|
-
font-size:
|
|
16
|
-
line-height: 1
|
|
28
|
+
font-size: var(--cp-font-size-main);
|
|
29
|
+
line-height: 1;
|
|
17
30
|
padding: 8px;
|
|
18
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Apply blend mode to all children except color inputs */
|
|
34
|
+
.cp-root .cp-label,
|
|
35
|
+
.cp-root .cp-setting-label,
|
|
36
|
+
.cp-root .cp-summary,
|
|
37
|
+
.cp-root .cp-controller-summary,
|
|
38
|
+
.cp-root .cp-separator,
|
|
39
|
+
.cp-root .cp-value-display,
|
|
40
|
+
.cp-root .cp-button,
|
|
41
|
+
.cp-root .cp-input-number,
|
|
42
|
+
.cp-root .cp-input-range,
|
|
43
|
+
.cp-root .cp-select,
|
|
44
|
+
.cp-root .cp-radio,
|
|
45
|
+
.cp-root .cp-checkbox
|
|
46
|
+
{
|
|
47
|
+
mix-blend-mode: difference;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.cp-root .cp-input-color,
|
|
51
|
+
.cp-root .cp-color-swatch {
|
|
52
|
+
mix-blend-mode: normal;
|
|
53
|
+
isolation: isolate;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.cp-root:not([open]) .cp-summary-root {
|
|
57
|
+
opacity: 0.5;
|
|
19
58
|
}
|
|
20
59
|
|
|
21
60
|
.cp-root::-webkit-scrollbar {
|
|
22
61
|
width: 1px;
|
|
62
|
+
height: 1px;
|
|
23
63
|
}
|
|
24
64
|
.cp-root::-webkit-scrollbar-track {
|
|
25
65
|
background: transparent;
|
|
26
66
|
}
|
|
27
67
|
.cp-root::-webkit-scrollbar-thumb {
|
|
28
|
-
background:
|
|
68
|
+
background: var(--cp-color-4);
|
|
29
69
|
}
|
|
30
70
|
|
|
31
71
|
.cp-summary {
|
|
32
72
|
cursor: pointer;
|
|
33
73
|
user-select: none;
|
|
34
|
-
font-weight: bold;
|
|
74
|
+
font-weight: var(--cp-font-weight-bold);
|
|
35
75
|
outline: none;
|
|
36
76
|
}
|
|
37
77
|
|
|
38
78
|
.cp-summary-root {
|
|
39
79
|
position: sticky;
|
|
40
80
|
top: 0;
|
|
81
|
+
cursor: grab;
|
|
41
82
|
}
|
|
42
83
|
|
|
43
84
|
.cp-stats {
|
|
44
85
|
float: right;
|
|
45
86
|
font-weight: normal;
|
|
46
87
|
opacity: 0.6;
|
|
47
|
-
font-size: 0.9em;
|
|
48
88
|
font-variant-numeric: tabular-nums;
|
|
49
89
|
}
|
|
50
90
|
|
|
@@ -52,7 +92,7 @@
|
|
|
52
92
|
margin-top: 4px;
|
|
53
93
|
display: flex;
|
|
54
94
|
flex-direction: column;
|
|
55
|
-
gap:
|
|
95
|
+
gap: 2px;
|
|
56
96
|
}
|
|
57
97
|
|
|
58
98
|
.cp-folder {
|
|
@@ -61,16 +101,18 @@
|
|
|
61
101
|
|
|
62
102
|
.cp-folder-content {
|
|
63
103
|
margin: 0 0 6px 0;
|
|
64
|
-
padding: 4px 0 0
|
|
104
|
+
padding: 4px 0 0 0px;
|
|
65
105
|
}
|
|
66
106
|
|
|
67
107
|
.cp-controller {
|
|
68
|
-
|
|
108
|
+
min-height: 18px;
|
|
109
|
+
display: grid;
|
|
110
|
+
grid-template-columns: 50% 50%;
|
|
111
|
+
align-items: center;
|
|
69
112
|
}
|
|
70
113
|
|
|
71
114
|
.cp-label {
|
|
72
115
|
margin: auto 0;
|
|
73
|
-
width: 50%;
|
|
74
116
|
flex-shrink: 0;
|
|
75
117
|
overflow: hidden;
|
|
76
118
|
text-overflow: ellipsis;
|
|
@@ -81,14 +123,16 @@
|
|
|
81
123
|
}
|
|
82
124
|
|
|
83
125
|
.cp-input-number {
|
|
84
|
-
width: 50%;
|
|
85
126
|
background: transparent;
|
|
86
|
-
border: 1px solid
|
|
127
|
+
border: 1px solid var(--cp-color-2);
|
|
87
128
|
color: inherit;
|
|
88
129
|
padding: 2px 4px;
|
|
89
|
-
border-radius:
|
|
130
|
+
border-radius: var(--cp-border-radius);
|
|
90
131
|
font-family: inherit;
|
|
91
132
|
font-size: inherit;
|
|
133
|
+
height: 100%;
|
|
134
|
+
box-sizing: border-box;
|
|
135
|
+
}
|
|
92
136
|
}
|
|
93
137
|
|
|
94
138
|
.cp-input-number:focus {
|
|
@@ -98,49 +142,78 @@
|
|
|
98
142
|
}
|
|
99
143
|
|
|
100
144
|
.cp-select {
|
|
101
|
-
|
|
102
|
-
background:
|
|
145
|
+
color: inherit;
|
|
146
|
+
background: var(--cp-color-1);
|
|
103
147
|
border: none;
|
|
104
|
-
padding:
|
|
105
|
-
|
|
106
|
-
|
|
148
|
+
padding: var(--cp-padding-v) 4px;
|
|
149
|
+
padding-right: 18px;
|
|
150
|
+
border-radius: var(--cp-border-radius);
|
|
107
151
|
font-size: inherit;
|
|
152
|
+
line-height: inherit;
|
|
153
|
+
font-family: inherit;
|
|
154
|
+
box-sizing: border-box;
|
|
155
|
+
appearance: none;
|
|
156
|
+
-webkit-appearance: none;
|
|
157
|
+
-moz-appearance: none;
|
|
158
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='%23fff' d='M1 2h6l-3 4z'/%3E%3C/svg%3E");
|
|
159
|
+
background-repeat: no-repeat;
|
|
160
|
+
background-position: right 4px center;
|
|
108
161
|
}
|
|
109
162
|
|
|
110
163
|
.cp-checkbox {
|
|
111
164
|
margin: auto 0;
|
|
165
|
+
width: 14px;
|
|
166
|
+
height: 14px;
|
|
167
|
+
appearance: none;
|
|
168
|
+
-webkit-appearance: none;
|
|
169
|
+
-moz-appearance: none;
|
|
170
|
+
border: none !important;
|
|
171
|
+
border-radius: var(--cp-border-radius);
|
|
172
|
+
background: var(--cp-color-1) !important;
|
|
173
|
+
cursor: pointer;
|
|
174
|
+
padding: 0;
|
|
175
|
+
outline: none;
|
|
176
|
+
font-size: 0;
|
|
177
|
+
line-height: 0;
|
|
178
|
+
color: transparent;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.cp-checkbox:checked {
|
|
182
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='3' fill='%23fff'/%3E%3C/svg%3E") !important;
|
|
183
|
+
background-repeat: no-repeat !important;
|
|
184
|
+
background-position: center !important;
|
|
185
|
+
background-size: 8px 8px !important;
|
|
112
186
|
}
|
|
113
187
|
|
|
114
188
|
.cp-button {
|
|
115
|
-
|
|
116
|
-
|
|
189
|
+
grid-column: 1 / -1;
|
|
190
|
+
color: inherit;
|
|
191
|
+
background: var(--cp-color-1);
|
|
117
192
|
border: none;
|
|
118
|
-
padding:
|
|
119
|
-
border-radius:
|
|
193
|
+
padding: var(--cp-padding-v) 2px;
|
|
194
|
+
border-radius: var(--cp-border-radius);
|
|
120
195
|
cursor: pointer;
|
|
121
196
|
text-align: center;
|
|
122
197
|
font-family: inherit;
|
|
123
198
|
font-size: inherit;
|
|
124
|
-
|
|
199
|
+
line-height: inherit;
|
|
125
200
|
}
|
|
126
201
|
|
|
127
202
|
.cp-button:hover {
|
|
128
|
-
background:
|
|
203
|
+
background: var(--cp-color-2);
|
|
129
204
|
}
|
|
130
205
|
|
|
131
206
|
.cp-button:active {
|
|
132
|
-
background:
|
|
207
|
+
background: var(--cp-color-3);
|
|
133
208
|
transform: translateY(1px);
|
|
134
209
|
}
|
|
135
210
|
|
|
136
211
|
.cp-controller[data-disabled="true"] {
|
|
137
|
-
|
|
212
|
+
color: var(--cp-color-1);
|
|
138
213
|
pointer-events: none;
|
|
139
|
-
cursor: not-allowed;
|
|
140
214
|
}
|
|
141
215
|
|
|
142
216
|
.cp-controller-details {
|
|
143
|
-
width: 50%;
|
|
144
217
|
}
|
|
145
218
|
|
|
146
219
|
.cp-controller-summary {
|
|
@@ -151,8 +224,9 @@
|
|
|
151
224
|
.cp-controller-summary-content {
|
|
152
225
|
display: inline-flex;
|
|
153
226
|
align-items: center;
|
|
154
|
-
gap:
|
|
155
|
-
width: calc(100% -
|
|
227
|
+
gap: 4px;
|
|
228
|
+
width: calc(100% - 10px);
|
|
229
|
+
min-height: 18px;
|
|
156
230
|
vertical-align: middle;
|
|
157
231
|
}
|
|
158
232
|
|
|
@@ -161,7 +235,7 @@
|
|
|
161
235
|
flex: 1;
|
|
162
236
|
min-width: 0;
|
|
163
237
|
height: 2px;
|
|
164
|
-
background:
|
|
238
|
+
background: var(--cp-color-1);
|
|
165
239
|
margin: 0;
|
|
166
240
|
vertical-align: middle;
|
|
167
241
|
cursor: grab;
|
|
@@ -189,7 +263,7 @@
|
|
|
189
263
|
min-width: 24px;
|
|
190
264
|
text-align: right;
|
|
191
265
|
font-variant-numeric: tabular-nums;
|
|
192
|
-
font-size:
|
|
266
|
+
font-size: var(--cp-font-size-details);
|
|
193
267
|
opacity: 0.8;
|
|
194
268
|
user-select: none;
|
|
195
269
|
}
|
|
@@ -199,81 +273,129 @@
|
|
|
199
273
|
background: transparent;
|
|
200
274
|
display: flex;
|
|
201
275
|
flex-direction: column;
|
|
202
|
-
gap:
|
|
276
|
+
gap: 2px;
|
|
203
277
|
}
|
|
204
278
|
|
|
205
279
|
.cp-separator {
|
|
206
280
|
border: none;
|
|
207
|
-
border-top: 1px solid
|
|
281
|
+
border-top: 1px solid var(--cp-color-1);
|
|
208
282
|
margin: 4px 0;
|
|
209
283
|
width: 100%;
|
|
210
284
|
}
|
|
211
285
|
|
|
212
286
|
.cp-setting-row {
|
|
213
|
-
display:
|
|
287
|
+
display: grid;
|
|
288
|
+
grid-template-columns: 50% 50%;
|
|
214
289
|
align-items: center;
|
|
215
|
-
gap:
|
|
290
|
+
gap: 2px;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.cp-array-row {
|
|
294
|
+
display: grid;
|
|
295
|
+
grid-template-columns: auto 1fr;
|
|
296
|
+
align-items: stretch;
|
|
297
|
+
gap: 2px;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.cp-gradient-stop {
|
|
301
|
+
display: grid;
|
|
302
|
+
grid-template-columns: 50% 50%;
|
|
303
|
+
align-items: stretch;
|
|
304
|
+
gap: 2px;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.cp-gradient-stop-row {
|
|
308
|
+
display: grid;
|
|
309
|
+
grid-template-columns: auto 1fr auto;
|
|
310
|
+
align-items: center;
|
|
311
|
+
gap: 2px;
|
|
216
312
|
}
|
|
217
313
|
|
|
218
314
|
.cp-setting-label {
|
|
219
|
-
|
|
220
|
-
font-size: 0.9em;
|
|
315
|
+
font-size: var(--cp-font-size-details);
|
|
221
316
|
opacity: 0.7;
|
|
222
317
|
}
|
|
223
318
|
|
|
224
319
|
.cp-input-small {
|
|
225
|
-
width: 50%;
|
|
226
320
|
}
|
|
227
321
|
|
|
228
322
|
.cp-radios {
|
|
229
|
-
width: 50%;
|
|
230
323
|
display: flex;
|
|
231
324
|
gap: 2px;
|
|
232
325
|
}
|
|
233
326
|
|
|
234
327
|
.cp-radio {
|
|
235
328
|
flex: 1;
|
|
236
|
-
font-size:
|
|
237
|
-
padding:
|
|
238
|
-
height: 100%;
|
|
329
|
+
font-size: var(--cp-font-size-details);
|
|
330
|
+
padding: var(--cp-padding-v) 2px;
|
|
239
331
|
}
|
|
240
332
|
|
|
241
333
|
.cp-radio[data-active="true"] {
|
|
242
|
-
background:
|
|
334
|
+
background: var(--cp-color-3);
|
|
243
335
|
border-color: #fff;
|
|
244
|
-
font-weight: bold;
|
|
336
|
+
font-weight: var(--cp-font-weight-bold);
|
|
245
337
|
}
|
|
246
338
|
|
|
247
339
|
.cp-button-delete {
|
|
248
|
-
|
|
340
|
+
grid-column: auto;
|
|
341
|
+
width: 100%;
|
|
342
|
+
min-width: 18px;
|
|
249
343
|
padding: 0;
|
|
250
344
|
display: flex;
|
|
251
345
|
align-items: center;
|
|
252
346
|
justify-content: center;
|
|
253
347
|
line-height: 1;
|
|
348
|
+
height: 100%;
|
|
254
349
|
}
|
|
255
350
|
|
|
256
351
|
.cp-input-color {
|
|
352
|
+
width: var(--cp-swatch-size);
|
|
353
|
+
height: var(--cp-swatch-size);
|
|
354
|
+
border: 1px solid var(--cp-color-1);
|
|
355
|
+
-webkit-appearance: none;
|
|
356
|
+
}
|
|
357
|
+
.cp-input-color::-webkit-color-swatch-wrapper {
|
|
257
358
|
padding: 0;
|
|
258
|
-
|
|
359
|
+
}
|
|
360
|
+
.cp-input-color::-webkit-color-swatch {
|
|
259
361
|
border: none;
|
|
260
|
-
|
|
261
|
-
|
|
362
|
+
border-radius: var(--cp-border-radius);
|
|
363
|
+
}
|
|
262
364
|
|
|
263
|
-
|
|
264
|
-
|
|
365
|
+
.cp-checkbox {
|
|
366
|
+
margin: auto 0;
|
|
367
|
+
width: 14px;
|
|
368
|
+
height: 14px;
|
|
369
|
+
appearance: none;
|
|
370
|
+
-webkit-appearance: none;
|
|
371
|
+
-moz-appearance: none;
|
|
372
|
+
border: 1px solid var(--cp-color-1);
|
|
373
|
+
border-radius: var(--cp-border-radius);
|
|
374
|
+
background: transparent;
|
|
265
375
|
cursor: pointer;
|
|
376
|
+
padding: 0;
|
|
377
|
+
outline: none;
|
|
378
|
+
font-size: 0;
|
|
379
|
+
line-height: 0;
|
|
380
|
+
color: transparent;
|
|
381
|
+
vertical-align: middle;
|
|
382
|
+
display: inline-block;
|
|
383
|
+
box-sizing: border-box;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.cp-checkbox:checked {
|
|
387
|
+
background: var(--cp-color-1);
|
|
266
388
|
}
|
|
267
389
|
|
|
268
390
|
.cp-color-swatch {
|
|
269
|
-
width:
|
|
270
|
-
height:
|
|
391
|
+
width: var(--cp-swatch-size);
|
|
392
|
+
height: var(--cp-swatch-size);
|
|
271
393
|
margin-right: 8px;
|
|
272
394
|
}
|
|
273
395
|
|
|
274
396
|
.cp-stops-container {
|
|
275
397
|
display: flex;
|
|
276
398
|
flex-direction: column;
|
|
277
|
-
gap:
|
|
399
|
+
gap: 2px;
|
|
278
400
|
}
|
|
279
|
-
`;let O=!1;function et(){if(O)return;const n=document.createElement("style");n.id="control-panel-styles",n.textContent=N,document.head.appendChild(n),O=!0}function r(n,t={},e=[]){const s=document.createElement(n);for(const[i,a]of Object.entries(t))i==="className"?s.className=String(a):i==="style"&&typeof a=="object"?Object.assign(s.style,a):i==="open"&&typeof a=="boolean"?a?s.setAttribute("open",""):s.removeAttribute("open"):typeof a!="object"&&s.setAttribute(i,String(a));for(const i of e)typeof i=="string"?s.appendChild(document.createTextNode(i)):s.appendChild(i);return s}function F(n){const t=r("button",{className:"cp-button cp-button-delete"},["×"]);return t.addEventListener("click",n),t}function st(n){return n.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()).trim()}function D(n,t,e){return Math.min(Math.max(n,t),e)}function it(n,t,e){if(t.length!==e.length)throw new Error("Input and output ranges must have the same length");if(t.length<2)throw new Error("Input and output ranges must have at least two values");let s=0;for(;s<t.length-1&&n>t[s+1];)s++;if(s===t.length-1)return e[e.length-1];if(s===0&&n<t[0])return e[0];const i=t[s],a=t[s+1],o=e[s],c=e[s+1];return(n-i)/(a-i)*(c-o)+o}class B{constructor(){this.source=null,this.stream=null,this.fftSize=2048,this.smoothingTimeConstant=.82,this.spectrumBoost=3,this.levels={volume:0,bass:0,mids:0,highs:0},this.peaks={volume:0,bass:0,mids:0,highs:0},this._isAnalyzing=!1,this.loop=()=>{this._isAnalyzing&&(requestAnimationFrame(this.loop),this.update())};const t=window.AudioContext||window.webkitAudioContext;this.ctx=new t,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=this.fftSize,this.analyser.smoothingTimeConstant=this.smoothingTimeConstant,this.dataArray=new Uint8Array(this.analyser.frequencyBinCount),this.waveformArray=new Uint8Array(this.analyser.frequencyBinCount)}setFFTSize(t){this.fftSize=t,this.analyser.fftSize=t,this.dataArray=new Uint8Array(this.analyser.frequencyBinCount),this.waveformArray=new Uint8Array(this.analyser.frequencyBinCount)}async setInput(t){try{let e;t==="browser"?e=navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}):e=navigator.mediaDevices.getUserMedia({audio:!0});const s=await e;this.ctx.state==="suspended"&&this.ctx.resume(),this.source&&this.source.disconnect(),this.stream&&this.stream.getTracks().forEach(i=>i.stop()),this.stream=s,this.source=this.ctx.createMediaStreamSource(this.stream),this.source.connect(this.analyser),this._isAnalyzing=!0,this.loop()}catch(e){console.error("Error accessing audio input:",e),this._isAnalyzing=!1}}update(){if(this.analyser.getByteFrequencyData(this.dataArray),this.analyser.getByteTimeDomainData(this.waveformArray),this.spectrumBoost!==1){const p=this.dataArray.length;for(let h=0;h<p;h++){const f=1+h/p*(this.spectrumBoost-1);this.dataArray[h]=Math.min(255,this.dataArray[h]*f)}}const t=[2,10],e=[10,150],s=[150,600],i=this.getAverage(t[0],t[1]),a=this.getAverage(e[0],e[1]),o=this.getAverage(s[0],s[1]),c=this.getAverage(0,s[1]);this.processLevel("bass",i),this.processLevel("mids",a),this.processLevel("highs",o),this.processLevel("volume",c)}processLevel(t,e){this.peaks[t]-=5e-4,this.peaks[t]=D(this.peaks[t],.1,1),e>this.peaks[t]&&(this.peaks[t]=e),this.levels[t]=D(it(e,[0,this.peaks[t]],[0,1]),0,1)}getAverage(t,e){let s=0;const i=e-t;if(i<=0)return 0;for(let a=t;a<e;a++)s+=this.dataArray[a];return s/i/255}getSignal(t){return()=>this.levels[t]}}const x=new B;class q{constructor(){this.midiAccess=null,this.values=new Map,this.isListening=!1,this.resolveListen=null,this.listeningCallback=null,this.init()}async init(){if(typeof navigator<"u"&&navigator.requestMIDIAccess)try{this.midiAccess=await navigator.requestMIDIAccess(),this.setupInputs(),this.midiAccess.onstatechange=t=>{t.port.type==="input"&&t.port.state==="connected"&&this.setupInputs()}}catch(t){console.warn("MIDI Access failed",t)}}setupInputs(){if(!this.midiAccess)return;const t=this.midiAccess.inputs.values();for(const e of t)e.onmidimessage=this.handleMessage.bind(this)}handleMessage(t){const e=t.data,[s]=e;if((s&240)>=240)return;const a=this.getIdFromMessage(t),o=this.normalizeValue(e);this.values.set(a,o),this.isListening&&this.resolveListen&&o>0&&(this.resolveListen(a),this.isListening=!1,this.resolveListen=null,this.listeningCallback&&this.listeningCallback())}getIdFromMessage(t){const e=t.data,[s,i]=e,a=s&240,o=t.currentTarget.name||"unknown",c=a===144||a===128?"note":"ctrl",p=o.replace(/[^a-zA-Z0-9]/g,"");return`${i}_${c}_${p}`}normalizeValue(t){const[e,s,i]=t,a=e&240;return a===144?i>0?1:0:a===128?0:a===176?i/127:0}listen(){return this.isListening=!0,new Promise(t=>{this.resolveListen=t})}cancelListen(){this.isListening=!1,this.resolveListen=null}getSignal(t){return()=>this.values.get(t)??0}}const z=new q;class R{constructor(){this.configs=new Map,this.lastRandomUpdateTime=0,this.currentRandomValue=0,this.startTime=performance.now(),this.configs.set("constant",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("sine",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("sawtooth",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("triangle",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("square",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("random",{frequency:10,amplitude:1,offset:0,phase:0})}setConfig(t,e){const s=this.configs.get(t);this.configs.set(t,{...s,...e})}getConfig(t){return{...this.configs.get(t)}}getTime(){return(performance.now()-this.startTime)/1e3}normalizeOutput(t,e){const s=t*e.amplitude+e.offset;return Math.max(0,Math.min(1,s))}constant(t){const e=t?{...this.configs.get("constant"),...t}:this.configs.get("constant"),i=this.getTime()*e.frequency%1;return this.normalizeOutput(i,e)}sine(t){const e=t?{...this.configs.get("sine"),...t}:this.configs.get("sine"),s=this.getTime(),i=e.phase*Math.PI*2,o=(Math.sin(s*e.frequency*Math.PI*2+i)+1)/2;return this.normalizeOutput(o,e)}sawtooth(t){const e=t?{...this.configs.get("sawtooth"),...t}:this.configs.get("sawtooth"),s=this.getTime(),i=e.phase,a=(s*e.frequency+i)%1+i%1;return this.normalizeOutput(a%1,e)}triangle(t){const e=t?{...this.configs.get("triangle"),...t}:this.configs.get("triangle"),s=this.getTime(),i=e.phase,a=(s*e.frequency+i)%1,o=a<.5?a*2:2-a*2;return this.normalizeOutput(o,e)}square(t){const e=t?{...this.configs.get("square"),...t}:this.configs.get("square"),s=this.getTime(),i=e.phase,o=(s*e.frequency+i)%1<.5?0:1;return this.normalizeOutput(o,e)}random(t){const e=t?{...this.configs.get("random"),...t}:this.configs.get("random"),s=performance.now(),i=1e3/e.frequency;return s-this.lastRandomUpdateTime>i&&(this.currentRandomValue=Math.random(),this.lastRandomUpdateTime=s),this.normalizeOutput(this.currentRandomValue,e)}getSignal(t){switch(t){case"constant":return()=>this.constant();case"sine":return()=>this.sine();case"sawtooth":return()=>this.sawtooth();case"triangle":return()=>this.triangle();case"square":return()=>this.square();case"random":return()=>this.random()}}reset(){this.startTime=performance.now(),this.lastRandomUpdateTime=0,this.currentRandomValue=0}}const j=new R,E=class E{constructor(t,e,s={}){this.changeFns=new Set,this.object=t,this.property=e,this.key=s.id??e,this.initialValue=this.object[this.property],this.domElement=r("div",{className:"cp-controller"});const i=s.label??st(e),a=r("label",{className:"cp-label"},[String(i)]);a.setAttribute("title",String(i)),this.domElement.appendChild(a),s.disabled&&this.domElement.setAttribute("data-disabled","true")}get value(){return this.object[this.property]}setValue(t,e=!0){this.object[this.property]=t,e&&this.emitChange(t),this.updateDisplay()}save(){return this.value}load(t){this.setValue(t)}reset(){this.setValue(this.initialValue)}onChange(t){return this.changeFns.add(t),this}emitChange(t){for(const e of this.changeFns)e(t)}appendWidget(t){this.domElement.appendChild(t)}};E.audio=x,E.midi=z,E.math=j;let u=E;const $={linear:n=>n,quadIn:n=>n*n,quadOut:n=>n*(2-n),quadInOut:n=>n<.5?2*n*n:-1+(4-2*n)*n,cubicIn:n=>n*n*n,cubicOut:n=>--n*n*n+1,cubicInOut:n=>n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1,expoIn:n=>n===0?0:Math.pow(2,10*(n-1)),expoOut:n=>n===1?1:-Math.pow(2,-10*n)+1,expoInOut:n=>n===0||n===1?n:(n*=2)<1?.5*Math.pow(2,10*(n-1)):.5*(-Math.pow(2,-10*--n)+2),sineIn:n=>1-Math.cos(n*Math.PI/2),sineOut:n=>Math.sin(n*Math.PI/2),sineInOut:n=>-(Math.cos(Math.PI*n)-1)/2};class U{constructor(t){this.rafId=null,this.currentSignalType=null,this.currentMidiId=null,this.currentEase="linear",this.currentBehaviour="forward",this.loop=()=>{if(this.currentSignalType){let e=0;this.currentSignalType==="midi"?this.currentMidiId&&(e=u.midi.getSignal(this.currentMidiId)()):["constant","sine","sawtooth","triangle","square","random"].includes(this.currentSignalType)?e=u.math.getSignal(this.currentSignalType)():["volume","bass","mids","highs"].includes(this.currentSignalType)&&(e=u.audio.getSignal(this.currentSignalType)());const s=$[this.currentEase](e);this.onChange(s,this.currentBehaviour),this.rafId=requestAnimationFrame(this.loop)}},this.onChange=t.onChange,this.setupControllers(t.container)}setupControllers(t){const e=this.createSettingSelect("signal",["none","volume","bass","mids","highs","constant","sine","sawtooth","triangle","square","random","midi"],o=>this.setSignalType(o));this.signalSelect=e.select,t.appendChild(e.row),this.midiRow=r("div",{className:"cp-setting-row",style:"display: none;"});const s=r("label",{className:"cp-setting-label"},["Midi"]);this.midiBtn=r("button",{className:"cp-button cp-input-small"},["Learn"]),this.midiBtn.addEventListener("click",async()=>{if(this.midiBtn.textContent==="Listening..."){u.midi.cancelListen(),this.setMidiId(null);return}this.midiBtn.textContent="Listening...";const o=await u.midi.listen();this.setMidiId(o)}),this.midiRow.appendChild(s),this.midiRow.appendChild(this.midiBtn),t.appendChild(this.midiRow),this.mathParamsContainer=r("div",{style:"display: none; flex-direction: column; gap: 4px;"}),t.appendChild(this.mathParamsContainer);const i=this.createSettingSelect("behaviour",["forward","backward","loopForward","loopBackward","pingpong"],o=>this.setBehaviour(o));this.behaviourRow=i.row,this.behaviourSelect=i.select,this.behaviourRow.style.display="none",this.behaviourSelect.value=this.currentBehaviour,t.appendChild(this.behaviourRow);const a=this.createSettingSelect("ease",Object.keys($),o=>this.setEase(o));this.easeRow=a.row,this.easeSelect=a.select,this.easeRow.style.display="none",this.easeSelect.value=this.currentEase,t.appendChild(this.easeRow)}createSettingSelect(t,e,s){const i=r("div",{className:"cp-setting-row"}),a=r("label",{className:"cp-setting-label"},[t]),o=r("select",{className:"cp-select cp-input-small"});return e.forEach(c=>{const p=r("option",{value:c},[c]);o.appendChild(p)}),o.addEventListener("change",()=>s(o.value)),i.appendChild(a),i.appendChild(o),{row:i,select:o}}createNumberInput(t,e,s,i,a,o){const c=r("div",{className:"cp-setting-row"}),p=r("label",{className:"cp-setting-label"},[t]),h=r("input",{className:"cp-input-number cp-input-small",type:"number",value:String(e),min:String(s),max:String(i),step:String(a)});return h.addEventListener("input",()=>{const m=parseFloat(h.value);isNaN(m)||o(m)}),c.appendChild(p),c.appendChild(h),{row:c,input:h}}updateMathParams(t){this.mathParamsContainer.innerHTML="";const e=u.math.getConfig(t);let s="Frequency",i=.1,a=10,o=.1;t==="random"?a=30:t==="constant"&&(s="Speed",i=.01,a=2,o=.01);const c=this.createNumberInput(s,e.frequency,i,a,o,m=>u.math.setConfig(t,{frequency:m}));this.mathParamsContainer.appendChild(c.row);const p=this.createNumberInput("Amplitude",e.amplitude,0,2,.1,m=>u.math.setConfig(t,{amplitude:m}));this.mathParamsContainer.appendChild(p.row);const h=this.createNumberInput("Offset",e.offset,0,1,.1,m=>u.math.setConfig(t,{offset:m}));if(this.mathParamsContainer.appendChild(h.row),["sine","sawtooth","triangle","square"].includes(t)){const m=this.createNumberInput("Phase",e.phase,0,1,.01,f=>u.math.setConfig(t,{phase:f}));this.mathParamsContainer.appendChild(m.row)}}setSignalType(t){if(!t||t==="none")this.currentSignalType=null,this.currentMidiId=null,this.midiRow.style.display="none",this.mathParamsContainer.style.display="none",this.easeRow.style.display="none",this.behaviourRow.style.display="none",this.stop(),this.signalSelect.value!=="none"&&(this.signalSelect.value="none");else{this.currentSignalType=t;const e=t==="midi",s=["constant","sine","sawtooth","triangle","square","random"].includes(t),i=["volume","bass","mids","highs"].includes(t);this.midiRow.style.display=e?"flex":"none",this.mathParamsContainer.style.display=s?"flex":"none",s&&this.updateMathParams(t),this.easeRow.style.display="flex",this.behaviourRow.style.display="flex",i?(this.currentMidiId=null,u.audio.ctx.state==="suspended"&&u.audio.setInput("microphone")):e||(this.currentMidiId=null),this.start(),this.signalSelect.value!==t&&(this.signalSelect.value=t)}}setMidiId(t){this.currentMidiId=t,this.midiBtn.textContent=t??"Learn"}setEase(t){this.currentEase=t,this.easeSelect.value!==t&&(this.easeSelect.value=t)}setBehaviour(t){this.currentBehaviour=t,this.behaviourSelect.value!==t&&(this.behaviourSelect.value=t)}start(){!this.rafId&&this.currentSignalType&&this.loop()}stop(){this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null)}save(){return{type:this.currentSignalType,midiId:this.currentMidiId,ease:this.currentEase,behaviour:this.currentBehaviour}}load(t){t&&(this.setSignalType(t.type),this.setMidiId(t.midiId||null),this.setEase(t.ease||"linear"),this.setBehaviour(t.behaviour||"forward"))}reset(){this.setSignalType("none"),this.setEase("linear"),this.setBehaviour("forward"),this.setMidiId(null)}}class H extends u{constructor(t,e,s={}){super(t,e,s),this.pingPongDirection=1,this.min=0,this.max=100,this.initialOptions=s,this.min=s.min??0,this.max=s.max??100;const i=r("details",{className:"cp-controller-details"}),a=r("summary",{className:"cp-controller-summary"});this.input=r("input",{type:"range",className:"cp-input-range",step:s.step??"any"}),s.min!==void 0&&(this.input.min=String(s.min)),s.max!==void 0&&(this.input.max=String(s.max)),this.input.value=String(this.value),this.display=r("span",{className:"cp-value-display"},[String(this.value.toFixed(1))]),this.input.addEventListener("input",()=>{const l=parseFloat(this.input.value);isNaN(l)||(this.setValue(l),this.display.textContent=String(l.toFixed(1)))}),this.input.addEventListener("click",l=>{l.stopPropagation()});const o=r("div",{className:"cp-controller-summary-content"});o.appendChild(this.input),o.appendChild(this.display),a.appendChild(o),i.appendChild(a);const c=r("div",{className:"cp-number-settings"}),p=this.createSetting("min",s.min,l=>this.setMin(l));this.minInput=p.input,c.appendChild(p.row);const h=this.createSetting("max",s.max,l=>this.setMax(l));this.maxInput=h.input,c.appendChild(h.row);const m=this.createSetting("step",s.step,l=>this.setStep(l));this.stepInput=m.input,c.appendChild(m.row);const f=r("hr",{className:"cp-separator"});c.appendChild(f),this.signalHandler=new U({container:c,onChange:(l,g)=>this.applySignal(l,g)}),i.appendChild(c),this.appendWidget(i)}setMin(t){typeof t=="number"&&(t=String(t)),t===""||isNaN(parseFloat(t))?this.input.removeAttribute("min"):(this.input.min=t,this.min=parseFloat(t)),this.minInput&&this.minInput.value!==t&&(this.minInput.value=t)}setMax(t){typeof t=="number"&&(t=String(t)),t===""||isNaN(parseFloat(t))?this.input.removeAttribute("max"):(this.input.max=t,this.max=parseFloat(t)),this.maxInput&&this.maxInput.value!==t&&(this.maxInput.value=t)}setStep(t){t===void 0&&(t=""),typeof t=="number"&&(t=String(t)),t===""||t==="any"||isNaN(parseFloat(t))?this.input.step="any":this.input.step=t,this.stepInput&&(t==="any"||t===""?this.stepInput.value="":this.stepInput.value!==t&&(this.stepInput.value=t))}applySignal(t,e){const s=this.max-this.min;let i;if(e==="forward")i=this.min+t*s;else if(e==="backward")i=this.max-t*s;else{const a=t*(s*.01);i=this.value,e==="loopForward"?(i+=a,i>this.max&&(i=this.min+(i-this.min)%s)):e==="loopBackward"?(i-=a,i<this.min&&(i=this.max-(this.max-i)%s)):e==="pingpong"&&(i+=a*this.pingPongDirection,i>=this.max?(i=this.max,this.pingPongDirection=-1):i<=this.min&&(i=this.min,this.pingPongDirection=1))}i=this.roundToStep(i),this.setValue(i),this.input.value=String(i),this.display.textContent=String(i.toFixed(1))}roundToStep(t){const e=this.input.step;if(e==="any"||e===""||isNaN(parseFloat(e)))return t;const s=parseFloat(e),i=this.min;return i+Math.round((t-i)/s)*s}createSetting(t,e,s){const i=r("div",{className:"cp-setting-row"}),a=r("label",{className:"cp-setting-label"},[t]),o=r("input",{type:"number",className:"cp-input-number cp-input-small",step:"any"});return e!==void 0&&(o.value=String(e)),o.addEventListener("input",()=>s(o.value)),i.appendChild(a),i.appendChild(o),{row:i,input:o}}updateDisplay(){this.input.value=String(this.value),this.display.textContent=String(this.value.toFixed(1))}save(){return{value:this.value,settings:{min:this.min,max:this.max,step:this.input.step,signal:this.signalHandler.save()}}}load(t){if(typeof t=="number")this.setValue(t),this.resetSettings();else if(typeof t=="object"&&t!==null&&"value"in t){const e=t.settings||{};e.min!==void 0?this.setMin(e.min):this.setMin(this.initialOptions.min!==void 0?this.initialOptions.min:""),e.max!==void 0?this.setMax(e.max):this.setMax(this.initialOptions.max!==void 0?this.initialOptions.max:""),e.step!==void 0?this.setStep(e.step):this.setStep(this.initialOptions.step);let s=t.value;!isNaN(this.min)&&s<this.min&&(s=this.min),!isNaN(this.max)&&s>this.max&&(s=this.max),this.setValue(s),this.signalHandler?.load(e.signal)}}reset(){this.setValue(this.initialValue),this.resetSettings()}resetSettings(){this.setMin(this.initialOptions.min!==void 0?this.initialOptions.min:""),this.setMax(this.initialOptions.max!==void 0?this.initialOptions.max:""),this.setStep(this.initialOptions.step),this.signalHandler?.reset()}}class W extends u{constructor(t,e,s){super(t,e,s),this.optionValues=[],this.select=r("select",{className:"cp-select"}),this.optionValues=s.options||[],this.optionValues.forEach((i,a)=>{const o=r("option",{value:String(a)},[String(i)]);this.select.appendChild(o)}),this.updateDisplay(),this.select.addEventListener("change",()=>{const i=parseInt(this.select.value),a=this.optionValues[i];this.setValue(a)}),this.appendWidget(this.select)}setOptions(t){this.select.innerHTML="",this.optionValues=t,this.optionValues.forEach((e,s)=>{const i=r("option",{value:String(s)},[String(e)]);this.select.appendChild(i)}),this.updateDisplay(),this.select.value===""&&this.optionValues.length>0&&this.setValue(this.optionValues[0])}updateDisplay(){const t=this.optionValues.indexOf(this.value);t!==-1&&(this.select.value=String(t))}}class _ extends u{constructor(t,e,s={}){const i={action:e};super(i,"action",s);const a=s.label??t;this.button=r("button",{className:"cp-button"},[String(a)]),this.button.addEventListener("click",()=>{const o=this.value;typeof o=="function"&&o(),this.emitChange(o)}),this.appendWidget(this.button)}updateDisplay(){}}class J extends u{constructor(t,e,s={}){super(t,e,s),this.input=r("input",{type:"checkbox",className:"cp-checkbox"}),this.input.checked=this.value,this.input.addEventListener("change",()=>{this.setValue(this.input.checked)}),this.appendWidget(this.input)}updateDisplay(){this.input.checked=this.value}}class G extends u{constructor(t,e,s){super(t,e,s),this.buttons=[],this.optionValues=[],this.container=r("div",{className:"cp-radios"}),this.optionValues=s.options||[],this.optionValues.forEach(i=>{const a=r("button",{className:"cp-button cp-radio"},[String(i)]);a.addEventListener("click",()=>{this.setValue(i)}),this.container.appendChild(a),this.buttons.push(a)}),this.updateDisplay(),this.appendWidget(this.container)}updateDisplay(){const t=this.value;this.buttons.forEach((e,s)=>{this.optionValues[s]===t?e.setAttribute("data-active","true"):e.removeAttribute("data-active")})}}class Z extends u{constructor(t,e,s={}){super(t,e,s),this.input=r("input",{type:"color",className:"cp-input-color",value:this.value||"#000000"}),this.appendWidget(this.input),this.input.addEventListener("input",i=>{const a=i.target;this.setValue(a.value)}),this.updateDisplay()}updateDisplay(){this.input.value=this.value}}function K(n){const t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;n=n.replace(t,(s,i,a,o)=>i+i+a+a+o+o);const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return e?[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]:[0,0,0]}function nt(n,t,e){return"#"+((1<<24)+(Math.round(n)<<16)+(Math.round(t)<<8)+Math.round(e)).toString(16).slice(1)}function I(n){const t=n/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function A(n){return n<=.0031308?n*12.92*255:(1.055*Math.pow(n,1/2.4)-.055)*255}function at(n,t,e){const[s,i,a]=K(n),[o,c,p]=K(t),h=I(s),m=I(i),f=I(a),l=I(o),g=I(c),y=I(p),v=h+e*(l-h),T=m+e*(g-m),S=f+e*(y-f),C=A(v),b=A(T),w=A(S);return nt(C,b,w)}class Y extends u{constructor(t,e,s={}){super(t,e,s),this.stops=[],this.pingPongDirection=1,this.animationT=0,this.manualPosition=0,this.initialOptions=s,this.stops=s.stops||[{color:"#000000",position:0},{color:"#ffffff",position:1}],this.sortStops();const i=r("details",{className:"cp-controller-details"}),a=r("summary",{className:"cp-controller-summary"}),o=r("div",{className:"cp-controller-summary-content"});this.displayColor=r("div",{className:"cp-color-swatch",style:`background-color: ${this.value}`}),this.displayText=r("span",{className:"cp-value-display"},[String(this.value)]),o.appendChild(this.displayColor),o.appendChild(this.displayText),a.appendChild(o),i.appendChild(a);const c=r("div",{className:"cp-number-settings"});this.stopsContainer=r("div",{className:"cp-stops-container"}),this.renderStops(),c.appendChild(this.stopsContainer);const p=r("button",{className:"cp-button"},["+ Add Stop"]);p.addEventListener("click",()=>{this.stops.push({color:"#ffffff",position:.5}),this.sortStops(),this.renderStops(),this.updateOutput()}),c.appendChild(p);const h=r("hr",{className:"cp-separator"});c.appendChild(h),this.signalHandler=new U({container:c,onChange:(m,f)=>this.applySignal(m,f)}),i.appendChild(c),this.appendWidget(i),this.updateOutput(0)}sortStops(){this.stops.sort((t,e)=>t.position-e.position)}renderStops(){this.stopsContainer.innerHTML="",this.stops.forEach((t,e)=>{const s=r("div",{className:"cp-setting-row"}),i=r("input",{type:"color",className:"cp-input-color",value:t.color});i.addEventListener("input",c=>{t.color=c.target.value,this.updateOutput()});const a=r("input",{type:"number",className:"cp-input-number cp-input-small",min:"0",max:"1",step:"0.01",value:String(t.position)});a.addEventListener("change",c=>{let p=parseFloat(c.target.value);isNaN(p)&&(p=0),t.position=Math.max(0,Math.min(1,p)),this.sortStops(),this.renderStops(),this.updateOutput()});const o=F(()=>{this.stops.splice(e,1),this.renderStops(),this.updateOutput()});s.appendChild(i),s.appendChild(a),s.appendChild(o),this.stopsContainer.appendChild(s)})}updateOutput(t=this.manualPosition){if(this.stops.length===0)return;if(this.stops.length===1){this.setValue(this.stops[0].color),this.updateDisplay();return}let e="#000000";if(t=Math.max(0,Math.min(1,t)),t<=this.stops[0].position)e=this.stops[0].color;else if(t>=this.stops[this.stops.length-1].position)e=this.stops[this.stops.length-1].color;else for(let s=0;s<this.stops.length-1;s++){const i=this.stops[s],a=this.stops[s+1];if(t>=i.position&&t<=a.position){const o=a.position-i.position,c=o===0?0:(t-i.position)/o;e=at(i.color,a.color,c);break}}this.setValue(e),this.updateDisplay()}updateDisplay(){this.displayColor&&(this.displayColor.style.backgroundColor=this.value),this.displayText&&(this.displayText.textContent=this.value)}applySignal(t,e){let s=t;if(e==="forward")s=t;else if(e==="backward")s=1-t;else{const i=t*.05;e==="loopForward"?(this.animationT=(this.animationT+i)%1,s=this.animationT):e==="loopBackward"?(this.animationT=(this.animationT-i+1)%1,s=this.animationT):e==="pingpong"&&(this.animationT+=i*this.pingPongDirection,this.animationT>=1?(this.animationT=1,this.pingPongDirection=-1):this.animationT<=0&&(this.animationT=0,this.pingPongDirection=1),s=this.animationT)}this.updateOutput(s),this.manualPosition=s}save(){return{stops:this.stops,settings:{signal:this.signalHandler.save()}}}load(t){t&&t.stops&&(this.stops=t.stops,this.sortStops(),this.renderStops()),t&&t.settings&&this.signalHandler?.load(t.settings.signal)}reset(){this.stops=this.initialOptions.stops||[{color:"#000000",position:0},{color:"#ffffff",position:1}],this.sortStops(),this.renderStops(),this.signalHandler?.reset(),this.updateOutput(0)}}class Q extends u{constructor(t,e,s={}){super(t,e,s),this.items=[],this.initialOptions=s,this.itemType=s.itemType||"string",this.items=this.parseValue(this.value);const i=r("details",{className:"cp-controller-details"}),a=r("summary",{className:"cp-controller-summary"}),o=r("div",{className:"cp-controller-summary-content"}),c=r("span",{className:"cp-value-display"},[`${this.items.length} items`]);o.appendChild(c),a.appendChild(o),i.appendChild(a);const p=r("div",{className:"cp-number-settings"});this.itemsContainer=r("div",{className:"cp-stops-container"}),this.renderItems(),p.appendChild(this.itemsContainer);const h=r("button",{className:"cp-button cp-input-small",style:"margin-top: 8px; width: 100%;"},["+ Add Item"]);h.addEventListener("click",()=>{this.addItem()}),p.appendChild(h),i.appendChild(p),this.appendWidget(i)}parseValue(t){return!t||t.trim()===""?[]:t.split(",").map(e=>e.trim())}serializeValue(){return this.items.join(",")}getDefaultItemValue(){switch(this.itemType){case"color":return"#ffffff";case"number":return"0";default:return""}}addItem(t){const e=t!==void 0?t:this.getDefaultItemValue();this.items.push(e),this.renderItems(),this.updateValue()}updateValue(){const t=this.serializeValue();this.setValue(t),this.updateSummary()}updateSummary(){const t=this.domElement.querySelector(".cp-value-display");t&&(t.textContent=`${this.items.length} items`)}renderItems(){this.itemsContainer.innerHTML="",this.items.forEach((t,e)=>{const s=r("div",{className:"cp-setting-row"});let i;this.itemType==="color"?i=r("input",{type:"color",className:"cp-input-color",value:t}):this.itemType==="number"?i=r("input",{type:"number",className:"cp-input-number cp-input-small",step:"any",value:t}):i=r("input",{type:"text",className:"cp-input-number cp-input-small",value:t}),i.addEventListener("input",o=>{this.items[e]=o.target.value,this.updateValue()});const a=F(()=>{this.items.splice(e,1),this.renderItems(),this.updateValue()});s.appendChild(i),s.appendChild(a),this.itemsContainer.appendChild(s)})}updateDisplay(){}save(){return[...this.items]}load(t){Array.isArray(t)?this.items=[...t]:typeof t=="string"&&(this.items=this.parseValue(t)),this.renderItems(),this.updateValue()}reset(){const t=this.initialValue||"";this.items=this.parseValue(t),this.renderItems(),this.updateValue()}}class ot{constructor(){this.frames=0,this.pollingInterval=1e3,this.prevTime=performance.now(),this.render=()=>{this.frames++;const t=performance.now();if(t>=this.prevTime+this.pollingInterval){const e=Math.round(this.frames*1e3/(t-this.prevTime));let s="";const i=performance.memory;i&&(s=` / ${Math.round(i.usedJSHeapSize/1048576)}MB`),this.domElement.textContent=`${e} FPS${s}`,this.prevTime=t,this.frames=0}this.rafId=requestAnimationFrame(this.render)},this.domElement=r("span",{className:"cp-stats"}),this.rafId=requestAnimationFrame(this.render)}destroy(){cancelAnimationFrame(this.rafId)}}class P{constructor(){this.controllers=[],this.folders=[]}addNumber(t,e,s={}){const i=new H(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addSelect(t,e,s={}){const i=new W(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addBoolean(t,e,s={}){const i=new J(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addButton(t,e,s={}){const i=new _(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addRadio(t,e,s={}){const i=new G(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addColor(t,e,s={}){const i=new Z(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addGradient(t,e,s={}){const i=new Y(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addArray(t,e,s={}){const i=new Q(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addFolder(t){const e=new X(t);return this.contentElement.appendChild(e.domElement),this.folders.push(e),e}save(){const t={controllers:{},folders:{}};for(const e of this.controllers)typeof e.value!="function"&&(t.controllers[e.key]=e.save());for(const e of this.folders)t.folders[e.title]=e.save();return t}load(t){if(!t){this.reset();return}for(const e of this.controllers)if(typeof e.value!="function")if(t.controllers&&e.key in t.controllers){const s=t.controllers[e.key];s!==void 0&&e.load(s)}else e.reset();for(const e of this.folders){const s=t.folders?t.folders[e.title]:void 0;e.load(s)}}reset(){for(const t of this.controllers)typeof t.value!="function"&&t.reset();for(const t of this.folders)t.reset()}}class X extends P{constructor(t){super(),this.title=t,this.domElement=r("details",{className:"cp-folder",open:!0}),this.summaryElement=r("summary",{className:"cp-summary"},[t]),this.domElement.appendChild(this.summaryElement),this.contentElement=r("div",{className:"cp-content cp-folder-content"}),this.domElement.appendChild(this.contentElement),this.domElement.appendChild(r("hr",{className:"cp-separator"}))}}class rt extends P{constructor(t,e={}){super(),et(),this.domElement=r("details",{className:"cp-root",open:!0}),this.summaryElement=r("summary",{className:"cp-summary cp-summary-root"}),this.domElement.appendChild(this.summaryElement);const s=r("span",{},[e.title||"ControlPanel"]);this.summaryElement.appendChild(s),this.stats=new ot,this.summaryElement.appendChild(this.stats.domElement),this.contentElement=r("div",{className:"cp-content"}),this.domElement.appendChild(this.contentElement);const i=this.addFolder("_Signals"),a={audioInput:null,fftSize:2048};i.addRadio(a,"audioInput",{label:"Audio Signal",options:["microphone","browser"]}).onChange(l=>{x.setInput(l)}),i.addSelect(a,"fftSize",{label:"FFT Size",options:[256,512,1024,2048]}).onChange(l=>{x.setFFTSize(l)}),i.addNumber(x,"smoothingTimeConstant",{min:0,max:.99,step:.01,label:"Smoothing"}).onChange(l=>{x.analyser.smoothingTimeConstant=l}),i.addNumber(x,"spectrumBoost",{min:1,max:5,step:.1,label:"Compression"}),t?t.appendChild(this.domElement):document.body.appendChild(this.domElement);const o=e.title||"ControlPanel";this.presetStoragePrefix=`cp-presets-${o}-`;const c=this.addFolder("_User Presets"),p=()=>{const l=["Default"];if(typeof localStorage>"u")return l;for(let g=0;g<localStorage.length;g++){const y=localStorage.key(g);if(y&&y.startsWith(this.presetStoragePrefix)){const v=y.substring(this.presetStoragePrefix.length);v!=="Default"&&!l.includes(v)&&l.push(v)}}return l.sort()},h={selected:"Default",save:()=>{const l=prompt("Preset Name:",h.selected);if(l){if(l==="Default"){alert("Cannot overwrite Default preset");return}const g=this.presetStoragePrefix+l;this.saveToLocalStorage(g);const y=p();f.setOptions(y),h.selected=l,f.setValue(l)}},load:()=>{const l=h.selected,g=this.presetStoragePrefix+l;this.loadFromLocalStorage(g),h.selected=l,f.setValue(l)},delete:()=>{if(h.selected==="Default"){alert("Cannot delete Default preset");return}if(confirm(`Delete preset "${h.selected}"?`)){const l=this.presetStoragePrefix+h.selected;localStorage.removeItem(l);const g=p();f.setOptions(g),h.selected="Default",f.setValue("Default"),this.reset()}},export:()=>{const l=this.save(),g=L=>{const M={controllers:{},folders:{}};for(const[k,V]of Object.entries(L.controllers))k.startsWith("_")||(M.controllers[k]=V);for(const[k,V]of Object.entries(L.folders))k.startsWith("_")||(M.folders[k]=g(V));return M},y=g(l),v={_presetName:h.selected||"CustomPreset",_exportDate:new Date().toISOString(),_instructions:"To add as factory preset: Copy 'controllers' and 'folders' fields into the presets.json file",...y},T=JSON.stringify(v,null,2),S=new Blob([T],{type:"application/json"}),C=URL.createObjectURL(S),b=document.createElement("a");b.href=C;const w=new Date().toISOString().split("T")[0],tt=h.selected.replace(/[^a-z0-9]/gi,"-").toLowerCase();b.download=`${o.toLowerCase()}-preset-${tt}-${w}.json`,document.body.appendChild(b),b.click(),document.body.removeChild(b),URL.revokeObjectURL(C)},import:()=>{const l=document.createElement("input");l.type="file",l.accept=".json",l.onchange=g=>{const y=g.target.files?.[0];if(!y)return;const v=new FileReader;v.onload=T=>{try{const S=T.target?.result,C=JSON.parse(S),b={controllers:C.controllers||{},folders:C.folders||{}};if(!b.controllers||!b.folders){alert("Invalid preset file: missing 'controllers' or 'folders'");return}this.load(b);const w=C._presetName||"ImportedPreset";if(confirm(`Preset loaded! Save as "${w}" to User Presets?`)){const L=this.presetStoragePrefix+w;this.saveToLocalStorage(L);const M=p();f.setOptions(M),h.selected=w,f.setValue(w)}}catch(S){alert(`Failed to import preset: ${S instanceof Error?S.message:"Invalid JSON"}`),console.error("Import error:",S)}},v.readAsText(y)},l.click()}},m=p(),f=c.addSelect(h,"selected",{label:"Preset",options:m});c.addButton("Load",()=>h.load()),c.addButton("Save / New",()=>h.save()),c.addButton("Delete",()=>h.delete()),c.addButton("Export JSON",()=>h.export()),c.addButton("Import JSON",()=>h.import())}saveToLocalStorage(t){const e=this.save();try{localStorage.setItem(t,JSON.stringify(e))}catch(s){console.warn("ControlPanel: Failed to save to localStorage",s)}}loadFromLocalStorage(t){try{const e=localStorage.getItem(t);if(e){const s=JSON.parse(e);this.load(s)}}catch(e){console.warn("ControlPanel: Failed to load from localStorage",e)}}saveDefaultPreset(){const t=this.presetStoragePrefix+"Default";this.save(),this.saveToLocalStorage(t)}destroy(){this.stats.destroy(),this.domElement.remove(),this.controllers=[],this.folders=[]}}d.ArrayController=Q,d.AudioSignals=B,d.BooleanController=J,d.ButtonController=_,d.ColorController=Z,d.ControlPanel=rt,d.ControlPanelContainer=P,d.Controller=u,d.Folder=X,d.GradientController=Y,d.MathSignals=R,d.MidiSignals=q,d.NumberController=H,d.RadioController=G,d.SelectController=W,d.audioSignals=x,d.mathSignals=j,d.midiSignals=z,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
|
401
|
+
`;let R=!1;function lt(){if(R)return;const n=document.createElement("style");n.id="control-panel-styles",n.textContent=L,document.head.appendChild(n),R=!0}function o(n,t={},e=[]){const s=document.createElement(n);for(const[i,a]of Object.entries(t))i==="className"?s.className=String(a):i==="style"&&typeof a=="object"?Object.assign(s.style,a):i==="open"&&typeof a=="boolean"?a?s.setAttribute("open",""):s.removeAttribute("open"):typeof a!="object"&&s.setAttribute(i,String(a));for(const i of e)typeof i=="string"?s.appendChild(document.createTextNode(i)):s.appendChild(i);return s}function j(n){const t=o("button",{className:"cp-button cp-button-delete"},["×"]);return t.addEventListener("click",n),t}function ct(n){return n.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()).trim()}function $(n,t,e){return Math.min(Math.max(n,t),e)}function pt(n,t,e){if(t.length!==e.length)throw new Error("Input and output ranges must have the same length");if(t.length<2)throw new Error("Input and output ranges must have at least two values");let s=0;for(;s<t.length-1&&n>t[s+1];)s++;if(s===t.length-1)return e[e.length-1];if(s===0&&n<t[0])return e[0];const i=t[s],a=t[s+1],r=e[s],l=e[s+1];return(n-i)/(a-i)*(l-r)+r}class H{constructor(){this.source=null,this.stream=null,this.fftSize=2048,this.smoothingTimeConstant=.82,this.spectrumBoost=3,this.levels={volume:0,bass:0,mids:0,highs:0},this.peaks={volume:0,bass:0,mids:0,highs:0},this._isAnalyzing=!1,this.loop=()=>{this._isAnalyzing&&(requestAnimationFrame(this.loop),this.update())};const t=window.AudioContext||window.webkitAudioContext;this.ctx=new t,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=this.fftSize,this.analyser.smoothingTimeConstant=this.smoothingTimeConstant,this.dataArray=new Uint8Array(this.analyser.frequencyBinCount),this.waveformArray=new Uint8Array(this.analyser.frequencyBinCount)}setFFTSize(t){this.fftSize=t,this.analyser.fftSize=t,this.dataArray=new Uint8Array(this.analyser.frequencyBinCount),this.waveformArray=new Uint8Array(this.analyser.frequencyBinCount)}async setInput(t){try{let e;t==="browser"?e=navigator.mediaDevices.getDisplayMedia({audio:!0,video:!0}):e=navigator.mediaDevices.getUserMedia({audio:!0});const s=await e;this.ctx.state==="suspended"&&this.ctx.resume(),this.source&&this.source.disconnect(),this.stream&&this.stream.getTracks().forEach(i=>i.stop()),this.stream=s,this.source=this.ctx.createMediaStreamSource(this.stream),this.source.connect(this.analyser),this._isAnalyzing=!0,this.loop()}catch(e){console.error("Error accessing audio input:",e),this._isAnalyzing=!1}}update(){if(this.analyser.getByteFrequencyData(this.dataArray),this.analyser.getByteTimeDomainData(this.waveformArray),this.spectrumBoost!==1){const p=this.dataArray.length;for(let u=0;u<p;u++){const b=1+u/p*(this.spectrumBoost-1);this.dataArray[u]=Math.min(255,this.dataArray[u]*b)}}const t=[2,10],e=[10,150],s=[150,600],i=this.getAverage(t[0],t[1]),a=this.getAverage(e[0],e[1]),r=this.getAverage(s[0],s[1]),l=this.getAverage(0,s[1]);this.processLevel("bass",i),this.processLevel("mids",a),this.processLevel("highs",r),this.processLevel("volume",l)}processLevel(t,e){this.peaks[t]-=5e-4,this.peaks[t]=$(this.peaks[t],.1,1),e>this.peaks[t]&&(this.peaks[t]=e),this.levels[t]=$(pt(e,[0,this.peaks[t]],[0,1]),0,1)}getAverage(t,e){let s=0;const i=e-t;if(i<=0)return 0;for(let a=t;a<e;a++)s+=this.dataArray[a];return s/i/255}getSignal(t){return()=>this.levels[t]}}const E=new H;class U{constructor(){this.midiAccess=null,this.values=new Map,this.isListening=!1,this.resolveListen=null,this.listeningCallback=null,this.init()}async init(){if(typeof navigator<"u"&&navigator.requestMIDIAccess)try{this.midiAccess=await navigator.requestMIDIAccess(),this.setupInputs(),this.midiAccess.onstatechange=t=>{t.port.type==="input"&&t.port.state==="connected"&&this.setupInputs()}}catch(t){console.warn("MIDI Access failed",t)}}setupInputs(){if(!this.midiAccess)return;const t=this.midiAccess.inputs.values();for(const e of t)e.onmidimessage=this.handleMessage.bind(this)}handleMessage(t){const e=t.data,[s]=e;if((s&240)>=240)return;const a=this.getIdFromMessage(t),r=this.normalizeValue(e);this.values.set(a,r),this.isListening&&this.resolveListen&&r>0&&(this.resolveListen(a),this.isListening=!1,this.resolveListen=null,this.listeningCallback&&this.listeningCallback())}getIdFromMessage(t){const e=t.data,[s,i]=e,a=s&240,r=t.currentTarget.name||"unknown",l=a===144||a===128?"note":"ctrl",p=r.replace(/[^a-zA-Z0-9]/g,"");return`${i}_${l}_${p}`}normalizeValue(t){const[e,s,i]=t,a=e&240;return a===144?i>0?1:0:a===128?0:a===176?i/127:0}listen(){return this.isListening=!0,new Promise(t=>{this.resolveListen=t})}cancelListen(){this.isListening=!1,this.resolveListen=null}getSignal(t){return()=>this.values.get(t)??0}}const W=new U;class _{constructor(){this.configs=new Map,this.lastRandomUpdateTime=0,this.currentRandomValue=0,this.startTime=performance.now(),this.configs.set("constant",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("sine",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("sawtooth",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("triangle",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("square",{frequency:.1,amplitude:1,offset:0,phase:0}),this.configs.set("random",{frequency:10,amplitude:1,offset:0,phase:0})}setConfig(t,e){const s=this.configs.get(t);this.configs.set(t,{...s,...e})}getConfig(t){return{...this.configs.get(t)}}getTime(){return(performance.now()-this.startTime)/1e3}normalizeOutput(t,e){const s=t*e.amplitude+e.offset;return Math.max(0,Math.min(1,s))}constant(t){const e=t?{...this.configs.get("constant"),...t}:this.configs.get("constant"),i=this.getTime()*e.frequency%1;return this.normalizeOutput(i,e)}sine(t){const e=t?{...this.configs.get("sine"),...t}:this.configs.get("sine"),s=this.getTime(),i=e.phase*Math.PI*2,r=(Math.sin(s*e.frequency*Math.PI*2+i)+1)/2;return this.normalizeOutput(r,e)}sawtooth(t){const e=t?{...this.configs.get("sawtooth"),...t}:this.configs.get("sawtooth"),s=this.getTime(),i=e.phase,a=(s*e.frequency+i)%1+i%1;return this.normalizeOutput(a%1,e)}triangle(t){const e=t?{...this.configs.get("triangle"),...t}:this.configs.get("triangle"),s=this.getTime(),i=e.phase,a=(s*e.frequency+i)%1,r=a<.5?a*2:2-a*2;return this.normalizeOutput(r,e)}square(t){const e=t?{...this.configs.get("square"),...t}:this.configs.get("square"),s=this.getTime(),i=e.phase,r=(s*e.frequency+i)%1<.5?0:1;return this.normalizeOutput(r,e)}random(t){const e=t?{...this.configs.get("random"),...t}:this.configs.get("random"),s=performance.now(),i=1e3/e.frequency;return s-this.lastRandomUpdateTime>i&&(this.currentRandomValue=Math.random(),this.lastRandomUpdateTime=s),this.normalizeOutput(this.currentRandomValue,e)}getSignal(t){switch(t){case"constant":return()=>this.constant();case"sine":return()=>this.sine();case"sawtooth":return()=>this.sawtooth();case"triangle":return()=>this.triangle();case"square":return()=>this.square();case"random":return()=>this.random()}}reset(){this.startTime=performance.now(),this.lastRandomUpdateTime=0,this.currentRandomValue=0}}const J=new _,A=class A{constructor(t,e,s={}){this.changeFns=new Set,this.object=t,this.property=e,this.key=s.id??e,this.initialValue=this.object[this.property],this.domElement=o("div",{className:"cp-controller"});const i=s.label??ct(e),a=o("label",{className:"cp-label"},[String(i)]);a.setAttribute("title",String(i)),this.domElement.appendChild(a),s.disabled&&this.domElement.setAttribute("data-disabled","true")}get value(){return this.object[this.property]}setValue(t,e=!0){this.object[this.property]=t,e&&this.emitChange(t),this.updateDisplay()}save(){return this.value}load(t){this.setValue(t)}reset(){this.setValue(this.initialValue)}onChange(t){return this.changeFns.add(t),this}emitChange(t){for(const e of this.changeFns)e(t)}appendWidget(t){this.domElement.appendChild(t)}};A.audio=E,A.midi=W,A.math=J;let d=A;class Y extends d{constructor(t,e,s={}){super(t,e,s),this.input=o("input",{type:"number",className:"cp-input-number",value:String(this.value)}),this.input.addEventListener("input",()=>{}),this.input.addEventListener("blur",()=>{const i=parseFloat(this.input.value);isNaN(i)?this.input.value=String(this.value):this.setValue(i)}),this.input.addEventListener("keydown",i=>{i.key==="Enter"&&this.input.blur()}),this.appendWidget(this.input)}updateDisplay(){this.input.value=String(this.value)}}const X={linear:n=>n,quadIn:n=>n*n,quadOut:n=>n*(2-n),quadInOut:n=>n<.5?2*n*n:-1+(4-2*n)*n,cubicIn:n=>n*n*n,cubicOut:n=>--n*n*n+1,cubicInOut:n=>n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1,expoIn:n=>n===0?0:Math.pow(2,10*(n-1)),expoOut:n=>n===1?1:-Math.pow(2,-10*n)+1,expoInOut:n=>n===0||n===1?n:(n*=2)<1?.5*Math.pow(2,10*(n-1)):.5*(-Math.pow(2,-10*--n)+2),sineIn:n=>1-Math.cos(n*Math.PI/2),sineOut:n=>Math.sin(n*Math.PI/2),sineInOut:n=>-(Math.cos(Math.PI*n)-1)/2};class G{constructor(t){this.rafId=null,this.currentSignalType=null,this.currentMidiId=null,this.currentEase="linear",this.currentBehaviour="forward",this.loop=()=>{if(this.currentSignalType){let e=0;this.currentSignalType==="midi"?this.currentMidiId&&(e=d.midi.getSignal(this.currentMidiId)()):["constant","sine","sawtooth","triangle","square","random"].includes(this.currentSignalType)?e=d.math.getSignal(this.currentSignalType)():["volume","bass","mids","highs"].includes(this.currentSignalType)&&(e=d.audio.getSignal(this.currentSignalType)());const s=X[this.currentEase](e);this.onChange(s,this.currentBehaviour),this.rafId=requestAnimationFrame(this.loop)}},this.onChange=t.onChange,this.setupControllers(t.container)}setupControllers(t){const e=this.createSettingSelect("signal",["none","volume","bass","mids","highs","constant","sine","sawtooth","triangle","square","random","midi"],l=>this.setSignalType(l));this.signalSelect=e.select,t.appendChild(e.row),this.midiRow=o("div",{className:"cp-setting-row",style:"display: none;"});const s=o("label",{className:"cp-setting-label"},["Midi"]);this.midiBtn=o("button",{className:"cp-button cp-input-small"},["Learn"]),this.midiBtn.addEventListener("click",async()=>{if(this.midiBtn.textContent==="Listening..."){d.midi.cancelListen(),this.setMidiId(null);return}this.midiBtn.textContent="Listening...";const l=await d.midi.listen();this.setMidiId(l)}),this.midiRow.appendChild(s),this.midiRow.appendChild(this.midiBtn),t.appendChild(this.midiRow),this.mathParamsContainer=o("div",{style:"display: none; flex-direction: column; gap: 4px;"}),t.appendChild(this.mathParamsContainer);const i=this.createSettingSelect("behaviour",["forward","backward","loopForward","loopBackward","pingpong"],l=>this.setBehaviour(l));this.behaviourRow=i.row,this.behaviourSelect=i.select,this.behaviourRow.style.display="none",this.behaviourSelect.value=this.currentBehaviour,t.appendChild(this.behaviourRow);const a=this.createSettingSelect("ease",Object.keys(X),l=>this.setEase(l));this.easeRow=a.row,this.easeSelect=a.select,this.easeRow.style.display="none",this.easeSelect.value=this.currentEase,t.appendChild(this.easeRow);const r=o("hr",{className:"cp-separator"});t.appendChild(r)}createSettingSelect(t,e,s){const i=o("div",{className:"cp-setting-row"}),a=o("label",{className:"cp-setting-label"},[t]),r=o("select",{className:"cp-select cp-input-small"});return e.forEach(l=>{const p=o("option",{value:l},[l]);r.appendChild(p)}),r.addEventListener("change",()=>s(r.value)),i.appendChild(a),i.appendChild(r),{row:i,select:r}}createNumberInput(t,e,s,i,a,r){const l=o("div",{className:"cp-setting-row"}),p=o("label",{className:"cp-setting-label"},[t]),u=o("input",{className:"cp-input-number cp-input-small",type:"number",value:String(e),min:String(s),max:String(i),step:String(a)});return u.addEventListener("input",()=>{const m=parseFloat(u.value);isNaN(m)||r(m)}),l.appendChild(p),l.appendChild(u),{row:l,input:u}}updateMathParams(t){this.mathParamsContainer.innerHTML="";const e=d.math.getConfig(t);let s="Frequency",i=.1,a=10,r=.1;t==="random"?a=30:t==="constant"&&(s="Speed",i=.01,a=2,r=.01);const l=this.createNumberInput(s,e.frequency,i,a,r,m=>d.math.setConfig(t,{frequency:m}));this.mathParamsContainer.appendChild(l.row);const p=this.createNumberInput("Amplitude",e.amplitude,0,2,.1,m=>d.math.setConfig(t,{amplitude:m}));this.mathParamsContainer.appendChild(p.row);const u=this.createNumberInput("Offset",e.offset,0,1,.1,m=>d.math.setConfig(t,{offset:m}));if(this.mathParamsContainer.appendChild(u.row),["sine","sawtooth","triangle","square"].includes(t)){const m=this.createNumberInput("Phase",e.phase,0,1,.01,b=>d.math.setConfig(t,{phase:b}));this.mathParamsContainer.appendChild(m.row)}}setSignalType(t){if(!t||t==="none")this.currentSignalType=null,this.currentMidiId=null,this.midiRow.style.display="none",this.mathParamsContainer.style.display="none",this.easeRow.style.display="none",this.behaviourRow.style.display="none",this.stop(),this.signalSelect.value!=="none"&&(this.signalSelect.value="none");else{this.currentSignalType=t;const e=t==="midi",s=["constant","sine","sawtooth","triangle","square","random"].includes(t),i=["volume","bass","mids","highs"].includes(t);this.midiRow.style.display=e?"grid":"none",this.mathParamsContainer.style.display=s?"grid":"none",s&&this.updateMathParams(t),this.easeRow.style.display="grid",this.behaviourRow.style.display="grid",i?(this.currentMidiId=null,d.audio.ctx.state==="suspended"&&d.audio.setInput("microphone")):e||(this.currentMidiId=null),this.start(),this.signalSelect.value!==t&&(this.signalSelect.value=t)}}setMidiId(t){this.currentMidiId=t,this.midiBtn.textContent=t??"Learn"}setEase(t){this.currentEase=t,this.easeSelect.value!==t&&(this.easeSelect.value=t)}setBehaviour(t){this.currentBehaviour=t,this.behaviourSelect.value!==t&&(this.behaviourSelect.value=t)}start(){!this.rafId&&this.currentSignalType&&this.loop()}stop(){this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null)}save(){return{type:this.currentSignalType,midiId:this.currentMidiId,ease:this.currentEase,behaviour:this.currentBehaviour}}load(t){t&&(this.setSignalType(t.type),this.setMidiId(t.midiId||null),this.setEase(t.ease||"linear"),this.setBehaviour(t.behaviour||"forward"))}reset(){this.setSignalType("none"),this.setEase("linear"),this.setBehaviour("forward"),this.setMidiId(null)}}class Z extends d{constructor(t,e,s={}){super(t,e,s),this.pingPongDirection=1,this.min=0,this.max=100,this.initialOptions=s,this.min=s.min??0,this.max=s.max??100;const i=o("details",{className:"cp-controller-details"}),a=o("summary",{className:"cp-controller-summary"});this.input=o("input",{type:"range",className:"cp-input-range",step:s.step??"any"}),s.min!==void 0&&(this.input.min=String(s.min)),s.max!==void 0&&(this.input.max=String(s.max)),this.input.value=String(this.value),this.display=o("span",{className:"cp-value-display"},[String(this.value.toFixed(1))]),this.input.addEventListener("input",()=>{const y=parseFloat(this.input.value);isNaN(y)||(this.setValue(y),this.display.textContent=String(y.toFixed(1)))}),this.input.addEventListener("click",y=>{y.stopPropagation()});const r=o("div",{className:"cp-controller-summary-content"});r.appendChild(this.input),r.appendChild(this.display),a.appendChild(r),i.appendChild(a);const l=o("div",{className:"cp-number-settings"}),p=this.createSetting("min",s.min,y=>this.setMin(y));this.minInput=p.input,l.appendChild(p.row);const u=this.createSetting("max",s.max,y=>this.setMax(y));this.maxInput=u.input,l.appendChild(u.row);const m=this.createSetting("step",s.step,y=>this.setStep(y));this.stepInput=m.input,l.appendChild(m.row);const b=o("hr",{className:"cp-separator"});l.appendChild(b),this.signalHandler=new G({container:l,onChange:(y,S)=>this.applySignal(y,S)}),i.appendChild(l),this.appendWidget(i)}setMin(t){typeof t=="number"&&(t=String(t)),t===""||isNaN(parseFloat(t))?this.input.removeAttribute("min"):(this.input.min=t,this.min=parseFloat(t)),this.minInput&&this.minInput.value!==t&&(this.minInput.value=t)}setMax(t){typeof t=="number"&&(t=String(t)),t===""||isNaN(parseFloat(t))?this.input.removeAttribute("max"):(this.input.max=t,this.max=parseFloat(t)),this.maxInput&&this.maxInput.value!==t&&(this.maxInput.value=t)}setStep(t){t===void 0&&(t=""),typeof t=="number"&&(t=String(t)),t===""||t==="any"||isNaN(parseFloat(t))?this.input.step="any":this.input.step=t,this.stepInput&&(t==="any"||t===""?this.stepInput.value="":this.stepInput.value!==t&&(this.stepInput.value=t))}applySignal(t,e){const s=this.max-this.min;let i;if(e==="forward")i=this.min+t*s;else if(e==="backward")i=this.max-t*s;else{const a=t*(s*.01);i=this.value,e==="loopForward"?(i+=a,i>this.max&&(i=this.min+(i-this.min)%s)):e==="loopBackward"?(i-=a,i<this.min&&(i=this.max-(this.max-i)%s)):e==="pingpong"&&(i+=a*this.pingPongDirection,i>=this.max?(i=this.max,this.pingPongDirection=-1):i<=this.min&&(i=this.min,this.pingPongDirection=1))}i=this.roundToStep(i),this.setValue(i),this.input.value=String(i),this.display.textContent=String(i.toFixed(1))}roundToStep(t){const e=this.input.step;if(e==="any"||e===""||isNaN(parseFloat(e)))return t;const s=parseFloat(e),i=this.min;return i+Math.round((t-i)/s)*s}createSetting(t,e,s){const i=o("div",{className:"cp-setting-row"}),a=o("label",{className:"cp-setting-label"},[t]),r=o("input",{type:"number",className:"cp-input-number cp-input-small",step:"any"});return e!==void 0&&(r.value=String(e)),r.addEventListener("input",()=>s(r.value)),i.appendChild(a),i.appendChild(r),{row:i,input:r}}updateDisplay(){this.input.value=String(this.value),this.display.textContent=String(this.value.toFixed(1))}save(){return{value:this.value,settings:{min:this.min,max:this.max,step:this.input.step,signal:this.signalHandler.save()}}}load(t){if(typeof t=="number")this.setValue(t),this.resetSettings();else if(typeof t=="object"&&t!==null&&"value"in t){const e=t.settings||{};e.min!==void 0?this.setMin(e.min):this.setMin(this.initialOptions.min!==void 0?this.initialOptions.min:""),e.max!==void 0?this.setMax(e.max):this.setMax(this.initialOptions.max!==void 0?this.initialOptions.max:""),e.step!==void 0?this.setStep(e.step):this.setStep(this.initialOptions.step);let s=t.value;!isNaN(this.min)&&s<this.min&&(s=this.min),!isNaN(this.max)&&s>this.max&&(s=this.max),this.setValue(s),this.signalHandler?.load(e.signal)}}reset(){this.setValue(this.initialValue),this.resetSettings()}resetSettings(){this.setMin(this.initialOptions.min!==void 0?this.initialOptions.min:""),this.setMax(this.initialOptions.max!==void 0?this.initialOptions.max:""),this.setStep(this.initialOptions.step),this.signalHandler?.reset()}}class K extends d{constructor(t,e,s){super(t,e,s),this.optionValues=[],this.select=o("select",{className:"cp-select"}),this.optionValues=s.options||[],this.optionValues.forEach((i,a)=>{const r=o("option",{value:String(a)},[String(i)]);this.select.appendChild(r)}),this.updateDisplay(),this.select.addEventListener("change",()=>{const i=parseInt(this.select.value),a=this.optionValues[i];this.setValue(a)}),this.appendWidget(this.select)}setOptions(t){this.select.innerHTML="",this.optionValues=t,this.optionValues.forEach((e,s)=>{const i=o("option",{value:String(s)},[String(e)]);this.select.appendChild(i)}),this.updateDisplay(),this.select.value===""&&this.optionValues.length>0&&this.setValue(this.optionValues[0])}updateDisplay(){const t=this.optionValues.indexOf(this.value);t!==-1&&(this.select.value=String(t))}}class Q extends d{constructor(t,e,s={}){const i={action:e};super(i,"action",s),this.domElement.querySelector(".cp-label")?.remove();const a=s.label??t;this.button=o("button",{className:"cp-button"},[String(a)]),this.button.addEventListener("click",()=>{const r=this.value;typeof r=="function"&&r(),this.emitChange(r)}),this.appendWidget(this.button)}updateDisplay(){}}class tt extends d{constructor(t,e,s={}){super(t,e,s),this.input=o("input",{type:"checkbox",className:"cp-checkbox"}),this.input.checked=this.value,this.input.addEventListener("change",()=>{this.setValue(this.input.checked)}),this.appendWidget(this.input)}updateDisplay(){this.input.checked=this.value}}class et extends d{constructor(t,e,s){super(t,e,s),this.buttons=[],this.optionValues=[],this.container=o("div",{className:"cp-radios"}),this.optionValues=s.options||[],this.optionValues.forEach(i=>{const a=o("button",{className:"cp-button cp-radio"},[String(i)]);a.addEventListener("click",()=>{this.setValue(i)}),this.container.appendChild(a),this.buttons.push(a)}),this.updateDisplay(),this.appendWidget(this.container)}updateDisplay(){const t=this.value;this.buttons.forEach((e,s)=>{this.optionValues[s]===t?e.setAttribute("data-active","true"):e.removeAttribute("data-active")})}}class st extends d{constructor(t,e,s={}){super(t,e,s),this.input=o("input",{type:"color",className:"cp-input-color",value:this.value||"#000000"}),this.appendWidget(this.input),this.input.addEventListener("input",i=>{const a=i.target;this.setValue(a.value)}),this.updateDisplay()}updateDisplay(){this.input.value=this.value}}function it(n){const t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;n=n.replace(t,(s,i,a,r)=>i+i+a+a+r+r);const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return e?[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]:[0,0,0]}function ht(n,t,e){return"#"+((1<<24)+(Math.round(n)<<16)+(Math.round(t)<<8)+Math.round(e)).toString(16).slice(1)}function N(n){const t=n/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function F(n){return n<=.0031308?n*12.92*255:(1.055*Math.pow(n,1/2.4)-.055)*255}function dt(n,t,e){const[s,i,a]=it(n),[r,l,p]=it(t),u=N(s),m=N(i),b=N(a),y=N(r),S=N(l),k=N(p),f=u+e*(y-u),B=m+e*(S-m),x=b+e*(k-b),c=F(f),g=F(B),v=F(x);return ht(c,g,v)}class nt extends d{constructor(t,e,s={}){super(t,e,s),this.stops=[],this.pingPongDirection=1,this.animationT=0,this.manualPosition=0,this.initialOptions=s,this.stops=s.stops||[{color:"#000000",position:0},{color:"#ffffff",position:1}],this.sortStops();const i=o("details",{className:"cp-controller-details"}),a=o("summary",{className:"cp-controller-summary"}),r=o("div",{className:"cp-controller-summary-content"});this.displayColor=o("div",{className:"cp-color-swatch",style:`background-color: ${this.value}`}),this.displayText=o("span",{className:"cp-value-display"},[String(this.value)]),r.appendChild(this.displayColor),r.appendChild(this.displayText),a.appendChild(r),i.appendChild(a);const l=o("div",{className:"cp-number-settings"});this.stopsContainer=o("div",{className:"cp-stops-container"}),this.renderStops(),l.appendChild(this.stopsContainer);const p=o("button",{className:"cp-button"},["+ Add Stop"]);p.addEventListener("click",()=>{this.stops.push({color:"#ffffff",position:.5}),this.sortStops(),this.renderStops(),this.updateOutput()}),l.appendChild(p);const u=o("hr",{className:"cp-separator"});l.appendChild(u),this.signalHandler=new G({container:l,onChange:(m,b)=>this.applySignal(m,b)}),i.appendChild(l),this.appendWidget(i),this.updateOutput(0)}sortStops(){this.stops.sort((t,e)=>t.position-e.position)}renderStops(){this.stopsContainer.innerHTML="",this.stops.forEach((t,e)=>{const s=o("div",{className:"cp-gradient-stop-row"}),i=o("input",{type:"color",className:"cp-input-color",value:t.color});i.addEventListener("input",l=>{t.color=l.target.value,this.updateOutput()});const a=o("input",{type:"number",className:"cp-input-number cp-input-small",min:"0",max:"1",step:"0.01",value:String(t.position)});a.addEventListener("change",l=>{let p=parseFloat(l.target.value);isNaN(p)&&(p=0),t.position=Math.max(0,Math.min(1,p)),this.sortStops(),this.renderStops(),this.updateOutput()});const r=j(()=>{this.stops.splice(e,1),this.renderStops(),this.updateOutput()});s.appendChild(i),s.appendChild(a),s.appendChild(r),this.stopsContainer.appendChild(s)})}updateOutput(t=this.manualPosition){if(this.stops.length===0)return;if(this.stops.length===1){this.setValue(this.stops[0].color),this.updateDisplay();return}let e="#000000";if(t=Math.max(0,Math.min(1,t)),t<=this.stops[0].position)e=this.stops[0].color;else if(t>=this.stops[this.stops.length-1].position)e=this.stops[this.stops.length-1].color;else for(let s=0;s<this.stops.length-1;s++){const i=this.stops[s],a=this.stops[s+1];if(t>=i.position&&t<=a.position){const r=a.position-i.position,l=r===0?0:(t-i.position)/r;e=dt(i.color,a.color,l);break}}this.setValue(e),this.updateDisplay()}updateDisplay(){this.displayColor&&(this.displayColor.style.backgroundColor=this.value),this.displayText&&(this.displayText.textContent=this.value)}applySignal(t,e){let s=t;if(e==="forward")s=t;else if(e==="backward")s=1-t;else{const i=t*.05;e==="loopForward"?(this.animationT=(this.animationT+i)%1,s=this.animationT):e==="loopBackward"?(this.animationT=(this.animationT-i+1)%1,s=this.animationT):e==="pingpong"&&(this.animationT+=i*this.pingPongDirection,this.animationT>=1?(this.animationT=1,this.pingPongDirection=-1):this.animationT<=0&&(this.animationT=0,this.pingPongDirection=1),s=this.animationT)}this.updateOutput(s),this.manualPosition=s}save(){return{stops:this.stops,settings:{signal:this.signalHandler.save()}}}load(t){t&&t.stops&&(this.stops=t.stops,this.sortStops(),this.renderStops()),t&&t.settings&&this.signalHandler?.load(t.settings.signal)}reset(){this.stops=this.initialOptions.stops||[{color:"#000000",position:0},{color:"#ffffff",position:1}],this.sortStops(),this.renderStops(),this.signalHandler?.reset(),this.updateOutput(0)}}class at extends d{constructor(t,e,s={}){super(t,e,s),this.items=[],this.initialOptions=s,this.itemType=s.itemType||"string",this.items=this.parseValue(this.value);const i=o("details",{className:"cp-controller-details"}),a=o("summary",{className:"cp-controller-summary"}),r=o("div",{className:"cp-controller-summary-content"}),l=o("span",{className:"cp-value-display"},[`${this.items.length} items`]);r.appendChild(l),a.appendChild(r),i.appendChild(a);const p=o("div",{className:"cp-number-settings"});this.itemsContainer=o("div",{className:"cp-stops-container"}),this.renderItems(),p.appendChild(this.itemsContainer);const u=o("button",{className:"cp-button cp-input-small",style:"margin-top: 8px; width: 100%;"},["+ Add Item"]);u.addEventListener("click",()=>{this.addItem()}),p.appendChild(u),i.appendChild(p),this.appendWidget(i)}parseValue(t){return!t||t.trim()===""?[]:t.split(",").map(e=>e.trim())}serializeValue(){return this.items.join(",")}getDefaultItemValue(){switch(this.itemType){case"color":return"#ffffff";case"number":return"0";default:return""}}addItem(t){const e=t!==void 0?t:this.getDefaultItemValue();this.items.push(e),this.renderItems(),this.updateValue()}updateValue(){const t=this.serializeValue();this.setValue(t),this.updateSummary()}updateSummary(){const t=this.domElement.querySelector(".cp-value-display");t&&(t.textContent=`${this.items.length} items`)}renderItems(){this.itemsContainer.innerHTML="",this.items.forEach((t,e)=>{const s=o("div",{className:"cp-array-row"});let i;this.itemType==="color"?i=o("input",{type:"color",className:"cp-input-color",value:t}):this.itemType==="number"?i=o("input",{type:"number",className:"cp-input-number cp-input-small",step:"any",value:t}):i=o("input",{type:"text",className:"cp-input-number cp-input-small",value:t}),i.addEventListener("input",r=>{this.items[e]=r.target.value,this.updateValue()});const a=j(()=>{this.items.splice(e,1),this.renderItems(),this.updateValue()});s.appendChild(i),s.appendChild(a),this.itemsContainer.appendChild(s)})}updateDisplay(){}save(){return[...this.items]}load(t){Array.isArray(t)?this.items=[...t]:typeof t=="string"&&(this.items=this.parseValue(t)),this.renderItems(),this.updateValue()}reset(){const t=this.initialValue||"";this.items=this.parseValue(t),this.renderItems(),this.updateValue()}}class ut{constructor(){this.frames=0,this.pollingInterval=1e3,this.prevTime=performance.now(),this.render=()=>{this.frames++;const t=performance.now();if(t>=this.prevTime+this.pollingInterval){const e=Math.round(this.frames*1e3/(t-this.prevTime));let s="";const i=performance.memory;i&&(s=` / ${Math.round(i.usedJSHeapSize/1048576)}MB`),this.domElement.textContent=`${e} FPS${s}`,this.prevTime=t,this.frames=0}this.rafId=requestAnimationFrame(this.render)},this.domElement=o("span",{className:"cp-stats"}),this.rafId=requestAnimationFrame(this.render)}destroy(){cancelAnimationFrame(this.rafId)}}class D{constructor(){this.controllers=[],this.folders=[]}addNumber(t,e,s={}){const i=new Y(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addRange(t,e,s={}){const i=new Z(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addSelect(t,e,s={}){const i=new K(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addBoolean(t,e,s={}){const i=new tt(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addButton(t,e,s={}){const i=new Q(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addRadio(t,e,s={}){const i=new et(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addColor(t,e,s={}){const i=new st(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addGradient(t,e,s={}){const i=new nt(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addArray(t,e,s={}){const i=new at(t,e,s);return this.contentElement.appendChild(i.domElement),this.controllers.push(i),i}addFolder(t){const e=new ot(t);return this.addSeparator(),this.contentElement.appendChild(e.domElement),this.folders.push(e),e}addSeparator(){const t=o("hr",{className:"cp-separator"});this.contentElement.appendChild(t)}save(){const t={controllers:{},folders:{}};for(const e of this.controllers)typeof e.value!="function"&&(t.controllers[e.key]=e.save());for(const e of this.folders)t.folders[e.title]=e.save();return t}load(t){if(!t){this.reset();return}for(const e of this.controllers)if(typeof e.value!="function")if(t.controllers&&e.key in t.controllers){const s=t.controllers[e.key];s!==void 0&&e.load(s)}else e.reset();for(const e of this.folders){const s=t.folders?t.folders[e.title]:void 0;e.load(s)}}reset(){for(const t of this.controllers)typeof t.value!="function"&&t.reset();for(const t of this.folders)t.reset()}}class ot extends D{constructor(t){super(),this.title=t,this.domElement=o("details",{className:"cp-folder",open:!0}),this.summaryElement=o("summary",{className:"cp-summary"},[t]),this.domElement.appendChild(this.summaryElement),this.contentElement=o("div",{className:"cp-content cp-folder-content"}),this.domElement.appendChild(this.contentElement)}}class mt extends D{constructor(t,e={}){super(),lt(),this.domElement=o("details",{className:"cp-root",open:!0}),this.summaryElement=o("summary",{className:"cp-summary cp-summary-root"}),this.domElement.appendChild(this.summaryElement);const s=o("span",{},[e.title||"ControlPanel"]);this.summaryElement.appendChild(s),this.stats=new ut,this.summaryElement.appendChild(this.stats.domElement);let i=!1,a=0,r=0,l=0,p=0;this.summaryElement.addEventListener("mousedown",c=>{if(c.target!==this.summaryElement&&c.target!==s)return;i=!0,a=c.clientX,r=c.clientY;const g=this.domElement.getBoundingClientRect();l=g.left,p=g.top,c.preventDefault()}),document.addEventListener("mousemove",c=>{if(!i)return;const g=c.clientX-a,v=c.clientY-r,w=l+g,z=p+v;this.domElement.style.left=`${w}px`,this.domElement.style.top=`${z}px`,this.domElement.style.right="auto",this.domElement.style.bottom="auto"}),document.addEventListener("mouseup",()=>{i&&(i=!1,this.savePositionAndSize())}),new ResizeObserver(()=>{i||this.savePositionAndSize()}).observe(this.domElement),this.restorePositionAndSize(),this.contentElement=o("div",{className:"cp-content"}),this.domElement.appendChild(this.contentElement);const m=this.addFolder("_Signals"),b={audioInput:null,fftSize:2048};m.addRadio(b,"audioInput",{label:"Audio Signal",options:["microphone","browser"]}).onChange(c=>{E.setInput(c)}),m.addSelect(b,"fftSize",{label:"FFT Size",options:[256,512,1024,2048]}).onChange(c=>{E.setFFTSize(c)}),m.addRange(E,"smoothingTimeConstant",{min:0,max:.99,step:.01,label:"Smoothing"}).onChange(c=>{E.analyser.smoothingTimeConstant=c}),m.addRange(E,"spectrumBoost",{min:1,max:5,step:.1,label:"Compression"}),t?t.appendChild(this.domElement):document.body.appendChild(this.domElement);const y=e.title||"ControlPanel";this.presetStoragePrefix=`cp-presets-${y}-`;const S=this.addFolder("_User Presets"),k=()=>{const c=["Default"];if(typeof localStorage>"u")return c;for(let g=0;g<localStorage.length;g++){const v=localStorage.key(g);if(v&&v.startsWith(this.presetStoragePrefix)){const w=v.substring(this.presetStoragePrefix.length);w!=="Default"&&!c.includes(w)&&c.push(w)}}return c.sort()},f={selected:"Default",save:()=>{const c=prompt("Preset Name:",f.selected);if(c){if(c==="Default"){alert("Cannot overwrite Default preset");return}const g=this.presetStoragePrefix+c;this.saveToLocalStorage(g);const v=k();x.setOptions(v),f.selected=c,x.setValue(c)}},load:()=>{const c=f.selected,g=this.presetStoragePrefix+c;this.loadFromLocalStorage(g),f.selected=c,x.setValue(c)},delete:()=>{if(f.selected==="Default"){alert("Cannot delete Default preset");return}if(confirm(`Delete preset "${f.selected}"?`)){const c=this.presetStoragePrefix+f.selected;localStorage.removeItem(c);const g=k();x.setOptions(g),f.selected="Default",x.setValue("Default"),this.reset()}},export:()=>{const c=this.save(),g=O=>{const P={controllers:{},folders:{}};for(const[V,q]of Object.entries(O.controllers))V.startsWith("_")||(P.controllers[V]=q);for(const[V,q]of Object.entries(O.folders))V.startsWith("_")||(P.folders[V]=g(q));return P},v=g(c),w={_presetName:f.selected||"CustomPreset",_exportDate:new Date().toISOString(),_instructions:"To add as factory preset: Copy 'controllers' and 'folders' fields into the presets.json file",...v},z=JSON.stringify(w,null,2),I=new Blob([z],{type:"application/json"}),T=URL.createObjectURL(I),C=document.createElement("a");C.href=T;const M=new Date().toISOString().split("T")[0],rt=f.selected.replace(/[^a-z0-9]/gi,"-").toLowerCase();C.download=`${y.toLowerCase()}-preset-${rt}-${M}.json`,document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(T)},import:()=>{const c=document.createElement("input");c.type="file",c.accept=".json",c.onchange=g=>{const v=g.target.files?.[0];if(!v)return;const w=new FileReader;w.onload=z=>{try{const I=z.target?.result,T=JSON.parse(I),C={controllers:T.controllers||{},folders:T.folders||{}};if(!C.controllers||!C.folders){alert("Invalid preset file: missing 'controllers' or 'folders'");return}this.load(C);const M=T._presetName||"ImportedPreset";if(confirm(`Preset loaded! Save as "${M}" to User Presets?`)){const O=this.presetStoragePrefix+M;this.saveToLocalStorage(O);const P=k();x.setOptions(P),f.selected=M,x.setValue(M)}}catch(I){alert(`Failed to import preset: ${I instanceof Error?I.message:"Invalid JSON"}`),console.error("Import error:",I)}},w.readAsText(v)},c.click()}},B=k(),x=S.addSelect(f,"selected",{label:"Preset",options:B});S.addButton("Load",()=>f.load()),S.addButton("Save",()=>f.save()),S.addButton("Delete",()=>f.delete()),S.addButton("Export",()=>f.export()),S.addButton("Import",()=>f.import())}saveToLocalStorage(t){const e=this.save();try{localStorage.setItem(t,JSON.stringify(e))}catch(s){console.warn("ControlPanel: Failed to save to localStorage",s)}}loadFromLocalStorage(t){try{const e=localStorage.getItem(t);if(e){const s=JSON.parse(e);this.load(s)}}catch(e){console.warn("ControlPanel: Failed to load from localStorage",e)}}saveDefaultPreset(){const t=this.presetStoragePrefix+"Default";this.save(),this.saveToLocalStorage(t)}savePositionAndSize(){const t=this.domElement.getBoundingClientRect(),e=`cp-position-${this.presetStoragePrefix}`,s={left:t.left,top:t.top,width:this.domElement.offsetWidth,height:this.domElement.offsetHeight};try{sessionStorage.setItem(e,JSON.stringify(s))}catch(i){console.warn("Failed to save panel position/size",i)}}restorePositionAndSize(){const t=`cp-position-${this.presetStoragePrefix}`;try{const e=sessionStorage.getItem(t);if(e){const s=JSON.parse(e);this.domElement.style.left=`${s.left}px`,this.domElement.style.top=`${s.top}px`,this.domElement.style.right="auto",this.domElement.style.bottom="auto",this.domElement.style.width=`${s.width}px`,this.domElement.style.height=`${s.height}px`}}catch(e){console.warn("Failed to restore panel position/size",e)}}destroy(){this.stats.destroy(),this.domElement.remove(),this.controllers=[],this.folders=[]}}h.ArrayController=at,h.AudioSignals=H,h.BooleanController=tt,h.ButtonController=Q,h.ColorController=st,h.ControlPanel=mt,h.ControlPanelContainer=D,h.Controller=d,h.Folder=ot,h.GradientController=nt,h.MathSignals=_,h.MidiSignals=U,h.NumberController=Y,h.RadioController=et,h.RangeController=Z,h.SelectController=K,h.audioSignals=E,h.mathSignals=J,h.midiSignals=W,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignalHandler.d.ts","sourceRoot":"","sources":["../../src/signals/SignalHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,UAAU,GACV,aAAa,GACb,cAAc,GACd,UAAU,CAAC;AAEf,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,WAAW,CAAC;IACvB,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,KAAK,IAAI,CAAC;CACpE;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED,qBAAa,aAAa;IAExB,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,iBAAiB,CAYT;IAChB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,gBAAgB,CAA8B;IAGtD,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,mBAAmB,CAAe;IAC1C,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,eAAe,CAAqB;IAG5C,OAAO,CAAC,QAAQ,CAA2D;gBAE/D,OAAO,EAAE,oBAAoB;IAKzC,OAAO,CAAC,gBAAgB;
|
|
1
|
+
{"version":3,"file":"SignalHandler.d.ts","sourceRoot":"","sources":["../../src/signals/SignalHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,UAAU,GACV,aAAa,GACb,cAAc,GACd,UAAU,CAAC;AAEf,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,WAAW,CAAC;IACvB,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,KAAK,IAAI,CAAC;CACpE;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED,qBAAa,aAAa;IAExB,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,iBAAiB,CAYT;IAChB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,gBAAgB,CAA8B;IAGtD,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,mBAAmB,CAAe;IAC1C,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,eAAe,CAAqB;IAG5C,OAAO,CAAC,QAAQ,CAA2D;gBAE/D,OAAO,EAAE,oBAAoB;IAKzC,OAAO,CAAC,gBAAgB;IAuFxB,OAAO,CAAC,mBAAmB;IAyB3B,OAAO,CAAC,iBAAiB;IAiCzB,OAAO,CAAC,gBAAgB;IAmExB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IA6ChC,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAK3B,OAAO,CAAC,GAAG,EAAE,IAAI;IAKjB,YAAY,CAAC,GAAG,EAAE,eAAe;IAKjC,OAAO,CAAC,IAAI,CAoCV;IAEF,KAAK;IAML,IAAI;IAOJ,IAAI,IAAI,kBAAkB;IAS1B,IAAI,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI;IASpC,KAAK;CAMN"}
|
package/dist/styles.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAoZA,wBAAgB,YAAY,SAS3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalmeadow/control-panel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A minimalist, framework-agnostic control panel GUI",
|
|
6
6
|
"author": "Digital Meadow <inbox@digitalmeadow.studio> (https://digitalmeadow.studio)",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"import": "./dist/index.js",
|
|
26
26
|
"require": "./dist/index.cjs"
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"./font.css": "./dist/fonts/font.css"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
31
|
"dev": "vite",
|
|
@@ -36,4 +37,4 @@
|
|
|
36
37
|
"typescript": "5.9.3",
|
|
37
38
|
"vite": "7.3.1"
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
}
|