perfect-gui 4.7.4 → 4.8.0

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.
@@ -307,7 +307,7 @@ function A(y) {
307
307
 
308
308
  .p-gui__slider {
309
309
  width: 100%;
310
- margin-bottom: 8px;
310
+ margin-bottom: 10px;
311
311
  padding: 7px;
312
312
  color: white;
313
313
  position: relative;
@@ -414,20 +414,20 @@ function A(y) {
414
414
  `
415
415
  );
416
416
  }
417
- class b {
417
+ class m {
418
418
  constructor(e = {}) {
419
419
  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) {
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(`${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();
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 m && (typeof m[m.instanceCounter] != "number" ? m[m.instanceCounter] = 0 : m[m.instanceCounter]++), this.instanceId = m[m.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);
427
427
  if (this.screenCorner.x == "left" ? this.xOffset = 0 : this.xOffset = this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
428
428
  let t = this.container.querySelectorAll(".p-gui");
429
- for (let o = 0; o < t.length; o++)
430
- 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));
429
+ for (let n = 0; n < t.length; n++)
430
+ this.screenCorner.y == t[n].dataset.cornerY && (this.screenCorner.x == "left" && t[n].dataset.cornerX == "left" ? this.xOffset += t[n].offsetWidth : this.screenCorner.x == "right" && t[n].dataset.cornerX == "right" && (this.xOffset -= t[n].offsetWidth));
431
431
  }
432
432
  this.yOffset = 0, this.position = {
433
433
  prevX: this.xOffset,
@@ -458,8 +458,8 @@ class b {
458
458
  let e = this._getScrollbarWidth(this.container);
459
459
  if (this.xOffset = this.screenCorner.x == "left" ? 0 : this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
460
460
  let t = this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);
461
- for (let o = 0; o < t.length && !(parseInt(t[o].id.replace("p-gui-", "")) > this.instanceId); o++)
462
- 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));
461
+ for (let n = 0; n < t.length && !(parseInt(t[n].id.replace("p-gui-", "")) > this.instanceId); n++)
462
+ this.screenCorner.y == t[n].dataset.cornerY && (this.screenCorner.x == "left" && t[n].dataset.cornerX == "left" ? this.xOffset += t[n].offsetWidth : this.screenCorner.x == "right" && t[n].dataset.cornerX == "right" && (this.xOffset -= t[n].offsetWidth));
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
  }
@@ -472,104 +472,104 @@ class b {
472
472
  e.className = "p-gui__header-close", e.addEventListener("click", this.toggleClose.bind(this)), this.header.append(e);
473
473
  }
474
474
  button(e, t) {
475
- let o = "";
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 = () => {
475
+ let n = "";
476
+ typeof e != "string" ? typeof e == "object" && (e != null && e.hasOwnProperty("name")) ? n = e.name == "" ? " " : e.name : n = " " : n = e == "" ? " " : e, this.imageContainer = null, typeof t != "function" && (t = () => {
477
477
  });
478
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));
479
+ a.className = "p-gui__button", a.textContent = n, 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));
480
480
  }
481
481
  image(e = {}, t) {
482
482
  if (typeof e != "object")
483
483
  throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);
484
- let o;
484
+ let n;
485
485
  if (typeof e.path == "string")
486
- o = e.path;
486
+ n = e.path;
487
487
  else
488
488
  throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
489
- let a = o.replace(/^.*[\\\/]/, ""), d;
490
- e.name == null ? d = a : d = typeof e.name == "string" && e.name || " ";
489
+ let a = n.replace(/^.*[\\\/]/, ""), p;
490
+ e.name == null ? p = a : p = typeof e.name == "string" && e.name || " ";
491
491
  const r = e.selected === !0, i = e.selectionBorder !== !1;
492
- let n = "";
493
- 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));
492
+ let o = "";
493
+ e.width && (typeof e.width == "number" && (e.width += "px"), o += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), o += `height: ${e.height}; `), this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer));
494
494
  const s = document.createElement("div");
495
- s.className = "p-gui__image", s.style = "background-image: url(" + o + "); " + n, this.imageContainer.append(s), r && i && s.classList.add("p-gui__image--selected");
495
+ s.className = "p-gui__image", s.style = "background-image: url(" + n + "); " + o, this.imageContainer.append(s), r && i && s.classList.add("p-gui__image--selected");
496
496
  const l = document.createElement("div");
497
- return l.className = "p-gui__image-text", l.textContent = d, s.append(l), s.addEventListener("click", () => {
498
- let c = s.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 && s.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: o, text: d });
497
+ return l.className = "p-gui__image-text", l.textContent = p, s.append(l), s.addEventListener("click", () => {
498
+ let u = s.parentElement.querySelectorAll(".p-gui__image--selected");
499
+ for (let c = 0; c < u.length; c++)
500
+ u[c].classList.remove("p-gui__image--selected");
501
+ i && s.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: n, text: p });
502
502
  }), s;
503
503
  }
