@forevka/wordcanvas 0.7.1 → 0.7.3

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 (64) hide show
  1. package/dist-lib/assets/{worker-D8rUOKfg.js → worker-CqU4Popa.js} +10903 -10736
  2. package/dist-lib/assets/worker-Cw5cYW5z.js +2418 -0
  3. package/dist-lib/blockFactory-DDCRWDnA.js +91 -0
  4. package/dist-lib/browser-BUrsjziD.js +612 -0
  5. package/dist-lib/builder.js +13 -13
  6. package/dist-lib/editorApp-CB_ZArIF.js +9566 -0
  7. package/dist-lib/export.js +4507 -4456
  8. package/dist-lib/generate-toc.js +7 -7
  9. package/dist-lib/import.js +2 -2
  10. package/dist-lib/lists-DpmgbDyt.js +110 -0
  11. package/dist-lib/measure.js +2 -2
  12. package/dist-lib/{measureHost-CMiJKdlk.js → measureHost-BlukHGwx.js} +1 -1
  13. package/dist-lib/metrics-bvGO8KDK.js +96 -0
  14. package/dist-lib/paintStyle-vT6jtWbH.js +74 -0
  15. package/dist-lib/pipeline-UryP-u7Z.js +1850 -0
  16. package/dist-lib/recalc-docx.js +2 -2
  17. package/dist-lib/recalcToc-BfXlXZik.js +3985 -0
  18. package/dist-lib/styleProps-DhqDEfvc.js +149 -0
  19. package/dist-lib/stylesheet-LTBEGkvG.js +146 -0
  20. package/dist-lib/toc-D09f4PrI.js +939 -0
  21. package/dist-lib/{webmcp-6WxRNKCc.js → webmcp-K6UZgQJ0.js} +60 -68
  22. package/dist-lib/wordcanvas-DBx2ana_.js +734 -0
  23. package/dist-lib/wordcanvas.js +4 -2
  24. package/dist-node/{chunk-CDN6WU2P.js → chunk-373K2XRY.js} +40 -22
  25. package/dist-node/chunk-373K2XRY.js.map +7 -0
  26. package/dist-node/{chunk-22JHAERT.js → chunk-3PUV3BG6.js} +235 -39
  27. package/dist-node/chunk-3PUV3BG6.js.map +7 -0
  28. package/dist-node/{chunk-4ICCHZX4.js → chunk-5RX3IHWE.js} +39 -3
  29. package/dist-node/chunk-5RX3IHWE.js.map +7 -0
  30. package/dist-node/{chunk-4PDVRJF6.js → chunk-EMY2P524.js} +32 -2
  31. package/dist-node/chunk-EMY2P524.js.map +7 -0
  32. package/dist-node/{chunk-BRAPV465.js → chunk-HWQKGDS2.js} +2 -2
  33. package/dist-node/{chunk-6AJJMHKY.js → chunk-KJV7GJ3H.js} +1 -1
  34. package/dist-node/chunk-KJV7GJ3H.js.map +7 -0
  35. package/dist-node/{chunk-RNB336F3.js → chunk-ZLLSXOO2.js} +92 -14
  36. package/dist-node/{chunk-RNB336F3.js.map → chunk-ZLLSXOO2.js.map} +2 -2
  37. package/dist-node/{engine-5FGDJD2H.js → engine-LLA6PCS5.js} +4 -4
  38. package/dist-node/export.js +89 -24
  39. package/dist-node/export.js.map +2 -2
  40. package/dist-node/generate-toc.js +6 -6
  41. package/dist-node/import.js +3 -3
  42. package/dist-node/measure.js +2 -2
  43. package/dist-node/recalc-docx.js +4 -4
  44. package/package.json +1 -1
  45. package/types/model.d.ts +46 -0
  46. package/types/wordcanvas.d.ts +493 -1
  47. package/dist-lib/assets/worker-wXuuyshQ.js +0 -2258
  48. package/dist-lib/blockFactory-CUI4Rqiq.js +0 -186
  49. package/dist-lib/browser-DkKxreJM.js +0 -1305
  50. package/dist-lib/editorApp-DLXMmtu5.js +0 -8023
  51. package/dist-lib/lists-Sc5I40JO.js +0 -110
  52. package/dist-lib/metrics-CkAo4zh8.js +0 -143
  53. package/dist-lib/pipeline-CbxmCE84.js +0 -1705
  54. package/dist-lib/recalcToc-g1hFKSNs.js +0 -3935
  55. package/dist-lib/styleProps-Db5pEkG8.js +0 -127
  56. package/dist-lib/toc-B6VpkJge.js +0 -213
  57. package/dist-lib/wordcanvas-CFqpDK0k.js +0 -125
  58. package/dist-node/chunk-22JHAERT.js.map +0 -7
  59. package/dist-node/chunk-4ICCHZX4.js.map +0 -7
  60. package/dist-node/chunk-4PDVRJF6.js.map +0 -7
  61. package/dist-node/chunk-6AJJMHKY.js.map +0 -7
  62. package/dist-node/chunk-CDN6WU2P.js.map +0 -7
  63. /package/dist-node/{chunk-BRAPV465.js.map → chunk-HWQKGDS2.js.map} +0 -0
  64. /package/dist-node/{engine-5FGDJD2H.js.map → engine-LLA6PCS5.js.map} +0 -0
