docx 9.9.0 → 9.11.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
@@ -1307,7 +1307,26 @@ declare const CompoundLine: {
1307
1307
  */
1308
1308
  export declare class ConcreteHyperlink extends XmlComponent {
1309
1309
  readonly linkId: string;
1310
- constructor(children: readonly ParagraphChild[], relationshipId: string, anchor?: string);
1310
+ private readonly drawingLink?;
1311
+ /**
1312
+ * @param children - Inline content of the hyperlink
1313
+ * @param relationshipId - Id of the external relationship, without the rId prefix
1314
+ * @param anchor - Bookmark name or external URL fragment
1315
+ * @param externalLink - The full address of an external hyperlink, so the relationship id is kept alongside its anchor
1316
+ */
1317
+ constructor(children: readonly ParagraphChild[], relationshipId: string, anchor?: string, externalLink?: string);
1318
+ /**
1319
+ * Creates the `a:hlinkClick` of a picture in the hyperlink, which links to the same address.
1320
+ *
1321
+ * The hyperlink decides which relationship its pictures use, rather than the pictures reading `linkId`, because only it
1322
+ * knows whether that relationship has lost the fragment to `w:anchor`. The picture's relationship is added as the
1323
+ * picture is written, through the context's relationships, so it lands in the part the picture is in, both when
1324
+ * packing and when patching.
1325
+ *
1326
+ * @param context - The context the picture is written in, whose relationships get the picture's link if it has its own
1327
+ * @param declareNamespace - Declares the DrawingML namespace, for elements outside `a:graphic` such as `wp:docPr`
1328
+ */
1329
+ createDrawingClick(context: IContext, declareNamespace: boolean): XmlComponent;
1311
1330
  }
1312
1331
 
1313
1332
  /**
@@ -3465,6 +3484,23 @@ export declare type EffectExtentAttributes = {
3465
3484
  */
3466
3485
  export declare const eighthPointMeasureValue: (val: number) => number;
3467
3486
 
3487
+ /**
3488
+ * A font file the document embeds: one face of one of its fonts, with the unique key it is obfuscated with.
3489
+ *
3490
+ * @property name - Font family name
3491
+ * @property data - Font file data of the face
3492
+ * @property bold - Whether the face is bold
3493
+ * @property italic - Whether the face is italic
3494
+ * @property fontKey - Unique key (GUID) the file is obfuscated with
3495
+ */
3496
+ declare type EmbeddedFontFile = {
3497
+ readonly name: string;
3498
+ readonly data: Buffer;
3499
+ readonly bold: boolean;
3500
+ readonly italic: boolean;
3501
+ readonly fontKey: string;
3502
+ };
3503
+
3468
3504
  /**
3469
3505
  * A file of a package that is embedded in the document, such as a sheet of an embedded workbook.
3470
3506
  */
@@ -3581,8 +3617,33 @@ export declare class EndnoteReference extends EmptyElement {
3581
3617
  constructor();
3582
3618
  }
3583
3619
 
3620
+ /**
3621
+ * A run with an endnote's reference mark, its number, in the document's text.
3622
+ *
3623
+ * It refers to one of the document's `endnotes` by its id, or is given its endnote's content, for an endnote of its
3624
+ * own, which is added to the document's endnotes when the run is written.
3625
+ *
3626
+ * @publicApi
3627
+ *
3628
+ * @example
3629
+ * ```typescript
3630
+ * new Paragraph({
3631
+ * children: [new TextRun("A claim"), new EndnoteReferenceRun({ children: [new Paragraph("Its source.")] })],
3632
+ * });
3633
+ * ```
3634
+ */
3584
3635
  export declare class EndnoteReferenceRun extends Run {
3585
- constructor(id: number);
3636
+ private readonly endnote?;
3637
+ /**
3638
+ * @param endnote - The id of one of the document's `endnotes`, or the endnote's content, for an endnote of the run's
3639
+ * own. Word has endnotes only in a document's body, so a run with its endnote's content is left out of headers,
3640
+ * footers, comments and notes
3641
+ */
3642
+ constructor(endnote: number | NoteContent);
3643
+ /**
3644
+ * Formats the run, with its own endnote added to the document's endnotes, and referred to by the id it has there.
3645
+ */
3646
+ prepForXml(context: IContext): IXmlableObject | undefined;
3586
3647
  }
3587
3648
 
3588
3649
  export declare class EndnoteReferenceRunAttributes extends XmlAttributeComponent<{
@@ -3594,8 +3655,22 @@ export declare class EndnoteReferenceRunAttributes extends XmlAttributeComponent
3594
3655
  }
3595
3656
 
3596
3657
  export declare class Endnotes extends XmlComponent {
3658
+ private readonly ownNotes;
3659
+ private highestId;
3597
3660
  constructor();
3598
3661
  createEndnote(id: number, paragraph: readonly Paragraph[]): void;
3662
+ /**
3663
+ * The id of the endnote that a reference run brings with it, which is added to the endnotes the first time the run
3664
+ * is written, with an id no other endnote has. Word has endnotes only in a document's body, so a run written
3665
+ * anywhere else, such as in a header, has none, and its endnote isn't added.
3666
+ *
3667
+ * @internal
3668
+ * @param reference - The run, which has the same endnote each time it is written
3669
+ * @param endnote - The endnote's content
3670
+ * @param context - The context the run is written in
3671
+ * @returns The endnote's id, or undefined outside the document's body
3672
+ */
3673
+ idOf(reference: object, endnote: NoteContent, context: IContext): number | undefined;
3599
3674
  /**
3600
3675
  * Formats the endnotes, with the page numbers worked out for their document written into their fields, when the
3601
3676
  * document's body is written with an estimate of its pages.
@@ -3657,6 +3732,11 @@ export declare type EstimatedPageNumbers = {
3657
3732
  * External hyperlinks create a relationship to an external resource (URL).
3658
3733
  * The relationship is created during document preparation and the hyperlink
3659
3734
  * is converted to a ConcreteHyperlink with the relationship ID.
3735
+ * URL fragments of at most 255 UTF-16 units are written as anchors, preserving any additional # characters.
3736
+ * Longer fragments stay in the original relationship URI to avoid exceeding Word's anchor limit;
3737
+ * those links retain the existing limitations for fragments with multiple # characters.
3738
+ * Word appends the anchor to the relationship target as described in MS-OI29500 §17.16.22:
3739
+ * https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oi29500/df06e423-11a6-4a36-bfb3-82139e531781
3660
3740
  *
3661
3741
  * Reference: http://officeopenxml.com/WPhyperlink.php
3662
3742
  *
@@ -3670,6 +3750,7 @@ export declare type EstimatedPageNumbers = {
3670
3750
  * <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded"/>
3671
3751
  * <xsd:attribute ref="r:id"/>
3672
3752
  * <xsd:attribute name="history" type="s:ST_OnOff" use="optional"/>
3753
+ * <xsd:attribute name="anchor" type="s:ST_String" use="optional"/>
3673
3754
  * </xsd:complexType>
3674
3755
  * ```
3675
3756
  *
@@ -3908,14 +3989,20 @@ export declare const fillSequenceNumbers: (body: IXmlableObject, context: IConte
3908
3989
  declare type FontOptions = {
3909
3990
  /** Font family name */
3910
3991
  readonly name: string;
3911
- /** Font file data (TTF, OTF, etc.) */
3992
+ /** Font file data (TTF, OTF, etc.) of the regular face */
3912
3993
  readonly data: Buffer;
3994
+ /** Font file data of the bold face, embedded as `w:embedBold` */
3995
+ readonly bold?: Buffer;
3996
+ /** Font file data of the italic face, embedded as `w:embedItalic` */
3997
+ readonly italic?: Buffer;
3998
+ /** Font file data of the bold italic face, embedded as `w:embedBoldItalic` */
3999
+ readonly boldItalic?: Buffer;
3913
4000
  /** Character set/encoding for the font */
3914
4001
  readonly characterSet?: (typeof CharacterSet)[keyof typeof CharacterSet];
3915
4002
  };
3916
4003
 
3917
4004
  /**
3918
- * Font options extended with a unique font key.
4005
+ * Font options extended with the unique key of the regular face's file.
3919
4006
  */
3920
4007
  declare type FontOptionsWithKey = FontOptions & {
3921
4008
  readonly fontKey: string;
@@ -3925,12 +4012,13 @@ declare type FontOptionsWithKey = FontOptions & {
3925
4012
  * Wrapper class for managing the font table and its relationships.
3926
4013
  *
3927
4014
  * Creates a font table with embedded font files and manages the relationships
3928
- * required for font embedding. Each font is assigned a unique key for obfuscation.
4015
+ * required for font embedding. Each face of a font is embedded as a file of its own,
4016
+ * with a unique key for obfuscation.
3929
4017
  *
3930
4018
  * @example
3931
4019
  * ```typescript
3932
4020
  * const fontWrapper = new FontWrapper([
3933
- * { name: "CustomFont", data: fontBuffer }
4021
+ * { name: "CustomFont", data: fontBuffer, bold: boldFontBuffer }
3934
4022
  * ]);
3935
4023
  * ```
3936
4024
  */
@@ -3938,7 +4026,10 @@ declare class FontWrapper implements IViewWrapper {
3938
4026
  readonly options: readonly FontOptions[];
3939
4027
  private readonly fontTable;
3940
4028
  private readonly relationships;
4029
+ /** @deprecated Use `files`, which has the file and key of each face a font embeds, not only the regular face's key */
3941
4030
  readonly fontOptionsWithKey: readonly FontOptionsWithKey[];
4031
+ /** The files of the faces the fonts embed, in order: the Nth is `fonts/font<N>.odttf`, with the relationship `rId<N>` */
4032
+ readonly files: readonly EmbeddedFontFile[];
3942
4033
  constructor(options: readonly FontOptions[]);
3943
4034
  get View(): XmlComponent;
3944
4035
  get Relationships(): Relationships;
@@ -4110,6 +4201,10 @@ export declare class FootnoteReferenceElement extends EmptyElement {
4110
4201
  * (typically a superscript number) that appears in the main document text.
4111
4202
  * Clicking this marker navigates to the corresponding footnote content.
4112
4203
  *
4204
+ * It refers to one of the document's `footnotes` by its id, or is given its footnote's content, for a footnote of its
4205
+ * own, which is added to the document's footnotes when the run is written. Content made before the document it goes
4206
+ * in, such as by a function that makes paragraphs, then brings its footnotes with it.
4207
+ *
4113
4208
  * Reference: http://officeopenxml.com/WPfootnotes.php
4114
4209
  *
4115
4210
  * @publicApi
@@ -4123,15 +4218,30 @@ export declare class FootnoteReferenceElement extends EmptyElement {
4123
4218
  * new FootnoteReferenceRun(1),
4124
4219
  * ],
4125
4220
  * });
4221
+ *
4222
+ * // Or with the footnote's content
4223
+ * new Paragraph({
4224
+ * children: [
4225
+ * new TextRun("This text has a footnote of its own"),
4226
+ * new FootnoteReferenceRun({ children: [new Paragraph("The footnote.")] }),
4227
+ * ],
4228
+ * });
4126
4229
  * ```
4127
4230
  */
4128
4231
  export declare class FootnoteReferenceRun extends Run {
4232
+ private readonly footnote?;
4129
4233
  /**
4130
4234
  * Creates a new footnote reference run.
4131
4235
  *
4132
- * @param id - Unique identifier linking to the footnote content
4236
+ * @param footnote - The id of one of the document's `footnotes`, or the footnote's content, for a footnote of the
4237
+ * run's own. Word has footnotes only in a document's body, so a run with its footnote's content is left out of
4238
+ * headers, footers, comments and notes
4133
4239
  */
4134
- constructor(id: number);
4240
+ constructor(footnote: number | NoteContent);
4241
+ /**
4242
+ * Formats the run, with its own footnote added to the document's footnotes, and referred to by the id it has there.
4243
+ */
4244
+ prepForXml(context: IContext): IXmlableObject | undefined;
4135
4245
  }
4136
4246
 
4137
4247
  /**
@@ -4191,6 +4301,8 @@ export declare class FootNoteReferenceRunAttributes extends XmlAttributeComponen
4191
4301
  * ```
4192
4302
  */
4193
4303
  export declare class FootNotes extends XmlComponent {
4304
+ private readonly ownNotes;
4305
+ private highestId;
4194
4306
  constructor();
4195
4307
  /**
4196
4308
  * Creates and adds a new footnote to the collection.
@@ -4199,6 +4311,18 @@ export declare class FootNotes extends XmlComponent {
4199
4311
  * @param paragraph - Array of paragraphs that make up the footnote content
4200
4312
  */
4201
4313
  createFootNote(id: number, paragraph: readonly Paragraph[]): void;
4314
+ /**
4315
+ * The id of the footnote that a reference run brings with it, which is added to the footnotes the first time the
4316
+ * run is written, with an id no other footnote has. Word has footnotes only in a document's body, so a run written
4317
+ * anywhere else, such as in a header, has none, and its footnote isn't added.
4318
+ *
4319
+ * @internal
4320
+ * @param reference - The run, which has the same footnote each time it is written
4321
+ * @param footnote - The footnote's content
4322
+ * @param context - The context the run is written in
4323
+ * @returns The footnote's id, or undefined outside the document's body
4324
+ */
4325
+ idOf(reference: object, footnote: NoteContent, context: IContext): number | undefined;
4202
4326
  /**
4203
4327
  * Formats the footnotes, with the page numbers worked out for their document written into their fields, when the
4204
4328
  * document's body is written with an estimate of its pages.
@@ -6493,12 +6617,7 @@ export declare type INumberedItemReferenceOptions = {
6493
6617
  */
6494
6618
  export declare type INumberingOptions = {
6495
6619
  /** Array of numbering configurations, each with levels and a reference name. */
6496
- readonly config: readonly {
6497
- /** Array of level definitions for this numbering configuration. */
6498
- readonly levels: readonly ILevelsOptions[];
6499
- /** Unique reference name for this numbering configuration. */
6500
- readonly reference: string;
6501
- }[];
6620
+ readonly config: readonly NumberingDefinition[];
6502
6621
  };
6503
6622
 
6504
6623
  /**
@@ -6814,8 +6933,13 @@ export declare type IParagraphStylePropertiesOptions = {
6814
6933
  readonly shading?: IShadingAttributesProperties;
6815
6934
  /** Numbering configuration for lists, or false to remove numbering */
6816
6935
  readonly numbering?: {
6817
- /** Reference ID of the numbering definition to use */
6818
- readonly reference: string;
6936
+ /**
6937
+ * The list the paragraph is in: the reference of one of the document's `numbering` configs, or a list's
6938
+ * definition, its reference and its levels, for a list the document's `numbering` option doesn't have.
6939
+ * The definition is added to the document's numbering when the paragraph is written, unless it already has
6940
+ * a list with that reference, which is kept
6941
+ */
6942
+ readonly reference: string | NumberingDefinition;
6819
6943
  /** Level in the numbering hierarchy (0-8) */
6820
6944
  readonly level: number;
6821
6945
  /** Instance number for multiple lists with same reference */
@@ -6993,7 +7117,13 @@ export declare type IRunStylePropertiesOptions = {
6993
7117
  readonly language?: ILanguageOptions;
6994
7118
  readonly border?: IBorderOptions;
6995
7119
  readonly snapToGrid?: boolean;
7120
+ /** Hides the text. `false` shows text that the run's style hides. */
6996
7121
  readonly vanish?: boolean;
7122
+ /**
7123
+ * Keeps a hidden paragraph mark hidden even when hidden text is shown, so its paragraph always runs on into the next one,
7124
+ * as Word's style separator does. It is meant for a paragraph's mark, with `vanish`:
7125
+ * `new Paragraph({ run: { vanish: true, specVanish: true } })`. Without `vanish`, Word doesn't hide the mark.
7126
+ */
6997
7127
  readonly specVanish?: boolean;
6998
7128
  readonly scale?: number;
6999
7129
  readonly math?: boolean;
@@ -7756,7 +7886,12 @@ export declare type ITableRowPropertiesOptions = ITableRowPropertiesOptionsBase
7756
7886
  export declare type ITableRowPropertiesOptionsBase = {
7757
7887
  /** Whether the row can be split across pages (cantSplit) */
7758
7888
  readonly cantSplit?: boolean;
7759
- /** Whether the row should be repeated as a header row on each page (tblHeader) */
7889
+ /**
7890
+ * Whether the row should be repeated as a header row on each page (tblHeader).
7891
+ *
7892
+ * Only the table's first row and the rows straight after it that also set this repeat. Word ignores it on
7893
+ * any row further down, so to repeat a different header for each part of a table, make each part a table of its own.
7894
+ */
7760
7895
  readonly tableHeader?: boolean;
7761
7896
  /** Row height configuration (trHeight) */
7762
7897
  readonly height?: {
@@ -8443,9 +8578,9 @@ export declare const LineNumberRestartFormat: {
8443
8578
  export declare const LineRuleType: {
8444
8579
  /** Line spacing is at least the specified value */
8445
8580
  readonly AT_LEAST: "atLeast";
8446
- /** Line spacing is exactly the specified value */
8581
+ /** Writes `exactly`, which isn't a value the schema allows, so Word ignores it. Use {@link LineRuleType.EXACT} for an exact line height. */
8447
8582
  readonly EXACTLY: "exactly";
8448
- /** Line spacing is exactly the specified value (alias for EXACTLY) */
8583
+ /** Line spacing is exactly the specified value */
8449
8584
  readonly EXACT: "exact";
8450
8585
  /** Line spacing is automatically determined based on content */
8451
8586
  readonly AUTO: "auto";
@@ -9446,6 +9581,18 @@ export declare type NonVisualDrawingPropertiesOptions = DrawingLinkOptions & {
9446
9581
  readonly title?: string;
9447
9582
  };
9448
9583
 
9584
+ /**
9585
+ * A footnote's or endnote's content: its paragraphs.
9586
+ *
9587
+ * A {@link FootnoteReferenceRun} or {@link EndnoteReferenceRun} can be given its note's content, rather than the id of
9588
+ * one of the document's `footnotes` or `endnotes`, for a note of its own. The note is added to the document's notes,
9589
+ * with an id none of them has, when the run is written in the document's body.
9590
+ */
9591
+ export declare type NoteContent = {
9592
+ /** The note's paragraphs */
9593
+ readonly children: readonly Paragraph[];
9594
+ };
9595
+
9449
9596
  /**
9450
9597
  * When the footnote or endnote numbering restarts.
9451
9598
  *
@@ -9709,8 +9856,11 @@ export declare class Numbering extends XmlComponent {
9709
9856
  *
9710
9857
  * @param reference - The reference name of the abstract numbering definition
9711
9858
  * @param instance - The instance number for this concrete numbering
9859
+ * @param definition - The list's definition, for a list a paragraph gives its own definition of. It is added with
9860
+ * its reference, unless the numbering already has a list with that reference, such as one of the document's
9861
+ * `numbering` option, which is kept
9712
9862
  */
9713
- createConcreteNumberingInstance(reference: string, instance: number): void;
9863
+ createConcreteNumberingInstance(reference: string, instance: number, definition?: NumberingDefinition): void;
9714
9864
  /**
9715
9865
  * Gets all concrete numbering instances.
9716
9866
  *
@@ -9725,6 +9875,22 @@ export declare class Numbering extends XmlComponent {
9725
9875
  get ReferenceConfig(): readonly Record<string, any>[];
9726
9876
  }
9727
9877
 
9878
+ /**
9879
+ * A list's definition: its reference and its levels.
9880
+ *
9881
+ * A document's `numbering` option has a definition for each of its lists. A paragraph can also be given a list's
9882
+ * definition as its `numbering`'s `reference`, for a list the document's `numbering` option doesn't have, which is added
9883
+ * to the document's numbering when the paragraph is written.
9884
+ *
9885
+ * @see {@link Numbering}
9886
+ */
9887
+ export declare type NumberingDefinition = {
9888
+ /** Array of level definitions for this numbering configuration. */
9889
+ readonly levels: readonly ILevelsOptions[];
9890
+ /** Unique reference name for this numbering configuration. */
9891
+ readonly reference: string;
9892
+ };
9893
+
9728
9894
  /**
9729
9895
  * Represents numbering properties for a paragraph.
9730
9896
  *
@@ -10858,7 +11024,7 @@ declare type PatchDetectorOptions = {
10858
11024
  *
10859
11025
  * @publicApi
10860
11026
  */
10861
- export declare const patchDocument: <T extends PatchDocumentOutputType = PatchDocumentOutputType>({ outputType, data, patches, keepOriginalStyles, placeholderDelimiters, recursive, footnotes, endnotes, pageNumbers, }: PatchDocumentOptions<T>) => Promise<OutputByType[T]>;
11027
+ export declare const patchDocument: <T extends PatchDocumentOutputType = PatchDocumentOutputType>({ outputType, data, patches, keepOriginalStyles, placeholderDelimiters, recursive, footnotes, endnotes, numbering, pageNumbers, }: PatchDocumentOptions<T>) => Promise<OutputByType[T]>;
10862
11028
 
10863
11029
  /**
10864
11030
  * Options for patching a document.
@@ -10871,6 +11037,7 @@ export declare const patchDocument: <T extends PatchDocumentOutputType = PatchDo
10871
11037
  * @property recursive - Whether to replace every occurrence of a placeholder in a paragraph, rather than only the first
10872
11038
  * @property footnotes - The footnotes that patches refer to with a `FootnoteReferenceRun`
10873
11039
  * @property endnotes - The endnotes that patches refer to with an `EndnoteReferenceRun`
11040
+ * @property numbering - The lists that the paragraphs in patches use, by their references
10874
11041
  * @property pageNumbers - Works out the page each bookmark is on, to write the page numbers of page references
10875
11042
  */
10876
11043
  export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = PatchDocumentOutputType> = {
@@ -10903,6 +11070,12 @@ export declare type PatchDocumentOptions<T extends PatchDocumentOutputType = Pat
10903
11070
  readonly endnotes?: Readonly<Record<string, {
10904
11071
  readonly children: readonly Paragraph[];
10905
11072
  }>>;
11073
+ /**
11074
+ * The lists that the paragraphs in patches use, as in a `Document`. A paragraph is put in one with
11075
+ * `numbering: { reference, level }`. Each list that patches use is added to the document's numbering, with ids that
11076
+ * none of the template's lists have, and so is the bullet list of `bullet` paragraphs
11077
+ */
11078
+ readonly numbering?: INumberingOptions;
10906
11079
  /**
10907
11080
  * Works out the page each bookmark of the patched document is on, and how many pages it has, so the page numbers of
10908
11081
  * its tables of contents and page references, and its numbers of pages, are written with it, rather than left as they