@kidlib/web-audio 0.1.1 → 0.1.3

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.
@@ -1,398 +1,256 @@
1
- var k = Object.defineProperty;
2
- var y = (m, d, t) => d in m ? k(m, d, { enumerable: !0, configurable: !0, writable: !0, value: t }) : m[d] = t;
3
- var h = (m, d, t) => y(m, typeof d != "symbol" ? d + "" : d, t);
4
- const u = class u extends HTMLElement {
5
- constructor() {
6
- super();
7
- h(this, "pathElement");
8
- h(this, "config", {
9
- minValue: 0,
10
- maxValue: 100,
11
- defaultValue: 0,
12
- minRotation: -170,
13
- maxRotation: 170,
14
- snapIncrement: 1,
15
- curve: 1,
16
- disabled: !1,
17
- borderStyle: "currentState"
18
- });
19
- h(this, "currentValue", 0);
20
- h(this, "currentRotation", 0);
21
- h(this, "rotationToValue");
22
- h(this, "valueToRotation");
23
- h(this, "applySnapping");
24
- h(this, "dragHandlers");
25
- h(this, "lastClickTime", 0);
26
- h(this, "DOUBLE_CLICK_THRESHOLD", 300);
27
- }
28
- static mapRange(t, e, n, i, s) {
29
- return e === t ? n : (s - t) * (i - n) / (e - t) + n;
30
- }
31
- static clamp(t, e, n) {
32
- return Math.min(Math.max(t, e), n);
33
- }
34
- // Observed attributes
35
- static get observedAttributes() {
36
- return [
37
- "min-value",
38
- "max-value",
39
- "default-value",
40
- "min-rotation",
41
- "max-rotation",
42
- "snap-increment",
43
- "allowed-values",
44
- "value",
45
- "disabled",
46
- "width",
47
- "height",
48
- "border-style",
49
- "curve",
50
- "color"
51
- ];
52
- }
53
- connectedCallback() {
54
- this.injectGlobalStyles(), this.createUtilityFunctions(), this.render(), this.updateColorFromAttribute(), this.setValue(this.config.defaultValue ?? this.config.minValue), this.createDraggable();
55
- }
56
- disconnectedCallback() {
57
- this.cleanup();
58
- }
59
- attributeChangedCallback(t, e, n) {
60
- if (e !== n) {
61
- if (t === "max-value" || t === "min-value") {
62
- const i = this.config.minValue, s = this.config.maxValue;
63
- this.updateConfigFromAttributes(), this.updateBorder();
64
- let o;
65
- t === "max-value" ? o = u.mapRange(
66
- i,
67
- // old min
68
- parseFloat(e),
69
- // old max
70
- this.config.minValue,
71
- // new min
72
- this.config.maxValue,
73
- // new max
74
- this.currentValue
75
- ) : o = u.mapRange(
76
- parseFloat(e),
77
- // old min
78
- s,
79
- // old max
80
- this.config.minValue,
81
- // new min
82
- this.config.maxValue,
83
- // new max
84
- this.currentValue
85
- ), this.createUtilityFunctions(), this.setValue(o);
86
- return;
87
- }
88
- if (this.updateConfigFromAttributes(), this.updateBorder(), t === "width" || t === "height" || t === "border-style") return;
89
- if (t === "color") {
90
- this.updateColorFromAttribute();
91
- return;
92
- }
93
- if (t === "curve") {
94
- this.createUtilityFunctions(), this.setValue(this.currentValue);
95
- return;
96
- }
97
- }
98
- }
99
- injectGlobalStyles() {
100
- if (u.stylesInjected) return;
101
- const t = document.createElement("style");
102
- t.id = "knob-element-styles", t.textContent = `
103
- knob-element {
104
- display: block;
105
- box-sizing: border-box;
106
- --knob-size: 120px;
107
- --knob-stroke: rgb(234, 234, 234);
108
-
109
- width: var(--knob-size, 120px);
110
- height: var(--knob-size, 120px);
111
-
112
- touch-action: none; /* Prevents browser touch gestures */
113
- user-select: none; /* Prevents text selection during drag */
114
- border-radius: 50%;
115
- cursor: grab;
116
- }
117
-
118
- knob-element[disabled] {
119
- opacity: 0.5;
120
- pointer-events: none;
121
- }
122
-
123
- knob-element:active {
124
- cursor: grabbing;
125
- }
126
- `, document.head.appendChild(t), u.stylesInjected = !0;
127
- }
128
- updateConfigFromAttributes() {
129
- const t = (r, a) => {
130
- const c = this.getAttribute(r);
131
- return c !== null ? parseFloat(c) : a;
132
- }, e = (r, a) => this.getAttribute(r) || a, n = (r) => {
133
- const a = this.getAttribute(r);
134
- if (a)
135
- try {
136
- return JSON.parse(a);
137
- } catch {
138
- console.warn(`KnobElement: Invalid ${r} JSON:`, a);
139
- return;
140
- }
141
- }, i = n("allowed-values");
142
- let s = t("min-value", 0), o = t("max-value", 100);
143
- if (i && i.length > 0) {
144
- const r = [...i].sort((f, l) => f - l), a = r[0], c = r[r.length - 1];
145
- this.hasAttribute("min-value") && s !== a && console.debug(
146
- `KnobElement: min-value (${s}) doesn't match first allowedValue (${a}). Using ${a}.`
147
- ), this.hasAttribute("max-value") && o !== c && console.debug(
148
- `KnobElement: max-value (${o}) doesn't match last allowedValue (${c}). Using ${c}.`
149
- ), this.hasAttribute("snap-thresholds") && console.debug(
150
- "KnobElement: allowedValues overrides snap-increment and snap-thresholds."
151
- ), s = a, o = c;
152
- }
153
- this.config = {
154
- minValue: s,
155
- maxValue: o,
156
- defaultValue: t("default-value", 0),
157
- minRotation: t("min-rotation", -150),
158
- maxRotation: t("max-rotation", 150),
159
- snapIncrement: t("snap-increment", 1),
160
- curve: t("curve", 1),
161
- borderStyle: e(
162
- "border-style",
163
- "currentState"
164
- ),
165
- allowedValues: i ? [...i].sort((r, a) => r - a) : void 0,
166
- snapThresholds: n(
167
- "snap-thresholds"
168
- ),
169
- disabled: this.hasAttribute("disabled")
170
- }, this.updateDimensions();
171
- }
172
- updateDimensions() {
173
- const t = this.getAttribute("width"), e = this.getAttribute("height");
174
- if (t || e) {
175
- const n = t || e || "120";
176
- this.style.setProperty("--knob-size", `${n}px`);
177
- }
178
- }
179
- updateColorFromAttribute() {
180
- const t = this.getAttribute("color");
181
- t && this.style.setProperty("--knob-stroke", t);
182
- }
183
- render() {
184
- this.innerHTML = `
185
- <svg class="ac-knob" width="100%" height="100%" viewBox="0 0 100 100">
186
- <path class="knob-path"
187
- fill="none"
188
- stroke="var(--knob-stroke)"
189
- stroke-width="5"
190
- stroke-linecap="round"
191
- stroke-linejoin="round"
192
- d="M50,50 L50,2"
193
- />
194
- </svg>
195
- `, this.pathElement = this.querySelector(".knob-path");
196
- }
197
- cleanup() {
198
- 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));
199
- }
200
- createUtilityFunctions() {
201
- const t = this.config.curve || 1;
202
- this.rotationToValue = (e) => {
203
- const n = u.mapRange(
204
- this.config.minRotation,
205
- this.config.maxRotation,
206
- 0,
207
- 1,
208
- e
209
- ), i = Math.pow(n, t);
210
- return u.mapRange(
211
- 0,
212
- 1,
213
- this.config.minValue,
214
- this.config.maxValue,
215
- i
216
- );
217
- }, this.valueToRotation = (e) => {
218
- const n = u.mapRange(
219
- this.config.minValue,
220
- this.config.maxValue,
221
- 0,
222
- 1,
223
- e
224
- ), i = Math.pow(n, 1 / t);
225
- return u.mapRange(
226
- 0,
227
- 1,
228
- this.config.minRotation,
229
- this.config.maxRotation,
230
- i
231
- );
232
- }, this.applySnapping = (e) => {
233
- if (this.config.allowedValues && this.config.allowedValues.length > 0)
234
- return this.config.allowedValues.reduce((i, s) => Math.abs(s - e) < Math.abs(i - e) ? s : i);
235
- if (this.config.snapIncrement <= 0) return e;
236
- let n = this.config.snapIncrement;
237
- if (this.config.snapThresholds) {
238
- for (const { maxValue: i, increment: s } of this.config.snapThresholds)
239
- if (e < i) {
240
- n = s;
241
- break;
242
- }
243
- }
244
- return Math.round(e / n) * n;
245
- };
246
- }
247
- // TODO(audiolib): Add keyboard controls and slider ARIA semantics in the planned accessibility pass.
248
- createDraggable() {
249
- const t = "pointerLockElement" in document && "requestPointerLock" in HTMLElement.prototype;
250
- let e = !1, n = 0, i = 0, s = 0, o = !1;
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 C() {
392
- w(L.KNOB, v);
252
+ function r() {
253
+ n(t.KNOB, e);
393
254
  }
394
- export {
395
- v as KnobElement,
396
- w as defineElement,
397
- C as registerKnobElement
398
- };
255
+ //#endregion
256
+ export { e as KnobElement, n as defineElement, r as registerKnobElement };