@kidlib/web-audio 0.1.0 → 0.1.2
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/README.md +9 -4
- package/dist/components.d.ts +2 -2
- package/dist/components.js +254 -396
- package/dist/index.d.ts +50 -50
- package/dist/index.js +4948 -7455
- package/dist/io.d.ts +11 -11
- package/dist/io.js +129 -191
- package/dist/keymap-C9_BObLQ.js +239 -0
- package/dist/processors/processors.js +1464 -1612
- package/package.json +25 -34
- package/dist/keymap-3lZMR1Ak.js +0 -167
package/dist/components.js
CHANGED
|
@@ -1,398 +1,256 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
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
|
-
const r = (l) => {
|
|
252
|
-
n = l.clientY, o = document.pointerLockElement === this, !(!t || document.pointerLockElement) && this.requestPointerLock().then(
|
|
253
|
-
() => {
|
|
254
|
-
o = document.pointerLockElement === this;
|
|
255
|
-
},
|
|
256
|
-
() => {
|
|
257
|
-
o = !1;
|
|
258
|
-
}
|
|
259
|
-
);
|
|
260
|
-
}, a = (l) => {
|
|
261
|
-
if (this.config.disabled) return;
|
|
262
|
-
const g = Date.now(), p = g - this.lastClickTime;
|
|
263
|
-
if (p < this.DOUBLE_CLICK_THRESHOLD && p > 0) {
|
|
264
|
-
this.resetToDefault();
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
this.lastClickTime = g, e = !0, i = this.currentRotation, s = 0, "touches" in l ? (n = l.touches[0].clientY, o = !1) : r(l);
|
|
268
|
-
}, c = (l) => {
|
|
269
|
-
if (!e) return;
|
|
270
|
-
let g;
|
|
271
|
-
const p = 2;
|
|
272
|
-
if (o && document.pointerLockElement)
|
|
273
|
-
s += l.movementY, g = -s * p;
|
|
274
|
-
else {
|
|
275
|
-
const x = "touches" in l ? l.touches[0].clientY : l.clientY;
|
|
276
|
-
g = (n - x) * p;
|
|
277
|
-
}
|
|
278
|
-
const V = i + g, E = u.clamp(
|
|
279
|
-
V,
|
|
280
|
-
this.config.minRotation,
|
|
281
|
-
this.config.maxRotation
|
|
282
|
-
), R = this.rotationToValue(E), b = this.applySnapping(R);
|
|
283
|
-
this.currentValue = b, b !== R ? this.currentRotation = this.valueToRotation(b) : this.currentRotation = E, this.updateBorder(), this.dispatchChangeEvent("user"), l.preventDefault();
|
|
284
|
-
}, f = () => {
|
|
285
|
-
e = !1, o && document.pointerLockElement && document.exitPointerLock(), o = !1;
|
|
286
|
-
};
|
|
287
|
-
this.dragHandlers = {
|
|
288
|
-
start: a,
|
|
289
|
-
move: c,
|
|
290
|
-
end: f
|
|
291
|
-
}, this.addEventListener("mousedown", a), this.addEventListener("touchstart", a, { passive: !1 }), document.addEventListener("mousemove", c), document.addEventListener("mouseup", f), document.addEventListener("touchmove", c, { passive: !1 }), document.addEventListener("touchend", f);
|
|
292
|
-
}
|
|
293
|
-
updateBorder() {
|
|
294
|
-
if (!this.pathElement) return;
|
|
295
|
-
if ((this.getAttribute("border-style") || "currentState") === "currentState") {
|
|
296
|
-
const s = (this.config.minRotation - 90) * Math.PI / 180, o = (this.currentRotation - 90) * Math.PI / 180, r = 48 * Math.cos(s) + 50, a = 48 * Math.sin(s) + 50, c = 48 * Math.cos(o) + 50, f = 48 * Math.sin(o) + 50, l = this.currentRotation - this.config.minRotation, g = Math.abs(l) > 180 ? 1 : 0, p = `M50,50 L${r},${a} A48,48,0,${g},1,${c},${f} Z`;
|
|
297
|
-
this.pathElement.setAttribute("d", p);
|
|
298
|
-
} else
|
|
299
|
-
this.pathElement.setAttribute("d", "M50,2 A48,48,0,1,1,49.9,2 Z");
|
|
300
|
-
}
|
|
301
|
-
dispatchChangeEvent(t = "programmatic") {
|
|
302
|
-
const e = u.mapRange(
|
|
303
|
-
this.config.minValue,
|
|
304
|
-
this.config.maxValue,
|
|
305
|
-
0,
|
|
306
|
-
100,
|
|
307
|
-
this.currentValue
|
|
308
|
-
), n = new CustomEvent("knob-change", {
|
|
309
|
-
detail: {
|
|
310
|
-
value: this.currentValue,
|
|
311
|
-
rotation: this.currentRotation,
|
|
312
|
-
percentage: e,
|
|
313
|
-
source: t
|
|
314
|
-
},
|
|
315
|
-
bubbles: !0
|
|
316
|
-
});
|
|
317
|
-
this.dispatchEvent(n);
|
|
318
|
-
}
|
|
319
|
-
// Public API
|
|
320
|
-
setValue(t) {
|
|
321
|
-
!this.valueToRotation || !this.pathElement || (this.currentValue = u.clamp(
|
|
322
|
-
t,
|
|
323
|
-
this.config.minValue,
|
|
324
|
-
this.config.maxValue
|
|
325
|
-
), this.currentRotation = this.valueToRotation(this.currentValue), this.updateBorder(), this.dispatchChangeEvent());
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Sets the knob value using a normalized 0-1 input, automatically handling
|
|
329
|
-
* the knob's range and curve transformation.
|
|
330
|
-
* @param normalizedValue - Value between 0 and 1
|
|
331
|
-
*/
|
|
332
|
-
setValueNormalized(t) {
|
|
333
|
-
const { minRotation: e, maxRotation: n } = this.config, i = Math.max(0, Math.min(1, t)), s = e + i * (n - e), o = this.rotationToValue(s);
|
|
334
|
-
this.setValue(o);
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Gets the current knob value as a normalized 0-1 value, accounting for
|
|
338
|
-
* the knob's range and curve. Inverse of setValueNormalized().
|
|
339
|
-
* @returns Normalized value between 0 and 1
|
|
340
|
-
*/
|
|
341
|
-
getValueNormalized() {
|
|
342
|
-
return (this.currentRotation - this.config.minRotation) / (this.config.maxRotation - this.config.minRotation);
|
|
343
|
-
}
|
|
344
|
-
resetToDefault() {
|
|
345
|
-
this.setValue(this.config.defaultValue);
|
|
346
|
-
}
|
|
347
|
-
getValue() {
|
|
348
|
-
return this.currentValue;
|
|
349
|
-
}
|
|
350
|
-
setCurve(t) {
|
|
351
|
-
this.config.curve = t, this.createUtilityFunctions(), this.setValue(this.currentValue);
|
|
352
|
-
}
|
|
353
|
-
getCurve() {
|
|
354
|
-
return this.config.curve || 1;
|
|
355
|
-
}
|
|
356
|
-
setDisabled(t) {
|
|
357
|
-
t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
358
|
-
}
|
|
359
|
-
isDisabled() {
|
|
360
|
-
return this.hasAttribute("disabled");
|
|
361
|
-
}
|
|
362
|
-
getPercentage() {
|
|
363
|
-
return u.mapRange(
|
|
364
|
-
this.config.minValue,
|
|
365
|
-
this.config.maxValue,
|
|
366
|
-
0,
|
|
367
|
-
100,
|
|
368
|
-
this.currentValue
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
// Property getters/setters for easier JS usage
|
|
372
|
-
get value() {
|
|
373
|
-
return this.getValue();
|
|
374
|
-
}
|
|
375
|
-
set value(t) {
|
|
376
|
-
this.setValue(t);
|
|
377
|
-
}
|
|
378
|
-
get disabled() {
|
|
379
|
-
return this.isDisabled();
|
|
380
|
-
}
|
|
381
|
-
set disabled(t) {
|
|
382
|
-
this.setDisabled(t);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
h(u, "stylesInjected", !1);
|
|
386
|
-
let v = u;
|
|
387
|
-
const L = { KNOB: "knob-element" };
|
|
388
|
-
function w(m, d) {
|
|
389
|
-
typeof customElements > "u" || customElements.get(m) || customElements.define(m, d);
|
|
1
|
+
//#region src/components/KnobElement.ts
|
|
2
|
+
var e = class e extends HTMLElement {
|
|
3
|
+
pathElement;
|
|
4
|
+
static stylesInjected = !1;
|
|
5
|
+
config = {
|
|
6
|
+
minValue: 0,
|
|
7
|
+
maxValue: 100,
|
|
8
|
+
defaultValue: 0,
|
|
9
|
+
minRotation: -170,
|
|
10
|
+
maxRotation: 170,
|
|
11
|
+
snapIncrement: 1,
|
|
12
|
+
curve: 1,
|
|
13
|
+
disabled: !1,
|
|
14
|
+
borderStyle: "currentState"
|
|
15
|
+
};
|
|
16
|
+
currentValue = 0;
|
|
17
|
+
currentRotation = 0;
|
|
18
|
+
rotationToValue;
|
|
19
|
+
valueToRotation;
|
|
20
|
+
applySnapping;
|
|
21
|
+
static mapRange(e, t, n, r, i) {
|
|
22
|
+
return t === e ? n : (i - e) * (r - n) / (t - e) + n;
|
|
23
|
+
}
|
|
24
|
+
static clamp(e, t, n) {
|
|
25
|
+
return Math.min(Math.max(e, t), n);
|
|
26
|
+
}
|
|
27
|
+
static get observedAttributes() {
|
|
28
|
+
return [
|
|
29
|
+
"min-value",
|
|
30
|
+
"max-value",
|
|
31
|
+
"default-value",
|
|
32
|
+
"min-rotation",
|
|
33
|
+
"max-rotation",
|
|
34
|
+
"snap-increment",
|
|
35
|
+
"allowed-values",
|
|
36
|
+
"value",
|
|
37
|
+
"disabled",
|
|
38
|
+
"width",
|
|
39
|
+
"height",
|
|
40
|
+
"border-style",
|
|
41
|
+
"curve",
|
|
42
|
+
"color"
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
}
|
|
48
|
+
connectedCallback() {
|
|
49
|
+
this.injectGlobalStyles(), this.createUtilityFunctions(), this.render(), this.updateColorFromAttribute(), this.setValue(this.config.defaultValue ?? this.config.minValue), this.createDraggable();
|
|
50
|
+
}
|
|
51
|
+
disconnectedCallback() {
|
|
52
|
+
this.cleanup();
|
|
53
|
+
}
|
|
54
|
+
attributeChangedCallback(t, n, r) {
|
|
55
|
+
if (n !== r) {
|
|
56
|
+
if (t === "max-value" || t === "min-value") {
|
|
57
|
+
let r = this.config.minValue, i = this.config.maxValue;
|
|
58
|
+
this.updateConfigFromAttributes(), this.updateBorder();
|
|
59
|
+
let a;
|
|
60
|
+
a = t === "max-value" ? e.mapRange(r, parseFloat(n), this.config.minValue, this.config.maxValue, this.currentValue) : e.mapRange(parseFloat(n), i, this.config.minValue, this.config.maxValue, this.currentValue), this.createUtilityFunctions(), this.setValue(a);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (this.updateConfigFromAttributes(), this.updateBorder(), t === "width" || t === "height" || t === "border-style") return;
|
|
64
|
+
if (t === "color") {
|
|
65
|
+
this.updateColorFromAttribute();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (t === "curve") {
|
|
69
|
+
this.createUtilityFunctions(), this.setValue(this.currentValue);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
injectGlobalStyles() {
|
|
75
|
+
if (e.stylesInjected) return;
|
|
76
|
+
let t = document.createElement("style");
|
|
77
|
+
t.id = "knob-element-styles", t.textContent = "\n knob-element {\n display: block;\n box-sizing: border-box;\n --knob-size: 120px;\n --knob-stroke: rgb(234, 234, 234);\n\n width: var(--knob-size, 120px); \n height: var(--knob-size, 120px);\n\n touch-action: none; /* Prevents browser touch gestures */\n user-select: none; /* Prevents text selection during drag */\n border-radius: 50%;\n cursor: grab;\n }\n \n knob-element[disabled] {\n opacity: 0.5;\n pointer-events: none; \n }\n \n knob-element:active {\n cursor: grabbing;\n }\n ", document.head.appendChild(t), e.stylesInjected = !0;
|
|
78
|
+
}
|
|
79
|
+
updateConfigFromAttributes() {
|
|
80
|
+
let e = (e, t) => {
|
|
81
|
+
let n = this.getAttribute(e);
|
|
82
|
+
return n === null ? t : parseFloat(n);
|
|
83
|
+
}, t = (e, t) => this.getAttribute(e) || t, n = (e) => {
|
|
84
|
+
let t = this.getAttribute(e);
|
|
85
|
+
if (t) try {
|
|
86
|
+
return JSON.parse(t);
|
|
87
|
+
} catch {
|
|
88
|
+
console.warn(`KnobElement: Invalid ${e} JSON:`, t);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}, r = n("allowed-values"), i = e("min-value", 0), a = e("max-value", 100);
|
|
92
|
+
if (r && r.length > 0) {
|
|
93
|
+
let e = [...r].sort((e, t) => e - t), t = e[0], n = e[e.length - 1];
|
|
94
|
+
this.hasAttribute("min-value") && i !== t && console.debug(`KnobElement: min-value (${i}) doesn't match first allowedValue (${t}). Using ${t}.`), this.hasAttribute("max-value") && a !== n && console.debug(`KnobElement: max-value (${a}) doesn't match last allowedValue (${n}). Using ${n}.`), this.hasAttribute("snap-thresholds") && console.debug("KnobElement: allowedValues overrides snap-increment and snap-thresholds."), i = t, a = n;
|
|
95
|
+
}
|
|
96
|
+
this.config = {
|
|
97
|
+
minValue: i,
|
|
98
|
+
maxValue: a,
|
|
99
|
+
defaultValue: e("default-value", 0),
|
|
100
|
+
minRotation: e("min-rotation", -150),
|
|
101
|
+
maxRotation: e("max-rotation", 150),
|
|
102
|
+
snapIncrement: e("snap-increment", 1),
|
|
103
|
+
curve: e("curve", 1),
|
|
104
|
+
borderStyle: t("border-style", "currentState"),
|
|
105
|
+
allowedValues: r ? [...r].sort((e, t) => e - t) : void 0,
|
|
106
|
+
snapThresholds: n("snap-thresholds"),
|
|
107
|
+
disabled: this.hasAttribute("disabled")
|
|
108
|
+
}, this.updateDimensions();
|
|
109
|
+
}
|
|
110
|
+
updateDimensions() {
|
|
111
|
+
let e = this.getAttribute("width"), t = this.getAttribute("height");
|
|
112
|
+
if (e || t) {
|
|
113
|
+
let n = e || t || "120";
|
|
114
|
+
this.style.setProperty("--knob-size", `${n}px`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
updateColorFromAttribute() {
|
|
118
|
+
let e = this.getAttribute("color");
|
|
119
|
+
e && this.style.setProperty("--knob-stroke", e);
|
|
120
|
+
}
|
|
121
|
+
render() {
|
|
122
|
+
this.innerHTML = "\n <svg class=\"ac-knob\" width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\">\n <path class=\"knob-path\" \n fill=\"none\" \n stroke=\"var(--knob-stroke)\" \n stroke-width=\"5\" \n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n d=\"M50,50 L50,2\"\n />\n </svg>\n ", this.pathElement = this.querySelector(".knob-path");
|
|
123
|
+
}
|
|
124
|
+
cleanup() {
|
|
125
|
+
this.dragHandlers && (this.removeEventListener("mousedown", this.dragHandlers.start), this.removeEventListener("touchstart", this.dragHandlers.start), document.removeEventListener("mousemove", this.dragHandlers.move), document.removeEventListener("mouseup", this.dragHandlers.end), document.removeEventListener("touchmove", this.dragHandlers.move), document.removeEventListener("touchend", this.dragHandlers.end));
|
|
126
|
+
}
|
|
127
|
+
createUtilityFunctions() {
|
|
128
|
+
let t = this.config.curve || 1;
|
|
129
|
+
this.rotationToValue = (n) => {
|
|
130
|
+
let r = e.mapRange(this.config.minRotation, this.config.maxRotation, 0, 1, n) ** +t;
|
|
131
|
+
return e.mapRange(0, 1, this.config.minValue, this.config.maxValue, r);
|
|
132
|
+
}, this.valueToRotation = (n) => {
|
|
133
|
+
let r = e.mapRange(this.config.minValue, this.config.maxValue, 0, 1, n) ** (1 / t);
|
|
134
|
+
return e.mapRange(0, 1, this.config.minRotation, this.config.maxRotation, r);
|
|
135
|
+
}, this.applySnapping = (e) => {
|
|
136
|
+
if (this.config.allowedValues && this.config.allowedValues.length > 0) return this.config.allowedValues.reduce((t, n) => Math.abs(n - e) < Math.abs(t - e) ? n : t);
|
|
137
|
+
if (this.config.snapIncrement <= 0) return e;
|
|
138
|
+
let t = this.config.snapIncrement;
|
|
139
|
+
if (this.config.snapThresholds) {
|
|
140
|
+
for (let { maxValue: n, increment: r } of this.config.snapThresholds) if (e < n) {
|
|
141
|
+
t = r;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return Math.round(e / t) * t;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
dragHandlers;
|
|
149
|
+
lastClickTime = 0;
|
|
150
|
+
DOUBLE_CLICK_THRESHOLD = 300;
|
|
151
|
+
createDraggable() {
|
|
152
|
+
let t = "pointerLockElement" in document && "requestPointerLock" in HTMLElement.prototype, n = !1, r = 0, i = 0, a = 0, o = !1, s = (e) => {
|
|
153
|
+
r = e.clientY, o = document.pointerLockElement === this, !(!t || document.pointerLockElement) && this.requestPointerLock().then(() => {
|
|
154
|
+
o = document.pointerLockElement === this;
|
|
155
|
+
}, () => {
|
|
156
|
+
o = !1;
|
|
157
|
+
});
|
|
158
|
+
}, c = (e) => {
|
|
159
|
+
if (this.config.disabled) return;
|
|
160
|
+
let t = Date.now(), c = t - this.lastClickTime;
|
|
161
|
+
if (c < this.DOUBLE_CLICK_THRESHOLD && c > 0) {
|
|
162
|
+
this.resetToDefault();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this.lastClickTime = t, n = !0, i = this.currentRotation, a = 0, "touches" in e ? (r = e.touches[0].clientY, o = !1) : s(e);
|
|
166
|
+
}, l = (t) => {
|
|
167
|
+
if (!n) return;
|
|
168
|
+
let s;
|
|
169
|
+
if (o && document.pointerLockElement) a += t.movementY, s = -a * 2;
|
|
170
|
+
else {
|
|
171
|
+
let e = "touches" in t ? t.touches[0].clientY : t.clientY;
|
|
172
|
+
s = (r - e) * 2;
|
|
173
|
+
}
|
|
174
|
+
let c = i + s, l = e.clamp(c, this.config.minRotation, this.config.maxRotation), u = this.rotationToValue(l), d = this.applySnapping(u);
|
|
175
|
+
this.currentValue = d, this.currentRotation = d === u ? l : this.valueToRotation(d), this.updateBorder(), this.dispatchChangeEvent("user"), t.preventDefault();
|
|
176
|
+
}, u = () => {
|
|
177
|
+
n = !1, o && document.pointerLockElement && document.exitPointerLock(), o = !1;
|
|
178
|
+
};
|
|
179
|
+
this.dragHandlers = {
|
|
180
|
+
start: c,
|
|
181
|
+
move: l,
|
|
182
|
+
end: u
|
|
183
|
+
}, this.addEventListener("mousedown", c), this.addEventListener("touchstart", c, { passive: !1 }), document.addEventListener("mousemove", l), document.addEventListener("mouseup", u), document.addEventListener("touchmove", l, { passive: !1 }), document.addEventListener("touchend", u);
|
|
184
|
+
}
|
|
185
|
+
updateBorder() {
|
|
186
|
+
if (this.pathElement) {
|
|
187
|
+
if ((this.getAttribute("border-style") || "currentState") === "currentState") {
|
|
188
|
+
let e = (this.config.minRotation - 90) * Math.PI / 180, t = (this.currentRotation - 90) * Math.PI / 180, n = 48 * Math.cos(e) + 50, r = 48 * Math.sin(e) + 50, i = 48 * Math.cos(t) + 50, a = 48 * Math.sin(t) + 50, o = this.currentRotation - this.config.minRotation, s = `M50,50 L${n},${r} A48,48,0,${+(Math.abs(o) > 180)},1,${i},${a} Z`;
|
|
189
|
+
this.pathElement.setAttribute("d", s);
|
|
190
|
+
} else this.pathElement.setAttribute("d", "M50,2 A48,48,0,1,1,49.9,2 Z");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
dispatchChangeEvent(t = "programmatic") {
|
|
194
|
+
let n = e.mapRange(this.config.minValue, this.config.maxValue, 0, 100, this.currentValue), r = new CustomEvent("knob-change", {
|
|
195
|
+
detail: {
|
|
196
|
+
value: this.currentValue,
|
|
197
|
+
rotation: this.currentRotation,
|
|
198
|
+
percentage: n,
|
|
199
|
+
source: t
|
|
200
|
+
},
|
|
201
|
+
bubbles: !0
|
|
202
|
+
});
|
|
203
|
+
this.dispatchEvent(r);
|
|
204
|
+
}
|
|
205
|
+
setValue(t) {
|
|
206
|
+
!this.valueToRotation || !this.pathElement || (this.currentValue = e.clamp(t, this.config.minValue, this.config.maxValue), this.currentRotation = this.valueToRotation(this.currentValue), this.updateBorder(), this.dispatchChangeEvent());
|
|
207
|
+
}
|
|
208
|
+
setValueNormalized(e) {
|
|
209
|
+
let { minRotation: t, maxRotation: n } = this.config, r = t + Math.max(0, Math.min(1, e)) * (n - t), i = this.rotationToValue(r);
|
|
210
|
+
this.setValue(i);
|
|
211
|
+
}
|
|
212
|
+
getValueNormalized() {
|
|
213
|
+
return (this.currentRotation - this.config.minRotation) / (this.config.maxRotation - this.config.minRotation);
|
|
214
|
+
}
|
|
215
|
+
resetToDefault() {
|
|
216
|
+
this.setValue(this.config.defaultValue);
|
|
217
|
+
}
|
|
218
|
+
getValue() {
|
|
219
|
+
return this.currentValue;
|
|
220
|
+
}
|
|
221
|
+
setCurve(e) {
|
|
222
|
+
this.config.curve = e, this.createUtilityFunctions(), this.setValue(this.currentValue);
|
|
223
|
+
}
|
|
224
|
+
getCurve() {
|
|
225
|
+
return this.config.curve || 1;
|
|
226
|
+
}
|
|
227
|
+
setDisabled(e) {
|
|
228
|
+
e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
229
|
+
}
|
|
230
|
+
isDisabled() {
|
|
231
|
+
return this.hasAttribute("disabled");
|
|
232
|
+
}
|
|
233
|
+
getPercentage() {
|
|
234
|
+
return e.mapRange(this.config.minValue, this.config.maxValue, 0, 100, this.currentValue);
|
|
235
|
+
}
|
|
236
|
+
get value() {
|
|
237
|
+
return this.getValue();
|
|
238
|
+
}
|
|
239
|
+
set value(e) {
|
|
240
|
+
this.setValue(e);
|
|
241
|
+
}
|
|
242
|
+
get disabled() {
|
|
243
|
+
return this.isDisabled();
|
|
244
|
+
}
|
|
245
|
+
set disabled(e) {
|
|
246
|
+
this.setDisabled(e);
|
|
247
|
+
}
|
|
248
|
+
}, t = { KNOB: "knob-element" };
|
|
249
|
+
function n(e, t) {
|
|
250
|
+
typeof customElements > "u" || customElements.get(e) || customElements.define(e, t);
|
|
390
251
|
}
|
|
391
|
-
function
|
|
392
|
-
|
|
252
|
+
function r() {
|
|
253
|
+
n(t.KNOB, e);
|
|
393
254
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
w as defineElement,
|
|
397
|
-
C as registerKnobElement
|
|
398
|
-
};
|
|
255
|
+
//#endregion
|
|
256
|
+
export { e as KnobElement, n as defineElement, r as registerKnobElement };
|