docx 9.1.1 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
  [![Known Vulnerabilities][snky-image]][snky-url]
15
15
  [![PRs Welcome][pr-image]][pr-url]
16
16
  [![codecov][codecov-image]][codecov-url]
17
+ [![Docx.js Editor][docxjs-editor-image]][docxjs-editor-url]
17
18
 
18
19
  <p align="center">
19
20
  <img src="https://i.imgur.com/QeL1HuU.png" alt="drawing"/>
@@ -64,6 +65,10 @@ More [here](https://github.com/dolanmiu/docx/tree/master/demo)
64
65
 
65
66
  Please refer to the [documentation at https://docx.js.org/](https://docx.js.org/) for details on how to use this library, examples and much more!
66
67
 
68
+ # Playground
69
+
70
+ Experience `docx` in action through [Docx.js Editor][docxjs-editor-url], an interactive playground where you can code and preview the results in real-time.
71
+
67
72
  # Examples
68
73
 
69
74
  Check the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples.
@@ -115,3 +120,5 @@ Made with 💖
115
120
  [patreon-url]: https://www.patreon.com/dolanmiu
116
121
  [browserstack-image]: https://user-images.githubusercontent.com/2917613/54233552-128e9d00-4505-11e9-88fb-025a4e04007c.png
117
122
  [browserstack-url]: https://www.browserstack.com
123
+ [docxjs-editor-image]: https://img.shields.io/badge/Docx.js%20Editor-2b579a.svg?style=flat&amp;logo=javascript&amp;logoColor=white
124
+ [docxjs-editor-url]: https://docxjs-editor.vercel.app/
package/dist/index.cjs CHANGED
@@ -13017,7 +13017,7 @@ class SpacingAttributes extends XmlAttributeComponent {
13017
13017
  line: "w:line",
13018
13018
  lineRule: "w:lineRule",
13019
13019
  beforeAutoSpacing: "w:beforeAutospacing",
13020
- afterAutoSpacing: "w:afterAutoSpacing"
13020
+ afterAutoSpacing: "w:afterAutospacing"
13021
13021
  });
13022
13022
  }
13023
13023
  }
