@office-open/pptx 0.6.4 → 0.6.6

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.
@@ -1,9 +1,9 @@
1
- import { i as __toCommonJS, n as __exportAll, r as __reExport, t as __esmMin } from "./chunk-090QGkrx.mjs";
2
- import { AppProperties, BaseXmlComponent, BuilderElement, EmptyElement, Formatter, ImportedXmlComponent, NextAttributeComponent, OoxmlMimeType, PrettifyType, Relationships, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, buildCorePropertiesXml, collectPlaceholderKeys, convertEmuToInches, convertEmuToPixels, convertEmuToPixels as convertEmuToPixels$1, convertEmuToPoints, convertInchesToEmu, convertPixelsToEmu, convertPixelsToEmu as convertPixelsToEmu$1, convertPointsToEmu, createPacker, escapeRegex, formatId, getReferencedMedia, hasPlaceholders, hashedId, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, stringContainerObj, uniqueId, uniqueNumericIdCreator, uniqueUuid, xsdRectAlignment, xsdStrikeStyle, xsdTextAlign, xsdTextAnchor, xsdTextCaps, xsdUnderlineStyle } from "@office-open/core";
1
+ import { i as __toCommonJS, n as __exportAll, r as __reExport, t as __esmMin } from "./chunk-DJOrGtkp.js";
2
+ import { AppProperties, BaseXmlComponent, BuilderElement, EmptyElement, Formatter, Formatter as Formatter$1, ImportedXmlComponent, NextAttributeComponent, OoxmlMimeType, PPTX_NS, Relationships, XmlComponent, ZIP_STORED_LEVEL, addSmartArtRelationships, appendContentType, buildCorePropertiesXml, collectPlaceholderKeys, compileMapping, convertEmuToInches, convertEmuToPixels, convertEmuToPixels as convertEmuToPixels$1, convertEmuToPoints, convertInchesToEmu, convertPixelsToEmu, convertPixelsToEmu as convertPixelsToEmu$1, convertPointsToEmu, createPacker, createReplacer, escapeRegex, formatId, getReferencedMedia, hasPlaceholders, hashedId, parseArchive, parseCorePropsElement, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, strFromU8, stringContainerObj, toJson, uniqueId, uniqueNumericIdCreator, uniqueUuid, unzipSync, xsdLineEndSize, xsdRectAlignment, xsdStrikeStyle, xsdTextAlign, xsdTextAnchor, xsdTextCaps, xsdUnderlineStyle, zipAndConvert } from "@office-open/core";
3
3
  import { BevelPresetType, CompoundLine, LineCap, LineJoin, PathShadeType, PenAlignment, PresetDash, PresetGeometry, PresetMaterialType, Stretch, TileFlipMode, buildFill, createBevel, createBlip, createBottomBevel, createColorElement, createColorTransforms, createEffectList, createEffectList as createEffectList$1, createGradientFill, createGradientStop, createGroupTransform2D, createOutline, createOutline as createOutline$1, createScene3D, createScene3D as createScene3D$1, createShape3D, createShape3D as createShape3D$1, createTransform2D, extractBlipFillMedia } from "@office-open/core/drawingml";
4
4
  import { ChartCollection, ChartSpace } from "@office-open/core/chart";
5
+ import { attr, attrBool, attrNum, children, colorAttr, escapeXml, findChild, findDeep, js2xml, textOf, xml, xml2js } from "@office-open/xml";
5
6
  import { DEFAULT_DRAWING_XML, SmartArtCollection, createDataModel, getColorXml, getLayoutXml, getStyleXml } from "@office-open/core/smartart";
6
- import { attr, attrBool, attrNum, children, colorAttr, findChild, findDeep, textOf, xml } from "@office-open/xml";
7
7
  import { toUint8Array } from "undio";
8
8
  export * from "@office-open/core/values";
9
9
  //#region src/file/drawingml/effects.ts
@@ -116,7 +116,7 @@ function createPptxEffectList(options) {
116
116
  return effectListOpts ? createEffectList$1(effectListOpts) : null;
117
117
  }
118
118
  var ReflectionAlignment;
119
- var init_effects = __esmMin((() => {
119
+ var init_effects = __esmMin(() => {
120
120
  ReflectionAlignment = {
121
121
  TOP_LEFT: "topLeft",
122
122
  TOP: "top",
@@ -128,23 +128,23 @@ var init_effects = __esmMin((() => {
128
128
  BOTTOM: "bottom",
129
129
  BOTTOM_RIGHT: "bottomRight"
130
130
  };
131
- }));
131
+ });
132
132
  //#endregion
133
133
  //#region src/file/drawingml/fill.ts
134
- var init_fill = __esmMin((() => {}));
134
+ var init_fill = __esmMin(() => {});
135
135
  //#endregion
136
136
  //#region src/file/xml-components/base.ts
137
- var init_base = __esmMin((() => {}));
137
+ var init_base = __esmMin(() => {});
138
138
  //#endregion
139
139
  //#region src/file/xml-components/index.ts
140
- var init_xml_components = __esmMin((() => {
140
+ var init_xml_components = __esmMin(() => {
141
141
  init_base();
142
- }));
142
+ });
143
143
  //#endregion
144
144
  //#region src/file/background/background.ts
145
145
  var background_exports = /* @__PURE__ */ __exportAll({ Background: () => Background });
146
146
  var Background, BackgroundProperties;
147
- var init_background = __esmMin((() => {
147
+ var init_background = __esmMin(() => {
148
148
  init_effects();
149
149
  init_fill();
150
150
  init_xml_components();
@@ -179,7 +179,7 @@ var init_background = __esmMin((() => {
179
179
  return obj;
180
180
  }
181
181
  };
182
- }));
182
+ });
183
183
  //#endregion
184
184
  //#region src/file/chart/chart-collection.ts
185
185
  init_background();
@@ -547,6 +547,9 @@ var GroupTransform2D = class extends XmlComponent {
547
547
  prepForXml(context) {
548
548
  return this.core["prepForXml"]?.(context);
549
549
  }
550
+ toXml(context) {
551
+ return this.core.toXml(context);
552
+ }
550
553
  };
551
554
  //#endregion
552
555
  //#region src/file/drawingml/group-shape-properties.ts
@@ -612,6 +615,9 @@ var EndParagraphRunProperties = class extends BuilderElement {
612
615
  prepForXml(_context) {
613
616
  return buildEndParagraphRunProperties(this.lang);
614
617
  }
618
+ toXml(_context) {
619
+ return `<a:endParaRPr lang="${this.lang}"/>`;
620
+ }
615
621
  };
616
622
  //#endregion
617
623
  //#region src/file/shape/paragraph/paragraph-properties.ts
@@ -679,6 +685,10 @@ var ParagraphProperties = class extends XmlComponent {
679
685
  prepForXml(_context) {
680
686
  return buildParagraphProperties(this.options);
681
687
  }
688
+ toXml(_context) {
689
+ const obj = buildParagraphProperties(this.options);
690
+ return obj ? xml(obj) : "";
691
+ }
682
692
  };
683
693
  //#endregion
684
694
  //#region src/file/shape/paragraph/run-properties.ts
@@ -776,6 +786,34 @@ var RunProperties = class extends XmlComponent {
776
786
  } }).prepForXml(context) ?? void 0;
777
787
  return buildRunProperties(opts, hyperlinkKey, fillObj, effectListObj, outlineObj);
778
788
  }
789
+ toXml(context) {
790
+ const opts = this.options;
791
+ let hyperlinkKey;
792
+ if (opts.hyperlink) {
793
+ hyperlinkKey = `hlink_${nextHyperlinkId++}`;
794
+ context.fileData?.hyperlinks?.addHyperlink(hyperlinkKey, opts.hyperlink.url, opts.hyperlink.tooltip);
795
+ }
796
+ let fillObj;
797
+ if (opts.fill !== void 0) fillObj = buildFill(opts.fill).prepForXml(context) ?? void 0;
798
+ let outlineObj;
799
+ if (opts.outline) outlineObj = createOutline$1({
800
+ width: 12700,
801
+ type: "solidFill",
802
+ color: { value: "000000" }
803
+ }).prepForXml(context) ?? void 0;
804
+ let effectListObj;
805
+ if (opts.shadow) effectListObj = createEffectList$1({ outerShadow: {
806
+ blurRadius: 50800,
807
+ distance: 38100,
808
+ direction: 27e5,
809
+ color: {
810
+ value: "000000",
811
+ transforms: { alpha: 4e4 }
812
+ }
813
+ } }).prepForXml(context) ?? void 0;
814
+ const obj = buildRunProperties(opts, hyperlinkKey, fillObj, effectListObj, outlineObj);
815
+ return obj ? xml(obj) : "";
816
+ }
779
817
  };