@@ -0,0 +1,939 @@
1
+ const N = [
2
+ "header",
3
+ "footer",
4
+ "headerFirst",
5
+ "headerEven",
6
+ "footerFirst",
7
+ "footerEven"
8
+ ], U = new Intl.Segmenter(void 0, { granularity: "grapheme" }), Y = new Intl.Segmenter(void 0, { granularity: "word" }), ye = (t) => t.runs.some((e) => e.text.length > 0) && t.runs.every((e) => e.text.length === 0 || e.style.hidden === !0), A = (t, e) => {
9
+ const n = [];
10
+ for (const s of t)
11
+ if (s.kind === "paragraph") n.push(s);
12
+ else if (s.kind === "table" && e)
13
+ for (const o of s.rows)
14
+ for (const r of o.cells) n.push(...A(r.blocks, e));
15
+ return n;
16
+ }, Z = (t, e) => A(t.section[e] ?? [], !0), ee = (t) => A(t.blocks, !0), J = (t) => [
17
+ ...A(t.blocks, !0),
18
+ ...N.flatMap((e) => Z(t, e)),
19
+ ...Object.values(t.footnotes ?? {}).flat()
20
+ ], te = (t, e) => J(t).find((n) => n.id === e), xe = (t, e) => J(t).findIndex((n) => n.id === e), H = (t, e) => {
21
+ for (const n of t)
22
+ if (e.add(n.id), n.kind === "table")
23
+ for (const s of n.rows) for (const o of s.cells) H(o.blocks, e);
24
+ }, we = (t, e) => {
25
+ const n = /* @__PURE__ */ new Set();
26
+ H(t.blocks, n);
27
+ for (const s of N) H(t.section[s] ?? [], n);
28
+ for (const s of Object.values(t.footnotes ?? {})) for (const o of s) n.add(o.id);
29
+ return n.has(e);
30
+ }, K = (t, e) => e === "body" ? t.blocks : t.section[e] ?? [];
31
+ function _(t, e, n) {
32
+ for (let s = 0; s < t.length; s++) {
33
+ const o = t[s];
34
+ if (o.kind === "paragraph") {
35
+ if (o.id === n)
36
+ return e === "body" ? { kind: "top", bi: s } : { kind: "band", band: e, bi: s };
37
+ } else if (o.kind === "table")
38
+ for (let r = 0; r < o.rows.length; r++) {
39
+ const i = o.rows[r];
40
+ for (let c = 0; c < i.cells.length; c++) {
41
+ const l = i.cells[c];
42
+ for (let a = 0; a < l.blocks.length; a++) {
43
+ const d = l.blocks[a];
44
+ if (d.kind === "paragraph" && d.id === n)
45
+ return { kind: "cell", where: e, bi: s, ri: r, ci: c, pi: a };
46
+ }
47
+ }
48
+ }
49
+ }
50
+ return null;
51
+ }
52
+ function C(t, e) {
53
+ const n = _(t.blocks, "body", e);
54
+ if (n) return n;
55
+ for (const s of N) {
56
+ const o = _(t.section[s] ?? [], s, e);
57
+ if (o) return o;
58
+ }
59
+ for (const [s, o] of Object.entries(t.footnotes ?? {})) {
60
+ const r = o.findIndex((i) => i.id === e);
61
+ if (r >= 0) return { kind: "footnote", noteId: s, pi: r };
62
+ }
63
+ return null;
64
+ }
65
+ function M(t, e) {
66
+ return e.kind === "top" ? t.blocks[e.bi] : e.kind === "band" ? t.section[e.band][e.bi] : e.kind === "footnote" ? t.footnotes[e.noteId][e.pi] : K(t, e.where)[e.bi].rows[e.ri].cells[e.ci].blocks[e.pi];
67
+ }
68
+ function R(t, e, n) {
69
+ if (e.kind === "footnote") {
70
+ const l = t.footnotes[e.noteId].slice();
71
+ return l[e.pi] = n, { ...t, footnotes: { ...t.footnotes, [e.noteId]: l } };
72
+ }
73
+ if (e.kind === "band") {
74
+ const l = (t.section[e.band] ?? []).slice();
75
+ return l[e.bi] = n, { ...t, section: { ...t.section, [e.band]: l } };
76
+ }
77
+ if (e.kind === "top") {
78
+ const l = t.blocks.slice();
79
+ return l[e.bi] = n, { ...t, blocks: l };
80
+ }
81
+ const s = K(t, e.where).slice(), o = s[e.bi], r = o.rows.slice(), i = { cells: r[e.ri].cells.slice() }, c = { ...i.cells[e.ci], blocks: i.cells[e.ci].blocks.slice() };
82
+ return c.blocks[e.pi] = n, i.cells[e.ci] = c, r[e.ri] = i, s[e.bi] = { ...o, rows: r, revision: o.revision + 1 }, e.where === "body" ? { ...t, blocks: s } : { ...t, section: { ...t.section, [e.where]: s } };
83
+ }
84
+ const Pe = (t, e) => C(t, e)?.kind === "cell", F = (t) => t.map((e) => e.text).join(""), pe = (t, e) => {
85
+ const n = te(t, e);
86
+ return n ? F(n.runs) : "";
87
+ };
88
+ function ve(t, e) {
89
+ let n = 0;
90
+ for (const s of U.segment(t)) {
91
+ if (s.index >= e) break;
92
+ n = s.index;
93
+ }
94
+ return n;
95
+ }
96
+ function Se(t, e) {
97
+ for (const n of U.segment(t)) {
98
+ const s = n.index + n.segment.length;
99
+ if (s > e) return s;
100
+ }
101
+ return t.length;
102
+ }
103
+ function Be(t, e) {
104
+ let n = 0;
105
+ for (const s of Y.segment(t)) {
106
+ if (s.index >= e) break;
107
+ s.isWordLike && (n = s.index);
108
+ }
109
+ return n;
110
+ }
111
+ function Re(t, e) {
112
+ for (const n of Y.segment(t)) {
113
+ const s = n.index + n.segment.length;
114
+ if (n.isWordLike && s > e) return s;
115
+ }
116
+ return t.length;
117
+ }
118
+ function ne(t, e) {
119
+ let n = 0;
120
+ for (const s of t) {
121
+ const o = n + s.text.length;
122
+ if (e > n && e <= o && s.text.length > 0) return s.style;
123
+ n = o;
124
+ }
125
+ return t[0]?.style;
126
+ }
127
+ function se(t = {}) {
128
+ return {
129
+ fontFamily: t.fontFamily ?? "Georgia, serif",
130
+ fontSizePx: t.fontSizePx ?? 16,
131
+ bold: !1,
132
+ italic: !1,
133
+ underline: !1,
134
+ strikethrough: !1,
135
+ color: t.color ?? "#202124"
136
+ };
137
+ }
138
+ function oe(t = {}) {
139
+ return {
140
+ align: "left",
141
+ lineHeight: t.lineHeight ?? 1.5,
142
+ spaceBeforePx: 0,
143
+ spaceAfterPx: 12,
144
+ indentFirstLinePx: 0,
145
+ indentLeftPx: 0
146
+ };
147
+ }
148
+ const Q = se(), Te = oe();
149
+ function re(t, e) {
150
+ return t.fontFamily === e.fontFamily && t.fontSizePx === e.fontSizePx && t.bold === e.bold && t.italic === e.italic && t.underline === e.underline && t.strikethrough === e.strikethrough && t.color === e.color && !!t.hidden == !!e.hidden && // hidden runs must never merge with visible ones
151
+ (t.letterSpacingPx ?? 0) === (e.letterSpacingPx ?? 0) && t.highlightColor === e.highlightColor && t.verticalAlign === e.verticalAlign && t.link === e.link && t.footnoteRef === e.footnoteRef && // adjacent refs must never merge into one run
152
+ t.sdtId === e.sdtId && // content-control boundaries survive normalization
153
+ t.fieldId === e.fieldId;
154
+ }
155
+ function x(t, e) {
156
+ const n = t.filter((o) => o.text.length > 0);
157
+ if (n.length === 0) return [{ text: "", style: t[0]?.style ?? e }];
158
+ const s = [{ ...n[0] }];
159
+ for (let o = 1; o < n.length; o++) {
160
+ const r = n[o], i = s[s.length - 1];
161
+ re(i.style, r.style) ? i.text += r.text : s.push({ ...r });
162
+ }
163
+ return s;
164
+ }
165
+ function m(t, e) {
166
+ const n = [], s = [];
167
+ let o = 0;
168
+ for (const r of t) {
169
+ const i = o + r.text.length;
170
+ i <= e ? n.push(r) : o >= e ? s.push(r) : (n.push({ text: r.text.slice(0, e - o), style: r.style }), s.push({ text: r.text.slice(e - o), style: r.style })), o = i;
171
+ }
172
+ return [n, s];
173
+ }
174
+ function V(t, e, n) {
175
+ const [, s] = m(t, e), [o] = m(s, n - e);
176
+ return o;
177
+ }
178
+ function P(t, e) {
179
+ return ne(t, e) ?? { ...Q };
180
+ }
181
+ function ie(t, e, n, s) {
182
+ const o = s ?? P(t, e), [r, i] = m(t, e);
183
+ return x([...r, { text: n, style: o }, ...i], o);
184
+ }
185
+ function le(t, e, n) {
186
+ const [s, o] = m(t, e);
187
+ return x([...s, ...n, ...o], P(t, e));
188
+ }
189
+ function ce(t, e, n) {
190
+ const [s, o] = m(t, e), [, r] = m(o, n - e);
191
+ return x([...s, ...r], P(t, e));
192
+ }
193
+ function Fe(t, e, n, s) {
194
+ const [o, r] = m(t, e), [i, c] = m(r, n - e), l = i.map((a) => ({ text: a.text, style: { ...a.style, ...s } }));
195
+ return x([...o, ...l, ...c], P(t, e));
196
+ }
197
+ function Ee(t, e, n, s) {
198
+ const [o, r] = m(t, e), [i, c] = m(r, n - e), l = i.map((h) => h.text).join(""), a = s(l);
199
+ let d = 0;
200
+ const f = a.length === l.length ? i.map((h) => {
201
+ const u = a.slice(d, d + h.text.length);
202
+ return d += h.text.length, { text: u, style: h.style };
203
+ }) : i;
204
+ return x([...o, ...f, ...c], P(t, e));
205
+ }
206
+ const b = (t) => t;
207
+ function T(t, e) {
208
+ const n = C(t, e);
209
+ if (!n) throw new Error(`paragraph ${e} not found`);
210
+ return { loc: n, block: M(t, n) };
211
+ }
212
+ function k(t, e) {
213
+ return e === "body" ? t.blocks : t.section[e] ?? [];
214
+ }
215
+ function w(t, e, n) {
216
+ return e === "body" ? { ...t, blocks: n } : { ...t, section: { ...t.section, [e]: n } };
217
+ }
218
+ function W(t, e) {
219
+ for (const n of ["body", ...N]) {
220
+ const s = k(t, n).findIndex((o) => o.id === e);
221
+ if (s >= 0) return { where: n, index: s };
222
+ }
223
+ return null;
224
+ }
225
+ function I(t, e) {
226
+ const n = W(t, e), s = n ? k(t, n.where)[n.index] : void 0;
227
+ if (!n || !s || s.kind !== "table") throw new Error(`table ${e} not found`);
228
+ return { where: n.where, bi: n.index, block: s };
229
+ }
230
+ function y(t, e, n, s) {
231
+ const o = k(t, e).slice();
232
+ return o[n] = { ...s, revision: s.revision + 1 }, w(t, e, o);
233
+ }
234
+ function D(t, e, n, s, o, r) {
235
+ const i = k(t, e).slice(), c = i[n], l = c.rows.slice(), a = { cells: l[s].cells.slice() };
236
+ return a.cells[o] = { ...a.cells[o], blocks: r }, l[s] = a, i[n] = { ...c, rows: l, revision: c.revision + 1 }, w(t, e, i);
237
+ }
238
+ function O(t) {
239
+ for (const e of t)
240
+ for (const n of e.cells)
241
+ for (const s of n.blocks) if (s.kind === "paragraph") return s;
242
+ }
243
+ function ae(t, e) {
244
+ const n = W(t, e);
245
+ if (n) {
246
+ const s = k(t, n.where)[n.index];
247
+ return s?.kind === "image" ? { kind: "top", where: n.where, index: n.index, image: s } : null;
248
+ }
249
+ for (let s = 0; s < t.blocks.length; s++) {
250
+ const o = t.blocks[s];
251
+ if (o.kind === "table")
252
+ for (let r = 0; r < o.rows.length; r++) {
253
+ const i = o.rows[r];
254
+ for (let c = 0; c < i.cells.length; c++) {
255
+ const l = i.cells[c];
256
+ for (let a = 0; a < l.blocks.length; a++) {
257
+ const d = l.blocks[a];
258
+ if (d.kind === "image" && d.id === e) return { kind: "cell", bi: s, ri: r, ci: c, ii: a, image: d };
259
+ }
260
+ }
261
+ }
262
+ }
263
+ return null;
264
+ }
265
+ function de(t) {
266
+ let e = 1;
267
+ const n = [];
268
+ for (const s of t.rows) {
269
+ let o = 0;
270
+ for (const r of s.cells) {
271
+ for (; (n[o] ?? 0) > 0; ) o++;
272
+ const i = Math.max(1, r.colSpan ?? 1), c = Math.max(1, r.rowSpan ?? 1);
273
+ if (c > 1) for (let l = 0; l < i; l++) n[o + l] = c;
274
+ o += i;
275
+ }
276
+ e = Math.max(e, o);
277
+ for (let r = 0; r < n.length; r++) n[r] > 0 && n[r]--;
278
+ }
279
+ return e;
280
+ }
281
+ function $(t) {
282
+ const e = de(t);
283
+ return t.colFractions && t.colFractions.length === e ? t.colFractions : Array.from({ length: e }, () => 1 / e);
284
+ }
285
+ function v(t, e) {
286
+ return { ...t, runs: e, revision: t.revision + 1 };
287
+ }
288
+ function Oe(t, e) {
289
+ switch (e.type) {
290
+ case "insertText": {
291
+ const { loc: n, block: s } = T(t, e.at.blockId), o = ie(s.runs, e.at.offset, e.text, e.style), r = e.text.length;
292
+ return {
293
+ doc: R(t, n, v(s, o)),
294
+ inverse: { type: "deleteRange", blockId: s.id, start: e.at.offset, end: e.at.offset + r },
295
+ mapPosition: (i) => i.blockId === s.id && i.offset >= e.at.offset ? { blockId: i.blockId, offset: i.offset + r } : i,
296
+ dirtyBlockIds: [s.id]
297
+ };
298
+ }
299
+ case "insertRuns": {
300
+ const { loc: n, block: s } = T(t, e.at.blockId), o = F(e.runs).length, r = le(s.runs, e.at.offset, e.runs);
301
+ return {
302
+ doc: R(t, n, v(s, r)),
303
+ inverse: { type: "deleteRange", blockId: s.id, start: e.at.offset, end: e.at.offset + o },
304
+ mapPosition: (i) => i.blockId === s.id && i.offset >= e.at.offset ? { blockId: i.blockId, offset: i.offset + o } : i,
305
+ dirtyBlockIds: [s.id]
306
+ };
307
+ }
308
+ case "deleteRange": {
309
+ const { loc: n, block: s } = T(t, e.blockId), o = V(s.runs, e.start, e.end), r = ce(s.runs, e.start, e.end), i = e.end - e.start;
310
+ return {
311
+ doc: R(t, n, v(s, r)),
312
+ inverse: { type: "insertRuns", at: { blockId: s.id, offset: e.start }, runs: o },
313
+ mapPosition: (c) => c.blockId !== s.id || c.offset <= e.start ? c : { blockId: c.blockId, offset: c.offset >= e.end ? c.offset - i : e.start },
314
+ dirtyBlockIds: [s.id]
315
+ };
316
+ }
317
+ case "setRuns": {
318
+ const { loc: n, block: s } = T(t, e.blockId);
319
+ return {
320
+ doc: R(t, n, v(s, e.runs)),
321
+ inverse: { type: "setRuns", blockId: s.id, runs: s.runs },
322
+ mapPosition: b,
323
+ // callers use setRuns for length-preserving restyles
324
+ dirtyBlockIds: [s.id]
325
+ };
326
+ }
327
+ case "setParaStyle": {
328
+ const { loc: n, block: s } = T(t, e.blockId), o = {};
329
+ for (const i of Object.keys(e.patch))
330
+ o[i] = s.style[i];
331
+ const r = {
332
+ ...s,
333
+ style: { ...s.style, ...e.patch },
334
+ revision: s.revision + 1
335
+ };
336
+ return {
337
+ doc: R(t, n, r),
338
+ inverse: { type: "setParaStyle", blockId: s.id, patch: o },
339
+ mapPosition: b,
340
+ dirtyBlockIds: [s.id]
341
+ };
342
+ }
343
+ case "splitParagraph": {
344
+ const n = C(t, e.at.blockId);
345
+ if (!n) throw new Error(`paragraph ${e.at.blockId} not found`);
346
+ const s = M(t, n), [o, r] = m(s.runs, e.at.offset), i = P(s.runs, e.at.offset), c = v(s, x(o, i)), l = {
347
+ kind: "paragraph",
348
+ id: e.newBlockId,
349
+ revision: 0,
350
+ runs: x(r, i),
351
+ style: e.newStyle ?? { ...s.style }
352
+ };
353
+ let a;
354
+ if (n.kind === "cell") {
355
+ const f = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks.slice();
356
+ f.splice(n.pi, 1, c, l), a = D(t, n.where, n.bi, n.ri, n.ci, f);
357
+ } else if (n.kind === "footnote") {
358
+ const d = t.footnotes[n.noteId].slice();
359
+ d.splice(n.pi, 1, c, l), a = { ...t, footnotes: { ...t.footnotes, [n.noteId]: d } };
360
+ } else {
361
+ const d = n.kind === "band" ? n.band : "body", f = k(t, d).slice();
362
+ f.splice(n.bi, 1, c, l), a = w(t, d, f);
363
+ }
364
+ return {
365
+ doc: a,
366
+ inverse: { type: "mergeParagraphs", firstBlockId: s.id },
367
+ mapPosition: (d) => d.blockId === s.id && d.offset >= e.at.offset ? { blockId: e.newBlockId, offset: d.offset - e.at.offset } : d,
368
+ dirtyBlockIds: [s.id, e.newBlockId]
369
+ };
370
+ }
371
+ case "mergeParagraphs": {
372
+ const n = C(t, e.firstBlockId);
373
+ if (!n) throw new Error(`paragraph ${e.firstBlockId} not found`);
374
+ const s = M(t, n);
375
+ let o;
376
+ if (n.kind === "cell") {
377
+ const a = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks[n.pi + 1];
378
+ if (!a || a.kind !== "paragraph")
379
+ throw new Error("mergeParagraphs: no next paragraph in cell");
380
+ o = a;
381
+ } else if (n.kind === "footnote") {
382
+ const l = t.footnotes[n.noteId][n.pi + 1];
383
+ if (!l) throw new Error("mergeParagraphs: no next paragraph in footnote");
384
+ o = l;
385
+ } else {
386
+ const l = n.kind === "band" ? n.band : "body", a = k(t, l)[n.bi + 1];
387
+ if (!a || a.kind !== "paragraph")
388
+ throw new Error("mergeParagraphs: no next paragraph");
389
+ o = a;
390
+ }
391
+ const r = F(s.runs).length, i = v(
392
+ s,
393
+ x([...s.runs, ...o.runs], P(s.runs, r))
394
+ );
395
+ let c;
396
+ if (n.kind === "cell") {
397
+ const a = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks.slice();
398
+ a.splice(n.pi, 2, i), c = D(t, n.where, n.bi, n.ri, n.ci, a);
399
+ } else if (n.kind === "footnote") {
400
+ const l = t.footnotes[n.noteId].slice();
401
+ l.splice(n.pi, 2, i), c = { ...t, footnotes: { ...t.footnotes, [n.noteId]: l } };
402
+ } else {
403
+ const l = n.kind === "band" ? n.band : "body", a = k(t, l).slice();
404
+ a.splice(n.bi, 2, i), c = w(t, l, a);
405
+ }
406
+ return {
407
+ doc: c,
408
+ inverse: {
409
+ type: "splitParagraph",
410
+ at: { blockId: s.id, offset: r },
411
+ newBlockId: o.id,
412
+ newStyle: o.style
413
+ },
414
+ mapPosition: (l) => l.blockId === o.id ? { blockId: s.id, offset: r + l.offset } : l,
415
+ dirtyBlockIds: [s.id, o.id]
416
+ };
417
+ }
418
+ case "insertBlock": {
419
+ const n = e.where ?? "body", s = k(t, n).slice();
420
+ return s.splice(e.index, 0, e.block), {
421
+ doc: w(t, n, s),
422
+ inverse: { type: "removeBlock", blockId: e.block.id },
423
+ mapPosition: b,
424
+ dirtyBlockIds: [e.block.id]
425
+ };
426
+ }
427
+ case "removeBlock": {
428
+ const n = W(t, e.blockId);
429
+ if (!n) throw new Error(`block ${e.blockId} not found`);
430
+ const s = k(t, n.where).slice(), o = s[n.index];
431
+ s.splice(n.index, 1);
432
+ const r = s[Math.min(n.index, s.length - 1)];
433
+ return {
434
+ doc: w(t, n.where, s),
435
+ inverse: { type: "insertBlock", index: n.index, block: o, where: n.where },
436
+ mapPosition: (i) => i.blockId === e.blockId && r ? { blockId: r.id, offset: 0 } : i,
437
+ dirtyBlockIds: [e.blockId]
438
+ };
439
+ }
440
+ case "setImageProps": {
441
+ const n = ae(t, e.blockId);
442
+ if (!n) throw new Error(`image ${e.blockId} not found`);
443
+ const s = n.image, o = {};
444
+ e.patch.widthPx !== void 0 && (o.widthPx = s.widthPx), e.patch.heightPx !== void 0 && (o.heightPx = s.heightPx), e.patch.align !== void 0 && (o.align = s.align), e.patch.wrap !== void 0 && (o.wrap = s.wrap ?? null), e.patch.anchor !== void 0 && (o.anchor = s.anchor ?? null);
445
+ const r = { ...s, revision: s.revision + 1 };
446
+ e.patch.widthPx !== void 0 && (r.widthPx = e.patch.widthPx), e.patch.heightPx !== void 0 && (r.heightPx = e.patch.heightPx), e.patch.align !== void 0 && (r.align = e.patch.align), e.patch.wrap !== void 0 && (e.patch.wrap === null ? delete r.wrap : r.wrap = e.patch.wrap), e.patch.anchor !== void 0 && (e.patch.anchor === null ? delete r.anchor : r.anchor = e.patch.anchor);
447
+ let i;
448
+ if (n.kind === "top") {
449
+ const c = k(t, n.where).slice();
450
+ c[n.index] = r, i = w(t, n.where, c);
451
+ } else {
452
+ const l = t.blocks[n.bi].rows[n.ri].cells[n.ci].blocks.slice();
453
+ l[n.ii] = r, i = D(t, "body", n.bi, n.ri, n.ci, l);
454
+ }
455
+ return {
456
+ doc: i,
457
+ inverse: { type: "setImageProps", blockId: e.blockId, patch: o },
458
+ mapPosition: b,
459
+ dirtyBlockIds: [e.blockId]
460
+ };
461
+ }
462
+ case "setTableColFractions": {
463
+ const { where: n, bi: s, block: o } = I(t, e.blockId), r = $(o);
464
+ return {
465
+ doc: y(t, n, s, { ...o, colFractions: e.fractions }),
466
+ inverse: { type: "setTableColFractions", blockId: e.blockId, fractions: r },
467
+ mapPosition: b,
468
+ dirtyBlockIds: [e.blockId]
469
+ };
470
+ }
471
+ case "setTableRow": {
472
+ const { where: n, bi: s, block: o } = I(t, e.tableId), r = o.rows[e.rowIndex];
473
+ if (!r) throw new Error("setTableRow: no such row");
474
+ const i = new Set(r.cells.flatMap((a) => a.blocks.map((d) => d.id))), c = o.rows.slice();
475
+ c[e.rowIndex] = e.row;
476
+ const l = O([e.row]);
477
+ return {
478
+ doc: y(t, n, s, { ...o, rows: c }),
479
+ inverse: { type: "setTableRow", tableId: e.tableId, rowIndex: e.rowIndex, row: r },
480
+ mapPosition: (a) => i.has(a.blockId) ? e.row.cells.some((f) => f.blocks.some((h) => h.id === a.blockId)) || !l ? a : { blockId: l.id, offset: 0 } : a,
481
+ dirtyBlockIds: [e.tableId]
482
+ };
483
+ }
484
+ case "insertTableRow": {
485
+ const { where: n, bi: s, block: o } = I(t, e.tableId), r = o.rows.slice();
486
+ return r.splice(e.rowIndex, 0, e.row), {
487
+ doc: y(t, n, s, { ...o, rows: r }),
488
+ inverse: { type: "removeTableRow", tableId: e.tableId, rowIndex: e.rowIndex },
489
+ mapPosition: b,
490
+ dirtyBlockIds: [e.tableId]
491
+ };
492
+ }
493
+ case "removeTableRow": {
494
+ const { where: n, bi: s, block: o } = I(t, e.tableId), r = o.rows[e.rowIndex];
495
+ if (!r) throw new Error("removeTableRow: no such row");
496
+ const i = o.rows.slice();
497
+ i.splice(e.rowIndex, 1);
498
+ const c = new Set(r.cells.flatMap((d) => d.blocks.map((f) => f.id))), l = i[Math.min(e.rowIndex, i.length - 1)], a = l ? O([l]) : void 0;
499
+ return {
500
+ doc: y(t, n, s, { ...o, rows: i }),
501
+ inverse: { type: "insertTableRow", tableId: e.tableId, rowIndex: e.rowIndex, row: r },
502
+ mapPosition: (d) => c.has(d.blockId) && a ? { blockId: a.id, offset: 0 } : d,
503
+ dirtyBlockIds: [e.tableId]
504
+ };
505
+ }
506
+ case "setListDefinition": {
507
+ const n = t.lists?.[e.listId] ?? null, s = { ...t.lists ?? {} };
508
+ return e.def ? s[e.listId] = e.def : delete s[e.listId], {
509
+ doc: { ...t, lists: s },
510
+ inverse: { type: "setListDefinition", listId: e.listId, def: n },
511
+ mapPosition: b,
512
+ // Indents come from the definition → every paragraph in the list must
513
+ // re-measure; their (revision,width) line-cache keys change with width.
514
+ dirtyBlockIds: []
515
+ };
516
+ }
517
+ case "setTableStructure": {
518
+ const { where: n, bi: s, block: o } = I(t, e.tableId), r = new Set(
519
+ o.rows.flatMap((a) => a.cells.flatMap((d) => d.blocks.map((f) => f.id)))
520
+ ), i = O(e.rows), c = { ...o, rows: e.rows };
521
+ e.colFractions ? c.colFractions = e.colFractions : delete c.colFractions;
522
+ const l = { type: "setTableStructure", tableId: e.tableId, rows: o.rows };
523
+ return o.colFractions && (l.colFractions = o.colFractions), {
524
+ doc: y(t, n, s, c),
525
+ inverse: l,
526
+ mapPosition: (a) => r.has(a.blockId) ? e.rows.some(
527
+ (f) => f.cells.some((h) => h.blocks.some((u) => u.id === a.blockId))
528
+ ) || !i ? a : { blockId: i.id, offset: 0 } : a,
529
+ dirtyBlockIds: [e.tableId]
530
+ };
531
+ }
532
+ case "insertTableColumn": {
533
+ const { where: n, bi: s, block: o } = I(t, e.tableId), r = { type: "setTableStructure", tableId: e.tableId, rows: o.rows };
534
+ o.colFractions && (r.colFractions = o.colFractions);
535
+ const i = o.rows.map((l, a) => {
536
+ const d = [];
537
+ let f = 0, h = !1;
538
+ for (const u of l.cells) {
539
+ const g = u.colSpan ?? 1;
540
+ if (!h && e.colIndex > f && e.colIndex < f + g)
541
+ d.push({ ...u, colSpan: g + 1 }), h = !0;
542
+ else if (!h && e.colIndex === f) {
543
+ const p = e.cells[a];
544
+ p && d.push(p), d.push(u), h = !0;
545
+ } else
546
+ d.push(u);
547
+ f += g;
548
+ }
549
+ if (!h) {
550
+ const u = e.cells[a];
551
+ u && d.push(u);
552
+ }
553
+ return { cells: d };
554
+ });
555
+ let c = e.fractions;
556
+ if (!c) {
557
+ const l = $(o), a = 1 / (l.length + 1);
558
+ c = l.map((d) => d * (1 - a)), c.splice(e.colIndex, 0, a);
559
+ }
560
+ return {
561
+ doc: y(t, n, s, { ...o, rows: i, colFractions: c }),
562
+ inverse: r,
563
+ mapPosition: b,
564
+ dirtyBlockIds: [e.tableId]
565
+ };
566
+ }
567
+ case "setStylesheet": {
568
+ const n = t.stylesheet ?? { styles: [], defaultStyleId: "Normal" };
569
+ return {
570
+ doc: { ...t, stylesheet: e.stylesheet },
571
+ inverse: { type: "setStylesheet", stylesheet: n },
572
+ mapPosition: b,
573
+ dirtyBlockIds: []
574
+ // restyling paragraphs happens via setRuns/setParaStyle ops
575
+ };
576
+ }
577
+ case "setTableStyleSheet": {
578
+ const n = t.tableStyles ?? {};
579
+ return {
580
+ doc: { ...t, tableStyles: e.tableStyles },
581
+ inverse: { type: "setTableStyleSheet", tableStyles: n },
582
+ mapPosition: b,
583
+ dirtyBlockIds: []
584
+ // re-baking cells happens via the table-replace ops
585
+ };
586
+ }
587
+ case "setTableStyleRef": {
588
+ const { where: n, bi: s, block: o } = I(t, e.tableId), r = o.styleId ?? null, i = o.condOverrides ?? null, c = { ...o };
589
+ return e.styleId === null ? delete c.styleId : c.styleId = e.styleId, e.condOverrides !== void 0 && (e.condOverrides === null ? delete c.condOverrides : c.condOverrides = e.condOverrides), {
590
+ doc: y(t, n, s, c),
591
+ inverse: { type: "setTableStyleRef", tableId: e.tableId, styleId: r, condOverrides: i },
592
+ mapPosition: b,
593
+ dirtyBlockIds: [e.tableId]
594
+ };
595
+ }
596
+ case "setSectionProps": {
597
+ const n = t.section, s = {
598
+ pageWidthPx: n.pageWidthPx,
599
+ pageHeightPx: n.pageHeightPx,
600
+ marginPx: { ...n.marginPx },
601
+ columns: n.columns ? { ...n.columns, ...n.columns.cols ? { cols: n.columns.cols.map((r) => ({ ...r })) } : {} } : null,
602
+ pageNumberStart: n.pageNumberStart ?? null,
603
+ headerDistancePx: n.headerDistancePx ?? null,
604
+ footerDistancePx: n.footerDistancePx ?? null,
605
+ pageColorHex: n.pageColorHex ?? null,
606
+ pageBorders: n.pageBorders ?? null
607
+ }, o = {
608
+ ...n,
609
+ pageWidthPx: e.geometry.pageWidthPx,
610
+ pageHeightPx: e.geometry.pageHeightPx,
611
+ marginPx: e.geometry.marginPx
612
+ };
613
+ return e.geometry.columns ? o.columns = e.geometry.columns : delete o.columns, e.geometry.pageNumberStart !== null ? o.pageNumberStart = e.geometry.pageNumberStart : delete o.pageNumberStart, e.geometry.headerDistancePx !== null ? o.headerDistancePx = e.geometry.headerDistancePx : delete o.headerDistancePx, e.geometry.footerDistancePx !== null ? o.footerDistancePx = e.geometry.footerDistancePx : delete o.footerDistancePx, e.geometry.pageColorHex !== null ? o.pageColorHex = e.geometry.pageColorHex : delete o.pageColorHex, e.geometry.pageBorders !== null ? o.pageBorders = e.geometry.pageBorders : delete o.pageBorders, {
614
+ doc: { ...t, section: o },
615
+ inverse: { type: "setSectionProps", geometry: s },
616
+ mapPosition: b,
617
+ dirtyBlockIds: []
618
+ // geometry change → full re-walk; line caches keyed by width
619
+ };
620
+ }
621
+ case "setFootnote": {
622
+ const n = t.footnotes?.[e.noteId] ?? null, s = { ...t.footnotes ?? {} };
623
+ e.paras ? s[e.noteId] = e.paras : delete s[e.noteId];
624
+ const o = new Set((n ?? []).map((i) => i.id)), r = t.blocks.find((i) => i.kind === "paragraph");
625
+ return {
626
+ doc: { ...t, footnotes: s },
627
+ inverse: { type: "setFootnote", noteId: e.noteId, paras: n },
628
+ mapPosition: (i) => o.has(i.blockId) ? (e.paras ?? []).some((l) => l.id === i.blockId) || !r ? i : { blockId: r.id, offset: 0 } : i,
629
+ dirtyBlockIds: []
630
+ };
631
+ }
632
+ case "setSdtProps": {
633
+ const n = t.sdts?.[e.id] ?? null, s = { ...t.sdts ?? {} };
634
+ return e.props ? s[e.id] = e.props : delete s[e.id], {
635
+ doc: { ...t, sdts: s },
636
+ inverse: { type: "setSdtProps", id: e.id, props: n },
637
+ mapPosition: b,
638
+ dirtyBlockIds: []
639
+ // run markers change via setRuns/applyStylePatch ops
640
+ };
641
+ }
642
+ case "setField": {
643
+ const n = t.fields?.[e.id] ?? null, s = { ...t.fields ?? {} };
644
+ return e.def ? s[e.id] = e.def : delete s[e.id], {
645
+ doc: { ...t, fields: s },
646
+ inverse: { type: "setField", id: e.id, def: n },
647
+ mapPosition: b,
648
+ dirtyBlockIds: []
649
+ // run/block fieldId markers change via setRuns/insert ops
650
+ };
651
+ }
652
+ case "setTocInstruction": {
653
+ const n = t.tocInstruction ?? null, s = { ...t };
654
+ return e.instruction !== null ? s.tocInstruction = e.instruction : delete s.tocInstruction, {
655
+ doc: s,
656
+ inverse: { type: "setTocInstruction", instruction: n },
657
+ mapPosition: b,
658
+ dirtyBlockIds: []
659
+ // entries are regenerated via insert/removeBlock ops in the same tx
660
+ };
661
+ }
662
+ case "setBookmark": {
663
+ const n = t.bookmarks?.[e.name] ?? null, s = { ...t.bookmarks ?? {} };
664
+ return e.range ? s[e.name] = e.range : delete s[e.name], {
665
+ doc: { ...t, bookmarks: s },
666
+ inverse: { type: "setBookmark", name: e.name, range: n },
667
+ mapPosition: b,
668
+ dirtyBlockIds: []
669
+ };
670
+ }
671
+ case "setSectionBand": {
672
+ const n = t.section[e.band] ?? null, s = { ...t.section };
673
+ e.blocks ? s[e.band] = e.blocks : delete s[e.band];
674
+ const o = new Set(
675
+ (n ?? []).filter((i) => i.kind === "paragraph").map((i) => i.id)
676
+ ), r = t.blocks.find((i) => i.kind === "paragraph");
677
+ return {
678
+ doc: { ...t, section: s },
679
+ inverse: { type: "setSectionBand", band: e.band, blocks: n },
680
+ mapPosition: (i) => o.has(i.blockId) ? (e.blocks ?? []).some((l) => l.id === i.blockId) || !r ? i : { blockId: r.id, offset: 0 } : i,
681
+ dirtyBlockIds: []
682
+ };
683
+ }
684
+ case "removeTableColumn": {
685
+ const { where: n, bi: s, block: o } = I(t, e.tableId), r = { type: "setTableStructure", tableId: e.tableId, rows: o.rows };
686
+ o.colFractions && (r.colFractions = o.colFractions);
687
+ const i = $(o), c = /* @__PURE__ */ new Set(), l = o.rows.map((u) => {
688
+ const g = [];
689
+ let p = 0;
690
+ for (const E of u.cells) {
691
+ const S = E.colSpan ?? 1;
692
+ if (e.colIndex >= p && e.colIndex < p + S)
693
+ if (S > 1) {
694
+ const B = { ...E };
695
+ S - 1 > 1 ? B.colSpan = S - 1 : delete B.colSpan, g.push(B);
696
+ } else
697
+ for (const B of E.blocks) c.add(B.id);
698
+ else
699
+ g.push(E);
700
+ p += S;
701
+ }
702
+ return { cells: g };
703
+ }), a = i.filter((u, g) => g !== e.colIndex), d = a.reduce((u, g) => u + g, 0) || 1, f = a.map((u) => u / d), h = O(l);
704
+ return {
705
+ doc: y(t, n, s, { ...o, rows: l, colFractions: f }),
706
+ inverse: r,
707
+ mapPosition: (u) => c.has(u.blockId) && h ? { blockId: h.id, offset: 0 } : u,
708
+ dirtyBlockIds: [e.tableId]
709
+ };
710
+ }
711
+ }
712
+ }
713
+ function X(t, e = 0) {
714
+ let n = e;
715
+ return {
716
+ siteId: t,
717
+ next: () => `${t}-${(n++).toString(36)}`,
718
+ count: () => n
719
+ };
720
+ }
721
+ let j = X("local");
722
+ function Ce(t, e = 0) {
723
+ j = X(t, e);
724
+ }
725
+ function z() {
726
+ return j.next();
727
+ }
728
+ function Le() {
729
+ return j.siteId;
730
+ }
731
+ const G = (t) => {
732
+ if (!t) return;
733
+ const e = t.match(/^(\d+)\s*-\s*(\d+)$/);
734
+ if (e) return { from: Number(e[1]), to: Number(e[2]) };
735
+ const n = t.match(/^\d+$/) ? Number(t) : NaN;
736
+ return Number.isNaN(n) ? void 0 : { from: n, to: n };
737
+ };
738
+ function fe(t) {
739
+ const e = {
740
+ useOutlineLevels: /\\u\b/.test(t),
741
+ hyperlinks: /\\h\b/.test(t),
742
+ hideInWeb: /\\z\b/.test(t)
743
+ }, n = G(t.match(/\\o\s+"([^"]+)"/)?.[1]);
744
+ n && (e.outlineRange = n);
745
+ const s = G(t.match(/\\n\s+"?([0-9-]+)"?/)?.[1]);
746
+ s && (e.hidePageNumberRange = s);
747
+ const o = t.match(/\\p\s+"([^"]*)"/)?.[1];
748
+ o !== void 0 && (e.separator = o);
749
+ const r = t.match(/\\t\s+"([^"]+)"/)?.[1];
750
+ if (r) {
751
+ const i = r.split(","), c = {};
752
+ for (let l = 0; l + 1 < i.length; l += 2) {
753
+ const a = i[l].trim(), d = Number(i[l + 1].trim());
754
+ a && d >= 1 && (c[a] = d);
755
+ }
756
+ Object.keys(c).length > 0 && (e.customStyles = c);
757
+ }
758
+ return e;
759
+ }
760
+ function Ne(t) {
761
+ const e = ["TOC"];
762
+ if (t.outlineRange && e.push(`\\o "${t.outlineRange.from}-${t.outlineRange.to}"`), t.useOutlineLevels && e.push("\\u"), t.customStyles && Object.keys(t.customStyles).length > 0) {
763
+ const n = Object.entries(t.customStyles).map(([s, o]) => `${s},${o}`).join(",");
764
+ e.push(`\\t "${n}"`);
765
+ }
766
+ return t.hyperlinks && e.push("\\h"), t.hidePageNumberRange && e.push(`\\n "${t.hidePageNumberRange.from}-${t.hidePageNumberRange.to}"`), t.separator !== void 0 && e.push(`\\p "${t.separator}"`), t.hideInWeb && e.push("\\z"), ` ${e.join(" ")} `;
767
+ }
768
+ const Ae = (t, e) => !!t && e >= t.from && e <= t.to;
769
+ function q(t, e) {
770
+ if (!e || !t.stylesheet) return;
771
+ const n = new Map(t.stylesheet.styles.map((r) => [r.id, r]));
772
+ let s = n.get(e);
773
+ const o = /* @__PURE__ */ new Set();
774
+ for (; s && !o.has(s.id); ) {
775
+ if (s.name && /(?:^|\s)heading\s*\d/i.test(s.name)) return s.name;
776
+ o.add(s.id), s = s.basedOn ? n.get(s.basedOn) : void 0;
777
+ }
778
+ return n.get(e)?.name;
779
+ }
780
+ function ue(t, e, n) {
781
+ const s = t.style.namedStyle;
782
+ if (n?.customStyles && s) {
783
+ const i = n.customStyles[s] ?? n.customStyles[q(e, s) ?? ""];
784
+ if (i) return i;
785
+ }
786
+ if (t.style.outlineLevel !== void 0) return t.style.outlineLevel + 1;
787
+ const o = s?.match(/^heading\s*(\d)$/i);
788
+ if (o) return Number(o[1]);
789
+ const r = q(e, s)?.match(/(?:^|\s)heading\s*(\d)/i);
790
+ return r ? Number(r[1]) : null;
791
+ }
792
+ function he(t, e, n = 3) {
793
+ const s = e?.outlineRange?.to ?? n, o = [];
794
+ for (const r of ee(t)) {
795
+ const i = ue(r, t, e);
796
+ i === null || i < 1 || i > s || e?.outlineRange && (i < e.outlineRange.from || i > e.outlineRange.to) || o.push({ block: r, level: i });
797
+ }
798
+ return o;
799
+ }
800
+ function De(t, e = 20) {
801
+ if (!t.bookmarks) return 0;
802
+ const n = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right;
803
+ let s = 0;
804
+ for (const o of t.blocks) {
805
+ if (o.kind !== "paragraph" || o.style.tocEntry) continue;
806
+ const r = o.runs.find((d) => d.style.link?.startsWith("#"))?.style.link?.slice(1);
807
+ if (!r) continue;
808
+ const i = t.bookmarks[r]?.start.blockId;
809
+ if (!i) continue;
810
+ const c = F(o.runs), l = c.match(/\t\d+\s*$/);
811
+ if (!l) continue;
812
+ o.runs = V(o.runs, 0, c.length - l[0].length), o.runs.length === 0 && (o.runs = [{ text: "", style: { ...L } }]);
813
+ const a = Math.min(9, Math.max(1, Math.round((o.style.indentLeftPx || 0) / e) + 1));
814
+ o.style.tocEntry = { targetId: i, level: a }, !o.style.tabStops?.length && n > 0 && (o.style.tabStops = [{ posPx: n, align: "right", leader: "dot" }]), o.revision++, s++;
815
+ }
816
+ return s;
817
+ }
818
+ const L = { ...Q, fontSizePx: 13 }, be = 20;
819
+ function ke(t, e, n, s) {
820
+ const o = t.indentStepPx ?? be, r = t.leader ?? "dot", i = { align: "left", lineHeight: 1.5, spaceBeforePx: 0, spaceAfterPx: 2, indentFirstLinePx: 0 };
821
+ let c, l;
822
+ if (s && (s.char || s.para)) {
823
+ c = { ...L, ...s.char, ...t.baseChar, ...t.levels?.[e]?.char };
824
+ const a = s.para?.indentLeftPx ?? 0;
825
+ l = {
826
+ ...i,
827
+ ...s.para,
828
+ indentLeftPx: a + (e - 1) * o,
829
+ ...t.levels?.[e]?.para
830
+ };
831
+ } else
832
+ c = { ...{ ...L, ...t.baseChar }, fontSizePx: e === 1 ? 14 : 13, bold: e === 1, ...t.levels?.[e]?.char }, l = {
833
+ ...i,
834
+ indentLeftPx: (e - 1) * o,
835
+ ...t.levels?.[e]?.para
836
+ };
837
+ return r !== "none" && n > 0 ? l.tabStops = [{ posPx: n, align: "right", leader: r }] : delete l.tabStops, { char: c, para: l };
838
+ }
839
+ function ge(t) {
840
+ if (t.title === null) return null;
841
+ const e = t.title ?? {}, n = { ...L, ...t.baseChar };
842
+ return {
843
+ text: e.text ?? "Table of Contents",
844
+ char: { ...n, fontSizePx: 20, bold: !0, ...e.char },
845
+ para: {
846
+ align: "left",
847
+ lineHeight: 1.4,
848
+ spaceBeforePx: 8,
849
+ spaceAfterPx: 12,
850
+ indentFirstLinePx: 0,
851
+ indentLeftPx: 0,
852
+ namedStyle: e.namedStyle ?? "tocTitle",
853
+ ...e.para
854
+ }
855
+ };
856
+ }
857
+ const me = 3;
858
+ function Ie(t, e = {}) {
859
+ const n = t.tocInstruction ? fe(t.tocInstruction) : void 0, s = e.maxLevel ?? n?.outlineRange?.to ?? me, o = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right, r = t.tocAnchorBlockId ? t.blocks.find((a) => a.kind === "paragraph" && a.id === t.tocAnchorBlockId) : void 0, i = r ? { char: r.runs[0]?.style, para: r.style } : void 0, c = [];
860
+ if (e.title !== void 0 ? e.title !== null : r === void 0) {
861
+ const a = ge(e);
862
+ a && c.push({
863
+ kind: "paragraph",
864
+ id: z(),
865
+ revision: 0,
866
+ runs: [{ text: a.text, style: a.char }],
867
+ style: a.para
868
+ });
869
+ }
870
+ for (const { block: a, level: d } of he(t, n, s)) {
871
+ const f = F(a.runs).replace(/\v/g, " ").trim();
872
+ if (f.length === 0) continue;
873
+ const { char: h, para: u } = ke(e, d, o, i);
874
+ c.push({
875
+ kind: "paragraph",
876
+ id: z(),
877
+ revision: 0,
878
+ runs: [{ text: f, style: h }],
879
+ style: { ...u, tocEntry: { targetId: a.id, level: d } }
880
+ });
881
+ }
882
+ return c;
883
+ }
884
+ function $e(t, e = {}) {
885
+ if (t.blocks.some((i) => i.kind === "paragraph" && i.style.tocEntry))
886
+ return { doc: t, generated: 0, headings: 0 };
887
+ if (t.tocAnchorBlockId === void 0) return { doc: t, generated: 0, headings: 0 };
888
+ const n = t.blocks.findIndex((i) => i.id === t.tocAnchorBlockId);
889
+ if (n < 0) return { doc: t, generated: 0, headings: 0 };
890
+ const s = Ie(t, e), o = s.reduce((i, c) => i + (c.style.tocEntry ? 1 : 0), 0);
891
+ if (o === 0) return { doc: t, generated: 0, headings: 0 };
892
+ const r = [...t.blocks];
893
+ return r.splice(n, 1, ...s), { doc: { ...t, blocks: r }, generated: o, headings: o };
894
+ }
895
+ export {
896
+ ae as A,
897
+ N as B,
898
+ ye as C,
899
+ V as D,
900
+ Se as E,
901
+ Ie as F,
902
+ ee as G,
903
+ Te as H,
904
+ x as I,
905
+ Q as J,
906
+ Z as K,
907
+ Be as L,
908
+ Re as M,
909
+ $ as N,
910
+ Ce as O,
911
+ X as P,
912
+ De as Q,
913
+ ke as a,
914
+ Ne as b,
915
+ J as c,
916
+ he as d,
917
+ de as e,
918
+ Oe as f,
919
+ $e as g,
920
+ we as h,
921
+ Ae as i,
922
+ te as j,
923
+ Fe as k,
924
+ xe as l,
925
+ W as m,
926
+ Le as n,
927
+ z as o,
928
+ fe as p,
929
+ Ee as q,
930
+ C as r,
931
+ ne as s,
932
+ F as t,
933
+ k as u,
934
+ Pe as v,
935
+ Y as w,
936
+ K as x,
937
+ ve as y,
938
+ pe as z
939
+ };