perfect-gui 4.12.0 → 4.12.4

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,78 +1,265 @@
1
- class R {
2
- constructor(e, t = {}, i) {
3
- if (this.parent = e, this.propReferences = [], typeof t != "object")
4
- throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof t}.`);
5
- let l = typeof t.label == "string" && t.label || " ";
1
+ let F = class {
2
+ constructor(t, e = {}, i) {
3
+ this.parent = t;
4
+ let s = "";
5
+ typeof e != "string" ? typeof e == "object" && (e != null && e.hasOwnProperty("label")) ? s = e.label == "" ? " " : e.label : s = " " : s = e == "" ? " " : e;
6
+ const l = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null, a = document.createElement("div");
7
+ return a.className = "p-gui__button", a.textContent = s, l && a.setAttribute("title", l), a.addEventListener("click", () => {
8
+ i && i(), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
9
+ }), typeof e.color == "string" && (a.style.setProperty("--color-accent", e.color), a.style.setProperty("--color-accent-hover", e.hoverColor || e.color)), this.parent.wrapper.append(a), a;
10
+ }
11
+ };
12
+ class M {
13
+ constructor(t, e = {}, i) {
14
+ if (this.parent = t, this.propReferences = [], typeof e != "object")
15
+ throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
16
+ let s = typeof e.label == "string" && e.label || " ";
6
17
  this.isObject = !1;
7
- let s = null;
8
- this.obj = t.obj, this.prop = t.prop;
9
- let o = typeof t.value == "number" ? t.value : null;
10
- if (this.min = t.min ?? 0, this.max = t.max ?? 1, this.step = t.step || (this.max - this.min) / 100, this.decimals = this.parent._countDecimals(this.step), this.callback = typeof i == "function" ? i : null, o !== null)
18
+ let l = null;
19
+ this.obj = e.obj, this.prop = e.prop;
20
+ let a = typeof e.value == "number" ? e.value : null;
21
+ if (this.min = e.min ?? 0, this.max = e.max ?? 1, this.step = e.step || (this.max - this.min) / 100, this.decimals = this.parent._countDecimals(this.step), this.callback = typeof i == "function" ? i : null, a !== null)
11
22
  (this.prop != null || this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
12
23
  else if (this.prop != null && this.obj != null) {
13
24
  if (typeof this.prop != "string")
14
25
  throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof this.prop}.`);
15
26
  if (typeof this.obj != "object")