780
818
  //#endregion
781
819
  //#region src/file/shape/paragraph/run.ts
@@ -799,6 +837,27 @@ var TextRun = class extends XmlComponent {
799
837
  if (this.options.text) children.push({ "a:t": [this.options.text] });
800
838
  return { "a:r": children.length === 0 ? {} : children.length === 1 && "_attr" in children[0] ? children[0] : children };
801
839
  }
840
+ /**
841
+ * Fast path: simple properties (no hyperlink/fill/shadow/outline) skip
842
+ * RunProperties side effects and serialize directly.
843
+ * Complex path uses RunProperties.toXml() + direct text serialization.
844
+ */
845
+ toXml(context) {
846
+ const opts = this.options;
847
+ const hasRPr = RunProperties.hasProperties(opts);
848
+ if (!hasRPr || !opts.hyperlink && !opts.fill && !opts.shadow && !opts.outline) {
849
+ let body = "";
850
+ if (hasRPr) {
851
+ const rPrObj = buildRunProperties(opts);
852
+ if (rPrObj) body += xml(rPrObj);
853
+ }
854
+ if (opts.text) body += `<a:t>${escapeXml(opts.text)}</a:t>`;
855
+ return body.length === 0 ? "<a:r/>" : `<a:r>${body}</a:r>`;
856
+ }
857
+ let body = new RunProperties(opts).toXml(context);
858
+ if (opts.text) body += `<a:t>${escapeXml(opts.text)}</a:t>`;
859
+ return body ? `<a:r>${body}</a:r>` : "<a:r/>";
860
+ }
802
861
  };
803
862
  //#endregion
804
863
  //#region src/file/shape/paragraph/paragraph.ts
@@ -828,6 +887,19 @@ var Paragraph = class extends XmlComponent {
828
887
  children.push(buildEndParagraphRunProperties());
829
888
  return { "a:p": children };
830
889
  }
890
+ toXml(context) {
891
+ const parts = [];
892
+ const pPr = buildParagraphProperties(this.options.properties ?? {});
893
+ if (pPr) parts.push(xml(pPr));
894
+ if (this.options.text) parts.push(new TextRun(this.options.text).toXml(context));
895
+ if (this.options.children) for (const rawChild of this.options.children) {
896
+ const child = rawChild instanceof TextRun || rawChild instanceof XmlComponent ? rawChild : new TextRun(rawChild);
897
+ parts.push(child.toXml(context));
898
+ }
899
+ parts.push("<a:endParaRPr lang=\"en-US\"/>");
900
+ const body = parts.join("");
901
+ return body ? `<a:p>${body}</a:p>` : "<a:p/>";
902
+ }
831
903
  };
832
904
  //#endregion
833
905
  //#region src/file/table/table-cell-properties.ts
@@ -867,6 +939,10 @@ var TableCellProperties = class extends BaseXmlComponent {
867
939
  }
868
940
  return { "a:tcPr": children.length === 0 ? {} : children.length === 1 && "_attr" in children[0] ? children[0] : children };
869
941
  }
942
+ toXml(context) {
943
+ const obj = this.prepForXml(context);
944
+ return obj ? xml(obj) : "<a:tcPr/>";
945
+ }
870
946
  };
871
947
  //#endregion
872
948
  //#region src/file/table/table-cell.ts
@@ -921,6 +997,34 @@ var TableCell = class extends BaseXmlComponent {
921
997
  if (tcPrObj) children.push(tcPrObj);
922
998
  return { "a:tc": children };
923
999
  }
1000
+ toXml(context) {
1001
+ const opts = this.options;
1002
+ const parts = [];
1003
+ const tcAttrs = [];
1004
+ if (opts.columnSpan !== void 0 && opts.columnSpan > 1) tcAttrs.push(`gridSpan="${opts.columnSpan}"`);
1005
+ if (opts.rowSpan !== void 0 && opts.rowSpan > 1) tcAttrs.push(`rowSpan="${opts.rowSpan}"`);
1006
+ const tcAttrStr = tcAttrs.length > 0 ? ` ${tcAttrs.join(" ")}` : "";
1007
+ const txParts = [];
1008
+ const margins = opts.margins;
1009
+ const bodyPrAttrs = [];
1010
+ if (margins?.top !== void 0) bodyPrAttrs.push(`tIns="${margins.top}"`);
1011
+ if (margins?.bottom !== void 0) bodyPrAttrs.push(`bIns="${margins.bottom}"`);
1012
+ if (margins?.left !== void 0) bodyPrAttrs.push(`lIns="${margins.left}"`);
1013
+ if (margins?.right !== void 0) bodyPrAttrs.push(`rIns="${margins.right}"`);
1014
+ const bodyPrStr = bodyPrAttrs.length > 0 ? ` ${bodyPrAttrs.join(" ")}` : "";
1015
+ txParts.push(`<a:bodyPr${bodyPrStr}/>`);
1016
+ txParts.push("<a:lstStyle/>");
1017
+ if (this.paragraphs) for (const p of this.paragraphs) txParts.push(p.toXml(context));
1018
+ else txParts.push("<a:p/>");
1019
+ parts.push(`<a:txBody>${txParts.join("")}</a:txBody>`);
1020
+ const tcPr = new TableCellProperties({
1021
+ fill: opts.fill,
1022
+ borders: opts.borders,
1023
+ verticalAlign: opts.verticalAlign ? xsdTextAnchor.to(opts.verticalAlign) : void 0
1024
+ });
1025
+ parts.push(tcPr.toXml(context));
1026
+ return `<a:tc${tcAttrStr}>${parts.join("")}</a:tc>`;
1027
+ }
924
1028
  };
925
1029
  //#endregion
926
1030
  //#region src/file/shape/text-body.ts
@@ -975,6 +1079,18 @@ var TextBody = class extends XmlComponent {
975
1079
  }
976
1080
  return { "p:txBody": children };
977
1081
  }
1082
+ toXml(context) {
1083
+ const parts = [];
1084
+ parts.push(xml(buildBodyPr(this.options)));
1085
+ parts.push("<a:lstStyle/>");
1086
+ if (this.options.children) for (const p of this.options.children) {
1087
+ const para = typeof p === "string" ? new Paragraph({ children: [new TextRun({ text: p })] }) : p instanceof Paragraph ? p : new Paragraph(p);
1088
+ parts.push(para.toXml(context));
1089
+ }
1090
+ else if (this.options.text !== void 0) parts.push(new Paragraph({ children: [new TextRun({ text: this.options.text })] }).toXml(context));
1091
+ else parts.push(new Paragraph().toXml(context));
1092
+ return `<p:txBody>${parts.join("")}</p:txBody>`;
1093
+ }
978
1094
  };
979
1095
  //#endregion
980
1096
  //#region src/file/notes/notes-slide.ts
@@ -1178,13 +1294,16 @@ var PresentationProperties = class PresentationProperties extends ImportedXmlCom
1178
1294
  key;
1179
1295
  constructor(showOptions) {
1180
1296
  super("p:presentationPr");
1181
- this.key = showOptions ? JSON.stringify(showOptions) : "";
1297
+ this.key = showOptions ? presPropsKey(showOptions) : "";
1182
1298
  if (!PresentationProperties.cache.has(this.key)) PresentationProperties.cache.set(this.key, ImportedXmlComponent.fromXmlString(buildPresPropsXml(showOptions)));
1183
1299
  }
1184
1300
  prepForXml() {
1185
1301
  return PresentationProperties.cache.get(this.key).prepForXml({ stack: [] });
1186
1302
  }
1187
1303
  };
1304
+ function presPropsKey(o) {
1305
+ return `l${o.loop ? 1 : 0}k${o.kiosk ? 1 : 0}n${o.showNarration ? 1 : 0}t${o.useTimings ? 1 : 0}`;
1306
+ }
1188
1307
  //#endregion
1189
1308
  //#region src/file/presentation/presentation.ts
1190
1309
  init_xml_components();
@@ -1309,6 +1428,9 @@ var Transform2D = class extends XmlComponent {
1309
1428
  prepForXml(context) {
1310
1429
  return this.core["prepForXml"]?.(context);
1311
1430
  }
1431
+ toXml(context) {
1432
+ return this.core.toXml(context);
1433
+ }
1312
1434
  };
1313
1435
  //#endregion
