@office-open/docx 0.6.3 → 0.6.5
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 +60 -89
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1265 -1751
- 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, DOCX_NS, EMPTY_OBJECT, EmptyElement, Formatter, Formatter as Formatter$1, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, OoxmlMimeType, PrettifyType, RawPassthrough, Relationships, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, appendContentType, appendRelationship, attrObj, chartAttr, convertEmuToPixels, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, createDefault, createOverride, createPacker, createReplacer, createTraverser, getNextRelationshipIndex, 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, toJson, 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,
|
|
@@ -2080,12 +2080,12 @@ var init_non_visual_properties = __esmMin((() => {
|
|
|
2080
2080
|
if (this.hyperlink) {
|
|
2081
2081
|
if (this.hyperlink.click && !hasStackClick) {
|
|
2082
2082
|
const linkId = uniqueId();
|
|
2083
|
-
context.viewWrapper.
|
|
2083
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.click, TargetModeType.EXTERNAL);
|
|
2084
2084
|
this.root.push(buildHyperlinkClickObj(linkId, false));
|
|
2085
2085
|
}
|
|
2086
2086
|
if (this.hyperlink.hover) {
|
|
2087
2087
|
const linkId = uniqueId();
|
|
2088
|
-
context.viewWrapper.
|
|
2088
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE$1, this.hyperlink.hover, TargetModeType.EXTERNAL);
|
|
2089
2089
|
this.root.push(buildHyperlinkHoverObj(linkId, false));
|
|
2090
2090
|
}
|
|
2091
2091
|
}
|
|
@@ -2723,12 +2723,12 @@ var init_doc_properties = __esmMin((() => {
|
|
|
2723
2723
|
if (this.hyperlink) {
|
|
2724
2724
|
if (this.hyperlink.click && !hasStackClick) {
|
|
2725
2725
|
const linkId = uniqueId();
|
|
2726
|
-
context.viewWrapper.
|
|
2726
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.click, TargetModeType.EXTERNAL);
|
|
2727
2727
|
this.root.push(buildHyperlinkClickObj(linkId, true));
|
|
2728
2728
|
}
|
|
2729
2729
|
if (this.hyperlink.hover) {
|
|
2730
2730
|
const linkId = uniqueId();
|
|
2731
|
-
context.viewWrapper.
|
|
2731
|
+
context.viewWrapper.relationships.addRelationship(linkId, HYPERLINK_RELATIONSHIP_TYPE, this.hyperlink.hover, TargetModeType.EXTERNAL);
|
|
2732
2732
|
this.root.push(buildHyperlinkHoverObj(linkId, true));
|
|
2733
2733
|
}
|
|
2734
2734
|
}
|
|
@@ -3010,7 +3010,7 @@ var init_media$1 = __esmMin((() => {
|
|
|
3010
3010
|
*
|
|
3011
3011
|
* @returns Read-only array of all media data in the collection
|
|
3012
3012
|
*/
|
|
3013
|
-
get
|
|
3013
|
+
get array() {
|
|
3014
3014
|
return [...this.map.values()];
|
|
3015
3015
|
}
|
|
3016
3016
|
};
|
|
@@ -3073,8 +3073,8 @@ var init_image_run = __esmMin((() => {
|
|
|
3073
3073
|
this.extraChildren.push(drawing);
|
|
3074
3074
|
}
|
|
3075
3075
|
prepForXml(context) {
|
|
3076
|
-
context.file.
|
|
3077
|
-
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);
|
|
3078
3078
|
return super.prepForXml(context);
|
|
3079
3079
|
}
|
|
3080
3080
|
};
|
|
@@ -3117,7 +3117,7 @@ var init_chart_run = __esmMin((() => {
|
|
|
3117
3117
|
title: this.chartOptions.title,
|
|
3118
3118
|
type: this.chartOptions.type
|
|
3119
3119
|
});
|
|
3120
|
-
context.file.
|
|
3120
|
+
context.file.charts.addChart(this.chartKey, {
|
|
3121
3121
|
chartSpace,
|
|
3122
3122
|
key: this.chartKey
|
|
3123
3123
|
});
|
|
@@ -3174,7 +3174,7 @@ var init_smartart_run = __esmMin((() => {
|
|
|
3174
3174
|
style: styleId,
|
|
3175
3175
|
color: colorId
|
|
3176
3176
|
};
|
|
3177
|
-
context.file.
|
|
3177
|
+
context.file.smartArts.addSmartArt(this.smartArtKey, smartArtData);
|
|
3178
3178
|
return super.prepForXml(context);
|
|
3179
3179
|
}
|
|
3180
3180
|
hashSmartArtData(options) {
|
|
@@ -3242,8 +3242,8 @@ var init_wpg_group_run = __esmMin((() => {
|
|
|
3242
3242
|
}
|
|
3243
3243
|
prepForXml(context) {
|
|
3244
3244
|
this.mediaDatas.forEach((child) => {
|
|
3245
|
-
context.file.
|
|
3246
|
-
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);
|
|
3247
3247
|
});
|
|
3248
3248
|
return super.prepForXml(context);
|
|
3249
3249
|
}
|
|
@@ -3503,12 +3503,9 @@ var init_font_wrapper = __esmMin((() => {
|
|
|
3503
3503
|
this.relationships = new Relationships();
|
|
3504
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`);
|
|
3505
3505
|
}
|
|
3506
|
-
get
|
|
3506
|
+
get view() {
|
|
3507
3507
|
return this.fontTable;
|
|
3508
3508
|
}
|
|
3509
|
-
get Relationships() {
|
|
3510
|
-
return this.relationships;
|
|
3511
|
-
}
|
|
3512
3509
|
};
|
|
3513
3510
|
}));
|
|
3514
3511
|
//#endregion
|
|
@@ -4486,7 +4483,7 @@ var init_math_fraction_properties = __esmMin((() => {
|
|
|
4486
4483
|
if (options.fractionType) children.push(new BuilderElement({
|
|
4487
4484
|
attributes: { val: {
|
|
4488
4485
|
key: "m:val",
|
|
4489
|
-
value:
|
|
4486
|
+
value: options.fractionType
|
|
4490
4487
|
} },
|
|
4491
4488
|
name: "m:type"
|
|
4492
4489
|
}));
|
|
@@ -6287,7 +6284,7 @@ var init_properties = __esmMin((() => {
|
|
|
6287
6284
|
* @returns The prepared XML object, or undefined if the component should be ignored
|
|
6288
6285
|
*/
|
|
6289
6286
|
prepForXml(context) {
|
|
6290
|
-
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);
|
|
6291
6288
|
return super.prepForXml(context);
|
|
6292
6289
|
}
|
|
6293
6290
|
};
|
|
@@ -6346,7 +6343,7 @@ var init_paragraph$1 = __esmMin((() => {
|
|
|
6346
6343
|
prepForXml(context) {
|
|
6347
6344
|
const children = [];
|
|
6348
6345
|
const { xml: pPrObj, numberingReferences } = this._props;
|
|
6349
|
-
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);
|
|
6350
6347
|
let finalPPrObj = pPrObj;
|
|
6351
6348
|
if (this.sectionProperties) {
|
|
6352
6349
|
const sectPrObj = this.sectionProperties.prepForXml(context);
|
|
@@ -6365,7 +6362,7 @@ var init_paragraph$1 = __esmMin((() => {
|
|
|
6365
6362
|
if (this.options.children) for (const rawChild of this.options.children) {
|
|
6366
6363
|
if (rawChild instanceof ExternalHyperlink) {
|
|
6367
6364
|
const concreteHyperlink = new ConcreteHyperlink(rawChild.options.children, uniqueId(), { tooltip: rawChild.options.tooltip });
|
|
6368
|
-
context.viewWrapper.
|
|
6365
|
+
context.viewWrapper.relationships.addRelationship(concreteHyperlink.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", rawChild.options.link, TargetModeType.EXTERNAL);
|
|
6369
6366
|
const obj = concreteHyperlink.prepForXml(context);
|
|
6370
6367
|
if (obj) children.push(obj);
|
|
6371
6368
|
continue;
|
|
@@ -6400,7 +6397,7 @@ var init_paragraph$1 = __esmMin((() => {
|
|
|
6400
6397
|
children: textRuns
|
|
6401
6398
|
});
|
|
6402
6399
|
const concrete = new ConcreteHyperlink(ext.options.children, uniqueId(), { tooltip: ext.options.tooltip });
|
|
6403
|
-
context.viewWrapper.
|
|
6400
|
+
context.viewWrapper.relationships.addRelationship(concrete.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ext.options.link, TargetModeType.EXTERNAL);
|
|
6404
6401
|
const obj = concrete.prepForXml(context);
|
|
6405
6402
|
if (obj) children.push(obj);
|
|
6406
6403
|
} else if ("anchor" in hyperlink) {
|
|
@@ -6528,9 +6525,6 @@ var init_comment_run = __esmMin((() => {
|
|
|
6528
6525
|
for (const child of children) this.root.push(new Comment(child));
|
|
6529
6526
|
this.relationships = new Relationships();
|
|
6530
6527
|
}
|
|
6531
|
-
get Relationships() {
|
|
6532
|
-
return this.relationships;
|
|
6533
|
-
}
|
|
6534
6528
|
};
|
|
6535
6529
|
}));
|
|
6536
6530
|
//#endregion
|
|
@@ -6694,7 +6688,7 @@ var init_ruby = __esmMin((() => {
|
|
|
6694
6688
|
name
|
|
6695
6689
|
});
|
|
6696
6690
|
createRuby = (options) => {
|
|
6697
|
-
const align = options.alignment ?? "
|
|
6691
|
+
const align = options.alignment ?? "center";
|
|
6698
6692
|
const hps = options.fontSize ?? 20;
|
|
6699
6693
|
const hpsRaise = options.raise ?? 20;
|
|
6700
6694
|
const hpsBaseText = options.baseFontSize ?? 40;
|
|
@@ -6705,7 +6699,7 @@ var init_ruby = __esmMin((() => {
|
|
|
6705
6699
|
new BuilderElement({
|
|
6706
6700
|
attributes: { val: {
|
|
6707
6701
|
key: "w:val",
|
|
6708
|
-
value:
|
|
6702
|
+
value: align
|
|
6709
6703
|
} },
|
|
6710
6704
|
name: "w:rubyAlign"
|
|
6711
6705
|
}),
|
|
@@ -6867,15 +6861,15 @@ var init_alt_chunk = __esmMin((() => {
|
|
|
6867
6861
|
const partPath = `afchunks/afchunk${relId}.${extension}`;
|
|
6868
6862
|
const rawData = typeof this.options.data === "string" ? new TextEncoder().encode(this.options.data) : this.options.data;
|
|
6869
6863
|
const data = this.options.contentType === "text/html" && typeof this.options.data === "string" ? new TextEncoder().encode(wrapHtmlDocument(this.options.data)) : rawData;
|
|
6870
|
-
context.viewWrapper.
|
|
6871
|
-
context.file.
|
|
6864
|
+
context.viewWrapper.relationships.addRelationship(relId, ALTCHUNK_RELATIONSHIP_TYPE, partPath);
|
|
6865
|
+
context.file.altChunks.addAltChunk(relId, {
|
|
6872
6866
|
key: relId,
|
|
6873
6867
|
data,
|
|
6874
6868
|
path: partPath,
|
|
6875
6869
|
extension,
|
|
6876
6870
|
contentType: this.options.contentType
|
|
6877
6871
|
});
|
|
6878
|
-
context.file.
|
|
6872
|
+
context.file.contentTypes.addAltChunk(`/word/${partPath}`, this.options.contentType, extension);
|
|
6879
6873
|
return super.prepForXml(context);
|
|
6880
6874
|
}
|
|
6881
6875
|
};
|
|
@@ -7260,12 +7254,12 @@ var init_sub_doc = __esmMin((() => {
|
|
|
7260
7254
|
const partPath = `subdocs/subdoc${relId}.docx`;
|
|
7261
7255
|
this.root.splice(0, 0, { _attr: { "r:id": `rId${relId}` } });
|
|
7262
7256
|
const data = typeof this.options.data === "string" ? new TextEncoder().encode(this.options.data) : this.options.data;
|
|
7263
|
-
context.viewWrapper.
|
|
7264
|
-
context.file.
|
|
7257
|
+
context.viewWrapper.relationships.addRelationship(relId, SUBDOC_RELATIONSHIP_TYPE, partPath);
|
|
7258
|
+
context.file.subDocs.addSubDoc(relId, {
|
|
7265
7259
|
data,
|
|
7266
7260
|
path: partPath
|
|
7267
7261
|
});
|
|
7268
|
-
context.file.
|
|
7262
|
+
context.file.contentTypes.addSubDoc(`/word/${partPath}`);
|
|
7269
7263
|
return super.prepForXml(context);
|
|
7270
7264
|
}
|
|
7271
7265
|
};
|
|
@@ -7469,8 +7463,8 @@ function buildCellMergeObj(options) {
|
|
|
7469
7463
|
"w:date": options.date,
|
|
7470
7464
|
"w:id": options.id
|
|
7471
7465
|
};
|
|
7472
|
-
if (options.verticalMerge !== void 0) attrs["w:vMerge"] = options.verticalMerge;
|
|
7473
|
-
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);
|
|
7474
7468
|
return { "w:cellMerge": { _attr: attrs } };
|
|
7475
7469
|
}
|
|
7476
7470
|
var VerticalMergeRevisionType, CellMerge;
|
|
@@ -7480,11 +7474,11 @@ var init_cell_merge = __esmMin((() => {
|
|
|
7480
7474
|
/**
|
|
7481
7475
|
* Cell that is merged with upper one.
|
|
7482
7476
|
*/
|
|
7483
|
-
CONTINUE: "
|
|
7477
|
+
CONTINUE: "continue",
|
|
7484
7478
|
/**
|
|
7485
7479
|
* Cell that is starting the vertical merge.
|
|
7486
7480
|
*/
|
|
7487
|
-
RESTART: "
|
|
7481
|
+
RESTART: "restart"
|
|
7488
7482
|
};
|
|
7489
7483
|
CellMerge = class extends XmlComponent {
|
|
7490
7484
|
constructor(options) {
|
|
@@ -7494,8 +7488,8 @@ var init_cell_merge = __esmMin((() => {
|
|
|
7494
7488
|
"w:date": options.date,
|
|
7495
7489
|
"w:id": options.id
|
|
7496
7490
|
};
|
|
7497
|
-
if (options.verticalMerge !== void 0) attrs["w:vMerge"] = options.verticalMerge;
|
|
7498
|
-
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);
|
|
7499
7493
|
this.root.push({ _attr: attrs });
|
|
7500
7494
|
}
|
|
7501
7495
|
};
|
|
@@ -8287,7 +8281,7 @@ var init_table_row$1 = __esmMin((() => {
|
|
|
8287
8281
|
this.options = options;
|
|
8288
8282
|
this.coercedChildren = options.children.map((child) => child instanceof TableCell || child instanceof StructuredDocumentTagCell || child instanceof StructuredDocumentTagRow ? child : new TableCell(child));
|
|
8289
8283
|
}
|
|
8290
|
-
get
|
|
8284
|
+
get cellCount() {
|
|
8291
8285
|
return this.coercedChildren.length;
|
|
8292
8286
|
}
|
|
8293
8287
|
get cells() {
|
|
@@ -8548,8 +8542,8 @@ var init_sdt_row = __esmMin((() => {
|
|
|
8548
8542
|
this.root.push(content);
|
|
8549
8543
|
}
|
|
8550
8544
|
}
|
|
8551
|
-
get
|
|
8552
|
-
return Math.max(...this.rows.map((r) => r.
|
|
8545
|
+
get cellCount() {
|
|
8546
|
+
return Math.max(...this.rows.map((r) => r.cellCount), 0);
|
|
8553
8547
|
}
|
|
8554
8548
|
get cells() {
|
|
8555
8549
|
return this.rows.flatMap((r) => r.cells);
|
|
@@ -8613,7 +8607,7 @@ var init_table = __esmMin((() => {
|
|
|
8613
8607
|
super("w:tbl");
|
|
8614
8608
|
this.options = options;
|
|
8615
8609
|
this.rows = options.rows.map((row) => row instanceof TableRow || row instanceof StructuredDocumentTagRow ? row : new TableRow(row));
|
|
8616
|
-
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);
|
|
8617
8611
|
this.rows.forEach((row, rowIndex) => {
|
|
8618
8612
|
if (rowIndex === this.rows.length - 1) return;
|
|
8619
8613
|
if (!(row instanceof TableRow)) return;
|
|
@@ -8851,7 +8845,7 @@ var AltChunkCollection = class {
|
|
|
8851
8845
|
addAltChunk(key, data) {
|
|
8852
8846
|
this.map.set(key, data);
|
|
8853
8847
|
}
|
|
8854
|
-
get
|
|
8848
|
+
get array() {
|
|
8855
8849
|
return [...this.map.values()];
|
|
8856
8850
|
}
|
|
8857
8851
|
};
|
|
@@ -8954,9 +8948,6 @@ var Bibliography = class extends XmlComponent {
|
|
|
8954
8948
|
for (const source of options.sources) this.root.push(new Source(source));
|
|
8955
8949
|
this.relationships = new Relationships();
|
|
8956
8950
|
}
|
|
8957
|
-
get Relationships() {
|
|
8958
|
-
return this.relationships;
|
|
8959
|
-
}
|
|
8960
8951
|
};
|
|
8961
8952
|
//#endregion
|
|
8962
8953
|
//#region src/file/content-types/content-types.ts
|
|
@@ -10329,15 +10320,15 @@ var SectionProperties = class extends XmlComponent {
|
|
|
10329
10320
|
}
|
|
10330
10321
|
addHeaderFooterGroup(type, group) {
|
|
10331
10322
|
if (group.default) this.root.push(createHeaderFooterReference(type, {
|
|
10332
|
-
id: group.default.
|
|
10323
|
+
id: group.default.view.referenceId,
|
|
10333
10324
|
type: HeaderFooterReferenceType.DEFAULT
|
|
10334
10325
|
}));
|
|
10335
10326
|
if (group.first) this.root.push(createHeaderFooterReference(type, {
|
|
10336
|
-
id: group.first.
|
|
10327
|
+
id: group.first.view.referenceId,
|
|
10337
10328
|
type: HeaderFooterReferenceType.FIRST
|
|
10338
10329
|
}));
|
|
10339
10330
|
if (group.even) this.root.push(createHeaderFooterReference(type, {
|
|
10340
|
-
id: group.even.
|
|
10331
|
+
id: group.even.view.referenceId,
|
|
10341
10332
|
type: HeaderFooterReferenceType.EVEN
|
|
10342
10333
|
}));
|
|
10343
10334
|
}
|
|
@@ -10552,7 +10543,7 @@ var DocumentBackground = class extends XmlComponent {
|
|
|
10552
10543
|
}
|
|
10553
10544
|
prepForXml(context) {
|
|
10554
10545
|
if (this.imageData) {
|
|
10555
|
-
context.file.
|
|
10546
|
+
context.file.media.addImage(this.imageData.fileName, {
|
|
10556
10547
|
type: this.imageData.type,
|
|
10557
10548
|
data: this.imageData.data,
|
|
10558
10549
|
fileName: this.imageData.fileName,
|
|
@@ -10702,14 +10693,6 @@ var Document = class extends XmlComponent {
|
|
|
10702
10693
|
this.body.push(item);
|
|
10703
10694
|
return this;
|
|
10704
10695
|
}
|
|
10705
|
-
/**
|
|
10706
|
-
* Gets the document body element.
|
|
10707
|
-
*
|
|
10708
|
-
* @returns The Body instance containing all document content
|
|
10709
|
-
*/
|
|
10710
|
-
get Body() {
|
|
10711
|
-
return this.body;
|
|
10712
|
-
}
|
|
10713
10696
|
};
|
|
10714
10697
|
//#endregion
|
|
10715
10698
|
//#region src/file/document-wrapper.ts
|
|
@@ -10746,12 +10729,9 @@ var DocumentWrapper = class {
|
|
|
10746
10729
|
this.document = new Document(options);
|
|
10747
10730
|
this.relationships = new Relationships();
|
|
10748
10731
|
}
|
|
10749
|
-
get
|
|
10732
|
+
get view() {
|
|
10750
10733
|
return this.document;
|
|
10751
10734
|
}
|
|
10752
|
-
get Relationships() {
|
|
10753
|
-
return this.relationships;
|
|
10754
|
-
}
|
|
10755
10735
|
};
|
|
10756
10736
|
//#endregion
|
|
10757
10737
|
//#region src/file/footnotes/footnote/run/continuation-seperator.ts
|
|
@@ -10931,12 +10911,9 @@ var EndnotesWrapper = class {
|
|
|
10931
10911
|
this.endnotes = new Endnotes();
|
|
10932
10912
|
this.relationships = new Relationships();
|
|
10933
10913
|
}
|
|
10934
|
-
get
|
|
10914
|
+
get view() {
|
|
10935
10915
|
return this.endnotes;
|
|
10936
10916
|
}
|
|
10937
|
-
get Relationships() {
|
|
10938
|
-
return this.relationships;
|
|
10939
|
-
}
|
|
10940
10917
|
};
|
|
10941
10918
|
//#endregion
|
|
10942
10919
|
//#region src/file/header-footer-base.ts
|
|
@@ -11010,7 +10987,7 @@ var HeaderFooterBase = class extends InitializableXmlComponent {
|
|
|
11010
10987
|
this.refId = referenceNumber;
|
|
11011
10988
|
if (!initContent) this.root.push(buildDocumentAttributes(namespaces));
|
|
11012
10989
|
}
|
|
11013
|
-
get
|
|
10990
|
+
get referenceId() {
|
|
11014
10991
|
return this.refId;
|
|
11015
10992
|
}
|
|
11016
10993
|
add(item) {
|
|
@@ -11086,6 +11063,7 @@ init_relationships();
|
|
|
11086
11063
|
var FooterWrapper = class {
|
|
11087
11064
|
footer;
|
|
11088
11065
|
relationships;
|
|
11066
|
+
media;
|
|
11089
11067
|
constructor(media, referenceId, initContent) {
|
|
11090
11068
|
this.media = media;
|
|
11091
11069
|
this.footer = new Footer$1(referenceId, initContent);
|
|
@@ -11097,15 +11075,9 @@ var FooterWrapper = class {
|
|
|
11097
11075
|
addChildElement(childElement) {
|
|
11098
11076
|
this.footer.addChildElement(childElement);
|
|
11099
11077
|
}
|
|
11100
|
-
get
|
|
11078
|
+
get view() {
|
|
11101
11079
|
return this.footer;
|
|
11102
11080
|
}
|
|
11103
|
-
get Relationships() {
|
|
11104
|
-
return this.relationships;
|
|
11105
|
-
}
|
|
11106
|
-
get Media() {
|
|
11107
|
-
return this.media;
|
|
11108
|
-
}
|
|
11109
11081
|
};
|
|
11110
11082
|
//#endregion
|
|
11111
11083
|
//#region src/file/footnotes/footnote/run/footnote-ref.ts
|
|
@@ -11330,22 +11302,19 @@ init_relationships();
|
|
|
11330
11302
|
* @example
|
|
11331
11303
|
* ```typescript
|
|
11332
11304
|
* const wrapper = new FootnotesWrapper();
|
|
11333
|
-
* const footnotes = wrapper.
|
|
11334
|
-
* const relationships = wrapper.
|
|
11305
|
+
* const footnotes = wrapper.view;
|
|
11306
|
+
* const relationships = wrapper.relationships;
|
|
11335
11307
|
* ```
|
|
11336
11308
|
*/
|
|
11337
11309
|
var FootnotesWrapper = class {
|
|
11338
|
-
|
|
11310
|
+
footnotes;
|
|
11339
11311
|
relationships;
|
|
11340
11312
|
constructor() {
|
|
11341
|
-
this.
|
|
11313
|
+
this.footnotes = new FootNotes();
|
|
11342
11314
|
this.relationships = new Relationships();
|
|
11343
11315
|
}
|
|
11344
|
-
get
|
|
11345
|
-
return this.
|
|
11346
|
-
}
|
|
11347
|
-
get Relationships() {
|
|
11348
|
-
return this.relationships;
|
|
11316
|
+
get view() {
|
|
11317
|
+
return this.footnotes;
|
|
11349
11318
|
}
|
|
11350
11319
|
};
|
|
11351
11320
|
//#endregion
|
|
@@ -11462,6 +11431,7 @@ init_relationships();
|
|
|
11462
11431
|
var HeaderWrapper = class {
|
|
11463
11432
|
header;
|
|
11464
11433
|
relationships;
|
|
11434
|
+
media;
|
|
11465
11435
|
constructor(media, referenceId, initContent) {
|
|
11466
11436
|
this.media = media;
|
|
11467
11437
|
this.header = new Header$1(referenceId, initContent);
|
|
@@ -11474,15 +11444,9 @@ var HeaderWrapper = class {
|
|
|
11474
11444
|
addChildElement(childElement) {
|
|
11475
11445
|
this.header.addChildElement(childElement);
|
|
11476
11446
|
}
|
|
11477
|
-
get
|
|
11447
|
+
get view() {
|
|
11478
11448
|
return this.header;
|
|
11479
11449
|
}
|
|
11480
|
-
get Relationships() {
|
|
11481
|
-
return this.relationships;
|
|
11482
|
-
}
|
|
11483
|
-
get Media() {
|
|
11484
|
-
return this.media;
|
|
11485
|
-
}
|
|
11486
11450
|
};
|
|
11487
11451
|
//#endregion
|
|
11488
11452
|
//#region src/file/numbering/level.ts
|
|
@@ -12303,7 +12267,7 @@ var Numbering = class extends XmlComponent {
|
|
|
12303
12267
|
*
|
|
12304
12268
|
* @returns An array of all concrete numbering instances
|
|
12305
12269
|
*/
|
|
12306
|
-
get
|
|
12270
|
+
get concreteNumbering() {
|
|
12307
12271
|
return [...this.concreteNumberingMap.values()];
|
|
12308
12272
|
}
|
|
12309
12273
|
/**
|
|
@@ -12311,7 +12275,7 @@ var Numbering = class extends XmlComponent {
|
|
|
12311
12275
|
*
|
|
12312
12276
|
* @returns An array of all numbering reference configurations
|
|
12313
12277
|
*/
|
|
12314
|
-
get
|
|
12278
|
+
get referenceConfig() {
|
|
12315
12279
|
return [...this.referenceConfigMap.values()];
|
|
12316
12280
|
}
|
|
12317
12281
|
};
|
|
@@ -13587,7 +13551,7 @@ var SubDocCollection = class {
|
|
|
13587
13551
|
addSubDoc(key, data) {
|
|
13588
13552
|
this.map.set(key, data);
|
|
13589
13553
|
}
|
|
13590
|
-
get
|
|
13554
|
+
get array() {
|
|
13591
13555
|
return [...this.map.values()];
|
|
13592
13556
|
}
|
|
13593
13557
|
};
|
|
@@ -13681,10 +13645,10 @@ init_relationships();
|
|
|
13681
13645
|
* ```
|
|
13682
13646
|
*/
|
|
13683
13647
|
var File = class {
|
|
13684
|
-
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13648
|
+
_currentRelationshipId = 1;
|
|
13649
|
+
document;
|
|
13650
|
+
_headers = [];
|
|
13651
|
+
_footers = [];
|
|
13688
13652
|
coreProperties;
|
|
13689
13653
|
numbering;
|
|
13690
13654
|
media;
|
|
@@ -13693,8 +13657,8 @@ var File = class {
|
|
|
13693
13657
|
altChunks;
|
|
13694
13658
|
subDocs;
|
|
13695
13659
|
fileRelationships;
|
|
13696
|
-
|
|
13697
|
-
|
|
13660
|
+
footNotes;
|
|
13661
|
+
endnotes;
|
|
13698
13662
|
settings;
|
|
13699
13663
|
contentTypes;
|
|
13700
13664
|
customProperties;
|
|
@@ -13702,7 +13666,7 @@ var File = class {
|
|
|
13702
13666
|
styles;
|
|
13703
13667
|
comments;
|
|
13704
13668
|
bibliography;
|
|
13705
|
-
|
|
13669
|
+
fontTable;
|
|
13706
13670
|
constructor(options) {
|
|
13707
13671
|
this.coreProperties = new CoreProperties({
|
|
13708
13672
|
...options,
|
|
@@ -13716,10 +13680,10 @@ var File = class {
|
|
|
13716
13680
|
this.fileRelationships = new Relationships();
|
|
13717
13681
|
this.customProperties = new CustomProperties(options.customProperties ?? []);
|
|
13718
13682
|
this.appProperties = new AppProperties();
|
|
13719
|
-
this.
|
|
13720
|
-
this.
|
|
13683
|
+
this.footNotes = new FootnotesWrapper();
|
|
13684
|
+
this.endnotes = new EndnotesWrapper();
|
|
13721
13685
|
this.contentTypes = new ContentTypes();
|
|
13722
|
-
this.
|
|
13686
|
+
this.document = new DocumentWrapper({ background: options.background });
|
|
13723
13687
|
this.settings = new Settings({
|
|
13724
13688
|
compatibility: options.compatibility,
|
|
13725
13689
|
compatibilityModeVersion: options.compatabilityModeVersion,
|
|
@@ -13772,16 +13736,16 @@ var File = class {
|
|
|
13772
13736
|
for (const section of options.sections) this.addSection(section);
|
|
13773
13737
|
if (options.footnotes) for (const key in options.footnotes) {
|
|
13774
13738
|
const children = options.footnotes[key].children.map((p) => p instanceof Paragraph ? p : new Paragraph(p));
|
|
13775
|
-
this.
|
|
13739
|
+
this.footNotes.view.createFootNote(parseFloat(key), children);
|
|
13776
13740
|
}
|
|
13777
13741
|
if (options.endnotes) for (const key in options.endnotes) {
|
|
13778
13742
|
const children = options.endnotes[key].children.map((p) => p instanceof Paragraph ? p : new Paragraph(p));
|
|
13779
|
-
this.
|
|
13743
|
+
this.endnotes.view.createEndnote(parseFloat(key), children);
|
|
13780
13744
|
}
|
|
13781
|
-
this.
|
|
13745
|
+
this.fontTable = new FontWrapper(options.fonts ?? []);
|
|
13782
13746
|
}
|
|
13783
13747
|
addSection({ headers = {}, footers = {}, children, properties }) {
|
|
13784
|
-
this.
|
|
13748
|
+
this.document.view.body.addSection({
|
|
13785
13749
|
...properties,
|
|
13786
13750
|
footerWrapperGroup: {
|
|
13787
13751
|
default: footers.default ? this.createFooter(footers.default) : void 0,
|
|
@@ -13794,113 +13758,56 @@ var File = class {
|
|
|
13794
13758
|
first: headers.first ? this.createHeader(headers.first) : void 0
|
|
13795
13759
|
}
|
|
13796
13760
|
});
|
|
13797
|
-
for (const rawChild of children) this.
|
|
13761
|
+
for (const rawChild of children) this.document.view.add(coerceSectionChild(rawChild));
|
|
13798
13762
|
}
|
|
13799
13763
|
createHeader(header) {
|
|
13800
|
-
const wrapper = new HeaderWrapper(this.media, this.
|
|
13764
|
+
const wrapper = new HeaderWrapper(this.media, this._currentRelationshipId++);
|
|
13801
13765
|
const children = header instanceof Header ? header.options.children : header;
|
|
13802
13766
|
for (const rawChild of children) wrapper.add(coerceSectionChild(rawChild));
|
|
13803
13767
|
this.addHeaderToDocument(wrapper);
|
|
13804
13768
|
return wrapper;
|
|
13805
13769
|
}
|
|
13806
13770
|
createFooter(footer) {
|
|
13807
|
-
const wrapper = new FooterWrapper(this.media, this.
|
|
13771
|
+
const wrapper = new FooterWrapper(this.media, this._currentRelationshipId++);
|
|
13808
13772
|
const children = footer instanceof Footer ? footer.options.children : footer;
|
|
13809
13773
|
for (const rawChild of children) wrapper.add(coerceSectionChild(rawChild));
|
|
13810
13774
|
this.addFooterToDocument(wrapper);
|
|
13811
13775
|
return wrapper;
|
|
13812
13776
|
}
|
|
13813
13777
|
addHeaderToDocument(header, type = HeaderFooterReferenceType.DEFAULT) {
|
|
13814
|
-
this.
|
|
13778
|
+
this._headers.push({
|
|
13815
13779
|
header,
|
|
13816
13780
|
type
|
|
13817
13781
|
});
|
|
13818
|
-
this.
|
|
13819
|
-
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);
|
|
13820
13784
|
}
|
|
13821
13785
|
addFooterToDocument(footer, type = HeaderFooterReferenceType.DEFAULT) {
|
|
13822
|
-
this.
|
|
13786
|
+
this._footers.push({
|
|
13823
13787
|
footer,
|
|
13824
13788
|
type
|
|
13825
13789
|
});
|
|
13826
|
-
this.
|
|
13827
|
-
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);
|
|
13828
13792
|
}
|
|
13829
13793
|
addDefaultRelationships() {
|
|
13830
13794
|
this.fileRelationships.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml");
|
|
13831
13795
|
this.fileRelationships.addRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml");
|
|
13832
13796
|
this.fileRelationships.addRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
|
|
13833
13797
|
this.fileRelationships.addRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", "docProps/custom.xml");
|
|
13834
|
-
this.
|
|
13835
|
-
this.
|
|
13836
|
-
this.
|
|
13837
|
-
this.
|
|
13838
|
-
this.
|
|
13839
|
-
this.
|
|
13840
|
-
if (this.bibliography) this.
|
|
13841
|
-
}
|
|
13842
|
-
get Document() {
|
|
13843
|
-
return this.documentWrapper;
|
|
13844
|
-
}
|
|
13845
|
-
get Styles() {
|
|
13846
|
-
return this.styles;
|
|
13847
|
-
}
|
|
13848
|
-
get CoreProperties() {
|
|
13849
|
-
return this.coreProperties;
|
|
13850
|
-
}
|
|
13851
|
-
get Numbering() {
|
|
13852
|
-
return this.numbering;
|
|
13853
|
-
}
|
|
13854
|
-
get Media() {
|
|
13855
|
-
return this.media;
|
|
13856
|
-
}
|
|
13857
|
-
get Charts() {
|
|
13858
|
-
return this.charts;
|
|
13859
|
-
}
|
|
13860
|
-
get SmartArts() {
|
|
13861
|
-
return this.smartArts;
|
|
13862
|
-
}
|
|
13863
|
-
get AltChunks() {
|
|
13864
|
-
return this.altChunks;
|
|
13865
|
-
}
|
|
13866
|
-
get SubDocs() {
|
|
13867
|
-
return this.subDocs;
|
|
13868
|
-
}
|
|
13869
|
-
get FileRelationships() {
|
|
13870
|
-
return this.fileRelationships;
|
|
13871
|
-
}
|
|
13872
|
-
get Headers() {
|
|
13873
|
-
return this.headers.map((item) => item.header);
|
|
13874
|
-
}
|
|
13875
|
-
get Footers() {
|
|
13876
|
-
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");
|
|
13877
13805
|
}
|
|
13878
|
-
get
|
|
13879
|
-
return this.
|
|
13806
|
+
get headers() {
|
|
13807
|
+
return this._headers.map((item) => item.header);
|
|
13880
13808
|
}
|
|
13881
|
-
get
|
|
13882
|
-
return this.
|
|
13883
|
-
}
|
|
13884
|
-
get AppProperties() {
|
|
13885
|
-
return this.appProperties;
|
|
13886
|
-
}
|
|
13887
|
-
get FootNotes() {
|
|
13888
|
-
return this.footnotesWrapper;
|
|
13889
|
-
}
|
|
13890
|
-
get Endnotes() {
|
|
13891
|
-
return this.endnotesWrapper;
|
|
13892
|
-
}
|
|
13893
|
-
get Settings() {
|
|
13894
|
-
return this.settings;
|
|
13895
|
-
}
|
|
13896
|
-
get Comments() {
|
|
13897
|
-
return this.comments;
|
|
13898
|
-
}
|
|
13899
|
-
get Bibliography() {
|
|
13900
|
-
return this.bibliography;
|
|
13901
|
-
}
|
|
13902
|
-
get FontTable() {
|
|
13903
|
-
return this.fontWrapper;
|
|
13809
|
+
get footers() {
|
|
13810
|
+
return this._footers.map((item) => item.footer);
|
|
13904
13811
|
}
|
|
13905
13812
|
};
|
|
13906
13813
|
//#endregion
|
|
@@ -14652,7 +14559,7 @@ function replaceNumberingPlaceholders(xml, concreteNumberings) {
|
|
|
14652
14559
|
var Compiler = class {
|
|
14653
14560
|
formatter;
|
|
14654
14561
|
constructor() {
|
|
14655
|
-
this.formatter = new Formatter();
|
|
14562
|
+
this.formatter = new Formatter$1();
|
|
14656
14563
|
}
|
|
14657
14564
|
/**
|
|
14658
14565
|
* Compiles a File object into a flat file map suitable for fflate zipSync.
|
|
@@ -14684,23 +14591,23 @@ var Compiler = class {
|
|
|
14684
14591
|
files[fileObj.path] = typeof fileObj.data === "string" ? textToUint8Array(fileObj.data) : fileObj.data;
|
|
14685
14592
|
}
|
|
14686
14593
|
for (const subFile of overrides) files[subFile.path] = typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data;
|
|
14687
|
-
for (const mediaData of file.
|
|
14594
|
+
for (const mediaData of file.media.array) {
|
|
14688
14595
|
files[`word/media/${mediaData.fileName}`] = [toUint8Array(mediaData.data), { level: ZIP_STORED_LEVEL }];
|
|
14689
14596
|
if (mediaData.type === "svg") files[`word/media/${mediaData.fallback.fileName}`] = [toUint8Array(mediaData.fallback.data), { level: ZIP_STORED_LEVEL }];
|
|
14690
14597
|
}
|
|
14691
|
-
for (const { data: buffer, name, fontKey } of file.
|
|
14598
|
+
for (const { data: buffer, name, fontKey } of file.fontTable.fontOptionsWithKey) {
|
|
14692
14599
|
const [nameWithoutExtension] = name.split(".");
|
|
14693
14600
|
files[`word/fonts/${nameWithoutExtension}.odttf`] = obfuscate(buffer, fontKey);
|
|
14694
14601
|
}
|
|
14695
14602
|
return files;
|
|
14696
14603
|
}
|
|
14697
14604
|
xmlifyFile(file, headerFormattedViews, footerFormattedViews, prettify) {
|
|
14698
|
-
const documentRelationshipCount = file.
|
|
14699
|
-
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, {
|
|
14700
14607
|
fileData: file,
|
|
14701
14608
|
file,
|
|
14702
14609
|
stack: [],
|
|
14703
|
-
viewWrapper: file.
|
|
14610
|
+
viewWrapper: file.document
|
|
14704
14611
|
}), {
|
|
14705
14612
|
declaration: {
|
|
14706
14613
|
encoding: "UTF-8",
|
|
@@ -14708,14 +14615,14 @@ var Compiler = class {
|
|
|
14708
14615
|
},
|
|
14709
14616
|
indent: prettify
|
|
14710
14617
|
});
|
|
14711
|
-
const commentRelationshipCount = file.
|
|
14712
|
-
const commentXmlData = xml(this.formatter.format(file.
|
|
14618
|
+
const commentRelationshipCount = file.comments.relationships.relationshipCount + 1;
|
|
14619
|
+
const commentXmlData = xml(this.formatter.format(file.comments, {
|
|
14713
14620
|
fileData: file,
|
|
14714
14621
|
file,
|
|
14715
14622
|
stack: [],
|
|
14716
14623
|
viewWrapper: {
|
|
14717
|
-
|
|
14718
|
-
|
|
14624
|
+
relationships: file.comments.relationships,
|
|
14625
|
+
view: file.comments
|
|
14719
14626
|
}
|
|
14720
14627
|
}), {
|
|
14721
14628
|
declaration: {
|
|
@@ -14724,12 +14631,12 @@ var Compiler = class {
|
|
|
14724
14631
|
},
|
|
14725
14632
|
indent: prettify
|
|
14726
14633
|
});
|
|
14727
|
-
const footnoteRelationshipCount = file.
|
|
14728
|
-
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, {
|
|
14729
14636
|
fileData: file,
|
|
14730
14637
|
file,
|
|
14731
14638
|
stack: [],
|
|
14732
|
-
viewWrapper: file.
|
|
14639
|
+
viewWrapper: file.footNotes
|
|
14733
14640
|
}), {
|
|
14734
14641
|
declaration: {
|
|
14735
14642
|
encoding: "UTF-8",
|
|
@@ -14737,16 +14644,16 @@ var Compiler = class {
|
|
|
14737
14644
|
},
|
|
14738
14645
|
indent: prettify
|
|
14739
14646
|
});
|
|
14740
|
-
const documentMediaDatas = hasPlaceholders(documentXmlData) ? getReferencedMedia(documentXmlData, file.
|
|
14741
|
-
const commentMediaDatas = hasPlaceholders(commentXmlData) ? getReferencedMedia(commentXmlData, file.
|
|
14742
|
-
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) : [];
|
|
14743
14650
|
return {
|
|
14744
14651
|
AppProperties: {
|
|
14745
|
-
data: xml(this.formatter.format(file.
|
|
14652
|
+
data: xml(this.formatter.format(file.appProperties, {
|
|
14746
14653
|
fileData: file,
|
|
14747
14654
|
file,
|
|
14748
14655
|
stack: [],
|
|
14749
|
-
viewWrapper: file.
|
|
14656
|
+
viewWrapper: file.document
|
|
14750
14657
|
}), { declaration: {
|
|
14751
14658
|
encoding: "UTF-8",
|
|
14752
14659
|
standalone: "yes"
|
|
@@ -14754,21 +14661,21 @@ var Compiler = class {
|
|
|
14754
14661
|
path: "docProps/app.xml"
|
|
14755
14662
|
},
|
|
14756
14663
|
Comments: {
|
|
14757
|
-
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),
|
|
14758
14665
|
path: "word/comments.xml"
|
|
14759
14666
|
},
|
|
14760
14667
|
CommentsRelationships: {
|
|
14761
14668
|
data: (() => {
|
|
14762
14669
|
commentMediaDatas.forEach((mediaData, i) => {
|
|
14763
|
-
file.
|
|
14670
|
+
file.comments.relationships.addRelationship(commentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14764
14671
|
});
|
|
14765
|
-
return xml(this.formatter.format(file.
|
|
14672
|
+
return xml(this.formatter.format(file.comments.relationships, {
|
|
14766
14673
|
fileData: file,
|
|
14767
14674
|
file,
|
|
14768
14675
|
stack: [],
|
|
14769
14676
|
viewWrapper: {
|
|
14770
|
-
|
|
14771
|
-
|
|
14677
|
+
relationships: file.comments.relationships,
|
|
14678
|
+
view: file.comments
|
|
14772
14679
|
}
|
|
14773
14680
|
}), {
|
|
14774
14681
|
declaration: { encoding: "UTF-8" },
|
|
@@ -14779,21 +14686,21 @@ var Compiler = class {
|
|
|
14779
14686
|
},
|
|
14780
14687
|
ContentTypes: {
|
|
14781
14688
|
data: (() => {
|
|
14782
|
-
file.
|
|
14783
|
-
file.
|
|
14689
|
+
file.charts.array.forEach((_, i) => {
|
|
14690
|
+
file.contentTypes.addChart(i + 1);
|
|
14784
14691
|
});
|
|
14785
|
-
file.
|
|
14786
|
-
file.
|
|
14787
|
-
file.
|
|
14788
|
-
file.
|
|
14789
|
-
file.
|
|
14790
|
-
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);
|
|
14791
14698
|
});
|
|
14792
|
-
return xml(this.formatter.format(file.
|
|
14699
|
+
return xml(this.formatter.format(file.contentTypes, {
|
|
14793
14700
|
fileData: file,
|
|
14794
14701
|
file,
|
|
14795
14702
|
stack: [],
|
|
14796
|
-
viewWrapper: file.
|
|
14703
|
+
viewWrapper: file.document
|
|
14797
14704
|
}), {
|
|
14798
14705
|
declaration: { encoding: "UTF-8" },
|
|
14799
14706
|
indent: prettify
|
|
@@ -14802,11 +14709,11 @@ var Compiler = class {
|
|
|
14802
14709
|
path: "[Content_Types].xml"
|
|
14803
14710
|
},
|
|
14804
14711
|
CustomProperties: {
|
|
14805
|
-
data: xml(this.formatter.format(file.
|
|
14712
|
+
data: xml(this.formatter.format(file.customProperties, {
|
|
14806
14713
|
fileData: file,
|
|
14807
14714
|
file,
|
|
14808
14715
|
stack: [],
|
|
14809
|
-
viewWrapper: file.
|
|
14716
|
+
viewWrapper: file.document
|
|
14810
14717
|
}), {
|
|
14811
14718
|
declaration: {
|
|
14812
14719
|
encoding: "UTF-8",
|
|
@@ -14820,20 +14727,20 @@ var Compiler = class {
|
|
|
14820
14727
|
data: (() => {
|
|
14821
14728
|
let xmlData = documentMediaDatas.length > 0 ? replaceImagePlaceholders(documentXmlData, documentMediaDatas, documentRelationshipCount, "rId") : documentXmlData;
|
|
14822
14729
|
if (hasPlaceholders(xmlData)) {
|
|
14823
|
-
xmlData = replaceChartPlaceholders(xmlData, file.
|
|
14824
|
-
const smartArtDataOffset = documentRelationshipCount + documentMediaDatas.length + file.
|
|
14825
|
-
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");
|
|
14826
14733
|
}
|
|
14827
|
-
return replaceNumberingPlaceholders(xmlData, file.
|
|
14734
|
+
return replaceNumberingPlaceholders(xmlData, file.numbering.concreteNumbering);
|
|
14828
14735
|
})(),
|
|
14829
14736
|
path: "word/document.xml"
|
|
14830
14737
|
},
|
|
14831
14738
|
Endnotes: {
|
|
14832
|
-
data: xml(this.formatter.format(file.
|
|
14739
|
+
data: xml(this.formatter.format(file.endnotes.view, {
|
|
14833
14740
|
fileData: file,
|
|
14834
14741
|
file,
|
|
14835
14742
|
stack: [],
|
|
14836
|
-
viewWrapper: file.
|
|
14743
|
+
viewWrapper: file.endnotes
|
|
14837
14744
|
}), {
|
|
14838
14745
|
declaration: { encoding: "UTF-8" },
|
|
14839
14746
|
indent: prettify
|
|
@@ -14841,11 +14748,11 @@ var Compiler = class {
|
|
|
14841
14748
|
path: "word/endnotes.xml"
|
|
14842
14749
|
},
|
|
14843
14750
|
EndnotesRelationships: {
|
|
14844
|
-
data: xml(this.formatter.format(file.
|
|
14751
|
+
data: xml(this.formatter.format(file.endnotes.relationships, {
|
|
14845
14752
|
fileData: file,
|
|
14846
14753
|
file,
|
|
14847
14754
|
stack: [],
|
|
14848
|
-
viewWrapper: file.
|
|
14755
|
+
viewWrapper: file.endnotes
|
|
14849
14756
|
}), {
|
|
14850
14757
|
declaration: { encoding: "UTF-8" },
|
|
14851
14758
|
indent: prettify
|
|
@@ -14853,11 +14760,11 @@ var Compiler = class {
|
|
|
14853
14760
|
path: "word/_rels/endnotes.xml.rels"
|
|
14854
14761
|
},
|
|
14855
14762
|
FileRelationships: {
|
|
14856
|
-
data: xml(this.formatter.format(file.
|
|
14763
|
+
data: xml(this.formatter.format(file.fileRelationships, {
|
|
14857
14764
|
fileData: file,
|
|
14858
14765
|
file,
|
|
14859
14766
|
stack: [],
|
|
14860
|
-
viewWrapper: file.
|
|
14767
|
+
viewWrapper: file.document
|
|
14861
14768
|
}), {
|
|
14862
14769
|
declaration: { encoding: "UTF-8" },
|
|
14863
14770
|
indent: prettify
|
|
@@ -14865,11 +14772,11 @@ var Compiler = class {
|
|
|
14865
14772
|
path: "_rels/.rels"
|
|
14866
14773
|
},
|
|
14867
14774
|
FontTable: {
|
|
14868
|
-
data: xml(this.formatter.format(file.
|
|
14775
|
+
data: xml(this.formatter.format(file.fontTable.view, {
|
|
14869
14776
|
fileData: file,
|
|
14870
14777
|
file,
|
|
14871
14778
|
stack: [],
|
|
14872
|
-
viewWrapper: file.
|
|
14779
|
+
viewWrapper: file.document
|
|
14873
14780
|
}), {
|
|
14874
14781
|
declaration: {
|
|
14875
14782
|
encoding: "UTF-8",
|
|
@@ -14880,11 +14787,11 @@ var Compiler = class {
|
|
|
14880
14787
|
path: "word/fontTable.xml"
|
|
14881
14788
|
},
|
|
14882
14789
|
FontTableRelationships: {
|
|
14883
|
-
data: xml(this.formatter.format(file.
|
|
14790
|
+
data: xml(this.formatter.format(file.fontTable.relationships, {
|
|
14884
14791
|
fileData: file,
|
|
14885
14792
|
file,
|
|
14886
14793
|
stack: [],
|
|
14887
|
-
viewWrapper: file.
|
|
14794
|
+
viewWrapper: file.document
|
|
14888
14795
|
}), {
|
|
14889
14796
|
declaration: { encoding: "UTF-8" },
|
|
14890
14797
|
indent: prettify
|
|
@@ -14892,19 +14799,19 @@ var Compiler = class {
|
|
|
14892
14799
|
path: "word/_rels/fontTable.xml.rels"
|
|
14893
14800
|
},
|
|
14894
14801
|
FootNotes: {
|
|
14895
|
-
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),
|
|
14896
14803
|
path: "word/footnotes.xml"
|
|
14897
14804
|
},
|
|
14898
14805
|
FootNotesRelationships: {
|
|
14899
14806
|
data: (() => {
|
|
14900
14807
|
footnoteMediaDatas.forEach((mediaData, i) => {
|
|
14901
|
-
file.
|
|
14808
|
+
file.footNotes.relationships.addRelationship(footnoteRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14902
14809
|
});
|
|
14903
|
-
return xml(this.formatter.format(file.
|
|
14810
|
+
return xml(this.formatter.format(file.footNotes.relationships, {
|
|
14904
14811
|
fileData: file,
|
|
14905
14812
|
file,
|
|
14906
14813
|
stack: [],
|
|
14907
|
-
viewWrapper: file.
|
|
14814
|
+
viewWrapper: file.footNotes
|
|
14908
14815
|
}), {
|
|
14909
14816
|
declaration: { encoding: "UTF-8" },
|
|
14910
14817
|
indent: prettify
|
|
@@ -14912,8 +14819,8 @@ var Compiler = class {
|
|
|
14912
14819
|
})(),
|
|
14913
14820
|
path: "word/_rels/footnotes.xml.rels"
|
|
14914
14821
|
},
|
|
14915
|
-
FooterRelationships: file.
|
|
14916
|
-
const xmlData = xml(this.formatter.format(footerWrapper.
|
|
14822
|
+
FooterRelationships: file.footers.map((footerWrapper, index) => {
|
|
14823
|
+
const xmlData = xml(this.formatter.format(footerWrapper.view, {
|
|
14917
14824
|
fileData: file,
|
|
14918
14825
|
file,
|
|
14919
14826
|
stack: [],
|
|
@@ -14923,11 +14830,11 @@ var Compiler = class {
|
|
|
14923
14830
|
indent: prettify
|
|
14924
14831
|
});
|
|
14925
14832
|
footerFormattedViews.set(index, xmlData);
|
|
14926
|
-
getReferencedMedia(xmlData, file.
|
|
14927
|
-
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}`);
|
|
14928
14835
|
});
|
|
14929
14836
|
return {
|
|
14930
|
-
data: xml(this.formatter.format(footerWrapper.
|
|
14837
|
+
data: xml(this.formatter.format(footerWrapper.relationships, {
|
|
14931
14838
|
fileData: file,
|
|
14932
14839
|
file,
|
|
14933
14840
|
stack: [],
|
|
@@ -14939,16 +14846,16 @@ var Compiler = class {
|
|
|
14939
14846
|
path: `word/_rels/footer${index + 1}.xml.rels`
|
|
14940
14847
|
};
|
|
14941
14848
|
}),
|
|
14942
|
-
Footers: file.
|
|
14849
|
+
Footers: file.footers.map((_footerWrapper, index) => {
|
|
14943
14850
|
const tempXmlData = footerFormattedViews.get(index);
|
|
14944
|
-
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.
|
|
14851
|
+
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.media.array) : [];
|
|
14945
14852
|
return {
|
|
14946
|
-
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),
|
|
14947
14854
|
path: `word/footer${index + 1}.xml`
|
|
14948
14855
|
};
|
|
14949
14856
|
}),
|
|
14950
|
-
HeaderRelationships: file.
|
|
14951
|
-
const xmlData = xml(this.formatter.format(headerWrapper.
|
|
14857
|
+
HeaderRelationships: file.headers.map((headerWrapper, index) => {
|
|
14858
|
+
const xmlData = xml(this.formatter.format(headerWrapper.view, {
|
|
14952
14859
|
fileData: file,
|
|
14953
14860
|
file,
|
|
14954
14861
|
stack: [],
|
|
@@ -14958,11 +14865,11 @@ var Compiler = class {
|
|
|
14958
14865
|
indent: prettify
|
|
14959
14866
|
});
|
|
14960
14867
|
headerFormattedViews.set(index, xmlData);
|
|
14961
|
-
getReferencedMedia(xmlData, file.
|
|
14962
|
-
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}`);
|
|
14963
14870
|
});
|
|
14964
14871
|
return {
|
|
14965
|
-
data: xml(this.formatter.format(headerWrapper.
|
|
14872
|
+
data: xml(this.formatter.format(headerWrapper.relationships, {
|
|
14966
14873
|
fileData: file,
|
|
14967
14874
|
file,
|
|
14968
14875
|
stack: [],
|
|
@@ -14974,20 +14881,20 @@ var Compiler = class {
|
|
|
14974
14881
|
path: `word/_rels/header${index + 1}.xml.rels`
|
|
14975
14882
|
};
|
|
14976
14883
|
}),
|
|
14977
|
-
Headers: file.
|
|
14884
|
+
Headers: file.headers.map((_headerWrapper, index) => {
|
|
14978
14885
|
const tempXmlData = headerFormattedViews.get(index);
|
|
14979
|
-
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.
|
|
14886
|
+
const mediaDatas = hasPlaceholders(tempXmlData) ? getReferencedMedia(tempXmlData, file.media.array) : [];
|
|
14980
14887
|
return {
|
|
14981
|
-
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),
|
|
14982
14889
|
path: `word/header${index + 1}.xml`
|
|
14983
14890
|
};
|
|
14984
14891
|
}),
|
|
14985
14892
|
Numbering: {
|
|
14986
|
-
data: xml(this.formatter.format(file.
|
|
14893
|
+
data: xml(this.formatter.format(file.numbering, {
|
|
14987
14894
|
fileData: file,
|
|
14988
14895
|
file,
|
|
14989
14896
|
stack: [],
|
|
14990
|
-
viewWrapper: file.
|
|
14897
|
+
viewWrapper: file.document
|
|
14991
14898
|
}), {
|
|
14992
14899
|
declaration: {
|
|
14993
14900
|
encoding: "UTF-8",
|
|
@@ -14998,11 +14905,11 @@ var Compiler = class {
|
|
|
14998
14905
|
path: "word/numbering.xml"
|
|
14999
14906
|
},
|
|
15000
14907
|
Properties: {
|
|
15001
|
-
data: xml(this.formatter.format(file.
|
|
14908
|
+
data: xml(this.formatter.format(file.coreProperties, {
|
|
15002
14909
|
fileData: file,
|
|
15003
14910
|
file,
|
|
15004
14911
|
stack: [],
|
|
15005
|
-
viewWrapper: file.
|
|
14912
|
+
viewWrapper: file.document
|
|
15006
14913
|
}), {
|
|
15007
14914
|
declaration: {
|
|
15008
14915
|
encoding: "UTF-8",
|
|
@@ -15015,24 +14922,24 @@ var Compiler = class {
|
|
|
15015
14922
|
Relationships: {
|
|
15016
14923
|
data: (() => {
|
|
15017
14924
|
documentMediaDatas.forEach((mediaData, i) => {
|
|
15018
|
-
file.
|
|
14925
|
+
file.document.relationships.addRelationship(documentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
15019
14926
|
});
|
|
15020
14927
|
const chartOffset = documentRelationshipCount + documentMediaDatas.length;
|
|
15021
|
-
file.
|
|
15022
|
-
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`);
|
|
15023
14930
|
});
|
|
15024
|
-
addSmartArtRelationships(file.
|
|
15025
|
-
file.
|
|
15026
|
-
}, 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, {
|
|
15027
14934
|
pathPrefix: "",
|
|
15028
14935
|
styleRelType: "http://schemas.microsoft.com/office/2007/relationships/diagramStyle"
|
|
15029
14936
|
});
|
|
15030
|
-
file.
|
|
15031
|
-
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, {
|
|
15032
14939
|
fileData: file,
|
|
15033
14940
|
file,
|
|
15034
14941
|
stack: [],
|
|
15035
|
-
viewWrapper: file.
|
|
14942
|
+
viewWrapper: file.document
|
|
15036
14943
|
}), {
|
|
15037
14944
|
declaration: { encoding: "UTF-8" },
|
|
15038
14945
|
indent: prettify
|
|
@@ -15041,11 +14948,11 @@ var Compiler = class {
|
|
|
15041
14948
|
path: "word/_rels/document.xml.rels"
|
|
15042
14949
|
},
|
|
15043
14950
|
Settings: {
|
|
15044
|
-
data: xml(this.formatter.format(file.
|
|
14951
|
+
data: xml(this.formatter.format(file.settings, {
|
|
15045
14952
|
fileData: file,
|
|
15046
14953
|
file,
|
|
15047
14954
|
stack: [],
|
|
15048
|
-
viewWrapper: file.
|
|
14955
|
+
viewWrapper: file.document
|
|
15049
14956
|
}), {
|
|
15050
14957
|
declaration: {
|
|
15051
14958
|
encoding: "UTF-8",
|
|
@@ -15056,28 +14963,28 @@ var Compiler = class {
|
|
|
15056
14963
|
path: "word/settings.xml"
|
|
15057
14964
|
},
|
|
15058
14965
|
Styles: {
|
|
15059
|
-
data: replaceNumberingPlaceholders(xml(this.formatter.format(file.
|
|
14966
|
+
data: replaceNumberingPlaceholders(xml(this.formatter.format(file.styles, {
|
|
15060
14967
|
fileData: file,
|
|
15061
14968
|
file,
|
|
15062
14969
|
stack: [],
|
|
15063
|
-
viewWrapper: file.
|
|
14970
|
+
viewWrapper: file.document
|
|
15064
14971
|
}), {
|
|
15065
14972
|
declaration: {
|
|
15066
14973
|
encoding: "UTF-8",
|
|
15067
14974
|
standalone: "yes"
|
|
15068
14975
|
},
|
|
15069
14976
|
indent: prettify
|
|
15070
|
-
}), file.
|
|
14977
|
+
}), file.numbering.concreteNumbering),
|
|
15071
14978
|
path: "word/styles.xml"
|
|
15072
14979
|
},
|
|
15073
|
-
...file.
|
|
15074
|
-
data: xml(this.formatter.format(file.
|
|
14980
|
+
...file.bibliography ? { Bibliography: {
|
|
14981
|
+
data: xml(this.formatter.format(file.bibliography, {
|
|
15075
14982
|
fileData: file,
|
|
15076
14983
|
file,
|
|
15077
14984
|
stack: [],
|
|
15078
14985
|
viewWrapper: {
|
|
15079
|
-
|
|
15080
|
-
|
|
14986
|
+
relationships: file.bibliography.relationships,
|
|
14987
|
+
view: file.bibliography
|
|
15081
14988
|
}
|
|
15082
14989
|
}), {
|
|
15083
14990
|
declaration: {
|
|
@@ -15088,12 +14995,12 @@ var Compiler = class {
|
|
|
15088
14995
|
}),
|
|
15089
14996
|
path: "word/bibliography.xml"
|
|
15090
14997
|
} } : {},
|
|
15091
|
-
...file.
|
|
14998
|
+
...file.charts.array.length > 0 ? { Charts: file.charts.array.flatMap((chartData, i) => [{
|
|
15092
14999
|
data: xml(this.formatter.format(chartData.chartSpace, {
|
|
15093
15000
|
fileData: file,
|
|
15094
15001
|
file,
|
|
15095
15002
|
stack: [],
|
|
15096
|
-
viewWrapper: file.
|
|
15003
|
+
viewWrapper: file.document
|
|
15097
15004
|
}), {
|
|
15098
15005
|
declaration: {
|
|
15099
15006
|
encoding: "UTF-8",
|
|
@@ -15109,13 +15016,13 @@ var Compiler = class {
|
|
|
15109
15016
|
} }),
|
|
15110
15017
|
path: `word/charts/_rels/chart${i + 1}.xml.rels`
|
|
15111
15018
|
}]) } : {},
|
|
15112
|
-
...file.
|
|
15113
|
-
DiagramData: file.
|
|
15019
|
+
...file.smartArts.array.length > 0 ? {
|
|
15020
|
+
DiagramData: file.smartArts.array.map((smartArtData, i) => ({
|
|
15114
15021
|
data: xml(this.formatter.format(smartArtData.dataModel, {
|
|
15115
15022
|
fileData: file,
|
|
15116
15023
|
file,
|
|
15117
15024
|
stack: [],
|
|
15118
|
-
viewWrapper: file.
|
|
15025
|
+
viewWrapper: file.document
|
|
15119
15026
|
}), {
|
|
15120
15027
|
declaration: {
|
|
15121
15028
|
encoding: "UTF-8",
|
|
@@ -15125,28 +15032,28 @@ var Compiler = class {
|
|
|
15125
15032
|
}),
|
|
15126
15033
|
path: `word/diagrams/data${i + 1}.xml`
|
|
15127
15034
|
})),
|
|
15128
|
-
DiagramLayout: file.
|
|
15035
|
+
DiagramLayout: file.smartArts.array.map((smartArtData, i) => ({
|
|
15129
15036
|
data: getLayoutXml(smartArtData.layout),
|
|
15130
15037
|
path: `word/diagrams/layout${i + 1}.xml`
|
|
15131
15038
|
})),
|
|
15132
|
-
DiagramStyle: file.
|
|
15039
|
+
DiagramStyle: file.smartArts.array.map((smartArtData, i) => ({
|
|
15133
15040
|
data: getStyleXml(smartArtData.style),
|
|
15134
15041
|
path: `word/diagrams/quickStyle${i + 1}.xml`
|
|
15135
15042
|
})),
|
|
15136
|
-
DiagramColors: file.
|
|
15043
|
+
DiagramColors: file.smartArts.array.map((smartArtData, i) => ({
|
|
15137
15044
|
data: getColorXml(smartArtData.color),
|
|
15138
15045
|
path: `word/diagrams/colors${i + 1}.xml`
|
|
15139
15046
|
})),
|
|
15140
|
-
DiagramDrawing: file.
|
|
15047
|
+
DiagramDrawing: file.smartArts.array.map((_, i) => ({
|
|
15141
15048
|
data: DEFAULT_DRAWING_XML,
|
|
15142
15049
|
path: `word/diagrams/drawing${i + 1}.xml`
|
|
15143
15050
|
}))
|
|
15144
15051
|
} : {},
|
|
15145
|
-
...file.
|
|
15052
|
+
...file.altChunks.array.length > 0 ? { AltChunks: file.altChunks.array.map((altChunkData) => ({
|
|
15146
15053
|
data: altChunkData.data,
|
|
15147
15054
|
path: `word/${altChunkData.path}`
|
|
15148
15055
|
})) } : {},
|
|
15149
|
-
...file.
|
|
15056
|
+
...file.subDocs.array.length > 0 ? { SubDocs: file.subDocs.array.map((subDocData) => ({
|
|
15150
15057
|
data: subDocData.data,
|
|
15151
15058
|
path: `word/${subDocData.path}`
|
|
15152
15059
|
})) } : {}
|
|
@@ -15190,581 +15097,30 @@ init_convenience_functions();
|
|
|
15190
15097
|
init_values();
|
|
15191
15098
|
__reExport(util_exports, values_exports);
|
|
15192
15099
|
//#endregion
|
|
15193
|
-
//#region src/patcher/util.ts
|
|
15194
|
-
/**
|
|
15195
|
-
* Utility functions for XML manipulation in document patching.
|
|
15196
|
-
*
|
|
15197
|
-
* @module
|
|
15198
|
-
*/
|
|
15199
|
-
init_text();
|
|
15200
|
-
/**
|
|
15201
|
-
* Converts XML string to JSON element structure.
|
|
15202
|
-
*
|
|
15203
|
-
* Parses XML text into a JavaScript object representation that can be
|
|
15204
|
-
* manipulated programmatically. Preserves spaces between elements for
|
|
15205
|
-
* accurate text handling.
|
|
15206
|
-
*
|
|
15207
|
-
* @param xmlData - The XML string to parse
|
|
15208
|
-
* @returns Parsed XML as an Element object
|
|
15209
|
-
*
|
|
15210
|
-
* @example
|
|
15211
|
-
* ```typescript
|
|
15212
|
-
* const element = toJson('<w:p><w:r><w:t>Hello</w:t></w:r></w:p>');
|
|
15213
|
-
* ```
|
|
15214
|
-
*/
|
|
15215
|
-
const toJson = (xmlData) => {
|
|
15216
|
-
return xml2js(xmlData, {
|
|
15217
|
-
captureSpacesBetweenElements: true,
|
|
15218
|
-
compact: false
|
|
15219
|
-
});
|
|
15220
|
-
};
|
|
15221
|
-
/**
|
|
15222
|
-
* Creates text element contents from a text string.
|
|
15223
|
-
*
|
|
15224
|
-
* Generates the XML element structure for a text node (w:t) by formatting
|
|
15225
|
-
* a Text component and extracting its element contents. Used when creating
|
|
15226
|
-
* new text runs during replacement operations.
|
|
15227
|
-
*
|
|
15228
|
-
* @param text - The text content to wrap in element structure
|
|
15229
|
-
* @returns Array of XML elements representing the text
|
|
15230
|
-
*
|
|
15231
|
-
* @example
|
|
15232
|
-
* ```typescript
|
|
15233
|
-
* const elements = createTextElementContents("Hello World");
|
|
15234
|
-
* // Returns XML elements for <w:t>Hello World</w:t>
|
|
15235
|
-
* ```
|
|
15236
|
-
*/
|
|
15237
|
-
const createTextElementContents = (text) => {
|
|
15238
|
-
return toJson(xml(buildText({ text }))).elements[0].elements ?? [];
|
|
15239
|
-
};
|
|
15240
|
-
/**
|
|
15241
|
-
* Adds xml:space="preserve" attribute to an element.
|
|
15242
|
-
*
|
|
15243
|
-
* The xml:space attribute instructs XML processors to preserve whitespace
|
|
15244
|
-
* in the element's content. This is important when text contains leading
|
|
15245
|
-
* or trailing spaces that must be maintained.
|
|
15246
|
-
*
|
|
15247
|
-
* @param element - The element to patch
|
|
15248
|
-
* @returns New element with xml:space attribute added
|
|
15249
|
-
*
|
|
15250
|
-
* @example
|
|
15251
|
-
* ```typescript
|
|
15252
|
-
* const patched = patchSpaceAttribute(textElement);
|
|
15253
|
-
* // Adds xml:space="preserve" to maintain whitespace
|
|
15254
|
-
* ```
|
|
15255
|
-
*/
|
|
15256
|
-
const patchSpaceAttribute = (element) => ({
|
|
15257
|
-
...element,
|
|
15258
|
-
attributes: { "xml:space": "preserve" }
|
|
15259
|
-
});
|
|
15260
|
-
/**
|
|
15261
|
-
* Retrieves first-level child elements by parent element name.
|
|
15262
|
-
*
|
|
15263
|
-
* Finds the first element with the specified name and returns its children.
|
|
15264
|
-
* Used to access collections like relationship elements or content type definitions.
|
|
15265
|
-
*
|
|
15266
|
-
* @param relationships - The parent XML element to search
|
|
15267
|
-
* @param id - The element name to find
|
|
15268
|
-
* @returns Array of child elements
|
|
15269
|
-
*
|
|
15270
|
-
* @example
|
|
15271
|
-
* ```typescript
|
|
15272
|
-
* const rels = getFirstLevelElements(relationshipsXml, "Relationships");
|
|
15273
|
-
* // Returns array of Relationship elements
|
|
15274
|
-
* ```
|
|
15275
|
-
*/
|
|
15276
|
-
const getFirstLevelElements = (relationships, id) => relationships.elements?.filter((e) => e.name === id)[0].elements ?? [];
|
|
15277
|
-
//#endregion
|
|
15278
|
-
//#region src/patcher/content-types-manager.ts
|
|
15279
|
-
/**
|
|
15280
|
-
* Appends a content type definition to the [Content_Types].xml structure.
|
|
15281
|
-
*
|
|
15282
|
-
* The [Content_Types].xml file declares the MIME types for all file extensions
|
|
15283
|
-
* in the OOXML package. This function adds a new content type if it doesn't
|
|
15284
|
-
* already exist, ensuring that newly added media files are properly declared.
|
|
15285
|
-
*
|
|
15286
|
-
* @param element - The [Content_Types].xml root element
|
|
15287
|
-
* @param contentType - The MIME type (e.g., "image/png")
|
|
15288
|
-
* @param extension - The file extension (e.g., "png")
|
|
15289
|
-
*
|
|
15290
|
-
* @example
|
|
15291
|
-
* ```typescript
|
|
15292
|
-
* appendContentType(contentTypesElement, "image/png", "png");
|
|
15293
|
-
* appendContentType(contentTypesElement, "image/jpeg", "jpg");
|
|
15294
|
-
* ```
|
|
15295
|
-
*/
|
|
15296
|
-
const appendContentType = (element, contentType, extension) => {
|
|
15297
|
-
const relationshipElements = getFirstLevelElements(element, "Types");
|
|
15298
|
-
if (relationshipElements.some((el) => el.type === "element" && el.name === "Default" && el?.attributes?.ContentType === contentType && el?.attributes?.Extension === extension)) return;
|
|
15299
|
-
relationshipElements.push({
|
|
15300
|
-
attributes: {
|
|
15301
|
-
ContentType: contentType,
|
|
15302
|
-
Extension: extension
|
|
15303
|
-
},
|
|
15304
|
-
name: "Default",
|
|
15305
|
-
type: "element"
|
|
15306
|
-
});
|
|
15307
|
-
};
|
|
15308
|
-
//#endregion
|
|
15309
|
-
//#region src/patcher/relationship-manager.ts
|
|
15310
|
-
/**
|
|
15311
|
-
* Extracts the numeric ID from a relationship ID string.
|
|
15312
|
-
*
|
|
15313
|
-
* @param relationshipId - Relationship ID in format "rId123"
|
|
15314
|
-
* @returns The numeric portion of the ID
|
|
15315
|
-
*/
|
|
15316
|
-
const getIdFromRelationshipId = (relationshipId) => {
|
|
15317
|
-
const output = parseInt(relationshipId.substring(3), 10);
|
|
15318
|
-
return isNaN(output) ? 0 : output;
|
|
15319
|
-
};
|
|
15320
|
-
/**
|
|
15321
|
-
* Determines the next available relationship ID number.
|
|
15322
|
-
*
|
|
15323
|
-
* Scans all existing relationships and returns the next sequential ID number
|
|
15324
|
-
* to use when adding a new relationship.
|
|
15325
|
-
*
|
|
15326
|
-
* @param relationships - The relationships XML element
|
|
15327
|
-
* @returns The next available relationship ID number
|
|
15328
|
-
*
|
|
15329
|
-
* @example
|
|
15330
|
-
* ```typescript
|
|
15331
|
-
* const nextId = getNextRelationshipIndex(relationshipsElement);
|
|
15332
|
-
* // If highest existing ID is rId5, returns 6
|
|
15333
|
-
* ```
|
|
15334
|
-
*/
|
|
15335
|
-
const getNextRelationshipIndex = (relationships) => {
|
|
15336
|
-
return getFirstLevelElements(relationships, "Relationships").map((e) => getIdFromRelationshipId(e.attributes?.Id?.toString() ?? "")).reduce((acc, curr) => Math.max(acc, curr), 0) + 1;
|
|
15337
|
-
};
|
|
15338
|
-
/**
|
|
15339
|
-
* Appends a new relationship to a .rels file structure.
|
|
15340
|
-
*
|
|
15341
|
-
* Relationships define connections between parts of an OOXML package,
|
|
15342
|
-
* such as linking documents to images, hyperlinks, or other resources.
|
|
15343
|
-
*
|
|
15344
|
-
* @param relationships - The relationships XML element
|
|
15345
|
-
* @param id - The relationship ID (number or string)
|
|
15346
|
-
* @param type - The relationship type URI
|
|
15347
|
-
* @param target - The target path or URI
|
|
15348
|
-
* @param targetMode - Optional target mode (Internal or External)
|
|
15349
|
-
* @returns The updated relationship elements array
|
|
15350
|
-
*
|
|
15351
|
-
* @example
|
|
15352
|
-
* ```typescript
|
|
15353
|
-
* appendRelationship(
|
|
15354
|
-
* relationshipsElement,
|
|
15355
|
-
* 6,
|
|
15356
|
-
* "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
15357
|
-
* "media/image1.png"
|
|
15358
|
-
* );
|
|
15359
|
-
* ```
|
|
15360
|
-
*/
|
|
15361
|
-
const appendRelationship = (relationships, id, type, target, targetMode) => {
|
|
15362
|
-
const relationshipElements = getFirstLevelElements(relationships, "Relationships");
|
|
15363
|
-
relationshipElements.push({
|
|
15364
|
-
attributes: {
|
|
15365
|
-
Id: `rId${id}`,
|
|
15366
|
-
Target: target,
|
|
15367
|
-
TargetMode: targetMode,
|
|
15368
|
-
Type: type
|
|
15369
|
-
},
|
|
15370
|
-
name: "Relationship",
|
|
15371
|
-
type: "element"
|
|
15372
|
-
});
|
|
15373
|
-
return relationshipElements;
|
|
15374
|
-
};
|
|
15375
|
-
//#endregion
|
|
15376
|
-
//#region src/patcher/paragraph-split-inject.ts
|
|
15377
|
-
var TokenNotFoundError = class extends Error {
|
|
15378
|
-
constructor(token) {
|
|
15379
|
-
super(`Token ${token} not found`);
|
|
15380
|
-
this.name = "TokenNotFoundError";
|
|
15381
|
-
}
|
|
15382
|
-
};
|
|
15383
|
-
/**
|
|
15384
|
-
* Finds the index of the run element containing a specific token.
|
|
15385
|
-
*
|
|
15386
|
-
* Searches through all run (w:r) elements in a paragraph to find which one
|
|
15387
|
-
* contains the specified token text. This is used to locate where new content
|
|
15388
|
-
* should be injected during replacement operations.
|
|
15389
|
-
*
|
|
15390
|
-
* @param paragraphElement - The paragraph element to search
|
|
15391
|
-
* @param token - The token text to find
|
|
15392
|
-
* @returns The index of the run element containing the token
|
|
15393
|
-
* @throws Error if the token is not found in any run
|
|
15394
|
-
*
|
|
15395
|
-
* @example
|
|
15396
|
-
* ```typescript
|
|
15397
|
-
* const index = findRunElementIndexWithToken(paragraph, "ɵ");
|
|
15398
|
-
* // Returns the index of the run containing the split token
|
|
15399
|
-
* ```
|
|
15400
|
-
*/
|
|
15401
|
-
const findRunElementIndexWithToken = (paragraphElement, token) => {
|
|
15402
|
-
for (let i = 0; i < (paragraphElement.elements ?? []).length; i++) {
|
|
15403
|
-
const element = paragraphElement.elements[i];
|
|
15404
|
-
if (element.type === "element" && element.name === "w:r") {
|
|
15405
|
-
const textElement = (element.elements ?? []).filter((e) => e.type === "element" && e.name === "w:t");
|
|
15406
|
-
for (const text of textElement) {
|
|
15407
|
-
if (!text.elements?.[0]) continue;
|
|
15408
|
-
if (text.elements[0].text?.includes(token)) return i;
|
|
15409
|
-
}
|
|
15410
|
-
}
|
|
15411
|
-
}
|
|
15412
|
-
throw new TokenNotFoundError(token);
|
|
15413
|
-
};
|
|
15414
|
-
/**
|
|
15415
|
-
* Splits a run element at a token position into left and right parts.
|
|
15416
|
-
*
|
|
15417
|
-
* Divides a run element at the location of a token, creating two separate
|
|
15418
|
-
* runs. This allows new content to be injected between the split parts while
|
|
15419
|
-
* preserving the original run's formatting properties.
|
|
15420
|
-
*
|
|
15421
|
-
* @param runElement - The run element to split
|
|
15422
|
-
* @param token - The token text marking the split point
|
|
15423
|
-
* @returns Object containing the left and right run elements
|
|
15424
|
-
*
|
|
15425
|
-
* @example
|
|
15426
|
-
* ```typescript
|
|
15427
|
-
* const { left, right } = splitRunElement(run, "ɵ");
|
|
15428
|
-
* // If run contains "Helloɵworld", left contains "Hello" and right contains "world"
|
|
15429
|
-
* ```
|
|
15430
|
-
*/
|
|
15431
|
-
const splitRunElement = (runElement, token) => {
|
|
15432
|
-
let splitIndex = -1;
|
|
15433
|
-
const splitElements = runElement.elements?.map((e, i) => {
|
|
15434
|
-
if (splitIndex !== -1) return e;
|
|
15435
|
-
if (e.type === "element" && e.name === "w:t") {
|
|
15436
|
-
const splitText = (e.elements?.[0]?.text ?? "").split(token);
|
|
15437
|
-
const newElements = splitText.map((t) => ({
|
|
15438
|
-
...e,
|
|
15439
|
-
...patchSpaceAttribute(e),
|
|
15440
|
-
elements: createTextElementContents(t)
|
|
15441
|
-
}));
|
|
15442
|
-
if (splitText.length > 1) splitIndex = i;
|
|
15443
|
-
return newElements;
|
|
15444
|
-
} else return e;
|
|
15445
|
-
}).flat() ?? [];
|
|
15446
|
-
return {
|
|
15447
|
-
left: {
|
|
15448
|
-
...JSON.parse(JSON.stringify(runElement)),
|
|
15449
|
-
elements: splitElements.slice(0, splitIndex + 1)
|
|
15450
|
-
},
|
|
15451
|
-
right: {
|
|
15452
|
-
...JSON.parse(JSON.stringify(runElement)),
|
|
15453
|
-
elements: splitElements.slice(splitIndex + 1)
|
|
15454
|
-
}
|
|
15455
|
-
};
|
|
15456
|
-
};
|
|
15457
|
-
//#endregion
|
|
15458
|
-
//#region src/patcher/paragraph-token-replacer.ts
|
|
15459
|
-
/**
|
|
15460
|
-
* Replacement modes for multi-run text replacement.
|
|
15461
|
-
*/
|
|
15462
|
-
const ReplaceMode = {
|
|
15463
|
-
/** Looking for the start of the replacement text */
|
|
15464
|
-
START: 0,
|
|
15465
|
-
/** Processing runs in the middle of the replacement text */
|
|
15466
|
-
MIDDLE: 1,
|
|
15467
|
-
/** Reached the end of the replacement text */
|
|
15468
|
-
END: 2
|
|
15469
|
-
};
|
|
15470
|
-
/**
|
|
15471
|
-
* Replaces a token with replacement text within a paragraph's run elements.
|
|
15472
|
-
*
|
|
15473
|
-
* Handles the complex case where placeholder text may span multiple runs
|
|
15474
|
-
* (text fragments) within a paragraph. Processes each run to replace the
|
|
15475
|
-
* appropriate portion of the token, handling start, middle, and end sections.
|
|
15476
|
-
*
|
|
15477
|
-
* @param paragraphElement - The paragraph XML element to modify
|
|
15478
|
-
* @param renderedParagraph - Pre-rendered paragraph structure with text positions
|
|
15479
|
-
* @param originalText - The token text to replace (e.g., "{{name}}")
|
|
15480
|
-
* @param replacementText - The text to replace it with (often a split token)
|
|
15481
|
-
* @returns The modified paragraph element
|
|
15482
|
-
*
|
|
15483
|
-
* @example
|
|
15484
|
-
* ```typescript
|
|
15485
|
-
* replaceTokenInParagraphElement({
|
|
15486
|
-
* paragraphElement,
|
|
15487
|
-
* renderedParagraph,
|
|
15488
|
-
* originalText: "{{placeholder}}",
|
|
15489
|
-
* replacementText: "ɵ",
|
|
15490
|
-
* });
|
|
15491
|
-
* ```
|
|
15492
|
-
*/
|
|
15493
|
-
const replaceTokenInParagraphElement = ({ paragraphElement, renderedParagraph, originalText, replacementText }) => {
|
|
15494
|
-
const startIndex = renderedParagraph.text.indexOf(originalText);
|
|
15495
|
-
const endIndex = startIndex + originalText.length - 1;
|
|
15496
|
-
let replaceMode = ReplaceMode.START;
|
|
15497
|
-
for (const run of renderedParagraph.runs) for (const { text, index, start, end } of run.parts) switch (replaceMode) {
|
|
15498
|
-
case ReplaceMode.START:
|
|
15499
|
-
if (startIndex >= start && startIndex <= end) {
|
|
15500
|
-
const offsetStartIndex = startIndex - start;
|
|
15501
|
-
const offsetEndIndex = Math.min(endIndex, end) - start;
|
|
15502
|
-
const partToReplace = text.substring(offsetStartIndex, offsetEndIndex + 1);
|
|
15503
|
-
if (partToReplace === "") continue;
|
|
15504
|
-
const firstPart = text.replace(partToReplace, replacementText);
|
|
15505
|
-
patchTextElement(paragraphElement.elements[run.index].elements[index], firstPart);
|
|
15506
|
-
replaceMode = ReplaceMode.MIDDLE;
|
|
15507
|
-
continue;
|
|
15508
|
-
}
|
|
15509
|
-
break;
|
|
15510
|
-
case ReplaceMode.MIDDLE:
|
|
15511
|
-
if (endIndex <= end) {
|
|
15512
|
-
const lastPart = text.substring(endIndex - start + 1);
|
|
15513
|
-
patchTextElement(paragraphElement.elements[run.index].elements[index], lastPart);
|
|
15514
|
-
const currentElement = paragraphElement.elements[run.index].elements[index];
|
|
15515
|
-
paragraphElement.elements[run.index].elements[index] = patchSpaceAttribute(currentElement);
|
|
15516
|
-
replaceMode = ReplaceMode.END;
|
|
15517
|
-
} else patchTextElement(paragraphElement.elements[run.index].elements[index], "");
|
|
15518
|
-
break;
|
|
15519
|
-
default:
|
|
15520
|
-
}
|
|
15521
|
-
return paragraphElement;
|
|
15522
|
-
};
|
|
15523
|
-
const patchTextElement = (element, text) => {
|
|
15524
|
-
element.elements = createTextElementContents(text);
|
|
15525
|
-
return element;
|
|
15526
|
-
};
|
|
15527
|
-
//#endregion
|
|
15528
|
-
//#region src/patcher/run-renderer.ts
|
|
15529
|
-
/**
|
|
15530
|
-
* Renders a paragraph element into a structured representation with text content.
|
|
15531
|
-
*
|
|
15532
|
-
* Extracts all text content from a paragraph (w:p) element by processing its
|
|
15533
|
-
* run (w:r) children. Calculates character positions for each text fragment
|
|
15534
|
-
* to enable precise text replacement operations.
|
|
15535
|
-
*
|
|
15536
|
-
* @param node - The paragraph element wrapper to render
|
|
15537
|
-
* @returns Rendered paragraph with text content, runs, and position information
|
|
15538
|
-
* @throws Error if the node is not a paragraph element
|
|
15539
|
-
*
|
|
15540
|
-
* @example
|
|
15541
|
-
* ```typescript
|
|
15542
|
-
* const rendered = renderParagraphNode(paragraphWrapper);
|
|
15543
|
-
* console.log(rendered.text); // "Hello World"
|
|
15544
|
-
* console.log(rendered.runs.length); // 2 (if text is in separate runs)
|
|
15545
|
-
* ```
|
|
15546
|
-
*/
|
|
15547
|
-
const renderParagraphNode = (node) => {
|
|
15548
|
-
if (node.element.name !== "w:p") throw new Error(`Invalid node type: ${node.element.name}`);
|
|
15549
|
-
if (!node.element.elements) return {
|
|
15550
|
-
index: -1,
|
|
15551
|
-
pathToParagraph: [],
|
|
15552
|
-
runs: [],
|
|
15553
|
-
text: ""
|
|
15554
|
-
};
|
|
15555
|
-
let currentRunStringLength = 0;
|
|
15556
|
-
const runs = node.element.elements.map((element, i) => ({
|
|
15557
|
-
element,
|
|
15558
|
-
i
|
|
15559
|
-
})).filter(({ element }) => element.name === "w:r").map(({ element, i }) => {
|
|
15560
|
-
const renderedRunNode = renderRunNode(element, i, currentRunStringLength);
|
|
15561
|
-
currentRunStringLength += renderedRunNode.text.length;
|
|
15562
|
-
return renderedRunNode;
|
|
15563
|
-
}).filter((e) => Boolean(e));
|
|
15564
|
-
const text = runs.reduce((acc, curr) => acc + curr.text, "");
|
|
15565
|
-
return {
|
|
15566
|
-
index: node.index,
|
|
15567
|
-
pathToParagraph: buildNodePath(node),
|
|
15568
|
-
runs,
|
|
15569
|
-
text
|
|
15570
|
-
};
|
|
15571
|
-
};
|
|
15572
|
-
const renderRunNode = (node, index, currentRunStringIndex) => {
|
|
15573
|
-
if (!node.elements) return {
|
|
15574
|
-
end: currentRunStringIndex,
|
|
15575
|
-
index: -1,
|
|
15576
|
-
parts: [],
|
|
15577
|
-
start: currentRunStringIndex,
|
|
15578
|
-
text: ""
|
|
15579
|
-
};
|
|
15580
|
-
let currentTextStringIndex = currentRunStringIndex;
|
|
15581
|
-
const parts = node.elements.map((element, i) => element.name === "w:t" && element.elements && element.elements.length > 0 ? (() => {
|
|
15582
|
-
const partStart = currentTextStringIndex;
|
|
15583
|
-
currentTextStringIndex += (element.elements[0].text?.toString() ?? "").length;
|
|
15584
|
-
return {
|
|
15585
|
-
end: currentTextStringIndex - 1,
|
|
15586
|
-
index: i,
|
|
15587
|
-
start: partStart,
|
|
15588
|
-
text: element.elements[0].text?.toString() ?? ""
|
|
15589
|
-
};
|
|
15590
|
-
})() : void 0).filter((e) => Boolean(e)).map((e) => e);
|
|
15591
|
-
const text = parts.reduce((acc, curr) => acc + curr.text, "");
|
|
15592
|
-
return {
|
|
15593
|
-
end: currentTextStringIndex - 1,
|
|
15594
|
-
index,
|
|
15595
|
-
parts,
|
|
15596
|
-
start: currentRunStringIndex,
|
|
15597
|
-
text
|
|
15598
|
-
};
|
|
15599
|
-
};
|
|
15600
|
-
const buildNodePath = (node) => node.parent ? [...buildNodePath(node.parent), node.index] : [node.index];
|
|
15601
|
-
//#endregion
|
|
15602
|
-
//#region src/patcher/traverser.ts
|
|
15603
|
-
const elementsToWrapper = (wrapper) => wrapper.element.elements?.map((e, i) => ({
|
|
15604
|
-
element: e,
|
|
15605
|
-
index: i,
|
|
15606
|
-
parent: wrapper
|
|
15607
|
-
})) ?? [];
|
|
15608
|
-
/**
|
|
15609
|
-
* Traverses an XML document tree to find and render all paragraphs.
|
|
15610
|
-
*
|
|
15611
|
-
* Uses breadth-first search to walk through the XML structure, identifying
|
|
15612
|
-
* all paragraph elements (w:p) and rendering their text content along with
|
|
15613
|
-
* positional information.
|
|
15614
|
-
*
|
|
15615
|
-
* @param node - The root XML element to traverse
|
|
15616
|
-
* @returns Array of rendered paragraph nodes with text content and positions
|
|
15617
|
-
*
|
|
15618
|
-
* @example
|
|
15619
|
-
* ```typescript
|
|
15620
|
-
* const paragraphs = traverse(documentElement);
|
|
15621
|
-
* paragraphs.forEach(p => console.log(p.text));
|
|
15622
|
-
* ```
|
|
15623
|
-
*/
|
|
15624
|
-
const traverse = (node) => {
|
|
15625
|
-
let renderedParagraphs = [];
|
|
15626
|
-
const queue = [...elementsToWrapper({
|
|
15627
|
-
element: node,
|
|
15628
|
-
index: 0,
|
|
15629
|
-
parent: void 0
|
|
15630
|
-
})];
|
|
15631
|
-
let currentNode;
|
|
15632
|
-
while (queue.length > 0) {
|
|
15633
|
-
currentNode = queue.shift();
|
|
15634
|
-
if (currentNode.element.name === "w:p") renderedParagraphs = [...renderedParagraphs, renderParagraphNode(currentNode)];
|
|
15635
|
-
queue.push(...elementsToWrapper(currentNode));
|
|
15636
|
-
}
|
|
15637
|
-
return renderedParagraphs;
|
|
15638
|
-
};
|
|
15639
|
-
/**
|
|
15640
|
-
* Finds all paragraphs containing specific text.
|
|
15641
|
-
*
|
|
15642
|
-
* Traverses the document and filters paragraphs to find those containing
|
|
15643
|
-
* the specified text string. Useful for locating placeholder text that
|
|
15644
|
-
* needs to be replaced.
|
|
15645
|
-
*
|
|
15646
|
-
* @param node - The root XML element to search
|
|
15647
|
-
* @param text - The text to search for
|
|
15648
|
-
* @returns Array of paragraph nodes containing the text
|
|
15649
|
-
*
|
|
15650
|
-
* @example
|
|
15651
|
-
* ```typescript
|
|
15652
|
-
* const matches = findLocationOfText(documentElement, "{{name}}");
|
|
15653
|
-
* // Returns all paragraphs containing "{{name}}"
|
|
15654
|
-
* ```
|
|
15655
|
-
*/
|
|
15656
|
-
const findLocationOfText = (node, text) => traverse(node).filter((p) => p.text.includes(text));
|
|
15657
|
-
//#endregion
|
|
15658
|
-
//#region src/patcher/replacer.ts
|
|
15659
|
-
/**
|
|
15660
|
-
* Replacer module for performing placeholder substitution in XML structures.
|
|
15661
|
-
*
|
|
15662
|
-
* @module
|
|
15663
|
-
*/
|
|
15664
|
-
const formatter = new Formatter();
|
|
15665
|
-
const SPLIT_TOKEN = "ɵ";
|
|
15666
|
-
/**
|
|
15667
|
-
* Replaces placeholder text in XML with new content from a patch.
|
|
15668
|
-
*
|
|
15669
|
-
* This function locates placeholder text within the XML structure and performs
|
|
15670
|
-
* the appropriate replacement based on the patch type (document or paragraph level).
|
|
15671
|
-
* It handles splitting runs, preserving styles, and injecting the new content.
|
|
15672
|
-
*
|
|
15673
|
-
* @param json - The XML element structure to search
|
|
15674
|
-
* @param patch - The patch definition containing replacement content
|
|
15675
|
-
* @param patchText - The placeholder text to find (e.g., "{{name}}")
|
|
15676
|
-
* @param context - The document context for formatting
|
|
15677
|
-
* @param keepOriginalStyles - Whether to preserve original text formatting
|
|
15678
|
-
* @returns Result containing the modified element and whether a replacement occurred
|
|
15679
|
-
*/
|
|
15680
|
-
const replacer = ({ json, patch, patchText, context, keepOriginalStyles = true }) => {
|
|
15681
|
-
const renderedParagraphs = findLocationOfText(json, patchText);
|
|
15682
|
-
if (renderedParagraphs.length === 0) return {
|
|
15683
|
-
didFindOccurrence: false,
|
|
15684
|
-
element: json
|
|
15685
|
-
};
|
|
15686
|
-
for (const renderedParagraph of renderedParagraphs) {
|
|
15687
|
-
const textJson = patch.children.map((c) => toJson(xml(formatter.format(c, context)))).map((c) => c.elements[0]);
|
|
15688
|
-
switch (patch.type) {
|
|
15689
|
-
case PatchType.DOCUMENT: {
|
|
15690
|
-
const parentElement = goToParentElementFromPath(json, renderedParagraph.pathToParagraph);
|
|
15691
|
-
const elementIndex = getLastElementIndexFromPath(renderedParagraph.pathToParagraph);
|
|
15692
|
-
parentElement.elements.splice(elementIndex, 1, ...textJson);
|
|
15693
|
-
break;
|
|
15694
|
-
}
|
|
15695
|
-
case PatchType.PARAGRAPH:
|
|
15696
|
-
default: {
|
|
15697
|
-
const paragraphElement = goToElementFromPath(json, renderedParagraph.pathToParagraph);
|
|
15698
|
-
replaceTokenInParagraphElement({
|
|
15699
|
-
originalText: patchText,
|
|
15700
|
-
paragraphElement,
|
|
15701
|
-
renderedParagraph,
|
|
15702
|
-
replacementText: SPLIT_TOKEN
|
|
15703
|
-
});
|
|
15704
|
-
const index = findRunElementIndexWithToken(paragraphElement, SPLIT_TOKEN);
|
|
15705
|
-
const runElementToBeReplaced = paragraphElement.elements[index];
|
|
15706
|
-
const { left, right } = splitRunElement(runElementToBeReplaced, SPLIT_TOKEN);
|
|
15707
|
-
let newRunElements = textJson;
|
|
15708
|
-
let patchedRightElement = right;
|
|
15709
|
-
if (keepOriginalStyles) {
|
|
15710
|
-
const runElementNonTextualElements = runElementToBeReplaced.elements.filter((e) => e.type === "element" && e.name === "w:rPr");
|
|
15711
|
-
newRunElements = textJson.map((e) => {
|
|
15712
|
-
if (e.type !== "element" || e.name !== "w:r" || e.elements?.some((c) => c.type === "element" && c.name === "w:rPr")) return e;
|
|
15713
|
-
return {
|
|
15714
|
-
...e,
|
|
15715
|
-
elements: [...runElementNonTextualElements, ...e.elements ?? []]
|
|
15716
|
-
};
|
|
15717
|
-
});
|
|
15718
|
-
patchedRightElement = {
|
|
15719
|
-
...right,
|
|
15720
|
-
elements: [...runElementNonTextualElements, ...right.elements]
|
|
15721
|
-
};
|
|
15722
|
-
}
|
|
15723
|
-
paragraphElement.elements.splice(index, 1, left, ...newRunElements, patchedRightElement);
|
|
15724
|
-
break;
|
|
15725
|
-
}
|
|
15726
|
-
}
|
|
15727
|
-
}
|
|
15728
|
-
return {
|
|
15729
|
-
didFindOccurrence: true,
|
|
15730
|
-
element: json
|
|
15731
|
-
};
|
|
15732
|
-
};
|
|
15733
|
-
const goToElementFromPath = (json, path) => {
|
|
15734
|
-
let element = json;
|
|
15735
|
-
for (let i = 1; i < path.length; i++) {
|
|
15736
|
-
const index = path[i];
|
|
15737
|
-
element = element.elements[index];
|
|
15738
|
-
}
|
|
15739
|
-
return element;
|
|
15740
|
-
};
|
|
15741
|
-
const goToParentElementFromPath = (json, path) => goToElementFromPath(json, path.slice(0, -1));
|
|
15742
|
-
const getLastElementIndexFromPath = (path) => path[path.length - 1];
|
|
15743
|
-
//#endregion
|
|
15744
15100
|
//#region src/patcher/from-docx.ts
|
|
15101
|
+
init_media();
|
|
15102
|
+
init_paragraph();
|
|
15103
|
+
init_relationship();
|
|
15104
|
+
init_convenience_functions();
|
|
15745
15105
|
/**
|
|
15746
15106
|
* Document patching module for modifying existing .docx files.
|
|
15747
15107
|
*
|
|
15748
|
-
* This module provides functionality to patch existing Word documents by replacing
|
|
15749
|
-
* placeholder text with new content while preserving the original document structure.
|
|
15750
|
-
*
|
|
15751
15108
|
* @module
|
|
15752
15109
|
*/
|
|
15753
|
-
|
|
15754
|
-
|
|
15755
|
-
|
|
15756
|
-
|
|
15110
|
+
const formatter = new Formatter();
|
|
15111
|
+
const docxReplacer = createReplacer({
|
|
15112
|
+
ns: DOCX_NS,
|
|
15113
|
+
formatChild: (child, context) => {
|
|
15114
|
+
return [toJson(xml(formatter.format(child, context))).elements[0]];
|
|
15115
|
+
}
|
|
15116
|
+
});
|
|
15757
15117
|
/**
|
|
15758
15118
|
* Patch type enumeration.
|
|
15759
15119
|
*
|
|
15760
|
-
* Determines how the replacement content should be inserted into the document.
|
|
15761
|
-
*
|
|
15762
15120
|
* @publicApi
|
|
15763
15121
|
*/
|
|
15764
15122
|
const PatchType = {
|
|
15765
|
-
/** Replace entire file-level elements (e.g., whole paragraphs) */
|
|
15766
15123
|
DOCUMENT: "file",
|
|
15767
|
-
/** Replace content within paragraphs (inline replacement) */
|
|
15768
15124
|
PARAGRAPH: "paragraph"
|
|
15769
15125
|
};
|
|
15770
15126
|
const UTF16LE = new Uint8Array([255, 254]);
|
|
@@ -15777,36 +15133,6 @@ const compareByteArrays = (a, b) => {
|
|
|
15777
15133
|
/**
|
|
15778
15134
|
* Patches an existing .docx document by replacing placeholders with new content.
|
|
15779
15135
|
*
|
|
15780
|
-
* This function opens an existing Word document, searches for placeholder text
|
|
15781
|
-
* (e.g., {{name}}), and replaces it with the provided content while preserving
|
|
15782
|
-
* the original document structure and optionally the original formatting.
|
|
15783
|
-
*
|
|
15784
|
-
* @param options - Configuration options for patching
|
|
15785
|
-
* @returns A promise resolving to the patched document in the specified output format
|
|
15786
|
-
*
|
|
15787
|
-
* @example
|
|
15788
|
-
* ```typescript
|
|
15789
|
-
* // Patch with paragraph content
|
|
15790
|
-
* const buffer = await patchDocument({
|
|
15791
|
-
* outputType: "nodebuffer",
|
|
15792
|
-
* data: templateBuffer,
|
|
15793
|
-
* patches: {
|
|
15794
|
-
* name: {
|
|
15795
|
-
* type: PatchType.PARAGRAPH,
|
|
15796
|
-
* children: [new TextRun({ text: "John Doe", bold: true })],
|
|
15797
|
-
* },
|
|
15798
|
-
* },
|
|
15799
|
-
* });
|
|
15800
|
-
*
|
|
15801
|
-
* // Patch with custom delimiters
|
|
15802
|
-
* const buffer = await patchDocument({
|
|
15803
|
-
* outputType: "nodebuffer",
|
|
15804
|
-
* data: templateBuffer,
|
|
15805
|
-
* patches: { ... },
|
|
15806
|
-
* placeholderDelimiters: { start: "<<", end: ">>" },
|
|
15807
|
-
* });
|
|
15808
|
-
* ```
|
|
15809
|
-
*
|
|
15810
15136
|
* @publicApi
|
|
15811
15137
|
*/
|
|
15812
15138
|
const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, placeholderDelimiters = {
|
|
@@ -15815,7 +15141,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15815
15141
|
}, recursive = true }) => {
|
|
15816
15142
|
const zipContent = unzipSync(toUint8Array(data));
|
|
15817
15143
|
const contexts = /* @__PURE__ */ new Map();
|
|
15818
|
-
const file = {
|
|
15144
|
+
const file = { media: new Media() };
|
|
15819
15145
|
const map = /* @__PURE__ */ new Map();
|
|
15820
15146
|
const imageRelationshipAdditions = [];
|
|
15821
15147
|
const hyperlinkRelationshipAdditions = [];
|
|
@@ -15850,7 +15176,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15850
15176
|
fileData: file,
|
|
15851
15177
|
file,
|
|
15852
15178
|
stack: [],
|
|
15853
|
-
viewWrapper: {
|
|
15179
|
+
viewWrapper: { relationships: { addRelationship: (linkId, _, target, __) => {
|
|
15854
15180
|
hyperlinkRelationshipAdditions.push({
|
|
15855
15181
|
hyperlink: {
|
|
15856
15182
|
id: linkId,
|
|
@@ -15866,7 +15192,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15866
15192
|
for (const [patchKey, patchValue] of Object.entries(patches)) {
|
|
15867
15193
|
const patchText = `${start}${patchKey}${end}`;
|
|
15868
15194
|
while (true) {
|
|
15869
|
-
const { didFindOccurrence } =
|
|
15195
|
+
const { didFindOccurrence } = docxReplacer({
|
|
15870
15196
|
context,
|
|
15871
15197
|
json,
|
|
15872
15198
|
keepOriginalStyles,
|
|
@@ -15891,7 +15217,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15891
15217
|
if (!recursive || !didFindOccurrence) break;
|
|
15892
15218
|
}
|
|
15893
15219
|
}
|
|
15894
|
-
const mediaDatas = getReferencedMedia(JSON.stringify(json), context.file.
|
|
15220
|
+
const mediaDatas = getReferencedMedia(JSON.stringify(json), context.file.media.array);
|
|
15895
15221
|
if (mediaDatas.length > 0) {
|
|
15896
15222
|
hasMedia = true;
|
|
15897
15223
|
imageRelationshipAdditions.push({
|
|
@@ -15931,14 +15257,11 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
|
|
|
15931
15257
|
appendContentType(contentTypesJson, "image/svg+xml", "svg");
|
|
15932
15258
|
}
|
|
15933
15259
|
const files = {};
|
|
15934
|
-
for (const [key, value] of map) files[key] = textToUint8Array(
|
|
15260
|
+
for (const [key, value] of map) files[key] = textToUint8Array(js2xml(value));
|
|
15935
15261
|
for (const [key, value] of binaryContentMap) files[key] = value;
|
|
15936
|
-
for (const { data: mediaData, fileName } of file.
|
|
15262
|
+
for (const { data: mediaData, fileName } of file.media.array) files[`word/media/${fileName}`] = mediaData instanceof Uint8Array ? mediaData : new Uint8Array(mediaData);
|
|
15937
15263
|
return await zipAndConvert(files, outputType, OoxmlMimeType.DOCX);
|
|
15938
15264
|
};
|
|
15939
|
-
const toXml = (jsonObj) => {
|
|
15940
|
-
return js2xml(jsonObj, { attributeValueFn: (str) => String(str).replace(/&(?!amp;|lt;|gt;|quot;|apos;)/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'") });
|
|
15941
|
-
};
|
|
15942
15265
|
const createRelationshipFile = () => ({
|
|
15943
15266
|
declaration: { attributes: {
|
|
15944
15267
|
encoding: "UTF-8",
|
|
@@ -15989,7 +15312,11 @@ const patchDetector = async ({ data }) => {
|
|
|
15989
15312
|
const patches = /* @__PURE__ */ new Set();
|
|
15990
15313
|
for (const [key, value] of Object.entries(zipContent)) {
|
|
15991
15314
|
if (!key.endsWith(".xml") && !key.endsWith(".rels")) continue;
|
|
15992
|
-
if (key.startsWith("word/") && !key.endsWith(".xml.rels"))
|
|
15315
|
+
if (key.startsWith("word/") && !key.endsWith(".xml.rels")) {
|
|
15316
|
+
const json = toJson(strFromU8(value));
|
|
15317
|
+
const { traverse } = createTraverser(DOCX_NS);
|
|
15318
|
+
traverse(json).forEach((p) => findPatchKeys(p.text).forEach((patch) => patches.add(patch)));
|
|
15319
|
+
}
|
|
15993
15320
|
}
|
|
15994
15321
|
return [...patches];
|
|
15995
15322
|
};
|
|
@@ -16003,939 +15330,1045 @@ const findPatchKeys = (text) => {
|
|
|
16003
15330
|
return text.match(/(?<=\{\{).+?(?=\}\})/gs) ?? [];
|
|
16004
15331
|
};
|
|
16005
15332
|
//#endregion
|
|
16006
|
-
//#region src/file/
|
|
15333
|
+
//#region src/file/drawing/drawing-parse.ts
|
|
16007
15334
|
/**
|
|
16008
|
-
*
|
|
15335
|
+
* Drawing parser for DOCX documents.
|
|
16009
15336
|
*
|
|
16010
|
-
* Parses w:
|
|
15337
|
+
* Parses w:drawing elements and extracts image, chart, or SmartArt data.
|
|
16011
15338
|
*
|
|
16012
15339
|
* @module
|
|
16013
15340
|
*/
|
|
16014
15341
|
/**
|
|
16015
|
-
* Parse a w:
|
|
16016
|
-
|
|
16017
|
-
function parseRunProperties(el) {
|
|
16018
|
-
const opts = {};
|
|
16019
|
-
const rStyle = findChild(el, "w:rStyle");
|
|
16020
|
-
if (rStyle) opts.style = attr(rStyle, "w:val");
|
|
16021
|
-
const font = findChild(el, "w:rFonts");
|
|
16022
|
-
if (font) {
|
|
16023
|
-
const ascii = attr(font, "w:ascii");
|
|
16024
|
-
const eastAsia = attr(font, "w:eastAsia");
|
|
16025
|
-
const hAnsi = attr(font, "w:hAnsi");
|
|
16026
|
-
const cs = attr(font, "w:cs");
|
|
16027
|
-
const hint = attr(font, "w:hint");
|
|
16028
|
-
if (ascii && !eastAsia && !hAnsi && !cs) opts.font = hint ? {
|
|
16029
|
-
name: ascii,
|
|
16030
|
-
hint
|
|
16031
|
-
} : ascii;
|
|
16032
|
-
else {
|
|
16033
|
-
const fontObj = {};
|
|
16034
|
-
if (ascii) fontObj.ascii = ascii;
|
|
16035
|
-
if (eastAsia) fontObj.eastAsia = eastAsia;
|
|
16036
|
-
if (hAnsi) fontObj.hAnsi = hAnsi;
|
|
16037
|
-
if (cs) fontObj.cs = cs;
|
|
16038
|
-
if (hint) fontObj.hint = hint;
|
|
16039
|
-
opts.font = fontObj;
|
|
16040
|
-
}
|
|
16041
|
-
}
|
|
16042
|
-
const bold = findChild(el, "w:b");
|
|
16043
|
-
if (bold) opts.bold = attrBool(bold, "w:val") ?? true;
|
|
16044
|
-
const boldCs = findChild(el, "w:bCs");
|
|
16045
|
-
if (boldCs) opts.boldComplexScript = attrBool(boldCs, "w:val") ?? true;
|
|
16046
|
-
const italics = findChild(el, "w:i");
|
|
16047
|
-
if (italics) opts.italics = attrBool(italics, "w:val") ?? true;
|
|
16048
|
-
const italicsCs = findChild(el, "w:iCs");
|
|
16049
|
-
if (italicsCs) opts.italicsComplexScript = attrBool(italicsCs, "w:val") ?? true;
|
|
16050
|
-
const underline = findChild(el, "w:u");
|
|
16051
|
-
if (underline) {
|
|
16052
|
-
const ul = {};
|
|
16053
|
-
const uType = attr(underline, "w:val");
|
|
16054
|
-
if (uType) ul.type = uType;
|
|
16055
|
-
const uColor = colorAttr(underline, "w:color");
|
|
16056
|
-
if (uColor) ul.color = uColor;
|
|
16057
|
-
opts.underline = ul;
|
|
16058
|
-
}
|
|
16059
|
-
for (const [name, optKey] of [
|
|
16060
|
-
["w:strike", "strike"],
|
|
16061
|
-
["w:dstrike", "doubleStrike"],
|
|
16062
|
-
["w:outline", "outline"],
|
|
16063
|
-
["w:shadow", "shadow"],
|
|
16064
|
-
["w:emboss", "emboss"],
|
|
16065
|
-
["w:imprint", "imprint"],
|
|
16066
|
-
["w:vanish", "vanish"],
|
|
16067
|
-
["w:webHidden", "webHidden"],
|
|
16068
|
-
["w:noProof", "noProof"],
|
|
16069
|
-
["w:snapToGrid", "snapToGrid"],
|
|
16070
|
-
["w:smallCaps", "smallCaps"],
|
|
16071
|
-
["w:caps", "allCaps"],
|
|
16072
|
-
["w:rtl", "rightToLeft"],
|
|
16073
|
-
["w:cs", "complexScript"],
|
|
16074
|
-
["w:specVanish", "specVanish"],
|
|
16075
|
-
["w:math", "math"]
|
|
16076
|
-
]) {
|
|
16077
|
-
const child = findChild(el, name);
|
|
16078
|
-
if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
|
|
16079
|
-
}
|
|
16080
|
-
const color = findChild(el, "w:color");
|
|
16081
|
-
if (color) {
|
|
16082
|
-
const c = colorAttr(color, "w:val");
|
|
16083
|
-
if (c) opts.color = c;
|
|
16084
|
-
}
|
|
16085
|
-
const sz = findChild(el, "w:sz");
|
|
16086
|
-
if (sz) {
|
|
16087
|
-
const halfPts = attrNum(sz, "w:val");
|
|
16088
|
-
if (halfPts !== void 0) opts.size = halfPts;
|
|
16089
|
-
}
|
|
16090
|
-
const szCs = findChild(el, "w:szCs");
|
|
16091
|
-
if (szCs) {
|
|
16092
|
-
const halfPts = attrNum(szCs, "w:val");
|
|
16093
|
-
if (halfPts !== void 0) opts.sizeComplexScript = halfPts;
|
|
16094
|
-
}
|
|
16095
|
-
const highlight = findChild(el, "w:highlight");
|
|
16096
|
-
if (highlight) {
|
|
16097
|
-
const val = attr(highlight, "w:val");
|
|
16098
|
-
if (val) opts.highlight = val;
|
|
16099
|
-
}
|
|
16100
|
-
const highlightCs = findChild(el, "w:highlightCs");
|
|
16101
|
-
if (highlightCs) {
|
|
16102
|
-
const val = attr(highlightCs, "w:val");
|
|
16103
|
-
if (val) opts.highlightComplexScript = val;
|
|
16104
|
-
}
|
|
16105
|
-
const vertAlign = findChild(el, "w:vertAlign");
|
|
16106
|
-
if (vertAlign) {
|
|
16107
|
-
const val = attr(vertAlign, "w:val");
|
|
16108
|
-
if (val === "subscript") opts.subScript = true;
|
|
16109
|
-
else if (val === "superscript") opts.superScript = true;
|
|
16110
|
-
}
|
|
16111
|
-
const effect = findChild(el, "w:effect");
|
|
16112
|
-
if (effect) {
|
|
16113
|
-
const val = attr(effect, "w:val");
|
|
16114
|
-
if (val) opts.effect = val;
|
|
16115
|
-
}
|
|
16116
|
-
const emphasisMark = findChild(el, "w:em");
|
|
16117
|
-
if (emphasisMark) {
|
|
16118
|
-
const val = attr(emphasisMark, "w:val");
|
|
16119
|
-
if (val) opts.emphasisMark = { type: val };
|
|
16120
|
-
}
|
|
16121
|
-
const spacing = findChild(el, "w:spacing");
|
|
16122
|
-
if (spacing) {
|
|
16123
|
-
const val = attrNum(spacing, "w:val");
|
|
16124
|
-
if (val !== void 0) opts.characterSpacing = val;
|
|
16125
|
-
}
|
|
16126
|
-
const scale = findChild(el, "w:w");
|
|
16127
|
-
if (scale) {
|
|
16128
|
-
const val = attrNum(scale, "w:val");
|
|
16129
|
-
if (val !== void 0) opts.scale = val;
|
|
16130
|
-
}
|
|
16131
|
-
const kern = findChild(el, "w:kern");
|
|
16132
|
-
if (kern) {
|
|
16133
|
-
const val = attrNum(kern, "w:val");
|
|
16134
|
-
if (val !== void 0) opts.kern = val;
|
|
16135
|
-
}
|
|
16136
|
-
const position = findChild(el, "w:position");
|
|
16137
|
-
if (position) {
|
|
16138
|
-
const val = attr(position, "w:val");
|
|
16139
|
-
if (val !== void 0) opts.position = val;
|
|
16140
|
-
}
|
|
16141
|
-
const fitText = findChild(el, "w:fitText");
|
|
16142
|
-
if (fitText) {
|
|
16143
|
-
const val = attrNum(fitText, "w:val");
|
|
16144
|
-
if (val !== void 0) opts.fitText = val;
|
|
16145
|
-
}
|
|
16146
|
-
const lang = findChild(el, "w:lang");
|
|
16147
|
-
if (lang) {
|
|
16148
|
-
const langObj = {};
|
|
16149
|
-
const val = attr(lang, "w:val");
|
|
16150
|
-
if (val) langObj.val = val;
|
|
16151
|
-
const eastAsia = attr(lang, "w:eastAsia");
|
|
16152
|
-
if (eastAsia) langObj.eastAsia = eastAsia;
|
|
16153
|
-
const bidi = attr(lang, "w:bidi");
|
|
16154
|
-
if (bidi) langObj.bidi = bidi;
|
|
16155
|
-
if (Object.keys(langObj).length > 0) opts.language = langObj;
|
|
16156
|
-
}
|
|
16157
|
-
const bdr = findChild(el, "w:bdr");
|
|
16158
|
-
if (bdr) opts.border = parseBorder(bdr);
|
|
16159
|
-
const shd = findChild(el, "w:shd");
|
|
16160
|
-
if (shd) opts.shading = parseShading(shd);
|
|
16161
|
-
return opts;
|
|
16162
|
-
}
|
|
16163
|
-
/**
|
|
16164
|
-
* Parse a w:bdr element into BorderOptions.
|
|
15342
|
+
* Parse a w:drawing element and dispatch to the correct parser
|
|
15343
|
+
* based on the graphicData URI.
|
|
16165
15344
|
*/
|
|
16166
|
-
function
|
|
16167
|
-
const
|
|
16168
|
-
|
|
16169
|
-
|
|
16170
|
-
|
|
16171
|
-
if (
|
|
16172
|
-
|
|
16173
|
-
if (size !== void 0) opts.size = size;
|
|
16174
|
-
const space = attrNum(el, "w:space");
|
|
16175
|
-
if (space !== void 0) opts.space = space;
|
|
16176
|
-
const shadow = attrBool(el, "w:shadow");
|
|
16177
|
-
if (shadow !== void 0) opts.shadow = shadow;
|
|
16178
|
-
const frame = attrBool(el, "w:frame");
|
|
16179
|
-
if (frame !== void 0) opts.frame = frame;
|
|
16180
|
-
return opts;
|
|
15345
|
+
function parseDrawingRun(el, ctx) {
|
|
15346
|
+
const graphicData = findDeep(el, "a:graphicData")[0];
|
|
15347
|
+
if (!graphicData) return void 0;
|
|
15348
|
+
const uri = attr(graphicData, "uri") ?? "";
|
|
15349
|
+
if (uri.includes("/chart")) return parseChartDrawing(el, ctx);
|
|
15350
|
+
if (uri.includes("/diagram")) return parseSmartArtDrawing(el, ctx);
|
|
15351
|
+
return parseImageRun(el, ctx);
|
|
16181
15352
|
}
|
|
16182
15353
|
/**
|
|
16183
|
-
*
|
|
15354
|
+
* Determine image type from file extension or MIME type.
|
|
16184
15355
|
*/
|
|
16185
|
-
function
|
|
16186
|
-
|
|
16187
|
-
|
|
16188
|
-
|
|
16189
|
-
|
|
16190
|
-
|
|
16191
|
-
|
|
16192
|
-
|
|
16193
|
-
|
|
15356
|
+
function imageTypeFromPath(path) {
|
|
15357
|
+
switch (path.split(".").pop()?.toLowerCase() ?? "") {
|
|
15358
|
+
case "jpg":
|
|
15359
|
+
case "jpeg": return "jpg";
|
|
15360
|
+
case "png": return "png";
|
|
15361
|
+
case "gif": return "gif";
|
|
15362
|
+
case "bmp": return "bmp";
|
|
15363
|
+
case "tif":
|
|
15364
|
+
case "tiff": return "tif";
|
|
15365
|
+
case "ico": return "ico";
|
|
15366
|
+
case "emf": return "emf";
|
|
15367
|
+
case "wmf": return "wmf";
|
|
15368
|
+
default: return "png";
|
|
15369
|
+
}
|
|
16194
15370
|
}
|
|
16195
|
-
/** Matches w:br[@w:type="page"] → PageBreak */
|
|
16196
|
-
const PARSED_PAGE_BREAK = Symbol("PageBreak");
|
|
16197
|
-
/** Matches w:br (line break) */
|
|
16198
|
-
const PARSED_LINE_BREAK = Symbol("LineBreak");
|
|
16199
|
-
/** Matches w:tab */
|
|
16200
|
-
const PARSED_TAB = Symbol("Tab");
|
|
16201
|
-
/** Matches w:cr */
|
|
16202
|
-
const PARSED_CR = Symbol("CarriageReturn");
|
|
16203
|
-
/** Matches w:noBreakHyphen */
|
|
16204
|
-
const PARSED_NO_BREAK_HYPHEN = Symbol("NoBreakHyphen");
|
|
16205
|
-
/** Matches w:softHyphen */
|
|
16206
|
-
const PARSED_SOFT_HYPHEN = Symbol("SoftHyphen");
|
|
16207
15371
|
/**
|
|
16208
|
-
* Parse a w:
|
|
16209
|
-
* Returns { properties, children } where children are parsed run content items.
|
|
15372
|
+
* Parse a w:drawing element and return image data wrapped in { image: ... }.
|
|
16210
15373
|
*/
|
|
16211
|
-
function
|
|
16212
|
-
const
|
|
16213
|
-
const
|
|
16214
|
-
const
|
|
16215
|
-
|
|
16216
|
-
|
|
16217
|
-
|
|
16218
|
-
|
|
16219
|
-
|
|
16220
|
-
|
|
16221
|
-
|
|
16222
|
-
|
|
16223
|
-
|
|
16224
|
-
|
|
16225
|
-
|
|
16226
|
-
|
|
16227
|
-
|
|
16228
|
-
|
|
16229
|
-
|
|
16230
|
-
|
|
16231
|
-
|
|
16232
|
-
|
|
16233
|
-
|
|
16234
|
-
|
|
16235
|
-
|
|
16236
|
-
|
|
16237
|
-
|
|
16238
|
-
|
|
16239
|
-
|
|
16240
|
-
|
|
16241
|
-
|
|
16242
|
-
|
|
16243
|
-
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
|
|
16251
|
-
|
|
16252
|
-
|
|
16253
|
-
|
|
15374
|
+
function parseImageRun(el, ctx) {
|
|
15375
|
+
const inline = findDeep(el, "wp:inline")[0];
|
|
15376
|
+
const anchor = inline ? void 0 : findDeep(el, "wp:anchor")[0];
|
|
15377
|
+
const parent = inline ?? anchor;
|
|
15378
|
+
if (!parent) return void 0;
|
|
15379
|
+
const extent = findChild(parent, "wp:extent");
|
|
15380
|
+
let width;
|
|
15381
|
+
let height;
|
|
15382
|
+
if (extent) {
|
|
15383
|
+
const cxEmu = attrNum(extent, "cx");
|
|
15384
|
+
const cyEmu = attrNum(extent, "cy");
|
|
15385
|
+
if (cxEmu !== void 0) width = convertEmuToPixels(cxEmu);
|
|
15386
|
+
if (cyEmu !== void 0) height = convertEmuToPixels(cyEmu);
|
|
15387
|
+
}
|
|
15388
|
+
const blip = findDeep(parent, "a:blip")[0];
|
|
15389
|
+
if (!blip) return void 0;
|
|
15390
|
+
const rEmbed = attr(blip, "r:embed");
|
|
15391
|
+
if (!rEmbed) return void 0;
|
|
15392
|
+
const mediaPath = ctx.docx.partRefs.media.get(rEmbed);
|
|
15393
|
+
if (!mediaPath) return void 0;
|
|
15394
|
+
const imageData = ctx.docx.doc.getRaw(mediaPath);
|
|
15395
|
+
if (!imageData) return void 0;
|
|
15396
|
+
const imageOpts = {
|
|
15397
|
+
type: imageTypeFromPath(mediaPath),
|
|
15398
|
+
data: imageData,
|
|
15399
|
+
transformation: {
|
|
15400
|
+
...width !== void 0 ? { width } : {},
|
|
15401
|
+
...height !== void 0 ? { height } : {}
|
|
15402
|
+
}
|
|
15403
|
+
};
|
|
15404
|
+
const docPr = findChild(parent, "wp:docPr");
|
|
15405
|
+
if (docPr) {
|
|
15406
|
+
const name = attr(docPr, "name");
|
|
15407
|
+
const descr = attr(docPr, "descr");
|
|
15408
|
+
const title = attr(docPr, "title");
|
|
15409
|
+
if (name || descr || title) imageOpts.altText = {
|
|
15410
|
+
...name ? { name } : {},
|
|
15411
|
+
...descr ? { description: descr } : {},
|
|
15412
|
+
...title ? { title } : {}
|
|
15413
|
+
};
|
|
15414
|
+
}
|
|
15415
|
+
if (anchor && !inline) {
|
|
15416
|
+
const floating = {};
|
|
15417
|
+
const posH = findChild(anchor, "wp:positionH");
|
|
15418
|
+
if (posH) {
|
|
15419
|
+
const align = findChild(posH, "wp:align");
|
|
15420
|
+
const posOffset = findChild(posH, "wp:posOffset");
|
|
15421
|
+
if (align) floating.horizontalPosition = { align: textOf(align) };
|
|
15422
|
+
else if (posOffset) {
|
|
15423
|
+
const val = Number(textOf(posOffset));
|
|
15424
|
+
if (!isNaN(val)) floating.horizontalPosition = { offset: val };
|
|
15425
|
+
}
|
|
15426
|
+
}
|
|
15427
|
+
const posV = findChild(anchor, "wp:positionV");
|
|
15428
|
+
if (posV) {
|
|
15429
|
+
const align = findChild(posV, "wp:align");
|
|
15430
|
+
const posOffset = findChild(posV, "wp:posOffset");
|
|
15431
|
+
if (align) floating.verticalPosition = { align: textOf(align) };
|
|
15432
|
+
else if (posOffset) {
|
|
15433
|
+
const val = Number(textOf(posOffset));
|
|
15434
|
+
if (!isNaN(val)) floating.verticalPosition = { offset: val };
|
|
15435
|
+
}
|
|
15436
|
+
}
|
|
15437
|
+
for (const wrapType of [
|
|
15438
|
+
"wrapSquare",
|
|
15439
|
+
"wrapTight",
|
|
15440
|
+
"wrapTopAndBottom",
|
|
15441
|
+
"wrapNone"
|
|
15442
|
+
]) if (findChild(anchor, `wp:${wrapType}`)) {
|
|
15443
|
+
floating.wrap = wrapType;
|
|
16254
15444
|
break;
|
|
15445
|
+
}
|
|
15446
|
+
if (attrBool(anchor, "behindDoc")) floating.behindDocument = true;
|
|
15447
|
+
if (Object.keys(floating).length > 0) imageOpts.floating = floating;
|
|
16255
15448
|
}
|
|
15449
|
+
return { image: imageOpts };
|
|
15450
|
+
}
|
|
15451
|
+
function getDrawingExtent(el) {
|
|
15452
|
+
const inline = findDeep(el, "wp:inline")[0];
|
|
15453
|
+
const anchor = inline ? void 0 : findDeep(el, "wp:anchor")[0];
|
|
15454
|
+
const parent = inline ?? anchor;
|
|
15455
|
+
if (!parent) return {};
|
|
15456
|
+
const extent = findChild(parent, "wp:extent");
|
|
15457
|
+
if (!extent) return {};
|
|
15458
|
+
const cxEmu = attrNum(extent, "cx");
|
|
15459
|
+
const cyEmu = attrNum(extent, "cy");
|
|
16256
15460
|
return {
|
|
16257
|
-
|
|
16258
|
-
|
|
15461
|
+
...cxEmu !== void 0 ? { width: convertEmuToPixels(cxEmu) } : {},
|
|
15462
|
+
...cyEmu !== void 0 ? { height: convertEmuToPixels(cyEmu) } : {}
|
|
16259
15463
|
};
|
|
16260
15464
|
}
|
|
16261
15465
|
/**
|
|
16262
|
-
*
|
|
16263
|
-
*
|
|
16264
|
-
* If the run contains only a commentReference, returns { commentReference: id } instead.
|
|
15466
|
+
* Look up a relationship ID in a map, with fallback for double "rId" prefix
|
|
15467
|
+
* that the library's generation code produces (e.g. "rIdrId7" → "rId7").
|
|
16265
15468
|
*/
|
|
16266
|
-
function
|
|
16267
|
-
|
|
16268
|
-
const
|
|
16269
|
-
|
|
16270
|
-
if (
|
|
16271
|
-
|
|
16272
|
-
|
|
16273
|
-
|
|
16274
|
-
|
|
16275
|
-
|
|
16276
|
-
|
|
16277
|
-
return
|
|
15469
|
+
function lookupRId(map, rId) {
|
|
15470
|
+
if (!rId) return void 0;
|
|
15471
|
+
const direct = map.get(rId);
|
|
15472
|
+
if (direct) return direct;
|
|
15473
|
+
if (rId.startsWith("rIdrId")) return map.get(rId.slice(3));
|
|
15474
|
+
}
|
|
15475
|
+
function parseChartDrawing(el, ctx) {
|
|
15476
|
+
const chartRef = findDeep(el, "c:chart")[0];
|
|
15477
|
+
if (!chartRef) return void 0;
|
|
15478
|
+
const rId = attr(chartRef, "r:id");
|
|
15479
|
+
const chartPath = lookupRId(ctx.docx.partRefs.charts, rId);
|
|
15480
|
+
if (!chartPath) return void 0;
|
|
15481
|
+
const chartXml = ctx.docx.doc.get(chartPath);
|
|
15482
|
+
if (!chartXml) return void 0;
|
|
15483
|
+
const opts = parseChartXml(chartXml);
|
|
15484
|
+
if (!opts) return void 0;
|
|
15485
|
+
const ext = getDrawingExtent(el);
|
|
15486
|
+
if (ext.width !== void 0 || ext.height !== void 0) opts.transformation = { ...ext };
|
|
15487
|
+
return { chart: opts };
|
|
16278
15488
|
}
|
|
16279
|
-
//#endregion
|
|
16280
|
-
//#region src/file/paragraph/paragraph-parse.ts
|
|
16281
|
-
/**
|
|
16282
|
-
* Paragraph parser for DOCX documents.
|
|
16283
|
-
*
|
|
16284
|
-
* Parses w:p and w:pPr Element trees into ParagraphOptions objects.
|
|
16285
|
-
*
|
|
16286
|
-
* @module
|
|
16287
|
-
*/
|
|
16288
|
-
init_style();
|
|
16289
|
-
init_math_parse();
|
|
16290
|
-
const HEADING_MAP = {
|
|
16291
|
-
Heading1: HeadingLevel.HEADING_1,
|
|
16292
|
-
Heading2: HeadingLevel.HEADING_2,
|
|
16293
|
-
Heading3: HeadingLevel.HEADING_3,
|
|
16294
|
-
Heading4: HeadingLevel.HEADING_4,
|
|
16295
|
-
Heading5: HeadingLevel.HEADING_5,
|
|
16296
|
-
Heading6: HeadingLevel.HEADING_6,
|
|
16297
|
-
Title: HeadingLevel.TITLE
|
|
16298
|
-
};
|
|
16299
15489
|
/**
|
|
16300
|
-
* Parse
|
|
15490
|
+
* Parse c:chartSpace element into ChartOptions.
|
|
16301
15491
|
*/
|
|
16302
|
-
function
|
|
15492
|
+
function parseChartXml(el) {
|
|
15493
|
+
const chart = findChild(el, "c:chart");
|
|
15494
|
+
if (!chart) return void 0;
|
|
16303
15495
|
const opts = {};
|
|
16304
|
-
const
|
|
16305
|
-
if (
|
|
16306
|
-
const
|
|
16307
|
-
if (
|
|
16308
|
-
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
|
|
16313
|
-
|
|
15496
|
+
const titleEl = findChild(chart, "c:title");
|
|
15497
|
+
if (titleEl) {
|
|
15498
|
+
const rich = findDeep(titleEl, "c:rich")[0];
|
|
15499
|
+
if (rich) {
|
|
15500
|
+
const t = findDeep(rich, "a:t")[0];
|
|
15501
|
+
if (t) {
|
|
15502
|
+
const title = textOf(t);
|
|
15503
|
+
if (title) opts.title = title;
|
|
15504
|
+
}
|
|
15505
|
+
}
|
|
16314
15506
|
}
|
|
16315
|
-
const
|
|
16316
|
-
if (
|
|
16317
|
-
|
|
16318
|
-
|
|
16319
|
-
|
|
16320
|
-
|
|
16321
|
-
|
|
16322
|
-
|
|
16323
|
-
|
|
16324
|
-
|
|
16325
|
-
|
|
16326
|
-
|
|
16327
|
-
|
|
16328
|
-
|
|
16329
|
-
|
|
16330
|
-
|
|
15507
|
+
const plotArea = findChild(chart, "c:plotArea");
|
|
15508
|
+
if (!plotArea) return void 0;
|
|
15509
|
+
let chartType;
|
|
15510
|
+
let typeElement;
|
|
15511
|
+
for (const child of plotArea.elements ?? []) {
|
|
15512
|
+
switch (child.name) {
|
|
15513
|
+
case "c:barChart": {
|
|
15514
|
+
const barDir = findChild(child, "c:barDir");
|
|
15515
|
+
chartType = barDir && attr(barDir, "val") === "bar" ? "bar" : "column";
|
|
15516
|
+
typeElement = child;
|
|
15517
|
+
break;
|
|
15518
|
+
}
|
|
15519
|
+
case "c:lineChart":
|
|
15520
|
+
chartType = "line";
|
|
15521
|
+
typeElement = child;
|
|
15522
|
+
break;
|
|
15523
|
+
case "c:pieChart":
|
|
15524
|
+
chartType = "pie";
|
|
15525
|
+
typeElement = child;
|
|
15526
|
+
break;
|
|
15527
|
+
case "c:areaChart":
|
|
15528
|
+
chartType = "area";
|
|
15529
|
+
typeElement = child;
|
|
15530
|
+
break;
|
|
15531
|
+
case "c:scatterChart":
|
|
15532
|
+
chartType = "scatter";
|
|
15533
|
+
typeElement = child;
|
|
15534
|
+
break;
|
|
15535
|
+
}
|
|
15536
|
+
if (chartType) break;
|
|
16331
15537
|
}
|
|
16332
|
-
|
|
16333
|
-
|
|
16334
|
-
|
|
16335
|
-
|
|
16336
|
-
|
|
16337
|
-
|
|
16338
|
-
|
|
16339
|
-
const
|
|
16340
|
-
if (
|
|
16341
|
-
const
|
|
16342
|
-
|
|
16343
|
-
|
|
16344
|
-
|
|
16345
|
-
|
|
16346
|
-
if (firstLine !== void 0) indentObj.firstLine = firstLine;
|
|
16347
|
-
if (Object.keys(indentObj).length > 0) opts.indent = indentObj;
|
|
15538
|
+
if (!chartType || !typeElement) return void 0;
|
|
15539
|
+
opts.type = chartType;
|
|
15540
|
+
const series = [];
|
|
15541
|
+
let categories;
|
|
15542
|
+
for (const serEl of typeElement.elements ?? []) {
|
|
15543
|
+
if (serEl.name !== "c:ser") continue;
|
|
15544
|
+
const nameParts = extractStrCache(serEl, "c:tx");
|
|
15545
|
+
const cats = extractStrCache(serEl, "c:cat");
|
|
15546
|
+
if (cats.length > 0 && !categories) categories = cats;
|
|
15547
|
+
const vals = extractNumCache(serEl);
|
|
15548
|
+
series.push({
|
|
15549
|
+
name: nameParts[0] ?? "",
|
|
15550
|
+
values: vals
|
|
15551
|
+
});
|
|
16348
15552
|
}
|
|
16349
|
-
|
|
16350
|
-
|
|
16351
|
-
|
|
16352
|
-
|
|
15553
|
+
opts.data = {
|
|
15554
|
+
categories: categories ?? [],
|
|
15555
|
+
series
|
|
15556
|
+
};
|
|
15557
|
+
opts.showLegend = findChild(chart, "c:legend") !== void 0;
|
|
15558
|
+
const styleEl = findChild(el, "c:style");
|
|
15559
|
+
if (styleEl) {
|
|
15560
|
+
const val = attrNum(styleEl, "val");
|
|
15561
|
+
if (val !== void 0) opts.style = val;
|
|
16353
15562
|
}
|
|
16354
|
-
|
|
16355
|
-
|
|
16356
|
-
|
|
16357
|
-
|
|
16358
|
-
|
|
16359
|
-
|
|
16360
|
-
|
|
16361
|
-
|
|
16362
|
-
|
|
16363
|
-
|
|
16364
|
-
|
|
16365
|
-
|
|
16366
|
-
|
|
16367
|
-
|
|
15563
|
+
return opts;
|
|
15564
|
+
}
|
|
15565
|
+
/**
|
|
15566
|
+
* Extract string values from c:strCache within a container element.
|
|
15567
|
+
*/
|
|
15568
|
+
function extractStrCache(parent, containerName) {
|
|
15569
|
+
const container = findChild(parent, containerName);
|
|
15570
|
+
if (!container) return [];
|
|
15571
|
+
const cache = findDeep(container, "c:strCache")[0];
|
|
15572
|
+
if (!cache) return [];
|
|
15573
|
+
const values = [];
|
|
15574
|
+
for (const pt of cache.elements ?? []) {
|
|
15575
|
+
if (pt.name !== "c:pt") continue;
|
|
15576
|
+
const v = findChild(pt, "c:v");
|
|
15577
|
+
if (v) values.push(textOf(v) ?? "");
|
|
16368
15578
|
}
|
|
16369
|
-
|
|
16370
|
-
|
|
16371
|
-
|
|
16372
|
-
|
|
16373
|
-
|
|
16374
|
-
|
|
16375
|
-
|
|
16376
|
-
|
|
16377
|
-
|
|
16378
|
-
|
|
16379
|
-
|
|
16380
|
-
|
|
16381
|
-
|
|
16382
|
-
|
|
16383
|
-
|
|
16384
|
-
|
|
16385
|
-
|
|
16386
|
-
|
|
16387
|
-
]) {
|
|
16388
|
-
const child = findChild(el, name);
|
|
16389
|
-
if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
|
|
15579
|
+
return values;
|
|
15580
|
+
}
|
|
15581
|
+
/**
|
|
15582
|
+
* Extract numeric values from c:numCache within a c:val container.
|
|
15583
|
+
*/
|
|
15584
|
+
function extractNumCache(parent) {
|
|
15585
|
+
const valEl = findChild(parent, "c:val");
|
|
15586
|
+
if (!valEl) return [];
|
|
15587
|
+
const cache = findDeep(valEl, "c:numCache")[0];
|
|
15588
|
+
if (!cache) return [];
|
|
15589
|
+
const values = [];
|
|
15590
|
+
for (const pt of cache.elements ?? []) {
|
|
15591
|
+
if (pt.name !== "c:pt") continue;
|
|
15592
|
+
const v = findChild(pt, "c:v");
|
|
15593
|
+
if (v) {
|
|
15594
|
+
const num = Number(textOf(v));
|
|
15595
|
+
if (!isNaN(num)) values.push(num);
|
|
15596
|
+
}
|
|
16390
15597
|
}
|
|
16391
|
-
|
|
16392
|
-
|
|
16393
|
-
|
|
16394
|
-
|
|
16395
|
-
|
|
16396
|
-
|
|
16397
|
-
|
|
16398
|
-
|
|
16399
|
-
|
|
16400
|
-
|
|
16401
|
-
|
|
16402
|
-
|
|
16403
|
-
|
|
16404
|
-
|
|
16405
|
-
|
|
16406
|
-
|
|
16407
|
-
|
|
16408
|
-
|
|
16409
|
-
|
|
16410
|
-
|
|
16411
|
-
|
|
15598
|
+
return values;
|
|
15599
|
+
}
|
|
15600
|
+
function parseSmartArtDrawing(el, ctx) {
|
|
15601
|
+
const relIds = findDeep(el, "dgm:relIds")[0];
|
|
15602
|
+
if (!relIds) return void 0;
|
|
15603
|
+
const rId = attr(relIds, "r:dm");
|
|
15604
|
+
const dataPath = lookupRId(ctx.docx.partRefs.diagramData, rId);
|
|
15605
|
+
if (!dataPath) return void 0;
|
|
15606
|
+
const dataEl = ctx.docx.doc.get(dataPath);
|
|
15607
|
+
if (!dataEl) return void 0;
|
|
15608
|
+
const opts = parseSmartArtDataXml(dataEl);
|
|
15609
|
+
if (!opts) return void 0;
|
|
15610
|
+
const ext = getDrawingExtent(el);
|
|
15611
|
+
if (ext.width !== void 0 || ext.height !== void 0) opts.transformation = { ...ext };
|
|
15612
|
+
return { smartArt: opts };
|
|
15613
|
+
}
|
|
15614
|
+
/**
|
|
15615
|
+
* Parse dgm:dataModel element into SmartArtOptions.
|
|
15616
|
+
*/
|
|
15617
|
+
function parseSmartArtDataXml(el) {
|
|
15618
|
+
const ptLst = findChild(el, "dgm:ptLst");
|
|
15619
|
+
if (!ptLst) return void 0;
|
|
15620
|
+
const opts = {};
|
|
15621
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
15622
|
+
for (const pt of ptLst.elements ?? []) {
|
|
15623
|
+
if (pt.name !== "dgm:pt") continue;
|
|
15624
|
+
const type = attr(pt, "type");
|
|
15625
|
+
const modelId = attr(pt, "modelId");
|
|
15626
|
+
if (type === "doc") {
|
|
15627
|
+
const prSet = findChild(pt, "dgm:prSet");
|
|
15628
|
+
if (prSet) {
|
|
15629
|
+
const loTypeId = attr(prSet, "loTypeId") ?? "";
|
|
15630
|
+
const qsTypeId = attr(prSet, "qsTypeId") ?? "";
|
|
15631
|
+
const csTypeId = attr(prSet, "csTypeId") ?? "";
|
|
15632
|
+
const layout = loTypeId.split("/").pop();
|
|
15633
|
+
if (layout) opts.layout = layout;
|
|
15634
|
+
const style = qsTypeId.split("/").pop();
|
|
15635
|
+
if (style) opts.style = style;
|
|
15636
|
+
const color = csTypeId.split("/").pop();
|
|
15637
|
+
if (color) opts.color = color;
|
|
16412
15638
|
}
|
|
15639
|
+
} else if (type === "node" && modelId) {
|
|
15640
|
+
const t = findDeep(pt, "a:t")[0];
|
|
15641
|
+
nodeMap.set(modelId, t ? textOf(t) ?? "" : "");
|
|
16413
15642
|
}
|
|
16414
|
-
if (Object.keys(border).length > 0) opts.border = border;
|
|
16415
|
-
}
|
|
16416
|
-
const shd = findChild(el, "w:shd");
|
|
16417
|
-
if (shd) {
|
|
16418
|
-
const shdObj = {};
|
|
16419
|
-
const fill = attr(shd, "w:fill");
|
|
16420
|
-
if (fill) shdObj.fill = fill;
|
|
16421
|
-
const color = attr(shd, "w:color");
|
|
16422
|
-
if (color) shdObj.color = color;
|
|
16423
|
-
const val = attr(shd, "w:val");
|
|
16424
|
-
if (val) shdObj.type = val;
|
|
16425
|
-
if (Object.keys(shdObj).length > 0) opts.shading = shdObj;
|
|
16426
|
-
}
|
|
16427
|
-
const textAlignment = findChild(el, "w:textAlignment");
|
|
16428
|
-
if (textAlignment) {
|
|
16429
|
-
const val = attr(textAlignment, "w:val");
|
|
16430
|
-
if (val) opts.textAlignment = val;
|
|
16431
|
-
}
|
|
16432
|
-
const outlineLvl = findChild(el, "w:outlineLvl");
|
|
16433
|
-
if (outlineLvl) {
|
|
16434
|
-
const val = attrNum(outlineLvl, "w:val");
|
|
16435
|
-
if (val !== void 0) opts.outlineLevel = val;
|
|
16436
15643
|
}
|
|
16437
|
-
const
|
|
16438
|
-
if (
|
|
16439
|
-
|
|
16440
|
-
|
|
15644
|
+
const cxnLst = findChild(el, "dgm:cxnLst");
|
|
15645
|
+
if (!cxnLst) {
|
|
15646
|
+
opts.data = { nodes: [] };
|
|
15647
|
+
return opts;
|
|
16441
15648
|
}
|
|
16442
|
-
const
|
|
16443
|
-
|
|
16444
|
-
|
|
16445
|
-
|
|
16446
|
-
const
|
|
16447
|
-
|
|
16448
|
-
|
|
16449
|
-
|
|
16450
|
-
[
|
|
16451
|
-
|
|
16452
|
-
["w:hAnchor", "hAnchor"],
|
|
16453
|
-
["w:x", "x"],
|
|
16454
|
-
["w:y", "y"],
|
|
16455
|
-
["w:hRule", "hRule"],
|
|
16456
|
-
["w:hSpace", "hSpace"],
|
|
16457
|
-
["w:vSpace", "vSpace"]
|
|
16458
|
-
]) {
|
|
16459
|
-
const val = attr(framePr, attrName);
|
|
16460
|
-
if (val !== void 0) frame[optName] = val;
|
|
15649
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
|
15650
|
+
for (const cxn of cxnLst.elements ?? []) {
|
|
15651
|
+
if (cxn.name !== "dgm:cxn") continue;
|
|
15652
|
+
const srcId = attr(cxn, "srcId");
|
|
15653
|
+
const destId = attr(cxn, "destId");
|
|
15654
|
+
if (!srcId || !destId || !nodeMap.has(destId)) continue;
|
|
15655
|
+
let arr = childrenMap.get(srcId);
|
|
15656
|
+
if (!arr) {
|
|
15657
|
+
arr = [];
|
|
15658
|
+
childrenMap.set(srcId, arr);
|
|
16461
15659
|
}
|
|
16462
|
-
|
|
16463
|
-
if (w !== void 0) frame.width = w;
|
|
16464
|
-
const h = attrNum(framePr, "w:h");
|
|
16465
|
-
if (h !== void 0) frame.height = h;
|
|
16466
|
-
if (Object.keys(frame).length > 0) opts.frame = frame;
|
|
15660
|
+
arr.push(destId);
|
|
16467
15661
|
}
|
|
15662
|
+
opts.data = { nodes: (childrenMap.get("0") ?? []).map((id) => buildSmartArtNode(id, nodeMap, childrenMap)) };
|
|
16468
15663
|
return opts;
|
|
16469
15664
|
}
|
|
15665
|
+
function buildSmartArtNode(id, nodeMap, childrenMap) {
|
|
15666
|
+
const text = nodeMap.get(id) ?? "";
|
|
15667
|
+
const childIds = childrenMap.get(id) ?? [];
|
|
15668
|
+
if (childIds.length === 0) return { text };
|
|
15669
|
+
return {
|
|
15670
|
+
text,
|
|
15671
|
+
children: childIds.map((cid) => buildSmartArtNode(cid, nodeMap, childrenMap))
|
|
15672
|
+
};
|
|
15673
|
+
}
|
|
15674
|
+
//#endregion
|
|
15675
|
+
//#region src/file/paragraph/run/run-parse.ts
|
|
16470
15676
|
/**
|
|
16471
|
-
*
|
|
15677
|
+
* Run properties parser for DOCX documents.
|
|
15678
|
+
*
|
|
15679
|
+
* Parses w:rPr Element trees into RunPropertiesOptions objects.
|
|
15680
|
+
*
|
|
15681
|
+
* @module
|
|
16472
15682
|
*/
|
|
16473
|
-
|
|
15683
|
+
/**
|
|
15684
|
+
* Parse a w:rPr element into RunPropertiesOptions.
|
|
15685
|
+
*/
|
|
15686
|
+
function parseRunProperties(el) {
|
|
16474
15687
|
const opts = {};
|
|
16475
|
-
const
|
|
16476
|
-
if (
|
|
16477
|
-
const
|
|
16478
|
-
|
|
16479
|
-
|
|
16480
|
-
|
|
16481
|
-
|
|
16482
|
-
|
|
16483
|
-
|
|
16484
|
-
|
|
16485
|
-
|
|
16486
|
-
|
|
16487
|
-
|
|
16488
|
-
|
|
16489
|
-
|
|
15688
|
+
const rStyle = findChild(el, "w:rStyle");
|
|
15689
|
+
if (rStyle) opts.style = attr(rStyle, "w:val");
|
|
15690
|
+
const font = findChild(el, "w:rFonts");
|
|
15691
|
+
if (font) {
|
|
15692
|
+
const ascii = attr(font, "w:ascii");
|
|
15693
|
+
const eastAsia = attr(font, "w:eastAsia");
|
|
15694
|
+
const hAnsi = attr(font, "w:hAnsi");
|
|
15695
|
+
const cs = attr(font, "w:cs");
|
|
15696
|
+
const hint = attr(font, "w:hint");
|
|
15697
|
+
if (ascii && !eastAsia && !hAnsi && !cs) opts.font = hint ? {
|
|
15698
|
+
name: ascii,
|
|
15699
|
+
hint
|
|
15700
|
+
} : ascii;
|
|
15701
|
+
else {
|
|
15702
|
+
const fontObj = {};
|
|
15703
|
+
if (ascii) fontObj.ascii = ascii;
|
|
15704
|
+
if (eastAsia) fontObj.eastAsia = eastAsia;
|
|
15705
|
+
if (hAnsi) fontObj.hAnsi = hAnsi;
|
|
15706
|
+
if (cs) fontObj.cs = cs;
|
|
15707
|
+
if (hint) fontObj.hint = hint;
|
|
15708
|
+
opts.font = fontObj;
|
|
16490
15709
|
}
|
|
16491
|
-
|
|
16492
|
-
|
|
16493
|
-
|
|
16494
|
-
|
|
16495
|
-
|
|
16496
|
-
|
|
16497
|
-
|
|
16498
|
-
|
|
16499
|
-
|
|
16500
|
-
|
|
16501
|
-
|
|
16502
|
-
|
|
16503
|
-
|
|
16504
|
-
|
|
16505
|
-
|
|
16506
|
-
|
|
16507
|
-
|
|
16508
|
-
|
|
16509
|
-
|
|
16510
|
-
|
|
15710
|
+
}
|
|
15711
|
+
const bold = findChild(el, "w:b");
|
|
15712
|
+
if (bold) opts.bold = attrBool(bold, "w:val") ?? true;
|
|
15713
|
+
const boldCs = findChild(el, "w:bCs");
|
|
15714
|
+
if (boldCs) opts.boldComplexScript = attrBool(boldCs, "w:val") ?? true;
|
|
15715
|
+
const italics = findChild(el, "w:i");
|
|
15716
|
+
if (italics) opts.italics = attrBool(italics, "w:val") ?? true;
|
|
15717
|
+
const italicsCs = findChild(el, "w:iCs");
|
|
15718
|
+
if (italicsCs) opts.italicsComplexScript = attrBool(italicsCs, "w:val") ?? true;
|
|
15719
|
+
const underline = findChild(el, "w:u");
|
|
15720
|
+
if (underline) {
|
|
15721
|
+
const ul = {};
|
|
15722
|
+
const uType = attr(underline, "w:val");
|
|
15723
|
+
if (uType) ul.type = uType;
|
|
15724
|
+
const uColor = colorAttr(underline, "w:color");
|
|
15725
|
+
if (uColor) ul.color = uColor;
|
|
15726
|
+
opts.underline = ul;
|
|
15727
|
+
}
|
|
15728
|
+
for (const [name, optKey] of [
|
|
15729
|
+
["w:strike", "strike"],
|
|
15730
|
+
["w:dstrike", "doubleStrike"],
|
|
15731
|
+
["w:outline", "outline"],
|
|
15732
|
+
["w:shadow", "shadow"],
|
|
15733
|
+
["w:emboss", "emboss"],
|
|
15734
|
+
["w:imprint", "imprint"],
|
|
15735
|
+
["w:vanish", "vanish"],
|
|
15736
|
+
["w:webHidden", "webHidden"],
|
|
15737
|
+
["w:noProof", "noProof"],
|
|
15738
|
+
["w:snapToGrid", "snapToGrid"],
|
|
15739
|
+
["w:smallCaps", "smallCaps"],
|
|
15740
|
+
["w:caps", "allCaps"],
|
|
15741
|
+
["w:rtl", "rightToLeft"],
|
|
15742
|
+
["w:cs", "complexScript"],
|
|
15743
|
+
["w:specVanish", "specVanish"],
|
|
15744
|
+
["w:math", "math"]
|
|
15745
|
+
]) {
|
|
15746
|
+
const child = findChild(el, name);
|
|
15747
|
+
if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
|
|
15748
|
+
}
|
|
15749
|
+
const color = findChild(el, "w:color");
|
|
15750
|
+
if (color) {
|
|
15751
|
+
const c = colorAttr(color, "w:val");
|
|
15752
|
+
if (c) opts.color = c;
|
|
15753
|
+
}
|
|
15754
|
+
const sz = findChild(el, "w:sz");
|
|
15755
|
+
if (sz) {
|
|
15756
|
+
const halfPts = attrNum(sz, "w:val");
|
|
15757
|
+
if (halfPts !== void 0) opts.size = halfPts;
|
|
15758
|
+
}
|
|
15759
|
+
const szCs = findChild(el, "w:szCs");
|
|
15760
|
+
if (szCs) {
|
|
15761
|
+
const halfPts = attrNum(szCs, "w:val");
|
|
15762
|
+
if (halfPts !== void 0) opts.sizeComplexScript = halfPts;
|
|
15763
|
+
}
|
|
15764
|
+
const highlight = findChild(el, "w:highlight");
|
|
15765
|
+
if (highlight) {
|
|
15766
|
+
const val = attr(highlight, "w:val");
|
|
15767
|
+
if (val) opts.highlight = val;
|
|
15768
|
+
}
|
|
15769
|
+
const highlightCs = findChild(el, "w:highlightCs");
|
|
15770
|
+
if (highlightCs) {
|
|
15771
|
+
const val = attr(highlightCs, "w:val");
|
|
15772
|
+
if (val) opts.highlightComplexScript = val;
|
|
15773
|
+
}
|
|
15774
|
+
const vertAlign = findChild(el, "w:vertAlign");
|
|
15775
|
+
if (vertAlign) {
|
|
15776
|
+
const val = attr(vertAlign, "w:val");
|
|
15777
|
+
if (val === "subscript") opts.subScript = true;
|
|
15778
|
+
else if (val === "superscript") opts.superScript = true;
|
|
15779
|
+
}
|
|
15780
|
+
const effect = findChild(el, "w:effect");
|
|
15781
|
+
if (effect) {
|
|
15782
|
+
const val = attr(effect, "w:val");
|
|
15783
|
+
if (val) opts.effect = val;
|
|
15784
|
+
}
|
|
15785
|
+
const emphasisMark = findChild(el, "w:em");
|
|
15786
|
+
if (emphasisMark) {
|
|
15787
|
+
const val = attr(emphasisMark, "w:val");
|
|
15788
|
+
if (val) opts.emphasisMark = { type: val };
|
|
15789
|
+
}
|
|
15790
|
+
const spacing = findChild(el, "w:spacing");
|
|
15791
|
+
if (spacing) {
|
|
15792
|
+
const val = attrNum(spacing, "w:val");
|
|
15793
|
+
if (val !== void 0) opts.characterSpacing = val;
|
|
15794
|
+
}
|
|
15795
|
+
const scale = findChild(el, "w:w");
|
|
15796
|
+
if (scale) {
|
|
15797
|
+
const val = attrNum(scale, "w:val");
|
|
15798
|
+
if (val !== void 0) opts.scale = val;
|
|
15799
|
+
}
|
|
15800
|
+
const kern = findChild(el, "w:kern");
|
|
15801
|
+
if (kern) {
|
|
15802
|
+
const val = attrNum(kern, "w:val");
|
|
15803
|
+
if (val !== void 0) opts.kern = val;
|
|
15804
|
+
}
|
|
15805
|
+
const position = findChild(el, "w:position");
|
|
15806
|
+
if (position) {
|
|
15807
|
+
const val = attr(position, "w:val");
|
|
15808
|
+
if (val !== void 0) opts.position = val;
|
|
15809
|
+
}
|
|
15810
|
+
const fitText = findChild(el, "w:fitText");
|
|
15811
|
+
if (fitText) {
|
|
15812
|
+
const val = attrNum(fitText, "w:val");
|
|
15813
|
+
if (val !== void 0) opts.fitText = val;
|
|
15814
|
+
}
|
|
15815
|
+
const lang = findChild(el, "w:lang");
|
|
15816
|
+
if (lang) {
|
|
15817
|
+
const langObj = {};
|
|
15818
|
+
const val = attr(lang, "w:val");
|
|
15819
|
+
if (val) langObj.val = val;
|
|
15820
|
+
const eastAsia = attr(lang, "w:eastAsia");
|
|
15821
|
+
if (eastAsia) langObj.eastAsia = eastAsia;
|
|
15822
|
+
const bidi = attr(lang, "w:bidi");
|
|
15823
|
+
if (bidi) langObj.bidi = bidi;
|
|
15824
|
+
if (Object.keys(langObj).length > 0) opts.language = langObj;
|
|
15825
|
+
}
|
|
15826
|
+
const bdr = findChild(el, "w:bdr");
|
|
15827
|
+
if (bdr) opts.border = parseBorder(bdr);
|
|
15828
|
+
const shd = findChild(el, "w:shd");
|
|
15829
|
+
if (shd) opts.shading = parseShading(shd);
|
|
15830
|
+
return opts;
|
|
15831
|
+
}
|
|
15832
|
+
/**
|
|
15833
|
+
* Parse a w:bdr element into BorderOptions.
|
|
15834
|
+
*/
|
|
15835
|
+
function parseBorder(el) {
|
|
15836
|
+
const opts = {};
|
|
15837
|
+
const style = attr(el, "w:val");
|
|
15838
|
+
if (style) opts.style = style;
|
|
15839
|
+
const color = colorAttr(el, "w:color");
|
|
15840
|
+
if (color) opts.color = color;
|
|
15841
|
+
const size = attrNum(el, "w:sz");
|
|
15842
|
+
if (size !== void 0) opts.size = size;
|
|
15843
|
+
const space = attrNum(el, "w:space");
|
|
15844
|
+
if (space !== void 0) opts.space = space;
|
|
15845
|
+
const shadow = attrBool(el, "w:shadow");
|
|
15846
|
+
if (shadow !== void 0) opts.shadow = shadow;
|
|
15847
|
+
const frame = attrBool(el, "w:frame");
|
|
15848
|
+
if (frame !== void 0) opts.frame = frame;
|
|
15849
|
+
return opts;
|
|
15850
|
+
}
|
|
15851
|
+
/**
|
|
15852
|
+
* Parse a w:shd element into ShadingAttributesProperties.
|
|
15853
|
+
*/
|
|
15854
|
+
function parseShading(el) {
|
|
15855
|
+
const opts = {};
|
|
15856
|
+
const fill = colorAttr(el, "w:fill");
|
|
15857
|
+
if (fill) opts.fill = fill;
|
|
15858
|
+
const color = colorAttr(el, "w:color");
|
|
15859
|
+
if (color) opts.color = color;
|
|
15860
|
+
const type = attr(el, "w:val");
|
|
15861
|
+
if (type) opts.type = type;
|
|
15862
|
+
return opts;
|
|
15863
|
+
}
|
|
15864
|
+
/** Matches w:br[@w:type="page"] → PageBreak */
|
|
15865
|
+
const PARSED_PAGE_BREAK = Symbol("PageBreak");
|
|
15866
|
+
/** Matches w:br (line break) */
|
|
15867
|
+
const PARSED_LINE_BREAK = Symbol("LineBreak");
|
|
15868
|
+
/** Matches w:tab */
|
|
15869
|
+
const PARSED_TAB = Symbol("Tab");
|
|
15870
|
+
/** Matches w:cr */
|
|
15871
|
+
const PARSED_CR = Symbol("CarriageReturn");
|
|
15872
|
+
/** Matches w:noBreakHyphen */
|
|
15873
|
+
const PARSED_NO_BREAK_HYPHEN = Symbol("NoBreakHyphen");
|
|
15874
|
+
/** Matches w:softHyphen */
|
|
15875
|
+
const PARSED_SOFT_HYPHEN = Symbol("SoftHyphen");
|
|
15876
|
+
/** Matches w:footnoteRef — auto-generated by Footnote class */
|
|
15877
|
+
const PARSED_FOOTNOTE_REF = Symbol("FootnoteRef");
|
|
15878
|
+
/** Matches w:br[@w:type="column"] */
|
|
15879
|
+
const PARSED_COLUMN_BREAK = Symbol("ColumnBreak");
|
|
15880
|
+
/**
|
|
15881
|
+
* Parse a w:r element into run data.
|
|
15882
|
+
* Returns { properties, children } where children are parsed run content items.
|
|
15883
|
+
*/
|
|
15884
|
+
function parseRun(el, _ctx) {
|
|
15885
|
+
const rPr = findChild(el, "w:rPr");
|
|
15886
|
+
const properties = rPr ? parseRunProperties(rPr) : void 0;
|
|
15887
|
+
const children = [];
|
|
15888
|
+
for (const child of el.elements ?? []) switch (child.name) {
|
|
15889
|
+
case "w:rPr": break;
|
|
15890
|
+
case "w:t": {
|
|
15891
|
+
const preserveSpace = attrBool(child, "xml:space");
|
|
15892
|
+
let text = textOf(child);
|
|
15893
|
+
if (preserveSpace && text) {}
|
|
15894
|
+
children.push(text);
|
|
16511
15895
|
break;
|
|
16512
15896
|
}
|
|
16513
|
-
case "w:
|
|
16514
|
-
const
|
|
16515
|
-
|
|
16516
|
-
if (id !== void 0 && name) childList.push({ bookmarkStart: {
|
|
16517
|
-
id,
|
|
16518
|
-
name
|
|
16519
|
-
} });
|
|
15897
|
+
case "w:delText": {
|
|
15898
|
+
const text = textOf(child);
|
|
15899
|
+
if (text) children.push(text);
|
|
16520
15900
|
break;
|
|
16521
15901
|
}
|
|
16522
|
-
case "w:
|
|
16523
|
-
const
|
|
16524
|
-
if (
|
|
15902
|
+
case "w:br": {
|
|
15903
|
+
const brType = attr(child, "w:type");
|
|
15904
|
+
if (brType === "page") children.push(PARSED_PAGE_BREAK);
|
|
15905
|
+
else if (brType === "column") children.push(PARSED_COLUMN_BREAK);
|
|
15906
|
+
else children.push(PARSED_LINE_BREAK);
|
|
16525
15907
|
break;
|
|
16526
15908
|
}
|
|
16527
|
-
case "w:
|
|
15909
|
+
case "w:tab":
|
|
15910
|
+
children.push(PARSED_TAB);
|
|
15911
|
+
break;
|
|
15912
|
+
case "w:cr":
|
|
15913
|
+
children.push(PARSED_CR);
|
|
15914
|
+
break;
|
|
15915
|
+
case "w:noBreakHyphen":
|
|
15916
|
+
children.push(PARSED_NO_BREAK_HYPHEN);
|
|
15917
|
+
break;
|
|
15918
|
+
case "w:softHyphen":
|
|
15919
|
+
children.push(PARSED_SOFT_HYPHEN);
|
|
15920
|
+
break;
|
|
15921
|
+
case "w:commentReference": {
|
|
16528
15922
|
const id = attrNum(child, "w:id");
|
|
16529
|
-
if (id !== void 0)
|
|
15923
|
+
if (id !== void 0) children.push({ commentReference: id });
|
|
16530
15924
|
break;
|
|
16531
15925
|
}
|
|
16532
|
-
case "w:
|
|
16533
|
-
|
|
16534
|
-
|
|
15926
|
+
case "w:drawing":
|
|
15927
|
+
case "w:pict": break;
|
|
15928
|
+
case "w:sym": {
|
|
15929
|
+
const charVal = attr(child, "w:char");
|
|
15930
|
+
const fontVal = attr(child, "w:font");
|
|
15931
|
+
if (charVal) children.push({ symbolRun: {
|
|
15932
|
+
char: charVal,
|
|
15933
|
+
symbolfont: fontVal ?? "Wingdings"
|
|
15934
|
+
} });
|
|
16535
15935
|
break;
|
|
16536
15936
|
}
|
|
16537
|
-
case "w:
|
|
15937
|
+
case "w:footnoteReference": {
|
|
16538
15938
|
const id = attrNum(child, "w:id");
|
|
16539
|
-
if (id !== void 0)
|
|
15939
|
+
if (id !== void 0) children.push({ footnoteReference: id });
|
|
16540
15940
|
break;
|
|
16541
15941
|
}
|
|
16542
|
-
case "
|
|
16543
|
-
const
|
|
16544
|
-
|
|
15942
|
+
case "w:endnoteReference": {
|
|
15943
|
+
const id = attrNum(child, "w:id");
|
|
15944
|
+
if (id !== void 0) children.push({ endnoteReference: id });
|
|
16545
15945
|
break;
|
|
16546
15946
|
}
|
|
15947
|
+
case "w:footnoteRef":
|
|
15948
|
+
case "w:endnoteRef":
|
|
15949
|
+
children.push(PARSED_FOOTNOTE_REF);
|
|
15950
|
+
break;
|
|
16547
15951
|
default:
|
|
16548
|
-
if (child.name && child.elements && child.elements.length > 0)
|
|
15952
|
+
if (child.name && child.elements && child.elements.length > 0) children.push(new RawPassthrough(child));
|
|
16549
15953
|
break;
|
|
16550
15954
|
}
|
|
16551
|
-
|
|
16552
|
-
|
|
16553
|
-
|
|
16554
|
-
|
|
16555
|
-
if (combined) {
|
|
16556
|
-
opts.text = combined;
|
|
16557
|
-
return opts;
|
|
16558
|
-
}
|
|
16559
|
-
}
|
|
16560
|
-
opts.children = childList;
|
|
16561
|
-
}
|
|
16562
|
-
return opts;
|
|
15955
|
+
return {
|
|
15956
|
+
properties,
|
|
15957
|
+
children
|
|
15958
|
+
};
|
|
16563
15959
|
}
|
|
16564
|
-
//#endregion
|
|
16565
|
-
//#region src/file/alt-chunk/alt-chunk-parse.ts
|
|
16566
15960
|
/**
|
|
16567
|
-
*
|
|
16568
|
-
*
|
|
16569
|
-
*
|
|
16570
|
-
*
|
|
16571
|
-
* @module
|
|
16572
|
-
*/
|
|
16573
|
-
/**
|
|
16574
|
-
* Parse a w:altChunk element into AltChunkOptions.
|
|
16575
|
-
* Reads the referenced data from the ZIP package.
|
|
15961
|
+
* Convert parsed run data into an RunOptions suitable for the Document constructor.
|
|
15962
|
+
* Simplifies the parsed children into text + break format.
|
|
15963
|
+
* If the run contains only a commentReference, returns { commentReference: id } instead.
|
|
15964
|
+
* If the run only contains footnoteRef/endnoteRef (auto-generated), returns empty options.
|
|
16576
15965
|
*/
|
|
16577
|
-
function
|
|
16578
|
-
const
|
|
16579
|
-
if (
|
|
16580
|
-
const
|
|
16581
|
-
|
|
16582
|
-
const
|
|
16583
|
-
|
|
16584
|
-
|
|
16585
|
-
|
|
16586
|
-
|
|
16587
|
-
|
|
16588
|
-
|
|
16589
|
-
|
|
16590
|
-
|
|
16591
|
-
|
|
16592
|
-
|
|
16593
|
-
|
|
16594
|
-
|
|
16595
|
-
|
|
16596
|
-
|
|
16597
|
-
|
|
16598
|
-
|
|
16599
|
-
|
|
16600
|
-
|
|
16601
|
-
return {
|
|
16602
|
-
data,
|
|
16603
|
-
contentType,
|
|
16604
|
-
extension
|
|
16605
|
-
};
|
|
15966
|
+
function parsedRunToOptions(parsed) {
|
|
15967
|
+
const contentChildren = parsed.children.filter((c) => c !== PARSED_FOOTNOTE_REF);
|
|
15968
|
+
if (contentChildren.length === 0 && parsed.children.some((c) => c === PARSED_FOOTNOTE_REF)) return null;
|
|
15969
|
+
const opts = { ...parsed.properties };
|
|
15970
|
+
const isRefChild = (c) => typeof c === "object" && c !== null && ("commentReference" in c || "footnoteReference" in c || "endnoteReference" in c);
|
|
15971
|
+
const refChildren = contentChildren.filter(isRefChild);
|
|
15972
|
+
const nonRefChildren = contentChildren.filter((c) => !isRefChild(c));
|
|
15973
|
+
if (refChildren.length > 0 && nonRefChildren.length === 0) return refChildren[0];
|
|
15974
|
+
const symbolIdx = nonRefChildren.findIndex((c) => typeof c === "object" && c !== null && "symbolRun" in c);
|
|
15975
|
+
if (symbolIdx >= 0 && nonRefChildren.length === 1 && !parsed.properties) return nonRefChildren[symbolIdx];
|
|
15976
|
+
const textParts = [];
|
|
15977
|
+
let breakCount = 0;
|
|
15978
|
+
let hasPageBreak = false;
|
|
15979
|
+
let hasColumnBreak = false;
|
|
15980
|
+
for (const child of nonRefChildren) if (typeof child === "string") textParts.push(child);
|
|
15981
|
+
else if (child === PARSED_LINE_BREAK) breakCount++;
|
|
15982
|
+
else if (child === PARSED_PAGE_BREAK) hasPageBreak = true;
|
|
15983
|
+
else if (child === PARSED_COLUMN_BREAK) hasColumnBreak = true;
|
|
15984
|
+
if (textParts.length > 0) opts.text = textParts.join("");
|
|
15985
|
+
if (breakCount > 0) opts.break = breakCount;
|
|
15986
|
+
if (hasPageBreak) opts.pageBreak = true;
|
|
15987
|
+
if (hasColumnBreak) opts.columnBreak = true;
|
|
15988
|
+
if (Object.keys(opts).length === 0 && textParts.length === 0 && breakCount === 0 && !hasPageBreak && !hasColumnBreak) return null;
|
|
15989
|
+
return opts;
|
|
16606
15990
|
}
|
|
16607
15991
|
//#endregion
|
|
16608
|
-
//#region src/file/
|
|
15992
|
+
//#region src/file/paragraph/paragraph-parse.ts
|
|
16609
15993
|
/**
|
|
16610
|
-
*
|
|
15994
|
+
* Paragraph parser for DOCX documents.
|
|
16611
15995
|
*
|
|
16612
|
-
* Parses w:
|
|
15996
|
+
* Parses w:p and w:pPr Element trees into ParagraphOptions objects.
|
|
16613
15997
|
*
|
|
16614
15998
|
* @module
|
|
16615
15999
|
*/
|
|
16000
|
+
init_style();
|
|
16001
|
+
init_math_parse();
|
|
16002
|
+
const HEADING_MAP = {
|
|
16003
|
+
Heading1: HeadingLevel.HEADING_1,
|
|
16004
|
+
Heading2: HeadingLevel.HEADING_2,
|
|
16005
|
+
Heading3: HeadingLevel.HEADING_3,
|
|
16006
|
+
Heading4: HeadingLevel.HEADING_4,
|
|
16007
|
+
Heading5: HeadingLevel.HEADING_5,
|
|
16008
|
+
Heading6: HeadingLevel.HEADING_6,
|
|
16009
|
+
Title: HeadingLevel.TITLE
|
|
16010
|
+
};
|
|
16616
16011
|
/**
|
|
16617
|
-
* Parse
|
|
16618
|
-
* based on the graphicData URI.
|
|
16619
|
-
*/
|
|
16620
|
-
function parseDrawingRun(el, ctx) {
|
|
16621
|
-
const graphicData = findDeep(el, "a:graphicData")[0];
|
|
16622
|
-
if (!graphicData) return void 0;
|
|
16623
|
-
const uri = attr(graphicData, "uri") ?? "";
|
|
16624
|
-
if (uri.includes("/chart")) return parseChartDrawing(el, ctx);
|
|
16625
|
-
if (uri.includes("/diagram")) return parseSmartArtDrawing(el, ctx);
|
|
16626
|
-
return parseImageRun(el, ctx);
|
|
16627
|
-
}
|
|
16628
|
-
/**
|
|
16629
|
-
* Determine image type from file extension or MIME type.
|
|
16012
|
+
* Parse w:pPr element into paragraph properties (without children).
|
|
16630
16013
|
*/
|
|
16631
|
-
function
|
|
16632
|
-
|
|
16633
|
-
|
|
16634
|
-
|
|
16635
|
-
|
|
16636
|
-
|
|
16637
|
-
|
|
16638
|
-
case "tif":
|
|
16639
|
-
case "tiff": return "tif";
|
|
16640
|
-
case "ico": return "ico";
|
|
16641
|
-
case "emf": return "emf";
|
|
16642
|
-
case "wmf": return "wmf";
|
|
16643
|
-
default: return "png";
|
|
16014
|
+
function parseParagraphProperties(el, _ctx) {
|
|
16015
|
+
const opts = {};
|
|
16016
|
+
const pStyle = findChild(el, "w:pStyle");
|
|
16017
|
+
if (pStyle) {
|
|
16018
|
+
const styleVal = attr(pStyle, "w:val");
|
|
16019
|
+
if (styleVal) if (HEADING_MAP[styleVal]) opts.heading = HEADING_MAP[styleVal];
|
|
16020
|
+
else opts.style = styleVal;
|
|
16644
16021
|
}
|
|
16645
|
-
|
|
16646
|
-
|
|
16647
|
-
|
|
16648
|
-
|
|
16649
|
-
function parseImageRun(el, ctx) {
|
|
16650
|
-
const inline = findDeep(el, "wp:inline")[0];
|
|
16651
|
-
const anchor = inline ? void 0 : findDeep(el, "wp:anchor")[0];
|
|
16652
|
-
const parent = inline ?? anchor;
|
|
16653
|
-
if (!parent) return void 0;
|
|
16654
|
-
const extent = findChild(parent, "wp:extent");
|
|
16655
|
-
let width;
|
|
16656
|
-
let height;
|
|
16657
|
-
if (extent) {
|
|
16658
|
-
const cxEmu = attrNum(extent, "cx");
|
|
16659
|
-
const cyEmu = attrNum(extent, "cy");
|
|
16660
|
-
if (cxEmu !== void 0) width = convertEmuToPixels(cxEmu);
|
|
16661
|
-
if (cyEmu !== void 0) height = convertEmuToPixels(cyEmu);
|
|
16022
|
+
const jc = findChild(el, "w:jc");
|
|
16023
|
+
if (jc) {
|
|
16024
|
+
const val = attr(jc, "w:val");
|
|
16025
|
+
if (val) opts.alignment = val;
|
|
16662
16026
|
}
|
|
16663
|
-
const
|
|
16664
|
-
if (
|
|
16665
|
-
|
|
16666
|
-
|
|
16667
|
-
|
|
16668
|
-
|
|
16669
|
-
|
|
16670
|
-
|
|
16671
|
-
|
|
16672
|
-
|
|
16673
|
-
|
|
16674
|
-
|
|
16675
|
-
|
|
16676
|
-
|
|
16677
|
-
|
|
16678
|
-
|
|
16679
|
-
const docPr = findChild(parent, "wp:docPr");
|
|
16680
|
-
if (docPr) {
|
|
16681
|
-
const name = attr(docPr, "name");
|
|
16682
|
-
const descr = attr(docPr, "descr");
|
|
16683
|
-
if (name || descr) imageOpts.altText = {
|
|
16684
|
-
...name ? { name } : {},
|
|
16685
|
-
...descr ? { description: descr } : {}
|
|
16686
|
-
};
|
|
16027
|
+
const spacing = findChild(el, "w:spacing");
|
|
16028
|
+
if (spacing) {
|
|
16029
|
+
const sp = {};
|
|
16030
|
+
const before = attrNum(spacing, "w:before");
|
|
16031
|
+
if (before !== void 0) sp.before = before;
|
|
16032
|
+
const after = attrNum(spacing, "w:after");
|
|
16033
|
+
if (after !== void 0) sp.after = after;
|
|
16034
|
+
const line = attrNum(spacing, "w:line");
|
|
16035
|
+
if (line !== void 0) sp.line = line;
|
|
16036
|
+
const lineRule = attr(spacing, "w:lineRule");
|
|
16037
|
+
if (lineRule) sp.lineRule = lineRule;
|
|
16038
|
+
const beforeAuto = attrBool(spacing, "w:beforeAutospacing") ?? attrBool(spacing, "w:beforeLines");
|
|
16039
|
+
if (beforeAuto !== void 0) sp.beforeAutoSpacing = beforeAuto;
|
|
16040
|
+
const afterAuto = attrBool(spacing, "w:afterAutospacing") ?? attrBool(spacing, "w:afterLines");
|
|
16041
|
+
if (afterAuto !== void 0) sp.afterAutoSpacing = afterAuto;
|
|
16042
|
+
if (Object.keys(sp).length > 0) opts.spacing = sp;
|
|
16687
16043
|
}
|
|
16688
|
-
|
|
16689
|
-
|
|
16690
|
-
const
|
|
16691
|
-
|
|
16692
|
-
|
|
16693
|
-
|
|
16694
|
-
|
|
16695
|
-
|
|
16696
|
-
|
|
16697
|
-
const
|
|
16698
|
-
if (
|
|
16699
|
-
|
|
16700
|
-
|
|
16701
|
-
|
|
16702
|
-
|
|
16703
|
-
|
|
16704
|
-
for (const wrapType of [
|
|
16705
|
-
"wrapSquare",
|
|
16706
|
-
"wrapTight",
|
|
16707
|
-
"wrapTopAndBottom",
|
|
16708
|
-
"wrapNone"
|
|
16709
|
-
]) if (findChild(anchor, `wp:${wrapType}`)) {
|
|
16710
|
-
floating.wrap = wrapType;
|
|
16711
|
-
break;
|
|
16712
|
-
}
|
|
16713
|
-
if (attrBool(anchor, "behindDoc")) floating.behindDocument = true;
|
|
16714
|
-
if (Object.keys(floating).length > 0) imageOpts.floating = floating;
|
|
16044
|
+
const ind = findChild(el, "w:ind");
|
|
16045
|
+
if (ind) {
|
|
16046
|
+
const indentObj = {};
|
|
16047
|
+
const left = attrNum(ind, "w:left");
|
|
16048
|
+
if (left !== void 0) indentObj.left = left;
|
|
16049
|
+
const right = attrNum(ind, "w:right");
|
|
16050
|
+
if (right !== void 0) indentObj.right = right;
|
|
16051
|
+
const start = attrNum(ind, "w:start");
|
|
16052
|
+
if (start !== void 0) indentObj.start = start;
|
|
16053
|
+
const end = attrNum(ind, "w:end");
|
|
16054
|
+
if (end !== void 0) indentObj.end = end;
|
|
16055
|
+
const hanging = attrNum(ind, "w:hanging");
|
|
16056
|
+
if (hanging !== void 0) indentObj.hanging = hanging;
|
|
16057
|
+
const firstLine = attrNum(ind, "w:firstLine");
|
|
16058
|
+
if (firstLine !== void 0) indentObj.firstLine = firstLine;
|
|
16059
|
+
if (Object.keys(indentObj).length > 0) opts.indent = indentObj;
|
|
16715
16060
|
}
|
|
16716
|
-
|
|
16717
|
-
|
|
16718
|
-
|
|
16719
|
-
|
|
16720
|
-
|
|
16721
|
-
|
|
16722
|
-
|
|
16723
|
-
|
|
16724
|
-
|
|
16725
|
-
|
|
16726
|
-
|
|
16727
|
-
|
|
16728
|
-
|
|
16729
|
-
|
|
16730
|
-
|
|
16731
|
-
|
|
16732
|
-
|
|
16733
|
-
|
|
16734
|
-
|
|
16735
|
-
|
|
16736
|
-
|
|
16737
|
-
|
|
16738
|
-
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
}
|
|
16742
|
-
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
16750
|
-
|
|
16751
|
-
|
|
16752
|
-
|
|
16753
|
-
|
|
16754
|
-
return { chart: opts };
|
|
16755
|
-
}
|
|
16756
|
-
/**
|
|
16757
|
-
* Parse c:chartSpace element into ChartOptions.
|
|
16758
|
-
*/
|
|
16759
|
-
function parseChartXml(el) {
|
|
16760
|
-
const chart = findChild(el, "c:chart");
|
|
16761
|
-
if (!chart) return void 0;
|
|
16762
|
-
const opts = {};
|
|
16763
|
-
const titleEl = findChild(chart, "c:title");
|
|
16764
|
-
if (titleEl) {
|
|
16765
|
-
const rich = findDeep(titleEl, "c:rich")[0];
|
|
16766
|
-
if (rich) {
|
|
16767
|
-
const t = findDeep(rich, "a:t")[0];
|
|
16768
|
-
if (t) {
|
|
16769
|
-
const title = textOf(t);
|
|
16770
|
-
if (title) opts.title = title;
|
|
16771
|
-
}
|
|
16061
|
+
const numPr = findChild(el, "w:numPr");
|
|
16062
|
+
if (numPr) {
|
|
16063
|
+
const ilvl = findChild(numPr, "w:ilvl");
|
|
16064
|
+
const level = ilvl ? attrNum(ilvl, "w:val") ?? 0 : 0;
|
|
16065
|
+
const numIdEl = findChild(numPr, "w:numId");
|
|
16066
|
+
const numId = numIdEl ? attr(numIdEl, "w:val") : void 0;
|
|
16067
|
+
if (numId !== void 0 && _ctx.numberingCache.size > 0) {
|
|
16068
|
+
const numEl = _ctx.docx.numbering;
|
|
16069
|
+
if (numEl) {
|
|
16070
|
+
let abstractNumId;
|
|
16071
|
+
for (const child of numEl.elements ?? []) {
|
|
16072
|
+
if (child.name !== "w:num") continue;
|
|
16073
|
+
if (attr(child, "w:numId") === numId) {
|
|
16074
|
+
const absRef = findChild(child, "w:abstractNumId");
|
|
16075
|
+
abstractNumId = absRef ? attr(absRef, "w:val") : void 0;
|
|
16076
|
+
break;
|
|
16077
|
+
}
|
|
16078
|
+
}
|
|
16079
|
+
if (abstractNumId !== void 0) opts.numbering = {
|
|
16080
|
+
reference: `list_${numId}`,
|
|
16081
|
+
level
|
|
16082
|
+
};
|
|
16083
|
+
else opts.bullet = { level };
|
|
16084
|
+
} else opts.bullet = { level };
|
|
16085
|
+
} else opts.bullet = { level };
|
|
16086
|
+
}
|
|
16087
|
+
const tabs = findChild(el, "w:tabs");
|
|
16088
|
+
if (tabs) {
|
|
16089
|
+
const tabStops = [];
|
|
16090
|
+
for (const tab of children(tabs, "w:tab")) {
|
|
16091
|
+
const tabObj = {};
|
|
16092
|
+
const pos = attrNum(tab, "w:pos");
|
|
16093
|
+
if (pos !== void 0) tabObj.position = pos;
|
|
16094
|
+
const val = attr(tab, "w:val");
|
|
16095
|
+
if (val) tabObj.type = val;
|
|
16096
|
+
const leader = attr(tab, "w:leader");
|
|
16097
|
+
if (leader) tabObj.leader = leader;
|
|
16098
|
+
tabStops.push(tabObj);
|
|
16772
16099
|
}
|
|
16100
|
+
if (tabStops.length > 0) opts.tabStops = tabStops;
|
|
16773
16101
|
}
|
|
16774
|
-
const
|
|
16775
|
-
|
|
16776
|
-
|
|
16777
|
-
|
|
16778
|
-
|
|
16779
|
-
|
|
16780
|
-
|
|
16781
|
-
|
|
16782
|
-
|
|
16783
|
-
|
|
16784
|
-
|
|
16102
|
+
for (const [name, optKey] of [
|
|
16103
|
+
["w:keepNext", "keepNext"],
|
|
16104
|
+
["w:keepLines", "keepLines"],
|
|
16105
|
+
["w:pageBreakBefore", "pageBreakBefore"],
|
|
16106
|
+
["w:widowControl", "widowControl"],
|
|
16107
|
+
["w:suppressLineNumbers", "suppressLineNumbers"],
|
|
16108
|
+
["w:contextualSpacing", "contextualSpacing"],
|
|
16109
|
+
["w:bidi", "bidirectional"],
|
|
16110
|
+
["w:wordWrap", "wordWrap"],
|
|
16111
|
+
["w:suppressAutoHyphens", "suppressAutoHyphens"],
|
|
16112
|
+
["w:adjustRightInd", "adjustRightInd"],
|
|
16113
|
+
["w:snapToGrid", "snapToGrid"],
|
|
16114
|
+
["w:mirrorIndents", "mirrorIndents"],
|
|
16115
|
+
["w:kinsoku", "kinsoku"],
|
|
16116
|
+
["w:topLinePunct", "topLinePunct"],
|
|
16117
|
+
["w:autoSpaceDE", "autoSpaceDE"],
|
|
16118
|
+
["w:overflowPunct", "overflowPunctuation"],
|
|
16119
|
+
["w:suppressOverlap", "suppressOverlap"]
|
|
16120
|
+
]) {
|
|
16121
|
+
const child = findChild(el, name);
|
|
16122
|
+
if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
|
|
16123
|
+
}
|
|
16124
|
+
if (findChild(el, "w:pBdr")) {
|
|
16125
|
+
const pBdr = findChild(el, "w:pBdr");
|
|
16126
|
+
const border = {};
|
|
16127
|
+
for (const side of [
|
|
16128
|
+
"top",
|
|
16129
|
+
"bottom",
|
|
16130
|
+
"left",
|
|
16131
|
+
"right"
|
|
16132
|
+
]) {
|
|
16133
|
+
const sideEl = findChild(pBdr, `w:${side}`);
|
|
16134
|
+
if (sideEl) {
|
|
16135
|
+
const sideOpts = {};
|
|
16136
|
+
const style = attr(sideEl, "w:val");
|
|
16137
|
+
if (style) sideOpts.style = style;
|
|
16138
|
+
const color = attr(sideEl, "w:color");
|
|
16139
|
+
if (color) sideOpts.color = color;
|
|
16140
|
+
const size = attrNum(sideEl, "w:sz");
|
|
16141
|
+
if (size !== void 0) sideOpts.size = size;
|
|
16142
|
+
const space = attrNum(sideEl, "w:space");
|
|
16143
|
+
if (space !== void 0) sideOpts.space = space;
|
|
16144
|
+
border[side] = sideOpts;
|
|
16785
16145
|
}
|
|
16786
|
-
case "c:lineChart":
|
|
16787
|
-
chartType = "line";
|
|
16788
|
-
typeElement = child;
|
|
16789
|
-
break;
|
|
16790
|
-
case "c:pieChart":
|
|
16791
|
-
chartType = "pie";
|
|
16792
|
-
typeElement = child;
|
|
16793
|
-
break;
|
|
16794
|
-
case "c:areaChart":
|
|
16795
|
-
chartType = "area";
|
|
16796
|
-
typeElement = child;
|
|
16797
|
-
break;
|
|
16798
|
-
case "c:scatterChart":
|
|
16799
|
-
chartType = "scatter";
|
|
16800
|
-
typeElement = child;
|
|
16801
|
-
break;
|
|
16802
16146
|
}
|
|
16803
|
-
if (
|
|
16147
|
+
if (Object.keys(border).length > 0) opts.border = border;
|
|
16804
16148
|
}
|
|
16805
|
-
|
|
16806
|
-
|
|
16807
|
-
|
|
16808
|
-
|
|
16809
|
-
|
|
16810
|
-
|
|
16811
|
-
|
|
16812
|
-
const
|
|
16813
|
-
if (
|
|
16814
|
-
|
|
16815
|
-
series.push({
|
|
16816
|
-
name: nameParts[0] ?? "",
|
|
16817
|
-
values: vals
|
|
16818
|
-
});
|
|
16149
|
+
const shd = findChild(el, "w:shd");
|
|
16150
|
+
if (shd) {
|
|
16151
|
+
const shdObj = {};
|
|
16152
|
+
const fill = attr(shd, "w:fill");
|
|
16153
|
+
if (fill) shdObj.fill = fill;
|
|
16154
|
+
const color = attr(shd, "w:color");
|
|
16155
|
+
if (color) shdObj.color = color;
|
|
16156
|
+
const val = attr(shd, "w:val");
|
|
16157
|
+
if (val) shdObj.type = val;
|
|
16158
|
+
if (Object.keys(shdObj).length > 0) opts.shading = shdObj;
|
|
16819
16159
|
}
|
|
16820
|
-
|
|
16821
|
-
|
|
16822
|
-
|
|
16823
|
-
|
|
16824
|
-
opts.showLegend = findChild(chart, "c:legend") !== void 0;
|
|
16825
|
-
const styleEl = findChild(el, "c:style");
|
|
16826
|
-
if (styleEl) {
|
|
16827
|
-
const val = attrNum(styleEl, "val");
|
|
16828
|
-
if (val !== void 0) opts.style = val;
|
|
16160
|
+
const textAlignment = findChild(el, "w:textAlignment");
|
|
16161
|
+
if (textAlignment) {
|
|
16162
|
+
const val = attr(textAlignment, "w:val");
|
|
16163
|
+
if (val) opts.textAlignment = val;
|
|
16829
16164
|
}
|
|
16830
|
-
|
|
16831
|
-
|
|
16832
|
-
|
|
16833
|
-
|
|
16834
|
-
*/
|
|
16835
|
-
function extractStrCache(parent, containerName) {
|
|
16836
|
-
const container = findChild(parent, containerName);
|
|
16837
|
-
if (!container) return [];
|
|
16838
|
-
const cache = findDeep(container, "c:strCache")[0];
|
|
16839
|
-
if (!cache) return [];
|
|
16840
|
-
const values = [];
|
|
16841
|
-
for (const pt of cache.elements ?? []) {
|
|
16842
|
-
if (pt.name !== "c:pt") continue;
|
|
16843
|
-
const v = findChild(pt, "c:v");
|
|
16844
|
-
if (v) values.push(textOf(v) ?? "");
|
|
16165
|
+
const outlineLvl = findChild(el, "w:outlineLvl");
|
|
16166
|
+
if (outlineLvl) {
|
|
16167
|
+
const val = attrNum(outlineLvl, "w:val");
|
|
16168
|
+
if (val !== void 0) opts.outlineLevel = val;
|
|
16845
16169
|
}
|
|
16846
|
-
|
|
16847
|
-
|
|
16848
|
-
|
|
16849
|
-
|
|
16850
|
-
|
|
16851
|
-
|
|
16852
|
-
|
|
16853
|
-
|
|
16854
|
-
|
|
16855
|
-
|
|
16856
|
-
|
|
16857
|
-
|
|
16858
|
-
|
|
16859
|
-
|
|
16860
|
-
|
|
16861
|
-
|
|
16862
|
-
|
|
16170
|
+
const cnfStyle = findChild(el, "w:cnfStyle");
|
|
16171
|
+
if (cnfStyle) {
|
|
16172
|
+
const val = attr(cnfStyle, "w:val");
|
|
16173
|
+
if (val) opts.cnfStyle = { val };
|
|
16174
|
+
}
|
|
16175
|
+
const rPr = findChild(el, "w:rPr");
|
|
16176
|
+
if (rPr) opts.run = parseRunProperties(rPr);
|
|
16177
|
+
const framePr = findChild(el, "w:framePr");
|
|
16178
|
+
if (framePr) {
|
|
16179
|
+
const frame = {};
|
|
16180
|
+
for (const [attrName, optName] of [
|
|
16181
|
+
["w:dropCap", "dropCap"],
|
|
16182
|
+
["w:lines", "lines"],
|
|
16183
|
+
["w:wrap", "wrap"],
|
|
16184
|
+
["w:vAnchor", "vAnchor"],
|
|
16185
|
+
["w:hAnchor", "hAnchor"],
|
|
16186
|
+
["w:x", "x"],
|
|
16187
|
+
["w:y", "y"],
|
|
16188
|
+
["w:hRule", "hRule"],
|
|
16189
|
+
["w:hSpace", "hSpace"],
|
|
16190
|
+
["w:vSpace", "vSpace"]
|
|
16191
|
+
]) {
|
|
16192
|
+
const val = attr(framePr, attrName);
|
|
16193
|
+
if (val !== void 0) frame[optName] = val;
|
|
16863
16194
|
}
|
|
16195
|
+
const w = attrNum(framePr, "w:w");
|
|
16196
|
+
if (w !== void 0) frame.width = w;
|
|
16197
|
+
const h = attrNum(framePr, "w:h");
|
|
16198
|
+
if (h !== void 0) frame.height = h;
|
|
16199
|
+
if (Object.keys(frame).length > 0) opts.frame = frame;
|
|
16864
16200
|
}
|
|
16865
|
-
return
|
|
16866
|
-
}
|
|
16867
|
-
function parseSmartArtDrawing(el, ctx) {
|
|
16868
|
-
const relIds = findDeep(el, "dgm:relIds")[0];
|
|
16869
|
-
if (!relIds) return void 0;
|
|
16870
|
-
const rId = attr(relIds, "r:dm");
|
|
16871
|
-
const dataPath = lookupRId(ctx.docx.partRefs.diagramData, rId);
|
|
16872
|
-
if (!dataPath) return void 0;
|
|
16873
|
-
const dataEl = ctx.docx.doc.get(dataPath);
|
|
16874
|
-
if (!dataEl) return void 0;
|
|
16875
|
-
const opts = parseSmartArtDataXml(dataEl);
|
|
16876
|
-
if (!opts) return void 0;
|
|
16877
|
-
const ext = getDrawingExtent(el);
|
|
16878
|
-
if (ext.width !== void 0 || ext.height !== void 0) opts.transformation = { ...ext };
|
|
16879
|
-
return { smartArt: opts };
|
|
16201
|
+
return opts;
|
|
16880
16202
|
}
|
|
16881
16203
|
/**
|
|
16882
|
-
* Parse
|
|
16204
|
+
* Parse a w:p element into ParagraphOptions.
|
|
16883
16205
|
*/
|
|
16884
|
-
function
|
|
16885
|
-
const ptLst = findChild(el, "dgm:ptLst");
|
|
16886
|
-
if (!ptLst) return void 0;
|
|
16206
|
+
function parseParagraph(el, ctx) {
|
|
16887
16207
|
const opts = {};
|
|
16888
|
-
const
|
|
16889
|
-
|
|
16890
|
-
|
|
16891
|
-
|
|
16892
|
-
|
|
16893
|
-
|
|
16894
|
-
const
|
|
16895
|
-
if (
|
|
16896
|
-
const
|
|
16897
|
-
|
|
16898
|
-
|
|
16899
|
-
|
|
16900
|
-
|
|
16901
|
-
const style = qsTypeId.split("/").pop();
|
|
16902
|
-
if (style) opts.style = style;
|
|
16903
|
-
const color = csTypeId.split("/").pop();
|
|
16904
|
-
if (color) opts.color = color;
|
|
16208
|
+
const pPr = findChild(el, "w:pPr");
|
|
16209
|
+
if (pPr) Object.assign(opts, parseParagraphProperties(pPr, ctx));
|
|
16210
|
+
const childList = [];
|
|
16211
|
+
for (const child of el.elements ?? []) switch (child.name) {
|
|
16212
|
+
case "w:pPr": break;
|
|
16213
|
+
case "w:r": {
|
|
16214
|
+
const drawingEl = findChild(child, "w:drawing");
|
|
16215
|
+
if (drawingEl) {
|
|
16216
|
+
const drawingChild = parseDrawingRun(drawingEl, ctx);
|
|
16217
|
+
if (drawingChild) {
|
|
16218
|
+
childList.push(drawingChild);
|
|
16219
|
+
break;
|
|
16220
|
+
}
|
|
16905
16221
|
}
|
|
16906
|
-
|
|
16907
|
-
const
|
|
16908
|
-
|
|
16222
|
+
const parsed = parseRun(child, ctx);
|
|
16223
|
+
const rawChildren = parsed.children.filter((c) => c instanceof RawPassthrough);
|
|
16224
|
+
const runOpts = parsedRunToOptions({
|
|
16225
|
+
...parsed,
|
|
16226
|
+
children: parsed.children.filter((c) => !(c instanceof RawPassthrough))
|
|
16227
|
+
});
|
|
16228
|
+
if (runOpts !== null) childList.push(runOpts);
|
|
16229
|
+
childList.push(...rawChildren);
|
|
16230
|
+
break;
|
|
16909
16231
|
}
|
|
16232
|
+
case "w:hyperlink": {
|
|
16233
|
+
const hl = {};
|
|
16234
|
+
const rId = attr(child, "r:id");
|
|
16235
|
+
if (rId) {
|
|
16236
|
+
const target = ctx.docx.partRefs.hyperlinks.get(rId);
|
|
16237
|
+
if (target) hl.link = target;
|
|
16238
|
+
}
|
|
16239
|
+
const anchor = attr(child, "w:anchor");
|
|
16240
|
+
if (anchor) hl.anchor = anchor;
|
|
16241
|
+
const tooltip = attr(child, "w:tooltip");
|
|
16242
|
+
if (tooltip) hl.tooltip = tooltip;
|
|
16243
|
+
const linkRuns = [];
|
|
16244
|
+
for (const sub of child.elements ?? []) if (sub.name === "w:r") {
|
|
16245
|
+
const runOpts = parsedRunToOptions(parseRun(sub, ctx));
|
|
16246
|
+
linkRuns.push(runOpts);
|
|
16247
|
+
}
|
|
16248
|
+
if (linkRuns.length > 0) {
|
|
16249
|
+
hl.children = linkRuns;
|
|
16250
|
+
childList.push({ hyperlink: hl });
|
|
16251
|
+
}
|
|
16252
|
+
break;
|
|
16253
|
+
}
|
|
16254
|
+
case "w:bookmarkStart": {
|
|
16255
|
+
const id = attrNum(child, "w:id");
|
|
16256
|
+
const name = attr(child, "w:name");
|
|
16257
|
+
if (id !== void 0 && name) childList.push({ bookmarkStart: {
|
|
16258
|
+
id,
|
|
16259
|
+
name
|
|
16260
|
+
} });
|
|
16261
|
+
break;
|
|
16262
|
+
}
|
|
16263
|
+
case "w:bookmarkEnd": {
|
|
16264
|
+
const id = attrNum(child, "w:id");
|
|
16265
|
+
if (id !== void 0) childList.push({ bookmarkEnd: id });
|
|
16266
|
+
break;
|
|
16267
|
+
}
|
|
16268
|
+
case "w:commentRangeStart": {
|
|
16269
|
+
const id = attrNum(child, "w:id");
|
|
16270
|
+
if (id !== void 0) childList.push({ commentRangeStart: id });
|
|
16271
|
+
break;
|
|
16272
|
+
}
|
|
16273
|
+
case "w:commentRangeEnd": {
|
|
16274
|
+
const id = attrNum(child, "w:id");
|
|
16275
|
+
if (id !== void 0) childList.push({ commentRangeEnd: id });
|
|
16276
|
+
break;
|
|
16277
|
+
}
|
|
16278
|
+
case "w:commentReference": {
|
|
16279
|
+
const id = attrNum(child, "w:id");
|
|
16280
|
+
if (id !== void 0) childList.push({ commentReference: id });
|
|
16281
|
+
break;
|
|
16282
|
+
}
|
|
16283
|
+
case "m:oMath": {
|
|
16284
|
+
const mathChildren = parseMathChildren(child);
|
|
16285
|
+
childList.push({ math: { children: mathChildren } });
|
|
16286
|
+
break;
|
|
16287
|
+
}
|
|
16288
|
+
case "w:ins": {
|
|
16289
|
+
const insRun = findChild(child, "w:r");
|
|
16290
|
+
if (insRun) {
|
|
16291
|
+
const runOpts = parsedRunToOptions(parseRun(insRun, ctx));
|
|
16292
|
+
if (runOpts !== null && typeof runOpts === "object" && !("commentReference" in runOpts)) childList.push({ insertion: {
|
|
16293
|
+
id: attrNum(child, "w:id") ?? 0,
|
|
16294
|
+
author: attr(child, "w:author") ?? "",
|
|
16295
|
+
date: attr(child, "w:date") ?? "",
|
|
16296
|
+
...runOpts
|
|
16297
|
+
} });
|
|
16298
|
+
}
|
|
16299
|
+
break;
|
|
16300
|
+
}
|
|
16301
|
+
case "w:del": {
|
|
16302
|
+
const delRun = findChild(child, "w:r");
|
|
16303
|
+
if (delRun) {
|
|
16304
|
+
const runOpts = parsedRunToOptions(parseRun(delRun, ctx));
|
|
16305
|
+
if (runOpts !== null && typeof runOpts === "object" && !("commentReference" in runOpts)) childList.push({ deletion: {
|
|
16306
|
+
id: attrNum(child, "w:id") ?? 0,
|
|
16307
|
+
author: attr(child, "w:author") ?? "",
|
|
16308
|
+
date: attr(child, "w:date") ?? "",
|
|
16309
|
+
...runOpts
|
|
16310
|
+
} });
|
|
16311
|
+
}
|
|
16312
|
+
break;
|
|
16313
|
+
}
|
|
16314
|
+
default:
|
|
16315
|
+
if (child.name && child.elements && child.elements.length > 0) childList.push(new RawPassthrough(child));
|
|
16316
|
+
break;
|
|
16910
16317
|
}
|
|
16911
|
-
|
|
16912
|
-
|
|
16913
|
-
|
|
16914
|
-
|
|
16915
|
-
|
|
16916
|
-
|
|
16917
|
-
|
|
16918
|
-
|
|
16919
|
-
const srcId = attr(cxn, "srcId");
|
|
16920
|
-
const destId = attr(cxn, "destId");
|
|
16921
|
-
if (!srcId || !destId || !nodeMap.has(destId)) continue;
|
|
16922
|
-
let arr = childrenMap.get(srcId);
|
|
16923
|
-
if (!arr) {
|
|
16924
|
-
arr = [];
|
|
16925
|
-
childrenMap.set(srcId, arr);
|
|
16318
|
+
if (childList.length > 0) {
|
|
16319
|
+
if (childList.every((c) => typeof c === "object" && c !== null && "text" in c && Object.keys(c).length === 1)) {
|
|
16320
|
+
const combined = childList.map((c) => c.text).join("");
|
|
16321
|
+
if (combined && Object.keys(opts).length === 0) return combined;
|
|
16322
|
+
if (combined) {
|
|
16323
|
+
opts.text = combined;
|
|
16324
|
+
return opts;
|
|
16325
|
+
}
|
|
16926
16326
|
}
|
|
16927
|
-
|
|
16327
|
+
opts.children = childList;
|
|
16928
16328
|
}
|
|
16929
|
-
opts.data = { nodes: (childrenMap.get("0") ?? []).map((id) => buildSmartArtNode(id, nodeMap, childrenMap)) };
|
|
16930
16329
|
return opts;
|
|
16931
16330
|
}
|
|
16932
|
-
|
|
16933
|
-
|
|
16934
|
-
|
|
16935
|
-
|
|
16331
|
+
//#endregion
|
|
16332
|
+
//#region src/file/alt-chunk/alt-chunk-parse.ts
|
|
16333
|
+
/**
|
|
16334
|
+
* AltChunk parser for DOCX documents.
|
|
16335
|
+
*
|
|
16336
|
+
* Parses w:altChunk elements and extracts embedded content from the ZIP.
|
|
16337
|
+
*
|
|
16338
|
+
* @module
|
|
16339
|
+
*/
|
|
16340
|
+
/**
|
|
16341
|
+
* Parse a w:altChunk element into AltChunkOptions.
|
|
16342
|
+
* Reads the referenced data from the ZIP package.
|
|
16343
|
+
*/
|
|
16344
|
+
function parseAltChunk(el, ctx) {
|
|
16345
|
+
const rId = attr(el, "r:id");
|
|
16346
|
+
if (!rId) throw new Error("w:altChunk missing r:id attribute");
|
|
16347
|
+
const path = ctx.docx.partRefs.afChunks.get(rId);
|
|
16348
|
+
if (!path) throw new Error(`AltChunk relationship ${rId} not found`);
|
|
16349
|
+
const data = ctx.docx.doc.getRaw(path);
|
|
16350
|
+
if (!data) throw new Error(`AltChunk data not found at ${path}`);
|
|
16351
|
+
const ext = path.split(".").pop() ?? "txt";
|
|
16352
|
+
let contentType;
|
|
16353
|
+
let extension;
|
|
16354
|
+
switch (ext) {
|
|
16355
|
+
case "html":
|
|
16356
|
+
contentType = "text/html";
|
|
16357
|
+
extension = "html";
|
|
16358
|
+
break;
|
|
16359
|
+
case "rtf":
|
|
16360
|
+
contentType = "application/rtf";
|
|
16361
|
+
extension = "rtf";
|
|
16362
|
+
break;
|
|
16363
|
+
default:
|
|
16364
|
+
contentType = "text/plain";
|
|
16365
|
+
extension = "txt";
|
|
16366
|
+
break;
|
|
16367
|
+
}
|
|
16936
16368
|
return {
|
|
16937
|
-
|
|
16938
|
-
|
|
16369
|
+
data,
|
|
16370
|
+
contentType,
|
|
16371
|
+
extension
|
|
16939
16372
|
};
|
|
16940
16373
|
}
|
|
16941
16374
|
//#endregion
|
|
@@ -17223,8 +16656,9 @@ function parseTableProperties(el) {
|
|
|
17223
16656
|
}
|
|
17224
16657
|
const tblW = findChild(el, "w:tblW");
|
|
17225
16658
|
if (tblW) {
|
|
17226
|
-
const
|
|
16659
|
+
const rawSize = attr(tblW, "w:w");
|
|
17227
16660
|
const type = attr(tblW, "w:type");
|
|
16661
|
+
const size = type === "pct" ? rawSize : attrNum(tblW, "w:w");
|
|
17228
16662
|
if (size !== void 0 || type) opts.width = {
|
|
17229
16663
|
size: size ?? 0,
|
|
17230
16664
|
...type ? { type } : {}
|
|
@@ -17395,6 +16829,29 @@ function parseTableCellProperties(el) {
|
|
|
17395
16829
|
if (Object.keys(borders).length > 0) opts.borders = borders;
|
|
17396
16830
|
}
|
|
17397
16831
|
if (findChild(el, "w:noWrap")) opts.noWrap = true;
|
|
16832
|
+
const tcMar = findChild(el, "w:tcMar");
|
|
16833
|
+
if (tcMar) {
|
|
16834
|
+
const margins = {};
|
|
16835
|
+
let marginUnitType;
|
|
16836
|
+
for (const side of [
|
|
16837
|
+
"top",
|
|
16838
|
+
"bottom",
|
|
16839
|
+
"left",
|
|
16840
|
+
"right"
|
|
16841
|
+
]) {
|
|
16842
|
+
const sideEl = findChild(tcMar, `w:${side}`);
|
|
16843
|
+
if (sideEl) {
|
|
16844
|
+
const size = attrNum(sideEl, "w:w");
|
|
16845
|
+
const type = attr(sideEl, "w:type");
|
|
16846
|
+
if (size !== void 0) {
|
|
16847
|
+
margins[side] = size;
|
|
16848
|
+
if (type && !marginUnitType) marginUnitType = type;
|
|
16849
|
+
}
|
|
16850
|
+
}
|
|
16851
|
+
}
|
|
16852
|
+
if (marginUnitType) margins.marginUnitType = marginUnitType;
|
|
16853
|
+
if (Object.keys(margins).length > 0) opts.margins = margins;
|
|
16854
|
+
}
|
|
17398
16855
|
const textDirection = findChild(el, "w:textDirection");
|
|
17399
16856
|
if (textDirection) {
|
|
17400
16857
|
const val = attr(textDirection, "w:val");
|
|
@@ -17538,10 +16995,15 @@ function parseSectionProperties(el, ctx) {
|
|
|
17538
16995
|
const page = {};
|
|
17539
16996
|
const size = {};
|
|
17540
16997
|
const w = attrNum(pgSz, "w:w");
|
|
17541
|
-
if (w !== void 0) size.width = w;
|
|
17542
16998
|
const h = attrNum(pgSz, "w:h");
|
|
17543
|
-
if (h !== void 0) size.height = h;
|
|
17544
16999
|
const orient = attr(pgSz, "w:orient");
|
|
17000
|
+
if (orient === "landscape" && w !== void 0 && h !== void 0) {
|
|
17001
|
+
size.width = h;
|
|
17002
|
+
size.height = w;
|
|
17003
|
+
} else {
|
|
17004
|
+
if (w !== void 0) size.width = w;
|
|
17005
|
+
if (h !== void 0) size.height = h;
|
|
17006
|
+
}
|
|
17545
17007
|
if (orient) size.orientation = orient;
|
|
17546
17008
|
if (Object.keys(size).length > 0) page.size = size;
|
|
17547
17009
|
const pgMar = findChild(el, "w:pgMar");
|
|
@@ -17612,8 +17074,8 @@ function parseSectionProperties(el, ctx) {
|
|
|
17612
17074
|
const lnNumType = findChild(el, "w:lnNumType");
|
|
17613
17075
|
if (lnNumType) {
|
|
17614
17076
|
const lineNumbers = {};
|
|
17615
|
-
const
|
|
17616
|
-
if (
|
|
17077
|
+
const countBy = attrNum(lnNumType, "w:countBy");
|
|
17078
|
+
if (countBy !== void 0) lineNumbers.countBy = countBy;
|
|
17617
17079
|
const start = attrNum(lnNumType, "w:start");
|
|
17618
17080
|
if (start !== void 0) lineNumbers.start = start;
|
|
17619
17081
|
const restart = attr(lnNumType, "w:restart");
|
|
@@ -17622,6 +17084,41 @@ function parseSectionProperties(el, ctx) {
|
|
|
17622
17084
|
if (distance !== void 0) lineNumbers.distance = distance;
|
|
17623
17085
|
if (Object.keys(lineNumbers).length > 0) opts.lineNumbers = lineNumbers;
|
|
17624
17086
|
}
|
|
17087
|
+
const pgBorders = findChild(el, "w:pgBorders");
|
|
17088
|
+
if (pgBorders) {
|
|
17089
|
+
const borders = {};
|
|
17090
|
+
for (const side of [
|
|
17091
|
+
"top",
|
|
17092
|
+
"left",
|
|
17093
|
+
"bottom",
|
|
17094
|
+
"right"
|
|
17095
|
+
]) {
|
|
17096
|
+
const sideEl = findChild(pgBorders, `w:${side}`);
|
|
17097
|
+
if (sideEl) {
|
|
17098
|
+
const b = {};
|
|
17099
|
+
const val = attr(sideEl, "w:val");
|
|
17100
|
+
if (val) b.style = val;
|
|
17101
|
+
const color = attr(sideEl, "w:color");
|
|
17102
|
+
if (color) b.color = color;
|
|
17103
|
+
const sz = attrNum(sideEl, "w:sz");
|
|
17104
|
+
if (sz !== void 0) b.size = sz;
|
|
17105
|
+
const space = attrNum(sideEl, "w:space");
|
|
17106
|
+
if (space !== void 0) b.space = space;
|
|
17107
|
+
borders[side] = b;
|
|
17108
|
+
}
|
|
17109
|
+
}
|
|
17110
|
+
const display = attr(pgBorders, "w:display");
|
|
17111
|
+
if (display) borders.display = display;
|
|
17112
|
+
const offsetFrom = attr(pgBorders, "w:offsetFrom");
|
|
17113
|
+
if (offsetFrom) borders.offsetFrom = offsetFrom;
|
|
17114
|
+
const zOrder = attr(pgBorders, "w:zOrder");
|
|
17115
|
+
if (zOrder) borders.zOrder = zOrder;
|
|
17116
|
+
if (Object.keys(borders).length > 0) {
|
|
17117
|
+
const page = opts.page ?? {};
|
|
17118
|
+
page.borders = borders;
|
|
17119
|
+
opts.page = page;
|
|
17120
|
+
}
|
|
17121
|
+
}
|
|
17625
17122
|
const vAlign = findChild(el, "w:vAlign");
|
|
17626
17123
|
if (vAlign) {
|
|
17627
17124
|
const val = attr(vAlign, "w:val");
|
|
@@ -17672,18 +17169,6 @@ function parseHeaderFooterRef(rId, ctx) {
|
|
|
17672
17169
|
function parseSectionChild(el, ctx) {
|
|
17673
17170
|
switch (el.name) {
|
|
17674
17171
|
case "w:p": {
|
|
17675
|
-
const drawing = findDeepElement(el, "w:drawing");
|
|
17676
|
-
if (drawing) {
|
|
17677
|
-
const drawingChild = parseDrawingRun(drawing, ctx);
|
|
17678
|
-
if (drawingChild) {
|
|
17679
|
-
const paraOpts = parseParagraph(el, ctx);
|
|
17680
|
-
const existingChildren = paraOpts.children ?? [];
|
|
17681
|
-
return { paragraph: {
|
|
17682
|
-
...paraOpts,
|
|
17683
|
-
children: [...existingChildren ?? [], drawingChild]
|
|
17684
|
-
} };
|
|
17685
|
-
}
|
|
17686
|
-
}
|
|
17687
17172
|
const pict = findChild(el, "w:pict");
|
|
17688
17173
|
if (pict) {
|
|
17689
17174
|
if (findDeepElement(pict, "v:textbox")) return { textbox: parseTextbox(pict, ctx) };
|
|
@@ -17750,7 +17235,8 @@ function parseBody(body, ctx) {
|
|
|
17750
17235
|
let start = 0;
|
|
17751
17236
|
for (let i = 0; i < boundaries.length; i++) {
|
|
17752
17237
|
const boundary = boundaries[i];
|
|
17753
|
-
const
|
|
17238
|
+
const endIdx = i < boundaries.length - 1 ? Math.max(start, boundary.index - 1) : boundary.index;
|
|
17239
|
+
const sectionElements = bodyChildren.slice(start, endIdx);
|
|
17754
17240
|
const parsedProps = parseSectionProperties(boundary.sectPr, ctx);
|
|
17755
17241
|
const rawProps = parsedProps;
|
|
17756
17242
|
const parsedHeaders = rawProps.parsedHeaders;
|
|
@@ -17841,6 +17327,7 @@ function parseNumberingDefinitions(el) {
|
|
|
17841
17327
|
const levelOpts = parseLevel(child);
|
|
17842
17328
|
if (levelOpts) levels.push(levelOpts);
|
|
17843
17329
|
}
|
|
17330
|
+
if (levels.length > 0 && levels.every((l) => l.format === "bullet")) continue;
|
|
17844
17331
|
if (levels.length > 0) configs.push({
|
|
17845
17332
|
reference: `list_${numId}`,
|
|
17846
17333
|
levels
|
|
@@ -17941,7 +17428,11 @@ function parseLevel(el) {
|
|
|
17941
17428
|
function parseSettings(el) {
|
|
17942
17429
|
if (!el) return {};
|
|
17943
17430
|
const opts = {};
|
|
17944
|
-
|
|
17431
|
+
const eohEl = findChild(el, "w:evenAndOddHeaders");
|
|
17432
|
+
if (eohEl) {
|
|
17433
|
+
const val = attr(eohEl, "w:val");
|
|
17434
|
+
opts.evenAndOddHeaderAndFooters = val !== "false" && val !== "0" && val !== "off";
|
|
17435
|
+
}
|
|
17945
17436
|
const viewEl = findChild(el, "w:view");
|
|
17946
17437
|
if (viewEl) {
|
|
17947
17438
|
const val = attr(viewEl, "w:val");
|
|
@@ -17993,15 +17484,6 @@ function parseSettings(el) {
|
|
|
17993
17484
|
}
|
|
17994
17485
|
if (vars.length > 0) opts.docVars = vars;
|
|
17995
17486
|
}
|
|
17996
|
-
const bgEl = findChild(el, "w:background");
|
|
17997
|
-
if (bgEl) {
|
|
17998
|
-
const bg = {};
|
|
17999
|
-
const color = attr(bgEl, "w:color");
|
|
18000
|
-
if (color) bg.color = color;
|
|
18001
|
-
const themeColor = attr(bgEl, "w:themeColor");
|
|
18002
|
-
if (themeColor) bg.themeColor = themeColor;
|
|
18003
|
-
if (Object.keys(bg).length > 0) opts.background = bg;
|
|
18004
|
-
}
|
|
18005
17487
|
const cscEl = findChild(el, "w:characterSpacingControl");
|
|
18006
17488
|
if (cscEl) {
|
|
18007
17489
|
const val = attr(cscEl, "w:val");
|
|
@@ -18052,8 +17534,30 @@ function buildNumberingCache(docx) {
|
|
|
18052
17534
|
}
|
|
18053
17535
|
return cache;
|
|
18054
17536
|
}
|
|
17537
|
+
/** Style IDs generated by DefaultStylesFactory — skip these during parsing. */
|
|
17538
|
+
const BUILTIN_STYLE_IDS = new Set([
|
|
17539
|
+
"Title",
|
|
17540
|
+
"Heading1",
|
|
17541
|
+
"Heading2",
|
|
17542
|
+
"Heading3",
|
|
17543
|
+
"Heading4",
|
|
17544
|
+
"Heading5",
|
|
17545
|
+
"Heading6",
|
|
17546
|
+
"Strong",
|
|
17547
|
+
"ListParagraph",
|
|
17548
|
+
"Hyperlink",
|
|
17549
|
+
"FootnoteText",
|
|
17550
|
+
"FootnoteTextChar",
|
|
17551
|
+
"EndnoteText",
|
|
17552
|
+
"EndnoteTextChar",
|
|
17553
|
+
"FootnoteReference",
|
|
17554
|
+
"EndnoteReference"
|
|
17555
|
+
]);
|
|
18055
17556
|
/**
|
|
18056
17557
|
* Parse w:styles element into StylesOptions.
|
|
17558
|
+
*
|
|
17559
|
+
* Skips built-in styles that DefaultStylesFactory already generates,
|
|
17560
|
+
* keeping only user-defined custom styles for round-trip fidelity.
|
|
18057
17561
|
*/
|
|
18058
17562
|
function parseStyleDefinitions(el, ctx) {
|
|
18059
17563
|
const opts = {};
|
|
@@ -18065,6 +17569,8 @@ function parseStyleDefinitions(el, ctx) {
|
|
|
18065
17569
|
} else if (child.name === "w:style") {
|
|
18066
17570
|
const styleOpts = parseStyleElement(child, ctx);
|
|
18067
17571
|
if (!styleOpts) continue;
|
|
17572
|
+
const styleId = styleOpts.id;
|
|
17573
|
+
if (styleId && BUILTIN_STYLE_IDS.has(styleId)) continue;
|
|
18068
17574
|
const type = styleOpts._type;
|
|
18069
17575
|
delete styleOpts._type;
|
|
18070
17576
|
if (type === "paragraph") paragraphStyles.push(styleOpts);
|
|
@@ -18232,6 +17738,12 @@ function parseDocument(data) {
|
|
|
18232
17738
|
const docx = parseDocx(data);
|
|
18233
17739
|
const ctx = new ParseContext(docx, buildStyleCache(docx), buildNumberingCache(docx));
|
|
18234
17740
|
const opts = { sections: parseBody(docx.body, ctx) };
|
|
17741
|
+
if (docx.background) {
|
|
17742
|
+
const bg = {};
|
|
17743
|
+
const color = attr(docx.background, "w:color");
|
|
17744
|
+
if (color) bg.color = color;
|
|
17745
|
+
if (Object.keys(bg).length > 0) opts.background = bg;
|
|
17746
|
+
}
|
|
18235
17747
|
if (docx.coreProps) {
|
|
18236
17748
|
const corePropsEl = docx.doc.get(docx.coreProps);
|
|
18237
17749
|
if (corePropsEl) {
|
|
@@ -18294,6 +17806,7 @@ function parseDocx(data) {
|
|
|
18294
17806
|
if (!documentEl) throw new Error("word/document.xml not found");
|
|
18295
17807
|
const body = documentEl.elements?.find((e) => e.name === "w:body");
|
|
18296
17808
|
if (!body) throw new Error("w:body not found in word/document.xml");
|
|
17809
|
+
const background = documentEl.elements?.find((e) => e.name === "w:background");
|
|
18297
17810
|
const styles = doc.get("word/styles.xml");
|
|
18298
17811
|
const numbering = doc.get("word/numbering.xml");
|
|
18299
17812
|
const settings = doc.get("word/settings.xml");
|
|
@@ -18304,6 +17817,7 @@ function parseDocx(data) {
|
|
|
18304
17817
|
return {
|
|
18305
17818
|
doc,
|
|
18306
17819
|
body,
|
|
17820
|
+
background,
|
|
18307
17821
|
styles,
|
|
18308
17822
|
numbering,
|
|
18309
17823
|
settings,
|