kindy-editor 3.2.1 → 3.2.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 (51) hide show
  1. package/dist-lib/assets/{worker-CHtzL1YW.js → worker-BIFTSRF2.js} +7043 -7021
  2. package/dist-lib/assets/{worker-_GAJUHf5.js → worker-DO8U44KQ.js} +1 -0
  3. package/dist-lib/{browser-BxYyzpLt.js → browser-xuRja-pP.js} +2 -2
  4. package/dist-lib/builder.js +7 -7
  5. package/dist-lib/changeAggregator-ymKDXGA8.js +376 -0
  6. package/dist-lib/{editorApp-7-JzxxVn.js → editorApp-zIpjgEaZ.js} +9026 -8276
  7. package/dist-lib/events.js +119 -43
  8. package/dist-lib/export.js +1742 -1724
  9. package/dist-lib/generate-toc.js +5 -5
  10. package/dist-lib/import.js +2 -2
  11. package/dist-lib/index-Dd7gMK7l.js +12857 -0
  12. package/dist-lib/{kindy-editor-DKDwpt09.js → kindy-editor-DuN692fi.js} +133 -83
  13. package/dist-lib/kindy-editor.js +9 -6
  14. package/dist-lib/{lists-DpmgbDyt.js → lists-BVCy5dMa.js} +2 -2
  15. package/dist-lib/measure.js +3 -3
  16. package/dist-lib/{measureHost-C2NOdNkI.js → measureHost-y37gLU6M.js} +2 -2
  17. package/dist-lib/{metrics-DHgtBP-R.js → metrics-CdfHD-8y.js} +3 -3
  18. package/dist-lib/{paintStyle-Cjk9egel.js → paintStyle-Cb7IGKPW.js} +51 -51
  19. package/dist-lib/{parse-D4RpPrd7.js → parse-DJZd-2A7.js} +20 -20
  20. package/dist-lib/{pipeline-DhhBcLvV.js → pipeline-DKgBMmw1.js} +301 -301
  21. package/dist-lib/recalc-docx.js +2 -2
  22. package/dist-lib/{recalcToc-n50vq4nC.js → recalcToc-DCykIt4o.js} +80 -80
  23. package/dist-lib/{styleProps-OePkgWnD.js → styleProps-Dg3Wf-ZJ.js} +3 -3
  24. package/dist-lib/{stylesheet-E5bu1xch.js → stylesheet-EQFx9l5c.js} +3 -3
  25. package/dist-lib/{toc-DSwkNKls.js → toc-BIj8uQ-W.js} +417 -388
  26. package/dist-lib/{webmcp-KVT__0GH.js → webmcp-QA5rVg1F.js} +2 -2
  27. package/docs/http-event-sink.md +7 -0
  28. package/docs/public-events.md +103 -0
  29. package/docs/template-variables.md +310 -0
  30. package/docs/track-changes-events.md +551 -0
  31. package/package.json +2 -2
  32. package/types/events.d.ts +67 -1
  33. package/types/kindy-editor.d.ts +126 -3
  34. package/dist-lib/eventHub-CZFpTVqe.js +0 -71
  35. package/dist-lib/events-D_WEQDa6.js +0 -104
  36. package/dist-lib/index-Brv5TV-9.js +0 -11822
  37. package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
  38. package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  39. package/docs/.vitepress/cache/deps/_metadata.json +0 -40
  40. package/docs/.vitepress/cache/deps/chunk-FNDFPMRQ.js +0 -13131
  41. package/docs/.vitepress/cache/deps/chunk-FNDFPMRQ.js.map +0 -7
  42. package/docs/.vitepress/cache/deps/chunk-IOFLAFGL.js +0 -9719
  43. package/docs/.vitepress/cache/deps/chunk-IOFLAFGL.js.map +0 -7
  44. package/docs/.vitepress/cache/deps/package.json +0 -3
  45. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4483
  46. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  47. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
  48. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  49. package/docs/.vitepress/cache/deps/vue.js +0 -347
  50. package/docs/.vitepress/cache/deps/vue.js.map +0 -7
  51. package/docs/.vitepress/config.ts +0 -30
