@forevka/wordcanvas 0.7.0 → 0.7.1
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/README.md +48 -1
- package/dist-lib/assets/{worker-BsOsK39A.js → worker-D8rUOKfg.js} +9603 -9451
- package/dist-lib/assets/worker-wXuuyshQ.js +2258 -0
- package/dist-lib/{blockFactory-Bcy0U40y.js → blockFactory-CUI4Rqiq.js} +50 -42
- package/dist-lib/{browser-5Sv4CuNy.js → browser-DkKxreJM.js} +404 -383
- package/dist-lib/builder.js +364 -109
- package/dist-lib/editorApp-DLXMmtu5.js +8023 -0
- package/dist-lib/export.js +3820 -3768
- package/dist-lib/generate-toc.js +4 -4
- package/dist-lib/import.js +4 -1538
- package/dist-lib/{lists-BegzmTmD.js → lists-Sc5I40JO.js} +2 -2
- package/dist-lib/pipeline-CbxmCE84.js +1705 -0
- package/dist-lib/recalc-docx.js +2 -2
- package/dist-lib/recalcToc-g1hFKSNs.js +3935 -0
- package/dist-lib/toc-B6VpkJge.js +213 -0
- package/dist-lib/{webmcp-B7Gvd58E.js → webmcp-6WxRNKCc.js} +2 -2
- package/dist-lib/{wordcanvas-BAxBeErX.js → wordcanvas-CFqpDK0k.js} +1 -1
- package/dist-lib/wordcanvas.js +1 -1
- package/dist-node/{chunk-GXFDF7UY.js → chunk-22JHAERT.js} +95 -23
- package/dist-node/chunk-22JHAERT.js.map +7 -0
- package/dist-node/{chunk-2RCPB7UZ.js → chunk-6AJJMHKY.js} +1 -1
- package/dist-node/chunk-6AJJMHKY.js.map +7 -0
- package/dist-node/{chunk-XDUDPPJW.js → chunk-CDN6WU2P.js} +89 -26
- package/dist-node/chunk-CDN6WU2P.js.map +7 -0
- package/dist-node/{chunk-TBSXA2I4.js → chunk-EGSAVPCC.js} +1 -1
- package/dist-node/chunk-EGSAVPCC.js.map +7 -0
- package/dist-node/{chunk-IJLL6IFJ.js → chunk-RNB336F3.js} +116 -5
- package/dist-node/{chunk-IJLL6IFJ.js.map → chunk-RNB336F3.js.map} +2 -2
- package/dist-node/{engine-FRCX7PXF.js → engine-5FGDJD2H.js} +3 -3
- package/dist-node/export.js +92 -31
- package/dist-node/export.js.map +2 -2
- package/dist-node/generate-toc.js +5 -5
- package/dist-node/import.js +3 -3
- package/dist-node/recalc-docx.js +4 -4
- package/dist-node/recalc-docx.js.map +1 -1
- package/package.json +1 -1
- package/types/model.d.ts +231 -225
- package/types/recalc-docx.d.ts +27 -27
- package/dist-lib/assets/worker-BbFAIxdy.js +0 -2163
- package/dist-lib/editorApp-DvjFPHiy.js +0 -7582
- package/dist-lib/recalcToc-uaLWt59L.js +0 -3835
- package/dist-lib/toc-CZel_Kk3.js +0 -127
- package/dist-node/chunk-2RCPB7UZ.js.map +0 -7
- package/dist-node/chunk-GXFDF7UY.js.map +0 -7
- package/dist-node/chunk-TBSXA2I4.js.map +0 -7
- package/dist-node/chunk-XDUDPPJW.js.map +0 -7
- /package/dist-node/{engine-FRCX7PXF.js.map → engine-5FGDJD2H.js.map} +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { t as b, v as k, y as v } from "./browser-DkKxreJM.js";
|
|
2
|
+
function y(t, e = 0) {
|
|
3
|
+
let i = e;
|
|
4
|
+
return {
|
|
5
|
+
siteId: t,
|
|
6
|
+
next: () => `${t}-${(i++).toString(36)}`,
|
|
7
|
+
count: () => i
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
let h = y("local");
|
|
11
|
+
function E(t, e = 0) {
|
|
12
|
+
h = y(t, e);
|
|
13
|
+
}
|
|
14
|
+
function g() {
|
|
15
|
+
return h.next();
|
|
16
|
+
}
|
|
17
|
+
function A() {
|
|
18
|
+
return h.siteId;
|
|
19
|
+
}
|
|
20
|
+
const m = (t) => {
|
|
21
|
+
if (!t) return;
|
|
22
|
+
const e = t.match(/^(\d+)\s*-\s*(\d+)$/);
|
|
23
|
+
if (e) return { from: Number(e[1]), to: Number(e[2]) };
|
|
24
|
+
const i = t.match(/^\d+$/) ? Number(t) : NaN;
|
|
25
|
+
return Number.isNaN(i) ? void 0 : { from: i, to: i };
|
|
26
|
+
};
|
|
27
|
+
function S(t) {
|
|
28
|
+
const e = {
|
|
29
|
+
useOutlineLevels: /\\u\b/.test(t),
|
|
30
|
+
hyperlinks: /\\h\b/.test(t),
|
|
31
|
+
hideInWeb: /\\z\b/.test(t)
|
|
32
|
+
}, i = m(t.match(/\\o\s+"([^"]+)"/)?.[1]);
|
|
33
|
+
i && (e.outlineRange = i);
|
|
34
|
+
const n = m(t.match(/\\n\s+"?([0-9-]+)"?/)?.[1]);
|
|
35
|
+
n && (e.hidePageNumberRange = n);
|
|
36
|
+
const a = t.match(/\\p\s+"([^"]*)"/)?.[1];
|
|
37
|
+
a !== void 0 && (e.separator = a);
|
|
38
|
+
const s = t.match(/\\t\s+"([^"]+)"/)?.[1];
|
|
39
|
+
if (s) {
|
|
40
|
+
const r = s.split(","), o = {};
|
|
41
|
+
for (let l = 0; l + 1 < r.length; l += 2) {
|
|
42
|
+
const c = r[l].trim(), u = Number(r[l + 1].trim());
|
|
43
|
+
c && u >= 1 && (o[c] = u);
|
|
44
|
+
}
|
|
45
|
+
Object.keys(o).length > 0 && (e.customStyles = o);
|
|
46
|
+
}
|
|
47
|
+
return e;
|
|
48
|
+
}
|
|
49
|
+
function B(t) {
|
|
50
|
+
const e = ["TOC"];
|
|
51
|
+
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) {
|
|
52
|
+
const i = Object.entries(t.customStyles).map(([n, a]) => `${n},${a}`).join(",");
|
|
53
|
+
e.push(`\\t "${i}"`);
|
|
54
|
+
}
|
|
55
|
+
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(" ")} `;
|
|
56
|
+
}
|
|
57
|
+
const C = (t, e) => !!t && e >= t.from && e <= t.to;
|
|
58
|
+
function p(t, e) {
|
|
59
|
+
if (!e || !t.stylesheet) return;
|
|
60
|
+
const i = new Map(t.stylesheet.styles.map((s) => [s.id, s]));
|
|
61
|
+
let n = i.get(e);
|
|
62
|
+
const a = /* @__PURE__ */ new Set();
|
|
63
|
+
for (; n && !a.has(n.id); ) {
|
|
64
|
+
if (n.name && /(?:^|\s)heading\s*\d/i.test(n.name)) return n.name;
|
|
65
|
+
a.add(n.id), n = n.basedOn ? i.get(n.basedOn) : void 0;
|
|
66
|
+
}
|
|
67
|
+
return i.get(e)?.name;
|
|
68
|
+
}
|
|
69
|
+
function I(t, e, i) {
|
|
70
|
+
const n = t.style.namedStyle;
|
|
71
|
+
if (i?.customStyles && n) {
|
|
72
|
+
const r = i.customStyles[n] ?? i.customStyles[p(e, n) ?? ""];
|
|
73
|
+
if (r) return r;
|
|
74
|
+
}
|
|
75
|
+
if (t.style.outlineLevel !== void 0) return t.style.outlineLevel + 1;
|
|
76
|
+
const a = n?.match(/^heading\s*(\d)$/i);
|
|
77
|
+
if (a) return Number(a[1]);
|
|
78
|
+
const s = p(e, n)?.match(/(?:^|\s)heading\s*(\d)/i);
|
|
79
|
+
return s ? Number(s[1]) : null;
|
|
80
|
+
}
|
|
81
|
+
function R(t, e, i = 3) {
|
|
82
|
+
const n = e?.outlineRange?.to ?? i, a = [];
|
|
83
|
+
for (const s of v(t)) {
|
|
84
|
+
const r = I(s, t, e);
|
|
85
|
+
r === null || r < 1 || r > n || e?.outlineRange && (r < e.outlineRange.from || r > e.outlineRange.to) || a.push({ block: s, level: r });
|
|
86
|
+
}
|
|
87
|
+
return a;
|
|
88
|
+
}
|
|
89
|
+
function H(t, e = 20) {
|
|
90
|
+
if (!t.bookmarks) return 0;
|
|
91
|
+
const i = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right;
|
|
92
|
+
let n = 0;
|
|
93
|
+
for (const a of t.blocks) {
|
|
94
|
+
if (a.kind !== "paragraph" || a.style.tocEntry) continue;
|
|
95
|
+
const s = a.runs.find((u) => u.style.link?.startsWith("#"))?.style.link?.slice(1);
|
|
96
|
+
if (!s) continue;
|
|
97
|
+
const r = t.bookmarks[s]?.start.blockId;
|
|
98
|
+
if (!r) continue;
|
|
99
|
+
const o = b(a.runs), l = o.match(/\t\d+\s*$/);
|
|
100
|
+
if (!l) continue;
|
|
101
|
+
a.runs = k(a.runs, 0, o.length - l[0].length), a.runs.length === 0 && (a.runs = [{ text: "", style: { ...f } }]);
|
|
102
|
+
const c = Math.min(9, Math.max(1, Math.round((a.style.indentLeftPx || 0) / e) + 1));
|
|
103
|
+
a.style.tocEntry = { targetId: r, level: c }, !a.style.tabStops?.length && i > 0 && (a.style.tabStops = [{ posPx: i, align: "right", leader: "dot" }]), a.revision++, n++;
|
|
104
|
+
}
|
|
105
|
+
return n;
|
|
106
|
+
}
|
|
107
|
+
const f = {
|
|
108
|
+
fontFamily: "Georgia, serif",
|
|
109
|
+
fontSizePx: 13,
|
|
110
|
+
bold: !1,
|
|
111
|
+
italic: !1,
|
|
112
|
+
underline: !1,
|
|
113
|
+
strikethrough: !1,
|
|
114
|
+
color: "#202124"
|
|
115
|
+
};
|
|
116
|
+
function L(t, e, i, n) {
|
|
117
|
+
const a = t.indentStepPx ?? 20, s = t.leader ?? "dot";
|
|
118
|
+
let r, o;
|
|
119
|
+
if (n && (n.char || n.para)) {
|
|
120
|
+
r = { ...f, ...n.char, ...t.baseChar, ...t.levels?.[e]?.char };
|
|
121
|
+
const l = n.para?.indentLeftPx ?? 0;
|
|
122
|
+
o = {
|
|
123
|
+
align: "left",
|
|
124
|
+
lineHeight: 1.5,
|
|
125
|
+
spaceBeforePx: 0,
|
|
126
|
+
spaceAfterPx: 2,
|
|
127
|
+
indentFirstLinePx: 0,
|
|
128
|
+
...n.para,
|
|
129
|
+
indentLeftPx: l + (e - 1) * a,
|
|
130
|
+
...t.levels?.[e]?.para
|
|
131
|
+
};
|
|
132
|
+
} else
|
|
133
|
+
r = { ...{ ...f, ...t.baseChar }, fontSizePx: e === 1 ? 14 : 13, bold: e === 1, ...t.levels?.[e]?.char }, o = {
|
|
134
|
+
align: "left",
|
|
135
|
+
lineHeight: 1.5,
|
|
136
|
+
spaceBeforePx: 0,
|
|
137
|
+
spaceAfterPx: 2,
|
|
138
|
+
indentFirstLinePx: 0,
|
|
139
|
+
indentLeftPx: (e - 1) * a,
|
|
140
|
+
...t.levels?.[e]?.para
|
|
141
|
+
};
|
|
142
|
+
return s !== "none" && i > 0 ? o.tabStops = [{ posPx: i, align: "right", leader: s }] : delete o.tabStops, { char: r, para: o };
|
|
143
|
+
}
|
|
144
|
+
function N(t) {
|
|
145
|
+
if (t.title === null) return null;
|
|
146
|
+
const e = t.title ?? {}, i = { ...f, ...t.baseChar };
|
|
147
|
+
return {
|
|
148
|
+
text: e.text ?? "Table of Contents",
|
|
149
|
+
char: { ...i, fontSizePx: 20, bold: !0, ...e.char },
|
|
150
|
+
para: {
|
|
151
|
+
align: "left",
|
|
152
|
+
lineHeight: 1.4,
|
|
153
|
+
spaceBeforePx: 8,
|
|
154
|
+
spaceAfterPx: 12,
|
|
155
|
+
indentFirstLinePx: 0,
|
|
156
|
+
indentLeftPx: 0,
|
|
157
|
+
namedStyle: e.namedStyle ?? "tocTitle",
|
|
158
|
+
...e.para
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const $ = 3;
|
|
163
|
+
function T(t, e = {}) {
|
|
164
|
+
const i = t.tocInstruction ? S(t.tocInstruction) : void 0, n = e.maxLevel ?? i?.outlineRange?.to ?? $, a = t.section.pageWidthPx - t.section.marginPx.left - t.section.marginPx.right, s = t.tocAnchorBlockId ? t.blocks.find((c) => c.kind === "paragraph" && c.id === t.tocAnchorBlockId) : void 0, r = s ? { char: s.runs[0]?.style, para: s.style } : void 0, o = [];
|
|
165
|
+
if (e.title !== void 0 ? e.title !== null : s === void 0) {
|
|
166
|
+
const c = N(e);
|
|
167
|
+
c && o.push({
|
|
168
|
+
kind: "paragraph",
|
|
169
|
+
id: g(),
|
|
170
|
+
revision: 0,
|
|
171
|
+
runs: [{ text: c.text, style: c.char }],
|
|
172
|
+
style: c.para
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
for (const { block: c, level: u } of R(t, i, n)) {
|
|
176
|
+
const d = b(c.runs).replace(/\v/g, " ").trim();
|
|
177
|
+
if (d.length === 0) continue;
|
|
178
|
+
const { char: x, para: P } = L(e, u, a, r);
|
|
179
|
+
o.push({
|
|
180
|
+
kind: "paragraph",
|
|
181
|
+
id: g(),
|
|
182
|
+
revision: 0,
|
|
183
|
+
runs: [{ text: d, style: x }],
|
|
184
|
+
style: { ...P, tocEntry: { targetId: c.id, level: u } }
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return o;
|
|
188
|
+
}
|
|
189
|
+
function W(t, e = {}) {
|
|
190
|
+
if (t.blocks.some((r) => r.kind === "paragraph" && r.style.tocEntry))
|
|
191
|
+
return { doc: t, generated: 0, headings: 0 };
|
|
192
|
+
if (t.tocAnchorBlockId === void 0) return { doc: t, generated: 0, headings: 0 };
|
|
193
|
+
const i = t.blocks.findIndex((r) => r.id === t.tocAnchorBlockId);
|
|
194
|
+
if (i < 0) return { doc: t, generated: 0, headings: 0 };
|
|
195
|
+
const n = T(t, e), a = n.reduce((r, o) => r + (o.style.tocEntry ? 1 : 0), 0);
|
|
196
|
+
if (a === 0) return { doc: t, generated: 0, headings: 0 };
|
|
197
|
+
const s = [...t.blocks];
|
|
198
|
+
return s.splice(i, 1, ...n), { doc: { ...t, blocks: s }, generated: a, headings: a };
|
|
199
|
+
}
|
|
200
|
+
export {
|
|
201
|
+
T as a,
|
|
202
|
+
B as b,
|
|
203
|
+
A as c,
|
|
204
|
+
R as d,
|
|
205
|
+
E as e,
|
|
206
|
+
g as f,
|
|
207
|
+
W as g,
|
|
208
|
+
y as h,
|
|
209
|
+
C as i,
|
|
210
|
+
H as m,
|
|
211
|
+
S as p,
|
|
212
|
+
L as t
|
|
213
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { p as j, c as _, n as F, t as k } from "./browser-
|
|
1
|
+
import { p as j, c as _, n as F, t as k } from "./browser-DkKxreJM.js";
|
|
2
2
|
const s = (e) => Math.round(e * 100) / 100;
|
|
3
3
|
function L(e) {
|
|
4
4
|
const o = { font: e.fontFamily, sizePx: e.fontSizePx };
|
|
@@ -339,7 +339,7 @@ function Y(e, o = {}, r = {}) {
|
|
|
339
339
|
if (i && e.search(i).total === 0)
|
|
340
340
|
return e.searchClear(), f(`text not found: ${i}`);
|
|
341
341
|
if (!e.getSelection()) return f("no selection (pass 'find' or select_range first)");
|
|
342
|
-
const { insertText: l } = await import("./editorApp-
|
|
342
|
+
const { insertText: l } = await import("./editorApp-DLXMmtu5.js").then((m) => m.c);
|
|
343
343
|
return e.dispatch(l(t)), i && e.searchClear(), g("inserted");
|
|
344
344
|
}
|
|
345
345
|
}), a({
|
|
@@ -27,7 +27,7 @@ class o {
|
|
|
27
27
|
},
|
|
28
28
|
onEvent: (n) => this.emit(n)
|
|
29
29
|
};
|
|
30
|
-
e.onLoadProgress?.({ phase: "bundle", percent: 0, loaded: 0, total: 0 }), import("./editorApp-
|
|
30
|
+
e.onLoadProgress?.({ phase: "bundle", percent: 0, loaded: 0, total: 0 }), import("./editorApp-DLXMmtu5.js").then((n) => n.e).then((n) => (e.onLoadProgress?.({ phase: "bundle", percent: 0.15, loaded: 0, total: 0 }), n.mountEditorApp(t)));
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
/** Subscribe to a collaboration event. Returns an unsubscribe function. */
|
package/dist-lib/wordcanvas.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
rootEl,
|
|
20
20
|
textOf,
|
|
21
21
|
val
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-6AJJMHKY.js";
|
|
23
23
|
import {
|
|
24
24
|
strFromU8,
|
|
25
25
|
unzipSync
|
|
@@ -28,8 +28,9 @@ import {
|
|
|
28
28
|
isCustomFieldInstruction,
|
|
29
29
|
markImportedTocEntries,
|
|
30
30
|
normalizeRuns,
|
|
31
|
-
parseFieldInstruction
|
|
32
|
-
|
|
31
|
+
parseFieldInstruction,
|
|
32
|
+
parseFieldSpec
|
|
33
|
+
} from "./chunk-CDN6WU2P.js";
|
|
33
34
|
|
|
34
35
|
// src/import/docx/units.ts
|
|
35
36
|
var twipsToPx = (tw) => tw / 15;
|
|
@@ -383,8 +384,16 @@ function parseParagraph(p, ctx) {
|
|
|
383
384
|
const para = { kind: "paragraph", props, inlines };
|
|
384
385
|
if (bookmarks.length > 0) para.bookmarks = bookmarks;
|
|
385
386
|
if (markers.length > 0) para.bookmarkMarkers = markers;
|
|
387
|
+
if (field.tocInstr !== void 0) para.tocField = field.tocInstr;
|
|
386
388
|
return para;
|
|
387
389
|
}
|
|
390
|
+
var BUILTIN_INLINE = /* @__PURE__ */ new Set(["PAGE", "NUMPAGES", "DATE", "TIME", "IF"]);
|
|
391
|
+
var FIELD_SPEC_STYLE = { fontFamily: "", fontSizePx: 16, bold: false, italic: false, underline: false, strikethrough: false, color: "#000000" };
|
|
392
|
+
function pageTokenFor(spec) {
|
|
393
|
+
if (spec.type === "NUMPAGES") return "{pages}";
|
|
394
|
+
if (spec.type === "PAGE") return `{page${spec.numFmt && spec.numFmt !== "arabic" ? `:${spec.numFmt}` : ""}}`;
|
|
395
|
+
return "";
|
|
396
|
+
}
|
|
388
397
|
function fieldToken(instr) {
|
|
389
398
|
if (/\bNUMPAGES\b/.test(instr)) return "{pages}";
|
|
390
399
|
if (/\bPAGE\b/.test(instr)) return "{page}";
|
|
@@ -483,7 +492,7 @@ function parseRun(r, out, ctx, field) {
|
|
|
483
492
|
if (field.pagerefAnchor && props.linkAnchor === void 0 && props.linkRelId === void 0) {
|
|
484
493
|
props.linkAnchor = field.pagerefAnchor;
|
|
485
494
|
}
|
|
486
|
-
out.push({ kind: "run", text, props });
|
|
495
|
+
out.push({ kind: "run", text, props, ...field.resultFieldId ? { fieldId: field.resultFieldId } : {} });
|
|
487
496
|
}
|
|
488
497
|
text = "";
|
|
489
498
|
};
|
|
@@ -531,6 +540,8 @@ function parseRun(r, out, ctx, field) {
|
|
|
531
540
|
field.instr += textOf(node);
|
|
532
541
|
const anchor = anchorFromInstr(field.instr);
|
|
533
542
|
if (anchor) field.pagerefAnchor = anchor;
|
|
543
|
+
const t = textOf(node);
|
|
544
|
+
if (field.tocInstr === void 0 && /\bTOC\b/.test(t)) field.tocInstr = t;
|
|
534
545
|
}
|
|
535
546
|
if (ctx.trackFields && ctx.fieldTrack.depth === 1) ctx.fieldTrack.topInstr += textOf(node);
|
|
536
547
|
break;
|
|
@@ -570,6 +581,7 @@ function handleFldChar(node, runProps, out, ctx, field) {
|
|
|
570
581
|
field.instr = "";
|
|
571
582
|
field.suppressResult = false;
|
|
572
583
|
field.pagerefAnchor = void 0;
|
|
584
|
+
field.resultFieldId = void 0;
|
|
573
585
|
}
|
|
574
586
|
if (ctx.trackFields) {
|
|
575
587
|
ft.depth++;
|
|
@@ -582,6 +594,23 @@ function handleFldChar(node, runProps, out, ctx, field) {
|
|
|
582
594
|
case "separate": {
|
|
583
595
|
if (ctx.trackFields && ft.depth === 1) decideCustomField(ctx);
|
|
584
596
|
if (field.depth !== 1) break;
|
|
597
|
+
if (ctx.trackFields) {
|
|
598
|
+
const parsed = parseFieldInstruction(field.instr);
|
|
599
|
+
if (BUILTIN_INLINE.has(parsed.name)) {
|
|
600
|
+
const spec = parseFieldSpec(parsed, FIELD_SPEC_STYLE);
|
|
601
|
+
if (spec) {
|
|
602
|
+
const fid = `field${ft.next.n++}`;
|
|
603
|
+
ft.registry[fid] = { id: fid, instruction: field.instr, name: parsed.name, kind: "builtin", spec };
|
|
604
|
+
if (spec.type === "PAGE" || spec.type === "NUMPAGES") {
|
|
605
|
+
out.push({ kind: "run", text: pageTokenFor(spec), props: runProps, fieldId: fid });
|
|
606
|
+
field.suppressResult = true;
|
|
607
|
+
} else {
|
|
608
|
+
field.resultFieldId = fid;
|
|
609
|
+
}
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
585
614
|
const token = ctx.fieldTokens ? fieldToken(field.instr) : void 0;
|
|
586
615
|
if (token) {
|
|
587
616
|
out.push({ kind: "run", text: token, props: runProps });
|
|
@@ -607,6 +636,7 @@ function handleFldChar(node, runProps, out, ctx, field) {
|
|
|
607
636
|
field.instr = "";
|
|
608
637
|
field.suppressResult = false;
|
|
609
638
|
field.pagerefAnchor = void 0;
|
|
639
|
+
field.resultFieldId = void 0;
|
|
610
640
|
}
|
|
611
641
|
break;
|
|
612
642
|
}
|
|
@@ -629,20 +659,49 @@ function parseDrawing(drawing, ctx) {
|
|
|
629
659
|
if (cy !== void 0) image.heightEmu = cy;
|
|
630
660
|
if (anchor) {
|
|
631
661
|
const square = el(anchor, "wp:wrapSquare") ?? el(anchor, "wp:wrapTight") ?? el(anchor, "wp:wrapThrough");
|
|
662
|
+
const wrapNone = el(anchor, "wp:wrapNone");
|
|
632
663
|
image.anchorWrap = square ? "square" : "block";
|
|
633
|
-
|
|
664
|
+
const posH = el(anchor, "wp:positionH");
|
|
665
|
+
const posV = el(anchor, "wp:positionV");
|
|
666
|
+
const alignText = posH && el(posH, "wp:align");
|
|
667
|
+
const align = alignText && textOf(alignText);
|
|
668
|
+
if (align === "left" || align === "right" || align === "center") image.anchorAlign = align;
|
|
669
|
+
if (wrapNone) {
|
|
670
|
+
const dec = findDeep(anchor, "adec:decorative");
|
|
671
|
+
const z = numAttr(anchor, "relativeHeight");
|
|
672
|
+
image.anchorFloat = {
|
|
673
|
+
behind: attr(anchor, "behindDoc") === "1",
|
|
674
|
+
offsetXEmu: posOffsetEmu(posH),
|
|
675
|
+
offsetYEmu: posOffsetEmu(posV),
|
|
676
|
+
relFromH: relFromH(posH),
|
|
677
|
+
relFromV: relFromV(posV),
|
|
678
|
+
decorative: !!dec && attr(dec, "val") !== "0",
|
|
679
|
+
...z !== void 0 ? { z } : {}
|
|
680
|
+
};
|
|
681
|
+
} else if (!square) {
|
|
634
682
|
ctx.warnings.add(
|
|
635
683
|
"images-anchored",
|
|
636
684
|
"Some floating images (overlapping or top-and-bottom wrap) were placed in the text flow."
|
|
637
685
|
);
|
|
638
686
|
}
|
|
639
|
-
const posH = el(anchor, "wp:positionH");
|
|
640
|
-
const alignText = posH && el(posH, "wp:align");
|
|
641
|
-
const align = alignText && textOf(alignText);
|
|
642
|
-
if (align === "left" || align === "right" || align === "center") image.anchorAlign = align;
|
|
643
687
|
}
|
|
644
688
|
return image;
|
|
645
689
|
}
|
|
690
|
+
function posOffsetEmu(pos) {
|
|
691
|
+
const off = pos && el(pos, "wp:posOffset");
|
|
692
|
+
const n = off ? Number(textOf(off).trim()) : NaN;
|
|
693
|
+
return Number.isFinite(n) ? n : 0;
|
|
694
|
+
}
|
|
695
|
+
var REL_FROM_H = /* @__PURE__ */ new Set(["page", "margin", "column", "leftMargin", "rightMargin", "character"]);
|
|
696
|
+
var REL_FROM_V = /* @__PURE__ */ new Set(["page", "margin", "paragraph", "line", "topMargin", "bottomMargin"]);
|
|
697
|
+
function relFromH(pos) {
|
|
698
|
+
const v = pos && attr(pos, "relativeFrom");
|
|
699
|
+
return v && REL_FROM_H.has(v) ? v : "column";
|
|
700
|
+
}
|
|
701
|
+
function relFromV(pos) {
|
|
702
|
+
const v = pos && attr(pos, "relativeFrom");
|
|
703
|
+
return v && REL_FROM_V.has(v) ? v : "paragraph";
|
|
704
|
+
}
|
|
646
705
|
function parseVmlPict(pict, ctx) {
|
|
647
706
|
const imagedata = findDeep(pict, "v:imagedata");
|
|
648
707
|
const relId = imagedata && attr(imagedata, "r:id");
|
|
@@ -954,6 +1013,7 @@ function createMapper(warnings, resolver, sdts = {}, numbering = /* @__PURE__ */
|
|
|
954
1013
|
for (let i = mapped.length - 1; i >= 0; i--) if (mapped[i].kind === "paragraph") return mapped[i];
|
|
955
1014
|
return void 0;
|
|
956
1015
|
};
|
|
1016
|
+
let tocAnchor;
|
|
957
1017
|
const mapBlocks = (blocks, media, resolveLink = NO_LINKS) => {
|
|
958
1018
|
const out = [];
|
|
959
1019
|
let pending = false;
|
|
@@ -985,6 +1045,10 @@ function createMapper(warnings, resolver, sdts = {}, numbering = /* @__PURE__ */
|
|
|
985
1045
|
const irBlock = blocks[bi];
|
|
986
1046
|
const mapped = irBlock.kind === "paragraph" ? mapParagraph(irBlock, media, resolveLink) : [mapTable(irBlock, media, resolveLink)];
|
|
987
1047
|
if (irBlock.fieldId) for (const b of mapped) b.fieldId = irBlock.fieldId;
|
|
1048
|
+
if (irBlock.kind === "paragraph" && irBlock.tocField !== void 0 && tocAnchor === void 0) {
|
|
1049
|
+
const p = mapped.find((b) => b.kind === "paragraph") ?? mapped[0];
|
|
1050
|
+
if (p) tocAnchor = { blockId: p.id, instruction: irBlock.tocField };
|
|
1051
|
+
}
|
|
988
1052
|
if (pending && mapped.length > 0) {
|
|
989
1053
|
const first = mapped[0];
|
|
990
1054
|
const empty = first.kind === "paragraph" && first.runs.every((r) => r.text.length === 0 || r.style.hidden);
|
|
@@ -1121,7 +1185,7 @@ function createMapper(warnings, resolver, sdts = {}, numbering = /* @__PURE__ */
|
|
|
1121
1185
|
}
|
|
1122
1186
|
case "run": {
|
|
1123
1187
|
const effective = resolver.run(ir.props.styleId, inline.props);
|
|
1124
|
-
runs.push(mapRun(inline.text, effective, resolveLink, inline.sdtId));
|
|
1188
|
+
runs.push(mapRun(inline.text, effective, resolveLink, inline.sdtId, inline.fieldId));
|
|
1125
1189
|
trailingBreak = false;
|
|
1126
1190
|
break;
|
|
1127
1191
|
}
|
|
@@ -1166,9 +1230,21 @@ function createMapper(warnings, resolver, sdts = {}, numbering = /* @__PURE__ */
|
|
|
1166
1230
|
align: inline.anchorAlign ?? (paraAlign === "justify" ? "left" : paraAlign)
|
|
1167
1231
|
};
|
|
1168
1232
|
if (inline.anchored && inline.anchorWrap === "square") image.wrap = "square";
|
|
1233
|
+
if (inline.anchorFloat) {
|
|
1234
|
+
const a = inline.anchorFloat;
|
|
1235
|
+
image.anchor = {
|
|
1236
|
+
behind: a.behind,
|
|
1237
|
+
offsetXPx: round2(emuToPx(a.offsetXEmu)),
|
|
1238
|
+
offsetYPx: round2(emuToPx(a.offsetYEmu)),
|
|
1239
|
+
relFromH: a.relFromH,
|
|
1240
|
+
relFromV: a.relFromV,
|
|
1241
|
+
...a.decorative ? { decorative: true } : {},
|
|
1242
|
+
...a.z !== void 0 ? { z: a.z } : {}
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1169
1245
|
return image;
|
|
1170
1246
|
}
|
|
1171
|
-
function mapRun(rawText, effective, resolveLink, sdtId) {
|
|
1247
|
+
function mapRun(rawText, effective, resolveLink, sdtId, fieldId) {
|
|
1172
1248
|
let text = rawText;
|
|
1173
1249
|
const style = mapCharStyle(effective);
|
|
1174
1250
|
if (effective.linkRelId) {
|
|
@@ -1191,6 +1267,7 @@ function createMapper(warnings, resolver, sdts = {}, numbering = /* @__PURE__ */
|
|
|
1191
1267
|
style.fontFamily = DEFAULT_CHAR.fontFamily;
|
|
1192
1268
|
}
|
|
1193
1269
|
}
|
|
1270
|
+
if (fieldId) style.fieldId = fieldId;
|
|
1194
1271
|
return { text, style };
|
|
1195
1272
|
}
|
|
1196
1273
|
function styleCell(p, ir, styled, hasBorderInfo, width, rowCount) {
|
|
@@ -1284,7 +1361,8 @@ function createMapper(warnings, resolver, sdts = {}, numbering = /* @__PURE__ */
|
|
|
1284
1361
|
}
|
|
1285
1362
|
return out;
|
|
1286
1363
|
},
|
|
1287
|
-
footnoteRefs: () => footnoteOrder.map((docxId) => ({ docxId, noteId: `fn${docxId}` }))
|
|
1364
|
+
footnoteRefs: () => footnoteOrder.map((docxId) => ({ docxId, noteId: `fn${docxId}` })),
|
|
1365
|
+
tocField: () => tocAnchor
|
|
1288
1366
|
};
|
|
1289
1367
|
}
|
|
1290
1368
|
var NUM_FORMAT_MAP = {
|
|
@@ -2031,10 +2109,10 @@ function runImport(bytes, onProgress, opts) {
|
|
|
2031
2109
|
if (Object.keys(bookmarks).length > 0) doc.bookmarks = bookmarks;
|
|
2032
2110
|
const stylesheet = buildStylesheet(styles, collectUsedStyleIds(ir.blocks));
|
|
2033
2111
|
if (stylesheet) doc.stylesheet = stylesheet;
|
|
2034
|
-
const
|
|
2035
|
-
if (
|
|
2036
|
-
doc.tocInstruction =
|
|
2037
|
-
markImportedTocEntries(doc);
|
|
2112
|
+
const toc = mapper.tocField();
|
|
2113
|
+
if (toc) {
|
|
2114
|
+
doc.tocInstruction = toc.instruction;
|
|
2115
|
+
if (markImportedTocEntries(doc) === 0) doc.tocAnchorBlockId = toc.blockId;
|
|
2038
2116
|
}
|
|
2039
2117
|
if (ir.fields) doc.fields = ir.fields;
|
|
2040
2118
|
return {
|
|
@@ -2044,12 +2122,6 @@ function runImport(bytes, onProgress, opts) {
|
|
|
2044
2122
|
media: mediaRecords
|
|
2045
2123
|
};
|
|
2046
2124
|
}
|
|
2047
|
-
function captureTocInstruction(xml) {
|
|
2048
|
-
const re = /<w:instrText[^>]*>([\s\S]*?)<\/w:instrText>/g;
|
|
2049
|
-
let m;
|
|
2050
|
-
while ((m = re.exec(xml)) !== null) if (/\bTOC\b/.test(m[1])) return m[1];
|
|
2051
|
-
return void 0;
|
|
2052
|
-
}
|
|
2053
2125
|
function mapStory(archive, documentRels, relId, mapper, mediaFor, warnings, sdts) {
|
|
2054
2126
|
if (!relId) return void 0;
|
|
2055
2127
|
const rel = documentRels.get(relId);
|
|
@@ -2100,4 +2172,4 @@ function partNameByRelType(rels, kind) {
|
|
|
2100
2172
|
export {
|
|
2101
2173
|
runImport
|
|
2102
2174
|
};
|
|
2103
|
-
//# sourceMappingURL=chunk-
|
|
2175
|
+
//# sourceMappingURL=chunk-22JHAERT.js.map
|