16
27
  throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof this.obj}.`);
17
- l == " " && (l = this.prop), s = this.propReferences.push(this.obj[this.prop]) - 1, this.isObject = !0;
28
+ s == " " && (s = this.prop), l = this.propReferences.push(this.obj[this.prop]) - 1, this.isObject = !0;
18
29
  } else
19
- (this.prop != null && this.obj == null || this.prop == null && this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), o = (this.max - this.min) / 2;
20
- const r = typeof t.tooltip == "string" ? t.tooltip : t.tooltip === !0 ? l : null;
21
- this.imageContainer = null;
22
- const n = document.createElement("div");
23
- n.className = "p-gui__slider", r && n.setAttribute("title", r);
24
- const c = document.createElement("div");
25
- c.className = "p-gui__slider-name", c.textContent = l, n.append(c), this.ctrlDiv = document.createElement("div"), this.ctrlDiv.className = "p-gui__slider-ctrl", this.ctrlDiv.setAttribute("type", "range"), this.ctrlDiv.setAttribute("min", this.min), this.ctrlDiv.setAttribute("max", this.max), n.append(this.ctrlDiv);
26
- const a = document.createElement("div");
27
- return a.className = "p-gui__slider-bar", this.ctrlDiv.append(a), this.handle = document.createElement("div"), this.handle.className = "p-gui__slider-handle", this.ctrlDiv.append(this.handle), this.filling = document.createElement("div"), this.filling.className = "p-gui__slider-filling", a.append(this.filling), this.valueInput = document.createElement("input"), this.valueInput.className = "p-gui__slider-value", this.valueInput.value = this.isObject ? this.obj[this.prop] : o, n.append(this.valueInput), setTimeout(() => {
28
- const d = this.handle.offsetWidth;
29
- this.handle.position = this._mapLinear(this.valueInput.value, this.min, this.max, d / 2, 88 - d / 2), this.handle.position = Math.min(this.handle.position, 88 - d / 2), this.handle.position = Math.max(this.handle.position, d / 2), this.handle.style.transform = `translate(-50%, -50%) translateX(${this.handle.position}px)`, this.filling.style.width = `${this.handle.position}px`;
30
+ (this.prop != null && this.obj == null || this.prop == null && this.obj != null) && console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'), a = (this.max - this.min) / 2;
31
+ const o = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null, r = document.createElement("div");
32
+ r.className = "p-gui__slider", o && r.setAttribute("title", o), this.parent.wrapper.append(r);
33
+ const p = document.createElement("div");
34
+ p.className = "p-gui__slider-name", p.textContent = s, r.append(p), this.ctrlDiv = document.createElement("div"), this.ctrlDiv.className = "p-gui__slider-ctrl", this.ctrlDiv.setAttribute("type", "range"), this.ctrlDiv.setAttribute("min", this.min), this.ctrlDiv.setAttribute("max", this.max), r.append(this.ctrlDiv);
35
+ const u = document.createElement("div");
36
+ return u.className = "p-gui__slider-bar", this.ctrlDiv.append(u), this.handle = document.createElement("div"), this.handle.className = "p-gui__slider-handle", this.ctrlDiv.append(this.handle), this.filling = document.createElement("div"), this.filling.className = "p-gui__slider-filling", u.append(this.filling), this.valueInput = document.createElement("input"), this.valueInput.className = "p-gui__slider-value", this.valueInput.value = this.isObject ? this.obj[this.prop] : a, r.append(this.valueInput), setTimeout(() => {
37
+ const n = this.handle.offsetWidth;
38
+ this.handle.position = this._mapLinear(this.valueInput.value, this.min, this.max, n / 2, 88 - n / 2), this.handle.position = Math.min(this.handle.position, 88 - n / 2), this.handle.position = Math.max(this.handle.position, n / 2), this.handle.style.transform = `translate(-50%, -50%) translateX(${this.handle.position}px)`, this.filling.style.width = `${this.handle.position}px`;
30
39
  }, 0), this.valueInput.addEventListener("change", () => {
31
40
  this._updateHandlePositionFromValue(), this._triggerCallbacks();
32
- }), this.ctrlDiv.addEventListener("pointerdown", (d) => {
33
- this.ctrlDiv.pointerDown = !0, this.ctrlDiv.prevPosition = d.clientX, this._updateHandlePositionFromPointer(d, !0);
34
- }), window.addEventListener("pointerup", (d) => {
41
+ }), this.ctrlDiv.addEventListener("pointerdown", (n) => {
42
+ this.ctrlDiv.pointerDown = !0, this.ctrlDiv.prevPosition = n.clientX, this._updateHandlePositionFromPointer(n, !0);
43
+ }), window.addEventListener("pointerup", (n) => {
35
44
  this.ctrlDiv.pointerDown = !1;
36
- }), window.addEventListener("pointermove", (d) => {
37
- this.ctrlDiv.pointerDown && (this.ctrlDiv.pointerDelta = d.clientX - this.ctrlDiv.prevPosition, this._updateHandlePositionFromPointer(d));
45
+ }), window.addEventListener("pointermove", (n) => {
46
+ this.ctrlDiv.pointerDown && (this.ctrlDiv.pointerDelta = n.clientX - this.ctrlDiv.prevPosition, this._updateHandlePositionFromPointer(n));
38
47
  }), this.isObject && Object.defineProperty(this.obj, this.prop, {
39
- set: (d) => {
40
- this.propReferences[s] = d, this.valueInput.value = d, this._updateHandlePositionFromValue(), this.callback && this.callback(parseFloat(this.valueInput.value));
48
+ set: (n) => {
49
+ this.propReferences[l] = n, this.valueInput.value = n, this._updateHandlePositionFromValue(), this.callback && this.callback(parseFloat(this.valueInput.value));
41
50
  },
42
- get: () => this.propReferences[s]
43
- }), n;
51
+ get: () => this.propReferences[l]
52
+ }), r;
44
53
  }
45
- _updateHandlePositionFromPointer(e, t = !1) {
46
- const i = this.ctrlDiv.offsetWidth, l = this.handle.offsetWidth, s = e.clientX - this.ctrlDiv.prevPosition, o = parseFloat(this.valueInput.value);
47
- let r;
48
- t ? r = e.offsetX : r = this.handle.position + s, r = Math.max(l / 2, Math.min(r, i - l / 2));
49
- let n = this.min + (this.max - this.min) * (r - l / 2) / (i - l);
50
- n > o ? n = this._quantizeFloor(n, this.step) : n = this._quantizeCeil(n, this.step), n = parseFloat(n.toFixed(9));
51
- const c = parseFloat((o + this.step).toFixed(9)), a = parseFloat((o - this.step).toFixed(9));
52
- (n >= c || n <= a) && (n = n.toFixed(this.decimals), this.valueInput.value = n, this.ctrlDiv.prevPosition = e.clientX, this.handle.style.transform = `translate(-50%, -50%) translateX(${r}px)`, this.handle.position = r, this.filling.style.width = this.handle.position + "px", this._triggerCallbacks());
54
+ _updateHandlePositionFromPointer(t, e = !1) {
55
+ const i = this.ctrlDiv.offsetWidth, s = this.handle.offsetWidth, l = t.clientX - this.ctrlDiv.prevPosition, a = parseFloat(this.valueInput.value);
56
+ let o;
57
+ e ? o = t.offsetX : o = this.handle.position + l, o = Math.max(s / 2, Math.min(o, i - s / 2));
58
+ let r = this.min + (this.max - this.min) * (o - s / 2) / (i - s);
59
+ r > a ? r = this._quantizeFloor(r, this.step) : r = this._quantizeCeil(r, this.step), r = parseFloat(r.toFixed(9));
60
+ const p = parseFloat((a + this.step).toFixed(9)), u = parseFloat((a - this.step).toFixed(9));
61
+ (r >= p || r <= u) && (r = r.toFixed(this.decimals), this.valueInput.value = r, this.ctrlDiv.prevPosition = t.clientX, this.handle.style.transform = `translate(-50%, -50%) translateX(${o}px)`, this.handle.position = o, this.filling.style.width = this.handle.position + "px", this._triggerCallbacks());
53
62
  }
54
63
  _updateHandlePositionFromValue() {
55
- const e = this.ctrlDiv.offsetWidth, t = this.handle.offsetWidth;
56
- let i = this._mapLinear(this.valueInput.value, this.min, this.max, t / 2, e - t / 2);
57
- i = Math.max(t / 2, Math.min(i, e - t / 2)), this.handle.style.transform = `translate(-50%, -50%) translateX(${i}px)`, this.handle.position = i, this.filling.style.width = this.handle.position + "px";
64
+ const t = this.ctrlDiv.offsetWidth, e = this.handle.offsetWidth;
65
+ let i = this._mapLinear(this.valueInput.value, this.min, this.max, e / 2, t - e / 2);
66
+ i = Math.max(e / 2, Math.min(i, t - e / 2)), this.handle.style.transform = `translate(-50%, -50%) translateX(${i}px)`, this.handle.position = i, this.filling.style.width = this.handle.position + "px";
58
67
  }
59
68
  _triggerCallbacks() {
60
69
  this.isObject ? this.obj[this.prop] = parseFloat(this.valueInput.value) : this.callback && this.callback(parseFloat(this.valueInput.value)), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
61
70
  }
62
- _mapLinear(e, t, i, l, s) {
63
- return l + (e - t) * (s - l) / (i - t);
71
+ _mapLinear(t, e, i, s, l) {
72
+ return s + (t - e) * (l - s) / (i - e);
64
73
  }
65
- _quantize(e, t) {
66
- return t * Math.round(e / t);
74
+ _quantize(t, e) {
75
+ return e * Math.round(t / e);
67
76
  }
68
- _quantizeCeil(e, t) {
69
- return t * Math.ceil(e / t);
77
+ _quantizeCeil(t, e) {
78
+ return e * Math.ceil(t / e);
70
79
  }
71
- _quantizeFloor(e, t) {
72
- return t * Math.floor(e / t);
80
+ _quantizeFloor(t, e) {
81
+ return e * Math.floor(t / e);
73
82
  }
74
83
  }
75
- const P = (
84
+ class H {
85
+ constructor(t, e = {}, i) {
86
+ if (this.parent = t, typeof e != "object")
87
+ throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);
88
+ let s;
89
+ if (typeof e.path == "string")
90
+ s = e.path;
91
+ else
92
+ throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
93
+ let l = s.replace(/^.*[\\\/]/, ""), a;
94
+ e.label == null ? a = l : a = typeof e.label == "string" && e.label || " ";
95
+ const o = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? a : null, r = e.selected === !0, p = e.selectionBorder !== !1;
96
+ let u = "";
97
+ e.width && (typeof e.width == "number" && (e.width += "px"), u += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), u += `height: ${e.height}; `);
98
+ const n = document.createElement("div");
99
+ n.className = "p-gui__image", n.style = "background-image: url(" + s + "); " + u, o && n.setAttribute("title", o), this.parent.imageContainer.append(n), r && p && n.classList.add("p-gui__image--selected");
100
+ const g = document.createElement("div");
101
+ return g.className = "p-gui__image-text", g.textContent = a, n.append(g), n.addEventListener("click", () => {
102
+ let d = n.parentElement.querySelectorAll(".p-gui__image--selected");
103
+ for (let c = 0; c < d.length; c++)
104
+ d[c].classList.remove("p-gui__image--selected");
105
+ p && n.classList.add("p-gui__image--selected"), typeof i == "function" && i({ path: s, text: a }), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
106
+ }), n;
107
+ }
108
+ }
109
+ class N {
110
+ constructor(t, e = {}, i) {
111
+ if (this.parent = t, typeof e != "object")
112
+ throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
113
+ let s = typeof e.label == "string" && e.label || " ", l = !1, a = null, o = e.obj, r = e.prop, p = typeof e.value == "boolean" ? e.value : null;
114
+ if (p !== null)
115
+ (r != null || o != null) && console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
116
+ else if (r != null && o != null) {
117
+ if (typeof r != "string")
118
+ throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof r}.`);
119
+ if (typeof o != "object")
120
+ throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof o}.`);
121
+ s == " " && (s = r), a = this.parent.propReferences.push(o[r]) - 1, l = !0;
122
+ } else
123
+ (r != null && o == null || r == null && o == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
124
+ const u = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null, n = document.createElement("div");
125
+ n.textContent = s, n.className = "p-gui__toggle", u && n.setAttribute("title", u), n.addEventListener("click", (c) => {
126
+ const h = c.target.childNodes[1];
127
+ let f = !0;
128
+ h.classList.contains("p-gui__toggle-checkbox--active") && (f = !1), h.classList.toggle("p-gui__toggle-checkbox--active"), l ? o[r] = f : typeof i == "function" && i(f), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
129
+ });
130
+ let g = (() => l ? o[r] ? " p-gui__toggle-checkbox--active" : "" : p ? " p-gui__toggle-checkbox--active" : "")();
131
+ const d = document.createElement("div");
132
+ return d.className = "p-gui__toggle-checkbox" + g, n.append(d), l && Object.defineProperty(o, r, {
133
+ set: (c) => {
134
+ this.parent.propReferences[a] = c, c ? d.classList.add("p-gui__toggle-checkbox--active") : d.classList.remove("p-gui__toggle-checkbox--active"), typeof i == "function" && i(c);
135
+ },
136
+ get: () => this.parent.propReferences[a]
137
+ }), n;
138
+ }
139
+ }
140
+ class X {
141
+ constructor(t, e = {}, i) {
142
+ if (this.parent = t, typeof e != "object")
143
+ throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
144
+ let s = typeof e.label == "string" ? e.label : " ", l = !1, a = null, o = e.obj, r = e.prop, p = Array.isArray(e.values) ? e.values : null, u, n = typeof p[0] != "string";
145
+ const g = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null;
146
+ if (i = typeof i == "function" ? i : null, e.value !== void 0 || e.value === void 0 && o === void 0 && r === void 0)
147
+ (r != null || o != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'), u = (() => {
148
+ if (!p)
149
+ return null;
150
+ if (typeof e.value == "string")
151
+ return p.indexOf(e.value);
152
+ if (typeof e.value == "number")
153
+ return e.value;
154
+ })();
155
+ else if (r != null && o != null) {
156
+ if (typeof r != "string")
157
+ throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof r}.`);
158
+ if (typeof o != "object")
159
+ throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof o}.`);
160
+ u = (() => {
161
+ if (!p)
162
+ return null;
163
+ if (typeof o[r] == "string")
164
+ return n ? p.find((h) => h.value === o[r]).value : p.indexOf(o[r]);
165
+ if (typeof o[r] == "number")
166
+ return n ? p.find((h) => h.value === o[r]).value : o[r];
167
+ })(), a = this.parent.propReferences.push(o[r]) - 1, l = !0;
168
+ } else
169
+ (r != null && o == null || r == null && o == null) && console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');
170
+ let d = document.createElement("div");
171
+ d.className = "p-gui__list", d.textContent = s, g && d.setAttribute("title", g), this.parent.wrapper.append(d);
172
+ let c = document.createElement("select");
173
+ return d.append(c), c.className = "p-gui__list-dropdown", c.addEventListener("change", (h) => {
174
+ l ? o[r] = h.target.value : i && i(h.target.value), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
175
+ }), p && p.forEach((h, f) => {
176
+ const b = n ? h.label : h, v = n ? h.value : h;
177
+ let m = document.createElement("option");
178
+ m.setAttribute("value", v), m.textContent = b, c.append(m), (!n && u == f || n && u == v) && m.setAttribute("selected", "");
179
+ }), l && Object.defineProperty(o, r, {
180
+ set: (h) => {
181
+ let f, b, v;
182
+ n ? (v = p.find((w) => w.value == h), b = (v == null ? void 0 : v.value) || p[0].value, f = p.indexOf(v)) : (typeof h == "string" && (f = p.indexOf(h), b = h), typeof h == "number" && (f = h, b = p[h])), this.parent.propReferences[a] = n ? b : h;
183
+ const m = c.querySelector("[selected]");
184
+ m && m.removeAttribute("selected"), c.querySelectorAll("option")[f].setAttribute("selected", ""), typeof i == "function" && i(n ? v : b, f);
185
+ },
186
+ get: () => this.parent.propReferences[a]
187
+ }), d;
188
+ }
189
+ }
190
+ class S {
191
+ constructor(t, e = {}, i) {
192
+ if (this.parent = t, typeof e != "object")
193
+ throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
194
+ let s = typeof e.label == "string" && e.label || " ", l = !1, a = null, o = e.obj, r = e.prop, p;
195
+ const u = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null;
196
+ 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}".`) : p = e.value), p || (p = "#000000"), e.value !== void 0)
197
+ (r != null || o != null) && console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
198
+ else if (r != null && o != null) {
199
+ if (typeof r != "string")
200
+ throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof r}.`);
201
+ if (typeof o != "object")
202
+ throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof o}.`);
203
+ s == " " && (s = r), a = this.parent.propReferences.push(o[r]) - 1, l = !0;
204
+ } else
205
+ (r != null && o == null || r == null && o == null) && console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');
206
+ const n = document.createElement("div");
207
+ n.className = "p-gui__color", n.textContent = s, u && n.setAttribute("title", u), this.parent.wrapper.append(n);
208
+ const g = document.createElement("input");
209
+ return g.className = "p-gui__color-picker", g.setAttribute("type", "color"), g.value = p, n.append(g), typeof i == "function" && g.addEventListener("input", () => {
210
+ l ? o[r] = g.value : typeof i == "function" && i(g.value), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
211
+ }), l && Object.defineProperty(o, r, {
212
+ set: (d) => {
213
+ this.parent.propReferences[a] = d, g.value = d, typeof i == "function" && i(d);
214
+ },
215
+ get: () => this.parent.propReferences[a]
216
+ }), n;
217
+ }
218
+ }
219
+ class W {
220
+ constructor(t, e = {}, i) {
221
+ if (this.parent = t, typeof e != "object")
222
+ throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
223
+ let s = typeof e.label == "string" && e.label || " ";
224
+ const l = e.x.min ?? 0, a = e.x.max ?? 1, o = e.y.min ?? 0, r = e.y.max ?? 1, p = e.x.step || (a - l) / 100, u = e.y.step || (r - o) / 100, n = this.parent._countDecimals(p), g = this.parent._countDecimals(u), d = e.x.obj, c = e.x.prop, h = this.parent.propReferences.push(d[c]) - 1, f = e.y.obj, b = e.y.prop, v = this.parent.propReferences.push(f[b]) - 1, m = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null;
225
+ i = typeof i == "function" ? i : null;
226
+ const w = document.createElement("div");
227
+ w.className = "p-gui__vector2", w.textContent = s, m && w.setAttribute("title", m), this.parent.wrapper.append(w);
228
+ const k = document.createElement("div");
229
+ k.className = "p-gui__vector-value", k.textContent = d[c] + ", " + f[b], w.append(k);
230
+ const _ = document.createElement("div");
231
+ _.className = "p-gui__vector2-area", w.append(_), _.addEventListener("click", (x) => {
232
+ const E = parseFloat(this.parent._mapLinear(x.offsetX, 0, _.clientWidth, l, a)), j = parseFloat(this.parent._mapLinear(x.offsetY, 0, _.clientHeight, r, o));
233
+ d[c] = E.toFixed(n), f[b] = j.toFixed(g), i && i(d[c], d[b]), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
234
+ });
235
+ const U = (x) => {
236
+ const E = _.getBoundingClientRect(), j = x.clientX - E.left, P = x.clientY - E.top, $ = this.parent._mapLinear(j, 0, _.clientWidth, l, a), O = this.parent._mapLinear(P, 0, _.clientHeight, r, o), D = Math.max(l, Math.min(a, $)), L = Math.max(o, Math.min(r, O));
237
+ d[c] = parseFloat(D.toFixed(n)), f[b] = parseFloat(L.toFixed(g)), i && i(d[c], f[b]), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
238
+ };
239
+ _.addEventListener("pointerdown", (x) => {
240
+ U(x), document.addEventListener("pointermove", U), document.addEventListener("pointerup", () => {
241
+ document.removeEventListener("pointermove", U);
242
+ }, { once: !0 });
243
+ });
244
+ const C = document.createElement("div");
245
+ C.className = "p-gui__vector2-line p-gui__vector2-line-x", _.append(C);
246
+ const R = document.createElement("div");
247
+ R.className = "p-gui__vector2-line p-gui__vector2-line-y", _.append(R);
248
+ const A = document.createElement("div");
249
+ return A.className = "p-gui__vector2-dot", _.append(A), A.style.left = this.parent._mapLinear(d[c], l, a, 0, _.clientWidth) + "px", A.style.top = this.parent._mapLinear(f[b], o, r, _.clientHeight, 0) + "px", Object.defineProperty(d, c, {
250
+ set: (x) => {
251
+ this.parent.propReferences[h] = x, A.style.left = this.parent._mapLinear(x, l, a, 0, _.clientWidth) + "px", k.textContent = String(x) + ", " + f[b];
252
+ },
253
+ get: () => this.parent.propReferences[h]
254
+ }), Object.defineProperty(f, b, {
255
+ set: (x) => {
256
+ this.parent.propReferences[v] = x, A.style.top = this.parent._mapLinear(x, o, r, _.clientHeight, 0) + "px", k.textContent = d[c] + ", " + String(x);
257
+ },
258
+ get: () => this.parent.propReferences[v]
259
+ }), w;
260
+ }
261
+ }
262
+ const G = (
76
263
  /* css */
77
264
  `
78
265
  .p-gui__button {
@@ -94,7 +281,7 @@ const P = (
94
281
  margin-inline: 0;
95
282
  }
96
283
  `
97
- ), O = (
284
+ ), Y = (
98
285
  /* css */
99
286
  `
100
287
  .p-gui__slider {
@@ -147,7 +334,7 @@ const P = (
147
334
  position: absolute;
148
335
  top: -25%;
149
336
  left: 0;
150
- height: 150%;
337
+ height: 100%;
151
338
  background: var(--color-accent);
152
339
  width: 0;
153
340
  }
@@ -157,8 +344,8 @@ const P = (
157
344
  }
158
345
 
159
346
  .p-gui__slider-handle {
160
- width: 15px;
161
- height: 8px;
347
+ width: 9px;
348
+ height: 9px;
162
349
  position: absolute;
163
350
  top: 50%;
164
351
  left: 0;
@@ -189,7 +376,7 @@ const P = (
189
376
  outline: none;
190
377
  }
191
378
  `
192
- ), $ = (
379
+ ), B = (
193
380
  /* css */
194
381
  `
195
382
  .p-gui__list {
@@ -231,44 +418,43 @@ const P = (
231
418
  background: rgba(255, 255, 255, .1);
232
419
  }
233
420
  `
234
- ), D = (
421
+ ), z = (
235
422
  /* css */
236
423
  `
237
- .p-gui__switch {
238
- background: rgba(255, 255, 255, .05);
424
+ .p-gui__toggle {
239
425
  color: var(--color-text-dark);
240
426
  transition: var(--transition) background, var(--transition) color;
241
427
  }
242
428
 
243
- .p-gui__switch:hover {
429
+ .p-gui__toggle:hover {
244
430
  background: rgba(255, 255, 255, .1);
245
431
  color: var(--color-text-light);
246
432
  }
247
433
 
248
- .p-gui__folder .p-gui__switch {
434
+ .p-gui__folder .p-gui__toggle {
249
435
  margin-inline: 0;
250
436
  }
251
437
 
252
- .p-gui__switch-checkbox {
253
- width: 5px;
254
- height: 5px;
255
- background-color: rgba(0, 0, 0, .5);
256
- border: 1px solid grey;
438
+ .p-gui__toggle-checkbox {
439
+ width: 10px;
440
+ height: 10px;
441
+ background-color: rgba(255, 255, 255, 0.1);
257
442
  position: absolute;
258
443
  top: 0;
259
444
  right: 10px;
260
445
  bottom: 0;
261
446
  margin: auto;
262
- border-radius: 50%;
447
+ border-radius: 2px;
263
448
  pointer-events: none;
449
+ transition: .5s all ease;
264
450
  }
265
451
 
266
- .p-gui__switch-checkbox--active {
267
- background-color: #00ff89;
268
- box-shadow: 0 0 7px #00ff89;
452
+ .p-gui__toggle-checkbox--active {
453
+ background-color: #ddd;
454
+ box-shadow: 0 0 5px #ddd;
269
455
  }
270
456
  `
271
- ), F = (
457
+ ), V = (
272
458
  /* css */
273
459
  `
274
460
  .p-gui__color {
@@ -306,7 +492,7 @@ const P = (
306
492
  border: none;
307
493
  }
308
494
  `
309
- ), L = (
495
+ ), T = (
310
496
  /* css */
311
497
  `
312
498
  .p-gui__vector2 {
@@ -371,7 +557,7 @@ const P = (
371
557
  position: absolute;
372
558
  }
373
559
  `
374
- ), H = (
560
+ ), Q = (
375
561
  /* css */
376
562
  `
377
563
  .p-gui__image-container {
@@ -427,13 +613,13 @@ const P = (
427
613
 
428
614
  }
429
615
  `
430
- ), N = (
616
+ ), q = (
431
617
  /* css */
432
618
  `
433
619
  .p-gui__folder {
434
620
  width: 100%;
435
621
  position: relative;
436
- background: #333333;
622
+ background: var(--color-bg);
437
623
  overflow: auto;
438
624
  margin-bottom: 2px;
439
625
  display: flex;
@@ -482,13 +668,13 @@ const P = (
482
668
  }
483
669
  `
484
670
  );