1314
1436
  //#region src/util/position.ts
@@ -1319,8 +1441,8 @@ var Transform2D = class extends XmlComponent {
1319
1441
  /**
1320
1442
  * Converts pixel position/size values to EMU, defaulting missing values to 0.
1321
1443
  *
1322
- * Used by components that always need a transform (ChartFrame, Picture,
1323
- * TableFrame, SmartArtFrame, MediaFrameBase, etc.).
1444
+ * Used by components that always need a transform (Chart, Picture,
1445
+ * Table, SmartArt, MediaFrameBase, etc.).
1324
1446
  */
1325
1447
  function emuPosition(opts) {
1326
1448
  return {
@@ -1346,33 +1468,41 @@ function emuPositionOptional(opts) {
1346
1468
  //#endregion
1347
1469
  //#region src/file/chart/chart-frame.ts
1348
1470
  init_xml_components();
1349
- let nextChartFrameId = 2048;
1471
+ let nextChartId = 2048;
1350
1472
  /**
1351
1473
  * p:graphicFrame — Slide-level graphic frame wrapping a chart.
1352
1474
  *
1353
1475
  * The chart is stored as a separate part (ppt/charts/chart{n}.xml)
1354
1476
  * and referenced via a relationship ID placeholder {chart:key}.
1355
1477
  */
1356
- var ChartFrame = class extends XmlComponent {
1478
+ var Chart = class extends XmlComponent {
1357
1479
  chartOptions;
1358
1480
  chartKey;
1359
1481
  constructor(options) {
1360
1482
  super("p:graphicFrame");
1361
1483
  this.chartOptions = options;
1362
- this.chartKey = `chart_${nextChartFrameId++}`;
1363
- const id = nextChartFrameId++;
1484
+ this.chartKey = `chart_${nextChartId++}`;
1485
+ const id = nextChartId++;
1364
1486
  this.root.push(new GraphicFrameNonVisual$2(id));
1365
1487
  this.root.push(new Transform2D({ ...emuPosition(options) }, "p"));
1366
1488
  this.root.push(new ChartGraphic(this.chartKey));
1367
1489
  }
1368
- prepForXml(context) {
1490
+ /** Register chart data with the File's Chart collection. */
1491
+ registerChart(context) {
1369
1492
  const file = context.fileData;
1370
1493
  if (file?.charts) file.charts.addChart(this.chartKey, {
1371
1494
  chartSpace: new ChartSpace(this.chartOptions),
1372
1495
  key: this.chartKey
1373
1496
  });
1497
+ }
1498
+ prepForXml(context) {
1499
+ this.registerChart(context);
1374
1500
  return super.prepForXml(context);
1375
1501
  }
1502
+ toXml(context) {
1503
+ this.registerChart(context);
1504
+ return super.toXml(context);
1505
+ }
1376
1506
  };
1377
1507
  var GraphicFrameNonVisual$2 = class extends XmlComponent {
1378
1508
  constructor(id) {
@@ -1572,12 +1702,20 @@ var MediaFrameBase = class extends XmlComponent {
1572
1702
  children: [new Transform2D({ ...emuPosition(options) }), new PresetGeometry({ preset: "rect" })]
1573
1703
  }));
1574
1704
  }
1575
- prepForXml(context) {
1705
+ /** Register media data with the File's Media collection. */
1706
+ registerMedia(context) {
1576
1707
  const file = context.fileData;
1577
1708
  if (this.posterData) file?.media.addImage(this.posterData.fileName, this.posterData);
1578
1709
  file?.media.addMedia(this.mediaData.fileName, this.mediaData);
1710
+ }
1711
+ prepForXml(context) {
1712
+ this.registerMedia(context);
1579
1713
  return super.prepForXml(context);
1580
1714
  }
1715
+ toXml(context) {
1716
+ this.registerMedia(context);
1717
+ return super.toXml(context);
1718
+ }
1581
1719
  };
1582
1720
  //#endregion
1583
1721
  //#region src/file/media/audio-frame.ts
@@ -1594,7 +1732,7 @@ var AudioFrame = class AudioFrame extends MediaFrameBase {
1594
1732
  const mediaFileName = `${(options.name ?? `Audio ${id}`).replace(/\s+/g, "_")}.${options.type}`;
1595
1733
  super(options, id, mediaFileName, {
1596
1734
  extUri: MEDIA_EXT_URI$1,
1597
- cNvPrPrefix: "a"
1735
+ cNvPrPrefix: "p"
1598
1736
  });
1599
1737
  }
1600
1738
  };
@@ -1711,12 +1849,12 @@ var VideoFrame = class VideoFrame extends MediaFrameBase {
1711
1849
  //#region src/file/drawingml/blip-fill.ts
1712
1850
  init_xml_components();
1713
1851
  /**
1714
- * a:blipFill — Image fill with stretch mode.
1852
+ * p:blipFill — Image fill with stretch mode (within p:pic context).
1715
1853
  * Uses core createBlip for the blip element.
1716
1854
  */
1717
1855
  var BlipFill = class extends XmlComponent {
1718
1856
  constructor(fileName) {
1719
- super("a:blipFill");
1857
+ super("p:blipFill");
1720
1858
  this.root.push(createBlip({ referenceId: fileName }));
1721
1859
  this.root.push(new Stretch());
1722
1860
  }
@@ -1725,12 +1863,11 @@ var BlipFill = class extends XmlComponent {
1725
1863
  //#region src/file/drawingml/non-visual-picture-props.ts
1726
1864
  init_xml_components();
1727
1865
  /**
1728
- * a:cNvPicPr — Non-visual picture drawing properties.
1729
- * Uses a: prefix (DrawingML type) but referenced via p:cNvPicPr in PML context.
1866
+ * p:cNvPicPr — Non-visual picture drawing properties (within p:pic context).
1730
1867
  */
1731
1868
  var NonVisualPictureProperties = class extends EmptyElement {
1732
1869
  constructor() {
1733
- super("a:cNvPicPr");
1870
+ super("p:cNvPicPr");
1734
1871
  }
1735
1872
  };
1736
1873
  //#endregion
@@ -1743,7 +1880,7 @@ var PictureNonVisual = class extends XmlComponent {
1743
1880
  constructor(id, name) {
1744
1881
  super("p:nvPicPr");
1745
1882
  this.root.push(new BuilderElement({
1746
- name: "a:cNvPr",
1883
+ name: "p:cNvPr",
1747
1884
  attributes: {
1748
1885
  id: {
1749
1886
  key: "id",
@@ -1769,7 +1906,7 @@ init_xml_components();
1769
1906
  /**
1770
1907
  * p:pic — A picture on a slide.
1771
1908
  *
1772
- * Registers image with Media collection via prepForXml.
1909
+ * Registers image with Media collection via prepForXml/toXml.
1773
1910
  * The ImageReplacer replaces `{fileName}` placeholder with actual rId.
1774
1911
  */
1775
1912
  var Picture = class Picture extends XmlComponent {
@@ -1802,10 +1939,18 @@ var Picture = class Picture extends XmlComponent {
1802
1939
  children: [new Transform2D({ ...emuPosition(options) }), new PresetGeometry({ preset: "rect" })]
1803
1940
  }));
1804
1941
  }
1805
- prepForXml(context) {
1942
+ /** Register image with the File's Media collection. */
1943
+ registerMedia(context) {
1806
1944
  context.fileData?.media.addImage(this.imageData.fileName, this.imageData);
1945
+ }
1946
+ prepForXml(context) {
1947
+ this.registerMedia(context);
1807
1948
  return super.prepForXml(context);
1808
1949
  }
1950
+ toXml(context) {
1951
+ this.registerMedia(context);
1952
+ return super.toXml(context);
1953
+ }
1809
1954
  };
1810
1955
  //#endregion
1811
1956
  //#region src/file/shape/group-shape.ts
@@ -1864,6 +2009,22 @@ var GroupShape = class GroupShape extends BaseXmlComponent {
1864
2009
  }
1865
2010
  return { "p:grpSp": children };
1866
2011
  }
2012
+ toXml(context) {
2013
+ const opts = this.options;
2014
+ const id = this.id;
2015
+ const parts = [];
2016
+ parts.push(`<p:nvGrpSpPr><p:cNvPr id="${id}" name="Group ${id}"/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>`);
2017
+ const xfrmAttrs = [];
2018
+ if (opts.flipHorizontal !== void 0) xfrmAttrs.push(`flipH="${opts.flipHorizontal ? 1 : 0}"`);
2019
+ if (opts.rotation !== void 0) xfrmAttrs.push(`rot="${opts.rotation}"`);
2020
+ const xfrmAttrStr = xfrmAttrs.length > 0 ? ` ${xfrmAttrs.join(" ")}` : "";
2021
+ parts.push(`<p:grpSpPr><a:xfrm${xfrmAttrStr}><a:off x="${convertPixelsToEmu$1(opts.x ?? 0)}" y="${convertPixelsToEmu$1(opts.y ?? 0)}"/><a:ext cx="${convertPixelsToEmu$1(opts.width ?? 0)}" cy="${convertPixelsToEmu$1(opts.height ?? 0)}"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>`);
2022
+ for (const rawChild of opts.children) {
2023
+ const s = coerceChild(rawChild).toXml(context);
2024
+ if (s) parts.push(s);
2025
+ }
2026
+ return `<p:grpSp>${parts.join("")}</p:grpSp>`;
2027
+ }
1867
2028
  };
1868
2029
  //#endregion
1869
2030
  //#region src/file/drawingml/non-visual-shape-props.ts
@@ -1894,16 +2055,11 @@ const ARROWHEAD_MAP = {
1894
2055
  oval: "oval",
1895
2056
  open: "arrow"
1896
2057
  };
1897
- const ARROWHEAD_SIZE_MAP = {
1898
- sm: "small",
1899
- med: "medium",
1900
- lg: "large"
1901
- };
1902
2058
  function toCoreLineEnd(type, width, length) {
1903
2059
  return {
1904
2060
  type: ARROWHEAD_MAP[type] ?? "triangle",
1905
- ...width ? { width: ARROWHEAD_SIZE_MAP[width] } : {},
1906
- ...length ? { length: ARROWHEAD_SIZE_MAP[length] } : {}
2061
+ ...width ? { width } : {},
2062
+ ...length ? { length } : {}
1907
2063
  };
1908
2064
  }
1909
2065
  /**
@@ -2189,6 +2345,10 @@ var ShapeProperties = class extends BaseXmlComponent {
2189
2345
  }
2190
2346
  return { "p:spPr": children };
2191
2347
  }
2348
+ toXml(context) {
2349
+ const obj = this.prepForXml(context);
2350
+ return obj ? xml(obj) : "";
2351
+ }
2192
2352
  };
2193
2353
  //#endregion
2194
2354
  //#region src/file/shape/shape.ts
@@ -2251,15 +2411,41 @@ var Shape = class Shape extends XmlComponent {
2251
2411
  if (txBodyObj) children.push(txBodyObj);
2252
2412
  return { "p:sp": children };
2253
2413
  }
2414
+ toXml(context) {
2415
+ const opts = this.options;
2416
+ const id = this.shapeId;
2417
+ const name = opts.name ?? `Shape ${id}`;
2418
+ const parts = [];
2419
+ let nvPrContent = "<p:nvPr/>";
2420
+ if (opts.placeholder) {
2421
+ const phAttrs = [`type="${opts.placeholder}"`];
2422
+ if (opts.placeholderIndex !== void 0) phAttrs.push(`idx="${opts.placeholderIndex}"`);
2423
+ nvPrContent = `<p:nvPr><p:ph ${phAttrs.join(" ")}/></p:nvPr>`;
2424
+ }
2425
+ parts.push(`<p:nvSpPr><p:cNvPr id="${id}" name="${escapeXml(name)}"/><p:cNvSpPr/>${nvPrContent}</p:nvSpPr>`);
2426
+ const spPrXml = new ShapeProperties({
2427
+ ...emuPositionOptional(opts),
2428
+ geometry: opts.geometry,
2429
+ fill: opts.fill,
2430
+ outline: opts.outline,
2431
+ effects: opts.effects,
2432
+ flipHorizontal: opts.flipHorizontal,
2433
+ rotation: opts.rotation
2434
+ }).toXml(context);
2435
+ if (spPrXml) parts.push(spPrXml);
2436
+ const txBody = new TextBody(opts.textBody ?? {});
2437
+ parts.push(txBody.toXml(context));
2438
+ return `<p:sp>${parts.join("")}</p:sp>`;
2439
+ }
2254
2440
  };
2255
2441
  //#endregion
2256
2442
  //#region src/file/smartart/smartart-frame.ts
2257
2443
  init_xml_components();
2258
- let nextSmartArtFrameId = 1024;
2444
+ let nextSmartArtId = 1024;
2259
2445
  /**
2260
2446
  * p:graphicFrame — Slide-level graphic frame wrapping a SmartArt diagram.
2261
2447
  */
2262
- var SmartArtFrame = class extends XmlComponent {
2448
+ var SmartArt = class extends XmlComponent {
2263
2449
  smartArtKey;
2264
2450
  dataModel;
2265
2451
  layoutId;
@@ -2267,18 +2453,19 @@ var SmartArtFrame = class extends XmlComponent {
2267
2453
  colorId;
2268
2454
  constructor(options) {
2269
2455
  super("p:graphicFrame");
2270
- this.smartArtKey = `smartart_${nextSmartArtFrameId++}`;
2456
+ this.smartArtKey = `smartart_${nextSmartArtId++}`;
2271
2457
  this.layoutId = options.layout ?? "default";
2272
2458
  this.styleId = options.style ?? "simple1";
2273
2459
  this.colorId = options.color ?? "accent1_2";
2274
2460
  this.dataModel = createDataModel(options.nodes, this.layoutId, this.styleId, this.colorId);
2275
- const id = nextSmartArtFrameId++;
2461
+ const id = nextSmartArtId++;
2276
2462
  const name = options.name ?? `Diagram ${id}`;
2277
2463
  this.root.push(new GraphicFrameNonVisual$1(id, name));
2278
2464
  this.root.push(new Transform2D({ ...emuPosition(options) }, "p"));
2279
2465
  this.root.push(new SmartArtGraphic(this.smartArtKey));
2280
2466
  }
2281
- prepForXml(context) {
2467
+ /** Register SmartArt data with the File's SmartArt collection. */
2468
+ registerSmartArt(context) {
2282
2469
  const file = context.fileData;
2283
2470
  if (file?.smartArts) file.smartArts.addSmartArt(this.smartArtKey, {
2284
2471
  key: this.smartArtKey,
@@ -2287,8 +2474,15 @@ var SmartArtFrame = class extends XmlComponent {
2287
2474
  style: this.styleId,
2288
2475
  color: this.colorId
2289
2476
  });
2477
+ }
2478
+ prepForXml(context) {
2479
+ this.registerSmartArt(context);
2290
2480
  return super.prepForXml(context);
2291
2481
  }
2482
+ toXml(context) {
2483
+ this.registerSmartArt(context);
2484
+ return super.toXml(context);
2485
+ }
2292
2486
  };
2293
2487
  var GraphicFrameNonVisual$1 = class extends XmlComponent {
2294
2488
  constructor(id, name) {
@@ -2385,6 +2579,9 @@ var Graphic = class extends BaseXmlComponent {
2385
2579
  if (tableObj) graphicDataChildren.push(tableObj);
2386
2580
  return { "a:graphic": [{ "a:graphicData": graphicDataChildren }] };
2387
2581
  }
2582
+ toXml(context) {
2583
+ return `<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">${this.table.toXml(context)}</a:graphicData></a:graphic>`;
2584
+ }
2388
2585
  };
2389
2586
  //#endregion
2390
2587
  //#region src/file/table/graphic-frame-non-visual.ts
@@ -2439,6 +2636,9 @@ var TableGrid = class extends BaseXmlComponent {
2439
2636
  prepForXml(_context) {
2440
2637
  return { "a:tblGrid": this.columnWidths.map((w) => ({ "a:gridCol": { _attr: { w } } })) };
2441
2638
  }
2639
+ toXml(_context) {
2640
+ return `<a:tblGrid>${this.columnWidths.map((w) => `<a:gridCol w="${w}"/>`).join("")}</a:tblGrid>`;
2641
+ }
2442
2642
  };
2443
2643
  //#endregion
2444
2644
  //#region src/file/table/table-properties.ts
@@ -2465,6 +2665,18 @@ var TableProperties = class extends BaseXmlComponent {
2465
2665
  if (opts.bandCol !== void 0) attrs.bandCol = opts.bandCol ? 1 : 0;
2466
2666
  return { "a:tblPr": Object.keys(attrs).length > 0 ? { _attr: attrs } : {} };
2467
2667
  }
2668
+ toXml(_context) {
2669
+ if (!this.options) return "<a:tblPr/>";
2670
+ const opts = this.options;
2671
+ const attrs = [];
2672
+ if (opts.firstRow !== void 0) attrs.push(`firstRow="${opts.firstRow ? 1 : 0}"`);
2673
+ if (opts.lastRow !== void 0) attrs.push(`lastRow="${opts.lastRow ? 1 : 0}"`);
2674
+ if (opts.bandRow !== void 0) attrs.push(`bandRow="${opts.bandRow ? 1 : 0}"`);
2675
+ if (opts.firstCol !== void 0) attrs.push(`firstCol="${opts.firstCol ? 1 : 0}"`);
2676
+ if (opts.lastCol !== void 0) attrs.push(`lastCol="${opts.lastCol ? 1 : 0}"`);
2677
+ if (opts.bandCol !== void 0) attrs.push(`bandCol="${opts.bandCol ? 1 : 0}"`);
2678
+ return attrs.length === 0 ? "<a:tblPr/>" : `<a:tblPr ${attrs.join(" ")}/>`;
2679
+ }
2468
2680
  };
2469
2681
  //#endregion
2470
2682
  //#region src/file/table/table-row.ts
@@ -2488,6 +2700,12 @@ var TableRow = class extends BaseXmlComponent {
2488
2700
  }
2489
2701
  return { "a:tr": children };
2490
2702
  }
2703
+ toXml(context) {
2704
+ const h = this.options.height ?? 0;
2705
+ const parts = [];
2706
+ for (const cell of this.options.cells) parts.push(new TableCell(cell).toXml(context));
2707
+ return `<a:tr h="${h}">${parts.join("")}</a:tr>`;
2708
+ }
2491
2709
  };
2492
2710
  //#endregion
2493
2711
  //#region src/file/table/table.ts
@@ -2496,7 +2714,7 @@ init_xml_components();
2496
2714
  * a:tbl — DrawingML table element.
2497
2715
  * Lazy: stores options, builds IXmlableObject in prepForXml.
2498
2716
  */
2499
- var Table = class extends BaseXmlComponent {
2717
+ var DrawingTable = class extends BaseXmlComponent {
2500
2718
  options;
2501
2719
  constructor(options) {
2502
2720
  super("a:tbl");
@@ -2540,6 +2758,43 @@ var Table = class extends BaseXmlComponent {
2540
2758
  }
2541
2759
  return { "a:tbl": children };
2542
2760
  }
2761
+ toXml(context) {
2762
+ const opts = this.options;
2763
+ const parts = [];
2764
+ const tblPr = new TableProperties({
2765
+ firstRow: opts.firstRow,
2766
+ lastRow: opts.lastRow,
2767
+ bandRow: opts.bandRow,
2768
+ firstCol: opts.firstCol,
2769
+ lastCol: opts.lastCol,
2770
+ bandCol: opts.bandCol
2771
+ });
2772
+ parts.push(tblPr.toXml(context));
2773
+ const colWidths = opts.columnWidths && opts.columnWidths.length > 0 ? [...opts.columnWidths] : Array.from({ length: opts.rows[0]?.cells.length ?? 1 }, () => 0);
2774
+ parts.push(new TableGrid(colWidths).toXml(context));
2775
+ const tb = opts.borders;
2776
+ const rowCount = opts.rows.length;
2777
+ for (let ri = 0; ri < rowCount; ri++) {
2778
+ const row = opts.rows[ri];
2779
+ const colCount = row.cells.length;
2780
+ const cells = tb ? row.cells.map((cell, ci) => {
2781
+ const b = { ...cell.borders };
2782
+ if (ri === 0 && tb.top && !b.top) b.top = tb.top;
2783
+ if (ri === rowCount - 1 && tb.bottom && !b.bottom) b.bottom = tb.bottom;
2784
+ if (ci === 0 && tb.left && !b.left) b.left = tb.left;
2785
+ if (ci === colCount - 1 && tb.right && !b.right) b.right = tb.right;
2786
+ return Object.keys(b).length === 0 ? cell : {
2787
+ ...cell,
2788
+ borders: b
2789
+ };
2790
+ }) : row.cells;
2791
+ parts.push(new TableRow({
2792
+ ...row,
2793
+ cells
2794
+ }).toXml(context));
2795
+ }
2796
+ return `<a:tbl>${parts.join("")}</a:tbl>`;
2797
+ }
2543
2798
  };
2544
2799
  //#endregion
2545
2800
  //#region src/file/table/table-frame.ts
@@ -2549,12 +2804,12 @@ init_xml_components();
2549
2804
  *
2550
2805
  * x/y/width/height accept pixel values, converted to EMUs internally.
2551
2806
  */
2552
- var TableFrame = class extends XmlComponent {
2807
+ var Table = class extends XmlComponent {
2553
2808
  constructor(options) {
2554
2809
  super("p:graphicFrame");
2555
2810
  this.root.push(new GraphicFrameNonVisual());
2556
2811
  this.root.push(new Transform2D({ ...emuPosition(options) }, "p"));
2557
- const table = new Table(options);
2812
+ const table = new DrawingTable(options);
2558
2813
  this.root.push(new Graphic(table));
2559
2814
  }
2560
2815
  };
@@ -2565,14 +2820,14 @@ function coerceChild(child) {
2565
2820
  if (child instanceof BaseXmlComponent) return child;
2566
2821
  if ("shape" in child) return new Shape(child.shape);
2567
2822
  if ("picture" in child) return new Picture(child.picture);
2568
- if ("table" in child) return new TableFrame(child.table);
2569
- if ("chart" in child) return new ChartFrame(child.chart);
2823
+ if ("table" in child) return new Table(child.table);
2824
+ if ("chart" in child) return new Chart(child.chart);
2570
2825
  if ("line" in child) return new LineShape(child.line);
2571
2826
  if ("connector" in child) return new ConnectorShape(child.connector);
2572
2827
  if ("video" in child) return new VideoFrame(child.video);
2573
2828
  if ("audio" in child) return new AudioFrame(child.audio);
2574
2829
  if ("group" in child) return new GroupShape(child.group);
2575
- if ("smartart" in child) return new SmartArtFrame(child.smartart);
2830
+ if ("smartart" in child) return new SmartArt(child.smartart);
2576
2831
  throw new Error("Unknown slide child type");
2577
2832
  }
2578
2833
  function coerceMasterChild(child) {
@@ -4130,6 +4385,37 @@ var Slide = class extends XmlComponent {
4130
4385
  }
4131
4386
  return { "p:sld": children };
4132
4387
  }
4388
+ toXml(context) {
4389
+ const parts = [];
4390
+ parts.push("<p:sld xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">");
4391
+ parts.push("<p:cSld>");
4392
+ if (this.background) {
4393
+ const bgObj = this.background.prepForXml(context);
4394
+ if (bgObj) parts.push(xml(bgObj));
4395
+ }
4396
+ parts.push("<p:spTree>");
4397
+ parts.push("<p:nvGrpSpPr><p:cNvPr id=\"1\" name=\"\"/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>");
4398
+ parts.push("<p:grpSpPr><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"0\" cy=\"0\"/><a:chOff x=\"0\" y=\"0\"/><a:chExt cx=\"0\" cy=\"0\"/></a:xfrm></p:grpSpPr>");
4399
+ const coercedChildren = this.children.map(coerceChild);
4400
+ for (const child of coercedChildren) {
4401
+ const s = child.toXml(context);
4402
+ if (s) parts.push(s);
4403
+ }
4404
+ parts.push("</p:spTree>");
4405
+ parts.push("</p:cSld>");
4406
+ parts.push("<p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr>");
4407
+ if (this.transition) {
4408
+ const transObj = buildTransition(this.transition);
4409
+ if (transObj) parts.push(xml(transObj));
4410
+ }
4411
+ const animations = collectAnimations(coercedChildren);
4412
+ if (animations.length > 0) {
4413
+ const timingObj = new SlideTiming(animations).prepForXml(context);
4414
+ if (timingObj) parts.push(xml(timingObj));
4415
+ }
4416
+ parts.push("</p:sld>");
4417
+ return parts.join("");
4418
+ }
4133
4419
  };
4134
4420
  //#endregion
4135
4421
  //#region src/file/table-styles.ts
@@ -4232,13 +4518,21 @@ var DefaultTheme = class DefaultTheme extends ImportedXmlComponent {
4232
4518
  cacheKey;
4233
4519
  constructor(options) {
4234
4520
  super("a:theme");
4235
- this.cacheKey = options ? JSON.stringify(options) : "";
4521
+ this.cacheKey = options ? themeKey(options) : "";
4236
4522
  if (!DefaultTheme.cache.has(this.cacheKey)) DefaultTheme.cache.set(this.cacheKey, ImportedXmlComponent.fromXmlString(buildThemeXml(options)));
4237
4523
  }
4238
4524
  prepForXml() {
4239
4525
  return DefaultTheme.cache.get(this.cacheKey).prepForXml({ stack: [] });
4240
4526
  }
4527
+ toXml(context) {
4528
+ return DefaultTheme.cache.get(this.cacheKey).toXml(context);
4529
+ }
4241
4530
  };
4531
+ function themeKey(o) {
4532
+ const c = o.colors;
4533
+ const f = o.fonts;
4534
+ return `n${o.name ?? ""}c${c?.dark1 ?? ""}${c?.light1 ?? ""}${c?.dark2 ?? ""}${c?.light2 ?? ""}${c?.accent1 ?? ""}${c?.accent2 ?? ""}${c?.accent3 ?? ""}${c?.accent4 ?? ""}${c?.accent5 ?? ""}${c?.accent6 ?? ""}${c?.hyperlink ?? ""}${c?.followedHyperlink ?? ""}f${f?.majorFont ?? ""}${f?.minorFont ?? ""}${f?.majorFontAsian ?? ""}${f?.minorFontAsian ?? ""}`;
4535
+ }
4242
4536
  //#endregion
4243
4537
  //#region src/file/view-properties.ts
4244
4538
  init_xml_components();
@@ -4856,29 +5150,27 @@ function collectRefs(xml, prefix, mediaArray) {
4856
5150
  }
4857
5151
  //#endregion
4858
5152
  //#region src/export/packer/next-compiler.ts
5153
+ /** Reusable TextEncoder (stateless, safe to share). */
5154
+ const encoder$1 = new TextEncoder();
4859
5155
  var Compiler = class {
4860
- formatter = new Formatter();
4861
- compile(file, prettifyXml, overrides = []) {
5156
+ formatter = new Formatter$1();
5157
+ compile(file, overrides = []) {
4862
5158
  const declaration = true;
4863
- const indent = prettifyXml;
4864
5159
  const context = {
4865
5160
  fileData: file,
4866
5161
  stack: []
4867
5162
  };
4868
5163
  const mapping = {
4869
5164
  AppProperties: {
4870
- data: xml(this.formatter.format(file.appProperties, context), { declaration }),
5165
+ data: this.formatter.formatToXml(file.appProperties, context, declaration),
4871
5166
  path: "docProps/app.xml"
4872
5167
  },
4873
5168
  Properties: {
4874
- data: xml(this.formatter.format(file.coreProperties, context), {
4875
- declaration,
4876
- indent
4877
- }),
5169
+ data: this.formatter.formatToXml(file.coreProperties, context, declaration),
4878
5170
  path: "docProps/core.xml"
4879
5171
  },
4880
5172
  FileRelationships: {
4881
- data: xml(this.formatter.format(file.fileRelationships, context), { declaration: false }),
5173
+ data: this.formatter.formatToXml(file.fileRelationships, context),
4882
5174
  path: "_rels/.rels"
4883
5175
  }
4884
5176
  };
@@ -4907,7 +5199,7 @@ var Compiler = class {
4907
5199
  path: `ppt/slideMasters/slideMaster${mi + 1}.xml`
4908
5200
  };
4909
5201
  mapping[`SlideMasterRels${mi}`] = {
4910
- data: xml(this.formatter.format(masterRels[mi], context), { declaration: false }),
5202
+ data: this.formatter.formatToXml(masterRels[mi], context),
4911
5203
  path: `ppt/slideMasters/_rels/slideMaster${mi + 1}.xml.rels`
4912
5204
  };
4913
5205
  }
@@ -4919,7 +5211,7 @@ var Compiler = class {
4919
5211
  path: `ppt/slideLayouts/slideLayout${li + 1}.xml`
4920
5212
  };
4921
5213
  mapping[`SlideLayoutRels${li}`] = {
4922
- data: xml(this.formatter.format(layoutRels[li], context), { declaration: false }),
5214
+ data: this.formatter.formatToXml(layoutRels[li], context),
4923
5215
  path: `ppt/slideLayouts/_rels/slideLayout${li + 1}.xml.rels`
4924
5216
  };
4925
5217
  }
@@ -4931,14 +5223,11 @@ var Compiler = class {
4931
5223
  if (file.notesSlides.length > 0) {
4932
5224
  file.presentationWrapper.relationships.addRelationship(file.presentationWrapper.relationships.relationshipCount + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster", "notesMasters/notesMaster1.xml");
4933
5225
  mapping["NotesMaster"] = {
4934
- data: xml(this.formatter.format(new DefaultNotesMaster(), context), {
4935
- declaration,
4936
- indent
4937
- }),
5226
+ data: this.formatter.formatToXml(new DefaultNotesMaster(), context, declaration),
4938
5227
  path: "ppt/notesMasters/notesMaster1.xml"
4939
5228
  };
4940
5229
  mapping["NotesMasterRelationships"] = {
4941
- data: xml(this.formatter.format(file.notesMasterRelationships, context), { declaration: false }),
5230
+ data: this.formatter.formatToXml(file.notesMasterRelationships, context),
4942
5231
  path: "ppt/notesMasters/_rels/notesMaster1.xml.rels"
4943
5232
  };
4944
5233
  }
@@ -4957,7 +5246,7 @@ var Compiler = class {
4957
5246
  path: "ppt/presentation.xml"
4958
5247
  };
4959
5248
  mapping["PresentationRelationships"] = {
4960
- data: xml(this.formatter.format(file.presentationWrapper.relationships, context), { declaration: false }),
5249
+ data: this.formatter.formatToXml(file.presentationWrapper.relationships, context),
4961
5250
  path: "ppt/_rels/presentation.xml.rels"
4962
5251
  };
4963
5252
  for (let i = 0; i < file.slides.length; i++) {
@@ -5026,7 +5315,7 @@ var Compiler = class {
5026
5315
  const notesSlideIndex = file.notesSlideIndexMap.get(i);
5027
5316
  if (notesSlideIndex !== void 0) slideWrapper.relationships.addRelationship(slideWrapper.relationships.relationshipCount + 1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide", `../notesSlides/notesSlide${notesSlideIndex + 1}.xml`);
5028
5317
  mapping[`SlideRelationships${i}`] = {
5029
- data: xml(this.formatter.format(slideWrapper.relationships, context), { declaration: false }),
5318
+ data: this.formatter.formatToXml(slideWrapper.relationships, context),
5030
5319
  path: `ppt/slides/_rels/slide${i + 1}.xml.rels`
5031
5320
  };
5032
5321
  }
@@ -5041,57 +5330,37 @@ var Compiler = class {
5041
5330
  file.contentTypes.addDiagramDrawing(i + 1);
5042
5331
  });
5043
5332
  mapping["ContentTypes"] = {
5044
- data: xml(this.formatter.format(file.contentTypes, context), { declaration: false }),
5333
+ data: this.formatter.formatToXml(file.contentTypes, context),
5045
5334
  path: "[Content_Types].xml"
5046
5335
  };
5047
- const files = {};
5048
- for (const key of Object.keys(mapping)) {
5049
- const entry = mapping[key];
5050
- files[entry.path] = textToUint8Array(entry.data);
5051
- }
5052
- for (const override of overrides) files[override.path] = override.data instanceof Uint8Array ? override.data : textToUint8Array(override.data);
5336
+ const files = compileMapping(mapping, overrides);
5053
5337
  for (let i = 0; i < file.charts.array.length; i++) {
5054
5338
  const chartData = file.charts.array[i];
5055
- files[`ppt/charts/chart${i + 1}.xml`] = textToUint8Array(xml(this.formatter.format(chartData.chartSpace, context), {
5056
- declaration,
5057
- indent
5058
- }));
5059
- files[`ppt/charts/_rels/chart${i + 1}.xml.rels`] = textToUint8Array(xml({ Relationships: { _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" } } }, { declaration: {
5339
+ files[`ppt/charts/chart${i + 1}.xml`] = encoder$1.encode(this.formatter.formatToXml(chartData.chartSpace, context, declaration));
5340
+ files[`ppt/charts/_rels/chart${i + 1}.xml.rels`] = encoder$1.encode(xml({ Relationships: { _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" } } }, { declaration: {
5060
5341
  encoding: "UTF-8",
5061
5342
  standalone: "yes"
5062
5343
  } }));
5063
5344
  }
5064
5345
  for (let i = 0; i < file.smartArts.array.length; i++) {
5065
5346
  const smartArtData = file.smartArts.array[i];
5066
- files[`ppt/diagrams/data${i + 1}.xml`] = textToUint8Array(xml(this.formatter.format(smartArtData.dataModel, context), {
5067
- declaration,
5068
- indent
5069
- }));
5070
- files[`ppt/diagrams/layout${i + 1}.xml`] = textToUint8Array(getLayoutXml(smartArtData.layout));
5071
- files[`ppt/diagrams/quickStyle${i + 1}.xml`] = textToUint8Array(getStyleXml(smartArtData.style));
5072
- files[`ppt/diagrams/colors${i + 1}.xml`] = textToUint8Array(getColorXml(smartArtData.color));
5073
- files[`ppt/diagrams/drawing${i + 1}.xml`] = textToUint8Array(DEFAULT_DRAWING_XML);
5347
+ files[`ppt/diagrams/data${i + 1}.xml`] = encoder$1.encode(this.formatter.formatToXml(smartArtData.dataModel, context, declaration));
5348
+ files[`ppt/diagrams/layout${i + 1}.xml`] = encoder$1.encode(getLayoutXml(smartArtData.layout));
5349
+ files[`ppt/diagrams/quickStyle${i + 1}.xml`] = encoder$1.encode(getStyleXml(smartArtData.style));
5350
+ files[`ppt/diagrams/colors${i + 1}.xml`] = encoder$1.encode(getColorXml(smartArtData.color));
5351
+ files[`ppt/diagrams/drawing${i + 1}.xml`] = encoder$1.encode(DEFAULT_DRAWING_XML);
5074
5352
  }
5075
5353
  for (let i = 0; i < file.notesSlides.length; i++) {
5076
5354
  const notesSlide = file.notesSlides[i];
5077
- files[`ppt/notesSlides/notesSlide${i + 1}.xml`] = textToUint8Array(xml(this.formatter.format(notesSlide, context), {
5078
- declaration,
5079
- indent
5080
- }));
5081
- files[`ppt/notesSlides/_rels/notesSlide${i + 1}.xml.rels`] = textToUint8Array(xml({ Relationships: { _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" } } }, { declaration: {
5355
+ files[`ppt/notesSlides/notesSlide${i + 1}.xml`] = encoder$1.encode(this.formatter.formatToXml(notesSlide, context, declaration));
5356
+ files[`ppt/notesSlides/_rels/notesSlide${i + 1}.xml.rels`] = encoder$1.encode(xml({ Relationships: { _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" } } }, { declaration: {
5082
5357
  encoding: "UTF-8",
5083
5358
  standalone: "yes"
5084
5359
  } }));
5085
5360
  }
5086
- if (file.commentAuthorList) files["ppt/commentAuthors.xml"] = textToUint8Array(xml(this.formatter.format(file.commentAuthorList, context), {
5087
- declaration,
5088
- indent
5089
- }));
5361
+ if (file.commentAuthorList) files["ppt/commentAuthors.xml"] = encoder$1.encode(this.formatter.formatToXml(file.commentAuthorList, context, declaration));
5090
5362
  const commentLists = file.slideCommentLists;
5091
- for (let i = 0; i < commentLists.length; i++) if (commentLists[i]) files[`ppt/comments/comment${i + 1}.xml`] = textToUint8Array(xml(this.formatter.format(commentLists[i], context), {
5092
- declaration,
5093
- indent
5094
- }));
5363
+ for (let i = 0; i < commentLists.length; i++) if (commentLists[i]) files[`ppt/comments/comment${i + 1}.xml`] = encoder$1.encode(this.formatter.formatToXml(commentLists[i], context, declaration));
5095
5364
  for (const image of file.media.array) {
5096
5365
  files[`ppt/media/${image.fileName}`] = [image.data, { level: ZIP_STORED_LEVEL }];
5097
5366
  if (image.type === "svg" && "fallback" in image) {
@@ -5102,15 +5371,11 @@ var Compiler = class {
5102
5371
  return files;
5103
5372
  }
5104
5373
  };
5105
- function textToUint8Array(data) {
5106
- if (data instanceof Uint8Array) return data;
5107
- return new TextEncoder().encode(data);
5108
- }
5109
5374
  //#endregion
5110
5375
  //#region src/export/packer/packer.ts
5111
5376
  const compiler = new Compiler();
5112
5377
  const Packer = createPacker({
5113
- compile: (file, prettify, overrides) => compiler.compile(file, prettify, overrides),
5378
+ compile: (file, overrides) => compiler.compile(file, overrides),
5114
5379
  mimeType: OoxmlMimeType.PPTX
5115
5380
  });
5116
5381
  //#endregion
@@ -6092,9 +6357,9 @@ function parseConnector(el) {
6092
6357
  const type = attr(headEnd, "type");
6093
6358
  if (type) opts.endArrowhead = type;
6094
6359
  const len = attr(headEnd, "len");
6095
- if (len) opts.arrowheadLength = len;
6360
+ if (len) opts.arrowheadLength = xsdLineEndSize.from(len);
6096
6361
  const w = attr(headEnd, "w");
6097
- if (w) opts.arrowheadWidth = w;
6362
+ if (w) opts.arrowheadWidth = xsdLineEndSize.from(w);
6098
6363
  }
6099
6364
  const tailEnd = findChild(ln, "a:tailEnd");
6100
6365
  if (tailEnd) {
@@ -7208,14 +7473,88 @@ function extractCommentText(txBody) {
7208
7473
  }
7209
7474
  return parts.join("");
7210
7475
  }
7476
+ //#endregion
7477
+ //#region src/patcher/from-pptx.ts
7478
+ /** Reusable TextEncoder (stateless, safe to share). */
7479
+ const encoder = new TextEncoder();
7480
+ const PatchType = { PARAGRAPH: "paragraph" };
7481
+ const formatter = new Formatter();
7482
+ const pptxReplacer = createReplacer({
7483
+ ns: PPTX_NS,
7484
+ formatChild: (child, context) => {
7485
+ return [xml2js(formatter.formatToXml(child, context), { captureSpacesBetweenElements: true }).elements[0]];
7486
+ },
7487
+ preserveSpace: false
7488
+ });
7489
+ const IMAGE_CONTENT_TYPES = [
7490
+ ["image/png", "png"],
7491
+ ["image/jpeg", "jpeg"],
7492
+ ["image/jpeg", "jpg"],
7493
+ ["image/bmp", "bmp"],
7494
+ ["image/gif", "gif"],
7495
+ ["image/svg+xml", "svg"],
7496
+ ["image/tiff", "tif"],
7497
+ ["image/tiff", "tiff"],
7498
+ ["image/x-emf", "emf"],
7499
+ ["image/x-wmf", "wmf"]
7500
+ ];
7501
+ const SLIDE_RE = /^ppt\/slides\/slide(\d+)\.xml$/;
7502
+ /**
7503
+ * Patches an existing .pptx presentation by replacing placeholders with new content.
7504
+ *
7505
+ * @publicApi
7506
+ */
7507
+ const patchPresentation = async ({ outputType, data, patches, keepOriginalStyles = true, placeholderDelimiters = {
7508
+ end: "}}",
7509
+ start: "{{"
7510
+ } }) => {
7511
+ const zipContent = unzipSync(toUint8Array(data));
7512
+ const xmlMap = /* @__PURE__ */ new Map();
7513
+ const binaryMap = /* @__PURE__ */ new Map();
7514
+ let hasMedia = false;
7515
+ for (const [key, value] of Object.entries(zipContent)) if (key.endsWith(".xml") || key.endsWith(".rels")) xmlMap.set(key, toJson(strFromU8(value)));
7516
+ else binaryMap.set(key, value);
7517
+ const slidePaths = Object.keys(zipContent).filter((k) => SLIDE_RE.test(k)).sort((a, b) => {
7518
+ return parseInt(a.match(SLIDE_RE)[1], 10) - parseInt(b.match(SLIDE_RE)[1], 10);
7519
+ });
7520
+ const { start, end } = placeholderDelimiters;
7521
+ if (!start.trim() || !end.trim()) throw new Error("Both start and end delimiters must be non-empty strings.");
7522
+ const context = { stack: [] };
7523
+ for (const slidePath of slidePaths) {
7524
+ const json = xmlMap.get(slidePath);
7525
+ if (!json) continue;
7526
+ for (const [patchKey, patchValue] of Object.entries(patches)) pptxReplacer({
7527
+ context,
7528
+ json,
7529
+ keepOriginalStyles,
7530
+ patch: patchValue,
7531
+ patchText: `${start}${patchKey}${end}`
7532
+ });
7533
+ }
7534
+ for (const [key, patch] of Object.entries(patches)) if ("data" in patch && patch.data instanceof Uint8Array) {
7535
+ const mediaPath = `ppt/media/${key}`;
7536
+ if (binaryMap.has(mediaPath)) {
7537
+ binaryMap.set(mediaPath, patch.data);
7538
+ hasMedia = true;
7539
+ }
7540
+ }
7541
+ if (hasMedia) {
7542
+ const contentTypes = xmlMap.get("[Content_Types].xml");
7543
+ if (contentTypes) for (const [contentType, extension] of IMAGE_CONTENT_TYPES) appendContentType(contentTypes, contentType, extension);
7544
+ }
7545
+ const files = {};
7546
+ for (const [key, value] of xmlMap) files[key] = encoder.encode(js2xml(value));
7547
+ for (const [key, value] of binaryMap) files[key] = value;
7548
+ return await zipAndConvert(files, outputType, OoxmlMimeType.PPTX);
7549
+ };
7211
7550
  __reExport(/* @__PURE__ */ __exportAll({
7212
7551
  AppProperties: () => AppProperties,
7213
7552
  AudioFrame: () => AudioFrame,
7214
7553
  Background: () => Background,
7215
7554
  BevelPresetType: () => BevelPresetType,
7216
7555
  BlipFill: () => BlipFill,
7556
+ Chart: () => Chart,
7217
7557
  ChartCollection: () => ChartCollection,
7218
- ChartFrame: () => ChartFrame,
7219
7558
  ChartSpace: () => ChartSpace,
7220
7559
  CompoundLine: () => CompoundLine,
7221
7560
  ConnectorShape: () => ConnectorShape,
@@ -7226,6 +7565,7 @@ __reExport(/* @__PURE__ */ __exportAll({
7226
7565
  DefaultSlideLayout: () => DefaultSlideLayout,
7227
7566
  DefaultSlideMaster: () => DefaultSlideMaster,
7228
7567
  DefaultTheme: () => DefaultTheme,
7568
+ DrawingTable: () => DrawingTable,
7229
7569
  EndParagraphRunProperties: () => EndParagraphRunProperties,
7230
7570
  Field: () => Field,
7231
7571
  File: () => File,
@@ -7244,6 +7584,7 @@ __reExport(/* @__PURE__ */ __exportAll({
7244
7584
  Packer: () => Packer,
7245
7585
  Paragraph: () => Paragraph,
7246
7586
  ParagraphProperties: () => ParagraphProperties,
7587
+ PatchType: () => PatchType,
7247
7588
  PathShadeType: () => PathShadeType,
7248
7589
  PenAlignment: () => PenAlignment,
7249
7590
  Picture: () => Picture,
@@ -7252,7 +7593,6 @@ __reExport(/* @__PURE__ */ __exportAll({
7252
7593
  PresetDash: () => PresetDash,
7253
7594
  PresetGeometry: () => PresetGeometry,
7254
7595
  PresetMaterialType: () => PresetMaterialType,
7255
- PrettifyType: () => PrettifyType,
7256
7596
  ReflectionAlignment: () => ReflectionAlignment,
7257
7597
  Relationships: () => Relationships,
7258
7598
  RunProperties: () => RunProperties,
@@ -7263,12 +7603,11 @@ __reExport(/* @__PURE__ */ __exportAll({
7263
7603
  SlideLayout: () => SlideLayout,
7264
7604
  SlideNumberField: () => SlideNumberField,
7265
7605
  SlideSizePreset: () => SlideSizePreset,
7266
- SmartArtFrame: () => SmartArtFrame,
7606
+ SmartArt: () => SmartArt,
7267
7607
  StrikeStyle: () => StrikeStyle,
7268
7608
  Table: () => Table,
7269
7609
  TableCell: () => TableCell,
7270
7610
  TableCellProperties: () => TableCellProperties,
7271
- TableFrame: () => TableFrame,
7272
7611
  TableProperties: () => TableProperties,
7273
7612
  TableRow: () => TableRow,
7274
7613
  Text: () => Text,
@@ -7308,12 +7647,13 @@ __reExport(/* @__PURE__ */ __exportAll({
7308
7647
  parseArchive: () => parseArchive,
7309
7648
  parsePptx: () => parsePptx,
7310
7649
  parsePresentation: () => parsePresentation,
7650
+ patchPresentation: () => patchPresentation,
7311
7651
  percentToTHousandths: () => percentToTHousandths,
7312
7652
  uniqueId: () => uniqueId,
7313
7653
  uniqueNumericIdCreator: () => uniqueNumericIdCreator,
7314
7654
  uniqueUuid: () => uniqueUuid
7315
7655
  }), util_exports);
7316
7656
  //#endregion
7317
- export { AppProperties, AudioFrame, Background, BevelPresetType, BlipFill, ChartCollection, ChartFrame, ChartSpace, CompoundLine, ConnectorShape, ContentTypes, CoreProperties, DateTimeField, DefaultNotesMaster, DefaultSlideLayout, DefaultSlideMaster, DefaultTheme, EndParagraphRunProperties, Field, File, File as Presentation, GroupShape, GroupShapeProperties, GroupTransform2D, HeaderFooter, LineCap, LineJoin, LineShape, Media, NonVisualDrawingProperties, NonVisualPictureProperties, NonVisualShapeProperties, NotesSlide, Packer, Paragraph, ParagraphProperties, PathShadeType, PenAlignment, Picture, PresentationWrapper, PresetDash, PresetGeometry, PresetMaterialType, PrettifyType, ReflectionAlignment, Relationships, RunProperties, Shape, ShapeProperties, ShapeTree, Slide, SlideLayout, SlideNumberField, SlideSizePreset, SmartArtFrame, StrikeStyle, Table, TableCell, TableCellProperties, TableFrame, TableProperties, TableRow, Text, TextAlignment, TextBody, TextCapitalization, TextRun, TileFlipMode, Transform2D, Transition, UnderlineStyle, VerticalAlignment, VideoFrame, buildFill, coerceChild, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertPixelsToEmu, convertPointsToEmu, createBevel, createBottomBevel, createColorElement, createColorTransforms, createEffectList, createGradientFill, createGradientStop, createOutline, createOutlineCompat, createPptxEffectList, createScene3D, createShape3D, createTransformation, extractBlipFillMedia, hashedId, parseArchive, parsePptx, parsePresentation, percentToTHousandths, uniqueId, uniqueNumericIdCreator, uniqueUuid };
7657
+ export { AppProperties, AudioFrame, Background, BevelPresetType, BlipFill, Chart, ChartCollection, ChartSpace, CompoundLine, ConnectorShape, ContentTypes, CoreProperties, DateTimeField, DefaultNotesMaster, DefaultSlideLayout, DefaultSlideMaster, DefaultTheme, DrawingTable, EndParagraphRunProperties, Field, File, File as Presentation, GroupShape, GroupShapeProperties, GroupTransform2D, HeaderFooter, LineCap, LineJoin, LineShape, Media, NonVisualDrawingProperties, NonVisualPictureProperties, NonVisualShapeProperties, NotesSlide, Packer, Paragraph, ParagraphProperties, PatchType, PathShadeType, PenAlignment, Picture, PresentationWrapper, PresetDash, PresetGeometry, PresetMaterialType, ReflectionAlignment, Relationships, RunProperties, Shape, ShapeProperties, ShapeTree, Slide, SlideLayout, SlideNumberField, SlideSizePreset, SmartArt, StrikeStyle, Table, TableCell, TableCellProperties, TableProperties, TableRow, Text, TextAlignment, TextBody, TextCapitalization, TextRun, TileFlipMode, Transform2D, Transition, UnderlineStyle, VerticalAlignment, VideoFrame, buildFill, coerceChild, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertPixelsToEmu, convertPointsToEmu, createBevel, createBottomBevel, createColorElement, createColorTransforms, createEffectList, createGradientFill, createGradientStop, createOutline, createOutlineCompat, createPptxEffectList, createScene3D, createShape3D, createTransformation, extractBlipFillMedia, hashedId, parseArchive, parsePptx, parsePresentation, patchPresentation, percentToTHousandths, uniqueId, uniqueNumericIdCreator, uniqueUuid };
7318
7658
 
7319
- //# sourceMappingURL=index.mjs.map
7659
+ //# sourceMappingURL=index.js.map