@@ -10,10 +10,10 @@ const S = [
10
10
  for (const s of t)
11
11
  if (s.kind === "paragraph") n.push(s);
12
12
  else if (s.kind === "table" && e)
13
- for (const o of s.rows)
14
- for (const i of o.cells) n.push(...L(i.blocks, e));
13
+ for (const r of s.rows)
14
+ for (const i of r.cells) n.push(...L(i.blocks, e));
15
15
  return n;
16
- }, q = (t, e) => L(t.section[e] ?? [], !0), le = (t) => L(t.blocks, !0), z = /* @__PURE__ */ new WeakMap(), ce = (t) => {
16
+ }, q = (t, e) => L(t.section[e] ?? [], !0), le = (t) => L(t.blocks, !0), z = /* @__PURE__ */ new WeakMap(), ae = (t) => {
17
17
  const e = [
18
18
  ...L(t.blocks, !0),
19
19
  ...S.flatMap((s) => q(t, s)),
@@ -21,66 +21,66 @@ const S = [
21
21
  ...Object.values(t.endnotes ?? {}).flat()
22
22
  ], n = /* @__PURE__ */ new Map();
23
23
  for (let s = 0; s < e.length; s++) {
24
- const o = e[s].id;
25
- n.has(o) || n.set(o, s);
24
+ const r = e[s].id;
25
+ n.has(r) || n.set(r, s);
26
26
  }
27
27
  return { list: e, byId: n };
28
28
  }, j = (t) => {
29
29
  let e = z.get(t);
30
- return e || (e = ce(t), z.set(t, e)), e;
31
- }, ae = (t) => j(t).list, de = (t, e) => {
30
+ return e || (e = ae(t), z.set(t, e)), e;
31
+ }, ce = (t) => j(t).list, de = (t, e) => {
32
32
  const n = j(t), s = n.byId.get(e);
33
33
  return s === void 0 ? void 0 : n.list[s];
34
34
  }, Me = (t, e) => {
35
35
  const n = j(t).byId.get(e);
36
36
  return n === void 0 ? -1 : n;
37
- }, G = /* @__PURE__ */ new WeakMap(), fe = (t) => {
38
- let e = G.get(t);
37
+ }, V = /* @__PURE__ */ new WeakMap(), fe = (t) => {
38
+ let e = V.get(t);
39
39
  if (!e) {
40
40
  const n = /* @__PURE__ */ new Set();
41
- for (const s of S) for (const o of q(t, s)) n.add(o.id);
42
- e = n, G.set(t, e);
41
+ for (const s of S) for (const r of q(t, s)) n.add(r.id);
42
+ e = n, V.set(t, e);
43
43
  }
44
44
  return e;
45
- }, U = /* @__PURE__ */ new WeakMap(), Ae = (t) => {
46
- let e = U.get(t);
45
+ }, K = /* @__PURE__ */ new WeakMap(), Ae = (t) => {
46
+ let e = K.get(t);
47
47
  if (!e) {
48
48
  const n = fe(t);
49
- e = ae(t).filter((s) => !n.has(s.id) && !ne(s)), U.set(t, e);
49
+ e = ce(t).filter((s) => !n.has(s.id) && !ne(s)), K.set(t, e);
50
50
  }
51
51
  return e;
52
- }, Y = /* @__PURE__ */ new WeakMap(), Le = (t, e) => {
53
- let n = Y.get(t);
54
- n || (n = /* @__PURE__ */ new Map(), Y.set(t, n));
52
+ }, G = /* @__PURE__ */ new WeakMap(), Le = (t, e) => {
53
+ let n = G.get(t);
54
+ n || (n = /* @__PURE__ */ new Map(), G.set(t, n));
55
55
  let s = n.get(e);
56
- return s || (s = q(t, e).filter((o) => !ne(o)), n.set(e, s)), s;
57
- }, D = (t, e) => {
56
+ return s || (s = q(t, e).filter((r) => !ne(r)), n.set(e, s)), s;
57
+ }, $ = (t, e) => {
58
58
  for (const n of t)
59
59
  if (e.add(n.id), n.kind === "table")
60
- for (const s of n.rows) for (const o of s.cells) D(o.blocks, e);
61
- }, We = (t, e) => {
60
+ for (const s of n.rows) for (const r of s.cells) $(r.blocks, e);
61
+ }, De = (t, e) => {
62
62
  const n = /* @__PURE__ */ new Set();
63
- D(t.blocks, n);
64
- for (const s of S) D(t.section[s] ?? [], n);
65
- for (const s of Object.values(t.footnotes ?? {})) for (const o of s) n.add(o.id);
66
- for (const s of Object.values(t.endnotes ?? {})) for (const o of s) n.add(o.id);
63
+ $(t.blocks, n);
64
+ for (const s of S) $(t.section[s] ?? [], n);
65
+ for (const s of Object.values(t.footnotes ?? {})) for (const r of s) n.add(r.id);
66
+ for (const s of Object.values(t.endnotes ?? {})) for (const r of s) n.add(r.id);
67
67
  return n.has(e);
68
68
  }, se = (t, e) => e === "body" ? t.blocks : t.section[e] ?? [];
69
- function V(t, e, n) {
69
+ function U(t, e, n) {
70
70
  for (let s = 0; s < t.length; s++) {
71
- const o = t[s];
72
- if (o.kind === "paragraph") {
73
- if (o.id === n)
71
+ const r = t[s];
72
+ if (r.kind === "paragraph") {
73
+ if (r.id === n)
74
74
  return e === "body" ? { kind: "top", bi: s } : { kind: "band", band: e, bi: s };
75
- } else if (o.kind === "table")
76
- for (let i = 0; i < o.rows.length; i++) {
77
- const r = o.rows[i];
78
- for (let c = 0; c < r.cells.length; c++) {
79
- const l = r.cells[c];
80
- for (let a = 0; a < l.blocks.length; a++) {
81
- const d = l.blocks[a];
75
+ } else if (r.kind === "table")
76
+ for (let i = 0; i < r.rows.length; i++) {
77
+ const o = r.rows[i];
78
+ for (let a = 0; a < o.cells.length; a++) {
79
+ const l = o.cells[a];
80
+ for (let c = 0; c < l.blocks.length; c++) {
81
+ const d = l.blocks[c];
82
82
  if (d.kind === "paragraph" && d.id === n)
83
- return { kind: "cell", where: e, bi: s, ri: i, ci: c, pi: a };
83
+ return { kind: "cell", where: e, bi: s, ri: i, ci: a, pi: c };
84
84
  }
85
85
  }
86
86
  }
@@ -88,18 +88,18 @@ function V(t, e, n) {
88
88
  return null;
89
89
  }
90
90
  function M(t, e) {
91
- const n = V(t.blocks, "body", e);
91
+ const n = U(t.blocks, "body", e);
92
92
  if (n) return n;
93
93
  for (const s of S) {
94
- const o = V(t.section[s] ?? [], s, e);
95
- if (o) return o;
94
+ const r = U(t.section[s] ?? [], s, e);
95
+ if (r) return r;
96
96
  }
97
- for (const [s, o] of Object.entries(t.footnotes ?? {})) {
98
- const i = o.findIndex((r) => r.id === e);
97
+ for (const [s, r] of Object.entries(t.footnotes ?? {})) {
98
+ const i = r.findIndex((o) => o.id === e);
99
99
  if (i >= 0) return { kind: "footnote", noteId: s, pi: i };
100
100
  }
101
- for (const [s, o] of Object.entries(t.endnotes ?? {})) {
102
- const i = o.findIndex((r) => r.id === e);
101
+ for (const [s, r] of Object.entries(t.endnotes ?? {})) {
102
+ const i = r.findIndex((o) => o.id === e);
103
103
  if (i >= 0) return { kind: "endnote", noteId: s, pi: i };
104
104
  }
105
105
  return null;
@@ -124,10 +124,10 @@ function R(t, e, n) {
124
124
  const l = t.blocks.slice();
125
125
  return l[e.bi] = n, { ...t, blocks: l };
126
126
  }
127
- const s = se(t, e.where).slice(), o = s[e.bi], i = o.rows.slice(), r = { cells: i[e.ri].cells.slice() }, c = { ...r.cells[e.ci], blocks: r.cells[e.ci].blocks.slice() };
128
- return c.blocks[e.pi] = n, r.cells[e.ci] = c, i[e.ri] = r, s[e.bi] = { ...o, rows: i, revision: o.revision + 1 }, e.where === "body" ? { ...t, blocks: s } : { ...t, section: { ...t.section, [e.where]: s } };
127
+ const s = se(t, e.where).slice(), r = s[e.bi], i = r.rows.slice(), o = { cells: i[e.ri].cells.slice() }, a = { ...o.cells[e.ci], blocks: o.cells[e.ci].blocks.slice() };
128
+ return a.blocks[e.pi] = n, o.cells[e.ci] = a, i[e.ri] = o, s[e.bi] = { ...r, rows: i, revision: r.revision + 1 }, e.where === "body" ? { ...t, blocks: s } : { ...t, section: { ...t.section, [e.where]: s } };
129
129
  }
130
- const $e = (t, e) => M(t, e)?.kind === "cell", F = (t) => t.map((e) => e.text).join(""), De = (t, e) => {
130
+ const We = (t, e) => M(t, e)?.kind === "cell", F = (t) => t.map((e) => e.text).join(""), $e = (t, e) => {
131
131
  const n = de(t, e);
132
132
  return n ? F(n.runs) : "";
133
133
  };
@@ -164,9 +164,9 @@ function _e(t, e) {
164
164
  function ue(t, e) {
165
165
  let n = 0;
166
166
  for (const s of t) {
167
- const o = n + s.text.length;
168
- if (e > n && e <= o && s.text.length > 0) return s.style;
169
- n = o;
167
+ const r = n + s.text.length;
168
+ if (e > n && e <= r && s.text.length > 0) return s.style;
169
+ n = r;
170
170
  }
171
171
  return t[0]?.style;
172
172
  }
@@ -199,45 +199,45 @@ function be(t = {}) {
199
199
  indentLeftPx: 0
200
200
  };
201
201
  }
202
- const oe = he(), Ge = be();
203
- function Ue(t) {
202
+ const re = he(), Ve = be();
203
+ function Ke(t) {
204
204
  const e = t.sdtPath;
205
205
  return e && e.length > 0 ? e[e.length - 1] : void 0;
206
206
  }
207
207
  function ke(t, e) {
208
208
  const n = t?.length ?? 0, s = e?.length ?? 0;
209
209
  if (n !== s) return !1;
210
- for (let o = 0; o < n; o++) if (t[o] !== e[o]) return !1;
210
+ for (let r = 0; r < n; r++) if (t[r] !== e[r]) return !1;
211
211
  return !0;
212
212
  }
213
- function Ye(t, e) {
213
+ function Ge(t, e) {
214
214
  return t.sdtPath?.includes(e) ?? !1;
215
215
  }
216
- function Ve(t, e) {
216
+ function Ue(t, e) {
217
217
  return t && t.length > 0 ? [...t, e] : [e];
218
218
  }
219
- function Xe(t, e) {
219
+ function Ye(t, e) {
220
220
  if (!t) return;
221
221
  const n = t.filter((s) => s !== e);
222
222
  return n.length > 0 ? n : void 0;
223
223
  }
224
- function Je(t, e) {
224
+ function Xe(t, e) {
225
225
  if (!t) return;
226
226
  const n = t.indexOf(e);
227
227
  return n < 0 ? void 0 : t.slice(0, n + 1);
228
228
  }
229
229
  function ge(t) {
230
- const e = (r) => Number.isFinite(r) ? Math.min(0.999, Math.max(0, r)) : 0;
231
- let { left: n, top: s, right: o, bottom: i } = { left: e(t.left), top: e(t.top), right: e(t.right), bottom: e(t.bottom) };
232
- if (n + o >= 1) {
233
- const r = 0.999 / (n + o);
234
- n *= r, o *= r;
230
+ const e = (o) => Number.isFinite(o) ? Math.min(0.999, Math.max(0, o)) : 0;
231
+ let { left: n, top: s, right: r, bottom: i } = { left: e(t.left), top: e(t.top), right: e(t.right), bottom: e(t.bottom) };
232
+ if (n + r >= 1) {
233
+ const o = 0.999 / (n + r);
234
+ n *= o, r *= o;
235
235
  }
236
236
  if (s + i >= 1) {
237
- const r = 0.999 / (s + i);
238
- s *= r, i *= r;
237
+ const o = 0.999 / (s + i);
238
+ s *= o, i *= o;
239
239
  }
240
- return { left: n, top: s, right: o, bottom: i };
240
+ return { left: n, top: s, right: r, bottom: i };
241
241
  }
242
242
  function me(t, e) {
243
243
  return !t || !e ? !t == !e : t.font === e.font && t.char === e.char;
@@ -248,6 +248,7 @@ function Ie(t, e) {
248
248
  !!t.smallCaps == !!e.smallCaps && t.link === e.link && t.footnoteRef === e.footnoteRef && // adjacent refs must never merge into one run
249
249
  ke(t.sdtPath, e.sdtPath) && // content-control boundaries (incl. nesting) survive normalization
250
250
  t.fieldId === e.fieldId && // inline-field boundaries survive normalization
251
+ t.variableKey === e.variableKey && // template variable boundaries survive normalization
251
252
  t.equation === e.equation && // inline equations are atomic — never merge (reference identity)
252
253
  // Minor run typography & effects (w:rPr extras) — compared so styled runs never
253
254
  // merge with plain ones (and a struck-through pair keeps its boundary).
@@ -257,55 +258,65 @@ function ye(t, e) {
257
258
  return t === e ? !0 : !t || !e ? !1 : t.color === e.color && t.widthPx === e.widthPx && t.style === e.style;
258
259
  }
259
260
  function x(t, e) {
260
- const n = t.filter((o) => o.text.length > 0);
261
+ const n = t.filter((r) => r.text.length > 0);
261
262
  if (n.length === 0) return [{ text: "", style: t[0]?.style ?? e }];
262
263
  const s = [{ ...n[0] }];
263
- for (let o = 1; o < n.length; o++) {
264
- const i = n[o], r = s[s.length - 1];
265
- Ie(r.style, i.style) ? r.text += i.text : s.push({ ...i });
264
+ for (let r = 1; r < n.length; r++) {
265
+ const i = n[r], o = s[s.length - 1];
266
+ Ie(o.style, i.style) ? o.text += i.text : s.push({ ...i });
266
267
  }
267
268
  return s;
268
269
  }
269
270
  function y(t, e) {
270
271
  const n = [], s = [];
271
- let o = 0;
272
+ let r = 0;
272
273
  for (const i of t) {
273
- const r = o + i.text.length;
274
- r <= e ? n.push(i) : o >= e ? s.push(i) : (n.push({ text: i.text.slice(0, e - o), style: i.style }), s.push({ text: i.text.slice(e - o), style: i.style })), o = r;
274
+ const o = r + i.text.length;
275
+ o <= e ? n.push(i) : r >= e ? s.push(i) : (n.push({ text: i.text.slice(0, e - r), style: i.style }), s.push({ text: i.text.slice(e - r), style: i.style })), r = o;
275
276
  }
276
277
  return [n, s];
277
278
  }
278
- function re(t, e, n) {
279
- const [, s] = y(t, e), [o] = y(s, n - e);
280
- return o;
279
+ function oe(t, e, n) {
280
+ const [, s] = y(t, e), [r] = y(s, n - e);
281
+ return r;
281
282
  }
282
283
  function p(t, e) {
283
- return ue(t, e) ?? { ...oe };
284
+ const n = ue(t, e) ?? { ...re };
285
+ if (n.variableKey !== void 0) {
286
+ const { variableKey: s, ...r } = n;
287
+ return r;
288
+ }
289
+ return n;
284
290
  }
285
291
  function we(t, e, n, s) {
286
- const o = s ?? p(t, e), [i, r] = y(t, e);
287
- return x([...i, { text: n, style: o }, ...r], o);
292
+ let r = s ?? p(t, e);
293
+ if (r.variableKey !== void 0) {
294
+ const { variableKey: a, ...l } = r;
295
+ r = l;
296
+ }
297
+ const [i, o] = y(t, e);
298
+ return x([...i, { text: n, style: r }, ...o], r);
288
299
  }
289
300
  function xe(t, e, n) {
290
- const [s, o] = y(t, e);
291
- return x([...s, ...n, ...o], p(t, e));
301
+ const [s, r] = y(t, e);
302
+ return x([...s, ...n, ...r], p(t, e));
292
303
  }
293
304
  function pe(t, e, n) {
294
- const [s, o] = y(t, e), [, i] = y(o, n - e);
305
+ const [s, r] = y(t, e), [, i] = y(r, n - e);
295
306
  return x([...s, ...i], p(t, e));
296
307
  }
297
- function Qe(t, e, n, s) {
298
- const [o, i] = y(t, e), [r, c] = y(i, n - e), l = r.map((a) => ({ text: a.text, style: { ...a.style, ...s } }));
299
- return x([...o, ...l, ...c], p(t, e));
308
+ function Je(t, e, n, s) {
309
+ const [r, i] = y(t, e), [o, a] = y(i, n - e), l = o.map((c) => ({ text: c.text, style: { ...c.style, ...s } }));
310
+ return x([...r, ...l, ...a], p(t, e));
300
311
  }
301
- function Ze(t, e, n, s) {
302
- const [o, i] = y(t, e), [r, c] = y(i, n - e), l = r.map((h) => h.text).join(""), a = s(l);
312
+ function Qe(t, e, n, s) {
313
+ const [r, i] = y(t, e), [o, a] = y(i, n - e), l = o.map((h) => h.text).join(""), c = s(l);
303
314
  let d = 0;
304
- const f = a.length === l.length ? r.map((h) => {
305
- const u = a.slice(d, d + h.text.length);
315
+ const f = c.length === l.length ? o.map((h) => {
316
+ const u = c.slice(d, d + h.text.length);
306
317
  return d += h.text.length, { text: u, style: h.style };
307
- }) : r;
308
- return x([...o, ...f, ...c], p(t, e));
318
+ }) : o;
319
+ return x([...r, ...f, ...a], p(t, e));
309
320
  }
310
321
  const b = (t) => t;
311
322
  function E(t, e) {
@@ -319,25 +330,25 @@ function k(t, e) {
319
330
  function w(t, e, n) {
320
331
  return e === "body" ? { ...t, blocks: n } : { ...t, section: { ...t.section, [e]: n } };
321
332
  }
322
- function W(t, e) {
333
+ function D(t, e) {
323
334
  for (const n of ["body", ...S]) {
324
- const s = k(t, n).findIndex((o) => o.id === e);
335
+ const s = k(t, n).findIndex((r) => r.id === e);
325
336
  if (s >= 0) return { where: n, index: s };
326
337
  }
327
338
  return null;
328
339
  }
329
340
  function g(t, e) {
330
- const n = W(t, e), s = n ? k(t, n.where)[n.index] : void 0;
341
+ const n = D(t, e), s = n ? k(t, n.where)[n.index] : void 0;
331
342
  if (!n || !s || s.kind !== "table") throw new Error(`table ${e} not found`);
332
343
  return { where: n.where, bi: n.index, block: s };
333
344
  }
334
345
  function m(t, e, n, s) {
335
- const o = k(t, e).slice();
336
- return o[n] = { ...s, revision: s.revision + 1 }, w(t, e, o);
346
+ const r = k(t, e).slice();
347
+ return r[n] = { ...s, revision: s.revision + 1 }, w(t, e, r);
337
348
  }
338
- function N(t, e, n, s, o, i) {
339
- const r = k(t, e).slice(), c = r[n], l = c.rows.slice(), a = { cells: l[s].cells.slice() };
340
- return a.cells[o] = { ...a.cells[o], blocks: i }, l[s] = a, r[n] = { ...c, rows: l, revision: c.revision + 1 }, w(t, e, r);
349
+ function N(t, e, n, s, r, i) {
350
+ const o = k(t, e).slice(), a = o[n], l = a.rows.slice(), c = { cells: l[s].cells.slice() };
351
+ return c.cells[r] = { ...c.cells[r], blocks: i }, l[s] = c, o[n] = { ...a, rows: l, revision: a.revision + 1 }, w(t, e, o);
341
352
  }
342
353
  function O(t) {
343
354
  for (const e of t)
@@ -345,21 +356,21 @@ function O(t) {
345
356
  for (const s of n.blocks) if (s.kind === "paragraph") return s;
346
357
  }
347
358
  function Pe(t, e) {
348
- const n = W(t, e);
359
+ const n = D(t, e);
349
360
  if (n) {
350
361
  const s = k(t, n.where)[n.index];
351
362
  return s?.kind === "image" ? { kind: "top", where: n.where, index: n.index, image: s } : null;
352
363
  }
353
364
  for (let s = 0; s < t.blocks.length; s++) {
354
- const o = t.blocks[s];
355
- if (o.kind === "table")
356
- for (let i = 0; i < o.rows.length; i++) {
357
- const r = o.rows[i];
358
- for (let c = 0; c < r.cells.length; c++) {
359
- const l = r.cells[c];
360
- for (let a = 0; a < l.blocks.length; a++) {
361
- const d = l.blocks[a];
362
- if (d.kind === "image" && d.id === e) return { kind: "cell", bi: s, ri: i, ci: c, ii: a, image: d };
365
+ const r = t.blocks[s];
366
+ if (r.kind === "table")
367
+ for (let i = 0; i < r.rows.length; i++) {
368
+ const o = r.rows[i];
369
+ for (let a = 0; a < o.cells.length; a++) {
370
+ const l = o.cells[a];
371
+ for (let c = 0; c < l.blocks.length; c++) {
372
+ const d = l.blocks[c];
373
+ if (d.kind === "image" && d.id === e) return { kind: "cell", bi: s, ri: i, ci: a, ii: c, image: d };
363
374
  }
364
375
  }
365
376
  }
@@ -367,24 +378,24 @@ function Pe(t, e) {
367
378
  return null;
368
379
  }
369
380
  function ve(t, e, n) {
370
- const s = W(t, e);
381
+ const s = D(t, e);
371
382
  if (s) {
372
- const o = k(t, s.where)[s.index];
373
- return o?.kind === n ? { kind: "top", where: s.where, index: s.index, block: o } : null;
383
+ const r = k(t, s.where)[s.index];
384
+ return r?.kind === n ? { kind: "top", where: s.where, index: s.index, block: r } : null;
374
385
  }
375
- for (const o of ["body", ...S]) {
376
- const i = k(t, o);
377
- for (let r = 0; r < i.length; r++) {
378
- const c = i[r];
379
- if (c.kind === "table")
380
- for (let l = 0; l < c.rows.length; l++) {
381
- const a = c.rows[l];
382
- for (let d = 0; d < a.cells.length; d++) {
383
- const f = a.cells[d];
386
+ for (const r of ["body", ...S]) {
387
+ const i = k(t, r);
388
+ for (let o = 0; o < i.length; o++) {
389
+ const a = i[o];
390
+ if (a.kind === "table")
391
+ for (let l = 0; l < a.rows.length; l++) {
392
+ const c = a.rows[l];
393
+ for (let d = 0; d < c.cells.length; d++) {
394
+ const f = c.cells[d];
384
395
  for (let h = 0; h < f.blocks.length; h++) {
385
396
  const u = f.blocks[h];
386
397
  if (u.kind === n && u.id === e)
387
- return { kind: "cell", where: o, bi: r, ri: l, ci: d, ii: h, block: u };
398
+ return { kind: "cell", where: r, bi: o, ri: l, ci: d, ii: h, block: u };
388
399
  }
389
400
  }
390
401
  }
@@ -392,66 +403,66 @@ function ve(t, e, n) {
392
403
  }
393
404
  return null;
394
405
  }
395
- function X(t, e) {
406
+ function Y(t, e) {
396
407
  return ve(t, e, "equation");
397
408
  }
398
- function J(t, e, n) {
409
+ function X(t, e, n) {
399
410
  if (e.kind === "top") {
400
411
  const i = k(t, e.where).slice();
401
412
  return i[e.index] = n, w(t, e.where, i);
402
413
  }
403
- const o = k(t, e.where)[e.bi].rows[e.ri].cells[e.ci].blocks.slice();
404
- return o[e.ii] = n, N(t, e.where, e.bi, e.ri, e.ci, o);
414
+ const r = k(t, e.where)[e.bi].rows[e.ri].cells[e.ci].blocks.slice();
415
+ return r[e.ii] = n, N(t, e.where, e.bi, e.ri, e.ci, r);
405
416
  }
406
417
  function Se(t) {
407
418
  let e = 1;
408
419
  const n = [];
409
420
  for (const s of t.rows) {
410
- let o = 0;
421
+ let r = 0;
411
422
  for (const i of s.cells) {
412
- for (; (n[o] ?? 0) > 0; ) o++;
413
- const r = Math.max(1, i.colSpan ?? 1), c = Math.max(1, i.rowSpan ?? 1);
414
- if (c > 1) for (let l = 0; l < r; l++) n[o + l] = c;
415
- o += r;
423
+ for (; (n[r] ?? 0) > 0; ) r++;
424
+ const o = Math.max(1, i.colSpan ?? 1), a = Math.max(1, i.rowSpan ?? 1);
425
+ if (a > 1) for (let l = 0; l < o; l++) n[r + l] = a;
426
+ r += o;
416
427
  }
417
- e = Math.max(e, o);
428
+ e = Math.max(e, r);
418
429
  for (let i = 0; i < n.length; i++) n[i] > 0 && n[i]--;
419
430
  }
420
431
  return e;
421
432
  }
422
- function $(t) {
433
+ function W(t) {
423
434
  const e = Se(t);
424
435
  return t.colFractions && t.colFractions.length === e ? t.colFractions : Array.from({ length: e }, () => 1 / e);
425
436
  }
426
437
  function v(t, e) {
427
438
  return { ...t, runs: e, revision: t.revision + 1 };
428
439
  }
429
- function Ke(t, e) {
440
+ function Ze(t, e) {
430
441
  switch (e.type) {
431
442
  case "insertText": {
432
- const { loc: n, block: s } = E(t, e.at.blockId), o = we(s.runs, e.at.offset, e.text, e.style), i = e.text.length;
443
+ const { loc: n, block: s } = E(t, e.at.blockId), r = we(s.runs, e.at.offset, e.text, e.style), i = e.text.length;
433
444
  return {
434
- doc: R(t, n, v(s, o)),
445
+ doc: R(t, n, v(s, r)),
435
446
  inverse: { type: "deleteRange", blockId: s.id, start: e.at.offset, end: e.at.offset + i },
436
- mapPosition: (r) => r.blockId === s.id && r.offset >= e.at.offset ? { blockId: r.blockId, offset: r.offset + i } : r,
447
+ mapPosition: (o) => o.blockId === s.id && o.offset >= e.at.offset ? { blockId: o.blockId, offset: o.offset + i } : o,
437
448
  dirtyBlockIds: [s.id]
438
449
  };
439
450
  }
440
451
  case "insertRuns": {
441
- const { loc: n, block: s } = E(t, e.at.blockId), o = F(e.runs).length, i = xe(s.runs, e.at.offset, e.runs);
452
+ const { loc: n, block: s } = E(t, e.at.blockId), r = F(e.runs).length, i = xe(s.runs, e.at.offset, e.runs);
442
453
  return {
443
454
  doc: R(t, n, v(s, i)),
444
- inverse: { type: "deleteRange", blockId: s.id, start: e.at.offset, end: e.at.offset + o },
445
- mapPosition: (r) => r.blockId === s.id && r.offset >= e.at.offset ? { blockId: r.blockId, offset: r.offset + o } : r,
455
+ inverse: { type: "deleteRange", blockId: s.id, start: e.at.offset, end: e.at.offset + r },
456
+ mapPosition: (o) => o.blockId === s.id && o.offset >= e.at.offset ? { blockId: o.blockId, offset: o.offset + r } : o,
446
457
  dirtyBlockIds: [s.id]
447
458
  };
448
459
  }
449
460
  case "deleteRange": {
450
- const { loc: n, block: s } = E(t, e.blockId), o = re(s.runs, e.start, e.end), i = pe(s.runs, e.start, e.end), r = e.end - e.start;
461
+ const { loc: n, block: s } = E(t, e.blockId), r = oe(s.runs, e.start, e.end), i = pe(s.runs, e.start, e.end), o = e.end - e.start;
451
462
  return {
452
463
  doc: R(t, n, v(s, i)),
453
- inverse: { type: "insertRuns", at: { blockId: s.id, offset: e.start }, runs: o },
454
- mapPosition: (c) => c.blockId !== s.id || c.offset <= e.start ? c : { blockId: c.blockId, offset: c.offset >= e.end ? c.offset - r : e.start },
464
+ inverse: { type: "insertRuns", at: { blockId: s.id, offset: e.start }, runs: r },
465
+ mapPosition: (a) => a.blockId !== s.id || a.offset <= e.start ? a : { blockId: a.blockId, offset: a.offset >= e.end ? a.offset - o : e.start },
455
466
  dirtyBlockIds: [s.id]
456
467
  };
457
468
  }
@@ -466,9 +477,9 @@ function Ke(t, e) {
466
477
  };
467
478
  }
468
479
  case "setParaStyle": {
469
- const { loc: n, block: s } = E(t, e.blockId), o = {};
470
- for (const r of Object.keys(e.patch))
471
- o[r] = s.style[r];
480
+ const { loc: n, block: s } = E(t, e.blockId), r = {};
481
+ for (const o of Object.keys(e.patch))
482
+ r[o] = s.style[o];
472
483
  const i = {
473
484
  ...s,
474
485
  style: { ...s.style, ...e.patch },
@@ -476,7 +487,7 @@ function Ke(t, e) {
476
487
  };
477
488
  return {
478
489
  doc: R(t, n, i),
479
- inverse: { type: "setParaStyle", blockId: s.id, patch: o },
490
+ inverse: { type: "setParaStyle", blockId: s.id, patch: r },
480
491
  mapPosition: b,
481
492
  dirtyBlockIds: [s.id]
482
493
  };
@@ -484,33 +495,33 @@ function Ke(t, e) {
484
495
  case "splitParagraph": {
485
496
  const n = M(t, e.at.blockId);
486
497
  if (!n) throw new Error(`paragraph ${e.at.blockId} not found`);
487
- const s = H(t, n), [o, i] = y(s.runs, e.at.offset), r = p(s.runs, e.at.offset), c = v(s, x(o, r)), l = {
498
+ const s = H(t, n), [r, i] = y(s.runs, e.at.offset), o = p(s.runs, e.at.offset), a = v(s, x(r, o)), l = {
488
499
  kind: "paragraph",
489
500
  id: e.newBlockId,
490
501
  revision: 0,
491
- runs: x(i, r),
502
+ runs: x(i, o),
492
503
  style: e.newStyle ?? { ...s.style },
493
504
  // The tail's block-level content control is declared by the op (the split
494
505
  // command carries the source paragraph's path; the merge inverse restores
495
506
  // the original tail's). Absent → the tail belongs to no block control.
496
507
  ...e.newSdtPath?.length ? { sdtPath: e.newSdtPath } : {}
497
508
  };
498
- let a;
509
+ let c;
499
510
  if (n.kind === "cell") {
500
511
  const f = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks.slice();
501
- f.splice(n.pi, 1, c, l), a = N(t, n.where, n.bi, n.ri, n.ci, f);
512
+ f.splice(n.pi, 1, a, l), c = N(t, n.where, n.bi, n.ri, n.ci, f);
502
513
  } else if (n.kind === "footnote") {
503
514
  const d = t.footnotes[n.noteId].slice();
504
- d.splice(n.pi, 1, c, l), a = { ...t, footnotes: { ...t.footnotes, [n.noteId]: d } };
515
+ d.splice(n.pi, 1, a, l), c = { ...t, footnotes: { ...t.footnotes, [n.noteId]: d } };
505
516
  } else if (n.kind === "endnote") {
506
517
  const d = t.endnotes[n.noteId].slice();
507
- d.splice(n.pi, 1, c, l), a = { ...t, endnotes: { ...t.endnotes, [n.noteId]: d } };
518
+ d.splice(n.pi, 1, a, l), c = { ...t, endnotes: { ...t.endnotes, [n.noteId]: d } };
508
519
  } else {
509
520
  const d = n.kind === "band" ? n.band : "body", f = k(t, d).slice();
510
- f.splice(n.bi, 1, c, l), a = w(t, d, f);
521
+ f.splice(n.bi, 1, a, l), c = w(t, d, f);
511
522
  }
512
523
  return {
513
- doc: a,
524
+ doc: c,
514
525
  inverse: { type: "mergeParagraphs", firstBlockId: s.id },
515
526
  mapPosition: (d) => d.blockId === s.id && d.offset >= e.at.offset ? { blockId: e.newBlockId, offset: d.offset - e.at.offset } : d,
516
527
  dirtyBlockIds: [s.id, e.newBlockId]
@@ -520,56 +531,56 @@ function Ke(t, e) {
520
531
  const n = M(t, e.firstBlockId);
521
532
  if (!n) throw new Error(`paragraph ${e.firstBlockId} not found`);
522
533
  const s = H(t, n);
523
- let o;
534
+ let r;
524
535
  if (n.kind === "cell") {
525
- const a = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks[n.pi + 1];
526
- if (!a || a.kind !== "paragraph")
536
+ const c = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks[n.pi + 1];
537
+ if (!c || c.kind !== "paragraph")
527
538
  throw new Error("mergeParagraphs: no next paragraph in cell");
528
- o = a;
539
+ r = c;
529
540
  } else if (n.kind === "footnote") {
530
541
  const l = t.footnotes[n.noteId][n.pi + 1];
531
542
  if (!l) throw new Error("mergeParagraphs: no next paragraph in footnote");
532
- o = l;
543
+ r = l;
533
544
  } else if (n.kind === "endnote") {
534
545
  const l = t.endnotes[n.noteId][n.pi + 1];
535
546
  if (!l) throw new Error("mergeParagraphs: no next paragraph in endnote");
536
- o = l;
547
+ r = l;
537
548
  } else {
538
- const l = n.kind === "band" ? n.band : "body", a = k(t, l)[n.bi + 1];
539
- if (!a || a.kind !== "paragraph")
549
+ const l = n.kind === "band" ? n.band : "body", c = k(t, l)[n.bi + 1];
550
+ if (!c || c.kind !== "paragraph")
540
551
  throw new Error("mergeParagraphs: no next paragraph");
541
- o = a;
552
+ r = c;
542
553
  }
543
- const i = F(s.runs).length, r = v(
554
+ const i = F(s.runs).length, o = v(
544
555
  s,
545
- x([...s.runs, ...o.runs], p(s.runs, i))
556
+ x([...s.runs, ...r.runs], p(s.runs, i))
546
557
  );
547
- let c;
558
+ let a;
548
559
  if (n.kind === "cell") {
549
- const a = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks.slice();
550
- a.splice(n.pi, 2, r), c = N(t, n.where, n.bi, n.ri, n.ci, a);
560
+ const c = k(t, n.where)[n.bi].rows[n.ri].cells[n.ci].blocks.slice();
561
+ c.splice(n.pi, 2, o), a = N(t, n.where, n.bi, n.ri, n.ci, c);
551
562
  } else if (n.kind === "footnote") {
552
563
  const l = t.footnotes[n.noteId].slice();
553
- l.splice(n.pi, 2, r), c = { ...t, footnotes: { ...t.footnotes, [n.noteId]: l } };
564
+ l.splice(n.pi, 2, o), a = { ...t, footnotes: { ...t.footnotes, [n.noteId]: l } };
554
565
  } else if (n.kind === "endnote") {
555
566
  const l = t.endnotes[n.noteId].slice();
556
- l.splice(n.pi, 2, r), c = { ...t, endnotes: { ...t.endnotes, [n.noteId]: l } };
567
+ l.splice(n.pi, 2, o), a = { ...t, endnotes: { ...t.endnotes, [n.noteId]: l } };
557
568
  } else {
558
- const l = n.kind === "band" ? n.band : "body", a = k(t, l).slice();
559
- a.splice(n.bi, 2, r), c = w(t, l, a);
569
+ const l = n.kind === "band" ? n.band : "body", c = k(t, l).slice();
570
+ c.splice(n.bi, 2, o), a = w(t, l, c);
560
571
  }
561
572
  return {
562
- doc: c,
573
+ doc: a,
563
574
  inverse: {
564
575
  type: "splitParagraph",
565
576
  at: { blockId: s.id, offset: i },
566
- newBlockId: o.id,
567
- newStyle: o.style,
577
+ newBlockId: r.id,
578
+ newStyle: r.style,
568
579
  // Restore the merged-away tail's block-level control on undo.
569
- ...o.sdtPath?.length ? { newSdtPath: o.sdtPath } : {}
580
+ ...r.sdtPath?.length ? { newSdtPath: r.sdtPath } : {}
570
581
  },
571
- mapPosition: (l) => l.blockId === o.id ? { blockId: s.id, offset: i + l.offset } : l,
572
- dirtyBlockIds: [s.id, o.id]
582
+ mapPosition: (l) => l.blockId === r.id ? { blockId: s.id, offset: i + l.offset } : l,
583
+ dirtyBlockIds: [s.id, r.id]
573
584
  };
574
585
  }
575
586
  case "insertBlock": {
@@ -582,156 +593,156 @@ function Ke(t, e) {
582
593
  };
583
594
  }
584
595
  case "removeBlock": {
585
- const n = W(t, e.blockId);
596
+ const n = D(t, e.blockId);
586
597
  if (!n) throw new Error(`block ${e.blockId} not found`);
587
- const s = k(t, n.where).slice(), o = s[n.index];
598
+ const s = k(t, n.where).slice(), r = s[n.index];
588
599
  s.splice(n.index, 1);
589
600
  const i = s[Math.min(n.index, s.length - 1)];
590
601
  return {
591
602
  doc: w(t, n.where, s),
592
- inverse: { type: "insertBlock", index: n.index, block: o, where: n.where },
593
- mapPosition: (r) => r.blockId === e.blockId && i ? { blockId: i.id, offset: 0 } : r,
603
+ inverse: { type: "insertBlock", index: n.index, block: r, where: n.where },
604
+ mapPosition: (o) => o.blockId === e.blockId && i ? { blockId: i.id, offset: 0 } : o,
594
605
  dirtyBlockIds: [e.blockId]
595
606
  };
596
607
  }
597
608
  case "setImageProps": {
598
609
  const n = Pe(t, e.blockId);
599
610
  if (!n) throw new Error(`image ${e.blockId} not found`);
600
- const s = n.image, o = {};
601
- 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), e.patch.crop !== void 0 && (o.crop = s.crop ?? null);
611
+ const s = n.image, r = {};
612
+ e.patch.widthPx !== void 0 && (r.widthPx = s.widthPx), e.patch.heightPx !== void 0 && (r.heightPx = s.heightPx), e.patch.align !== void 0 && (r.align = s.align), e.patch.wrap !== void 0 && (r.wrap = s.wrap ?? null), e.patch.anchor !== void 0 && (r.anchor = s.anchor ?? null), e.patch.crop !== void 0 && (r.crop = s.crop ?? null);
602
613
  const i = { ...s, revision: s.revision + 1 };
603
614
  e.patch.widthPx !== void 0 && (i.widthPx = e.patch.widthPx), e.patch.heightPx !== void 0 && (i.heightPx = e.patch.heightPx), e.patch.align !== void 0 && (i.align = e.patch.align), e.patch.wrap !== void 0 && (e.patch.wrap === null ? delete i.wrap : i.wrap = e.patch.wrap), e.patch.anchor !== void 0 && (e.patch.anchor === null ? delete i.anchor : i.anchor = e.patch.anchor), e.patch.crop !== void 0 && (e.patch.crop === null ? delete i.crop : i.crop = ge(e.patch.crop));
604
- let r;
615
+ let o;
605
616
  if (n.kind === "top") {
606
- const c = k(t, n.where).slice();
607
- c[n.index] = i, r = w(t, n.where, c);
617
+ const a = k(t, n.where).slice();
618
+ a[n.index] = i, o = w(t, n.where, a);
608
619
  } else {
609
620
  const l = t.blocks[n.bi].rows[n.ri].cells[n.ci].blocks.slice();
610
- l[n.ii] = i, r = N(t, "body", n.bi, n.ri, n.ci, l);
621
+ l[n.ii] = i, o = N(t, "body", n.bi, n.ri, n.ci, l);
611
622
  }
612
623
  return {
613
- doc: r,
614
- inverse: { type: "setImageProps", blockId: e.blockId, patch: o },
624
+ doc: o,
625
+ inverse: { type: "setImageProps", blockId: e.blockId, patch: r },
615
626
  mapPosition: b,
616
627
  dirtyBlockIds: [e.blockId]
617
628
  };
618
629
  }
619
630
  case "setEquation": {
620
- const n = X(t, e.blockId);
631
+ const n = Y(t, e.blockId);
621
632
  if (!n) throw new Error(`equation ${e.blockId} not found`);
622
- const s = n.block.equation, o = { ...n.block, revision: n.block.revision + 1, equation: e.equation };
633
+ const s = n.block.equation, r = { ...n.block, revision: n.block.revision + 1, equation: e.equation };
623
634
  return {
624
- doc: J(t, n, o),
635
+ doc: X(t, n, r),
625
636
  inverse: { type: "setEquation", blockId: e.blockId, equation: s },
626
637
  mapPosition: b,
627
638
  dirtyBlockIds: [e.blockId]
628
639
  };
629
640
  }
630
641
  case "setEquationAlign": {
631
- const n = X(t, e.blockId);
642
+ const n = Y(t, e.blockId);
632
643
  if (!n) throw new Error(`equation ${e.blockId} not found`);
633
- const s = n.block.align ?? "center", o = { ...n.block, revision: n.block.revision + 1, align: e.align };
644
+ const s = n.block.align ?? "center", r = { ...n.block, revision: n.block.revision + 1, align: e.align };
634
645
  return {
635
- doc: J(t, n, o),
646
+ doc: X(t, n, r),
636
647
  inverse: { type: "setEquationAlign", blockId: e.blockId, align: s },
637
648
  mapPosition: b,
638
649
  dirtyBlockIds: [e.blockId]
639
650
  };
640
651
  }
641
652
  case "setTableColFractions": {
642
- const { where: n, bi: s, block: o } = g(t, e.blockId), i = $(o);
653
+ const { where: n, bi: s, block: r } = g(t, e.blockId), i = W(r);
643
654
  return {
644
- doc: m(t, n, s, { ...o, colFractions: e.fractions }),
655
+ doc: m(t, n, s, { ...r, colFractions: e.fractions }),
645
656
  inverse: { type: "setTableColFractions", blockId: e.blockId, fractions: i },
646
657
  mapPosition: b,
647
658
  dirtyBlockIds: [e.blockId]
648
659
  };
649
660
  }
650
661
  case "setTableWidthMode": {
651
- const { where: n, bi: s, block: o } = g(t, e.blockId), i = o.widthMode, r = { ...o };
652
- return e.mode && e.mode !== "fixed" ? r.widthMode = e.mode : delete r.widthMode, {
653
- doc: m(t, n, s, r),
662
+ const { where: n, bi: s, block: r } = g(t, e.blockId), i = r.widthMode, o = { ...r };
663
+ return e.mode && e.mode !== "fixed" ? o.widthMode = e.mode : delete o.widthMode, {
664
+ doc: m(t, n, s, o),
654
665
  inverse: { type: "setTableWidthMode", blockId: e.blockId, mode: i },
655
666
  mapPosition: b,
656
667
  dirtyBlockIds: [e.blockId]
657
668
  };
658
669
  }
659
670
  case "setTablePreferredWidth": {
660
- const { where: n, bi: s, block: o } = g(t, e.blockId), i = o.preferredWidth, r = { ...o };
661
- return e.width ? r.preferredWidth = e.width : delete r.preferredWidth, {
662
- doc: m(t, n, s, r),
671
+ const { where: n, bi: s, block: r } = g(t, e.blockId), i = r.preferredWidth, o = { ...r };
672
+ return e.width ? o.preferredWidth = e.width : delete o.preferredWidth, {
673
+ doc: m(t, n, s, o),
663
674
  inverse: { type: "setTablePreferredWidth", blockId: e.blockId, width: i ?? null },
664
675
  mapPosition: b,
665
676
  dirtyBlockIds: [e.blockId]
666
677
  };
667
678
  }
668
679
  case "setTableAlign": {
669
- const { where: n, bi: s, block: o } = g(t, e.blockId), i = o.align, r = { ...o };
670
- return e.align && e.align !== "left" ? r.align = e.align : delete r.align, {
671
- doc: m(t, n, s, r),
680
+ const { where: n, bi: s, block: r } = g(t, e.blockId), i = r.align, o = { ...r };
681
+ return e.align && e.align !== "left" ? o.align = e.align : delete o.align, {
682
+ doc: m(t, n, s, o),
672
683
  inverse: { type: "setTableAlign", blockId: e.blockId, align: i ?? null },
673
684
  mapPosition: b,
674
685
  dirtyBlockIds: [e.blockId]
675
686
  };
676
687
  }
677
688
  case "setTableProps": {
678
- const { where: n, bi: s, block: o } = g(t, e.blockId), i = Object.keys(e.patch), r = {}, c = { ...o }, l = o, a = r;
689
+ const { where: n, bi: s, block: r } = g(t, e.blockId), i = Object.keys(e.patch), o = {}, a = { ...r }, l = r, c = o;
679
690
  for (const d of i) {
680
- a[d] = l[d] ?? null;
691
+ c[d] = l[d] ?? null;
681
692
  const f = e.patch[d];
682
- f == null ? delete c[d] : c[d] = f;
693
+ f == null ? delete a[d] : a[d] = f;
683
694
  }
684
695
  return {
685
- doc: m(t, n, s, c),
686
- inverse: { type: "setTableProps", blockId: e.blockId, patch: r },
696
+ doc: m(t, n, s, a),
697
+ inverse: { type: "setTableProps", blockId: e.blockId, patch: o },
687
698
  mapPosition: b,
688
699
  dirtyBlockIds: [e.blockId]
689
700
  };
690
701
  }
691
702
  case "setTableRow": {
692
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = o.rows[e.rowIndex];
703
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = r.rows[e.rowIndex];
693
704
  if (!i) throw new Error("setTableRow: no such row");
694
- const r = new Set(i.cells.flatMap((a) => a.blocks.map((d) => d.id))), c = o.rows.slice();
695
- c[e.rowIndex] = e.row;
705
+ const o = new Set(i.cells.flatMap((c) => c.blocks.map((d) => d.id))), a = r.rows.slice();
706
+ a[e.rowIndex] = e.row;
696
707
  const l = O([e.row]);
697
708
  return {
698
- doc: m(t, n, s, { ...o, rows: c }),
709
+ doc: m(t, n, s, { ...r, rows: a }),
699
710
  inverse: { type: "setTableRow", tableId: e.tableId, rowIndex: e.rowIndex, row: i },
700
- mapPosition: (a) => r.has(a.blockId) ? e.row.cells.some((f) => f.blocks.some((h) => h.id === a.blockId)) || !l ? a : { blockId: l.id, offset: 0 } : a,
711
+ mapPosition: (c) => o.has(c.blockId) ? e.row.cells.some((f) => f.blocks.some((h) => h.id === c.blockId)) || !l ? c : { blockId: l.id, offset: 0 } : c,
701
712
  dirtyBlockIds: [e.tableId]
702
713
  };
703
714
  }
704
715
  case "insertTableRow": {
705
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = o.rows.slice();
716
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = r.rows.slice();
706
717
  return i.splice(e.rowIndex, 0, e.row), {
707
- doc: m(t, n, s, { ...o, rows: i }),
718
+ doc: m(t, n, s, { ...r, rows: i }),
708
719
  inverse: { type: "removeTableRow", tableId: e.tableId, rowIndex: e.rowIndex },
709
720
  mapPosition: b,
710
721
  dirtyBlockIds: [e.tableId]
711
722
  };
712
723
  }
713
724
  case "removeTableRow": {
714
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = o.rows[e.rowIndex];
725
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = r.rows[e.rowIndex];
715
726
  if (!i) throw new Error("removeTableRow: no such row");
716
- const r = o.rows.slice();
717
- r.splice(e.rowIndex, 1);
718
- const c = new Set(i.cells.flatMap((d) => d.blocks.map((f) => f.id))), l = r[Math.min(e.rowIndex, r.length - 1)], a = l ? O([l]) : void 0;
727
+ const o = r.rows.slice();
728
+ o.splice(e.rowIndex, 1);
729
+ const a = new Set(i.cells.flatMap((d) => d.blocks.map((f) => f.id))), l = o[Math.min(e.rowIndex, o.length - 1)], c = l ? O([l]) : void 0;
719
730
  return {
720
- doc: m(t, n, s, { ...o, rows: r }),
731
+ doc: m(t, n, s, { ...r, rows: o }),
721
732
  inverse: { type: "insertTableRow", tableId: e.tableId, rowIndex: e.rowIndex, row: i },
722
- mapPosition: (d) => c.has(d.blockId) && a ? { blockId: a.id, offset: 0 } : d,
733
+ mapPosition: (d) => a.has(d.blockId) && c ? { blockId: c.id, offset: 0 } : d,
723
734
  dirtyBlockIds: [e.tableId]
724
735
  };
725
736
  }
726
737
  case "setRowHeight": {
727
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = o.rows[e.rowIndex];
738
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = r.rows[e.rowIndex];
728
739
  if (!i) throw new Error("setRowHeight: no such row");
729
- const r = i.props?.height ?? null, c = { ...i }, l = { ...i.props ?? {} };
730
- e.height ? l.height = e.height : delete l.height, Object.keys(l).length ? c.props = l : delete c.props;
731
- const a = o.rows.slice();
732
- return a[e.rowIndex] = c, {
733
- doc: m(t, n, s, { ...o, rows: a }),
734
- inverse: { type: "setRowHeight", tableId: e.tableId, rowIndex: e.rowIndex, height: r },
740
+ const o = i.props?.height ?? null, a = { ...i }, l = { ...i.props ?? {} };
741
+ e.height ? l.height = e.height : delete l.height, Object.keys(l).length ? a.props = l : delete a.props;
742
+ const c = r.rows.slice();
743
+ return c[e.rowIndex] = a, {
744
+ doc: m(t, n, s, { ...r, rows: c }),
745
+ inverse: { type: "setRowHeight", tableId: e.tableId, rowIndex: e.rowIndex, height: o },
735
746
  mapPosition: b,
736
747
  dirtyBlockIds: [e.tableId]
737
748
  };
@@ -748,24 +759,24 @@ function Ke(t, e) {
748
759
  };
749
760
  }
750
761
  case "setTableStructure": {
751
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = new Set(
752
- o.rows.flatMap((a) => a.cells.flatMap((d) => d.blocks.map((f) => f.id)))
753
- ), r = O(e.rows), c = { ...o, rows: e.rows };
754
- e.colFractions ? c.colFractions = e.colFractions : delete c.colFractions;
755
- const l = { type: "setTableStructure", tableId: e.tableId, rows: o.rows };
756
- return o.colFractions && (l.colFractions = o.colFractions), {
757
- doc: m(t, n, s, c),
762
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = new Set(
763
+ r.rows.flatMap((c) => c.cells.flatMap((d) => d.blocks.map((f) => f.id)))
764
+ ), o = O(e.rows), a = { ...r, rows: e.rows };
765
+ e.colFractions ? a.colFractions = e.colFractions : delete a.colFractions;
766
+ const l = { type: "setTableStructure", tableId: e.tableId, rows: r.rows };
767
+ return r.colFractions && (l.colFractions = r.colFractions), {
768
+ doc: m(t, n, s, a),
758
769
  inverse: l,
759
- mapPosition: (a) => i.has(a.blockId) ? e.rows.some(
760
- (f) => f.cells.some((h) => h.blocks.some((u) => u.id === a.blockId))
761
- ) || !r ? a : { blockId: r.id, offset: 0 } : a,
770
+ mapPosition: (c) => i.has(c.blockId) ? e.rows.some(
771
+ (f) => f.cells.some((h) => h.blocks.some((u) => u.id === c.blockId))
772
+ ) || !o ? c : { blockId: o.id, offset: 0 } : c,
762
773
  dirtyBlockIds: [e.tableId]
763
774
  };
764
775
  }
765
776
  case "insertTableColumn": {
766
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = { type: "setTableStructure", tableId: e.tableId, rows: o.rows };
767
- o.colFractions && (i.colFractions = o.colFractions);
768
- const r = o.rows.map((l, a) => {
777
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = { type: "setTableStructure", tableId: e.tableId, rows: r.rows };
778
+ r.colFractions && (i.colFractions = r.colFractions);
779
+ const o = r.rows.map((l, c) => {
769
780
  const d = [];
770
781
  let f = 0, h = !1;
771
782
  for (const u of l.cells) {
@@ -773,25 +784,25 @@ function Ke(t, e) {
773
784
  if (!h && e.colIndex > f && e.colIndex < f + I)
774
785
  d.push({ ...u, colSpan: I + 1 }), h = !0;
775
786
  else if (!h && e.colIndex === f) {
776
- const P = e.cells[a];
787
+ const P = e.cells[c];
777
788
  P && d.push(P), d.push(u), h = !0;
778
789
  } else
779
790
  d.push(u);
780
791
  f += I;
781
792
  }
782
793
  if (!h) {
783
- const u = e.cells[a];
794
+ const u = e.cells[c];
784
795
  u && d.push(u);
785
796
  }
786
797
  return { cells: d };
787
798
  });
788
- let c = e.fractions;
789
- if (!c) {
790
- const l = $(o), a = 1 / (l.length + 1);
791
- c = l.map((d) => d * (1 - a)), c.splice(e.colIndex, 0, a);
799
+ let a = e.fractions;
800
+ if (!a) {
801
+ const l = W(r), c = 1 / (l.length + 1);
802
+ a = l.map((d) => d * (1 - c)), a.splice(e.colIndex, 0, c);
792
803
  }
793
804
  return {
794
- doc: m(t, n, s, { ...o, rows: r, colFractions: c }),
805
+ doc: m(t, n, s, { ...r, rows: o, colFractions: a }),
795
806
  inverse: i,
796
807
  mapPosition: b,
797
808
  dirtyBlockIds: [e.tableId]
@@ -818,10 +829,10 @@ function Ke(t, e) {
818
829
  };
819
830
  }
820
831
  case "setTableStyleRef": {
821
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = o.styleId ?? null, r = o.condOverrides ?? null, c = { ...o };
822
- 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), {
823
- doc: m(t, n, s, c),
824
- inverse: { type: "setTableStyleRef", tableId: e.tableId, styleId: i, condOverrides: r },
832
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = r.styleId ?? null, o = r.condOverrides ?? null, a = { ...r };
833
+ return e.styleId === null ? delete a.styleId : a.styleId = e.styleId, e.condOverrides !== void 0 && (e.condOverrides === null ? delete a.condOverrides : a.condOverrides = e.condOverrides), {
834
+ doc: m(t, n, s, a),
835
+ inverse: { type: "setTableStyleRef", tableId: e.tableId, styleId: i, condOverrides: o },
825
836
  mapPosition: b,
826
837
  dirtyBlockIds: [e.tableId]
827
838
  };
@@ -839,14 +850,14 @@ function Ke(t, e) {
839
850
  pageBorders: n.pageBorders ?? null,
840
851
  breakType: n.breakType ?? null,
841
852
  lineNumbering: n.lineNumbering ? { ...n.lineNumbering } : null
842
- }, o = {
853
+ }, r = {
843
854
  ...n,
844
855
  pageWidthPx: e.geometry.pageWidthPx,
845
856
  pageHeightPx: e.geometry.pageHeightPx,
846
857
  marginPx: e.geometry.marginPx
847
858
  };
848
- 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, e.geometry.breakType !== null ? o.breakType = e.geometry.breakType : delete o.breakType, e.geometry.lineNumbering !== null ? o.lineNumbering = e.geometry.lineNumbering : delete o.lineNumbering, {
849
- doc: { ...t, section: o },
859
+ return e.geometry.columns ? r.columns = e.geometry.columns : delete r.columns, e.geometry.pageNumberStart !== null ? r.pageNumberStart = e.geometry.pageNumberStart : delete r.pageNumberStart, e.geometry.headerDistancePx !== null ? r.headerDistancePx = e.geometry.headerDistancePx : delete r.headerDistancePx, e.geometry.footerDistancePx !== null ? r.footerDistancePx = e.geometry.footerDistancePx : delete r.footerDistancePx, e.geometry.pageColorHex !== null ? r.pageColorHex = e.geometry.pageColorHex : delete r.pageColorHex, e.geometry.pageBorders !== null ? r.pageBorders = e.geometry.pageBorders : delete r.pageBorders, e.geometry.breakType !== null ? r.breakType = e.geometry.breakType : delete r.breakType, e.geometry.lineNumbering !== null ? r.lineNumbering = e.geometry.lineNumbering : delete r.lineNumbering, {
860
+ doc: { ...t, section: r },
850
861
  inverse: { type: "setSectionProps", geometry: s },
851
862
  mapPosition: b,
852
863
  dirtyBlockIds: []
@@ -856,22 +867,22 @@ function Ke(t, e) {
856
867
  case "setFootnote": {
857
868
  const n = t.footnotes?.[e.noteId] ?? null, s = { ...t.footnotes ?? {} };
858
869
  e.paras ? s[e.noteId] = e.paras : delete s[e.noteId];
859
- const o = new Set((n ?? []).map((r) => r.id)), i = t.blocks.find((r) => r.kind === "paragraph");
870
+ const r = new Set((n ?? []).map((o) => o.id)), i = t.blocks.find((o) => o.kind === "paragraph");
860
871
  return {
861
872
  doc: { ...t, footnotes: s },
862
873
  inverse: { type: "setFootnote", noteId: e.noteId, paras: n },
863
- mapPosition: (r) => o.has(r.blockId) ? (e.paras ?? []).some((l) => l.id === r.blockId) || !i ? r : { blockId: i.id, offset: 0 } : r,
874
+ mapPosition: (o) => r.has(o.blockId) ? (e.paras ?? []).some((l) => l.id === o.blockId) || !i ? o : { blockId: i.id, offset: 0 } : o,
864
875
  dirtyBlockIds: []
865
876
  };
866
877
  }
867
878
  case "setEndnote": {
868
879
  const n = t.endnotes?.[e.noteId] ?? null, s = { ...t.endnotes ?? {} };
869
880
  e.paras ? s[e.noteId] = e.paras : delete s[e.noteId];
870
- const o = new Set((n ?? []).map((r) => r.id)), i = t.blocks.find((r) => r.kind === "paragraph");
881
+ const r = new Set((n ?? []).map((o) => o.id)), i = t.blocks.find((o) => o.kind === "paragraph");
871
882
  return {
872
883
  doc: { ...t, endnotes: s },
873
884
  inverse: { type: "setEndnote", noteId: e.noteId, paras: n },
874
- mapPosition: (r) => o.has(r.blockId) ? (e.paras ?? []).some((l) => l.id === r.blockId) || !i ? r : { blockId: i.id, offset: 0 } : r,
885
+ mapPosition: (o) => r.has(o.blockId) ? (e.paras ?? []).some((l) => l.id === o.blockId) || !i ? o : { blockId: i.id, offset: 0 } : o,
875
886
  dirtyBlockIds: []
876
887
  };
877
888
  }
@@ -895,6 +906,24 @@ function Ke(t, e) {
895
906
  // run/block fieldId markers change via setRuns/insert ops
896
907
  };
897
908
  }
909
+ case "setTemplateVariable": {
910
+ const n = t.templateVariables?.[e.key] ?? null, s = { ...t.templateVariables ?? {} };
911
+ return e.def ? s[e.key] = e.def : delete s[e.key], {
912
+ doc: { ...t, templateVariables: s },
913
+ inverse: { type: "setTemplateVariable", key: e.key, def: n },
914
+ mapPosition: b,
915
+ dirtyBlockIds: []
916
+ };
917
+ }
918
+ case "setVariableDisplayMode": {
919
+ const n = t.variableDisplayMode ?? "code";
920
+ return {
921
+ doc: { ...t, variableDisplayMode: e.mode },
922
+ inverse: { type: "setVariableDisplayMode", mode: n },
923
+ mapPosition: b,
924
+ dirtyBlockIds: []
925
+ };
926
+ }
898
927
  case "setTocInstruction": {
899
928
  const n = t.tocInstruction ?? null, s = { ...t };
900
929
  return e.instruction !== null ? s.tocInstruction = e.instruction : delete s.tocInstruction, {
@@ -917,20 +946,20 @@ function Ke(t, e) {
917
946
  case "setSectionBand": {
918
947
  const n = t.section[e.band] ?? null, s = { ...t.section };
919
948
  e.blocks ? s[e.band] = e.blocks : delete s[e.band];
920
- const o = new Set(
921
- (n ?? []).filter((r) => r.kind === "paragraph").map((r) => r.id)
922
- ), i = t.blocks.find((r) => r.kind === "paragraph");
949
+ const r = new Set(
950
+ (n ?? []).filter((o) => o.kind === "paragraph").map((o) => o.id)
951
+ ), i = t.blocks.find((o) => o.kind === "paragraph");
923
952
  return {
924
953
  doc: { ...t, section: s },
925
954
  inverse: { type: "setSectionBand", band: e.band, blocks: n },
926
- mapPosition: (r) => o.has(r.blockId) ? (e.blocks ?? []).some((l) => l.id === r.blockId) || !i ? r : { blockId: i.id, offset: 0 } : r,
955
+ mapPosition: (o) => r.has(o.blockId) ? (e.blocks ?? []).some((l) => l.id === o.blockId) || !i ? o : { blockId: i.id, offset: 0 } : o,
927
956
  dirtyBlockIds: []
928
957
  };
929
958
  }
930
959
  case "removeTableColumn": {
931
- const { where: n, bi: s, block: o } = g(t, e.tableId), i = { type: "setTableStructure", tableId: e.tableId, rows: o.rows };
932
- o.colFractions && (i.colFractions = o.colFractions);
933
- const r = $(o), c = /* @__PURE__ */ new Set(), l = o.rows.map((u) => {
960
+ const { where: n, bi: s, block: r } = g(t, e.tableId), i = { type: "setTableStructure", tableId: e.tableId, rows: r.rows };
961
+ r.colFractions && (i.colFractions = r.colFractions);
962
+ const o = W(r), a = /* @__PURE__ */ new Set(), l = r.rows.map((u) => {
934
963
  const I = [];
935
964
  let P = 0;
936
965
  for (const C of u.cells) {
@@ -940,17 +969,17 @@ function Ke(t, e) {
940
969
  const T = { ...C };
941
970
  B - 1 > 1 ? T.colSpan = B - 1 : delete T.colSpan, I.push(T);
942
971
  } else
943
- for (const T of C.blocks) c.add(T.id);
972
+ for (const T of C.blocks) a.add(T.id);
944
973
  else
945
974
  I.push(C);
946
975
  P += B;
947
976
  }
948
977
  return { cells: I };
949
- }), a = r.filter((u, I) => I !== e.colIndex), d = a.reduce((u, I) => u + I, 0) || 1, f = a.map((u) => u / d), h = O(l);
978
+ }), c = o.filter((u, I) => I !== e.colIndex), d = c.reduce((u, I) => u + I, 0) || 1, f = c.map((u) => u / d), h = O(l);
950
979
  return {
951
- doc: m(t, n, s, { ...o, rows: l, colFractions: f }),
980
+ doc: m(t, n, s, { ...r, rows: l, colFractions: f }),
952
981
  inverse: i,
953
- mapPosition: (u) => c.has(u.blockId) && h ? { blockId: h.id, offset: 0 } : u,
982
+ mapPosition: (u) => a.has(u.blockId) && h ? { blockId: h.id, offset: 0 } : u,
954
983
  dirtyBlockIds: [e.tableId]
955
984
  };
956
985
  }
@@ -968,13 +997,13 @@ let _ = ie("local");
968
997
  function et(t, e = 0) {
969
998
  _ = ie(t, e);
970
999
  }
971
- function Q() {
1000
+ function J() {
972
1001
  return _.next();
973
1002
  }
974
1003
  function tt() {
975
1004
  return _.siteId;
976
1005
  }
977
- const Z = (t) => {
1006
+ const Q = (t) => {
978
1007
  if (!t) return;
979
1008
  const e = t.match(/^(\d+)\s*-\s*(\d+)$/);
980
1009
  if (e) return { from: Number(e[1]), to: Number(e[2]) };
@@ -986,101 +1015,101 @@ function Be(t) {
986
1015
  useOutlineLevels: /\\u\b/.test(t),
987
1016
  hyperlinks: /\\h\b/.test(t),
988
1017
  hideInWeb: /\\z\b/.test(t)
989
- }, n = Z(t.match(/\\o\s+"([^"]+)"/)?.[1]);
1018
+ }, n = Q(t.match(/\\o\s+"([^"]+)"/)?.[1]);
990
1019
  n && (e.outlineRange = n);
991
- const s = Z(t.match(/\\n\s+"?([0-9-]+)"?/)?.[1]);
1020
+ const s = Q(t.match(/\\n\s+"?([0-9-]+)"?/)?.[1]);
992
1021
  s && (e.hidePageNumberRange = s);
993
- const o = t.match(/\\p\s+"([^"]*)"/)?.[1];
994
- o !== void 0 && (e.separator = o);
1022
+ const r = t.match(/\\p\s+"([^"]*)"/)?.[1];
1023
+ r !== void 0 && (e.separator = r);
995
1024
  const i = t.match(/\\t\s+"([^"]+)"/)?.[1];
996
1025
  if (i) {
997
- const r = i.split(","), c = {};
998
- for (let l = 0; l + 1 < r.length; l += 2) {
999
- const a = r[l].trim(), d = Number(r[l + 1].trim());
1000
- a && d >= 1 && (c[a] = d);
1026
+ const o = i.split(","), a = {};
1027
+ for (let l = 0; l + 1 < o.length; l += 2) {
1028
+ const c = o[l].trim(), d = Number(o[l + 1].trim());
1029
+ c && d >= 1 && (a[c] = d);
1001
1030
  }
1002
- Object.keys(c).length > 0 && (e.customStyles = c);
1031
+ Object.keys(a).length > 0 && (e.customStyles = a);
1003
1032
  }
1004
1033
  return e;
1005
1034
  }
1006
1035
  function nt(t) {
1007
1036
  const e = ["TOC"];
1008
1037
  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) {
1009
- const n = Object.entries(t.customStyles).map(([s, o]) => `${s},${o}`).join(",");
1038
+ const n = Object.entries(t.customStyles).map(([s, r]) => `${s},${r}`).join(",");
1010
1039
  e.push(`\\t "${n}"`);
1011
1040
  }
1012
1041
  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(" ")} `;
1013
1042
  }
1014
1043
  const st = (t, e) => !!t && e >= t.from && e <= t.to;
1015
- function K(t, e) {
1044
+ function Z(t, e) {
1016
1045
  if (!e || !t.stylesheet) return;
1017
1046
  const n = new Map(t.stylesheet.styles.map((i) => [i.id, i]));
1018
1047
  let s = n.get(e);
1019
- const o = /* @__PURE__ */ new Set();
1020
- for (; s && !o.has(s.id); ) {
1048
+ const r = /* @__PURE__ */ new Set();
1049
+ for (; s && !r.has(s.id); ) {
1021
1050
  if (s.name && /(?:^|\s)heading\s*\d/i.test(s.name)) return s.name;
1022
- o.add(s.id), s = s.basedOn ? n.get(s.basedOn) : void 0;
1051
+ r.add(s.id), s = s.basedOn ? n.get(s.basedOn) : void 0;
1023
1052
  }
1024
1053
  return n.get(e)?.name;
1025
1054
  }
1026
1055
  function Te(t, e, n) {
1027
1056
  const s = t.style.namedStyle;
1028
1057
  if (n?.customStyles && s) {
1029
- const r = n.customStyles[s] ?? n.customStyles[K(e, s) ?? ""];
1030
- if (r) return r;
1058
+ const o = n.customStyles[s] ?? n.customStyles[Z(e, s) ?? ""];
1059
+ if (o) return o;
1031
1060
  }
1032
1061
  if (t.style.outlineLevel !== void 0) return t.style.outlineLevel + 1;
1033
- const o = s?.match(/^heading\s*(\d)$/i);
1034
- if (o) return Number(o[1]);
1035
- const i = K(e, s)?.match(/(?:^|\s)heading\s*(\d)/i);
1062
+ const r = s?.match(/^heading\s*(\d)$/i);
1063
+ if (r) return Number(r[1]);
1064
+ const i = Z(e, s)?.match(/(?:^|\s)heading\s*(\d)/i);
1036
1065
  return i ? Number(i[1]) : null;
1037
1066
  }
1038
1067
  function Re(t, e, n = 3) {
1039
- const s = e?.outlineRange?.to ?? n, o = [];
1068
+ const s = e?.outlineRange?.to ?? n, r = [];
1040
1069
  for (const i of le(t)) {
1041
- const r = Te(i, t, e);
1042
- r === null || r < 1 || r > s || e?.outlineRange && (r < e.outlineRange.from || r > e.outlineRange.to) || o.push({ block: i, level: r });
1070
+ const o = Te(i, t, e);
1071
+ o === null || o < 1 || o > s || e?.outlineRange && (o < e.outlineRange.from || o > e.outlineRange.to) || r.push({ block: i, level: o });
1043
1072
  }
1044
- return o;
1073
+ return r;
1045
1074
  }
1046
- function ot(t, e = 20) {
1075
+ function rt(t, e = 20) {
1047
1076
  if (!t.bookmarks) return 0;
1048
1077
  const n = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right;
1049
1078
  let s = 0;
1050
- for (const o of t.blocks) {
1051
- if (o.kind !== "paragraph" || o.style.tocEntry) continue;
1052
- const i = o.runs.find((d) => d.style.link?.startsWith("#"))?.style.link?.slice(1);
1079
+ for (const r of t.blocks) {
1080
+ if (r.kind !== "paragraph" || r.style.tocEntry) continue;
1081
+ const i = r.runs.find((d) => d.style.link?.startsWith("#"))?.style.link?.slice(1);
1053
1082
  if (!i) continue;
1054
- const r = t.bookmarks[i]?.start.blockId;
1055
- if (!r) continue;
1056
- const c = F(o.runs), l = c.match(/\t\d+\s*$/);
1083
+ const o = t.bookmarks[i]?.start.blockId;
1084
+ if (!o) continue;
1085
+ const a = F(r.runs), l = a.match(/\t\d+\s*$/);
1057
1086
  if (!l) continue;
1058
- o.runs = re(o.runs, 0, c.length - l[0].length), o.runs.length === 0 && (o.runs = [{ text: "", style: { ...A } }]);
1059
- const a = Math.min(9, Math.max(1, Math.round((o.style.indentLeftPx || 0) / e) + 1));
1060
- o.style.tocEntry = { targetId: r, level: a }, !o.style.tabStops?.length && n > 0 && (o.style.tabStops = [{ posPx: n, align: "right", leader: "dot" }]), o.revision++, s++;
1087
+ r.runs = oe(r.runs, 0, a.length - l[0].length), r.runs.length === 0 && (r.runs = [{ text: "", style: { ...A } }]);
1088
+ const c = Math.min(9, Math.max(1, Math.round((r.style.indentLeftPx || 0) / e) + 1));
1089
+ r.style.tocEntry = { targetId: o, level: c }, !r.style.tabStops?.length && n > 0 && (r.style.tabStops = [{ posPx: n, align: "right", leader: "dot" }]), r.revision++, s++;
1061
1090
  }
1062
1091
  return s;
1063
1092
  }
1064
- const A = { ...oe, fontSizePx: 13 }, Ee = 20;
1093
+ const A = { ...re, fontSizePx: 13 }, Ee = 20;
1065
1094
  function Fe(t, e, n, s) {
1066
- const o = t.indentStepPx ?? Ee, i = t.leader ?? "dot", r = { align: "left", lineHeight: 1.5, spaceBeforePx: 0, spaceAfterPx: 2, indentFirstLinePx: 0 };
1067
- let c, l;
1095
+ const r = t.indentStepPx ?? Ee, i = t.leader ?? "dot", o = { align: "left", lineHeight: 1.5, spaceBeforePx: 0, spaceAfterPx: 2, indentFirstLinePx: 0 };
1096
+ let a, l;
1068
1097
  if (s && (s.char || s.para)) {
1069
- c = { ...A, ...s.char, ...t.baseChar, ...t.levels?.[e]?.char };
1070
- const a = s.para?.indentLeftPx ?? 0;
1098
+ a = { ...A, ...s.char, ...t.baseChar, ...t.levels?.[e]?.char };
1099
+ const c = s.para?.indentLeftPx ?? 0;
1071
1100
  l = {
1072
- ...r,
1101
+ ...o,
1073
1102
  ...s.para,
1074
- indentLeftPx: a + (e - 1) * o,
1103
+ indentLeftPx: c + (e - 1) * r,
1075
1104
  ...t.levels?.[e]?.para
1076
1105
  };
1077
1106
  } else
1078
- c = { ...{ ...A, ...t.baseChar }, fontSizePx: e === 1 ? 14 : 13, bold: e === 1, ...t.levels?.[e]?.char }, l = {
1079
- ...r,
1080
- indentLeftPx: (e - 1) * o,
1107
+ a = { ...{ ...A, ...t.baseChar }, fontSizePx: e === 1 ? 14 : 13, bold: e === 1, ...t.levels?.[e]?.char }, l = {
1108
+ ...o,
1109
+ indentLeftPx: (e - 1) * r,
1081
1110
  ...t.levels?.[e]?.para
1082
1111
  };
1083
- return i !== "none" && n > 0 ? l.tabStops = [{ posPx: n, align: "right", leader: i }] : delete l.tabStops, { char: c, para: l };
1112
+ return i !== "none" && n > 0 ? l.tabStops = [{ posPx: n, align: "right", leader: i }] : delete l.tabStops, { char: a, para: l };
1084
1113
  }
1085
1114
  function Ce(t) {
1086
1115
  if (t.title === null) return null;
@@ -1102,95 +1131,95 @@ function Ce(t) {
1102
1131
  }
1103
1132
  const Oe = 3;
1104
1133
  function Ne(t, e = {}) {
1105
- const n = t.tocInstruction ? Be(t.tocInstruction) : void 0, s = e.maxLevel ?? n?.outlineRange?.to ?? Oe, o = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right, i = t.tocAnchorBlockId ? t.blocks.find((a) => a.kind === "paragraph" && a.id === t.tocAnchorBlockId) : void 0, r = i ? { char: i.runs[0]?.style, para: i.style } : void 0, c = [];
1134
+ const n = t.tocInstruction ? Be(t.tocInstruction) : void 0, s = e.maxLevel ?? n?.outlineRange?.to ?? Oe, r = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right, i = t.tocAnchorBlockId ? t.blocks.find((c) => c.kind === "paragraph" && c.id === t.tocAnchorBlockId) : void 0, o = i ? { char: i.runs[0]?.style, para: i.style } : void 0, a = [];
1106
1135
  if (e.title !== void 0 ? e.title !== null : i === void 0) {
1107
- const a = Ce(e);
1108
- a && c.push({
1136
+ const c = Ce(e);
1137
+ c && a.push({
1109
1138
  kind: "paragraph",
1110
- id: Q(),
1139
+ id: J(),
1111
1140
  revision: 0,
1112
- runs: [{ text: a.text, style: a.char }],
1113
- style: a.para
1141
+ runs: [{ text: c.text, style: c.char }],
1142
+ style: c.para
1114
1143
  });
1115
1144
  }
1116
- for (const { block: a, level: d } of Re(t, n, s)) {
1117
- const f = F(a.runs).replace(/\v/g, " ").trim();
1145
+ for (const { block: c, level: d } of Re(t, n, s)) {
1146
+ const f = F(c.runs).replace(/\v/g, " ").trim();
1118
1147
  if (f.length === 0) continue;
1119
- const { char: h, para: u } = Fe(e, d, o, r);
1120
- c.push({
1148
+ const { char: h, para: u } = Fe(e, d, r, o);
1149
+ a.push({
1121
1150
  kind: "paragraph",
1122
- id: Q(),
1151
+ id: J(),
1123
1152
  revision: 0,
1124
1153
  runs: [{ text: f, style: h }],
1125
- style: { ...u, tocEntry: { targetId: a.id, level: d } }
1154
+ style: { ...u, tocEntry: { targetId: c.id, level: d } }
1126
1155
  });
1127
1156
  }
1128
- return c;
1157
+ return a;
1129
1158
  }
1130
- function rt(t, e = {}) {
1131
- if (t.blocks.some((r) => r.kind === "paragraph" && r.style.tocEntry))
1159
+ function ot(t, e = {}) {
1160
+ if (t.blocks.some((o) => o.kind === "paragraph" && o.style.tocEntry))
1132
1161
  return { doc: t, generated: 0, headings: 0 };
1133
1162
  if (t.tocAnchorBlockId === void 0) return { doc: t, generated: 0, headings: 0 };
1134
- const n = t.blocks.findIndex((r) => r.id === t.tocAnchorBlockId);
1163
+ const n = t.blocks.findIndex((o) => o.id === t.tocAnchorBlockId);
1135
1164
  if (n < 0) return { doc: t, generated: 0, headings: 0 };
1136
- const s = Ne(t, e), o = s.reduce((r, c) => r + (c.style.tocEntry ? 1 : 0), 0);
1137
- if (o === 0) return { doc: t, generated: 0, headings: 0 };
1165
+ const s = Ne(t, e), r = s.reduce((o, a) => o + (a.style.tocEntry ? 1 : 0), 0);
1166
+ if (r === 0) return { doc: t, generated: 0, headings: 0 };
1138
1167
  const i = [...t.blocks];
1139
- return i.splice(n, 1, ...s), { doc: { ...t, blocks: i }, generated: o, headings: o };
1168
+ return i.splice(n, 1, ...s), { doc: { ...t, blocks: i }, generated: r, headings: r };
1140
1169
  }
1141
1170
  export {
1142
- ot as $,
1143
- De as A,
1171
+ et as $,
1172
+ Qe as A,
1144
1173
  S as B,
1145
- X as C,
1146
- oe as D,
1147
- Je as E,
1148
- Ve as F,
1149
- Q as G,
1150
- ne as H,
1151
- y as I,
1152
- x as J,
1153
- re as K,
1154
- qe as L,
1155
- ze as M,
1156
- Xe as N,
1157
- Ne as O,
1158
- le as P,
1159
- Ge as Q,
1160
- Le as R,
1161
- Ae as S,
1162
- je as T,
1163
- _e as U,
1164
- q as V,
1165
- se as W,
1166
- H as X,
1167
- $ as Y,
1168
- et as Z,
1169
- ie as _,
1170
- ae as a,
1171
- nt as b,
1172
- Fe as c,
1174
+ M as C,
1175
+ re as D,
1176
+ te as E,
1177
+ Pe as F,
1178
+ Ke as G,
1179
+ Ge as H,
1180
+ We as I,
1181
+ He as J,
1182
+ Y as K,
1183
+ Xe as L,
1184
+ Ue as M,
1185
+ y as N,
1186
+ oe as O,
1187
+ qe as P,
1188
+ ze as Q,
1189
+ Ye as R,
1190
+ Ne as S,
1191
+ le as T,
1192
+ Le as U,
1193
+ Ae as V,
1194
+ je as W,
1195
+ _e as X,
1196
+ q as Y,
1197
+ se as Z,
1198
+ H as _,
1199
+ Be as a,
1200
+ Fe as b,
1201
+ de as c,
1173
1202
  Re as d,
1174
- Se as e,
1175
- Ke as f,
1176
- rt as g,
1177
- We as h,
1203
+ $e as e,
1204
+ ie as f,
1205
+ Se as g,
1206
+ Ve as h,
1178
1207
  st as i,
1179
- de as j,
1180
- Qe as k,
1181
- Me as l,
1182
- W as m,
1183
- tt as n,
1184
- k as o,
1185
- Be as p,
1186
- Ze as q,
1187
- M as r,
1208
+ nt as j,
1209
+ ot as k,
1210
+ J as l,
1211
+ rt as m,
1212
+ x as n,
1213
+ W as o,
1214
+ ce as p,
1215
+ ne as q,
1216
+ Ze as r,
1188
1217
  ue as s,
1189
1218
  F as t,
1190
- Pe as u,
1191
- Ue as v,
1192
- te as w,
1193
- Ye as x,
1194
- $e as y,
1195
- He as z
1219
+ De as u,
1220
+ Je as v,
1221
+ Me as w,
1222
+ D as x,
1223
+ tt as y,
1224
+ k as z
1196
1225
  };