@office-open/docx 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { i as __toCommonJS, n as __exportAll, r as __reExport, t as __esmMin } from "./chunk-090QGkrx.mjs";
2
- import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, DOCX_NS, EMPTY_OBJECT, EmptyElement, Formatter, Formatter as Formatter$1, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, OoxmlMimeType, PrettifyType, RawPassthrough, Relationships, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, appendContentType, appendRelationship, attrObj, chartAttr, convertEmuToPixels, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, createDefault, createOverride, createPacker, createReplacer, createTraverser, getNextRelationshipIndex, getReferencedMedia, hasPlaceholders, hashedId, hpsMeasureObj, hpsMeasureObj as hpsMeasureObj$1, numberValObj, numberValObj as numberValObj$1, onOffObj, onOffObj as onOffObj$1, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, strFromU8, stringContainerObj, stringEnumValObj, stringEnumValObj as stringEnumValObj$1, stringValObj, stringValObj as stringValObj$1, toJson, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipSync, wrapEl, xsdVerticalMergeRev, zipAndConvert } from "@office-open/core";
3
- import { textToUint8Array, toUint8Array } from "undio";
2
+ import { AppProperties, BaseXmlComponent, BuilderElement, BuilderElement as BuilderElement$1, DOCX_NS, EMPTY_OBJECT, EmptyElement, Formatter, Formatter as Formatter$1, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, NextAttributeComponent, OoxmlMimeType, RawPassthrough, Relationships, TargetModeType, XmlAttributeComponent, XmlAttributeComponent as XmlAttributeComponent$1, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, appendContentType, appendRelationship, attrObj, chartAttr, convertEmuToPixels, convertInchesToTwip, convertMillimetersToTwip, convertPixelsToEmu, convertToXmlComponent, createDefault, createOverride, createPacker, createReplacer, createTraverser, getNextRelationshipIndex, getReferencedMedia, hasPlaceholders, hashedId, hpsMeasureObj, hpsMeasureObj as hpsMeasureObj$1, numberValObj, numberValObj as numberValObj$1, onOffObj, onOffObj as onOffObj$1, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, strFromU8, stringContainerObj, stringEnumValObj, stringEnumValObj as stringEnumValObj$1, stringValObj, stringValObj as stringValObj$1, toJson, uniqueId, uniqueNumericIdCreator, uniqueNumericIdCreator as uniqueNumericIdCreator$1, uniqueUuid, unzipSync, wrapEl, xsdVerticalMergeRev, zipAndConvert } from "@office-open/core";
3
+ import { attr, attrBool, attrNum, children, colorAttr, findChild, findDeep, js2xml, textOf, xml, xml2js } from "@office-open/xml";
4
+ import { toUint8Array } from "undio";
4
5
  import { PresetGeometry, buildFill, createBlipFill, createCustomGeometry, createEffectDag, createEffectList, createOutline, createScene3D, createShape3D, createTransform2D, extractBlipFillMedia } from "@office-open/core/drawingml";
5
6
  import { ChartCollection, ChartSpace } from "@office-open/core/chart";
6
7
  import { COLOR_CATEGORIES, DEFAULT_DRAWING_XML, LAYOUT_CATEGORIES, STYLE_CATEGORIES, SmartArtCollection, createDataModel, getColorXml, getLayoutXml, getStyleXml } from "@office-open/core/smartart";
7
- import { attr, attrBool, attrNum, children, colorAttr, findChild, findDeep, js2xml, textOf, xml, xml2js } from "@office-open/xml";
8
8
  export * from "@office-open/core/values";
9
9
  export * from "@office-open/core/smartart";
10
10
  //#region src/file/xml-components/base.ts
@@ -1443,6 +1443,14 @@ var init_run$1 = __esmMin((() => {
1443
1443
  } else children.push(child);
1444
1444
  return { "w:r": children.length > 0 ? children : {} };
1445
1445
  }
1446
+ /**
1447
+ * Fast path: pre-built object → xml() string. Slow path: prepForXml → xml.
1448
+ */
1449
+ toXml(context) {
1450
+ if (this._prebuilt && this.extraChildren.length === 0) return xml(this._prebuilt);
1451
+ const obj = this.prepForXml(context);
1452
+ return obj ? xml(obj) : "";
1453
+ }
1446
1454
  };
1447
1455
  }));
1448
1456
  //#endregion
@@ -6287,6 +6295,15 @@ var init_properties = __esmMin((() => {
6287
6295
  if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this.numberingReferences) context.file.numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
6288
6296
  return super.prepForXml(context);
6289
6297
  }
6298
+ /**
6299
+ * Register numbering references (side effect) before serialization.
6300
+ * toXml() bypasses prepForXml(), so numbering registration must be
6301
+ * triggered explicitly here.
6302
+ */
6303
+ toXml(context) {
6304
+ if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this.numberingReferences) context.file.numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
6305
+ return super.toXml(context);
6306
+ }
6290
6307
  };