504
504
  slider(e = {}, t) {
505
505
  if (typeof e != "object")
506
506
  throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
507
- let o = typeof e.name == "string" && e.name || " ", a = !1, d = null, r = e.obj, i = e.prop, n = typeof e.value == "number" ? e.value : null, s = e.min ?? 0, l = e.max ?? 1, c = e.step || (l - s) / 100;
508
- if (n !== null)
507
+ let n = typeof e.name == "string" && e.name || " ", a = !1, p = null, r = e.obj, i = e.prop, o = typeof e.value == "number" ? e.value : null, s = e.min ?? 0, l = e.max ?? 1, u = e.step || (l - s) / 100;
508
+ if (o !== null)
509
509
  (i != null || r != null) && console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
510
510
  else if (i != null && r != null) {
511
511
  if (typeof i != "string")
512
512
  throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof i}.`);
513
513
  if (typeof r != "object")
514
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;
515
+ n == " " && (n = i), p = this.propReferences.push(r[i]) - 1, a = !0;
516
516
  } else
517
- (i != null && r == null || i == null && r == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), n = (l - s) / 2;
517
+ (i != null && r == null || i == null && r == null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), o = (l - s) / 2;
518
518
  this.imageContainer = null;
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", s), u.setAttribute("max", l), u.setAttribute("step", c), u.setAttribute("value", a ? r[i] : n), p.append(u);
519
+ const c = document.createElement("div");
520
+ c.className = "p-gui__slider", c.textContent = n, this.wrapper.append(c);
521
+ const d = document.createElement("input");
522
+ d.className = "p-gui__slider-ctrl", d.setAttribute("type", "range"), d.setAttribute("min", s), d.setAttribute("max", l), d.setAttribute("step", u), d.setAttribute("value", a ? r[i] : o), c.append(d);
523
523
  const h = document.createElement("div");
524
- h.className = "p-gui__slider-value", h.textContent = String(a ? r[i] : n), p.append(h), u.addEventListener("input", () => {
525
- h.textContent = u.value, a ? r[i] = u.value : typeof t == "function" && t(parseFloat(u.value));
524
+ h.className = "p-gui__slider-value", h.textContent = String(a ? r[i] : o), c.append(h), d.addEventListener("input", () => {
525
+ h.textContent = d.value, a ? r[i] = d.value : typeof t == "function" && t(parseFloat(d.value));
526
526
  }), a && Object.defineProperty(r, i, {
527
- set: (m) => {
528
- this.propReferences[d] = m, u.value = m, h.textContent = String(m), typeof t == "function" && t(parseFloat(u.value));
527
+ set: (g) => {
528
+ this.propReferences[p] = g, d.value = g, h.textContent = String(g), typeof t == "function" && t(parseFloat(d.value));
529
529
  },
530
- get: () => this.propReferences[d]
530
+ get: () => this.propReferences[p]
531
531
  });
532
532
  }
533
533
  toggle(e = {}, t) {
534
534
  if (typeof e != "object")
535
535
  throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
536
- let o = typeof e.name == "string" && e.name || " ", a = !1, d = null, r = e.obj, i = e.prop, n = typeof e.value == "boolean" ? e.value : null;
537
- if (n !== null)
536
+ let n = typeof e.name == "string" && e.name || " ", a = !1, p = null, r = e.obj, i = e.prop, o = typeof e.value == "boolean" ? e.value : null;
537
+ if (o !== null)
538
538
  (i != null || r != null) && console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
539
539
  else if (i != null && r != null) {
540
540
  if (typeof i != "string")
541
541
  throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof i}.`);
542
542
  if (typeof r != "object")
543
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;
544
+ n == " " && (n = i), p = this.propReferences.push(r[i]) - 1, a = !0;
545
545
  } else