485
- function M(j) {
671
+ function J(y) {
486
672
  return (
487
673
  /* css */
488
674
  `
489
675
  .p-gui {
490
676
  --main-border-radius: 3px;
491
- --color-bg: #121212;
677
+ --color-bg: #161616;
492
678
  --color-border: #222222;
493
679
  --color-border-2: transparent;
494
680
  --color-text-light: #ffffff;
@@ -497,7 +683,7 @@ function M(j) {
497
683
  --color-accent-hover: #dddddd;
498
684
  --transition: .1s linear;
499
685
 
500
- position: ${j};
686
+ position: ${y};
501
687
  top: 0;
502
688
  left: 0;
503
689
  transform: translate3d(0,0,0);
@@ -589,7 +775,7 @@ function M(j) {
589
775
 
590
776
  .p-gui__slider,
591
777
  .p-gui__button,
592
- .p-gui__switch,
778
+ .p-gui__toggle,
593
779
  .p-gui__list,
594
780
  .p-gui__vector2,
595
781
  .p-gui__color {
@@ -606,45 +792,45 @@ function M(j) {
606
792
 
607
793
  .p-gui__slider:hover,
608
794
  .p-gui__button:hover,
609
- .p-gui__switch:hover,
795
+ .p-gui__toggle:hover,
610
796
  .p-gui__list:hover,
611
797
  .p-gui__vector2:hover,
612
798
  .p-gui__color:hover {
613
799
  border-color: rgba(255,255,255,.2);
614
800
  }
615
801
 
616
- ${P}
802
+ ${G}
617
803
 
618
- ${H}
804
+ ${Q}
619
805
 
620
- ${$}
806
+ ${B}
621
807
 
622
- ${D}
808
+ ${z}
623
809
 
624
- ${O}
810
+ ${Y}
625
811
 
626
- ${F}
812
+ ${V}
627
813
 
628
- ${L}
814
+ ${T}
629
815
 
630
- ${N}
816
+ ${q}
631
817
  `
632
818
  );
633
819
  }
634
- class U {
635
- constructor(e = {}) {
636
- if (this.firstParent = this, e.container ? (this.container = typeof e.container == "string" ? document.querySelector(e.container) : e.container, this.position_type = "absolute") : (this.container = document.body, this.position_type = "fixed"), this.propReferences = [], this.folders = [], e.isFolder) {
637
- this._folderConstructor(e.folderOptions);
820
+ class I {
821
+ constructor(t = {}) {
822
+ if (this.firstParent = this, t.container ? (this.container = typeof t.container == "string" ? document.querySelector(t.container) : t.container, this.position_type = "absolute") : (this.container = document.body, this.position_type = "fixed"), this.propReferences = [], this.folders = [], t.isFolder) {
823
+ this._folderConstructor(t.folderOptions);
638
824
  return;
639
825
  }
640
- typeof e.onUpdate == "function" && (this.onUpdate = e.onUpdate), this.label = e != null && typeof e.label == "string" ? e.label : "", this.backgroundColor = e.color || null, this.opacity = e.opacity || 1, this.container == document.body ? this.maxHeight = window.innerHeight : this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight), e.maxHeight && (this.initMaxHeight = e.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), this.screenCorner = this._parseScreenCorner(e.position), window.perfectGUI || (window.perfectGUI = {}), window.perfectGUI.instanceCounter == null ? window.perfectGUI.instanceCounter = 0 : window.perfectGUI.instanceCounter++, this.instanceId = window.perfectGUI.instanceCounter, this.wrapperWidth = e.width || 290, this.stylesheet = document.createElement("style"), this.stylesheet.setAttribute("type", "text/css"), this.stylesheet.setAttribute("id", "lm-gui-stylesheet"), document.head.append(this.stylesheet), this.instanceId == 0 && this._addStyles(`${M(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();
826
+ 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(this.container.clientHeight, window.innerHeight), 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(`${J(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), 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();
641
827
  }
642
828
  _styleInstance() {
643
- let e = this._getScrollbarWidth(this.container);
644
- if (this.screenCorner.x == "left" ? this.xOffset = 0 : this.xOffset = this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
645
- let t = this.container.querySelectorAll(".p-gui");
646
- for (let i = 0; i < t.length; i++)
647
- this.screenCorner.y == t[i].dataset.cornerY && (this.screenCorner.x == "left" && t[i].dataset.cornerX == "left" ? this.xOffset += t[i].offsetWidth : this.screenCorner.x == "right" && t[i].dataset.cornerX == "right" && (this.xOffset -= t[i].offsetWidth));
829
+ let t = this._getScrollbarWidth(this.container);
830
+ if (this.screenCorner.x == "left" ? this.xOffset = 0 : this.xOffset = this.container.clientWidth - this.wrapperWidth - t, this.instanceId > 0) {
831
+ let e = this.container.querySelectorAll(".p-gui");
832
+ for (let i = 0; i < e.length; i++)
833
+ this.screenCorner.y == e[i].dataset.cornerY && (this.screenCorner.x == "left" && e[i].dataset.cornerX == "left" ? this.xOffset += e[i].offsetWidth : this.screenCorner.x == "right" && e[i].dataset.cornerX == "right" && (this.xOffset -= e[i].offsetWidth));
648
834
  }
649
835
  this.yOffset = 0, this.position = {
650
836
  prevX: this.xOffset,
@@ -660,253 +846,88 @@ class U {
660
846
  opacity: ${this.opacity};
661
847
  }`);
662
848
  }
663
- _folderConstructor(e) {
664
- this.wrapper = e.wrapper, this.isFolder = !0, this.parent = e.parent, this.firstParent = e.firstParent;
849
+ _folderConstructor(t) {
850
+ this.wrapper = t.wrapper, this.isFolder = !0, this.parent = t.parent, this.firstParent = t.firstParent;
665
851
  }
666
- _parseScreenCorner(e) {
667
- let t = { x: "right", y: "top" };
668
- 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;
852
+ _parseScreenCorner(t) {
853
+ let e = { x: "right", y: "top" };
854
+ return t == null || (typeof t != "string" && console.error("[perfect-gui] Position must be a string."), t.includes("left") && (e.x = "left"), t.includes("bottom") && (e.y = "bottom")), e;
669
855
  }
670
- _getScrollbarWidth(e) {
671
- return e === document.body ? window.innerWidth - document.documentElement.clientWidth : e.offsetWidth - e.clientWidth;
856
+ _getScrollbarWidth(t) {
857
+ return t === document.body ? window.innerWidth - document.documentElement.clientWidth : t.offsetWidth - t.clientWidth;
672
858
  }
673
859
  _handleResize() {
674
860
  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)
675
861
  return;
676
- let e = this._getScrollbarWidth(this.container);
677
- if (this.xOffset = this.screenCorner.x == "left" ? 0 : this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
678
- let t = this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);
679
- for (let i = 0; i < t.length && !(parseInt(t[i].id.replace("p-gui-", "")) > this.instanceId); i++)
680
- this.screenCorner.y == t[i].dataset.cornerY && (this.screenCorner.x == "left" && t[i].dataset.cornerX == "left" ? this.xOffset += t[i].offsetWidth : this.screenCorner.x == "right" && t[i].dataset.cornerX == "right" && (this.xOffset -= t[i].offsetWidth));
862
+ let t = this._getScrollbarWidth(this.container);
863
+ if (this.xOffset = this.screenCorner.x == "left" ? 0 : this.container.clientWidth - this.wrapperWidth - t, this.instanceId > 0) {
864
+ let e = this.container.querySelectorAll(`.p-gui:not(#${this.wrapper.id}):not([data-dragged])`);
865
+ for (let i = 0; i < e.length && !(parseInt(e[i].id.replace("p-gui-", "")) > this.instanceId); i++)
866
+ this.screenCorner.y == e[i].dataset.cornerY && (this.screenCorner.x == "left" && e[i].dataset.cornerX == "left" ? this.xOffset += e[i].offsetWidth : this.screenCorner.x == "right" && e[i].dataset.cornerX == "right" && (this.xOffset -= e[i].offsetWidth));
681
867
  }
682
868
  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)`;
683
869
  }
684
- _addStyles(e) {
685
- this.stylesheet.innerHTML += e;
870
+ _addStyles(t) {
871
+ this.stylesheet.innerHTML += t;
686
872
  }
687
873
  _addWrapper() {
688
874
  this.wrapper = document.createElement("div"), this.wrapper.id = "p-gui-" + this.instanceId, this.wrapper.className = "p-gui", this.wrapper.setAttribute("data-lenis-prevent", ""), this.container.append(this.wrapper), 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.wrapper.append(this.header);
689
- const e = document.createElement("div");
690
- e.className = "p-gui__header-close", e.addEventListener("click", this.toggleClose.bind(this)), this.header.append(e);
875
+ const t = document.createElement("div");
876
+ t.className = "p-gui__header-close", t.addEventListener("click", this.toggleClose.bind(this)), this.header.append(t);
691
877
  }
692
- button(e, t) {
693
- let i = "";
694
- typeof e != "string" ? typeof e == "object" && (e != null && e.hasOwnProperty("label")) ? i = e.label == "" ? " " : e.label : i = " " : i = e == "" ? " " : e;
695
- const l = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
696
- this.imageContainer = null;
697
- const s = document.createElement("div");
698
- s.className = "p-gui__button", s.textContent = i, l && s.setAttribute("title", l), s.addEventListener("click", () => {
699
- t && t(), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
700
- }), this.wrapper.append(s), typeof e.color == "string" && (s.style.setProperty("--color-accent", e.color), s.style.setProperty("--color-accent-hover", e.hoverColor || e.color));
878
+ button(t = {}, e) {
879
+ return this.imageContainer = null, new F(this, t, e);
701
880
  }
702
- image(e = {}, t) {
703
- if (typeof e != "object")
704
- throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);
705
- let i;
706
- if (typeof e.path == "string")
707
- i = e.path;
708
- else
709
- throw typeof e.path == null ? Error("[GUI] image() path must be provided.") : Error("[GUI] image() path must be a string.");
710
- let l = i.replace(/^.*[\\\/]/, ""), s;
711
- e.label == null ? s = l : s = typeof e.label == "string" && e.label || " ";
712
- const o = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? s : null, r = e.selected === !0, n = e.selectionBorder !== !1;
713
- let c = "";
714
- e.width && (typeof e.width == "number" && (e.width += "px"), c += `flex: 0 0 calc(${e.width} - 5px); `), e.height && (typeof e.height == "number" && (e.height += "px"), c += `height: ${e.height}; `), this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer));
715
- const a = document.createElement("div");
716
- a.className = "p-gui__image", a.style = "background-image: url(" + i + "); " + c, o && a.setAttribute("title", o), this.imageContainer.append(a), r && n && a.classList.add("p-gui__image--selected");
717
- const d = document.createElement("div");
718
- return d.className = "p-gui__image-text", d.textContent = s, a.append(d), a.addEventListener("click", () => {
719
- let p = a.parentElement.querySelectorAll(".p-gui__image--selected");
720
- for (let h = 0; h < p.length; h++)
721
- p[h].classList.remove("p-gui__image--selected");
722
- n && a.classList.add("p-gui__image--selected"), typeof t == "function" && t({ path: i, text: s }), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
723
- }), a;
724
- }
725
- slider(e = {}, t) {
726
- const i = new R(this, e, t);
727
- this.wrapper.append(i);
728
- }
729
- toggle(e = {}, t) {
730
- if (typeof e != "object")
731
- throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
732
- let i = typeof e.label == "string" && e.label || " ", l = !1, s = null, o = e.obj, r = e.prop, n = typeof e.value == "boolean" ? e.value : null;
733
- if (n !== null)
734
- (r != null || o != null) && console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
735
- else if (r != null && o != null) {
736
- if (typeof r != "string")
737
- throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof r}.`);
738
- if (typeof o != "object")
739
- throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof o}.`);
740
- i == " " && (i = r), s = this.propReferences.push(o[r]) - 1, l = !0;
741
- } else
742
- (r != null && o == null || r == null && o == null) && console.warn('[GUI] toggle() "obj" and "prop" parameters must be used together.');
743
- const c = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
744
- this.imageContainer = null;
745
- const a = document.createElement("div");
746
- a.textContent = i, a.className = "p-gui__switch", c && a.setAttribute("title", c), this.wrapper.append(a), a.addEventListener("click", (h) => {
747
- const u = h.target.childNodes[1];
748
- let f = !0;
749
- u.classList.contains("p-gui__switch-checkbox--active") && (f = !1), u.classList.toggle("p-gui__switch-checkbox--active"), l ? o[r] = f : typeof t == "function" && t(f), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
750
- });
751
- let d = (() => l ? o[r] ? " p-gui__switch-checkbox--active" : "" : n ? " p-gui__switch-checkbox--active" : "")();
752
- const p = document.createElement("div");
753
- p.className = "p-gui__switch-checkbox" + d, a.append(p), l && Object.defineProperty(o, r, {
754
- set: (h) => {
755
- this.propReferences[s] = h, h ? p.classList.add("p-gui__switch-checkbox--active") : p.classList.remove("p-gui__switch-checkbox--active"), typeof t == "function" && t(h);
756
- },
757
- get: () => this.propReferences[s]
758
- });
881
+ image(t = {}, e) {
882
+ return this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer)), new H(this, t, e);
759
883
  }
760
- list(e = {}, t) {
761
- if (typeof e != "object")
762
- throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
763
- let i = typeof e.label == "string" ? e.label : " ", l = !1, s = null, o = e.obj, r = e.prop, n = Array.isArray(e.values) ? e.values : null, c, a = typeof n[0] != "string";
764
- const d = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
765
- if (t = typeof t == "function" ? t : null, e.value !== void 0 || e.value === void 0 && o === void 0 && r === void 0)
766
- (r != null || o != null) && console.warn('[GUI] list() "obj" and "prop" parameters are ignored when a "value" parameter is used.'), c = (() => {
767
- if (!n)
768
- return null;
769
- if (typeof e.value == "string")
770
- return n.indexOf(e.value);
771
- if (typeof e.value == "number")
772
- return e.value;
773
- })();
774
- else if (r != null && o != null) {
775
- if (typeof r != "string")
776
- throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof r}.`);
777
- if (typeof o != "object")
778
- throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof o}.`);
779
- c = (() => {
780
- if (!n)
781
- return null;
782
- if (typeof o[r] == "string")
783
- return a ? n.find((u) => u.value === o[r]).value : n.indexOf(o[r]);
784
- if (typeof o[r] == "number")
785
- return a ? n.find((u) => u.value === o[r]).value : o[r];
786
- })(), s = this.propReferences.push(o[r]) - 1, l = !0;
787
- } else
788
- (r != null && o == null || r == null && o == null) && console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');
789
- this.imageContainer = null;
790
- let p = document.createElement("div");
791
- p.className = "p-gui__list", p.textContent = i, d && p.setAttribute("title", d), this.wrapper.append(p);
792
- let h = document.createElement("select");
793
- p.append(h), h.className = "p-gui__list-dropdown", h.addEventListener("change", (u) => {
794
- l ? o[r] = u.target.value : t && t(u.target.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
795
- }), n && n.forEach((u, f) => {
796
- const g = a ? u.label : u, x = a ? u.value : u;
797
- let v = document.createElement("option");
798
- v.setAttribute("value", x), v.textContent = g, h.append(v), (!a && c == f || a && c == x) && v.setAttribute("selected", "");
799
- }), l && Object.defineProperty(o, r, {
800
- set: (u) => {
801
- let f, g, x;
802
- a ? (x = n.find((m) => m.value == u), g = (x == null ? void 0 : x.value) || n[0].value, f = n.indexOf(x)) : (typeof u == "string" && (f = n.indexOf(u), g = u), typeof u == "number" && (f = u, g = n[u])), this.propReferences[s] = a ? g : u;
803
- const v = h.querySelector("[selected]");
804
- v && v.removeAttribute("selected"), h.querySelectorAll("option")[f].setAttribute("selected", ""), typeof t == "function" && t(a ? x : g, f);
805
- },
806
- get: () => this.propReferences[s]
807
- });
884
+ slider(t = {}, e) {
885
+ return this.imageContainer = null, new M(this, t, e);
808
886
  }
809
- color(e = {}, t) {
810
- if (typeof e != "object")
811
- throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
812
- let i = typeof e.label == "string" && e.label || " ", l = !1, s = null, o = e.obj, r = e.prop, n;
813
- const c = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
814
- 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)
815
- (r != null || o != null) && console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');
816
- else if (r != null && o != null) {
817
- if (typeof r != "string")
818
- throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof r}.`);
819
- if (typeof o != "object")
820
- throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof o}.`);
821
- i == " " && (i = r), s = this.propReferences.push(o[r]) - 1, l = !0;
822
- } else
823
- (r != null && o == null || r == null && o == null) && console.warn('[GUI] color() "obj" and "prop" parameters must be used together.');
887
+ toggle(t = {}, e) {
824
888
  this.imageContainer = null;
825
- const a = document.createElement("div");
826
- a.className = "p-gui__color", a.textContent = i, c && a.setAttribute("title", c), this.wrapper.append(a);
827
- const d = document.createElement("input");
828
- d.className = "p-gui__color-picker", d.setAttribute("type", "color"), d.value = n, a.append(d), typeof t == "function" && d.addEventListener("input", () => {
829
- l ? o[r] = d.value : typeof t == "function" && t(d.value), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
830
- }), l && Object.defineProperty(o, r, {
831
- set: (p) => {
832
- this.propReferences[s] = p, d.value = p, typeof t == "function" && t(p);
833
- },
834
- get: () => this.propReferences[s]
835
- });
889
+ const i = new N(this, t, e);
890
+ return this.wrapper.append(i), i;
836
891
  }
837
- vector2(e = {}, t) {
838
- if (typeof e != "object")
839
- throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
840
- let i = typeof e.label == "string" && e.label || " ";
841
- const l = e.x.min ?? 0, s = e.x.max ?? 1, o = e.y.min ?? 0, r = e.y.max ?? 1, n = e.x.step || (s - l) / 100, c = e.y.step || (r - o) / 100, a = this._countDecimals(n), d = this._countDecimals(c), p = e.x.obj, h = e.x.prop, u = this.propReferences.push(p[h]) - 1, f = e.y.obj, g = e.y.prop, x = this.propReferences.push(f[g]) - 1, v = typeof e.tooltip == "string" ? e.tooltip : e.tooltip === !0 ? i : null;
842
- t = typeof t == "function" ? t : null, this.imageContainer = null;
843
- const m = document.createElement("div");
844
- m.className = "p-gui__vector2", m.textContent = i, v && m.setAttribute("title", v), this.wrapper.append(m);
845
- const y = document.createElement("div");
846
- y.className = "p-gui__vector-value", y.textContent = p[h] + ", " + f[g], m.append(y);
847
- const b = document.createElement("div");
848
- b.className = "p-gui__vector2-area", m.append(b), b.addEventListener("click", (_) => {
849
- const k = parseFloat(this._mapLinear(_.offsetX, 0, b.clientWidth, l, s)), E = parseFloat(this._mapLinear(_.offsetY, 0, b.clientHeight, r, o));
850
- p[h] = k.toFixed(a), f[g] = E.toFixed(d), t && t(p[h], p[g]), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
851
- });
852
- let A = !1;
853
- b.addEventListener("pointerdown", (_) => {
854
- A = !0;
855
- }), b.addEventListener("pointerup", () => {
856
- A = !1;
857
- }), b.addEventListener("pointermove", (_) => {
858
- if (A) {
859
- const k = parseFloat(this._mapLinear(_.offsetX, 0, b.clientWidth, l, s)), E = parseFloat(this._mapLinear(_.offsetY, 0, b.clientHeight, r, o));
860
- p[h] = k.toFixed(a), f[g] = E.toFixed(d), t && t(p[h], p[g]), this.onUpdate ? this.onUpdate() : this.isFolder && this.firstParent.onUpdate && this.firstParent.onUpdate();
861
- }
862
- });
863
- const I = document.createElement("div");
864
- I.className = "p-gui__vector2-line p-gui__vector2-line-x", b.append(I);
865
- const C = document.createElement("div");
866
- C.className = "p-gui__vector2-line p-gui__vector2-line-y", b.append(C);
867
- const w = document.createElement("div");
868
- w.className = "p-gui__vector2-dot", b.append(w), w.style.left = this._mapLinear(p[h], l, s, 0, b.clientWidth) + "px", w.style.top = this._mapLinear(f[g], o, r, b.clientHeight, 0) + "px", Object.defineProperty(p, h, {
869
- set: (_) => {
870
- this.propReferences[u] = _, w.style.left = this._mapLinear(_, l, s, 0, b.clientWidth) + "px", y.textContent = String(_) + ", " + f[g];
871
- },
872
- get: () => this.propReferences[u]
873
- }), Object.defineProperty(f, g, {
874
- set: (_) => {
875
- this.propReferences[x] = _, w.style.top = this._mapLinear(_, o, r, b.clientHeight, 0) + "px", y.textContent = p[h] + ", " + String(_);
876
- },
877
- get: () => this.propReferences[x]
878
- });
892
+ list(t = {}, e) {
893
+ return this.imageContainer = null, new X(this, t, e);
879
894
  }
880
- folder(e = {}) {
881
- let t = typeof e.closed == "boolean" ? e.closed : !1, i = e.label || "", l = e.color || null, s = e.maxHeight || null;
895
+ color(t = {}, e) {
896
+ return this.imageContainer = null, new S(this, t, e);
897
+ }
898
+ vector2(t = {}, e) {
899
+ return this.imageContainer = null, new W(this, t, e);
900
+ }
901
+ folder(t = {}) {
902
+ let e = typeof t.closed == "boolean" ? t.closed : !1, i = t.label || "", s = t.color || null, l = t.maxHeight || null;
882
903
  this.imageContainer = null;
883
- let o = "p-gui__folder";
884
- this.folders.length == 0 && (o += " p-gui__folder--first"), t && (o += " p-gui__folder--closed");
885
- let r = l ? `background-color: ${l};` : "";
886
- r += s ? `max-height: ${s}px;` : "";
887
- const n = document.createElement("div");
888
- n.className = o, n.style = r, this.wrapper.append(n);
889
- const c = document.createElement("div");
890
- c.innerHTML = `<span class="p-gui__folder-arrow"></span>${i}`, c.className = "p-gui__folder-header", n.append(c), c.addEventListener("click", () => {
891
- n.classList.toggle("p-gui__folder--closed");
904
+ let a = "p-gui__folder";
905
+ this.folders.length == 0 && (a += " p-gui__folder--first"), e && (a += " p-gui__folder--closed");
906
+ let o = s ? `background-color: ${s};` : "";
907
+ o += l ? `max-height: ${l}px;` : "";
908
+ const r = document.createElement("div");
909
+ r.className = a, r.style = o, this.wrapper.append(r);
910
+ const p = document.createElement("div");
911
+ p.innerHTML = `<span class="p-gui__folder-arrow"></span>${i}`, p.className = "p-gui__folder-header", r.append(p), p.addEventListener("click", () => {
912
+ r.classList.toggle("p-gui__folder--closed");
892
913
  });
893
- let a = new U({ isFolder: !0, folderOptions: {
894
- wrapper: n,
914
+ let u = new I({ isFolder: !0, folderOptions: {
915
+ wrapper: r,
895
916
  parent: this,
896
917
  firstParent: this.firstParent
897
918
  } });
898
- return this.folders.push(a), a;
919
+ return this.folders.push(u), u;
899
920
  }
900
921
  _makeDraggable() {
901
- var e = this;
902
- this.header.addEventListener("pointerdown", t), this.header.addEventListener("pointerup", l);
903
- function t(s) {
904
- s.preventDefault(), e.position.initX = e.position.x, e.position.initY = e.position.y, e.position.prevX = s.clientX, e.position.prevY = s.clientY, document.addEventListener("pointermove", i);
922
+ var t = this;
923
+ this.header.addEventListener("pointerdown", e), this.header.addEventListener("pointerup", s);
924
+ function e(l) {
925
+ l.preventDefault(), t.position.initX = t.position.x, t.position.initY = t.position.y, t.position.prevX = l.clientX, t.position.prevY = l.clientY, document.addEventListener("pointermove", i);
905
926
  }
906
- function i(s) {
907
- s.preventDefault(), e.hasBeenDragged || (e.hasBeenDragged = !0, e.wrapper.setAttribute("data-dragged", "true")), e.position.x = e.position.initX + s.clientX - e.position.prevX, e.position.y = e.position.initY + s.clientY - e.position.prevY, e.wrapper.style.transform = "translate3d(" + e.position.x + "px," + e.position.y + "px,0)";
927
+ function i(l) {
928
+ l.preventDefault(), t.hasBeenDragged || (t.hasBeenDragged = !0, t.wrapper.setAttribute("data-dragged", "true")), t.position.x = t.position.initX + l.clientX - t.position.prevX, t.position.y = t.position.initY + l.clientY - t.position.prevY, t.wrapper.style.transform = "translate3d(" + t.position.x + "px," + t.position.y + "px,0)";
908
929
  }
909
- function l(s) {
930
+ function s(l) {
910
931
  document.removeEventListener("pointermove", i);
911
932
  }
912
933
  }
@@ -916,18 +937,18 @@ class U {
916
937
  kill() {
917
938
  this.wrapper.remove();
918
939
  }
919
- _mapLinear(e, t, i, l, s) {
920
- return l + (e - t) * (s - l) / (i - t);
940
+ _mapLinear(t, e, i, s, l) {
941
+ return s + (t - e) * (l - s) / (i - e);
921
942
  }
922
- _countDecimals(e) {
923
- const t = e.toString(), i = t.indexOf(".");
924
- return i === -1 ? 0 : t.length - i - 1;
943
+ _countDecimals(t) {
944
+ const e = t.toString(), i = e.indexOf(".");
945
+ return i === -1 ? 0 : e.length - i - 1;
925
946
  }
926
- static registerPlugin(e) {
927
- for (let t in e)
928
- U.prototype[t] = e[t];
947
+ static registerPlugin(t) {
948
+ for (let e in t)
949
+ I.prototype[e] = t[e];
929
950
  }
930
951
  }
931
952
  export {
932
- U as default
953
+ I as default
933
954
  };