perfect-gui 4.3.5 → 4.4.1
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 +126 -108
- package/dist/perfect-gui.umd.js +3 -3
- package/package.json +1 -1
- package/src/index.js +88 -13
package/dist/perfect-gui.mjs
CHANGED
|
@@ -413,13 +413,13 @@ function w(y) {
|
|
|
413
413
|
`
|
|
414
414
|
);
|
|
415
415
|
}
|
|
416
|
-
class
|
|
416
|
+
class f {
|
|
417
417
|
constructor(e = {}) {
|
|
418
418
|
if (e.container ? (this.container = typeof e.container == "string" ? document.querySelector(e.container) : e.container, this.position_type = "absolute") : (this.container = document.body, this.position_type = "fixed"), this.propReferences = [], this.folders = [], e.isFolder) {
|
|
419
419
|
this._folderConstructor(e.folderOptions);
|
|
420
420
|
return;
|
|
421
421
|
}
|
|
422
|
-
this.name = e != null && typeof e.name == "string" ? e.name : "", this.backgroundColor = e.color || null, this.container == document.body ? this.maxHeight = window.innerHeight : this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight), e.maxHeight && (this.initMaxHeight = e.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), this.screenCorner = this._parseScreenCorner(e.position), this instanceof
|
|
422
|
+
this.name = e != null && typeof e.name == "string" ? e.name : "", this.backgroundColor = e.color || null, this.container == document.body ? this.maxHeight = window.innerHeight : this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight), e.maxHeight && (this.initMaxHeight = e.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), this.screenCorner = this._parseScreenCorner(e.position), this instanceof f && (typeof f[f.instanceCounter] != "number" ? f[f.instanceCounter] = 0 : f[f.instanceCounter]++), this.instanceId = f[f.instanceCounter], this.wrapperWidth = e.width || 290, this.stylesheet = document.createElement("style"), this.stylesheet.setAttribute("type", "text/css"), this.stylesheet.setAttribute("id", "lm-gui-stylesheet"), document.head.append(this.stylesheet), this.instanceId == 0 && this._addStyles(`${w(this.position_type)}`), this._styleInstance(), this._addWrapper(), this.wrapper.setAttribute("data-corner-x", this.screenCorner.x), this.wrapper.setAttribute("data-corner-y", this.screenCorner.y), e.autoRepositioning != !1 && window.addEventListener("resize", this._handleResize.bind(this)), this._handleResize(), this.hasBeenDragged = !1, e.draggable == !0 && this._makeDraggable(), this.closed = !1, e.closed && this.toggleClose();
|
|
423
423
|
}
|
|
424
424
|
_styleInstance() {
|
|
425
425
|
let e = this._getScrollbarWidth(this.container);
|
|
@@ -508,94 +508,112 @@ class u {
|
|
|
508
508
|
i = e.path;
|
|
509
509
|
else
|
|
510
510
|
throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
|
|
511
|
-
let r = i.replace(/^.*[\\\/]/, ""),
|
|
512
|
-
e.name == null ?
|
|
513
|
-
const
|
|
514
|
-
let
|
|
515
|
-
e.width && (typeof e.width == "number" && (e.width += "px"),
|
|
511
|
+
let r = i.replace(/^.*[\\\/]/, ""), s;
|
|
512
|
+
e.name == null ? s = r : s = typeof e.name == "string" && e.name || " ";
|
|
513
|
+
const o = e.selected === !0, n = e.selectionBorder !== !1;
|
|
514
|
+
let a = "";
|
|
515
|
+
e.width && (typeof e.width == "number" && (e.width += "px"), a += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), a += `height: ${e.height}; `), this.imageContainer || (this.imageContainer = this._createElement({
|
|
516
516
|
class: "p-gui__image-container"
|
|
517
517
|
}));
|
|
518
518
|
var l = this._createElement({
|
|
519
519
|
class: "p-gui__image",
|
|
520
|
-
inline: "background-image: url(" + i + "); " +
|
|
520
|
+
inline: "background-image: url(" + i + "); " + a,
|
|
521
521
|
parent: this.imageContainer
|
|
522
522
|
});
|
|
523
|
-
|
|
523
|
+
o && n && l.classList.add("p-gui__image--selected"), this._createElement({
|
|
524
524
|
parent: l,
|
|
525
525
|
class: "p-gui__image-text",
|
|
526
|
-
textContent:
|
|
526
|
+
textContent: s
|
|
527
527
|
}), typeof t == "function" && (l.onclick = () => {
|
|
528
|
-
let
|
|
529
|
-
for (let
|
|
530
|
-
|
|
531
|
-
|
|
528
|
+
let u = this.imageContainer.querySelectorAll(".p-gui__image--selected");
|
|
529
|
+
for (let p = 0; p < u.length; p++)
|
|
530
|
+
u[p].classList.remove("p-gui__image--selected");
|
|
531
|
+
n && l.classList.add("p-gui__image--selected"), t({ path: i, text: s });
|
|
532
532
|
});
|
|
533
533
|
}
|
|
534
534
|
slider(e = {}, t) {
|
|
535
535
|
if (typeof e != "object")
|
|
536
536
|
throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
|
|
537
|
-
let i = typeof e.name == "string" && e.name || " ", r = !1,
|
|
538
|
-
if (
|
|
539
|
-
(
|
|
540
|
-
else if (
|
|
541
|
-
if (typeof
|
|
542
|
-
throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof
|
|
543
|
-
if (typeof
|
|
544
|
-
throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof
|
|
545
|
-
i == " " && (i =
|
|
537
|
+
let i = typeof e.name == "string" && e.name || " ", r = !1, s = null, o = e.obj || e.object, n = e.prop || e.property, a = typeof e.value == "number" ? e.value : null, l = e.min ?? 0, u = e.max ?? 1, p = e.step || (u - l) / 100;
|
|
538
|
+
if (a !== null)
|
|
539
|
+
(n != null || o != null) && console.warn('[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.');
|
|
540
|
+
else if (n != null && o != null) {
|
|
541
|
+
if (typeof n != "string")
|
|
542
|
+
throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof n}.`);
|
|
543
|
+
if (typeof o != "object")
|
|
544
|
+
throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof o}.`);
|
|
545
|
+
i == " " && (i = n), s = this.propReferences.push(o[n]) - 1, r = !0;
|
|
546
546
|
} else
|
|
547
|
-
(
|
|
547
|
+
(n != null && o == null || n == null && o == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), a = (u - l) / 2;
|
|
548
548
|
this.imageContainer = null;
|
|
549
|
-
var
|
|
549
|
+
var c = this._createElement({
|
|
550
550
|
class: "p-gui__slider",
|
|
551
551
|
textContent: i
|
|
552
|
-
}),
|
|
553
|
-
parent:
|
|
552
|
+
}), g = this._createElement({
|
|
553
|
+
parent: c,
|
|
554
554
|
el: "input",
|
|
555
555
|
class: "p-gui__slider-ctrl",
|
|
556
556
|
customAttributes: {
|
|
557
557
|
type: "range",
|
|
558
558
|
min: l,
|
|
559
|
-
max:
|
|
560
|
-
step:
|
|
561
|
-
value: r ?
|
|
559
|
+
max: u,
|
|
560
|
+
step: p,
|
|
561
|
+
value: r ? o[n] : a
|
|
562
562
|
}
|
|
563
|
-
}),
|
|
564
|
-
parent:
|
|
563
|
+
}), b = this._createElement({
|
|
564
|
+
parent: c,
|
|
565
565
|
class: "p-gui__slider-value",
|
|
566
|
-
textContent: String(r ?
|
|
566
|
+
textContent: String(r ? o[n] : a)
|
|
567
567
|
});
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}), r && Object.defineProperty(
|
|
571
|
-
set: (
|
|
572
|
-
this.propReferences[
|
|
568
|
+
g.addEventListener("input", () => {
|
|
569
|
+
b.textContent = g.value, r ? o[n] = g.value : typeof t == "function" && t(parseFloat(g.value));
|
|
570
|
+
}), r && Object.defineProperty(o, n, {
|
|
571
|
+
set: (_) => {
|
|
572
|
+
this.propReferences[s] = _, g.value = _, b.textContent = String(_), typeof t == "function" && t(parseFloat(g.value));
|
|
573
573
|
},
|
|
574
|
-
get: () => this.propReferences[
|
|
574
|
+
get: () => this.propReferences[s]
|
|
575
575
|
});
|
|
576
576
|
}
|
|
577
577
|
toggle(e = {}, t) {
|
|
578
578
|
if (typeof e != "object")
|
|
579
579
|
throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
|
|
580
|
-
let i = typeof e.name == "string" && e.name || " ", r = e.value
|
|
580
|
+
let i = typeof e.name == "string" && e.name || " ", r = !1, s = null, o = e.obj || e.object, n = e.prop || e.property, a = typeof e.value == "boolean" ? e.value : null;
|
|
581
|
+
if (a !== null)
|
|
582
|
+
(n != null || o != null) && console.warn('[GUI] toggle() "obj" and "property" parameters are ignored when a "value" parameter is used.');
|
|
583
|
+
else if (n != null && o != null) {
|
|
584
|
+
if (typeof n != "string")
|
|
585
|
+
throw Error(`[GUI] toggle() "prop" (or "property") parameter must be an string. Received: ${typeof n}.`);
|
|
586
|
+
if (typeof o != "object")
|
|
587
|
+
throw Error(`[GUI] toggle() "obj" (or "object") parameter must be an object. Received: ${typeof o}.`);
|
|
588
|
+
i == " " && (i = n), s = this.propReferences.push(o[n]) - 1, r = !0;
|
|
589
|
+
} else
|
|
590
|
+
(n != null && o == null || n == null && o == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
|
|
581
591
|
this.imageContainer = null;
|
|
582
|
-
|
|
592
|
+
const l = this._createElement({
|
|
583
593
|
class: "p-gui__switch",
|
|
584
|
-
onclick: (
|
|
585
|
-
|
|
586
|
-
|
|
594
|
+
onclick: (c) => {
|
|
595
|
+
const g = c.target.childNodes[1];
|
|
596
|
+
let b = !0;
|
|
597
|
+
g.classList.contains("p-gui__switch-checkbox--active") && (b = !1), g.classList.toggle("p-gui__switch-checkbox--active"), r ? o[n] = b : typeof t == "function" && t(b);
|
|
587
598
|
},
|
|
588
599
|
textContent: i
|
|
589
|
-
})
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
600
|
+
});
|
|
601
|
+
let u = (() => r ? o[n] ? " p-gui__switch-checkbox--active" : "" : a ? " p-gui__switch-checkbox--active" : "")();
|
|
602
|
+
const p = this._createElement({
|
|
603
|
+
parent: l,
|
|
604
|
+
class: "p-gui__switch-checkbox" + u
|
|
605
|
+
});
|
|
606
|
+
r && Object.defineProperty(o, n, {
|
|
607
|
+
set: (c) => {
|
|
608
|
+
this.propReferences[s] = c, c ? p.classList.add("p-gui__switch-checkbox--active") : p.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(c);
|
|
609
|
+
},
|
|
610
|
+
get: () => this.propReferences[s]
|
|
593
611
|
});
|
|
594
612
|
}
|
|
595
613
|
list(e = {}, t) {
|
|
596
614
|
if (typeof e != "object")
|
|
597
615
|
throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
|
|
598
|
-
let i = typeof e.name == "string" ? e.name : " ", r = Array.isArray(e.values) ? e.values : null,
|
|
616
|
+
let i = typeof e.name == "string" ? e.name : " ", r = Array.isArray(e.values) ? e.values : null, s = (() => {
|
|
599
617
|
if (!r)
|
|
600
618
|
return null;
|
|
601
619
|
if (typeof e.value == "string")
|
|
@@ -604,27 +622,27 @@ class u {
|
|
|
604
622
|
return e.value;
|
|
605
623
|
})();
|
|
606
624
|
t = typeof t == "function" ? t : null, this.imageContainer = null;
|
|
607
|
-
let
|
|
625
|
+
let o = this._createElement({
|
|
608
626
|
class: "p-gui__list",
|
|
609
627
|
textContent: i
|
|
610
|
-
}),
|
|
611
|
-
parent:
|
|
628
|
+
}), n = this._createElement({
|
|
629
|
+
parent: o,
|
|
612
630
|
el: "select",
|
|
613
631
|
class: "p-gui__list-dropdown",
|
|
614
|
-
onchange: (
|
|
615
|
-
t && t(
|
|
632
|
+
onchange: (a) => {
|
|
633
|
+
t && t(a.target.value);
|
|
616
634
|
}
|
|
617
635
|
});
|
|
618
|
-
r && r.forEach((
|
|
619
|
-
let
|
|
620
|
-
parent:
|
|
636
|
+
r && r.forEach((a, l) => {
|
|
637
|
+
let u = this._createElement({
|
|
638
|
+
parent: n,
|
|
621
639
|
el: "option",
|
|
622
640
|
customAttributes: {
|
|
623
|
-
value:
|
|
641
|
+
value: a
|
|
624
642
|
},
|
|
625
|
-
textContent:
|
|
643
|
+
textContent: a
|
|
626
644
|
});
|
|
627
|
-
|
|
645
|
+
s == l && u.setAttribute("selected", "");
|
|
628
646
|
});
|
|
629
647
|
}
|
|
630
648
|
options(e, t) {
|
|
@@ -636,51 +654,51 @@ class u {
|
|
|
636
654
|
if (typeof e != "object")
|
|
637
655
|
throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
|
|
638
656
|
let i = typeof e.name == "string" && e.name || " ";
|
|
639
|
-
const r = e.x.min ?? 0,
|
|
657
|
+
const r = e.x.min ?? 0, s = e.x.max ?? 1, o = e.y.min ?? 0, n = e.y.max ?? 1, a = e.x.obj || e.x.object, l = e.x.prop || e.x.property, u = this.propReferences.push(a[l]) - 1, p = e.y.obj || e.y.object, c = e.y.prop || e.y.property, g = this.propReferences.push(p[c]) - 1;
|
|
640
658
|
t = typeof t == "function" ? t : null, this.imageContainer = null;
|
|
641
|
-
const
|
|
659
|
+
const b = this._createElement({
|
|
642
660
|
class: "p-gui__vector2",
|
|
643
661
|
textContent: i
|
|
644
|
-
}),
|
|
645
|
-
parent:
|
|
662
|
+
}), _ = this._createElement({
|
|
663
|
+
parent: b,
|
|
646
664
|
class: "p-gui__vector-value",
|
|
647
|
-
textContent:
|
|
648
|
-
}),
|
|
649
|
-
parent:
|
|
665
|
+
textContent: a[l] + ", " + p[c]
|
|
666
|
+
}), d = this._createElement({
|
|
667
|
+
parent: b,
|
|
650
668
|
el: "div",
|
|
651
669
|
class: "p-gui__vector2-area",
|
|
652
|
-
onclick: (
|
|
653
|
-
|
|
670
|
+
onclick: (h) => {
|
|
671
|
+
a[l] = parseFloat(this._mapLinear(h.offsetX, 0, d.clientWidth, r, s).toFixed(2)), p[c] = parseFloat(this._mapLinear(h.offsetY, 0, d.clientHeight, n, o).toFixed(2)), t && t(a[l], a[c]);
|
|
654
672
|
}
|
|
655
673
|
});
|
|
656
674
|
let m = !1;
|
|
657
|
-
|
|
675
|
+
d.addEventListener("pointerdown", (h) => {
|
|
658
676
|
m = !0;
|
|
659
|
-
}),
|
|
677
|
+
}), d.addEventListener("pointerup", () => {
|
|
660
678
|
m = !1;
|
|
661
|
-
}),
|
|
662
|
-
m && (
|
|
679
|
+
}), d.addEventListener("pointermove", (h) => {
|
|
680
|
+
m && (a[l] = parseFloat(this._mapLinear(h.offsetX, 0, d.clientWidth, r, s).toFixed(2)), p[c] = parseFloat(this._mapLinear(h.offsetY, 0, d.clientHeight, n, o).toFixed(2)), t && t(a[l], a[c]));
|
|
663
681
|
}), this._createElement({
|
|
664
|
-
parent:
|
|
682
|
+
parent: d,
|
|
665
683
|
class: "p-gui__vector2-line p-gui__vector2-line-x"
|
|
666
684
|
}), this._createElement({
|
|
667
|
-
parent:
|
|
685
|
+
parent: d,
|
|
668
686
|
class: "p-gui__vector2-line p-gui__vector2-line-y"
|
|
669
687
|
});
|
|
670
688
|
const x = this._createElement({
|
|
671
|
-
parent:
|
|
689
|
+
parent: d,
|
|
672
690
|
class: "p-gui__vector2-dot"
|
|
673
691
|
});
|
|
674
|
-
x.style.left = this._mapLinear(
|
|
675
|
-
set: (
|
|
676
|
-
this.propReferences[
|
|
692
|
+
x.style.left = this._mapLinear(a[l], r, s, 0, d.clientWidth) + "px", x.style.top = this._mapLinear(p[c], o, n, d.clientHeight, 0) + "px", Object.defineProperty(a, l, {
|
|
693
|
+
set: (h) => {
|
|
694
|
+
this.propReferences[u] = h, x.style.left = this._mapLinear(h, r, s, 0, d.clientWidth) + "px", _.textContent = String(h) + ", " + p[c];
|
|
677
695
|
},
|
|
678
|
-
get: () => this.propReferences[
|
|
679
|
-
}), Object.defineProperty(
|
|
680
|
-
set: (
|
|
681
|
-
this.propReferences[
|
|
696
|
+
get: () => this.propReferences[u]
|
|
697
|
+
}), Object.defineProperty(p, c, {
|
|
698
|
+
set: (h) => {
|
|
699
|
+
this.propReferences[g] = h, x.style.top = this._mapLinear(h, o, n, d.clientHeight, 0) + "px", _.textContent = a[l] + ", " + String(h);
|
|
682
700
|
},
|
|
683
|
-
get: () => this.propReferences[
|
|
701
|
+
get: () => this.propReferences[g]
|
|
684
702
|
});
|
|
685
703
|
}
|
|
686
704
|
color(e = {}, t) {
|
|
@@ -688,31 +706,31 @@ class u {
|
|
|
688
706
|
throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
|
|
689
707
|
let i = typeof e.name == "string" && e.name || " ", r;
|
|
690
708
|
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");
|
|
691
|
-
const
|
|
709
|
+
const s = this._createElement({
|
|
692
710
|
el: "div",
|
|
693
711
|
class: "p-gui__color",
|
|
694
712
|
textContent: i
|
|
695
|
-
}),
|
|
696
|
-
parent:
|
|
713
|
+
}), o = this._createElement({
|
|
714
|
+
parent: s,
|
|
697
715
|
el: "input",
|
|
698
716
|
class: "p-gui__color-picker",
|
|
699
717
|
type: "color",
|
|
700
718
|
value: r
|
|
701
719
|
});
|
|
702
|
-
typeof t == "function" &&
|
|
703
|
-
t(
|
|
720
|
+
typeof t == "function" && o.addEventListener("input", () => {
|
|
721
|
+
t(o.value);
|
|
704
722
|
});
|
|
705
723
|
}
|
|
706
724
|
folder(e = {}) {
|
|
707
|
-
let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.name || "", r = e.color || null,
|
|
725
|
+
let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.name || "", r = e.color || null, s = e.maxHeight || null;
|
|
708
726
|
this.imageContainer = null;
|
|
709
|
-
let
|
|
710
|
-
this.folders.length == 0 && (
|
|
711
|
-
let
|
|
712
|
-
|
|
713
|
-
let
|
|
714
|
-
class:
|
|
715
|
-
inline:
|
|
727
|
+
let o = "p-gui__folder";
|
|
728
|
+
this.folders.length == 0 && (o += " p-gui__folder--first"), t && (o += " p-gui__folder--closed");
|
|
729
|
+
let n = r ? `background-color: ${r};` : "";
|
|
730
|
+
n += s ? `max-height: ${s}px;` : "";
|
|
731
|
+
let a = this._createElement({
|
|
732
|
+
class: o,
|
|
733
|
+
inline: n
|
|
716
734
|
});
|
|
717
735
|
this._createElement({
|
|
718
736
|
innerHTML: `<span class="p-gui__folder-arrow"></span>${i}`,
|
|
@@ -720,23 +738,23 @@ class u {
|
|
|
720
738
|
onclick: function() {
|
|
721
739
|
this.parentNode.classList.toggle("p-gui__folder--closed");
|
|
722
740
|
},
|
|
723
|
-
parent:
|
|
741
|
+
parent: a
|
|
724
742
|
});
|
|
725
|
-
let l = new
|
|
726
|
-
wrapper:
|
|
743
|
+
let l = new f({ isFolder: !0, folderOptions: {
|
|
744
|
+
wrapper: a
|
|
727
745
|
} });
|
|
728
746
|
return this.folders.push(l), l;
|
|
729
747
|
}
|
|
730
748
|
_makeDraggable() {
|
|
731
749
|
var e = this;
|
|
732
750
|
this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", r);
|
|
733
|
-
function t(
|
|
734
|
-
|
|
751
|
+
function t(s) {
|
|
752
|
+
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);
|
|
735
753
|
}
|
|
736
|
-
function i(
|
|
737
|
-
|
|
754
|
+
function i(s) {
|
|
755
|
+
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)";
|
|
738
756
|
}
|
|
739
|
-
function r(
|
|
757
|
+
function r(s) {
|
|
740
758
|
document.removeEventListener("pointermove", i);
|
|
741
759
|
}
|
|
742
760
|
}
|
|
@@ -746,10 +764,10 @@ class u {
|
|
|
746
764
|
kill() {
|
|
747
765
|
this.wrapper.remove();
|
|
748
766
|
}
|
|
749
|
-
_mapLinear(e, t, i, r,
|
|
750
|
-
return r + (e - t) * (
|
|
767
|
+
_mapLinear(e, t, i, r, s) {
|
|
768
|
+
return r + (e - t) * (s - r) / (i - t);
|
|
751
769
|
}
|
|
752
770
|
}
|
|
753
771
|
export {
|
|
754
|
-
|
|
772
|
+
f as default
|
|
755
773
|
};
|
package/dist/perfect-gui.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(x,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(x=typeof globalThis<"u"?globalThis:x||self,x["Perfect GUI"]=c())})(this,function(){"use strict";function x(w){return`
|
|
2
2
|
.p-gui {
|
|
3
3
|
--main-border-radius: 5px;
|
|
4
4
|
--color-bg: #121212;
|
|
@@ -407,10 +407,10 @@
|
|
|
407
407
|
.p-gui__folder--closed .p-gui__folder-arrow {
|
|
408
408
|
transform: rotate(0deg);
|
|
409
409
|
}
|
|
410
|
-
`}class c{constructor(e={}){if(e.container?(this.container=typeof e.container=="string"?document.querySelector(e.container):e.container,this.position_type="absolute"):(this.container=document.body,this.position_type="fixed"),this.propReferences=[],this.folders=[],e.isFolder){this._folderConstructor(e.folderOptions);return}this.name=e!=null&&typeof e.name=="string"?e.name:"",this.backgroundColor=e.color||null,this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),e.maxHeight&&(this.initMaxHeight=e.maxHeight,this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.screenCorner=this._parseScreenCorner(e.position),this instanceof c&&(typeof c[c.instanceCounter]!="number"?c[c.instanceCounter]=0:c[c.instanceCounter]++),this.instanceId=c[c.instanceCounter],this.wrapperWidth=e.width||290,this.stylesheet=document.createElement("style"),this.stylesheet.setAttribute("type","text/css"),this.stylesheet.setAttribute("id","lm-gui-stylesheet"),document.head.append(this.stylesheet),this.instanceId==0&&this._addStyles(`${
|
|
410
|
+
`}class c{constructor(e={}){if(e.container?(this.container=typeof e.container=="string"?document.querySelector(e.container):e.container,this.position_type="absolute"):(this.container=document.body,this.position_type="fixed"),this.propReferences=[],this.folders=[],e.isFolder){this._folderConstructor(e.folderOptions);return}this.name=e!=null&&typeof e.name=="string"?e.name:"",this.backgroundColor=e.color||null,this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),e.maxHeight&&(this.initMaxHeight=e.maxHeight,this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.screenCorner=this._parseScreenCorner(e.position),this instanceof c&&(typeof c[c.instanceCounter]!="number"?c[c.instanceCounter]=0:c[c.instanceCounter]++),this.instanceId=c[c.instanceCounter],this.wrapperWidth=e.width||290,this.stylesheet=document.createElement("style"),this.stylesheet.setAttribute("type","text/css"),this.stylesheet.setAttribute("id","lm-gui-stylesheet"),document.head.append(this.stylesheet),this.instanceId==0&&this._addStyles(`${x(this.position_type)}`),this._styleInstance(),this._addWrapper(),this.wrapper.setAttribute("data-corner-x",this.screenCorner.x),this.wrapper.setAttribute("data-corner-y",this.screenCorner.y),e.autoRepositioning!=!1&&window.addEventListener("resize",this._handleResize.bind(this)),this._handleResize(),this.hasBeenDragged=!1,e.draggable==!0&&this._makeDraggable(),this.closed=!1,e.closed&&this.toggleClose()}_styleInstance(){let e=this._getScrollbarWidth(this.container);if(this.screenCorner.x=="left"?this.xOffset=0:this.xOffset=this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(".p-gui");for(let i=0;i<t.length;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.yOffset=0,this.position={prevX:this.xOffset,prevY:this.yOffset,x:this.xOffset,y:this.yOffset},this._addStyles(`#p-gui-${this.instanceId} {
|
|
411
411
|
width: ${this.wrapperWidth}px;
|
|
412
412
|
max-height: ${this.maxHeight}px;
|
|
413
413
|
transform: translate3d(${this.xOffset}px,${this.yOffset}px,0);
|
|
414
414
|
${this.screenCorner.y=="top"?"":"top: auto; bottom: 0;"}
|
|
415
415
|
${this.backgroundColor?"background: "+this.backgroundColor+";":""}
|
|
416
|
-
}`)}_folderConstructor(e){this.wrapper=e.wrapper}_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)`}_createElement(e){e.el=e.el||"div";var t=document.createElement(e.el);if(e.id&&(t.id=e.id),e.class&&(t.className=e.class),e.inline&&(t.style=e.inline),e.href&&(t.href=e.href),e.onclick&&(t.onclick=e.onclick),e.onchange&&(t.onchange=e.onchange),e.textContent&&(t.textContent=e.textContent),e.innerHTML&&(t.innerHTML=e.innerHTML),e.type&&(t.type=e.type),e.value&&(t.value=e.value),e.customAttributes)for(var i in e.customAttributes)t.setAttribute(i,e.customAttributes[i]);return e.parent=e.parent?e.parent:this.wrapper,e.parent.append(t),t}_addStyles(e){this.stylesheet.innerHTML+=e}_addWrapper(){this.wrapper=this._createElement({parent:this.container,id:"p-gui-"+this.instanceId,class:"p-gui"}),this.header=this._createElement({parent:this.wrapper,class:"p-gui__header",textContent:this.name,inline:`${this.backgroundColor?"border-color: "+this.backgroundColor+";":""}`}),this._createElement({parent:this.header,class:"p-gui__header-close",onclick:this.toggleClose.bind(this)})}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,this.imageContainer=null,typeof t!="function"&&(t=()=>{});const r=this._createElement({class:"p-gui__button",textContent:i,onclick:t});typeof e.color=="string"&&(r.style.setProperty("--color-accent",e.color),r.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 r=i.replace(/^.*[\\\/]/,""),o;e.name==null?o=r:o=typeof e.name=="string"&&e.name||" ";const s=e.selected===!0,a=e.selectionBorder!==!1;let n="";e.width&&(typeof e.width=="number"&&(e.width+="px"),n+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),n+=`height: ${e.height}; `),this.imageContainer||(this.imageContainer=this._createElement({class:"p-gui__image-container"}));var l=this._createElement({class:"p-gui__image",inline:"background-image: url("+i+"); "+n,parent:this.imageContainer});s&&a&&l.classList.add("p-gui__image--selected"),this._createElement({parent:l,class:"p-gui__image-text",textContent:o}),typeof t=="function"&&(l.onclick=()=>{let g=this.imageContainer.querySelectorAll(".p-gui__image--selected");for(let h=0;h<g.length;h++)g[h].classList.remove("p-gui__image--selected");a&&l.classList.add("p-gui__image--selected"),t({path:i,text:o})})}slider(e={},t){if(typeof e!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",r=!1,o=null,s=e.obj||e.object,a=e.prop||e.property,n=typeof e.value=="number"?e.value:null,l=e.min??0,g=e.max??1,h=e.step||(g-l)/100;if(n!==null)(a!=null||s!=null)&&console.warn('[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.');else if(a!=null&&s!=null){if(typeof a!="string")throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof a}.`);if(typeof s!="object")throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof s}.`);i==" "&&(i=a),o=this.propReferences.push(s[a])-1,r=!0}else(a!=null&&s==null||a==null&&s==null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),n=(g-l)/2;this.imageContainer=null;var u=this._createElement({class:"p-gui__slider",textContent:i}),f=this._createElement({parent:u,el:"input",class:"p-gui__slider-ctrl",customAttributes:{type:"range",min:l,max:g,step:h,value:r?s[a]:n}}),x=this._createElement({parent:u,class:"p-gui__slider-value",textContent:String(r?s[a]:n)});f.addEventListener("input",()=>{x.textContent=f.value,r&&(s[a]=f.value),typeof t=="function"&&t(parseFloat(f.value))}),r&&Object.defineProperty(s,a,{set:b=>{this.propReferences[o]=b,f.value=b,x.textContent=String(b)},get:()=>this.propReferences[o]})}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||" ",r=e.value===!0;this.imageContainer=null;let o=this._createElement({class:"p-gui__switch",onclick:a=>{let n=a.target.childNodes[1],l=!0;n.classList.contains("p-gui__switch-checkbox--active")&&(l=!1),n.classList.toggle("p-gui__switch-checkbox--active"),typeof t=="function"&&t(l)},textContent:i}),s=r?" p-gui__switch-checkbox--active":"";this._createElement({parent:o,class:"p-gui__switch-checkbox"+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:" ",r=Array.isArray(e.values)?e.values:null,o=(()=>{if(!r)return null;if(typeof e.value=="string")return r.indexOf(e.value);if(typeof e.value=="number")return e.value})();t=typeof t=="function"?t:null,this.imageContainer=null;let s=this._createElement({class:"p-gui__list",textContent:i}),a=this._createElement({parent:s,el:"select",class:"p-gui__list-dropdown",onchange:n=>{t&&t(n.target.value)}});r&&r.forEach((n,l)=>{let g=this._createElement({parent:a,el:"option",customAttributes:{value:n},textContent:n});o==l&&g.setAttribute("selected","")})}options(e,t){if(typeof e!="object")throw Error(`[GUI] options() first parameter must be an object. Received: ${typeof e}.`);this.list(e,t)}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 r=e.x.min??0,o=e.x.max??1,s=e.y.min??0,a=e.y.max??1,n=e.x.obj||e.x.object,l=e.x.prop||e.x.property,g=this.propReferences.push(n[l])-1,h=e.y.obj||e.y.object,u=e.y.prop||e.y.property,f=this.propReferences.push(h[u])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const x=this._createElement({class:"p-gui__vector2",textContent:i}),b=this._createElement({parent:x,class:"p-gui__vector-value",textContent:n[l]+", "+h[u]}),p=this._createElement({parent:x,el:"div",class:"p-gui__vector2-area",onclick:d=>{n[l]=parseFloat(this._mapLinear(d.offsetX,0,p.clientWidth,r,o).toFixed(2)),h[u]=parseFloat(this._mapLinear(d.offsetY,0,p.clientHeight,a,s).toFixed(2)),t&&t(n[l],n[u])}});let y=!1;p.addEventListener("pointerdown",d=>{y=!0}),p.addEventListener("pointerup",()=>{y=!1}),p.addEventListener("pointermove",d=>{y&&(n[l]=parseFloat(this._mapLinear(d.offsetX,0,p.clientWidth,r,o).toFixed(2)),h[u]=parseFloat(this._mapLinear(d.offsetY,0,p.clientHeight,a,s).toFixed(2)),t&&t(n[l],n[u]))}),this._createElement({parent:p,class:"p-gui__vector2-line p-gui__vector2-line-x"}),this._createElement({parent:p,class:"p-gui__vector2-line p-gui__vector2-line-y"});const m=this._createElement({parent:p,class:"p-gui__vector2-dot"});m.style.left=this._mapLinear(n[l],r,o,0,p.clientWidth)+"px",m.style.top=this._mapLinear(h[u],s,a,p.clientHeight,0)+"px",Object.defineProperty(n,l,{set:d=>{this.propReferences[g]=d,m.style.left=this._mapLinear(d,r,o,0,p.clientWidth)+"px",b.textContent=String(d)+", "+h[u]},get:()=>this.propReferences[g]}),Object.defineProperty(h,u,{set:d=>{this.propReferences[f]=d,m.style.top=this._mapLinear(d,s,a,p.clientHeight,0)+"px",b.textContent=n[l]+", "+String(d)},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||" ",r;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");const o=this._createElement({el:"div",class:"p-gui__color",textContent:i}),s=this._createElement({parent:o,el:"input",class:"p-gui__color-picker",type:"color",value:r});typeof t=="function"&&s.addEventListener("input",()=>{t(s.value)})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,i=e.name||"",r=e.color||null,o=e.maxHeight||null;this.imageContainer=null;let s="p-gui__folder";this.folders.length==0&&(s+=" p-gui__folder--first"),t&&(s+=" p-gui__folder--closed");let a=r?`background-color: ${r};`:"";a+=o?`max-height: ${o}px;`:"";let n=this._createElement({class:s,inline:a});this._createElement({innerHTML:`<span class="p-gui__folder-arrow"></span>${i}`,class:"p-gui__folder-header",onclick:function(){this.parentNode.classList.toggle("p-gui__folder--closed")},parent:n});let l=new c({isFolder:!0,folderOptions:{wrapper:n}});return this.folders.push(l),l}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",r);function t(o){o.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=o.clientX,e.position.prevY=o.clientY,document.addEventListener("pointermove",i)}function i(o){o.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+o.clientX-e.position.prevX,e.position.y=e.position.initY+o.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function r(o){document.removeEventListener("pointermove",i)}}toggleClose(){this.closed=!this.closed,this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,i,r,o){return r+(e-t)*(o-r)/(i-t)}}return c});
|
|
416
|
+
}`)}_folderConstructor(e){this.wrapper=e.wrapper}_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)`}_createElement(e){e.el=e.el||"div";var t=document.createElement(e.el);if(e.id&&(t.id=e.id),e.class&&(t.className=e.class),e.inline&&(t.style=e.inline),e.href&&(t.href=e.href),e.onclick&&(t.onclick=e.onclick),e.onchange&&(t.onchange=e.onchange),e.textContent&&(t.textContent=e.textContent),e.innerHTML&&(t.innerHTML=e.innerHTML),e.type&&(t.type=e.type),e.value&&(t.value=e.value),e.customAttributes)for(var i in e.customAttributes)t.setAttribute(i,e.customAttributes[i]);return e.parent=e.parent?e.parent:this.wrapper,e.parent.append(t),t}_addStyles(e){this.stylesheet.innerHTML+=e}_addWrapper(){this.wrapper=this._createElement({parent:this.container,id:"p-gui-"+this.instanceId,class:"p-gui"}),this.header=this._createElement({parent:this.wrapper,class:"p-gui__header",textContent:this.name,inline:`${this.backgroundColor?"border-color: "+this.backgroundColor+";":""}`}),this._createElement({parent:this.header,class:"p-gui__header-close",onclick:this.toggleClose.bind(this)})}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,this.imageContainer=null,typeof t!="function"&&(t=()=>{});const r=this._createElement({class:"p-gui__button",textContent:i,onclick:t});typeof e.color=="string"&&(r.style.setProperty("--color-accent",e.color),r.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 r=i.replace(/^.*[\\\/]/,""),s;e.name==null?s=r:s=typeof e.name=="string"&&e.name||" ";const o=e.selected===!0,n=e.selectionBorder!==!1;let a="";e.width&&(typeof e.width=="number"&&(e.width+="px"),a+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),a+=`height: ${e.height}; `),this.imageContainer||(this.imageContainer=this._createElement({class:"p-gui__image-container"}));var l=this._createElement({class:"p-gui__image",inline:"background-image: url("+i+"); "+a,parent:this.imageContainer});o&&n&&l.classList.add("p-gui__image--selected"),this._createElement({parent:l,class:"p-gui__image-text",textContent:s}),typeof t=="function"&&(l.onclick=()=>{let g=this.imageContainer.querySelectorAll(".p-gui__image--selected");for(let d=0;d<g.length;d++)g[d].classList.remove("p-gui__image--selected");n&&l.classList.add("p-gui__image--selected"),t({path:i,text:s})})}slider(e={},t){if(typeof e!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",r=!1,s=null,o=e.obj||e.object,n=e.prop||e.property,a=typeof e.value=="number"?e.value:null,l=e.min??0,g=e.max??1,d=e.step||(g-l)/100;if(a!==null)(n!=null||o!=null)&&console.warn('[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),s=this.propReferences.push(o[n])-1,r=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),a=(g-l)/2;this.imageContainer=null;var p=this._createElement({class:"p-gui__slider",textContent:i}),f=this._createElement({parent:p,el:"input",class:"p-gui__slider-ctrl",customAttributes:{type:"range",min:l,max:g,step:d,value:r?o[n]:a}}),b=this._createElement({parent:p,class:"p-gui__slider-value",textContent:String(r?o[n]:a)});f.addEventListener("input",()=>{b.textContent=f.value,r?o[n]=f.value:typeof t=="function"&&t(parseFloat(f.value))}),r&&Object.defineProperty(o,n,{set:_=>{this.propReferences[s]=_,f.value=_,b.textContent=String(_),typeof t=="function"&&t(parseFloat(f.value))},get:()=>this.propReferences[s]})}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||" ",r=!1,s=null,o=e.obj||e.object,n=e.prop||e.property,a=typeof e.value=="boolean"?e.value:null;if(a!==null)(n!=null||o!=null)&&console.warn('[GUI] toggle() "obj" and "property" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] toggle() "prop" (or "property") parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] toggle() "obj" (or "object") parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),s=this.propReferences.push(o[n])-1,r=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const l=this._createElement({class:"p-gui__switch",onclick:p=>{const f=p.target.childNodes[1];let b=!0;f.classList.contains("p-gui__switch-checkbox--active")&&(b=!1),f.classList.toggle("p-gui__switch-checkbox--active"),r?o[n]=b:typeof t=="function"&&t(b)},textContent:i});let g=(()=>r?o[n]?" p-gui__switch-checkbox--active":"":a?" p-gui__switch-checkbox--active":"")();const d=this._createElement({parent:l,class:"p-gui__switch-checkbox"+g});r&&Object.defineProperty(o,n,{set:p=>{this.propReferences[s]=p,p?d.classList.add("p-gui__switch-checkbox--active"):d.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(p)},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:" ",r=Array.isArray(e.values)?e.values:null,s=(()=>{if(!r)return null;if(typeof e.value=="string")return r.indexOf(e.value);if(typeof e.value=="number")return e.value})();t=typeof t=="function"?t:null,this.imageContainer=null;let o=this._createElement({class:"p-gui__list",textContent:i}),n=this._createElement({parent:o,el:"select",class:"p-gui__list-dropdown",onchange:a=>{t&&t(a.target.value)}});r&&r.forEach((a,l)=>{let g=this._createElement({parent:n,el:"option",customAttributes:{value:a},textContent:a});s==l&&g.setAttribute("selected","")})}options(e,t){if(typeof e!="object")throw Error(`[GUI] options() first parameter must be an object. Received: ${typeof e}.`);this.list(e,t)}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 r=e.x.min??0,s=e.x.max??1,o=e.y.min??0,n=e.y.max??1,a=e.x.obj||e.x.object,l=e.x.prop||e.x.property,g=this.propReferences.push(a[l])-1,d=e.y.obj||e.y.object,p=e.y.prop||e.y.property,f=this.propReferences.push(d[p])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const b=this._createElement({class:"p-gui__vector2",textContent:i}),_=this._createElement({parent:b,class:"p-gui__vector-value",textContent:a[l]+", "+d[p]}),h=this._createElement({parent:b,el:"div",class:"p-gui__vector2-area",onclick:u=>{a[l]=parseFloat(this._mapLinear(u.offsetX,0,h.clientWidth,r,s).toFixed(2)),d[p]=parseFloat(this._mapLinear(u.offsetY,0,h.clientHeight,n,o).toFixed(2)),t&&t(a[l],a[p])}});let y=!1;h.addEventListener("pointerdown",u=>{y=!0}),h.addEventListener("pointerup",()=>{y=!1}),h.addEventListener("pointermove",u=>{y&&(a[l]=parseFloat(this._mapLinear(u.offsetX,0,h.clientWidth,r,s).toFixed(2)),d[p]=parseFloat(this._mapLinear(u.offsetY,0,h.clientHeight,n,o).toFixed(2)),t&&t(a[l],a[p]))}),this._createElement({parent:h,class:"p-gui__vector2-line p-gui__vector2-line-x"}),this._createElement({parent:h,class:"p-gui__vector2-line p-gui__vector2-line-y"});const m=this._createElement({parent:h,class:"p-gui__vector2-dot"});m.style.left=this._mapLinear(a[l],r,s,0,h.clientWidth)+"px",m.style.top=this._mapLinear(d[p],o,n,h.clientHeight,0)+"px",Object.defineProperty(a,l,{set:u=>{this.propReferences[g]=u,m.style.left=this._mapLinear(u,r,s,0,h.clientWidth)+"px",_.textContent=String(u)+", "+d[p]},get:()=>this.propReferences[g]}),Object.defineProperty(d,p,{set:u=>{this.propReferences[f]=u,m.style.top=this._mapLinear(u,o,n,h.clientHeight,0)+"px",_.textContent=a[l]+", "+String(u)},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||" ",r;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");const s=this._createElement({el:"div",class:"p-gui__color",textContent:i}),o=this._createElement({parent:s,el:"input",class:"p-gui__color-picker",type:"color",value:r});typeof t=="function"&&o.addEventListener("input",()=>{t(o.value)})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,i=e.name||"",r=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=r?`background-color: ${r};`:"";n+=s?`max-height: ${s}px;`:"";let a=this._createElement({class:o,inline:n});this._createElement({innerHTML:`<span class="p-gui__folder-arrow"></span>${i}`,class:"p-gui__folder-header",onclick:function(){this.parentNode.classList.toggle("p-gui__folder--closed")},parent:a});let l=new c({isFolder:!0,folderOptions:{wrapper:a}});return this.folders.push(l),l}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",r);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 r(s){document.removeEventListener("pointermove",i)}}toggleClose(){this.closed=!this.closed,this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,i,r,s){return r+(e-t)*(s-r)/(i-t)}}return c});
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -423,10 +423,11 @@ export default class GUI {
|
|
|
423
423
|
if ( isObject ) {
|
|
424
424
|
obj[prop] = slider_ctrl.value;
|
|
425
425
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
else {
|
|
427
|
+
if (typeof callback == "function") {
|
|
428
|
+
callback(parseFloat(slider_ctrl.value));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
430
431
|
});
|
|
431
432
|
|
|
432
433
|
if ( isObject ) {
|
|
@@ -435,6 +436,10 @@ export default class GUI {
|
|
|
435
436
|
this.propReferences[propReferenceIndex] = val;
|
|
436
437
|
slider_ctrl.value = val;
|
|
437
438
|
slider_value.textContent = String( val );
|
|
439
|
+
|
|
440
|
+
if (typeof callback == "function") {
|
|
441
|
+
callback(parseFloat(slider_ctrl.value));
|
|
442
|
+
}
|
|
438
443
|
},
|
|
439
444
|
get: () => {
|
|
440
445
|
return this.propReferences[propReferenceIndex];
|
|
@@ -449,32 +454,102 @@ export default class GUI {
|
|
|
449
454
|
}
|
|
450
455
|
|
|
451
456
|
let name = typeof params.name == 'string' ? params.name || ' ' : ' ';
|
|
452
|
-
let
|
|
457
|
+
let isObject = false;
|
|
458
|
+
let propReferenceIndex = null;
|
|
459
|
+
let obj = params.obj || params.object;
|
|
460
|
+
let prop = params.prop || params.property;
|
|
461
|
+
let value = typeof params.value === 'boolean' ? params.value : null;
|
|
462
|
+
|
|
463
|
+
// callback mode
|
|
464
|
+
if ( value !== null ) {
|
|
465
|
+
if (prop != undefined || obj != undefined) {
|
|
466
|
+
console.warn(`[GUI] toggle() "obj" and "property" parameters are ignored when a "value" parameter is used.`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// object-binding
|
|
471
|
+
else if (prop != undefined && obj != undefined) {
|
|
472
|
+
if (typeof prop != 'string') {
|
|
473
|
+
throw Error(`[GUI] toggle() "prop" (or "property") parameter must be an string. Received: ${typeof prop}.`);
|
|
474
|
+
}
|
|
475
|
+
if (typeof obj != 'object') {
|
|
476
|
+
throw Error(`[GUI] toggle() "obj" (or "object") parameter must be an object. Received: ${typeof obj}.`);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (name == ' ') {
|
|
480
|
+
name = prop;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
propReferenceIndex = this.propReferences.push(obj[prop]) - 1;
|
|
484
|
+
isObject = true;
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
if ((prop != undefined && obj == undefined) || (prop == undefined && obj == undefined)) {
|
|
488
|
+
console.warn(`[GUI] toggle() "obj" and "prop" parameters must be used together.`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
453
491
|
|
|
454
492
|
this.imageContainer = null;
|
|
455
493
|
|
|
456
|
-
|
|
494
|
+
const container = this._createElement({
|
|
457
495
|
class: 'p-gui__switch',
|
|
458
496
|
onclick: (ev) => {
|
|
459
|
-
|
|
460
|
-
|
|
497
|
+
const checkbox = ev.target.childNodes[1];
|
|
498
|
+
|
|
499
|
+
let value = true;
|
|
500
|
+
|
|
461
501
|
if (checkbox.classList.contains('p-gui__switch-checkbox--active')) {
|
|
462
502
|
value = false;
|
|
463
503
|
}
|
|
504
|
+
|
|
464
505
|
checkbox.classList.toggle('p-gui__switch-checkbox--active');
|
|
465
|
-
|
|
466
|
-
|
|
506
|
+
|
|
507
|
+
if ( isObject ) {
|
|
508
|
+
obj[prop] = value;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
else {
|
|
512
|
+
if (typeof callback == 'function') {
|
|
513
|
+
callback(value);
|
|
514
|
+
}
|
|
467
515
|
}
|
|
468
516
|
},
|
|
469
517
|
textContent: name
|
|
470
518
|
});
|
|
471
519
|
|
|
472
|
-
let activeClass =
|
|
520
|
+
let activeClass = (() => {
|
|
521
|
+
if (!isObject) {
|
|
522
|
+
return value ? ' p-gui__switch-checkbox--active' : '';
|
|
523
|
+
} else {
|
|
524
|
+
return obj[prop] ? ' p-gui__switch-checkbox--active' : '';
|
|
525
|
+
}
|
|
526
|
+
})();
|
|
473
527
|
|
|
474
|
-
this._createElement({
|
|
475
|
-
parent:
|
|
528
|
+
const checkbox = this._createElement({
|
|
529
|
+
parent: container,
|
|
476
530
|
class: 'p-gui__switch-checkbox' + activeClass
|
|
477
531
|
});
|
|
532
|
+
|
|
533
|
+
if ( isObject ) {
|
|
534
|
+
Object.defineProperty( obj, prop, {
|
|
535
|
+
set: val => {
|
|
536
|
+
this.propReferences[propReferenceIndex] = val;
|
|
537
|
+
|
|
538
|
+
if (val) {
|
|
539
|
+
checkbox.classList.add('p-gui__switch-checkbox--active');
|
|
540
|
+
} else {
|
|
541
|
+
checkbox.classList.remove('p-gui__switch-checkbox--active');
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (typeof callback == 'function') {
|
|
545
|
+
callback(val);
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
get: () => {
|
|
549
|
+
return this.propReferences[propReferenceIndex];
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
478
553
|
}
|
|
479
554
|
|
|
480
555
|
list(params = {}, callback) {
|