docx 9.9.0 → 9.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/html.cjs +14192 -0
- package/dist/html.d.cts +152 -0
- package/dist/html.d.ts +152 -0
- package/dist/html.iife.js +14193 -0
- package/dist/html.mjs +14190 -0
- package/dist/html.umd.cjs +14198 -0
- package/dist/index.cjs +729 -173
- package/dist/index.d.cts +194 -21
- package/dist/index.d.ts +194 -21
- package/dist/index.iife.js +729 -173
- package/dist/index.mjs +729 -173
- package/dist/index.umd.cjs +729 -173
- package/dist/layout.cjs +1 -6
- package/dist/layout.iife.js +1 -6
- package/dist/layout.mjs +1 -6
- package/dist/layout.umd.cjs +1 -6
- package/package.json +24 -5
package/dist/index.iife.js
CHANGED
|
@@ -11033,7 +11033,7 @@ DOT: "dot" };
|
|
|
11033
11033
|
if (options.imprint !== void 0) this.push(new OnOffElement("w:imprint", options.imprint));
|
|
11034
11034
|
if (options.noProof !== void 0) this.push(new OnOffElement("w:noProof", options.noProof));
|
|
11035
11035
|
if (options.snapToGrid !== void 0) this.push(new OnOffElement("w:snapToGrid", options.snapToGrid));
|
|
11036
|
-
if (options.vanish) this.push(new OnOffElement("w:vanish", options.vanish));
|
|
11036
|
+
if (options.vanish !== void 0) this.push(new OnOffElement("w:vanish", options.vanish));
|
|
11037
11037
|
if (options.color) this.push(new Color(options.color));
|
|
11038
11038
|
if (options.characterSpacing) this.push(new CharacterSpacing(options.characterSpacing));
|
|
11039
11039
|
if (options.scale !== void 0) this.push(new NumberValueElement("w:w", options.scale));
|
|
@@ -11052,8 +11052,8 @@ DOT: "dot" };
|
|
|
11052
11052
|
if (options.rightToLeft !== void 0) this.push(new OnOffElement("w:rtl", options.rightToLeft));
|
|
11053
11053
|
if (options.emphasisMark) this.push(createEmphasisMark(options.emphasisMark.type));
|
|
11054
11054
|
if (options.language) this.push(createLanguageComponent(options.language));
|
|
11055
|
-
if (options.specVanish) this.push(new OnOffElement("w:specVanish", options.
|
|
11056
|
-
if (options.math) this.push(new OnOffElement("w:oMath", options.math));
|
|
11055
|
+
if (options.specVanish !== void 0) this.push(new OnOffElement("w:specVanish", options.specVanish));
|
|
11056
|
+
if (options.math !== void 0) this.push(new OnOffElement("w:oMath", options.math));
|
|
11057
11057
|
if (options.revision) this.push(new RunPropertiesChange(options.revision));
|
|
11058
11058
|
}
|
|
11059
11059
|
push(item) {
|
|
@@ -12787,7 +12787,7 @@ DOT: "dot" };
|
|
|
12787
12787
|
hash.sha512 = hash.sha.sha512;
|
|
12788
12788
|
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
12789
12789
|
})))(), 1);
|
|
12790
|
-
var urlAlphabet = "
|
|
12790
|
+
var urlAlphabet = "57X6y3wQZNzYjJB2L_10pxbackgroundhimselfUTF-8DEMOGRAPHICSVqvt4KW9";
|
|
12791
12791
|
//#endregion
|
|
12792
12792
|
//#region node_modules/nanoid/non-secure/index.js
|
|
12793
12793
|
var customAlphabet = (alphabet, defaultSize = 21) => {
|
|
@@ -14584,48 +14584,6 @@ DOT: "dot" };
|
|
|
14584
14584
|
}
|
|
14585
14585
|
};
|
|
14586
14586
|
//#endregion
|
|
14587
|
-
//#region src/file/drawing/doc-properties/doc-properties-children.ts
|
|
14588
|
-
/**
|
|
14589
|
-
* Child elements for document properties.
|
|
14590
|
-
*
|
|
14591
|
-
* This module provides hyperlink elements that can be attached to
|
|
14592
|
-
* drawing elements for interactive behavior.
|
|
14593
|
-
*
|
|
14594
|
-
* @module
|
|
14595
|
-
*/
|
|
14596
|
-
/**
|
|
14597
|
-
* Creates a click hyperlink element for a drawing.
|
|
14598
|
-
*
|
|
14599
|
-
* This element defines what happens when a user clicks on a drawing element.
|
|
14600
|
-
*
|
|
14601
|
-
* ## XSD Schema
|
|
14602
|
-
* ```xml
|
|
14603
|
-
* <xsd:complexType name="CT_Hyperlink">
|
|
14604
|
-
* <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded"/>
|
|
14605
|
-
* <xsd:attribute name="tgtFrame" type="s:ST_String"/>
|
|
14606
|
-
* <xsd:attribute name="tooltip" type="s:ST_String"/>
|
|
14607
|
-
* <xsd:attribute name="docLocation" type="s:ST_String"/>
|
|
14608
|
-
* <xsd:attribute name="history" type="s:ST_OnOff"/>
|
|
14609
|
-
* <xsd:attribute name="anchor" type="s:ST_String"/>
|
|
14610
|
-
* <xsd:attribute ref="r:id"/>
|
|
14611
|
-
* </xsd:complexType>
|
|
14612
|
-
* ```
|
|
14613
|
-
*
|
|
14614
|
-
* @param linkId - The relationship ID for the hyperlink target
|
|
14615
|
-
* @param hasXmlNs - Whether to include the XML namespace declaration
|
|
14616
|
-
* @returns An XML component representing the click hyperlink
|
|
14617
|
-
*/
|
|
14618
|
-
var createHyperlinkClick = (linkId, hasXmlNs) => new BuilderElement({
|
|
14619
|
-
name: "a:hlinkClick",
|
|
14620
|
-
attributes: _objectSpread2(_objectSpread2({}, hasXmlNs ? { xmlns: {
|
|
14621
|
-
key: "xmlns:a",
|
|
14622
|
-
value: "http://schemas.openxmlformats.org/drawingml/2006/main"
|
|
14623
|
-
} } : {}), {}, { id: {
|
|
14624
|
-
key: "r:id",
|
|
14625
|
-
value: `rId${linkId}`
|
|
14626
|
-
} })
|
|
14627
|
-
});
|
|
14628
|
-
//#endregion
|
|
14629
14587
|
//#region src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts
|
|
14630
14588
|
/**
|
|
14631
14589
|
* Non-visual properties attributes module.
|
|
@@ -14706,7 +14664,7 @@ DOT: "dot" };
|
|
|
14706
14664
|
for (let i = context.stack.length - 1; i >= 0; i--) {
|
|
14707
14665
|
const element = context.stack[i];
|
|
14708
14666
|
if (!(element instanceof ConcreteHyperlink)) continue;
|
|
14709
|
-
this.root.push(
|
|
14667
|
+
this.root.push(element.createDrawingClick(context, false));
|
|
14710
14668
|
break;
|
|
14711
14669
|
}
|
|
14712
14670
|
const result = super.prepForXml(context);
|
|
@@ -15376,6 +15334,48 @@ EXTERNAL: "External" };
|
|
|
15376
15334
|
}
|
|
15377
15335
|
});
|
|
15378
15336
|
//#endregion
|
|
15337
|
+
//#region src/file/drawing/doc-properties/doc-properties-children.ts
|
|
15338
|
+
/**
|
|
15339
|
+
* Child elements for document properties.
|
|
15340
|
+
*
|
|
15341
|
+
* This module provides hyperlink elements that can be attached to
|
|
15342
|
+
* drawing elements for interactive behavior.
|
|
15343
|
+
*
|
|
15344
|
+
* @module
|
|
15345
|
+
*/
|
|
15346
|
+
/**
|
|
15347
|
+
* Creates a click hyperlink element for a drawing.
|
|
15348
|
+
*
|
|
15349
|
+
* This element defines what happens when a user clicks on a drawing element.
|
|
15350
|
+
*
|
|
15351
|
+
* ## XSD Schema
|
|
15352
|
+
* ```xml
|
|
15353
|
+
* <xsd:complexType name="CT_Hyperlink">
|
|
15354
|
+
* <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded"/>
|
|
15355
|
+
* <xsd:attribute name="tgtFrame" type="s:ST_String"/>
|
|
15356
|
+
* <xsd:attribute name="tooltip" type="s:ST_String"/>
|
|
15357
|
+
* <xsd:attribute name="docLocation" type="s:ST_String"/>
|
|
15358
|
+
* <xsd:attribute name="history" type="s:ST_OnOff"/>
|
|
15359
|
+
* <xsd:attribute name="anchor" type="s:ST_String"/>
|
|
15360
|
+
* <xsd:attribute ref="r:id"/>
|
|
15361
|
+
* </xsd:complexType>
|
|
15362
|
+
* ```
|
|
15363
|
+
*
|
|
15364
|
+
* @param linkId - The relationship ID for the hyperlink target
|
|
15365
|
+
* @param hasXmlNs - Whether to include the XML namespace declaration
|
|
15366
|
+
* @returns An XML component representing the click hyperlink
|
|
15367
|
+
*/
|
|
15368
|
+
var createHyperlinkClick = (linkId, hasXmlNs) => new BuilderElement({
|
|
15369
|
+
name: "a:hlinkClick",
|
|
15370
|
+
attributes: _objectSpread2(_objectSpread2({}, hasXmlNs ? { xmlns: {
|
|
15371
|
+
key: "xmlns:a",
|
|
15372
|
+
value: "http://schemas.openxmlformats.org/drawingml/2006/main"
|
|
15373
|
+
} } : {}), {}, { id: {
|
|
15374
|
+
key: "r:id",
|
|
15375
|
+
value: `rId${linkId}`
|
|
15376
|
+
} })
|
|
15377
|
+
});
|
|
15378
|
+
//#endregion
|
|
15379
15379
|
//#region src/file/drawing/doc-properties/non-visual-drawing-properties.ts
|
|
15380
15380
|
/**
|
|
15381
15381
|
* Non-visual drawing properties (`CT_NonVisualDrawingProps`) of the shapes, pictures and groups inside a drawing:
|
|
@@ -15570,7 +15570,7 @@ EXTERNAL: "External" };
|
|
|
15570
15570
|
} else for (let i = context.stack.length - 1; i >= 0; i--) {
|
|
15571
15571
|
const element = context.stack[i];
|
|
15572
15572
|
if (!(element instanceof ConcreteHyperlink)) continue;
|
|
15573
|
-
this.root.push(
|
|
15573
|
+
this.root.push(element.createDrawingClick(context, true));
|
|
15574
15574
|
break;
|
|
15575
15575
|
}
|
|
15576
15576
|
if (this.decorative) this.root.push(createDecorativeExtensionList(true));
|
|
@@ -16885,14 +16885,14 @@ EXTERNAL: "External" };
|
|
|
16885
16885
|
}
|
|
16886
16886
|
};
|
|
16887
16887
|
/** The name of a formatted element, or `_attr` for its parent's attributes */
|
|
16888
|
-
var nameOf$
|
|
16888
|
+
var nameOf$3 = (element) => typeof element === "object" && element !== null ? Object.keys(element)[0] : void 0;
|
|
16889
16889
|
/** The children of a formatted element. An element with only attributes has them as its one child */
|
|
16890
16890
|
var childrenOf = (element) => {
|
|
16891
|
-
const name = nameOf$
|
|
16891
|
+
const name = nameOf$3(element);
|
|
16892
16892
|
const content = name === void 0 ? void 0 : element[name];
|
|
16893
16893
|
return Array.isArray(content) ? content : content === void 0 ? [] : [content];
|
|
16894
16894
|
};
|
|
16895
|
-
var childOf = (element, name) => childrenOf(element).find((child) => nameOf$
|
|
16895
|
+
var childOf = (element, name) => childrenOf(element).find((child) => nameOf$3(child) === name);
|
|
16896
16896
|
var attributeOf = (element, attribute) => {
|
|
16897
16897
|
var _childOf;
|
|
16898
16898
|
return (_childOf = childOf(element, "_attr")) === null || _childOf === void 0 || (_childOf = _childOf._attr) === null || _childOf === void 0 ? void 0 : _childOf[attribute];
|
|
@@ -16916,7 +16916,7 @@ EXTERNAL: "External" };
|
|
|
16916
16916
|
* so the paragraphs in it aren't taken for headings. Nor are paragraphs in text boxes, as in Word.
|
|
16917
16917
|
*/
|
|
16918
16918
|
var blocksOf = (elements) => elements.flatMap((element) => {
|
|
16919
|
-
const name = nameOf$
|
|
16919
|
+
const name = nameOf$3(element);
|
|
16920
16920
|
if (name === "w:p" || writtenTables.has(element)) return [element];
|
|
16921
16921
|
return name !== void 0 && BLOCK_CONTAINERS.has(name) ? blocksOf(childrenOf(element)) : [];
|
|
16922
16922
|
});
|
|
@@ -16936,7 +16936,7 @@ EXTERNAL: "External" };
|
|
|
16936
16936
|
]);
|
|
16937
16937
|
/** The text an element in a run stands for, such as `\t` for a tab. A page or column break isn't text */
|
|
16938
16938
|
var textOfRunContent = (element) => {
|
|
16939
|
-
switch (nameOf$
|
|
16939
|
+
switch (nameOf$3(element)) {
|
|
16940
16940
|
case "w:t": return childrenOf(element).filter((child) => typeof child === "string").join("");
|
|
16941
16941
|
case "w:tab": return " ";
|
|
16942
16942
|
case "w:br": return [void 0, "textWrapping"].includes(attributeOf(element, "w:type")) ? "\n" : "";
|
|
@@ -16949,7 +16949,7 @@ EXTERNAL: "External" };
|
|
|
16949
16949
|
var textOf = (paragraph) => {
|
|
16950
16950
|
const fields = [];
|
|
16951
16951
|
const read = (element) => {
|
|
16952
|
-
const name = nameOf$
|
|
16952
|
+
const name = nameOf$3(element);
|
|
16953
16953
|
if (name !== void 0 && TEXT_CONTAINERS.has(name)) return childrenOf(element).map(read).join("");
|
|
16954
16954
|
if (name === "w:fldChar") {
|
|
16955
16955
|
const type = attributeOf(element, "w:fldCharType");
|
|
@@ -16964,7 +16964,7 @@ EXTERNAL: "External" };
|
|
|
16964
16964
|
};
|
|
16965
16965
|
/** The bookmarks started and ended in an element, in order */
|
|
16966
16966
|
var bookmarkMarksOf = (element) => {
|
|
16967
|
-
const name = nameOf$
|
|
16967
|
+
const name = nameOf$3(element);
|
|
16968
16968
|
if (name === "w:bookmarkStart") return [{
|
|
16969
16969
|
start: true,
|
|
16970
16970
|
id: attributeOf(element, "w:id"),
|
|
@@ -17009,7 +17009,7 @@ EXTERNAL: "External" };
|
|
|
17009
17009
|
var stylesOf = (context) => {
|
|
17010
17010
|
var _context$file;
|
|
17011
17011
|
const styles = (_context$file = context.file) === null || _context$file === void 0 || (_context$file = _context$file.Styles) === null || _context$file === void 0 ? void 0 : _context$file.prepForXml(context);
|
|
17012
|
-
return new Map(childrenOf(styles).filter((style) => nameOf$
|
|
17012
|
+
return new Map(childrenOf(styles).filter((style) => nameOf$3(style) === "w:style" && ["paragraph", void 0].includes(attributeOf(style, "w:type"))).map((style) => [attributeOf(style, "w:styleId"), {
|
|
17013
17013
|
name: attributeOf(childOf(style, "w:name"), "w:val"),
|
|
17014
17014
|
basedOn: attributeOf(childOf(style, "w:basedOn"), "w:val"),
|
|
17015
17015
|
outlineLevel: numberAttributeOf(childOf(childOf(style, "w:pPr"), "w:outlineLvl"), "w:val")
|
|
@@ -17137,7 +17137,7 @@ EXTERNAL: "External" };
|
|
|
17137
17137
|
/** Puts a bookmark around the content of a formatted paragraph */
|
|
17138
17138
|
var bookmark = (paragraph, name, id, context) => {
|
|
17139
17139
|
const children = childrenOf(paragraph);
|
|
17140
|
-
const start = children.findIndex((child) => nameOf$
|
|
17140
|
+
const start = children.findIndex((child) => nameOf$3(child) === "w:pPr") + 1;
|
|
17141
17141
|
paragraph["w:p"] = [
|
|
17142
17142
|
...children.slice(0, start),
|
|
17143
17143
|
new BookmarkStart(name, id).prepForXml(context),
|
|
@@ -17158,7 +17158,7 @@ EXTERNAL: "External" };
|
|
|
17158
17158
|
if (tables.length === 0) return;
|
|
17159
17159
|
const styles = stylesOf(context);
|
|
17160
17160
|
const followBookmarks = tables.some(([, { properties }]) => Boolean(properties.entriesFromBookmark));
|
|
17161
|
-
const headings = paragraphDetailsOf(blocks.filter((block) => nameOf$
|
|
17161
|
+
const headings = paragraphDetailsOf(blocks.filter((block) => nameOf$3(block) === "w:p"), followBookmarks).map((paragraph) => ({
|
|
17162
17162
|
paragraph,
|
|
17163
17163
|
levels: tables.map(([, { properties }]) => levelIn(properties, paragraph, styles))
|
|
17164
17164
|
})).filter(({ levels }) => levels.some((level) => level !== void 0)).map((heading, index) => _objectSpread2(_objectSpread2({}, heading), {}, { id: bookmarkIds.get(index) }));
|
|
@@ -17173,7 +17173,7 @@ EXTERNAL: "External" };
|
|
|
17173
17173
|
}];
|
|
17174
17174
|
});
|
|
17175
17175
|
if (entries.length === 0) return;
|
|
17176
|
-
table["w:sdt"] = childrenOf(table).map((child) => nameOf$
|
|
17176
|
+
table["w:sdt"] = childrenOf(table).map((child) => nameOf$3(child) === "w:sdtContent" ? contentOf(options, entries, styles, context) : child);
|
|
17177
17177
|
});
|
|
17178
17178
|
};
|
|
17179
17179
|
//#endregion
|
|
@@ -17353,21 +17353,21 @@ EXTERNAL: "External" };
|
|
|
17353
17353
|
*
|
|
17354
17354
|
* @module
|
|
17355
17355
|
*/
|
|
17356
|
-
var nameOf$
|
|
17356
|
+
var nameOf$2 = (element) => {
|
|
17357
17357
|
const name = typeof element === "object" && element !== null && !Array.isArray(element) ? Object.keys(element)[0] : void 0;
|
|
17358
17358
|
return name === "_attr" ? void 0 : name;
|
|
17359
17359
|
};
|
|
17360
17360
|
var textElement = (text) => ({ "w:t": [{ _attr: { "xml:space": "preserve" } }, text] });
|
|
17361
17361
|
/** The elements docx formats to write a document */
|
|
17362
17362
|
var FORMATTED = {
|
|
17363
|
-
nameOf: nameOf$
|
|
17363
|
+
nameOf: nameOf$2,
|
|
17364
17364
|
contentOf: (element) => {
|
|
17365
|
-
const content = element[nameOf$
|
|
17365
|
+
const content = element[nameOf$2(element)];
|
|
17366
17366
|
return Array.isArray(content) ? content : void 0;
|
|
17367
17367
|
},
|
|
17368
17368
|
attributeOf: (element, attribute) => {
|
|
17369
17369
|
var _holder$_attr;
|
|
17370
|
-
const content = element[nameOf$
|
|
17370
|
+
const content = element[nameOf$2(element)];
|
|
17371
17371
|
const holder = Array.isArray(content) ? content.find((child) => typeof child === "object" && child !== null && "_attr" in child) : content;
|
|
17372
17372
|
return holder === null || holder === void 0 || (_holder$_attr = holder._attr) === null || _holder$_attr === void 0 ? void 0 : _holder$_attr[attribute];
|
|
17373
17373
|
},
|
|
@@ -18496,9 +18496,9 @@ EXTERNAL: "External" };
|
|
|
18496
18496
|
var LineRuleType = {
|
|
18497
18497
|
/** Line spacing is at least the specified value */
|
|
18498
18498
|
AT_LEAST: "atLeast",
|
|
18499
|
-
/**
|
|
18499
|
+
/** Writes `exactly`, which isn't a value the schema allows, so Word ignores it. Use {@link LineRuleType.EXACT} for an exact line height. */
|
|
18500
18500
|
EXACTLY: "exactly",
|
|
18501
|
-
/** Line spacing is exactly the specified value
|
|
18501
|
+
/** Line spacing is exactly the specified value */
|
|
18502
18502
|
EXACT: "exact",
|
|
18503
18503
|
/** Line spacing is automatically determined based on content */
|
|
18504
18504
|
AUTO: "auto"
|
|
@@ -18958,20 +18958,44 @@ MAX: 9026 };
|
|
|
18958
18958
|
* ```
|
|
18959
18959
|
*/
|
|
18960
18960
|
var ConcreteHyperlink = class extends XmlComponent {
|
|
18961
|
-
|
|
18961
|
+
/**
|
|
18962
|
+
* @param children - Inline content of the hyperlink
|
|
18963
|
+
* @param relationshipId - Id of the external relationship, without the rId prefix
|
|
18964
|
+
* @param anchor - Bookmark name or external URL fragment
|
|
18965
|
+
* @param externalLink - The full address of an external hyperlink, so the relationship id is kept alongside its anchor
|
|
18966
|
+
*/
|
|
18967
|
+
constructor(children, relationshipId, anchor, externalLink) {
|
|
18962
18968
|
super("w:hyperlink");
|
|
18963
18969
|
_defineProperty(this, "linkId", void 0);
|
|
18970
|
+
_defineProperty(this, "drawingLink", void 0);
|
|
18964
18971
|
this.linkId = relationshipId;
|
|
18972
|
+
this.drawingLink = anchor && externalLink !== void 0 ? new DrawingLink(externalLink) : void 0;
|
|
18965
18973
|
const attributes = new HyperlinkAttributes({
|
|
18966
18974
|
history: 1,
|
|
18967
18975
|
anchor: anchor ? anchor : void 0,
|
|
18968
|
-
id: !anchor ? `rId${this.linkId}` : void 0
|
|
18976
|
+
id: !anchor || externalLink !== void 0 ? `rId${this.linkId}` : void 0
|
|
18969
18977
|
});
|
|
18970
18978
|
this.root.push(attributes);
|
|
18971
18979
|
children.forEach((child) => {
|
|
18972
18980
|
this.root.push(child);
|
|
18973
18981
|
});
|
|
18974
18982
|
}
|
|
18983
|
+
/**
|
|
18984
|
+
* Creates the `a:hlinkClick` of a picture in the hyperlink, which links to the same address.
|
|
18985
|
+
*
|
|
18986
|
+
* The hyperlink decides which relationship its pictures use, rather than the pictures reading `linkId`, because only it
|
|
18987
|
+
* knows whether that relationship has lost the fragment to `w:anchor`. The picture's relationship is added as the
|
|
18988
|
+
* picture is written, through the context's relationships, so it lands in the part the picture is in, both when
|
|
18989
|
+
* packing and when patching.
|
|
18990
|
+
*
|
|
18991
|
+
* @param context - The context the picture is written in, whose relationships get the picture's link if it has its own
|
|
18992
|
+
* @param declareNamespace - Declares the DrawingML namespace, for elements outside `a:graphic` such as `wp:docPr`
|
|
18993
|
+
*/
|
|
18994
|
+
createDrawingClick(context, declareNamespace) {
|
|
18995
|
+
if (!this.drawingLink) return createHyperlinkClick(this.linkId, declareNamespace);
|
|
18996
|
+
this.drawingLink.addRelationship(context);
|
|
18997
|
+
return this.drawingLink.createClick(declareNamespace);
|
|
18998
|
+
}
|
|
18975
18999
|
};
|
|
18976
19000
|
/**
|
|
18977
19001
|
* Represents an internal hyperlink to a bookmark within the document.
|
|
@@ -19020,6 +19044,11 @@ MAX: 9026 };
|
|
|
19020
19044
|
* External hyperlinks create a relationship to an external resource (URL).
|
|
19021
19045
|
* The relationship is created during document preparation and the hyperlink
|
|
19022
19046
|
* is converted to a ConcreteHyperlink with the relationship ID.
|
|
19047
|
+
* URL fragments of at most 255 UTF-16 units are written as anchors, preserving any additional # characters.
|
|
19048
|
+
* Longer fragments stay in the original relationship URI to avoid exceeding Word's anchor limit;
|
|
19049
|
+
* those links retain the existing limitations for fragments with multiple # characters.
|
|
19050
|
+
* Word appends the anchor to the relationship target as described in MS-OI29500 §17.16.22:
|
|
19051
|
+
* https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oi29500/df06e423-11a6-4a36-bfb3-82139e531781
|
|
19023
19052
|
*
|
|
19024
19053
|
* Reference: http://officeopenxml.com/WPhyperlink.php
|
|
19025
19054
|
*
|
|
@@ -19033,6 +19062,7 @@ MAX: 9026 };
|
|
|
19033
19062
|
* <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded"/>
|
|
19034
19063
|
* <xsd:attribute ref="r:id"/>
|
|
19035
19064
|
* <xsd:attribute name="history" type="s:ST_OnOff" use="optional"/>
|
|
19065
|
+
* <xsd:attribute name="anchor" type="s:ST_String" use="optional"/>
|
|
19036
19066
|
* </xsd:complexType>
|
|
19037
19067
|
* ```
|
|
19038
19068
|
*
|
|
@@ -19481,6 +19511,29 @@ MAX: 9026 };
|
|
|
19481
19511
|
}
|
|
19482
19512
|
};
|
|
19483
19513
|
//#endregion
|
|
19514
|
+
//#region src/file/paragraph/links/external-hyperlink-target.ts
|
|
19515
|
+
/**
|
|
19516
|
+
* External hyperlink targets and fragments for WordprocessingML.
|
|
19517
|
+
*
|
|
19518
|
+
* Word appends the anchor to the relationship target, separated by a # character.
|
|
19519
|
+
* Reference: https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oi29500/df06e423-11a6-4a36-bfb3-82139e531781
|
|
19520
|
+
*
|
|
19521
|
+
* @module
|
|
19522
|
+
*/
|
|
19523
|
+
var MAX_ANCHOR_LENGTH = 255;
|
|
19524
|
+
/**
|
|
19525
|
+
* Splits a nonempty fragment that fits Word's anchor limit without decoding or normalizing either part.
|
|
19526
|
+
* Longer fragments stay in the original relationship URI, retaining its existing multi-hash limitations.
|
|
19527
|
+
*/
|
|
19528
|
+
var externalHyperlinkTarget = (link) => {
|
|
19529
|
+
const index = link.indexOf("#");
|
|
19530
|
+
const fragmentLength = link.length - index - 1;
|
|
19531
|
+
return index > 0 && fragmentLength > 0 && fragmentLength <= MAX_ANCHOR_LENGTH ? {
|
|
19532
|
+
target: link.slice(0, index),
|
|
19533
|
+
anchor: link.slice(index + 1)
|
|
19534
|
+
} : { target: link };
|
|
19535
|
+
};
|
|
19536
|
+
//#endregion
|
|
19484
19537
|
//#region src/file/fonts/font.ts
|
|
19485
19538
|
/**
|
|
19486
19539
|
* Font module for WordprocessingML documents.
|
|
@@ -19619,32 +19672,26 @@ MAX: 9026 };
|
|
|
19619
19672
|
]
|
|
19620
19673
|
});
|
|
19621
19674
|
//#endregion
|
|
19622
|
-
//#region src/file/fonts/create-
|
|
19675
|
+
//#region src/file/fonts/create-embedded-font.ts
|
|
19623
19676
|
/**
|
|
19624
|
-
* Creates
|
|
19677
|
+
* Creates an embedded font with default settings.
|
|
19625
19678
|
*
|
|
19626
19679
|
* This helper function creates a font definition with standard font signature
|
|
19627
19680
|
* values that work for most common fonts. The signature specifies Unicode
|
|
19628
19681
|
* and code page ranges supported by the font.
|
|
19629
19682
|
*
|
|
19630
|
-
* @param options - Font creation options
|
|
19631
|
-
* @param options.name - Font name
|
|
19632
|
-
* @param options.index - Font relationship index
|
|
19633
|
-
* @param options.fontKey - Unique font key (GUID) for obfuscation
|
|
19634
|
-
* @param options.characterSet - Optional character set identifier
|
|
19635
|
-
*
|
|
19636
19683
|
* @returns XmlComponent representing the font definition
|
|
19637
19684
|
*
|
|
19638
19685
|
* @example
|
|
19639
19686
|
* ```typescript
|
|
19640
|
-
* const font =
|
|
19687
|
+
* const font = createEmbeddedFont({
|
|
19641
19688
|
* name: "Arial",
|
|
19642
|
-
*
|
|
19643
|
-
* fontKey: "12345678-1234-1234-1234-
|
|
19689
|
+
* embedRegular: { id: "rId1", fontKey: "12345678-1234-1234-1234-123456789012" },
|
|
19690
|
+
* embedBold: { id: "rId2", fontKey: "12345678-1234-1234-1234-123456789013" },
|
|
19644
19691
|
* });
|
|
19645
19692
|
* ```
|
|
19646
19693
|
*/
|
|
19647
|
-
var
|
|
19694
|
+
var createEmbeddedFont = ({ name, characterSet, embedRegular, embedBold, embedItalic, embedBoldItalic }) => createFont({
|
|
19648
19695
|
name,
|
|
19649
19696
|
sig: {
|
|
19650
19697
|
usb0: "E0002AFF",
|
|
@@ -19657,10 +19704,10 @@ MAX: 9026 };
|
|
|
19657
19704
|
charset: characterSet,
|
|
19658
19705
|
family: "auto",
|
|
19659
19706
|
pitch: "variable",
|
|
19660
|
-
embedRegular
|
|
19661
|
-
|
|
19662
|
-
|
|
19663
|
-
|
|
19707
|
+
embedRegular,
|
|
19708
|
+
embedBold,
|
|
19709
|
+
embedItalic,
|
|
19710
|
+
embedBoldItalic
|
|
19664
19711
|
});
|
|
19665
19712
|
//#endregion
|
|
19666
19713
|
//#region src/file/fonts/font-table.ts
|
|
@@ -19738,25 +19785,47 @@ MAX: 9026 };
|
|
|
19738
19785
|
value: "w14 w15 w16se w16cid w16 w16cex w16sdtdh"
|
|
19739
19786
|
}
|
|
19740
19787
|
},
|
|
19741
|
-
children: fonts.map(
|
|
19742
|
-
name: font.name,
|
|
19743
|
-
index: i + 1,
|
|
19744
|
-
fontKey: font.fontKey,
|
|
19745
|
-
characterSet: font.characterSet
|
|
19746
|
-
}))
|
|
19788
|
+
children: fonts.map(createEmbeddedFont)
|
|
19747
19789
|
});
|
|
19748
19790
|
//#endregion
|
|
19749
19791
|
//#region src/file/fonts/font-wrapper.ts
|
|
19792
|
+
var FACES = [
|
|
19793
|
+
{
|
|
19794
|
+
option: "data",
|
|
19795
|
+
element: "embedRegular",
|
|
19796
|
+
bold: false,
|
|
19797
|
+
italic: false
|
|
19798
|
+
},
|
|
19799
|
+
{
|
|
19800
|
+
option: "bold",
|
|
19801
|
+
element: "embedBold",
|
|
19802
|
+
bold: true,
|
|
19803
|
+
italic: false
|
|
19804
|
+
},
|
|
19805
|
+
{
|
|
19806
|
+
option: "italic",
|
|
19807
|
+
element: "embedItalic",
|
|
19808
|
+
bold: false,
|
|
19809
|
+
italic: true
|
|
19810
|
+
},
|
|
19811
|
+
{
|
|
19812
|
+
option: "boldItalic",
|
|
19813
|
+
element: "embedBoldItalic",
|
|
19814
|
+
bold: true,
|
|
19815
|
+
italic: true
|
|
19816
|
+
}
|
|
19817
|
+
];
|
|
19750
19818
|
/**
|
|
19751
19819
|
* Wrapper class for managing the font table and its relationships.
|
|
19752
19820
|
*
|
|
19753
19821
|
* Creates a font table with embedded font files and manages the relationships
|
|
19754
|
-
* required for font embedding. Each font is
|
|
19822
|
+
* required for font embedding. Each face of a font is embedded as a file of its own,
|
|
19823
|
+
* with a unique key for obfuscation.
|
|
19755
19824
|
*
|
|
19756
19825
|
* @example
|
|
19757
19826
|
* ```typescript
|
|
19758
19827
|
* const fontWrapper = new FontWrapper([
|
|
19759
|
-
* { name: "CustomFont", data: fontBuffer }
|
|
19828
|
+
* { name: "CustomFont", data: fontBuffer, bold: boldFontBuffer }
|
|
19760
19829
|
* ]);
|
|
19761
19830
|
* ```
|
|
19762
19831
|
*/
|
|
@@ -19765,12 +19834,43 @@ MAX: 9026 };
|
|
|
19765
19834
|
_defineProperty(this, "options", void 0);
|
|
19766
19835
|
_defineProperty(this, "fontTable", void 0);
|
|
19767
19836
|
_defineProperty(this, "relationships", void 0);
|
|
19768
|
-
_defineProperty(
|
|
19837
|
+
_defineProperty(
|
|
19838
|
+
this,
|
|
19839
|
+
/** @deprecated Use `files`, which has the file and key of each face a font embeds, not only the regular face's key */
|
|
19840
|
+
"fontOptionsWithKey",
|
|
19841
|
+
[]
|
|
19842
|
+
);
|
|
19843
|
+
_defineProperty(
|
|
19844
|
+
this,
|
|
19845
|
+
/** The files of the faces the fonts embed, in order: the Nth is `fonts/font<N>.odttf`, with the relationship `rId<N>` */
|
|
19846
|
+
"files",
|
|
19847
|
+
[]
|
|
19848
|
+
);
|
|
19769
19849
|
this.options = options;
|
|
19770
|
-
|
|
19771
|
-
|
|
19850
|
+
const faces = options.map((font) => FACES.flatMap(({ option, element, bold, italic }) => {
|
|
19851
|
+
const data = font[option];
|
|
19852
|
+
return data ? [{
|
|
19853
|
+
element,
|
|
19854
|
+
file: {
|
|
19855
|
+
name: font.name,
|
|
19856
|
+
data,
|
|
19857
|
+
bold,
|
|
19858
|
+
italic,
|
|
19859
|
+
fontKey: uniqueUuid()
|
|
19860
|
+
}
|
|
19861
|
+
}] : [];
|
|
19862
|
+
}));
|
|
19863
|
+
this.files = faces.flatMap((ofFont) => ofFont.map(({ file }) => file));
|
|
19864
|
+
this.fontOptionsWithKey = options.map((font, index) => _objectSpread2(_objectSpread2({}, font), {}, { fontKey: faces[index][0].file.fontKey }));
|
|
19865
|
+
this.fontTable = createFontTable(options.map((font, index) => _objectSpread2({
|
|
19866
|
+
name: font.name,
|
|
19867
|
+
characterSet: font.characterSet
|
|
19868
|
+
}, Object.fromEntries(faces[index].map(({ element, file }) => [element, {
|
|
19869
|
+
id: `rId${this.files.indexOf(file) + 1}`,
|
|
19870
|
+
fontKey: file.fontKey
|
|
19871
|
+
}])))));
|
|
19772
19872
|
this.relationships = new Relationships();
|
|
19773
|
-
for (let i = 0; i <
|
|
19873
|
+
for (let i = 0; i < this.files.length; i++) this.relationships.addRelationship(i + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font", `fonts/font${i + 1}.odttf`);
|
|
19774
19874
|
}
|
|
19775
19875
|
get View() {
|
|
19776
19876
|
return this.fontTable;
|
|
@@ -20130,12 +20230,14 @@ MAX: 9026 };
|
|
|
20130
20230
|
if (options.widowControl !== void 0) this.push(new OnOffElement("w:widowControl", options.widowControl));
|
|
20131
20231
|
if (options.bullet) this.push(new NumberProperties(1, options.bullet.level));
|
|
20132
20232
|
if (options.numbering) {
|
|
20133
|
-
|
|
20233
|
+
const { reference: list, instance = 0, level } = options.numbering;
|
|
20234
|
+
const reference = typeof list === "string" ? list : list.reference;
|
|
20134
20235
|
this.numberingReferences.push({
|
|
20135
|
-
reference
|
|
20136
|
-
instance
|
|
20236
|
+
reference,
|
|
20237
|
+
instance,
|
|
20238
|
+
definition: typeof list === "string" ? void 0 : list
|
|
20137
20239
|
});
|
|
20138
|
-
this.push(new NumberProperties(`${
|
|
20240
|
+
this.push(new NumberProperties(`${reference}-${instance}`, level));
|
|
20139
20241
|
} else if (options.numbering === false) this.push(new NumberProperties(0, 0));
|
|
20140
20242
|
if (options.border) this.push(new Border(options.border));
|
|
20141
20243
|
if (options.thematicBreak) this.push(new ThematicBreak());
|
|
@@ -20215,7 +20317,7 @@ MAX: 9026 };
|
|
|
20215
20317
|
* @returns The prepared XML object, or undefined if the component should be ignored
|
|
20216
20318
|
*/
|
|
20217
20319
|
prepForXml(context) {
|
|
20218
|
-
if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this.numberingReferences) context.file.Numbering.createConcreteNumberingInstance(reference
|
|
20320
|
+
if (!(context.viewWrapper instanceof FontWrapper)) for (const { reference, instance, definition } of this.numberingReferences) context.file.Numbering.createConcreteNumberingInstance(reference, instance, definition);
|
|
20219
20321
|
return super.prepForXml(context);
|
|
20220
20322
|
}
|
|
20221
20323
|
};
|
|
@@ -20293,8 +20395,9 @@ MAX: 9026 };
|
|
|
20293
20395
|
prepForXml(context) {
|
|
20294
20396
|
for (const element of this.root) if (element instanceof ExternalHyperlink) {
|
|
20295
20397
|
const index = this.root.indexOf(element);
|
|
20296
|
-
const
|
|
20297
|
-
|
|
20398
|
+
const { target, anchor } = externalHyperlinkTarget(element.options.link);
|
|
20399
|
+
const concreteHyperlink = new ConcreteHyperlink(element.options.children, uniqueId(), anchor, element.options.link);
|
|
20400
|
+
context.viewWrapper.Relationships.addRelationship(concreteHyperlink.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", target, TargetModeType.EXTERNAL);
|
|
20298
20401
|
this.root[index] = concreteHyperlink;
|
|
20299
20402
|
}
|
|
20300
20403
|
return super.prepForXml(context);
|
|
@@ -26548,6 +26651,35 @@ MAX: 9026 };
|
|
|
26548
26651
|
}
|
|
26549
26652
|
};
|
|
26550
26653
|
//#endregion
|
|
26654
|
+
//#region src/file/footnotes/footnote/note-paragraph.ts
|
|
26655
|
+
/**
|
|
26656
|
+
* The first paragraph of a footnote or endnote, written with the run that shows the note's number before its content.
|
|
26657
|
+
*
|
|
26658
|
+
* The run is added to what the paragraph is written as, rather than to the paragraph, so a paragraph in more than one
|
|
26659
|
+
* note, such as the notes of two documents, or two notes with the same content, has one number in each.
|
|
26660
|
+
*
|
|
26661
|
+
* @internal
|
|
26662
|
+
*/
|
|
26663
|
+
var FirstNoteParagraph = class extends XmlComponent {
|
|
26664
|
+
constructor(paragraph, mark) {
|
|
26665
|
+
super("w:p");
|
|
26666
|
+
_defineProperty(this, "paragraph", void 0);
|
|
26667
|
+
_defineProperty(this, "mark", void 0);
|
|
26668
|
+
this.paragraph = paragraph;
|
|
26669
|
+
this.mark = mark;
|
|
26670
|
+
}
|
|
26671
|
+
prepForXml(context) {
|
|
26672
|
+
const content = this.paragraph.prepForXml(context)["w:p"];
|
|
26673
|
+
const children = Array.isArray(content) ? content : [];
|
|
26674
|
+
const index = children.length > 0 && "w:pPr" in children[0] ? 1 : 0;
|
|
26675
|
+
return { "w:p": [
|
|
26676
|
+
...children.slice(0, index),
|
|
26677
|
+
this.mark.prepForXml(context),
|
|
26678
|
+
...children.slice(index)
|
|
26679
|
+
] };
|
|
26680
|
+
}
|
|
26681
|
+
};
|
|
26682
|
+
//#endregion
|
|
26551
26683
|
//#region src/file/endnotes/endnote/endnote-attributes.ts
|
|
26552
26684
|
var EndnoteAttributes = class extends XmlAttributeComponent {
|
|
26553
26685
|
constructor(..._args) {
|
|
@@ -26579,11 +26711,7 @@ MAX: 9026 };
|
|
|
26579
26711
|
type: options.type,
|
|
26580
26712
|
id: options.id
|
|
26581
26713
|
}));
|
|
26582
|
-
for (
|
|
26583
|
-
const child = options.children[i];
|
|
26584
|
-
if (i === 0) child.addRunToFront(new EndnoteRefRun());
|
|
26585
|
-
this.root.push(child);
|
|
26586
|
-
}
|
|
26714
|
+
for (const [index, child] of options.children.entries()) this.root.push(index === 0 ? new FirstNoteParagraph(child, new EndnoteRefRun()) : child);
|
|
26587
26715
|
}
|
|
26588
26716
|
};
|
|
26589
26717
|
//#endregion
|
|
@@ -26702,6 +26830,8 @@ MAX: 9026 };
|
|
|
26702
26830
|
var Endnotes = class extends XmlComponent {
|
|
26703
26831
|
constructor() {
|
|
26704
26832
|
super("w:endnotes");
|
|
26833
|
+
_defineProperty(this, "ownNotes", /* @__PURE__ */ new Map());
|
|
26834
|
+
_defineProperty(this, "highestId", 0);
|
|
26705
26835
|
this.root.push(new EndnotesAttributes({
|
|
26706
26836
|
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
|
|
26707
26837
|
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
|
@@ -26754,6 +26884,27 @@ MAX: 9026 };
|
|
|
26754
26884
|
children: paragraph
|
|
26755
26885
|
});
|
|
26756
26886
|
this.root.push(endnote);
|
|
26887
|
+
if (Number.isFinite(id)) this.highestId = Math.max(this.highestId, Math.floor(id));
|
|
26888
|
+
}
|
|
26889
|
+
/**
|
|
26890
|
+
* The id of the endnote that a reference run brings with it, which is added to the endnotes the first time the run
|
|
26891
|
+
* is written, with an id no other endnote has. Word has endnotes only in a document's body, so a run written
|
|
26892
|
+
* anywhere else, such as in a header, has none, and its endnote isn't added.
|
|
26893
|
+
*
|
|
26894
|
+
* @internal
|
|
26895
|
+
* @param reference - The run, which has the same endnote each time it is written
|
|
26896
|
+
* @param endnote - The endnote's content
|
|
26897
|
+
* @param context - The context the run is written in
|
|
26898
|
+
* @returns The endnote's id, or undefined outside the document's body
|
|
26899
|
+
*/
|
|
26900
|
+
idOf(reference, endnote, context) {
|
|
26901
|
+
if (context.viewWrapper !== context.file.Document) return;
|
|
26902
|
+
const existing = this.ownNotes.get(reference);
|
|
26903
|
+
if (existing !== void 0) return existing;
|
|
26904
|
+
const id = this.highestId + 1;
|
|
26905
|
+
this.createEndnote(id, endnote.children);
|
|
26906
|
+
this.ownNotes.set(reference, id);
|
|
26907
|
+
return id;
|
|
26757
26908
|
}
|
|
26758
26909
|
/**
|
|
26759
26910
|
* Formats the endnotes, with the page numbers worked out for their document written into their fields, when the
|
|
@@ -27098,11 +27249,7 @@ MAX: 9026 };
|
|
|
27098
27249
|
type: options.type,
|
|
27099
27250
|
id: options.id
|
|
27100
27251
|
}));
|
|
27101
|
-
for (
|
|
27102
|
-
const child = options.children[i];
|
|
27103
|
-
if (i === 0) child.addRunToFront(new FootnoteRefRun());
|
|
27104
|
-
this.root.push(child);
|
|
27105
|
-
}
|
|
27252
|
+
for (const [index, child] of options.children.entries()) this.root.push(index === 0 ? new FirstNoteParagraph(child, new FootnoteRefRun()) : child);
|
|
27106
27253
|
}
|
|
27107
27254
|
};
|
|
27108
27255
|
//#endregion
|
|
@@ -27205,6 +27352,8 @@ MAX: 9026 };
|
|
|
27205
27352
|
var FootNotes = class extends XmlComponent {
|
|
27206
27353
|
constructor() {
|
|
27207
27354
|
super("w:footnotes");
|
|
27355
|
+
_defineProperty(this, "ownNotes", /* @__PURE__ */ new Map());
|
|
27356
|
+
_defineProperty(this, "highestId", 0);
|
|
27208
27357
|
this.root.push(new FootnotesAttributes({
|
|
27209
27358
|
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
|
|
27210
27359
|
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
|
@@ -27263,6 +27412,27 @@ MAX: 9026 };
|
|
|
27263
27412
|
children: paragraph
|
|
27264
27413
|
});
|
|
27265
27414
|
this.root.push(footnote);
|
|
27415
|
+
if (Number.isFinite(id)) this.highestId = Math.max(this.highestId, Math.floor(id));
|
|
27416
|
+
}
|
|
27417
|
+
/**
|
|
27418
|
+
* The id of the footnote that a reference run brings with it, which is added to the footnotes the first time the
|
|
27419
|
+
* run is written, with an id no other footnote has. Word has footnotes only in a document's body, so a run written
|
|
27420
|
+
* anywhere else, such as in a header, has none, and its footnote isn't added.
|
|
27421
|
+
*
|
|
27422
|
+
* @internal
|
|
27423
|
+
* @param reference - The run, which has the same footnote each time it is written
|
|
27424
|
+
* @param footnote - The footnote's content
|
|
27425
|
+
* @param context - The context the run is written in
|
|
27426
|
+
* @returns The footnote's id, or undefined outside the document's body
|
|
27427
|
+
*/
|
|
27428
|
+
idOf(reference, footnote, context) {
|
|
27429
|
+
if (context.viewWrapper !== context.file.Document) return;
|
|
27430
|
+
const existing = this.ownNotes.get(reference);
|
|
27431
|
+
if (existing !== void 0) return existing;
|
|
27432
|
+
const id = this.highestId + 1;
|
|
27433
|
+
this.createFootNote(id, footnote.children);
|
|
27434
|
+
this.ownNotes.set(reference, id);
|
|
27435
|
+
return id;
|
|
27266
27436
|
}
|
|
27267
27437
|
/**
|
|
27268
27438
|
* Formats the footnotes, with the page numbers worked out for their document written into their fields, when the
|
|
@@ -28471,8 +28641,15 @@ MAX: 9026 };
|
|
|
28471
28641
|
*
|
|
28472
28642
|
* @param reference - The reference name of the abstract numbering definition
|
|
28473
28643
|
* @param instance - The instance number for this concrete numbering
|
|
28644
|
+
* @param definition - The list's definition, for a list a paragraph gives its own definition of. It is added with
|
|
28645
|
+
* its reference, unless the numbering already has a list with that reference, such as one of the document's
|
|
28646
|
+
* `numbering` option, which is kept
|
|
28474
28647
|
*/
|
|
28475
|
-
createConcreteNumberingInstance(reference, instance) {
|
|
28648
|
+
createConcreteNumberingInstance(reference, instance, definition) {
|
|
28649
|
+
if (definition && !this.abstractNumberingMap.has(definition.reference)) {
|
|
28650
|
+
this.abstractNumberingMap.set(definition.reference, new AbstractNumbering(this.abstractNumUniqueNumericId(), definition.levels));
|
|
28651
|
+
this.referenceConfigMap.set(definition.reference, definition.levels);
|
|
28652
|
+
}
|
|
28476
28653
|
const abstractNumbering = this.abstractNumberingMap.get(reference);
|
|
28477
28654
|
if (!abstractNumbering) return;
|
|
28478
28655
|
const fullReference = `${reference}-${instance}`;
|
|
@@ -29572,7 +29749,7 @@ MAX: 9026 };
|
|
|
29572
29749
|
//#endregion
|
|
29573
29750
|
//#region src/file/styles/styles.ts
|
|
29574
29751
|
/** The name of a formatted element, such as `w:style`, or `_attr` for its parent's attributes */
|
|
29575
|
-
var nameOf = (child) => typeof child === "object" ? Object.keys(child)[0] : void 0;
|
|
29752
|
+
var nameOf$1 = (child) => typeof child === "object" ? Object.keys(child)[0] : void 0;
|
|
29576
29753
|
/** The attributes of a formatted `w:style` */
|
|
29577
29754
|
var attributesOf = (style) => {
|
|
29578
29755
|
var _flat$find;
|
|
@@ -29652,16 +29829,16 @@ MAX: 9026 };
|
|
|
29652
29829
|
const xml = super.prepForXml(context);
|
|
29653
29830
|
const children = xml["w:styles"];
|
|
29654
29831
|
if (!Array.isArray(children)) return xml;
|
|
29655
|
-
const named = (name) => children.filter((child) => nameOf(child) === name);
|
|
29656
|
-
const ids = children.map((child) => nameOf(child) === "w:style" ? styleIdOf(child) : void 0);
|
|
29832
|
+
const named = (name) => children.filter((child) => nameOf$1(child) === name);
|
|
29833
|
+
const ids = children.map((child) => nameOf$1(child) === "w:style" ? styleIdOf(child) : void 0);
|
|
29657
29834
|
const kept = children.filter((child, index) => ![
|
|
29658
29835
|
"_attr",
|
|
29659
29836
|
"w:docDefaults",
|
|
29660
29837
|
"w:latentStyles"
|
|
29661
|
-
].includes(nameOf(child)) && (ids[index] === void 0 || ids.lastIndexOf(ids[index]) === index));
|
|
29662
|
-
const styles = kept.some((child) => nameOf(child) === "w:style" && isDefaultParagraphStyle(child)) ? kept : kept.map((child) => {
|
|
29838
|
+
].includes(nameOf$1(child)) && (ids[index] === void 0 || ids.lastIndexOf(ids[index]) === index));
|
|
29839
|
+
const styles = kept.some((child) => nameOf$1(child) === "w:style" && isDefaultParagraphStyle(child)) ? kept : kept.map((child) => {
|
|
29663
29840
|
var _attributesOf$wType, _attributesOf2;
|
|
29664
|
-
return nameOf(child) === "w:style" && styleIdOf(child) === "Normal" && ((_attributesOf$wType = (_attributesOf2 = attributesOf(child)) === null || _attributesOf2 === void 0 ? void 0 : _attributesOf2["w:type"]) !== null && _attributesOf$wType !== void 0 ? _attributesOf$wType : "paragraph") === "paragraph" ? markedAsDefault(child) : child;
|
|
29841
|
+
return nameOf$1(child) === "w:style" && styleIdOf(child) === "Normal" && ((_attributesOf$wType = (_attributesOf2 = attributesOf(child)) === null || _attributesOf2 === void 0 ? void 0 : _attributesOf2["w:type"]) !== null && _attributesOf$wType !== void 0 ? _attributesOf$wType : "paragraph") === "paragraph" ? markedAsDefault(child) : child;
|
|
29665
29842
|
});
|
|
29666
29843
|
return { "w:styles": [
|
|
29667
29844
|
...named("_attr"),
|
|
@@ -31054,16 +31231,6 @@ MAX: 9026 };
|
|
|
31054
31231
|
//#endregion
|
|
31055
31232
|
//#region src/file/footnotes/footnote/run/reference-run.ts
|
|
31056
31233
|
/**
|
|
31057
|
-
* Footnote reference run module for WordprocessingML documents.
|
|
31058
|
-
*
|
|
31059
|
-
* This module provides the footnote reference marker that appears in the
|
|
31060
|
-
* main document text to indicate a footnote.
|
|
31061
|
-
*
|
|
31062
|
-
* Reference: http://officeopenxml.com/WPfootnotes.php
|
|
31063
|
-
*
|
|
31064
|
-
* @module
|
|
31065
|
-
*/
|
|
31066
|
-
/**
|
|
31067
31234
|
* Represents the attributes for a footnote reference element.
|
|
31068
31235
|
*
|
|
31069
31236
|
* @internal
|
|
@@ -31103,6 +31270,10 @@ MAX: 9026 };
|
|
|
31103
31270
|
* (typically a superscript number) that appears in the main document text.
|
|
31104
31271
|
* Clicking this marker navigates to the corresponding footnote content.
|
|
31105
31272
|
*
|
|
31273
|
+
* It refers to one of the document's `footnotes` by its id, or is given its footnote's content, for a footnote of its
|
|
31274
|
+
* own, which is added to the document's footnotes when the run is written. Content made before the document it goes
|
|
31275
|
+
* in, such as by a function that makes paragraphs, then brings its footnotes with it.
|
|
31276
|
+
*
|
|
31106
31277
|
* Reference: http://officeopenxml.com/WPfootnotes.php
|
|
31107
31278
|
*
|
|
31108
31279
|
* @publicApi
|
|
@@ -31116,17 +31287,44 @@ MAX: 9026 };
|
|
|
31116
31287
|
* new FootnoteReferenceRun(1),
|
|
31117
31288
|
* ],
|
|
31118
31289
|
* });
|
|
31290
|
+
*
|
|
31291
|
+
* // Or with the footnote's content
|
|
31292
|
+
* new Paragraph({
|
|
31293
|
+
* children: [
|
|
31294
|
+
* new TextRun("This text has a footnote of its own"),
|
|
31295
|
+
* new FootnoteReferenceRun({ children: [new Paragraph("The footnote.")] }),
|
|
31296
|
+
* ],
|
|
31297
|
+
* });
|
|
31119
31298
|
* ```
|
|
31120
31299
|
*/
|
|
31121
31300
|
var FootnoteReferenceRun = class extends Run {
|
|
31122
31301
|
/**
|
|
31123
31302
|
* Creates a new footnote reference run.
|
|
31124
31303
|
*
|
|
31125
|
-
* @param
|
|
31304
|
+
* @param footnote - The id of one of the document's `footnotes`, or the footnote's content, for a footnote of the
|
|
31305
|
+
* run's own. Word has footnotes only in a document's body, so a run with its footnote's content is left out of
|
|
31306
|
+
* headers, footers, comments and notes
|
|
31126
31307
|
*/
|
|
31127
|
-
constructor(
|
|
31308
|
+
constructor(footnote) {
|
|
31128
31309
|
super({ style: "FootnoteReference" });
|
|
31310
|
+
_defineProperty(this, "footnote", void 0);
|
|
31311
|
+
if (typeof footnote === "number") this.root.push(new FootnoteReference(footnote));
|
|
31312
|
+
else this.footnote = footnote;
|
|
31313
|
+
}
|
|
31314
|
+
/**
|
|
31315
|
+
* Formats the run, with its own footnote added to the document's footnotes, and referred to by the id it has there.
|
|
31316
|
+
*/
|
|
31317
|
+
prepForXml(context) {
|
|
31318
|
+
var _context$file;
|
|
31319
|
+
if (this.footnote === void 0) return super.prepForXml(context);
|
|
31320
|
+
const id = (_context$file = context.file) === null || _context$file === void 0 ? void 0 : _context$file.FootNotes.View.idOf(this, this.footnote, context);
|
|
31321
|
+
if (id === void 0) return;
|
|
31129
31322
|
this.root.push(new FootnoteReference(id));
|
|
31323
|
+
try {
|
|
31324
|
+
return super.prepForXml(context);
|
|
31325
|
+
} finally {
|
|
31326
|
+
this.root.pop();
|
|
31327
|
+
}
|
|
31130
31328
|
}
|
|
31131
31329
|
};
|
|
31132
31330
|
//#endregion
|
|
@@ -31143,10 +31341,47 @@ MAX: 9026 };
|
|
|
31143
31341
|
this.root.push(new EndnoteReferenceRunAttributes({ id }));
|
|
31144
31342
|
}
|
|
31145
31343
|
};
|
|
31344
|
+
/**
|
|
31345
|
+
* A run with an endnote's reference mark, its number, in the document's text.
|
|
31346
|
+
*
|
|
31347
|
+
* It refers to one of the document's `endnotes` by its id, or is given its endnote's content, for an endnote of its
|
|
31348
|
+
* own, which is added to the document's endnotes when the run is written.
|
|
31349
|
+
*
|
|
31350
|
+
* @publicApi
|
|
31351
|
+
*
|
|
31352
|
+
* @example
|
|
31353
|
+
* ```typescript
|
|
31354
|
+
* new Paragraph({
|
|
31355
|
+
* children: [new TextRun("A claim"), new EndnoteReferenceRun({ children: [new Paragraph("Its source.")] })],
|
|
31356
|
+
* });
|
|
31357
|
+
* ```
|
|
31358
|
+
*/
|
|
31146
31359
|
var EndnoteReferenceRun = class extends Run {
|
|
31147
|
-
|
|
31360
|
+
/**
|
|
31361
|
+
* @param endnote - The id of one of the document's `endnotes`, or the endnote's content, for an endnote of the run's
|
|
31362
|
+
* own. Word has endnotes only in a document's body, so a run with its endnote's content is left out of headers,
|
|
31363
|
+
* footers, comments and notes
|
|
31364
|
+
*/
|
|
31365
|
+
constructor(endnote) {
|
|
31148
31366
|
super({ style: "EndnoteReference" });
|
|
31367
|
+
_defineProperty(this, "endnote", void 0);
|
|
31368
|
+
if (typeof endnote === "number") this.root.push(new EndnoteIdReference(endnote));
|
|
31369
|
+
else this.endnote = endnote;
|
|
31370
|
+
}
|
|
31371
|
+
/**
|
|
31372
|
+
* Formats the run, with its own endnote added to the document's endnotes, and referred to by the id it has there.
|
|
31373
|
+
*/
|
|
31374
|
+
prepForXml(context) {
|
|
31375
|
+
var _context$file;
|
|
31376
|
+
if (this.endnote === void 0) return super.prepForXml(context);
|
|
31377
|
+
const id = (_context$file = context.file) === null || _context$file === void 0 ? void 0 : _context$file.Endnotes.View.idOf(this, this.endnote, context);
|
|
31378
|
+
if (id === void 0) return;
|
|
31149
31379
|
this.root.push(new EndnoteIdReference(id));
|
|
31380
|
+
try {
|
|
31381
|
+
return super.prepForXml(context);
|
|
31382
|
+
} finally {
|
|
31383
|
+
this.root.pop();
|
|
31384
|
+
}
|
|
31150
31385
|
}
|
|
31151
31386
|
};
|
|
31152
31387
|
//#endregion
|
|
@@ -35348,11 +35583,11 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
35348
35583
|
*
|
|
35349
35584
|
* @module
|
|
35350
35585
|
*/
|
|
35351
|
-
var formatter$
|
|
35586
|
+
var formatter$4 = new Formatter();
|
|
35352
35587
|
/**
|
|
35353
35588
|
* Formats a part's XML, with the relationships that anything in it that refers to other parts adds to.
|
|
35354
35589
|
*/
|
|
35355
|
-
var xmlifyPart = (file, content, prettify, relationships, standalone = true) => (0, import_xml.default)(formatter$
|
|
35590
|
+
var xmlifyPart = (file, content, prettify, relationships, standalone = true) => (0, import_xml.default)(formatter$4.format(content, {
|
|
35356
35591
|
viewWrapper: {
|
|
35357
35592
|
View: content,
|
|
35358
35593
|
Relationships: relationships
|
|
@@ -35469,7 +35704,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
35469
35704
|
zip.file(`word/media/${data.fileName}`, data.data);
|
|
35470
35705
|
zip.file(`word/media/${data.fallback.fileName}`, data.fallback.data);
|
|
35471
35706
|
}
|
|
35472
|
-
for (const [i, { data: buffer, fontKey }] of file.FontTable.
|
|
35707
|
+
for (const [i, { data: buffer, fontKey }] of file.FontTable.files.entries()) zip.file(`word/fonts/font${i + 1}.odttf`, obfuscate(buffer, fontKey));
|
|
35473
35708
|
return zip;
|
|
35474
35709
|
}
|
|
35475
35710
|
xmlifyFile(file, prettify) {
|
|
@@ -36122,7 +36357,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36122
36357
|
*
|
|
36123
36358
|
* @module
|
|
36124
36359
|
*/
|
|
36125
|
-
var formatter$
|
|
36360
|
+
var formatter$3 = new Formatter();
|
|
36126
36361
|
/**
|
|
36127
36362
|
* Converts XML string to JSON element structure.
|
|
36128
36363
|
*
|
|
@@ -36162,7 +36397,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36162
36397
|
*/
|
|
36163
36398
|
var createTextElementContents = (text) => {
|
|
36164
36399
|
var _textJson$elements$0$;
|
|
36165
|
-
return (_textJson$elements$0$ = toJson((0, import_xml.default)(formatter$
|
|
36400
|
+
return (_textJson$elements$0$ = toJson((0, import_xml.default)(formatter$3.format(new Text({ text })))).elements[0].elements) !== null && _textJson$elements$0$ !== void 0 ? _textJson$elements$0$ : [];
|
|
36166
36401
|
};
|
|
36167
36402
|
/**
|
|
36168
36403
|
* Adds xml:space="preserve" attribute to an element.
|
|
@@ -36278,6 +36513,81 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36278
36513
|
});
|
|
36279
36514
|
};
|
|
36280
36515
|
//#endregion
|
|
36516
|
+
//#region src/patcher/drawing-ids.ts
|
|
36517
|
+
var DRAWINGS = /* @__PURE__ */ new Set(["wp:inline", "wp:anchor"]);
|
|
36518
|
+
var ID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
36519
|
+
"wp:docPr",
|
|
36520
|
+
"wps:cNvPr",
|
|
36521
|
+
"wpg:cNvPr"
|
|
36522
|
+
]);
|
|
36523
|
+
var REFERENCE_ELEMENTS = /* @__PURE__ */ new Set(["a:stCxn", "a:endCxn"]);
|
|
36524
|
+
var idOf$1 = (element, names) => {
|
|
36525
|
+
var _element$name, _element$attributes;
|
|
36526
|
+
if (!names.has((_element$name = element.name) !== null && _element$name !== void 0 ? _element$name : "")) return;
|
|
36527
|
+
const id = Number((_element$attributes = element.attributes) === null || _element$attributes === void 0 ? void 0 : _element$attributes.id);
|
|
36528
|
+
return Number.isInteger(id) ? id : void 0;
|
|
36529
|
+
};
|
|
36530
|
+
/**
|
|
36531
|
+
* Finds the id of every drawing in an element, at any depth, and of the shapes in them, such as in a group.
|
|
36532
|
+
*
|
|
36533
|
+
* @param element - The element to search, such as a part's root
|
|
36534
|
+
* @returns The ids, once for each element that has one
|
|
36535
|
+
*/
|
|
36536
|
+
var findDrawingIds = (element) => {
|
|
36537
|
+
var _element$elements;
|
|
36538
|
+
const id = idOf$1(element, ID_ELEMENTS);
|
|
36539
|
+
return [...id === void 0 ? [] : [id], ...((_element$elements = element.elements) !== null && _element$elements !== void 0 ? _element$elements : []).flatMap(findDrawingIds)];
|
|
36540
|
+
};
|
|
36541
|
+
var ownIdsOf = (drawing) => {
|
|
36542
|
+
const idsIn = (element) => {
|
|
36543
|
+
var _element$elements2;
|
|
36544
|
+
const id = idOf$1(element, ID_ELEMENTS);
|
|
36545
|
+
return [...id === void 0 ? [] : [id], ...((_element$elements2 = element.elements) !== null && _element$elements2 !== void 0 ? _element$elements2 : []).flatMap((child) => {
|
|
36546
|
+
var _child$name;
|
|
36547
|
+
return DRAWINGS.has((_child$name = child.name) !== null && _child$name !== void 0 ? _child$name : "") ? [] : idsIn(child);
|
|
36548
|
+
})];
|
|
36549
|
+
};
|
|
36550
|
+
return idsIn(drawing);
|
|
36551
|
+
};
|
|
36552
|
+
/**
|
|
36553
|
+
* Creates a function that renumbers the drawings in content being inserted, so none has an id another drawing in the
|
|
36554
|
+
* document has. Word finds a document whose drawings share an id unreadable, even when they are in different parts,
|
|
36555
|
+
* such as a header and the body. A drawing's id is chosen when it is created, without knowing which ids the template
|
|
36556
|
+
* has, and content inserted more than once would have the same ids each time.
|
|
36557
|
+
*
|
|
36558
|
+
* A drawing keeps its ids if nothing in the document has them yet, and otherwise gets the next unused ones. The
|
|
36559
|
+
* connectors in a drawing then still join the shapes they did.
|
|
36560
|
+
*
|
|
36561
|
+
* @param idsInDocument - The ids of the drawings already in the document, and of the shapes in them
|
|
36562
|
+
* @returns A function that returns the elements with their drawings renumbered
|
|
36563
|
+
*/
|
|
36564
|
+
var renumberDrawingsAvoiding = (idsInDocument) => {
|
|
36565
|
+
const usedIds = new Set(idsInDocument);
|
|
36566
|
+
let highestId = idsInDocument.reduce((highest, id) => Math.max(highest, id), 0);
|
|
36567
|
+
const newIdFor = (id) => {
|
|
36568
|
+
const newId = usedIds.has(id) ? highestId + 1 : id;
|
|
36569
|
+
highestId = Math.max(highestId, newId);
|
|
36570
|
+
usedIds.add(newId);
|
|
36571
|
+
return newId;
|
|
36572
|
+
};
|
|
36573
|
+
const renumberDrawing = (drawing) => {
|
|
36574
|
+
const newIds = new Map([...new Set(ownIdsOf(drawing))].map((id) => [id, newIdFor(id)]));
|
|
36575
|
+
const renumberIn = (element) => {
|
|
36576
|
+
var _element$name2, _idOf;
|
|
36577
|
+
if (element !== drawing && DRAWINGS.has((_element$name2 = element.name) !== null && _element$name2 !== void 0 ? _element$name2 : "")) return renumberDrawing(element);
|
|
36578
|
+
const id = (_idOf = idOf$1(element, ID_ELEMENTS)) !== null && _idOf !== void 0 ? _idOf : idOf$1(element, REFERENCE_ELEMENTS);
|
|
36579
|
+
const newId = id === void 0 ? void 0 : newIds.get(id);
|
|
36580
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({}, element), newId === void 0 ? {} : { attributes: _objectSpread2(_objectSpread2({}, element.attributes), {}, { id: String(newId) }) }), element.elements === void 0 ? {} : { elements: element.elements.map(renumberIn) });
|
|
36581
|
+
};
|
|
36582
|
+
return renumberIn(drawing);
|
|
36583
|
+
};
|
|
36584
|
+
const renumber = (element) => {
|
|
36585
|
+
var _element$name3;
|
|
36586
|
+
return DRAWINGS.has((_element$name3 = element.name) !== null && _element$name3 !== void 0 ? _element$name3 : "") ? renumberDrawing(element) : _objectSpread2(_objectSpread2({}, element), element.elements === void 0 ? {} : { elements: element.elements.map(renumber) });
|
|
36587
|
+
};
|
|
36588
|
+
return (elements) => elements.map(renumber);
|
|
36589
|
+
};
|
|
36590
|
+
//#endregion
|
|
36281
36591
|
//#region src/patcher/patch-type.ts
|
|
36282
36592
|
/**
|
|
36283
36593
|
* The types of patch `patchDocument` applies.
|
|
@@ -36621,8 +36931,8 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36621
36931
|
*
|
|
36622
36932
|
* @module
|
|
36623
36933
|
*/
|
|
36624
|
-
var formatter$
|
|
36625
|
-
var DOCUMENT_PATH = "word/document.xml";
|
|
36934
|
+
var formatter$2 = new Formatter();
|
|
36935
|
+
var DOCUMENT_PATH$1 = "word/document.xml";
|
|
36626
36936
|
var FOOTNOTES = {
|
|
36627
36937
|
path: "word/footnotes.xml",
|
|
36628
36938
|
rootName: "w:footnotes",
|
|
@@ -36657,7 +36967,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36657
36967
|
]
|
|
36658
36968
|
}
|
|
36659
36969
|
};
|
|
36660
|
-
var formatElement = (component, context) => toJson((0, import_xml.default)(formatter$
|
|
36970
|
+
var formatElement$1 = (component, context) => toJson((0, import_xml.default)(formatter$2.format(component, context))).elements[0];
|
|
36661
36971
|
var findIds = (element, names) => {
|
|
36662
36972
|
var _element$name, _element$attributes, _element$elements;
|
|
36663
36973
|
const id = names.includes((_element$name = element.name) !== null && _element$name !== void 0 ? _element$name : "") ? Number((_element$attributes = element.attributes) === null || _element$attributes === void 0 ? void 0 : _element$attributes["w:id"]) : NaN;
|
|
@@ -36673,8 +36983,10 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36673
36983
|
...elements.slice(index)
|
|
36674
36984
|
] });
|
|
36675
36985
|
};
|
|
36676
|
-
var patchNotesOfKind = (kind, notes, parts, { createContext, addContentTypeOverride, renumberBookmarks }) => {
|
|
36986
|
+
var patchNotesOfKind = (kind, notes, parts, { createContext, addContentTypeOverride, renumberBookmarks, renumberDrawings, renumberLists, useStyles }) => {
|
|
36677
36987
|
const givenNotes = new Map(Object.entries(notes).map(([id, note]) => [Number(id), note]));
|
|
36988
|
+
const carriedIds = /* @__PURE__ */ new Map();
|
|
36989
|
+
let highestGivenId = [...givenNotes.keys()].filter(Number.isFinite).reduce((highest, id) => Math.max(highest, Math.floor(id)), 0);
|
|
36678
36990
|
const noteOfId = /* @__PURE__ */ new Map();
|
|
36679
36991
|
let highestId;
|
|
36680
36992
|
const renumber = (element) => {
|
|
@@ -36687,11 +36999,11 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36687
36999
|
};
|
|
36688
37000
|
const findOrAddPart = () => {
|
|
36689
37001
|
var _parts$get;
|
|
36690
|
-
const relationship = getFirstLevelElements((_parts$get = parts.get(relationshipsPathOf(DOCUMENT_PATH))) !== null && _parts$get !== void 0 ? _parts$get : {}, "Relationships").find((element) => {
|
|
37002
|
+
const relationship = getFirstLevelElements((_parts$get = parts.get(relationshipsPathOf(DOCUMENT_PATH$1))) !== null && _parts$get !== void 0 ? _parts$get : {}, "Relationships").find((element) => {
|
|
36691
37003
|
var _element$attributes3;
|
|
36692
37004
|
return ((_element$attributes3 = element.attributes) === null || _element$attributes3 === void 0 ? void 0 : _element$attributes3.Type) === kind.relationshipType;
|
|
36693
37005
|
});
|
|
36694
|
-
const path = relationship ? resolveTarget(DOCUMENT_PATH, String(relationship.attributes.Target)) : kind.path;
|
|
37006
|
+
const path = relationship ? resolveTarget(DOCUMENT_PATH$1, String(relationship.attributes.Target)) : kind.path;
|
|
36695
37007
|
if (!parts.has(path)) {
|
|
36696
37008
|
parts.set(path, {
|
|
36697
37009
|
declaration: { attributes: {
|
|
@@ -36699,11 +37011,11 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36699
37011
|
encoding: "UTF-8",
|
|
36700
37012
|
standalone: "yes"
|
|
36701
37013
|
} },
|
|
36702
|
-
elements: [formatElement(kind.create.part(), createContext(path))]
|
|
37014
|
+
elements: [formatElement$1(kind.create.part(), createContext(path))]
|
|
36703
37015
|
});
|
|
36704
37016
|
addContentTypeOverride(kind.contentType, `/${path}`);
|
|
36705
37017
|
}
|
|
36706
|
-
if (!relationship) createContext(DOCUMENT_PATH).viewWrapper.Relationships.addRelationship(uniqueId(), kind.relationshipType, relativeTarget(DOCUMENT_PATH, path));
|
|
37018
|
+
if (!relationship) createContext(DOCUMENT_PATH$1).viewWrapper.Relationships.addRelationship(uniqueId(), kind.relationshipType, relativeTarget(DOCUMENT_PATH$1, path));
|
|
36707
37019
|
return path;
|
|
36708
37020
|
};
|
|
36709
37021
|
const write = () => {
|
|
@@ -36711,14 +37023,14 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36711
37023
|
const path = findOrAddPart();
|
|
36712
37024
|
const context = createContext(path);
|
|
36713
37025
|
const contentOfNote = new Map([...new Set(noteOfId.values())].map((note) => {
|
|
36714
|
-
const mark = formatElement(kind.create.mark(), context);
|
|
36715
|
-
return [note, renumberBookmarks(note.children.map((paragraph) => formatElement(paragraph, context)).map((paragraph, index) => index === 0 ? withMark(paragraph, mark) : paragraph))];
|
|
37026
|
+
const mark = formatElement$1(kind.create.mark(), context);
|
|
37027
|
+
return [note, useStyles(renumberLists(renumberBookmarks(note.children.map((paragraph) => formatElement$1(paragraph, context)).map((paragraph, index) => index === 0 ? withMark(paragraph, mark) : paragraph))))];
|
|
36716
37028
|
}));
|
|
36717
37029
|
getFirstLevelElements(parts.get(path), kind.rootName).push(...[...noteOfId].map(([id, note]) => ({
|
|
36718
37030
|
type: "element",
|
|
36719
37031
|
name: kind.noteName,
|
|
36720
37032
|
attributes: { "w:id": String(id) },
|
|
36721
|
-
elements: [...contentOfNote.get(note)]
|
|
37033
|
+
elements: [...renumberDrawings(contentOfNote.get(note))]
|
|
36722
37034
|
})));
|
|
36723
37035
|
const stylesPart = parts.get("word/styles.xml");
|
|
36724
37036
|
if (stylesPart) {
|
|
@@ -36727,37 +37039,165 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
36727
37039
|
var _style$attributes;
|
|
36728
37040
|
return (_style$attributes = style.attributes) === null || _style$attributes === void 0 ? void 0 : _style$attributes["w:styleId"];
|
|
36729
37041
|
}));
|
|
36730
|
-
styles.push(...kind.create.styles().map((style) => formatElement(style, context)).filter((style) => {
|
|
37042
|
+
styles.push(...kind.create.styles().map((style) => formatElement$1(style, context)).filter((style) => {
|
|
36731
37043
|
var _style$attributes2;
|
|
36732
37044
|
return !styleIds.has((_style$attributes2 = style.attributes) === null || _style$attributes2 === void 0 ? void 0 : _style$attributes2["w:styleId"]);
|
|
36733
37045
|
}));
|
|
36734
37046
|
}
|
|
36735
37047
|
};
|
|
37048
|
+
const carry = (reference, note) => {
|
|
37049
|
+
const existing = carriedIds.get(reference);
|
|
37050
|
+
if (existing !== void 0) return existing;
|
|
37051
|
+
highestGivenId++;
|
|
37052
|
+
givenNotes.set(highestGivenId, note);
|
|
37053
|
+
carriedIds.set(reference, highestGivenId);
|
|
37054
|
+
return highestGivenId;
|
|
37055
|
+
};
|
|
36736
37056
|
return {
|
|
36737
37057
|
renumber: (elements) => elements.map(renumber),
|
|
36738
|
-
write
|
|
37058
|
+
write,
|
|
37059
|
+
carry
|
|
36739
37060
|
};
|
|
36740
37061
|
};
|
|
36741
37062
|
/**
|
|
36742
37063
|
* Creates the writer of the footnotes and endnotes that patches refer to.
|
|
36743
37064
|
*
|
|
36744
37065
|
* A patch refers to a note with a reference run, such as `new FootnoteReferenceRun(1)`, whose id is the note's in
|
|
36745
|
-
* `footnotes
|
|
37066
|
+
* `footnotes`, or with a run that brings its note with it, such as `new FootnoteReferenceRun({ children })`, which is
|
|
37067
|
+
* given an id with `carry` as it is written. Only references to these notes are renumbered, and only the notes that
|
|
37068
|
+
* are referred to are written.
|
|
36746
37069
|
*
|
|
36747
37070
|
* @param notes - The footnotes and endnotes, by the id the patches' reference runs are given
|
|
36748
37071
|
* @param parts - The document's XML parts, parsed, by their paths, which the notes are written to
|
|
36749
37072
|
* @param helpers - The patcher's helpers for what the notes refer to
|
|
36750
37073
|
*/
|
|
36751
37074
|
var patchNotes = ({ footnotes = {}, endnotes = {} }, parts, helpers) => {
|
|
36752
|
-
const patchers =
|
|
37075
|
+
const patchers = {
|
|
37076
|
+
footnotes: patchNotesOfKind(FOOTNOTES, footnotes, parts, helpers),
|
|
37077
|
+
endnotes: patchNotesOfKind(ENDNOTES, endnotes, parts, helpers)
|
|
37078
|
+
};
|
|
36753
37079
|
return {
|
|
36754
|
-
|
|
37080
|
+
carry: (kind, reference, note) => patchers[kind].carry(reference, note),
|
|
37081
|
+
renumber: (elements) => Object.values(patchers).reduce((renumbered, patcher) => patcher.renumber(renumbered), elements),
|
|
36755
37082
|
write: () => {
|
|
36756
|
-
for (const patcher of patchers) patcher.write();
|
|
37083
|
+
for (const patcher of Object.values(patchers)) patcher.write();
|
|
36757
37084
|
}
|
|
36758
37085
|
};
|
|
36759
37086
|
};
|
|
36760
37087
|
//#endregion
|
|
37088
|
+
//#region src/patcher/numbering.ts
|
|
37089
|
+
/**
|
|
37090
|
+
* Lists in content inserted into an existing document.
|
|
37091
|
+
*
|
|
37092
|
+
* @module
|
|
37093
|
+
*/
|
|
37094
|
+
var formatter$1 = new Formatter();
|
|
37095
|
+
var DOCUMENT_PATH = "word/document.xml";
|
|
37096
|
+
var NUMBERING_PATH = "word/numbering.xml";
|
|
37097
|
+
var NUMBERING_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";
|
|
37098
|
+
var NUMBERING_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";
|
|
37099
|
+
var BULLET_REFERENCE = "default-bullet-numbering";
|
|
37100
|
+
var BULLET_NUM_ID = "1";
|
|
37101
|
+
var formatElement = (component, context) => toJson((0, import_xml.default)(formatter$1.format(component, context))).elements[0];
|
|
37102
|
+
var highestOf = (ids) => ids.reduce((highest, id) => Math.max(highest, id), 0);
|
|
37103
|
+
/**
|
|
37104
|
+
* Creates the writer of the lists that patches use.
|
|
37105
|
+
*
|
|
37106
|
+
* A paragraph in a patch is put in a list as in a Document, with `numbering: { reference, level }` for one of the
|
|
37107
|
+
* numbering's references, or with `bullet`. It is written with a placeholder for its list's id, or for a bullet, with
|
|
37108
|
+
* the id a Document's bullet list has, which a template's lists may have too.
|
|
37109
|
+
*
|
|
37110
|
+
* @param numbering - The numbering the patches' paragraphs add their lists to as they are written
|
|
37111
|
+
* @param parts - The document's XML parts, parsed, by their paths, which the lists are written to
|
|
37112
|
+
* @param helpers - The patcher's helpers for the numbering part
|
|
37113
|
+
*/
|
|
37114
|
+
var patchNumbering = (numbering, parts, { createContext, addContentTypeOverride }) => {
|
|
37115
|
+
const newNumIds = /* @__PURE__ */ new Map();
|
|
37116
|
+
let highestNumId;
|
|
37117
|
+
const numberingRelationship = () => {
|
|
37118
|
+
var _parts$get;
|
|
37119
|
+
return getFirstLevelElements((_parts$get = parts.get(relationshipsPathOf(DOCUMENT_PATH))) !== null && _parts$get !== void 0 ? _parts$get : {}, "Relationships").find((element) => {
|
|
37120
|
+
var _element$attributes;
|
|
37121
|
+
return ((_element$attributes = element.attributes) === null || _element$attributes === void 0 ? void 0 : _element$attributes.Type) === NUMBERING_RELATIONSHIP;
|
|
37122
|
+
});
|
|
37123
|
+
};
|
|
37124
|
+
const numberingPath = (relationship = numberingRelationship()) => relationship ? resolveTarget(DOCUMENT_PATH, String(relationship.attributes.Target)) : NUMBERING_PATH;
|
|
37125
|
+
const idsInTemplate = (name, attribute) => {
|
|
37126
|
+
var _parts$get2;
|
|
37127
|
+
return getFirstLevelElements((_parts$get2 = parts.get(numberingPath())) !== null && _parts$get2 !== void 0 ? _parts$get2 : {}, "w:numbering").filter((element) => element.name === name).map((element) => Number(element.attributes[attribute]));
|
|
37128
|
+
};
|
|
37129
|
+
const listOf = (numId) => {
|
|
37130
|
+
if (numId === BULLET_NUM_ID) return numbering.ConcreteNumbering.find(({ reference }) => reference === BULLET_REFERENCE);
|
|
37131
|
+
if (!numId.startsWith("{")) return;
|
|
37132
|
+
const list = numbering.ConcreteNumbering.find(({ reference, instance }) => numId === `{${reference}-${instance}}`);
|
|
37133
|
+
if (!list) {
|
|
37134
|
+
const reference = numId.slice(1, -1).replace(/-\d+$/, "");
|
|
37135
|
+
throw new Error(`A paragraph in a patch uses the numbering "${reference}", which isn't in the numbering option of patchDocument. Add it there with its levels, as in a Document`);
|
|
37136
|
+
}
|
|
37137
|
+
return list;
|
|
37138
|
+
};
|
|
37139
|
+
const newNumIdOf = (list) => {
|
|
37140
|
+
var _highestNumId;
|
|
37141
|
+
const knownId = newNumIds.get(list.numId);
|
|
37142
|
+
if (knownId !== void 0) return knownId;
|
|
37143
|
+
highestNumId = ((_highestNumId = highestNumId) !== null && _highestNumId !== void 0 ? _highestNumId : highestOf(idsInTemplate("w:num", "w:numId"))) + 1;
|
|
37144
|
+
newNumIds.set(list.numId, highestNumId);
|
|
37145
|
+
return highestNumId;
|
|
37146
|
+
};
|
|
37147
|
+
const renumber = (element) => {
|
|
37148
|
+
const list = element.name === "w:numId" ? listOf(String(element.attributes["w:val"])) : void 0;
|
|
37149
|
+
if (list === void 0) return element.elements === void 0 ? element : _objectSpread2(_objectSpread2({}, element), {}, { elements: element.elements.map(renumber) });
|
|
37150
|
+
return _objectSpread2(_objectSpread2({}, element), {}, { attributes: _objectSpread2(_objectSpread2({}, element.attributes), {}, { "w:val": String(newNumIdOf(list)) }) });
|
|
37151
|
+
};
|
|
37152
|
+
const findOrAddPart = (written) => {
|
|
37153
|
+
const relationship = numberingRelationship();
|
|
37154
|
+
const path = numberingPath(relationship);
|
|
37155
|
+
if (!parts.has(path)) {
|
|
37156
|
+
parts.set(path, {
|
|
37157
|
+
declaration: { attributes: {
|
|
37158
|
+
version: "1.0",
|
|
37159
|
+
encoding: "UTF-8",
|
|
37160
|
+
standalone: "yes"
|
|
37161
|
+
} },
|
|
37162
|
+
elements: [_objectSpread2(_objectSpread2({}, written), {}, { elements: [] })]
|
|
37163
|
+
});
|
|
37164
|
+
addContentTypeOverride(NUMBERING_CONTENT_TYPE, `/${path}`);
|
|
37165
|
+
}
|
|
37166
|
+
if (!relationship) createContext(DOCUMENT_PATH).viewWrapper.Relationships.addRelationship(uniqueId(), NUMBERING_RELATIONSHIP, relativeTarget(DOCUMENT_PATH, path));
|
|
37167
|
+
return path;
|
|
37168
|
+
};
|
|
37169
|
+
const write = () => {
|
|
37170
|
+
var _root$attributes$mcI, _root$attributes;
|
|
37171
|
+
if (newNumIds.size === 0) return;
|
|
37172
|
+
const written = formatElement(numbering, createContext(numberingPath()));
|
|
37173
|
+
const abstractNumIdOf = (list) => Number(list.elements.find((element) => element.name === "w:abstractNumId").attributes["w:val"]);
|
|
37174
|
+
const lists = written.elements.filter((element) => element.name === "w:num" && newNumIds.has(Number(element.attributes["w:numId"])));
|
|
37175
|
+
const highestAbstractNumId = highestOf(idsInTemplate("w:abstractNum", "w:abstractNumId"));
|
|
37176
|
+
const newAbstractNumIds = new Map([...new Set(lists.map(abstractNumIdOf))].map((id, index) => [id, highestAbstractNumId + index + 1]));
|
|
37177
|
+
const abstractLists = written.elements.flatMap((element) => {
|
|
37178
|
+
const newId = element.name === "w:abstractNum" ? newAbstractNumIds.get(Number(element.attributes["w:abstractNumId"])) : void 0;
|
|
37179
|
+
return newId === void 0 ? [] : [_objectSpread2(_objectSpread2({}, element), {}, { attributes: _objectSpread2(_objectSpread2({}, element.attributes), {}, { "w:abstractNumId": String(newId) }) })];
|
|
37180
|
+
});
|
|
37181
|
+
const path = findOrAddPart(written);
|
|
37182
|
+
const root = parts.get(path).elements.find((element) => element.name === "w:numbering");
|
|
37183
|
+
root.attributes = _objectSpread2(_objectSpread2(_objectSpread2({}, Object.fromEntries(Object.entries(written.attributes).filter(([name]) => name.startsWith("xmlns:")))), root.attributes), {}, { "mc:Ignorable": [.../* @__PURE__ */ new Set([...String((_root$attributes$mcI = (_root$attributes = root.attributes) === null || _root$attributes === void 0 ? void 0 : _root$attributes["mc:Ignorable"]) !== null && _root$attributes$mcI !== void 0 ? _root$attributes$mcI : "").split(" "), ...String(written.attributes["mc:Ignorable"]).split(" ")])].filter((prefix) => prefix !== "").join(" ") });
|
|
37184
|
+
const elements = getFirstLevelElements(parts.get(path), "w:numbering");
|
|
37185
|
+
const firstIndexOf = (names) => {
|
|
37186
|
+
const index = elements.findIndex((element) => names.includes(element.name));
|
|
37187
|
+
return index === -1 ? elements.length : index;
|
|
37188
|
+
};
|
|
37189
|
+
elements.splice(firstIndexOf(["w:num", "w:numIdMacAtCleanup"]), 0, ...abstractLists);
|
|
37190
|
+
elements.splice(firstIndexOf(["w:numIdMacAtCleanup"]), 0, ...lists.map((list) => _objectSpread2(_objectSpread2({}, list), {}, {
|
|
37191
|
+
attributes: _objectSpread2(_objectSpread2({}, list.attributes), {}, { "w:numId": String(newNumIds.get(Number(list.attributes["w:numId"]))) }),
|
|
37192
|
+
elements: list.elements.map((element) => element.name === "w:abstractNumId" ? _objectSpread2(_objectSpread2({}, element), {}, { attributes: { "w:val": String(newAbstractNumIds.get(abstractNumIdOf(list))) } }) : element)
|
|
37193
|
+
})));
|
|
37194
|
+
};
|
|
37195
|
+
return {
|
|
37196
|
+
renumber: (elements) => elements.map(renumber),
|
|
37197
|
+
write
|
|
37198
|
+
};
|
|
37199
|
+
};
|
|
37200
|
+
//#endregion
|
|
36761
37201
|
//#region src/patcher/page-numbers.ts
|
|
36762
37202
|
/**
|
|
36763
37203
|
* Page numbers written into a template's fields once `patchDocument` has patched it, from an estimate of its pages, as
|
|
@@ -37185,7 +37625,6 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37185
37625
|
*
|
|
37186
37626
|
* @module
|
|
37187
37627
|
*/
|
|
37188
|
-
var formatter = new Formatter();
|
|
37189
37628
|
var SPLIT_TOKEN = "";
|
|
37190
37629
|
/**
|
|
37191
37630
|
* Replaces placeholder text in XML with new content from a patch.
|
|
@@ -37202,7 +37641,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37202
37641
|
* @param keepOriginalStyles - Whether to preserve original text formatting
|
|
37203
37642
|
* @param recursive - Whether to replace every occurrence in a paragraph, rather than only the first
|
|
37204
37643
|
* @param renumberIds - Renumbers the bookmarks and note references the patch inserts, so they don't take an id the
|
|
37205
|
-
* document uses
|
|
37644
|
+
* document uses, and records the styles it uses
|
|
37206
37645
|
* @returns Result containing the modified element and whether a replacement occurred
|
|
37207
37646
|
*/
|
|
37208
37647
|
var replacer = ({ json, patch, patchText, context, keepOriginalStyles = true, recursive = true, renumberIds = (elements) => elements }) => {
|
|
@@ -37258,7 +37697,10 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37258
37697
|
var formatChildren = (patch, context, renumberIds) => renumberIds(patch.children.flatMap((c) => {
|
|
37259
37698
|
var _c$writtenAs;
|
|
37260
37699
|
return (_c$writtenAs = c.writtenAs) !== null && _c$writtenAs !== void 0 ? _c$writtenAs : c;
|
|
37261
|
-
}).
|
|
37700
|
+
}).flatMap((c) => {
|
|
37701
|
+
const formatted = c.prepForXml(context);
|
|
37702
|
+
return formatted ? [toJson((0, import_xml.default)(formatted)).elements[0]] : [];
|
|
37703
|
+
}));
|
|
37262
37704
|
/**
|
|
37263
37705
|
* Replaces the first occurrence of the placeholder from `fromIndex` on, splitting the run it starts in.
|
|
37264
37706
|
*
|
|
@@ -37382,6 +37824,91 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37382
37824
|
var goToParentElementFromPath = (json, path) => goToElementFromPath(json, path.slice(0, path.length - 1));
|
|
37383
37825
|
var getLastElementIndexFromPath = (path) => path[path.length - 1];
|
|
37384
37826
|
//#endregion
|
|
37827
|
+
//#region src/patcher/styles.ts
|
|
37828
|
+
/**
|
|
37829
|
+
* Styles of content inserted into an existing document.
|
|
37830
|
+
*
|
|
37831
|
+
* @module
|
|
37832
|
+
*/
|
|
37833
|
+
var formatter = new Formatter();
|
|
37834
|
+
var STYLES_PATH = "word/styles.xml";
|
|
37835
|
+
var REFERENCES = /* @__PURE__ */ new Set([
|
|
37836
|
+
"w:pStyle",
|
|
37837
|
+
"w:rStyle",
|
|
37838
|
+
"w:tblStyle",
|
|
37839
|
+
"w:basedOn",
|
|
37840
|
+
"w:next",
|
|
37841
|
+
"w:link"
|
|
37842
|
+
]);
|
|
37843
|
+
var idOf = (style) => {
|
|
37844
|
+
var _style$attributes;
|
|
37845
|
+
return String((_style$attributes = style.attributes) === null || _style$attributes === void 0 ? void 0 : _style$attributes["w:styleId"]);
|
|
37846
|
+
};
|
|
37847
|
+
var nameOf = (style) => {
|
|
37848
|
+
var _style$elements;
|
|
37849
|
+
const name = (_style$elements = style.elements) === null || _style$elements === void 0 || (_style$elements = _style$elements.find((element) => element.name === "w:name")) === null || _style$elements === void 0 || (_style$elements = _style$elements.attributes) === null || _style$elements === void 0 ? void 0 : _style$elements["w:val"];
|
|
37850
|
+
return name === void 0 ? void 0 : String(name).toLowerCase();
|
|
37851
|
+
};
|
|
37852
|
+
var formatDefaultStyles = (context) => new Map(Object.values(createDefaultStyles()).map((style) => toJson((0, import_xml.default)(formatter.format(style, context))).elements[0]).filter((style) => style.name === "w:style").map((style) => [idOf(style), style]));
|
|
37853
|
+
/**
|
|
37854
|
+
* Creates the writer of the styles that patches use.
|
|
37855
|
+
*
|
|
37856
|
+
* A paragraph in a patch refers to its style by its id, such as `Heading1` for `HeadingLevel.HEADING_1`, which a
|
|
37857
|
+
* template may not have, as Word only saves the styles that a document uses. Word shows a paragraph whose style the
|
|
37858
|
+
* document doesn't have in the Normal style, and LibreOffice leaves out its number if it is in a list, so the styles of
|
|
37859
|
+
* docx's that the content uses are added to the document.
|
|
37860
|
+
*
|
|
37861
|
+
* @param parts - The document's XML parts, parsed, by their paths, whose styles part the styles are added to
|
|
37862
|
+
* @param createContext - Creates a context to format content for a part with
|
|
37863
|
+
*/
|
|
37864
|
+
var patchStyles = (parts, createContext) => {
|
|
37865
|
+
var _parts$get;
|
|
37866
|
+
const templateStyles = getFirstLevelElements((_parts$get = parts.get(STYLES_PATH)) !== null && _parts$get !== void 0 ? _parts$get : {}, "w:styles").filter((element) => element.name === "w:style");
|
|
37867
|
+
const templateIds = new Set(templateStyles.map(idOf));
|
|
37868
|
+
let defaultStyles;
|
|
37869
|
+
const defaultStyleOf = (id) => {
|
|
37870
|
+
var _defaultStyles;
|
|
37871
|
+
(_defaultStyles = defaultStyles) !== null && _defaultStyles !== void 0 || (defaultStyles = formatDefaultStyles(createContext(STYLES_PATH)));
|
|
37872
|
+
return defaultStyles.get(id);
|
|
37873
|
+
};
|
|
37874
|
+
const missingIds = /* @__PURE__ */ new Set();
|
|
37875
|
+
const idsInDocument = /* @__PURE__ */ new Map();
|
|
37876
|
+
const findIdInDocument = (id) => {
|
|
37877
|
+
const style = templateIds.has(id) ? void 0 : defaultStyleOf(id);
|
|
37878
|
+
if (style === void 0) return id;
|
|
37879
|
+
const sameStyle = templateStyles.find((templateStyle) => {
|
|
37880
|
+
var _templateStyle$attrib, _style$attributes2;
|
|
37881
|
+
return ((_templateStyle$attrib = templateStyle.attributes) === null || _templateStyle$attrib === void 0 ? void 0 : _templateStyle$attrib["w:type"]) === ((_style$attributes2 = style.attributes) === null || _style$attributes2 === void 0 ? void 0 : _style$attributes2["w:type"]) && nameOf(templateStyle) === nameOf(style);
|
|
37882
|
+
});
|
|
37883
|
+
if (sameStyle !== void 0) return idOf(sameStyle);
|
|
37884
|
+
missingIds.add(id);
|
|
37885
|
+
return id;
|
|
37886
|
+
};
|
|
37887
|
+
const idInDocument = (id) => {
|
|
37888
|
+
if (!idsInDocument.has(id)) idsInDocument.set(id, findIdInDocument(id));
|
|
37889
|
+
return idsInDocument.get(id);
|
|
37890
|
+
};
|
|
37891
|
+
const withIdsInDocument = (element) => {
|
|
37892
|
+
var _element$name;
|
|
37893
|
+
if (REFERENCES.has((_element$name = element.name) !== null && _element$name !== void 0 ? _element$name : "")) return _objectSpread2(_objectSpread2({}, element), {}, { attributes: _objectSpread2(_objectSpread2({}, element.attributes), {}, { "w:val": idInDocument(String(element.attributes["w:val"])) }) });
|
|
37894
|
+
return element.elements === void 0 ? element : _objectSpread2(_objectSpread2({}, element), {}, { elements: element.elements.map(withIdsInDocument) });
|
|
37895
|
+
};
|
|
37896
|
+
const write = () => {
|
|
37897
|
+
const stylesPart = parts.get(STYLES_PATH);
|
|
37898
|
+
if (!stylesPart) return;
|
|
37899
|
+
const styles = getFirstLevelElements(stylesPart, "w:styles");
|
|
37900
|
+
const ids = new Set(styles.map(idOf));
|
|
37901
|
+
for (const id of missingIds) if (!ids.has(id)) {
|
|
37902
|
+
ids.add(id);
|
|
37903
|
+
styles.push(withIdsInDocument(defaultStyleOf(id)));
|
|
37904
|
+
}
|
|
37905
|
+
};
|
|
37906
|
+
return {
|
|
37907
|
+
use: (elements) => elements.map(withIdsInDocument),
|
|
37908
|
+
write
|
|
37909
|
+
};
|
|
37910
|
+
};
|
|
37911
|
+
//#endregion
|
|
37385
37912
|
//#region src/patcher/table-rows.ts
|
|
37386
37913
|
var EMPTY = {
|
|
37387
37914
|
type: PatchType.PARAGRAPH,
|
|
@@ -37396,8 +37923,9 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37396
37923
|
* @param patch - The rows of data
|
|
37397
37924
|
* @param delimiters - The placeholders' delimiters
|
|
37398
37925
|
* @param patchPlaceholder - Patches a field in a copy of the rows, as `patchDocument` patches a placeholder
|
|
37926
|
+
* @param renumberDrawings - Gives the drawings in a copy of the rows ids no other drawing in the document has
|
|
37399
37927
|
*/
|
|
37400
|
-
var patchTableRows = ({ json, key, patch, delimiters: { start, end }, patchPlaceholder }) => {
|
|
37928
|
+
var patchTableRows = ({ json, key, patch, delimiters: { start, end }, patchPlaceholder, renumberDrawings }) => {
|
|
37401
37929
|
const fieldStart = `${start}${key}.`;
|
|
37402
37930
|
for (const rows of findRowsToRepeat(json, fieldStart)) {
|
|
37403
37931
|
const fields = fieldsIn(rows.elements, fieldStart, end);
|
|
@@ -37405,7 +37933,7 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37405
37933
|
const copy = {
|
|
37406
37934
|
type: "element",
|
|
37407
37935
|
name: "w:tbl",
|
|
37408
|
-
elements: [...index === 0 ? rows.elements.map(copyOf) : withoutIds(rows.elements)]
|
|
37936
|
+
elements: [...index === 0 ? rows.elements.map(copyOf) : renumberDrawings(withoutIds(rows.elements))]
|
|
37409
37937
|
};
|
|
37410
37938
|
const fieldPatches = new Map(Object.entries(row).flatMap(([field, p]) => p === void 0 ? [] : [[field, p]]));
|
|
37411
37939
|
for (const [field, fieldPatch] of fieldPatches) patchPlaceholder(copy, `${key}.${field}`, fieldPatch);
|
|
@@ -37655,14 +38183,17 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37655
38183
|
var _ref = _asyncToGenerator(function* ({ outputType, data, patches, keepOriginalStyles, placeholderDelimiters = {
|
|
37656
38184
|
start: "{{",
|
|
37657
38185
|
end: "}}"
|
|
37658
|
-
}, recursive = true, footnotes, endnotes, pageNumbers }) {
|
|
38186
|
+
}, recursive = true, footnotes, endnotes, numbering = { config: [] }, pageNumbers }) {
|
|
37659
38187
|
const zipContent = data instanceof import_jszip_min.default ? data : yield import_jszip_min.default.loadAsync(data);
|
|
37660
38188
|
const contexts = /* @__PURE__ */ new Map();
|
|
37661
38189
|
const themeColors = yield readThemeColors(zipContent);
|
|
37662
38190
|
const contentTypeOverrides = [];
|
|
37663
38191
|
const file = {
|
|
37664
38192
|
Media: new Media(),
|
|
38193
|
+
Numbering: new Numbering(numbering),
|
|
37665
38194
|
Theme: themeColors && { Colors: themeColors },
|
|
38195
|
+
FootNotes: { View: { idOf: (reference, note, context) => carryNote("footnotes", reference, note, context) } },
|
|
38196
|
+
Endnotes: { View: { idOf: (reference, note, context) => carryNote("endnotes", reference, note, context) } },
|
|
37666
38197
|
PackageParts: new PackageParts({ addOverride: (contentType, partName) => contentTypeOverrides.push({
|
|
37667
38198
|
contentType,
|
|
37668
38199
|
partName
|
|
@@ -37705,9 +38236,12 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37705
38236
|
map.set(key, json);
|
|
37706
38237
|
}
|
|
37707
38238
|
const renumberBookmarks = renumberBookmarksAvoiding([...map.values()].flatMap(findBookmarkIds));
|
|
37708
|
-
const
|
|
37709
|
-
|
|
37710
|
-
|
|
38239
|
+
const renumberDrawings = renumberDrawingsAvoiding([...map.values()].flatMap(findDrawingIds));
|
|
38240
|
+
const viewWrappers = /* @__PURE__ */ new Map();
|
|
38241
|
+
const viewWrapperOf = (key) => {
|
|
38242
|
+
const existing = viewWrappers.get(key);
|
|
38243
|
+
if (existing) return existing;
|
|
38244
|
+
const viewWrapper = { Relationships: { addRelationship: (id, type, target, targetMode) => {
|
|
37711
38245
|
relationshipAdditions.push({
|
|
37712
38246
|
key,
|
|
37713
38247
|
id,
|
|
@@ -37715,20 +38249,38 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37715
38249
|
target,
|
|
37716
38250
|
targetMode
|
|
37717
38251
|
});
|
|
37718
|
-
} } }
|
|
38252
|
+
} } };
|
|
38253
|
+
viewWrappers.set(key, viewWrapper);
|
|
38254
|
+
return viewWrapper;
|
|
38255
|
+
};
|
|
38256
|
+
const createContext = (key) => ({
|
|
38257
|
+
file,
|
|
38258
|
+
viewWrapper: viewWrapperOf(key),
|
|
37719
38259
|
stack: []
|
|
37720
38260
|
});
|
|
38261
|
+
const addContentTypeOverride = (contentType, partName) => {
|
|
38262
|
+
contentTypeOverrides.push({
|
|
38263
|
+
contentType,
|
|
38264
|
+
partName
|
|
38265
|
+
});
|
|
38266
|
+
};
|
|
38267
|
+
const styles = patchStyles(map, createContext);
|
|
38268
|
+
const lists = patchNumbering(file.Numbering, map, {
|
|
38269
|
+
createContext,
|
|
38270
|
+
addContentTypeOverride
|
|
38271
|
+
});
|
|
37721
38272
|
const notes = patchNotes({
|
|
37722
38273
|
footnotes,
|
|
37723
38274
|
endnotes
|
|
37724
38275
|
}, map, {
|
|
37725
38276
|
createContext,
|
|
37726
|
-
addContentTypeOverride
|
|
37727
|
-
|
|
37728
|
-
|
|
37729
|
-
|
|
37730
|
-
|
|
38277
|
+
addContentTypeOverride,
|
|
38278
|
+
renumberBookmarks,
|
|
38279
|
+
renumberDrawings,
|
|
38280
|
+
renumberLists: lists.renumber,
|
|
38281
|
+
useStyles: styles.use
|
|
37731
38282
|
});
|
|
38283
|
+
const carryNote = (kind, reference, note, context) => context.viewWrapper === viewWrapperOf("word/document.xml") ? notes.carry(kind, reference, note) : void 0;
|
|
37732
38284
|
patchDrawings({
|
|
37733
38285
|
parts: map,
|
|
37734
38286
|
binaryParts: binaryContentMap,
|
|
@@ -37755,7 +38307,8 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37755
38307
|
start,
|
|
37756
38308
|
end
|
|
37757
38309
|
},
|
|
37758
|
-
patchPlaceholder
|
|
38310
|
+
patchPlaceholder,
|
|
38311
|
+
renumberDrawings
|
|
37759
38312
|
});
|
|
37760
38313
|
return;
|
|
37761
38314
|
}
|
|
@@ -37764,12 +38317,13 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37764
38317
|
json: element,
|
|
37765
38318
|
patch: _objectSpread2(_objectSpread2({}, patchValue), {}, { children: patchValue.children.flatMap((child) => child instanceof Bookmark ? child.writtenAs : [child]).map((child) => {
|
|
37766
38319
|
if (child instanceof ExternalHyperlink) {
|
|
37767
|
-
const
|
|
38320
|
+
const { target, anchor } = externalHyperlinkTarget(child.options.link);
|
|
38321
|
+
const concreteHyperlink = new ConcreteHyperlink(child.options.children, uniqueId(), anchor, child.options.link);
|
|
37768
38322
|
hyperlinkRelationships.push({
|
|
37769
38323
|
key,
|
|
37770
38324
|
id: concreteHyperlink.linkId,
|
|
37771
38325
|
type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
|
|
37772
|
-
target
|
|
38326
|
+
target,
|
|
37773
38327
|
targetMode: TargetModeType.EXTERNAL
|
|
37774
38328
|
});
|
|
37775
38329
|
return concreteHyperlink;
|
|
@@ -37779,13 +38333,15 @@ while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[+
|
|
|
37779
38333
|
context,
|
|
37780
38334
|
keepOriginalStyles,
|
|
37781
38335
|
recursive,
|
|
37782
|
-
renumberIds: (elements) => notes.renumber(renumberBookmarks(elements))
|
|
38336
|
+
renumberIds: (elements) => styles.use(lists.renumber(notes.renumber(renumberBookmarks(renumberDrawings(elements)))))
|
|
37783
38337
|
});
|
|
37784
38338
|
if (didFindOccurrence) relationshipAdditions.push(...hyperlinkRelationships);
|
|
37785
38339
|
};
|
|
37786
38340
|
for (const [patchKey, patchValue] of patchesInOrder) patchPlaceholder(json, patchKey, patchValue);
|
|
37787
38341
|
}
|
|
37788
38342
|
notes.write();
|
|
38343
|
+
lists.write();
|
|
38344
|
+
styles.write();
|
|
37789
38345
|
for (const [key, json] of map) {
|
|
37790
38346
|
if (!key.startsWith("word/") || key.endsWith(".xml.rels")) continue;
|
|
37791
38347
|
const mediaDatas = imageReplacer.getMediaData(JSON.stringify(json), file.Media);
|