uxml-preview 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1292 @@
1
+ import { loadYoga as lt, PositionType as z, Direction as ct, BoxSizing as ut, FlexDirection as D, Wrap as A, Justify as I, Align as E, Display as ft, Overflow as dt, Edge as M } from "yoga-layout/load";
2
+ const K = {
3
+ VisualElement: { hasText: !1 },
4
+ Label: { hasText: !0 },
5
+ Button: { hasText: !0 }
6
+ };
7
+ function U(t) {
8
+ return K[t.name.local] ?? null;
9
+ }
10
+ function ie() {
11
+ return Object.keys(K);
12
+ }
13
+ const Q = {
14
+ "align-content": "flex-start",
15
+ "align-items": "stretch",
16
+ "align-self": "auto",
17
+ "flex-basis": "auto",
18
+ "flex-direction": "column",
19
+ "flex-grow": "0",
20
+ "flex-shrink": "1",
21
+ "flex-wrap": "nowrap",
22
+ "justify-content": "flex-start",
23
+ display: "flex",
24
+ position: "relative",
25
+ overflow: "visible",
26
+ bottom: "auto",
27
+ left: "auto",
28
+ right: "auto",
29
+ top: "auto",
30
+ height: "auto",
31
+ width: "auto",
32
+ "max-height": "none",
33
+ "max-width": "none",
34
+ "min-height": "auto",
35
+ "min-width": "auto",
36
+ "border-bottom-width": "0",
37
+ "border-left-width": "0",
38
+ "border-right-width": "0",
39
+ "border-top-width": "0",
40
+ "margin-bottom": "0",
41
+ "margin-left": "0",
42
+ "margin-right": "0",
43
+ "margin-top": "0",
44
+ "padding-bottom": "0",
45
+ "padding-left": "0",
46
+ "padding-right": "0",
47
+ "padding-top": "0",
48
+ "font-size": "12px"
49
+ }, pt = ["em", "rem", "vh", "vw", "vmin", "vmax", "pt", "cm", "in"];
50
+ function P(t) {
51
+ const n = t.trim();
52
+ if (n === "") return { length: null, problem: "empty value" };
53
+ if (n === "auto") return { length: { kind: "auto" } };
54
+ if (n === "none") return { length: { kind: "none" } };
55
+ if (n === "initial") return { length: { kind: "auto" } };
56
+ if (n.startsWith("calc("))
57
+ return { length: null, problem: "calc() is not supported in USS" };
58
+ const e = /^(-?(?:\d+\.?\d*|\.\d+))([a-z%]*)$/i.exec(n);
59
+ if (e === null) return { length: null, problem: `cannot read "${n}" as a length` };
60
+ const i = Number(e[1]), l = e[2].toLowerCase();
61
+ return l === "" || l === "px" ? { length: { kind: "px", value: i } } : l === "%" ? { length: { kind: "percent", value: i } } : pt.includes(l) ? { length: null, problem: `"${l}" is not a USS unit` } : { length: null, problem: `unknown unit "${l}"` };
62
+ }
63
+ function B(t) {
64
+ const n = t.trim();
65
+ return /^-?(\d+\.?\d*|\.\d+)$/.test(n) ? Number(n) : null;
66
+ }
67
+ let _ = null;
68
+ async function re() {
69
+ _ ?? (_ = await lt());
70
+ }
71
+ function se() {
72
+ return _ !== null;
73
+ }
74
+ let W = 0;
75
+ function oe() {
76
+ return W;
77
+ }
78
+ const R = {
79
+ auto: E.Auto,
80
+ "flex-start": E.FlexStart,
81
+ center: E.Center,
82
+ "flex-end": E.FlexEnd,
83
+ stretch: E.Stretch,
84
+ baseline: E.Baseline,
85
+ "space-between": E.SpaceBetween,
86
+ "space-around": E.SpaceAround,
87
+ "space-evenly": E.SpaceEvenly
88
+ }, ht = {
89
+ "flex-start": I.FlexStart,
90
+ center: I.Center,
91
+ "flex-end": I.FlexEnd,
92
+ "space-between": I.SpaceBetween,
93
+ "space-around": I.SpaceAround,
94
+ "space-evenly": I.SpaceEvenly
95
+ }, gt = {
96
+ column: D.Column,
97
+ "column-reverse": D.ColumnReverse,
98
+ row: D.Row,
99
+ "row-reverse": D.RowReverse
100
+ }, mt = {
101
+ nowrap: A.NoWrap,
102
+ wrap: A.Wrap,
103
+ "wrap-reverse": A.WrapReverse
104
+ }, wt = [
105
+ ["left", M.Left],
106
+ ["top", M.Top],
107
+ ["right", M.Right],
108
+ ["bottom", M.Bottom]
109
+ ];
110
+ function bt(t, n, e) {
111
+ const i = _;
112
+ if (i === null)
113
+ throw new Error("loadLayoutEngine() must be awaited before rendering");
114
+ const l = [], r = /* @__PURE__ */ new Map(), p = [], g = /* @__PURE__ */ new Map();
115
+ let b = 0, d = !1;
116
+ const s = (a, o) => {
117
+ var h;
118
+ return ((h = a.get(o)) == null ? void 0 : h.value) ?? Q[o] ?? "";
119
+ };
120
+ function c(a, o) {
121
+ l.push({ kind: "unsupported-property", message: a, node: o.id });
122
+ }
123
+ function u(a, o, h) {
124
+ const v = s(a, o);
125
+ if (v === "") return null;
126
+ const { length: y, problem: T } = P(v);
127
+ return T !== void 0 && c(`${o}: ${T}`, h), y;
128
+ }
129
+ function f(a) {
130
+ if (a !== null)
131
+ switch (a.kind) {
132
+ case "px":
133
+ return a.value;
134
+ case "percent":
135
+ return `${a.value}%`;
136
+ case "auto":
137
+ return "auto";
138
+ case "none":
139
+ return;
140
+ }
141
+ }
142
+ function x(a) {
143
+ if (a !== null) {
144
+ if (a.kind === "px") return a.value;
145
+ if (a.kind === "percent") return `${a.value}%`;
146
+ }
147
+ }
148
+ function S(a, o, h) {
149
+ a.setBoxSizing(ut.BorderBox), a.setFlexDirection(gt[s(o, "flex-direction")] ?? D.Column), a.setFlexWrap(mt[s(o, "flex-wrap")] ?? A.NoWrap), a.setJustifyContent(ht[s(o, "justify-content")] ?? I.FlexStart), a.setAlignItems(R[s(o, "align-items")] ?? E.Stretch), a.setAlignSelf(R[s(o, "align-self")] ?? E.Auto), a.setAlignContent(R[s(o, "align-content")] ?? E.FlexStart), a.setFlexGrow(B(s(o, "flex-grow")) ?? 0), a.setFlexShrink(B(s(o, "flex-shrink")) ?? 1), a.setFlexBasis(f(u(o, "flex-basis", h)));
150
+ const v = s(o, "position");
151
+ (v === "fixed" || v === "sticky") && c(`position: ${v} is not supported in USS; treated as relative`, h), a.setPositionType(
152
+ v === "absolute" ? z.Absolute : z.Relative
153
+ ), s(o, "display") === "none" && a.setDisplay(ft.None);
154
+ const y = s(o, "overflow");
155
+ y === "hidden" ? a.setOverflow(dt.Hidden) : (y === "auto" || y === "scroll") && c(`overflow: ${y} needs a ScrollView element in USS`, h), a.setWidth(f(u(o, "width", h))), a.setHeight(f(u(o, "height", h))), a.setMinWidth(x(u(o, "min-width", h))), a.setMinHeight(x(u(o, "min-height", h))), a.setMaxWidth(x(u(o, "max-width", h))), a.setMaxHeight(x(u(o, "max-height", h)));
156
+ for (const [T, N] of wt) {
157
+ a.setMargin(N, x(u(o, `margin-${T}`, h))), a.setPadding(N, x(u(o, `padding-${T}`, h)));
158
+ const O = x(u(o, `border-${T}-width`, h));
159
+ a.setBorder(N, typeof O == "number" ? O : void 0), a.setPosition(N, x(u(o, T, h)));
160
+ }
161
+ }
162
+ function m(a) {
163
+ var o;
164
+ return (o = a.attributes.find((h) => h.name === "text")) == null ? void 0 : o.value;
165
+ }
166
+ function $(a, o) {
167
+ const h = n.get(a.id) ?? /* @__PURE__ */ new Map(), v = i.Node.create();
168
+ b++, W++, g.set(a, v), p.push(a), S(v, h, a), o !== null && o.insertChild(v, o.getChildCount());
169
+ const y = U(a), T = m(a);
170
+ if ((y == null ? void 0 : y.hasText) === !0 && T !== void 0 && T.length > 0) {
171
+ a.children.length > 0 && c(
172
+ `<${a.name.local}> has both a text attribute and children; children are not drawn`,
173
+ a
174
+ );
175
+ const O = u(h, "font-size", a), at = {
176
+ fontSize: O !== null && O.kind === "px" ? O.value : 12,
177
+ fontStyle: s(h, "-unity-font-style") || "normal",
178
+ whiteSpace: s(h, "white-space") || "normal"
179
+ };
180
+ v.setMeasureFunc(
181
+ (H) => e.measureText(
182
+ T,
183
+ at,
184
+ Number.isFinite(H) ? H : 0
185
+ )
186
+ );
187
+ return;
188
+ }
189
+ for (const O of a.children) {
190
+ if (U(O) === null) {
191
+ l.push({
192
+ kind: "unsupported-control",
193
+ message: `<${O.name.local}> is not supported in v0.1 and is not drawn`,
194
+ node: O.id
195
+ });
196
+ continue;
197
+ }
198
+ $(O, v);
199
+ }
200
+ }
201
+ $(t, null);
202
+ const k = g.get(t);
203
+ k.setWidth(e.size.width), k.setHeight(e.size.height), k.setPositionType(z.Relative), k.calculateLayout(e.size.width, e.size.height, ct.LTR);
204
+ function w(a, o, h) {
205
+ const v = g.get(a);
206
+ if (v === void 0) return;
207
+ const y = v.getComputedLayout(), T = o + y.left, N = h + y.top;
208
+ r.set(a.id, { left: T, top: N, width: y.width, height: y.height });
209
+ for (const O of a.children) w(O, T, N);
210
+ }
211
+ return w(t, 0, 0), {
212
+ boxes: r,
213
+ painted: p,
214
+ warnings: l,
215
+ dispose() {
216
+ d || (d = !0, k.freeRecursive(), W -= b, g.clear());
217
+ }
218
+ };
219
+ }
220
+ const xt = 1.2;
221
+ function vt(t) {
222
+ var e;
223
+ let n = null;
224
+ if (t !== void 0) {
225
+ const i = t.createElement("canvas");
226
+ n = ((e = i.getContext) == null ? void 0 : e.call(i, "2d")) ?? null;
227
+ }
228
+ return (i, l, r) => {
229
+ const p = l.fontSize * xt, g = (f) => {
230
+ if (n === null)
231
+ return f.length * l.fontSize * 0.5;
232
+ const x = l.fontStyle.includes("bold") ? "bold" : "normal", S = l.fontStyle.includes("italic") ? "italic" : "normal";
233
+ return n.font = `${S} ${x} ${l.fontSize}px sans-serif`, n.measureText(f).width;
234
+ };
235
+ if (!(l.whiteSpace !== "nowrap" && l.whiteSpace !== "pre") || r <= 0) {
236
+ const f = i.split(`
237
+ `);
238
+ return { width: f.reduce((S, m) => Math.max(S, g(m)), 0), height: f.length * p };
239
+ }
240
+ const d = i.split(/\s+/).filter((f) => f.length > 0);
241
+ let s = 1, c = 0, u = 0;
242
+ for (const f of d) {
243
+ const x = g(f), S = c === 0 ? 0 : g(" ");
244
+ c > 0 && c + S + x > r ? (u = Math.max(u, c), s++, c = x) : c += S + x;
245
+ }
246
+ return u = Math.max(u, c), { width: u, height: s * p };
247
+ };
248
+ }
249
+ const kt = /* @__PURE__ */ new Set([
250
+ "box-shadow",
251
+ "filter",
252
+ "backdrop-filter",
253
+ "mix-blend-mode",
254
+ "background-blend-mode",
255
+ "clip-path",
256
+ "mask",
257
+ "outline",
258
+ "line-height",
259
+ "text-transform",
260
+ "text-decoration",
261
+ "z-index",
262
+ "float",
263
+ "clear",
264
+ "border-style"
265
+ ]), St = /* @__PURE__ */ new Set([
266
+ "gap",
267
+ "row-gap",
268
+ "column-gap",
269
+ "aspect-ratio",
270
+ "background-size",
271
+ "background-position",
272
+ "background-repeat",
273
+ "overflow-wrap",
274
+ "word-break"
275
+ ]), q = ["top", "right", "bottom", "left"], yt = {
276
+ normal: { weight: "normal", style: "normal" },
277
+ bold: { weight: "bold", style: "normal" },
278
+ italic: { weight: "normal", style: "italic" },
279
+ "bold-and-italic": { weight: "bold", style: "italic" }
280
+ }, $t = {
281
+ upper: "flex-start",
282
+ middle: "center",
283
+ lower: "flex-end"
284
+ }, Tt = {
285
+ left: "flex-start",
286
+ center: "center",
287
+ right: "flex-end"
288
+ };
289
+ function Ot(t) {
290
+ const n = /^(?:url|resource)\(\s*(["']?)(.*?)\1\s*\)$/.exec(t.trim());
291
+ return n === null ? null : n[2];
292
+ }
293
+ function Et(t, n, e = {}) {
294
+ var S;
295
+ const i = {}, l = [], r = (m) => {
296
+ var $;
297
+ return ($ = t.get(m)) == null ? void 0 : $.value;
298
+ }, p = (m, $) => {
299
+ l.push({ kind: m, message: $, node: n });
300
+ };
301
+ i["box-sizing"] = "border-box";
302
+ for (const [m] of t)
303
+ kt.has(m) ? p("unsupported-property", `${m} does not exist in USS and is ignored`) : St.has(m) && p(
304
+ "version-dependent",
305
+ `${m} depends on the Unity version; verify it in your project`
306
+ );
307
+ const g = [
308
+ "background-color",
309
+ "color",
310
+ "opacity",
311
+ "visibility",
312
+ "letter-spacing",
313
+ "word-spacing",
314
+ "white-space",
315
+ "text-overflow",
316
+ "cursor",
317
+ "font-size",
318
+ "transform-origin"
319
+ ];
320
+ for (const m of g) {
321
+ const $ = r(m);
322
+ $ !== void 0 && (i[m] = $);
323
+ }
324
+ r("display") === "none" && (i.display = "none"), r("overflow") === "hidden" && (i.overflow = "hidden");
325
+ for (const m of q) {
326
+ const $ = r(`border-${m}-width`);
327
+ if ($ !== void 0 && $ !== "0") {
328
+ const { length: a, problem: o } = P($);
329
+ a === null || a.kind !== "px" ? p(
330
+ "unsupported-property",
331
+ `border-${m}-width: ${o ?? `"${$}" is not a pixel length`}; ignored`
332
+ ) : (i[`border-${m}-width`] = `${a.value}px`, i[`border-${m}-style`] = "solid");
333
+ }
334
+ const k = r(`border-${m}-color`);
335
+ k !== void 0 && (i[`border-${m}-color`] = k);
336
+ const w = r(`padding-${m}`);
337
+ w !== void 0 && w !== "0" && (i[`padding-${m}`] = w);
338
+ }
339
+ for (const m of [
340
+ "top-left",
341
+ "top-right",
342
+ "bottom-right",
343
+ "bottom-left"
344
+ ]) {
345
+ const $ = r(`border-${m}-radius`);
346
+ $ !== void 0 && (i[`border-${m}-radius`] = $);
347
+ }
348
+ const b = r("-unity-font-style");
349
+ if (b !== void 0) {
350
+ const m = yt[b];
351
+ m === void 0 ? p("unsupported-property", `-unity-font-style: ${b} is not a USS value`) : (i["font-weight"] = m.weight, i["font-style"] = m.style);
352
+ }
353
+ const d = r("-unity-text-align");
354
+ if (d !== void 0) {
355
+ const [m, $] = d.split("-"), k = $t[m ?? ""], w = Tt[$ ?? ""];
356
+ k === void 0 || w === void 0 ? p("unsupported-property", `-unity-text-align: ${d} is not a USS value`) : (i["align-items"] = k, i["justify-content"] = w);
357
+ }
358
+ const s = [], c = r("translate");
359
+ c !== void 0 && s.push(`translate(${c.replace(/\s+/, ", ")})`);
360
+ const u = r("rotate");
361
+ u !== void 0 && s.push(`rotate(${u})`);
362
+ const f = r("scale");
363
+ f !== void 0 && s.push(`scale(${f.replace(/\s+/, ", ")})`), s.length > 0 && (i.transform = s.join(" "));
364
+ const x = r("background-image");
365
+ if (x !== void 0 && x !== "none") {
366
+ const m = Ot(x);
367
+ if (m === null)
368
+ p("asset-unresolved", `background-image: cannot read "${x}" as an asset path`);
369
+ else {
370
+ const $ = ((S = e.resolveAsset) == null ? void 0 : S.call(e, m)) ?? null;
371
+ $ === null ? (i["background-image"] = "repeating-linear-gradient(45deg, rgba(255,0,255,0.35) 0 6px, rgba(0,0,0,0) 6px 12px)", p("asset-unresolved", `background-image: "${m}" was not resolved`)) : (i["background-image"] = `url("${$}")`, i["background-size"] = r("background-size") ?? "contain", i["background-repeat"] = r("background-repeat") ?? "no-repeat", i["background-position"] = r("background-position") ?? "center");
372
+ }
373
+ }
374
+ return r("-unity-background-image-tint-color") !== void 0 && p(
375
+ "unsupported-property",
376
+ "-unity-background-image-tint-color has no CSS equivalent and is not drawn"
377
+ ), q.some((m) => r(`-unity-slice-${m}`) !== void 0) && p("unsupported-property", "-unity-slice-* (9-slice) is not drawn in this preview"), r("-unity-font-definition") !== void 0 && p(
378
+ "unsupported-property",
379
+ "-unity-font-definition names a Unity font asset; the browser default is used"
380
+ ), { declarations: i, warnings: l };
381
+ }
382
+ const Nt = "data-uxml-node";
383
+ function It(t, n, e, i, l) {
384
+ const r = [], p = /* @__PURE__ */ new Map();
385
+ function g(s) {
386
+ const c = e.get(s.id), u = (f) => {
387
+ var m;
388
+ const x = ((m = c == null ? void 0 : c.get(f)) == null ? void 0 : m.value) ?? Q[f] ?? "0", { length: S } = P(x);
389
+ return S !== null && S.kind === "px" ? S.value : 0;
390
+ };
391
+ return { left: u("border-left-width"), top: u("border-top-width") };
392
+ }
393
+ function b(s, c, u) {
394
+ var h;
395
+ const f = n.get(s.id);
396
+ if (f === void 0) return null;
397
+ const x = l.document.createElement("div");
398
+ x.setAttribute(Nt, String(s.id));
399
+ const S = e.get(s.id) ?? /* @__PURE__ */ new Map(), m = Et(S, s.id, l);
400
+ r.push(...m.warnings);
401
+ const $ = c === null ? 0 : f.left - c.left - u.left, k = c === null ? 0 : f.top - c.top - u.top, w = {
402
+ position: "absolute",
403
+ left: `${$}px`,
404
+ top: `${k}px`,
405
+ width: `${f.width}px`,
406
+ height: `${f.height}px`,
407
+ margin: "0",
408
+ ...m.declarations
409
+ };
410
+ for (const [v, y] of Object.entries(w))
411
+ x.style.setProperty(v, y);
412
+ const a = U(s), o = (h = s.attributes.find((v) => v.name === "text")) == null ? void 0 : h.value;
413
+ if ((a == null ? void 0 : a.hasText) === !0 && o !== void 0 && o.length > 0)
414
+ x.style.setProperty("display", m.declarations.display ?? "flex"), m.declarations["align-items"] === void 0 && x.style.setProperty("align-items", "flex-start"), m.declarations["justify-content"] === void 0 && x.style.setProperty("justify-content", "flex-start"), x.textContent = Ct(o);
415
+ else {
416
+ const v = g(s);
417
+ for (const y of s.children) {
418
+ const T = b(y, f, v);
419
+ T !== null && x.appendChild(T);
420
+ }
421
+ }
422
+ return p.set(s.id, x), x;
423
+ }
424
+ i.replaceChildren();
425
+ const d = b(t, null, { left: 0, top: 0 });
426
+ return d !== null && (d.style.setProperty("position", "relative"), i.appendChild(d)), { warnings: r, elements: p };
427
+ }
428
+ function Ct(t) {
429
+ const n = (e, i) => !Number.isInteger(e) || e < 0 || e > 1114111 || e >= 55296 && e <= 57343 ? i : String.fromCodePoint(e);
430
+ return t.replace(/&#x([0-9a-f]+);/gi, (e, i) => n(parseInt(i, 16), e)).replace(/&#(\d+);/g, (e, i) => n(Number(i), e)).replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
431
+ }
432
+ const V = /[A-Za-z0-9_-]/;
433
+ function C(t) {
434
+ return t === " " || t === " " || t === `
435
+ ` || t === "\r" || t === "\f";
436
+ }
437
+ function F(t, n, e) {
438
+ let i = n, l = 0;
439
+ for (; i < t.length; ) {
440
+ const r = t[i];
441
+ if (r === '"' || r === "'") {
442
+ const p = t.indexOf(r, i + 1);
443
+ i = p < 0 ? t.length : p + 1;
444
+ continue;
445
+ }
446
+ if (r === "/" && t[i + 1] === "*") {
447
+ const p = t.indexOf("*/", i + 2);
448
+ i = p < 0 ? t.length : p + 2;
449
+ continue;
450
+ }
451
+ if (r === "(" || r === "[")
452
+ l++;
453
+ else if (r === ")" || r === "]")
454
+ l > 0 && l--;
455
+ else if (l === 0 && e.includes(r))
456
+ return i;
457
+ i++;
458
+ }
459
+ return t.length;
460
+ }
461
+ function tt(t, n, e) {
462
+ let i = n, l = e;
463
+ for (; i < l && C(t[i]); ) i++;
464
+ for (; l > i && C(t[l - 1]); ) l--;
465
+ return { start: i, end: l };
466
+ }
467
+ function et(t, n, e, i) {
468
+ const l = [];
469
+ let r = n;
470
+ for (; r < e; ) {
471
+ for (; r < e && (C(t[r]) || t.startsWith("/*", r)); )
472
+ if (t.startsWith("/*", r)) {
473
+ const s = t.indexOf("*/", r + 2);
474
+ r = s < 0 ? e : s + 2;
475
+ } else
476
+ r++;
477
+ if (r >= e) break;
478
+ if (t[r] === ";") {
479
+ r++;
480
+ continue;
481
+ }
482
+ const p = r, g = F(t, p, ":;}");
483
+ if (g >= e || t[g] !== ":") {
484
+ const s = Math.min(g, e);
485
+ i == null || i("declaration without a value", p, s), r = s + 1;
486
+ continue;
487
+ }
488
+ const b = Math.min(F(t, g + 1, ";}"), e), d = tt(t, g + 1, b);
489
+ l.push({
490
+ property: t.slice(p, g).trim(),
491
+ value: t.slice(d.start, d.end),
492
+ span: { start: p, end: d.end },
493
+ dirty: !1
494
+ }), r = b + 1;
495
+ }
496
+ return l;
497
+ }
498
+ function Dt(t) {
499
+ const n = t.span.end - 1 - t.value.length;
500
+ return n < t.span.start ? null : n;
501
+ }
502
+ function Mt(t, n = null, e = 0) {
503
+ const i = [], l = [];
504
+ let r = 0;
505
+ function p(k, w, a) {
506
+ i.push({
507
+ kind: "malformed",
508
+ message: k,
509
+ at: { in: "uss", sheet: e, span: { start: w, end: a } }
510
+ });
511
+ }
512
+ function g() {
513
+ for (; ; ) {
514
+ for (; C(t[r]); ) r++;
515
+ if (t.startsWith("/*", r)) {
516
+ const k = t.indexOf("*/", r + 2);
517
+ r = k < 0 ? t.length : k + 2;
518
+ continue;
519
+ }
520
+ return;
521
+ }
522
+ }
523
+ const b = (k, w) => F(t, k, w), d = (k, w) => tt(t, k, w);
524
+ function s(k) {
525
+ let w = k + 1, a = 1;
526
+ for (; w < t.length; ) {
527
+ const o = t[w];
528
+ if (o === '"' || o === "'") {
529
+ const h = t.indexOf(o, w + 1);
530
+ w = h < 0 ? t.length : h + 1;
531
+ continue;
532
+ }
533
+ if (o === "/" && t[w + 1] === "*") {
534
+ const h = t.indexOf("*/", w + 2);
535
+ w = h < 0 ? t.length : h + 2;
536
+ continue;
537
+ }
538
+ if (o === "{") a++;
539
+ else if (o === "}" && --a === 0) return w + 1;
540
+ w++;
541
+ }
542
+ return t.length;
543
+ }
544
+ function c(k) {
545
+ let w = k;
546
+ for (; w < t.length && V.test(t[w]); ) w++;
547
+ return w;
548
+ }
549
+ function u(k) {
550
+ const w = t[k], a = w === "(" ? ")" : "]";
551
+ let o = k + 1, h = 1;
552
+ for (; o < t.length; ) {
553
+ const v = t[o];
554
+ if (v === '"' || v === "'") {
555
+ const y = t.indexOf(v, o + 1);
556
+ o = y < 0 ? t.length : y + 1;
557
+ continue;
558
+ }
559
+ if (v === w) h++;
560
+ else if (v === a && --h === 0) return o + 1;
561
+ o++;
562
+ }
563
+ return t.length;
564
+ }
565
+ function f(k, w) {
566
+ const a = [];
567
+ let o = k;
568
+ for (; o < w; ) {
569
+ const h = t[o];
570
+ if (C(h) || h === ">" || h === "+" || h === "~" || h === ",") break;
571
+ if (h === "*")
572
+ a.push({ kind: "universal" }), o++;
573
+ else if (h === "." || h === "#") {
574
+ const v = c(o + 1);
575
+ a.push(
576
+ h === "." ? { kind: "class", name: t.slice(o + 1, v) } : { kind: "name", name: t.slice(o + 1, v) }
577
+ ), o = v;
578
+ } else if (h === "[") {
579
+ const v = Math.min(u(o), w);
580
+ a.push({ kind: "unknown", text: t.slice(o, v) }), o = v;
581
+ } else if (h === ":")
582
+ if (t[o + 1] === ":") {
583
+ const v = c(o + 2);
584
+ a.push({ kind: "unknown", text: t.slice(o, v) }), o = v;
585
+ } else {
586
+ const v = c(o + 1);
587
+ if (t[v] === "(") {
588
+ const y = Math.min(u(v), w);
589
+ a.push({ kind: "unknown", text: t.slice(o, y) }), o = y;
590
+ } else
591
+ a.push({ kind: "pseudo", name: t.slice(o + 1, v) }), o = v;
592
+ }
593
+ else if (V.test(h)) {
594
+ const v = c(o);
595
+ a.push({ kind: "type", name: t.slice(o, v) }), o = v;
596
+ } else
597
+ a.push({ kind: "unknown", text: h }), o++;
598
+ }
599
+ return { simple: a, next: o };
600
+ }
601
+ function x(k, w) {
602
+ const a = d(k, w), o = [];
603
+ let h = "descendant", v = null, y = a.start;
604
+ for (; y < a.end; ) {
605
+ const T = t[y];
606
+ if (C(T)) {
607
+ y++;
608
+ continue;
609
+ }
610
+ if (T === ">") {
611
+ h = "child", y++;
612
+ continue;
613
+ }
614
+ if (T === "+" || T === "~") {
615
+ v = T, y++;
616
+ continue;
617
+ }
618
+ const { simple: N, next: O } = f(y, a.end);
619
+ if (O === y) {
620
+ y++;
621
+ continue;
622
+ }
623
+ v !== null && (N.unshift({ kind: "unknown", text: v }), v = null), o.push({ combinator: h, simple: N }), h = "descendant", y = O;
624
+ }
625
+ return { parts: o, span: a };
626
+ }
627
+ function S(k, w) {
628
+ const a = [];
629
+ let o = k;
630
+ for (; ; ) {
631
+ const h = Math.min(b(o, ","), w);
632
+ if (a.push(x(o, h)), h >= w) break;
633
+ o = h + 1;
634
+ }
635
+ return a;
636
+ }
637
+ function m() {
638
+ const k = r, w = c(r + 1), a = t.slice(r + 1, w), o = b(w, "{;");
639
+ if (o < t.length && t[o] === "{") {
640
+ const v = s(o);
641
+ return r = v, { kind: "unknown", span: { start: k, end: v } };
642
+ }
643
+ const h = o < t.length ? o + 1 : t.length;
644
+ if (r = h, a === "import") {
645
+ const v = t.slice(w, h), y = /["']([^"']*)["']/.exec(v);
646
+ return y === null ? (p("@import without a quoted path", k, h), { kind: "unknown", span: { start: k, end: h } }) : { kind: "import", url: y[1], span: { start: k, end: h } };
647
+ }
648
+ return { kind: "unknown", span: { start: k, end: h } };
649
+ }
650
+ function $() {
651
+ const k = r, w = b(k, "{");
652
+ if (w >= t.length)
653
+ return p("rule without a block", k, t.length), r = t.length, { kind: "unknown", span: { start: k, end: t.length } };
654
+ const a = d(k, w), o = s(w);
655
+ (o > t.length || t[o - 1] !== "}") && p("unterminated rule block", k, o);
656
+ const h = {
657
+ selectors: S(a.start, a.end),
658
+ declarations: et(t, w + 1, o - 1, p),
659
+ span: { start: a.start, end: o },
660
+ selectorSpan: a,
661
+ selectorDirty: !1,
662
+ declarationsDirty: !1
663
+ };
664
+ return r = o, { kind: "rule", rule: h };
665
+ }
666
+ for (; g(), !(r >= t.length); )
667
+ l.push(t[r] === "@" ? m() : $());
668
+ return { sheet: { source: t, origin: n, items: l }, warnings: i };
669
+ }
670
+ const At = /* @__PURE__ */ new Set([
671
+ "color",
672
+ "font-size",
673
+ "letter-spacing",
674
+ "word-spacing",
675
+ "visibility",
676
+ "white-space",
677
+ "-unity-font",
678
+ "-unity-font-definition",
679
+ "-unity-font-style",
680
+ "-unity-paragraph-spacing",
681
+ "-unity-text-align",
682
+ "-unity-text-outline-color",
683
+ "-unity-text-outline-width"
684
+ ]);
685
+ function zt(t) {
686
+ return t.startsWith("--") || At.has(t);
687
+ }
688
+ function G(t) {
689
+ const n = [];
690
+ let e = 0, i = -1;
691
+ for (let l = 0; l < t.length; l++) {
692
+ const r = t[l];
693
+ r === "(" ? e++ : r === ")" && (e = Math.max(0, e - 1)), e === 0 && /\s/.test(r) ? i >= 0 && (n.push(t.slice(i, l)), i = -1) : i < 0 && (i = l);
694
+ }
695
+ return i >= 0 && n.push(t.slice(i)), n;
696
+ }
697
+ function Rt(t) {
698
+ const [n, e, i, l] = t;
699
+ return n === void 0 ? null : e === void 0 ? [n, n, n, n] : i === void 0 ? [n, e, n, e] : l === void 0 ? [n, e, i, e] : [n, e, i, l];
700
+ }
701
+ const Ut = {
702
+ margin: ["margin-top", "margin-right", "margin-bottom", "margin-left"],
703
+ padding: ["padding-top", "padding-right", "padding-bottom", "padding-left"],
704
+ "border-width": [
705
+ "border-top-width",
706
+ "border-right-width",
707
+ "border-bottom-width",
708
+ "border-left-width"
709
+ ],
710
+ "border-color": [
711
+ "border-top-color",
712
+ "border-right-color",
713
+ "border-bottom-color",
714
+ "border-left-color"
715
+ ],
716
+ // Radii run clockwise from the top-left corner, not top/right/bottom/left.
717
+ "border-radius": [
718
+ "border-top-left-radius",
719
+ "border-top-right-radius",
720
+ "border-bottom-right-radius",
721
+ "border-bottom-left-radius"
722
+ ]
723
+ };
724
+ function Y(t) {
725
+ return /^-?(\d+\.?\d*|\.\d+)$/.test(t);
726
+ }
727
+ function Wt(t) {
728
+ const [n, e, i] = t;
729
+ return n === void 0 ? [] : n === "none" ? [["flex-grow", "0"], ["flex-shrink", "0"], ["flex-basis", "auto"]] : n === "auto" ? [["flex-grow", "1"], ["flex-shrink", "1"], ["flex-basis", "auto"]] : e === void 0 ? Y(n) ? [["flex-grow", n], ["flex-shrink", "1"], ["flex-basis", "0"]] : [["flex-grow", "1"], ["flex-shrink", "1"], ["flex-basis", n]] : i === void 0 ? Y(e) ? [["flex-grow", n], ["flex-shrink", e], ["flex-basis", "0"]] : [["flex-grow", n], ["flex-shrink", "1"], ["flex-basis", e]] : [["flex-grow", n], ["flex-shrink", e], ["flex-basis", i]];
730
+ }
731
+ function Z(t, n) {
732
+ if (t === "flex") return Wt(G(n));
733
+ const e = Ut[t];
734
+ if (e === void 0) return [[t, n]];
735
+ const i = Rt(G(n));
736
+ return i === null ? [[t, n]] : e.map((l, r) => [l, i[r]]);
737
+ }
738
+ function Ft(t) {
739
+ var e;
740
+ const n = (e = t.attributes.find((i) => i.name === "class")) == null ? void 0 : e.value;
741
+ return n === void 0 ? [] : n.split(/\s+/).filter((i) => i.length > 0);
742
+ }
743
+ function Lt(t) {
744
+ var n;
745
+ return (n = t.attributes.find((e) => e.name === "name")) == null ? void 0 : n.value;
746
+ }
747
+ function jt(t, n, e) {
748
+ switch (t.kind) {
749
+ case "universal":
750
+ return !0;
751
+ case "type":
752
+ return n.name.local === t.name;
753
+ case "class":
754
+ return Ft(n).includes(t.name);
755
+ case "name":
756
+ return Lt(n) === t.name;
757
+ case "pseudo":
758
+ return t.name === "root" ? n === e.root : e.activeStates.has(t.name);
759
+ case "unknown":
760
+ return !1;
761
+ }
762
+ }
763
+ function Pt(t, n, e) {
764
+ return t.simple.every((i) => jt(i, n, e));
765
+ }
766
+ function L(t, n, e, i) {
767
+ if (!Pt(t[n], e, i)) return !1;
768
+ if (n === 0) return !0;
769
+ const l = i.parentOf(e);
770
+ if (t[n].combinator === "child")
771
+ return l !== null && L(t, n - 1, l, i);
772
+ for (let r = l; r !== null; r = i.parentOf(r))
773
+ if (L(t, n - 1, r, i)) return !0;
774
+ return !1;
775
+ }
776
+ function _t(t, n, e) {
777
+ return t.parts.length === 0 ? !1 : L(t.parts, t.parts.length - 1, n, e);
778
+ }
779
+ function Ht(t) {
780
+ for (const n of t)
781
+ for (const e of n.parts)
782
+ for (const i of e.simple)
783
+ if (i.kind === "unknown") return i.text;
784
+ return null;
785
+ }
786
+ function Bt(t) {
787
+ const n = /* @__PURE__ */ new Map([[t, null]]), e = [t];
788
+ for (; e.length > 0; ) {
789
+ const i = e.pop();
790
+ for (const l of i.children)
791
+ n.set(l, i), e.push(l);
792
+ }
793
+ return n;
794
+ }
795
+ function qt(t) {
796
+ let n = 0, e = 0, i = 0;
797
+ for (const l of t.parts)
798
+ for (const r of l.simple)
799
+ switch (r.kind) {
800
+ case "name":
801
+ n++;
802
+ break;
803
+ case "class":
804
+ case "pseudo":
805
+ e++;
806
+ break;
807
+ case "type":
808
+ i++;
809
+ break;
810
+ }
811
+ return [n, e, i];
812
+ }
813
+ function nt(t, n) {
814
+ return t[0] - n[0] || t[1] - n[1] || t[2] - n[2];
815
+ }
816
+ const Vt = [Number.MAX_SAFE_INTEGER, 0, 0];
817
+ function Gt(t) {
818
+ const n = [], e = /* @__PURE__ */ new Map();
819
+ t.sheets.forEach((r, p) => {
820
+ r.origin !== null && !e.has(r.origin) && e.set(r.origin, p);
821
+ });
822
+ const i = /* @__PURE__ */ new Set(), l = (r) => {
823
+ if (i.has(r)) return;
824
+ i.add(r);
825
+ const p = t.sheets[r];
826
+ p !== void 0 && p.items.forEach((g, b) => {
827
+ if (g.kind === "rule")
828
+ n.push({ rule: g.rule, sheet: r, item: b });
829
+ else if (g.kind === "import") {
830
+ const d = e.get(g.url);
831
+ d !== void 0 && l(d);
832
+ }
833
+ });
834
+ };
835
+ return l(0), n;
836
+ }
837
+ function Yt(t) {
838
+ return t.selectors.some(
839
+ (n) => n.parts.some((e) => e.simple.some((i) => i.kind === "pseudo" && i.name === "root"))
840
+ );
841
+ }
842
+ function it(t, n) {
843
+ const e = Bt(t.root), i = {
844
+ parentOf: (g) => e.get(g) ?? null,
845
+ root: t.root,
846
+ activeStates: (n == null ? void 0 : n.activeStates) ?? /* @__PURE__ */ new Set()
847
+ }, l = [], r = [];
848
+ let p = !1;
849
+ for (const g of Gt(t)) {
850
+ const b = Ht(g.rule.selectors);
851
+ if (b !== null) {
852
+ l.push({
853
+ kind: "unsupported-selector",
854
+ message: `"${b}" is not supported in USS; the whole rule is ignored`,
855
+ at: { in: "uss", sheet: g.sheet, span: g.rule.selectorSpan }
856
+ });
857
+ continue;
858
+ }
859
+ !p && Yt(g.rule) && (p = !0, l.push({
860
+ kind: "version-dependent",
861
+ message: ":root in USS names the element the stylesheet was applied to, not the document root as in CSS. This preview matches it against the <ui:UXML> element; verify against your Unity version.",
862
+ at: { in: "uss", sheet: g.sheet, span: g.rule.selectorSpan }
863
+ })), r.push(g);
864
+ }
865
+ return { ctx: i, usable: r, warnings: l };
866
+ }
867
+ function Zt(t, n) {
868
+ const e = n.attributes.find((l) => l.name === "style");
869
+ if (e === void 0) return [];
870
+ const i = Dt(e);
871
+ return i === null ? [] : et(t.source, i, i + e.value.length);
872
+ }
873
+ function rt(t, n, e) {
874
+ const i = [];
875
+ let l = 0;
876
+ const r = (p, g, b, d) => {
877
+ i.push({ property: p, value: g, origin: b, specificity: d, order: l++, winner: !1 });
878
+ };
879
+ for (const p of e.usable) {
880
+ let g = null;
881
+ for (const b of p.rule.selectors) {
882
+ if (!_t(b, n, e.ctx)) continue;
883
+ const d = qt(b);
884
+ (g === null || nt(d, g) > 0) && (g = d);
885
+ }
886
+ g !== null && p.rule.declarations.forEach((b, d) => {
887
+ for (const [s, c] of Z(b.property, b.value))
888
+ r(s, c, { kind: "rule", sheet: p.sheet, item: p.item, declIndex: d }, g);
889
+ });
890
+ }
891
+ return Zt(t, n).forEach((p, g) => {
892
+ for (const [b, d] of Z(p.property, p.value))
893
+ r(b, d, { kind: "inline", node: n.id, declIndex: g }, Vt);
894
+ }), i;
895
+ }
896
+ function st(t) {
897
+ const n = /* @__PURE__ */ new Map();
898
+ for (const e of t) {
899
+ const i = n.get(e.property);
900
+ if (i === void 0) {
901
+ n.set(e.property, e);
902
+ continue;
903
+ }
904
+ const l = nt(e.specificity, i.specificity);
905
+ (l > 0 || l === 0 && e.order > i.order) && n.set(e.property, e);
906
+ }
907
+ for (const e of n.values()) e.winner = !0;
908
+ return n;
909
+ }
910
+ const Jt = /var\(\s*(--[^,)\s]+)\s*(?:,([^)]*))?\)/;
911
+ function j(t, n, e = /* @__PURE__ */ new Set()) {
912
+ var l;
913
+ let i = t;
914
+ for (let r = 0; r < 32; r++) {
915
+ const p = Jt.exec(i);
916
+ if (p === null) return i;
917
+ const g = p[1], b = (l = p[2]) == null ? void 0 : l.trim();
918
+ if (e.has(g)) return null;
919
+ const d = /* @__PURE__ */ new Set([...e, g]), s = n.get(g), c = s !== void 0 ? j(s, n, d) : b !== void 0 && b.length > 0 ? j(b, n, d) : null;
920
+ if (c === null) return null;
921
+ i = i.slice(0, p.index) + c + i.slice(p.index + p[0].length);
922
+ }
923
+ return null;
924
+ }
925
+ function Xt(t, n) {
926
+ const e = it(t, n), i = [...e.warnings], l = /* @__PURE__ */ new Map(), r = (p, g) => {
927
+ const b = st(rt(t, p, e)), d = /* @__PURE__ */ new Map();
928
+ for (const [u, f] of g)
929
+ u.startsWith("--") && d.set(u, f.value);
930
+ for (const [u, f] of b)
931
+ u.startsWith("--") && d.set(u, f.value);
932
+ const s = /* @__PURE__ */ new Map();
933
+ for (const [u, f] of g) s.set(u, f);
934
+ for (const [u, f] of b) {
935
+ const x = j(f.value, d);
936
+ if (x === null) {
937
+ i.push({
938
+ kind: "unsupported-property",
939
+ message: `${u}: var() reference could not be resolved; declaration dropped`,
940
+ node: p.id
941
+ });
942
+ continue;
943
+ }
944
+ s.set(u, { value: x, origin: f.origin });
945
+ }
946
+ l.set(p.id, s);
947
+ const c = /* @__PURE__ */ new Map();
948
+ for (const [u, f] of s)
949
+ zt(u) && c.set(u, {
950
+ value: f.value,
951
+ origin: { kind: "inherited", from: p.id, origin: f.origin }
952
+ });
953
+ for (const u of p.children) r(u, c);
954
+ };
955
+ return r(t.root, /* @__PURE__ */ new Map()), { styles: l, warnings: i };
956
+ }
957
+ function ae(t, n, e, i) {
958
+ const l = it(t, i), r = rt(t, n, l).filter(
959
+ (p) => p.property === e
960
+ );
961
+ return st(r), r;
962
+ }
963
+ function J(t) {
964
+ return t !== void 0 && /[A-Za-z0-9_.:-]/.test(t);
965
+ }
966
+ function X(t) {
967
+ return t !== void 0 && /[A-Za-z_]/.test(t);
968
+ }
969
+ function Kt(t) {
970
+ return t === " " || t === " " || t === `
971
+ ` || t === "\r";
972
+ }
973
+ function Qt(t) {
974
+ const n = [];
975
+ let e = 0, i = 0;
976
+ const l = () => i++;
977
+ function r(c, u, f) {
978
+ n.push({
979
+ kind: "malformed",
980
+ message: c,
981
+ at: { in: "uxml", span: { start: u, end: f } }
982
+ });
983
+ }
984
+ function p() {
985
+ for (; Kt(t[e]); ) e++;
986
+ }
987
+ function g() {
988
+ for (; ; ) {
989
+ const c = t.indexOf("<", e);
990
+ if (c < 0) {
991
+ e = t.length;
992
+ return;
993
+ }
994
+ const u = t[c + 1];
995
+ if (u === "!") {
996
+ if (t.startsWith("<!--", c)) {
997
+ const f = t.indexOf("-->", c + 4);
998
+ e = f < 0 ? t.length : f + 3;
999
+ } else if (t.startsWith("<![CDATA[", c)) {
1000
+ const f = t.indexOf("]]>", c + 9);
1001
+ e = f < 0 ? t.length : f + 3;
1002
+ } else {
1003
+ const f = t.indexOf(">", c);
1004
+ e = f < 0 ? t.length : f + 1;
1005
+ }
1006
+ continue;
1007
+ }
1008
+ if (u === "?") {
1009
+ const f = t.indexOf("?>", c + 2);
1010
+ e = f < 0 ? t.length : f + 2;
1011
+ continue;
1012
+ }
1013
+ e = c;
1014
+ return;
1015
+ }
1016
+ }
1017
+ function b() {
1018
+ const c = e;
1019
+ for (; J(t[e]); ) e++;
1020
+ const u = t.slice(c, e), f = u.indexOf(":");
1021
+ return f < 0 ? { prefix: null, local: u } : { prefix: u.slice(0, f), local: u.slice(f + 1) };
1022
+ }
1023
+ function d() {
1024
+ const c = e;
1025
+ for (; J(t[e]); ) e++;
1026
+ if (e === c) return null;
1027
+ const u = t.slice(c, e), f = e;
1028
+ if (p(), t[e] !== "=")
1029
+ return e = f, r(`attribute "${u}" has no value`, c, f), { name: u, value: "", span: { start: c, end: f } };
1030
+ e++, p();
1031
+ const x = t[e];
1032
+ if (x !== '"' && x !== "'")
1033
+ return r(`attribute "${u}" has an unquoted value`, c, e), { name: u, value: "", span: { start: c, end: e } };
1034
+ e++;
1035
+ const S = e, m = t.indexOf(x, e);
1036
+ return m < 0 ? (r(`attribute "${u}" has an unterminated value`, c, t.length), e = t.length, { name: u, value: t.slice(S), span: { start: c, end: e } }) : (e = m + 1, { name: u, value: t.slice(S, m), span: { start: c, end: e } });
1037
+ }
1038
+ function s() {
1039
+ const c = e;
1040
+ e++;
1041
+ const u = b(), f = [];
1042
+ let x = !1;
1043
+ for (; ; ) {
1044
+ p();
1045
+ const a = t[e];
1046
+ if (a === void 0) {
1047
+ r("unterminated open tag", c, t.length);
1048
+ break;
1049
+ }
1050
+ if (a === ">") {
1051
+ e++;
1052
+ break;
1053
+ }
1054
+ if (a === "/" && t[e + 1] === ">") {
1055
+ e += 2, x = !0;
1056
+ break;
1057
+ }
1058
+ const o = d();
1059
+ if (o === null) {
1060
+ e++;
1061
+ continue;
1062
+ }
1063
+ f.push(o);
1064
+ }
1065
+ const S = { start: c, end: e };
1066
+ if (x)
1067
+ return {
1068
+ id: l(),
1069
+ name: u,
1070
+ attributes: f,
1071
+ children: [],
1072
+ spans: { openTag: S, inner: { start: e, end: e }, closeTag: null },
1073
+ tagDirty: !1,
1074
+ childrenDirty: !1
1075
+ };
1076
+ const m = e, $ = [];
1077
+ for (; ; ) {
1078
+ if (g(), e >= t.length) {
1079
+ r(`unterminated element <${ot(u)}>`, c, t.length);
1080
+ break;
1081
+ }
1082
+ const a = t[e + 1];
1083
+ if (a === "/") break;
1084
+ if (!X(a)) {
1085
+ e++;
1086
+ continue;
1087
+ }
1088
+ $.push(s());
1089
+ }
1090
+ const k = e;
1091
+ let w = null;
1092
+ if (t.startsWith("</", e)) {
1093
+ const a = t.indexOf(">", e), o = a < 0 ? t.length : a + 1;
1094
+ a < 0 && r("unterminated end tag", e, o), w = { start: e, end: o }, e = o;
1095
+ }
1096
+ return {
1097
+ id: l(),
1098
+ name: u,
1099
+ attributes: f,
1100
+ children: $,
1101
+ spans: { openTag: S, inner: { start: m, end: k }, closeTag: w },
1102
+ tagDirty: !1,
1103
+ childrenDirty: !1
1104
+ };
1105
+ }
1106
+ return g(), e < t.length && X(t[e + 1]) ? { root: s(), warnings: n } : (r("no root element", 0, 0), {
1107
+ root: {
1108
+ id: l(),
1109
+ name: { prefix: null, local: "" },
1110
+ attributes: [],
1111
+ children: [],
1112
+ spans: { openTag: { start: 0, end: 0 }, inner: { start: 0, end: 0 }, closeTag: null },
1113
+ tagDirty: !1,
1114
+ childrenDirty: !1
1115
+ },
1116
+ warnings: n
1117
+ });
1118
+ }
1119
+ function ot(t) {
1120
+ return t.prefix === null ? t.local : `${t.prefix}:${t.local}`;
1121
+ }
1122
+ function te(t, n) {
1123
+ const e = (d) => t.slice(d.start, d.end);
1124
+ function i(d) {
1125
+ return d.spans.closeTag !== null ? d.spans.closeTag.end : Math.max(d.spans.openTag.end, d.spans.inner.end);
1126
+ }
1127
+ function l(d) {
1128
+ return d.includes('"') ? d.includes("'") ? `"${d.replace(/"/g, "&quot;")}"` : `'${d}'` : `"${d}"`;
1129
+ }
1130
+ function r(d) {
1131
+ const s = d.attributes.map((u) => ` ${u.name}=${l(u.value)}`).join(""), c = ot(d.name);
1132
+ return d.spans.closeTag === null ? `<${c}${s} />` : `<${c}${s}>`;
1133
+ }
1134
+ function p(d) {
1135
+ var f, x;
1136
+ const s = e(d.spans.inner), c = ((f = /^[ \t]*\r?\n[ \t]*/.exec(s)) == null ? void 0 : f[0]) ?? "", u = ((x = /\r?\n[ \t]*$/.exec(s)) == null ? void 0 : x[0]) ?? "";
1137
+ return { between: c, before: c, after: u };
1138
+ }
1139
+ function g(d) {
1140
+ const { inner: s } = d.spans;
1141
+ if (d.children.length === 0) return e(s);
1142
+ if (d.childrenDirty) {
1143
+ const { between: f, before: x, after: S } = p(d);
1144
+ return x + d.children.map(b).join(f) + S;
1145
+ }
1146
+ let c = "", u = s.start;
1147
+ for (const f of d.children)
1148
+ c += t.slice(u, f.spans.openTag.start), c += b(f), u = i(f);
1149
+ return c + t.slice(u, s.end);
1150
+ }
1151
+ function b(d) {
1152
+ const s = d.tagDirty ? r(d) : e(d.spans.openTag), c = d.spans.closeTag === null ? "" : e(d.spans.closeTag);
1153
+ return s + g(d) + c;
1154
+ }
1155
+ return t.slice(0, n.spans.openTag.start) + b(n) + t.slice(i(n));
1156
+ }
1157
+ function ee(t) {
1158
+ const n = t.source, e = (s) => n.slice(s.start, s.end);
1159
+ function i(s) {
1160
+ return s.parts.map((c, u) => {
1161
+ const f = u === 0 ? "" : c.combinator === "child" ? " > " : " ", x = c.simple.map((S) => {
1162
+ switch (S.kind) {
1163
+ case "universal":
1164
+ return "*";
1165
+ case "type":
1166
+ return S.name;
1167
+ case "class":
1168
+ return `.${S.name}`;
1169
+ case "name":
1170
+ return `#${S.name}`;
1171
+ case "pseudo":
1172
+ return `:${S.name}`;
1173
+ case "unknown":
1174
+ return S.text;
1175
+ }
1176
+ }).join("");
1177
+ return f + x;
1178
+ }).join("");
1179
+ }
1180
+ function l(s) {
1181
+ var m, $;
1182
+ const c = s.declarations[0];
1183
+ if (c === void 0) return { between: "", before: "", after: "" };
1184
+ const u = n.lastIndexOf(`
1185
+ `, c.span.start), f = u < 0 ? "" : n.slice(u, c.span.start), x = n.slice(s.selectorSpan.end, s.span.end), S = (($ = (m = /\r?\n[ \t]*\}$/.exec(x)) == null ? void 0 : m[0]) == null ? void 0 : $.replace(/\}$/, "")) ?? "";
1186
+ return { between: `;${f}`, before: f, after: `;${S}` };
1187
+ }
1188
+ function r(s) {
1189
+ const c = s.selectorDirty ? s.selectors.map(i).join(", ") : e(s.selectorSpan);
1190
+ if (s.declarations.length === 0)
1191
+ return c + n.slice(s.selectorSpan.end, s.span.end);
1192
+ const u = n.slice(s.selectorSpan.end, s.declarations[0].span.start);
1193
+ if (s.declarationsDirty) {
1194
+ const { between: S, before: m, after: $ } = l(s), k = u.slice(0, u.indexOf("{") + 1), w = s.declarations.map(p).join(S);
1195
+ return `${c}${k}${m}${w}${$}}`;
1196
+ }
1197
+ let f = c, x = s.selectorSpan.end;
1198
+ for (const S of s.declarations)
1199
+ f += n.slice(x, S.span.start), f += p(S), x = S.span.end;
1200
+ return f + n.slice(x, s.span.end);
1201
+ }
1202
+ function p(s) {
1203
+ return s.dirty ? `${s.property}: ${s.value}` : e(s.span);
1204
+ }
1205
+ function g(s) {
1206
+ return s.kind === "rule" ? r(s.rule) : e(s.span);
1207
+ }
1208
+ let b = "", d = 0;
1209
+ for (const s of t.items) {
1210
+ const c = s.kind === "rule" ? s.rule.span : s.span;
1211
+ b += n.slice(d, c.start), b += g(s), d = c.end;
1212
+ }
1213
+ return b + n.slice(d);
1214
+ }
1215
+ function le(t, n, e) {
1216
+ var p;
1217
+ const i = Qt(t), l = [...i.warnings], r = [];
1218
+ if (n !== void 0) {
1219
+ const g = /* @__PURE__ */ new Set(), b = [
1220
+ { text: n, origin: null }
1221
+ ];
1222
+ for (; b.length > 0; ) {
1223
+ const d = b.shift(), s = r.length, c = Mt(d.text, d.origin, s);
1224
+ r.push(c.sheet), l.push(...c.warnings);
1225
+ for (const u of c.sheet.items) {
1226
+ if (u.kind !== "import" || g.has(u.url)) continue;
1227
+ g.add(u.url);
1228
+ const f = ((p = e == null ? void 0 : e.resolveImport) == null ? void 0 : p.call(e, u.url)) ?? null;
1229
+ if (f === null) {
1230
+ l.push({
1231
+ kind: "import-unresolved",
1232
+ message: (e == null ? void 0 : e.resolveImport) === void 0 ? `@import "${u.url}" was not loaded: pass resolveImport to read it` : `@import "${u.url}" could not be resolved`,
1233
+ at: { in: "uss", sheet: s, span: u.span }
1234
+ });
1235
+ continue;
1236
+ }
1237
+ b.push({ text: f, origin: u.url });
1238
+ }
1239
+ }
1240
+ }
1241
+ return { source: t, root: i.root, sheets: r, warnings: l };
1242
+ }
1243
+ function ce(t) {
1244
+ const n = t.sheets[0];
1245
+ return {
1246
+ uxml: te(t.source, t.root),
1247
+ // Only the sheet passed to `parse` round-trips. `@import`ed sheets (Phase 3)
1248
+ // are separate files and are not this function's to write.
1249
+ uss: n === void 0 ? "" : ee(n)
1250
+ };
1251
+ }
1252
+ function ue(t, n, e) {
1253
+ const i = n.ownerDocument, l = (e == null ? void 0 : e.size) ?? {
1254
+ width: n.clientWidth,
1255
+ height: n.clientHeight
1256
+ }, r = Xt(
1257
+ t,
1258
+ (e == null ? void 0 : e.activeStates) === void 0 ? void 0 : { activeStates: e.activeStates }
1259
+ ), p = (e == null ? void 0 : e.measureText) ?? vt(i), g = bt(t.root, r.styles, { size: l, measureText: p });
1260
+ let b;
1261
+ try {
1262
+ b = It(t.root, g.boxes, r.styles, n, {
1263
+ document: i,
1264
+ resolveAsset: e == null ? void 0 : e.resolveAsset
1265
+ });
1266
+ } catch (s) {
1267
+ throw g.dispose(), s;
1268
+ }
1269
+ let d = !1;
1270
+ return {
1271
+ warnings: [...r.warnings, ...g.warnings, ...b.warnings],
1272
+ elements: b.elements,
1273
+ boxes: g.boxes,
1274
+ dispose() {
1275
+ d || (d = !0, g.dispose(), n.replaceChildren());
1276
+ }
1277
+ };
1278
+ }
1279
+ export {
1280
+ Nt as NODE_ATTRIBUTE,
1281
+ vt as createDefaultMeasureText,
1282
+ ae as explainProperty,
1283
+ zt as isInherited,
1284
+ se as isLayoutEngineReady,
1285
+ oe as liveNodeCount,
1286
+ re as loadLayoutEngine,
1287
+ le as parse,
1288
+ ue as render,
1289
+ Xt as resolveStyles,
1290
+ ce as serialize,
1291
+ ie as supportedControlNames
1292
+ };