docx 8.5.0 → 8.6.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.
Files changed (29) hide show
  1. package/build/file/drawing/inline/graphic/graphic-data/pic/blip/blip-extentions.d.ts +3 -0
  2. package/build/file/drawing/inline/graphic/graphic-data/pic/blip/blip.d.ts +1 -3
  3. package/build/file/index.d.ts +1 -0
  4. package/build/file/media/data.d.ts +12 -3
  5. package/build/file/paragraph/math/n-ary/index.d.ts +3 -0
  6. package/build/file/paragraph/math/n-ary/math-limit-location.d.ts +1 -1
  7. package/build/file/paragraph/math/n-ary/math-limit-lower.d.ts +9 -0
  8. package/build/file/paragraph/math/n-ary/math-limit-lower.spec.d.ts +1 -0
  9. package/build/file/paragraph/math/n-ary/math-limit-upper.d.ts +9 -0
  10. package/build/file/paragraph/math/n-ary/math-limit-upper.spec.d.ts +1 -0
  11. package/build/file/paragraph/math/n-ary/math-limit.d.ts +5 -0
  12. package/build/file/paragraph/math/n-ary/math-limit.spec.d.ts +1 -0
  13. package/build/file/paragraph/math/n-ary/math-n-ary-properties.d.ts +1 -1
  14. package/build/file/paragraph/properties.d.ts +1 -1
  15. package/build/file/paragraph/run/image-run.d.ts +14 -4
  16. package/build/file/paragraph/run/properties.d.ts +20 -1
  17. package/build/index.cjs +283 -153
  18. package/build/index.iife.js +283 -153
  19. package/build/index.mjs +283 -153
  20. package/build/index.umd.js +283 -153
  21. package/build/patcher/from-docx.d.ts +18 -4
  22. package/build/patcher/index.d.ts +1 -0
  23. package/build/patcher/patch-detector.d.ts +6 -0
  24. package/build/patcher/patch-detector.spec.d.ts +1 -0
  25. package/build/patcher/replacer.d.ts +7 -2
  26. package/build/patcher/replacer.spec.d.ts +80 -1
  27. package/build/patcher/run-renderer.d.ts +1 -1
  28. package/build/patcher/traverser.d.ts +1 -0
  29. package/package.json +2 -2
package/build/index.mjs CHANGED
@@ -10034,6 +10034,25 @@ const TextEffect = {
10034
10034
  SPARKLE: "sparkle",
10035
10035
  NONE: "none"
10036
10036
  };
10037
+ const HighlightColor = {
10038
+ BLACK: "black",
10039
+ BLUE: "blue",
10040
+ CYAN: "cyan",
10041
+ DARK_BLUE: "darkBlue",
10042
+ DARK_CYAN: "darkCyan",
10043
+ DARK_GRAY: "darkGray",
10044
+ DARK_GREEN: "darkGreen",
10045
+ DARK_MAGENTA: "darkMagenta",
10046
+ DARK_RED: "darkRed",
10047
+ DARK_YELLOW: "darkYellow",
10048
+ GREEN: "green",
10049
+ LIGHT_GRAY: "lightGray",
10050
+ MAGENTA: "magenta",
10051
+ NONE: "none",
10052
+ RED: "red",
10053
+ WHITE: "white",
10054
+ YELLOW: "yellow"
10055
+ };
10037
10056
  class RunProperties extends IgnoreIfEmptyXmlComponent {
10038
10057
  constructor(options2) {
10039
10058
  var _a, _b;
@@ -10181,11 +10200,9 @@ class Text extends XmlComponent {
10181
10200
  if (typeof options2 === "string") {
10182
10201
  this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
10183
10202
  this.root.push(options2);
10184
- return this;
10185
10203
  } else {
10186
10204
  this.root.push(new TextAttributes({ space: (_a = options2.space) != null ? _a : SpaceType.DEFAULT }));
10187
10205
  this.root.push(options2.text);
10188
- return this;
10189
10206
  }
10190
10207
  }
10191
10208
  }
@@ -10425,26 +10442,47 @@ class GraphicDataAttributes extends XmlAttributeComponent {
10425
10442
  });
10426
10443
  }
10427
10444
  }
