@office-open/docx 0.6.8 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -20
- package/dist/index.d.mts +5 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +49 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- /package/dist/{chunk-090QGkrx.mjs → chunk-DHfcOUro.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as __toCommonJS, n as __exportAll, r as __reExport, t as __esmMin } from "./chunk-
|
|
2
|
-
import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, DOCX_NS, EMPTY_OBJECT, EmptyElement, Formatter, Formatter as Formatter$1, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, OoxmlMimeType, RawPassthrough, Relationships, TargetModeType, XmlComponent,
|
|
1
|
+
import { i as __toCommonJS, n as __exportAll, r as __reExport, t as __esmMin } from "./chunk-DHfcOUro.mjs";
|
|
2
|
+
import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, DOCX_NS, EMPTY_OBJECT, EmptyElement, Formatter, Formatter as Formatter$1, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, OoxmlMimeType, RawPassthrough, Relationships, TargetModeType, XmlComponent, 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 { attr, attrBool, attrNum, children, colorAttr, findChild, findDeep, js2xml, textOf, xml, xml2js } from "@office-open/xml";
|
|
4
4
|
import { toUint8Array } from "undio";
|
|
5
5
|
import { PresetGeometry, buildFill, createBlipFill, createCustomGeometry, createEffectDag, createEffectList, createOutline, createScene3D, createShape3D, createTransform2D, extractBlipFillMedia } from "@office-open/core/drawingml";
|
|
@@ -1888,7 +1888,7 @@ var createTextBoxContent;
|
|
|
1888
1888
|
var init_text_box_content = __esmMin((() => {
|
|
1889
1889
|
init_xml_components();
|
|
1890
1890
|
createTextBoxContent = (children) => new BuilderElement({
|
|
1891
|
-
children
|
|
1891
|
+
children,
|
|
1892
1892
|
name: "wps:txbxContent"
|
|
1893
1893
|
});
|
|
1894
1894
|
}));
|
|
@@ -1991,9 +1991,7 @@ var init_hyperlink = __esmMin((() => {
|
|
|
1991
1991
|
if (props.tooltip !== void 0) attr["w:tooltip"] = props.tooltip;
|
|
1992
1992
|
if (props.tgtFrame !== void 0) attr["w:tgtFrame"] = props.tgtFrame;
|
|
1993
1993
|
this.root.push({ _attr: attr });
|
|
1994
|
-
children.
|
|
1995
|
-
this.root.push(child);
|
|
1996
|
-
});
|
|
1994
|
+
for (const child of children) this.root.push(child);
|
|
1997
1995
|
}
|
|
1998
1996
|
};
|
|
1999
1997
|
InternalHyperlink = class extends ConcreteHyperlink {
|
|
@@ -2005,6 +2003,7 @@ var init_hyperlink = __esmMin((() => {
|
|
|
2005
2003
|
}
|
|
2006
2004
|
};
|
|
2007
2005
|
ExternalHyperlink = class extends XmlComponent {
|
|
2006
|
+
options;
|
|
2008
2007
|
constructor(options) {
|
|
2009
2008
|
super("w:externalHyperlink");
|
|
2010
2009
|
this.options = options;
|
|
@@ -3214,10 +3213,10 @@ var init_wpg_group_run = __esmMin((() => {
|
|
|
3214
3213
|
this.extraChildren.push(drawing);
|
|
3215
3214
|
}
|
|
3216
3215
|
prepForXml(context) {
|
|
3217
|
-
this.mediaDatas
|
|
3216
|
+
for (const child of this.mediaDatas) {
|
|
3218
3217
|
context.file.media.addImage(child.fileName, child);
|
|
3219
3218
|
if (child.type === "svg") context.file.media.addImage(child.fallback.fileName, child.fallback);
|
|
3220
|
-
}
|
|
3219
|
+
}
|
|
3221
3220
|
return super.prepForXml(context);
|
|
3222
3221
|
}
|
|
3223
3222
|
};
|
|
@@ -3463,6 +3462,7 @@ var init_font_wrapper = __esmMin((() => {
|
|
|
3463
3462
|
init_convenience_functions();
|
|
3464
3463
|
init_font_table();
|
|
3465
3464
|
FontWrapper = class {
|
|
3465
|
+
options;
|
|
3466
3466
|
fontTable;
|
|
3467
3467
|
relationships;
|
|
3468
3468
|
fontOptionsWithKey = [];
|
|
@@ -8246,12 +8246,13 @@ var init_table_row$1 = __esmMin((() => {
|
|
|
8246
8246
|
init_table_property_exceptions();
|
|
8247
8247
|
init_table_row_properties();
|
|
8248
8248
|
TableRow = class extends BaseXmlComponent {
|
|
8249
|
+
options;
|
|
8249
8250
|
extraCells = [];
|
|
8250
8251
|
coercedChildren;
|
|
8251
8252
|
constructor(options) {
|
|
8252
8253
|
super("w:tr");
|
|
8253
8254
|
this.options = options;
|
|
8254
|
-
this.coercedChildren = options.
|
|
8255
|
+
this.coercedChildren = options.cells.map((child) => child instanceof TableCell || child instanceof StructuredDocumentTagCell || child instanceof StructuredDocumentTagRow ? child : new TableCell(child));
|
|
8255
8256
|
}
|
|
8256
8257
|
get cellCount() {
|
|
8257
8258
|
return this.coercedChildren.length;
|
|
@@ -8470,6 +8471,7 @@ var init_table_cell = __esmMin((() => {
|
|
|
8470
8471
|
init_xml_components();
|
|
8471
8472
|
init_table_cell_properties();
|
|
8472
8473
|
TableCell = class extends BaseXmlComponent {
|
|
8474
|
+
options;
|
|
8473
8475
|
constructor(options) {
|
|
8474
8476
|
super("w:tc");
|
|
8475
8477
|
this.options = options;
|
|
@@ -8570,11 +8572,11 @@ var init_table = __esmMin((() => {
|
|
|
8570
8572
|
this.options = options;
|
|
8571
8573
|
this.rows = options.rows.map((row) => row instanceof TableRow || row instanceof StructuredDocumentTagRow ? row : new TableRow(row));
|
|
8572
8574
|
this.columnWidths = options.columnWidths ?? Array(Math.max(...this.rows.map((row) => row.cellCount))).fill(100);
|
|
8573
|
-
this.rows.
|
|
8574
|
-
|
|
8575
|
-
if (!(row instanceof TableRow))
|
|
8575
|
+
for (let rowIndex = 0; rowIndex < this.rows.length - 1; rowIndex++) {
|
|
8576
|
+
const row = this.rows[rowIndex];
|
|
8577
|
+
if (!(row instanceof TableRow)) continue;
|
|
8576
8578
|
let columnIndex = 0;
|
|
8577
|
-
row.cells
|
|
8579
|
+
for (const cell of row.cells) {
|
|
8578
8580
|
if (cell.options.rowSpan && cell.options.rowSpan > 1) {
|
|
8579
8581
|
const nextRow = this.rows[rowIndex + 1];
|
|
8580
8582
|
if (nextRow instanceof TableRow) {
|
|
@@ -8589,8 +8591,8 @@ var init_table = __esmMin((() => {
|
|
|
8589
8591
|
}
|
|
8590
8592
|
}
|
|
8591
8593
|
columnIndex += cell.options.columnSpan || 1;
|
|
8592
|
-
}
|
|
8593
|
-
}
|
|
8594
|
+
}
|
|
8595
|
+
}
|
|
8594
8596
|
}
|
|
8595
8597
|
toXml(context) {
|
|
8596
8598
|
const parts = [];
|
|
@@ -11007,7 +11009,7 @@ init_relationships();
|
|
|
11007
11009
|
* const footerWrapper = new FooterWrapper(media, 1);
|
|
11008
11010
|
* footerWrapper.add(new Paragraph("Page Footer"));
|
|
11009
11011
|
* footerWrapper.add(new Table({
|
|
11010
|
-
* rows: [new TableRow({
|
|
11012
|
+
* rows: [new TableRow({ cells: [new TableCell({ children: [new Paragraph("Cell")] })] })],
|
|
11011
11013
|
* }));
|
|
11012
11014
|
* ```
|
|
11013
11015
|
*/
|
|
@@ -11375,7 +11377,7 @@ init_relationships();
|
|
|
11375
11377
|
* const headerWrapper = new HeaderWrapper(media, 1);
|
|
11376
11378
|
* headerWrapper.add(new Paragraph("Page Header"));
|
|
11377
11379
|
* headerWrapper.add(new Table({
|
|
11378
|
-
* rows: [new TableRow({
|
|
11380
|
+
* rows: [new TableRow({ cells: [new TableCell({ children: [new Paragraph("Cell")] })] })],
|
|
11379
11381
|
* }));
|
|
11380
11382
|
* ```
|
|
11381
11383
|
*/
|
|
@@ -14524,7 +14526,7 @@ var Compiler = class {
|
|
|
14524
14526
|
* @param overrides - Optional custom XML file overrides
|
|
14525
14527
|
* @returns A Zippable object mapping file paths to their content
|
|
14526
14528
|
*/
|
|
14527
|
-
compile(file, overrides = []) {
|
|
14529
|
+
compile(file, overrides = [], mediaLevel = 0) {
|
|
14528
14530
|
const files = {};
|
|
14529
14531
|
const headerFormattedViews = /* @__PURE__ */ new Map();
|
|
14530
14532
|
const footerFormattedViews = /* @__PURE__ */ new Map();
|
|
@@ -14537,8 +14539,8 @@ var Compiler = class {
|
|
|
14537
14539
|
}
|
|
14538
14540
|
for (const subFile of overrides) files[subFile.path] = typeof subFile.data === "string" ? encoder$1.encode(subFile.data) : subFile.data;
|
|
14539
14541
|
for (const mediaData of file.media.array) {
|
|
14540
|
-
files[`word/media/${mediaData.fileName}`] = [toUint8Array(mediaData.data), { level:
|
|
14541
|
-
if (mediaData.type === "svg") files[`word/media/${mediaData.fallback.fileName}`] = [toUint8Array(mediaData.fallback.data), { level:
|
|
14542
|
+
files[`word/media/${mediaData.fileName}`] = [toUint8Array(mediaData.data), { level: mediaLevel }];
|
|
14543
|
+
if (mediaData.type === "svg") files[`word/media/${mediaData.fallback.fileName}`] = [toUint8Array(mediaData.fallback.data), { level: mediaLevel }];
|
|
14542
14544
|
}
|
|
14543
14545
|
for (const { data: buffer, name, fontKey } of file.fontTable.fontOptionsWithKey) {
|
|
14544
14546
|
const [nameWithoutExtension] = name.split(".");
|
|
@@ -14571,14 +14573,14 @@ var Compiler = class {
|
|
|
14571
14573
|
path: "docProps/app.xml"
|
|
14572
14574
|
},
|
|
14573
14575
|
Comments: {
|
|
14574
|
-
data:
|
|
14576
|
+
data: (() => {
|
|
14577
|
+
return replaceNumberingPlaceholders(commentMediaDatas.length > 0 ? replaceImagePlaceholders(commentXmlData, commentMediaDatas, commentRelationshipCount, "rId") : commentXmlData, file.numbering.concreteNumbering);
|
|
14578
|
+
})(),
|
|
14575
14579
|
path: "word/comments.xml"
|
|
14576
14580
|
},
|
|
14577
14581
|
CommentsRelationships: {
|
|
14578
14582
|
data: (() => {
|
|
14579
|
-
commentMediaDatas.
|
|
14580
|
-
file.comments.relationships.addRelationship(commentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14581
|
-
});
|
|
14583
|
+
for (let i = 0; i < commentMediaDatas.length; i++) file.comments.relationships.addRelationship(commentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${commentMediaDatas[i].fileName}`);
|
|
14582
14584
|
return this.formatter.formatToXml(file.comments.relationships, mkCtx({
|
|
14583
14585
|
relationships: file.comments.relationships,
|
|
14584
14586
|
view: file.comments
|
|
@@ -14588,16 +14590,14 @@ var Compiler = class {
|
|
|
14588
14590
|
},
|
|
14589
14591
|
ContentTypes: {
|
|
14590
14592
|
data: (() => {
|
|
14591
|
-
file.charts.array.
|
|
14592
|
-
|
|
14593
|
-
});
|
|
14594
|
-
file.smartArts.array.forEach((_, i) => {
|
|
14593
|
+
for (let i = 0; i < file.charts.array.length; i++) file.contentTypes.addChart(i + 1);
|
|
14594
|
+
for (let i = 0; i < file.smartArts.array.length; i++) {
|
|
14595
14595
|
file.contentTypes.addDiagramData(i + 1);
|
|
14596
14596
|
file.contentTypes.addDiagramLayout(i + 1);
|
|
14597
14597
|
file.contentTypes.addDiagramStyle(i + 1);
|
|
14598
14598
|
file.contentTypes.addDiagramColors(i + 1);
|
|
14599
14599
|
file.contentTypes.addDiagramDrawing(i + 1);
|
|
14600
|
-
}
|
|
14600
|
+
}
|
|
14601
14601
|
return this.formatter.formatToXml(file.contentTypes, mkCtx(file.document));
|
|
14602
14602
|
})(),
|
|
14603
14603
|
path: "[Content_Types].xml"
|
|
@@ -14635,18 +14635,18 @@ var Compiler = class {
|
|
|
14635
14635
|
path: "word/fontTable.xml"
|
|
14636
14636
|
},
|
|
14637
14637
|
FontTableRelationships: {
|
|
14638
|
-
data: this.formatter.formatToXml(file.fontTable.relationships, mkCtx(file.document)),
|
|
14638
|
+
data: (() => this.formatter.formatToXml(file.fontTable.relationships, mkCtx(file.document)))(),
|
|
14639
14639
|
path: "word/_rels/fontTable.xml.rels"
|
|
14640
14640
|
},
|
|
14641
14641
|
FootNotes: {
|
|
14642
|
-
data:
|
|
14642
|
+
data: (() => {
|
|
14643
|
+
return replaceNumberingPlaceholders(footnoteMediaDatas.length > 0 ? replaceImagePlaceholders(footnoteXmlData, footnoteMediaDatas, footnoteRelationshipCount, "rId") : footnoteXmlData, file.numbering.concreteNumbering);
|
|
14644
|
+
})(),
|
|
14643
14645
|
path: "word/footnotes.xml"
|
|
14644
14646
|
},
|
|
14645
14647
|
FootNotesRelationships: {
|
|
14646
14648
|
data: (() => {
|
|
14647
|
-
footnoteMediaDatas.
|
|
14648
|
-
file.footNotes.relationships.addRelationship(footnoteRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14649
|
-
});
|
|
14649
|
+
for (let i = 0; i < footnoteMediaDatas.length; i++) file.footNotes.relationships.addRelationship(footnoteRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${footnoteMediaDatas[i].fileName}`);
|
|
14650
14650
|
return this.formatter.formatToXml(file.footNotes.relationships, mkCtx(file.footNotes));
|
|
14651
14651
|
})(),
|
|
14652
14652
|
path: "word/_rels/footnotes.xml.rels"
|
|
@@ -14654,9 +14654,8 @@ var Compiler = class {
|
|
|
14654
14654
|
FooterRelationships: file.footers.map((footerWrapper, index) => {
|
|
14655
14655
|
const xmlData = this.formatter.formatToXml(footerWrapper.view, mkCtx(footerWrapper));
|
|
14656
14656
|
footerFormattedViews.set(index, xmlData);
|
|
14657
|
-
getReferencedMedia(xmlData, file.media.array)
|
|
14658
|
-
|
|
14659
|
-
});
|
|
14657
|
+
const mediaDatas = getReferencedMedia(xmlData, file.media.array);
|
|
14658
|
+
for (let i = 0; i < mediaDatas.length; i++) footerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaDatas[i].fileName}`);
|
|
14660
14659
|
return {
|
|
14661
14660
|
data: this.formatter.formatToXml(footerWrapper.relationships, mkCtx(footerWrapper)),
|
|
14662
14661
|
path: `word/_rels/footer${index + 1}.xml.rels`
|
|
@@ -14673,9 +14672,8 @@ var Compiler = class {
|
|
|
14673
14672
|
HeaderRelationships: file.headers.map((headerWrapper, index) => {
|
|
14674
14673
|
const xmlData = this.formatter.formatToXml(headerWrapper.view, mkCtx(headerWrapper));
|
|
14675
14674
|
headerFormattedViews.set(index, xmlData);
|
|
14676
|
-
getReferencedMedia(xmlData, file.media.array)
|
|
14677
|
-
|
|
14678
|
-
});
|
|
14675
|
+
const mediaDatas = getReferencedMedia(xmlData, file.media.array);
|
|
14676
|
+
for (let i = 0; i < mediaDatas.length; i++) headerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaDatas[i].fileName}`);
|
|
14679
14677
|
return {
|
|
14680
14678
|
data: this.formatter.formatToXml(headerWrapper.relationships, mkCtx(headerWrapper)),
|
|
14681
14679
|
path: `word/_rels/header${index + 1}.xml.rels`
|
|
@@ -14699,13 +14697,9 @@ var Compiler = class {
|
|
|
14699
14697
|
},
|
|
14700
14698
|
Relationships: {
|
|
14701
14699
|
data: (() => {
|
|
14702
|
-
documentMediaDatas.
|
|
14703
|
-
file.document.relationships.addRelationship(documentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
|
|
14704
|
-
});
|
|
14700
|
+
for (let i = 0; i < documentMediaDatas.length; i++) file.document.relationships.addRelationship(documentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${documentMediaDatas[i].fileName}`);
|
|
14705
14701
|
const chartOffset = documentRelationshipCount + documentMediaDatas.length;
|
|
14706
|
-
file.charts.array.
|
|
14707
|
-
file.document.relationships.addRelationship(chartOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `charts/chart${i + 1}.xml`);
|
|
14708
|
-
});
|
|
14702
|
+
for (let i = 0; i < file.charts.array.length; i++) file.document.relationships.addRelationship(chartOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `charts/chart${i + 1}.xml`);
|
|
14709
14703
|
addSmartArtRelationships(file.smartArts.array.map((s) => s.key), (id, type, target) => {
|
|
14710
14704
|
file.document.relationships.addRelationship(id, type, target);
|
|
14711
14705
|
}, documentRelationshipCount + documentMediaDatas.length + file.charts.array.length, 0, {
|
|
@@ -14722,7 +14716,9 @@ var Compiler = class {
|
|
|
14722
14716
|
path: "word/settings.xml"
|
|
14723
14717
|
},
|
|
14724
14718
|
Styles: {
|
|
14725
|
-
data:
|
|
14719
|
+
data: (() => {
|
|
14720
|
+
return replaceNumberingPlaceholders(this.formatter.formatToXml(file.styles, mkCtx(file.document)), file.numbering.concreteNumbering);
|
|
14721
|
+
})(),
|
|
14726
14722
|
path: "word/styles.xml"
|
|
14727
14723
|
},
|
|
14728
14724
|
...file.bibliography ? { Bibliography: {
|
|
@@ -14787,7 +14783,7 @@ const compiler = new Compiler();
|
|
|
14787
14783
|
* ```
|
|
14788
14784
|
*/
|
|
14789
14785
|
const Packer = createPacker({
|
|
14790
|
-
compile: (file, overrides) => compiler.compile(file, overrides),
|
|
14786
|
+
compile: (file, overrides, mediaLevel) => compiler.compile(file, overrides, mediaLevel),
|
|
14791
14787
|
mimeType: OoxmlMimeType.DOCX
|
|
14792
14788
|
});
|
|
14793
14789
|
//#endregion
|
|
@@ -15012,7 +15008,7 @@ const createRelationshipFile = () => ({
|
|
|
15012
15008
|
*
|
|
15013
15009
|
* // Use detected placeholders to create patches
|
|
15014
15010
|
* const patches = {};
|
|
15015
|
-
*
|
|
15011
|
+
* for (const key of placeholders) {
|
|
15016
15012
|
* patches[key] = {
|
|
15017
15013
|
* type: PatchType.PARAGRAPH,
|
|
15018
15014
|
* children: [new TextRun(getUserData(key))],
|
|
@@ -15028,7 +15024,7 @@ const patchDetector = async ({ data }) => {
|
|
|
15028
15024
|
if (key.startsWith("word/") && !key.endsWith(".xml.rels")) {
|
|
15029
15025
|
const json = toJson(strFromU8(value));
|
|
15030
15026
|
const { traverse } = createTraverser(DOCX_NS);
|
|
15031
|
-
traverse(json)
|
|
15027
|
+
for (const p of traverse(json)) for (const patch of findPatchKeys(p.text)) patches.add(patch);
|
|
15032
15028
|
}
|
|
15033
15029
|
}
|
|
15034
15030
|
return [...patches];
|
|
@@ -16683,6 +16679,9 @@ function findDeep$1(parent, name) {
|
|
|
16683
16679
|
//#endregion
|
|
16684
16680
|
//#region src/parse/context.ts
|
|
16685
16681
|
var ParseContext = class {
|
|
16682
|
+
docx;
|
|
16683
|
+
styleCache;
|
|
16684
|
+
numberingCache;
|
|
16686
16685
|
constructor(docx, styleCache, numberingCache) {
|
|
16687
16686
|
this.docx = docx;
|
|
16688
16687
|
this.styleCache = styleCache;
|