diff --git a/api/classes/index.AbstractNumbering.html b/api/classes/index.AbstractNumbering.html
index 1e9f020525..f85faf202f 100644
--- a/api/classes/index.AbstractNumbering.html
+++ b/api/classes/index.AbstractNumbering.html
@@ -18,24 +18,24 @@ bulleted lists that can be referenced by concrete numbering instances.
Each abstract definition can contain up to 9 levels.
diff --git a/api/classes/index.Body.html b/api/classes/index.Body.html
index 30b25bac62..c039eaa863 100644
--- a/api/classes/index.Body.html
+++ b/api/classes/index.Body.html
@@ -20,24 +20,24 @@ have its section properties stored in a paragraph's properties at the end of tha
section. The last section's properties are stored as a direct child of the body element.
diff --git a/api/classes/index.Bookmark.html b/api/classes/index.Bookmark.html
index 67689f7769..23ec0d550a 100644
--- a/api/classes/index.Bookmark.html
+++ b/api/classes/index.Bookmark.html
@@ -21,17 +21,17 @@ of a start marker, content, and an end marker.
diff --git a/api/classes/index.BookmarkEnd.html b/api/classes/index.BookmarkEnd.html
index c42e2267a2..07435989ec 100644
--- a/api/classes/index.BookmarkEnd.html
+++ b/api/classes/index.BookmarkEnd.html
@@ -18,7 +18,7 @@ It must be paired with a corresponding BookmarkStart element with the same id,
taken from bookmarkUniqueNumericId (see BookmarkStart).
diff --git a/api/classes/index.BookmarkStart.html b/api/classes/index.BookmarkStart.html
index 0a1b6039e3..768126c8f9 100644
--- a/api/classes/index.BookmarkStart.html
+++ b/api/classes/index.BookmarkStart.html
@@ -20,24 +20,24 @@ It must be paired with a corresponding BookmarkEnd element with the same id.
same as a Bookmark's.
diff --git a/api/classes/index.CellMerge.html b/api/classes/index.CellMerge.html
index 4d449fb45a..0f4fa99f13 100644
--- a/api/classes/index.CellMerge.html
+++ b/api/classes/index.CellMerge.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.CellMergeAttributes.html b/api/classes/index.CellMergeAttributes.html
index 4ecee2f100..bb6d23ce19 100644
--- a/api/classes/index.CellMergeAttributes.html
+++ b/api/classes/index.CellMergeAttributes.html
@@ -19,18 +19,18 @@ can define an xmlKeys map to specify the transformation.
This class generates the w14:checkbox element that defines the checkbox behavior,
including its checked state and the symbols used for checked and unchecked states.
diff --git a/api/classes/index.CommentRangeEnd.html b/api/classes/index.CommentRangeEnd.html
index 6388b5d036..57094cb95f 100644
--- a/api/classes/index.CommentRangeEnd.html
+++ b/api/classes/index.CommentRangeEnd.html
@@ -20,7 +20,7 @@ Must be paired with a CommentRangeStart with the same ID.
diff --git a/api/classes/index.CommentRangeStart.html b/api/classes/index.CommentRangeStart.html
index 90870d2e3a..a71e78d048 100644
--- a/api/classes/index.CommentRangeStart.html
+++ b/api/classes/index.CommentRangeStart.html
@@ -20,7 +20,7 @@ Must be paired with a CommentRangeEnd with the same ID.
diff --git a/api/classes/index.CommentReference.html b/api/classes/index.CommentReference.html
index 7b66f0091b..95db736b3d 100644
--- a/api/classes/index.CommentReference.html
+++ b/api/classes/index.CommentReference.html
@@ -20,7 +20,7 @@ It should be placed after the CommentRangeEnd element.
diff --git a/api/classes/index.Comments.html b/api/classes/index.Comments.html
index 22c1de649b..bfb0750693 100644
--- a/api/classes/index.Comments.html
+++ b/api/classes/index.Comments.html
@@ -18,7 +18,7 @@ comment definitions in the document. When any comment uses parentId
threading is activated and thread data is generated for commentsExtended.xml.
diff --git a/api/classes/index.ConcreteHyperlink.html b/api/classes/index.ConcreteHyperlink.html
index b7e9fcd345..05350d2e9d 100644
--- a/api/classes/index.ConcreteHyperlink.html
+++ b/api/classes/index.ConcreteHyperlink.html
@@ -17,11 +17,11 @@
Use InternalHyperlink or ExternalHyperlink for creating hyperlinks in documents.
diff --git a/api/classes/index.DeletedTableCell.html b/api/classes/index.DeletedTableCell.html
index 94915c0791..7ab757e47f 100644
--- a/api/classes/index.DeletedTableCell.html
+++ b/api/classes/index.DeletedTableCell.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.DeletedTableRow.html b/api/classes/index.DeletedTableRow.html
index 2c03d4fe15..16d7318989 100644
--- a/api/classes/index.DeletedTableRow.html
+++ b/api/classes/index.DeletedTableRow.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
// Create a deleted text run newDeletedTextRun({ id:2, author:"Jane Smith", date:"2024-01-15T11:00:00Z", text:"This text was removed", italics:true });
// Deleted run with page number field newDeletedTextRun({ id:3, author:"John Doe", date:"2024-01-15T12:00:00Z", children: [PageNumber.CURRENT] });
+
Example
// Create a deleted text run newDeletedTextRun({ id:2, author:"Jane Smith", date:"2024-01-15T11:00:00Z", text:"This text was removed", italics:true });
// Deleted run with page number field newDeletedTextRun({ id:3, author:"John Doe", date:"2024-01-15T12:00:00Z", children: [PageNumber.CURRENT] });
newDocumentBackground({ color:"FFFF00" }); // Yellow background newDocumentBackground({ color: { theme:"accent1", lighter:80 } }); // A light version of the theme's first accent color
+
Example
newDocumentBackground({ color:"FFFF00" }); // Yellow background newDocumentBackground({ color: { theme:"accent1", lighter:80 } }); // A light version of the theme's first accent color
diff --git a/api/classes/index.DocumentDefaults.html b/api/classes/index.DocumentDefaults.html
index 06e2a271ba..c28e5ed357 100644
--- a/api/classes/index.DocumentDefaults.html
+++ b/api/classes/index.DocumentDefaults.html
@@ -17,24 +17,24 @@
paragraphs and runs in a document unless overridden by a style or direct formatting.
// Set default font and spacing for the document newDocumentDefaults({ run: { font:"Calibri", size:22 }, paragraph: { spacing: { after:200, line:276 } } });
+
Example
// Set default font and spacing for the document newDocumentDefaults({ run: { font:"Calibri", size:22 }, paragraph: { spacing: { after:200, line:276 } } });
diff --git a/api/classes/index.DrawingPatch.html b/api/classes/index.DrawingPatch.html
index 10bb54ceb5..9d6d2f9dbf 100644
--- a/api/classes/index.DrawingPatch.html
+++ b/api/classes/index.DrawingPatch.html
@@ -20,14 +20,14 @@ is one: it replaces the data of a chart made in Word.
diff --git a/api/classes/index.EndnoteIdReference.html b/api/classes/index.EndnoteIdReference.html
index 47e9e8f2c7..f20508bebb 100644
--- a/api/classes/index.EndnoteIdReference.html
+++ b/api/classes/index.EndnoteIdReference.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.EndnoteReferenceRun.html b/api/classes/index.EndnoteReferenceRun.html
index d70a15e28a..67f7f22172 100644
--- a/api/classes/index.EndnoteReferenceRun.html
+++ b/api/classes/index.EndnoteReferenceRun.html
@@ -24,14 +24,14 @@ own, which is added to the document's endnotes when the run is written.
diff --git a/api/classes/index.EndnoteReferenceRunAttributes.html b/api/classes/index.EndnoteReferenceRunAttributes.html
index cdbc267ec1..4eb8e5f24c 100644
--- a/api/classes/index.EndnoteReferenceRunAttributes.html
+++ b/api/classes/index.EndnoteReferenceRunAttributes.html
@@ -19,18 +19,18 @@ can define an xmlKeys map to specify the transformation.
diff --git a/api/classes/index.Endnotes.html b/api/classes/index.Endnotes.html
index 1080eadb6d..73e54bfeb5 100644
--- a/api/classes/index.Endnotes.html
+++ b/api/classes/index.Endnotes.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.ExternalHyperlink.html b/api/classes/index.ExternalHyperlink.html
index e772e97b9d..7c4c57f7eb 100644
--- a/api/classes/index.ExternalHyperlink.html
+++ b/api/classes/index.ExternalHyperlink.html
@@ -26,7 +26,7 @@ Word appends the anchor to the relationship target as described in MS-OI29500 §
The document's macros, when it has any: its VBA project (word/vbaProject.bin), the events of the document it
+handles (word/vbaData.xml), and the project's relationships, to the events.
+
+
Returns FileMacros|undefined
Media
@@ -219,7 +232,7 @@ including relationships, content types, and document properties.
diff --git a/api/classes/index.FootNotes.html b/api/classes/index.FootNotes.html
index da7b4b2170..c160ca7520 100644
--- a/api/classes/index.FootNotes.html
+++ b/api/classes/index.FootNotes.html
@@ -19,24 +19,24 @@ footnotes define the line that separates body text from footnotes and the
line used when footnotes continue across pages.
diff --git a/api/classes/index.FooterWrapper.html b/api/classes/index.FooterWrapper.html
index 00e8b8b82c..88d8587013 100644
--- a/api/classes/index.FooterWrapper.html
+++ b/api/classes/index.FooterWrapper.html
@@ -29,7 +29,7 @@ Each section can have multiple footers for different page types.
diff --git a/api/classes/index.FootnoteReferenceRun.html b/api/classes/index.FootnoteReferenceRun.html
index 62ee2e59f8..ec8614d9a2 100644
--- a/api/classes/index.FootnoteReferenceRun.html
+++ b/api/classes/index.FootnoteReferenceRun.html
@@ -25,18 +25,18 @@ in, such as by a function that makes paragraphs, then brings its footnotes with
Public Api
-
Example
// Add a footnote reference in a paragraph newParagraph({ children: [ newTextRun("This text has a footnote"), newFootnoteReferenceRun(1), ], });
// Or with the footnote's content newParagraph({ children: [ newTextRun("This text has a footnote of its own"), newFootnoteReferenceRun({ children: [newParagraph("The footnote.")] }), ], });
+
Example
// Add a footnote reference in a paragraph newParagraph({ children: [ newTextRun("This text has a footnote"), newFootnoteReferenceRun(1), ], });
// Or with the footnote's content newParagraph({ children: [ newTextRun("This text has a footnote of its own"), newFootnoteReferenceRun({ children: [newParagraph("The footnote.")] }), ], });
diff --git a/api/classes/index.GridSpan.html b/api/classes/index.GridSpan.html
index c11e0f4d26..8d9d1b1821 100644
--- a/api/classes/index.GridSpan.html
+++ b/api/classes/index.GridSpan.html
@@ -17,24 +17,24 @@
in the table grid. This is used to merge cells horizontally (column span).
diff --git a/api/classes/index.HeaderWrapper.html b/api/classes/index.HeaderWrapper.html
index e607f91053..2f6904d106 100644
--- a/api/classes/index.HeaderWrapper.html
+++ b/api/classes/index.HeaderWrapper.html
@@ -29,7 +29,7 @@ Each section can have multiple headers for different page types.
HpsMeasure elements are used for font sizes and other measurements in WordprocessingML.
Values can be specified as numbers (interpreted as half-points) or with explicit units.
diff --git a/api/classes/index.IgnoreIfEmptyXmlComponent.html b/api/classes/index.IgnoreIfEmptyXmlComponent.html
index 2bd81d9011..ab57d26f4d 100644
--- a/api/classes/index.IgnoreIfEmptyXmlComponent.html
+++ b/api/classes/index.IgnoreIfEmptyXmlComponent.html
@@ -20,11 +20,11 @@ to be excluded from the output.
diff --git a/api/classes/index.ImageRun.html b/api/classes/index.ImageRun.html
index 3960bedea0..f51bf23c13 100644
--- a/api/classes/index.ImageRun.html
+++ b/api/classes/index.ImageRun.html
@@ -26,14 +26,14 @@ including JPG, PNG, GIF, BMP, and SVG. Optionally wraps the run in
diff --git a/api/classes/index.ImportedXmlComponent.html b/api/classes/index.ImportedXmlComponent.html
index 08c5aadf85..20aacadb89 100644
--- a/api/classes/index.ImportedXmlComponent.html
+++ b/api/classes/index.ImportedXmlComponent.html
@@ -19,18 +19,18 @@ templates or when you need to include pre-existing XML fragments.
-
Example
// Parse XML string into component tree constcomponent = ImportedXmlComponent.fromXmlString( '<w:p><w:r><w:t>Hello World</w:t></w:r></w:p>' );
diff --git a/api/classes/index.InitializableXmlComponent.html b/api/classes/index.InitializableXmlComponent.html
index f8c34c7a25..311f005e5a 100644
--- a/api/classes/index.InitializableXmlComponent.html
+++ b/api/classes/index.InitializableXmlComponent.html
@@ -19,18 +19,18 @@ create a new component that shares or extends the children of an existing compon
-
Example
classMyElementextendsInitializableXmlComponent { constructor(init?: MyElement) { super("w:myElement", init); // If init is provided, this.root is copied from init // Otherwise, this.root is an empty array } }
constelement2 = newMyElement(element1); // element2 now has the same children as element1
+
Example
classMyElementextendsInitializableXmlComponent { constructor(init?: MyElement) { super("w:myElement", init); // If init is provided, this.root is copied from init // Otherwise, this.root is an empty array } }
diff --git a/api/classes/index.InsertedTableCell.html b/api/classes/index.InsertedTableCell.html
index ef0afa35ea..802312dd85 100644
--- a/api/classes/index.InsertedTableCell.html
+++ b/api/classes/index.InsertedTableCell.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.InsertedTableRow.html b/api/classes/index.InsertedTableRow.html
index 41217f56dd..5d72bf7d83 100644
--- a/api/classes/index.InsertedTableRow.html
+++ b/api/classes/index.InsertedTableRow.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.InsertedTextRun.html b/api/classes/index.InsertedTextRun.html
index 48a93268d4..dc6374e5c8 100644
--- a/api/classes/index.InsertedTextRun.html
+++ b/api/classes/index.InsertedTextRun.html
@@ -21,23 +21,23 @@ made the insertion and when.
diff --git a/api/classes/index.InternalHyperlink.html b/api/classes/index.InternalHyperlink.html
index b5ab4d36d1..54151df2e7 100644
--- a/api/classes/index.InternalHyperlink.html
+++ b/api/classes/index.InternalHyperlink.html
@@ -20,23 +20,23 @@ The bookmark must exist in the document for the hyperlink to function.
diff --git a/api/classes/index.LevelBase.html b/api/classes/index.LevelBase.html
index a17613e9e5..471e174abb 100644
--- a/api/classes/index.LevelBase.html
+++ b/api/classes/index.LevelBase.html
@@ -18,11 +18,11 @@ numbering scheme. Each level can have its own numbering format, text template,
alignment, and styling.
diff --git a/api/classes/index.MathDegree.html b/api/classes/index.MathDegree.html
index 83d8fb8242..0ed2e00b6a 100644
--- a/api/classes/index.MathDegree.html
+++ b/api/classes/index.MathDegree.html
@@ -17,18 +17,18 @@
For square roots, this element is typically hidden.
// n over k, as a binomial coefficient, in brackets newMathRoundBrackets({ children: [newMathFraction({ numerator: [newMathRun("n")], denominator: [newMathRun("k")], type:"noBar" })], });
+
// n over k, as a binomial coefficient, in brackets newMathRoundBrackets({ children: [newMathFraction({ numerator: [newMathRun("n")], denominator: [newMathRun("k")], type:"noBar" })], });
diff --git a/api/classes/index.MathFunctionName.html b/api/classes/index.MathFunctionName.html
index 5013ee509d..33ff2bfed1 100644
--- a/api/classes/index.MathFunctionName.html
+++ b/api/classes/index.MathFunctionName.html
@@ -17,18 +17,18 @@
that appears before the function argument.
diff --git a/api/classes/index.MathFunctionProperties.html b/api/classes/index.MathFunctionProperties.html
index bd7c71d596..06524357d2 100644
--- a/api/classes/index.MathFunctionProperties.html
+++ b/api/classes/index.MathFunctionProperties.html
@@ -17,18 +17,18 @@
such as function name alignment and spacing.
diff --git a/api/classes/index.MathLimitUpper.html b/api/classes/index.MathLimitUpper.html
index 848d98aca2..0f763caf95 100644
--- a/api/classes/index.MathLimitUpper.html
+++ b/api/classes/index.MathLimitUpper.html
@@ -20,23 +20,23 @@ commonly used for mathematical notation like lim with conditions above.
diff --git a/api/classes/index.MathPreSubSuperScript.html b/api/classes/index.MathPreSubSuperScript.html
index 490c312fd2..485e1f6207 100644
--- a/api/classes/index.MathPreSubSuperScript.html
+++ b/api/classes/index.MathPreSubSuperScript.html
@@ -20,23 +20,23 @@ positioned before (to the left of) the base, commonly used in tensor notation.
diff --git a/api/classes/index.MathRadicalProperties.html b/api/classes/index.MathRadicalProperties.html
index 79c8f1575c..d6ed4f17b9 100644
--- a/api/classes/index.MathRadicalProperties.html
+++ b/api/classes/index.MathRadicalProperties.html
@@ -17,18 +17,18 @@
such as whether to hide the degree (for square roots).
diff --git a/api/classes/index.MathRun.html b/api/classes/index.MathRun.html
index 43d7305b37..dfbf526668 100644
--- a/api/classes/index.MathRun.html
+++ b/api/classes/index.MathRun.html
@@ -20,7 +20,7 @@ similar to how Run contains text in regular paragraphs.
diff --git a/api/classes/index.MathSubSuperScript.html b/api/classes/index.MathSubSuperScript.html
index 3fa2572d80..12d58cf6c1 100644
--- a/api/classes/index.MathSubSuperScript.html
+++ b/api/classes/index.MathSubSuperScript.html
@@ -20,23 +20,23 @@ commonly used for tensor notation or indexed variables with exponents.
// x with subscript i and superscript 2 newMathSubSuperScript({ children: [newMathRun("x")], subScript: [newMathRun("i")], superScript: [newMathRun("2")], });
+
Example
// x with subscript i and superscript 2 newMathSubSuperScript({ children: [newMathRun("x")], subScript: [newMathRun("i")], superScript: [newMathRun("2")], });
diff --git a/api/classes/index.Media.html b/api/classes/index.Media.html
index 562cd99dbe..9f3d3c3546 100644
--- a/api/classes/index.Media.html
+++ b/api/classes/index.Media.html
@@ -24,7 +24,7 @@ is stored with a unique key for retrieval.
diff --git a/api/classes/index.NextAttributeComponent.html b/api/classes/index.NextAttributeComponent.html
index c62b73de76..4dae84a150 100644
--- a/api/classes/index.NextAttributeComponent.html
+++ b/api/classes/index.NextAttributeComponent.html
@@ -19,7 +19,7 @@ This gives more control but is more verbose than XmlAttributeComponent.
diff --git a/api/classes/index.Numbering.html b/api/classes/index.Numbering.html
index 817c8af149..4844da07e3 100644
--- a/api/classes/index.Numbering.html
+++ b/api/classes/index.Numbering.html
@@ -19,24 +19,24 @@ Each numbering configuration includes a default bullet list and any
custom numbering schemes defined by the user.
diff --git a/api/classes/index.OnOffElement.html b/api/classes/index.OnOffElement.html
index e570e73439..8bc54d74af 100644
--- a/api/classes/index.OnOffElement.html
+++ b/api/classes/index.OnOffElement.html
@@ -17,24 +17,24 @@
A value of true (or 1) means the property is enabled. A value of false (or 0) means
it is explicitly disabled. When the value is true, the attribute is often omitted.
diff --git a/api/classes/index.Packer.html b/api/classes/index.Packer.html
index 1c7b64110c..eb369f7557 100644
--- a/api/classes/index.Packer.html
+++ b/api/classes/index.Packer.html
@@ -21,12 +21,12 @@ of the document structure into OOXML format and compression into a .docx ZIP arc
Public Api
-
Example
// Export to buffer (Node.js) constbuffer = awaitPacker.toBuffer(doc);
// Export to blob (browser) constblob = awaitPacker.toBlob(doc);
// Export with prettified XML constbuffer = awaitPacker.toBuffer(doc, PrettifyType.WITH_2_BLANKS);
+
Example
// Export to buffer (Node.js) constbuffer = awaitPacker.toBuffer(doc);
// Export to blob (browser) constblob = awaitPacker.toBlob(doc);
// Export with prettified XML constbuffer = awaitPacker.toBuffer(doc, PrettifyType.WITH_2_BLANKS);
diff --git a/api/classes/index.PageBorders.html b/api/classes/index.PageBorders.html
index 71a3915fe0..f77c91a0c0 100644
--- a/api/classes/index.PageBorders.html
+++ b/api/classes/index.PageBorders.html
@@ -17,24 +17,24 @@
including which pages display the borders and how they are positioned.
diff --git a/api/classes/index.PageTextDirection.html b/api/classes/index.PageTextDirection.html
index 23cdbf508c..867e2ae59c 100644
--- a/api/classes/index.PageTextDirection.html
+++ b/api/classes/index.PageTextDirection.html
@@ -19,18 +19,18 @@ for all pages in a section.
-
Example
// Horizontal text flow (left-to-right, top-to-bottom) newPageTextDirection(PageTextDirectionType.LEFT_TO_RIGHT_TOP_TO_BOTTOM);
// Vertical text flow (top-to-bottom, right-to-left) newPageTextDirection(PageTextDirectionType.TOP_TO_BOTTOM_RIGHT_TO_LEFT);
+
Example
// Horizontal text flow (left-to-right, top-to-bottom) newPageTextDirection(PageTextDirectionType.LEFT_TO_RIGHT_TOP_TO_BOTTOM);
// Vertical text flow (top-to-bottom, right-to-left) newPageTextDirection(PageTextDirectionType.TOP_TO_BOTTOM_RIGHT_TO_LEFT);
diff --git a/api/classes/index.Paragraph.html b/api/classes/index.Paragraph.html
index abf28e31b1..f94d4cc5ca 100644
--- a/api/classes/index.Paragraph.html
+++ b/api/classes/index.Paragraph.html
@@ -20,23 +20,23 @@ various inline elements such as text runs, images, hyperlinks, and bookmarks.
diff --git a/api/classes/index.ParagraphPropertiesChange.html b/api/classes/index.ParagraphPropertiesChange.html
index 312ec5a488..4d400505e1 100644
--- a/api/classes/index.ParagraphPropertiesChange.html
+++ b/api/classes/index.ParagraphPropertiesChange.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.ParagraphPropertiesDefaults.html b/api/classes/index.ParagraphPropertiesDefaults.html
index a335822f92..3ef6f241f8 100644
--- a/api/classes/index.ParagraphPropertiesDefaults.html
+++ b/api/classes/index.ParagraphPropertiesDefaults.html
@@ -17,24 +17,24 @@
to all paragraphs in the document unless overridden.
diff --git a/api/classes/index.ParagraphRunProperties.html b/api/classes/index.ParagraphRunProperties.html
index 36ba4329cc..127587e42f 100644
--- a/api/classes/index.ParagraphRunProperties.html
+++ b/api/classes/index.ParagraphRunProperties.html
@@ -17,7 +17,7 @@
such as bold, italic, font, size, color, underline, and other text effects.
The EG_RPrBase group includes elements like rStyle, rFonts, b, bCs, i, iCs,
@@ -25,14 +25,14 @@ caps, smallCaps, strike, dstrike, outline, shadow, emboss, imprint, noProof,
snapToGrid, vanish, color, spacing, w, kern, position, sz, szCs, highlight,
u, effect, bdr, shd, vertAlign, rtl, em, lang, and more.
diff --git a/api/classes/index.PositionalTab.html b/api/classes/index.PositionalTab.html
index 1de992259b..b20916adfb 100644
--- a/api/classes/index.PositionalTab.html
+++ b/api/classes/index.PositionalTab.html
@@ -21,23 +21,23 @@ an exact alignment and position within the paragraph.
diff --git a/api/classes/index.RunProperties.html b/api/classes/index.RunProperties.html
index f525978c3e..b36bfc3a76 100644
--- a/api/classes/index.RunProperties.html
+++ b/api/classes/index.RunProperties.html
@@ -17,7 +17,7 @@
such as bold, italic, font, size, color, underline, and other text effects.
The EG_RPrBase group includes elements like rStyle, rFonts, b, bCs, i, iCs,
@@ -25,7 +25,7 @@ caps, smallCaps, strike, dstrike, outline, shadow, emboss, imprint, noProof,
snapToGrid, vanish, color, spacing, w, kern, position, sz, szCs, highlight,
u, effect, bdr, shd, vertAlign, rtl, em, lang, and more.
diff --git a/api/classes/index.RunPropertiesDefaults.html b/api/classes/index.RunPropertiesDefaults.html
index c0fecad37f..6a65ab4aaa 100644
--- a/api/classes/index.RunPropertiesDefaults.html
+++ b/api/classes/index.RunPropertiesDefaults.html
@@ -17,24 +17,24 @@
to all text runs in the document unless overridden by styles or direct formatting.
diff --git a/api/classes/index.SectionProperties.html b/api/classes/index.SectionProperties.html
index 28857165bd..241051a35b 100644
--- a/api/classes/index.SectionProperties.html
+++ b/api/classes/index.SectionProperties.html
@@ -18,24 +18,24 @@ including page size, margins, headers/footers, columns, and page numbering.
A document can contain multiple sections with different properties.
diff --git a/api/classes/index.SectionPropertiesChange.html b/api/classes/index.SectionPropertiesChange.html
index 74e112330c..59c41634c8 100644
--- a/api/classes/index.SectionPropertiesChange.html
+++ b/api/classes/index.SectionPropertiesChange.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/index.SimpleField.html b/api/classes/index.SimpleField.html
index 4ce9428a3c..cc2d9a1d2e 100644
--- a/api/classes/index.SimpleField.html
+++ b/api/classes/index.SimpleField.html
@@ -21,16 +21,16 @@ Simple fields are typically used for fields that don't require complex nesting.<
diff --git a/api/classes/index.SimpleMailMergeField.html b/api/classes/index.SimpleMailMergeField.html
index e344d57750..ceaf6ebdb3 100644
--- a/api/classes/index.SimpleMailMergeField.html
+++ b/api/classes/index.SimpleMailMergeField.html
@@ -19,18 +19,18 @@ It creates a MERGEFIELD that will be populated with data during mail merge.
-
Example
// Creates a merge field for "FirstName" newSimpleMailMergeField("FirstName"); // Renders as: MERGEFIELD FirstName with placeholder «FirstName»
+
Example
// Creates a merge field for "FirstName" newSimpleMailMergeField("FirstName"); // Renders as: MERGEFIELD FirstName with placeholder «FirstName»
diff --git a/api/classes/index.StringContainer.html b/api/classes/index.StringContainer.html
index 56a30148ea..de7acd28ce 100644
--- a/api/classes/index.StringContainer.html
+++ b/api/classes/index.StringContainer.html
@@ -19,18 +19,18 @@ rather than an attribute.
diff --git a/api/classes/index.StringEnumValueElement.html b/api/classes/index.StringEnumValueElement.html
index f9470b3955..1b9c8675a8 100644
--- a/api/classes/index.StringEnumValueElement.html
+++ b/api/classes/index.StringEnumValueElement.html
@@ -18,7 +18,7 @@ type parameter to enforce type safety for enum values.
<xsd:complexTypename="CT_Style"> <xsd:sequence> <!-- Style elements including rPr for run properties --> <xsd:elementname="rPr"type="CT_RPr"minOccurs="0"maxOccurs="1"/> </xsd:sequence> <xsd:attributename="type"type="ST_StyleType"use="optional"/> <xsd:attributename="styleId"type="s:ST_String"use="optional"/> </xsd:complexType>
+
<xsd:complexTypename="CT_Style"> <xsd:sequence> <!-- Style elements including rPr for run properties --> <xsd:elementname="rPr"type="CT_RPr"minOccurs="0"maxOccurs="1"/> </xsd:sequence> <xsd:attributename="type"type="ST_StyleType"use="optional"/> <xsd:attributename="styleId"type="s:ST_String"use="optional"/> </xsd:complexType>
-
Example
// Create a custom character style for highlighting newStyleForCharacter({ id:"Highlight", name:"Highlight Text", basedOn:"DefaultParagraphFont", run: { color:"FF0000", bold:true } });
+
Example
// Create a custom character style for highlighting newStyleForCharacter({ id:"Highlight", name:"Highlight Text", basedOn:"DefaultParagraphFont", run: { color:"FF0000", bold:true } });
diff --git a/api/classes/index.StyleLevel.html b/api/classes/index.StyleLevel.html
index 718b72ab3b..e1d2738a9a 100644
--- a/api/classes/index.StyleLevel.html
+++ b/api/classes/index.StyleLevel.html
@@ -20,7 +20,7 @@ custom styles to be included in the table of contents at specific levels.
diff --git a/api/classes/index.Styles.html b/api/classes/index.Styles.html
index b953e7504b..b337ba2dae 100644
--- a/api/classes/index.Styles.html
+++ b/api/classes/index.Styles.html
@@ -18,24 +18,24 @@ individual style definitions for paragraphs and characters. Styles provide
a way to define consistent formatting across a document.
diff --git a/api/classes/index.TDirection.html b/api/classes/index.TDirection.html
index 7730629175..24657d14db 100644
--- a/api/classes/index.TDirection.html
+++ b/api/classes/index.TDirection.html
@@ -17,24 +17,24 @@
useful for creating rotated text or supporting different writing systems.
diff --git a/api/classes/index.Table.html b/api/classes/index.Table.html
index bfc9f0afbd..c177386b9b 100644
--- a/api/classes/index.Table.html
+++ b/api/classes/index.Table.html
@@ -20,7 +20,7 @@ Tables are used to organize content into a grid structure.
diff --git a/api/classes/index.TableBorders.html b/api/classes/index.TableBorders.html
index e67f00a237..45b25e71d4 100644
--- a/api/classes/index.TableBorders.html
+++ b/api/classes/index.TableBorders.html
@@ -21,18 +21,18 @@ line, unless fillMissingSides is false, when it is left to the tabl
diff --git a/api/classes/index.TableCellBorders.html b/api/classes/index.TableCellBorders.html
index a0c1a29ddb..b1cd468001 100644
--- a/api/classes/index.TableCellBorders.html
+++ b/api/classes/index.TableCellBorders.html
@@ -17,7 +17,7 @@
can be configured independently with different styles, colors, and widths.
diff --git a/api/classes/index.TableRow.html b/api/classes/index.TableRow.html
index 6f6029aac3..a9b1ed20e0 100644
--- a/api/classes/index.TableRow.html
+++ b/api/classes/index.TableRow.html
@@ -20,7 +20,7 @@ one or more table cells that hold the actual content.
diff --git a/api/classes/index.TableRowProperties.html b/api/classes/index.TableRowProperties.html
index 965b1f89f0..9b895ddbdd 100644
--- a/api/classes/index.TableRowProperties.html
+++ b/api/classes/index.TableRowProperties.html
@@ -23,14 +23,14 @@ whether it can split across pages, and whether it's a header row.
diff --git a/api/classes/index.TableRowPropertiesChange.html b/api/classes/index.TableRowPropertiesChange.html
index 3a786d4012..30857be719 100644
--- a/api/classes/index.TableRowPropertiesChange.html
+++ b/api/classes/index.TableRowPropertiesChange.html
@@ -20,18 +20,18 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
// Textbox in a paragraph, after its text newParagraph({ children: [ newTextRun("See the note: "), newTextbox({ children: [newParagraph("A note")], style: { width:"2in", height:"auto" } }) ] });
+
Example
// Simple textbox with text newTextbox({ children: [newParagraph("Hello World")], style: { width:"3in", height:"1in" } });
// Textbox in a paragraph, after its text newParagraph({ children: [ newTextRun("See the note: "), newTextbox({ children: [newParagraph("A note")], style: { width:"2in", height:"auto" } }) ] });
// A document whose theme has a green accent and Georgia for headings constdoc = newDocument({ theme: { colors: { accent1:"2E7D32" }, fonts: { headings:"Georgia" } }, sections: [], });
+
Example
// A document whose theme has a green accent and Georgia for headings constdoc = newDocument({ theme: { colors: { accent1:"2E7D32" }, fonts: { headings:"Georgia" } }, sections: [], });
diff --git a/api/classes/index.VerticalMerge.html b/api/classes/index.VerticalMerge.html
index b2a8885e90..f3292bfb05 100644
--- a/api/classes/index.VerticalMerge.html
+++ b/api/classes/index.VerticalMerge.html
@@ -18,24 +18,24 @@ Cells can either restart a new merge region or continue an existing one from abo
This is used to create row spans in tables.
Use ShapeRun from docx/shapes, with type: "rectangle" and children for a text box. It has plain
options for fills, lines, effects and text layout, and can be any of the preset shapes.
diff --git a/api/classes/index.XmlAttributeComponent.html b/api/classes/index.XmlAttributeComponent.html
index 0cbb071ab8..77df51b1fc 100644
--- a/api/classes/index.XmlAttributeComponent.html
+++ b/api/classes/index.XmlAttributeComponent.html
@@ -19,7 +19,7 @@ can define an xmlKeys map to specify the transformation.
diff --git a/api/classes/index.XmlComponent.html b/api/classes/index.XmlComponent.html
index 990499dfe6..9343614262 100644
--- a/api/classes/index.XmlComponent.html
+++ b/api/classes/index.XmlComponent.html
@@ -20,11 +20,11 @@ the intermediate object format used by the xml serialization library.
-
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
+
Example
// Creating a custom XML component classMyElementextendsXmlComponent { constructor(text: string) { super("w:myElement"); this.root.push(newAttributes({ val:text })); } }
constelement = newMyElement("Hello"); // When serialized: <w:myElement w:val="Hello"/>
diff --git a/api/classes/math.MathBrackets.html b/api/classes/math.MathBrackets.html
index 333f97ebda..24aa36650f 100644
--- a/api/classes/math.MathBrackets.html
+++ b/api/classes/math.MathBrackets.html
@@ -22,14 +22,14 @@ with what they hold.
diff --git a/api/classes/math.MathLargeOperator.html b/api/classes/math.MathLargeOperator.html
index e3102f51fa..fe56839fe8 100644
--- a/api/classes/math.MathLargeOperator.html
+++ b/api/classes/math.MathLargeOperator.html
@@ -21,14 +21,14 @@ it applies to. MathSum and MathIntegral are two of the
diff --git a/api/classes/math.MathMatrix.html b/api/classes/math.MathMatrix.html
index d1123ee2d8..ee9f78fdff 100644
--- a/api/classes/math.MathMatrix.html
+++ b/api/classes/math.MathMatrix.html
@@ -23,14 +23,14 @@ and Pages centre every column.
diff --git a/api/classes/math.MathPhantom.html b/api/classes/math.MathPhantom.html
index a31a92406e..b03f2815ef 100644
--- a/api/classes/math.MathPhantom.html
+++ b/api/classes/math.MathPhantom.html
@@ -17,18 +17,18 @@ line things up with it. Or math that is seen but takes up no room, or less, as <
-
Example
// As much space as "x+y" takes up newMathPhantom({ children: [newMathRun("x+y")] });
// A tall fraction that doesn't push its line apart newMathPhantom({ visible:true, height:false, depth:false, children: [fraction] });
+
Example
// As much space as "x+y" takes up newMathPhantom({ children: [newMathRun("x+y")] });
// A tall fraction that doesn't push its line apart newMathPhantom({ visible:true, height:false, depth:false, children: [fraction] });
diff --git a/api/classes/shapes.ShapeCanvasRun.html b/api/classes/shapes.ShapeCanvasRun.html
index de81512586..3b612e7563 100644
--- a/api/classes/shapes.ShapeCanvasRun.html
+++ b/api/classes/shapes.ShapeCanvasRun.html
@@ -28,14 +28,14 @@ written in mc:AlternateContent, with the group as its fallback, unl
diff --git a/api/classes/shapes.ShapeGroupRun.html b/api/classes/shapes.ShapeGroupRun.html
index f3d3bd93c8..460c598b06 100644
--- a/api/classes/shapes.ShapeGroupRun.html
+++ b/api/classes/shapes.ShapeGroupRun.html
@@ -28,14 +28,14 @@ when shapes are moved on a Copy
diff --git a/api/classes/shapes.ShapeRun.html b/api/classes/shapes.ShapeRun.html
index d64e777044..312e343638 100644
--- a/api/classes/shapes.ShapeRun.html
+++ b/api/classes/shapes.ShapeRun.html
@@ -22,18 +22,18 @@ and arrowheads, and text inside it. It sits inline with text unless floati
Public Api
-
Example
// A black bar inline with text newParagraph({ children: [ newTextRun("Name: "), newShapeRun({ type:"rectangle", transformation: { width:200, height:4 }, fill:"000000", line:"none" }), ], });
// A black bar inline with text newParagraph({ children: [ newTextRun("Name: "), newShapeRun({ type:"rectangle", transformation: { width:200, height:4 }, fill:"000000", line:"none" }), ], });
diff --git a/api/classes/watermarks.ImageWatermark.html b/api/classes/watermarks.ImageWatermark.html
index aaa06332c2..34c20b3ec3 100644
--- a/api/classes/watermarks.ImageWatermark.html
+++ b/api/classes/watermarks.ImageWatermark.html
@@ -39,14 +39,14 @@ way as an ImageRun.
diff --git a/api/classes/watermarks.TextWatermark.html b/api/classes/watermarks.TextWatermark.html
index 2ac6f80f8c..3ff22ebd59 100644
--- a/api/classes/watermarks.TextWatermark.html
+++ b/api/classes/watermarks.TextWatermark.html
@@ -33,18 +33,18 @@ recognizes it and can remove or replace it through that command.
\n option - causes the field result to be the paragraph number without trailing periods. No information about prior numbered levels is displayed unless it is included as part of the current level.
diff --git a/api/functions/html.htmlToContent.html b/api/functions/html.htmlToContent.html
index c33e1c2b90..5071825e8c 100644
--- a/api/functions/html.htmlToContent.html
+++ b/api/functions/html.htmlToContent.html
@@ -50,7 +50,7 @@ read as a browser reads it, and what the document can't have, such as a video, i
diff --git a/api/functions/html.htmlToRuns.html b/api/functions/html.htmlToRuns.html
index eb680926fa..f15decd92c 100644
--- a/api/functions/html.htmlToRuns.html
+++ b/api/functions/html.htmlToRuns.html
@@ -39,7 +39,7 @@ and lists is kept, without the tables and lists, with a warning, as a paragraph
diff --git a/api/functions/index.convertToXmlComponent.html b/api/functions/index.convertToXmlComponent.html
index 07aaaa7215..4ac1d21f8a 100644
--- a/api/functions/index.convertToXmlComponent.html
+++ b/api/functions/index.convertToXmlComponent.html
@@ -35,7 +35,7 @@ ImportedXmlComponent objects that match the structure of the original XML.
This element specifies the settings for the document grid, which enables precise layout of full-width East Asian language characters within a document by specifying the desired number of characters per line and lines per page for all East Asian text content in this section.
diff --git a/api/functions/index.createEmphasisMark.html b/api/functions/index.createEmphasisMark.html
index 17e178aea7..941e3895e5 100644
--- a/api/functions/index.createEmphasisMark.html
+++ b/api/functions/index.createEmphasisMark.html
@@ -21,7 +21,7 @@
text to emphasize it. This is commonly used in East Asian typography.
// Endnotes at the end of the document, numbered 001, 002, 003 createEndnoteProperties({ position:EndnotePosition.DOCUMENT_END, numberFormat: { type:NumberFormat.CUSTOM, format:"001" }, });
+
Example
// Endnotes at the end of the document, numbered 001, 002, 003 createEndnoteProperties({ position:EndnotePosition.DOCUMENT_END, numberFormat: { type:NumberFormat.CUSTOM, format:"001" }, });
// Footnotes at the end of the section, numbered a, b, c and restarting in each section createFootnoteProperties({ position:FootnotePosition.SECTION_END, numberFormat: { type:NumberFormat.LOWER_LETTER }, restart:NoteNumberRestart.EACH_SECTION, });
+
Example
// Footnotes at the end of the section, numbered a, b, c and restarting in each section createFootnoteProperties({ position:FootnotePosition.SECTION_END, numberFormat: { type:NumberFormat.LOWER_LETTER }, restart:NoteNumberRestart.EACH_SECTION, });
diff --git a/api/functions/index.createFrameProperties.html b/api/functions/index.createFrameProperties.html
index bf7dfb9da3..5287a6bf4d 100644
--- a/api/functions/index.createFrameProperties.html
+++ b/api/functions/index.createFrameProperties.html
@@ -22,7 +22,7 @@ They support both coordinate-based and alignment-based positioning, along with
drop cap effects and various text wrapping options.
diff --git a/api/functions/index.createHorizontalPosition.html b/api/functions/index.createHorizontalPosition.html
index 8de7aa2f75..6969887df1 100644
--- a/api/functions/index.createHorizontalPosition.html
+++ b/api/functions/index.createHorizontalPosition.html
@@ -21,7 +21,7 @@
object relative to a base element (page, margin, column, etc.).
diff --git a/api/functions/index.createMathAccentCharacter.html b/api/functions/index.createMathAccentCharacter.html
index e34812bb29..d97253cccf 100644
--- a/api/functions/index.createMathAccentCharacter.html
+++ b/api/functions/index.createMathAccentCharacter.html
@@ -21,7 +21,7 @@
such as summation (∑), integral (∫), or product (∏) symbols.
diff --git a/api/functions/index.createMathNAryProperties.html b/api/functions/index.createMathNAryProperties.html
index 43d1583122..93f87b9081 100644
--- a/api/functions/index.createMathNAryProperties.html
+++ b/api/functions/index.createMathNAryProperties.html
@@ -21,7 +21,7 @@
and integrals, including the operator character and limit positioning.
diff --git a/api/functions/index.createMathSubScriptElement.html b/api/functions/index.createMathSubScriptElement.html
index 22b7894116..7fe8980e04 100644
--- a/api/functions/index.createMathSubScriptElement.html
+++ b/api/functions/index.createMathSubScriptElement.html
@@ -21,7 +21,7 @@
script objects, and other structures that support subscripts.
diff --git a/api/functions/index.createMathSuperScriptElement.html b/api/functions/index.createMathSuperScriptElement.html
index d9f40f0017..7780c8072e 100644
--- a/api/functions/index.createMathSuperScriptElement.html
+++ b/api/functions/index.createMathSuperScriptElement.html
@@ -21,7 +21,7 @@
script objects, and other structures that support superscripts.
diff --git a/api/functions/index.createPageNumberType.html b/api/functions/index.createPageNumberType.html
index 80a977fdd3..bbf54091fc 100644
--- a/api/functions/index.createPageNumberType.html
+++ b/api/functions/index.createPageNumberType.html
@@ -21,7 +21,7 @@
for all pages in a section.
diff --git a/api/functions/index.createRunFonts.html b/api/functions/index.createRunFonts.html
index 2efd9b8f9f..a1858967ca 100644
--- a/api/functions/index.createRunFonts.html
+++ b/api/functions/index.createRunFonts.html
@@ -22,7 +22,7 @@ ranges in a run. This allows documents to use different fonts for ASCII, complex
script, East Asian, and high ANSI characters.
diff --git a/api/functions/index.createSectionType.html b/api/functions/index.createSectionType.html
index eea09672b3..04e95904ab 100644
--- a/api/functions/index.createSectionType.html
+++ b/api/functions/index.createSectionType.html
@@ -21,7 +21,7 @@
where the new section begins relative to the previous section.
diff --git a/api/functions/index.createTableFloatProperties.html b/api/functions/index.createTableFloatProperties.html
index 1d0ea1ab66..7883f64428 100644
--- a/api/functions/index.createTableFloatProperties.html
+++ b/api/functions/index.createTableFloatProperties.html
@@ -22,7 +22,7 @@ including anchor points, offsets, and text wrapping behavior.
The overlap option isn't part of it: the table properties write it as w:tblOverlap.
diff --git a/api/functions/index.createTableLook.html b/api/functions/index.createTableLook.html
index 44c86abe4c..b3b00f936e 100644
--- a/api/functions/index.createTableLook.html
+++ b/api/functions/index.createTableLook.html
@@ -29,12 +29,12 @@ styles to apply special formatting to specific regions of the table.
diff --git a/api/functions/index.createTableRowHeight.html b/api/functions/index.createTableRowHeight.html
index cf867203a7..286b223e77 100644
--- a/api/functions/index.createTableRowHeight.html
+++ b/api/functions/index.createTableRowHeight.html
@@ -21,7 +21,7 @@
determining how the height should be applied.
diff --git a/api/functions/index.createVmlShape.html b/api/functions/index.createVmlShape.html
index ebfd7c90c2..417063bb38 100644
--- a/api/functions/index.createVmlShape.html
+++ b/api/functions/index.createVmlShape.html
@@ -21,7 +21,7 @@
The shape's appearance is determined by its type (a reference to a v:shapetype), its style,
and its children.
diff --git a/api/functions/index.createWrapNone.html b/api/functions/index.createWrapNone.html
index 7d224e4881..45bc0704d5 100644
--- a/api/functions/index.createWrapNone.html
+++ b/api/functions/index.createWrapNone.html
@@ -23,7 +23,7 @@ without wrapping around it.
diff --git a/api/functions/index.createWrapSquare.html b/api/functions/index.createWrapSquare.html
index 7968b0d75d..165124f1ff 100644
--- a/api/functions/index.createWrapSquare.html
+++ b/api/functions/index.createWrapSquare.html
@@ -21,7 +21,7 @@
of the drawing on the specified side(s).
diff --git a/api/functions/index.createWrapThrough.html b/api/functions/index.createWrapThrough.html
index 15bb965be6..39a15f4185 100644
--- a/api/functions/index.createWrapThrough.html
+++ b/api/functions/index.createWrapThrough.html
@@ -21,7 +21,7 @@
fills any open space inside the drawing, such as the middle of a ring.
diff --git a/api/functions/index.createWrapTight.html b/api/functions/index.createWrapTight.html
index d9862e07b5..e87b5df117 100644
--- a/api/functions/index.createWrapTight.html
+++ b/api/functions/index.createWrapTight.html
@@ -21,7 +21,7 @@
of the drawing rather than its rectangular bounding box.
diff --git a/api/functions/index.dateTimeValue.html b/api/functions/index.dateTimeValue.html
index f85f7afa41..3da4898512 100644
--- a/api/functions/index.dateTimeValue.html
+++ b/api/functions/index.dateTimeValue.html
@@ -31,12 +31,12 @@ This matches the xsd:dateTime format required by OOXML.
diff --git a/api/functions/index.elementOf.html b/api/functions/index.elementOf.html
index 5153736ed8..355f27d4bd 100644
--- a/api/functions/index.elementOf.html
+++ b/api/functions/index.elementOf.html
@@ -31,7 +31,7 @@ is constructed with its element as rootKey.
diff --git a/api/functions/index.fillPartPageNumbers.html b/api/functions/index.fillPartPageNumbers.html
index 3f5b09e079..5a6c7145ea 100644
--- a/api/functions/index.fillPartPageNumbers.html
+++ b/api/functions/index.fillPartPageNumbers.html
@@ -35,7 +35,7 @@ are left as they are
diff --git a/api/functions/index.fillSequenceNumbers.html b/api/functions/index.fillSequenceNumbers.html
index ec7e7fcd45..1a09500974 100644
--- a/api/functions/index.fillSequenceNumbers.html
+++ b/api/functions/index.fillSequenceNumbers.html
@@ -27,7 +27,7 @@ tables of contents are filled in from its headings, as Word leaves a heading's S
diff --git a/api/functions/index.hpsMeasureValue.html b/api/functions/index.hpsMeasureValue.html
index 3445f82c74..642ba72d85 100644
--- a/api/functions/index.hpsMeasureValue.html
+++ b/api/functions/index.hpsMeasureValue.html
@@ -31,12 +31,12 @@ HPS (half-points) are commonly used for font sizes.
diff --git a/api/functions/index.isXmlComponent.html b/api/functions/index.isXmlComponent.html
index 685591a121..70e4b5f4f8 100644
--- a/api/functions/index.isXmlComponent.html
+++ b/api/functions/index.isXmlComponent.html
@@ -32,7 +32,7 @@ method that would write it.
diff --git a/api/functions/index.patchDocument.html b/api/functions/index.patchDocument.html
index b9b141f9b6..e4f368444a 100644
--- a/api/functions/index.patchDocument.html
+++ b/api/functions/index.patchDocument.html
@@ -35,14 +35,14 @@ the original document structure and optionally the original formatting.
diff --git a/api/functions/index.universalMeasureToTwips.html b/api/functions/index.universalMeasureToTwips.html
index d32691d483..91a6a89dcc 100644
--- a/api/functions/index.universalMeasureToTwips.html
+++ b/api/functions/index.universalMeasureToTwips.html
@@ -30,12 +30,12 @@ Strings are converted according to their unit suffix.
diff --git a/api/functions/layout.estimatePageNumbersWith.html b/api/functions/layout.estimatePageNumbersWith.html
index 4ba7a06b1b..0f87171f00 100644
--- a/api/functions/layout.estimatePageNumbersWith.html
+++ b/api/functions/layout.estimatePageNumbersWith.html
@@ -32,7 +32,7 @@ options say. Give what it returns to a document as its pageNumbers,
diff --git a/api/functions/layout.layoutDocument.html b/api/functions/layout.layoutDocument.html
index d793e73758..49cd55c02d 100644
--- a/api/functions/layout.layoutDocument.html
+++ b/api/functions/layout.layoutDocument.html
@@ -40,7 +40,7 @@ text box, it stops, and gives the pages up to there, with why in stoppedAt
diff --git a/api/functions/layout.measureWithPretext.html b/api/functions/layout.measureWithPretext.html
index e54b6c58db..6cb56c218a 100644
--- a/api/functions/layout.measureWithPretext.html
+++ b/api/functions/layout.measureWithPretext.html
@@ -40,7 +40,7 @@ measures text in another, and Pretext keeps the widths it measured.
Writes a document's VBA macros from their code, for the document's macros: the VBA project, and the events of the
+document that ThisDocument's code handles, such as Document_Open. The document is then a macro-enabled document,
+which Word opens from a .docm file. Word asks whether to enable its macros, as for any document with macros from
+elsewhere.
+
VBA keeps code in Windows-1252, the code page of Word in English and the other Western European languages, so a
+character it doesn't have goes in a string as ChrW, such as ChrW(&H4E2D) for "中", or two for a character beyond
+U+FFFF, such as ChrW(&HD83D) & ChrW(&HDE00) for "😀".
+
Word compiles the code when it first runs a macro, so a mistake in it shows then, in the VBA editor.
If a module's name isn't a VBA name of up to 31 characters, or is taken: by another module, ignoring case, or
+by ThisDocument, the project, Project, or a library it uses, VBA, Word, stdole, Normal or Office
+
+
+
Throws
If code has a character Windows-1252 doesn't
+
+
+
+
+
+
Settings
+
+
Member Visibility
+
+
+
+
+
+
+
diff --git a/api/functions/math.latexToMath.html b/api/functions/math.latexToMath.html
index ced851ac0d..1ce688f6cc 100644
--- a/api/functions/math.latexToMath.html
+++ b/api/functions/math.latexToMath.html
@@ -39,12 +39,12 @@ cases and aligned equations, with \tag for their numbers. The math
}. The error says where
In a page without a bundler, load dist/html.umd.cjs after dist/index.umd.cjs and dist/math.umd.cjs. It adds the docxHtml global. See the HTML documentation.
+
Macros
+
VBA macros, written from their code, make a document a macro-enabled document (.docm), with docx/macros:
VBA macros for docx documents, written from their code. A document with macros is a macro-enabled document, which
+Word opens from a .docm file.
+
Macros come with the docx package, from docx/macros. Everything else, such as the document and its paragraphs,
+comes from docx. The macros go in the document's macros.
diff --git a/api/types/charts.BarChartBaseOptions.html b/api/types/charts.BarChartBaseOptions.html
index 979de8e8bd..b073f1b407 100644
--- a/api/types/charts.BarChartBaseOptions.html
+++ b/api/types/charts.BarChartBaseOptions.html
@@ -31,7 +31,7 @@ Default is Office's: -27 for column charts and 0 for bar charts. Stacked bars al
@@ -49,14 +49,14 @@ bar, line or area chart spaces them by date
Sales. 2025: Jan 10, Feb 20.", and none for a decorative chart. An empty description removes it
+
diff --git a/api/types/charts.CategoryChartOptions.html b/api/types/charts.CategoryChartOptions.html
index f181e5923e..70877d04b6 100644
--- a/api/types/charts.CategoryChartOptions.html
+++ b/api/types/charts.CategoryChartOptions.html
@@ -59,7 +59,7 @@ in years, are labelled in rows, the groups below their categories
diff --git a/api/types/charts.ChartAxisCrossing.html b/api/types/charts.ChartAxisCrossing.html
index 81332f8f98..68495b986f 100644
--- a/api/types/charts.ChartAxisCrossing.html
+++ b/api/types/charts.ChartAxisCrossing.html
@@ -20,7 +20,7 @@ the value is the category's number, from 1, or when the categories are dates, a
diff --git a/api/types/charts.ChartAxisGroup.html b/api/types/charts.ChartAxisGroup.html
index ab9db67e9c..ed1f21e18b 100644
--- a/api/types/charts.ChartAxisGroup.html
+++ b/api/types/charts.ChartAxisGroup.html
@@ -19,7 +19,7 @@ chart's are along the bottom and the top.
diff --git a/api/types/charts.ChartCategoryGroup.html b/api/types/charts.ChartCategoryGroup.html
index de49dae6dd..a15c4a2b07 100644
--- a/api/types/charts.ChartCategoryGroup.html
+++ b/api/types/charts.ChartCategoryGroup.html
@@ -20,7 +20,7 @@ categories, or groups of its own, such as the months of each quarter of each yea
@@ -67,21 +67,21 @@ a point, and where they fit best on a pie. A chart's position is for the series
another way keep Office's, unless their own labels give one
diff --git a/api/types/charts.ChartDataPatchOptions.html b/api/types/charts.ChartDataPatchOptions.html
index dd88a72380..ea27e8944c 100644
--- a/api/types/charts.ChartDataPatchOptions.html
+++ b/api/types/charts.ChartDataPatchOptions.html
@@ -19,7 +19,7 @@ series' points, or for a stock chart its prices.
diff --git a/api/types/charts.ChartErrorBarsAmount.html b/api/types/charts.ChartErrorBarsAmount.html
index 7065f56570..bdf642243b 100644
--- a/api/types/charts.ChartErrorBarsAmount.html
+++ b/api/types/charts.ChartErrorBarsAmount.html
@@ -64,7 +64,7 @@ deviations, or the standard error.
diff --git a/api/types/charts.ChartLineDash.html b/api/types/charts.ChartLineDash.html
index 3f49f86459..2d731a88b0 100644
--- a/api/types/charts.ChartLineDash.html
+++ b/api/types/charts.ChartLineDash.html
@@ -19,7 +19,7 @@ and so on.
diff --git a/api/types/charts.ChartPointLabel.html b/api/types/charts.ChartPointLabel.html
index 0362657f3a..8b3828ae39 100644
--- a/api/types/charts.ChartPointLabel.html
+++ b/api/types/charts.ChartPointLabel.html
@@ -19,7 +19,7 @@ format and its font. Anything left out is as the series' labels have it.
diff --git a/api/types/charts.ChartTrendline.html b/api/types/charts.ChartTrendline.html
index 98d607fbf2..290f17db4f 100644
--- a/api/types/charts.ChartTrendline.html
+++ b/api/types/charts.ChartTrendline.html
@@ -20,7 +20,7 @@ forecast. It is drawn as a dotted line in the series' colour, and has an entry i
@@ -57,7 +57,7 @@ forecast. It is drawn as a dotted line in the series' colour, and has an entry i
along the x axis. Default is 0. Not for moving averages
@@ -73,35 +73,35 @@ the x axis. Default is 0. Not for moving averages
linear, exponential and polynomial trendlines, and above 0 for exponential ones
+
diff --git a/api/types/charts.ChartValueAxis.html b/api/types/charts.ChartValueAxis.html
index d1feda3de6..77b45e7a05 100644
--- a/api/types/charts.ChartValueAxis.html
+++ b/api/types/charts.ChartValueAxis.html
@@ -43,7 +43,7 @@ of 0 or less can't be shown. Default is a linear scale
diff --git a/api/types/charts.ComboChartSeriesType.html b/api/types/charts.ComboChartSeriesType.html
index 565b207cec..6c2766dd7f 100644
--- a/api/types/charts.ComboChartSeriesType.html
+++ b/api/types/charts.ComboChartSeriesType.html
@@ -19,7 +19,7 @@ or an area. A chart with series of more than one type is Word's "Combo"
@@ -59,14 +59,14 @@ with undefined, takes the next of the theme's accent colours
one for each slice in the order of the categories, where undefined leaves a slice in. Default is 0
+
diff --git a/api/types/charts.SplitPieChartBaseOptions.html b/api/types/charts.SplitPieChartBaseOptions.html
index 2e4907ce43..fdd715cb7e 100644
--- a/api/types/charts.SplitPieChartBaseOptions.html
+++ b/api/types/charts.SplitPieChartBaseOptions.html
@@ -42,7 +42,7 @@ second pie or a stacked bar, joined to the slice of the pie that stands for them
diff --git a/api/types/html.HtmlImage.html b/api/types/html.HtmlImage.html
index 70ccdcf616..4f711dddaf 100644
--- a/api/types/html.HtmlImage.html
+++ b/api/types/html.HtmlImage.html
@@ -16,7 +16,7 @@
SVG given without one is shown as nothing there.
@@ -51,7 +51,7 @@ an object of each address and its image, or a function that gives the image for
has none. An address is looked for as it is written, and then resolved against baseUrl.
@@ -59,7 +59,7 @@ has none. An address is looked for as it is written, and then resolved against <
of a document with docx's default page size and margins. Wider images are scaled down.
@@ -68,14 +68,14 @@ the foot of the page each is referred to on, by default, or "endnotes
page has them. Word's own HTML says which of its notes are footnotes and which are endnotes, which they stay.
@@ -86,7 +86,7 @@ element give it different styles, the most specific selector's is used, as in CS
document, such as in its styles option or the template it patches.
+
@@ -94,7 +94,7 @@ document, such as in its styles option or the template it patches.<
editor it comes from. Rules in @media print blocks are used, and those in other @media blocks aren't.
+
@@ -103,7 +103,7 @@ of their datetime attribute, or this time, or now: an ISO 8601 date
2026-10-13T09:30:00Z. Without it, they are underlined and struck through, as a browser shows them.
+
diff --git a/api/types/index.AttributePayload.html b/api/types/index.AttributePayload.html
index b6cb05c67c..a064bd9d74 100644
--- a/api/types/index.AttributePayload.html
+++ b/api/types/index.AttributePayload.html
@@ -21,7 +21,7 @@ control over attribute name mapping.
An event of a document that its macros can handle, in the document's own module, ThisDocument. Each is the event's
+name in VBA, after "Document_", such as "open" for Document_Open.
The events of the document that the project handles in ThisDocument, such as "open" for Document_Open. Word only
+runs the handlers of the events listed. createMacros lists them from the code. For a project from a .docm, they
+are the wne:docEvents in its word/vbaData.xml
+
+
+
Readonlyproject
+
project:Uint8Array|ArrayBuffer
+
The VBA project, the file Word keeps a document's macros in. createMacros from docx/macros writes it from VBA
+code. Or it is the word/vbaProject.bin of a .docm Word saved
Specifies the additional length, in EMUs, which shall be added to the bottom edge of the DrawingML object to determine its actual bottom edge including effects.
Specifies the additional length, in EMUs, which shall be added to the left edge of the DrawingML object to determine its actual left edge including effects.
Specifies the additional length, in EMUs, which shall be added to the right edge of the DrawingML object to determine its actual right edge including effects.
Specifies the additional length, in EMUs, which shall be added to the top edge of the DrawingML object to determine its actual top edge including effects.
@@ -63,14 +63,14 @@ name. The page references to a bookmark that isn't in it are left blank.
the first of them on may not be Word's. Nothing of them is written into the document.
+
@@ -88,7 +88,7 @@ those in headers, footers and notes.
in headers and footers only on its pages, show. Those of a section whose number is undefined are left blank.
+
diff --git a/api/types/index.GraphicMediaData.html b/api/types/index.GraphicMediaData.html
index 846847bc39..89fa14c49f 100644
--- a/api/types/index.GraphicMediaData.html
+++ b/api/types/index.GraphicMediaData.html
@@ -25,7 +25,7 @@ graphic it is. This is how docx/shapes writes its shapes.
diff --git a/api/types/index.IContext.html b/api/types/index.IContext.html
index 9a33221588..43750d9f88 100644
--- a/api/types/index.IContext.html
+++ b/api/types/index.IContext.html
@@ -18,7 +18,7 @@ during the conversion of components to XML.
diff --git a/api/types/index.ICropOptions.html b/api/types/index.ICropOptions.html
index 535ae2f212..bf23eff2fc 100644
--- a/api/types/index.ICropOptions.html
+++ b/api/types/index.ICropOptions.html
@@ -19,7 +19,7 @@ side of the image.
Specifies the number of characters to be allowed on the document grid for each line in this section.
This attribute's value shall be specified by multiplying the difference between the desired character pitch and the character pitch for that character in the font size of the Normal font by 4096.
This value shall then be used to add the character pitch for the specified point size to each character in the section [: This results in text in the Normal style having a specific number of characters per line. ]
-
<w:docGridw:charSize="40960" …/>
+
<w:docGridw:charSize="40960" …/>
The charSpace attribute specifies a value of 40960, which means that the delta between the character pitch of each character in the grid and the Normal font is 10 points, resulting in a character pitch of 11+10 = 21 points for all characters in this section. ]
@@ -42,13 +42,13 @@
The possible values for this attribute are defined by the ST_DecimalNumber simple type (§2.18.16).
Specifies the number of lines to be allowed on the document grid for the current page assuming all lines have equal line pitch applied to them. This line pitch shall not be added to any line which appears within a table cell unless the element (§2.15.3.1) is present in the document's compatibility settings.
This attribute is specified in twentieths of a point, and defines the pitch for each line of text on this page such that the desired number of single spaced lines of text fits on the current page.
-
<w:docGridw:linePitch="684" …/>
+
<w:docGridw:linePitch="684" …/>
The linePitch attribute specifies that 34.2 points is to the amount of pitch allowed for each line on this page in order to maintain the specific document grid. ]
@@ -58,7 +58,7 @@
The possible values for this attribute are defined by the ST_DecimalNumber simple type (§2.18.16).
The grid can define a grid which snaps all East Asian characters to grid positions, but leaves Latin text with its default spacing; a grid which adds the specified character pitch to each character on each row; or a grid which affects only the line pitch for the current section.
Specifies that the paragraph (or at least part of it) should be rendered on the same page as the next paragraph when possible. If multiple paragraphs are to be kept together but they exceed a page, then the set of paragraphs begin on a new page and page breaks are used thereafter as needed.
The value of newPage specifies that the line numbers shall restart at the top of each page to the value specified by the start attribute. In this case, newPage is the default, so this value could have been omitted entirely.
The possible values for this attribute are defined by the ST_LineNumberRestart simple type (§2.18.54).
This information is used to determine the actual paper size to use on the printer.
This implies that the actual paper size width and height are reversed for pages in this section. If this attribute is omitted, then portrait shall be implied.
Although the page width is 11", and page height is 8.5", according to the w and h attributes, because the orient attribute is set to landscape, pages in this section are printed on 8.5x11" paper in landscape mode.
The possible values for this attribute are defined by the ST_PageOrientation simple type (§2.18.71).
diff --git a/api/types/index.IRunStylePropertiesOptions.html b/api/types/index.IRunStylePropertiesOptions.html
index 0d4b90358a..389c520557 100644
--- a/api/types/index.IRunStylePropertiesOptions.html
+++ b/api/types/index.IRunStylePropertiesOptions.html
@@ -19,7 +19,7 @@ including font, size, bold, italic, underline, color, and other character format
@@ -239,34 +239,34 @@ as Word's style separator does. It is meant for a paragraph's mark, with v
new Paragraph({ run: { vanish: true, specVanish: true } }). Without vanish, Word doesn't hide the mark.
+
diff --git a/api/types/index.ITableCellBorders.html b/api/types/index.ITableCellBorders.html
index 0f8d9280f4..586e1b4cc3 100644
--- a/api/types/index.ITableCellBorders.html
+++ b/api/types/index.ITableCellBorders.html
@@ -22,7 +22,7 @@ can be specified for top, bottom, left, right, start, and end edges.
@@ -46,7 +46,7 @@ If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosi
If the attribute is omitted, the value is assumed to be zero.
@@ -57,7 +57,7 @@ If relativeVerticalPosition is also specified, then the absoluteVerticalPosition
If the attribute is omitted, the value is assumed to be zero.
@@ -65,7 +65,7 @@ If the attribute is omitted, the value is assumed to be zero.
below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
+
@@ -85,7 +85,7 @@ If omitted, the value is assumed to be page.
to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
+
@@ -121,7 +121,7 @@ inline - the table should be vertically aligned in line with the surrounding tex
top - the table should be vertically aligned to the top edge of the anchor
+
@@ -129,7 +129,7 @@ top - the table should be vertically aligned to the top edge of the anchor
to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
+
@@ -137,7 +137,7 @@ to the right of the table. The value is in twentieths of a point. If omitted, th
above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
+
@@ -88,7 +88,7 @@ When true, horizontal banding (alternating row colors) is disabled.
When false or undefined, horizontal banding is enabled if defined in the table style.
+
@@ -97,7 +97,7 @@ When true, vertical banding (alternating column colors) is disabled.
When false or undefined, vertical banding is enabled if defined in the table style.
+
diff --git a/api/types/index.ITableOfContentsOptions.html b/api/types/index.ITableOfContentsOptions.html
index 25ac2819ab..6738c00c89 100644
--- a/api/types/index.ITableOfContentsOptions.html
+++ b/api/types/index.ITableOfContentsOptions.html
@@ -23,7 +23,7 @@ Options correspond to field switches in the TOC field code.
@@ -59,7 +59,7 @@ The identifier designated by text in this switch's field-argument corresponds to
Use captionLabelIncludingNumbers (\c) to build a table of captions with labels and numbers.
@@ -85,7 +85,7 @@ the bookmark named by text in this switch's field-argument.
that separate an entry and its page number. The default is a tab with leader dots.
+
@@ -96,21 +96,21 @@ to the style with a style ID of HeadingX (e.g. 1 corresponds to Heading1).
If no heading range is specified, all heading levels used in the document are listed.
+
@@ -119,21 +119,21 @@ Page numbers are omitted from all levels unless a range of entry levels is speci
text in this switch's field-argument. A range is specified as for \l.
+
@@ -168,7 +168,7 @@ with each doublet being a comma-separated set of style name and table of content
text in this switch's field-argument (which is typically a letter).
+
@@ -178,14 +178,14 @@ where startLevel and endLevel are integers, and startLevel has a value equal-to
TC fields that assign entries to lower levels are skipped.
+
@@ -79,66 +79,66 @@ parent cell) when the document is packed, so the table renders the same in every
consumer. Supply explicit values to take full control of the grid.
+
diff --git a/api/types/index.ITableRowOptions.html b/api/types/index.ITableRowOptions.html
index 4c98f5f412..386c3f29be 100644
--- a/api/types/index.ITableRowOptions.html
+++ b/api/types/index.ITableRowOptions.html
@@ -34,7 +34,7 @@ the group on one page.
diff --git a/api/types/index.IThemeColorsOptions.html b/api/types/index.IThemeColorsOptions.html
index c0dc90f089..b602a676bd 100644
--- a/api/types/index.IThemeColorsOptions.html
+++ b/api/types/index.IThemeColorsOptions.html
@@ -21,7 +21,7 @@ when the theme's colors change. The colors not given are Office's.
diff --git a/api/types/index.IXmlAttribute.html b/api/types/index.IXmlAttribute.html
index 3e2be68c98..e0fdebc6f0 100644
--- a/api/types/index.IXmlAttribute.html
+++ b/api/types/index.IXmlAttribute.html
@@ -17,7 +17,7 @@
numbers, or booleans, which will be converted to strings in the final XML.
diff --git a/api/types/index.InputDataType.html b/api/types/index.InputDataType.html
index ee3483731d..187495b4cf 100644
--- a/api/types/index.InputDataType.html
+++ b/api/types/index.InputDataType.html
@@ -17,7 +17,7 @@
arrays, and streams, such as fs.createReadStream's or Packer.toStream's.
diff --git a/api/types/index.MathRunStyle.html b/api/types/index.MathRunStyle.html
index 4f5b73a119..073933f407 100644
--- a/api/types/index.MathRunStyle.html
+++ b/api/types/index.MathRunStyle.html
@@ -23,7 +23,7 @@
alphabet other than roman is plain unless given a style, as LaTeX draws its alphabets upright.
diff --git a/api/types/index.NoteContent.html b/api/types/index.NoteContent.html
index bce00e9f3f..f6d2eff0d8 100644
--- a/api/types/index.NoteContent.html
+++ b/api/types/index.NoteContent.html
@@ -19,7 +19,7 @@ with an id none of them has, when the run is written in the document's body.
diff --git a/api/types/index.NumberingDefinition.html b/api/types/index.NumberingDefinition.html
index deef133e88..c178eb763a 100644
--- a/api/types/index.NumberingDefinition.html
+++ b/api/types/index.NumberingDefinition.html
@@ -23,7 +23,7 @@ to the document's numbering when the paragraph is written.
diff --git a/api/types/index.OutputByType.html b/api/types/index.OutputByType.html
index 6d0a484746..c1bdf2bf5d 100644
--- a/api/types/index.OutputByType.html
+++ b/api/types/index.OutputByType.html
@@ -18,13 +18,13 @@ format determines the return type. Based on JSZip's output types.
-
Example
// Generate as base64 string constdoc: OutputByType["base64"] = awaitpacker.toBase64(document);
// Generate as Buffer (Node.js) constdoc: OutputByType["nodebuffer"] = awaitpacker.toBuffer(document);
// Generate as Blob (browser) constdoc: OutputByType["blob"] = awaitpacker.toBlob(document);
+
Example
// Generate as base64 string constdoc: OutputByType["base64"] = awaitpacker.toBase64(document);
// Generate as Buffer (Node.js) constdoc: OutputByType["nodebuffer"] = awaitpacker.toBuffer(document);
// Generate as Blob (browser) constdoc: OutputByType["blob"] = awaitpacker.toBlob(document);
diff --git a/api/types/index.PageNumberEstimator.html b/api/types/index.PageNumberEstimator.html
index de4f9bc462..057b6f003f 100644
--- a/api/types/index.PageNumberEstimator.html
+++ b/api/types/index.PageNumberEstimator.html
@@ -38,7 +38,7 @@ page counts can be written with it.
diff --git a/api/types/index.ParagraphChild.html b/api/types/index.ParagraphChild.html
index a7067a3ccf..1037cddcbb 100644
--- a/api/types/index.ParagraphChild.html
+++ b/api/types/index.ParagraphChild.html
@@ -17,7 +17,7 @@ This union type represents all valid inline content elements that can appear
within a paragraph in WordprocessingML.
diff --git a/api/types/index.RelationshipType.html b/api/types/index.RelationshipType.html
index 3c762524e9..797041ef13 100644
--- a/api/types/index.RelationshipType.html
+++ b/api/types/index.RelationshipType.html
@@ -17,7 +17,7 @@
Each type corresponds to a specific kind of document component or resource.
diff --git a/api/types/index.TableRowsPatch.html b/api/types/index.TableRowsPatch.html
index 9158de4c00..90980f0518 100644
--- a/api/types/index.TableRowsPatch.html
+++ b/api/types/index.TableRowsPatch.html
@@ -24,7 +24,7 @@ none. The other patches are applied after the rows are repeated, so a placeholde
@@ -55,14 +55,14 @@ A field's patch can repeat rows of a table in the copy in turn, whose fields are
repeated for each part, with its item's fields, and an item without parts has no row
diff --git a/api/types/index.TemplatePageNumberEstimator.html b/api/types/index.TemplatePageNumberEstimator.html
index 71a7bed7f5..edf3ce16fd 100644
--- a/api/types/index.TemplatePageNumberEstimator.html
+++ b/api/types/index.TemplatePageNumberEstimator.html
@@ -33,7 +33,7 @@ pages, are written with it.
Specifies the height of the containing block of the shape. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element.
Specifies the position of the left of the containing block of the shape relative to the element left of it in the flow of the page. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element. This property shall not be used for shapes anchored inline.
Specifies the position of the bottom of the containing block of the shape relative to the shape anchor. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element.
Specifies the position of the left of the containing block of the shape relative to the shape anchor. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element.
Specifies the position of the right of the containing block of the shape relative to the shape anchor. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element.
Specifies the position of the top of the containing block of the shape relative to the shape anchor. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element.
Specifies the type of positioning used to place an element. Default is static. When the element is contained inside a group, this property must be absolute.
Specifies relative horizontal position data for objects in WordprocessingML documents. This modifies the mso-position-horizontal property. Default is text.
Specifies relative vertical position data for objects in WordprocessingML documents. This modifies the mso-position-vertical property. Default is text.
Specifies the position of the top of the containing block of the shape relative to the element above it in the flow of the page. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element. This property shall not be used for shapes anchored inline.
Specifies the width of the containing block of the shape. Default is 0. It is specified in CSS units or, for elements in a group, in the coordinate system of the parent element.
Specifies the distance from the bottom of the shape to the text that wraps around it. Default is 0 pt. Note that this property is different from the CSS margin property, which changes the origin of the shape to include the margin areas. This property does not change the origin.
Specifies the distance from the left side of the shape to the text that wraps around it. Default is 0 pt. Note that this property is different from the CSS margin property, which changes the origin of the shape to include the margin areas. This property does not change the origin.
Specifies the distance from the right side of the shape to the text that wraps around it. Default is 0 pt. Note that this property is different from the CSS margin property, which changes the origin of the shape to include the margin areas. This property does not change the origin.
Specifies the distance from the top of the shape to the text that wraps around it. Default is 0 pt. Note that this property is different from the CSS margin property, which changes the origin of the shape to include the margin areas. This property does not change the origin.
Specifies whether the wrap coordinates were customized by the user. If the wrap coordinates are generated by an editor, this property is true; otherwise they were customized by a user. Default is false.
diff --git a/api/types/index.XmlElement.html b/api/types/index.XmlElement.html
index 6a28a6761e..630f299ea9 100644
--- a/api/types/index.XmlElement.html
+++ b/api/types/index.XmlElement.html
@@ -26,7 +26,7 @@ and the rest in instruction.
@@ -63,7 +63,7 @@ nearest to Word's lays it out. It still stops where it has no guess, such as at
is off, so the numbers written are Word's, as near as the layout knows, or blank.
+
@@ -73,7 +73,7 @@ break, and tabs move to their stops, as Word lays them out, and lines are as tal
width tables, so the layout stops at text in a font that isn't in them and isn't given as a file or embedded.
+
diff --git a/api/types/layout.MeasureWidth.html b/api/types/layout.MeasureWidth.html
index bd5bd91ad0..20f4f23275 100644
--- a/api/types/layout.MeasureWidth.html
+++ b/api/types/layout.MeasureWidth.html
@@ -33,7 +33,7 @@ between characters and the width of scaled text, which the document's formatting
The module's code, as it is typed in the VBA editor
+
+
+
Readonlyname
+
name:string
+
The module's name, such as "Formatting". A macro in it is "Formatting.MacroName" when the macro's name alone could
+be another module's too. It starts with a letter, then has letters, digits and underscores, up to 31 of them
diff --git a/api/types/shapes.ConnectorEnd.html b/api/types/shapes.ConnectorEnd.html
index 0147502f12..ec5d8a25b6 100644
--- a/api/types/shapes.ConnectorEnd.html
+++ b/api/types/shapes.ConnectorEnd.html
@@ -38,7 +38,7 @@ bottom-left corner. On a shape without connection points, the connector ends at
diff --git a/api/types/shapes.CustomShapeGeometry.html b/api/types/shapes.CustomShapeGeometry.html
index 7a6c542d54..bd183f35d4 100644
--- a/api/types/shapes.CustomShapeGeometry.html
+++ b/api/types/shapes.CustomShapeGeometry.html
@@ -50,7 +50,7 @@ fill the shape. Later paths are drawn over earlier ones
diff --git a/api/types/shapes.CustomShapePath.html b/api/types/shapes.CustomShapePath.html
index f96142dfe1..2f3cb9e364 100644
--- a/api/types/shapes.CustomShapePath.html
+++ b/api/types/shapes.CustomShapePath.html
@@ -20,7 +20,7 @@ own, so paths can overlap without cutting holes in each other.
diff --git a/api/types/shapes.CustomShapePathFill.html b/api/types/shapes.CustomShapePathFill.html
index 56b95ba54a..276e40ccbb 100644
--- a/api/types/shapes.CustomShapePathFill.html
+++ b/api/types/shapes.CustomShapePathFill.html
@@ -19,7 +19,7 @@ fill made lighter or darker, as Word's preset shapes shade the top of a cube or
diff --git a/api/types/shapes.IShapeCanvasOptions.html b/api/types/shapes.IShapeCanvasOptions.html
index 37a2c500ea..e0242fab3d 100644
--- a/api/types/shapes.IShapeCanvasOptions.html
+++ b/api/types/shapes.IShapeCanvasOptions.html
@@ -64,7 +64,7 @@ The shapes are not scaled.
diff --git a/api/types/shapes.IShapeConnectorOptions.html b/api/types/shapes.IShapeConnectorOptions.html
index 36cc0dcd06..c00f10f84c 100644
--- a/api/types/shapes.IShapeConnectorOptions.html
+++ b/api/types/shapes.IShapeConnectorOptions.html
@@ -23,7 +23,7 @@ or several connectors join the same two shapes, their ends are spread out along
@@ -64,21 +64,21 @@ or several connectors join the same two shapes, their ends are spread out along
shape, so Word doesn't move it when the connector moves
diff --git a/api/types/shapes.IShapeGroupChildOptions.html b/api/types/shapes.IShapeGroupChildOptions.html
index 3a8c9940a0..673cfc4d2c 100644
--- a/api/types/shapes.IShapeGroupChildOptions.html
+++ b/api/types/shapes.IShapeGroupChildOptions.html
@@ -20,7 +20,7 @@ in pixels, unless a layout places it, and id names it
diff --git a/api/types/shapes.IShapeGroupOptions.html b/api/types/shapes.IShapeGroupOptions.html
index bc2017aa3f..70e7f0ce1a 100644
--- a/api/types/shapes.IShapeGroupOptions.html
+++ b/api/types/shapes.IShapeGroupOptions.html
@@ -50,7 +50,7 @@ the box around the children. A different size scales every shape in the group.
diff --git a/api/types/shapes.IShapeNestedGroupOptions.html b/api/types/shapes.IShapeNestedGroupOptions.html
index e9fde525ff..d028f233b5 100644
--- a/api/types/shapes.IShapeNestedGroupOptions.html
+++ b/api/types/shapes.IShapeNestedGroupOptions.html
@@ -47,7 +47,7 @@ box around the children, and a different size scales every child
diff --git a/api/types/shapes.IShapeOptions.html b/api/types/shapes.IShapeOptions.html
index 41323ccf39..2e78c026d1 100644
--- a/api/types/shapes.IShapeOptions.html
+++ b/api/types/shapes.IShapeOptions.html
@@ -23,7 +23,7 @@ or startAngle and endAngle for a "pie"
diff --git a/api/types/shapes.PresetShapeAdjustments.html b/api/types/shapes.PresetShapeAdjustments.html
index a2aaa4ecf2..4836b2ce81 100644
--- a/api/types/shapes.PresetShapeAdjustments.html
+++ b/api/types/shapes.PresetShapeAdjustments.html
@@ -21,7 +21,7 @@ allows, so a value that is too large acts like the largest allowed value.
diff --git a/api/types/shapes.ShapeAdjustments.html b/api/types/shapes.ShapeAdjustments.html
index 5f970f2af5..e343dfa78e 100644
--- a/api/types/shapes.ShapeAdjustments.html
+++ b/api/types/shapes.ShapeAdjustments.html
@@ -23,7 +23,7 @@ It is never for shapes without handles, which take no adjustments.<
diff --git a/api/types/shapes.ShapeFlowLayout.html b/api/types/shapes.ShapeFlowLayout.html
index d966a5d1bd..187c5077f9 100644
--- a/api/types/shapes.ShapeFlowLayout.html
+++ b/api/types/shapes.ShapeFlowLayout.html
@@ -20,7 +20,7 @@ that connect to it, and the shapes on each level are ordered so connectors cross
@@ -52,26 +52,26 @@ with a lane goes in the band of that name, and shapes without one g
across the direction the flow runs in, each with a header at the start of the flow
diff --git a/api/types/shapes.ShapeHorizontalPosition.html b/api/types/shapes.ShapeHorizontalPosition.html
index 41863c2505..4b70c14bb7 100644
--- a/api/types/shapes.ShapeHorizontalPosition.html
+++ b/api/types/shapes.ShapeHorizontalPosition.html
@@ -26,7 +26,7 @@ a base of the page, the space between its margins, or one of its margins
diff --git a/api/types/shapes.ShapeLayout.html b/api/types/shapes.ShapeLayout.html
index ee28b71dfa..97ec442c11 100644
--- a/api/types/shapes.ShapeLayout.html
+++ b/api/types/shapes.ShapeLayout.html
@@ -20,7 +20,7 @@ layout, which is placed around them. Connectors are routed after the shapes are
diff --git a/api/types/shapes.ShapeSize.html b/api/types/shapes.ShapeSize.html
index a907bc5efa..8239a5e056 100644
--- a/api/types/shapes.ShapeSize.html
+++ b/api/types/shapes.ShapeSize.html
@@ -19,7 +19,7 @@ percentage of the space between the page's margins, or of what floating.si
diff --git a/api/types/shapes.ShapeTextWarp.html b/api/types/shapes.ShapeTextWarp.html
index e70d1a19bc..26760c5576 100644
--- a/api/types/shapes.ShapeTextWarp.html
+++ b/api/types/shapes.ShapeTextWarp.html
@@ -19,7 +19,7 @@ The ...Filled arches, circle and button spread the text over the wh
diff --git a/api/types/shapes.ShapeThemeColor.html b/api/types/shapes.ShapeThemeColor.html
index 10e9c2d2ab..df66b9cb6c 100644
--- a/api/types/shapes.ShapeThemeColor.html
+++ b/api/types/shapes.ShapeThemeColor.html
@@ -20,7 +20,7 @@ same as docx's ThemeColor, which text, borders and sha
diff --git a/api/types/shapes.ShapeTransformation.html b/api/types/shapes.ShapeTransformation.html
index e3b5a36f18..5a7c21d505 100644
--- a/api/types/shapes.ShapeTransformation.html
+++ b/api/types/shapes.ShapeTransformation.html
@@ -30,7 +30,7 @@ between the margins for a floating shape, such as "100%"<
diff --git a/api/types/shapes.ShapeTreeLayout.html b/api/types/shapes.ShapeTreeLayout.html
index 227871476c..e7de8a4da3 100644
--- a/api/types/shapes.ShapeTreeLayout.html
+++ b/api/types/shapes.ShapeTreeLayout.html
@@ -20,7 +20,7 @@ children are placed side by side below their parent, which is centred over them.
diff --git a/api/types/shapes.ShapeVerticalPosition.html b/api/types/shapes.ShapeVerticalPosition.html
index c9889c81a5..6a928bcb05 100644
--- a/api/types/shapes.ShapeVerticalPosition.html
+++ b/api/types/shapes.ShapeVerticalPosition.html
@@ -26,7 +26,7 @@ a base of the page, the space between its margins, or one of its margins
diff --git a/api/variables/index.CharacterSet.html b/api/variables/index.CharacterSet.html
index a65be457f7..1e36a88d10 100644
--- a/api/variables/index.CharacterSet.html
+++ b/api/variables/index.CharacterSet.html
@@ -60,7 +60,7 @@ Maps character set names to their hexadecimal identifiers.
diff --git a/api/variables/index.DocumentAttributeNamespaces.html b/api/variables/index.DocumentAttributeNamespaces.html
index 4c237fd70f..726a0415fd 100644
--- a/api/variables/index.DocumentAttributeNamespaces.html
+++ b/api/variables/index.DocumentAttributeNamespaces.html
@@ -94,7 +94,7 @@ in a document, including WordprocessingML, DrawingML, VML, and others.
The grid can define a grid which snaps all East Asian characters to grid positions, but leaves Latin text with its default spacing; a grid which adds the specified character pitch to all characters on each row; or a grid which affects only the line pitch for the current section.
When this value is set, the input specified via the user interface may be restricted to the number of lines per page and characters per line, with the consumer or producer translating this information based on the current font data to get the resulting line and character pitch values
diff --git a/api/variables/index.DropCapType.html b/api/variables/index.DropCapType.html
index 1d437ede21..f6c3cca065 100644
--- a/api/variables/index.DropCapType.html
+++ b/api/variables/index.DropCapType.html
@@ -32,7 +32,7 @@ beginning of a paragraph. This enum defines how the drop cap should be positione
diff --git a/api/variables/index.EMPTY_OBJECT.html b/api/variables/index.EMPTY_OBJECT.html
index b5d8727ec4..9e62671cd9 100644
--- a/api/variables/index.EMPTY_OBJECT.html
+++ b/api/variables/index.EMPTY_OBJECT.html
@@ -20,7 +20,7 @@ has no children or attributes.
This simple type specifies the possible types of headers and footers which may be specified for a given header or footer reference in a document. This value determines the page(s) on which the current header or footer shall be displayed.
Specifies that this header or footer shall appear on the first page in this section. The appearance of this header or footer is contingent on the setting of the titlePg element (§2.10.6).
diff --git a/api/variables/index.LevelFormat.html b/api/variables/index.LevelFormat.html
index 21d86d71d6..fd13006ebe 100644
--- a/api/variables/index.LevelFormat.html
+++ b/api/variables/index.LevelFormat.html
@@ -274,14 +274,14 @@ decimal, roman numerals, letters, and various international formats.
-
Example
// Use decimal numbering (1, 2, 3...) format: LevelFormat.DECIMAL
// Use lowercase roman numerals (i, ii, iii...) format: LevelFormat.LOWER_ROMAN
// Use bullet points format: LevelFormat.BULLET
+
Example
// Use decimal numbering (1, 2, 3...) format: LevelFormat.DECIMAL
// Use lowercase roman numerals (i, ii, iii...) format: LevelFormat.LOWER_ROMAN
This simple type specifies when the line numbering in the parent section shall be reset to its restart value. The line numbering increments for each line (even if the line number itself is not displayed) until it reaches the restart point specified by this element.
This simple type specifies the orientation of all pages in the parent section. This information is used to determine the actual paper size to use when printing the file.
diff --git a/api/variables/index.PageTextDirectionType.html b/api/variables/index.PageTextDirectionType.html
index d9d51dd883..e8074822bc 100644
--- a/api/variables/index.PageTextDirectionType.html
+++ b/api/variables/index.PageTextDirectionType.html
@@ -28,7 +28,7 @@ vertically (top-to-bottom), commonly used for East Asian languages.
Top-to-bottom, right-to-left (vertical East Asian text flow)
diff --git a/api/variables/index.TextEffect.html b/api/variables/index.TextEffect.html
index a38a01b9f0..6ead21e91b 100644
--- a/api/variables/index.TextEffect.html
+++ b/api/variables/index.TextEffect.html
@@ -17,7 +17,7 @@
these effects are deprecated and may not be supported by all applications.
diff --git a/api/variables/index.VerticalAlign.html b/api/variables/index.VerticalAlign.html
index a01f5a5bed..fbd5f1985c 100644
--- a/api/variables/index.VerticalAlign.html
+++ b/api/variables/index.VerticalAlign.html
@@ -32,7 +32,7 @@ backward-compatibility and will be removed in the next major release.
diff --git a/api/variables/index.VerticalAlignTable.html b/api/variables/index.VerticalAlignTable.html
index feb71f7926..0fb3651c0c 100644
--- a/api/variables/index.VerticalAlignTable.html
+++ b/api/variables/index.VerticalAlignTable.html
@@ -28,7 +28,7 @@ are valid according to ECMA-376 (§17.18.87 ST_VerticalJc within <w:tcP
diff --git a/api/variables/index.VerticalMergeType.html b/api/variables/index.VerticalMergeType.html
index aa72e1abf9..b5712fc287 100644
--- a/api/variables/index.VerticalMergeType.html
+++ b/api/variables/index.VerticalMergeType.html
@@ -29,7 +29,7 @@ This cell continues a vertical merge started by a cell above it.
This cell begins a new vertical merge region.
diff --git a/api/variables/index.bookmarkUniqueNumericId.html b/api/variables/index.bookmarkUniqueNumericId.html
index 75d3ee74ad..e6b54bf9b5 100644
--- a/api/variables/index.bookmarkUniqueNumericId.html
+++ b/api/variables/index.bookmarkUniqueNumericId.html
@@ -22,12 +22,12 @@ than a generator per instance.
diff --git a/api/variables/index.docPropertiesUniqueNumericId.html b/api/variables/index.docPropertiesUniqueNumericId.html
index 12cc517a5e..dd21b8c9ff 100644
--- a/api/variables/index.docPropertiesUniqueNumericId.html
+++ b/api/variables/index.docPropertiesUniqueNumericId.html
@@ -23,12 +23,12 @@ one counter rather than a generator per instance.
diff --git a/api/variables/layout.estimatePageNumbers.html b/api/variables/layout.estimatePageNumbers.html
index 52179b75ee..a7d6c2569b 100644
--- a/api/variables/layout.estimatePageNumbers.html
+++ b/api/variables/layout.estimatePageNumbers.html
@@ -51,7 +51,7 @@ written, and the numbers left blank stay blank, without asking to update the fie
diff --git a/live-examples/lib/index.d.ts b/live-examples/lib/index.d.ts
index a7fd14699e..dd0af6071a 100644
--- a/live-examples/lib/index.d.ts
+++ b/live-examples/lib/index.d.ts
@@ -1419,7 +1419,13 @@ export declare const concreteNumUniqueNumericIdGen: () => UniqueNumericIdCreator
* ```
*/
declare class ContentTypes extends XmlComponent {
- constructor();
+ /**
+ * @param options.macros - Whether the document has VBA macros, which makes its main part a macro-enabled document
+ * and adds the VBA project (word/vbaProject.bin)
+ */
+ constructor({ macros }?: {
+ readonly macros?: boolean;
+ });
/**
* Registers the comments part in the content types.
*/
@@ -3374,6 +3380,33 @@ export declare const DocumentGridType: {
readonly SNAP_TO_CHARS: "snapToChars";
};
+/**
+ * An event of a document that its macros can handle, in the document's own module, ThisDocument. Each is the event's
+ * name in VBA, after "Document_", such as "open" for `Document_Open`.
+ *
+ * @publicApi
+ */
+export declare type DocumentMacroEvent = "new" | "open" | "close" | "sync" | "xmlAfterInsert" | "xmlBeforeDelete" | "contentControlAfterAdd" | "contentControlBeforeDelete" | "contentControlOnExit" | "contentControlOnEnter" | "contentControlBeforeStoreUpdate" | "contentControlBeforeContentUpdate" | "buildingBlockInsert";
+
+/**
+ * A document's VBA macros, for the document's `macros`.
+ *
+ * @publicApi
+ */
+export declare type DocumentMacros = {
+ /**
+ * The VBA project, the file Word keeps a document's macros in. `createMacros` from `docx/macros` writes it from VBA
+ * code. Or it is the word/vbaProject.bin of a .docm Word saved
+ */
+ readonly project: Uint8Array | ArrayBuffer;
+ /**
+ * The events of the document that the project handles in ThisDocument, such as "open" for `Document_Open`. Word only
+ * runs the handlers of the events listed. `createMacros` lists them from the code. For a project from a .docm, they
+ * are the `wne:docEvents` in its word/vbaData.xml
+ */
+ readonly events?: readonly DocumentMacroEvent[];
+};
+
/**
* Wrapper for the main document body.
*
@@ -3941,6 +3974,7 @@ declare class File_2 {
private readonly fontWrapper;
private readonly theme;
private readonly packageParts;
+ private readonly macros?;
constructor(options: IPropertiesOptions);
private addSection;
private createHeader;
@@ -3972,6 +4006,11 @@ declare class File_2 {
get Theme(): Theme;
/** The parts that drawings, such as charts, add to the package when it is written. */
get PackageParts(): PackageParts;
+ /**
+ * The document's macros, when it has any: its VBA project (word/vbaProject.bin), the events of the document it
+ * handles (word/vbaData.xml), and the project's relationships, to the events.
+ */
+ get Macros(): FileMacros | undefined;
}
export { File_2 as Document }
export { File_2 as File }
@@ -3987,6 +4026,18 @@ export declare class FileChild extends XmlComponent {
readonly fileChild: symbol;
}
+/**
+ * A document's macros, as the document writes them.
+ */
+declare type FileMacros = {
+ /** The VBA project (word/vbaProject.bin) */
+ readonly project: Uint8Array;
+ /** The events of the document the project handles (word/vbaData.xml), if it handles any */
+ readonly events?: XmlComponent;
+ /** The project's relationships (word/_rels/vbaProject.bin.rels), to its events */
+ readonly relationships: Relationships;
+};
+
/**
* Patch definition for document-level replacement.
*
@@ -7086,6 +7137,7 @@ export declare type IPatch = ParagraphPatch | FilePatch;
* @property hyphenation - Hyphenation settings
* @property theme - The document's theme: its colors, and its fonts for headings and body text
* @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
+ * @property macros - The document's VBA macros, which make it a macro-enabled document (.docm)
*/
export declare type IPropertiesOptions = {
readonly sections: readonly ISectionOptions[];
@@ -7129,6 +7181,11 @@ export declare type IPropertiesOptions = {
* from `docx/layout`, which lays out the document's pages as Word would
*/
readonly pageNumbers?: PageNumberEstimator;
+ /**
+ * The document's VBA macros. `createMacros` from `docx/macros` writes them from VBA code. A document with macros is a
+ * macro-enabled document, which Word only opens from a .docm file
+ */
+ readonly macros?: DocumentMacros;
};
/**
@@ -8753,6 +8810,12 @@ export declare const LineRuleType: {
*/
export declare const longHexNumber: (val: string) => string;
+/**
+ * The types of the relationships to a document's macros: to its VBA project, and from that to the events it handles.
+ * Only the document adds these, so a package part's relationship can't be one of them.
+ */
+declare type MacroRelationshipType = "http://schemas.microsoft.com/office/2006/relationships/vbaProject" | "http://schemas.microsoft.com/office/2006/relationships/wordVbaData";
+
/**
* Represents a mathematical equation in a WordprocessingML document.
*
@@ -11599,7 +11662,7 @@ declare class Relationships extends XmlComponent {
* @param target - Path to the target part
* @param targetMode - Optional mode indicating if target is external
*/
- addRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType]): void;
+ addRelationship(id: number | string, type: RelationshipType | MacroRelationshipType, target: string, targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType]): void;
/**
* Creates a copy of the relationships given. Relationships added to the copy aren't added to them, so the compiler
* adds the ones it writes for a part, such as to its images, to a copy, and packing a document again doesn't add
diff --git a/live-examples/lib/index.iife.js b/live-examples/lib/index.iife.js
index e5f66f5b3d..4aba6ad2ca 100644
--- a/live-examples/lib/index.iife.js
+++ b/live-examples/lib/index.iife.js
@@ -18874,7 +18874,11 @@ MAX: 9026 };
* ```
*/
var ContentTypes = class extends XmlComponent {
- constructor() {
+ /**
+ * @param options.macros - Whether the document has VBA macros, which makes its main part a macro-enabled document
+ * and adds the VBA project (word/vbaProject.bin)
+ */
+ constructor({ macros = false } = {}) {
super("Types");
this.root.push(new ContentTypeAttributes({ xmlns: "http://schemas.openxmlformats.org/package/2006/content-types" }));
this.root.push(createDefault("image/png", "png"));
@@ -18886,7 +18890,7 @@ MAX: 9026 };
this.root.push(createDefault("application/vnd.openxmlformats-package.relationships+xml", "rels"));
this.root.push(createDefault("application/xml", "xml"));
this.root.push(createDefault("application/vnd.openxmlformats-officedocument.obfuscatedFont", "odttf"));
- this.root.push(createOverride("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", "/word/document.xml"));
+ this.root.push(createOverride(macros ? "application/vnd.ms-word.document.macroEnabled.main+xml" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", "/word/document.xml"));
this.root.push(createOverride("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", "/word/styles.xml"));
this.root.push(createOverride("application/vnd.openxmlformats-package.core-properties+xml", "/docProps/core.xml"));
this.root.push(createOverride("application/vnd.openxmlformats-officedocument.custom-properties+xml", "/docProps/custom.xml"));
@@ -18897,6 +18901,7 @@ MAX: 9026 };
this.root.push(createOverride("application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", "/word/settings.xml"));
this.root.push(createOverride("application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml", "/word/fontTable.xml"));
this.root.push(createOverride("application/vnd.openxmlformats-officedocument.theme+xml", "/word/theme/theme1.xml"));
+ if (macros) this.root.push(createOverride("application/vnd.ms-office.vbaProject", "/word/vbaProject.bin"));
}
/**
* Registers the comments part in the content types.
@@ -19334,6 +19339,58 @@ MAX: 9026 };
}
};
//#endregion
+ //#region src/file/document-macros/document-macros.ts
+ /**
+ * Document macros module: a document's VBA macros, which make it a macro-enabled document (.docm).
+ *
+ * The macros are a VBA project, which Word keeps in word/vbaProject.bin. The events of the document that the project
+ * handles are listed in word/vbaData.xml, as Word only runs a handler, such as `Document_Open`, for an event listed
+ * there.
+ *
+ * Reference: ooxml-schemas/microsoft/wml-2006.xsd (CT_VbaSuppData), [MS-OFFMACRO2]
+ *
+ * @module
+ */
+ var EVENT_ELEMENTS = {
+ new: "wne:eventDocNew",
+ open: "wne:eventDocOpen",
+ close: "wne:eventDocClose",
+ sync: "wne:eventDocSync",
+ xmlAfterInsert: "wne:eventDocXmlAfterInsert",
+ xmlBeforeDelete: "wne:eventDocXmlBeforeDelete",
+ contentControlAfterAdd: "wne:eventDocContentControlAfterInsert",
+ contentControlBeforeDelete: "wne:eventDocContentControlBeforeDelete",
+ contentControlOnExit: "wne:eventDocContentControlOnExit",
+ contentControlOnEnter: "wne:eventDocContentControlOnEnter",
+ contentControlBeforeStoreUpdate: "wne:eventDocStoreUpdate",
+ contentControlBeforeContentUpdate: "wne:eventDocContentControlContentUpdate",
+ buildingBlockInsert: "wne:eventDocBuildingBlockAfterInsert"
+ };
+ /**
+ * The events of a document that its macros handle (word/vbaData.xml).
+ *
+ * ## XSD Schema
+ * ```xml
+ *
+ *
+ *
+ *
+ *
+ *
+ * ```
+ */
+ var createMacroEvents = (events) => new BuilderElement({
+ name: "wne:vbaSuppData",
+ attributes: { namespace: {
+ key: "xmlns:wne",
+ value: "http://schemas.microsoft.com/office/word/2006/wordml"
+ } },
+ children: [new BuilderElement({
+ name: "wne:docEvents",
+ children: Object.entries(EVENT_ELEMENTS).filter(([event]) => events.includes(event)).map(([, name]) => new BuilderElement({ name }))
+ })]
+ });
+ //#endregion
//#region src/file/document/document-background/document-background.ts
/**
* Document background module for WordprocessingML documents.
@@ -23625,6 +23682,16 @@ MAX: 9026 };
*
* @module
*/
+ var COMPOUND_FILE_SIGNATURE = [
+ 208,
+ 207,
+ 17,
+ 224,
+ 161,
+ 177,
+ 26,
+ 225
+ ];
/**
* Represents a Word document file.
*
@@ -23701,7 +23768,7 @@ MAX: 9026 };
*/
var File = class {
constructor(options) {
- var _options$creator, _options$revision, _options$lastModified, _options$comments, _options$customProper, _options$features, _options$features2, _options$fonts, _options$hyphenation, _options$hyphenation2, _options$hyphenation3, _options$hyphenation4, _options$fonts2;
+ var _options$creator, _options$revision, _options$lastModified, _options$comments, _options$customProper, _this$macros, _options$features, _options$features2, _options$fonts, _options$hyphenation, _options$hyphenation2, _options$hyphenation3, _options$hyphenation4, _options$fonts2;
_defineProperty(this, "currentRelationshipId", 1);
_defineProperty(this, "documentWrapper", void 0);
_defineProperty(this, "headers", []);
@@ -23733,6 +23800,19 @@ MAX: 9026 };
_defineProperty(this, "fontWrapper", void 0);
_defineProperty(this, "theme", void 0);
_defineProperty(this, "packageParts", void 0);
+ _defineProperty(this, "macros", void 0);
+ if (options.macros !== void 0) {
+ const { project, events = [] } = options.macros;
+ const bytes = project instanceof Uint8Array ? project : new Uint8Array(project);
+ if (!COMPOUND_FILE_SIGNATURE.every((byte, index) => bytes[index] === byte)) throw new Error("macros.project isn't a VBA project. Use createMacros from docx/macros, or the word/vbaProject.bin in a .docm rather than the .docm itself");
+ const relationships = new Relationships();
+ if (events.length > 0) relationships.addRelationship(1, "http://schemas.microsoft.com/office/2006/relationships/wordVbaData", "vbaData.xml");
+ this.macros = {
+ project: bytes,
+ events: events.length > 0 ? createMacroEvents(events) : void 0,
+ relationships
+ };
+ }
this.coreProperties = new CoreProperties(_objectSpread2(_objectSpread2({}, options), {}, {
creator: (_options$creator = options.creator) !== null && _options$creator !== void 0 ? _options$creator : "Un-named",
revision: (_options$revision = options.revision) !== null && _options$revision !== void 0 ? _options$revision : 1,
@@ -23747,7 +23827,8 @@ MAX: 9026 };
this.appProperties = new AppProperties();
this.footnotesWrapper = new FootnotesWrapper();
this.endnotesWrapper = new EndnotesWrapper();
- this.contentTypes = new ContentTypes();
+ this.contentTypes = new ContentTypes({ macros: this.macros !== void 0 });
+ if (((_this$macros = this.macros) === null || _this$macros === void 0 ? void 0 : _this$macros.events) !== void 0) this.contentTypes.addOverride("application/vnd.ms-word.vbaData+xml", "/word/vbaData.xml");
this.packageParts = new PackageParts(this.contentTypes);
this.documentWrapper = new DocumentWrapper({
background: options.background,
@@ -23798,6 +23879,7 @@ MAX: 9026 };
this.fontWrapper = new FontWrapper((_options$fonts2 = options.fonts) !== null && _options$fonts2 !== void 0 ? _options$fonts2 : []);
this.theme = new Theme(options.theme);
this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", "theme/theme1.xml");
+ if (this.macros !== void 0) this.documentWrapper.Relationships.addRelationship(this.currentRelationshipId++, "http://schemas.microsoft.com/office/2006/relationships/vbaProject", "vbaProject.bin");
}
addSection({ headers = {}, footers = {}, children, properties }) {
this.documentWrapper.View.Body.addSection(_objectSpread2(_objectSpread2({}, properties), {}, {
@@ -23929,6 +24011,13 @@ MAX: 9026 };
get PackageParts() {
return this.packageParts;
}
+ /**
+ * The document's macros, when it has any: its VBA project (word/vbaProject.bin), the events of the document it
+ * handles (word/vbaData.xml), and the project's relationships, to the events.
+ */
+ get Macros() {
+ return this.macros;
+ }
};
//#endregion
//#region src/file/table-of-contents/sdt-properties.ts
@@ -34351,6 +34440,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
else zip.file(obj.path, encodeUtf8(obj.data));
for (const { path, data } of packageParts) zip.file(path, typeof data === "string" ? encodeUtf8(data) : data);
for (const subFile of overrides) zip.file(subFile.path, encodeUtf8(subFile.data));
+ if (file.Macros !== void 0) zip.file("word/vbaProject.bin", file.Macros.project);
for (const data of file.Media.Array) if (data.type !== "svg") zip.file(`word/media/${data.fileName}`, data.data);
else {
zip.file(`word/media/${data.fileName}`, data.data);
@@ -34360,6 +34450,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
return zip;
}
xmlifyFile(file, prettify) {
+ var _file$Macros;
const documentXmlData = stringifyXmlable(this.formatter.format(file.Document.View, {
viewWrapper: file.Document,
file,
@@ -34412,7 +34503,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
const commentMediaDatas = this.imageReplacer.getMediaData(commentXmlData, file.Media);
const footnoteMediaDatas = this.imageReplacer.getMediaData(footnoteXmlData, file.Media);
const endnoteMediaDatas = this.imageReplacer.getMediaData(endnoteXmlData, file.Media);
- return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
+ return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
Relationships: {
data: (() => {
const relationships = Relationships.copy(file.Document.Relationships);
@@ -34753,7 +34844,34 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
}
}),
path: "word/theme/theme1.xml"
+ }
+ }, ((_file$Macros = file.Macros) === null || _file$Macros === void 0 ? void 0 : _file$Macros.events) ? {
+ MacroEvents: {
+ data: stringifyXmlable(this.formatter.format(file.Macros.events, {
+ viewWrapper: file.Document,
+ file,
+ stack: []
+ }), {
+ indent: prettify,
+ declaration: {
+ standalone: "yes",
+ encoding: "UTF-8"
+ }
+ }),
+ path: "word/vbaData.xml"
},
+ MacroRelationships: {
+ data: stringifyXmlable(this.formatter.format(file.Macros.relationships, {
+ viewWrapper: file.Document,
+ file,
+ stack: []
+ }), {
+ indent: prettify,
+ declaration: { encoding: "UTF-8" }
+ }),
+ path: "word/_rels/vbaProject.bin.rels"
+ }
+ } : {}), {}, {
PackageParts: xmlifyPackageParts(file, prettify),
Numbering: {
data: stringifyXmlable(this.formatter.format(file.Numbering, {
@@ -34835,6 +34953,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
WITH_TAB: " "
};
var convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
+ var mimeTypeOf = (file) => file.Macros === void 0 ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.ms-word.document.macroEnabled.12";
/**
* Exports documents to various output formats.
*
@@ -34871,7 +34990,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
return _asyncToGenerator(function* (file, type, prettify, overrides = []) {
return _this.compiler.compile(file, convertPrettifyType(prettify), overrides).generateAsync({
type,
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ mimeType: mimeTypeOf(file),
compression: "DEFLATE"
});
}).apply(this, arguments);
@@ -34943,7 +35062,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
const stream = new import_stream_browserify.Stream();
this.compiler.compile(file, convertPrettifyType(prettify), overrides).generateAsync({
type: "nodebuffer",
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ mimeType: mimeTypeOf(file),
compression: "DEFLATE"
}).then((z) => {
stream.emit("data", z);
diff --git a/live-examples/lib/macros.d.ts b/live-examples/lib/macros.d.ts
new file mode 100644
index 0000000000..2b96cbcc49
--- /dev/null
+++ b/live-examples/lib/macros.d.ts
@@ -0,0 +1,71 @@
+import type { DocumentMacroEvent } from 'docx';
+import type { DocumentMacros } from 'docx';
+
+/**
+ * Writes a document's VBA macros from their code, for the document's `macros`: the VBA project, and the events of the
+ * document that ThisDocument's code handles, such as `Document_Open`. The document is then a macro-enabled document,
+ * which Word opens from a .docm file. Word asks whether to enable its macros, as for any document with macros from
+ * elsewhere.
+ *
+ * VBA keeps code in Windows-1252, the code page of Word in English and the other Western European languages, so a
+ * character it doesn't have goes in a string as `ChrW`, such as `ChrW(&H4E2D)` for "中", or two for a character beyond
+ * U+FFFF, such as `ChrW(&HD83D) & ChrW(&HDE00)` for "😀".
+ *
+ * Word compiles the code when it first runs a macro, so a mistake in it shows then, in the VBA editor.
+ *
+ * @publicApi
+ *
+ * @example
+ * ```typescript
+ * const doc = new Document({
+ * macros: createMacros({
+ * thisDocument: 'Private Sub Document_Open()\n MsgBox "Hello"\nEnd Sub',
+ * modules: [{ name: "Formatting", code: "Sub MakeBold()\n Selection.Font.Bold = True\nEnd Sub" }],
+ * }),
+ * sections: [{ children: [new Paragraph("Hello World")] }],
+ * });
+ * ```
+ *
+ * @throws If a module's name isn't a VBA name of up to 31 characters, or is taken: by another module, ignoring case, or
+ * by ThisDocument, the project, Project, or a library it uses, VBA, Word, stdole, Normal or Office
+ * @returns The document's macros, for its `macros`: the VBA project, and the events of the document it handles
+ * @throws If code has a character Windows-1252 doesn't
+ */
+export declare const createMacros: ({ thisDocument, modules, classModules }?: MacrosOptions) => DocumentMacros & {
+ readonly project: Uint8Array;
+ readonly events: readonly DocumentMacroEvent[];
+};
+
+/**
+ * A module of VBA code, as the VBA editor shows it.
+ *
+ * @publicApi
+ */
+export declare type MacroModule = {
+ /**
+ * The module's name, such as "Formatting". A macro in it is "Formatting.MacroName" when the macro's name alone could
+ * be another module's too. It starts with a letter, then has letters, digits and underscores, up to 31 of them
+ */
+ readonly name: string;
+ /** The module's code, as it is typed in the VBA editor */
+ readonly code: string;
+};
+
+/**
+ * Options for {@link createMacros}.
+ *
+ * @publicApi
+ */
+export declare type MacrosOptions = {
+ /**
+ * The code of the document's own module, ThisDocument in the VBA editor, where the document's events are handled,
+ * such as `Document_Open` when it opens
+ */
+ readonly thisDocument?: string;
+ /** Modules, with the macros Word lists in its Macros dialog, and the procedures and functions they use */
+ readonly modules?: readonly MacroModule[];
+ /** Class modules, which define classes of objects */
+ readonly classModules?: readonly MacroModule[];
+};
+
+export { }
diff --git a/live-examples/lib/macros.iife.js b/live-examples/lib/macros.iife.js
new file mode 100644
index 0000000000..efba775480
--- /dev/null
+++ b/live-examples/lib/macros.iife.js
@@ -0,0 +1,687 @@
+var docxMacros = (function(exports) {
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
+ //#region src/macros/code-page.ts
+ /**
+ * The code page the VBA project's text is written in: its code, and the names of the project and its modules.
+ *
+ * @module
+ */
+ /**
+ * Windows-1252, the code page of VBA in Word set to English and the other Western European languages. Its number goes in
+ * the project, which is how VBA knows it.
+ */
+ var CODE_PAGE = 1252;
+ var BYTES = new Map([..."€_‚ƒ„…†‡ˆ‰Š‹Œ_Ž__‘’“”•–—˜™š›œ_žŸ"].flatMap((character, index) => character === "_" ? [] : [[character, 128 + index]]));
+ /**
+ * Encodes text in Windows-1252.
+ *
+ * @param what - What the text is, for the error, such as `The code of module "Greetings"`
+ * @throws If the text has a character Windows-1252 doesn't
+ */
+ var encodeWindows1252 = (text, what) => Uint8Array.from([...text], (character) => {
+ const code = character.codePointAt(0);
+ const byte = code < 128 || code >= 160 && code <= 255 ? code : BYTES.get(character);
+ if (byte === void 0) {
+ const chrW = Array.from({ length: character.length }, (_, index) => `ChrW(&H${character.charCodeAt(index).toString(16).toUpperCase()})`);
+ throw new Error(`${what} has "${character}", which VBA can't keep in its code page, Windows-1252. Write it with ChrW instead, such as ${chrW.join(" & ")} in a string`);
+ }
+ return byte;
+ });
+ //#endregion
+ //#region src/macros/compound-file.ts
+ var SECTOR_SIZE = 512;
+ var MINI_SECTOR_SIZE = 64;
+ var MINI_STREAM_CUTOFF = 4096;
+ var DIRECTORY_ENTRY_SIZE = 128;
+ var SECTOR_NUMBERS_PER_SECTOR = SECTOR_SIZE / 4;
+ var HEADER_FAT_SECTORS = 109;
+ var FREE_SECTOR = 4294967295;
+ var END_OF_CHAIN = 4294967294;
+ var FAT_SECTOR = 4294967293;
+ var NO_STREAM = 4294967295;
+ var STORAGE = 1;
+ var STREAM = 2;
+ var ROOT_STORAGE = 5;
+ var RED = 0;
+ var BLACK = 1;
+ /**
+ * Orders the entries of a storage as the file's red-black trees do: a shorter name first, then by the names in capitals.
+ */
+ var compareNames = (a, b) => {
+ if (a.length !== b.length) return a.length - b.length;
+ const upperA = a.toUpperCase();
+ const upperB = b.toUpperCase();
+ return upperA < upperB ? -1 : upperA > upperB ? 1 : 0;
+ };
+ /**
+ * Links a storage's entries, in order, into a balanced tree that is a valid red-black tree: the entries on its deepest
+ * level are red, and the rest black.
+ *
+ * @returns The id of the tree's root
+ */
+ var linkTree = (entries, ids) => {
+ const depths = [];
+ const link = (from, to, depth) => {
+ if (from > to) return NO_STREAM;
+ const middle = Math.floor((from + to) / 2);
+ const entry = entries[ids[middle]];
+ depths[middle] = depth;
+ entry.left = link(from, middle - 1, depth + 1);
+ entry.right = link(middle + 1, to, depth + 1);
+ return ids[middle];
+ };
+ const root = link(0, ids.length - 1, 0);
+ const deepest = Math.max(...depths);
+ for (const [index, id] of ids.entries()) entries[id].color = depths[index] === deepest && deepest > 0 ? RED : BLACK;
+ return root;
+ };
+ /**
+ * The directory's entries, the root first, with each storage's entries linked into its tree.
+ */
+ var createDirectory = (children) => {
+ const entry = (name, type, data) => {
+ if (name.length === 0 || name.length > 31 || /[/\\:!]/.test(name)) throw new Error(`Invalid compound file entry name "${name}"`);
+ return {
+ name,
+ type,
+ data,
+ left: NO_STREAM,
+ right: NO_STREAM,
+ child: NO_STREAM,
+ color: BLACK,
+ start: 0,
+ size: 0
+ };
+ };
+ const entries = [entry("Root Entry", ROOT_STORAGE)];
+ const addChildren = (parent, storageChildren) => {
+ const sorted = [...storageChildren].sort((a, b) => compareNames(a.name, b.name));
+ for (const [index, child] of sorted.entries()) if (index > 0 && compareNames(sorted[index - 1].name, child.name) === 0) throw new Error(`Two compound file entries in a storage are named "${child.name}"`);
+ const ids = sorted.map((child) => {
+ entries.push("children" in child ? entry(child.name, STORAGE) : entry(child.name, STREAM, child.data));
+ return entries.length - 1;
+ });
+ parent.child = ids.length === 0 ? NO_STREAM : linkTree(entries, ids);
+ for (const [index, child] of sorted.entries()) if ("children" in child) addChildren(entries[ids[index]], child.children);
+ };
+ addChildren(entries[0], children);
+ return entries;
+ };
+ /**
+ * Lays out a chain of sectors, each pointing to the next, in a table of sector numbers, such as the FAT.
+ *
+ * @returns The chain's first sector, or END_OF_CHAIN for none
+ */
+ var addChain = (table, count, value) => {
+ if (count === 0) return END_OF_CHAIN;
+ const start = table.length;
+ for (let index = 0; index < count; index++) table.push(value !== null && value !== void 0 ? value : index === count - 1 ? END_OF_CHAIN : start + index + 1);
+ return start;
+ };
+ /**
+ * Writes a compound file of version 3, as Office writes VBA projects.
+ *
+ * @param children - The root storage's streams and storages
+ * @throws If two entries of a storage have the same name, ignoring case, or a name is empty, longer than 31 characters or
+ * has "/", "\", ":" or "!"
+ */
+ var createCompoundFile = (children) => {
+ const entries = createDirectory(children);
+ const streams = entries.filter((entry) => entry.type === STREAM);
+ const miniStreams = streams.filter((entry) => entry.data.length < MINI_STREAM_CUTOFF);
+ const largeStreams = streams.filter((entry) => entry.data.length >= MINI_STREAM_CUTOFF);
+ const miniFat = [];
+ for (const stream of miniStreams) {
+ stream.start = addChain(miniFat, Math.ceil(stream.data.length / MINI_SECTOR_SIZE));
+ stream.size = stream.data.length;
+ }
+ const miniStreamSize = miniFat.length * MINI_SECTOR_SIZE;
+ const fat = [];
+ const directoryStart = addChain(fat, Math.ceil(entries.length / (SECTOR_SIZE / DIRECTORY_ENTRY_SIZE)));
+ const miniFatSectors = Math.ceil(miniFat.length / SECTOR_NUMBERS_PER_SECTOR);
+ const miniFatStart = addChain(fat, miniFatSectors);
+ entries[0].start = addChain(fat, Math.ceil(miniStreamSize / SECTOR_SIZE));
+ entries[0].size = miniStreamSize;
+ for (const stream of largeStreams) {
+ stream.start = addChain(fat, Math.ceil(stream.data.length / SECTOR_SIZE));
+ stream.size = stream.data.length;
+ }
+ let fatSectors = 0;
+ while (fatSectors * SECTOR_NUMBERS_PER_SECTOR < fat.length + fatSectors) fatSectors++;
+ if (fatSectors > HEADER_FAT_SECTORS) throw new Error(`A compound file of more than ${13952 * SECTOR_SIZE} bytes isn't supported`);
+ const fatStart = addChain(fat, fatSectors, FAT_SECTOR);
+ const file = new Uint8Array(SECTOR_SIZE + fat.length * SECTOR_SIZE);
+ const view = new DataView(file.buffer);
+ const sectorOffset = (sector) => SECTOR_SIZE + sector * SECTOR_SIZE;
+ file.set([
+ 208,
+ 207,
+ 17,
+ 224,
+ 161,
+ 177,
+ 26,
+ 225
+ ]);
+ view.setUint16(24, 62, true);
+ view.setUint16(26, 3, true);
+ view.setUint16(28, 65534, true);
+ view.setUint16(30, 9, true);
+ view.setUint16(32, 6, true);
+ view.setUint32(44, fatSectors, true);
+ view.setUint32(48, directoryStart, true);
+ view.setUint32(56, MINI_STREAM_CUTOFF, true);
+ view.setUint32(60, miniFatStart, true);
+ view.setUint32(64, miniFatSectors, true);
+ view.setUint32(68, END_OF_CHAIN, true);
+ for (let index = 0; index < HEADER_FAT_SECTORS; index++) view.setUint32(76 + index * 4, index < fatSectors ? fatStart + index : FREE_SECTOR, true);
+ for (let index = 0; index < Math.ceil(entries.length / 4) * 4; index++) {
+ const offset = sectorOffset(directoryStart) + index * DIRECTORY_ENTRY_SIZE;
+ const entry = entries[index];
+ if (entry === void 0) {
+ view.setUint32(offset + 68, NO_STREAM, true);
+ view.setUint32(offset + 72, NO_STREAM, true);
+ view.setUint32(offset + 76, NO_STREAM, true);
+ continue;
+ }
+ for (let position = 0; position < entry.name.length; position++) view.setUint16(offset + position * 2, entry.name.charCodeAt(position), true);
+ view.setUint16(offset + 64, (entry.name.length + 1) * 2, true);
+ view.setUint8(offset + 66, entry.type);
+ view.setUint8(offset + 67, entry.color);
+ view.setUint32(offset + 68, entry.left, true);
+ view.setUint32(offset + 72, entry.right, true);
+ view.setUint32(offset + 76, entry.child, true);
+ view.setUint32(offset + 116, entry.type === STORAGE ? 0 : entry.start, true);
+ view.setUint32(offset + 120, entry.size, true);
+ }
+ for (let index = 0; index < miniFatSectors * SECTOR_NUMBERS_PER_SECTOR; index++) {
+ var _miniFat$index;
+ view.setUint32(sectorOffset(miniFatStart) + index * 4, (_miniFat$index = miniFat[index]) !== null && _miniFat$index !== void 0 ? _miniFat$index : FREE_SECTOR, true);
+ }
+ for (const stream of miniStreams) file.set(stream.data, sectorOffset(entries[0].start) + stream.start * MINI_SECTOR_SIZE);
+ for (const stream of largeStreams) file.set(stream.data, sectorOffset(stream.start));
+ for (let index = 0; index < fatSectors * SECTOR_NUMBERS_PER_SECTOR; index++) {
+ var _fat$index;
+ view.setUint32(sectorOffset(fatStart) + index * 4, (_fat$index = fat[index]) !== null && _fat$index !== void 0 ? _fat$index : FREE_SECTOR, true);
+ }
+ return file;
+ };
+ //#endregion
+ //#region src/macros/compression.ts
+ /**
+ * The compression VBA uses for a project's module information and for each module's code, a run length encoding.
+ *
+ * Reference: [MS-OVBA] 2.4.1 Compression and Decompression
+ *
+ * @module
+ */
+ var CHUNK_SIZE = 4096;
+ /**
+ * The bits of a copy token that hold the copy's length, the rest holding its offset. The further into its chunk a copy
+ * is, the more bits its offset can need.
+ *
+ * Reference: [MS-OVBA] 2.4.1.3.19.1 CopyToken Help
+ *
+ * @param position - How far into its chunk the copy is, at least 1
+ */
+ var lengthBitsAt = (position) => 16 - Math.max(32 - Math.clz32(position - 1), 4);
+ /**
+ * The longest earlier run of bytes in the chunk that the bytes from `current` repeat, the nearest of the longest.
+ *
+ * Reference: [MS-OVBA] 2.4.1.3.19.4 Matching
+ *
+ * @returns How far back the run starts and how long it is, or `undefined` for none of at least 3 bytes
+ */
+ var findMatch = (data, chunkStart, current, chunkEnd) => {
+ let bestLength = 0;
+ let bestCandidate = 0;
+ for (let candidate = current - 1; candidate >= chunkStart; candidate--) {
+ let length = 0;
+ while (current + length < chunkEnd && data[current + length] === data[candidate + length]) length++;
+ if (length > bestLength) {
+ bestLength = length;
+ bestCandidate = candidate;
+ }
+ }
+ if (bestLength < 3) return;
+ const maximumLength = (1 << lengthBitsAt(current - chunkStart)) - 1 + 3;
+ return {
+ offset: current - bestCandidate,
+ length: Math.min(bestLength, maximumLength)
+ };
+ };
+ /**
+ * Compresses a chunk: groups of up to eight tokens, each group after a byte whose bits say which of its tokens are a
+ * byte as it is and which copy earlier bytes.
+ *
+ * Reference: [MS-OVBA] 2.4.1.3.7 Compressing a DecompressedChunk
+ */
+ var compressChunk = (data, chunkStart, chunkEnd) => {
+ const tokens = [];
+ let current = chunkStart;
+ while (current < chunkEnd) {
+ const flagIndex = tokens.length;
+ tokens.push(0);
+ for (let index = 0; index < 8 && current < chunkEnd; index++) {
+ const match = findMatch(data, chunkStart, current, chunkEnd);
+ if (match === void 0) {
+ tokens.push(data[current]);
+ current++;
+ } else {
+ const lengthBits = lengthBitsAt(current - chunkStart);
+ const token = match.offset - 1 << lengthBits | match.length - 3;
+ tokens.push(token & 255, token >> 8);
+ tokens[flagIndex] |= 1 << index;
+ current += match.length;
+ }
+ }
+ }
+ if (tokens.length <= CHUNK_SIZE) {
+ const compressedHeader = 45056 | tokens.length + 2 - 3;
+ return [
+ compressedHeader & 255,
+ compressedHeader >> 8,
+ ...tokens
+ ];
+ }
+ const raw = new Uint8Array(CHUNK_SIZE);
+ raw.set(data.subarray(chunkStart, chunkEnd));
+ return [
+ 255,
+ 63,
+ ...raw
+ ];
+ };
+ /**
+ * Compresses data as VBA does.
+ *
+ * Reference: [MS-OVBA] 2.4.1.3.6 Compression algorithm
+ */
+ var compress = (data) => {
+ const output = [1];
+ for (let chunkStart = 0; chunkStart < data.length; chunkStart += CHUNK_SIZE) output.push(...compressChunk(data, chunkStart, Math.min(chunkStart + CHUNK_SIZE, data.length)));
+ return Uint8Array.from(output);
+ };
+ //#endregion
+ //#region \0@oxc-project+runtime@0.152.0/helpers/esm/typeof.js
+ function _typeof(o) {
+ "@babel/helpers - typeof";
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
+ return typeof o;
+ } : function(o) {
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
+ }, _typeof(o);
+ }
+ //#endregion
+ //#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPrimitive.js
+ function toPrimitive(t, r) {
+ if ("object" != _typeof(t) || !t) return t;
+ var e = t[Symbol.toPrimitive];
+ if (void 0 !== e) {
+ var i = e.call(t, r || "default");
+ if ("object" != _typeof(i)) return i;
+ throw new TypeError("@@toPrimitive must return a primitive value.");
+ }
+ return ("string" === r ? String : Number)(t);
+ }
+ //#endregion
+ //#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPropertyKey.js
+ function toPropertyKey(t) {
+ var i = toPrimitive(t, "string");
+ return "symbol" == _typeof(i) ? i : i + "";
+ }
+ //#endregion
+ //#region \0@oxc-project+runtime@0.152.0/helpers/esm/defineProperty.js
+ function _defineProperty(e, r, t) {
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
+ value: t,
+ enumerable: !0,
+ configurable: !0,
+ writable: !0
+ }) : e[r] = t, e;
+ }
+ //#endregion
+ //#region \0@oxc-project+runtime@0.152.0/helpers/esm/objectSpread2.js
+ function ownKeys(e, r) {
+ var t = Object.keys(e);
+ if (Object.getOwnPropertySymbols) {
+ var o = Object.getOwnPropertySymbols(e);
+ r && (o = o.filter(function(r) {
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
+ })), t.push.apply(t, o);
+ }
+ return t;
+ }
+ function _objectSpread2(e) {
+ for (var r = 1; r < arguments.length; r++) {
+ var t = null != arguments[r] ? arguments[r] : {};
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
+ _defineProperty(e, r, t[r]);
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
+ });
+ }
+ return e;
+ }
+ //#endregion
+ //#region src/macros/create-macros.ts
+ var PROJECT_NAME = "Project";
+ var PROJECT_ID = "{6D8A8E5B-1C9F-4E2B-9A4D-3B5F7C2E1D60}";
+ var REFERENCES = [
+ {
+ name: "stdole",
+ registered: "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\System32\\stdole2.tlb#OLE Automation"
+ },
+ {
+ name: "Normal",
+ project: "*\\CNormal"
+ },
+ {
+ name: "Office",
+ registered: "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE16\\MSO.DLL#Microsoft Office 16.0 Object Library"
+ }
+ ];
+ var TAKEN_NAMES = [
+ "ThisDocument",
+ PROJECT_NAME,
+ "VBA",
+ "Word",
+ ...REFERENCES.map(({ name }) => name)
+ ];
+ var ATTRIBUTES = {
+ document: (name) => [
+ `Attribute VB_Name = "${name}"`,
+ "Attribute VB_Base = \"1Normal.ThisDocument\"",
+ "Attribute VB_GlobalNameSpace = False",
+ "Attribute VB_Creatable = False",
+ "Attribute VB_PredeclaredId = True",
+ "Attribute VB_Exposed = True",
+ "Attribute VB_TemplateDerived = True",
+ "Attribute VB_Customizable = True"
+ ].join("\r\n"),
+ module: (name) => `Attribute VB_Name = "${name}"`,
+ class: (name) => [
+ `Attribute VB_Name = "${name}"`,
+ "Attribute VB_Base = \"0{FCFB3D2A-A0FA-1068-A738-08002B3371B5}\"",
+ "Attribute VB_GlobalNameSpace = False",
+ "Attribute VB_Creatable = False",
+ "Attribute VB_PredeclaredId = False",
+ "Attribute VB_Exposed = False",
+ "Attribute VB_TemplateDerived = False",
+ "Attribute VB_Customizable = False"
+ ].join("\r\n")
+ };
+ var uint16 = (value) => [value & 255, value >> 8 & 255];
+ var uint32 = (value) => [
+ value & 255,
+ value >> 8 & 255,
+ value >> 16 & 255,
+ value >>> 24 & 255
+ ];
+ var utf16 = (text) => [...text].flatMap((character) => uint16(character.charCodeAt(0)));
+ /**
+ * A record of the project's module information: its id, the size of its data, then its data.
+ */
+ var record = (id, data) => [
+ ...uint16(id),
+ ...uint32(data.length),
+ ...data
+ ];
+ /**
+ * Obfuscates one of the project's properties as VBA does, as hexadecimal digits: whether it is locked, its password and
+ * whether it is shown.
+ *
+ * Reference: [MS-OVBA] 2.4.3.2 Encryption
+ *
+ * @param seed - Any byte. Its bits 1 and 2 are how many bytes of padding go before the data
+ */
+ var obfuscate = (data, seed) => {
+ const version = 2;
+ const projectKey = [...PROJECT_ID].reduce((sum, character) => sum + character.charCodeAt(0) & 255, 0);
+ const versionEncrypted = seed ^ version;
+ const projectKeyEncrypted = seed ^ projectKey;
+ const output = [
+ seed,
+ versionEncrypted,
+ projectKeyEncrypted
+ ];
+ let unencrypted = projectKey;
+ let encrypted = projectKeyEncrypted;
+ let previousEncrypted = versionEncrypted;
+ const write = (byte) => {
+ const value = (byte ^ previousEncrypted + unencrypted & 255) & 255;
+ output.push(value);
+ previousEncrypted = encrypted;
+ encrypted = value;
+ unencrypted = byte;
+ };
+ const padding = (seed & 6) / 2;
+ for (let index = 0; index < padding; index++) write(0);
+ for (const byte of [...uint32(data.length), ...data]) write(byte);
+ return output.map((byte) => byte.toString(16).toUpperCase().padStart(2, "0")).join("");
+ };
+ /**
+ * The PROJECT stream: the project's properties, as text.
+ *
+ * Reference: [MS-OVBA] 2.3.1 PROJECT Stream
+ */
+ var createProjectStream = (modules) => {
+ const items = modules.map(({ name, kind }) => kind === "document" ? `Document=${name}/&H00000000` : kind === "module" ? `Module=${name}` : `Class=${name}`);
+ return encodeWindows1252([
+ `ID="${PROJECT_ID}"`,
+ ...items,
+ `Name="${PROJECT_NAME}"`,
+ "HelpContextID=\"0\"",
+ "VersionCompatible32=\"393222000\"",
+ `CMG="${obfuscate(uint32(0), 138)}"`,
+ `DPB="${obfuscate([0], 163)}"`,
+ `GC="${obfuscate([255], 188)}"`,
+ "",
+ "[Host Extender Info]",
+ "&H00000001={3832D640-CF90-11CF-8E43-00A0C911005A};VBE;&H00000000",
+ "",
+ "[Workspace]",
+ ...modules.map(({ name }) => `${name}=0, 0, 0, 0, C`)
+ ].map((line) => `${line}\r\n`).join(""), "The project");
+ };
+ /**
+ * The PROJECTwm stream: the modules' names in Unicode too.
+ *
+ * Reference: [MS-OVBA] 2.3.3 PROJECTwm Stream
+ */
+ var createNamesStream = (modules) => Uint8Array.from([
+ ...modules.flatMap(({ name }) => [
+ ...encodeWindows1252(name, "A module's name"),
+ 0,
+ ...utf16(name),
+ 0,
+ 0
+ ]),
+ 0,
+ 0
+ ]);
+ /**
+ * The dir stream: the project's information, the libraries it refers to and its modules, compressed.
+ *
+ * Reference: [MS-OVBA] 2.3.4.2 dir Stream
+ */
+ var createDirStream = (modules) => {
+ const name = (text) => [...encodeWindows1252(text, "A name")];
+ const information = [
+ ...record(1, uint32(1)),
+ ...record(2, uint32(1033)),
+ ...record(20, uint32(1033)),
+ ...record(3, uint16(CODE_PAGE)),
+ ...record(4, name(PROJECT_NAME)),
+ ...record(5, []),
+ ...record(64, []),
+ ...record(6, []),
+ ...record(61, []),
+ ...record(7, uint32(0)),
+ ...record(8, uint32(0)),
+ ...uint16(9),
+ ...uint32(4),
+ ...uint32(1),
+ ...uint16(0),
+ ...record(12, []),
+ ...record(60, [])
+ ];
+ const references = REFERENCES.flatMap((reference) => {
+ const referenceName = [...record(22, name(reference.name)), ...record(62, utf16(reference.name))];
+ if ("project" in reference) {
+ const projectId = name(reference.project);
+ return [...referenceName, ...record(14, [
+ ...uint32(projectId.length),
+ ...projectId,
+ ...uint32(projectId.length),
+ ...projectId,
+ ...uint32(1),
+ ...uint16(0)
+ ])];
+ }
+ const libraryId = name(reference.registered);
+ return [...referenceName, ...record(13, [
+ ...uint32(libraryId.length),
+ ...libraryId,
+ ...uint32(0),
+ ...uint16(0)
+ ])];
+ });
+ const moduleRecords = modules.flatMap((module) => [
+ ...record(25, name(module.name)),
+ ...record(71, utf16(module.name)),
+ ...record(26, name(module.name)),
+ ...record(50, utf16(module.name)),
+ ...record(28, []),
+ ...record(72, []),
+ ...record(49, uint32(0)),
+ ...record(30, uint32(0)),
+ ...record(44, uint16(65535)),
+ ...record(module.kind === "module" ? 33 : 34, []),
+ ...record(43, [])
+ ]);
+ return compress(Uint8Array.from([
+ ...information,
+ ...references,
+ ...record(15, uint16(modules.length)),
+ ...record(19, uint16(65535)),
+ ...moduleRecords,
+ ...record(16, [])
+ ]));
+ };
+ var NAME = /^[A-Za-z][A-Za-z0-9_]{0,30}$/;
+ var EVENTS = new Map([
+ "new",
+ "open",
+ "close",
+ "sync",
+ "xmlAfterInsert",
+ "xmlBeforeDelete",
+ "contentControlAfterAdd",
+ "contentControlBeforeDelete",
+ "contentControlOnExit",
+ "contentControlOnEnter",
+ "contentControlBeforeStoreUpdate",
+ "contentControlBeforeContentUpdate",
+ "buildingBlockInsert"
+ ].map((event) => [event.toUpperCase(), event]));
+ var EVENT_HANDLER = /^[ \t]*(?:(?:Private|Public|Friend)[ \t]+)?(?:Static[ \t]+)?Sub[ \t]+Document_(\w+)[ \t]*\(/gim;
+ /**
+ * The events of the document that ThisDocument's code has a handler for, which Word runs the handlers of.
+ */
+ var findEvents = (code) => [...new Set([...code.matchAll(EVENT_HANDLER)].flatMap(([, name]) => {
+ var _EVENTS$get;
+ return (_EVENTS$get = EVENTS.get(name.toUpperCase())) !== null && _EVENTS$get !== void 0 ? _EVENTS$get : [];
+ }))];
+ /**
+ * Writes a document's VBA macros from their code, for the document's `macros`: the VBA project, and the events of the
+ * document that ThisDocument's code handles, such as `Document_Open`. The document is then a macro-enabled document,
+ * which Word opens from a .docm file. Word asks whether to enable its macros, as for any document with macros from
+ * elsewhere.
+ *
+ * VBA keeps code in Windows-1252, the code page of Word in English and the other Western European languages, so a
+ * character it doesn't have goes in a string as `ChrW`, such as `ChrW(&H4E2D)` for "中", or two for a character beyond
+ * U+FFFF, such as `ChrW(&HD83D) & ChrW(&HDE00)` for "😀".
+ *
+ * Word compiles the code when it first runs a macro, so a mistake in it shows then, in the VBA editor.
+ *
+ * @publicApi
+ *
+ * @example
+ * ```typescript
+ * const doc = new Document({
+ * macros: createMacros({
+ * thisDocument: 'Private Sub Document_Open()\n MsgBox "Hello"\nEnd Sub',
+ * modules: [{ name: "Formatting", code: "Sub MakeBold()\n Selection.Font.Bold = True\nEnd Sub" }],
+ * }),
+ * sections: [{ children: [new Paragraph("Hello World")] }],
+ * });
+ * ```
+ *
+ * @throws If a module's name isn't a VBA name of up to 31 characters, or is taken: by another module, ignoring case, or
+ * by ThisDocument, the project, Project, or a library it uses, VBA, Word, stdole, Normal or Office
+ * @returns The document's macros, for its `macros`: the VBA project, and the events of the document it handles
+ * @throws If code has a character Windows-1252 doesn't
+ */
+ var createMacros = ({ thisDocument = "", modules = [], classModules = [] } = {}) => {
+ const given = [...modules.map((module) => _objectSpread2(_objectSpread2({}, module), {}, { kind: "module" })), ...classModules.map((module) => _objectSpread2(_objectSpread2({}, module), {}, { kind: "class" }))];
+ for (const [index, { name }] of given.entries()) {
+ if (!NAME.test(name)) throw new Error(`Invalid module name "${name}". Expected a letter, then letters, digits and underscores, up to 31 of them, such as "Formatting"`);
+ const taken = [...TAKEN_NAMES, ...given.slice(0, index).map((module) => module.name)].find((takenName) => takenName.toLowerCase() === name.toLowerCase());
+ if (taken !== void 0) throw new Error(`Invalid module name "${name}". ${taken} is already a name in the project`);
+ }
+ const projectModules = [{
+ name: "ThisDocument",
+ kind: "document",
+ code: thisDocument
+ }, ...given].map(({ name, kind, code }) => {
+ const lines = code.replace(/\r\n?/g, "\n").replace(/\n$/, "");
+ return {
+ name,
+ kind,
+ source: encodeWindows1252(`${ATTRIBUTES[kind](name)}\r\n${lines === "" ? "" : `${lines.replace(/\n/g, "\r\n")}\r\n`}`, `The code of ${name}`)
+ };
+ });
+ return {
+ project: createCompoundFile([
+ {
+ name: "VBA",
+ children: [
+ {
+ name: "_VBA_PROJECT",
+ data: Uint8Array.from([
+ 204,
+ 97,
+ 255,
+ 255,
+ 0,
+ 1,
+ 0
+ ])
+ },
+ {
+ name: "dir",
+ data: createDirStream(projectModules)
+ },
+ ...projectModules.map(({ name, source }) => ({
+ name,
+ data: compress(source)
+ }))
+ ]
+ },
+ {
+ name: "PROJECT",
+ data: createProjectStream(projectModules)
+ },
+ {
+ name: "PROJECTwm",
+ data: createNamesStream(projectModules)
+ }
+ ]),
+ events: findEvents(thisDocument)
+ };
+ };
+ //#endregion
+ exports.createMacros = createMacros;
+ return exports;
+})({});
diff --git a/live-examples/live-examples.js b/live-examples/live-examples.js
index 3e2a2f151b..19079fee01 100644
--- a/live-examples/live-examples.js
+++ b/live-examples/live-examples.js
@@ -34,6 +34,7 @@
"docx/layout": { file: "layout", global: "docxLayout" },
// docx/html writes math with docx/math, so it is loaded after it
"docx/html": { file: "html", global: "docxHtml", after: ["docx/math"] },
+ "docx/macros": { file: "macros", global: "docxMacros" },
};
// Packages from npm an example can import too, from jsDelivr at the version the docs are written for: where each is, and
@@ -48,6 +49,10 @@
// docx-preview draws these as empty space
const NOT_DRAWN = { "docx/shapes": "shapes", "docx/charts": "charts", "docx/watermarks": "watermarks" };
+ // The type of a document with macros, a .docm, which Word doesn't open as a .docx. A blob's type is in lower case
+ const DOCM = "application/vnd.ms-word.document.macroenabled.12";
+ const extensionOf = (blob) => (blob.type === DOCM ? "docm" : "docx");
+
// The editor's types for what docx's types use from Node, and for the parts of Node an example can use
const NODE_TYPES = `
declare class Buffer extends Uint8Array {
@@ -184,7 +189,10 @@ declare module "stream" {
const AsyncFunction = (async () => {}).constructor;
- /** Runs an example, and returns the .docx it makes: the one it writes with fs.writeFileSync, or else its last Document */
+ /**
+ * Runs an example, and returns the .docx or .docm it makes: the one it writes with fs.writeFileSync, or else its last
+ * Document
+ */
const make = async (source) => {
const imports = importsOf(source).filter((name) => name in MODULES);
const packageNames = importsOf(source).filter((name) => name in PACKAGES);
@@ -235,8 +243,8 @@ declare module "stream" {
return encoding ? new FileBuffer(bytes).toString(encoding) : new FileBuffer(bytes);
},
writeFileSync: (path, data, encoding) => {
- if (/\.docx$/i.test(path)) {
- written = bytesOf(data, encoding);
+ if (/\.doc[xm]$/i.test(path)) {
+ written = new Blob([bytesOf(data, encoding)], /\.docm$/i.test(path) ? { type: DOCM } : {});
}
},
createWriteStream: () => ({}),
@@ -265,7 +273,7 @@ declare module "stream" {
await new Promise((resolve) => setTimeout(resolve));
if (written) {
- return new Blob([written]);
+ return written;
}
const failure = results.find((result) => result.status === "rejected");
if (failure) {
@@ -397,7 +405,7 @@ declare module "stream" {
const download = button("Download .docx", () => {
const link = document.createElement("a");
link.href = URL.createObjectURL(example.blob);
- link.download = "example.docx";
+ link.download = `example.${extensionOf(example.blob)}`;
link.click();
// Some browsers start the download after click() returns
setTimeout(() => URL.revokeObjectURL(link.href), 60_000);
@@ -469,13 +477,18 @@ declare module "stream" {
pages.classList.remove("drawing");
fit();
example.blob = blob;
+ download.textContent = `Download .${extensionOf(blob)}`;
download.disabled = false;
preview.classList.remove("live-example__preview--stale");
const notDrawn = importsOf(source)
.filter((name) => name in NOT_DRAWN)
.map((name) => NOT_DRAWN[name]);
setStatus(
- notDrawn.length > 0 ? `The preview can't draw ${notDrawn.join(" or ")}. Download the file to see them in Word.` : "",
+ notDrawn.length > 0
+ ? `The preview can't draw ${notDrawn.join(" or ")}. Download the file to see them in Word.`
+ : blob.type === DOCM
+ ? "The preview doesn't run macros. Download the .docm to run them in Word."
+ : "",
);
} catch (error) {
if (runNumber === example.runs) {
diff --git a/usage/macros.md b/usage/macros.md
new file mode 100644
index 0000000000..67f15d8659
--- /dev/null
+++ b/usage/macros.md
@@ -0,0 +1,199 @@
+# Macros
+
+
+
+A document can have VBA macros: code that Word runs from its Macros dialog, or when something happens to the document, such as when it opens. A document with macros is a macro-enabled document, saved as a `.docm`.
+
+`createMacros` writes a document's macros from their VBA code. It comes with the `docx` package, from `docx/macros`, and the macros go in the document's `macros`:
+
+```ts
+import { Document, Packer, Paragraph } from "docx";
+import { createMacros } from "docx/macros";
+```
+
+In a page without a bundler, load `dist/macros.umd.cjs` after `dist/index.umd.cjs` (or `dist/macros.iife.js` after `dist/index.iife.js`). It adds a `docxMacros` global, such as `docxMacros.createMacros({ ... })`.
+
+## Example
+
+```ts live
+import * as fs from "fs";
+import { Document, Packer, Paragraph } from "docx";
+import { createMacros } from "docx/macros";
+
+const doc = new Document({
+ macros: createMacros({
+ modules: [
+ {
+ name: "Greetings",
+ code: `
+Sub SayHello()
+ MsgBox "Hello from docx"
+End Sub
+`,
+ },
+ ],
+ }),
+ sections: [{ children: [new Paragraph("Run SayHello from View > Macros.")] }],
+});
+
+Packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My Document.docm", buffer);
+});
+```
+
+Save a document with macros as a `.docm`. Word won't open it from a `.docx`, the extension of a document without macros. `Packer.toBlob` gives it a `.docm`'s type, `application/vnd.ms-word.document.macroEnabled.12`.
+
+Word disables the macros of a document from elsewhere until they are enabled, as for any `.docm`. Word for Mac asks when the document opens, and Word for Windows shows a bar with **Enable Content**. Word for Windows [blocks the macros of a file from the internet](https://learn.microsoft.com/en-us/microsoft-365-apps/security/internet-macros-blocked), though, such as a `.docm` a web page made and the browser downloaded, without **Enable Content**. To run them, right-click the file, choose **Properties** and tick **Unblock** on the **General** tab. An organization's policy can block macros all the same. Word for the web doesn't run macros.
+
+## Options
+
+| Property | Type | Notes | Description |
+| -------------- | --------------- | -------- | -------------------------------------------------------------------------------------------------------------- |
+| `thisDocument` | `string` | Optional | The code of the document's own module, ThisDocument in the VBA editor, where the document's events are handled |
+| `modules` | `MacroModule[]` | Optional | Modules, with the macros Word lists in its Macros dialog, and the procedures and functions they use |
+| `classModules` | `MacroModule[]` | Optional | Class modules, which define classes of objects |
+
+Each module is:
+
+| Property | Type | Notes | Description |
+| -------- | -------- | -------- | --------------------------------------------------------------------------------------------------------- |
+| `name` | `string` | Required | The module's name, such as `Formatting`. A letter, then letters, digits and underscores, up to 31 of them |
+| `code` | `string` | Required | The module's code, as it is typed in the VBA editor |
+
+A module can't have the name of another, ignoring case, or a name the project has already: `ThisDocument`, `Project`, and the libraries it uses, `VBA`, `Word`, `stdole`, `Normal` and `Office`.
+
+Word compiles the code when it first runs a macro, so a mistake in it shows then, in the VBA editor.
+
+## The document's events
+
+ThisDocument handles the document's events, such as `Document_Open` when it opens and `Document_Close` when it closes. Word only runs the handler of an event the document lists, and `createMacros` lists those `thisDocument` has.
+
+```ts live
+import * as fs from "fs";
+import { Document, Packer, Paragraph } from "docx";
+import { createMacros } from "docx/macros";
+
+const doc = new Document({
+ macros: createMacros({
+ thisDocument: `
+Private Sub Document_Open()
+ ActiveDocument.Content.InsertParagraphAfter
+ ActiveDocument.Content.InsertAfter "Opened on " & Format(Date, "d mmmm yyyy") & "."
+End Sub
+`,
+ }),
+ sections: [{ children: [new Paragraph("Enable macros when Word asks, and the date it opened is added below.")] }],
+});
+
+Packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My Document.docm", buffer);
+});
+```
+
+## Class modules
+
+A class module defines a class, which code in the other modules makes objects of with `New`:
+
+```ts live
+import * as fs from "fs";
+import { Document, Packer, Paragraph } from "docx";
+import { createMacros } from "docx/macros";
+
+const doc = new Document({
+ macros: createMacros({
+ modules: [
+ {
+ name: "Counting",
+ code: `
+Sub CountParagraphs()
+ Dim tally As New Counter
+ Dim item As Paragraph
+ For Each item In ActiveDocument.Paragraphs
+ tally.Add
+ Next
+ MsgBox "This document has " & tally.Value & " paragraphs"
+End Sub
+`,
+ },
+ ],
+ classModules: [
+ {
+ name: "Counter",
+ code: `
+Private count As Long
+
+Public Sub Add()
+ count = count + 1
+End Sub
+
+Public Property Get Value() As Long
+ Value = count
+End Property
+`,
+ },
+ ],
+ }),
+ sections: [{ children: [new Paragraph("Run CountParagraphs from View > Macros."), new Paragraph("This is the second.")] }],
+});
+
+Packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My Document.docm", buffer);
+});
+```
+
+## Characters in the code
+
+VBA keeps code in Windows-1252, the code page of Word in English and the other Western European languages. It has the accented letters of those languages, and `createMacros` throws for a character it doesn't have. Write one in a string with `ChrW` and its code in hexadecimal instead, such as `ChrW(&H4E2D)` for "中". `ChrW` goes up to `&HFFFF`, so a character beyond that, such as an emoji, is two, its UTF-16 surrogate pair: `ChrW(&HD83D) & ChrW(&HDE00)` for "😀". The error `createMacros` throws gives the `ChrW` to write.
+
+## Macros from a .docm
+
+A `.docm` Word saved keeps its macros in its `word/vbaProject.bin`. A `.docm` is a zip, so the file is in it, as it is in a `.docx`. Give the document it as `macros.project`, with the events its ThisDocument handles:
+
+```ts live
+import * as fs from "fs";
+import { Document, Packer, Paragraph } from "docx";
+
+const doc = new Document({
+ macros: {
+ project: fs.readFileSync("./demo/assets/vbaProject.bin"),
+ events: ["open"],
+ },
+ sections: [{ children: [new Paragraph("Enable macros when Word asks, and the document says where its macros came from.")] }],
+});
+
+Packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My Document.docm", buffer);
+});
+```
+
+The `.docm` lists the events in its `word/vbaData.xml`, in ``:
+
+| Handler in ThisDocument | In `events` | In `word/vbaData.xml` |
+| -------------------------------------------- | ------------------------------------- | ----------------------------------------- |
+| `Document_New` | `"new"` | `wne:eventDocNew` |
+| `Document_Open` | `"open"` | `wne:eventDocOpen` |
+| `Document_Close` | `"close"` | `wne:eventDocClose` |
+| `Document_Sync` | `"sync"` | `wne:eventDocSync` |
+| `Document_XMLAfterInsert` | `"xmlAfterInsert"` | `wne:eventDocXmlAfterInsert` |
+| `Document_XMLBeforeDelete` | `"xmlBeforeDelete"` | `wne:eventDocXmlBeforeDelete` |
+| `Document_ContentControlAfterAdd` | `"contentControlAfterAdd"` | `wne:eventDocContentControlAfterInsert` |
+| `Document_ContentControlBeforeDelete` | `"contentControlBeforeDelete"` | `wne:eventDocContentControlBeforeDelete` |
+| `Document_ContentControlOnExit` | `"contentControlOnExit"` | `wne:eventDocContentControlOnExit` |
+| `Document_ContentControlOnEnter` | `"contentControlOnEnter"` | `wne:eventDocContentControlOnEnter` |
+| `Document_ContentControlBeforeStoreUpdate` | `"contentControlBeforeStoreUpdate"` | `wne:eventDocStoreUpdate` |
+| `Document_ContentControlBeforeContentUpdate` | `"contentControlBeforeContentUpdate"` | `wne:eventDocContentControlContentUpdate` |
+| `Document_BuildingBlockInsert` | `"buildingBlockInsert"` | `wne:eventDocBuildingBlockAfterInsert` |
+
+## Examples
+
+### Macros from their code
+
+[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/macros/macros.ts ":include")
+
+_Source: https://github.com/dolanmiu/docx/blob/master/demo/macros/macros.ts_
+
+### Macros from a .docm
+
+[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/macros/macros-from-docm.ts ":include")
+
+_Source: https://github.com/dolanmiu/docx/blob/master/demo/macros/macros-from-docm.ts_
Example