docx 9.3.0 → 9.4.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/dist/index.cjs CHANGED
@@ -9376,32 +9376,59 @@ class BordersAttributes extends XmlAttributeComponent {
9376
9376
  }
9377
9377
  }
9378
9378
  const BorderStyle = {
9379
+ /** a single line */
9379
9380
  SINGLE: "single",
9381
+ /** a line with a series of alternating thin and thick strokes */
9380
9382
  DASH_DOT_STROKED: "dashDotStroked",
9383
+ /** a dashed line */
9381
9384
  DASHED: "dashed",
9385
+ /** a dashed line with small gaps */
9382
9386
  DASH_SMALL_GAP: "dashSmallGap",
9387
+ /** a line with alternating dots and dashes */
9383
9388
  DOT_DASH: "dotDash",
9389
+ /** a line with a repeating dot - dot - dash sequence */
9384
9390
  DOT_DOT_DASH: "dotDotDash",
9391
+ /** a dotted line */
9385
9392
  DOTTED: "dotted",
9393
+ /** a double line */
9386
9394
  DOUBLE: "double",
9395
+ /** a double wavy line */
9387
9396
  DOUBLE_WAVE: "doubleWave",
9397
+ /** an inset set of lines */
9388
9398
  INSET: "inset",
9399
+ /** no border */
9389
9400
  NIL: "nil",
9401
+ /** no border */
9390
9402
  NONE: "none",
9403
+ /** an outset set of lines */
9391
9404
  OUTSET: "outset",
9405
+ /** a single line */
9392
9406
  THICK: "thick",
9407
+ /** a thick line contained within a thin line with a large-sized intermediate gap */
9393
9408
  THICK_THIN_LARGE_GAP: "thickThinLargeGap",
9409
+ /** a thick line contained within a thin line with a medium-sized intermediate gap */
9394
9410
  THICK_THIN_MEDIUM_GAP: "thickThinMediumGap",
9411
+ /** a thick line contained within a thin line with a small intermediate gap */
9395
9412
  THICK_THIN_SMALL_GAP: "thickThinSmallGap",
9413
+ /** a thin line contained within a thick line with a large-sized intermediate gap */
9396
9414
  THIN_THICK_LARGE_GAP: "thinThickLargeGap",
9415
+ /** a thick line contained within a thin line with a medium-sized intermediate gap */
9397
9416
  THIN_THICK_MEDIUM_GAP: "thinThickMediumGap",
9417
+ /** a thick line contained within a thin line with a small intermediate gap */
9398
9418
  THIN_THICK_SMALL_GAP: "thinThickSmallGap",
9419
+ /** a thin-thick-thin line with a large gap */
9399
9420
  THIN_THICK_THIN_LARGE_GAP: "thinThickThinLargeGap",
9421
+ /** a thin-thick-thin line with a medium gap */
9400
9422
  THIN_THICK_THIN_MEDIUM_GAP: "thinThickThinMediumGap",
9423
+ /** a thin-thick-thin line with a small gap */
9401
9424
  THIN_THICK_THIN_SMALL_GAP: "thinThickThinSmallGap",
9425
+ /** a three-staged gradient line, getting darker towards the paragraph */
9402
9426
  THREE_D_EMBOSS: "threeDEmboss",
9427
+ /** a three-staged gradient like, getting darker away from the paragraph */
9403
9428
  THREE_D_ENGRAVE: "threeDEngrave",
9429
+ /** a triple line */
9404
9430
  TRIPLE: "triple",
9431
+ /** a wavy line */
9405
9432
  WAVE: "wave"
9406
9433
  };
