perfect-gui 4.10.0 → 4.11.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.
@@ -1,29 +1,30 @@
1
- class A {
1
+ class E {
2
2
  constructor(e = {}, t) {
3
3
  if (this.propReferences = [], typeof e != "object")
4
4
  throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
5
- let o = typeof e.name == "string" && e.name || " ";
5
+ let i = typeof e.name == "string" && e.name || " ";
6
6
  this.isObject = !1;
7
- let a = null;
7
+ let l = null;
8
8
  this.obj = e.obj, this.prop = e.prop;
9
- let l = typeof e.value == "number" ? e.value : null;
10
- if (this.min = e.min ?? 0, this.max = e.max ?? 1, this.step = e.step || (this.max - this.min) / 100, l !== null)
9
+ let a = typeof e.value == "number" ? e.value : null;
10
+ if (this.min = e.min ?? 0, this.max = e.max ?? 1, this.step = e.step || (this.max - this.min) / 100, a !== null)
11
11
  (this.prop != null || this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
12
12
  else if (this.prop != null && this.obj != null) {
13
13
  if (typeof this.prop != "string")
14
14
  throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof this.prop}.`);
15
15
  if (typeof this.obj != "object")
16
16
  throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof this.obj}.`);
17
- o == " " && (o = this.prop), a = this.propReferences.push(this.obj[this.prop]) - 1, this.isObject = !0;
17
+ i == " " && (i = this.prop), l = this.propReferences.push(this.obj[this.prop]) - 1, this.isObject = !0;
18
18
  } else
19
- (this.prop != null && this.obj == null || this.prop == null && this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), l = (this.max - this.min) / 2;
19
+ (this.prop != null && this.obj == null || this.prop == null && this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), a = (this.max - this.min) / 2;
20
+ const o = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
20
21
  this.imageContainer = null;
21
- const i = document.createElement("div");
22
- i.className = "p-gui__slider";
23
- const r = document.createElement("div");
24
- r.className = "p-gui__slider-name", r.textContent = o, i.append(r), this.ctrlDiv = document.createElement("div"), this.ctrlDiv.className = "p-gui__slider-ctrl", this.ctrlDiv.setAttribute("type", "range"), this.ctrlDiv.setAttribute("min", this.min), this.ctrlDiv.setAttribute("max", this.max), i.append(this.ctrlDiv);
25
22
  const n = document.createElement("div");
26
- return n.className = "p-gui__slider-bar", this.ctrlDiv.append(n), this.handle = document.createElement("div"), this.handle.className = "p-gui__slider-handle", this.ctrlDiv.append(this.handle), this.filling = document.createElement("div"), this.filling.className = "p-gui__slider-filling", n.append(this.filling), this.valueInput = document.createElement("input"), this.valueInput.className = "p-gui__slider-value", this.valueInput.value = this.isObject ? this.obj[this.prop] : l, i.append(this.valueInput), setTimeout(() => {
23
+ n.className = "p-gui__slider", o && n.setAttribute("title", o);
24
+ const r = document.createElement("div");
25
+ r.className = "p-gui__slider-name", r.textContent = i, n.append(r), this.ctrlDiv = document.createElement("div"), this.ctrlDiv.className = "p-gui__slider-ctrl", this.ctrlDiv.setAttribute("type", "range"), this.ctrlDiv.setAttribute("min", this.min), this.ctrlDiv.setAttribute("max", this.max), n.append(this.ctrlDiv);
26
+ const d = document.createElement("div");
27
+ return d.className = "p-gui__slider-bar", this.ctrlDiv.append(d), this.handle = document.createElement("div"), this.handle.className = "p-gui__slider-handle", this.ctrlDiv.append(this.handle), this.filling = document.createElement("div"), this.filling.className = "p-gui__slider-filling", d.append(this.filling), this.valueInput = document.createElement("input"), this.valueInput.className = "p-gui__slider-value", this.valueInput.value = this.isObject ? this.obj[this.prop] : a, n.append(this.valueInput), setTimeout(() => {
27
28
  const s = this.handle.offsetWidth;
28
29
  this.handle.position = this._mapLinear(this.valueInput.value, this.min, this.max, s / 2, 88 - s / 2), this.handle.style.transform = `translate(-50%, -50%) translateX(${this.handle.position}px)`, this.filling.style.width = `${this.handle.position}px`;
29
30
  }, 0), this.valueInput.addEventListener("change", () => {
@@ -36,38 +37,38 @@ class A {
36
37
  this.ctrlDiv.pointerDown && (this.ctrlDiv.pointerDelta = s.clientX - this.ctrlDiv.prevPosition, this._updateHandlePositionFromPointer(s));
37
38
  }), this.isObject && Object.defineProperty(this.obj, this.prop, {
38
39
  set: (s) => {
39
- this.propReferences[a] = s, this.valueInput.value = s, this._updateHandlePositionFromValue(), typeof t == "function" && t(parseFloat(this.valueInput.value));
40
+ this.propReferences[l] = s, this.valueInput.value = s, this._updateHandlePositionFromValue(), typeof t == "function" && t(parseFloat(this.valueInput.value));
40
41
  },
41
- get: () => this.propReferences[a]
42
- }), i;
42
+ get: () => this.propReferences[l]
43
+ }), n;
43
44
  }
44
45
  _updateHandlePositionFromPointer(e, t = !1) {
45
- const o = this.ctrlDiv.offsetWidth, a = this.handle.offsetWidth, l = e.clientX - this.ctrlDiv.prevPosition;
46
- let i;
47
- const r = parseFloat(this.valueInput.value);
48
- t ? i = e.offsetX : i = this.handle.position + l, i = Math.max(a / 2, Math.min(i, o - a / 2));
49
- let n = this.min + (this.max - this.min) * (i - a / 2) / (o - a);
50
- n > r ? n = this._quantizeFloor(n, this.step) : n = this._quantizeCeil(n, this.step), n = parseFloat(n.toFixed(9));
51
- const s = parseFloat((r + this.step).toFixed(9)), d = parseFloat((r - this.step).toFixed(9));
52
- if (n >= s || n <= d) {
53
- const f = this._countDecimals(this.step);
54
- n = n.toFixed(f), this.valueInput.value = n, this.ctrlDiv.prevPosition = e.clientX, this.handle.style.transform = `translate(-50%, -50%) translateX(${i}px)`, this.handle.position = i, this.filling.style.width = this.handle.position + "px", this._triggerCallbacks();
46
+ const i = this.ctrlDiv.offsetWidth, l = this.handle.offsetWidth, a = e.clientX - this.ctrlDiv.prevPosition;
47
+ let o;
48
+ const n = parseFloat(this.valueInput.value);
49
+ t ? o = e.offsetX : o = this.handle.position + a, o = Math.max(l / 2, Math.min(o, i - l / 2));
50
+ let r = this.min + (this.max - this.min) * (o - l / 2) / (i - l);
51
+ r > n ? r = this._quantizeFloor(r, this.step) : r = this._quantizeCeil(r, this.step), r = parseFloat(r.toFixed(9));
52
+ const d = parseFloat((n + this.step).toFixed(9)), s = parseFloat((n - this.step).toFixed(9));
53
+ if (r >= d || r <= s) {
54
+ const p = this._countDecimals(this.step);
55
+ r = r.toFixed(p), this.valueInput.value = r, this.ctrlDiv.prevPosition = e.clientX, this.handle.style.transform = `translate(-50%, -50%) translateX(${o}px)`, this.handle.position = o, this.filling.style.width = this.handle.position + "px", this._triggerCallbacks();
55
56
  }
56
57
  }
57
58
  _countDecimals(e) {
58
- const t = e.toString(), o = t.indexOf(".");
59
- return o === -1 ? 0 : t.length - o - 1;
59
+ const t = e.toString(), i = t.indexOf(".");
60
+ return i === -1 ? 0 : t.length - i - 1;
60
61
  }
61
62
  _updateHandlePositionFromValue() {
62
63
  const e = this.ctrlDiv.offsetWidth, t = this.handle.offsetWidth;
63
- let o = this._mapLinear(this.valueInput.value, this.min, this.max, t / 2, e - t / 2);
64
- o = Math.max(t / 2, Math.min(o, e - t / 2)), this.handle.style.transform = `translate(-50%, -50%) translateX(${o}px)`, this.handle.position = o, this.filling.style.width = this.handle.position + "px";
64
+ let i = this._mapLinear(this.valueInput.value, this.min, this.max, t / 2, e - t / 2);
65
+ i = Math.max(t / 2, Math.min(i, e - t / 2)), this.handle.style.transform = `translate(-50%, -50%) translateX(${i}px)`, this.handle.position = i, this.filling.style.width = this.handle.position + "px";
65
66
  }
66
67
  _triggerCallbacks() {
67
68
  this.isObject ? this.obj[this.prop] = parseFloat(this.valueInput.value) : typeof callback == "function" && callback(parseFloat(this.valueInput.value)), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
68
69
  }
69
- _mapLinear(e, t, o, a, l) {
70
- return a + (e - t) * (l - a) / (o - t);
70
+ _mapLinear(e, t, i, l, a) {
71
+ return l + (e - t) * (a - l) / (i - t);
71
72
  }
72
73
  _quantize(e, t) {
73
74
  return t * Math.round(e / t);
@@ -79,7 +80,7 @@ class A {
79
80
  return t * Math.floor(e / t);
80
81
  }
81
82
  }
82
- const E = (
83
+ const k = (
83
84
  /* css */
84
85
  `
85
86
  .p-gui__button {
@@ -233,7 +234,7 @@ const E = (
233
234
  background: rgba(255, 255, 255, .1);
234
235
  }
235
236
  `
236
- ), k = (
237
+ ), I = (
237
238
  /* css */
238
239
  `
239
240
  .p-gui__switch {
@@ -270,7 +271,7 @@ const E = (
270
271
  box-shadow: 0 0 7px #00ff89;
271
272
  }
272
273
  `
273
- ), I = (
274
+ ), C = (
274
275
  /* css */
275
276
  `
276
277
  .p-gui__color {
@@ -308,7 +309,7 @@ const E = (
308
309
  border: none;
309
310
  }
310
311
  `
311
- ), C = (
312
+ ), R = (
312
313
  /* css */
313
314
  `
314
315
  .p-gui__vector2 {
@@ -373,7 +374,7 @@ const E = (
373
374
  position: absolute;
374
375
  }
375
376
  `
376
- ), R = (
377
+ ), P = (
377
378
  /* css */
378
379
  `
379
380
  .p-gui__image-container {
@@ -399,7 +400,7 @@ const E = (
399
400
  }
400
401
 
401
402
  .p-gui__image:hover {
402
- color: var(--color-text-text);
403
+ color: var(--color-text-light);
403
404
  }
404
405
 
405
406
  .p-gui__image::after {
@@ -429,7 +430,7 @@ const E = (
429
430
 
430
431
  }
431
432
  `
432
- ), P = (
433
+ ), O = (
433
434
  /* css */
434
435
  `
435
436
  .p-gui__folder {
@@ -488,7 +489,7 @@ const E = (
488
489
  }
489
490
  `
490
491
  );
491
- function F(v) {
492
+ function $(w) {
492
493
  return (
493
494
  /* css */
494
495
  `
@@ -503,7 +504,7 @@ function F(v) {
503
504
  --color-accent-hover: #218fda;
504
505
  --transition: .1s linear;
505
506
 
506
- position: ${v};
507
+ position: ${w};
507
508
  top: 0;
508
509
  left: 0;
509
510
  transform: translate3d(0,0,0);
@@ -526,6 +527,11 @@ function F(v) {
526
527
  border-radius: var(--main-border-radius);
527
528
  border: 1px solid var(--color-border);
528
529
  line-height: normal;
530
+ transition: var(--transition) opacity;
531
+ }
532
+
533
+ .p-gui:hover {
534
+ opacity: 1!important;
529
535
  }
530
536
 
531
537
  .p-gui * {
@@ -616,38 +622,38 @@ function F(v) {
616
622
  border-color: rgba(255,255,255,.2);
617
623
  }
618
624
 
619
- ${E}
625
+ ${k}
620
626
 
621
- ${R}
627
+ ${P}
622
628
 
623
629
  ${j}
624
630
 
625
- ${k}
631
+ ${I}
626
632
 
627
633
  ${U}
628
634
 
629
- ${I}
630
-
631
635
  ${C}
632
636
 
633
- ${P}
637
+ ${R}
638
+
639
+ ${O}
634
640
  `
635
641
  );
636
642
  }
637
- class y {
643
+ class A {
638
644
  constructor(e = {}) {
639
645
  if (this.firstParent = this, 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) {
640
646
  this._folderConstructor(e.folderOptions);
641
647
  return;
642
648
  }
643
- typeof e.onUpdate == "function" && (this.onUpdate = e.onUpdate), 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), window.perfectGUI || (window.perfectGUI = {}), window.perfectGUI.instanceCounter == null ? window.perfectGUI.instanceCounter = 0 : window.perfectGUI.instanceCounter++, this.instanceId = window.perfectGUI.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(`${F(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();
649
+ typeof e.onUpdate == "function" && (this.onUpdate = e.onUpdate), this.name = e != null && typeof e.name == "string" ? e.name : "", this.backgroundColor = e.color || null, this.opacity = e.opacity || 1, 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), window.perfectGUI || (window.perfectGUI = {}), window.perfectGUI.instanceCounter == null ? window.perfectGUI.instanceCounter = 0 : window.perfectGUI.instanceCounter++, this.instanceId = window.perfectGUI.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();
644
650
  }
645
651
  _styleInstance() {
646
652
  let e = this._getScrollbarWidth(this.container);
647
653
  if (this.screenCorner.x == "left" ? this.xOffset = 0 : this.xOffset = this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
648
654
  let t = this.container.querySelectorAll(".p-gui");
649
- for (let o = 0; o < t.length; o++)
650
- this.screenCorner.y == t[o].dataset.cornerY && (this.screenCorner.x == "left" && t[o].dataset.cornerX == "left" ? this.xOffset += t[o].offsetWidth : this.screenCorner.x == "right" && t[o].dataset.cornerX == "right" && (this.xOffset -= t[o].offsetWidth));
655
+ for (let i = 0; i < t.length; i++)
656
+ 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));
651
657
  }
652
658
  this.yOffset = 0, this.position = {
653
659
  prevX: this.xOffset,
@@ -660,6 +666,7 @@ class y {
660
666
  transform: translate3d(${this.xOffset}px,${this.yOffset}px,0);
661
667
  ${this.screenCorner.y == "top" ? "" : "top: auto; bottom: 0;"}
662
668
  ${this.backgroundColor ? "background: " + this.backgroundColor + ";" : ""}
669
+ opacity: ${this.opacity};
663
670
  }`);
664
671
  }
665
672
  _folderConstructor(e) {
@@ -678,8 +685,8 @@ class y {
678
685
  let e = this._getScrollbarWidth(this.container);
679
686
  if (this.xOffset = this.screenCorner.x == "left" ? 0 : this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
680
687
  let t = this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);
681
- for (let o = 0; o < t.length && !(parseInt(t[o].id.replace("p-gui-", "")) > this.instanceId); o++)
682
- this.screenCorner.y == t[o].dataset.cornerY && (this.screenCorner.x == "left" && t[o].dataset.cornerX == "left" ? this.xOffset += t[o].offsetWidth : this.screenCorner.x == "right" && t[o].dataset.cornerX == "right" && (this.xOffset -= t[o].offsetWidth));
688
+ for (let i = 0; i < t.length && !(parseInt(t[i].id.replace("p-gui-", "")) > this.instanceId); i++)
689
+ 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));
683
690
  }
684
691
  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)`;
685
692
  }
@@ -692,248 +699,220 @@ class y {
692
699
  e.className = "p-gui__header-close", e.addEventListener("click", this.toggleClose.bind(this)), this.header.append(e);
693
700
  }
694
701
  button(e, t) {
695
- let o = "";
696
- typeof e != "string" ? typeof e == "object" && (e != null && e.hasOwnProperty("name")) ? o = e.name == "" ? " " : e.name : o = " " : o = e == "" ? " " : e, this.imageContainer = null;
702
+ let i = "";
703
+ typeof e != "string" ? typeof e == "object" && (e != null && e.hasOwnProperty("name")) ? i = e.name == "" ? " " : e.name : i = " " : i = e == "" ? " " : e;
704
+ const l = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
705
+ this.imageContainer = null;
697
706
  const a = document.createElement("div");
698
- a.className = "p-gui__button", a.textContent = o, a.addEventListener("click", () => {
707
+ a.className = "p-gui__button", a.textContent = i, l && a.setAttribute("title", l), a.addEventListener("click", () => {
699
708
  this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate(), t && t();
700
709
  }), this.wrapper.append(a), typeof e.color == "string" && (a.style.setProperty("--color-accent", e.color), a.style.setProperty("--color-accent-hover", e.hoverColor || e.color));
701
710
  }
702
711
  image(e = {}, t) {
703
712
  if (typeof e != "object")
704
713
  throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);
705
- let o;
714
+ let i;
706
715
  if (typeof e.path == "string")
707
- o = e.path;
716
+ i = e.path;
708
717
  else
709
718
  throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
710
- let a = o.replace(/^.*[\\\/]/, ""), l;
711
- e.name == null ? l = a : l = typeof e.name == "string" && e.name || " ";
712
- const i = e.selected === !0, r = e.selectionBorder !== !1;
713
- let n = "";
714
- 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 = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer));
719
+ let l = i.replace(/^.*[\\\/]/, ""), a;
720
+ e.name == null ? a = l : a = typeof e.name == "string" && e.name || " ";
721
+ const o = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? a : null, n = e.selected === !0, r = e.selectionBorder !== !1;
722
+ let d = "";
723
+ e.width && (typeof e.width == "number" && (e.width += "px"), d += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), d += `height: ${e.height}; `), this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer));
715
724
  const s = document.createElement("div");
716
- s.className = "p-gui__image", s.style = "background-image: url(" + o + "); " + n, this.imageContainer.append(s), i && r && s.classList.add("p-gui__image--selected");
717
- const d = document.createElement("div");
718
- return d.className = "p-gui__image-text", d.textContent = l, s.append(d), s.addEventListener("click", () => {
719
- let f = s.parentElement.querySelectorAll(".p-gui__image--selected");
720
- for (let c = 0; c < f.length; c++)
721
- f[c].classList.remove("p-gui__image--selected");
722
- r && s.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: o, text: l }), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
725
+ s.className = "p-gui__image", s.style = "background-image: url(" + i + "); " + d, o && s.setAttribute("title", o), this.imageContainer.append(s), n && r && s.classList.add("p-gui__image--selected");
726
+ const p = document.createElement("div");
727
+ return p.className = "p-gui__image-text", p.textContent = a, s.append(p), s.addEventListener("click", () => {
728
+ let c = s.parentElement.querySelectorAll(".p-gui__image--selected");
729
+ for (let f = 0; f < c.length; f++)
730
+ c[f].classList.remove("p-gui__image--selected");
731
+ r && s.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: i, text: a }), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
723
732
  }), s;
724
733
  }
725
734
  slider(e = {}, t) {
726
- const o = new A(e, t);
727
- this.wrapper.append(o);
728
- }
729
- sliderOld(e = {}, t) {
730
- if (typeof e != "object")
731
- throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
732
- let o = typeof e.name == "string" && e.name || " ", a = !1, l = null, i = e.obj, r = e.prop, n = typeof e.value == "number" ? e.value : null, s = e.min ?? 0, d = e.max ?? 1, f = e.step || (d - s) / 100;
733
- if (n !== null)
734
- (r != null || i != null) && console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
735
- else if (r != null && i != null) {
736
- if (typeof r != "string")
737
- throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof r}.`);
738
- if (typeof i != "object")
739
- throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof i}.`);
740
- o == " " && (o = r), l = this.propReferences.push(i[r]) - 1, a = !0;
741
- } else
742
- (r != null && i == null || r == null && i != null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), n = (d - s) / 2;
743
- this.imageContainer = null;
744
- const c = document.createElement("div");
745
- c.className = "p-gui__slider", this.wrapper.append(c);
746
- const u = document.createElement("div");
747
- u.className = "p-gui__slider-name", u.textContent = o, c.append(u);
748
- const p = document.createElement("input");
749
- p.className = "p-gui__slider-ctrl", p.setAttribute("type", "range"), p.setAttribute("min", s), p.setAttribute("max", d), p.setAttribute("step", f), p.setAttribute("value", a ? i[r] : n), c.append(p);
750
- const g = document.createElement("input");
751
- g.className = "p-gui__slider-value", g.value = String(a ? i[r] : n), c.append(g), g.addEventListener("change", () => {
752
- p.value = parseFloat(g.value);
753
- }), p.addEventListener("input", () => {
754
- g.value = p.value, a ? i[r] = parseFloat(p.value) : typeof t == "function" && t(parseFloat(p.value)), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
755
- }), a && Object.defineProperty(i, r, {
756
- set: (h) => {
757
- this.propReferences[l] = h, p.value = h, g.textContent = String(h), typeof t == "function" && t(parseFloat(p.value));
758
- },
759
- get: () => this.propReferences[l]
760
- });
735
+ const i = new E(e, t);
736
+ this.wrapper.append(i);
761
737
  }
762
738
  toggle(e = {}, t) {
763
739
  if (typeof e != "object")
764
740
  throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
765
- let o = typeof e.name == "string" && e.name || " ", a = !1, l = null, i = e.obj, r = e.prop, n = typeof e.value == "boolean" ? e.value : null;
766
- if (n !== null)
767
- (r != null || i != null) && console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
768
- else if (r != null && i != null) {
769
- if (typeof r != "string")
770
- throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof r}.`);
771
- if (typeof i != "object")
772
- throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof i}.`);
773
- o == " " && (o = r), l = this.propReferences.push(i[r]) - 1, a = !0;
741
+ let i = typeof e.name == "string" && e.name || " ", l = !1, a = null, o = e.obj, n = e.prop, r = typeof e.value == "boolean" ? e.value : null;
742
+ if (r !== null)
743
+ (n != null || o != null) && console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
744
+ else if (n != null && o != null) {
745
+ if (typeof n != "string")
746
+ throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof n}.`);
747
+ if (typeof o != "object")
748
+ throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof o}.`);
749
+ i == " " && (i = n), a = this.propReferences.push(o[n]) - 1, l = !0;
774
750
  } else
775
- (r != null && i == null || r == null && i == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
751
+ (n != null && o == null || n == null && o == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
752
+ const d = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
776
753
  this.imageContainer = null;
777
754
  const s = document.createElement("div");
778
- s.textContent = o, s.className = "p-gui__switch", this.wrapper.append(s), s.addEventListener("click", (c) => {
779
- const u = c.target.childNodes[1];
780
- let p = !0;
781
- u.classList.contains("p-gui__switch-checkbox--active") && (p = !1), u.classList.toggle("p-gui__switch-checkbox--active"), a ? i[r] = p : typeof t == "function" && t(p), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
755
+ s.textContent = i, s.className = "p-gui__switch", d && s.setAttribute("title", d), this.wrapper.append(s), s.addEventListener("click", (f) => {
756
+ const u = f.target.childNodes[1];
757
+ let g = !0;
758
+ u.classList.contains("p-gui__switch-checkbox--active") && (g = !1), u.classList.toggle("p-gui__switch-checkbox--active"), l ? o[n] = g : typeof t == "function" && t(g), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
782
759
  });
783
- let d = (() => a ? i[r] ? " p-gui__switch-checkbox--active" : "" : n ? " p-gui__switch-checkbox--active" : "")();
784
- const f = document.createElement("div");
785
- f.className = "p-gui__switch-checkbox" + d, s.append(f), a && Object.defineProperty(i, r, {
786
- set: (c) => {
787
- this.propReferences[l] = c, c ? f.classList.add("p-gui__switch-checkbox--active") : f.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(c);
760
+ let p = (() => l ? o[n] ? " p-gui__switch-checkbox--active" : "" : r ? " p-gui__switch-checkbox--active" : "")();
761
+ const c = document.createElement("div");
762
+ c.className = "p-gui__switch-checkbox" + p, s.append(c), l && Object.defineProperty(o, n, {
763
+ set: (f) => {
764
+ this.propReferences[a] = f, f ? c.classList.add("p-gui__switch-checkbox--active") : c.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(f);
788
765
  },
789
- get: () => this.propReferences[l]
766
+ get: () => this.propReferences[a]
790
767
  });
791
768
  }
792
769
  list(e = {}, t) {
793
770
  if (typeof e != "object")
794
771
  throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
795
- let o = typeof e.name == "string" ? e.name : " ", a = !1, l = null, i = e.obj, r = e.prop, n = Array.isArray(e.values) ? e.values : null, s, d = typeof n[0] != "string";
796
- if (t = typeof t == "function" ? t : null, e.value !== void 0 || e.value === void 0 && i === void 0 && r === void 0)
797
- (r != null || i != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'), s = (() => {
798
- if (!n)
772
+ let i = typeof e.name == "string" ? e.name : " ", l = !1, a = null, o = e.obj, n = e.prop, r = Array.isArray(e.values) ? e.values : null, d, s = typeof r[0] != "string";
773
+ const p = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
774
+ if (t = typeof t == "function" ? t : null, e.value !== void 0 || e.value === void 0 && o === void 0 && n === void 0)
775
+ (n != null || o != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'), d = (() => {
776
+ if (!r)
799
777
  return null;
800
778
  if (typeof e.value == "string")
801
- return n.indexOf(e.value);
779
+ return r.indexOf(e.value);
802
780
  if (typeof e.value == "number")
803
781
  return e.value;
804
782
  })();
805
- else if (r != null && i != null) {
806
- if (typeof r != "string")
807
- throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof r}.`);
808
- if (typeof i != "object")
809
- throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof i}.`);
810
- s = (() => {
811
- if (!n)
783
+ else if (n != null && o != null) {
784
+ if (typeof n != "string")
785
+ throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof n}.`);
786
+ if (typeof o != "object")
787
+ throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof o}.`);
788
+ d = (() => {
789
+ if (!r)
812
790
  return null;
813
- if (typeof i[r] == "string")
814
- return d ? n.find((u) => u.value === i[r]).value : n.indexOf(i[r]);
815
- if (typeof i[r] == "number")
816
- return d ? n.find((u) => u.value === i[r]).value : i[r];
817
- })(), l = this.propReferences.push(i[r]) - 1, a = !0;
791
+ if (typeof o[n] == "string")
792
+ return s ? r.find((u) => u.value === o[n]).value : r.indexOf(o[n]);
793
+ if (typeof o[n] == "number")
794
+ return s ? r.find((u) => u.value === o[n]).value : o[n];
795
+ })(), a = this.propReferences.push(o[n]) - 1, l = !0;
818
796
  } else
819
- (r != null && i == null || r == null && i == null) && console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');
797
+ (n != null && o == null || n == null && o == null) && console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');
820
798
  this.imageContainer = null;
821
- let f = document.createElement("div");
822
- f.className = "p-gui__list", f.textContent = o, this.wrapper.append(f);
823
- let c = document.createElement("select");
824
- f.append(c), c.className = "p-gui__list-dropdown", c.addEventListener("change", (u) => {
825
- a ? i[r] = u.target.value : t && t(u.target.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
826
- }), n && n.forEach((u, p) => {
827
- const g = d ? u.name : u, h = d ? u.value : u;
828
- let m = document.createElement("option");
829
- m.setAttribute("value", h), m.textContent = g, c.append(m), (!d && s == p || d && s == h) && m.setAttribute("selected", "");
830
- }), a && Object.defineProperty(i, r, {
799
+ let c = document.createElement("div");
800
+ c.className = "p-gui__list", c.textContent = i, p && c.setAttribute("title", p), this.wrapper.append(c);
801
+ let f = document.createElement("select");
802
+ c.append(f), f.className = "p-gui__list-dropdown", f.addEventListener("change", (u) => {
803
+ l ? o[n] = u.target.value : t && t(u.target.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
804
+ }), r && r.forEach((u, g) => {
805
+ const _ = s ? u.name : u, h = s ? u.value : u;
806
+ let x = document.createElement("option");
807
+ x.setAttribute("value", h), x.textContent = _, f.append(x), (!s && d == g || s && d == h) && x.setAttribute("selected", "");
808
+ }), l && Object.defineProperty(o, n, {
831
809
  set: (u) => {
832
- let p, g, h;
833
- d ? (h = n.find((x) => x.value == u), g = (h == null ? void 0 : h.value) || n[0].value, p = n.indexOf(h)) : (typeof u == "string" && (p = n.indexOf(u), g = u), typeof u == "number" && (p = u, g = n[u])), this.propReferences[l] = d ? g : u;
834
- const m = c.querySelector("[selected]");
835
- m && m.removeAttribute("selected"), c.querySelectorAll("option")[p].setAttribute("selected", ""), typeof t == "function" && t(d ? h : g, p);
810
+ let g, _, h;
811
+ s ? (h = r.find((v) => v.value == u), _ = (h == null ? void 0 : h.value) || r[0].value, g = r.indexOf(h)) : (typeof u == "string" && (g = r.indexOf(u), _ = u), typeof u == "number" && (g = u, _ = r[u])), this.propReferences[a] = s ? _ : u;
812
+ const x = f.querySelector("[selected]");
813
+ x && x.removeAttribute("selected"), f.querySelectorAll("option")[g].setAttribute("selected", ""), typeof t == "function" && t(s ? h : _, g);
836
814
  },
837
- get: () => this.propReferences[l]
815
+ get: () => this.propReferences[a]
838
816
  });
839
817
  }
840
818
  vector2(e = {}, t) {
841
819
  if (typeof e != "object")
842
820
  throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
843
- let o = typeof e.name == "string" && e.name || " ";
844
- const a = e.x.min ?? 0, l = e.x.max ?? 1, i = e.y.min ?? 0, r = e.y.max ?? 1, n = e.x.obj, s = e.x.prop, d = this.propReferences.push(n[s]) - 1, f = e.y.obj, c = e.y.prop, u = this.propReferences.push(f[c]) - 1;
821
+ let i = typeof e.name == "string" && e.name || " ";
822
+ const l = e.x.min ?? 0, a = e.x.max ?? 1, o = e.y.min ?? 0, n = e.y.max ?? 1, r = e.x.obj, d = e.x.prop, s = this.propReferences.push(r[d]) - 1, p = e.y.obj, c = e.y.prop, f = this.propReferences.push(p[c]) - 1, u = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
845
823
  t = typeof t == "function" ? t : null, this.imageContainer = null;
846
- const p = document.createElement("div");
847
- p.className = "p-gui__vector2", p.textContent = o, this.wrapper.append(p);
848
824
  const g = document.createElement("div");
849
- g.className = "p-gui__vector-value", g.textContent = n[s] + ", " + f[c], p.append(g);
825
+ g.className = "p-gui__vector2", g.textContent = i, u && g.setAttribute("title", u), this.wrapper.append(g);
826
+ const _ = document.createElement("div");
827
+ _.className = "p-gui__vector-value", _.textContent = r[d] + ", " + p[c], g.append(_);
850
828
  const h = document.createElement("div");
851
- h.className = "p-gui__vector2-area", p.append(h), h.addEventListener("click", (b) => {
852
- n[s] = parseFloat(this._mapLinear(b.offsetX, 0, h.clientWidth, a, l).toFixed(2)), f[c] = parseFloat(this._mapLinear(b.offsetY, 0, h.clientHeight, r, i).toFixed(2)), t && t(n[s], n[c]), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
829
+ h.className = "p-gui__vector2-area", g.append(h), h.addEventListener("click", (b) => {
830
+ r[d] = parseFloat(this._mapLinear(b.offsetX, 0, h.clientWidth, l, a).toFixed(2)), p[c] = parseFloat(this._mapLinear(b.offsetY, 0, h.clientHeight, n, o).toFixed(2)), t && t(r[d], r[c]), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
853
831
  });
854
- let m = !1;
832
+ let x = !1;
855
833
  h.addEventListener("pointerdown", (b) => {
856
- m = !0;
834
+ x = !0;
857
835
  }), h.addEventListener("pointerup", () => {
858
- m = !1;
836
+ x = !1;
859
837
  }), h.addEventListener("pointermove", (b) => {
860
- m && (n[s] = parseFloat(this._mapLinear(b.offsetX, 0, h.clientWidth, a, l).toFixed(2)), f[c] = parseFloat(this._mapLinear(b.offsetY, 0, h.clientHeight, r, i).toFixed(2)), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate(), t && t(n[s], n[c]));
838
+ x && (r[d] = parseFloat(this._mapLinear(b.offsetX, 0, h.clientWidth, l, a).toFixed(2)), p[c] = parseFloat(this._mapLinear(b.offsetY, 0, h.clientHeight, n, o).toFixed(2)), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate(), t && t(r[d], r[c]));
861
839
  });
862
- const x = document.createElement("div");
863
- x.className = "p-gui__vector2-line p-gui__vector2-line-x", h.append(x);
864
- const w = document.createElement("div");
865
- w.className = "p-gui__vector2-line p-gui__vector2-line-y", h.append(w);
866
- const _ = document.createElement("div");
867
- _.className = "p-gui__vector2-dot", h.append(_), _.style.left = this._mapLinear(n[s], a, l, 0, h.clientWidth) + "px", _.style.top = this._mapLinear(f[c], i, r, h.clientHeight, 0) + "px", Object.defineProperty(n, s, {
840
+ const v = document.createElement("div");
841
+ v.className = "p-gui__vector2-line p-gui__vector2-line-x", h.append(v);
842
+ const y = document.createElement("div");
843
+ y.className = "p-gui__vector2-line p-gui__vector2-line-y", h.append(y);
844
+ const m = document.createElement("div");
845
+ m.className = "p-gui__vector2-dot", h.append(m), m.style.left = this._mapLinear(r[d], l, a, 0, h.clientWidth) + "px", m.style.top = this._mapLinear(p[c], o, n, h.clientHeight, 0) + "px", Object.defineProperty(r, d, {
868
846
  set: (b) => {
869
- this.propReferences[d] = b, _.style.left = this._mapLinear(b, a, l, 0, h.clientWidth) + "px", g.textContent = String(b) + ", " + f[c];
847
+ this.propReferences[s] = b, m.style.left = this._mapLinear(b, l, a, 0, h.clientWidth) + "px", _.textContent = String(b) + ", " + p[c];
870
848
  },
871
- get: () => this.propReferences[d]
872
- }), Object.defineProperty(f, c, {
849
+ get: () => this.propReferences[s]
850
+ }), Object.defineProperty(p, c, {
873
851
  set: (b) => {
874
- this.propReferences[u] = b, _.style.top = this._mapLinear(b, i, r, h.clientHeight, 0) + "px", g.textContent = n[s] + ", " + String(b);
852
+ this.propReferences[f] = b, m.style.top = this._mapLinear(b, o, n, h.clientHeight, 0) + "px", _.textContent = r[d] + ", " + String(b);
875
853
  },
876
- get: () => this.propReferences[u]
854
+ get: () => this.propReferences[f]
877
855
  });
878
856
  }
879
857
  color(e = {}, t) {
880
858
  if (typeof e != "object")
881
859
  throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
882
- let o = typeof e.name == "string" && e.name || " ", a = !1, l = null, i = e.obj, r = e.prop, n;
883
- if (typeof e.value == "string" && (e.value.length != 7 || e.value[0] != "#" ? console.error(`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${e.value}".`) : n = e.value), n || (n = "#000000"), e.value !== void 0)
884
- (r != null || i != null) && console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
885
- else if (r != null && i != null) {
886
- if (typeof r != "string")
887
- throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof r}.`);
888
- if (typeof i != "object")
889
- throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof i}.`);
890
- o == " " && (o = r), l = this.propReferences.push(i[r]) - 1, a = !0;
860
+ let i = typeof e.name == "string" && e.name || " ", l = !1, a = null, o = e.obj, n = e.prop, r;
861
+ const d = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
862
+ if (typeof e.value == "string" && (e.value.length != 7 || e.value[0] != "#" ? console.error(`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${e.value}".`) : r = e.value), r || (r = "#000000"), e.value !== void 0)
863
+ (n != null || o != null) && console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
864
+ else if (n != null && o != null) {
865
+ if (typeof n != "string")
866
+ throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof n}.`);
867
+ if (typeof o != "object")
868
+ throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof o}.`);
869
+ i == " " && (i = n), a = this.propReferences.push(o[n]) - 1, l = !0;
891
870
  } else
