documents.js 1.40.0 → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
1
+ import { AttributeSchema, BinaryPartSchema, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, DefinedNameSchema, PackageSchema, PartSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, attr as attr$1, base64ToBytes, base64ToBytes as base64ToBytes$1, buildXml, bytesToBase64, bytesToBase64 as bytesToBase64$1, childrenWithTag, compactCodec, compactPackageCodec, decodeCompactPackage, decodeEntities, decodePackage, decodePackage as decodePackage$1, elementsWithTag, elementsWithTag as elementsWithTag$1, encodeCompactPackage, encodePackage, encodePackage as encodePackage$1, fromCompact, isCompactXmlNode, isXmlNode, packageCodec, parsePackage, parseXml, readDocx, readPptx, resolveRelationships, resolveRelationships as resolveRelationships$1, rootElement, rootElement as rootElement$1, serializePackage, textContent, textContent as textContent$1, toCompact, unzipPackage, walk, xmlCodec, zipPackage } from "ooxml.js";
2
2
  import { COLOR_BLACK, ContentBlockSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentSectionSchema as ContentSectionSchema$1, ContentShapeSchema, ContentSlideSchema, ContentSlideSchema as ContentSlideSchema$1, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, LAYOUT_FORMAT_VERSION, LAYOUT_FORMAT_VERSION as LAYOUT_FORMAT_VERSION$1, LayoutDocumentSchema, LayoutMetadataSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, colorToRgbHex, isContentBlock, rgbHexToColor } from "document-content-model";
3
3
  import { z } from "zod";
4
- import { ODF_MEDIA_TYPES, StyleRegistry, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, formatOdfLength, readOdp, readOdt, resolveStyle, setDocumentMediaType, syncManifest, xmlnsAttributes } from "odf.js";
4
+ import { ODF_MEDIA_TYPES, StyleRegistry, applyOdfTransform, base64ToBytes as base64ToBytes$2, bytesToBase64 as bytesToBase64$2, decodeOdfText, decodePackage as decodePackage$2, encodePackage as encodePackage$2, formatOdfLength, parseOdfLength, readOdp, readOdt, resolveOdfShapeGeometry, resolveStyle, setDocumentMediaType, syncManifest, syncManifest as syncManifest$1, xmlnsAttributes } from "odf.js";
5
5
  import { Unzlib, inflateSync, unzlibSync, zlibSync } from "fflate";
6
6
  //#region src/model/content.ts
7
7
  const CONTENT_FORMAT_VERSION = 1;
