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