perfect-gui 4.6.6 → 4.7.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,4 +1,4 @@
1
- function w(m) {
1
+ function A(y) {
2
2
  return (
3
3
  /* css */
4
4
  `
@@ -10,7 +10,7 @@ function w(m) {
10
10
  --color-accent: #1681ca;
11
11
  --color-accent-hover: #218fda;
12
12
 
13
- position: ${m};
13
+ position: ${y};
14
14
  top: 0;
15
15
  left: 0;
16
16
  transform: translate3d(0,0,0);
@@ -420,7 +420,7 @@ class b {
420
420
  this._folderConstructor(e.folderOptions);
421
421
  return;
422
422
  }
423
- this.name = e != null && typeof e.name == "string" ? e.name : "", this.backgroundColor = e.color || null, this.container == document.body ? this.maxHeight = window.innerHeight : this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight), e.maxHeight && (this.initMaxHeight = e.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), this.screenCorner = this._parseScreenCorner(e.position), this instanceof b && (typeof b[b.instanceCounter] != "number" ? b[b.instanceCounter] = 0 : b[b.instanceCounter]++), this.instanceId = b[b.instanceCounter], this.wrapperWidth = e.width || 290, this.stylesheet = document.createElement("style"), this.stylesheet.setAttribute("type", "text/css"), this.stylesheet.setAttribute("id", "lm-gui-stylesheet"), document.head.append(this.stylesheet), this.instanceId == 0 && this._addStyles(`${w(this.position_type)}`), this._styleInstance(), this._addWrapper(), this.wrapper.setAttribute("data-corner-x", this.screenCorner.x), this.wrapper.setAttribute("data-corner-y", this.screenCorner.y), e.autoRepositioning != !1 && window.addEventListener("resize", this._handleResize.bind(this)), this._handleResize(), this.hasBeenDragged = !1, e.draggable == !0 && this._makeDraggable(), this.closed = !1, e.closed && this.toggleClose();
423
+ this.name = e != null && typeof e.name == "string" ? e.name : "", this.backgroundColor = e.color || null, this.container == document.body ? this.maxHeight = window.innerHeight : this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight), e.maxHeight && (this.initMaxHeight = e.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), this.screenCorner = this._parseScreenCorner(e.position), this instanceof b && (typeof b[b.instanceCounter] != "number" ? b[b.instanceCounter] = 0 : b[b.instanceCounter]++), this.instanceId = b[b.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(`${A(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();
424
424
  }
425
425
  _styleInstance() {
426
426
  let e = this._getScrollbarWidth(this.container);
@@ -463,43 +463,20 @@ class b {
463
463
  }
464
464
  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)`;
465
465
  }
466
- _createElement(e) {
467
- e.el = e.el || "div";
468
- var t = document.createElement(e.el);
469
- if (e.id && (t.id = e.id), e.class && (t.className = e.class), e.inline && (t.style = e.inline), e.href && (t.href = e.href), e.onclick && (t.onclick = e.onclick), e.onchange && (t.onchange = e.onchange), e.textContent && (t.textContent = e.textContent), e.innerHTML && (t.innerHTML = e.innerHTML), e.type && (t.type = e.type), e.value && (t.value = e.value), e.customAttributes)
470
- for (var o in e.customAttributes)
471
- t.setAttribute(o, e.customAttributes[o]);
472
- return e.parent = e.parent ? e.parent : this.wrapper, e.parent.append(t), t;
473
- }
474
466
  _addStyles(e) {
475
467
  this.stylesheet.innerHTML += e;
476
468
  }
477
469
  _addWrapper() {
478
- this.wrapper = this._createElement({
479
- parent: this.container,
480
- id: "p-gui-" + this.instanceId,
481
- class: "p-gui"
482
- }), this.header = this._createElement({
483
- parent: this.wrapper,
484
- class: "p-gui__header",
485
- textContent: this.name,
486
- inline: `${this.backgroundColor ? "border-color: " + this.backgroundColor + ";" : ""}`
487
- }), this._createElement({
488
- parent: this.header,
489
- class: "p-gui__header-close",
490
- onclick: this.toggleClose.bind(this)
491
- });
470
+ 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);
471
+ const e = document.createElement("div");
472
+ e.className = "p-gui__header-close", e.addEventListener("click", this.toggleClose.bind(this)), this.header.append(e);
492
473
  }
493
474
  button(e, t) {
494
475
  let o = "";
495
476
  typeof e != "string" ? typeof e == "object" && (e != null && e.hasOwnProperty("name")) ? o = e.name == "" ? " " : e.name : o = " " : o = e == "" ? " " : e, this.imageContainer = null, typeof t != "function" && (t = () => {
496
477
  });
497
- const a = this._createElement({
498
- class: "p-gui__button",
499
- textContent: o,
500
- onclick: t
501
- });
502
- typeof e.color == "string" && (a.style.setProperty("--color-accent", e.color), a.style.setProperty("--color-accent-hover", e.hoverColor || e.color));
478
+ const a = document.createElement("div");
479
+ a.className = "p-gui__button", a.textContent = o, a.addEventListener("click", 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));
503
480
  }
504
481
  image(e = {}, t) {
505
482
  if (typeof e != "object")
@@ -509,114 +486,86 @@ class b {
509
486
  o = e.path;
510
487
  else
511
488
  throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
512
- let a = o.replace(/^.*[\\\/]/, ""), n;
513
- e.name == null ? n = a : n = typeof e.name == "string" && e.name || " ";
489
+ let a = o.replace(/^.*[\\\/]/, ""), d;
490
+ e.name == null ? d = a : d = typeof e.name == "string" && e.name || " ";
514
491
  const r = e.selected === !0, i = e.selectionBorder !== !1;
515
492
  let s = "";
516
- e.width && (typeof e.width == "number" && (e.width += "px"), s += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), s += `height: ${e.height}; `), this.imageContainer || (this.imageContainer = this._createElement({
517
- class: "p-gui__image-container"
518
- }));
519
- var l = this._createElement({
520
- class: "p-gui__image",
521
- inline: "background-image: url(" + o + "); " + s,
522
- parent: this.imageContainer
523
- });
524
- return r && i && l.classList.add("p-gui__image--selected"), this._createElement({
525
- parent: l,
526
- class: "p-gui__image-text",
527
- textContent: n
528
- }), l.onclick = () => {
529
- let c = l.parentElement.querySelectorAll(".p-gui__image--selected");
530
- for (let d = 0; d < c.length; d++)
531
- c[d].classList.remove("p-gui__image--selected");
532
- i && l.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: o, text: n });
533
- }, l;
493
+ e.width && (typeof e.width == "number" && (e.width += "px"), s += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), s += `height: ${e.height}; `), this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer));
494
+ const n = document.createElement("div");
495
+ n.className = "p-gui__image", n.style = "background-image: url(" + o + "); " + s, this.imageContainer.append(n), r && i && n.classList.add("p-gui__image--selected");
496
+ const l = document.createElement("div");
497
+ return l.className = "p-gui__image-text", l.textContent = d, n.append(l), n.addEventListener("click", () => {
498
+ let c = n.parentElement.querySelectorAll(".p-gui__image--selected");
499
+ for (let p = 0; p < c.length; p++)
500
+ c[p].classList.remove("p-gui__image--selected");
501
+ i && n.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: o, text: d });
502
+ }), n;
534
503
  }
535
504
  slider(e = {}, t) {
536
505
  if (typeof e != "object")
537
506
  throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
538
- let o = typeof e.name == "string" && e.name || " ", a = !1, n = null, r = e.obj || e.object, i = e.prop || e.property, s = typeof e.value == "number" ? e.value : null, l = e.min ?? 0, c = e.max ?? 1, d = e.step || (c - l) / 100;
507
+ let o = typeof e.name == "string" && e.name || " ", a = !1, d = null, r = e.obj, i = e.prop, s = typeof e.value == "number" ? e.value : null, n = e.min ?? 0, l = e.max ?? 1, c = e.step || (l - n) / 100;
539
508
  if (s !== null)
540
- (i != null || r != null) && console.warn('[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.');
509
+ (i != null || r != null) && console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
541
510
  else if (i != null && r != null) {
542
511
  if (typeof i != "string")
543
- throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);
512
+ throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof i}.`);
544
513
  if (typeof r != "object")
545
- throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);
546
- o == " " && (o = i), n = this.propReferences.push(r[i]) - 1, a = !0;
514
+ throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof r}.`);
515
+ o == " " && (o = i), d = this.propReferences.push(r[i]) - 1, a = !0;
547
516
  } else
548
- (i != null && r == null || i == null && r == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), s = (c - l) / 2;
517
+ (i != null && r == null || i == null && r == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), s = (l - n) / 2;
549
518
  this.imageContainer = null;
550
- var p = this._createElement({
551
- class: "p-gui__slider",
552
- textContent: o
553
- }), u = this._createElement({
554
- parent: p,
555
- el: "input",
556
- class: "p-gui__slider-ctrl",
557
- customAttributes: {
558
- type: "range",
559
- min: l,
560
- max: c,
561
- step: d,
562
- value: a ? r[i] : s
563
- }
564
- }), g = this._createElement({
565
- parent: p,
566
- class: "p-gui__slider-value",
567
- textContent: String(a ? r[i] : s)
568
- });
569
- u.addEventListener("input", () => {
570
- g.textContent = u.value, a ? r[i] = u.value : typeof t == "function" && t(parseFloat(u.value));
519
+ const p = document.createElement("div");
520
+ p.className = "p-gui__slider", p.textContent = o, this.wrapper.append(p);
521
+ const u = document.createElement("input");
522
+ u.className = "p-gui__slider-ctrl", u.setAttribute("type", "range"), u.setAttribute("min", n), u.setAttribute("max", l), u.setAttribute("step", c), u.setAttribute("value", a ? r[i] : s), p.append(u);
523
+ const h = document.createElement("div");
524
+ h.className = "p-gui__slider-value", h.textContent = String(a ? r[i] : s), p.append(h), u.addEventListener("input", () => {
525
+ h.textContent = u.value, a ? r[i] = u.value : typeof t == "function" && t(parseFloat(u.value));
571
526
  }), a && Object.defineProperty(r, i, {
572
- set: (_) => {
573
- this.propReferences[n] = _, u.value = _, g.textContent = String(_), typeof t == "function" && t(parseFloat(u.value));
527
+ set: (m) => {
528
+ this.propReferences[d] = m, u.value = m, h.textContent = String(m), typeof t == "function" && t(parseFloat(u.value));
574
529
  },
575
- get: () => this.propReferences[n]
530
+ get: () => this.propReferences[d]
576
531
  });
577
532
  }
578
533
  toggle(e = {}, t) {
579
534
  if (typeof e != "object")
580
535
  throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
581
- let o = typeof e.name == "string" && e.name || " ", a = !1, n = null, r = e.obj || e.object, i = e.prop || e.property, s = typeof e.value == "boolean" ? e.value : null;
536
+ let o = typeof e.name == "string" && e.name || " ", a = !1, d = null, r = e.obj, i = e.prop, s = typeof e.value == "boolean" ? e.value : null;
582
537
  if (s !== null)
583
- (i != null || r != null) && console.warn('[GUI] toggle() "obj" and "property" parameters are ignored when a "value" parameter is used.');
538
+ (i != null || r != null) && console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
584
539
  else if (i != null && r != null) {
585
540
  if (typeof i != "string")
586
- throw Error(`[GUI] toggle() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);
541
+ throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof i}.`);
587
542
  if (typeof r != "object")
588
- throw Error(`[GUI] toggle() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);
589
- o == " " && (o = i), n = this.propReferences.push(r[i]) - 1, a = !0;
543
+ throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof r}.`);
544
+ o == " " && (o = i), d = this.propReferences.push(r[i]) - 1, a = !0;
590
545
  } else
591
546
  (i != null && r == null || i == null && r == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
592
547
  this.imageContainer = null;
593
- const l = this._createElement({
594
- class: "p-gui__switch",
595
- onclick: (p) => {
596
- const u = p.target.childNodes[1];
597
- let g = !0;
598
- u.classList.contains("p-gui__switch-checkbox--active") && (g = !1), u.classList.toggle("p-gui__switch-checkbox--active"), a ? r[i] = g : typeof t == "function" && t(g);
599
- },
600
- textContent: o
548
+ const n = document.createElement("div");
549
+ n.textContent = o, n.className = "p-gui__switch", this.wrapper.append(n), n.addEventListener("click", (p) => {
550
+ const u = p.target.childNodes[1];
551
+ let h = !0;
552
+ u.classList.contains("p-gui__switch-checkbox--active") && (h = !1), u.classList.toggle("p-gui__switch-checkbox--active"), a ? r[i] = h : typeof t == "function" && t(h);
601
553
  });
602
- let c = (() => a ? r[i] ? " p-gui__switch-checkbox--active" : "" : s ? " p-gui__switch-checkbox--active" : "")();
603
- const d = this._createElement({
604
- parent: l,
605
- class: "p-gui__switch-checkbox" + c
606
- });
607
- a && Object.defineProperty(r, i, {
554
+ let l = (() => a ? r[i] ? " p-gui__switch-checkbox--active" : "" : s ? " p-gui__switch-checkbox--active" : "")();
555
+ const c = document.createElement("div");
556
+ c.className = "p-gui__switch-checkbox" + l, n.append(c), a && Object.defineProperty(r, i, {
608
557
  set: (p) => {
609
- this.propReferences[n] = p, p ? d.classList.add("p-gui__switch-checkbox--active") : d.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(p);
558
+ this.propReferences[d] = p, p ? c.classList.add("p-gui__switch-checkbox--active") : c.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(p);
610
559
  },
611
- get: () => this.propReferences[n]
560
+ get: () => this.propReferences[d]
612
561
  });
613
562
  }
614
563
  list(e = {}, t) {
615
564
  if (typeof e != "object")
616
565
  throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
617
- let o = typeof e.name == "string" ? e.name : " ", a = !1, n = null, r = e.obj || e.object, i = e.prop || e.property, s = Array.isArray(e.values) ? e.values : null, l;
566
+ let o = typeof e.name == "string" ? e.name : " ", a = !1, d = null, r = e.obj, i = e.prop, s = Array.isArray(e.values) ? e.values : null, n;
618
567
  if (t = typeof t == "function" ? t : null, e.value !== void 0 || e.value === void 0 && r === void 0 && i === void 0)
619
- (i != null || r != null) && console.warn('[GUI] list() "obj" and "property" parameters are ignored when a "value" parameter is used.'), l = (() => {
568
+ (i != null || r != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'), n = (() => {
620
569
  if (!s)
621
570
  return null;
622
571
  if (typeof e.value == "string")
@@ -626,46 +575,33 @@ class b {
626
575
  })();
627
576
  else if (i != null && r != null) {
628
577
  if (typeof i != "string")
629
- throw Error(`[GUI] list() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);
578
+ throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof i}.`);
630
579
  if (typeof r != "object")
631
- throw Error(`[GUI] list() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);
632
- l = (() => {
580
+ throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof r}.`);
581
+ n = (() => {
633
582
  if (!s)
634
583
  return null;
635
584
  if (typeof r[i] == "string")
636
585
  return s.indexOf(r[i]);
637
586
  if (typeof r[i] == "number")
638
587
  return r[i];
639
- })(), n = this.propReferences.push(r[i]) - 1, a = !0;
588
+ })(), d = this.propReferences.push(r[i]) - 1, a = !0;
640
589
  } else
641
590
  (i != null && r == null || i == null && r == null) && console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');
642
591
  this.imageContainer = null;
643
- let c = this._createElement({
644
- class: "p-gui__list",
645
- textContent: o
646
- }), d = this._createElement({
647
- parent: c,
648
- el: "select",
649
- class: "p-gui__list-dropdown",
650
- onchange: (p) => {
651
- a ? r[i] = p.target.value : t && t(p.target.value);
652
- }
653
- });
654
- s && s.forEach((p, u) => {
655
- let g = this._createElement({
656
- parent: d,
657
- el: "option",
658
- customAttributes: {
659
- value: p
660
- },
661
- textContent: p
662
- });
663
- l == u && g.setAttribute("selected", "");
592
+ let l = document.createElement("div");
593
+ l.className = "p-gui__list", l.textContent = o, this.wrapper.append(l);
594
+ let c = document.createElement("select");
595
+ l.append(c), c.className = "p-gui__list-dropdown", c.addEventListener("change", (p) => {
596
+ a ? r[i] = p.target.value : t && t(p.target.value);
597
+ }), s && s.forEach((p, u) => {
598
+ let h = document.createElement("option");
599
+ h.setAttribute("value", p), h.textContent = p, c.append(h), n == u && h.setAttribute("selected", "");
664
600
  }), a && Object.defineProperty(r, i, {
665
601
  set: (p) => {
666
- typeof p == "string" && (l = s.indexOf(p)), typeof p == "number" && (l = p), this.propReferences[n] = l, d.querySelector("[selected]").removeAttribute("selected"), d.querySelectorAll("option")[l].setAttribute("selected", ""), typeof t == "function" && t(l);
602
+ typeof p == "string" && (n = s.indexOf(p)), typeof p == "number" && (n = p), this.propReferences[d] = n, c.querySelector("[selected]").removeAttribute("selected"), c.querySelectorAll("option")[n].setAttribute("selected", ""), typeof t == "function" && t(n);
667
603
  },
668
- get: () => this.propReferences[n]
604
+ get: () => this.propReferences[d]
669
605
  });
670
606
  }
671
607
  options(e, t) {
@@ -677,49 +613,37 @@ class b {
677
613
  if (typeof e != "object")
678
614
  throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
679
615
  let o = typeof e.name == "string" && e.name || " ";
680
- const a = e.x.min ?? 0, n = e.x.max ?? 1, r = e.y.min ?? 0, i = e.y.max ?? 1, s = e.x.obj || e.x.object, l = e.x.prop || e.x.property, c = this.propReferences.push(s[l]) - 1, d = e.y.obj || e.y.object, p = e.y.prop || e.y.property, u = this.propReferences.push(d[p]) - 1;
616
+ const a = e.x.min ?? 0, d = e.x.max ?? 1, r = e.y.min ?? 0, i = e.y.max ?? 1, s = e.x.obj, n = e.x.prop, l = this.propReferences.push(s[n]) - 1, c = e.y.obj, p = e.y.prop, u = this.propReferences.push(c[p]) - 1;
681
617
  t = typeof t == "function" ? t : null, this.imageContainer = null;
682
- const g = this._createElement({
683
- class: "p-gui__vector2",
684
- textContent: o
685
- }), _ = this._createElement({
686
- parent: g,
687
- class: "p-gui__vector-value",
688
- textContent: s[l] + ", " + d[p]
689
- }), h = this._createElement({
690
- parent: g,
691
- el: "div",
692
- class: "p-gui__vector2-area",
693
- onclick: (f) => {
694
- s[l] = parseFloat(this._mapLinear(f.offsetX, 0, h.clientWidth, a, n).toFixed(2)), d[p] = parseFloat(this._mapLinear(f.offsetY, 0, h.clientHeight, i, r).toFixed(2)), t && t(s[l], s[p]);
695
- }
696
- });
697
- let y = !1;
698
- h.addEventListener("pointerdown", (f) => {
699
- y = !0;
700
- }), h.addEventListener("pointerup", () => {
701
- y = !1;
702
- }), h.addEventListener("pointermove", (f) => {
703
- y && (s[l] = parseFloat(this._mapLinear(f.offsetX, 0, h.clientWidth, a, n).toFixed(2)), d[p] = parseFloat(this._mapLinear(f.offsetY, 0, h.clientHeight, i, r).toFixed(2)), t && t(s[l], s[p]));
704
- }), this._createElement({
705
- parent: h,
706
- class: "p-gui__vector2-line p-gui__vector2-line-x"
707
- }), this._createElement({
708
- parent: h,
709
- class: "p-gui__vector2-line p-gui__vector2-line-y"
618
+ const h = document.createElement("div");
619
+ h.className = "p-gui__vector2", h.textContent = o, this.wrapper.append(h);
620
+ const m = document.createElement("div");
621
+ m.className = "p-gui__vector-value", m.textContent = s[n] + ", " + c[p], h.append(m);
622
+ const f = document.createElement("div");
623
+ f.className = "p-gui__vector2-area", h.append(f), f.addEventListener("click", (g) => {
624
+ s[n] = parseFloat(this._mapLinear(g.offsetX, 0, f.clientWidth, a, d).toFixed(2)), c[p] = parseFloat(this._mapLinear(g.offsetY, 0, f.clientHeight, i, r).toFixed(2)), t && t(s[n], s[p]);
710
625
  });
711
- const x = this._createElement({
712
- parent: h,
713
- class: "p-gui__vector2-dot"
626
+ let _ = !1;
627
+ f.addEventListener("pointerdown", (g) => {
628
+ _ = !0;
629
+ }), f.addEventListener("pointerup", () => {
630
+ _ = !1;
631
+ }), f.addEventListener("pointermove", (g) => {
632
+ _ && (s[n] = parseFloat(this._mapLinear(g.offsetX, 0, f.clientWidth, a, d).toFixed(2)), c[p] = parseFloat(this._mapLinear(g.offsetY, 0, f.clientHeight, i, r).toFixed(2)), t && t(s[n], s[p]));
714
633
  });
715
- x.style.left = this._mapLinear(s[l], a, n, 0, h.clientWidth) + "px", x.style.top = this._mapLinear(d[p], r, i, h.clientHeight, 0) + "px", Object.defineProperty(s, l, {
716
- set: (f) => {
717
- this.propReferences[c] = f, x.style.left = this._mapLinear(f, a, n, 0, h.clientWidth) + "px", _.textContent = String(f) + ", " + d[p];
634
+ const w = document.createElement("div");
635
+ w.className = "p-gui__vector2-line p-gui__vector2-line-x", f.append(w);
636
+ const v = document.createElement("div");
637
+ v.className = "p-gui__vector2-line p-gui__vector2-line-y", f.append(v);
638
+ const x = document.createElement("div");
639
+ x.className = "p-gui__vector2-dot", f.append(x), x.style.left = this._mapLinear(s[n], a, d, 0, f.clientWidth) + "px", x.style.top = this._mapLinear(c[p], r, i, f.clientHeight, 0) + "px", Object.defineProperty(s, n, {
640
+ set: (g) => {
641
+ this.propReferences[l] = g, x.style.left = this._mapLinear(g, a, d, 0, f.clientWidth) + "px", m.textContent = String(g) + ", " + c[p];
718
642
  },
719
- get: () => this.propReferences[c]
720
- }), Object.defineProperty(d, p, {
721
- set: (f) => {
722
- this.propReferences[u] = f, x.style.top = this._mapLinear(f, r, i, h.clientHeight, 0) + "px", _.textContent = s[l] + ", " + String(f);
643
+ get: () => this.propReferences[l]
644
+ }), Object.defineProperty(c, p, {
645
+ set: (g) => {
646
+ this.propReferences[u] = g, x.style.top = this._mapLinear(g, r, i, f.clientHeight, 0) + "px", m.textContent = s[n] + ", " + String(g);
723
647
  },
724
648
  get: () => this.propReferences[u]
725
649
  });
@@ -727,56 +651,42 @@ class b {
727
651
  color(e = {}, t) {
728
652
  if (typeof e != "object")
729
653
  throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
730
- let o = typeof e.name == "string" && e.name || " ", a = !1, n = null, r = e.obj || e.object, i = e.prop || e.property, s;
654
+ let o = typeof e.name == "string" && e.name || " ", a = !1, d = null, r = e.obj, i = e.prop, s;
731
655
  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}".`) : s = e.value), s || (s = "#000000"), e.value !== void 0)