@@ -300,11 +300,11 @@ function ensureContentTypeOverride(pkg, partPath, contentType) {
300
300
  //#endregion
301
301
  //#region src/opc/media.ts
302
302
  const IMAGE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
303
- function escapeRegExp(value) {
303
+ function escapeRegExp$1(value) {
304
304
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
305
305
  }
306
306
  function nextMediaIndex(pkg, mediaDir, fileNamePrefix, extension) {
307
- const pattern = new RegExp(`^${escapeRegExp(fileNamePrefix)}(\\d+)\\.${escapeRegExp(extension)}$`);
307
+ const pattern = new RegExp(`^${escapeRegExp$1(fileNamePrefix)}(\\d+)\\.${escapeRegExp$1(extension)}$`);
308
308
  const prefix = `${mediaDir}/`;
309
309
  let max = 0;
310
310
  for (const path of Object.keys(pkg.parts)) {
@@ -318,7 +318,7 @@ function nextMediaIndex(pkg, mediaDir, fileNamePrefix, extension) {
318
318
  }
319
319
  return max + 1;
320
320
  }
321
- function addImageMedia(pkg, fromPartPath, mediaDir, format, bytes) {
321
+ function addImageMedia$1(pkg, fromPartPath, mediaDir, format, bytes) {
322
322
  const extension = format === "jpeg" ? "jpeg" : "png";
323
323
  const fileNamePrefix = "image";
324
324
  const partPath = `${mediaDir}/${fileNamePrefix}${nextMediaIndex(pkg, mediaDir, fileNamePrefix, extension)}.${extension}`;
@@ -400,7 +400,7 @@ function buildInlineDrawing(relationshipId, widthPt, heightPt, id, altText) {
400
400
  }, [inline]);
401
401
  }
402
402
  function insertImageMedia(context, documentRoot, image) {
403
- const { relationshipId } = addImageMedia(context.pkg, context.partPath, context.mediaDir, image.format, image.bytes);
403
+ const { relationshipId } = addImageMedia$1(context.pkg, context.partPath, context.mediaDir, image.format, image.bytes);
404
404
  const id = nextDrawingId(documentRoot);
405
405
  return buildInlineDrawing(relationshipId, image.widthPt, image.heightPt, id, image.altText);
406
406
  }
@@ -520,7 +520,7 @@ function needsSpacePreserve(text) {
520
520
  }
521
521
  //#endregion
522
522
  //#region src/edit/docx/run.ts
523
- function directChild$5(parent, tag) {
523
+ function directChild$8(parent, tag) {
524
524
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
525
525
  }
526
526
  function appendUElement(rPr, value) {
@@ -529,7 +529,7 @@ function appendUElement(rPr, value) {
529
529
  return created;
530
530
  }
531
531
  function findOrCreateT(run) {
532
- const existing = directChild$5(run, "w:t");
532
+ const existing = directChild$8(run, "w:t");
533
533
  if (existing !== void 0) return existing;
534
534
  const created = el("w:t");
535
535
  run.children.push(created);
@@ -549,7 +549,7 @@ var DocxRun = class {
549
549
  }
550
550
  rPr(create) {
551
551
  const node = this.live();
552
- return create ? ensureFirstChild(node, "w:rPr") : directChild$5(node, "w:rPr");
552
+ return create ? ensureFirstChild(node, "w:rPr") : directChild$8(node, "w:rPr");
553
553
  }
554
554
  get text() {
555
555
  return textContent$1(this.live());
@@ -573,14 +573,14 @@ var DocxRun = class {
573
573
  }
574
574
  get underline() {
575
575
  const rPr = this.rPr(false);
576
- const uElement = rPr === void 0 ? void 0 : directChild$5(rPr, "w:u");
576
+ const uElement = rPr === void 0 ? void 0 : directChild$8(rPr, "w:u");
577
577
  if (uElement === void 0) return false;
578
578
  for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
579
579
  return true;
580
580
  }
581
581
  set underline(value) {
582
582
  const rPr = this.rPr(true);
583
- const existing = directChild$5(rPr, "w:u");
583
+ const existing = directChild$8(rPr, "w:u");
584
584
  if (existing === void 0) {
585
585
  appendUElement(rPr, value);
586
586
  return;
@@ -654,7 +654,7 @@ function buildRun$1(init = {}) {
654
654
  }
655
655
  //#endregion
656
656
  //#region src/edit/docx/paragraph.ts
657
- function directChild$4(parent, tag) {
657
+ function directChild$7(parent, tag) {
658
658
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
659
659
  }
660
660
  var DocxParagraph = class {
@@ -673,7 +673,7 @@ var DocxParagraph = class {
673
673
  }
674
674
  pPr(create) {
675
675
  const node = this.live();
676
- return create ? ensureFirstChild(node, "w:pPr") : directChild$4(node, "w:pPr");
676
+ return create ? ensureFirstChild(node, "w:pPr") : directChild$7(node, "w:pPr");
677
677
  }
678
678
  get text() {
679
679
  return textContent$1(this.live());
@@ -710,7 +710,7 @@ var DocxParagraph = class {
710
710
  set styleId(value) {
711
711
  if (value === void 0) {
712
712
  const pPr = this.pPr(false);
713
- const existing = pPr === void 0 ? void 0 : directChild$4(pPr, "w:pStyle");
713
+ const existing = pPr === void 0 ? void 0 : directChild$7(pPr, "w:pStyle");
714
714
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
715
715
  return;
716
716
  }
@@ -722,7 +722,7 @@ var DocxParagraph = class {
722
722
  set alignment(value) {
723
723
  if (value === void 0) {
724
724
  const pPr = this.pPr(false);
725
- const existing = pPr === void 0 ? void 0 : directChild$4(pPr, "w:jc");
725
+ const existing = pPr === void 0 ? void 0 : directChild$7(pPr, "w:jc");
726
726
  if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
727
727
  return;
728
728
  }
@@ -730,12 +730,12 @@ var DocxParagraph = class {
730
730
  }
731
731
  get list() {
732
732
  const pPr = this.pPr(false);
733
- const numPr = pPr === void 0 ? void 0 : directChild$4(pPr, "w:numPr");
733
+ const numPr = pPr === void 0 ? void 0 : directChild$7(pPr, "w:numPr");
734
734
  if (numPr === void 0) return;
735
- const numIdElement = directChild$4(numPr, "w:numId");
735
+ const numIdElement = directChild$7(numPr, "w:numId");
736
736
  const numId = numIdElement === void 0 ? void 0 : attr$1(numIdElement, "w:val");
737
737
  if (numId === void 0) return;
738
- const ilvlElement = directChild$4(numPr, "w:ilvl");
738
+ const ilvlElement = directChild$7(numPr, "w:ilvl");
739
739
  const ilvl = ilvlElement === void 0 ? void 0 : attr$1(ilvlElement, "w:val");
740
740
  return {
741
741
  numId,
@@ -745,7 +745,7 @@ var DocxParagraph = class {
745
745
  set list(value) {
746
746
  const pPr = this.pPr(true);
747
747
  if (value === void 0) {
748
- const existing = directChild$4(pPr, "w:numPr");
748
+ const existing = directChild$7(pPr, "w:numPr");
749
749
  if (existing !== void 0) removeChild(pPr.children, existing);
750
750
  return;
751
751
  }
@@ -779,7 +779,7 @@ function buildParagraph$1(init = {}) {
779
779
  const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
780
780
  const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
781
781
  const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
782
- function declaration$2() {
782
+ function declaration$3() {
783
783
  return {
784
784
  type: "declaration",
785
785
  attributes: [
@@ -848,23 +848,23 @@ function createEmptyDocxPackage() {
848
848
  return { parts: {
849
849
  "[Content_Types].xml": {
850
850
  kind: "xml",
851
- nodes: [declaration$2(), contentTypes]
851
+ nodes: [declaration$3(), contentTypes]
852
852
  },
853
853
  "_rels/.rels": {
854
854
  kind: "xml",
855
- nodes: [declaration$2(), rootRels]
855
+ nodes: [declaration$3(), rootRels]
856
856
  },
857
857
  "word/document.xml": {
858
858
  kind: "xml",
859
- nodes: [declaration$2(), document]
859
+ nodes: [declaration$3(), document]
860
860
  },
861
861
  "word/_rels/document.xml.rels": {
862
862
  kind: "xml",
863
- nodes: [declaration$2(), documentRels]
863
+ nodes: [declaration$3(), documentRels]
864
864
  },
865
865
  "word/styles.xml": {
866
866
  kind: "xml",
867
- nodes: [declaration$2(), styles]
867
+ nodes: [declaration$3(), styles]
868
868
  }
869
869
  } };
870
870
  }
@@ -1155,7 +1155,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
1155
1155
  const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
1156
1156
  const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
1157
1157
  const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
1158
- function declaration$1() {
1158
+ function declaration$2() {
1159
1159
  return {
1160
1160
  type: "declaration",
1161
1161
  attributes: [
@@ -1305,7 +1305,7 @@ function ensureNotesMaster(pkg) {
1305
1305
  });
1306
1306
  pkg.parts[NOTES_MASTER_PART_PATH] = {
1307
1307
  kind: "xml",
1308
- nodes: [declaration$1(), buildNotesMaster()]
1308
+ nodes: [declaration$2(), buildNotesMaster()]
1309
1309
  };
1310
1310
  ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
1311
1311
  const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
@@ -1344,15 +1344,15 @@ function createEmptyPptxPackage() {
1344
1344
  const pkg = { parts: {
1345
1345
  "[Content_Types].xml": {
1346
1346
  kind: "xml",
1347
- nodes: [declaration$1(), contentTypes]
1347
+ nodes: [declaration$2(), contentTypes]
1348
1348
  },
1349
1349
  "_rels/.rels": {
1350
1350
  kind: "xml",
1351
- nodes: [declaration$1(), rootRels]
1351
+ nodes: [declaration$2(), rootRels]
1352
1352
  },
1353
1353
  [PRESENTATION_PART_PATH$1]: {
1354
1354
  kind: "xml",
1355
- nodes: [declaration$1(), el("p:presentation", {
1355
+ nodes: [declaration$2(), el("p:presentation", {
1356
1356
  "xmlns:p": PML_NS,
1357
1357
  "xmlns:r": R_NS
1358
1358
  })]
@@ -1365,7 +1365,7 @@ function createEmptyPptxPackage() {
1365
1365
  });
1366
1366
  pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
1367
1367
  kind: "xml",
1368
- nodes: [declaration$1(), buildSlideLayout()]
1368
+ nodes: [declaration$2(), buildSlideLayout()]
1369
1369
  };
1370
1370
  ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
1371
1371
  const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
@@ -1380,12 +1380,12 @@ function createEmptyPptxPackage() {
1380
1380
  });
1381
1381
  pkg.parts[SLIDE_MASTER_PART_PATH] = {
1382
1382
  kind: "xml",
1383
- nodes: [declaration$1(), buildSlideMaster(masterToLayoutRelId)]
1383
+ nodes: [declaration$2(), buildSlideMaster(masterToLayoutRelId)]
1384
1384
  };
1385
1385
  ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
1386
1386
  pkg.parts[THEME_PART_PATH] = {
1387
1387
  kind: "xml",
1388
- nodes: [declaration$1(), buildTheme()]
1388
+ nodes: [declaration$2(), buildTheme()]
1389
1389
  };
1390
1390
  ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
1391
1391
  const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
@@ -1410,7 +1410,7 @@ function createEmptyPptxPackage() {
1410
1410
  }
1411
1411
  //#endregion
1412
1412
  //#region src/edit/pptx/shape.ts
1413
- function directChild$3(parent, tag) {
1413
+ function directChild$6(parent, tag) {
1414
1414
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1415
1415
  }
1416
1416
  function parseEmuAttr(element, name) {
@@ -1431,7 +1431,7 @@ var PptxShape = class {
1431
1431
  }
1432
1432
  spPrElement(create) {
1433
1433
  const node = this.live();
1434
- const existing = directChild$3(node, "p:spPr");
1434
+ const existing = directChild$6(node, "p:spPr");
1435
1435
  if (existing !== void 0 || !create) return existing;
1436
1436
  const created = el("p:spPr");
1437
1437
  node.children.push(created);
@@ -1439,10 +1439,10 @@ var PptxShape = class {
1439
1439
  }
1440
1440
  get frame() {
1441
1441
  const spPr = this.spPrElement(false);
1442
- const xfrm = spPr === void 0 ? void 0 : directChild$3(spPr, "a:xfrm");
1442
+ const xfrm = spPr === void 0 ? void 0 : directChild$6(spPr, "a:xfrm");
1443
1443
  if (xfrm === void 0) return;
1444
- const off = directChild$3(xfrm, "a:off");
1445
- const ext = directChild$3(xfrm, "a:ext");
1444
+ const off = directChild$6(xfrm, "a:off");
1445
+ const ext = directChild$6(xfrm, "a:ext");
1446
1446
  if (off === void 0 || ext === void 0) return;
1447
1447
  const x = parseEmuAttr(off, "x");
1448
1448
  const y = parseEmuAttr(off, "y");
@@ -1458,7 +1458,7 @@ var PptxShape = class {
1458
1458
  }
1459
1459
  set frame(value) {
1460
1460
  const spPr = this.spPrElement(true);
1461
- let xfrm = directChild$3(spPr, "a:xfrm");
1461
+ let xfrm = directChild$6(spPr, "a:xfrm");
1462
1462
  if (xfrm === void 0) {
1463
1463
  xfrm = el("a:xfrm");
1464
1464
  spPr.children.unshift(xfrm);
@@ -1472,12 +1472,12 @@ var PptxShape = class {
1472
1472
  })];
1473
1473
  }
1474
1474
  get text() {
1475
- const txBody = directChild$3(this.live(), "p:txBody");
1475
+ const txBody = directChild$6(this.live(), "p:txBody");
1476
1476
  return txBody === void 0 ? "" : textContent$1(txBody);
1477
1477
  }
1478
1478
  set text(value) {
1479
1479
  const node = this.live();
1480
- let txBody = directChild$3(node, "p:txBody");
1480
+ let txBody = directChild$6(node, "p:txBody");
1481
1481
  if (txBody === void 0) {
1482
1482
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1483
1483
  node.children.push(txBody);
@@ -1488,7 +1488,7 @@ var PptxShape = class {
1488
1488
  }
1489
1489
  setParagraphs(paragraphs) {
1490
1490
  const node = this.live();
1491
- let txBody = directChild$3(node, "p:txBody");
1491
+ let txBody = directChild$6(node, "p:txBody");
1492
1492
  if (txBody === void 0) {
1493
1493
  txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
1494
1494
  node.children.push(txBody);
@@ -1594,17 +1594,17 @@ function nextShapeId(slideRoot) {
1594
1594
  return max + 1;
1595
1595
  }
1596
1596
  function insertPictureShapeMedia(context, slideRoot, frame, image) {
1597
- const { relationshipId } = addImageMedia(context.pkg, context.partPath, context.mediaDir, image.format, image.bytes);
1597
+ const { relationshipId } = addImageMedia$1(context.pkg, context.partPath, context.mediaDir, image.format, image.bytes);
1598
1598
  return buildPictureShape(frame, relationshipId, nextShapeId(slideRoot));
1599
1599
  }
1600
1600
  //#endregion
1601
1601
  //#region src/edit/pptx/slide.ts
1602
- function directChild$2(parent, tag) {
1602
+ function directChild$5(parent, tag) {
1603
1603
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1604
1604
  }
1605
1605
  function findSpTree(slideRoot) {
1606
- const cSld = directChild$2(slideRoot, "p:cSld");
1607
- const spTree = cSld === void 0 ? void 0 : directChild$2(cSld, "p:spTree");
1606
+ const cSld = directChild$5(slideRoot, "p:cSld");
1607
+ const spTree = cSld === void 0 ? void 0 : directChild$5(cSld, "p:spTree");
1608
1608
  if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
1609
1609
  return spTree;
1610
1610
  }
@@ -1736,7 +1736,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
1736
1736
  const MEDIA_DIR = "ppt/media";
1737
1737
  const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
1738
1738
  const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
1739
- function directChild$1(parent, tag) {
1739
+ function directChild$4(parent, tag) {
1740
1740
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
1741
1741
  }
1742
1742
  function attrValue(element, name) {
@@ -1748,12 +1748,12 @@ function findPresentationRoot(pkg) {
1748
1748
  return root;
1749
1749
  }
1750
1750
  function findSldIdLst(presentationRoot) {
1751
- const sldIdLst = directChild$1(presentationRoot, "p:sldIdLst");
1751
+ const sldIdLst = directChild$4(presentationRoot, "p:sldIdLst");
1752
1752
  if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
1753
1753
  return sldIdLst;
1754
1754
  }
1755
1755
  function findSldSz(presentationRoot) {
1756
- const sldSz = directChild$1(presentationRoot, "p:sldSz");
1756
+ const sldSz = directChild$4(presentationRoot, "p:sldSz");
1757
1757
  if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
1758
1758
  return sldSz;
1759
1759
  }
@@ -1914,12 +1914,12 @@ function buildPptxPackage(content) {
1914
1914
  if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
1915
1915
  for (const slide of content.slides) {
1916
1916
  const pptxSlide = editor.addSlide();
1917
- for (const shape of slide.shapes) appendShape(pptxSlide, shape);
1917
+ for (const shape of slide.shapes) appendShape$1(pptxSlide, shape);
1918
1918
  if (slide.notes.length > 0) pptxSlide.notes = slide.notes;
1919
1919
  }
1920
1920
  return editor.toPackage();
1921
1921
  }
1922
- function appendShape(slide, shape) {
1922
+ function appendShape$1(slide, shape) {
1923
1923
  const [onlyBlock] = shape.blocks;
1924
1924
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
1925
1925
  slide.addImage({
@@ -1952,12 +1952,12 @@ function appendShape(slide, shape) {
1952
1952
  }
1953
1953
  //#endregion
1954
1954
  //#region src/edit/odt/automatic-styles.ts
1955
- const CONTENT_PART_PATH$1 = "content.xml";
1955
+ const CONTENT_PART_PATH$2 = "content.xml";
1956
1956
  function ensureAutomaticStyles(pkg) {
1957
- const part = pkg.parts[CONTENT_PART_PATH$1];
1958
- if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$1} part`);
1957
+ const part = pkg.parts[CONTENT_PART_PATH$2];
1958
+ if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$2} part`);
1959
1959
  const root = part.nodes.find((n) => n.type === "element");
1960
- if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$1} has no root element`);
1960
+ if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$2} has no root element`);
1961
1961
  for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
1962
1962
  const created = el("office:automatic-styles");
1963
1963
  const insertBeforeTags = /* @__PURE__ */ new Set([
@@ -2051,7 +2051,7 @@ function applyStyleChange(pkg, element, family, change) {
2051
2051
  ...readCurrentStyleProperties(pkg, element, family),
2052
2052
  ...change
2053
2053
  };
2054
- const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$1).intern({
2054
+ const name = StyleRegistry.forPart(pkg, CONTENT_PART_PATH$2).intern({
2055
2055
  family,
2056
2056
  properties: merged
2057
2057
  });
@@ -2282,7 +2282,7 @@ function buildList(pkg) {
2282
2282
  }
2283
2283
  //#endregion
2284
2284
  //#region src/edit/odt/scaffold.ts
2285
- const CONTENT_NS_PREFIXES = [
2285
+ const CONTENT_NS_PREFIXES$1 = [
2286
2286
  "office",
2287
2287
  "style",
2288
2288
  "text",
@@ -2292,7 +2292,7 @@ const CONTENT_NS_PREFIXES = [
2292
2292
  "svg",
2293
2293
  "xlink"
2294
2294
  ];
2295
- const STYLES_NS_PREFIXES = [
2295
+ const STYLES_NS_PREFIXES$1 = [
2296
2296
  "office",
2297
2297
  "style",
2298
2298
  "text",
@@ -2302,16 +2302,16 @@ const STYLES_NS_PREFIXES = [
2302
2302
  "svg",
2303
2303
  "xlink"
2304
2304
  ];
2305
- const META_NS_PREFIXES = [
2305
+ const META_NS_PREFIXES$1 = [
2306
2306
  "office",
2307
2307
  "meta",
2308
2308
  "dc"
2309
2309
  ];
2310
- const ODF_VERSION = "1.3";
2311
- const PAGE_LAYOUT_NAME = "PM1";
2312
- const MASTER_PAGE_NAME = "Standard";
2310
+ const ODF_VERSION$1 = "1.3";
2311
+ const PAGE_LAYOUT_NAME$1 = "PM1";
2312
+ const MASTER_PAGE_NAME$1 = "Standard";
2313
2313
  const DEFAULT_MARGIN_PT = 72;
2314
- function declaration() {
2314
+ function declaration$1() {
2315
2315
  return {
2316
2316
  type: "declaration",
2317
2317
  attributes: [
@@ -2330,8 +2330,8 @@ function declaration() {
2330
2330
  ]
2331
2331
  };
2332
2332
  }
2333
- function buildPageLayout() {
2334
- return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME }, [el("style:page-layout-properties", {
2333
+ function buildPageLayout$1() {
2334
+ return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME$1 }, [el("style:page-layout-properties", {
2335
2335
  "fo:page-width": `${PAGE_SIZE_LETTER.widthPt}pt`,
2336
2336
  "fo:page-height": `${PAGE_SIZE_LETTER.heightPt}pt`,
2337
2337
  "fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
@@ -2340,44 +2340,44 @@ function buildPageLayout() {
2340
2340
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
2341
2341
  })]);
2342
2342
  }
2343
- function buildStylesXml() {
2343
+ function buildStylesXml$1() {
2344
2344
  return el("office:document-styles", {
2345
- ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
2346
- "office:version": ODF_VERSION
2345
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES$1]),
2346
+ "office:version": ODF_VERSION$1
2347
2347
  }, [
2348
2348
  el("office:styles"),
2349
- el("office:automatic-styles", {}, [buildPageLayout()]),
2349
+ el("office:automatic-styles", {}, [buildPageLayout$1()]),
2350
2350
  el("office:master-styles", {}, [el("style:master-page", {
2351
- "style:name": MASTER_PAGE_NAME,
2352
- "style:page-layout-name": PAGE_LAYOUT_NAME
2351
+ "style:name": MASTER_PAGE_NAME$1,
2352
+ "style:page-layout-name": PAGE_LAYOUT_NAME$1
2353
2353
  })])
2354
2354
  ]);
2355
2355
  }
2356
- function buildContentXml() {
2356
+ function buildContentXml$1() {
2357
2357
  return el("office:document-content", {
2358
- ...xmlnsAttributes([...CONTENT_NS_PREFIXES]),
2359
- "office:version": ODF_VERSION
2358
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES$1]),
2359
+ "office:version": ODF_VERSION$1
2360
2360
  }, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
2361
2361
  }
2362
- function buildMetaXml() {
2362
+ function buildMetaXml$1() {
2363
2363
  return el("office:document-meta", {
2364
- ...xmlnsAttributes([...META_NS_PREFIXES]),
2365
- "office:version": ODF_VERSION
2364
+ ...xmlnsAttributes([...META_NS_PREFIXES$1]),
2365
+ "office:version": ODF_VERSION$1
2366
2366
  }, [el("office:meta")]);
2367
2367
  }
2368
2368
  function createEmptyOdtPackage() {
2369
2369
  const pkg = { parts: {
2370
2370
  "content.xml": {
2371
2371
  kind: "xml",
2372
- nodes: [declaration(), buildContentXml()]
2372
+ nodes: [declaration$1(), buildContentXml$1()]
2373
2373
  },
2374
2374
  "styles.xml": {
2375
2375
  kind: "xml",
2376
- nodes: [declaration(), buildStylesXml()]
2376
+ nodes: [declaration$1(), buildStylesXml$1()]
2377
2377
  },
2378
2378
  "meta.xml": {
2379
2379
  kind: "xml",
2380
- nodes: [declaration(), buildMetaXml()]
2380
+ nodes: [declaration$1(), buildMetaXml$1()]
2381
2381
  }
2382
2382
  } };
2383
2383
  setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odt);
@@ -2498,20 +2498,20 @@ function buildTable(pkg, init) {
2498
2498
  }
2499
2499
  //#endregion
2500
2500
  //#region src/edit/odt/editor.ts
2501
- const CONTENT_PART_PATH = "content.xml";
2501
+ const CONTENT_PART_PATH$1 = "content.xml";
2502
2502
  function findContentRoot(pkg) {
2503
- const part = pkg.parts[CONTENT_PART_PATH];
2503
+ const part = pkg.parts[CONTENT_PART_PATH$1];
2504
2504
  const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2505
- if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH}`);
2505
+ if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH$1}`);
2506
2506
  return root;
2507
2507
  }
2508
- function directChild(parent, tag) {
2508
+ function directChild$3(parent, tag) {
2509
2509
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2510
2510
  }
2511
2511
  function findOfficeText(contentRoot) {
2512
- const body = directChild(contentRoot, "office:body");
2513
- const text = body === void 0 ? void 0 : directChild(body, "office:text");
2514
- if (text === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:text element`);
2512
+ const body = directChild$3(contentRoot, "office:body");
2513
+ const text = body === void 0 ? void 0 : directChild$3(body, "office:text");
2514
+ if (text === void 0) throw new Error(`${CONTENT_PART_PATH$1} has no office:body/office:text element`);
2515
2515
  return text;
2516
2516
  }
2517
2517
  var OdtBodyImpl = class {
@@ -2642,6 +2642,474 @@ function appendBlock(body, block) {
2642
2642
  else if (block.kind === "table") appendTable(body, block);
2643
2643
  }
2644
2644
  //#endregion
2645
+ //#region src/edit/odp/scaffold.ts
2646
+ const CONTENT_NS_PREFIXES = [
2647
+ "office",
2648
+ "style",
2649
+ "text",
2650
+ "table",
2651
+ "draw",
2652
+ "presentation",
2653
+ "fo",
2654
+ "svg",
2655
+ "xlink"
2656
+ ];
2657
+ const STYLES_NS_PREFIXES = [
2658
+ "office",
2659
+ "style",
2660
+ "text",
2661
+ "table",
2662
+ "draw",
2663
+ "presentation",
2664
+ "fo",
2665
+ "svg",
2666
+ "xlink"
2667
+ ];
2668
+ const META_NS_PREFIXES = [
2669
+ "office",
2670
+ "meta",
2671
+ "dc"
2672
+ ];
2673
+ const ODF_VERSION = "1.3";
2674
+ const MASTER_PAGE_NAME = "Standard";
2675
+ function declaration() {
2676
+ return {
2677
+ type: "declaration",
2678
+ attributes: [
2679
+ {
2680
+ name: "version",
2681
+ value: "1.0"
2682
+ },
2683
+ {
2684
+ name: "encoding",
2685
+ value: "UTF-8"
2686
+ },
2687
+ {
2688
+ name: "standalone",
2689
+ value: "yes"
2690
+ }
2691
+ ]
2692
+ };
2693
+ }
2694
+ function buildPageLayout() {
2695
+ return el("style:page-layout", { "style:name": "PM1" }, [el("style:page-layout-properties", {
2696
+ "fo:page-width": `${SLIDE_SIZE_WIDESCREEN.widthPt}pt`,
2697
+ "fo:page-height": `${SLIDE_SIZE_WIDESCREEN.heightPt}pt`
2698
+ })]);
2699
+ }
2700
+ function buildStylesXml() {
2701
+ return el("office:document-styles", {
2702
+ ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
2703
+ "office:version": ODF_VERSION
2704
+ }, [
2705
+ el("office:styles"),
2706
+ el("office:automatic-styles", {}, [buildPageLayout()]),
2707
+ el("office:master-styles", {}, [el("style:master-page", {
2708
+ "style:name": MASTER_PAGE_NAME,
2709
+ "style:page-layout-name": "PM1"
2710
+ })])
2711
+ ]);
2712
+ }
2713
+ function buildContentXml() {
2714
+ return el("office:document-content", {
2715
+ ...xmlnsAttributes([...CONTENT_NS_PREFIXES]),
2716
+ "office:version": ODF_VERSION
2717
+ }, [el("office:automatic-styles"), el("office:body", {}, [el("office:presentation")])]);
2718
+ }
2719
+ function buildMetaXml() {
2720
+ return el("office:document-meta", {
2721
+ ...xmlnsAttributes([...META_NS_PREFIXES]),
2722
+ "office:version": ODF_VERSION
2723
+ }, [el("office:meta")]);
2724
+ }
2725
+ function createEmptyOdpPackage() {
2726
+ const pkg = { parts: {
2727
+ "content.xml": {
2728
+ kind: "xml",
2729
+ nodes: [declaration(), buildContentXml()]
2730
+ },
2731
+ "styles.xml": {
2732
+ kind: "xml",
2733
+ nodes: [declaration(), buildStylesXml()]
2734
+ },
2735
+ "meta.xml": {
2736
+ kind: "xml",
2737
+ nodes: [declaration(), buildMetaXml()]
2738
+ }
2739
+ } };
2740
+ setDocumentMediaType(pkg, ODF_MEDIA_TYPES.odp);
2741
+ syncManifest(pkg);
2742
+ return pkg;
2743
+ }
2744
+ //#endregion
2745
+ //#region src/odf-package/media.ts
2746
+ const PICTURES_DIR = "Pictures";
2747
+ function escapeRegExp(value) {
2748
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2749
+ }
2750
+ function nextPictureIndex(pkg, extension) {
2751
+ const pattern = new RegExp(`^image(\\d+)\\.${escapeRegExp(extension)}$`);
2752
+ const prefix = `${PICTURES_DIR}/`;
2753
+ let max = 0;
2754
+ for (const path of Object.keys(pkg.parts)) {
2755
+ if (!path.startsWith(prefix)) continue;
2756
+ const match = pattern.exec(path.slice(prefix.length));
2757
+ if (match === null) continue;
2758
+ const digits = match[1];
2759
+ if (digits === void 0) continue;
2760
+ const n = Number.parseInt(digits, 10);
2761
+ if (n > max) max = n;
2762
+ }
2763
+ return max + 1;
2764
+ }
2765
+ function addImageMedia(pkg, imageBytes, format) {
2766
+ const index = nextPictureIndex(pkg, format);
2767
+ const partPath = `${PICTURES_DIR}/image${index}.${format}`;
2768
+ pkg.parts[partPath] = {
2769
+ kind: "binary",
2770
+ base64: bytesToBase64$2(imageBytes)
2771
+ };
2772
+ syncManifest$1(pkg);
2773
+ return { partPath };
2774
+ }
2775
+ //#endregion
2776
+ //#region src/edit/odp/shape.ts
2777
+ function directChild$2(parent, tag) {
2778
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2779
+ }
2780
+ function buildTransformAttr(frame, rotationDeg) {
2781
+ const angleRad = -rotationDeg * Math.PI / 180;
2782
+ const localCenter = {
2783
+ xPt: frame.widthPt / 2,
2784
+ yPt: frame.heightPt / 2
2785
+ };
2786
+ const rotatedCenter = applyOdfTransform([{
2787
+ kind: "rotate",
2788
+ angleRad
2789
+ }], localCenter);
2790
+ const desiredCenter = {
2791
+ xPt: frame.xPt + frame.widthPt / 2,
2792
+ yPt: frame.yPt + frame.heightPt / 2
2793
+ };
2794
+ const txPt = desiredCenter.xPt - rotatedCenter.xPt;
2795
+ const tyPt = desiredCenter.yPt - rotatedCenter.yPt;
2796
+ return `rotate(${angleRad}) translate(${formatOdfLength(txPt)} ${formatOdfLength(tyPt)})`;
2797
+ }
2798
+ var OdpShape = class {
2799
+ container;
2800
+ node;
2801
+ pkg;
2802
+ removed = false;
2803
+ constructor(container, node, pkg) {
2804
+ this.container = container;
2805
+ this.node = node;
2806
+ this.pkg = pkg;
2807
+ }
2808
+ live() {
2809
+ if (this.removed) throw new Error("this OdpShape has been removed from its slide and can no longer be used");
2810
+ return this.node;
2811
+ }
2812
+ get name() {
2813
+ return attr$1(this.live(), "draw:name");
2814
+ }
2815
+ get frame() {
2816
+ return resolveOdfShapeGeometry(this.live())?.frame;
2817
+ }
2818
+ set frame(value) {
2819
+ this.applyGeometry(value, this.rotationDeg);
2820
+ }
2821
+ get rotationDeg() {
2822
+ return resolveOdfShapeGeometry(this.live())?.rotationDeg;
2823
+ }
2824
+ set rotationDeg(value) {
2825
+ const currentFrame = this.frame;
2826
+ if (currentFrame === void 0) throw new Error("cannot set rotationDeg on a shape with no resolvable frame (missing svg:width/svg:height)");
2827
+ this.applyGeometry(currentFrame, value);
2828
+ }
2829
+ applyGeometry(frame, rotationDeg) {
2830
+ const node = this.live();
2831
+ setAttr(node, "svg:width", formatOdfLength(frame.widthPt));
2832
+ setAttr(node, "svg:height", formatOdfLength(frame.heightPt));
2833
+ if (rotationDeg === void 0 || rotationDeg === 0) {
2834
+ removeAttr(node, "draw:transform");
2835
+ setAttr(node, "svg:x", formatOdfLength(frame.xPt));
2836
+ setAttr(node, "svg:y", formatOdfLength(frame.yPt));
2837
+ } else {
2838
+ removeAttr(node, "svg:x");
2839
+ removeAttr(node, "svg:y");
2840
+ setAttr(node, "draw:transform", buildTransformAttr(frame, rotationDeg));
2841
+ }
2842
+ }
2843
+ textBox(create) {
2844
+ const node = this.live();
2845
+ const existing = directChild$2(node, "draw:text-box");
2846
+ if (existing !== void 0 || !create) return existing;
2847
+ const created = el("draw:text-box");
2848
+ node.children.push(created);
2849
+ return created;
2850
+ }
2851
+ paragraphs() {
2852
+ const textBox = this.textBox(false);
2853
+ if (textBox === void 0) return [];
2854
+ const out = [];
2855
+ for (const child of textBox.children) if (child.type === "element" && child.tag === "text:p") out.push(new OdtParagraph(textBox.children, child, this.pkg));
2856
+ return out;
2857
+ }
2858
+ appendParagraph(init) {
2859
+ const textBox = this.textBox(true);
2860
+ const paragraphElement = buildParagraph(this.pkg, init);
2861
+ textBox.children.push(paragraphElement);
2862
+ return new OdtParagraph(textBox.children, paragraphElement, this.pkg);
2863
+ }
2864
+ get text() {
2865
+ return this.paragraphs().map((p) => p.text).join("\n");
2866
+ }
2867
+ set text(value) {
2868
+ const textBox = this.textBox(true);
2869
+ textBox.children = [buildParagraph(this.pkg, { text: value })];
2870
+ }
2871
+ addList() {
2872
+ const textBox = this.textBox(true);
2873
+ const listElement = buildList(this.pkg);
2874
+ textBox.children.push(listElement);
2875
+ return new OdtList(textBox.children, listElement, this.pkg);
2876
+ }
2877
+ remove() {
2878
+ removeChild(this.container, this.live());
2879
+ this.removed = true;
2880
+ }
2881
+ };
2882
+ function buildTextBoxFrame(pkg, frame, text) {
2883
+ return el("draw:frame", {
2884
+ "svg:x": formatOdfLength(frame.xPt),
2885
+ "svg:y": formatOdfLength(frame.yPt),
2886
+ "svg:width": formatOdfLength(frame.widthPt),
2887
+ "svg:height": formatOdfLength(frame.heightPt)
2888
+ }, [el("draw:text-box", {}, [buildParagraph(pkg, { text })])]);
2889
+ }
2890
+ function buildImageFrame(partPath, frame) {
2891
+ return el("draw:frame", {
2892
+ "svg:x": formatOdfLength(frame.xPt),
2893
+ "svg:y": formatOdfLength(frame.yPt),
2894
+ "svg:width": formatOdfLength(frame.widthPt),
2895
+ "svg:height": formatOdfLength(frame.heightPt)
2896
+ }, [el("draw:image", { "xlink:href": partPath })]);
2897
+ }
2898
+ //#endregion
2899
+ //#region src/edit/odp/image.ts
2900
+ function insertImageFrameMedia(context, frame, image) {
2901
+ const { partPath } = addImageMedia(context.pkg, image.bytes, image.format);
2902
+ return buildImageFrame(partPath, frame);
2903
+ }
2904
+ //#endregion
2905
+ //#region src/edit/odp/slide.ts
2906
+ function directChild$1(parent, tag) {
2907
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2908
+ }
2909
+ const NOTES_FRAME_X_PT = 20;
2910
+ const NOTES_FRAME_Y_PT = 400;
2911
+ const NOTES_FRAME_WIDTH_PT = 300;
2912
+ const NOTES_FRAME_HEIGHT_PT = 100;
2913
+ function buildNotesElement(pkg, value) {
2914
+ const textBox = el("draw:text-box", {}, value.split("\n").map((line) => buildParagraph(pkg, { text: line })));
2915
+ return el("presentation:notes", {}, [el("draw:frame", {
2916
+ "svg:x": formatOdfLength(NOTES_FRAME_X_PT),
2917
+ "svg:y": formatOdfLength(NOTES_FRAME_Y_PT),
2918
+ "svg:width": formatOdfLength(NOTES_FRAME_WIDTH_PT),
2919
+ "svg:height": formatOdfLength(NOTES_FRAME_HEIGHT_PT)
2920
+ }, [textBox])]);
2921
+ }
2922
+ var OdpSlide = class {
2923
+ container;
2924
+ node;
2925
+ context;
2926
+ removed = false;
2927
+ constructor(container, node, context) {
2928
+ this.container = container;
2929
+ this.node = node;
2930
+ this.context = context;
2931
+ }
2932
+ live() {
2933
+ if (this.removed) throw new Error("this OdpSlide has been removed from the presentation and can no longer be used");
2934
+ return this.node;
2935
+ }
2936
+ shapes() {
2937
+ const node = this.live();
2938
+ const out = [];
2939
+ for (const child of node.children) if (child.type === "element" && child.tag === "draw:frame") out.push(new OdpShape(node.children, child, this.context.pkg));
2940
+ return out;
2941
+ }
2942
+ addTextBox(init) {
2943
+ const node = this.live();
2944
+ const frameElement = buildTextBoxFrame(this.context.pkg, init.frame, init.text);
2945
+ node.children.push(frameElement);
2946
+ return new OdpShape(node.children, frameElement, this.context.pkg);
2947
+ }
2948
+ addImage(init) {
2949
+ const node = this.live();
2950
+ const frameElement = insertImageFrameMedia({ pkg: this.context.pkg }, init.frame, init);
2951
+ node.children.push(frameElement);
2952
+ return new OdpShape(node.children, frameElement, this.context.pkg);
2953
+ }
2954
+ get notes() {
2955
+ const notesElement = directChild$1(this.live(), "presentation:notes");
2956
+ if (notesElement === void 0) return "";
2957
+ return elementsWithTag$1(notesElement.children, "text:p").map((p) => decodeOdfText$1(p.children)).join("\n");
2958
+ }
2959
+ set notes(value) {
2960
+ const node = this.live();
2961
+ const existing = directChild$1(node, "presentation:notes");
2962
+ const notesElement = buildNotesElement(this.context.pkg, value);
2963
+ if (existing === void 0) node.children.push(notesElement);
2964
+ else existing.children = notesElement.children;
2965
+ }
2966
+ remove() {
2967
+ removeChild(this.container, this.live());
2968
+ this.removed = true;
2969
+ }
2970
+ };
2971
+ //#endregion
2972
+ //#region src/edit/odp/editor.ts
2973
+ const CONTENT_PART_PATH = "content.xml";
2974
+ const STYLES_PART_PATH = "styles.xml";
2975
+ function directChild(parent, tag) {
2976
+ for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
2977
+ }
2978
+ function findRoot(pkg, partPath) {
2979
+ const part = pkg.parts[partPath];
2980
+ const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
2981
+ if (root === void 0) throw new Error(`package has no root element at ${partPath}`);
2982
+ return root;
2983
+ }
2984
+ function findOfficePresentation(pkg) {
2985
+ const body = directChild(findRoot(pkg, CONTENT_PART_PATH), "office:body");
2986
+ const presentation = body === void 0 ? void 0 : directChild(body, "office:presentation");
2987
+ if (presentation === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:presentation element`);
2988
+ return presentation;
2989
+ }
2990
+ function findPageLayoutProperties(pkg) {
2991
+ const pageLayout = directChild(findRoot(pkg, STYLES_PART_PATH), "office:automatic-styles")?.children.find((c) => c.type === "element" && c.tag === "style:page-layout" && attr$1(c, "style:name") === "PM1");
2992
+ const properties = pageLayout === void 0 ? void 0 : directChild(pageLayout, "style:page-layout-properties");
2993
+ if (properties === void 0) throw new Error(`${STYLES_PART_PATH} has no style:page-layout[style:name="PM1"]/style:page-layout-properties element`);
2994
+ return properties;
2995
+ }
2996
+ var OdpEditor = class {
2997
+ pkg;
2998
+ constructor(pkg) {
2999
+ this.pkg = pkg;
3000
+ }
3001
+ slides() {
3002
+ const presentation = findOfficePresentation(this.pkg);
3003
+ const out = [];
3004
+ for (const child of presentation.children) if (child.type === "element" && child.tag === "draw:page") {
3005
+ const context = { pkg: this.pkg };
3006
+ out.push(new OdpSlide(presentation.children, child, context));
3007
+ }
3008
+ return out;
3009
+ }
3010
+ addSlide() {
3011
+ const presentation = findOfficePresentation(this.pkg);
3012
+ const pageElement = el("draw:page", { "draw:master-page-name": MASTER_PAGE_NAME });
3013
+ presentation.children.push(pageElement);
3014
+ const context = { pkg: this.pkg };
3015
+ return new OdpSlide(presentation.children, pageElement, context);
3016
+ }
3017
+ removeSlideAt(index) {
3018
+ const presentation = findOfficePresentation(this.pkg);
3019
+ const target = presentation.children.filter((c) => c.type === "element" && c.tag === "draw:page")[index];
3020
+ if (target === void 0) throw new Error(`slide index ${index} does not exist`);
3021
+ const listIndex = presentation.children.indexOf(target);
3022
+ presentation.children.splice(listIndex, 1);
3023
+ }
3024
+ moveSlide(from, to) {
3025
+ const presentation = findOfficePresentation(this.pkg);
3026
+ const pageIndices = [];
3027
+ presentation.children.forEach((child, i) => {
3028
+ if (child.type === "element" && child.tag === "draw:page") pageIndices.push(i);
3029
+ });
3030
+ const fromChildIndex = pageIndices[from];
3031
+ if (fromChildIndex === void 0) throw new Error(`slide index ${from} does not exist`);
3032
+ const [moved] = presentation.children.splice(fromChildIndex, 1);
3033
+ if (moved === void 0) throw new Error(`slide index ${from} does not exist`);
3034
+ const updatedIndices = [];
3035
+ presentation.children.forEach((child, i) => {
3036
+ if (child.type === "element" && child.tag === "draw:page") updatedIndices.push(i);
3037
+ });
3038
+ const insertAt = to < updatedIndices.length ? updatedIndices[to] ?? presentation.children.length : presentation.children.length;
3039
+ presentation.children.splice(insertAt, 0, moved);
3040
+ }
3041
+ get slideSize() {
3042
+ const properties = findPageLayoutProperties(this.pkg);
3043
+ const widthValue = attr$1(properties, "fo:page-width");
3044
+ const heightValue = attr$1(properties, "fo:page-height");
3045
+ const widthPt = widthValue === void 0 ? void 0 : parseOdfLength(widthValue);
3046
+ const heightPt = heightValue === void 0 ? void 0 : parseOdfLength(heightValue);
3047
+ return {
3048
+ widthPt: widthPt ?? 0,
3049
+ heightPt: heightPt ?? 0
3050
+ };
3051
+ }
3052
+ set slideSize(size) {
3053
+ const properties = findPageLayoutProperties(this.pkg);
3054
+ properties.attributes = [{
3055
+ name: "fo:page-width",
3056
+ value: formatOdfLength(size.widthPt)
3057
+ }, {
3058
+ name: "fo:page-height",
3059
+ value: formatOdfLength(size.heightPt)
3060
+ }];
3061
+ }
3062
+ toPackage() {
3063
+ return this.pkg;
3064
+ }
3065
+ toBytes() {
3066
+ return encodePackage$2(this.pkg);
3067
+ }
3068
+ };
3069
+ function openOdp(bytes) {
3070
+ return new OdpEditor(decodePackage$2(bytes));
3071
+ }
3072
+ function createOdp() {
3073
+ return new OdpEditor(createEmptyOdpPackage());
3074
+ }
3075
+ //#endregion
3076
+ //#region src/edit/odp/content.ts
3077
+ function buildOdpPackage(content) {
3078
+ if (content.kind !== "presentation") throw new Error("buildOdpPackage requires a presentation ContentDocument");
3079
+ const editor = createOdp();
3080
+ const firstSlide = content.slides[0];
3081
+ if (firstSlide !== void 0) editor.slideSize = firstSlide.size;
3082
+ for (const slide of content.slides) {
3083
+ const odpSlide = editor.addSlide();
3084
+ for (const shape of slide.shapes) appendShape(odpSlide, shape);
3085
+ if (slide.notes.length > 0) odpSlide.notes = slide.notes;
3086
+ }
3087
+ return editor.toPackage();
3088
+ }
3089
+ function appendShape(slide, shape) {
3090
+ const [onlyBlock] = shape.blocks;
3091
+ if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
3092
+ const imageShape = slide.addImage({
3093
+ frame: shape.frame,
3094
+ format: onlyBlock.format,
3095
+ bytes: base64ToBytes$2(onlyBlock.base64),
3096
+ altText: onlyBlock.altText
3097
+ });
3098
+ if (shape.rotationDeg !== void 0) imageShape.rotationDeg = shape.rotationDeg;
3099
+ return;
3100
+ }
3101
+ const textShape = slide.addTextBox({
3102
+ frame: shape.frame,
3103
+ text: ""
3104
+ });
3105
+ if (shape.rotationDeg !== void 0) textShape.rotationDeg = shape.rotationDeg;
3106
+ textShape.paragraphs()[0]?.remove();
3107
+ for (const block of shape.blocks) {
3108
+ if (block.kind !== "paragraph") continue;
3109
+ populateParagraph(textShape.appendParagraph(), block);
3110
+ }
3111
+ }
3112
+ //#endregion
2645
3113
  //#region src/bytes/crc32.ts
2646
3114
  const CRC32_POLYNOMIAL = 3988292384;
2647
3115
  const BYTE_VALUES = 256;
@@ -8463,6 +8931,13 @@ function pdfToOdt(bytes, options) {
8463
8931
  }), { signal: options?.signal });
8464
8932
  return encodePackage$2(buildOdtPackage(content));
8465
8933
  }
8934
+ function pdfToOdp(bytes, options) {
8935
+ const content = reconstructPresentation(readPdf(bytes, {
8936
+ signal: options?.signal,
8937
+ sink: options?.sink
8938
+ }), { signal: options?.signal });
8939
+ return encodePackage$2(buildOdpPackage(content));
8940
+ }
8466
8941
  //#endregion
8467
8942
  //#region src/convert/codec.ts
8468
8943
  const docxPdfCodec = z.codec(DocxBytesSchema, PdfBytesSchema, {
@@ -8477,6 +8952,10 @@ const odtPdfCodec = z.codec(OdtBytesSchema, PdfBytesSchema, {
8477
8952
  decode: (odtBytes) => odtToPdf(odtBytes),
8478
8953
  encode: (pdfBytes) => pdfToOdt(pdfBytes)
8479
8954
  });
8955
+ const odpPdfCodec = z.codec(OdpBytesSchema, PdfBytesSchema, {
8956
+ decode: (odpBytes) => odpToPdf(odpBytes),
8957
+ encode: (pdfBytes) => pdfToOdp(pdfBytes)
8958
+ });
8480
8959
  //#endregion
8481
8960
  //#region src/convert/local.ts
8482
8961
  const SUPPORTED_CONVERSIONS = [
@@ -8507,6 +8986,10 @@ const SUPPORTED_CONVERSIONS = [
8507
8986
  {
8508
8987
  source: "pdf",
8509
8988
  target: "odt"
8989
+ },
8990
+ {
8991
+ source: "pdf",
8992
+ target: "odp"
8510
8993
  }
8511
8994
  ];
8512
8995
  function substitutionDiagnostic(substitution, context) {
@@ -8623,6 +9106,19 @@ function createLocalDocumentConverter() {
8623
9106
  diagnostics
8624
9107
  });
8625
9108
  }
9109
+ if (source.format === "pdf" && targetFormat === "odp") {
9110
+ const bytes = pdfToOdp(source.bytes, {
9111
+ signal: options.signal,
9112
+ sink: (d) => diagnostics.push(fromPdfDiagnostic(d))
9113
+ });
9114
+ return Promise.resolve({
9115
+ document: {
9116
+ format: "odp",
9117
+ bytes
9118
+ },
9119
+ diagnostics
9120
+ });
9121
+ }
8626
9122
  return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
8627
9123
  }
8628
9124
  };
@@ -8634,4 +9130,4 @@ function fixedClock(date) {
8634
9130
  return { now: () => date };
8635
9131
  }
8636
9132
  //#endregion
8637
- export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdsBytesSchema, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odpToPdf, odtPdfCodec, odtToPdf, openDocx, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdpContent, readOdtContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };
9133
+ export { AttributeSchema, BinaryPartSchema, COLOR_BLACK, CONTENT_FORMAT_VERSION, CommentSchema, CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, ContentBlockSchema, ContentDocumentSchema, ContentImageBlockSchema, ContentPageBreakSchema, ContentParagraphSchema, ContentRunSchema, ContentSectionSchema, ContentShapeSchema, ContentSlideSchema, ContentTableCellSchema, ContentTableRowSchema, ContentTableSchema, DEFAULT_LAYOUT_FONT, DefinedNameSchema, DocxBytesSchema, DocxEditor, DocxParagraph, DocxRun, DocxTable, DocxTableCell, DocxTableRow, LAYOUT_FORMAT_VERSION, NOOP_DIAGNOSTIC_SINK, OdgBytesSchema, OdpBytesSchema, OdpEditor, OdpShape, OdpSlide, OdsBytesSchema, OdtBytesSchema, OdtEditor, OdtList, OdtListItem, OdtParagraph, OdtRun, OdtTable, OdtTableCell, OdtTableRow, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PackageSchema, PartSchema, PdfBytesSchema, PdfEncryptedError, PdfParseError, PptxBytesSchema, PptxEditor, PptxShape, PptxSlide, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, attr, base64ToBytes, buildDocxPackage, buildOdpPackage, buildOdtPackage, buildPptxPackage, buildXml, bytesToBase64, childrenWithTag, compactCodec, compactPackageCodec, convertPresentationToLayout, convertWordprocessingToLayout, createDocx, createLocalDocumentConverter, createOdp, createOdt, createPptx, decodeCompactPackage, decodeEntities, decodePackage, docxPdfCodec, docxToPdf, elementsWithTag, encodeCompactPackage, encodePackage, fixedClock, flipY, fromCompact, isCompactXmlNode, isContentBlock, isXmlNode, odpPdfCodec, odpToPdf, odtPdfCodec, odtToPdf, openDocx, openOdp, openOdt, openPptx, packageCodec, parsePackage, parseXml, pdfCodec, pdfToDocx, pdfToOdp, pdfToOdt, pdfToPptx, pptxPdfCodec, pptxToPdf, readDocxContent, readOdpContent, readOdtContent, readPdf, readPptxContent, reconstructPresentation, reconstructWordprocessing, resolveRelationships, rgbHexToColor, rootElement, serializePackage, systemClock, textContent, throwIfAborted, toCompact, unzipPackage, walk, writePdf, xmlCodec, zipPackage };