docx 9.8.0 → 9.9.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.d.cts CHANGED
@@ -103,11 +103,11 @@ export declare const abstractNumUniqueNumericIdGen: () => UniqueNumericIdCreator
103
103
  * @publicApi
104
104
  */
105
105
  export declare const AlignmentType: {
106
- /** Align Start */
106
+ /** Align Start: the left in a left-to-right paragraph, and the right in a `bidirectional` (right-to-left) paragraph */
107
107
  readonly START: "start";
108
108
  /** Align Center */
109
109
  readonly CENTER: "center";
110
- /** End */
110
+ /** Align End: the right in a left-to-right paragraph, and the left in a `bidirectional` (right-to-left) paragraph */
111
111
  readonly END: "end";
112
112
  /** Justified */
113
113
  readonly BOTH: "both";
@@ -123,9 +123,9 @@ export declare const AlignmentType: {
123
123
  readonly LOW_KASHIDA: "lowKashida";
124
124
  /** Thai Language Justification */
125
125
  readonly THAI_DISTRIBUTE: "thaiDistribute";
126
- /** Align Left */
126
+ /** Align Left: a paragraph stays on the left of the page even when it is `bidirectional` (right-to-left) */
127
127
  readonly LEFT: "left";
128
- /** Align Right */
128
+ /** Align Right: a paragraph stays on the right of the page even when it is `bidirectional` (right-to-left) */
129
129
  readonly RIGHT: "right";
130
130
  /** Justified */
131
131
  readonly JUSTIFIED: "both";
@@ -383,10 +383,13 @@ declare class Body_2 extends XmlComponent {
383
383
  /**
384
384
  * Section properties that were moved into a paragraph at the end of their section
385
385
  * by {@link addSection}, keyed by that paragraph. Used to find the section that
386
- * governs a given child of the body.
386
+ * governs a given child of the body, and to write each section's properties into
387
+ * its paragraph while the body is written.
387
388
  */
388
389
  private readonly sectionParagraphs;
389
- constructor();
390
+ private readonly headingBookmarkIds;
391
+ private readonly pageNumbers?;
392
+ constructor({ pageNumbers }?: IBodyOptions);
390
393
  /**
391
394
  * Finds the section properties that govern a top-level child of the body.
392
395
  *
@@ -403,8 +406,10 @@ declare class Body_2 extends XmlComponent {
403
406
  /**
404
407
  * Adds new section properties to the document body.
405
408
  *
406
- * Creates a new section by moving the previous section's properties into a paragraph
407
- * at the end of that section, and then adding the new section as the current section.
409
+ * Creates a new section by moving the previous section's properties into the last
410
+ * paragraph of that section, and then adding the new section as the current section.
411
+ * When that section doesn't end with a paragraph of its own (it ends with a table, or
412
+ * it is empty), an empty paragraph is added to hold its properties.
408
413
  *
409
414
  * According to the OOXML specification:
410
415
  * - Section properties for all sections except the last must be stored in a paragraph's
@@ -418,7 +423,11 @@ declare class Body_2 extends XmlComponent {
418
423
  * Prepares the body element for XML serialization.
419
424
  *
420
425
  * Ensures that the last section's properties are placed as a direct child of the body
421
- * element, as required by the OOXML specification.
426
+ * element, as required by the OOXML specification. Once the body is written, its tables
427
+ * of contents are filled in from its headings, and, when the body has a page number
428
+ * estimator, its page references are given their page numbers. Its SEQ fields are given
429
+ * their numbers after the tables of contents are filled in, as Word leaves a heading's SEQ
430
+ * number out of its entry.
422
431
  *
423
432
  * @param context - The XML serialization context
424
433
  * @returns The prepared XML object or undefined
@@ -433,6 +442,18 @@ declare class Body_2 extends XmlComponent {
433
442
  * @param component - The XML component to add (paragraph, table, etc.)
434
443
  */
435
444
  push(component: XmlComponent): void;
445
+ /**
446
+ * The paragraph the current section ends with, which can hold its properties.
447
+ *
448
+ * There is none when the section ends with something other than a paragraph, or is empty:
449
+ * its last child is then the placeholder at the start of the body (removed when the body is
450
+ * written) or the paragraph that ends the section before, which has properties of its own.
451
+ */
452
+ private lastParagraphOfSection;
453
+ /**
454
+ * An empty paragraph to end a section that has no paragraph of its own to end it. The section's
455
+ * properties are written into it with the others, when the body is written.
456
+ */
436
457
  private createSectionParagraph;
437
458
  }
438
459
  export { Body_2 as Body }
@@ -482,13 +503,21 @@ export declare class Bookmark {
482
503
  readonly children: readonly ParagraphChild[];
483
504
  readonly end: BookmarkEnd;
484
505
  constructor(options: IBookmarkOptions);
506
+ /**
507
+ * The components written in this bookmark's place: its start, its children and its end. A bookmark in its
508
+ * children is written the same way, so one bookmark can hold another.
509
+ *
510
+ * @internal
511
+ */
512
+ get writtenAs(): readonly (ParagraphChild | BookmarkStart | BookmarkEnd)[];
485
513
  }
486
514
 
487
515
  /**
488
516
  * Represents the end marker of a bookmark range.
489
517
  *
490
518
  * This element marks the end of a bookmarked region in the document.
491
- * It must be paired with a corresponding BookmarkStart element with the same id.
519
+ * It must be paired with a corresponding BookmarkStart element with the same id,
520
+ * taken from `bookmarkUniqueNumericId` (see `BookmarkStart`).
492
521
  *
493
522
  * Reference: http://officeopenxml.com/WPbookmark.php
494
523
  *
@@ -507,7 +536,9 @@ export declare class Bookmark {
507
536
  *
508
537
  * @example
509
538
  * ```typescript
510
- * new BookmarkEnd(1);
539
+ * const id = bookmarkUniqueNumericId();
540
+ * new BookmarkStart("myBookmark", id);
541
+ * new BookmarkEnd(id);
511
542
  * ```
512
543
  */
513
544
  export declare class BookmarkEnd extends XmlComponent {
@@ -520,6 +551,10 @@ export declare class BookmarkEnd extends XmlComponent {
520
551
  * This element marks the beginning of a bookmarked region in the document.
521
552
  * It must be paired with a corresponding BookmarkEnd element with the same id.
522
553
  *
554
+ * The id must be unique in the document. `Bookmark` takes its ids from
555
+ * `bookmarkUniqueNumericId`, so take this one from it too, or it can be the
556
+ * same as a `Bookmark`'s.
557
+ *
523
558
  * Reference: http://officeopenxml.com/WPbookmark.php
524
559
  *
525
560
  * ## XSD Schema
@@ -537,7 +572,10 @@ export declare class BookmarkEnd extends XmlComponent {
537
572
  *
538
573
  * @example
539
574
  * ```typescript
540
- * new BookmarkStart("myBookmark", 1);
575
+ * // A bookmark across two paragraphs
576
+ * const id = bookmarkUniqueNumericId();
577
+ * new Paragraph({ children: [new BookmarkStart("myBookmark", id), new TextRun("First")] });
578
+ * new Paragraph({ children: [new TextRun("Last"), new BookmarkEnd(id)] });
541
579
  * ```
542
580
  */
543
581
  export declare class BookmarkStart extends XmlComponent {
@@ -1181,6 +1219,11 @@ export declare class Comments extends XmlComponent {
1181
1219
  get CommentIdsData(): readonly ICommentIdData[] | undefined;
1182
1220
  /** Whether there are no comments, in which case the document has no comments.xml part. */
1183
1221
  get IsEmpty(): boolean;
1222
+ /**
1223
+ * Formats the comments, with the page numbers worked out for their document written into their fields, when the
1224
+ * document's body is written with an estimate of its pages.
1225
+ */
1226
+ prepForXml(context: IContext): IXmlableObject | undefined;
1184
1227
  }
1185
1228
 
1186
1229
  /**
@@ -1462,7 +1505,7 @@ declare type CoreGroupOptions = {
1462
1505
  * it: use it instead of alternative text for images that carry no information, such as borders and flourishes.
1463
1506
  */
1464
1507
  declare type CoreImageOptions = DrawingLinkOptions & {
1465
- /** Size, position, rotation, and flip settings for the image. Width and height are specified in pixels. */
1508
+ /** Size, position, rotation, and flip settings for the image. Width and height are in pixels, at 96 to the inch, not EMUs. */
1466
1509
  readonly transformation: IMediaTransformation;
1467
1510
  /** Floating layout options. When set, the image is positioned freely on the page rather than inline with text. Controls text wrapping, overlap, anchoring, and z-order. */
1468
1511
  readonly floating?: IFloating;
@@ -1691,6 +1734,57 @@ export declare const createDotEmphasisMark: () => XmlComponent;
1691
1734
  */
1692
1735
  export declare const createEmphasisMark: (emphasisMarkType?: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType]) => XmlComponent;
1693
1736
 
1737
+ /**
1738
+ * Creates the endnote properties (endnotePr) of a section.
1739
+ *
1740
+ * ## XSD Schema
1741
+ * ```xml
1742
+ * <xsd:complexType name="CT_EdnProps">
1743
+ * <xsd:sequence>
1744
+ * <xsd:element name="pos" type="CT_EdnPos" minOccurs="0"/>
1745
+ * <xsd:element name="numFmt" type="CT_NumFmt" minOccurs="0"/>
1746
+ * <xsd:group ref="EG_FtnEdnNumProps" minOccurs="0"/>
1747
+ * </xsd:sequence>
1748
+ * </xsd:complexType>
1749
+ * ```
1750
+ *
1751
+ * @example
1752
+ * ```typescript
1753
+ * // Endnotes at the end of the document, numbered 001, 002, 003
1754
+ * createEndnoteProperties({
1755
+ * position: EndnotePosition.DOCUMENT_END,
1756
+ * numberFormat: { type: NumberFormat.CUSTOM, format: "001" },
1757
+ * });
1758
+ * ```
1759
+ */
1760
+ export declare const createEndnoteProperties: (options: IEndnotePropertiesOptions) => XmlComponent;
1761
+
1762
+ /**
1763
+ * Creates the footnote properties (footnotePr) of a section.
1764
+ *
1765
+ * ## XSD Schema
1766
+ * ```xml
1767
+ * <xsd:complexType name="CT_FtnProps">
1768
+ * <xsd:sequence>
1769
+ * <xsd:element name="pos" type="CT_FtnPos" minOccurs="0"/>
1770
+ * <xsd:element name="numFmt" type="CT_NumFmt" minOccurs="0"/>
1771
+ * <xsd:group ref="EG_FtnEdnNumProps" minOccurs="0"/>
1772
+ * </xsd:sequence>
1773
+ * </xsd:complexType>
1774
+ * ```
1775
+ *
1776
+ * @example
1777
+ * ```typescript
1778
+ * // Footnotes at the end of the section, numbered a, b, c and restarting in each section
1779
+ * createFootnoteProperties({
1780
+ * position: FootnotePosition.SECTION_END,
1781
+ * numberFormat: { type: NumberFormat.LOWER_LETTER },
1782
+ * restart: NoteNumberRestart.EACH_SECTION,
1783
+ * });
1784
+ * ```
1785
+ */
1786
+ export declare const createFootnoteProperties: (options: IFootnotePropertiesOptions) => XmlComponent;
1787
+
1694
1788
  /**
1695
1789
  * Creates a frame properties XML component for paragraph text frames.
1696
1790
  *
@@ -2123,7 +2217,7 @@ export declare const createPageMargin: (top: number | UniversalMeasure, right: n
2123
2217
  * });
2124
2218
  * ```
2125
2219
  */
2126
- export declare const createPageNumberType: ({ start, formatType, separator }: IPageNumberTypeAttributes) => XmlComponent;
2220
+ export declare const createPageNumberType: ({ start, formatType, separator, chapterHeadingLevel }: IPageNumberTypeAttributes) => XmlComponent;
2127
2221
 
2128
2222
  /**
2129
2223
  * This element specifies the properties (size and orientation) for all pages in the current section.
@@ -3456,6 +3550,28 @@ export declare class EndnoteIdReference extends XmlComponent {
3456
3550
  constructor(id: number);
3457
3551
  }
3458
3552
 
3553
+ /**
3554
+ * Where the endnotes of a section are placed.
3555
+ *
3556
+ * ## XSD Schema
3557
+ * ```xml
3558
+ * <xsd:simpleType name="ST_EdnPos">
3559
+ * <xsd:restriction base="xsd:string">
3560
+ * <xsd:enumeration value="sectEnd"/>
3561
+ * <xsd:enumeration value="docEnd"/>
3562
+ * </xsd:restriction>
3563
+ * </xsd:simpleType>
3564
+ * ```
3565
+ *
3566
+ * @publicApi
3567
+ */
3568
+ export declare const EndnotePosition: {
3569
+ /** At the end of the section */
3570
+ readonly SECTION_END: "sectEnd";
3571
+ /** At the end of the document */
3572
+ readonly DOCUMENT_END: "docEnd";
3573
+ };
3574
+
3459
3575
  /**
3460
3576
  * Represents a reference to an endnote.
3461
3577
  *
@@ -3480,6 +3596,11 @@ export declare class EndnoteReferenceRunAttributes extends XmlAttributeComponent
3480
3596
  export declare class Endnotes extends XmlComponent {
3481
3597
  constructor();
3482
3598
  createEndnote(id: number, paragraph: readonly Paragraph[]): void;
3599
+ /**
3600
+ * Formats the endnotes, with the page numbers worked out for their document written into their fields, when the
3601
+ * document's body is written with an estimate of its pages.
3602
+ */
3603
+ prepForXml(context: IContext): IXmlableObject | undefined;
3483
3604
  }
3484
3605
 
3485
3606
  declare class EndnotesWrapper implements IViewWrapper {
@@ -3490,6 +3611,46 @@ declare class EndnotesWrapper implements IViewWrapper {
3490
3611
  get Relationships(): Relationships;
3491
3612
  }
3492
3613
 
3614
+ /**
3615
+ * The page each bookmark of a document starts on, and the number of pages of the document and of each of its sections,
3616
+ * as a {@link PageNumberEstimator} works them out.
3617
+ *
3618
+ * @publicApi
3619
+ */
3620
+ export declare type EstimatedPageNumbers = {
3621
+ /**
3622
+ * The number of the page each bookmark starts on, as the page shows it, such as `"3"` or `"iv"`, by the bookmark's
3623
+ * name. The page references to a bookmark that isn't in it are left blank.
3624
+ */
3625
+ readonly bookmarks: ReadonlyMap<string, string>;
3626
+ /** The number of pages of the document, which its NUMPAGES fields show. They are left blank without it */
3627
+ readonly pageCount?: number;
3628
+ /**
3629
+ * The number of pages of each of the document's sections, in order, which the SECTIONPAGES fields in the section, and
3630
+ * in headers and footers only on its pages, show. Those of a section whose number is undefined are left blank.
3631
+ */
3632
+ readonly sectionPageCounts?: readonly (number | undefined)[];
3633
+ /**
3634
+ * The number of the page each bookmark starts on, as a number, such as 4, by the bookmark's name, which the page
3635
+ * references to it with a number format of their own write in that format: `PAGEREF Results \* roman` writes "iv".
3636
+ * Those to a bookmark that isn't in it are left blank.
3637
+ */
3638
+ readonly bookmarkPageNumbers?: ReadonlyMap<string, number>;
3639
+ /**
3640
+ * What each page reference with `\p` (`useRelativePosition`) in the body writes, by the name of the bookmark it
3641
+ * refers to, in the order they are in the body: "above" or "below" when it is on the same page as the bookmark, and
3642
+ * "on page" and the bookmark's page otherwise, such as "on page 4". Those it has nothing for are left blank, as are
3643
+ * those in headers, footers and notes.
3644
+ */
3645
+ readonly relativePositions?: ReadonlyMap<string, readonly (string | undefined)[]>;
3646
+ /**
3647
+ * Where the estimator guessed, when it was asked to lay out past what it can't lay out as Word does, as
3648
+ * `estimatePageNumbersWith({ guess: true })` from `docx/layout` is, in the order of the pages. The page numbers from
3649
+ * the first of them on may not be Word's. Nothing of them is written into the document.
3650
+ */
3651
+ readonly guesses?: readonly PageNumberGuess[];
3652
+ };
3653
+
3493
3654
  /**
3494
3655
  * Represents an external hyperlink to a URL outside the document.
3495
3656
  *
@@ -3713,6 +3874,34 @@ declare type FilePatch = {
3713
3874
  readonly children: readonly FileChild[];
3714
3875
  };
3715
3876
 
3877
+ /**
3878
+ * Writes the page numbers the estimator works out into the fields of a formatted body that show them: the PAGEREF fields
3879
+ * in its tables of contents and elsewhere, those with `\p` and in number formats of their own, and its NUMPAGES and
3880
+ * SECTIONPAGES fields. A field whose number the estimator didn't work out is left as it is. Page references and tables
3881
+ * of contents are written clean, whether or not their numbers were worked out. The estimate is kept for the document's
3882
+ * headers and footers.
3883
+ */
3884
+ export declare const fillPageNumbers: (body: IXmlableObject, context: IContext, estimator: PageNumberEstimator) => void;
3885
+
3886
+ /**
3887
+ * Writes the page numbers worked out for the document a header, footer, footnote, endnote or comment is in into the
3888
+ * fields of the formatted part that show them, once the document's body is written. Its page references and SEQ fields
3889
+ * are written clean, and its SEQ fields are left blank: Word writes them as an error, "Error! Main Document Only.".
3890
+ *
3891
+ * @param part - The formatted part, if it has anything to write
3892
+ * @param context - The context it was formatted in, with the document it is in
3893
+ * @param referenceId - The number of the relationship to a header or footer. The SECTIONPAGES fields of the other parts
3894
+ * are left as they are
3895
+ */
3896
+ export declare const fillPartPageNumbers: (part: IXmlableObject | undefined, context: IContext, referenceId?: number) => void;
3897
+
3898
+ /**
3899
+ * Writes the numbers of the SEQ fields of a formatted body into them, counted as Word counts them (see
3900
+ * {@link sequenceNumbering}), and writes them clean, whether or not their numbers were worked out. It is done after its
3901
+ * tables of contents are filled in from its headings, as Word leaves a heading's SEQ number out of its entry.
3902
+ */
3903
+ export declare const fillSequenceNumbers: (body: IXmlableObject, context: IContext) => void;
3904
+
3716
3905
  /**
3717
3906
  * Options for embedding a font in the document.
3718
3907
  */
@@ -3820,6 +4009,11 @@ declare class Footer_2 extends InitializableXmlComponent {
3820
4009
  constructor(referenceNumber: number, initContent?: XmlComponent);
3821
4010
  get ReferenceId(): number;
3822
4011
  add(item: Paragraph | Table): void;
4012
+ /**
4013
+ * Formats the footer, with the page numbers worked out for its document written into its fields, when the document's
4014
+ * body is written with an estimate of its pages.
4015
+ */
4016
+ prepForXml(context: IContext): IXmlableObject | undefined;
3823
4017
  }
3824
4018
 
3825
4019
  /**
@@ -3852,6 +4046,34 @@ export declare class FooterWrapper implements IViewWrapper {
3852
4046
  get Media(): Media;
3853
4047
  }
3854
4048
 
4049
+ /**
4050
+ * Where the footnotes of a section are placed.
4051
+ *
4052
+ * ## XSD Schema
4053
+ * ```xml
4054
+ * <xsd:simpleType name="ST_FtnPos">
4055
+ * <xsd:restriction base="xsd:string">
4056
+ * <xsd:enumeration value="pageBottom"/>
4057
+ * <xsd:enumeration value="beneathText"/>
4058
+ * <xsd:enumeration value="sectEnd"/>
4059
+ * <xsd:enumeration value="docEnd"/>
4060
+ * </xsd:restriction>
4061
+ * </xsd:simpleType>
4062
+ * ```
4063
+ *
4064
+ * @publicApi
4065
+ */
4066
+ export declare const FootnotePosition: {
4067
+ /** At the bottom of each page */
4068
+ readonly PAGE_BOTTOM: "pageBottom";
4069
+ /** Directly below the text on each page */
4070
+ readonly BENEATH_TEXT: "beneathText";
4071
+ /** At the end of the section */
4072
+ readonly SECTION_END: "sectEnd";
4073
+ /** At the end of the document */
4074
+ readonly DOCUMENT_END: "docEnd";
4075
+ };
4076
+
3855
4077
  /**
3856
4078
  * Represents a footnote reference element in WordprocessingML.
3857
4079
  *
@@ -3977,6 +4199,11 @@ export declare class FootNotes extends XmlComponent {
3977
4199
  * @param paragraph - Array of paragraphs that make up the footnote content
3978
4200
  */
3979
4201
  createFootNote(id: number, paragraph: readonly Paragraph[]): void;
4202
+ /**
4203
+ * Formats the footnotes, with the page numbers worked out for their document written into their fields, when the
4204
+ * document's body is written with an estimate of its pages.
4205
+ */
4206
+ prepForXml(context: IContext): IXmlableObject | undefined;
3980
4207
  }
3981
4208
 
3982
4209
  /**
@@ -4168,6 +4395,11 @@ declare class Header_2 extends InitializableXmlComponent {
4168
4395
  constructor(referenceNumber: number, initContent?: XmlComponent);
4169
4396
  get ReferenceId(): number;
4170
4397
  add(item: Paragraph | Table): void;
4398
+ /**
4399
+ * Formats the header, with the page numbers worked out for its document written into its fields, when the document's
4400
+ * body is written with an estimate of its pages.
4401
+ */
4402
+ prepForXml(context: IContext): IXmlableObject | undefined;
4171
4403
  }
4172
4404
 
4173
4405
  /**
@@ -4596,10 +4828,10 @@ declare type IBaseFrameOptions = {
4596
4828
  readonly anchorLock?: boolean;
4597
4829
  /** Drop cap effect type */
4598
4830
  readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType];
4599
- /** Frame width in twips */
4600
- readonly width: number;
4601
- /** Frame height in twips */
4602
- readonly height: number;
4831
+ /** Frame width in twips. When omitted, the frame is as wide as its content. */
4832
+ readonly width?: number;
4833
+ /** Frame height in twips. When omitted, the frame is as tall as its content. */
4834
+ readonly height?: number;
4603
4835
  /** Text wrapping behavior around the frame */
4604
4836
  readonly wrap?: (typeof FrameWrap)[keyof typeof FrameWrap];
4605
4837
  /** Number of lines for drop cap effect */
@@ -4635,6 +4867,14 @@ export declare type IBaseParagraphStyleOptions = {
4635
4867
  readonly run?: IRunStylePropertiesOptions;
4636
4868
  } & IStyleOptions;
4637
4869
 
4870
+ /**
4871
+ * Options for the body of a document.
4872
+ */
4873
+ export declare type IBodyOptions = {
4874
+ /** Works out the page each bookmark is on, to write the page numbers of page references. See {@link PageNumberEstimator} */
4875
+ readonly pageNumbers?: PageNumberEstimator;
4876
+ };
4877
+
4638
4878
  export declare type IBodyPropertiesOptions = {
4639
4879
  readonly wrap?: (typeof TextWrappingType)[keyof typeof TextWrappingType];
4640
4880
  readonly verticalAnchor?: VerticalAnchor;
@@ -5280,12 +5520,15 @@ export declare type IDocumentHeader = {
5280
5520
  * Options for creating a Document element.
5281
5521
  *
5282
5522
  * @property background - Optional background settings for the document
5523
+ * @property pageNumbers - Works out the page each bookmark is on, to write the page numbers of page references
5283
5524
  *
5284
5525
  * @see {@link Document}
5285
5526
  */
5286
5527
  export declare type IDocumentOptions = {
5287
5528
  /** Optional background settings for the document */
5288
5529
  readonly background?: IDocumentBackgroundOptions;
5530
+ /** Works out the page each bookmark is on, to write the page numbers of page references. See {@link PageNumberEstimator} */
5531
+ readonly pageNumbers?: PageNumberEstimator;
5289
5532
  };
5290
5533
 
5291
5534
  /**
@@ -5303,6 +5546,19 @@ export declare type IDrawingOptions = DrawingLinkOptions & {
5303
5546
  readonly effectExtent?: EffectExtentAttributes;
5304
5547
  };
5305
5548
 
5549
+ /**
5550
+ * Endnote settings of a section.
5551
+ *
5552
+ * @property position - Where the endnotes are placed
5553
+ * @property numberFormat - Number format of the endnotes
5554
+ * @property start - Number of the first endnote
5555
+ * @property restart - When the numbering restarts
5556
+ */
5557
+ export declare type IEndnotePropertiesOptions = INotePropertiesBaseOptions & {
5558
+ /** Where the endnotes are placed */
5559
+ readonly position?: (typeof EndnotePosition)[keyof typeof EndnotePosition];
5560
+ };
5561
+
5306
5562
  export declare type IExtendedMediaData = IMediaData | WpsMediaData | WpgMediaData | GraphicMediaData;
5307
5563
 
5308
5564
  /**
@@ -5362,6 +5618,19 @@ declare type IFontOptions = {
5362
5618
  readonly hint?: string;
5363
5619
  };
5364
5620
 
5621
+ /**
5622
+ * Footnote settings of a section.
5623
+ *
5624
+ * @property position - Where the footnotes are placed
5625
+ * @property numberFormat - Number format of the footnotes
5626
+ * @property start - Number of the first footnote
5627
+ * @property restart - When the numbering restarts
5628
+ */
5629
+ export declare type IFootnotePropertiesOptions = INotePropertiesBaseOptions & {
5630
+ /** Where the footnotes are placed */
5631
+ readonly position?: (typeof FootnotePosition)[keyof typeof FootnotePosition];
5632
+ };
5633
+
5365
5634
  /**
5366
5635
  * Union type for all frame positioning options.
5367
5636
  *
@@ -5743,6 +6012,11 @@ export declare type IMathFractionOptions = {
5743
6012
  readonly numerator: readonly MathComponent[];
5744
6013
  /** Math components for the denominator (bottom) of the fraction */
5745
6014
  readonly denominator: readonly MathComponent[];
6015
+ /**
6016
+ * How the fraction is drawn: stacked, skewed, linear, or stacked with no bar.
6017
+ * @default "stacked"
6018
+ */
6019
+ readonly type?: MathFractionType;
5746
6020
  };
5747
6021
 
5748
6022
  /**
@@ -5769,6 +6043,11 @@ export declare type IMathIntegralOptions = {
5769
6043
  readonly subScript?: readonly MathComponent[];
5770
6044
  /** Optional upper bound of integration */
5771
6045
  readonly superScript?: readonly MathComponent[];
6046
+ /**
6047
+ * Where the limits go: above and below the ∫, or to its right.
6048
+ * @default "side"
6049
+ */
6050
+ readonly limits?: MathLimitsPosition;
5772
6051
  };
5773
6052
 
5774
6053
  /**
@@ -5869,6 +6148,11 @@ export declare type IMathSumOptions = {
5869
6148
  readonly subScript?: readonly MathComponent[];
5870
6149
  /** Optional upper bound (superscript) of the sum */
5871
6150
  readonly superScript?: readonly MathComponent[];
6151
+ /**
6152
+ * Where the limits go: above and below the ∑, or to its right.
6153
+ * @default "aboveBelow"
6154
+ */
6155
+ readonly limits?: MathLimitsPosition;
5872
6156
  };
5873
6157
 
5874
6158
  /**
@@ -5930,8 +6214,9 @@ export declare type IMediaTransformation = {
5930
6214
  readonly top?: number;
5931
6215
  readonly left?: number;
5932
6216
  };
6217
+ /** Display width in pixels, at 96 to the inch, not EMUs. Word won't open a drawing more than 225457 pixels wide */
5933
6218
  readonly width: number;
5934
- /** Display height in pixels */
6219
+ /** Display height in pixels, at 96 to the inch, not EMUs. Word won't open a drawing more than 225457 pixels tall */
5935
6220
  readonly height: number;
5936
6221
  /** Optional flip transformations */
5937
6222
  readonly flip?: {
@@ -6065,6 +6350,28 @@ declare type INonVisualShapePropertiesOptions = {
6065
6350
  readonly txBox: string;
6066
6351
  };
6067
6352
 
6353
+ /**
6354
+ * Number format of the footnotes or endnotes of a section.
6355
+ *
6356
+ * @property type - Number format (decimal, roman, letter, etc.)
6357
+ * @property format - Pattern used with `NumberFormat.CUSTOM`, such as "001"
6358
+ */
6359
+ export declare type INoteNumberFormatOptions = {
6360
+ /** Number format (decimal, roman, letter, etc.) */
6361
+ readonly type: (typeof NumberFormat)[keyof typeof NumberFormat];
6362
+ /** Pattern used with `NumberFormat.CUSTOM`, such as "001" */
6363
+ readonly format?: string;
6364
+ };
6365
+
6366
+ declare type INotePropertiesBaseOptions = {
6367
+ /** Number format of the notes */
6368
+ readonly numberFormat?: INoteNumberFormatOptions;
6369
+ /** Number of the first note */
6370
+ readonly start?: number;
6371
+ /** When the numbering restarts */
6372
+ readonly restart?: (typeof NoteNumberRestart)[keyof typeof NoteNumberRestart];
6373
+ };
6374
+
6068
6375
  /**
6069
6376
  * Supported input data types for document patching.
6070
6377
  *
@@ -6281,6 +6588,7 @@ export declare type IPageMarginAttributes = {
6281
6588
  * @property start - Starting page number for the section
6282
6589
  * @property formatType - Number format (decimal, roman, letter, etc.)
6283
6590
  * @property separator - Separator between chapter and page number
6591
+ * @property chapterHeadingLevel - The level of the headings whose numbers are the chapter numbers
6284
6592
  */
6285
6593
  export declare type IPageNumberTypeAttributes = {
6286
6594
  /** Starting page number for the section */
@@ -6289,6 +6597,12 @@ export declare type IPageNumberTypeAttributes = {
6289
6597
  readonly formatType?: (typeof NumberFormat)[keyof typeof NumberFormat];
6290
6598
  /** Separator between chapter and page number (default: hyphen) */
6291
6599
  readonly separator?: (typeof PageNumberSeparator)[keyof typeof PageNumberSeparator];
6600
+ /**
6601
+ * Puts the chapter number before each page number, such as "2-5" for page 5 of chapter 2. The chapter number is the
6602
+ * number of the last heading of this level (1 to 9, for `HeadingLevel.HEADING_1` to `HEADING_9`), so those headings
6603
+ * must be numbered through their style (`w:chapStyle`)
6604
+ */
6605
+ readonly chapterHeadingLevel?: number;
6292
6606
  };
6293
6607
 
6294
6608
  /**
@@ -6429,7 +6743,11 @@ export declare type IParagraphPropertiesOptions = {
6429
6743
  export declare type IParagraphPropertiesOptionsBase = {
6430
6744
  /** Heading level (Heading1, Heading2, etc.) - applies predefined heading style */
6431
6745
  readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
6432
- /** Whether to render text right-to-left for bidirectional languages */
6746
+ /**
6747
+ * Whether to lay the paragraph out right-to-left, for languages such as Arabic and Hebrew.
6748
+ * A right-to-left paragraph starts on the right of the page, so it is right-aligned unless `alignment` says otherwise.
6749
+ * `alignment` `LEFT` and `RIGHT` still mean those sides of the page, while `START` and `END` follow the paragraph's direction.
6750
+ */
6433
6751
  readonly bidirectional?: boolean;
6434
6752
  /** Whether to insert a page break before this paragraph */
6435
6753
  readonly pageBreakBefore?: boolean;
@@ -6542,6 +6860,7 @@ export declare type IPatch = ParagraphPatch | FilePatch;
6542
6860
  * @property fonts - Font configurations
6543
6861
  * @property hyphenation - Hyphenation settings
6544
6862
  * @property theme - The document's theme: its colors, and its fonts for headings and body text
6863
+ * @property pageNumbers - Works out the page each bookmark is on, so the page numbers of tables of contents and page references are written with the document
6545
6864
  */
6546
6865
  export declare type IPropertiesOptions = {
6547
6866
  readonly sections: readonly ISectionOptions[];
@@ -6579,6 +6898,12 @@ export declare type IPropertiesOptions = {
6579
6898
  * from Office 2016 to 2021 unless the options change it
6580
6899
  */
6581
6900
  readonly theme?: IThemeOptions;
6901
+ /**
6902
+ * Works out the page each bookmark is on, so the page numbers of the document's tables of contents and page
6903
+ * references are written with it, rather than left blank until Word updates them. Give it `estimatePageNumbers`
6904
+ * from `docx/layout`, which lays out the document's pages as Word would
6905
+ */
6906
+ readonly pageNumbers?: PageNumberEstimator;
6582
6907
  };
6583
6908
 
6584
6909
  /**
@@ -6732,6 +7057,8 @@ export declare type ISectionPropertiesChangeOptions = IChangedAttributesProperti
6732
7057
  * @property verticalAlign - Vertical alignment of text on page
6733
7058
  * @property column - Column layout settings
6734
7059
  * @property type - Section break type (next page, continuous, etc.)
7060
+ * @property footnoteProperties - Footnote placement and numbering
7061
+ * @property endnoteProperties - Endnote placement and numbering
6735
7062
  *
6736
7063
  * @see {@link SectionProperties}
6737
7064
  */
@@ -6769,6 +7096,10 @@ export declare type ISectionPropertiesOptionsBase = {
6769
7096
  readonly column?: IColumnsAttributes;
6770
7097
  /** Section break type (next page, continuous, even page, odd page) */
6771
7098
  readonly type?: (typeof SectionType)[keyof typeof SectionType];
7099
+ /** Where the footnotes of the section are placed and how they are numbered */
7100
+ readonly footnoteProperties?: IFootnotePropertiesOptions;
7101
+ /** Where the endnotes of the section are placed and how they are numbered */
7102
+ readonly endnoteProperties?: IEndnotePropertiesOptions;
6772
7103
  };
6773
7104
 
6774
7105
  /**
@@ -6785,6 +7116,8 @@ declare type ISettingsOptions = {
6785
7116
  readonly trackRevisions?: boolean;
6786
7117
  /** Update fields when document is opened */
6787
7118
  readonly updateFields?: boolean;
7119
+ /** Keep the document's embedded fonts when it is saved again, as Word's "Embed fonts in the file" option does */
7120
+ readonly embedFonts?: boolean;
6788
7121
  /** Compatibility settings for older Word versions */
6789
7122
  readonly compatibility?: ICompatibilityOptions;
6790
7123
  /** Default distance between tab stops in twips */
@@ -6806,6 +7139,14 @@ export declare type IShadingAttributesProperties = {
6806
7139
  readonly type?: (typeof ShadingType)[keyof typeof ShadingType];
6807
7140
  };
6808
7141
 
7142
+ /**
7143
+ * Options for a simple field.
7144
+ */
7145
+ export declare type ISimpleFieldOptions = {
7146
+ /** Locks the field so Word keeps the cached value when fields are updated. Not locked by default. */
7147
+ readonly locked?: boolean;
7148
+ };
7149
+
6809
7150
  /**
6810
7151
  * Properties for configuring paragraph spacing.
6811
7152
  *
@@ -6908,9 +7249,9 @@ export declare type IStylesOptions = {
6908
7249
  readonly default?: IDefaultStylesOptions;
6909
7250
  /** Initial base XML component for styles root element */
6910
7251
  readonly initialStyles?: BaseXmlComponent;
6911
- /** Array of custom paragraph style definitions */
7252
+ /** Array of custom paragraph style definitions. Each takes the place of a default or external style with its id */
6912
7253
  readonly paragraphStyles?: readonly IParagraphStyleOptions[];
6913
- /** Array of custom character style definitions */
7254
+ /** Array of custom character style definitions. Each takes the place of a default or external style with its id */
6914
7255
  readonly characterStyles?: readonly ICharacterStyleOptions[];
6915
7256
  /** Array of styles imported from external sources */
6916
7257
  readonly importedStyles?: readonly (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
@@ -7338,8 +7679,10 @@ export declare type ITableOptions = {
7338
7679
  * Widths of the grid columns (`w:tblGrid`) in twips (twentieths of a point).
7339
7680
  *
7340
7681
  * Word treats the grid as a hint and lays the table out from `width` and the cells'
7341
- * widths, but Google Docs, Apple Pages and QuickLook lay the table out from the grid
7342
- * alone and ignore percentage widths. When omitted, the grid is derived from `width`
7682
+ * widths, sizing columns whose cells have no width to their content, so each cell
7683
+ * without a `width` of its own is given the width of the columns it spans, scaled up
7684
+ * to the table's `width` when that is wider. Google Docs, Apple Pages and QuickLook
7685
+ * lay the table out from the grid alone and ignore percentage widths. When omitted, the grid is derived from `width`
7343
7686
  * and the cells' widths, resolved against the page (or, for nested tables, the
7344
7687
  * parent cell) when the document is packed, so the table renders the same in every
7345
7688
  * consumer. Supply explicit values to take full control of the grid.
@@ -8289,12 +8632,27 @@ export declare class MathDenominator extends XmlComponent {
8289
8632
  * numerator: [new MathRun("a + b")],
8290
8633
  * denominator: [new MathRun("c")],
8291
8634
  * });
8635
+ *
8636
+ * // n over k, as a binomial coefficient, in brackets
8637
+ * new MathRoundBrackets({
8638
+ * children: [new MathFraction({ numerator: [new MathRun("n")], denominator: [new MathRun("k")], type: "noBar" })],
8639
+ * });
8292
8640
  * ```
8293
8641
  */
8294
8642
  export declare class MathFraction extends XmlComponent {
8295
8643
  constructor(options: IMathFractionOptions);
8296
8644
  }
8297
8645
 
8646
+ /**
8647
+ * How a fraction is drawn (`m:type`):
8648
+ *
8649
+ * - `"stacked"`: the numerator over the denominator, with a bar between them;
8650
+ * - `"skewed"`: the numerator up and to the left of a slash, and the denominator down and to the right, as ½;
8651
+ * - `"linear"`: on one line, with a slash between them, as a/b;
8652
+ * - `"noBar"`: stacked, with no bar between them, as in a binomial coefficient.
8653
+ */
8654
+ export declare type MathFractionType = "stacked" | "skewed" | "linear" | "noBar";
8655
+
8298
8656
  /**
8299
8657
  * Represents a mathematical function in a math equation.
8300
8658
  *
@@ -8479,6 +8837,14 @@ export declare class MathLimitLower extends XmlComponent {
8479
8837
  constructor(options: IMathLimitLowerOptions);
8480
8838
  }
8481
8839
 
8840
+ /**
8841
+ * Where a large operator's limits go (`m:limLoc`):
8842
+ *
8843
+ * - `"aboveBelow"`: above and below it, as a sum's usually are;
8844
+ * - `"side"`: to its right, as a superscript and subscript, as an integral's usually are.
8845
+ */
8846
+ export declare type MathLimitsPosition = "aboveBelow" | "side";
8847
+
8482
8848
  /**
8483
8849
  * Represents an upper limit structure in a math equation.
8484
8850
  *
@@ -8691,6 +9057,8 @@ export declare class MathRoundBrackets extends XmlComponent {
8691
9057
  * ```typescript
8692
9058
  * new MathRun("x + y");
8693
9059
  * new MathRun({ text: "if ", normalText: true });
9060
+ * new MathRun({ text: "R", script: "doubleStruck" });
9061
+ * new MathRun({ text: "d", style: "plain" });
8694
9062
  * ```
8695
9063
  */
8696
9064
  export declare class MathRun extends XmlComponent {
@@ -8705,12 +9073,54 @@ export declare type MathRunOptions = {
8705
9073
  readonly text: string;
8706
9074
  /**
8707
9075
  * Writes the text as ordinary text rather than math, as Word's "Normal Text" button does (`m:nor`): upright and in
8708
- * the document's font, with its spaces kept. For words in an equation, such as "if" and "otherwise" in cases.
9076
+ * the document's font, with its spaces kept. For words in an equation, such as "if" and "otherwise" in cases. It
9077
+ * can't be given with `style` or `script`, which are for math.
8709
9078
  * @default false
8710
9079
  */
8711
9080
  readonly normalText?: boolean;
9081
+ /**
9082
+ * How the letters are drawn: plain (upright), bold, italic or both (`m:sty`).
9083
+ * @default "plain" with a `script` other than roman, as LaTeX draws its alphabets upright; otherwise none, and Word
9084
+ * draws letters in italic
9085
+ */
9086
+ readonly style?: MathRunStyle;
9087
+ /**
9088
+ * The alphabet the letters are drawn in, such as double-struck for ℝ (`m:scr`).
9089
+ */
9090
+ readonly script?: MathRunScript;
9091
+ /**
9092
+ * Takes the text as it is (`m:lit`), rather than as something Word builds up or lines up, such as an `&` in a
9093
+ * `MathEquationArray`, which would otherwise be a point the rows line up at.
9094
+ * @default false
9095
+ */
9096
+ readonly literal?: boolean;
8712
9097
  };
8713
9098
 
9099
+ /**
9100
+ * The alphabet a {@link MathRun}'s letters are drawn in (`m:scr`):
9101
+ *
9102
+ * - `"roman"`: the math font's own letters, as Word draws them unless a run has an alphabet;
9103
+ * - `"script"`: 𝒜, as LaTeX's `\mathcal` and `\mathscr`;
9104
+ * - `"fraktur"`: 𝔄, as `\mathfrak`;
9105
+ * - `"doubleStruck"`: 𝔸, as `\mathbb`, for sets such as ℝ;
9106
+ * - `"sansSerif"`: 𝖠, as `\mathsf`;
9107
+ * - `"monospace"`: 𝙰, as `\mathtt`.
9108
+ */
9109
+ export declare type MathRunScript = "roman" | "script" | "fraktur" | "doubleStruck" | "sansSerif" | "monospace";
9110
+
9111
+ /**
9112
+ * How a {@link MathRun}'s letters are drawn (`m:sty`):
9113
+ *
9114
+ * - `"plain"`: upright, as LaTeX's `\mathrm`;
9115
+ * - `"bold"`: bold and upright, as `\mathbf`;
9116
+ * - `"italic"`: italic, as `\mathit`;
9117
+ * - `"boldItalic"`: bold and italic, as `\boldsymbol`.
9118
+ *
9119
+ * Word draws letters in italic, and digits and capital Greek letters upright, unless a run has a style. A run in an
9120
+ * alphabet other than roman is plain unless given a style, as LaTeX draws its alphabets upright.
9121
+ */
9122
+ export declare type MathRunStyle = "plain" | "bold" | "italic" | "boldItalic";
9123
+
8714
9124
  /**
8715
9125
  * Represents square brackets in a math equation.
8716
9126
  *
@@ -9036,6 +9446,31 @@ export declare type NonVisualDrawingPropertiesOptions = DrawingLinkOptions & {
9036
9446
  readonly title?: string;
9037
9447
  };
9038
9448
 
9449
+ /**
9450
+ * When the footnote or endnote numbering restarts.
9451
+ *
9452
+ * ## XSD Schema
9453
+ * ```xml
9454
+ * <xsd:simpleType name="ST_RestartNumber">
9455
+ * <xsd:restriction base="xsd:string">
9456
+ * <xsd:enumeration value="continuous"/>
9457
+ * <xsd:enumeration value="eachSect"/>
9458
+ * <xsd:enumeration value="eachPage"/>
9459
+ * </xsd:restriction>
9460
+ * </xsd:simpleType>
9461
+ * ```
9462
+ *
9463
+ * @publicApi
9464
+ */
9465
+ export declare const NoteNumberRestart: {
9466
+ /** Numbering never restarts */
9467
+ readonly CONTINUOUS: "continuous";
9468
+ /** Numbering restarts in each section */
9469
+ readonly EACH_SECTION: "eachSect";
9470
+ /** Numbering restarts on each page */
9471
+ readonly EACH_PAGE: "eachPage";
9472
+ };
9473
+
9039
9474
  /**
9040
9475
  * Creates a field/cross reference to a numbered item in the document.
9041
9476
  *
@@ -9177,6 +9612,7 @@ export declare const NumberFormat: {
9177
9612
  readonly THAI_COUNTING: "thaiCounting";
9178
9613
  readonly BAHT_TEXT: "bahtText";
9179
9614
  readonly DOLLAR_TEXT: "dollarText";
9615
+ readonly CUSTOM: "custom";
9180
9616
  };
9181
9617
 
9182
9618
  /**
@@ -9570,6 +10006,7 @@ export declare class PackagePart {
9570
10006
  private readonly addedTo;
9571
10007
  /**
9572
10008
  * @throws If the folder isn't a single folder name, or is one of the folders docx writes parts of its own in
10009
+ * @throws If the name or the extension isn't a single part of a file name, which could lead out of the folder
9573
10010
  */
9574
10011
  constructor(options: PackagePartOptions);
9575
10012
  /**
@@ -9614,7 +10051,7 @@ declare class PackageParts {
9614
10051
  /**
9615
10052
  * @param contentTypes - Where each part's content type is added
9616
10053
  * @param existingPaths - The paths under word/ of the parts the package already has, such as a template's charts,
9617
- * which new parts are numbered after
10054
+ * which new parts don't take
9618
10055
  */
9619
10056
  constructor(contentTypes: Pick<ContentTypes, "addOverride">, existingPaths?: ReadonlySet<string>);
9620
10057
  /**
@@ -9928,6 +10365,32 @@ export declare class PageNumberElement extends EmptyElement {
9928
10365
  constructor();
9929
10366
  }
9930
10367
 
10368
+ /**
10369
+ * Works out which page each bookmark of a document starts on, and how many pages the document and its sections have,
10370
+ * from the body of the document as it is written, so the page numbers of its tables of contents, page references and
10371
+ * page counts can be written with it.
10372
+ *
10373
+ * `estimatePageNumbers`, from `docx/layout`, is one. Give it to a document as its `pageNumbers`.
10374
+ *
10375
+ * @param body - The document's body, formatted to be written as XML
10376
+ * @param context - The context the body was formatted in, with the document it is in
10377
+ *
10378
+ * @publicApi
10379
+ */
10380
+ export declare type PageNumberEstimator = (body: IXmlableObject, context: IContext) => EstimatedPageNumbers;
10381
+
10382
+ /**
10383
+ * Where a {@link PageNumberEstimator} guessed at something it can't lay out as Word does.
10384
+ *
10385
+ * @publicApi
10386
+ */
10387
+ export declare type PageNumberGuess = {
10388
+ /** What it guessed at, as why it would have stopped there, such as `"a font not in the width tables"` */
10389
+ readonly reason: string;
10390
+ /** The page it guessed on, counted from 1 for the first page of the document, whatever number the page shows */
10391
+ readonly page: number;
10392
+ };
10393
+
9931
10394
  /**
9932
10395
  * Specifies the separator character between chapter number and page number.
9933
10396
  *
@@ -9955,7 +10418,7 @@ export declare const PageNumberSeparator: {
9955
10418
  readonly COLON: "colon";
9956
10419
  /** Em dash separator (—) */
9957
10420
  readonly EM_DASH: "emDash";
9958
- /** En dash separator (–) */
10421
+ /** En dash separator (–), written as `enDash` */
9959
10422
  readonly EN_DASH: "endash";
9960
10423
  };
9961
10424
 
@@ -9998,6 +10461,10 @@ export declare const PageOrientation: {
9998
10461
  * The PAGEREF field displays the page number of the page containing
9999
10462
  * the specified bookmark, useful for cross-references like "see page 5".
10000
10463
  *
10464
+ * It is written dirty, so Word fills in the page number when it opens the document, after asking to. When the
10465
+ * document is given `pageNumbers`, it is written clean, with the number they work out, or blank when they couldn't,
10466
+ * and Word doesn't ask.
10467
+ *
10001
10468
  * @publicApi
10002
10469
  *
10003
10470
  * @example
@@ -10094,6 +10561,24 @@ export declare class Paragraph extends FileChild {
10094
10561
  private readonly properties;
10095
10562
  constructor(options: string | IParagraphOptions);
10096
10563
  prepForXml(context: IContext): IXmlableObject | undefined;
10564
+ /**
10565
+ * Ends a section at this paragraph by adding the section's properties to the paragraph's properties,
10566
+ * as Word does with the last paragraph of each section but the last.
10567
+ *
10568
+ * The body adds them only while it is written and removes them afterwards with
10569
+ * {@link removeSectionProperties}, so the same paragraph can be used in other documents.
10570
+ *
10571
+ * @internal
10572
+ * @param sectionProperties - The properties of the section the paragraph ends
10573
+ */
10574
+ addSectionProperties(sectionProperties: SectionProperties): void;
10575
+ /**
10576
+ * Removes the section properties added with {@link addSectionProperties}.
10577
+ *
10578
+ * @internal
10579
+ * @param sectionProperties - The properties of the section to remove
10580
+ */
10581
+ removeSectionProperties(sectionProperties: SectionProperties): void;
10097
10582
  addRunToFront(run: Run): Paragraph;
10098
10583
  }
10099
10584
 
@@ -10236,6 +10721,21 @@ export declare class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
10236
10721
  * @param item - The XML component to add to the paragraph properties
10237
10722
  */
10238
10723
  push(item: XmlComponent): void;
10724
+ /**
10725
+ * Adds the section properties (`w:sectPr`) of the section this paragraph ends.
10726
+ *
10727
+ * They go after the paragraph's run properties and before its revision (`w:pPrChange`),
10728
+ * the order CT_PPr gives them.
10729
+ *
10730
+ * @param sectionProperties - The properties of the section the paragraph ends
10731
+ */
10732
+ addSectionProperties(sectionProperties: SectionProperties): void;
10733
+ /**
10734
+ * Removes the section properties added with {@link addSectionProperties}.
10735
+ *
10736
+ * @param sectionProperties - The properties of the section to remove
10737
+ */
10738
+ removeSectionProperties(sectionProperties: SectionProperties): void;
10239
10739
  /**
10240
10740
  * Prepares the paragraph properties for XML serialization.
10241
10741
  *
@@ -10358,7 +10858,7 @@ declare type PatchDetectorOptions = {
10358
10858
  *
10359
10859
  * @publicApi
10360
10860
  */
10361
- export declare const patchDocument: <T extends PatchDocumentOutputType = PatchDocumentOutputType>({ outputType, data, patches, keepOriginalStyles, placeholderDelimiters, recursive, }: PatchDocumentOptions<T>) => Promise<OutputByType[T]>;
10861
+ export declare const patchDocument: <T extends PatchDocumentOutputType = PatchDocumentOutputType>({ outputType, data, patches, keepOriginalStyles, placeholderDelimiters, recursive, footnotes, endnotes, pageNumbers, }: PatchDocumentOptions<T>) => Promise<OutputByType[T]>;
10362
10862
 
10363
10863
  /**
10364
10864
  * Options for patching a document.
@@ -10369,6 +10869,9 @@ export declare const patchDocument: <T extends PatchDocumentOutputType = PatchDo
10369
10869
  * @property keepOriginalStyles - Whether to preserve original text formatting
10370
10870
  * @property placeholderDelimiters - Custom delimiter characters for placeholders
10371
10871
  * @property recursive - Whether to replace every occurrence of a placeholder in a paragraph, rather than only the first
10872
+ * @property footnotes - The footnotes that patches refer to with a `FootnoteReferenceRun`
10873
+ * @property endnotes - The endnotes that patches refer to with an `EndnoteReferenceRun`
10874
+ * @property pageNumbers - Works out the page each bookmark is on, to write the page numbers of page references
10372
10875
  */
10373
10876
  export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = PatchDocumentOutputType> = {
10374
10877
  /** Output format type */
@@ -10376,10 +10879,10 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
10376
10879
  /** Input document data */
10377
10880
  readonly data: InputDataType;
10378
10881
  /**
10379
- * Mapping of placeholder keys to patch content, or to a {@link DrawingPatch}, such as `docx/charts`' `ChartDataPatch`,
10380
- * for a drawing whose alt text holds the placeholder
10882
+ * Mapping of placeholder keys to patch content, to a {@link TableRowsPatch} that repeats the rows of a table, or to a
10883
+ * {@link DrawingPatch}, such as `docx/charts`' `ChartDataPatch`, for a drawing whose alt text holds the placeholder
10381
10884
  */
10382
- readonly patches: Readonly<Record<string, IPatch | DrawingPatch>>;
10885
+ readonly patches: Readonly<Record<string, IPatch | TableRowsPatch | DrawingPatch>>;
10383
10886
  /** Preserve original formatting of replaced text (default: true) */
10384
10887
  readonly keepOriginalStyles?: boolean;
10385
10888
  /** Custom placeholder delimiters (default: {{ and }}) */
@@ -10389,6 +10892,23 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
10389
10892
  }>;
10390
10893
  /** Replace every occurrence of a placeholder in a paragraph, rather than only the first (default: true) */
10391
10894
  readonly recursive?: boolean;
10895
+ /**
10896
+ * The footnotes that patches refer to, by the id given to their `FootnoteReferenceRun`s, as in a `Document`. Each
10897
+ * reference a patch inserts gets a footnote of its own, with an id that none of the document's footnotes have
10898
+ */
10899
+ readonly footnotes?: Readonly<Record<string, {
10900
+ readonly children: readonly Paragraph[];
10901
+ }>>;
10902
+ /** The endnotes that patches refer to, by the id given to their `EndnoteReferenceRun`s, as with footnotes */
10903
+ readonly endnotes?: Readonly<Record<string, {
10904
+ readonly children: readonly Paragraph[];
10905
+ }>>;
10906
+ /**
10907
+ * Works out the page each bookmark of the patched document is on, and how many pages it has, so the page numbers of
10908
+ * its tables of contents and page references, and its numbers of pages, are written with it, rather than left as they
10909
+ * were in the template. Give it `estimatePageNumbers` from `docx/layout`. See {@link TemplatePageNumberEstimator}
10910
+ */
10911
+ readonly pageNumbers?: TemplatePageNumberEstimator;
10392
10912
  };
10393
10913
 
10394
10914
  /**
@@ -10396,6 +10916,27 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
10396
10916
  */
10397
10917
  export declare type PatchDocumentOutputType = OutputType;
10398
10918
 
10919
+ /**
10920
+ * A template once `patchDocument` has patched it, as a {@link TemplatePageNumberEstimator} reads it.
10921
+ *
10922
+ * @publicApi
10923
+ */
10924
+ export declare type PatchedTemplate = {
10925
+ /**
10926
+ * Each XML part of the template's package, by its path in the package, such as "word/document.xml". Each is parsed as
10927
+ * `patchDocument` parses it, with xml-js's `xml2js`, not compact, and keeping the spaces between elements
10928
+ * (`captureSpacesBetweenElements`), as the spaces in a text element are its text
10929
+ */
10930
+ readonly parts: ReadonlyMap<string, Element_2>;
10931
+ /** Each of its other parts, such as its pictures and the fonts it embeds, by its path in the package, as bytes */
10932
+ readonly binaryParts?: ReadonlyMap<string, Uint8Array>;
10933
+ /**
10934
+ * Each .docx the template imports (`w:altChunk`), which Word turns into paragraphs and tables of the template's own
10935
+ * when it opens it, unzipped and read as the template is, by its path in the template's package
10936
+ */
10937
+ readonly importedDocuments?: ReadonlyMap<string, PatchedTemplate>;
10938
+ };
10939
+
10399
10940
  /**
10400
10941
  * Patch type enumeration.
10401
10942
  *
@@ -10408,6 +10949,11 @@ export declare const PatchType: {
10408
10949
  readonly DOCUMENT: "file";
10409
10950
  /** Replace content within paragraphs (inline replacement) */
10410
10951
  readonly PARAGRAPH: "paragraph";
10952
+ /**
10953
+ * Repeat the rows of a table that hold the placeholder's fields, such as `{{items.name}}`, once for each row of
10954
+ * data. See {@link TableRowsPatch}
10955
+ */
10956
+ readonly TABLE_ROWS: "tableRows";
10411
10957
  /**
10412
10958
  * Change a drawing whose alt text holds the placeholder, and the parts it refers to, such as the data of a chart made
10413
10959
  * in Word. See {@link DrawingPatch}
@@ -10714,6 +11260,16 @@ declare class Relationships extends XmlComponent {
10714
11260
  * @param targetMode - Optional mode indicating if target is external
10715
11261
  */
10716
11262
  addRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType]): void;
11263
+ /**
11264
+ * Creates a copy of the relationships given. Relationships added to the copy aren't added to them, so the compiler
11265
+ * adds the ones it writes for a part, such as to its images, to a copy, and packing a document again doesn't add
11266
+ * them a second time.
11267
+ *
11268
+ * Static, as `IContext` is public and has `Relationships`, so a new instance member would change the public API.
11269
+ *
11270
+ * @param relationships - The relationships to copy
11271
+ */
11272
+ static copy(relationships: Relationships): Relationships;
10717
11273
  /**
10718
11274
  * Gets the count of relationships in this collection.
10719
11275
  * Excludes the attributes element from the count.
@@ -11041,7 +11597,7 @@ export declare class SectionProperties extends XmlComponent {
11041
11597
  * the width of a single column. Percentage table widths are resolved against it.
11042
11598
  */
11043
11599
  private readonly availableTextWidth;
11044
- constructor({ page: { size: { width, height, orientation, code, }, margin: { top, right, bottom, left, header, footer, gutter, }, pageNumbers, borders, textDirection, }, grid: { linePitch, charSpace, type: gridType }, headerWrapperGroup, footerWrapperGroup, lineNumbers, titlePage, verticalAlign, column, type, revision, }?: ISectionPropertiesOptions);
11600
+ constructor({ page: { size: { width, height, orientation, code, }, margin: { top, right, bottom, left, header, footer, gutter, }, pageNumbers, borders, textDirection, }, grid: { linePitch, charSpace, type: gridType }, headerWrapperGroup, footerWrapperGroup, lineNumbers, titlePage, verticalAlign, column, type, footnoteProperties, endnoteProperties, revision, }?: ISectionPropertiesOptions);
11045
11601
  /**
11046
11602
  * Width, in twips, available to block-level content (paragraphs and tables) in this section.
11047
11603
  *
@@ -11116,6 +11672,10 @@ export declare class Separator extends EmptyElement {
11116
11672
  * Each identifier maintains its own sequence, allowing you to have separate numbering
11117
11673
  * for figures, tables, equations, etc.
11118
11674
  *
11675
+ * It is written dirty, so Word numbers it when it opens the document, after asking to update the fields. When the
11676
+ * document is given `pageNumbers`, it is written clean, with its number counted as Word counts it, or blank where
11677
+ * Word's count isn't known, and Word doesn't ask.
11678
+ *
11119
11679
  * Reference: http://officeopenxml.com/WPrun.php
11120
11680
  *
11121
11681
  * @publicApi
@@ -11157,6 +11717,7 @@ export declare class SequentialIdentifier extends Run {
11157
11717
  * ```xml
11158
11718
  * <xsd:complexType name="CT_Settings">
11159
11719
  * <xsd:sequence>
11720
+ * <xsd:element name="embedTrueTypeFonts" type="CT_OnOff" minOccurs="0"/>
11160
11721
  * <xsd:element name="trackRevisions" type="CT_OnOff" minOccurs="0"/>
11161
11722
  * <xsd:element name="defaultTabStop" type="CT_TwipsMeasure" minOccurs="0"/>
11162
11723
  * <xsd:element name="autoHyphenation" type="CT_OnOff" minOccurs="0"/>
@@ -11344,10 +11905,13 @@ export declare const signedTwipsMeasureValue: (val: UniversalMeasure | number) =
11344
11905
  *
11345
11906
  * // Simple field with cached value
11346
11907
  * new SimpleField("DATE", "2024-01-01");
11908
+ *
11909
+ * // Locked field, Word keeps the cached value when fields are updated
11910
+ * new SimpleField("DATE", "2024-01-01", { locked: true });
11347
11911
  * ```
11348
11912
  */
11349
11913
  export declare class SimpleField extends XmlComponent {
11350
- constructor(instruction: string, cachedValue?: string);
11914
+ constructor(instruction: string, cachedValue?: string, options?: ISimpleFieldOptions);
11351
11915
  }
11352
11916
 
11353
11917
  /**
@@ -11820,6 +12384,13 @@ export declare class Table extends FileChild {
11820
12384
  * serializing.
11821
12385
  */
11822
12386
  prepForXml(context: IContext): IXmlableObject | undefined;
12387
+ /**
12388
+ * Gives each cell without a width of its own the width of the `columnWidths` it spans, as Word sizes the columns of
12389
+ * cells without a width to their content, whatever the grid says. When the table's width is wider than the columns
12390
+ * add up to, they are scaled up to fill it, as Word and LibreOffice lay them out, so columns given as proportions
12391
+ * keep them.
12392
+ */
12393
+ private setCellWidths;
11823
12394
  /**
11824
12395
  * Finds the width in twips available to this table from the serialization context:
11825
12396
  * the parent cell for a nested table, otherwise the text width of the section the
@@ -11911,7 +12482,14 @@ export declare class TableCell extends XmlComponent {
11911
12482
  readonly options: WithHexColors<Omit<ITableCellOptions, "revision">> & {
11912
12483
  readonly revision?: WithHexColors<NonNullable<ITableCellOptions["revision"]>>;
11913
12484
  };
12485
+ private readonly properties;
11914
12486
  constructor(options: ITableCellOptions);
12487
+ /**
12488
+ * Gives the cell, unless it has a width of its own, the width of the table's columns it spans, in twips.
12489
+ *
12490
+ * @internal
12491
+ */
12492
+ setColumnWidth(twips: number): void;
11915
12493
  prepForXml(context: IContext): IXmlableObject | undefined;
11916
12494
  }
11917
12495
 
@@ -11983,6 +12561,12 @@ export declare const TableLayoutType: {
11983
12561
  * TableOfContents creates an auto-generated list of document headings
11984
12562
  * with page numbers. It uses a TOC field code to generate entries.
11985
12563
  *
12564
+ * Unless it is given `cachedEntries` or `contentChildren`, it is written with an
12565
+ * entry for each heading its options include, linked to a bookmark on the heading,
12566
+ * so it isn't empty before Word updates it or in applications that don't update it.
12567
+ * The page numbers are left for Word to fill in when it updates the field, unless the document's `pageNumbers`
12568
+ * writes them.
12569
+ *
11986
12570
  * Reference: http://officeopenxml.com/WPtableOfContents.php
11987
12571
  *
11988
12572
  * @publicApi
@@ -12007,6 +12591,8 @@ export declare const TableLayoutType: {
12007
12591
  * ```
12008
12592
  */
12009
12593
  export declare class TableOfContents extends FileChild {
12594
+ /** What it is filled in with from the headings, when it isn't given its content */
12595
+ private readonly fromHeadings?;
12010
12596
  constructor(alias?: string, { contentChildren, cachedEntries, beginDirty, ...properties }?: ITableOfContentsOptions & {
12011
12597
  readonly contentChildren?: readonly (XmlComponent | string)[];
12012
12598
  /**
@@ -12015,8 +12601,20 @@ export declare class TableOfContents extends FileChild {
12015
12601
  * Note that indentation should come from the paragraph styles defined on the document. By default the styles are TOC1, TOC2, etc. These can be overridden with stylesWithLevels (\t)
12016
12602
  */
12017
12603
  readonly cachedEntries?: readonly ToCEntry[];
12604
+ /**
12605
+ * Whether the field is written dirty, so Word updates the table when it opens the document, after asking to.
12606
+ * Default is dirty, unless the document is given `pageNumbers`: then it is written clean, so Word shows it as
12607
+ * it is written, and doesn't ask.
12608
+ */
12018
12609
  readonly beginDirty?: boolean;
12019
12610
  });
12611
+ /**
12612
+ * Written empty, and filled in from the headings once the body it is in is written, unless it was given its content.
12613
+ * The page numbers are aligned to the right of the text in its section.
12614
+ */
12615
+ prepForXml(context: IContext): IXmlableObject | undefined;
12616
+ /** The width of the text in the section it is in */
12617
+ private textWidthIn;
12020
12618
  private getTabStopsForLevel;
12021
12619
  private buildCachedContentRun;
12022
12620
  private buildCachedContentParagraphChild;
@@ -12108,6 +12706,52 @@ export declare class TableRowPropertiesChange extends XmlComponent {
12108
12706
  constructor(options: ITableRowPropertiesChangeOptions);
12109
12707
  }
12110
12708
 
12709
+ /**
12710
+ * Patch definition that repeats the rows of a table in the template, once for each row of data, so a table can be
12711
+ * designed in Word and filled in with any number of rows.
12712
+ *
12713
+ * The rows it repeats are those that hold its fields: placeholders made of the patch's key, a dot and the field's name,
12714
+ * such as `{{items.name}}` and `{{items.price}}` for the patch `items`. Each copy's fields are patched with a row's
12715
+ * patches, by their field's name, and the other rows of the table, such as its header, are kept as they are. Rows next
12716
+ * to each other are repeated together, such as a row for an item and a row for its notes.
12717
+ *
12718
+ * A field that a row has no patch for is left empty. With no rows, the rows are removed, and so is a table left with
12719
+ * none. The other patches are applied after the rows are repeated, so a placeholder of theirs in a repeated row, such as
12720
+ * `{{currency}}`, is patched in every copy.
12721
+ *
12722
+ * @example
12723
+ * ```typescript
12724
+ * const text = (value: string): IPatch => ({ type: PatchType.PARAGRAPH, children: [new TextRun(value)] });
12725
+ *
12726
+ * await patchDocument({
12727
+ * outputType: "nodebuffer",
12728
+ * data: template,
12729
+ * patches: {
12730
+ * items: {
12731
+ * type: PatchType.TABLE_ROWS,
12732
+ * rows: [
12733
+ * { name: text("Apples"), price: text("1.20") },
12734
+ * { name: text("Pears"), price: text("0.90") },
12735
+ * ],
12736
+ * },
12737
+ * },
12738
+ * });
12739
+ * ```
12740
+ *
12741
+ * @publicApi
12742
+ */
12743
+ export declare type TableRowsPatch = {
12744
+ /** Indicates this patch repeats the rows of a table */
12745
+ readonly type: typeof PatchType.TABLE_ROWS;
12746
+ /**
12747
+ * The patches for each copy of the rows, by the name of the field they patch, such as `name` for `{{items.name}}`.
12748
+ * A field's patch can repeat rows of a table in the copy in turn, whose fields are then such as
12749
+ * `{{items.parts.name}}`. When those fields are in the copy's own row, rather than in a table in it, the row is
12750
+ * repeated for each part, with its item's fields, and an item without parts has no row
12751
+ */
12752
+ readonly rows: readonly Readonly<Record<string, IPatch | TableRowsPatch | undefined>>[];
12753
+ };
12754
+
12111
12755
  export declare type TableVerticalAlign = (typeof VerticalAlignTable)[keyof typeof VerticalAlignTable];
12112
12756
 
12113
12757
  /**
@@ -12246,6 +12890,17 @@ export declare type TemplatePackage = {
12246
12890
  readonly format: (content: XmlComponent) => Element_2;
12247
12891
  };
12248
12892
 
12893
+ /**
12894
+ * Works out which page each bookmark of a template starts on, and how many pages it and each of its sections have, once
12895
+ * `patchDocument` has patched it, so the page numbers of its tables of contents and page references, and its numbers of
12896
+ * pages, are written with it.
12897
+ *
12898
+ * `estimatePageNumbers`, from `docx/layout`, is one. Give it to `patchDocument` as its `pageNumbers`.
12899
+ *
12900
+ * @publicApi
12901
+ */
12902
+ export declare type TemplatePageNumberEstimator = (template: PatchedTemplate) => EstimatedPageNumbers;
12903
+
12249
12904
  /**
12250
12905
  * A part of a template's package, as a {@link DrawingPatch} sees it.
12251
12906
  *
@@ -13128,21 +13783,6 @@ declare type WithHexColors<T> = Omit<T, "borders" | "shading"> & {
13128
13783
  };
13129
13784
  };
13130
13785
 
13131
- /**
13132
- * @ignore
13133
- */
13134
- export declare const WORKAROUND2 = "";
13135
-
13136
- /**
13137
- * @ignore
13138
- */
13139
- export declare const WORKAROUND3 = "";
13140
-
13141
- /**
13142
- * @ignore
13143
- */
13144
- export declare const WORKAROUND4 = "";
13145
-
13146
13786
  export declare type WpgCommonMediaData = {
13147
13787
  readonly outline?: OutlineOptions;
13148
13788
  readonly solidFill?: SolidFillOptions;