@office-open/docx 0.6.2 → 0.6.4
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/dist/index.d.mts +125 -134
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +838 -389
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as __toCommonJS, n as __exportAll, r as __reExport, t as __esmMin } from "./chunk-090QGkrx.mjs";
|
|
2
|
-
import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, EMPTY_OBJECT, EmptyElement, Formatter, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, OoxmlMimeType, PrettifyType, RawPassthrough, Relationships, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, attrObj, chartAttr, convertEmuToPixels, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, createDefault, createOverride, createPacker, getReferencedMedia, hasPlaceholders, hashedId, hpsMeasureObj, hpsMeasureObj as hpsMeasureObj$1, numberValObj, numberValObj as numberValObj$1, onOffObj, onOffObj as onOffObj$1, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, strFromU8, stringContainerObj, stringEnumValObj, stringEnumValObj as stringEnumValObj$1, stringValObj, stringValObj as stringValObj$1, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipSync, wrapEl, zipAndConvert } from "@office-open/core";
|
|
2
|
+
import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, EMPTY_OBJECT, EmptyElement, Formatter, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, OoxmlMimeType, PrettifyType, RawPassthrough, Relationships, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, attrObj, chartAttr, convertEmuToPixels, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, createDefault, createOverride, createPacker, getReferencedMedia, hasPlaceholders, hashedId, hpsMeasureObj, hpsMeasureObj as hpsMeasureObj$1, numberValObj, numberValObj as numberValObj$1, onOffObj, onOffObj as onOffObj$1, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, strFromU8, stringContainerObj, stringEnumValObj, stringEnumValObj as stringEnumValObj$1, stringValObj, stringValObj as stringValObj$1, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipSync, wrapEl, xsdVerticalMergeRev, zipAndConvert } from "@office-open/core";
|
|
3
3
|
import { textToUint8Array, toUint8Array } from "undio";
|
|
4
4
|
import { PresetGeometry, buildFill, createBlipFill, createCustomGeometry, createEffectDag, createEffectList, createOutline, createScene3D, createShape3D, createTransform2D, extractBlipFillMedia } from "@office-open/core/drawingml";
|
|
5
5
|
import { ChartCollection, ChartSpace } from "@office-open/core/chart";
|
|
@@ -1755,7 +1755,7 @@ var init_shape_properties = __esmMin((() => {
|
|
|
1755
1755
|
}
|
|
1756
1756
|
prepForXml(context) {
|
|
1757
1757
|
const media = this.fillOptions ? extractBlipFillMedia(this.fillOptions) : void 0;
|
|
1758
|
-
if (media) context.file.
|
|
1758
|
+
if (media) context.file.media.addImage(media.fileName, {
|
|
1759
1759
|
data: media.data,
|
|
1760
1760
|
fileName: media.fileName,
|
|
1761
1761
|
type: media.type,
|
|
@@ -2004,9 +2004,12 @@ var init_hyperlink = __esmMin((() => {
|
|
|
2004
2004
|
};
|
|
2005
2005
|
ConcreteHyperlink = class extends XmlComponent {
|
|
2006
2006
|
linkId;
|
|
2007
|
-
constructor(children, relationshipId,
|
|
2007
|
+
constructor(children, relationshipId, options) {
|
|
2008
2008
|
super("w:hyperlink");
|
|
2009
2009
|
this.linkId = relationshipId;
|
|
2010
|
+
const anchor = options?.anchor;
|
|
2011
|
+
const tooltip = options?.tooltip;
|
|
2012
|
+
const tgtFrame = options?.tgtFrame;
|
|
2010
2013
|
const props = {
|
|
2011
2014
|
anchor: anchor ? anchor : void 0,
|
|
2012
2015
|
history: 1,
|
|
@@ -2028,7 +2031,10 @@ var init_hyperlink = __esmMin((() => {
|
|
|
2028
2031
|
};
|
|
2029
2032
|
InternalHyperlink = class extends ConcreteHyperlink {
|
|
2030
2033
|
constructor(options) {
|
|
2031
|
-
super(options.children, uniqueId(),
|
|
2034
|
+
super(options.children, uniqueId(), {
|
|
2035
|
+
anchor: options.anchor,
|
|
2036
|
+
tooltip: options.tooltip
|
|
2037
|
+
});
|
|
2032
2038
|
}
|
|
2033
2039
|
};
|
|
2034
2040
|
ExternalHyperlink = class extends XmlComponent {
|
|
@@ -2074,12 +2080,12 @@ var init_non_visual_properties = __esmMin((() => {
|
|
|
2074
2080
|
if (this.hyperlink) {
|
|
2075
2081
|
if (this.hyperlink.click && !hasStackClick) {
|
|
2076
2082
|
const linkId = uniqueId();
|
|
2077
|
-
context.viewWrapper.
|
|
2083
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.click, TargetModeType.EXTERNAL);
|
|
2078
2084
|
this.root.push(buildHyperlinkClickObj(linkId, false));
|
|
2079
2085
|
}
|
|
2080
2086
|
if (this.hyperlink.hover) {
|
|
2081
2087
|
const linkId = uniqueId();
|
|
2082
|
-
context.viewWrapper.
|
|
2088
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.hover, TargetModeType.EXTERNAL);
|
|
2083
2089
|
this.root.push(buildHyperlinkHoverObj(linkId, false));
|
|
2084
2090
|
}
|
|
2085
2091
|
}
|
|
@@ -2717,12 +2723,12 @@ var init_doc_properties = __esmMin((() => {
|
|
|
2717
2723
|
if (this.hyperlink) {
|
|
2718
2724
|
if (this.hyperlink.click && !hasStackClick) {
|
|
2719
2725
|
const linkId = uniqueId();
|
|
2720
|
-
context.viewWrapper.
|
|
2726
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.click, TargetModeType.EXTERNAL);
|
|
2721
2727
|
this.root.push(buildHyperlinkClickObj(linkId, true));
|
|
2722
2728
|
}
|
|
2723
2729
|
if (this.hyperlink.hover) {
|
|
2724
2730
|
const linkId = uniqueId();
|
|
2725
|
-
context.viewWrapper.
|
|
2731
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.hover, TargetModeType.EXTERNAL);
|
|
2726
2732
|
this.root.push(buildHyperlinkHoverObj(linkId, true));
|
|
2727
2733
|
}
|
|
2728
2734
|
}
|
|
@@ -3004,7 +3010,7 @@ var init_media$1 = __esmMin((() => {
|
|
|
3004
3010
|
*
|
|
3005
3011
|
* @returns Read-only array of all media data in the collection
|
|
3006
3012
|
*/
|
|
3007
|
-
get
|
|
3013
|
+
get array() {
|
|
3008
3014
|
return [...this.map.values()];
|
|
3009
3015
|
}
|
|
3010
3016
|
};
|
|
@@ -3067,8 +3073,8 @@ var init_image_run = __esmMin((() => {
|
|
|
3067
3073
|
this.extraChildren.push(drawing);
|
|
3068
3074
|
}
|
|
3069
3075
|
prepForXml(context) {
|
|
3070
|
-
context.file.
|
|
3071
|
-
if (this.imageData.type === "svg") context.file.
|
|
3076
|
+
context.file.media.addImage(this.imageData.fileName, this.imageData);
|
|
3077
|
+
if (this.imageData.type === "svg") context.file.media.addImage(this.imageData.fallback.fileName, this.imageData.fallback);
|
|
3072
3078
|
return super.prepForXml(context);
|
|
3073
3079
|
}
|
|
3074
3080
|
};
|
|
@@ -3111,7 +3117,7 @@ var init_chart_run = __esmMin((() => {
|
|
|
3111
3117
|
title: this.chartOptions.title,
|
|
3112
3118
|
type: this.chartOptions.type
|
|
3113
3119
|
});
|
|
3114
|
-
context.file.
|
|
3120
|
+
context.file.charts.addChart(this.chartKey, {
|
|
3115
3121
|
chartSpace,
|
|
3116
3122
|
key: this.chartKey
|
|
3117
3123
|
});
|
|
@@ -3168,7 +3174,7 @@ var init_smartart_run = __esmMin((() => {
|
|
|
3168
3174
|
style: styleId,
|
|
3169
3175
|
color: colorId
|
|
3170
3176
|
};
|
|
3171
|
-
context.file.
|
|
3177
|
+
context.file.smartArts.addSmartArt(this.smartArtKey, smartArtData);
|
|
3172
3178
|
return super.prepForXml(context);
|
|
3173
3179
|
}
|
|
3174
3180
|
hashSmartArtData(options) {
|
|
@@ -3236,8 +3242,8 @@ var init_wpg_group_run = __esmMin((() => {
|
|
|
3236
3242
|
}
|
|
3237
3243
|
prepForXml(context) {
|
|
3238
3244
|
this.mediaDatas.forEach((child) => {
|
|
3239
|
-
context.file.
|
|
3240
|
-
if (child.type === "svg") context.file.
|
|
3245
|
+
context.file.media.addImage(child.fileName, child);
|
|
3246
|
+
if (child.type === "svg") context.file.media.addImage(child.fallback.fileName, child.fallback);
|
|
3241
3247
|
});
|
|
3242
3248
|
return super.prepForXml(context);
|
|
3243
3249
|
}
|
|
@@ -3497,12 +3503,9 @@ var init_font_wrapper = __esmMin((() => {
|
|
|
3497
3503
|
this.relationships = new Relationships();
|
|
3498
3504
|
for (let i = 0; i < options.length; i++) this.relationships.addRelationship(i + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font", `fonts/${options[i].name}.odttf`);
|
|
3499
3505
|
}
|
|
3500
|
-
get
|
|
3506
|
+
get view() {
|
|
3501
3507
|
return this.fontTable;
|
|
3502
3508
|
}
|
|
3503
|
-
get Relationships() {
|
|
3504
|
-
return this.relationships;
|
|
3505
|
-
}
|
|
3506
3509
|
};
|
|
3507
3510
|
}));
|
|
3508
3511
|
//#endregion
|
|
@@ -4480,7 +4483,7 @@ var init_math_fraction_properties = __esmMin((() => {
|
|
|
4480
4483
|
if (options.fractionType) children.push(new BuilderElement({
|
|
4481
4484
|
attributes: { val: {
|
|
4482
4485
|
key: "m:val",
|
|
4483
|
-
value:
|
|
4486
|
+
value: options.fractionType
|
|
4484
4487
|
} },
|
|
4485
4488
|
name: "m:type"
|
|
4486
4489
|
}));
|
|
@@ -6281,7 +6284,7 @@ var init_properties = __esmMin((() => {
|
|
|
6281
6284
|
* @returns The prepared XML object, or undefined if the component should be ignored
|
|
6282
6285
|
*/
|
|
6283
6286
|
prepForXml(context) {
|
|
6284
|
-
if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this.numberingReferences) context.file.
|
|
6287
|
+
if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this.numberingReferences) context.file.numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
|
|
6285
6288
|
return super.prepForXml(context);
|
|
6286
6289
|
}
|
|
6287
6290
|
};
|
|
@@ -6340,7 +6343,7 @@ var init_paragraph$1 = __esmMin((() => {
|
|
|
6340
6343
|
prepForXml(context) {
|
|
6341
6344
|
const children = [];
|
|
6342
6345
|
const { xml: pPrObj, numberingReferences } = this._props;
|
|
6343
|
-
if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of numberingReferences) context.file.
|
|
6346
|
+
if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of numberingReferences) context.file.numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
|
|
6344
6347
|
let finalPPrObj = pPrObj;
|
|
6345
6348
|
if (this.sectionProperties) {
|
|
6346
6349
|
const sectPrObj = this.sectionProperties.prepForXml(context);
|
|
@@ -6358,8 +6361,8 @@ var init_paragraph$1 = __esmMin((() => {
|
|
|
6358
6361
|
}
|
|
6359
6362
|
if (this.options.children) for (const rawChild of this.options.children) {
|
|
6360
6363
|
if (rawChild instanceof ExternalHyperlink) {
|
|
6361
|
-
const concreteHyperlink = new ConcreteHyperlink(rawChild.options.children, uniqueId());
|
|
6362
|
-
context.viewWrapper.
|
|
6364
|
+
const concreteHyperlink = new ConcreteHyperlink(rawChild.options.children, uniqueId(), { tooltip: rawChild.options.tooltip });
|
|
6365
|
+
context.viewWrapper.relationships.addRelationship(concreteHyperlink.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", rawChild.options.link, TargetModeType.EXTERNAL);
|
|
6363
6366
|
const obj = concreteHyperlink.prepForXml(context);
|
|
6364
6367
|
if (obj) children.push(obj);
|
|
6365
6368
|
continue;
|
|
@@ -6383,22 +6386,25 @@ var init_paragraph$1 = __esmMin((() => {
|
|
|
6383
6386
|
else if ("image" in rawChild) child = new ImageRun(rawChild.image);
|
|
6384
6387
|
else if (typeof rawChild === "object" && rawChild !== null && "hyperlink" in rawChild) {
|
|
6385
6388
|
const { hyperlink, ...runOpts } = rawChild;
|
|
6386
|
-
const
|
|
6389
|
+
const hlChildren = hyperlink.children;
|
|
6390
|
+
const textRuns = [];
|
|
6391
|
+
if (hlChildren && hlChildren.length > 0) for (const rc of hlChildren) textRuns.push(new TextRun(rc));
|
|
6392
|
+
else textRuns.push(new TextRun(runOpts));
|
|
6387
6393
|
if ("link" in hyperlink) {
|
|
6388
6394
|
const ext = new ExternalHyperlink({
|
|
6389
6395
|
link: hyperlink.link,
|
|
6390
6396
|
tooltip: hyperlink.tooltip,
|
|
6391
|
-
children:
|
|
6397
|
+
children: textRuns
|
|
6392
6398
|
});
|
|
6393
|
-
const concrete = new ConcreteHyperlink(ext.options.children, uniqueId());
|
|
6394
|
-
context.viewWrapper.
|
|
6399
|
+
const concrete = new ConcreteHyperlink(ext.options.children, uniqueId(), { tooltip: ext.options.tooltip });
|
|
6400
|
+
context.viewWrapper.relationships.addRelationship(concrete.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ext.options.link, TargetModeType.EXTERNAL);
|
|
6395
6401
|
const obj = concrete.prepForXml(context);
|
|
6396
6402
|
if (obj) children.push(obj);
|
|
6397
6403
|
} else if ("anchor" in hyperlink) {
|
|
6398
6404
|
const obj = new InternalHyperlink({
|
|
6399
6405
|
anchor: hyperlink.anchor,
|
|
6400
6406
|
tooltip: hyperlink.tooltip,
|
|
6401
|
-
children:
|
|
6407
|
+
children: textRuns
|
|
6402
6408
|
}).prepForXml(context);
|
|
6403
6409
|
if (obj) children.push(obj);
|
|
6404
6410
|
}
|
|
@@ -6414,7 +6420,15 @@ var init_paragraph$1 = __esmMin((() => {
|
|
|
6414
6420
|
else if ("commentRangeStart" in rawChild) child = new CommentRangeStart(rawChild.commentRangeStart);
|
|
6415
6421
|
else if ("commentRangeEnd" in rawChild) child = new CommentRangeEnd(rawChild.commentRangeEnd);
|
|
6416
6422
|
else if ("commentReference" in rawChild) child = new TextRun({ children: [new CommentReference(rawChild.commentReference)] });
|
|
6417
|
-
else if ("
|
|
6423
|
+
else if ("bookmarkStart" in rawChild) {
|
|
6424
|
+
const startObj = new BookmarkStart(rawChild.bookmarkStart.name, rawChild.bookmarkStart.id).prepForXml(context);
|
|
6425
|
+
if (startObj) children.push(startObj);
|
|
6426
|
+
continue;
|
|
6427
|
+
} else if ("bookmarkEnd" in rawChild) {
|
|
6428
|
+
const endObj = new BookmarkEnd(rawChild.bookmarkEnd).prepForXml(context);
|
|
6429
|
+
if (endObj) children.push(endObj);
|
|
6430
|
+
continue;
|
|
6431
|
+
} else if ("insertion" in rawChild) child = new InsertedTextRun(rawChild.insertion);
|
|
6418
6432
|
else if ("deletion" in rawChild) child = new DeletedTextRun(rawChild.deletion);
|
|
6419
6433
|
else child = new TextRun(rawChild);
|
|
6420
6434
|
const obj = child.prepForXml(context);
|
|
@@ -6511,9 +6525,6 @@ var init_comment_run = __esmMin((() => {
|
|
|
6511
6525
|
for (const child of children) this.root.push(new Comment(child));
|
|
6512
6526
|
this.relationships = new Relationships();
|
|
6513
6527
|
}
|
|
6514
|
-
get Relationships() {
|
|
6515
|
-
return this.relationships;
|
|
6516
|
-
}
|
|
6517
6528
|
};
|
|
6518
6529
|
}));
|
|
6519
6530
|
//#endregion
|
|
@@ -6677,7 +6688,7 @@ var init_ruby = __esmMin((() => {
|
|
|
6677
6688
|
name
|
|
6678
6689
|
});
|
|
6679
6690
|
createRuby = (options) => {
|
|
6680
|
-
const align = options.alignment ?? "
|
|
6691
|
+
const align = options.alignment ?? "center";
|
|
6681
6692
|
const hps = options.fontSize ?? 20;
|
|
6682
6693
|
const hpsRaise = options.raise ?? 20;
|
|
6683
6694
|
const hpsBaseText = options.baseFontSize ?? 40;
|
|
@@ -6688,7 +6699,7 @@ var init_ruby = __esmMin((() => {
|
|
|
6688
6699
|
new BuilderElement({
|
|
6689
6700
|
attributes: { val: {
|
|
6690
6701
|
key: "w:val",
|
|
6691
|
-
value:
|
|
6702
|
+
value: align
|
|
6692
6703
|
} },
|
|
6693
6704
|
name: "w:rubyAlign"
|
|
6694
6705
|
}),
|
|
@@ -6850,15 +6861,15 @@ var init_alt_chunk = __esmMin((() => {
|
|
|
6850
6861
|
const partPath = `afchunks/afchunk${relId}.${extension}`;
|
|
6851
6862
|
const rawData = typeof this.options.data === "string" ? new TextEncoder().encode(this.options.data) : this.options.data;
|
|
6852
6863
|
const data = this.options.contentType === "text/html" && typeof this.options.data === "string" ? new TextEncoder().encode(wrapHtmlDocument(this.options.data)) : rawData;
|
|
6853
|
-
context.viewWrapper.
|
|
6854
|
-
context.file.
|
|
6864
|
+
context.viewWrapper.relationships.addRelationship(relId, ALTCHUNK_RELATIONSHIP_TYPE, partPath);
|
|
6865
|
+
context.file.altChunks.addAltChunk(relId, {
|
|
6855
6866
|
key: relId,
|
|
6856
6867
|
data,
|
|
6857
6868
|
path: partPath,
|
|
6858
6869
|
extension,
|
|
6859
6870
|
contentType: this.options.contentType
|
|
6860
6871
|
});
|
|
6861
|
-
context.file.
|
|
6872
|
+
context.file.contentTypes.addAltChunk(`/word/${partPath}`, this.options.contentType, extension);
|
|
6862
6873
|
return super.prepForXml(context);
|
|
6863
6874
|
}
|
|
6864
6875
|
};
|
|
@@ -7243,12 +7254,12 @@ var init_sub_doc = __esmMin((() => {
|
|
|
7243
7254
|
const partPath = `subdocs/subdoc${relId}.docx`;
|
|
7244
7255
|
this.root.splice(0, 0, { _attr: { "r:id": `rId${relId}` } });
|
|
7245
7256
|
const data = typeof this.options.data === "string" ? new TextEncoder().encode(this.options.data) : this.options.data;
|
|
7246
|
-
context.viewWrapper.
|
|
7247
|
-
context.file.
|
|
7257
|
+
context.viewWrapper.relationships.addRelationship(relId, SUBDOC_RELATIONSHIP_TYPE, partPath);
|
|
7258
|
+
context.file.subDocs.addSubDoc(relId, {
|
|
7248
7259
|
data,
|
|
7249
7260
|
path: partPath
|
|
7250
7261
|
});
|
|
7251
|
-
context.file.
|
|
7262
|
+
context.file.contentTypes.addSubDoc(`/word/${partPath}`);
|
|
7252
7263
|
return super.prepForXml(context);
|
|
7253
7264
|
}
|
|
7254
7265
|
};
|
|
@@ -7452,8 +7463,8 @@ function buildCellMergeObj(options) {
|
|
|
7452
7463
|
"w:date": options.date,
|
|
7453
7464
|
"w:id": options.id
|
|
7454
7465
|
};
|
|
7455
|
-
if (options.verticalMerge !== void 0) attrs["w:vMerge"] = options.verticalMerge;
|
|
7456
|
-
if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = options.verticalMergeOriginal;
|
|
7466
|
+
if (options.verticalMerge !== void 0) attrs["w:vMerge"] = xsdVerticalMergeRev.to(options.verticalMerge);
|
|
7467
|
+
if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = xsdVerticalMergeRev.to(options.verticalMergeOriginal);
|
|
7457
7468
|
return { "w:cellMerge": { _attr: attrs } };
|
|
7458
7469
|
}
|
|
7459
7470
|
var VerticalMergeRevisionType, CellMerge;
|
|
@@ -7463,11 +7474,11 @@ var init_cell_merge = __esmMin((() => {
|
|
|
7463
7474
|
/**
|
|
7464
7475
|
* Cell that is merged with upper one.
|
|
7465
7476
|
*/
|
|
7466
|
-
CONTINUE: "
|
|
7477
|
+
CONTINUE: "continue",
|
|
7467
7478
|
/**
|
|
7468
7479
|
* Cell that is starting the vertical merge.
|
|
7469
7480
|
*/
|
|
7470
|
-
RESTART: "
|
|
7481
|
+
RESTART: "restart"
|
|
7471
7482
|
};
|
|
7472
7483
|
CellMerge = class extends XmlComponent {
|
|
7473
7484
|
constructor(options) {
|
|
@@ -7477,8 +7488,8 @@ var init_cell_merge = __esmMin((() => {
|
|
|
7477
7488
|
"w:date": options.date,
|
|
7478
7489
|
"w:id": options.id
|
|
7479
7490
|
};
|
|
7480
|
-
if (options.verticalMerge !== void 0) attrs["w:vMerge"] = options.verticalMerge;
|
|
7481
|
-
if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = options.verticalMergeOriginal;
|
|
7491
|
+
if (options.verticalMerge !== void 0) attrs["w:vMerge"] = xsdVerticalMergeRev.to(options.verticalMerge);
|
|
7492
|
+
if (options.verticalMergeOriginal !== void 0) attrs["w:vMergeOrig"] = xsdVerticalMergeRev.to(options.verticalMergeOriginal);
|
|
7482
7493
|
this.root.push({ _attr: attrs });
|
|
7483
7494
|
}
|
|
7484
7495
|
};
|
|
@@ -8270,7 +8281,7 @@ var init_table_row$1 = __esmMin((() => {
|
|
|
8270
8281
|
this.options = options;
|
|
8271
8282
|
this.coercedChildren = options.children.map((child) => child instanceof TableCell || child instanceof StructuredDocumentTagCell || child instanceof StructuredDocumentTagRow ? child : new TableCell(child));
|
|
8272
8283
|
}
|
|
8273
|
-
get
|
|
8284
|
+
get cellCount() {
|
|
8274
8285
|
return this.coercedChildren.length;
|
|
8275
8286
|
}
|
|
8276
8287
|
get cells() {
|
|
@@ -8531,8 +8542,8 @@ var init_sdt_row = __esmMin((() => {
|
|
|
8531
8542
|
this.root.push(content);
|
|
8532
8543
|
}
|
|
8533
8544
|
}
|
|
8534
|
-
get
|
|
8535
|
-
return Math.max(...this.rows.map((r) => r.
|
|
8545
|
+
get cellCount() {
|
|
8546
|
+
return Math.max(...this.rows.map((r) => r.cellCount), 0);
|
|
8536
8547
|
}
|
|
8537
8548
|
get cells() {
|
|
8538
8549
|
return this.rows.flatMap((r) => r.cells);
|
|
@@ -8596,7 +8607,7 @@ var init_table = __esmMin((() => {
|
|
|
8596
8607
|
super("w:tbl");
|
|
8597
8608
|
this.options = options;
|
|
8598
8609
|
this.rows = options.rows.map((row) => row instanceof TableRow || row instanceof StructuredDocumentTagRow ? row : new TableRow(row));
|
|
8599
|
-
this.columnWidths = options.columnWidths ?? Array(Math.max(...this.rows.map((row) => row.
|
|
8610
|
+
this.columnWidths = options.columnWidths ?? Array(Math.max(...this.rows.map((row) => row.cellCount))).fill(100);
|
|
8600
8611
|
this.rows.forEach((row, rowIndex) => {
|
|
8601
8612
|
if (rowIndex === this.rows.length - 1) return;
|
|
8602
8613
|
if (!(row instanceof TableRow)) return;
|
|
@@ -8834,7 +8845,7 @@ var AltChunkCollection = class {
|
|
|
8834
8845
|
addAltChunk(key, data) {
|
|
8835
8846
|
this.map.set(key, data);
|
|
8836
8847
|
}
|
|
8837
|
-
get
|
|
8848
|
+
get array() {
|
|
8838
8849
|
return [...this.map.values()];
|
|
8839
8850
|
}
|
|
8840
8851
|
};
|
|
@@ -8937,9 +8948,6 @@ var Bibliography = class extends XmlComponent {
|
|
|
8937
8948
|
for (const source of options.sources) this.root.push(new Source(source));
|
|
8938
8949
|
this.relationships = new Relationships();
|
|
8939
8950
|
}
|
|
8940
|
-
get Relationships() {
|
|
8941
|
-
return this.relationships;
|
|
8942
|
-
}
|
|
8943
8951
|
};
|
|
8944
8952
|
//#endregion
|
|
8945
8953
|
//#region src/file/content-types/content-types.ts
|
|
@@ -10312,15 +10320,15 @@ var SectionProperties = class extends XmlComponent {
|
|
|
10312
10320
|
}
|
|
10313
10321
|
addHeaderFooterGroup(type, group) {
|
|
10314
10322
|
if (group.default) this.root.push(createHeaderFooterReference(type, {
|
|
10315
|
-
id: group.default.
|
|
10323
|
+
id: group.default.view.referenceId,
|
|
10316
10324
|
type: HeaderFooterReferenceType.DEFAULT
|
|
10317
10325
|
}));
|
|
10318
10326
|
if (group.first) this.root.push(createHeaderFooterReference(type, {
|
|
10319
|
-
id: group.first.
|
|
10327
|
+
id: group.first.view.referenceId,
|
|
10320
10328
|
type: HeaderFooterReferenceType.FIRST
|
|
10321
10329
|
}));
|
|
10322
10330
|
if (group.even) this.root.push(createHeaderFooterReference(type, {
|
|
10323
|
-
id: group.even.
|
|
10331
|
+
id: group.even.view.referenceId,
|
|
10324
10332
|
type: HeaderFooterReferenceType.EVEN
|
|
10325
10333
|
}));
|
|
10326
10334
|
}
|
|
@@ -10535,7 +10543,7 @@ var DocumentBackground = class extends XmlComponent {
|
|
|
10535
10543
|
}
|
|
10536
10544
|
prepForXml(context) {
|
|
10537
10545
|
if (this.imageData) {
|
|
10538
|
-
context.file.
|
|
10546
|
+
context.file.media.addImage(this.imageData.fileName, {
|
|
10539
10547
|
type: this.imageData.type,
|
|
10540
10548
|
data: this.imageData.data,
|
|
10541
10549
|
fileName: this.imageData.fileName,
|
|
@@ -10685,14 +10693,6 @@ var Document = class extends XmlComponent {
|
|
|
10685
10693
|
this.body.push(item);
|
|
10686
10694
|
return this;
|
|
10687
10695
|
}
|
|
10688
|
-
/**
|
|
10689
|
-
* Gets the document body element.
|
|
10690
|
-
*
|
|
10691
|
-
* @returns The Body instance containing all document content
|
|
10692
|
-
*/
|
|
10693
|
-
get Body() {
|
|
10694
|
-
return this.body;
|
|
10695
|
-
}
|
|
10696
10696
|
};
|
|
10697
10697
|
//#endregion
|
|
10698
10698
|
//#region src/file/document-wrapper.ts
|
|
@@ -10729,12 +10729,9 @@ var DocumentWrapper = class {
|
|
|
10729
10729
|
this.document = new Document(options);
|
|
10730
10730
|
this.relationships = new Relationships();
|
|
10731
10731
|
}
|
|
10732
|
-
get
|
|
10732
|
+
get view() {
|
|
10733
10733
|
return this.document;
|
|
10734
10734
|
}
|
|
10735
|
-
get Relationships() {
|
|
10736
|
-
return this.relationships;
|
|
10737
|
-
}
|
|
10738
10735
|
};
|
|
10739
10736
|
//#endregion
|
|
10740
10737
|
//#region src/file/footnotes/footnote/run/continuation-seperator.ts
|
|
@@ -10914,12 +10911,9 @@ var EndnotesWrapper = class {
|
|
|
10914
10911
|
this.endnotes = new Endnotes();
|
|
10915
10912
|
this.relationships = new Relationships();
|
|
10916
10913
|
}
|
|
10917
|
-
get
|
|
10914
|
+
get view() {
|
|
10918
10915
|
return this.endnotes;
|
|
10919
10916
|
}
|
|
10920
|
-
get Relationships() {
|
|
10921
|
-
return this.relationships;
|
|
10922
|
-
}
|
|
10923
10917
|
};
|
|
10924
10918
|
//#endregion
|
|
10925
10919
|
//#region src/file/header-footer-base.ts
|
|
@@ -10993,7 +10987,7 @@ var HeaderFooterBase = class extends InitializableXmlComponent {
|
|
|
10993
10987
|
this.refId = referenceNumber;
|
|
10994
10988
|
if (!initContent) this.root.push(buildDocumentAttributes(namespaces));
|
|
10995
10989
|
}
|
|
10996
|
-
get
|
|
10990
|
+
get referenceId() {
|
|
10997
10991
|
return this.refId;
|
|
10998
10992
|
}
|
|
10999
10993
|
add(item) {
|
|
@@ -11069,6 +11063,7 @@ init_relationships();
|
|
|
11069
11063
|
var FooterWrapper = class {
|
|
11070
11064
|
footer;
|
|
11071
11065
|
relationships;
|
|
11066
|
+
media;
|
|
11072
11067
|
constructor(media, referenceId, initContent) {
|
|
11073
11068
|
this.media = media;
|
|
11074
11069
|
this.footer = new Footer$1(referenceId, initContent);
|
|
@@ -11080,15 +11075,9 @@ var FooterWrapper = class {
|
|
|
11080
11075
|
addChildElement(childElement) {
|
|
11081
11076
|
this.footer.addChildElement(childElement);
|
|
11082
11077
|
}
|
|
11083
|
-
get
|
|
11078
|
+
get view() {
|
|
11084
11079
|
return this.footer;
|
|
11085
11080
|
}
|
|
11086
|
-
get Relationships() {
|
|
11087
|
-
return this.relationships;
|
|
11088
|
-
}
|
|
11089
|
-
get Media() {
|
|
11090
|
-
return this.media;
|
|
11091
|
-
}
|
|
11092
11081
|
};
|
|
11093
11082
|
//#endregion
|
|
11094
11083
|
//#region src/file/footnotes/footnote/run/footnote-ref.ts
|
|
@@ -11313,22 +11302,19 @@ init_relationships();
|
|
|
11313
11302
|
* @example
|
|
11314
11303
|
* ```typescript
|
|
11315
11304
|
* const wrapper = new FootnotesWrapper();
|
|
11316
|
-
* const footnotes = wrapper.
|
|
11317
|
-
* const relationships = wrapper.
|
|
11305
|
+
* const footnotes = wrapper.view;
|
|
11306
|
+
* const relationships = wrapper.relationships;
|
|
11318
11307
|
* ```
|
|
11319
11308
|
*/
|
|
11320
11309
|
var FootnotesWrapper = class {
|
|
11321
|
-
|
|
11310
|
+
footnotes;
|
|
11322
11311
|
relationships;
|
|
11323
11312
|
constructor() {
|
|
11324
|
-
this.
|
|
11313
|
+
this.footnotes = new FootNotes();
|
|
11325
11314
|
this.relationships = new Relationships();
|
|
11326
11315
|
}
|
|
11327
|
-
get
|
|
11328
|
-
return this.
|
|
11329
|
-
}
|
|
11330
|
-
get Relationships() {
|
|
11331
|
-
return this.relationships;
|
|
11316
|
+
get view() {
|
|
11317
|
+
return this.footnotes;
|
|
11332
11318
|
}
|
|
11333
11319
|
};
|
|
11334
11320
|
//#endregion
|
|
@@ -11445,6 +11431,7 @@ init_relationships();
|
|
|
11445
11431
|
var HeaderWrapper = class {
|
|
11446
11432
|
header;
|
|
11447
11433
|
relationships;
|
|
11434
|
+
media;
|
|
11448
11435
|
constructor(media, referenceId, initContent) {
|
|
11449
11436
|
this.media = media;
|
|
11450
11437
|
this.header = new Header$1(referenceId, initContent);
|
|
@@ -11457,15 +11444,9 @@ var HeaderWrapper = class {
|
|
|
11457
11444
|
addChildElement(childElement) {
|
|
11458
11445
|
this.header.addChildElement(childElement);
|
|
11459
11446
|
}
|
|
11460
|
-
get
|
|
11447
|
+
get view() {
|
|
11461
11448
|
return this.header;
|
|
11462
11449
|
}
|
|
11463
|
-
get Relationships() {
|
|
11464
|
-
return this.relationships;
|
|
11465
|
-
}
|
|
11466
|
-
get Media() {
|
|
11467
|
-
return this.media;
|
|
11468
|
-
}
|
|
11469
11450
|
};
|
|
11470
11451
|
//#endregion
|
|
11471
11452
|
//#region src/file/numbering/level.ts
|
|
@@ -12286,7 +12267,7 @@ var Numbering = class extends XmlComponent {
|
|
|
12286
12267
|
*
|
|
12287
12268
|
* @returns An array of all concrete numbering instances
|
|
12288
12269
|
*/
|
|
12289
|
-
get
|
|
12270
|
+
get concreteNumbering() {
|
|
12290
12271
|
return [...this.concreteNumberingMap.values()];
|
|
12291
12272
|
}
|
|
12292
12273
|
/**
|
|
@@ -12294,7 +12275,7 @@ var Numbering = class extends XmlComponent {
|
|
|
12294
12275
|
*
|
|
12295
12276
|
* @returns An array of all numbering reference configurations
|
|
12296
12277
|
*/
|
|
12297
|
-
get
|
|
12278
|
+
get referenceConfig() {
|
|
12298
12279
|
return [...this.referenceConfigMap.values()];
|
|
12299
12280
|
}
|
|
12300
12281
|
};
|
|
@@ -13570,7 +13551,7 @@ var SubDocCollection = class {
|
|
|
13570
13551
|
addSubDoc(key, data) {
|
|
13571
13552
|
this.map.set(key, data);
|
|
13572
13553
|
}
|
|
13573
|
-
get
|
|
13554
|
+
get array() {
|
|
13574
13555
|
return [...this.map.values()];
|
|
13575
13556
|
}
|
|
13576
13557
|
};
|
|
@@ -13664,10 +13645,10 @@ init_relationships();
|
|
|
13664
13645
|
* ```
|
|
13665
13646
|
*/
|
|
13666
13647
|
var File = class {
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13648
|
+
_currentRelationshipId = 1;
|
|
13649
|
+
document;
|
|
13650
|
+
_headers = [];
|
|
13651
|
+
_footers = [];
|
|
13671
13652
|
coreProperties;
|
|
13672
13653
|
numbering;
|
|
13673
13654
|
media;
|
|
@@ -13676,8 +13657,8 @@ var File = class {
|
|
|
13676
13657
|
altChunks;
|
|
13677
13658
|
subDocs;
|
|
13678
13659
|
fileRelationships;
|
|
13679
|
-
|
|
13680
|
-
|
|
13660
|
+
footNotes;
|
|
13661
|
+
endnotes;
|
|
13681
13662
|
settings;
|
|
13682
13663
|
contentTypes;
|
|
13683
13664
|
customProperties;
|
|
@@ -13685,7 +13666,7 @@ var File = class {
|
|
|
13685
13666
|
styles;
|
|
13686
13667
|
comments;
|
|
13687
13668
|
bibliography;
|
|
13688
|
-
|
|
13669
|
+
fontTable;
|
|
13689
13670
|
constructor(options) {
|
|
13690
13671
|
this.coreProperties = new CoreProperties({
|
|
13691
13672
|
...options,
|
|
@@ -13699,10 +13680,10 @@ var File = class {
|
|
|
13699
13680
|
this.fileRelationships = new Relationships();
|
|
13700
13681
|
this.customProperties = new CustomProperties(options.customProperties ?? []);
|
|
13701
13682
|
this.appProperties = new AppProperties();
|
|
13702
|
-
this.
|
|
13703
|
-
this.
|
|
13683
|
+
this.footNotes = new FootnotesWrapper();
|
|
13684
|
+
this.endnotes = new EndnotesWrapper();
|
|
13704
13685
|
this.contentTypes = new ContentTypes();
|
|
13705
|
-
this.
|
|
13686
|
+
this.document = new DocumentWrapper({ background: options.background });
|
|
13706
13687
|
this.settings = new Settings({
|
|
13707
13688
|
compatibility: options.compatibility,
|
|
13708
13689
|
compatibilityModeVersion: options.compatabilityModeVersion,
|
|
@@ -13755,16 +13736,16 @@ var File = class {
|
|
|
13755
13736
|
for (const section of options.sections) this.addSection(section);
|
|
13756
13737
|
if (options.footnotes) for (const key in options.footnotes) {
|
|
13757
13738
|
const children = options.footnotes[key].children.map((p) => p instanceof Paragraph ? p : new Paragraph(p));
|
|
13758
|
-
this.
|
|
13739
|
+
this.footNotes.view.createFootNote(parseFloat(key), children);
|
|
13759
13740
|
}
|
|
13760
13741
|
if (options.endnotes) for (const key in options.endnotes) {
|
|
13761
13742
|
const children = options.endnotes[key].children.map((p) => p instanceof Paragraph ? p : new Paragraph(p));
|
|
13762
|
-
this.
|
|
13743
|
+
this.endnotes.view.createEndnote(parseFloat(key), children);
|
|
13763
13744
|
}
|
|
13764
|
-
this.
|
|
13745
|
+
this.fontTable = new FontWrapper(options.fonts ?? []);
|
|
13765
13746
|
}
|
|
13766
13747
|
addSection({ headers = {}, footers = {}, children, properties }) {
|
|
13767
|
-
this.
|
|
13748
|
+
this.document.view.body.addSection({
|
|
13768
13749
|
...properties,
|
|
13769
13750
|
footerWrapperGroup: {
|
|
13770
13751
|
default: footers.default ? this.createFooter(footers.default) : void 0,
|
|
@@ -13777,113 +13758,56 @@ var File = class {
|
|
|
13777
13758
|
first: headers.first ? this.createHeader(headers.first) : void 0
|
|
13778
13759
|
}
|
|
13779
13760
|
});
|
|
13780
|
-
for (const rawChild of children) this.
|
|
13761
|
+
for (const rawChild of children) this.document.view.add(coerceSectionChild(rawChild));
|
|
13781
13762
|
}
|
|
13782
13763
|
createHeader(header) {
|
|
13783
|
-
const wrapper = new HeaderWrapper(this.media, this.
|
|
13764
|
+
const wrapper = new HeaderWrapper(this.media, this._currentRelationshipId++);
|
|
13784
13765
|
const children = header instanceof Header ? header.options.children : header;
|
|
13785
13766
|
for (const rawChild of children) wrapper.add(coerceSectionChild(rawChild));
|
|
13786
13767
|
this.addHeaderToDocument(wrapper);
|
|
13787
13768
|
return wrapper;
|
|
13788
13769
|
}
|
|
13789
13770
|
createFooter(footer) {
|
|
13790
|
-
const wrapper = new FooterWrapper(this.media, this.
|
|
13771
|
+
const wrapper = new FooterWrapper(this.media, this._currentRelationshipId++);
|
|
13791
13772
|
const children = footer instanceof Footer ? footer.options.children : footer;
|
|
13792
13773
|
for (const rawChild of children) wrapper.add(coerceSectionChild(rawChild));
|
|
13793
13774
|
this.addFooterToDocument(wrapper);
|
|
13794
13775
|
return wrapper;
|
|
13795
13776
|
}
|
|
13796
13777
|
addHeaderToDocument(header, type = HeaderFooterReferenceType.DEFAULT) {
|
|
13797
|
-
this.
|
|
13778
|
+
this._headers.push({
|
|
13798
13779
|
header,
|
|
13799
13780
|
type
|
|
13800
13781
|
});
|
|
13801
|
-
this.
|
|
13802
|
-
this.contentTypes.addHeader(this.
|
|
13782
|
+
this.document.relationships.addRelationship(header.view.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", `header${this._headers.length}.xml`);
|
|
13783
|
+
this.contentTypes.addHeader(this._headers.length);
|
|
13803
13784
|
}
|
|
13804
13785
|
addFooterToDocument(footer, type = HeaderFooterReferenceType.DEFAULT) {
|
|
13805
|
-
this.
|
|
13786
|
+
this._footers.push({
|
|
13806
13787
|
footer,
|
|
13807
13788
|
type
|
|
13808
13789
|
});
|
|
13809
|
-
this.
|
|
13810
|
-
this.contentTypes.addFooter(this.
|
|
13790
|
+
this.document.relationships.addRelationship(footer.view.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", `footer${this._footers.length}.xml`);
|
|
13791
|
+
this.contentTypes.addFooter(this._footers.length);
|
|
13811
13792
|
}
|
|
13812
13793
|
addDefaultRelationships() {
|
|
13813
13794
|
this.fileRelationships.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml");
|
|
13814
13795
|
this.fileRelationships.addRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml");
|
|
13815
13796
|
this.fileRelationships.addRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
|
|
13816
13797
|
this.fileRelationships.addRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", "docProps/custom.xml");
|
|
13817
|
-
this.
|
|
13818
|
-
this.
|
|
13819
|
-
this.
|
|
13820
|
-
this.
|
|
13821
|
-
this.
|
|
13822
|
-
this.
|
|
13823
|
-
if (this.bibliography) this.
|
|
13824
|
-
}
|
|
13825
|
-
get Document() {
|
|
13826
|
-
return this.documentWrapper;
|
|
13827
|
-
}
|
|
13828
|
-
get Styles() {
|
|
13829
|
-
return this.styles;
|
|
13830
|
-
}
|
|
13831
|
-
get CoreProperties() {
|
|
13832
|
-
return this.coreProperties;
|
|
13833
|
-
}
|
|
13834
|
-
get Numbering() {
|
|
13835
|
-
return this.numbering;
|
|
13836
|
-
}
|
|
13837
|
-
get Media() {
|
|
13838
|
-
return this.media;
|
|
13839
|
-
}
|
|
13840
|
-
get Charts() {
|
|
13841
|
-
return this.charts;
|
|
13842
|
-
}
|
|
13843
|
-
get SmartArts() {
|
|
13844
|
-
return this.smartArts;
|
|
13845
|
-
}
|
|
13846
|
-
get AltChunks() {
|
|
13847
|
-
return this.altChunks;
|
|
13848
|
-
}
|
|
13849
|
-
get SubDocs() {
|
|
13850
|
-
return this.subDocs;
|
|
13851
|
-
}
|
|
13852
|
-
get FileRelationships() {
|
|
13853
|
-
return this.fileRelationships;
|
|
13854
|
-
}
|
|
13855
|
-
get Headers() {
|
|
13856
|
-
return this.headers.map((item) => item.header);
|
|
13857
|
-
}
|
|
13858
|
-
get Footers() {
|
|
13859
|
-
return this.footers.map((item) => item.footer);
|
|
13798
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
|
13799
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
|
|
13800
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", "footnotes.xml");
|
|
13801
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes", "endnotes.xml");
|
|
13802
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml");
|
|
13803
|
+
this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml");
|
|
13804
|
+
if (this.bibliography) this.document.relationships.addRelationship(this._currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography", "bibliography.xml");
|
|
13860
13805
|
}
|
|
13861
|
-
get
|
|
13862
|
-
return this.
|
|
13806
|
+
get headers() {
|
|
13807
|
+
return this._headers.map((item) => item.header);
|
|
13863
13808
|
}
|
|
13864
|
-
get
|
|
13865
|
-
return this.
|
|
13866
|
-
}
|
|
13867
|
-
get AppProperties() {
|
|
13868
|
-
return this.appProperties;
|
|
13869
|
-
}
|
|
13870
|
-
get FootNotes() {
|
|
13871
|
-
return this.footnotesWrapper;
|
|
13872
|
-
}
|
|
13873
|
-
get Endnotes() {
|
|
13874
|
-
return this.endnotesWrapper;
|
|
13875
|
-
}
|
|
13876
|
-
get Settings() {
|
|
13877
|
-
return this.settings;
|
|
13878
|
-
}
|
|
13879
|
-
get Comments() {
|
|
13880
|
-
return this.comments;
|
|
13881
|
-
}
|
|
13882
|
-
get Bibliography() {
|
|
13883
|
-
return this.bibliography;
|
|
13884
|
-
}
|
|
13885
|
-
get FontTable() {
|
|
13886
|
-
return this.fontWrapper;
|
|
13809
|
+
get footers() {
|
|
13810
|
+
return this._footers.map((item) => item.footer);
|
|
13887
13811
|
}
|
|
13888
13812
|
};
|
|
13889
13813
|
//#endregion
|
|
@@ -14667,23 +14591,23 @@ var Compiler = class {
|
|
|
14667
14591
|
files[fileObj.path] = typeof fileObj.data === "string" ? textToUint8Array(fileObj.data) : fileObj.data;
|
|
14668
14592
|
}
|
|
14669
14593
|
for (const subFile of overrides) files[subFile.path] = typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data;
|
|
14670
|
-
for (const mediaData of file.
|
|
14594
|
+
for (const mediaData of file.media.array) {
|
|
14671
14595
|
files[`word/media/${mediaData.fileName}`] = [toUint8Array(mediaData.data), { level: ZIP_STORED_LEVEL }];
|
|
14672
14596
|
if (mediaData.type === "svg") files[`word/media/${mediaData.fallback.fileName}`] = [toUint8Array(mediaData.fallback.data), { level: ZIP_STORED_LEVEL }];
|
|
14673
14597
|
}
|
|
14674
|
-
for (const { data: buffer, name, fontKey } of file.
|
|
14598
|
+
for (const { data: buffer, name, fontKey } of file.fontTable.fontOptionsWithKey) {
|
|
14675
14599
|
const [nameWithoutExtension] = name.split(".");
|
|
14676
14600
|
files[`word/fonts/${nameWithoutExtension}.odttf`] = obfuscate(buffer, fontKey);
|
|
14677
14601
|
}
|
|
14678
14602
|
return files;
|
|
14679
14603
|
}
|
|
14680
14604
|
xmlifyFile(file, headerFormattedViews, footerFormattedViews, prettify) {
|
|
14681
|
-
const documentRelationshipCount = file.
|
|
14682
|
-
const documentXmlData = xml(this.formatter.format(file.
|
|
14605
|
+
const documentRelationshipCount = file.document.relationships.relationshipCount + 1;
|
|
14606
|
+
const documentXmlData = xml(this.formatter.format(file.document.view, {
|
|
14683
14607
|
fileData: file,
|
|
14684
14608
|
file,
|
|
14685
14609
|
stack: [],
|
|
14686
|
-
viewWrapper: file.
|
|
14610
|
+
viewWrapper: file.document
|
|
14687
14611
|
}), {
|
|
14688
14612
|
declaration: {
|
|
14689
14613
|
encoding: "UTF-8",
|
|
@@ -14691,14 +14615,14 @@ var Compiler = class {
|
|
|
14691
14615
|
},
|
|
14692
14616
|
indent: prettify
|
|
14693
14617
|
});
|
|
14694
|
-
const commentRelationshipCount = file.
|
|
14695
|
-
const commentXmlData = xml(this.formatter.format(file.
|
|
14618
|
+
const commentRelationshipCount = file.comments.relationships.relationshipCount + 1;
|
|
14619
|
+
const commentXmlData = xml(this.formatter.format(file.comments, {
|
|
14696
14620
|
fileData: file,
|
|
14697
14621
|
file,
|
|
14698
14622
|
stack: [],
|
|
14699
14623
|
viewWrapper: {
|
|
14700
|
-
|
|
14701
|
-
|
|
14624
|
+
relationships: file.comments.relationships,
|
|
14625
|
+
view: file.comments
|
|
14702
14626
|
}
|
|
14703
14627
|
}), {
|
|
14704
14628
|
declaration: {
|
|
@@ -14707,12 +14631,12 @@ var Compiler = class {
|
|
|
14707
14631
|
},
|
|
14708
14632
|
indent: prettify
|
|
14709
14633
|
});
|
|
14710
|
-
const footnoteRelationshipCount = file.
|
|
14711
|
-
const footnoteXmlData = xml(this.formatter.format(file.
|
|
14634
|
+
const footnoteRelationshipCount = file.footNotes.relationships.relationshipCount + 1;
|
|
14635
|
+
const footnoteXmlData = xml(this.formatter.format(file.footNotes.view, {
|
|
14712
14636
|
fileData: file,
|
|
14713
14637
|
file,
|
|
14714
14638
|
stack: [],
|
|
14715
|
-
viewWrapper: file.
|
|
14639
|
+
viewWrapper: file.footNotes
|
|
14716
14640
|
}), {
|
|
14717
14641
|
declaration: {
|
|
14718
14642
|
encoding: "UTF-8",
|
|
@@ -14720,16 +14644,16 @@ var Compiler = class {
|
|
|
14720
14644
|
},
|
|
14721
14645
|
indent: prettify
|
|
14722
14646
|
});
|
|
14723
|
-
const documentMediaDatas = hasPlaceholders(documentXmlData) ? getReferencedMedia(documentXmlData, file.
|
|
14724
|
-
const commentMediaDatas = hasPlaceholders(commentXmlData) ? getReferencedMedia(commentXmlData, file.
|
|
14725
|
-
const footnoteMediaDatas = hasPlaceholders(footnoteXmlData) ? getReferencedMedia(footnoteXmlData, file.
|
|
14647
|
+
const documentMediaDatas = hasPlaceholders(documentXmlData) ? getReferencedMedia(documentXmlData, file.media.array) : [];
|
|
14648
|
+
const commentMediaDatas = hasPlaceholders(commentXmlData) ? getReferencedMedia(commentXmlData, file.media.array) : [];
|
|
14649
|
+
const footnoteMediaDatas = hasPlaceholders(footnoteXmlData) ? getReferencedMedia(footnoteXmlData, file.media.array) : [];
|
|
14726
14650
|
return {
|
|
14727
14651
|
AppProperties: {
|
|
14728
|
-
data: xml(this.formatter.format(file.
|
|
14652
|
+
data: xml(this.formatter.format(file.appProperties, {
|
|
14729
14653
|
fileData: file,
|
|
14730
14654
|
file,
|
|
14731
14655
|
stack: [],
|
|
14732
|
-
viewWrapper: file.
|
|
14656
|
+
viewWrapper: file.document
|
|
14733
14657
|
}), { declaration: {
|
|
14734
14658
|
encoding: "UTF-8",
|
|
14735
14659
|
standalone: "yes"
|
|
@@ -14737,21 +14661,21 @@ var Compiler = class {
|
|
|
14737
14661
|
path: "docProps/app.xml"
|
|
14738
14662
|
},
|
|
14739
14663
|
Comments: {
|
|
14740
|
-
data: replaceNumberingPlaceholders(commentMediaDatas.length > 0 ? replaceImagePlaceholders(commentXmlData, commentMediaDatas, commentRelationshipCount, "rId") : commentXmlData, file.
|
|
14664
|
+
data: replaceNumberingPlaceholders(commentMediaDatas.length > 0 ? replaceImagePlaceholders(commentXmlData, commentMediaDatas, commentRelationshipCount, "rId") : commentXmlData, file.numbering.concreteNumbering),
|
|
14741
14665
|
path: "word/comments.xml"
|
|
14742
14666
|
},
|
|
14743
14667
|
CommentsRelationships: {
|
|
14744
14668
|
data: (() => {
|
|
14745
14669
|
commentMediaDatas.forEach((mediaData, i) => {
|
|
14746
|
-
file.
|
|
14670
|
+
file.comments.relationships.addRelationship(commentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14747
14671
|
});
|
|
14748
|
-
return xml(this.formatter.format(file.
|
|
14672
|
+
return xml(this.formatter.format(file.comments.relationships, {
|
|
14749
14673
|
fileData: file,
|
|
14750
14674
|
file,
|
|
14751
14675
|
stack: [],
|
|
14752
14676
|
viewWrapper: {
|
|
14753
|
-
|
|
14754
|
-
|
|
14677
|
+
relationships: file.comments.relationships,
|
|
14678
|
+
view: file.comments
|
|
14755
14679
|
}
|
|
14756
14680
|
}), {
|
|
14757
14681
|
declaration: { encoding: "UTF-8" },
|
|
@@ -14762,21 +14686,21 @@ var Compiler = class {
|
|
|
14762
14686
|
},
|
|
14763
14687
|
ContentTypes: {
|
|
14764
14688
|
data: (() => {
|
|
14765
|
-
file.
|
|
14766
|
-
file.
|
|
14689
|
+
file.charts.array.forEach((_, i) => {
|
|
14690
|
+
file.contentTypes.addChart(i + 1);
|
|
14767
14691
|
});
|
|
14768
|
-
file.
|
|
14769
|
-
file.
|
|
14770
|
-
file.
|
|
14771
|
-
file.
|
|
14772
|
-
file.
|
|
14773
|
-
file.
|
|
14692
|
+
file.smartArts.array.forEach((_, i) => {
|
|
14693
|
+
file.contentTypes.addDiagramData(i + 1);
|
|
14694
|
+
file.contentTypes.addDiagramLayout(i + 1);
|
|
14695
|
+
file.contentTypes.addDiagramStyle(i + 1);
|
|
14696
|
+
file.contentTypes.addDiagramColors(i + 1);
|
|
14697
|
+
file.contentTypes.addDiagramDrawing(i + 1);
|
|
14774
14698
|
});
|
|
14775
|
-
return xml(this.formatter.format(file.
|
|
14699
|
+
return xml(this.formatter.format(file.contentTypes, {
|
|
14776
14700
|
fileData: file,
|
|
14777
14701
|
file,
|
|
14778
14702
|
stack: [],
|
|
14779
|
-
viewWrapper: file.
|
|
14703
|
+
viewWrapper: file.document
|
|
14780
14704
|
}), {
|
|
14781
14705
|
declaration: { encoding: "UTF-8" },
|
|
14782
14706
|
indent: prettify
|
|
@@ -14785,11 +14709,11 @@ var Compiler = class {
|
|
|
14785
14709
|
path: "[Content_Types].xml"
|
|
14786
14710
|
},
|
|
14787
14711
|
CustomProperties: {
|
|
14788
|
-
data: xml(this.formatter.format(file.
|
|
14712
|
+
data: xml(this.formatter.format(file.customProperties, {
|
|
14789
14713
|
fileData: file,
|
|
14790
14714
|
file,
|
|
14791
14715
|
stack: [],
|
|
14792
|
-
viewWrapper: file.
|
|
14716
|
+
viewWrapper: file.document
|
|
14793
14717
|
}), {
|
|
14794
14718
|
declaration: {
|
|
14795
14719
|
encoding: "UTF-8",
|
|
@@ -14803,20 +14727,20 @@ var Compiler = class {
|
|
|
14803
14727
|
data: (() => {
|
|
14804
14728
|
let xmlData = documentMediaDatas.length > 0 ? replaceImagePlaceholders(documentXmlData, documentMediaDatas, documentRelationshipCount, "rId") : documentXmlData;
|
|
14805
14729
|
if (hasPlaceholders(xmlData)) {
|
|
14806
|
-
xmlData = replaceChartPlaceholders(xmlData, file.
|
|
14807
|
-
const smartArtDataOffset = documentRelationshipCount + documentMediaDatas.length + file.
|
|
14808
|
-
xmlData = replaceSmartArtPlaceholders(xmlData, file.
|
|
14730
|
+
xmlData = replaceChartPlaceholders(xmlData, file.charts.array.map((c) => c.key), documentRelationshipCount + documentMediaDatas.length, "rId");
|
|
14731
|
+
const smartArtDataOffset = documentRelationshipCount + documentMediaDatas.length + file.charts.array.length;
|
|
14732
|
+
xmlData = replaceSmartArtPlaceholders(xmlData, file.smartArts.array.map((s) => s.key), smartArtDataOffset, "rId");
|
|
14809
14733
|
}
|
|
14810
|
-
return replaceNumberingPlaceholders(xmlData, file.
|
|
14734
|
+
return replaceNumberingPlaceholders(xmlData, file.numbering.concreteNumbering);
|
|
14811
14735
|
})(),
|
|
14812
14736
|
path: "word/document.xml"
|
|
14813
14737
|
},
|
|
14814
14738
|
Endnotes: {
|
|
14815
|
-
data: xml(this.formatter.format(file.
|
|
14739
|
+
data: xml(this.formatter.format(file.endnotes.view, {
|
|
14816
14740
|
fileData: file,
|
|
14817
14741
|
file,
|
|
14818
14742
|
stack: [],
|
|
14819
|
-
viewWrapper: file.
|
|
14743
|
+
viewWrapper: file.endnotes
|
|
14820
14744
|
}), {
|
|
14821
14745
|
declaration: { encoding: "UTF-8" },
|
|
14822
14746
|
indent: prettify
|
|
@@ -14824,11 +14748,11 @@ var Compiler = class {
|
|
|
14824
14748
|
path: "word/endnotes.xml"
|
|
14825
14749
|
},
|
|
14826
14750
|
EndnotesRelationships: {
|
|
14827
|
-
data: xml(this.formatter.format(file.
|
|
14751
|
+
data: xml(this.formatter.format(file.endnotes.relationships, {
|
|
14828
14752
|
fileData: file,
|
|
14829
14753
|
file,
|
|
14830
14754
|
stack: [],
|
|
14831
|
-
viewWrapper: file.
|
|
14755
|
+
viewWrapper: file.endnotes
|
|
14832
14756
|
}), {
|
|
14833
14757
|
declaration: { encoding: "UTF-8" },
|
|
14834
14758
|
indent: prettify
|
|
@@ -14836,11 +14760,11 @@ var Compiler = class {
|
|
|
14836
14760
|
path: "word/_rels/endnotes.xml.rels"
|
|
14837
14761
|
},
|
|
14838
14762
|
FileRelationships: {
|
|
14839
|
-
data: xml(this.formatter.format(file.
|
|
14763
|
+
data: xml(this.formatter.format(file.fileRelationships, {
|
|
14840
14764
|
fileData: file,
|
|
14841
14765
|
file,
|
|
14842
14766
|
stack: [],
|
|
14843
|
-
viewWrapper: file.
|
|
14767
|
+
viewWrapper: file.document
|
|
14844
14768
|
}), {
|
|
14845
14769
|
declaration: { encoding: "UTF-8" },
|
|
14846
14770
|
indent: prettify
|
|
@@ -14848,11 +14772,11 @@ var Compiler = class {
|
|
|
14848
14772
|
path: "_rels/.rels"
|
|
14849
14773
|
},
|
|
14850
14774
|
FontTable: {
|
|
14851
|
-
data: xml(this.formatter.format(file.
|
|
14775
|
+
data: xml(this.formatter.format(file.fontTable.view, {
|
|
14852
14776
|
fileData: file,
|
|
14853
14777
|
file,
|
|
14854
14778
|
stack: [],
|
|
14855
|
-
viewWrapper: file.
|
|
14779
|
+
viewWrapper: file.document
|
|
14856
14780
|
}), {
|
|
14857
14781
|
declaration: {
|
|
14858
14782
|
encoding: "UTF-8",
|
|
@@ -14863,11 +14787,11 @@ var Compiler = class {
|
|
|
14863
14787
|
path: "word/fontTable.xml"
|
|
14864
14788
|
},
|
|
14865
14789
|
FontTableRelationships: {
|
|
14866
|
-
data: xml(this.formatter.format(file.
|
|
14790
|
+
data: xml(this.formatter.format(file.fontTable.relationships, {
|
|
14867
14791
|
fileData: file,
|
|
14868
14792
|
file,
|
|
14869
14793
|
stack: [],
|
|
14870
|
-
viewWrapper: file.
|
|
14794
|
+
viewWrapper: file.document
|
|
14871
14795
|
}), {
|
|
14872
14796
|
declaration: { encoding: "UTF-8" },
|
|
14873
14797
|
indent: prettify
|
|
@@ -14875,19 +14799,19 @@ var Compiler = class {
|
|
|
14875
14799
|
path: "word/_rels/fontTable.xml.rels"
|
|
14876
14800
|
},
|
|
14877
14801
|
FootNotes: {
|
|
14878
|
-
data: replaceNumberingPlaceholders(footnoteMediaDatas.length > 0 ? replaceImagePlaceholders(footnoteXmlData, footnoteMediaDatas, footnoteRelationshipCount, "rId") : footnoteXmlData, file.
|
|
14802
|
+
data: replaceNumberingPlaceholders(footnoteMediaDatas.length > 0 ? replaceImagePlaceholders(footnoteXmlData, footnoteMediaDatas, footnoteRelationshipCount, "rId") : footnoteXmlData, file.numbering.concreteNumbering),
|
|
14879
14803
|
path: "word/footnotes.xml"
|
|
14880
14804
|
},
|
|
14881
14805
|
FootNotesRelationships: {
|
|
14882
14806
|
data: (() => {
|
|
14883
14807
|
footnoteMediaDatas.forEach((mediaData, i) => {
|
|
14884
|
-
file.
|
|
14808
|
+
file.footNotes.relationships.addRelationship(footnoteRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14885
14809
|
});
|
|
14886
|
-
return xml(this.formatter.format(file.
|
|
14810
|
+
return xml(this.formatter.format(file.footNotes.relationships, {
|
|
14887
14811
|
fileData: file,
|
|
14888
14812
|
file,
|
|
14889
14813
|
stack: [],
|
|
14890
|
-
viewWrapper: file.
|
|
14814
|
+
viewWrapper: file.footNotes
|
|
14891
14815
|
}), {
|
|
14892
14816
|
declaration: { encoding: "UTF-8" },
|
|
14893
14817
|
indent: prettify
|
|
@@ -14895,8 +14819,8 @@ var Compiler = class {
|
|
|
14895
14819
|
})(),
|
|
14896
14820
|
path: "word/_rels/footnotes.xml.rels"
|
|
14897
14821
|
},
|
|
14898
|
-
FooterRelationships: file.
|
|
14899
|
-
const xmlData = xml(this.formatter.format(footerWrapper.
|
|
14822
|
+
FooterRelationships: file.footers.map((footerWrapper, index) => {
|
|
14823
|
+
const xmlData = xml(this.formatter.format(footerWrapper.view, {
|
|
14900
14824
|
fileData: file,
|
|
14901
14825
|
file,
|
|
14902
14826
|
stack: [],
|
|
@@ -14906,11 +14830,11 @@ var Compiler = class {
|
|
|
14906
14830
|
indent: prettify
|
|
14907
14831
|
});
|
|
14908
14832
|
footerFormattedViews.set(index, xmlData);
|
|
14909
|
-
getReferencedMedia(xmlData, file.
|
|
14910
|
-
footerWrapper.
|
|
14833
|
+
getReferencedMedia(xmlData, file.media.array).forEach((mediaData, i) => {
|
|
14834
|
+
footerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14911
14835
|
});
|
|
14912
14836
|
return {
|
|
14913
|
-
data: xml(this.formatter.format(footerWrapper.
|
|
14837
|
+
data: xml(this.formatter.format(footerWrapper.relationships, {
|
|
14914
14838
|
fileData: file,
|
|
14915
14839
|
file,
|
|
14916
14840
|
stack: [],
|
|
@@ -14922,16 +14846,16 @@ var Compiler = class {
|
|
|
14922
14846
|
path: `word/_rels/footer${index + 1}.xml.rels`
|
|
14923
14847
|
};
|
|
14924
14848
|
}),
|
|
14925
|
-
Footers: file.
|
|
14849
|
+
Footers: file.footers.map((_footerWrapper, index) => {
|
|
14926
14850
|
const tempXmlData = footerFormattedViews.get(index);
|
|
14927
|
-
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.
|
|
14851
|
+
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.media.array) : [];
|
|
14928
14852
|
return {
|
|
14929
|
-
data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.
|
|
14853
|
+
data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.numbering.concreteNumbering),
|
|
14930
14854
|
path: `word/footer${index + 1}.xml`
|
|
14931
14855
|
};
|
|
14932
14856
|
}),
|
|
14933
|
-
HeaderRelationships: file.
|
|
14934
|
-
const xmlData = xml(this.formatter.format(headerWrapper.
|
|
14857
|
+
HeaderRelationships: file.headers.map((headerWrapper, index) => {
|
|
14858
|
+
const xmlData = xml(this.formatter.format(headerWrapper.view, {
|
|
14935
14859
|
fileData: file,
|
|
14936
14860
|
file,
|
|
14937
14861
|
stack: [],
|
|
@@ -14941,11 +14865,11 @@ var Compiler = class {
|
|
|
14941
14865
|
indent: prettify
|
|
14942
14866
|
});
|
|
14943
14867
|
headerFormattedViews.set(index, xmlData);
|
|
14944
|
-
getReferencedMedia(xmlData, file.
|
|
14945
|
-
headerWrapper.
|
|
14868
|
+
getReferencedMedia(xmlData, file.media.array).forEach((mediaData, i) => {
|
|
14869
|
+
headerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14946
14870
|
});
|
|
14947
14871
|
return {
|
|
14948
|
-
data: xml(this.formatter.format(headerWrapper.
|
|
14872
|
+
data: xml(this.formatter.format(headerWrapper.relationships, {
|
|
14949
14873
|
fileData: file,
|
|
14950
14874
|
file,
|
|
14951
14875
|
stack: [],
|
|
@@ -14957,20 +14881,20 @@ var Compiler = class {
|
|
|
14957
14881
|
path: `word/_rels/header${index + 1}.xml.rels`
|
|
14958
14882
|
};
|
|
14959
14883
|
}),
|
|
14960
|
-
Headers: file.
|
|
14884
|
+
Headers: file.headers.map((_headerWrapper, index) => {
|
|
14961
14885
|
const tempXmlData = headerFormattedViews.get(index);
|
|
14962
|
-
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.
|
|
14886
|
+
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.media.array) : [];
|
|
14963
14887
|
return {
|
|
14964
|
-
data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.
|
|
14888
|
+
data: replaceNumberingPlaceholders(mediaDatas.length > 0 ? replaceImagePlaceholders(tempXmlData, mediaDatas, 0, "rId") : tempXmlData, file.numbering.concreteNumbering),
|
|
14965
14889
|
path: `word/header${index + 1}.xml`
|
|
14966
14890
|
};
|
|
14967
14891
|
}),
|
|
14968
14892
|
Numbering: {
|
|
14969
|
-
data: xml(this.formatter.format(file.
|
|
14893
|
+
data: xml(this.formatter.format(file.numbering, {
|
|
14970
14894
|
fileData: file,
|
|
14971
14895
|
file,
|
|
14972
14896
|
stack: [],
|
|
14973
|
-
viewWrapper: file.
|
|
14897
|
+
viewWrapper: file.document
|
|
14974
14898
|
}), {
|
|
14975
14899
|
declaration: {
|
|
14976
14900
|
encoding: "UTF-8",
|
|
@@ -14981,11 +14905,11 @@ var Compiler = class {
|
|
|
14981
14905
|
path: "word/numbering.xml"
|
|
14982
14906
|
},
|
|
14983
14907
|
Properties: {
|
|
14984
|
-
data: xml(this.formatter.format(file.
|
|
14908
|
+
data: xml(this.formatter.format(file.coreProperties, {
|
|
14985
14909
|
fileData: file,
|
|
14986
14910
|
file,
|
|
14987
14911
|
stack: [],
|
|
14988
|
-
viewWrapper: file.
|
|
14912
|
+
viewWrapper: file.document
|
|
14989
14913
|
}), {
|
|
14990
14914
|
declaration: {
|
|
14991
14915
|
encoding: "UTF-8",
|
|
@@ -14998,24 +14922,24 @@ var Compiler = class {
|
|
|
14998
14922
|
Relationships: {
|
|
14999
14923
|
data: (() => {
|
|
15000
14924
|
documentMediaDatas.forEach((mediaData, i) => {
|
|
15001
|
-
file.
|
|
14925
|
+
file.document.relationships.addRelationship(documentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
15002
14926
|
});
|
|
15003
14927
|
const chartOffset = documentRelationshipCount + documentMediaDatas.length;
|
|
15004
|
-
file.
|
|
15005
|
-
file.
|
|
14928
|
+
file.charts.array.forEach((_chartData, i) => {
|
|
14929
|
+
file.document.relationships.addRelationship(chartOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `charts/chart${i + 1}.xml`);
|
|
15006
14930
|
});
|
|
15007
|
-
addSmartArtRelationships(file.
|
|
15008
|
-
file.
|
|
15009
|
-
}, documentRelationshipCount + documentMediaDatas.length + file.
|
|
14931
|
+
addSmartArtRelationships(file.smartArts.array.map((s) => s.key), (id, type, target) => {
|
|
14932
|
+
file.document.relationships.addRelationship(id, type, target);
|
|
14933
|
+
}, documentRelationshipCount + documentMediaDatas.length + file.charts.array.length, 0, {
|
|
15010
14934
|
pathPrefix: "",
|
|
15011
14935
|
styleRelType: "http://schemas.microsoft.com/office/2007/relationships/diagramStyle"
|
|
15012
14936
|
});
|
|
15013
|
-
file.
|
|
15014
|
-
return xml(this.formatter.format(file.
|
|
14937
|
+
file.document.relationships.addRelationship(file.document.relationships.relationshipCount + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", "fontTable.xml");
|
|
14938
|
+
return xml(this.formatter.format(file.document.relationships, {
|
|
15015
14939
|
fileData: file,
|
|
15016
14940
|
file,
|
|
15017
14941
|
stack: [],
|
|
15018
|
-
viewWrapper: file.
|
|
14942
|
+
viewWrapper: file.document
|
|
15019
14943
|
}), {
|
|
15020
14944
|
declaration: { encoding: "UTF-8" },
|
|
15021
14945
|
indent: prettify
|
|
@@ -15024,11 +14948,11 @@ var Compiler = class {
|
|
|
15024
14948
|
path: "word/_rels/document.xml.rels"
|
|
15025
14949
|
},
|
|
15026
14950
|
Settings: {
|
|
15027
|
-
data: xml(this.formatter.format(file.
|
|
14951
|
+
data: xml(this.formatter.format(file.settings, {
|
|
15028
14952
|
fileData: file,
|
|
15029
14953
|
file,
|
|
15030
14954
|
stack: [],
|
|
15031
|
-
viewWrapper: file.
|
|
14955
|
+
viewWrapper: file.document
|
|
15032
14956
|
}), {
|
|
15033
14957
|
declaration: {
|
|
15034
14958
|
encoding: "UTF-8",
|
|
@@ -15039,28 +14963,28 @@ var Compiler = class {
|
|
|
15039
14963
|
path: "word/settings.xml"
|
|
15040
14964
|
},
|
|
15041
14965
|
Styles: {
|
|
15042
|
-
data: replaceNumberingPlaceholders(xml(this.formatter.format(file.
|
|
14966
|
+
data: replaceNumberingPlaceholders(xml(this.formatter.format(file.styles, {
|
|
15043
14967
|
fileData: file,
|
|
15044
14968
|
file,
|
|
15045
14969
|
stack: [],
|
|
15046
|
-
viewWrapper: file.
|
|
14970
|
+
viewWrapper: file.document
|
|
15047
14971
|
}), {
|
|
15048
14972
|
declaration: {
|
|
15049
14973
|
encoding: "UTF-8",
|
|
15050
14974
|
standalone: "yes"
|
|
15051
14975
|
},
|
|
15052
14976
|
indent: prettify
|
|
15053
|
-
}), file.
|
|
14977
|
+
}), file.numbering.concreteNumbering),
|
|
15054
14978
|
path: "word/styles.xml"
|
|
15055
14979
|
},
|
|
15056
|
-
...file.
|
|
15057
|
-
data: xml(this.formatter.format(file.
|
|
14980
|
+
...file.bibliography ? { Bibliography: {
|
|
14981
|
+
data: xml(this.formatter.format(file.bibliography, {
|
|
15058
14982
|
fileData: file,
|
|
15059
14983
|
file,
|
|
15060
14984
|
stack: [],
|
|
15061
14985
|
viewWrapper: {
|
|
15062
|
-
|
|
15063
|
-
|
|
14986
|
+
relationships: file.bibliography.relationships,
|
|
14987
|
+
view: file.bibliography
|
|
15064
14988
|
}
|
|
15065
14989
|
}), {
|
|
15066
14990
|
declaration: {
|
|
@@ -15071,12 +14995,12 @@ var Compiler = class {
|
|
|
15071
14995
|
}),
|
|
15072
14996
|
path: "word/bibliography.xml"
|
|
15073
14997
|
} } : {},
|
|
15074
|
-
...file.
|
|
14998
|
+
...file.charts.array.length > 0 ? { Charts: file.charts.array.flatMap((chartData, i) => [{
|
|
15075
14999
|
data: xml(this.formatter.format(chartData.chartSpace, {
|
|
15076
15000
|
fileData: file,
|
|
15077
15001
|
file,
|
|
15078
15002
|
stack: [],
|
|
15079
|
-
viewWrapper: file.
|
|
15003
|
+
viewWrapper: file.document
|
|
15080
15004
|
}), {
|
|
15081
15005
|
declaration: {
|
|
15082
15006
|
encoding: "UTF-8",
|
|
@@ -15092,13 +15016,13 @@ var Compiler = class {
|
|
|
15092
15016
|
} }),
|
|
15093
15017
|
path: `word/charts/_rels/chart${i + 1}.xml.rels`
|
|
15094
15018
|
}]) } : {},
|
|
15095
|
-
...file.
|
|
15096
|
-
DiagramData: file.
|
|
15019
|
+
...file.smartArts.array.length > 0 ? {
|
|
15020
|
+
DiagramData: file.smartArts.array.map((smartArtData, i) => ({
|
|
15097
15021
|
data: xml(this.formatter.format(smartArtData.dataModel, {
|
|
15098
15022
|
fileData: file,
|
|
15099
15023
|
file,
|
|
15100
15024
|
stack: [],
|
|
15101
|
-
viewWrapper: file.
|
|
15025
|
+
viewWrapper: file.document
|
|
15102
15026
|
}), {
|
|
15103
15027
|
declaration: {
|
|
15104
15028
|
encoding: "UTF-8",
|
|
@@ -15108,28 +15032,28 @@ var Compiler = class {
|
|
|
15108
15032
|
}),
|
|
15109
15033
|
path: `word/diagrams/data${i + 1}.xml`
|
|
15110
15034
|
})),
|
|
15111
|
-
DiagramLayout: file.
|
|
15035
|
+
DiagramLayout: file.smartArts.array.map((smartArtData, i) => ({
|
|
15112
15036
|
data: getLayoutXml(smartArtData.layout),
|
|
15113
15037
|
path: `word/diagrams/layout${i + 1}.xml`
|
|
15114
15038
|
})),
|
|
15115
|
-
DiagramStyle: file.
|
|
15039
|
+
DiagramStyle: file.smartArts.array.map((smartArtData, i) => ({
|
|
15116
15040
|
data: getStyleXml(smartArtData.style),
|
|
15117
15041
|
path: `word/diagrams/quickStyle${i + 1}.xml`
|
|
15118
15042
|
})),
|
|
15119
|
-
DiagramColors: file.
|
|
15043
|
+
DiagramColors: file.smartArts.array.map((smartArtData, i) => ({
|
|
15120
15044
|
data: getColorXml(smartArtData.color),
|
|
15121
15045
|
path: `word/diagrams/colors${i + 1}.xml`
|
|
15122
15046
|
})),
|
|
15123
|
-
DiagramDrawing: file.
|
|
15047
|
+
DiagramDrawing: file.smartArts.array.map((_, i) => ({
|
|
15124
15048
|
data: DEFAULT_DRAWING_XML,
|
|
15125
15049
|
path: `word/diagrams/drawing${i + 1}.xml`
|
|
15126
15050
|
}))
|
|
15127
15051
|
} : {},
|
|
15128
|
-
...file.
|
|
15052
|
+
...file.altChunks.array.length > 0 ? { AltChunks: file.altChunks.array.map((altChunkData) => ({
|
|
15129
15053
|
data: altChunkData.data,
|
|
15130
15054
|
path: `word/${altChunkData.path}`
|
|
15131
15055
|
})) } : {},
|
|
15132
|
-
...file.
|
|
15056
|
+
...file.subDocs.array.length > 0 ? { SubDocs: file.subDocs.array.map((subDocData) => ({
|
|
15133
15057
|
data: subDocData.data,
|
|
15134
15058
|
path: `word/${subDocData.path}`
|
|
15135
15059
|
})) } : {}
|
|
@@ -15857,7 +15781,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15857
15781
|
...patchValue,
|
|
15858
15782
|
children: patchValue.children.map((element) => {
|
|
15859
15783
|
if (element instanceof ExternalHyperlink) {
|
|
15860
|
-
const concreteHyperlink = new ConcreteHyperlink(element.options.children, uniqueId());
|
|
15784
|
+
const concreteHyperlink = new ConcreteHyperlink(element.options.children, uniqueId(), { tooltip: element.options.tooltip });
|
|
15861
15785
|
hyperlinkRelationshipAdditions.push({
|
|
15862
15786
|
hyperlink: {
|
|
15863
15787
|
id: concreteHyperlink.linkId,
|
|
@@ -15874,7 +15798,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15874
15798
|
if (!recursive || !didFindOccurrence) break;
|
|
15875
15799
|
}
|
|
15876
15800
|
}
|
|
15877
|
-
const mediaDatas = getReferencedMedia(JSON.stringify(json), context.file.
|
|
15801
|
+
const mediaDatas = getReferencedMedia(JSON.stringify(json), context.file.media.array);
|
|
15878
15802
|
if (mediaDatas.length > 0) {
|
|
15879
15803
|
hasMedia = true;
|
|
15880
15804
|
imageRelationshipAdditions.push({
|
|
@@ -15916,7 +15840,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15916
15840
|
const files = {};
|
|
15917
15841
|
for (const [key, value] of map) files[key] = textToUint8Array(toXml(value));
|
|
15918
15842
|
for (const [key, value] of binaryContentMap) files[key] = value;
|
|
15919
|
-
for (const { data: mediaData, fileName } of file.
|
|
15843
|
+
for (const { data: mediaData, fileName } of file.media.array) files[`word/media/${fileName}`] = mediaData instanceof Uint8Array ? mediaData : new Uint8Array(mediaData);
|
|
15920
15844
|
return await zipAndConvert(files, outputType, OoxmlMimeType.DOCX);
|
|
15921
15845
|
};
|
|
15922
15846
|
const toXml = (jsonObj) => {
|
|
@@ -15986,49 +15910,6 @@ const findPatchKeys = (text) => {
|
|
|
15986
15910
|
return text.match(/(?<=\{\{).+?(?=\}\})/gs) ?? [];
|
|
15987
15911
|
};
|
|
15988
15912
|
//#endregion
|
|
15989
|
-
//#region src/file/alt-chunk/alt-chunk-parse.ts
|
|
15990
|
-
/**
|
|
15991
|
-
* AltChunk parser for DOCX documents.
|
|
15992
|
-
*
|
|
15993
|
-
* Parses w:altChunk elements and extracts embedded content from the ZIP.
|
|
15994
|
-
*
|
|
15995
|
-
* @module
|
|
15996
|
-
*/
|
|
15997
|
-
/**
|
|
15998
|
-
* Parse a w:altChunk element into AltChunkOptions.
|
|
15999
|
-
* Reads the referenced data from the ZIP package.
|
|
16000
|
-
*/
|
|
16001
|
-
function parseAltChunk(el, ctx) {
|
|
16002
|
-
const rId = attr(el, "r:id");
|
|
16003
|
-
if (!rId) throw new Error("w:altChunk missing r:id attribute");
|
|
16004
|
-
const path = ctx.docx.partRefs.afChunks.get(rId);
|
|
16005
|
-
if (!path) throw new Error(`AltChunk relationship ${rId} not found`);
|
|
16006
|
-
const data = ctx.docx.doc.getRaw(path);
|
|
16007
|
-
if (!data) throw new Error(`AltChunk data not found at ${path}`);
|
|
16008
|
-
const ext = path.split(".").pop() ?? "txt";
|
|
16009
|
-
let contentType;
|
|
16010
|
-
let extension;
|
|
16011
|
-
switch (ext) {
|
|
16012
|
-
case "html":
|
|
16013
|
-
contentType = "text/html";
|
|
16014
|
-
extension = "html";
|
|
16015
|
-
break;
|
|
16016
|
-
case "rtf":
|
|
16017
|
-
contentType = "application/rtf";
|
|
16018
|
-
extension = "rtf";
|
|
16019
|
-
break;
|
|
16020
|
-
default:
|
|
16021
|
-
contentType = "text/plain";
|
|
16022
|
-
extension = "txt";
|
|
16023
|
-
break;
|
|
16024
|
-
}
|
|
16025
|
-
return {
|
|
16026
|
-
data,
|
|
16027
|
-
contentType,
|
|
16028
|
-
extension
|
|
16029
|
-
};
|
|
16030
|
-
}
|
|
16031
|
-
//#endregion
|
|
16032
15913
|
//#region src/file/drawing/drawing-parse.ts
|
|
16033
15914
|
/**
|
|
16034
15915
|
* Drawing parser for DOCX documents.
|
|
@@ -16104,9 +15985,11 @@ function parseImageRun(el, ctx) {
|
|
|
16104
15985
|
if (docPr) {
|
|
16105
15986
|
const name = attr(docPr, "name");
|
|
16106
15987
|
const descr = attr(docPr, "descr");
|
|
16107
|
-
|
|
15988
|
+
const title = attr(docPr, "title");
|
|
15989
|
+
if (name || descr || title) imageOpts.altText = {
|
|
16108
15990
|
...name ? { name } : {},
|
|
16109
|
-
...descr ? { description: descr } : {}
|
|
15991
|
+
...descr ? { description: descr } : {},
|
|
15992
|
+
...title ? { title } : {}
|
|
16110
15993
|
};
|
|
16111
15994
|
}
|
|
16112
15995
|
if (anchor && !inline) {
|
|
@@ -16116,14 +15999,20 @@ function parseImageRun(el, ctx) {
|
|
|
16116
15999
|
const align = findChild(posH, "wp:align");
|
|
16117
16000
|
const posOffset = findChild(posH, "wp:posOffset");
|
|
16118
16001
|
if (align) floating.horizontalPosition = { align: textOf(align) };
|
|
16119
|
-
else if (posOffset)
|
|
16002
|
+
else if (posOffset) {
|
|
16003
|
+
const val = Number(textOf(posOffset));
|
|
16004
|
+
if (!isNaN(val)) floating.horizontalPosition = { offset: val };
|
|
16005
|
+
}
|
|
16120
16006
|
}
|
|
16121
16007
|
const posV = findChild(anchor, "wp:positionV");
|
|
16122
16008
|
if (posV) {
|
|
16123
16009
|
const align = findChild(posV, "wp:align");
|
|
16124
16010
|
const posOffset = findChild(posV, "wp:posOffset");
|
|
16125
16011
|
if (align) floating.verticalPosition = { align: textOf(align) };
|
|
16126
|
-
else if (posOffset)
|
|
16012
|
+
else if (posOffset) {
|
|
16013
|
+
const val = Number(textOf(posOffset));
|
|
16014
|
+
if (!isNaN(val)) floating.verticalPosition = { offset: val };
|
|
16015
|
+
}
|
|
16127
16016
|
}
|
|
16128
16017
|
for (const wrapType of [
|
|
16129
16018
|
"wrapSquare",
|
|
@@ -16564,6 +16453,10 @@ const PARSED_CR = Symbol("CarriageReturn");
|
|
|
16564
16453
|
const PARSED_NO_BREAK_HYPHEN = Symbol("NoBreakHyphen");
|
|
16565
16454
|
/** Matches w:softHyphen */
|
|
16566
16455
|
const PARSED_SOFT_HYPHEN = Symbol("SoftHyphen");
|
|
16456
|
+
/** Matches w:footnoteRef — auto-generated by Footnote class */
|
|
16457
|
+
const PARSED_FOOTNOTE_REF = Symbol("FootnoteRef");
|
|
16458
|
+
/** Matches w:br[@w:type="column"] */
|
|
16459
|
+
const PARSED_COLUMN_BREAK = Symbol("ColumnBreak");
|
|
16567
16460
|
/**
|
|
16568
16461
|
* Parse a w:r element into run data.
|
|
16569
16462
|
* Returns { properties, children } where children are parsed run content items.
|
|
@@ -16581,10 +16474,15 @@ function parseRun(el, _ctx) {
|
|
|
16581
16474
|
children.push(text);
|
|
16582
16475
|
break;
|
|
16583
16476
|
}
|
|
16477
|
+
case "w:delText": {
|
|
16478
|
+
const text = textOf(child);
|
|
16479
|
+
if (text) children.push(text);
|
|
16480
|
+
break;
|
|
16481
|
+
}
|
|
16584
16482
|
case "w:br": {
|
|
16585
16483
|
const brType = attr(child, "w:type");
|
|
16586
16484
|
if (brType === "page") children.push(PARSED_PAGE_BREAK);
|
|
16587
|
-
else if (brType === "column") children.push(
|
|
16485
|
+
else if (brType === "column") children.push(PARSED_COLUMN_BREAK);
|
|
16588
16486
|
else children.push(PARSED_LINE_BREAK);
|
|
16589
16487
|
break;
|
|
16590
16488
|
}
|
|
@@ -16607,8 +16505,29 @@ function parseRun(el, _ctx) {
|
|
|
16607
16505
|
}
|
|
16608
16506
|
case "w:drawing":
|
|
16609
16507
|
case "w:pict": break;
|
|
16610
|
-
case "w:
|
|
16611
|
-
|
|
16508
|
+
case "w:sym": {
|
|
16509
|
+
const charVal = attr(child, "w:char");
|
|
16510
|
+
const fontVal = attr(child, "w:font");
|
|
16511
|
+
if (charVal) children.push({ symbolRun: {
|
|
16512
|
+
char: charVal,
|
|
16513
|
+
symbolfont: fontVal ?? "Wingdings"
|
|
16514
|
+
} });
|
|
16515
|
+
break;
|
|
16516
|
+
}
|
|
16517
|
+
case "w:footnoteReference": {
|
|
16518
|
+
const id = attrNum(child, "w:id");
|
|
16519
|
+
if (id !== void 0) children.push({ footnoteReference: id });
|
|
16520
|
+
break;
|
|
16521
|
+
}
|
|
16522
|
+
case "w:endnoteReference": {
|
|
16523
|
+
const id = attrNum(child, "w:id");
|
|
16524
|
+
if (id !== void 0) children.push({ endnoteReference: id });
|
|
16525
|
+
break;
|
|
16526
|
+
}
|
|
16527
|
+
case "w:footnoteRef":
|
|
16528
|
+
case "w:endnoteRef":
|
|
16529
|
+
children.push(PARSED_FOOTNOTE_REF);
|
|
16530
|
+
break;
|
|
16612
16531
|
default:
|
|
16613
16532
|
if (child.name && child.elements && child.elements.length > 0) children.push(new RawPassthrough(child));
|
|
16614
16533
|
break;
|
|
@@ -16622,18 +16541,31 @@ function parseRun(el, _ctx) {
|
|
|
16622
16541
|
* Convert parsed run data into an RunOptions suitable for the Document constructor.
|
|
16623
16542
|
* Simplifies the parsed children into text + break format.
|
|
16624
16543
|
* If the run contains only a commentReference, returns { commentReference: id } instead.
|
|
16544
|
+
* If the run only contains footnoteRef/endnoteRef (auto-generated), returns empty options.
|
|
16625
16545
|
*/
|
|
16626
16546
|
function parsedRunToOptions(parsed) {
|
|
16547
|
+
const contentChildren = parsed.children.filter((c) => c !== PARSED_FOOTNOTE_REF);
|
|
16548
|
+
if (contentChildren.length === 0 && parsed.children.some((c) => c === PARSED_FOOTNOTE_REF)) return null;
|
|
16627
16549
|
const opts = { ...parsed.properties };
|
|
16628
|
-
const
|
|
16629
|
-
const
|
|
16630
|
-
|
|
16550
|
+
const isRefChild = (c) => typeof c === "object" && c !== null && ("commentReference" in c || "footnoteReference" in c || "endnoteReference" in c);
|
|
16551
|
+
const refChildren = contentChildren.filter(isRefChild);
|
|
16552
|
+
const nonRefChildren = contentChildren.filter((c) => !isRefChild(c));
|
|
16553
|
+
if (refChildren.length > 0 && nonRefChildren.length === 0) return refChildren[0];
|
|
16554
|
+
const symbolIdx = nonRefChildren.findIndex((c) => typeof c === "object" && c !== null && "symbolRun" in c);
|
|
16555
|
+
if (symbolIdx >= 0 && nonRefChildren.length === 1 && !parsed.properties) return nonRefChildren[symbolIdx];
|
|
16631
16556
|
const textParts = [];
|
|
16632
16557
|
let breakCount = 0;
|
|
16633
|
-
|
|
16558
|
+
let hasPageBreak = false;
|
|
16559
|
+
let hasColumnBreak = false;
|
|
16560
|
+
for (const child of nonRefChildren) if (typeof child === "string") textParts.push(child);
|
|
16634
16561
|
else if (child === PARSED_LINE_BREAK) breakCount++;
|
|
16562
|
+
else if (child === PARSED_PAGE_BREAK) hasPageBreak = true;
|
|
16563
|
+
else if (child === PARSED_COLUMN_BREAK) hasColumnBreak = true;
|
|
16635
16564
|
if (textParts.length > 0) opts.text = textParts.join("");
|
|
16636
16565
|
if (breakCount > 0) opts.break = breakCount;
|
|
16566
|
+
if (hasPageBreak) opts.pageBreak = true;
|
|
16567
|
+
if (hasColumnBreak) opts.columnBreak = true;
|
|
16568
|
+
if (Object.keys(opts).length === 0 && textParts.length === 0 && breakCount === 0 && !hasPageBreak && !hasColumnBreak) return null;
|
|
16637
16569
|
return opts;
|
|
16638
16570
|
}
|
|
16639
16571
|
//#endregion
|
|
@@ -16709,7 +16641,28 @@ function parseParagraphProperties(el, _ctx) {
|
|
|
16709
16641
|
const numPr = findChild(el, "w:numPr");
|
|
16710
16642
|
if (numPr) {
|
|
16711
16643
|
const ilvl = findChild(numPr, "w:ilvl");
|
|
16712
|
-
|
|
16644
|
+
const level = ilvl ? attrNum(ilvl, "w:val") ?? 0 : 0;
|
|
16645
|
+
const numIdEl = findChild(numPr, "w:numId");
|
|
16646
|
+
const numId = numIdEl ? attr(numIdEl, "w:val") : void 0;
|
|
16647
|
+
if (numId !== void 0 && _ctx.numberingCache.size > 0) {
|
|
16648
|
+
const numEl = _ctx.docx.numbering;
|
|
16649
|
+
if (numEl) {
|
|
16650
|
+
let abstractNumId;
|
|
16651
|
+
for (const child of numEl.elements ?? []) {
|
|
16652
|
+
if (child.name !== "w:num") continue;
|
|
16653
|
+
if (attr(child, "w:numId") === numId) {
|
|
16654
|
+
const absRef = findChild(child, "w:abstractNumId");
|
|
16655
|
+
abstractNumId = absRef ? attr(absRef, "w:val") : void 0;
|
|
16656
|
+
break;
|
|
16657
|
+
}
|
|
16658
|
+
}
|
|
16659
|
+
if (abstractNumId !== void 0) opts.numbering = {
|
|
16660
|
+
reference: `list_${numId}`,
|
|
16661
|
+
level
|
|
16662
|
+
};
|
|
16663
|
+
else opts.bullet = { level };
|
|
16664
|
+
} else opts.bullet = { level };
|
|
16665
|
+
} else opts.bullet = { level };
|
|
16713
16666
|
}
|
|
16714
16667
|
const tabs = findChild(el, "w:tabs");
|
|
16715
16668
|
if (tabs) {
|
|
@@ -16838,27 +16791,60 @@ function parseParagraph(el, ctx) {
|
|
|
16838
16791
|
for (const child of el.elements ?? []) switch (child.name) {
|
|
16839
16792
|
case "w:pPr": break;
|
|
16840
16793
|
case "w:r": {
|
|
16794
|
+
const drawingEl = findChild(child, "w:drawing");
|
|
16795
|
+
if (drawingEl) {
|
|
16796
|
+
const drawingChild = parseDrawingRun(drawingEl, ctx);
|
|
16797
|
+
if (drawingChild) {
|
|
16798
|
+
childList.push(drawingChild);
|
|
16799
|
+
break;
|
|
16800
|
+
}
|
|
16801
|
+
}
|
|
16841
16802
|
const parsed = parseRun(child, ctx);
|
|
16842
16803
|
const rawChildren = parsed.children.filter((c) => c instanceof RawPassthrough);
|
|
16843
16804
|
const runOpts = parsedRunToOptions({
|
|
16844
16805
|
...parsed,
|
|
16845
16806
|
children: parsed.children.filter((c) => !(c instanceof RawPassthrough))
|
|
16846
16807
|
});
|
|
16847
|
-
childList.push(runOpts);
|
|
16808
|
+
if (runOpts !== null) childList.push(runOpts);
|
|
16848
16809
|
childList.push(...rawChildren);
|
|
16849
16810
|
break;
|
|
16850
16811
|
}
|
|
16851
16812
|
case "w:hyperlink": {
|
|
16813
|
+
const hl = {};
|
|
16814
|
+
const rId = attr(child, "r:id");
|
|
16815
|
+
if (rId) {
|
|
16816
|
+
const target = ctx.docx.partRefs.hyperlinks.get(rId);
|
|
16817
|
+
if (target) hl.link = target;
|
|
16818
|
+
}
|
|
16819
|
+
const anchor = attr(child, "w:anchor");
|
|
16820
|
+
if (anchor) hl.anchor = anchor;
|
|
16821
|
+
const tooltip = attr(child, "w:tooltip");
|
|
16822
|
+
if (tooltip) hl.tooltip = tooltip;
|
|
16852
16823
|
const linkRuns = [];
|
|
16853
16824
|
for (const sub of child.elements ?? []) if (sub.name === "w:r") {
|
|
16854
16825
|
const runOpts = parsedRunToOptions(parseRun(sub, ctx));
|
|
16855
16826
|
linkRuns.push(runOpts);
|
|
16856
16827
|
}
|
|
16857
|
-
|
|
16828
|
+
if (linkRuns.length > 0) {
|
|
16829
|
+
hl.children = linkRuns;
|
|
16830
|
+
childList.push({ hyperlink: hl });
|
|
16831
|
+
}
|
|
16832
|
+
break;
|
|
16833
|
+
}
|
|
16834
|
+
case "w:bookmarkStart": {
|
|
16835
|
+
const id = attrNum(child, "w:id");
|
|
16836
|
+
const name = attr(child, "w:name");
|
|
16837
|
+
if (id !== void 0 && name) childList.push({ bookmarkStart: {
|
|
16838
|
+
id,
|
|
16839
|
+
name
|
|
16840
|
+
} });
|
|
16841
|
+
break;
|
|
16842
|
+
}
|
|
16843
|
+
case "w:bookmarkEnd": {
|
|
16844
|
+
const id = attrNum(child, "w:id");
|
|
16845
|
+
if (id !== void 0) childList.push({ bookmarkEnd: id });
|
|
16858
16846
|
break;
|
|
16859
16847
|
}
|
|
16860
|
-
case "w:bookmarkStart":
|
|
16861
|
-
case "w:bookmarkEnd": break;
|
|
16862
16848
|
case "w:commentRangeStart": {
|
|
16863
16849
|
const id = attrNum(child, "w:id");
|
|
16864
16850
|
if (id !== void 0) childList.push({ commentRangeStart: id });
|
|
@@ -16879,12 +16865,38 @@ function parseParagraph(el, ctx) {
|
|
|
16879
16865
|
childList.push({ math: { children: mathChildren } });
|
|
16880
16866
|
break;
|
|
16881
16867
|
}
|
|
16868
|
+
case "w:ins": {
|
|
16869
|
+
const insRun = findChild(child, "w:r");
|
|
16870
|
+
if (insRun) {
|
|
16871
|
+
const runOpts = parsedRunToOptions(parseRun(insRun, ctx));
|
|
16872
|
+
if (runOpts !== null && typeof runOpts === "object" && !("commentReference" in runOpts)) childList.push({ insertion: {
|
|
16873
|
+
id: attrNum(child, "w:id") ?? 0,
|
|
16874
|
+
author: attr(child, "w:author") ?? "",
|
|
16875
|
+
date: attr(child, "w:date") ?? "",
|
|
16876
|
+
...runOpts
|
|
16877
|
+
} });
|
|
16878
|
+
}
|
|
16879
|
+
break;
|
|
16880
|
+
}
|
|
16881
|
+
case "w:del": {
|
|
16882
|
+
const delRun = findChild(child, "w:r");
|
|
16883
|
+
if (delRun) {
|
|
16884
|
+
const runOpts = parsedRunToOptions(parseRun(delRun, ctx));
|
|
16885
|
+
if (runOpts !== null && typeof runOpts === "object" && !("commentReference" in runOpts)) childList.push({ deletion: {
|
|
16886
|
+
id: attrNum(child, "w:id") ?? 0,
|
|
16887
|
+
author: attr(child, "w:author") ?? "",
|
|
16888
|
+
date: attr(child, "w:date") ?? "",
|
|
16889
|
+
...runOpts
|
|
16890
|
+
} });
|
|
16891
|
+
}
|
|
16892
|
+
break;
|
|
16893
|
+
}
|
|
16882
16894
|
default:
|
|
16883
16895
|
if (child.name && child.elements && child.elements.length > 0) childList.push(new RawPassthrough(child));
|
|
16884
16896
|
break;
|
|
16885
16897
|
}
|
|
16886
16898
|
if (childList.length > 0) {
|
|
16887
|
-
if (childList.every((c) => typeof c === "object" && c !== null && "text" in c && Object.keys(c).length
|
|
16899
|
+
if (childList.every((c) => typeof c === "object" && c !== null && "text" in c && Object.keys(c).length === 1)) {
|
|
16888
16900
|
const combined = childList.map((c) => c.text).join("");
|
|
16889
16901
|
if (combined && Object.keys(opts).length === 0) return combined;
|
|
16890
16902
|
if (combined) {
|
|
@@ -16897,6 +16909,49 @@ function parseParagraph(el, ctx) {
|
|
|
16897
16909
|
return opts;
|
|
16898
16910
|
}
|
|
16899
16911
|
//#endregion
|
|
16912
|
+
//#region src/file/alt-chunk/alt-chunk-parse.ts
|
|
16913
|
+
/**
|
|
16914
|
+
* AltChunk parser for DOCX documents.
|
|
16915
|
+
*
|
|
16916
|
+
* Parses w:altChunk elements and extracts embedded content from the ZIP.
|
|
16917
|
+
*
|
|
16918
|
+
* @module
|
|
16919
|
+
*/
|
|
16920
|
+
/**
|
|
16921
|
+
* Parse a w:altChunk element into AltChunkOptions.
|
|
16922
|
+
* Reads the referenced data from the ZIP package.
|
|
16923
|
+
*/
|
|
16924
|
+
function parseAltChunk(el, ctx) {
|
|
16925
|
+
const rId = attr(el, "r:id");
|
|
16926
|
+
if (!rId) throw new Error("w:altChunk missing r:id attribute");
|
|
16927
|
+
const path = ctx.docx.partRefs.afChunks.get(rId);
|
|
16928
|
+
if (!path) throw new Error(`AltChunk relationship ${rId} not found`);
|
|
16929
|
+
const data = ctx.docx.doc.getRaw(path);
|
|
16930
|
+
if (!data) throw new Error(`AltChunk data not found at ${path}`);
|
|
16931
|
+
const ext = path.split(".").pop() ?? "txt";
|
|
16932
|
+
let contentType;
|
|
16933
|
+
let extension;
|
|
16934
|
+
switch (ext) {
|
|
16935
|
+
case "html":
|
|
16936
|
+
contentType = "text/html";
|
|
16937
|
+
extension = "html";
|
|
16938
|
+
break;
|
|
16939
|
+
case "rtf":
|
|
16940
|
+
contentType = "application/rtf";
|
|
16941
|
+
extension = "rtf";
|
|
16942
|
+
break;
|
|
16943
|
+
default:
|
|
16944
|
+
contentType = "text/plain";
|
|
16945
|
+
extension = "txt";
|
|
16946
|
+
break;
|
|
16947
|
+
}
|
|
16948
|
+
return {
|
|
16949
|
+
data,
|
|
16950
|
+
contentType,
|
|
16951
|
+
extension
|
|
16952
|
+
};
|
|
16953
|
+
}
|
|
16954
|
+
//#endregion
|
|
16900
16955
|
//#region src/file/sdt/sdt-parse.ts
|
|
16901
16956
|
/**
|
|
16902
16957
|
* Structured Document Tag parser for DOCX documents.
|
|
@@ -17181,8 +17236,9 @@ function parseTableProperties(el) {
|
|
|
17181
17236
|
}
|
|
17182
17237
|
const tblW = findChild(el, "w:tblW");
|
|
17183
17238
|
if (tblW) {
|
|
17184
|
-
const
|
|
17239
|
+
const rawSize = attr(tblW, "w:w");
|
|
17185
17240
|
const type = attr(tblW, "w:type");
|
|
17241
|
+
const size = type === "pct" ? rawSize : attrNum(tblW, "w:w");
|
|
17186
17242
|
if (size !== void 0 || type) opts.width = {
|
|
17187
17243
|
size: size ?? 0,
|
|
17188
17244
|
...type ? { type } : {}
|
|
@@ -17353,6 +17409,29 @@ function parseTableCellProperties(el) {
|
|
|
17353
17409
|
if (Object.keys(borders).length > 0) opts.borders = borders;
|
|
17354
17410
|
}
|
|
17355
17411
|
if (findChild(el, "w:noWrap")) opts.noWrap = true;
|
|
17412
|
+
const tcMar = findChild(el, "w:tcMar");
|
|
17413
|
+
if (tcMar) {
|
|
17414
|
+
const margins = {};
|
|
17415
|
+
let marginUnitType;
|
|
17416
|
+
for (const side of [
|
|
17417
|
+
"top",
|
|
17418
|
+
"bottom",
|
|
17419
|
+
"left",
|
|
17420
|
+
"right"
|
|
17421
|
+
]) {
|
|
17422
|
+
const sideEl = findChild(tcMar, `w:${side}`);
|
|
17423
|
+
if (sideEl) {
|
|
17424
|
+
const size = attrNum(sideEl, "w:w");
|
|
17425
|
+
const type = attr(sideEl, "w:type");
|
|
17426
|
+
if (size !== void 0) {
|
|
17427
|
+
margins[side] = size;
|
|
17428
|
+
if (type && !marginUnitType) marginUnitType = type;
|
|
17429
|
+
}
|
|
17430
|
+
}
|
|
17431
|
+
}
|
|
17432
|
+
if (marginUnitType) margins.marginUnitType = marginUnitType;
|
|
17433
|
+
if (Object.keys(margins).length > 0) opts.margins = margins;
|
|
17434
|
+
}
|
|
17356
17435
|
const textDirection = findChild(el, "w:textDirection");
|
|
17357
17436
|
if (textDirection) {
|
|
17358
17437
|
const val = attr(textDirection, "w:val");
|
|
@@ -17496,10 +17575,15 @@ function parseSectionProperties(el, ctx) {
|
|
|
17496
17575
|
const page = {};
|
|
17497
17576
|
const size = {};
|
|
17498
17577
|
const w = attrNum(pgSz, "w:w");
|
|
17499
|
-
if (w !== void 0) size.width = w;
|
|
17500
17578
|
const h = attrNum(pgSz, "w:h");
|
|
17501
|
-
if (h !== void 0) size.height = h;
|
|
17502
17579
|
const orient = attr(pgSz, "w:orient");
|
|
17580
|
+
if (orient === "landscape" && w !== void 0 && h !== void 0) {
|
|
17581
|
+
size.width = h;
|
|
17582
|
+
size.height = w;
|
|
17583
|
+
} else {
|
|
17584
|
+
if (w !== void 0) size.width = w;
|
|
17585
|
+
if (h !== void 0) size.height = h;
|
|
17586
|
+
}
|
|
17503
17587
|
if (orient) size.orientation = orient;
|
|
17504
17588
|
if (Object.keys(size).length > 0) page.size = size;
|
|
17505
17589
|
const pgMar = findChild(el, "w:pgMar");
|
|
@@ -17570,8 +17654,8 @@ function parseSectionProperties(el, ctx) {
|
|
|
17570
17654
|
const lnNumType = findChild(el, "w:lnNumType");
|
|
17571
17655
|
if (lnNumType) {
|
|
17572
17656
|
const lineNumbers = {};
|
|
17573
|
-
const
|
|
17574
|
-
if (
|
|
17657
|
+
const countBy = attrNum(lnNumType, "w:countBy");
|
|
17658
|
+
if (countBy !== void 0) lineNumbers.countBy = countBy;
|
|
17575
17659
|
const start = attrNum(lnNumType, "w:start");
|
|
17576
17660
|
if (start !== void 0) lineNumbers.start = start;
|
|
17577
17661
|
const restart = attr(lnNumType, "w:restart");
|
|
@@ -17580,6 +17664,41 @@ function parseSectionProperties(el, ctx) {
|
|
|
17580
17664
|
if (distance !== void 0) lineNumbers.distance = distance;
|
|
17581
17665
|
if (Object.keys(lineNumbers).length > 0) opts.lineNumbers = lineNumbers;
|
|
17582
17666
|
}
|
|
17667
|
+
const pgBorders = findChild(el, "w:pgBorders");
|
|
17668
|
+
if (pgBorders) {
|
|
17669
|
+
const borders = {};
|
|
17670
|
+
for (const side of [
|
|
17671
|
+
"top",
|
|
17672
|
+
"left",
|
|
17673
|
+
"bottom",
|
|
17674
|
+
"right"
|
|
17675
|
+
]) {
|
|
17676
|
+
const sideEl = findChild(pgBorders, `w:${side}`);
|
|
17677
|
+
if (sideEl) {
|
|
17678
|
+
const b = {};
|
|
17679
|
+
const val = attr(sideEl, "w:val");
|
|
17680
|
+
if (val) b.style = val;
|
|
17681
|
+
const color = attr(sideEl, "w:color");
|
|
17682
|
+
if (color) b.color = color;
|
|
17683
|
+
const sz = attrNum(sideEl, "w:sz");
|
|
17684
|
+
if (sz !== void 0) b.size = sz;
|
|
17685
|
+
const space = attrNum(sideEl, "w:space");
|
|
17686
|
+
if (space !== void 0) b.space = space;
|
|
17687
|
+
borders[side] = b;
|
|
17688
|
+
}
|
|
17689
|
+
}
|
|
17690
|
+
const display = attr(pgBorders, "w:display");
|
|
17691
|
+
if (display) borders.display = display;
|
|
17692
|
+
const offsetFrom = attr(pgBorders, "w:offsetFrom");
|
|
17693
|
+
if (offsetFrom) borders.offsetFrom = offsetFrom;
|
|
17694
|
+
const zOrder = attr(pgBorders, "w:zOrder");
|
|
17695
|
+
if (zOrder) borders.zOrder = zOrder;
|
|
17696
|
+
if (Object.keys(borders).length > 0) {
|
|
17697
|
+
const page = opts.page ?? {};
|
|
17698
|
+
page.borders = borders;
|
|
17699
|
+
opts.page = page;
|
|
17700
|
+
}
|
|
17701
|
+
}
|
|
17583
17702
|
const vAlign = findChild(el, "w:vAlign");
|
|
17584
17703
|
if (vAlign) {
|
|
17585
17704
|
const val = attr(vAlign, "w:val");
|
|
@@ -17630,18 +17749,6 @@ function parseHeaderFooterRef(rId, ctx) {
|
|
|
17630
17749
|
function parseSectionChild(el, ctx) {
|
|
17631
17750
|
switch (el.name) {
|
|
17632
17751
|
case "w:p": {
|
|
17633
|
-
const drawing = findDeepElement(el, "w:drawing");
|
|
17634
|
-
if (drawing) {
|
|
17635
|
-
const drawingChild = parseDrawingRun(drawing, ctx);
|
|
17636
|
-
if (drawingChild) {
|
|
17637
|
-
const paraOpts = parseParagraph(el, ctx);
|
|
17638
|
-
const existingChildren = paraOpts.children ?? [];
|
|
17639
|
-
return { paragraph: {
|
|
17640
|
-
...paraOpts,
|
|
17641
|
-
children: [...existingChildren ?? [], drawingChild]
|
|
17642
|
-
} };
|
|
17643
|
-
}
|
|
17644
|
-
}
|
|
17645
17752
|
const pict = findChild(el, "w:pict");
|
|
17646
17753
|
if (pict) {
|
|
17647
17754
|
if (findDeepElement(pict, "v:textbox")) return { textbox: parseTextbox(pict, ctx) };
|
|
@@ -17708,7 +17815,8 @@ function parseBody(body, ctx) {
|
|
|
17708
17815
|
let start = 0;
|
|
17709
17816
|
for (let i = 0; i < boundaries.length; i++) {
|
|
17710
17817
|
const boundary = boundaries[i];
|
|
17711
|
-
const
|
|
17818
|
+
const endIdx = i < boundaries.length - 1 ? Math.max(start, boundary.index - 1) : boundary.index;
|
|
17819
|
+
const sectionElements = bodyChildren.slice(start, endIdx);
|
|
17712
17820
|
const parsedProps = parseSectionProperties(boundary.sectPr, ctx);
|
|
17713
17821
|
const rawProps = parsedProps;
|
|
17714
17822
|
const parsedHeaders = rawProps.parsedHeaders;
|
|
@@ -17763,6 +17871,136 @@ function parseCustomProperties(el) {
|
|
|
17763
17871
|
return result;
|
|
17764
17872
|
}
|
|
17765
17873
|
//#endregion
|
|
17874
|
+
//#region src/parse/numbering.ts
|
|
17875
|
+
/**
|
|
17876
|
+
* Numbering definition parser for DOCX documents.
|
|
17877
|
+
*
|
|
17878
|
+
* Parses w:numbering elements into NumberingOptions objects for round-trip fidelity.
|
|
17879
|
+
*
|
|
17880
|
+
* @module
|
|
17881
|
+
*/
|
|
17882
|
+
/**
|
|
17883
|
+
* Parse w:numbering element into NumberingOptions.
|
|
17884
|
+
*/
|
|
17885
|
+
function parseNumberingDefinitions(el) {
|
|
17886
|
+
const abstractNums = /* @__PURE__ */ new Map();
|
|
17887
|
+
for (const child of el.elements ?? []) {
|
|
17888
|
+
if (child.name !== "w:abstractNum") continue;
|
|
17889
|
+
const id = attr(child, "w:abstractNumId");
|
|
17890
|
+
if (id !== void 0) abstractNums.set(id, child);
|
|
17891
|
+
}
|
|
17892
|
+
const numToAbstract = /* @__PURE__ */ new Map();
|
|
17893
|
+
for (const child of el.elements ?? []) {
|
|
17894
|
+
if (child.name !== "w:num") continue;
|
|
17895
|
+
const numId = attr(child, "w:numId");
|
|
17896
|
+
const abstractRef = findChild(child, "w:abstractNumId");
|
|
17897
|
+
const abstractId = abstractRef ? attr(abstractRef, "w:val") : void 0;
|
|
17898
|
+
if (numId !== void 0 && abstractId !== void 0) numToAbstract.set(numId, abstractId);
|
|
17899
|
+
}
|
|
17900
|
+
const configs = [];
|
|
17901
|
+
for (const [numId, abstractId] of numToAbstract) {
|
|
17902
|
+
const abstractEl = abstractNums.get(abstractId);
|
|
17903
|
+
if (!abstractEl) continue;
|
|
17904
|
+
const levels = [];
|
|
17905
|
+
for (const child of abstractEl.elements ?? []) {
|
|
17906
|
+
if (child.name !== "w:lvl") continue;
|
|
17907
|
+
const levelOpts = parseLevel(child);
|
|
17908
|
+
if (levelOpts) levels.push(levelOpts);
|
|
17909
|
+
}
|
|
17910
|
+
if (levels.length > 0 && levels.every((l) => l.format === "bullet")) continue;
|
|
17911
|
+
if (levels.length > 0) configs.push({
|
|
17912
|
+
reference: `list_${numId}`,
|
|
17913
|
+
levels
|
|
17914
|
+
});
|
|
17915
|
+
}
|
|
17916
|
+
if (configs.length === 0) return void 0;
|
|
17917
|
+
return { config: configs };
|
|
17918
|
+
}
|
|
17919
|
+
function parseLevel(el) {
|
|
17920
|
+
const opts = {};
|
|
17921
|
+
const level = attrNum(el, "w:ilvl");
|
|
17922
|
+
if (level !== void 0) opts.level = level;
|
|
17923
|
+
const start = findChild(el, "w:start");
|
|
17924
|
+
if (start) {
|
|
17925
|
+
const val = attrNum(start, "w:val");
|
|
17926
|
+
if (val !== void 0) opts.start = val;
|
|
17927
|
+
}
|
|
17928
|
+
const numFmt = findChild(el, "w:numFmt");
|
|
17929
|
+
if (numFmt) {
|
|
17930
|
+
const val = attr(numFmt, "w:val");
|
|
17931
|
+
if (val) opts.format = val;
|
|
17932
|
+
}
|
|
17933
|
+
const lvlText = findChild(el, "w:lvlText");
|
|
17934
|
+
if (lvlText) {
|
|
17935
|
+
const val = attr(lvlText, "w:val");
|
|
17936
|
+
if (val) opts.text = val;
|
|
17937
|
+
}
|
|
17938
|
+
const lvlJc = findChild(el, "w:lvlJc");
|
|
17939
|
+
if (lvlJc) {
|
|
17940
|
+
const val = attr(lvlJc, "w:val");
|
|
17941
|
+
if (val) opts.alignment = val;
|
|
17942
|
+
}
|
|
17943
|
+
const suff = findChild(el, "w:suff");
|
|
17944
|
+
if (suff) {
|
|
17945
|
+
const val = attr(suff, "w:val");
|
|
17946
|
+
if (val) opts.suffix = val;
|
|
17947
|
+
}
|
|
17948
|
+
if (findChild(el, "w:isLgl")) opts.isLegalNumberingStyle = true;
|
|
17949
|
+
const rPr = findChild(el, "w:rPr");
|
|
17950
|
+
if (rPr) {
|
|
17951
|
+
const style = {};
|
|
17952
|
+
const sz = findChild(rPr, "w:sz");
|
|
17953
|
+
if (sz) {
|
|
17954
|
+
const val = attrNum(sz, "w:val");
|
|
17955
|
+
if (val !== void 0) {
|
|
17956
|
+
if (!style.run) style.run = {};
|
|
17957
|
+
style.run.size = val;
|
|
17958
|
+
}
|
|
17959
|
+
}
|
|
17960
|
+
const rFonts = findChild(rPr, "w:rFonts");
|
|
17961
|
+
if (rFonts) {
|
|
17962
|
+
const ascii = attr(rFonts, "w:ascii");
|
|
17963
|
+
if (ascii) {
|
|
17964
|
+
if (!style.run) style.run = {};
|
|
17965
|
+
style.run.font = ascii;
|
|
17966
|
+
}
|
|
17967
|
+
}
|
|
17968
|
+
if (Object.keys(style).length > 0) opts.style = style;
|
|
17969
|
+
}
|
|
17970
|
+
const pPr = findChild(el, "w:pPr");
|
|
17971
|
+
if (pPr) {
|
|
17972
|
+
const style = opts.style ?? {};
|
|
17973
|
+
const paraStyle = {};
|
|
17974
|
+
const ind = findChild(pPr, "w:ind");
|
|
17975
|
+
if (ind) {
|
|
17976
|
+
const indent = {};
|
|
17977
|
+
const left = attrNum(ind, "w:left");
|
|
17978
|
+
if (left !== void 0) indent.left = left;
|
|
17979
|
+
const hanging = attrNum(ind, "w:hanging");
|
|
17980
|
+
if (hanging !== void 0) indent.hanging = hanging;
|
|
17981
|
+
if (Object.keys(indent).length > 0) paraStyle.indent = indent;
|
|
17982
|
+
}
|
|
17983
|
+
if (findChild(pPr, "w:tabs")) {
|
|
17984
|
+
const tabStops = [];
|
|
17985
|
+
for (const tab of pPr.elements ?? []) {
|
|
17986
|
+
if (tab.name !== "w:tab") continue;
|
|
17987
|
+
const tabObj = {};
|
|
17988
|
+
const pos = attrNum(tab, "w:pos");
|
|
17989
|
+
if (pos !== void 0) tabObj.position = pos;
|
|
17990
|
+
const val = attr(tab, "w:val");
|
|
17991
|
+
if (val) tabObj.type = val;
|
|
17992
|
+
tabStops.push(tabObj);
|
|
17993
|
+
}
|
|
17994
|
+
if (tabStops.length > 0) paraStyle.tabStops = tabStops;
|
|
17995
|
+
}
|
|
17996
|
+
if (Object.keys(paraStyle).length > 0) {
|
|
17997
|
+
style.paragraph = paraStyle;
|
|
17998
|
+
opts.style = style;
|
|
17999
|
+
}
|
|
18000
|
+
}
|
|
18001
|
+
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
18002
|
+
}
|
|
18003
|
+
//#endregion
|
|
17766
18004
|
//#region src/parse/settings.ts
|
|
17767
18005
|
/**
|
|
17768
18006
|
* Parse word/settings.xml Element into PropertiesOptions fields.
|
|
@@ -17770,7 +18008,11 @@ function parseCustomProperties(el) {
|
|
|
17770
18008
|
function parseSettings(el) {
|
|
17771
18009
|
if (!el) return {};
|
|
17772
18010
|
const opts = {};
|
|
17773
|
-
|
|
18011
|
+
const eohEl = findChild(el, "w:evenAndOddHeaders");
|
|
18012
|
+
if (eohEl) {
|
|
18013
|
+
const val = attr(eohEl, "w:val");
|
|
18014
|
+
opts.evenAndOddHeaderAndFooters = val !== "false" && val !== "0" && val !== "off";
|
|
18015
|
+
}
|
|
17774
18016
|
const viewEl = findChild(el, "w:view");
|
|
17775
18017
|
if (viewEl) {
|
|
17776
18018
|
const val = attr(viewEl, "w:val");
|
|
@@ -17822,15 +18064,6 @@ function parseSettings(el) {
|
|
|
17822
18064
|
}
|
|
17823
18065
|
if (vars.length > 0) opts.docVars = vars;
|
|
17824
18066
|
}
|
|
17825
|
-
const bgEl = findChild(el, "w:background");
|
|
17826
|
-
if (bgEl) {
|
|
17827
|
-
const bg = {};
|
|
17828
|
-
const color = attr(bgEl, "w:color");
|
|
17829
|
-
if (color) bg.color = color;
|
|
17830
|
-
const themeColor = attr(bgEl, "w:themeColor");
|
|
17831
|
-
if (themeColor) bg.themeColor = themeColor;
|
|
17832
|
-
if (Object.keys(bg).length > 0) opts.background = bg;
|
|
17833
|
-
}
|
|
17834
18067
|
const cscEl = findChild(el, "w:characterSpacingControl");
|
|
17835
18068
|
if (cscEl) {
|
|
17836
18069
|
const val = attr(cscEl, "w:val");
|
|
@@ -17845,10 +18078,11 @@ function parseSettings(el) {
|
|
|
17845
18078
|
//#endregion
|
|
17846
18079
|
//#region src/parse/styles.ts
|
|
17847
18080
|
/**
|
|
17848
|
-
* Style cache builder for DOCX
|
|
18081
|
+
* Style cache builder and definition parser for DOCX documents.
|
|
17849
18082
|
*
|
|
17850
18083
|
* Builds lookup maps from parsed styles.xml and numbering.xml elements
|
|
17851
18084
|
* for efficient style resolution during document parsing.
|
|
18085
|
+
* Also parses full style definitions into StylesOptions for round-trip fidelity.
|
|
17852
18086
|
*
|
|
17853
18087
|
* @module
|
|
17854
18088
|
*/
|
|
@@ -17861,8 +18095,7 @@ function buildStyleCache(docx) {
|
|
|
17861
18095
|
if (!docx.styles) return cache;
|
|
17862
18096
|
for (const child of docx.styles.elements ?? []) {
|
|
17863
18097
|
if (child.name !== "w:style") continue;
|
|
17864
|
-
const
|
|
17865
|
-
const styleId = styleIdEl ? attr(styleIdEl, "w:val") : void 0;
|
|
18098
|
+
const styleId = attr(child, "w:styleId");
|
|
17866
18099
|
if (styleId) cache.set(styleId, child);
|
|
17867
18100
|
}
|
|
17868
18101
|
return cache;
|
|
@@ -17881,6 +18114,133 @@ function buildNumberingCache(docx) {
|
|
|
17881
18114
|
}
|
|
17882
18115
|
return cache;
|
|
17883
18116
|
}
|
|
18117
|
+
/** Style IDs generated by DefaultStylesFactory — skip these during parsing. */
|
|
18118
|
+
const BUILTIN_STYLE_IDS = new Set([
|
|
18119
|
+
"Title",
|
|
18120
|
+
"Heading1",
|
|
18121
|
+
"Heading2",
|
|
18122
|
+
"Heading3",
|
|
18123
|
+
"Heading4",
|
|
18124
|
+
"Heading5",
|
|
18125
|
+
"Heading6",
|
|
18126
|
+
"Strong",
|
|
18127
|
+
"ListParagraph",
|
|
18128
|
+
"Hyperlink",
|
|
18129
|
+
"FootnoteText",
|
|
18130
|
+
"FootnoteTextChar",
|
|
18131
|
+
"EndnoteText",
|
|
18132
|
+
"EndnoteTextChar",
|
|
18133
|
+
"FootnoteReference",
|
|
18134
|
+
"EndnoteReference"
|
|
18135
|
+
]);
|
|
18136
|
+
/**
|
|
18137
|
+
* Parse w:styles element into StylesOptions.
|
|
18138
|
+
*
|
|
18139
|
+
* Skips built-in styles that DefaultStylesFactory already generates,
|
|
18140
|
+
* keeping only user-defined custom styles for round-trip fidelity.
|
|
18141
|
+
*/
|
|
18142
|
+
function parseStyleDefinitions(el, ctx) {
|
|
18143
|
+
const opts = {};
|
|
18144
|
+
const paragraphStyles = [];
|
|
18145
|
+
const characterStyles = [];
|
|
18146
|
+
for (const child of el.elements ?? []) if (child.name === "w:docDefaults") {
|
|
18147
|
+
const defOpts = parseDocDefaults(child);
|
|
18148
|
+
if (defOpts) opts.default = defOpts;
|
|
18149
|
+
} else if (child.name === "w:style") {
|
|
18150
|
+
const styleOpts = parseStyleElement(child, ctx);
|
|
18151
|
+
if (!styleOpts) continue;
|
|
18152
|
+
const styleId = styleOpts.id;
|
|
18153
|
+
if (styleId && BUILTIN_STYLE_IDS.has(styleId)) continue;
|
|
18154
|
+
const type = styleOpts._type;
|
|
18155
|
+
delete styleOpts._type;
|
|
18156
|
+
if (type === "paragraph") paragraphStyles.push(styleOpts);
|
|
18157
|
+
else if (type === "character") characterStyles.push(styleOpts);
|
|
18158
|
+
}
|
|
18159
|
+
if (paragraphStyles.length > 0) opts.paragraphStyles = paragraphStyles;
|
|
18160
|
+
if (characterStyles.length > 0) opts.characterStyles = characterStyles;
|
|
18161
|
+
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
18162
|
+
}
|
|
18163
|
+
function parseDocDefaults(el) {
|
|
18164
|
+
const result = {};
|
|
18165
|
+
const docDefaults = {};
|
|
18166
|
+
const rPrDefault = findChild(el, "w:rPrDefault");
|
|
18167
|
+
if (rPrDefault) {
|
|
18168
|
+
const rPr = findChild(rPrDefault, "w:rPr");
|
|
18169
|
+
if (rPr) {
|
|
18170
|
+
const runDefaults = parseRunProperties(rPr);
|
|
18171
|
+
if (Object.keys(runDefaults).length > 0) docDefaults.run = runDefaults;
|
|
18172
|
+
}
|
|
18173
|
+
}
|
|
18174
|
+
const pPrDefault = findChild(el, "w:pPrDefault");
|
|
18175
|
+
if (pPrDefault) {
|
|
18176
|
+
const pPr = findChild(pPrDefault, "w:pPr");
|
|
18177
|
+
if (pPr) {
|
|
18178
|
+
const paraDefaults = {};
|
|
18179
|
+
const spacing = findChild(pPr, "w:spacing");
|
|
18180
|
+
if (spacing) {
|
|
18181
|
+
const sp = {};
|
|
18182
|
+
const before = attrNum(spacing, "w:before");
|
|
18183
|
+
if (before !== void 0) sp.before = before;
|
|
18184
|
+
const after = attrNum(spacing, "w:after");
|
|
18185
|
+
if (after !== void 0) sp.after = after;
|
|
18186
|
+
const line = attrNum(spacing, "w:line");
|
|
18187
|
+
if (line !== void 0) sp.line = line;
|
|
18188
|
+
if (Object.keys(sp).length > 0) paraDefaults.spacing = sp;
|
|
18189
|
+
}
|
|
18190
|
+
if (Object.keys(paraDefaults).length > 0) docDefaults.paragraph = paraDefaults;
|
|
18191
|
+
}
|
|
18192
|
+
}
|
|
18193
|
+
if (Object.keys(docDefaults).length > 0) result.document = docDefaults;
|
|
18194
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
18195
|
+
}
|
|
18196
|
+
function parseStyleElement(el, ctx) {
|
|
18197
|
+
const opts = {};
|
|
18198
|
+
const type = attr(el, "w:type");
|
|
18199
|
+
if (type) opts._type = type;
|
|
18200
|
+
const id = attr(el, "w:styleId");
|
|
18201
|
+
if (id) opts.id = id;
|
|
18202
|
+
if (attrBool(el, "w:default")) opts.default = true;
|
|
18203
|
+
if (attrBool(el, "w:customStyle")) opts.customStyle = "1";
|
|
18204
|
+
const nameEl = findChild(el, "w:name");
|
|
18205
|
+
if (nameEl) {
|
|
18206
|
+
const name = attr(nameEl, "w:val");
|
|
18207
|
+
if (name) opts.name = name;
|
|
18208
|
+
}
|
|
18209
|
+
const basedOn = findChild(el, "w:basedOn");
|
|
18210
|
+
if (basedOn) {
|
|
18211
|
+
const val = attr(basedOn, "w:val");
|
|
18212
|
+
if (val) opts.basedOn = val;
|
|
18213
|
+
}
|
|
18214
|
+
const next = findChild(el, "w:next");
|
|
18215
|
+
if (next) {
|
|
18216
|
+
const val = attr(next, "w:val");
|
|
18217
|
+
if (val) opts.next = val;
|
|
18218
|
+
}
|
|
18219
|
+
const link = findChild(el, "w:link");
|
|
18220
|
+
if (link) {
|
|
18221
|
+
const val = attr(link, "w:val");
|
|
18222
|
+
if (val) opts.link = val;
|
|
18223
|
+
}
|
|
18224
|
+
const uiPriority = findChild(el, "w:uiPriority");
|
|
18225
|
+
if (uiPriority) {
|
|
18226
|
+
const val = attrNum(uiPriority, "w:val");
|
|
18227
|
+
if (val !== void 0) opts.uiPriority = val;
|
|
18228
|
+
}
|
|
18229
|
+
if (findChild(el, "w:qFormat")) opts.quickFormat = true;
|
|
18230
|
+
if (findChild(el, "w:semiHidden")) opts.semiHidden = true;
|
|
18231
|
+
if (findChild(el, "w:unhideWhenUsed")) opts.unhideWhenUsed = true;
|
|
18232
|
+
const pPr = findChild(el, "w:pPr");
|
|
18233
|
+
if (pPr) {
|
|
18234
|
+
const paraOpts = parseParagraphProperties(pPr, ctx);
|
|
18235
|
+
if (Object.keys(paraOpts).length > 0) opts.paragraph = paraOpts;
|
|
18236
|
+
}
|
|
18237
|
+
const rPr = findChild(el, "w:rPr");
|
|
18238
|
+
if (rPr) {
|
|
18239
|
+
const runOpts = parseRunProperties(rPr);
|
|
18240
|
+
if (Object.keys(runOpts).length > 0) opts.run = runOpts;
|
|
18241
|
+
}
|
|
18242
|
+
return opts;
|
|
18243
|
+
}
|
|
17884
18244
|
//#endregion
|
|
17885
18245
|
//#region src/parse.ts
|
|
17886
18246
|
function resolveRelsPath(target) {
|
|
@@ -17892,6 +18252,7 @@ function parseDocPartRefs(doc) {
|
|
|
17892
18252
|
const refs = {
|
|
17893
18253
|
headers: /* @__PURE__ */ new Map(),
|
|
17894
18254
|
footers: /* @__PURE__ */ new Map(),
|
|
18255
|
+
hyperlinks: /* @__PURE__ */ new Map(),
|
|
17895
18256
|
charts: /* @__PURE__ */ new Map(),
|
|
17896
18257
|
diagramData: /* @__PURE__ */ new Map(),
|
|
17897
18258
|
media: /* @__PURE__ */ new Map(),
|
|
@@ -17917,6 +18278,7 @@ function parseDocPartRefs(doc) {
|
|
|
17917
18278
|
else if (type.includes("/image") || type.includes("/media")) refs.media.set(id, path);
|
|
17918
18279
|
else if (type.includes("/aFChunk")) refs.afChunks.set(id, path);
|
|
17919
18280
|
else if (type.includes("/subDocument")) refs.subDocs.set(id, path);
|
|
18281
|
+
else if (type.includes("/hyperlink")) refs.hyperlinks.set(id, target);
|
|
17920
18282
|
}
|
|
17921
18283
|
return refs;
|
|
17922
18284
|
}
|
|
@@ -17956,6 +18318,12 @@ function parseDocument(data) {
|
|
|
17956
18318
|
const docx = parseDocx(data);
|
|
17957
18319
|
const ctx = new ParseContext(docx, buildStyleCache(docx), buildNumberingCache(docx));
|
|
17958
18320
|
const opts = { sections: parseBody(docx.body, ctx) };
|
|
18321
|
+
if (docx.background) {
|
|
18322
|
+
const bg = {};
|
|
18323
|
+
const color = attr(docx.background, "w:color");
|
|
18324
|
+
if (color) bg.color = color;
|
|
18325
|
+
if (Object.keys(bg).length > 0) opts.background = bg;
|
|
18326
|
+
}
|
|
17959
18327
|
if (docx.coreProps) {
|
|
17960
18328
|
const corePropsEl = docx.doc.get(docx.coreProps);
|
|
17961
18329
|
if (corePropsEl) {
|
|
@@ -17977,14 +18345,48 @@ function parseDocument(data) {
|
|
|
17977
18345
|
if (cpEntries.length > 0) opts.customProperties = cpEntries;
|
|
17978
18346
|
}
|
|
17979
18347
|
}
|
|
18348
|
+
if (docx.partRefs.comments) {
|
|
18349
|
+
const commentsEl = docx.doc.get(docx.partRefs.comments);
|
|
18350
|
+
if (commentsEl) {
|
|
18351
|
+
const comments = parseComments(commentsEl, ctx);
|
|
18352
|
+
if (comments.length > 0) opts.comments = { children: comments };
|
|
18353
|
+
}
|
|
18354
|
+
}
|
|
18355
|
+
if (docx.partRefs.footnotes) {
|
|
18356
|
+
const footnotesEl = docx.doc.get(docx.partRefs.footnotes);
|
|
18357
|
+
if (footnotesEl) {
|
|
18358
|
+
const footnotes = parseNotesContent(footnotesEl, "w:footnote", ctx);
|
|
18359
|
+
const footnotesMap = {};
|
|
18360
|
+
for (const fn of footnotes) footnotesMap[String(fn.id)] = { children: fn.children };
|
|
18361
|
+
if (Object.keys(footnotesMap).length > 0) opts.footnotes = footnotesMap;
|
|
18362
|
+
}
|
|
18363
|
+
}
|
|
18364
|
+
if (docx.partRefs.endnotes) {
|
|
18365
|
+
const endnotesEl = docx.doc.get(docx.partRefs.endnotes);
|
|
18366
|
+
if (endnotesEl) {
|
|
18367
|
+
const endnotes = parseNotesContent(endnotesEl, "w:endnote", ctx);
|
|
18368
|
+
const endnotesMap = {};
|
|
18369
|
+
for (const en of endnotes) endnotesMap[String(en.id)] = { children: en.children };
|
|
18370
|
+
if (Object.keys(endnotesMap).length > 0) opts.endnotes = endnotesMap;
|
|
18371
|
+
}
|
|
18372
|
+
}
|
|
18373
|
+
if (docx.styles) {
|
|
18374
|
+
const styleOpts = parseStyleDefinitions(docx.styles, ctx);
|
|
18375
|
+
if (styleOpts) opts.styles = styleOpts;
|
|
18376
|
+
}
|
|
18377
|
+
if (docx.numbering) {
|
|
18378
|
+
const numOpts = parseNumberingDefinitions(docx.numbering);
|
|
18379
|
+
if (numOpts) opts.numbering = numOpts;
|
|
18380
|
+
}
|
|
17980
18381
|
return opts;
|
|
17981
18382
|
}
|
|
17982
18383
|
function parseDocx(data) {
|
|
17983
|
-
const doc = parseArchive(data);
|
|
18384
|
+
const doc = parseArchive(toUint8Array(data));
|
|
17984
18385
|
const documentEl = doc.get("word/document.xml");
|
|
17985
18386
|
if (!documentEl) throw new Error("word/document.xml not found");
|
|
17986
18387
|
const body = documentEl.elements?.find((e) => e.name === "w:body");
|
|
17987
18388
|
if (!body) throw new Error("w:body not found in word/document.xml");
|
|
18389
|
+
const background = documentEl.elements?.find((e) => e.name === "w:background");
|
|
17988
18390
|
const styles = doc.get("word/styles.xml");
|
|
17989
18391
|
const numbering = doc.get("word/numbering.xml");
|
|
17990
18392
|
const settings = doc.get("word/settings.xml");
|
|
@@ -17995,6 +18397,7 @@ function parseDocx(data) {
|
|
|
17995
18397
|
return {
|
|
17996
18398
|
doc,
|
|
17997
18399
|
body,
|
|
18400
|
+
background,
|
|
17998
18401
|
styles,
|
|
17999
18402
|
numbering,
|
|
18000
18403
|
settings,
|
|
@@ -18006,6 +18409,52 @@ function parseDocx(data) {
|
|
|
18006
18409
|
customProps
|
|
18007
18410
|
};
|
|
18008
18411
|
}
|
|
18412
|
+
/**
|
|
18413
|
+
* Parse w:comments element into CommentOptions array.
|
|
18414
|
+
*/
|
|
18415
|
+
function parseComments(el, ctx) {
|
|
18416
|
+
const comments = [];
|
|
18417
|
+
for (const child of el.elements ?? []) {
|
|
18418
|
+
if (child.name !== "w:comment") continue;
|
|
18419
|
+
const id = attrNum(child, "w:id");
|
|
18420
|
+
if (id === void 0) continue;
|
|
18421
|
+
const author = attr(child, "w:author");
|
|
18422
|
+
const initials = attr(child, "w:initials");
|
|
18423
|
+
const date = attr(child, "w:date");
|
|
18424
|
+
const children = [];
|
|
18425
|
+
for (const sub of child.elements ?? []) if (sub.name === "w:p") children.push(parseParagraph(sub, ctx));
|
|
18426
|
+
comments.push({
|
|
18427
|
+
id,
|
|
18428
|
+
author: author || void 0,
|
|
18429
|
+
initials: initials || void 0,
|
|
18430
|
+
date: date || void 0,
|
|
18431
|
+
children
|
|
18432
|
+
});
|
|
18433
|
+
}
|
|
18434
|
+
return comments;
|
|
18435
|
+
}
|
|
18436
|
+
/**
|
|
18437
|
+
* Parse footnotes or endnotes content into {id, children} array.
|
|
18438
|
+
* Skips system notes (id=-1 for separator, id=0 for continuation separator).
|
|
18439
|
+
*/
|
|
18440
|
+
function parseNotesContent(el, tagName, ctx) {
|
|
18441
|
+
const notes = [];
|
|
18442
|
+
for (const child of el.elements ?? []) {
|
|
18443
|
+
if (child.name !== tagName) continue;
|
|
18444
|
+
const id = attrNum(child, "w:id");
|
|
18445
|
+
if (id === void 0) continue;
|
|
18446
|
+
if (id < 1) continue;
|
|
18447
|
+
const type = attr(child, "w:type");
|
|
18448
|
+
const children = [];
|
|
18449
|
+
for (const sub of child.elements ?? []) if (sub.name === "w:p") children.push(parseParagraph(sub, ctx));
|
|
18450
|
+
notes.push({
|
|
18451
|
+
id,
|
|
18452
|
+
type: type || void 0,
|
|
18453
|
+
children
|
|
18454
|
+
});
|
|
18455
|
+
}
|
|
18456
|
+
return notes;
|
|
18457
|
+
}
|
|
18009
18458
|
//#endregion
|
|
18010
18459
|
//#region src/index.ts
|
|
18011
18460
|
var src_exports = /* @__PURE__ */ __exportAll({
|