monowind 0.1.0 → 0.1.2

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
@@ -8,13 +8,12 @@ function t(t, n) {
8
8
  function n(t, n) {
9
9
  return e(n * t / 100);
10
10
  }
11
- function r(e) {
12
- let t = document.createElement("span");
13
- t.setAttribute("aria-hidden", "true"), t.style.cssText = "position:absolute!important;visibility:hidden!important;pointer-events:none!important;white-space:pre!important;overflow-wrap:normal!important;top:0!important;left:0!important;padding:0!important;margin:0!important;border:0!important;", t.textContent = "M".repeat(100), e.appendChild(t);
14
- let n = t.getBoundingClientRect();
15
- return e.removeChild(t), {
11
+ function r(e, t) {
12
+ let n = t.getBoundingClientRect(), r = parseFloat(getComputedStyle(e).letterSpacing) || 0;
13
+ return {
16
14
  width: n.width / 100,
17
- height: n.height
15
+ height: n.height,
16
+ letterSpacing: r
18
17
  };
19
18
  }
20
19
  function i() {
@@ -22,219 +21,248 @@ function i() {
22
21
  }
23
22
  //#endregion
24
23
  //#region src/wrap.ts
25
- function a(e, t) {
26
- return e.trim() === "" ? [] : e.split("\n").flatMap((e) => c(e, t));
27
- }
28
- function o(e, t) {
29
- return a(e, t).length;
30
- }
31
- function s(e) {
32
- let t = [], n = 0, r = /-+/g, i;
33
- for (; (i = r.exec(e)) !== null;) {
34
- let r = i.index + i[0].length;
35
- r < e.length && !/[0-9]/.test(e[r]) && (t.push(e.slice(n, r)), n = r);
36
- }
37
- return t.push(e.slice(n)), t;
38
- }
39
- function c(e, t) {
40
- let n = e.split(/[ \t\r\n\f]+/).filter(Boolean);
41
- if (n.length === 0) return [""];
42
- if (t <= 0) return [n.join(" ")];
43
- let r = [], i = "";
44
- for (let e of n) {
45
- let n = !1;
46
- for (let a of s(e)) {
47
- let e = +(!n && i !== "");
48
- if (i !== "" && i.length + e + a.length <= t) i += e ? ` ${a}` : a;
49
- else {
50
- for (i !== "" && r.push(i); a.length > t;) r.push(a.slice(0, t)), a = a.slice(t);
51
- i = a;
52
- }
53
- n = !0;
54
- }
55
- }
56
- return r.push(i), r;
57
- }
58
- //#endregion
59
- //#region src/layout.ts
60
- function l(e, t) {
61
- return u(e, t, void 0, 0, 0, "fill", {
62
- maxContent: /* @__PURE__ */ new WeakMap(),
63
- minContent: /* @__PURE__ */ new WeakMap()
64
- }), { height: e.localRect.height };
65
- }
66
- function u(e, t, n, r, i, a, s, c) {
67
- let l = e.style, u = c?.height, p = h(l.minWidth, t) ?? 0, m = h(l.maxWidth, t), _ = h(l.minHeight, n) ?? 0, b = h(l.maxHeight, n), x = {
68
- top: f(l.padding.top, t),
69
- right: f(l.padding.right, t),
70
- bottom: f(l.padding.bottom, t),
71
- left: f(l.padding.left, t)
72
- };
73
- e.resolvedPadding = x;
74
- let S = c?.width ?? d(E(l, t, a, e, s), p, m), C = D(l, n), w = L(S, u ?? C ?? (_ > 0 ? _ : void 0) ?? Infinity, l.border, x), T;
75
- if (e.children.length === 0) T = e.text ? l.whiteSpace === "nowrap" ? e.text.split("\n").length : o(e.text, w.width) : e.intrinsicHeight;
76
- else if (l.display === "flex" && l.flexDirection === "row") T = v(e, w.width, w.height, l.border, x, s);
77
- else if (l.display === "flex" && l.flexDirection === "column") {
78
- let t = u !== void 0 || C !== void 0;
79
- T = y(e, w.width, w.height, t, l.border, x, s);
80
- } else T = g(e, w.width, l.border, x, s);
81
- let O = T + l.border.top + l.border.bottom + x.top + x.bottom, k = u ?? C ?? O;
82
- e.unclampedHeight = k, e.localRect = {
83
- x: r,
84
- y: i,
85
- width: S,
86
- height: d(k, _, b)
87
- };
24
+ function a(e) {
25
+ let t = [], n = 0;
26
+ for (let r = 0; r <= e.length; r++) (r === e.length || e[r] === "\n") && (t.push({
27
+ start: n,
28
+ end: r
29
+ }), n = r + 1);
30
+ return t;
88
31
  }
89
- function d(e, t, n) {
90
- return Math.max(t, n === void 0 ? e : Math.min(e, n));
32
+ function o(e, t, n = {}) {
33
+ if (!/[^ \t\r\n\f]/.test(e)) return [];
34
+ let r = [], i = 0;
35
+ for (let a = 0; a <= e.length; a++) (a === e.length || e[a] === "\n") && (r.push(...h(e, i, a, t, n)), i = a + 1);
36
+ return r;
91
37
  }
92
- function f(e, t) {
93
- return typeof e == "number" ? e : t === void 0 || !Number.isFinite(t) ? 0 : n(e.percent, t);
38
+ function s(e, t, n) {
39
+ if (!n) return t - e;
40
+ let r = 0;
41
+ for (let i = e; i < t; i++) r += n[i] ?? 1;
42
+ return r;
94
43
  }
95
- function p(e, t) {
96
- let n = (e) => e === null ? null : f(e, t);
97
- return {
98
- top: n(e.top),
99
- right: n(e.right),
100
- bottom: n(e.bottom),
101
- left: n(e.left)
102
- };
44
+ function c(e, t, n, r = 0) {
45
+ return t <= e ? 0 : s(e, t, n) - Math.min(r, l(t - 1, n));
103
46
  }
104
- function m(e) {
105
- return typeof e == "number" ? e : 0;
47
+ function l(e, t) {
48
+ return t ? (t[e] ?? 1) - 1 : 0;
106
49
  }
107
- function h(e, t) {
108
- if (e !== void 0 && e !== "auto") return typeof e == "number" ? e : t === void 0 ? void 0 : n(e.percent, t);
50
+ function u(e, t = {}) {
51
+ let { advances: n, tracking: r = 0 } = t, i = 0;
52
+ for (let t of m(e, 0, e.length)) for (let a of f(e, t.start, t.end)) i = Math.max(i, c(a.start, a.end, n, r));
53
+ return i;
109
54
  }
110
- function g(e, t, n, r, i) {
111
- let a = n.left + r.left, o = n.top + r.top, s = o, c = null;
112
- for (let n of e.children) {
113
- let e = p(n.style.margin, t), r = e.top ?? 0, o = e.bottom ?? 0, l = e.left ?? 0, d = e.right ?? 0;
114
- u(n, Math.max(0, t - l - d), void 0, 0, 0, "fill", i);
115
- let f = t - n.localRect.width, m = e.left === null && e.right === null, h = e.left === null && e.right !== null;
116
- e.right === null && e.left;
117
- let g;
118
- g = m ? Math.floor(f / 2) : h ? f - d : l, s += c === null ? r : _(c, r), n.localRect = {
119
- ...n.localRect,
120
- x: a + g,
121
- y: s
122
- }, s += n.localRect.height, c = o;
55
+ function d(e, t) {
56
+ let n = 0;
57
+ for (let r = 0; r < e.length; r++) e[r] === "" && (t(r, n), n++);
58
+ }
59
+ function f(e, t, n) {
60
+ let r = [], i = t;
61
+ for (let a = t; a < n; a++) {
62
+ if (e[a] === "") {
63
+ a > i && r.push({
64
+ start: i,
65
+ end: a
66
+ }), r.push({
67
+ start: a,
68
+ end: a + 1
69
+ }), i = a + 1;
70
+ continue;
71
+ }
72
+ if (e[a] !== "-") continue;
73
+ for (; a + 1 < n && e[a + 1] === "-";) a++;
74
+ let t = a + 1;
75
+ t < n && !/[0-9]/.test(e[t]) && (r.push({
76
+ start: i,
77
+ end: t
78
+ }), i = t);
123
79
  }
124
- return c !== null && (s += c), s - o;
125
- }
126
- function _(e, t) {
127
- return e >= 0 && t >= 0 ? Math.max(e, t) : e <= 0 && t <= 0 ? Math.min(e, t) : e + t;
80
+ return r.push({
81
+ start: i,
82
+ end: n
83
+ }), r;
84
+ }
85
+ var p = /[ \t\r\n\f]/;
86
+ function m(e, t, n) {
87
+ let r = [], i = t;
88
+ for (; i < n;) {
89
+ for (; i < n && p.test(e[i]);) i++;
90
+ if (i >= n) break;
91
+ let t = i;
92
+ for (; i < n && !p.test(e[i]);) i++;
93
+ r.push({
94
+ start: t,
95
+ end: i
96
+ });
97
+ }
98
+ return r;
99
+ }
100
+ function h(e, t, n, r, { advances: i, tracking: a = 0 }) {
101
+ let o = m(e, t, n);
102
+ if (o.length === 0) return [{
103
+ start: t,
104
+ end: t
105
+ }];
106
+ if (r <= 0) return [{
107
+ start: o[0].start,
108
+ end: o[o.length - 1].end
109
+ }];
110
+ let u = [], d = null, p = 0;
111
+ for (let t of o) {
112
+ let n = !1;
113
+ for (let o of f(e, t.start, t.end)) {
114
+ let e = o.start, t = o.end, f = d !== null && !n ? e - 1 : e, m = p + s(f, t, i), h = Math.min(a, l(t - 1, i));
115
+ if (d !== null && m - h <= r) d.end = t, p = m;
116
+ else {
117
+ for (d !== null && u.push(d);;) {
118
+ let n = e;
119
+ for (; n < t && c(e, n + 1, i, a) <= r;) n++;
120
+ if (n === t || n === e) break;
121
+ u.push({
122
+ start: e,
123
+ end: n
124
+ }), e = n;
125
+ }
126
+ d = {
127
+ start: e,
128
+ end: t
129
+ }, p = s(e, t, i);
130
+ }
131
+ n = !0;
132
+ }
133
+ }
134
+ return d !== null && u.push(d), u;
128
135
  }
129
- function v(e, t, n, r, i, a) {
130
- let o = f(e.style.gapX, t), s = f(e.style.gapY, n), c = A(e).map((e) => {
131
- let n = p(e.style.margin, t);
136
+ //#endregion
137
+ //#region src/flex.ts
138
+ function g(e, t, n, r, i, a, o) {
139
+ let s = W(e.style.gapX, t), c = W(e.style.gapY, n), l = D(e).map((e) => {
140
+ let n = G(e.style.margin, t);
132
141
  return {
133
142
  node: e,
134
- intrinsic: O(e, t, a),
143
+ base: E(e, t, o),
135
144
  grow: e.style.flexGrow,
136
145
  shrink: e.style.flexShrink,
137
- min: M(e, t, a),
138
- max: h(e.style.maxWidth, t),
139
- margin: n,
140
- marginLeft: n.left,
141
- marginRight: n.right
146
+ min: A(e, t, o),
147
+ max: q(e.style.maxWidth, t),
148
+ margin: n
142
149
  };
143
- }), l = [];
150
+ }), u = [];
144
151
  if (e.style.flexWrap === "wrap") {
145
152
  let n = [], r = 0;
146
- for (let e of c) {
147
- let i = Math.max(0, d(e.intrinsic, e.min, e.max)) + (e.marginLeft ?? 0) + (e.marginRight ?? 0), a = n.length === 0 ? i : r + o + i;
148
- n.length > 0 && a > t && (l.push(n), n = [], r = 0), n.push(e), r = n.length === 1 ? i : r + o + i;
149
- }
150
- n.length > 0 && l.push(n), e.style.wrapReverse && l.reverse();
151
- } else l.push(c);
152
- let m = r.left + i.left, g = r.top + i.top, _ = 0, v = 0;
153
- for (let r = 0; r < l.length; r++) {
154
- let i = l[r], c = o * Math.max(0, i.length - 1), f = i.reduce((e, t) => e + (t.marginLeft ?? 0) + (t.marginRight ?? 0), 0), p = Math.max(0, t - c - f), y = i.some((e) => e.marginLeft === null || e.marginRight === null), x = i.reduce((e, t) => e + t.intrinsic, 0), T = y && x <= p ? i.map((e) => e.intrinsic) : C(i, p);
155
- for (let e = 0; e < i.length; e++) u(i[e].node, t, void 0, 0, 0, "fill", a, { width: T[e] });
156
- let E = i.reduce((e, t) => Math.max(e, t.node.localRect.height), 0), D = l.length === 1 && Number.isFinite(n) ? Math.max(n, E) : E;
157
- for (let r = 0; r < i.length; r++) {
158
- let o = i[r].node, s = o.style.alignSelf === "auto" ? e.style.alignItems : o.style.alignSelf, c = i[r].margin, l = c.top === null || c.bottom === null, f = o.style.height !== void 0 && o.style.height.kind !== "auto";
159
- if (s === "stretch" && !l && !f && D > o.localRect.height) {
160
- let e = c.top ?? 0, i = c.bottom ?? 0, s = Number.isFinite(n) ? n : void 0, l = d(Math.max(0, D - e - i), h(o.style.minHeight, s) ?? 0, h(o.style.maxHeight, s));
161
- if (l === o.localRect.height) continue;
162
- u(o, t, void 0, 0, 0, "fill", a, {
163
- width: T[r],
164
- height: l
153
+ for (let e of l) {
154
+ let i = Math.max(0, U(e.base, e.min, e.max)) + (e.margin.left ?? 0) + (e.margin.right ?? 0), a = n.length === 0 ? i : r + s + i;
155
+ n.length > 0 && a > t && (u.push(n), n = [], r = 0), n.push(e), r = n.length === 1 ? i : r + s + i;
156
+ }
157
+ n.length > 0 && u.push(n), e.style.wrapReverse && u.reverse();
158
+ } else u.push(l);
159
+ let d = i.left + a.left, f = i.top + a.top, p = u.map((e) => {
160
+ let n = s * Math.max(0, e.length - 1), i = e.reduce((e, t) => e + (t.margin.left ?? 0) + (t.margin.right ?? 0), 0), a = Math.max(0, t - n - i), c = e.some((e) => e.margin.left === null || e.margin.right === null), l = e.reduce((e, t) => e + t.base, 0), u = c && l <= a ? e.map((e) => Math.max(0, U(e.base, e.min, e.max))) : S(e, a);
161
+ for (let n = 0; n < e.length; n++) H(e[n].node, t, r, 0, 0, "fill", o, { width: u[n] });
162
+ return {
163
+ row: e,
164
+ widths: u,
165
+ availableForItems: a,
166
+ height: e.reduce((e, t) => Math.max(e, t.node.localRect.height), 0)
167
+ };
168
+ }), m = p.map((e) => e.height), h = c * Math.max(0, p.length - 1), g;
169
+ if (e.style.flexWrap === "nowrap") Number.isFinite(n) && (m[0] = Math.max(n, m[0] ?? 0)), g = [0];
170
+ else {
171
+ let t = m.reduce((e, t) => e + t, 0), r = Number.isFinite(n) ? Math.max(0, n - t - h) : 0, i = O(e.style);
172
+ if (i === "stretch" && r > 0) {
173
+ let e = C(Array.from({ length: p.length }, () => 1), r);
174
+ for (let t = 0; t < m.length; t++) m[t] += e[t];
175
+ g = x("start", m, 0);
176
+ } else g = x(i === "stretch" ? "start" : i, m, r);
177
+ }
178
+ for (let i = 0; i < p.length; i++) {
179
+ let { row: a, widths: l, availableForItems: u } = p[i], h = m[i], _ = g[i] + i * c;
180
+ for (let i = 0; i < a.length; i++) {
181
+ let s = a[i].node, c = w(s, e), u = a[i].margin, d = u.top === null || u.bottom === null, f = s.style.height !== void 0 && s.style.height.kind !== "auto";
182
+ if (c === "stretch" && !d && !f && h > s.localRect.height) {
183
+ let e = u.top ?? 0, a = u.bottom ?? 0, c = Number.isFinite(n) ? n : void 0, d = U(Math.max(0, h - e - a), q(s.style.minHeight, c) ?? 0, q(s.style.maxHeight, c));
184
+ if (d === s.localRect.height) continue;
185
+ H(s, t, r, 0, 0, "fill", o, {
186
+ width: l[i],
187
+ height: d
165
188
  });
166
189
  }
167
190
  }
168
- let O = T.reduce((e, t) => e + t, 0), k = Math.max(0, p - O), A = i.reduce((e, t) => e + +(t.marginLeft === null) + +(t.marginRight === null), 0), M = Array.from({ length: i.length }, () => 0), N = Array.from({ length: i.length }, () => 0), P;
169
- if (A > 0 && k > 0) {
170
- let e = w(Array.from({ length: A }, () => 1), k), t = 0;
171
- for (let n = 0; n < i.length; n++) i[n].marginLeft === null && (M[n] = e[t++]), i[n].marginRight === null && (N[n] = e[t++]);
172
- P = S("start", T, 0);
173
- } else P = S(j(e.style), T, k);
174
- let F = 0;
175
- for (let t = 0; t < i.length; t++) {
176
- let n = i[t], r = n.node, a = n.marginLeft ?? 0, s = n.marginRight ?? 0;
177
- F += M[t] + a, r.localRect = {
191
+ let v = l.reduce((e, t) => e + t, 0), b = Math.max(0, u - v), S = a.reduce((e, t) => e + +(t.margin.left === null) + +(t.margin.right === null), 0), T = Array.from({ length: a.length }, () => 0), E = Array.from({ length: a.length }, () => 0), D;
192
+ if (S > 0 && b > 0) {
193
+ let e = C(Array.from({ length: S }, () => 1), b), t = 0;
194
+ for (let n = 0; n < a.length; n++) a[n].margin.left === null && (T[n] = e[t++]), a[n].margin.right === null && (E[n] = e[t++]);
195
+ D = x("start", l, 0);
196
+ } else D = x(k(e.style), l, b);
197
+ let O = 0;
198
+ for (let t = 0; t < a.length; t++) {
199
+ let n = a[t], r = n.node, i = n.margin.left ?? 0, o = n.margin.right ?? 0;
200
+ O += T[t] + i, r.localRect = {
178
201
  ...r.localRect,
179
- x: m + P[t] + t * o + F,
180
- y: g + _ + b(r, e.style.alignItems, D, n.margin)
181
- }, F += N[t] + s;
202
+ x: d + D[t] + t * s + O,
203
+ y: f + _ + y(r, e.style.alignItems, h, n.margin)
204
+ }, O += E[t] + o;
182
205
  }
183
- let I = r < l.length - 1 ? s : 0;
184
- _ += D + I, v += D + I;
185
206
  }
186
- return Number.isFinite(n) ? Math.max(n, v) : v;
207
+ let v = m.reduce((e, t) => e + t, 0) + h, b = Number.isFinite(n) ? Math.max(n, v) : v;
208
+ return _(e, i, a, t, b), b;
209
+ }
210
+ function _(e, t, n, r, i) {
211
+ for (let a of e.children) V(a.style) && (a.staticSlot = {
212
+ kind: "flex",
213
+ direction: e.style.flexDirection,
214
+ originX: t.left + n.left,
215
+ originY: t.top + n.top,
216
+ innerWidth: r,
217
+ innerHeight: i
218
+ });
187
219
  }
188
- function y(e, t, r, i, a, o, s) {
189
- let c = f(e.style.gapY, r), l = A(e).map((i) => {
190
- let a = p(i.style.margin, t), o = a.left ?? 0, c = a.right ?? 0;
191
- u(i, Math.max(0, t - o - c), void 0, 0, 0, (i.style.alignSelf === "auto" ? e.style.alignItems : i.style.alignSelf) === "stretch" ? "fill" : "shrink", s);
192
- let l = Number.isFinite(r) ? r : void 0, d = i.style.flexBasis, f = d === void 0 || d.kind === "auto" ? i.unclampedHeight : d.kind === "cells" ? d.value : d.kind === "percent" && l !== void 0 ? n(d.value, l) : i.unclampedHeight, m = i.style.minHeight === "auto" ? i.style.overflow === "visible" ? i.localRect.height : 0 : void 0;
220
+ function v(e, t, r, i, a, o, s) {
221
+ let c = W(e.style.gapY, r), l = D(e).map((a) => {
222
+ let o = G(a.style.margin, t), c = Math.max(0, t - (o.left ?? 0) - (o.right ?? 0)), l = w(a, e) === "stretch";
223
+ H(a, c, i && Number.isFinite(r) ? r : void 0, 0, 0, l ? "fill" : "shrink", s);
224
+ let u = Number.isFinite(r) ? r : void 0, d = a.style.flexBasis, f = d === void 0 || d.kind === "auto" ? a.unclampedHeight : d.kind === "cells" ? d.value : d.kind === "percent" && u !== void 0 ? n(d.value, u) : a.unclampedHeight, p = a.style.minHeight === "auto" ? a.style.overflow === "visible" ? a.localRect.height : 0 : void 0;
193
225
  return {
194
- node: i,
195
- intrinsic: f,
196
- grow: i.style.flexGrow,
197
- shrink: i.style.flexShrink,
198
- min: m ?? h(i.style.minHeight, l) ?? 0,
199
- max: h(i.style.maxHeight, l),
200
- margin: a,
201
- marginTop: a.top,
202
- marginBottom: a.bottom,
203
- marginLeft: o,
204
- marginRight: c
226
+ node: a,
227
+ base: f,
228
+ grow: a.style.flexGrow,
229
+ shrink: a.style.flexShrink,
230
+ min: p ?? q(a.style.minHeight, u) ?? 0,
231
+ max: q(a.style.maxHeight, u),
232
+ margin: o
205
233
  };
206
- }), d = c * Math.max(0, l.length - 1), m = l.reduce((e, t) => e + (t.marginTop ?? 0) + (t.marginBottom ?? 0), 0), g = Number.isFinite(r), _ = l.reduce((e, t) => e + t.intrinsic, 0), v = g ? Math.max(0, r - d - m) : _, y = i ? v : Math.max(v, _), b = l.some((e) => e.marginTop === null || e.marginBottom === null), T = g && !(g && b && _ <= y) ? C(l, y) : l.map((e) => e.intrinsic);
207
- for (let n = 0; n < l.length; n++) if (T[n] !== l[n].intrinsic) {
208
- let r = l[n], i = Math.max(0, t - r.marginLeft - r.marginRight), a = (r.node.style.alignSelf === "auto" ? e.style.alignItems : r.node.style.alignSelf) === "stretch";
209
- u(r.node, i, T[n], 0, 0, a ? "fill" : "shrink", s, { height: T[n] });
210
- }
211
- let E = T.reduce((e, t) => e + t, 0), D = Math.max(0, y - E), O = l.reduce((e, t) => e + +(t.marginTop === null) + +(t.marginBottom === null), 0), k = Array.from({ length: l.length }, () => 0), M = Array.from({ length: l.length }, () => 0), N;
212
- if (O > 0 && D > 0) {
213
- let e = w(Array.from({ length: O }, () => 1), D), t = 0;
214
- for (let n = 0; n < l.length; n++) l[n].marginTop === null && (k[n] = e[t++]), l[n].marginBottom === null && (M[n] = e[t++]);
215
- N = S("start", T, 0);
216
- } else N = S(j(e.style), T, D);
217
- let P = a.left + o.left, F = a.top + o.top, I = 0;
234
+ }), u = c * Math.max(0, l.length - 1), d = l.reduce((e, t) => e + (t.margin.top ?? 0) + (t.margin.bottom ?? 0), 0), f = Number.isFinite(r), p = l.reduce((e, t) => e + t.base, 0), m = f ? Math.max(0, r - u - d) : p, h = i ? m : Math.max(m, p), g = l.some((e) => e.margin.top === null || e.margin.bottom === null), v = f && !(f && g && p <= h) ? S(l, h) : l.map((e) => Math.max(0, U(e.base, e.min, e.max)));
235
+ for (let n = 0; n < l.length; n++) if (v[n] !== l[n].node.localRect.height) {
236
+ let r = l[n], i = Math.max(0, t - (r.margin.left ?? 0) - (r.margin.right ?? 0)), a = w(r.node, e) === "stretch";
237
+ H(r.node, i, v[n], 0, 0, a ? "fill" : "shrink", s, { height: v[n] });
238
+ }
239
+ let y = v.reduce((e, t) => e + t, 0), T = Math.max(0, h - y), E = l.reduce((e, t) => e + +(t.margin.top === null) + +(t.margin.bottom === null), 0), O = Array.from({ length: l.length }, () => 0), A = Array.from({ length: l.length }, () => 0), j;
240
+ if (E > 0 && T > 0) {
241
+ let e = C(Array.from({ length: E }, () => 1), T), t = 0;
242
+ for (let n = 0; n < l.length; n++) l[n].margin.top === null && (O[n] = e[t++]), l[n].margin.bottom === null && (A[n] = e[t++]);
243
+ j = x("start", v, 0);
244
+ } else j = x(k(e.style), v, T);
245
+ let M = a.left + o.left, N = a.top + o.top, P = 0;
218
246
  for (let n = 0; n < l.length; n++) {
219
- let r = l[n], i = r.node, a = r.marginTop ?? 0, o = r.marginBottom ?? 0;
220
- I += k[n] + a, i.localRect = {
247
+ let r = l[n], i = r.node, a = r.margin.top ?? 0, o = r.margin.bottom ?? 0;
248
+ P += O[n] + a, i.localRect = {
221
249
  ...i.localRect,
222
- x: P + x(i, e.style.alignItems, t, r.margin),
223
- y: F + N[n] + n * c + I
224
- }, I += M[n] + o;
250
+ x: M + b(i, e.style.alignItems, t, r.margin),
251
+ y: N + j[n] + n * c + P
252
+ }, P += A[n] + o;
225
253
  }
226
- let L = E + d + m;
227
- return g ? Math.max(r, L) : L;
254
+ let F = y + u + d, I = f ? Math.max(r, F) : F;
255
+ return _(e, a, o, t, I), I;
228
256
  }
229
- function b(e, t, n, r) {
257
+ function y(e, t, n, r) {
230
258
  let i = e.style.alignSelf === "auto" ? t : e.style.alignSelf, a = r.top ?? 0, o = r.bottom ?? 0, s = n - e.localRect.height, c = r.top === null && r.bottom === null, l = r.top === null && r.bottom !== null, u = r.bottom === null && r.top !== null;
231
259
  return c ? Math.floor(s / 2) : l ? s - o : u ? a : a + T(i, n, e.localRect.height);
232
260
  }
233
- function x(e, t, n, r) {
261
+ function b(e, t, n, r) {
234
262
  let i = e.style.alignSelf === "auto" ? t : e.style.alignSelf, a = r.left ?? 0, o = r.right ?? 0, s = n - e.localRect.width, c = r.left === null && r.right === null, l = r.left === null && r.right !== null, u = r.right === null && r.left !== null;
235
263
  return c ? Math.floor(s / 2) : l ? s - o : u ? a : a + T(i, n, e.localRect.width);
236
264
  }
237
- function S(e, t, n) {
265
+ function x(e, t, n) {
238
266
  let r = t.length;
239
267
  if (r === 0) return [];
240
268
  let i = [], a = 0;
@@ -244,7 +272,7 @@ function S(e, t, n) {
244
272
  return i;
245
273
  }
246
274
  if ((e === "space-around" || e === "space-evenly") && n > 0) {
247
- let o = w(Array.from({ length: r + 1 }, (t, n) => e === "space-evenly" || n === 0 || n === r ? 1 : 2), n);
275
+ let o = C(Array.from({ length: r + 1 }, (t, n) => e === "space-evenly" || n === 0 || n === r ? 1 : 2), n);
248
276
  for (let e = 0; e < r; e++) a += o[e], i.push(a), a += t[e];
249
277
  return i;
250
278
  }
@@ -252,8 +280,8 @@ function S(e, t, n) {
252
280
  for (let e = 0; e < r; e++) i.push(a), a += t[e];
253
281
  return i;
254
282
  }
255
- function C(e, t) {
256
- let n = e.length, r = (t, n) => Math.max(0, d(t, e[n].min ?? 0, e[n].max)), i = e.map((e) => e.intrinsic), a = t >= i.reduce((e, t, n) => e + r(t, n), 0), o = Array.from({ length: n }, () => 0), s = Array.from({ length: n }, () => !1);
283
+ function S(e, t) {
284
+ let n = e.length, r = (t, n) => Math.max(0, U(t, e[n].min ?? 0, e[n].max)), i = e.map((e) => e.base), a = t >= i.reduce((e, t, n) => e + r(t, n), 0), o = Array.from({ length: n }, () => 0), s = Array.from({ length: n }, () => !1);
257
285
  for (let t = 0; t < n; t++) {
258
286
  let n = r(i[t], t);
259
287
  ((a ? e[t].grow : e[t].shrink) === 0 || a && i[t] > n || !a && i[t] < n) && (o[t] = n, s[t] = !0);
@@ -262,7 +290,7 @@ function C(e, t) {
262
290
  let c = [];
263
291
  for (let e = 0; e < n; e++) s[e] || c.push(e);
264
292
  if (c.length === 0) break;
265
- let l = o.reduce((e, t, n) => s[n] ? e + t : e, 0), u = c.reduce((e, t) => e + i[t], 0), d = t - l - u, f = a ? Math.max(0, d) : Math.max(0, -d), p = w(c.map((t) => a ? e[t].grow : i[t] * e[t].shrink), f), m = c.map((e, t) => i[e] + (a ? p[t] : -p[t])), h = c.map((e, t) => r(m[t], e)), g = h.reduce((e, t, n) => e + (t - m[n]), 0);
293
+ let l = o.reduce((e, t, n) => s[n] ? e + t : e, 0), u = c.reduce((e, t) => e + i[t], 0), d = t - l - u, f = a ? Math.max(0, d) : Math.max(0, -d), p = C(c.map((t) => a ? e[t].grow : i[t] * e[t].shrink), f), m = c.map((e, t) => i[e] + (a ? p[t] : -p[t])), h = c.map((e, t) => r(m[t], e)), g = h.reduce((e, t, n) => e + (t - m[n]), 0);
266
294
  if (g === 0) {
267
295
  for (let e = 0; e < c.length; e++) o[c[e]] = h[e];
268
296
  break;
@@ -274,7 +302,7 @@ function C(e, t) {
274
302
  }
275
303
  return o;
276
304
  }
277
- function w(e, t) {
305
+ function C(e, t) {
278
306
  let n = e.reduce((e, t) => e + t, 0);
279
307
  if (n === 0 || t <= 0) return e.map(() => 0);
280
308
  let r = e.map((e) => e / n * t), i = r.map(Math.floor), a = t - i.reduce((e, t) => e + t, 0);
@@ -287,75 +315,1099 @@ function w(e, t) {
287
315
  }
288
316
  return i;
289
317
  }
318
+ function w(e, t) {
319
+ return e.style.alignSelf === "auto" ? t.style.alignItems : e.style.alignSelf;
320
+ }
290
321
  function T(e, t, n) {
291
322
  return e === "center" ? Math.max(0, Math.floor((t - n) / 2)) : e === "end" ? Math.max(0, t - n) : 0;
292
323
  }
293
- function E(e, t, n, r, i) {
324
+ function E(e, t, n) {
325
+ let r = e.style.flexBasis, i = e.style.width;
326
+ return r !== void 0 && r.kind !== "auto" ? Y(r, t, e, n) : i !== void 0 && i.kind !== "auto" ? Y(i, t, e, n) : X(e, n);
327
+ }
328
+ function D(e) {
329
+ let t = e.children.filter((e) => !V(e.style)).sort((e, t) => e.style.order - t.style.order);
330
+ return e.style.flexReverse && t.reverse(), t;
331
+ }
332
+ function O(e) {
333
+ return e.wrapReverse ? e.alignContent === "start" ? "end" : e.alignContent === "end" ? "start" : e.alignContent : e.alignContent;
334
+ }
335
+ function k(e) {
336
+ let t = e.justifyContent === "stretch" ? "start" : e.justifyContent;
337
+ return e.flexReverse ? t === "start" ? "end" : t === "end" ? "start" : t : t;
338
+ }
339
+ function A(e, t, n) {
340
+ return e.style.minWidth === "auto" ? e.style.overflow === "visible" ? Z(e, n) : 0 : q(e.style.minWidth, t) ?? 0;
341
+ }
342
+ //#endregion
343
+ //#region src/types.ts
344
+ function j() {
345
+ return {
346
+ display: "block",
347
+ flexDirection: "row",
348
+ flexReverse: !1,
349
+ flexWrap: "nowrap",
350
+ wrapReverse: !1,
351
+ flexGrow: 0,
352
+ flexShrink: 0,
353
+ flexBasis: void 0,
354
+ order: 0,
355
+ justifyContent: "stretch",
356
+ alignContent: "stretch",
357
+ alignItems: "stretch",
358
+ alignSelf: "auto",
359
+ justifyItems: "stretch",
360
+ justifySelf: "auto",
361
+ gridTemplateColumns: { kind: "none" },
362
+ gridTemplateRows: { kind: "none" },
363
+ gridAutoColumns: [N()],
364
+ gridAutoRows: [N()],
365
+ gridAutoFlow: {
366
+ direction: "row",
367
+ dense: !1
368
+ },
369
+ gridTemplateAreas: null,
370
+ gridColumnStart: { kind: "auto" },
371
+ gridColumnEnd: { kind: "auto" },
372
+ gridRowStart: { kind: "auto" },
373
+ gridRowEnd: { kind: "auto" },
374
+ width: void 0,
375
+ height: void 0,
376
+ minWidth: "auto",
377
+ minHeight: "auto",
378
+ maxWidth: void 0,
379
+ maxHeight: void 0,
380
+ padding: M(),
381
+ margin: {
382
+ top: 0,
383
+ right: 0,
384
+ bottom: 0,
385
+ left: 0
386
+ },
387
+ position: "static",
388
+ insets: {
389
+ top: null,
390
+ right: null,
391
+ bottom: null,
392
+ left: null
393
+ },
394
+ gapX: 0,
395
+ gapY: 0,
396
+ border: M(),
397
+ borderStyle: {
398
+ top: "solid",
399
+ right: "solid",
400
+ bottom: "solid",
401
+ left: "solid"
402
+ },
403
+ overflow: "visible",
404
+ whiteSpace: "normal",
405
+ tabSize: 8,
406
+ lineGap: 0,
407
+ tracking: 0,
408
+ textOverflow: "clip",
409
+ color: void 0,
410
+ backgroundColor: void 0,
411
+ borderColor: {
412
+ top: void 0,
413
+ right: void 0,
414
+ bottom: void 0,
415
+ left: void 0
416
+ },
417
+ textAlignBlocked: !1
418
+ };
419
+ }
420
+ function M() {
421
+ return {
422
+ top: 0,
423
+ right: 0,
424
+ bottom: 0,
425
+ left: 0
426
+ };
427
+ }
428
+ function N() {
429
+ return {
430
+ min: { kind: "auto" },
431
+ max: { kind: "auto" }
432
+ };
433
+ }
434
+ //#endregion
435
+ //#region src/grid.ts
436
+ function P(e, t, n, r, i, a) {
437
+ let o = e.style, s = Number.isFinite(n) ? n : void 0, c = e.subgrid?.cols, l = e.subgrid?.rows, u = c ? c.gap : W(o.gapX, t), d = l ? l.gap : W(o.gapY, s), f = oe(e, t, s, u, d, e.subgrid ? {
438
+ col: e.subgrid.colSpan,
439
+ row: e.subgrid.rowSpan
440
+ } : void 0), { children: p, placed: m, colLines: h, rowLines: g, colTracks: _, rowTracks: v, colCollapsed: y, rowCollapsed: b } = f, x = p.map((e) => G(e.style.margin, t)), S = p.map((e) => e.style.justifySelf === "auto" ? o.justifyItems : e.style.justifySelf), C = p.map(F), T = c ? ee(c) : ye(_, y, te(f, C, x, a), t, u, o.justifyContent === "stretch"), E = c ? c.positions : be(T, t, o.justifyContent), D = [];
441
+ for (let e = 0; e < p.length; e++) {
442
+ let t = p[e], n = m.items[e], r = Se(E, T.sizes, n.col.start, n.col.span), i = x[e], o = Math.max(0, r - R(i)), s = C[e];
443
+ if (s.cols || s.rows) {
444
+ let e = s.cols ? I(E, T, u, n.col.start, n.col.span, L(t, "cols", i, r)) : void 0;
445
+ t.subgrid = {
446
+ colSpan: n.col.span,
447
+ rowSpan: n.row.span,
448
+ cols: e,
449
+ rows: void 0
450
+ };
451
+ } else t.subgrid = void 0;
452
+ let c = S[e], l = i.left === null || i.right === null, d = t.style.width !== void 0 && t.style.width.kind !== "auto";
453
+ s.cols ? H(t, r, void 0, 0, 0, "fill", a, { width: o }) : c === "stretch" && !l && !d ? H(t, r, void 0, 0, 0, "fill", a, { width: U(o, t.style.minWidth === "auto" ? t.style.overflow === "visible" ? Z(t, a) : 0 : q(t.style.minWidth, r) ?? 0, J(t.style.maxWidth, r, t, a)) }) : H(t, o, void 0, 0, 0, "shrink", a), D.push(t.localRect.width);
454
+ }
455
+ let O = l ? ee(l) : ye(v, b, ne(f, C, x), s ?? "max-content", d, o.alignContent === "stretch"), k = xe(O), A = l ? l.positions : be(O, s ?? k, o.alignContent), j = r.left + i.left, M = r.top + i.top;
456
+ for (let t = 0; t < p.length; t++) {
457
+ let n = p[t], r = m.items[t], i = x[t], o = Se(E, T.sizes, r.col.start, r.col.span), s = Se(A, O.sizes, r.row.start, r.row.span), c = Math.max(0, s - ue(i)), l = w(n, e), u = i.top === null || i.bottom === null, f = n.style.height !== void 0 && n.style.height.kind !== "auto";
458
+ if (C[t].rows) n.subgrid.rows = I(A, O, d, r.row.start, r.row.span, L(n, "rows", i, o)), H(n, o, s, 0, 0, "fill", a, {
459
+ width: D[t],
460
+ height: c
461
+ });
462
+ else if (l === "stretch" && !u && !f) {
463
+ let e = U(c, n.style.minHeight === "auto" ? n.style.overflow === "visible" ? n.localRect.height : 0 : q(n.style.minHeight, s) ?? 0, q(n.style.maxHeight, s));
464
+ e !== n.localRect.height && H(n, o, s, 0, 0, "fill", a, {
465
+ width: D[t],
466
+ height: e
467
+ });
468
+ } else n.style.height?.kind === "percent" && H(n, o, s, 0, 0, "fill", a, { width: D[t] });
469
+ n.localRect = {
470
+ ...n.localRect,
471
+ x: j + E[r.col.start] + Ce(S[t], i.left, i.right, o, n.localRect.width),
472
+ y: M + A[r.row.start] + Ce(l, i.top, i.bottom, s, n.localRect.height)
473
+ };
474
+ }
475
+ let N = Number.isFinite(n) ? Math.max(n, k) : k, P = e.children.filter((e) => V(e.style));
476
+ if (P.length > 0) {
477
+ let e = V(o) ? {
478
+ x: r.left,
479
+ y: r.top,
480
+ width: i.left + t + i.right,
481
+ height: i.top + N + i.bottom
482
+ } : {
483
+ x: j,
484
+ y: M,
485
+ width: t,
486
+ height: N
487
+ };
488
+ for (let n of P) {
489
+ let r = ie(n.style.gridColumnStart, n.style.gridColumnEnd, h, m.colOrigin, E, T.sizes, -i.left, t + i.right), a = ie(n.style.gridRowStart, n.style.gridRowEnd, g, m.rowOrigin, A, O.sizes, -i.top, N + i.bottom);
490
+ n.staticSlot = {
491
+ kind: "grid",
492
+ area: {
493
+ x: j + r.start,
494
+ y: M + a.start,
495
+ width: Math.max(0, r.end - r.start),
496
+ height: Math.max(0, a.end - a.start)
497
+ },
498
+ staticArea: e
499
+ };
500
+ }
501
+ }
502
+ return N;
503
+ }
504
+ function F(e) {
505
+ let t = e.style.display === "grid";
506
+ return {
507
+ cols: t && e.style.gridTemplateColumns.kind === "subgrid",
508
+ rows: t && e.style.gridTemplateRows.kind === "subgrid"
509
+ };
510
+ }
511
+ function I(e, t, n, r, i, a) {
512
+ let o = e[r] + a.start, s = t.sizes.slice(r, r + i);
513
+ return s[0] = Math.max(0, s[0] - a.start), s[i - 1] = Math.max(0, s[i - 1] - a.end), {
514
+ positions: Array.from({ length: i }, (t, n) => n === 0 ? 0 : e[r + n] - o),
515
+ sizes: s,
516
+ gapBefore: Array.from({ length: i }, (e, n) => n === 0 ? 0 : t.gapBefore[r + n]),
517
+ gap: n
518
+ };
519
+ }
520
+ function ee(e) {
521
+ return {
522
+ sizes: e.sizes,
523
+ gapBefore: e.gapBefore,
524
+ limits: e.sizes
525
+ };
526
+ }
527
+ function te(e, t, n, r) {
528
+ let i = [];
529
+ return e.children.forEach((a, o) => {
530
+ let s = e.placed.items[o], c = n[o];
531
+ if (t[o].cols) {
532
+ let e = L(a, "cols", c, 0);
533
+ for (let t of re(a, "cols", s, e, r)) i.push({
534
+ ...t,
535
+ start: t.start + s.col.start
536
+ });
537
+ return;
538
+ }
539
+ i.push({
540
+ start: s.col.start,
541
+ span: s.col.span,
542
+ min: z(a, "min", r) + R(c),
543
+ max: z(a, "max", r) + R(c)
544
+ });
545
+ }), i;
546
+ }
547
+ function ne(e, t, n) {
548
+ let r = [];
549
+ return e.children.forEach((i, a) => {
550
+ let o = e.placed.items[a], s = n[a];
551
+ if (t[a].rows) {
552
+ let e = L(i, "rows", s, 0);
553
+ for (let t of re(i, "rows", o, e)) r.push({
554
+ ...t,
555
+ start: t.start + o.row.start
556
+ });
557
+ return;
558
+ }
559
+ let c = i.localRect.height + ue(s);
560
+ r.push({
561
+ start: o.row.start,
562
+ span: o.row.span,
563
+ min: c,
564
+ max: c
565
+ });
566
+ }), r;
567
+ }
568
+ function L(e, t, n, r) {
569
+ let { border: i, padding: a } = e.style;
570
+ return t === "cols" ? {
571
+ start: (n.left ?? 0) + i.left + W(a.left, r),
572
+ end: (n.right ?? 0) + i.right + W(a.right, r)
573
+ } : {
574
+ start: (n.top ?? 0) + i.top + W(a.top, r),
575
+ end: (n.bottom ?? 0) + i.bottom + W(a.bottom, r)
576
+ };
577
+ }
578
+ function re(e, t, n, r, i) {
579
+ let a = t === "cols" ? n.col.span : n.row.span, o = oe(e, void 0, void 0, 0, 0, {
580
+ col: n.col.span,
581
+ row: n.row.span
582
+ }), s = [];
583
+ if (o.children.forEach((e, n) => {
584
+ let c = o.placed.items[n], l = t === "cols" ? c.col : c.row, u = l.start === 0, d = l.start + l.span === a, f = (u ? r.start : 0) + (d ? r.end : 0), p = G(e.style.margin, 0);
585
+ if (F(e)[t]) {
586
+ let n = L(e, t, p, 0), a = re(e, t, c, {
587
+ start: n.start + (u ? r.start : 0),
588
+ end: n.end + (d ? r.end : 0)
589
+ }, i);
590
+ for (let e of a) s.push({
591
+ ...e,
592
+ start: e.start + l.start
593
+ });
594
+ return;
595
+ }
596
+ if (t === "cols") s.push({
597
+ start: l.start,
598
+ span: l.span,
599
+ min: z(e, "min", i) + R(p) + f,
600
+ max: z(e, "max", i) + R(p) + f
601
+ });
602
+ else {
603
+ let t = e.localRect.height + ue(p) + f;
604
+ s.push({
605
+ start: l.start,
606
+ span: l.span,
607
+ min: t,
608
+ max: t
609
+ });
610
+ }
611
+ }), s.length === 0) {
612
+ let e = r.start + r.end;
613
+ s.push({
614
+ start: 0,
615
+ span: a,
616
+ min: e,
617
+ max: e
618
+ });
619
+ }
620
+ return s;
621
+ }
622
+ function ie(e, t, n, r, i, a, o, s) {
623
+ let c = he(e, "start", n), l = he(t, "end", n);
624
+ c !== null && l !== null ? c > l ? [c, l] = [l, c] : c === l && (l = null) : c !== null && t.kind === "span" ? l = ge(c, t, 1, n) : l !== null && e.kind === "span" && (c = ge(l, e, -1, n));
625
+ let u = i.length, d = (e) => {
626
+ if (e === null) return;
627
+ let t = e - r;
628
+ return t < 0 || t > u || u === 0 ? void 0 : t;
629
+ }, f = (e) => e === u ? i[u - 1] + a[u - 1] : i[e], p = (e) => e === 0 ? i[0] : i[e - 1] + a[e - 1], m = d(c), h = d(l);
630
+ return {
631
+ start: m === void 0 ? o : f(m),
632
+ end: h === void 0 ? s : p(h)
633
+ };
634
+ }
635
+ function ae(e, t) {
636
+ let n = t.gridIntrinsic.get(e);
637
+ if (n !== void 0) return n;
638
+ let r = e.style, i = typeof r.gapX == "number" ? r.gapX : 0, a = oe(e, void 0, void 0, i, 0, e.subgrid ? {
639
+ col: e.subgrid.colSpan,
640
+ row: e.subgrid.rowSpan
641
+ } : void 0), o = a.children.map(F), s = a.children.map((e) => G(e.style.margin, 0)), c = ye(a.colTracks, a.colCollapsed, te(a, o, s, t), "min-content", i, !1), l = c.gapBefore.reduce((e, t) => e + t, 0), u = {
642
+ min: c.sizes.reduce((e, t) => e + t, 0) + l,
643
+ max: c.limits.reduce((e, t) => e + t, 0) + l
644
+ };
645
+ return t.gridIntrinsic.set(e, u), u;
646
+ }
647
+ function oe(e, t, n, r, i, a) {
648
+ let o = e.style, s = le(e), c = o.gridTemplateColumns.kind === "subgrid" && a !== void 0, l = o.gridTemplateRows.kind === "subgrid" && a !== void 0, u = c ? se(a.col) : de(o.gridTemplateColumns, t, r), d = l ? se(a.row) : de(o.gridTemplateRows, n, i), f = o.gridTemplateAreas, p = [...u.tracks], m = [...d.tracks];
649
+ if (f) {
650
+ c || fe(p, u.lineNames, f.columns, o.gridAutoColumns), l || fe(m, d.lineNames, f.rows, o.gridAutoRows);
651
+ for (let [e, t] of f.areas) u.lineNames[Math.min(t.colStart, p.length)].push(`${e}-start`), u.lineNames[Math.min(t.colEnd, p.length)].push(`${e}-end`), d.lineNames[Math.min(t.rowStart, m.length)].push(`${e}-start`), d.lineNames[Math.min(t.rowEnd, m.length)].push(`${e}-end`);
652
+ }
653
+ let h = {
654
+ explicitCount: p.length,
655
+ names: u.lineNames
656
+ }, g = {
657
+ explicitCount: m.length,
658
+ names: d.lineNames
659
+ }, _ = ve(s.map((e) => ({
660
+ col: _e(e.style.gridColumnStart, e.style.gridColumnEnd, h),
661
+ row: _e(e.style.gridRowStart, e.style.gridRowEnd, g)
662
+ })), p.length, m.length, o.gridAutoFlow);
663
+ return c && ce(_, "col", p.length), l && ce(_, "row", m.length), {
664
+ children: s,
665
+ placed: _,
666
+ colLines: h,
667
+ rowLines: g,
668
+ colTracks: pe(p, _.colOrigin, _.colCount, o.gridAutoColumns),
669
+ rowTracks: pe(m, _.rowOrigin, _.rowCount, o.gridAutoRows),
670
+ colCollapsed: me(u, _.colOrigin, _.colCount, _.items.map((e) => e.col)),
671
+ rowCollapsed: me(d, _.rowOrigin, _.rowCount, _.items.map((e) => e.row))
672
+ };
673
+ }
674
+ function se(e) {
675
+ return {
676
+ tracks: Array.from({ length: e }, () => N()),
677
+ lineNames: Array.from({ length: e + 1 }, () => [])
678
+ };
679
+ }
680
+ function ce(e, t, n) {
681
+ let r = t === "col" ? e.colOrigin : e.rowOrigin;
682
+ for (let i of e.items) {
683
+ let e = i[t], a = Math.min(Math.max(e.start + r, 0), n - 1), o = Math.min(Math.max(e.start + r + e.span, a + 1), n);
684
+ e.start = a, e.span = o - a;
685
+ }
686
+ t === "col" ? (e.colOrigin = 0, e.colCount = n) : (e.rowOrigin = 0, e.rowCount = n);
687
+ }
688
+ function le(e) {
689
+ return e.children.filter((e) => !V(e.style) && !e.inlineBox).sort((e, t) => e.style.order - t.style.order);
690
+ }
691
+ function R(e) {
692
+ return (e.left ?? 0) + (e.right ?? 0);
693
+ }
694
+ function ue(e) {
695
+ return (e.top ?? 0) + (e.bottom ?? 0);
696
+ }
697
+ function z(e, t, n) {
698
+ let r = e.style, i;
699
+ r.width !== void 0 && r.width.kind !== "auto" && r.width.kind !== "percent" && (i = Y(r.width, 0, e, n)), i === void 0 && (i = t === "min" ? Z(e, n) : X(e, n));
700
+ let a = typeof r.minWidth == "number" ? r.minWidth : 0, o = typeof r.maxWidth == "number" ? r.maxWidth : void 0;
701
+ return Math.max(0, U(i, a, o));
702
+ }
703
+ function de(e, t, n) {
704
+ if (e.kind !== "tracks") return {
705
+ tracks: [],
706
+ lineNames: [[]]
707
+ };
708
+ let r = (e.lineNames ?? Array.from({ length: e.tracks.length + 1 }, () => [])).map((e) => [...e]);
709
+ if (!e.autoRepeat) return {
710
+ tracks: e.tracks,
711
+ lineNames: r
712
+ };
713
+ let { index: i, tracks: a, mode: o } = e.autoRepeat, s = 1;
714
+ if (t !== void 0) {
715
+ let e = a.reduce((e, n) => {
716
+ let r = B(n.min, t) ?? B(n.max, t) ?? 1;
717
+ return e + Math.max(1, r);
718
+ }, 0);
719
+ s = Math.max(1, Math.floor((t + n) / (e + n * a.length)));
720
+ }
721
+ let c = [];
722
+ for (let e = 0; e < s; e++) c.push(...a);
723
+ let l = [
724
+ ...e.tracks.slice(0, i),
725
+ ...c,
726
+ ...e.tracks.slice(i)
727
+ ], u = e.autoRepeat.lineNames ?? Array.from({ length: a.length + 1 }, () => []), d = r.slice(0, i), f = [...e.autoRepeat.leadingNames ?? []];
728
+ for (let e = 0; e < s; e++) {
729
+ f.push(...u[0]);
730
+ for (let e = 0; e < a.length; e++) d.push(f), f = [...u[e + 1]];
731
+ }
732
+ return d.push([...f, ...r[i]]), d.push(...r.slice(i + 1)), o === "auto-fit" ? {
733
+ tracks: l,
734
+ lineNames: d,
735
+ autoFit: {
736
+ start: i,
737
+ end: i + c.length
738
+ }
739
+ } : {
740
+ tracks: l,
741
+ lineNames: d
742
+ };
743
+ }
744
+ function B(e, t) {
745
+ if (e.kind === "cells") return e.value;
746
+ if (e.kind === "percent" && t !== void 0) return n(e.value, t);
747
+ if (e.kind === "math") {
748
+ let n = [];
749
+ for (let r of e.args) {
750
+ let e = B(r, t);
751
+ if (e === void 0) return;
752
+ n.push(e);
753
+ }
754
+ return e.fn === "min" ? Math.min(...n) : Math.max(...n);
755
+ }
756
+ }
757
+ function fe(e, t, n, r) {
758
+ for (let i = e.length; i < n; i++) e.push(r[(i - e.length) % r.length]), t.push([]);
759
+ }
760
+ function pe(e, t, n, r) {
761
+ let i = [];
762
+ for (let a = 0; a < n; a++) {
763
+ let n = a + t;
764
+ if (n >= 0 && n < e.length) i.push(e[n]);
765
+ else {
766
+ let t = n < 0 ? n : n - e.length;
767
+ i.push(r[(t % r.length + r.length) % r.length]);
768
+ }
769
+ }
770
+ return i;
771
+ }
772
+ function me(e, t, n, r) {
773
+ let i = Array.from({ length: n }, () => !1);
774
+ if (!e.autoFit) return i;
775
+ for (let a = e.autoFit.start; a < e.autoFit.end; a++) {
776
+ let e = a - t;
777
+ e < 0 || e >= n || r.some((t) => e >= t.start && e < t.start + t.span) || (i[e] = !0);
778
+ }
779
+ return i;
780
+ }
781
+ function he(e, t, n) {
782
+ if (e.kind === "line") return e.value > 0 ? e.value - 1 : n.explicitCount + 1 + e.value;
783
+ if (e.kind !== "name") return null;
784
+ if (e.nth === void 0) {
785
+ let r = `${e.name}-${t}`, i = n.names.findIndex((e) => e.includes(r));
786
+ if (i !== -1) return i;
787
+ }
788
+ let r = e.nth ?? 1, i = n.explicitCount, a = 0;
789
+ if (r > 0) {
790
+ for (let t = 0; t <= i; t++) if (n.names[t].includes(e.name) && ++a === r) return t;
791
+ return i + (r - a);
792
+ }
793
+ for (let t = i; t >= 0; t--) if (n.names[t].includes(e.name) && ++a === -r) return t;
794
+ return -(-r - a);
795
+ }
796
+ function ge(e, t, n, r) {
797
+ if (t.name === void 0) return e + n * t.value;
798
+ let i = t.value, a = e;
799
+ for (; i > 0;) a += n, (!(a >= 0 && a <= r.explicitCount) || r.names[a].includes(t.name)) && i--;
800
+ return a;
801
+ }
802
+ function _e(e, t, n) {
803
+ let r = he(e, "start", n), i = he(t, "end", n);
804
+ if (r !== null && i !== null) return r === i ? {
805
+ start: r,
806
+ span: 1
807
+ } : {
808
+ start: Math.min(r, i),
809
+ span: Math.abs(i - r)
810
+ };
811
+ if (r !== null) return {
812
+ start: r,
813
+ span: (t.kind === "span" ? ge(r, t, 1, n) : r + 1) - r
814
+ };
815
+ if (i !== null) {
816
+ let t = e.kind === "span" ? ge(i, e, -1, n) : i - 1;
817
+ return {
818
+ start: t,
819
+ span: i - t
820
+ };
821
+ }
822
+ return {
823
+ start: null,
824
+ span: e.kind === "span" ? e.value : t.kind === "span" ? t.value : 1
825
+ };
826
+ }
827
+ function ve(e, t, n, r) {
828
+ let i = r.direction === "row", a = e.map((e) => i ? e.row : e.col), o = e.map((e) => i ? e.col : e.row), s = i ? t : n, c = i ? n : t, l = 0, u = Math.max(s, 1);
829
+ for (let t = 0; t < e.length; t++) {
830
+ let e = o[t];
831
+ e.start !== null && (l = Math.min(l, e.start), u = Math.max(u, e.start + e.span));
832
+ }
833
+ for (let t = 0; t < e.length; t++) {
834
+ let e = o[t];
835
+ e.start === null && (u = Math.max(u, l + e.span));
836
+ }
837
+ let d = 0;
838
+ for (let t = 0; t < e.length; t++) {
839
+ let e = a[t];
840
+ e.start !== null && (d = Math.min(d, e.start));
841
+ }
842
+ let f = /* @__PURE__ */ new Set(), p = (e, t, n, r) => {
843
+ for (let i = e; i < e + n; i++) for (let e = t; e < t + r; e++) if (f.has(`${i}:${e}`)) return !1;
844
+ return !0;
845
+ }, m = (e, t, n, r) => {
846
+ for (let i = e; i < e + n; i++) for (let e = t; e < t + r; e++) f.add(`${i}:${e}`);
847
+ }, h = e.map(() => null);
848
+ for (let t = 0; t < e.length; t++) {
849
+ let e = a[t], n = o[t];
850
+ e.start !== null && n.start !== null && (h[t] = {
851
+ major: e.start,
852
+ minor: n.start
853
+ }, m(e.start, n.start, e.span, n.span));
854
+ }
855
+ let g = /* @__PURE__ */ new Map();
856
+ for (let t = 0; t < e.length; t++) {
857
+ let e = a[t], n = o[t];
858
+ if (e.start === null || n.start !== null) continue;
859
+ let i = r.dense ? l : Math.max(l, g.get(e.start) ?? l);
860
+ for (; !p(e.start, i, e.span, n.span);) i++;
861
+ h[t] = {
862
+ major: e.start,
863
+ minor: i
864
+ }, m(e.start, i, e.span, n.span), r.dense || g.set(e.start, i + n.span), u = Math.max(u, i + n.span);
865
+ }
866
+ let _ = d, v = l;
867
+ for (let t = 0; t < e.length; t++) {
868
+ if (h[t] !== null) continue;
869
+ let e = a[t], n = o[t];
870
+ if (r.dense && (_ = d, v = l), n.start !== null) {
871
+ for (n.start < v && _++; !p(_, n.start, e.span, n.span);) _++;
872
+ h[t] = {
873
+ major: _,
874
+ minor: n.start
875
+ }, m(_, n.start, e.span, n.span), v = n.start + n.span;
876
+ } else {
877
+ let r = _, i = v;
878
+ for (;;) {
879
+ if (i + n.span > u) {
880
+ r++, i = l;
881
+ continue;
882
+ }
883
+ if (p(r, i, e.span, n.span)) break;
884
+ i++;
885
+ }
886
+ h[t] = {
887
+ major: r,
888
+ minor: i
889
+ }, m(r, i, e.span, n.span), _ = r, v = i + n.span;
890
+ }
891
+ }
892
+ let y = Math.max(c, d);
893
+ for (let t = 0; t < e.length; t++) y = Math.max(y, h[t].major + a[t].span);
894
+ let b = e.map((e, t) => {
895
+ let n = {
896
+ start: h[t].major - d,
897
+ span: a[t].span
898
+ }, r = {
899
+ start: h[t].minor - l,
900
+ span: o[t].span
901
+ };
902
+ return i ? {
903
+ col: r,
904
+ row: n
905
+ } : {
906
+ col: n,
907
+ row: r
908
+ };
909
+ }), x = y - d, S = u - l;
910
+ return i ? {
911
+ items: b,
912
+ colOrigin: l,
913
+ colCount: S,
914
+ rowOrigin: d,
915
+ rowCount: x
916
+ } : {
917
+ items: b,
918
+ colOrigin: d,
919
+ colCount: x,
920
+ rowOrigin: l,
921
+ rowCount: S
922
+ };
923
+ }
924
+ function ye(t, n, r, i, a, o) {
925
+ let s = typeof i == "number" ? i : void 0, c = t.map((e, t) => {
926
+ if (n[t]) return {
927
+ base: 0,
928
+ limit: 0,
929
+ baseIntrinsic: !1,
930
+ limitKind: "fixed",
931
+ frFactor: 0,
932
+ collapsed: !0
933
+ };
934
+ let r = B(e.min, s), i = r ?? 0, a = r === void 0, o = e.max;
935
+ if (o.kind === "fr") return {
936
+ base: i,
937
+ limit: null,
938
+ baseIntrinsic: a,
939
+ limitKind: "fr",
940
+ frFactor: o.value,
941
+ collapsed: !1
942
+ };
943
+ let c = B(o, s);
944
+ return c === void 0 ? {
945
+ base: i,
946
+ limit: null,
947
+ baseIntrinsic: a,
948
+ limitKind: o.kind === "min-content" ? "intrinsic-min" : "intrinsic-max",
949
+ frFactor: 0,
950
+ collapsed: !1
951
+ } : {
952
+ base: i,
953
+ limit: c,
954
+ baseIntrinsic: a,
955
+ limitKind: "fixed",
956
+ frFactor: 0,
957
+ collapsed: !1
958
+ };
959
+ }), l = c.map((e, t) => t === 0 || e.collapsed ? 0 : c.slice(0, t).some((e) => !e.collapsed) ? a : 0), u = (e, t) => {
960
+ let n = 0;
961
+ for (let r = e + 1; r < e + t; r++) n += l[r];
962
+ return n;
963
+ }, d = (e) => e.collapsed ? 0 : e.limitKind === "fixed" ? e.limit : Math.max(e.base, e.limit ?? e.base), f = [...r].sort((e, t) => e.span - t.span);
964
+ for (let e of f) {
965
+ let t = [], n = !1;
966
+ for (let r = e.start; r < e.start + e.span; r++) {
967
+ let e = c[r];
968
+ e !== void 0 && (e.limitKind === "fr" && (n = !0), t.push(e));
969
+ }
970
+ if (t.length === 0) continue;
971
+ let r = u(e.start, e.span);
972
+ if (n) {
973
+ let n = t.filter((e) => e.limitKind === "fr" && e.baseIntrinsic && !e.collapsed);
974
+ if (n.length === 0) continue;
975
+ let i = t.reduce((e, t) => e + t.base, 0) + r, a = e.min - i;
976
+ if (a > 0) {
977
+ let e = n.reduce((e, t) => e + t.frFactor, 0), t = C(n.map((t) => e > 0 ? t.frFactor : 1), a);
978
+ n.forEach((e, n) => {
979
+ e.base += t[n];
980
+ });
981
+ }
982
+ continue;
983
+ }
984
+ let i = t.filter((e) => e.baseIntrinsic && !e.collapsed);
985
+ if (i.length > 0) {
986
+ let n = t.reduce((e, t) => e + t.base, 0) + r, a = e.min - n;
987
+ if (a > 0) {
988
+ let e = C(i.map(() => 1), a);
989
+ i.forEach((t, n) => {
990
+ t.base += e[n];
991
+ });
992
+ }
993
+ }
994
+ for (let [n, i] of [["intrinsic-min", e.min], ["intrinsic-max", e.max]]) {
995
+ let e = t.filter((e) => e.limitKind === n && !e.collapsed);
996
+ if (e.length === 0) continue;
997
+ let a = i - (t.reduce((e, t) => e + d(t), 0) + r);
998
+ if (a > 0) {
999
+ let t = C(e.map(() => 1), a);
1000
+ e.forEach((e, n) => {
1001
+ e.limit = d(e) + t[n];
1002
+ });
1003
+ }
1004
+ }
1005
+ }
1006
+ for (let e of c) e.collapsed || (e.limitKind === "fixed" ? e.base = Math.min(e.base, e.limit) : e.limitKind !== "fr" && (e.limit = Math.max(e.base, e.limit ?? e.base)));
1007
+ if (s === void 0) {
1008
+ let t = c.filter((e) => e.limitKind === "fr" && !e.collapsed);
1009
+ if (t.length > 0) {
1010
+ let n = 0;
1011
+ for (let e of t) e.frFactor > 0 && (n = Math.max(n, e.base / e.frFactor));
1012
+ for (let e of r) {
1013
+ let t = 0, r = u(e.start, e.span);
1014
+ for (let n = e.start; n < e.start + e.span; n++) {
1015
+ let e = c[n];
1016
+ e === void 0 || e.collapsed || (e.limitKind === "fr" ? t += e.frFactor : r += d(e));
1017
+ }
1018
+ t <= 0 || (n = Math.max(n, (e.max - r) / Math.max(t, 1)));
1019
+ }
1020
+ for (let r of t) {
1021
+ let t = Math.max(r.base, e(r.frFactor * n));
1022
+ r.limit = t, i === "max-content" && (r.base = t);
1023
+ }
1024
+ }
1025
+ if (i === "max-content") for (let e of c) !e.collapsed && e.limitKind !== "fr" && (e.base = d(e));
1026
+ } else {
1027
+ let e = l.reduce((e, t) => e + t, 0), t = s - e - c.reduce((e, t) => e + t.base, 0);
1028
+ for (; !(t <= 0);) {
1029
+ let e = c.filter((e) => !e.collapsed && e.limitKind !== "fr" && e.base < d(e));
1030
+ if (e.length === 0) break;
1031
+ let n = C(e.map(() => 1), t), r = 0;
1032
+ if (e.forEach((e, t) => {
1033
+ let i = Math.min(n[t], d(e) - e.base);
1034
+ e.base += i, r += i;
1035
+ }), t -= r, r === 0) break;
1036
+ }
1037
+ let n = c.filter((e) => e.limitKind === "fr");
1038
+ if (n.length > 0) {
1039
+ let t = Math.max(0, s - e - c.reduce((e, t) => e + (t.limitKind === "fr" ? 0 : t.base), 0)), r = n, i = t, a = n.reduce((e, t) => e + t.frFactor, 0);
1040
+ for (a < 1 && (i = Math.floor(i * a));;) {
1041
+ let e = C(r.map((e) => e.frFactor), i), t = r.filter((t, n) => e[n] < t.base);
1042
+ if (t.length === 0) {
1043
+ r.forEach((t, n) => {
1044
+ t.base = Math.max(t.base, e[n]);
1045
+ });
1046
+ break;
1047
+ }
1048
+ for (let e of t) i -= e.base;
1049
+ if (i = Math.max(0, i), r = r.filter((e) => !t.includes(e)), r.length === 0) break;
1050
+ }
1051
+ }
1052
+ if (o) {
1053
+ let t = s - e - c.reduce((e, t) => e + t.base, 0), n = c.filter((e) => !e.collapsed && e.limitKind === "intrinsic-max");
1054
+ if (t > 0 && n.length > 0) {
1055
+ let e = C(n.map(() => 1), t);
1056
+ n.forEach((t, n) => {
1057
+ t.base += e[n];
1058
+ });
1059
+ }
1060
+ }
1061
+ }
1062
+ return {
1063
+ sizes: c.map((e) => e.base),
1064
+ gapBefore: l,
1065
+ limits: c.map((e) => d(e))
1066
+ };
1067
+ }
1068
+ function be(e, t, n) {
1069
+ let { sizes: r, gapBefore: i } = e, a = Math.max(0, t - xe(e)), o = x(n === "stretch" ? "start" : n, r, a), s = [], c = 0;
1070
+ for (let e = 0; e < r.length; e++) c += i[e], s.push(o[e] + c);
1071
+ return s;
1072
+ }
1073
+ function xe(e) {
1074
+ return e.sizes.reduce((e, t) => e + t, 0) + e.gapBefore.reduce((e, t) => e + t, 0);
1075
+ }
1076
+ function Se(e, t, n, r) {
1077
+ let i = n + r - 1;
1078
+ return e[n] === void 0 || e[i] === void 0 ? 0 : e[i] + t[i] - e[n];
1079
+ }
1080
+ function Ce(e, t, n, r, i) {
1081
+ let a = t ?? 0, o = n ?? 0, s = r - i;
1082
+ return t === null && n === null ? Math.floor(s / 2) : t === null ? s - o : n === null ? a : a + T(e, r, i + a + o);
1083
+ }
1084
+ //#endregion
1085
+ //#region src/positioning.ts
1086
+ function we(e) {
1087
+ return e.position === "absolute" || e.position === "fixed" ? "absolute" : e.position === "relative" || e.position === "sticky" ? "relative" : "static";
1088
+ }
1089
+ function Te(e, t, n, r, i) {
1090
+ for (let a of e.children) {
1091
+ let o = we(a.style);
1092
+ if (o === "relative") {
1093
+ let t = e.localRect.width - e.style.border.left - e.style.border.right - e.resolvedPadding.left - e.resolvedPadding.right, n = e.localRect.height - e.style.border.top - e.style.border.bottom - e.resolvedPadding.top - e.resolvedPadding.bottom;
1094
+ a.localRect.x += Ee(a.style.insets.left, a.style.insets.right, t), a.localRect.y += Ee(a.style.insets.top, a.style.insets.bottom, n);
1095
+ } else o === "absolute" && Oe(a, e, t, n, r, i);
1096
+ Te(a, t + a.localRect.x, n + a.localRect.y, [...r, {
1097
+ node: a,
1098
+ absX: t + a.localRect.x,
1099
+ absY: n + a.localRect.y
1100
+ }], i);
1101
+ }
1102
+ }
1103
+ function Ee(e, t, n) {
1104
+ return e === null ? t === null ? 0 : -W(t, n) : W(e, n);
1105
+ }
1106
+ function De(e, t) {
1107
+ if (!t) for (let t = e.length - 1; t > 0; t--) {
1108
+ let n = e[t];
1109
+ if (!Ie(n.node.style)) continue;
1110
+ let r = n.node.style.border;
1111
+ return {
1112
+ x: n.absX + r.left,
1113
+ y: n.absY + r.top,
1114
+ width: Math.max(0, n.node.localRect.width - r.left - r.right),
1115
+ height: Math.max(0, n.node.localRect.height - r.top - r.bottom)
1116
+ };
1117
+ }
1118
+ let n = e[0];
1119
+ return {
1120
+ x: n.absX,
1121
+ y: n.absY,
1122
+ width: n.node.localRect.width,
1123
+ height: n.node.localRect.height
1124
+ };
1125
+ }
1126
+ function Oe(e, t, n, r, i, a) {
1127
+ let o = e.style, s = o.position === "fixed", c = e.staticSlot, l = c?.kind === "grid" && !s && Ie(t.style) ? {
1128
+ x: n + c.area.x,
1129
+ y: r + c.area.y,
1130
+ width: c.area.width,
1131
+ height: c.area.height
1132
+ } : De(i, s), u = o.insets.left === null ? null : W(o.insets.left, l.width), d = o.insets.right === null ? null : W(o.insets.right, l.width), f = o.insets.top === null ? null : W(o.insets.top, l.height), p = o.insets.bottom === null ? null : W(o.insets.bottom, l.height), m = G(o.margin, l.width), h = m.left ?? 0, g = m.right ?? 0, _ = m.top ?? 0, v = m.bottom ?? 0, y = o.width === void 0 || o.width.kind === "auto", b = o.height === void 0 || o.height.kind === "auto", x = J(o.minWidth, l.width, e, a) ?? 0, S = J(o.maxWidth, l.width, e, a), C = {};
1133
+ if (!y) C.width = U(Y(o.width, l.width, e, a), x, S);
1134
+ else if (u !== null && d !== null) C.width = U(Math.max(0, l.width - u - d - h - g), x, S);
1135
+ else {
1136
+ let t = Math.max(0, l.width - (u ?? 0) - (d ?? 0) - h - g);
1137
+ C.width = U(Math.min(X(e, a), Math.max(Z(e, a), t)), x, S);
1138
+ }
1139
+ f !== null && p !== null && b && (C.height = U(Math.max(0, l.height - f - p - _ - v), q(o.minHeight, l.height) ?? 0, q(o.maxHeight, l.height))), H(e, l.width, l.height, 0, 0, "shrink", a, C);
1140
+ let w = e.localRect.width, T = e.localRect.height, E;
1141
+ if (u !== null && d !== null) {
1142
+ let e = Math.max(0, l.width - u - d - w - h - g), t = m.left === null && m.right === null;
1143
+ E = l.x + u + h + (t ? Math.floor(e / 2) : m.left === null ? e : 0);
1144
+ } else E = u === null ? d === null ? Ne(e, t, n, w) : l.x + l.width - d - w - g : l.x + u + h;
1145
+ let D;
1146
+ if (f !== null && p !== null) {
1147
+ let e = Math.max(0, l.height - f - p - T - _ - v), t = m.top === null && m.bottom === null;
1148
+ D = l.y + f + _ + (t ? Math.floor(e / 2) : m.top === null ? e : 0);
1149
+ } else D = f === null ? p === null ? Pe(e, t, r, T) : l.y + l.height - p - T - v : l.y + f + _;
1150
+ e.localRect = {
1151
+ ...e.localRect,
1152
+ x: E - n,
1153
+ y: D - r
1154
+ };
1155
+ }
1156
+ function ke(e, t, n) {
1157
+ return x(e, [n], Math.max(0, t - n))[0];
1158
+ }
1159
+ function Ae(e, t, n, r) {
1160
+ return T(w(e, t), n, r);
1161
+ }
1162
+ function je(e, t, n, r, i) {
1163
+ let a = G(e.style.margin, n.innerWidth), [o, s, c, l] = r === "x" ? [
1164
+ a.left ?? 0,
1165
+ a.right ?? 0,
1166
+ n.innerWidth,
1167
+ n.direction === "row"
1168
+ ] : [
1169
+ a.top ?? 0,
1170
+ a.bottom ?? 0,
1171
+ n.innerHeight,
1172
+ n.direction === "column"
1173
+ ], u = i + o + s;
1174
+ return (l ? ke(k(t.style), c, u) : Ae(e, t, c, u)) + o;
1175
+ }
1176
+ function Me(e, t, n, r, i) {
1177
+ let a = G(e.style.margin, n.width), o = e.style.justifySelf === "auto" ? t.style.justifyItems : e.style.justifySelf, [s, c, l, u] = r === "x" ? [
1178
+ a.left ?? 0,
1179
+ a.right ?? 0,
1180
+ n.width,
1181
+ o
1182
+ ] : [
1183
+ a.top ?? 0,
1184
+ a.bottom ?? 0,
1185
+ n.height,
1186
+ w(e, t)
1187
+ ];
1188
+ return T(u, l, i + s + c) + s;
1189
+ }
1190
+ function Ne(e, t, n, r) {
1191
+ let i = e.staticSlot;
1192
+ return i === void 0 ? n : i.kind === "block" ? n + i.x : i.kind === "grid" ? n + i.staticArea.x + Me(e, t, i.staticArea, "x", r) : n + i.originX + je(e, t, i, "x", r);
1193
+ }
1194
+ function Pe(e, t, n, r) {
1195
+ let i = e.staticSlot;
1196
+ return i === void 0 ? n : i.kind === "block" ? n + i.y : i.kind === "grid" ? n + i.staticArea.y + Me(e, t, i.staticArea, "y", r) : n + i.originY + je(e, t, i, "y", r);
1197
+ }
1198
+ //#endregion
1199
+ //#region src/layout.ts
1200
+ function Fe(e, t) {
1201
+ let n = Le();
1202
+ return H(e, t, void 0, 0, 0, "fill", n), Te(e, 0, 0, [{
1203
+ node: e,
1204
+ absX: 0,
1205
+ absY: 0
1206
+ }], n), { height: e.localRect.height };
1207
+ }
1208
+ function V(e) {
1209
+ return e.position === "absolute" || e.position === "fixed";
1210
+ }
1211
+ function Ie(e) {
1212
+ return e.position !== "static";
1213
+ }
1214
+ function Le() {
1215
+ return {
1216
+ maxContent: /* @__PURE__ */ new WeakMap(),
1217
+ minContent: /* @__PURE__ */ new WeakMap(),
1218
+ gridIntrinsic: /* @__PURE__ */ new WeakMap()
1219
+ };
1220
+ }
1221
+ function H(e, t, n, r, i, a, o, c) {
1222
+ let l = e.style, u = c?.height, f = J(l.minWidth, t, e, o) ?? 0, p = J(l.maxWidth, t, e, o), m = q(l.minHeight, n) ?? 0, h = q(l.maxHeight, n), _ = {
1223
+ top: W(l.padding.top, t),
1224
+ right: W(l.padding.right, t),
1225
+ bottom: W(l.padding.bottom, t),
1226
+ left: W(l.padding.left, t)
1227
+ };
1228
+ e.resolvedPadding = _;
1229
+ let y = c?.width ?? U(Ue(l, t, a, e, o), f, p), b = We(l, n), x = qe(y, u ?? b ?? (m > 0 ? m : void 0) ?? Infinity, l.border, _), S = u !== void 0 || b !== void 0, C = S && Number.isFinite(x.height) ? x.height : void 0, w;
1230
+ if (Re(e)) {
1231
+ if (e.text) {
1232
+ let t = e.children.filter((e) => e.inlineBox);
1233
+ d(e.text, (n, r) => {
1234
+ let i = t[r];
1235
+ H(i, x.width, void 0, 0, 0, "shrink", o), e.advances[n] = Math.max(1, i.localRect.width);
1236
+ });
1237
+ let n = Be(e, x.width);
1238
+ if (w = n.totalRows, ze(e, n, x.width, x.height, _), t.length > 0) {
1239
+ let r = (e) => n.spans.findIndex((t) => e >= t.start && e < t.end);
1240
+ d(e.text, (i, a) => {
1241
+ let o = r(i);
1242
+ if (o === -1) return;
1243
+ let c = n.spans[o];
1244
+ t[a].localRect = {
1245
+ ...t[a].localRect,
1246
+ x: l.border.left + _.left + s(c.start, i, e.advances),
1247
+ y: l.border.top + _.top + n.lineY[o]
1248
+ };
1249
+ });
1250
+ }
1251
+ } else w = e.intrinsicHeight;
1252
+ for (let t of e.children) {
1253
+ if (t.inlineBox) continue;
1254
+ let e = G(t.style.margin, x.width);
1255
+ t.staticSlot = {
1256
+ kind: "block",
1257
+ x: l.border.left + _.left + (e.left ?? 0),
1258
+ y: l.border.top + _.top + (e.top ?? 0)
1259
+ };
1260
+ }
1261
+ } else w = l.display === "flex" && l.flexDirection === "row" ? g(e, x.width, x.height, C, l.border, _, o) : l.display === "flex" && l.flexDirection === "column" ? v(e, x.width, x.height, S, l.border, _, o) : l.display === "grid" ? P(e, x.width, x.height, l.border, _, o) : Ve(e, x.width, C, l.border, _, o);
1262
+ let T = w + l.border.top + l.border.bottom + _.top + _.bottom, E = u ?? b ?? T;
1263
+ e.unclampedHeight = E, e.localRect = {
1264
+ x: r,
1265
+ y: i,
1266
+ width: y,
1267
+ height: U(E, m, h)
1268
+ };
1269
+ }
1270
+ function Re(e) {
1271
+ return e.children.some((e) => !V(e.style) && !e.inlineBox) ? !1 : e.text !== "" || e.style.display !== "flex" && e.style.display !== "grid";
1272
+ }
1273
+ function U(e, t, n) {
1274
+ return Math.max(t, n === void 0 ? e : Math.min(e, n));
1275
+ }
1276
+ function ze(e, t, n, r, i) {
1277
+ let a = e.style;
1278
+ if (a.display !== "flex" && a.display !== "grid" || t.spans.length === 0) return;
1279
+ let o = a.display === "flex" && a.flexDirection === "column", s = t.spans.reduce((t, n) => Math.max(t, c(n.start, n.end, e.advances, a.tracking)), 0), l = Math.max(0, n - s);
1280
+ if (l > 0) {
1281
+ let e = a.display === "grid" ? T(a.justifyItems, n, s) : o ? T(a.alignItems, n, s) : x(k(a), [s], l)[0];
1282
+ e > 0 && (i.left += e, i.right += l - e);
1283
+ }
1284
+ if (Number.isFinite(r)) {
1285
+ let e = Math.max(0, r - t.totalRows);
1286
+ if (e > 0) {
1287
+ let n = a.display === "grid" || !o ? T(a.alignItems, r, t.totalRows) : x(k(a), [t.totalRows], e)[0];
1288
+ n > 0 && (i.top += n, i.bottom += e - n);
1289
+ }
1290
+ }
1291
+ }
1292
+ function Be(e, t) {
1293
+ let n = e.style.whiteSpace === "normal" ? o(e.text, t, {
1294
+ advances: e.advances,
1295
+ tracking: e.style.tracking
1296
+ }) : a(e.text), r = e.children.filter((e) => e.inlineBox), i = [], s = 0, c = 0;
1297
+ for (let t = 0; t < n.length; t++) {
1298
+ i.push(s);
1299
+ let a = n[t], o = 1;
1300
+ for (let t = a.start; t < a.end; t++) e.text[t] === "" && (o = Math.max(o, r[c].localRect.height), c++);
1301
+ s += o + (t < n.length - 1 ? e.style.lineGap : 0);
1302
+ }
1303
+ return {
1304
+ spans: n,
1305
+ lineY: i,
1306
+ totalRows: s
1307
+ };
1308
+ }
1309
+ function W(e, t) {
1310
+ return typeof e == "number" ? e : t === void 0 || !Number.isFinite(t) ? 0 : n(e.percent, t);
1311
+ }
1312
+ function G(e, t) {
1313
+ let n = (e) => e === null ? null : W(e, t);
1314
+ return {
1315
+ top: n(e.top),
1316
+ right: n(e.right),
1317
+ bottom: n(e.bottom),
1318
+ left: n(e.left)
1319
+ };
1320
+ }
1321
+ function K(e) {
1322
+ return typeof e == "number" ? e : 0;
1323
+ }
1324
+ function q(e, t) {
1325
+ if (e !== void 0 && typeof e != "string") return typeof e == "number" ? e : t === void 0 ? void 0 : n(e.percent, t);
1326
+ }
1327
+ function J(e, t, n, r) {
1328
+ return e === "min-content" || e === "max-content" || e === "fit-content" ? Y({ kind: e }, t, n, r) : q(e, t);
1329
+ }
1330
+ function Ve(e, t, n, r, i, a) {
1331
+ let o = r.left + i.left, s = r.top + i.top, c = s, l = null;
1332
+ for (let r of e.children) {
1333
+ let e = G(r.style.margin, t), i = e.top ?? 0, s = e.bottom ?? 0, u = e.left ?? 0, d = e.right ?? 0;
1334
+ if (V(r.style)) {
1335
+ r.staticSlot = {
1336
+ kind: "block",
1337
+ x: o + u,
1338
+ y: c + (l === null ? i : He(l, i))
1339
+ };
1340
+ continue;
1341
+ }
1342
+ H(r, Math.max(0, t - u - d), n, 0, 0, "fill", a);
1343
+ let f = t - r.localRect.width, p = e.left === null && e.right === null, m = e.left === null && e.right !== null;
1344
+ e.right === null && e.left;
1345
+ let h;
1346
+ h = p ? Math.floor(f / 2) : m ? f - d : u, c += l === null ? i : He(l, i), r.localRect = {
1347
+ ...r.localRect,
1348
+ x: o + h,
1349
+ y: c
1350
+ }, c += r.localRect.height, l = s;
1351
+ }
1352
+ return l !== null && (c += l), c - s;
1353
+ }
1354
+ function He(e, t) {
1355
+ return e >= 0 && t >= 0 ? Math.max(e, t) : e <= 0 && t <= 0 ? Math.min(e, t) : e + t;
1356
+ }
1357
+ function Ue(e, t, n, r, i) {
294
1358
  let a = e.width;
295
- return a !== void 0 && a.kind !== "auto" ? k(a, t, r, i) : n === "shrink" ? Math.min(t, N(r, i)) : t;
1359
+ return a !== void 0 && a.kind !== "auto" ? Y(a, t, r, i) : n === "shrink" ? Math.min(t, X(r, i)) : t;
296
1360
  }
297
- function D(e, t) {
1361
+ function We(e, t) {
298
1362
  if (e.height?.kind === "cells") return e.height.value;
299
1363
  if (e.height?.kind === "percent" && t != null) return n(e.height.value, t);
300
1364
  }
301
- function O(e, t, n) {
302
- let r = e.style.flexBasis, i = e.style.width;
303
- return r !== void 0 && r.kind !== "auto" ? k(r, t, e, n) : i !== void 0 && i.kind !== "auto" ? k(i, t, e, n) : N(e, n);
304
- }
305
- function k(e, t, r, i) {
1365
+ function Y(e, t, r, i) {
306
1366
  switch (e.kind) {
307
1367
  case "cells": return e.value;
308
1368
  case "percent": return n(e.value, t);
309
- case "min-content": return F(r, i);
310
- case "max-content": return N(r, i);
311
- case "fit-content": return Math.min(N(r, i), Math.max(F(r, i), t));
312
- case "auto": return N(r, i);
1369
+ case "min-content": return Z(r, i);
1370
+ case "max-content": return X(r, i);
1371
+ case "fit-content": return Math.min(X(r, i), Math.max(Z(r, i), t));
1372
+ case "auto": return X(r, i);
313
1373
  }
314
1374
  }
315
- function A(e) {
316
- let t = [...e.children].sort((e, t) => e.style.order - t.style.order);
317
- return e.style.flexReverse && t.reverse(), t;
318
- }
319
- function j(e) {
320
- return e.flexReverse ? e.justifyContent === "start" ? "end" : e.justifyContent === "end" ? "start" : e.justifyContent : e.justifyContent;
321
- }
322
- function M(e, t, n) {
323
- return e.style.minWidth === "auto" ? e.style.overflow === "visible" ? F(e, n) : 0 : h(e.style.minWidth, t) ?? 0;
324
- }
325
- function N(e, t) {
1375
+ function X(e, t) {
326
1376
  let n = t.maxContent.get(e);
327
1377
  if (n !== void 0) return n;
328
- let r = e.style, i = P(e, t) + r.border.left + r.border.right + m(r.padding.left) + m(r.padding.right);
1378
+ let r = e.style, i = Ge(e, t) + r.border.left + r.border.right + K(r.padding.left) + K(r.padding.right);
329
1379
  return t.maxContent.set(e, i), i;
330
1380
  }
331
- function P(e, t) {
332
- if (e.children.length === 0) return e.intrinsicWidth;
1381
+ function Ge(e, t) {
1382
+ let n = e.children.filter((e) => !V(e.style) && !e.inlineBox);
1383
+ if (n.length === 0) return e.intrinsicWidth;
1384
+ if (e.style.display === "grid") return ae(e, t).max;
333
1385
  if (e.style.display === "flex" && e.style.flexDirection === "row") {
334
- let n = m(e.style.gapX) * Math.max(0, e.children.length - 1);
335
- return e.children.reduce((e, n) => e + N(n, t), 0) + n;
1386
+ let r = K(e.style.gapX) * Math.max(0, n.length - 1);
1387
+ return n.reduce((e, n) => e + X(n, t), 0) + r;
336
1388
  }
337
- return e.children.reduce((e, n) => Math.max(e, N(n, t)), 0);
1389
+ return n.reduce((e, n) => Math.max(e, X(n, t)), 0);
338
1390
  }
339
- function F(e, t) {
1391
+ function Z(e, t) {
340
1392
  let n = t.minContent.get(e);
341
1393
  if (n !== void 0) return n;
342
- let r = e.style, i = I(e, t) + r.border.left + r.border.right + m(r.padding.left) + m(r.padding.right);
1394
+ let r = e.style, i = Ke(e, t) + r.border.left + r.border.right + K(r.padding.left) + K(r.padding.right);
343
1395
  return t.minContent.set(e, i), i;
344
1396
  }
345
- function I(e, t) {
346
- if (e.children.length === 0) {
347
- if (!e.text || e.style.whiteSpace === "nowrap") return e.intrinsicWidth;
348
- let t = 0;
349
- for (let n of e.text.split(/[ \t\r\n\f]+/)) for (let e of s(n)) e.length > t && (t = e.length);
350
- return t;
351
- }
1397
+ function Ke(e, t) {
1398
+ let n = e.children.filter((e) => !V(e.style) && !e.inlineBox);
1399
+ if (n.length === 0) return !e.text || e.style.whiteSpace !== "normal" ? e.intrinsicWidth : u(e.text, {
1400
+ advances: e.advances,
1401
+ tracking: e.style.tracking
1402
+ });
1403
+ if (e.style.display === "grid") return ae(e, t).min;
352
1404
  if (e.style.display === "flex" && e.style.flexDirection === "row" && e.style.flexWrap === "nowrap") {
353
- let n = m(e.style.gapX) * Math.max(0, e.children.length - 1);
354
- return e.children.reduce((e, n) => e + F(n, t), 0) + n;
1405
+ let r = K(e.style.gapX) * Math.max(0, n.length - 1);
1406
+ return n.reduce((e, n) => e + Z(n, t), 0) + r;
355
1407
  }
356
- return e.children.reduce((e, n) => Math.max(e, F(n, t)), 0);
1408
+ return n.reduce((e, n) => Math.max(e, Z(n, t)), 0);
357
1409
  }
358
- function L(e, t, n, r) {
1410
+ function qe(e, t, n, r) {
359
1411
  return {
360
1412
  width: Math.max(0, e - n.left - n.right - r.left - r.right),
361
1413
  height: Math.max(0, t - n.top - n.bottom - r.top - r.bottom)
@@ -363,7 +1415,7 @@ function L(e, t, n, r) {
363
1415
  }
364
1416
  //#endregion
365
1417
  //#region src/borders.ts
366
- function R(e, t, n) {
1418
+ function Je(e, t, n) {
367
1419
  let r = e.border;
368
1420
  if (r.top === 0 && r.right === 0 && r.bottom === 0 && r.left === 0) return;
369
1421
  let i = Math.max(r.top, r.right, r.bottom, r.left);
@@ -379,11 +1431,11 @@ function R(e, t, n) {
379
1431
  width: t.width - (i.left ? a : 0) - (i.right ? a : 0),
380
1432
  height: t.height - (i.top ? a : 0) - (i.bottom ? a : 0)
381
1433
  };
382
- o.width <= 0 || o.height <= 0 || z(n, e.borderStyle, e.borderColor, o, i);
1434
+ o.width <= 0 || o.height <= 0 || Ye(n, e.borderStyle, e.borderColor, o, i);
383
1435
  }
384
1436
  }
385
- function z(e, t, n, r, i) {
386
- let a = B(t.top), o = B(t.right), s = B(t.bottom), c = B(t.left), l = (e, t, n) => n(B(e === t ? e : "solid")), { x: u, y: d, width: f, height: p } = r, m = f >= 2 && p >= 2, h = u + +!!i.left, g = u + f - +!!i.right, _ = d + +!!i.top, v = d + p - +!!i.bottom;
1437
+ function Ye(e, t, n, r, i) {
1438
+ let a = Q(t.top), o = Q(t.right), s = Q(t.bottom), c = Q(t.left), l = (e, t, n) => n(Q(e === t ? e : "solid")), { x: u, y: d, width: f, height: p } = r, m = f >= 2 && p >= 2, h = u + +!!i.left, g = u + f - +!!i.right, _ = d + +!!i.top, v = d + p - +!!i.bottom;
387
1439
  if (i.top && g > h && e.push({
388
1440
  glyph: a.h,
389
1441
  x: h,
@@ -436,7 +1488,7 @@ function z(e, t, n, r, i) {
436
1488
  color: n.bottom
437
1489
  }));
438
1490
  }
439
- function B(e) {
1491
+ function Q(e) {
440
1492
  switch (e) {
441
1493
  case "double": return {
442
1494
  h: "═",
@@ -474,24 +1526,46 @@ function B(e) {
474
1526
  }
475
1527
  //#endregion
476
1528
  //#region src/render.ts
477
- function ee(e, t) {
478
- let n = [];
479
- V(e, 0, 0, n, !0), ne(t, n);
480
- }
481
- function V(e, t, n, r, i) {
482
- let a = t + e.localRect.x, o = n + e.localRect.y;
483
- i || te(e.source, e.localRect, e.resolvedPadding, e.style.border, e.style.textAlignBlocked, e.style.overflow, e.style.whiteSpace), R(e.style, {
484
- x: a,
485
- y: o,
1529
+ function Xe(e, t) {
1530
+ let n = [], r = /* @__PURE__ */ new Set();
1531
+ Ze(e, 0, 0, n, !0, r), et(t, n);
1532
+ for (let t of Array.from(e.source.querySelectorAll("[data-mw-inline-inset]"))) if (!r.has(t)) {
1533
+ t.removeAttribute("data-mw-inline-inset");
1534
+ let e = t.style;
1535
+ for (let t of [
1536
+ "--mw-it",
1537
+ "--mw-ir",
1538
+ "--mw-ib",
1539
+ "--mw-il"
1540
+ ]) e.removeProperty(t);
1541
+ }
1542
+ }
1543
+ function Ze(e, t, n, r, i, a) {
1544
+ let o = t + e.localRect.x, s = n + e.localRect.y;
1545
+ if (e.inlineElements) for (let { element: t, tracking: n, padLeft: r, padRight: i, insets: o } of e.inlineElements) {
1546
+ let e = t;
1547
+ e.style.setProperty("--mw-ls", String(n)), r > 0 ? e.style.setProperty("--mw-ipl", String(r)) : e.style.removeProperty("--mw-ipl"), i > 0 ? e.style.setProperty("--mw-ipr", String(i)) : e.style.removeProperty("--mw-ipr"), o && (a.add(t), Qe(e, o));
1548
+ }
1549
+ i || $e(e), Je(e.style, {
1550
+ x: o,
1551
+ y: s,
486
1552
  width: e.localRect.width,
487
1553
  height: e.localRect.height
488
1554
  }, r);
489
- for (let t of e.children) V(t, a, o, r, !1);
1555
+ for (let t of e.children) Ze(t, o, s, r, !1, a);
490
1556
  }
491
- function te(e, t, n, r, i, a, o) {
492
- e.setAttribute("data-mw-laid-out", ""), o === "nowrap" ? e.setAttribute("data-mw-nowrap", "") : e.removeAttribute("data-mw-nowrap"), e.style.setProperty("--mw-x", String(t.x)), e.style.setProperty("--mw-y", String(t.y)), e.style.setProperty("--mw-w", String(t.width)), e.style.setProperty("--mw-h", String(t.height)), a === "clip" ? e.setAttribute("data-mw-clip", "") : e.removeAttribute("data-mw-clip"), e.style.setProperty("--mw-pt", String(n.top)), e.style.setProperty("--mw-pr", String(n.right)), e.style.setProperty("--mw-pb", String(n.bottom)), e.style.setProperty("--mw-pl", String(n.left)), e.style.setProperty("--mw-bt", String(r.top)), e.style.setProperty("--mw-br", String(r.right)), e.style.setProperty("--mw-bb", String(r.bottom)), e.style.setProperty("--mw-bl", String(r.left)), i ? e.setAttribute("data-mw-text-align-blocked", "") : e.removeAttribute("data-mw-text-align-blocked");
1557
+ function Qe(e, t) {
1558
+ e.setAttribute("data-mw-inline-inset", "");
1559
+ let n = (t, n) => {
1560
+ n === null ? e.style.removeProperty(t) : e.style.setProperty(t, String(n));
1561
+ };
1562
+ n("--mw-it", t.top), n("--mw-ir", t.right), n("--mw-ib", t.bottom), n("--mw-il", t.left);
493
1563
  }
494
- function ne(e, t) {
1564
+ function $e(e) {
1565
+ let t = e.source, n = e.localRect, r = e.resolvedPadding, { border: i, textAlignBlocked: a, overflow: o, whiteSpace: s, tracking: c, lineGap: l } = e.style;
1566
+ t.setAttribute(e.inlineBox ? "data-mw-inline-box" : "data-mw-laid-out", ""), t.removeAttribute(e.inlineBox ? "data-mw-laid-out" : "data-mw-inline-box"), t.style.setProperty("--mw-ls", String(c)), t.style.setProperty("--mw-lh", String(l + 1)), t.style.setProperty("--mw-lhs", String(-l / 2)), s === "normal" ? t.removeAttribute("data-mw-nowrap") : t.setAttribute("data-mw-nowrap", ""), s === "pre" ? t.setAttribute("data-mw-pre", "") : t.removeAttribute("data-mw-pre"), t.style.setProperty("--mw-x", String(n.x)), t.style.setProperty("--mw-y", String(n.y)), t.style.setProperty("--mw-w", String(n.width)), t.style.setProperty("--mw-h", String(n.height)), o === "clip" ? t.setAttribute("data-mw-clip", "") : t.removeAttribute("data-mw-clip"), t.style.setProperty("--mw-pt", String(r.top)), t.style.setProperty("--mw-pr", String(r.right)), t.style.setProperty("--mw-pb", String(r.bottom)), t.style.setProperty("--mw-pl", String(r.left)), t.style.setProperty("--mw-bt", String(i.top)), t.style.setProperty("--mw-br", String(i.right)), t.style.setProperty("--mw-bb", String(i.bottom)), t.style.setProperty("--mw-bl", String(i.left)), a ? t.setAttribute("data-mw-text-align-blocked", "") : t.removeAttribute("data-mw-text-align-blocked"), e.droppedText ? t.setAttribute("data-mw-dropped-text", "") : t.removeAttribute("data-mw-dropped-text");
1567
+ }
1568
+ function et(e, t) {
495
1569
  e.replaceChildren();
496
1570
  for (let n of t) for (let t = 0; t < n.length; t++) {
497
1571
  let r = document.createElement("span");
@@ -500,64 +1574,97 @@ function ne(e, t) {
500
1574
  }
501
1575
  //#endregion
502
1576
  //#region src/style.ts
503
- function re(e, t) {
504
- let n = getComputedStyle(e), r = ae(e) ? e.computedStyleMap() : null, i = e.getAttribute("class") ?? "", a = e.style, o = n.display;
1577
+ function tt(e, t, n) {
1578
+ let r = getComputedStyle(e), i = parseFloat(r.fontSize) || t, a = it(e) ? e.computedStyleMap() : null, o = e.getAttribute("class") ?? "", s = e.style, c = r.display, l = c === "flex" || c === "inline-flex" ? "flex" : c === "grid" || c === "inline-grid" ? "grid" : c === "none" ? "none" : "block", u = { kind: "none" }, d = { kind: "none" }, f = [N()], p = [N()], m = {
1579
+ direction: "row",
1580
+ dense: !1
1581
+ }, h = null;
1582
+ if (l === "grid") {
1583
+ if (a) u = vt(a.get("grid-template-columns")?.toString() ?? "", t), d = vt(a.get("grid-template-rows")?.toString() ?? "", t);
1584
+ else {
1585
+ e.setAttribute("data-mw-degrid", "");
1586
+ try {
1587
+ u = vt(r.getPropertyValue("grid-template-columns"), t), d = vt(r.getPropertyValue("grid-template-rows"), t);
1588
+ } finally {
1589
+ e.removeAttribute("data-mw-degrid");
1590
+ }
1591
+ }
1592
+ f = St(r.getPropertyValue("grid-auto-columns"), t), p = St(r.getPropertyValue("grid-auto-rows"), t), m = Ot(r.getPropertyValue("grid-auto-flow")), h = xt(r.getPropertyValue("grid-template-areas"));
1593
+ }
505
1594
  return {
506
- display: o === "flex" ? "flex" : o === "grid" ? "grid" : o === "none" ? "none" : (o.startsWith("inline"), "block"),
507
- flexDirection: n.flexDirection.startsWith("column") ? "column" : "row",
508
- flexReverse: n.flexDirection.endsWith("-reverse"),
509
- flexWrap: n.flexWrap.startsWith("wrap") ? "wrap" : "nowrap",
510
- wrapReverse: n.flexWrap === "wrap-reverse",
511
- flexGrow: Number(n.flexGrow) || 0,
512
- flexShrink: n.flexShrink === "" ? 1 : Number(n.flexShrink) || 0,
513
- flexBasis: le(n.flexBasis, t),
514
- order: Number(n.order) || 0,
515
- justifyContent: oe(n.justifyContent),
516
- alignItems: U(n.alignItems),
517
- alignSelf: se(n.alignSelf),
518
- width: q(r, n.width, "width", t, i, a),
519
- height: q(r, n.height, "height", t, i, a),
520
- minWidth: G(n.minWidth, t) ?? "auto",
521
- minHeight: G(n.minHeight, t) ?? "auto",
522
- maxWidth: G(n.maxWidth, t),
523
- maxHeight: G(n.maxHeight, t),
524
- padding: de(n, t),
525
- margin: ce(n, r, i, t),
526
- gapX: K(n.columnGap === "normal" ? "0px" : n.columnGap, t),
527
- gapY: K(n.rowGap === "normal" ? "0px" : n.rowGap, t),
528
- border: fe(n),
1595
+ display: l,
1596
+ flexDirection: r.flexDirection.startsWith("column") ? "column" : "row",
1597
+ flexReverse: r.flexDirection.endsWith("-reverse"),
1598
+ flexWrap: r.flexWrap.startsWith("wrap") ? "wrap" : "nowrap",
1599
+ wrapReverse: r.flexWrap === "wrap-reverse",
1600
+ flexGrow: Number(r.flexGrow) || 0,
1601
+ flexShrink: r.flexShrink === "" ? 1 : Number(r.flexShrink) || 0,
1602
+ flexBasis: gt(r.flexBasis, t),
1603
+ order: Number(r.order) || 0,
1604
+ justifyContent: at(r.justifyContent),
1605
+ alignContent: at(r.alignContent),
1606
+ alignItems: ot(r.alignItems),
1607
+ alignSelf: st(r.alignSelf),
1608
+ justifyItems: ot(r.justifyItems),
1609
+ justifySelf: st(r.justifySelf),
1610
+ gridTemplateColumns: u,
1611
+ gridTemplateRows: d,
1612
+ gridAutoColumns: f,
1613
+ gridAutoRows: p,
1614
+ gridAutoFlow: m,
1615
+ gridTemplateAreas: h,
1616
+ gridColumnStart: Dt(r.getPropertyValue("grid-column-start")),
1617
+ gridColumnEnd: Dt(r.getPropertyValue("grid-column-end")),
1618
+ gridRowStart: Dt(r.getPropertyValue("grid-row-start")),
1619
+ gridRowEnd: Dt(r.getPropertyValue("grid-row-end")),
1620
+ width: ht(a, r.width, "width", t, o, s),
1621
+ height: ht(a, r.height, "height", t, o, s),
1622
+ minWidth: mt(r.minWidth, t) ?? "auto",
1623
+ minHeight: mt(r.minHeight, t) ?? "auto",
1624
+ maxWidth: mt(r.maxWidth, t),
1625
+ maxHeight: mt(r.maxHeight, t),
1626
+ padding: At(r, t),
1627
+ margin: ct(r, a, o, t),
1628
+ position: dt(r.position),
1629
+ insets: ft(r, a, o, s, t),
1630
+ gapX: $(r.columnGap === "normal" ? "0px" : r.columnGap, t),
1631
+ gapY: $(r.rowGap === "normal" ? "0px" : r.rowGap, t),
1632
+ border: jt(r),
529
1633
  borderStyle: {
530
- top: W(n.borderTopStyle),
531
- right: W(n.borderRightStyle),
532
- bottom: W(n.borderBottomStyle),
533
- left: W(n.borderLeftStyle)
1634
+ top: pt(r.borderTopStyle),
1635
+ right: pt(r.borderRightStyle),
1636
+ bottom: pt(r.borderBottomStyle),
1637
+ left: pt(r.borderLeftStyle)
534
1638
  },
535
- overflow: H(n.overflow) || H(n.overflowX) || H(n.overflowY) ? "clip" : "visible",
536
- whiteSpace: n.whiteSpace === "nowrap" || n.whiteSpace === "pre" ? "nowrap" : "normal",
537
- textOverflow: n.textOverflow === "ellipsis" ? "ellipsis" : "clip",
538
- color: n.color,
539
- backgroundColor: n.backgroundColor === "rgba(0, 0, 0, 0)" ? void 0 : n.backgroundColor,
1639
+ overflow: nt(r.overflow) || nt(r.overflowX) || nt(r.overflowY) ? "clip" : "visible",
1640
+ whiteSpace: r.whiteSpace === "pre" ? "pre" : r.whiteSpace === "nowrap" ? "nowrap" : "normal",
1641
+ tabSize: Math.max(1, Math.floor(parseFloat(r.tabSize)) || 8),
1642
+ lineGap: ut(r.lineHeight, n?.height ?? i),
1643
+ tracking: lt(r.letterSpacing, i, n?.letterSpacing ?? 0),
1644
+ textOverflow: r.textOverflow === "ellipsis" ? "ellipsis" : "clip",
1645
+ color: r.color,
1646
+ backgroundColor: r.backgroundColor === "rgba(0, 0, 0, 0)" ? void 0 : r.backgroundColor,
540
1647
  borderColor: {
541
- top: n.borderTopColor,
542
- right: n.borderRightColor,
543
- bottom: n.borderBottomColor,
544
- left: n.borderLeftColor
1648
+ top: r.borderTopColor,
1649
+ right: r.borderRightColor,
1650
+ bottom: r.borderBottomColor,
1651
+ left: r.borderLeftColor
545
1652
  },
546
- textAlignBlocked: ie(i, a)
1653
+ textAlignBlocked: rt(o, s)
547
1654
  };
548
1655
  }
549
- function H(e) {
1656
+ function nt(e) {
550
1657
  return e === "hidden" || e === "clip";
551
1658
  }
552
- function ie(e, t) {
1659
+ function rt(e, t) {
553
1660
  if (/(?:^|[\s:.[!])text-(?:center|justify)/.test(e)) return !0;
554
1661
  let n = t.textAlign;
555
1662
  return n === "center" || n === "justify";
556
1663
  }
557
- function ae(e) {
1664
+ function it(e) {
558
1665
  return typeof e.computedStyleMap == "function";
559
1666
  }
560
- function oe(e) {
1667
+ function at(e) {
561
1668
  switch (e) {
562
1669
  case "center": return "center";
563
1670
  case "flex-end":
@@ -566,10 +1673,13 @@ function oe(e) {
566
1673
  case "space-between": return "space-between";
567
1674
  case "space-around": return "space-around";
568
1675
  case "space-evenly": return "space-evenly";
1676
+ case "normal":
1677
+ case "stretch":
1678
+ case "": return "stretch";
569
1679
  default: return "start";
570
1680
  }
571
1681
  }
572
- function U(e) {
1682
+ function ot(e) {
573
1683
  switch (e) {
574
1684
  case "center": return "center";
575
1685
  case "flex-end":
@@ -580,10 +1690,10 @@ function U(e) {
580
1690
  default: return "start";
581
1691
  }
582
1692
  }
583
- function se(e) {
584
- return e === "auto" || e === "" || e === "normal" ? "auto" : U(e);
1693
+ function st(e) {
1694
+ return e === "auto" || e === "" || e === "normal" ? "auto" : ot(e);
585
1695
  }
586
- function ce(e, t, n, r) {
1696
+ function ct(e, t, n, r) {
587
1697
  let i = (i, a, o) => {
588
1698
  if (t) {
589
1699
  let e = t.get(i)?.toString().trim();
@@ -595,10 +1705,10 @@ function ce(e, t, n, r) {
595
1705
  } else if (o.test(n)) return null;
596
1706
  let s = e.getPropertyValue(i);
597
1707
  if (s === "auto") return null;
598
- let c = K(s, r);
1708
+ let c = $(s, r);
599
1709
  if (c !== 0) return c;
600
1710
  let l = e.getPropertyValue(a);
601
- return l === "auto" ? null : K(l, r);
1711
+ return l === "auto" ? null : $(l, r);
602
1712
  };
603
1713
  return {
604
1714
  top: i("margin-top", "margin-block-start", /(?:^|[\s:.[!])(?:m|my|mt)-auto\b/),
@@ -607,7 +1717,44 @@ function ce(e, t, n, r) {
607
1717
  left: i("margin-left", "margin-inline-start", /(?:^|[\s:.[!])(?:m|mx|ml|ms)-auto\b/)
608
1718
  };
609
1719
  }
610
- function W(e) {
1720
+ function lt(e, t, n) {
1721
+ let r = (e === "normal" ? 0 : parseFloat(e) || 0) - n;
1722
+ return r <= 0 ? 0 : Math.floor(r / (.025 * t) + 1e-6);
1723
+ }
1724
+ function ut(e, t) {
1725
+ if (!e || e === "normal" || t <= 0) return 0;
1726
+ let n = parseFloat(e);
1727
+ return Number.isFinite(n) ? Math.max(0, Math.floor(n / t + 1e-6) - 1) : 0;
1728
+ }
1729
+ function dt(e) {
1730
+ switch (e) {
1731
+ case "relative":
1732
+ case "absolute":
1733
+ case "fixed":
1734
+ case "sticky": return e;
1735
+ default: return "static";
1736
+ }
1737
+ }
1738
+ function ft(e, t, n, r, i) {
1739
+ let a = (a, o) => {
1740
+ if (t) {
1741
+ let e = t.get(a)?.toString().trim();
1742
+ return !e || e === "auto" ? null : $(e, i);
1743
+ }
1744
+ let s = r[a];
1745
+ if (s) return s === "auto" ? null : $(s, i);
1746
+ if (!o.test(n)) return null;
1747
+ let c = e.getPropertyValue(a);
1748
+ return !c || c === "auto" ? null : $(c, i);
1749
+ };
1750
+ return {
1751
+ top: a("top", /(?:^|[\s:.[!])-?(?:top|inset|inset-y)-/),
1752
+ right: a("right", /(?:^|[\s:.[!])-?(?:right|end|inset|inset-x)-/),
1753
+ bottom: a("bottom", /(?:^|[\s:.[!])-?(?:bottom|inset|inset-y)-/),
1754
+ left: a("left", /(?:^|[\s:.[!])-?(?:left|start|inset|inset-x)-/)
1755
+ };
1756
+ }
1757
+ function pt(e) {
611
1758
  switch (e) {
612
1759
  case "double": return "double";
613
1760
  case "dashed": return "dashed";
@@ -615,8 +1762,9 @@ function W(e) {
615
1762
  default: return "solid";
616
1763
  }
617
1764
  }
618
- function G(e, n) {
1765
+ function mt(e, n) {
619
1766
  if (!e || e === "none" || e === "auto") return;
1767
+ if (e === "min-content" || e === "max-content" || e === "fit-content") return e;
620
1768
  if (e.endsWith("%")) {
621
1769
  let t = parseFloat(e);
622
1770
  return Number.isFinite(t) ? { percent: t } : void 0;
@@ -624,7 +1772,7 @@ function G(e, n) {
624
1772
  let r = parseFloat(e);
625
1773
  return Number.isFinite(r) ? t(r, n) : void 0;
626
1774
  }
627
- function K(e, n) {
1775
+ function $(e, n) {
628
1776
  if (!e || e === "auto" || e === "none") return 0;
629
1777
  if (e.endsWith("%")) {
630
1778
  let t = parseFloat(e);
@@ -633,13 +1781,13 @@ function K(e, n) {
633
1781
  let r = parseFloat(e);
634
1782
  return Number.isFinite(r) ? t(r, n) : 0;
635
1783
  }
636
- function q(n, r, i, a, o, s) {
1784
+ function ht(n, r, i, a, o, s) {
637
1785
  if (n) {
638
1786
  let r = n.get(i);
639
1787
  if (r == null) return;
640
1788
  let o = r.toString().trim();
641
1789
  if (o === "auto") return { kind: "auto" };
642
- let s = J(o);
1790
+ let s = _t(o);
643
1791
  if (s) return s;
644
1792
  if (o.endsWith("%")) return {
645
1793
  kind: "percent",
@@ -657,7 +1805,7 @@ function q(n, r, i, a, o, s) {
657
1805
  let c = i === "width" ? s.width : s.height;
658
1806
  if (c) {
659
1807
  if (c === "auto") return { kind: "auto" };
660
- let e = J(c);
1808
+ let e = _t(c);
661
1809
  if (e) return e;
662
1810
  if (c.endsWith("%")) return {
663
1811
  kind: "percent",
@@ -673,7 +1821,7 @@ function q(n, r, i, a, o, s) {
673
1821
  if (RegExp(`(?:^|[\\s:.[!])${l}-min\\b`).test(o)) return { kind: "min-content" };
674
1822
  if (RegExp(`(?:^|[\\s:.[!])${l}-max\\b`).test(o)) return { kind: "max-content" };
675
1823
  if (RegExp(`(?:^|[\\s:.[!])${l}-fit\\b`).test(o)) return { kind: "fit-content" };
676
- if (!ue(o, l) || r === "auto") return { kind: "auto" };
1824
+ if (!kt(o, l) || r === "auto") return { kind: "auto" };
677
1825
  if (r.endsWith("%")) return {
678
1826
  kind: "percent",
679
1827
  value: parseFloat(r)
@@ -684,9 +1832,9 @@ function q(n, r, i, a, o, s) {
684
1832
  value: t(u, a)
685
1833
  };
686
1834
  }
687
- function le(e, n) {
1835
+ function gt(e, n) {
688
1836
  if (!e || e === "auto" || e === "content") return;
689
- let r = J(e);
1837
+ let r = _t(e);
690
1838
  if (r) return r;
691
1839
  if (e.endsWith("%")) {
692
1840
  let t = parseFloat(e);
@@ -701,125 +1849,284 @@ function le(e, n) {
701
1849
  value: t(i, n)
702
1850
  } : void 0;
703
1851
  }
704
- function J(e) {
1852
+ function _t(e) {
705
1853
  if (e === "min-content") return { kind: "min-content" };
706
1854
  if (e === "max-content") return { kind: "max-content" };
707
1855
  if (e === "fit-content") return { kind: "fit-content" };
708
1856
  }
709
- function ue(e, t) {
710
- return (t === "w" ? /(?:^|[\s:.[!])w-/ : /(?:^|[\s:.[!])h-/).test(e);
1857
+ function vt(e, t) {
1858
+ let n = e.trim();
1859
+ if (!n || n === "none") return { kind: "none" };
1860
+ if (n === "subgrid" || n.startsWith("subgrid ")) return { kind: "subgrid" };
1861
+ let r = [], i = [], a = [], o = (e) => {
1862
+ i.push(a), a = [], r.push(e);
1863
+ }, s;
1864
+ for (let e of Et(n)) {
1865
+ let n = bt(e);
1866
+ if (n) {
1867
+ a.push(...n);
1868
+ continue;
1869
+ }
1870
+ let i = e.match(/^repeat\(\s*([^,]+?)\s*,(.*)\)$/s);
1871
+ if (i) {
1872
+ let e = yt(i[2].trim(), t);
1873
+ if (e.tracks.length === 0) continue;
1874
+ let n = i[1];
1875
+ if (n === "auto-fill" || n === "auto-fit") {
1876
+ s || (s = {
1877
+ index: r.length,
1878
+ tracks: e.tracks,
1879
+ mode: n
1880
+ }, e.lineNames.some((e) => e.length > 0) && (s.lineNames = e.lineNames), a.length > 0 && (s.leadingNames = a), a = []);
1881
+ continue;
1882
+ }
1883
+ let c = Math.max(0, Math.floor(Number(n) || 0));
1884
+ for (let t = 0; t < c; t++) {
1885
+ a.push(...e.lineNames[0]);
1886
+ for (let t = 0; t < e.tracks.length; t++) o(e.tracks[t]), a.push(...e.lineNames[t + 1]);
1887
+ }
1888
+ continue;
1889
+ }
1890
+ o(Ct(e, t));
1891
+ }
1892
+ if (i.push(a), r.length === 0 && !s) return { kind: "none" };
1893
+ let c = {
1894
+ kind: "tracks",
1895
+ tracks: r
1896
+ };
1897
+ return i.some((e) => e.length > 0) && (c.lineNames = i), s && (c.autoRepeat = s), c;
1898
+ }
1899
+ function yt(e, t) {
1900
+ let n = [], r = [], i = [];
1901
+ for (let a of Et(e)) {
1902
+ let e = bt(a);
1903
+ if (e) {
1904
+ i.push(...e);
1905
+ continue;
1906
+ }
1907
+ r.push(i), i = [], n.push(Ct(a, t));
1908
+ }
1909
+ return r.push(i), {
1910
+ tracks: n,
1911
+ lineNames: r
1912
+ };
1913
+ }
1914
+ function bt(e) {
1915
+ let t = e.match(/^\[(.*)\]$/s);
1916
+ return t ? t[1].split(/\s+/).filter((e) => e !== "") : null;
711
1917
  }
712
- function de(e, t) {
1918
+ function xt(e) {
1919
+ let t = [];
1920
+ for (let n of e.matchAll(/"([^"]*)"|'([^']*)'/g)) {
1921
+ let e = (n[1] ?? n[2] ?? "").trim().split(/\s+/).filter((e) => e !== "");
1922
+ if (e.length === 0) return null;
1923
+ t.push(e);
1924
+ }
1925
+ if (t.length === 0) return null;
1926
+ let n = t[0].length;
1927
+ if (t.some((e) => e.length !== n)) return null;
1928
+ let r = /* @__PURE__ */ new Map();
1929
+ t.forEach((e, t) => {
1930
+ e.forEach((e, n) => {
1931
+ if (/^\.+$/.test(e)) return;
1932
+ let i = r.get(e);
1933
+ i ? (i.colStart = Math.min(i.colStart, n), i.colEnd = Math.max(i.colEnd, n + 1), i.rowStart = Math.min(i.rowStart, t), i.rowEnd = Math.max(i.rowEnd, t + 1)) : r.set(e, {
1934
+ colStart: n,
1935
+ colEnd: n + 1,
1936
+ rowStart: t,
1937
+ rowEnd: t + 1
1938
+ });
1939
+ });
1940
+ });
1941
+ for (let [e, n] of r) for (let r = n.rowStart; r < n.rowEnd; r++) for (let i = n.colStart; i < n.colEnd; i++) if (t[r][i] !== e) return null;
713
1942
  return {
714
- top: K(e.getPropertyValue("padding-top"), t),
715
- right: K(e.getPropertyValue("padding-right"), t),
716
- bottom: K(e.getPropertyValue("padding-bottom"), t),
717
- left: K(e.getPropertyValue("padding-left"), t)
1943
+ columns: n,
1944
+ rows: t.length,
1945
+ areas: r
718
1946
  };
719
1947
  }
720
- function fe(t) {
721
- let n = (n, r) => t.getPropertyValue(r) === "none" ? 0 : e(parseFloat(t.getPropertyValue(n)) || 0);
1948
+ function St(e, t) {
1949
+ let n = Et(e.trim()).filter((e) => e !== "" && !e.startsWith("[")).map((e) => Ct(e, t));
1950
+ return n.length > 0 ? n : [N()];
1951
+ }
1952
+ function Ct(e, t) {
1953
+ let n = e.match(/^minmax\((.*)\)$/s);
1954
+ if (n) {
1955
+ let e = Tt(n[1]).map((e) => e.trim());
1956
+ return e.length === 2 ? {
1957
+ min: wt(e[0], t),
1958
+ max: wt(e[1], t)
1959
+ } : {
1960
+ min: { kind: "auto" },
1961
+ max: { kind: "auto" }
1962
+ };
1963
+ }
1964
+ let r = wt(e, t);
1965
+ return r.kind === "fr" ? {
1966
+ min: { kind: "auto" },
1967
+ max: r
1968
+ } : {
1969
+ min: r,
1970
+ max: r
1971
+ };
1972
+ }
1973
+ function wt(n, r) {
1974
+ if (n === "auto" || n.startsWith("fit-content")) return { kind: "auto" };
1975
+ if (n === "min-content") return { kind: "min-content" };
1976
+ if (n === "max-content") return { kind: "max-content" };
1977
+ let i = n.match(/^(min|max)\((.*)\)$/s);
1978
+ if (i) {
1979
+ let e = Tt(i[2]).map((e) => wt(e.trim(), r)), t = e.every((e) => e.kind === "cells" || e.kind === "percent" || e.kind === "math");
1980
+ return e.length > 0 && t ? {
1981
+ kind: "math",
1982
+ fn: i[1],
1983
+ args: e
1984
+ } : { kind: "auto" };
1985
+ }
1986
+ if (n.endsWith("fr")) {
1987
+ let e = parseFloat(n);
1988
+ return Number.isFinite(e) && e >= 0 ? {
1989
+ kind: "fr",
1990
+ value: e
1991
+ } : { kind: "auto" };
1992
+ }
1993
+ if (n.endsWith("%")) {
1994
+ let e = parseFloat(n);
1995
+ return Number.isFinite(e) ? {
1996
+ kind: "percent",
1997
+ value: e
1998
+ } : { kind: "auto" };
1999
+ }
2000
+ let a = parseFloat(n);
2001
+ return Number.isFinite(a) ? {
2002
+ kind: "cells",
2003
+ value: n.endsWith("rem") ? e(a / .25) : t(a, r)
2004
+ } : { kind: "auto" };
2005
+ }
2006
+ function Tt(e) {
2007
+ let t = [], n = 0, r = 0;
2008
+ for (let i = 0; i < e.length; i++) {
2009
+ let a = e[i];
2010
+ a === "(" ? n++ : a === ")" ? n-- : a === "," && n === 0 && (t.push(e.slice(r, i)), r = i + 1);
2011
+ }
2012
+ return t.push(e.slice(r)), t.filter((e) => e.trim() !== "");
2013
+ }
2014
+ function Et(e) {
2015
+ let t = [], n = 0, r = -1;
2016
+ for (let i = 0; i < e.length; i++) {
2017
+ let a = e[i];
2018
+ a === "(" || a === "[" ? n++ : (a === ")" || a === "]") && n--, /\s/.test(a) && n === 0 ? (r !== -1 && t.push(e.slice(r, i)), r = -1) : r === -1 && (r = i);
2019
+ }
2020
+ return r !== -1 && t.push(e.slice(r)), t;
2021
+ }
2022
+ function Dt(e) {
2023
+ let t = e.trim();
2024
+ if (!t || t === "auto") return { kind: "auto" };
2025
+ let n = !1, r, i;
2026
+ for (let e of t.split(/\s+/)) e === "span" ? n = !0 : /^-?\d+$/.test(e) ? r = Number(e) : i = e;
2027
+ if (n) {
2028
+ let e = r ?? 1;
2029
+ return e < 1 ? { kind: "auto" } : i === void 0 ? {
2030
+ kind: "span",
2031
+ value: e
2032
+ } : {
2033
+ kind: "span",
2034
+ value: e,
2035
+ name: i
2036
+ };
2037
+ }
2038
+ return i === void 0 ? r !== void 0 && r !== 0 ? {
2039
+ kind: "line",
2040
+ value: r
2041
+ } : { kind: "auto" } : r === 0 ? { kind: "auto" } : r === void 0 ? {
2042
+ kind: "name",
2043
+ name: i
2044
+ } : {
2045
+ kind: "name",
2046
+ name: i,
2047
+ nth: r
2048
+ };
2049
+ }
2050
+ function Ot(e) {
722
2051
  return {
723
- top: n("border-top-width", "border-top-style"),
724
- right: n("border-right-width", "border-right-style"),
725
- bottom: n("border-bottom-width", "border-bottom-style"),
726
- left: n("border-left-width", "border-left-style")
2052
+ direction: e.includes("column") ? "column" : "row",
2053
+ dense: e.includes("dense")
727
2054
  };
728
2055
  }
729
- //#endregion
730
- //#region src/types.ts
731
- function pe() {
2056
+ function kt(e, t) {
2057
+ return (t === "w" ? /(?:^|[\s:.[!])w-/ : /(?:^|[\s:.[!])h-/).test(e);
2058
+ }
2059
+ function At(e, t) {
732
2060
  return {
733
- display: "block",
734
- flexDirection: "row",
735
- flexReverse: !1,
736
- flexWrap: "nowrap",
737
- wrapReverse: !1,
738
- flexGrow: 0,
739
- flexShrink: 0,
740
- flexBasis: void 0,
741
- order: 0,
742
- justifyContent: "start",
743
- alignItems: "start",
744
- alignSelf: "auto",
745
- width: void 0,
746
- height: void 0,
747
- minWidth: "auto",
748
- minHeight: "auto",
749
- maxWidth: void 0,
750
- maxHeight: void 0,
751
- padding: Y(),
752
- margin: {
753
- top: 0,
754
- right: 0,
755
- bottom: 0,
756
- left: 0
757
- },
758
- gapX: 0,
759
- gapY: 0,
760
- border: Y(),
761
- borderStyle: {
762
- top: "solid",
763
- right: "solid",
764
- bottom: "solid",
765
- left: "solid"
766
- },
767
- overflow: "visible",
768
- whiteSpace: "normal",
769
- textOverflow: "clip",
770
- color: void 0,
771
- backgroundColor: void 0,
772
- borderColor: {
773
- top: void 0,
774
- right: void 0,
775
- bottom: void 0,
776
- left: void 0
777
- },
778
- textAlignBlocked: !1
2061
+ top: $(e.getPropertyValue("padding-top"), t),
2062
+ right: $(e.getPropertyValue("padding-right"), t),
2063
+ bottom: $(e.getPropertyValue("padding-bottom"), t),
2064
+ left: $(e.getPropertyValue("padding-left"), t)
779
2065
  };
780
2066
  }
781
- function Y() {
2067
+ function jt(t) {
2068
+ let n = (n, r) => t.getPropertyValue(r) === "none" ? 0 : e(parseFloat(t.getPropertyValue(n)) || 0);
782
2069
  return {
783
- top: 0,
784
- right: 0,
785
- bottom: 0,
786
- left: 0
2070
+ top: n("border-top-width", "border-top-style"),
2071
+ right: n("border-right-width", "border-right-style"),
2072
+ bottom: n("border-bottom-width", "border-bottom-style"),
2073
+ left: n("border-left-width", "border-left-style")
787
2074
  };
788
2075
  }
789
2076
  //#endregion
790
2077
  //#region src/tree.ts
791
- function X(e, t) {
792
- let n = re(e, t);
793
- if (n.display === "none") return null;
794
- let r = Array.from(e.children);
795
- if (r.every(he)) {
796
- let t = Z(e).split("\n").map((e) => e.trim()).join("\n").trim(), r = ge(t), i = t.length > 0 ? _e(t) : 0;
797
- return {
2078
+ function Mt(e, t, n) {
2079
+ let r = tt(e, t, n);
2080
+ if (r.display === "none") return null;
2081
+ let i = Array.from(e.children), a = i.map(Lt);
2082
+ if (!a.includes("block")) {
2083
+ let o = Rt(e, r.tracking, {
2084
+ rootFontSizePx: t,
2085
+ rootLetterSpacingPx: n?.letterSpacing ?? 0,
2086
+ cellMetrics: n,
2087
+ preserve: r.whiteSpace === "pre",
2088
+ tabSize: r.tabSize
2089
+ }), s = o.chars.join("");
2090
+ if (o.boxes.length > 0) {
2091
+ let e = Le();
2092
+ d(o.chars, (t, n) => {
2093
+ o.advances[t] = Math.max(1, X(o.boxes[n], e));
2094
+ });
2095
+ }
2096
+ let c = Ut(s, o.advances, r.tracking), l = s.length > 0 ? Wt(s) : 0, u = [...o.boxes];
2097
+ for (let e = 0; e < i.length; e++) {
2098
+ if (a[e] !== "out-of-flow") continue;
2099
+ let r = Mt(i[e], t, n);
2100
+ r && u.push(r);
2101
+ }
2102
+ let f = {
798
2103
  source: e,
799
- style: n,
800
- children: [],
801
- text: t,
802
- intrinsicWidth: r,
803
- intrinsicHeight: i,
2104
+ style: r,
2105
+ children: u,
2106
+ text: s,
2107
+ intrinsicWidth: c,
2108
+ intrinsicHeight: l,
804
2109
  localRect: {
805
2110
  x: 0,
806
2111
  y: 0,
807
- width: r,
808
- height: i
2112
+ width: c,
2113
+ height: l
809
2114
  },
810
2115
  unclampedHeight: 0,
811
- resolvedPadding: Y()
2116
+ resolvedPadding: M()
812
2117
  };
2118
+ return (o.advances.some((e) => e !== 1) || o.boxes.length > 0) && (f.advances = o.advances), o.inlineElements.length > 0 && (f.inlineElements = o.inlineElements), f;
813
2119
  }
814
- let i = [];
815
- for (let e of r) {
816
- let n = X(e, t);
817
- n && i.push(n);
2120
+ let o = [];
2121
+ for (let e = 0; e < i.length; e++) {
2122
+ if (a[e] === "none") continue;
2123
+ let r = Mt(i[e], t, n);
2124
+ r && o.push(r);
818
2125
  }
819
- return {
2126
+ let s = {
820
2127
  source: e,
821
- style: n,
822
- children: i,
2128
+ style: r,
2129
+ children: o,
823
2130
  text: "",
824
2131
  intrinsicWidth: 0,
825
2132
  intrinsicHeight: 0,
@@ -830,49 +2137,152 @@ function X(e, t) {
830
2137
  height: 0
831
2138
  },
832
2139
  unclampedHeight: 0,
833
- resolvedPadding: Y()
2140
+ resolvedPadding: M()
834
2141
  };
2142
+ return Jt(e, s), s;
2143
+ }
2144
+ var Nt = /* @__PURE__ */ new Set(/* @__PURE__ */ "A.ABBR.B.BDI.BDO.BR.CITE.CODE.DATA.DFN.EM.I.KBD.MARK.Q.S.SAMP.SMALL.SPAN.STRONG.SUB.SUP.TIME.U.VAR.WBR".split("."));
2145
+ function Pt(e, t) {
2146
+ return t || (Nt.has(e.tagName) ? "inline" : "block");
2147
+ }
2148
+ function Ft(e, t) {
2149
+ let n = Pt(e, t);
2150
+ return n === "inline" || n === "contents";
2151
+ }
2152
+ function It(e, t) {
2153
+ let n = Pt(e, t);
2154
+ return n.startsWith("inline") && n !== "inline";
2155
+ }
2156
+ function Lt(e) {
2157
+ let t = getComputedStyle(e);
2158
+ return t.display === "none" ? "none" : t.position === "absolute" || t.position === "fixed" ? "out-of-flow" : Ft(e, t.display) || It(e, t.display) ? "inline" : "block";
2159
+ }
2160
+ function Rt(e, t, n) {
2161
+ let r = {
2162
+ chars: [],
2163
+ advances: [],
2164
+ inlineElements: [],
2165
+ boxes: []
2166
+ };
2167
+ return zt(e, t, n, r), n.preserve ? (r.chars[r.chars.length - 1] === "\n" && (r.chars.pop(), r.advances.pop()), r) : Ht(r);
835
2168
  }
836
- var me = /* @__PURE__ */ new Set(/* @__PURE__ */ "A.ABBR.B.BDI.BDO.BR.CITE.CODE.DATA.DFN.EM.I.KBD.MARK.Q.S.SAMP.SMALL.SPAN.STRONG.SUB.SUP.TIME.U.VAR.WBR".split("."));
837
- function he(e) {
838
- if (me.has(e.tagName)) return !0;
839
- let t = getComputedStyle(e).display;
840
- return t.startsWith("inline") || t === "contents";
2169
+ function zt(e, t, n, r) {
2170
+ let i = () => {
2171
+ let e = 0;
2172
+ for (let t = r.chars.length - 1; t >= 0 && r.chars[t] !== "\n"; t--) e += r.advances[t];
2173
+ return e;
2174
+ };
2175
+ for (let a of Array.from(e.childNodes)) if (a.nodeType === Node.TEXT_NODE) {
2176
+ if (n.preserve) for (let e of (a.textContent ?? "").replace(/\r\n?/g, "\n")) if (e === "\n") r.chars.push("\n"), r.advances.push(0);
2177
+ else if (e === " ") {
2178
+ let e = (Math.floor(i() / n.tabSize) + 1) * n.tabSize;
2179
+ for (let t = i(); t < e; t++) r.chars.push(" "), r.advances.push(1);
2180
+ } else r.chars.push(e), r.advances.push(1 + t);
2181
+ else for (let e of (a.textContent ?? "").replace(/[ \t\r\n\f]+/g, " ")) r.chars.push(e), r.advances.push(1 + t);
2182
+ } else if (a.nodeType === Node.ELEMENT_NODE) {
2183
+ let e = a;
2184
+ if (e.tagName === "BR") {
2185
+ r.chars.push("\n"), r.advances.push(0);
2186
+ continue;
2187
+ }
2188
+ let t = getComputedStyle(e);
2189
+ if (t.display === "none" || t.position === "absolute" || t.position === "fixed") continue;
2190
+ if (It(e, t.display)) {
2191
+ let t = Mt(e, n.rootFontSizePx, n.cellMetrics);
2192
+ t && (t.inlineBox = !0, r.chars.push(""), r.advances.push(1), r.boxes.push(t));
2193
+ continue;
2194
+ }
2195
+ if (!Ft(e, t.display)) {
2196
+ qt(e);
2197
+ continue;
2198
+ }
2199
+ let i = lt(t.letterSpacing, parseFloat(t.fontSize) || n.rootFontSizePx, n.rootLetterSpacingPx), o = Bt(t.paddingLeft, n.rootFontSizePx), s = Bt(t.paddingRight, n.rootFontSizePx);
2200
+ r.inlineElements.push({
2201
+ element: e,
2202
+ tracking: i,
2203
+ padLeft: o,
2204
+ padRight: s,
2205
+ insets: t.position === "static" ? null : Vt(t, n.rootFontSizePx)
2206
+ });
2207
+ for (let e = 0; e < o; e++) r.chars.push("⁠"), r.advances.push(1);
2208
+ zt(e, i, n, r);
2209
+ for (let e = 0; e < s; e++) r.chars.push("⁠"), r.advances.push(1);
2210
+ }
841
2211
  }
842
- function Z(e) {
843
- let t = [];
844
- for (let n of Array.from(e.childNodes)) if (n.nodeType === Node.TEXT_NODE) t.push((n.textContent ?? "").replace(/[ \t\r\n\f]+/g, " "));
845
- else if (n.nodeType === Node.ELEMENT_NODE) {
846
- let e = n;
847
- e.tagName === "BR" ? t.push("\n") : t.push(Z(e));
2212
+ function Bt(e, n) {
2213
+ if (!e || e.endsWith("%")) return 0;
2214
+ let r = parseFloat(e);
2215
+ return Number.isFinite(r) ? Math.max(0, t(r, n)) : 0;
2216
+ }
2217
+ function Vt(e, n) {
2218
+ let r = (e) => {
2219
+ if (!e || e === "auto" || e.endsWith("%")) return null;
2220
+ let r = parseFloat(e);
2221
+ return Number.isFinite(r) ? t(r, n) : null;
2222
+ };
2223
+ return {
2224
+ top: r(e.top),
2225
+ right: r(e.right),
2226
+ bottom: r(e.bottom),
2227
+ left: r(e.left)
2228
+ };
2229
+ }
2230
+ function Ht(e) {
2231
+ let t = [], n = [], r = () => {
2232
+ let e = t.length;
2233
+ for (; e > 0 && t[e - 1] !== "\n";) e--;
2234
+ return e;
2235
+ }, i = () => {
2236
+ for (; t.length > r() && t[t.length - 1] === " ";) t.pop(), n.pop();
2237
+ };
2238
+ for (let r = 0; r < e.chars.length; r++) {
2239
+ let a = e.chars[r];
2240
+ if (a === " ") {
2241
+ let e = t.length - 1;
2242
+ for (; e >= 0 && t[e] === "⁠";) e--;
2243
+ if (e < 0 || t[e] === "\n" || t[e] === " ") continue;
2244
+ } else a === "\n" && i();
2245
+ t.push(a), n.push(e.advances[r]);
848
2246
  }
849
- return t.join("");
2247
+ for (i(); t[0] === "\n";) t.shift(), n.shift();
2248
+ for (; t[t.length - 1] === "\n";) t.pop(), n.pop();
2249
+ return {
2250
+ chars: t,
2251
+ advances: n,
2252
+ inlineElements: e.inlineElements,
2253
+ boxes: e.boxes
2254
+ };
850
2255
  }
851
- function ge(e) {
852
- let t = 0;
853
- for (let n of e.split("\n")) n.length > t && (t = n.length);
854
- return t;
2256
+ function Ut(e, t, n) {
2257
+ let r = 0, i = 0;
2258
+ for (let a = 0; a <= e.length; a++) (a === e.length || e[a] === "\n") && (r = Math.max(r, c(i, a, t, n)), i = a + 1);
2259
+ return r;
855
2260
  }
856
- function _e(e) {
2261
+ function Wt(e) {
857
2262
  return e.split("\n").length;
858
2263
  }
2264
+ var Gt = /* @__PURE__ */ new WeakSet(), Kt = /* @__PURE__ */ new WeakSet();
2265
+ function qt(e) {
2266
+ Kt.has(e) || (Kt.add(e), console.warn("[monowind] A block-level element nested inside a text run can't be laid out and was skipped. Give it its own place in the layout instead.", e));
2267
+ }
2268
+ function Jt(e, t) {
2269
+ Array.from(e.childNodes).some((e) => e.nodeType === Node.TEXT_NODE && /[^ \t\r\n\f]/.test(e.textContent ?? "")) && (t.droppedText = !0, !Gt.has(e) && (Gt.add(e), console.warn("[monowind] Direct text next to block-level children can't be laid out and was hidden. Wrap each text segment in its own element (e.g. a <div>).", e)));
2270
+ }
859
2271
  //#endregion
860
2272
  //#region src/element.ts
861
- var ve = "\n<style>\n :host { display: block; position: relative; contain: layout style; }\n #viewport { position: relative; width: 100%; height: 100%; }\n #decorations { position: absolute; inset: 0; pointer-events: none; user-select: none; white-space: pre; }\n</style>\n<div id=\"viewport\">\n <div id=\"decorations\" aria-hidden=\"true\"></div>\n <slot></slot>\n</div>\n", Q = class extends HTMLElement {
2273
+ var Yt = "\n<style>\n :host { display: block; position: relative; contain: layout style; }\n #viewport { position: relative; width: 100%; height: 100%; }\n /* When the host hides its own dropped direct text (visibility, see\n * styles.css), the decoration layer must not sink with it. Scoped to\n * that state so an authored 'invisible' on the host stays intact. */\n :host([data-mw-dropped-text]) #viewport { visibility: visible; }\n #decorations { position: absolute; inset: 0; pointer-events: none; user-select: none; white-space: pre; }\n</style>\n<div id=\"viewport\">\n <div id=\"decorations\" aria-hidden=\"true\"></div>\n <slot></slot>\n</div>\n", Xt = typeof HTMLElement > "u" ? class {} : HTMLElement, Zt = class extends Xt {
862
2274
  #e;
863
2275
  #t;
864
- #n = null;
2276
+ #n;
865
2277
  #r = null;
866
- #i = !1;
867
- #a = 0;
2278
+ #i = null;
2279
+ #a = !1;
868
2280
  #o = null;
869
2281
  constructor() {
870
- super(), this.#e = this.attachShadow({ mode: "open" }), this.#e.innerHTML = ve, this.#t = this.#e.getElementById("decorations");
2282
+ super(), this.#e = this.attachShadow({ mode: "open" }), this.#e.innerHTML = Yt, this.#t = this.#e.getElementById("decorations"), this.#n = document.createElement("span"), this.#n.setAttribute("aria-hidden", "true"), this.#n.setAttribute("data-mw-probe", ""), this.#n.style.cssText = "position:absolute!important;top:0!important;left:0!important;visibility:hidden!important;pointer-events:none!important;user-select:none!important;white-space:pre!important;overflow-wrap:normal!important;padding:0!important;margin:0!important;border:0!important;", this.#n.textContent = "M".repeat(100);
871
2283
  }
872
2284
  connectedCallback() {
873
- this.#n = new ResizeObserver(() => this.#l()), this.#n.observe(this), this.#r = new MutationObserver((e) => {
874
- this.#a > 0 || e.every(this.#c) || (e.some((e) => e.target === this && e.type === "attributes") && (this.#o = null), this.#l());
875
- }), this.#r.observe(this, {
2285
+ this.#n.parentNode !== this && this.appendChild(this.#n), this.#r = new ResizeObserver(() => this.#c()), this.#r.observe(this), this.#i = new MutationObserver(() => this.#c()), this.#i.observe(this, {
876
2286
  childList: !0,
877
2287
  subtree: !0,
878
2288
  characterData: !0,
@@ -880,48 +2290,45 @@ var ve = "\n<style>\n :host { display: block; position: relative; contain: layo
880
2290
  attributeFilter: ["class", "style"]
881
2291
  }), document.fonts?.ready.then(this.#s).catch((e) => {
882
2292
  console.warn("[monowind] document.fonts.ready failed:", e);
883
- }), document.fonts?.addEventListener("loadingdone", this.#s), this.#l();
2293
+ }), document.fonts?.addEventListener("loadingdone", this.#s), this.#c();
884
2294
  }
885
2295
  disconnectedCallback() {
886
- this.#n?.disconnect(), this.#r?.disconnect(), this.#n = null, this.#r = null, document.fonts?.removeEventListener("loadingdone", this.#s), this.#o = null;
2296
+ this.#r?.disconnect(), this.#i?.disconnect(), this.#r = null, this.#i = null, document.fonts?.removeEventListener("loadingdone", this.#s);
887
2297
  }
888
2298
  #s = () => {
889
- this.#o = null, this.#l();
890
- };
891
- #c = (e) => {
892
- if (e.type !== "attributes") return !1;
893
- let t = e.attributeName;
894
- return t === "data-mw-laid-out" || t === "data-mw-ready" || t === "data-mw-text-align-blocked" || t === "data-mw-clip" || t === "data-mw-nowrap" || t === "style" && this.#a > 0;
2299
+ requestAnimationFrame(() => this.#c());
895
2300
  };
896
- #l() {
897
- this.#i || (this.#i = !0, requestAnimationFrame(() => {
898
- this.#i = !1;
2301
+ #c() {
2302
+ this.#a || (this.#a = !0, requestAnimationFrame(() => {
2303
+ this.#a = !1;
899
2304
  try {
900
- this.#u();
2305
+ this.#l();
901
2306
  } catch (e) {
902
2307
  console.error("[monowind] layout failed:", e);
903
2308
  }
904
2309
  }));
905
2310
  }
906
- #u() {
907
- this.#a++, this.setAttribute("measuring", "");
2311
+ #l() {
2312
+ this.setAttribute("measuring", "");
908
2313
  try {
909
- this.#o || (this.#o = r(this), this.style.setProperty("--mw-cw", `${this.#o.width}px`), this.style.setProperty("--mw-ch", `${this.#o.height}px`));
910
- let e = this.#o, t = Math.max(0, Math.floor(this.clientWidth / e.width));
911
- if (t === 0) return;
912
- let n = i(), a = [];
913
- for (let e of Array.from(this.children)) {
914
- let t = X(e, n);
915
- t && a.push(t);
2314
+ let e = r(this, this.#n), t = this.#o;
2315
+ (t === null || t.width !== e.width || t.height !== e.height || t.letterSpacing !== e.letterSpacing) && (this.style.setProperty("--mw-cw", `${e.width}px`), this.style.setProperty("--mw-ch", `${e.height}px`), this.style.setProperty("--mw-rls", `${e.letterSpacing}px`)), this.#o = e;
2316
+ let n = getComputedStyle(this), a = (parseFloat(n.paddingLeft) || 0) + (parseFloat(n.paddingRight) || 0), o = Math.max(0, Math.floor((this.clientWidth - a) / e.width));
2317
+ if (o === 0) return;
2318
+ let s = i(), c = [];
2319
+ for (let t of Array.from(this.children)) {
2320
+ if (t === this.#n) continue;
2321
+ let n = Mt(t, s, e);
2322
+ n && c.push(n);
916
2323
  }
917
- if (a.length === 0) {
2324
+ if (Array.from(this.childNodes).some((e) => e.nodeType === Node.TEXT_NODE && /[^ \t\r\n\f]/.test(e.textContent ?? "")) ? (this.hasAttribute("data-mw-dropped-text") || console.warn("[monowind] Direct text inside <mono-wind> can't be laid out and was hidden. Wrap each text segment in its own element (e.g. a <div>).", this), this.setAttribute("data-mw-dropped-text", "")) : this.removeAttribute("data-mw-dropped-text"), c.length === 0) {
918
2325
  this.#t.replaceChildren(), this.setAttribute("data-mw-ready", "");
919
2326
  return;
920
2327
  }
921
- let o = {
2328
+ let l = {
922
2329
  source: this,
923
- style: pe(),
924
- children: a,
2330
+ style: j(),
2331
+ children: c,
925
2332
  text: "",
926
2333
  intrinsicWidth: 0,
927
2334
  intrinsicHeight: 0,
@@ -932,56 +2339,65 @@ var ve = "\n<style>\n :host { display: block; position: relative; contain: layo
932
2339
  height: 0
933
2340
  },
934
2341
  unclampedHeight: 0,
935
- resolvedPadding: {
936
- top: 0,
937
- right: 0,
938
- bottom: 0,
939
- left: 0
940
- }
941
- }, { height: s } = l(o, t);
942
- ee(o, this.#t), this.style.height = `${s * e.height}px`, this.setAttribute("data-mw-ready", "");
2342
+ resolvedPadding: M()
2343
+ }, { height: u } = Fe(l, o);
2344
+ Xe(l, this.#t);
2345
+ let d = n.boxSizing === "border-box" ? (parseFloat(n.paddingTop) || 0) + (parseFloat(n.paddingBottom) || 0) + (parseFloat(n.borderTopWidth) || 0) + (parseFloat(n.borderBottomWidth) || 0) : 0;
2346
+ this.style.height = `${u * e.height + d}px`, this.setAttribute("data-mw-ready", "");
943
2347
  } finally {
944
- this.removeAttribute("measuring"), queueMicrotask(() => {
945
- this.#r?.takeRecords(), this.#a--;
946
- });
2348
+ this.removeAttribute("measuring"), this.#i?.takeRecords();
947
2349
  }
948
2350
  }
949
2351
  };
950
- function ye() {
951
- customElements.get("mono-wind") || customElements.define("mono-wind", Q);
2352
+ function Qt() {
2353
+ typeof customElements > "u" || customElements.get("mono-wind") || customElements.define("mono-wind", Zt);
952
2354
  }
953
2355
  //#endregion
954
2356
  //#region src/ascii.ts
955
- function be(e) {
2357
+ function $t(e) {
956
2358
  let t = e.localRect.width, n = e.localRect.height;
957
2359
  if (t <= 0 || n <= 0) return "";
958
2360
  let r = Array.from({ length: n }, () => Array.from({ length: t }, () => " "));
959
- return $(e, 0, 0, (e, i, a) => {
2361
+ return en(e, 0, 0, (e, i, a) => {
960
2362
  e >= 0 && e < t && i >= 0 && i < n && (r[i][e] = a);
961
2363
  }), r.map((e) => e.join("").trimEnd()).join("\n");
962
2364
  }
963
- function $(e, t, n, r) {
964
- let i = t + e.localRect.x, o = n + e.localRect.y, s = e.style, c = [];
965
- R(s, {
2365
+ function en(e, t, n, r) {
2366
+ let i = t + e.localRect.x, a = n + e.localRect.y, o = e.style, c = [];
2367
+ Je(o, {
966
2368
  x: i,
967
- y: o,
2369
+ y: a,
968
2370
  width: e.localRect.width,
969
2371
  height: e.localRect.height
970
2372
  }, c);
971
2373
  for (let e of c) for (let t = 0; t < e.length; t++) r(e.x + t, e.y, e.glyph);
972
- if (e.children.length === 0 && e.text) {
973
- let t = e.resolvedPadding, n = i + s.border.left + t.left, c = o + s.border.top + t.top, l = e.localRect.width - s.border.left - s.border.right - t.left - t.right, u = s.whiteSpace === "nowrap" ? e.text.split("\n").map((e) => xe(e, l, s)) : a(e.text, l);
974
- for (let e = 0; e < u.length; e++) {
975
- let t = u[e];
976
- for (let i = 0; i < t.length; i++) r(n + i, c + e, t[i]);
2374
+ if (!e.children.some((e) => !e.inlineBox && e.style.position !== "absolute" && e.style.position !== "fixed") && e.text) {
2375
+ let t = e.resolvedPadding, n = i + o.border.left + t.left, c = a + o.border.top + t.top, l = e.localRect.width - o.border.left - o.border.right - t.left - t.right, { spans: u, lineY: d } = Be(e, l);
2376
+ for (let t = 0; t < u.length; t++) {
2377
+ let i = u[t], a = c + d[t], f = o.whiteSpace !== "normal" && o.overflow === "clip" ? tn(e.text, i, l, e.advances, o) : {
2378
+ end: i.end,
2379
+ ellipsis: !1
2380
+ }, p = n;
2381
+ for (let t = i.start; t < f.end; t++) e.text[t] !== "" && e.text[t] !== "⁠" && r(p, a, e.text[t]), p += s(t, t + 1, e.advances);
2382
+ f.ellipsis && r(p, a, "…");
977
2383
  }
978
2384
  }
979
- for (let t of e.children) $(t, i, o, r);
2385
+ for (let t of e.children) en(t, i, a, r);
980
2386
  }
981
- function xe(e, t, n) {
982
- return n.overflow !== "clip" || e.length <= t ? e : t <= 0 ? "" : n.textOverflow === "ellipsis" ? `${e.slice(0, t - 1)}…` : e.slice(0, t);
2387
+ function tn(e, t, n, r, i) {
2388
+ let { textOverflow: a, tracking: o } = i;
2389
+ if (c(t.start, t.end, r, o) <= n) return {
2390
+ end: t.end,
2391
+ ellipsis: !1
2392
+ };
2393
+ let s = a === "ellipsis" ? n - 1 : n, l = t.start;
2394
+ for (; l < t.end && c(t.start, l + 1, r, o) <= s;) l++;
2395
+ return {
2396
+ end: l,
2397
+ ellipsis: a === "ellipsis" && n > 0
2398
+ };
983
2399
  }
984
2400
  //#endregion
985
- export { Q as MonoWindElement, ye as defineMonoWind, be as renderAscii };
2401
+ export { Zt as MonoWindElement, Qt as defineMonoWind, $t as renderAscii };
986
2402
 
987
2403
  //# sourceMappingURL=index.js.map