kindy-editor 3.2.6 → 3.2.8

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.
Files changed (31) hide show
  1. package/dist-lib/assets/{worker-B7ALyZOw.js → worker-DjZBUOhB.js} +1009 -997
  2. package/dist-lib/assets/{worker-z-dyEi8F.js → worker-Du8hmveE.js} +2234 -2222
  3. package/dist-lib/builder.js +4 -4
  4. package/dist-lib/events.js +9 -120
  5. package/dist-lib/export.js +9 -11
  6. package/dist-lib/generate-toc.js +3 -3
  7. package/dist-lib/import.js +2 -2
  8. package/dist-lib/index-D5dkvB0x.js +490 -0
  9. package/dist-lib/{editorApp-Bu3dbUIU.js → kindy-editor-T1YCQdwF.js} +13483 -11185
  10. package/dist-lib/kindy-editor.js +4 -4
  11. package/dist-lib/measure.js +3 -4
  12. package/dist-lib/{measureHost-CpqJsipA.js → measureHost-BG9FPivu.js} +17 -18
  13. package/dist-lib/{paintStyle-Cb7IGKPW.js → metrics-D7Ma2xlj.js} +175 -148
  14. package/dist-lib/{parse-CKw-ZDr9.js → parse-BsUkqk-n.js} +3 -3
  15. package/dist-lib/{pipeline-BkC7G8gU.js → pipeline-CX_Hc5BD.js} +850 -837
  16. package/dist-lib/{qrcode-oNwKusWD.js → qrcode--5MhVNEZ.js} +1 -1
  17. package/dist-lib/{qrcode-efBlPzzh.js → qrcode-CR8i1-w0.js} +11 -11
  18. package/dist-lib/recalc-docx.js +1 -1
  19. package/dist-lib/{recalcToc-Bc8V9Ecn.js → recalcToc-zAFS4S6S.js} +755 -742
  20. package/dist-lib/{stylesheet-BT1DGhnx.js → stylesheet-BfxJTGA5.js} +1 -1
  21. package/dist-lib/{webmcp-ClHEa6Gq.js → webmcp-Ds469lXP.js} +2 -2
  22. package/docs/find-and-replace.md +224 -0
  23. package/docs/security-review.md +26 -0
  24. package/docs/table-editing.md +17 -2
  25. package/docs/table-form-integration.md +53 -1
  26. package/package.json +6 -6
  27. package/types/import.d.ts +7 -0
  28. package/types/kindy-editor.d.ts +30 -0
  29. package/dist-lib/changeAggregator-ZI959nPP.js +0 -376
  30. package/dist-lib/kindy-editor-CToKn_gP.js +0 -2171
  31. package/dist-lib/metrics-CdfHD-8y.js +0 -31
@@ -1,7 +1,6 @@
1
- import { o as Ln, r as Ls, t as Os, s as Ps } from "./qrcode-efBlPzzh.js";
1
+ import { l as Ln, m as Ls, t as Os, s as Ps } from "./qrcode-CR8i1-w0.js";
2
2
  import { c as Is, f as Ze } from "./lists-BVCy5dMa.js";
