@margoengine/ui 0.0.0-stage → 1.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1224 -2
- package/dist/basic.d.ts +87 -0
- package/dist/collections.d.ts +180 -0
- package/dist/color.d.ts +24 -0
- package/dist/controls.d.ts +130 -0
- package/dist/curved.d.ts +41 -0
- package/dist/curved.js +105 -0
- package/dist/dom-CWJhpotq.js +340 -0
- package/dist/dom-host.d.ts +67 -0
- package/dist/dom-host.js +563 -0
- package/dist/dom-spec.d.ts +21 -0
- package/dist/dom.d.ts +63 -0
- package/dist/draw.d.ts +107 -0
- package/dist/editor.d.ts +83 -0
- package/dist/editor.js +323 -0
- package/dist/errors-CDgOgzCd.js +7 -0
- package/dist/focus.d.ts +12 -0
- package/dist/forms.d.ts +114 -0
- package/dist/forms.js +354 -0
- package/dist/gl-bb768Mje.js +165 -0
- package/dist/gl-load-wwKmojhb.js +5 -0
- package/dist/gl-load.d.ts +3 -0
- package/dist/gl.d.ts +30 -0
- package/dist/i18n.d.ts +69 -0
- package/dist/i18n.js +117 -0
- package/dist/image.d.ts +74 -0
- package/dist/image.js +295 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +4 -0
- package/dist/input-dom.d.ts +14 -0
- package/dist/input.d.ts +92 -0
- package/dist/input.js +315 -0
- package/dist/interaction.d.ts +106 -0
- package/dist/keyboard.d.ts +40 -0
- package/dist/keyboard.js +132 -0
- package/dist/layout.d.ts +116 -0
- package/dist/markup.d.ts +89 -0
- package/dist/markup.js +369 -0
- package/dist/meters-yaZRtwsX.js +1401 -0
- package/dist/meters.d.ts +72 -0
- package/dist/mirror.d.ts +30 -0
- package/dist/overlays.d.ts +89 -0
- package/dist/painter.d.ts +115 -0
- package/dist/pass-CAn29pqc.js +15 -0
- package/dist/react.d.ts +99 -0
- package/dist/react.js +246 -0
- package/dist/renderer-Vs-YtiWv.js +1741 -0
- package/dist/renderer.d.ts +138 -0
- package/dist/rsc/react.js +3 -0
- package/dist/shader.d.ts +6 -0
- package/dist/theme.d.ts +104 -0
- package/dist/ui.d.ts +328 -0
- package/dist/virtual.d.ts +81 -0
- package/dist/widget.d.ts +196 -0
- package/dist/world-gl.d.ts +32 -0
- package/dist/world-gl.js +195 -0
- package/dist/world.d.ts +216 -0
- package/dist/world.js +561 -0
- package/package.json +117 -4
|
@@ -0,0 +1,1401 @@
|
|
|
1
|
+
import { n as e, r as t } from "./errors-CDgOgzCd.js";
|
|
2
|
+
import { hexColor as n } from "@margoengine/math/color";
|
|
3
|
+
//#region src/layout.ts
|
|
4
|
+
var r = [
|
|
5
|
+
0,
|
|
6
|
+
0,
|
|
7
|
+
0,
|
|
8
|
+
0
|
|
9
|
+
];
|
|
10
|
+
function i(n) {
|
|
11
|
+
if (n === void 0) return r;
|
|
12
|
+
let i = typeof n == "number" ? [n] : n;
|
|
13
|
+
if (!Array.isArray(i) || ![
|
|
14
|
+
1,
|
|
15
|
+
2,
|
|
16
|
+
4
|
|
17
|
+
].includes(i.length) || i.some((e) => typeof e != "number")) throw t("Edges are a number, [vertical, horizontal] or [top, right, bottom, left]", "ui");
|
|
18
|
+
if (i.some((e) => !Number.isFinite(e) || e < -1e6 || e > 1e6)) throw e("Edges must be finite numbers within 1e6 UI units", "ui");
|
|
19
|
+
return i.length === 1 ? [
|
|
20
|
+
i[0],
|
|
21
|
+
i[0],
|
|
22
|
+
i[0],
|
|
23
|
+
i[0]
|
|
24
|
+
] : i.length === 2 ? [
|
|
25
|
+
i[0],
|
|
26
|
+
i[1],
|
|
27
|
+
i[0],
|
|
28
|
+
i[1]
|
|
29
|
+
] : i;
|
|
30
|
+
}
|
|
31
|
+
function a(n) {
|
|
32
|
+
let r = (n, r) => {
|
|
33
|
+
if (r !== void 0 && r !== "auto" && r !== "fill") {
|
|
34
|
+
if (typeof r == "number") {
|
|
35
|
+
if (!Number.isFinite(r) || r < 0) throw e(`${n} must be finite and not negative`, "ui");
|
|
36
|
+
} else if (!(typeof r == "string" && /^\d+(\.\d+)?%$/.test(r))) throw t(`${n} is a number, 'auto', 'fill' or a percentage such as '50%'`, "ui");
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
r("width", n.width), r("height", n.height);
|
|
40
|
+
for (let t of [
|
|
41
|
+
"minWidth",
|
|
42
|
+
"maxWidth",
|
|
43
|
+
"minHeight",
|
|
44
|
+
"maxHeight",
|
|
45
|
+
"cellWidth",
|
|
46
|
+
"cellHeight"
|
|
47
|
+
]) {
|
|
48
|
+
let r = n[t];
|
|
49
|
+
if (r !== void 0 && (typeof r != "number" || !(r >= 0))) throw e(`${t} must be a number of at least 0`, "ui");
|
|
50
|
+
}
|
|
51
|
+
for (let t of ["grow", "shrink"]) {
|
|
52
|
+
let r = n[t];
|
|
53
|
+
if (r !== void 0 && (typeof r != "number" || !Number.isFinite(r) || r < 0)) throw e(`${t} must be a finite number of at least 0`, "ui");
|
|
54
|
+
}
|
|
55
|
+
if (n.columns !== void 0 && (!Number.isInteger(n.columns) || n.columns < 1)) throw e("columns must be an integer of at least 1", "ui");
|
|
56
|
+
let a = n.gap;
|
|
57
|
+
if (a !== void 0) {
|
|
58
|
+
let t = typeof a == "number" ? [a] : a;
|
|
59
|
+
if (!Array.isArray(t) || t.length > 2 || t.some((e) => !Number.isFinite(e) || e < 0)) throw e("gap is a number of at least 0 or [column gap, row gap]", "ui");
|
|
60
|
+
}
|
|
61
|
+
if (n.wrap !== void 0 && typeof n.wrap != "boolean") throw t("wrap is true or false", "ui");
|
|
62
|
+
if (n.offset !== void 0 && (n.offset.length !== 2 || n.offset.some((e) => !Number.isFinite(e)))) throw e("offset is [x, y] in finite UI units", "ui");
|
|
63
|
+
return i(n.padding), i(n.margin), n;
|
|
64
|
+
}
|
|
65
|
+
var o = (e) => e.style.direction === "row", s = (e) => typeof e == "string" && e.endsWith("%") ? Number.parseFloat(e) / 100 : void 0, c = (e, t) => typeof e == "number" ? e : s(e) !== void 0 && Number.isFinite(t) ? s(e) * t : void 0, l = (e, t, n) => Math.max(t ?? 0, Math.min(n ?? Infinity, e)), u = (e) => typeof e.gap == "number" ? [e.gap, e.gap] : [e.gap?.[0] ?? 0, e.gap?.[1] ?? e.gap?.[0] ?? 0], d = (e) => e.children.filter((t) => t.visible !== !1 && t.style.position !== "absolute" && e.style.direction !== "stack"), f = (e) => e.children.filter((t) => t.visible !== !1 && (t.style.position === "absolute" || e.style.direction === "stack")), p = (e) => e[1] + e[3], m = (e) => e[0] + e[2];
|
|
66
|
+
function h(e, t, n) {
|
|
67
|
+
let r = e.get(t), i = r?.get(n);
|
|
68
|
+
if (i) return i;
|
|
69
|
+
let a = g(e, t, n);
|
|
70
|
+
return r || e.set(t, r = /* @__PURE__ */ new Map()), r.set(n, a), a;
|
|
71
|
+
}
|
|
72
|
+
function g(e, t, n) {
|
|
73
|
+
let r = t.style, a = d(t), s = f(t);
|
|
74
|
+
if (!a.length && !s.length) {
|
|
75
|
+
let e = t.measure?.(n);
|
|
76
|
+
return {
|
|
77
|
+
width: e?.width ?? 0,
|
|
78
|
+
height: e?.height ?? 0
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
let [c, l] = u(r);
|
|
82
|
+
if (r.direction === "stack" || !a.length && s.length) {
|
|
83
|
+
let t = 0, r = 0;
|
|
84
|
+
for (let a of s) {
|
|
85
|
+
let o = i(a.style.margin), s = _(e, a, n - p(o));
|
|
86
|
+
t = Math.max(t, s.width + p(o)), r = Math.max(r, s.height + m(o));
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
width: t,
|
|
90
|
+
height: r
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (r.direction === "grid") {
|
|
94
|
+
let t = r.columns ?? 1, o = a.map((t) => {
|
|
95
|
+
let r = i(t.style.margin), a = _(e, t, n);
|
|
96
|
+
return {
|
|
97
|
+
width: a.width + p(r),
|
|
98
|
+
height: a.height + m(r)
|
|
99
|
+
};
|
|
100
|
+
}), s = r.cellWidth ?? Math.max(0, ...o.map((e) => e.width)), u = r.cellHeight ?? Math.max(0, ...o.map((e) => e.height)), d = Math.ceil(a.length / t);
|
|
101
|
+
return {
|
|
102
|
+
width: t * s + (t - 1) * c,
|
|
103
|
+
height: d * u + Math.max(0, d - 1) * l
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
let h = o(t);
|
|
107
|
+
if (h && r.wrap && Number.isFinite(n)) {
|
|
108
|
+
let r = E(T(e, t, a, n, Infinity), n, c), i = 0, o = 0;
|
|
109
|
+
for (let t of r) i = Math.max(i, O(t, n, c, !0, !1)), o += D(e, t, Infinity);
|
|
110
|
+
return {
|
|
111
|
+
width: i,
|
|
112
|
+
height: o + l * (r.length - 1)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
let g = 0, v = 0;
|
|
116
|
+
for (let t of a) {
|
|
117
|
+
let r = i(t.style.margin), a = _(e, t, n - (h ? 0 : p(r)));
|
|
118
|
+
g += (h ? a.width + p(r) : a.height + m(r)) + (h ? c : l), v = Math.max(v, h ? a.height + m(r) : a.width + p(r));
|
|
119
|
+
}
|
|
120
|
+
return g -= h ? c : l, h ? {
|
|
121
|
+
width: g,
|
|
122
|
+
height: v
|
|
123
|
+
} : {
|
|
124
|
+
width: v,
|
|
125
|
+
height: g
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function _(e, t, n, r) {
|
|
129
|
+
let a = t.style, o = i(a.padding), s = r ?? c(a.width, n), u = s !== void 0, d = h(e, t, Math.max(0, (s ?? n) - p(o)));
|
|
130
|
+
s = l(u ? s : d.width + p(o), a.minWidth, a.maxWidth);
|
|
131
|
+
let f = c(a.height, Infinity);
|
|
132
|
+
return f = l(f ?? d.height + m(o), a.minHeight, a.maxHeight), {
|
|
133
|
+
width: s,
|
|
134
|
+
height: f
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function v(e, t, n) {
|
|
138
|
+
return _(e, t, n, n).height;
|
|
139
|
+
}
|
|
140
|
+
function y(e, t) {
|
|
141
|
+
b(/* @__PURE__ */ new Map(), e, t.x, t.y, t.width, t.height);
|
|
142
|
+
}
|
|
143
|
+
function b(e, t, n, r, a, o) {
|
|
144
|
+
t.rect = {
|
|
145
|
+
x: n,
|
|
146
|
+
y: r,
|
|
147
|
+
width: a,
|
|
148
|
+
height: o
|
|
149
|
+
};
|
|
150
|
+
let s = t.style, c = i(s.padding), l = {
|
|
151
|
+
x: n + c[3],
|
|
152
|
+
y: r + c[0],
|
|
153
|
+
width: Math.max(0, a - p(c)),
|
|
154
|
+
height: Math.max(0, o - m(c))
|
|
155
|
+
};
|
|
156
|
+
t.contentWidth = l.width, t.contentHeight = l.height;
|
|
157
|
+
let u = d(t);
|
|
158
|
+
s.direction === "grid" ? S(e, t, u, l) : u.length && k(e, t, u, l);
|
|
159
|
+
for (let i of f(t)) j(e, t, i, l, {
|
|
160
|
+
x: n,
|
|
161
|
+
y: r,
|
|
162
|
+
width: a,
|
|
163
|
+
height: o
|
|
164
|
+
});
|
|
165
|
+
for (let e of t.children) {
|
|
166
|
+
e.visible === !1 && (e.rect = {
|
|
167
|
+
x: n,
|
|
168
|
+
y: r,
|
|
169
|
+
width: 0,
|
|
170
|
+
height: 0
|
|
171
|
+
});
|
|
172
|
+
let t = e.style.offset;
|
|
173
|
+
t && e.visible !== !1 && x(e, t[0], t[1]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function x(e, t, n) {
|
|
177
|
+
if (t || n) {
|
|
178
|
+
e.rect = {
|
|
179
|
+
...e.rect,
|
|
180
|
+
x: e.rect.x + t,
|
|
181
|
+
y: e.rect.y + n
|
|
182
|
+
};
|
|
183
|
+
for (let r of e.children) x(r, t, n);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function S(e, t, n, r) {
|
|
187
|
+
let a = t.style, [o, s] = u(a), c = a.columns ?? 1, l = n.map((t) => {
|
|
188
|
+
let n = i(t.style.margin), a = _(e, t, r.width);
|
|
189
|
+
return {
|
|
190
|
+
width: a.width + p(n),
|
|
191
|
+
height: a.height + m(n)
|
|
192
|
+
};
|
|
193
|
+
}), d = a.cellWidth ?? Math.max(0, ...l.map((e) => e.width)), f = a.cellHeight ?? Math.max(0, ...l.map((e) => e.height)), h = Math.ceil(n.length / c), g = h * f + Math.max(0, h - 1) * s, v = C(t, g, r.height, "y");
|
|
194
|
+
t.contentHeight = g, n.forEach((t, n) => {
|
|
195
|
+
let a = i(t.style.margin), l = r.x + n % c * (d + o), u = r.y + Math.floor(n / c) * (f + s) - v, h = d - p(a), g = f - m(a);
|
|
196
|
+
b(e, t, l + a[3], u + a[0], Math.max(0, h), Math.max(0, g));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function C(e, t, n, r) {
|
|
200
|
+
if (e.style.overflow !== "scroll") return 0;
|
|
201
|
+
let i = r === "x" ? "scrollX" : "scrollY", a = Math.max(0, t - n), o = Math.max(0, Math.min(a, e[i] ?? 0));
|
|
202
|
+
return e[i] = o, o;
|
|
203
|
+
}
|
|
204
|
+
var w = (e) => e.style.align ?? (o(e) ? "center" : "stretch");
|
|
205
|
+
function T(e, t, n, r, a) {
|
|
206
|
+
let s = o(t), u = w(t);
|
|
207
|
+
return n.map((t) => {
|
|
208
|
+
let n = t.style, o = i(n.margin), d = s ? n.width : n.height, f = s ? p(o) : m(o), h = s ? m(o) : p(o), g, y = c(d, r);
|
|
209
|
+
if (y !== void 0) g = y;
|
|
210
|
+
else if (d === "fill") g = 0;
|
|
211
|
+
else if (s) g = _(e, t, Math.max(0, r - f)).width;
|
|
212
|
+
else {
|
|
213
|
+
let r = n.alignSelf && n.alignSelf !== "auto" ? n.alignSelf : u, i = c(n.width, a) ?? (r === "stretch" || n.width === "fill" ? a - h : void 0);
|
|
214
|
+
g = i === void 0 ? _(e, t, a - h).height : v(e, t, l(i, n.minWidth, n.maxWidth));
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
child: t,
|
|
218
|
+
m: o,
|
|
219
|
+
base: l(g, s ? n.minWidth : n.minHeight, s ? n.maxWidth : n.maxHeight),
|
|
220
|
+
min: (s ? n.minWidth : n.minHeight) ?? 0,
|
|
221
|
+
max: (s ? n.maxWidth : n.maxHeight) ?? Infinity,
|
|
222
|
+
grow: n.grow ?? +(d === "fill"),
|
|
223
|
+
shrink: n.shrink ?? 1,
|
|
224
|
+
size: 0
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function E(e, t, n) {
|
|
229
|
+
let r = [], i = [], a = 0;
|
|
230
|
+
for (let o of e) {
|
|
231
|
+
let e = o.base + p(o.m);
|
|
232
|
+
i.length && a + n + e > t + 1e-9 && (r.push(i), i = [], a = 0), a += (i.length ? n : 0) + e, i.push(o);
|
|
233
|
+
}
|
|
234
|
+
return i.length && r.push(i), r;
|
|
235
|
+
}
|
|
236
|
+
function D(e, t, n) {
|
|
237
|
+
let r = 0;
|
|
238
|
+
for (let i of t) {
|
|
239
|
+
let t = i.child.style, a = c(t.height, n) ?? v(e, i.child, i.size);
|
|
240
|
+
r = Math.max(r, l(a, t.minHeight, t.maxHeight) + m(i.m));
|
|
241
|
+
}
|
|
242
|
+
return r;
|
|
243
|
+
}
|
|
244
|
+
function O(e, t, n, r, i) {
|
|
245
|
+
let a = (e) => r ? p(e.m) : m(e.m), o = e.reduce((e, t) => e + a(t), 0) + n * (e.length - 1), s = e.reduce((e, t) => e + t.base, o), c = i ? Math.max(0, t - s) : t - s, l = c > 0, u = (e) => l ? e.grow : e.shrink;
|
|
246
|
+
for (let t of e) t.size = t.base;
|
|
247
|
+
let d = new Set(e.filter((e) => c === 0 || !(u(e) > 0)));
|
|
248
|
+
for (; d.size < e.length;) {
|
|
249
|
+
let n = e.filter((e) => !d.has(e)), r = t - e.reduce((e, t) => e + (d.has(t) ? t.size : t.base), o), i = n.reduce((e, t) => e + u(t), 0);
|
|
250
|
+
i < 1 && Math.abs(c * i) < Math.abs(r) && (r = c * i);
|
|
251
|
+
let a = (e) => l ? e.grow : e.shrink * e.base, s = n.reduce((e, t) => e + a(t), 0), f = n.map((e) => e.base + (s > 0 ? r * a(e) / s : 0)), p = 0;
|
|
252
|
+
n.forEach((e, t) => {
|
|
253
|
+
e.size = Math.max(e.min, Math.min(e.max, f[t])), p += e.size - f[t];
|
|
254
|
+
}), n.forEach((e, t) => {
|
|
255
|
+
let n = e.size - f[t];
|
|
256
|
+
(Math.abs(p) < 1e-9 || p > 0 && n > 0 || p < 0 && n < 0) && d.add(e);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return e.reduce((e, t) => e + t.size, o);
|
|
260
|
+
}
|
|
261
|
+
function k(e, t, n, r) {
|
|
262
|
+
let i = t.style, a = o(t), [s, c] = u(i), l = a ? s : c, d = a ? r.width : r.height, f = T(e, t, n, d, a ? r.height : r.width);
|
|
263
|
+
if (a && i.wrap) {
|
|
264
|
+
let n = E(f, d, s), i = n.map((e) => O(e, d, s, !0, !1)), a = n.map((t) => D(e, t, r.height)), o = a.reduce((e, t) => e + t, 0) + c * (n.length - 1), l = C(t, o, r.height, "y");
|
|
265
|
+
t.contentHeight = o;
|
|
266
|
+
let u = r.y - l;
|
|
267
|
+
n.forEach((n, o) => {
|
|
268
|
+
A(e, t, n, {
|
|
269
|
+
x: r.x,
|
|
270
|
+
y: u,
|
|
271
|
+
width: r.width,
|
|
272
|
+
height: a[o]
|
|
273
|
+
}, i[o], 0), u += a[o] + c;
|
|
274
|
+
});
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
let p = O(f, d, l, a, i.overflow === "scroll"), m = C(t, p, d, a ? "x" : "y");
|
|
278
|
+
a ? t.contentWidth = p : t.contentHeight = p, A(e, t, f, r, p, m);
|
|
279
|
+
}
|
|
280
|
+
function A(e, t, n, r, i, a) {
|
|
281
|
+
let s = t.style, d = o(t), [f, h] = u(s), g = d ? f : h, y = d ? r.width : r.height, x = d ? r.height : r.width, S = w(t), C = (e) => d ? p(e.m) : m(e.m), T = Math.max(0, y - i), E = 0, D = g, O = n.length;
|
|
282
|
+
switch (s.justify ?? "start") {
|
|
283
|
+
case "center":
|
|
284
|
+
E = T / 2;
|
|
285
|
+
break;
|
|
286
|
+
case "end":
|
|
287
|
+
E = T;
|
|
288
|
+
break;
|
|
289
|
+
case "space-between":
|
|
290
|
+
O > 1 && (D = g + T / (O - 1));
|
|
291
|
+
break;
|
|
292
|
+
case "space-around":
|
|
293
|
+
E = T / O / 2, D = g + T / O;
|
|
294
|
+
break;
|
|
295
|
+
case "space-evenly": E = T / (O + 1), D = g + T / (O + 1);
|
|
296
|
+
}
|
|
297
|
+
let k = E - a;
|
|
298
|
+
for (let t of n) {
|
|
299
|
+
let n = t.child.style, i = n.alignSelf && n.alignSelf !== "auto" ? n.alignSelf : S, a = d ? m(t.m) : p(t.m), o = d ? n.height : n.width, s = d ? n.minHeight : n.minWidth, u = d ? n.maxHeight : n.maxWidth, f = Math.max(0, x - a), h, g = c(o, x);
|
|
300
|
+
h = g === void 0 ? o === "fill" || i === "stretch" ? f : d ? v(e, t.child, t.size) : _(e, t.child, f).width : g, d && g === void 0 && o !== "fill" && i !== "stretch" && (h = v(e, t.child, t.size)), h = l(h, s, u);
|
|
301
|
+
let y = i === "center" ? (f - h) / 2 : i === "end" ? f - h : 0, w = (d ? r.x : r.y) + k + (d ? t.m[3] : t.m[0]), T = (d ? r.y : r.x) + y + (d ? t.m[0] : t.m[3]);
|
|
302
|
+
d ? b(e, t.child, w, T, t.size, h) : b(e, t.child, T, w, h, t.size), k += t.size + C(t) + D;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function j(e, t, n, r, a) {
|
|
306
|
+
let o = n.style, s = i(o.margin), u = o.anchor ?? "stretch", d = o.bleed && t.style.direction === "stack" ? a : r, f = Math.max(0, d.width - p(s)), h = Math.max(0, d.height - m(s)), g = u === "stretch", y = o.width === "fill" || g && (o.width === void 0 || o.width === "auto"), x = o.height === "fill" || g && (o.height === void 0 || o.height === "auto"), S = y ? f : c(o.width, d.width) ?? _(e, n, f).width;
|
|
307
|
+
S = l(S, o.minWidth, o.maxWidth);
|
|
308
|
+
let C = x ? h : c(o.height, d.height);
|
|
309
|
+
C = l(C ?? v(e, n, S), o.minHeight, o.maxHeight);
|
|
310
|
+
let w = u.includes("left"), T = u.includes("right"), E = u.includes("top"), D = u.includes("bottom"), O = w ? 0 : T ? f - S : g ? 0 : (f - S) / 2, k = E ? 0 : D ? h - C : g ? 0 : (h - C) / 2;
|
|
311
|
+
b(e, n, d.x + s[3] + O, d.y + s[0] + k, S, C);
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/widget.ts
|
|
315
|
+
var M = 0, N = class n {
|
|
316
|
+
get opacity() {
|
|
317
|
+
return 1;
|
|
318
|
+
}
|
|
319
|
+
constructor(e = {}) {
|
|
320
|
+
this.children = [], this.parent = null, this.ui = null, this.rect = {
|
|
321
|
+
x: 0,
|
|
322
|
+
y: 0,
|
|
323
|
+
width: 0,
|
|
324
|
+
height: 0
|
|
325
|
+
}, this.scrollX = 0, this.scrollY = 0, this.contentWidth = 0, this.contentHeight = 0, this.role = "generic", this.hovered = !1, this.pressed = !1, this.focused = !1, this.focusVisible = !1, this.focusable = !1, this.levels = {
|
|
326
|
+
hover: 0,
|
|
327
|
+
press: 0,
|
|
328
|
+
focus: 0
|
|
329
|
+
}, this.handlers = /* @__PURE__ */ new Map();
|
|
330
|
+
let { id: n, visible: r, enabled: i, label: o, description: s, tooltip: c, pointerEvents: l, children: u, ...d } = e;
|
|
331
|
+
if (this.id = n ?? `w${++M}`, typeof this.id != "string" || !this.id) throw t("A widget id is a non-empty string", "ui");
|
|
332
|
+
if (this._style = a({ ...d }), this._visible = r ?? !0, this._enabled = i ?? !0, this._label = o, this._description = s, this._tooltip = c, l !== void 0 && l !== "auto" && l !== "none") throw t("pointerEvents is 'auto' or 'none'", "ui");
|
|
333
|
+
this.pointerEvents = l ?? "none", u && this.add(...u);
|
|
334
|
+
}
|
|
335
|
+
get style() {
|
|
336
|
+
return this._style;
|
|
337
|
+
}
|
|
338
|
+
setStyle(e) {
|
|
339
|
+
return this._style = a({
|
|
340
|
+
...this._style,
|
|
341
|
+
...e
|
|
342
|
+
}), this.invalidate(), this;
|
|
343
|
+
}
|
|
344
|
+
setStyleQuiet(e) {
|
|
345
|
+
this._style = {
|
|
346
|
+
...this._style,
|
|
347
|
+
...e
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
get visible() {
|
|
351
|
+
return this._visible;
|
|
352
|
+
}
|
|
353
|
+
set visible(e) {
|
|
354
|
+
e !== this._visible && (this._visible = e, e || this.ui?.widgetHidden(this), this.invalidate());
|
|
355
|
+
}
|
|
356
|
+
get enabled() {
|
|
357
|
+
return this._enabled;
|
|
358
|
+
}
|
|
359
|
+
set enabled(e) {
|
|
360
|
+
e !== this._enabled && (this._enabled = e, e || this.ui?.widgetHidden(this), this.invalidate(!1));
|
|
361
|
+
}
|
|
362
|
+
get label() {
|
|
363
|
+
return this._label ?? this.text ?? "";
|
|
364
|
+
}
|
|
365
|
+
set label(e) {
|
|
366
|
+
this._label = e, this.ui?.touchMirror();
|
|
367
|
+
}
|
|
368
|
+
get description() {
|
|
369
|
+
return this._description;
|
|
370
|
+
}
|
|
371
|
+
set description(e) {
|
|
372
|
+
this._description = e, this.ui?.touchMirror();
|
|
373
|
+
}
|
|
374
|
+
get tooltip() {
|
|
375
|
+
return this._tooltip;
|
|
376
|
+
}
|
|
377
|
+
set tooltip(e) {
|
|
378
|
+
this._tooltip = e;
|
|
379
|
+
}
|
|
380
|
+
get text() {}
|
|
381
|
+
get shown() {
|
|
382
|
+
for (let e = this; e; e = e.parent) if (!e._visible) return !1;
|
|
383
|
+
return !0;
|
|
384
|
+
}
|
|
385
|
+
get active() {
|
|
386
|
+
for (let e = this; e; e = e.parent) if (!e._enabled) return !1;
|
|
387
|
+
return !0;
|
|
388
|
+
}
|
|
389
|
+
add(...e) {
|
|
390
|
+
for (let t of e) this.insert(t, this.children.length);
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
insert(r, i) {
|
|
394
|
+
if (!(r instanceof n)) throw t("Expected a Widget; create one with new Panel() and similar", "ui");
|
|
395
|
+
for (let e = this; e; e = e.parent) if (e === r) throw t("A widget cannot contain itself or its ancestor", "ui");
|
|
396
|
+
if (!Number.isInteger(i)) throw e("index must be an integer", "ui");
|
|
397
|
+
let a = r.parent === this ? this.children.indexOf(r) : -1;
|
|
398
|
+
return r.parent?.detach(r), a >= 0 && a < i && i--, this.children.splice(Math.max(0, Math.min(this.children.length, i)), 0, r), r.parent = this, r.attachTo(this.ui), this.invalidate(), this;
|
|
399
|
+
}
|
|
400
|
+
remove(e) {
|
|
401
|
+
return e.parent === this && this.detach(e), this;
|
|
402
|
+
}
|
|
403
|
+
clear() {
|
|
404
|
+
for (let e of [...this.children]) this.detach(e);
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
removeFromParent() {
|
|
408
|
+
return this.parent?.detach(this), this;
|
|
409
|
+
}
|
|
410
|
+
detach(e) {
|
|
411
|
+
let t = this.children.indexOf(e);
|
|
412
|
+
t < 0 || (this.children.splice(t, 1), e.parent = null, this.ui?.widgetRemoved(e), e.attachTo(null), this.invalidate());
|
|
413
|
+
}
|
|
414
|
+
attachTo(e) {
|
|
415
|
+
if (this.ui !== e) {
|
|
416
|
+
this.ui = e, this.attached(e);
|
|
417
|
+
for (let t of this.children) t.attachTo(e);
|
|
418
|
+
e?.widgetAdded(this);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
attached(e) {}
|
|
422
|
+
find(e) {
|
|
423
|
+
if (this.id === e) return this;
|
|
424
|
+
for (let t of this.children) {
|
|
425
|
+
let n = t.find(e);
|
|
426
|
+
if (n) return n;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
walk(e) {
|
|
430
|
+
e(this);
|
|
431
|
+
for (let t of [...this.children]) t.walk(e);
|
|
432
|
+
}
|
|
433
|
+
on(e, n) {
|
|
434
|
+
if (typeof e != "string" || typeof n != "function") throw t("on(type, handler) takes an event name and a function", "ui");
|
|
435
|
+
let r = this.handlers.get(e);
|
|
436
|
+
r || this.handlers.set(e, r = /* @__PURE__ */ new Set()), r.add(n);
|
|
437
|
+
let i = (() => void r.delete(n));
|
|
438
|
+
return i[Symbol.dispose ?? Symbol.for("Symbol.dispose")] = i, i;
|
|
439
|
+
}
|
|
440
|
+
emit(e, t = {}) {
|
|
441
|
+
let n = this.handlers.get(e);
|
|
442
|
+
if (!n) return;
|
|
443
|
+
let r = {
|
|
444
|
+
...t,
|
|
445
|
+
type: e,
|
|
446
|
+
target: this
|
|
447
|
+
};
|
|
448
|
+
for (let e of [...n]) e(r);
|
|
449
|
+
}
|
|
450
|
+
invalidate(e = !0) {
|
|
451
|
+
this.ui?.invalidate(e);
|
|
452
|
+
}
|
|
453
|
+
measure(e) {
|
|
454
|
+
return {
|
|
455
|
+
width: 0,
|
|
456
|
+
height: 0
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
draw(e) {}
|
|
460
|
+
drawAfter(e) {}
|
|
461
|
+
tick(e) {
|
|
462
|
+
let t = this.ui && this.ui.motion ? e / Math.max(.001, this.ui.theme.transition) : 1, n = (e, n) => {
|
|
463
|
+
let r = this.levels[e];
|
|
464
|
+
return r !== +!!n && (this.levels[e] = n ? Math.min(1, r + t) : Math.max(0, r - t), !0);
|
|
465
|
+
}, r = n("hover", this.hovered && this.active), i = n("press", this.pressed), a = n("focus", this.focusVisible);
|
|
466
|
+
return r || i || a;
|
|
467
|
+
}
|
|
468
|
+
command(e) {
|
|
469
|
+
return !1;
|
|
470
|
+
}
|
|
471
|
+
activate() {}
|
|
472
|
+
pointerDown(e, t) {
|
|
473
|
+
return !1;
|
|
474
|
+
}
|
|
475
|
+
pointerMove(e, t) {}
|
|
476
|
+
pointerUp(e, t) {}
|
|
477
|
+
wheel(e) {
|
|
478
|
+
if (this._style.overflow !== "scroll") return !1;
|
|
479
|
+
let [t, , n] = i(this._style.padding), r = Math.max(0, this.rect.height - t - n), a = this.scrollY;
|
|
480
|
+
return this.scrollY = Math.max(0, Math.min(Math.max(0, this.contentHeight - r), this.scrollY + e)), this.scrollY !== a && this.invalidate(), this.scrollY !== a;
|
|
481
|
+
}
|
|
482
|
+
hitTest(e, t) {
|
|
483
|
+
if (!this._visible) return null;
|
|
484
|
+
let n = this.rect, r = e >= n.x && e < n.x + n.width && t >= n.y && t < n.y + n.height;
|
|
485
|
+
if (this._style.overflow && this._style.overflow !== "visible" && !r) return null;
|
|
486
|
+
for (let n = this.children.length - 1; n >= 0; n--) {
|
|
487
|
+
let r = this.children[n].hitTest(e, t);
|
|
488
|
+
if (r) return r;
|
|
489
|
+
}
|
|
490
|
+
return r && this.pointerEvents === "auto" ? this : null;
|
|
491
|
+
}
|
|
492
|
+
drawFocus({ list: e, theme: t }, n = 3) {
|
|
493
|
+
if (this.levels.focus <= 0) return;
|
|
494
|
+
let r = this.rect, i = this.ui.color("focus"), a = [
|
|
495
|
+
i[0],
|
|
496
|
+
i[1],
|
|
497
|
+
i[2],
|
|
498
|
+
i[3] * this.levels.focus
|
|
499
|
+
];
|
|
500
|
+
e.rect(r.x - n, r.y - n, r.width + 2 * n, r.height + 2 * n, {
|
|
501
|
+
border: a,
|
|
502
|
+
borderWidth: t.focusWidth,
|
|
503
|
+
radius: t.radius + n
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
scrollIntoView() {
|
|
507
|
+
for (let e = this.parent; e; e = e.parent) {
|
|
508
|
+
if (e._style.overflow !== "scroll") continue;
|
|
509
|
+
let t = this.rect, n = e.rect;
|
|
510
|
+
t.y < n.y ? e.scrollY = Math.max(0, e.scrollY - (n.y - t.y) - 4) : t.y + t.height > n.y + n.height && (e.scrollY += t.y + t.height - (n.y + n.height) + 4), e.invalidate();
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
dispose() {
|
|
514
|
+
this.removeFromParent();
|
|
515
|
+
for (let e of [...this.children]) e.dispose();
|
|
516
|
+
this.handlers.clear();
|
|
517
|
+
}
|
|
518
|
+
[Symbol.dispose ?? Symbol.for("Symbol.dispose")]() {
|
|
519
|
+
this.dispose();
|
|
520
|
+
}
|
|
521
|
+
}, P = class extends N {
|
|
522
|
+
constructor(e = {}) {
|
|
523
|
+
let { background: t = "none", border: n = !1, shadow: r = !1, radius: i, ...a } = e;
|
|
524
|
+
super({
|
|
525
|
+
direction: "column",
|
|
526
|
+
...a
|
|
527
|
+
}), this._background = t, this._border = n, this._shadow = r, this._radius = i, this.pointerEvents = e.pointerEvents ?? (t === "none" ? "none" : "auto");
|
|
528
|
+
}
|
|
529
|
+
get background() {
|
|
530
|
+
return this._background;
|
|
531
|
+
}
|
|
532
|
+
set background(e) {
|
|
533
|
+
this._background = e, this.pointerEvents === "none" && e !== "none" && (this.pointerEvents = "auto"), this.invalidate(!1);
|
|
534
|
+
}
|
|
535
|
+
get border() {
|
|
536
|
+
return this._border;
|
|
537
|
+
}
|
|
538
|
+
set border(e) {
|
|
539
|
+
this._border = e, this.invalidate(!1);
|
|
540
|
+
}
|
|
541
|
+
get shadow() {
|
|
542
|
+
return this._shadow;
|
|
543
|
+
}
|
|
544
|
+
set shadow(e) {
|
|
545
|
+
this._shadow = e, this.invalidate(!1);
|
|
546
|
+
}
|
|
547
|
+
draw(e) {
|
|
548
|
+
let { list: t, theme: n, ui: r } = e, i = this.rect, a = this._radius ?? n.radius;
|
|
549
|
+
if (this._background === "none" && !this._border) return;
|
|
550
|
+
this._shadow && n.shadowBlur > 0 && this._background !== "none" && t.rect(i.x, i.y + 4, i.width, i.height, {
|
|
551
|
+
fill: r.color("shadow"),
|
|
552
|
+
radius: a,
|
|
553
|
+
blur: n.shadowBlur / 2
|
|
554
|
+
});
|
|
555
|
+
let o = this._background === "raised" ? "surfaceRaised" : this._background === "sunken" ? "surfaceSunken" : this._background;
|
|
556
|
+
t.rect(i.x, i.y, i.width, i.height, {
|
|
557
|
+
fill: this._background === "none" ? void 0 : r.color(o),
|
|
558
|
+
border: this._border ? r.color("border") : void 0,
|
|
559
|
+
borderWidth: this._border ? n.borderWidth : 0,
|
|
560
|
+
radius: a
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}, F = class extends N {
|
|
564
|
+
constructor(e = {}) {
|
|
565
|
+
let { text: n = "", size: r = "body", color: i = "text", align: a = "start", wrap: o = !0, outline: s = !1, lineHeight: c = 1.25, ...l } = e;
|
|
566
|
+
if (super(l), typeof n != "string") throw t("Label text is a string", "ui");
|
|
567
|
+
this._text = n, this._size = r, this._color = i, this._align = a, this._wrap = o, this._outline = s, this._lineHeight = c, this.role = "text";
|
|
568
|
+
}
|
|
569
|
+
get text() {
|
|
570
|
+
return this._text;
|
|
571
|
+
}
|
|
572
|
+
set text(e) {
|
|
573
|
+
let t = String(e);
|
|
574
|
+
t !== this._text && (this._text = t, this.invalidate(), this.ui?.touchMirror());
|
|
575
|
+
}
|
|
576
|
+
get size() {
|
|
577
|
+
return this._size;
|
|
578
|
+
}
|
|
579
|
+
set size(e) {
|
|
580
|
+
this._size = e, this.invalidate();
|
|
581
|
+
}
|
|
582
|
+
get color() {
|
|
583
|
+
return this._color;
|
|
584
|
+
}
|
|
585
|
+
set color(e) {
|
|
586
|
+
this._color = e, this.invalidate(!1);
|
|
587
|
+
}
|
|
588
|
+
get align() {
|
|
589
|
+
return this._align;
|
|
590
|
+
}
|
|
591
|
+
set align(e) {
|
|
592
|
+
this._align = e, this.invalidate(!1);
|
|
593
|
+
}
|
|
594
|
+
get wrap() {
|
|
595
|
+
return this._wrap;
|
|
596
|
+
}
|
|
597
|
+
set wrap(e) {
|
|
598
|
+
this._wrap = e, this.invalidate();
|
|
599
|
+
}
|
|
600
|
+
get outline() {
|
|
601
|
+
return this._outline;
|
|
602
|
+
}
|
|
603
|
+
set outline(e) {
|
|
604
|
+
this._outline = e, this.invalidate(!1);
|
|
605
|
+
}
|
|
606
|
+
measure(e) {
|
|
607
|
+
return !this.ui || !this._text ? {
|
|
608
|
+
width: 0,
|
|
609
|
+
height: 0
|
|
610
|
+
} : this.ui.measureText(this._text, this._size, this._wrap ? e : Infinity, this._lineHeight);
|
|
611
|
+
}
|
|
612
|
+
draw({ list: e, ui: t }) {
|
|
613
|
+
if (!this._text) return;
|
|
614
|
+
let n = this.rect, r = t.textLayout(this._text, this._size, this._wrap ? n.width : Infinity, this._lineHeight, this._align), i = r.bounds.right - r.bounds.left, a = this._align === "end" != (t.textDirection(this._text) === "rtl"), o = this._align === "center" ? (n.width - i) / 2 : a ? n.width - i : 0, s = t.color(this._color);
|
|
615
|
+
e.text(n.x + o - r.bounds.left, n.y, r, t.font, s, this._outline ? {
|
|
616
|
+
width: 1.5,
|
|
617
|
+
color: t.color("background")
|
|
618
|
+
} : void 0);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/color.ts
|
|
623
|
+
function I(r) {
|
|
624
|
+
if (typeof r != "string") {
|
|
625
|
+
if (!Array.isArray(r) || r.length !== 4) throw t("A colour is a #rrggbb string or [r, g, b, a]", "ui");
|
|
626
|
+
if (r.some((e) => typeof e != "number" || !(e >= 0 && e <= 1))) throw e("Colour channels must be numbers from 0 to 1", "ui");
|
|
627
|
+
return r;
|
|
628
|
+
}
|
|
629
|
+
let i = n(r.trim());
|
|
630
|
+
if (!i) throw t(`Unsupported colour '${r}'; use #rgb, #rrggbb or #rrggbbaa`, "ui");
|
|
631
|
+
return i;
|
|
632
|
+
}
|
|
633
|
+
function L(e, t) {
|
|
634
|
+
return [
|
|
635
|
+
e[0],
|
|
636
|
+
e[1],
|
|
637
|
+
e[2],
|
|
638
|
+
e[3] * t
|
|
639
|
+
];
|
|
640
|
+
}
|
|
641
|
+
function R(e, t, n) {
|
|
642
|
+
return [
|
|
643
|
+
e[0] + (t[0] - e[0]) * n,
|
|
644
|
+
e[1] + (t[1] - e[1]) * n,
|
|
645
|
+
e[2] + (t[2] - e[2]) * n,
|
|
646
|
+
e[3] + (t[3] - e[3]) * n
|
|
647
|
+
];
|
|
648
|
+
}
|
|
649
|
+
var z = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
|
|
650
|
+
function B(e) {
|
|
651
|
+
let t = I(e);
|
|
652
|
+
return .2126 * z(t[0]) + .7152 * z(t[1]) + .0722 * z(t[2]);
|
|
653
|
+
}
|
|
654
|
+
function V(e, t) {
|
|
655
|
+
let n = B(e), r = B(t);
|
|
656
|
+
return (Math.max(n, r) + .05) / (Math.min(n, r) + .05);
|
|
657
|
+
}
|
|
658
|
+
var H = {
|
|
659
|
+
protanopia: [
|
|
660
|
+
.152286,
|
|
661
|
+
1.052583,
|
|
662
|
+
-.204868,
|
|
663
|
+
.114503,
|
|
664
|
+
.786281,
|
|
665
|
+
.099216,
|
|
666
|
+
-.003882,
|
|
667
|
+
-.048116,
|
|
668
|
+
1.051998
|
|
669
|
+
],
|
|
670
|
+
deuteranopia: [
|
|
671
|
+
.367322,
|
|
672
|
+
.860646,
|
|
673
|
+
-.227968,
|
|
674
|
+
.280085,
|
|
675
|
+
.672501,
|
|
676
|
+
.047413,
|
|
677
|
+
-.01182,
|
|
678
|
+
.04294,
|
|
679
|
+
.968881
|
|
680
|
+
],
|
|
681
|
+
tritanopia: [
|
|
682
|
+
1.255528,
|
|
683
|
+
-.076749,
|
|
684
|
+
-.178779,
|
|
685
|
+
-.078411,
|
|
686
|
+
.930809,
|
|
687
|
+
.147602,
|
|
688
|
+
.004733,
|
|
689
|
+
.691367,
|
|
690
|
+
.3039
|
|
691
|
+
]
|
|
692
|
+
}, U = (e) => {
|
|
693
|
+
let t = Math.max(0, Math.min(1, e));
|
|
694
|
+
return t <= .0031308 ? t * 12.92 : 1.055 * t ** (1 / 2.4) - .055;
|
|
695
|
+
};
|
|
696
|
+
function W(e, t) {
|
|
697
|
+
let n = I(e), r = H[t], i = z(n[0]), a = z(n[1]), o = z(n[2]);
|
|
698
|
+
return [
|
|
699
|
+
U(r[0] * i + r[1] * a + r[2] * o),
|
|
700
|
+
U(r[3] * i + r[4] * a + r[5] * o),
|
|
701
|
+
U(r[6] * i + r[7] * a + r[8] * o),
|
|
702
|
+
n[3]
|
|
703
|
+
];
|
|
704
|
+
}
|
|
705
|
+
function G(e, t) {
|
|
706
|
+
let n = (e) => {
|
|
707
|
+
let t = I(e), n = z(t[0]), r = z(t[1]), i = z(t[2]), a = (e) => e > 216 / 24389 ? Math.cbrt(e) : (24389 / 27 * e + 16) / 116, o = a((.4124564 * n + .3575761 * r + .1804375 * i) / .95047), s = a(.2126729 * n + .7151522 * r + .072175 * i), c = a((.0193339 * n + .119192 * r + .9503041 * i) / 1.08883);
|
|
708
|
+
return [
|
|
709
|
+
116 * s - 16,
|
|
710
|
+
500 * (o - s),
|
|
711
|
+
200 * (s - c)
|
|
712
|
+
];
|
|
713
|
+
}, r = n(e), i = n(t);
|
|
714
|
+
return Math.hypot(r[0] - i[0], r[1] - i[1], r[2] - i[2]);
|
|
715
|
+
}
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region src/controls.ts
|
|
718
|
+
function K(e, t, n) {
|
|
719
|
+
if (!n) return {
|
|
720
|
+
fill: e.color("disabled"),
|
|
721
|
+
text: e.color("onDisabled"),
|
|
722
|
+
border: e.color("disabled")
|
|
723
|
+
};
|
|
724
|
+
switch (t) {
|
|
725
|
+
case "primary": return {
|
|
726
|
+
fill: e.color("primary"),
|
|
727
|
+
text: e.color("onPrimary"),
|
|
728
|
+
border: e.color("primary")
|
|
729
|
+
};
|
|
730
|
+
case "danger": return {
|
|
731
|
+
fill: e.color("danger"),
|
|
732
|
+
text: e.color("onDanger"),
|
|
733
|
+
border: e.color("danger")
|
|
734
|
+
};
|
|
735
|
+
case "ghost": return {
|
|
736
|
+
fill: [
|
|
737
|
+
0,
|
|
738
|
+
0,
|
|
739
|
+
0,
|
|
740
|
+
0
|
|
741
|
+
],
|
|
742
|
+
text: e.color("text"),
|
|
743
|
+
border: [
|
|
744
|
+
0,
|
|
745
|
+
0,
|
|
746
|
+
0,
|
|
747
|
+
0
|
|
748
|
+
]
|
|
749
|
+
};
|
|
750
|
+
default: return {
|
|
751
|
+
fill: e.color("surfaceRaised"),
|
|
752
|
+
text: e.color("text"),
|
|
753
|
+
border: e.color("border")
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
var q = class extends N {
|
|
758
|
+
constructor(e = {}) {
|
|
759
|
+
let { text: n = "", icon: r = "", variant: i = "secondary", size: a = "body", onClick: o, ...s } = e;
|
|
760
|
+
if (super({
|
|
761
|
+
padding: [8, 20],
|
|
762
|
+
minHeight: 44,
|
|
763
|
+
...s
|
|
764
|
+
}), typeof n != "string" || typeof r != "string") throw t("Button text and icon are strings", "ui");
|
|
765
|
+
this._text = n, this._icon = r, this._variant = i, this._size = a, this.role = "button", this.focusable = !0, this.pointerEvents = "auto", o && this.on("click", o);
|
|
766
|
+
}
|
|
767
|
+
get text() {
|
|
768
|
+
return this._text;
|
|
769
|
+
}
|
|
770
|
+
set text(e) {
|
|
771
|
+
this._text = String(e), this.invalidate(), this.ui?.touchMirror();
|
|
772
|
+
}
|
|
773
|
+
get icon() {
|
|
774
|
+
return this._icon;
|
|
775
|
+
}
|
|
776
|
+
set icon(e) {
|
|
777
|
+
this._icon = e, this.invalidate();
|
|
778
|
+
}
|
|
779
|
+
get variant() {
|
|
780
|
+
return this._variant;
|
|
781
|
+
}
|
|
782
|
+
set variant(e) {
|
|
783
|
+
this._variant = e, this.invalidate(!1);
|
|
784
|
+
}
|
|
785
|
+
get caption() {
|
|
786
|
+
return this._icon ? `${this._icon} ${this._text}` : this._text;
|
|
787
|
+
}
|
|
788
|
+
measure(e) {
|
|
789
|
+
return this.ui ? this.ui.measureText(this.caption || " ", this._size, e, 1.25) : {
|
|
790
|
+
width: 0,
|
|
791
|
+
height: 0
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
activate() {
|
|
795
|
+
this.active && this.emit("click");
|
|
796
|
+
}
|
|
797
|
+
draw(e) {
|
|
798
|
+
let { list: t, ui: n, theme: r } = e, i = this.rect, a = K(n, this._variant, this.active), o = this.levels.hover, s = this.levels.press, c = a.fill;
|
|
799
|
+
if (this.active) {
|
|
800
|
+
let e = .14 * o + .1 * s;
|
|
801
|
+
c = this._variant === "ghost" ? L(n.color("text"), e) : R(c, n.color("text"), e);
|
|
802
|
+
}
|
|
803
|
+
t.rect(i.x, i.y, i.width, i.height, {
|
|
804
|
+
fill: c,
|
|
805
|
+
border: a.border,
|
|
806
|
+
borderWidth: this._variant === "secondary" ? r.borderWidth : 0,
|
|
807
|
+
radius: r.radius
|
|
808
|
+
});
|
|
809
|
+
let l = n.textLayout(this.caption, this._size, Infinity, 1.25, "center"), u = l.bounds.right - l.bounds.left, d = l.lineHeight * l.lines.length;
|
|
810
|
+
t.text(i.x + (i.width - u) / 2 - l.bounds.left, i.y + (i.height - d) / 2, l, n.font, a.text), this.drawFocus(e);
|
|
811
|
+
}
|
|
812
|
+
}, J = class extends N {
|
|
813
|
+
constructor(e = {}) {
|
|
814
|
+
let { text: t = "", checked: n = !1, variant: r = "switch", onChange: i, ...a } = e;
|
|
815
|
+
super({
|
|
816
|
+
padding: [6, 0],
|
|
817
|
+
minHeight: 44,
|
|
818
|
+
...a
|
|
819
|
+
}), this._text = String(t), this._checked = !!n, this.slide = +!!n, this.variant = r, this.role = r === "switch" ? "switch" : "checkbox", this.focusable = !0, this.pointerEvents = "auto", i && this.on("change", i);
|
|
820
|
+
}
|
|
821
|
+
get text() {
|
|
822
|
+
return this._text;
|
|
823
|
+
}
|
|
824
|
+
set text(e) {
|
|
825
|
+
this._text = String(e), this.invalidate(), this.ui?.touchMirror();
|
|
826
|
+
}
|
|
827
|
+
get checked() {
|
|
828
|
+
return this._checked;
|
|
829
|
+
}
|
|
830
|
+
set checked(e) {
|
|
831
|
+
e = !!e, e !== this._checked && (this._checked = e, this.invalidate(!1), this.ui?.touchMirror());
|
|
832
|
+
}
|
|
833
|
+
activate() {
|
|
834
|
+
this.active && (this.checked = !this._checked, this.emit("change", { value: this._checked }));
|
|
835
|
+
}
|
|
836
|
+
get track() {
|
|
837
|
+
return this.variant === "switch" ? {
|
|
838
|
+
width: 48,
|
|
839
|
+
height: 28
|
|
840
|
+
} : {
|
|
841
|
+
width: 28,
|
|
842
|
+
height: 28
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
measure(e) {
|
|
846
|
+
if (!this.ui) return {
|
|
847
|
+
width: 0,
|
|
848
|
+
height: 0
|
|
849
|
+
};
|
|
850
|
+
let t = this.track, n = this._text ? this.ui.measureText(this._text, "body", Math.max(0, e - t.width - 12), 1.25) : {
|
|
851
|
+
width: 0,
|
|
852
|
+
height: 0
|
|
853
|
+
};
|
|
854
|
+
return {
|
|
855
|
+
width: t.width + (this._text ? 12 + n.width : 0),
|
|
856
|
+
height: Math.max(t.height, n.height)
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
tick(e) {
|
|
860
|
+
let t = super.tick(e), n = +!!this._checked;
|
|
861
|
+
if (this.slide !== n) {
|
|
862
|
+
let r = this.ui && this.ui.motion ? e / Math.max(.001, this.ui.theme.transition) : 1;
|
|
863
|
+
this.slide = n > this.slide ? Math.min(1, this.slide + r) : Math.max(0, this.slide - r), t = !0;
|
|
864
|
+
}
|
|
865
|
+
return t;
|
|
866
|
+
}
|
|
867
|
+
draw(e) {
|
|
868
|
+
let { list: t, ui: n, theme: r } = e, i = this.rect, a = this.track, o = this.active, s = i.y + (i.height - a.height) / 2, c = this._checked, l = o ? n.color("border") : n.color("disabled"), u = R(o ? c ? n.color("primary") : n.color("surfaceSunken") : n.color("disabled"), n.color("text"), .16 * this.levels.hover);
|
|
869
|
+
if (this.variant === "switch") {
|
|
870
|
+
t.rect(i.x, s, a.width, a.height, {
|
|
871
|
+
fill: u,
|
|
872
|
+
border: l,
|
|
873
|
+
borderWidth: r.borderWidth,
|
|
874
|
+
radius: a.height / 2
|
|
875
|
+
});
|
|
876
|
+
let e = a.height - 8, d = i.x + 4 + (a.width - e - 8) * this.slide;
|
|
877
|
+
t.rect(d, s + 4, e, e, {
|
|
878
|
+
fill: o ? c ? n.color("onPrimary") : n.color("text") : n.color("onDisabled"),
|
|
879
|
+
radius: e / 2
|
|
880
|
+
});
|
|
881
|
+
} else t.rect(i.x, s, a.width, a.height, {
|
|
882
|
+
fill: n.color("surfaceSunken"),
|
|
883
|
+
border: l,
|
|
884
|
+
borderWidth: Math.max(r.borderWidth, 2),
|
|
885
|
+
radius: Math.min(r.radius, 6)
|
|
886
|
+
}), c && t.rect(i.x + 6, s + 6, a.width - 12, a.height - 12, {
|
|
887
|
+
fill: o ? n.color("primary") : n.color("onDisabled"),
|
|
888
|
+
radius: 3
|
|
889
|
+
});
|
|
890
|
+
if (this._text) {
|
|
891
|
+
let e = n.textLayout(this._text, "body", Math.max(0, i.width - a.width - 12), 1.25, "start"), r = e.lineHeight * e.lines.length;
|
|
892
|
+
t.text(i.x + a.width + 12 - e.bounds.left, i.y + (i.height - r) / 2, e, n.font, o ? n.color("text") : n.color("onDisabled"));
|
|
893
|
+
}
|
|
894
|
+
this.drawFocus(e, 2);
|
|
895
|
+
}
|
|
896
|
+
}, Y = class extends N {
|
|
897
|
+
constructor(t = {}) {
|
|
898
|
+
let { min: n = 0, max: r = 1, step: i = 0, value: a, text: o = "", showValue: s = !0, format: c, onChange: l, ...u } = t;
|
|
899
|
+
if (super({
|
|
900
|
+
minHeight: 44,
|
|
901
|
+
...u
|
|
902
|
+
}), this.dragging = !1, ![
|
|
903
|
+
n,
|
|
904
|
+
r,
|
|
905
|
+
i
|
|
906
|
+
].every(Number.isFinite) || !(n < r)) throw e("Slider needs finite min < max", "ui");
|
|
907
|
+
if (i < 0) throw e("Slider step must be 0 or more", "ui");
|
|
908
|
+
this.min = n, this.max = r, this.step = i, this._text = o, this.showValue = s, this.format = c ?? ((e) => String(Math.round(e * 100) / 100)), this._value = this.snap(a ?? n), this.role = "slider", this.focusable = !0, this.pointerEvents = "auto", l && this.on("change", l);
|
|
909
|
+
}
|
|
910
|
+
get text() {
|
|
911
|
+
return this._text;
|
|
912
|
+
}
|
|
913
|
+
get value() {
|
|
914
|
+
return this._value;
|
|
915
|
+
}
|
|
916
|
+
set value(t) {
|
|
917
|
+
if (!Number.isFinite(t)) throw e("Slider value must be a finite number", "ui");
|
|
918
|
+
let n = this.snap(t);
|
|
919
|
+
n !== this._value && (this._value = n, this.invalidate(!1), this.ui?.touchMirror());
|
|
920
|
+
}
|
|
921
|
+
get valueText() {
|
|
922
|
+
return this.format(this._value);
|
|
923
|
+
}
|
|
924
|
+
snap(e) {
|
|
925
|
+
let t = Math.max(this.min, Math.min(this.max, e));
|
|
926
|
+
return this.step > 0 && (t = Math.min(this.max, this.min + Math.round((t - this.min) / this.step) * this.step)), Math.round(t * 1e9) / 1e9;
|
|
927
|
+
}
|
|
928
|
+
change(e) {
|
|
929
|
+
let t = this._value;
|
|
930
|
+
this.value = e, this._value !== t && this.emit("change", { value: this._value });
|
|
931
|
+
}
|
|
932
|
+
setValue(e) {
|
|
933
|
+
this.active && this.change(e);
|
|
934
|
+
}
|
|
935
|
+
command(e) {
|
|
936
|
+
if (!this.active || e !== "left" && e !== "right") return !1;
|
|
937
|
+
let t = this.step || (this.max - this.min) / 20;
|
|
938
|
+
return this.change(this._value + (e === "right" ? t : -t)), !0;
|
|
939
|
+
}
|
|
940
|
+
measure() {
|
|
941
|
+
return {
|
|
942
|
+
width: 220,
|
|
943
|
+
height: 32
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
get trackRect() {
|
|
947
|
+
let e = this.rect, t = this._text ? Math.min(e.width * .35, 140) : 0, n = this.showValue ? 56 : 0;
|
|
948
|
+
return {
|
|
949
|
+
x: e.x + t + (t ? 12 : 0) + 14,
|
|
950
|
+
width: Math.max(1, e.width - t - (t ? 12 : 0) - n - 28 - (n ? 8 : 0))
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
fromPointer(e) {
|
|
954
|
+
let t = this.trackRect;
|
|
955
|
+
this.change(this.min + (e - t.x) / t.width * (this.max - this.min));
|
|
956
|
+
}
|
|
957
|
+
pointerDown(e) {
|
|
958
|
+
return this.active ? (this.dragging = !0, this.fromPointer(e), !0) : !1;
|
|
959
|
+
}
|
|
960
|
+
pointerMove(e) {
|
|
961
|
+
this.dragging && this.fromPointer(e);
|
|
962
|
+
}
|
|
963
|
+
pointerUp() {
|
|
964
|
+
this.dragging = !1;
|
|
965
|
+
}
|
|
966
|
+
draw(e) {
|
|
967
|
+
let { list: t, ui: n, theme: r } = e, i = this.rect, a = this.trackRect, o = this.active, s = i.y + i.height / 2, c = (this._value - this.min) / (this.max - this.min);
|
|
968
|
+
if (this._text) {
|
|
969
|
+
let e = n.textLayout(this._text, "body", Math.min(i.width * .35, 140), 1.25, "start"), r = e.lineHeight * e.lines.length;
|
|
970
|
+
t.text(i.x, i.y + (i.height - r) / 2, e, n.font, o ? n.color("text") : n.color("onDisabled"));
|
|
971
|
+
}
|
|
972
|
+
t.rect(a.x - 14, s - 5, a.width + 28, 10, {
|
|
973
|
+
fill: n.color("surfaceSunken"),
|
|
974
|
+
border: n.color("border"),
|
|
975
|
+
borderWidth: r.borderWidth,
|
|
976
|
+
radius: 5
|
|
977
|
+
}), c > 0 && t.rect(a.x - 14, s - 5, 14 + a.width * c, 10, {
|
|
978
|
+
fill: o ? n.color("primary") : n.color("onDisabled"),
|
|
979
|
+
radius: 5
|
|
980
|
+
});
|
|
981
|
+
let l = a.x + a.width * c, u = 1 + .12 * this.levels.hover;
|
|
982
|
+
if (t.rect(l - 12 * u, s - 12 * u, 24 * u, 24 * u, {
|
|
983
|
+
fill: o ? n.color("text") : n.color("disabled"),
|
|
984
|
+
border: o ? n.color("primary") : n.color("onDisabled"),
|
|
985
|
+
borderWidth: 3,
|
|
986
|
+
radius: 12 * u
|
|
987
|
+
}), this.showValue) {
|
|
988
|
+
let e = n.textLayout(this.valueText, "body", Infinity, 1.25, "end"), r = e.lineHeight * e.lines.length, a = e.bounds.right - e.bounds.left;
|
|
989
|
+
t.text(i.x + i.width - a - e.bounds.left, i.y + (i.height - r) / 2, e, n.font, o ? n.color("textMuted") : n.color("onDisabled"));
|
|
990
|
+
}
|
|
991
|
+
this.drawFocus(e, 0);
|
|
992
|
+
}
|
|
993
|
+
}, X = class extends N {
|
|
994
|
+
constructor(e, t, n) {
|
|
995
|
+
super({
|
|
996
|
+
padding: [8, 14],
|
|
997
|
+
minHeight: 44,
|
|
998
|
+
enabled: !n.disabled
|
|
999
|
+
}), this.list = e, this.index = t, this.entry = n, this.selected = !1, this.role = "option", this.focusable = !0, this.pointerEvents = "auto";
|
|
1000
|
+
}
|
|
1001
|
+
get text() {
|
|
1002
|
+
return this.entry.label;
|
|
1003
|
+
}
|
|
1004
|
+
activate() {
|
|
1005
|
+
this.active && this.list.select(this.index, !0);
|
|
1006
|
+
}
|
|
1007
|
+
measure(e) {
|
|
1008
|
+
return this.ui ? this.ui.measureText(this.entry.label, "body", e - 16, 1.25) : {
|
|
1009
|
+
width: 0,
|
|
1010
|
+
height: 0
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
draw(e) {
|
|
1014
|
+
let { list: t, ui: n, theme: r } = e, i = this.rect, a = this.active, o = this.selected ? n.color("surfaceRaised") : n.color("surface");
|
|
1015
|
+
t.rect(i.x, i.y, i.width, i.height, {
|
|
1016
|
+
fill: R(o, n.color("text"), .1 * this.levels.hover),
|
|
1017
|
+
radius: r.radius
|
|
1018
|
+
}), this.selected && t.rect(i.x, i.y + 6, 5, i.height - 12, {
|
|
1019
|
+
fill: n.color("primary"),
|
|
1020
|
+
radius: 2.5
|
|
1021
|
+
});
|
|
1022
|
+
let s = a ? n.color("text") : n.color("onDisabled"), c = n.textLayout(this.entry.label, "body", Math.max(0, i.width - 28), 1.25, "start"), l = c.lineHeight * c.lines.length;
|
|
1023
|
+
if (t.text(i.x + 14 - c.bounds.left, i.y + (i.height - l) / 2, c, n.font, s), this.entry.detail) {
|
|
1024
|
+
let e = n.textLayout(this.entry.detail, "small", Infinity, 1.2, "end"), r = e.lineHeight * e.lines.length;
|
|
1025
|
+
t.text(i.x + i.width - 14 - (e.bounds.right - e.bounds.left) - e.bounds.left, i.y + (i.height - r) / 2, e, n.font, a ? n.color("textMuted") : n.color("onDisabled"));
|
|
1026
|
+
}
|
|
1027
|
+
this.drawFocus(e, 0);
|
|
1028
|
+
}
|
|
1029
|
+
}, Z = class extends P {
|
|
1030
|
+
constructor(e = {}) {
|
|
1031
|
+
let { items: t = [], selected: n = -1, onSelect: r, ...i } = e;
|
|
1032
|
+
super({
|
|
1033
|
+
background: "surface",
|
|
1034
|
+
border: !0,
|
|
1035
|
+
padding: 4,
|
|
1036
|
+
gap: 2,
|
|
1037
|
+
overflow: "scroll",
|
|
1038
|
+
...i
|
|
1039
|
+
}), this._items = [], this._selected = -1, this.role = "listbox", this.items = t, this.select(n), r && this.on("select", r);
|
|
1040
|
+
}
|
|
1041
|
+
get items() {
|
|
1042
|
+
return this._items;
|
|
1043
|
+
}
|
|
1044
|
+
set items(e) {
|
|
1045
|
+
if (!Array.isArray(e)) throw t("List items are an array of strings or { label } entries", "ui");
|
|
1046
|
+
this._items = e.map((e) => {
|
|
1047
|
+
if (typeof e == "string") return { label: e };
|
|
1048
|
+
if (!e || typeof e.label != "string") throw t("A list entry is a string or has a string label", "ui");
|
|
1049
|
+
return e;
|
|
1050
|
+
}), this._selected = -1, this.clear(), this._items.forEach((e, t) => this.add(new X(this, t, e)));
|
|
1051
|
+
}
|
|
1052
|
+
get selected() {
|
|
1053
|
+
return this._selected;
|
|
1054
|
+
}
|
|
1055
|
+
get selectedItem() {
|
|
1056
|
+
return this._items[this._selected];
|
|
1057
|
+
}
|
|
1058
|
+
select(t, n = !1) {
|
|
1059
|
+
if (!Number.isInteger(t) || t < -1 || t >= this._items.length) {
|
|
1060
|
+
if (t === -1) return;
|
|
1061
|
+
throw e(`List index ${t} is outside 0..${this._items.length - 1}`, "ui");
|
|
1062
|
+
}
|
|
1063
|
+
this._selected = t;
|
|
1064
|
+
for (let e of this.children) e instanceof X && (e.selected = e.index === t);
|
|
1065
|
+
if (this.invalidate(!1), this.ui?.touchMirror(), n && t >= 0) {
|
|
1066
|
+
let e = this._items[t];
|
|
1067
|
+
this.emit("select", {
|
|
1068
|
+
index: t,
|
|
1069
|
+
item: e.value ?? e
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}, Q = class extends N {
|
|
1074
|
+
constructor(e, t) {
|
|
1075
|
+
super({}), this.inventory = e, this.index = t, this.item = null, this.role = "button", this.focusable = !0, this.pointerEvents = "auto";
|
|
1076
|
+
}
|
|
1077
|
+
get text() {
|
|
1078
|
+
return this.item ? `${this.item.name}${(this.item.count ?? 1) > 1 ? `, ${this.item.count}` : ""}` : `Empty slot ${this.index + 1}`;
|
|
1079
|
+
}
|
|
1080
|
+
activate() {
|
|
1081
|
+
this.active && this.inventory.activateSlot(this.index);
|
|
1082
|
+
}
|
|
1083
|
+
command(e) {
|
|
1084
|
+
return e === "cancel" && this.inventory.cancelCarry();
|
|
1085
|
+
}
|
|
1086
|
+
pointerDown(e, t) {
|
|
1087
|
+
return this.active && this.inventory.beginDrag(this.index, e, t);
|
|
1088
|
+
}
|
|
1089
|
+
pointerMove(e, t) {
|
|
1090
|
+
this.inventory.dragTo(e, t);
|
|
1091
|
+
}
|
|
1092
|
+
pointerUp(e, t) {
|
|
1093
|
+
this.inventory.endDrag(e, t);
|
|
1094
|
+
}
|
|
1095
|
+
draw(e) {
|
|
1096
|
+
let { list: t, ui: n, theme: r } = e, i = this.rect, a = this.inventory, o = a.carried === this.index, s = a.selected === this.index, c = a.dragging === this.index;
|
|
1097
|
+
t.rect(i.x, i.y, i.width, i.height, {
|
|
1098
|
+
fill: R(n.color("surfaceSunken"), n.color("text"), .1 * this.levels.hover),
|
|
1099
|
+
border: o ? n.color("accent") : s ? n.color("primary") : n.color("border"),
|
|
1100
|
+
borderWidth: o || s ? Math.max(2, r.borderWidth + 1) : r.borderWidth,
|
|
1101
|
+
radius: Math.min(r.radius, 8)
|
|
1102
|
+
}), this.item && !c && this.drawItem(e, i.x, i.y, i.width, i.height), this.drawFocus(e, 2);
|
|
1103
|
+
}
|
|
1104
|
+
drawItem({ list: e, ui: t }, n, r, i, a, o = 1) {
|
|
1105
|
+
let s = this.item;
|
|
1106
|
+
if (s.color) {
|
|
1107
|
+
let c = t.color(s.color);
|
|
1108
|
+
e.rect(n + 6, r + a - 7, i - 12, 3, {
|
|
1109
|
+
fill: [
|
|
1110
|
+
c[0],
|
|
1111
|
+
c[1],
|
|
1112
|
+
c[2],
|
|
1113
|
+
c[3] * o
|
|
1114
|
+
],
|
|
1115
|
+
radius: 1.5
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
let c = s.icon ?? s.name.slice(0, 1).toUpperCase(), l = t.textLayout(c, Math.round(a * .5), Infinity, 1.2, "center"), u = l.lineHeight * l.lines.length, d = t.color("text");
|
|
1119
|
+
if (e.text(n + (i - (l.bounds.right - l.bounds.left)) / 2 - l.bounds.left, r + (a - u) / 2 - 2, l, t.font, [
|
|
1120
|
+
d[0],
|
|
1121
|
+
d[1],
|
|
1122
|
+
d[2],
|
|
1123
|
+
d[3] * o
|
|
1124
|
+
]), (s.count ?? 1) > 1) {
|
|
1125
|
+
let o = t.textLayout(String(s.count), "small", Infinity, 1.2, "end");
|
|
1126
|
+
e.text(n + i - 6 - (o.bounds.right - o.bounds.left) - o.bounds.left, r + a - 6 - o.lineHeight - 4, o, t.font, d, {
|
|
1127
|
+
width: 2,
|
|
1128
|
+
color: t.color("surfaceSunken")
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}, ee = class extends N {
|
|
1133
|
+
constructor(t = {}) {
|
|
1134
|
+
let { columns: n = 5, slots: r, slotSize: i = 56, slotGap: a = 6, items: o = [], onSelect: s, onMove: c, onUse: l, ...u } = t;
|
|
1135
|
+
if (!Number.isInteger(n) || n < 1) throw e("Inventory columns must be an integer of at least 1", "ui");
|
|
1136
|
+
let d = r ?? n * 4;
|
|
1137
|
+
if (!Number.isInteger(d) || d < 0 || d > 4096) throw e("Inventory slots must be an integer from 0 to 4096", "ui");
|
|
1138
|
+
super({
|
|
1139
|
+
direction: "grid",
|
|
1140
|
+
columns: n,
|
|
1141
|
+
cellWidth: i,
|
|
1142
|
+
cellHeight: i,
|
|
1143
|
+
gap: a,
|
|
1144
|
+
...u
|
|
1145
|
+
}), this._items = [], this.slotWidgets = [], this.dragging = -1, this.dragStart = null, this.dragPoint = {
|
|
1146
|
+
x: 0,
|
|
1147
|
+
y: 0
|
|
1148
|
+
}, this._selected = -1, this._carried = -1, this.pendingDrag = -1, this.role = "group";
|
|
1149
|
+
for (let e = 0; e < d; e++) {
|
|
1150
|
+
let t = new Q(this, e);
|
|
1151
|
+
this.slotWidgets.push(t), this.add(t);
|
|
1152
|
+
}
|
|
1153
|
+
this.items = o, s && this.on("select", s), c && this.on("move", c), l && this.on("use", l);
|
|
1154
|
+
}
|
|
1155
|
+
get slots() {
|
|
1156
|
+
return this.slotWidgets.length;
|
|
1157
|
+
}
|
|
1158
|
+
get columns() {
|
|
1159
|
+
return this.style.columns ?? 1;
|
|
1160
|
+
}
|
|
1161
|
+
get items() {
|
|
1162
|
+
return this._items;
|
|
1163
|
+
}
|
|
1164
|
+
set items(e) {
|
|
1165
|
+
this._items = this.slotWidgets.map((t, n) => e[n] ?? null), this.slotWidgets.forEach((e, t) => this.sync(t)), this._carried = this._selected = -1, this.invalidate(!1), this.ui?.touchMirror();
|
|
1166
|
+
}
|
|
1167
|
+
slot(t) {
|
|
1168
|
+
let n = this.slotWidgets[t];
|
|
1169
|
+
if (!n) throw e(`Inventory slot ${t} does not exist`, "ui");
|
|
1170
|
+
return n;
|
|
1171
|
+
}
|
|
1172
|
+
get selected() {
|
|
1173
|
+
return this._selected;
|
|
1174
|
+
}
|
|
1175
|
+
get carried() {
|
|
1176
|
+
return this._carried;
|
|
1177
|
+
}
|
|
1178
|
+
get(e) {
|
|
1179
|
+
return this._items[e] ?? null;
|
|
1180
|
+
}
|
|
1181
|
+
set(e, t) {
|
|
1182
|
+
this.slot(e), this._items[e] = t, this.sync(e), this.invalidate(!1), this.ui?.touchMirror();
|
|
1183
|
+
}
|
|
1184
|
+
swap(e, t) {
|
|
1185
|
+
this.slot(e), this.slot(t), e !== t && ([this._items[e], this._items[t]] = [this._items[t], this._items[e]], this.sync(e), this.sync(t), this.invalidate(!1), this.ui?.touchMirror(), this.emit("move", {
|
|
1186
|
+
from: e,
|
|
1187
|
+
index: t,
|
|
1188
|
+
item: this._items[t]
|
|
1189
|
+
}));
|
|
1190
|
+
}
|
|
1191
|
+
sync(e) {
|
|
1192
|
+
let t = this.slotWidgets[e], n = this._items[e];
|
|
1193
|
+
t.item = n, t.tooltip = n ? n.description ? `${n.name}\n${n.description}` : n.name : void 0;
|
|
1194
|
+
}
|
|
1195
|
+
activateSlot(e) {
|
|
1196
|
+
if (this._carried >= 0) {
|
|
1197
|
+
let t = this._carried;
|
|
1198
|
+
this._carried = -1, t === e ? this.emit("use", {
|
|
1199
|
+
index: e,
|
|
1200
|
+
item: this._items[e]
|
|
1201
|
+
}) : this.swap(t, e);
|
|
1202
|
+
} else this._items[e] && (this._carried = e, this._selected = e, this.emit("select", {
|
|
1203
|
+
index: e,
|
|
1204
|
+
item: this._items[e]
|
|
1205
|
+
}));
|
|
1206
|
+
this.invalidate(!1);
|
|
1207
|
+
}
|
|
1208
|
+
cancelCarry() {
|
|
1209
|
+
return this._carried < 0 ? !1 : (this._carried = -1, this.invalidate(!1), !0);
|
|
1210
|
+
}
|
|
1211
|
+
beginDrag(e, t, n) {
|
|
1212
|
+
return this.dragStart = {
|
|
1213
|
+
x: t,
|
|
1214
|
+
y: n
|
|
1215
|
+
}, this.dragPoint = {
|
|
1216
|
+
x: t,
|
|
1217
|
+
y: n
|
|
1218
|
+
}, this.dragging = -1, this.pendingDrag = e, !0;
|
|
1219
|
+
}
|
|
1220
|
+
dragTo(e, t) {
|
|
1221
|
+
this.dragPoint = {
|
|
1222
|
+
x: e,
|
|
1223
|
+
y: t
|
|
1224
|
+
}, this.dragging < 0 && this.dragStart && this.items[this.pendingDrag] && Math.hypot(e - this.dragStart.x, t - this.dragStart.y) > 6 && (this.dragging = this.pendingDrag, this.ui?.cancelTooltip()), this.dragging >= 0 && this.invalidate(!1);
|
|
1225
|
+
}
|
|
1226
|
+
endDrag(e, t) {
|
|
1227
|
+
let n = this.dragging, r = this.pendingDrag;
|
|
1228
|
+
if (this.dragging = this.pendingDrag = -1, this.dragStart = null, n >= 0) {
|
|
1229
|
+
let r = this.slotAt(e, t);
|
|
1230
|
+
r >= 0 && r !== n && this.swap(n, r), this._carried = -1;
|
|
1231
|
+
} else r >= 0 && this.slotAt(e, t) === r && this.activateSlot(r);
|
|
1232
|
+
this.invalidate(!1);
|
|
1233
|
+
}
|
|
1234
|
+
slotAt(e, t) {
|
|
1235
|
+
return this.slotWidgets.findIndex((n) => e >= n.rect.x && e < n.rect.x + n.rect.width && t >= n.rect.y && t < n.rect.y + n.rect.height);
|
|
1236
|
+
}
|
|
1237
|
+
draw() {}
|
|
1238
|
+
drawAfter(e) {
|
|
1239
|
+
if (this.dragging < 0) return;
|
|
1240
|
+
let t = this.slotWidgets[this.dragging], n = t.rect;
|
|
1241
|
+
e.list.rect(this.dragPoint.x - n.width / 2, this.dragPoint.y - n.height / 2, n.width, n.height, {
|
|
1242
|
+
fill: L(e.ui.color("surfaceRaised"), .9),
|
|
1243
|
+
border: e.ui.color("primary"),
|
|
1244
|
+
borderWidth: 2,
|
|
1245
|
+
radius: 8
|
|
1246
|
+
}), t.drawItem(e, this.dragPoint.x - n.width / 2, this.dragPoint.y - n.height / 2, n.width, n.height);
|
|
1247
|
+
}
|
|
1248
|
+
}, te = class extends P {
|
|
1249
|
+
constructor(e = {}) {
|
|
1250
|
+
let { title: t = "", items: n = [], ...r } = e;
|
|
1251
|
+
super({
|
|
1252
|
+
background: "surface",
|
|
1253
|
+
border: !0,
|
|
1254
|
+
shadow: !0,
|
|
1255
|
+
padding: 24,
|
|
1256
|
+
gap: 8,
|
|
1257
|
+
width: 340,
|
|
1258
|
+
anchor: "center",
|
|
1259
|
+
...r
|
|
1260
|
+
}), this.role = "group", this.heading = new F({
|
|
1261
|
+
text: t,
|
|
1262
|
+
size: "title",
|
|
1263
|
+
align: "center",
|
|
1264
|
+
margin: [
|
|
1265
|
+
0,
|
|
1266
|
+
0,
|
|
1267
|
+
8,
|
|
1268
|
+
0
|
|
1269
|
+
],
|
|
1270
|
+
visible: !!t
|
|
1271
|
+
}), this.label = t, this.add(this.heading), n.forEach((e, t) => {
|
|
1272
|
+
let n = new q({
|
|
1273
|
+
text: e.label,
|
|
1274
|
+
icon: e.icon,
|
|
1275
|
+
variant: e.variant ?? (t === 0 ? "primary" : "secondary"),
|
|
1276
|
+
enabled: !e.disabled
|
|
1277
|
+
});
|
|
1278
|
+
e.onSelect && n.on("click", () => e.onSelect()), this.add(n);
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
get title() {
|
|
1282
|
+
return this.heading.text;
|
|
1283
|
+
}
|
|
1284
|
+
set title(e) {
|
|
1285
|
+
this.heading.text = e, this.heading.visible = !!e, this.label = e;
|
|
1286
|
+
}
|
|
1287
|
+
}, $ = class extends N {
|
|
1288
|
+
constructor(t = {}) {
|
|
1289
|
+
let { value: n = 0, max: r = 1, text: i = "", variant: a = "primary", display: o = "percent", smooth: s = !0, trail: c = !1, ...l } = t;
|
|
1290
|
+
if (super({
|
|
1291
|
+
minHeight: 24,
|
|
1292
|
+
...l
|
|
1293
|
+
}), this.shown_ = 0, this.chip = 0, this.chipHold = 0, !Number.isFinite(r) || !(r > 0)) throw e("ProgressBar max must be a number above 0", "ui");
|
|
1294
|
+
if (!Number.isFinite(n)) throw e("ProgressBar value must be a finite number", "ui");
|
|
1295
|
+
this.max = r, this._value = Math.max(0, Math.min(r, n)), this._text = i, this._variant = a, this.display = o, this.smooth = s, this.trail = c, this.shown_ = this.chip = this._value / r, this.role = "progressbar";
|
|
1296
|
+
}
|
|
1297
|
+
get text() {
|
|
1298
|
+
return this._text;
|
|
1299
|
+
}
|
|
1300
|
+
set text(e) {
|
|
1301
|
+
this._text = String(e), this.invalidate(!1), this.ui?.touchMirror();
|
|
1302
|
+
}
|
|
1303
|
+
get value() {
|
|
1304
|
+
return this._value;
|
|
1305
|
+
}
|
|
1306
|
+
set value(t) {
|
|
1307
|
+
if (!Number.isFinite(t)) throw e("ProgressBar value must be a finite number", "ui");
|
|
1308
|
+
let n = Math.max(0, Math.min(this.max, t));
|
|
1309
|
+
n !== this._value && (n < this._value && this.trail && (this.chip = Math.max(this.chip, this._value / this.max), this.chipHold = .45), this._value = n, this.invalidate(!1), this.ui?.touchMirror());
|
|
1310
|
+
}
|
|
1311
|
+
get variant() {
|
|
1312
|
+
return this._variant;
|
|
1313
|
+
}
|
|
1314
|
+
set variant(e) {
|
|
1315
|
+
this._variant = e, this.invalidate(!1);
|
|
1316
|
+
}
|
|
1317
|
+
get valueText() {
|
|
1318
|
+
return this.display === "fraction" ? `${Math.round(this._value)} / ${Math.round(this.max)}` : `${Math.round(this._value / this.max * 100)}%`;
|
|
1319
|
+
}
|
|
1320
|
+
measure() {
|
|
1321
|
+
return {
|
|
1322
|
+
width: 200,
|
|
1323
|
+
height: 24
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
tick(e) {
|
|
1327
|
+
let t = super.tick(e), n = this._value / this.max, r = this.smooth && !!this.ui?.motion;
|
|
1328
|
+
if (this.shown_ !== n) {
|
|
1329
|
+
let i = Math.max(Math.abs(n - this.shown_) * 8, .5) * e;
|
|
1330
|
+
this.shown_ = !r || Math.abs(n - this.shown_) <= i ? n : this.shown_ + Math.sign(n - this.shown_) * i, t = !0;
|
|
1331
|
+
}
|
|
1332
|
+
if (this.chip < this.shown_ && (this.chip = this.shown_), this.chip > this.shown_) {
|
|
1333
|
+
if (this.chipHold > 0) this.chipHold = Math.max(0, this.chipHold - e);
|
|
1334
|
+
else {
|
|
1335
|
+
let t = .6 * e;
|
|
1336
|
+
this.chip = !r || this.chip - t <= this.shown_ ? this.shown_ : this.chip - t;
|
|
1337
|
+
}
|
|
1338
|
+
t = !0;
|
|
1339
|
+
}
|
|
1340
|
+
return t;
|
|
1341
|
+
}
|
|
1342
|
+
fillColor(e, t) {
|
|
1343
|
+
let n = this._variant;
|
|
1344
|
+
return n === "health" ? e.color(t > .5 ? "success" : t > .25 ? "warning" : "danger") : e.color(n);
|
|
1345
|
+
}
|
|
1346
|
+
draw({ list: e, ui: t, theme: n }) {
|
|
1347
|
+
let r = this.rect, i = Math.min(n.radius, r.height / 2), a = Math.max(0, Math.min(1, this.shown_)), o = this._value / this.max;
|
|
1348
|
+
e.rect(r.x, r.y, r.width, r.height, {
|
|
1349
|
+
fill: t.color("surfaceSunken"),
|
|
1350
|
+
border: t.color("border"),
|
|
1351
|
+
borderWidth: n.borderWidth,
|
|
1352
|
+
radius: i
|
|
1353
|
+
});
|
|
1354
|
+
let s = n.borderWidth, c = r.width - 2 * s;
|
|
1355
|
+
if (this.trail && this.chip > a) {
|
|
1356
|
+
let n = t.color("text");
|
|
1357
|
+
e.rect(r.x + s, r.y + s, c * Math.min(1, this.chip), r.height - 2 * s, {
|
|
1358
|
+
fill: [
|
|
1359
|
+
n[0],
|
|
1360
|
+
n[1],
|
|
1361
|
+
n[2],
|
|
1362
|
+
.55
|
|
1363
|
+
],
|
|
1364
|
+
radius: i - 1
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
a > 0 && e.rect(r.x + s, r.y + s, Math.max(c * a, Math.min(c, 2 * i)), r.height - 2 * s, {
|
|
1368
|
+
fill: this.fillColor(t, o),
|
|
1369
|
+
radius: i - 1
|
|
1370
|
+
});
|
|
1371
|
+
let l = {
|
|
1372
|
+
width: 2,
|
|
1373
|
+
color: t.color("surfaceSunken")
|
|
1374
|
+
};
|
|
1375
|
+
if (r.height >= 20) {
|
|
1376
|
+
if (this._text) {
|
|
1377
|
+
let n = t.textLayout(this._text, "small", Math.max(0, r.width - 16), 1.2, "start"), i = n.lineHeight * n.lines.length;
|
|
1378
|
+
e.text(r.x + 10 - n.bounds.left, r.y + (r.height - i) / 2, n, t.font, t.color("text"), l);
|
|
1379
|
+
}
|
|
1380
|
+
if (this.display !== "none") {
|
|
1381
|
+
let n = t.textLayout(this.valueText, "small", Infinity, 1.2, "end"), i = n.lineHeight * n.lines.length, a = n.bounds.right - n.bounds.left;
|
|
1382
|
+
e.text(r.x + r.width - 10 - a - n.bounds.left, r.y + (r.height - i) / 2, n, t.font, t.color("text"), l);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
}, ne = class extends $ {
|
|
1387
|
+
constructor(e = {}) {
|
|
1388
|
+
let t = e.max ?? 100;
|
|
1389
|
+
super({
|
|
1390
|
+
text: "HP",
|
|
1391
|
+
display: "fraction",
|
|
1392
|
+
...e,
|
|
1393
|
+
max: t,
|
|
1394
|
+
value: e.value ?? t,
|
|
1395
|
+
variant: "health",
|
|
1396
|
+
trail: !0
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
//#endregion
|
|
1401
|
+
export { a as C, x as S, F as _, X as a, y as b, Y as c, V as d, B as f, L as g, W as h, Z as i, J as l, I as m, $ as n, te as o, R as p, ee as r, q as s, ne as t, G as u, P as v, i as x, N as y };
|