perfect-gui 4.2.1 → 4.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/perfect-gui.mjs +65 -62
- package/package.json +1 -1
- package/src/index.js +26 -8
package/dist/perfect-gui.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function y
|
|
1
|
+
function w(y) {
|
|
2
2
|
return (
|
|
3
3
|
/* css */
|
|
4
4
|
`
|
|
@@ -10,7 +10,7 @@ function y(w) {
|
|
|
10
10
|
--color-accent: #1681ca;
|
|
11
11
|
--color-accent-hover: #218fda;
|
|
12
12
|
|
|
13
|
-
position: ${
|
|
13
|
+
position: ${y};
|
|
14
14
|
top: 0;
|
|
15
15
|
left: 0;
|
|
16
16
|
transform: translate3d(0,0,0);
|
|
@@ -405,7 +405,7 @@ class h {
|
|
|
405
405
|
this._folderConstructor(e.folderOptions);
|
|
406
406
|
return;
|
|
407
407
|
}
|
|
408
|
-
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 h && (typeof h[h.instanceCounter] != "number" ? h[h.instanceCounter] = 0 : h[h.instanceCounter]++), this.instanceId = h[h.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(`${
|
|
408
|
+
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 h && (typeof h[h.instanceCounter] != "number" ? h[h.instanceCounter] = 0 : h[h.instanceCounter]++), this.instanceId = h[h.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();
|
|
409
409
|
}
|
|
410
410
|
_styleInstance() {
|
|
411
411
|
let e = this._getScrollbarWidth(this.container);
|
|
@@ -476,12 +476,15 @@ class h {
|
|
|
476
476
|
});
|
|
477
477
|
}
|
|
478
478
|
button(e, t) {
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
let i = "";
|
|
480
|
+
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 = () => {
|
|
481
|
+
});
|
|
482
|
+
const r = this._createElement({
|
|
481
483
|
class: "p-gui__button",
|
|
482
|
-
textContent:
|
|
484
|
+
textContent: i,
|
|
483
485
|
onclick: t
|
|
484
486
|
});
|
|
487
|
+
typeof e.color == "string" && (r.style.setProperty("--color-accent", e.color), r.style.setProperty("--color-accent-hover", e.hoverColor || e.color));
|
|
485
488
|
}
|
|
486
489
|
image(e = {}, t) {
|
|
487
490
|
if (typeof e != "object")
|
|
@@ -491,8 +494,8 @@ class h {
|
|
|
491
494
|
i = e.path;
|
|
492
495
|
else
|
|
493
496
|
throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
|
|
494
|
-
let
|
|
495
|
-
e.name == null ?
|
|
497
|
+
let r = i.replace(/^.*[\\\/]/, ""), o;
|
|
498
|
+
e.name == null ? o = r : o = typeof e.name == "string" && e.name || " ", this.imageContainer || (this.imageContainer = this._createElement({
|
|
496
499
|
class: "p-gui__image-container"
|
|
497
500
|
}));
|
|
498
501
|
var n = this._createElement({
|
|
@@ -503,13 +506,13 @@ class h {
|
|
|
503
506
|
this._createElement({
|
|
504
507
|
parent: n,
|
|
505
508
|
class: "p-gui__image-text",
|
|
506
|
-
textContent:
|
|
507
|
-
}), typeof t == "function" && (n.onclick = () => t({ path: i, text:
|
|
509
|
+
textContent: o
|
|
510
|
+
}), typeof t == "function" && (n.onclick = () => t({ path: i, text: o }));
|
|
508
511
|
}
|
|
509
512
|
slider(e = {}, t) {
|
|
510
513
|
if (typeof e != "object")
|
|
511
514
|
throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
|
|
512
|
-
let i = typeof e.name == "string" && e.name || " ",
|
|
515
|
+
let i = typeof e.name == "string" && e.name || " ", r = !1, o = null, n = e.obj || e.object, s = e.prop || e.property, a = typeof e.value == "number" ? e.value : null, l = e.min ?? 0, f = e.max ?? 1, g = e.step || (f - l) / 100;
|
|
513
516
|
if (a !== null)
|
|
514
517
|
(s != null || n != null) && console.warn('[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.');
|
|
515
518
|
else if (s != null && n != null) {
|
|
@@ -517,9 +520,9 @@ class h {
|
|
|
517
520
|
throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof s}.`);
|
|
518
521
|
if (typeof n != "object")
|
|
519
522
|
throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof n}.`);
|
|
520
|
-
i == " " && (i = s),
|
|
523
|
+
i == " " && (i = s), o = this.propReferences.push(n[s]) - 1, r = !0;
|
|
521
524
|
} else
|
|
522
|
-
(s != null && n == null || s == null && n == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), a = (f -
|
|
525
|
+
(s != null && n == null || s == null && n == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), a = (f - l) / 2;
|
|
523
526
|
this.imageContainer = null;
|
|
524
527
|
var d = this._createElement({
|
|
525
528
|
class: "p-gui__slider",
|
|
@@ -530,60 +533,60 @@ class h {
|
|
|
530
533
|
class: "p-gui__slider-ctrl",
|
|
531
534
|
customAttributes: {
|
|
532
535
|
type: "range",
|
|
533
|
-
min:
|
|
536
|
+
min: l,
|
|
534
537
|
max: f,
|
|
535
538
|
step: g,
|
|
536
|
-
value:
|
|
539
|
+
value: r ? n[s] : a
|
|
537
540
|
}
|
|
538
541
|
}), _ = this._createElement({
|
|
539
542
|
parent: d,
|
|
540
543
|
class: "p-gui__slider-value",
|
|
541
|
-
textContent: String(
|
|
544
|
+
textContent: String(r ? n[s] : a)
|
|
542
545
|
});
|
|
543
546
|
u.addEventListener("input", () => {
|
|
544
|
-
_.textContent = u.value,
|
|
545
|
-
}),
|
|
547
|
+
_.textContent = u.value, r && (n[s] = u.value), typeof t == "function" && t(parseFloat(u.value));
|
|
548
|
+
}), r && Object.defineProperty(n, s, {
|
|
546
549
|
set: (b) => {
|
|
547
|
-
this.propReferences[
|
|
550
|
+
this.propReferences[o] = b, u.value = b, _.textContent = String(b);
|
|
548
551
|
},
|
|
549
|
-
get: () => this.propReferences[
|
|
552
|
+
get: () => this.propReferences[o]
|
|
550
553
|
});
|
|
551
554
|
}
|
|
552
555
|
toggle(e = {}, t) {
|
|
553
556
|
if (typeof e != "object")
|
|
554
557
|
throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
|
|
555
|
-
let i = typeof e.name == "string" && e.name || " ",
|
|
558
|
+
let i = typeof e.name == "string" && e.name || " ", r = e.value === !0;
|
|
556
559
|
this.imageContainer = null;
|
|
557
|
-
let
|
|
560
|
+
let o = this._createElement({
|
|
558
561
|
class: "p-gui__switch",
|
|
559
562
|
onclick: (s) => {
|
|
560
|
-
let a = s.target.childNodes[1],
|
|
561
|
-
a.classList.contains("p-gui__switch-checkbox--active") && (
|
|
563
|
+
let a = s.target.childNodes[1], l = !0;
|
|
564
|
+
a.classList.contains("p-gui__switch-checkbox--active") && (l = !1), a.classList.toggle("p-gui__switch-checkbox--active"), typeof t == "function" && t(l);
|
|
562
565
|
},
|
|
563
566
|
textContent: i
|
|
564
|
-
}), n =
|
|
567
|
+
}), n = r ? " p-gui__switch-checkbox--active" : "";
|
|
565
568
|
this._createElement({
|
|
566
|
-
parent:
|
|
569
|
+
parent: o,
|
|
567
570
|
class: "p-gui__switch-checkbox" + n
|
|
568
571
|
});
|
|
569
572
|
}
|
|
570
573
|
list(e = {}, t) {
|
|
571
574
|
if (typeof e != "object")
|
|
572
575
|
throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
|
|
573
|
-
let i = typeof e.name == "string" ? e.name : " ",
|
|
576
|
+
let i = typeof e.name == "string" ? e.name : " ", r = Array.isArray(e.values) ? e.values : null;
|
|
574
577
|
t = typeof t == "function" ? t : null, this.imageContainer = null;
|
|
575
|
-
let
|
|
578
|
+
let o = this._createElement({
|
|
576
579
|
class: "p-gui__list",
|
|
577
580
|
textContent: i
|
|
578
581
|
}), n = this._createElement({
|
|
579
|
-
parent:
|
|
582
|
+
parent: o,
|
|
580
583
|
el: "select",
|
|
581
584
|
class: "p-gui__list-dropdown",
|
|
582
585
|
onchange: (s) => {
|
|
583
586
|
t && t(s.target.value);
|
|
584
587
|
}
|
|
585
588
|
});
|
|
586
|
-
|
|
589
|
+
r.forEach((s) => {
|
|
587
590
|
this._createElement({
|
|
588
591
|
parent: n,
|
|
589
592
|
el: "option",
|
|
@@ -603,7 +606,7 @@ class h {
|
|
|
603
606
|
if (typeof e != "object")
|
|
604
607
|
throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
|
|
605
608
|
let i = typeof e.name == "string" && e.name || " ";
|
|
606
|
-
const
|
|
609
|
+
const r = e.x.min ?? 0, o = e.x.max ?? 1, n = e.y.min ?? 0, s = e.y.max ?? 1, a = e.x.obj || e.x.object, l = e.x.prop || e.x.property, f = this.propReferences.push(a[l]) - 1, g = e.y.obj || e.y.object, d = e.y.prop || e.y.property, u = this.propReferences.push(g[d]) - 1;
|
|
607
610
|
t = typeof t == "function" ? t : null, this.imageContainer = null;
|
|
608
611
|
const _ = this._createElement({
|
|
609
612
|
class: "p-gui__vector2",
|
|
@@ -611,41 +614,41 @@ class h {
|
|
|
611
614
|
}), b = this._createElement({
|
|
612
615
|
parent: _,
|
|
613
616
|
class: "p-gui__vector-value",
|
|
614
|
-
textContent: a[
|
|
615
|
-
}),
|
|
617
|
+
textContent: a[l] + ", " + g[d]
|
|
618
|
+
}), p = this._createElement({
|
|
616
619
|
parent: _,
|
|
617
620
|
el: "div",
|
|
618
621
|
class: "p-gui__vector2-area",
|
|
619
622
|
onclick: (c) => {
|
|
620
|
-
a[
|
|
623
|
+
a[l] = parseFloat(this._mapLinear(c.offsetX, 0, p.clientWidth, r, o).toFixed(2)), g[d] = parseFloat(this._mapLinear(c.offsetY, 0, p.clientHeight, s, n).toFixed(2)), t && t(a[l], a[d]);
|
|
621
624
|
}
|
|
622
625
|
});
|
|
623
626
|
let m = !1;
|
|
624
|
-
|
|
627
|
+
p.addEventListener("pointerdown", (c) => {
|
|
625
628
|
m = !0;
|
|
626
|
-
}),
|
|
629
|
+
}), p.addEventListener("pointerup", () => {
|
|
627
630
|
m = !1;
|
|
628
|
-
}),
|
|
629
|
-
m && (a[
|
|
631
|
+
}), p.addEventListener("pointermove", (c) => {
|
|
632
|
+
m && (a[l] = parseFloat(this._mapLinear(c.offsetX, 0, p.clientWidth, r, o).toFixed(2)), g[d] = parseFloat(this._mapLinear(c.offsetY, 0, p.clientHeight, s, n).toFixed(2)), t && t(a[l], a[d]));
|
|
630
633
|
}), this._createElement({
|
|
631
|
-
parent:
|
|
634
|
+
parent: p,
|
|
632
635
|
class: "p-gui__vector2-line p-gui__vector2-line-x"
|
|
633
636
|
}), this._createElement({
|
|
634
|
-
parent:
|
|
637
|
+
parent: p,
|
|
635
638
|
class: "p-gui__vector2-line p-gui__vector2-line-y"
|
|
636
639
|
});
|
|
637
640
|
const x = this._createElement({
|
|
638
|
-
parent:
|
|
641
|
+
parent: p,
|
|
639
642
|
class: "p-gui__vector2-dot"
|
|
640
643
|
});
|
|
641
|
-
x.style.left = this._mapLinear(a[
|
|
644
|
+
x.style.left = this._mapLinear(a[l], r, o, 0, p.clientWidth) + "px", x.style.top = this._mapLinear(g[d], n, s, p.clientHeight, 0) + "px", Object.defineProperty(a, l, {
|
|
642
645
|
set: (c) => {
|
|
643
|
-
this.propReferences[f] = c, x.style.left = this._mapLinear(c,
|
|
646
|
+
this.propReferences[f] = c, x.style.left = this._mapLinear(c, r, o, 0, p.clientWidth) + "px", b.textContent = String(c) + ", " + g[d];
|
|
644
647
|
},
|
|
645
648
|
get: () => this.propReferences[f]
|
|
646
649
|
}), Object.defineProperty(g, d, {
|
|
647
650
|
set: (c) => {
|
|
648
|
-
this.propReferences[u] = c, x.style.top = this._mapLinear(c, n, s,
|
|
651
|
+
this.propReferences[u] = c, x.style.top = this._mapLinear(c, n, s, p.clientHeight, 0) + "px", b.textContent = a[l] + ", " + String(c);
|
|
649
652
|
},
|
|
650
653
|
get: () => this.propReferences[u]
|
|
651
654
|
});
|
|
@@ -653,30 +656,30 @@ class h {
|
|
|
653
656
|
color(e = {}, t) {
|
|
654
657
|
if (typeof e != "object")
|
|
655
658
|
throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
|
|
656
|
-
let i = typeof e.name == "string" && e.name || " ",
|
|
657
|
-
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}".`) :
|
|
658
|
-
const
|
|
659
|
+
let i = typeof e.name == "string" && e.name || " ", r;
|
|
660
|
+
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");
|
|
661
|
+
const o = this._createElement({
|
|
659
662
|
el: "div",
|
|
660
663
|
class: "p-gui__color",
|
|
661
664
|
textContent: i
|
|
662
665
|
}), n = this._createElement({
|
|
663
|
-
parent:
|
|
666
|
+
parent: o,
|
|
664
667
|
el: "input",
|
|
665
668
|
class: "p-gui__color-picker",
|
|
666
669
|
type: "color",
|
|
667
|
-
value:
|
|
670
|
+
value: r
|
|
668
671
|
});
|
|
669
672
|
typeof t == "function" && n.addEventListener("input", () => {
|
|
670
673
|
t(n.value);
|
|
671
674
|
});
|
|
672
675
|
}
|
|
673
676
|
folder(e = {}) {
|
|
674
|
-
let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.name || "",
|
|
677
|
+
let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.name || "", r = e.color || null, o = e.maxHeight || null;
|
|
675
678
|
this.imageContainer = null;
|
|
676
679
|
let n = "p-gui__folder";
|
|
677
680
|
this.folders.length == 0 && (n += " p-gui__folder--first"), t && (n += " p-gui__folder--closed");
|
|
678
|
-
let s =
|
|
679
|
-
s +=
|
|
681
|
+
let s = r ? `background-color: ${r};` : "";
|
|
682
|
+
s += o ? `max-height: ${o}px;` : "";
|
|
680
683
|
let a = this._createElement({
|
|
681
684
|
class: n,
|
|
682
685
|
inline: s
|
|
@@ -689,21 +692,21 @@ class h {
|
|
|
689
692
|
},
|
|
690
693
|
parent: a
|
|
691
694
|
});
|
|
692
|
-
let
|
|
695
|
+
let l = new h({ isFolder: !0, folderOptions: {
|
|
693
696
|
wrapper: a
|
|
694
697
|
} });
|
|
695
|
-
return this.folders.push(
|
|
698
|
+
return this.folders.push(l), l;
|
|
696
699
|
}
|
|
697
700
|
_makeDraggable() {
|
|
698
701
|
var e = this;
|
|
699
|
-
this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup",
|
|
700
|
-
function t(
|
|
701
|
-
|
|
702
|
+
this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", r);
|
|
703
|
+
function t(o) {
|
|
704
|
+
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);
|
|
702
705
|
}
|
|
703
|
-
function i(
|
|
704
|
-
|
|
706
|
+
function i(o) {
|
|
707
|
+
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)";
|
|
705
708
|
}
|
|
706
|
-
function o
|
|
709
|
+
function r(o) {
|
|
707
710
|
document.removeEventListener("pointermove", i);
|
|
708
711
|
}
|
|
709
712
|
}
|
|
@@ -713,8 +716,8 @@ class h {
|
|
|
713
716
|
kill() {
|
|
714
717
|
this.wrapper.remove();
|
|
715
718
|
}
|
|
716
|
-
_mapLinear(e, t, i,
|
|
717
|
-
return
|
|
719
|
+
_mapLinear(e, t, i, r, o) {
|
|
720
|
+
return r + (e - t) * (o - r) / (i - t);
|
|
718
721
|
}
|
|
719
722
|
}
|
|
720
723
|
export {
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -221,16 +221,16 @@ export default class GUI {
|
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
button(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
button(options, callback) {
|
|
225
|
+
let name = '';
|
|
226
|
+
if (typeof options != 'string') {
|
|
227
|
+
if (typeof options == 'object' && options?.hasOwnProperty('name')) {
|
|
228
|
+
name = options.name == '' ? ' ' : options.name;
|
|
228
229
|
} else {
|
|
229
230
|
name = ' ';
|
|
230
231
|
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
name = ' ';
|
|
232
|
+
} else {
|
|
233
|
+
name = options == '' ? ' ' : options;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
this.imageContainer = null;
|
|
@@ -238,12 +238,30 @@ export default class GUI {
|
|
|
238
238
|
if (typeof callback != 'function') {
|
|
239
239
|
callback = () => {};
|
|
240
240
|
}
|
|
241
|
+
|
|
242
|
+
/* let create_options = {
|
|
243
|
+
class: 'p-gui__button',
|
|
244
|
+
textContent: name,
|
|
245
|
+
onclick: callback
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
if (typeof options.color == 'string') {
|
|
249
|
+
create_options.inline = 'background-color: ' + options.color;
|
|
250
|
+
}
|
|
241
251
|
|
|
242
|
-
this._createElement(
|
|
252
|
+
this._createElement(create_options); */
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
const el = this._createElement({
|
|
243
256
|
class: 'p-gui__button',
|
|
244
257
|
textContent: name,
|
|
245
258
|
onclick: callback
|
|
246
259
|
});
|
|
260
|
+
|
|
261
|
+
if (typeof options.color == 'string') {
|
|
262
|
+
el.style.setProperty('--color-accent', options.color);
|
|
263
|
+
el.style.setProperty('--color-accent-hover', options.hoverColor || options.color);
|
|
264
|
+
}
|
|
247
265
|
}
|
|
248
266
|
|
|
249
267
|
image(params = {}, callback) {
|