3
- import { m as he, f as Ue, c as le } from "./metrics-CdfHD-8y.js";
4
- import { c as vs, f as On, M as nt, g as Rs, P as Mt, w as Ws, s as Ts } from "./paintStyle-Cb7IGKPW.js";
3
+ import { c as vs, f as On, M as nt, m as he, a as Ue, S as Rs, b as le, P as Mt, w as Ws, s as Ts } from "./metrics-D7Ma2xlj.js";
5
4
  const Gs = [
6
5
  "BN",
7
6
  "BN",
@@ -1069,8 +1068,8 @@ function _s(e, t) {
1069
1068
  a++;
1070
1069
  const h = c > 0 ? s[c - 1] : l, u = a < n ? s[a] : l, E = h !== "L" ? "R" : "L";
1071
1070
  if (E === (u !== "L" ? "R" : "L"))
1072
- for (let S = c; S < a; S++)
1073
- s[S] = E;
1071
+ for (let A = c; A < a; A++)
1072
+ s[A] = E;
1074
1073
  c = a - 1;
1075
1074
  }
1076
1075
  for (let c = 0; c < n; c++)
@@ -1808,61 +1807,61 @@ function Tr(e) {
1808
1807
  function Gr(e, t, n) {
1809
1808
  const s = $s();
1810
1809
  let i = 0;
1811
- const r = [], o = [], x = [], l = [], d = [], c = [], a = [], h = [], u = [], E = [], p = [], S = [];
1812
- for (const A of s.segment(e))
1813
- for (const C of Ar(A.segment, A.isWordLike ?? !1, A.index, n)) {
1814
- let P = function() {
1810
+ const r = [], o = [], x = [], l = [], d = [], c = [], a = [], h = [], u = [], E = [], p = [], A = [];
1811
+ for (const m of s.segment(e))
1812
+ for (const y of Ar(m.segment, m.isWordLike ?? !1, m.index, n)) {
1813
+ let O = function() {
1815
1814
  c[B] !== null && (o[B] = [
1816
1815
  Qt(r, c, a, B)
1817
- ], c[B] = null), o[B].push(C.text), x[B] = x[B] || C.isWordLike, h[B] = h[B] || ee, u[B] = u[B] || v, E[B] = y, p[B] = $, S[B] = Vt(u[B], H);
1816
+ ], c[B] = null), o[B].push(y.text), x[B] = x[B] || y.isWordLike, h[B] = h[B] || J, u[B] = u[B] || I, E[B] = w, p[B] = K, A[B] = Vt(u[B], W);
1818
1817
  };
1819
- const _ = C.kind === "text", O = pr(C.text, C.isWordLike, C.kind), ee = fe(C.text), v = Jt(C.text), H = qe(C.text), y = mt(C.text), $ = gr(C.text), B = i - 1;
1820
- t.carryCJKAfterClosingQuote && _ && i > 0 && l[B] === "text" && ee && h[B] && E[B] || _ && i > 0 && l[B] === "text" && or(C.text) && h[B] || _ && i > 0 && l[B] === "text" && p[B] ? P() : _ && i > 0 && l[B] === "text" && C.isWordLike && v && S[B] ? (P(), x[B] = !0) : O !== null && i > 0 && l[B] === "text" && c[B] === O ? a[B] = (a[B] ?? 1) + 1 : _ && !C.isWordLike && i > 0 && l[B] === "text" && !h[B] && (ir(C.text) || C.text === "-" && x[B]) ? P() : (r[i] = C.text, o[i] = [C.text], x[i] = C.isWordLike, l[i] = C.kind, d[i] = C.start, c[i] = O, a[i] = O === null ? 0 : 1, h[i] = ee, u[i] = v, E[i] = y, p[i] = $, S[i] = Vt(v, H), i++);
1818
+ const _ = y.kind === "text", L = pr(y.text, y.isWordLike, y.kind), J = fe(y.text), I = Jt(y.text), W = qe(y.text), w = mt(y.text), K = gr(y.text), B = i - 1;
1819
+ t.carryCJKAfterClosingQuote && _ && i > 0 && l[B] === "text" && J && h[B] && E[B] || _ && i > 0 && l[B] === "text" && or(y.text) && h[B] || _ && i > 0 && l[B] === "text" && p[B] ? O() : _ && i > 0 && l[B] === "text" && y.isWordLike && I && A[B] ? (O(), x[B] = !0) : L !== null && i > 0 && l[B] === "text" && c[B] === L ? a[B] = (a[B] ?? 1) + 1 : _ && !y.isWordLike && i > 0 && l[B] === "text" && !h[B] && (ir(y.text) || y.text === "-" && x[B]) ? O() : (r[i] = y.text, o[i] = [y.text], x[i] = y.isWordLike, l[i] = y.kind, d[i] = y.start, c[i] = L, a[i] = L === null ? 0 : 1, h[i] = J, u[i] = I, E[i] = w, p[i] = K, A[i] = Vt(I, W), i++);
1821
1820
  }
1822
- for (let A = 0; A < i; A++) {
1823
- if (c[A] !== null) {
1824
- r[A] = Qt(r, c, a, A);
1821
+ for (let m = 0; m < i; m++) {
1822
+ if (c[m] !== null) {
1823
+ r[m] = Qt(r, c, a, m);
1825
1824
  continue;
1826
1825
  }
1827
- r[A] = de(o[A]);
1826
+ r[m] = de(o[m]);
1828
1827
  }
1829
- for (let A = 1; A < i; A++)
1830
- l[A] === "text" && !x[A] && Ct(r[A]) && l[A - 1] === "text" && !h[A - 1] && (r[A - 1] += r[A], x[A - 1] = x[A - 1] || x[A], r[A] = "");
1831
- const m = Array.from({ length: i }, () => null);
1832
- let W = -1;
1833
- for (let A = i - 1; A >= 0; A--) {
1834
- const C = r[A];
1835
- if (C.length !== 0) {
1836
- if (l[A] === "text" && !x[A] && W >= 0 && l[W] === "text" && (cr(C) || C === "-" && hr(r[W]))) {
1837
- const _ = m[W] ?? [];
1838
- _.push(C), m[W] = _, d[W] = d[A], r[A] = "";
1828
+ for (let m = 1; m < i; m++)
1829
+ l[m] === "text" && !x[m] && Ct(r[m]) && l[m - 1] === "text" && !h[m - 1] && (r[m - 1] += r[m], x[m - 1] = x[m - 1] || x[m], r[m] = "");
1830
+ const N = Array.from({ length: i }, () => null);
1831
+ let R = -1;
1832
+ for (let m = i - 1; m >= 0; m--) {
1833
+ const y = r[m];
1834
+ if (y.length !== 0) {
1835
+ if (l[m] === "text" && !x[m] && R >= 0 && l[R] === "text" && (cr(y) || y === "-" && hr(r[R]))) {
1836
+ const _ = N[R] ?? [];
1837
+ _.push(y), N[R] = _, d[R] = d[m], r[m] = "";
1839
1838
  continue;
1840
1839
  }
1841
- W = A;
1840
+ R = m;
1842
1841
  }
1843
1842
  }
1844
- for (let A = 0; A < i; A++) {
1845
- const C = m[A];
1846
- C != null && (r[A] = Sr(C, r[A]));
1843
+ for (let m = 0; m < i; m++) {
1844
+ const y = N[m];
1845
+ y != null && (r[m] = Sr(y, r[m]));
1847
1846
  }
1848
- let L = 0;
1849
- for (let A = 0; A < i; A++) {
1850
- const C = r[A];
1851
- C.length !== 0 && (L !== A && (r[L] = C, x[L] = x[A], l[L] = l[A], d[L] = d[A]), L++);
1847
+ let D = 0;
1848
+ for (let m = 0; m < i; m++) {
1849
+ const y = r[m];
1850
+ y.length !== 0 && (D !== m && (r[D] = y, x[D] = x[m], l[D] = l[m], d[D] = d[m]), D++);
1852
1851
  }
1853
- r.length = L, x.length = L, l.length = L, d.length = L;
1854
- const w = Wr({
1855
- len: L,
1852
+ r.length = D, x.length = D, l.length = D, d.length = D;
1853
+ const H = Wr({
1854
+ len: D,
1856
1855
  texts: r,
1857
1856
  isWordLike: x,
1858
1857
  kinds: l,
1859
1858
  starts: d
1860
- }), D = Tr(vr(Rr(Ir(br(Br(w))))));
1861
- for (let A = 0; A < D.len - 1; A++) {
1862
- const C = Fr(D.texts[A]);
1863
- C !== null && (D.kinds[A] !== "space" && D.kinds[A] !== "preserved-space" || D.kinds[A + 1] !== "text" || !Jt(D.texts[A + 1]) || (D.texts[A] = C.space, D.isWordLike[A] = !1, D.kinds[A] = D.kinds[A] === "preserved-space" ? "preserved-space" : "space", D.texts[A + 1] = C.marks + D.texts[A + 1], D.starts[A + 1] = D.starts[A] + C.space.length));
1859
+ }), b = Tr(vr(Rr(Ir(br(Br(H))))));
1860
+ for (let m = 0; m < b.len - 1; m++) {
1861
+ const y = Fr(b.texts[m]);
1862
+ y !== null && (b.kinds[m] !== "space" && b.kinds[m] !== "preserved-space" || b.kinds[m + 1] !== "text" || !Jt(b.texts[m + 1]) || (b.texts[m] = y.space, b.isWordLike[m] = !1, b.kinds[m] = b.kinds[m] === "preserved-space" ? "preserved-space" : "space", b.texts[m + 1] = y.marks + b.texts[m + 1], b.starts[m + 1] = b.starts[m] + y.space.length));
1864
1863
  }
1865
- return D;
1864
+ return b;
1866
1865
  }
1867
1866
  function Hr(e, t) {
1868
1867
  if (e.len === 0)
@@ -1897,10 +1896,10 @@ function _r(e, t, n) {
1897
1896
  }
1898
1897
  function c(h, u) {
1899
1898
  let E = !1;
1900
- for (let m = h; m < u; m++)
1901
- E = E || t.isWordLike[m];
1902
- const p = t.starts[h], S = u < t.len ? t.starts[u] : e.length;
1903
- s.push(e.slice(p, S)), i.push(E), r.push("text"), o.push(p);
1899
+ for (let N = h; N < u; N++)
1900
+ E = E || t.isWordLike[N];
1901
+ const p = t.starts[h], A = u < t.len ? t.starts[u] : e.length;
1902
+ s.push(e.slice(p, A)), i.push(E), r.push("text"), o.push(p);
1904
1903
  }
1905
1904
  function a(h) {
1906
1905
  if (!(x < 0)) {
@@ -2059,8 +2058,8 @@ function Zr(e, t, n, s, i) {
2059
2058
  if (a === null)
2060
2059
  c.push(p);
2061
2060
  else {
2062
- const S = a + u, m = Ae(S, n);
2063
- c.push(Ce(S, m, s) - h);
2061
+ const A = a + u, N = Ae(A, n);
2062
+ c.push(Ce(A, N, s) - h);
2064
2063
  }
2065
2064
  a = u, h = p;
2066
2065
  }
@@ -2182,124 +2181,124 @@ function di(e, t, n, s) {
2182
2181
  if (i.startSegmentIndex === i.endSegmentIndex)
2183
2182
  return t.segmentIndex = i.consumedEndSegmentIndex, t.graphemeIndex = 0, 0;
2184
2183
  const { widths: r, kinds: o, breakableFitAdvances: x, breakablePreferredBreaks: l, discretionaryHyphenWidth: d } = e, c = ot(), a = c.lineFitEpsilon, h = s + a, u = t.segmentIndex, E = t.graphemeIndex;
2185
- let p = 0, S = !1, m = t.segmentIndex, W = t.graphemeIndex, L = -1, w = 0, D = 0, A = null;
2186
- function C() {
2187
- return A === "soft-hyphen" && L === m && W === 0 ? D : p;
2184
+ let p = 0, A = !1, N = t.segmentIndex, R = t.graphemeIndex, D = -1, H = 0, b = 0, m = null;
2185
+ function y() {
2186
+ return m === "soft-hyphen" && D === N && R === 0 ? b : p;
2188
2187
  }
2189
- function _(B = m, P = W, U = C()) {
2190
- return S ? (t.segmentIndex = B, t.graphemeIndex = P, xi(e, U, u, E, B, P)) : null;
2188
+ function _(B = N, O = R, U = y()) {
2189
+ return A ? (t.segmentIndex = B, t.graphemeIndex = O, xi(e, U, u, E, B, O)) : null;
2191
2190
  }
2192
- function O(B, P) {
2193
- S = !0, m = B + 1, W = 0, p = P;
2191
+ function L(B, O) {
2192
+ A = !0, N = B + 1, R = 0, p = O;
2194
2193
  }
2195
- function ee(B, P, U) {
2196
- S = !0, m = B, W = P + 1, p = U;
2194
+ function J(B, O, U) {
2195
+ A = !0, N = B, R = O + 1, p = U;
2197
2196
  }
2198
- function v(B, P) {
2199
- if (!S) {
2200
- O(B, P);
2197
+ function I(B, O) {
2198
+ if (!A) {
2199
+ L(B, O);
2201
2200
  return;
2202
2201
  }
2203
- p += P, m = B + 1, W = 0;
2202
+ p += O, N = B + 1, R = 0;
2204
2203
  }
2205
- function H(B, P, U, I, Y, K) {
2206
- if (!P)
2204
+ function W(B, O, U, P, Q, q) {
2205
+ if (!O)
2207
2206
  return;
2208
- const q = tn(e, B, U, Y), T = nn(e, B, U, Y, I);
2209
- L = U + 1, w = p - K + q, D = p - K + T, A = B;
2207
+ const $ = tn(e, B, U, Q), T = nn(e, B, U, Q, P);
2208
+ D = U + 1, H = p - q + $, b = p - q + T, m = B;
2210
2209
  }
2211
- function y(B, P) {
2212
- const U = x[B], I = l[B] ?? null;
2213
- let Y = I === null ? -1 : Gn(I, 0, P + 1), K = -1, q = 0;
2214
- for (let T = P; T < U.length; T++) {
2210
+ function w(B, O) {
2211
+ const U = x[B], P = l[B] ?? null;
2212
+ let Q = P === null ? -1 : Gn(P, 0, O + 1), q = -1, $ = 0;
2213
+ for (let T = O; T < U.length; T++) {
2215
2214
  const pe = U[T];
2216
- if (!S)
2217
- ee(B, T, pe);
2215
+ if (!A)
2216
+ J(B, T, pe);
2218
2217
  else {
2219
2218
  const ge = ci(e, !0, pe), Fe = p + ge;
2220
2219
  if (li(e, Fe) > h)
2221
- return I !== null && K > P ? _(B, K, q) : _();
2222
- p = Fe, m = B, W = T + 1;
2220
+ return P !== null && q > O ? _(B, q, $) : _();
2221
+ p = Fe, N = B, R = T + 1;
2223
2222
  }
2224
2223
  const se = T + 1;
2225
- I !== null && I[Y] === se && (K = se, q = p, Y++);
2224
+ P !== null && P[Q] === se && (q = se, $ = p, Q++);
2226
2225
  }
2227
- return S && m === B && W === U.length && (m = B + 1, W = 0), null;
2226
+ return A && N === B && R === U.length && (N = B + 1, R = 0), null;
2228
2227
  }
2229
- function $() {
2230
- return A !== "soft-hyphen" || L < 0 ? null : w <= h ? _(L, 0, D) : null;
2228
+ function K() {
2229
+ return m !== "soft-hyphen" || D < 0 ? null : H <= h ? _(D, 0, b) : null;
2231
2230
  }
2232
2231
  for (let B = t.segmentIndex; B < i.endSegmentIndex; B++) {
2233
- const P = o[B], U = Tn(P), I = B === t.segmentIndex ? t.graphemeIndex : 0, Y = ri(e, S, B), K = P === "tab" ? si(p + Y, e.tabStopAdvance) : r[B], q = Y + K, T = oi(e, P, B, Y, K);
2234
- if (P === "soft-hyphen" && I === 0) {
2235
- S && (m = B + 1, W = 0, L = B + 1, w = p + d, D = p + d, A = P);
2232
+ const O = o[B], U = Tn(O), P = B === t.segmentIndex ? t.graphemeIndex : 0, Q = ri(e, A, B), q = O === "tab" ? si(p + Q, e.tabStopAdvance) : r[B], $ = Q + q, T = oi(e, O, B, Q, q);
2233
+ if (O === "soft-hyphen" && P === 0) {
2234
+ A && (N = B + 1, R = 0, D = B + 1, H = p + d, b = p + d, m = O);
2236
2235
  continue;
2237
2236
  }
2238
- if (!S) {
2239
- if (I > 0) {
2240
- const se = y(B, I);
2237
+ if (!A) {
2238
+ if (P > 0) {
2239
+ const se = w(B, P);
2241
2240
  if (se !== null)
2242
2241
  return se;
2243
2242
  } else if (T > h && x[B] !== null) {
2244
- const se = y(B, 0);
2243
+ const se = w(B, 0);
2245
2244
  if (se !== null)
2246
2245
  return se;
2247
2246
  } else
2248
- O(B, K);
2249
- H(P, U, B, K, Y, q);
2247
+ L(B, q);
2248
+ W(O, U, B, q, Q, $);
2250
2249
  continue;
2251
2250
  }
2252
2251
  if (p + T > h) {
2253
- const se = p + tn(e, P, B, Y), ge = p + nn(e, P, B, Y, K);
2254
- if (A === "soft-hyphen" && c.preferEarlySoftHyphenBreak && w <= h)
2255
- return _(L, 0, D);
2256
- const Fe = $();
2252
+ const se = p + tn(e, O, B, Q), ge = p + nn(e, O, B, Q, q);
2253
+ if (m === "soft-hyphen" && c.preferEarlySoftHyphenBreak && H <= h)
2254
+ return _(D, 0, b);
2255
+ const Fe = K();
2257
2256
  if (Fe !== null)
2258
2257
  return Fe;
2259
2258
  if (U && se <= h)
2260
- return v(B, q), _(B + 1, 0, ge);
2261
- if (L >= 0 && w <= h)
2262
- return m > L || m === L && W > 0 ? _() : _(L, 0, D);
2259
+ return I(B, $), _(B + 1, 0, ge);
2260
+ if (D >= 0 && H <= h)
2261
+ return N > D || N === D && R > 0 ? _() : _(D, 0, b);
2263
2262
  if (T > h && x[B] !== null) {
2264
2263
  const $e = _();
2265
2264
  if ($e !== null)
2266
2265
  return $e;
2267
- const Be = y(B, 0);
2266
+ const Be = w(B, 0);
2268
2267
  if (Be !== null)
2269
2268
  return Be;
2270
2269
  }
2271
2270
  return _();
2272
2271
  }
2273
- v(B, q), H(P, U, B, K, Y, q);
2272
+ I(B, $), W(O, U, B, q, Q, $);
2274
2273
  }
2275
- return L === i.consumedEndSegmentIndex && W === 0 ? _(i.consumedEndSegmentIndex, 0, D) : _(i.consumedEndSegmentIndex, 0, p);
2274
+ return D === i.consumedEndSegmentIndex && R === 0 ? _(i.consumedEndSegmentIndex, 0, b) : _(i.consumedEndSegmentIndex, 0, p);
2276
2275
  }
2277
2276
  function pi(e, t, n) {
2278
2277
  const { widths: s, kinds: i, breakableFitAdvances: r, breakablePreferredBreaks: o } = e, l = ot().lineFitEpsilon, d = n + l;
2279
2278
  let c = 0, a = !1, h = t.segmentIndex, u = t.graphemeIndex, E = -1, p = 0;
2280
- for (let S = t.segmentIndex; S < s.length; S++) {
2281
- const m = i[S], W = Tn(m), L = S === t.segmentIndex ? t.graphemeIndex : 0, w = r[S], D = s[S];
2279
+ for (let A = t.segmentIndex; A < s.length; A++) {
2280
+ const N = i[A], R = Tn(N), D = A === t.segmentIndex ? t.graphemeIndex : 0, H = r[A], b = s[A];
2282
2281
  if (!a) {
2283
- if (L > 0 || D > d && w !== null) {
2284
- const A = w, C = o[S] ?? null;
2285
- let _ = C === null ? -1 : Gn(C, 0, L + 1), O = -1, ee = 0;
2286
- const v = A[L];
2287
- a = !0, c = v, h = S, u = L + 1, C !== null && C[_] === u && (O = u, ee = c, _++);
2288
- for (let H = L + 1; H < A.length; H++) {
2289
- const y = A[H];
2290
- if (c + y > d)
2291
- return C !== null && O > L ? (t.segmentIndex = S, t.graphemeIndex = O, ee) : (t.segmentIndex = h, t.graphemeIndex = u, c);
2292
- c += y, h = S, u = H + 1, C !== null && C[_] === u && (O = u, ee = c, _++);
2282
+ if (D > 0 || b > d && H !== null) {
2283
+ const m = H, y = o[A] ?? null;
2284
+ let _ = y === null ? -1 : Gn(y, 0, D + 1), L = -1, J = 0;
2285
+ const I = m[D];
2286
+ a = !0, c = I, h = A, u = D + 1, y !== null && y[_] === u && (L = u, J = c, _++);
2287
+ for (let W = D + 1; W < m.length; W++) {
2288
+ const w = m[W];
2289
+ if (c + w > d)
2290
+ return y !== null && L > D ? (t.segmentIndex = A, t.graphemeIndex = L, J) : (t.segmentIndex = h, t.graphemeIndex = u, c);
2291
+ c += w, h = A, u = W + 1, y !== null && y[_] === u && (L = u, J = c, _++);
2293
2292
  }
2294
- h === S && u === A.length && (h = S + 1, u = 0);
2293
+ h === A && u === m.length && (h = A + 1, u = 0);
2295
2294
  } else
2296
- a = !0, c = D, h = S + 1, u = 0;
2297
- W && (E = S + 1, p = c - D);
2295
+ a = !0, c = b, h = A + 1, u = 0;
2296
+ R && (E = A + 1, p = c - b);
2298
2297
  continue;
2299
2298
  }
2300
- if (c + D > d)
2301
- return W ? (t.segmentIndex = S + 1, t.graphemeIndex = 0, c) : E >= 0 ? h > E || h === E && u > 0 ? (t.segmentIndex = h, t.graphemeIndex = u, c) : (t.segmentIndex = E, t.graphemeIndex = 0, p) : (t.segmentIndex = h, t.graphemeIndex = u, c);
2302
- c += D, h = S + 1, u = 0, W && (E = S + 1, p = c - D);
2299
+ if (c + b > d)
2300
+ return R ? (t.segmentIndex = A + 1, t.graphemeIndex = 0, c) : E >= 0 ? h > E || h === E && u > 0 ? (t.segmentIndex = h, t.graphemeIndex = u, c) : (t.segmentIndex = E, t.graphemeIndex = 0, p) : (t.segmentIndex = h, t.graphemeIndex = u, c);
2301
+ c += b, h = A + 1, u = 0, R && (E = A + 1, p = c - b);
2303
2302
  }
2304
2303
  return a ? (t.segmentIndex = h, t.graphemeIndex = u, c) : null;
2305
2304
  }
@@ -2469,78 +2468,78 @@ function Ci(e, t, n, s, i) {
2469
2468
  if (e.len === 0)
2470
2469
  return Ai();
2471
2470
  const h = [], u = [], E = [], p = [];
2472
- let S = e.chunks.length <= 1 && !a;
2473
- const m = n ? [] : null, W = [], L = [], w = [], D = n ? [] : null, A = Array.from({ length: e.len });
2474
- function C(v, H, y, $, B, P, U, I, Y) {
2475
- B !== "text" && B !== "space" && B !== "zero-width-break" && (S = !1), h.push(H), u.push(y), E.push($), p.push(B), m?.push(P), W.push(U), L.push(I), a && w.push(Y), D !== null && D.push(v);
2471
+ let A = e.chunks.length <= 1 && !a;
2472
+ const N = n ? [] : null, R = [], D = [], H = [], b = n ? [] : null, m = Array.from({ length: e.len });
2473
+ function y(I, W, w, K, B, O, U, P, Q) {
2474
+ B !== "text" && B !== "space" && B !== "zero-width-break" && (A = !1), h.push(W), u.push(w), E.push(K), p.push(B), N?.push(O), R.push(U), D.push(P), a && H.push(Q), b !== null && b.push(I);
2476
2475
  }
2477
- function _(v, H, y, $, B) {
2478
- const P = Ae(v, o), U = a ? cn(v, H) : 0, I = bi(Ce(v, P, x), U, i), Y = H === "space" || H === "preserved-space" || H === "zero-width-break" ? 0 : I, K = Y === 0 ? 0 : Y + (U > 0 ? i : 0), q = H === "space" || H === "zero-width-break" ? 0 : I;
2479
- if (B && $ && v.length > 1) {
2476
+ function _(I, W, w, K, B) {
2477
+ const O = Ae(I, o), U = a ? cn(I, W) : 0, P = bi(Ce(I, O, x), U, i), Q = W === "space" || W === "preserved-space" || W === "zero-width-break" ? 0 : P, q = Q === 0 ? 0 : Q + (U > 0 ? i : 0), $ = W === "space" || W === "zero-width-break" ? 0 : P;
2478
+ if (B && K && I.length > 1) {
2480
2479
  let T = "sum-graphemes";
2481
- i !== 0 ? T = "segment-prefixes" : et(v) ? T = "pair-context" : r.preferPrefixWidthsForBreakableRuns && (T = "segment-prefixes");
2482
- const pe = Zr(v, P, o, x, T), se = pe === null || s === "keep-all" ? null : Bi(v);
2483
- C(v, I, K, q, H, y, pe, se, U);
2480
+ i !== 0 ? T = "segment-prefixes" : et(I) ? T = "pair-context" : r.preferPrefixWidthsForBreakableRuns && (T = "segment-prefixes");
2481
+ const pe = Zr(I, O, o, x, T), se = pe === null || s === "keep-all" ? null : Bi(I);
2482
+ y(I, P, q, $, W, w, pe, se, U);
2484
2483
  return;
2485
2484
  }
2486
- C(v, I, K, q, H, y, null, null, U);
2485
+ y(I, P, q, $, W, w, null, null, U);
2487
2486
  }
2488
- for (let v = 0; v < e.len; v++) {
2489
- A[v] = h.length;
2490
- const H = e.texts[v], y = e.isWordLike[v], $ = e.kinds[v], B = e.starts[v];
2491
- if ($ === "soft-hyphen") {
2492
- C(H, 0, l, l, $, B, null, null, 0);
2487
+ for (let I = 0; I < e.len; I++) {
2488
+ m[I] = h.length;
2489
+ const W = e.texts[I], w = e.isWordLike[I], K = e.kinds[I], B = e.starts[I];
2490
+ if (K === "soft-hyphen") {
2491
+ y(W, 0, l, l, K, B, null, null, 0);
2493
2492
  continue;
2494
2493
  }
2495
- if ($ === "hard-break") {
2496
- C(H, 0, 0, 0, $, B, null, null, 0);
2494
+ if (K === "hard-break") {
2495
+ y(W, 0, 0, 0, K, B, null, null, 0);
2497
2496
  continue;
2498
2497
  }
2499
- if ($ === "tab") {
2500
- C(H, 0, 0, 0, $, B, null, null, a ? cn(H, $) : 0);
2498
+ if (K === "tab") {
2499
+ y(W, 0, 0, 0, K, B, null, null, a ? cn(W, K) : 0);
2501
2500
  continue;
2502
2501
  }
2503
- const P = Ae(H, o);
2504
- if ($ === "text" && P.containsCJK) {
2505
- const U = Ei(H, r), I = s === "keep-all" ? Mi(H, U, r.breakKeepAllAfterPunctuation) : U;
2506
- for (let Y = 0; Y < I.length; Y++) {
2507
- const K = I[Y];
2508
- _(K.text, "text", B + K.start, y, s === "keep-all" || !fe(K.text));
2502
+ const O = Ae(W, o);
2503
+ if (K === "text" && O.containsCJK) {
2504
+ const U = Ei(W, r), P = s === "keep-all" ? Mi(W, U, r.breakKeepAllAfterPunctuation) : U;
2505
+ for (let Q = 0; Q < P.length; Q++) {
2506
+ const q = P[Q];
2507
+ _(q.text, "text", B + q.start, w, s === "keep-all" || !fe(q.text));
2509
2508
  }
2510
2509
  continue;
2511
2510
  }
2512
- _(H, $, B, y, !0);
2511
+ _(W, K, B, w, !0);
2513
2512
  }
2514
- const O = yi(e.chunks, A, h.length), ee = m === null ? null : Pn(e.normalized, m);
2515
- return D !== null ? {
2513
+ const L = yi(e.chunks, m, h.length), J = N === null ? null : Pn(e.normalized, N);
2514
+ return b !== null ? {
2516
2515
  widths: h,
2517
2516
  lineEndFitAdvances: u,
2518
2517
  lineEndPaintAdvances: E,
2519
2518
  kinds: p,
2520
- simpleLineWalkFastPath: S,
2521
- segLevels: ee,
2522
- breakableFitAdvances: W,
2523
- breakablePreferredBreaks: L,
2519
+ simpleLineWalkFastPath: A,
2520
+ segLevels: J,
2521
+ breakableFitAdvances: R,
2522
+ breakablePreferredBreaks: D,
2524
2523
  letterSpacing: i,
2525
- spacingGraphemeCounts: w,
2524
+ spacingGraphemeCounts: H,
2526
2525
  discretionaryHyphenWidth: l,
2527
2526
  tabStopAdvance: c,
2528
- chunks: O,
2529
- segments: D
2527
+ chunks: L,
2528
+ segments: b
2530
2529
  } : {
2531
2530
  widths: h,
2532
2531
  lineEndFitAdvances: u,
2533
2532
  lineEndPaintAdvances: E,
2534
2533
  kinds: p,
2535
- simpleLineWalkFastPath: S,
2536
- segLevels: ee,
2537
- breakableFitAdvances: W,
2538
- breakablePreferredBreaks: L,
2534
+ simpleLineWalkFastPath: A,
2535
+ segLevels: J,
2536
+ breakableFitAdvances: R,
2537
+ breakablePreferredBreaks: D,
2539
2538
  letterSpacing: i,
2540
- spacingGraphemeCounts: w,
2539
+ spacingGraphemeCounts: H,
2541
2540
  discretionaryHyphenWidth: l,
2542
2541
  tabStopAdvance: c,
2543
- chunks: O
2542
+ chunks: L
2544
2543
  };
2545
2544
  }
2546
2545
  function yi(e, t, n) {
@@ -2630,25 +2629,25 @@ function vi(e, t, n, s) {
2630
2629
  x++, n.segmentIndex = 0, n.graphemeIndex = 0;
2631
2630
  continue;
2632
2631
  }
2633
- const m = l.naturalWidth + l.extraWidth, W = d + m;
2634
- if (r > 0 && W > o)
2632
+ const N = l.naturalWidth + l.extraWidth, R = d + N;
2633
+ if (r > 0 && R > o)
2635
2634
  break e;
2636
- s?.(l, d, m, pt(ln), {
2635
+ s?.(l, d, N, pt(ln), {
2637
2636
  segmentIndex: l.endSegmentIndex,
2638
2637
  graphemeIndex: l.endGraphemeIndex
2639
- }), r += W, o = Math.max(0, i - r), x++, n.segmentIndex = 0, n.graphemeIndex = 0;
2638
+ }), r += R, o = Math.max(0, i - r), x++, n.segmentIndex = 0, n.graphemeIndex = 0;
2640
2639
  continue;
2641
2640
  }
2642
2641
  const a = d + l.extraWidth;
2643
2642
  if (r > 0 && a >= o)
2644
2643
  break e;
2645
2644
  if (c) {
2646
- const m = a + l.naturalWidth;
2647
- if (m <= o) {
2645
+ const N = a + l.naturalWidth;
2646
+ if (N <= o) {
2648
2647
  s?.(l, d, l.naturalWidth + l.extraWidth, pt(ln), {
2649
2648
  segmentIndex: l.endSegmentIndex,
2650
2649
  graphemeIndex: l.endGraphemeIndex
2651
- }), r += m, o = Math.max(0, i - r), x++, n.segmentIndex = 0, n.graphemeIndex = 0;
2650
+ }), r += N, o = Math.max(0, i - r), x++, n.segmentIndex = 0, n.graphemeIndex = 0;
2652
2651
  continue;
2653
2652
  }
2654
2653
  }
@@ -2664,18 +2663,18 @@ function vi(e, t, n, s) {
2664
2663
  x++, n.segmentIndex = 0, n.graphemeIndex = 0;
2665
2664
  continue;
2666
2665
  }
2667
- const p = E + l.extraWidth, S = d + p;
2668
- if (r > 0 && c && S > o)
2666
+ const p = E + l.extraWidth, A = d + p;
2667
+ if (r > 0 && c && A > o)
2669
2668
  break e;
2670
2669
  if (r > 0 && c && d > 0 && Pi(u.segmentIndex, u.graphemeIndex)) {
2671
- const m = { segmentIndex: 0, graphemeIndex: 0 };
2672
- if (St(l.prepared, m, Math.max(1, i - l.extraWidth)) !== null && (m.segmentIndex > u.segmentIndex || m.segmentIndex === u.segmentIndex && m.graphemeIndex > u.graphemeIndex))
2670
+ const N = { segmentIndex: 0, graphemeIndex: 0 };
2671
+ if (St(l.prepared, N, Math.max(1, i - l.extraWidth)) !== null && (N.segmentIndex > u.segmentIndex || N.segmentIndex === u.segmentIndex && N.graphemeIndex > u.graphemeIndex))
2673
2672
  break e;
2674
2673
  }
2675
2674
  if (s?.(l, d, p, pt(n), {
2676
2675
  segmentIndex: u.segmentIndex,
2677
2676
  graphemeIndex: u.graphemeIndex
2678
- }), r += S, o = Math.max(0, i - r), u.segmentIndex === l.endSegmentIndex && u.graphemeIndex === l.endGraphemeIndex) {
2677
+ }), r += A, o = Math.max(0, i - r), u.segmentIndex === l.endSegmentIndex && u.graphemeIndex === l.endGraphemeIndex) {
2679
2678
  x++, n.segmentIndex = 0, n.graphemeIndex = 0;
2680
2679
  continue;
2681
2680
  }
@@ -3002,8 +3001,8 @@ function c0(e, t, n) {
3002
3001
  rules: []
3003
3002
  }, a = De(i, d.width), h = De(Hn(i.width, r, i.ascent + o), d.width), E = { ...Re([c, a, h], "left"), width: d.width + i.width };
3004
3003
  if (!t) return E;
3005
- const p = ne(t, ze(ze(n))), S = s.radicalDegreeRaise * l, m = Me(p, 0, -S), W = De(E, p.width);
3006
- return { ...Re([m, W], "left"), width: p.width + E.width };
3004
+ const p = ne(t, ze(ze(n))), A = s.radicalDegreeRaise * l, N = Me(p, 0, -A), R = De(E, p.width);
3005
+ return { ...Re([N, R], "left"), width: p.width + E.width };
3007
3006
  }
3008
3007
  function l0(e, t, n, s) {
3009
3008
  const i = s.font.constants(s.style.sizePx), r = ne(n, s), o = [];
@@ -3034,26 +3033,26 @@ function x0(e, t) {
3034
3033
  function f0(e, t) {
3035
3034
  const n = t.font.constants(t.style.sizePx), s = 2 * n.thickSpace, i = n.thinSpace * 3;
3036
3035
  if (e.length === 0) return tt();
3037
- const r = e.map((p) => p.map((S) => ne(S, t))), o = Math.max(...r.map((p) => p.length));
3036
+ const r = e.map((p) => p.map((A) => ne(A, t))), o = Math.max(...r.map((p) => p.length));
3038
3037
  if (o === 0) return tt();
3039
3038
  const x = [];
3040
- for (let p = 0; p < o; p++) x[p] = Math.max(0, ...r.map((S) => S[p] ? S[p].width : 0));
3039
+ for (let p = 0; p < o; p++) x[p] = Math.max(0, ...r.map((A) => A[p] ? A[p].width : 0));
3041
3040
  const l = r.map((p) => ({
3042
- ascent: Math.max(0, ...p.map((S) => S.ascent)),
3043
- descent: Math.max(0, ...p.map((S) => S.descent))
3044
- })), d = l.reduce((p, S) => p + S.ascent + S.descent, 0) + i * (e.length - 1), c = n.axisHeight;
3041
+ ascent: Math.max(0, ...p.map((A) => A.ascent)),
3042
+ descent: Math.max(0, ...p.map((A) => A.descent))
3043
+ })), d = l.reduce((p, A) => p + A.ascent + A.descent, 0) + i * (e.length - 1), c = n.axisHeight;
3045
3044
  let a = -(d / 2) - c;
3046
3045
  const h = [];
3047
3046
  for (let p = 0; p < r.length; p++) {
3048
- const S = l[p], m = a + S.ascent;
3049
- let W = 0;
3050
- for (let L = 0; L < o; L++) {
3051
- const w = r[p][L];
3052
- w && h.push(Me(De(ve(w, x[L]), W), 0, m)), W += x[L] + s;
3047
+ const A = l[p], N = a + A.ascent;
3048
+ let R = 0;
3049
+ for (let D = 0; D < o; D++) {
3050
+ const H = r[p][D];
3051
+ H && h.push(Me(De(ve(H, x[D]), R), 0, N)), R += x[D] + s;
3053
3052
  }
3054
- a += S.ascent + S.descent + i;
3053
+ a += A.ascent + A.descent + i;
3055
3054
  }
3056
- const u = x.reduce((p, S) => p + S, 0) + s * (o - 1);
3055
+ const u = x.reduce((p, A) => p + A, 0) + s * (o - 1);
3057
3056
  return { ...Re(h, "left"), width: u };
3058
3057
  }
3059
3058
  const u0 = {
@@ -3387,61 +3386,75 @@ const W0 = (e) => e.reduce((t, n) => t + n.height, 0);
3387
3386
  function T0(e, t) {
3388
3387
  const n = t?.cjkFallback ?? null, s = t?.cjkLocale, i = t?.arabicFallback ?? null, r = t?.hebrewFallback ?? null, o = new At(), x = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
3389
3388
  let d = null;
3390
- const c = (w, D) => {
3391
- d?.add(w.id);
3392
- const A = x.get(w.id);
3393
- if (A && A.revision === w.revision && A.width === D) return A.lines;
3394
- const C = ls(w, D, o);
3395
- return x.set(w.id, { revision: w.revision, width: D, lines: C }), C;
3396
- }, a = (w, D, A, C) => {
3397
- d?.add(w.id);
3398
- const _ = l.get(w.id);
3399
- if (_ && _.revision === w.revision && _.width === D) return _.measured;
3400
- const O = Te(w, D, A, C);
3401
- return l.set(w.id, { revision: w.revision, width: D, measured: O }), O;
3389
+ const c = (b, m) => {
3390
+ d?.add(b.id);
3391
+ const y = x.get(b.id);
3392
+ if (y && y.revision === b.revision && y.width === m) return y.lines;
3393
+ const _ = ls(b, m, o);
3394
+ return x.set(b.id, { revision: b.revision, width: m, lines: _ }), _;
3395
+ }, a = (b, m, y, _) => {
3396
+ d?.add(b.id);
3397
+ const L = l.get(b.id);
3398
+ if (L && L.revision === b.revision && L.width === m) return L.measured;
3399
+ const J = Te(b, m, y, _);
3400
+ return l.set(b.id, { revision: b.revision, width: m, measured: J }), J;
3402
3401
  }, h = /* @__PURE__ */ new WeakMap();
3403
3402
  let u = 0;
3404
- const E = (w) => {
3405
- let D = h.get(w);
3406
- return D === void 0 && (D = ++u, h.set(w, D)), D;
3407
- }, p = /* @__PURE__ */ new WeakMap(), S = (w) => {
3408
- let D = p.get(w);
3409
- return D === void 0 && (D = Q0(w).some((A) => /\{(date|time)\}/.test(A)), p.set(w, D)), D;
3410
- }, m = /* @__PURE__ */ new Map();
3411
- let W = null;
3412
- const L = (w, D, A, C, _, O, ee) => {
3413
- if (S(w)) return je(w, D, A, C, _, O, ee);
3414
- const v = `${E(w)}|${D}|${A}|${C}|${_}|${ee ? 1 : 0}`;
3415
- W?.add(v);
3416
- const H = m.get(v);
3417
- if (H) return H;
3418
- const y = je(w, D, A, C, _, O, ee);
3419
- return m.set(v, y), y;
3403
+ const E = (b) => {
3404
+ let m = h.get(b);
3405
+ return m === void 0 && (m = ++u, h.set(b, m)), m;
3406
+ }, p = /* @__PURE__ */ new WeakMap(), A = (b) => {
3407
+ let m = p.get(b);
3408
+ return m === void 0 && (m = Q0(b).some((y) => /\{(date|time)\}/.test(y)), p.set(b, m)), m;
3409
+ }, N = /* @__PURE__ */ new Map();
3410
+ let R = null;
3411
+ const D = (b, m, y, _, L, J, I) => {
3412
+ if (A(b)) return je(b, m, y, _, L, J, I);
3413
+ const W = `${E(b)}|${m}|${y}|${_}|${L}|${I ? 1 : 0}`;
3414
+ R?.add(W);
3415
+ const w = N.get(W);
3416
+ if (w) return w;
3417
+ const K = je(b, m, y, _, L, J, I);
3418
+ return N.set(W, K), K;
3419
+ }, H = (b) => {
3420
+ const m = l.get(b);
3421
+ if (m?.measured)
3422
+ for (const y of m.measured.rows)
3423
+ for (const _ of y.cells)
3424
+ for (const L of _.items)
3425
+ L.kind === "para" ? (o.evict(L.block.id), x.delete(L.block.id)) : L.kind === "table" && H(L.block.id);
3426
+ o.evict(b), x.delete(b), l.delete(b);
3420
3427
  };
3421
3428
  return {
3422
- layout(w, D, A) {
3423
- e && Ts(e), m0(n), N0(i), S0(r), A0(s), es = w.defaultTabStopPx && w.defaultTabStopPx > 0 ? w.defaultTabStopPx : Zn;
3424
- const C = A?.rawBand ?? null;
3425
- d = C === null ? /* @__PURE__ */ new Set() : null, W = C === null ? /* @__PURE__ */ new Set() : null;
3429
+ layout(b, m, y) {
3430
+ if (m && m.length > 0)
3431
+ for (const L of m)
3432
+ H(L);
3433
+ e && Ts(e), m0(n), N0(i), S0(r), A0(s), es = b.defaultTabStopPx && b.defaultTabStopPx > 0 ? b.defaultTabStopPx : Zn;
3434
+ const _ = y?.rawBand ?? null;
3435
+ d = _ === null ? /* @__PURE__ */ new Set() : null, R = _ === null ? /* @__PURE__ */ new Set() : null;
3426
3436
  try {
3427
- const _ = J0(w, c, (O) => (d?.add(O.id), o.get(O)), C, a, L);
3437
+ const L = J0(b, c, (J) => (d?.add(J.id), o.get(J)), _, a, D);
3428
3438
  if (d) {
3429
- for (const O of x.keys()) d.has(O) || x.delete(O);
3430
- for (const O of l.keys()) d.has(O) || l.delete(O);
3439
+ for (const J of x.keys()) d.has(J) || x.delete(J);
3440
+ for (const J of l.keys()) d.has(J) || l.delete(J);
3431
3441
  o.retainOnly(d);
3432
3442
  }
3433
- if (W)
3434
- for (const O of m.keys()) W.has(O) || m.delete(O);
3435
- return _;
3443
+ if (R)
3444
+ for (const J of N.keys()) R.has(J) || N.delete(J);
3445
+ return L;
3436
3446
  } finally {
3437
- d = null, W = null;
3447
+ d = null, R = null;
3438
3448
  }
3439
3449
  },
3440
- evict(w) {
3441
- o.evict(w), x.delete(w), l.delete(w);
3450
+ evict(b) {
3451
+ H(b);
3452
+ },
3453
+ invalidate(b) {
3454
+ H(b);
3442
3455
  },
3443
3456
  reset() {
3444
- o.clear(), x.clear(), l.clear(), m.clear();
3457
+ o.clear(), x.clear(), l.clear(), N.clear();
3445
3458
  }
3446
3459
  };
3447
3460
  }
@@ -3495,21 +3508,21 @@ function vt(e, t, n, s, i, r) {
3495
3508
  let d = 0, c = 0, a = 0, h = 0;
3496
3509
  for (const p of x.fragments) {
3497
3510
  d += p.gapBefore;
3498
- const S = t.runs[p.itemIndex];
3499
- if (S.style.equation) {
3500
- const L = Ot(S.style.equation, nt, S.style.fontSizePx);
3501
- c = Math.max(c, L.ascent), a = Math.max(a, L.descent), h = Math.max(h, S.style.fontSizePx);
3502
- const w = En(S.text, r[p.itemIndex], p.text);
3503
- r[p.itemIndex] = w.end, l.push({
3511
+ const A = t.runs[p.itemIndex];
3512
+ if (A.style.equation) {
3513
+ const D = Ot(A.style.equation, nt, A.style.fontSizePx);
3514
+ c = Math.max(c, D.ascent), a = Math.max(a, D.descent), h = Math.max(h, A.style.fontSizePx);
3515
+ const H = En(A.text, r[p.itemIndex], p.text);
3516
+ r[p.itemIndex] = H.end, l.push({
3504
3517
  frag: {
3505
3518
  blockId: e.id,
3506
- startOffset: i[p.itemIndex] + w.start,
3507
- endOffset: i[p.itemIndex] + w.end,
3519
+ startOffset: i[p.itemIndex] + H.start,
3520
+ endOffset: i[p.itemIndex] + H.end,
3508
3521
  text: p.text,
3509
- style: S.style,
3522
+ style: A.style,
3510
3523
  x: d,
3511
3524
  width: p.occupiedWidth,
3512
- equation: L
3525
+ equation: D
3513
3526
  },
3514
3527
  hadGap: p.gapBefore > 0,
3515
3528
  gap: p.gapBefore,
@@ -3517,30 +3530,30 @@ function vt(e, t, n, s, i, r) {
3517
3530
  }), d += p.occupiedWidth;
3518
3531
  continue;
3519
3532
  }
3520
- const m = Ue(le(S.style));
3521
- c = Math.max(c, m.ascent), a = Math.max(a, m.descent), h = Math.max(h, S.style.fontSizePx);
3522
- const W = p.occupiedWidth * Ws(S.style);
3533
+ const N = Ue(le(A.style));
3534
+ c = Math.max(c, N.ascent), a = Math.max(a, N.descent), h = Math.max(h, A.style.fontSizePx);
3535
+ const R = p.occupiedWidth * Ws(A.style);
3523
3536
  if (p.text.length > 0) {
3524
- const L = En(S.text, r[p.itemIndex], p.text);
3525
- r[p.itemIndex] = L.end;
3526
- const w = {
3537
+ const D = En(A.text, r[p.itemIndex], p.text);
3538
+ r[p.itemIndex] = D.end;
3539
+ const H = {
3527
3540
  blockId: e.id,
3528
- startOffset: i[p.itemIndex] + L.start,
3529
- endOffset: i[p.itemIndex] + L.end,
3541
+ startOffset: i[p.itemIndex] + D.start,
3542
+ endOffset: i[p.itemIndex] + D.end,
3530
3543
  text: p.text,
3531
- style: S.style,
3544
+ style: A.style,
3532
3545
  x: d,
3533
- width: W
3546
+ width: R
3534
3547
  };
3535
- L.map && (w.offsetMap = L.map), l.push({ frag: w, hadGap: p.gapBefore > 0, gap: p.gapBefore, spaces: ts(p.text) });
3548
+ D.map && (H.offsetMap = D.map), l.push({ frag: H, hadGap: p.gapBefore > 0, gap: p.gapBefore, spaces: ts(p.text) });
3536
3549
  }
3537
- d += W;
3550
+ d += R;
3538
3551
  }
3539
3552
  if (h === 0) {
3540
3553
  const p = e.runs[0]?.style;
3541
3554
  if (p) {
3542
- const S = Ue(le(p));
3543
- c = S.ascent, a = S.descent, h = p.fontSizePx;
3555
+ const A = Ue(le(p));
3556
+ c = A.ascent, a = A.descent, h = p.fontSizePx;
3544
3557
  }
3545
3558
  }
3546
3559
  const u = c + a, E = It(e.style, h, u);
@@ -3571,24 +3584,24 @@ const ss = { fontFamily: "Georgia, serif", fontSizePx: 16 }, Mn = { fontFamily:
3571
3584
  function K0(e, t, n, s, i) {
3572
3585
  const r = [];
3573
3586
  let o = [], x = n, l = n;
3574
- for (const w of t) {
3575
- let D = 0;
3587
+ for (const H of t) {
3588
+ let b = 0;
3576
3589
  for (; ; ) {
3577
- const C = w.text.indexOf(" ", D);
3578
- if (C < 0) break;
3579
- const _ = w.text.slice(D, C);
3580
- _.length > 0 && o.push({ text: _, style: w.style }), l += C - D, r.push({ runs: o, start: x }), l += 1, x = l, o = [], D = C + 1;
3590
+ const y = H.text.indexOf(" ", b);
3591
+ if (y < 0) break;
3592
+ const _ = H.text.slice(b, y);
3593
+ _.length > 0 && o.push({ text: _, style: H.style }), l += y - b, r.push({ runs: o, start: x }), l += 1, x = l, o = [], b = y + 1;
3581
3594
  }
3582
- const A = w.text.slice(D);
3583
- A.length > 0 && o.push({ text: A, style: w.style }), l += A.length;
3595
+ const m = H.text.slice(b);
3596
+ m.length > 0 && o.push({ text: m, style: H.style }), l += m.length;
3584
3597
  }
3585
3598
  r.push({ runs: o, start: x });
3586
- const d = (e.style.tabStops ?? []).slice().sort((w, D) => w.posPx - D.posPx), c = t.find((w) => w.text.length > 0)?.style ?? e.runs[0]?.style, a = [];
3587
- let h = [], u = [], E = [], p = i, S = 0, m = 0, W = !1;
3588
- const L = (w) => {
3589
- if (S === 0 && c) {
3590
- const D = Ue(le(c));
3591
- S = It(e.style, c.fontSizePx, D.ascent + D.descent), m = (S - (D.ascent + D.descent)) / 2 + D.ascent;
3599
+ const d = (e.style.tabStops ?? []).slice().sort((H, b) => H.posPx - b.posPx), c = t.find((H) => H.text.length > 0)?.style ?? e.runs[0]?.style, a = [];
3600
+ let h = [], u = [], E = [], p = i, A = 0, N = 0, R = !1;
3601
+ const D = (H) => {
3602
+ if (A === 0 && c) {
3603
+ const b = Ue(le(c));
3604
+ A = It(e.style, c.fontSizePx, b.ascent + b.descent), N = (A - (b.ascent + b.descent)) / 2 + b.ascent;
3592
3605
  }
3593
3606
  a.push({
3594
3607
  frags: h,
@@ -3596,35 +3609,35 @@ function K0(e, t, n, s, i) {
3596
3609
  indent: 0,
3597
3610
  // fragment x is already absolute (tab/indent baked in)
3598
3611
  lineMaxWidth: s,
3599
- height: S,
3600
- ascent: m,
3612
+ height: A,
3613
+ ascent: N,
3601
3614
  // A tab-positioned line stays ragged (its manual x must not be re-justified);
3602
3615
  // pure wrapped continuation lines justify normally when the paragraph does.
3603
- lastOfSegment: w || W,
3604
- ...W ? { tabbed: !0 } : {},
3616
+ lastOfSegment: H || R,
3617
+ ...R ? { tabbed: !0 } : {},
3605
3618
  ...u.length > 0 ? { leaders: u } : {},
3606
3619
  ...E.length > 0 ? { tabArrows: E } : {}
3607
- }), h = [], u = [], E = [], p = 0, S = 0, m = 0, W = !1;
3620
+ }), h = [], u = [], E = [], p = 0, A = 0, N = 0, R = !1;
3608
3621
  };
3609
- return r.forEach((w, D) => {
3610
- if (D > 0) {
3611
- const H = j0(p, d, s), y = H.align ?? "left", $ = he(w.runs.map((U) => U.text).join(""), le(w.runs[0]?.style ?? c ?? ss)), B = p + $ <= s;
3612
- let P = H.posPx;
3613
- B && y === "right" ? P = H.posPx - $ : B && y === "center" ? P = H.posPx - $ / 2 : B && y === "decimal" && (P = H.posPx - U0(w.runs)), P < p && (P = p), (H.leader ?? "none") !== "none" && P > p + 1 && c && u.push({ x1: p, x2: P, kind: H.leader ?? "none", color: c.color, fontSizePx: c.fontSizePx }), E.push({ x1: p, x2: Math.max(P, p) }), p = P, W = !0;
3622
+ return r.forEach((H, b) => {
3623
+ if (b > 0) {
3624
+ const W = j0(p, d, s), w = W.align ?? "left", K = he(H.runs.map((U) => U.text).join(""), le(H.runs[0]?.style ?? c ?? ss)), B = p + K <= s;
3625
+ let O = W.posPx;
3626
+ B && w === "right" ? O = W.posPx - K : B && w === "center" ? O = W.posPx - K / 2 : B && w === "decimal" && (O = W.posPx - U0(H.runs)), O < p && (O = p), (W.leader ?? "none") !== "none" && O > p + 1 && c && u.push({ x1: p, x2: O, kind: W.leader ?? "none", color: c.color, fontSizePx: c.fontSizePx }), E.push({ x1: p, x2: Math.max(O, p) }), p = O, R = !0;
3614
3627
  }
3615
- if (w.runs.length === 0) return;
3616
- const A = Qn(w.runs), C = { prepared: A.prepared, runs: A.runs, startOffset: w.start }, _ = Pt(A.runs, w.start), O = A.runs.map(() => 0);
3617
- let ee, v = !0;
3628
+ if (H.runs.length === 0) return;
3629
+ const m = Qn(H.runs), y = { prepared: m.prepared, runs: m.runs, startOffset: H.start }, _ = Pt(m.runs, H.start), L = m.runs.map(() => 0);
3630
+ let J, I = !0;
3618
3631
  for (; ; ) {
3619
- const H = Math.max(24, s - (v ? p : 0)), y = vt(e, C, H, ee, _, O);
3620
- if (y === null) break;
3621
- v || L(!1);
3622
- const $ = v ? p : 0;
3623
- for (const B of y.frags)
3624
- B.frag.x += $, h.push(B);
3625
- p = $ + y.width, S = Math.max(S, y.height), m = Math.max(m, y.ascent), ee = y.end, v = !1;
3632
+ const W = Math.max(24, s - (I ? p : 0)), w = vt(e, y, W, J, _, L);
3633
+ if (w === null) break;
3634
+ I || D(!1);
3635
+ const K = I ? p : 0;
3636
+ for (const B of w.frags)
3637
+ B.frag.x += K, h.push(B);
3638
+ p = K + w.width, A = Math.max(A, w.height), N = Math.max(N, w.ascent), J = w.end, I = !1;
3626
3639
  }
3627
- }), L(!0), a;
3640
+ }), D(!0), a;
3628
3641
  }
3629
3642
  function rs(e, t) {
3630
3643
  if (t <= 0) return;
@@ -3708,36 +3721,36 @@ function ls(e, t, n) {
3708
3721
  const d = [];
3709
3722
  for (let u = 0; u < s.length; u++) {
3710
3723
  const E = s[u];
3711
- if (E.runs.some((L) => L.text.includes(" "))) {
3724
+ if (E.runs.some((D) => D.text.includes(" "))) {
3712
3725
  x.push(...K0(e, E.runs, E.startOffset, t, l ? e.style.indentFirstLinePx : 0)), l = !1, d[u] = x.length - 1;
3713
3726
  continue;
3714
3727
  }
3715
- const p = Pt(E.runs, E.startOffset), S = E.runs.map(() => 0);
3716
- let m, W = !1;
3728
+ const p = Pt(E.runs, E.startOffset), A = E.runs.map(() => 0);
3729
+ let N, R = !1;
3717
3730
  for (; ; ) {
3718
- const L = l ? e.style.indentFirstLinePx : 0, w = t - L, D = vt(e, E, w, m, p, S);
3719
- if (D === null) break;
3731
+ const D = l ? e.style.indentFirstLinePx : 0, H = t - D, b = vt(e, E, H, N, p, A);
3732
+ if (b === null) break;
3720
3733
  x.push({
3721
- frags: D.frags,
3722
- width: D.width,
3723
- indent: L,
3724
- lineMaxWidth: w,
3725
- height: D.height,
3726
- ascent: D.ascent,
3734
+ frags: b.frags,
3735
+ width: b.width,
3736
+ indent: D,
3737
+ lineMaxWidth: H,
3738
+ height: b.height,
3739
+ ascent: b.ascent,
3727
3740
  lastOfSegment: !1
3728
- }), m = D.end, l = !1, W = !0;
3741
+ }), N = b.end, l = !1, R = !0;
3729
3742
  }
3730
- if (W)
3743
+ if (R)
3731
3744
  x[x.length - 1].lastOfSegment = !0;
3732
3745
  else {
3733
- const L = ns(e);
3746
+ const D = ns(e);
3734
3747
  x.push({
3735
3748
  frags: [],
3736
3749
  width: 0,
3737
3750
  indent: 0,
3738
3751
  lineMaxWidth: t,
3739
- height: L.height,
3740
- ascent: L.ascent,
3752
+ height: D.height,
3753
+ ascent: D.ascent,
3741
3754
  lastOfSegment: !0,
3742
3755
  emptyOffset: E.startOffset
3743
3756
  }), l = !1;
@@ -3752,18 +3765,18 @@ function ls(e, t, n) {
3752
3765
  let h = 0;
3753
3766
  for (const u of x) {
3754
3767
  if (u.tabbed) {
3755
- const m = u.frags.length > 0 || (u.leaders?.length ?? 0) > 0 || (u.tabArrows?.length ?? 0) > 0;
3756
- a && m && q0(u, r, t);
3768
+ const N = u.frags.length > 0 || (u.leaders?.length ?? 0) > 0 || (u.tabArrows?.length ?? 0) > 0;
3769
+ a && N && q0(u, r, t);
3757
3770
  } else if (r !== null && u.frags.length > 0) {
3758
- const m = cs(u.frags, r);
3759
- u.frags = m.frags, u.width = m.width;
3771
+ const N = cs(u.frags, r);
3772
+ u.frags = N.frags, u.width = N.width;
3760
3773
  }
3761
3774
  const E = u.lineMaxWidth - u.width;
3762
3775
  let p = u.indent;
3763
3776
  c === "center" ? p += E / 2 : c === "right" ? p += E : c === "justify" && !u.lastOfSegment && rs(u.frags, E);
3764
- for (const m of u.frags) m.frag.x += p;
3765
- const S = { y: h, height: u.height, ascent: u.ascent, fragments: u.frags.map((m) => m.frag) };
3766
- u.emptyOffset !== void 0 && (S.emptyOffset = u.emptyOffset), u.leaders && u.leaders.length > 0 && (S.leaders = u.leaders.map((m) => ({ ...m, x1: m.x1 + p, x2: m.x2 + p }))), u.tabArrows && u.tabArrows.length > 0 && (S.tabArrows = u.tabArrows.map((m) => ({ x1: m.x1 + p, x2: m.x2 + p }))), u.paragraphEnd && (S.paragraphEnd = !0), u.lineBreak && (S.lineBreak = !0), i.push(S), h += u.height;
3777
+ for (const N of u.frags) N.frag.x += p;
3778
+ const A = { y: h, height: u.height, ascent: u.ascent, fragments: u.frags.map((N) => N.frag) };
3779
+ u.emptyOffset !== void 0 && (A.emptyOffset = u.emptyOffset), u.leaders && u.leaders.length > 0 && (A.leaders = u.leaders.map((N) => ({ ...N, x1: N.x1 + p, x2: N.x2 + p }))), u.tabArrows && u.tabArrows.length > 0 && (A.tabArrows = u.tabArrows.map((N) => ({ x1: N.x1 + p, x2: N.x2 + p }))), u.paragraphEnd && (A.paragraphEnd = !0), u.lineBreak && (A.lineBreak = !0), i.push(A), h += u.height;
3767
3780
  }
3768
3781
  return i;
3769
3782
  }
@@ -3814,103 +3827,103 @@ function J0(e, t, n, s, i = Te, r = je) {
3814
3827
  const g = x.get(f);
3815
3828
  if (g) return g;
3816
3829
  let F = f.marginPx.top, k = f.pageHeightPx - f.marginPx.bottom;
3817
- const M = [f.header, f.headerFirst, f.headerEven].filter((G) => !!G), N = [f.footer, f.footerFirst, f.footerEven].filter((G) => !!G);
3818
- if (M.length > 0 || N.length > 0) {
3830
+ const M = [f.header, f.headerFirst, f.headerEven].filter((G) => !!G), S = [f.footer, f.footerFirst, f.footerEven].filter((G) => !!G);
3831
+ if (M.length > 0 || S.length > 0) {
3819
3832
  l ??= new At();
3820
- const G = f.pageWidthPx - f.marginPx.left - f.marginPx.right, j = f.marginPx.left, R = (V) => je(V, G, j, 999, 999, l, !1).height, Z = (V) => {
3821
- const Q = je(V, G, j, 999, 999, l, !1);
3822
- for (const te of Q.placed)
3823
- if (!!te.table || !!te.image || !!te.equation || te.lines.some((oe) => oe.fragments.some((X) => X.text.trim().length > 0 || !!X.equation))) return Q.height - te.y;
3833
+ const G = f.pageWidthPx - f.marginPx.left - f.marginPx.right, j = f.marginPx.left, v = (X) => je(X, G, j, 999, 999, l, !1).height, ee = (X) => {
3834
+ const V = je(X, G, j, 999, 999, l, !1);
3835
+ for (const te of V.placed)
3836
+ if (!!te.table || !!te.image || !!te.equation || te.lines.some((oe) => oe.fragments.some((Z) => Z.text.trim().length > 0 || !!Z.equation))) return V.height - te.y;
3824
3837
  return 0;
3825
- }, J = M.reduce((V, Q) => Math.max(V, R(Q)), 0);
3826
- if (J > 0) {
3827
- const V = bn(f, J);
3828
- F = Math.max(F, V + J + 6);
3838
+ }, Y = M.reduce((X, V) => Math.max(X, v(V)), 0);
3839
+ if (Y > 0) {
3840
+ const X = bn(f, Y);
3841
+ F = Math.max(F, X + Y + 6);
3829
3842
  }
3830
- const z = N.reduce((V, Q) => Math.max(V, R(Q)), 0);
3843
+ const z = S.reduce((X, V) => Math.max(X, v(V)), 0);
3831
3844
  if (z > 0)
3832
3845
  if (f.footerDistancePx !== void 0) {
3833
- const V = f.pageHeightPx - f.footerDistancePx, Q = N.reduce((te, ie) => Math.max(te, Z(ie)), 0);
3834
- k = Math.min(k, V - Q);
3846
+ const X = f.pageHeightPx - f.footerDistancePx, V = S.reduce((te, ie) => Math.max(te, ee(ie)), 0);
3847
+ k = Math.min(k, X - V);
3835
3848
  } else
3836
3849
  k = Math.min(k, Cn(f, z) - 6);
3837
3850
  k = Math.max(k, F + 24);
3838
3851
  }
3839
- const b = { top: F, bottom: k };
3840
- return x.set(f, b), b;
3852
+ const C = { top: F, bottom: k };
3853
+ return x.set(f, C), C;
3841
3854
  }, c = fs(e);
3842
- let a = c[0].props, h = 0, u = 0, E = 0, p = 0, S = 1, m = 0, W = [], L = [];
3843
- const w = (f) => {
3855
+ let a = c[0].props, h = 0, u = 0, E = 0, p = 0, A = 1, N = 0, R = [], D = [];
3856
+ const H = (f) => {
3844
3857
  a = f;
3845
3858
  const g = d(a);
3846
- h = a.marginPx.left, u = g.top, E = g.bottom, p = a.pageWidthPx - a.marginPx.left - a.marginPx.right, S = Math.max(1, a.columns?.count ?? 1);
3859
+ h = a.marginPx.left, u = g.top, E = g.bottom, p = a.pageWidthPx - a.marginPx.left - a.marginPx.right, A = Math.max(1, a.columns?.count ?? 1);
3847
3860
  const F = a.columns?.gapPx ?? 24, k = a.columns?.cols;
3848
- if (S > 1 && k && k.length === S) {
3861
+ if (A > 1 && k && k.length === A) {
3849
3862
  let M = h;
3850
- W = k.map((N, b) => {
3851
- const G = { x: M, width: N.widthPx };
3852
- return M += N.widthPx + (b < S - 1 ? N.spaceAfterPx : 0), G;
3853
- }), m = Math.min(...k.map((N) => N.widthPx));
3854
- } else S > 1 ? (m = (p - (S - 1) * F) / S, W = Array.from({ length: S }, (M, N) => ({
3855
- x: h + N * (m + F),
3856
- width: m
3857
- }))) : (m = p, W = [{ x: h, width: p }]);
3858
- L = a.columns?.sep ? W.slice(0, -1).map((M, N) => (M.x + M.width + W[N + 1].x) / 2) : [];
3863
+ R = k.map((S, C) => {
3864
+ const G = { x: M, width: S.widthPx };
3865
+ return M += S.widthPx + (C < A - 1 ? S.spaceAfterPx : 0), G;
3866
+ }), N = Math.min(...k.map((S) => S.widthPx));
3867
+ } else A > 1 ? (N = (p - (A - 1) * F) / A, R = Array.from({ length: A }, (M, S) => ({
3868
+ x: h + S * (N + F),
3869
+ width: N
3870
+ }))) : (N = p, R = [{ x: h, width: p }]);
3871
+ D = a.columns?.sep ? R.slice(0, -1).map((M, S) => (M.x + M.width + R[S + 1].x) / 2) : [];
3859
3872
  };
3860
- w(a);
3861
- const D = e.lists ?? {}, A = (f) => {
3873
+ H(a);
3874
+ const b = e.lists ?? {}, m = (f) => {
3862
3875
  const g = f.style.list;
3863
3876
  if (!g) return null;
3864
- const F = D[g.listId];
3877
+ const F = b[g.listId];
3865
3878
  return F ? F.levels[Math.min(g.level, F.levels.length - 1)] ?? null : null;
3866
- }, C = (f) => f.style.indentLeftPx + (A(f)?.indentLeftPx ?? 0), _ = (f) => f.style.direction === "rtl" ? f.style.indentRightPx ?? 0 : C(f), O = (f) => f.style.direction === "rtl" ? C(f) : f.style.indentRightPx ?? 0, ee = (f) => A(f)?.indentLeftPx ?? 0, v = /* @__PURE__ */ new Map(), H = /* @__PURE__ */ new Map(), y = (f) => {
3867
- const g = f.style.list, F = A(f);
3879
+ }, y = (f) => f.style.indentLeftPx + (m(f)?.indentLeftPx ?? 0), _ = (f) => f.style.direction === "rtl" ? f.style.indentRightPx ?? 0 : y(f), L = (f) => f.style.direction === "rtl" ? y(f) : f.style.indentRightPx ?? 0, J = (f) => m(f)?.indentLeftPx ?? 0, I = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new Map(), w = (f) => {
3880
+ const g = f.style.list, F = m(f);
3868
3881
  if (!g || !F) return;
3869
- const k = D[g.listId], M = v.get(g.listId) ?? [];
3870
- M[g.level] = (M[g.level] ?? F.start - 1) + 1, M.length = g.level + 1, v.set(g.listId, M);
3871
- const N = Is(k, g.level, M);
3872
- if (N.length === 0) return;
3873
- const b = f.runs[0]?.style;
3874
- b && H.set(f.id, {
3875
- text: N,
3876
- style: { ...b, ...F.markerStyle ?? {} },
3882
+ const k = b[g.listId], M = I.get(g.listId) ?? [];
3883
+ M[g.level] = (M[g.level] ?? F.start - 1) + 1, M.length = g.level + 1, I.set(g.listId, M);
3884
+ const S = Is(k, g.level, M);
3885
+ if (S.length === 0) return;
3886
+ const C = f.runs[0]?.style;
3887
+ C && W.set(f.id, {
3888
+ text: S,
3889
+ style: { ...C, ...F.markerStyle ?? {} },
3877
3890
  hangingPx: F.hangingPx
3878
3891
  });
3879
- }, $ = (f) => {
3892
+ }, K = (f) => {
3880
3893
  for (const g of f)
3881
- if (g.kind === "paragraph") y(g);
3882
- else if (g.kind === "table") for (const F of g.rows) for (const k of F.cells) $(k.blocks);
3894
+ if (g.kind === "paragraph") w(g);
3895
+ else if (g.kind === "table") for (const F of g.rows) for (const k of F.cells) K(k.blocks);
3883
3896
  };
3884
- $(e.blocks);
3885
- const B = { indentOf: ee, markers: H }, P = [];
3897
+ K(e.blocks);
3898
+ const B = { indentOf: J, markers: W }, O = [];
3886
3899
  let U = 0;
3887
3900
  for (let f = 0; f < e.blocks.length; f++) {
3888
- for (; f > c[U].endBlock; ) w(c[++U].props);
3901
+ for (; f > c[U].endBlock; ) H(c[++U].props);
3889
3902
  const g = e.blocks[f];
3890
3903
  if (g.kind === "paragraph") {
3891
3904
  if (H0(g)) continue;
3892
3905
  const F = g.style.tocEntry ? $0 : 0;
3893
- P.push({
3906
+ O.push({
3894
3907
  kind: "para",
3895
3908
  block: g,
3896
- lines: t(g, m - _(g) - O(g) - F)
3909
+ lines: t(g, N - _(g) - L(g) - F)
3897
3910
  });
3898
3911
  } else if (g.kind === "image")
3899
- P.push({ kind: "image", block: g, height: g.anchor ? 0 : g.heightPx });
3912
+ O.push({ kind: "image", block: g, height: g.anchor ? 0 : g.heightPx });
3900
3913
  else if (g.kind === "equation") {
3901
3914
  const F = We(g);
3902
- P.push({ kind: "equation", block: g, box: F, height: F.ascent + F.descent });
3915
+ O.push({ kind: "equation", block: g, box: F, height: F.ascent + F.descent });
3903
3916
  } else {
3904
- const F = i(g, m, t, B);
3905
- P.push({ kind: "table", block: g, ...F });
3917
+ const F = i(g, N, t, B);
3918
+ O.push({ kind: "table", block: g, ...F });
3906
3919
  }
3907
3920
  }
3908
- U = 0, w(c[0].props);
3909
- const I = [], Y = () => {
3910
- I.push(a);
3921
+ U = 0, H(c[0].props);
3922
+ const P = [], Q = () => {
3923
+ P.push(a);
3911
3924
  const f = {
3912
- index: I.length - 1,
3913
- number: I.length,
3925
+ index: P.length - 1,
3926
+ number: P.length,
3914
3927
  // provisional; the post-pass sets the real value
3915
3928
  blocks: [],
3916
3929
  widthPx: a.pageWidthPx,
@@ -3919,9 +3932,9 @@ function J0(e, t, n, s, i = Te, r = je) {
3919
3932
  contentTopPx: u,
3920
3933
  contentBottomPx: E
3921
3934
  };
3922
- return a.pageColorHex !== void 0 && (f.pageColorHex = a.pageColorHex), a.pageBorders !== void 0 && (f.pageBorders = a.pageBorders), L.length && (f.columnSeparatorsX = L.slice()), f;
3923
- }, K = [Y()];
3924
- let q = K[0], T = u;
3935
+ return a.pageColorHex !== void 0 && (f.pageColorHex = a.pageColorHex), a.pageBorders !== void 0 && (f.pageBorders = a.pageBorders), D.length && (f.columnSeparatorsX = D.slice()), f;
3936
+ }, q = [Q()];
3937
+ let $ = q[0], T = u;
3925
3938
  const pe = /* @__PURE__ */ new Map(), se = 14, ge = 18, Fe = e.footnotes ?? {}, $e = Object.keys(Fe).length > 0;
3926
3939
  let Be = 0;
3927
3940
  const re = () => E - Be, lt = /* @__PURE__ */ new Set(), Ge = [[]], Je = [0], Tt = /* @__PURE__ */ new Map(), Gt = (f) => {
@@ -3929,37 +3942,37 @@ function J0(e, t, n, s, i = Te, r = je) {
3929
3942
  if (!g || g.length === 0) return null;
3930
3943
  const F = Math.max(40, p - ge);
3931
3944
  let k = 0;
3932
- return { paras: g.map((N) => {
3933
- const b = t(N, F);
3934
- return k += N.style.spaceBeforePx + me(b) + N.style.spaceAfterPx, { p: N, lines: b };
3945
+ return { paras: g.map((S) => {
3946
+ const C = t(S, F);
3947
+ return k += S.style.spaceBeforePx + me(C) + S.style.spaceAfterPx, { p: S, lines: C };
3935
3948
  }), height: k };
3936
3949
  }, gs = (f, g, F) => {
3937
3950
  const k = [];
3938
3951
  for (let M = g; M < g + F; M++)
3939
- for (const N of f[M].fragments) {
3940
- const b = N.style.footnoteRef;
3941
- b && Fe[b] && !lt.has(b) && !k.some(([G]) => G === b) && k.push([b, N.text]);
3952
+ for (const S of f[M].fragments) {
3953
+ const C = S.style.footnoteRef;
3954
+ C && Fe[C] && !lt.has(C) && !k.some(([G]) => G === C) && k.push([C, S.text]);
3942
3955
  }
3943
3956
  return k;
3944
3957
  };
3945
3958
  let Oe = 0, Ye = 0;
3946
- const ue = () => W[Oe]?.x ?? h, ae = () => q.blocks.length > Ye, Qe = () => {
3947
- Oe = 0, Ye = 0, q = Y(), K.push(q), Ge.push([]), Je.push(0), Be = 0, T = u, Se = [];
3959
+ const ue = () => R[Oe]?.x ?? h, ae = () => $.blocks.length > Ye, Qe = () => {
3960
+ Oe = 0, Ye = 0, $ = Q(), q.push($), Ge.push([]), Je.push(0), Be = 0, T = u, Se = [];
3948
3961
  }, xe = () => {
3949
- Oe + 1 < S ? (Oe++, Ye = q.blocks.length, T = u, Se = []) : Qe();
3962
+ Oe + 1 < A ? (Oe++, Ye = $.blocks.length, T = u, Se = []) : Qe();
3950
3963
  }, Fs = () => {
3951
- q.widthPx = a.pageWidthPx, q.heightPx = a.pageHeightPx, q.marginPx = a.marginPx, q.contentTopPx = u, q.contentBottomPx = E, a.pageColorHex !== void 0 ? q.pageColorHex = a.pageColorHex : delete q.pageColorHex, a.pageBorders !== void 0 ? q.pageBorders = a.pageBorders : delete q.pageBorders, L.length ? q.columnSeparatorsX = L.slice() : delete q.columnSeparatorsX, I[q.index] = a, Oe = 0, Ye = 0, T = u, Se = [];
3964
+ $.widthPx = a.pageWidthPx, $.heightPx = a.pageHeightPx, $.marginPx = a.marginPx, $.contentTopPx = u, $.contentBottomPx = E, a.pageColorHex !== void 0 ? $.pageColorHex = a.pageColorHex : delete $.pageColorHex, a.pageBorders !== void 0 ? $.pageBorders = a.pageBorders : delete $.pageBorders, D.length ? $.columnSeparatorsX = D.slice() : delete $.columnSeparatorsX, P[$.index] = a, Oe = 0, Ye = 0, T = u, Se = [];
3952
3965
  }, ms = (f) => {
3953
- if (q.blocks.length === 0 ? Fs() : Qe(), f === "evenPage" || f === "oddPage") {
3966
+ if ($.blocks.length === 0 ? Fs() : Qe(), f === "evenPage" || f === "oddPage") {
3954
3967
  const g = f === "evenPage";
3955
- q.number % 2 === 0 !== g && Qe();
3968
+ $.number % 2 === 0 !== g && Qe();
3956
3969
  }
3957
3970
  }, Ns = (f, g, F, k) => {
3958
3971
  if (f.style.direction !== "rtl") return g - k.hangingPx;
3959
3972
  let M = 0;
3960
- for (const b of F?.fragments ?? []) M = Math.max(M, b.x + b.width);
3961
- const N = he(k.text, le(k.style));
3962
- return g + M + Math.max(0, k.hangingPx - N);
3973
+ for (const C of F?.fragments ?? []) M = Math.max(M, C.x + C.width);
3974
+ const S = he(k.text, le(k.style));
3975
+ return g + M + Math.max(0, k.hangingPx - S);
3963
3976
  }, Ss = (f, g, F, k) => {
3964
3977
  const M = {
3965
3978
  blockId: f.id,
@@ -3967,14 +3980,14 @@ function J0(e, t, n, s, i = Te, r = je) {
3967
3980
  y: T,
3968
3981
  firstLineIndex: F,
3969
3982
  lines: []
3970
- }, N = F === 0 ? H.get(f.id) : void 0;
3971
- N && (M.marker = { text: N.text, style: N.style, x: Ns(f, M.x, g[F], N) }), f.style.tocEntry && pe.set(f.id, { chunk: M, rightEdge: ue() + m, para: f }), q.blocks.push(M);
3972
- let b = 0;
3983
+ }, S = F === 0 ? W.get(f.id) : void 0;
3984
+ S && (M.marker = { text: S.text, style: S.style, x: Ns(f, M.x, g[F], S) }), f.style.tocEntry && pe.set(f.id, { chunk: M, rightEdge: ue() + N, para: f }), $.blocks.push(M);
3985
+ let C = 0;
3973
3986
  for (let j = F; j < F + k; j++) {
3974
- const R = g[j];
3975
- M.lines.push({ ...R, y: T - M.y }), T += R.height, b += R.height;
3987
+ const v = g[j];
3988
+ M.lines.push({ ...v, y: T - M.y }), T += v.height, C += v.height;
3976
3989
  }
3977
- const G = we(f.style, m - _(f) - O(f), b);
3990
+ const G = we(f.style, N - _(f) - L(f), C);
3978
3991
  G && (M.paraDecor = G);
3979
3992
  }, As = (f, g) => {
3980
3993
  let F = 0, k = T;
@@ -3982,28 +3995,28 @@ function J0(e, t, n, s, i = Te, r = je) {
3982
3995
  k += f[g + F].height, F++;
3983
3996
  return F;
3984
3997
  }, Ht = (f) => {
3985
- let g = Ge[q.index].length === 0 ? se : 0;
3998
+ let g = Ge[$.index].length === 0 ? se : 0;
3986
3999
  const F = [];
3987
4000
  for (const [k, M] of f) {
3988
- const N = Gt(k);
3989
- N && (g += N.height, F.push([k, M, N]));
4001
+ const S = Gt(k);
4002
+ S && (g += S.height, F.push([k, M, S]));
3990
4003
  }
3991
4004
  return { H: g, measures: F };
3992
4005
  }, _t = (f, g) => {
3993
4006
  for (const [F, k] of f)
3994
- lt.add(F), Ge[q.index].push(F), Tt.set(F, k);
3995
- Be += g, Je[q.index] = Be;
4007
+ lt.add(F), Ge[$.index].push(F), Tt.set(F, k);
4008
+ Be += g, Je[$.index] = Be;
3996
4009
  }, Es = (f) => {
3997
4010
  const g = [], F = (k) => {
3998
4011
  for (const M of k)
3999
4012
  if (M.kind === "paragraph") {
4000
- let N = 0;
4001
- for (const b of M.runs) {
4002
- const G = b.style.footnoteRef;
4003
- G && Fe[G] && !lt.has(G) && !g.some(([j]) => j === G) && g.push([G, b.text]), N += b.text.length;
4013
+ let S = 0;
4014
+ for (const C of M.runs) {
4015
+ const G = C.style.footnoteRef;
4016
+ G && Fe[G] && !lt.has(G) && !g.some(([j]) => j === G) && g.push([G, C.text]), S += C.text.length;
4004
4017
  }
4005
4018
  } else if (M.kind === "table")
4006
- for (const N of M.rows) for (const b of N.cells) F(b.blocks);
4019
+ for (const S of M.rows) for (const C of S.cells) F(C.blocks);
4007
4020
  };
4008
4021
  for (const k of f) for (const M of k.cells) F(M.blocks);
4009
4022
  return g;
@@ -4012,12 +4025,12 @@ function J0(e, t, n, s, i = Te, r = je) {
4012
4025
  if (F <= 0) return F;
4013
4026
  const k = gs(f, g, F);
4014
4027
  if (k.length === 0) return F;
4015
- const { H: M, measures: N } = Ht(k);
4016
- if (N.length === 0) return F;
4017
- let b = 0;
4018
- for (let j = g; j < g + F; j++) b += f[j].height;
4019
- if (T + b + M <= re() || F === 1 && !ae())
4020
- return _t(N, M), F;
4028
+ const { H: M, measures: S } = Ht(k);
4029
+ if (S.length === 0) return F;
4030
+ let C = 0;
4031
+ for (let j = g; j < g + F; j++) C += f[j].height;
4032
+ if (T + C + M <= re() || F === 1 && !ae())
4033
+ return _t(S, M), F;
4021
4034
  F--;
4022
4035
  }
4023
4036
  }, ks = (f, g) => {
@@ -4028,15 +4041,15 @@ function J0(e, t, n, s, i = Te, r = je) {
4028
4041
  let F = 0;
4029
4042
  for (; F < g.length; ) {
4030
4043
  const k = g.length - F, M = As(g, F);
4031
- let N;
4044
+ let S;
4032
4045
  if (M >= k)
4033
- N = k;
4046
+ S = k;
4034
4047
  else {
4035
- N = M;
4036
- const b = f.style.widowControl !== !1;
4037
- b && k - N === 1 && (N -= Bn - 1), b && F === 0 && N > 0 && N < kn && (N = 0), N <= 0 && (N = ae() ? 0 : Math.max(1, M));
4048
+ S = M;
4049
+ const C = f.style.widowControl !== !1;
4050
+ C && k - S === 1 && (S -= Bn - 1), C && F === 0 && S > 0 && S < kn && (S = 0), S <= 0 && (S = ae() ? 0 : Math.max(1, M));
4038
4051
  }
4039
- if (N > 0 && $e && (N = Ms(g, F, N)), N > 0 && (Ss(f, g, F, N), F += N), F >= g.length) return;
4052
+ if (S > 0 && $e && (S = Ms(g, F, S)), S > 0 && (Ss(f, g, F, S), F += S), F >= g.length) return;
4040
4053
  xe();
4041
4054
  }
4042
4055
  }, me = (f) => {
@@ -4046,7 +4059,7 @@ function J0(e, t, n, s, i = Te, r = je) {
4046
4059
  };
4047
4060
  let Se = [];
4048
4061
  const jt = 10, Bs = (f) => {
4049
- let g = ue(), F = ue() + m;
4062
+ let g = ue(), F = ue() + N;
4050
4063
  for (const k of Se)
4051
4064
  f >= k.bottom || (k.side === "left" ? g = Math.max(g, k.right + jt) : F = Math.min(F, k.left - jt));
4052
4065
  return { x0: g, width: Math.max(40, F - g) };
@@ -4087,7 +4100,7 @@ function J0(e, t, n, s, i = Te, r = je) {
4087
4100
  break;
4088
4101
  }
4089
4102
  const M = { src: f.src, width: f.widthPx, height: f.heightPx, z: g.z ?? 0, ...f.crop ? { crop: f.crop } : {} };
4090
- g.behind ? M.behind = !0 : M.front = !0, q.blocks.push({
4103
+ g.behind ? M.behind = !0 : M.front = !0, $.blocks.push({
4091
4104
  blockId: f.id,
4092
4105
  x: F + g.offsetXPx,
4093
4106
  y: k + g.offsetYPx,
@@ -4101,8 +4114,8 @@ function J0(e, t, n, s, i = Te, r = je) {
4101
4114
  return;
4102
4115
  }
4103
4116
  T + f.heightPx > re() && ae() && xe();
4104
- const g = f.wrap === "square" && f.align !== "center", F = m - f.widthPx, k = ue() + (f.align === "center" ? F / 2 : f.align === "right" ? F : 0);
4105
- q.blocks.push({
4117
+ const g = f.wrap === "square" && f.align !== "center", F = N - f.widthPx, k = ue() + (f.align === "center" ? F / 2 : f.align === "right" ? F : 0);
4118
+ $.blocks.push({
4106
4119
  blockId: f.id,
4107
4120
  x: k,
4108
4121
  y: T,
@@ -4113,10 +4126,10 @@ function J0(e, t, n, s, i = Te, r = je) {
4113
4126
  }, ys = (f, g) => {
4114
4127
  const F = g.ascent + g.descent;
4115
4128
  T + F > re() && ae() && xe();
4116
- const k = f.align ?? "center", M = m - g.width, N = ue() + (k === "center" ? M / 2 : k === "right" ? M : 0);
4117
- q.blocks.push({
4129
+ const k = f.align ?? "center", M = N - g.width, S = ue() + (k === "center" ? M / 2 : k === "right" ? M : 0);
4130
+ $.blocks.push({
4118
4131
  blockId: f.id,
4119
- x: N,
4132
+ x: S,
4120
4133
  y: T,
4121
4134
  firstLineIndex: 0,
4122
4135
  lines: [],
@@ -4124,63 +4137,63 @@ function J0(e, t, n, s, i = Te, r = je) {
4124
4137
  }), T += F;
4125
4138
  }, ws = (f) => {
4126
4139
  const g = n(f), F = is(f), k = Xn(f.style.align, f.style.direction);
4127
- let M = !0, N = 0, b = null;
4140
+ let M = !0, S = 0, C = null;
4128
4141
  const G = () => {
4129
- if (b && b.lines.length) {
4130
- const R = we(f.style, m - _(f) - O(f), W0(b.lines));
4131
- R && (b.paraDecor = R);
4142
+ if (C && C.lines.length) {
4143
+ const v = we(f.style, N - _(f) - L(f), W0(C.lines));
4144
+ v && (C.paraDecor = v);
4132
4145
  }
4133
- }, j = (R, Z, J, z) => {
4134
- if (b === null) {
4135
- b = { blockId: f.id, x: ue() + _(f), y: T, firstLineIndex: N, lines: [] };
4136
- const Q = N === 0 ? H.get(f.id) : void 0;
4137
- if (Q) {
4146
+ }, j = (v, ee, Y, z) => {
4147
+ if (C === null) {
4148
+ C = { blockId: f.id, x: ue() + _(f), y: T, firstLineIndex: S, lines: [] };
4149
+ const V = S === 0 ? W.get(f.id) : void 0;
4150
+ if (V) {
4138
4151
  let te;
4139
4152
  if (f.style.direction === "rtl") {
4140
4153
  let ie = 0;
4141
- for (const X of R) ie = Math.max(ie, X.frag.x + X.frag.width);
4142
- const oe = he(Q.text, le(Q.style));
4143
- te = b.x + ie + Math.max(0, Q.hangingPx - oe);
4154
+ for (const Z of v) ie = Math.max(ie, Z.frag.x + Z.frag.width);
4155
+ const oe = he(V.text, le(V.style));
4156
+ te = C.x + ie + Math.max(0, V.hangingPx - oe);
4144
4157
  } else
4145
- te = b.x + (R[0]?.frag.x ?? 0) - Q.hangingPx;
4146
- b.marker = { text: Q.text, style: Q.style, x: te };
4158
+ te = C.x + (v[0]?.frag.x ?? 0) - V.hangingPx;
4159
+ C.marker = { text: V.text, style: V.style, x: te };
4147
4160
  }
4148
- q.blocks.push(b);
4161
+ $.blocks.push(C);
4149
4162
  }
4150
- const V = { y: T - b.y, height: Z, ascent: J, fragments: R.map((Q) => Q.frag) };
4151
- z !== void 0 && (V.emptyOffset = z), b.lines.push(V), T += Z, N++;
4163
+ const X = { y: T - C.y, height: ee, ascent: Y, fragments: v.map((V) => V.frag) };
4164
+ z !== void 0 && (X.emptyOffset = z), C.lines.push(X), T += ee, S++;
4152
4165
  };
4153
- for (const R of g) {
4154
- const Z = Pt(R.runs, R.startOffset), J = R.runs.map(() => 0);
4155
- let z, V = !1, Q = null;
4166
+ for (const v of g) {
4167
+ const ee = Pt(v.runs, v.startOffset), Y = v.runs.map(() => 0);
4168
+ let z, X = !1, V = null;
4156
4169
  for (; ; ) {
4157
- const te = J.slice(), ie = Bs(T), oe = M ? f.style.indentFirstLinePx : 0, X = vt(
4170
+ const te = Y.slice(), ie = Bs(T), oe = M ? f.style.indentFirstLinePx : 0, Z = vt(
4158
4171
  f,
4159
- R,
4160
- Math.max(24, ie.width - _(f) - oe - O(f)),
4172
+ v,
4173
+ Math.max(24, ie.width - _(f) - oe - L(f)),
4161
4174
  z,
4162
- Z,
4163
- J
4175
+ ee,
4176
+ Y
4164
4177
  );
4165
- if (X === null) break;
4166
- if (T + X.height > re() && ae()) {
4167
- for (let Ne = 0; Ne < J.length; Ne++) J[Ne] = te[Ne];
4168
- G(), xe(), b = null;
4178
+ if (Z === null) break;
4179
+ if (T + Z.height > re() && ae()) {
4180
+ for (let Ne = 0; Ne < Y.length; Ne++) Y[Ne] = te[Ne];
4181
+ G(), xe(), C = null;
4169
4182
  continue;
4170
4183
  }
4171
- if (F !== null && X.frags.length > 0) {
4172
- const Ne = cs(X.frags, F);
4173
- X.frags = Ne.frags, X.width = Ne.width;
4184
+ if (F !== null && Z.frags.length > 0) {
4185
+ const Ne = cs(Z.frags, F);
4186
+ Z.frags = Ne.frags, Z.width = Ne.width;
4174
4187
  }
4175
- const xt = ie.width - oe - O(f) - X.width;
4188
+ const xt = ie.width - oe - L(f) - Z.width;
4176
4189
  let ft = ie.x0 - ue() + oe;
4177
4190
  k === "center" ? ft += xt / 2 : k === "right" && (ft += xt);
4178
- for (const Ne of X.frags) Ne.frag.x += ft;
4179
- k === "justify" && (Q && rs(Q.frags, Q.slack), Q = { frags: X.frags, slack: xt }), j(X.frags, X.height, X.ascent), z = X.end, M = !1, V = !0;
4191
+ for (const Ne of Z.frags) Ne.frag.x += ft;
4192
+ k === "justify" && (V && rs(V.frags, V.slack), V = { frags: Z.frags, slack: xt }), j(Z.frags, Z.height, Z.ascent), z = Z.end, M = !1, X = !0;
4180
4193
  }
4181
- if (!V) {
4194
+ if (!X) {
4182
4195
  const te = ns(f);
4183
- T + te.height > re() && ae() && (G(), xe(), b = null), j([], te.height, te.ascent, R.startOffset), M = !1;
4196
+ T + te.height > re() && ae() && (G(), xe(), C = null), j([], te.height, te.ascent, v.startOffset), M = !1;
4184
4197
  }
4185
4198
  }
4186
4199
  G();
@@ -4189,49 +4202,49 @@ function J0(e, t, n, s, i = Te, r = je) {
4189
4202
  g && ae() && T + f.height > re() && f.height <= E - u && xe();
4190
4203
  let F = 0;
4191
4204
  for (; F < f.rows.length && f.block.rows[F]?.props?.repeatHeader; ) F++;
4192
- const k = F > 0 && F < f.rows.length && !g, M = k ? f.rows.slice(0, F) : [], N = M.reduce((G, j) => G + j.height, 0);
4193
- let b = 0;
4194
- for (; b < f.rows.length; ) {
4195
- const G = k && b >= F, j = G ? N : 0;
4196
- let R = 0, Z = T + j;
4197
- for (; b + R < f.rows.length && Z + f.rows[b + R].height <= re(); )
4198
- Z += f.rows[b + R].height, R++;
4199
- if (R === 0) {
4205
+ const k = F > 0 && F < f.rows.length && !g, M = k ? f.rows.slice(0, F) : [], S = M.reduce((G, j) => G + j.height, 0);
4206
+ let C = 0;
4207
+ for (; C < f.rows.length; ) {
4208
+ const G = k && C >= F, j = G ? S : 0;
4209
+ let v = 0, ee = T + j;
4210
+ for (; C + v < f.rows.length && ee + f.rows[C + v].height <= re(); )
4211
+ ee += f.rows[C + v].height, v++;
4212
+ if (v === 0) {
4200
4213
  if (ae()) {
4201
4214
  xe();
4202
4215
  continue;
4203
4216
  }
4204
- R = 1;
4217
+ v = 1;
4205
4218
  }
4206
- let J = [], z = 0;
4219
+ let Y = [], z = 0;
4207
4220
  for (; ; ) {
4208
- const Q = Es(f.block.rows.slice(b, b + R));
4209
- if (Q.length === 0) break;
4210
- const { H: te, measures: ie } = Ht(Q);
4221
+ const V = Es(f.block.rows.slice(C, C + v));
4222
+ if (V.length === 0) break;
4223
+ const { H: te, measures: ie } = Ht(V);
4211
4224
  if (ie.length === 0) break;
4212
4225
  let oe = j;
4213
- for (let X = b; X < b + R; X++) oe += f.rows[X].height;
4214
- if (T + oe + te <= re() || R === 1 && !ae()) {
4215
- J = ie, z = te;
4226
+ for (let Z = C; Z < C + v; Z++) oe += f.rows[Z].height;
4227
+ if (T + oe + te <= re() || v === 1 && !ae()) {
4228
+ Y = ie, z = te;
4216
4229
  break;
4217
4230
  }
4218
- if (R--, R === 0) break;
4231
+ if (v--, v === 0) break;
4219
4232
  }
4220
- if (R === 0) {
4233
+ if (v === 0) {
4221
4234
  xe();
4222
4235
  continue;
4223
4236
  }
4224
- J.length > 0 && _t(J, z), G && (q.blocks.push(Ke(f.block, M, f.colWidths, ue() + f.xOffset, T, f.tableWidth, 0, B)), T += N);
4225
- const V = f.rows.slice(b, b + R);
4226
- q.blocks.push(Ke(f.block, V, f.colWidths, ue() + f.xOffset, T, f.tableWidth, b, B)), T += V.reduce((Q, te) => Q + te.height, 0), b += R, b < f.rows.length && xe();
4237
+ Y.length > 0 && _t(Y, z), G && ($.blocks.push(Ke(f.block, M, f.colWidths, ue() + f.xOffset, T, f.tableWidth, 0, B)), T += S);
4238
+ const X = f.rows.slice(C, C + v);
4239
+ $.blocks.push(Ke(f.block, X, f.colWidths, ue() + f.xOffset, T, f.tableWidth, C, B)), T += X.reduce((V, te) => V + te.height, 0), C += v, C < f.rows.length && xe();
4227
4240
  }
4228
4241
  }, Ve = (f, g) => f?.kind === "para" && g?.kind === "para" && f.block.style.contextualSpacing === !0 && f.block.style.namedStyle === g.block.style.namedStyle;
4229
- for (let f = 0; f < P.length; f++) {
4242
+ for (let f = 0; f < O.length; f++) {
4230
4243
  if (f > c[U].endBlock) {
4231
- for (; f > c[U].endBlock; ) w(c[++U].props);
4244
+ for (; f > c[U].endBlock; ) H(c[++U].props);
4232
4245
  ms(c[U].breakType);
4233
4246
  }
4234
- const g = P[f], F = (R) => R?.kind === "table" || R?.kind === "equation" || R?.kind === "image" && R.block.anchor === void 0, k = F(P[f - 1]), M = F(P[f + 1]);
4247
+ const g = O[f], F = (v) => v?.kind === "table" || v?.kind === "equation" || v?.kind === "image" && v.block.anchor === void 0, k = F(O[f - 1]), M = F(O[f + 1]);
4235
4248
  if (g.kind === "image") {
4236
4249
  if (g.block.anchor) {
4237
4250
  Ut(g.block);
@@ -4242,121 +4255,121 @@ function J0(e, t, n, s, i = Te, r = je) {
4242
4255
  }
4243
4256
  if (g.kind === "equation") {
4244
4257
  k || (T += be);
4245
- for (const R of Se) R.bottom > T && (T = R.bottom);
4258
+ for (const v of Se) v.bottom > T && (T = v.bottom);
4246
4259
  ys(g.block, g.box), M || (T += be);
4247
4260
  continue;
4248
4261
  }
4249
4262
  if (g.kind === "table") {
4250
4263
  k || (T += be);
4251
- for (const R of Se) R.bottom > T && (T = R.bottom);
4264
+ for (const v of Se) v.bottom > T && (T = v.bottom);
4252
4265
  Ds(g), M || (T += be);
4253
4266
  continue;
4254
4267
  }
4255
- const { block: N, lines: b } = g;
4256
- N.style.pageBreakBefore === !0 && (q.blocks.length > 0 || Oe > 0) ? Qe() : N.style.columnBreakBefore === !0 && ae() && xe();
4257
- const G = Ve(g, P[f - 1]), j = Ve(g, P[f + 1]);
4258
- if (G || (T += N.style.spaceBeforePx), T >= re() && ae() && xe(), bs(T)) {
4259
- T += Sn(N.style), ws(N), T += An(N.style), j || (T += N.style.spaceAfterPx);
4268
+ const { block: S, lines: C } = g;
4269
+ S.style.pageBreakBefore === !0 && ($.blocks.length > 0 || Oe > 0) ? Qe() : S.style.columnBreakBefore === !0 && ae() && xe();
4270
+ const G = Ve(g, O[f - 1]), j = Ve(g, O[f + 1]);
4271
+ if (G || (T += S.style.spaceBeforePx), T >= re() && ae() && xe(), bs(T)) {
4272
+ T += Sn(S.style), ws(S), T += An(S.style), j || (T += S.style.spaceAfterPx);
4260
4273
  continue;
4261
4274
  }
4262
- if (N.style.keepWithNext === !0 && P[f + 1] !== void 0 && ae()) {
4263
- let R = T + me(b) + (j ? 0 : N.style.spaceAfterPx), Z = R <= re();
4264
- for (let J = f + 1; Z; J++) {
4265
- const z = P[J];
4275
+ if (S.style.keepWithNext === !0 && O[f + 1] !== void 0 && ae()) {
4276
+ let v = T + me(C) + (j ? 0 : S.style.spaceAfterPx), ee = v <= re();
4277
+ for (let Y = f + 1; ee; Y++) {
4278
+ const z = O[Y];
4266
4279
  if (z === void 0) break;
4267
4280
  if (z.kind !== "para") {
4268
- const X = z.kind === "table" ? z.rows[0]?.height ?? z.height : z.height;
4269
- R + be + X > re() && (Z = !1);
4281
+ const Z = z.kind === "table" ? z.rows[0]?.height ?? z.height : z.height;
4282
+ v + be + Z > re() && (ee = !1);
4270
4283
  break;
4271
4284
  }
4272
- Ve(z, P[J - 1]) || (R += z.block.style.spaceBeforePx);
4273
- const V = Ve(z, P[J + 1]) ? 0 : z.block.style.spaceAfterPx, Q = z.block.style.keepWithNext === !0 && P[J + 1] !== void 0;
4274
- if (Q || z.block.style.keepLinesTogether === !0) {
4275
- const X = me(z.lines);
4276
- if (R + X > re()) {
4277
- Z = !1;
4285
+ Ve(z, O[Y - 1]) || (v += z.block.style.spaceBeforePx);
4286
+ const X = Ve(z, O[Y + 1]) ? 0 : z.block.style.spaceAfterPx, V = z.block.style.keepWithNext === !0 && O[Y + 1] !== void 0;
4287
+ if (V || z.block.style.keepLinesTogether === !0) {
4288
+ const Z = me(z.lines);
4289
+ if (v + Z > re()) {
4290
+ ee = !1;
4278
4291
  break;
4279
4292
  }
4280
- if (R += X + V, !Q) break;
4293
+ if (v += Z + X, !V) break;
4281
4294
  continue;
4282
4295
  }
4283
- if (P[J + 1] !== void 0 && z.block.runs.every((X) => X.text.trim().length === 0)) {
4284
- const X = me(z.lines);
4285
- if (R + X > re()) {
4286
- Z = !1;
4296
+ if (O[Y + 1] !== void 0 && z.block.runs.every((Z) => Z.text.trim().length === 0)) {
4297
+ const Z = me(z.lines);
4298
+ if (v + Z > re()) {
4299
+ ee = !1;
4287
4300
  break;
4288
4301
  }
4289
- R += X + V;
4302
+ v += Z + X;
4290
4303
  continue;
4291
4304
  }
4292
- let te = 0, ie = R;
4305
+ let te = 0, ie = v;
4293
4306
  for (; te < z.lines.length && ie + z.lines[te].height <= re(); )
4294
4307
  ie += z.lines[te].height, te++;
4295
4308
  let oe = te;
4296
- te < z.lines.length && z.block.style.widowControl !== !1 && (z.lines.length - oe === 1 && (oe -= Bn - 1), oe < kn && (oe = 0)), oe <= 0 && (Z = !1);
4309
+ te < z.lines.length && z.block.style.widowControl !== !1 && (z.lines.length - oe === 1 && (oe -= Bn - 1), oe < kn && (oe = 0)), oe <= 0 && (ee = !1);
4297
4310
  break;
4298
4311
  }
4299
- Z || xe();
4312
+ ee || xe();
4300
4313
  }
4301
- T += Sn(N.style), ks(N, b), T += An(N.style), j || (T += N.style.spaceAfterPx);
4314
+ T += Sn(S.style), ks(S, C), T += An(S.style), j || (T += S.style.spaceAfterPx);
4302
4315
  }
4303
- if (I.some((f) => f.lineNumbering)) {
4316
+ if (P.some((f) => f.lineNumbering)) {
4304
4317
  const f = le(Mn);
4305
4318
  let g = 1, F = !1, k = null;
4306
- for (const M of K) {
4307
- const N = I[M.index], b = N.lineNumbering;
4308
- if (!b) {
4309
- k = N;
4319
+ for (const M of q) {
4320
+ const S = P[M.index], C = S.lineNumbering;
4321
+ if (!C) {
4322
+ k = S;
4310
4323
  continue;
4311
4324
  }
4312
- const G = b.start ?? 1, j = Math.max(1, Math.round(b.countBy ?? 1)), R = b.restart ?? "newPage";
4313
- R === "newPage" ? g = G : R === "newSection" ? N !== k && (g = G) : F || (g = G), F = !0;
4314
- const Z = M.marginPx.left - (b.distancePx ?? z0), J = [];
4325
+ const G = C.start ?? 1, j = Math.max(1, Math.round(C.countBy ?? 1)), v = C.restart ?? "newPage";
4326
+ v === "newPage" ? g = G : v === "newSection" ? S !== k && (g = G) : F || (g = G), F = !0;
4327
+ const ee = M.marginPx.left - (C.distancePx ?? z0), Y = [];
4315
4328
  for (const z of M.blocks)
4316
4329
  if (!(z.lines.length === 0 || z.image || z.table || z.equation))
4317
- for (const V of z.lines) {
4330
+ for (const X of z.lines) {
4318
4331
  if (g % j === 0) {
4319
- const Q = String(g);
4320
- J.push({
4321
- x: Z - he(Q, f),
4322
- baseline: z.y + V.y + V.ascent,
4323
- text: Q,
4332
+ const V = String(g);
4333
+ Y.push({
4334
+ x: ee - he(V, f),
4335
+ baseline: z.y + X.y + X.ascent,
4336
+ text: V,
4324
4337
  style: Mn
4325
4338
  });
4326
4339
  }
4327
4340
  g++;
4328
4341
  }
4329
- J.length > 0 && (M.lineNumbers = J), k = N;
4342
+ Y.length > 0 && (M.lineNumbers = Y), k = S;
4330
4343
  }
4331
4344
  }
4332
- for (const f of K) {
4345
+ for (const f of q) {
4333
4346
  const g = Ge[f.index];
4334
4347
  if (!g || g.length === 0) continue;
4335
- const F = I[f.index];
4336
- w(F);
4348
+ const F = P[f.index];
4349
+ H(F);
4337
4350
  let k = E - Je[f.index];
4338
4351
  f.footnoteRuleY = k + 4, k += se;
4339
4352
  const M = F.marginPx.left;
4340
- for (const N of g) {
4341
- const b = Gt(N);
4342
- if (!b) continue;
4353
+ for (const S of g) {
4354
+ const C = Gt(S);
4355
+ if (!C) continue;
4343
4356
  let G = !0;
4344
- for (const j of b.paras) {
4357
+ for (const j of C.paras) {
4345
4358
  k += j.p.style.spaceBeforePx;
4346
- const R = {
4359
+ const v = {
4347
4360
  blockId: j.p.id,
4348
4361
  x: M + ge,
4349
4362
  y: k,
4350
4363
  firstLineIndex: 0,
4351
4364
  lines: j.lines
4352
4365
  };
4353
- G && j.p.runs[0] && (R.marker = { text: `${Tt.get(N) ?? "•"}.`, style: j.p.runs[0].style, x: M }, G = !1);
4354
- const Z = we(
4366
+ G && j.p.runs[0] && (v.marker = { text: `${Tt.get(S) ?? "•"}.`, style: j.p.runs[0].style, x: M }, G = !1);
4367
+ const ee = we(
4355
4368
  j.p.style,
4356
4369
  p - ge - j.p.style.indentLeftPx - (j.p.style.indentRightPx ?? 0),
4357
4370
  me(j.lines)
4358
4371
  );
4359
- Z && (R.paraDecor = Z), f.blocks.push(R), k += me(j.lines) + j.p.style.spaceAfterPx;
4372
+ ee && (v.paraDecor = ee), f.blocks.push(v), k += me(j.lines) + j.p.style.spaceAfterPx;
4360
4373
  }
4361
4374
  }
4362
4375
  }
@@ -4365,42 +4378,42 @@ function J0(e, t, n, s, i = Te, r = je) {
4365
4378
  const f = [], g = /* @__PURE__ */ new Set(), F = (k) => {
4366
4379
  for (const M of k)
4367
4380
  if (M.kind === "paragraph")
4368
- for (const N of M.runs) {
4369
- const b = N.style.endnoteRef;
4370
- b && at[b] && !g.has(b) && (g.add(b), f.push([b, N.text]));
4381
+ for (const S of M.runs) {
4382
+ const C = S.style.endnoteRef;
4383
+ C && at[C] && !g.has(C) && (g.add(C), f.push([C, S.text]));
4371
4384
  }
4372
4385
  else if (M.kind === "table")
4373
- for (const N of M.rows) for (const b of N.cells) F(b.blocks);
4386
+ for (const S of M.rows) for (const C of S.cells) F(C.blocks);
4374
4387
  };
4375
4388
  if (F(e.blocks), f.length > 0) {
4376
- w(c[c.length - 1].props);
4389
+ H(c[c.length - 1].props);
4377
4390
  const k = Math.max(40, p - ge), M = a.marginPx.left;
4378
- let N = K[K.length - 1];
4379
- const b = () => {
4380
- N = Y(), delete N.columnSeparatorsX, K.push(N), Ge.push([]), Je.push(0);
4391
+ let S = q[q.length - 1];
4392
+ const C = () => {
4393
+ S = Q(), delete S.columnSeparatorsX, q.push(S), Ge.push([]), Je.push(0);
4381
4394
  };
4382
- N.blocks.length > 0 ? b() : delete N.columnSeparatorsX;
4383
- let G = N.contentTopPx;
4384
- N.endnoteRuleY = G + 4, G += se;
4385
- for (const [j, R] of f) {
4386
- let Z = !0;
4387
- for (const J of at[j]) {
4388
- const z = t(J, k);
4389
- G + J.style.spaceBeforePx + me(z) > N.contentBottomPx && N.blocks.length > 0 && (b(), G = N.contentTopPx), G += J.style.spaceBeforePx;
4390
- const V = {
4391
- blockId: J.id,
4395
+ S.blocks.length > 0 ? C() : delete S.columnSeparatorsX;
4396
+ let G = S.contentTopPx;
4397
+ S.endnoteRuleY = G + 4, G += se;
4398
+ for (const [j, v] of f) {
4399
+ let ee = !0;
4400
+ for (const Y of at[j]) {
4401
+ const z = t(Y, k);
4402
+ G + Y.style.spaceBeforePx + me(z) > S.contentBottomPx && S.blocks.length > 0 && (C(), G = S.contentTopPx), G += Y.style.spaceBeforePx;
4403
+ const X = {
4404
+ blockId: Y.id,
4392
4405
  x: M + ge,
4393
4406
  y: G,
4394
4407
  firstLineIndex: 0,
4395
4408
  lines: z
4396
4409
  };
4397
- Z && J.runs[0] && (V.marker = { text: `${R}.`, style: J.runs[0].style, x: M }, Z = !1);
4398
- const Q = we(
4399
- J.style,
4400
- p - ge - J.style.indentLeftPx - (J.style.indentRightPx ?? 0),
4410
+ ee && Y.runs[0] && (X.marker = { text: `${v}.`, style: Y.runs[0].style, x: M }, ee = !1);
4411
+ const V = we(
4412
+ Y.style,
4413
+ p - ge - Y.style.indentLeftPx - (Y.style.indentRightPx ?? 0),
4401
4414
  me(z)
4402
4415
  );
4403
- Q && (V.paraDecor = Q), N.blocks.push(V), G += me(z) + J.style.spaceAfterPx;
4416
+ V && (X.paraDecor = V), S.blocks.push(X), G += me(z) + Y.style.spaceAfterPx;
4404
4417
  }
4405
4418
  }
4406
4419
  }
@@ -4414,93 +4427,93 @@ function J0(e, t, n, s, i = Te, r = je) {
4414
4427
  const M = g(F.b) - g(k.b);
4415
4428
  if (M !== 0) return M;
4416
4429
  if (g(F.b) !== 1) {
4417
- const N = (F.b.image.z ?? 0) - (k.b.image.z ?? 0);
4418
- if (N !== 0) return N;
4430
+ const S = (F.b.image.z ?? 0) - (k.b.image.z ?? 0);
4431
+ if (S !== 0) return S;
4419
4432
  }
4420
4433
  return F.i - k.i;
4421
4434
  }).map((F) => F.b);
4422
4435
  };
4423
- for (const f of K) f.blocks = zt(f.blocks);
4436
+ for (const f of q) f.blocks = zt(f.blocks);
4424
4437
  const Xe = [];
4425
4438
  {
4426
4439
  let f = 0;
4427
- for (let g = 0; g < K.length; g++) {
4428
- const F = I[g];
4429
- (g === 0 || I[g - 1] !== F) && F.pageNumberStart !== void 0 ? f = F.pageNumberStart : f++, Xe.push(f), K[g].number = f;
4440
+ for (let g = 0; g < q.length; g++) {
4441
+ const F = P[g];
4442
+ (g === 0 || P[g - 1] !== F) && F.pageNumberStart !== void 0 ? f = F.pageNumberStart : f++, Xe.push(f), q[g].number = f;
4430
4443
  }
4431
4444
  }
4432
4445
  const Kt = e.fields;
4433
4446
  if (Kt) {
4434
4447
  const f = (M) => {
4435
4448
  if (M === void 0) return !1;
4436
- const N = Kt[M], b = N && N.kind === "builtin" ? N.spec?.type : void 0;
4437
- return b === "PAGE" || b === "NUMPAGES";
4438
- }, g = (M, N) => {
4439
- let b = 0;
4449
+ const S = Kt[M], C = S && S.kind === "builtin" ? S.spec?.type : void 0;
4450
+ return C === "PAGE" || C === "NUMPAGES";
4451
+ }, g = (M, S) => {
4452
+ let C = 0;
4440
4453
  for (const G of M.fragments) {
4441
- if (b !== 0 && (G.x += b), !f(G.style.fieldId)) continue;
4442
- const j = us(G.text, N, K.length);
4454
+ if (C !== 0 && (G.x += C), !f(G.style.fieldId)) continue;
4455
+ const j = us(G.text, S, q.length);
4443
4456
  if (j === G.text) continue;
4444
- const R = G.endOffset - G.startOffset, Z = G.width;
4445
- G.text = j, G.width = he(j, le(G.style)), G.offsetMap = Array.from({ length: j.length + 1 }, (J, z) => z === j.length ? R : 0), b += G.width - Z;
4457
+ const v = G.endOffset - G.startOffset, ee = G.width;
4458
+ G.text = j, G.width = he(j, le(G.style)), G.offsetMap = Array.from({ length: j.length + 1 }, (Y, z) => z === j.length ? v : 0), C += G.width - ee;
4446
4459
  }
4447
- }, F = (M) => M.fragments.some((N) => f(N.style.fieldId)), k = (M, N) => {
4448
- let b = null;
4460
+ }, F = (M) => M.fragments.some((S) => f(S.style.fieldId)), k = (M, S) => {
4461
+ let C = null;
4449
4462
  for (let G = 0; G < M.lines.length; G++) {
4450
4463
  const j = M.lines[G];
4451
4464
  if (!F(j)) continue;
4452
- const R = { ...j, fragments: j.fragments.map((Z) => ({ ...Z })) };
4453
- g(R, N), (b ??= M.lines.slice())[G] = R;
4465
+ const v = { ...j, fragments: j.fragments.map((ee) => ({ ...ee })) };
4466
+ g(v, S), (C ??= M.lines.slice())[G] = v;
4454
4467
  }
4455
- if (b && (M.lines = b), M.table) for (const G of M.table.rows) for (const j of G.cells) for (const R of j.blocks) k(R, N);
4468
+ if (C && (M.lines = C), M.table) for (const G of M.table.rows) for (const j of G.cells) for (const v of j.blocks) k(v, S);
4456
4469
  };
4457
- for (const M of K) for (const N of M.blocks) k(N, Xe[M.index]);
4470
+ for (const M of q) for (const S of M.blocks) k(S, Xe[M.index]);
4458
4471
  }
4459
4472
  if (pe.size > 0) {
4460
4473
  const f = /* @__PURE__ */ new Map(), g = (F, k) => {
4461
4474
  for (const M of F)
4462
- if (f.has(M.blockId) || f.set(M.blockId, k), M.table) for (const N of M.table.rows) for (const b of N.cells) g(b.blocks, k);
4475
+ if (f.has(M.blockId) || f.set(M.blockId, k), M.table) for (const S of M.table.rows) for (const C of S.cells) g(C.blocks, k);
4463
4476
  };
4464
- for (const F of K) g(F.blocks, Xe[F.index]);
4477
+ for (const F of q) g(F.blocks, Xe[F.index]);
4465
4478
  for (const F of pe.values()) {
4466
4479
  const k = F.para.style.tocEntry.targetId, M = f.get(k);
4467
4480
  if (M === void 0) continue;
4468
- const N = F.para.runs[0]?.style;
4469
- if (!N || F.chunk.lines.length === 0) continue;
4470
- const b = String(M);
4481
+ const S = F.para.runs[0]?.style;
4482
+ if (!S || F.chunk.lines.length === 0) continue;
4483
+ const C = String(M);
4471
4484
  F.chunk.toc = {
4472
- numText: b,
4473
- numX: F.rightEdge - he(b, le(N)),
4485
+ numText: C,
4486
+ numX: F.rightEdge - he(C, le(S)),
4474
4487
  lineIndex: F.chunk.lines.length - 1,
4475
- style: N,
4488
+ style: S,
4476
4489
  targetId: k
4477
4490
  };
4478
4491
  }
4479
4492
  }
4480
4493
  const qt = (f, g, F, k) => {
4481
- const M = g === "header" ? f.headerFirst : f.footerFirst, N = g === "header" ? f.headerEven : f.footerEven;
4494
+ const M = g === "header" ? f.headerFirst : f.footerFirst, S = g === "header" ? f.headerEven : f.footerEven;
4482
4495
  if (F && M) return { blocks: M, source: g === "header" ? "headerFirst" : "footerFirst" };
4483
- if (k && N) return { blocks: N, source: g === "header" ? "headerEven" : "footerEven" };
4484
- const b = f[g];
4485
- return b ? { blocks: b, source: g } : null;
4496
+ if (k && S) return { blocks: S, source: g === "header" ? "headerEven" : "footerEven" };
4497
+ const C = f[g];
4498
+ return C ? { blocks: C, source: g } : null;
4486
4499
  };
4487
- if (I.some((f) => as.some((g) => f[g]))) {
4500
+ if (P.some((f) => as.some((g) => f[g]))) {
4488
4501
  const f = new At();
4489
- for (const g of K) {
4490
- const F = I[g.index], k = F.pageWidthPx - F.marginPx.left - F.marginPx.right, M = F.marginPx.left, N = g.index === 0 || I[g.index - 1] !== F, b = Xe[g.index], G = b % 2 === 0, j = qt(F, "header", N, G);
4502
+ for (const g of q) {
4503
+ const F = P[g.index], k = F.pageWidthPx - F.marginPx.left - F.marginPx.right, M = F.marginPx.left, S = g.index === 0 || P[g.index - 1] !== F, C = Xe[g.index], G = C % 2 === 0, j = qt(F, "header", S, G);
4491
4504
  if (j) {
4492
- const Z = s === "header", J = r(j.blocks, k, M, b, K.length, f, Z), z = bn(F, J.height);
4493
- g.header = J.placed.map((V) => Et(V, z)), g.headerSource = j.source;
4505
+ const ee = s === "header", Y = r(j.blocks, k, M, C, q.length, f, ee), z = bn(F, Y.height);
4506
+ g.header = Y.placed.map((X) => Et(X, z)), g.headerSource = j.source;
4494
4507
  }
4495
- const R = qt(F, "footer", N, G);
4496
- if (R) {
4497
- const Z = s === "footer", J = r(R.blocks, k, M, b, K.length, f, Z), z = Cn(F, J.height);
4498
- g.footer = J.placed.map((V) => Et(V, z)), g.footerSource = R.source;
4508
+ const v = qt(F, "footer", S, G);
4509
+ if (v) {
4510
+ const ee = s === "footer", Y = r(v.blocks, k, M, C, q.length, f, ee), z = Cn(F, Y.height);
4511
+ g.footer = Y.placed.map((X) => Et(X, z)), g.footerSource = v.source;
4499
4512
  }
4500
4513
  }
4501
4514
  }
4502
4515
  return {
4503
- pages: K,
4516
+ pages: q,
4504
4517
  pageWidthPx: e.section.pageWidthPx,
4505
4518
  pageHeightPx: e.section.pageHeightPx,
4506
4519
  marginPx: e.section.marginPx
@@ -4674,15 +4687,15 @@ function ds(e, t, n, s) {
4674
4687
  let a = 0;
4675
4688
  for (const h of c.cells) {
4676
4689
  for (; a < i && l[a] > 0; ) a++;
4677
- const u = Math.max(1, h.colSpan ?? 1), E = Math.max(1, h.rowSpan ?? 1), p = a, S = to(h, t, n, s);
4690
+ const u = Math.max(1, h.colSpan ?? 1), E = Math.max(1, h.rowSpan ?? 1), p = a, A = to(h, t, n, s);
4678
4691
  if (u === 1)
4679
- p < i && (S.min > r[p] && (r[p] = S.min), S.max > o[p] && (o[p] = S.max));
4692
+ p < i && (A.min > r[p] && (r[p] = A.min), A.max > o[p] && (o[p] = A.max));
4680
4693
  else {
4681
- const m = [];
4682
- for (let W = 0; W < u && p + W < i; W++) m.push(p + W);
4683
- m.length > 0 && x.push({ colStart: p, cols: m, mm: S });
4694
+ const N = [];
4695
+ for (let R = 0; R < u && p + R < i; R++) N.push(p + R);
4696
+ N.length > 0 && x.push({ colStart: p, cols: N, mm: A });
4684
4697
  }
4685
- if (E > 1) for (let m = 0; m < u && p + m < i; m++) l[p + m] = E;
4698
+ if (E > 1) for (let N = 0; N < u && p + N < i; N++) l[p + N] = E;
4686
4699
  a = p + u;
4687
4700
  }
4688
4701
  for (let h = 0; h < i; h++) l[h] > 0 && l[h]--;
@@ -4742,51 +4755,51 @@ function Te(e, t, n, s) {
4742
4755
  let u = 0;
4743
4756
  const E = h.cells.map((p) => {
4744
4757
  for (; u < o && x[u] > 0; ) u++;
4745
- const S = Math.max(1, p.colSpan ?? 1), m = Math.max(1, p.rowSpan ?? 1), W = u;
4746
- let L = 0;
4747
- for (let O = 0; O < S; O++) L += r[u + O] ?? r[o - 1] ?? 40;
4748
- if (m > 1) for (let O = 0; O < S && u + O < o; O++) x[u + O] = m;
4749
- u += S;
4750
- const w = Rt(p), D = Math.max(8, L - w.left - w.right), A = ps(p.textDirection);
4751
- if (A) {
4752
- let O = 0;
4753
- const ee = p.blocks.map((v) => {
4754
- if (v.kind === "paragraph") {
4755
- const y = n(v, Wt);
4756
- let $ = 0;
4757
- for (const B of y) $ = Math.max($, hs(B));
4758
- return O = Math.max(O, $ + v.style.indentLeftPx + s.indentOf(v) + (v.style.indentRightPx ?? 0)), { kind: "para", block: v, lines: y };
4758
+ const A = Math.max(1, p.colSpan ?? 1), N = Math.max(1, p.rowSpan ?? 1), R = u;
4759
+ let D = 0;
4760
+ for (let L = 0; L < A; L++) D += r[u + L] ?? r[o - 1] ?? 40;
4761
+ if (N > 1) for (let L = 0; L < A && u + L < o; L++) x[u + L] = N;
4762
+ u += A;
4763
+ const H = Rt(p), b = Math.max(8, D - H.left - H.right), m = ps(p.textDirection);
4764
+ if (m) {
4765
+ let L = 0;
4766
+ const J = p.blocks.map((I) => {
4767
+ if (I.kind === "paragraph") {
4768
+ const w = n(I, Wt);
4769
+ let K = 0;
4770
+ for (const B of w) K = Math.max(K, hs(B));
4771
+ return L = Math.max(L, K + I.style.indentLeftPx + s.indentOf(I) + (I.style.indentRightPx ?? 0)), { kind: "para", block: I, lines: w };
4759
4772
  }
4760
- if (v.kind === "image")
4761
- return v.anchor ? { kind: "image", block: v, width: v.widthPx, height: v.heightPx } : (O = Math.max(O, v.widthPx + ce), { kind: "image", block: v, width: v.widthPx, height: v.heightPx });
4762
- if (v.kind === "equation") {
4763
- const y = We(v);
4764
- return O = Math.max(O, y.width + ce), { kind: "equation", block: v, box: y, width: y.width, height: y.ascent + y.descent };
4773
+ if (I.kind === "image")
4774
+ return I.anchor ? { kind: "image", block: I, width: I.widthPx, height: I.heightPx } : (L = Math.max(L, I.widthPx + ce), { kind: "image", block: I, width: I.widthPx, height: I.heightPx });
4775
+ if (I.kind === "equation") {
4776
+ const w = We(I);
4777
+ return L = Math.max(L, w.width + ce), { kind: "equation", block: I, box: w, width: w.width, height: w.ascent + w.descent };
4765
4778
  }
4766
- const H = Te(v, D, n, s);
4767
- return O = Math.max(O, H.tableWidth + ce), { kind: "table", block: v, ...H };
4779
+ const W = Te(I, b, n, s);
4780
+ return L = Math.max(L, W.tableWidth + ce), { kind: "table", block: I, ...W };
4768
4781
  });
4769
- return { cell: p, items: ee, height: O + w.top + w.bottom, width: L, colStart: W, rowSpan: m, rot: A };
4782
+ return { cell: p, items: J, height: L + H.top + H.bottom, width: D, colStart: R, rowSpan: N, rot: m };
4770
4783
  }
4771
- let C = 0;
4772
- const _ = p.blocks.map((O) => {
4773
- if (O.kind === "paragraph") {
4774
- const v = D - O.style.indentLeftPx - s.indentOf(O) - (O.style.indentRightPx ?? 0), H = n(O, Math.max(8, v));
4775
- return C += O.style.spaceBeforePx + Ee(H) + O.style.spaceAfterPx, { kind: "para", block: O, lines: H };
4784
+ let y = 0;
4785
+ const _ = p.blocks.map((L) => {
4786
+ if (L.kind === "paragraph") {
4787
+ const I = b - L.style.indentLeftPx - s.indentOf(L) - (L.style.indentRightPx ?? 0), W = n(L, Math.max(8, I));
4788
+ return y += L.style.spaceBeforePx + Ee(W) + L.style.spaceAfterPx, { kind: "para", block: L, lines: W };
4776
4789
  }
4777
- if (O.kind === "image") {
4778
- if (O.anchor) return { kind: "image", block: O, width: O.widthPx, height: O.heightPx };
4779
- const v = Math.min(1, D / Math.max(1, O.widthPx)), H = O.widthPx * v, y = O.heightPx * v;
4780
- return C += y + ce, { kind: "image", block: O, width: H, height: y };
4790
+ if (L.kind === "image") {
4791
+ if (L.anchor) return { kind: "image", block: L, width: L.widthPx, height: L.heightPx };
4792
+ const I = Math.min(1, b / Math.max(1, L.widthPx)), W = L.widthPx * I, w = L.heightPx * I;
4793
+ return y += w + ce, { kind: "image", block: L, width: W, height: w };
4781
4794
  }
4782
- if (O.kind === "equation") {
4783
- const v = We(O), H = v.ascent + v.descent;
4784
- return C += H + ce, { kind: "equation", block: O, box: v, width: v.width, height: H };
4795
+ if (L.kind === "equation") {
4796
+ const I = We(L), W = I.ascent + I.descent;
4797
+ return y += W + ce, { kind: "equation", block: L, box: I, width: I.width, height: W };
4785
4798
  }
4786
- const ee = Te(O, D, n, s);
4787
- return C += ee.height + ce, { kind: "table", block: O, ...ee };
4799
+ const J = Te(L, b, n, s);
4800
+ return y += J.height + ce, { kind: "table", block: L, ...J };
4788
4801
  });
4789
- return { cell: p, items: _, height: C + w.top + w.bottom, width: L, colStart: W, rowSpan: m };
4802
+ return { cell: p, items: _, height: y + H.top + H.bottom, width: D, colStart: R, rowSpan: N };
4790
4803
  });
4791
4804
  for (let p = 0; p < o; p++) x[p] > 0 && x[p]--;
4792
4805
  return { cells: E, height: 0 };
@@ -4798,9 +4811,9 @@ function Te(e, t, n, s) {
4798
4811
  for (const E of h.cells) {
4799
4812
  if (E.rowSpan <= 1) continue;
4800
4813
  const p = Math.min(l.length - 1, u + E.rowSpan - 1);
4801
- let S = 0;
4802
- for (let m = u; m <= p; m++) S += d[m];
4803
- E.height > S && (d[p] += E.height - S);
4814
+ let A = 0;
4815
+ for (let N = u; N <= p; N++) A += d[N];
4816
+ E.height > A && (d[p] += E.height - A);
4804
4817
  }
4805
4818
  }), l.forEach((h, u) => h.height = d[u]);
4806
4819
  const c = i === "fixed" && !e.preferredWidth ? t : r.reduce((h, u) => h + u, 0), a = io(e.align, t, c) + (e.indentPx ?? 0);
@@ -4827,136 +4840,136 @@ function Ke(e, t, n, s, i, r, o, x) {
4827
4840
  for (const u of t) d.push(d[d.length - 1] + u.height);
4828
4841
  const c = l[l.length - 1] ?? 0, a = [];
4829
4842
  for (let u = 0; u < t.length; u++) {
4830
- const E = t[u], p = d[u], S = [];
4831
- for (const m of E.cells) {
4832
- const W = l[m.colStart] ?? l[l.length - 1], L = s + (e.bidiVisual ? c - W - m.width : W), w = Math.min(t.length - 1, u + m.rowSpan - 1), D = d[w + 1] - p, A = [], C = Rt(m.cell), _ = m.width - C.left - C.right;
4833
- if (m.rot) {
4834
- const y = D - C.top - C.bottom, $ = so(m.rot), B = m.rot === "cw" ? L + C.left + _ : L + C.left, P = m.rot === "cw" ? p + C.top : p + C.top + y;
4843
+ const E = t[u], p = d[u], A = [];
4844
+ for (const N of E.cells) {
4845
+ const R = l[N.colStart] ?? l[l.length - 1], D = s + (e.bidiVisual ? c - R - N.width : R), H = Math.min(t.length - 1, u + N.rowSpan - 1), b = d[H + 1] - p, m = [], y = Rt(N.cell), _ = N.width - y.left - y.right;
4846
+ if (N.rot) {
4847
+ const w = b - y.top - y.bottom, K = so(N.rot), B = N.rot === "cw" ? D + y.left + _ : D + y.left, O = N.rot === "cw" ? p + y.top : p + y.top + w;
4835
4848
  let U = 0;
4836
- for (const I of m.items)
4837
- if (I.kind === "para") {
4838
- U += I.block.style.spaceBeforePx;
4839
- const Y = I.block.style.indentLeftPx + x.indentOf(I.block), K = { blockId: I.block.id, x: Y, y: U, firstLineIndex: 0, lines: I.lines }, q = x.markers.get(I.block.id);
4840
- q && (K.marker = { text: q.text, style: q.style, x: Math.max(0, Y - q.hangingPx) });
4849
+ for (const P of N.items)
4850
+ if (P.kind === "para") {
4851
+ U += P.block.style.spaceBeforePx;
4852
+ const Q = P.block.style.indentLeftPx + x.indentOf(P.block), q = { blockId: P.block.id, x: Q, y: U, firstLineIndex: 0, lines: P.lines }, $ = x.markers.get(P.block.id);
4853
+ $ && (q.marker = { text: $.text, style: $.style, x: Math.max(0, Q - $.hangingPx) });
4841
4854
  const T = we(
4842
- I.block.style,
4843
- y - I.block.style.indentLeftPx - x.indentOf(I.block) - (I.block.style.indentRightPx ?? 0),
4844
- Ee(I.lines)
4855
+ P.block.style,
4856
+ w - P.block.style.indentLeftPx - x.indentOf(P.block) - (P.block.style.indentRightPx ?? 0),
4857
+ Ee(P.lines)
4845
4858
  );
4846
- T && (K.paraDecor = T), A.push(K), U += Ee(I.lines) + I.block.style.spaceAfterPx;
4847
- } else if (I.kind === "image") {
4848
- const Y = I.block.anchor;
4849
- if (Y) {
4850
- const K = { src: I.block.src, width: I.block.widthPx, height: I.block.heightPx, z: Y.z ?? 0 };
4851
- Y.behind ? K.behind = !0 : K.front = !0, A.push({ blockId: I.block.id, x: Y.offsetXPx, y: Y.offsetYPx, firstLineIndex: 0, lines: [], image: K });
4859
+ T && (q.paraDecor = T), m.push(q), U += Ee(P.lines) + P.block.style.spaceAfterPx;
4860
+ } else if (P.kind === "image") {
4861
+ const Q = P.block.anchor;
4862
+ if (Q) {
4863
+ const q = { src: P.block.src, width: P.block.widthPx, height: P.block.heightPx, z: Q.z ?? 0 };
4864
+ Q.behind ? q.behind = !0 : q.front = !0, m.push({ blockId: P.block.id, x: Q.offsetXPx, y: Q.offsetYPx, firstLineIndex: 0, lines: [], image: q });
4852
4865
  continue;
4853
4866
  }
4854
- A.push({ blockId: I.block.id, x: 0, y: U, firstLineIndex: 0, lines: [], image: { src: I.block.src, width: I.width, height: I.height } }), U += I.height + ce;
4855
- } else I.kind === "equation" ? (A.push({ blockId: I.block.id, x: 0, y: U, firstLineIndex: 0, lines: [], equation: { box: I.box, width: I.width, height: I.height, baseline: I.box.ascent } }), U += I.height + ce) : (A.push(Ke(I.block, I.rows, I.colWidths, I.xOffset, U, I.tableWidth, 0, x)), U += I.height + ce);
4856
- S.push({
4857
- x: L,
4867
+ m.push({ blockId: P.block.id, x: 0, y: U, firstLineIndex: 0, lines: [], image: { src: P.block.src, width: P.width, height: P.height } }), U += P.height + ce;
4868
+ } else P.kind === "equation" ? (m.push({ blockId: P.block.id, x: 0, y: U, firstLineIndex: 0, lines: [], equation: { box: P.box, width: P.width, height: P.height, baseline: P.box.ascent } }), U += P.height + ce) : (m.push(Ke(P.block, P.rows, P.colWidths, P.xOffset, U, P.tableWidth, 0, x)), U += P.height + ce);
4869
+ A.push({
4870
+ x: D,
4858
4871
  y: p,
4859
- width: m.width,
4860
- height: D,
4872
+ width: N.width,
4873
+ height: b,
4861
4874
  originRow: o + u,
4862
- originCol: m.colStart,
4863
- blocks: A,
4864
- ...m.cell.shading !== void 0 ? { shading: m.cell.shading } : {},
4865
- ...m.cell.borders !== void 0 ? { borders: m.cell.borders } : {},
4866
- contentClip: { x: L + C.left, y: p, width: _, height: D },
4867
- rotation: { angle: $, originX: B, originY: P }
4875
+ originCol: N.colStart,
4876
+ blocks: m,
4877
+ ...N.cell.shading !== void 0 ? { shading: N.cell.shading } : {},
4878
+ ...N.cell.borders !== void 0 ? { borders: N.cell.borders } : {},
4879
+ contentClip: { x: D + y.left, y: p, width: _, height: b },
4880
+ rotation: { angle: K, originX: B, originY: O }
4868
4881
  });
4869
4882
  continue;
4870
4883
  }
4871
- const O = m.cell.vAlign, ee = O === "center" || O === "bottom" ? Math.max(0, D - m.height) : 0, v = O === "center" ? ee / 2 : O === "bottom" ? ee : 0;
4872
- let H = p + C.top + v;
4873
- for (const y of m.items)
4874
- if (y.kind === "para") {
4875
- H += y.block.style.spaceBeforePx;
4876
- const $ = L + C.left + y.block.style.indentLeftPx + x.indentOf(y.block), B = {
4877
- blockId: y.block.id,
4878
- x: $,
4879
- y: H,
4884
+ const L = N.cell.vAlign, J = L === "center" || L === "bottom" ? Math.max(0, b - N.height) : 0, I = L === "center" ? J / 2 : L === "bottom" ? J : 0;
4885
+ let W = p + y.top + I;
4886
+ for (const w of N.items)
4887
+ if (w.kind === "para") {
4888
+ W += w.block.style.spaceBeforePx;
4889
+ const K = D + y.left + w.block.style.indentLeftPx + x.indentOf(w.block), B = {
4890
+ blockId: w.block.id,
4891
+ x: K,
4892
+ y: W,
4880
4893
  firstLineIndex: 0,
4881
- lines: y.lines
4894
+ lines: w.lines
4882
4895
  // line.y is already block-relative; coords stay consistent
4883
- }, P = x.markers.get(y.block.id);
4884
- P && (B.marker = { text: P.text, style: P.style, x: Math.max(L + 1, $ - P.hangingPx) });
4896
+ }, O = x.markers.get(w.block.id);
4897
+ O && (B.marker = { text: O.text, style: O.style, x: Math.max(D + 1, K - O.hangingPx) });
4885
4898
  const U = we(
4886
- y.block.style,
4887
- _ - y.block.style.indentLeftPx - x.indentOf(y.block) - (y.block.style.indentRightPx ?? 0),
4888
- Ee(y.lines)
4899
+ w.block.style,
4900
+ _ - w.block.style.indentLeftPx - x.indentOf(w.block) - (w.block.style.indentRightPx ?? 0),
4901
+ Ee(w.lines)
4889
4902
  );
4890
- U && (B.paraDecor = U), A.push(B), H += Ee(y.lines) + y.block.style.spaceAfterPx;
4891
- } else if (y.kind === "image") {
4892
- const $ = y.block.anchor;
4893
- if ($) {
4894
- const P = {
4895
- src: y.block.src,
4896
- width: y.block.widthPx,
4897
- height: y.block.heightPx,
4898
- z: $.z ?? 0
4903
+ U && (B.paraDecor = U), m.push(B), W += Ee(w.lines) + w.block.style.spaceAfterPx;
4904
+ } else if (w.kind === "image") {
4905
+ const K = w.block.anchor;
4906
+ if (K) {
4907
+ const O = {
4908
+ src: w.block.src,
4909
+ width: w.block.widthPx,
4910
+ height: w.block.heightPx,
4911
+ z: K.z ?? 0
4899
4912
  };
4900
- $.behind ? P.behind = !0 : P.front = !0, A.push({
4901
- blockId: y.block.id,
4902
- x: L + C.left + $.offsetXPx,
4903
- y: p + C.top + $.offsetYPx,
4913
+ K.behind ? O.behind = !0 : O.front = !0, m.push({
4914
+ blockId: w.block.id,
4915
+ x: D + y.left + K.offsetXPx,
4916
+ y: p + y.top + K.offsetYPx,
4904
4917
  firstLineIndex: 0,
4905
4918
  lines: [],
4906
- image: P
4919
+ image: O
4907
4920
  });
4908
4921
  continue;
4909
4922
  }
4910
- const B = D - C.top - C.bottom;
4911
- if (m.items.length === 1 && B > y.height + 8) {
4912
- const P = Math.max(_ / y.block.widthPx, B / y.block.heightPx), U = y.block.widthPx * P, I = y.block.heightPx * P, Y = L + C.left, K = p + C.top;
4913
- A.push({
4914
- blockId: y.block.id,
4915
- x: Y + (_ - U) / 2,
4916
- y: K + (B - I) / 2,
4923
+ const B = b - y.top - y.bottom;
4924
+ if (N.items.length === 1 && B > w.height + 8) {
4925
+ const O = Math.max(_ / w.block.widthPx, B / w.block.heightPx), U = w.block.widthPx * O, P = w.block.heightPx * O, Q = D + y.left, q = p + y.top;
4926
+ m.push({
4927
+ blockId: w.block.id,
4928
+ x: Q + (_ - U) / 2,
4929
+ y: q + (B - P) / 2,
4917
4930
  firstLineIndex: 0,
4918
4931
  lines: [],
4919
- image: { src: y.block.src, width: U, height: I, clip: { x: Y, y: K, width: _, height: B } }
4920
- }), H += y.height + ce;
4932
+ image: { src: w.block.src, width: U, height: P, clip: { x: Q, y: q, width: _, height: B } }
4933
+ }), W += w.height + ce;
4921
4934
  } else {
4922
- const P = _ - y.width, U = L + C.left + (y.block.align === "center" ? P / 2 : y.block.align === "right" ? P : 0);
4923
- A.push({
4924
- blockId: y.block.id,
4935
+ const O = _ - w.width, U = D + y.left + (w.block.align === "center" ? O / 2 : w.block.align === "right" ? O : 0);
4936
+ m.push({
4937
+ blockId: w.block.id,
4925
4938
  x: U,
4926
- y: H,
4939
+ y: W,
4927
4940
  firstLineIndex: 0,
4928
4941
  lines: [],
4929
- image: { src: y.block.src, width: y.width, height: y.height }
4930
- }), H += y.height + ce;
4942
+ image: { src: w.block.src, width: w.width, height: w.height }
4943
+ }), W += w.height + ce;
4931
4944
  }
4932
- } else if (y.kind === "equation") {
4933
- const $ = y.block.align ?? "center", B = _ - y.width, P = L + C.left + ($ === "center" ? B / 2 : $ === "right" ? B : 0);
4934
- A.push({
4935
- blockId: y.block.id,
4936
- x: P,
4937
- y: H,
4945
+ } else if (w.kind === "equation") {
4946
+ const K = w.block.align ?? "center", B = _ - w.width, O = D + y.left + (K === "center" ? B / 2 : K === "right" ? B : 0);
4947
+ m.push({
4948
+ blockId: w.block.id,
4949
+ x: O,
4950
+ y: W,
4938
4951
  firstLineIndex: 0,
4939
4952
  lines: [],
4940
- equation: { box: y.box, width: y.width, height: y.height, baseline: y.box.ascent }
4941
- }), H += y.height + ce;
4953
+ equation: { box: w.box, width: w.width, height: w.height, baseline: w.box.ascent }
4954
+ }), W += w.height + ce;
4942
4955
  } else
4943
- A.push(Ke(y.block, y.rows, y.colWidths, L + C.left + y.xOffset, H, y.tableWidth, 0, x)), H += y.height + ce;
4944
- S.push({
4945
- x: L,
4956
+ m.push(Ke(w.block, w.rows, w.colWidths, D + y.left + w.xOffset, W, w.tableWidth, 0, x)), W += w.height + ce;
4957
+ A.push({
4958
+ x: D,
4946
4959
  y: p,
4947
- width: m.width,
4948
- height: D,
4960
+ width: N.width,
4961
+ height: b,
4949
4962
  originRow: o + u,
4950
- originCol: m.colStart,
4951
- blocks: A,
4952
- ...m.cell.shading !== void 0 ? { shading: m.cell.shading } : {},
4953
- ...m.cell.borders !== void 0 ? { borders: m.cell.borders } : {},
4963
+ originCol: N.colStart,
4964
+ blocks: m,
4965
+ ...N.cell.shading !== void 0 ? { shading: N.cell.shading } : {},
4966
+ ...N.cell.borders !== void 0 ? { borders: N.cell.borders } : {},
4954
4967
  // Horizontal content band (full cell height): clips over-wide text to the
4955
4968
  // inner box so it never paints onto the border or into the next column.
4956
- contentClip: { x: L + C.left, y: p, width: _, height: D }
4969
+ contentClip: { x: D + y.left, y: p, width: _, height: b }
4957
4970
  });
4958
4971
  }
4959
- a.push({ y: p, height: E.height, cells: S });
4972
+ a.push({ y: p, height: E.height, cells: A });
4960
4973
  }
4961
4974
  const h = t.reduce((u, E) => u + E.height, 0);
4962
4975
  return {
@@ -4969,7 +4982,7 @@ function Ke(e, t, n, s, i, r, o, x) {
4969
4982
  table: { x: s, y: i, width: r, height: h, rows: a, colWidths: n, ...e.bidiVisual ? { bidiVisual: !0 } : {} }
4970
4983
  };
4971
4984
  }
4972
- const fo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4985
+ const xo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4973
4986
  __proto__: null,
4974
4987
  createLayoutEngine: T0,
4975
4988
  effectiveSection: xs,
@@ -4983,7 +4996,7 @@ function oo(e) {
4983
4996
  for (const s of e.pages) n(s.blocks, s.number);
4984
4997
  return t;
4985
4998
  }
4986
- function uo(e, t) {
4999
+ function fo(e, t) {
4987
5000
  const n = oo(t), s = [];
4988
5001
  for (const i of e.blocks) {
4989
5002
  if (i.kind !== "paragraph") continue;
@@ -5007,8 +5020,8 @@ function uo(e, t) {
5007
5020
  return s;
5008
5021
  }
5009
5022
  export {
5010
- uo as a,
5011
- fo as b,
5023
+ fo as a,
5024
+ xo as b,
5012
5025
  T0 as c,
5013
5026
  Ot as e,
5014
5027
  oo as p