uxml-preview 0.1.0 → 0.3.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 CHANGED
@@ -1,16 +1,140 @@
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 }
1
+ import { loadYoga as Me, PositionType as Z, Direction as le, Edge as P, BoxSizing as Re, FlexDirection as V, Wrap as q, Justify as W, Align as L, Display as Ue, Overflow as De } from "yoga-layout/load";
2
+ const xe = {
3
+ // VisualElement is the base class and carries no class of its own.
4
+ VisualElement: { hasText: !1, classes: [], parts: [] },
5
+ Label: { hasText: !0, classes: ["unity-label"], parts: [] },
6
+ Button: { hasText: !0, classes: ["unity-button"], parts: [] },
7
+ // Image draws a texture, not text. Its picture reaches this renderer through
8
+ // `background-image` in USS, which `resolveAsset` can turn into something a
9
+ // browser will load; a texture assigned from C# has no path to follow here.
10
+ Image: { hasText: !1, classes: ["unity-image"], parts: [] },
11
+ /**
12
+ * Four elements from one tag. The names below are observed in
13
+ * `tests/golden/unity/scrollview-*.json`, not taken from documentation — the
14
+ * middle one, `unity-content-and-vertical-scroll-container`, is not in
15
+ * Unity's manual diagram at all and was found by dumping.
16
+ *
17
+ * The styles are inference, unlike the names: they are how this renderer
18
+ * reproduces the measured geometry, and the three `scrollview-*` golden cases
19
+ * are what decides whether the inference is right.
20
+ */
21
+ ScrollView: {
22
+ hasText: !1,
23
+ classes: ["unity-scroll-view"],
24
+ parts: [
25
+ // Fills the ScrollView's content box, and lays the viewport out beside
26
+ // the vertical scrollbar — hence row.
27
+ {
28
+ name: "unity-content-and-vertical-scroll-container",
29
+ style: { "flex-grow": "1", "flex-direction": "row" }
30
+ },
31
+ // What actually clips. Takes whatever width the scrollbar leaves.
32
+ { name: "unity-content-viewport", style: { "flex-grow": "1", overflow: "hidden" } },
33
+ // `flex-shrink: 0` is the whole reason a ScrollView is not one box:
34
+ // this grows to the content's height instead of being squeezed into the
35
+ // viewport's, so children keep their sizes and the viewport crops them.
36
+ // Without it three 60px children in a 100px view come out 33/34/33.
37
+ { name: "unity-content-container", style: { "flex-shrink": "0" } }
38
+ ]
39
+ }
40
+ }, ce = { hasText: !1, classes: [], parts: [] }, Le = "UXML", ze = /* @__PURE__ */ new Set(["Style"]);
41
+ function _e(e) {
42
+ return ze.has(e.name.local);
43
+ }
44
+ function F(e) {
45
+ const n = xe[e.name.local];
46
+ return n !== void 0 ? { spec: n, fallback: !1 } : je(e) ? { spec: ce, fallback: !1 } : { spec: ce, fallback: !0 };
47
+ }
48
+ function je(e) {
49
+ return e.name.local === Le;
50
+ }
51
+ function We(e) {
52
+ return F(e).spec.classes;
53
+ }
54
+ function Be() {
55
+ return Object.keys(xe);
56
+ }
57
+ const Y = "6000.0.40f1", ve = `:disabled {
58
+ opacity: 0.5;
59
+ }
60
+
61
+ .unity-button {
62
+ margin: 1px 3px;
63
+ -unity-text-align: middle-center;
64
+ }
65
+ `, Fe = 13;
66
+ function Pe(e) {
67
+ return e ? Fe : 0;
68
+ }
69
+ const Ve = /* @__PURE__ */ new Set([
70
+ "color",
71
+ "font-size",
72
+ "letter-spacing",
73
+ "word-spacing",
74
+ "visibility",
75
+ "white-space",
76
+ "-unity-font",
77
+ "-unity-font-definition",
78
+ "-unity-font-style",
79
+ "-unity-paragraph-spacing",
80
+ "-unity-text-align",
81
+ "-unity-text-outline-color",
82
+ "-unity-text-outline-width"
83
+ ]);
84
+ function He(e) {
85
+ return e.startsWith("--") || Ve.has(e);
86
+ }
87
+ function ue(e) {
88
+ const n = [];
89
+ let t = 0, i = -1;
90
+ for (let l = 0; l < e.length; l++) {
91
+ const s = e[l];
92
+ s === "(" ? t++ : s === ")" && (t = Math.max(0, t - 1)), t === 0 && /\s/.test(s) ? i >= 0 && (n.push(e.slice(i, l)), i = -1) : i < 0 && (i = l);
93
+ }
94
+ return i >= 0 && n.push(e.slice(i)), n;
95
+ }
96
+ function qe(e) {
97
+ const [n, t, i, l] = e;
98
+ return n === void 0 ? null : t === void 0 ? [n, n, n, n] : i === void 0 ? [n, t, n, t] : l === void 0 ? [n, t, i, t] : [n, t, i, l];
99
+ }
100
+ const Ge = {
101
+ margin: ["margin-top", "margin-right", "margin-bottom", "margin-left"],
102
+ padding: ["padding-top", "padding-right", "padding-bottom", "padding-left"],
103
+ "border-width": [
104
+ "border-top-width",
105
+ "border-right-width",
106
+ "border-bottom-width",
107
+ "border-left-width"
108
+ ],
109
+ "border-color": [
110
+ "border-top-color",
111
+ "border-right-color",
112
+ "border-bottom-color",
113
+ "border-left-color"
114
+ ],
115
+ // Radii run clockwise from the top-left corner, not top/right/bottom/left.
116
+ "border-radius": [
117
+ "border-top-left-radius",
118
+ "border-top-right-radius",
119
+ "border-bottom-right-radius",
120
+ "border-bottom-left-radius"
121
+ ]
6
122
  };
