perfect-gui 5.1.3 → 6.0.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/.eslintrc.js +30 -0
- package/dist/perfect-gui.js +454 -585
- package/package.json +5 -3
- package/src/components/{Button.js → Button.ts} +26 -12
- package/src/components/Color.ts +93 -0
- package/src/components/{Image.js → Image.ts} +40 -25
- package/src/components/List.ts +173 -0
- package/src/components/{Slider.js → Slider.ts} +78 -77
- package/src/components/Toggle.ts +98 -0
- package/src/components/{Vector2.js → Vector2.ts} +47 -36
- package/src/{index.js → index.ts} +287 -142
- package/src/plugins/three.js +2 -8
- package/tsconfig.json +111 -0
- package/src/components/Color.js +0 -107
- package/src/components/List.js +0 -178
- package/src/components/Toggle.js +0 -124
package/dist/perfect-gui.js
CHANGED
|
@@ -1,375 +1,242 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
class
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
c = !1, i = e;
|
|
241
|
-
else
|
|
242
|
-
throw Error("[GUI] color() invalid parameters.");
|
|
243
|
-
let a = typeof i.label == "string" && i.label || " ", h = null;
|
|
244
|
-
const p = typeof i.tooltip == "string" ? i.tooltip : i.tooltip === !0 ? a : null;
|
|
245
|
-
c ? (a == " " && (a = o), h = this.parent.propReferences.push(n[o]) - 1, l = n[o] || "#000000") : (typeof i.value == "string" && (i.value.length != 7 || i.value[0] != "#" ? console.error(
|
|
246
|
-
`[GUI] color() 'value' parameter must be an hexadecimal string in the format "#ffffff". Received: "${i.value}".`
|
|
247
|
-
) : l = i.value), l || (l = "#000000"));
|
|
248
|
-
const s = document.createElement("div");
|
|
249
|
-
s.className = "p-gui__color", s.textContent = a, p && s.setAttribute("title", p), this.parent.wrapper.append(s), this.element = s;
|
|
250
|
-
const f = document.createElement("input");
|
|
251
|
-
f.className = "p-gui__color-picker", f.setAttribute("type", "color"), f.value = l, s.append(f), f.addEventListener("input", () => {
|
|
252
|
-
c ? n[o] = f.value : typeof this.callback == "function" && this.callback(f.value), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
253
|
-
}), c && Object.defineProperty(n, o, {
|
|
254
|
-
set: (b) => {
|
|
255
|
-
this.parent.propReferences[h] = b, f.value = b, typeof this.callback == "function" && this.callback(b);
|
|
256
|
-
},
|
|
257
|
-
get: () => this.parent.propReferences[h]
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
onChange(t) {
|
|
261
|
-
return this.callback = t, this;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
class G {
|
|
265
|
-
constructor(t, e, r, d, i) {
|
|
266
|
-
this.parent = t, this.callback = null;
|
|
267
|
-
let l = {}, c, n, o, a;
|
|
268
|
-
if (e && typeof e == "object" && typeof r == "string" && typeof d == "string")
|
|
269
|
-
c = e, n = e, o = r, a = d, l = i || {};
|
|
270
|
-
else if (e && typeof e == "object" && e.x && e.x.obj)
|
|
271
|
-
l = e, c = l.x.obj, o = l.x.prop, n = l.y.obj, a = l.y.prop;
|
|
272
|
-
else
|
|
273
|
-
throw Error(
|
|
274
|
-
"[GUI] vector2() invalid parameters. Use: gui.vector2(obj, 'propX', 'propY', params)"
|
|
275
|
-
);
|
|
276
|
-
let h = typeof l.label == "string" && l.label || " ";
|
|
277
|
-
h === " " && (h = o + " / " + a);
|
|
278
|
-
const p = l.x || {}, s = l.y || {}, f = p.min ?? l.min ?? 0, b = p.max ?? l.max ?? 1, g = s.min ?? l.min ?? 0, u = s.max ?? l.max ?? 1, m = p.step || l.step || (b - f) / 100, x = s.step || l.step || (u - g) / 100, w = this.parent._countDecimals(m), y = this.parent._countDecimals(x), U = this.parent.propReferences.push(c[o]) - 1, L = this.parent.propReferences.push(n[a]) - 1, D = typeof l.tooltip == "string" ? l.tooltip : l.tooltip === !0 ? h : null, A = document.createElement("div");
|
|
279
|
-
A.className = "p-gui__vector2", A.textContent = h, D && A.setAttribute("title", D), this.parent.wrapper.append(A);
|
|
280
|
-
const E = document.createElement("div");
|
|
281
|
-
E.className = "p-gui__vector-value", E.textContent = c[o] + ", " + n[a], A.append(E);
|
|
282
|
-
const _ = document.createElement("div");
|
|
283
|
-
_.className = "p-gui__vector2-area", A.append(_), _.addEventListener("click", (v) => {
|
|
284
|
-
const j = parseFloat(
|
|
285
|
-
this.parent._mapLinear(
|
|
286
|
-
v.offsetX,
|
|
287
|
-
0,
|
|
288
|
-
_.clientWidth,
|
|
289
|
-
f,
|
|
290
|
-
b
|
|
291
|
-
)
|
|
292
|
-
), R = parseFloat(
|
|
293
|
-
this.parent._mapLinear(
|
|
294
|
-
v.offsetY,
|
|
295
|
-
0,
|
|
296
|
-
_.clientHeight,
|
|
297
|
-
u,
|
|
298
|
-
g
|
|
299
|
-
)
|
|
300
|
-
);
|
|
301
|
-
c[o] = j.toFixed(w), n[a] = R.toFixed(y), this.callback && this.callback(c[o], c[a]), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
302
|
-
});
|
|
303
|
-
const O = (v) => {
|
|
304
|
-
const j = _.getBoundingClientRect(), R = v.clientX - j.left, H = v.clientY - j.top, M = this.parent._mapLinear(
|
|
305
|
-
R,
|
|
306
|
-
0,
|
|
307
|
-
_.clientWidth,
|
|
308
|
-
f,
|
|
309
|
-
b
|
|
310
|
-
), X = this.parent._mapLinear(
|
|
311
|
-
H,
|
|
312
|
-
0,
|
|
313
|
-
_.clientHeight,
|
|
314
|
-
u,
|
|
315
|
-
g
|
|
316
|
-
), $ = Math.max(f, Math.min(b, M)), W = Math.max(g, Math.min(u, X));
|
|
317
|
-
c[o] = parseFloat($.toFixed(w)), n[a] = parseFloat(W.toFixed(y)), this.callback && this.callback(c[o], n[a]), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
318
|
-
};
|
|
319
|
-
_.addEventListener("pointerdown", (v) => {
|
|
320
|
-
O(v), document.addEventListener("pointermove", O), document.addEventListener(
|
|
321
|
-
"pointerup",
|
|
322
|
-
() => {
|
|
323
|
-
document.removeEventListener(
|
|
324
|
-
"pointermove",
|
|
325
|
-
O
|
|
326
|
-
);
|
|
327
|
-
},
|
|
328
|
-
{ once: !0 }
|
|
329
|
-
);
|
|
330
|
-
});
|
|
331
|
-
const N = document.createElement("div");
|
|
332
|
-
N.className = "p-gui__vector2-line p-gui__vector2-line-x", _.append(N);
|
|
333
|
-
const F = document.createElement("div");
|
|
334
|
-
F.className = "p-gui__vector2-line p-gui__vector2-line-y", _.append(F);
|
|
335
|
-
const I = document.createElement("div");
|
|
336
|
-
I.className = "p-gui__vector2-dot", _.append(I);
|
|
337
|
-
const P = () => {
|
|
338
|
-
I.style.left = this.parent._mapLinear(
|
|
339
|
-
c[o],
|
|
340
|
-
f,
|
|
341
|
-
b,
|
|
342
|
-
0,
|
|
343
|
-
_.clientWidth
|
|
344
|
-
) + "px", I.style.top = this.parent._mapLinear(
|
|
345
|
-
n[a],
|
|
346
|
-
g,
|
|
347
|
-
u,
|
|
348
|
-
_.clientHeight,
|
|
349
|
-
0
|
|
350
|
-
) + "px";
|
|
351
|
-
};
|
|
352
|
-
P(), new ResizeObserver(() => {
|
|
353
|
-
P();
|
|
354
|
-
}).observe(_), Object.defineProperty(c, o, {
|
|
355
|
-
set: (v) => {
|
|
356
|
-
this.parent.propReferences[U] = v, P(), E.textContent = String(v) + ", " + n[a];
|
|
357
|
-
},
|
|
358
|
-
get: () => this.parent.propReferences[U]
|
|
359
|
-
}), Object.defineProperty(n, a, {
|
|
360
|
-
set: (v) => {
|
|
361
|
-
this.parent.propReferences[L] = v, P(), E.textContent = c[o] + ", " + String(v);
|
|
362
|
-
},
|
|
363
|
-
get: () => this.parent.propReferences[L]
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
onChange(t) {
|
|
367
|
-
return this.callback = t, this;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const Q = ".p-gui__button{background:var(--color-accent);text-align:center;color:var(--color-bg);border:1px solid transparent;box-sizing:border-box;transition:var(--transition) background,var(--transition) border-color}.p-gui__button:hover{background:var(--color-accent-hover);border-color:#fff3}.p-gui__folder .p-gui__button{margin-inline:0}", q = ".p-gui__slider{position:relative;min-height:14px;display:flex;align-items:center;justify-content:space-between;gap:10px;color:var(--color-text-dark);transition:color var(--transition);padding:3px;touch-action:none}.p-gui__slider:hover{color:var(--color-text-light)}.p-gui__slider-name{width:50%;text-overflow:ellipsis;overflow:hidden}.p-gui__slider-ctrl{-webkit-appearance:none;padding:0;font:inherit;outline:none;box-sizing:border-box;cursor:pointer;position:relative;right:0;height:14px;margin:0 0 0 auto;width:37%;touch-action:none}.p-gui__slider-bar{position:absolute;top:50%;left:0;height:2px;background:#fff3;width:100%;transform:translateY(-50%)}.p-gui__slider-filling{position:absolute;top:-25%;left:0;height:100%;background:var(--color-accent);width:0;pointer-events:none}.p-gui__slider:hover .p-gui__slider-filling{background:var(--color-accent-hover)}.p-gui__slider-handle{width:9px;height:9px;position:absolute;top:50%;left:0;border-radius:2px;transform:translate(-50%,-50%);pointer-events:none;background:var(--color-text-dark);box-shadow:0 0 2px #00000080}.p-gui__slider:hover .p-gui__slider-handle{background:var(--color-text-light)}.p-gui__slider-value{display:inline-block;right:7px;width:13%;border:none;color:#fff;border-radius:2px;background:#ffffff1a;padding:2px 4px;color:inherit}.p-gui__slider-value:focus{outline:none}", J = ".p-gui__list{cursor:default;color:var(--color-text-dark);transition:var(--transition) color}.p-gui__list:hover{color:var(--color-text-light)}.p-gui__list-dropdown{background:#ffffff0d;color:#fff;padding:0 12px 0 5px;top:0}.p-gui__list-dropdown{position:absolute;right:5px;top:0;bottom:0;margin:auto;height:calc(100% - 4px);cursor:pointer;border-radius:3px;border:1px solid var(--color-border-2);outline:none}.p-gui__list-dropdown option{background:#fff;color:#000}.p-gui__list-dropdown:hover{background:#ffffff1a}", Z = ".p-gui__toggle{color:var(--color-text-dark);transition:var(--transition) background,var(--transition) color}.p-gui__toggle:hover{background:#ffffff1a;color:var(--color-text-light)}.p-gui__folder .p-gui__toggle{margin-inline:0}.p-gui__toggle-checkbox{width:10px;height:10px;background-color:#ffffff1a;position:absolute;top:0;right:10px;bottom:0;margin:auto;border-radius:2px;pointer-events:none;transition:.5s all ease}.p-gui__toggle-checkbox--active{background-color:#ddd;box-shadow:0 0 5px #ddd}", K = ".p-gui__color{cursor:default;color:var(--color-text-dark);transition:var(--transition) color}.p-gui__color:hover{color:var(--color-text-light)}.p-gui__color-picker{position:absolute;right:5px;top:0;bottom:0;margin:auto;height:calc(100% - 4px);cursor:pointer;border-radius:3px;border:1px solid var(--color-border-2);outline:none;-webkit-appearance:none;padding:0;background-color:transparent;border:1px solid #222222;overflow:hidden}.p-gui__color-picker::-webkit-color-swatch-wrapper{padding:0}.p-gui__color-picker::-webkit-color-swatch{border:none}", ee = ".p-gui__vector2{background:transparent;aspect-ratio:1;padding-bottom:0;color:var(--color-text-dark)}.p-gui__vector2:hover{color:var(--color-text-light)}.p-gui__vector2-area{position:relative;background:#0000004d;margin-top:8px;width:100%;height:calc(100% - 28px);touch-action:none}.p-gui__vector2-line{position:absolute;background:#fff;opacity:.3;pointer-events:none}.p-gui__vector2-line-x{width:100%;height:1px;left:0;top:50%;transform:translateY(-50%)}.p-gui__vector2-line-y{width:1px;height:100%;top:0;left:50%;transform:translate(-50%)}.p-gui__vector2-dot{position:absolute;top:0;left:0;width:8px;height:8px;border-radius:50%;background:#d5d5d5;border:2px solid #ff9999;transform:translate(-50%,-50%);pointer-events:none}.p-gui__vector-value{display:inline-block;right:7px;position:absolute}", te = '.p-gui__image-container{width:100%;padding:3px;display:flex;justify-content:flex-start;flex-wrap:wrap;box-sizing:border-box}.p-gui__image{background-size:cover;cursor:pointer;position:relative;margin:1px 2.5px 19px;border-radius:var(--main-border-radius);flex:0 0 calc(33.333% - 5px);height:90px;background-position:center;color:var(--color-text-dark);transition:var(--transition) color}.p-gui__image:hover{color:var(--color-text-light)}.p-gui__image:after{position:absolute;top:0;left:0;width:100%;height:100%;content:"";border:1px solid transparent;box-sizing:border-box;border-radius:var(--main-border-radius);transition:var(--transition) border-color}.p-gui__image--selected:after{border-color:#06ff89}.p-gui__image-text{position:absolute;bottom:-15px;text-shadow:0 -1px 0 #111;white-space:nowrap;width:100%;overflow:hidden;text-overflow:ellipsis}', ie = ".p-gui__folder{width:100%;position:relative;background:var(--color-bg);margin-bottom:2px;display:flex;flex-wrap:wrap;border:1px solid var(--color-border-2);border-radius:var(--main-border-radius);box-sizing:border-box;border-left:1px solid #bbbbbb}.p-gui__folder--first{margin-top:0}.p-gui__folder-content{display:grid;grid-template-rows:1fr;transition:.25s grid-template-rows ease;width:100%}.p-gui__folder-inner{overflow:hidden;padding-left:3px;padding-right:2px}.p-gui__folder--closed .p-gui__folder-content{grid-template-rows:0fr}.p-gui__folder-header{padding:5px 3px;background-color:#00000080;color:#fff;cursor:pointer;width:100%;box-sizing:border-box;border-top-right-radius:var(--main-border-radius);border-bottom-right-radius:var(--main-border-radius)}.p-gui__folder-header:hover{background-color:#000000bf}.p-gui__folder-arrow{width:8px;height:8px;display:inline-block;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAHlBMVEUAAAD///////////////////////////////////8kfJuVAAAACXRSTlMA9Z1fCdMo1yxEJnA0AAAAK0lEQVQI12PABlRgjKkJUMZMYRhjpgqMAZSEMICSaIzpDWiKhdENhEhgAgATSg5jyWnYewAAAABJRU5ErkJggg==);background-size:contain;margin-right:5px;transform:rotate(90deg)}.p-gui__folder--closed .p-gui__folder-arrow{transform:rotate(0)}", re = ".p-gui__tabs{width:100%;position:relative;background:var(--color-bg);margin-bottom:2px;border:1px solid var(--color-border-2);border-radius:var(--main-border-radius);box-sizing:border-box;border-left:1px solid #bbbbbb;padding-block:0}.p-gui__tabs--first{margin-top:0}.p-gui__tabs-header{display:flex;background-color:#00000080;border-top-left-radius:var(--main-border-radius);border-top-right-radius:var(--main-border-radius)}.p-gui__tab-button{padding:7px 10px;background:transparent;color:#bbb;cursor:pointer;border:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;font-family:inherit}.p-gui__tab-button:last-child{border-right:none}.p-gui__tab-button:hover{color:#fff}.p-gui__tab-button--active{background-color:var(--color-bg);color:#fff;border-bottom:1px solid transparent}.p-gui__tabs-content{position:relative;width:100%}.p-gui__tab-pane{display:none;width:100%;padding-top:4px;box-sizing:border-box}.p-gui__tab-pane--active{display:block}";
|
|
371
|
-
function oe(k) {
|
|
372
|
-
return `
|
|
1
|
+
//#region src/components/Button.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
constructor(e, t = {}) {
|
|
4
|
+
if (this.callback = null, this.parent = e, typeof t != "object") throw Error(`[GUI] button() first parameter must be an object. Received: ${typeof t}.`);
|
|
5
|
+
let n = t.label || "\xA0", r = typeof t.tooltip == "string" ? t.tooltip : t.tooltip === !0 ? n : null, i = document.createElement("div");
|
|
6
|
+
i.className = "p-gui__button", i.textContent = n, r && i.setAttribute("title", r), i.addEventListener("click", () => {
|
|
7
|
+
this.callback && this.callback(), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
8
|
+
}), typeof t.color == "string" && (i.style.setProperty("--color-accent", t.color), i.style.setProperty("--color-accent-hover", t.hoverColor || t.color)), this.parent.wrapper.append(i), this.element = i;
|
|
9
|
+
}
|
|
10
|
+
onClick(e) {
|
|
11
|
+
return this.callback = e, this;
|
|
12
|
+
}
|
|
13
|
+
}, t = class {
|
|
14
|
+
constructor(e, t, n, r = {}) {
|
|
15
|
+
if (this.callback = null, this.parent = e, this.propReferences = [], t && typeof t == "object" && typeof n == "string") this.obj = t, this.prop = n;
|
|
16
|
+
else throw Error("[GUI] slider() invalid parameters.");
|
|
17
|
+
let i = typeof r.label == "string" && r.label || "\xA0";
|
|
18
|
+
i == "\xA0" && (i = this.prop), this.min = r.min ?? 0, this.max = r.max ?? 1, this.step = r.step || (this.max - this.min) / 100, this.decimals = this.parent._countDecimals(this.step);
|
|
19
|
+
let a = this.propReferences.push(this.obj[this.prop]) - 1, o = typeof r.tooltip == "string" ? r.tooltip : r.tooltip === !0 ? i : null, s = document.createElement("div");
|
|
20
|
+
s.className = "p-gui__slider", o && s.setAttribute("title", o), this.parent.wrapper.append(s), this.element = s;
|
|
21
|
+
let c = document.createElement("div");
|
|
22
|
+
c.className = "p-gui__slider-name", c.textContent = i, s.append(c), this.ctrlDiv = document.createElement("div"), this.ctrlDiv.prevPosition = 0, this.ctrlDiv.className = "p-gui__slider-ctrl", this.ctrlDiv.setAttribute("type", "range"), this.ctrlDiv.setAttribute("min", String(this.min)), this.ctrlDiv.setAttribute("max", String(this.max)), s.append(this.ctrlDiv);
|
|
23
|
+
let l = document.createElement("div");
|
|
24
|
+
l.className = "p-gui__slider-bar", this.ctrlDiv.append(l), 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", l.append(this.filling), this.valueInput = document.createElement("input"), this.valueInput.className = "p-gui__slider-value", this.valueInput.value = this.obj[this.prop], s.append(this.valueInput), setTimeout(() => {
|
|
25
|
+
let e = this.ctrlDiv.offsetWidth, t = this.handle.offsetWidth;
|
|
26
|
+
this.handle.position = this.parent._mapLinear(parseFloat(this.valueInput.value), this.min, this.max, t / 2, e - t / 2), this.handle.position = Math.min(this.handle.position, e - t / 2), this.handle.position = Math.max(this.handle.position, t / 2), this.handle.style.transform = `translate(-50%, -50%) translateX(${this.handle.position}px)`, this.filling.style.width = `${this.handle.position}px`;
|
|
27
|
+
}, 0), this.valueInput.addEventListener("change", () => {
|
|
28
|
+
this._updateHandlePositionFromValue(), this._triggerCallbacks();
|
|
29
|
+
}), this.ctrlDiv.addEventListener("pointerdown", (e) => {
|
|
30
|
+
this.ctrlDiv.pointerDown = !0, this.ctrlDiv.prevPosition = e.clientX, this._updateHandlePositionFromPointer(e, !0);
|
|
31
|
+
}), window.addEventListener("pointerup", (e) => {
|
|
32
|
+
this.ctrlDiv.pointerDown = !1;
|
|
33
|
+
}), window.addEventListener("pointercancel", (e) => {
|
|
34
|
+
this.ctrlDiv.pointerDown = !1;
|
|
35
|
+
}), window.addEventListener("pointermove", (e) => {
|
|
36
|
+
this.ctrlDiv.pointerDown && (this.ctrlDiv.pointerDelta = e.clientX - (this.ctrlDiv.prevPosition ?? 0), this._updateHandlePositionFromPointer(e));
|
|
37
|
+
}), Object.defineProperty(this.obj, this.prop, {
|
|
38
|
+
set: (e) => {
|
|
39
|
+
this.propReferences[a] = e, this.valueInput.value = e, this._updateHandlePositionFromValue(), this.callback && this.callback(parseFloat(this.valueInput.value));
|
|
40
|
+
},
|
|
41
|
+
get: () => this.propReferences[a]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
_updateHandlePositionFromPointer(e, t = !1) {
|
|
45
|
+
let n = this.ctrlDiv.getBoundingClientRect(), r = n.width, i = this.handle.offsetWidth, a = e.clientX - (this.ctrlDiv.prevPosition ?? 0), o = parseFloat(this.valueInput.value), s;
|
|
46
|
+
s = t ? e.clientX - n.left : (this.handle.position ?? 0) + a, s = Math.max(i / 2, Math.min(s, r - i / 2));
|
|
47
|
+
let c = this.min + (this.max - this.min) * (s - i / 2) / (r - i);
|
|
48
|
+
c = c > o ? this._quantizeFloor(c, this.step) : this._quantizeCeil(c, this.step), c = parseFloat(c.toFixed(9));
|
|
49
|
+
let l = parseFloat((o + this.step).toFixed(9)), u = parseFloat((o - this.step).toFixed(9));
|
|
50
|
+
(c >= l || c <= u) && (c = parseFloat(c.toFixed(this.decimals)), this.valueInput.value = String(c), this.ctrlDiv.prevPosition = e.clientX, this.handle.style.transform = `translate(-50%, -50%) translateX(${s}px)`, this.handle.position = s, this.filling.style.width = this.handle.position + "px", this._triggerCallbacks());
|
|
51
|
+
}
|
|
52
|
+
_updateHandlePositionFromValue() {
|
|
53
|
+
let e = this.ctrlDiv.offsetWidth, t = this.handle.offsetWidth, n = this.parent._mapLinear(parseFloat(this.valueInput.value), this.min, this.max, t / 2, e - t / 2);
|
|
54
|
+
n = Math.max(t / 2, Math.min(n, e - t / 2)), this.handle.style.transform = `translate(-50%, -50%) translateX(${n}px)`, this.handle.position = n, this.filling.style.width = this.handle.position + "px";
|
|
55
|
+
}
|
|
56
|
+
_triggerCallbacks() {
|
|
57
|
+
this.obj[this.prop] = parseFloat(this.valueInput.value), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
58
|
+
}
|
|
59
|
+
_quantize(e, t) {
|
|
60
|
+
return t * Math.round(e / t);
|
|
61
|
+
}
|
|
62
|
+
_quantizeCeil(e, t) {
|
|
63
|
+
return t * Math.ceil(e / t);
|
|
64
|
+
}
|
|
65
|
+
_quantizeFloor(e, t) {
|
|
66
|
+
return t * Math.floor(e / t);
|
|
67
|
+
}
|
|
68
|
+
onChange(e) {
|
|
69
|
+
return this.callback = e, this;
|
|
70
|
+
}
|
|
71
|
+
}, n = class {
|
|
72
|
+
constructor(e, t, n = {}) {
|
|
73
|
+
if (this.callback = null, this.parent = e, t === void 0) throw Error("[GUI] image() path must be provided.");
|
|
74
|
+
if (typeof t != "string") throw Error("[GUI] image() path must be a string.");
|
|
75
|
+
if (typeof n != "object") throw Error(`[GUI] image() second parameter must be an object. Received: ${typeof n}.`);
|
|
76
|
+
let r = t.replace(/^.*[\\\/]/, ""), i;
|
|
77
|
+
i = n.label == null ? r : typeof n.label == "string" && n.label || "\xA0";
|
|
78
|
+
let a = typeof n.tooltip == "string" ? n.tooltip : n.tooltip === !0 ? i : null, o = n.selected === !0, s = n.selectionBorder !== !1, c = "";
|
|
79
|
+
if (n.width) {
|
|
80
|
+
let e = n.width;
|
|
81
|
+
typeof e == "number" && (e = `${e}px`), c += `flex: 0 0 calc(${e} - 5px); `;
|
|
82
|
+
}
|
|
83
|
+
if (n.height) {
|
|
84
|
+
let e = n.height;
|
|
85
|
+
typeof e == "number" && (e = `${e}px`), c += `height: ${e}; `;
|
|
86
|
+
}
|
|
87
|
+
let l = document.createElement("div");
|
|
88
|
+
l.className = "p-gui__image", l.style = "background-image: url(" + t + "); " + c, a && l.setAttribute("title", a), this.parent.imageContainer.append(l), this.element = l, o && s && l.classList.add("p-gui__image--selected");
|
|
89
|
+
let u = document.createElement("div");
|
|
90
|
+
u.className = "p-gui__image-text", u.textContent = i, l.append(u), l.addEventListener("click", () => {
|
|
91
|
+
let e = l.parentElement?.querySelectorAll(".p-gui__image--selected") || [];
|
|
92
|
+
for (let t = 0; t < e.length; t++) e[t].classList.remove("p-gui__image--selected");
|
|
93
|
+
s && l.classList.add("p-gui__image--selected"), typeof this.callback == "function" && this.callback({
|
|
94
|
+
path: t,
|
|
95
|
+
text: i
|
|
96
|
+
}), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
onClick(e) {
|
|
100
|
+
return this.callback = e, this;
|
|
101
|
+
}
|
|
102
|
+
}, r = class {
|
|
103
|
+
constructor(e, t, n, r = {}) {
|
|
104
|
+
if (this.parent = e, this.callback = null, !t || typeof t != "object" || typeof n != "string") throw Error("[GUI] toggle() invalid parameters.");
|
|
105
|
+
let i = typeof r.label == "string" && r.label !== "" ? r.label : n, a = this.parent.propReferences.push(t[n]) - 1, o = typeof r.tooltip == "string" ? r.tooltip : r.tooltip === !0 ? i : null, s = document.createElement("div");
|
|
106
|
+
s.textContent = i, s.className = "p-gui__toggle", o && s.setAttribute("title", o), this.parent.wrapper.append(s), this.element = s;
|
|
107
|
+
let c = t[n] ? " p-gui__toggle-checkbox--active" : "", l = document.createElement("div");
|
|
108
|
+
l.className = "p-gui__toggle-checkbox" + c, s.append(l), s.addEventListener("click", (e) => {
|
|
109
|
+
if (!e.target || !(e.target instanceof HTMLElement)) return;
|
|
110
|
+
let r = !0;
|
|
111
|
+
l.classList.contains("p-gui__toggle-checkbox--active") && (r = !1), l.classList.toggle("p-gui__toggle-checkbox--active"), t[n] = r, this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
112
|
+
}), Object.defineProperty(t, n, {
|
|
113
|
+
set: (e) => {
|
|
114
|
+
this.parent.propReferences[a] = e, e ? l.classList.add("p-gui__toggle-checkbox--active") : l.classList.remove("p-gui__toggle-checkbox--active"), typeof this.callback == "function" && this.callback(e);
|
|
115
|
+
},
|
|
116
|
+
get: () => this.parent.propReferences[a]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
onChange(e) {
|
|
120
|
+
return this.callback = e, this;
|
|
121
|
+
}
|
|
122
|
+
}, i = class {
|
|
123
|
+
constructor(e, t, n, r, i = {}) {
|
|
124
|
+
if (this.parent = e, this.callback = null, !t || typeof t != "object" || typeof n != "string") throw Error("[GUI] list() invalid parameters.");
|
|
125
|
+
let a = typeof i.label == "string" ? i.label : n, o = Array.isArray(r) ? r : null;
|
|
126
|
+
if (!o) throw Error("[GUI] list() Third argument must be an array.");
|
|
127
|
+
let s = o && o.length > 0 && typeof o[0] == "object", c = typeof i.tooltip == "string" ? i.tooltip : i.tooltip === !0 ? a : null, l = (() => {
|
|
128
|
+
if (!o) return null;
|
|
129
|
+
if (typeof t[n] == "string") return s ? o.find((e) => e.value === t[n])?.value : o.indexOf(t[n]);
|
|
130
|
+
if (typeof t[n] == "number") return s ? o.find((e) => e.value === t[n])?.value : t[n];
|
|
131
|
+
})(), u = this.parent.propReferences.push(t[n]) - 1, d = document.createElement("div");
|
|
132
|
+
d.className = "p-gui__list", d.textContent = a, c && d.setAttribute("title", c), this.parent.wrapper.append(d), this.element = d;
|
|
133
|
+
let f = document.createElement("select");
|
|
134
|
+
d.append(f), f.className = "p-gui__list-dropdown", f.addEventListener("change", (e) => {
|
|
135
|
+
t[n] = e.target.value, this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
136
|
+
}), o && o.forEach((e, t) => {
|
|
137
|
+
let n = s ? e.label : e, r = s ? e.value : e, i = document.createElement("option");
|
|
138
|
+
i.setAttribute("value", String(r)), i.textContent = String(n), f.append(i), (!s && l == t || s && l == r) && i.setAttribute("selected", "");
|
|
139
|
+
}), Object.defineProperty(t, n, {
|
|
140
|
+
set: (e) => {
|
|
141
|
+
let t, n, r;
|
|
142
|
+
if (s) {
|
|
143
|
+
if (r = o?.find((t) => t.value == e), !r) {
|
|
144
|
+
console.error(`[GUI] list() value ${e} not found in values`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
n = r?.value || o[0].value, t = o.indexOf(r);
|
|
148
|
+
} else typeof e == "string" && (t = o.indexOf(e), n = e), typeof e == "number" && (t = e, n = o[e]);
|
|
149
|
+
if (t === void 0 || n === void 0) {
|
|
150
|
+
console.error("[GUI] list() newIndex or newValue is undefined");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.parent.propReferences[u] = s ? n : e;
|
|
154
|
+
let i = f.querySelector("[selected]");
|
|
155
|
+
i && i.removeAttribute("selected"), f.querySelectorAll("option")[t].setAttribute("selected", ""), typeof this.callback == "function" && (s && r ? this.callback(r, t) : this.callback(n, t));
|
|
156
|
+
},
|
|
157
|
+
get: () => this.parent.propReferences[u]
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
onChange(e) {
|
|
161
|
+
return this.callback = e, this;
|
|
162
|
+
}
|
|
163
|
+
}, a = class {
|
|
164
|
+
constructor(e, t, n, r = {}) {
|
|
165
|
+
if (this.callback = null, this.parent = e, typeof t != "object" || typeof n != "string") throw Error("[GUI] color() invalid parameters. Expected (object, string, options).");
|
|
166
|
+
let i = typeof r.label == "string" && r.label || "\xA0";
|
|
167
|
+
i === "\xA0" && (i = n);
|
|
168
|
+
let a = typeof r.tooltip == "string" ? r.tooltip : r.tooltip === !0 ? i : null, o = this.parent.propReferences.push(t[n]) - 1, s = t[n] || "#000000", c = document.createElement("div");
|
|
169
|
+
c.className = "p-gui__color", c.textContent = i, a && c.setAttribute("title", a), this.parent.wrapper.append(c), this.element = c;
|
|
170
|
+
let l = document.createElement("input");
|
|
171
|
+
l.className = "p-gui__color-picker", l.setAttribute("type", "color"), l.value = s, c.append(l), l.addEventListener("input", () => {
|
|
172
|
+
t[n] = l.value, this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
173
|
+
}), Object.defineProperty(t, n, {
|
|
174
|
+
set: (e) => {
|
|
175
|
+
this.parent.propReferences[o] = e, l.value = e, typeof this.callback == "function" && this.callback(e);
|
|
176
|
+
},
|
|
177
|
+
get: () => this.parent.propReferences[o]
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
onChange(e) {
|
|
181
|
+
return this.callback = e, this;
|
|
182
|
+
}
|
|
183
|
+
}, o = class {
|
|
184
|
+
constructor(e, t, n, r, i = {}) {
|
|
185
|
+
this.parent = e, this.callback = null;
|
|
186
|
+
let a, o;
|
|
187
|
+
if (t && typeof t == "object" && typeof n == "string" && typeof r == "string") a = t, o = t, n = n, r = r;
|
|
188
|
+
else throw Error("[GUI] vector2() invalid parameters. Use: gui.vector2(obj, 'propX', 'propY', options)");
|
|
189
|
+
let s = typeof i.label == "string" && i.label || "\xA0";
|
|
190
|
+
s === "\xA0" && (s = n + " / " + r);
|
|
191
|
+
let c = i.x || {}, l = i.y || {}, u = c.min ?? i.min ?? 0, d = c.max ?? i.max ?? 1, f = l.min ?? i.min ?? 0, p = l.max ?? i.max ?? 1, m = c.step || i.step || (d - u) / 100, h = l.step || i.step || (p - f) / 100, g = this.parent._countDecimals(m), _ = this.parent._countDecimals(h), v = this.parent.propReferences.push(a[n]) - 1, y = this.parent.propReferences.push(o[r]) - 1, b = typeof i.tooltip == "string" ? i.tooltip : i.tooltip === !0 ? s : null, x = document.createElement("div");
|
|
192
|
+
x.className = "p-gui__vector2", x.textContent = s, b && x.setAttribute("title", b), this.parent.wrapper.append(x);
|
|
193
|
+
let S = document.createElement("div");
|
|
194
|
+
S.className = "p-gui__vector-value", S.textContent = a[n] + ", " + o[r], x.append(S);
|
|
195
|
+
let C = document.createElement("div");
|
|
196
|
+
C.className = "p-gui__vector2-area", x.append(C), C.addEventListener("click", (e) => {
|
|
197
|
+
let t = parseFloat(this.parent._mapLinear(e.offsetX, 0, C.clientWidth, u, d)), i = parseFloat(this.parent._mapLinear(e.offsetY, 0, C.clientHeight, p, f));
|
|
198
|
+
a[n] = t.toFixed(g), o[r] = i.toFixed(_), this.callback && this.callback(a[n], a[r]), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
199
|
+
});
|
|
200
|
+
let w = (e) => {
|
|
201
|
+
let t = C.getBoundingClientRect(), i = e.clientX - t.left, s = e.clientY - t.top, c = this.parent._mapLinear(i, 0, C.clientWidth, u, d), l = this.parent._mapLinear(s, 0, C.clientHeight, p, f), m = Math.max(u, Math.min(d, c)), h = Math.max(f, Math.min(p, l));
|
|
202
|
+
a[n] = parseFloat(m.toFixed(g)), o[r] = parseFloat(h.toFixed(_)), this.callback && this.callback(a[n], o[r]), this.parent.onUpdate ? this.parent.onUpdate() : this.parent.isFolder && this.parent.firstParent.onUpdate && this.parent.firstParent.onUpdate();
|
|
203
|
+
};
|
|
204
|
+
C.addEventListener("pointerdown", (e) => {
|
|
205
|
+
w(e), document.addEventListener("pointermove", w), document.addEventListener("pointerup", () => {
|
|
206
|
+
document.removeEventListener("pointermove", w);
|
|
207
|
+
}, { once: !0 });
|
|
208
|
+
});
|
|
209
|
+
let T = document.createElement("div");
|
|
210
|
+
T.className = "p-gui__vector2-line p-gui__vector2-line-x", C.append(T);
|
|
211
|
+
let E = document.createElement("div");
|
|
212
|
+
E.className = "p-gui__vector2-line p-gui__vector2-line-y", C.append(E);
|
|
213
|
+
let D = document.createElement("div");
|
|
214
|
+
D.className = "p-gui__vector2-dot", C.append(D);
|
|
215
|
+
let O = () => {
|
|
216
|
+
D.style.left = this.parent._mapLinear(a[n], u, d, 0, C.clientWidth) + "px", D.style.top = this.parent._mapLinear(o[r], f, p, C.clientHeight, 0) + "px";
|
|
217
|
+
};
|
|
218
|
+
O(), new ResizeObserver(() => {
|
|
219
|
+
O();
|
|
220
|
+
}).observe(C), Object.defineProperty(a, n, {
|
|
221
|
+
set: (e) => {
|
|
222
|
+
this.parent.propReferences[v] = e, O(), S.textContent = String(e) + ", " + o[r];
|
|
223
|
+
},
|
|
224
|
+
get: () => this.parent.propReferences[v]
|
|
225
|
+
}), Object.defineProperty(o, r, {
|
|
226
|
+
set: (e) => {
|
|
227
|
+
this.parent.propReferences[y] = e, O(), S.textContent = a[n] + ", " + String(e);
|
|
228
|
+
},
|
|
229
|
+
get: () => this.parent.propReferences[y]
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
onChange(e) {
|
|
233
|
+
return this.callback = e, this;
|
|
234
|
+
}
|
|
235
|
+
}, s = ".p-gui__button{background:var(--color-accent);text-align:center;color:var(--color-bg);box-sizing:border-box;transition:var(--transition) background, var(--transition) border-color;border:1px solid #0000}.p-gui__button:hover{background:var(--color-accent-hover);border-color:#fff3}.p-gui__folder .p-gui__button{margin-inline:0}", c = ".p-gui__slider{min-height:14px;color:var(--color-text-dark);transition:color var(--transition);touch-action:none;justify-content:space-between;align-items:center;gap:10px;padding:3px;display:flex;position:relative}.p-gui__slider:hover{color:var(--color-text-light)}.p-gui__slider-name{text-overflow:ellipsis;width:50%;overflow:hidden}.p-gui__slider-ctrl{-webkit-appearance:none;font:inherit;box-sizing:border-box;cursor:pointer;touch-action:none;outline:none;width:37%;height:14px;margin:0 0 0 auto;padding:0;position:relative;right:0}.p-gui__slider-bar{background:#fff3;width:100%;height:2px;position:absolute;top:50%;left:0;transform:translateY(-50%)}.p-gui__slider-filling{background:var(--color-accent);pointer-events:none;width:0;height:100%;position:absolute;top:-25%;left:0}.p-gui__slider:hover .p-gui__slider-filling{background:var(--color-accent-hover)}.p-gui__slider-handle{pointer-events:none;background:var(--color-text-dark);border-radius:2px;width:9px;height:9px;position:absolute;top:50%;left:0;transform:translate(-50%,-50%);box-shadow:0 0 2px #00000080}.p-gui__slider:hover .p-gui__slider-handle{background:var(--color-text-light)}.p-gui__slider-value{color:inherit;width:13%;background:#ffffff1a;border:none;border-radius:2px;padding:2px 4px;display:inline-block;right:7px}.p-gui__slider-value:focus{outline:none}", l = ".p-gui__list{cursor:default;color:var(--color-text-dark);transition:var(--transition) color}.p-gui__list:hover{color:var(--color-text-light)}.p-gui__list-dropdown{color:#fff;background:#ffffff0d;padding:0 12px 0 5px;top:0}.p-gui__list-dropdown{cursor:pointer;border:1px solid var(--color-border-2);border-radius:3px;outline:none;height:calc(100% - 4px);margin:auto;position:absolute;top:0;bottom:0;right:5px}.p-gui__list-dropdown option{color:#000;background:#fff}.p-gui__list-dropdown:hover{background:#ffffff1a}", u = ".p-gui__toggle{color:var(--color-text-dark);transition:var(--transition) background, var(--transition) color}.p-gui__toggle:hover{color:var(--color-text-light);background:#ffffff1a}.p-gui__folder .p-gui__toggle{margin-inline:0}.p-gui__toggle-checkbox{pointer-events:none;background-color:#ffffff1a;border-radius:2px;width:10px;height:10px;margin:auto;transition:all .5s;position:absolute;top:0;bottom:0;right:10px}.p-gui__toggle-checkbox--active{background-color:#ddd;box-shadow:0 0 5px #ddd}", d = ".p-gui__color{cursor:default;color:var(--color-text-dark);transition:var(--transition) color}.p-gui__color:hover{color:var(--color-text-light)}.p-gui__color-picker{cursor:pointer;border:1px solid var(--color-border-2);-webkit-appearance:none;background-color:#0000;border:1px solid #222;border-radius:3px;outline:none;height:calc(100% - 4px);margin:auto;padding:0;position:absolute;top:0;bottom:0;right:5px;overflow:hidden}.p-gui__color-picker::-webkit-color-swatch-wrapper{padding:0}.p-gui__color-picker::-webkit-color-swatch{border:none}", f = ".p-gui__vector2{aspect-ratio:1;color:var(--color-text-dark);background:0 0;padding-bottom:0}.p-gui__vector2:hover{color:var(--color-text-light)}.p-gui__vector2-area{touch-action:none;background:#0000004d;width:100%;height:calc(100% - 28px);margin-top:8px;position:relative}.p-gui__vector2-line{opacity:.3;pointer-events:none;background:#fff;position:absolute}.p-gui__vector2-line-x{width:100%;height:1px;top:50%;left:0;transform:translateY(-50%)}.p-gui__vector2-line-y{width:1px;height:100%;top:0;left:50%;transform:translate(-50%)}.p-gui__vector2-dot{pointer-events:none;background:#d5d5d5;border:2px solid #f99;border-radius:50%;width:8px;height:8px;position:absolute;top:0;left:0;transform:translate(-50%,-50%)}.p-gui__vector-value{display:inline-block;position:absolute;right:7px}", p = ".p-gui__image-container{box-sizing:border-box;flex-wrap:wrap;justify-content:flex-start;width:100%;padding:3px;display:flex}.p-gui__image{cursor:pointer;border-radius:var(--main-border-radius);height:90px;color:var(--color-text-dark);transition:var(--transition) color;background-position:50%;background-size:cover;flex:0 0 calc(33.333% - 5px);margin:1px 2.5px 19px;position:relative}.p-gui__image:hover{color:var(--color-text-light)}.p-gui__image:after{content:\"\";box-sizing:border-box;border-radius:var(--main-border-radius);width:100%;height:100%;transition:var(--transition) border-color;border:1px solid #0000;position:absolute;top:0;left:0}.p-gui__image--selected:after{border-color:#06ff89}.p-gui__image-text{text-shadow:0 -1px #111;white-space:nowrap;text-overflow:ellipsis;width:100%;position:absolute;bottom:-15px;overflow:hidden}", m = ".p-gui__folder{background:var(--color-bg);border:1px solid var(--color-border-2);border-radius:var(--main-border-radius);box-sizing:border-box;border-left:1px solid #bbb;flex-wrap:wrap;width:100%;margin-bottom:2px;display:flex;position:relative}.p-gui__folder--first{margin-top:0}.p-gui__folder-content{grid-template-rows:1fr;width:100%;transition:grid-template-rows .25s;display:grid}.p-gui__folder-inner{padding-left:3px;padding-right:2px;overflow:hidden}.p-gui__folder--closed .p-gui__folder-content{grid-template-rows:0fr}.p-gui__folder-header{color:#fff;cursor:pointer;box-sizing:border-box;border-top-right-radius:var(--main-border-radius);border-bottom-right-radius:var(--main-border-radius);background-color:#00000080;width:100%;padding:5px 3px}.p-gui__folder-header:hover{background-color:#000000bf}.p-gui__folder-arrow{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAHlBMVEUAAAD///////////////////////////////////8kfJuVAAAACXRSTlMA9Z1fCdMo1yxEJnA0AAAAK0lEQVQI12PABlRgjKkJUMZMYRhjpgqMAZSEMICSaIzpDWiKhdENhEhgAgATSg5jyWnYewAAAABJRU5ErkJggg==);background-size:contain;width:8px;height:8px;margin-right:5px;display:inline-block;transform:rotate(90deg)}.p-gui__folder--closed .p-gui__folder-arrow{transform:rotate(0)}", h = ".p-gui__tabs{background:var(--color-bg);border:1px solid var(--color-border-2);border-radius:var(--main-border-radius);box-sizing:border-box;border-left:1px solid #bbb;width:100%;margin-bottom:2px;padding-block:0;position:relative}.p-gui__tabs--first{margin-top:0}.p-gui__tabs-header{border-top-left-radius:var(--main-border-radius);border-top-right-radius:var(--main-border-radius);background-color:#00000080;display:flex}.p-gui__tab-button{color:#bbb;cursor:pointer;white-space:nowrap;text-overflow:ellipsis;background:0 0;border:none;flex:1;padding:7px 10px;font-family:inherit;overflow:hidden}.p-gui__tab-button:last-child{border-right:none}.p-gui__tab-button:hover{color:#fff}.p-gui__tab-button--active{background-color:var(--color-bg);color:#fff;border-bottom:1px solid #0000}.p-gui__tabs-content{width:100%;position:relative}.p-gui__tab-pane{box-sizing:border-box;width:100%;padding-top:4px;display:none}.p-gui__tab-pane--active{display:block}";
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/styles/styles.js
|
|
238
|
+
function g(e) {
|
|
239
|
+
return `
|
|
373
240
|
.p-gui {
|
|
374
241
|
--main-border-radius: 6px;
|
|
375
242
|
--color-bg: #161616;
|
|
@@ -381,7 +248,7 @@ function oe(k) {
|
|
|
381
248
|
--color-accent-hover: #dddddd;
|
|
382
249
|
--transition: .1s linear;
|
|
383
250
|
|
|
384
|
-
position: ${
|
|
251
|
+
position: ${e};
|
|
385
252
|
top: 0;
|
|
386
253
|
left: 0;
|
|
387
254
|
transform: translate3d(0,0,0);
|
|
@@ -517,49 +384,70 @@ function oe(k) {
|
|
|
517
384
|
border-color: rgba(255,255,255,.2);
|
|
518
385
|
}
|
|
519
386
|
|
|
520
|
-
${
|
|
387
|
+
${s}
|
|
521
388
|
|
|
522
|
-
${
|
|
389
|
+
${p}
|
|
523
390
|
|
|
524
|
-
${
|
|
391
|
+
${l}
|
|
525
392
|
|
|
526
|
-
${
|
|
393
|
+
${u}
|
|
527
394
|
|
|
528
|
-
${
|
|
395
|
+
${c}
|
|
529
396
|
|
|
530
|
-
${
|
|
397
|
+
${d}
|
|
531
398
|
|
|
532
|
-
${
|
|
399
|
+
${f}
|
|
533
400
|
|
|
534
|
-
${
|
|
401
|
+
${m}
|
|
535
402
|
|
|
536
|
-
${
|
|
403
|
+
${h}
|
|
537
404
|
`;
|
|
538
405
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/index.ts
|
|
408
|
+
var _ = class s {
|
|
409
|
+
constructor(e = {}, t = !1) {
|
|
410
|
+
if (this.container = document.body, this.label = "", this.backgroundColor = null, this.opacity = 1, this.maxHeight = window.innerHeight, this.initMaxHeight = null, this.instanceId = 0, this.wrapperWidth = 290, this.stylesheet = null, this.closed = !1, this.domElement = null, this.hasBeenDragged = !1, this.xOffset = 0, this.yOffset = 0, this.position = {
|
|
411
|
+
initX: 0,
|
|
412
|
+
initY: 0,
|
|
413
|
+
prevX: 0,
|
|
414
|
+
prevY: 0,
|
|
415
|
+
x: 0,
|
|
416
|
+
y: 0
|
|
417
|
+
}, this.isFolder = !1, this.parent = null, this.imageContainer = null, this.previousInnerScroll = 0, this.onUpdate = null, this._onPointerDown = (e) => {
|
|
418
|
+
e.preventDefault(), this.position.initX = this.position.x, this.position.initY = this.position.y, this.position.prevX = e.clientX, this.position.prevY = e.clientY, this.container.addEventListener("pointermove", this._onPointerMove), document.addEventListener("pointerup", this._onPointerUp);
|
|
419
|
+
}, this._onPointerMove = (e) => {
|
|
420
|
+
e.preventDefault(), this.hasBeenDragged || (this.hasBeenDragged = !0, this.domElement?.setAttribute("data-dragged", "true")), this.position.x = this.position.initX + e.clientX - this.position.prevX, this.position.y = this.position.initY + e.clientY - this.position.prevY, this.domElement && (this.domElement.style.transform = `translate3d(${this.position.x}px, ${this.position.y}px, 0)`);
|
|
421
|
+
}, this._onPointerUp = () => {
|
|
422
|
+
this.container.removeEventListener("pointermove", this._onPointerMove), document.removeEventListener("pointerup", this._onPointerUp);
|
|
423
|
+
}, this.firstParent = this, this.folders = [], this.tabsArray = [], this.propReferences = [], e.isFolder) {
|
|
424
|
+
this._folderConstructor(e.folderOptions);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if (t) return;
|
|
428
|
+
let n = "fixed";
|
|
429
|
+
if (e.container) {
|
|
430
|
+
let t = typeof e.container == "string" ? document.querySelector(e.container) : e.container;
|
|
431
|
+
t instanceof HTMLElement && (this.container = t, n = "absolute");
|
|
432
|
+
}
|
|
433
|
+
this.screenCorner = this._parseScreenCorner(e.position), e.width && (this.wrapperWidth = e.width), typeof e.onUpdate == "function" && (this.onUpdate = e.onUpdate), this.label = typeof e.label == "string" ? e.label : "", this.backgroundColor = e.color || null, this.opacity = e.opacity || 1, this.container && this.container !== document.body && (this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight)), e.maxHeight && (this.initMaxHeight = e.maxHeight, this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight)), window.perfectGUI || (window.perfectGUI = {}), window.perfectGUI.instanceCounter == null ? window.perfectGUI.instanceCounter = 0 : window.perfectGUI.instanceCounter++, this.instanceId = window.perfectGUI.instanceCounter, 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(`${g(n)}`), this._styleInstance(), this.closed = !!e.closed;
|
|
434
|
+
let [r, i] = this._addWrapper();
|
|
435
|
+
this.domElement = r, this.wrapper = i, this.domElement.setAttribute("data-corner-x", this.screenCorner.x), this.domElement.setAttribute("data-corner-y", this.screenCorner.y), e.autoRepositioning != 0 && window.addEventListener("resize", this._handleResize.bind(this)), this._handleResize(), e.draggable == 1 && this._makeDraggable();
|
|
436
|
+
}
|
|
437
|
+
_styleInstance() {
|
|
438
|
+
let e = this._getScrollbarWidth(this.container);
|
|
439
|
+
if (this.screenCorner.x == "left" ? this.xOffset = 0 : this.xOffset = this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
|
|
440
|
+
let e = this.container.querySelectorAll(".p-gui");
|
|
441
|
+
for (let t = 0; t < e.length; t++) this.screenCorner.y == e[t].dataset.cornerY && (this.screenCorner.x == "left" && e[t].dataset.cornerX == "left" ? this.xOffset += e[t].offsetWidth : this.screenCorner.x == "right" && e[t].dataset.cornerX == "right" && (this.xOffset -= e[t].offsetWidth));
|
|
442
|
+
}
|
|
443
|
+
this.yOffset = 0, this.position = {
|
|
444
|
+
initX: this.xOffset,
|
|
445
|
+
initY: this.yOffset,
|
|
446
|
+
prevX: this.xOffset,
|
|
447
|
+
prevY: this.yOffset,
|
|
448
|
+
x: this.xOffset,
|
|
449
|
+
y: this.yOffset
|
|
450
|
+
}, this._addStyles(`#p-gui-${this.instanceId} {
|
|
563
451
|
width: ${this.wrapperWidth}px;
|
|
564
452
|
max-height: ${this.maxHeight}px;
|
|
565
453
|
transform: translate3d(${this.xOffset}px,${this.yOffset}px,0);
|
|
@@ -567,183 +455,164 @@ class C {
|
|
|
567
455
|
${this.backgroundColor ? "background: " + this.backgroundColor + ";" : ""}
|
|
568
456
|
opacity: ${this.opacity};
|
|
569
457
|
}`);
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
toggleClose() {
|
|
730
|
-
this.closed = !this.closed, this.closed ? (this.previousInnerScroll = this.wrapper.scrollTop, this.wrapper.scrollTo(0, 0)) : this.wrapper.scrollTo(0, this.previousInnerScroll), this.domElement.classList.toggle("p-gui--collapsed");
|
|
731
|
-
}
|
|
732
|
-
kill() {
|
|
733
|
-
this.domElement.remove();
|
|
734
|
-
}
|
|
735
|
-
_mapLinear(t, e, r, d, i) {
|
|
736
|
-
return d + (t - e) * (i - d) / (r - e);
|
|
737
|
-
}
|
|
738
|
-
_countDecimals(t) {
|
|
739
|
-
const e = t.toString(), r = e.indexOf(".");
|
|
740
|
-
return r === -1 ? 0 : e.length - r - 1;
|
|
741
|
-
}
|
|
742
|
-
static registerPlugin(t) {
|
|
743
|
-
for (let e in t)
|
|
744
|
-
C.prototype[e] = t[e];
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
export {
|
|
748
|
-
C as default
|
|
458
|
+
}
|
|
459
|
+
_folderConstructor(e) {
|
|
460
|
+
if (!e) throw Error("[perfect-gui] folderOptions is undefined");
|
|
461
|
+
this.domElement = e.container, this.isFolder = !0, this.parent = e.parent, this.firstParent = e.firstParent, this.wrapper = e.wrapper;
|
|
462
|
+
}
|
|
463
|
+
_parseScreenCorner(e) {
|
|
464
|
+
let t = {
|
|
465
|
+
x: "right",
|
|
466
|
+
y: "top"
|
|
467
|
+
};
|
|
468
|
+
return e == null ? t : (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);
|
|
469
|
+
}
|
|
470
|
+
_getScrollbarWidth(e) {
|
|
471
|
+
return e === document.body ? window.innerWidth - document.documentElement.clientWidth : e.offsetWidth - e.clientWidth;
|
|
472
|
+
}
|
|
473
|
+
_handleResize() {
|
|
474
|
+
if (!this.domElement || (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;
|
|
475
|
+
let e = this._getScrollbarWidth(this.container);
|
|
476
|
+
if (this.xOffset = this.screenCorner.x == "left" ? 0 : this.container.clientWidth - this.wrapperWidth - e, this.instanceId > 0) {
|
|
477
|
+
let e = this.container.querySelectorAll(`.p-gui:not(#${this.domElement.id}):not([data-dragged])`);
|
|
478
|
+
for (let t = 0; t < e.length && !(parseInt(e[t].id.replace("p-gui-", "")) > this.instanceId); t++) this.screenCorner.y == e[t].dataset.cornerY && (this.screenCorner.x == "left" && e[t].dataset.cornerX == "left" ? this.xOffset += e[t].offsetWidth : this.screenCorner.x == "right" && e[t].dataset.cornerX == "right" && (this.xOffset -= e[t].offsetWidth));
|
|
479
|
+
}
|
|
480
|
+
this.position = {
|
|
481
|
+
initX: this.xOffset,
|
|
482
|
+
initY: this.yOffset,
|
|
483
|
+
prevX: this.xOffset,
|
|
484
|
+
prevY: this.yOffset,
|
|
485
|
+
x: this.xOffset,
|
|
486
|
+
y: this.yOffset
|
|
487
|
+
}, this.domElement.style.transform = `translate3d(${this.position.x}px, ${this.position.y}px, 0)`;
|
|
488
|
+
}
|
|
489
|
+
_addStyles(e) {
|
|
490
|
+
this.stylesheet && (this.stylesheet.innerHTML += e);
|
|
491
|
+
}
|
|
492
|
+
_addWrapper() {
|
|
493
|
+
let e = document.createElement("div");
|
|
494
|
+
e.id = "p-gui-" + this.instanceId, e.className = "p-gui" + (this.closed ? " p-gui--collapsed" : ""), e.setAttribute("data-lenis-prevent", ""), this.container.append(e), 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 + ";" : ""}`, e.append(this.header);
|
|
495
|
+
let t = document.createElement("div");
|
|
496
|
+
t.className = "p-gui__header-close", t.addEventListener("click", this.toggleClose.bind(this)), this.header.append(t);
|
|
497
|
+
let n = document.createElement("div");
|
|
498
|
+
n.className = "p-gui__content", e.append(n);
|
|
499
|
+
let r = document.createElement("div");
|
|
500
|
+
return r.className = "p-gui__inner", n.append(r), [e, r];
|
|
501
|
+
}
|
|
502
|
+
button(t = {}) {
|
|
503
|
+
return this.imageContainer = null, new e(this, t);
|
|
504
|
+
}
|
|
505
|
+
image(e, t = {}) {
|
|
506
|
+
return this.imageContainer || (this.imageContainer = document.createElement("div"), this.imageContainer.className = "p-gui__image-container", this.wrapper.append(this.imageContainer)), new n(this, e, t);
|
|
507
|
+
}
|
|
508
|
+
slider(e, n, r) {
|
|
509
|
+
return this.imageContainer = null, new t(this, e, n, r);
|
|
510
|
+
}
|
|
511
|
+
toggle(e, t, n) {
|
|
512
|
+
return this.imageContainer = null, new r(this, e, t, n);
|
|
513
|
+
}
|
|
514
|
+
list(e, t, n, r) {
|
|
515
|
+
return this.imageContainer = null, new i(this, e, t, n, r);
|
|
516
|
+
}
|
|
517
|
+
color(e, t, n) {
|
|
518
|
+
return this.imageContainer = null, new a(this, e, t, n);
|
|
519
|
+
}
|
|
520
|
+
vector2(e, t, n, r) {
|
|
521
|
+
return this.imageContainer = null, new o(this, e, t, n, r);
|
|
522
|
+
}
|
|
523
|
+
folder(e) {
|
|
524
|
+
let t = typeof e.closed == "boolean" ? e.closed : !1, n = e.label || "", r = e.color || null, i = e.maxHeight || null;
|
|
525
|
+
this.imageContainer = null;
|
|
526
|
+
let a = "p-gui__folder";
|
|
527
|
+
this.folders.length == 0 && (a += " p-gui__folder--first"), t && (a += " p-gui__folder--closed");
|
|
528
|
+
let o = r ? `background-color: ${r};` : "";
|
|
529
|
+
o += i ? `max-height: ${i}px; overflow-y: auto;` : "";
|
|
530
|
+
let s = document.createElement("div");
|
|
531
|
+
s.className = a, s.style = o, this.wrapper.append(s);
|
|
532
|
+
let c = document.createElement("div");
|
|
533
|
+
c.innerHTML = `<span class="p-gui__folder-arrow"></span>${n}`, c.className = "p-gui__folder-header", s.append(c);
|
|
534
|
+
let l = document.createElement("div");
|
|
535
|
+
l.className = "p-gui__folder-content", s.append(l);
|
|
536
|
+
let u = document.createElement("div");
|
|
537
|
+
u.className = "p-gui__folder-inner", l.append(u), c.addEventListener("click", () => {
|
|
538
|
+
s.classList.toggle("p-gui__folder--closed");
|
|
539
|
+
});
|
|
540
|
+
let d = new v({
|
|
541
|
+
container: s,
|
|
542
|
+
wrapper: u,
|
|
543
|
+
parent: this,
|
|
544
|
+
firstParent: this.firstParent
|
|
545
|
+
});
|
|
546
|
+
return this.folders.push(d), d;
|
|
547
|
+
}
|
|
548
|
+
tabs(e = {}) {
|
|
549
|
+
let t = Array.isArray(e.tabs) ? e.tabs : [], n = e.active || 0, r = e.color || null, i = e.maxHeight || null;
|
|
550
|
+
this.imageContainer = null;
|
|
551
|
+
let a = "p-gui__tabs";
|
|
552
|
+
this.tabsArray.length == 0 && (a += " p-gui__tabs--first");
|
|
553
|
+
let o = r ? `background-color: ${r};` : "";
|
|
554
|
+
o += i ? `max-height: ${i}px; overflow-y: auto;` : "";
|
|
555
|
+
let s = document.createElement("div");
|
|
556
|
+
s.className = a, s.style = o, this.wrapper.append(s);
|
|
557
|
+
let c = document.createElement("div");
|
|
558
|
+
c.className = "p-gui__tabs-header", s.append(c);
|
|
559
|
+
let l = document.createElement("div");
|
|
560
|
+
l.className = "p-gui__tabs-content", s.append(l);
|
|
561
|
+
let u = [];
|
|
562
|
+
t.forEach((e, t) => {
|
|
563
|
+
let r = typeof e == "string" ? e : e.label || `Tab ${t + 1}`, i = document.createElement("button");
|
|
564
|
+
i.className = "p-gui__tab-button", t === n && (i.className += " p-gui__tab-button--active"), i.textContent = r, c.append(i);
|
|
565
|
+
let a = document.createElement("div");
|
|
566
|
+
a.className = "p-gui__tab-pane", t === n && (a.className += " p-gui__tab-pane--active"), l.append(a);
|
|
567
|
+
let o = new v({
|
|
568
|
+
container: s,
|
|
569
|
+
wrapper: a,
|
|
570
|
+
parent: this,
|
|
571
|
+
firstParent: this.firstParent
|
|
572
|
+
});
|
|
573
|
+
u.push({
|
|
574
|
+
gui: o,
|
|
575
|
+
button: i,
|
|
576
|
+
pane: a
|
|
577
|
+
}), i.addEventListener("click", () => {
|
|
578
|
+
u.forEach((e) => {
|
|
579
|
+
e.button.classList.remove("p-gui__tab-button--active"), e.pane.classList.remove("p-gui__tab-pane--active");
|
|
580
|
+
}), i.classList.add("p-gui__tab-button--active"), a.classList.add("p-gui__tab-pane--active");
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
let d = new v({
|
|
584
|
+
container: s,
|
|
585
|
+
wrapper: u[n]?.pane || document.createElement("div"),
|
|
586
|
+
parent: this,
|
|
587
|
+
firstParent: this.firstParent
|
|
588
|
+
});
|
|
589
|
+
return d.getTab = (e) => u[e]?.gui || null, d.getTabElement = (e) => u[e]?.button || null, d.setActiveTab = (e) => {
|
|
590
|
+
e >= 0 && e < u.length && u[e].button.click();
|
|
591
|
+
}, d.getActiveTab = () => u.findIndex((e) => e.button.classList.contains("p-gui__tab-button--active")), d.element = s, this.tabsArray.push(d), d;
|
|
592
|
+
}
|
|
593
|
+
_makeDraggable() {
|
|
594
|
+
!this.domElement || !this.header || this.header.addEventListener("pointerdown", this._onPointerDown);
|
|
595
|
+
}
|
|
596
|
+
toggleClose() {
|
|
597
|
+
this.domElement && (this.closed = !this.closed, this.closed ? (this.previousInnerScroll = this.wrapper.scrollTop, this.wrapper.scrollTo(0, 0)) : this.wrapper.scrollTo(0, this.previousInnerScroll), this.domElement.classList.toggle("p-gui--collapsed"));
|
|
598
|
+
}
|
|
599
|
+
kill() {
|
|
600
|
+
this.domElement && this.domElement.remove();
|
|
601
|
+
}
|
|
602
|
+
_mapLinear(e, t, n, r, i) {
|
|
603
|
+
return r + (e - t) * (i - r) / (n - t);
|
|
604
|
+
}
|
|
605
|
+
_countDecimals(e) {
|
|
606
|
+
let t = e.toString(), n = t.indexOf(".");
|
|
607
|
+
return n === -1 ? 0 : t.length - n - 1;
|
|
608
|
+
}
|
|
609
|
+
static registerPlugin(e) {
|
|
610
|
+
for (let t in e) s.prototype[t] = e[t];
|
|
611
|
+
}
|
|
612
|
+
}, v = class extends _ {
|
|
613
|
+
constructor(e) {
|
|
614
|
+
super({}, !0), this.isFolder = !0, this.domElement = e.container, this.wrapper = e.wrapper, this.parent = e.parent, this.firstParent = e.firstParent;
|
|
615
|
+
}
|
|
749
616
|
};
|
|
617
|
+
//#endregion
|
|
618
|
+
export { v as Folder, _ as default };
|