@coco-vexel/coco-office 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/README.md +120 -2
- package/THIRD_PARTY_NOTICES.md +1188 -0
- package/dist/excel-worker-browser.cjs +6544 -0
- package/dist/excel-worker-browser.cjs.map +1 -0
- package/dist/excel-worker-browser.d.cts +2 -0
- package/dist/excel-worker-browser.d.ts +2 -0
- package/dist/excel-worker-browser.js +6523 -0
- package/dist/excel-worker-browser.js.map +1 -0
- package/dist/excel-worker.cjs +6547 -0
- package/dist/excel-worker.cjs.map +1 -0
- package/dist/excel-worker.d.cts +2 -0
- package/dist/excel-worker.d.ts +2 -0
- package/dist/excel-worker.js +6526 -0
- package/dist/excel-worker.js.map +1 -0
- package/dist/excel.cjs +12523 -0
- package/dist/excel.cjs.map +1 -0
- package/dist/excel.d.cts +2252 -0
- package/dist/excel.d.ts +2252 -0
- package/dist/excel.js +12368 -0
- package/dist/excel.js.map +1 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel-worker-browser.cjs +12304 -0
- package/dist/kernel-worker-browser.cjs.map +1 -0
- package/dist/kernel-worker-browser.d.cts +2 -0
- package/dist/kernel-worker-browser.d.ts +2 -0
- package/dist/kernel-worker-browser.js +12283 -0
- package/dist/kernel-worker-browser.js.map +1 -0
- package/dist/kernel-worker.cjs +12309 -0
- package/dist/kernel-worker.cjs.map +1 -0
- package/dist/kernel-worker.d.cts +2 -0
- package/dist/kernel-worker.d.ts +2 -0
- package/dist/kernel-worker.js +12288 -0
- package/dist/kernel-worker.js.map +1 -0
- package/dist/pack.cjs +459 -0
- package/dist/pack.cjs.map +1 -0
- package/dist/pack.d.cts +119 -0
- package/dist/pack.d.ts +119 -0
- package/dist/pack.js +408 -0
- package/dist/pack.js.map +1 -0
- package/dist/ppt.cjs +7427 -0
- package/dist/ppt.cjs.map +1 -0
- package/dist/ppt.d.cts +1432 -0
- package/dist/ppt.d.ts +1432 -0
- package/dist/ppt.js +7355 -0
- package/dist/ppt.js.map +1 -0
- package/dist/shared.cjs +105 -0
- package/dist/shared.cjs.map +1 -0
- package/dist/shared.d.cts +31 -0
- package/dist/shared.d.ts +31 -0
- package/dist/shared.js +81 -0
- package/dist/shared.js.map +1 -0
- package/dist/types-BVkkdcfh.d.cts +54 -0
- package/dist/types-BVkkdcfh.d.ts +54 -0
- package/dist/types-C2vQfM-b.d.cts +102 -0
- package/dist/types-C2vQfM-b.d.ts +102 -0
- package/dist/view-DAkeR0RW.d.ts +1199 -0
- package/dist/view-DX2YAG5A.d.cts +1199 -0
- package/dist/word-view.cjs +1824 -0
- package/dist/word-view.cjs.map +1 -0
- package/dist/word-view.d.cts +2 -0
- package/dist/word-view.d.ts +2 -0
- package/dist/word-view.js +1791 -0
- package/dist/word-view.js.map +1 -0
- package/dist/word.cjs +14111 -0
- package/dist/word.cjs.map +1 -0
- package/dist/word.d.cts +3042 -0
- package/dist/word.d.ts +3042 -0
- package/dist/word.js +14016 -0
- package/dist/word.js.map +1 -0
- package/package.json +103 -3
|
@@ -0,0 +1,1791 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
21
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
|
|
23
|
+
// src/word/namespaces.ts
|
|
24
|
+
var W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
25
|
+
var R_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
26
|
+
var A_NS = "http://schemas.openxmlformats.org/drawingml/2006/main";
|
|
27
|
+
var WP_NS = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
|
|
28
|
+
var PIC_NS = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
29
|
+
var CHART_NS = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
30
|
+
var DGM_NS = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
|
|
31
|
+
var WPS_NS = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
32
|
+
var WPG_NS = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";
|
|
33
|
+
var WPC_NS = "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas";
|
|
34
|
+
var MC_NS = "http://schemas.openxmlformats.org/markup-compatibility/2006";
|
|
35
|
+
var VML_NS = "urn:schemas-microsoft-com:vml";
|
|
36
|
+
var W14_NS = "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
37
|
+
var MATH_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math";
|
|
38
|
+
|
|
39
|
+
// src/pack/part.ts
|
|
40
|
+
function isXmlPart(part) {
|
|
41
|
+
return part.xmlDom !== void 0;
|
|
42
|
+
}
|
|
43
|
+
__name(isXmlPart, "isXmlPart");
|
|
44
|
+
|
|
45
|
+
// src/pack/package.ts
|
|
46
|
+
function getPart(pkg, path) {
|
|
47
|
+
return pkg.parts.get(path);
|
|
48
|
+
}
|
|
49
|
+
__name(getPart, "getPart");
|
|
50
|
+
function listParts(pkg) {
|
|
51
|
+
return Array.from(pkg.parts.values());
|
|
52
|
+
}
|
|
53
|
+
__name(listParts, "listParts");
|
|
54
|
+
|
|
55
|
+
// src/word/style-queries.ts
|
|
56
|
+
var STYLES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";
|
|
57
|
+
function findStylesPart(pkg) {
|
|
58
|
+
for (const part of pkg.parts.values()) {
|
|
59
|
+
if (part.contentType === STYLES_CONTENT_TYPE && part.xmlDom) {
|
|
60
|
+
return part;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
__name(findStylesPart, "findStylesPart");
|
|
66
|
+
function childAttr(el, ns, localName, attrNs, attrLocal) {
|
|
67
|
+
const children = el.childNodes;
|
|
68
|
+
for (let i = 0; i < children.length; i++) {
|
|
69
|
+
const c = children[i];
|
|
70
|
+
if (c && c.nodeType === 1 && c.namespaceURI === ns && c.localName === localName) {
|
|
71
|
+
return c.getAttributeNS(attrNs, attrLocal);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
__name(childAttr, "childAttr");
|
|
77
|
+
function styleOutlineLevel(styleEl) {
|
|
78
|
+
const children = styleEl.childNodes;
|
|
79
|
+
for (let i = 0; i < children.length; i++) {
|
|
80
|
+
const c = children[i];
|
|
81
|
+
if (!c || c.nodeType !== 1) continue;
|
|
82
|
+
const el = c;
|
|
83
|
+
if (el.namespaceURI !== W_NS || el.localName !== "pPr") continue;
|
|
84
|
+
const pPrChildren = el.childNodes;
|
|
85
|
+
for (let j = 0; j < pPrChildren.length; j++) {
|
|
86
|
+
const pc = pPrChildren[j];
|
|
87
|
+
if (!pc || pc.nodeType !== 1) continue;
|
|
88
|
+
const pcel = pc;
|
|
89
|
+
if (pcel.namespaceURI !== W_NS || pcel.localName !== "outlineLvl") continue;
|
|
90
|
+
const raw = pcel.getAttributeNS(W_NS, "val");
|
|
91
|
+
if (raw === null) return void 0;
|
|
92
|
+
const n = parseInt(raw, 10);
|
|
93
|
+
return Number.isFinite(n) && n >= 0 && n <= 8 ? n : void 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
__name(styleOutlineLevel, "styleOutlineLevel");
|
|
99
|
+
function parseStyleType(raw) {
|
|
100
|
+
switch (raw) {
|
|
101
|
+
case "paragraph":
|
|
102
|
+
return "paragraph";
|
|
103
|
+
case "character":
|
|
104
|
+
return "character";
|
|
105
|
+
case "table":
|
|
106
|
+
return "table";
|
|
107
|
+
case "numbering":
|
|
108
|
+
return "numbering";
|
|
109
|
+
default:
|
|
110
|
+
return "paragraph";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
__name(parseStyleType, "parseStyleType");
|
|
114
|
+
function buildStylesIndex(pkg) {
|
|
115
|
+
var _a;
|
|
116
|
+
const idx = /* @__PURE__ */ new Map();
|
|
117
|
+
const stylesPart = findStylesPart(pkg);
|
|
118
|
+
if (!stylesPart) return idx;
|
|
119
|
+
const styleEls = stylesPart.xmlDom.getElementsByTagNameNS(W_NS, "style");
|
|
120
|
+
for (let i = 0; i < styleEls.length; i++) {
|
|
121
|
+
const el = styleEls[i];
|
|
122
|
+
if (!el) continue;
|
|
123
|
+
const styleId = el.getAttributeNS(W_NS, "styleId");
|
|
124
|
+
if (!styleId) continue;
|
|
125
|
+
const type = parseStyleType(el.getAttributeNS(W_NS, "type"));
|
|
126
|
+
const name = (_a = childAttr(el, W_NS, "name", W_NS, "val")) != null ? _a : styleId;
|
|
127
|
+
const basedOnRaw = childAttr(el, W_NS, "basedOn", W_NS, "val");
|
|
128
|
+
const info = { styleId, name, type };
|
|
129
|
+
if (basedOnRaw) info.basedOn = basedOnRaw;
|
|
130
|
+
const outlineLvlVal = styleOutlineLevel(el);
|
|
131
|
+
if (outlineLvlVal !== void 0) info.outlineLevel = outlineLvlVal;
|
|
132
|
+
idx.set(styleId, info);
|
|
133
|
+
}
|
|
134
|
+
return idx;
|
|
135
|
+
}
|
|
136
|
+
__name(buildStylesIndex, "buildStylesIndex");
|
|
137
|
+
|
|
138
|
+
// src/word/list-tables.ts
|
|
139
|
+
import { serializeToWellFormedString } from "slimdom";
|
|
140
|
+
|
|
141
|
+
// src/word/runs.ts
|
|
142
|
+
function isWElement(node, localName) {
|
|
143
|
+
return node.nodeType === 1 && node.namespaceURI === W_NS && node.localName === localName;
|
|
144
|
+
}
|
|
145
|
+
__name(isWElement, "isWElement");
|
|
146
|
+
function getParagraphRuns(paragraph) {
|
|
147
|
+
const runs = [];
|
|
148
|
+
const children = paragraph.childNodes;
|
|
149
|
+
for (let i = 0; i < children.length; i++) {
|
|
150
|
+
const child = children[i];
|
|
151
|
+
if (child && isWElement(child, "r")) {
|
|
152
|
+
runs.push(child);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return runs;
|
|
156
|
+
}
|
|
157
|
+
__name(getParagraphRuns, "getParagraphRuns");
|
|
158
|
+
function getRunText(run, opts) {
|
|
159
|
+
var _a;
|
|
160
|
+
const faithful = (opts == null ? void 0 : opts.structuralWhitespace) === true;
|
|
161
|
+
let text = "";
|
|
162
|
+
const children = run.childNodes;
|
|
163
|
+
for (let i = 0; i < children.length; i++) {
|
|
164
|
+
const child = children[i];
|
|
165
|
+
if (!child || child.nodeType !== 1) continue;
|
|
166
|
+
const el = child;
|
|
167
|
+
if (el.namespaceURI !== W_NS) continue;
|
|
168
|
+
const local = el.localName;
|
|
169
|
+
if (local === "t") {
|
|
170
|
+
text += (_a = el.textContent) != null ? _a : "";
|
|
171
|
+
} else if (faithful) {
|
|
172
|
+
if (local === "tab") {
|
|
173
|
+
text += " ";
|
|
174
|
+
} else if (local === "br") {
|
|
175
|
+
const type = el.getAttributeNS(W_NS, "type");
|
|
176
|
+
if (type === null || type === "" || type === "textWrapping") {
|
|
177
|
+
text += "\n";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return text;
|
|
183
|
+
}
|
|
184
|
+
__name(getRunText, "getRunText");
|
|
185
|
+
function getParagraphText(paragraph, opts) {
|
|
186
|
+
return getParagraphRuns(paragraph).map((r) => getRunText(r, opts)).join("");
|
|
187
|
+
}
|
|
188
|
+
__name(getParagraphText, "getParagraphText");
|
|
189
|
+
|
|
190
|
+
// src/word/stories.ts
|
|
191
|
+
function snapshot(col) {
|
|
192
|
+
const out = [];
|
|
193
|
+
for (let i = 0; i < col.length; i++) {
|
|
194
|
+
const el = col[i];
|
|
195
|
+
if (el) out.push(el);
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
__name(snapshot, "snapshot");
|
|
200
|
+
function listStories(pkg, opts = {}) {
|
|
201
|
+
var _a;
|
|
202
|
+
const wanted = new Set(
|
|
203
|
+
(_a = opts.kinds) != null ? _a : ["body", "header", "footer", "footnote", "endnote", "comment"]
|
|
204
|
+
);
|
|
205
|
+
const out = [];
|
|
206
|
+
for (const part of pkg.parts.values()) {
|
|
207
|
+
if (!isXmlPart(part) || !part.xmlDom) continue;
|
|
208
|
+
const ct = part.contentType;
|
|
209
|
+
if (wanted.has("body") && (ct.endsWith(".document.main+xml") || ct.endsWith(".document.macroEnabled.main+xml") || ct.endsWith(".template.main+xml") || ct.endsWith(".template.macroEnabledTemplate.main+xml"))) {
|
|
210
|
+
const bodies = snapshot(part.xmlDom.getElementsByTagNameNS(W_NS, "body"));
|
|
211
|
+
if (bodies.length > 0) {
|
|
212
|
+
out.push({ id: "body", kind: "body", root: bodies[0], partPath: part.path });
|
|
213
|
+
}
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (wanted.has("header") && ct.endsWith(".header+xml")) {
|
|
217
|
+
const hdrs = snapshot(part.xmlDom.getElementsByTagNameNS(W_NS, "hdr"));
|
|
218
|
+
if (hdrs.length > 0) {
|
|
219
|
+
out.push({
|
|
220
|
+
id: `header:${part.path}`,
|
|
221
|
+
kind: "header",
|
|
222
|
+
root: hdrs[0],
|
|
223
|
+
partPath: part.path
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (wanted.has("footer") && ct.endsWith(".footer+xml")) {
|
|
229
|
+
const ftrs = snapshot(part.xmlDom.getElementsByTagNameNS(W_NS, "ftr"));
|
|
230
|
+
if (ftrs.length > 0) {
|
|
231
|
+
out.push({
|
|
232
|
+
id: `footer:${part.path}`,
|
|
233
|
+
kind: "footer",
|
|
234
|
+
root: ftrs[0],
|
|
235
|
+
partPath: part.path
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (wanted.has("footnote") && ct.endsWith(".footnotes+xml")) {
|
|
241
|
+
const notes = snapshot(part.xmlDom.getElementsByTagNameNS(W_NS, "footnote"));
|
|
242
|
+
for (const note of notes) {
|
|
243
|
+
const id = numAttr(note, W_NS, "id");
|
|
244
|
+
if (id === null) continue;
|
|
245
|
+
out.push({
|
|
246
|
+
id: `footnote:${id}`,
|
|
247
|
+
kind: "footnote",
|
|
248
|
+
root: note,
|
|
249
|
+
partPath: part.path
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (wanted.has("endnote") && ct.endsWith(".endnotes+xml")) {
|
|
255
|
+
const notes = snapshot(part.xmlDom.getElementsByTagNameNS(W_NS, "endnote"));
|
|
256
|
+
for (const note of notes) {
|
|
257
|
+
const id = numAttr(note, W_NS, "id");
|
|
258
|
+
if (id === null) continue;
|
|
259
|
+
out.push({
|
|
260
|
+
id: `endnote:${id}`,
|
|
261
|
+
kind: "endnote",
|
|
262
|
+
root: note,
|
|
263
|
+
partPath: part.path
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (wanted.has("comment") && ct.endsWith(".comments+xml")) {
|
|
269
|
+
const comments = snapshot(part.xmlDom.getElementsByTagNameNS(W_NS, "comment"));
|
|
270
|
+
for (const c of comments) {
|
|
271
|
+
const id = numAttr(c, W_NS, "id");
|
|
272
|
+
if (id === null) continue;
|
|
273
|
+
out.push({
|
|
274
|
+
id: `comment:${id}`,
|
|
275
|
+
kind: "comment",
|
|
276
|
+
root: c,
|
|
277
|
+
partPath: part.path
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return out;
|
|
283
|
+
}
|
|
284
|
+
__name(listStories, "listStories");
|
|
285
|
+
function getStoryParagraphs(story) {
|
|
286
|
+
return snapshot(story.root.getElementsByTagNameNS(W_NS, "p"));
|
|
287
|
+
}
|
|
288
|
+
__name(getStoryParagraphs, "getStoryParagraphs");
|
|
289
|
+
function findStoryFor(pkg, el) {
|
|
290
|
+
for (const s of listStories(pkg)) {
|
|
291
|
+
if (s.root.contains(el)) return s;
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
__name(findStoryFor, "findStoryFor");
|
|
296
|
+
function resolveScope(pkg, scope) {
|
|
297
|
+
if (scope === "body") return listStories(pkg, { kinds: ["body"] });
|
|
298
|
+
if (scope === "all") return listStories(pkg);
|
|
299
|
+
const wanted = new Set(scope);
|
|
300
|
+
return listStories(pkg).filter((s) => wanted.has(s.id));
|
|
301
|
+
}
|
|
302
|
+
__name(resolveScope, "resolveScope");
|
|
303
|
+
function numAttr(el, ns, local) {
|
|
304
|
+
const v = el.getAttributeNS(ns, local);
|
|
305
|
+
if (v === null) return null;
|
|
306
|
+
const n = Number(v);
|
|
307
|
+
return Number.isFinite(n) ? n : null;
|
|
308
|
+
}
|
|
309
|
+
__name(numAttr, "numAttr");
|
|
310
|
+
|
|
311
|
+
// src/word/list-tables.ts
|
|
312
|
+
function snapshot2(col) {
|
|
313
|
+
const out = [];
|
|
314
|
+
for (let i = 0; i < col.length; i++) {
|
|
315
|
+
const el = col[i];
|
|
316
|
+
if (el) out.push(el);
|
|
317
|
+
}
|
|
318
|
+
return out;
|
|
319
|
+
}
|
|
320
|
+
__name(snapshot2, "snapshot");
|
|
321
|
+
function hasTableAncestor(el) {
|
|
322
|
+
let p = el.parentElement;
|
|
323
|
+
while (p) {
|
|
324
|
+
if (p.namespaceURI === W_NS) {
|
|
325
|
+
if (p.localName === "tbl") return true;
|
|
326
|
+
if (p.localName === "body" || p.localName === "hdr" || p.localName === "ftr" || p.localName === "footnote" || p.localName === "endnote" || p.localName === "comment") {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
p = p.parentElement;
|
|
331
|
+
}
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
__name(hasTableAncestor, "hasTableAncestor");
|
|
335
|
+
function prevParaId(tbl) {
|
|
336
|
+
var _a;
|
|
337
|
+
const sib = tbl.previousElementSibling;
|
|
338
|
+
if (sib && sib.namespaceURI === W_NS && sib.localName === "p") {
|
|
339
|
+
return (_a = sib.getAttributeNS(W14_NS, "paraId")) != null ? _a : void 0;
|
|
340
|
+
}
|
|
341
|
+
return void 0;
|
|
342
|
+
}
|
|
343
|
+
__name(prevParaId, "prevParaId");
|
|
344
|
+
function nextParaId(tbl) {
|
|
345
|
+
var _a;
|
|
346
|
+
const sib = tbl.nextElementSibling;
|
|
347
|
+
if (sib && sib.namespaceURI === W_NS && sib.localName === "p") {
|
|
348
|
+
return (_a = sib.getAttributeNS(W14_NS, "paraId")) != null ? _a : void 0;
|
|
349
|
+
}
|
|
350
|
+
return void 0;
|
|
351
|
+
}
|
|
352
|
+
__name(nextParaId, "nextParaId");
|
|
353
|
+
function readGridSpan(tc) {
|
|
354
|
+
for (let i = 0; i < tc.childNodes.length; i++) {
|
|
355
|
+
const child = tc.childNodes[i];
|
|
356
|
+
if (child.nodeType !== 1 || child.namespaceURI !== W_NS || child.localName !== "tcPr") continue;
|
|
357
|
+
for (let j = 0; j < child.childNodes.length; j++) {
|
|
358
|
+
const sub = child.childNodes[j];
|
|
359
|
+
if (sub.nodeType !== 1 || sub.namespaceURI !== W_NS || sub.localName !== "gridSpan") continue;
|
|
360
|
+
const val = sub.getAttributeNS(W_NS, "val");
|
|
361
|
+
const parsed = val !== null ? parseInt(val, 10) : NaN;
|
|
362
|
+
return !isNaN(parsed) && parsed > 1 ? parsed : 1;
|
|
363
|
+
}
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
return 1;
|
|
367
|
+
}
|
|
368
|
+
__name(readGridSpan, "readGridSpan");
|
|
369
|
+
function readVMerge(tc) {
|
|
370
|
+
for (let i = 0; i < tc.childNodes.length; i++) {
|
|
371
|
+
const child = tc.childNodes[i];
|
|
372
|
+
if (child.nodeType !== 1 || child.namespaceURI !== W_NS || child.localName !== "tcPr") continue;
|
|
373
|
+
for (let j = 0; j < child.childNodes.length; j++) {
|
|
374
|
+
const sub = child.childNodes[j];
|
|
375
|
+
if (sub.nodeType !== 1 || sub.namespaceURI !== W_NS || sub.localName !== "vMerge") continue;
|
|
376
|
+
const val = sub.getAttributeNS(W_NS, "val");
|
|
377
|
+
return val === "restart" ? "restart" : "continue";
|
|
378
|
+
}
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
__name(readVMerge, "readVMerge");
|
|
384
|
+
function readCellWidth(tc) {
|
|
385
|
+
var _a;
|
|
386
|
+
const tcPr = firstDirectChildW(tc, "tcPr");
|
|
387
|
+
if (!tcPr) return void 0;
|
|
388
|
+
const tcW = firstDirectChildW(tcPr, "tcW");
|
|
389
|
+
if (!tcW) return void 0;
|
|
390
|
+
const raw = (_a = tcW.getAttributeNS(W_NS, "w")) != null ? _a : tcW.getAttribute("w:w");
|
|
391
|
+
if (raw === null) return void 0;
|
|
392
|
+
const parsed = parseInt(raw, 10);
|
|
393
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
394
|
+
}
|
|
395
|
+
__name(readCellWidth, "readCellWidth");
|
|
396
|
+
function readCellShading(tc) {
|
|
397
|
+
var _a, _b, _c;
|
|
398
|
+
const tcPr = firstDirectChildW(tc, "tcPr");
|
|
399
|
+
if (!tcPr) return void 0;
|
|
400
|
+
const shd = firstDirectChildW(tcPr, "shd");
|
|
401
|
+
if (!shd) return void 0;
|
|
402
|
+
const result = {};
|
|
403
|
+
const fill = (_a = shd.getAttributeNS(W_NS, "fill")) != null ? _a : shd.getAttribute("w:fill");
|
|
404
|
+
const color = (_b = shd.getAttributeNS(W_NS, "color")) != null ? _b : shd.getAttribute("w:color");
|
|
405
|
+
const val = (_c = shd.getAttributeNS(W_NS, "val")) != null ? _c : shd.getAttribute("w:val");
|
|
406
|
+
if (fill !== null) result.fill = fill;
|
|
407
|
+
if (color !== null) result.color = color;
|
|
408
|
+
if (val !== null) result.val = val;
|
|
409
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
410
|
+
}
|
|
411
|
+
__name(readCellShading, "readCellShading");
|
|
412
|
+
function readCellVerticalAlignment(tc) {
|
|
413
|
+
var _a;
|
|
414
|
+
const tcPr = firstDirectChildW(tc, "tcPr");
|
|
415
|
+
if (!tcPr) return void 0;
|
|
416
|
+
const vAlign = firstDirectChildW(tcPr, "vAlign");
|
|
417
|
+
if (!vAlign) return void 0;
|
|
418
|
+
const raw = (_a = vAlign.getAttributeNS(W_NS, "val")) != null ? _a : vAlign.getAttribute("w:val");
|
|
419
|
+
if (raw === "top" || raw === "center" || raw === "bottom" || raw === "both") return raw;
|
|
420
|
+
return void 0;
|
|
421
|
+
}
|
|
422
|
+
__name(readCellVerticalAlignment, "readCellVerticalAlignment");
|
|
423
|
+
function firstDirectChildW(el, localName) {
|
|
424
|
+
for (let i = 0; i < el.childNodes.length; i++) {
|
|
425
|
+
const child = el.childNodes[i];
|
|
426
|
+
if ((child == null ? void 0 : child.nodeType) === 1 && child.namespaceURI === W_NS && child.localName === localName) {
|
|
427
|
+
return child;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
__name(firstDirectChildW, "firstDirectChildW");
|
|
433
|
+
function readTrHeight(tr) {
|
|
434
|
+
for (let i = 0; i < tr.childNodes.length; i++) {
|
|
435
|
+
const child = tr.childNodes[i];
|
|
436
|
+
if (child.nodeType !== 1 || child.namespaceURI !== W_NS || child.localName !== "trPr") continue;
|
|
437
|
+
for (let j = 0; j < child.childNodes.length; j++) {
|
|
438
|
+
const sub = child.childNodes[j];
|
|
439
|
+
if (sub.nodeType !== 1 || sub.namespaceURI !== W_NS || sub.localName !== "trHeight") continue;
|
|
440
|
+
const valAttr = sub.getAttributeNS(W_NS, "val");
|
|
441
|
+
const val = valAttr !== null ? parseInt(valAttr, 10) : 0;
|
|
442
|
+
const hRuleAttr = sub.getAttributeNS(W_NS, "hRule");
|
|
443
|
+
let hRule = "auto";
|
|
444
|
+
if (hRuleAttr === "atLeast") hRule = "atLeast";
|
|
445
|
+
else if (hRuleAttr === "exact") hRule = "exact";
|
|
446
|
+
return { val: isNaN(val) ? 0 : val, hRule };
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
__name(readTrHeight, "readTrHeight");
|
|
453
|
+
function firstCellParaId(tc) {
|
|
454
|
+
var _a;
|
|
455
|
+
for (let k = 0; k < tc.childNodes.length; k++) {
|
|
456
|
+
const p = tc.childNodes[k];
|
|
457
|
+
if (!p || p.nodeType !== 1 || p.namespaceURI !== W_NS || p.localName !== "p") continue;
|
|
458
|
+
return (_a = p.getAttributeNS(W14_NS, "paraId")) != null ? _a : void 0;
|
|
459
|
+
}
|
|
460
|
+
return void 0;
|
|
461
|
+
}
|
|
462
|
+
__name(firstCellParaId, "firstCellParaId");
|
|
463
|
+
function collectCellDrawingIds(tc, drawingToId) {
|
|
464
|
+
const ids = [];
|
|
465
|
+
const drawings = tc.getElementsByTagNameNS(W_NS, "drawing");
|
|
466
|
+
for (let i = 0; i < drawings.length; i++) {
|
|
467
|
+
const dr = drawings[i];
|
|
468
|
+
if (!dr) continue;
|
|
469
|
+
if (nearestCellOf(dr) !== tc) continue;
|
|
470
|
+
const id = drawingToId.get(dr);
|
|
471
|
+
if (id !== void 0) ids.push(id);
|
|
472
|
+
}
|
|
473
|
+
return ids;
|
|
474
|
+
}
|
|
475
|
+
__name(collectCellDrawingIds, "collectCellDrawingIds");
|
|
476
|
+
function nearestCellOf(el) {
|
|
477
|
+
let p = el.parentElement;
|
|
478
|
+
while (p) {
|
|
479
|
+
if (p.namespaceURI === W_NS) {
|
|
480
|
+
if (p.localName === "tc") return p;
|
|
481
|
+
if (p.localName === "body" || p.localName === "hdr" || p.localName === "ftr" || p.localName === "footnote" || p.localName === "endnote" || p.localName === "comment") {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
p = p.parentElement;
|
|
486
|
+
}
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
__name(nearestCellOf, "nearestCellOf");
|
|
490
|
+
function collectCellParagraphIds(tc) {
|
|
491
|
+
const ids = [];
|
|
492
|
+
for (let k = 0; k < tc.childNodes.length; k++) {
|
|
493
|
+
const p = tc.childNodes[k];
|
|
494
|
+
if (!p || p.nodeType !== 1 || p.namespaceURI !== W_NS || p.localName !== "p") continue;
|
|
495
|
+
const paraId = p.getAttributeNS(W14_NS, "paraId");
|
|
496
|
+
if (paraId) ids.push(paraId);
|
|
497
|
+
}
|
|
498
|
+
return ids;
|
|
499
|
+
}
|
|
500
|
+
__name(collectCellParagraphIds, "collectCellParagraphIds");
|
|
501
|
+
function directDrawingIdsInParagraph(p, ownerCell, drawingToId) {
|
|
502
|
+
const ids = [];
|
|
503
|
+
const drawings = p.getElementsByTagNameNS(W_NS, "drawing");
|
|
504
|
+
for (let i = 0; i < drawings.length; i++) {
|
|
505
|
+
const dr = drawings[i];
|
|
506
|
+
if (!dr || nearestCellOf(dr) !== ownerCell) continue;
|
|
507
|
+
const id = drawingToId.get(dr);
|
|
508
|
+
if (id !== void 0) ids.push(id);
|
|
509
|
+
}
|
|
510
|
+
return ids;
|
|
511
|
+
}
|
|
512
|
+
__name(directDrawingIdsInParagraph, "directDrawingIdsInParagraph");
|
|
513
|
+
function collectCellBlocks(tc, drawingToId, tableToId) {
|
|
514
|
+
var _a;
|
|
515
|
+
const blocks = [];
|
|
516
|
+
for (let k = 0; k < tc.childNodes.length; k++) {
|
|
517
|
+
const child = tc.childNodes[k];
|
|
518
|
+
if (!child || child.nodeType !== 1 || child.namespaceURI !== W_NS) continue;
|
|
519
|
+
if (child.localName === "p") {
|
|
520
|
+
const paraId = (_a = child.getAttributeNS(W14_NS, "paraId")) != null ? _a : void 0;
|
|
521
|
+
const text = getParagraphText(child);
|
|
522
|
+
const drawingIds = directDrawingIdsInParagraph(child, tc, drawingToId);
|
|
523
|
+
if (paraId && (text.length > 0 || drawingIds.length === 0)) {
|
|
524
|
+
blocks.push({ type: "paragraph", paraId, text });
|
|
525
|
+
}
|
|
526
|
+
for (const drawingId of drawingIds) {
|
|
527
|
+
blocks.push(
|
|
528
|
+
paraId ? { type: "drawing", drawingId, paraId } : { type: "drawing", drawingId }
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (child.localName === "tbl") {
|
|
534
|
+
const tableId = tableToId.get(child);
|
|
535
|
+
if (tableId) blocks.push({ type: "table", tableId });
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return blocks;
|
|
539
|
+
}
|
|
540
|
+
__name(collectCellBlocks, "collectCellBlocks");
|
|
541
|
+
function extractCellGrid(tbl, drawingToId, tableToId) {
|
|
542
|
+
const rows = [];
|
|
543
|
+
for (let i = 0; i < tbl.childNodes.length; i++) {
|
|
544
|
+
const tr = tbl.childNodes[i];
|
|
545
|
+
if (!tr || tr.nodeType !== 1 || tr.namespaceURI !== W_NS || tr.localName !== "tr") continue;
|
|
546
|
+
const rowCells = [];
|
|
547
|
+
for (let j = 0; j < tr.childNodes.length; j++) {
|
|
548
|
+
const tc = tr.childNodes[j];
|
|
549
|
+
if (!tc || tc.nodeType !== 1 || tc.namespaceURI !== W_NS || tc.localName !== "tc") continue;
|
|
550
|
+
const paragraphs = [];
|
|
551
|
+
for (let k = 0; k < tc.childNodes.length; k++) {
|
|
552
|
+
const p = tc.childNodes[k];
|
|
553
|
+
if (!p || p.nodeType !== 1 || p.namespaceURI !== W_NS || p.localName !== "p") continue;
|
|
554
|
+
paragraphs.push(getParagraphText(p));
|
|
555
|
+
}
|
|
556
|
+
const cell = {
|
|
557
|
+
text: paragraphs.join("\n"),
|
|
558
|
+
gridSpan: readGridSpan(tc),
|
|
559
|
+
vMerge: readVMerge(tc),
|
|
560
|
+
paragraphIds: collectCellParagraphIds(tc),
|
|
561
|
+
blocks: collectCellBlocks(tc, drawingToId, tableToId),
|
|
562
|
+
imageDrawingIds: collectCellDrawingIds(tc, drawingToId)
|
|
563
|
+
};
|
|
564
|
+
const fpid = firstCellParaId(tc);
|
|
565
|
+
if (fpid !== void 0) cell.firstParaId = fpid;
|
|
566
|
+
const width = readCellWidth(tc);
|
|
567
|
+
if (width !== void 0) cell.width = width;
|
|
568
|
+
const shading = readCellShading(tc);
|
|
569
|
+
if (shading !== void 0) cell.shading = shading;
|
|
570
|
+
const verticalAlignment = readCellVerticalAlignment(tc);
|
|
571
|
+
if (verticalAlignment !== void 0) cell.verticalAlignment = verticalAlignment;
|
|
572
|
+
rowCells.push(cell);
|
|
573
|
+
}
|
|
574
|
+
rows.push(rowCells);
|
|
575
|
+
}
|
|
576
|
+
return rows;
|
|
577
|
+
}
|
|
578
|
+
__name(extractCellGrid, "extractCellGrid");
|
|
579
|
+
function analyzeTable(tbl, tableId, partPath, index, includeCellTexts, drawingToId, tableToId) {
|
|
580
|
+
var _a;
|
|
581
|
+
let rowCount = 0;
|
|
582
|
+
let hasMerge = false;
|
|
583
|
+
const rowHeights = [];
|
|
584
|
+
const hasNestedTables = tbl.getElementsByTagNameNS(W_NS, "tbl").length > 0;
|
|
585
|
+
for (let i = 0; i < tbl.childNodes.length; i++) {
|
|
586
|
+
const child = tbl.childNodes[i];
|
|
587
|
+
if (child.nodeType !== 1) continue;
|
|
588
|
+
if (child.namespaceURI !== W_NS) continue;
|
|
589
|
+
if (child.localName === "tr") {
|
|
590
|
+
rowCount++;
|
|
591
|
+
rowHeights.push(readTrHeight(child));
|
|
592
|
+
if (!hasMerge) {
|
|
593
|
+
const cells = snapshot2(child.getElementsByTagNameNS(W_NS, "tc"));
|
|
594
|
+
for (const tc of cells) {
|
|
595
|
+
const gridSpanEls = tc.getElementsByTagNameNS(W_NS, "gridSpan");
|
|
596
|
+
if (gridSpanEls.length > 0) {
|
|
597
|
+
const val = gridSpanEls[0].getAttributeNS(W_NS, "val");
|
|
598
|
+
if (val && Number(val) > 1) {
|
|
599
|
+
hasMerge = true;
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (tc.getElementsByTagNameNS(W_NS, "vMerge").length > 0) {
|
|
604
|
+
hasMerge = true;
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
let colCount = 0;
|
|
612
|
+
const columnWidths = [];
|
|
613
|
+
const tblGridEls = tbl.getElementsByTagNameNS(W_NS, "tblGrid");
|
|
614
|
+
if (tblGridEls.length > 0) {
|
|
615
|
+
const gridCols = tblGridEls[0].getElementsByTagNameNS(W_NS, "gridCol");
|
|
616
|
+
colCount = gridCols.length;
|
|
617
|
+
for (let i = 0; i < gridCols.length; i++) {
|
|
618
|
+
const wAttr = gridCols[i].getAttributeNS(W_NS, "w");
|
|
619
|
+
columnWidths.push(wAttr !== null ? Number(wAttr) : 0);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
let tableStyleId;
|
|
623
|
+
const tblStyleEls = tbl.getElementsByTagNameNS(W_NS, "tblStyle");
|
|
624
|
+
if (tblStyleEls.length > 0) {
|
|
625
|
+
tableStyleId = (_a = tblStyleEls[0].getAttributeNS(W_NS, "val")) != null ? _a : void 0;
|
|
626
|
+
}
|
|
627
|
+
const hasImages = tbl.getElementsByTagNameNS(W_NS, "drawing").length > 0;
|
|
628
|
+
const info = {
|
|
629
|
+
tableId,
|
|
630
|
+
partPath,
|
|
631
|
+
index,
|
|
632
|
+
isNested: hasTableAncestor(tbl),
|
|
633
|
+
rowCount,
|
|
634
|
+
colCount,
|
|
635
|
+
hasMerge,
|
|
636
|
+
hasImages,
|
|
637
|
+
hasNestedTables,
|
|
638
|
+
columnWidths,
|
|
639
|
+
rowHeights
|
|
640
|
+
};
|
|
641
|
+
if (tableStyleId !== void 0) info.tableStyleId = tableStyleId;
|
|
642
|
+
const prev = prevParaId(tbl);
|
|
643
|
+
if (prev !== void 0) info.prevParaId = prev;
|
|
644
|
+
const next = nextParaId(tbl);
|
|
645
|
+
if (next !== void 0) info.nextParaId = next;
|
|
646
|
+
if (includeCellTexts) {
|
|
647
|
+
const grid = extractCellGrid(tbl, drawingToId, tableToId);
|
|
648
|
+
info.cellGrid = grid;
|
|
649
|
+
info.cells = grid.map((row) => row.map((cell) => cell.text));
|
|
650
|
+
}
|
|
651
|
+
return info;
|
|
652
|
+
}
|
|
653
|
+
__name(analyzeTable, "analyzeTable");
|
|
654
|
+
function buildDrawingReverseMap(drawingIdx) {
|
|
655
|
+
const rev = /* @__PURE__ */ new Map();
|
|
656
|
+
for (const [id, el] of drawingIdx) rev.set(el, id);
|
|
657
|
+
return rev;
|
|
658
|
+
}
|
|
659
|
+
__name(buildDrawingReverseMap, "buildDrawingReverseMap");
|
|
660
|
+
function buildTableReverseMap(tblIdx) {
|
|
661
|
+
const rev = /* @__PURE__ */ new Map();
|
|
662
|
+
for (const [id, el] of tblIdx) rev.set(el, id);
|
|
663
|
+
return rev;
|
|
664
|
+
}
|
|
665
|
+
__name(buildTableReverseMap, "buildTableReverseMap");
|
|
666
|
+
function findStoryForEl(el, stories) {
|
|
667
|
+
for (const s of stories) {
|
|
668
|
+
if (s.root.contains(el)) return s;
|
|
669
|
+
}
|
|
670
|
+
return void 0;
|
|
671
|
+
}
|
|
672
|
+
__name(findStoryForEl, "findStoryForEl");
|
|
673
|
+
function listTables(pkg, indices, opts) {
|
|
674
|
+
var _a, _b, _c;
|
|
675
|
+
const scope = (_a = opts == null ? void 0 : opts.scope) != null ? _a : "body";
|
|
676
|
+
const includeNested = (_b = opts == null ? void 0 : opts.includeNested) != null ? _b : false;
|
|
677
|
+
const includeCellTexts = (_c = opts == null ? void 0 : opts.includeCellTexts) != null ? _c : false;
|
|
678
|
+
const stories = resolveScope(pkg, scope);
|
|
679
|
+
const result = [];
|
|
680
|
+
let idx = 1;
|
|
681
|
+
const drawingToId = includeCellTexts ? buildDrawingReverseMap(indices.drawingIdx) : EMPTY_DRAWING_REV;
|
|
682
|
+
const tableToId = includeCellTexts ? buildTableReverseMap(indices.tblIdx) : EMPTY_TABLE_REV;
|
|
683
|
+
for (const [tableId, tbl] of indices.tblIdx) {
|
|
684
|
+
if (!includeNested && hasTableAncestor(tbl)) continue;
|
|
685
|
+
const story = findStoryForEl(tbl, stories);
|
|
686
|
+
if (!story) continue;
|
|
687
|
+
result.push(
|
|
688
|
+
analyzeTable(tbl, tableId, story.partPath, idx++, includeCellTexts, drawingToId, tableToId)
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
return result;
|
|
692
|
+
}
|
|
693
|
+
__name(listTables, "listTables");
|
|
694
|
+
var EMPTY_DRAWING_REV = /* @__PURE__ */ new Map();
|
|
695
|
+
var EMPTY_TABLE_REV = /* @__PURE__ */ new Map();
|
|
696
|
+
function buildTableIndex(parts) {
|
|
697
|
+
const tblIdx = /* @__PURE__ */ new Map();
|
|
698
|
+
let n = 1;
|
|
699
|
+
for (const part of parts) {
|
|
700
|
+
const ct = part.contentType;
|
|
701
|
+
if (!ct.includes("wordprocessingml") && !ct.endsWith(".main+xml") && !ct.endsWith(".header+xml") && !ct.endsWith(".footer+xml") && !ct.endsWith(".footnotes+xml") && !ct.endsWith(".endnotes+xml")) {
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
if (!part.xmlDom) continue;
|
|
705
|
+
const tbls = part.xmlDom.getElementsByTagNameNS(W_NS, "tbl");
|
|
706
|
+
for (let i = 0; i < tbls.length; i++) {
|
|
707
|
+
const tbl = tbls[i];
|
|
708
|
+
if (!tbl) continue;
|
|
709
|
+
const id = `tbl-${String(n).padStart(4, "0")}`;
|
|
710
|
+
tblIdx.set(id, tbl);
|
|
711
|
+
n++;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return tblIdx;
|
|
715
|
+
}
|
|
716
|
+
__name(buildTableIndex, "buildTableIndex");
|
|
717
|
+
|
|
718
|
+
// src/word/list-drawings.ts
|
|
719
|
+
function snapshot3(col) {
|
|
720
|
+
const out = [];
|
|
721
|
+
for (let i = 0; i < col.length; i++) {
|
|
722
|
+
const el = col[i];
|
|
723
|
+
if (el) out.push(el);
|
|
724
|
+
}
|
|
725
|
+
return out;
|
|
726
|
+
}
|
|
727
|
+
__name(snapshot3, "snapshot");
|
|
728
|
+
function parseOnOff(value) {
|
|
729
|
+
if (value === null) return void 0;
|
|
730
|
+
const v = value.trim().toLowerCase();
|
|
731
|
+
if (v === "1" || v === "true" || v === "on") return true;
|
|
732
|
+
if (v === "0" || v === "false" || v === "off") return false;
|
|
733
|
+
return void 0;
|
|
734
|
+
}
|
|
735
|
+
__name(parseOnOff, "parseOnOff");
|
|
736
|
+
function hasFallbackAncestor(el) {
|
|
737
|
+
let p = el.parentElement;
|
|
738
|
+
while (p) {
|
|
739
|
+
if (p.namespaceURI === MC_NS && p.localName === "Fallback") return true;
|
|
740
|
+
p = p.parentElement;
|
|
741
|
+
}
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
__name(hasFallbackAncestor, "hasFallbackAncestor");
|
|
745
|
+
function firstDirectChild(parent, ns, local) {
|
|
746
|
+
for (let i = 0; i < parent.childNodes.length; i++) {
|
|
747
|
+
const child = parent.childNodes[i];
|
|
748
|
+
if (child && child.nodeType === 1 && child.namespaceURI === ns && child.localName === local) {
|
|
749
|
+
return child;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
__name(firstDirectChild, "firstDirectChild");
|
|
755
|
+
function firstDescendant(parent, ns, local) {
|
|
756
|
+
const col = parent.getElementsByTagNameNS(ns, local);
|
|
757
|
+
return col.length > 0 ? col[0] : null;
|
|
758
|
+
}
|
|
759
|
+
__name(firstDescendant, "firstDescendant");
|
|
760
|
+
function readNumAttr(el, ns, local) {
|
|
761
|
+
const v = ns === null ? el.getAttribute(local) : el.getAttributeNS(ns, local);
|
|
762
|
+
if (v === null) return void 0;
|
|
763
|
+
const n = Number(v);
|
|
764
|
+
return Number.isFinite(n) ? n : void 0;
|
|
765
|
+
}
|
|
766
|
+
__name(readNumAttr, "readNumAttr");
|
|
767
|
+
function textContentOfDirect(el) {
|
|
768
|
+
var _a;
|
|
769
|
+
let s = "";
|
|
770
|
+
for (let i = 0; i < el.childNodes.length; i++) {
|
|
771
|
+
const child = el.childNodes[i];
|
|
772
|
+
if (child.nodeType === 3) {
|
|
773
|
+
s += (_a = child.nodeValue) != null ? _a : "";
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
return s;
|
|
777
|
+
}
|
|
778
|
+
__name(textContentOfDirect, "textContentOfDirect");
|
|
779
|
+
function readPositionAxis(axisEl) {
|
|
780
|
+
const out = {};
|
|
781
|
+
const relativeFrom = axisEl.getAttribute("relativeFrom");
|
|
782
|
+
if (relativeFrom !== null) out.relativeFrom = relativeFrom;
|
|
783
|
+
const posOffsetEl = firstDirectChild(axisEl, WP_NS, "posOffset");
|
|
784
|
+
if (posOffsetEl) {
|
|
785
|
+
const txt = textContentOfDirect(posOffsetEl).trim();
|
|
786
|
+
const n = Number(txt);
|
|
787
|
+
if (Number.isFinite(n)) out.posOffset = n;
|
|
788
|
+
} else {
|
|
789
|
+
const alignEl = firstDirectChild(axisEl, WP_NS, "align");
|
|
790
|
+
if (alignEl) {
|
|
791
|
+
const txt = textContentOfDirect(alignEl).trim();
|
|
792
|
+
if (txt) out.align = txt;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
return out;
|
|
796
|
+
}
|
|
797
|
+
__name(readPositionAxis, "readPositionAxis");
|
|
798
|
+
function readWrap(anchor) {
|
|
799
|
+
if (firstDirectChild(anchor, WP_NS, "wrapTopAndBottom")) return "topAndBottom";
|
|
800
|
+
if (firstDirectChild(anchor, WP_NS, "wrapSquare")) return "square";
|
|
801
|
+
if (firstDirectChild(anchor, WP_NS, "wrapTight")) return "tight";
|
|
802
|
+
if (firstDirectChild(anchor, WP_NS, "wrapThrough")) return "through";
|
|
803
|
+
if (firstDirectChild(anchor, WP_NS, "wrapNone")) {
|
|
804
|
+
const behind = parseOnOff(anchor.getAttribute("behindDoc"));
|
|
805
|
+
if (behind === true) return "behind";
|
|
806
|
+
if (behind === false) return "inFront";
|
|
807
|
+
return "none";
|
|
808
|
+
}
|
|
809
|
+
return void 0;
|
|
810
|
+
}
|
|
811
|
+
__name(readWrap, "readWrap");
|
|
812
|
+
function readExtent(container) {
|
|
813
|
+
var _a, _b;
|
|
814
|
+
const ext = firstDirectChild(container, WP_NS, "extent");
|
|
815
|
+
if (!ext) return { cx: 0, cy: 0 };
|
|
816
|
+
const cx = (_a = readNumAttr(ext, null, "cx")) != null ? _a : 0;
|
|
817
|
+
const cy = (_b = readNumAttr(ext, null, "cy")) != null ? _b : 0;
|
|
818
|
+
return { cx, cy };
|
|
819
|
+
}
|
|
820
|
+
__name(readExtent, "readExtent");
|
|
821
|
+
function readPosition(anchor) {
|
|
822
|
+
const out = {};
|
|
823
|
+
const h = firstDirectChild(anchor, WP_NS, "positionH");
|
|
824
|
+
if (h) out.horizontal = readPositionAxis(h);
|
|
825
|
+
const v = firstDirectChild(anchor, WP_NS, "positionV");
|
|
826
|
+
if (v) out.vertical = readPositionAxis(v);
|
|
827
|
+
return out;
|
|
828
|
+
}
|
|
829
|
+
__name(readPosition, "readPosition");
|
|
830
|
+
function detectKind(container) {
|
|
831
|
+
var _a;
|
|
832
|
+
const graphic = firstDescendant(container, A_NS, "graphic");
|
|
833
|
+
if (!graphic) return "other";
|
|
834
|
+
const gd = firstDescendant(graphic, A_NS, "graphicData");
|
|
835
|
+
if (!gd) return "other";
|
|
836
|
+
const uri = (_a = gd.getAttribute("uri")) != null ? _a : "";
|
|
837
|
+
if (uri === PIC_NS) return "picture";
|
|
838
|
+
if (uri === CHART_NS) return "chart";
|
|
839
|
+
if (uri === DGM_NS) return "smartArt";
|
|
840
|
+
if (uri === WPG_NS) return "group";
|
|
841
|
+
if (uri === WPC_NS) return "canvas";
|
|
842
|
+
if (uri === WPS_NS) {
|
|
843
|
+
if (gd.getElementsByTagNameNS(W_NS, "txbxContent").length > 0) return "textBox";
|
|
844
|
+
return "shape";
|
|
845
|
+
}
|
|
846
|
+
return "other";
|
|
847
|
+
}
|
|
848
|
+
__name(detectKind, "detectKind");
|
|
849
|
+
function hasPicReferenceIn(container) {
|
|
850
|
+
return container.getElementsByTagNameNS(PIC_NS, "pic").length > 0;
|
|
851
|
+
}
|
|
852
|
+
__name(hasPicReferenceIn, "hasPicReferenceIn");
|
|
853
|
+
var LINE_CONNECTOR_PRESETS = /* @__PURE__ */ new Set([
|
|
854
|
+
"line",
|
|
855
|
+
"straightConnector1",
|
|
856
|
+
"bentConnector2",
|
|
857
|
+
"bentConnector3",
|
|
858
|
+
"bentConnector4",
|
|
859
|
+
"bentConnector5",
|
|
860
|
+
"curvedConnector2",
|
|
861
|
+
"curvedConnector3",
|
|
862
|
+
"curvedConnector4",
|
|
863
|
+
"curvedConnector5"
|
|
864
|
+
]);
|
|
865
|
+
function isLineOrConnectorShape(container) {
|
|
866
|
+
var _a;
|
|
867
|
+
const prstGeoms = container.getElementsByTagNameNS(A_NS, "prstGeom");
|
|
868
|
+
for (let i = 0; i < prstGeoms.length; i++) {
|
|
869
|
+
const prst = (_a = prstGeoms[i]) == null ? void 0 : _a.getAttribute("prst");
|
|
870
|
+
if (prst && LINE_CONNECTOR_PRESETS.has(prst)) return true;
|
|
871
|
+
}
|
|
872
|
+
if (container.getElementsByTagNameNS(WPS_NS, "cNvCnPr").length > 0) return true;
|
|
873
|
+
if (container.getElementsByTagNameNS(VML_NS, "line").length > 0) return true;
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
__name(isLineOrConnectorShape, "isLineOrConnectorShape");
|
|
877
|
+
function readShapeSignals(container, isTextBox, runTextOpts, drawingToId = /* @__PURE__ */ new Map(), tableToId = /* @__PURE__ */ new Map()) {
|
|
878
|
+
const wspSpPr = firstDescendant(container, WPS_NS, "spPr");
|
|
879
|
+
const aSpPr = firstDescendant(container, A_NS, "spPr");
|
|
880
|
+
const spPr = wspSpPr != null ? wspSpPr : aSpPr;
|
|
881
|
+
let hasBorder = false;
|
|
882
|
+
let hasFill = false;
|
|
883
|
+
if (spPr) {
|
|
884
|
+
const ln = firstDirectChild(spPr, A_NS, "ln");
|
|
885
|
+
if (ln) {
|
|
886
|
+
const noLineFill = firstDirectChild(ln, A_NS, "noFill");
|
|
887
|
+
const widthAttr = ln.getAttribute("w");
|
|
888
|
+
const isZeroWidth = widthAttr !== null && widthAttr.trim() === "0";
|
|
889
|
+
hasBorder = !noLineFill && !isZeroWidth;
|
|
890
|
+
}
|
|
891
|
+
const noFill = firstDirectChild(spPr, A_NS, "noFill");
|
|
892
|
+
if (!noFill) {
|
|
893
|
+
hasFill = !!firstDirectChild(spPr, A_NS, "solidFill") || !!firstDirectChild(spPr, A_NS, "gradFill") || !!firstDirectChild(spPr, A_NS, "blipFill") || !!firstDirectChild(spPr, A_NS, "pattFill");
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
const out = { hasBorder, hasFill };
|
|
897
|
+
if (isTextBox) {
|
|
898
|
+
const txbx = firstDescendant(container, W_NS, "txbxContent");
|
|
899
|
+
if (txbx) {
|
|
900
|
+
const paragraphs = snapshot3(txbx.getElementsByTagNameNS(W_NS, "p"));
|
|
901
|
+
const ids = [];
|
|
902
|
+
for (const p of paragraphs) {
|
|
903
|
+
const id = p.getAttributeNS(W14_NS, "paraId");
|
|
904
|
+
if (id) ids.push(id.toUpperCase());
|
|
905
|
+
}
|
|
906
|
+
out.innerParagraphIds = ids;
|
|
907
|
+
out.innerBlocks = collectTextBoxBlocks(txbx, drawingToId, tableToId, runTextOpts);
|
|
908
|
+
let joined = "";
|
|
909
|
+
if (runTextOpts == null ? void 0 : runTextOpts.structuralWhitespace) {
|
|
910
|
+
const runs = snapshot3(txbx.getElementsByTagNameNS(W_NS, "r"));
|
|
911
|
+
for (const r of runs) {
|
|
912
|
+
joined += getRunText(r, runTextOpts);
|
|
913
|
+
}
|
|
914
|
+
} else {
|
|
915
|
+
const tEls = snapshot3(txbx.getElementsByTagNameNS(W_NS, "t"));
|
|
916
|
+
for (const t of tEls) {
|
|
917
|
+
joined += textContentOfDirect(t);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
out.hasInnerText = joined.length > 0;
|
|
921
|
+
const trimmed = joined.trim();
|
|
922
|
+
if (trimmed.length > 0) out.innerText = trimmed;
|
|
923
|
+
const firstP = firstDescendant(txbx, W_NS, "p");
|
|
924
|
+
if (firstP) {
|
|
925
|
+
const pPr = firstDirectChild(firstP, W_NS, "pPr");
|
|
926
|
+
if (pPr) {
|
|
927
|
+
const jc = firstDirectChild(pPr, W_NS, "jc");
|
|
928
|
+
if (jc) {
|
|
929
|
+
const val = jc.getAttributeNS(W_NS, "val");
|
|
930
|
+
if (val) out.innerTextAlign = val;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
out.hasInnerText = false;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return out;
|
|
939
|
+
}
|
|
940
|
+
__name(readShapeSignals, "readShapeSignals");
|
|
941
|
+
function findAnchorParagraph(drawing) {
|
|
942
|
+
let p = drawing.parentElement;
|
|
943
|
+
let runEl = null;
|
|
944
|
+
let containerP = null;
|
|
945
|
+
while (p) {
|
|
946
|
+
if (p.namespaceURI === W_NS) {
|
|
947
|
+
if (p.localName === "r" && !runEl) runEl = p;
|
|
948
|
+
if (p.localName === "p") {
|
|
949
|
+
containerP = p;
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
p = p.parentElement;
|
|
954
|
+
}
|
|
955
|
+
if (!containerP) return { para: null, runIndex: void 0 };
|
|
956
|
+
let q = containerP.parentElement;
|
|
957
|
+
while (q) {
|
|
958
|
+
if (q.namespaceURI === W_NS) {
|
|
959
|
+
if (q.localName === "txbxContent") {
|
|
960
|
+
return { para: null, runIndex: void 0 };
|
|
961
|
+
}
|
|
962
|
+
if (q.localName === "body" || q.localName === "hdr" || q.localName === "ftr" || q.localName === "footnote" || q.localName === "endnote" || q.localName === "comment") {
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
q = q.parentElement;
|
|
967
|
+
}
|
|
968
|
+
let runIndex;
|
|
969
|
+
if (runEl) {
|
|
970
|
+
let n = 0;
|
|
971
|
+
for (let i = 0; i < containerP.childNodes.length; i++) {
|
|
972
|
+
const child = containerP.childNodes[i];
|
|
973
|
+
if (child && child.nodeType === 1 && child.namespaceURI === W_NS && child.localName === "r") {
|
|
974
|
+
if (child === runEl) {
|
|
975
|
+
runIndex = n;
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
n++;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return { para: containerP, runIndex };
|
|
983
|
+
}
|
|
984
|
+
__name(findAnchorParagraph, "findAnchorParagraph");
|
|
985
|
+
function nearestAncestor(el, ns, localName) {
|
|
986
|
+
let p = el.parentElement;
|
|
987
|
+
while (p) {
|
|
988
|
+
if (p.namespaceURI === ns && p.localName === localName) return p;
|
|
989
|
+
p = p.parentElement;
|
|
990
|
+
}
|
|
991
|
+
return null;
|
|
992
|
+
}
|
|
993
|
+
__name(nearestAncestor, "nearestAncestor");
|
|
994
|
+
function paragraphText(p, runTextOpts) {
|
|
995
|
+
let text = "";
|
|
996
|
+
for (let i = 0; i < p.childNodes.length; i++) {
|
|
997
|
+
const child = p.childNodes[i];
|
|
998
|
+
if (!child || child.nodeType !== 1 || child.namespaceURI !== W_NS) continue;
|
|
999
|
+
if (child.localName === "r") text += getRunText(child, runTextOpts);
|
|
1000
|
+
}
|
|
1001
|
+
return text;
|
|
1002
|
+
}
|
|
1003
|
+
__name(paragraphText, "paragraphText");
|
|
1004
|
+
function directDrawingIdsInTextBoxParagraph(p, ownerTxbx, drawingToId) {
|
|
1005
|
+
const ids = [];
|
|
1006
|
+
const drawings = p.getElementsByTagNameNS(W_NS, "drawing");
|
|
1007
|
+
for (let i = 0; i < drawings.length; i++) {
|
|
1008
|
+
const drawing = drawings[i];
|
|
1009
|
+
if (!drawing || nearestAncestor(drawing, W_NS, "txbxContent") !== ownerTxbx) continue;
|
|
1010
|
+
const id = drawingToId.get(drawing);
|
|
1011
|
+
if (id) ids.push(id);
|
|
1012
|
+
}
|
|
1013
|
+
return ids;
|
|
1014
|
+
}
|
|
1015
|
+
__name(directDrawingIdsInTextBoxParagraph, "directDrawingIdsInTextBoxParagraph");
|
|
1016
|
+
function collectTextBoxBlocks(txbx, drawingToId, tableToId, runTextOpts) {
|
|
1017
|
+
var _a;
|
|
1018
|
+
const blocks = [];
|
|
1019
|
+
for (let i = 0; i < txbx.childNodes.length; i++) {
|
|
1020
|
+
const child = txbx.childNodes[i];
|
|
1021
|
+
if (!child || child.nodeType !== 1 || child.namespaceURI !== W_NS) continue;
|
|
1022
|
+
if (child.localName === "p") {
|
|
1023
|
+
const paraId = (_a = child.getAttributeNS(W14_NS, "paraId")) != null ? _a : void 0;
|
|
1024
|
+
const text = paragraphText(child, runTextOpts);
|
|
1025
|
+
const drawingIds = directDrawingIdsInTextBoxParagraph(child, txbx, drawingToId);
|
|
1026
|
+
if (paraId && (text.length > 0 || drawingIds.length === 0)) {
|
|
1027
|
+
blocks.push({ type: "paragraph", paraId: paraId.toUpperCase(), text });
|
|
1028
|
+
}
|
|
1029
|
+
for (const drawingId of drawingIds) {
|
|
1030
|
+
blocks.push(
|
|
1031
|
+
paraId ? { type: "drawing", drawingId, paraId: paraId.toUpperCase() } : { type: "drawing", drawingId }
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
1036
|
+
if (child.localName === "tbl") {
|
|
1037
|
+
const tableId = tableToId.get(child);
|
|
1038
|
+
if (tableId) blocks.push({ type: "table", tableId });
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return blocks;
|
|
1042
|
+
}
|
|
1043
|
+
__name(collectTextBoxBlocks, "collectTextBoxBlocks");
|
|
1044
|
+
function reverseElementIndex(index) {
|
|
1045
|
+
const reversed = /* @__PURE__ */ new Map();
|
|
1046
|
+
for (const [id, el] of index) reversed.set(el, id);
|
|
1047
|
+
return reversed;
|
|
1048
|
+
}
|
|
1049
|
+
__name(reverseElementIndex, "reverseElementIndex");
|
|
1050
|
+
function findStoryForEl2(el, stories) {
|
|
1051
|
+
for (const s of stories) {
|
|
1052
|
+
if (s.root.contains(el)) return s;
|
|
1053
|
+
}
|
|
1054
|
+
return void 0;
|
|
1055
|
+
}
|
|
1056
|
+
__name(findStoryForEl2, "findStoryForEl");
|
|
1057
|
+
function isHeaderFooterPart(pkg, partPath) {
|
|
1058
|
+
const part = pkg.parts.get(partPath);
|
|
1059
|
+
if (!part) return false;
|
|
1060
|
+
const ct = part.contentType;
|
|
1061
|
+
return ct.endsWith(".header+xml") || ct.endsWith(".footer+xml");
|
|
1062
|
+
}
|
|
1063
|
+
__name(isHeaderFooterPart, "isHeaderFooterPart");
|
|
1064
|
+
function analyzeDrawing(drawing, runTextOpts, drawingToId, tableToId) {
|
|
1065
|
+
var _a;
|
|
1066
|
+
const inlineEl = firstDirectChild(drawing, WP_NS, "inline");
|
|
1067
|
+
const anchorEl = firstDirectChild(drawing, WP_NS, "anchor");
|
|
1068
|
+
const container = inlineEl != null ? inlineEl : anchorEl;
|
|
1069
|
+
const anchoringMode = anchorEl ? "anchor" : "inline";
|
|
1070
|
+
const kind = container ? detectKind(container) : "other";
|
|
1071
|
+
const extentEMU = container ? readExtent(container) : { cx: 0, cy: 0 };
|
|
1072
|
+
const hasPicReference = container ? hasPicReferenceIn(container) : false;
|
|
1073
|
+
const { para, runIndex } = findAnchorParagraph(drawing);
|
|
1074
|
+
const anchorParaId = (_a = para == null ? void 0 : para.getAttributeNS(W14_NS, "paraId")) != null ? _a : void 0;
|
|
1075
|
+
const info = {
|
|
1076
|
+
anchoringMode,
|
|
1077
|
+
kind,
|
|
1078
|
+
extentEMU,
|
|
1079
|
+
hasPicReference
|
|
1080
|
+
};
|
|
1081
|
+
if (anchorEl) {
|
|
1082
|
+
const wrap = readWrap(anchorEl);
|
|
1083
|
+
if (wrap !== void 0) info.wrap = wrap;
|
|
1084
|
+
const pos = readPosition(anchorEl);
|
|
1085
|
+
if (pos.horizontal || pos.vertical) info.position = pos;
|
|
1086
|
+
}
|
|
1087
|
+
if (anchorParaId !== void 0) info.anchorParaId = anchorParaId;
|
|
1088
|
+
if (runIndex !== void 0) info.runIndex = runIndex;
|
|
1089
|
+
if (kind === "shape" || kind === "textBox") {
|
|
1090
|
+
const sig = container ? readShapeSignals(container, kind === "textBox", runTextOpts, drawingToId, tableToId) : { hasBorder: false, hasFill: false };
|
|
1091
|
+
info.hasBorder = sig.hasBorder;
|
|
1092
|
+
info.hasFill = sig.hasFill;
|
|
1093
|
+
if (sig.hasInnerText !== void 0) info.hasInnerText = sig.hasInnerText;
|
|
1094
|
+
if (sig.innerText !== void 0) info.innerText = sig.innerText;
|
|
1095
|
+
if (sig.innerParagraphIds !== void 0) info.innerParagraphIds = sig.innerParagraphIds;
|
|
1096
|
+
if (sig.innerBlocks !== void 0) info.innerBlocks = sig.innerBlocks;
|
|
1097
|
+
if (sig.innerTextAlign !== void 0) info.innerTextAlign = sig.innerTextAlign;
|
|
1098
|
+
}
|
|
1099
|
+
if (kind === "shape" && container) {
|
|
1100
|
+
info.isLineOrConnector = isLineOrConnectorShape(container);
|
|
1101
|
+
}
|
|
1102
|
+
return info;
|
|
1103
|
+
}
|
|
1104
|
+
__name(analyzeDrawing, "analyzeDrawing");
|
|
1105
|
+
function listDrawings(pkg, indices, opts) {
|
|
1106
|
+
var _a;
|
|
1107
|
+
const scope = (_a = opts == null ? void 0 : opts.scope) != null ? _a : "body";
|
|
1108
|
+
const stories = resolveScope(pkg, scope);
|
|
1109
|
+
const result = [];
|
|
1110
|
+
let idx = 1;
|
|
1111
|
+
const runTextOpts = (opts == null ? void 0 : opts.structuralWhitespace) ? { structuralWhitespace: true } : void 0;
|
|
1112
|
+
const drawingToId = reverseElementIndex(indices.drawingIdx);
|
|
1113
|
+
const tableToId = reverseElementIndex(indices.tblIdx);
|
|
1114
|
+
for (const [drawingId, drawing] of indices.drawingIdx) {
|
|
1115
|
+
const story = findStoryForEl2(drawing, stories);
|
|
1116
|
+
if (!story) continue;
|
|
1117
|
+
const info = __spreadValues({
|
|
1118
|
+
drawingId,
|
|
1119
|
+
partPath: story.partPath,
|
|
1120
|
+
index: idx++,
|
|
1121
|
+
isInHeaderFooter: isHeaderFooterPart(pkg, story.partPath)
|
|
1122
|
+
}, analyzeDrawing(drawing, runTextOpts, drawingToId, tableToId));
|
|
1123
|
+
result.push(info);
|
|
1124
|
+
}
|
|
1125
|
+
return result;
|
|
1126
|
+
}
|
|
1127
|
+
__name(listDrawings, "listDrawings");
|
|
1128
|
+
function buildDrawingIndex(parts) {
|
|
1129
|
+
const drawingIdx = /* @__PURE__ */ new Map();
|
|
1130
|
+
let n = 1;
|
|
1131
|
+
for (const part of parts) {
|
|
1132
|
+
const ct = part.contentType;
|
|
1133
|
+
if (!ct.includes("wordprocessingml") && !ct.endsWith(".main+xml") && !ct.endsWith(".header+xml") && !ct.endsWith(".footer+xml") && !ct.endsWith(".footnotes+xml") && !ct.endsWith(".endnotes+xml") && !ct.endsWith(".comments+xml")) {
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
if (!part.xmlDom) continue;
|
|
1137
|
+
const drawings = part.xmlDom.getElementsByTagNameNS(W_NS, "drawing");
|
|
1138
|
+
for (let i = 0; i < drawings.length; i++) {
|
|
1139
|
+
const dr = drawings[i];
|
|
1140
|
+
if (!dr) continue;
|
|
1141
|
+
if (hasFallbackAncestor(dr)) continue;
|
|
1142
|
+
const id = `dr-${String(n).padStart(4, "0")}`;
|
|
1143
|
+
drawingIdx.set(id, dr);
|
|
1144
|
+
n++;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
return drawingIdx;
|
|
1148
|
+
}
|
|
1149
|
+
__name(buildDrawingIndex, "buildDrawingIndex");
|
|
1150
|
+
|
|
1151
|
+
// src/word/indices.ts
|
|
1152
|
+
var _BookmarkLoadError = class _BookmarkLoadError extends Error {
|
|
1153
|
+
constructor(code, message, details = {}) {
|
|
1154
|
+
super(message);
|
|
1155
|
+
__publicField(this, "code");
|
|
1156
|
+
__publicField(this, "details");
|
|
1157
|
+
this.name = "BookmarkLoadError";
|
|
1158
|
+
this.code = code;
|
|
1159
|
+
this.details = details;
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
__name(_BookmarkLoadError, "BookmarkLoadError");
|
|
1163
|
+
var BookmarkLoadError = _BookmarkLoadError;
|
|
1164
|
+
function isWordContentPart(part) {
|
|
1165
|
+
const ct = part.contentType;
|
|
1166
|
+
return ct.includes("wordprocessingml") || ct.endsWith(".main+xml") || ct.endsWith(".header+xml") || ct.endsWith(".footer+xml") || ct.endsWith(".footnotes+xml") || ct.endsWith(".endnotes+xml") || ct.endsWith(".comments+xml");
|
|
1167
|
+
}
|
|
1168
|
+
__name(isWordContentPart, "isWordContentPart");
|
|
1169
|
+
function isCommentsPart(part) {
|
|
1170
|
+
return part.contentType.endsWith(".comments+xml");
|
|
1171
|
+
}
|
|
1172
|
+
__name(isCommentsPart, "isCommentsPart");
|
|
1173
|
+
function snapshot4(col) {
|
|
1174
|
+
const out = [];
|
|
1175
|
+
for (let i = 0; i < col.length; i++) {
|
|
1176
|
+
const el = col[i];
|
|
1177
|
+
if (el) out.push(el);
|
|
1178
|
+
}
|
|
1179
|
+
return out;
|
|
1180
|
+
}
|
|
1181
|
+
__name(snapshot4, "snapshot");
|
|
1182
|
+
function buildIndices(pkg) {
|
|
1183
|
+
const paraIdx = /* @__PURE__ */ new Map();
|
|
1184
|
+
const bookmarkIdx = /* @__PURE__ */ new Map();
|
|
1185
|
+
const commentIdx = /* @__PURE__ */ new Map();
|
|
1186
|
+
const pendingStarts = /* @__PURE__ */ new Map();
|
|
1187
|
+
for (const part of pkg.parts.values()) {
|
|
1188
|
+
if (!isXmlPart(part) || !part.xmlDom) continue;
|
|
1189
|
+
if (!isWordContentPart(part)) continue;
|
|
1190
|
+
const paragraphs = snapshot4(part.xmlDom.getElementsByTagNameNS(W_NS, "p"));
|
|
1191
|
+
for (const p of paragraphs) {
|
|
1192
|
+
const id = p.getAttributeNS(W14_NS, "paraId");
|
|
1193
|
+
if (id) paraIdx.set(id.toUpperCase(), p);
|
|
1194
|
+
}
|
|
1195
|
+
const starts = snapshot4(part.xmlDom.getElementsByTagNameNS(W_NS, "bookmarkStart"));
|
|
1196
|
+
for (const start of starts) {
|
|
1197
|
+
const bId = start.getAttributeNS(W_NS, "id");
|
|
1198
|
+
const bName = start.getAttributeNS(W_NS, "name");
|
|
1199
|
+
if (bName === null) {
|
|
1200
|
+
throw new BookmarkLoadError(
|
|
1201
|
+
"BOOKMARK_NAME_EMPTY_ON_LOAD",
|
|
1202
|
+
`bookmarkStart with w:id="${bId != null ? bId : ""}" has no w:name`,
|
|
1203
|
+
{ partPath: part.path, bookmarkId: bId != null ? bId : null }
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
if (bName.length === 0) {
|
|
1207
|
+
throw new BookmarkLoadError(
|
|
1208
|
+
"BOOKMARK_NAME_EMPTY_ON_LOAD",
|
|
1209
|
+
`bookmarkStart with w:id="${bId != null ? bId : ""}" has empty w:name`,
|
|
1210
|
+
{ partPath: part.path, bookmarkId: bId != null ? bId : null }
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
if (bookmarkIdx.has(bName)) {
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
bookmarkIdx.set(bName, { start, end: null, partPath: part.path });
|
|
1217
|
+
if (bId !== null) {
|
|
1218
|
+
pendingStarts.set(`${part.path}::${bId}`, { start, partPath: part.path, name: bName });
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const ends = snapshot4(part.xmlDom.getElementsByTagNameNS(W_NS, "bookmarkEnd"));
|
|
1222
|
+
for (const end of ends) {
|
|
1223
|
+
const eId = end.getAttributeNS(W_NS, "id");
|
|
1224
|
+
if (eId === null) continue;
|
|
1225
|
+
const matched = pendingStarts.get(`${part.path}::${eId}`);
|
|
1226
|
+
if (matched) {
|
|
1227
|
+
const entry = bookmarkIdx.get(matched.name);
|
|
1228
|
+
if (entry) entry.end = end;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
const anchorStarts = snapshot4(part.xmlDom.getElementsByTagNameNS(W_NS, "commentRangeStart"));
|
|
1232
|
+
const anchorEnds = snapshot4(part.xmlDom.getElementsByTagNameNS(W_NS, "commentRangeEnd"));
|
|
1233
|
+
const anchorRefs = snapshot4(part.xmlDom.getElementsByTagNameNS(W_NS, "commentReference"));
|
|
1234
|
+
for (const anchor of anchorStarts) {
|
|
1235
|
+
const id = numAttr2(anchor, W_NS, "id");
|
|
1236
|
+
if (id === null) continue;
|
|
1237
|
+
getOrCreateCommentEntry(commentIdx, id).anchors.start = anchor;
|
|
1238
|
+
}
|
|
1239
|
+
for (const anchor of anchorEnds) {
|
|
1240
|
+
const id = numAttr2(anchor, W_NS, "id");
|
|
1241
|
+
if (id === null) continue;
|
|
1242
|
+
getOrCreateCommentEntry(commentIdx, id).anchors.end = anchor;
|
|
1243
|
+
}
|
|
1244
|
+
for (const anchor of anchorRefs) {
|
|
1245
|
+
const id = numAttr2(anchor, W_NS, "id");
|
|
1246
|
+
if (id === null) continue;
|
|
1247
|
+
getOrCreateCommentEntry(commentIdx, id).anchors.ref = anchor;
|
|
1248
|
+
}
|
|
1249
|
+
if (isCommentsPart(part)) {
|
|
1250
|
+
const comments = snapshot4(part.xmlDom.getElementsByTagNameNS(W_NS, "comment"));
|
|
1251
|
+
for (const c of comments) {
|
|
1252
|
+
const id = numAttr2(c, W_NS, "id");
|
|
1253
|
+
if (id === null) continue;
|
|
1254
|
+
getOrCreateCommentEntry(commentIdx, id).comment = c;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
const stylesIdx = buildStylesIndex(pkg);
|
|
1259
|
+
const tblIdx = buildTableIndex(pkg.parts.values());
|
|
1260
|
+
const drawingIdx = buildDrawingIndex(pkg.parts.values());
|
|
1261
|
+
return { paraIdx, bookmarkIdx, commentIdx, stylesIdx, tblIdx, drawingIdx };
|
|
1262
|
+
}
|
|
1263
|
+
__name(buildIndices, "buildIndices");
|
|
1264
|
+
function numAttr2(el, ns, local) {
|
|
1265
|
+
const v = el.getAttributeNS(ns, local);
|
|
1266
|
+
if (v === null) return null;
|
|
1267
|
+
const n = Number(v);
|
|
1268
|
+
return Number.isFinite(n) ? n : null;
|
|
1269
|
+
}
|
|
1270
|
+
__name(numAttr2, "numAttr");
|
|
1271
|
+
function getOrCreateCommentEntry(idx, id) {
|
|
1272
|
+
let e = idx.get(id);
|
|
1273
|
+
if (!e) {
|
|
1274
|
+
e = { comment: null, anchors: { start: null, end: null, ref: null } };
|
|
1275
|
+
idx.set(id, e);
|
|
1276
|
+
}
|
|
1277
|
+
return e;
|
|
1278
|
+
}
|
|
1279
|
+
__name(getOrCreateCommentEntry, "getOrCreateCommentEntry");
|
|
1280
|
+
|
|
1281
|
+
// src/word/list-paragraphs.ts
|
|
1282
|
+
var PREVIEW_CHAR_LIMIT = 100;
|
|
1283
|
+
function getStyleId(p) {
|
|
1284
|
+
const pPr = firstDirectChild2(p, W_NS, "pPr");
|
|
1285
|
+
if (!pPr) return void 0;
|
|
1286
|
+
const pStyle = firstDirectChild2(pPr, W_NS, "pStyle");
|
|
1287
|
+
if (!pStyle) return void 0;
|
|
1288
|
+
const val = pStyle.getAttributeNS(W_NS, "val");
|
|
1289
|
+
return val != null ? val : void 0;
|
|
1290
|
+
}
|
|
1291
|
+
__name(getStyleId, "getStyleId");
|
|
1292
|
+
function firstDirectChild2(el, ns, local) {
|
|
1293
|
+
const children = el.childNodes;
|
|
1294
|
+
for (let i = 0; i < children.length; i++) {
|
|
1295
|
+
const c = children[i];
|
|
1296
|
+
if (c && c.nodeType === 1 && c.namespaceURI === ns && c.localName === local) {
|
|
1297
|
+
return c;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return null;
|
|
1301
|
+
}
|
|
1302
|
+
__name(firstDirectChild2, "firstDirectChild");
|
|
1303
|
+
function getTableCellAncestors(p) {
|
|
1304
|
+
let tc = null;
|
|
1305
|
+
let tr = null;
|
|
1306
|
+
let el = p.parentElement;
|
|
1307
|
+
while (el) {
|
|
1308
|
+
if (el.namespaceURI === W_NS) {
|
|
1309
|
+
if (!tc) {
|
|
1310
|
+
if (el.localName === "tc") {
|
|
1311
|
+
tc = el;
|
|
1312
|
+
} else if (el.localName === "body" || el.localName === "hdr" || el.localName === "ftr" || el.localName === "footnote" || el.localName === "endnote" || el.localName === "comment") {
|
|
1313
|
+
return null;
|
|
1314
|
+
}
|
|
1315
|
+
} else if (!tr) {
|
|
1316
|
+
if (el.localName === "tr") {
|
|
1317
|
+
tr = el;
|
|
1318
|
+
}
|
|
1319
|
+
} else {
|
|
1320
|
+
if (el.localName === "tbl") {
|
|
1321
|
+
return { tc, tr, tbl: el };
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
el = el.parentElement;
|
|
1326
|
+
}
|
|
1327
|
+
return null;
|
|
1328
|
+
}
|
|
1329
|
+
__name(getTableCellAncestors, "getTableCellAncestors");
|
|
1330
|
+
function rowIndexOf(tr, tbl) {
|
|
1331
|
+
let idx = 0;
|
|
1332
|
+
const children = tbl.childNodes;
|
|
1333
|
+
for (let i = 0; i < children.length; i++) {
|
|
1334
|
+
const c = children[i];
|
|
1335
|
+
if (c.nodeType !== 1 || c.namespaceURI !== W_NS || c.localName !== "tr") continue;
|
|
1336
|
+
if (c === tr) return idx;
|
|
1337
|
+
idx++;
|
|
1338
|
+
}
|
|
1339
|
+
return -1;
|
|
1340
|
+
}
|
|
1341
|
+
__name(rowIndexOf, "rowIndexOf");
|
|
1342
|
+
function colIndexOf(tc, tr) {
|
|
1343
|
+
let idx = 0;
|
|
1344
|
+
const children = tr.childNodes;
|
|
1345
|
+
for (let i = 0; i < children.length; i++) {
|
|
1346
|
+
const c = children[i];
|
|
1347
|
+
if (c.nodeType !== 1 || c.namespaceURI !== W_NS || c.localName !== "tc") continue;
|
|
1348
|
+
if (c === tc) return idx;
|
|
1349
|
+
idx++;
|
|
1350
|
+
}
|
|
1351
|
+
return -1;
|
|
1352
|
+
}
|
|
1353
|
+
__name(colIndexOf, "colIndexOf");
|
|
1354
|
+
function detectHasRevisions(p) {
|
|
1355
|
+
return p.getElementsByTagNameNS(W_NS, "ins").length > 0 || p.getElementsByTagNameNS(W_NS, "del").length > 0;
|
|
1356
|
+
}
|
|
1357
|
+
__name(detectHasRevisions, "detectHasRevisions");
|
|
1358
|
+
function detectHasComments(p) {
|
|
1359
|
+
return p.getElementsByTagNameNS(W_NS, "commentRangeStart").length > 0 || p.getElementsByTagNameNS(W_NS, "commentRangeEnd").length > 0 || p.getElementsByTagNameNS(W_NS, "commentReference").length > 0;
|
|
1360
|
+
}
|
|
1361
|
+
__name(detectHasComments, "detectHasComments");
|
|
1362
|
+
function detectHasBookmarks(p) {
|
|
1363
|
+
return p.getElementsByTagNameNS(W_NS, "bookmarkStart").length > 0 || p.getElementsByTagNameNS(W_NS, "bookmarkEnd").length > 0;
|
|
1364
|
+
}
|
|
1365
|
+
__name(detectHasBookmarks, "detectHasBookmarks");
|
|
1366
|
+
function detectHasMath(p) {
|
|
1367
|
+
return p.getElementsByTagNameNS(MATH_NS, "oMath").length > 0;
|
|
1368
|
+
}
|
|
1369
|
+
__name(detectHasMath, "detectHasMath");
|
|
1370
|
+
function buildParagraphInfo(story, p, textFormat = "full", includeFormat = false, runTextOpts) {
|
|
1371
|
+
return buildInfo(story, p, textFormat, includeFormat, runTextOpts);
|
|
1372
|
+
}
|
|
1373
|
+
__name(buildParagraphInfo, "buildParagraphInfo");
|
|
1374
|
+
function buildInfo(story, p, textFormat, includeFormat, runTextOpts, tblReverseIdx) {
|
|
1375
|
+
var _a;
|
|
1376
|
+
const paraIdRaw = (_a = p.getAttributeNS(W14_NS, "paraId")) != null ? _a : "";
|
|
1377
|
+
const paraId = paraIdRaw.toUpperCase();
|
|
1378
|
+
const fullText = getParagraphText(p, runTextOpts);
|
|
1379
|
+
const truncated = textFormat === "preview" && fullText.length > PREVIEW_CHAR_LIMIT;
|
|
1380
|
+
const text = truncated ? fullText.slice(0, PREVIEW_CHAR_LIMIT) : fullText;
|
|
1381
|
+
const styleId = getStyleId(p);
|
|
1382
|
+
const hasRevisions = detectHasRevisions(p);
|
|
1383
|
+
const hasComments = detectHasComments(p);
|
|
1384
|
+
const hasBookmarks = detectHasBookmarks(p);
|
|
1385
|
+
const hasMath = detectHasMath(p);
|
|
1386
|
+
const info = { paraId, story, text };
|
|
1387
|
+
if (truncated) info.truncated = true;
|
|
1388
|
+
if (styleId !== void 0) info.styleId = styleId;
|
|
1389
|
+
if (hasRevisions) info.hasRevisions = true;
|
|
1390
|
+
if (hasComments) info.hasComments = true;
|
|
1391
|
+
if (hasBookmarks) info.hasBookmarks = true;
|
|
1392
|
+
if (hasMath) info.hasMath = true;
|
|
1393
|
+
if (includeFormat) {
|
|
1394
|
+
const pPr = firstDirectChild2(p, W_NS, "pPr");
|
|
1395
|
+
let fmt = pPr ? parseParagraphFormat(pPr) : void 0;
|
|
1396
|
+
if (detectManualPageBreak(p)) {
|
|
1397
|
+
fmt = __spreadProps(__spreadValues({}, fmt != null ? fmt : {}), { hasManualPageBreak: true });
|
|
1398
|
+
}
|
|
1399
|
+
const runColor = detectFirstRunColor(p);
|
|
1400
|
+
if (runColor !== void 0) {
|
|
1401
|
+
fmt = __spreadProps(__spreadValues({}, fmt != null ? fmt : {}), { firstRunColor: runColor });
|
|
1402
|
+
}
|
|
1403
|
+
if (fmt) info.format = fmt;
|
|
1404
|
+
}
|
|
1405
|
+
if (tblReverseIdx !== void 0) {
|
|
1406
|
+
const ancestors = getTableCellAncestors(p);
|
|
1407
|
+
if (ancestors !== null) {
|
|
1408
|
+
const { tc, tr, tbl } = ancestors;
|
|
1409
|
+
const tableId = tblReverseIdx.get(tbl);
|
|
1410
|
+
if (tableId !== void 0) {
|
|
1411
|
+
const row = rowIndexOf(tr, tbl);
|
|
1412
|
+
const col = colIndexOf(tc, tr);
|
|
1413
|
+
info.table = { tableId, row, col };
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
return info;
|
|
1418
|
+
}
|
|
1419
|
+
__name(buildInfo, "buildInfo");
|
|
1420
|
+
function parseParagraphFormat(pPr) {
|
|
1421
|
+
const fmt = {};
|
|
1422
|
+
let hasAny = false;
|
|
1423
|
+
const jc = firstDirectChild2(pPr, W_NS, "jc");
|
|
1424
|
+
if (jc) {
|
|
1425
|
+
const val = jc.getAttributeNS(W_NS, "val");
|
|
1426
|
+
if (val === "left" || val === "center" || val === "right" || val === "both" || val === "distribute") {
|
|
1427
|
+
fmt.alignment = val;
|
|
1428
|
+
hasAny = true;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const ind = firstDirectChild2(pPr, W_NS, "ind");
|
|
1432
|
+
if (ind) {
|
|
1433
|
+
const left = numAttrTwips(ind, "left");
|
|
1434
|
+
const right = numAttrTwips(ind, "right");
|
|
1435
|
+
const firstLineRaw = numAttrTwips(ind, "firstLine");
|
|
1436
|
+
const hangingRaw = numAttrTwips(ind, "hanging");
|
|
1437
|
+
const firstLine = firstLineRaw !== void 0 ? firstLineRaw : hangingRaw !== void 0 ? -hangingRaw : void 0;
|
|
1438
|
+
if (left !== void 0 || right !== void 0 || firstLine !== void 0) {
|
|
1439
|
+
fmt.indent = {};
|
|
1440
|
+
if (left !== void 0) fmt.indent.left = left;
|
|
1441
|
+
if (right !== void 0) fmt.indent.right = right;
|
|
1442
|
+
if (firstLine !== void 0) fmt.indent.firstLine = firstLine;
|
|
1443
|
+
hasAny = true;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
const spacing = firstDirectChild2(pPr, W_NS, "spacing");
|
|
1447
|
+
if (spacing) {
|
|
1448
|
+
const before = numAttrTwips(spacing, "before");
|
|
1449
|
+
const after = numAttrTwips(spacing, "after");
|
|
1450
|
+
const line = numAttrTwips(spacing, "line");
|
|
1451
|
+
const lineRuleRaw = spacing.getAttributeNS(W_NS, "lineRule");
|
|
1452
|
+
const lineRule = lineRuleRaw === "auto" || lineRuleRaw === "exact" || lineRuleRaw === "atLeast" ? lineRuleRaw : void 0;
|
|
1453
|
+
if (before !== void 0 || after !== void 0 || line !== void 0 || lineRule !== void 0) {
|
|
1454
|
+
fmt.spacing = {};
|
|
1455
|
+
if (before !== void 0) fmt.spacing.before = before;
|
|
1456
|
+
if (after !== void 0) fmt.spacing.after = after;
|
|
1457
|
+
if (line !== void 0) fmt.spacing.line = line;
|
|
1458
|
+
if (lineRule !== void 0) fmt.spacing.lineRule = lineRule;
|
|
1459
|
+
hasAny = true;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const pRpr = firstDirectChild2(pPr, W_NS, "rPr");
|
|
1463
|
+
if (pRpr) {
|
|
1464
|
+
const sz = firstDirectChild2(pRpr, W_NS, "sz");
|
|
1465
|
+
if (sz) {
|
|
1466
|
+
const szVal = numAttrTwips(sz, "val");
|
|
1467
|
+
if (szVal !== void 0) {
|
|
1468
|
+
fmt.fontSize = szVal / 2;
|
|
1469
|
+
hasAny = true;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
const b = firstDirectChild2(pRpr, W_NS, "b");
|
|
1473
|
+
if (b) {
|
|
1474
|
+
const bVal = b.getAttributeNS(W_NS, "val");
|
|
1475
|
+
fmt.bold = bVal !== "0" && bVal !== "false";
|
|
1476
|
+
hasAny = true;
|
|
1477
|
+
}
|
|
1478
|
+
const color = firstDirectChild2(pRpr, W_NS, "color");
|
|
1479
|
+
if (color) {
|
|
1480
|
+
const cVal = color.getAttributeNS(W_NS, "val");
|
|
1481
|
+
if (cVal) {
|
|
1482
|
+
fmt.color = cVal;
|
|
1483
|
+
hasAny = true;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
const outlineLvl = firstDirectChild2(pPr, W_NS, "outlineLvl");
|
|
1488
|
+
if (outlineLvl) {
|
|
1489
|
+
const val = numAttrTwips(outlineLvl, "val");
|
|
1490
|
+
if (val !== void 0 && val >= 0 && val <= 9) {
|
|
1491
|
+
fmt.outlineLevel = val;
|
|
1492
|
+
hasAny = true;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
const numPr = firstDirectChild2(pPr, W_NS, "numPr");
|
|
1496
|
+
if (numPr) {
|
|
1497
|
+
const numId = firstDirectChild2(numPr, W_NS, "numId");
|
|
1498
|
+
const numIdVal = numId == null ? void 0 : numId.getAttributeNS(W_NS, "val");
|
|
1499
|
+
if (numIdVal !== void 0 && numIdVal !== "0") {
|
|
1500
|
+
fmt.hasNumbering = true;
|
|
1501
|
+
hasAny = true;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
const pbb = firstDirectChild2(pPr, W_NS, "pageBreakBefore");
|
|
1505
|
+
if (pbb) {
|
|
1506
|
+
const v = pbb.getAttributeNS(W_NS, "val");
|
|
1507
|
+
fmt.pageBreakBefore = v !== "0" && v !== "false";
|
|
1508
|
+
hasAny = true;
|
|
1509
|
+
}
|
|
1510
|
+
if (firstDirectChild2(pPr, W_NS, "sectPr")) {
|
|
1511
|
+
fmt.hasSectionBreak = true;
|
|
1512
|
+
hasAny = true;
|
|
1513
|
+
}
|
|
1514
|
+
return hasAny ? fmt : void 0;
|
|
1515
|
+
}
|
|
1516
|
+
__name(parseParagraphFormat, "parseParagraphFormat");
|
|
1517
|
+
function detectManualPageBreak(p) {
|
|
1518
|
+
const runs = p.getElementsByTagNameNS(W_NS, "r");
|
|
1519
|
+
for (let i = 0; i < runs.length; i++) {
|
|
1520
|
+
const run = runs[i];
|
|
1521
|
+
if (!run || run.parentNode !== p) continue;
|
|
1522
|
+
const brs = run.getElementsByTagNameNS(W_NS, "br");
|
|
1523
|
+
for (let j = 0; j < brs.length; j++) {
|
|
1524
|
+
const br = brs[j];
|
|
1525
|
+
if (!br) continue;
|
|
1526
|
+
const type = br.getAttributeNS(W_NS, "type");
|
|
1527
|
+
if (type === "page") return true;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return false;
|
|
1531
|
+
}
|
|
1532
|
+
__name(detectManualPageBreak, "detectManualPageBreak");
|
|
1533
|
+
function detectFirstRunColor(p) {
|
|
1534
|
+
const runs = p.getElementsByTagNameNS(W_NS, "r");
|
|
1535
|
+
for (let i = 0; i < runs.length; i++) {
|
|
1536
|
+
const run = runs[i];
|
|
1537
|
+
if (!run || run.parentNode !== p) continue;
|
|
1538
|
+
const rPr = firstDirectChild2(run, W_NS, "rPr");
|
|
1539
|
+
if (!rPr) return void 0;
|
|
1540
|
+
const color = firstDirectChild2(rPr, W_NS, "color");
|
|
1541
|
+
if (!color) return void 0;
|
|
1542
|
+
const val = color.getAttributeNS(W_NS, "val");
|
|
1543
|
+
return val != null ? val : void 0;
|
|
1544
|
+
}
|
|
1545
|
+
return void 0;
|
|
1546
|
+
}
|
|
1547
|
+
__name(detectFirstRunColor, "detectFirstRunColor");
|
|
1548
|
+
function numAttrTwips(el, local) {
|
|
1549
|
+
const raw = el.getAttributeNS(W_NS, local);
|
|
1550
|
+
if (raw === null) return void 0;
|
|
1551
|
+
const n = parseInt(raw, 10);
|
|
1552
|
+
return Number.isFinite(n) ? n : void 0;
|
|
1553
|
+
}
|
|
1554
|
+
__name(numAttrTwips, "numAttrTwips");
|
|
1555
|
+
|
|
1556
|
+
// src/word/plan-executors/placeholder-image.ts
|
|
1557
|
+
import { parseXmlDocument } from "slimdom";
|
|
1558
|
+
function resolveRelTarget(relsPartPath, target) {
|
|
1559
|
+
let t = target.trim();
|
|
1560
|
+
if (t.startsWith("/")) return t.slice(1);
|
|
1561
|
+
while (t.startsWith("./")) t = t.slice(2);
|
|
1562
|
+
const base = hostDirOfRelsPart(relsPartPath);
|
|
1563
|
+
if (base === "") return t;
|
|
1564
|
+
let pathParts = base.split("/").filter(Boolean);
|
|
1565
|
+
while (t.startsWith("../")) {
|
|
1566
|
+
pathParts = pathParts.slice(0, -1);
|
|
1567
|
+
t = t.slice(3);
|
|
1568
|
+
}
|
|
1569
|
+
return pathParts.length === 0 ? t : `${pathParts.join("/")}/${t}`;
|
|
1570
|
+
}
|
|
1571
|
+
__name(resolveRelTarget, "resolveRelTarget");
|
|
1572
|
+
function hostDirOfRelsPart(relsPath) {
|
|
1573
|
+
const idx = relsPath.lastIndexOf("/_rels/");
|
|
1574
|
+
if (idx < 0) {
|
|
1575
|
+
return "";
|
|
1576
|
+
}
|
|
1577
|
+
return relsPath.slice(0, idx);
|
|
1578
|
+
}
|
|
1579
|
+
__name(hostDirOfRelsPart, "hostDirOfRelsPart");
|
|
1580
|
+
|
|
1581
|
+
// src/word/section-queries.ts
|
|
1582
|
+
function listSections(pkg) {
|
|
1583
|
+
var _a, _b;
|
|
1584
|
+
const stories = listStories(pkg, { kinds: ["body"] });
|
|
1585
|
+
if (stories.length === 0) return [];
|
|
1586
|
+
const body = stories[0].root;
|
|
1587
|
+
const partPath = stories[0].partPath;
|
|
1588
|
+
const relsPath = relsPathFor(partPath);
|
|
1589
|
+
const out = [];
|
|
1590
|
+
let sectionFirstParaId;
|
|
1591
|
+
let lastParaIdInBody;
|
|
1592
|
+
let sectionIndex = 0;
|
|
1593
|
+
for (let i = 0; i < body.childNodes.length; i++) {
|
|
1594
|
+
const node = body.childNodes[i];
|
|
1595
|
+
if (!node || node.nodeType !== 1) continue;
|
|
1596
|
+
const el = node;
|
|
1597
|
+
if (el.namespaceURI !== W_NS) continue;
|
|
1598
|
+
if (el.localName === "p") {
|
|
1599
|
+
const paraId = (_b = (_a = el.getAttributeNS(W14_NS, "paraId")) == null ? void 0 : _a.toUpperCase()) != null ? _b : "";
|
|
1600
|
+
if (paraId.length === 0) continue;
|
|
1601
|
+
if (sectionFirstParaId === void 0) sectionFirstParaId = paraId;
|
|
1602
|
+
lastParaIdInBody = paraId;
|
|
1603
|
+
const pPr = firstDirectChild3(el, W_NS, "pPr");
|
|
1604
|
+
const inlineSectPr = pPr ? firstDirectChild3(pPr, W_NS, "sectPr") : null;
|
|
1605
|
+
if (inlineSectPr) {
|
|
1606
|
+
out.push(
|
|
1607
|
+
buildSection(sectionIndex++, sectionFirstParaId, paraId, inlineSectPr, pkg, relsPath)
|
|
1608
|
+
);
|
|
1609
|
+
sectionFirstParaId = void 0;
|
|
1610
|
+
}
|
|
1611
|
+
} else if (el.localName === "sectPr") {
|
|
1612
|
+
if (sectionFirstParaId !== void 0 && lastParaIdInBody !== void 0) {
|
|
1613
|
+
out.push(
|
|
1614
|
+
buildSection(sectionIndex++, sectionFirstParaId, lastParaIdInBody, el, pkg, relsPath)
|
|
1615
|
+
);
|
|
1616
|
+
sectionFirstParaId = void 0;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
return out;
|
|
1621
|
+
}
|
|
1622
|
+
__name(listSections, "listSections");
|
|
1623
|
+
function buildSection(sectionIndex, firstParaId, lastParaId, sectPr, pkg, relsPath) {
|
|
1624
|
+
const info = { sectionIndex, firstParaId, lastParaId };
|
|
1625
|
+
const typeEl = firstDirectChild3(sectPr, W_NS, "type");
|
|
1626
|
+
if (typeEl) {
|
|
1627
|
+
const v = typeEl.getAttributeNS(W_NS, "val");
|
|
1628
|
+
if (v === "nextPage" || v === "continuous" || v === "evenPage" || v === "oddPage" || v === "nextColumn") {
|
|
1629
|
+
info.type = v;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
const headerRefs = collectRefs(sectPr, "headerReference", pkg, relsPath);
|
|
1633
|
+
if (headerRefs.length > 0) info.headerRefs = headerRefs;
|
|
1634
|
+
const footerRefs = collectRefs(sectPr, "footerReference", pkg, relsPath);
|
|
1635
|
+
if (footerRefs.length > 0) info.footerRefs = footerRefs;
|
|
1636
|
+
if (firstDirectChild3(sectPr, W_NS, "titlePg")) info.titlePage = true;
|
|
1637
|
+
return info;
|
|
1638
|
+
}
|
|
1639
|
+
__name(buildSection, "buildSection");
|
|
1640
|
+
function collectRefs(sectPr, localName, pkg, relsPath) {
|
|
1641
|
+
const refs = [];
|
|
1642
|
+
if (!relsPath) return refs;
|
|
1643
|
+
const relMap = loadRels(pkg, relsPath);
|
|
1644
|
+
if (!relMap) return refs;
|
|
1645
|
+
const nodes = sectPr.getElementsByTagNameNS(W_NS, localName);
|
|
1646
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1647
|
+
const el = nodes[i];
|
|
1648
|
+
if (!el || el.parentNode !== sectPr) continue;
|
|
1649
|
+
const typeAttr = el.getAttributeNS(W_NS, "type");
|
|
1650
|
+
const rId = el.getAttributeNS(R_NS, "id");
|
|
1651
|
+
if (!rId) continue;
|
|
1652
|
+
const target = relMap.get(rId);
|
|
1653
|
+
if (!target) continue;
|
|
1654
|
+
const partName = resolveRelTarget(relsPath, target);
|
|
1655
|
+
const type = typeAttr === "first" || typeAttr === "even" ? typeAttr : "default";
|
|
1656
|
+
refs.push({ type, partName });
|
|
1657
|
+
}
|
|
1658
|
+
return refs;
|
|
1659
|
+
}
|
|
1660
|
+
__name(collectRefs, "collectRefs");
|
|
1661
|
+
var RELS_NS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
1662
|
+
function loadRels(pkg, relsPath) {
|
|
1663
|
+
for (const part of listParts(pkg)) {
|
|
1664
|
+
if (part.path !== relsPath) continue;
|
|
1665
|
+
if (!part.xmlDom) return null;
|
|
1666
|
+
const map = /* @__PURE__ */ new Map();
|
|
1667
|
+
const nodes = part.xmlDom.getElementsByTagNameNS(RELS_NS, "Relationship");
|
|
1668
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1669
|
+
const el = nodes[i];
|
|
1670
|
+
if (!el) continue;
|
|
1671
|
+
const id = el.getAttribute("Id");
|
|
1672
|
+
const target = el.getAttribute("Target");
|
|
1673
|
+
if (id && target) map.set(id, target);
|
|
1674
|
+
}
|
|
1675
|
+
return map;
|
|
1676
|
+
}
|
|
1677
|
+
return null;
|
|
1678
|
+
}
|
|
1679
|
+
__name(loadRels, "loadRels");
|
|
1680
|
+
function relsPathFor(partPath) {
|
|
1681
|
+
const lastSlash = partPath.lastIndexOf("/");
|
|
1682
|
+
const dir = lastSlash >= 0 ? partPath.slice(0, lastSlash) : "";
|
|
1683
|
+
const file = partPath.slice(lastSlash + 1);
|
|
1684
|
+
return dir.length > 0 ? `${dir}/_rels/${file}.rels` : `_rels/${file}.rels`;
|
|
1685
|
+
}
|
|
1686
|
+
__name(relsPathFor, "relsPathFor");
|
|
1687
|
+
function firstDirectChild3(el, ns, local) {
|
|
1688
|
+
for (let i = 0; i < el.childNodes.length; i++) {
|
|
1689
|
+
const c = el.childNodes[i];
|
|
1690
|
+
if (!c || c.nodeType !== 1) continue;
|
|
1691
|
+
const ce = c;
|
|
1692
|
+
if (ce.namespaceURI === ns && ce.localName === local) return ce;
|
|
1693
|
+
}
|
|
1694
|
+
return null;
|
|
1695
|
+
}
|
|
1696
|
+
__name(firstDirectChild3, "firstDirectChild");
|
|
1697
|
+
|
|
1698
|
+
// src/word/plan-executors/insert-image-ops.ts
|
|
1699
|
+
import { parseXmlDocument as parseXmlDocument2 } from "slimdom";
|
|
1700
|
+
var RELS_NS2 = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
1701
|
+
function relsPathFor2(partPath) {
|
|
1702
|
+
const idx = partPath.lastIndexOf("/");
|
|
1703
|
+
if (idx < 0) return `_rels/${partPath}.rels`;
|
|
1704
|
+
const dir = partPath.slice(0, idx);
|
|
1705
|
+
const name = partPath.slice(idx + 1);
|
|
1706
|
+
return `${dir}/_rels/${name}.rels`;
|
|
1707
|
+
}
|
|
1708
|
+
__name(relsPathFor2, "relsPathFor");
|
|
1709
|
+
function getImageBytesSync(pkg, indices, drawingId) {
|
|
1710
|
+
var _a;
|
|
1711
|
+
const dr = indices.drawingIdx.get(drawingId);
|
|
1712
|
+
if (!dr) return null;
|
|
1713
|
+
const blips = dr.getElementsByTagNameNS(A_NS, "blip");
|
|
1714
|
+
if (blips.length === 0) return null;
|
|
1715
|
+
const blip = blips[0];
|
|
1716
|
+
const rId = blip.getAttributeNS(R_NS, "embed");
|
|
1717
|
+
if (!rId) return null;
|
|
1718
|
+
const story = findStoryFor(pkg, dr);
|
|
1719
|
+
if (!story) return null;
|
|
1720
|
+
const hostPartPath = story.partPath;
|
|
1721
|
+
const relsPath = relsPathFor2(hostPartPath);
|
|
1722
|
+
const relsPart = getPart(pkg, relsPath);
|
|
1723
|
+
if (!relsPart || !isXmlPart(relsPart) || !relsPart.xmlDom) return null;
|
|
1724
|
+
const rels = relsPart.xmlDom.getElementsByTagNameNS(RELS_NS2, "Relationship");
|
|
1725
|
+
let mediaPath = null;
|
|
1726
|
+
for (let i = 0; i < rels.length; i++) {
|
|
1727
|
+
const r = rels[i];
|
|
1728
|
+
if (r.getAttribute("Id") === rId) {
|
|
1729
|
+
const target = (_a = r.getAttribute("Target")) != null ? _a : "";
|
|
1730
|
+
mediaPath = resolveTarget(relsPath, target);
|
|
1731
|
+
break;
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
if (!mediaPath) return null;
|
|
1735
|
+
const mediaPart = getPart(pkg, mediaPath);
|
|
1736
|
+
if (!mediaPart) return null;
|
|
1737
|
+
const bytes = mediaPart.bytes;
|
|
1738
|
+
if (!bytes) return null;
|
|
1739
|
+
const contentType = mediaPart.contentType;
|
|
1740
|
+
const extentEMU = readDrawingExtent(dr);
|
|
1741
|
+
return { bytes, contentType, extentEMU };
|
|
1742
|
+
}
|
|
1743
|
+
__name(getImageBytesSync, "getImageBytesSync");
|
|
1744
|
+
function readDrawingExtent(drawing) {
|
|
1745
|
+
var _a, _b;
|
|
1746
|
+
for (let i = 0; i < drawing.childNodes.length; i++) {
|
|
1747
|
+
const c = drawing.childNodes[i];
|
|
1748
|
+
if (!c || c.nodeType !== 1) continue;
|
|
1749
|
+
if (c.namespaceURI !== WP_NS) continue;
|
|
1750
|
+
if (c.localName !== "inline" && c.localName !== "anchor") continue;
|
|
1751
|
+
for (let j = 0; j < c.childNodes.length; j++) {
|
|
1752
|
+
const ext = c.childNodes[j];
|
|
1753
|
+
if (!ext || ext.nodeType !== 1) continue;
|
|
1754
|
+
if (ext.namespaceURI === WP_NS && ext.localName === "extent") {
|
|
1755
|
+
const cx = parseInt((_a = ext.getAttribute("cx")) != null ? _a : "0", 10);
|
|
1756
|
+
const cy = parseInt((_b = ext.getAttribute("cy")) != null ? _b : "0", 10);
|
|
1757
|
+
return { cx: isNaN(cx) ? 0 : cx, cy: isNaN(cy) ? 0 : cy };
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
return { cx: 0, cy: 0 };
|
|
1762
|
+
}
|
|
1763
|
+
__name(readDrawingExtent, "readDrawingExtent");
|
|
1764
|
+
function resolveTarget(relsPartPath, target) {
|
|
1765
|
+
let t = target.trim();
|
|
1766
|
+
if (t.startsWith("/")) return t.slice(1);
|
|
1767
|
+
while (t.startsWith("./")) t = t.slice(2);
|
|
1768
|
+
const idx = relsPartPath.lastIndexOf("/_rels/");
|
|
1769
|
+
if (idx < 0) return t;
|
|
1770
|
+
const hostDir = relsPartPath.slice(0, idx);
|
|
1771
|
+
let parts = hostDir.split("/").filter(Boolean);
|
|
1772
|
+
while (t.startsWith("../")) {
|
|
1773
|
+
parts = parts.slice(0, -1);
|
|
1774
|
+
t = t.slice(3);
|
|
1775
|
+
}
|
|
1776
|
+
return parts.length === 0 ? t : `${parts.join("/")}/${t}`;
|
|
1777
|
+
}
|
|
1778
|
+
__name(resolveTarget, "resolveTarget");
|
|
1779
|
+
export {
|
|
1780
|
+
W14_NS,
|
|
1781
|
+
W_NS,
|
|
1782
|
+
buildIndices,
|
|
1783
|
+
buildParagraphInfo,
|
|
1784
|
+
getImageBytesSync,
|
|
1785
|
+
getStoryParagraphs,
|
|
1786
|
+
listDrawings,
|
|
1787
|
+
listSections,
|
|
1788
|
+
listStories,
|
|
1789
|
+
listTables
|
|
1790
|
+
};
|
|
1791
|
+
//# sourceMappingURL=word-view.js.map
|