@digitalmeadow/control-panel 1.0.16 → 1.0.17
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/index.js +112 -110
- package/dist/index.umd.cjs +7 -5
- package/dist/styles.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const W = `
|
|
2
2
|
.cp-root {
|
|
3
|
-
--cp-scale:
|
|
3
|
+
--cp-scale: 2;
|
|
4
4
|
|
|
5
5
|
--cp-space-1: calc(1px * var(--cp-scale));
|
|
6
6
|
--cp-space-2: calc(2px * var(--cp-scale));
|
|
@@ -8,6 +8,8 @@ const W = `
|
|
|
8
8
|
--cp-space-6: calc(6px * var(--cp-scale));
|
|
9
9
|
--cp-space-8: calc(8px * var(--cp-scale));
|
|
10
10
|
|
|
11
|
+
--cp-border-width: calc(1px * var(--cp-scale));
|
|
12
|
+
|
|
11
13
|
--cp-font-size-main: calc(10px * var(--cp-scale));
|
|
12
14
|
--cp-font-size-details: calc(10px * var(--cp-scale));
|
|
13
15
|
|
|
@@ -142,7 +144,7 @@ const W = `
|
|
|
142
144
|
padding: var(--cp-space-2) var(--cp-space-4);
|
|
143
145
|
background: transparent;
|
|
144
146
|
color: inherit;
|
|
145
|
-
border:
|
|
147
|
+
border: var(--cp-border-width) solid var(--cp-color-2);
|
|
146
148
|
border-radius: var(--cp-border-radius);
|
|
147
149
|
font-family: inherit;
|
|
148
150
|
font-size: inherit;
|
|
@@ -186,7 +188,7 @@ const W = `
|
|
|
186
188
|
-moz-appearance: none;
|
|
187
189
|
color: transparent;
|
|
188
190
|
background: transparent;
|
|
189
|
-
border:
|
|
191
|
+
border: var(--cp-border-width) solid var(--cp-color-2);
|
|
190
192
|
border-radius: var(--cp-border-radius);
|
|
191
193
|
outline: none;
|
|
192
194
|
font-size: 0;
|
|
@@ -292,7 +294,7 @@ const W = `
|
|
|
292
294
|
margin: var(--cp-space-4) 0;
|
|
293
295
|
width: 100%;
|
|
294
296
|
border: none;
|
|
295
|
-
border-top:
|
|
297
|
+
border-top: var(--cp-border-width) solid var(--cp-color-1);
|
|
296
298
|
}
|
|
297
299
|
|
|
298
300
|
.cp-setting-row {
|
|
@@ -360,7 +362,7 @@ const W = `
|
|
|
360
362
|
.cp-input-color {
|
|
361
363
|
width: var(--cp-swatch-size);
|
|
362
364
|
height: var(--cp-swatch-size);
|
|
363
|
-
border:
|
|
365
|
+
border: var(--cp-border-width) solid var(--cp-color-1);
|
|
364
366
|
border-radius: 50%;
|
|
365
367
|
-webkit-appearance: none;
|
|
366
368
|
}
|
|
@@ -390,7 +392,7 @@ function _() {
|
|
|
390
392
|
const n = document.createElement("style");
|
|
391
393
|
n.id = "control-panel-styles", n.textContent = W, document.head.appendChild(n), B = !0;
|
|
392
394
|
}
|
|
393
|
-
function
|
|
395
|
+
function o(n, t = {}, e = []) {
|
|
394
396
|
const s = document.createElement(n);
|
|
395
397
|
for (const [i, a] of Object.entries(t))
|
|
396
398
|
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));
|
|
@@ -399,7 +401,7 @@ function r(n, t = {}, e = []) {
|
|
|
399
401
|
return s;
|
|
400
402
|
}
|
|
401
403
|
function j(n) {
|
|
402
|
-
const t =
|
|
404
|
+
const t = o(
|
|
403
405
|
"button",
|
|
404
406
|
{
|
|
405
407
|
className: "cp-button cp-button-delete"
|
|
@@ -426,8 +428,8 @@ function Y(n, t, e) {
|
|
|
426
428
|
return e[e.length - 1];
|
|
427
429
|
if (s === 0 && n < t[0])
|
|
428
430
|
return e[0];
|
|
429
|
-
const i = t[s], a = t[s + 1],
|
|
430
|
-
return (n - i) / (a - i) * (l -
|
|
431
|
+
const i = t[s], a = t[s + 1], r = e[s], l = e[s + 1];
|
|
432
|
+
return (n - i) / (a - i) * (l - r) + r;
|
|
431
433
|
}
|
|
432
434
|
class X {
|
|
433
435
|
constructor() {
|
|
@@ -473,8 +475,8 @@ class X {
|
|
|
473
475
|
this.dataArray[h] = Math.min(255, this.dataArray[h] * y);
|
|
474
476
|
}
|
|
475
477
|
}
|
|
476
|
-
const t = [2, 10], e = [10, 150], s = [150, 600], i = this.getAverage(t[0], t[1]), a = this.getAverage(e[0], e[1]),
|
|
477
|
-
this.processLevel("bass", i), this.processLevel("mids", a), this.processLevel("highs",
|
|
478
|
+
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]);
|
|
479
|
+
this.processLevel("bass", i), this.processLevel("mids", a), this.processLevel("highs", r), this.processLevel("volume", l);
|
|
478
480
|
}
|
|
479
481
|
processLevel(t, e) {
|
|
480
482
|
this.peaks[t] -= 5e-4, this.peaks[t] = q(this.peaks[t], 0.1, 1), e > this.peaks[t] && (this.peaks[t] = e), this.levels[t] = q(
|
|
@@ -519,11 +521,11 @@ class G {
|
|
|
519
521
|
handleMessage(t) {
|
|
520
522
|
const e = t.data, [s] = e;
|
|
521
523
|
if ((s & 240) >= 240) return;
|
|
522
|
-
const a = this.getIdFromMessage(t),
|
|
523
|
-
this.values.set(a,
|
|
524
|
+
const a = this.getIdFromMessage(t), r = this.normalizeValue(e);
|
|
525
|
+
this.values.set(a, r), this.isListening && this.resolveListen && r > 0 && (this.resolveListen(a), this.isListening = !1, this.resolveListen = null, this.listeningCallback && this.listeningCallback());
|
|
524
526
|
}
|
|
525
527
|
getIdFromMessage(t) {
|
|
526
|
-
const e = t.data, [s, i] = e, a = s & 240,
|
|
528
|
+
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, "");
|
|
527
529
|
return `${i}_${l}_${p}`;
|
|
528
530
|
}
|
|
529
531
|
normalizeValue(t) {
|
|
@@ -598,20 +600,20 @@ class K {
|
|
|
598
600
|
return this.normalizeOutput(i, e);
|
|
599
601
|
}
|
|
600
602
|
sine(t) {
|
|
601
|
-
const e = t ? { ...this.configs.get("sine"), ...t } : this.configs.get("sine"), s = this.getTime(), i = e.phase * Math.PI * 2,
|
|
602
|
-
return this.normalizeOutput(
|
|
603
|
+
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;
|
|
604
|
+
return this.normalizeOutput(r, e);
|
|
603
605
|
}
|
|
604
606
|
sawtooth(t) {
|
|
605
607
|
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;
|
|
606
608
|
return this.normalizeOutput(a % 1, e);
|
|
607
609
|
}
|
|
608
610
|
triangle(t) {
|
|
609
|
-
const e = t ? { ...this.configs.get("triangle"), ...t } : this.configs.get("triangle"), s = this.getTime(), i = e.phase, a = (s * e.frequency + i) % 1,
|
|
610
|
-
return this.normalizeOutput(
|
|
611
|
+
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 < 0.5 ? a * 2 : 2 - a * 2;
|
|
612
|
+
return this.normalizeOutput(r, e);
|
|
611
613
|
}
|
|
612
614
|
square(t) {
|
|
613
|
-
const e = t ? { ...this.configs.get("square"), ...t } : this.configs.get("square"), s = this.getTime(), i = e.phase,
|
|
614
|
-
return this.normalizeOutput(
|
|
615
|
+
const e = t ? { ...this.configs.get("square"), ...t } : this.configs.get("square"), s = this.getTime(), i = e.phase, r = (s * e.frequency + i) % 1 < 0.5 ? 0 : 1;
|
|
616
|
+
return this.normalizeOutput(r, e);
|
|
615
617
|
}
|
|
616
618
|
random(t) {
|
|
617
619
|
const e = t ? { ...this.configs.get("random"), ...t } : this.configs.get("random"), s = performance.now(), i = 1e3 / e.frequency;
|
|
@@ -639,8 +641,8 @@ class K {
|
|
|
639
641
|
}
|
|
640
642
|
const Q = new K(), A = class A {
|
|
641
643
|
constructor(t, e, s = {}) {
|
|
642
|
-
this.changeFns = /* @__PURE__ */ new Set(), this.object = t, this.property = e, this.key = s.id ?? e, this.initialValue = this.object[this.property], this.domElement =
|
|
643
|
-
const i = s.label ?? J(e), a =
|
|
644
|
+
this.changeFns = /* @__PURE__ */ 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" });
|
|
645
|
+
const i = s.label ?? J(e), a = o("label", { className: "cp-label" }, [
|
|
644
646
|
String(i)
|
|
645
647
|
]);
|
|
646
648
|
a.setAttribute("title", String(i)), this.domElement.appendChild(a), s.disabled && this.domElement.setAttribute("data-disabled", "true");
|
|
@@ -675,7 +677,7 @@ A.audio = k, A.midi = Z, A.math = Q;
|
|
|
675
677
|
let u = A;
|
|
676
678
|
class tt extends u {
|
|
677
679
|
constructor(t, e, s = {}) {
|
|
678
|
-
super(t, e, s), this.input =
|
|
680
|
+
super(t, e, s), this.input = o("input", {
|
|
679
681
|
type: "number",
|
|
680
682
|
className: "cp-input-number",
|
|
681
683
|
value: String(this.value)
|
|
@@ -747,16 +749,16 @@ class H {
|
|
|
747
749
|
],
|
|
748
750
|
(l) => this.setSignalType(l)
|
|
749
751
|
);
|
|
750
|
-
this.signalSelect = e.select, t.appendChild(e.row), this.midiRow =
|
|
752
|
+
this.signalSelect = e.select, t.appendChild(e.row), this.midiRow = o("div", {
|
|
751
753
|
className: "cp-setting-row",
|
|
752
754
|
style: "display: none;"
|
|
753
755
|
});
|
|
754
|
-
const s =
|
|
756
|
+
const s = o(
|
|
755
757
|
"label",
|
|
756
758
|
{ className: "cp-setting-label" },
|
|
757
759
|
["Midi"]
|
|
758
760
|
);
|
|
759
|
-
this.midiBtn =
|
|
761
|
+
this.midiBtn = o(
|
|
760
762
|
"button",
|
|
761
763
|
{ className: "cp-button cp-input-small" },
|
|
762
764
|
["Learn"]
|
|
@@ -768,7 +770,7 @@ class H {
|
|
|
768
770
|
this.midiBtn.textContent = "Listening...";
|
|
769
771
|
const l = await u.midi.listen();
|
|
770
772
|
this.setMidiId(l);
|
|
771
|
-
}), this.midiRow.appendChild(s), this.midiRow.appendChild(this.midiBtn), t.appendChild(this.midiRow), this.mathParamsContainer =
|
|
773
|
+
}), this.midiRow.appendChild(s), this.midiRow.appendChild(this.midiBtn), t.appendChild(this.midiRow), this.mathParamsContainer = o("div", {
|
|
772
774
|
className: "cp-number-settings"
|
|
773
775
|
}), t.appendChild(this.mathParamsContainer);
|
|
774
776
|
const i = this.createSettingSelect(
|
|
@@ -783,24 +785,24 @@ class H {
|
|
|
783
785
|
(l) => this.setEase(l)
|
|
784
786
|
);
|
|
785
787
|
this.easeRow = a.row, this.easeSelect = a.select, this.easeRow.style.display = "none", this.easeSelect.value = this.currentEase, t.appendChild(this.easeRow);
|
|
786
|
-
const
|
|
787
|
-
t.appendChild(
|
|
788
|
+
const r = o("hr", { className: "cp-separator" });
|
|
789
|
+
t.appendChild(r);
|
|
788
790
|
}
|
|
789
791
|
createSettingSelect(t, e, s) {
|
|
790
|
-
const i =
|
|
792
|
+
const i = o("div", { className: "cp-setting-row" }), a = o("label", { className: "cp-setting-label" }, [
|
|
791
793
|
t
|
|
792
|
-
]),
|
|
794
|
+
]), r = o("select", {
|
|
793
795
|
className: "cp-select cp-input-small"
|
|
794
796
|
});
|
|
795
797
|
return e.forEach((l) => {
|
|
796
|
-
const p =
|
|
797
|
-
|
|
798
|
-
}),
|
|
798
|
+
const p = o("option", { value: l }, [l]);
|
|
799
|
+
r.appendChild(p);
|
|
800
|
+
}), r.addEventListener("change", () => s(r.value)), i.appendChild(a), i.appendChild(r), { row: i, select: r };
|
|
799
801
|
}
|
|
800
|
-
createNumberInput(t, e, s, i, a,
|
|
801
|
-
const l =
|
|
802
|
+
createNumberInput(t, e, s, i, a, r) {
|
|
803
|
+
const l = o("div", { className: "cp-setting-row" }), p = o("label", { className: "cp-setting-label" }, [
|
|
802
804
|
t
|
|
803
|
-
]), h =
|
|
805
|
+
]), h = o("input", {
|
|
804
806
|
className: "cp-input-number cp-input-small",
|
|
805
807
|
type: "number",
|
|
806
808
|
value: String(e),
|
|
@@ -810,20 +812,20 @@ class H {
|
|
|
810
812
|
});
|
|
811
813
|
return h.addEventListener("input", () => {
|
|
812
814
|
const d = parseFloat(h.value);
|
|
813
|
-
isNaN(d) ||
|
|
815
|
+
isNaN(d) || r(d);
|
|
814
816
|
}), l.appendChild(p), l.appendChild(h), { row: l, input: h };
|
|
815
817
|
}
|
|
816
818
|
updateMathParams(t) {
|
|
817
819
|
this.mathParamsContainer.innerHTML = "";
|
|
818
820
|
const e = u.math.getConfig(t);
|
|
819
|
-
let s = "Frequency", i = 0.1, a = 10,
|
|
820
|
-
t === "random" ? a = 30 : t === "constant" && (s = "Speed", i = 0.01, a = 2,
|
|
821
|
+
let s = "Frequency", i = 0.1, a = 10, r = 0.1;
|
|
822
|
+
t === "random" ? a = 30 : t === "constant" && (s = "Speed", i = 0.01, a = 2, r = 0.01);
|
|
821
823
|
const l = this.createNumberInput(
|
|
822
824
|
s,
|
|
823
825
|
e.frequency,
|
|
824
826
|
i,
|
|
825
827
|
a,
|
|
826
|
-
|
|
828
|
+
r,
|
|
827
829
|
(d) => u.math.setConfig(t, { frequency: d })
|
|
828
830
|
);
|
|
829
831
|
this.mathParamsContainer.appendChild(l.row);
|
|
@@ -905,16 +907,16 @@ class H {
|
|
|
905
907
|
class et extends u {
|
|
906
908
|
constructor(t, e, s = {}) {
|
|
907
909
|
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;
|
|
908
|
-
const i =
|
|
910
|
+
const i = o("details", {
|
|
909
911
|
className: "cp-controller-details"
|
|
910
|
-
}), a =
|
|
912
|
+
}), a = o("summary", {
|
|
911
913
|
className: "cp-controller-summary"
|
|
912
914
|
});
|
|
913
|
-
this.input =
|
|
915
|
+
this.input = o("input", {
|
|
914
916
|
type: "range",
|
|
915
917
|
className: "cp-input-range",
|
|
916
918
|
step: s.step ?? "any"
|
|
917
|
-
}), 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 =
|
|
919
|
+
}), 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(
|
|
918
920
|
"span",
|
|
919
921
|
{
|
|
920
922
|
className: "cp-value-display"
|
|
@@ -926,11 +928,11 @@ class et extends u {
|
|
|
926
928
|
}), this.input.addEventListener("click", (f) => {
|
|
927
929
|
f.stopPropagation();
|
|
928
930
|
});
|
|
929
|
-
const
|
|
931
|
+
const r = o("div", {
|
|
930
932
|
className: "cp-controller-summary-content"
|
|
931
933
|
});
|
|
932
|
-
|
|
933
|
-
const l =
|
|
934
|
+
r.appendChild(this.input), r.appendChild(this.display), a.appendChild(r), i.appendChild(a);
|
|
935
|
+
const l = o("div", { className: "cp-number-settings" }), p = this.createSetting(
|
|
934
936
|
"min",
|
|
935
937
|
s.min,
|
|
936
938
|
(f) => this.setMin(f)
|
|
@@ -948,7 +950,7 @@ class et extends u {
|
|
|
948
950
|
(f) => this.setStep(f)
|
|
949
951
|
);
|
|
950
952
|
this.stepInput = d.input, l.appendChild(d.row);
|
|
951
|
-
const y =
|
|
953
|
+
const y = o("hr", { className: "cp-separator" });
|
|
952
954
|
l.appendChild(y), this.signalHandler = new H({
|
|
953
955
|
container: l,
|
|
954
956
|
onChange: (f, b) => this.applySignal(f, b)
|
|
@@ -985,14 +987,14 @@ class et extends u {
|
|
|
985
987
|
return i + Math.round((t - i) / s) * s;
|
|
986
988
|
}
|
|
987
989
|
createSetting(t, e, s) {
|
|
988
|
-
const i =
|
|
990
|
+
const i = o("div", { className: "cp-setting-row" }), a = o("label", { className: "cp-setting-label" }, [
|
|
989
991
|
t
|
|
990
|
-
]),
|
|
992
|
+
]), r = o("input", {
|
|
991
993
|
type: "number",
|
|
992
994
|
className: "cp-input-number cp-input-small",
|
|
993
995
|
step: "any"
|
|
994
996
|
});
|
|
995
|
-
return e !== void 0 && (
|
|
997
|
+
return e !== void 0 && (r.value = String(e)), r.addEventListener("input", () => s(r.value)), i.appendChild(a), i.appendChild(r), { row: i, input: r };
|
|
996
998
|
}
|
|
997
999
|
updateDisplay() {
|
|
998
1000
|
this.input.value = String(this.value), this.display.textContent = String(this.value.toFixed(1));
|
|
@@ -1035,11 +1037,11 @@ class et extends u {
|
|
|
1035
1037
|
}
|
|
1036
1038
|
class st extends u {
|
|
1037
1039
|
constructor(t, e, s) {
|
|
1038
|
-
super(t, e, s), this.optionValues = [], this.select =
|
|
1039
|
-
const
|
|
1040
|
+
super(t, e, s), this.optionValues = [], this.select = o("select", { className: "cp-select" }), this.optionValues = s.options || [], this.optionValues.forEach((i, a) => {
|
|
1041
|
+
const r = o("option", { value: String(a) }, [
|
|
1040
1042
|
String(i)
|
|
1041
1043
|
]);
|
|
1042
|
-
this.select.appendChild(
|
|
1044
|
+
this.select.appendChild(r);
|
|
1043
1045
|
}), this.updateDisplay(), this.select.addEventListener("change", () => {
|
|
1044
1046
|
const i = parseInt(this.select.value), a = this.optionValues[i];
|
|
1045
1047
|
this.setValue(a);
|
|
@@ -1047,7 +1049,7 @@ class st extends u {
|
|
|
1047
1049
|
}
|
|
1048
1050
|
setOptions(t) {
|
|
1049
1051
|
this.select.innerHTML = "", this.optionValues = t, this.optionValues.forEach((e, s) => {
|
|
1050
|
-
const i =
|
|
1052
|
+
const i = o("option", { value: String(s) }, [
|
|
1051
1053
|
String(e)
|
|
1052
1054
|
]);
|
|
1053
1055
|
this.select.appendChild(i);
|
|
@@ -1063,11 +1065,11 @@ class it extends u {
|
|
|
1063
1065
|
const i = { action: e };
|
|
1064
1066
|
super(i, "action", s), this.domElement.querySelector(".cp-label")?.remove();
|
|
1065
1067
|
const a = s.label ?? t;
|
|
1066
|
-
this.button =
|
|
1068
|
+
this.button = o("button", { className: "cp-button" }, [
|
|
1067
1069
|
String(a)
|
|
1068
1070
|
]), this.button.addEventListener("click", () => {
|
|
1069
|
-
const
|
|
1070
|
-
typeof
|
|
1071
|
+
const r = this.value;
|
|
1072
|
+
typeof r == "function" && r(), this.emitChange(r);
|
|
1071
1073
|
}), this.appendWidget(this.button);
|
|
1072
1074
|
}
|
|
1073
1075
|
updateDisplay() {
|
|
@@ -1075,7 +1077,7 @@ class it extends u {
|
|
|
1075
1077
|
}
|
|
1076
1078
|
class nt extends u {
|
|
1077
1079
|
constructor(t, e, s = {}) {
|
|
1078
|
-
super(t, e, s), this.input =
|
|
1080
|
+
super(t, e, s), this.input = o("input", {
|
|
1079
1081
|
type: "checkbox",
|
|
1080
1082
|
className: "cp-checkbox"
|
|
1081
1083
|
}), this.input.checked = this.value, this.input.addEventListener("change", () => {
|
|
@@ -1088,8 +1090,8 @@ class nt extends u {
|
|
|
1088
1090
|
}
|
|
1089
1091
|
class at extends u {
|
|
1090
1092
|
constructor(t, e, s) {
|
|
1091
|
-
super(t, e, s), this.buttons = [], this.optionValues = [], this.container =
|
|
1092
|
-
const a =
|
|
1093
|
+
super(t, e, s), this.buttons = [], this.optionValues = [], this.container = o("div", { className: "cp-radios" }), this.optionValues = s.options || [], this.optionValues.forEach((i) => {
|
|
1094
|
+
const a = o("button", { className: "cp-button cp-radio" }, [
|
|
1093
1095
|
String(i)
|
|
1094
1096
|
]);
|
|
1095
1097
|
a.addEventListener("click", () => {
|
|
@@ -1104,9 +1106,9 @@ class at extends u {
|
|
|
1104
1106
|
});
|
|
1105
1107
|
}
|
|
1106
1108
|
}
|
|
1107
|
-
class
|
|
1109
|
+
class rt extends u {
|
|
1108
1110
|
constructor(t, e, s = {}) {
|
|
1109
|
-
super(t, e, s), this.input =
|
|
1111
|
+
super(t, e, s), this.input = o("input", {
|
|
1110
1112
|
type: "color",
|
|
1111
1113
|
className: "cp-input-color",
|
|
1112
1114
|
value: this.value || "#000000"
|
|
@@ -1121,7 +1123,7 @@ class ot extends u {
|
|
|
1121
1123
|
}
|
|
1122
1124
|
function $(n) {
|
|
1123
1125
|
const t = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
1124
|
-
n = n.replace(t, (s, i, a,
|
|
1126
|
+
n = n.replace(t, (s, i, a, r) => i + i + a + a + r + r);
|
|
1125
1127
|
const e = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);
|
|
1126
1128
|
return e ? [
|
|
1127
1129
|
parseInt(e[1], 16),
|
|
@@ -1129,7 +1131,7 @@ function $(n) {
|
|
|
1129
1131
|
parseInt(e[3], 16)
|
|
1130
1132
|
] : [0, 0, 0];
|
|
1131
1133
|
}
|
|
1132
|
-
function
|
|
1134
|
+
function ot(n, t, e) {
|
|
1133
1135
|
return "#" + ((1 << 24) + (Math.round(n) << 16) + (Math.round(t) << 8) + Math.round(e)).toString(16).slice(1);
|
|
1134
1136
|
}
|
|
1135
1137
|
function T(n) {
|
|
@@ -1140,8 +1142,8 @@ function F(n) {
|
|
|
1140
1142
|
return n <= 31308e-7 ? n * 12.92 * 255 : (1.055 * Math.pow(n, 1 / 2.4) - 0.055) * 255;
|
|
1141
1143
|
}
|
|
1142
1144
|
function lt(n, t, e) {
|
|
1143
|
-
const [s, i, a] = $(n), [
|
|
1144
|
-
return
|
|
1145
|
+
const [s, i, a] = $(n), [r, l, p] = $(t), h = T(s), d = T(i), y = T(a), f = T(r), b = T(l), E = T(p), g = h + e * (f - h), V = d + e * (b - d), S = y + e * (E - y), c = F(g), m = F(V), v = F(S);
|
|
1146
|
+
return ot(c, m, v);
|
|
1145
1147
|
}
|
|
1146
1148
|
class ct extends u {
|
|
1147
1149
|
constructor(t, e, s = {}) {
|
|
@@ -1149,23 +1151,23 @@ class ct extends u {
|
|
|
1149
1151
|
{ color: "#000000", position: 0 },
|
|
1150
1152
|
{ color: "#ffffff", position: 1 }
|
|
1151
1153
|
], this.sortStops();
|
|
1152
|
-
const i =
|
|
1154
|
+
const i = o("details", {
|
|
1153
1155
|
className: "cp-controller-details"
|
|
1154
|
-
}), a =
|
|
1156
|
+
}), a = o("summary", {
|
|
1155
1157
|
className: "cp-controller-summary"
|
|
1156
|
-
}),
|
|
1158
|
+
}), r = o("div", {
|
|
1157
1159
|
className: "cp-controller-summary-content"
|
|
1158
1160
|
});
|
|
1159
|
-
this.displayText =
|
|
1161
|
+
this.displayText = o(
|
|
1160
1162
|
"span",
|
|
1161
1163
|
{ className: "cp-value-display" },
|
|
1162
1164
|
[String(this.value)]
|
|
1163
|
-
),
|
|
1164
|
-
const l =
|
|
1165
|
-
this.stopsContainer =
|
|
1165
|
+
), r.appendChild(this.displayText), a.appendChild(r), i.appendChild(a);
|
|
1166
|
+
const l = o("div", { className: "cp-number-settings" });
|
|
1167
|
+
this.stopsContainer = o("div", {
|
|
1166
1168
|
className: "cp-stops-container"
|
|
1167
1169
|
}), this.renderStops(), l.appendChild(this.stopsContainer);
|
|
1168
|
-
const p =
|
|
1170
|
+
const p = o(
|
|
1169
1171
|
"button",
|
|
1170
1172
|
{
|
|
1171
1173
|
className: "cp-button"
|
|
@@ -1175,7 +1177,7 @@ class ct extends u {
|
|
|
1175
1177
|
p.addEventListener("click", () => {
|
|
1176
1178
|
this.stops.push({ color: "#ffffff", position: 0.5 }), this.sortStops(), this.renderStops(), this.updateOutput();
|
|
1177
1179
|
}), l.appendChild(p);
|
|
1178
|
-
const h =
|
|
1180
|
+
const h = o("hr", { className: "cp-separator" });
|
|
1179
1181
|
l.appendChild(h), this.signalHandler = new H({
|
|
1180
1182
|
container: l,
|
|
1181
1183
|
onChange: (d, y) => this.applySignal(d, y)
|
|
@@ -1186,7 +1188,7 @@ class ct extends u {
|
|
|
1186
1188
|
}
|
|
1187
1189
|
renderStops() {
|
|
1188
1190
|
this.stopsContainer.innerHTML = "", this.stops.forEach((t, e) => {
|
|
1189
|
-
const s =
|
|
1191
|
+
const s = o("div", { className: "cp-gradient-stop-row" }), i = o("input", {
|
|
1190
1192
|
type: "color",
|
|
1191
1193
|
className: "cp-input-color",
|
|
1192
1194
|
value: t.color
|
|
@@ -1194,7 +1196,7 @@ class ct extends u {
|
|
|
1194
1196
|
i.addEventListener("input", (l) => {
|
|
1195
1197
|
t.color = l.target.value, this.updateOutput();
|
|
1196
1198
|
});
|
|
1197
|
-
const a =
|
|
1199
|
+
const a = o("input", {
|
|
1198
1200
|
type: "number",
|
|
1199
1201
|
className: "cp-input-number cp-input-small",
|
|
1200
1202
|
min: "0",
|
|
@@ -1206,10 +1208,10 @@ class ct extends u {
|
|
|
1206
1208
|
let p = parseFloat(l.target.value);
|
|
1207
1209
|
isNaN(p) && (p = 0), t.position = Math.max(0, Math.min(1, p)), this.sortStops(), this.renderStops(), this.updateOutput();
|
|
1208
1210
|
});
|
|
1209
|
-
const
|
|
1211
|
+
const r = j(() => {
|
|
1210
1212
|
this.stops.splice(e, 1), this.renderStops(), this.updateOutput();
|
|
1211
1213
|
});
|
|
1212
|
-
s.appendChild(i), s.appendChild(a), s.appendChild(
|
|
1214
|
+
s.appendChild(i), s.appendChild(a), s.appendChild(r), this.stopsContainer.appendChild(s);
|
|
1213
1215
|
});
|
|
1214
1216
|
}
|
|
1215
1217
|
// Calculate color at t (0-1) and update value
|
|
@@ -1228,7 +1230,7 @@ class ct extends u {
|
|
|
1228
1230
|
for (let s = 0; s < this.stops.length - 1; s++) {
|
|
1229
1231
|
const i = this.stops[s], a = this.stops[s + 1];
|
|
1230
1232
|
if (t >= i.position && t <= a.position) {
|
|
1231
|
-
const
|
|
1233
|
+
const r = a.position - i.position, l = r === 0 ? 0 : (t - i.position) / r;
|
|
1232
1234
|
e = lt(i.color, a.color, l);
|
|
1233
1235
|
break;
|
|
1234
1236
|
}
|
|
@@ -1271,21 +1273,21 @@ class ct extends u {
|
|
|
1271
1273
|
class pt extends u {
|
|
1272
1274
|
constructor(t, e, s = {}) {
|
|
1273
1275
|
super(t, e, s), this.items = [], this.initialOptions = s, this.itemType = s.itemType || "string", this.items = this.parseValue(this.value);
|
|
1274
|
-
const i =
|
|
1276
|
+
const i = o("details", {
|
|
1275
1277
|
className: "cp-controller-details"
|
|
1276
|
-
}), a =
|
|
1278
|
+
}), a = o("summary", {
|
|
1277
1279
|
className: "cp-controller-summary"
|
|
1278
|
-
}),
|
|
1280
|
+
}), r = o("div", {
|
|
1279
1281
|
className: "cp-controller-summary-content"
|
|
1280
|
-
}), l =
|
|
1282
|
+
}), l = o("span", { className: "cp-value-display" }, [
|
|
1281
1283
|
`${this.items.length} items`
|
|
1282
1284
|
]);
|
|
1283
|
-
|
|
1284
|
-
const p =
|
|
1285
|
-
this.itemsContainer =
|
|
1285
|
+
r.appendChild(l), a.appendChild(r), i.appendChild(a);
|
|
1286
|
+
const p = o("div", { className: "cp-number-settings" });
|
|
1287
|
+
this.itemsContainer = o("div", {
|
|
1286
1288
|
className: "cp-stops-container"
|
|
1287
1289
|
}), this.renderItems(), p.appendChild(this.itemsContainer);
|
|
1288
|
-
const h =
|
|
1290
|
+
const h = o(
|
|
1289
1291
|
"button",
|
|
1290
1292
|
{
|
|
1291
1293
|
className: "cp-button cp-input-small",
|
|
@@ -1327,23 +1329,23 @@ class pt extends u {
|
|
|
1327
1329
|
}
|
|
1328
1330
|
renderItems() {
|
|
1329
1331
|
this.itemsContainer.innerHTML = "", this.items.forEach((t, e) => {
|
|
1330
|
-
const s =
|
|
1332
|
+
const s = o("div", { className: "cp-array-row" });
|
|
1331
1333
|
let i;
|
|
1332
|
-
this.itemType === "color" ? i =
|
|
1334
|
+
this.itemType === "color" ? i = o("input", {
|
|
1333
1335
|
type: "color",
|
|
1334
1336
|
className: "cp-input-color",
|
|
1335
1337
|
value: t
|
|
1336
|
-
}) : this.itemType === "number" ? i =
|
|
1338
|
+
}) : this.itemType === "number" ? i = o("input", {
|
|
1337
1339
|
type: "number",
|
|
1338
1340
|
className: "cp-input-number cp-input-small",
|
|
1339
1341
|
step: "any",
|
|
1340
1342
|
value: t
|
|
1341
|
-
}) : i =
|
|
1343
|
+
}) : i = o("input", {
|
|
1342
1344
|
type: "text",
|
|
1343
1345
|
className: "cp-input-number cp-input-small",
|
|
1344
1346
|
value: t
|
|
1345
|
-
}), i.addEventListener("input", (
|
|
1346
|
-
this.items[e] =
|
|
1347
|
+
}), i.addEventListener("input", (r) => {
|
|
1348
|
+
this.items[e] = r.target.value, this.updateValue();
|
|
1347
1349
|
});
|
|
1348
1350
|
const a = j(() => {
|
|
1349
1351
|
this.items.splice(e, 1), this.renderItems(), this.updateValue();
|
|
@@ -1376,7 +1378,7 @@ class ht {
|
|
|
1376
1378
|
i && (s = ` / ${Math.round(i.usedJSHeapSize / 1048576)}MB`), this.domElement.textContent = `${e} FPS${s}`, this.prevTime = t, this.frames = 0;
|
|
1377
1379
|
}
|
|
1378
1380
|
this.rafId = requestAnimationFrame(this.render);
|
|
1379
|
-
}, this.domElement =
|
|
1381
|
+
}, this.domElement = o("span", { className: "cp-stats" }), this.rafId = requestAnimationFrame(this.render);
|
|
1380
1382
|
}
|
|
1381
1383
|
destroy() {
|
|
1382
1384
|
cancelAnimationFrame(this.rafId);
|
|
@@ -1411,7 +1413,7 @@ class U {
|
|
|
1411
1413
|
return this.contentElement.appendChild(i.domElement), this.controllers.push(i), i;
|
|
1412
1414
|
}
|
|
1413
1415
|
addColor(t, e, s = {}) {
|
|
1414
|
-
const i = new
|
|
1416
|
+
const i = new rt(t, e, s);
|
|
1415
1417
|
return this.contentElement.appendChild(i.domElement), this.controllers.push(i), i;
|
|
1416
1418
|
}
|
|
1417
1419
|
addGradient(t, e, s = {}) {
|
|
@@ -1427,7 +1429,7 @@ class U {
|
|
|
1427
1429
|
return this.addSeparator(), this.contentElement.appendChild(e.domElement), this.folders.push(e), e;
|
|
1428
1430
|
}
|
|
1429
1431
|
addSeparator() {
|
|
1430
|
-
const t =
|
|
1432
|
+
const t = o("hr", { className: "cp-separator" });
|
|
1431
1433
|
this.contentElement.appendChild(t);
|
|
1432
1434
|
}
|
|
1433
1435
|
save() {
|
|
@@ -1467,47 +1469,47 @@ class U {
|
|
|
1467
1469
|
}
|
|
1468
1470
|
class dt extends U {
|
|
1469
1471
|
constructor(t) {
|
|
1470
|
-
super(), this.title = t, this.domElement =
|
|
1472
|
+
super(), this.title = t, this.domElement = o("details", {
|
|
1471
1473
|
className: "cp-folder",
|
|
1472
1474
|
open: !0
|
|
1473
|
-
}), this.summaryElement =
|
|
1475
|
+
}), this.summaryElement = o(
|
|
1474
1476
|
"summary",
|
|
1475
1477
|
{
|
|
1476
1478
|
className: "cp-summary"
|
|
1477
1479
|
},
|
|
1478
1480
|
[t]
|
|
1479
|
-
), this.domElement.appendChild(this.summaryElement), this.contentElement =
|
|
1481
|
+
), this.domElement.appendChild(this.summaryElement), this.contentElement = o("div", {
|
|
1480
1482
|
className: "cp-content cp-folder-content"
|
|
1481
1483
|
}), this.domElement.appendChild(this.contentElement);
|
|
1482
1484
|
}
|
|
1483
1485
|
}
|
|
1484
1486
|
class ut extends U {
|
|
1485
1487
|
constructor(t, e = {}) {
|
|
1486
|
-
super(), _(), this.domElement =
|
|
1488
|
+
super(), _(), this.domElement = o("details", {
|
|
1487
1489
|
className: "cp-root",
|
|
1488
1490
|
open: !0
|
|
1489
|
-
}), this.summaryElement =
|
|
1491
|
+
}), this.summaryElement = o("summary", {
|
|
1490
1492
|
className: "cp-summary cp-summary-root"
|
|
1491
1493
|
}), this.domElement.appendChild(this.summaryElement);
|
|
1492
|
-
const s =
|
|
1494
|
+
const s = o("span", {}, [
|
|
1493
1495
|
e.title || "ControlPanel"
|
|
1494
1496
|
]);
|
|
1495
1497
|
this.summaryElement.appendChild(s), this.stats = new ht(), this.summaryElement.appendChild(this.stats.domElement);
|
|
1496
|
-
let i = !1, a = 0,
|
|
1498
|
+
let i = !1, a = 0, r = 0, l = 0, p = 0;
|
|
1497
1499
|
this.summaryElement.addEventListener("mousedown", (c) => {
|
|
1498
1500
|
if (c.target !== this.summaryElement && c.target !== s) return;
|
|
1499
|
-
i = !0, a = c.clientX,
|
|
1501
|
+
i = !0, a = c.clientX, r = c.clientY;
|
|
1500
1502
|
const m = this.domElement.getBoundingClientRect();
|
|
1501
1503
|
l = m.left, p = m.top, c.preventDefault();
|
|
1502
1504
|
}), document.addEventListener("mousemove", (c) => {
|
|
1503
1505
|
if (!i) return;
|
|
1504
|
-
const m = c.clientX - a, v = c.clientY -
|
|
1506
|
+
const m = c.clientX - a, v = c.clientY - r, w = l + m, M = p + v;
|
|
1505
1507
|
this.domElement.style.left = `${w}px`, this.domElement.style.top = `${M}px`, this.domElement.style.right = "auto", this.domElement.style.bottom = "auto";
|
|
1506
1508
|
}), document.addEventListener("mouseup", () => {
|
|
1507
1509
|
i && (i = !1, this.savePositionAndSize());
|
|
1508
1510
|
}), new ResizeObserver(() => {
|
|
1509
1511
|
i || this.savePositionAndSize();
|
|
1510
|
-
}).observe(this.domElement), this.restorePositionAndSize(), this.contentElement =
|
|
1512
|
+
}).observe(this.domElement), this.restorePositionAndSize(), this.contentElement = o("div", { className: "cp-content" }), this.domElement.appendChild(this.contentElement);
|
|
1511
1513
|
const d = this.addFolder("_Signals"), y = {
|
|
1512
1514
|
audioInput: null,
|
|
1513
1515
|
fftSize: 2048
|
|
@@ -1701,7 +1703,7 @@ export {
|
|
|
1701
1703
|
X as AudioSignals,
|
|
1702
1704
|
nt as BooleanController,
|
|
1703
1705
|
it as ButtonController,
|
|
1704
|
-
|
|
1706
|
+
rt as ColorController,
|
|
1705
1707
|
ut as ControlPanel,
|
|
1706
1708
|
U as ControlPanelContainer,
|
|
1707
1709
|
u as Controller,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
-
--cp-scale:
|
|
3
|
+
--cp-scale: 2;
|
|
4
4
|
|
|
5
5
|
--cp-space-1: calc(1px * var(--cp-scale));
|
|
6
6
|
--cp-space-2: calc(2px * var(--cp-scale));
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
--cp-space-6: calc(6px * var(--cp-scale));
|
|
9
9
|
--cp-space-8: calc(8px * var(--cp-scale));
|
|
10
10
|
|
|
11
|
+
--cp-border-width: calc(1px * var(--cp-scale));
|
|
12
|
+
|
|
11
13
|
--cp-font-size-main: calc(10px * var(--cp-scale));
|
|
12
14
|
--cp-font-size-details: calc(10px * var(--cp-scale));
|
|
13
15
|
|
|
@@ -142,7 +144,7 @@
|
|
|
142
144
|
padding: var(--cp-space-2) var(--cp-space-4);
|
|
143
145
|
background: transparent;
|
|
144
146
|
color: inherit;
|
|
145
|
-
border:
|
|
147
|
+
border: var(--cp-border-width) solid var(--cp-color-2);
|
|
146
148
|
border-radius: var(--cp-border-radius);
|
|
147
149
|
font-family: inherit;
|
|
148
150
|
font-size: inherit;
|
|
@@ -186,7 +188,7 @@
|
|
|
186
188
|
-moz-appearance: none;
|
|
187
189
|
color: transparent;
|
|
188
190
|
background: transparent;
|
|
189
|
-
border:
|
|
191
|
+
border: var(--cp-border-width) solid var(--cp-color-2);
|
|
190
192
|
border-radius: var(--cp-border-radius);
|
|
191
193
|
outline: none;
|
|
192
194
|
font-size: 0;
|
|
@@ -292,7 +294,7 @@
|
|
|
292
294
|
margin: var(--cp-space-4) 0;
|
|
293
295
|
width: 100%;
|
|
294
296
|
border: none;
|
|
295
|
-
border-top:
|
|
297
|
+
border-top: var(--cp-border-width) solid var(--cp-color-1);
|
|
296
298
|
}
|
|
297
299
|
|
|
298
300
|
.cp-setting-row {
|
|
@@ -360,7 +362,7 @@
|
|
|
360
362
|
.cp-input-color {
|
|
361
363
|
width: var(--cp-swatch-size);
|
|
362
364
|
height: var(--cp-swatch-size);
|
|
363
|
-
border:
|
|
365
|
+
border: var(--cp-border-width) solid var(--cp-color-1);
|
|
364
366
|
border-radius: 50%;
|
|
365
367
|
-webkit-appearance: none;
|
|
366
368
|
}
|
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":"AAuYA,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.17",
|
|
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)",
|