546
546
  (i != null && r == null || i == null && r == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
547
547
  this.imageContainer = null;
548
548
  const s = document.createElement("div");
549
- s.textContent = o, s.className = "p-gui__switch", this.wrapper.append(s), s.addEventListener("click", (p) => {
550
- const u = p.target.childNodes[1];
549
+ s.textContent = n, s.className = "p-gui__switch", this.wrapper.append(s), s.addEventListener("click", (c) => {
550
+ const d = c.target.childNodes[1];
551
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);
552
+ d.classList.contains("p-gui__switch-checkbox--active") && (h = !1), d.classList.toggle("p-gui__switch-checkbox--active"), a ? r[i] = h : typeof t == "function" && t(h);
553
553
  });
554
- let l = (() => a ? r[i] ? " p-gui__switch-checkbox--active" : "" : n ? " p-gui__switch-checkbox--active" : "")();
555
- const c = document.createElement("div");
556
- c.className = "p-gui__switch-checkbox" + l, s.append(c), a && Object.defineProperty(r, i, {
557
- set: (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);
554
+ let l = (() => a ? r[i] ? " p-gui__switch-checkbox--active" : "" : o ? " p-gui__switch-checkbox--active" : "")();
555
+ const u = document.createElement("div");
556
+ u.className = "p-gui__switch-checkbox" + l, s.append(u), a && Object.defineProperty(r, i, {
557
+ set: (c) => {
558
+ this.propReferences[p] = c, c ? u.classList.add("p-gui__switch-checkbox--active") : u.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(c);
559
559
  },
560
- get: () => this.propReferences[d]
560
+ get: () => this.propReferences[p]
561
561
  });
562
562
  }
563
563
  list(e = {}, t) {
564
564
  if (typeof e != "object")
565
565
  throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
566
- let o = typeof e.name == "string" ? e.name : " ", a = !1, d = null, r = e.obj, i = e.prop, n = Array.isArray(e.values) ? e.values : null, s;
566
+ let n = typeof e.name == "string" ? e.name : " ", a = !1, p = null, r = e.obj, i = e.prop, o = Array.isArray(e.values) ? e.values : null, s, l = typeof o[0] != "string";
567
567
  if (t = typeof t == "function" ? t : null, e.value !== void 0 || e.value === void 0 && r === void 0 && i === void 0)
568
568
  (i != null || r != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'), s = (() => {
569
- if (!n)
569
+ if (!o)
570
570
  return null;
571
571
  if (typeof e.value == "string")
572
- return n.indexOf(e.value);
572
+ return o.indexOf(e.value);
573
573
  if (typeof e.value == "number")
574
574
  return e.value;
575
575
  })();
@@ -579,30 +579,31 @@ class b {
579
579
  if (typeof r != "object")
580
580
  throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof r}.`);
581
581
  s = (() => {
582
- if (!n)
582
+ if (!o)
583
583
  return null;
584
584
  if (typeof r[i] == "string")
585
- return n.indexOf(r[i]);
585
+ return l ? o.find((d) => d.value === r[i]).value : o.indexOf(r[i]);
586
586
  if (typeof r[i] == "number")
587
- return r[i];
588
- })(), d = this.propReferences.push(r[i]) - 1, a = !0;
587
+ return l ? o.find((d) => d.value === r[i]).value : r[i];
588
+ })(), p = this.propReferences.push(r[i]) - 1, a = !0;
589
589
  } else
590
590
  (i != null && r == null || i == null && r == null) && console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');
591
591
  this.imageContainer = null;
592
- let l = document.createElement("div");
593
- l.className = "p-gui__list", l.textContent = o, this.wrapper.append(l);
592
+ let u = document.createElement("div");
593
+ u.className = "p-gui__list", u.textContent = n, this.wrapper.append(u);
594
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
- }), n && n.forEach((p, u) => {
598
- let h = document.createElement("option");
599
- h.setAttribute("value", p), h.textContent = p, c.append(h), s == u && h.setAttribute("selected", "");
595
+ u.append(c), c.className = "p-gui__list-dropdown", c.addEventListener("change", (d) => {
596
+ a ? r[i] = d.target.value : t && t(d.target.value);
597
+ }), o && o.forEach((d, h) => {
598
+ const g = l ? d.name : d, f = l ? d.value : d;
599
+ let x = document.createElement("option");
600
+ x.setAttribute("value", f), x.textContent = g, c.append(x), (!l && s == h || l && s == f) && x.setAttribute("selected", "");
600
601
  }), a && Object.defineProperty(r, i, {
601
- set: (p) => {
602
- let u, h;
603
- typeof p == "string" && (u = n.indexOf(p), h = p), typeof p == "number" && (u = p, h = n[p]), this.propReferences[d] = p, c.querySelector("[selected]").removeAttribute("selected"), c.querySelectorAll("option")[u].setAttribute("selected", ""), typeof t == "function" && t(h, u);
602
+ set: (d) => {
603
+ let h, g, f;
604
+ l ? (f = o.find((x) => x.value == d), g = f.value, h = o.indexOf(f)) : (typeof d == "string" && (h = o.indexOf(d), g = d), typeof d == "number" && (h = d, g = o[d])), this.propReferences[p] = l ? g : d, c.querySelector("[selected]").removeAttribute("selected"), c.querySelectorAll("option")[h].setAttribute("selected", ""), typeof t == "function" && t(l ? f : g, h);
604
605
  },
605
- get: () => this.propReferences[d]
606
+ get: () => this.propReferences[p]
606
607
  });
607
608
  }
608
609
  options(e, t) {
@@ -613,98 +614,98 @@ class b {
613
614
  vector2(e = {}, t) {
614
615
  if (typeof e != "object")
615
616
  throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
616
- let o = typeof e.name == "string" && e.name || " ";
617
- const a = e.x.min ?? 0, d = e.x.max ?? 1, r = e.y.min ?? 0, i = e.y.max ?? 1, n = e.x.obj, s = e.x.prop, l = this.propReferences.push(n[s]) - 1, c = e.y.obj, p = e.y.prop, u = this.propReferences.push(c[p]) - 1;
617
+ let n = typeof e.name == "string" && e.name || " ";
618
+ const a = e.x.min ?? 0, p = e.x.max ?? 1, r = e.y.min ?? 0, i = e.y.max ?? 1, o = e.x.obj, s = e.x.prop, l = this.propReferences.push(o[s]) - 1, u = e.y.obj, c = e.y.prop, d = this.propReferences.push(u[c]) - 1;
618
619
  t = typeof t == "function" ? t : null, this.imageContainer = null;
619
620
  const h = document.createElement("div");
620
- h.className = "p-gui__vector2", h.textContent = o, this.wrapper.append(h);
621
- const m = document.createElement("div");
622
- m.className = "p-gui__vector-value", m.textContent = n[s] + ", " + c[p], h.append(m);
621
+ h.className = "p-gui__vector2", h.textContent = n, this.wrapper.append(h);
622
+ const g = document.createElement("div");
623
+ g.className = "p-gui__vector-value", g.textContent = o[s] + ", " + u[c], h.append(g);
623
624
  const f = document.createElement("div");
624
- f.className = "p-gui__vector2-area", h.append(f), f.addEventListener("click", (g) => {
625
- n[s] = 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(n[s], n[p]);
625
+ f.className = "p-gui__vector2-area", h.append(f), f.addEventListener("click", (b) => {
626
+ o[s] = parseFloat(this._mapLinear(b.offsetX, 0, f.clientWidth, a, p).toFixed(2)), u[c] = parseFloat(this._mapLinear(b.offsetY, 0, f.clientHeight, i, r).toFixed(2)), t && t(o[s], o[c]);
626
627
  });
627
- let _ = !1;
628
- f.addEventListener("pointerdown", (g) => {
629
- _ = !0;
628
+ let x = !1;
629
+ f.addEventListener("pointerdown", (b) => {
630
+ x = !0;
630
631
  }), f.addEventListener("pointerup", () => {
631
- _ = !1;
632
- }), f.addEventListener("pointermove", (g) => {
633
- _ && (n[s] = 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(n[s], n[p]));
632
+ x = !1;
633
+ }), f.addEventListener("pointermove", (b) => {
634
+ x && (o[s] = parseFloat(this._mapLinear(b.offsetX, 0, f.clientWidth, a, p).toFixed(2)), u[c] = parseFloat(this._mapLinear(b.offsetY, 0, f.clientHeight, i, r).toFixed(2)), t && t(o[s], o[c]));
634
635
  });
635
636
  const w = document.createElement("div");
636
637
  w.className = "p-gui__vector2-line p-gui__vector2-line-x", f.append(w);
637
638
  const v = document.createElement("div");
638
639
  v.className = "p-gui__vector2-line p-gui__vector2-line-y", f.append(v);
639
- const x = document.createElement("div");
640
- x.className = "p-gui__vector2-dot", f.append(x), x.style.left = this._mapLinear(n[s], a, d, 0, f.clientWidth) + "px", x.style.top = this._mapLinear(c[p], r, i, f.clientHeight, 0) + "px", Object.defineProperty(n, s, {
641
- set: (g) => {
642
- this.propReferences[l] = g, x.style.left = this._mapLinear(g, a, d, 0, f.clientWidth) + "px", m.textContent = String(g) + ", " + c[p];
640
+ const _ = document.createElement("div");
641
+ _.className = "p-gui__vector2-dot", f.append(_), _.style.left = this._mapLinear(o[s], a, p, 0, f.clientWidth) + "px", _.style.top = this._mapLinear(u[c], r, i, f.clientHeight, 0) + "px", Object.defineProperty(o, s, {
642
+ set: (b) => {
643
+ this.propReferences[l] = b, _.style.left = this._mapLinear(b, a, p, 0, f.clientWidth) + "px", g.textContent = String(b) + ", " + u[c];
643
644
  },
644
645
  get: () => this.propReferences[l]
645
- }), Object.defineProperty(c, p, {
646
- set: (g) => {
647
- this.propReferences[u] = g, x.style.top = this._mapLinear(g, r, i, f.clientHeight, 0) + "px", m.textContent = n[s] + ", " + String(g);
646
+ }), Object.defineProperty(u, c, {
647
+ set: (b) => {
648
+ this.propReferences[d] = b, _.style.top = this._mapLinear(b, r, i, f.clientHeight, 0) + "px", g.textContent = o[s] + ", " + String(b);
648
649
  },
649
- get: () => this.propReferences[u]
650
+ get: () => this.propReferences[d]
650
651
  });
651
652
  }
652
653
  color(e = {}, t) {
653
654
  if (typeof e != "object")
654
655
  throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
655
- let o = typeof e.name == "string" && e.name || " ", a = !1, d = null, r = e.obj, i = e.prop, n;
656
- 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)
656
+ let n = typeof e.name == "string" && e.name || " ", a = !1, p = null, r = e.obj, i = e.prop, o;
657
+ 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}".`) : o = e.value), o || (o = "#000000"), e.value !== void 0)
657
658
  (i != null || r != null) && console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