892
- (r != null && i == null || r == null && i == null) && console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');
871
+ (n != null && o == null || n == null && o == null) && console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');
893
872
  this.imageContainer = null;
894
873
  const s = document.createElement("div");
895
- s.className = "p-gui__color", s.textContent = o, this.wrapper.append(s);
896
- const d = document.createElement("input");
897
- d.className = "p-gui__color-picker", d.setAttribute("type", "color"), d.value = n, s.append(d), typeof t == "function" && d.addEventListener("input", () => {
898
- a ? i[r] = d.value : typeof t == "function" && t(d.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
899
- }), a && Object.defineProperty(i, r, {
900
- set: (f) => {
901
- this.propReferences[l] = f, d.value = f, typeof t == "function" && t(f);
874
+ s.className = "p-gui__color", s.textContent = i, d && s.setAttribute("title", d), this.wrapper.append(s);
875
+ const p = document.createElement("input");
876
+ p.className = "p-gui__color-picker", p.setAttribute("type", "color"), p.value = r, s.append(p), typeof t == "function" && p.addEventListener("input", () => {
877
+ l ? o[n] = p.value : typeof t == "function" && t(p.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
878
+ }), l && Object.defineProperty(o, n, {
879
+ set: (c) => {
880
+ this.propReferences[a] = c, p.value = c, typeof t == "function" && t(c);
902
881
  },
903
- get: () => this.propReferences[l]
882
+ get: () => this.propReferences[a]
904
883
  });
905
884
  }
906
885
  folder(e = {}) {
907
- let t = typeof e.closed == "boolean" ? e.closed : !1, o = e.name || "", a = e.color || null, l = e.maxHeight || null;
886
+ let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.name || "", l = e.color || null, a = e.maxHeight || null;
908
887
  this.imageContainer = null;
909
- let i = "p-gui__folder";
910
- this.folders.length == 0 && (i += " p-gui__folder--first"), t && (i += " p-gui__folder--closed");
911
- let r = a ? `background-color: ${a};` : "";
912
- r += l ? `max-height: ${l}px;` : "";
913
- const n = document.createElement("div");
914
- n.className = i, n.style = r, this.wrapper.append(n);
915
- const s = document.createElement("div");
916
- s.innerHTML = `<span class="p-gui__folder-arrow"></span>${o}`, s.className = "p-gui__folder-header", n.append(s), s.addEventListener("click", () => {
917
- n.classList.toggle("p-gui__folder--closed");
888
+ let o = "p-gui__folder";
889
+ this.folders.length == 0 && (o += " p-gui__folder--first"), t && (o += " p-gui__folder--closed");
890
+ let n = l ? `background-color: ${l};` : "";
891
+ n += a ? `max-height: ${a}px;` : "";
892
+ const r = document.createElement("div");
893
+ r.className = o, r.style = n, this.wrapper.append(r);
894
+ const d = document.createElement("div");
895
+ d.innerHTML = `<span class="p-gui__folder-arrow"></span>${i}`, d.className = "p-gui__folder-header", r.append(d), d.addEventListener("click", () => {
896
+ r.classList.toggle("p-gui__folder--closed");
918
897
  });
919
- let d = new y({ isFolder: !0, folderOptions: {
920
- wrapper: n,
898
+ let s = new A({ isFolder: !0, folderOptions: {
899
+ wrapper: r,
921
900
  parent: this,
922
901
  firstParent: this.firstParent
923
902
  } });
924
- return this.folders.push(d), d;
903
+ return this.folders.push(s), s;
925
904
  }
926
905
  _makeDraggable() {
927
906
  var e = this;
928
- this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", a);
929
- function t(l) {
930
- l.preventDefault(), e.position.initX = e.position.x, e.position.initY = e.position.y, e.position.prevX = l.clientX, e.position.prevY = l.clientY, document.addEventListener("pointermove", o);
907
+ this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", l);
908
+ function t(a) {
909
+ a.preventDefault(), e.position.initX = e.position.x, e.position.initY = e.position.y, e.position.prevX = a.clientX, e.position.prevY = a.clientY, document.addEventListener("pointermove", i);
931
910
  }
932
- function o(l) {
933
- l.preventDefault(), e.hasBeenDragged || (e.hasBeenDragged = !0, e.wrapper.setAttribute("data-dragged", "true")), e.position.x = e.position.initX + l.clientX - e.position.prevX, e.position.y = e.position.initY + l.clientY - e.position.prevY, e.wrapper.style.transform = "translate3d(" + e.position.x + "px," + e.position.y + "px,0)";
911
+ function i(a) {
912
+ a.preventDefault(), e.hasBeenDragged || (e.hasBeenDragged = !0, e.wrapper.setAttribute("data-dragged", "true")), e.position.x = e.position.initX + a.clientX - e.position.prevX, e.position.y = e.position.initY + a.clientY - e.position.prevY, e.wrapper.style.transform = "translate3d(" + e.position.x + "px," + e.position.y + "px,0)";
934
913
  }
935
- function a(l) {
936
- document.removeEventListener("pointermove", o);
914
+ function l(a) {
915
+ document.removeEventListener("pointermove", i);
937
916
  }
938
917
  }
939
918
  toggleClose() {
@@ -942,10 +921,10 @@ class y {
942
921
  kill() {
943
922
  this.wrapper.remove();
944
923
  }
945
- _mapLinear(e, t, o, a, l) {
946
- return a + (e - t) * (l - a) / (o - t);
924
+ _mapLinear(e, t, i, l, a) {
925
+ return l + (e - t) * (a - l) / (i - t);
947
926
  }
948
927
  }
949
928
  export {
950
- y as default
929
+ A as default
951
930
  };
@@ -1,4 +1,4 @@
1
- (function(x,v){typeof exports=="object"&&typeof module<"u"?module.exports=v():typeof define=="function"&&define.amd?define(v):(x=typeof globalThis<"u"?globalThis:x||self,x["Perfect GUI"]=v())})(this,function(){"use strict";class x{constructor(e={},t){if(this.propReferences=[],typeof e!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ";this.isObject=!1;let a=null;this.obj=e.obj,this.prop=e.prop;let l=typeof e.value=="number"?e.value:null;if(this.min=e.min??0,this.max=e.max??1,this.step=e.step||(this.max-this.min)/100,l!==null)(this.prop!=null||this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(this.prop!=null&&this.obj!=null){if(typeof this.prop!="string")throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof this.prop}.`);if(typeof this.obj!="object")throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof this.obj}.`);o==" "&&(o=this.prop),a=this.propReferences.push(this.obj[this.prop])-1,this.isObject=!0}else(this.prop!=null&&this.obj==null||this.prop==null&&this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),l=(this.max-this.min)/2;this.imageContainer=null;const i=document.createElement("div");i.className="p-gui__slider";const r=document.createElement("div");r.className="p-gui__slider-name",r.textContent=o,i.append(r),this.ctrlDiv=document.createElement("div"),this.ctrlDiv.className="p-gui__slider-ctrl",this.ctrlDiv.setAttribute("type","range"),this.ctrlDiv.setAttribute("min",this.min),this.ctrlDiv.setAttribute("max",this.max),i.append(this.ctrlDiv);const n=document.createElement("div");return n.className="p-gui__slider-bar",this.ctrlDiv.append(n),this.handle=document.createElement("div"),this.handle.className="p-gui__slider-handle",this.ctrlDiv.append(this.handle),this.filling=document.createElement("div"),this.filling.className="p-gui__slider-filling",n.append(this.filling),this.valueInput=document.createElement("input"),this.valueInput.className="p-gui__slider-value",this.valueInput.value=this.isObject?this.obj[this.prop]:l,i.append(this.valueInput),setTimeout(()=>{const s=this.handle.offsetWidth;this.handle.position=this._mapLinear(this.valueInput.value,this.min,this.max,s/2,88-s/2),this.handle.style.transform=`translate(-50%, -50%) translateX(${this.handle.position}px)`,this.filling.style.width=`${this.handle.position}px`},0),this.valueInput.addEventListener("change",()=>{this._updateHandlePositionFromValue(),this._triggerCallbacks()}),this.ctrlDiv.addEventListener("pointerdown",s=>{this.ctrlDiv.pointerDown=!0,this.ctrlDiv.prevPosition=s.clientX,this._updateHandlePositionFromPointer(s,!0)}),window.addEventListener("pointerup",s=>{this.ctrlDiv.pointerDown=!1}),window.addEventListener("pointermove",s=>{this.ctrlDiv.pointerDown&&(this.ctrlDiv.pointerDelta=s.clientX-this.ctrlDiv.prevPosition,this._updateHandlePositionFromPointer(s))}),this.isObject&&Object.defineProperty(this.obj,this.prop,{set:s=>{this.propReferences[a]=s,this.valueInput.value=s,this._updateHandlePositionFromValue(),typeof t=="function"&&t(parseFloat(this.valueInput.value))},get:()=>this.propReferences[a]}),i}_updateHandlePositionFromPointer(e,t=!1){const o=this.ctrlDiv.offsetWidth,a=this.handle.offsetWidth,l=e.clientX-this.ctrlDiv.prevPosition;let i;const r=parseFloat(this.valueInput.value);t?i=e.offsetX:i=this.handle.position+l,i=Math.max(a/2,Math.min(i,o-a/2));let n=this.min+(this.max-this.min)*(i-a/2)/(o-a);n>r?n=this._quantizeFloor(n,this.step):n=this._quantizeCeil(n,this.step),n=parseFloat(n.toFixed(9));const s=parseFloat((r+this.step).toFixed(9)),d=parseFloat((r-this.step).toFixed(9));if(n>=s||n<=d){const f=this._countDecimals(this.step);n=n.toFixed(f),this.valueInput.value=n,this.ctrlDiv.prevPosition=e.clientX,this.handle.style.transform=`translate(-50%, -50%) translateX(${i}px)`,this.handle.position=i,this.filling.style.width=this.handle.position+"px",this._triggerCallbacks()}}_countDecimals(e){const t=e.toString(),o=t.indexOf(".");return o===-1?0:t.length-o-1}_updateHandlePositionFromValue(){const e=this.ctrlDiv.offsetWidth,t=this.handle.offsetWidth;let o=this._mapLinear(this.valueInput.value,this.min,this.max,t/2,e-t/2);o=Math.max(t/2,Math.min(o,e-t/2)),this.handle.style.transform=`translate(-50%, -50%) translateX(${o}px)`,this.handle.position=o,this.filling.style.width=this.handle.position+"px"}_triggerCallbacks(){this.isObject?this.obj[this.prop]=parseFloat(this.valueInput.value):typeof callback=="function"&&callback(parseFloat(this.valueInput.value)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}_mapLinear(e,t,o,a,l){return a+(e-t)*(l-a)/(o-t)}_quantize(e,t){return t*Math.round(e/t)}_quantizeCeil(e,t){return t*Math.ceil(e/t)}_quantizeFloor(e,t){return t*Math.floor(e/t)}}const v=`
1
+ (function(v,w){typeof exports=="object"&&typeof module<"u"?module.exports=w():typeof define=="function"&&define.amd?define(w):(v=typeof globalThis<"u"?globalThis:v||self,v["Perfect GUI"]=w())})(this,function(){"use strict";class v{constructor(e={},t){if(this.propReferences=[],typeof e!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ";this.isObject=!1;let l=null;this.obj=e.obj,this.prop=e.prop;let a=typeof e.value=="number"?e.value:null;if(this.min=e.min??0,this.max=e.max??1,this.step=e.step||(this.max-this.min)/100,a!==null)(this.prop!=null||this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(this.prop!=null&&this.obj!=null){if(typeof this.prop!="string")throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof this.prop}.`);if(typeof this.obj!="object")throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof this.obj}.`);i==" "&&(i=this.prop),l=this.propReferences.push(this.obj[this.prop])-1,this.isObject=!0}else(this.prop!=null&&this.obj==null||this.prop==null&&this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),a=(this.max-this.min)/2;const o=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;this.imageContainer=null;const n=document.createElement("div");n.className="p-gui__slider",o&&n.setAttribute("title",o);const r=document.createElement("div");r.className="p-gui__slider-name",r.textContent=i,n.append(r),this.ctrlDiv=document.createElement("div"),this.ctrlDiv.className="p-gui__slider-ctrl",this.ctrlDiv.setAttribute("type","range"),this.ctrlDiv.setAttribute("min",this.min),this.ctrlDiv.setAttribute("max",this.max),n.append(this.ctrlDiv);const d=document.createElement("div");return d.className="p-gui__slider-bar",this.ctrlDiv.append(d),this.handle=document.createElement("div"),this.handle.className="p-gui__slider-handle",this.ctrlDiv.append(this.handle),this.filling=document.createElement("div"),this.filling.className="p-gui__slider-filling",d.append(this.filling),this.valueInput=document.createElement("input"),this.valueInput.className="p-gui__slider-value",this.valueInput.value=this.isObject?this.obj[this.prop]:a,n.append(this.valueInput),setTimeout(()=>{const s=this.handle.offsetWidth;this.handle.position=this._mapLinear(this.valueInput.value,this.min,this.max,s/2,88-s/2),this.handle.style.transform=`translate(-50%, -50%) translateX(${this.handle.position}px)`,this.filling.style.width=`${this.handle.position}px`},0),this.valueInput.addEventListener("change",()=>{this._updateHandlePositionFromValue(),this._triggerCallbacks()}),this.ctrlDiv.addEventListener("pointerdown",s=>{this.ctrlDiv.pointerDown=!0,this.ctrlDiv.prevPosition=s.clientX,this._updateHandlePositionFromPointer(s,!0)}),window.addEventListener("pointerup",s=>{this.ctrlDiv.pointerDown=!1}),window.addEventListener("pointermove",s=>{this.ctrlDiv.pointerDown&&(this.ctrlDiv.pointerDelta=s.clientX-this.ctrlDiv.prevPosition,this._updateHandlePositionFromPointer(s))}),this.isObject&&Object.defineProperty(this.obj,this.prop,{set:s=>{this.propReferences[l]=s,this.valueInput.value=s,this._updateHandlePositionFromValue(),typeof t=="function"&&t(parseFloat(this.valueInput.value))},get:()=>this.propReferences[l]}),n}_updateHandlePositionFromPointer(e,t=!1){const i=this.ctrlDiv.offsetWidth,l=this.handle.offsetWidth,a=e.clientX-this.ctrlDiv.prevPosition;let o;const n=parseFloat(this.valueInput.value);t?o=e.offsetX:o=this.handle.position+a,o=Math.max(l/2,Math.min(o,i-l/2));let r=this.min+(this.max-this.min)*(o-l/2)/(i-l);r>n?r=this._quantizeFloor(r,this.step):r=this._quantizeCeil(r,this.step),r=parseFloat(r.toFixed(9));const d=parseFloat((n+this.step).toFixed(9)),s=parseFloat((n-this.step).toFixed(9));if(r>=d||r<=s){const p=this._countDecimals(this.step);r=r.toFixed(p),this.valueInput.value=r,this.ctrlDiv.prevPosition=e.clientX,this.handle.style.transform=`translate(-50%, -50%) translateX(${o}px)`,this.handle.position=o,this.filling.style.width=this.handle.position+"px",this._triggerCallbacks()}}_countDecimals(e){const t=e.toString(),i=t.indexOf(".");return i===-1?0:t.length-i-1}_updateHandlePositionFromValue(){const e=this.ctrlDiv.offsetWidth,t=this.handle.offsetWidth;let i=this._mapLinear(this.valueInput.value,this.min,this.max,t/2,e-t/2);i=Math.max(t/2,Math.min(i,e-t/2)),this.handle.style.transform=`translate(-50%, -50%) translateX(${i}px)`,this.handle.position=i,this.filling.style.width=this.handle.position+"px"}_triggerCallbacks(){this.isObject?this.obj[this.prop]=parseFloat(this.valueInput.value):typeof callback=="function"&&callback(parseFloat(this.valueInput.value)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}_mapLinear(e,t,i,l,a){return l+(e-t)*(a-l)/(i-t)}_quantize(e,t){return t*Math.round(e/t)}_quantizeCeil(e,t){return t*Math.ceil(e/t)}_quantizeFloor(e,t){return t*Math.floor(e/t)}}const w=`
2
2
  .p-gui__button {
3
3
  background: var(--color-accent);
4
4
  text-align: center;
@@ -143,7 +143,7 @@
143
143
  .p-gui__list-dropdown:hover {
144
144
  background: rgba(255, 255, 255, .1);
145
145
  }
146
- `,k=`
146
+ `,I=`
147
147
  .p-gui__switch {
148
148
  background: rgba(255, 255, 255, .05);
149
149
  color: var(--color-text-dark);
@@ -177,7 +177,7 @@
177
177
  background-color: #00ff89;
178
178
  box-shadow: 0 0 7px #00ff89;
179
179
  }
180
- `,I=`
180
+ `,C=`
181
181
  .p-gui__color {
182
182
  cursor: default;
183
183
  color: var(--color-text-dark);
@@ -212,7 +212,7 @@
212
212
  .p-gui__color-picker::-webkit-color-swatch {
213
213
  border: none;
214
214
  }
215
- `,C=`
215
+ `,R=`
216
216
  .p-gui__vector2 {
217
217
  background: transparent;
218
218
  aspect-ratio: 1;
@@ -274,7 +274,7 @@
274
274
  right: 7px;
275
275
  position: absolute;
276
276
  }
277
- `,R=`
277
+ `,P=`
278
278
  .p-gui__image-container {
279
279
  width: 100%;
280
280
  padding: 3px;
@@ -298,7 +298,7 @@
298
298
  }
299
299
 
300
300
  .p-gui__image:hover {
301
- color: var(--color-text-text);
301
+ color: var(--color-text-light);
302
302
  }
303
303
 
304
304
  .p-gui__image::after {
@@ -327,7 +327,7 @@
327
327
  text-overflow: ellipsis;
328
328
 
329
329
  }
330
- `,P=`
330
+ `,O=`
331
331
  .p-gui__folder {
332
332
  width: 100%;
333
333
  position: relative;
@@ -382,7 +382,7 @@
382
382
  .p-gui__folder--closed .p-gui__folder-arrow {
383
383
  transform: rotate(0deg);
384
384
  }
385
- `;function F(A){return`
385
+ `;function $(E){return`
386
386
  .p-gui {
387
387
  --main-border-radius: 5px;
388
388
  --color-bg: #121212;
@@ -394,7 +394,7 @@
394
394
  --color-accent-hover: #218fda;
395
395
  --transition: .1s linear;
396
396
 
397
- position: ${A};
397
+ position: ${E};
398
398
  top: 0;
399
399
  left: 0;
400
400
  transform: translate3d(0,0,0);
@@ -417,6 +417,11 @@
417
417
  border-radius: var(--main-border-radius);
418
418
  border: 1px solid var(--color-border);
419
419
  line-height: normal;
420
+ transition: var(--transition) opacity;
421
+ }
422
+
423
+ .p-gui:hover {
424
+ opacity: 1!important;
420
425
  }
421
426
 
422
427
  .p-gui * {
@@ -507,25 +512,26 @@
507
512
  border-color: rgba(255,255,255,.2);
508
513
  }
509
514
 
510
- ${v}
515
+ ${w}
511
516
 
512
- ${R}
517
+ ${P}
513
518
 
514
519
  ${j}
515
520
 
516
- ${k}
521
+ ${I}
517
522
 
518
523
  ${U}
519
524
 
520
- ${I}
521
-
522
525
  ${C}
523
526
 
524
- ${P}
525
- `}class y{constructor(e={}){if(this.firstParent=this,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}typeof e.onUpdate=="function"&&(this.onUpdate=e.onUpdate),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),window.perfectGUI||(window.perfectGUI={}),window.perfectGUI.instanceCounter==null?window.perfectGUI.instanceCounter=0:window.perfectGUI.instanceCounter++,this.instanceId=window.perfectGUI.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(`${F(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 o=0;o<t.length;o++)this.screenCorner.y==t[o].dataset.cornerY&&(this.screenCorner.x=="left"&&t[o].dataset.cornerX=="left"?this.xOffset+=t[o].offsetWidth:this.screenCorner.x=="right"&&t[o].dataset.cornerX=="right"&&(this.xOffset-=t[o].offsetWidth))}this.yOffset=0,this.position={prevX:this.xOffset,prevY:this.yOffset,x:this.xOffset,y:this.yOffset},this._addStyles(`#p-gui-${this.instanceId} {
527
+ ${R}
528
+
529
+ ${O}
530
+ `}class A{constructor(e={}){if(this.firstParent=this,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}typeof e.onUpdate=="function"&&(this.onUpdate=e.onUpdate),this.name=e!=null&&typeof e.name=="string"?e.name:"",this.backgroundColor=e.color||null,this.opacity=e.opacity||1,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),window.perfectGUI||(window.perfectGUI={}),window.perfectGUI.instanceCounter==null?window.perfectGUI.instanceCounter=0:window.perfectGUI.instanceCounter++,this.instanceId=window.perfectGUI.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} {
526
531
  width: ${this.wrapperWidth}px;
527
532
  max-height: ${this.maxHeight}px;
528
533
  transform: translate3d(${this.xOffset}px,${this.yOffset}px,0);
529
534
  ${this.screenCorner.y=="top"?"":"top: auto; bottom: 0;"}
530
535
  ${this.backgroundColor?"background: "+this.backgroundColor+";":""}
531
- }`)}_folderConstructor(e){this.wrapper=e.wrapper,this.isFolder=!0,this.parent=e.parent,this.firstParent=e.firstParent}_parseScreenCorner(e){let t={x:"right",y:"top"};return e==null||(typeof e!="string"&&console.error("[perfect-gui] Position must be a string."),e.includes("left")&&(t.x="left"),e.includes("bottom")&&(t.y="bottom")),t}_getScrollbarWidth(e){return e===document.body?window.innerWidth-document.documentElement.clientWidth:e.offsetWidth-e.clientWidth}_handleResize(){if(this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),this.initMaxHeight&&(this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.wrapper.style.maxHeight=this.maxHeight+"px",this.hasBeenDragged)return;let e=this._getScrollbarWidth(this.container);if(this.xOffset=this.screenCorner.x=="left"?0:this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);for(let o=0;o<t.length&&!(parseInt(t[o].id.replace("p-gui-",""))>this.instanceId);o++)this.screenCorner.y==t[o].dataset.cornerY&&(this.screenCorner.x=="left"&&t[o].dataset.cornerX=="left"?this.xOffset+=t[o].offsetWidth:this.screenCorner.x=="right"&&t[o].dataset.cornerX=="right"&&(this.xOffset-=t[o].offsetWidth))}this.position={prevX:this.xOffset,prevY:this.yOffset,x:this.xOffset,y:this.yOffset},this.wrapper.style.transform=`translate3d(${this.position.x}px, ${this.position.y}px, 0)`}_addStyles(e){this.stylesheet.innerHTML+=e}_addWrapper(){this.wrapper=document.createElement("div"),this.wrapper.id="p-gui-"+this.instanceId,this.wrapper.className="p-gui",this.container.append(this.wrapper),this.header=document.createElement("div"),this.header.className="p-gui__header",this.header.textContent=this.name,this.header.style=`${this.backgroundColor?"border-color: "+this.backgroundColor+";":""}`,this.wrapper.append(this.header);const e=document.createElement("div");e.className="p-gui__header-close",e.addEventListener("click",this.toggleClose.bind(this)),this.header.append(e)}button(e,t){let o="";typeof e!="string"?typeof e=="object"&&(e!=null&&e.hasOwnProperty("name"))?o=e.name==""?" ":e.name:o=" ":o=e==""?" ":e,this.imageContainer=null;const a=document.createElement("div");a.className="p-gui__button",a.textContent=o,a.addEventListener("click",()=>{this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t()}),this.wrapper.append(a),typeof e.color=="string"&&(a.style.setProperty("--color-accent",e.color),a.style.setProperty("--color-accent-hover",e.hoverColor||e.color))}image(e={},t){if(typeof e!="object")throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);let o;if(typeof e.path=="string")o=e.path;else throw typeof e.path==null?Error("[GUI] image() path must be provided."):Error("[GUI] image() path must be a string.");let a=o.replace(/^.*[\\\/]/,""),l;e.name==null?l=a:l=typeof e.name=="string"&&e.name||" ";const i=e.selected===!0,r=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=document.createElement("div"),this.imageContainer.className="p-gui__image-container",this.wrapper.append(this.imageContainer));const s=document.createElement("div");s.className="p-gui__image",s.style="background-image: url("+o+"); "+n,this.imageContainer.append(s),i&&r&&s.classList.add("p-gui__image--selected");const d=document.createElement("div");return d.className="p-gui__image-text",d.textContent=l,s.append(d),s.addEventListener("click",()=>{let f=s.parentElement.querySelectorAll(".p-gui__image--selected");for(let c=0;c<f.length;c++)f[c].classList.remove("p-gui__image--selected");r&&s.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:o,text:l}),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),s}slider(e={},t){const o=new x(e,t);this.wrapper.append(o)}sliderOld(e={},t){if(typeof e!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ",a=!1,l=null,i=e.obj,r=e.prop,n=typeof e.value=="number"?e.value:null,s=e.min??0,d=e.max??1,f=e.step||(d-s)/100;if(n!==null)(r!=null||i!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof i}.`);o==" "&&(o=r),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),n=(d-s)/2;this.imageContainer=null;const c=document.createElement("div");c.className="p-gui__slider",this.wrapper.append(c);const u=document.createElement("div");u.className="p-gui__slider-name",u.textContent=o,c.append(u);const p=document.createElement("input");p.className="p-gui__slider-ctrl",p.setAttribute("type","range"),p.setAttribute("min",s),p.setAttribute("max",d),p.setAttribute("step",f),p.setAttribute("value",a?i[r]:n),c.append(p);const g=document.createElement("input");g.className="p-gui__slider-value",g.value=String(a?i[r]:n),c.append(g),g.addEventListener("change",()=>{p.value=parseFloat(g.value)}),p.addEventListener("input",()=>{g.value=p.value,a?i[r]=parseFloat(p.value):typeof t=="function"&&t(parseFloat(p.value)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),a&&Object.defineProperty(i,r,{set:h=>{this.propReferences[l]=h,p.value=h,g.textContent=String(h),typeof t=="function"&&t(parseFloat(p.value))},get:()=>this.propReferences[l]})}toggle(e={},t){if(typeof e!="object")throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ",a=!1,l=null,i=e.obj,r=e.prop,n=typeof e.value=="boolean"?e.value:null;if(n!==null)(r!=null||i!=null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof i}.`);o==" "&&(o=r),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i==null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const s=document.createElement("div");s.textContent=o,s.className="p-gui__switch",this.wrapper.append(s),s.addEventListener("click",c=>{const u=c.target.childNodes[1];let p=!0;u.classList.contains("p-gui__switch-checkbox--active")&&(p=!1),u.classList.toggle("p-gui__switch-checkbox--active"),a?i[r]=p:typeof t=="function"&&t(p),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let d=(()=>a?i[r]?" p-gui__switch-checkbox--active":"":n?" p-gui__switch-checkbox--active":"")();const f=document.createElement("div");f.className="p-gui__switch-checkbox"+d,s.append(f),a&&Object.defineProperty(i,r,{set:c=>{this.propReferences[l]=c,c?f.classList.add("p-gui__switch-checkbox--active"):f.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(c)},get:()=>this.propReferences[l]})}list(e={},t){if(typeof e!="object")throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"?e.name:" ",a=!1,l=null,i=e.obj,r=e.prop,n=Array.isArray(e.values)?e.values:null,s,d=typeof n[0]!="string";if(t=typeof t=="function"?t:null,e.value!==void 0||e.value===void 0&&i===void 0&&r===void 0)(r!=null||i!=null)&&console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'),s=(()=>{if(!n)return null;if(typeof e.value=="string")return n.indexOf(e.value);if(typeof e.value=="number")return e.value})();else if(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof i}.`);s=(()=>{if(!n)return null;if(typeof i[r]=="string")return d?n.find(u=>u.value===i[r]).value:n.indexOf(i[r]);if(typeof i[r]=="number")return d?n.find(u=>u.value===i[r]).value:i[r]})(),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i==null)&&console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');this.imageContainer=null;let f=document.createElement("div");f.className="p-gui__list",f.textContent=o,this.wrapper.append(f);let c=document.createElement("select");f.append(c),c.className="p-gui__list-dropdown",c.addEventListener("change",u=>{a?i[r]=u.target.value:t&&t(u.target.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),n&&n.forEach((u,p)=>{const g=d?u.name:u,h=d?u.value:u;let m=document.createElement("option");m.setAttribute("value",h),m.textContent=g,c.append(m),(!d&&s==p||d&&s==h)&&m.setAttribute("selected","")}),a&&Object.defineProperty(i,r,{set:u=>{let p,g,h;d?(h=n.find(w=>w.value==u),g=(h==null?void 0:h.value)||n[0].value,p=n.indexOf(h)):(typeof u=="string"&&(p=n.indexOf(u),g=u),typeof u=="number"&&(p=u,g=n[u])),this.propReferences[l]=d?g:u;const m=c.querySelector("[selected]");m&&m.removeAttribute("selected"),c.querySelectorAll("option")[p].setAttribute("selected",""),typeof t=="function"&&t(d?h:g,p)},get:()=>this.propReferences[l]})}vector2(e={},t){if(typeof e!="object")throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ";const a=e.x.min??0,l=e.x.max??1,i=e.y.min??0,r=e.y.max??1,n=e.x.obj,s=e.x.prop,d=this.propReferences.push(n[s])-1,f=e.y.obj,c=e.y.prop,u=this.propReferences.push(f[c])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const p=document.createElement("div");p.className="p-gui__vector2",p.textContent=o,this.wrapper.append(p);const g=document.createElement("div");g.className="p-gui__vector-value",g.textContent=n[s]+", "+f[c],p.append(g);const h=document.createElement("div");h.className="p-gui__vector2-area",p.append(h),h.addEventListener("click",b=>{n[s]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,l).toFixed(2)),f[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,r,i).toFixed(2)),t&&t(n[s],n[c]),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let m=!1;h.addEventListener("pointerdown",b=>{m=!0}),h.addEventListener("pointerup",()=>{m=!1}),h.addEventListener("pointermove",b=>{m&&(n[s]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,l).toFixed(2)),f[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,r,i).toFixed(2)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t(n[s],n[c]))});const w=document.createElement("div");w.className="p-gui__vector2-line p-gui__vector2-line-x",h.append(w);const E=document.createElement("div");E.className="p-gui__vector2-line p-gui__vector2-line-y",h.append(E);const _=document.createElement("div");_.className="p-gui__vector2-dot",h.append(_),_.style.left=this._mapLinear(n[s],a,l,0,h.clientWidth)+"px",_.style.top=this._mapLinear(f[c],i,r,h.clientHeight,0)+"px",Object.defineProperty(n,s,{set:b=>{this.propReferences[d]=b,_.style.left=this._mapLinear(b,a,l,0,h.clientWidth)+"px",g.textContent=String(b)+", "+f[c]},get:()=>this.propReferences[d]}),Object.defineProperty(f,c,{set:b=>{this.propReferences[u]=b,_.style.top=this._mapLinear(b,i,r,h.clientHeight,0)+"px",g.textContent=n[s]+", "+String(b)},get:()=>this.propReferences[u]})}color(e={},t){if(typeof e!="object")throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ",a=!1,l=null,i=e.obj,r=e.prop,n;if(typeof e.value=="string"&&(e.value.length!=7||e.value[0]!="#"?console.error(`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${e.value}".`):n=e.value),n||(n="#000000"),e.value!==void 0)(r!=null||i!=null)&&console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof i}.`);o==" "&&(o=r),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i==null)&&console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const s=document.createElement("div");s.className="p-gui__color",s.textContent=o,this.wrapper.append(s);const d=document.createElement("input");d.className="p-gui__color-picker",d.setAttribute("type","color"),d.value=n,s.append(d),typeof t=="function"&&d.addEventListener("input",()=>{a?i[r]=d.value:typeof t=="function"&&t(d.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),a&&Object.defineProperty(i,r,{set:f=>{this.propReferences[l]=f,d.value=f,typeof t=="function"&&t(f)},get:()=>this.propReferences[l]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,o=e.name||"",a=e.color||null,l=e.maxHeight||null;this.imageContainer=null;let i="p-gui__folder";this.folders.length==0&&(i+=" p-gui__folder--first"),t&&(i+=" p-gui__folder--closed");let r=a?`background-color: ${a};`:"";r+=l?`max-height: ${l}px;`:"";const n=document.createElement("div");n.className=i,n.style=r,this.wrapper.append(n);const s=document.createElement("div");s.innerHTML=`<span class="p-gui__folder-arrow"></span>${o}`,s.className="p-gui__folder-header",n.append(s),s.addEventListener("click",()=>{n.classList.toggle("p-gui__folder--closed")});let d=new y({isFolder:!0,folderOptions:{wrapper:n,parent:this,firstParent:this.firstParent}});return this.folders.push(d),d}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",a);function t(l){l.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=l.clientX,e.position.prevY=l.clientY,document.addEventListener("pointermove",o)}function o(l){l.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+l.clientX-e.position.prevX,e.position.y=e.position.initY+l.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function a(l){document.removeEventListener("pointermove",o)}}toggleClose(){this.closed=!this.closed,this.closed?(this.previousInnerScroll=this.wrapper.scrollTop,this.wrapper.scrollTo(0,0)):this.wrapper.scrollTo(0,this.previousInnerScroll),this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,o,a,l){return a+(e-t)*(l-a)/(o-t)}}return y});
536
+ opacity: ${this.opacity};
537
+ }`)}_folderConstructor(e){this.wrapper=e.wrapper,this.isFolder=!0,this.parent=e.parent,this.firstParent=e.firstParent}_parseScreenCorner(e){let t={x:"right",y:"top"};return e==null||(typeof e!="string"&&console.error("[perfect-gui] Position must be a string."),e.includes("left")&&(t.x="left"),e.includes("bottom")&&(t.y="bottom")),t}_getScrollbarWidth(e){return e===document.body?window.innerWidth-document.documentElement.clientWidth:e.offsetWidth-e.clientWidth}_handleResize(){if(this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),this.initMaxHeight&&(this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.wrapper.style.maxHeight=this.maxHeight+"px",this.hasBeenDragged)return;let e=this._getScrollbarWidth(this.container);if(this.xOffset=this.screenCorner.x=="left"?0:this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);for(let i=0;i<t.length&&!(parseInt(t[i].id.replace("p-gui-",""))>this.instanceId);i++)this.screenCorner.y==t[i].dataset.cornerY&&(this.screenCorner.x=="left"&&t[i].dataset.cornerX=="left"?this.xOffset+=t[i].offsetWidth:this.screenCorner.x=="right"&&t[i].dataset.cornerX=="right"&&(this.xOffset-=t[i].offsetWidth))}this.position={prevX:this.xOffset,prevY:this.yOffset,x:this.xOffset,y:this.yOffset},this.wrapper.style.transform=`translate3d(${this.position.x}px, ${this.position.y}px, 0)`}_addStyles(e){this.stylesheet.innerHTML+=e}_addWrapper(){this.wrapper=document.createElement("div"),this.wrapper.id="p-gui-"+this.instanceId,this.wrapper.className="p-gui",this.container.append(this.wrapper),this.header=document.createElement("div"),this.header.className="p-gui__header",this.header.textContent=this.name,this.header.style=`${this.backgroundColor?"border-color: "+this.backgroundColor+";":""}`,this.wrapper.append(this.header);const e=document.createElement("div");e.className="p-gui__header-close",e.addEventListener("click",this.toggleClose.bind(this)),this.header.append(e)}button(e,t){let i="";typeof e!="string"?typeof e=="object"&&(e!=null&&e.hasOwnProperty("name"))?i=e.name==""?" ":e.name:i=" ":i=e==""?" ":e;const l=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;this.imageContainer=null;const a=document.createElement("div");a.className="p-gui__button",a.textContent=i,l&&a.setAttribute("title",l),a.addEventListener("click",()=>{this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t()}),this.wrapper.append(a),typeof e.color=="string"&&(a.style.setProperty("--color-accent",e.color),a.style.setProperty("--color-accent-hover",e.hoverColor||e.color))}image(e={},t){if(typeof e!="object")throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);let i;if(typeof e.path=="string")i=e.path;else throw typeof e.path==null?Error("[GUI] image() path must be provided."):Error("[GUI] image() path must be a string.");let l=i.replace(/^.*[\\\/]/,""),a;e.name==null?a=l:a=typeof e.name=="string"&&e.name||" ";const o=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?a:null,n=e.selected===!0,r=e.selectionBorder!==!1;let d="";e.width&&(typeof e.width=="number"&&(e.width+="px"),d+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),d+=`height: ${e.height}; `),this.imageContainer||(this.imageContainer=document.createElement("div"),this.imageContainer.className="p-gui__image-container",this.wrapper.append(this.imageContainer));const s=document.createElement("div");s.className="p-gui__image",s.style="background-image: url("+i+"); "+d,o&&s.setAttribute("title",o),this.imageContainer.append(s),n&&r&&s.classList.add("p-gui__image--selected");const p=document.createElement("div");return p.className="p-gui__image-text",p.textContent=a,s.append(p),s.addEventListener("click",()=>{let c=s.parentElement.querySelectorAll(".p-gui__image--selected");for(let f=0;f<c.length;f++)c[f].classList.remove("p-gui__image--selected");r&&s.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:i,text:a}),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),s}slider(e={},t){const i=new v(e,t);this.wrapper.append(i)}toggle(e={},t){if(typeof e!="object")throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",l=!1,a=null,o=e.obj,n=e.prop,r=typeof e.value=="boolean"?e.value:null;if(r!==null)(n!=null||o!=null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),a=this.propReferences.push(o[n])-1,l=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');const d=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;this.imageContainer=null;const s=document.createElement("div");s.textContent=i,s.className="p-gui__switch",d&&s.setAttribute("title",d),this.wrapper.append(s),s.addEventListener("click",f=>{const u=f.target.childNodes[1];let g=!0;u.classList.contains("p-gui__switch-checkbox--active")&&(g=!1),u.classList.toggle("p-gui__switch-checkbox--active"),l?o[n]=g:typeof t=="function"&&t(g),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let p=(()=>l?o[n]?" p-gui__switch-checkbox--active":"":r?" p-gui__switch-checkbox--active":"")();const c=document.createElement("div");c.className="p-gui__switch-checkbox"+p,s.append(c),l&&Object.defineProperty(o,n,{set:f=>{this.propReferences[a]=f,f?c.classList.add("p-gui__switch-checkbox--active"):c.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(f)},get:()=>this.propReferences[a]})}list(e={},t){if(typeof e!="object")throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"?e.name:" ",l=!1,a=null,o=e.obj,n=e.prop,r=Array.isArray(e.values)?e.values:null,d,s=typeof r[0]!="string";const p=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;if(t=typeof t=="function"?t:null,e.value!==void 0||e.value===void 0&&o===void 0&&n===void 0)(n!=null||o!=null)&&console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'),d=(()=>{if(!r)return null;if(typeof e.value=="string")return r.indexOf(e.value);if(typeof e.value=="number")return e.value})();else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof o}.`);d=(()=>{if(!r)return null;if(typeof o[n]=="string")return s?r.find(u=>u.value===o[n]).value:r.indexOf(o[n]);if(typeof o[n]=="number")return s?r.find(u=>u.value===o[n]).value:o[n]})(),a=this.propReferences.push(o[n])-1,l=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');this.imageContainer=null;let c=document.createElement("div");c.className="p-gui__list",c.textContent=i,p&&c.setAttribute("title",p),this.wrapper.append(c);let f=document.createElement("select");c.append(f),f.className="p-gui__list-dropdown",f.addEventListener("change",u=>{l?o[n]=u.target.value:t&&t(u.target.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),r&&r.forEach((u,g)=>{const _=s?u.name:u,h=s?u.value:u;let m=document.createElement("option");m.setAttribute("value",h),m.textContent=_,f.append(m),(!s&&d==g||s&&d==h)&&m.setAttribute("selected","")}),l&&Object.defineProperty(o,n,{set:u=>{let g,_,h;s?(h=r.find(y=>y.value==u),_=(h==null?void 0:h.value)||r[0].value,g=r.indexOf(h)):(typeof u=="string"&&(g=r.indexOf(u),_=u),typeof u=="number"&&(g=u,_=r[u])),this.propReferences[a]=s?_:u;const m=f.querySelector("[selected]");m&&m.removeAttribute("selected"),f.querySelectorAll("option")[g].setAttribute("selected",""),typeof t=="function"&&t(s?h:_,g)},get:()=>this.propReferences[a]})}vector2(e={},t){if(typeof e!="object")throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ";const l=e.x.min??0,a=e.x.max??1,o=e.y.min??0,n=e.y.max??1,r=e.x.obj,d=e.x.prop,s=this.propReferences.push(r[d])-1,p=e.y.obj,c=e.y.prop,f=this.propReferences.push(p[c])-1,u=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;t=typeof t=="function"?t:null,this.imageContainer=null;const g=document.createElement("div");g.className="p-gui__vector2",g.textContent=i,u&&g.setAttribute("title",u),this.wrapper.append(g);const _=document.createElement("div");_.className="p-gui__vector-value",_.textContent=r[d]+", "+p[c],g.append(_);const h=document.createElement("div");h.className="p-gui__vector2-area",g.append(h),h.addEventListener("click",b=>{r[d]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,l,a).toFixed(2)),p[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,n,o).toFixed(2)),t&&t(r[d],r[c]),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let m=!1;h.addEventListener("pointerdown",b=>{m=!0}),h.addEventListener("pointerup",()=>{m=!1}),h.addEventListener("pointermove",b=>{m&&(r[d]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,l,a).toFixed(2)),p[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,n,o).toFixed(2)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t(r[d],r[c]))});const y=document.createElement("div");y.className="p-gui__vector2-line p-gui__vector2-line-x",h.append(y);const k=document.createElement("div");k.className="p-gui__vector2-line p-gui__vector2-line-y",h.append(k);const x=document.createElement("div");x.className="p-gui__vector2-dot",h.append(x),x.style.left=this._mapLinear(r[d],l,a,0,h.clientWidth)+"px",x.style.top=this._mapLinear(p[c],o,n,h.clientHeight,0)+"px",Object.defineProperty(r,d,{set:b=>{this.propReferences[s]=b,x.style.left=this._mapLinear(b,l,a,0,h.clientWidth)+"px",_.textContent=String(b)+", "+p[c]},get:()=>this.propReferences[s]}),Object.defineProperty(p,c,{set:b=>{this.propReferences[f]=b,x.style.top=this._mapLinear(b,o,n,h.clientHeight,0)+"px",_.textContent=r[d]+", "+String(b)},get:()=>this.propReferences[f]})}color(e={},t){if(typeof e!="object")throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);let i=typeof e.name=="string"&&e.name||" ",l=!1,a=null,o=e.obj,n=e.prop,r;const d=typeof e.tooltip=="string"?e.tooltip:e.tooltip===!0?i:null;if(typeof e.value=="string"&&(e.value.length!=7||e.value[0]!="#"?console.error(`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${e.value}".`):r=e.value),r||(r="#000000"),e.value!==void 0)(n!=null||o!=null)&&console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(n!=null&&o!=null){if(typeof n!="string")throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof n}.`);if(typeof o!="object")throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof o}.`);i==" "&&(i=n),a=this.propReferences.push(o[n])-1,l=!0}else(n!=null&&o==null||n==null&&o==null)&&console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const s=document.createElement("div");s.className="p-gui__color",s.textContent=i,d&&s.setAttribute("title",d),this.wrapper.append(s);const p=document.createElement("input");p.className="p-gui__color-picker",p.setAttribute("type","color"),p.value=r,s.append(p),typeof t=="function"&&p.addEventListener("input",()=>{l?o[n]=p.value:typeof t=="function"&&t(p.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),l&&Object.defineProperty(o,n,{set:c=>{this.propReferences[a]=c,p.value=c,typeof t=="function"&&t(c)},get:()=>this.propReferences[a]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,i=e.name||"",l=e.color||null,a=e.maxHeight||null;this.imageContainer=null;let o="p-gui__folder";this.folders.length==0&&(o+=" p-gui__folder--first"),t&&(o+=" p-gui__folder--closed");let n=l?`background-color: ${l};`:"";n+=a?`max-height: ${a}px;`:"";const r=document.createElement("div");r.className=o,r.style=n,this.wrapper.append(r);const d=document.createElement("div");d.innerHTML=`<span class="p-gui__folder-arrow"></span>${i}`,d.className="p-gui__folder-header",r.append(d),d.addEventListener("click",()=>{r.classList.toggle("p-gui__folder--closed")});let s=new A({isFolder:!0,folderOptions:{wrapper:r,parent:this,firstParent:this.firstParent}});return this.folders.push(s),s}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",l);function t(a){a.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=a.clientX,e.position.prevY=a.clientY,document.addEventListener("pointermove",i)}function i(a){a.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+a.clientX-e.position.prevX,e.position.y=e.position.initY+a.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function l(a){document.removeEventListener("pointermove",i)}}toggleClose(){this.closed=!this.closed,this.closed?(this.previousInnerScroll=this.wrapper.scrollTop,this.wrapper.scrollTo(0,0)):this.wrapper.scrollTo(0,this.previousInnerScroll),this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,i,l,a){return l+(e-t)*(a-l)/(i-t)}}return A});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-gui",
3
- "version": "4.10.0",
3
+ "version": "4.11.1",
4
4
  "description": "GUI for JavaScript",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -45,12 +45,17 @@ export default class Slider {
45
45
 
46
46
  value = (this.max - this.min) / 2;
47
47
  }
48
+ const tooltip = (typeof params.tooltip === 'string') ? params.tooltip : (params.tooltip === true ? name : null);
48
49
 
49
50
  this.imageContainer = null;
50
51
 
51
52
  const container = document.createElement('div');
52
53
  container.className = 'p-gui__slider';
53
54
 
55
+ if (tooltip) {
56
+ container.setAttribute('title', tooltip);
57
+ }
58
+
54
59
  const slider_name = document.createElement('div');
55
60
  slider_name.className = 'p-gui__slider-name';
56
61
  slider_name.textContent = name;
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import Slider from './Slider';
1
+ import Slider from './components/Slider';
2
2
  import styles from './styles/styles';
3
3
 
4
4
  export default class GUI {
@@ -28,6 +28,7 @@ export default class GUI {
28
28
  this.name = (options != undefined && typeof options.name == "string") ? options.name : '';
29
29
 
30
30
  this.backgroundColor = options.color || null;
31
+ this.opacity = options.opacity || 1;
31
32
 
32
33
  if (this.container == document.body) {
33
34
  this.maxHeight = window.innerHeight;
@@ -116,6 +117,7 @@ export default class GUI {
116
117
  transform: translate3d(${this.xOffset}px,${this.yOffset}px,0);
117
118
  ${ this.screenCorner.y == 'top' ? '' : 'top: auto; bottom: 0;' }
118
119
  ${ this.backgroundColor ? 'background: ' + this.backgroundColor + ';' : '' }
120
+ opacity: ${this.opacity};
119
121
  }`);
120
122
  }
121
123
 
@@ -216,11 +218,16 @@ export default class GUI {
216
218
  name = options == '' ? ' ' : options;
217
219
  }
218
220
 
221
+ const tooltip = (typeof options.tooltip === 'string') ? options.tooltip : (options.tooltip === true ? name : null);
222
+
219
223
  this.imageContainer = null;
220
224
 
221
225
  const el = document.createElement('div');
222
226
  el.className = 'p-gui__button';
223
227
  el.textContent = name;
228
+ if ( tooltip ) {
229
+ el.setAttribute('title', tooltip);
230
+ }
224
231
  el.addEventListener('click', () => {
225
232
  if (this.onUpdate) {
226
233
  this.onUpdate();
@@ -262,6 +269,8 @@ export default class GUI {
262
269
  name = typeof params.name == 'string' ? params.name || ' ' : ' ';
263
270
  }
264
271
 
272
+ const tooltip = (typeof params.tooltip === 'string') ? params.tooltip : (params.tooltip === true ? name : null);
273
+
265
274
  const selected = params.selected === true;
266
275
  const selectionBorder = params.selectionBorder !== false;
267
276
 
@@ -291,6 +300,9 @@ export default class GUI {
291
300
  const image = document.createElement('div');
292
301
  image.className = 'p-gui__image';
293
302
  image.style = 'background-image: url(' + path + '); ' + inline_styles;
303
+ if ( tooltip ) {
304
+ image.setAttribute('title', tooltip);
305
+ }
294
306
  this.imageContainer.append(image);
295
307
 
296
308
  if (selected && selectionBorder) {
@@ -328,117 +340,6 @@ export default class GUI {
328
340
  const el = new Slider(params, callback);
329
341
  this.wrapper.append(el);
330
342
  }
331
-
332
- sliderOld (params = {}, callback) {
333
- if (typeof params != 'object') {
334
- throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof params}.`);
335
- }
336
-
337
- let name = typeof params.name == 'string' ? params.name || ' ' : ' ';
338
- let isObject = false;
339
- let propReferenceIndex = null;
340
- let obj = params.obj;
341
- let prop = params.prop;
342
- let value = typeof params.value == 'number' ? params.value : null;
343
- let min = params.min ?? 0;
344
- let max = params.max ?? 1;
345
- let step = params.step || (max - min) / 100;
346
-
347
- // callback mode
348
- if ( value !== null ) {
349
- if (prop != undefined || obj != undefined) {
350
- console.warn(`[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.`);
351
- }
352
- }
353
- // object-binding
354
- else if (prop != undefined && obj != undefined) {
355
- if (typeof prop != 'string') {
356
- throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof prop}.`);
357
- }
358
- if (typeof obj != 'object') {
359
- throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof obj}.`);
360
- }
361
-
362
- if (name == ' ') {
363
- name = prop;
364
- }
365
-
366
- propReferenceIndex = this.propReferences.push(obj[prop]) - 1;
367
- isObject = true;
368
- }
369
- else {
370
- if ((prop != undefined && obj == undefined) || (prop == undefined && obj != undefined)) {
371
- console.warn(`[GUI] slider() "obj" and "prop" parameters must be used together.`);
372
- }
373
-
374
- value = (max - min) / 2;
375
- }
376
-
377
- this.imageContainer = null;
378
-
379
- const container = document.createElement('div');
380
- container.className = 'p-gui__slider';
381
- this.wrapper.append(container);
382
-
383
- const slider_name = document.createElement('div');
384
- slider_name.className = 'p-gui__slider-name';
385
- slider_name.textContent = name;
386
- container.append(slider_name);
387
-
388
- const slider_ctrl = document.createElement('input');
389
- slider_ctrl.className = 'p-gui__slider-ctrl';
390
- slider_ctrl.setAttribute('type', 'range');
391
- slider_ctrl.setAttribute('min', min);
392
- slider_ctrl.setAttribute('max', max);
393
- slider_ctrl.setAttribute('step', step);
394
- slider_ctrl.setAttribute('value', isObject ? obj[prop] : value);
395
- container.append(slider_ctrl);
396
-
397
- const slider_value = document.createElement('input');
398
- slider_value.className = 'p-gui__slider-value';
399
- slider_value.value = isObject ? String(obj[prop]) : String(value);
400
- container.append(slider_value);
401
-
402
- slider_value.addEventListener('change', () => {
403
- slider_ctrl.value = parseFloat(slider_value.value);
404
- })
405
-
406
- slider_ctrl.addEventListener('input', () => {
407
- slider_value.value = slider_ctrl.value;
408
-
409
- if ( isObject ) {
410
- obj[prop] = parseFloat(slider_ctrl.value);
411
- }
412
- else {
413
- if (typeof callback == "function") {
414
- callback(parseFloat(slider_ctrl.value));
415
- }
416
- }
417
-
418
- if (this.onUpdate) {
419
- this.onUpdate();
420
- } else if (this.isFolder && this.firstParent.onUpdate) {
421
- this.firstParent.onUpdate();
422
- }
423
- });
424
-
425
- if ( isObject ) {
426
- Object.defineProperty( obj, prop, {
427
- set: val => {
428
- this.propReferences[propReferenceIndex] = val;
429
- slider_ctrl.value = val;
430
- slider_value.textContent = String( val );
431
-
432
- if (typeof callback == "function") {
433
- callback(parseFloat(slider_ctrl.value));
434
- }
435
- },
436
- get: () => {
437
- return this.propReferences[propReferenceIndex];
438
- }
439
- });
440
- }
441
- }
442
343
 
443
344
  toggle(params = {}, callback) {
444
345
  if (typeof params != 'object') {
@@ -481,11 +382,16 @@ export default class GUI {
481
382
  }
482
383
  }
483
384
 
385
+ const tooltip = (typeof params.tooltip === 'string') ? params.tooltip : (params.tooltip === true ? name : null);
386
+
484
387
  this.imageContainer = null;
485
388
 
486
389
  const container = document.createElement('div');
487
390
  container.textContent = name;
488
391
  container.className = 'p-gui__switch';
392
+ if ( tooltip ) {
393
+ container.setAttribute('title', tooltip);
394
+ }
489
395
  this.wrapper.append(container);
490
396
 
491
397
  container.addEventListener('click', (ev) => {
@@ -563,6 +469,7 @@ export default class GUI {
563
469
  let values = Array.isArray(params.values) ? params.values : null;
564
470
  let value;
565
471
  let objectValues = typeof values[0] == 'string' ? false : true;
472
+ const tooltip = (typeof params.tooltip === 'string') ? params.tooltip : (params.tooltip === true ? name : null);
566
473
 
567
474
  callback = typeof callback == 'function' ? callback : null;
568
475
 
@@ -632,6 +539,9 @@ export default class GUI {
632
539
  let container = document.createElement('div');
633
540
  container.className = 'p-gui__list';
634
541
  container.textContent = name;
542
+ if (tooltip) {
543
+ container.setAttribute('title', tooltip);
544
+ }
635
545
  this.wrapper.append(container);
636
546
 
637
547
  let select = document.createElement('select');
@@ -734,6 +644,8 @@ export default class GUI {
734
644
  const propY = params.y.prop;
735
645
  const propYReferenceIndex = this.propReferences.push(objectY[propY]) - 1;
736
646
 
647
+ const tooltip = (typeof params.tooltip === 'string') ? params.tooltip : (params.tooltip === true ? name : null);
648
+
737
649
  callback = typeof callback == 'function' ? callback : null;
738
650
 
739
651
  this.imageContainer = null;
@@ -741,6 +653,9 @@ export default class GUI {
741
653
  const container = document.createElement('div');
742
654
  container.className = 'p-gui__vector2';
743
655
  container.textContent = name;
656
+ if ( tooltip ) {
657
+ container.setAttribute('title', tooltip);
658
+ }
744
659
  this.wrapper.append(container);
745
660
 
746
661
  const vector_value = document.createElement('div');
@@ -840,6 +755,7 @@ export default class GUI {
840
755
  let obj = params.obj;
841
756
  let prop = params.prop;
842
757
  let value;
758
+ const tooltip = (typeof params.tooltip === 'string') ? params.tooltip : (params.tooltip === true ? name : null);
843
759
 
844
760
  if (typeof params.value == 'string') {
845
761
  if (params.value.length != 7 || params.value[0] != '#') {
@@ -885,6 +801,9 @@ export default class GUI {
885
801
  const container = document.createElement('div');
886
802
  container.className = 'p-gui__color';
887
803
  container.textContent = name;
804
+ if ( tooltip ) {
805
+ container.setAttribute('title', tooltip);
806
+ }
888
807
  this.wrapper.append(container);
889
808
 
890
809
  const colorpicker = document.createElement('input');
@@ -22,7 +22,7 @@ export default /* css */ `
22
22
  }
23
23
 
24
24
  .p-gui__image:hover {
25
- color: var(--color-text-text);
25
+ color: var(--color-text-light);
26
26
  }
27
27
 
28
28
  .p-gui__image::after {
@@ -48,6 +48,11 @@ export default function( position_type ) {
48
48
  border-radius: var(--main-border-radius);
49
49
  border: 1px solid var(--color-border);
50
50
  line-height: normal;
51
+ transition: var(--transition) opacity;
52
+ }
53
+
54
+ .p-gui:hover {
55
+ opacity: 1!important;
51
56
  }
52
57
 
53
58
  .p-gui * {