@@ -15310,10 +15310,10 @@ const createFont = ({
15310
15310
  // http://www.datypic.com/sc/ooxml/e-w_charset-1.html
15311
15311
  ...charset ? [createStringElement("w:charset", charset)] : [],
15312
15312
  // http://www.datypic.com/sc/ooxml/e-w_family-1.html
15313
- ...family ? [createStringElement("w:family", family)] : [],
15313
+ ...[createStringElement("w:family", family)],
15314
15314
  // http://www.datypic.com/sc/ooxml/e-w_notTrueType-1.html
15315
15315
  ...notTrueType ? [new OnOffElement("w:notTrueType", notTrueType)] : [],
15316
- ...pitch ? [createStringElement("w:pitch", pitch)] : [],
15316
+ ...[createStringElement("w:pitch", pitch)],
15317
15317
  // http://www.datypic.com/sc/ooxml/e-w_sig-1.html
15318
15318
  ...sig ? [
15319
15319
  new BuilderElement({
@@ -20200,7 +20200,7 @@ class Compiler {
20200
20200
  this.imageReplacer = new ImageReplacer();
20201
20201
  this.numberingReplacer = new NumberingReplacer();
20202
20202
  }
20203
- compile(file, prettifyXml) {
20203
+ compile(file, prettifyXml, overrides = []) {
20204
20204
  const zip = new JSZip();
20205
20205
  const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
20206
20206
  const map = new Map(Object.entries(xmlifiedFileMapping));
@@ -20213,6 +20213,9 @@ class Compiler {
20213
20213
  zip.file(obj.path, obj.data);
20214
20214
  }
20215
20215
  }
20216
+ for (const subFile of overrides) {
20217
+ zip.file(subFile.path, subFile.data);
20218
+ }
20216
20219
  for (const data of file.Media.Array) {
20217
20220
  if (data.type !== "svg") {
20218
20221
  zip.file(`word/media/${data.fileName}`, data.data);
@@ -20635,54 +20638,36 @@ const PrettifyType = {
20635
20638
  WITH_TAB: " "
20636
20639
  };
20637
20640
  const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
20638
- class Packer {
20639
- static toString(file, prettify) {
20640
- return __async(this, null, function* () {
20641
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20642
- const zipData = yield zip.generateAsync({
20643
- type: "string",
20641
+ const _Packer = class _Packer {
20642
+ // eslint-disable-next-line require-await
20643
+ static pack(_0, _12, _2) {
20644
+ return __async(this, arguments, function* (file, type2, prettify, overrides = []) {
20645
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20646
+ return zip.generateAsync({
20647
+ type: type2,
20644
20648
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20645
20649
  compression: "DEFLATE"
20646
20650
  });
20647
- return zipData;
20648
20651
  });
20649
20652
  }
20650
- static toBuffer(file, prettify) {
20651
- return __async(this, null, function* () {
20652
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20653
- const zipData = yield zip.generateAsync({
20654
- type: "nodebuffer",
20655
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20656
- compression: "DEFLATE"
20657
- });
20658
- return zipData;
20659
- });
20653
+ static toString(file, prettify, overrides = []) {
20654
+ return _Packer.pack(file, "string", prettify, overrides);
20660
20655
  }
20661
- static toBase64String(file, prettify) {
20662
- return __async(this, null, function* () {
20663
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20664
- const zipData = yield zip.generateAsync({
20665
- type: "base64",
20666
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20667
- compression: "DEFLATE"
20668
- });
20669
- return zipData;
20670
- });
20656
+ static toBuffer(file, prettify, overrides = []) {
20657
+ return _Packer.pack(file, "nodebuffer", prettify, overrides);
20671
20658
  }
20672
- static toBlob(file, prettify) {
20673
- return __async(this, null, function* () {
20674
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20675
- const zipData = yield zip.generateAsync({
20676
- type: "blob",
20677
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20678
- compression: "DEFLATE"
20679
- });
20680
- return zipData;
20681
- });
20659
+ static toBase64String(file, prettify, overrides = []) {
20660
+ return _Packer.pack(file, "base64", prettify, overrides);
20682
20661
  }
20683
- static toStream(file, prettify) {
20662
+ static toBlob(file, prettify, overrides = []) {
20663
+ return _Packer.pack(file, "blob", prettify, overrides);
20664
+ }
20665
+ static toArrayBuffer(file, prettify, overrides = []) {
20666
+ return _Packer.pack(file, "arraybuffer", prettify, overrides);
20667
+ }
20668
+ static toStream(file, prettify, overrides = []) {
20684
20669
  const stream = new streamBrowserifyExports.Stream();
20685
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20670
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20686
20671
  zip.generateAsync({
20687
20672
  type: "nodebuffer",
20688
20673
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
@@ -20693,8 +20678,9 @@ class Packer {
20693
20678
  });
20694
20679
  return stream;
20695
20680
  }
20696
- }
20697
- __publicField(Packer, "compiler", new Compiler());
20681
+ };
20682
+ __publicField(_Packer, "compiler", new Compiler());
20683
+ let Packer = _Packer;
20698
20684
  const formatter$1 = new Formatter();
20699
20685
  const toJson = (xmlData) => {
20700
20686
  const xmlObj = libExports.xml2js(xmlData, { compact: false, captureSpacesBetweenElements: true });
package/dist/index.d.cts CHANGED
@@ -1352,7 +1352,6 @@ export declare type IParagraphOptions = {
1352
1352
  } & IParagraphPropertiesOptions;
1353
1353
 
1354
1354
  export declare type IParagraphPropertiesOptions = {
1355
- readonly border?: IBordersOptions;
1356
1355
  readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
1357
1356
  readonly bidirectional?: boolean;
1358
1357
  readonly pageBreakBefore?: boolean;
@@ -1361,7 +1360,6 @@ export declare type IParagraphPropertiesOptions = {
1361
1360
  readonly bullet?: {
1362
1361
  readonly level: number;
1363
1362
  };
1364
- readonly shading?: IShadingAttributesProperties;
1365
1363
  readonly widowControl?: boolean;
1366
1364
  readonly frame?: IFrameOptions;
1367
1365
  readonly suppressLineNumbers?: boolean;
@@ -1377,6 +1375,8 @@ export declare type IParagraphStyleOptions = {
1377
1375
  } & IBaseParagraphStyleOptions;
1378
1376
 
1379
1377
  export declare type IParagraphStylePropertiesOptions = {
1378
+ readonly border?: IBordersOptions;
1379
+ readonly shading?: IShadingAttributesProperties;
1380
1380
  readonly numbering?: {
1381
1381
  readonly reference: string;
1382
1382
  readonly level: number;
@@ -1387,7 +1387,7 @@ export declare type IParagraphStylePropertiesOptions = {
1387
1387
 
1388
1388
  export declare type IPatch = ParagraphPatch | FilePatch;
1389
1389
 
1390
- declare type IPropertiesOptions = {
1390
+ export declare type IPropertiesOptions = {
1391
1391
  readonly sections: readonly ISectionOptions[];
1392
1392
  readonly title?: string;
1393
1393
  readonly subject?: string;
@@ -1708,6 +1708,11 @@ export declare interface IXmlableObject extends Record<string, unknown> {
1708
1708
 
1709
1709
  export declare type IXmlAttribute = Readonly<Record<string, string | number | boolean>>;
1710
1710
 
1711
+ declare type IXmlifyedFile = {
1712
+ readonly data: string;
1713
+ readonly path: string;
1714
+ };
1715
+
1711
1716
  export declare type IXYFrameOptions = {
1712
1717
  readonly type: "absolute";
1713
1718
  readonly position: {
@@ -2137,7 +2142,7 @@ declare type OutlineSchemeSolidFill = {
2137
2142
 
2138
2143
  declare type OutlineSolidFill = OutlineRgbSolidFill | OutlineSchemeSolidFill;
2139
2144
 
2140
- declare type OutputByType = {
2145
+ export declare type OutputByType = {
2141
2146
  readonly base64: string;
2142
2147
  readonly string: string;
2143
2148
  readonly text: string;
@@ -2149,17 +2154,21 @@ declare type OutputByType = {
2149
2154
  readonly nodebuffer: Buffer;
2150
2155
  };
2151
2156
 
2157
+ export declare type OutputType = keyof OutputByType;
2158
+
2152
2159
  export declare const OverlapType: {
2153
2160
  readonly NEVER: "never";
2154
2161
  readonly OVERLAP: "overlap";
2155
2162
  };
2156
2163
 
2157
2164
  export declare class Packer {
2158
- static toString(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string>;
2159
- static toBuffer(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Buffer>;
2160
- static toBase64String(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string>;
2161
- static toBlob(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Blob>;
2162
- static toStream(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Stream;
2165
+ static pack<T extends OutputType>(file: File_2, type: T, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<OutputByType[T]>;
2166
+ static toString(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<string>;
2167
+ static toBuffer(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<Buffer>;
2168
+ static toBase64String(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<string>;
2169
+ static toBlob(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<Blob>;
2170
+ static toArrayBuffer(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<ArrayBuffer>;
2171
+ static toStream(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Stream;
2163
2172
  private static readonly compiler;
2164
2173
  }
2165
2174
 
@@ -2288,7 +2297,7 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
2288
2297
  readonly keepOriginalStyles?: boolean;
2289
2298
  };
2290
2299
 
2291
- export declare type PatchDocumentOutputType = keyof OutputByType;
2300
+ export declare type PatchDocumentOutputType = OutputType;
2292
2301
 
2293
2302
  export declare const PatchType: {
2294
2303
  readonly DOCUMENT: "file";
package/dist/index.d.ts CHANGED
@@ -1352,7 +1352,6 @@ export declare type IParagraphOptions = {
1352
1352
  } & IParagraphPropertiesOptions;
1353
1353
 
1354
1354
  export declare type IParagraphPropertiesOptions = {
1355
- readonly border?: IBordersOptions;
1356
1355
  readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
1357
1356
  readonly bidirectional?: boolean;
1358
1357
  readonly pageBreakBefore?: boolean;
@@ -1361,7 +1360,6 @@ export declare type IParagraphPropertiesOptions = {
1361
1360
  readonly bullet?: {
1362
1361
  readonly level: number;
1363
1362
  };
1364
- readonly shading?: IShadingAttributesProperties;
1365
1363
  readonly widowControl?: boolean;
1366
1364
  readonly frame?: IFrameOptions;
1367
1365
  readonly suppressLineNumbers?: boolean;
@@ -1377,6 +1375,8 @@ export declare type IParagraphStyleOptions = {
1377
1375
  } & IBaseParagraphStyleOptions;
1378
1376
 
1379
1377
  export declare type IParagraphStylePropertiesOptions = {
1378
+ readonly border?: IBordersOptions;
1379
+ readonly shading?: IShadingAttributesProperties;
1380
1380
  readonly numbering?: {
1381
1381
  readonly reference: string;
1382
1382
  readonly level: number;
@@ -1387,7 +1387,7 @@ export declare type IParagraphStylePropertiesOptions = {
1387
1387
 
1388
1388
  export declare type IPatch = ParagraphPatch | FilePatch;
1389
1389
 
1390
- declare type IPropertiesOptions = {
1390
+ export declare type IPropertiesOptions = {
1391
1391
  readonly sections: readonly ISectionOptions[];
1392
1392
  readonly title?: string;
1393
1393
  readonly subject?: string;
@@ -1708,6 +1708,11 @@ export declare interface IXmlableObject extends Record<string, unknown> {
1708
1708
 
1709
1709
  export declare type IXmlAttribute = Readonly<Record<string, string | number | boolean>>;
1710
1710
 
1711
+ declare type IXmlifyedFile = {
1712
+ readonly data: string;
1713
+ readonly path: string;
1714
+ };
1715
+
1711
1716
  export declare type IXYFrameOptions = {
1712
1717
  readonly type: "absolute";
1713
1718
  readonly position: {
@@ -2137,7 +2142,7 @@ declare type OutlineSchemeSolidFill = {
2137
2142
 
2138
2143
  declare type OutlineSolidFill = OutlineRgbSolidFill | OutlineSchemeSolidFill;
2139
2144
 
2140
- declare type OutputByType = {
2145
+ export declare type OutputByType = {
2141
2146
  readonly base64: string;
2142
2147
  readonly string: string;
2143
2148
  readonly text: string;
@@ -2149,17 +2154,21 @@ declare type OutputByType = {
2149
2154
  readonly nodebuffer: Buffer;
2150
2155
  };
2151
2156
 
2157
+ export declare type OutputType = keyof OutputByType;
2158
+
2152
2159
  export declare const OverlapType: {
2153
2160
  readonly NEVER: "never";
2154
2161
  readonly OVERLAP: "overlap";
2155
2162
  };
2156
2163
 
2157
2164
  export declare class Packer {
2158
- static toString(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string>;
2159
- static toBuffer(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Buffer>;
2160
- static toBase64String(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string>;
2161
- static toBlob(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Blob>;
2162
- static toStream(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Stream;
2165
+ static pack<T extends OutputType>(file: File_2, type: T, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<OutputByType[T]>;
2166
+ static toString(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<string>;
2167
+ static toBuffer(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<Buffer>;
2168
+ static toBase64String(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<string>;
2169
+ static toBlob(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<Blob>;
2170
+ static toArrayBuffer(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Promise<ArrayBuffer>;
2171
+ static toStream(file: File_2, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], overrides?: readonly IXmlifyedFile[]): Stream;
2163
2172
  private static readonly compiler;
2164
2173
  }
2165
2174
 
@@ -2288,7 +2297,7 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
2288
2297
  readonly keepOriginalStyles?: boolean;
2289
2298
  };
2290
2299
 
2291
- export declare type PatchDocumentOutputType = keyof OutputByType;
2300
+ export declare type PatchDocumentOutputType = OutputType;
2292
2301
 
2293
2302
  export declare const PatchType: {
2294
2303
  readonly DOCUMENT: "file";
@@ -13017,7 +13017,7 @@ var __async = (__this, __arguments, generator) => {
13017
13017
  line: "w:line",
13018
13018
  lineRule: "w:lineRule",
13019
13019
  beforeAutoSpacing: "w:beforeAutospacing",
13020
- afterAutoSpacing: "w:afterAutoSpacing"
13020
+ afterAutoSpacing: "w:afterAutospacing"
13021
13021
  });
13022
13022
  }
13023
13023
  }
@@ -15310,10 +15310,10 @@ var __async = (__this, __arguments, generator) => {
15310
15310
  // http://www.datypic.com/sc/ooxml/e-w_charset-1.html
15311
15311
  ...charset ? [createStringElement("w:charset", charset)] : [],
15312
15312
  // http://www.datypic.com/sc/ooxml/e-w_family-1.html
15313
- ...family ? [createStringElement("w:family", family)] : [],
15313
+ ...[createStringElement("w:family", family)],
15314
15314
  // http://www.datypic.com/sc/ooxml/e-w_notTrueType-1.html
15315
15315
  ...notTrueType ? [new OnOffElement("w:notTrueType", notTrueType)] : [],
15316
- ...pitch ? [createStringElement("w:pitch", pitch)] : [],
15316
+ ...[createStringElement("w:pitch", pitch)],
15317
15317
  // http://www.datypic.com/sc/ooxml/e-w_sig-1.html
15318
15318
  ...sig ? [
15319
15319
  new BuilderElement({
@@ -20200,7 +20200,7 @@ var __async = (__this, __arguments, generator) => {
20200
20200
  this.imageReplacer = new ImageReplacer();
20201
20201
  this.numberingReplacer = new NumberingReplacer();
20202
20202
  }
20203
- compile(file, prettifyXml) {
20203
+ compile(file, prettifyXml, overrides = []) {
20204
20204
  const zip = new JSZip();
20205
20205
  const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
20206
20206
  const map = new Map(Object.entries(xmlifiedFileMapping));
@@ -20213,6 +20213,9 @@ var __async = (__this, __arguments, generator) => {
20213
20213
  zip.file(obj.path, obj.data);
20214
20214
  }
20215
20215
  }
20216
+ for (const subFile of overrides) {
20217
+ zip.file(subFile.path, subFile.data);
20218
+ }
20216
20219
  for (const data of file.Media.Array) {
20217
20220
  if (data.type !== "svg") {
20218
20221
  zip.file(`word/media/${data.fileName}`, data.data);
@@ -20635,54 +20638,36 @@ var __async = (__this, __arguments, generator) => {
20635
20638
  WITH_TAB: " "
20636
20639
  };
20637
20640
  const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
20638
- class Packer {
20639
- static toString(file, prettify) {
20640
- return __async(this, null, function* () {
20641
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20642
- const zipData = yield zip.generateAsync({
20643
- type: "string",
20641
+ const _Packer = class _Packer {
20642
+ // eslint-disable-next-line require-await
20643
+ static pack(_0, _12, _2) {
20644
+ return __async(this, arguments, function* (file, type2, prettify, overrides = []) {
20645
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20646
+ return zip.generateAsync({
20647
+ type: type2,
20644
20648
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20645
20649
  compression: "DEFLATE"
20646
20650
  });
20647
- return zipData;
20648
20651
  });
20649
20652
  }
20650
- static toBuffer(file, prettify) {
20651
- return __async(this, null, function* () {
20652
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20653
- const zipData = yield zip.generateAsync({
20654
- type: "nodebuffer",
20655
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20656
- compression: "DEFLATE"
20657
- });
20658
- return zipData;
20659
- });
20653
+ static toString(file, prettify, overrides = []) {
20654
+ return _Packer.pack(file, "string", prettify, overrides);
20660
20655
  }
20661
- static toBase64String(file, prettify) {
20662
- return __async(this, null, function* () {
20663
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20664
- const zipData = yield zip.generateAsync({
20665
- type: "base64",
20666
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20667
- compression: "DEFLATE"
20668
- });
20669
- return zipData;
20670
- });
20656
+ static toBuffer(file, prettify, overrides = []) {
20657
+ return _Packer.pack(file, "nodebuffer", prettify, overrides);
20671
20658
  }
20672
- static toBlob(file, prettify) {
20673
- return __async(this, null, function* () {
20674
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20675
- const zipData = yield zip.generateAsync({
20676
- type: "blob",
20677
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20678
- compression: "DEFLATE"
20679
- });
20680
- return zipData;
20681
- });
20659
+ static toBase64String(file, prettify, overrides = []) {
20660
+ return _Packer.pack(file, "base64", prettify, overrides);
20682
20661
  }
20683
- static toStream(file, prettify) {
20662
+ static toBlob(file, prettify, overrides = []) {
20663
+ return _Packer.pack(file, "blob", prettify, overrides);
20664
+ }
20665
+ static toArrayBuffer(file, prettify, overrides = []) {
20666
+ return _Packer.pack(file, "arraybuffer", prettify, overrides);
20667
+ }
20668
+ static toStream(file, prettify, overrides = []) {
20684
20669
  const stream = new streamBrowserifyExports.Stream();
20685
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20670
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20686
20671
  zip.generateAsync({
20687
20672
  type: "nodebuffer",
20688
20673
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
@@ -20693,8 +20678,9 @@ var __async = (__this, __arguments, generator) => {
20693
20678
  });
20694
20679
  return stream;
20695
20680
  }
20696
- }
20697
- __publicField(Packer, "compiler", new Compiler());
20681
+ };
20682
+ __publicField(_Packer, "compiler", new Compiler());
20683
+ let Packer = _Packer;
20698
20684
  const formatter$1 = new Formatter();
20699
20685
  const toJson = (xmlData) => {
20700
20686
  const xmlObj = libExports.xml2js(xmlData, { compact: false, captureSpacesBetweenElements: true });
package/dist/index.mjs CHANGED
@@ -13015,7 +13015,7 @@ class SpacingAttributes extends XmlAttributeComponent {
13015
13015
  line: "w:line",
13016
13016
  lineRule: "w:lineRule",
13017
13017
  beforeAutoSpacing: "w:beforeAutospacing",
13018
- afterAutoSpacing: "w:afterAutoSpacing"
13018
+ afterAutoSpacing: "w:afterAutospacing"
13019
13019
  });
13020
13020
  }
13021
13021
  }
@@ -15308,10 +15308,10 @@ const createFont = ({
15308
15308
  // http://www.datypic.com/sc/ooxml/e-w_charset-1.html
15309
15309
  ...charset ? [createStringElement("w:charset", charset)] : [],
15310
15310
  // http://www.datypic.com/sc/ooxml/e-w_family-1.html
15311
- ...family ? [createStringElement("w:family", family)] : [],
15311
+ ...[createStringElement("w:family", family)],
15312
15312
  // http://www.datypic.com/sc/ooxml/e-w_notTrueType-1.html
15313
15313
  ...notTrueType ? [new OnOffElement("w:notTrueType", notTrueType)] : [],
15314
- ...pitch ? [createStringElement("w:pitch", pitch)] : [],
15314
+ ...[createStringElement("w:pitch", pitch)],
15315
15315
  // http://www.datypic.com/sc/ooxml/e-w_sig-1.html
15316
15316
  ...sig ? [
15317
15317
  new BuilderElement({
@@ -20198,7 +20198,7 @@ class Compiler {
20198
20198
  this.imageReplacer = new ImageReplacer();
20199
20199
  this.numberingReplacer = new NumberingReplacer();
20200
20200
  }
20201
- compile(file, prettifyXml) {
20201
+ compile(file, prettifyXml, overrides = []) {
20202
20202
  const zip = new JSZip();
20203
20203
  const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
20204
20204
  const map = new Map(Object.entries(xmlifiedFileMapping));
@@ -20211,6 +20211,9 @@ class Compiler {
20211
20211
  zip.file(obj.path, obj.data);
20212
20212
  }
20213
20213
  }
20214
+ for (const subFile of overrides) {
20215
+ zip.file(subFile.path, subFile.data);
20216
+ }
20214
20217
  for (const data of file.Media.Array) {
20215
20218
  if (data.type !== "svg") {
20216
20219
  zip.file(`word/media/${data.fileName}`, data.data);
@@ -20633,54 +20636,36 @@ const PrettifyType = {
20633
20636
  WITH_TAB: " "
20634
20637
  };
20635
20638
  const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
20636
- class Packer {
20637
- static toString(file, prettify) {
20638
- return __async(this, null, function* () {
20639
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20640
- const zipData = yield zip.generateAsync({
20641
- type: "string",
20639
+ const _Packer = class _Packer {
20640
+ // eslint-disable-next-line require-await
20641
+ static pack(_0, _12, _2) {
20642
+ return __async(this, arguments, function* (file, type2, prettify, overrides = []) {
20643
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20644
+ return zip.generateAsync({
20645
+ type: type2,
20642
20646
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20643
20647
  compression: "DEFLATE"
20644
20648
  });
20645
- return zipData;
20646
20649
  });
20647
20650
  }
20648
- static toBuffer(file, prettify) {
20649
- return __async(this, null, function* () {
20650
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20651
- const zipData = yield zip.generateAsync({
20652
- type: "nodebuffer",
20653
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20654
- compression: "DEFLATE"
20655
- });
20656
- return zipData;
20657
- });
20651
+ static toString(file, prettify, overrides = []) {
20652
+ return _Packer.pack(file, "string", prettify, overrides);
20658
20653
  }
20659
- static toBase64String(file, prettify) {
20660
- return __async(this, null, function* () {
20661
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20662
- const zipData = yield zip.generateAsync({
20663
- type: "base64",
20664
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20665
- compression: "DEFLATE"
20666
- });
20667
- return zipData;
20668
- });
20654
+ static toBuffer(file, prettify, overrides = []) {
20655
+ return _Packer.pack(file, "nodebuffer", prettify, overrides);
20669
20656
  }
20670
- static toBlob(file, prettify) {
20671
- return __async(this, null, function* () {
20672
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20673
- const zipData = yield zip.generateAsync({
20674
- type: "blob",
20675
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20676
- compression: "DEFLATE"
20677
- });
20678
- return zipData;
20679
- });
20657
+ static toBase64String(file, prettify, overrides = []) {
20658
+ return _Packer.pack(file, "base64", prettify, overrides);
20680
20659
  }
20681
- static toStream(file, prettify) {
20660
+ static toBlob(file, prettify, overrides = []) {
20661
+ return _Packer.pack(file, "blob", prettify, overrides);
20662
+ }
20663
+ static toArrayBuffer(file, prettify, overrides = []) {
20664
+ return _Packer.pack(file, "arraybuffer", prettify, overrides);
20665
+ }
20666
+ static toStream(file, prettify, overrides = []) {
20682
20667
  const stream = new streamBrowserifyExports.Stream();
20683
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20668
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20684
20669
  zip.generateAsync({
20685
20670
  type: "nodebuffer",
20686
20671
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
@@ -20691,8 +20676,9 @@ class Packer {
20691
20676
  });
20692
20677
  return stream;
20693
20678
  }
20694
- }
20695
- __publicField(Packer, "compiler", new Compiler());
20679
+ };
20680
+ __publicField(_Packer, "compiler", new Compiler());
20681
+ let Packer = _Packer;
20696
20682
  const formatter$1 = new Formatter();
20697
20683
  const toJson = (xmlData) => {
20698
20684
  const xmlObj = libExports.xml2js(xmlData, { compact: false, captureSpacesBetweenElements: true });
@@ -13019,7 +13019,7 @@ var __async = (__this, __arguments, generator) => {
13019
13019
  line: "w:line",
13020
13020
  lineRule: "w:lineRule",
13021
13021
  beforeAutoSpacing: "w:beforeAutospacing",
13022
- afterAutoSpacing: "w:afterAutoSpacing"
13022
+ afterAutoSpacing: "w:afterAutospacing"
13023
13023
  });
13024
13024
  }
13025
13025
  }
@@ -15312,10 +15312,10 @@ var __async = (__this, __arguments, generator) => {
15312
15312
  // http://www.datypic.com/sc/ooxml/e-w_charset-1.html
15313
15313
  ...charset ? [createStringElement("w:charset", charset)] : [],
15314
15314
  // http://www.datypic.com/sc/ooxml/e-w_family-1.html
15315
- ...family ? [createStringElement("w:family", family)] : [],
15315
+ ...[createStringElement("w:family", family)],
15316
15316
  // http://www.datypic.com/sc/ooxml/e-w_notTrueType-1.html
15317
15317
  ...notTrueType ? [new OnOffElement("w:notTrueType", notTrueType)] : [],
15318
- ...pitch ? [createStringElement("w:pitch", pitch)] : [],
15318
+ ...[createStringElement("w:pitch", pitch)],
15319
15319
  // http://www.datypic.com/sc/ooxml/e-w_sig-1.html
15320
15320
  ...sig ? [
15321
15321
  new BuilderElement({
@@ -20202,7 +20202,7 @@ var __async = (__this, __arguments, generator) => {
20202
20202
  this.imageReplacer = new ImageReplacer();
20203
20203
  this.numberingReplacer = new NumberingReplacer();
20204
20204
  }
20205
- compile(file, prettifyXml) {
20205
+ compile(file, prettifyXml, overrides = []) {
20206
20206
  const zip = new JSZip();
20207
20207
  const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
20208
20208
  const map = new Map(Object.entries(xmlifiedFileMapping));
@@ -20215,6 +20215,9 @@ var __async = (__this, __arguments, generator) => {
20215
20215
  zip.file(obj.path, obj.data);
20216
20216
  }
20217
20217
  }
20218
+ for (const subFile of overrides) {
20219
+ zip.file(subFile.path, subFile.data);
20220
+ }
20218
20221
  for (const data of file.Media.Array) {
20219
20222
  if (data.type !== "svg") {
20220
20223
  zip.file(`word/media/${data.fileName}`, data.data);
@@ -20637,54 +20640,36 @@ var __async = (__this, __arguments, generator) => {
20637
20640
  WITH_TAB: " "
20638
20641
  };
20639
20642
  const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
20640
- class Packer {
20641
- static toString(file, prettify) {
20642
- return __async(this, null, function* () {
20643
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20644
- const zipData = yield zip.generateAsync({
20645
- type: "string",
20643
+ const _Packer = class _Packer {
20644
+ // eslint-disable-next-line require-await
20645
+ static pack(_0, _12, _2) {
20646
+ return __async(this, arguments, function* (file, type2, prettify, overrides = []) {
20647
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20648
+ return zip.generateAsync({
20649
+ type: type2,
20646
20650
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20647
20651
  compression: "DEFLATE"
20648
20652
  });
20649
- return zipData;
20650
20653
  });
20651
20654
  }
20652
- static toBuffer(file, prettify) {
20653
- return __async(this, null, function* () {
20654
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20655
- const zipData = yield zip.generateAsync({
20656
- type: "nodebuffer",
20657
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20658
- compression: "DEFLATE"
20659
- });
20660
- return zipData;
20661
- });
20655
+ static toString(file, prettify, overrides = []) {
20656
+ return _Packer.pack(file, "string", prettify, overrides);
20662
20657
  }
20663
- static toBase64String(file, prettify) {
20664
- return __async(this, null, function* () {
20665
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20666
- const zipData = yield zip.generateAsync({
20667
- type: "base64",
20668
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20669
- compression: "DEFLATE"
20670
- });
20671
- return zipData;
20672
- });
20658
+ static toBuffer(file, prettify, overrides = []) {
20659
+ return _Packer.pack(file, "nodebuffer", prettify, overrides);
20673
20660
  }
20674
- static toBlob(file, prettify) {
20675
- return __async(this, null, function* () {
20676
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20677
- const zipData = yield zip.generateAsync({
20678
- type: "blob",
20679
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
20680
- compression: "DEFLATE"
20681
- });
20682
- return zipData;
20683
- });
20661
+ static toBase64String(file, prettify, overrides = []) {
20662
+ return _Packer.pack(file, "base64", prettify, overrides);
20684
20663
  }
20685
- static toStream(file, prettify) {
20664
+ static toBlob(file, prettify, overrides = []) {
20665
+ return _Packer.pack(file, "blob", prettify, overrides);
20666
+ }
20667
+ static toArrayBuffer(file, prettify, overrides = []) {
20668
+ return _Packer.pack(file, "arraybuffer", prettify, overrides);
20669
+ }
20670
+ static toStream(file, prettify, overrides = []) {
20686
20671
  const stream = new streamBrowserifyExports.Stream();
20687
- const zip = this.compiler.compile(file, convertPrettifyType(prettify));
20672
+ const zip = this.compiler.compile(file, convertPrettifyType(prettify), overrides);
20688
20673
  zip.generateAsync({
20689
20674
  type: "nodebuffer",
20690
20675
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
@@ -20695,8 +20680,9 @@ var __async = (__this, __arguments, generator) => {
20695
20680
  });
20696
20681
  return stream;
20697
20682
  }
20698
- }
20699
- __publicField(Packer, "compiler", new Compiler());
20683
+ };
20684
+ __publicField(_Packer, "compiler", new Compiler());
20685
+ let Packer = _Packer;
20700
20686
  const formatter$1 = new Formatter();
20701
20687
  const toJson = (xmlData) => {
20702
20688
  const xmlObj = libExports.xml2js(xmlData, { compact: false, captureSpacesBetweenElements: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docx",
3
- "version": "9.1.1",
3
+ "version": "9.3.0",
4
4
  "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
5
5
  "type": "module",
6
6
  "main": "dist/index.umd.cjs",
@@ -61,7 +61,7 @@
61
61
  "@types/node": "^22.7.5",
62
62
  "hash.js": "^1.1.7",
63
63
  "jszip": "^3.10.1",
64
- "nanoid": "^5.0.4",
64
+ "nanoid": "^5.1.3",
65
65
  "xml": "^1.0.1",
66
66
  "xml-js": "^1.6.8"
67
67
  },
@@ -79,8 +79,8 @@
79
79
  "@types/xml": "^1.0.8",
80
80
  "@typescript-eslint/eslint-plugin": "^8.8.1",
81
81
  "@typescript-eslint/parser": "^8.8.1",
82
- "@vitest/coverage-v8": "^2.1.8",
83
- "@vitest/ui": "^2.1.2",
82
+ "@vitest/coverage-v8": "^3.0.8",
83
+ "@vitest/ui": "^3.0.8",
84
84
  "cspell": "^8.2.3",
85
85
  "docsify-cli": "^4.3.0",
86
86
  "eslint": "^9.13.0",
@@ -95,7 +95,7 @@
95
95
  "glob": "^11.0.0",
96
96
  "inquirer": "^12.0.0",
97
97
  "jiti": "^2.3.3",
98
- "jsdom": "^25.0.1",
98
+ "jsdom": "^26.0.0",
99
99
  "pre-commit": "^1.2.2",
100
100
  "prettier": "^3.1.1",
101
101
  "tsconfig-paths": "^4.0.0",
@@ -106,9 +106,9 @@
106
106
  "unzipper": "^0.12.3",
107
107
  "vite": "^6.0.1",
108
108
  "vite-plugin-dts": "^4.2.4",
109
- "vite-plugin-node-polyfills": "^0.22.0",
109
+ "vite-plugin-node-polyfills": "^0.23.0",
110
110
  "vite-tsconfig-paths": "^5.0.1",
111
- "vitest": "^2.1.8"
111
+ "vitest": "^3.0.8"
112
112
  },
113
113
  "engines": {
114
114
  "node": ">=10"