ooxml.js 4.0.12 → 4.1.0
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 +3 -2
- package/dist/{codec-CZkWeDXF.d.cts → codec-DO0MNF45.d.cts} +1 -1
- package/dist/{codec-BOGj_yQL.d.ts → codec-DxnbKt4O.d.ts} +1 -1
- package/dist/codec.d.cts +1 -1
- package/dist/codec.d.ts +1 -1
- package/dist/index.cjs +8 -9
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/package-io/read.cjs +4 -1
- package/dist/package-io/read.d.cts +2 -2
- package/dist/package-io/read.d.ts +2 -2
- package/dist/package-io/read.js +4 -2
- package/dist/{read-CMDEXqGw.d.ts → read-CevviAf2.d.ts} +2 -1
- package/dist/read-DPAy4uu8.cjs +1188 -0
- package/dist/read-Legu2Pt-.js +1141 -0
- package/dist/{read-DzmMJPHd.d.cts → read-VbRhmjOh.d.cts} +2 -1
- package/dist/typed/document-package.cjs +4 -5
- package/dist/typed/document-package.js +2 -3
- package/dist/typed/docx/read.cjs +5 -645
- package/dist/typed/docx/read.js +1 -641
- package/dist/typed/embedded.cjs +4 -0
- package/dist/typed/embedded.d.cts +12 -0
- package/dist/typed/embedded.d.ts +12 -0
- package/dist/typed/embedded.js +2 -0
- package/dist/typed/pptx/read.cjs +3 -390
- package/dist/typed/pptx/read.js +1 -388
- package/dist/typed/xlsx/content.cjs +1 -1
- package/dist/typed/xlsx/content.js +1 -1
- package/package.json +2 -1
package/dist/typed/docx/read.cjs
CHANGED
|
@@ -1,646 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const require_typed_shared_drawingml = require("../shared/drawingml.cjs");
|
|
8
|
-
const require_typed_shared_source_path = require("../shared/source-path.cjs");
|
|
9
|
-
const require_typed_docx_styles = require("./styles.cjs");
|
|
10
|
-
const require_typed_docx_numbering = require("./numbering.cjs");
|
|
11
|
-
const require_typed_docx_constructs = require("./constructs.cjs");
|
|
12
|
-
let zod = require("zod");
|
|
13
|
-
let document_schema_js = require("document-schema.js");
|
|
14
|
-
//#region src/typed/docx/read.ts
|
|
15
|
-
const CommentSchema = zod.z.object({
|
|
16
|
-
author: zod.z.string().optional(),
|
|
17
|
-
text: zod.z.string()
|
|
18
|
-
});
|
|
19
|
-
const FootnoteSchema = zod.z.object({
|
|
20
|
-
type: zod.z.string().optional(),
|
|
21
|
-
text: zod.z.string()
|
|
22
|
-
});
|
|
23
|
-
const DocxDocumentSchema = zod.z.object({
|
|
24
|
-
metadata: require_typed_shared_metadata.DocumentMetadataSchema,
|
|
25
|
-
sections: zod.z.array(document_schema_js.ContentSectionSchema),
|
|
26
|
-
comments: zod.z.array(CommentSchema),
|
|
27
|
-
footnotes: zod.z.array(FootnoteSchema),
|
|
28
|
-
headers: zod.z.array(zod.z.string()),
|
|
29
|
-
footers: zod.z.array(zod.z.string()),
|
|
30
|
-
numbering: zod.z.record(zod.z.string(), require_typed_docx_numbering.NumberingDefinitionSchema)
|
|
31
|
-
});
|
|
32
|
-
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
33
|
-
const STYLES_PART_PATH = "word/styles.xml";
|
|
34
|
-
const THEME_REL_SUFFIX = "/theme";
|
|
35
|
-
const DEFAULT_MARGIN_PT = 72;
|
|
36
|
-
const DEFAULT_MARGINS = {
|
|
37
|
-
topPt: DEFAULT_MARGIN_PT,
|
|
38
|
-
rightPt: DEFAULT_MARGIN_PT,
|
|
39
|
-
bottomPt: DEFAULT_MARGIN_PT,
|
|
40
|
-
leftPt: DEFAULT_MARGIN_PT
|
|
41
|
-
};
|
|
42
|
-
function readPageSize(sectPr) {
|
|
43
|
-
const pgSz = require_typed_util.childrenWithTag(sectPr, "w:pgSz")[0];
|
|
44
|
-
const w = pgSz === void 0 ? void 0 : require_typed_util.attr(pgSz, "w:w");
|
|
45
|
-
const h = pgSz === void 0 ? void 0 : require_typed_util.attr(pgSz, "w:h");
|
|
46
|
-
return w === void 0 || h === void 0 ? document_schema_js.PAGE_SIZE_LETTER : {
|
|
47
|
-
widthPt: require_typed_shared_units.twipsToPt(Number(w)),
|
|
48
|
-
heightPt: require_typed_shared_units.twipsToPt(Number(h))
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function readMargins(sectPr) {
|
|
52
|
-
const pgMar = require_typed_util.childrenWithTag(sectPr, "w:pgMar")[0];
|
|
53
|
-
if (pgMar === void 0) return DEFAULT_MARGINS;
|
|
54
|
-
const top = require_typed_util.attr(pgMar, "w:top");
|
|
55
|
-
const right = require_typed_util.attr(pgMar, "w:right");
|
|
56
|
-
const bottom = require_typed_util.attr(pgMar, "w:bottom");
|
|
57
|
-
const left = require_typed_util.attr(pgMar, "w:left");
|
|
58
|
-
return {
|
|
59
|
-
topPt: top === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(top)),
|
|
60
|
-
rightPt: right === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(right)),
|
|
61
|
-
bottomPt: bottom === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(bottom)),
|
|
62
|
-
leftPt: left === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(left))
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function readListMembership(pPr) {
|
|
66
|
-
const numPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:numPr")[0];
|
|
67
|
-
if (numPr === void 0) return;
|
|
68
|
-
const numIdEl = require_typed_util.childrenWithTag(numPr, "w:numId")[0];
|
|
69
|
-
const numId = numIdEl === void 0 ? void 0 : require_typed_util.attr(numIdEl, "w:val");
|
|
70
|
-
if (numId === void 0) return;
|
|
71
|
-
const ilvlEl = require_typed_util.childrenWithTag(numPr, "w:ilvl")[0];
|
|
72
|
-
const ilvlVal = ilvlEl === void 0 ? void 0 : require_typed_util.attr(ilvlEl, "w:val");
|
|
73
|
-
return {
|
|
74
|
-
numId,
|
|
75
|
-
level: ilvlVal === void 0 ? 0 : Number(ilvlVal)
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function readToggle(el) {
|
|
79
|
-
if (el === void 0) return false;
|
|
80
|
-
const val = require_typed_util.attr(el, "w:val");
|
|
81
|
-
return val === void 0 || val !== "0" && val !== "false" && val !== "off";
|
|
82
|
-
}
|
|
83
|
-
function hasPageBreakBefore(paragraph) {
|
|
84
|
-
const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
|
|
85
|
-
return readToggle(pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:pageBreakBefore")[0]);
|
|
86
|
-
}
|
|
87
|
-
function readRunText(run) {
|
|
88
|
-
let text = "";
|
|
89
|
-
for (const child of run.children) {
|
|
90
|
-
if (child.type !== "element") continue;
|
|
91
|
-
if (child.tag === "w:t" || child.tag === "w:delText") text += require_typed_util.textContent(child);
|
|
92
|
-
else if (child.tag === "w:tab") text += " ";
|
|
93
|
-
else if (child.tag === "w:br" || child.tag === "w:cr") text += "\n";
|
|
94
|
-
}
|
|
95
|
-
return text;
|
|
96
|
-
}
|
|
97
|
-
function readDrawingImage(drawing, ctx) {
|
|
98
|
-
const container = require_typed_util.childrenWithTag(drawing, "wp:inline")[0] ?? require_typed_util.childrenWithTag(drawing, "wp:anchor")[0];
|
|
99
|
-
if (container === void 0) return;
|
|
100
|
-
const extent = require_typed_util.childrenWithTag(container, "wp:extent")[0];
|
|
101
|
-
const cx = extent === void 0 ? void 0 : require_typed_util.attr(extent, "cx");
|
|
102
|
-
const cy = extent === void 0 ? void 0 : require_typed_util.attr(extent, "cy");
|
|
103
|
-
if (cx === void 0 || cy === void 0) return;
|
|
104
|
-
const docPr = require_typed_util.childrenWithTag(container, "wp:docPr")[0];
|
|
105
|
-
const altText = docPr === void 0 ? void 0 : require_typed_util.attr(docPr, "descr") ?? require_typed_util.attr(docPr, "title");
|
|
106
|
-
const blip = require_typed_util.elementsWithTag(container.children, "a:blip")[0];
|
|
107
|
-
const rId = blip === void 0 ? void 0 : require_typed_util.attr(blip, "r:embed");
|
|
108
|
-
const rel = rId === void 0 ? void 0 : ctx.rels.get(rId);
|
|
109
|
-
const mediaPart = rel === void 0 ? void 0 : ctx.pkg.parts[rel.target];
|
|
110
|
-
if (mediaPart?.kind !== "binary") return;
|
|
111
|
-
const bytes = require_util_base64.base64ToBytes(mediaPart.base64);
|
|
112
|
-
const format = require_image_sniff.sniffImageFormat(bytes);
|
|
113
|
-
if (format === void 0) return;
|
|
114
|
-
const image = {
|
|
115
|
-
kind: "image",
|
|
116
|
-
format,
|
|
117
|
-
base64: mediaPart.base64,
|
|
118
|
-
widthPt: require_typed_shared_units.emuToPt(Number(cx)),
|
|
119
|
-
heightPt: require_typed_shared_units.emuToPt(Number(cy))
|
|
120
|
-
};
|
|
121
|
-
if (altText !== void 0) image.altText = require_typed_util.decodeEntities(altText);
|
|
122
|
-
return image;
|
|
123
|
-
}
|
|
124
|
-
function collectDrawings(nodes, carryDeletions, out) {
|
|
125
|
-
for (const node of nodes) {
|
|
126
|
-
if (node.type !== "element") continue;
|
|
127
|
-
if (!carryDeletions && (node.tag === "w:del" || node.tag === "w:moveFrom")) continue;
|
|
128
|
-
if (node.tag === "w:drawing") {
|
|
129
|
-
out.push(node);
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
collectDrawings(node.children, carryDeletions, out);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
function readParagraphImages(paragraph, ctx, carryDeletions) {
|
|
136
|
-
const drawings = [];
|
|
137
|
-
collectDrawings(paragraph.children, carryDeletions, drawings);
|
|
138
|
-
const images = [];
|
|
139
|
-
for (const drawing of drawings) {
|
|
140
|
-
const image = readDrawingImage(drawing, ctx);
|
|
141
|
-
if (image !== void 0) images.push(image);
|
|
142
|
-
}
|
|
143
|
-
return images;
|
|
144
|
-
}
|
|
145
|
-
function readRun(run, paragraph, context) {
|
|
146
|
-
const props = require_typed_docx_styles.resolveRunProperties(run, paragraph, context);
|
|
147
|
-
return {
|
|
148
|
-
text: readRunText(run),
|
|
149
|
-
bold: props.bold,
|
|
150
|
-
italic: props.italic,
|
|
151
|
-
underline: props.underline,
|
|
152
|
-
strike: props.strike,
|
|
153
|
-
fontFamily: props.fontFamily,
|
|
154
|
-
sizePt: props.sizePt,
|
|
155
|
-
color: props.color
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
function readParagraphRuns(paragraph, ctx, carryDeletions) {
|
|
159
|
-
const runs = [];
|
|
160
|
-
let fieldState = "none";
|
|
161
|
-
function walk(nodes, hyperlinkTarget) {
|
|
162
|
-
for (const node of nodes) {
|
|
163
|
-
if (node.type !== "element") continue;
|
|
164
|
-
if (node.tag === "w:r") {
|
|
165
|
-
const type = require_typed_docx_constructs.fieldCharType(node);
|
|
166
|
-
if (type !== void 0) {
|
|
167
|
-
if (type === "begin") fieldState = "code";
|
|
168
|
-
else if (type === "separate") fieldState = "result";
|
|
169
|
-
else if (type === "end") fieldState = "none";
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
if (fieldState === "code") continue;
|
|
173
|
-
const run = readRun(node, paragraph, ctx.styles);
|
|
174
|
-
runs.push(hyperlinkTarget === void 0 ? run : {
|
|
175
|
-
...run,
|
|
176
|
-
hyperlink: hyperlinkTarget
|
|
177
|
-
});
|
|
178
|
-
} else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
|
|
179
|
-
else if (node.tag === "w:hyperlink") {
|
|
180
|
-
const rId = require_typed_util.attr(node, "r:id");
|
|
181
|
-
const target = rId === void 0 ? void 0 : ctx.rels.get(rId)?.target;
|
|
182
|
-
walk(node.children, target ?? hyperlinkTarget);
|
|
183
|
-
} else if (node.tag === "w:ins" || node.tag === "w:moveTo") walk(node.children, hyperlinkTarget);
|
|
184
|
-
else if (node.tag === "w:del" || node.tag === "w:moveFrom") {
|
|
185
|
-
if (carryDeletions) walk(node.children, hyperlinkTarget);
|
|
186
|
-
} else if (node.tag === "w:sdt") {
|
|
187
|
-
const sdtContent = require_typed_util.childrenWithTag(node, "w:sdtContent")[0];
|
|
188
|
-
if (sdtContent !== void 0) walk(sdtContent.children, hyperlinkTarget);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
walk(paragraph.children, void 0);
|
|
193
|
-
return runs;
|
|
194
|
-
}
|
|
195
|
-
function readParagraph(paragraph, ctx, carryDeletions) {
|
|
196
|
-
const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
|
|
197
|
-
const pStyleEl = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:pStyle")[0];
|
|
198
|
-
const props = require_typed_docx_styles.resolveParagraphProperties(paragraph, ctx.styles);
|
|
199
|
-
return {
|
|
200
|
-
kind: "paragraph",
|
|
201
|
-
runs: readParagraphRuns(paragraph, ctx, carryDeletions),
|
|
202
|
-
styleId: pStyleEl === void 0 ? void 0 : require_typed_util.attr(pStyleEl, "w:val"),
|
|
203
|
-
headingLevel: props.outlineLvl === void 0 ? void 0 : (0, document_schema_js.clampHeadingLevel)(props.outlineLvl + 1),
|
|
204
|
-
alignment: props.alignment,
|
|
205
|
-
list: readListMembership(pPr),
|
|
206
|
-
spacingBeforePt: props.spacingBeforePt,
|
|
207
|
-
spacingAfterPt: props.spacingAfterPt,
|
|
208
|
-
lineSpacing: props.lineSpacing,
|
|
209
|
-
indentLeftPt: props.indentLeftPt,
|
|
210
|
-
indentFirstLinePt: props.indentFirstLinePt
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
function readCellShading(tcPr) {
|
|
214
|
-
const shd = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:shd")[0];
|
|
215
|
-
const fill = shd === void 0 ? void 0 : require_typed_util.attr(shd, "w:fill");
|
|
216
|
-
return fill === void 0 || fill === "auto" || fill === "none" ? void 0 : (0, document_schema_js.rgbHexToColor)(fill);
|
|
217
|
-
}
|
|
218
|
-
const BORDER_STYLE_MAP = /* @__PURE__ */ new Map([
|
|
219
|
-
["single", "solid"],
|
|
220
|
-
["thick", "solid"],
|
|
221
|
-
["triple", "solid"],
|
|
222
|
-
["outset", "solid"],
|
|
223
|
-
["inset", "solid"],
|
|
224
|
-
["threeDEmboss", "solid"],
|
|
225
|
-
["threeDEngrave", "solid"],
|
|
226
|
-
["dashed", "dashed"],
|
|
227
|
-
["dashSmallGap", "dashed"],
|
|
228
|
-
["dashDotStroked", "dashed"],
|
|
229
|
-
["dotDash", "dashed"],
|
|
230
|
-
["dotted", "dotted"],
|
|
231
|
-
["dotDotDash", "dotted"],
|
|
232
|
-
["double", "double"],
|
|
233
|
-
["doubleWave", "double"]
|
|
234
|
-
]);
|
|
235
|
-
const DEFAULT_BORDER_WIDTH_EIGHTH_POINTS = 4;
|
|
236
|
-
function readCellBorderEdge(tcBorders, tag) {
|
|
237
|
-
const edge = tcBorders === void 0 ? void 0 : require_typed_util.childrenWithTag(tcBorders, tag)[0];
|
|
238
|
-
const val = edge === void 0 ? void 0 : require_typed_util.attr(edge, "w:val");
|
|
239
|
-
if (edge === void 0 || val === void 0 || val === "nil" || val === "none") return;
|
|
240
|
-
const sz = require_typed_util.attr(edge, "w:sz");
|
|
241
|
-
const colorVal = require_typed_util.attr(edge, "w:color");
|
|
242
|
-
return {
|
|
243
|
-
color: colorVal === void 0 || colorVal === "auto" ? document_schema_js.COLOR_BLACK : (0, document_schema_js.rgbHexToColor)(colorVal),
|
|
244
|
-
widthPt: require_typed_shared_units.eighthPointsToPt(sz === void 0 ? DEFAULT_BORDER_WIDTH_EIGHTH_POINTS : Number(sz)),
|
|
245
|
-
style: BORDER_STYLE_MAP.get(val) ?? "solid"
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
function readCellBorders(tcPr) {
|
|
249
|
-
const tcBorders = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:tcBorders")[0];
|
|
250
|
-
if (tcBorders === void 0) return;
|
|
251
|
-
const borders = {};
|
|
252
|
-
const left = readCellBorderEdge(tcBorders, "w:left") ?? readCellBorderEdge(tcBorders, "w:start");
|
|
253
|
-
const right = readCellBorderEdge(tcBorders, "w:right") ?? readCellBorderEdge(tcBorders, "w:end");
|
|
254
|
-
const top = readCellBorderEdge(tcBorders, "w:top");
|
|
255
|
-
const bottom = readCellBorderEdge(tcBorders, "w:bottom");
|
|
256
|
-
if (left !== void 0) borders.left = left;
|
|
257
|
-
if (right !== void 0) borders.right = right;
|
|
258
|
-
if (top !== void 0) borders.top = top;
|
|
259
|
-
if (bottom !== void 0) borders.bottom = bottom;
|
|
260
|
-
return Object.keys(borders).length === 0 ? void 0 : borders;
|
|
261
|
-
}
|
|
262
|
-
function readRawCell(tc, ctx, carryDeletions) {
|
|
263
|
-
const tcPr = require_typed_util.childrenWithTag(tc, "w:tcPr")[0];
|
|
264
|
-
const gridSpanEl = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:gridSpan")[0];
|
|
265
|
-
const gridSpanVal = gridSpanEl === void 0 ? void 0 : require_typed_util.attr(gridSpanEl, "w:val");
|
|
266
|
-
const vMerge = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:vMerge")[0];
|
|
267
|
-
const vMergeVal = vMerge === void 0 ? void 0 : require_typed_util.attr(vMerge, "w:val") ?? "continue";
|
|
268
|
-
return {
|
|
269
|
-
gridSpan: gridSpanVal === void 0 ? 1 : Number(gridSpanVal),
|
|
270
|
-
isVMergeContinuation: vMergeVal === "continue",
|
|
271
|
-
background: readCellShading(tcPr),
|
|
272
|
-
borders: readCellBorders(tcPr),
|
|
273
|
-
blocks: readBlockScope(tc.children, ctx, carryDeletions)
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function readRowHeightPt(tr) {
|
|
277
|
-
const trPr = require_typed_util.childrenWithTag(tr, "w:trPr")[0];
|
|
278
|
-
if (trPr === void 0) return;
|
|
279
|
-
const trHeight = require_typed_util.childrenWithTag(trPr, "w:trHeight")[0];
|
|
280
|
-
const val = trHeight === void 0 ? void 0 : require_typed_util.attr(trHeight, "w:val");
|
|
281
|
-
return val === void 0 ? void 0 : require_typed_shared_units.twipsToPt(Number(val));
|
|
282
|
-
}
|
|
283
|
-
function readTable(tbl, ctx, carryDeletions) {
|
|
284
|
-
const tblGrid = require_typed_util.childrenWithTag(tbl, "w:tblGrid")[0];
|
|
285
|
-
const columnWidthsPt = tblGrid === void 0 ? [] : require_typed_util.childrenWithTag(tblGrid, "w:gridCol").map((col) => require_typed_shared_units.twipsToPt(Number(require_typed_util.attr(col, "w:w") ?? "0")));
|
|
286
|
-
const trs = require_typed_util.childrenWithTag(tbl, "w:tr");
|
|
287
|
-
const rawRows = trs.map((tr) => require_typed_util.childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, ctx, carryDeletions)));
|
|
288
|
-
const rowColumnIndices = rawRows.map((row) => {
|
|
289
|
-
const indices = [];
|
|
290
|
-
let col = 0;
|
|
291
|
-
for (const cell of row) {
|
|
292
|
-
indices.push(col);
|
|
293
|
-
col += cell.gridSpan;
|
|
294
|
-
}
|
|
295
|
-
return indices;
|
|
296
|
-
});
|
|
297
|
-
return {
|
|
298
|
-
kind: "table",
|
|
299
|
-
columnWidthsPt,
|
|
300
|
-
rows: rawRows.map((row, rowIndex) => ({
|
|
301
|
-
heightPt: readRowHeightPt(trs[rowIndex]),
|
|
302
|
-
cells: row.map((cell, cellIndex) => {
|
|
303
|
-
if (cell.isVMergeContinuation) return { blocks: [] };
|
|
304
|
-
const colIndex = rowColumnIndices[rowIndex][cellIndex];
|
|
305
|
-
let rowSpan = 1;
|
|
306
|
-
for (let r = rowIndex + 1; r < rawRows.length; r++) {
|
|
307
|
-
const matchIndex = rowColumnIndices[r].indexOf(colIndex);
|
|
308
|
-
if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
|
|
309
|
-
rowSpan++;
|
|
310
|
-
}
|
|
311
|
-
return {
|
|
312
|
-
blocks: cell.blocks,
|
|
313
|
-
colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
|
|
314
|
-
rowSpan: rowSpan > 1 ? rowSpan : void 0,
|
|
315
|
-
background: cell.background,
|
|
316
|
-
borders: cell.borders
|
|
317
|
-
};
|
|
318
|
-
})
|
|
319
|
-
}))
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
function newFlowState() {
|
|
323
|
-
return {
|
|
324
|
-
blocks: [],
|
|
325
|
-
extents: [],
|
|
326
|
-
sectionBreaks: [],
|
|
327
|
-
bookmarkEvents: [],
|
|
328
|
-
openFields: [],
|
|
329
|
-
order: 0
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
function resolveBookmarkExtents(events) {
|
|
333
|
-
const byId = /* @__PURE__ */ new Map();
|
|
334
|
-
for (const event of events) {
|
|
335
|
-
const existing = byId.get(event.id);
|
|
336
|
-
if (existing === void 0) byId.set(event.id, [event]);
|
|
337
|
-
else existing.push(event);
|
|
338
|
-
}
|
|
339
|
-
const extents = [];
|
|
340
|
-
for (const halves of byId.values()) {
|
|
341
|
-
const start = halves.filter((half) => half.kind === "start");
|
|
342
|
-
const end = halves.filter((half) => half.kind === "end");
|
|
343
|
-
const open = start[0];
|
|
344
|
-
const close = end[0];
|
|
345
|
-
if (start.length !== 1 || end.length !== 1 || open === void 0 || close === void 0) continue;
|
|
346
|
-
if (open.name === void 0 || !open.qualified || !close.qualified || close.index < open.index) continue;
|
|
347
|
-
extents.push({
|
|
348
|
-
startIndex: open.index,
|
|
349
|
-
endIndex: close.index,
|
|
350
|
-
order: open.order,
|
|
351
|
-
descriptor: require_typed_docx_constructs.bookmarkAnchorDescriptor(open.name)
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
return extents;
|
|
355
|
-
}
|
|
356
|
-
function wholeParagraphTrackedChange(index) {
|
|
357
|
-
const content = require_typed_docx_constructs.contentBearingChildren(index);
|
|
358
|
-
const first = content[0];
|
|
359
|
-
if (first === void 0) return;
|
|
360
|
-
const change = require_typed_docx_constructs.PROVENANCE_CHANGE_BY_TAG.get(first.tag);
|
|
361
|
-
if (change === void 0 || !content.every((child) => child.tag === first.tag)) return;
|
|
362
|
-
return {
|
|
363
|
-
element: first,
|
|
364
|
-
change
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
function recordParagraphBookmarks(index, paragraphIndex, endIndex, state) {
|
|
368
|
-
index.elements.forEach((element, position) => {
|
|
369
|
-
if (element.tag !== "w:bookmarkStart" && element.tag !== "w:bookmarkEnd") return;
|
|
370
|
-
const id = require_typed_util.attr(element, "w:id");
|
|
371
|
-
if (id === void 0) return;
|
|
372
|
-
const leading = index.firstContentIndex === -1 || position < index.firstContentIndex;
|
|
373
|
-
const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
|
|
374
|
-
if (element.tag === "w:bookmarkStart") {
|
|
375
|
-
const name = require_typed_util.attr(element, "w:name");
|
|
376
|
-
state.bookmarkEvents.push({
|
|
377
|
-
id,
|
|
378
|
-
name: name === void 0 ? void 0 : require_typed_util.decodeEntities(name),
|
|
379
|
-
kind: "start",
|
|
380
|
-
index: leading ? paragraphIndex : endIndex,
|
|
381
|
-
qualified: leading || trailing,
|
|
382
|
-
order: state.order++
|
|
383
|
-
});
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
state.bookmarkEvents.push({
|
|
387
|
-
id,
|
|
388
|
-
name: void 0,
|
|
389
|
-
kind: "end",
|
|
390
|
-
index: trailing ? endIndex : paragraphIndex,
|
|
391
|
-
qualified: leading || trailing,
|
|
392
|
-
order: state.order++
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
function scanParagraphFields(index, paragraphIndex, endIndex, state) {
|
|
397
|
-
const content = require_typed_docx_constructs.contentBearingChildren(index);
|
|
398
|
-
content.forEach((child, position) => {
|
|
399
|
-
if (child.tag === "w:fldSimple") {
|
|
400
|
-
if (content.length === 1) state.extents.push({
|
|
401
|
-
startIndex: paragraphIndex,
|
|
402
|
-
endIndex,
|
|
403
|
-
order: state.order++,
|
|
404
|
-
descriptor: {
|
|
405
|
-
kind: "field",
|
|
406
|
-
instruction: require_typed_util.decodeEntities(require_typed_util.attr(child, "w:instr") ?? "")
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
if (child.tag !== "w:r") return;
|
|
412
|
-
const type = require_typed_docx_constructs.fieldCharType(child);
|
|
413
|
-
if (type === "begin") {
|
|
414
|
-
state.openFields.push({
|
|
415
|
-
instruction: "",
|
|
416
|
-
inCode: true,
|
|
417
|
-
startIndex: paragraphIndex,
|
|
418
|
-
qualifiedStart: position === 0,
|
|
419
|
-
order: state.order++
|
|
420
|
-
});
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
if (type === "separate") {
|
|
424
|
-
const open = state.openFields[state.openFields.length - 1];
|
|
425
|
-
if (open !== void 0) open.inCode = false;
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
if (type === "end") {
|
|
429
|
-
const open = state.openFields.pop();
|
|
430
|
-
if (open !== void 0 && open.qualifiedStart && position === content.length - 1) state.extents.push({
|
|
431
|
-
startIndex: open.startIndex,
|
|
432
|
-
endIndex,
|
|
433
|
-
order: open.order,
|
|
434
|
-
descriptor: {
|
|
435
|
-
kind: "field",
|
|
436
|
-
instruction: open.instruction
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
const open = state.openFields[state.openFields.length - 1];
|
|
442
|
-
if (open?.inCode === true) open.instruction += require_typed_docx_constructs.runInstructionText(child);
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
function collectParagraph(paragraph, ctx, state, carryDeletions) {
|
|
446
|
-
const index = require_typed_docx_constructs.indexParagraphContent(paragraph);
|
|
447
|
-
const tracked = wholeParagraphTrackedChange(index);
|
|
448
|
-
const paragraphDeleted = carryDeletions || tracked !== void 0 && require_typed_docx_constructs.isDeletedChange(tracked.change);
|
|
449
|
-
if (hasPageBreakBefore(paragraph)) state.blocks.push({ kind: "pageBreak" });
|
|
450
|
-
const paragraphIndex = state.blocks.length;
|
|
451
|
-
state.blocks.push(readParagraph(paragraph, ctx, paragraphDeleted));
|
|
452
|
-
state.blocks.push(...readParagraphImages(paragraph, ctx, paragraphDeleted));
|
|
453
|
-
const endIndex = state.blocks.length;
|
|
454
|
-
if (tracked !== void 0) state.extents.push({
|
|
455
|
-
startIndex: paragraphIndex,
|
|
456
|
-
endIndex,
|
|
457
|
-
order: state.order++,
|
|
458
|
-
descriptor: require_typed_docx_constructs.readProvenanceDescriptor(tracked.element, tracked.change)
|
|
459
|
-
});
|
|
460
|
-
recordParagraphBookmarks(index, paragraphIndex, endIndex, state);
|
|
461
|
-
scanParagraphFields(index, paragraphIndex, endIndex, state);
|
|
462
|
-
const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
|
|
463
|
-
const sectPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:sectPr")[0];
|
|
464
|
-
if (sectPr !== void 0) state.sectionBreaks.push({
|
|
465
|
-
index: state.blocks.length,
|
|
466
|
-
sectPr
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
function collectFlowNodes(nodes, ctx, state, carryDeletions) {
|
|
470
|
-
for (const node of nodes) {
|
|
471
|
-
if (node.type !== "element") continue;
|
|
472
|
-
if (node.tag === "w:p") {
|
|
473
|
-
collectParagraph(node, ctx, state, carryDeletions);
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
if (node.tag === "w:tbl") {
|
|
477
|
-
state.blocks.push(readTable(node, ctx, carryDeletions));
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
if (node.tag === "w:sdt") {
|
|
481
|
-
const order = state.order++;
|
|
482
|
-
const startIndex = state.blocks.length;
|
|
483
|
-
const sdtContent = require_typed_util.childrenWithTag(node, "w:sdtContent")[0];
|
|
484
|
-
if (sdtContent !== void 0) collectFlowNodes(sdtContent.children, ctx, state, carryDeletions);
|
|
485
|
-
state.extents.push({
|
|
486
|
-
startIndex,
|
|
487
|
-
endIndex: state.blocks.length,
|
|
488
|
-
order,
|
|
489
|
-
descriptor: require_typed_docx_constructs.readContentControlDescriptor(node)
|
|
490
|
-
});
|
|
491
|
-
continue;
|
|
492
|
-
}
|
|
493
|
-
const change = require_typed_docx_constructs.PROVENANCE_CHANGE_BY_TAG.get(node.tag);
|
|
494
|
-
if (change !== void 0) {
|
|
495
|
-
const order = state.order++;
|
|
496
|
-
const startIndex = state.blocks.length;
|
|
497
|
-
collectFlowNodes(node.children, ctx, state, carryDeletions || require_typed_docx_constructs.isDeletedChange(change));
|
|
498
|
-
state.extents.push({
|
|
499
|
-
startIndex,
|
|
500
|
-
endIndex: state.blocks.length,
|
|
501
|
-
order,
|
|
502
|
-
descriptor: require_typed_docx_constructs.readProvenanceDescriptor(node, change)
|
|
503
|
-
});
|
|
504
|
-
continue;
|
|
505
|
-
}
|
|
506
|
-
if (node.tag === "mc:AlternateContent") {
|
|
507
|
-
const target = require_typed_util.childrenWithTag(node, "mc:Fallback")[0] ?? require_typed_util.childrenWithTag(node, "mc:Choice")[0];
|
|
508
|
-
if (target !== void 0) collectFlowNodes(target.children, ctx, state, carryDeletions);
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
if (node.tag === "w:bookmarkStart") {
|
|
512
|
-
const id = require_typed_util.attr(node, "w:id");
|
|
513
|
-
const name = require_typed_util.attr(node, "w:name");
|
|
514
|
-
if (id !== void 0) state.bookmarkEvents.push({
|
|
515
|
-
id,
|
|
516
|
-
name: name === void 0 ? void 0 : require_typed_util.decodeEntities(name),
|
|
517
|
-
kind: "start",
|
|
518
|
-
index: state.blocks.length,
|
|
519
|
-
qualified: true,
|
|
520
|
-
order: state.order++
|
|
521
|
-
});
|
|
522
|
-
continue;
|
|
523
|
-
}
|
|
524
|
-
if (node.tag === "w:bookmarkEnd") {
|
|
525
|
-
const id = require_typed_util.attr(node, "w:id");
|
|
526
|
-
if (id !== void 0) state.bookmarkEvents.push({
|
|
527
|
-
id,
|
|
528
|
-
name: void 0,
|
|
529
|
-
kind: "end",
|
|
530
|
-
index: state.blocks.length,
|
|
531
|
-
qualified: true,
|
|
532
|
-
order: state.order++
|
|
533
|
-
});
|
|
534
|
-
continue;
|
|
535
|
-
}
|
|
536
|
-
if (node.tag === "w:sectPr") state.sectionBreaks.push({
|
|
537
|
-
index: state.blocks.length,
|
|
538
|
-
sectPr: node
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
function readBlockScope(nodes, ctx, carryDeletions) {
|
|
543
|
-
const state = newFlowState();
|
|
544
|
-
collectFlowNodes(nodes, ctx, state, carryDeletions);
|
|
545
|
-
return require_typed_docx_constructs.insertConstructMarkers(state.blocks, [...state.extents, ...resolveBookmarkExtents(state.bookmarkEvents)]);
|
|
546
|
-
}
|
|
547
|
-
function readSections(body, ctx) {
|
|
548
|
-
const state = newFlowState();
|
|
549
|
-
collectFlowNodes(body.children, ctx, state, false);
|
|
550
|
-
const extents = [...state.extents, ...resolveBookmarkExtents(state.bookmarkEvents)];
|
|
551
|
-
function sliceSection(pageSize, margins, from, to) {
|
|
552
|
-
const contained = extents.filter((extent) => extent.startIndex >= from && extent.endIndex <= to).map((extent) => ({
|
|
553
|
-
...extent,
|
|
554
|
-
startIndex: extent.startIndex - from,
|
|
555
|
-
endIndex: extent.endIndex - from
|
|
556
|
-
}));
|
|
557
|
-
return {
|
|
558
|
-
pageSize,
|
|
559
|
-
margins,
|
|
560
|
-
blocks: require_typed_docx_constructs.insertConstructMarkers(state.blocks.slice(from, to), contained)
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
const sections = [];
|
|
564
|
-
let from = 0;
|
|
565
|
-
for (const sectionBreak of state.sectionBreaks) {
|
|
566
|
-
sections.push(sliceSection(readPageSize(sectionBreak.sectPr), readMargins(sectionBreak.sectPr), from, sectionBreak.index));
|
|
567
|
-
from = sectionBreak.index;
|
|
568
|
-
}
|
|
569
|
-
if (from < state.blocks.length || sections.length === 0) sections.push(sliceSection(document_schema_js.PAGE_SIZE_LETTER, DEFAULT_MARGINS, from, state.blocks.length));
|
|
570
|
-
sections.forEach((section, sectionIndex) => require_typed_shared_source_path.assignSourcePaths(section.blocks, `sections[${sectionIndex}]`));
|
|
571
|
-
return sections;
|
|
572
|
-
}
|
|
573
|
-
function readDocumentTheme(pkg, docRels) {
|
|
574
|
-
for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX)) {
|
|
575
|
-
const themeRoot = require_typed_util.rootElement(pkg.parts[rel.target]);
|
|
576
|
-
if (themeRoot !== void 0) return require_typed_shared_drawingml.readTheme(themeRoot);
|
|
577
|
-
}
|
|
578
|
-
return require_typed_shared_drawingml.EMPTY_THEME;
|
|
579
|
-
}
|
|
580
|
-
function readComment(comment) {
|
|
581
|
-
const author = require_typed_util.attr(comment, "w:author");
|
|
582
|
-
const result = { text: require_typed_util.elementsWithTag(comment.children, "w:t").map(require_typed_util.textContent).join("") };
|
|
583
|
-
if (author !== void 0) result.author = author;
|
|
584
|
-
return result;
|
|
585
|
-
}
|
|
586
|
-
function readFootnote(footnote) {
|
|
587
|
-
const type = require_typed_util.attr(footnote, "w:type");
|
|
588
|
-
const result = { text: require_typed_util.elementsWithTag(footnote.children, "w:t").map(require_typed_util.textContent).join("") };
|
|
589
|
-
if (type !== void 0) result.type = type;
|
|
590
|
-
return result;
|
|
591
|
-
}
|
|
592
|
-
function readComments(pkg) {
|
|
593
|
-
const root = require_typed_util.rootElement(pkg.parts["word/comments.xml"]);
|
|
594
|
-
if (root === void 0) return [];
|
|
595
|
-
return require_typed_util.childrenWithTag(root, "w:comment").map(readComment);
|
|
596
|
-
}
|
|
597
|
-
function readFootnotes(pkg) {
|
|
598
|
-
const root = require_typed_util.rootElement(pkg.parts["word/footnotes.xml"]);
|
|
599
|
-
if (root === void 0) return [];
|
|
600
|
-
const out = [];
|
|
601
|
-
for (const fn of require_typed_util.childrenWithTag(root, "w:footnote")) {
|
|
602
|
-
const type = require_typed_util.attr(fn, "w:type");
|
|
603
|
-
if (type === "separator" || type === "continuationSeparator") continue;
|
|
604
|
-
out.push(readFootnote(fn));
|
|
605
|
-
}
|
|
606
|
-
return out;
|
|
607
|
-
}
|
|
608
|
-
function readHeaderFooterText(pkg, prefix) {
|
|
609
|
-
const out = [];
|
|
610
|
-
for (const path of Object.keys(pkg.parts)) {
|
|
611
|
-
if (!path.startsWith(prefix) || !path.endsWith(".xml")) continue;
|
|
612
|
-
const part = pkg.parts[path];
|
|
613
|
-
if (part?.kind !== "xml") continue;
|
|
614
|
-
out.push(require_typed_util.elementsWithTag(part.nodes, "w:t").map(require_typed_util.textContent).join(""));
|
|
615
|
-
}
|
|
616
|
-
return out;
|
|
617
|
-
}
|
|
618
|
-
function readDocxContent(pkg) {
|
|
619
|
-
const documentRoot = require_typed_util.rootElement(pkg.parts[DOCUMENT_PART_PATH]);
|
|
620
|
-
if (documentRoot === void 0) throw new Error(`readDocxContent: package has no ${DOCUMENT_PART_PATH} part`);
|
|
621
|
-
const body = require_typed_util.childrenWithTag(documentRoot, "w:body")[0];
|
|
622
|
-
if (body === void 0) throw new Error(`readDocxContent: ${DOCUMENT_PART_PATH} has no w:body element`);
|
|
623
|
-
const docRels = require_typed_util.resolveRelationships(pkg, DOCUMENT_PART_PATH);
|
|
624
|
-
const ctx = {
|
|
625
|
-
styles: {
|
|
626
|
-
stylesRoot: require_typed_util.rootElement(pkg.parts[STYLES_PART_PATH]),
|
|
627
|
-
theme: readDocumentTheme(pkg, docRels)
|
|
628
|
-
},
|
|
629
|
-
rels: docRels,
|
|
630
|
-
pkg
|
|
631
|
-
};
|
|
632
|
-
return {
|
|
633
|
-
metadata: require_typed_shared_metadata.readCoreProperties(pkg),
|
|
634
|
-
sections: readSections(body, ctx),
|
|
635
|
-
comments: readComments(pkg),
|
|
636
|
-
footnotes: readFootnotes(pkg),
|
|
637
|
-
headers: readHeaderFooterText(pkg, "word/header"),
|
|
638
|
-
footers: readHeaderFooterText(pkg, "word/footer"),
|
|
639
|
-
numbering: require_typed_docx_numbering.readNumberingDefinitions(pkg)
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
//#endregion
|
|
643
|
-
exports.CommentSchema = CommentSchema;
|
|
644
|
-
exports.DocxDocumentSchema = DocxDocumentSchema;
|
|
645
|
-
exports.FootnoteSchema = FootnoteSchema;
|
|
646
|
-
exports.readDocxContent = readDocxContent;
|
|
2
|
+
const require_read = require("../../read-DPAy4uu8.cjs");
|
|
3
|
+
exports.CommentSchema = require_read.CommentSchema;
|
|
4
|
+
exports.DocxDocumentSchema = require_read.DocxDocumentSchema;
|
|
5
|
+
exports.FootnoteSchema = require_read.FootnoteSchema;
|
|
6
|
+
exports.readDocxContent = require_read.readDocxContent;
|