kindy-editor 3.2.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/assets/{worker-_GAJUHf5.js → worker-DO8U44KQ.js} +1 -0
- package/dist-lib/builder.js +4 -4
- package/dist-lib/{editorApp-7-JzxxVn.js → editorApp-N20nk5uQ.js} +9214 -8515
- package/dist-lib/events.js +1 -1
- package/dist-lib/export.js +1396 -1385
- package/dist-lib/generate-toc.js +3 -3
- package/dist-lib/import.js +2 -2
- package/dist-lib/index-Dd7gMK7l.js +12857 -0
- package/dist-lib/{kindy-editor-DKDwpt09.js → kindy-editor-D4xSNtvA.js} +133 -83
- package/dist-lib/kindy-editor.js +1 -1
- package/dist-lib/{parse-D4RpPrd7.js → parse-JE_w0NNt.js} +3 -3
- package/dist-lib/{pipeline-DhhBcLvV.js → pipeline-CgbvBwNe.js} +1 -1
- package/dist-lib/recalc-docx.js +1 -1
- package/dist-lib/{recalcToc-n50vq4nC.js → recalcToc-DKJK9f5X.js} +1 -1
- package/dist-lib/{stylesheet-E5bu1xch.js → stylesheet-COz2MSt6.js} +1 -1
- package/dist-lib/{toc-DSwkNKls.js → toc-C6XLbDEA.js} +389 -360
- package/dist-lib/{webmcp-KVT__0GH.js → webmcp-DrpPKUeh.js} +2 -2
- package/docs/.vitepress/config.ts +2 -0
- package/docs/public-events.md +1 -0
- package/docs/template-variables.md +310 -0
- package/package.json +1 -1
- package/types/kindy-editor.d.ts +122 -3
- package/dist-lib/index-Brv5TV-9.js +0 -11822
|
@@ -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
|
|
14
|
-
for (const i of
|
|
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(),
|
|
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
|
|
25
|
-
n.has(
|
|
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 =
|
|
31
|
-
},
|
|
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
|
-
},
|
|
38
|
-
let e =
|
|
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
|
|
42
|
-
e = n,
|
|
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
|
-
},
|
|
46
|
-
let e =
|
|
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 =
|
|
49
|
+
e = ce(t).filter((s) => !n.has(s.id) && !ne(s)), K.set(t, e);
|
|
50
50
|
}
|
|
51
51
|
return e;
|
|
52
|
-
},
|
|
53
|
-
let n =
|
|
54
|
-
n || (n = /* @__PURE__ */ new Map(),
|
|
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((
|
|
57
|
-
},
|
|
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
|
|
61
|
-
},
|
|
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
|
-
|
|
64
|
-
for (const s of S)
|
|
65
|
-
for (const s of Object.values(t.footnotes ?? {})) for (const
|
|
66
|
-
for (const s of Object.values(t.endnotes ?? {})) for (const
|
|
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
|
|
69
|
+
function U(t, e, n) {
|
|
70
70
|
for (let s = 0; s < t.length; s++) {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
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 (
|
|
76
|
-
for (let i = 0; i <
|
|
77
|
-
const
|
|
78
|
-
for (let
|
|
79
|
-
const l =
|
|
80
|
-
for (let
|
|
81
|
-
const d = l.blocks[
|
|
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:
|
|
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 =
|
|
91
|
+
const n = U(t.blocks, "body", e);
|
|
92
92
|
if (n) return n;
|
|
93
93
|
for (const s of S) {
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
94
|
+
const r = U(t.section[s] ?? [], s, e);
|
|
95
|
+
if (r) return r;
|
|
96
96
|
}
|
|
97
|
-
for (const [s,
|
|
98
|
-
const i =
|
|
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,
|
|
102
|
-
const i =
|
|
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(),
|
|
128
|
-
return
|
|
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
|
|
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
|
|
168
|
-
if (e > n && e <=
|
|
169
|
-
n =
|
|
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
|
|
203
|
-
function
|
|
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
|
|
210
|
+
for (let r = 0; r < n; r++) if (t[r] !== e[r]) return !1;
|
|
211
211
|
return !0;
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function Ge(t, e) {
|
|
214
214
|
return t.sdtPath?.includes(e) ?? !1;
|
|
215
215
|
}
|
|
216
|
-
function
|
|
216
|
+
function Ue(t, e) {
|
|
217
217
|
return t && t.length > 0 ? [...t, e] : [e];
|
|
218
218
|
}
|
|
219
|
-
function
|
|
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
|
|
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 = (
|
|
231
|
-
let { left: n, top: s, right:
|
|
232
|
-
if (n +
|
|
233
|
-
const
|
|
234
|
-
n *=
|
|
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
|
|
238
|
-
s *=
|
|
237
|
+
const o = 0.999 / (s + i);
|
|
238
|
+
s *= o, i *= o;
|
|
239
239
|
}
|
|
240
|
-
return { left: n, top: s, right:
|
|
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((
|
|
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
|
|
264
|
-
const i = n[
|
|
265
|
-
Ie(
|
|
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
|
|
272
|
+
let r = 0;
|
|
272
273
|
for (const i of t) {
|
|
273
|
-
const
|
|
274
|
-
|
|
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
|
|
279
|
-
const [, s] = y(t, e), [
|
|
280
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
287
|
-
|
|
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,
|
|
291
|
-
return x([...s, ...n, ...
|
|
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,
|
|
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
|
|
298
|
-
const [
|
|
299
|
-
return x([...
|
|
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
|
|
302
|
-
const [
|
|
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 =
|
|
305
|
-
const u =
|
|
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
|
-
}) :
|
|
308
|
-
return x([...
|
|
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
|
|
333
|
+
function D(t, e) {
|
|
323
334
|
for (const n of ["body", ...S]) {
|
|
324
|
-
const s = k(t, n).findIndex((
|
|
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 =
|
|
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
|
|
336
|
-
return
|
|
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,
|
|
339
|
-
const
|
|
340
|
-
return
|
|
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 =
|
|
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
|
|
355
|
-
if (
|
|
356
|
-
for (let i = 0; i <
|
|
357
|
-
const
|
|
358
|
-
for (let
|
|
359
|
-
const l =
|
|
360
|
-
for (let
|
|
361
|
-
const d = l.blocks[
|
|
362
|
-
if (d.kind === "image" && d.id === e) return { kind: "cell", bi: s, ri: i, ci:
|
|
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 =
|
|
381
|
+
const s = D(t, e);
|
|
371
382
|
if (s) {
|
|
372
|
-
const
|
|
373
|
-
return
|
|
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
|
|
376
|
-
const i = k(t,
|
|
377
|
-
for (let
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
380
|
-
for (let l = 0; l <
|
|
381
|
-
const
|
|
382
|
-
for (let d = 0; d <
|
|
383
|
-
const f =
|
|
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:
|
|
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
|
|
406
|
+
function Y(t, e) {
|
|
396
407
|
return ve(t, e, "equation");
|
|
397
408
|
}
|
|
398
|
-
function
|
|
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
|
|
404
|
-
return
|
|
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
|
|
421
|
+
let r = 0;
|
|
411
422
|
for (const i of s.cells) {
|
|
412
|
-
for (; (n[
|
|
413
|
-
const
|
|
414
|
-
if (
|
|
415
|
-
|
|
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,
|
|
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
|
|
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
|
|
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),
|
|
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,
|
|
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: (
|
|
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),
|
|
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 +
|
|
445
|
-
mapPosition: (
|
|
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),
|
|
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:
|
|
454
|
-
mapPosition: (
|
|
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),
|
|
470
|
-
for (const
|
|
471
|
-
o
|
|
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:
|
|
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), [
|
|
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,
|
|
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
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
521
|
+
f.splice(n.bi, 1, a, l), c = w(t, d, f);
|
|
511
522
|
}
|
|
512
523
|
return {
|
|
513
|
-
doc:
|
|
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
|
|
534
|
+
let r;
|
|
524
535
|
if (n.kind === "cell") {
|
|
525
|
-
const
|
|
526
|
-
if (!
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
547
|
+
r = l;
|
|
537
548
|
} else {
|
|
538
|
-
const l = n.kind === "band" ? n.band : "body",
|
|
539
|
-
if (!
|
|
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
|
-
|
|
552
|
+
r = c;
|
|
542
553
|
}
|
|
543
|
-
const i = F(s.runs).length,
|
|
554
|
+
const i = F(s.runs).length, o = v(
|
|
544
555
|
s,
|
|
545
|
-
x([...s.runs, ...
|
|
556
|
+
x([...s.runs, ...r.runs], p(s.runs, i))
|
|
546
557
|
);
|
|
547
|
-
let
|
|
558
|
+
let a;
|
|
548
559
|
if (n.kind === "cell") {
|
|
549
|
-
const
|
|
550
|
-
|
|
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,
|
|
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,
|
|
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",
|
|
559
|
-
|
|
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:
|
|
573
|
+
doc: a,
|
|
563
574
|
inverse: {
|
|
564
575
|
type: "splitParagraph",
|
|
565
576
|
at: { blockId: s.id, offset: i },
|
|
566
|
-
newBlockId:
|
|
567
|
-
newStyle:
|
|
577
|
+
newBlockId: r.id,
|
|
578
|
+
newStyle: r.style,
|
|
568
579
|
// Restore the merged-away tail's block-level control on undo.
|
|
569
|
-
...
|
|
580
|
+
...r.sdtPath?.length ? { newSdtPath: r.sdtPath } : {}
|
|
570
581
|
},
|
|
571
|
-
mapPosition: (l) => l.blockId ===
|
|
572
|
-
dirtyBlockIds: [s.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 =
|
|
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(),
|
|
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:
|
|
593
|
-
mapPosition: (
|
|
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,
|
|
601
|
-
e.patch.widthPx !== void 0 && (
|
|
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
|
|
615
|
+
let o;
|
|
605
616
|
if (n.kind === "top") {
|
|
606
|
-
const
|
|
607
|
-
|
|
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,
|
|
621
|
+
l[n.ii] = i, o = N(t, "body", n.bi, n.ri, n.ci, l);
|
|
611
622
|
}
|
|
612
623
|
return {
|
|
613
|
-
doc:
|
|
614
|
-
inverse: { type: "setImageProps", blockId: e.blockId, patch:
|
|
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 =
|
|
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,
|
|
633
|
+
const s = n.block.equation, r = { ...n.block, revision: n.block.revision + 1, equation: e.equation };
|
|
623
634
|
return {
|
|
624
|
-
doc:
|
|
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 =
|
|
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",
|
|
644
|
+
const s = n.block.align ?? "center", r = { ...n.block, revision: n.block.revision + 1, align: e.align };
|
|
634
645
|
return {
|
|
635
|
-
doc:
|
|
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:
|
|
653
|
+
const { where: n, bi: s, block: r } = g(t, e.blockId), i = W(r);
|
|
643
654
|
return {
|
|
644
|
-
doc: m(t, n, s, { ...
|
|
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:
|
|
652
|
-
return e.mode && e.mode !== "fixed" ?
|
|
653
|
-
doc: m(t, n, s,
|
|
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:
|
|
661
|
-
return e.width ?
|
|
662
|
-
doc: m(t, n, s,
|
|
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:
|
|
670
|
-
return e.align && e.align !== "left" ?
|
|
671
|
-
doc: m(t, n, s,
|
|
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:
|
|
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
|
-
|
|
691
|
+
c[d] = l[d] ?? null;
|
|
681
692
|
const f = e.patch[d];
|
|
682
|
-
f == null ? delete
|
|
693
|
+
f == null ? delete a[d] : a[d] = f;
|
|
683
694
|
}
|
|
684
695
|
return {
|
|
685
|
-
doc: m(t, n, s,
|
|
686
|
-
inverse: { type: "setTableProps", blockId: e.blockId, patch:
|
|
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:
|
|
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
|
|
695
|
-
|
|
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, { ...
|
|
709
|
+
doc: m(t, n, s, { ...r, rows: a }),
|
|
699
710
|
inverse: { type: "setTableRow", tableId: e.tableId, rowIndex: e.rowIndex, row: i },
|
|
700
|
-
mapPosition: (
|
|
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:
|
|
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, { ...
|
|
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:
|
|
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
|
|
717
|
-
|
|
718
|
-
const
|
|
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, { ...
|
|
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) =>
|
|
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:
|
|
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
|
|
730
|
-
e.height ? l.height = e.height : delete l.height, Object.keys(l).length ?
|
|
731
|
-
const
|
|
732
|
-
return
|
|
733
|
-
doc: m(t, n, s, { ...
|
|
734
|
-
inverse: { type: "setRowHeight", tableId: e.tableId, rowIndex: e.rowIndex, height:
|
|
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:
|
|
752
|
-
|
|
753
|
-
),
|
|
754
|
-
e.colFractions ?
|
|
755
|
-
const l = { type: "setTableStructure", tableId: e.tableId, rows:
|
|
756
|
-
return
|
|
757
|
-
doc: m(t, n, s,
|
|
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: (
|
|
760
|
-
(f) => f.cells.some((h) => h.blocks.some((u) => u.id ===
|
|
761
|
-
) || !
|
|
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:
|
|
767
|
-
|
|
768
|
-
const
|
|
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[
|
|
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[
|
|
794
|
+
const u = e.cells[c];
|
|
784
795
|
u && d.push(u);
|
|
785
796
|
}
|
|
786
797
|
return { cells: d };
|
|
787
798
|
});
|
|
788
|
-
let
|
|
789
|
-
if (!
|
|
790
|
-
const l =
|
|
791
|
-
|
|
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, { ...
|
|
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:
|
|
822
|
-
return e.styleId === null ? delete
|
|
823
|
-
doc: m(t, n, s,
|
|
824
|
-
inverse: { type: "setTableStyleRef", tableId: e.tableId, styleId: i, condOverrides:
|
|
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
|
-
},
|
|
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 ?
|
|
849
|
-
doc: { ...t, section:
|
|
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
|
|
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: (
|
|
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
|
|
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: (
|
|
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
|
|
921
|
-
(n ?? []).filter((
|
|
922
|
-
), i = t.blocks.find((
|
|
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: (
|
|
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:
|
|
932
|
-
|
|
933
|
-
const
|
|
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)
|
|
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
|
-
}),
|
|
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, { ...
|
|
980
|
+
doc: m(t, n, s, { ...r, rows: l, colFractions: f }),
|
|
952
981
|
inverse: i,
|
|
953
|
-
mapPosition: (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
|
|
1000
|
+
function J() {
|
|
972
1001
|
return _.next();
|
|
973
1002
|
}
|
|
974
1003
|
function tt() {
|
|
975
1004
|
return _.siteId;
|
|
976
1005
|
}
|
|
977
|
-
const
|
|
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 =
|
|
1018
|
+
}, n = Q(t.match(/\\o\s+"([^"]+)"/)?.[1]);
|
|
990
1019
|
n && (e.outlineRange = n);
|
|
991
|
-
const s =
|
|
1020
|
+
const s = Q(t.match(/\\n\s+"?([0-9-]+)"?/)?.[1]);
|
|
992
1021
|
s && (e.hidePageNumberRange = s);
|
|
993
|
-
const
|
|
994
|
-
|
|
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
|
|
998
|
-
for (let l = 0; l + 1 <
|
|
999
|
-
const
|
|
1000
|
-
|
|
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(
|
|
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,
|
|
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
|
|
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
|
|
1020
|
-
for (; s && !
|
|
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
|
-
|
|
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
|
|
1030
|
-
if (
|
|
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
|
|
1034
|
-
if (
|
|
1035
|
-
const 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,
|
|
1068
|
+
const s = e?.outlineRange?.to ?? n, r = [];
|
|
1040
1069
|
for (const i of le(t)) {
|
|
1041
|
-
const
|
|
1042
|
-
|
|
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
|
|
1073
|
+
return r;
|
|
1045
1074
|
}
|
|
1046
|
-
function
|
|
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
|
|
1051
|
-
if (
|
|
1052
|
-
const i =
|
|
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
|
|
1055
|
-
if (!
|
|
1056
|
-
const
|
|
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
|
-
|
|
1059
|
-
const
|
|
1060
|
-
|
|
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 = { ...
|
|
1093
|
+
const A = { ...re, fontSizePx: 13 }, Ee = 20;
|
|
1065
1094
|
function Fe(t, e, n, s) {
|
|
1066
|
-
const
|
|
1067
|
-
let
|
|
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
|
-
|
|
1070
|
-
const
|
|
1098
|
+
a = { ...A, ...s.char, ...t.baseChar, ...t.levels?.[e]?.char };
|
|
1099
|
+
const c = s.para?.indentLeftPx ?? 0;
|
|
1071
1100
|
l = {
|
|
1072
|
-
...
|
|
1101
|
+
...o,
|
|
1073
1102
|
...s.para,
|
|
1074
|
-
indentLeftPx:
|
|
1103
|
+
indentLeftPx: c + (e - 1) * r,
|
|
1075
1104
|
...t.levels?.[e]?.para
|
|
1076
1105
|
};
|
|
1077
1106
|
} else
|
|
1078
|
-
|
|
1079
|
-
...
|
|
1080
|
-
indentLeftPx: (e - 1) *
|
|
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:
|
|
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,61 +1131,61 @@ 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,
|
|
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
|
|
1108
|
-
|
|
1136
|
+
const c = Ce(e);
|
|
1137
|
+
c && a.push({
|
|
1109
1138
|
kind: "paragraph",
|
|
1110
|
-
id:
|
|
1139
|
+
id: J(),
|
|
1111
1140
|
revision: 0,
|
|
1112
|
-
runs: [{ text:
|
|
1113
|
-
style:
|
|
1141
|
+
runs: [{ text: c.text, style: c.char }],
|
|
1142
|
+
style: c.para
|
|
1114
1143
|
});
|
|
1115
1144
|
}
|
|
1116
|
-
for (const { block:
|
|
1117
|
-
const f = F(
|
|
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,
|
|
1120
|
-
|
|
1148
|
+
const { char: h, para: u } = Fe(e, d, r, o);
|
|
1149
|
+
a.push({
|
|
1121
1150
|
kind: "paragraph",
|
|
1122
|
-
id:
|
|
1151
|
+
id: J(),
|
|
1123
1152
|
revision: 0,
|
|
1124
1153
|
runs: [{ text: f, style: h }],
|
|
1125
|
-
style: { ...u, tocEntry: { targetId:
|
|
1154
|
+
style: { ...u, tocEntry: { targetId: c.id, level: d } }
|
|
1126
1155
|
});
|
|
1127
1156
|
}
|
|
1128
|
-
return
|
|
1157
|
+
return a;
|
|
1129
1158
|
}
|
|
1130
|
-
function
|
|
1131
|
-
if (t.blocks.some((
|
|
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((
|
|
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),
|
|
1137
|
-
if (
|
|
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:
|
|
1168
|
+
return i.splice(n, 1, ...s), { doc: { ...t, blocks: i }, generated: r, headings: r };
|
|
1140
1169
|
}
|
|
1141
1170
|
export {
|
|
1142
|
-
|
|
1143
|
-
|
|
1171
|
+
rt as $,
|
|
1172
|
+
$e as A,
|
|
1144
1173
|
S as B,
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1174
|
+
Y as C,
|
|
1175
|
+
re as D,
|
|
1176
|
+
Xe as E,
|
|
1177
|
+
Ue as F,
|
|
1178
|
+
J as G,
|
|
1150
1179
|
ne as H,
|
|
1151
1180
|
y as I,
|
|
1152
1181
|
x as J,
|
|
1153
|
-
|
|
1182
|
+
oe as K,
|
|
1154
1183
|
qe as L,
|
|
1155
1184
|
ze as M,
|
|
1156
|
-
|
|
1185
|
+
Ye as N,
|
|
1157
1186
|
Ne as O,
|
|
1158
1187
|
le as P,
|
|
1159
|
-
|
|
1188
|
+
Ve as Q,
|
|
1160
1189
|
Le as R,
|
|
1161
1190
|
Ae as S,
|
|
1162
1191
|
je as T,
|
|
@@ -1164,33 +1193,33 @@ export {
|
|
|
1164
1193
|
q as V,
|
|
1165
1194
|
se as W,
|
|
1166
1195
|
H as X,
|
|
1167
|
-
|
|
1196
|
+
W as Y,
|
|
1168
1197
|
et as Z,
|
|
1169
1198
|
ie as _,
|
|
1170
|
-
|
|
1199
|
+
ce as a,
|
|
1171
1200
|
nt as b,
|
|
1172
1201
|
Fe as c,
|
|
1173
1202
|
Re as d,
|
|
1174
1203
|
Se as e,
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1204
|
+
Ze as f,
|
|
1205
|
+
ot as g,
|
|
1206
|
+
De as h,
|
|
1178
1207
|
st as i,
|
|
1179
1208
|
de as j,
|
|
1180
|
-
|
|
1209
|
+
Je as k,
|
|
1181
1210
|
Me as l,
|
|
1182
|
-
|
|
1211
|
+
D as m,
|
|
1183
1212
|
tt as n,
|
|
1184
1213
|
k as o,
|
|
1185
1214
|
Be as p,
|
|
1186
|
-
|
|
1215
|
+
Qe as q,
|
|
1187
1216
|
M as r,
|
|
1188
1217
|
ue as s,
|
|
1189
1218
|
F as t,
|
|
1190
1219
|
Pe as u,
|
|
1191
|
-
|
|
1220
|
+
Ke as v,
|
|
1192
1221
|
te as w,
|
|
1193
|
-
|
|
1194
|
-
|
|
1222
|
+
Ge as x,
|
|
1223
|
+
We as y,
|
|
1195
1224
|
He as z
|
|
1196
1225
|
};
|