perfect-gui 4.9.8 → 4.10.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.
- package/dist/perfect-gui.mjs +647 -422
- package/dist/perfect-gui.umd.js +404 -293
- package/package.json +1 -1
- package/src/Slider.js +242 -0
- package/src/index.js +28 -6
- package/src/styles/_button.js +21 -0
- package/src/styles/_color.js +36 -0
- package/src/styles/_folder.js +56 -0
- package/src/styles/_image.js +54 -0
- package/src/styles/_list.js +35 -0
- package/src/styles/_slider.js +92 -0
- package/src/styles/_switch.js +35 -0
- package/src/styles/_vector2.js +63 -0
- package/src/styles/styles.js +156 -0
- package/src/styles.js +0 -421
package/dist/perfect-gui.umd.js
CHANGED
|
@@ -1,197 +1,227 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
top: 0;
|
|
12
|
-
left: 0;
|
|
13
|
-
transform: translate3d(0,0,0);
|
|
14
|
-
padding-top: 21px;
|
|
15
|
-
background: var(--color-bg);
|
|
16
|
-
display: flex;
|
|
17
|
-
justify-content: center;
|
|
18
|
-
flex-wrap: wrap;
|
|
19
|
-
font-family: Verdana, Arial, sans-serif;
|
|
20
|
-
width: 290px;
|
|
21
|
-
overflow: auto;
|
|
22
|
-
box-shadow: 0 0 2px black;
|
|
23
|
-
box-sizing: border-box;
|
|
24
|
-
z-index: 99999;
|
|
25
|
-
user-select: none;
|
|
26
|
-
border-bottom-right-radius: 3px;
|
|
27
|
-
border-bottom-left-radius: 3px;
|
|
28
|
-
cursor: auto;
|
|
29
|
-
border-radius: var(--main-border-radius);
|
|
30
|
-
border: 1px solid var(--color-border);
|
|
31
|
-
line-height: normal;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.p-gui * {
|
|
35
|
-
font-size: 11px;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.p-gui::-webkit-scrollbar,
|
|
39
|
-
.p-gui *::-webkit-scrollbar {
|
|
40
|
-
width: 10px;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.p-gui::-webkit-scrollbar-track,
|
|
44
|
-
.p-gui *::-webkit-scrollbar-track {
|
|
45
|
-
background: #2f2f2f;
|
|
46
|
-
border-radius: 3px;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.p-gui::-webkit-scrollbar-thumb,
|
|
50
|
-
.p-gui *::-webkit-scrollbar-thumb {
|
|
51
|
-
background: #757576;
|
|
52
|
-
border-radius: 10px;
|
|
53
|
-
box-sizing: border-box;
|
|
54
|
-
border: 1px solid #2f2f2f;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.p-gui--collapsed {
|
|
58
|
-
height: 0;
|
|
59
|
-
padding: 21px 10px 0 10px;
|
|
60
|
-
overflow: hidden;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.p-gui__header {
|
|
64
|
-
position: absolute;
|
|
65
|
-
top: 0;
|
|
66
|
-
left: 0;
|
|
67
|
-
width: 100%;
|
|
68
|
-
height: 20px;
|
|
69
|
-
background-color: rgba(0, 0, 0, .8);
|
|
70
|
-
cursor: grab;
|
|
71
|
-
color: grey;
|
|
72
|
-
font-size: 10px;
|
|
73
|
-
line-height: 20px;
|
|
74
|
-
padding-left: 12px;
|
|
75
|
-
box-sizing: border-box;
|
|
76
|
-
touch-action: none;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
.p-gui__header-close {
|
|
80
|
-
width: 20px;
|
|
81
|
-
height: 20px;
|
|
82
|
-
position: absolute;
|
|
83
|
-
top: 0;
|
|
84
|
-
right: 5px;
|
|
85
|
-
cursor: pointer;
|
|
86
|
-
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUAQMAAAC3R49OAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAABFJREFUCNdjIAb8//8BjIkAAOrOBd3TR0jRAAAAAElFTkSuQmCC);
|
|
87
|
-
background-size: 50% 50%;
|
|
88
|
-
background-position: center;
|
|
89
|
-
background-repeat: no-repeat;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.p-gui--collapsed .p-gui__header-close {
|
|
93
|
-
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUAQMAAAC3R49OAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAABVJREFUCNdjYEhgIIj///8AwsSoBQD43QydY5mb0QAAAABJRU5ErkJggg==);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.p-gui__image-container {
|
|
97
|
-
width: 100%;
|
|
98
|
-
padding: 3px;
|
|
99
|
-
display: flex;
|
|
100
|
-
justify-content: flex-start;
|
|
101
|
-
flex-wrap: wrap;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.p-gui__image {
|
|
105
|
-
background-size: cover;
|
|
106
|
-
cursor: pointer;
|
|
107
|
-
position: relative;
|
|
108
|
-
margin: 1px 2.5px 19px 2.5px;
|
|
109
|
-
border-radius: var(--main-border-radius);
|
|
110
|
-
flex: 0 0 calc(33.333% - 5px);
|
|
111
|
-
height: 90px;
|
|
112
|
-
background-position: center;
|
|
113
|
-
}
|
|
1
|
+
(function(x,v){typeof exports=="object"&&typeof module<"u"?module.exports=v():typeof define=="function"&&define.amd?define(v):(x=typeof globalThis<"u"?globalThis:x||self,x["Perfect GUI"]=v())})(this,function(){"use strict";class x{constructor(e={},t){if(this.propReferences=[],typeof e!="object")throw Error(`[GUI] slider() first parameter must be an object. Received: ${typeof e}.`);let o=typeof e.name=="string"&&e.name||" ";this.isObject=!1;let a=null;this.obj=e.obj,this.prop=e.prop;let l=typeof e.value=="number"?e.value:null;if(this.min=e.min??0,this.max=e.max??1,this.step=e.step||(this.max-this.min)/100,l!==null)(this.prop!=null||this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(this.prop!=null&&this.obj!=null){if(typeof this.prop!="string")throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof this.prop}.`);if(typeof this.obj!="object")throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof this.obj}.`);o==" "&&(o=this.prop),a=this.propReferences.push(this.obj[this.prop])-1,this.isObject=!0}else(this.prop!=null&&this.obj==null||this.prop==null&&this.obj!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),l=(this.max-this.min)/2;this.imageContainer=null;const i=document.createElement("div");i.className="p-gui__slider";const r=document.createElement("div");r.className="p-gui__slider-name",r.textContent=o,i.append(r),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),i.append(this.ctrlDiv);const n=document.createElement("div");return n.className="p-gui__slider-bar",this.ctrlDiv.append(n),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",n.append(this.filling),this.valueInput=document.createElement("input"),this.valueInput.className="p-gui__slider-value",this.valueInput.value=this.isObject?this.obj[this.prop]:l,i.append(this.valueInput),setTimeout(()=>{const s=this.handle.offsetWidth;this.handle.position=this._mapLinear(this.valueInput.value,this.min,this.max,s/2,88-s/2),this.handle.style.transform=`translate(-50%, -50%) translateX(${this.handle.position}px)`,this.filling.style.width=`${this.handle.position}px`},0),this.valueInput.addEventListener("change",()=>{this._updateHandlePositionFromValue(),this._triggerCallbacks()}),this.ctrlDiv.addEventListener("pointerdown",s=>{this.ctrlDiv.pointerDown=!0,this.ctrlDiv.prevPosition=s.clientX,this._updateHandlePositionFromPointer(s,!0)}),window.addEventListener("pointerup",s=>{this.ctrlDiv.pointerDown=!1}),window.addEventListener("pointermove",s=>{this.ctrlDiv.pointerDown&&(this.ctrlDiv.pointerDelta=s.clientX-this.ctrlDiv.prevPosition,this._updateHandlePositionFromPointer(s))}),this.isObject&&Object.defineProperty(this.obj,this.prop,{set:s=>{this.propReferences[a]=s,this.valueInput.value=s,this._updateHandlePositionFromValue(),typeof t=="function"&&t(parseFloat(this.valueInput.value))},get:()=>this.propReferences[a]}),i}_updateHandlePositionFromPointer(e,t=!1){const o=this.ctrlDiv.offsetWidth,a=this.handle.offsetWidth,l=e.clientX-this.ctrlDiv.prevPosition;let i;const r=parseFloat(this.valueInput.value);t?i=e.offsetX:i=this.handle.position+l,i=Math.max(a/2,Math.min(i,o-a/2));let n=this.min+(this.max-this.min)*(i-a/2)/(o-a);n>r?n=this._quantizeFloor(n,this.step):n=this._quantizeCeil(n,this.step),n=parseFloat(n.toFixed(9));const s=parseFloat((r+this.step).toFixed(9)),d=parseFloat((r-this.step).toFixed(9));if(n>=s||n<=d){const f=this._countDecimals(this.step);n=n.toFixed(f),this.valueInput.value=n,this.ctrlDiv.prevPosition=e.clientX,this.handle.style.transform=`translate(-50%, -50%) translateX(${i}px)`,this.handle.position=i,this.filling.style.width=this.handle.position+"px",this._triggerCallbacks()}}_countDecimals(e){const t=e.toString(),o=t.indexOf(".");return o===-1?0:t.length-o-1}_updateHandlePositionFromValue(){const e=this.ctrlDiv.offsetWidth,t=this.handle.offsetWidth;let o=this._mapLinear(this.valueInput.value,this.min,this.max,t/2,e-t/2);o=Math.max(t/2,Math.min(o,e-t/2)),this.handle.style.transform=`translate(-50%, -50%) translateX(${o}px)`,this.handle.position=o,this.filling.style.width=this.handle.position+"px"}_triggerCallbacks(){this.isObject?this.obj[this.prop]=parseFloat(this.valueInput.value):typeof callback=="function"&&callback(parseFloat(this.valueInput.value)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}_mapLinear(e,t,o,a,l){return a+(e-t)*(l-a)/(o-t)}_quantize(e,t){return t*Math.round(e/t)}_quantizeCeil(e,t){return t*Math.ceil(e/t)}_quantizeFloor(e,t){return t*Math.floor(e/t)}}const v=`
|
|
2
|
+
.p-gui__button {
|
|
3
|
+
background: var(--color-accent);
|
|
4
|
+
text-align: center;
|
|
5
|
+
color: white;
|
|
6
|
+
border: none;
|
|
7
|
+
border: 1px solid transparent;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
transition: var(--transition) background, var(--transition) border-color;
|
|
10
|
+
}
|
|
114
11
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
height: 100%;
|
|
121
|
-
content: '';
|
|
122
|
-
border: 1px solid #06FF89;
|
|
123
|
-
box-sizing: border-box;
|
|
124
|
-
border-radius: var(--main-border-radius);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
.p-gui__image-text {
|
|
128
|
-
position: absolute;
|
|
129
|
-
bottom: -15px;
|
|
130
|
-
color: #eee;
|
|
131
|
-
text-shadow: 0 -1px 0 #111;
|
|
132
|
-
white-space: nowrap;
|
|
133
|
-
width: 100%;
|
|
134
|
-
overflow: hidden;
|
|
135
|
-
text-overflow: ellipsis;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
.p-gui__button,
|
|
139
|
-
.p-gui__switch,
|
|
140
|
-
.p-gui__list,
|
|
141
|
-
.p-gui__vector2,
|
|
142
|
-
.p-gui__color {
|
|
143
|
-
width: 100%;
|
|
144
|
-
padding: 7px 13px;
|
|
145
|
-
color: white;
|
|
146
|
-
cursor: pointer;
|
|
147
|
-
position: relative;
|
|
148
|
-
box-sizing: border-box;
|
|
149
|
-
margin-bottom: 3px;
|
|
150
|
-
margin: 3px;
|
|
151
|
-
|
|
152
|
-
border: 1px solid var(--color-border-2);
|
|
153
|
-
border-radius: var(--main-border-radius);
|
|
154
|
-
}
|
|
12
|
+
.p-gui__button:hover {
|
|
13
|
+
background: var(--color-accent-hover);
|
|
14
|
+
color: var(--color-text-light);
|
|
15
|
+
border-color: rgba(255, 255, 255, 0.2);
|
|
16
|
+
}
|
|
155
17
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
border: none;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
.p-gui__button:hover {
|
|
174
|
-
background: var(--color-accent-hover);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
.p-gui__switch {
|
|
178
|
-
background: rgba(255, 255, 255, .05);
|
|
179
|
-
}
|
|
18
|
+
.p-gui__folder .p-gui__button {
|
|
19
|
+
margin-inline: 0;
|
|
20
|
+
}
|
|
21
|
+
`,U=`
|
|
22
|
+
.p-gui__slider {
|
|
23
|
+
position: relative;
|
|
24
|
+
min-height: 14px;
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
gap: 10px;
|
|
29
|
+
color: var(--color-text-dark);
|
|
30
|
+
transition: color var(--transition);
|
|
31
|
+
}
|
|
180
32
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
33
|
+
.p-gui__slider:hover {
|
|
34
|
+
color: var(--color-text-light);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.p-gui__slider-name {
|
|
38
|
+
width: 50%;
|
|
39
|
+
text-overflow: ellipsis;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.p-gui__slider-ctrl {
|
|
44
|
+
-webkit-appearance: none;
|
|
45
|
+
padding: 0;
|
|
46
|
+
font: inherit;
|
|
47
|
+
outline: none;
|
|
48
|
+
box-sizing: border-box;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
position: relative;
|
|
51
|
+
right: 0;
|
|
52
|
+
height: 14px;
|
|
53
|
+
margin: 0 0 0 auto;
|
|
54
|
+
width: 37%;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.p-gui__slider-bar {
|
|
58
|
+
position: absolute;
|
|
59
|
+
top: 50%;
|
|
60
|
+
left: 0;
|
|
61
|
+
height: 2px;
|
|
62
|
+
background: rgba(255, 255, 255, .2);
|
|
63
|
+
width: 100%;
|
|
64
|
+
transform: translateY(-50%);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.p-gui__slider-filling {
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: -25%;
|
|
70
|
+
left: 0;
|
|
71
|
+
height: 150%;
|
|
72
|
+
background: var(--color-accent);
|
|
73
|
+
width: 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.p-gui__slider:hover .p-gui__slider-filling {
|
|
77
|
+
background: var(--color-accent-hover);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.p-gui__slider-handle {
|
|
81
|
+
width: 15px;
|
|
82
|
+
height: 8px;
|
|
83
|
+
position: absolute;
|
|
84
|
+
top: 50%;
|
|
85
|
+
left: 0;
|
|
86
|
+
border-radius: 2px;
|
|
87
|
+
transform: translate(-50%, -50%);
|
|
88
|
+
pointer-events: none;
|
|
89
|
+
background: var(--color-text-dark);
|
|
90
|
+
box-shadow: 0 0 2px rgba(0, 0, 0, .5);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.p-gui__slider:hover .p-gui__slider-handle {
|
|
94
|
+
background: var(--color-text-light);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.p-gui__slider-value {
|
|
98
|
+
display: inline-block;
|
|
99
|
+
right: 7px;
|
|
100
|
+
width: 13%;
|
|
101
|
+
border: none;
|
|
102
|
+
color: white;
|
|
103
|
+
border-radius: 2px;
|
|
104
|
+
background: rgba(255, 255, 255, 0.1);
|
|
105
|
+
padding: 2px 4px;
|
|
106
|
+
color: inherit;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.p-gui__slider-value:focus {
|
|
110
|
+
outline: none;
|
|
111
|
+
}
|
|
112
|
+
`,j=`
|
|
113
|
+
.p-gui__list {
|
|
114
|
+
cursor: default;
|
|
115
|
+
color: var(--color-text-dark);
|
|
116
|
+
transition: var(--transition) color;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.p-gui__list:hover {
|
|
120
|
+
color: var(--color-text-light);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.p-gui__list-dropdown {
|
|
124
|
+
background: rgba(255, 255, 255,.05);
|
|
125
|
+
color: white;
|
|
126
|
+
padding: 0 12px 0 5px;
|
|
127
|
+
top: 0px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.p-gui__list-dropdown {
|
|
131
|
+
position: absolute;
|
|
132
|
+
right: 5px;
|
|
133
|
+
top: 0;
|
|
134
|
+
bottom: 0;
|
|
135
|
+
margin: auto;
|
|
136
|
+
height: 21px;
|
|
137
|
+
cursor: pointer;
|
|
138
|
+
border-radius: 3px;
|
|
139
|
+
border: 1px solid var(--color-border-2);
|
|
140
|
+
outline: none;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.p-gui__list-dropdown:hover {
|
|
144
|
+
background: rgba(255, 255, 255, .1);
|
|
145
|
+
}
|
|
146
|
+
`,k=`
|
|
147
|
+
.p-gui__switch {
|
|
148
|
+
background: rgba(255, 255, 255, .05);
|
|
149
|
+
color: var(--color-text-dark);
|
|
150
|
+
transition: var(--transition) background, var(--transition) color;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.p-gui__switch:hover {
|
|
154
|
+
background: rgba(255, 255, 255, .1);
|
|
155
|
+
color: var(--color-text-light);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.p-gui__folder .p-gui__switch {
|
|
159
|
+
margin-inline: 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.p-gui__switch-checkbox {
|
|
163
|
+
width: 5px;
|
|
164
|
+
height: 5px;
|
|
165
|
+
background-color: rgba(0, 0, 0, .5);
|
|
166
|
+
border: 1px solid grey;
|
|
167
|
+
position: absolute;
|
|
168
|
+
top: 0;
|
|
169
|
+
right: 10px;
|
|
170
|
+
bottom: 0;
|
|
171
|
+
margin: auto;
|
|
172
|
+
border-radius: 50%;
|
|
173
|
+
pointer-events: none;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.p-gui__switch-checkbox--active {
|
|
177
|
+
background-color: #00ff89;
|
|
178
|
+
box-shadow: 0 0 7px #00ff89;
|
|
179
|
+
}
|
|
180
|
+
`,I=`
|
|
181
|
+
.p-gui__color {
|
|
182
|
+
cursor: default;
|
|
183
|
+
color: var(--color-text-dark);
|
|
184
|
+
transition: var(--transition) color;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.p-gui__color:hover {
|
|
188
|
+
color: var(--color-text-light);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.p-gui__color-picker {
|
|
192
|
+
position: absolute;
|
|
193
|
+
right: 5px;
|
|
194
|
+
top: 0;
|
|
195
|
+
bottom: 0;
|
|
196
|
+
margin: auto;
|
|
197
|
+
height: 21px;
|
|
198
|
+
cursor: pointer;
|
|
199
|
+
border-radius: 3px;
|
|
200
|
+
border: 1px solid var(--color-border-2);
|
|
201
|
+
outline: none;
|
|
202
|
+
-webkit-appearance: none;
|
|
203
|
+
padding: 0;
|
|
204
|
+
background-color: transparent;
|
|
205
|
+
border: 1px solid #222222;
|
|
206
|
+
overflow: hidden;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.p-gui__color-picker::-webkit-color-swatch-wrapper {
|
|
210
|
+
padding: 0;
|
|
211
|
+
}
|
|
212
|
+
.p-gui__color-picker::-webkit-color-swatch {
|
|
213
|
+
border: none;
|
|
214
|
+
}
|
|
215
|
+
`,C=`
|
|
191
216
|
.p-gui__vector2 {
|
|
192
217
|
background: transparent;
|
|
193
218
|
aspect-ratio: 1;
|
|
194
219
|
padding-bottom: 0;
|
|
220
|
+
color: var(--color-text-dark);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.p-gui__vector2:hover {
|
|
224
|
+
color: var(--color-text-light);
|
|
195
225
|
}
|
|
196
226
|
|
|
197
227
|
.p-gui__vector2-area {
|
|
@@ -239,125 +269,65 @@
|
|
|
239
269
|
pointer-events: none;
|
|
240
270
|
}
|
|
241
271
|
|
|
242
|
-
.p-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
background-color: rgba(0, 0, 0, .5);
|
|
246
|
-
border: 1px solid grey;
|
|
272
|
+
.p-gui__vector-value {
|
|
273
|
+
display: inline-block;
|
|
274
|
+
right: 7px;
|
|
247
275
|
position: absolute;
|
|
248
|
-
top: 0;
|
|
249
|
-
right: 10px;
|
|
250
|
-
bottom: 0;
|
|
251
|
-
margin: auto;
|
|
252
|
-
border-radius: 50%;
|
|
253
|
-
pointer-events: none;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
.p-gui__switch-checkbox--active {
|
|
257
|
-
background-color: #00ff89;
|
|
258
|
-
box-shadow: 0 0 7px #00ff89;
|
|
259
276
|
}
|
|
260
|
-
|
|
261
|
-
.p-
|
|
262
|
-
|
|
263
|
-
|
|
277
|
+
`,R=`
|
|
278
|
+
.p-gui__image-container {
|
|
279
|
+
width: 100%;
|
|
280
|
+
padding: 3px;
|
|
281
|
+
display: flex;
|
|
282
|
+
justify-content: flex-start;
|
|
283
|
+
flex-wrap: wrap;
|
|
284
|
+
box-sizing: border-box;
|
|
264
285
|
}
|
|
265
286
|
|
|
266
|
-
.p-
|
|
267
|
-
|
|
268
|
-
position: absolute;
|
|
269
|
-
right: 5px;
|
|
270
|
-
top: 0;
|
|
271
|
-
bottom: 0;
|
|
272
|
-
margin: auto;
|
|
273
|
-
height: 21px;
|
|
287
|
+
.p-gui__image {
|
|
288
|
+
background-size: cover;
|
|
274
289
|
cursor: pointer;
|
|
275
|
-
border-radius: 3px;
|
|
276
|
-
border: 1px solid var(--color-border-2);
|
|
277
|
-
outline: none;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
.p-gui__list-dropdown {
|
|
281
|
-
background: rgba(255, 255, 255,.05);
|
|
282
|
-
color: white;
|
|
283
|
-
padding: 0 12px;
|
|
284
|
-
top: 0px;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
.p-gui__list-dropdown:hover {
|
|
288
|
-
background: rgba(255, 255, 255, .1);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
.p-gui__color-picker {
|
|
292
|
-
-webkit-appearance: none;
|
|
293
|
-
padding: 0;
|
|
294
|
-
background-color: transparent;
|
|
295
|
-
border: 1px solid #222222;
|
|
296
|
-
overflow: hidden;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
.p-gui__color-picker::-webkit-color-swatch-wrapper {
|
|
300
|
-
padding: 0;
|
|
301
|
-
}
|
|
302
|
-
.p-gui__color-picker::-webkit-color-swatch {
|
|
303
|
-
border: none;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
.p-gui__slider {
|
|
307
|
-
box-sizing: border-box;
|
|
308
|
-
width: calc(100% - 10px);
|
|
309
|
-
margin: 0 auto 10px auto;
|
|
310
|
-
padding: 7px 0;
|
|
311
|
-
color: white;
|
|
312
290
|
position: relative;
|
|
313
|
-
|
|
291
|
+
margin: 1px 2.5px 19px 2.5px;
|
|
292
|
+
border-radius: var(--main-border-radius);
|
|
293
|
+
flex: 0 0 calc(33.333% - 5px);
|
|
294
|
+
height: 90px;
|
|
295
|
+
background-position: center;
|
|
296
|
+
color: var(--color-text-dark);
|
|
297
|
+
transition: var(--transition) color;
|
|
314
298
|
}
|
|
315
|
-
|
|
316
|
-
.p-
|
|
317
|
-
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
opacity: .8;
|
|
322
|
-
background: var(--color-accent);
|
|
323
|
-
box-sizing: border-box;
|
|
324
|
-
cursor: pointer;
|
|
299
|
+
|
|
300
|
+
.p-gui__image:hover {
|
|
301
|
+
color: var(--color-text-text);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.p-gui__image::after {
|
|
325
305
|
position: absolute;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
height: 5px;
|
|
306
|
+
top: 0;
|
|
307
|
+
left: 0;
|
|
329
308
|
width: 100%;
|
|
330
|
-
|
|
309
|
+
height: 100%;
|
|
310
|
+
content: '';
|
|
311
|
+
border: 1px solid transparent;
|
|
312
|
+
box-sizing: border-box;
|
|
331
313
|
border-radius: var(--main-border-radius);
|
|
314
|
+
transition: var(--transition) border-color;
|
|
332
315
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
.p-gui__slider-ctrl::-webkit-slider-runnable-track {
|
|
336
|
-
height: 13px;
|
|
337
|
-
border: none;
|
|
338
|
-
border-radius: 0;
|
|
339
|
-
background-color: transparent; /* supprimé définie sur l'input */
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/* Curseur */
|
|
343
|
-
.p-gui__slider-ctrl::-webkit-slider-thumb {
|
|
344
|
-
-webkit-appearance: none; /* également nécessaire sur le curseur */
|
|
345
|
-
width: 15px;
|
|
346
|
-
height: 7px;
|
|
347
|
-
border: none; /* pris en compte sur Webkit et Edge */
|
|
348
|
-
background: white; /* pris en compte sur Webkit only */
|
|
349
|
-
position: relative;
|
|
350
|
-
top: 3px;
|
|
351
|
-
border-radius: 1px;
|
|
316
|
+
.p-gui__image--selected::after {
|
|
317
|
+
border-color: #06FF89;
|
|
352
318
|
}
|
|
353
319
|
|
|
354
|
-
.p-
|
|
355
|
-
.p-gui__vector-value {
|
|
356
|
-
display: inline-block;
|
|
320
|
+
.p-gui__image-text {
|
|
357
321
|
position: absolute;
|
|
358
|
-
|
|
322
|
+
bottom: -15px;
|
|
323
|
+
text-shadow: 0 -1px 0 #111;
|
|
324
|
+
white-space: nowrap;
|
|
325
|
+
width: 100%;
|
|
326
|
+
overflow: hidden;
|
|
327
|
+
text-overflow: ellipsis;
|
|
328
|
+
|
|
359
329
|
}
|
|
360
|
-
|
|
330
|
+
`,P=`
|
|
361
331
|
.p-gui__folder {
|
|
362
332
|
width: 100%;
|
|
363
333
|
position: relative;
|
|
@@ -369,6 +339,7 @@
|
|
|
369
339
|
border: 1px solid grey;
|
|
370
340
|
padding: 0 3px 3px 3px;
|
|
371
341
|
border-radius: var(--main-border-radius);
|
|
342
|
+
box-sizing: border-box;
|
|
372
343
|
}
|
|
373
344
|
|
|
374
345
|
.p-gui__folder:last-of-type {
|
|
@@ -411,10 +382,150 @@
|
|
|
411
382
|
.p-gui__folder--closed .p-gui__folder-arrow {
|
|
412
383
|
transform: rotate(0deg);
|
|
413
384
|
}
|
|
414
|
-
|
|
385
|
+
`;function F(A){return`
|
|
386
|
+
.p-gui {
|
|
387
|
+
--main-border-radius: 5px;
|
|
388
|
+
--color-bg: #121212;
|
|
389
|
+
--color-border: #484848;
|
|
390
|
+
--color-border-2: rgba(255,255,255,.1);
|
|
391
|
+
--color-text-light: #ffffff;
|
|
392
|
+
--color-text-dark: #bbbbbb;
|
|
393
|
+
--color-accent: #1681ca;
|
|
394
|
+
--color-accent-hover: #218fda;
|
|
395
|
+
--transition: .1s linear;
|
|
396
|
+
|
|
397
|
+
position: ${A};
|
|
398
|
+
top: 0;
|
|
399
|
+
left: 0;
|
|
400
|
+
transform: translate3d(0,0,0);
|
|
401
|
+
padding-top: 21px;
|
|
402
|
+
padding-inline: 3px;
|
|
403
|
+
background: var(--color-bg);
|
|
404
|
+
display: block;
|
|
405
|
+
justify-content: center;
|
|
406
|
+
flex-wrap: wrap;
|
|
407
|
+
font-family: "Arial Rounded MT Bold", Arial, sans-serif;
|
|
408
|
+
width: 290px;
|
|
409
|
+
overflow: auto;
|
|
410
|
+
box-shadow: 0 0 2px black;
|
|
411
|
+
box-sizing: border-box;
|
|
412
|
+
z-index: 99999;
|
|
413
|
+
user-select: none;
|
|
414
|
+
border-bottom-right-radius: 3px;
|
|
415
|
+
border-bottom-left-radius: 3px;
|
|
416
|
+
cursor: auto;
|
|
417
|
+
border-radius: var(--main-border-radius);
|
|
418
|
+
border: 1px solid var(--color-border);
|
|
419
|
+
line-height: normal;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.p-gui * {
|
|
423
|
+
font-size: 11px;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
.p-gui::-webkit-scrollbar,
|
|
427
|
+
.p-gui *::-webkit-scrollbar {
|
|
428
|
+
width: 10px;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
.p-gui::-webkit-scrollbar-track,
|
|
432
|
+
.p-gui *::-webkit-scrollbar-track {
|
|
433
|
+
background: #2f2f2f;
|
|
434
|
+
border-radius: 3px;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.p-gui::-webkit-scrollbar-thumb,
|
|
438
|
+
.p-gui *::-webkit-scrollbar-thumb {
|
|
439
|
+
background: #757576;
|
|
440
|
+
border-radius: 10px;
|
|
441
|
+
box-sizing: border-box;
|
|
442
|
+
border: 1px solid #2f2f2f;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.p-gui--collapsed {
|
|
446
|
+
height: 0;
|
|
447
|
+
padding: 21px 10px 0 10px;
|
|
448
|
+
overflow: hidden;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.p-gui__header {
|
|
452
|
+
position: absolute;
|
|
453
|
+
top: 0;
|
|
454
|
+
left: 0;
|
|
455
|
+
width: 100%;
|
|
456
|
+
height: 20px;
|
|
457
|
+
background-color: rgba(0, 0, 0, .8);
|
|
458
|
+
cursor: grab;
|
|
459
|
+
color: grey;
|
|
460
|
+
font-size: 10px;
|
|
461
|
+
line-height: 20px;
|
|
462
|
+
padding-left: 12px;
|
|
463
|
+
box-sizing: border-box;
|
|
464
|
+
touch-action: none;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
.p-gui__header-close {
|
|
468
|
+
width: 20px;
|
|
469
|
+
height: 20px;
|
|
470
|
+
position: absolute;
|
|
471
|
+
top: 0;
|
|
472
|
+
right: 5px;
|
|
473
|
+
cursor: pointer;
|
|
474
|
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUAQMAAAC3R49OAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAABFJREFUCNdjIAb8//8BjIkAAOrOBd3TR0jRAAAAAElFTkSuQmCC);
|
|
475
|
+
background-size: 50% 50%;
|
|
476
|
+
background-position: center;
|
|
477
|
+
background-repeat: no-repeat;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.p-gui--collapsed .p-gui__header-close {
|
|
481
|
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUAQMAAAC3R49OAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAABVJREFUCNdjYEhgIIj///8AwsSoBQD43QydY5mb0QAAAABJRU5ErkJggg==);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
.p-gui__slider,
|
|
485
|
+
.p-gui__button,
|
|
486
|
+
.p-gui__switch,
|
|
487
|
+
.p-gui__list,
|
|
488
|
+
.p-gui__vector2,
|
|
489
|
+
.p-gui__color {
|
|
490
|
+
width: 100%;
|
|
491
|
+
padding: 7px;
|
|
492
|
+
cursor: pointer;
|
|
493
|
+
position: relative;
|
|
494
|
+
box-sizing: border-box;
|
|
495
|
+
margin-block: 3px;
|
|
496
|
+
border: 1px solid var(--color-border-2);
|
|
497
|
+
border-radius: var(--main-border-radius);
|
|
498
|
+
transition: var(--transition) border-color;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.p-gui__slider:hover,
|
|
502
|
+
.p-gui__button:hover,
|
|
503
|
+
.p-gui__switch:hover,
|
|
504
|
+
.p-gui__list:hover,
|
|
505
|
+
.p-gui__vector2:hover,
|
|
506
|
+
.p-gui__color:hover {
|
|
507
|
+
border-color: rgba(255,255,255,.2);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
${v}
|
|
511
|
+
|
|
512
|
+
${R}
|
|
513
|
+
|
|
514
|
+
${j}
|
|
515
|
+
|
|
516
|
+
${k}
|
|
517
|
+
|
|
518
|
+
${U}
|
|
519
|
+
|
|
520
|
+
${I}
|
|
521
|
+
|
|
522
|
+
${C}
|
|
523
|
+
|
|
524
|
+
${P}
|
|
525
|
+
`}class y{constructor(e={}){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){this._folderConstructor(e.folderOptions);return}typeof e.onUpdate=="function"&&(this.onUpdate=e.onUpdate),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),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(`${F(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} {
|
|
415
526
|
width: ${this.wrapperWidth}px;
|
|
416
527
|
max-height: ${this.maxHeight}px;
|
|
417
528
|
transform: translate3d(${this.xOffset}px,${this.yOffset}px,0);
|
|
418
529
|
${this.screenCorner.y=="top"?"":"top: auto; bottom: 0;"}
|
|
419
530
|
${this.backgroundColor?"background: "+this.backgroundColor+";":""}
|
|
420
|
-
}`)}_folderConstructor(e){this.wrapper=e.wrapper,this.isFolder=!0,this.parent=e.parent,this.firstParent=e.firstParent}_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;const a=document.createElement("div");a.className="p-gui__button",a.textContent=o,a.addEventListener("click",()=>{this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&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(/^.*[\\\/]/,""),p;e.name==null?p=a:p=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=p,s.append(l),s.addEventListener("click",()=>{let f=s.parentElement.querySelectorAll(".p-gui__image--selected");for(let c=0;c<f.length;c++)f[c].classList.remove("p-gui__image--selected");i&&s.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:o,text:p}),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),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,p=null,r=e.obj,i=e.prop,n=typeof e.value=="number"?e.value:null,s=e.min??0,l=e.max??1,f=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),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.'),n=(l-s)/2;this.imageContainer=null;const c=document.createElement("div");c.className="p-gui__slider",c.textContent=o,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",f),d.setAttribute("value",a?r[i]:n),c.append(d);const h=document.createElement("div");h.className="p-gui__slider-value",h.textContent=String(a?r[i]:n),c.append(h),d.addEventListener("input",()=>{h.textContent=d.value,a?r[i]=parseFloat(d.value):typeof t=="function"&&t(parseFloat(d.value)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),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 o=typeof e.name=="string"&&e.name||" ",a=!1,p=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),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=o,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),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let l=(()=>a?r[i]?" p-gui__switch-checkbox--active":"":n?" p-gui__switch-checkbox--active":"")();const f=document.createElement("div");f.className="p-gui__switch-checkbox"+l,s.append(f),a&&Object.defineProperty(r,i,{set:c=>{this.propReferences[p]=c,c?f.classList.add("p-gui__switch-checkbox--active"):f.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 o=typeof e.name=="string"?e.name:" ",a=!1,p=null,r=e.obj,i=e.prop,n=Array.isArray(e.values)?e.values:null,s,l=typeof n[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(!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 l?n.find(d=>d.value===r[i]).value:n.indexOf(r[i]);if(typeof r[i]=="number")return l?n.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 f=document.createElement("div");f.className="p-gui__list",f.textContent=o,this.wrapper.append(f);let c=document.createElement("select");f.append(c),c.className="p-gui__list-dropdown",c.addEventListener("change",d=>{a?r[i]=d.target.value:t&&t(d.target.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),n&&n.forEach((d,h)=>{const g=l?d.name:d,u=l?d.value:d;let m=document.createElement("option");m.setAttribute("value",u),m.textContent=g,c.append(m),(!l&&s==h||l&&s==u)&&m.setAttribute("selected","")}),a&&Object.defineProperty(r,i,{set:d=>{let h,g,u;l?(u=n.find(v=>v.value==d),g=(u==null?void 0:u.value)||n[0].value,h=n.indexOf(u)):(typeof d=="string"&&(h=n.indexOf(d),g=d),typeof d=="number"&&(h=d,g=n[d])),this.propReferences[p]=l?g:d;const m=c.querySelector("[selected]");m&&m.removeAttribute("selected"),c.querySelectorAll("option")[h].setAttribute("selected",""),typeof t=="function"&&t(l?u:g,h)},get:()=>this.propReferences[p]})}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,p=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,f=e.y.obj,c=e.y.prop,d=this.propReferences.push(f[c])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const h=document.createElement("div");h.className="p-gui__vector2",h.textContent=o,this.wrapper.append(h);const g=document.createElement("div");g.className="p-gui__vector-value",g.textContent=n[s]+", "+f[c],h.append(g);const u=document.createElement("div");u.className="p-gui__vector2-area",h.append(u),u.addEventListener("click",b=>{n[s]=parseFloat(this._mapLinear(b.offsetX,0,u.clientWidth,a,p).toFixed(2)),f[c]=parseFloat(this._mapLinear(b.offsetY,0,u.clientHeight,i,r).toFixed(2)),t&&t(n[s],n[c]),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let m=!1;u.addEventListener("pointerdown",b=>{m=!0}),u.addEventListener("pointerup",()=>{m=!1}),u.addEventListener("pointermove",b=>{m&&(n[s]=parseFloat(this._mapLinear(b.offsetX,0,u.clientWidth,a,p).toFixed(2)),f[c]=parseFloat(this._mapLinear(b.offsetY,0,u.clientHeight,i,r).toFixed(2)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t(n[s],n[c]))});const v=document.createElement("div");v.className="p-gui__vector2-line p-gui__vector2-line-x",u.append(v);const y=document.createElement("div");y.className="p-gui__vector2-line p-gui__vector2-line-y",u.append(y);const _=document.createElement("div");_.className="p-gui__vector2-dot",u.append(_),_.style.left=this._mapLinear(n[s],a,p,0,u.clientWidth)+"px",_.style.top=this._mapLinear(f[c],r,i,u.clientHeight,0)+"px",Object.defineProperty(n,s,{set:b=>{this.propReferences[l]=b,_.style.left=this._mapLinear(b,a,p,0,u.clientWidth)+"px",g.textContent=String(b)+", "+f[c]},get:()=>this.propReferences[l]}),Object.defineProperty(f,c,{set:b=>{this.propReferences[d]=b,_.style.top=this._mapLinear(b,r,i,u.clientHeight,0)+"px",g.textContent=n[s]+", "+String(b)},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 o=typeof e.name=="string"&&e.name||" ",a=!1,p=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),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=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),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),a&&Object.defineProperty(r,i,{set:f=>{this.propReferences[p]=f,l.value=f,typeof t=="function"&&t(f)},get:()=>this.propReferences[p]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,o=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 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 x({isFolder:!0,folderOptions:{wrapper:n,parent:this,firstParent:this.firstParent}});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",o)}function o(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",o)}}toggleClose(){this.closed=!this.closed,this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,o,a,p){return a+(e-t)*(p-a)/(o-t)}}return x});
|
|
531
|
+
}`)}_folderConstructor(e){this.wrapper=e.wrapper,this.isFolder=!0,this.parent=e.parent,this.firstParent=e.firstParent}_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;const a=document.createElement("div");a.className="p-gui__button",a.textContent=o,a.addEventListener("click",()=>{this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&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(/^.*[\\\/]/,""),l;e.name==null?l=a:l=typeof e.name=="string"&&e.name||" ";const i=e.selected===!0,r=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),i&&r&&s.classList.add("p-gui__image--selected");const d=document.createElement("div");return d.className="p-gui__image-text",d.textContent=l,s.append(d),s.addEventListener("click",()=>{let f=s.parentElement.querySelectorAll(".p-gui__image--selected");for(let c=0;c<f.length;c++)f[c].classList.remove("p-gui__image--selected");r&&s.classList.add("p-gui__image--selected"),typeof t=="function"&&t({path:o,text:l}),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),s}slider(e={},t){const o=new x(e,t);this.wrapper.append(o)}sliderOld(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,l=null,i=e.obj,r=e.prop,n=typeof e.value=="number"?e.value:null,s=e.min??0,d=e.max??1,f=e.step||(d-s)/100;if(n!==null)(r!=null||i!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] slider() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] slider() "obj" parameter must be an object. Received: ${typeof i}.`);o==" "&&(o=r),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i!=null)&&console.warn('[GUI] slider() "obj" and "prop" parameters must be used together.'),n=(d-s)/2;this.imageContainer=null;const c=document.createElement("div");c.className="p-gui__slider",this.wrapper.append(c);const u=document.createElement("div");u.className="p-gui__slider-name",u.textContent=o,c.append(u);const p=document.createElement("input");p.className="p-gui__slider-ctrl",p.setAttribute("type","range"),p.setAttribute("min",s),p.setAttribute("max",d),p.setAttribute("step",f),p.setAttribute("value",a?i[r]:n),c.append(p);const g=document.createElement("input");g.className="p-gui__slider-value",g.value=String(a?i[r]:n),c.append(g),g.addEventListener("change",()=>{p.value=parseFloat(g.value)}),p.addEventListener("input",()=>{g.value=p.value,a?i[r]=parseFloat(p.value):typeof t=="function"&&t(parseFloat(p.value)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),a&&Object.defineProperty(i,r,{set:h=>{this.propReferences[l]=h,p.value=h,g.textContent=String(h),typeof t=="function"&&t(parseFloat(p.value))},get:()=>this.propReferences[l]})}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,l=null,i=e.obj,r=e.prop,n=typeof e.value=="boolean"?e.value:null;if(n!==null)(r!=null||i!=null)&&console.warn('[GUI] toggle() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] toggle() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] toggle() "obj" parameter must be an object. Received: ${typeof i}.`);o==" "&&(o=r),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i==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",c=>{const u=c.target.childNodes[1];let p=!0;u.classList.contains("p-gui__switch-checkbox--active")&&(p=!1),u.classList.toggle("p-gui__switch-checkbox--active"),a?i[r]=p:typeof t=="function"&&t(p),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let d=(()=>a?i[r]?" p-gui__switch-checkbox--active":"":n?" p-gui__switch-checkbox--active":"")();const f=document.createElement("div");f.className="p-gui__switch-checkbox"+d,s.append(f),a&&Object.defineProperty(i,r,{set:c=>{this.propReferences[l]=c,c?f.classList.add("p-gui__switch-checkbox--active"):f.classList.remove("p-gui__switch-checkbox--active"),typeof t=="function"&&t(c)},get:()=>this.propReferences[l]})}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,l=null,i=e.obj,r=e.prop,n=Array.isArray(e.values)?e.values:null,s,d=typeof n[0]!="string";if(t=typeof t=="function"?t:null,e.value!==void 0||e.value===void 0&&i===void 0&&r===void 0)(r!=null||i!=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(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] list() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] list() "obj" parameter must be an object. Received: ${typeof i}.`);s=(()=>{if(!n)return null;if(typeof i[r]=="string")return d?n.find(u=>u.value===i[r]).value:n.indexOf(i[r]);if(typeof i[r]=="number")return d?n.find(u=>u.value===i[r]).value:i[r]})(),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i==null)&&console.warn('[GUI] list() "obj" and "prop" parameters must be used together.');this.imageContainer=null;let f=document.createElement("div");f.className="p-gui__list",f.textContent=o,this.wrapper.append(f);let c=document.createElement("select");f.append(c),c.className="p-gui__list-dropdown",c.addEventListener("change",u=>{a?i[r]=u.target.value:t&&t(u.target.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),n&&n.forEach((u,p)=>{const g=d?u.name:u,h=d?u.value:u;let m=document.createElement("option");m.setAttribute("value",h),m.textContent=g,c.append(m),(!d&&s==p||d&&s==h)&&m.setAttribute("selected","")}),a&&Object.defineProperty(i,r,{set:u=>{let p,g,h;d?(h=n.find(w=>w.value==u),g=(h==null?void 0:h.value)||n[0].value,p=n.indexOf(h)):(typeof u=="string"&&(p=n.indexOf(u),g=u),typeof u=="number"&&(p=u,g=n[u])),this.propReferences[l]=d?g:u;const m=c.querySelector("[selected]");m&&m.removeAttribute("selected"),c.querySelectorAll("option")[p].setAttribute("selected",""),typeof t=="function"&&t(d?h:g,p)},get:()=>this.propReferences[l]})}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,l=e.x.max??1,i=e.y.min??0,r=e.y.max??1,n=e.x.obj,s=e.x.prop,d=this.propReferences.push(n[s])-1,f=e.y.obj,c=e.y.prop,u=this.propReferences.push(f[c])-1;t=typeof t=="function"?t:null,this.imageContainer=null;const p=document.createElement("div");p.className="p-gui__vector2",p.textContent=o,this.wrapper.append(p);const g=document.createElement("div");g.className="p-gui__vector-value",g.textContent=n[s]+", "+f[c],p.append(g);const h=document.createElement("div");h.className="p-gui__vector2-area",p.append(h),h.addEventListener("click",b=>{n[s]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,l).toFixed(2)),f[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,r,i).toFixed(2)),t&&t(n[s],n[c]),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()});let m=!1;h.addEventListener("pointerdown",b=>{m=!0}),h.addEventListener("pointerup",()=>{m=!1}),h.addEventListener("pointermove",b=>{m&&(n[s]=parseFloat(this._mapLinear(b.offsetX,0,h.clientWidth,a,l).toFixed(2)),f[c]=parseFloat(this._mapLinear(b.offsetY,0,h.clientHeight,r,i).toFixed(2)),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate(),t&&t(n[s],n[c]))});const w=document.createElement("div");w.className="p-gui__vector2-line p-gui__vector2-line-x",h.append(w);const E=document.createElement("div");E.className="p-gui__vector2-line p-gui__vector2-line-y",h.append(E);const _=document.createElement("div");_.className="p-gui__vector2-dot",h.append(_),_.style.left=this._mapLinear(n[s],a,l,0,h.clientWidth)+"px",_.style.top=this._mapLinear(f[c],i,r,h.clientHeight,0)+"px",Object.defineProperty(n,s,{set:b=>{this.propReferences[d]=b,_.style.left=this._mapLinear(b,a,l,0,h.clientWidth)+"px",g.textContent=String(b)+", "+f[c]},get:()=>this.propReferences[d]}),Object.defineProperty(f,c,{set:b=>{this.propReferences[u]=b,_.style.top=this._mapLinear(b,i,r,h.clientHeight,0)+"px",g.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,l=null,i=e.obj,r=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)(r!=null||i!=null)&&console.warn('[GUI] color() "obj" and "prop" parameters are ignored when a "value" parameter is used.');else if(r!=null&&i!=null){if(typeof r!="string")throw Error(`[GUI] color() "prop" parameter must be an string. Received: ${typeof r}.`);if(typeof i!="object")throw Error(`[GUI] color() "obj" parameter must be an object. Received: ${typeof i}.`);o==" "&&(o=r),l=this.propReferences.push(i[r])-1,a=!0}else(r!=null&&i==null||r==null&&i==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 d=document.createElement("input");d.className="p-gui__color-picker",d.setAttribute("type","color"),d.value=n,s.append(d),typeof t=="function"&&d.addEventListener("input",()=>{a?i[r]=d.value:typeof t=="function"&&t(d.value),this.onUpdate?this.onUpdate():this.isFolder&&this.firstParent.onUpdate&&this.firstParent.onUpdate()}),a&&Object.defineProperty(i,r,{set:f=>{this.propReferences[l]=f,d.value=f,typeof t=="function"&&t(f)},get:()=>this.propReferences[l]})}folder(e={}){let t=typeof e.closed=="boolean"?e.closed:!1,o=e.name||"",a=e.color||null,l=e.maxHeight||null;this.imageContainer=null;let i="p-gui__folder";this.folders.length==0&&(i+=" p-gui__folder--first"),t&&(i+=" p-gui__folder--closed");let r=a?`background-color: ${a};`:"";r+=l?`max-height: ${l}px;`:"";const n=document.createElement("div");n.className=i,n.style=r,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 d=new y({isFolder:!0,folderOptions:{wrapper:n,parent:this,firstParent:this.firstParent}});return this.folders.push(d),d}_makeDraggable(){var e=this;this.header.addEventListener("pointerdown",t),this.header.addEventListener("pointerup",a);function t(l){l.preventDefault(),e.position.initX=e.position.x,e.position.initY=e.position.y,e.position.prevX=l.clientX,e.position.prevY=l.clientY,document.addEventListener("pointermove",o)}function o(l){l.preventDefault(),e.hasBeenDragged||(e.hasBeenDragged=!0,e.wrapper.setAttribute("data-dragged","true")),e.position.x=e.position.initX+l.clientX-e.position.prevX,e.position.y=e.position.initY+l.clientY-e.position.prevY,e.wrapper.style.transform="translate3d("+e.position.x+"px,"+e.position.y+"px,0)"}function a(l){document.removeEventListener("pointermove",o)}}toggleClose(){this.closed=!this.closed,this.closed?(this.previousInnerScroll=this.wrapper.scrollTop,this.wrapper.scrollTo(0,0)):this.wrapper.scrollTo(0,this.previousInnerScroll),this.wrapper.classList.toggle("p-gui--collapsed")}kill(){this.wrapper.remove()}_mapLinear(e,t,o,a,l){return a+(e-t)*(l-a)/(o-t)}}return y});
|