658
659
  else if (i != null && r != null) {
659
660
  if (typeof i != "string")
660
661
  throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof i}.`);
661
662
  if (typeof r != "object")
662
663
  throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof r}.`);
663
- o == " " && (o = i), d = this.propReferences.push(r[i]) - 1, a = !0;
664
+ n == " " && (n = i), p = this.propReferences.push(r[i]) - 1, a = !0;
664
665
  } else
665
666
  (i != null && r == null || i == null && r == null) && console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');
666
667
  this.imageContainer = null;
667
668
  const s = document.createElement("div");
668
- s.className = "p-gui__color", s.textContent = o, this.wrapper.append(s);
669
+ s.className = "p-gui__color", s.textContent = n, this.wrapper.append(s);
669
670
  const l = document.createElement("input");
670
- l.className = "p-gui__color-picker", l.setAttribute("type", "color"), l.value = n, s.append(l), typeof t == "function" && l.addEventListener("input", () => {
671
+ l.className = "p-gui__color-picker", l.setAttribute("type", "color"), l.value = o, s.append(l), typeof t == "function" && l.addEventListener("input", () => {
671
672
  a ? r[i] = l.value : typeof t == "function" && t(l.value);
672
673
  }), a && Object.defineProperty(r, i, {
673
- set: (c) => {
674
- this.propReferences[d] = c, l.value = c, typeof t == "function" && t(c);
674
+ set: (u) => {
675
+ this.propReferences[p] = u, l.value = u, typeof t == "function" && t(u);
675
676
  },
676
- get: () => this.propReferences[d]
677
+ get: () => this.propReferences[p]
677
678
  });
678
679
  }
679
680
  folder(e = {}) {
680
- let t = typeof e.closed == "boolean" ? e.closed : !1, o = e.name || "", a = e.color || null, d = e.maxHeight || null;
681
+ let t = typeof e.closed == "boolean" ? e.closed : !1, n = e.name || "", a = e.color || null, p = e.maxHeight || null;
681
682
  this.imageContainer = null;
682
683
  let r = "p-gui__folder";
683
684
  this.folders.length == 0 && (r += " p-gui__folder--first"), t && (r += " p-gui__folder--closed");
684
685
  let i = a ? `background-color: ${a};` : "";
685
- i += d ? `max-height: ${d}px;` : "";
686
- const n = document.createElement("div");
687
- n.className = r, n.style = i, this.wrapper.append(n);
686
+ i += p ? `max-height: ${p}px;` : "";
687
+ const o = document.createElement("div");
688
+ o.className = r, o.style = i, this.wrapper.append(o);
688
689
  const s = document.createElement("div");
689
- s.innerHTML = `<span class="p-gui__folder-arrow"></span>${o}`, s.className = "p-gui__folder-header", n.append(s), s.addEventListener("click", () => {
690
- n.classList.toggle("p-gui__folder--closed");
690
+ s.innerHTML = `<span class="p-gui__folder-arrow"></span>${n}`, s.className = "p-gui__folder-header", o.append(s), s.addEventListener("click", () => {
691
+ o.classList.toggle("p-gui__folder--closed");
691
692
  });
692
- let l = new b({ isFolder: !0, folderOptions: {
693
- wrapper: n
693
+ let l = new m({ isFolder: !0, folderOptions: {
694
+ wrapper: o
694
695
  } });
695
696
  return this.folders.push(l), l;
696
697
  }
697
698
  _makeDraggable() {
698
699
  var e = this;
699
700
  this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", a);
700
- function t(d) {
701
- 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);
701
+ function t(p) {
702
+ p.preventDefault(), e.position.initX = e.position.x, e.position.initY = e.position.y, e.position.prevX = p.clientX, e.position.prevY = p.clientY, document.addEventListener("pointermove", n);
702
703
  }
703
- function o(d) {
704
- 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)";
704
+ function n(p) {
705
+ p.preventDefault(), e.hasBeenDragged || (e.hasBeenDragged = !0, e.wrapper.setAttribute("data-dragged", "true")), e.position.x = e.position.initX + p.clientX - e.position.prevX, e.position.y = e.position.initY + p.clientY - e.position.prevY, e.wrapper.style.transform = "translate3d(" + e.position.x + "px," + e.position.y + "px,0)";
705
706
  }
706
- function a(d) {
707
- document.removeEventListener("pointermove", o);
707
+ function a(p) {
708
+ document.removeEventListener("pointermove", n);
708
709
  }
709
710
  }
710
711
  toggleClose() {
@@ -713,10 +714,10 @@ class b {
713
714
  kill() {
714
715
  this.wrapper.remove();
715
716
  }
716
- _mapLinear(e, t, o, a, d) {
717
- return a + (e - t) * (d - a) / (o - t);
717
+ _mapLinear(e, t, n, a, p) {
718
+ return a + (e - t) * (p - a) / (n - t);
718
719
  }
719
720
  }
720
721
  export {
721
- b as default
722
+ m as default
722
723
  };
@@ -1,4 +1,4 @@
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`
1
+ (function(w,b){typeof exports=="object"&&typeof module<"u"?module.exports=b():typeof define=="function"&&define.amd?define(b):(w=typeof globalThis<"u"?globalThis:w||self,w["Perfect GUI"]=b())})(this,function(){"use strict";function w(A){return`
2
2
  .p-gui {
3
3
  --main-border-radius: 5px;
4
4
  --color-bg: #121212;
@@ -304,7 +304,7 @@
304
304
 
305
305
  .p-gui__slider {
306
306
  width: 100%;
307
- margin-bottom: 8px;
307
+ margin-bottom: 10px;
308
308
  padding: 7px;
309
309
  color: white;
310
310
  position: relative;
@@ -408,10 +408,10 @@
408
408
  .p-gui__folder--closed .p-gui__folder-arrow {
409
409
  transform: rotate(0deg);
410
410
  }
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} {
411
+ `}class b{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 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()}_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 n=0;n<t.length;n++)this.screenCorner.y==t[n].dataset.cornerY&&(this.screenCorner.x=="left"&&t[n].dataset.cornerX=="left"?this.xOffset+=t[n].offsetWidth:this.screenCorner.x=="right"&&t[n].dataset.cornerX=="right"&&(this.xOffset-=t[n].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)`}_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 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),r&&i&&s.classList.add("p-gui__image--selected");const l=document.createElement("div");return l.className="p-gui__image-text",l.textContent=d,s.append(l),s.addEventListener("click",()=>{let c=s.parentElement.querySelectorAll(".p-gui__image--selected");for(let p=0;p<c.length;p++)c[p].classList.remove("p-gui__image--selected");i&&s.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:o,text:d})}),s}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,n=typeof e.value=="number"?e.value:null,s=e.min??0,l=e.max??1,c=e.step||(l-s)/100;if(n!==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.'),n=(l-s)/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",s),u.setAttribute("max",l),u.setAttribute("step",c),u.setAttribute("value",a?r[i]:n),p.append(u);const f=document.createElement("div");f.className="p-gui__slider-value",f.textContent=String(a?r[i]:n),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,n=typeof e.value=="boolean"?e.value:null;if(n!==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 s=document.createElement("div");s.textContent=o,s.className="p-gui__switch",this.wrapper.append(s),s.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":"":n?" p-gui__switch-checkbox--active":"")();const c=document.createElement("div");c.className="p-gui__switch-checkbox"+l,s.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,n=Array.isArray(e.values)?e.values:null,s;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.'),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(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}.`);s=(()=>{if(!n)return null;if(typeof r[i]=="string")return n.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)}),n&&n.forEach((p,u)=>{let f=document.createElement("option");f.setAttribute("value",p),f.textContent=p,c.append(f),s==u&&f.setAttribute("selected","")}),a&&Object.defineProperty(r,i,{set:p=>{let u,f;typeof p=="string"&&(u=n.indexOf(p),f=p),typeof p=="number"&&(u=p,f=n[p]),this.propReferences[d]=p,c.querySelector("[selected]").removeAttribute("selected"),c.querySelectorAll("option")[u].setAttribute("selected",""),typeof t=="function"&&t(f,u)},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,n=e.x.obj,s=e.x.prop,l=this.propReferences.push(n[s])-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=n[s]+", "+c[p],f.append(m);const h=document.createElement("div");h.className="p-gui__vector2-area",f.append(h),h.addEventListener("click",b=>{n[s]=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(n[s],n[p])});let w=!1;h.addEventListener("pointerdown",b=>{w=!0}),h.addEventListener("pointerup",()=>{w=!1}),h.addEventListener("pointermove",b=>{w&&(n[s]=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(n[s],n[p]))});const y=document.createElement("div");y.className="p-gui__vector2-line p-gui__vector2-line-x",h.append(y);const v=document.createElement("div");v.className="p-gui__vector2-line p-gui__vector2-line-y",h.append(v);const x=document.createElement("div");x.className="p-gui__vector2-dot",h.append(x),x.style.left=this._mapLinear(n[s],a,d,0,h.clientWidth)+"px",x.style.top=this._mapLinear(c[p],r,i,h.clientHeight,0)+"px",Object.defineProperty(n,s,{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=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,d=null,r=e.obj,i=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)(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 s=document.createElement("div");s.className="p-gui__color",s.textContent=o,this.wrapper.append(s);const l=document.createElement("input");l.className="p-gui__color-picker",l.setAttribute("type","color"),l.value=n,s.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 n=document.createElement("div");n.className=r,n.style=i,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 l=new g({isFolder:!0,folderOptions:{wrapper:n}});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});
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 n=0;n<t.length&&!(parseInt(t[n].id.replace("p-gui-",""))>this.instanceId);n++)this.screenCorner.y==t[n].dataset.cornerY&&(this.screenCorner.x=="left"&&t[n].dataset.cornerX=="left"?this.xOffset+=t[n].offsetWidth:this.screenCorner.x=="right"&&t[n].dataset.cornerX=="right"&&(this.xOffset-=t[n].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 n="";typeof e!="string"?typeof e=="object"&&(e!=null&&e.hasOwnProperty("name"))?n=e.name==""?" ":e.name:n=" ":n=e==""?" ":e,this.imageContainer=null,typeof t!="function"&&(t=()=>{});const a=document.createElement("div");a.className="p-gui__button",a.textContent=n,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 n;if(typeof e.path=="string")n=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=n.replace(/^.*[\\\/]/,""),p;e.name==null?p=a:p=typeof e.name=="string"&&e.name||" ";const r=e.selected===!0,i=e.selectionBorder!==!1;let o="";e.width&&(typeof e.width=="number"&&(e.width+="px"),o+=`flex: 0 0 calc(${e.width} - 5px); `),e.height&&(typeof e.height=="number"&&(e.height+="px"),o+=`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("+n+"); "+o,this.imageContainer.append(s),r&&i&&s.classList.add("p-gui__image--selected");const l=document.createElement("div");return l.className="p-gui__image-text",l.textContent=p,s.append(l),s.addEventListener("click",()=>{let u=s.parentElement.querySelectorAll(".p-gui__image--selected");for(let c=0;c<u.length;c++)u[c].classList.remove("p-gui__image--selected");i&&s.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:n,text:p})}),s}slider(e={},t){if(typeof e!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);let n=typeof e.name=="string"&&e.name||" ",a=!1,p=null,r=e.obj,i=e.prop,o=typeof e.value=="number"?e.value:null,s=e.min??0,l=e.max??1,u=e.step||(l-s)/100;if(o!==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}.`);n==" "&&(n=i),p=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.'),o=(l-s)/2;this.imageContainer=null;const c=document.createElement("div");c.className="p-gui__slider",c.textContent=n,this.wrapper.append(c);const d=document.createElement("input");d.className="p-gui__slider-ctrl",d.setAttribute("type","range"),d.setAttribute("min",s),d.setAttribute("max",l),d.setAttribute("step",u),d.setAttribute("value",a?r[i]:o),c.append(d);const h=document.createElement("div");h.className="p-gui__slider-value",h.textContent=String(a?r[i]:o),c.append(h),d.addEventListener("input",()=>{h.textContent=d.value,a?r[i]=d.value:typeof t=="function"&&t(parseFloat(d.value))}),a&&Object.defineProperty(r,i,{set:g=>{this.propReferences[p]=g,d.value=g,h.textContent=String(g),typeof t=="function"&&t(parseFloat(d.value))},get:()=>this.propReferences[p]})}toggle(e={},t){if(typeof e!="object")throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);let n=typeof e.name=="string"&&e.name||" ",a=!1,p=null,r=e.obj,i=e.prop,o=typeof e.value=="boolean"?e.value:null;if(o!==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}.`);n==" "&&(n=i),p=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 s=document.createElement("div");s.textContent=n,s.className="p-gui__switch",this.wrapper.append(s),s.addEventListener("click",c=>{const d=c.target.childNodes[1];let h=!0;d.classList.contains("p-gui__switch-checkbox--active")&&(h=!1),d.classList.toggle("p-gui__switch-checkbox--active"),a?r[i]=h:typeof t=="function"&&t(h)});let l=(()=>a?r[i]?" p-gui__switch-checkbox--active":"":o?" p-gui__switch-checkbox--active":"")();const u=document.createElement("div");u.className="p-gui__switch-checkbox"+l,s.append(u),a&&Object.defineProperty(r,i,{set:c=>{this.propReferences[p]=c,c?u.classList.add("p-gui__switch-checkbox--active"):u.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(c)},get:()=>this.propReferences[p]})}list(e={},t){if(typeof e!="object")throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);let n=typeof e.name=="string"?e.name:" ",a=!1,p=null,r=e.obj,i=e.prop,o=Array.isArray(e.values)?e.values:null,s,l=typeof o[0]!="string";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.'),s=(()=>{if(!o)return null;if(typeof e.value=="string")return o.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}.`);s=(()=>{if(!o)return null;if(typeof r[i]=="string")return l?o.find(d=>d.value===r[i]).value:o.indexOf(r[i]);if(typeof r[i]=="number")return l?o.find(d=>d.value===r[i]).value:r[i]})(),p=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 u=document.createElement("div");u.className="p-gui__list",u.textContent=n,this.wrapper.append(u);let c=document.createElement("select");u.append(c),c.className="p-gui__list-dropdown",c.addEventListener("change",d=>{a?r[i]=d.target.value:t&&t(d.target.value)}),o&&o.forEach((d,h)=>{const g=l?d.name:d,f=l?d.value:d;let x=document.createElement("option");x.setAttribute("value",f),x.textContent=g,c.append(x),(!l&&s==h||l&&s==f)&&x.setAttribute("selected","")}),a&&Object.defineProperty(r,i,{set:d=>{let h,g,f;l?(f=o.find(x=>x.value==d),g=f.value,h=o.indexOf(f)):(typeof d=="string"&&(h=o.indexOf(d),g=d),typeof d=="number"&&(h=d,g=o[d])),this.propReferences[p]=l?g:d,c.querySelector("[selected]").removeAttribute("selected"),c.querySelectorAll("option")[h].setAttribute("selected",""),typeof t=="function"&&t(l?f:g,h)},get:()=>this.propReferences[p]})}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 n=typeof e.name=="string"&&e.name||" ";const a=e.x.min??0,p=e.x.max??1,r=e.y.min??0,i=e.y.max??1,o=e.x.obj,s=e.x.prop,l=this.propReferences.push(o[s])-1,u=e.y.obj,c=e.y.prop,d=this.propReferences.push(u[c])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const h=document.createElement("div");h.className="p-gui__vector2",h.textContent=n,this.wrapper.append(h);const g=document.createElement("div");g.className="p-gui__vector-value",g.textContent=o[s]+", "+u[c],h.append(g);const f=document.createElement("div");f.className="p-gui__vector2-area",h.append(f),f.addEventListener("click",m=>{o[s]=parseFloat(this._mapLinear(m.offsetX,0,f.clientWidth,a,p).toFixed(2)),u[c]=parseFloat(this._mapLinear(m.offsetY,0,f.clientHeight,i,r).toFixed(2)),t&&t(o[s],o[c])});let x=!1;f.addEventListener("pointerdown",m=>{x=!0}),f.addEventListener("pointerup",()=>{x=!1}),f.addEventListener("pointermove",m=>{x&&(o[s]=parseFloat(this._mapLinear(m.offsetX,0,f.clientWidth,a,p).toFixed(2)),u[c]=parseFloat(this._mapLinear(m.offsetY,0,f.clientHeight,i,r).toFixed(2)),t&&t(o[s],o[c]))});const v=document.createElement("div");v.className="p-gui__vector2-line p-gui__vector2-line-x",f.append(v);const y=document.createElement("div");y.className="p-gui__vector2-line p-gui__vector2-line-y",f.append(y);const _=document.createElement("div");_.className="p-gui__vector2-dot",f.append(_),_.style.left=this._mapLinear(o[s],a,p,0,f.clientWidth)+"px",_.style.top=this._mapLinear(u[c],r,i,f.clientHeight,0)+"px",Object.defineProperty(o,s,{set:m=>{this.propReferences[l]=m,_.style.left=this._mapLinear(m,a,p,0,f.clientWidth)+"px",g.textContent=String(m)+", "+u[c]},get:()=>this.propReferences[l]}),Object.defineProperty(u,c,{set:m=>{this.propReferences[d]=m,_.style.top=this._mapLinear(m,r,i,f.clientHeight,0)+"px",g.textContent=o[s]+", "+String(m)},get:()=>this.propReferences[d]})}color(e={},t){if(typeof e!="object")throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);let n=typeof e.name=="string"&&e.name||" ",a=!1,p=null,r=e.obj,i=e.prop,o;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}".`):o=e.value),o||(o="#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}.`);n==" "&&(n=i),p=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 s=document.createElement("div");s.className="p-gui__color",s.textContent=n,this.wrapper.append(s);const l=document.createElement("input");l.className="p-gui__color-picker",l.setAttribute("type","color"),l.value=o,s.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:u=>{this.propReferences[p]=u,l.value=u,typeof t=="function"&&t(u)},get:()=>this.propReferences[p]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,n=e.name||"",a=e.color||null,p=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+=p?`max-height: ${p}px;`:"";const o=document.createElement("div");o.className=r,o.style=i,this.wrapper.append(o);const s=document.createElement("div");s.innerHTML=`<span class="p-gui__folder-arrow"></span>${n}`,s.className="p-gui__folder-header",o.append(s),s.addEventListener("click",()=>{o.classList.toggle("p-gui__folder--closed")});let l=new b({isFolder:!0,folderOptions:{wrapper:o}});return this.folders.push(l),l}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",a);function t(p){p.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=p.clientX,e.position.prevY=p.clientY,document.addEventListener("pointermove",n)}function n(p){p.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+p.clientX-e.position.prevX,e.position.y=e.position.initY+p.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function a(p){document.removeEventListener("pointermove",n)}}toggleClose(){this.closed=!this.closed,this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,n,a,p){return a+(e-t)*(p-a)/(n-t)}}return b});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "perfect-gui",
3
- "version": "4.7.4",
4
- "description": "Nice and simple GUI for JavaScript",
3
+ "version": "4.8.0",
4
+ "description": "GUI for JavaScript",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "build": "vite build"
package/src/index.js CHANGED
@@ -518,6 +518,7 @@ export default class GUI {
518
518
  let prop = params.prop;
519
519
  let values = Array.isArray(params.values) ? params.values : null;
520
520
  let value;
521
+ let objectValues = typeof values[0] == 'string' ? false : true;
521
522
 
522
523
  callback = typeof callback == 'function' ? callback : null;
523
524
 
@@ -555,16 +556,27 @@ export default class GUI {
555
556
  return null;
556
557
  }
557
558
  if (typeof obj[prop] == 'string') {
558
- return values.indexOf(obj[prop]);
559
+ if ( !objectValues ) { // values is an array of strings
560
+ return values.indexOf(obj[prop]);
561
+ }
562
+ else { // values is an array of objects
563
+ return values.find(item => item.value === obj[prop]).value;
564
+ }
559
565
  }
560
566
  if (typeof obj[prop] == 'number') {
561
- return obj[prop];
567
+ if ( !objectValues ) { // values is an array of strings
568
+ return obj[prop];
569
+ }
570
+ else { // values is an array of objects
571
+ return values.find(item => item.value === obj[prop]).value;
572
+ }
562
573
  }
563
574
  })();
564
575
 
565
576
  propReferenceIndex = this.propReferences.push(obj[prop]) - 1;
566
577
  isObject = true;
567
578
  }
579
+
568
580
  else {
569
581
  if ((prop != undefined && obj == undefined) || (prop == undefined && obj == undefined)) {
570
582
  console.warn(`[GUI] list() "obj" and "prop" parameters must be used together.`);
@@ -595,12 +607,14 @@ export default class GUI {
595
607
  {
596
608
  values.forEach((item, index) =>
597
609
  {
610
+ const optionName = objectValues ? item.name : item;
611
+ const optionValue = objectValues ? item.value : item;
598
612
  let option = document.createElement('option');
599
- option.setAttribute('value', item);
600
- option.textContent = item;
613
+ option.setAttribute('value', optionValue);
614
+ option.textContent = optionName;
601
615
  select.append(option);
602
616
 
603
- if (value == index) {
617
+ if (!objectValues && value == index || objectValues && value == optionValue) {
604
618
  option.setAttribute('selected', '');
605
619
  }
606
620
  });
@@ -609,23 +623,33 @@ export default class GUI {
609
623
  if ( isObject ) {
610
624
  Object.defineProperty( obj, prop, {
611
625
  set: val => {
612
- let index, value;
613
- if (typeof val == 'string') {
614
- index = values.indexOf(val);
615
- value = val;
616
- }
617
- if (typeof val == 'number') {
618
- index = val;
619
- value = values[val];
626
+ let newIndex, newValue, newObj;
627
+ if (objectValues) {
628
+ newObj = values.find(item => item.value == val);
629
+ newValue = newObj.value;
630
+ newIndex = values.indexOf(newObj);
631
+ } else {
632
+ if (typeof val == 'string') {
633
+ newIndex = values.indexOf(val);
634
+ newValue = val;
635
+ }
636
+ if (typeof val == 'number') {
637
+ newIndex = val;
638
+ newValue = values[val];
639
+ }
620
640
  }
621
641
 
622
- this.propReferences[propReferenceIndex] = val;
642
+ this.propReferences[propReferenceIndex] = objectValues ? newValue : val;
623
643
 
624
644
  select.querySelector('[selected]').removeAttribute('selected')
625
- select.querySelectorAll('option')[index].setAttribute('selected', '');
645
+ select.querySelectorAll('option')[newIndex].setAttribute('selected', '');
626
646
 
627
647
  if (typeof callback == 'function') {
628
- callback(value, index);
648
+ if (objectValues) {
649
+ callback(newObj, newIndex);
650
+ } else {
651
+ callback(newValue, newIndex);
652
+ }
629
653
  }
630
654
  },
631
655
  get: () => {
package/src/styles.js CHANGED
@@ -310,7 +310,7 @@ export default function( position_type ) {
310
310
 
311
311
  .p-gui__slider {
312
312
  width: 100%;
313
- margin-bottom: 8px;
313
+ margin-bottom: 10px;
314
314
  padding: 7px;
315
315
  color: white;
316
316
  position: relative;