perfect-gui 4.11.1 → 4.11.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/dist/perfect-gui.mjs +114 -114
- package/dist/perfect-gui.umd.js +2 -2
- package/package.json +1 -1
- package/src/components/Slider.js +6 -6
- package/src/index.js +1 -1
package/dist/perfect-gui.mjs
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
class E {
|
|
2
|
-
constructor(e = {},
|
|
3
|
-
if (this.propReferences = [], typeof
|
|
4
|
-
throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof
|
|
5
|
-
let
|
|
2
|
+
constructor(e, t = {}, i) {
|
|
3
|
+
if (this.parent = e, this.propReferences = [], typeof t != "object")
|
|
4
|
+
throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof t}.`);
|
|
5
|
+
let a = typeof t.name == "string" && t.name || " ";
|
|
6
6
|
this.isObject = !1;
|
|
7
|
-
let
|
|
8
|
-
this.obj =
|
|
9
|
-
let
|
|
10
|
-
if (this.min =
|
|
7
|
+
let s = null;
|
|
8
|
+
this.obj = t.obj, this.prop = t.prop;
|
|
9
|
+
let o = typeof t.value == "number" ? t.value : null;
|
|
10
|
+
if (this.min = t.min ?? 0, this.max = t.max ?? 1, this.step = t.step || (this.max - this.min) / 100, o !== null)
|
|
11
11
|
(this.prop != null || this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
|
|
12
12
|
else if (this.prop != null && this.obj != null) {
|
|
13
13
|
if (typeof this.prop != "string")
|
|
14
14
|
throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof this.prop}.`);
|
|
15
15
|
if (typeof this.obj != "object")
|
|
16
16
|
throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof this.obj}.`);
|
|
17
|
-
|
|
17
|
+
a == " " && (a = this.prop), s = this.propReferences.push(this.obj[this.prop]) - 1, this.isObject = !0;
|
|
18
18
|
} else
|
|
19
|
-
(this.prop != null && this.obj == null || this.prop == null && this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),
|
|
20
|
-
const
|
|
19
|
+
(this.prop != null && this.obj == null || this.prop == null && this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), o = (this.max - this.min) / 2;
|
|
20
|
+
const n = typeof t.tooltip == "string" ? t.tooltip : t.tooltip === !0 ? a : null;
|
|
21
21
|
this.imageContainer = null;
|
|
22
|
-
const n = document.createElement("div");
|
|
23
|
-
n.className = "p-gui__slider", o && n.setAttribute("title", o);
|
|
24
22
|
const r = document.createElement("div");
|
|
25
|
-
r.className = "p-gui__slider
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
r.className = "p-gui__slider", n && r.setAttribute("title", n);
|
|
24
|
+
const p = document.createElement("div");
|
|
25
|
+
p.className = "p-gui__slider-name", p.textContent = a, r.append(p), this.ctrlDiv = document.createElement("div"), this.ctrlDiv.className = "p-gui__slider-ctrl", this.ctrlDiv.setAttribute("type", "range"), this.ctrlDiv.setAttribute("min", this.min), this.ctrlDiv.setAttribute("max", this.max), r.append(this.ctrlDiv);
|
|
26
|
+
const l = document.createElement("div");
|
|
27
|
+
return l.className = "p-gui__slider-bar", this.ctrlDiv.append(l), this.handle = document.createElement("div"), this.handle.className = "p-gui__slider-handle", this.ctrlDiv.append(this.handle), this.filling = document.createElement("div"), this.filling.className = "p-gui__slider-filling", l.append(this.filling), this.valueInput = document.createElement("input"), this.valueInput.className = "p-gui__slider-value", this.valueInput.value = this.isObject ? this.obj[this.prop] : o, r.append(this.valueInput), setTimeout(() => {
|
|
28
|
+
const d = this.handle.offsetWidth;
|
|
29
|
+
this.handle.position = this._mapLinear(this.valueInput.value, this.min, this.max, d / 2, 88 - d / 2), this.handle.style.transform = `translate(-50%, -50%) translateX(${this.handle.position}px)`, this.filling.style.width = `${this.handle.position}px`;
|
|
30
30
|
}, 0), this.valueInput.addEventListener("change", () => {
|
|
31
31
|
this._updateHandlePositionFromValue(), this._triggerCallbacks();
|
|
32
|
-
}), this.ctrlDiv.addEventListener("pointerdown", (
|
|
33
|
-
this.ctrlDiv.pointerDown = !0, this.ctrlDiv.prevPosition =
|
|
34
|
-
}), window.addEventListener("pointerup", (
|
|
32
|
+
}), this.ctrlDiv.addEventListener("pointerdown", (d) => {
|
|
33
|
+
this.ctrlDiv.pointerDown = !0, this.ctrlDiv.prevPosition = d.clientX, this._updateHandlePositionFromPointer(d, !0);
|
|
34
|
+
}), window.addEventListener("pointerup", (d) => {
|
|
35
35
|
this.ctrlDiv.pointerDown = !1;
|
|
36
|
-
}), window.addEventListener("pointermove", (
|
|
37
|
-
this.ctrlDiv.pointerDown && (this.ctrlDiv.pointerDelta =
|
|
36
|
+
}), window.addEventListener("pointermove", (d) => {
|
|
37
|
+
this.ctrlDiv.pointerDown && (this.ctrlDiv.pointerDelta = d.clientX - this.ctrlDiv.prevPosition, this._updateHandlePositionFromPointer(d));
|
|
38
38
|
}), this.isObject && Object.defineProperty(this.obj, this.prop, {
|
|
39
|
-
set: (
|
|
40
|
-
this.propReferences[
|
|
39
|
+
set: (d) => {
|
|
40
|
+
this.propReferences[s] = d, this.valueInput.value = d, this._updateHandlePositionFromValue(), typeof i == "function" && i(parseFloat(this.valueInput.value));
|
|
41
41
|
},
|
|
42
|
-
get: () => this.propReferences[
|
|
43
|
-
}),
|
|
42
|
+
get: () => this.propReferences[s]
|
|
43
|
+
}), r;
|
|
44
44
|
}
|
|
45
45
|
_updateHandlePositionFromPointer(e, t = !1) {
|
|
46
|
-
const i = this.ctrlDiv.offsetWidth,
|
|
46
|
+
const i = this.ctrlDiv.offsetWidth, a = this.handle.offsetWidth, s = e.clientX - this.ctrlDiv.prevPosition;
|
|
47
47
|
let o;
|
|
48
48
|
const n = parseFloat(this.valueInput.value);
|
|
49
|
-
t ? o = e.offsetX : o = this.handle.position +
|
|
50
|
-
let r = this.min + (this.max - this.min) * (o -
|
|
49
|
+
t ? o = e.offsetX : o = this.handle.position + s, o = Math.max(a / 2, Math.min(o, i - a / 2));
|
|
50
|
+
let r = this.min + (this.max - this.min) * (o - a / 2) / (i - a);
|
|
51
51
|
r > n ? r = this._quantizeFloor(r, this.step) : r = this._quantizeCeil(r, this.step), r = parseFloat(r.toFixed(9));
|
|
52
|
-
const
|
|
53
|
-
if (r >=
|
|
54
|
-
const
|
|
55
|
-
r = r.toFixed(
|
|
52
|
+
const p = parseFloat((n + this.step).toFixed(9)), l = parseFloat((n - this.step).toFixed(9));
|
|
53
|
+
if (r >= p || r <= l) {
|
|
54
|
+
const d = this._countDecimals(this.step);
|
|
55
|
+
r = r.toFixed(d), this.valueInput.value = r, this.ctrlDiv.prevPosition = e.clientX, this.handle.style.transform = `translate(-50%, -50%) translateX(${o}px)`, this.handle.position = o, this.filling.style.width = this.handle.position + "px", this._triggerCallbacks();
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
_countDecimals(e) {
|
|
@@ -65,10 +65,10 @@ class E {
|
|
|
65
65
|
i = Math.max(t / 2, Math.min(i, e - t / 2)), this.handle.style.transform = `translate(-50%, -50%) translateX(${i}px)`, this.handle.position = i, this.filling.style.width = this.handle.position + "px";
|
|
66
66
|
}
|
|
67
67
|
_triggerCallbacks() {
|
|
68
|
-
this.isObject ? this.obj[this.prop] = parseFloat(this.valueInput.value) : typeof callback == "function" && callback(parseFloat(this.valueInput.value)), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
|
|
68
|
+
this.isObject ? this.obj[this.prop] = parseFloat(this.valueInput.value) : typeof callback == "function" && callback(parseFloat(this.valueInput.value)), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
69
69
|
}
|
|
70
|
-
_mapLinear(e, t, i,
|
|
71
|
-
return
|
|
70
|
+
_mapLinear(e, t, i, a, s) {
|
|
71
|
+
return a + (e - t) * (s - a) / (i - t);
|
|
72
72
|
}
|
|
73
73
|
_quantize(e, t) {
|
|
74
74
|
return t * Math.round(e / t);
|
|
@@ -701,12 +701,12 @@ class A {
|
|
|
701
701
|
button(e, t) {
|
|
702
702
|
let i = "";
|
|
703
703
|
typeof e != "string" ? typeof e == "object" && (e != null && e.hasOwnProperty("name")) ? i = e.name == "" ? " " : e.name : i = " " : i = e == "" ? " " : e;
|
|
704
|
-
const
|
|
704
|
+
const a = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
|
|
705
705
|
this.imageContainer = null;
|
|
706
|
-
const
|
|
707
|
-
|
|
706
|
+
const s = document.createElement("div");
|
|
707
|
+
s.className = "p-gui__button", s.textContent = i, a && s.setAttribute("title", a), s.addEventListener("click", () => {
|
|
708
708
|
this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate(), t && t();
|
|
709
|
-
}), this.wrapper.append(
|
|
709
|
+
}), this.wrapper.append(s), typeof e.color == "string" && (s.style.setProperty("--color-accent", e.color), s.style.setProperty("--color-accent-hover", e.hoverColor || e.color));
|
|
710
710
|
}
|
|
711
711
|
image(e = {}, t) {
|
|
712
712
|
if (typeof e != "object")
|
|
@@ -716,29 +716,29 @@ class A {
|
|
|
716
716
|
i = e.path;
|
|
717
717
|
else
|
|
718
718
|
throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
|
|
719
|
-
let
|
|
720
|
-
e.name == null ?
|
|
721
|
-
const o = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ?
|
|
722
|
-
let
|
|
723
|
-
e.width && (typeof e.width == "number" && (e.width += "px"),
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
const
|
|
727
|
-
return
|
|
728
|
-
let c =
|
|
719
|
+
let a = i.replace(/^.*[\\\/]/, ""), s;
|
|
720
|
+
e.name == null ? s = a : s = typeof e.name == "string" && e.name || " ";
|
|
721
|
+
const o = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null, n = e.selected === !0, r = e.selectionBorder !== !1;
|
|
722
|
+
let p = "";
|
|
723
|
+
e.width && (typeof e.width == "number" && (e.width += "px"), p += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), p += `height: ${e.height}; `), this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer));
|
|
724
|
+
const l = document.createElement("div");
|
|
725
|
+
l.className = "p-gui__image", l.style = "background-image: url(" + i + "); " + p, o && l.setAttribute("title", o), this.imageContainer.append(l), n && r && l.classList.add("p-gui__image--selected");
|
|
726
|
+
const d = document.createElement("div");
|
|
727
|
+
return d.className = "p-gui__image-text", d.textContent = s, l.append(d), l.addEventListener("click", () => {
|
|
728
|
+
let c = l.parentElement.querySelectorAll(".p-gui__image--selected");
|
|
729
729
|
for (let f = 0; f < c.length; f++)
|
|
730
730
|
c[f].classList.remove("p-gui__image--selected");
|
|
731
|
-
r &&
|
|
732
|
-
}),
|
|
731
|
+
r && l.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: i, text: s }), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
|
|
732
|
+
}), l;
|
|
733
733
|
}
|
|
734
734
|
slider(e = {}, t) {
|
|
735
|
-
const i = new E(e, t);
|
|
735
|
+
const i = new E(this, e, t);
|
|
736
736
|
this.wrapper.append(i);
|
|
737
737
|
}
|
|
738
738
|
toggle(e = {}, t) {
|
|
739
739
|
if (typeof e != "object")
|
|
740
740
|
throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
|
|
741
|
-
let i = typeof e.name == "string" && e.name || " ",
|
|
741
|
+
let i = typeof e.name == "string" && e.name || " ", a = !1, s = null, o = e.obj, n = e.prop, r = typeof e.value == "boolean" ? e.value : null;
|
|
742
742
|
if (r !== null)
|
|
743
743
|
(n != null || o != null) && console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
|
|
744
744
|
else if (n != null && o != null) {
|
|
@@ -746,33 +746,33 @@ class A {
|
|
|
746
746
|
throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof n}.`);
|
|
747
747
|
if (typeof o != "object")
|
|
748
748
|
throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof o}.`);
|
|
749
|
-
i == " " && (i = n),
|
|
749
|
+
i == " " && (i = n), s = this.propReferences.push(o[n]) - 1, a = !0;
|
|
750
750
|
} else
|
|
751
751
|
(n != null && o == null || n == null && o == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
|
|
752
|
-
const
|
|
752
|
+
const p = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
|
|
753
753
|
this.imageContainer = null;
|
|
754
|
-
const
|
|
755
|
-
|
|
754
|
+
const l = document.createElement("div");
|
|
755
|
+
l.textContent = i, l.className = "p-gui__switch", p && l.setAttribute("title", p), this.wrapper.append(l), l.addEventListener("click", (f) => {
|
|
756
756
|
const u = f.target.childNodes[1];
|
|
757
757
|
let g = !0;
|
|
758
|
-
u.classList.contains("p-gui__switch-checkbox--active") && (g = !1), u.classList.toggle("p-gui__switch-checkbox--active"),
|
|
758
|
+
u.classList.contains("p-gui__switch-checkbox--active") && (g = !1), u.classList.toggle("p-gui__switch-checkbox--active"), a ? o[n] = g : typeof t == "function" && t(g), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
|
|
759
759
|
});
|
|
760
|
-
let
|
|
760
|
+
let d = (() => a ? o[n] ? " p-gui__switch-checkbox--active" : "" : r ? " p-gui__switch-checkbox--active" : "")();
|
|
761
761
|
const c = document.createElement("div");
|
|
762
|
-
c.className = "p-gui__switch-checkbox" +
|
|
762
|
+
c.className = "p-gui__switch-checkbox" + d, l.append(c), a && Object.defineProperty(o, n, {
|
|
763
763
|
set: (f) => {
|
|
764
|
-
this.propReferences[
|
|
764
|
+
this.propReferences[s] = f, f ? c.classList.add("p-gui__switch-checkbox--active") : c.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(f);
|
|
765
765
|
},
|
|
766
|
-
get: () => this.propReferences[
|
|
766
|
+
get: () => this.propReferences[s]
|
|
767
767
|
});
|
|
768
768
|
}
|
|
769
769
|
list(e = {}, t) {
|
|
770
770
|
if (typeof e != "object")
|
|
771
771
|
throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
|
|
772
|
-
let i = typeof e.name == "string" ? e.name : " ",
|
|
773
|
-
const
|
|
772
|
+
let i = typeof e.name == "string" ? e.name : " ", a = !1, s = null, o = e.obj, n = e.prop, r = Array.isArray(e.values) ? e.values : null, p, l = typeof r[0] != "string";
|
|
773
|
+
const d = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
|
|
774
774
|
if (t = typeof t == "function" ? t : null, e.value !== void 0 || e.value === void 0 && o === void 0 && n === void 0)
|
|
775
|
-
(n != null || o != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'),
|
|
775
|
+
(n != null || o != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'), p = (() => {
|
|
776
776
|
if (!r)
|
|
777
777
|
return null;
|
|
778
778
|
if (typeof e.value == "string")
|
|
@@ -785,49 +785,49 @@ class A {
|
|
|
785
785
|
throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof n}.`);
|
|
786
786
|
if (typeof o != "object")
|
|
787
787
|
throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof o}.`);
|
|
788
|
-
|
|
788
|
+
p = (() => {
|
|
789
789
|
if (!r)
|
|
790
790
|
return null;
|
|
791
791
|
if (typeof o[n] == "string")
|
|
792
|
-
return
|
|
792
|
+
return l ? r.find((u) => u.value === o[n]).value : r.indexOf(o[n]);
|
|
793
793
|
if (typeof o[n] == "number")
|
|
794
|
-
return
|
|
795
|
-
})(),
|
|
794
|
+
return l ? r.find((u) => u.value === o[n]).value : o[n];
|
|
795
|
+
})(), s = this.propReferences.push(o[n]) - 1, a = !0;
|
|
796
796
|
} else
|
|
797
797
|
(n != null && o == null || n == null && o == null) && console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');
|
|
798
798
|
this.imageContainer = null;
|
|
799
799
|
let c = document.createElement("div");
|
|
800
|
-
c.className = "p-gui__list", c.textContent = i,
|
|
800
|
+
c.className = "p-gui__list", c.textContent = i, d && c.setAttribute("title", d), this.wrapper.append(c);
|
|
801
801
|
let f = document.createElement("select");
|
|
802
802
|
c.append(f), f.className = "p-gui__list-dropdown", f.addEventListener("change", (u) => {
|
|
803
|
-
|
|
803
|
+
a ? o[n] = u.target.value : t && t(u.target.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
|
|
804
804
|
}), r && r.forEach((u, g) => {
|
|
805
|
-
const _ =
|
|
805
|
+
const _ = l ? u.name : u, h = l ? u.value : u;
|
|
806
806
|
let x = document.createElement("option");
|
|
807
|
-
x.setAttribute("value", h), x.textContent = _, f.append(x), (!
|
|
808
|
-
}),
|
|
807
|
+
x.setAttribute("value", h), x.textContent = _, f.append(x), (!l && p == g || l && p == h) && x.setAttribute("selected", "");
|
|
808
|
+
}), a && Object.defineProperty(o, n, {
|
|
809
809
|
set: (u) => {
|
|
810
810
|
let g, _, h;
|
|
811
|
-
|
|
811
|
+
l ? (h = r.find((v) => v.value == u), _ = (h == null ? void 0 : h.value) || r[0].value, g = r.indexOf(h)) : (typeof u == "string" && (g = r.indexOf(u), _ = u), typeof u == "number" && (g = u, _ = r[u])), this.propReferences[s] = l ? _ : u;
|
|
812
812
|
const x = f.querySelector("[selected]");
|
|
813
|
-
x && x.removeAttribute("selected"), f.querySelectorAll("option")[g].setAttribute("selected", ""), typeof t == "function" && t(
|
|
813
|
+
x && x.removeAttribute("selected"), f.querySelectorAll("option")[g].setAttribute("selected", ""), typeof t == "function" && t(l ? h : _, g);
|
|
814
814
|
},
|
|
815
|
-
get: () => this.propReferences[
|
|
815
|
+
get: () => this.propReferences[s]
|
|
816
816
|
});
|
|
817
817
|
}
|
|
818
818
|
vector2(e = {}, t) {
|
|
819
819
|
if (typeof e != "object")
|
|
820
820
|
throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
|
|
821
821
|
let i = typeof e.name == "string" && e.name || " ";
|
|
822
|
-
const
|
|
822
|
+
const a = e.x.min ?? 0, s = e.x.max ?? 1, o = e.y.min ?? 0, n = e.y.max ?? 1, r = e.x.obj, p = e.x.prop, l = this.propReferences.push(r[p]) - 1, d = e.y.obj, c = e.y.prop, f = this.propReferences.push(d[c]) - 1, u = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
|
|
823
823
|
t = typeof t == "function" ? t : null, this.imageContainer = null;
|
|
824
824
|
const g = document.createElement("div");
|
|
825
825
|
g.className = "p-gui__vector2", g.textContent = i, u && g.setAttribute("title", u), this.wrapper.append(g);
|
|
826
826
|
const _ = document.createElement("div");
|
|
827
|
-
_.className = "p-gui__vector-value", _.textContent = r[
|
|
827
|
+
_.className = "p-gui__vector-value", _.textContent = r[p] + ", " + d[c], g.append(_);
|
|
828
828
|
const h = document.createElement("div");
|
|
829
829
|
h.className = "p-gui__vector2-area", g.append(h), h.addEventListener("click", (b) => {
|
|
830
|
-
r[
|
|
830
|
+
r[p] = parseFloat(this._mapLinear(b.offsetX, 0, h.clientWidth, a, s).toFixed(2)), d[c] = parseFloat(this._mapLinear(b.offsetY, 0, h.clientHeight, n, o).toFixed(2)), t && t(r[p], r[c]), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
|
|
831
831
|
});
|
|
832
832
|
let x = !1;
|
|
833
833
|
h.addEventListener("pointerdown", (b) => {
|
|
@@ -835,21 +835,21 @@ class A {
|
|
|
835
835
|
}), h.addEventListener("pointerup", () => {
|
|
836
836
|
x = !1;
|
|
837
837
|
}), h.addEventListener("pointermove", (b) => {
|
|
838
|
-
x && (r[
|
|
838
|
+
x && (r[p] = parseFloat(this._mapLinear(b.offsetX, 0, h.clientWidth, a, s).toFixed(2)), d[c] = parseFloat(this._mapLinear(b.offsetY, 0, h.clientHeight, n, o).toFixed(2)), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate(), t && t(r[p], r[c]));
|
|
839
839
|
});
|
|
840
840
|
const v = document.createElement("div");
|
|
841
841
|
v.className = "p-gui__vector2-line p-gui__vector2-line-x", h.append(v);
|
|
842
842
|
const y = document.createElement("div");
|
|
843
843
|
y.className = "p-gui__vector2-line p-gui__vector2-line-y", h.append(y);
|
|
844
844
|
const m = document.createElement("div");
|
|
845
|
-
m.className = "p-gui__vector2-dot", h.append(m), m.style.left = this._mapLinear(r[
|
|
845
|
+
m.className = "p-gui__vector2-dot", h.append(m), m.style.left = this._mapLinear(r[p], a, s, 0, h.clientWidth) + "px", m.style.top = this._mapLinear(d[c], o, n, h.clientHeight, 0) + "px", Object.defineProperty(r, p, {
|
|
846
846
|
set: (b) => {
|
|
847
|
-
this.propReferences[
|
|
847
|
+
this.propReferences[l] = b, m.style.left = this._mapLinear(b, a, s, 0, h.clientWidth) + "px", _.textContent = String(b) + ", " + d[c];
|
|
848
848
|
},
|
|
849
|
-
get: () => this.propReferences[
|
|
850
|
-
}), Object.defineProperty(
|
|
849
|
+
get: () => this.propReferences[l]
|
|
850
|
+
}), Object.defineProperty(d, c, {
|
|
851
851
|
set: (b) => {
|
|
852
|
-
this.propReferences[f] = b, m.style.top = this._mapLinear(b, o, n, h.clientHeight, 0) + "px", _.textContent = r[
|
|
852
|
+
this.propReferences[f] = b, m.style.top = this._mapLinear(b, o, n, h.clientHeight, 0) + "px", _.textContent = r[p] + ", " + String(b);
|
|
853
853
|
},
|
|
854
854
|
get: () => this.propReferences[f]
|
|
855
855
|
});
|
|
@@ -857,8 +857,8 @@ class A {
|
|
|
857
857
|
color(e = {}, t) {
|
|
858
858
|
if (typeof e != "object")
|
|
859
859
|
throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
|
|
860
|
-
let i = typeof e.name == "string" && e.name || " ",
|
|
861
|
-
const
|
|
860
|
+
let i = typeof e.name == "string" && e.name || " ", a = !1, s = null, o = e.obj, n = e.prop, r;
|
|
861
|
+
const p = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
|
|
862
862
|
if (typeof e.value == "string" && (e.value.length != 7 || e.value[0] != "#" ? console.error(`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${e.value}".`) : r = e.value), r || (r = "#000000"), e.value !== void 0)
|
|
863
863
|
(n != null || o != null) && console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
|
|
864
864
|
else if (n != null && o != null) {
|
|
@@ -866,52 +866,52 @@ class A {
|
|
|
866
866
|
throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof n}.`);
|
|
867
867
|
if (typeof o != "object")
|
|
868
868
|
throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof o}.`);
|
|
869
|
-
i == " " && (i = n),
|
|
869
|
+
i == " " && (i = n), s = this.propReferences.push(o[n]) - 1, a = !0;
|
|
870
870
|
} else
|
|
871
871
|
(n != null && o == null || n == null && o == null) && console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');
|
|
872
872
|
this.imageContainer = null;
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
const
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
}),
|
|
873
|
+
const l = document.createElement("div");
|
|
874
|
+
l.className = "p-gui__color", l.textContent = i, p && l.setAttribute("title", p), this.wrapper.append(l);
|
|
875
|
+
const d = document.createElement("input");
|
|
876
|
+
d.className = "p-gui__color-picker", d.setAttribute("type", "color"), d.value = r, l.append(d), typeof t == "function" && d.addEventListener("input", () => {
|
|
877
|
+
a ? o[n] = d.value : typeof t == "function" && t(d.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
|
|
878
|
+
}), a && Object.defineProperty(o, n, {
|
|
879
879
|
set: (c) => {
|
|
880
|
-
this.propReferences[
|
|
880
|
+
this.propReferences[s] = c, d.value = c, typeof t == "function" && t(c);
|
|
881
881
|
},
|
|
882
|
-
get: () => this.propReferences[
|
|
882
|
+
get: () => this.propReferences[s]
|
|
883
883
|
});
|
|
884
884
|
}
|
|
885
885
|
folder(e = {}) {
|
|
886
|
-
let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.name || "",
|
|
886
|
+
let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.name || "", a = e.color || null, s = e.maxHeight || null;
|
|
887
887
|
this.imageContainer = null;
|
|
888
888
|
let o = "p-gui__folder";
|
|
889
889
|
this.folders.length == 0 && (o += " p-gui__folder--first"), t && (o += " p-gui__folder--closed");
|
|
890
|
-
let n =
|
|
891
|
-
n +=
|
|
890
|
+
let n = a ? `background-color: ${a};` : "";
|
|
891
|
+
n += s ? `max-height: ${s}px;` : "";
|
|
892
892
|
const r = document.createElement("div");
|
|
893
893
|
r.className = o, r.style = n, this.wrapper.append(r);
|
|
894
|
-
const
|
|
895
|
-
|
|
894
|
+
const p = document.createElement("div");
|
|
895
|
+
p.innerHTML = `<span class="p-gui__folder-arrow"></span>${i}`, p.className = "p-gui__folder-header", r.append(p), p.addEventListener("click", () => {
|
|
896
896
|
r.classList.toggle("p-gui__folder--closed");
|
|
897
897
|
});
|
|
898
|
-
let
|
|
898
|
+
let l = new A({ isFolder: !0, folderOptions: {
|
|
899
899
|
wrapper: r,
|
|
900
900
|
parent: this,
|
|
901
901
|
firstParent: this.firstParent
|
|
902
902
|
} });
|
|
903
|
-
return this.folders.push(
|
|
903
|
+
return this.folders.push(l), l;
|
|
904
904
|
}
|
|
905
905
|
_makeDraggable() {
|
|
906
906
|
var e = this;
|
|
907
|
-
this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup",
|
|
908
|
-
function t(
|
|
909
|
-
|
|
907
|
+
this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", a);
|
|
908
|
+
function t(s) {
|
|
909
|
+
s.preventDefault(), e.position.initX = e.position.x, e.position.initY = e.position.y, e.position.prevX = s.clientX, e.position.prevY = s.clientY, document.addEventListener("pointermove", i);
|
|
910
910
|
}
|
|
911
|
-
function i(
|
|
912
|
-
|
|
911
|
+
function i(s) {
|
|
912
|
+
s.preventDefault(), e.hasBeenDragged || (e.hasBeenDragged = !0, e.wrapper.setAttribute("data-dragged", "true")), e.position.x = e.position.initX + s.clientX - e.position.prevX, e.position.y = e.position.initY + s.clientY - e.position.prevY, e.wrapper.style.transform = "translate3d(" + e.position.x + "px," + e.position.y + "px,0)";
|
|
913
913
|
}
|
|
914
|
-
function
|
|
914
|
+
function a(s) {
|
|
915
915
|
document.removeEventListener("pointermove", i);
|
|
916
916
|
}
|
|
917
917
|
}
|
|
@@ -921,8 +921,8 @@ class A {
|
|
|
921
921
|
kill() {
|
|
922
922
|
this.wrapper.remove();
|
|
923
923
|
}
|
|
924
|
-
_mapLinear(e, t, i,
|
|
925
|
-
return
|
|
924
|
+
_mapLinear(e, t, i, a, s) {
|
|
925
|
+
return a + (e - t) * (s - a) / (i - t);
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
928
|
export {
|
package/dist/perfect-gui.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(v,w){typeof exports=="object"&&typeof module<"u"?module.exports=w():typeof define=="function"&&define.amd?define(w):(v=typeof globalThis<"u"?globalThis:v||self,v["Perfect GUI"]=w())})(this,function(){"use strict";class v{constructor(e={},
|
|
1
|
+
(function(v,w){typeof exports=="object"&&typeof module<"u"?module.exports=w():typeof define=="function"&&define.amd?define(w):(v=typeof globalThis<"u"?globalThis:v||self,v["Perfect GUI"]=w())})(this,function(){"use strict";class v{constructor(e,t={},i){if(this.parent=e,this.propReferences=[],typeof t!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof t}.`);let a=typeof t.name=="string"&&t.name||" ";this.isObject=!1;let s=null;this.obj=t.obj,this.prop=t.prop;let o=typeof t.value=="number"?t.value:null;if(this.min=t.min??0,this.max=t.max??1,this.step=t.step||(this.max-this.min)/100,o!==null)(this.prop!=null||this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(this.prop!=null&&this.obj!=null){if(typeof this.prop!="string")throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof this.prop}.`);if(typeof this.obj!="object")throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof this.obj}.`);a==" "&&(a=this.prop),s=this.propReferences.push(this.obj[this.prop])-1,this.isObject=!0}else(this.prop!=null&&this.obj==null||this.prop==null&&this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),o=(this.max-this.min)/2;const n=typeof t.tooltip=="string"?t.tooltip:t.tooltip===!0?a:null;this.imageContainer=null;const r=document.createElement("div");r.className="p-gui__slider",n&&r.setAttribute("title",n);const p=document.createElement("div");p.className="p-gui__slider-name",p.textContent=a,r.append(p),this.ctrlDiv=document.createElement("div"),this.ctrlDiv.className="p-gui__slider-ctrl",this.ctrlDiv.setAttribute("type","range"),this.ctrlDiv.setAttribute("min",this.min),this.ctrlDiv.setAttribute("max",this.max),r.append(this.ctrlDiv);const l=document.createElement("div");return l.className="p-gui__slider-bar",this.ctrlDiv.append(l),this.handle=document.createElement("div"),this.handle.className="p-gui__slider-handle",this.ctrlDiv.append(this.handle),this.filling=document.createElement("div"),this.filling.className="p-gui__slider-filling",l.append(this.filling),this.valueInput=document.createElement("input"),this.valueInput.className="p-gui__slider-value",this.valueInput.value=this.isObject?this.obj[this.prop]:o,r.append(this.valueInput),setTimeout(()=>{const d=this.handle.offsetWidth;this.handle.position=this._mapLinear(this.valueInput.value,this.min,this.max,d/2,88-d/2),this.handle.style.transform=`translate(-50%, -50%) translateX(${this.handle.position}px)`,this.filling.style.width=`${this.handle.position}px`},0),this.valueInput.addEventListener("change",()=>{this._updateHandlePositionFromValue(),this._triggerCallbacks()}),this.ctrlDiv.addEventListener("pointerdown",d=>{this.ctrlDiv.pointerDown=!0,this.ctrlDiv.prevPosition=d.clientX,this._updateHandlePositionFromPointer(d,!0)}),window.addEventListener("pointerup",d=>{this.ctrlDiv.pointerDown=!1}),window.addEventListener("pointermove",d=>{this.ctrlDiv.pointerDown&&(this.ctrlDiv.pointerDelta=d.clientX-this.ctrlDiv.prevPosition,this._updateHandlePositionFromPointer(d))}),this.isObject&&Object.defineProperty(this.obj,this.prop,{set:d=>{this.propReferences[s]=d,this.valueInput.value=d,this._updateHandlePositionFromValue(),typeof i=="function"&&i(parseFloat(this.valueInput.value))},get:()=>this.propReferences[s]}),r}_updateHandlePositionFromPointer(e,t=!1){const i=this.ctrlDiv.offsetWidth,a=this.handle.offsetWidth,s=e.clientX-this.ctrlDiv.prevPosition;let o;const n=parseFloat(this.valueInput.value);t?o=e.offsetX:o=this.handle.position+s,o=Math.max(a/2,Math.min(o,i-a/2));let r=this.min+(this.max-this.min)*(o-a/2)/(i-a);r>n?r=this._quantizeFloor(r,this.step):r=this._quantizeCeil(r,this.step),r=parseFloat(r.toFixed(9));const p=parseFloat((n+this.step).toFixed(9)),l=parseFloat((n-this.step).toFixed(9));if(r>=p||r<=l){const d=this._countDecimals(this.step);r=r.toFixed(d),this.valueInput.value=r,this.ctrlDiv.prevPosition=e.clientX,this.handle.style.transform=`translate(-50%, -50%) translateX(${o}px)`,this.handle.position=o,this.filling.style.width=this.handle.position+"px",this._triggerCallbacks()}}_countDecimals(e){const t=e.toString(),i=t.indexOf(".");return i===-1?0:t.length-i-1}_updateHandlePositionFromValue(){const e=this.ctrlDiv.offsetWidth,t=this.handle.offsetWidth;let i=this._mapLinear(this.valueInput.value,this.min,this.max,t/2,e-t/2);i=Math.max(t/2,Math.min(i,e-t/2)),this.handle.style.transform=`translate(-50%, -50%) translateX(${i}px)`,this.handle.position=i,this.filling.style.width=this.handle.position+"px"}_triggerCallbacks(){this.isObject?this.obj[this.prop]=parseFloat(this.valueInput.value):typeof callback=="function"&&callback(parseFloat(this.valueInput.value)),this.parent.onUpdate?this.parent.onUpdate():this.parent.isFolder&&this.parent.firstParent.onUpdate&&this.parent.firstParent.onUpdate()}_mapLinear(e,t,i,a,s){return a+(e-t)*(s-a)/(i-t)}_quantize(e,t){return t*Math.round(e/t)}_quantizeCeil(e,t){return t*Math.ceil(e/t)}_quantizeFloor(e,t){return t*Math.floor(e/t)}}const w=`
|
|
2
2
|
.p-gui__button {
|
|
3
3
|
background: var(--color-accent);
|
|
4
4
|
text-align: center;
|
|
@@ -534,4 +534,4 @@
|
|
|
534
534
|
${this.screenCorner.y=="top"?"":"top: auto; bottom: 0;"}
|
|
535
535
|
${this.backgroundColor?"background: "+this.backgroundColor+";":""}
|
|
536
536
|
opacity: ${this.opacity};
|
|
537
|
-
}`)}_folderConstructor(e){this.wrapper=e.wrapper,this.isFolder=!0,this.parent=e.parent,this.firstParent=e.firstParent}_parseScreenCorner(e){let t={x:"right",y:"top"};return e==null||(typeof e!="string"&&console.error("[perfect-gui] Position must be a string."),e.includes("left")&&(t.x="left"),e.includes("bottom")&&(t.y="bottom")),t}_getScrollbarWidth(e){return e===document.body?window.innerWidth-document.documentElement.clientWidth:e.offsetWidth-e.clientWidth}_handleResize(){if(this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),this.initMaxHeight&&(this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.wrapper.style.maxHeight=this.maxHeight+"px",this.hasBeenDragged)return;let e=this._getScrollbarWidth(this.container);if(this.xOffset=this.screenCorner.x=="left"?0:this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);for(let i=0;i<t.length&&!(parseInt(t[i].id.replace("p-gui-",""))>this.instanceId);i++)this.screenCorner.y==t[i].dataset.cornerY&&(this.screenCorner.x=="left"&&t[i].dataset.cornerX=="left"?this.xOffset+=t[i].offsetWidth:this.screenCorner.x=="right"&&t[i].dataset.cornerX=="right"&&(this.xOffset-=t[i].offsetWidth))}this.position={prevX:this.xOffset,prevY:this.yOffset,x:this.xOffset,y:this.yOffset},this.wrapper.style.transform=`translate3d(${this.position.x}px, ${this.position.y}px, 0)`}_addStyles(e){this.stylesheet.innerHTML+=e}_addWrapper(){this.wrapper=document.createElement("div"),this.wrapper.id="p-gui-"+this.instanceId,this.wrapper.className="p-gui",this.container.append(this.wrapper),this.header=document.createElement("div"),this.header.className="p-gui__header",this.header.textContent=this.name,this.header.style=`${this.backgroundColor?"border-color: "+this.backgroundColor+";":""}`,this.wrapper.append(this.header);const e=document.createElement("div");e.className="p-gui__header-close",e.addEventListener("click",this.toggleClose.bind(this)),this.header.append(e)}button(e,t){let i="";typeof e!="string"?typeof e=="object"&&(e!=null&&e.hasOwnProperty("name"))?i=e.name==""?" ":e.name:i=" ":i=e==""?" ":e;const l=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;this.imageContainer=null;const a=document.createElement("div");a.className="p-gui__button",a.textContent=i,l&&a.setAttribute("title",l),a.addEventListener("click",()=>{this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t()}),this.wrapper.append(a),typeof e.color=="string"&&(a.style.setProperty("--color-accent",e.color),a.style.setProperty("--color-accent-hover",e.hoverColor||e.color))}image(e={},t){if(typeof e!="object")throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);let i;if(typeof e.path=="string")i=e.path;else throw typeof e.path==null?Error("[GUI] image() path must be provided."):Error("[GUI] image() path must be a string.");let l=i.replace(/^.*[\\\/]/,""),a;e.name==null?a=l:a=typeof e.name=="string"&&e.name||" ";const o=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?a:null,n=e.selected===!0,r=e.selectionBorder!==!1;let d="";e.width&&(typeof e.width=="number"&&(e.width+="px"),d+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),d+=`height: ${e.height}; `),this.imageContainer||(this.imageContainer=document.createElement("div"),this.imageContainer.className="p-gui__image-container",this.wrapper.append(this.imageContainer));const s=document.createElement("div");s.className="p-gui__image",s.style="background-image: url("+i+"); "+d,o&&s.setAttribute("title",o),this.imageContainer.append(s),n&&r&&s.classList.add("p-gui__image--selected");const p=document.createElement("div");return p.className="p-gui__image-text",p.textContent=a,s.append(p),s.addEventListener("click",()=>{let c=s.parentElement.querySelectorAll(".p-gui__image--selected");for(let f=0;f<c.length;f++)c[f].classList.remove("p-gui__image--selected");r&&s.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:i,text:a}),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),s}slider(e={},t){const i=new v(e,t);this.wrapper.append(i)}toggle(e={},t){if(typeof e!="object")throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",l=!1,a=null,o=e.obj,n=e.prop,r=typeof e.value=="boolean"?e.value:null;if(r!==null)(n!=null||o!=null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),a=this.propReferences.push(o[n])-1,l=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');const d=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;this.imageContainer=null;const s=document.createElement("div");s.textContent=i,s.className="p-gui__switch",d&&s.setAttribute("title",d),this.wrapper.append(s),s.addEventListener("click",f=>{const u=f.target.childNodes[1];let g=!0;u.classList.contains("p-gui__switch-checkbox--active")&&(g=!1),u.classList.toggle("p-gui__switch-checkbox--active"),l?o[n]=g:typeof t=="function"&&t(g),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let p=(()=>l?o[n]?" p-gui__switch-checkbox--active":"":r?" p-gui__switch-checkbox--active":"")();const c=document.createElement("div");c.className="p-gui__switch-checkbox"+p,s.append(c),l&&Object.defineProperty(o,n,{set:f=>{this.propReferences[a]=f,f?c.classList.add("p-gui__switch-checkbox--active"):c.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(f)},get:()=>this.propReferences[a]})}list(e={},t){if(typeof e!="object")throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"?e.name:" ",l=!1,a=null,o=e.obj,n=e.prop,r=Array.isArray(e.values)?e.values:null,d,s=typeof r[0]!="string";const p=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;if(t=typeof t=="function"?t:null,e.value!==void 0||e.value===void 0&&o===void 0&&n===void 0)(n!=null||o!=null)&&console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'),d=(()=>{if(!r)return null;if(typeof e.value=="string")return r.indexOf(e.value);if(typeof e.value=="number")return e.value})();else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof o}.`);d=(()=>{if(!r)return null;if(typeof o[n]=="string")return s?r.find(u=>u.value===o[n]).value:r.indexOf(o[n]);if(typeof o[n]=="number")return s?r.find(u=>u.value===o[n]).value:o[n]})(),a=this.propReferences.push(o[n])-1,l=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');this.imageContainer=null;let c=document.createElement("div");c.className="p-gui__list",c.textContent=i,p&&c.setAttribute("title",p),this.wrapper.append(c);let f=document.createElement("select");c.append(f),f.className="p-gui__list-dropdown",f.addEventListener("change",u=>{l?o[n]=u.target.value:t&&t(u.target.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),r&&r.forEach((u,g)=>{const _=s?u.name:u,h=s?u.value:u;let m=document.createElement("option");m.setAttribute("value",h),m.textContent=_,f.append(m),(!s&&d==g||s&&d==h)&&m.setAttribute("selected","")}),l&&Object.defineProperty(o,n,{set:u=>{let g,_,h;s?(h=r.find(y=>y.value==u),_=(h==null?void 0:h.value)||r[0].value,g=r.indexOf(h)):(typeof u=="string"&&(g=r.indexOf(u),_=u),typeof u=="number"&&(g=u,_=r[u])),this.propReferences[a]=s?_:u;const m=f.querySelector("[selected]");m&&m.removeAttribute("selected"),f.querySelectorAll("option")[g].setAttribute("selected",""),typeof t=="function"&&t(s?h:_,g)},get:()=>this.propReferences[a]})}vector2(e={},t){if(typeof e!="object")throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ";const l=e.x.min??0,a=e.x.max??1,o=e.y.min??0,n=e.y.max??1,r=e.x.obj,d=e.x.prop,s=this.propReferences.push(r[d])-1,p=e.y.obj,c=e.y.prop,f=this.propReferences.push(p[c])-1,u=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;t=typeof t=="function"?t:null,this.imageContainer=null;const g=document.createElement("div");g.className="p-gui__vector2",g.textContent=i,u&&g.setAttribute("title",u),this.wrapper.append(g);const _=document.createElement("div");_.className="p-gui__vector-value",_.textContent=r[d]+", "+p[c],g.append(_);const h=document.createElement("div");h.className="p-gui__vector2-area",g.append(h),h.addEventListener("click",b=>{r[d]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,l,a).toFixed(2)),p[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,n,o).toFixed(2)),t&&t(r[d],r[c]),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let m=!1;h.addEventListener("pointerdown",b=>{m=!0}),h.addEventListener("pointerup",()=>{m=!1}),h.addEventListener("pointermove",b=>{m&&(r[d]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,l,a).toFixed(2)),p[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,n,o).toFixed(2)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t(r[d],r[c]))});const y=document.createElement("div");y.className="p-gui__vector2-line p-gui__vector2-line-x",h.append(y);const k=document.createElement("div");k.className="p-gui__vector2-line p-gui__vector2-line-y",h.append(k);const x=document.createElement("div");x.className="p-gui__vector2-dot",h.append(x),x.style.left=this._mapLinear(r[d],l,a,0,h.clientWidth)+"px",x.style.top=this._mapLinear(p[c],o,n,h.clientHeight,0)+"px",Object.defineProperty(r,d,{set:b=>{this.propReferences[s]=b,x.style.left=this._mapLinear(b,l,a,0,h.clientWidth)+"px",_.textContent=String(b)+", "+p[c]},get:()=>this.propReferences[s]}),Object.defineProperty(p,c,{set:b=>{this.propReferences[f]=b,x.style.top=this._mapLinear(b,o,n,h.clientHeight,0)+"px",_.textContent=r[d]+", "+String(b)},get:()=>this.propReferences[f]})}color(e={},t){if(typeof e!="object")throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",l=!1,a=null,o=e.obj,n=e.prop,r;const d=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;if(typeof e.value=="string"&&(e.value.length!=7||e.value[0]!="#"?console.error(`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${e.value}".`):r=e.value),r||(r="#000000"),e.value!==void 0)(n!=null||o!=null)&&console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),a=this.propReferences.push(o[n])-1,l=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const s=document.createElement("div");s.className="p-gui__color",s.textContent=i,d&&s.setAttribute("title",d),this.wrapper.append(s);const p=document.createElement("input");p.className="p-gui__color-picker",p.setAttribute("type","color"),p.value=r,s.append(p),typeof t=="function"&&p.addEventListener("input",()=>{l?o[n]=p.value:typeof t=="function"&&t(p.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),l&&Object.defineProperty(o,n,{set:c=>{this.propReferences[a]=c,p.value=c,typeof t=="function"&&t(c)},get:()=>this.propReferences[a]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,i=e.name||"",l=e.color||null,a=e.maxHeight||null;this.imageContainer=null;let o="p-gui__folder";this.folders.length==0&&(o+=" p-gui__folder--first"),t&&(o+=" p-gui__folder--closed");let n=l?`background-color: ${l};`:"";n+=a?`max-height: ${a}px;`:"";const r=document.createElement("div");r.className=o,r.style=n,this.wrapper.append(r);const d=document.createElement("div");d.innerHTML=`<span class="p-gui__folder-arrow"></span>${i}`,d.className="p-gui__folder-header",r.append(d),d.addEventListener("click",()=>{r.classList.toggle("p-gui__folder--closed")});let s=new A({isFolder:!0,folderOptions:{wrapper:r,parent:this,firstParent:this.firstParent}});return this.folders.push(s),s}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",l);function t(a){a.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=a.clientX,e.position.prevY=a.clientY,document.addEventListener("pointermove",i)}function i(a){a.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+a.clientX-e.position.prevX,e.position.y=e.position.initY+a.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function l(a){document.removeEventListener("pointermove",i)}}toggleClose(){this.closed=!this.closed,this.closed?(this.previousInnerScroll=this.wrapper.scrollTop,this.wrapper.scrollTo(0,0)):this.wrapper.scrollTo(0,this.previousInnerScroll),this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,i,l,a){return l+(e-t)*(a-l)/(i-t)}}return A});
|
|
537
|
+
}`)}_folderConstructor(e){this.wrapper=e.wrapper,this.isFolder=!0,this.parent=e.parent,this.firstParent=e.firstParent}_parseScreenCorner(e){let t={x:"right",y:"top"};return e==null||(typeof e!="string"&&console.error("[perfect-gui] Position must be a string."),e.includes("left")&&(t.x="left"),e.includes("bottom")&&(t.y="bottom")),t}_getScrollbarWidth(e){return e===document.body?window.innerWidth-document.documentElement.clientWidth:e.offsetWidth-e.clientWidth}_handleResize(){if(this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),this.initMaxHeight&&(this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.wrapper.style.maxHeight=this.maxHeight+"px",this.hasBeenDragged)return;let e=this._getScrollbarWidth(this.container);if(this.xOffset=this.screenCorner.x=="left"?0:this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);for(let i=0;i<t.length&&!(parseInt(t[i].id.replace("p-gui-",""))>this.instanceId);i++)this.screenCorner.y==t[i].dataset.cornerY&&(this.screenCorner.x=="left"&&t[i].dataset.cornerX=="left"?this.xOffset+=t[i].offsetWidth:this.screenCorner.x=="right"&&t[i].dataset.cornerX=="right"&&(this.xOffset-=t[i].offsetWidth))}this.position={prevX:this.xOffset,prevY:this.yOffset,x:this.xOffset,y:this.yOffset},this.wrapper.style.transform=`translate3d(${this.position.x}px, ${this.position.y}px, 0)`}_addStyles(e){this.stylesheet.innerHTML+=e}_addWrapper(){this.wrapper=document.createElement("div"),this.wrapper.id="p-gui-"+this.instanceId,this.wrapper.className="p-gui",this.container.append(this.wrapper),this.header=document.createElement("div"),this.header.className="p-gui__header",this.header.textContent=this.name,this.header.style=`${this.backgroundColor?"border-color: "+this.backgroundColor+";":""}`,this.wrapper.append(this.header);const e=document.createElement("div");e.className="p-gui__header-close",e.addEventListener("click",this.toggleClose.bind(this)),this.header.append(e)}button(e,t){let i="";typeof e!="string"?typeof e=="object"&&(e!=null&&e.hasOwnProperty("name"))?i=e.name==""?" ":e.name:i=" ":i=e==""?" ":e;const a=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;this.imageContainer=null;const s=document.createElement("div");s.className="p-gui__button",s.textContent=i,a&&s.setAttribute("title",a),s.addEventListener("click",()=>{this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t()}),this.wrapper.append(s),typeof e.color=="string"&&(s.style.setProperty("--color-accent",e.color),s.style.setProperty("--color-accent-hover",e.hoverColor||e.color))}image(e={},t){if(typeof e!="object")throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);let i;if(typeof e.path=="string")i=e.path;else throw typeof e.path==null?Error("[GUI] image() path must be provided."):Error("[GUI] image() path must be a string.");let a=i.replace(/^.*[\\\/]/,""),s;e.name==null?s=a:s=typeof e.name=="string"&&e.name||" ";const o=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?s:null,n=e.selected===!0,r=e.selectionBorder!==!1;let p="";e.width&&(typeof e.width=="number"&&(e.width+="px"),p+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),p+=`height: ${e.height}; `),this.imageContainer||(this.imageContainer=document.createElement("div"),this.imageContainer.className="p-gui__image-container",this.wrapper.append(this.imageContainer));const l=document.createElement("div");l.className="p-gui__image",l.style="background-image: url("+i+"); "+p,o&&l.setAttribute("title",o),this.imageContainer.append(l),n&&r&&l.classList.add("p-gui__image--selected");const d=document.createElement("div");return d.className="p-gui__image-text",d.textContent=s,l.append(d),l.addEventListener("click",()=>{let c=l.parentElement.querySelectorAll(".p-gui__image--selected");for(let f=0;f<c.length;f++)c[f].classList.remove("p-gui__image--selected");r&&l.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:i,text:s}),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),l}slider(e={},t){const i=new v(this,e,t);this.wrapper.append(i)}toggle(e={},t){if(typeof e!="object")throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",a=!1,s=null,o=e.obj,n=e.prop,r=typeof e.value=="boolean"?e.value:null;if(r!==null)(n!=null||o!=null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),s=this.propReferences.push(o[n])-1,a=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');const p=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;this.imageContainer=null;const l=document.createElement("div");l.textContent=i,l.className="p-gui__switch",p&&l.setAttribute("title",p),this.wrapper.append(l),l.addEventListener("click",f=>{const u=f.target.childNodes[1];let g=!0;u.classList.contains("p-gui__switch-checkbox--active")&&(g=!1),u.classList.toggle("p-gui__switch-checkbox--active"),a?o[n]=g:typeof t=="function"&&t(g),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let d=(()=>a?o[n]?" p-gui__switch-checkbox--active":"":r?" p-gui__switch-checkbox--active":"")();const c=document.createElement("div");c.className="p-gui__switch-checkbox"+d,l.append(c),a&&Object.defineProperty(o,n,{set:f=>{this.propReferences[s]=f,f?c.classList.add("p-gui__switch-checkbox--active"):c.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(f)},get:()=>this.propReferences[s]})}list(e={},t){if(typeof e!="object")throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"?e.name:" ",a=!1,s=null,o=e.obj,n=e.prop,r=Array.isArray(e.values)?e.values:null,p,l=typeof r[0]!="string";const d=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;if(t=typeof t=="function"?t:null,e.value!==void 0||e.value===void 0&&o===void 0&&n===void 0)(n!=null||o!=null)&&console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'),p=(()=>{if(!r)return null;if(typeof e.value=="string")return r.indexOf(e.value);if(typeof e.value=="number")return e.value})();else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof o}.`);p=(()=>{if(!r)return null;if(typeof o[n]=="string")return l?r.find(u=>u.value===o[n]).value:r.indexOf(o[n]);if(typeof o[n]=="number")return l?r.find(u=>u.value===o[n]).value:o[n]})(),s=this.propReferences.push(o[n])-1,a=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');this.imageContainer=null;let c=document.createElement("div");c.className="p-gui__list",c.textContent=i,d&&c.setAttribute("title",d),this.wrapper.append(c);let f=document.createElement("select");c.append(f),f.className="p-gui__list-dropdown",f.addEventListener("change",u=>{a?o[n]=u.target.value:t&&t(u.target.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),r&&r.forEach((u,g)=>{const _=l?u.name:u,h=l?u.value:u;let m=document.createElement("option");m.setAttribute("value",h),m.textContent=_,f.append(m),(!l&&p==g||l&&p==h)&&m.setAttribute("selected","")}),a&&Object.defineProperty(o,n,{set:u=>{let g,_,h;l?(h=r.find(y=>y.value==u),_=(h==null?void 0:h.value)||r[0].value,g=r.indexOf(h)):(typeof u=="string"&&(g=r.indexOf(u),_=u),typeof u=="number"&&(g=u,_=r[u])),this.propReferences[s]=l?_:u;const m=f.querySelector("[selected]");m&&m.removeAttribute("selected"),f.querySelectorAll("option")[g].setAttribute("selected",""),typeof t=="function"&&t(l?h:_,g)},get:()=>this.propReferences[s]})}vector2(e={},t){if(typeof e!="object")throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ";const a=e.x.min??0,s=e.x.max??1,o=e.y.min??0,n=e.y.max??1,r=e.x.obj,p=e.x.prop,l=this.propReferences.push(r[p])-1,d=e.y.obj,c=e.y.prop,f=this.propReferences.push(d[c])-1,u=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;t=typeof t=="function"?t:null,this.imageContainer=null;const g=document.createElement("div");g.className="p-gui__vector2",g.textContent=i,u&&g.setAttribute("title",u),this.wrapper.append(g);const _=document.createElement("div");_.className="p-gui__vector-value",_.textContent=r[p]+", "+d[c],g.append(_);const h=document.createElement("div");h.className="p-gui__vector2-area",g.append(h),h.addEventListener("click",b=>{r[p]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,s).toFixed(2)),d[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,n,o).toFixed(2)),t&&t(r[p],r[c]),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let m=!1;h.addEventListener("pointerdown",b=>{m=!0}),h.addEventListener("pointerup",()=>{m=!1}),h.addEventListener("pointermove",b=>{m&&(r[p]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,s).toFixed(2)),d[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,n,o).toFixed(2)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t(r[p],r[c]))});const y=document.createElement("div");y.className="p-gui__vector2-line p-gui__vector2-line-x",h.append(y);const k=document.createElement("div");k.className="p-gui__vector2-line p-gui__vector2-line-y",h.append(k);const x=document.createElement("div");x.className="p-gui__vector2-dot",h.append(x),x.style.left=this._mapLinear(r[p],a,s,0,h.clientWidth)+"px",x.style.top=this._mapLinear(d[c],o,n,h.clientHeight,0)+"px",Object.defineProperty(r,p,{set:b=>{this.propReferences[l]=b,x.style.left=this._mapLinear(b,a,s,0,h.clientWidth)+"px",_.textContent=String(b)+", "+d[c]},get:()=>this.propReferences[l]}),Object.defineProperty(d,c,{set:b=>{this.propReferences[f]=b,x.style.top=this._mapLinear(b,o,n,h.clientHeight,0)+"px",_.textContent=r[p]+", "+String(b)},get:()=>this.propReferences[f]})}color(e={},t){if(typeof e!="object")throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",a=!1,s=null,o=e.obj,n=e.prop,r;const p=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;if(typeof e.value=="string"&&(e.value.length!=7||e.value[0]!="#"?console.error(`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${e.value}".`):r=e.value),r||(r="#000000"),e.value!==void 0)(n!=null||o!=null)&&console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),s=this.propReferences.push(o[n])-1,a=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const l=document.createElement("div");l.className="p-gui__color",l.textContent=i,p&&l.setAttribute("title",p),this.wrapper.append(l);const d=document.createElement("input");d.className="p-gui__color-picker",d.setAttribute("type","color"),d.value=r,l.append(d),typeof t=="function"&&d.addEventListener("input",()=>{a?o[n]=d.value:typeof t=="function"&&t(d.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),a&&Object.defineProperty(o,n,{set:c=>{this.propReferences[s]=c,d.value=c,typeof t=="function"&&t(c)},get:()=>this.propReferences[s]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,i=e.name||"",a=e.color||null,s=e.maxHeight||null;this.imageContainer=null;let o="p-gui__folder";this.folders.length==0&&(o+=" p-gui__folder--first"),t&&(o+=" p-gui__folder--closed");let n=a?`background-color: ${a};`:"";n+=s?`max-height: ${s}px;`:"";const r=document.createElement("div");r.className=o,r.style=n,this.wrapper.append(r);const p=document.createElement("div");p.innerHTML=`<span class="p-gui__folder-arrow"></span>${i}`,p.className="p-gui__folder-header",r.append(p),p.addEventListener("click",()=>{r.classList.toggle("p-gui__folder--closed")});let l=new A({isFolder:!0,folderOptions:{wrapper:r,parent:this,firstParent:this.firstParent}});return this.folders.push(l),l}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",a);function t(s){s.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=s.clientX,e.position.prevY=s.clientY,document.addEventListener("pointermove",i)}function i(s){s.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+s.clientX-e.position.prevX,e.position.y=e.position.initY+s.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function a(s){document.removeEventListener("pointermove",i)}}toggleClose(){this.closed=!this.closed,this.closed?(this.previousInnerScroll=this.wrapper.scrollTop,this.wrapper.scrollTo(0,0)):this.wrapper.scrollTo(0,this.previousInnerScroll),this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,i,a,s){return a+(e-t)*(s-a)/(i-t)}}return A});
|
package/package.json
CHANGED
package/src/components/Slider.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export default class Slider {
|
|
2
|
-
constructor(params = {}, callback) {
|
|
2
|
+
constructor(parent, params = {}, callback) {
|
|
3
|
+
this.parent = parent;
|
|
3
4
|
this.propReferences = [];
|
|
4
5
|
|
|
5
6
|
if (typeof params != 'object') {
|
|
@@ -212,7 +213,6 @@ export default class Slider {
|
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
_triggerCallbacks() {
|
|
215
|
-
|
|
216
216
|
if ( this.isObject ) {
|
|
217
217
|
this.obj[this.prop] = parseFloat(this.valueInput.value);
|
|
218
218
|
}
|
|
@@ -222,10 +222,10 @@ export default class Slider {
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
if (this.onUpdate) {
|
|
226
|
-
this.onUpdate();
|
|
227
|
-
} else if (this.isFolder && this.firstParent.onUpdate) {
|
|
228
|
-
this.firstParent.onUpdate();
|
|
225
|
+
if (this.parent.onUpdate) {
|
|
226
|
+
this.parent.onUpdate();
|
|
227
|
+
} else if (this.parent.isFolder && this.parent.firstParent.onUpdate) {
|
|
228
|
+
this.parent.firstParent.onUpdate();
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|