6291
6308
  ParagraphPropertiesChange = class extends XmlComponent {
6292
6309
  constructor(options) {
@@ -6444,6 +6461,103 @@ var init_paragraph$1 = __esmMin((() => {
6444
6461
  setSectionProperties(section) {
6445
6462
  this.sectionProperties = section;
6446
6463
  }
6464
+ /**
6465
+ * Direct XML serialization — bypasses IXmlableObject tree construction.
6466
+ * Coerces children and calls their toXml() methods for zero-allocation output.
6467
+ */
6468
+ toXml(context) {
6469
+ const parts = [];
6470
+ if (!(context.viewWrapper instanceof FontWrapper)) for (const reference of this._props.numberingReferences) context.file.numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
6471
+ let finalPPrObj = this._props.xml;
6472
+ if (this.sectionProperties) {
6473
+ const sectPrObj = this.sectionProperties.prepForXml(context);
6474
+ if (sectPrObj) if (finalPPrObj) finalPPrObj["w:pPr"].push(sectPrObj);
6475
+ else finalPPrObj = { "w:pPr": [sectPrObj] };
6476
+ }
6477
+ if (finalPPrObj) parts.push(xml(finalPPrObj));
6478
+ for (const run of this.frontRuns) {
6479
+ const s = run.toXml(context);
6480
+ if (s) parts.push(s);
6481
+ }
6482
+ if (this._textRun) {
6483
+ const s = this._textRun.toXml(context);
6484
+ if (s) parts.push(s);
6485
+ }
6486
+ if (this.options.children) {
6487
+ for (const rawChild of this.options.children) for (const s of this.serializeChild(rawChild, context)) if (s) parts.push(s);
6488
+ }
6489
+ const body = parts.join("");
6490
+ return body ? `<w:p>${body}</w:p>` : "<w:p/>";
6491
+ }
6492
+ /**
6493
+ * Serialize a single child element, handling all type coercions and side effects.
6494
+ * Returns an array of XML strings (Bookmark yields 3 parts: start + children + end).
6495
+ */
6496
+ serializeChild(rawChild, context) {
6497
+ if (rawChild instanceof ExternalHyperlink) {
6498
+ const concreteHyperlink = new ConcreteHyperlink(rawChild.options.children, uniqueId(), { tooltip: rawChild.options.tooltip });
6499
+ context.viewWrapper.relationships.addRelationship(concreteHyperlink.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", rawChild.options.link, TargetModeType.EXTERNAL);
6500
+ return [concreteHyperlink.toXml(context)];
6501
+ }
6502
+ if (rawChild instanceof Bookmark) {
6503
+ const parts = [];
6504
+ parts.push(rawChild.start.toXml(context));
6505
+ for (const textRun of rawChild.children) if (textRun instanceof BaseXmlComponent) parts.push(textRun.toXml(context));
6506
+ parts.push(rawChild.end.toXml(context));
6507
+ return parts;
6508
+ }
6509
+ if (typeof rawChild === "object" && rawChild !== null && "hyperlink" in rawChild) {
6510
+ const { hyperlink, ...runOpts } = rawChild;
6511
+ const hlChildren = hyperlink.children;
6512
+ const textRuns = [];
6513
+ if (hlChildren && hlChildren.length > 0) for (const rc of hlChildren) textRuns.push(new TextRun(rc));
6514
+ else textRuns.push(new TextRun(runOpts));
6515
+ if ("link" in hyperlink) {
6516
+ const ext = new ExternalHyperlink({
6517
+ link: hyperlink.link,
6518
+ tooltip: hyperlink.tooltip,
6519
+ children: textRuns
6520
+ });
6521
+ const concrete = new ConcreteHyperlink(ext.options.children, uniqueId(), { tooltip: ext.options.tooltip });
6522
+ context.viewWrapper.relationships.addRelationship(concrete.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ext.options.link, TargetModeType.EXTERNAL);
6523
+ return [concrete.toXml(context)];
6524
+ }
6525
+ if ("anchor" in hyperlink) return [new InternalHyperlink({
6526
+ anchor: hyperlink.anchor,
6527
+ tooltip: hyperlink.tooltip,
6528
+ children: textRuns
6529
+ }).toXml(context)];
6530
+ return [];
6531
+ }
6532
+ if (typeof rawChild === "object" && rawChild !== null && "bookmarkStart" in rawChild) return [new BookmarkStart(rawChild.bookmarkStart.name, rawChild.bookmarkStart.id).toXml(context)];
6533
+ if (typeof rawChild === "object" && rawChild !== null && "bookmarkEnd" in rawChild) return [new BookmarkEnd(rawChild.bookmarkEnd).toXml(context)];
6534
+ const child = this.coerceChild(rawChild);
6535
+ return child ? [child.toXml(context)] : [];
6536
+ }
6537
+ /** Coerce a raw child option into a BaseXmlComponent instance. */
6538
+ coerceChild(rawChild) {
6539
+ if (typeof rawChild === "string") return new TextRun(rawChild);
6540
+ if (rawChild instanceof BaseXmlComponent) return rawChild;
6541
+ if ("chart" in rawChild) return new ChartRun(rawChild.chart);
6542
+ if ("smartArt" in rawChild) return new SmartArtRun(rawChild.smartArt);
6543
+ if ("image" in rawChild) return new ImageRun(rawChild.image);
6544
+ if ("math" in rawChild && typeof rawChild === "object" && rawChild !== null && typeof rawChild.math === "object" && rawChild.math !== null) {
6545
+ const coercedChildren = rawChild.math.children?.map(coerceMathJson);
6546
+ return new Math$1(coercedChildren ? { children: coercedChildren } : { children: [] });
6547
+ }
6548
+ if ("symbolRun" in rawChild) return new SymbolRun(rawChild.symbolRun);
6549
+ if ("footnoteReference" in rawChild) return new FootnoteReferenceRun(rawChild.footnoteReference);
6550
+ if ("endnoteReference" in rawChild) return new EndnoteReferenceRun(rawChild.endnoteReference);
6551
+ if ("pageBreak" in rawChild) return new PageBreak();
6552
+ if ("columnBreak" in rawChild) return new ColumnBreak();
6553
+ if ("commentRangeStart" in rawChild) return new CommentRangeStart(rawChild.commentRangeStart);
6554
+ if ("commentRangeEnd" in rawChild) return new CommentRangeEnd(rawChild.commentRangeEnd);
6555
+ if ("commentReference" in rawChild) return new TextRun({ children: [new CommentReference(rawChild.commentReference)] });
6556
+ if ("insertion" in rawChild) return new InsertedTextRun(rawChild.insertion);
6557
+ if ("deletion" in rawChild) return new DeletedTextRun(rawChild.deletion);
6558
+ if ("hyperlink" in rawChild || "bookmarkStart" in rawChild || "bookmarkEnd" in rawChild) return;
6559
+ return new TextRun(rawChild);
6560
+ }
6447
6561
  };
6448
6562
  }));
6449
6563
  //#endregion
@@ -8337,6 +8451,19 @@ var init_table_row$1 = __esmMin((() => {
8337
8451
  }
8338
8452
  return { "w:tr": children.length ? children : EMPTY_OBJECT };
8339
8453
  }
8454
+ toXml(context) {
8455
+ const parts = [];
8456
+ if (this.options.propertyExceptions) parts.push(new TablePropertyExceptions(this.options.propertyExceptions).toXml(context));
8457
+ const trPrObj = buildTableRowProperties(this.options);
8458
+ if (trPrObj) parts.push(xml(trPrObj));
8459
+ const prefixCount = parts.length;
8460
+ for (const child of this.coercedChildren) parts.push(child.toXml(context));
8461
+ if (this.extraCells.length > 0) for (const { cell, columnIndex } of this.extraCells) {
8462
+ const insertIdx = this.findInsertIndex(columnIndex, prefixCount);
8463
+ parts.splice(insertIdx, 0, cell.toXml(context));
8464
+ }
8465
+ return parts.length ? `<w:tr>${parts.join("")}</w:tr>` : "<w:tr/>";
8466
+ }
8340
8467
  findInsertIndex(columnIndex, prefixCount) {
8341
8468
  let colIdx = 0;
8342
8469
  for (let i = 0; i < this.coercedChildren.length; i++) {
@@ -8521,6 +8648,15 @@ var init_table_cell = __esmMin((() => {
8521
8648
  if (!(coerced[coerced.length - 1] instanceof Paragraph)) children.push(new Paragraph({}).prepForXml(context));
8522
8649
  return { "w:tc": children };
8523
8650
  }
8651
+ toXml(context) {
8652
+ const parts = [];
8653
+ const tPrObj = buildTableCellProperties(this.options);
8654
+ if (tPrObj) parts.push(xml(tPrObj));
8655
+ const coerced = this.options.children.map((c) => c instanceof BaseXmlComponent ? c : lazyCoerce(c));
8656
+ for (const child of coerced) parts.push(child.toXml(context));
8657
+ if (!(coerced[coerced.length - 1] instanceof Paragraph)) parts.push(new Paragraph({}).toXml(context));
8658
+ return `<w:tc>${parts.join("")}</w:tc>`;
8659
+ }
8524
8660
  };
8525
8661
  }));
8526
8662
  //#endregion
@@ -8659,6 +8795,31 @@ var init_table = __esmMin((() => {
8659
8795
  }
8660
8796
  return { "w:tbl": children };
8661
8797
  }
8798
+ toXml(context) {
8799
+ const parts = [];
8800
+ const tblPr = new TableProperties({
8801
+ alignment: this.options.alignment,
8802
+ borders: this.options.borders ?? {},
8803
+ caption: this.options.caption,
8804
+ cellMargin: this.options.margins,
8805
+ cellSpacing: this.options.cellSpacing,
8806
+ description: this.options.description,
8807
+ float: this.options.float,
8808
+ indent: this.options.indent,
8809
+ layout: this.options.layout,
8810
+ revision: this.options.revision,
8811
+ style: this.options.style,
8812
+ styleColBandSize: this.options.styleColBandSize,
8813
+ styleRowBandSize: this.options.styleRowBandSize,
8814
+ tableLook: this.options.tableLook,
8815
+ visuallyRightToLeft: this.options.visuallyRightToLeft,
8816
+ width: this.options.width ?? { size: 100 }
8817
+ });
8818
+ parts.push(tblPr.toXml(context));
8819
+ parts.push(new TableGrid(this.columnWidths, this.options.columnWidthsRevision).toXml(context));
8820
+ for (const row of this.rows) parts.push(row.toXml(context));
8821
+ return `<w:tbl>${parts.join("")}</w:tbl>`;
8822
+ }
8662
8823
  };
8663
8824
  }));