7
- function U(t) {
8
- return K[t.name.local] ?? null;
123
+ function de(e) {
124
+ return /^-?(\d+\.?\d*|\.\d+)$/.test(e);
125
+ }
126
+ function Ye(e) {
127
+ const [n, t, i] = e;
128
+ 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"]] : t === void 0 ? de(n) ? [["flex-grow", n], ["flex-shrink", "1"], ["flex-basis", "0"]] : [["flex-grow", "1"], ["flex-shrink", "1"], ["flex-basis", n]] : i === void 0 ? de(t) ? [["flex-grow", n], ["flex-shrink", t], ["flex-basis", "0"]] : [["flex-grow", n], ["flex-shrink", "1"], ["flex-basis", t]] : [["flex-grow", n], ["flex-shrink", t], ["flex-basis", i]];
9
129
  }
10
- function ie() {
11
- return Object.keys(K);
130
+ function J(e, n) {
131
+ if (e === "flex") return Ye(ue(n));
132
+ const t = Ge[e];
133
+ if (t === void 0) return [[e, n]];
134
+ const i = qe(ue(n));
135
+ return i === null ? [[e, n]] : t.map((l, s) => [l, i[s]]);
12
136
  }
13
- const Q = {
137
+ const ee = {
14
138
  "align-content": "flex-start",
15
139
  "align-items": "stretch",
16
140
  "align-self": "auto",
@@ -46,207 +170,256 @@ const Q = {
46
170
  "padding-right": "0",
47
171
  "padding-top": "0",
48
172
  "font-size": "12px"
49
- }, pt = ["em", "rem", "vh", "vw", "vmin", "vmax", "pt", "cm", "in"];
50
- function P(t) {
51
- const n = t.trim();
173
+ }, Xe = ["em", "rem", "vh", "vw", "vmin", "vmax", "pt", "cm", "in"];
174
+ function X(e) {
175
+ const n = e.trim();
52
176
  if (n === "") return { length: null, problem: "empty value" };
53
177
  if (n === "auto") return { length: { kind: "auto" } };
54
178
  if (n === "none") return { length: { kind: "none" } };
55
179
  if (n === "initial") return { length: { kind: "auto" } };
56
180
  if (n.startsWith("calc("))
57
181
  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}"` };
182
+ const t = /^(-?(?:\d+\.?\d*|\.\d+))([a-z%]*)$/i.exec(n);
183
+ if (t === null) return { length: null, problem: `cannot read "${n}" as a length` };
184
+ const i = Number(t[1]), l = t[2].toLowerCase();
185
+ return l === "" || l === "px" ? { length: { kind: "px", value: i } } : l === "%" ? { length: { kind: "percent", value: i } } : Xe.includes(l) ? { length: null, problem: `"${l}" is not a USS unit` } : { length: null, problem: `unknown unit "${l}"` };
62
186
  }
63
- function B(t) {
64
- const n = t.trim();
187
+ function fe(e) {
188
+ const n = e.trim();
65
189
  return /^-?(\d+\.?\d*|\.\d+)$/.test(n) ? Number(n) : null;
66
190
  }
67
- let _ = null;
68
- async function re() {
69
- _ ?? (_ = await lt());
191
+ let se = null;
192
+ async function Ut() {
193
+ se ?? (se = await Me());
70
194
  }
71
- function se() {
72
- return _ !== null;
195
+ function Dt() {
196
+ return se !== null;
73
197
  }
74
- let W = 0;
75
- function oe() {
76
- return W;
198
+ let G = 0;
199
+ function Lt() {
200
+ return G;
77
201
  }
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]
202
+ const K = {
203
+ auto: L.Auto,
204
+ "flex-start": L.FlexStart,
205
+ center: L.Center,
206
+ "flex-end": L.FlexEnd,
207
+ stretch: L.Stretch,
208
+ baseline: L.Baseline,
209
+ "space-between": L.SpaceBetween,
210
+ "space-around": L.SpaceAround,
211
+ "space-evenly": L.SpaceEvenly
212
+ }, Ze = {
213
+ "flex-start": W.FlexStart,
214
+ center: W.Center,
215
+ "flex-end": W.FlexEnd,
216
+ "space-between": W.SpaceBetween,
217
+ "space-around": W.SpaceAround,
218
+ "space-evenly": W.SpaceEvenly
219
+ }, Je = {
220
+ column: V.Column,
221
+ "column-reverse": V.ColumnReverse,
222
+ row: V.Row,
223
+ "row-reverse": V.RowReverse
224
+ }, Ke = {
225
+ nowrap: q.NoWrap,
226
+ wrap: q.Wrap,
227
+ "wrap-reverse": q.WrapReverse
228
+ }, Qe = [
229
+ ["left", P.Left],
230
+ ["top", P.Top],
231
+ ["right", P.Right],
232
+ ["bottom", P.Bottom]
109
233
  ];
110
- function bt(t, n, e) {
111
- const i = _;
112
- if (i === null)
234
+ function et(e, n, t, i) {
235
+ const l = se;
236
+ if (l === null)
113
237
  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] ?? "";
238
+ const s = [], m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), v = [], u = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
239
+ let a = 0, d = !1, o = !1;
240
+ const f = (p, k) => {
241
+ var T;
242
+ return ((T = p.get(k)) == null ? void 0 : T.value) ?? ee[k] ?? "";
119
243
  };
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) {
244
+ function w(p, k) {
245
+ s.push({ kind: "unsupported-property", message: p, node: k.id });
246
+ }
247
+ function c(p, k, T) {
248
+ const N = f(p, k);
249
+ if (N === "") return null;
250
+ const { length: C, problem: A } = X(N);
251
+ return A !== void 0 && w(`${k}: ${A}`, T), C;
252
+ }
253
+ function S(p) {
254
+ if (p !== null)
255
+ switch (p.kind) {
132
256
  case "px":
133
- return a.value;
257
+ return p.value;
134
258
  case "percent":
135
- return `${a.value}%`;
259
+ return `${p.value}%`;
136
260
  case "auto":
137
261
  return "auto";
138
262
  case "none":
139
263
  return;
140
264
  }
141
265
  }
142
- function x(a) {
143
- if (a !== null) {
144
- if (a.kind === "px") return a.value;
145
- if (a.kind === "percent") return `${a.value}%`;
266
+ function h(p) {
267
+ if (p !== null) {
268
+ if (p.kind === "px") return p.value;
269
+ if (p.kind === "percent") return `${p.value}%`;
146
270
  }
147
271
  }
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)));
272
+ function x(p, k, T) {
273
+ p.setBoxSizing(Re.BorderBox), p.setFlexDirection(Je[f(k, "flex-direction")] ?? V.Column), p.setFlexWrap(Ke[f(k, "flex-wrap")] ?? q.NoWrap), p.setJustifyContent(Ze[f(k, "justify-content")] ?? W.FlexStart), p.setAlignItems(K[f(k, "align-items")] ?? L.Stretch), p.setAlignSelf(K[f(k, "align-self")] ?? L.Auto), p.setAlignContent(K[f(k, "align-content")] ?? L.FlexStart), p.setFlexGrow(fe(f(k, "flex-grow")) ?? 0), p.setFlexShrink(fe(f(k, "flex-shrink")) ?? 1), p.setFlexBasis(S(c(k, "flex-basis", T)));
274
+ const N = f(k, "position");
275
+ (N === "fixed" || N === "sticky") && w(`position: ${N} is not supported in USS; treated as relative`, T), p.setPositionType(
276
+ N === "absolute" ? Z.Absolute : Z.Relative
277
+ ), f(k, "display") === "none" && p.setDisplay(Ue.None);
278
+ const C = f(k, "overflow");
279
+ C === "hidden" ? p.setOverflow(De.Hidden) : (C === "auto" || C === "scroll") && w(`overflow: ${C} needs a ScrollView element in USS`, T), p.setWidth(S(c(k, "width", T))), p.setHeight(S(c(k, "height", T))), p.setMinWidth(h(c(k, "min-width", T))), p.setMinHeight(h(c(k, "min-height", T))), p.setMaxWidth(h(c(k, "max-width", T))), p.setMaxHeight(h(c(k, "max-height", T)));
280
+ for (const [A, I] of Qe) {
281
+ p.setMargin(I, h(c(k, `margin-${A}`, T))), p.setPadding(I, h(c(k, `padding-${A}`, T)));
282
+ const _ = h(c(k, `border-${A}-width`, T));
283
+ p.setBorder(I, typeof _ == "number" ? _ : void 0), p.setPosition(I, h(c(k, A, T)));
160
284
  }
161
285
  }
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
286
+ function y(p) {
287
+ var k;
288
+ return (k = p.attributes.find((T) => T.name === "text")) == null ? void 0 : k.value;
289
+ }
290
+ const b = ["text", "label"];
291
+ function $(p) {
292
+ return b.filter(
293
+ (k) => p.attributes.some((T) => T.name === k && T.value.length > 0)
294
+ );
295
+ }
296
+ function O(p, k) {
297
+ if (_e(p)) return;
298
+ const T = n.get(p.id) ?? /* @__PURE__ */ new Map(), N = l.Node.create();
299
+ a++, G++, u.set(p, N), v.push(p), x(N, T, p), k !== null && k.insertChild(N, k.getChildCount());
300
+ const { spec: C, fallback: A } = F(p), I = y(p), _ = C.hasText && I !== void 0 && I.length > 0;
301
+ if (A) {
302
+ const M = $(p);
303
+ s.push({
304
+ kind: "unsupported-control",
305
+ message: `<${p.name.local}> has no renderer in this version and is drawn as a plain VisualElement` + (M.length === 0 ? "" : `; its ${M.join(" and ")} attribute${M.length > 1 ? "s are" : " is"} not drawn, because Unity draws that through a child element`),
306
+ node: p.id
307
+ });
308
+ }
309
+ if (_) {
310
+ p.children.length > 0 && w(
311
+ `<${p.name.local}> has both a text attribute and children; children are not drawn`,
312
+ p
174
313
  );
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"
314
+ const M = c(T, "font-size", p), z = {
315
+ fontSize: M !== null && M.kind === "px" ? M.value : 12,
316
+ fontStyle: f(T, "-unity-font-style") || "normal",
317
+ whiteSpace: f(T, "white-space") || "normal"
179
318
  };
180
- v.setMeasureFunc(
181
- (H) => e.measureText(
182
- T,
183
- at,
184
- Number.isFinite(H) ? H : 0
319
+ N.setMeasureFunc(
320
+ (U) => i.measureText(
321
+ I,
322
+ z,
323
+ Number.isFinite(U) ? U : 0
185
324
  )
186
325
  );
187
326
  return;
188
327
  }
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
328
+ let j = N;
329
+ if (C.parts.length > 0) {
330
+ o || (o = !0, s.push({
331
+ kind: "version-dependent",
332
+ message: `<${p.name.local}> is drawn with the implicit child elements Unity builds for it, and their geometry was measured on Unity ${Y}. Other versions may differ; see src/controls/theme.ts.`,
333
+ node: p.id
334
+ }));
335
+ const M = [], z = [], U = t.get(p.id);
336
+ for (const oe of C.parts) {
337
+ const ae = (U == null ? void 0 : U.get(oe.name)) ?? /* @__PURE__ */ new Map(), H = l.Node.create();
338
+ a++, G++, x(H, ae, p), j.insertChild(H, j.getChildCount()), j = H, z.push(H), M.push({
339
+ name: oe.name,
340
+ owner: p.id,
341
+ box: { left: 0, top: 0, width: 0, height: 0 },
342
+ style: ae
195
343
  });
196
- continue;
197
344
  }
198
- $(O, v);
345
+ g.set(p.id, M), r.set(p.id, z);
346
+ }
347
+ for (const M of p.children) O(M, j);
348
+ }
349
+ O(e, null);
350
+ const E = u.get(e);
351
+ E.setWidth(i.size.width), E.setHeight(i.size.height), E.setPositionType(Z.Relative), E.calculateLayout(i.size.width, i.size.height, le.LTR);
352
+ const R = /* @__PURE__ */ new Map();
353
+ for (let p = 0; p < 3; p++) {
354
+ let k = !1;
355
+ for (const [T, N] of g) {
356
+ const C = r.get(T);
357
+ if (C === void 0) continue;
358
+ const A = N.findIndex((U) => U.name === "unity-content-viewport"), I = N.findIndex((U) => U.name === "unity-content-container");
359
+ if (A === -1 || I === -1) continue;
360
+ const _ = C[A].getComputedLayout(), M = C[I].getComputedLayout().height > _.height + 0.01, z = Pe(M);
361
+ (R.get(T) ?? 0) !== z && (R.set(T, z), C[A].setMargin(P.Right, z), k = !0);
199
362
  }
363
+ if (!k) break;
364
+ E.calculateLayout(i.size.width, i.size.height, le.LTR);
365
+ }
366
+ function D(p, k, T) {
367
+ const N = u.get(p);
368
+ if (N === void 0) return;
369
+ const C = N.getComputedLayout();
370
+ let A = k + C.left, I = T + C.top;
371
+ m.set(p.id, { left: A, top: I, width: C.width, height: C.height });
372
+ const _ = g.get(p.id), j = r.get(p.id);
373
+ _ !== void 0 && j !== void 0 && _.forEach((M, z) => {
374
+ const U = j[z].getComputedLayout();
375
+ A += U.left, I += U.top, M.box = { left: A, top: I, width: U.width, height: U.height };
376
+ });
377
+ for (const M of p.children) D(M, A, I);
200
378
  }
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,
379
+ return D(e, 0, 0), {
380
+ boxes: m,
381
+ parts: g,
382
+ painted: v,
383
+ warnings: s,
215
384
  dispose() {
216
- d || (d = !0, k.freeRecursive(), W -= b, g.clear());
385
+ d || (d = !0, E.freeRecursive(), G -= a, u.clear(), r.clear());
217
386
  }
218
387
  };
219
388
  }
220
- const xt = 1.2;
221
- function vt(t) {
222
- var e;
389
+ const tt = 1.2;
390
+ function nt(e) {
391
+ var t;
223
392
  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;
393
+ if (e !== void 0) {
394
+ const i = e.createElement("canvas");
395
+ n = ((t = i.getContext) == null ? void 0 : t.call(i, "2d")) ?? null;
227
396
  }
228
- return (i, l, r) => {
229
- const p = l.fontSize * xt, g = (f) => {
397
+ return (i, l, s) => {
398
+ const m = l.fontSize * tt, g = (o) => {
230
399
  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;
400
+ return o.length * l.fontSize * 0.5;
401
+ const f = l.fontStyle.includes("bold") ? "bold" : "normal", w = l.fontStyle.includes("italic") ? "italic" : "normal";
402
+ return n.font = `${w} ${f} ${l.fontSize}px sans-serif`, n.measureText(o).width;
234
403
  };
235
- if (!(l.whiteSpace !== "nowrap" && l.whiteSpace !== "pre") || r <= 0) {
236
- const f = i.split(`
404
+ if (!(l.whiteSpace !== "nowrap" && l.whiteSpace !== "pre") || s <= 0) {
405
+ const o = i.split(`
237
406
  `);
238
- return { width: f.reduce((S, m) => Math.max(S, g(m)), 0), height: f.length * p };
407
+ return { width: o.reduce((w, c) => Math.max(w, g(c)), 0), height: o.length * m };
239
408
  }
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;
409
+ const u = i.split(/\s+/).filter((o) => o.length > 0);
410
+ let r = 1, a = 0, d = 0;
411
+ for (const o of u) {
412
+ const f = g(o), w = a === 0 ? 0 : g(" ");
413
+ a > 0 && a + w + f > s ? (d = Math.max(d, a), r++, a = f) : a += w + f;
245
414
  }
246
- return u = Math.max(u, c), { width: u, height: s * p };
415
+ return d = Math.max(d, a), { width: d, height: r * m };
247
416
  };
248
417
  }
249
- const kt = /* @__PURE__ */ new Set([
418
+ function ye(e) {
419
+ const n = (t, i) => !Number.isInteger(t) || t < 0 || t > 1114111 || t >= 55296 && t <= 57343 ? i : String.fromCodePoint(t);
420
+ return e.replace(/&#x([0-9a-f]+);/gi, (t, i) => n(parseInt(i, 16), t)).replace(/&#(\d+);/g, (t, i) => n(Number(i), t)).replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
421
+ }
422
+ const it = /* @__PURE__ */ new Set([
250
423
  "box-shadow",
251
424
  "filter",
252
425
  "backdrop-filter",
@@ -262,7 +435,7 @@ const kt = /* @__PURE__ */ new Set([
262
435
  "float",
263
436
  "clear",
264
437
  "border-style"
265
- ]), St = /* @__PURE__ */ new Set([
438
+ ]), st = /* @__PURE__ */ new Set([
266
439
  "gap",
267
440
  "row-gap",
268
441
  "column-gap",
@@ -272,37 +445,41 @@ const kt = /* @__PURE__ */ new Set([
272
445
  "background-repeat",
273
446
  "overflow-wrap",
274
447
  "word-break"
275
- ]), q = ["top", "right", "bottom", "left"], yt = {
448
+ ]), pe = ["top", "right", "bottom", "left"], rt = {
276
449
  normal: { weight: "normal", style: "normal" },
277
450
  bold: { weight: "bold", style: "normal" },
278
451
  italic: { weight: "normal", style: "italic" },
279
452
  "bold-and-italic": { weight: "bold", style: "italic" }
280
- }, $t = {
453
+ }, ot = {
281
454
  upper: "flex-start",
282
455
  middle: "center",
283
456
  lower: "flex-end"
284
- }, Tt = {
457
+ }, at = {
285
458
  left: "flex-start",
286
459
  center: "center",
287
460
  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];
461
+ }, Q = {
462
+ "stretch-to-fill": "100% 100%",
463
+ "scale-and-crop": "cover",
464
+ "scale-to-fit": "contain"
465
+ }, he = "stretch-to-fill";
466
+ function lt(e) {
467
+ const n = /^(url|resource)\(\s*(["']?)(.*?)\2\s*\)$/.exec(e.trim());
468
+ return n === null ? null : { form: n[1], path: n[3] };
292
469
  }
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 });
470
+ function me(e, n, t = {}) {
471
+ var w;
472
+ const i = {}, l = [], s = (c) => {
473
+ var S;
474
+ return (S = e.get(c)) == null ? void 0 : S.value;
475
+ }, m = (c, S) => {
476
+ l.push({ kind: c, message: S, node: n });
300
477
  };
301
478
  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(
479
+ for (const [c] of e)
480
+ it.has(c) ? m("unsupported-property", `${c} does not exist in USS and is ignored`) : st.has(c) && m(
304
481
  "version-dependent",
305
- `${m} depends on the Unity version; verify it in your project`
482
+ `${c} depends on the Unity version; verify it in your project`
306
483
  );
307
484
  const g = [
308
485
  "background-color",
@@ -317,793 +494,929 @@ function Et(t, n, e = {}) {
317
494
  "font-size",
318
495
  "transform-origin"
319
496
  ];
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(
497
+ for (const c of g) {
498
+ const S = s(c);
499
+ S !== void 0 && (i[c] = S);
500
+ }
501
+ s("display") === "none" && (i.display = "none"), s("overflow") === "hidden" && (i.overflow = "hidden");
502
+ for (const c of pe) {
503
+ const S = s(`border-${c}-width`);
504
+ if (S !== void 0 && S !== "0") {
505
+ const { length: y, problem: b } = X(S);
506
+ y === null || y.kind !== "px" ? m(
330
507
  "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");
508
+ `border-${c}-width: ${b ?? `"${S}" is not a pixel length`}; ignored`
509
+ ) : (i[`border-${c}-width`] = `${y.value}px`, i[`border-${c}-style`] = "solid");
333
510
  }
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);
511
+ const h = s(`border-${c}-color`);
512
+ h !== void 0 && (i[`border-${c}-color`] = h);
513
+ const x = s(`padding-${c}`);
514
+ x !== void 0 && x !== "0" && (i[`padding-${c}`] = x);
338
515
  }
339
- for (const m of [
516
+ for (const c of [
340
517
  "top-left",
341
518
  "top-right",
342
519
  "bottom-right",
343
520
  "bottom-left"
344
521
  ]) {
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`);
522
+ const S = s(`border-${c}-radius`);
523
+ S !== void 0 && (i[`border-${c}-radius`] = S);
524
+ }
525
+ const v = s("-unity-font-style");
526
+ if (v !== void 0) {
527
+ const c = rt[v];
528
+ c === void 0 ? m("unsupported-property", `-unity-font-style: ${v} is not a USS value`) : (i["font-weight"] = c.weight, i["font-style"] = c.style);
529
+ }
530
+ const u = s("-unity-text-align");
531
+ if (u !== void 0) {
532
+ const [c, S] = u.split("-"), h = ot[c ?? ""], x = at[S ?? ""];
533
+ h === void 0 || x === void 0 ? m("unsupported-property", `-unity-text-align: ${u} is not a USS value`) : (i["align-items"] = h, i["justify-content"] = x);
534
+ }
535
+ const r = [], a = s("translate");
536
+ a !== void 0 && r.push(`translate(${a.replace(/\s+/, ", ")})`);
537
+ const d = s("rotate");
538
+ d !== void 0 && r.push(`rotate(${d})`);
539
+ const o = s("scale");
540
+ o !== void 0 && r.push(`scale(${o.replace(/\s+/, ", ")})`), r.length > 0 && (i.transform = r.join(" "));
541
+ const f = s("background-image");
542
+ if (f !== void 0 && f !== "none") {
543
+ const c = lt(f);
544
+ if (c === null)
545
+ m("asset-unresolved", `background-image: cannot read "${f}" as an asset path`);
369
546
  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");
547
+ const { form: S, path: h } = c, x = ((w = t.resolveAsset) == null ? void 0 : w.call(t, h, S)) ?? null;
548
+ if (x === null)
549
+ i["background-image"] = "repeating-linear-gradient(45deg, rgba(255,0,255,0.35) 0 6px, rgba(0,0,0,0) 6px 12px)", m("asset-unresolved", `background-image: "${h}" was not resolved`);
550
+ else {
551
+ i["background-image"] = `url("${x}")`, i["background-repeat"] = s("background-repeat") ?? "no-repeat", i["background-position"] = s("background-position") ?? "center";
552
+ const y = s("background-size"), b = s("-unity-background-scale-mode") ?? he, $ = Q[b];
553
+ $ === void 0 && m(
554
+ "unsupported-property",
555
+ `-unity-background-scale-mode: ${b} is not a USS value; expected one of ${Object.keys(Q).join(", ")}`
556
+ ), i["background-size"] = y ?? $ ?? Q[he];
557
+ }
372
558
  }
373
559
  }
374
- return r("-unity-background-image-tint-color") !== void 0 && p(
560
+ return s("-unity-background-image-tint-color") !== void 0 && m(
375
561
  "unsupported-property",
376
562
  "-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(
563
+ ), pe.some((c) => s(`-unity-slice-${c}`) !== void 0) && m("unsupported-property", "-unity-slice-* (9-slice) is not drawn in this preview"), s("-unity-font-definition") !== void 0 && m(
378
564
  "unsupported-property",
379
565
  "-unity-font-definition names a Unity font asset; the browser default is used"
380
566
  ), { declarations: i, warnings: l };
381
567
  }
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);
568
+ const ct = "data-uxml-node", ut = "data-uxml-part", dt = "data-uxml-part-owner";
569
+ function ft(e, n, t, i, l, s) {
570
+ const m = [], g = /* @__PURE__ */ new Map();
571
+ function v(d) {
572
+ const o = i.get(d.id), f = (w) => {
573
+ var h;
574
+ const c = ((h = o == null ? void 0 : o.get(w)) == null ? void 0 : h.value) ?? ee[w] ?? "0", { length: S } = X(c);
389
575
  return S !== null && S.kind === "px" ? S.value : 0;
390
576
  };
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 = {
577
+ return { left: f("border-left-width"), top: f("border-top-width") };
578
+ }
579
+ function u(d) {
580
+ const o = (f) => {
581
+ var S;
582
+ const w = ((S = d.style.get(f)) == null ? void 0 : S.value) ?? ee[f] ?? "0", { length: c } = X(w);
583
+ return c !== null && c.kind === "px" ? c.value : 0;
584
+ };
585
+ return { left: o("border-left-width"), top: o("border-top-width") };
586
+ }
587
+ function r(d, o, f) {
588
+ var E;
589
+ const w = n.get(d.id);
590
+ if (w === void 0) return null;
591
+ const c = s.document.createElement("div");
592
+ c.setAttribute(ct, String(d.id));
593
+ const S = i.get(d.id) ?? /* @__PURE__ */ new Map(), h = me(S, d.id, s);
594
+ m.push(...h.warnings);
595
+ const x = o === null ? 0 : w.left - o.left - f.left, y = o === null ? 0 : w.top - o.top - f.top, b = {
402
596
  position: "absolute",
403
- left: `${$}px`,
404
- top: `${k}px`,
405
- width: `${f.width}px`,
406
- height: `${f.height}px`,
597
+ left: `${x}px`,
598
+ top: `${y}px`,
599
+ width: `${w.width}px`,
600
+ height: `${w.height}px`,
407
601
  margin: "0",
408
- ...m.declarations
602
+ ...h.declarations
409
603
  };
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);
604
+ for (const [R, D] of Object.entries(b))
605
+ c.style.setProperty(R, D);
606
+ const { spec: $ } = F(d), O = (E = d.attributes.find((R) => R.name === "text")) == null ? void 0 : E.value;
607
+ if ($.hasText && O !== void 0 && O.length > 0)
608
+ c.style.setProperty("display", h.declarations.display ?? "flex"), h.declarations["align-items"] === void 0 && c.style.setProperty("align-items", "flex-start"), h.declarations["justify-content"] === void 0 && c.style.setProperty("justify-content", "flex-start"), c.textContent = ye(O);
415
609
  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);
610
+ let R = c, D = w, p = v(d);
611
+ for (const k of t.get(d.id) ?? []) {
612
+ const T = s.document.createElement("div");
613
+ T.setAttribute(ut, k.name), T.setAttribute(dt, String(d.id));
614
+ const N = me(k.style, d.id, s);
615
+ m.push(...N.warnings);
616
+ const C = {
617
+ position: "absolute",
618
+ left: `${k.box.left - D.left - p.left}px`,
619
+ top: `${k.box.top - D.top - p.top}px`,
620
+ width: `${k.box.width}px`,
621
+ height: `${k.box.height}px`,
622
+ margin: "0",
623
+ ...N.declarations
624
+ };
625
+ for (const [A, I] of Object.entries(C))
626
+ T.style.setProperty(A, I);
627
+ R.appendChild(T), R = T, D = k.box, p = u(k);
628
+ }
629
+ for (const k of d.children) {
630
+ const T = r(k, D, p);
631
+ T !== null && R.appendChild(T);
420
632
  }
421
633
  }
422
- return p.set(s.id, x), x;
634
+ return g.set(d.id, c), c;
423
635
  }
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 };
636
+ l.replaceChildren();
637
+ const a = r(e, null, { left: 0, top: 0 });
638
+ return a !== null && (a.style.setProperty("position", "relative"), l.appendChild(a)), { warnings: m, elements: g };
427
639
  }
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, "&");
640
+ const ge = /[A-Za-z0-9_-]/;
641
+ function B(e) {
642
+ return e === " " || e === " " || e === `
643
+ ` || e === "\r" || e === "\f";
431
644
  }
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) {
645
+ function te(e, n, t) {
438
646
  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;
647
+ for (; i < e.length; ) {
648
+ const s = e[i];
649
+ if (s === '"' || s === "'") {
650
+ const m = e.indexOf(s, i + 1);
651
+ i = m < 0 ? e.length : m + 1;
444
652
  continue;
445
653
  }
446
- if (r === "/" && t[i + 1] === "*") {
447
- const p = t.indexOf("*/", i + 2);
448
- i = p < 0 ? t.length : p + 2;
654
+ if (s === "/" && e[i + 1] === "*") {
655
+ const m = e.indexOf("*/", i + 2);
656
+ i = m < 0 ? e.length : m + 2;
449
657
  continue;
450
658
  }
451
- if (r === "(" || r === "[")
659
+ if (s === "(" || s === "[")
452
660
  l++;
453
- else if (r === ")" || r === "]")
661
+ else if (s === ")" || s === "]")
454
662
  l > 0 && l--;
455
- else if (l === 0 && e.includes(r))
663
+ else if (l === 0 && t.includes(s))
456
664
  return i;
457
665
  i++;
458
666
  }
459
- return t.length;
667
+ return e.length;
460
668
  }
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--;
669
+ function ke(e, n, t) {
670
+ let i = n, l = t;
671
+ for (; i < l && B(e[i]); ) i++;
672
+ for (; l > i && B(e[l - 1]); ) l--;
465
673
  return { start: i, end: l };
466
674
  }
467
- function et(t, n, e, i) {
675
+ function Se(e, n, t, i) {
468
676
  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;
677
+ let s = n;
678
+ for (; s < t; ) {
679
+ for (; s < t && (B(e[s]) || e.startsWith("/*", s)); )
680
+ if (e.startsWith("/*", s)) {
681
+ const r = e.indexOf("*/", s + 2);
682
+ s = r < 0 ? t : r + 2;
475
683
  } else
476
- r++;
477
- if (r >= e) break;
478
- if (t[r] === ";") {
479
- r++;
684
+ s++;
685
+ if (s >= t) break;
686
+ if (e[s] === ";") {
687
+ s++;
480
688
  continue;
481
689
  }
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;
690
+ const m = s, g = te(e, m, ":;}");
691
+ if (g >= t || e[g] !== ":") {
692
+ const r = Math.min(g, t);
693
+ i == null || i("declaration without a value", m, r), s = r + 1;
486
694
  continue;
487
695
  }
488
- const b = Math.min(F(t, g + 1, ";}"), e), d = tt(t, g + 1, b);
696
+ const v = Math.min(te(e, g + 1, ";}"), t), u = ke(e, g + 1, v);
489
697
  l.push({
490
- property: t.slice(p, g).trim(),
491
- value: t.slice(d.start, d.end),
492
- span: { start: p, end: d.end },
698
+ property: e.slice(m, g).trim(),
699
+ value: e.slice(u.start, u.end),
700
+ span: { start: m, end: u.end },
493
701
  dirty: !1
494
- }), r = b + 1;
702
+ }), s = v + 1;
495
703
  }
496
704
  return l;
497
705
  }
498
- function Dt(t) {
499
- const n = t.span.end - 1 - t.value.length;
500
- return n < t.span.start ? null : n;
706
+ function pt(e) {
707
+ const n = e.span.end - 1 - e.value.length;
708
+ return n < e.span.start ? null : n;
501
709
  }
502
- function Mt(t, n = null, e = 0) {
710
+ function re(e, n = null, t = 0) {
503
711
  const i = [], l = [];
504
- let r = 0;
505
- function p(k, w, a) {
712
+ let s = 0;
713
+ function m(h, x, y) {
506
714
  i.push({
507
715
  kind: "malformed",
508
- message: k,
509
- at: { in: "uss", sheet: e, span: { start: w, end: a } }
716
+ message: h,
717
+ at: { in: "uss", sheet: t, span: { start: x, end: y } }
510
718
  });
511
719
  }
512
720
  function g() {
513
721
  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;
722
+ for (; B(e[s]); ) s++;
723
+ if (e.startsWith("/*", s)) {
724
+ const h = e.indexOf("*/", s + 2);
725
+ s = h < 0 ? e.length : h + 2;
518
726
  continue;
519
727
  }
520
728
  return;
521
729
  }
522
730
  }
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;
731
+ const v = (h, x) => te(e, h, x), u = (h, x) => ke(e, h, x);
732
+ function r(h) {
733
+ let x = h + 1, y = 1;
734
+ for (; x < e.length; ) {
735
+ const b = e[x];
736
+ if (b === '"' || b === "'") {
737
+ const $ = e.indexOf(b, x + 1);
738
+ x = $ < 0 ? e.length : $ + 1;
531
739
  continue;
532
740
  }
533
- if (o === "/" && t[w + 1] === "*") {
534
- const h = t.indexOf("*/", w + 2);
535
- w = h < 0 ? t.length : h + 2;
741
+ if (b === "/" && e[x + 1] === "*") {
742
+ const $ = e.indexOf("*/", x + 2);
743
+ x = $ < 0 ? e.length : $ + 2;
536
744
  continue;
537
745
  }
538
- if (o === "{") a++;
539
- else if (o === "}" && --a === 0) return w + 1;
540
- w++;
746
+ if (b === "{") y++;
747
+ else if (b === "}" && --y === 0) return x + 1;
748
+ x++;
541
749
  }
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;
750
+ return e.length;
751
+ }
752
+ function a(h) {
753
+ let x = h;
754
+ for (; x < e.length && ge.test(e[x]); ) x++;
755
+ return x;
756
+ }
757
+ function d(h) {
758
+ const x = e[h], y = x === "(" ? ")" : "]";
759
+ let b = h + 1, $ = 1;
760
+ for (; b < e.length; ) {
761
+ const O = e[b];
762
+ if (O === '"' || O === "'") {
763
+ const E = e.indexOf(O, b + 1);
764
+ b = E < 0 ? e.length : E + 1;
557
765
  continue;
558
766
  }
559
- if (v === w) h++;
560
- else if (v === a && --h === 0) return o + 1;
561
- o++;
767
+ if (O === x) $++;
768
+ else if (O === y && --$ === 0) return b + 1;
769
+ b++;
562
770
  }
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;
771
+ return e.length;
772
+ }
773
+ function o(h, x) {
774
+ const y = [];
775
+ let b = h;
776
+ for (; b < x; ) {
777
+ const $ = e[b];
778
+ if (B($) || $ === ">" || $ === "+" || $ === "~" || $ === ",") break;
779
+ if ($ === "*")
780
+ y.push({ kind: "universal" }), b++;
781
+ else if ($ === "." || $ === "#") {
782
+ const O = a(b + 1);
783
+ y.push(
784
+ $ === "." ? { kind: "class", name: e.slice(b + 1, O) } : { kind: "name", name: e.slice(b + 1, O) }
785
+ ), b = O;
786
+ } else if ($ === "[") {
787
+ const O = Math.min(d(b), x);
788
+ y.push({ kind: "unknown", text: e.slice(b, O) }), b = O;
789
+ } else if ($ === ":")
790
+ if (e[b + 1] === ":") {
791
+ const O = a(b + 2);
792
+ y.push({ kind: "unknown", text: e.slice(b, O) }), b = O;
585
793
  } 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;
794
+ const O = a(b + 1);
795
+ if (e[O] === "(") {
796
+ const E = Math.min(d(O), x);
797
+ y.push({ kind: "unknown", text: e.slice(b, E) }), b = E;
590
798
  } else
591
- a.push({ kind: "pseudo", name: t.slice(o + 1, v) }), o = v;
799
+ y.push({ kind: "pseudo", name: e.slice(b + 1, O) }), b = O;
592
800
  }
593
- else if (V.test(h)) {
594
- const v = c(o);
595
- a.push({ kind: "type", name: t.slice(o, v) }), o = v;
801
+ else if (ge.test($)) {
802
+ const O = a(b);
803
+ y.push({ kind: "type", name: e.slice(b, O) }), b = O;
596
804
  } else
597
- a.push({ kind: "unknown", text: h }), o++;
805
+ y.push({ kind: "unknown", text: $ }), b++;
598
806
  }
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++;
807
+ return { simple: y, next: b };
808
+ }
809
+ function f(h, x) {
810
+ const y = u(h, x), b = [];
811
+ let $ = "descendant", O = null, E = y.start;
812
+ for (; E < y.end; ) {
813
+ const R = e[E];
814
+ if (B(R)) {
815
+ E++;
608
816
  continue;
609
817
  }
610
- if (T === ">") {
611
- h = "child", y++;
818
+ if (R === ">") {
819
+ $ = "child", E++;
612
820
  continue;
613
821
  }
614
- if (T === "+" || T === "~") {
615
- v = T, y++;
822
+ if (R === "+" || R === "~") {
823
+ O = R, E++;
616
824
  continue;
617
825
  }
618
- const { simple: N, next: O } = f(y, a.end);
619
- if (O === y) {
620
- y++;
826
+ const { simple: D, next: p } = o(E, y.end);
827
+ if (p === E) {
828
+ E++;
621
829
  continue;
622
830
  }
623
- v !== null && (N.unshift({ kind: "unknown", text: v }), v = null), o.push({ combinator: h, simple: N }), h = "descendant", y = O;
831
+ O !== null && (D.unshift({ kind: "unknown", text: O }), O = null), b.push({ combinator: $, simple: D }), $ = "descendant", E = p;
624
832
  }
625
- return { parts: o, span: a };
833
+ return { parts: b, span: y };
626
834
  }
627
- function S(k, w) {
628
- const a = [];
629
- let o = k;
835
+ function w(h, x) {
836
+ const y = [];
837
+ let b = h;
630
838
  for (; ; ) {
631
- const h = Math.min(b(o, ","), w);
632
- if (a.push(x(o, h)), h >= w) break;
633
- o = h + 1;
839
+ const $ = Math.min(v(b, ","), x);
840
+ if (y.push(f(b, $)), $ >= x) break;
841
+ b = $ + 1;
634
842
  }
635
- return a;
843
+ return y;
636
844
  }
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 } };
845
+ function c() {
846
+ const h = s, x = a(s + 1), y = e.slice(s + 1, x), b = v(x, "{;");
847
+ if (b < e.length && e[b] === "{") {
848
+ const O = r(b);
849
+ return s = O, { kind: "unknown", span: { start: h, end: O } };
642
850
  }
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 } };
851
+ const $ = b < e.length ? b + 1 : e.length;
852
+ if (s = $, y === "import") {
853
+ const O = e.slice(x, $), E = /["']([^"']*)["']/.exec(O);
854
+ return E === null ? (m("@import without a quoted path", h, $), { kind: "unknown", span: { start: h, end: $ } }) : { kind: "import", url: E[1], span: { start: h, end: $ } };
647
855
  }
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,
856
+ return { kind: "unknown", span: { start: h, end: $ } };
857
+ }
858
+ function S() {
859
+ const h = s, x = v(h, "{");
860
+ if (x >= e.length)
861
+ return m("rule without a block", h, e.length), s = e.length, { kind: "unknown", span: { start: h, end: e.length } };
862
+ const y = u(h, x), b = r(x);
863
+ (b > e.length || e[b - 1] !== "}") && m("unterminated rule block", h, b);
864
+ const $ = {
865
+ selectors: w(y.start, y.end),
866
+ declarations: Se(e, x + 1, b - 1, m),
867
+ span: { start: y.start, end: b },
868
+ selectorSpan: y,
661
869
  selectorDirty: !1,
662
870
  declarationsDirty: !1
663
871
  };
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);
872
+ return s = b, { kind: "rule", rule: $ };
694
873
  }
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]]);
874
+ for (; g(), !(s >= e.length); )
875
+ l.push(e[s] === "@" ? c() : S());
876
+ return { sheet: { source: e, origin: n, items: l }, warnings: i };
737
877
  }
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) {
878
+ function ht(e, n, t) {
879
+ switch (e.kind) {
749
880
  case "universal":
750
881
  return !0;
751
882
  case "type":
752
- return n.name.local === t.name;
883
+ return t.typeNameOf(n) === e.name;
753
884
  case "class":
754
- return Ft(n).includes(t.name);
885
+ return t.classesOf(n).includes(e.name);
755
886
  case "name":
756
- return Lt(n) === t.name;
887
+ return t.idOf(n) === e.name;
757
888
  case "pseudo":
758
- return t.name === "root" ? n === e.root : e.activeStates.has(t.name);
889
+ return e.name === "root" ? t.isRoot(n) : t.statesOf(n).has(e.name);
759
890
  case "unknown":
760
891
  return !1;
761
892
  }
762
893
  }
763
- function Pt(t, n, e) {
764
- return t.simple.every((i) => jt(i, n, e));
894
+ function mt(e, n, t) {
895
+ return e.simple.every((i) => ht(i, n, t));
765
896
  }
766
- function L(t, n, e, i) {
767
- if (!Pt(t[n], e, i)) return !1;
897
+ function ne(e, n, t, i) {
898
+ if (!mt(e[n], t, i)) return !1;
768
899
  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;
900
+ const l = i.parentOf(t);
901
+ if (e[n].combinator === "child")
902
+ return l !== null && ne(e, n - 1, l, i);
903
+ for (let s = l; s !== null; s = i.parentOf(s))
904
+ if (ne(e, n - 1, s, i)) return !0;
774
905
  return !1;
775
906
  }
776
- function _t(t, n, e) {
777
- return t.parts.length === 0 ? !1 : L(t.parts, t.parts.length - 1, n, e);
907
+ function $e(e, n, t) {
908
+ return e.parts.length === 0 ? !1 : ne(e.parts, e.parts.length - 1, n, t);
909
+ }
910
+ function gt(e) {
911
+ const n = [];
912
+ for (const t of e.parts)
913
+ for (const i of t.simple)
914
+ i.kind === "pseudo" && i.name !== "root" && !n.includes(i.name) && n.push(i.name);
915
+ return n;
778
916
  }
779
- function Ht(t) {
780
- for (const n of t)
781
- for (const e of n.parts)
782
- for (const i of e.simple)
917
+ function wt(e) {
918
+ const n = [];
919
+ for (const t of e)
920
+ for (const i of t.parts)
921
+ for (const l of i.simple) {
922
+ if (l.kind !== "name" && l.kind !== "class" || !l.name.startsWith("unity-")) continue;
923
+ const s = l.kind === "name" ? `#${l.name}` : `.${l.name}`;
924
+ n.includes(s) || n.push(s);
925
+ }
926
+ return n;
927
+ }
928
+ function Te(e) {
929
+ for (const n of e)
930
+ for (const t of n.parts)
931
+ for (const i of t.simple)
783
932
  if (i.kind === "unknown") return i.text;
784
933
  return null;
785
934
  }
786
- function Bt(t) {
787
- const n = /* @__PURE__ */ new Map([[t, null]]), e = [t];
788
- for (; e.length > 0; ) {
789
- const i = e.pop();
935
+ function bt(e) {
936
+ const n = /* @__PURE__ */ new Map([[e, null]]), t = [e];
937
+ for (; t.length > 0; ) {
938
+ const i = t.pop();
790
939
  for (const l of i.children)
791
- n.set(l, i), e.push(l);
940
+ n.set(l, i), t.push(l);
792
941
  }
793
942
  return n;
794
943
  }
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) {
944
+ function xt(e) {
945
+ let n = 0, t = 0, i = 0;
946
+ for (const l of e.parts)
947
+ for (const s of l.simple)
948
+ switch (s.kind) {
800
949
  case "name":
801
950
  n++;
802
951
  break;
803
952
  case "class":
804
953
  case "pseudo":
805
- e++;
954
+ t++;
806
955
  break;
807
956
  case "type":
808
957
  i++;
809
958
  break;
810
959
  }
811
- return [n, e, i];
960
+ return [n, t, i];
812
961
  }
813
- function nt(t, n) {
814
- return t[0] - n[0] || t[1] - n[1] || t[2] - n[2];
962
+ function Oe(e, n) {
963
+ return e[0] - n[0] || e[1] - n[1] || e[2] - n[2];
815
964
  }
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) => {
965
+ const vt = [Number.MAX_SAFE_INTEGER, 0, 0], yt = re(ve, null, -1).sheet.items.flatMap(
966
+ (e, n) => e.kind === "rule" ? [{ rule: e.rule, sheet: -1, item: n, builtin: !0 }] : []
967
+ );
968
+ function kt(e) {
969
+ return ve.slice(e.selectorSpan.start, e.selectorSpan.end).trim();
970
+ }
971
+ function St(e, n, t, i) {
972
+ const l = (t == null ? void 0 : t.activeStates) ?? /* @__PURE__ */ new Set(), s = Object.entries((t == null ? void 0 : t.states) ?? {}), m = [];
973
+ for (const [r, a] of s) {
974
+ const d = re(`${r} {}`, null, -1).sheet.items.find((f) => f.kind === "rule"), o = d === void 0 ? r : Te(d.rule.selectors);
975
+ if (d === void 0 || o !== null) {
976
+ i.push({
977
+ kind: "unsupported-selector",
978
+ message: `states key "${r}" is not a usable USS selector; it is ignored`
979
+ });
980
+ continue;
981
+ }
982
+ m.push({ selectors: d.rule.selectors, states: a });
983
+ }
984
+ const g = /* @__PURE__ */ new Map(), v = (r) => r.attributes.some((a) => a.name === "enabled" && a.value === "false"), u = (r, a) => {
985
+ const d = a || v(r), o = new Set(l);
986
+ d && o.add("disabled");
987
+ for (const f of m)
988
+ if (f.selectors.some((w) => $e(w, { kind: "element", node: r }, n)))
989
+ for (const w of f.states) o.add(w);
990
+ g.set(r, o);
991
+ for (const f of r.children) u(f, d);
992
+ };
993
+ return u(e.root, !1), g;
994
+ }
995
+ function $t(e) {
996
+ const n = [], t = /* @__PURE__ */ new Map();
997
+ e.sheets.forEach((s, m) => {
998
+ s.origin !== null && !t.has(s.origin) && t.set(s.origin, m);
999
+ }), n.push(...yt);
1000
+ const i = /* @__PURE__ */ new Set(), l = (s) => {
1001
+ if (i.has(s)) return;
1002
+ i.add(s);
1003
+ const m = e.sheets[s];
1004
+ m !== void 0 && m.items.forEach((g, v) => {
827
1005
  if (g.kind === "rule")
828
- n.push({ rule: g.rule, sheet: r, item: b });
1006
+ n.push({ rule: g.rule, sheet: s, item: v });
829
1007
  else if (g.kind === "import") {
830
- const d = e.get(g.url);
831
- d !== void 0 && l(d);
1008
+ const u = t.get(g.url);
1009
+ u !== void 0 && l(u);
832
1010
  }
833
1011
  });
834
1012
  };
835
1013
  return l(0), n;
836
1014
  }
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"))
1015
+ function Tt(e) {
1016
+ return e.selectors.some(
1017
+ (n) => n.parts.some((t) => t.simple.some((i) => i.kind === "pseudo" && i.name === "root"))
840
1018
  );
841
1019
  }
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({
1020
+ function Ee(e, n) {
1021
+ const t = bt(e.root), i = [], l = /* @__PURE__ */ new Set(), s = (o) => {
1022
+ var w;
1023
+ const f = (w = o.attributes.find((c) => c.name === "class")) == null ? void 0 : w.value;
1024
+ return f === void 0 ? [] : f.split(/\s+/).filter((c) => c.length > 0);
1025
+ }, m = (o, f) => {
1026
+ var w;
1027
+ return (w = o.attributes.find((c) => c.name === f)) == null ? void 0 : w.value;
1028
+ }, g = {
1029
+ /**
1030
+ * The rule the measurement forced.
1031
+ *
1032
+ * An element from the file gets its *file* parent, even when its layout
1033
+ * parent is a part — `#Grid > .slot` reaches a slot inside a ScrollView in
1034
+ * Unity, so parts are transparent here. Parts themselves follow the real
1035
+ * chain: each sits inside the one before it, and the outermost inside its
1036
+ * owner. That is the hierarchy the dumps show, so descendant selectors like
1037
+ * `.panel #unity-content-viewport` behave as they do in Unity.
1038
+ */
1039
+ parentOf: (o) => {
1040
+ if (o.kind === "element") {
1041
+ const c = t.get(o.node) ?? null;
1042
+ return c === null ? null : { kind: "element", node: c };
1043
+ }
1044
+ if (o.depth === 0) return { kind: "element", node: o.owner };
1045
+ const w = F(o.owner).spec.parts[o.depth - 1];
1046
+ return { kind: "part", owner: o.owner, name: w.name, depth: o.depth - 1 };
1047
+ },
1048
+ isRoot: (o) => o.kind === "element" && o.node === e.root,
1049
+ // Unity's parts are VisualElements, so a `VisualElement` rule reaches them.
1050
+ // Not measured — `part-type-selector` is the case that will settle it.
1051
+ typeNameOf: (o) => o.kind === "element" ? o.node.name.local : "VisualElement",
1052
+ idOf: (o) => o.kind === "element" ? m(o.node, "name") : o.name,
1053
+ // Implicit classes are as real as written ones for matching: in Unity the
1054
+ // element genuinely carries them, which is why `.unity-button` in author USS
1055
+ // hits a plain `<ui:Button />`. Parts carry classes too in Unity, but which
1056
+ // ones is unmeasured, so none are claimed here.
1057
+ classesOf: (o) => o.kind === "element" ? [...s(o.node), ...We(o.node)] : []
1058
+ }, v = { ...g, statesOf: () => l }, u = St(e, v, n, i), r = {
1059
+ ...g,
1060
+ // A part inherits its owner's states: `SetEnabled(false)` disables the whole
1061
+ // subtree, and a part is inside it.
1062
+ statesOf: (o) => u.get(o.kind === "element" ? o.node : o.owner) ?? l
1063
+ }, a = [];
1064
+ let d = !1;
1065
+ for (const o of $t(e)) {
1066
+ if (o.builtin === !0) {
1067
+ a.push(o);
1068
+ continue;
1069
+ }
1070
+ const f = Te(o.rule.selectors);
1071
+ if (f !== null) {
1072
+ i.push({
853
1073
  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 }
1074
+ message: `"${f}" is not supported in USS; the whole rule is ignored`,
1075
+ at: { in: "uss", sheet: o.sheet, span: o.rule.selectorSpan }
856
1076
  });
857
1077
  continue;
858
1078
  }
859
- !p && Yt(g.rule) && (p = !0, l.push({
1079
+ !d && Tt(o.rule) && (d = !0, i.push({
860
1080
  kind: "version-dependent",
861
1081
  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);
1082
+ at: { in: "uss", sheet: o.sheet, span: o.rule.selectorSpan }
1083
+ })), a.push(o);
864
1084
  }
865
- return { ctx: i, usable: r, warnings: l };
1085
+ return { ctx: r, usable: a, warnings: i };
866
1086
  }
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);
1087
+ function Ot(e, n) {
1088
+ const t = n.attributes.find((l) => l.name === "style");
1089
+ if (t === void 0) return [];
1090
+ const i = pt(t);
1091
+ return i === null ? [] : Se(e.source, i, i + t.value.length);
872
1092
  }
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 });
1093
+ function Ne(e, n, t, i) {
1094
+ const l = [];
1095
+ let s = 0;
1096
+ const m = (g, v, u, r, a) => {
1097
+ l.push({ property: g, value: v, origin: u, rank: r, specificity: a, order: s++, winner: !1 });
878
1098
  };
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);
1099
+ if (n.kind === "part") {
1100
+ const g = F(n.owner).spec.parts[n.depth];
1101
+ for (const [v, u] of Object.entries((g == null ? void 0 : g.style) ?? {}))
1102
+ for (const [r, a] of J(v, u))
1103
+ m(
1104
+ r,
1105
+ a,
1106
+ {
1107
+ kind: "builtin-theme",
1108
+ selector: `#${n.name}`,
1109
+ property: r,
1110
+ unityVersion: Y
1111
+ },
1112
+ 0,
1113
+ [0, 0, 0]
1114
+ );
1115
+ }
1116
+ for (const g of t.usable) {
1117
+ let v = null, u = [];
1118
+ for (const r of g.rule.selectors) {
1119
+ if (!$e(r, n, t.ctx)) continue;
1120
+ const a = xt(r);
1121
+ (v === null || Oe(a, v) > 0) && (v = a, u = gt(r));
885
1122
  }
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);
1123
+ v !== null && (i == null || i.add(g), g.rule.declarations.forEach((r, a) => {
1124
+ for (const [d, o] of J(r.property, r.value)) {
1125
+ const f = g.builtin === !0 ? {
1126
+ kind: "builtin-theme",
1127
+ selector: kt(g.rule),
1128
+ property: d,
1129
+ unityVersion: Y
1130
+ } : {
1131
+ kind: "rule",
1132
+ sheet: g.sheet,
1133
+ item: g.item,
1134
+ declIndex: a,
1135
+ // Omitted rather than set to [] when unconditional, so the
1136
+ // common case stays the shape it has always been.
1137
+ ...u.length > 0 ? { states: u } : {}
1138
+ };
1139
+ m(d, o, f, g.builtin === !0 ? 0 : 1, v);
1140
+ }
1141
+ }));
1142
+ }
1143
+ if (n.kind === "element") {
1144
+ const g = n.node;
1145
+ Ot(e, g).forEach((v, u) => {
1146
+ for (const [r, a] of J(v.property, v.value))
1147
+ m(r, a, { kind: "inline", node: g.id, declIndex: u }, 1, vt);
889
1148
  });
890
1149
  }
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;
1150
+ return l;
895
1151
  }
896
- function st(t) {
1152
+ function Ce(e) {
897
1153
  const n = /* @__PURE__ */ new Map();
898
- for (const e of t) {
899
- const i = n.get(e.property);
1154
+ for (const t of e) {
1155
+ const i = n.get(t.property);
900
1156
  if (i === void 0) {
901
- n.set(e.property, e);
1157
+ n.set(t.property, t);
902
1158
  continue;
903
1159
  }
904
- const l = nt(e.specificity, i.specificity);
905
- (l > 0 || l === 0 && e.order > i.order) && n.set(e.property, e);
1160
+ if (t.rank !== i.rank) {
1161
+ t.rank > i.rank && n.set(t.property, t);
1162
+ continue;
1163
+ }
1164
+ const l = Oe(t.specificity, i.specificity);
1165
+ (l > 0 || l === 0 && t.order > i.order) && n.set(t.property, t);
906
1166
  }
907
- for (const e of n.values()) e.winner = !0;
1167
+ for (const t of n.values()) t.winner = !0;
908
1168
  return n;
909
1169
  }
910
- const Jt = /var\(\s*(--[^,)\s]+)\s*(?:,([^)]*))?\)/;
911
- function j(t, n, e = /* @__PURE__ */ new Set()) {
1170
+ const Et = /var\(\s*(--[^,)\s]+)\s*(?:,([^)]*))?\)/;
1171
+ function ie(e, n, t = /* @__PURE__ */ new Set()) {
912
1172
  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);
1173
+ let i = e;
1174
+ for (let s = 0; s < 32; s++) {
1175
+ const m = Et.exec(i);
1176
+ if (m === null) return i;
1177
+ const g = m[1], v = (l = m[2]) == null ? void 0 : l.trim();
1178
+ if (t.has(g)) return null;
1179
+ const u = /* @__PURE__ */ new Set([...t, g]), r = n.get(g), a = r !== void 0 ? ie(r, n, u) : v !== void 0 && v.length > 0 ? ie(v, n, u) : null;
1180
+ if (a === null) return null;
1181
+ i = i.slice(0, m.index) + a + i.slice(m.index + m[0].length);
922
1182
  }
923
1183
  return null;
924
1184
  }
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) {
1185
+ function Nt(e, n) {
1186
+ const t = Ee(e, n), i = [...t.warnings], l = /* @__PURE__ */ new Map();
1187
+ let s = !1;
1188
+ const m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), v = (r, a, d) => {
1189
+ const o = Ne(e, r, t, g);
1190
+ !s && o.some((h) => h.origin.kind === "builtin-theme") && (s = !0);
1191
+ const f = Ce(o), w = /* @__PURE__ */ new Map();
1192
+ for (const [h, x] of a)
1193
+ h.startsWith("--") && w.set(h, x.value);
1194
+ for (const [h, x] of f)
1195
+ h.startsWith("--") && w.set(h, x.value);
1196
+ const c = /* @__PURE__ */ new Map();
1197
+ for (const [h, x] of a) c.set(h, x);
1198
+ for (const [h, x] of f) {
1199
+ const y = ie(x.value, w);
1200
+ if (y === null) {
937
1201
  i.push({
938
1202
  kind: "unsupported-property",
939
- message: `${u}: var() reference could not be resolved; declaration dropped`,
940
- node: p.id
1203
+ message: `${h}: var() reference could not be resolved; declaration dropped`,
1204
+ node: d
941
1205
  });
942
1206
  continue;
943
1207
  }
944
- s.set(u, { value: x, origin: f.origin });
1208
+ c.set(h, { value: y, origin: x.origin });
945
1209
  }
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 }
1210
+ const S = /* @__PURE__ */ new Map();
1211
+ for (const [h, x] of c)
1212
+ He(h) && S.set(h, {
1213
+ value: x.value,
1214
+ origin: { kind: "inherited", from: d, origin: x.origin }
952
1215
  });
953
- for (const u of p.children) r(u, c);
1216
+ return { computed: c, forChildren: S };
1217
+ }, u = (r, a) => {
1218
+ const d = v({ kind: "element", node: r }, a, r.id);
1219
+ l.set(r.id, d.computed);
1220
+ let o = d.forChildren;
1221
+ const f = F(r).spec.parts;
1222
+ if (f.length > 0) {
1223
+ const w = /* @__PURE__ */ new Map();
1224
+ f.forEach((c, S) => {
1225
+ const h = v(
1226
+ { kind: "part", owner: r, name: c.name, depth: S },
1227
+ o,
1228
+ r.id
1229
+ );
1230
+ w.set(c.name, h.computed), o = h.forChildren;
1231
+ }), m.set(r.id, w);
1232
+ }
1233
+ for (const w of r.children) u(w, o);
954
1234
  };
955
- return r(t.root, /* @__PURE__ */ new Map()), { styles: l, warnings: i };
1235
+ u(e.root, /* @__PURE__ */ new Map()), s && i.push({
1236
+ kind: "version-dependent",
1237
+ message: `Unity's control defaults were applied, as measured on ${Y} (Unity ships these as a theme stylesheet). Other versions may use different values; see src/controls/theme.ts.`
1238
+ });
1239
+ for (const r of t.usable) {
1240
+ if (r.builtin === !0 || g.has(r)) continue;
1241
+ const a = wt(r.rule.selectors);
1242
+ a.length !== 0 && i.push({
1243
+ kind: "unsupported-selector",
1244
+ message: `${a.join(", ")} matched nothing. Those names belong to the elements a control builds for itself, and only controls with a renderer of their own have them — ${Be().join(", ")}. Anything else is drawn as a plain box and has no parts to style.`,
1245
+ at: { in: "uss", sheet: r.sheet, span: r.rule.selectorSpan }
1246
+ });
1247
+ }
1248
+ return { styles: l, partStyles: m, warnings: i };
956
1249
  }
957
- function ae(t, n, e, i) {
958
- const l = it(t, i), r = rt(t, n, l).filter(
959
- (p) => p.property === e
1250
+ function zt(e, n, t, i) {
1251
+ const l = Ee(e, i), s = Ne(e, { kind: "element", node: n }, l).filter(
1252
+ (m) => m.property === t
960
1253
  );
961
- return st(r), r;
1254
+ return Ce(s), s;
962
1255
  }
963
- function J(t) {
964
- return t !== void 0 && /[A-Za-z0-9_.:-]/.test(t);
1256
+ const _t = [
1257
+ {
1258
+ id: "text-metrics",
1259
+ kind: "unreproducible",
1260
+ summary: "Text-dependent layout can be a few pixels off Unity.",
1261
+ detail: "A browser measures text with its own font stack; Unity measures with its font asset. Both engines apply the same layout rule, so this is not a layout defect — it is measured in docs/accuracy.md at 10 of 16 known divergent values, all traced to this one cause."
1262
+ },
1263
+ {
1264
+ id: "wrap-container-height",
1265
+ kind: "unspecified",
1266
+ summary: "A wrapping container's height can differ from Unity.",
1267
+ detail: "Unity's own rule for sizing a container whose children wrap is not yet identified, so there is no confirmed target to match. Tracked in docs/accuracy.md as the one unresolved divergence."
1268
+ },
1269
+ {
1270
+ id: "yoga-percent-without-parent-size",
1271
+ kind: "upstream",
1272
+ summary: "A main-axis percentage against an unsized parent can resolve differently.",
1273
+ detail: "The yoga-layout version this package depends on resolves a main-axis percentage against an indefinite parent differently from the Yoga vendored inside Unity 6000.0.40f1. Not configurable: no available setting reproduces Unity's answer without breaking cases that currently match. Fully deterministic and pinned to a case in docs/accuracy.md — this always reproduces the same way, it just cannot be fixed from inside this repository."
1274
+ }
1275
+ ];
1276
+ function we(e) {
1277
+ return e !== void 0 && /[A-Za-z0-9_.:-]/.test(e);
965
1278
  }
966
- function X(t) {
967
- return t !== void 0 && /[A-Za-z_]/.test(t);
1279
+ function be(e) {
1280
+ return e !== void 0 && /[A-Za-z_]/.test(e);
968
1281
  }
969
- function Kt(t) {
970
- return t === " " || t === " " || t === `
971
- ` || t === "\r";
1282
+ function Ct(e) {
1283
+ return e === " " || e === " " || e === `
1284
+ ` || e === "\r";
972
1285
  }
973
- function Qt(t) {
1286
+ function At(e) {
974
1287
  const n = [];
975
- let e = 0, i = 0;
1288
+ let t = 0, i = 0;
976
1289
  const l = () => i++;
977
- function r(c, u, f) {
1290
+ function s(a, d, o) {
978
1291
  n.push({
979
1292
  kind: "malformed",
980
- message: c,
981
- at: { in: "uxml", span: { start: u, end: f } }
1293
+ message: a,
1294
+ at: { in: "uxml", span: { start: d, end: o } }
982
1295
  });
983
1296
  }
984
- function p() {
985
- for (; Kt(t[e]); ) e++;
1297
+ function m() {
1298
+ for (; Ct(e[t]); ) t++;
986
1299
  }
987
1300
  function g() {
988
1301
  for (; ; ) {
989
- const c = t.indexOf("<", e);
990
- if (c < 0) {
991
- e = t.length;
1302
+ const a = e.indexOf("<", t);
1303
+ if (a < 0) {
1304
+ t = e.length;
992
1305
  return;
993
1306
  }
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;
1307
+ const d = e[a + 1];
1308
+ if (d === "!") {
1309
+ if (e.startsWith("<!--", a)) {
1310
+ const o = e.indexOf("-->", a + 4);
1311
+ t = o < 0 ? e.length : o + 3;
1312
+ } else if (e.startsWith("<![CDATA[", a)) {
1313
+ const o = e.indexOf("]]>", a + 9);
1314
+ t = o < 0 ? e.length : o + 3;
1002
1315
  } else {
1003
- const f = t.indexOf(">", c);
1004
- e = f < 0 ? t.length : f + 1;
1316
+ const o = e.indexOf(">", a);
1317
+ t = o < 0 ? e.length : o + 1;
1005
1318
  }
1006
1319
  continue;
1007
1320
  }
1008
- if (u === "?") {
1009
- const f = t.indexOf("?>", c + 2);
1010
- e = f < 0 ? t.length : f + 2;
1321
+ if (d === "?") {
1322
+ const o = e.indexOf("?>", a + 2);
1323
+ t = o < 0 ? e.length : o + 2;
1011
1324
  continue;
1012
1325
  }
1013
- e = c;
1326
+ t = a;
1014
1327
  return;
1015
1328
  }
1016
1329
  }
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;
1330
+ function v() {
1331
+ const a = t;
1332
+ for (; we(e[t]); ) t++;
1333
+ const d = e.slice(a, t), o = d.indexOf(":");
1334
+ return o < 0 ? { prefix: null, local: d } : { prefix: d.slice(0, o), local: d.slice(o + 1) };
1335
+ }
1336
+ function u() {
1337
+ const a = t;
1338
+ for (; we(e[t]); ) t++;
1339
+ if (t === a) return null;
1340
+ const d = e.slice(a, t), o = t;
1341
+ if (m(), e[t] !== "=")
1342
+ return t = o, s(`attribute "${d}" has no value`, a, o), { name: d, value: "", span: { start: a, end: o } };
1343
+ t++, m();
1344
+ const f = e[t];
1345
+ if (f !== '"' && f !== "'")
1346
+ return s(`attribute "${d}" has an unquoted value`, a, t), { name: d, value: "", span: { start: a, end: t } };
1347
+ t++;
1348
+ const w = t, c = e.indexOf(f, t);
1349
+ return c < 0 ? (s(`attribute "${d}" has an unterminated value`, a, e.length), t = e.length, { name: d, value: e.slice(w), span: { start: a, end: t } }) : (t = c + 1, { name: d, value: e.slice(w, c), span: { start: a, end: t } });
1350
+ }
1351
+ function r() {
1352
+ const a = t;
1353
+ t++;
1354
+ const d = v(), o = [];
1355
+ let f = !1;
1043
1356
  for (; ; ) {
1044
- p();
1045
- const a = t[e];
1046
- if (a === void 0) {
1047
- r("unterminated open tag", c, t.length);
1357
+ m();
1358
+ const y = e[t];
1359
+ if (y === void 0) {
1360
+ s("unterminated open tag", a, e.length);
1048
1361
  break;
1049
1362
  }
1050
- if (a === ">") {
1051
- e++;
1363
+ if (y === ">") {
1364
+ t++;
1052
1365
  break;
1053
1366
  }
1054
- if (a === "/" && t[e + 1] === ">") {
1055
- e += 2, x = !0;
1367
+ if (y === "/" && e[t + 1] === ">") {
1368
+ t += 2, f = !0;
1056
1369
  break;
1057
1370
  }
1058
- const o = d();
1059
- if (o === null) {
1060
- e++;
1371
+ const b = u();
1372
+ if (b === null) {
1373
+ t++;
1061
1374
  continue;
1062
1375
  }
1063
- f.push(o);
1376
+ o.push(b);
1064
1377
  }
1065
- const S = { start: c, end: e };
1066
- if (x)
1378
+ const w = { start: a, end: t };
1379
+ if (f)
1067
1380
  return {
1068
1381
  id: l(),
1069
- name: u,
1070
- attributes: f,
1382
+ name: d,
1383
+ attributes: o,
1071
1384
  children: [],
1072
- spans: { openTag: S, inner: { start: e, end: e }, closeTag: null },
1385
+ spans: { openTag: w, inner: { start: t, end: t }, closeTag: null },
1073
1386
  tagDirty: !1,
1074
1387
  childrenDirty: !1
1075
1388
  };
1076
- const m = e, $ = [];
1389
+ const c = t, S = [];
1077
1390
  for (; ; ) {
1078
- if (g(), e >= t.length) {
1079
- r(`unterminated element <${ot(u)}>`, c, t.length);
1391
+ if (g(), t >= e.length) {
1392
+ s(`unterminated element <${Ae(d)}>`, a, e.length);
1080
1393
  break;
1081
1394
  }
1082
- const a = t[e + 1];
1083
- if (a === "/") break;
1084
- if (!X(a)) {
1085
- e++;
1395
+ const y = e[t + 1];
1396
+ if (y === "/") break;
1397
+ if (!be(y)) {
1398
+ t++;
1086
1399
  continue;
1087
1400
  }
1088
- $.push(s());
1401
+ S.push(r());
1089
1402
  }
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;
1403
+ const h = t;
1404
+ let x = null;
1405
+ if (e.startsWith("</", t)) {
1406
+ const y = e.indexOf(">", t), b = y < 0 ? e.length : y + 1;
1407
+ y < 0 && s("unterminated end tag", t, b), x = { start: t, end: b }, t = b;
1095
1408
  }
1096
1409
  return {
1097
1410
  id: l(),
1098
- name: u,
1099
- attributes: f,
1100
- children: $,
1101
- spans: { openTag: S, inner: { start: m, end: k }, closeTag: w },
1411
+ name: d,
1412
+ attributes: o,
1413
+ children: S,
1414
+ spans: { openTag: w, inner: { start: c, end: h }, closeTag: x },
1102
1415
  tagDirty: !1,
1103
1416
  childrenDirty: !1
1104
1417
  };
1105
1418
  }
1106
- return g(), e < t.length && X(t[e + 1]) ? { root: s(), warnings: n } : (r("no root element", 0, 0), {
1419
+ return g(), t < e.length && be(e[t + 1]) ? { root: r(), warnings: n } : (s("no root element", 0, 0), {
1107
1420
  root: {
1108
1421
  id: l(),
1109
1422
  name: { prefix: null, local: "" },
@@ -1116,177 +1429,202 @@ function Qt(t) {
1116
1429
  warnings: n
1117
1430
  });
1118
1431
  }
1119
- function ot(t) {
1120
- return t.prefix === null ? t.local : `${t.prefix}:${t.local}`;
1432
+ function Ae(e) {
1433
+ return e.prefix === null ? e.local : `${e.prefix}:${e.local}`;
1121
1434
  }
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;
1435
+ function It(e, n) {
1436
+ const t = (u) => e.slice(u.start, u.end);
1437
+ function i(u) {
1438
+ return u.spans.closeTag !== null ? u.spans.closeTag.end : Math.max(u.spans.openTag.end, u.spans.inner.end);
1439
+ }
1440
+ function l(u) {
1441
+ return u.includes('"') ? u.includes("'") ? `"${u.replace(/"/g, "&quot;")}"` : `'${u}'` : `"${u}"`;
1442
+ }
1443
+ function s(u) {
1444
+ const r = u.attributes.map((d) => ` ${d.name}=${l(d.value)}`).join(""), a = Ae(u.name);
1445
+ return u.spans.closeTag === null ? `<${a}${r} />` : `<${a}${r}>`;
1446
+ }
1447
+ function m(u) {
1448
+ var o, f;
1449
+ const r = t(u.spans.inner), a = ((o = /^[ \t]*\r?\n[ \t]*/.exec(r)) == null ? void 0 : o[0]) ?? "", d = ((f = /\r?\n[ \t]*$/.exec(r)) == null ? void 0 : f[0]) ?? "";
1450
+ return { between: a, before: a, after: d };
1451
+ }
1452
+ function g(u) {
1453
+ const { inner: r } = u.spans;
1454
+ if (u.children.length === 0) return t(r);
1455
+ if (u.childrenDirty) {
1456
+ const { between: o, before: f, after: w } = m(u);
1457
+ return f + u.children.map(v).join(o) + w;
1145
1458
  }
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);
1459
+ let a = "", d = r.start;
1460
+ for (const o of u.children)
1461
+ a += e.slice(d, o.spans.openTag.start), a += v(o), d = i(o);
1462
+ return a + e.slice(d, r.end);
1150
1463
  }
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;
1464
+ function v(u) {
1465
+ const r = u.tagDirty ? s(u) : t(u.spans.openTag), a = u.spans.closeTag === null ? "" : t(u.spans.closeTag);
1466
+ return r + g(u) + a;
1154
1467
  }
1155
- return t.slice(0, n.spans.openTag.start) + b(n) + t.slice(i(n));
1468
+ return e.slice(0, n.spans.openTag.start) + v(n) + e.slice(i(n));
1156
1469
  }
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) {
1470
+ function Mt(e) {
1471
+ const n = e.source, t = (r) => n.slice(r.start, r.end);
1472
+ function i(r) {
1473
+ return r.parts.map((a, d) => {
1474
+ const o = d === 0 ? "" : a.combinator === "child" ? " > " : " ", f = a.simple.map((w) => {
1475
+ switch (w.kind) {
1163
1476
  case "universal":
1164
1477
  return "*";
1165
1478
  case "type":
1166
- return S.name;
1479
+ return w.name;
1167
1480
  case "class":
1168
- return `.${S.name}`;
1481
+ return `.${w.name}`;
1169
1482
  case "name":
1170
- return `#${S.name}`;
1483
+ return `#${w.name}`;
1171
1484
  case "pseudo":
1172
- return `:${S.name}`;
1485
+ return `:${w.name}`;
1173
1486
  case "unknown":
1174
- return S.text;
1487
+ return w.text;
1175
1488
  }
1176
1489
  }).join("");
1177
- return f + x;
1490
+ return o + f;
1178
1491
  }).join("");
1179
1492
  }
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}${$}}`;
1493
+ function l(r) {
1494
+ var c, S;
1495
+ const a = r.declarations[0];
1496
+ if (a === void 0) return { between: "", before: "", after: "" };
1497
+ const d = n.lastIndexOf(`
1498
+ `, a.span.start), o = d < 0 ? "" : n.slice(d, a.span.start), f = n.slice(r.selectorSpan.end, r.span.end), w = ((S = (c = /\r?\n[ \t]*\}$/.exec(f)) == null ? void 0 : c[0]) == null ? void 0 : S.replace(/\}$/, "")) ?? "";
1499
+ return { between: `;${o}`, before: o, after: `;${w}` };
1500
+ }
1501
+ function s(r) {
1502
+ const a = r.selectorDirty ? r.selectors.map(i).join(", ") : t(r.selectorSpan);
1503
+ if (r.declarations.length === 0)
1504
+ return a + n.slice(r.selectorSpan.end, r.span.end);
1505
+ const d = n.slice(r.selectorSpan.end, r.declarations[0].span.start);
1506
+ if (r.declarationsDirty) {
1507
+ const { between: w, before: c, after: S } = l(r), h = d.slice(0, d.indexOf("{") + 1), x = r.declarations.map(m).join(w);
1508
+ return `${a}${h}${c}${x}${S}}`;
1196
1509
  }
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);
1510
+ let o = a, f = r.selectorSpan.end;
1511
+ for (const w of r.declarations)
1512
+ o += n.slice(f, w.span.start), o += m(w), f = w.span.end;
1513
+ return o + n.slice(f, r.span.end);
1514
+ }
1515
+ function m(r) {
1516
+ return r.dirty ? `${r.property}: ${r.value}` : t(r.span);
1201
1517
  }
1202
- function p(s) {
1203
- return s.dirty ? `${s.property}: ${s.value}` : e(s.span);
1518
+ function g(r) {
1519
+ return r.kind === "rule" ? s(r.rule) : t(r.span);
1204
1520
  }
1205
- function g(s) {
1206
- return s.kind === "rule" ? r(s.rule) : e(s.span);
1521
+ let v = "", u = 0;
1522
+ for (const r of e.items) {
1523
+ const a = r.kind === "rule" ? r.rule.span : r.span;
1524
+ v += n.slice(u, a.start), v += g(r), u = a.end;
1207
1525
  }
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;
1526
+ return v + n.slice(u);
1527
+ }
1528
+ function Ie(e, n = []) {
1529
+ var t;
1530
+ if (e.name.local === "Style") {
1531
+ const i = (t = e.attributes.find((l) => l.name === "src")) == null ? void 0 : t.value;
1532
+ i !== void 0 && i.length > 0 && n.push(ye(i));
1212
1533
  }
1213
- return b + n.slice(d);
1534
+ for (const i of e.children) Ie(i, n);
1535
+ return n;
1214
1536
  }
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 }
1537
+ function jt(e, n, t) {
1538
+ var g, v;
1539
+ const i = At(e), l = [...i.warnings], s = [], m = [];
1540
+ for (const u of Ie(i.root)) {
1541
+ const r = ((g = t == null ? void 0 : t.resolveImport) == null ? void 0 : g.call(t, u)) ?? null;
1542
+ if (r === null) {
1543
+ l.push({
1544
+ kind: "import-unresolved",
1545
+ message: (t == null ? void 0 : t.resolveImport) === void 0 ? `<Style src="${u}"> was not loaded: pass resolveImport to read it, or pass the stylesheet text directly. Until then this document renders unstyled.` : `<Style src="${u}"> could not be resolved`,
1546
+ node: i.root.id
1547
+ });
1548
+ continue;
1549
+ }
1550
+ m.push({ text: r, origin: u });
1551
+ }
1552
+ if (n !== void 0 || m.length > 0) {
1553
+ const u = /* @__PURE__ */ new Set(), r = [
1554
+ ...m,
1555
+ ...n === void 0 ? [] : [{ text: n, origin: null }]
1221
1556
  ];
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) {
1557
+ for (; r.length > 0; ) {
1558
+ const a = r.shift(), d = s.length, o = re(a.text, a.origin, d);
1559
+ s.push(o.sheet), l.push(...o.warnings);
1560
+ for (const f of o.sheet.items) {
1561
+ if (f.kind !== "import" || u.has(f.url)) continue;
1562
+ u.add(f.url);
1563
+ const w = ((v = t == null ? void 0 : t.resolveImport) == null ? void 0 : v.call(t, f.url)) ?? null;
1564
+ if (w === null) {
1230
1565
  l.push({
1231
1566
  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 }
1567
+ message: (t == null ? void 0 : t.resolveImport) === void 0 ? `@import "${f.url}" was not loaded: pass resolveImport to read it` : `@import "${f.url}" could not be resolved`,
1568
+ at: { in: "uss", sheet: d, span: f.span }
1234
1569
  });
1235
1570
  continue;
1236
1571
  }
1237
- b.push({ text: f, origin: u.url });
1572
+ r.push({ text: w, origin: f.url });
1238
1573
  }
1239
1574
  }
1240
1575
  }
1241
- return { source: t, root: i.root, sheets: r, warnings: l };
1576
+ return { source: e, root: i.root, sheets: s, warnings: l };
1242
1577
  }
1243
- function ce(t) {
1244
- const n = t.sheets[0];
1578
+ function Wt(e) {
1579
+ const n = e.sheets[0];
1245
1580
  return {
1246
- uxml: te(t.source, t.root),
1581
+ uxml: It(e.source, e.root),
1247
1582
  // Only the sheet passed to `parse` round-trips. `@import`ed sheets (Phase 3)
1248
1583
  // are separate files and are not this function's to write.
1249
- uss: n === void 0 ? "" : ee(n)
1584
+ uss: n === void 0 ? "" : Mt(n)
1250
1585
  };
1251
1586
  }
1252
- function ue(t, n, e) {
1253
- const i = n.ownerDocument, l = (e == null ? void 0 : e.size) ?? {
1587
+ function Bt(e, n, t) {
1588
+ const i = n.ownerDocument, l = (t == null ? void 0 : t.size) ?? {
1254
1589
  width: n.clientWidth,
1255
1590
  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;
1591
+ }, s = Nt(e, {
1592
+ ...(t == null ? void 0 : t.activeStates) === void 0 ? {} : { activeStates: t.activeStates },
1593
+ ...(t == null ? void 0 : t.states) === void 0 ? {} : { states: t.states }
1594
+ }), m = (t == null ? void 0 : t.measureText) ?? nt(i), g = et(e.root, s.styles, s.partStyles, { size: l, measureText: m });
1595
+ let v;
1261
1596
  try {
1262
- b = It(t.root, g.boxes, r.styles, n, {
1597
+ v = ft(e.root, g.boxes, g.parts, s.styles, n, {
1263
1598
  document: i,
1264
- resolveAsset: e == null ? void 0 : e.resolveAsset
1599
+ resolveAsset: t == null ? void 0 : t.resolveAsset
1265
1600
  });
1266
- } catch (s) {
1267
- throw g.dispose(), s;
1601
+ } catch (r) {
1602
+ throw g.dispose(), r;
1268
1603
  }
1269
- let d = !1;
1604
+ let u = !1;
1270
1605
  return {
1271
- warnings: [...r.warnings, ...g.warnings, ...b.warnings],
1272
- elements: b.elements,
1606
+ warnings: [...s.warnings, ...g.warnings, ...v.warnings],
1607
+ elements: v.elements,
1273
1608
  boxes: g.boxes,
1274
1609
  dispose() {
1275
- d || (d = !0, g.dispose(), n.replaceChildren());
1610
+ u || (u = !0, g.dispose(), n.replaceChildren());
1276
1611
  }
1277
1612
  };
1278
1613
  }
1279
1614
  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
1615
+ _t as KNOWN_DIVERGENCES,
1616
+ ct as NODE_ATTRIBUTE,
1617
+ ut as PART_ATTRIBUTE,
1618
+ dt as PART_OWNER_ATTRIBUTE,
1619
+ nt as createDefaultMeasureText,
1620
+ zt as explainProperty,
1621
+ He as isInherited,
1622
+ Dt as isLayoutEngineReady,
1623
+ Lt as liveNodeCount,
1624
+ Ut as loadLayoutEngine,
1625
+ jt as parse,
1626
+ Bt as render,
1627
+ Nt as resolveStyles,
1628
+ Wt as serialize,
1629
+ Be as supportedControlNames
1292
1630
  };