perfect-gui 4.12.4 → 4.12.6
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/dist/perfect-gui.js +56 -50
- package/package.json +1 -1
- package/src/components/Vector2.js +16 -4
package/dist/perfect-gui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
let
|
|
1
|
+
let M = class {
|
|
2
2
|
constructor(t, e = {}, i) {
|
|
3
3
|
this.parent = t;
|
|
4
4
|
let s = "";
|
|
@@ -9,7 +9,7 @@ let F = class {
|
|
|
9
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
10
|
}
|
|
11
11
|
};
|
|
12
|
-
class
|
|
12
|
+
class H {
|
|
13
13
|
constructor(t, e = {}, i) {
|
|
14
14
|
if (this.parent = t, this.propReferences = [], typeof e != "object")
|
|
15
15
|
throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);
|
|
@@ -81,7 +81,7 @@ class M {
|
|
|
81
81
|
return e * Math.floor(t / e);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
class
|
|
84
|
+
class N {
|
|
85
85
|
constructor(t, e = {}, i) {
|
|
86
86
|
if (this.parent = t, typeof e != "object")
|
|
87
87
|
throw Error(`[GUI] image() first parameter must be an object. Received: ${typeof e}.`);
|
|
@@ -106,7 +106,7 @@ class H {
|
|
|
106
106
|
}), n;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
class
|
|
109
|
+
class X {
|
|
110
110
|
constructor(t, e = {}, i) {
|
|
111
111
|
if (this.parent = t, typeof e != "object")
|
|
112
112
|
throw Error(`[GUI] toggle() first parameter must be an object. Received: ${typeof e}.`);
|
|
@@ -137,7 +137,7 @@ class N {
|
|
|
137
137
|
}), n;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
class
|
|
140
|
+
class S {
|
|
141
141
|
constructor(t, e = {}, i) {
|
|
142
142
|
if (this.parent = t, typeof e != "object")
|
|
143
143
|
throw Error(`[GUI] list() first parameter must be an object. Received: ${typeof e}.`);
|
|
@@ -187,7 +187,7 @@ class X {
|
|
|
187
187
|
}), d;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
class
|
|
190
|
+
class W {
|
|
191
191
|
constructor(t, e = {}, i) {
|
|
192
192
|
if (this.parent = t, typeof e != "object")
|
|
193
193
|
throw Error(`[GUI] color() first parameter must be an object. Received: ${typeof e}.`);
|
|
@@ -216,7 +216,7 @@ class S {
|
|
|
216
216
|
}), n;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
class
|
|
219
|
+
class G {
|
|
220
220
|
constructor(t, e = {}, i) {
|
|
221
221
|
if (this.parent = t, typeof e != "object")
|
|
222
222
|
throw Error(`[GUI] vector2() first parameter must be an object. Received: ${typeof e}.`);
|
|
@@ -225,41 +225,47 @@ class W {
|
|
|
225
225
|
i = typeof i == "function" ? i : null;
|
|
226
226
|
const w = document.createElement("div");
|
|
227
227
|
w.className = "p-gui__vector2", w.textContent = s, m && w.setAttribute("title", m), this.parent.wrapper.append(w);
|
|
228
|
-
const
|
|
229
|
-
|
|
228
|
+
const A = document.createElement("div");
|
|
229
|
+
A.className = "p-gui__vector-value", A.textContent = d[c] + ", " + f[b], w.append(A);
|
|
230
230
|
const _ = document.createElement("div");
|
|
231
231
|
_.className = "p-gui__vector2-area", w.append(_), _.addEventListener("click", (x) => {
|
|
232
|
-
const
|
|
233
|
-
d[c] =
|
|
232
|
+
const U = parseFloat(this.parent._mapLinear(x.offsetX, 0, _.clientWidth, l, a)), I = parseFloat(this.parent._mapLinear(x.offsetY, 0, _.clientHeight, r, o));
|
|
233
|
+
d[c] = U.toFixed(n), f[b] = I.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
234
|
});
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
d[c] = parseFloat(
|
|
235
|
+
const j = (x) => {
|
|
236
|
+
const U = _.getBoundingClientRect(), I = x.clientX - U.left, O = x.clientY - U.top, $ = this.parent._mapLinear(I, 0, _.clientWidth, l, a), D = this.parent._mapLinear(O, 0, _.clientHeight, r, o), F = Math.max(l, Math.min(a, $)), L = Math.max(o, Math.min(r, D));
|
|
237
|
+
d[c] = parseFloat(F.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
238
|
};
|
|
239
239
|
_.addEventListener("pointerdown", (x) => {
|
|
240
|
-
|
|
241
|
-
document.removeEventListener("pointermove",
|
|
240
|
+
j(x), document.addEventListener("pointermove", j), document.addEventListener("pointerup", () => {
|
|
241
|
+
document.removeEventListener("pointermove", j);
|
|
242
242
|
}, { once: !0 });
|
|
243
243
|
});
|
|
244
|
-
const C = document.createElement("div");
|
|
245
|
-
C.className = "p-gui__vector2-line p-gui__vector2-line-x", _.append(C);
|
|
246
244
|
const R = document.createElement("div");
|
|
247
|
-
R.className = "p-gui__vector2-line p-gui__vector2-line-
|
|
248
|
-
const
|
|
249
|
-
|
|
245
|
+
R.className = "p-gui__vector2-line p-gui__vector2-line-x", _.append(R);
|
|
246
|
+
const P = document.createElement("div");
|
|
247
|
+
P.className = "p-gui__vector2-line p-gui__vector2-line-y", _.append(P);
|
|
248
|
+
const k = document.createElement("div");
|
|
249
|
+
k.className = "p-gui__vector2-dot", _.append(k);
|
|
250
|
+
const E = () => {
|
|
251
|
+
k.style.left = this.parent._mapLinear(d[c], l, a, 0, _.clientWidth) + "px", k.style.top = this.parent._mapLinear(f[b], o, r, _.clientHeight, 0) + "px";
|
|
252
|
+
};
|
|
253
|
+
return E(), new ResizeObserver(() => {
|
|
254
|
+
E();
|
|
255
|
+
}).observe(_), Object.defineProperty(d, c, {
|
|
250
256
|
set: (x) => {
|
|
251
|
-
this.parent.propReferences[h] = x,
|
|
257
|
+
this.parent.propReferences[h] = x, E(), A.textContent = String(x) + ", " + f[b];
|
|
252
258
|
},
|
|
253
259
|
get: () => this.parent.propReferences[h]
|
|
254
260
|
}), Object.defineProperty(f, b, {
|
|
255
261
|
set: (x) => {
|
|
256
|
-
this.parent.propReferences[v] = x,
|
|
262
|
+
this.parent.propReferences[v] = x, E(), A.textContent = d[c] + ", " + String(x);
|
|
257
263
|
},
|
|
258
264
|
get: () => this.parent.propReferences[v]
|
|
259
265
|
}), w;
|
|
260
266
|
}
|
|
261
267
|
}
|
|
262
|
-
const
|
|
268
|
+
const Y = (
|
|
263
269
|
/* css */
|
|
264
270
|
`
|
|
265
271
|
.p-gui__button {
|
|
@@ -281,7 +287,7 @@ const G = (
|
|
|
281
287
|
margin-inline: 0;
|
|
282
288
|
}
|
|
283
289
|
`
|
|
284
|
-
),
|
|
290
|
+
), z = (
|
|
285
291
|
/* css */
|
|
286
292
|
`
|
|
287
293
|
.p-gui__slider {
|
|
@@ -418,7 +424,7 @@ const G = (
|
|
|
418
424
|
background: rgba(255, 255, 255, .1);
|
|
419
425
|
}
|
|
420
426
|
`
|
|
421
|
-
),
|
|
427
|
+
), V = (
|
|
422
428
|
/* css */
|
|
423
429
|
`
|
|
424
430
|
.p-gui__toggle {
|
|
@@ -454,7 +460,7 @@ const G = (
|
|
|
454
460
|
box-shadow: 0 0 5px #ddd;
|
|
455
461
|
}
|
|
456
462
|
`
|
|
457
|
-
),
|
|
463
|
+
), T = (
|
|
458
464
|
/* css */
|
|
459
465
|
`
|
|
460
466
|
.p-gui__color {
|
|
@@ -492,7 +498,7 @@ const G = (
|
|
|
492
498
|
border: none;
|
|
493
499
|
}
|
|
494
500
|
`
|
|
495
|
-
),
|
|
501
|
+
), Q = (
|
|
496
502
|
/* css */
|
|
497
503
|
`
|
|
498
504
|
.p-gui__vector2 {
|
|
@@ -557,7 +563,7 @@ const G = (
|
|
|
557
563
|
position: absolute;
|
|
558
564
|
}
|
|
559
565
|
`
|
|
560
|
-
),
|
|
566
|
+
), q = (
|
|
561
567
|
/* css */
|
|
562
568
|
`
|
|
563
569
|
.p-gui__image-container {
|
|
@@ -613,7 +619,7 @@ const G = (
|
|
|
613
619
|
|
|
614
620
|
}
|
|
615
621
|
`
|
|
616
|
-
),
|
|
622
|
+
), J = (
|
|
617
623
|
/* css */
|
|
618
624
|
`
|
|
619
625
|
.p-gui__folder {
|
|
@@ -668,7 +674,7 @@ const G = (
|
|
|
668
674
|
}
|
|
669
675
|
`
|
|
670
676
|
);
|
|
671
|
-
function
|
|
677
|
+
function Z(y) {
|
|
672
678
|
return (
|
|
673
679
|
/* css */
|
|
674
680
|
`
|
|
@@ -799,31 +805,31 @@ function J(y) {
|
|
|
799
805
|
border-color: rgba(255,255,255,.2);
|
|
800
806
|
}
|
|
801
807
|
|
|
802
|
-
${
|
|
808
|
+
${Y}
|
|
803
809
|
|
|
804
|
-
${
|
|
810
|
+
${q}
|
|
805
811
|
|
|
806
812
|
${B}
|
|
807
813
|
|
|
808
|
-
${z}
|
|
809
|
-
|
|
810
|
-
${Y}
|
|
811
|
-
|
|
812
814
|
${V}
|
|
815
|
+
|
|
816
|
+
${z}
|
|
813
817
|
|
|
814
818
|
${T}
|
|
815
819
|
|
|
816
|
-
${
|
|
820
|
+
${Q}
|
|
821
|
+
|
|
822
|
+
${J}
|
|
817
823
|
`
|
|
818
824
|
);
|
|
819
825
|
}
|
|
820
|
-
class
|
|
826
|
+
class C {
|
|
821
827
|
constructor(t = {}) {
|
|
822
828
|
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
829
|
this._folderConstructor(t.folderOptions);
|
|
824
830
|
return;
|
|
825
831
|
}
|
|
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(`${
|
|
832
|
+
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(`${Z(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();
|
|
827
833
|
}
|
|
828
834
|
_styleInstance() {
|
|
829
835
|
let t = this._getScrollbarWidth(this.container);
|
|
@@ -876,27 +882,27 @@ class I {
|
|
|
876
882
|
t.className = "p-gui__header-close", t.addEventListener("click", this.toggleClose.bind(this)), this.header.append(t);
|
|
877
883
|
}
|
|
878
884
|
button(t = {}, e) {
|
|
879
|
-
return this.imageContainer = null, new
|
|
885
|
+
return this.imageContainer = null, new M(this, t, e);
|
|
880
886
|
}
|
|
881
887
|
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
|
|
888
|
+
return this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer)), new N(this, t, e);
|
|
883
889
|
}
|
|
884
890
|
slider(t = {}, e) {
|
|
885
|
-
return this.imageContainer = null, new
|
|
891
|
+
return this.imageContainer = null, new H(this, t, e);
|
|
886
892
|
}
|
|
887
893
|
toggle(t = {}, e) {
|
|
888
894
|
this.imageContainer = null;
|
|
889
|
-
const i = new
|
|
895
|
+
const i = new X(this, t, e);
|
|
890
896
|
return this.wrapper.append(i), i;
|
|
891
897
|
}
|
|
892
898
|
list(t = {}, e) {
|
|
893
|
-
return this.imageContainer = null, new
|
|
899
|
+
return this.imageContainer = null, new S(this, t, e);
|
|
894
900
|
}
|
|
895
901
|
color(t = {}, e) {
|
|
896
|
-
return this.imageContainer = null, new
|
|
902
|
+
return this.imageContainer = null, new W(this, t, e);
|
|
897
903
|
}
|
|
898
904
|
vector2(t = {}, e) {
|
|
899
|
-
return this.imageContainer = null, new
|
|
905
|
+
return this.imageContainer = null, new G(this, t, e);
|
|
900
906
|
}
|
|
901
907
|
folder(t = {}) {
|
|
902
908
|
let e = typeof t.closed == "boolean" ? t.closed : !1, i = t.label || "", s = t.color || null, l = t.maxHeight || null;
|
|
@@ -911,7 +917,7 @@ class I {
|
|
|
911
917
|
p.innerHTML = `<span class="p-gui__folder-arrow"></span>${i}`, p.className = "p-gui__folder-header", r.append(p), p.addEventListener("click", () => {
|
|
912
918
|
r.classList.toggle("p-gui__folder--closed");
|
|
913
919
|
});
|
|
914
|
-
let u = new
|
|
920
|
+
let u = new C({ isFolder: !0, folderOptions: {
|
|
915
921
|
wrapper: r,
|
|
916
922
|
parent: this,
|
|
917
923
|
firstParent: this.firstParent
|
|
@@ -946,9 +952,9 @@ class I {
|
|
|
946
952
|
}
|
|
947
953
|
static registerPlugin(t) {
|
|
948
954
|
for (let e in t)
|
|
949
|
-
|
|
955
|
+
C.prototype[e] = t[e];
|
|
950
956
|
}
|
|
951
957
|
}
|
|
952
958
|
export {
|
|
953
|
-
|
|
959
|
+
C as default
|
|
954
960
|
};
|
package/package.json
CHANGED
|
@@ -115,13 +115,25 @@ export default class Vector2 {
|
|
|
115
115
|
dot.className = 'p-gui__vector2-dot';
|
|
116
116
|
area.append(dot);
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
// Function to update dot position based on current values
|
|
119
|
+
const updateDotPosition = () => {
|
|
120
|
+
dot.style.left = this.parent._mapLinear(objectX[propX], minX, maxX, 0, area.clientWidth) + 'px';
|
|
121
|
+
dot.style.top = this.parent._mapLinear(objectY[propY], minY, maxY, area.clientHeight, 0) + 'px';
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Initial position
|
|
125
|
+
updateDotPosition();
|
|
126
|
+
|
|
127
|
+
// Observe area resize (e.g., when scrollbars appear/disappear)
|
|
128
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
129
|
+
updateDotPosition();
|
|
130
|
+
});
|
|
131
|
+
resizeObserver.observe(area);
|
|
120
132
|
|
|
121
133
|
Object.defineProperty( objectX, propX, {
|
|
122
134
|
set: val => {
|
|
123
135
|
this.parent.propReferences[propXReferenceIndex] = val;
|
|
124
|
-
|
|
136
|
+
updateDotPosition();
|
|
125
137
|
vector_value.textContent = String( val ) + ', ' + objectY[propY];
|
|
126
138
|
},
|
|
127
139
|
get: () => {
|
|
@@ -132,7 +144,7 @@ export default class Vector2 {
|
|
|
132
144
|
Object.defineProperty( objectY, propY, {
|
|
133
145
|
set: val => {
|
|
134
146
|
this.parent.propReferences[propYReferenceIndex] = val;
|
|
135
|
-
|
|
147
|
+
updateDotPosition();
|
|
136
148
|
vector_value.textContent = objectX[propX] + ', ' + String( val );
|
|
137
149
|
},
|
|
138
150
|
get: () => {
|