8664
8825
  //#endregion
@@ -10430,6 +10591,17 @@ var Body = class extends XmlComponent {
10430
10591
  return super.prepForXml(context);
10431
10592
  }
10432
10593
  /**
10594
+ * Direct XML serialization — ensures section properties are appended
10595
+ * before delegating to the default XmlComponent.toXml() traversal.
10596
+ */
10597
+ toXml(context) {
10598
+ if (this.sections.length === 1) {
10599
+ this.root.splice(0, 1);
10600
+ this.root.push(this.sections.pop());
10601
+ }
10602
+ return super.toXml(context);
10603
+ }
10604
+ /**
10433
10605
  * Adds a block-level component to the body.
10434
10606
  *
10435
10607
  * This method is used internally by the Document class to add paragraphs,
@@ -12376,7 +12548,6 @@ init_xml_components();
12376
12548
  var Compatibility = class extends XmlComponent {
12377
12549
  constructor(options) {
12378
12550
  super("w:compat");
12379
- if (options.version) this.root.push(createCompatibilitySetting("compatibilityMode", options.version));
12380
12551
  if (options.useSingleBorderforContiguousCells) this.root.push(onOffObj("w:useSingleBorderforContiguousCells", options.useSingleBorderforContiguousCells));
12381
12552
  if (options.wordPerfectJustification) this.root.push(onOffObj("w:wpJustification", options.wordPerfectJustification));
12382
12553
  if (options.noTabStopForHangingIndent) this.root.push(onOffObj("w:noTabHangInd", options.noTabStopForHangingIndent));
@@ -12442,6 +12613,7 @@ var Compatibility = class extends XmlComponent {
12442
12613
  if (options.ignoreVerticalAlignmentInTextboxes) this.root.push(onOffObj("w:doNotVertAlignInTxbx", options.ignoreVerticalAlignmentInTextboxes));
12443
12614
  if (options.useAnsiKerningPairs) this.root.push(onOffObj("w:useAnsiKerningPairs", options.useAnsiKerningPairs));
12444
12615
  if (options.cachedColumnBalance) this.root.push(onOffObj("w:cachedColBalance", options.cachedColumnBalance));
12616
+ if (options.version) this.root.push(createCompatibilitySetting("compatibilityMode", options.version));
12445
12617
  if (options.overrideTableStyleFontSizeAndJustification) this.root.push(createCompatibilitySetting("overrideTableStyleFontSizeAndJustification", 1));
12446
12618
  if (options.enableOpenTypeFeatures) this.root.push(createCompatibilitySetting("enableOpenTypeFeatures", 1));
12447
12619
  if (options.doNotFlipMirrorIndents) this.root.push(createCompatibilitySetting("doNotFlipMirrorIndents", 1));
@@ -12518,40 +12690,26 @@ var Settings = class extends XmlComponent {
12518
12690
  "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
12519
12691
  "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
12520
12692
  } });
12521
- if (options.trackRevisions !== void 0) this.root.push(onOffObj("w:trackRevisions", options.trackRevisions));
12522
- if (options.documentProtection !== void 0) this.root.push(new DocumentProtection(options.documentProtection));
12693
+ if (options.writeProtection !== void 0) this.root.push(new WriteProtection(options.writeProtection));
12523
12694
  if (options.view !== void 0) this.root.push(new View(options.view));
12524
12695
  if (options.zoom !== void 0) this.root.push(new Zoom({
12525
12696
  val: options.zoom.val,
12526
12697
  percent: options.zoom.percent ?? 100
12527
12698
  }));
12528
- if (options.writeProtection !== void 0) this.root.push(new WriteProtection(options.writeProtection));
12529
12699
  if (options.displayBackgroundShape !== void 0) this.root.push(onOffObj("w:displayBackgroundShape", options.displayBackgroundShape));
12530
12700
  if (options.embedTrueTypeFonts !== void 0) this.root.push(onOffObj("w:embedTrueTypeFonts", options.embedTrueTypeFonts));
12531
12701
  if (options.embedSystemFonts !== void 0) this.root.push(onOffObj("w:embedSystemFonts", options.embedSystemFonts));
12532
12702
  if (options.saveSubsetFonts !== void 0) this.root.push(onOffObj("w:saveSubsetFonts", options.saveSubsetFonts));
12533
- if (options.docVars !== void 0 && options.docVars.length > 0) this.root.push(new BuilderElement({
12534
- name: "w:docVars",
12535
- children: options.docVars.map((v) => new BuilderElement({
12536
- name: "w:docVar",
12537
- attributes: [{
12538
- key: "w:name",
12539
- value: v.name
12540
- }, {
12541
- key: "w:val",
12542
- value: v.val
12543
- }]
12544
- }))
12545
- }));
12546
- if (options.evenAndOddHeaders !== void 0) this.root.push(onOffObj("w:evenAndOddHeaders", options.evenAndOddHeaders));
12547
- if (options.updateFields !== void 0) this.root.push(onOffObj("w:updateFields", options.updateFields));
12703
+ if (options.trackRevisions !== void 0) this.root.push(onOffObj("w:trackRevisions", options.trackRevisions));
12704
+ if (options.documentProtection !== void 0) this.root.push(new DocumentProtection(options.documentProtection));
12548
12705
  this.root.push(numberValObj("w:defaultTabStop", options.defaultTabStop ?? 420));
12549
12706
  if (options.hyphenation?.autoHyphenation !== void 0) this.root.push(onOffObj("w:autoHyphenation", options.hyphenation.autoHyphenation));
12550
- if (options.hyphenation?.hyphenationZone !== void 0) this.root.push(numberValObj("w:hyphenationZone", options.hyphenation.hyphenationZone));
12551
12707
  if (options.hyphenation?.consecutiveHyphenLimit !== void 0) this.root.push(numberValObj("w:consecutiveHyphenLimit", options.hyphenation.consecutiveHyphenLimit));
12708
+ if (options.hyphenation?.hyphenationZone !== void 0) this.root.push(numberValObj("w:hyphenationZone", options.hyphenation.hyphenationZone));
12552
12709
  if (options.hyphenation?.doNotHyphenateCaps !== void 0) this.root.push(onOffObj("w:doNotHyphenateCaps", options.hyphenation.doNotHyphenateCaps));
12710
+ if (options.evenAndOddHeaders !== void 0) this.root.push(onOffObj("w:evenAndOddHeaders", options.evenAndOddHeaders));
12553
12711
  this.root.push(stringValObj("w:characterSpacingControl", options.characterSpacingControl ?? "compressPunctuation"));
12554
- if (options.colorSchemeMapping !== void 0) this.root.push(new ColorSchemeMapping(options.colorSchemeMapping));
12712
+ if (options.updateFields !== void 0) this.root.push(onOffObj("w:updateFields", options.updateFields));
12555
12713
  this.root.push(new Compatibility({
12556
12714
  ...options.compatibility,
12557
12715
  version: options.compatibility?.version ?? options.compatibilityModeVersion ?? 15,
@@ -12566,6 +12724,20 @@ var Settings = class extends XmlComponent {
12566
12724
  enableOpenTypeFeatures: options.compatibility?.enableOpenTypeFeatures ?? true,
12567
12725
  doNotFlipMirrorIndents: options.compatibility?.doNotFlipMirrorIndents ?? true
12568
12726
  }));
12727
+ if (options.docVars !== void 0 && options.docVars.length > 0) this.root.push(new BuilderElement({
12728
+ name: "w:docVars",
12729
+ children: options.docVars.map((v) => new BuilderElement({
12730
+ name: "w:docVar",
12731
+ attributes: [{
12732
+ key: "w:name",
12733
+ value: v.name
12734
+ }, {
12735
+ key: "w:val",
12736
+ value: v.val
12737
+ }]
12738
+ }))
12739
+ }));
12740
+ if (options.colorSchemeMapping !== void 0) this.root.push(new ColorSchemeMapping(options.colorSchemeMapping));
12569
12741
  }
12570
12742
  };
12571
12743
  /**
@@ -13717,9 +13889,10 @@ var File = class {
13717
13889
  if (options.externalStyles !== void 0) {
13718
13890
  const defaultStyles = new DefaultStylesFactory().newInstance(options.styles?.default);
13719
13891
  const externalStyles = new ExternalStylesFactory().newInstance(options.externalStyles);
13892
+ const defaultStyleElements = defaultStyles.importedStyles.slice(1);
13720
13893
  this.styles = new Styles({
13721
13894
  ...externalStyles,
13722
- importedStyles: [...defaultStyles.importedStyles, ...externalStyles.importedStyles]
13895
+ importedStyles: [...externalStyles.importedStyles, ...defaultStyleElements]
13723
13896
  });
13724
13897
  } else if (options.styles) {
13725
13898
  const defaultStyles = new DefaultStylesFactory().newInstance(options.styles.default);
@@ -14538,11 +14711,13 @@ const obfuscate = (buf, fontKey) => {
14538
14711
  //#region src/export/packer/numbering-placeholders.ts
14539
14712
  function replaceNumberingPlaceholders(xml, concreteNumberings) {
14540
14713
  let result = xml;
14541
- for (const { reference, instance, numId } of concreteNumberings) result = result.replace(new RegExp(`{${reference}-${instance}}`, "g"), numId.toString());
14714
+ for (const { reference, instance, numId } of concreteNumberings) result = result.replaceAll(`{${reference}-${instance}}`, numId.toString());
14542
14715
  return result;
14543
14716
  }
14544
14717
  //#endregion
14545
14718
  //#region src/export/packer/next-compiler.ts
14719
+ /** Reusable TextEncoder (stateless, safe to share). */
14720
+ const encoder$1 = new TextEncoder();
14546
14721
  /**
14547
14722
  * Compiles File objects into OOXML-compliant ZIP file data.
14548
14723
  *
@@ -14553,7 +14728,7 @@ function replaceNumberingPlaceholders(xml, concreteNumberings) {
14553
14728
  * @example
14554
14729
  * ```typescript
14555
14730
  * const compiler = new Compiler();
14556
- * const files = compiler.compile(file, PrettifyType.WITH_2_BLANKS);
14731
+ * const files = compiler.compile(file);
14557
14732
  * ```
14558
14733
  */
