perfect-gui 4.4.0 → 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.
@@ -413,13 +413,13 @@ function w(y) {
413
413
  `
414
414
  );
415
415
  }
416
- class u {
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 u && (typeof u[u.instanceCounter] != "number" ? u[u.instanceCounter] = 0 : u[u.instanceCounter]++), this.instanceId = u[u.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();
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(/^.*[\\\/]/, ""), o;
512
- e.name == null ? o = r : o = typeof e.name == "string" && e.name || " ";
513
- const s = e.selected === !0, a = e.selectionBorder !== !1;
514
- let n = "";
515
- 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({
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 + "); " + n,
520
+ inline: "background-image: url(" + i + "); " + a,
521
521
  parent: this.imageContainer
522
522
  });
523
- s && a && l.classList.add("p-gui__image--selected"), this._createElement({
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: o
526
+ textContent: s
527
527
  }), typeof t == "function" && (l.onclick = () => {
528
- let g = this.imageContainer.querySelectorAll(".p-gui__image--selected");
529
- for (let d = 0; d < g.length; d++)
530
- g[d].classList.remove("p-gui__image--selected");
531
- a && l.classList.add("p-gui__image--selected"), t({ path: i, text: o });
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, 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, d = e.step || (g - l) / 100;
538
- if (n !== null)
539
- (a != null || s != null) && console.warn('[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.');
540
- else if (a != null && s != null) {
541
- if (typeof a != "string")
542
- throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof a}.`);
543
- if (typeof s != "object")
544
- throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof s}.`);
545
- i == " " && (i = a), o = this.propReferences.push(s[a]) - 1, r = !0;
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
- (a != null && s == null || a == null && s == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), n = (g - l) / 2;
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 h = this._createElement({
549
+ var c = this._createElement({
550
550
  class: "p-gui__slider",
551
551
  textContent: i
552
- }), f = this._createElement({
553
- parent: h,
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: g,
560
- step: d,
561
- value: r ? s[a] : n
559
+ max: u,
560
+ step: p,
561
+ value: r ? o[n] : a
562
562
  }
563
- }), _ = this._createElement({
564
- parent: h,
563
+ }), b = this._createElement({
564
+ parent: c,
565
565
  class: "p-gui__slider-value",
566
- textContent: String(r ? s[a] : n)
566
+ textContent: String(r ? o[n] : a)
567
567
  });
568
- f.addEventListener("input", () => {
569
- _.textContent = f.value, r && (s[a] = f.value), typeof t == "function" && t(parseFloat(f.value));
570
- }), r && Object.defineProperty(s, a, {
571
- set: (b) => {
572
- this.propReferences[o] = b, f.value = b, _.textContent = String(b);
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[o]
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 === !0;
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
- let o = this._createElement({
592
+ const l = this._createElement({
583
593
  class: "p-gui__switch",
584
- onclick: (a) => {
585
- let n = a.target.childNodes[1], l = !0;
586
- n.classList.contains("p-gui__switch-checkbox--active") && (l = !1), n.classList.toggle("p-gui__switch-checkbox--active"), typeof t == "function" && t(l);
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
- }), s = r ? " p-gui__switch-checkbox--active" : "";
590
- this._createElement({
591
- parent: o,
592
- class: "p-gui__switch-checkbox" + s
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, o = (() => {
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 s = this._createElement({
625
+ let o = this._createElement({
608
626
  class: "p-gui__list",
609
627
  textContent: i
610
- }), a = this._createElement({
611
- parent: s,
628
+ }), n = this._createElement({
629
+ parent: o,
612
630
  el: "select",
613
631
  class: "p-gui__list-dropdown",
614
- onchange: (n) => {
615
- t && t(n.target.value);
632
+ onchange: (a) => {
633
+ t && t(a.target.value);
616
634
  }
617
635
  });
618
- r && r.forEach((n, l) => {
619
- let g = this._createElement({
620
- parent: a,
636
+ r && r.forEach((a, l) => {
637
+ let u = this._createElement({
638
+ parent: n,
621
639
  el: "option",
622
640
  customAttributes: {
623
- value: n
641
+ value: a
624
642
  },
625
- textContent: n
643
+ textContent: a
626
644
  });
627
- o == l && g.setAttribute("selected", "");
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, 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, d = e.y.obj || e.y.object, h = e.y.prop || e.y.property, f = this.propReferences.push(d[h]) - 1;
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 _ = this._createElement({
659
+ const b = this._createElement({
642
660
  class: "p-gui__vector2",
643
661
  textContent: i
644
- }), b = this._createElement({
645
- parent: _,
662
+ }), _ = this._createElement({
663
+ parent: b,
646
664
  class: "p-gui__vector-value",
647
- textContent: n[l] + ", " + d[h]
648
- }), c = this._createElement({
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: (p) => {
653
- n[l] = parseFloat(this._mapLinear(p.offsetX, 0, c.clientWidth, r, o).toFixed(2)), d[h] = parseFloat(this._mapLinear(p.offsetY, 0, c.clientHeight, a, s).toFixed(2)), t && t(n[l], n[h]);
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
- c.addEventListener("pointerdown", (p) => {
675
+ d.addEventListener("pointerdown", (h) => {
658
676
  m = !0;
659
- }), c.addEventListener("pointerup", () => {
677
+ }), d.addEventListener("pointerup", () => {
660
678
  m = !1;
661
- }), c.addEventListener("pointermove", (p) => {
662
- m && (n[l] = parseFloat(this._mapLinear(p.offsetX, 0, c.clientWidth, r, o).toFixed(2)), d[h] = parseFloat(this._mapLinear(p.offsetY, 0, c.clientHeight, a, s).toFixed(2)), t && t(n[l], n[h]));
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: c,
682
+ parent: d,
665
683
  class: "p-gui__vector2-line p-gui__vector2-line-x"
666
684
  }), this._createElement({
667
- parent: c,
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: c,
689
+ parent: d,
672
690
  class: "p-gui__vector2-dot"
673
691
  });
674
- x.style.left = this._mapLinear(n[l], r, o, 0, c.clientWidth) + "px", x.style.top = this._mapLinear(d[h], s, a, c.clientHeight, 0) + "px", Object.defineProperty(n, l, {
675
- set: (p) => {
676
- this.propReferences[g] = p, x.style.left = this._mapLinear(p, r, o, 0, c.clientWidth) + "px", b.textContent = String(p) + ", " + d[h];
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[g]
679
- }), Object.defineProperty(d, h, {
680
- set: (p) => {
681
- this.propReferences[f] = p, x.style.top = this._mapLinear(p, s, a, c.clientHeight, 0) + "px", b.textContent = n[l] + ", " + String(p);
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[f]
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 o = this._createElement({
709
+ const s = this._createElement({
692
710
  el: "div",
693
711
  class: "p-gui__color",
694
712
  textContent: i
695
- }), s = this._createElement({
696
- parent: o,
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" && s.addEventListener("input", () => {
703
- t(s.value);
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, o = e.maxHeight || 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 s = "p-gui__folder";
710
- this.folders.length == 0 && (s += " p-gui__folder--first"), t && (s += " p-gui__folder--closed");
711
- let a = r ? `background-color: ${r};` : "";
712
- a += o ? `max-height: ${o}px;` : "";
713
- let n = this._createElement({
714
- class: s,
715
- inline: a
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: n
741
+ parent: a
724
742
  });
725
- let l = new u({ isFolder: !0, folderOptions: {
726
- wrapper: n
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(o) {
734
- 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);
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(o) {
737
- 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)";
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(o) {
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, o) {
750
- return r + (e - t) * (o - r) / (i - 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
- u as default
772
+ f as default
755
773
  };
@@ -1,4 +1,4 @@
1
- (function(_,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(_=typeof globalThis<"u"?globalThis:_||self,_["Perfect GUI"]=c())})(this,function(){"use strict";function _(w){return`
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(`${_(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} {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-gui",
3
- "version": "4.4.0",
3
+ "version": "4.4.1",
4
4
  "description": "Nice and simple GUI for JavaScript",
5
5
  "main": "src/index.js",
6
6
  "scripts": {