@office-open/docx 0.9.5 → 0.9.7
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 +10 -10
- package/dist/context-BrtlmvVE.mjs +323 -0
- package/dist/context-BrtlmvVE.mjs.map +1 -0
- package/dist/{core-properties-BMagGcpC.d.mts → core-properties-CBMhgSrn.d.mts} +700 -558
- package/dist/core-properties-CBMhgSrn.d.mts.map +1 -0
- package/dist/{generate-BVfOLdwW.mjs → generate-BMTVflV1.mjs} +50 -34
- package/dist/generate-BMTVflV1.mjs.map +1 -0
- package/dist/generate.d.mts +1 -1
- package/dist/generate.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/parse-K59nx6MF.mjs +1927 -0
- package/dist/parse-K59nx6MF.mjs.map +1 -0
- package/dist/parse.d.mts +1 -1
- package/dist/parse.mjs +1 -1
- package/dist/parts-BQBGNSGm.mjs +12090 -0
- package/dist/parts-BQBGNSGm.mjs.map +1 -0
- package/dist/patch/index.d.mts +1 -1
- package/dist/patch/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/context-CSBntKXD.mjs +0 -5116
- package/dist/context-CSBntKXD.mjs.map +0 -1
- package/dist/core-properties-BMagGcpC.d.mts.map +0 -1
- package/dist/document-DYH7tGnw.mjs +0 -6227
- package/dist/document-DYH7tGnw.mjs.map +0 -1
- package/dist/generate-BVfOLdwW.mjs.map +0 -1
- package/dist/parse-Db2NGghB.mjs +0 -514
- package/dist/parse-Db2NGghB.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -79,31 +79,31 @@ Check the [demo folder](./demo) for 100+ working examples covering every feature
|
|
|
79
79
|
|
|
80
80
|
Performance vs original `docx` (9.6.1) package (higher ops/s is better, Windows 11 / Node 24).
|
|
81
81
|
|
|
82
|
-
**Default** = XML DEFLATE level 1 (SuperFast, matching MS Office)
|
|
82
|
+
**Default** = XML DEFLATE level 1 (SuperFast); media is split by type, matching MS Office Word — already-compressed formats (PNG/JPEG/GIF) are STOREd, the rest (EMF/WMF/BMP/TIFF/…) use DEFLATE level 1 (verified on a real MS Office file). **All STORE** = no compression (`{ compression: { xml: 0, media: 0 } }`). **docx** (async only) always uses DEFLATE for ALL entries including images (via JSZip, hardcoded, no STORE option).
|
|
83
83
|
|
|
84
84
|
```typescript
|
|
85
85
|
// Default (matches MS Office)
|
|
86
86
|
await generateDocument(options);
|
|
87
87
|
// All STORE (no compression)
|
|
88
|
-
await generateDocument(options, { compression: { xml: 0 } });
|
|
88
|
+
await generateDocument(options, { compression: { xml: 0, media: 0 } });
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
**Create + toBuffer (end-to-end)**
|
|
92
92
|
|
|
93
93
|
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|
|
94
94
|
| ------------------------------ | -----------: | ------------: | -------------: | --------------: | --------: |
|
|
95
|
-
| Simple (2p + 1 img) |
|
|
96
|
-
| Styled paragraphs (20) + 1 img |
|
|
97
|
-
| Table (10x5) | 1,
|
|
98
|
-
| Full featured + 2 imgs |
|
|
95
|
+
| Simple (2p + 1 img) | 1,047 ops/s | 605 ops/s | 1,444 ops/s | 1,448 ops/s | 82 ops/s |
|
|
96
|
+
| Styled paragraphs (20) + 1 img | 1,133 ops/s | 593 ops/s | 1,610 ops/s | 1,679 ops/s | 89 ops/s |
|
|
97
|
+
| Table (10x5) | 1,695 ops/s | 785 ops/s | 4,144 ops/s | 3,928 ops/s | 239 ops/s |
|
|
98
|
+
| Full featured + 2 imgs | 769 ops/s | 439 ops/s | 785 ops/s | 814 ops/s | 57 ops/s |
|
|
99
99
|
|
|
100
100
|
**Large Files — Create + toBuffer**
|
|
101
101
|
|
|
102
102
|
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|
|
103
103
|
| ------------------------------ | -----------: | ------------: | -------------: | --------------: | ---------: |
|
|
104
|
-
| 2000 paragraphs + 20 images |
|
|
105
|
-
| 200x10 table |
|
|
106
|
-
| 20 sections x 100p + 40 images |
|
|
104
|
+
| 2000 paragraphs + 20 images | 62.7 ops/s | 51.9 ops/s | 34.7 ops/s | 35.2 ops/s | 3.0 ops/s |
|
|
105
|
+
| 200x10 table | 261 ops/s | 218 ops/s | 271 ops/s | 271 ops/s | 36.3 ops/s |
|
|
106
|
+
| 20 sections x 100p + 40 images | 35.8 ops/s | 27.1 ops/s | 18.0 ops/s | 18.7 ops/s | 1.8 ops/s |
|
|
107
107
|
|
|
108
108
|
**Large File (~100MB) — Mixed Content**
|
|
109
109
|
|
|
@@ -111,7 +111,7 @@ await generateDocument(options, { compression: { xml: 0 } });
|
|
|
111
111
|
|
|
112
112
|
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|
|
113
113
|
| ------------------------ | -----------: | ------------: | -------------: | --------------: | ---------: |
|
|
114
|
-
| Mixed (500p+38img+50x10) |
|
|
114
|
+
| Mixed (500p+38img+50x10) | 9.7 ops/s | 8.2 ops/s | 5.1 ops/s | 4.2 ops/s | 0.30 ops/s |
|
|
115
115
|
|
|
116
116
|
## License
|
|
117
117
|
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { M as DefaultStylesFactory, O as Styles, ft as FontWrapper, q as Numbering, xn as Media } from "./parts-BQBGNSGm.mjs";
|
|
2
|
+
import { Relationships } from "@office-open/core";
|
|
3
|
+
import { js2xml, xml2js } from "@office-open/xml";
|
|
4
|
+
import { ChartCollection } from "@office-open/core/chart";
|
|
5
|
+
import { SmartArtCollection } from "@office-open/core/smartart";
|
|
6
|
+
//#region src/parts/alt-chunk/alt-chunk-collection.ts
|
|
7
|
+
/**
|
|
8
|
+
* Manages alternative format chunk parts in a document.
|
|
9
|
+
*
|
|
10
|
+
* Stores external content (HTML, RTF, plain text) that will be
|
|
11
|
+
* serialized into separate parts in the DOCX package.
|
|
12
|
+
*/
|
|
13
|
+
var AltChunkCollection = class {
|
|
14
|
+
map;
|
|
15
|
+
constructor() {
|
|
16
|
+
this.map = /* @__PURE__ */ new Map();
|
|
17
|
+
}
|
|
18
|
+
addAltChunk(key, data) {
|
|
19
|
+
this.map.set(key, data);
|
|
20
|
+
}
|
|
21
|
+
get array() {
|
|
22
|
+
return [...this.map.values()];
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/parts/sub-doc/sub-doc-collection.ts
|
|
27
|
+
/**
|
|
28
|
+
* Manages sub-document parts in a document.
|
|
29
|
+
*/
|
|
30
|
+
var SubDocCollection = class {
|
|
31
|
+
map;
|
|
32
|
+
constructor() {
|
|
33
|
+
this.map = /* @__PURE__ */ new Map();
|
|
34
|
+
}
|
|
35
|
+
addSubDoc(key, data) {
|
|
36
|
+
this.map.set(key, data);
|
|
37
|
+
}
|
|
38
|
+
get array() {
|
|
39
|
+
return [...this.map.values()];
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/parts/styles/external-styles-factory.ts
|
|
44
|
+
/**
|
|
45
|
+
* External styles factory module for WordprocessingML documents.
|
|
46
|
+
*
|
|
47
|
+
* Parses styles from external XML and returns raw XML strings.
|
|
48
|
+
* No XmlComponent dependency.
|
|
49
|
+
*
|
|
50
|
+
* Reference: http://officeopenxml.com/WPstyles.php
|
|
51
|
+
*
|
|
52
|
+
* @module
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Factory for creating styles from external XML sources.
|
|
56
|
+
*
|
|
57
|
+
* Parses styles from XML (typically from a styles.xml file)
|
|
58
|
+
* and returns raw XML strings for each style element.
|
|
59
|
+
*/
|
|
60
|
+
var ExternalStylesFactory = class {
|
|
61
|
+
/**
|
|
62
|
+
* Creates new Styles based on the given XML data.
|
|
63
|
+
*
|
|
64
|
+
* Parses the styles XML and converts each child to a raw XML string.
|
|
65
|
+
*/
|
|
66
|
+
newInstance(xmlData) {
|
|
67
|
+
const xmlObj = xml2js(xmlData, { compact: false });
|
|
68
|
+
let stylesXmlElement;
|
|
69
|
+
for (const xmlElm of xmlObj.elements || []) if (xmlElm.name === "w:styles") stylesXmlElement = xmlElm;
|
|
70
|
+
if (stylesXmlElement === void 0) return {
|
|
71
|
+
importedStyles: [],
|
|
72
|
+
initialAttributes: {}
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
importedStyles: (stylesXmlElement.elements || []).map((childElm) => ({ _raw: js2xml({ elements: [childElm] }) })),
|
|
76
|
+
initialAttributes: stylesXmlElement.attributes ?? {}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/context.ts
|
|
82
|
+
/**
|
|
83
|
+
* DOCX compilation context.
|
|
84
|
+
*
|
|
85
|
+
* DocxWriteContext holds all mutable state needed during document compilation.
|
|
86
|
+
* generateDocument() creates a DocxWriteContext internally.
|
|
87
|
+
*
|
|
88
|
+
* @module
|
|
89
|
+
*/
|
|
90
|
+
var DocxWriteContext = class {
|
|
91
|
+
_currentRelationshipId = 1;
|
|
92
|
+
_sectionProperties = [];
|
|
93
|
+
get sectionProperties() {
|
|
94
|
+
return this._sectionProperties;
|
|
95
|
+
}
|
|
96
|
+
addRelationship(_type, _target, _mode) {
|
|
97
|
+
return `rId${this._currentRelationshipId++}`;
|
|
98
|
+
}
|
|
99
|
+
addMedia(_data, _type) {
|
|
100
|
+
return "";
|
|
101
|
+
}
|
|
102
|
+
_headers = [];
|
|
103
|
+
_footers = [];
|
|
104
|
+
constructor(options) {
|
|
105
|
+
this._options = options;
|
|
106
|
+
this.numbering = new Numbering(options.numbering ? options.numbering : { config: [] });
|
|
107
|
+
this.comments = { relationships: new Relationships() };
|
|
108
|
+
this.fileRelationships = new Relationships();
|
|
109
|
+
this.footNotes = {
|
|
110
|
+
relationships: new Relationships(),
|
|
111
|
+
notes: /* @__PURE__ */ new Map()
|
|
112
|
+
};
|
|
113
|
+
this.endnotes = {
|
|
114
|
+
relationships: new Relationships(),
|
|
115
|
+
notes: /* @__PURE__ */ new Map()
|
|
116
|
+
};
|
|
117
|
+
this.document = { relationships: new Relationships() };
|
|
118
|
+
this._settingsOptions = {
|
|
119
|
+
compatibility: options.compatibility,
|
|
120
|
+
compatibilityModeVersion: options.compatabilityModeVersion,
|
|
121
|
+
defaultTabStop: options.defaultTabStop,
|
|
122
|
+
evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,
|
|
123
|
+
characterSpacingControl: options.characterSpacingControl,
|
|
124
|
+
hyphenation: {
|
|
125
|
+
autoHyphenation: options.hyphenation?.autoHyphenation,
|
|
126
|
+
consecutiveHyphenLimit: options.hyphenation?.consecutiveHyphenLimit,
|
|
127
|
+
doNotHyphenateCaps: options.hyphenation?.doNotHyphenateCaps,
|
|
128
|
+
hyphenationZone: options.hyphenation?.hyphenationZone
|
|
129
|
+
},
|
|
130
|
+
trackRevisions: options.features?.trackRevisions,
|
|
131
|
+
updateFields: options.features?.updateFields,
|
|
132
|
+
documentProtection: options.features?.documentProtection,
|
|
133
|
+
view: options.view,
|
|
134
|
+
zoom: options.zoom,
|
|
135
|
+
writeProtection: options.writeProtection,
|
|
136
|
+
displayBackgroundShape: options.displayBackgroundShape ?? (options.background?.image ? true : void 0),
|
|
137
|
+
embedTrueTypeFonts: options.embedTrueTypeFonts,
|
|
138
|
+
embedSystemFonts: options.embedSystemFonts,
|
|
139
|
+
saveSubsetFonts: options.saveSubsetFonts,
|
|
140
|
+
docVars: options.docVars,
|
|
141
|
+
colorSchemeMapping: options.colorSchemeMapping,
|
|
142
|
+
mailMerge: options.mailMerge,
|
|
143
|
+
...options.settings
|
|
144
|
+
};
|
|
145
|
+
this.media = new Media();
|
|
146
|
+
this.charts = new ChartCollection();
|
|
147
|
+
this.smartArts = new SmartArtCollection();
|
|
148
|
+
this.altChunks = new AltChunkCollection();
|
|
149
|
+
this.subDocs = new SubDocCollection();
|
|
150
|
+
if (options.externalStyles !== void 0) {
|
|
151
|
+
const defaultStyles = new DefaultStylesFactory().newInstance(options.styles?.default);
|
|
152
|
+
const externalStyles = new ExternalStylesFactory().newInstance(options.externalStyles);
|
|
153
|
+
const defaultStyleElements = defaultStyles.importedStyles.slice(2);
|
|
154
|
+
this.styles = new Styles({
|
|
155
|
+
...externalStyles,
|
|
156
|
+
importedStyles: [...externalStyles.importedStyles, ...defaultStyleElements]
|
|
157
|
+
});
|
|
158
|
+
} else if (options.styles) {
|
|
159
|
+
const defaultStyles = new DefaultStylesFactory().newInstance(options.styles.default);
|
|
160
|
+
const { importedStyles: parsedStyles, paragraphStyles, characterStyles, ...restStyles } = options.styles;
|
|
161
|
+
const merged = defaultStyles.importedStyles ? [...defaultStyles.importedStyles] : [];
|
|
162
|
+
if (restStyles.docDefaultsXml) {
|
|
163
|
+
const ddIdx = merged.findIndex((s) => s._raw.startsWith("<w:docDefaults"));
|
|
164
|
+
if (ddIdx >= 0) merged[ddIdx] = { _raw: restStyles.docDefaultsXml };
|
|
165
|
+
}
|
|
166
|
+
if (restStyles.latentStylesXml) {
|
|
167
|
+
const latentIdx = merged.findIndex((s) => s._raw.startsWith("<w:latentStyles"));
|
|
168
|
+
if (latentIdx >= 0) merged[latentIdx] = { _raw: restStyles.latentStylesXml };
|
|
169
|
+
}
|
|
170
|
+
if (parsedStyles && parsedStyles.length > 0) {
|
|
171
|
+
merged.splice(2);
|
|
172
|
+
merged.push(...parsedStyles);
|
|
173
|
+
this.styles = new Styles({
|
|
174
|
+
...defaultStyles,
|
|
175
|
+
importedStyles: merged,
|
|
176
|
+
...restStyles
|
|
177
|
+
});
|
|
178
|
+
} else this.styles = new Styles({
|
|
179
|
+
...defaultStyles,
|
|
180
|
+
paragraphStyles,
|
|
181
|
+
characterStyles,
|
|
182
|
+
...restStyles
|
|
183
|
+
});
|
|
184
|
+
} else {
|
|
185
|
+
const stylesFactory = new DefaultStylesFactory();
|
|
186
|
+
this.styles = new Styles(stylesFactory.newInstance());
|
|
187
|
+
}
|
|
188
|
+
if (options.styles?.paragraphStyles) for (const style of options.styles.paragraphStyles) {
|
|
189
|
+
const num = style.paragraph?.numbering;
|
|
190
|
+
if (num) this.numbering.createConcreteNumberingInstance(num.reference, num.instance ?? 0);
|
|
191
|
+
}
|
|
192
|
+
this.addDefaultRelationships();
|
|
193
|
+
for (const section of options.sections) this.addSection(section);
|
|
194
|
+
if (options.footnotes) for (const key in options.footnotes) this.footNotes.notes.set(parseFloat(key), options.footnotes[key].children);
|
|
195
|
+
if (options.endnotes) for (const key in options.endnotes) this.endnotes.notes.set(parseFloat(key), options.endnotes[key].children);
|
|
196
|
+
this.fontTable = new FontWrapper(options.fonts ?? []);
|
|
197
|
+
this.glossaryOptions = options.glossary;
|
|
198
|
+
this.webSettings = options.webSettings ?? void 0;
|
|
199
|
+
if (options.glossary) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument", "glossary/document.xml");
|
|
200
|
+
if (this.webSettings) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings", "webSettings.xml");
|
|
201
|
+
}
|
|
202
|
+
get headers() {
|
|
203
|
+
return this._headers;
|
|
204
|
+
}
|
|
205
|
+
get footers() {
|
|
206
|
+
return this._footers;
|
|
207
|
+
}
|
|
208
|
+
addSection({ headers = {}, footers = {}, properties }) {
|
|
209
|
+
const sectPrOptions = {
|
|
210
|
+
...properties,
|
|
211
|
+
footerWrapperGroup: {
|
|
212
|
+
default: footers.default ? this.createFooter(footers.default) : void 0,
|
|
213
|
+
even: footers.even ? this.createFooter(footers.even) : void 0,
|
|
214
|
+
first: footers.first ? this.createFooter(footers.first) : void 0
|
|
215
|
+
},
|
|
216
|
+
headerWrapperGroup: {
|
|
217
|
+
default: headers.default ? this.createHeader(headers.default) : void 0,
|
|
218
|
+
even: headers.even ? this.createHeader(headers.even) : void 0,
|
|
219
|
+
first: headers.first ? this.createHeader(headers.first) : void 0
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
this._sectionProperties.push(sectPrOptions);
|
|
223
|
+
}
|
|
224
|
+
createHeader(header) {
|
|
225
|
+
const referenceId = this._currentRelationshipId++;
|
|
226
|
+
const entry = {
|
|
227
|
+
children: header,
|
|
228
|
+
relationships: new Relationships(),
|
|
229
|
+
referenceId
|
|
230
|
+
};
|
|
231
|
+
this.addHeaderToDocument(entry);
|
|
232
|
+
return entry;
|
|
233
|
+
}
|
|
234
|
+
createFooter(footer) {
|
|
235
|
+
const referenceId = this._currentRelationshipId++;
|
|
236
|
+
const entry = {
|
|
237
|
+
children: footer,
|
|
238
|
+
relationships: new Relationships(),
|
|
239
|
+
referenceId
|
|
240
|
+
};
|
|
241
|
+
this.addFooterToDocument(entry);
|
|
242
|
+
return entry;
|
|
243
|
+
}
|
|
244
|
+
addHeaderToDocument(header) {
|
|
245
|
+
this._headers.push(header);
|
|
246
|
+
this.document.relationships.addRelationship(header.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", `header${this._headers.length}.xml`);
|
|
247
|
+
}
|
|
248
|
+
addFooterToDocument(footer) {
|
|
249
|
+
this._footers.push(footer);
|
|
250
|
+
this.document.relationships.addRelationship(footer.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", `footer${this._footers.length}.xml`);
|
|
251
|
+
}
|
|
252
|
+
addDefaultRelationships() {
|
|
253
|
+
this.fileRelationships.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml");
|
|
254
|
+
this.fileRelationships.addRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml");
|
|
255
|
+
this.fileRelationships.addRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
|
|
256
|
+
this.fileRelationships.addRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", "docProps/custom.xml");
|
|
257
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
|
258
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
|
|
259
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", "footnotes.xml");
|
|
260
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", "endnotes.xml");
|
|
261
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml");
|
|
262
|
+
if (this._options.comments?.children?.length) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml");
|
|
263
|
+
if (this._options.bibliography) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography", "bibliography.xml");
|
|
264
|
+
const themePart = this._options.rawParts?.find((p) => p.path.startsWith("word/theme/"));
|
|
265
|
+
if (themePart) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", themePart.path.replace(/^word\//, ""));
|
|
266
|
+
for (const part of this._options.rawParts ?? []) if (part.path.startsWith("customXml/") && part.path.endsWith(".xml") && !part.path.includes("/_rels/") && !part.path.includes("itemProps")) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml", `../${part.path}`);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* DOCX-specific read context.
|
|
271
|
+
*
|
|
272
|
+
* Holds references to the parsed DocxDocument and cached style/numbering data
|
|
273
|
+
* used throughout the DOCX parsing pipeline. Implements ReadContext for
|
|
274
|
+
* descriptor pipeline compatibility.
|
|
275
|
+
*/
|
|
276
|
+
var DocxReadContext = class {
|
|
277
|
+
docx;
|
|
278
|
+
styleCache;
|
|
279
|
+
numberingCache;
|
|
280
|
+
/**
|
|
281
|
+
* Path of the part currently being parsed. Each part carries its own .rels
|
|
282
|
+
* with independent rId numbering, so drawings inside a part must resolve
|
|
283
|
+
* image relationships against that part's rels. Defaults to the document body.
|
|
284
|
+
*/
|
|
285
|
+
currentPart = "word/document.xml";
|
|
286
|
+
constructor(docx, styleCache, numberingCache) {
|
|
287
|
+
this.docx = docx;
|
|
288
|
+
this.styleCache = styleCache;
|
|
289
|
+
this.numberingCache = numberingCache;
|
|
290
|
+
}
|
|
291
|
+
resolveRelationship(rId) {
|
|
292
|
+
const partMedia = this.docx.partRefs.partMedia.get(this.currentPart);
|
|
293
|
+
if (partMedia) {
|
|
294
|
+
const media = partMedia.get(rId);
|
|
295
|
+
if (media) return media;
|
|
296
|
+
}
|
|
297
|
+
return this.docx.partRefs.headers.get(rId) ?? this.docx.partRefs.footers.get(rId) ?? this.docx.partRefs.media.get(rId) ?? this.docx.partRefs.charts.get(rId) ?? this.docx.partRefs.diagramData.get(rId) ?? this.docx.partRefs.afChunks.get(rId) ?? this.docx.partRefs.subDocs.get(rId) ?? this.docx.partRefs.hyperlinks.get(rId);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Run `fn` with `currentPart` temporarily set to `partPath`, restoring the
|
|
301
|
+
* previous value afterwards. Use when parsing a sub-document part (header,
|
|
302
|
+
* footer, footnotes, …) so its drawings resolve images from its own rels.
|
|
303
|
+
*/
|
|
304
|
+
withPart(partPath, fn) {
|
|
305
|
+
const prev = this.currentPart;
|
|
306
|
+
this.currentPart = partPath;
|
|
307
|
+
try {
|
|
308
|
+
return fn();
|
|
309
|
+
} finally {
|
|
310
|
+
this.currentPart = prev;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
getPart(path) {
|
|
314
|
+
return this.docx.doc.get(path);
|
|
315
|
+
}
|
|
316
|
+
getRaw(path) {
|
|
317
|
+
return this.docx.doc.getRaw(path);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
//#endregion
|
|
321
|
+
export { AltChunkCollection as i, DocxWriteContext as n, SubDocCollection as r, DocxReadContext as t };
|
|
322
|
+
|
|
323
|
+
//# sourceMappingURL=context-BrtlmvVE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-BrtlmvVE.mjs","names":[],"sources":["../src/parts/alt-chunk/alt-chunk-collection.ts","../src/parts/sub-doc/sub-doc-collection.ts","../src/parts/styles/external-styles-factory.ts","../src/context.ts"],"sourcesContent":["/**\n * AltChunk collection module for managing alternative format content parts.\n *\n * @module\n */\n\n/**\n * Stores alternative format chunk data for later serialization by the compiler.\n */\nexport interface AltChunkData {\n /** Unique key for this alt chunk (e.g., relId) */\n key: string;\n /** Raw content data */\n data: Uint8Array;\n /** Part sub-path within word/ (e.g., \"afchunks/afchunk1.html\") */\n path: string;\n /** File extension (e.g., \"html\", \"rtf\", \"txt\") */\n extension: string;\n /** MIME content type (e.g., \"text/html\", \"application/rtf\") */\n contentType: string;\n}\n\n/**\n * Manages alternative format chunk parts in a document.\n *\n * Stores external content (HTML, RTF, plain text) that will be\n * serialized into separate parts in the DOCX package.\n */\nexport class AltChunkCollection {\n private map: Map<string, AltChunkData>;\n\n public constructor() {\n this.map = new Map<string, AltChunkData>();\n }\n\n public addAltChunk(key: string, data: AltChunkData): void {\n this.map.set(key, data);\n }\n\n public get array(): AltChunkData[] {\n return [...this.map.values()];\n }\n}\n","/**\n * Sub-document collection module for managing sub-document parts.\n *\n * @module\n */\n\n/**\n * Stores sub-document data for later serialization by the compiler.\n */\nexport interface SubDocData {\n /** Raw document data (.docx bytes) */\n data: Uint8Array;\n /** Part sub-path within word/ (e.g., \"subdocs/subdoc1.docx\") */\n path: string;\n}\n\n/**\n * Manages sub-document parts in a document.\n */\nexport class SubDocCollection {\n private map: Map<string, SubDocData>;\n\n public constructor() {\n this.map = new Map<string, SubDocData>();\n }\n\n public addSubDoc(key: string, data: SubDocData): void {\n this.map.set(key, data);\n }\n\n public get array(): SubDocData[] {\n return [...this.map.values()];\n }\n}\n","/**\n * External styles factory module for WordprocessingML documents.\n *\n * Parses styles from external XML and returns raw XML strings.\n * No XmlComponent dependency.\n *\n * Reference: http://officeopenxml.com/WPstyles.php\n *\n * @module\n */\nimport { js2xml, xml2js } from \"@office-open/xml\";\nimport type { Element as XMLElement } from \"@office-open/xml\";\n\nimport type { StylesOptions } from \"./styles\";\n\n/**\n * Factory for creating styles from external XML sources.\n *\n * Parses styles from XML (typically from a styles.xml file)\n * and returns raw XML strings for each style element.\n */\nexport class ExternalStylesFactory {\n /**\n * Creates new Styles based on the given XML data.\n *\n * Parses the styles XML and converts each child to a raw XML string.\n */\n public newInstance(xmlData: string): StylesOptions {\n const xmlObj = xml2js(xmlData, { compact: false }) as XMLElement;\n\n let stylesXmlElement: XMLElement | undefined;\n for (const xmlElm of xmlObj.elements || []) {\n if (xmlElm.name === \"w:styles\") {\n stylesXmlElement = xmlElm;\n }\n }\n\n if (stylesXmlElement === undefined) {\n return { importedStyles: [], initialAttributes: {} };\n }\n\n const stylesElements = stylesXmlElement.elements || [];\n\n return {\n importedStyles: stylesElements.map((childElm) => ({\n _raw: js2xml({ elements: [childElm] }),\n })),\n initialAttributes: (stylesXmlElement.attributes as Record<string, string>) ?? {},\n };\n }\n}\n","/**\n * DOCX compilation context.\n *\n * DocxWriteContext holds all mutable state needed during document compilation.\n * generateDocument() creates a DocxWriteContext internally.\n *\n * @module\n */\n\nimport { Relationships } from \"@office-open/core\";\nimport { ChartCollection } from \"@office-open/core/chart\";\nimport type { ReadContext, WriteContext } from \"@office-open/core/descriptor\";\nimport { SmartArtCollection } from \"@office-open/core/smartart\";\nimport type { Element } from \"@office-open/xml\";\nimport { AltChunkCollection } from \"@parts/alt-chunk/alt-chunk-collection\";\nimport type { DocumentOptions } from \"@parts/core-properties\";\nimport type { SectionPropertiesOptions } from \"@parts/document/body/section-properties/section-properties\";\nimport { FontWrapper } from \"@parts/fonts/font-wrapper\";\nimport type { GlossaryDocumentOptions } from \"@parts/glossary-document\";\nimport type { HeaderFooterEntry } from \"@parts/header-footer\";\nimport { Numbering } from \"@parts/numbering\";\nimport type { ParagraphOptions } from \"@parts/paragraph/paragraph\";\nimport type { SettingsOptions } from \"@parts/settings/settings\";\nimport { Styles } from \"@parts/styles\";\nimport { ExternalStylesFactory } from \"@parts/styles/external-styles-factory\";\nimport { DefaultStylesFactory } from \"@parts/styles/factory\";\nimport { SubDocCollection } from \"@parts/sub-doc/sub-doc-collection\";\nimport type { WebSettingsOptions } from \"@parts/web-settings\";\nimport { Media } from \"@shared/media\";\nimport type { SectionOptions } from \"@shared/section\";\nimport type { SectionChild } from \"@shared/section\";\n\nimport type { DocxDocument } from \"./parse\";\n\n/** Interface for document view wrappers — provides relationships access. */\nexport interface ViewWrapper {\n relationships: Relationships;\n}\n\n// ── BodyContext ──\n\n/**\n * Context for body-level stringification.\n *\n * Pure JSON pipeline context — extends WriteContext for descriptor compatibility.\n * No dependency on XmlComponent Context (compile/ uses zero toXml calls).\n */\nexport interface BodyContext extends WriteContext {\n /** The root write context with all mutable document state. */\n fileData: DocxWriteContext;\n /** Alias for fileData — some descriptor internals access context.file. */\n file: DocxWriteContext;\n /** Current view wrapper for relationship access. */\n viewWrapper: { relationships: Relationships };\n /** Stringify a body-level child element — injected to break circular imports. */\n stringifyChild: (child: SectionChild, ctx: BodyContext) => string;\n}\n\n// ── DocxWriteContext ──\n\nexport class DocxWriteContext implements WriteContext {\n private _currentRelationshipId = 1;\n\n // --- Accessed by XmlComponent via context.file.* during toXml() ---\n declare public document: { relationships: Relationships };\n declare public numbering: Numbering;\n declare public media: Media;\n declare public charts: ChartCollection;\n declare public smartArts: SmartArtCollection;\n declare public altChunks: AltChunkCollection;\n declare public subDocs: SubDocCollection;\n declare public comments: { relationships: Relationships };\n declare public footNotes: {\n relationships: Relationships;\n notes: Map<number, (ParagraphOptions | string)[]>;\n };\n declare public endnotes: {\n relationships: Relationships;\n notes: Map<number, (ParagraphOptions | string)[]>;\n };\n\n // --- Additional state used by the compiler ---\n declare public fileRelationships: Relationships;\n declare public _settingsOptions: SettingsOptions;\n declare public styles: Styles;\n declare public fontTable: FontWrapper;\n declare public glossaryOptions: GlossaryDocumentOptions | undefined;\n declare public webSettings: WebSettingsOptions | undefined;\n\n // --- Section properties (one per section, raw options for descriptor pipeline) ---\n private _sectionProperties: SectionPropertiesOptions[] = [];\n public get sectionProperties(): readonly SectionPropertiesOptions[] {\n return this._sectionProperties;\n }\n\n // --- WriteContext interface (core descriptor pipeline) ---\n\n public addRelationship(_type: string, _target: string, _mode?: string): string {\n const id = this._currentRelationshipId++;\n return `rId${id}`;\n }\n\n public addMedia(_data: Uint8Array, _type: string): string {\n // DOCX media registration goes through Media.addImage() in compiler.\n return \"\";\n }\n\n // --- Internal tracking ---\n private _headers: HeaderFooterEntry[] = [];\n private _footers: HeaderFooterEntry[] = [];\n\n // --- Original input preserved for descriptor usage ---\n declare public _options: DocumentOptions;\n\n constructor(options: DocumentOptions) {\n this._options = options;\n\n this.numbering = new Numbering(options.numbering ? options.numbering : { config: [] });\n\n this.comments = { relationships: new Relationships() };\n this.fileRelationships = new Relationships();\n this.footNotes = { relationships: new Relationships(), notes: new Map() };\n this.endnotes = { relationships: new Relationships(), notes: new Map() };\n this.document = { relationships: new Relationships() };\n this._settingsOptions = {\n compatibility: options.compatibility,\n compatibilityModeVersion: options.compatabilityModeVersion,\n defaultTabStop: options.defaultTabStop,\n evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,\n characterSpacingControl: options.characterSpacingControl,\n hyphenation: {\n autoHyphenation: options.hyphenation?.autoHyphenation,\n consecutiveHyphenLimit: options.hyphenation?.consecutiveHyphenLimit,\n doNotHyphenateCaps: options.hyphenation?.doNotHyphenateCaps,\n hyphenationZone: options.hyphenation?.hyphenationZone,\n },\n trackRevisions: options.features?.trackRevisions,\n updateFields: options.features?.updateFields,\n documentProtection: options.features?.documentProtection,\n view: options.view,\n zoom: options.zoom,\n writeProtection: options.writeProtection,\n displayBackgroundShape:\n options.displayBackgroundShape ?? (options.background?.image ? true : undefined),\n embedTrueTypeFonts: options.embedTrueTypeFonts,\n embedSystemFonts: options.embedSystemFonts,\n saveSubsetFonts: options.saveSubsetFonts,\n docVars: options.docVars,\n colorSchemeMapping: options.colorSchemeMapping,\n mailMerge: options.mailMerge,\n ...options.settings,\n };\n\n this.media = new Media();\n this.charts = new ChartCollection();\n this.smartArts = new SmartArtCollection();\n this.altChunks = new AltChunkCollection();\n this.subDocs = new SubDocCollection();\n\n if (options.externalStyles !== undefined) {\n const defaultFactory = new DefaultStylesFactory();\n const defaultStyles = defaultFactory.newInstance(options.styles?.default);\n const externalFactory = new ExternalStylesFactory();\n const externalStyles = externalFactory.newInstance(options.externalStyles);\n // Skip docDefaults AND latentStyles from default factory —\n // external styles already provide them; XSD requires docDefaults → latentStyles → style sequence\n const defaultStyleElements = defaultStyles.importedStyles!.slice(2);\n this.styles = new Styles({\n ...externalStyles,\n importedStyles: [...externalStyles.importedStyles!, ...defaultStyleElements],\n });\n } else if (options.styles) {\n const stylesFactory = new DefaultStylesFactory();\n const defaultStyles = stylesFactory.newInstance(options.styles.default);\n // importedStyles[0]=docDefaults, [1]=latentStyles, [2+]=builtin styles.\n // paragraphStyles/characterStyles stay available for numbering registration\n // below but are NOT emitted when round-tripping (the raw importedStyles\n // already carry every source style — emitting both would duplicate them).\n const {\n importedStyles: parsedStyles,\n paragraphStyles,\n characterStyles,\n ...restStyles\n } = options.styles;\n const merged = defaultStyles.importedStyles ? [...defaultStyles.importedStyles] : [];\n if (restStyles.docDefaultsXml) {\n const ddIdx = merged.findIndex((s) => s._raw.startsWith(\"<w:docDefaults\"));\n if (ddIdx >= 0) merged[ddIdx] = { _raw: restStyles.docDefaultsXml };\n }\n if (restStyles.latentStylesXml) {\n const latentIdx = merged.findIndex((s) => s._raw.startsWith(\"<w:latentStyles\"));\n if (latentIdx >= 0) merged[latentIdx] = { _raw: restStyles.latentStylesXml };\n }\n if (parsedStyles && parsedStyles.length > 0) {\n // Round-trip: emit verbatim source styles (suppress factory builtins\n // and structured re-emission).\n merged.splice(2);\n merged.push(...parsedStyles);\n this.styles = new Styles({ ...defaultStyles, importedStyles: merged, ...restStyles });\n } else {\n // Generation: factory builtins + structured custom styles.\n this.styles = new Styles({\n ...defaultStyles,\n paragraphStyles,\n characterStyles,\n ...restStyles,\n });\n }\n } else {\n const stylesFactory = new DefaultStylesFactory();\n this.styles = new Styles(stylesFactory.newInstance());\n }\n\n // Register numbering references from custom paragraph/character styles.\n // Style definitions may contain numbering properties whose concrete instances\n // are never created through the body paragraph processing path.\n if (options.styles?.paragraphStyles) {\n for (const style of options.styles.paragraphStyles) {\n const num = style.paragraph?.numbering;\n if (num) {\n this.numbering.createConcreteNumberingInstance(num.reference, num.instance ?? 0);\n }\n }\n }\n\n this.addDefaultRelationships();\n\n for (const section of options.sections) {\n this.addSection(section);\n }\n\n if (options.footnotes) {\n for (const key in options.footnotes) {\n this.footNotes.notes.set(parseFloat(key), options.footnotes[key].children);\n }\n }\n\n if (options.endnotes) {\n for (const key in options.endnotes) {\n this.endnotes.notes.set(parseFloat(key), options.endnotes[key].children);\n }\n }\n\n this.fontTable = new FontWrapper(options.fonts ?? []);\n this.glossaryOptions = options.glossary;\n this.webSettings = options.webSettings ?? undefined;\n\n if (options.glossary) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument\",\n \"glossary/document.xml\",\n );\n }\n\n if (this.webSettings) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings\",\n \"webSettings.xml\",\n );\n }\n }\n\n get headers(): HeaderFooterEntry[] {\n return this._headers;\n }\n\n get footers(): HeaderFooterEntry[] {\n return this._footers;\n }\n\n // --- Private helpers ---\n\n private addSection({ headers = {}, footers = {}, properties }: SectionOptions): void {\n const sectPrOptions: SectionPropertiesOptions = {\n ...properties,\n footerWrapperGroup: {\n default: footers.default ? this.createFooter(footers.default) : undefined,\n even: footers.even ? this.createFooter(footers.even) : undefined,\n first: footers.first ? this.createFooter(footers.first) : undefined,\n },\n headerWrapperGroup: {\n default: headers.default ? this.createHeader(headers.default) : undefined,\n even: headers.even ? this.createHeader(headers.even) : undefined,\n first: headers.first ? this.createHeader(headers.first) : undefined,\n },\n };\n this._sectionProperties.push(sectPrOptions);\n }\n\n private createHeader(header: SectionChild[]): HeaderFooterEntry {\n const referenceId = this._currentRelationshipId++;\n const entry: HeaderFooterEntry = {\n children: header,\n relationships: new Relationships(),\n referenceId,\n };\n this.addHeaderToDocument(entry);\n return entry;\n }\n\n private createFooter(footer: SectionChild[]): HeaderFooterEntry {\n const referenceId = this._currentRelationshipId++;\n const entry: HeaderFooterEntry = {\n children: footer,\n relationships: new Relationships(),\n referenceId,\n };\n this.addFooterToDocument(entry);\n return entry;\n }\n\n private addHeaderToDocument(header: HeaderFooterEntry): void {\n this._headers.push(header);\n this.document.relationships.addRelationship(\n header.referenceId,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header\",\n `header${this._headers.length}.xml`,\n );\n }\n\n private addFooterToDocument(footer: HeaderFooterEntry): void {\n this._footers.push(footer);\n this.document.relationships.addRelationship(\n footer.referenceId,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer\",\n `footer${this._footers.length}.xml`,\n );\n }\n\n private addDefaultRelationships(): void {\n this.fileRelationships.addRelationship(\n 1,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\",\n \"word/document.xml\",\n );\n this.fileRelationships.addRelationship(\n 2,\n \"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\",\n \"docProps/core.xml\",\n );\n this.fileRelationships.addRelationship(\n 3,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\",\n \"docProps/app.xml\",\n );\n this.fileRelationships.addRelationship(\n 4,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties\",\n \"docProps/custom.xml\",\n );\n\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\",\n \"styles.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering\",\n \"numbering.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes\",\n \"footnotes.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes\",\n \"endnotes.xml\",\n );\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\",\n \"settings.xml\",\n );\n // Comments is an optional part — only wire the document→comments relationship\n // when the document actually carries comments. Emitting it unconditionally\n // produces an orphan comments.xml that Word rejects as an OPC violation\n // (empty part with no [Content_Types] Override when content types are\n // passed through from the source on round-trip).\n if (this._options.comments?.children?.length) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments\",\n \"comments.xml\",\n );\n }\n if (this._options.bibliography) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography\",\n \"bibliography.xml\",\n );\n }\n\n // Theme — a raw-passthrough part. Only declare the document→theme\n // relationship when the source carried one, so Word can resolve theme\n // colors/fonts. Without it theme1.xml is an orphan part Word may reject.\n const themePart = this._options.rawParts?.find((p) => p.path.startsWith(\"word/theme/\"));\n if (themePart) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\",\n themePart.path.replace(/^word\\//, \"\"),\n );\n }\n\n // customXml storage — raw-passthrough parts. Declare the document→customXml\n // relationship for each item (itemProps are linked via the item's own .rels,\n // not directly by the document) so Word can bind cover-page metadata, etc.\n for (const part of this._options.rawParts ?? []) {\n if (\n part.path.startsWith(\"customXml/\") &&\n part.path.endsWith(\".xml\") &&\n !part.path.includes(\"/_rels/\") &&\n !part.path.includes(\"itemProps\")\n ) {\n this.document.relationships.addRelationship(\n this._currentRelationshipId++,\n \"http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml\",\n `../${part.path}`,\n );\n }\n }\n }\n}\n\n// ── DocxReadContext ──\n\n/**\n * DOCX-specific read context.\n *\n * Holds references to the parsed DocxDocument and cached style/numbering data\n * used throughout the DOCX parsing pipeline. Implements ReadContext for\n * descriptor pipeline compatibility.\n */\nexport class DocxReadContext implements ReadContext {\n /**\n * Path of the part currently being parsed. Each part carries its own .rels\n * with independent rId numbering, so drawings inside a part must resolve\n * image relationships against that part's rels. Defaults to the document body.\n */\n public currentPart = \"word/document.xml\";\n\n constructor(\n public docx: DocxDocument,\n public styleCache: Map<string, Element>,\n public numberingCache: Map<string, Element>,\n ) {}\n\n resolveRelationship(rId: string): string | undefined {\n const partMedia = this.docx.partRefs.partMedia.get(this.currentPart);\n if (partMedia) {\n const media = partMedia.get(rId);\n if (media) return media;\n }\n return (\n this.docx.partRefs.headers.get(rId) ??\n this.docx.partRefs.footers.get(rId) ??\n this.docx.partRefs.media.get(rId) ??\n this.docx.partRefs.charts.get(rId) ??\n this.docx.partRefs.diagramData.get(rId) ??\n this.docx.partRefs.afChunks.get(rId) ??\n this.docx.partRefs.subDocs.get(rId) ??\n this.docx.partRefs.hyperlinks.get(rId)\n );\n }\n\n /**\n * Run `fn` with `currentPart` temporarily set to `partPath`, restoring the\n * previous value afterwards. Use when parsing a sub-document part (header,\n * footer, footnotes, …) so its drawings resolve images from its own rels.\n */\n withPart<T>(partPath: string, fn: () => T): T {\n const prev = this.currentPart;\n this.currentPart = partPath;\n try {\n return fn();\n } finally {\n this.currentPart = prev;\n }\n }\n\n getPart(path: string): Element | undefined {\n return this.docx.doc.get(path);\n }\n\n getRaw(path: string): Uint8Array | undefined {\n return this.docx.doc.getRaw(path);\n }\n}\n"],"mappings":";;;;;;;;;;;;AA4BA,IAAa,qBAAb,MAAgC;CAC9B;CAEA,cAAqB;EACnB,KAAK,sBAAM,IAAI,IAA0B;CAC3C;CAEA,YAAmB,KAAa,MAA0B;EACxD,KAAK,IAAI,IAAI,KAAK,IAAI;CACxB;CAEA,IAAW,QAAwB;EACjC,OAAO,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC;CAC9B;AACF;;;;;;ACvBA,IAAa,mBAAb,MAA8B;CAC5B;CAEA,cAAqB;EACnB,KAAK,sBAAM,IAAI,IAAwB;CACzC;CAEA,UAAiB,KAAa,MAAwB;EACpD,KAAK,IAAI,IAAI,KAAK,IAAI;CACxB;CAEA,IAAW,QAAsB;EAC/B,OAAO,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC;CAC9B;AACF;;;;;;;;;;;;;;;;;;;ACZA,IAAa,wBAAb,MAAmC;;;;;;CAMjC,YAAmB,SAAgC;EACjD,MAAM,SAAS,OAAO,SAAS,EAAE,SAAS,MAAM,CAAC;EAEjD,IAAI;EACJ,KAAK,MAAM,UAAU,OAAO,YAAY,CAAC,GACvC,IAAI,OAAO,SAAS,YAClB,mBAAmB;EAIvB,IAAI,qBAAqB,KAAA,GACvB,OAAO;GAAE,gBAAgB,CAAC;GAAG,mBAAmB,CAAC;EAAE;EAKrD,OAAO;GACL,iBAHqB,iBAAiB,YAAY,CAAC,GAGpB,KAAK,cAAc,EAChD,MAAM,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,EACvC,EAAE;GACF,mBAAoB,iBAAiB,cAAyC,CAAC;EACjF;CACF;AACF;;;;;;;;;;;ACUA,IAAa,mBAAb,MAAsD;CACpD,yBAAiC;CA6BjC,qBAAyD,CAAC;CAC1D,IAAW,oBAAyD;EAClE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