9407
9434
  class Border extends IgnoreIfEmptyXmlComponent {
@@ -11801,107 +11828,157 @@ const hashedId = (data) => hash.sha1().update(data instanceof ArrayBuffer ? new
11801
11828
  const generateUuidPart = (count) => customAlphabet("1234567890abcdef", count)();
11802
11829
  const uniqueUuid = () => `${generateUuidPart(8)}-${generateUuidPart(4)}-${generateUuidPart(4)}-${generateUuidPart(4)}-${generateUuidPart(12)}`;
11803
11830
  const HorizontalPositionRelativeFrom = {
11831
+ /**
11832
+ * ## Character
11833
+ *
11834
+ * Specifies that the horizontal positioning shall be relative to the position of the anchor within its run content.
11835
+ */
11804
11836
  CHARACTER: "character",
11837
+ /**
11838
+ * ## Column
11839
+ *
11840
+ * Specifies that the horizontal positioning shall be relative to the extents of the column which contains its anchor.
11841
+ */
11805
11842
  COLUMN: "column",
11843
+ /**
11844
+ * ## Inside Margin
11845
+ *
11846
+ * Specifies that the horizontal positioning shall be relative to the inside margin of the current page (the left margin on odd pages, right on even pages).
11847
+ */
11806
11848
  INSIDE_MARGIN: "insideMargin",
11849
+ /**
11850
+ * ## Left Margin
11851
+ *
11852
+ * Specifies that the horizontal positioning shall be relative to the left margin of the page.
11853
+ */
11807
11854
  LEFT_MARGIN: "leftMargin",
11855
+ /**
11856
+ * ## Page Margin
11857
+ *
11858
+ * Specifies that the horizontal positioning shall be relative to the page margins.
11859
+ */
11808
11860
  MARGIN: "margin",
11861
+ /**
11862
+ * ## Outside Margin
11863
+ *
11864
+ * Specifies that the horizontal positioning shall be relative to the outside margin of the current page (the right margin on odd pages, left on even pages).
11865
+ */
11809
11866
  OUTSIDE_MARGIN: "outsideMargin",
11867
+ /**
11868
+ * ## Page Edge
11869
+ *
11870
+ * Specifies that the horizontal positioning shall be relative to the edge of the page.
11871
+ */
11810
11872
  PAGE: "page",
11873
+ /**
11874
+ * ## Right Margin
11875
+ *
11876
+ * Specifies that the horizontal positioning shall be relative to the right margin of the page.
11877
+ */
11811
11878
  RIGHT_MARGIN: "rightMargin"
11812
11879
  };
11813
11880
  const VerticalPositionRelativeFrom = {
11881
+ /**
11882
+ * ## Bottom Margin
11883
+ *
11884
+ * Specifies that the vertical positioning shall be relative to the bottom margin of the current page.
11885
+ */
11814
11886
  BOTTOM_MARGIN: "bottomMargin",
11887
+ /**
11888
+ * ## Inside Margin
11889
+ *
11890
+ * Specifies that the vertical positioning shall be relative to the inside margin of the current page.
11891
+ */
11815
11892
  INSIDE_MARGIN: "insideMargin",
11893
+ /**
11894
+ * ## Line
11895
+ *
11896
+ * Specifies that the vertical positioning shall be relative to the line containing the anchor character.
11897
+ */
11816
11898
  LINE: "line",
11899
+ /**
11900
+ * ## Page Margin
11901
+ *
11902
+ * Specifies that the vertical positioning shall be relative to the page margins.
11903
+ */
11817
11904
  MARGIN: "margin",
11905
+ /**
11906
+ * ## Outside Margin
11907
+ *
11908
+ * Specifies that the vertical positioning shall be relative to the outside margin of the current page.
11909
+ */
11818
11910
  OUTSIDE_MARGIN: "outsideMargin",
11911
+ /**
11912
+ * ## Page Edge
11913
+ *
11914
+ * Specifies that the vertical positioning shall be relative to the edge of the page.
11915
+ */
11819
11916
  PAGE: "page",
11917
+ /**
11918
+ * ## Paragraph
11919
+ *
11920
+ * Specifies that the vertical positioning shall be relative to the paragraph which contains the drawing anchor.
11921
+ */
11820
11922
  PARAGRAPH: "paragraph",
11923
+ /**
11924
+ * ## Top Margin
11925
+ *
11926
+ * Specifies that the vertical positioning shall be relative to the top margin of the current page.
11927
+ */
11821
11928
  TOP_MARGIN: "topMargin"
11822
11929
  };
11823
- class SimplePosAttributes extends XmlAttributeComponent {
11824
- constructor() {
11825
- super(...arguments);
11826
- __publicField(this, "xmlKeys", {
11827
- x: "x",
11828
- y: "y"
11829
- });
11830
- }
11831
- }
11832
- class SimplePos extends XmlComponent {
11833
- constructor() {
11834
- super("wp:simplePos");
11835
- this.root.push(
11836
- new SimplePosAttributes({
11837
- x: 0,
11838
- y: 0
11839
- })
11840
- );
11841
- }
11842
- }
11843
- class Align extends XmlComponent {
11844
- constructor(value) {
11845
- super("wp:align");
11846
- this.root.push(value);
11847
- }
11848
- }
11849
- class PositionOffset extends XmlComponent {
11850
- constructor(offsetValue) {
11851
- super("wp:posOffset");
11852
- this.root.push(offsetValue.toString());
11853
- }
11854
- }
11855
- class HorizontalPositionAttributes extends XmlAttributeComponent {
11856
- constructor() {
11857
- super(...arguments);
11858
- __publicField(this, "xmlKeys", {
11859
- relativeFrom: "relativeFrom"
11860
- });
11861
- }
11862
- }
11863
- class HorizontalPosition extends XmlComponent {
11864
- constructor(horizontalPosition) {
11865
- super("wp:positionH");
11866
- this.root.push(
11867
- new HorizontalPositionAttributes({
11868
- relativeFrom: horizontalPosition.relative || HorizontalPositionRelativeFrom.PAGE
11869
- })
11870
- );
11871
- if (horizontalPosition.align) {
11872
- this.root.push(new Align(horizontalPosition.align));
11873
- } else if (horizontalPosition.offset !== void 0) {
11874
- this.root.push(new PositionOffset(horizontalPosition.offset));
11875
- } else {
11876
- throw new Error("There is no configuration provided for floating position (Align or offset)");
11877
- }
11878
- }
11879
- }
11880
- class VerticalPositionAttributes extends XmlAttributeComponent {
11881
- constructor() {
11882
- super(...arguments);
11883
- __publicField(this, "xmlKeys", {
11884
- relativeFrom: "relativeFrom"
11885
- });
11886
- }
11887
- }
11888
- class VerticalPosition extends XmlComponent {
11889
- constructor(verticalPosition) {
11890
- super("wp:positionV");
11891
- this.root.push(
11892
- new VerticalPositionAttributes({
11893
- relativeFrom: verticalPosition.relative || VerticalPositionRelativeFrom.PAGE
11894
- })
11895
- );
11896
- if (verticalPosition.align) {
11897
- this.root.push(new Align(verticalPosition.align));
11898
- } else if (verticalPosition.offset !== void 0) {
11899
- this.root.push(new PositionOffset(verticalPosition.offset));
11900
- } else {
11901
- throw new Error("There is no configuration provided for floating position (Align or offset)");
11902
- }
11930
+ const createSimplePos = () => new BuilderElement({
11931
+ name: "wp:simplePos",
11932
+ // NOTE: It's not fully supported in Microsoft Word, but this element is needed anyway
11933
+ attributes: {
11934
+ x: { key: "x", value: 0 },
11935
+ y: { key: "y", value: 0 }
11903
11936
  }
11904
- }
11937
+ });
11938
+ const createAlign = (value) => new BuilderElement({
11939
+ name: "wp:align",
11940
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11941
+ children: [value]
11942
+ });
11943
+ const createPositionOffset = (offsetValue) => new BuilderElement({
11944
+ name: "wp:posOffset",
11945
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11946
+ children: [offsetValue.toString()]
11947
+ });
11948
+ const createHorizontalPosition = ({ relative, align, offset }) => new BuilderElement({
11949
+ name: "wp:positionH",
11950
+ attributes: {
11951
+ relativeFrom: { key: "relativeFrom", value: relative != null ? relative : HorizontalPositionRelativeFrom.PAGE }
11952
+ },
11953
+ children: [
11954
+ (() => {
11955
+ if (align) {
11956
+ return createAlign(align);
11957
+ } else if (offset !== void 0) {
11958
+ return createPositionOffset(offset);
11959
+ } else {
11960
+ throw new Error("There is no configuration provided for floating position (Align or offset)");
11961
+ }
11962
+ })()
11963
+ ]
11964
+ });
11965
+ const createVerticalPosition = ({ relative, align, offset }) => new BuilderElement({
11966
+ name: "wp:positionV",
11967
+ attributes: {
11968
+ relativeFrom: { key: "relativeFrom", value: relative != null ? relative : VerticalPositionRelativeFrom.PAGE }
11969
+ },
11970
+ children: [
11971
+ (() => {
11972
+ if (align) {
11973
+ return createAlign(align);
11974
+ } else if (offset !== void 0) {
11975
+ return createPositionOffset(offset);
11976
+ } else {
11977
+ throw new Error("There is no configuration provided for floating position (Align or offset)");
11978
+ }
11979
+ })()
11980
+ ]
11981
+ });
11905
11982
  class GraphicDataAttributes extends XmlAttributeComponent {
11906
11983
  constructor() {
11907
11984
  super(...arguments);
@@ -12444,26 +12521,13 @@ const createEffectExtent = ({ top, right, bottom, left }) => new BuilderElement(
12444
12521
  }
12445
12522
  }
12446
12523
  });
12447
- class ExtentAttributes extends XmlAttributeComponent {
12448
- constructor() {
12449
- super(...arguments);
12450
- __publicField(this, "xmlKeys", {
12451
- cx: "cx",
12452
- cy: "cy"
12453
- });
12454
- }
12455
- }
12456
- class Extent extends XmlComponent {
12457
- constructor(x, y) {
12458
- super("wp:extent");
12459
- __publicField(this, "attributes");
12460
- this.attributes = new ExtentAttributes({
12461
- cx: x,
12462
- cy: y
12463
- });
12464
- this.root.push(this.attributes);
12524
+ const createExtent = ({ x, y }) => new BuilderElement({
12525
+ name: "wp:extent",
12526
+ attributes: {
12527
+ x: { key: "cx", value: x },
12528
+ y: { key: "cy", value: y }
12465
12529
  }
12466
- }
12530
+ });
12467
12531
  class GraphicFrameLockAttributes extends XmlAttributeComponent {
12468
12532
  constructor() {
12469
12533
  super(...arguments);
@@ -12484,12 +12548,10 @@ class GraphicFrameLocks extends XmlComponent {
12484
12548
  );
12485
12549
  }
12486
12550
  }
12487
- class GraphicFrameProperties extends XmlComponent {
12488
- constructor() {
12489
- super("wp:cNvGraphicFramePr");
12490
- this.root.push(new GraphicFrameLocks());
12491
- }
12492
- }
12551
+ const createGraphicFrameProperties = () => new BuilderElement({
12552
+ name: "wp:cNvGraphicFramePr",
12553
+ children: [new GraphicFrameLocks()]
12554
+ });
12493
12555
  class AnchorAttributes extends XmlAttributeComponent {
12494
12556
  constructor() {
12495
12557
  super(...arguments);
@@ -12537,10 +12599,10 @@ class Anchor extends XmlComponent {
12537
12599
  relativeHeight: floating.zIndex ? floating.zIndex : transform.emus.y
12538
12600
  })
12539
12601
  );
12540
- this.root.push(new SimplePos());
12541
- this.root.push(new HorizontalPosition(floating.horizontalPosition));
12542
- this.root.push(new VerticalPosition(floating.verticalPosition));
12543
- this.root.push(new Extent(transform.emus.x, transform.emus.y));
12602
+ this.root.push(createSimplePos());
12603
+ this.root.push(createHorizontalPosition(floating.horizontalPosition));
12604
+ this.root.push(createVerticalPosition(floating.verticalPosition));
12605
+ this.root.push(createExtent({ x: transform.emus.x, y: transform.emus.y }));
12544
12606
  this.root.push(createEffectExtent({ top: 0, right: 0, bottom: 0, left: 0 }));
12545
12607
  if (drawingOptions.floating !== void 0 && drawingOptions.floating.wrap !== void 0) {
12546
12608
  switch (drawingOptions.floating.wrap.type) {
@@ -12561,7 +12623,7 @@ class Anchor extends XmlComponent {
12561
12623
  this.root.push(new WrapNone());
12562
12624
  }
12563
12625
  this.root.push(new DocProperties(drawingOptions.docProperties));
12564
- this.root.push(new GraphicFrameProperties());
12626
+ this.root.push(createGraphicFrameProperties());
12565
12627
  this.root.push(new Graphic({ mediaData, transform, outline: drawingOptions.outline }));
12566
12628
  }
12567
12629
  }
@@ -12588,7 +12650,7 @@ const createInline = ({ mediaData, transform, docProperties, outline }) => {
12588
12650
  }
12589
12651
  },
12590
12652
  children: [
12591
- new Extent(transform.emus.x, transform.emus.y),
12653
+ createExtent({ x: transform.emus.x, y: transform.emus.y }),
12592
12654
  createEffectExtent(
12593
12655
  outline ? {
12594
12656
  top: ((_a = outline.width) != null ? _a : 9525) * 2,
@@ -12598,7 +12660,7 @@ const createInline = ({ mediaData, transform, docProperties, outline }) => {
12598
12660
  } : { top: 0, right: 0, bottom: 0, left: 0 }
12599
12661
  ),
12600
12662
  new DocProperties(docProperties),
12601
- new GraphicFrameProperties(),
12663
+ createGraphicFrameProperties(),
12602
12664
  new Graphic({ mediaData, transform, outline })
12603
12665
  ]
12604
12666
  });
@@ -12721,6 +12783,59 @@ class SimpleMailMergeField extends SimpleField {
12721
12783
  super(` MERGEFIELD ${fieldName} `, `«${fieldName}»`);
12722
12784
  }
12723
12785
  }
