docx 9.8.1 → 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.ts 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
  *
@@ -5945,8 +6214,9 @@ export declare type IMediaTransformation = {
5945
6214
  readonly top?: number;
5946
6215
  readonly left?: number;
5947
6216
  };
6217
+ /** Display width in pixels, at 96 to the inch, not EMUs. Word won't open a drawing more than 225457 pixels wide */
5948
6218
  readonly width: number;
5949
- /** 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 */
5950
6220
  readonly height: number;
5951
6221
  /** Optional flip transformations */
5952
6222
  readonly flip?: {
@@ -6080,6 +6350,28 @@ declare type INonVisualShapePropertiesOptions = {
6080
6350
  readonly txBox: string;
6081
6351
  };
6082
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
+
6083
6375
  /**
6084
6376
  * Supported input data types for document patching.
6085
6377
  *
@@ -6296,6 +6588,7 @@ export declare type IPageMarginAttributes = {
6296
6588
  * @property start - Starting page number for the section
6297
6589
  * @property formatType - Number format (decimal, roman, letter, etc.)
6298
6590
  * @property separator - Separator between chapter and page number
6591
+ * @property chapterHeadingLevel - The level of the headings whose numbers are the chapter numbers
6299
6592
  */
6300
6593
  export declare type IPageNumberTypeAttributes = {
6301
6594
  /** Starting page number for the section */
@@ -6304,6 +6597,12 @@ export declare type IPageNumberTypeAttributes = {
6304
6597
  readonly formatType?: (typeof NumberFormat)[keyof typeof NumberFormat];
6305
6598
  /** Separator between chapter and page number (default: hyphen) */
6306
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;
6307
6606
  };
6308
6607
 
6309
6608
  /**
@@ -6444,7 +6743,11 @@ export declare type IParagraphPropertiesOptions = {
6444
6743
  export declare type IParagraphPropertiesOptionsBase = {
6445
6744
  /** Heading level (Heading1, Heading2, etc.) - applies predefined heading style */
6446
6745
  readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
6447
- /** 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
+ */
6448
6751
  readonly bidirectional?: boolean;
6449
6752
  /** Whether to insert a page break before this paragraph */
6450
6753
  readonly pageBreakBefore?: boolean;
@@ -6557,6 +6860,7 @@ export declare type IPatch = ParagraphPatch | FilePatch;
6557
6860
  * @property fonts - Font configurations
6558
6861
  * @property hyphenation - Hyphenation settings
6559
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
6560
6864
  */
6561
6865
  export declare type IPropertiesOptions = {
6562
6866
  readonly sections: readonly ISectionOptions[];
@@ -6594,6 +6898,12 @@ export declare type IPropertiesOptions = {
6594
6898
  * from Office 2016 to 2021 unless the options change it
6595
6899
  */
6596
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;
6597
6907
  };
6598
6908
 
6599
6909
  /**
@@ -6747,6 +7057,8 @@ export declare type ISectionPropertiesChangeOptions = IChangedAttributesProperti
6747
7057
  * @property verticalAlign - Vertical alignment of text on page
6748
7058
  * @property column - Column layout settings
6749
7059
  * @property type - Section break type (next page, continuous, etc.)
7060
+ * @property footnoteProperties - Footnote placement and numbering
7061
+ * @property endnoteProperties - Endnote placement and numbering
6750
7062
  *
6751
7063
  * @see {@link SectionProperties}
6752
7064
  */
@@ -6784,6 +7096,10 @@ export declare type ISectionPropertiesOptionsBase = {
6784
7096
  readonly column?: IColumnsAttributes;
6785
7097
  /** Section break type (next page, continuous, even page, odd page) */
6786
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;
6787
7103
  };
6788
7104
 
6789
7105
  /**
@@ -6800,6 +7116,8 @@ declare type ISettingsOptions = {
6800
7116
  readonly trackRevisions?: boolean;
6801
7117
  /** Update fields when document is opened */
6802
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;
6803
7121
  /** Compatibility settings for older Word versions */
6804
7122
  readonly compatibility?: ICompatibilityOptions;
6805
7123
  /** Default distance between tab stops in twips */
@@ -6821,6 +7139,14 @@ export declare type IShadingAttributesProperties = {
6821
7139
  readonly type?: (typeof ShadingType)[keyof typeof ShadingType];
6822
7140
  };
6823
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
+
6824
7150
  /**
6825
7151
  * Properties for configuring paragraph spacing.
6826
7152
  *
@@ -6923,9 +7249,9 @@ export declare type IStylesOptions = {
6923
7249
  readonly default?: IDefaultStylesOptions;
6924
7250
  /** Initial base XML component for styles root element */
6925
7251
  readonly initialStyles?: BaseXmlComponent;
6926
- /** 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 */
6927
7253
  readonly paragraphStyles?: readonly IParagraphStyleOptions[];
6928
- /** 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 */
6929
7255
  readonly characterStyles?: readonly ICharacterStyleOptions[];
6930
7256
  /** Array of styles imported from external sources */
6931
7257
  readonly importedStyles?: readonly (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
@@ -7353,8 +7679,10 @@ export declare type ITableOptions = {
7353
7679
  * Widths of the grid columns (`w:tblGrid`) in twips (twentieths of a point).
7354
7680
  *
7355
7681
  * Word treats the grid as a hint and lays the table out from `width` and the cells'
7356
- * widths, but Google Docs, Apple Pages and QuickLook lay the table out from the grid
7357
- * 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`
7358
7686
  * and the cells' widths, resolved against the page (or, for nested tables, the
7359
7687
  * parent cell) when the document is packed, so the table renders the same in every
7360
7688
  * consumer. Supply explicit values to take full control of the grid.
@@ -9118,6 +9446,31 @@ export declare type NonVisualDrawingPropertiesOptions = DrawingLinkOptions & {
9118
9446
  readonly title?: string;
9119
9447
  };
9120
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
+
9121
9474
  /**
9122
9475
  * Creates a field/cross reference to a numbered item in the document.
9123
9476
  *
@@ -9259,6 +9612,7 @@ export declare const NumberFormat: {
9259
9612
  readonly THAI_COUNTING: "thaiCounting";
9260
9613
  readonly BAHT_TEXT: "bahtText";
9261
9614
  readonly DOLLAR_TEXT: "dollarText";
9615
+ readonly CUSTOM: "custom";
9262
9616
  };
9263
9617
 
9264
9618
  /**
@@ -9652,6 +10006,7 @@ export declare class PackagePart {
9652
10006
  private readonly addedTo;
9653
10007
  /**
9654
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
9655
10010
  */
9656
10011
  constructor(options: PackagePartOptions);
9657
10012
  /**
@@ -9696,7 +10051,7 @@ declare class PackageParts {
9696
10051
  /**
9697
10052
  * @param contentTypes - Where each part's content type is added
9698
10053
  * @param existingPaths - The paths under word/ of the parts the package already has, such as a template's charts,
9699
- * which new parts are numbered after
10054
+ * which new parts don't take
9700
10055
  */
9701
10056
  constructor(contentTypes: Pick<ContentTypes, "addOverride">, existingPaths?: ReadonlySet<string>);
9702
10057
  /**
@@ -10010,6 +10365,32 @@ export declare class PageNumberElement extends EmptyElement {
10010
10365
  constructor();
10011
10366
  }
10012
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
+
10013
10394
  /**
10014
10395
  * Specifies the separator character between chapter number and page number.
10015
10396
  *
@@ -10037,7 +10418,7 @@ export declare const PageNumberSeparator: {
10037
10418
  readonly COLON: "colon";
10038
10419
  /** Em dash separator (—) */
10039
10420
  readonly EM_DASH: "emDash";
10040
- /** En dash separator (–) */
10421
+ /** En dash separator (–), written as `enDash` */
10041
10422
  readonly EN_DASH: "endash";
10042
10423
  };
10043
10424
 
@@ -10080,6 +10461,10 @@ export declare const PageOrientation: {
10080
10461
  * The PAGEREF field displays the page number of the page containing
10081
10462
  * the specified bookmark, useful for cross-references like "see page 5".
10082
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
+ *
10083
10468
  * @publicApi
10084
10469
  *
10085
10470
  * @example
@@ -10176,6 +10561,24 @@ export declare class Paragraph extends FileChild {
10176
10561
  private readonly properties;
10177
10562
  constructor(options: string | IParagraphOptions);
10178
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;
10179
10582
  addRunToFront(run: Run): Paragraph;
10180
10583
  }
10181
10584
 
@@ -10318,6 +10721,21 @@ export declare class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
10318
10721
  * @param item - The XML component to add to the paragraph properties
10319
10722
  */
10320
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;
10321
10739
  /**
10322
10740
  * Prepares the paragraph properties for XML serialization.
10323
10741
  *
@@ -10440,7 +10858,7 @@ declare type PatchDetectorOptions = {
10440
10858
  *
10441
10859
  * @publicApi
10442
10860
  */
10443
- 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]>;
10444
10862
 
10445
10863
  /**
10446
10864
  * Options for patching a document.
@@ -10451,6 +10869,9 @@ export declare const patchDocument: <T extends PatchDocumentOutputType = PatchDo
10451
10869
  * @property keepOriginalStyles - Whether to preserve original text formatting
10452
10870
  * @property placeholderDelimiters - Custom delimiter characters for placeholders
10453
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
10454
10875
  */
10455
10876
  export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = PatchDocumentOutputType> = {
10456
10877
  /** Output format type */
@@ -10458,10 +10879,10 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
10458
10879
  /** Input document data */
10459
10880
  readonly data: InputDataType;
10460
10881
  /**
10461
- * Mapping of placeholder keys to patch content, or to a {@link DrawingPatch}, such as `docx/charts`' `ChartDataPatch`,
10462
- * 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
10463
10884
  */
10464
- readonly patches: Readonly<Record<string, IPatch | DrawingPatch>>;
10885
+ readonly patches: Readonly<Record<string, IPatch | TableRowsPatch | DrawingPatch>>;
10465
10886
  /** Preserve original formatting of replaced text (default: true) */
10466
10887
  readonly keepOriginalStyles?: boolean;
10467
10888
  /** Custom placeholder delimiters (default: {{ and }}) */
@@ -10471,6 +10892,23 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
10471
10892
  }>;
10472
10893
  /** Replace every occurrence of a placeholder in a paragraph, rather than only the first (default: true) */
10473
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;
10474
10912
  };
10475
10913
 
10476
10914
  /**
@@ -10478,6 +10916,27 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
10478
10916
  */
10479
10917
  export declare type PatchDocumentOutputType = OutputType;
10480
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
+
10481
10940
  /**
10482
10941
  * Patch type enumeration.
10483
10942
  *
@@ -10490,6 +10949,11 @@ export declare const PatchType: {
10490
10949
  readonly DOCUMENT: "file";
10491
10950
  /** Replace content within paragraphs (inline replacement) */
10492
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";
10493
10957
  /**
10494
10958
  * Change a drawing whose alt text holds the placeholder, and the parts it refers to, such as the data of a chart made
10495
10959
  * in Word. See {@link DrawingPatch}
@@ -10796,6 +11260,16 @@ declare class Relationships extends XmlComponent {
10796
11260
  * @param targetMode - Optional mode indicating if target is external
10797
11261
  */
10798
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;
10799
11273
  /**
10800
11274
  * Gets the count of relationships in this collection.
10801
11275
  * Excludes the attributes element from the count.
@@ -11123,7 +11597,7 @@ export declare class SectionProperties extends XmlComponent {
11123
11597
  * the width of a single column. Percentage table widths are resolved against it.
11124
11598
  */
11125
11599
  private readonly availableTextWidth;
11126
- 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);
11127
11601
  /**
11128
11602
  * Width, in twips, available to block-level content (paragraphs and tables) in this section.
11129
11603
  *
@@ -11198,6 +11672,10 @@ export declare class Separator extends EmptyElement {
11198
11672
  * Each identifier maintains its own sequence, allowing you to have separate numbering
11199
11673
  * for figures, tables, equations, etc.
11200
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
+ *
11201
11679
  * Reference: http://officeopenxml.com/WPrun.php
11202
11680
  *
11203
11681
  * @publicApi
@@ -11239,6 +11717,7 @@ export declare class SequentialIdentifier extends Run {
11239
11717
  * ```xml
11240
11718
  * <xsd:complexType name="CT_Settings">
11241
11719
  * <xsd:sequence>
11720
+ * <xsd:element name="embedTrueTypeFonts" type="CT_OnOff" minOccurs="0"/>
11242
11721
  * <xsd:element name="trackRevisions" type="CT_OnOff" minOccurs="0"/>
11243
11722
  * <xsd:element name="defaultTabStop" type="CT_TwipsMeasure" minOccurs="0"/>
11244
11723
  * <xsd:element name="autoHyphenation" type="CT_OnOff" minOccurs="0"/>
@@ -11426,10 +11905,13 @@ export declare const signedTwipsMeasureValue: (val: UniversalMeasure | number) =
11426
11905
  *
11427
11906
  * // Simple field with cached value
11428
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 });
11429
11911
  * ```
11430
11912
  */
11431
11913
  export declare class SimpleField extends XmlComponent {
11432
- constructor(instruction: string, cachedValue?: string);
11914
+ constructor(instruction: string, cachedValue?: string, options?: ISimpleFieldOptions);
11433
11915
  }
11434
11916
 
11435
11917
  /**
@@ -11902,6 +12384,13 @@ export declare class Table extends FileChild {
11902
12384
  * serializing.
11903
12385
  */
11904
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;
11905
12394
  /**
11906
12395
  * Finds the width in twips available to this table from the serialization context:
11907
12396
  * the parent cell for a nested table, otherwise the text width of the section the
@@ -11993,7 +12482,14 @@ export declare class TableCell extends XmlComponent {
11993
12482
  readonly options: WithHexColors<Omit<ITableCellOptions, "revision">> & {
11994
12483
  readonly revision?: WithHexColors<NonNullable<ITableCellOptions["revision"]>>;
11995
12484
  };
12485
+ private readonly properties;
11996
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;
11997
12493
  prepForXml(context: IContext): IXmlableObject | undefined;
11998
12494
  }
11999
12495
 
@@ -12065,6 +12561,12 @@ export declare const TableLayoutType: {
12065
12561
  * TableOfContents creates an auto-generated list of document headings
12066
12562
  * with page numbers. It uses a TOC field code to generate entries.
12067
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
+ *
12068
12570
  * Reference: http://officeopenxml.com/WPtableOfContents.php
12069
12571
  *
12070
12572
  * @publicApi
@@ -12089,6 +12591,8 @@ export declare const TableLayoutType: {
12089
12591
  * ```
12090
12592
  */
12091
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?;
12092
12596
  constructor(alias?: string, { contentChildren, cachedEntries, beginDirty, ...properties }?: ITableOfContentsOptions & {
12093
12597
  readonly contentChildren?: readonly (XmlComponent | string)[];
12094
12598
  /**
@@ -12097,8 +12601,20 @@ export declare class TableOfContents extends FileChild {
12097
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)
12098
12602
  */
12099
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
+ */
12100
12609
  readonly beginDirty?: boolean;
12101
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;
12102
12618
  private getTabStopsForLevel;
12103
12619
  private buildCachedContentRun;
12104
12620
  private buildCachedContentParagraphChild;
@@ -12190,6 +12706,52 @@ export declare class TableRowPropertiesChange extends XmlComponent {
12190
12706
  constructor(options: ITableRowPropertiesChangeOptions);
12191
12707
  }
12192
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
+
12193
12755
  export declare type TableVerticalAlign = (typeof VerticalAlignTable)[keyof typeof VerticalAlignTable];
12194
12756
 
12195
12757
  /**
@@ -12328,6 +12890,17 @@ export declare type TemplatePackage = {
12328
12890
  readonly format: (content: XmlComponent) => Element_2;
12329
12891
  };
12330
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
+
12331
12904
  /**
12332
12905
  * A part of a template's package, as a {@link DrawingPatch} sees it.
12333
12906
  *