14559
14734
  var Compiler = class {
@@ -14575,22 +14750,21 @@ var Compiler = class {
14575
14750
  * DEFLATE compression set by the caller via zipSync options.
14576
14751
  *
14577
14752
  * @param file - The document to compile
14578
- * @param prettifyXml - Optional XML formatting style
14579
14753
  * @param overrides - Optional custom XML file overrides
14580
14754
  * @returns A Zippable object mapping file paths to their content
14581
14755
  */
14582
- compile(file, prettifyXml, overrides = []) {
14756
+ compile(file, overrides = []) {
14583
14757
  const files = {};
14584
14758
  const headerFormattedViews = /* @__PURE__ */ new Map();
14585
14759
  const footerFormattedViews = /* @__PURE__ */ new Map();
14586
- const xmlifiedFileMapping = this.xmlifyFile(file, headerFormattedViews, footerFormattedViews, prettifyXml);
14760
+ const xmlifiedFileMapping = this.xmlifyFile(file, headerFormattedViews, footerFormattedViews);
14587
14761
  const map = new Map(Object.entries(xmlifiedFileMapping));
14588
- for (const [, obj] of map) if (Array.isArray(obj)) for (const subFile of obj) files[subFile.path] = typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data;
14762
+ for (const [, obj] of map) if (Array.isArray(obj)) for (const subFile of obj) files[subFile.path] = typeof subFile.data === "string" ? encoder$1.encode(subFile.data) : subFile.data;
14589
14763
  else {
14590
14764
  const fileObj = obj;
14591
- files[fileObj.path] = typeof fileObj.data === "string" ? textToUint8Array(fileObj.data) : fileObj.data;
14765
+ files[fileObj.path] = typeof fileObj.data === "string" ? encoder$1.encode(fileObj.data) : fileObj.data;
14592
14766
  }
14593
- for (const subFile of overrides) files[subFile.path] = typeof subFile.data === "string" ? textToUint8Array(subFile.data) : subFile.data;
14767
+ for (const subFile of overrides) files[subFile.path] = typeof subFile.data === "string" ? encoder$1.encode(subFile.data) : subFile.data;
14594
14768
  for (const mediaData of file.media.array) {
14595
14769
  files[`word/media/${mediaData.fileName}`] = [toUint8Array(mediaData.data), { level: ZIP_STORED_LEVEL }];
14596
14770
  if (mediaData.type === "svg") files[`word/media/${mediaData.fallback.fileName}`] = [toUint8Array(mediaData.fallback.data), { level: ZIP_STORED_LEVEL }];
@@ -14601,63 +14775,28 @@ var Compiler = class {
14601
14775
  }
14602
14776
  return files;
14603
14777
  }
14604
- xmlifyFile(file, headerFormattedViews, footerFormattedViews, prettify) {
14605
- const documentRelationshipCount = file.document.relationships.relationshipCount + 1;
14606
- const documentXmlData = xml(this.formatter.format(file.document.view, {
14778
+ xmlifyFile(file, headerFormattedViews, footerFormattedViews) {
14779
+ const mkCtx = (viewWrapper) => ({
14607
14780
  fileData: file,
14608
14781
  file,
14609
14782
  stack: [],
14610
- viewWrapper: file.document
14611
- }), {
14612
- declaration: {
14613
- encoding: "UTF-8",
14614
- standalone: "yes"
14615
- },
14616
- indent: prettify
14783
+ viewWrapper
14617
14784
  });
14785
+ const documentRelationshipCount = file.document.relationships.relationshipCount + 1;
14786
+ const documentXmlData = this.formatter.formatToXml(file.document.view, mkCtx(file.document));
14618
14787
  const commentRelationshipCount = file.comments.relationships.relationshipCount + 1;
14619
- const commentXmlData = xml(this.formatter.format(file.comments, {
14620
- fileData: file,
14621
- file,
14622
- stack: [],
14623
- viewWrapper: {
14624
- relationships: file.comments.relationships,
14625
- view: file.comments
14626
- }
14627
- }), {
14628
- declaration: {
14629
- encoding: "UTF-8",
14630
- standalone: "yes"
14631
- },
14632
- indent: prettify
14633
- });
14788
+ const commentXmlData = this.formatter.formatToXml(file.comments, mkCtx({
14789
+ relationships: file.comments.relationships,
14790
+ view: file.comments
14791
+ }));
14634
14792
  const footnoteRelationshipCount = file.footNotes.relationships.relationshipCount + 1;
14635
- const footnoteXmlData = xml(this.formatter.format(file.footNotes.view, {
14636
- fileData: file,
14637
- file,
14638
- stack: [],
14639
- viewWrapper: file.footNotes
14640
- }), {
14641
- declaration: {
14642
- encoding: "UTF-8",
14643
- standalone: "yes"
14644
- },
14645
- indent: prettify
14646
- });
14793
+ const footnoteXmlData = this.formatter.formatToXml(file.footNotes.view, mkCtx(file.footNotes));
14647
14794
  const documentMediaDatas = hasPlaceholders(documentXmlData) ? getReferencedMedia(documentXmlData, file.media.array) : [];
14648
14795
  const commentMediaDatas = hasPlaceholders(commentXmlData) ? getReferencedMedia(commentXmlData, file.media.array) : [];
14649
14796
  const footnoteMediaDatas = hasPlaceholders(footnoteXmlData) ? getReferencedMedia(footnoteXmlData, file.media.array) : [];
14650
14797
  return {
14651
14798
  AppProperties: {
14652
- data: xml(this.formatter.format(file.appProperties, {
14653
- fileData: file,
14654
- file,
14655
- stack: [],
14656
- viewWrapper: file.document
14657
- }), { declaration: {
14658
- encoding: "UTF-8",
14659
- standalone: "yes"
14660
- } }),
14799
+ data: this.formatter.formatToXml(file.appProperties, mkCtx(file.document)),
14661
14800
  path: "docProps/app.xml"
14662
14801
  },
14663
14802
  Comments: {
@@ -14669,18 +14808,10 @@ var Compiler = class {
14669
14808
  commentMediaDatas.forEach((mediaData, i) => {
14670
14809
  file.comments.relationships.addRelationship(commentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14671
14810
  });
14672
- return xml(this.formatter.format(file.comments.relationships, {
14673
- fileData: file,
14674
- file,
14675
- stack: [],
14676
- viewWrapper: {
14677
- relationships: file.comments.relationships,
14678
- view: file.comments
14679
- }
14680
- }), {
14681
- declaration: { encoding: "UTF-8" },
14682
- indent: prettify
14683
- });
14811
+ return this.formatter.formatToXml(file.comments.relationships, mkCtx({
14812
+ relationships: file.comments.relationships,
14813
+ view: file.comments
14814
+ }));
14684
14815
  })(),
14685
14816
  path: "word/_rels/comments.xml.rels"
14686
14817
  },
@@ -14696,31 +14827,12 @@ var Compiler = class {
14696
14827
  file.contentTypes.addDiagramColors(i + 1);
14697
14828
  file.contentTypes.addDiagramDrawing(i + 1);
14698
14829
  });
14699
- return xml(this.formatter.format(file.contentTypes, {
14700
- fileData: file,
14701
- file,
14702
- stack: [],
14703
- viewWrapper: file.document
14704
- }), {
14705
- declaration: { encoding: "UTF-8" },
14706
- indent: prettify
14707
- });
14830
+ return this.formatter.formatToXml(file.contentTypes, mkCtx(file.document));
14708
14831
  })(),
14709
14832
  path: "[Content_Types].xml"
14710
14833
  },
14711
14834
  CustomProperties: {
14712
- data: xml(this.formatter.format(file.customProperties, {
14713
- fileData: file,
14714
- file,
14715
- stack: [],
14716
- viewWrapper: file.document
14717
- }), {
14718
- declaration: {
14719
- encoding: "UTF-8",
14720
- standalone: "yes"
14721
- },
14722
- indent: prettify
14723
- }),
14835
+ data: this.formatter.formatToXml(file.customProperties, mkCtx(file.document)),
14724
14836
  path: "docProps/custom.xml"
14725
14837
  },
14726
14838
  Document: {
@@ -14736,66 +14848,23 @@ var Compiler = class {
14736
14848
  path: "word/document.xml"
14737
14849
  },
14738
14850
  Endnotes: {
14739
- data: xml(this.formatter.format(file.endnotes.view, {
14740
- fileData: file,
14741
- file,
14742
- stack: [],
14743
- viewWrapper: file.endnotes
14744
- }), {
14745
- declaration: { encoding: "UTF-8" },
14746
- indent: prettify
14747
- }),
14851
+ data: this.formatter.formatToXml(file.endnotes.view, mkCtx(file.endnotes)),
14748
14852
  path: "word/endnotes.xml"
14749
14853
  },
14750
14854
  EndnotesRelationships: {
14751
- data: xml(this.formatter.format(file.endnotes.relationships, {
14752
- fileData: file,
14753
- file,
14754
- stack: [],
14755
- viewWrapper: file.endnotes
14756
- }), {
14757
- declaration: { encoding: "UTF-8" },
14758
- indent: prettify
14759
- }),
14855
+ data: this.formatter.formatToXml(file.endnotes.relationships, mkCtx(file.endnotes)),
14760
14856
  path: "word/_rels/endnotes.xml.rels"
14761
14857
  },
14762
14858
  FileRelationships: {
14763
- data: xml(this.formatter.format(file.fileRelationships, {
14764
- fileData: file,
14765
- file,
14766
- stack: [],
14767
- viewWrapper: file.document
14768
- }), {
14769
- declaration: { encoding: "UTF-8" },
14770
- indent: prettify
14771
- }),
14859
+ data: this.formatter.formatToXml(file.fileRelationships, mkCtx(file.document)),
14772
14860
  path: "_rels/.rels"
14773
14861
  },
14774
14862
  FontTable: {
14775
- data: xml(this.formatter.format(file.fontTable.view, {
14776
- fileData: file,
14777
- file,
14778
- stack: [],
14779
- viewWrapper: file.document
14780
- }), {
14781
- declaration: {
14782
- encoding: "UTF-8",
14783
- standalone: "yes"
14784
- },
14785
- indent: prettify
14786
- }),
14863
+ data: this.formatter.formatToXml(file.fontTable.view, mkCtx(file.document)),
14787
14864
  path: "word/fontTable.xml"
14788
14865
  },
14789
14866
  FontTableRelationships: {
14790
- data: xml(this.formatter.format(file.fontTable.relationships, {
14791
- fileData: file,
14792
- file,
14793
- stack: [],
14794
- viewWrapper: file.document
14795
- }), {
14796
- declaration: { encoding: "UTF-8" },
14797
- indent: prettify
14798
- }),
14867
+ data: this.formatter.formatToXml(file.fontTable.relationships, mkCtx(file.document)),
14799
14868
  path: "word/_rels/fontTable.xml.rels"
14800
14869
  },
14801
14870
  FootNotes: {
@@ -14807,42 +14876,18 @@ var Compiler = class {
14807
14876
  footnoteMediaDatas.forEach((mediaData, i) => {
14808
14877
  file.footNotes.relationships.addRelationship(footnoteRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14809
14878
  });
14810
- return xml(this.formatter.format(file.footNotes.relationships, {
14811
- fileData: file,
14812
- file,
14813
- stack: [],
14814
- viewWrapper: file.footNotes
14815
- }), {
14816
- declaration: { encoding: "UTF-8" },
14817
- indent: prettify
14818
- });
14879
+ return this.formatter.formatToXml(file.footNotes.relationships, mkCtx(file.footNotes));
14819
14880
  })(),
14820
14881
  path: "word/_rels/footnotes.xml.rels"
14821
14882
  },
14822
14883
  FooterRelationships: file.footers.map((footerWrapper, index) => {
14823
- const xmlData = xml(this.formatter.format(footerWrapper.view, {
14824
- fileData: file,
14825
- file,
14826
- stack: [],
14827
- viewWrapper: footerWrapper
14828
- }), {
14829
- declaration: { encoding: "UTF-8" },
14830
- indent: prettify
14831
- });
14884
+ const xmlData = this.formatter.formatToXml(footerWrapper.view, mkCtx(footerWrapper));
14832
14885
  footerFormattedViews.set(index, xmlData);
14833
14886
  getReferencedMedia(xmlData, file.media.array).forEach((mediaData, i) => {
14834
14887
  footerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14835
14888
  });
14836
14889
  return {
14837
- data: xml(this.formatter.format(footerWrapper.relationships, {
14838
- fileData: file,
14839
- file,
14840
- stack: [],
14841
- viewWrapper: footerWrapper
14842
- }), {
14843
- declaration: { encoding: "UTF-8" },
14844
- indent: prettify
14845
- }),
14890
+ data: this.formatter.formatToXml(footerWrapper.relationships, mkCtx(footerWrapper)),
14846
14891
  path: `word/_rels/footer${index + 1}.xml.rels`
14847
14892
  };
14848
14893
  }),
@@ -14855,29 +14900,13 @@ var Compiler = class {
14855
14900
  };
14856
14901
  }),
14857
14902
  HeaderRelationships: file.headers.map((headerWrapper, index) => {
14858
- const xmlData = xml(this.formatter.format(headerWrapper.view, {
14859
- fileData: file,
14860
- file,
14861
- stack: [],
14862
- viewWrapper: headerWrapper
14863
- }), {
14864
- declaration: { encoding: "UTF-8" },
14865
- indent: prettify
14866
- });
14903
+ const xmlData = this.formatter.formatToXml(headerWrapper.view, mkCtx(headerWrapper));
14867
14904
  headerFormattedViews.set(index, xmlData);
14868
14905
  getReferencedMedia(xmlData, file.media.array).forEach((mediaData, i) => {
14869
14906
  headerWrapper.relationships.addRelationship(i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`);
14870
14907
  });
14871
14908
  return {
14872
- data: xml(this.formatter.format(headerWrapper.relationships, {
14873
- fileData: file,
14874
- file,
14875
- stack: [],
14876
- viewWrapper: headerWrapper
14877
- }), {
14878
- declaration: { encoding: "UTF-8" },
14879
- indent: prettify
14880
- }),
14909
+ data: this.formatter.formatToXml(headerWrapper.relationships, mkCtx(headerWrapper)),
14881
14910
  path: `word/_rels/header${index + 1}.xml.rels`
14882
14911
  };
14883
14912
  }),
@@ -14890,33 +14919,11 @@ var Compiler = class {
14890
14919
  };
14891
14920
  }),
14892
14921
  Numbering: {
14893
- data: xml(this.formatter.format(file.numbering, {
14894
- fileData: file,
14895
- file,
14896
- stack: [],
14897
- viewWrapper: file.document
14898
- }), {
14899
- declaration: {
14900
- encoding: "UTF-8",
14901
- standalone: "yes"
14902
- },
14903
- indent: prettify
14904
- }),
14922
+ data: this.formatter.formatToXml(file.numbering, mkCtx(file.document)),
14905
14923
  path: "word/numbering.xml"
14906
14924
  },
14907
14925
  Properties: {
14908
- data: xml(this.formatter.format(file.coreProperties, {
14909
- fileData: file,
14910
- file,
14911
- stack: [],
14912
- viewWrapper: file.document
14913
- }), {
14914
- declaration: {
14915
- encoding: "UTF-8",
14916
- standalone: "yes"
14917
- },
14918
- indent: prettify
14919
- }),
14926
+ data: this.formatter.formatToXml(file.coreProperties, mkCtx(file.document)),
14920
14927
  path: "docProps/core.xml"
14921
14928
  },
14922
14929
  Relationships: {
@@ -14935,101 +14942,35 @@ var Compiler = class {
14935
14942
  styleRelType: "http://schemas.microsoft.com/office/2007/relationships/diagramStyle"
14936
14943
  });
14937
14944
  file.document.relationships.addRelationship(file.document.relationships.relationshipCount + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable", "fontTable.xml");
14938
- return xml(this.formatter.format(file.document.relationships, {
14939
- fileData: file,
14940
- file,
14941
- stack: [],
14942
- viewWrapper: file.document
14943
- }), {
14944
- declaration: { encoding: "UTF-8" },
14945
- indent: prettify
14946
- });
14945
+ return this.formatter.formatToXml(file.document.relationships, mkCtx(file.document));
14947
14946
  })(),
14948
14947
  path: "word/_rels/document.xml.rels"
14949
14948
  },
14950
14949
  Settings: {
14951
- data: xml(this.formatter.format(file.settings, {
14952
- fileData: file,
14953
- file,
14954
- stack: [],
14955
- viewWrapper: file.document
14956
- }), {
14957
- declaration: {
14958
- encoding: "UTF-8",
14959
- standalone: "yes"
14960
- },
14961
- indent: prettify
14962
- }),
14950
+ data: this.formatter.formatToXml(file.settings, mkCtx(file.document)),
14963
14951
  path: "word/settings.xml"
14964
14952
  },
14965
14953
  Styles: {
14966
- data: replaceNumberingPlaceholders(xml(this.formatter.format(file.styles, {
14967
- fileData: file,
14968
- file,
14969
- stack: [],
14970
- viewWrapper: file.document
14971
- }), {
14972
- declaration: {
14973
- encoding: "UTF-8",
14974
- standalone: "yes"
14975
- },
14976
- indent: prettify
14977
- }), file.numbering.concreteNumbering),
14954
+ data: replaceNumberingPlaceholders(this.formatter.formatToXml(file.styles, mkCtx(file.document)), file.numbering.concreteNumbering),
14978
14955
  path: "word/styles.xml"
14979
14956
  },
14980
14957
  ...file.bibliography ? { Bibliography: {
14981
- data: xml(this.formatter.format(file.bibliography, {
14982
- fileData: file,
14983
- file,
14984
- stack: [],
14985
- viewWrapper: {
14986
- relationships: file.bibliography.relationships,
14987
- view: file.bibliography
14988
- }
14989
- }), {
14990
- declaration: {
14991
- encoding: "UTF-8",
14992
- standalone: "yes"
14993
- },
14994
- indent: prettify
14995
- }),
14958
+ data: this.formatter.formatToXml(file.bibliography, mkCtx({
14959
+ relationships: file.bibliography.relationships,
14960
+ view: file.bibliography
14961
+ })),
14996
14962
  path: "word/bibliography.xml"
14997
14963
  } } : {},
14998
14964
  ...file.charts.array.length > 0 ? { Charts: file.charts.array.flatMap((chartData, i) => [{
14999
- data: xml(this.formatter.format(chartData.chartSpace, {
15000
- fileData: file,
15001
- file,
15002
- stack: [],
15003
- viewWrapper: file.document
15004
- }), {
15005
- declaration: {
15006
- encoding: "UTF-8",
15007
- standalone: "yes"
15008
- },
15009
- indent: prettify
15010
- }),
14965
+ data: this.formatter.formatToXml(chartData.chartSpace, mkCtx(file.document)),
15011
14966
  path: `word/charts/chart${i + 1}.xml`
15012
14967
  }, {
15013
- data: xml({ Relationships: { _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" } } }, { declaration: {
15014
- encoding: "UTF-8",
15015
- standalone: "yes"
15016
- } }),
14968
+ data: xml({ Relationships: { _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" } } }),
15017
14969
  path: `word/charts/_rels/chart${i + 1}.xml.rels`
15018
14970
  }]) } : {},
15019
14971
  ...file.smartArts.array.length > 0 ? {
15020
14972
  DiagramData: file.smartArts.array.map((smartArtData, i) => ({
15021
- data: xml(this.formatter.format(smartArtData.dataModel, {
15022
- fileData: file,
15023
- file,
15024
- stack: [],
15025
- viewWrapper: file.document
15026
- }), {
15027
- declaration: {
15028
- encoding: "UTF-8",
15029
- standalone: "yes"
15030
- },
15031
- indent: prettify
15032
- }),
14973
+ data: this.formatter.formatToXml(smartArtData.dataModel, mkCtx(file.document)),
15033
14974
  path: `word/diagrams/data${i + 1}.xml`
15034
14975
  })),
15035
14976
  DiagramLayout: file.smartArts.array.map((smartArtData, i) => ({
@@ -15072,11 +15013,10 @@ const compiler = new Compiler();
15072
15013
  * ```typescript
15073
15014
  * const buffer = await Packer.toBuffer(doc);
15074
15015
  * const blob = await Packer.toBlob(doc);
15075
- * const buffer = await Packer.toBuffer(doc, PrettifyType.WITH_2_BLANKS);
15076
15016
  * ```
15077
15017
  */
15078
15018
  const Packer = createPacker({
15079
- compile: (file, prettify, overrides) => compiler.compile(file, prettify, overrides),
15019
+ compile: (file, overrides) => compiler.compile(file, overrides),
15080
15020
  mimeType: OoxmlMimeType.DOCX
15081
15021
  });
15082
15022
  //#endregion
@@ -15102,6 +15042,8 @@ init_media();
15102
15042
  init_paragraph();
15103
15043
  init_relationship();
15104
15044
  init_convenience_functions();
15045
+ /** Reusable TextEncoder (stateless, safe to share). */
15046
+ const encoder = new TextEncoder();
15105
15047
  /**
15106
15048
  * Document patching module for modifying existing .docx files.
15107
15049
  *
@@ -15111,7 +15053,7 @@ const formatter = new Formatter();
15111
15053
  const docxReplacer = createReplacer({
15112
15054
  ns: DOCX_NS,
15113
15055
  formatChild: (child, context) => {
15114
- return [toJson(xml(formatter.format(child, context))).elements[0]];
15056
+ return [xml2js(formatter.formatToXml(child, context), { captureSpacesBetweenElements: true }).elements[0]];
15115
15057
  }
15116
15058
  });
15117
15059
  /**
@@ -15135,7 +15077,7 @@ const compareByteArrays = (a, b) => {
15135
15077
  *
15136
15078
  * @publicApi
15137
15079
  */
15138
- const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, placeholderDelimiters = {
15080
+ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles = true, placeholderDelimiters = {
15139
15081
  end: "}}",
15140
15082
  start: "{{"
15141
15083
  }, recursive = true }) => {
@@ -15257,7 +15199,7 @@ const patchDocument = async ({ outputType, data, patches, keepOriginalStyles, pl
15257
15199
  appendContentType(contentTypesJson, "image/svg+xml", "svg");
15258
15200
  }
15259
15201
  const files = {};
15260
- for (const [key, value] of map) files[key] = textToUint8Array(js2xml(value));
15202
+ for (const [key, value] of map) files[key] = encoder.encode(js2xml(value));
15261
15203
  for (const [key, value] of binaryContentMap) files[key] = value;
15262
15204
  for (const { data: mediaData, fileName } of file.media.array) files[`word/media/${fileName}`] = mediaData instanceof Uint8Array ? mediaData : new Uint8Array(mediaData);
15263
15205
  return await zipAndConvert(files, outputType, OoxmlMimeType.DOCX);
@@ -18052,7 +17994,6 @@ var src_exports = /* @__PURE__ */ __exportAll({
18052
17994
  PositionalTabAlignment: () => PositionalTabAlignment,
18053
17995
  PositionalTabLeader: () => PositionalTabLeader,
18054
17996
  PositionalTabRelativeTo: () => PositionalTabRelativeTo,
18055
- PrettifyType: () => PrettifyType,
18056
17997
  RelativeHorizontalPosition: () => RelativeHorizontalPosition,
18057
17998
  RelativeVerticalPosition: () => RelativeVerticalPosition,
18058
17999
  RubyAlign: () => RubyAlign,
@@ -18278,6 +18219,6 @@ var src_exports = /* @__PURE__ */ __exportAll({
18278
18219
  __reExport(src_exports, file_exports);
18279
18220
  __reExport(src_exports, util_exports);
18280
18221
  //#endregion
18281
- export { AbstractNumbering, AlignmentType, AltChunk, AltChunkCollection, AnnotationReference, Attributes, BaseXmlComponent, Bdo, Bibliography, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, COLOR_CATEGORIES, CarriageReturn, CellMerge, CharacterSet, ChartCollection, ChartRun, ChartSpace, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DEFAULT_DRAWING_XML, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, Dir, File as Document, File, DocumentAttributeNamespaces, DocumentBackground, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EditGroupType, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, Endnotes, ExternalHyperlink, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FormFieldTextType, FractionType, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HyperlinkType, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LAYOUT_CATEGORIES, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math$1 as Math, MathAngledBrackets, MathBorderBox, MathBox, MathCurlyBrackets, MathDegree, MathDenominator, MathEqArr, MathFraction, MathFunction, MathFunctionName, MathGroupChr, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathMatrix, MathNumerator, MathParagraph, MathPhant, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, MoveFromRangeEnd, MoveFromRangeStart, MoveToRangeEnd, MoveToRangeStart, MovedFromTextRun, MovedToTextRun, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchType, PermEnd, PermStart, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabRelativeTo, PrettifyType, RelativeHorizontalPosition, RelativeVerticalPosition, RubyAlign, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, STYLE_CATEGORIES, SdtDateMappingType, SdtLock, SectionProperties, SectionPropertiesChange, SectionType, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SmartArtCollection, SmartArtRun, SoftHyphen, SpaceType, StructuredDocumentTagBlock, StructuredDocumentTagCell, StructuredDocumentTagContent, StructuredDocumentTagProperties, StructuredDocumentTagRow, StructuredDocumentTagRun, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SubDoc, SubDocCollection, SymbolRun, TDirection, Tab, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TablePropertyExceptions, TableRow, TableRowProperties, TableRowPropertiesChange, TextAlignmentType, TextBodyWrappingType, TextDirection, TextEffect, TextHorzOverflowType, TextRun, TextVertOverflowType, TextVerticalType, TextWrappingSide, TextWrappingType, Textbox, TextboxTightWrapType, ThematicBreak, UnderlineType, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND4, WidthType, WpgGroupRun, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, attrObj, bookmarkUniqueNumericIdGen, buildBorderObj, buildCellMergeObj, buildCnfStyleObj, buildDeletedTableCellObj, buildDeletedTableRowObj, buildDivIdObj, buildDocumentAttributes, buildEmphasisMarkObj, buildFramePropertiesObj, buildGridSpan, buildIndentObj, buildInsertedTableCellObj, buildInsertedTableRowObj, buildNumberProperties, buildOutlineLevelObj, buildParagraphBorders, buildParagraphProperties, buildRunFontsObj, buildRunProperties, buildShadingObj, buildSpacingObj, buildTabStopObj, buildTableBorders, buildTableCellBorders, buildTableFloatPropertiesObj, buildTableProperties, buildTableRowProperties, buildTableRowPropertiesChangeObj, buildTableWidthObj, buildTextDirection, buildThematicBreakObj, buildUnderlineObj, buildVerticalMerge, chartAttr, coerceMathJson, coerceSectionChild, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createBreak, createCnfStyle, createColumns, createDataModel, createDivId, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFormFieldData, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccent, createMathAccentCharacter, createMathAccentProperties, createMathBar, createMathBarProperties, createMathBase, createMathBorderBoxProperties, createMathBoxProperties, createMathControlProperties, createMathEqArrProperties, createMathFractionProperties, createMathFunctionProperties, createMathGroupChrProperties, createMathLimitLocation, createMathLimitLowProperties, createMathLimitUpperProperties, createMathMatrixProperties, createMathNAryProperties, createMathPhantProperties, createMathPreSubSuperScriptProperties, createMathProperties, createMathRunProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRuby, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableOverlap, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapThrough, createWrapTight, createWrapTopAndBottom, docPropertiesUniqueNumericIdGen, getColorXml, getLayoutXml, getStyleXml, hashedId, hpsMeasureObj, numberValObj, onOffObj, parseArchive, parseDocument, parseDocx, parseMathChildren, patchDetector, patchDocument, sectionMarginDefaults, sectionPageSizeDefaults, stringContainerObj, stringEnumValObj, stringValObj, uniqueId, uniqueNumericIdCreator, uniqueUuid, wrapEl };
18222
+ export { AbstractNumbering, AlignmentType, AltChunk, AltChunkCollection, AnnotationReference, Attributes, BaseXmlComponent, Bdo, Bibliography, Body, Bookmark, BookmarkEnd, BookmarkStart, Border, BorderStyle, BuilderElement, COLOR_CATEGORIES, CarriageReturn, CellMerge, CharacterSet, ChartCollection, ChartRun, ChartSpace, CheckBox, CheckBoxSymbolElement, CheckBoxUtil, Column, ColumnBreak, Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments, ConcreteHyperlink, ConcreteNumbering, ContinuationSeparator, DEFAULT_DRAWING_XML, DayLong, DayShort, DeletedTableCell, DeletedTableRow, DeletedTextRun, Dir, File as Document, File, DocumentAttributeNamespaces, DocumentBackground, DocumentDefaults, DocumentGridType, Drawing, DropCapType, EMPTY_OBJECT, EditGroupType, EmphasisMarkType, EmptyElement, EndnoteIdReference, EndnoteReference, EndnoteReferenceRun, Endnotes, ExternalHyperlink, FootNotes, Footer, FooterWrapper, FootnoteReference, FootnoteReferenceElement, FootnoteReferenceRun, FormFieldTextType, FractionType, FrameAnchorType, FrameWrap, GridSpan, Header, HeaderFooterReferenceType, HeaderFooterType, HeaderWrapper, HeadingLevel, HeightRule, HighlightColor, HorizontalPositionAlign, HorizontalPositionRelativeFrom, HyperlinkType, IgnoreIfEmptyXmlComponent, ImageRun, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, InsertedTableCell, InsertedTableRow, InsertedTextRun, InternalHyperlink, LAYOUT_CATEGORIES, LastRenderedPageBreak, LeaderType, Level, LevelBase, LevelForOverride, LevelFormat, LevelOverride, LevelSuffix, LineNumberRestartFormat, LineRuleType, Math$1 as Math, MathAngledBrackets, MathBorderBox, MathBox, MathCurlyBrackets, MathDegree, MathDenominator, MathEqArr, MathFraction, MathFunction, MathFunctionName, MathGroupChr, MathIntegral, MathLimit, MathLimitLower, MathLimitUpper, MathMatrix, MathNumerator, MathParagraph, MathPhant, MathPreSubSuperScript, MathRadical, MathRadicalProperties, MathRoundBrackets, MathRun, MathSquareBrackets, MathSubScript, MathSubSuperScript, MathSum, MathSuperScript, Media, MonthLong, MonthShort, MoveFromRangeEnd, MoveFromRangeStart, MoveToRangeEnd, MoveToRangeStart, MovedFromTextRun, MovedToTextRun, NextAttributeComponent, NoBreakHyphen, NumberFormat, NumberProperties, NumberedItemReference, NumberedItemReferenceFormat, Numbering, OverlapType, Packer, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder, PageBorders, PageBreak, PageBreakBefore, PageNumber, PageNumberElement, PageNumberSeparator, PageOrientation, PageReference, PageTextDirection, PageTextDirectionType, Paragraph, ParagraphProperties, ParagraphPropertiesChange, ParagraphPropertiesDefaults, ParagraphRunProperties, PatchType, PermEnd, PermStart, PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabRelativeTo, RelativeHorizontalPosition, RelativeVerticalPosition, RubyAlign, Run, RunProperties, RunPropertiesChange, RunPropertiesDefaults, STYLE_CATEGORIES, SdtDateMappingType, SdtLock, SectionProperties, SectionPropertiesChange, SectionType, Separator, SequentialIdentifier, ShadingType, SimpleField, SimpleMailMergeField, SmartArtCollection, SmartArtRun, SoftHyphen, SpaceType, StructuredDocumentTagBlock, StructuredDocumentTagCell, StructuredDocumentTagContent, StructuredDocumentTagProperties, StructuredDocumentTagRow, StructuredDocumentTagRun, StyleForCharacter, StyleForParagraph, StyleLevel, Styles, SubDoc, SubDocCollection, SymbolRun, TDirection, Tab, TabStopPosition, TabStopType, Table, TableAnchorType, TableBorders, TableCell, TableCellBorders, TableLayoutType, TableOfContents, TableProperties, TablePropertyExceptions, TableRow, TableRowProperties, TableRowPropertiesChange, TextAlignmentType, TextBodyWrappingType, TextDirection, TextEffect, TextHorzOverflowType, TextRun, TextVertOverflowType, TextVerticalType, TextWrappingSide, TextWrappingType, Textbox, TextboxTightWrapType, ThematicBreak, UnderlineType, VerticalAlignSection, VerticalAlignTable, VerticalAnchor, VerticalMerge, VerticalMergeRevisionType, VerticalMergeType, VerticalPositionAlign, VerticalPositionRelativeFrom, WORKAROUND2, WORKAROUND4, WidthType, WpgGroupRun, WpsShapeRun, XmlAttributeComponent, XmlComponent, YearLong, YearShort, abstractNumUniqueNumericIdGen, attrObj, bookmarkUniqueNumericIdGen, buildBorderObj, buildCellMergeObj, buildCnfStyleObj, buildDeletedTableCellObj, buildDeletedTableRowObj, buildDivIdObj, buildDocumentAttributes, buildEmphasisMarkObj, buildFramePropertiesObj, buildGridSpan, buildIndentObj, buildInsertedTableCellObj, buildInsertedTableRowObj, buildNumberProperties, buildOutlineLevelObj, buildParagraphBorders, buildParagraphProperties, buildRunFontsObj, buildRunProperties, buildShadingObj, buildSpacingObj, buildTabStopObj, buildTableBorders, buildTableCellBorders, buildTableFloatPropertiesObj, buildTableProperties, buildTableRowProperties, buildTableRowPropertiesChangeObj, buildTableWidthObj, buildTextDirection, buildThematicBreakObj, buildUnderlineObj, buildVerticalMerge, chartAttr, coerceMathJson, coerceSectionChild, concreteNumUniqueNumericIdGen, convertInchesToTwip, convertMillimetersToTwip, convertToXmlComponent, createAlignment, createBodyProperties, createBorderElement, createBreak, createCnfStyle, createColumns, createDataModel, createDivId, createDocumentGrid, createDotEmphasisMark, createEmphasisMark, createFormFieldData, createFrameProperties, createHeaderFooterReference, createHorizontalPosition, createIndent, createLineNumberType, createMathAccent, createMathAccentCharacter, createMathAccentProperties, createMathBar, createMathBarProperties, createMathBase, createMathBorderBoxProperties, createMathBoxProperties, createMathControlProperties, createMathEqArrProperties, createMathFractionProperties, createMathFunctionProperties, createMathGroupChrProperties, createMathLimitLocation, createMathLimitLowProperties, createMathLimitUpperProperties, createMathMatrixProperties, createMathNAryProperties, createMathPhantProperties, createMathPreSubSuperScriptProperties, createMathProperties, createMathRunProperties, createMathSubScriptElement, createMathSubScriptProperties, createMathSubSuperScriptProperties, createMathSuperScriptElement, createMathSuperScriptProperties, createOutlineLevel, createPageMargin, createPageNumberType, createPageSize, createParagraphStyle, createRuby, createRunFonts, createSectionType, createShading, createSimplePos, createSpacing, createStringElement, createTabStop, createTabStopItem, createTableFloatProperties, createTableLayout, createTableLook, createTableOverlap, createTableRowHeight, createTableWidthElement, createTransformation, createUnderline, createVerticalAlign, createVerticalPosition, createWrapNone, createWrapSquare, createWrapThrough, createWrapTight, createWrapTopAndBottom, docPropertiesUniqueNumericIdGen, getColorXml, getLayoutXml, getStyleXml, hashedId, hpsMeasureObj, numberValObj, onOffObj, parseArchive, parseDocument, parseDocx, parseMathChildren, patchDetector, patchDocument, sectionMarginDefaults, sectionPageSizeDefaults, stringContainerObj, stringEnumValObj, stringValObj, uniqueId, uniqueNumericIdCreator, uniqueUuid, wrapEl };
18282
18223
 
18283
18224
  //# sourceMappingURL=index.mjs.map