732
- (i != null || r != null) && console.warn('[GUI] color() "obj" and "property" parameters are ignored when a "value" parameter is used.');
656
+ (i != null || r != null) && console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
733
657
  else if (i != null && r != null) {
734
658
  if (typeof i != "string")
735
- throw Error(`[GUI] color() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);
659
+ throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof i}.`);
736
660
  if (typeof r != "object")
737
- throw Error(`[GUI] color() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);
738
- o == " " && (o = i), n = this.propReferences.push(r[i]) - 1, a = !0;
661
+ throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof r}.`);
662
+ o == " " && (o = i), d = this.propReferences.push(r[i]) - 1, a = !0;
739
663
  } else
740
664
  (i != null && r == null || i == null && r == null) && console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');
741
665
  this.imageContainer = null;
742
- const l = this._createElement({
743
- el: "div",
744
- class: "p-gui__color",
745
- textContent: o
746
- }), c = this._createElement({
747
- parent: l,
748
- el: "input",
749
- class: "p-gui__color-picker",
750
- type: "color",
751
- value: s
752
- });
753
- typeof t == "function" && c.addEventListener("input", () => {
754
- a ? r[i] = c.value : typeof t == "function" && t(c.value);
666
+ const n = document.createElement("div");
667
+ n.className = "p-gui__color", n.textContent = o, this.wrapper.append(n);
668
+ const l = document.createElement("input");
669
+ l.className = "p-gui__color-picker", l.setAttribute("type", "color"), l.value = s, n.append(l), typeof t == "function" && l.addEventListener("input", () => {
670
+ a ? r[i] = l.value : typeof t == "function" && t(l.value);
755
671
  }), a && Object.defineProperty(r, i, {
756
- set: (d) => {
757
- this.propReferences[n] = d, c.value = d, typeof t == "function" && t(d);
672
+ set: (c) => {
673
+ this.propReferences[d] = c, l.value = c, typeof t == "function" && t(c);
758
674
  },
759
- get: () => this.propReferences[n]
675
+ get: () => this.propReferences[d]
760
676
  });
761
677
  }
762
678
  folder(e = {}) {
763
- let t = typeof e.closed == "boolean" ? e.closed : !1, o = e.name || "", a = e.color || null, n = e.maxHeight || null;
679
+ let t = typeof e.closed == "boolean" ? e.closed : !1, o = e.name || "", a = e.color || null, d = e.maxHeight || null;
764
680
  this.imageContainer = null;
765
681
  let r = "p-gui__folder";
766
682
  this.folders.length == 0 && (r += " p-gui__folder--first"), t && (r += " p-gui__folder--closed");
767
683
  let i = a ? `background-color: ${a};` : "";
768
- i += n ? `max-height: ${n}px;` : "";
769
- let s = this._createElement({
770
- class: r,
771
- inline: i
772
- });
773
- this._createElement({
774
- innerHTML: `<span class="p-gui__folder-arrow"></span>${o}`,
775
- class: "p-gui__folder-header",
776
- onclick: function() {
777
- this.parentNode.classList.toggle("p-gui__folder--closed");
778
- },
779
- parent: s
684
+ i += d ? `max-height: ${d}px;` : "";
685
+ const s = document.createElement("div");
686
+ s.className = r, s.style = i, this.wrapper.append(s);
687
+ const n = document.createElement("div");
688
+ n.innerHTML = `<span class="p-gui__folder-arrow"></span>${o}`, n.className = "p-gui__folder-header", s.append(n), n.addEventListener("click", () => {
689
+ s.classList.toggle("p-gui__folder--closed");
780
690
  });
781
691
  let l = new b({ isFolder: !0, folderOptions: {
782
692
  wrapper: s
@@ -786,13 +696,13 @@ class b {
786
696
  _makeDraggable() {
787
697
  var e = this;
788
698
  this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", a);
789
- function t(n) {
790
- n.preventDefault(), e.position.initX = e.position.x, e.position.initY = e.position.y, e.position.prevX = n.clientX, e.position.prevY = n.clientY, document.addEventListener("pointermove", o);
699
+ function t(d) {
700
+ d.preventDefault(), e.position.initX = e.position.x, e.position.initY = e.position.y, e.position.prevX = d.clientX, e.position.prevY = d.clientY, document.addEventListener("pointermove", o);
791
701
  }
792
- function o(n) {
793
- n.preventDefault(), e.hasBeenDragged || (e.hasBeenDragged = !0, e.wrapper.setAttribute("data-dragged", "true")), e.position.x = e.position.initX + n.clientX - e.position.prevX, e.position.y = e.position.initY + n.clientY - e.position.prevY, e.wrapper.style.transform = "translate3d(" + e.position.x + "px," + e.position.y + "px,0)";
702
+ function o(d) {
703
+ d.preventDefault(), e.hasBeenDragged || (e.hasBeenDragged = !0, e.wrapper.setAttribute("data-dragged", "true")), e.position.x = e.position.initX + d.clientX - e.position.prevX, e.position.y = e.position.initY + d.clientY - e.position.prevY, e.wrapper.style.transform = "translate3d(" + e.position.x + "px," + e.position.y + "px,0)";
794
704
  }
795
- function a(n) {
705
+ function a(d) {
796
706
  document.removeEventListener("pointermove", o);
797
707
  }
798
708
  }
@@ -802,8 +712,8 @@ class b {
802
712
  kill() {
803
713
  this.wrapper.remove();
804
714
  }
805
- _mapLinear(e, t, o, a, n) {
806
- return a + (e - t) * (n - a) / (o - t);
715
+ _mapLinear(e, t, o, a, d) {
716
+ return a + (e - t) * (d - a) / (o - t);
807
717
  }
808
718
  }
809
719
  export {
@@ -1,4 +1,4 @@
1
- (function(x,u){typeof exports=="object"&&typeof module<"u"?module.exports=u():typeof define=="function"&&define.amd?define(u):(x=typeof globalThis<"u"?globalThis:x||self,x["Perfect GUI"]=u())})(this,function(){"use strict";function x(w){return`
1
+ (function(_,g){typeof exports=="object"&&typeof module<"u"?module.exports=g():typeof define=="function"&&define.amd?define(g):(_=typeof globalThis<"u"?globalThis:_||self,_["Perfect GUI"]=g())})(this,function(){"use strict";function _(A){return`
2
2
  .p-gui {
3
3
  --main-border-radius: 5px;
4
4
  --color-bg: #121212;
@@ -7,7 +7,7 @@
7
7
  --color-accent: #1681ca;
8
8
  --color-accent-hover: #218fda;
9
9
 
10
- position: ${w};
10
+ position: ${A};
11
11
  top: 0;
12
12
  left: 0;
13
13
  transform: translate3d(0,0,0);
@@ -408,10 +408,10 @@
408
408
  .p-gui__folder--closed .p-gui__folder-arrow {
409
409
  transform: rotate(0deg);
410
410
  }
411
- `}class u{constructor(e={}){if(e.container?(this.container=typeof e.container=="string"?document.querySelector(e.container):e.container,this.position_type="absolute"):(this.container=document.body,this.position_type="fixed"),this.propReferences=[],this.folders=[],e.isFolder){this._folderConstructor(e.folderOptions);return}this.name=e!=null&&typeof e.name=="string"?e.name:"",this.backgroundColor=e.color||null,this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),e.maxHeight&&(this.initMaxHeight=e.maxHeight,this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.screenCorner=this._parseScreenCorner(e.position),this instanceof u&&(typeof u[u.instanceCounter]!="number"?u[u.instanceCounter]=0:u[u.instanceCounter]++),this.instanceId=u[u.instanceCounter],this.wrapperWidth=e.width||290,this.stylesheet=document.createElement("style"),this.stylesheet.setAttribute("type","text/css"),this.stylesheet.setAttribute("id","lm-gui-stylesheet"),document.head.append(this.stylesheet),this.instanceId==0&&this._addStyles(`${x(this.position_type)}`),this._styleInstance(),this._addWrapper(),this.wrapper.setAttribute("data-corner-x",this.screenCorner.x),this.wrapper.setAttribute("data-corner-y",this.screenCorner.y),e.autoRepositioning!=!1&&window.addEventListener("resize",this._handleResize.bind(this)),this._handleResize(),this.hasBeenDragged=!1,e.draggable==!0&&this._makeDraggable(),this.closed=!1,e.closed&&this.toggleClose()}_styleInstance(){let e=this._getScrollbarWidth(this.container);if(this.screenCorner.x=="left"?this.xOffset=0:this.xOffset=this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(".p-gui");for(let 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} {
411
+ `}class g{constructor(e={}){if(e.container?(this.container=typeof e.container=="string"?document.querySelector(e.container):e.container,this.position_type="absolute"):(this.container=document.body,this.position_type="fixed"),this.propReferences=[],this.folders=[],e.isFolder){this._folderConstructor(e.folderOptions);return}this.name=e!=null&&typeof e.name=="string"?e.name:"",this.backgroundColor=e.color||null,this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),e.maxHeight&&(this.initMaxHeight=e.maxHeight,this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.screenCorner=this._parseScreenCorner(e.position),this instanceof g&&(typeof g[g.instanceCounter]!="number"?g[g.instanceCounter]=0:g[g.instanceCounter]++),this.instanceId=g[g.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 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} {
412
412
  width: ${this.wrapperWidth}px;
413
413
  max-height: ${this.maxHeight}px;
414
414
  transform: translate3d(${this.xOffset}px,${this.yOffset}px,0);
415
415
  ${this.screenCorner.y=="top"?"":"top: auto; bottom: 0;"}
416
416
  ${this.backgroundColor?"background: "+this.backgroundColor+";":""}
417
- }`)}_folderConstructor(e){this.wrapper=e.wrapper}_parseScreenCorner(e){let t={x:"right",y:"top"};return e==null||(typeof e!="string"&&console.error("[perfect-gui] Position must be a string."),e.includes("left")&&(t.x="left"),e.includes("bottom")&&(t.y="bottom")),t}_getScrollbarWidth(e){return e===document.body?window.innerWidth-document.documentElement.clientWidth:e.offsetWidth-e.clientWidth}_handleResize(){if(this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),this.initMaxHeight&&(this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.wrapper.style.maxHeight=this.maxHeight+"px",this.hasBeenDragged)return;let e=this._getScrollbarWidth(this.container);if(this.xOffset=this.screenCorner.x=="left"?0:this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);for(let 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)`}_createElement(e){e.el=e.el||"div";var t=document.createElement(e.el);if(e.id&&(t.id=e.id),e.class&&(t.className=e.class),e.inline&&(t.style=e.inline),e.href&&(t.href=e.href),e.onclick&&(t.onclick=e.onclick),e.onchange&&(t.onchange=e.onchange),e.textContent&&(t.textContent=e.textContent),e.innerHTML&&(t.innerHTML=e.innerHTML),e.type&&(t.type=e.type),e.value&&(t.value=e.value),e.customAttributes)for(var o in e.customAttributes)t.setAttribute(o,e.customAttributes[o]);return e.parent=e.parent?e.parent:this.wrapper,e.parent.append(t),t}_addStyles(e){this.stylesheet.innerHTML+=e}_addWrapper(){this.wrapper=this._createElement({parent:this.container,id:"p-gui-"+this.instanceId,class:"p-gui"}),this.header=this._createElement({parent:this.wrapper,class:"p-gui__header",textContent:this.name,inline:`${this.backgroundColor?"border-color: "+this.backgroundColor+";":""}`}),this._createElement({parent:this.header,class:"p-gui__header-close",onclick:this.toggleClose.bind(this)})}button(e,t){let o="";typeof e!="string"?typeof e=="object"&&(e!=null&&e.hasOwnProperty("name"))?o=e.name==""?" ":e.name:o=" ":o=e==""?" ":e,this.imageContainer=null,typeof t!="function"&&(t=()=>{});const a=this._createElement({class:"p-gui__button",textContent:o,onclick:t});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(/^.*[\\\/]/,""),n;e.name==null?n=a:n=typeof e.name=="string"&&e.name||" ";const r=e.selected===!0,i=e.selectionBorder!==!1;let s="";e.width&&(typeof e.width=="number"&&(e.width+="px"),s+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),s+=`height: ${e.height}; `),this.imageContainer||(this.imageContainer=this._createElement({class:"p-gui__image-container"}));var l=this._createElement({class:"p-gui__image",inline:"background-image: url("+o+"); "+s,parent:this.imageContainer});return r&&i&&l.classList.add("p-gui__image--selected"),this._createElement({parent:l,class:"p-gui__image-text",textContent:n}),l.onclick=()=>{let c=l.parentElement.querySelectorAll(".p-gui__image--selected");for(let d=0;d<c.length;d++)c[d].classList.remove("p-gui__image--selected");i&&l.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:o,text:n})},l}slider(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,n=null,r=e.obj||e.object,i=e.prop||e.property,s=typeof e.value=="number"?e.value:null,l=e.min??0,c=e.max??1,d=e.step||(c-l)/100;if(s!==null)(i!=null||r!=null)&&console.warn('[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.');else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);o==" "&&(o=i),n=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),s=(c-l)/2;this.imageContainer=null;var p=this._createElement({class:"p-gui__slider",textContent:o}),f=this._createElement({parent:p,el:"input",class:"p-gui__slider-ctrl",customAttributes:{type:"range",min:l,max:c,step:d,value:a?r[i]:s}}),b=this._createElement({parent:p,class:"p-gui__slider-value",textContent:String(a?r[i]:s)});f.addEventListener("input",()=>{b.textContent=f.value,a?r[i]=f.value:typeof t=="function"&&t(parseFloat(f.value))}),a&&Object.defineProperty(r,i,{set:_=>{this.propReferences[n]=_,f.value=_,b.textContent=String(_),typeof t=="function"&&t(parseFloat(f.value))},get:()=>this.propReferences[n]})}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,n=null,r=e.obj||e.object,i=e.prop||e.property,s=typeof e.value=="boolean"?e.value:null;if(s!==null)(i!=null||r!=null)&&console.warn('[GUI] toggle() "obj" and "property" parameters are ignored when a "value" parameter is used.');else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] toggle() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] toggle() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);o==" "&&(o=i),n=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const l=this._createElement({class:"p-gui__switch",onclick:p=>{const f=p.target.childNodes[1];let b=!0;f.classList.contains("p-gui__switch-checkbox--active")&&(b=!1),f.classList.toggle("p-gui__switch-checkbox--active"),a?r[i]=b:typeof t=="function"&&t(b)},textContent:o});let c=(()=>a?r[i]?" p-gui__switch-checkbox--active":"":s?" p-gui__switch-checkbox--active":"")();const d=this._createElement({parent:l,class:"p-gui__switch-checkbox"+c});a&&Object.defineProperty(r,i,{set:p=>{this.propReferences[n]=p,p?d.classList.add("p-gui__switch-checkbox--active"):d.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(p)},get:()=>this.propReferences[n]})}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,n=null,r=e.obj||e.object,i=e.prop||e.property,s=Array.isArray(e.values)?e.values:null,l;if(t=typeof t=="function"?t:null,e.value!==void 0||e.value===void 0&&r===void 0&&i===void 0)(i!=null||r!=null)&&console.warn('[GUI] list() "obj" and "property" parameters are ignored when a "value" parameter is used.'),l=(()=>{if(!s)return null;if(typeof e.value=="string")return s.indexOf(e.value);if(typeof e.value=="number")return e.value})();else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] list() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] list() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);l=(()=>{if(!s)return null;if(typeof r[i]=="string")return s.indexOf(r[i]);if(typeof r[i]=="number")return r[i]})(),n=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');this.imageContainer=null;let c=this._createElement({class:"p-gui__list",textContent:o}),d=this._createElement({parent:c,el:"select",class:"p-gui__list-dropdown",onchange:p=>{a?r[i]=p.target.value:t&&t(p.target.value)}});s&&s.forEach((p,f)=>{let b=this._createElement({parent:d,el:"option",customAttributes:{value:p},textContent:p});l==f&&b.setAttribute("selected","")}),a&&Object.defineProperty(r,i,{set:p=>{typeof p=="string"&&(l=s.indexOf(p)),typeof p=="number"&&(l=p),this.propReferences[n]=l,d.querySelector("[selected]").removeAttribute("selected"),d.querySelectorAll("option")[l].setAttribute("selected",""),typeof t=="function"&&t(l)},get:()=>this.propReferences[n]})}options(e,t){if(typeof e!="object")throw Error(`[GUI] options() first parameter must be an object. Received: ${typeof e}.`);this.list(e,t)}vector2(e={},t){if(typeof e!="object")throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ";const a=e.x.min??0,n=e.x.max??1,r=e.y.min??0,i=e.y.max??1,s=e.x.obj||e.x.object,l=e.x.prop||e.x.property,c=this.propReferences.push(s[l])-1,d=e.y.obj||e.y.object,p=e.y.prop||e.y.property,f=this.propReferences.push(d[p])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const b=this._createElement({class:"p-gui__vector2",textContent:o}),_=this._createElement({parent:b,class:"p-gui__vector-value",textContent:s[l]+", "+d[p]}),h=this._createElement({parent:b,el:"div",class:"p-gui__vector2-area",onclick:g=>{s[l]=parseFloat(this._mapLinear(g.offsetX,0,h.clientWidth,a,n).toFixed(2)),d[p]=parseFloat(this._mapLinear(g.offsetY,0,h.clientHeight,i,r).toFixed(2)),t&&t(s[l],s[p])}});let m=!1;h.addEventListener("pointerdown",g=>{m=!0}),h.addEventListener("pointerup",()=>{m=!1}),h.addEventListener("pointermove",g=>{m&&(s[l]=parseFloat(this._mapLinear(g.offsetX,0,h.clientWidth,a,n).toFixed(2)),d[p]=parseFloat(this._mapLinear(g.offsetY,0,h.clientHeight,i,r).toFixed(2)),t&&t(s[l],s[p]))}),this._createElement({parent:h,class:"p-gui__vector2-line p-gui__vector2-line-x"}),this._createElement({parent:h,class:"p-gui__vector2-line p-gui__vector2-line-y"});const y=this._createElement({parent:h,class:"p-gui__vector2-dot"});y.style.left=this._mapLinear(s[l],a,n,0,h.clientWidth)+"px",y.style.top=this._mapLinear(d[p],r,i,h.clientHeight,0)+"px",Object.defineProperty(s,l,{set:g=>{this.propReferences[c]=g,y.style.left=this._mapLinear(g,a,n,0,h.clientWidth)+"px",_.textContent=String(g)+", "+d[p]},get:()=>this.propReferences[c]}),Object.defineProperty(d,p,{set:g=>{this.propReferences[f]=g,y.style.top=this._mapLinear(g,r,i,h.clientHeight,0)+"px",_.textContent=s[l]+", "+String(g)},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 o=typeof e.name=="string"&&e.name||" ",a=!1,n=null,r=e.obj||e.object,i=e.prop||e.property,s;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}".`):s=e.value),s||(s="#000000"),e.value!==void 0)(i!=null||r!=null)&&console.warn('[GUI] color() "obj" and "property" parameters are ignored when a "value" parameter is used.');else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] color() "prop" (or "property") parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] color() "obj" (or "object") parameter must be an object. Received: ${typeof r}.`);o==" "&&(o=i),n=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const l=this._createElement({el:"div",class:"p-gui__color",textContent:o}),c=this._createElement({parent:l,el:"input",class:"p-gui__color-picker",type:"color",value:s});typeof t=="function"&&c.addEventListener("input",()=>{a?r[i]=c.value:typeof t=="function"&&t(c.value)}),a&&Object.defineProperty(r,i,{set:d=>{this.propReferences[n]=d,c.value=d,typeof t=="function"&&t(d)},get:()=>this.propReferences[n]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,o=e.name||"",a=e.color||null,n=e.maxHeight||null;this.imageContainer=null;let r="p-gui__folder";this.folders.length==0&&(r+=" p-gui__folder--first"),t&&(r+=" p-gui__folder--closed");let i=a?`background-color: ${a};`:"";i+=n?`max-height: ${n}px;`:"";let s=this._createElement({class:r,inline:i});this._createElement({innerHTML:`<span class="p-gui__folder-arrow"></span>${o}`,class:"p-gui__folder-header",onclick:function(){this.parentNode.classList.toggle("p-gui__folder--closed")},parent:s});let l=new u({isFolder:!0,folderOptions:{wrapper:s}});return this.folders.push(l),l}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",a);function t(n){n.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=n.clientX,e.position.prevY=n.clientY,document.addEventListener("pointermove",o)}function o(n){n.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+n.clientX-e.position.prevX,e.position.y=e.position.initY+n.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function a(n){document.removeEventListener("pointermove",o)}}toggleClose(){this.closed=!this.closed,this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,o,a,n){return a+(e-t)*(n-a)/(o-t)}}return u});
417
+ }`)}_folderConstructor(e){this.wrapper=e.wrapper}_parseScreenCorner(e){let t={x:"right",y:"top"};return e==null||(typeof e!="string"&&console.error("[perfect-gui] Position must be a string."),e.includes("left")&&(t.x="left"),e.includes("bottom")&&(t.y="bottom")),t}_getScrollbarWidth(e){return e===document.body?window.innerWidth-document.documentElement.clientWidth:e.offsetWidth-e.clientWidth}_handleResize(){if(this.container==document.body?this.maxHeight=window.innerHeight:this.maxHeight=Math.min(this.container.clientHeight,window.innerHeight),this.initMaxHeight&&(this.maxHeight=Math.min(this.initMaxHeight,this.maxHeight)),this.wrapper.style.maxHeight=this.maxHeight+"px",this.hasBeenDragged)return;let e=this._getScrollbarWidth(this.container);if(this.xOffset=this.screenCorner.x=="left"?0:this.container.clientWidth-this.wrapperWidth-e,this.instanceId>0){let t=this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);for(let 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,typeof t!="function"&&(t=()=>{});const a=document.createElement("div");a.className="p-gui__button",a.textContent=o,a.addEventListener("click",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(/^.*[\\\/]/,""),d;e.name==null?d=a:d=typeof e.name=="string"&&e.name||" ";const r=e.selected===!0,i=e.selectionBorder!==!1;let s="";e.width&&(typeof e.width=="number"&&(e.width+="px"),s+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),s+=`height: ${e.height}; `),this.imageContainer||(this.imageContainer=document.createElement("div"),this.imageContainer.className="p-gui__image-container",this.wrapper.append(this.imageContainer));const n=document.createElement("div");n.className="p-gui__image",n.style="background-image: url("+o+"); "+s,this.imageContainer.append(n),r&&i&&n.classList.add("p-gui__image--selected");const l=document.createElement("div");return l.className="p-gui__image-text",l.textContent=d,n.append(l),n.addEventListener("click",()=>{let c=n.parentElement.querySelectorAll(".p-gui__image--selected");for(let p=0;p<c.length;p++)c[p].classList.remove("p-gui__image--selected");i&&n.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:o,text:d})}),n}slider(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,d=null,r=e.obj,i=e.prop,s=typeof e.value=="number"?e.value:null,n=e.min??0,l=e.max??1,c=e.step||(l-n)/100;if(s!==null)(i!=null||r!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof r}.`);o==" "&&(o=i),d=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),s=(l-n)/2;this.imageContainer=null;const p=document.createElement("div");p.className="p-gui__slider",p.textContent=o,this.wrapper.append(p);const u=document.createElement("input");u.className="p-gui__slider-ctrl",u.setAttribute("type","range"),u.setAttribute("min",n),u.setAttribute("max",l),u.setAttribute("step",c),u.setAttribute("value",a?r[i]:s),p.append(u);const f=document.createElement("div");f.className="p-gui__slider-value",f.textContent=String(a?r[i]:s),p.append(f),u.addEventListener("input",()=>{f.textContent=u.value,a?r[i]=u.value:typeof t=="function"&&t(parseFloat(u.value))}),a&&Object.defineProperty(r,i,{set:m=>{this.propReferences[d]=m,u.value=m,f.textContent=String(m),typeof t=="function"&&t(parseFloat(u.value))},get:()=>this.propReferences[d]})}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,d=null,r=e.obj,i=e.prop,s=typeof e.value=="boolean"?e.value:null;if(s!==null)(i!=null||r!=null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof r}.`);o==" "&&(o=i),d=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const n=document.createElement("div");n.textContent=o,n.className="p-gui__switch",this.wrapper.append(n),n.addEventListener("click",p=>{const u=p.target.childNodes[1];let f=!0;u.classList.contains("p-gui__switch-checkbox--active")&&(f=!1),u.classList.toggle("p-gui__switch-checkbox--active"),a?r[i]=f:typeof t=="function"&&t(f)});let l=(()=>a?r[i]?" p-gui__switch-checkbox--active":"":s?" p-gui__switch-checkbox--active":"")();const c=document.createElement("div");c.className="p-gui__switch-checkbox"+l,n.append(c),a&&Object.defineProperty(r,i,{set:p=>{this.propReferences[d]=p,p?c.classList.add("p-gui__switch-checkbox--active"):c.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(p)},get:()=>this.propReferences[d]})}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,d=null,r=e.obj,i=e.prop,s=Array.isArray(e.values)?e.values:null,n;if(t=typeof t=="function"?t:null,e.value!==void 0||e.value===void 0&&r===void 0&&i===void 0)(i!=null||r!=null)&&console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'),n=(()=>{if(!s)return null;if(typeof e.value=="string")return s.indexOf(e.value);if(typeof e.value=="number")return e.value})();else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof r}.`);n=(()=>{if(!s)return null;if(typeof r[i]=="string")return s.indexOf(r[i]);if(typeof r[i]=="number")return r[i]})(),d=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');this.imageContainer=null;let l=document.createElement("div");l.className="p-gui__list",l.textContent=o,this.wrapper.append(l);let c=document.createElement("select");l.append(c),c.className="p-gui__list-dropdown",c.addEventListener("change",p=>{a?r[i]=p.target.value:t&&t(p.target.value)}),s&&s.forEach((p,u)=>{let f=document.createElement("option");f.setAttribute("value",p),f.textContent=p,c.append(f),n==u&&f.setAttribute("selected","")}),a&&Object.defineProperty(r,i,{set:p=>{typeof p=="string"&&(n=s.indexOf(p)),typeof p=="number"&&(n=p),this.propReferences[d]=n,c.querySelector("[selected]").removeAttribute("selected"),c.querySelectorAll("option")[n].setAttribute("selected",""),typeof t=="function"&&t(n)},get:()=>this.propReferences[d]})}options(e,t){if(typeof e!="object")throw Error(`[GUI] options() first parameter must be an object. Received: ${typeof e}.`);this.list(e,t)}vector2(e={},t){if(typeof e!="object")throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ";const a=e.x.min??0,d=e.x.max??1,r=e.y.min??0,i=e.y.max??1,s=e.x.obj,n=e.x.prop,l=this.propReferences.push(s[n])-1,c=e.y.obj,p=e.y.prop,u=this.propReferences.push(c[p])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const f=document.createElement("div");f.className="p-gui__vector2",f.textContent=o,this.wrapper.append(f);const m=document.createElement("div");m.className="p-gui__vector-value",m.textContent=s[n]+", "+c[p],f.append(m);const h=document.createElement("div");h.className="p-gui__vector2-area",f.append(h),h.addEventListener("click",b=>{s[n]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,d).toFixed(2)),c[p]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,i,r).toFixed(2)),t&&t(s[n],s[p])});let w=!1;h.addEventListener("pointerdown",b=>{w=!0}),h.addEventListener("pointerup",()=>{w=!1}),h.addEventListener("pointermove",b=>{w&&(s[n]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,d).toFixed(2)),c[p]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,i,r).toFixed(2)),t&&t(s[n],s[p]))});const v=document.createElement("div");v.className="p-gui__vector2-line p-gui__vector2-line-x",h.append(v);const y=document.createElement("div");y.className="p-gui__vector2-line p-gui__vector2-line-y",h.append(y);const x=document.createElement("div");x.className="p-gui__vector2-dot",h.append(x),x.style.left=this._mapLinear(s[n],a,d,0,h.clientWidth)+"px",x.style.top=this._mapLinear(c[p],r,i,h.clientHeight,0)+"px",Object.defineProperty(s,n,{set:b=>{this.propReferences[l]=b,x.style.left=this._mapLinear(b,a,d,0,h.clientWidth)+"px",m.textContent=String(b)+", "+c[p]},get:()=>this.propReferences[l]}),Object.defineProperty(c,p,{set:b=>{this.propReferences[u]=b,x.style.top=this._mapLinear(b,r,i,h.clientHeight,0)+"px",m.textContent=s[n]+", "+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,d=null,r=e.obj,i=e.prop,s;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}".`):s=e.value),s||(s="#000000"),e.value!==void 0)(i!=null||r!=null)&&console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(i!=null&&r!=null){if(typeof i!="string")throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof i}.`);if(typeof r!="object")throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof r}.`);o==" "&&(o=i),d=this.propReferences.push(r[i])-1,a=!0}else(i!=null&&r==null||i==null&&r==null)&&console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');this.imageContainer=null;const n=document.createElement("div");n.className="p-gui__color",n.textContent=o,this.wrapper.append(n);const l=document.createElement("input");l.className="p-gui__color-picker",l.setAttribute("type","color"),l.value=s,n.append(l),typeof t=="function"&&l.addEventListener("input",()=>{a?r[i]=l.value:typeof t=="function"&&t(l.value)}),a&&Object.defineProperty(r,i,{set:c=>{this.propReferences[d]=c,l.value=c,typeof t=="function"&&t(c)},get:()=>this.propReferences[d]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,o=e.name||"",a=e.color||null,d=e.maxHeight||null;this.imageContainer=null;let r="p-gui__folder";this.folders.length==0&&(r+=" p-gui__folder--first"),t&&(r+=" p-gui__folder--closed");let i=a?`background-color: ${a};`:"";i+=d?`max-height: ${d}px;`:"";const s=document.createElement("div");s.className=r,s.style=i,this.wrapper.append(s);const n=document.createElement("div");n.innerHTML=`<span class="p-gui__folder-arrow"></span>${o}`,n.className="p-gui__folder-header",s.append(n),n.addEventListener("click",()=>{s.classList.toggle("p-gui__folder--closed")});let l=new g({isFolder:!0,folderOptions:{wrapper:s}});return this.folders.push(l),l}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",a);function t(d){d.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=d.clientX,e.position.prevY=d.clientY,document.addEventListener("pointermove",o)}function o(d){d.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+d.clientX-e.position.prevX,e.position.y=e.position.initY+d.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function a(d){document.removeEventListener("pointermove",o)}}toggleClose(){this.closed=!this.closed,this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,o,a,d){return a+(e-t)*(d-a)/(o-t)}}return g});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-gui",
3
- "version": "4.6.6",
3
+ "version": "4.7.2",
4
4
  "description": "Nice and simple GUI for JavaScript",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -172,53 +172,27 @@ export default class GUI {
172
172
  this.position = {prevX:this.xOffset, prevY:this.yOffset, x:this.xOffset, y:this.yOffset};
173
173
  this.wrapper.style.transform = `translate3d(${this.position.x}px, ${this.position.y}px, 0)`;
174
174
  }
175
-
176
- _createElement(element) {
177
- element.el = element.el || 'div';
178
- var domElement = document.createElement(element.el);
179
- if (element.id) domElement.id = element.id;
180
- if (element.class) domElement.className = element.class;
181
- if (element.inline) domElement.style = element.inline;
182
- if (element.href) domElement.href = element.href;
183
- if (element.onclick) domElement.onclick = element.onclick;
184
- if (element.onchange) domElement.onchange = element.onchange;
185
- if (element.textContent) domElement.textContent = element.textContent;
186
- if (element.innerHTML) domElement.innerHTML = element.innerHTML;
187
- if (element.type) domElement.type = element.type;
188
- if (element.value) domElement.value = element.value;
189
- if (element.customAttributes) {
190
- for (var i in element.customAttributes) {
191
- domElement.setAttribute(i, element.customAttributes[i]);
192
- }
193
- }
194
- element.parent = element.parent ? element.parent : this.wrapper;
195
- element.parent.append(domElement);
196
- return domElement;
197
- }
198
175
 
199
176
  _addStyles(styles) {
200
177
  this.stylesheet.innerHTML += styles;
201
178
  }
202
179
 
203
180
  _addWrapper() {
204
- this.wrapper = this._createElement({
205
- parent: this.container,
206
- id: 'p-gui-'+this.instanceId,
207
- class: 'p-gui'
208
- });
181
+ this.wrapper = document.createElement('div');
182
+ this.wrapper.id = 'p-gui-'+this.instanceId;
183
+ this.wrapper.className = 'p-gui';
184
+ this.container.append(this.wrapper);
209
185
 
210
- this.header = this._createElement({
211
- parent: this.wrapper,
212
- class: 'p-gui__header',
213
- textContent: this.name,
214
- inline: `${ this.backgroundColor ? 'border-color: ' + this.backgroundColor + ';' : ''}`
215
- });
186
+ this.header = document.createElement('div');
187
+ this.header.className = 'p-gui__header';
188
+ this.header.textContent = this.name;
189
+ this.header.style = `${ this.backgroundColor ? 'border-color: ' + this.backgroundColor + ';' : ''}`;
190
+ this.wrapper.append(this.header);
216
191
 
217
- this._createElement({
218
- parent: this.header,
219
- class: 'p-gui__header-close',
220
- onclick: this.toggleClose.bind(this)
221
- });
192
+ const close_btn = document.createElement('div');
193
+ close_btn.className = 'p-gui__header-close';
194
+ close_btn.addEventListener('click', this.toggleClose.bind(this));
195
+ this.header.append(close_btn);
222
196
  }
223
197
 
224
198
  button(options, callback) {
@@ -238,25 +212,12 @@ export default class GUI {
238
212
  if (typeof callback != 'function') {
239
213
  callback = () => {};
240
214
  }
241
-
242
- /* let create_options = {
243
- class: 'p-gui__button',
244
- textContent: name,
245
- onclick: callback
246
- };
247
-
248
- if (typeof options.color == 'string') {
249
- create_options.inline = 'background-color: ' + options.color;
250
- }
251
-
252
- this._createElement(create_options); */
253
215
 
254
-
255
- const el = this._createElement({
256
- class: 'p-gui__button',
257
- textContent: name,
258
- onclick: callback
259
- });
216
+ const el = document.createElement('div');
217
+ el.className = 'p-gui__button';
218
+ el.textContent = name;
219
+ el.addEventListener('click', callback);
220
+ this.wrapper.append(el);
260
221
 
261
222
  if (typeof options.color == 'string') {
262
223
  el.style.setProperty('--color-accent', options.color);
@@ -307,31 +268,28 @@ export default class GUI {
307
268
  }
308
269
 
309
270
  if (!this.imageContainer) {
310
- this.imageContainer = this._createElement({
311
- class: 'p-gui__image-container'
312
- });
271
+ this.imageContainer = document.createElement('div');
272
+ this.imageContainer.className = 'p-gui__image-container';
273
+ this.wrapper.append(this.imageContainer);
313
274
  }
314
275
 
315
- // Image
316
- var image = this._createElement({
317
- class: 'p-gui__image',
318
- inline: 'background-image: url(' + path + '); ' + inline_styles,
319
- parent: this.imageContainer
320
- });
276
+ // Image button
277
+ const image = document.createElement('div');
278
+ image.className = 'p-gui__image';
279
+ image.style = 'background-image: url(' + path + '); ' + inline_styles;
280
+ this.imageContainer.append(image);
321
281
 
322
282
  if (selected && selectionBorder) {
323
283
  image.classList.add('p-gui__image--selected');
324
284
  }
325
285
 
326
286
  // Text inside image
327
- this._createElement({
328
- parent: image,
329
- class: 'p-gui__image-text',
330
- textContent: name
331
- });
287
+ const text = document.createElement('div');
288
+ text.className = 'p-gui__image-text';
289
+ text.textContent = name;
290
+ image.append(text);
332
291
 
333
-
334
- image.onclick = () => {
292
+ image.addEventListener('click', () => {
335
293
  let selected_items = image.parentElement.querySelectorAll('.p-gui__image--selected');
336
294
  for (let i = 0; i < selected_items.length; i++) {
337
295
  selected_items[i].classList.remove('p-gui__image--selected');
@@ -342,7 +300,7 @@ export default class GUI {
342
300
  if (typeof callback == 'function') {
343
301
  callback({ path, text: name });
344
302
  }
345
- };
303
+ });
346
304
 
347
305
  return image;
348
306
  }
@@ -355,8 +313,8 @@ export default class GUI {
355
313
  let name = typeof params.name == 'string' ? params.name || ' ' : ' ';
356
314
  let isObject = false;
357
315
  let propReferenceIndex = null;
358
- let obj = params.obj || params.object;
359
- let prop = params.prop || params.property;
316
+ let obj = params.obj;
317
+ let prop = params.prop;
360
318
  let value = typeof params.value == 'number' ? params.value : null;
361
319
  let min = params.min ?? 0;
362
320
  let max = params.max ?? 1;
@@ -365,16 +323,16 @@ export default class GUI {
365
323
  // callback mode
366
324
  if ( value !== null ) {
367
325
  if (prop != undefined || obj != undefined) {
368
- console.warn(`[GUI] slider() "obj" and "property" parameters are ignored when a "value" parameter is used.`);
326
+ console.warn(`[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.`);
369
327
  }
370
328
  }
371
329
  // object-binding
372
330
  else if (prop != undefined && obj != undefined) {
373
331
  if (typeof prop != 'string') {
374
- throw Error(`[GUI] slider() "prop" (or "property") parameter must be an string. Received: ${typeof prop}.`);
332
+ throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof prop}.`);
375
333
  }
376
334
  if (typeof obj != 'object') {
377
- throw Error(`[GUI] slider() "obj" (or "object") parameter must be an object. Received: ${typeof obj}.`);
335
+ throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof obj}.`);
378
336
  }
379
337
 
380
338
  if (name == ' ') {
@@ -394,29 +352,24 @@ export default class GUI {
394
352
 
395
353
  this.imageContainer = null;
396
354
 
397
- var container = this._createElement({
398
- class: 'p-gui__slider',
399
- textContent: name
400
- });
401
-
402
- var slider_ctrl = this._createElement({
403
- parent: container,
404
- el: 'input',
405
- class: 'p-gui__slider-ctrl',
406
- customAttributes: {
407
- type: 'range',
408
- min,
409
- max,
410
- step,
411
- value: isObject ? obj[prop] : value
412
- }
413
- });
355
+ const container = document.createElement('div');
356
+ container.className = 'p-gui__slider';
357
+ container.textContent = name;
358
+ this.wrapper.append(container);
414
359
 
415
- var slider_value = this._createElement({
416
- parent: container,
417
- class: 'p-gui__slider-value',
418
- textContent: isObject ? String(obj[prop]) : String(value)
419
- });
360
+ const slider_ctrl = document.createElement('input');
361
+ slider_ctrl.className = 'p-gui__slider-ctrl';
362
+ slider_ctrl.setAttribute('type', 'range');
363
+ slider_ctrl.setAttribute('min', min);
364
+ slider_ctrl.setAttribute('max', max);
365
+ slider_ctrl.setAttribute('step', step);
366
+ slider_ctrl.setAttribute('value', isObject ? obj[prop] : value);
367
+ container.append(slider_ctrl);
368
+
369
+ const slider_value = document.createElement('div');
370
+ slider_value.className = 'p-gui__slider-value';
371
+ slider_value.textContent = isObject ? String(obj[prop]) : String(value);
372
+ container.append(slider_value);
420
373
 
421
374
  slider_ctrl.addEventListener('input', () => {
422
375
  slider_value.textContent = slider_ctrl.value;
@@ -457,24 +410,24 @@ export default class GUI {
457
410
  let name = typeof params.name == 'string' ? params.name || ' ' : ' ';
458
411
  let isObject = false;
459
412
  let propReferenceIndex = null;
460
- let obj = params.obj || params.object;
461
- let prop = params.prop || params.property;
413
+ let obj = params.obj;
414
+ let prop = params.prop;
462
415
  let value = typeof params.value === 'boolean' ? params.value : null;
463
416
 
464
417
  // callback mode
465
418
  if ( value !== null ) {
466
419
  if (prop != undefined || obj != undefined) {
467
- console.warn(`[GUI] toggle() "obj" and "property" parameters are ignored when a "value" parameter is used.`);
420
+ console.warn(`[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.`);
468
421
  }
469
422
  }
470
423
 
471
424
  // object-binding
472
425
  else if (prop != undefined && obj != undefined) {
473
426
  if (typeof prop != 'string') {
474
- throw Error(`[GUI] toggle() "prop" (or "property") parameter must be an string. Received: ${typeof prop}.`);
427
+ throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof prop}.`);
475
428
  }
476
429
  if (typeof obj != 'object') {
477
- throw Error(`[GUI] toggle() "obj" (or "object") parameter must be an object. Received: ${typeof obj}.`);
430
+ throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof obj}.`);
478
431
  }
479
432
 
480
433
  if (name == ' ') {
@@ -492,30 +445,31 @@ export default class GUI {
492
445
 
493
446
  this.imageContainer = null;
494
447
 
495
- const container = this._createElement({
496
- class: 'p-gui__switch',
497
- onclick: (ev) => {
498
- const checkbox = ev.target.childNodes[1];
499
-
500
- let value = true;
501
-
502
- if (checkbox.classList.contains('p-gui__switch-checkbox--active')) {
503
- value = false;
504
- }
505
-
506
- checkbox.classList.toggle('p-gui__switch-checkbox--active');
448
+ const container = document.createElement('div');
449
+ container.textContent = name;
450
+ container.className = 'p-gui__switch';
451
+ this.wrapper.append(container);
507
452
 
508
- if ( isObject ) {
509
- obj[prop] = value;
510
- }
511
-
512
- else {
513
- if (typeof callback == 'function') {
514
- callback(value);
515
- }
453
+ container.addEventListener('click', (ev) => {
454
+ const checkbox = ev.target.childNodes[1];
455
+
456
+ let value = true;
457
+
458
+ if (checkbox.classList.contains('p-gui__switch-checkbox--active')) {
459
+ value = false;
460
+ }
461
+
462
+ checkbox.classList.toggle('p-gui__switch-checkbox--active');
463
+
464
+ if ( isObject ) {
465
+ obj[prop] = value;
466
+ }
467
+
468
+ else {
469
+ if (typeof callback == 'function') {
470
+ callback(value);
516
471
  }
517
- },
518
- textContent: name
472
+ }
519
473
  });
520
474
 
521
475
  let activeClass = (() => {
@@ -526,10 +480,9 @@ export default class GUI {
526
480
  }
527
481
  })();
528
482
 
529
- const checkbox = this._createElement({
530
- parent: container,
531
- class: 'p-gui__switch-checkbox' + activeClass
532
- });
483
+ const checkbox = document.createElement('div');
484
+ checkbox.className = 'p-gui__switch-checkbox' + activeClass;
485
+ container.append(checkbox);
533
486
 
534
487
  if ( isObject ) {
535
488
  Object.defineProperty( obj, prop, {
@@ -561,8 +514,8 @@ export default class GUI {
561
514
  let name = typeof params.name == 'string' ? params.name : ' ';
562
515
  let isObject = false;
563
516
  let propReferenceIndex = null;
564
- let obj = params.obj || params.object;
565
- let prop = params.prop || params.property;
517
+ let obj = params.obj;
518
+ let prop = params.prop;
566
519
  let values = Array.isArray(params.values) ? params.values : null;
567
520
  let value;
568
521
 
@@ -572,7 +525,7 @@ export default class GUI {
572
525
  if ( params.value !== undefined ||
573
526
  (params.value === undefined && obj === undefined && prop === undefined)) {
574
527
  if (prop != undefined || obj != undefined) {
575
- console.warn(`[GUI] list() "obj" and "property" parameters are ignored when a "value" parameter is used.`);
528
+ console.warn(`[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.`);
576
529
  }
577
530
 
578
531
  value = (() => {
@@ -588,16 +541,16 @@ export default class GUI {
588
541
  })();
589
542
  }
590
543
 
591
- // object-binding
544
+ // object-binding mode
592
545
  else if (prop != undefined && obj != undefined) {
593
546
  if (typeof prop != 'string') {
594
- throw Error(`[GUI] list() "prop" (or "property") parameter must be an string. Received: ${typeof prop}.`);
547
+ throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof prop}.`);
595
548
  }
596
549
  if (typeof obj != 'object') {
597
- throw Error(`[GUI] list() "obj" (or "object") parameter must be an object. Received: ${typeof obj}.`);
550
+ throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof obj}.`);
598
551
  }
599
552
 
600
- value = (() => {
553
+ value = (() => {
601
554
  if (!values) {
602
555
  return null;
603
556
  }
@@ -620,23 +573,21 @@ export default class GUI {
620
573
 
621
574
  this.imageContainer = null;
622
575
 
623
- let container = this._createElement({
624
- class: 'p-gui__list',
625
- textContent: name
626
- });
576
+ let container = document.createElement('div');
577
+ container.className = 'p-gui__list';
578
+ container.textContent = name;
579
+ this.wrapper.append(container);
627
580
 
628
- let select = this._createElement({
629
- parent: container,
630
- el: 'select',
631
- class: 'p-gui__list-dropdown',
632
- onchange: (ev) => {
633
- if ( isObject ) {
634
- obj[prop] = ev.target.value;
635
- }
581
+ let select = document.createElement('select');
582
+ container.append(select);
583
+ select.className = 'p-gui__list-dropdown';
584
+ select.addEventListener('change', (ev) => {
585
+ if ( isObject ) {
586
+ obj[prop] = ev.target.value;
587
+ }
636
588
 
637
- else if (callback) {
638
- callback(ev.target.value);
639
- }
589
+ else if (callback) {
590
+ callback(ev.target.value);
640
591
  }
641
592
  });
642
593
 
@@ -644,14 +595,11 @@ export default class GUI {
644
595
  {
645
596
  values.forEach((item, index) =>
646
597
  {
647
- let option = this._createElement({
648
- parent: select,
649
- el: 'option',
650
- customAttributes: {
651
- value: item,
652
- },
653
- textContent: item
654
- });
598
+ let option = document.createElement('option');
599
+ option.setAttribute('value', item);
600
+ option.textContent = item;
601
+ select.append(option);
602
+
655
603
  if (value == index) {
656
604
  option.setAttribute('selected', '');
657
605
  }
@@ -703,42 +651,40 @@ export default class GUI {
703
651
  const minY = params.y.min ?? 0;
704
652
  const maxY = params.y.max ?? 1;
705
653
 
706
- const objectX = params.x.obj || params.x.object;
707
- const propX = params.x.prop || params.x.property;
654
+ const objectX = params.x.obj;
655
+ const propX = params.x.prop;
708
656
  const propXReferenceIndex = this.propReferences.push(objectX[propX]) - 1;
709
657
 
710
- const objectY = params.y.obj || params.y.object;
711
- const propY = params.y.prop || params.y.property;
658
+ const objectY = params.y.obj;
659
+ const propY = params.y.prop;
712
660
  const propYReferenceIndex = this.propReferences.push(objectY[propY]) - 1;
713
661
 
714
662
  callback = typeof callback == 'function' ? callback : null;
715
663
 
716
664
  this.imageContainer = null;
717
665
 
718
- const container = this._createElement({
719
- class: 'p-gui__vector2',
720
- textContent: name
721
- });
666
+ const container = document.createElement('div');
667
+ container.className = 'p-gui__vector2';
668
+ container.textContent = name;
669
+ this.wrapper.append(container);
722
670
 
723
- const vector_value = this._createElement({
724
- parent: container,
725
- class: 'p-gui__vector-value',
726
- textContent: objectX[propX] + ', ' + objectY[propY]
727
- });
671
+ const vector_value = document.createElement('div');
672
+ vector_value.className = 'p-gui__vector-value';
673
+ vector_value.textContent = objectX[propX] + ', ' + objectY[propY];
674
+ container.append(vector_value);
728
675
 
729
- const area = this._createElement({
730
- parent: container,
731
- el: 'div',
732
- class: 'p-gui__vector2-area',
733
- onclick: (evt) => {
734
- objectX[propX] = parseFloat(this._mapLinear(evt.offsetX, 0, area.clientWidth, minX, maxX).toFixed(2));
735
- objectY[propY] = parseFloat(this._mapLinear(evt.offsetY, 0, area.clientHeight, maxY, minY).toFixed(2));
676
+ const area = document.createElement('div');
677
+ area.className = 'p-gui__vector2-area';
678
+ container.append(area);
679
+ area.addEventListener('click', evt => {
680
+ objectX[propX] = parseFloat(this._mapLinear(evt.offsetX, 0, area.clientWidth, minX, maxX).toFixed(2));
681
+ objectY[propY] = parseFloat(this._mapLinear(evt.offsetY, 0, area.clientHeight, maxY, minY).toFixed(2));
736
682
 
737
- if (callback) {
738
- callback(objectX[propX], objectX[propY]);
739
- }
740
- },
683
+ if (callback) {
684
+ callback(objectX[propX], objectX[propY]);
685
+ }
741
686
  });
687
+
742
688
  let pointer_is_down = false;
743
689
  area.addEventListener('pointerdown', (evt) => {
744
690
  pointer_is_down = true;
@@ -757,20 +703,17 @@ export default class GUI {
757
703
  }
758
704
  });
759
705
 
760
- this._createElement({
761
- parent: area,
762
- class: 'p-gui__vector2-line p-gui__vector2-line-x'
763
- });
764
-
765
- this._createElement({
766
- parent: area,
767
- class: 'p-gui__vector2-line p-gui__vector2-line-y'
768
- });
706
+ const line_x = document.createElement('div');
707
+ line_x.className = 'p-gui__vector2-line p-gui__vector2-line-x';
708
+ area.append(line_x);
769
709
 
770
- const dot = this._createElement({
771
- parent: area,
772
- class: 'p-gui__vector2-dot'
773
- });
710
+ const line_y = document.createElement('div');
711
+ line_y.className = 'p-gui__vector2-line p-gui__vector2-line-y';
712
+ area.append(line_y);
713
+
714
+ const dot = document.createElement('div');
715
+ dot.className = 'p-gui__vector2-dot';
716
+ area.append(dot);
774
717
 
775
718
  dot.style.left = this._mapLinear(objectX[propX], minX, maxX, 0, area.clientWidth) + 'px';
776
719
  dot.style.top = this._mapLinear(objectY[propY], minY, maxY, area.clientHeight, 0) + 'px';
@@ -807,8 +750,8 @@ export default class GUI {
807
750
 
808
751
  let isObject = false;
809
752
  let propReferenceIndex = null;
810
- let obj = params.obj || params.object;
811
- let prop = params.prop || params.property;
753
+ let obj = params.obj;
754
+ let prop = params.prop;
812
755
  let value;
813
756
 
814
757
  if (typeof params.value == 'string') {
@@ -824,17 +767,17 @@ export default class GUI {
824
767
  // callback mode
825
768
  if ( params.value !== undefined ) {
826
769
  if (prop != undefined || obj != undefined) {
827
- console.warn(`[GUI] color() "obj" and "property" parameters are ignored when a "value" parameter is used.`);
770
+ console.warn(`[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.`);
828
771
  }
829
772
  }
830
773
 
831
774
  // object-binding
832
775
  else if (prop != undefined && obj != undefined) {
833
776
  if (typeof prop != 'string') {
834
- throw Error(`[GUI] color() "prop" (or "property") parameter must be an string. Received: ${typeof prop}.`);
777
+ throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof prop}.`);
835
778
  }
836
779
  if (typeof obj != 'object') {
837
- throw Error(`[GUI] color() "obj" (or "object") parameter must be an object. Received: ${typeof obj}.`);
780
+ throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof obj}.`);
838
781
  }
839
782
 
840
783
  if (name == ' ') {
@@ -852,19 +795,16 @@ export default class GUI {
852
795
 
853
796
  this.imageContainer = null;
854
797
 
855
- const container = this._createElement({
856
- el: 'div',
857
- class: 'p-gui__color',
858
- textContent: name,
859
- });
798
+ const container = document.createElement('div');
799
+ container.className = 'p-gui__color';
800
+ container.textContent = name;
801
+ this.wrapper.append(container);
860
802
 
861
- const colorpicker = this._createElement({
862
- parent: container,
863
- el: 'input',
864
- class: 'p-gui__color-picker',
865
- type: 'color',
866
- value
867
- });
803
+ const colorpicker = document.createElement('input');
804
+ colorpicker.className = 'p-gui__color-picker';
805
+ colorpicker.setAttribute('type', 'color');
806
+ colorpicker.value = value;
807
+ container.append(colorpicker);
868
808
 
869
809
  if (typeof callback == 'function') {
870
810
  colorpicker.addEventListener('input', () => {
@@ -916,19 +856,18 @@ export default class GUI {
916
856
 
917
857
  let container_style = color ? `background-color: ${color};` : '';
918
858
  container_style += maxHeight ? `max-height: ${maxHeight}px;` : '';
859
+
860
+ const container = document.createElement('div');
861
+ container.className = className;
862
+ container.style = container_style;
863
+ this.wrapper.append(container);
919
864
 
920
- let container = this._createElement({
921
- class: className,
922
- inline: container_style,
923
- });
924
-
925
- let folderHeader = this._createElement({
926
- innerHTML: `<span class="p-gui__folder-arrow"></span>${name}`,
927
- class: 'p-gui__folder-header',
928
- onclick: function() {
929
- this.parentNode.classList.toggle('p-gui__folder--closed');
930
- },
931
- parent: container
865
+ const folderHeader = document.createElement('div');
866
+ folderHeader.innerHTML = `<span class="p-gui__folder-arrow"></span>${name}`;
867
+ folderHeader.className = 'p-gui__folder-header';
868
+ container.append(folderHeader);
869
+ folderHeader.addEventListener('click', () => {
870
+ container.classList.toggle('p-gui__folder--closed');
932
871
  });
933
872
 
934
873
  let folder = new GUI({isFolder: true, folderOptions: {