12786
+ class RelationshipsAttributes extends XmlAttributeComponent {
12787
+ constructor() {
12788
+ super(...arguments);
12789
+ __publicField(this, "xmlKeys", {
12790
+ xmlns: "xmlns"
12791
+ });
12792
+ }
12793
+ }
12794
+ class RelationshipAttributes extends XmlAttributeComponent {
12795
+ constructor() {
12796
+ super(...arguments);
12797
+ __publicField(this, "xmlKeys", {
12798
+ id: "Id",
12799
+ type: "Type",
12800
+ target: "Target",
12801
+ targetMode: "TargetMode"
12802
+ });
12803
+ }
12804
+ }
12805
+ const TargetModeType = {
12806
+ EXTERNAL: "External"
12807
+ };
12808
+ class Relationship extends XmlComponent {
12809
+ constructor(id, type2, target, targetMode) {
12810
+ super("Relationship");
12811
+ this.root.push(
12812
+ new RelationshipAttributes({
12813
+ id,
12814
+ type: type2,
12815
+ target,
12816
+ targetMode
12817
+ })
12818
+ );
12819
+ }
12820
+ }
12821
+ class Relationships extends XmlComponent {
12822
+ constructor() {
12823
+ super("Relationships");
12824
+ this.root.push(
12825
+ new RelationshipsAttributes({
12826
+ xmlns: "http://schemas.openxmlformats.org/package/2006/relationships"
12827
+ })
12828
+ );
12829
+ }
12830
+ createRelationship(id, type2, target, targetMode) {
12831
+ const relationship = new Relationship(`rId${id}`, type2, target, targetMode);
12832
+ this.root.push(relationship);
12833
+ return relationship;
12834
+ }
12835
+ get RelationshipCount() {
12836
+ return this.root.length - 1;
12837
+ }
12838
+ }
12724
12839
  class CommentAttributes extends XmlAttributeComponent {
12725
12840
  constructor() {
12726
12841
  super(...arguments);
@@ -12808,6 +12923,7 @@ class Comment extends XmlComponent {
12808
12923
  class Comments extends XmlComponent {
12809
12924
  constructor({ children }) {
12810
12925
  super("w:comments");
12926
+ __publicField(this, "relationships");
12811
12927
  this.root.push(
12812
12928
  new RootCommentsAttributes({
12813
12929
  "xmlns:cx": "http://schemas.microsoft.com/office/drawing/2014/chartex",
@@ -12846,6 +12962,10 @@ class Comments extends XmlComponent {
12846
12962
  for (const child of children) {
12847
12963
  this.root.push(new Comment(child));
12848
12964
  }
12965
+ this.relationships = new Relationships();
12966
+ }
12967
+ get Relationships() {
12968
+ return this.relationships;
12849
12969
  }
12850
12970
  }
12851
12971
  class NoBreakHyphen extends EmptyElement {
@@ -13131,33 +13251,6 @@ class FileChild extends XmlComponent {
13131
13251
  __publicField(this, "fileChild", Symbol());
13132
13252
  }
13133
13253
  }
13134
- class RelationshipAttributes extends XmlAttributeComponent {
13135
- constructor() {
13136
- super(...arguments);
13137
- __publicField(this, "xmlKeys", {
13138
- id: "Id",
13139
- type: "Type",
13140
- target: "Target",
13141
- targetMode: "TargetMode"
13142
- });
13143
- }
13144
- }
13145
- const TargetModeType = {
13146
- EXTERNAL: "External"
13147
- };
13148
- class Relationship extends XmlComponent {
13149
- constructor(id, type2, target, targetMode) {
13150
- super("Relationship");
13151
- this.root.push(
13152
- new RelationshipAttributes({
13153
- id,
13154
- type: type2,
13155
- target,
13156
- targetMode
13157
- })
13158
- );
13159
- }
13160
- }
13161
13254
  class HyperlinkAttributes extends XmlAttributeComponent {
13162
13255
  constructor() {
13163
13256
  super(...arguments);
@@ -13316,36 +13409,40 @@ class Columns extends XmlComponent {
13316
13409
  }
13317
13410
  }
13318
13411
  const DocumentGridType = {
13412
+ /**
13413
+ * Specifies that no document grid shall be applied to the contents of the current section in the document.
13414
+ */
13319
13415
  DEFAULT: "default",
13416
+ /**
13417
+ * Specifies that the parent section shall have additional line pitch added to each line within it (as specified on the <docGrid> element (§2.6.5)) in order to maintain the specified number of lines per page.
13418
+ */
13320
13419
  LINES: "lines",
13420
+ /**
13421
+ * Specifies that the parent section shall have both the additional line pitch and character pitch added to each line and character within it (as specified on the <docGrid> element (§2.6.5)) in order to maintain a specific number of lines per page and characters per line.
13422
+ *
13423
+ * When this value is set, the input specified via the user interface may be allowed in exact number of line/character pitch units. */
13321
13424
  LINES_AND_CHARS: "linesAndChars",
13425
+ /**
13426
+ * Specifies that the parent section shall have both the additional line pitch and character pitch added to each line and character within it (as specified on the <docGrid> element (§2.6.5)) in order to maintain a specific number of lines per page and characters per line.
13427
+ *
13428
+ * When this value is set, the input specified via the user interface may be restricted to the number of lines per page and characters per line, with the consumer or producer translating this information based on the current font data to get the resulting line and character pitch values
13429
+ */
13322
13430
  SNAP_TO_CHARS: "snapToChars"
13323
13431
  };
13324
- class DocGridAttributes extends XmlAttributeComponent {
13325
- constructor() {
13326
- super(...arguments);
13327
- __publicField(this, "xmlKeys", {
13328
- type: "w:type",
13329
- linePitch: "w:linePitch",
13330
- charSpace: "w:charSpace"
13331
- });
13332
- }
13333
- }
13334
- class DocumentGrid extends XmlComponent {
13335
- constructor(linePitch, charSpace, type2) {
13336
- super("w:docGrid");
13337
- this.root.push(
13338
- new DocGridAttributes({
13339
- type: type2,
13340
- linePitch: decimalNumber(linePitch),
13341
- charSpace: charSpace ? decimalNumber(charSpace) : void 0
13342
- })
13343
- );
13432
+ const createDocumentGrid = ({ type: type2, linePitch, charSpace }) => new BuilderElement({
13433
+ name: "w:docGrid",
13434
+ attributes: {
13435
+ type: { key: "w:type", value: type2 },
13436
+ linePitch: { key: "w:linePitch", value: decimalNumber(linePitch) },
13437
+ charSpace: { key: "w:charSpace", value: charSpace ? decimalNumber(charSpace) : void 0 }
13344
13438
  }
13345
- }
13439
+ });
13346
13440
  const HeaderFooterReferenceType = {
13441
+ /** Specifies that this header or footer shall appear on every page in this section which is not overridden with a specific `even` or `first` page header/footer. In a section with all three types specified, this type shall be used on all odd numbered pages (counting from the `first` page in the section, not the section numbering). */
13347
13442
  DEFAULT: "default",
13443
+ /** Specifies that this header or footer shall appear on the first page in this section. The appearance of this header or footer is contingent on the setting of the `titlePg` element (§2.10.6). */
13348
13444
  FIRST: "first",
13445
+ /** Specifies that this header or footer shall appear on all even numbered pages in this section (counting from the first page in the section, not the section numbering). The appearance of this header or footer is contingent on the setting of the `evenAndOddHeaders` element (§2.10.1). */
13349
13446
  EVEN: "even"
13350
13447
  };
13351
13448
  class FooterReferenceAttributes extends XmlAttributeComponent {
@@ -13373,8 +13470,23 @@ class HeaderFooterReference extends XmlComponent {
13373
13470
  }
13374
13471
  }
13375
13472
  const LineNumberRestartFormat = {
13473
+ /**
13474
+ * ## Restart Line Numbering on Each Page
13475
+ *
13476
+ * Specifies that line numbering for the parent section shall restart to the starting value whenever a new page is displayed.
13477
+ */
13376
13478
  NEW_PAGE: "newPage",
13479
+ /**
13480
+ * ## Restart Line Numbering for Each Section
13481
+ *
13482
+ * Specifies that line numbering for the parent section shall restart to the starting value whenever the parent begins.
13483
+ */
13377
13484
  NEW_SECTION: "newSection",
13485
+ /**
13486
+ * ## Continue Line Numbering From Previous Section
13487
+ *
13488
+ * Specifies that line numbering for the parent section shall continue from the line numbering from the end of the previous section, if any.
13489
+ */
13378
13490
  CONTINUOUS: "continuous"
13379
13491
  };
13380
13492
  const createLineNumberType = ({ countBy, start, restart, distance }) => new BuilderElement({
@@ -13489,24 +13601,32 @@ class PageNumberType extends XmlComponent {
13489
13601
  }
13490
13602
  }
13491
13603
  const PageOrientation = {
13604
+ /**
13605
+ * ## Portrait Mode
13606
+ *
13607
+ * Specifies that pages in this section shall be printed in portrait mode.
13608
+ */
13492
13609
  PORTRAIT: "portrait",
13610
+ /**
13611
+ * ## Landscape Mode
13612
+ *
13613
+ * Specifies that pages in this section shall be printed in landscape mode, which prints the page contents with a 90 degree rotation with respect to the normal page orientation.
13614
+ */
13493
13615
  LANDSCAPE: "landscape"
13494
13616
  };
13495
- class PageSize extends XmlComponent {
13496
- constructor(width, height, orientation) {
13497
- super("w:pgSz");
13498
- const flip = orientation === PageOrientation.LANDSCAPE;
13499
- const widthTwips = twipsMeasureValue(width);
13500
- const heightTwips = twipsMeasureValue(height);
13501
- this.root.push(
13502
- new NextAttributeComponent({
13503
- width: { key: "w:w", value: flip ? heightTwips : widthTwips },
13504
- height: { key: "w:h", value: flip ? widthTwips : heightTwips },
13505
- orientation: { key: "w:orient", value: orientation }
13506
- })
13507
- );
13508
- }
13509
- }
13617
+ const createPageSize = ({ width, height, orientation, code }) => {
13618
+ const widthTwips = twipsMeasureValue(width);
13619
+ const heightTwips = twipsMeasureValue(height);
13620
+ return new BuilderElement({
13621
+ name: "w:pgSz",
13622
+ attributes: {
13623
+ width: { key: "w:w", value: orientation === PageOrientation.LANDSCAPE ? heightTwips : widthTwips },
13624
+ height: { key: "w:h", value: orientation === PageOrientation.LANDSCAPE ? widthTwips : heightTwips },
13625
+ orientation: { key: "w:orient", value: orientation },
13626
+ code: { key: "w:code", value: code }
13627
+ }
13628
+ });
13629
+ };
13510
13630
  const PageTextDirectionType = {
13511
13631
  LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb",
13512
13632
  TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl"
@@ -13598,7 +13718,7 @@ class SectionProperties extends XmlComponent {
13598
13718
  if (type2) {
13599
13719
  this.root.push(new Type(type2));
13600
13720
  }
13601
- this.root.push(new PageSize(width, height, orientation));
13721
+ this.root.push(createPageSize({ width, height, orientation }));
13602
13722
  this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter));
13603
13723
  if (borders) {
13604
13724
  this.root.push(new PageBorders(borders));
@@ -13619,7 +13739,7 @@ class SectionProperties extends XmlComponent {
13619
13739
  if (textDirection) {
13620
13740
  this.root.push(new PageTextDirection(textDirection));
13621
13741
  }
13622
- this.root.push(new DocumentGrid(linePitch, charSpace, gridType));
13742
+ this.root.push(createDocumentGrid({ linePitch, charSpace, type: gridType }));
13623
13743
  }
13624
13744
  addHeaderFooterGroup(type2, group) {
13625
13745
  if (group.default) {
@@ -13825,32 +13945,6 @@ class Document extends XmlComponent {
13825
13945
  return this.body;
13826
13946
  }
13827
13947
  }
13828
- class RelationshipsAttributes extends XmlAttributeComponent {
13829
- constructor() {
13830
- super(...arguments);
13831
- __publicField(this, "xmlKeys", {
13832
- xmlns: "xmlns"
13833
- });
13834
- }
13835
- }
13836
- class Relationships extends XmlComponent {
13837
- constructor() {
13838
- super("Relationships");
13839
- this.root.push(
13840
- new RelationshipsAttributes({
13841
- xmlns: "http://schemas.openxmlformats.org/package/2006/relationships"
13842
- })
13843
- );
13844
- }
13845
- createRelationship(id, type2, target, targetMode) {
13846
- const relationship = new Relationship(`rId${id}`, type2, target, targetMode);
13847
- this.root.push(relationship);
13848
- return relationship;
13849
- }
13850
- get RelationshipCount() {
13851
- return this.root.length - 1;
13852
- }
13853
- }
13854
13948
  class DocumentWrapper {
13855
13949
  constructor(options) {
13856
13950
  __publicField(this, "document");
@@ -14171,117 +14265,93 @@ class MathFraction extends XmlComponent {
14171
14265
  this.root.push(new MathDenominator(options.denominator));
14172
14266
  }
14173
14267
  }
14174
- class MathAccentCharacterAttributes extends XmlAttributeComponent {
14175
- constructor() {
14176
- super(...arguments);
14177
- __publicField(this, "xmlKeys", { accent: "m:val" });
14178
- }
14179
- }
14180
- class MathAccentCharacter extends XmlComponent {
14181
- constructor(accent) {
14182
- super("m:chr");
14183
- this.root.push(new MathAccentCharacterAttributes({ accent }));
14184
- }
14185
- }
14186
- class MathBase extends XmlComponent {
14187
- constructor(children) {
14188
- super("m:e");
14189
- for (const child of children) {
14190
- this.root.push(child);
14191
- }
14192
- }
14193
- }
14194
- class MathLimitLocationAttributes extends XmlAttributeComponent {
14195
- constructor() {
14196
- super(...arguments);
14197
- __publicField(this, "xmlKeys", { value: "m:val" });
14198
- }
14199
- }
14200
- class MathLimitLocation extends XmlComponent {
14201
- constructor(value) {
14202
- super("m:limLoc");
14203
- this.root.push(new MathLimitLocationAttributes({ value: value || "undOvr" }));
14204
- }
14205
- }
14206
- class MathSubScriptHideAttributes extends XmlAttributeComponent {
14207
- constructor() {
14208
- super(...arguments);
14209
- __publicField(this, "xmlKeys", { hide: "m:val" });
14210
- }
14211
- }
14212
- class MathSubScriptHide extends XmlComponent {
14213
- constructor() {
14214
- super("m:subHide");
14215
- this.root.push(new MathSubScriptHideAttributes({ hide: 1 }));
14216
- }
14217
- }
14218
- class MathSuperScriptHideAttributes extends XmlAttributeComponent {
14219
- constructor() {
14220
- super(...arguments);
14221
- __publicField(this, "xmlKeys", { hide: "m:val" });
14222
- }
14223
- }
14224
- class MathSuperScriptHide extends XmlComponent {
14225
- constructor() {
14226
- super("m:supHide");
14227
- this.root.push(new MathSuperScriptHideAttributes({ hide: 1 }));
14268
+ const createMathAccentCharacter = ({ accent }) => new BuilderElement({
14269
+ name: "m:chr",
14270
+ attributes: {
14271
+ accent: { key: "m:val", value: accent }
14228
14272
  }
14229
- }
14230
- class MathNAryProperties extends XmlComponent {
14231
- constructor(accent, hasSuperScript, hasSubScript, limitLocationVal) {
14232
- super("m:naryPr");
14233
- if (!!accent) {
14234
- this.root.push(new MathAccentCharacter(accent));
14235
- }
14236
- this.root.push(new MathLimitLocation(limitLocationVal));
14237
- if (!hasSuperScript) {
14238
- this.root.push(new MathSuperScriptHide());
14239
- }
14240
- if (!hasSubScript) {
14241
- this.root.push(new MathSubScriptHide());
14242
- }
14273
+ });
14274
+ const createMathBase = ({ children }) => new BuilderElement({
14275
+ name: "m:e",
14276
+ children
14277
+ });
14278
+ const createMathLimitLocation = ({ value }) => new BuilderElement({
14279
+ name: "m:limLoc",
14280
+ attributes: {
14281
+ value: { key: "m:val", value: value || "undOvr" }
14243
14282
  }
14244
- }
14245
- class MathSubScriptElement extends XmlComponent {
14246
- constructor(children) {
14247
- super("m:sub");
14248
- for (const child of children) {
14249
- this.root.push(child);
14250
- }
14283
+ });
14284
+ const createMathSubScriptHide = () => new BuilderElement({
14285
+ name: "m:subHide",
14286
+ attributes: {
14287
+ hide: { key: "m:val", value: 1 }
14251
14288
  }
14252
- }
14253
- class MathSuperScriptElement extends XmlComponent {
14254
- constructor(children) {
14255
- super("m:sup");
14256
- for (const child of children) {
14257
- this.root.push(child);
14258
- }
14289
+ });
14290
+ const createMathSuperScriptHide = () => new BuilderElement({
14291
+ name: "m:supHide",
14292
+ attributes: {
14293
+ hide: { key: "m:val", value: 1 }
14259
14294
  }
14260
- }
14295
+ });
14296
+ const createMathNAryProperties = ({
14297
+ accent,
14298
+ hasSuperScript,
14299
+ hasSubScript,
14300
+ limitLocationVal
14301
+ }) => new BuilderElement({
14302
+ name: "m:naryPr",
14303
+ children: [
14304
+ ...!!accent ? [createMathAccentCharacter({ accent })] : [],
14305
+ createMathLimitLocation({ value: limitLocationVal }),
14306
+ ...!hasSuperScript ? [createMathSuperScriptHide()] : [],
14307
+ ...!hasSubScript ? [createMathSubScriptHide()] : []
14308
+ ]
14309
+ });
14310
+ const createMathSubScriptElement = ({ children }) => new BuilderElement({
14311
+ name: "m:sub",
14312
+ children
14313
+ });
14314
+ const createMathSuperScriptElement = ({ children }) => new BuilderElement({
14315
+ name: "m:sup",
14316
+ children
14317
+ });
14261
14318
  class MathSum extends XmlComponent {
14262
14319
  constructor(options) {
14263
14320
  super("m:nary");
14264
- this.root.push(new MathNAryProperties("∑", !!options.superScript, !!options.subScript));
14321
+ this.root.push(
14322
+ createMathNAryProperties({
14323
+ accent: "∑",
14324
+ hasSuperScript: !!options.superScript,
14325
+ hasSubScript: !!options.subScript
14326
+ })
14327
+ );
14265
14328
  if (!!options.subScript) {
14266
- this.root.push(new MathSubScriptElement(options.subScript));
14329
+ this.root.push(createMathSubScriptElement({ children: options.subScript }));
14267
14330
  }
14268
14331
  if (!!options.superScript) {
14269
- this.root.push(new MathSuperScriptElement(options.superScript));
14332
+ this.root.push(createMathSuperScriptElement({ children: options.superScript }));
14270
14333
  }
14271
- this.root.push(new MathBase(options.children));
14334
+ this.root.push(createMathBase({ children: options.children }));
14272
14335
  }
14273
14336
  }
14274
14337
  class MathIntegral extends XmlComponent {
14275
14338
  constructor(options) {
14276
14339
  super("m:nary");
14277
- this.root.push(new MathNAryProperties("", !!options.superScript, !!options.subScript, "subSup"));
14340
+ this.root.push(
14341
+ createMathNAryProperties({
14342
+ accent: "",
14343
+ hasSuperScript: !!options.superScript,
14344
+ hasSubScript: !!options.subScript,
14345
+ limitLocationVal: "subSup"
14346
+ })
14347
+ );
14278
14348
  if (!!options.subScript) {
14279
- this.root.push(new MathSubScriptElement(options.subScript));
14349
+ this.root.push(createMathSubScriptElement({ children: options.subScript }));
14280
14350
  }
14281
14351
  if (!!options.superScript) {
14282
- this.root.push(new MathSuperScriptElement(options.superScript));
14352
+ this.root.push(createMathSuperScriptElement({ children: options.superScript }));
14283
14353
  }
14284
- this.root.push(new MathBase(options.children));
14354
+ this.root.push(createMathBase({ children: options.children }));
14285
14355
  }
14286
14356
  }
14287
14357
  class MathLimit extends XmlComponent {
@@ -14295,69 +14365,65 @@ class MathLimit extends XmlComponent {
14295
14365
  class MathLimitUpper extends XmlComponent {
14296
14366
  constructor(options) {
14297
14367
  super("m:limUpp");
14298
- this.root.push(new MathBase(options.children));
14368
+ this.root.push(createMathBase({ children: options.children }));
14299
14369
  this.root.push(new MathLimit(options.limit));
14300
14370
  }
14301
14371
  }
14302
14372
  class MathLimitLower extends XmlComponent {
14303
14373
  constructor(options) {
14304
14374
  super("m:limLow");
14305
- this.root.push(new MathBase(options.children));
14375
+ this.root.push(createMathBase({ children: options.children }));
14306
14376
  this.root.push(new MathLimit(options.limit));
14307
14377
  }
14308
14378
  }
14309
- class MathSuperScriptProperties extends XmlComponent {
14310
- constructor() {
14311
- super("m:sSupPr");
14312
- }
14313
- }
14379
+ const createMathSuperScriptProperties = () => new BuilderElement({
14380
+ name: "m:sSupPr"
14381
+ });
14314
14382
  class MathSuperScript extends XmlComponent {
14315
14383
  constructor(options) {
14316
14384
  super("m:sSup");
14317
- this.root.push(new MathSuperScriptProperties());
14318
- this.root.push(new MathBase(options.children));
14319
- this.root.push(new MathSuperScriptElement(options.superScript));
14320
- }
14321
- }
14322
- class MathSubScriptProperties extends XmlComponent {
14323
- constructor() {
14324
- super("m:sSubPr");
14385
+ this.root.push(createMathSuperScriptProperties());
14386
+ this.root.push(createMathBase({ children: options.children }));
14387
+ this.root.push(createMathSuperScriptElement({ children: options.superScript }));
14325
14388
  }
14326
14389
  }
14390
+ const createMathSubScriptProperties = () => new BuilderElement({
14391
+ name: "m:sSubPr"
14392
+ });
14327
14393
  class MathSubScript extends XmlComponent {
14328
14394
  constructor(options) {
14329
14395
  super("m:sSub");
14330
- this.root.push(new MathSubScriptProperties());
14331
- this.root.push(new MathBase(options.children));
14332
- this.root.push(new MathSubScriptElement(options.subScript));
14333
- }
14334
- }
14335
- class MathSubSuperScriptProperties extends XmlComponent {
14336
- constructor() {
14337
- super("m:sSubSupPr");
14396
+ this.root.push(createMathSubScriptProperties());
14397
+ this.root.push(createMathBase({ children: options.children }));
14398
+ this.root.push(createMathSubScriptElement({ children: options.subScript }));
14338
14399
  }
14339
14400
  }
14401
+ const createMathSubSuperScriptProperties = () => new BuilderElement({
14402
+ name: "m:sSubSupPr"
14403
+ });
14340
14404
  class MathSubSuperScript extends XmlComponent {
14341
14405
  constructor(options) {
14342
14406
  super("m:sSubSup");
14343
- this.root.push(new MathSubSuperScriptProperties());
14344
- this.root.push(new MathBase(options.children));
14345
- this.root.push(new MathSubScriptElement(options.subScript));
14346
- this.root.push(new MathSuperScriptElement(options.superScript));
14407
+ this.root.push(createMathSubSuperScriptProperties());
14408
+ this.root.push(createMathBase({ children: options.children }));
14409
+ this.root.push(createMathSubScriptElement({ children: options.subScript }));
14410
+ this.root.push(createMathSuperScriptElement({ children: options.superScript }));
14347
14411
  }
14348
14412
  }
14349
- class MathPreSubSuperScriptProperties extends XmlComponent {
14350
- constructor() {
14351
- super("m:sPrePr");
14352
- }
14353
- }
14354
- class MathPreSubSuperScript extends XmlComponent {
14355
- constructor(options) {
14356
- super("m:sPre");
14357
- this.root.push(new MathPreSubSuperScriptProperties());
14358
- this.root.push(new MathBase(options.children));
14359
- this.root.push(new MathSubScriptElement(options.subScript));
14360
- this.root.push(new MathSuperScriptElement(options.superScript));
14413
+ const createMathPreSubSuperScriptProperties = () => new BuilderElement({
14414
+ name: "m:sPrePr"
14415
+ });
14416
+ class MathPreSubSuperScript extends BuilderElement {
14417
+ constructor({ children, subScript, superScript }) {
14418
+ super({
14419
+ name: "m:sPre",
14420
+ children: [
14421
+ createMathPreSubSuperScriptProperties(),
14422
+ createMathBase({ children }),
14423
+ createMathSubScriptElement({ children: subScript }),
14424
+ createMathSuperScriptElement({ children: superScript })
14425
+ ]
14426
+ });
14361
14427
  }
14362
14428
  }
14363
14429
  const WORKAROUND4 = "";
@@ -14396,7 +14462,7 @@ class MathRadical extends XmlComponent {
14396
14462
  super("m:rad");
14397
14463
  this.root.push(new MathRadicalProperties(!!options.degree));
14398
14464
  this.root.push(new MathDegree(options.degree));
14399
- this.root.push(new MathBase(options.children));
14465
+ this.root.push(createMathBase({ children: options.children }));
14400
14466
  }
14401
14467
  }
14402
14468
  class MathFunctionName extends XmlComponent {
@@ -14417,83 +14483,75 @@ class MathFunction extends XmlComponent {
14417
14483
  super("m:func");
14418
14484
  this.root.push(new MathFunctionProperties());
14419
14485
  this.root.push(new MathFunctionName(options.name));
14420
- this.root.push(new MathBase(options.children));
14421
- }
14422
- }
14423
- class MathBeginningCharacterAttributes extends XmlAttributeComponent {
14424
- constructor() {
14425
- super(...arguments);
14426
- __publicField(this, "xmlKeys", { character: "m:val" });
14427
- }
14428
- }
14429
- class MathBeginningCharacter extends XmlComponent {
14430
- constructor(character) {
14431
- super("m:begChr");
14432
- this.root.push(new MathBeginningCharacterAttributes({ character }));
14433
- }
14434
- }
14435
- class MathEndingCharacterAttributes extends XmlAttributeComponent {
14436
- constructor() {
14437
- super(...arguments);
14438
- __publicField(this, "xmlKeys", { character: "m:val" });
14486
+ this.root.push(createMathBase({ children: options.children }));
14439
14487
  }
14440
14488
  }
14441
- class MathEndingCharacter extends XmlComponent {
14442
- constructor(character) {
14443
- super("m:endChr");
14444
- this.root.push(new MathEndingCharacterAttributes({ character }));
14489
+ const createMathBeginningCharacter = ({ character }) => new BuilderElement({
14490
+ name: "m:begChr",
14491
+ attributes: {
14492
+ character: { key: "m:val", value: character }
14445
14493
  }
14446
- }
14447
- class MathBracketProperties extends XmlComponent {
14448
- constructor(options) {
14449
- super("m:dPr");
14450
- if (!!options) {
14451
- this.root.push(new MathBeginningCharacter(options.beginningCharacter));
14452
- this.root.push(new MathEndingCharacter(options.endingCharacter));
14453
- }
14494
+ });
14495
+ const createMathEndingCharacter = ({ character }) => new BuilderElement({
14496
+ name: "m:endChr",
14497
+ attributes: {
14498
+ character: { key: "m:val", value: character }
14454
14499
  }
14455
- }
14500
+ });
14501
+ const createMathBracketProperties = ({ characters }) => new BuilderElement({
14502
+ name: "m:dPr",
14503
+ children: !!characters ? [
14504
+ createMathBeginningCharacter({ character: characters.beginningCharacter }),
14505
+ createMathEndingCharacter({ character: characters.endingCharacter })
14506
+ ] : []
14507
+ });
14456
14508
  class MathRoundBrackets extends XmlComponent {
14457
14509
  constructor(options) {
14458
14510
  super("m:d");
14459
- this.root.push(new MathBracketProperties());
14460
- this.root.push(new MathBase(options.children));
14511
+ this.root.push(createMathBracketProperties({}));
14512
+ this.root.push(createMathBase({ children: options.children }));
14461
14513
  }
14462
14514
  }
14463
14515
  class MathSquareBrackets extends XmlComponent {
14464
14516
  constructor(options) {
14465
14517
  super("m:d");
14466
14518
  this.root.push(
14467
- new MathBracketProperties({
14468
- beginningCharacter: "[",
14469
- endingCharacter: "]"
14519
+ createMathBracketProperties({
14520
+ characters: {
14521
+ beginningCharacter: "[",
14522
+ endingCharacter: "]"
14523
+ }
14470
14524
  })
14471
14525
  );
14472
- this.root.push(new MathBase(options.children));
14526
+ this.root.push(createMathBase({ children: options.children }));
14473
14527
  }
14474
14528
  }
14475
14529
  class MathCurlyBrackets extends XmlComponent {
14476
14530
  constructor(options) {
14477
14531
  super("m:d");
14478
14532
  this.root.push(
14479
- new MathBracketProperties({
14480
- beginningCharacter: "{",
14481
- endingCharacter: "}"
14533
+ createMathBracketProperties({
14534
+ characters: {
14535
+ beginningCharacter: "{",
14536
+ endingCharacter: "}"
14537
+ }
14482
14538
  })
14483
14539
  );
14484
- this.root.push(new MathBase(options.children));
14540
+ this.root.push(createMathBase({ children: options.children }));
14485
14541
  }
14486
14542
  }
14487
14543
  class MathAngledBrackets extends XmlComponent {
14488
14544
  constructor(options) {
14489
14545
  super("m:d");
14490
14546
  this.root.push(
14491
- new MathBracketProperties({
14492
- beginningCharacter: "〈",
14493
- endingCharacter: ""
14547
+ createMathBracketProperties({
14548
+ characters: {
14549
+ beginningCharacter: "",
14550
+ endingCharacter: "〉"
14551
+ }
14494
14552
  })
14495
14553
  );
14496
- this.root.push(new MathBase(options.children));
14554
+ this.root.push(createMathBase({ children: options.children }));
14497
14555
  }
14498
14556
  }
14499
14557
  class TableGrid extends XmlComponent {
@@ -14852,6 +14910,21 @@ class TableLayout extends XmlComponent {
14852
14910
  this.root.push(new TableLayoutAttributes({ type: type2 }));
14853
14911
  }
14854
14912
  }
14913
+ const CellSpacingType = {
14914
+ /** Value is in twentieths of a point */
14915
+ DXA: "dxa"
14916
+ };
14917
+ class TableCellSpacingElement extends XmlComponent {
14918
+ constructor({ type: type2 = CellSpacingType.DXA, value }) {
14919
+ super("w:tblCellSpacing");
14920
+ this.root.push(
14921
+ new NextAttributeComponent({
14922
+ type: { key: "w:type", value: type2 },
14923
+ value: { key: "w:w", value: measurementOrPercentValue(value) }
14924
+ })
14925
+ );
14926
+ }
14927
+ }
14855
14928
  class TableProperties extends IgnoreIfEmptyXmlComponent {
14856
14929
  constructor(options) {
14857
14930
  super("w:tblPr");
@@ -14885,6 +14958,9 @@ class TableProperties extends IgnoreIfEmptyXmlComponent {
14885
14958
  if (options.cellMargin) {
14886
14959
  this.root.push(new TableCellMargin(TableCellMarginElementType.TABLE, options.cellMargin));
14887
14960
  }
14961
+ if (options.cellSpacing) {
14962
+ this.root.push(new TableCellSpacingElement(options.cellSpacing));
14963
+ }
14888
14964
  }
14889
14965
  }
14890
14966
  class Table extends FileChild {
@@ -14900,7 +14976,8 @@ class Table extends FileChild {
14900
14976
  style,
14901
14977
  borders,
14902
14978
  alignment,
14903
- visuallyRightToLeft
14979
+ visuallyRightToLeft,
14980
+ cellSpacing
14904
14981
  }) {
14905
14982
  super("w:tbl");
14906
14983
  this.root.push(
@@ -14913,7 +14990,8 @@ class Table extends FileChild {
14913
14990
  style,
14914
14991
  alignment,
14915
14992
  cellMargin: margins,
14916
- visuallyRightToLeft
14993
+ visuallyRightToLeft,
14994
+ cellSpacing
14917
14995
  })
14918
14996
  );
14919
14997
  this.root.push(new TableGrid(columnWidths));
@@ -14979,6 +15057,9 @@ class TableRowProperties extends IgnoreIfEmptyXmlComponent {
14979
15057
  if (options.height) {
14980
15058
  this.root.push(new TableRowHeight(options.height.value, options.height.rule));
14981
15059
  }
15060
+ if (options.cellSpacing) {
15061
+ this.root.push(new TableCellSpacingElement(options.cellSpacing));
15062
+ }
14982
15063
  }
14983
15064
  }
14984
15065
  class TableRow extends XmlComponent {
@@ -17524,12 +17605,7 @@ const styleToKeyMap = {
17524
17605
  zIndex: "z-index"
17525
17606
  };
17526
17607
  const formatShapeStyle = (style) => style ? Object.entries(style).map(([key, value]) => `${styleToKeyMap[key]}:${value}`).join(";") : void 0;
17527
- const createShape = ({
17528
- id,
17529
- children,
17530
- type: type2 = SHAPE_TYPE,
17531
- style
17532
- }) => new BuilderElement({
17608
+ const createShape = ({ id, children, type: type2 = SHAPE_TYPE, style }) => new BuilderElement({
17533
17609
  name: "v:shape",
17534
17610
  attributes: {
17535
17611
  id: {
@@ -20246,7 +20322,26 @@ class Compiler {
20246
20322
  }
20247
20323
  }
20248
20324
  );
20325
+ const commentRelationshipCount = file.Comments.Relationships.RelationshipCount + 1;
20326
+ const commentXmlData = xml(
20327
+ this.formatter.format(file.Comments, {
20328
+ viewWrapper: {
20329
+ View: file.Comments,
20330
+ Relationships: file.Comments.Relationships
20331
+ },
20332
+ file,
20333
+ stack: []
20334
+ }),
20335
+ {
20336
+ indent: prettify,
20337
+ declaration: {
20338
+ standalone: "yes",
20339
+ encoding: "UTF-8"
20340
+ }
20341
+ }
20342
+ );
20249
20343
  const documentMediaDatas = this.imageReplacer.getMediaData(documentXmlData, file.Media);
20344
+ const commentMediaDatas = this.imageReplacer.getMediaData(commentXmlData, file.Media);
20250
20345
  return {
20251
20346
  Relationships: {
20252
20347
  data: (() => {
@@ -20579,22 +20674,41 @@ class Compiler {
20579
20674
  path: "word/settings.xml"
20580
20675
  },
20581
20676
  Comments: {
20582
- data: xml(
20583
- this.formatter.format(file.Comments, {
20584
- viewWrapper: file.Document,
20585
- file,
20586
- stack: []
20587
- }),
20588
- {
20589
- indent: prettify,
20590
- declaration: {
20591
- standalone: "yes",
20592
- encoding: "UTF-8"
20593
- }
20594
- }
20595
- ),
20677
+ data: (() => {
20678
+ const xmlData = this.imageReplacer.replace(commentXmlData, commentMediaDatas, commentRelationshipCount);
20679
+ const referenedXmlData = this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
20680
+ return referenedXmlData;
20681
+ })(),
20596
20682
  path: "word/comments.xml"
20597
20683
  },
20684
+ CommentsRelationships: {
20685
+ data: (() => {
20686
+ commentMediaDatas.forEach((mediaData, i) => {
20687
+ file.Comments.Relationships.createRelationship(
20688
+ commentRelationshipCount + i,
20689
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
20690
+ `media/${mediaData.fileName}`
20691
+ );
20692
+ });
20693
+ return xml(
20694
+ this.formatter.format(file.Comments.Relationships, {
20695
+ viewWrapper: {
20696
+ View: file.Comments,
20697
+ Relationships: file.Comments.Relationships
20698
+ },
20699
+ file,
20700
+ stack: []
20701
+ }),
20702
+ {
20703
+ indent: prettify,
20704
+ declaration: {
20705
+ encoding: "UTF-8"
20706
+ }
20707
+ }
20708
+ );
20709
+ })(),
20710
+ path: "word/_rels/comments.xml.rels"
20711
+ },
20598
20712
  FontTable: {
20599
20713
  data: xml(
20600
20714
  this.formatter.format(file.FontTable.View, {
@@ -20923,9 +21037,8 @@ const traverse = (node) => {
20923
21037
  currentNode = queue2.shift();
20924
21038
  if (currentNode.element.name === "w:p") {
20925
21039
  renderedParagraphs = [...renderedParagraphs, renderParagraphNode(currentNode)];
20926
- } else {
20927
- queue2.push(...elementsToWrapper(currentNode));
20928
21040
  }
21041
+ queue2.push(...elementsToWrapper(currentNode));
20929
21042
  }
20930
21043
  return renderedParagraphs;
20931
21044
  };
@@ -21003,14 +21116,21 @@ const PatchType = {
21003
21116
  PARAGRAPH: "paragraph"
21004
21117
  };
21005
21118
  const imageReplacer = new ImageReplacer();
21119
+ const UTF16LE = Buffer.from([255, 254]);
21120
+ const UTF16BE = Buffer.from([254, 255]);
21006
21121
  const patchDocument = (_0) => __async(exports, [_0], function* ({
21007
21122
  outputType,
21008
21123
  data,
21009
21124
  patches,
21010
- keepOriginalStyles
21125
+ keepOriginalStyles,
21126
+ placeholderDelimiters = { start: "{{", end: "}}" },
21127
+ /**
21128
+ * Search for occurrences over patched document
21129
+ */
21130
+ recursive = true
21011
21131
  }) {
21012
- var _a, _b, _c, _d;
21013
- const zipContent = yield JSZip.loadAsync(data);
21132
+ var _a, _b, _c;
21133
+ const zipContent = data instanceof JSZip ? data : yield JSZip.loadAsync(data);
21014
21134
  const contexts = /* @__PURE__ */ new Map();
21015
21135
  const file = {
21016
21136
  Media: new Media()
@@ -21021,15 +21141,20 @@ const patchDocument = (_0) => __async(exports, [_0], function* ({
21021
21141
  let hasMedia = false;
21022
21142
  const binaryContentMap = /* @__PURE__ */ new Map();
21023
21143
  for (const [key, value] of Object.entries(zipContent.files)) {
21144
+ const binaryValue = yield value.async("uint8array");
21145
+ const startBytes = binaryValue.slice(0, 2);
21146
+ if (UTF16LE.equals(startBytes) || UTF16BE.equals(startBytes)) {
21147
+ binaryContentMap.set(key, binaryValue);
21148
+ continue;
21149
+ }
21024
21150
  if (!key.endsWith(".xml") && !key.endsWith(".rels")) {
21025
- binaryContentMap.set(key, yield value.async("uint8array"));
21151
+ binaryContentMap.set(key, binaryValue);
21026
21152
  continue;
21027
21153
  }
21028
21154
  const json = toJson(yield value.async("text"));
21029
21155
  if (key === "word/document.xml") {
21030
21156
  const document2 = (_a = json.elements) == null ? void 0 : _a.find((i) => i.name === "w:document");
21031
- if (document2) {
21032
- document2.attributes = (_b = document2.attributes) != null ? _b : {};
21157
+ if (document2 && document2.attributes) {
21033
21158
  for (const ns of ["mc", "wp", "r", "w15", "m"]) {
21034
21159
  document2.attributes[`xmlns:${ns}`] = DocumentAttributeNamespaces[ns];
21035
21160
  }
@@ -21055,8 +21180,12 @@ const patchDocument = (_0) => __async(exports, [_0], function* ({
21055
21180
  stack: []
21056
21181
  };
21057
21182
  contexts.set(key, context);
21183
+ if (!(placeholderDelimiters == null ? void 0 : placeholderDelimiters.start.trim()) || !(placeholderDelimiters == null ? void 0 : placeholderDelimiters.end.trim())) {
21184
+ throw new Error("Both start and end delimiters must be non-empty strings.");
21185
+ }
21186
+ const { start, end } = placeholderDelimiters;
21058
21187
  for (const [patchKey, patchValue] of Object.entries(patches)) {
21059
- const patchText = `{{${patchKey}}}`;
21188
+ const patchText = `${start}${patchKey}${end}`;
21060
21189
  while (true) {
21061
21190
  const { didFindOccurrence } = replacer({
21062
21191
  json,
@@ -21082,7 +21211,7 @@ const patchDocument = (_0) => __async(exports, [_0], function* ({
21082
21211
  context,
21083
21212
  keepOriginalStyles
21084
21213
  });
21085
- if (!didFindOccurrence) {
21214
+ if (!recursive || !didFindOccurrence) {
21086
21215
  break;
21087
21216
  }
21088
21217
  }
@@ -21100,7 +21229,7 @@ const patchDocument = (_0) => __async(exports, [_0], function* ({
21100
21229
  }
21101
21230
  for (const { key, mediaDatas } of imageRelationshipAdditions) {
21102
21231
  const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
21103
- const relationshipsJson = (_c = map.get(relationshipKey)) != null ? _c : createRelationshipFile();
21232
+ const relationshipsJson = (_b = map.get(relationshipKey)) != null ? _b : createRelationshipFile();
21104
21233
  map.set(relationshipKey, relationshipsJson);
21105
21234
  const index = getNextRelationshipIndex(relationshipsJson);
21106
21235
  const newJson = imageReplacer.replace(JSON.stringify(map.get(key)), mediaDatas, index);
@@ -21117,7 +21246,7 @@ const patchDocument = (_0) => __async(exports, [_0], function* ({
21117
21246
  }
21118
21247
  for (const { key, hyperlink } of hyperlinkRelationshipAdditions) {
21119
21248
  const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
21120
- const relationshipsJson = (_d = map.get(relationshipKey)) != null ? _d : createRelationshipFile();
21249
+ const relationshipsJson = (_c = map.get(relationshipKey)) != null ? _c : createRelationshipFile();
21121
21250
  map.set(relationshipKey, relationshipsJson);
21122
21251
  appendRelationship(
21123
21252
  relationshipsJson,
@@ -21157,7 +21286,10 @@ const patchDocument = (_0) => __async(exports, [_0], function* ({
21157
21286
  });
21158
21287
  });
21159
21288
  const toXml = (jsonObj) => {
21160
- const output = libExports.js2xml(jsonObj);
21289
+ const output = libExports.js2xml(jsonObj, {
21290
+ attributeValueFn: (str) => String(str).replace(/&(?!amp;|lt;|gt;|quot;|apos;)/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;")
21291
+ // cspell:words apos
21292
+ });
21161
21293
  return output;
21162
21294
  };
21163
21295
  const createRelationshipFile = () => ({
@@ -21180,7 +21312,7 @@ const createRelationshipFile = () => ({
21180
21312
  ]
21181
21313
  });
21182
21314
  const patchDetector = (_0) => __async(exports, [_0], function* ({ data }) {
21183
- const zipContent = yield JSZip.loadAsync(data);
21315
+ const zipContent = data instanceof JSZip ? data : yield JSZip.loadAsync(data);
21184
21316
  const patches = /* @__PURE__ */ new Set();
21185
21317
  for (const [key, value] of Object.entries(zipContent.files)) {
21186
21318
  if (!key.endsWith(".xml") && !key.endsWith(".rels")) {
@@ -21233,14 +21365,12 @@ exports.ContinuationSeparator = ContinuationSeparator;
21233
21365
  exports.DayLong = DayLong;
21234
21366
  exports.DayShort = DayShort;
21235
21367
  exports.DeletedTextRun = DeletedTextRun;
21236
- exports.DocGridAttributes = DocGridAttributes;
21237
21368
  exports.Document = File;
21238
21369
  exports.DocumentAttributeNamespaces = DocumentAttributeNamespaces;
21239
21370
  exports.DocumentAttributes = DocumentAttributes;
21240
21371
  exports.DocumentBackground = DocumentBackground;
21241
21372
  exports.DocumentBackgroundAttributes = DocumentBackgroundAttributes;
21242
21373
  exports.DocumentDefaults = DocumentDefaults;
21243
- exports.DocumentGrid = DocumentGrid;
21244
21374
  exports.DocumentGridType = DocumentGridType;
21245
21375
  exports.DotEmphasisMark = DotEmphasisMark;
21246
21376
  exports.Drawing = Drawing;
@@ -21271,7 +21401,6 @@ exports.HeaderWrapper = HeaderWrapper;
21271
21401
  exports.HeadingLevel = HeadingLevel;
21272
21402
  exports.HeightRule = HeightRule;
21273
21403
  exports.HighlightColor = HighlightColor;
21274
- exports.HorizontalPosition = HorizontalPosition;
21275
21404
  exports.HorizontalPositionAlign = HorizontalPositionAlign;
21276
21405
  exports.HorizontalPositionRelativeFrom = HorizontalPositionRelativeFrom;
21277
21406
  exports.HpsMeasureElement = HpsMeasureElement;
@@ -21295,9 +21424,7 @@ exports.LevelSuffix = LevelSuffix;
21295
21424
  exports.LineNumberRestartFormat = LineNumberRestartFormat;
21296
21425
  exports.LineRuleType = LineRuleType;
21297
21426
  exports.Math = Math$1;
21298
- exports.MathAccentCharacter = MathAccentCharacter;
21299
21427
  exports.MathAngledBrackets = MathAngledBrackets;
21300
- exports.MathBase = MathBase;
21301
21428
  exports.MathCurlyBrackets = MathCurlyBrackets;
21302
21429
  exports.MathDegree = MathDegree;
21303
21430
  exports.MathDenominator = MathDenominator;
@@ -21307,27 +21434,19 @@ exports.MathFunctionName = MathFunctionName;
21307
21434
  exports.MathFunctionProperties = MathFunctionProperties;
21308
21435
  exports.MathIntegral = MathIntegral;
21309
21436
  exports.MathLimit = MathLimit;
21310
- exports.MathLimitLocation = MathLimitLocation;
21311
21437
  exports.MathLimitLower = MathLimitLower;
21312
21438
  exports.MathLimitUpper = MathLimitUpper;
21313
- exports.MathNAryProperties = MathNAryProperties;
21314
21439
  exports.MathNumerator = MathNumerator;
21315
21440
  exports.MathPreSubSuperScript = MathPreSubSuperScript;
21316
- exports.MathPreSubSuperScriptProperties = MathPreSubSuperScriptProperties;
21317
21441
  exports.MathRadical = MathRadical;
21318
21442
  exports.MathRadicalProperties = MathRadicalProperties;
21319
21443
  exports.MathRoundBrackets = MathRoundBrackets;
21320
21444
  exports.MathRun = MathRun;
21321
21445
  exports.MathSquareBrackets = MathSquareBrackets;
21322
21446
  exports.MathSubScript = MathSubScript;
21323
- exports.MathSubScriptElement = MathSubScriptElement;
21324
- exports.MathSubScriptProperties = MathSubScriptProperties;
21325
21447
  exports.MathSubSuperScript = MathSubSuperScript;
21326
- exports.MathSubSuperScriptProperties = MathSubSuperScriptProperties;
21327
21448
  exports.MathSum = MathSum;
21328
21449
  exports.MathSuperScript = MathSuperScript;
21329
- exports.MathSuperScriptElement = MathSuperScriptElement;
21330
- exports.MathSuperScriptProperties = MathSuperScriptProperties;
21331
21450
  exports.Media = Media;
21332
21451
  exports.MonthLong = MonthLong;
21333
21452
  exports.MonthShort = MonthShort;
@@ -21355,7 +21474,6 @@ exports.PageNumberType = PageNumberType;
21355
21474
  exports.PageNumberTypeAttributes = PageNumberTypeAttributes;
21356
21475
  exports.PageOrientation = PageOrientation;
21357
21476
  exports.PageReference = PageReference;
21358
- exports.PageSize = PageSize;
21359
21477
  exports.PageTextDirection = PageTextDirection;
21360
21478
  exports.PageTextDirectionType = PageTextDirectionType;
21361
21479
  exports.Paragraph = Paragraph;
@@ -21383,7 +21501,6 @@ exports.Shading = Shading;
21383
21501
  exports.ShadingType = ShadingType;
21384
21502
  exports.SimpleField = SimpleField;
21385
21503
  exports.SimpleMailMergeField = SimpleMailMergeField;
21386
- exports.SimplePos = SimplePos;
21387
21504
  exports.SoftHyphen = SoftHyphen;
21388
21505
  exports.SpaceType = SpaceType;
21389
21506
  exports.Spacing = Spacing;
@@ -21433,7 +21550,6 @@ exports.VerticalAlignAttributes = VerticalAlignAttributes;
21433
21550
  exports.VerticalAlignElement = VerticalAlignElement;
21434
21551
  exports.VerticalMerge = VerticalMerge;
21435
21552
  exports.VerticalMergeType = VerticalMergeType;
21436
- exports.VerticalPosition = VerticalPosition;
21437
21553
  exports.VerticalPositionAlign = VerticalPositionAlign;
21438
21554
  exports.VerticalPositionRelativeFrom = VerticalPositionRelativeFrom;
21439
21555
  exports.WORKAROUND2 = WORKAROUND2;
@@ -21454,9 +21570,24 @@ exports.concreteNumUniqueNumericIdGen = concreteNumUniqueNumericIdGen;
21454
21570
  exports.convertInchesToTwip = convertInchesToTwip;
21455
21571
  exports.convertMillimetersToTwip = convertMillimetersToTwip;
21456
21572
  exports.convertToXmlComponent = convertToXmlComponent;
21573
+ exports.createDocumentGrid = createDocumentGrid;
21457
21574
  exports.createFrameProperties = createFrameProperties;
21575
+ exports.createHorizontalPosition = createHorizontalPosition;
21458
21576
  exports.createLineNumberType = createLineNumberType;
21577
+ exports.createMathAccentCharacter = createMathAccentCharacter;
21578
+ exports.createMathBase = createMathBase;
21579
+ exports.createMathLimitLocation = createMathLimitLocation;
21580
+ exports.createMathNAryProperties = createMathNAryProperties;
21581
+ exports.createMathPreSubSuperScriptProperties = createMathPreSubSuperScriptProperties;
21582
+ exports.createMathSubScriptElement = createMathSubScriptElement;
21583
+ exports.createMathSubScriptProperties = createMathSubScriptProperties;
21584
+ exports.createMathSubSuperScriptProperties = createMathSubSuperScriptProperties;
21585
+ exports.createMathSuperScriptElement = createMathSuperScriptElement;
21586
+ exports.createMathSuperScriptProperties = createMathSuperScriptProperties;
21587
+ exports.createPageSize = createPageSize;
21588
+ exports.createSimplePos = createSimplePos;
21459
21589
  exports.createStringElement = createStringElement;
21590
+ exports.createVerticalPosition = createVerticalPosition;
21460
21591
  exports.dateTimeValue = dateTimeValue;
21461
21592
  exports.decimalNumber = decimalNumber;
21462
21593
  exports.docPropertiesUniqueNumericIdGen = docPropertiesUniqueNumericIdGen;