perfect-gui 5.1.0 → 5.1.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.
package/README.md CHANGED
@@ -13,6 +13,7 @@
13
13
  - **Modern UI**: Clean, customizable, and polished design right out of the box.
14
14
  - **Rich Inputs**: Support for sliders, buttons, color pickers, vectors, images, lists, and toggles.
15
15
  - **Folders**: Easily group and organize your controls in collapsible sections.
16
+ - **Tabs**: Create tabbed interfaces to organize content in separate panels.
16
17
  - **Draggable & Auto-positioned**: Snap it to screen edges or let the user drag it anywhere.
17
18
  - **Data Binding**: Automatically sync your controls with object properties.
18
19
  - **Zero Dependencies**: Lightweight and built with vanilla JavaScript.
@@ -110,4 +111,5 @@ See the [Documentation](https://thibka.github.io/perfect-gui/) for a comprehensi
110
111
  - [`color()`](https://thibka.github.io/perfect-gui/public/#color)
111
112
  - [`vector2()`](https://thibka.github.io/perfect-gui/public/#vector2)
112
113
  - [`folder()`](https://thibka.github.io/perfect-gui/public/#folder)
114
+ - [`tabs()`](https://thibka.github.io/perfect-gui/public/#tabs)
113
115
  - [`toggleClose()`](https://thibka.github.io/perfect-gui/public)
@@ -543,7 +543,7 @@ class C {
543
543
  typeof t.onUpdate == "function" && (this.onUpdate = t.onUpdate), this.label = t != null && typeof t.label == "string" ? t.label : "", this.backgroundColor = t.color || null, this.opacity = t.opacity || 1, this.container == document.body ? this.maxHeight = window.innerHeight : this.maxHeight = Math.min(
544
544
  this.container.clientHeight,
545
545
  window.innerHeight
546
- ), t.maxHeight && (this.initMaxHeight = t.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), this.screenCorner = this._parseScreenCorner(t.position), window.perfectGUI || (window.perfectGUI = {}), window.perfectGUI.instanceCounter == null ? window.perfectGUI.instanceCounter = 0 : window.perfectGUI.instanceCounter++, this.instanceId = window.perfectGUI.instanceCounter, this.wrapperWidth = t.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(`${oe(this.position_type)}`), this._styleInstance(), this._addWrapper(), this.domElement.setAttribute("data-corner-x", this.screenCorner.x), this.domElement.setAttribute("data-corner-y", this.screenCorner.y), t.autoRepositioning != !1 && window.addEventListener("resize", this._handleResize.bind(this)), this._handleResize(), this.hasBeenDragged = !1, t.draggable == !0 && this._makeDraggable(), this.closed = !1, t.closed && this.toggleClose();
546
+ ), t.maxHeight && (this.initMaxHeight = t.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), this.screenCorner = this._parseScreenCorner(t.position), window.perfectGUI || (window.perfectGUI = {}), window.perfectGUI.instanceCounter == null ? window.perfectGUI.instanceCounter = 0 : window.perfectGUI.instanceCounter++, this.instanceId = window.perfectGUI.instanceCounter, this.wrapperWidth = t.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(`${oe(this.position_type)}`), this._styleInstance(), this.closed = !!t.closed, this._addWrapper(), this.domElement.setAttribute("data-corner-x", this.screenCorner.x), this.domElement.setAttribute("data-corner-y", this.screenCorner.y), t.autoRepositioning != !1 && window.addEventListener("resize", this._handleResize.bind(this)), this._handleResize(), this.hasBeenDragged = !1, t.draggable == !0 && this._makeDraggable();
547
547
  }
548
548
  _styleInstance() {
549
549
  let t = this._getScrollbarWidth(this.container);
@@ -603,7 +603,7 @@ class C {
603
603
  this.stylesheet.innerHTML += t;
604
604
  }
605
605
  _addWrapper() {
606
- this.domElement = document.createElement("div"), this.domElement.id = "p-gui-" + this.instanceId, this.domElement.className = "p-gui", this.domElement.setAttribute("data-lenis-prevent", ""), this.container.append(this.domElement), this.header = document.createElement("div"), this.header.className = "p-gui__header", this.header.textContent = this.label, this.header.style = `${this.backgroundColor ? "border-color: " + this.backgroundColor + ";" : ""}`, this.domElement.append(this.header);
606
+ this.domElement = document.createElement("div"), this.domElement.id = "p-gui-" + this.instanceId, this.domElement.className = "p-gui" + (this.closed ? " p-gui--collapsed" : ""), this.domElement.setAttribute("data-lenis-prevent", ""), this.container.append(this.domElement), this.header = document.createElement("div"), this.header.className = "p-gui__header", this.header.textContent = this.label, this.header.style = `${this.backgroundColor ? "border-color: " + this.backgroundColor + ";" : ""}`, this.domElement.append(this.header);
607
607
  const t = document.createElement("div");
608
608
  t.className = "p-gui__header-close", t.addEventListener("click", this.toggleClose.bind(this)), this.header.append(t);
609
609
  const e = document.createElement("div");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "perfect-gui",
3
3
  "type": "module",
4
- "version": "5.1.0",
4
+ "version": "5.1.2",
5
5
  "description": "GUI for JavaScript",
6
6
  "main": "dist/perfect-gui.js",
7
7
  "module": "dist/perfect-gui.js",
@@ -91,17 +91,18 @@ export default class Slider {
91
91
 
92
92
  // init position
93
93
  setTimeout(() => {
94
+ const sliderWidth = this.ctrlDiv.offsetWidth;
94
95
  const handleWidth = this.handle.offsetWidth;
95
96
  this.handle.position = this._mapLinear(
96
97
  this.valueInput.value,
97
98
  this.min,
98
99
  this.max,
99
100
  handleWidth / 2,
100
- 88 - handleWidth / 2,
101
+ sliderWidth - handleWidth / 2,
101
102
  );
102
103
  this.handle.position = Math.min(
103
104
  this.handle.position,
104
- 88 - handleWidth / 2,
105
+ sliderWidth - handleWidth / 2,
105
106
  );
106
107
  this.handle.position = Math.max(
107
108
  this.handle.position,
@@ -126,6 +127,10 @@ export default class Slider {
126
127
  this.ctrlDiv.pointerDown = false;
127
128
  });
128
129
 
130
+ window.addEventListener('pointercancel', (evt) => {
131
+ this.ctrlDiv.pointerDown = false;
132
+ });
133
+
129
134
  window.addEventListener('pointermove', (evt) => {
130
135
  if (this.ctrlDiv.pointerDown) {
131
136
  this.ctrlDiv.pointerDelta =
@@ -154,14 +159,15 @@ export default class Slider {
154
159
  }
155
160
 
156
161
  _updateHandlePositionFromPointer(evt, firstDown = false) {
157
- const sliderWidth = this.ctrlDiv.offsetWidth;
162
+ const rect = this.ctrlDiv.getBoundingClientRect();
163
+ const sliderWidth = rect.width;
158
164
  const handleWidth = this.handle.offsetWidth;
159
165
  const pointerDelta = evt.clientX - this.ctrlDiv.prevPosition;
160
166
  const currentValue = parseFloat(this.valueInput.value);
161
167
  let handlePosition;
162
168
 
163
169
  if (firstDown) {
164
- handlePosition = evt.offsetX;
170
+ handlePosition = evt.clientX - rect.left;
165
171
  } else {
166
172
  handlePosition = this.handle.position + pointerDelta;
167
173
  }
package/src/index.js CHANGED
@@ -81,6 +81,7 @@ export default class GUI {
81
81
  // Instance specific styles
82
82
  this._styleInstance();
83
83
 
84
+ this.closed = !!options.closed;
84
85
  this._addWrapper();
85
86
  this.domElement.setAttribute('data-corner-x', this.screenCorner.x);
86
87
  this.domElement.setAttribute('data-corner-y', this.screenCorner.y);
@@ -92,9 +93,6 @@ export default class GUI {
92
93
 
93
94
  this.hasBeenDragged = false;
94
95
  if (options.draggable == true) this._makeDraggable();
95
-
96
- this.closed = false;
97
- if (options.closed) this.toggleClose();
98
96
  }
99
97
 
100
98
  _styleInstance() {
@@ -245,7 +243,7 @@ export default class GUI {
245
243
  _addWrapper() {
246
244
  this.domElement = document.createElement('div');
247
245
  this.domElement.id = 'p-gui-' + this.instanceId;
248
- this.domElement.className = 'p-gui';
246
+ this.domElement.className = 'p-gui' + (this.closed ? ' p-gui--collapsed' : '');
249
247
  this.domElement.setAttribute('data-lenis-prevent', '');
250
248
  this.container.append(this.domElement);
251
249
 
@@ -8,6 +8,7 @@
8
8
  color: var(--color-text-dark);
9
9
  transition: color var(--transition);
10
10
  padding: 3px;
11
+ touch-action: none;
11
12
  }
12
13
 
13
14
  .p-gui__slider:hover {
@@ -32,6 +33,7 @@
32
33
  height: 14px;
33
34
  margin: 0 0 0 auto;
34
35
  width: 37%;
36
+ touch-action: none;
35
37
  }
36
38
 
37
39
  .p-gui__slider-bar {
@@ -51,6 +53,7 @@
51
53
  height: 100%;
52
54
  background: var(--color-accent);
53
55
  width: 0;
56
+ pointer-events: none;
54
57
  }
55
58
 
56
59
  .p-gui__slider:hover .p-gui__slider-filling {