10428
- class BlipAttributes extends XmlAttributeComponent {
10429
- constructor() {
10430
- super(...arguments);
10431
- __publicField(this, "xmlKeys", {
10432
- embed: "r:embed",
10433
- cstate: "cstate"
10434
- });
10435
- }
10436
- }
10437
- class Blip extends XmlComponent {
10438
- constructor(mediaData) {
10439
- super("a:blip");
10440
- this.root.push(
10441
- new BlipAttributes({
10442
- embed: `rId{${mediaData.fileName}}`,
10443
- cstate: "none"
10444
- })
10445
- );
10445
+ const createSvgBlip = (mediaData) => new BuilderElement({
10446
+ name: "asvg:svgBlip",
10447
+ attributes: {
10448
+ asvg: {
10449
+ key: "xmlns:asvg",
10450
+ value: "http://schemas.microsoft.com/office/drawing/2016/SVG/main"
10451
+ },
10452
+ embed: {
10453
+ key: "r:embed",
10454
+ value: `rId{${mediaData.fileName}}`
10455
+ }
10446
10456
  }
10447
- }
10457
+ });
10458
+ const createExtention = (mediaData) => new BuilderElement({
10459
+ name: "a:ext",
10460
+ attributes: {
10461
+ uri: {
10462
+ key: "uri",
10463
+ value: "{96DAC541-7B7A-43D3-8B79-37D633B846F1}"
10464
+ }
10465
+ },
10466
+ children: [createSvgBlip(mediaData)]
10467
+ });
10468
+ const createExtentionList = (mediaData) => new BuilderElement({
10469
+ name: "a:extLst",
10470
+ children: [createExtention(mediaData)]
10471
+ });
10472
+ const createBlip = (mediaData) => new BuilderElement({
10473
+ name: "a:blip",
10474
+ attributes: {
10475
+ embed: {
10476
+ key: "r:embed",
10477
+ value: `rId{${mediaData.type === "svg" ? mediaData.fallback.fileName : mediaData.fileName}}`
10478
+ },
10479
+ cstate: {
10480
+ key: "cstate",
10481
+ value: "none"
10482
+ }
10483
+ },
10484
+ children: mediaData.type === "svg" ? [createExtentionList(mediaData)] : []
10485
+ });
10448
10486
  class SourceRectangle extends XmlComponent {
10449
10487
  constructor() {
10450
10488
  super("a:srcRect");
@@ -10464,7 +10502,7 @@ class Stretch extends XmlComponent {
10464
10502
  class BlipFill extends XmlComponent {
10465
10503
  constructor(mediaData) {
10466
10504
  super("pic:blipFill");
10467
- this.root.push(new Blip(mediaData));
10505
+ this.root.push(createBlip(mediaData));
10468
10506
  this.root.push(new SourceRectangle());
10469
10507
  this.root.push(new Stretch());
10470
10508
  }
@@ -11114,28 +11152,57 @@ class Drawing extends XmlComponent {
11114
11152
  }
11115
11153
  }
11116
11154
  }
11155
+ const convertDataURIToBinary = (dataURI) => {
11156
+ if (typeof atob === "function") {
11157
+ const BASE64_MARKER = ";base64,";
11158
+ const base64Index = dataURI.indexOf(BASE64_MARKER);
11159
+ const base64IndexWithOffset = base64Index === -1 ? 0 : base64Index + BASE64_MARKER.length;
11160
+ return new Uint8Array(
11161
+ atob(dataURI.substring(base64IndexWithOffset)).split("").map((c) => c.charCodeAt(0))
11162
+ );
11163
+ } else {
11164
+ const b = require("buffer");
11165
+ return new b.Buffer(dataURI, "base64");
11166
+ }
11167
+ };
11168
+ const standardizeData = (data) => typeof data === "string" ? convertDataURIToBinary(data) : data;
11169
+ const createImageData = (options2, key) => ({
11170
+ data: standardizeData(options2.data),
11171
+ fileName: key,
11172
+ transformation: {
11173
+ pixels: {
11174
+ x: Math.round(options2.transformation.width),
11175
+ y: Math.round(options2.transformation.height)
11176
+ },
11177
+ emus: {
11178
+ x: Math.round(options2.transformation.width * 9525),
11179
+ y: Math.round(options2.transformation.height * 9525)
11180
+ },
11181
+ flip: options2.transformation.flip,
11182
+ rotation: options2.transformation.rotation ? options2.transformation.rotation * 6e4 : void 0
11183
+ }
11184
+ });
11117
11185
  class ImageRun extends Run {
11118
11186
  constructor(options2) {
11119
11187
  super({});
11120
- __publicField(this, "key", `${uniqueId()}.png`);
11188
+ __publicField(this, "key");
11189
+ __publicField(this, "fallbackKey", `${uniqueId()}.png`);
11121
11190
  __publicField(this, "imageData");
11122
- const newData = typeof options2.data === "string" ? this.convertDataURIToBinary(options2.data) : options2.data;
11123
- this.imageData = {
11124
- stream: newData,
11125
- fileName: this.key,
11126
- transformation: {
11127
- pixels: {
11128
- x: Math.round(options2.transformation.width),
11129
- y: Math.round(options2.transformation.height)
11130
- },
11131
- emus: {
11132
- x: Math.round(options2.transformation.width * 9525),
11133
- y: Math.round(options2.transformation.height * 9525)
11134
- },
11135
- flip: options2.transformation.flip,
11136
- rotation: options2.transformation.rotation ? options2.transformation.rotation * 6e4 : void 0
11137
- }
11138
- };
11191
+ this.key = `${uniqueId()}.${options2.type}`;
11192
+ this.imageData = options2.type === "svg" ? __spreadProps(__spreadValues({
11193
+ type: options2.type
11194
+ }, createImageData(options2, this.key)), {
11195
+ fallback: __spreadValues({
11196
+ type: options2.fallback.type
11197
+ }, createImageData(
11198
+ __spreadProps(__spreadValues({}, options2.fallback), {
11199
+ transformation: options2.transformation
11200
+ }),
11201
+ this.fallbackKey
11202
+ ))
11203
+ }) : __spreadValues({
11204
+ type: options2.type
11205
+ }, createImageData(options2, this.key));
11139
11206
  const drawing = new Drawing(this.imageData, {
11140
11207
  floating: options2.floating,
11141
11208
  docProperties: options2.altText,
@@ -11145,20 +11212,10 @@ class ImageRun extends Run {
11145
11212
  }
11146
11213
  prepForXml(context) {
11147
11214
  context.file.Media.addImage(this.key, this.imageData);
11148
- return super.prepForXml(context);
11149
- }
11150
- convertDataURIToBinary(dataURI) {
11151
- if (typeof atob === "function") {
11152
- const BASE64_MARKER = ";base64,";
11153
- const base64Index = dataURI.indexOf(BASE64_MARKER);
11154
- const base64IndexWithOffset = base64Index === -1 ? 0 : base64Index + BASE64_MARKER.length;
11155
- return new Uint8Array(
11156
- atob(dataURI.substring(base64IndexWithOffset)).split("").map((c) => c.charCodeAt(0))
11157
- );
11158
- } else {
11159
- const b = require("buffer");
11160
- return new b.Buffer(dataURI, "base64");
11215
+ if (this.imageData.type === "svg") {
11216
+ context.file.Media.addImage(this.fallbackKey, this.imageData.fallback);
11161
11217
  }
11218
+ return super.prepForXml(context);
11162
11219
  }
11163
11220
  }
11164
11221
  class SequentialIdentifierInstruction extends XmlComponent {
@@ -12487,6 +12544,8 @@ class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
12487
12544
  instance: (_a = options2.numbering.instance) != null ? _a : 0
12488
12545
  });
12489
12546
  this.push(new NumberProperties(`${options2.numbering.reference}-${(_b = options2.numbering.instance) != null ? _b : 0}`, options2.numbering.level));
12547
+ } else if (options2.numbering === false) {
12548
+ this.push(new NumberProperties(0, 0));
12490
12549
  }
12491
12550
  if (options2.border) {
12492
12551
  this.push(new Border(options2.border));
@@ -12671,9 +12730,9 @@ class MathLimitLocationAttributes extends XmlAttributeComponent {
12671
12730
  }
12672
12731
  }
12673
12732
  class MathLimitLocation extends XmlComponent {
12674
- constructor() {
12733
+ constructor(value) {
12675
12734
  super("m:limLoc");
12676
- this.root.push(new MathLimitLocationAttributes({ value: "undOvr" }));
12735
+ this.root.push(new MathLimitLocationAttributes({ value: value || "undOvr" }));
12677
12736
  }
12678
12737
  }
12679
12738
  class MathSubScriptHideAttributes extends XmlAttributeComponent {
@@ -12701,12 +12760,12 @@ class MathSuperScriptHide extends XmlComponent {
12701
12760
  }
12702
12761
  }
12703
12762
  class MathNAryProperties extends XmlComponent {
12704
- constructor(accent, hasSuperScript, hasSubScript) {
12763
+ constructor(accent, hasSuperScript, hasSubScript, limitLocationVal) {
12705
12764
  super("m:naryPr");
12706
12765
  if (!!accent) {
12707
12766
  this.root.push(new MathAccentCharacter(accent));
12708
12767
  }
12709
- this.root.push(new MathLimitLocation());
12768
+ this.root.push(new MathLimitLocation(limitLocationVal));
12710
12769
  if (!hasSuperScript) {
12711
12770
  this.root.push(new MathSuperScriptHide());
12712
12771
  }
@@ -12747,7 +12806,7 @@ class MathSum extends XmlComponent {
12747
12806
  class MathIntegral extends XmlComponent {
12748
12807
  constructor(options2) {
12749
12808
  super("m:nary");
12750
- this.root.push(new MathNAryProperties("", !!options2.superScript, !!options2.subScript));
12809
+ this.root.push(new MathNAryProperties("", !!options2.superScript, !!options2.subScript, "subSup"));
12751
12810
  if (!!options2.subScript) {
12752
12811
  this.root.push(new MathSubScriptElement(options2.subScript));
12753
12812
  }
@@ -12757,6 +12816,28 @@ class MathIntegral extends XmlComponent {
12757
12816
  this.root.push(new MathBase(options2.children));
12758
12817
  }
12759
12818
  }
12819
+ class MathLimit extends XmlComponent {
12820
+ constructor(children) {
12821
+ super("m:lim");
12822
+ for (const child of children) {
12823
+ this.root.push(child);
12824
+ }
12825
+ }
12826
+ }
12827
+ class MathLimitUpper extends XmlComponent {
12828
+ constructor(options2) {
12829
+ super("m:limUpp");
12830
+ this.root.push(new MathBase(options2.children));
12831
+ this.root.push(new MathLimit(options2.limit));
12832
+ }
12833
+ }
12834
+ class MathLimitLower extends XmlComponent {
12835
+ constructor(options2) {
12836
+ super("m:limLow");
12837
+ this.root.push(new MathBase(options2.children));
12838
+ this.root.push(new MathLimit(options2.limit));
12839
+ }
12840
+ }
12760
12841
  class MathSuperScriptProperties extends XmlComponent {
12761
12842
  constructor() {
12762
12843
  super("m:sSupPr");
@@ -13571,6 +13652,7 @@ class ContentTypes extends XmlComponent {
13571
13652
  this.root.push(new Default("image/jpeg", "jpg"));
13572
13653
  this.root.push(new Default("image/bmp", "bmp"));
13573
13654
  this.root.push(new Default("image/gif", "gif"));
13655
+ this.root.push(new Default("image/svg+xml", "svg"));
13574
13656
  this.root.push(new Default("application/vnd.openxmlformats-package.relationships+xml", "rels"));
13575
13657
  this.root.push(new Default("application/xml", "xml"));
13576
13658
  this.root.push(new Default("application/vnd.openxmlformats-officedocument.obfuscatedFont", "odttf"));
@@ -15450,7 +15532,7 @@ class File {
15450
15532
  defaultTabStop: options2.defaultTabStop
15451
15533
  });
15452
15534
  this.media = new Media();
15453
- if (options2.externalStyles) {
15535
+ if (options2.externalStyles !== void 0) {
15454
15536
  const stylesFactory = new ExternalStylesFactory();
15455
15537
  this.styles = stylesFactory.newInstance(options2.externalStyles);
15456
15538
  } else if (options2.styles) {
@@ -18891,8 +18973,13 @@ class Compiler {
18891
18973
  zip.file(obj.path, obj.data);
18892
18974
  }
18893
18975
  }
18894
- for (const { stream, fileName } of file.Media.Array) {
18895
- zip.file(`word/media/${fileName}`, stream);
18976
+ for (const data of file.Media.Array) {
18977
+ if (data.type !== "svg") {
18978
+ zip.file(`word/media/${data.fileName}`, data.data);
18979
+ } else {
18980
+ zip.file(`word/media/${data.fileName}`, data.data);
18981
+ zip.file(`word/media/${data.fallback.fileName}`, data.fallback.data);
18982
+ }
18896
18983
  }
18897
18984
  for (const { data: buffer2, name, fontKey } of file.FontTable.fontOptionsWithKey) {
18898
18985
  const [nameWithoutExtension] = name.split(".");
@@ -19477,64 +19564,6 @@ const splitRunElement = (runElement, token) => {
19477
19564
  });
19478
19565
  return { left: leftRunElement, right: rightRunElement };
19479
19566
  };
19480
- const formatter = new Formatter();
19481
- const SPLIT_TOKEN = "ɵ";
19482
- const replacer = (json, patch, patchText, renderedParagraphs, context, keepOriginalStyles = false) => {
19483
- for (const renderedParagraph of renderedParagraphs) {
19484
- const textJson = patch.children.map((c) => toJson(xml$1(formatter.format(c, context)))).map((c) => c.elements[0]);
19485
- switch (patch.type) {
19486
- case PatchType.DOCUMENT: {
19487
- const parentElement = goToParentElementFromPath(json, renderedParagraph.path);
19488
- const elementIndex = getLastElementIndexFromPath(renderedParagraph.path);
19489
- parentElement.elements.splice(elementIndex, 1, ...textJson);
19490
- break;
19491
- }
19492
- case PatchType.PARAGRAPH:
19493
- default: {
19494
- const paragraphElement = goToElementFromPath(json, renderedParagraph.path);
19495
- replaceTokenInParagraphElement({
19496
- paragraphElement,
19497
- renderedParagraph,
19498
- originalText: patchText,
19499
- replacementText: SPLIT_TOKEN
19500
- });
19501
- const index = findRunElementIndexWithToken(paragraphElement, SPLIT_TOKEN);
19502
- const runElementToBeReplaced = paragraphElement.elements[index];
19503
- const { left, right } = splitRunElement(runElementToBeReplaced, SPLIT_TOKEN);
19504
- let newRunElements = textJson;
19505
- let patchedRightElement = right;
19506
- if (keepOriginalStyles) {
19507
- const runElementNonTextualElements = runElementToBeReplaced.elements.filter(
19508
- (e) => e.type === "element" && e.name !== "w:t"
19509
- );
19510
- newRunElements = textJson.map((e) => __spreadProps(__spreadValues({}, e), {
19511
- elements: [...runElementNonTextualElements, ...e.elements]
19512
- }));
19513
- patchedRightElement = __spreadProps(__spreadValues({}, right), {
19514
- elements: [...runElementNonTextualElements, ...right.elements]
19515
- });
19516
- }
19517
- paragraphElement.elements.splice(index, 1, left, ...newRunElements, patchedRightElement);
19518
- break;
19519
- }
19520
- }
19521
- }
19522
- return json;
19523
- };
19524
- const goToElementFromPath = (json, path) => {
19525
- let element2 = json;
19526
- for (let i = 1; i < path.length; i++) {
19527
- const index = path[i];
19528
- const nextElements = element2.elements;
19529
- if (!nextElements) {
19530
- throw new Error("Could not find element");
19531
- }
19532
- element2 = nextElements[index];
19533
- }
19534
- return element2;
19535
- };
19536
- const goToParentElementFromPath = (json, path) => goToElementFromPath(json, path.slice(0, path.length - 1));
19537
- const getLastElementIndexFromPath = (path) => path[path.length - 1];
19538
19567
  const renderParagraphNode = (node) => {
19539
19568
  if (node.element.name !== "w:p") {
19540
19569
  throw new Error(`Invalid node type: ${node.element.name}`);
@@ -19544,7 +19573,7 @@ const renderParagraphNode = (node) => {
19544
19573
  text: "",
19545
19574
  runs: [],
19546
19575
  index: -1,
19547
- path: []
19576
+ pathToParagraph: []
19548
19577
  };
19549
19578
  }
19550
19579
  let currentRunStringLength = 0;
@@ -19552,13 +19581,13 @@ const renderParagraphNode = (node) => {
19552
19581
  const renderedRunNode = renderRunNode(element2, i, currentRunStringLength);
19553
19582
  currentRunStringLength += renderedRunNode.text.length;
19554
19583
  return renderedRunNode;
19555
- }).filter((e) => !!e).map((e) => e);
19584
+ }).filter((e) => !!e);
19556
19585
  const text = runs.reduce((acc, curr) => acc + curr.text, "");
19557
19586
  return {
19558
19587
  text,
19559
19588
  runs,
19560
19589
  index: node.index,
19561
- path: buildNodePath(node)
19590
+ pathToParagraph: buildNodePath(node)
19562
19591
  };
19563
19592
  };
19564
19593
  const renderRunNode = (node, index, currentRunStringIndex) => {
@@ -19605,7 +19634,7 @@ const elementsToWrapper = (wrapper) => {
19605
19634
  parent: wrapper
19606
19635
  }))) != null ? _b : [];
19607
19636
  };
19608
- const findLocationOfText = (node, text) => {
19637
+ const traverse = (node) => {
19609
19638
  let renderedParagraphs = [];
19610
19639
  const queue2 = [
19611
19640
  ...elementsToWrapper({
@@ -19623,8 +19652,74 @@ const findLocationOfText = (node, text) => {
19623
19652
  queue2.push(...elementsToWrapper(currentNode));
19624
19653
  }
19625
19654
  }
19626
- return renderedParagraphs.filter((p) => p.text.includes(text));
19655
+ return renderedParagraphs;
19656
+ };
19657
+ const findLocationOfText = (node, text) => traverse(node).filter((p) => p.text.includes(text));
19658
+ const formatter = new Formatter();
19659
+ const SPLIT_TOKEN = "ɵ";
19660
+ const replacer = ({
19661
+ json,
19662
+ patch,
19663
+ patchText,
19664
+ context,
19665
+ keepOriginalStyles = true
19666
+ }) => {
19667
+ const renderedParagraphs = findLocationOfText(json, patchText);
19668
+ if (renderedParagraphs.length === 0) {
19669
+ throw new Error(`Could not find text ${patchText}`);
19670
+ }
19671
+ for (const renderedParagraph of renderedParagraphs) {
19672
+ const textJson = patch.children.map((c) => toJson(xml$1(formatter.format(c, context)))).map((c) => c.elements[0]);
19673
+ switch (patch.type) {
19674
+ case PatchType.DOCUMENT: {
19675
+ const parentElement = goToParentElementFromPath(json, renderedParagraph.pathToParagraph);
19676
+ const elementIndex = getLastElementIndexFromPath(renderedParagraph.pathToParagraph);
19677
+ parentElement.elements.splice(elementIndex, 1, ...textJson);
19678
+ break;
19679
+ }
19680
+ case PatchType.PARAGRAPH:
19681
+ default: {
19682
+ const paragraphElement = goToElementFromPath(json, renderedParagraph.pathToParagraph);
19683
+ replaceTokenInParagraphElement({
19684
+ paragraphElement,
19685
+ renderedParagraph,
19686
+ originalText: patchText,
19687
+ replacementText: SPLIT_TOKEN
19688
+ });
19689
+ const index = findRunElementIndexWithToken(paragraphElement, SPLIT_TOKEN);
19690
+ const runElementToBeReplaced = paragraphElement.elements[index];
19691
+ const { left, right } = splitRunElement(runElementToBeReplaced, SPLIT_TOKEN);
19692
+ let newRunElements = textJson;
19693
+ let patchedRightElement = right;
19694
+ if (keepOriginalStyles) {
19695
+ const runElementNonTextualElements = runElementToBeReplaced.elements.filter(
19696
+ (e) => e.type === "element" && e.name !== "w:t"
19697
+ );
19698
+ newRunElements = textJson.map((e) => __spreadProps(__spreadValues({}, e), {
19699
+ elements: [...runElementNonTextualElements, ...e.elements]
19700
+ }));
19701
+ patchedRightElement = __spreadProps(__spreadValues({}, right), {
19702
+ elements: [...runElementNonTextualElements, ...right.elements]
19703
+ });
19704
+ }
19705
+ paragraphElement.elements.splice(index, 1, left, ...newRunElements, patchedRightElement);
19706
+ break;
19707
+ }
19708
+ }
19709
+ }
19710
+ return json;
19711
+ };
19712
+ const goToElementFromPath = (json, path) => {
19713
+ let element2 = json;
19714
+ for (let i = 1; i < path.length; i++) {
19715
+ const index = path[i];
19716
+ const nextElements = element2.elements;
19717
+ element2 = nextElements[index];
19718
+ }
19719
+ return element2;
19627
19720
  };
19721
+ const goToParentElementFromPath = (json, path) => goToElementFromPath(json, path.slice(0, path.length - 1));
19722
+ const getLastElementIndexFromPath = (path) => path[path.length - 1];
19628
19723
  const getIdFromRelationshipId = (relationshipId) => {
19629
19724
  const output = parseInt(relationshipId.substring(3), 10);
19630
19725
  return isNaN(output) ? 0 : output;
@@ -19675,7 +19770,12 @@ const PatchType = {
19675
19770
  PARAGRAPH: "paragraph"
19676
19771
  };
19677
19772
  const imageReplacer = new ImageReplacer();
19678
- const patchDocument = (data, options2) => __async(void 0, null, function* () {
19773
+ const patchDocument = (_0) => __async(void 0, [_0], function* ({
19774
+ outputType,
19775
+ data,
19776
+ patches,
19777
+ keepOriginalStyles
19778
+ }) {
19679
19779
  var _a, _b;
19680
19780
  const zipContent = yield JSZip.loadAsync(data);
19681
19781
  const contexts = /* @__PURE__ */ new Map();
@@ -19712,34 +19812,38 @@ const patchDocument = (data, options2) => __async(void 0, null, function* () {
19712
19812
  stack: []
19713
19813
  };
19714
19814
  contexts.set(key, context);
19715
- for (const [patchKey, patchValue] of Object.entries(options2.patches)) {
19815
+ for (const [patchKey, patchValue] of Object.entries(patches)) {
19716
19816
  const patchText = `{{${patchKey}}}`;
19717
- const renderedParagraphs = findLocationOfText(json, patchText);
19718
- replacer(
19719
- json,
19720
- __spreadProps(__spreadValues({}, patchValue), {
19721
- children: patchValue.children.map((element2) => {
19722
- if (element2 instanceof ExternalHyperlink) {
19723
- const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
19724
- hyperlinkRelationshipAdditions.push({
19725
- key,
19726
- hyperlink: {
19727
- id: concreteHyperlink.linkId,
19728
- link: element2.options.link
19817
+ while (true) {
19818
+ try {
19819
+ replacer({
19820
+ json,
19821
+ patch: __spreadProps(__spreadValues({}, patchValue), {
19822
+ children: patchValue.children.map((element2) => {
19823
+ if (element2 instanceof ExternalHyperlink) {
19824
+ const concreteHyperlink = new ConcreteHyperlink(element2.options.children, uniqueId());
19825
+ hyperlinkRelationshipAdditions.push({
19826
+ key,
19827
+ hyperlink: {
19828
+ id: concreteHyperlink.linkId,
19829
+ link: element2.options.link
19830
+ }
19831
+ });
19832
+ return concreteHyperlink;
19833
+ } else {
19834
+ return element2;
19729
19835
  }
19730
- });
19731
- return concreteHyperlink;
19732
- } else {
19733
- return element2;
19734
- }
19735
- })
19736
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19737
- }),
19738
- patchText,
19739
- renderedParagraphs,
19740
- context,
19741
- options2.keepOriginalStyles
19742
- );
19836
+ })
19837
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19838
+ }),
19839
+ patchText,
19840
+ context,
19841
+ keepOriginalStyles
19842
+ });
19843
+ } catch (e) {
19844
+ break;
19845
+ }
19846
+ }
19743
19847
  }
19744
19848
  const mediaDatas = imageReplacer.getMediaData(JSON.stringify(json), context.file.Media);
19745
19849
  if (mediaDatas.length > 0) {
@@ -19791,6 +19895,7 @@ const patchDocument = (data, options2) => __async(void 0, null, function* () {
19791
19895
  appendContentType(contentTypesJson, "image/jpeg", "jpg");
19792
19896
  appendContentType(contentTypesJson, "image/bmp", "bmp");
19793
19897
  appendContentType(contentTypesJson, "image/gif", "gif");
19898
+ appendContentType(contentTypesJson, "image/svg+xml", "svg");
19794
19899
  }
19795
19900
  const zip = new JSZip();
19796
19901
  for (const [key, value] of map) {
@@ -19800,11 +19905,11 @@ const patchDocument = (data, options2) => __async(void 0, null, function* () {
19800
19905
  for (const [key, value] of binaryContentMap) {
19801
19906
  zip.file(key, value);
19802
19907
  }
19803
- for (const { stream, fileName } of file.Media.Array) {
19908
+ for (const { data: stream, fileName } of file.Media.Array) {
19804
19909
  zip.file(`word/media/${fileName}`, stream);
19805
19910
  }
19806
19911
  return zip.generateAsync({
19807
- type: "uint8array",
19912
+ type: outputType,
19808
19913
  mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
19809
19914
  compression: "DEFLATE"
19810
19915
  });
@@ -19832,6 +19937,25 @@ const createRelationshipFile = () => ({
19832
19937
  }
19833
19938
  ]
19834
19939
  });
19940
+ const patchDetector = (_0) => __async(void 0, [_0], function* ({ data }) {
19941
+ const zipContent = yield JSZip.loadAsync(data);
19942
+ const patches = /* @__PURE__ */ new Set();
19943
+ for (const [key, value] of Object.entries(zipContent.files)) {
19944
+ if (!key.endsWith(".xml") && !key.endsWith(".rels")) {
19945
+ continue;
19946
+ }
19947
+ if (key.startsWith("word/") && !key.endsWith(".xml.rels")) {
19948
+ const json = toJson(yield value.async("text"));
19949
+ traverse(json).forEach((p) => findPatchKeys(p.text).forEach((patch) => patches.add(patch)));
19950
+ }
19951
+ }
19952
+ return Array.from(patches);
19953
+ });
19954
+ const findPatchKeys = (text) => {
19955
+ var _a;
19956
+ const pattern = new RegExp("(?<=\\{\\{).+?(?=\\}\\})", "gs");
19957
+ return (_a = text.match(pattern)) != null ? _a : [];
19958
+ };
19835
19959
  export {
19836
19960
  AbstractNumbering,
19837
19961
  Alignment,
@@ -19886,6 +20010,7 @@ export {
19886
20010
  EndnoteReference,
19887
20011
  ExternalHyperlink,
19888
20012
  File,
20013
+ FileChild,
19889
20014
  FootNoteReferenceRunAttributes,
19890
20015
  FootNotes,
19891
20016
  Footer2 as Footer,
@@ -19903,6 +20028,7 @@ export {
19903
20028
  HeaderWrapper,
19904
20029
  HeadingLevel,
19905
20030
  HeightRule,
20031
+ HighlightColor,
19906
20032
  HorizontalPosition,
19907
20033
  HorizontalPositionAlign,
19908
20034
  HorizontalPositionRelativeFrom,
@@ -19938,7 +20064,10 @@ export {
19938
20064
  MathFunctionName,
19939
20065
  MathFunctionProperties,
19940
20066
  MathIntegral,
20067
+ MathLimit,
19941
20068
  MathLimitLocation,
20069
+ MathLimitLower,
20070
+ MathLimitUpper,
19942
20071
  MathNAryProperties,
19943
20072
  MathNumerator,
19944
20073
  MathPreSubSuperScript,
@@ -20093,6 +20222,7 @@ export {
20093
20222
  hpsMeasureValue,
20094
20223
  longHexNumber,
20095
20224
  measurementOrPercentValue,
20225
+ patchDetector,
20096
20226
  patchDocument,
20097
20227
  percentageValue,
20098
20228
  pointMeasureValue,