perfect-gui 4.11.0 → 4.11.2

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