ooxml.js 2.4.0 → 2.5.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 +40 -2
- package/dist/codec.cjs +28 -0
- package/dist/codec.d.cts +72 -0
- package/dist/codec.d.ts +72 -0
- package/dist/codec.js +24 -0
- package/dist/compact.cjs +162 -0
- package/dist/compact.d.cts +70 -0
- package/dist/compact.d.ts +70 -0
- package/dist/compact.js +152 -0
- package/dist/image/sniff.cjs +28 -0
- package/dist/image/sniff.d.cts +5 -0
- package/dist/image/sniff.d.ts +5 -0
- package/dist/image/sniff.js +27 -0
- package/dist/index.cjs +83 -3025
- package/dist/index.d.cts +22 -527
- package/dist/index.d.ts +22 -527
- package/dist/index.js +22 -2964
- package/dist/model/node.cjs +67 -0
- package/dist/model/node.d.cts +2 -0
- package/dist/model/node.d.ts +2 -0
- package/dist/model/node.js +58 -0
- package/dist/model/package.cjs +19 -0
- package/dist/model/package.d.cts +2 -0
- package/dist/model/package.d.ts +2 -0
- package/dist/model/package.js +15 -0
- package/dist/node-CkBWRjNR.d.cts +83 -0
- package/dist/node-CkBWRjNR.d.ts +83 -0
- package/dist/package-BUojjTXf.d.ts +114 -0
- package/dist/package-L24lkba-.d.cts +114 -0
- package/dist/package-io/read.cjs +33 -0
- package/dist/package-io/read.d.cts +5 -0
- package/dist/package-io/read.d.ts +5 -0
- package/dist/package-io/read.js +32 -0
- package/dist/package-io/write.cjs +18 -0
- package/dist/package-io/write.d.cts +5 -0
- package/dist/package-io/write.d.ts +5 -0
- package/dist/package-io/write.js +17 -0
- package/dist/typed/docx/read.cjs +332 -0
- package/dist/typed/docx/read.d.cts +52 -0
- package/dist/typed/docx/read.d.ts +52 -0
- package/dist/typed/docx/read.js +328 -0
- package/dist/typed/docx/styles.cjs +148 -0
- package/dist/typed/docx/styles.d.cts +29 -0
- package/dist/typed/docx/styles.d.ts +29 -0
- package/dist/typed/docx/styles.js +146 -0
- package/dist/typed/pptx/inherit.cjs +96 -0
- package/dist/typed/pptx/inherit.d.cts +30 -0
- package/dist/typed/pptx/inherit.d.ts +30 -0
- package/dist/typed/pptx/inherit.js +90 -0
- package/dist/typed/pptx/read.cjs +364 -0
- package/dist/typed/pptx/read.d.cts +44 -0
- package/dist/typed/pptx/read.d.ts +44 -0
- package/dist/typed/pptx/read.js +362 -0
- package/dist/typed/shared/color.cjs +85 -0
- package/dist/typed/shared/color.d.cts +9 -0
- package/dist/typed/shared/color.d.ts +9 -0
- package/dist/typed/shared/color.js +84 -0
- package/dist/typed/shared/drawingml.cjs +191 -0
- package/dist/typed/shared/drawingml.d.cts +40 -0
- package/dist/typed/shared/drawingml.d.ts +40 -0
- package/dist/typed/shared/drawingml.js +180 -0
- package/dist/typed/shared/metadata.cjs +44 -0
- package/dist/typed/shared/metadata.d.cts +16 -0
- package/dist/typed/shared/metadata.d.ts +16 -0
- package/dist/typed/shared/metadata.js +42 -0
- package/dist/typed/shared/source-path.cjs +18 -0
- package/dist/typed/shared/source-path.d.cts +5 -0
- package/dist/typed/shared/source-path.d.ts +5 -0
- package/dist/typed/shared/source-path.js +17 -0
- package/dist/typed/shared/units.cjs +55 -0
- package/dist/typed/shared/units.d.cts +20 -0
- package/dist/typed/shared/units.d.ts +20 -0
- package/dist/typed/shared/units.js +38 -0
- package/dist/typed/util.cjs +85 -0
- package/dist/typed/util.d.cts +18 -0
- package/dist/typed/util.d.ts +18 -0
- package/dist/typed/util.js +77 -0
- package/dist/typed/xlsx/a1.cjs +64 -0
- package/dist/typed/xlsx/a1.d.cts +19 -0
- package/dist/typed/xlsx/a1.d.ts +19 -0
- package/dist/typed/xlsx/a1.js +58 -0
- package/dist/typed/xlsx/build.cjs +456 -0
- package/dist/typed/xlsx/build.d.cts +6 -0
- package/dist/typed/xlsx/build.d.ts +6 -0
- package/dist/typed/xlsx/build.js +455 -0
- package/dist/typed/xlsx/content.cjs +257 -0
- package/dist/typed/xlsx/content.d.cts +6 -0
- package/dist/typed/xlsx/content.d.ts +6 -0
- package/dist/typed/xlsx/content.js +256 -0
- package/dist/typed/xlsx/defined-names.cjs +90 -0
- package/dist/typed/xlsx/defined-names.d.cts +20 -0
- package/dist/typed/xlsx/defined-names.d.ts +20 -0
- package/dist/typed/xlsx/defined-names.js +83 -0
- package/dist/typed/xlsx/print-settings.cjs +116 -0
- package/dist/typed/xlsx/print-settings.d.cts +8 -0
- package/dist/typed/xlsx/print-settings.d.ts +8 -0
- package/dist/typed/xlsx/print-settings.js +114 -0
- package/dist/typed/xlsx/shared-strings.cjs +35 -0
- package/dist/typed/xlsx/shared-strings.d.cts +12 -0
- package/dist/typed/xlsx/shared-strings.d.ts +12 -0
- package/dist/typed/xlsx/shared-strings.js +33 -0
- package/dist/typed/xlsx/units.cjs +21 -0
- package/dist/typed/xlsx/units.d.cts +8 -0
- package/dist/typed/xlsx/units.d.ts +8 -0
- package/dist/typed/xlsx/units.js +16 -0
- package/dist/typed/xlsx/util.cjs +53 -0
- package/dist/typed/xlsx/util.d.cts +10 -0
- package/dist/typed/xlsx/util.d.ts +10 -0
- package/dist/typed/xlsx/util.js +47 -0
- package/dist/typed/xlsx.cjs +140 -0
- package/dist/typed/xlsx.d.cts +43 -0
- package/dist/typed/xlsx.d.ts +43 -0
- package/dist/typed/xlsx.js +135 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/xml/build.cjs +46 -0
- package/dist/xml/build.d.cts +5 -0
- package/dist/xml/build.d.ts +5 -0
- package/dist/xml/build.js +46 -0
- package/dist/xml/entities.cjs +7 -0
- package/dist/xml/entities.d.cts +4 -0
- package/dist/xml/entities.d.ts +4 -0
- package/dist/xml/entities.js +6 -0
- package/dist/xml/fragment.cjs +22 -0
- package/dist/xml/fragment.d.cts +6 -0
- package/dist/xml/fragment.d.ts +6 -0
- package/dist/xml/fragment.js +20 -0
- package/dist/xml/parse.cjs +88 -0
- package/dist/xml/parse.d.cts +5 -0
- package/dist/xml/parse.d.ts +5 -0
- package/dist/xml/parse.js +88 -0
- package/dist/zip.cjs +12 -0
- package/dist/zip.d.cts +5 -0
- package/dist/zip.d.ts +5 -0
- package/dist/zip.js +10 -0
- package/package.json +9 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { base64ToBytes } from "../util/base64.js";
|
|
2
|
+
import { zipPackage } from "../zip.js";
|
|
3
|
+
import { buildXml } from "../xml/build.js";
|
|
4
|
+
//#region src/package-io/write.ts
|
|
5
|
+
function serializePackage(pkg) {
|
|
6
|
+
const entries = {};
|
|
7
|
+
for (const [path, part] of Object.entries(pkg.parts)) entries[path] = partToBytes(part);
|
|
8
|
+
return zipPackage(entries);
|
|
9
|
+
}
|
|
10
|
+
function partToBytes(part) {
|
|
11
|
+
switch (part.kind) {
|
|
12
|
+
case "xml": return new TextEncoder().encode(buildXml(part.nodes));
|
|
13
|
+
case "binary": return base64ToBytes(part.base64);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { serializePackage };
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_typed_util = require("../util.cjs");
|
|
3
|
+
const require_typed_shared_metadata = require("../shared/metadata.cjs");
|
|
4
|
+
const require_typed_shared_units = require("../shared/units.cjs");
|
|
5
|
+
const require_typed_shared_drawingml = require("../shared/drawingml.cjs");
|
|
6
|
+
const require_typed_shared_source_path = require("../shared/source-path.cjs");
|
|
7
|
+
const require_typed_docx_styles = require("./styles.cjs");
|
|
8
|
+
let zod = require("zod");
|
|
9
|
+
let document_schema_js = require("document-schema.js");
|
|
10
|
+
//#region src/typed/docx/read.ts
|
|
11
|
+
const CommentSchema = zod.z.object({
|
|
12
|
+
author: zod.z.string().optional(),
|
|
13
|
+
text: zod.z.string()
|
|
14
|
+
});
|
|
15
|
+
const FootnoteSchema = zod.z.object({
|
|
16
|
+
type: zod.z.string().optional(),
|
|
17
|
+
text: zod.z.string()
|
|
18
|
+
});
|
|
19
|
+
const DocxDocumentSchema = zod.z.object({
|
|
20
|
+
metadata: require_typed_shared_metadata.DocumentMetadataSchema,
|
|
21
|
+
sections: zod.z.array(document_schema_js.ContentSectionSchema),
|
|
22
|
+
comments: zod.z.array(CommentSchema),
|
|
23
|
+
footnotes: zod.z.array(FootnoteSchema),
|
|
24
|
+
headers: zod.z.array(zod.z.string()),
|
|
25
|
+
footers: zod.z.array(zod.z.string())
|
|
26
|
+
});
|
|
27
|
+
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
28
|
+
const STYLES_PART_PATH = "word/styles.xml";
|
|
29
|
+
const THEME_REL_SUFFIX = "/theme";
|
|
30
|
+
const DEFAULT_MARGIN_PT = 72;
|
|
31
|
+
const DEFAULT_MARGINS = {
|
|
32
|
+
topPt: DEFAULT_MARGIN_PT,
|
|
33
|
+
rightPt: DEFAULT_MARGIN_PT,
|
|
34
|
+
bottomPt: DEFAULT_MARGIN_PT,
|
|
35
|
+
leftPt: DEFAULT_MARGIN_PT
|
|
36
|
+
};
|
|
37
|
+
function readPageSize(sectPr) {
|
|
38
|
+
const pgSz = require_typed_util.childrenWithTag(sectPr, "w:pgSz")[0];
|
|
39
|
+
const w = pgSz === void 0 ? void 0 : require_typed_util.attr(pgSz, "w:w");
|
|
40
|
+
const h = pgSz === void 0 ? void 0 : require_typed_util.attr(pgSz, "w:h");
|
|
41
|
+
return w === void 0 || h === void 0 ? document_schema_js.PAGE_SIZE_LETTER : {
|
|
42
|
+
widthPt: require_typed_shared_units.twipsToPt(Number(w)),
|
|
43
|
+
heightPt: require_typed_shared_units.twipsToPt(Number(h))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function readMargins(sectPr) {
|
|
47
|
+
const pgMar = require_typed_util.childrenWithTag(sectPr, "w:pgMar")[0];
|
|
48
|
+
if (pgMar === void 0) return DEFAULT_MARGINS;
|
|
49
|
+
const top = require_typed_util.attr(pgMar, "w:top");
|
|
50
|
+
const right = require_typed_util.attr(pgMar, "w:right");
|
|
51
|
+
const bottom = require_typed_util.attr(pgMar, "w:bottom");
|
|
52
|
+
const left = require_typed_util.attr(pgMar, "w:left");
|
|
53
|
+
return {
|
|
54
|
+
topPt: top === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(top)),
|
|
55
|
+
rightPt: right === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(right)),
|
|
56
|
+
bottomPt: bottom === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(bottom)),
|
|
57
|
+
leftPt: left === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(left))
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function readListMembership(pPr) {
|
|
61
|
+
const numPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:numPr")[0];
|
|
62
|
+
if (numPr === void 0) return;
|
|
63
|
+
const numIdEl = require_typed_util.childrenWithTag(numPr, "w:numId")[0];
|
|
64
|
+
const numId = numIdEl === void 0 ? void 0 : require_typed_util.attr(numIdEl, "w:val");
|
|
65
|
+
if (numId === void 0) return;
|
|
66
|
+
const ilvlEl = require_typed_util.childrenWithTag(numPr, "w:ilvl")[0];
|
|
67
|
+
const ilvlVal = ilvlEl === void 0 ? void 0 : require_typed_util.attr(ilvlEl, "w:val");
|
|
68
|
+
return {
|
|
69
|
+
numId,
|
|
70
|
+
level: ilvlVal === void 0 ? 0 : Number(ilvlVal)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function readToggle(el) {
|
|
74
|
+
if (el === void 0) return false;
|
|
75
|
+
const val = require_typed_util.attr(el, "w:val");
|
|
76
|
+
return val === void 0 || val !== "0" && val !== "false" && val !== "off";
|
|
77
|
+
}
|
|
78
|
+
function hasPageBreakBefore(paragraph) {
|
|
79
|
+
const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
|
|
80
|
+
return readToggle(pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:pageBreakBefore")[0]);
|
|
81
|
+
}
|
|
82
|
+
function readRunText(run) {
|
|
83
|
+
let text = "";
|
|
84
|
+
for (const child of run.children) {
|
|
85
|
+
if (child.type !== "element") continue;
|
|
86
|
+
if (child.tag === "w:t") text += require_typed_util.textContent(child);
|
|
87
|
+
else if (child.tag === "w:tab") text += " ";
|
|
88
|
+
else if (child.tag === "w:br" || child.tag === "w:cr") text += "\n";
|
|
89
|
+
}
|
|
90
|
+
return text;
|
|
91
|
+
}
|
|
92
|
+
function readRun(run, paragraph, context) {
|
|
93
|
+
const props = require_typed_docx_styles.resolveRunProperties(run, paragraph, context);
|
|
94
|
+
return {
|
|
95
|
+
text: readRunText(run),
|
|
96
|
+
bold: props.bold,
|
|
97
|
+
italic: props.italic,
|
|
98
|
+
underline: props.underline,
|
|
99
|
+
strike: props.strike,
|
|
100
|
+
fontFamily: props.fontFamily,
|
|
101
|
+
sizePt: props.sizePt,
|
|
102
|
+
color: props.color
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function readParagraphRuns(paragraph, context, rels) {
|
|
106
|
+
const runs = [];
|
|
107
|
+
let fieldState = "none";
|
|
108
|
+
function walk(nodes, hyperlinkTarget) {
|
|
109
|
+
for (const node of nodes) {
|
|
110
|
+
if (node.type !== "element") continue;
|
|
111
|
+
if (node.tag === "w:r") {
|
|
112
|
+
const fldChar = require_typed_util.childrenWithTag(node, "w:fldChar")[0];
|
|
113
|
+
if (fldChar !== void 0) {
|
|
114
|
+
const type = require_typed_util.attr(fldChar, "w:fldCharType");
|
|
115
|
+
if (type === "begin") fieldState = "code";
|
|
116
|
+
else if (type === "separate") fieldState = "result";
|
|
117
|
+
else if (type === "end") fieldState = "none";
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (fieldState === "code") continue;
|
|
121
|
+
const run = readRun(node, paragraph, context);
|
|
122
|
+
runs.push(hyperlinkTarget === void 0 ? run : {
|
|
123
|
+
...run,
|
|
124
|
+
hyperlink: hyperlinkTarget
|
|
125
|
+
});
|
|
126
|
+
} else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
|
|
127
|
+
else if (node.tag === "w:hyperlink") {
|
|
128
|
+
const rId = require_typed_util.attr(node, "r:id");
|
|
129
|
+
const target = rId === void 0 ? void 0 : rels.get(rId)?.target;
|
|
130
|
+
walk(node.children, target ?? hyperlinkTarget);
|
|
131
|
+
} else if (node.tag === "w:ins") walk(node.children, hyperlinkTarget);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
walk(paragraph.children, void 0);
|
|
135
|
+
return runs;
|
|
136
|
+
}
|
|
137
|
+
function readParagraph(paragraph, context, rels) {
|
|
138
|
+
const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
|
|
139
|
+
const pStyleEl = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:pStyle")[0];
|
|
140
|
+
const props = require_typed_docx_styles.resolveParagraphProperties(paragraph, context);
|
|
141
|
+
return {
|
|
142
|
+
kind: "paragraph",
|
|
143
|
+
runs: readParagraphRuns(paragraph, context, rels),
|
|
144
|
+
styleId: pStyleEl === void 0 ? void 0 : require_typed_util.attr(pStyleEl, "w:val"),
|
|
145
|
+
alignment: props.alignment,
|
|
146
|
+
list: readListMembership(pPr),
|
|
147
|
+
spacingBeforePt: props.spacingBeforePt,
|
|
148
|
+
spacingAfterPt: props.spacingAfterPt,
|
|
149
|
+
lineSpacing: props.lineSpacing,
|
|
150
|
+
indentLeftPt: props.indentLeftPt,
|
|
151
|
+
indentFirstLinePt: props.indentFirstLinePt
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function readCellShading(tcPr) {
|
|
155
|
+
const shd = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:shd")[0];
|
|
156
|
+
const fill = shd === void 0 ? void 0 : require_typed_util.attr(shd, "w:fill");
|
|
157
|
+
return fill === void 0 || fill === "auto" || fill === "none" ? void 0 : (0, document_schema_js.rgbHexToColor)(fill);
|
|
158
|
+
}
|
|
159
|
+
function readRawCell(tc, context, rels) {
|
|
160
|
+
const tcPr = require_typed_util.childrenWithTag(tc, "w:tcPr")[0];
|
|
161
|
+
const gridSpanEl = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:gridSpan")[0];
|
|
162
|
+
const gridSpanVal = gridSpanEl === void 0 ? void 0 : require_typed_util.attr(gridSpanEl, "w:val");
|
|
163
|
+
const vMerge = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:vMerge")[0];
|
|
164
|
+
const vMergeVal = vMerge === void 0 ? void 0 : require_typed_util.attr(vMerge, "w:val") ?? "continue";
|
|
165
|
+
return {
|
|
166
|
+
gridSpan: gridSpanVal === void 0 ? 1 : Number(gridSpanVal),
|
|
167
|
+
isVMergeContinuation: vMergeVal === "continue",
|
|
168
|
+
background: readCellShading(tcPr),
|
|
169
|
+
blocks: readBodyBlocks(tc.children, context, rels)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function readTable(tbl, context, rels) {
|
|
173
|
+
const tblGrid = require_typed_util.childrenWithTag(tbl, "w:tblGrid")[0];
|
|
174
|
+
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")));
|
|
175
|
+
const rawRows = require_typed_util.childrenWithTag(tbl, "w:tr").map((tr) => require_typed_util.childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels)));
|
|
176
|
+
const rowColumnIndices = rawRows.map((row) => {
|
|
177
|
+
const indices = [];
|
|
178
|
+
let col = 0;
|
|
179
|
+
for (const cell of row) {
|
|
180
|
+
indices.push(col);
|
|
181
|
+
col += cell.gridSpan;
|
|
182
|
+
}
|
|
183
|
+
return indices;
|
|
184
|
+
});
|
|
185
|
+
return {
|
|
186
|
+
kind: "table",
|
|
187
|
+
columnWidthsPt,
|
|
188
|
+
rows: rawRows.map((row, rowIndex) => ({ cells: row.map((cell, cellIndex) => {
|
|
189
|
+
if (cell.isVMergeContinuation) return { blocks: [] };
|
|
190
|
+
const colIndex = rowColumnIndices[rowIndex][cellIndex];
|
|
191
|
+
let rowSpan = 1;
|
|
192
|
+
for (let r = rowIndex + 1; r < rawRows.length; r++) {
|
|
193
|
+
const matchIndex = rowColumnIndices[r].indexOf(colIndex);
|
|
194
|
+
if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
|
|
195
|
+
rowSpan++;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
blocks: cell.blocks,
|
|
199
|
+
colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
|
|
200
|
+
rowSpan: rowSpan > 1 ? rowSpan : void 0,
|
|
201
|
+
background: cell.background
|
|
202
|
+
};
|
|
203
|
+
}) }))
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function readBodyBlocks(nodes, context, rels) {
|
|
207
|
+
const blocks = [];
|
|
208
|
+
for (const node of nodes) {
|
|
209
|
+
if (node.type !== "element") continue;
|
|
210
|
+
if (node.tag === "w:p") {
|
|
211
|
+
if (hasPageBreakBefore(node)) blocks.push({ kind: "pageBreak" });
|
|
212
|
+
blocks.push(readParagraph(node, context, rels));
|
|
213
|
+
} else if (node.tag === "w:tbl") blocks.push(readTable(node, context, rels));
|
|
214
|
+
else if (node.tag === "w:sdt") {
|
|
215
|
+
const sdtContent = require_typed_util.childrenWithTag(node, "w:sdtContent")[0];
|
|
216
|
+
if (sdtContent !== void 0) blocks.push(...readBodyBlocks(sdtContent.children, context, rels));
|
|
217
|
+
} else if (node.tag === "w:ins") blocks.push(...readBodyBlocks(node.children, context, rels));
|
|
218
|
+
else if (node.tag === "mc:AlternateContent") {
|
|
219
|
+
const target = require_typed_util.childrenWithTag(node, "mc:Fallback")[0] ?? require_typed_util.childrenWithTag(node, "mc:Choice")[0];
|
|
220
|
+
if (target !== void 0) blocks.push(...readBodyBlocks(target.children, context, rels));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return blocks;
|
|
224
|
+
}
|
|
225
|
+
function readSections(body, context, rels) {
|
|
226
|
+
const sections = [];
|
|
227
|
+
let currentBlocks = [];
|
|
228
|
+
for (const node of body.children) {
|
|
229
|
+
if (node.type !== "element") continue;
|
|
230
|
+
if (node.tag === "w:sectPr") {
|
|
231
|
+
sections.push({
|
|
232
|
+
pageSize: readPageSize(node),
|
|
233
|
+
margins: readMargins(node),
|
|
234
|
+
blocks: currentBlocks
|
|
235
|
+
});
|
|
236
|
+
currentBlocks = [];
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (node.tag === "w:p") {
|
|
240
|
+
const pPr = require_typed_util.childrenWithTag(node, "w:pPr")[0];
|
|
241
|
+
const sectPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:sectPr")[0];
|
|
242
|
+
if (hasPageBreakBefore(node)) currentBlocks.push({ kind: "pageBreak" });
|
|
243
|
+
currentBlocks.push(readParagraph(node, context, rels));
|
|
244
|
+
if (sectPr !== void 0) {
|
|
245
|
+
sections.push({
|
|
246
|
+
pageSize: readPageSize(sectPr),
|
|
247
|
+
margins: readMargins(sectPr),
|
|
248
|
+
blocks: currentBlocks
|
|
249
|
+
});
|
|
250
|
+
currentBlocks = [];
|
|
251
|
+
}
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
currentBlocks.push(...readBodyBlocks([node], context, rels));
|
|
255
|
+
}
|
|
256
|
+
if (currentBlocks.length > 0 || sections.length === 0) sections.push({
|
|
257
|
+
pageSize: document_schema_js.PAGE_SIZE_LETTER,
|
|
258
|
+
margins: DEFAULT_MARGINS,
|
|
259
|
+
blocks: currentBlocks
|
|
260
|
+
});
|
|
261
|
+
sections.forEach((section, sectionIndex) => require_typed_shared_source_path.assignSourcePaths(section.blocks, `sections[${sectionIndex}]`));
|
|
262
|
+
return sections;
|
|
263
|
+
}
|
|
264
|
+
function readDocumentTheme(pkg, docRels) {
|
|
265
|
+
for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX)) {
|
|
266
|
+
const themeRoot = require_typed_util.rootElement(pkg.parts[rel.target]);
|
|
267
|
+
if (themeRoot !== void 0) return require_typed_shared_drawingml.readTheme(themeRoot);
|
|
268
|
+
}
|
|
269
|
+
return require_typed_shared_drawingml.EMPTY_THEME;
|
|
270
|
+
}
|
|
271
|
+
function readComment(comment) {
|
|
272
|
+
const author = require_typed_util.attr(comment, "w:author");
|
|
273
|
+
const result = { text: require_typed_util.elementsWithTag(comment.children, "w:t").map(require_typed_util.textContent).join("") };
|
|
274
|
+
if (author !== void 0) result.author = author;
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
function readFootnote(footnote) {
|
|
278
|
+
const type = require_typed_util.attr(footnote, "w:type");
|
|
279
|
+
const result = { text: require_typed_util.elementsWithTag(footnote.children, "w:t").map(require_typed_util.textContent).join("") };
|
|
280
|
+
if (type !== void 0) result.type = type;
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
function readComments(pkg) {
|
|
284
|
+
const root = require_typed_util.rootElement(pkg.parts["word/comments.xml"]);
|
|
285
|
+
if (root === void 0) return [];
|
|
286
|
+
return require_typed_util.childrenWithTag(root, "w:comment").map(readComment);
|
|
287
|
+
}
|
|
288
|
+
function readFootnotes(pkg) {
|
|
289
|
+
const root = require_typed_util.rootElement(pkg.parts["word/footnotes.xml"]);
|
|
290
|
+
if (root === void 0) return [];
|
|
291
|
+
const out = [];
|
|
292
|
+
for (const fn of require_typed_util.childrenWithTag(root, "w:footnote")) {
|
|
293
|
+
const type = require_typed_util.attr(fn, "w:type");
|
|
294
|
+
if (type === "separator" || type === "continuationSeparator") continue;
|
|
295
|
+
out.push(readFootnote(fn));
|
|
296
|
+
}
|
|
297
|
+
return out;
|
|
298
|
+
}
|
|
299
|
+
function readHeaderFooterText(pkg, prefix) {
|
|
300
|
+
const out = [];
|
|
301
|
+
for (const path of Object.keys(pkg.parts)) {
|
|
302
|
+
if (!path.startsWith(prefix) || !path.endsWith(".xml")) continue;
|
|
303
|
+
const part = pkg.parts[path];
|
|
304
|
+
if (part?.kind !== "xml") continue;
|
|
305
|
+
out.push(require_typed_util.elementsWithTag(part.nodes, "w:t").map(require_typed_util.textContent).join(""));
|
|
306
|
+
}
|
|
307
|
+
return out;
|
|
308
|
+
}
|
|
309
|
+
function readDocx(pkg) {
|
|
310
|
+
const documentRoot = require_typed_util.rootElement(pkg.parts[DOCUMENT_PART_PATH]);
|
|
311
|
+
if (documentRoot === void 0) throw new Error(`readDocx: package has no ${DOCUMENT_PART_PATH} part`);
|
|
312
|
+
const body = require_typed_util.childrenWithTag(documentRoot, "w:body")[0];
|
|
313
|
+
if (body === void 0) throw new Error(`readDocx: ${DOCUMENT_PART_PATH} has no w:body element`);
|
|
314
|
+
const docRels = require_typed_util.resolveRelationships(pkg, DOCUMENT_PART_PATH);
|
|
315
|
+
const context = {
|
|
316
|
+
stylesRoot: require_typed_util.rootElement(pkg.parts[STYLES_PART_PATH]),
|
|
317
|
+
theme: readDocumentTheme(pkg, docRels)
|
|
318
|
+
};
|
|
319
|
+
return {
|
|
320
|
+
metadata: require_typed_shared_metadata.readCoreProperties(pkg),
|
|
321
|
+
sections: readSections(body, context, docRels),
|
|
322
|
+
comments: readComments(pkg),
|
|
323
|
+
footnotes: readFootnotes(pkg),
|
|
324
|
+
headers: readHeaderFooterText(pkg, "word/header"),
|
|
325
|
+
footers: readHeaderFooterText(pkg, "word/footer")
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
exports.CommentSchema = CommentSchema;
|
|
330
|
+
exports.DocxDocumentSchema = DocxDocumentSchema;
|
|
331
|
+
exports.FootnoteSchema = FootnoteSchema;
|
|
332
|
+
exports.readDocx = readDocx;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { r as Package } from "../../package-L24lkba-.cjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ContentBlock } from "document-schema.js";
|
|
4
|
+
//#region src/typed/docx/read.d.ts
|
|
5
|
+
declare const CommentSchema: z.ZodObject<{
|
|
6
|
+
author: z.ZodOptional<z.ZodString>;
|
|
7
|
+
text: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type Comment = z.infer<typeof CommentSchema>;
|
|
10
|
+
declare const FootnoteSchema: z.ZodObject<{
|
|
11
|
+
type: z.ZodOptional<z.ZodString>;
|
|
12
|
+
text: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
type Footnote = z.infer<typeof FootnoteSchema>;
|
|
15
|
+
declare const DocxDocumentSchema: z.ZodObject<{
|
|
16
|
+
metadata: z.ZodObject<{
|
|
17
|
+
title: z.ZodOptional<z.ZodString>;
|
|
18
|
+
author: z.ZodOptional<z.ZodString>;
|
|
19
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
20
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
|
+
creator: z.ZodOptional<z.ZodString>;
|
|
22
|
+
createdIso: z.ZodOptional<z.ZodString>;
|
|
23
|
+
modifiedIso: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
sections: z.ZodArray<z.ZodObject<{
|
|
26
|
+
pageSize: z.ZodObject<{
|
|
27
|
+
widthPt: z.ZodNumber;
|
|
28
|
+
heightPt: z.ZodNumber;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
margins: z.ZodObject<{
|
|
31
|
+
topPt: z.ZodNumber;
|
|
32
|
+
rightPt: z.ZodNumber;
|
|
33
|
+
bottomPt: z.ZodNumber;
|
|
34
|
+
leftPt: z.ZodNumber;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
blocks: z.ZodArray<z.ZodCustom<ContentBlock, ContentBlock>>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
comments: z.ZodArray<z.ZodObject<{
|
|
39
|
+
author: z.ZodOptional<z.ZodString>;
|
|
40
|
+
text: z.ZodString;
|
|
41
|
+
}, z.core.$strip>>;
|
|
42
|
+
footnotes: z.ZodArray<z.ZodObject<{
|
|
43
|
+
type: z.ZodOptional<z.ZodString>;
|
|
44
|
+
text: z.ZodString;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
headers: z.ZodArray<z.ZodString>;
|
|
47
|
+
footers: z.ZodArray<z.ZodString>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
type DocxDocument = z.infer<typeof DocxDocumentSchema>;
|
|
50
|
+
declare function readDocx(pkg: Package): DocxDocument;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { Comment, CommentSchema, DocxDocument, DocxDocumentSchema, Footnote, FootnoteSchema, readDocx };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { r as Package } from "../../package-BUojjTXf.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ContentBlock } from "document-schema.js";
|
|
4
|
+
//#region src/typed/docx/read.d.ts
|
|
5
|
+
declare const CommentSchema: z.ZodObject<{
|
|
6
|
+
author: z.ZodOptional<z.ZodString>;
|
|
7
|
+
text: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type Comment = z.infer<typeof CommentSchema>;
|
|
10
|
+
declare const FootnoteSchema: z.ZodObject<{
|
|
11
|
+
type: z.ZodOptional<z.ZodString>;
|
|
12
|
+
text: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
type Footnote = z.infer<typeof FootnoteSchema>;
|
|
15
|
+
declare const DocxDocumentSchema: z.ZodObject<{
|
|
16
|
+
metadata: z.ZodObject<{
|
|
17
|
+
title: z.ZodOptional<z.ZodString>;
|
|
18
|
+
author: z.ZodOptional<z.ZodString>;
|
|
19
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
20
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
|
+
creator: z.ZodOptional<z.ZodString>;
|
|
22
|
+
createdIso: z.ZodOptional<z.ZodString>;
|
|
23
|
+
modifiedIso: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
sections: z.ZodArray<z.ZodObject<{
|
|
26
|
+
pageSize: z.ZodObject<{
|
|
27
|
+
widthPt: z.ZodNumber;
|
|
28
|
+
heightPt: z.ZodNumber;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
margins: z.ZodObject<{
|
|
31
|
+
topPt: z.ZodNumber;
|
|
32
|
+
rightPt: z.ZodNumber;
|
|
33
|
+
bottomPt: z.ZodNumber;
|
|
34
|
+
leftPt: z.ZodNumber;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
blocks: z.ZodArray<z.ZodCustom<ContentBlock, ContentBlock>>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
comments: z.ZodArray<z.ZodObject<{
|
|
39
|
+
author: z.ZodOptional<z.ZodString>;
|
|
40
|
+
text: z.ZodString;
|
|
41
|
+
}, z.core.$strip>>;
|
|
42
|
+
footnotes: z.ZodArray<z.ZodObject<{
|
|
43
|
+
type: z.ZodOptional<z.ZodString>;
|
|
44
|
+
text: z.ZodString;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
headers: z.ZodArray<z.ZodString>;
|
|
47
|
+
footers: z.ZodArray<z.ZodString>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
type DocxDocument = z.infer<typeof DocxDocumentSchema>;
|
|
50
|
+
declare function readDocx(pkg: Package): DocxDocument;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { Comment, CommentSchema, DocxDocument, DocxDocumentSchema, Footnote, FootnoteSchema, readDocx };
|